From e5b724402942b25df45444f4ca85c1bd88f01f54 Mon Sep 17 00:00:00 2001 From: Hafifie PKB Date: Tue, 17 Sep 2024 17:05:00 +0800 Subject: [PATCH 01/10] added timestamp and fixed block for duplicate nota and timestamp --- app/AddTunai.php | 2 +- app/Http/Controllers/TunaiController.php | 26 ++++++- ...add_column_timestamp_to_addtunai_table.php | 73 +++++++++++++++++++ 3 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 database/migrations/2024_09_02_153041_add_column_timestamp_to_addtunai_table.php diff --git a/app/AddTunai.php b/app/AddTunai.php index 2aadf68..635f389 100644 --- a/app/AddTunai.php +++ b/app/AddTunai.php @@ -13,7 +13,7 @@ class AddTunai extends Model * * @var array */ - protected $fillable = ['tarikh','kodcaw','kodlaluan','tambah','kurang','nota']; + protected $fillable = ['tarikh','kodcaw','kodlaluan','tambah','kurang','nota','created_at']; public $timestamps = false; /** diff --git a/app/Http/Controllers/TunaiController.php b/app/Http/Controllers/TunaiController.php index 904d2ec..aa93a4c 100644 --- a/app/Http/Controllers/TunaiController.php +++ b/app/Http/Controllers/TunaiController.php @@ -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); diff --git a/database/migrations/2024_09_02_153041_add_column_timestamp_to_addtunai_table.php b/database/migrations/2024_09_02_153041_add_column_timestamp_to_addtunai_table.php new file mode 100644 index 0000000..d47036c --- /dev/null +++ b/database/migrations/2024_09_02_153041_add_column_timestamp_to_addtunai_table.php @@ -0,0 +1,73 @@ +getPdo(); + return true; + } catch(\Exception $e){ + return false; + } + }); + return $db_connection; + } + + public function up() + { + $this->db_connection = $this->getActiveDB(); + + foreach($this->db_connection as $dbase){ + Schema::connection($dbase)->table('addtunai', function (Blueprint $table) use($dbase) { + + $isCreatedAt = Schema::connection($dbase)->hasColumn('addtunai', 'created_at'); + + if (! $isCreatedAt) { + $table->timestamp('created_at'); + } + }); + } + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + $this->db_connection = $this->getActiveDB(); + + foreach($this->db_connection as $dbase){ + $columns = ['created_at']; + + $columns_exist = array_filter($columns,function($column) use($dbase){ + return Schema::connection($dbase)->hasColumn('addtunai', $column); + }); + + Schema::connection($dbase)->table('addtunai', function(Blueprint $table) use($columns_exist){ + foreach($columns_exist as $column){ + $table->dropColumn($column); + } + }); + } + } +} From e3ea221d12d217bf9b39bb0b4aa870c02687bb4d Mon Sep 17 00:00:00 2001 From: hafifierahman Date: Tue, 29 Oct 2024 22:50:39 +0800 Subject: [PATCH 02/10] test cashflow --- app/Http/Controllers/DenominasiController.php | 8 + app/Services/CashFlow/TellerServices.php | 296 ++++++++++++++++++ routes/web.php | 1 + 3 files changed, 305 insertions(+) create mode 100644 app/Services/CashFlow/TellerServices.php diff --git a/app/Http/Controllers/DenominasiController.php b/app/Http/Controllers/DenominasiController.php index 066e0d5..a0f0fae 100644 --- a/app/Http/Controllers/DenominasiController.php +++ b/app/Http/Controllers/DenominasiController.php @@ -5,12 +5,20 @@ namespace App\Http\Controllers; use App\CawanganDetail; use App\Cawangan; use App\Denominasi; +use App\Services\CashFlow\TellerServices; use Illuminate\Http\Request; use Carbon\Carbon; class DenominasiController extends Controller { + public function test($kodcaw,Request $request){ + $teller = new TellerServices($kodcaw); + $response = $teller->CashDeposit($request); + + return response()->json($response); + } + public function listdenominasi($kodcaw) { $current = Carbon::now(); diff --git a/app/Services/CashFlow/TellerServices.php b/app/Services/CashFlow/TellerServices.php new file mode 100644 index 0000000..067594b --- /dev/null +++ b/app/Services/CashFlow/TellerServices.php @@ -0,0 +1,296 @@ +cawangan = $kodcaw; + } + + private function CheckTunai(Request $request){ + $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$this->cawangan)->first(); + $current = Carbon::now(); + $current = new Carbon(); + + try{ + /* Checking Status Data include Tunai */ + $tunai = Tunai::on($cawangan['mysql']) + ->where([['kodcaw','=',$this->cawangan],['tarikh','=',$current->toDateString()],['kodlaluan','=',$request->teller]]); + $tunai = optional($tunai->first())->toArray(); + + if(empty($tunai)){ + // Create transaction of cash in teller + $tunai = Tunai::on($cawangan['mysql'])->create([ + 'tarikh' => $current->toDateString(), + 'kodcaw'=> $this->cawangan, + 'kodlaluan'=>$request->teller, + 'bakiawal'=>$request->bakiawal, + 'masuk'=>$request->masuk, + 'yuran'=>$request->yuran, + 'keluar'=>$request->keluar, + 'baki'=>$request->baki, + 'tambah'=>$request->amt, + 'kurang'=>$request->kurang + ]); + } + + } catch (\Exception $e) { + DB::connection($cawangan['mysql'])->rollBack(); + + // Handle the exception or re-throw + throw $e; + } + + } + + private function checkAddTunai(Request $request){ + $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$this->cawangan)->first(); + $current = Carbon::now(); + $current = new Carbon(); + + /* Checking AddTunai */ + + //Same Note e.g P1 and S1 + $same_note = AddTunai::on($cawangan['mysql']) + ->where('kodlaluan', $request->teller) + ->where('nota',$request->nota) + ->where('tarikh',$current->toDateString())->first(); + + if($same_note){ + //Throw this + Log::error('Error: same-note :' . $this->cawangan . ': Name :' . $request->teller); + return 'same-note'; + } + + //Time Interval + $latestRecord = AddTunai::on($cawangan['mysql'])->where('kodlaluan', $request->teller)->latest()->first(); + if($latestRecord){ + $time = Carbon::parse($latestRecord->created_at); + $time_end = $time->copy()->addMinutes(1); + + if($current->between($time,$time_end)){ + //Throw this + Log::error('Error: within 1 minute :' . $this->cawangan . ': Name :' . $request->teller); + return 'within 1 minute'; + } + } + + return 'success'; + } + + private function getDenoTotal(Request $request){ + $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$this->cawangan)->first(); + $current = Carbon::now(); + $current = new Carbon(); + + $deno = Denominasi::on($cawangan['mysql'])->where('tarikh','=',$current->toDateString()); + $deno = optional($deno->first())->toArray(); + + if(empty($deno)){ + return "empty"; + Log::error("Empty Denominasi Data"); + } + + $deno['txtsen1'] -= intval($request->ambilansen1); + $deno['txtsen5'] -= intval($request->ambilansen5); + $deno['txtsen10'] -= intval($request->ambilansen10); + $deno['txtsen20'] -= intval($request->ambilansen20); + $deno['txtsen50'] -= intval($request->ambilansen50); + + $deno['txtring1'] -= intval($request->ambilanring1); + $deno['txtring5'] -= intval($request->ambilanring5); + $deno['txtring10'] -= intval($request->ambilanring10); + $deno['txtring20'] -= intval($request->ambilanring20); + $deno['txtring50'] -= intval($request->ambilanring50); + $deno['txtring100'] -= intval($request->ambilanring100); + + $k01 = ($deno['txtsen1'] * 0.01); + $k05 = ($deno['txtsen5'] * 0.05); + $k010 = ($deno['txtsen10'] * 0.10); + $k020 = ($deno['txtsen20'] * 0.20); + $k050 = ($deno['txtsen50'] * 0.50); + $k1 = ($deno['txtring1'] * 1); + $k5 = ($deno['txtring5'] * 5); + $k10 = ($deno['txtring10'] * 10); + $k20 = ($deno['txtring20'] * 20); + $k50 = ($deno['txtring50'] * 50); + $k100 = ($deno['txtring100'] * 100); + + $totalkeping = $k01 + $k05 + $k010 + $k020 + + $k050 + $k1 + $k5 + $k10 + $k20 + + $k50 + $k100; + + $array_total_cash = [ + 'syiling1' => $k01, + 'syiling5' => $k05, + 'syiling10' => $k010, + 'syiling20' => $k020, + 'syiling50' => $k050, + 'kertas1' => $k1, + 'kertas5' => $k5, + 'kertas10' => $k10, + 'kertas20' => $k20, + 'kertas50' => $k50, + 'kertas100' => $k100, + ]; + + return ['deno' => $deno,'total' => $totalkeping,'cash' => $array_total_cash]; + } + + + public function CashDeposit(Request $request){ + + $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$this->cawangan)->first(); + $current = Carbon::now(); + $current = new Carbon(); + + try { + // Start transaction + DB::connection($cawangan['mysql'])->beginTransaction(); + DB::connection('mysql7')->beginTransaction(); + + + /* Addtunai Transaction */ + $response_addtunai = $this->checkAddTunai($request); + + if($response_addtunai !== 'success'){ + Log::error("Unsuccessful Tunai"); + Log::debug($response_addtunai); + throw new Exception('Unsuccessful Tunai'); + } + + AddTunai::on($cawangan['mysql'])->create([ + 'tarikh' => $current->toDateString(), + 'kodcaw'=> $this->cawangan, + 'kodlaluan'=>$request->teller, + 'tambah'=>$request->amt, + 'kurang'=> 0, + 'nota'=>$request->nota, + 'created_at'=>$current + ]); + + /* Tunai Transaction */ + $tunai = Tunai::on($cawangan['mysql']) + ->where([['kodcaw','=',$this->cawangan],['tarikh','=',$current->toDateString()],['kodlaluan','=',$request->teller]]); + $tunai = optional($tunai->first())->toArray(); + + if(empty($tunai)){ + Log::debug($this->cawangan); + Log::debug($current->toDateString()); + Log::debug($request->teller); + Log::error("Empty Tunai Data"); + throw new Exception("Empty Tunai Data"); + } + + $total_teller_deposit = $tunai['tambah'] + $request->amt; + $remaining_teller_cashflow = $tunai['baki'] + $request->amt; + + Tunai::on($cawangan['mysql'])->where( [['tarikh','=', $current->toDateString()],['kodlaluan','=', $request->teller] ])-> + update(array( + 'tambah' => $total_teller_deposit, + 'baki' => $remaining_teller_cashflow + )); + + /* Vault Transaction */ + $vault = Vault::on($cawangan['mysql']) + ->where('kodcaw','=',$this->cawangan) + ->where('tarikh','=',$current->toDateString()); + $vault = optional($vault->first())->toArray(); + + if(empty($vault)){ + Log::error("Empty Vault Data"); + throw new Exception("Empty Vault Data"); + } + + $total_vault_deposit = $vault['keluar'] + $request->amt; + $remaining_vault = $vault['bakiawal'] - $total_vault_deposit + $vault['masuk'] + $vault['pendahuluan'] - $vault['serahan'] - $vault['totpanjar']; + + Vault::on($cawangan['mysql'])->where([['tarikh','=',$current->toDateString()],['kodcaw','=', $this->cawangan]])->update(array( + 'keluar' => $total_vault_deposit, + 'bakiakhir' => $remaining_vault, + 'bakieod' => $remaining_vault + ) ); + + /* Denominasi Transaction */ + + $response_deno = $this->getDenoTotal($request); + + if($response_deno == 'empty') + throw new Exception("Empty Denominasi Data"); + + $deno = $response_deno['deno']; + $total = $response_deno['total']; + $cash = $response_deno['cash']; + + Denominasi::on($cawangan['mysql'])->where([['tarikh','=',$current->toDateString()]])->update(array( + 'txtring1'=> $deno['txtring1'], + 'k1'=> $cash['kertas1'], + 'txtring5'=> $deno['txtring5'], + 'k5'=> $cash['kertas5'], + 'txtsen1'=> $deno['txtsen1'], + 'k01'=> $cash['syiling1'], + 'txtsen5'=> $deno['txtsen5'], + 'k05'=> $cash['syiling5'], + 'txtsen10'=> $deno['txtsen10'], + 'k010'=> $cash['syiling10'], + 'txtsen20'=> $deno['txtsen20'], + 'k020'=> $cash['syiling20'], + 'txtsen50'=> $deno['txtsen50'], + 'k050'=> $cash['syiling50'], + 'txtring10'=> $deno['txtring10'], + 'k10'=> $cash['kertas10'], + 'txtring20'=> $deno['txtring20'], + 'k20'=> $cash['kertas20'], + 'txtring50'=> $deno['txtring50'], + 'k50'=> $cash['kertas50'], + 'txtring100'=> $deno['txtring100'], + 'k100'=> $cash['kertas100'], + 'txtjumlah'=> $total, + 'jumlahkeping' => $total + ) ); + + /* RequestTeller Transaction */ + RequestTeller::on('mysql7')->where([['no','=',$request->no],['kodcaw','=',$this->cawangan],['kodlaluan','=',$request->teller],['update','=',0]])->update(array( + 'update' => 1 + )); + + // Commit transactions + DB::connection($cawangan['mysql'])->commit(); + DB::connection('mysql7')->commit(); + + return 'success'; + + } catch (\Exception $e) { + DB::connection($cawangan['mysql'])->rollBack(); + DB::connection('mysql7')->rollBack(); + + + // Handle the exception or re-throw + throw $e; + } + + } + + public function CashWithdrawals(){ + + } + +} diff --git a/routes/web.php b/routes/web.php index b2b3a62..ad8c8d1 100644 --- a/routes/web.php +++ b/routes/web.php @@ -646,6 +646,7 @@ $router->group(['prefix'=>'api'], function () use ($router){ $router->get('/cawangan/getcawnotisall/{kodcaw}',['uses'=>'CawanganCallCenterController@getcawnotisall']); $router->get('/cawangan/bycawnotisperingatan/{kodcaw}/{notisid}',['uses'=>'CawanganCallCenterController@bycawnotisperingatan']); + $router->post('test/updatetunai/{kodcaw}',['uses'=>'DenominasiController@test']); }); From 3a7259a64c9fa2cb5fec34443bf4c1b21a463349 Mon Sep 17 00:00:00 2001 From: hafifierahman Date: Fri, 1 Nov 2024 09:28:48 +0800 Subject: [PATCH 03/10] added function for cashdeposit and cash withdrawals --- app/Http/Controllers/TunaiController.php | 27 ++++ app/Services/CashFlow/TellerServices.php | 193 +++++++++++++++++++---- routes/web.php | 1 + 3 files changed, 193 insertions(+), 28 deletions(-) diff --git a/app/Http/Controllers/TunaiController.php b/app/Http/Controllers/TunaiController.php index aa93a4c..1e36f79 100644 --- a/app/Http/Controllers/TunaiController.php +++ b/app/Http/Controllers/TunaiController.php @@ -291,6 +291,33 @@ class TunaiController extends Controller return response()->json($addtunai); } + public function updateRequestTellerDeno($kodcaw,Request $request){ + + $requestteller = RequestTeller::on('mysql7')->where([['no','=',$request->no],['kodcaw','=',$kodcaw],['kodlaluan','=',$request->kodlaluan],['update','=',0]])->update(array( + 'update' => 1, + 'bd1' => $request->bd1, + 'bd5' => $request->bd5, + 'bd10' => $request->bd10, + 'bd20' => $request->bd20, + 'bd50' => $request->bd50, + 'bd100' => $request->bd100, + 'txtring1' => $request->txtring1, + 'txtring5' => $request->txtring5, + 'txtring10' => $request->txtring10, + 'txtring20' => $request->txtring20, + 'txtring50' => $request->txtring50, + 'txtring100' => $request->txtring100, + 'txtring1000' => $request->txtring1000, + 'txtsen1' => $request->txtsen1, + 'txtsen5' => $request->txtsen5, + 'txtsen10' => $request->txtsen10, + 'txtsen20' => $request->txtsen20, + 'txtsen50' => $request->txtsen50, + ) ); + + return response()->json($requestteller); + } + public function getRequestTeller($kodcaw) { diff --git a/app/Services/CashFlow/TellerServices.php b/app/Services/CashFlow/TellerServices.php index 067594b..99cc56e 100644 --- a/app/Services/CashFlow/TellerServices.php +++ b/app/Services/CashFlow/TellerServices.php @@ -96,7 +96,7 @@ class TellerServices return 'success'; } - private function getDenoTotal(Request $request){ + private function getDenoTotal(Request $request,$operator){ $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$this->cawangan)->first(); $current = Carbon::now(); $current = new Carbon(); @@ -109,18 +109,18 @@ class TellerServices Log::error("Empty Denominasi Data"); } - $deno['txtsen1'] -= intval($request->ambilansen1); - $deno['txtsen5'] -= intval($request->ambilansen5); - $deno['txtsen10'] -= intval($request->ambilansen10); - $deno['txtsen20'] -= intval($request->ambilansen20); - $deno['txtsen50'] -= intval($request->ambilansen50); + $deno['txtsen1'] += ($operator == 'add') ? intval($request->ambilansen1) : -intval($request->ambilansen1); + $deno['txtsen5'] += ($operator == 'add') ? intval($request->ambilansen5) : -intval($request->ambilansen5); + $deno['txtsen10'] += ($operator == 'add') ? intval($request->ambilansen10) : -intval($request->ambilansen10); + $deno['txtsen20'] += ($operator == 'add') ? intval($request->ambilansen20) : -intval($request->ambilansen20); + $deno['txtsen50'] += ($operator == 'add') ? intval($request->ambilansen50) : -intval($request->ambilansen50); - $deno['txtring1'] -= intval($request->ambilanring1); - $deno['txtring5'] -= intval($request->ambilanring5); - $deno['txtring10'] -= intval($request->ambilanring10); - $deno['txtring20'] -= intval($request->ambilanring20); - $deno['txtring50'] -= intval($request->ambilanring50); - $deno['txtring100'] -= intval($request->ambilanring100); + $deno['txtring1'] += ($operator == 'add') ? intval($request->ambilanring1) : -intval($request->ambilanring1); + $deno['txtring5'] += ($operator == 'add') ? intval($request->ambilanring5) : -intval($request->ambilanring5); + $deno['txtring10'] += ($operator == 'add') ? intval($request->ambilanring10) : -intval($request->ambilanring10); + $deno['txtring20'] += ($operator == 'add') ? intval($request->ambilanring20) : -intval($request->ambilanring20); + $deno['txtring50'] += ($operator == 'add') ? intval($request->ambilanring50) : -intval($request->ambilanring50); + $deno['txtring100'] += ($operator == 'add') ? intval($request->ambilanring100) : -intval($request->ambilanring100); $k01 = ($deno['txtsen1'] * 0.01); $k05 = ($deno['txtsen5'] * 0.05); @@ -162,17 +162,17 @@ class TellerServices $current = Carbon::now(); $current = new Carbon(); + // Start transaction + DB::connection($cawangan['mysql'])->beginTransaction(); + DB::connection('mysql7')->beginTransaction(); + try { - // Start transaction - DB::connection($cawangan['mysql'])->beginTransaction(); - DB::connection('mysql7')->beginTransaction(); - /* Addtunai Transaction */ $response_addtunai = $this->checkAddTunai($request); if($response_addtunai !== 'success'){ - Log::error("Unsuccessful Tunai"); + // Log::error("Unsuccessful Tunai"); Log::debug($response_addtunai); throw new Exception('Unsuccessful Tunai'); } @@ -196,7 +196,6 @@ class TellerServices Log::debug($this->cawangan); Log::debug($current->toDateString()); Log::debug($request->teller); - Log::error("Empty Tunai Data"); throw new Exception("Empty Tunai Data"); } @@ -216,7 +215,6 @@ class TellerServices $vault = optional($vault->first())->toArray(); if(empty($vault)){ - Log::error("Empty Vault Data"); throw new Exception("Empty Vault Data"); } @@ -227,11 +225,11 @@ class TellerServices 'keluar' => $total_vault_deposit, 'bakiakhir' => $remaining_vault, 'bakieod' => $remaining_vault - ) ); + )); /* Denominasi Transaction */ - $response_deno = $this->getDenoTotal($request); + $response_deno = $this->getDenoTotal($request,'subtract'); if($response_deno == 'empty') throw new Exception("Empty Denominasi Data"); @@ -268,9 +266,27 @@ class TellerServices ) ); /* RequestTeller Transaction */ - RequestTeller::on('mysql7')->where([['no','=',$request->no],['kodcaw','=',$this->cawangan],['kodlaluan','=',$request->teller],['update','=',0]])->update(array( - 'update' => 1 - )); + $requestteller = RequestTeller::on('mysql7')->where([['no','=',$request->no],['kodcaw','=',$this->cawangan],['kodlaluan','=',$request->teller],['update','=',0]])->update(array( + 'update' => 1, + 'bd1' => 0, + 'bd5' => 0, + 'bd10' => 0, + 'bd20' => 0, + 'bd50' => 0, + 'bd100' => 0, + 'txtring1' => ($request->ambilanring1) ? $request->ambilanring1 : 0, + 'txtring5' => ($request->ambilanring5) ? $request->ambilanring5 : 0, + 'txtring10' => ($request->ambilanring10) ? $request->ambilanring10 : 0, + 'txtring20' => ($request->ambilanring20) ? $request->ambilanring20 : 0, + 'txtring50' => ($request->ambilanring50) ? $request->ambilanring50 : 0, + 'txtring100' => ($request->ambilanring100) ? $request->ambilanring100 : 0, + 'txtring1000' => 0, + 'txtsen1' => ($request->ambilansen1) ? $request->ambilansen1 : 0, + 'txtsen5' => ($request->ambilansen5) ? $request->ambilansen5 : 0, + 'txtsen10' => ($request->ambilansen10) ? $request->ambilansen10 : 0, + 'txtsen20' => ($request->ambilansen20) ? $request->ambilansen20 : 0, + 'txtsen50' => ($request->ambilansen50) ? $request->ambilansen50 : 0, + ) ); // Commit transactions DB::connection($cawangan['mysql'])->commit(); @@ -281,16 +297,137 @@ class TellerServices } catch (\Exception $e) { DB::connection($cawangan['mysql'])->rollBack(); DB::connection('mysql7')->rollBack(); - + Log::error("Transaction failed: " . $e->getMessage()); - // Handle the exception or re-throw - throw $e; + return 'error'; } } - public function CashWithdrawals(){ + public function CashWithdrawals(Request $request){ + $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$this->cawangan)->first(); + $current = Carbon::now(); + $current = new Carbon(); + // Start transaction + DB::connection($cawangan['mysql'])->beginTransaction(); + DB::connection('mysql7')->beginTransaction(); + + try { + + /* Addtunai Transaction */ + $response_addtunai = $this->checkAddTunai($request); + + if($response_addtunai !== 'success'){ + // Log::error("Unsuccessful Tunai"); + Log::debug($response_addtunai); + throw new Exception('Unsuccessful Tunai'); + } + + AddTunai::on($cawangan['mysql'])->create([ + 'tarikh' => $current->toDateString(), + 'kodcaw'=> $this->cawangan, + 'kodlaluan'=>$request->teller, + 'tambah'=>$request->amt, + 'kurang'=> 0, + 'nota'=>$request->nota, + 'created_at'=>$current + ]); + + /* Tunai Transaction */ + $tunai = Tunai::on($cawangan['mysql']) + ->where([['kodcaw','=',$this->cawangan],['tarikh','=',$current->toDateString()],['kodlaluan','=',$request->teller]]); + $tunai = optional($tunai->first())->toArray(); + + if(empty($tunai)){ + Log::debug($this->cawangan); + Log::debug($current->toDateString()); + Log::debug($request->teller); + throw new Exception("Empty Tunai Data"); + } + + $total_teller_deposit = $tunai['kurang'] + $request->amt; + $remaining_teller_cashflow = $tunai['baki'] + $request->amt; + + Tunai::on($cawangan['mysql'])->where( [['tarikh','=', $current->toDateString()],['kodlaluan','=', $request->teller] ])-> + update(array( + 'kurang' => $total_teller_deposit, + 'baki' => $remaining_teller_cashflow + )); + + /* Vault Transaction */ + $vault = Vault::on($cawangan['mysql']) + ->where('kodcaw','=',$this->cawangan) + ->where('tarikh','=',$current->toDateString()); + $vault = optional($vault->first())->toArray(); + + if(empty($vault)){ + throw new Exception("Empty Vault Data"); + } + + $total_vault_deposit = $vault['masuk'] + $request->amt; + $remaining_vault = $vault['bakiawal'] - $vault['keluar'] + $total_vault_deposit + $vault['pendahuluan'] - $vault['serahan'] - $vault['totpanjar']; + + Vault::on($cawangan['mysql'])->where([['tarikh','=',$current->toDateString()],['kodcaw','=', $this->cawangan]])->update(array( + 'masuk' => $total_vault_deposit, + 'bakiakhir' => $remaining_vault, + 'bakieod' => $remaining_vault + )); + + /* Denominasi Transaction */ + $response_deno = $this->getDenoTotal($request,'add'); + + if($response_deno == 'empty') + throw new Exception("Empty Denominasi Data"); + + $deno = $response_deno['deno']; + $total = $response_deno['total']; + $cash = $response_deno['cash']; + + Denominasi::on($cawangan['mysql'])->where([['tarikh','=',$current->toDateString()]])->update(array( + 'txtring1'=> $deno['txtring1'], + 'k1'=> $cash['kertas1'], + 'txtring5'=> $deno['txtring5'], + 'k5'=> $cash['kertas5'], + 'txtsen1'=> $deno['txtsen1'], + 'k01'=> $cash['syiling1'], + 'txtsen5'=> $deno['txtsen5'], + 'k05'=> $cash['syiling5'], + 'txtsen10'=> $deno['txtsen10'], + 'k010'=> $cash['syiling10'], + 'txtsen20'=> $deno['txtsen20'], + 'k020'=> $cash['syiling20'], + 'txtsen50'=> $deno['txtsen50'], + 'k050'=> $cash['syiling50'], + 'txtring10'=> $deno['txtring10'], + 'k10'=> $cash['kertas10'], + 'txtring20'=> $deno['txtring20'], + 'k20'=> $cash['kertas20'], + 'txtring50'=> $deno['txtring50'], + 'k50'=> $cash['kertas50'], + 'txtring100'=> $deno['txtring100'], + 'k100'=> $cash['kertas100'], + 'txtjumlah'=> $total, + 'jumlahkeping' => $total + ) ); + + /* RequestTeller Transaction */ + $requestteller = RequestTeller::on('mysql7')->where([['no','=',$request->no],['kodcaw','=',$this->cawangan],['kodlaluan','=',$request->teller],['update','=',0]])->update(array( + 'update' => 1, + ) ); + + // Commit transactions + DB::connection($cawangan['mysql'])->commit(); + DB::connection('mysql7')->commit(); + + return 'success'; + }catch(\Exception $e){ + DB::connection($cawangan['mysql'])->rollBack(); + DB::connection('mysql7')->rollBack(); + Log::error("Transaction failed: " . $e->getMessage()); + + return 'error'; + } } } diff --git a/routes/web.php b/routes/web.php index ad8c8d1..d91c904 100644 --- a/routes/web.php +++ b/routes/web.php @@ -383,6 +383,7 @@ $router->group(['prefix'=>'api'], function () use ($router){ $router->get('requestTeller/getlaporanberkala/{kodcaw}',['uses' => 'TunaiController@getRequestTellerLaporanSerahanBerkala']); $router->get('requestTeller/get/{kodcaw}/date',['uses' => 'TunaiController@getRequestTellerByDate']); $router->put('requestTeller/update/{kodcaw}',['uses' => 'TunaiController@updateRequestTeller']); + $router->put('requestTeller/updatedeno/{kodcaw}',['uses' => 'TunaiController@updateRequestTellerDeno']); $router->put('requestTeller/batal/{kodcaw}',['uses' => 'TunaiController@batalRequestTeller']); $router->get('requestTeller/checkproses',['uses'=>'TunaiController@CheckProsesReqTeller']); From 9443075afd521b34095814b07b3ee68b04c5e92f Mon Sep 17 00:00:00 2001 From: hafifierahman Date: Mon, 4 Nov 2024 01:19:10 +0800 Subject: [PATCH 04/10] added denominasi --- app/Http/Controllers/DenominasiController.php | 8 ++++++++ app/Services/CashFlow/TellerServices.php | 6 +++--- routes/web.php | 1 + 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/app/Http/Controllers/DenominasiController.php b/app/Http/Controllers/DenominasiController.php index a0f0fae..385b90c 100644 --- a/app/Http/Controllers/DenominasiController.php +++ b/app/Http/Controllers/DenominasiController.php @@ -19,6 +19,14 @@ class DenominasiController extends Controller return response()->json($response); } + public function test2($kodcaw,Request $request){ + $teller = new TellerServices($kodcaw); + $response = $teller->CashWithdrawals($request); + + return response()->json($response); + } + + public function listdenominasi($kodcaw) { $current = Carbon::now(); diff --git a/app/Services/CashFlow/TellerServices.php b/app/Services/CashFlow/TellerServices.php index 99cc56e..4535066 100644 --- a/app/Services/CashFlow/TellerServices.php +++ b/app/Services/CashFlow/TellerServices.php @@ -328,8 +328,8 @@ class TellerServices 'tarikh' => $current->toDateString(), 'kodcaw'=> $this->cawangan, 'kodlaluan'=>$request->teller, - 'tambah'=>$request->amt, - 'kurang'=> 0, + 'tambah'=>0, + 'kurang'=> $request->amt, 'nota'=>$request->nota, 'created_at'=>$current ]); @@ -347,7 +347,7 @@ class TellerServices } $total_teller_deposit = $tunai['kurang'] + $request->amt; - $remaining_teller_cashflow = $tunai['baki'] + $request->amt; + $remaining_teller_cashflow = $tunai['baki'] - $request->amt; Tunai::on($cawangan['mysql'])->where( [['tarikh','=', $current->toDateString()],['kodlaluan','=', $request->teller] ])-> update(array( diff --git a/routes/web.php b/routes/web.php index d91c904..c75748b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -648,6 +648,7 @@ $router->group(['prefix'=>'api'], function () use ($router){ $router->get('/cawangan/bycawnotisperingatan/{kodcaw}/{notisid}',['uses'=>'CawanganCallCenterController@bycawnotisperingatan']); $router->post('test/updatetunai/{kodcaw}',['uses'=>'DenominasiController@test']); + $router->post('test/serahantunai/{kodcaw}',['uses'=>'DenominasiController@test2']); }); From 8da43b9501a0ef4f810ca22f2d3a594e565e3913 Mon Sep 17 00:00:00 2001 From: Hafifie PKB Date: Mon, 4 Nov 2024 19:08:22 +0800 Subject: [PATCH 05/10] added panjar route --- app/Http/Controllers/DenominasiController.php | 14 ++ app/Services/Miscellaneous/PanjarServices.php | 147 ++++++++++++------ routes/web.php | 3 + 3 files changed, 119 insertions(+), 45 deletions(-) diff --git a/app/Http/Controllers/DenominasiController.php b/app/Http/Controllers/DenominasiController.php index 385b90c..efdcd73 100644 --- a/app/Http/Controllers/DenominasiController.php +++ b/app/Http/Controllers/DenominasiController.php @@ -7,6 +7,7 @@ use App\Cawangan; use App\Denominasi; use App\Services\CashFlow\TellerServices; use Illuminate\Http\Request; +use App\Services\Miscellaneous\PanjarServices; use Carbon\Carbon; @@ -26,6 +27,19 @@ class DenominasiController extends Controller return response()->json($response); } + public function test3($kodcaw,Request $request){ + $teller = new PanjarServices($kodcaw); + $response = $teller->create($request); + + return response()->json($response); + } + + public function test4($kodcaw,Request $request){ + $teller = new PanjarServices($kodcaw); + $response = $teller->delete($request); + + return response()->json($response); + } public function listdenominasi($kodcaw) { diff --git a/app/Services/Miscellaneous/PanjarServices.php b/app/Services/Miscellaneous/PanjarServices.php index 255202f..46ded2c 100644 --- a/app/Services/Miscellaneous/PanjarServices.php +++ b/app/Services/Miscellaneous/PanjarServices.php @@ -9,6 +9,7 @@ use App\DenoPanjar; use App\Panjar; use App\Vault; use Carbon\Carbon; +use DateTime; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Log; @@ -40,11 +41,12 @@ class PanjarServices private function calculation_denominasi($array_deno = [],$denominasi = [],$jenis_panjar){ - if(isset($array_deno) <= 0 || isset($denominasi) <= 0){ + if(empty($array_deno) && empty($denominasi)){ + return empty($array_deno); return 'no data'; } - if($jenis_panjar != 'masuk' || $jenis_panjar != 'keluar') return 'no data'; + if($jenis_panjar != 'masuk' && $jenis_panjar != 'keluar') return 'no data'; $records = []; foreach($this->namelist_deno as $deno => $value){ @@ -80,6 +82,37 @@ class PanjarServices ]; } + private function checkModal($jenismodal){ + switch ($jenismodal) { + case "selenggara": + $kategori = "Baiki dan Selenggara"; + $tag = 2; + break; + case "keraian": + $kategori = "Keraian & Promosi"; + $tag = 3; + break; + case "belanjaam": + $kategori = "Belanja AM"; + $tag = 1; + break; + case "perubatan": + $kategori = "Belanja AM - Perubatan"; + $tag = 1; + break; + case "dapur": + $kategori = "Belanja AM - Barangan Dapur"; + $tag = 1; + break; + case "pos": + $kategori = "Belanja AM - Postage"; + $tag = 1; + break; + } + + return ['kategori' => $kategori, 'tag' => $tag]; + } + public function delete(Request $request){ $current = Carbon::now(); $current = new Carbon(); @@ -89,14 +122,14 @@ class PanjarServices $panjar = Panjar::on($cawangan['mysql'])->latest('tarikh')->where('nobaucer', $request->nobaucer)->first(); $vault = Vault::on($cawangan['mysql'])->latest('tarikh')->first(); $deno_panjar = DenoPanjar::on('mysql7')->where('kodcaw', $this->cawangan)->where('recno', $request->recno)->latest('tarikh','masa')->first(); - + $totalperubatan = floatval($this->getPerubatanAmount($panjar['tuntutoleh'])) + $panjar['bayaran']; try{ if (!$panjar) throw new \Exception('Custom Exception: Panjar Does Not Exist!'); if (!$denominasi) throw new \Exception('Custom Exception: Denominasi Does Not Exist!'); if (!$vault) throw new \Exception('Custom Exception: Vault Does Not Exist!'); if (!$deno_panjar) throw new \Exception('Custom Exception: Denominasi Panjar Does Not Exist!'); - DB::transaction(function () use ($cawangan,$deno_panjar,$panjar,$denominasi,$current,$vault,$request) { + DB::transaction(function () use ($cawangan,$deno_panjar,$panjar,$denominasi,$current,$vault,$request,$bakiperubatan) { $return_data = $this->calculation_denominasi($deno_panjar,$denominasi,'masuk'); if($return_data == 'no data') throw new \Exception('Custom Exception: Denominasi Panjar Not Return Data'); @@ -155,11 +188,8 @@ class PanjarServices 'bakieod'=>$bakiakhir )); - DenoPanjar::on('mysql7')->where('kodcaw', $this->cawangan)->where('recno', $panjar['recno'])->latest('tarikh','masa')->delete(); - Panjar::on($cawangan['mysql'])->where('recno',$panjar['recno'])->delete(); - $audit = new Audit(); - $audit->users = $request->tuntutoleh; + $audit->users = $panjar['tuntutoleh']; $audit->actions = "Keluarkan Perbelanjaan"; $audit->new_data = $panjar; $audit->kodcaw = $this->cawangan; @@ -167,10 +197,23 @@ class PanjarServices $audit->updated_at = $current; $audit->save(); + DenoPanjar::on('mysql7')->where('kodcaw', $this->cawangan)->where('recno', $panjar['recno'])->latest('tarikh','masa')->delete(); + Panjar::on($cawangan['mysql'])->where('recno',$panjar['recno'])->delete(); + + $array_response = [ + 'result' => 'success', + 'data' => 1, + 'bakiperubatan' => $totalperubatan, + ]; + }); }catch(\Exception $e){ - dd($e->getMessage()); - Log::error('Exception: ' , $e->getMessage()); + $array_response = [ + 'result' => 'error', + 'data' => $e->getMessage() + ]; + Log::error('Exception: ' . $e->getMessage()); + return $array_response; } } @@ -181,25 +224,29 @@ class PanjarServices $cawangan = Cawangan::on('mysql7')->where('kodcaw', $this->cawangan)->first(); $denominasi = Denominasi::on($cawangan['mysql'])->latest('tarikh')->first(); $vault = Vault::on($cawangan['mysql'])->latest('tarikh')->first(); - try{ if (!$denominasi) throw new \Exception('Custom Exception: Denominasi Does Not Exist!'); if (!$vault) throw new \Exception('Custom Exception: Vault Does Not Exist!'); - DB::transaction(function () use ($cawangan,$denominasi,$current,$vault,$request) { + return $response = DB::transaction(function () use ($cawangan,$denominasi,$current,$vault,$request) { + $myDateTime = DateTime::createFromFormat('Y-m-d', $request->tarikhbil); + $tarikhbil = $myDateTime->format('dmY'); + $tagmodal = $this->checkModal($request->jenismodal); + $bakiperubatan = $this->getPerubatanAmount($request->tuntutan); + $currentbaki = floatval($bakiperubatan) - floatval($request->bayaran); $panjar = Panjar::on($cawangan['mysql']) ->create([ 'tarikh'=> $current->toDateString(), 'deskripsi'=> $request->deskripsi, 'bayaran' => $request->bayaran, - 'tag' => $request->tag, - 'kategori' => $request->kategori, - 'id' => $request->id, - 'bakiperubatan' => $request->bakiperubatan, - 'nobaucer' => $request->nobaucer, - 'nobil' => $request->nobil, - 'tuntutoleh' => $request->tuntutoleh + 'tag' => $tagmodal['tag'], + 'kategori' => $tagmodal['kategori'], + 'id' => $request->kodlaluan, + 'bakiperubatan' => $currentbaki, + 'nobaucer' => $request->baucer, + 'nobil' => $tarikhbil, + 'tuntutoleh' => $request->tuntutan ]); $denopanjar = DenoPanjar::on('mysql7')->create([ @@ -207,27 +254,27 @@ class PanjarServices 'masa' => $current->toTimeString(), 'kodcaw' => $this->cawangan, 'kodlaluan' => $request->kodlaluan, - 'serahan' => $request->serahan, - 'bd1' => $request->bd1, - 'bd5' => $request->bd5, - 'bd10' => $request->bd10, - 'bd20' => $request->bd20, - 'bd50' => $request->bd50, - 'bd100' => $request->bd100, - 'txtring1' => $request->txtring1, - 'txtring5' => $request->txtring5, - 'txtring10' => $request->txtring10, - 'txtring20' => $request->txtring20, - 'txtring50' => $request->txtring50, - 'txtring100' => $request->txtring100, - 'txtring1000' => $request->txtring1000, - 'txtsen1' => $request->txtsen1, - 'txtsen5' => $request->txtsen5, - 'txtsen10' => $request->txtsen10, - 'txtsen20' => $request->txtsen20, - 'txtsen50' => $request->txtsen50, - 'jenis' =>$request->jenis, - 'recno' =>$panjar['recno'], + 'serahan' => $request->bayaran, + 'bd1' => 0, + 'bd5' => 0, + 'bd10' => 0, + 'bd20' => 0, + 'bd50' => 0, + 'bd100' => 0, + 'txtring1' => $request->ambilanring1, + 'txtring5' => $request->ambilanring5, + 'txtring10' => $request->ambilanring10, + 'txtring20' => $request->ambilanring20, + 'txtring50' => $request->ambilanring50, + 'txtring100' => $request->ambilanring100, + 'txtring1000' => 0, + 'txtsen1' => $request->ambilansen1, + 'txtsen5' => $request->ambilansen5, + 'txtsen10' => $request->ambilansen10, + 'txtsen20' => $request->ambilansen20, + 'txtsen50' => $request->ambilansen50, + 'jenis' =>$request->jenismodal, + 'recno' =>$panjar['id'], 'update' => '0' ]); @@ -297,21 +344,31 @@ class PanjarServices $audit->updated_at = $current; $audit->save(); + $array_response = [ 'result' => 'success', - 'data' => 1 + 'data' => 1, + 'bakiperubatan' => $currentbaki, ]; - return response()->json($array_response); + return $array_response; }); }catch(\Exception $e){ - dd($e->getMessage()); $array_response = [ 'result' => 'error', 'data' => $e->getMessage() ]; - return response()->json($array_response); - Log::error('Exception: ' , $e->getMessage()); + Log::error('Exception: ' . $e->getMessage()); + return $array_response; } + + return response()->json($response); + } + + public function getPerubatanAmount($tuntutanoleh){ + $cawangan = Cawangan::on('mysql7')->where('kodcaw', $this->cawangan)->first(); + $panjar = Panjar::on($cawangan['mysql'])->where('kategori','Belanja AM - Perubatan')->where('tuntutoleh',$tuntutanoleh)->sum('bayaran'); + + return $panjar; } } diff --git a/routes/web.php b/routes/web.php index c75748b..0998243 100644 --- a/routes/web.php +++ b/routes/web.php @@ -649,6 +649,9 @@ $router->group(['prefix'=>'api'], function () use ($router){ $router->post('test/updatetunai/{kodcaw}',['uses'=>'DenominasiController@test']); $router->post('test/serahantunai/{kodcaw}',['uses'=>'DenominasiController@test2']); + $router->post('test/createpanjar/{kodcaw}',['uses'=>'DenominasiController@test3']); + $router->post('test/deletepanjar/{kodcaw}',['uses'=>'DenominasiController@test4']); + }); From 24bf497d3d45565fb8df565d51f2f86adaed6aa7 Mon Sep 17 00:00:00 2001 From: Hafifie PKB Date: Wed, 6 Nov 2024 19:45:12 +0800 Subject: [PATCH 06/10] fix teller deno masuk panjar --- app/Services/Miscellaneous/PanjarServices.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/Services/Miscellaneous/PanjarServices.php b/app/Services/Miscellaneous/PanjarServices.php index 46ded2c..deafb20 100644 --- a/app/Services/Miscellaneous/PanjarServices.php +++ b/app/Services/Miscellaneous/PanjarServices.php @@ -129,7 +129,7 @@ class PanjarServices if (!$vault) throw new \Exception('Custom Exception: Vault Does Not Exist!'); if (!$deno_panjar) throw new \Exception('Custom Exception: Denominasi Panjar Does Not Exist!'); - DB::transaction(function () use ($cawangan,$deno_panjar,$panjar,$denominasi,$current,$vault,$request,$bakiperubatan) { + return DB::transaction(function () use ($cawangan,$deno_panjar,$panjar,$denominasi,$current,$vault,$totalperubatan) { $return_data = $this->calculation_denominasi($deno_panjar,$denominasi,'masuk'); if($return_data == 'no data') throw new \Exception('Custom Exception: Denominasi Panjar Not Return Data'); @@ -200,11 +200,13 @@ class PanjarServices DenoPanjar::on('mysql7')->where('kodcaw', $this->cawangan)->where('recno', $panjar['recno'])->latest('tarikh','masa')->delete(); Panjar::on($cawangan['mysql'])->where('recno',$panjar['recno'])->delete(); - $array_response = [ + return $array_response = [ 'result' => 'success', 'data' => 1, 'bakiperubatan' => $totalperubatan, - ]; + 'tuntutoleh' => $panjar['tuntutoleh'], + 'jenis' => ($panjar['kategori'] == 'Belanja AM - Perubatan') ? 'perubatan' : 'none' + ]; }); }catch(\Exception $e){ @@ -278,7 +280,7 @@ class PanjarServices 'update' => '0' ]); - $return_data = $this->calculation_denominasi($denopanjar,$denominasi,'masuk'); + $return_data = $this->calculation_denominasi($denopanjar,$denominasi,'keluar'); if($return_data == 'no data') throw new \Exception('Custom Exception: Denominasi Panjar Not Return Data'); Denominasi::on($cawangan['mysql'])->where([['tarikh','=',$current->toDateString()]])->update(array( From 494408a5cc426217f8b3ff7a1f00c5954bc648af Mon Sep 17 00:00:00 2001 From: hafifierahman Date: Fri, 8 Nov 2024 21:49:22 +0800 Subject: [PATCH 07/10] finished panjar and tunai, also added migration for recno in requestteller --- app/Http/Controllers/TunaiController.php | 9 ++++++ app/Services/CashFlow/TellerServices.php | 6 ++-- app/Services/Miscellaneous/PanjarServices.php | 14 +++++----- ...01144_add_recno_to_requestteller_table.php | 28 +++++++++++++++++++ routes/web.php | 1 + 5 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 database/migrations/2024_11_11_101144_add_recno_to_requestteller_table.php diff --git a/app/Http/Controllers/TunaiController.php b/app/Http/Controllers/TunaiController.php index 1e36f79..63902af 100644 --- a/app/Http/Controllers/TunaiController.php +++ b/app/Http/Controllers/TunaiController.php @@ -339,6 +339,15 @@ class TunaiController extends Controller return response()->json($requestteller); } + public function getRequestTellerByRecno($kodcaw,Request $request){ + $current = Carbon::now(); + $current = new Carbon(); + + $requestteller=RequestTeller::on('mysql7')->where([['kodcaw','=',$kodcaw],['update','=',1],['recno','=',$request->recno],['kodlaluan','=',$request->teller]])->get(); + + return response()->json($requestteller); + } + public function getRequestTellerLaporanSerahanBerkala($kodcaw,Request $request) { diff --git a/app/Services/CashFlow/TellerServices.php b/app/Services/CashFlow/TellerServices.php index 4535066..1219d07 100644 --- a/app/Services/CashFlow/TellerServices.php +++ b/app/Services/CashFlow/TellerServices.php @@ -177,7 +177,7 @@ class TellerServices throw new Exception('Unsuccessful Tunai'); } - AddTunai::on($cawangan['mysql'])->create([ + $addtunai = AddTunai::on($cawangan['mysql'])->create([ 'tarikh' => $current->toDateString(), 'kodcaw'=> $this->cawangan, 'kodlaluan'=>$request->teller, @@ -286,6 +286,7 @@ class TellerServices 'txtsen10' => ($request->ambilansen10) ? $request->ambilansen10 : 0, 'txtsen20' => ($request->ambilansen20) ? $request->ambilansen20 : 0, 'txtsen50' => ($request->ambilansen50) ? $request->ambilansen50 : 0, + 'recno' => $addtunai['id'] ) ); // Commit transactions @@ -324,7 +325,7 @@ class TellerServices throw new Exception('Unsuccessful Tunai'); } - AddTunai::on($cawangan['mysql'])->create([ + $addtunai = AddTunai::on($cawangan['mysql'])->create([ 'tarikh' => $current->toDateString(), 'kodcaw'=> $this->cawangan, 'kodlaluan'=>$request->teller, @@ -414,6 +415,7 @@ class TellerServices /* RequestTeller Transaction */ $requestteller = RequestTeller::on('mysql7')->where([['no','=',$request->no],['kodcaw','=',$this->cawangan],['kodlaluan','=',$request->teller],['update','=',0]])->update(array( 'update' => 1, + 'recno' => $addtunai['id'] ) ); // Commit transactions diff --git a/app/Services/Miscellaneous/PanjarServices.php b/app/Services/Miscellaneous/PanjarServices.php index deafb20..bd79ecd 100644 --- a/app/Services/Miscellaneous/PanjarServices.php +++ b/app/Services/Miscellaneous/PanjarServices.php @@ -122,14 +122,13 @@ class PanjarServices $panjar = Panjar::on($cawangan['mysql'])->latest('tarikh')->where('nobaucer', $request->nobaucer)->first(); $vault = Vault::on($cawangan['mysql'])->latest('tarikh')->first(); $deno_panjar = DenoPanjar::on('mysql7')->where('kodcaw', $this->cawangan)->where('recno', $request->recno)->latest('tarikh','masa')->first(); - $totalperubatan = floatval($this->getPerubatanAmount($panjar['tuntutoleh'])) + $panjar['bayaran']; try{ if (!$panjar) throw new \Exception('Custom Exception: Panjar Does Not Exist!'); if (!$denominasi) throw new \Exception('Custom Exception: Denominasi Does Not Exist!'); if (!$vault) throw new \Exception('Custom Exception: Vault Does Not Exist!'); if (!$deno_panjar) throw new \Exception('Custom Exception: Denominasi Panjar Does Not Exist!'); - return DB::transaction(function () use ($cawangan,$deno_panjar,$panjar,$denominasi,$current,$vault,$totalperubatan) { + return DB::transaction(function () use ($cawangan,$deno_panjar,$panjar,$denominasi,$current,$vault) { $return_data = $this->calculation_denominasi($deno_panjar,$denominasi,'masuk'); if($return_data == 'no data') throw new \Exception('Custom Exception: Denominasi Panjar Not Return Data'); @@ -200,10 +199,12 @@ class PanjarServices DenoPanjar::on('mysql7')->where('kodcaw', $this->cawangan)->where('recno', $panjar['recno'])->latest('tarikh','masa')->delete(); Panjar::on($cawangan['mysql'])->where('recno',$panjar['recno'])->delete(); + $totalperubatan = floatval($this->getPerubatanAmount($panjar['tuntutoleh'])); + return $array_response = [ 'result' => 'success', 'data' => 1, - 'bakiperubatan' => $totalperubatan, + 'totalperubatan' => $totalperubatan, 'tuntutoleh' => $panjar['tuntutoleh'], 'jenis' => ($panjar['kategori'] == 'Belanja AM - Perubatan') ? 'perubatan' : 'none' ]; @@ -235,8 +236,6 @@ class PanjarServices $myDateTime = DateTime::createFromFormat('Y-m-d', $request->tarikhbil); $tarikhbil = $myDateTime->format('dmY'); $tagmodal = $this->checkModal($request->jenismodal); - $bakiperubatan = $this->getPerubatanAmount($request->tuntutan); - $currentbaki = floatval($bakiperubatan) - floatval($request->bayaran); $panjar = Panjar::on($cawangan['mysql']) ->create([ 'tarikh'=> $current->toDateString(), @@ -245,7 +244,7 @@ class PanjarServices 'tag' => $tagmodal['tag'], 'kategori' => $tagmodal['kategori'], 'id' => $request->kodlaluan, - 'bakiperubatan' => $currentbaki, + 'bakiperubatan' => 0, 'nobaucer' => $request->baucer, 'nobil' => $tarikhbil, 'tuntutoleh' => $request->tuntutan @@ -346,11 +345,12 @@ class PanjarServices $audit->updated_at = $current; $audit->save(); + $totalperubatan = $this->getPerubatanAmount($request->tuntutan); $array_response = [ 'result' => 'success', 'data' => 1, - 'bakiperubatan' => $currentbaki, + 'totalperubatan' => $totalperubatan, ]; return $array_response; diff --git a/database/migrations/2024_11_11_101144_add_recno_to_requestteller_table.php b/database/migrations/2024_11_11_101144_add_recno_to_requestteller_table.php new file mode 100644 index 0000000..9861ce9 --- /dev/null +++ b/database/migrations/2024_11_11_101144_add_recno_to_requestteller_table.php @@ -0,0 +1,28 @@ +hasColumn('requestteller', $column); + }); + + Schema::connection('mysql7')->table('requestteller', function (Blueprint $table) use ($columns_not_exist) { + array_walk($columns_not_exist, function ($column) use ($table) { + $table->integer($column); + }); + }); + } +} diff --git a/routes/web.php b/routes/web.php index 0998243..99355fe 100644 --- a/routes/web.php +++ b/routes/web.php @@ -380,6 +380,7 @@ $router->group(['prefix'=>'api'], function () use ($router){ $router->post('requestTeller/{kodcaw}',['uses' => 'TunaiController@createRequestTeller']); $router->get('requestTeller/get/{kodcaw}',['uses' => 'TunaiController@getRequestTeller']); $router->get('requestTeller/getlaporan/{kodcaw}',['uses' => 'TunaiController@getRequestTellerLaporanSerahan']); + $router->get('requestTeller/getrekod/{kodcaw}',['uses' => 'TunaiController@getRequestTellerByRecno']); $router->get('requestTeller/getlaporanberkala/{kodcaw}',['uses' => 'TunaiController@getRequestTellerLaporanSerahanBerkala']); $router->get('requestTeller/get/{kodcaw}/date',['uses' => 'TunaiController@getRequestTellerByDate']); $router->put('requestTeller/update/{kodcaw}',['uses' => 'TunaiController@updateRequestTeller']); From 00f077544b1b59560ebcbf6420d01da22d78d791 Mon Sep 17 00:00:00 2001 From: hafifierahman Date: Sun, 10 Nov 2024 22:32:28 +0800 Subject: [PATCH 08/10] edited route test to panjar --- app/Http/Controllers/DenominasiController.php | 17 ++++++++++++----- app/Services/Miscellaneous/PanjarServices.php | 4 +++- routes/web.php | 10 +++++----- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/app/Http/Controllers/DenominasiController.php b/app/Http/Controllers/DenominasiController.php index efdcd73..3dc632c 100644 --- a/app/Http/Controllers/DenominasiController.php +++ b/app/Http/Controllers/DenominasiController.php @@ -8,39 +8,46 @@ use App\Denominasi; use App\Services\CashFlow\TellerServices; use Illuminate\Http\Request; use App\Services\Miscellaneous\PanjarServices; - +use Log; use Carbon\Carbon; class DenominasiController extends Controller { - public function test($kodcaw,Request $request){ + public function cashdeposit($kodcaw,Request $request){ $teller = new TellerServices($kodcaw); $response = $teller->CashDeposit($request); return response()->json($response); } - public function test2($kodcaw,Request $request){ + public function cashwithdraw($kodcaw,Request $request){ $teller = new TellerServices($kodcaw); $response = $teller->CashWithdrawals($request); return response()->json($response); } - public function test3($kodcaw,Request $request){ + public function createpanjar($kodcaw,Request $request){ $teller = new PanjarServices($kodcaw); $response = $teller->create($request); return response()->json($response); } - public function test4($kodcaw,Request $request){ + public function deletepanjar($kodcaw,Request $request){ $teller = new PanjarServices($kodcaw); $response = $teller->delete($request); return response()->json($response); } + public function getPerubatanAmount($kodcaw,Request $request){ + $teller = new PanjarServices($kodcaw); + $response = $teller->getPerubatanAmount($request->tuntutoleh); + + return response()->json($response); + } + public function listdenominasi($kodcaw) { $current = Carbon::now(); diff --git a/app/Services/Miscellaneous/PanjarServices.php b/app/Services/Miscellaneous/PanjarServices.php index bd79ecd..498bafc 100644 --- a/app/Services/Miscellaneous/PanjarServices.php +++ b/app/Services/Miscellaneous/PanjarServices.php @@ -368,8 +368,10 @@ class PanjarServices } public function getPerubatanAmount($tuntutanoleh){ + $current = Carbon::now(); + $cawangan = Cawangan::on('mysql7')->where('kodcaw', $this->cawangan)->first(); - $panjar = Panjar::on($cawangan['mysql'])->where('kategori','Belanja AM - Perubatan')->where('tuntutoleh',$tuntutanoleh)->sum('bayaran'); + $panjar = Panjar::on($cawangan['mysql'])->whereYear('tarikh',$current->year)->where('kategori','Belanja AM - Perubatan')->where('tuntutoleh',$tuntutanoleh)->sum('bayaran'); return $panjar; } diff --git a/routes/web.php b/routes/web.php index 99355fe..08e33c3 100644 --- a/routes/web.php +++ b/routes/web.php @@ -648,11 +648,11 @@ $router->group(['prefix'=>'api'], function () use ($router){ $router->get('/cawangan/getcawnotisall/{kodcaw}',['uses'=>'CawanganCallCenterController@getcawnotisall']); $router->get('/cawangan/bycawnotisperingatan/{kodcaw}/{notisid}',['uses'=>'CawanganCallCenterController@bycawnotisperingatan']); - $router->post('test/updatetunai/{kodcaw}',['uses'=>'DenominasiController@test']); - $router->post('test/serahantunai/{kodcaw}',['uses'=>'DenominasiController@test2']); - $router->post('test/createpanjar/{kodcaw}',['uses'=>'DenominasiController@test3']); - $router->post('test/deletepanjar/{kodcaw}',['uses'=>'DenominasiController@test4']); - + $router->post('panjar/updatetunai/{kodcaw}',['uses'=>'DenominasiController@cashdeposit']); + $router->post('panjar/serahantunai/{kodcaw}',['uses'=>'DenominasiController@cashwithdraw']); + $router->post('panjar/createpanjar/{kodcaw}',['uses'=>'DenominasiController@createpanjar']); + $router->post('panjar/deletepanjar/{kodcaw}',['uses'=>'DenominasiController@deletepanjar']); + $router->get('panjar/getperubatan/{kodcaw}',['uses'=>'DenominasiController@getPerubatanAmount']); }); From dad354f55b1abeb9a008a219221b0c51f67dc3b7 Mon Sep 17 00:00:00 2001 From: Hafifie PKB Date: Sun, 17 Nov 2024 14:07:24 +0800 Subject: [PATCH 09/10] added rekod tunai di aliran tunai --- app/Http/Controllers/TunaiController.php | 8 ++++++++ routes/web.php | 3 +++ 2 files changed, 11 insertions(+) diff --git a/app/Http/Controllers/TunaiController.php b/app/Http/Controllers/TunaiController.php index 63902af..eebdc80 100644 --- a/app/Http/Controllers/TunaiController.php +++ b/app/Http/Controllers/TunaiController.php @@ -702,4 +702,12 @@ class TunaiController extends Controller return response()->json($requestteller); } + + public function getAccStatement($kodcaw, Request $request){ + $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$kodcaw)->first(); + + $addtunai = AddTunai::on($cawangan['mysql'])->where('tarikh',$request->tarikh)->where('kodlaluan',$request->teller)->get(); + + return $addtunai; + } } diff --git a/routes/web.php b/routes/web.php index 08e33c3..b1b6696 100644 --- a/routes/web.php +++ b/routes/web.php @@ -654,6 +654,9 @@ $router->group(['prefix'=>'api'], function () use ($router){ $router->post('panjar/deletepanjar/{kodcaw}',['uses'=>'DenominasiController@deletepanjar']); $router->get('panjar/getperubatan/{kodcaw}',['uses'=>'DenominasiController@getPerubatanAmount']); + /* Endpoint for Account Statements */ + $router->get('record/accountstatement/{kodcaw}',['uses'=>'TunaiController@getAccStatement']); + }); $router->group(['prefix'=>'e-arrahn'], function () use ($router){ From 445774313840bb6026ae86658e11888392e22766 Mon Sep 17 00:00:00 2001 From: Hafifie PKB Date: Tue, 19 Nov 2024 12:40:21 +0800 Subject: [PATCH 10/10] db connection put in try catch --- app/Services/CashFlow/TellerServices.php | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/app/Services/CashFlow/TellerServices.php b/app/Services/CashFlow/TellerServices.php index 1219d07..651025e 100644 --- a/app/Services/CashFlow/TellerServices.php +++ b/app/Services/CashFlow/TellerServices.php @@ -161,12 +161,11 @@ class TellerServices $cawangan = Cawangan::on('mysql7')->where('kodcaw','=',$this->cawangan)->first(); $current = Carbon::now(); $current = new Carbon(); - - // Start transaction - DB::connection($cawangan['mysql'])->beginTransaction(); - DB::connection('mysql7')->beginTransaction(); try { + // Start transaction + DB::connection($cawangan['mysql'])->beginTransaction(); + DB::connection('mysql7')->beginTransaction(); /* Addtunai Transaction */ $response_addtunai = $this->checkAddTunai($request); @@ -310,12 +309,12 @@ class TellerServices $current = Carbon::now(); $current = new Carbon(); - // Start transaction - DB::connection($cawangan['mysql'])->beginTransaction(); - DB::connection('mysql7')->beginTransaction(); - try { + // Start transaction + DB::connection($cawangan['mysql'])->beginTransaction(); + DB::connection('mysql7')->beginTransaction(); + /* Addtunai Transaction */ $response_addtunai = $this->checkAddTunai($request);