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 @@