added timestamp and fixed block for duplicate nota and timestamp
This commit is contained in:
@@ -11,7 +11,7 @@ use App\Denominasi;
|
||||
use App\Vault;
|
||||
use Illuminate\Http\Request;
|
||||
use Carbon\Carbon;
|
||||
|
||||
use Illuminate\Support\Facades\Log;
|
||||
class TunaiController extends Controller
|
||||
{
|
||||
|
||||
@@ -194,7 +194,28 @@ class TunaiController extends Controller
|
||||
$current = new Carbon();
|
||||
$cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first();
|
||||
|
||||
//Same Note e.g P1 and S1
|
||||
$same_note = AddTunai::on($cawangan['mysql'])
|
||||
->where('kodlaluan', $request->kodlaluan)
|
||||
->where('nota',$request->nota)
|
||||
->where('tarikh',$current->toDateString())->first();
|
||||
|
||||
if($same_note){
|
||||
Log::error('Error: same-note :' . $kodcaw . ': Name :' . $request->kodlaluan);
|
||||
return 'same-note';
|
||||
}
|
||||
|
||||
//Time Interval
|
||||
$latestRecord = AddTunai::on($cawangan['mysql'])->where('kodlaluan', $request->kodlaluan)->latest()->first();
|
||||
if($latestRecord){
|
||||
$time = Carbon::parse($latestRecord->created_at);
|
||||
$time_end = $time->copy()->addMinutes(1);
|
||||
|
||||
if($current->between($time,$time_end)){
|
||||
Log::error('Error: within 1 minute :' . $kodcaw . ': Name :' . $request->kodlaluan);
|
||||
return 'within 1 minute';
|
||||
}
|
||||
}
|
||||
|
||||
$addtunai=AddTunai::on($cawangan['mysql'])->create([
|
||||
|
||||
@@ -203,7 +224,8 @@ class TunaiController extends Controller
|
||||
'kodlaluan'=>$request->kodlaluan,
|
||||
'tambah'=>$request->tambah,
|
||||
'kurang'=>$request->kurang,
|
||||
'nota'=>$request->nota
|
||||
'nota'=>$request->nota,
|
||||
'created_at'=>$current
|
||||
]);
|
||||
|
||||
return response()->json($addtunai,201);
|
||||
|
||||
Reference in New Issue
Block a user