From 96193a2880d36be14b43f7c01ae934a26385e0fa Mon Sep 17 00:00:00 2001 From: edmondlang Date: Wed, 17 May 2023 23:36:32 +0800 Subject: [PATCH 01/11] recalculate wallet balance --- .../ControllersLogic/CallbackBillplzLogic.php | 22 ++++++++- .../Services/RecalculatesWalletBalance.php | 48 +++++++++++++++++++ .../Wallets/Services/UpdatesWalletBalance.php | 11 ++++- 3 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 app/Classes/Modules/Wallets/Services/RecalculatesWalletBalance.php diff --git a/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php b/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php index a9beb2d0..7c7ed52c 100644 --- a/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php +++ b/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php @@ -25,6 +25,7 @@ use App\Classes\Modules\Transactions\Services\FetchesTransaction; use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Log; +use App\Classes\Modules\Wallets\Services\RecalculatesWalletBalance; class CallbackBillplzLogic { @@ -45,20 +46,25 @@ class CallbackBillplzLogic /** @var CreateCashBackTransactionProcessor */ private $createCashBackTransactionProcessor; + /** @var RecalculatesWalletBalance */ + private $recalculatesWalletBalance; + /** * CallbackBillplzLogic constructor. * @param GetBillplzBill $getBillplzBill * @param FetchesTransaction $fetchesTransaction * @param UpdatesTransactionStatus $updatesTransactionStatus * @param UpdatesWalletBalance $updatesWalletBalance + * @param RecalculatesWalletBalance $recalculatesWalletBalance */ - public function __construct(GetBillplzBill $getBillplzBill, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, UpdatesWalletBalance $updatesWalletBalance, CreateCashBackTransactionProcessor $createCashBackTransactionProcessor) + public function __construct(GetBillplzBill $getBillplzBill, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, UpdatesWalletBalance $updatesWalletBalance, CreateCashBackTransactionProcessor $createCashBackTransactionProcessor, RecalculatesWalletBalance $recalculatesWalletBalance) { $this->getBillplzBill = $getBillplzBill; $this->fetchesTransaction = $fetchesTransaction; $this->updatesTransactionStatus = $updatesTransactionStatus; $this->updatesWalletBalance = $updatesWalletBalance; $this->createCashBackTransactionProcessor = $createCashBackTransactionProcessor; + $this->recalculatesWalletBalance = $recalculatesWalletBalance; } @@ -104,6 +110,20 @@ class CallbackBillplzLogic // $cash_back_transaction = $this->createCashBackTransactionProcessor->execute($transaction); // } + + $wallet = null; + if ($transaction->owner instanceof Wallet) { + $wallet = $transaction->owner; + } + + if ($transaction->owner->company->wallets()->first() instanceof Wallet) { + $wallet = $transaction->owner->company->wallets()->first(); + } + + if ($wallet != null) { + $this->recalculatesWalletBalance->execute($wallet); + } + $token = Auth::fromUser(User::find(1)); $request->headers->set('Authorization', 'Bearer '.$token); diff --git a/app/Classes/Modules/Wallets/Services/RecalculatesWalletBalance.php b/app/Classes/Modules/Wallets/Services/RecalculatesWalletBalance.php new file mode 100644 index 00000000..651bee4a --- /dev/null +++ b/app/Classes/Modules/Wallets/Services/RecalculatesWalletBalance.php @@ -0,0 +1,48 @@ +updatesWalletBalance = $updatesWalletBalance; + } + /** + * @param Wallet $model + * @param $amount + * @return \Illuminate\Database\Eloquent\Model + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function execute(Wallet $wallet) + { + + $i = 0; + $topups = 0; + $credit = 0; + $payments = 0; + $debit = 0; + + foreach ($wallet->transactions as $transaction) { + if (!in_array((int) $transaction->status, [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])) continue; + if ((int) $transaction->type === TransactionType::TOP_UP) { + $topups += (float) $transaction->amount; + } + if ((int) $transaction->type === TransactionType::CREDIT_NOTE) $credit += (float) $transaction->amount; + if ((int) $transaction->type === TransactionType::PAYMENT) $payments += (float) $transaction->amount; + if ((int) $transaction->type === TransactionType::DEBIT_NOTE) $debit += (float) $transaction->amount; + } + $auditBalance = ($topups + $credit) - ($payments + $debit); + + return $auditBalance; + } +} diff --git a/app/Classes/Modules/Wallets/Services/UpdatesWalletBalance.php b/app/Classes/Modules/Wallets/Services/UpdatesWalletBalance.php index a724cf24..a94fd9a8 100644 --- a/app/Classes/Modules/Wallets/Services/UpdatesWalletBalance.php +++ b/app/Classes/Modules/Wallets/Services/UpdatesWalletBalance.php @@ -10,6 +10,13 @@ use App\Models\Company; class UpdatesWalletBalance extends AbstractUpdateRecord { + private $recalculatesWalletBalance; + + public function __construct(RecalculatesWalletBalance $recalculatesWalletBalance) + { + $this->recalculatesWalletBalance = $recalculatesWalletBalance; + } + /** * @param Wallet $model * @param $amount @@ -18,7 +25,9 @@ class UpdatesWalletBalance extends AbstractUpdateRecord */ public function execute(Wallet $model, $amount) { - $model->amount = $model->amount + $amount; + $auditBalance = $this->recalculatesWalletBalance->execute($model); + + $model->amount = $auditBalance; return $this->handler($model); } From d5b04b9b8111f34f25344f8f37c6baedf89cfcc2 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Wed, 17 May 2023 23:44:49 +0800 Subject: [PATCH 02/11] AuditAndUpdateWallletBalance --- .../Commands/AuditAndUpdateWallletBalance.php | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 app/Console/Commands/AuditAndUpdateWallletBalance.php diff --git a/app/Console/Commands/AuditAndUpdateWallletBalance.php b/app/Console/Commands/AuditAndUpdateWallletBalance.php new file mode 100644 index 00000000..453c39be --- /dev/null +++ b/app/Console/Commands/AuditAndUpdateWallletBalance.php @@ -0,0 +1,77 @@ +removesCompanyFromSegment = $removesCompanyFromSegment; + } + + /** + * Execute the console command. + * + * @return int + */ + public function handle() + { + $wallets = Wallet::all(); + + $i = 0; + foreach ($wallets as $wallet) { + $topups = 0; + $credit = 0; + $payments = 0; + $debit = 0; + + foreach ($wallet->transactions as $transaction) { + if (!in_array((int) $transaction->status, [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])) continue; + if ((int) $transaction->type === TransactionType::TOP_UP) { + $topups += (float) $transaction->amount; + } + if ((int) $transaction->type === TransactionType::CREDIT_NOTE) $credit += (float) $transaction->amount; + if ((int) $transaction->type === TransactionType::PAYMENT) $payments += (float) $transaction->amount; + if ((int) $transaction->type === TransactionType::DEBIT_NOTE) $debit += (float) $transaction->amount; + } + $auditBalance = ($topups + $credit) - ($payments + $debit); + $diffenrence = round((float) $wallet->amount - (($topups + $credit) - ($payments + $debit)), 2); + if ((($diffenrence == 0) || ($diffenrence == -0)) and $wallet->amount > -0.01) continue; + + $i++; + + $this->info($i . ". Marking: " . $wallet->owner->reference . "(" . $wallet->id . ")" . PHP_EOL . "Current Balance: " . $wallet->amount . PHP_EOL . "Audit Balance: " . ($auditBalance) . PHP_EOL . "Difference: " . $diffenrence . PHP_EOL); + } + } +} From 43a9bf6742418a4f9f505b3fb869086b589d955f Mon Sep 17 00:00:00 2001 From: edmondlang Date: Wed, 17 May 2023 23:49:32 +0800 Subject: [PATCH 03/11] AuditAndUpdateWallletBalance --- app/Console/Commands/AuditAndUpdateWallletBalance.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/Console/Commands/AuditAndUpdateWallletBalance.php b/app/Console/Commands/AuditAndUpdateWallletBalance.php index 453c39be..0dd1be05 100644 --- a/app/Console/Commands/AuditAndUpdateWallletBalance.php +++ b/app/Console/Commands/AuditAndUpdateWallletBalance.php @@ -72,6 +72,8 @@ class AuditAndUpdateWallletBalance extends Command $i++; $this->info($i . ". Marking: " . $wallet->owner->reference . "(" . $wallet->id . ")" . PHP_EOL . "Current Balance: " . $wallet->amount . PHP_EOL . "Audit Balance: " . ($auditBalance) . PHP_EOL . "Difference: " . $diffenrence . PHP_EOL); + + Wallet::where('id', $wallet->id)->update(['amount' => $auditBalance]); } } } From 35edc807a8adf2731f04fd23a8df102c4219e4fc Mon Sep 17 00:00:00 2001 From: edmondlang Date: Thu, 18 May 2023 00:07:20 +0800 Subject: [PATCH 04/11] recalculate wallet balance --- .../ControllersLogic/CallbackBillplzLogic.php | 8 ++++---- .../ControllersLogic/CreateBookingPaymentLogic.php | 11 +++++++++-- .../Modules/Wallets/Services/UpdatesWalletBalance.php | 11 +---------- 3 files changed, 14 insertions(+), 16 deletions(-) diff --git a/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php b/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php index 7c7ed52c..bcaa57a7 100644 --- a/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php +++ b/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php @@ -114,14 +114,14 @@ class CallbackBillplzLogic $wallet = null; if ($transaction->owner instanceof Wallet) { $wallet = $transaction->owner; - } - - if ($transaction->owner->company->wallets()->first() instanceof Wallet) { + } else if ($transaction->owner->company->wallets()->first() instanceof Wallet) { $wallet = $transaction->owner->company->wallets()->first(); } if ($wallet != null) { - $this->recalculatesWalletBalance->execute($wallet); + $walletBalance = $this->recalculatesWalletBalance->execute($wallet); + + $this->updatesWalletBalance->execute($wallet, $walletBalance); } $token = Auth::fromUser(User::find(1)); diff --git a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingPaymentLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingPaymentLogic.php index 1140ecd9..77d8252d 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingPaymentLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingPaymentLogic.php @@ -29,6 +29,7 @@ use App\Models\Wallet; use Carbon\Carbon; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use App\Classes\Modules\Wallets\Services\RecalculatesWalletBalance; class CreateBookingPaymentLogic extends AbstractControllerLogic { @@ -70,6 +71,9 @@ class CreateBookingPaymentLogic extends AbstractControllerLogic /** @var CreateCashBackTransactionProcessor */ private $createCashBackTransactionProcessor; + /** @var RecalculatesWalletBalance */ + private $recalculatesWalletBalance; + /** * CreateBookingPaymentLogic constructor. * @param FetchesBookingQuotation $fetchBookingQuotation @@ -81,8 +85,9 @@ class CreateBookingPaymentLogic extends AbstractControllerLogic * @param UpdatesWalletBalance $updatesWalletBalance * @param UpdatesTransactionStatus $updatesTransactionStatus * @param CreateCashBackTransactionProcessor $createCashBackTransactionProcessor + * @param RecalculatesWalletBalance $recalculatesWalletBalance */ - public function __construct(FetchesBookingQuotation $fetchBookingQuotation, FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesTransaction $createsTransaction, CalculatesBookingOutstanding $calculatesBookingOutstanding, CreatesBillplzBill $createsBillplzBill, UpdatesWalletBalance $updatesWalletBalance, UpdatesTransactionStatus $updatesTransactionStatus, CreateCashBackTransactionProcessor $createCashBackTransactionProcessor) + public function __construct(FetchesBookingQuotation $fetchBookingQuotation, FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesTransaction $createsTransaction, CalculatesBookingOutstanding $calculatesBookingOutstanding, CreatesBillplzBill $createsBillplzBill, UpdatesWalletBalance $updatesWalletBalance, UpdatesTransactionStatus $updatesTransactionStatus, CreateCashBackTransactionProcessor $createCashBackTransactionProcessor, RecalculatesWalletBalance $recalculatesWalletBalance) { $this->fetchBookingQuotation = $fetchBookingQuotation; $this->fetchesCompanyPaymentAttemptLimit = $fetchesCompanyPaymentAttemptLimit; @@ -93,6 +98,7 @@ class CreateBookingPaymentLogic extends AbstractControllerLogic $this->updatesWalletBalance = $updatesWalletBalance; $this->updatesTransactionStatus = $updatesTransactionStatus; $this->createCashBackTransactionProcessor = $createCashBackTransactionProcessor; + $this->recalculatesWalletBalance = $recalculatesWalletBalance; } /** @@ -138,7 +144,8 @@ class CreateBookingPaymentLogic extends AbstractControllerLogic $paymentReference = $billNumber; - $this->updatesWalletBalance->execute($wallet, ($amount * -1)); + $walletBalance = $this->recalculatesWalletBalance->execute($wallet); + $this->updatesWalletBalance->execute($wallet, $walletBalance); } $billNumber = $this->generatesTransactionBillNumber->execute('PYMT-'); diff --git a/app/Classes/Modules/Wallets/Services/UpdatesWalletBalance.php b/app/Classes/Modules/Wallets/Services/UpdatesWalletBalance.php index a94fd9a8..a724cf24 100644 --- a/app/Classes/Modules/Wallets/Services/UpdatesWalletBalance.php +++ b/app/Classes/Modules/Wallets/Services/UpdatesWalletBalance.php @@ -10,13 +10,6 @@ use App\Models\Company; class UpdatesWalletBalance extends AbstractUpdateRecord { - private $recalculatesWalletBalance; - - public function __construct(RecalculatesWalletBalance $recalculatesWalletBalance) - { - $this->recalculatesWalletBalance = $recalculatesWalletBalance; - } - /** * @param Wallet $model * @param $amount @@ -25,9 +18,7 @@ class UpdatesWalletBalance extends AbstractUpdateRecord */ public function execute(Wallet $model, $amount) { - $auditBalance = $this->recalculatesWalletBalance->execute($model); - - $model->amount = $auditBalance; + $model->amount = $model->amount + $amount; return $this->handler($model); } From b452cf0027e30f93937ffa548a222d7e3456fb91 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Thu, 18 May 2023 19:22:58 +0800 Subject: [PATCH 05/11] recalculate wallet balance --- .../ControllersLogic/CallbackBillplzLogic.php | 21 +++------------ .../Wallets/Services/UpdatesWalletBalance.php | 27 ++++++++++++++----- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php b/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php index bcaa57a7..186ef3b6 100644 --- a/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php +++ b/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php @@ -98,32 +98,17 @@ class CallbackBillplzLogic } if($transaction->status !== ApprovalStatus::COMPLETED && $transaction->status !== ApprovalStatus::APPROVED){ - - if($transaction->owner instanceof Wallet && $transaction->status !== ApprovalStatus::APPROVED && $status === ApprovalStatus::APPROVED) { - $this->updatesWalletBalance->execute($transaction->owner, $transaction->amount); - } $this->updatesTransactionStatus->execute($transaction, $status); + } + if($transaction->owner instanceof Wallet) { + $this->updatesWalletBalance->execute($transaction->owner, $transaction->amount); } // if ($transaction->type == TransactionType::PAYMENT) { // $cash_back_transaction = $this->createCashBackTransactionProcessor->execute($transaction); // } - - $wallet = null; - if ($transaction->owner instanceof Wallet) { - $wallet = $transaction->owner; - } else if ($transaction->owner->company->wallets()->first() instanceof Wallet) { - $wallet = $transaction->owner->company->wallets()->first(); - } - - if ($wallet != null) { - $walletBalance = $this->recalculatesWalletBalance->execute($wallet); - - $this->updatesWalletBalance->execute($wallet, $walletBalance); - } - $token = Auth::fromUser(User::find(1)); $request->headers->set('Authorization', 'Bearer '.$token); diff --git a/app/Classes/Modules/Wallets/Services/UpdatesWalletBalance.php b/app/Classes/Modules/Wallets/Services/UpdatesWalletBalance.php index a724cf24..5b384272 100644 --- a/app/Classes/Modules/Wallets/Services/UpdatesWalletBalance.php +++ b/app/Classes/Modules/Wallets/Services/UpdatesWalletBalance.php @@ -3,10 +3,10 @@ namespace App\Classes\Modules\Wallets\Services; use App\Classes\General\Eloquent\AbstractUpdateRecord; -use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord; -use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject; +use App\Classes\ValueObjects\Constants\ApprovalStatus; +use App\Classes\ValueObjects\Constants\TransactionType; use App\Models\Wallet; -use App\Models\Company; +use Illuminate\Support\Facades\Log; class UpdatesWalletBalance extends AbstractUpdateRecord { @@ -16,10 +16,25 @@ class UpdatesWalletBalance extends AbstractUpdateRecord * @return \Illuminate\Database\Eloquent\Model * @throws \App\Classes\Exceptions\MalformedRequestException */ - public function execute(Wallet $model, $amount) { + public function execute(Wallet $model, $amount) + { + $i = 0; + $topups = 0; + $credit = 0; + $payments = 0; + $debit = 0; - $model->amount = $model->amount + $amount; + foreach ($model->transactions as $transaction) { + Log::debug($transaction); + if (!in_array((int) $transaction->status, [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])) continue; + if ((int) $transaction->type === TransactionType::TOP_UP) $topups += (float) $transaction->amount; + if ((int) $transaction->type === TransactionType::CREDIT_NOTE) $credit += (float) $transaction->amount; + if ((int) $transaction->type === TransactionType::PAYMENT) $payments += (float) $transaction->amount; + if ((int) $transaction->type === TransactionType::DEBIT_NOTE) $debit += (float) $transaction->amount; + } + $auditBalance = ($topups + $credit) - ($payments + $debit); + + $model->amount = $auditBalance; return $this->handler($model); - } } From 27509f59371b8c5528303dc772851e7c4359f7dd Mon Sep 17 00:00:00 2001 From: edmondlang Date: Thu, 18 May 2023 19:31:51 +0800 Subject: [PATCH 06/11] recalculate wallet balance --- app/Classes/Modules/Wallets/Services/UpdatesWalletBalance.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/app/Classes/Modules/Wallets/Services/UpdatesWalletBalance.php b/app/Classes/Modules/Wallets/Services/UpdatesWalletBalance.php index 5b384272..4812660a 100644 --- a/app/Classes/Modules/Wallets/Services/UpdatesWalletBalance.php +++ b/app/Classes/Modules/Wallets/Services/UpdatesWalletBalance.php @@ -6,7 +6,6 @@ use App\Classes\General\Eloquent\AbstractUpdateRecord; use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Classes\ValueObjects\Constants\TransactionType; use App\Models\Wallet; -use Illuminate\Support\Facades\Log; class UpdatesWalletBalance extends AbstractUpdateRecord { @@ -25,7 +24,6 @@ class UpdatesWalletBalance extends AbstractUpdateRecord $debit = 0; foreach ($model->transactions as $transaction) { - Log::debug($transaction); if (!in_array((int) $transaction->status, [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])) continue; if ((int) $transaction->type === TransactionType::TOP_UP) $topups += (float) $transaction->amount; if ((int) $transaction->type === TransactionType::CREDIT_NOTE) $credit += (float) $transaction->amount; From 1f105421a121a5406bd1d68b3498d6513751f962 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Tue, 30 May 2023 12:32:29 +0800 Subject: [PATCH 07/11] xpo 04-2023 --- .../Bookings/ControllersLogic/AutoPurchaseOrderFillLogic.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Classes/Modules/Bookings/ControllersLogic/AutoPurchaseOrderFillLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/AutoPurchaseOrderFillLogic.php index bc837878..617691e8 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/AutoPurchaseOrderFillLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/AutoPurchaseOrderFillLogic.php @@ -65,7 +65,7 @@ class AutoPurchaseOrderFillLogic extends AbstractControllerLogic public function logic(Request $request) : JsonResponse { $bookings = Booking::where('service_id', '!=', 4)->where(function($query){ - return $query->whereMonth('created_at', '<', 03)->whereYear('created_at', 2023); + return $query->whereMonth('created_at', '=', 04)->whereYear('created_at', 2023); })->whereDoesntHave('transactions', function($q){ $q->where('type', TransactionType::PURCHASE_ORDER); $q->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED]); From 839cce332081e28b741b843fbf72764637ea8480 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Tue, 30 May 2023 18:09:20 +0800 Subject: [PATCH 08/11] honey trap changes --- .../Imports/ImportHoneyTrapController.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Imports/ImportHoneyTrapController.php b/app/Http/Controllers/Imports/ImportHoneyTrapController.php index 81ef237b..fda686f4 100644 --- a/app/Http/Controllers/Imports/ImportHoneyTrapController.php +++ b/app/Http/Controllers/Imports/ImportHoneyTrapController.php @@ -33,9 +33,18 @@ class ImportHoneyTrapController $excelRows = $import->rows; $excelRows = $excelRows->toArray(); - $returnArray = []; + $returnArray = []; + $segment_name = 'honey trap campaign'; + $segment = Segment::where('name', $segment_name)->first(); - $segment_id = Segment::where('name', 'honey trap platinum')->first()->id; + if (!$segment) { + $row['status'] = 'Failed'; + $row['message'] = '"' . $segment_name . '"' . ' not found'; + $returnArray[] = $row; + return response()->json($returnArray); + } + + $segment_id = $segment->id; foreach ($excelRows as $row) { From f37d775e97e536ce312d722b7f2cf6e7dc7a4a6d Mon Sep 17 00:00:00 2001 From: edmondlang Date: Tue, 30 May 2023 19:06:28 +0800 Subject: [PATCH 09/11] honey trap changes --- app/Http/Controllers/Imports/ImportHoneyTrapController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Imports/ImportHoneyTrapController.php b/app/Http/Controllers/Imports/ImportHoneyTrapController.php index fda686f4..f19cbcd4 100644 --- a/app/Http/Controllers/Imports/ImportHoneyTrapController.php +++ b/app/Http/Controllers/Imports/ImportHoneyTrapController.php @@ -120,6 +120,6 @@ class ImportHoneyTrapController { $unixTime = (($date - 25569) * 86400); $date = new DateTime("@$unixTime"); - return $date->format('d/m/Y'); + return $date->format('Y-m-d'); // Change the format to 'Y-m-d' } } From 4bd28e3ccad9cb08a385a66d3249a058be9cd803 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Tue, 30 May 2023 19:38:45 +0800 Subject: [PATCH 10/11] add company id in support --- resources/views/pages/customer_support.blade.php | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/views/pages/customer_support.blade.php b/resources/views/pages/customer_support.blade.php index bebb4a15..dbb0885b 100644 --- a/resources/views/pages/customer_support.blade.php +++ b/resources/views/pages/customer_support.blade.php @@ -36,6 +36,7 @@ @endphp

Customer Account

+

Company Id: {{$company->id}}

Marking: {{$company->reference}}

Account Type: {{$company->type === 1 ? 'Business' : 'Personal'}}

@if($company->type === 1)

Company's Name: {{$company->name}}

@endif From 77f533111fc2ff20ee3ca544418f41e81a998d67 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Sat, 3 Jun 2023 23:13:26 +0800 Subject: [PATCH 11/11] accounting mapping api files and calling api, api need to be updated --- .../UpdateBankStatementDetailLogic.php | 82 +++++++-------- .../Processors/ChecksBillNumber.php | 45 +++++++++ .../ImportStatementInvoiceController.php | 99 +++++++++++++++++++ .../ImportStatementReceiptsController.php | 50 ++++++++++ .../sections/TransactionsMappingComponent.vue | 83 ++++++++++++---- routes/api.php | 2 + 6 files changed, 305 insertions(+), 56 deletions(-) create mode 100644 app/Classes/Modules/Accounting/Processors/ChecksBillNumber.php create mode 100644 app/Http/Controllers/Imports/ImportStatementInvoiceController.php create mode 100644 app/Http/Controllers/Imports/ImportStatementReceiptsController.php diff --git a/app/Classes/Modules/Accounting/ControllersLogic/UpdateBankStatementDetailLogic.php b/app/Classes/Modules/Accounting/ControllersLogic/UpdateBankStatementDetailLogic.php index 73221f53..e9a14323 100644 --- a/app/Classes/Modules/Accounting/ControllersLogic/UpdateBankStatementDetailLogic.php +++ b/app/Classes/Modules/Accounting/ControllersLogic/UpdateBankStatementDetailLogic.php @@ -7,14 +7,11 @@ use App\Classes\Exceptions\MalformedRequestException; use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Accounting\Services\UpdatesBankStatementDetails; use App\Classes\Modules\Accounting\Services\FetchesBankStatementDetails; -use App\Classes\Modules\Accounting\Standards\Rules\CanUpdateCompany; -use App\Classes\Modules\Accounting\DataTransferObjects\BankStatementDetailObject; -use App\Classes\Modules\Accounting\DataTransferObjects\BankStatementTransactionObject; -use App\Http\Resources\BankStatementDetailResource; use App\Classes\Modules\Accounting\Services\CreatesBankStatementTransactionOwner; use App\Classes\Modules\Accounting\Services\FetchesBankStatementTransaction; use App\Classes\ValueObjects\Constants\StatementTransactionOwnerType; use App\Classes\ValueObjects\Constants\SystemType; +use App\Classes\Modules\Accounting\Processors\ChecksBillNumber; use App\Models\Transaction; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -49,19 +46,24 @@ class UpdateBankStatementDetailLogic extends AbstractControllerLogic /** @var CreatesBankStatementTransactionOwner */ private $createsBankStatementTransactionOwner; + /** @var ChecksBillNumber */ + private $checksBillNumber; + /** * UpdateBankStatementDetailLogic constructor. * @param UpdatesBankStatementDetails $updatesBankStatementDetails * @param FetchesBankStatementDetails $fetchesBankStatementDetails * @param fetchesBankStatementTransaction $fetchesBankStatementTransaction * @param CreatesBankStatementTransactionOwner $createsBankStatementTransactionOwner + * @param ChecksBillNumber $checksBillNumber */ - public function __construct(UpdatesBankStatementDetails $updatesBankStatementDetails, FetchesBankStatementDetails $fetchesBankStatementDetails, FetchesBankStatementTransaction $fetchesBankStatementTransaction, CreatesBankStatementTransactionOwner $createsBankStatementTransactionOwner) + public function __construct(UpdatesBankStatementDetails $updatesBankStatementDetails, FetchesBankStatementDetails $fetchesBankStatementDetails, FetchesBankStatementTransaction $fetchesBankStatementTransaction, CreatesBankStatementTransactionOwner $createsBankStatementTransactionOwner, ChecksBillNumber $checksBillNumber) { $this->updatesBankStatementDetails = $updatesBankStatementDetails; $this->fetchesBankStatementDetails = $fetchesBankStatementDetails; $this->fetchesBankStatementTransaction = $fetchesBankStatementTransaction; $this->createsBankStatementTransactionOwner = $createsBankStatementTransactionOwner; + $this->checksBillNumber = $checksBillNumber; } @@ -83,7 +85,8 @@ class UpdateBankStatementDetailLogic extends AbstractControllerLogic switch ($request->input('pay_for')) { case 'sales': if (in_array($request->input('system_references'), ['exchange', 'izyim'])) { - $transaction = $this->verifyBillNumber($request->input('transaction_reference'), $request->input('system_references')); + // $transaction = $this->verifyBillNumber($request->input('transaction_reference'), $request->input('system_references')); + $transaction = $this->checksBillNumber->execute($request->input('transaction_reference'), $request->input('system_references')); // todo-new: update / test on izyim system @@ -117,7 +120,8 @@ class UpdateBankStatementDetailLogic extends AbstractControllerLogic case 'top_up': - $transaction = $this->verifyBillNumber($request->input('transaction_reference'), $request->input('system_references')); + // $transaction = $this->verifyBillNumber($request->input('transaction_reference'), $request->input('system_references')); + $transaction = $this->checksBillNumber->execute($request->input('transaction_reference'), $request->input('system_references')); $owner_type = Transaction::class; $owner_id = $transaction->id; @@ -174,38 +178,38 @@ class UpdateBankStatementDetailLogic extends AbstractControllerLogic // return $this->resourceResponse(new BankStatementDetailResource($query)); } - public function verifyBillNumber($bill_no, $system_reference) - { - if ($system_reference == 'izyim') { - try { - $url = 'https://izyim.cief-malaysia.com/public/api/v1/transactions/query'; - $client = new \GuzzleHttp\Client(['verify' => false]); - $response = $client->request('GET', $url . '?api-key=510acd13d8d24375cf038ad626c282565451461a9c2399357e0b65365300787e&filters={"bill_no":' . $bill_no . '}'); - $body = $response->getBody(); - $data = json_decode($body, true); - dd($data); - $payload = $data['payload']; - $transactions2 = $payload['data']; - dd($transactions2); - return $transactions2; - } catch (\Exception $exception) { - Log::error($exception); - dd($exception); - preg_match('/\{.*\}/s', $exception->getMessage(), $matches); - $jsonError = json_decode($matches[0]); - // Retrieved Transactions failed - throw new MalformedRequestException($jsonError->title); - } - } + // public function verifyBillNumber($bill_no, $system_reference) + // { + // if ($system_reference == 'izyim') { + // try { + // $url = 'https://izyim.cief-malaysia.com/public/api/v1/transactions/query'; + // $client = new \GuzzleHttp\Client(['verify' => false]); + // $response = $client->request('GET', $url . '?api-key=510acd13d8d24375cf038ad626c282565451461a9c2399357e0b65365300787e&filters={"bill_no":' . $bill_no . '}'); + // $body = $response->getBody(); + // $data = json_decode($body, true); + // dd($data); + // $payload = $data['payload']; + // $transactions2 = $payload['data']; + // dd($transactions2); + // return $transactions2; + // } catch (\Exception $exception) { + // Log::error($exception); + // dd($exception); + // preg_match('/\{.*\}/s', $exception->getMessage(), $matches); + // $jsonError = json_decode($matches[0]); + // // Retrieved Transactions failed + // throw new MalformedRequestException($jsonError->title); + // } + // } - if ($system_reference == 'exchange') { - $transaction = Transaction::where('bill_no', $bill_no)->first(); - if ($transaction) { - return $transaction; - } - } + // if ($system_reference == 'exchange') { + // $transaction = Transaction::where('bill_no', $bill_no)->first(); + // if ($transaction) { + // return $transaction; + // } + // } - // if not found - throw new MalformedRequestException('Bill Number Not Found.'); - } + // // if not found + // throw new MalformedRequestException('Bill Number Not Found.'); + // } } diff --git a/app/Classes/Modules/Accounting/Processors/ChecksBillNumber.php b/app/Classes/Modules/Accounting/Processors/ChecksBillNumber.php new file mode 100644 index 00000000..ddaa55c3 --- /dev/null +++ b/app/Classes/Modules/Accounting/Processors/ChecksBillNumber.php @@ -0,0 +1,45 @@ + false]); + $response = $client->request('GET', $url . '?api-key=510acd13d8d24375cf038ad626c282565451461a9c2399357e0b65365300787e&filters={"bill_no":' . $bill_no . '}'); + $body = $response->getBody(); + $data = json_decode($body, true); + dd($data); + $payload = $data['payload']; + $transactions2 = $payload['data']; + dd($transactions2); + return $transactions2; + } catch (\Exception $exception) { + Log::error($exception); + dd($exception); + preg_match('/\{.*\}/s', $exception->getMessage(), $matches); + $jsonError = json_decode($matches[0]); + // Retrieved Transactions failed + throw new MalformedRequestException($jsonError->title); + } + } + + if ($system_reference == 'exchange') { + $transaction = Transaction::where('bill_no', $bill_no)->first(); + if ($transaction) { + return $transaction; + } + } + + // if not found + throw new MalformedRequestException('Bill Number Not Found.'); + } +} diff --git a/app/Http/Controllers/Imports/ImportStatementInvoiceController.php b/app/Http/Controllers/Imports/ImportStatementInvoiceController.php new file mode 100644 index 00000000..a59f9463 --- /dev/null +++ b/app/Http/Controllers/Imports/ImportStatementInvoiceController.php @@ -0,0 +1,99 @@ +input('files'), '', ApprovalStatus::APPROVED, 'imports'); + $file = json_decode($object->getFiles()[0])->file_info->original->file; + + $import = new GenericImport(); + Excel::import($import, $file); + $excelRows = $import->rows; + $excelRows = $excelRows->toArray(); + + foreach ($excelRows as $row) { + dd($row); + // $row['debtor_code'] + + // attempt 1 - try map by amount and date + // $transactionDate = $this->changeExcelDate($row['date']); + // $transaction = Transaction::where('original_amount', $row['total'])->whereDate('created_at', $transactionDate)->get(); + // if ($transaction) { + // // check company + // // $company = Company::where('debtor', $row['debtor_code'])->first(); + // // dd($company); + // // try to verify is it the correct transaction + // } + + // Shipping Info + // TOPUP -> map with transaction.bill_no + if (str_starts_with($row['shipping_info'], 'TOPUP')) { + // find in exchange first, if cannont then find in izyim + // (App()->make(ChecksBillNumber::class))->execute($bill_no, 'exchange'); + } + + // if 5 digits -> exchange booking reference + // find transation + // find statement_transaction_owners, and fill up the details + + // if <5 digits, find the transaction id (order number in izyim), find the payment in izyim + // find transation + // find statement_transaction_owners, and fill up the details + + // dd([ + // 'type' => $statementTransactionOwnerType, + // 'system' => $system, + // // 'owner_type' => Transaction::class, + // // todo-new: make sure owner_type is a class + // 'owner_type' => $owner_type, + // 'owner_id' => $owner_id, + // 'owner_reference' => $owner_reference + // ]); + + // $bankStatementTransaction->owners()->firstOrCreate([ + // 'type' => $statementTransactionOwnerType, + // 'system' => $system, + // // 'owner_type' => Transaction::class, + // // todo-new: make sure owner_type is a class + // 'owner_type' => $owner_type, + // 'owner_id' => $owner_id, + // 'owner_reference' => $owner_reference + // ]); + + + } + } + + public function changeExcelDate($date) + { + $unixTime = (($date - 25569) * 86400); + $date = new DateTime("@$unixTime"); + return $date->format('Y-m-d'); // Change the format to 'Y-m-d' + } +} diff --git a/app/Http/Controllers/Imports/ImportStatementReceiptsController.php b/app/Http/Controllers/Imports/ImportStatementReceiptsController.php new file mode 100644 index 00000000..22111881 --- /dev/null +++ b/app/Http/Controllers/Imports/ImportStatementReceiptsController.php @@ -0,0 +1,50 @@ +input('files'), '', ApprovalStatus::APPROVED, 'imports'); + $file = json_decode($object->getFiles()[0])->file_info->original->file; + + $import = new GenericImport(); + Excel::import($import, $file); + $excelRows = $import->rows; + $excelRows = $excelRows->toArray(); + + foreach ($excelRows as $row) { + // if has date column + // $transactionDate = $this->changeExcelDate($row['date']); + } + } + + public function changeExcelDate($date) + { + $unixTime = (($date - 25569) * 86400); + $date = new DateTime("@$unixTime"); + return $date->format('Y-m-d'); // Change the format to 'Y-m-d' + } +} diff --git a/resources/assets/vue/components/accounting/sections/TransactionsMappingComponent.vue b/resources/assets/vue/components/accounting/sections/TransactionsMappingComponent.vue index c35db4bd..a29a4066 100644 --- a/resources/assets/vue/components/accounting/sections/TransactionsMappingComponent.vue +++ b/resources/assets/vue/components/accounting/sections/TransactionsMappingComponent.vue @@ -55,16 +55,16 @@
X
-
+
Approve all the Mapping Below
-
- +
@@ -105,10 +105,18 @@
Export Invoices To AutoCount
-
+
- -
Import Invoices
+
+
+ + + +
+
+
Import Invoices
+
Nest Step
@@ -116,10 +124,18 @@
Export Receipts To AutoCount
-
+
- -
Import Receipts
+
+
+ + + +
+
+
Import Receipts
+
Nest Step
@@ -133,7 +149,12 @@