diff --git a/app/Classes/Modules/Accounting/Processors/CreateBankStatementTransactionOwnersProcessor.php b/app/Classes/Modules/Accounting/Processors/CreateBankStatementTransactionOwnersProcessor.php index f3d61595..53f9a1d1 100644 --- a/app/Classes/Modules/Accounting/Processors/CreateBankStatementTransactionOwnersProcessor.php +++ b/app/Classes/Modules/Accounting/Processors/CreateBankStatementTransactionOwnersProcessor.php @@ -27,11 +27,11 @@ class CreateBankStatementTransactionOwnersProcessor */ public function execute() { -// $transactions = StatementTransaction::whereDoesntHave('owners', function($query){ -// return $query->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]); -// })->get(); + $transactions = StatementTransaction::whereDoesntHave('owners', function($query){ + return $query->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]); + })->get(); - $transactions = StatementTransaction::whereDoesntHave('owners')->where('amount', '<', 0)->get(); +// $transactions = StatementTransaction::whereDoesntHave('owners')->where('amount', '<', 0)->get(); foreach ($transactions as $transaction) { @@ -45,6 +45,7 @@ class CreateBankStatementTransactionOwnersProcessor 'system' => 'EXCHANGE', 'owner_type' => Transaction::class, 'owner_id'=> $creditTransaction->id, + 'owner_reference'=> $creditTransaction->owner->marking, ]); } @@ -57,6 +58,7 @@ class CreateBankStatementTransactionOwnersProcessor 'system' => 'SHIPPING_PORTAL', 'owner_type' => Transaction::class, 'owner_id'=> $creditTransaction['id'], + 'owner_reference'=> $creditTransaction['order']['reference'], ]); } @@ -68,6 +70,7 @@ class CreateBankStatementTransactionOwnersProcessor 'system' => 'EXCHANGE', 'owner_type' => Transaction::class, 'owner_id'=> $creditTransaction->id, + 'owner_reference'=> $creditTransaction->owner->owner->reference, ]); } @@ -112,6 +115,7 @@ class CreateBankStatementTransactionOwnersProcessor 'system' => 'EXCHANGE', 'owner_type' => Group::class, 'owner_id'=> $debitTransaction->id, + 'owner_reference'=> $debitTransaction->bill_no ]); } @@ -126,6 +130,7 @@ class CreateBankStatementTransactionOwnersProcessor 'system' => 'EXCHANGE', 'owner_type' => Transaction::class, 'owner_id'=> $debitTransaction->id, + 'owner_reference'=> $debitTransaction->owner->owner->marking, ]); } @@ -191,6 +196,7 @@ class CreateBankStatementTransactionOwnersProcessor 'system' => 'EXCHANGE', 'owner_type' => Transaction::class, 'owner_id' => $transaction->id, + 'owner_reference' => $transaction->reference, 'bill_no' => $transaction->bill_no ]; } @@ -201,6 +207,7 @@ class CreateBankStatementTransactionOwnersProcessor 'system' => 'EXCHANGE', 'owner_type' => Transaction::class, 'owner_id' => $transaction->id, + 'owner_reference' => $transaction->reference, 'bill_no' => $transaction->bill_no ]; } @@ -211,6 +218,7 @@ class CreateBankStatementTransactionOwnersProcessor 'system' => 'IZYIM', 'owner_type' => Transaction::class, 'owner_id' => $transaction->id, + 'owner_reference' => $transaction->reference, 'bill_no' => $transaction->bill_no ]; } @@ -242,10 +250,20 @@ class CreateBankStatementTransactionOwnersProcessor } private function getTransactionsFromShippingPortal($amount, $dateRange){ + $url = 'https://izyim.cief-malaysia.com/public/api/v1/transactions/query'; + return $this->getFromShippingPortal($amount, $dateRange, $url); + } + + private function getGroupsFromShippingPortal($amount, $dateRange){ + $url = 'https://izyim.cief-malaysia.com/public/api/v1/groups/query'; + return $this->getFromShippingPortal($amount, $dateRange, $url); + } + + private function getFromShippingPortal($amount, $dateRange, $url){ try{ $client = new \GuzzleHttp\Client(['verify' => false]); - $response = $client->request('GET', 'https://izyim.cief-malaysia.com/public/api/v1/list?api-key=510acd13d8d24375cf038ad626c282565451461a9c2399357e0b65365300787e&filters={"order_by":{"column":"id","DESC":true},"status_in":[2],"type":2,"created_after":"'.$dateRange['start_date'].'","created_before":"'.$dateRange['end_date'].'","amount_exceed":'.($amount - 0.01).',"amount_short":'.($amount + 0.01).'}'); + $response = $client->request('GET', $url.'?api-key=510acd13d8d24375cf038ad626c282565451461a9c2399357e0b65365300787e&filters={"order_by":{"column":"id","DESC":true},"status_in":[2],"type":2,"created_after":"'.$dateRange['start_date'].'","created_before":"'.$dateRange['end_date'].'","amount_exceed":'.($amount - 0.01).',"amount_short":'.($amount + 0.01).'}'); $body = $response->getBody(); $data = json_decode($body, true); $payload = $data['payload']; diff --git a/database/migrations/2023_04_07_212512_create_statement_transaction_owners_table.php b/database/migrations/2023_04_07_212512_create_statement_transaction_owners_table.php index 50d3a9c8..2ac51506 100644 --- a/database/migrations/2023_04_07_212512_create_statement_transaction_owners_table.php +++ b/database/migrations/2023_04_07_212512_create_statement_transaction_owners_table.php @@ -22,9 +22,10 @@ class CreateStatementTransactionOwnersTable extends Migration $table->string('system')->nullable(); $table->string('owner_type')->nullable(); $table->bigInteger('owner_id')->nullable(); + $table->bigInteger('owner_reference')->nullable(); $table->string('invoice_reference')->nullable(); $table->string('receipt_reference')->nullable(); - $table->string('is_auto_mapped')->default(true); + $table->string('is_auto_mapped')->default(false); $table->integer('status')->default(ApprovalStatus::PENDING_VERIFICATION); $table->foreign('statement_transaction_id')->references('id')->on('statement_transactions');