mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-22 14:04:01 +00:00
import ambank and cief lite statement
This commit is contained in:
@@ -0,0 +1,225 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Accounting\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Models\AccountStatement;
|
||||
use App\Models\StatementAccount;
|
||||
use App\Models\StatementTransaction;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
class ImportAmbankStatementLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Import Ambank Statement Transactions Details',
|
||||
'message' => 'You have successfully updated the Ambank Statement Transactions Details'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
|
||||
$object = new DocumentObject('', $request->input('files'), '', ApprovalStatus::APPROVED, 'imports');
|
||||
|
||||
foreach ($object->getFiles() as $file){
|
||||
$collection = Excel::toCollection(null, json_decode($file)->file_info->original->file, null, null, true);
|
||||
|
||||
$statementDetails = $collection->first();
|
||||
|
||||
$statementDateRange = trim(explode(':', $statementDetails[3][0])[1]);
|
||||
$dateFrom = trim(explode('-', $statementDateRange)[0]);
|
||||
$dateTo = trim(explode('-', $statementDateRange)[1]);
|
||||
$dateFrom = carbon::createFromFormat('d/m/Y', $dateFrom);
|
||||
$dateTo = carbon::createFromFormat('d/m/Y', $dateTo);
|
||||
$dateTo = carbon::parse($dateTo);
|
||||
$totalDebit = $statementDetails[7][7];
|
||||
$totalCredit = $statementDetails[8][7];
|
||||
$totalTransactions = $totalDebit + $totalCredit;
|
||||
$beginBalance = ((float) str_replace(',', '', $statementDetails[6][10]));
|
||||
$endBalance = ((float) str_replace(',', '', $statementDetails[9][10]));
|
||||
|
||||
$account = StatementAccount::where('number', 8881040198515)->first();
|
||||
|
||||
if (!$account) {
|
||||
throw new Exception("Statement Account for CIEF LITE not found.");
|
||||
}
|
||||
|
||||
$statement = AccountStatement::whereDate('date_from', $dateFrom)
|
||||
->whereDate('date_to', $dateTo)
|
||||
->where('total_amount', $totalTransactions)
|
||||
->where('begin_balance', $beginBalance)
|
||||
->where('end_balance', $endBalance)
|
||||
->first();
|
||||
|
||||
|
||||
if(!$statement){
|
||||
$statement = new AccountStatement([
|
||||
'date_from' => $dateFrom,
|
||||
'date_to' => $dateTo,
|
||||
'total_amount' => $totalTransactions,
|
||||
'begin_balance' => $beginBalance,
|
||||
'end_balance' => $endBalance,
|
||||
]);
|
||||
}
|
||||
|
||||
$account->statements()->save($statement);
|
||||
|
||||
$collection->map(function ($sheet, $key) use ($statement) {
|
||||
if ($key === 0) {
|
||||
$sheet->slice(13)->map(function ($row, $index) use ($statement, $sheet, $key) {
|
||||
if (!$row[0] || !$row[11]) {
|
||||
return;
|
||||
}
|
||||
|
||||
$postingDate = carbon::createFromFormat('dM', trim($row[0]));
|
||||
|
||||
$description = trim($row[1]);
|
||||
|
||||
$nextRow = $sheet->slice(13)[$index + 1];
|
||||
|
||||
if (!$nextRow[0] && $nextRow[1]) {
|
||||
foreach ($nextRow as $col) {
|
||||
if ($col) {
|
||||
$description .= ' '. $col;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$descriptionArr = explode(',', $description);
|
||||
|
||||
$transactionDescription = array_key_exists(0, $descriptionArr) ? trim($descriptionArr[0]) : "";
|
||||
$description2 = array_key_exists(1, $descriptionArr) ? trim($descriptionArr[1]) : "";
|
||||
$description3 = array_key_exists(2, $descriptionArr) ? trim($descriptionArr[2]) : "";
|
||||
$description4 = array_key_exists(3, $descriptionArr) ? trim($descriptionArr[3]) : "";
|
||||
$description5 = array_key_exists(4, $descriptionArr) ? trim($descriptionArr[4]) : "";
|
||||
|
||||
if (count($descriptionArr) > 5) {
|
||||
for ($i = 5; $i < count($descriptionArr); $i++) {
|
||||
$description5 = $description5 . array_key_exists($i, $descriptionArr) ? trim($descriptionArr[$i]) : "";
|
||||
}
|
||||
}
|
||||
|
||||
$amount = $row[9] ? ((float) str_replace(',', '', trim($row[9]))) : (-((float) str_replace(',', '', $row[8])));
|
||||
$endBalance = ((float) str_replace(',', '', $row[11]));
|
||||
$transaction = new StatementTransaction([
|
||||
'posting_date' => $postingDate,
|
||||
'transaction_description' => $transactionDescription,
|
||||
'transaction_description_2' => $description2,
|
||||
'transaction_description_3' => $description3,
|
||||
'transaction_description_4' => $description4,
|
||||
'transaction_description_5' => $description5,
|
||||
'amount' => $amount,
|
||||
'end_balance' => $endBalance,
|
||||
]);
|
||||
|
||||
// Check if the transaction already exists for this statement
|
||||
$existingTransaction = StatementTransaction::whereDate('posting_date', $postingDate)
|
||||
->where('amount', $amount)
|
||||
->where('transaction_description', $transactionDescription)
|
||||
->whereRaw("CAST(REPLACE(end_balance,',','') AS DECIMAL(15,2)) = ?",[$endBalance])
|
||||
->first();
|
||||
|
||||
if (!$existingTransaction) {
|
||||
$statement->transactions()->save($transaction);
|
||||
}
|
||||
|
||||
return $transaction;
|
||||
});
|
||||
} else {
|
||||
if (strpos($sheet->first()->first(), "DATE") === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
$extraColumn = 0;
|
||||
if (count($sheet->first()) > 7 && $sheet->first()[7]) {
|
||||
$extraColumn = 1;
|
||||
}
|
||||
|
||||
$sheet->slice(1)->map(function ($row, $index) use ($statement, $sheet, $extraColumn, $key) {
|
||||
if (!$row[0] || !$row[6 + $extraColumn]) {
|
||||
return;
|
||||
}
|
||||
|
||||
$postingDate = carbon::createFromFormat('dM', trim($row[0]));
|
||||
|
||||
$description = trim($row[1]);
|
||||
|
||||
$nextRow = $sheet->slice(1)[$index + 1];
|
||||
|
||||
if (!$nextRow[0] && $nextRow[1]) {
|
||||
foreach ($nextRow as $col) {
|
||||
if ($col) {
|
||||
$description .= ' '. $col;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$descriptionArr = explode(',', $description);
|
||||
|
||||
$transactionDescription = array_key_exists(0, $descriptionArr) ? trim($descriptionArr[0]) : "";
|
||||
$description2 = array_key_exists(1, $descriptionArr) ? trim($descriptionArr[1]) : "";
|
||||
$description3 = array_key_exists(2, $descriptionArr) ? trim($descriptionArr[2]) : "";
|
||||
$description4 = array_key_exists(3, $descriptionArr) ? trim($descriptionArr[3]) : "";
|
||||
$description5 = array_key_exists(4, $descriptionArr) ? trim($descriptionArr[4]) : "";
|
||||
|
||||
if (count($descriptionArr) > 5) {
|
||||
for ($i = 5; $i < count($descriptionArr); $i++) {
|
||||
$description5 = $description5 . array_key_exists($i, $descriptionArr) ? trim($descriptionArr[$i]) : "";
|
||||
}
|
||||
}
|
||||
|
||||
$amount = $row[5 + $extraColumn] ? ((float) str_replace(',', '', trim($row[5 + $extraColumn]))) : (-((float) str_replace(',', '', $row[4 + $extraColumn])));
|
||||
$endBalance = ((float) str_replace(',', '', $row[6 + $extraColumn]));
|
||||
$transaction = new StatementTransaction([
|
||||
'posting_date' => $postingDate,
|
||||
'transaction_description' => $transactionDescription,
|
||||
'transaction_description_2' => $description2,
|
||||
'transaction_description_3' => $description3,
|
||||
'transaction_description_4' => $description4,
|
||||
'transaction_description_5' => $description5,
|
||||
'amount' => $amount,
|
||||
'end_balance' => $endBalance,
|
||||
]);
|
||||
|
||||
// Check if the transaction already exists for this statement
|
||||
$existingTransaction = StatementTransaction::whereDate('posting_date', $postingDate)
|
||||
->where('amount', $amount)
|
||||
->where('transaction_description', $transactionDescription)
|
||||
->whereRaw("CAST(REPLACE(end_balance,',','') AS DECIMAL(15,2)) = ?",[$endBalance])
|
||||
->first();
|
||||
|
||||
if (!$existingTransaction) {
|
||||
$statement->transactions()->save($transaction);
|
||||
}
|
||||
|
||||
return $transaction;
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return $this->response([]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Accounting\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Models\AccountStatement;
|
||||
use App\Models\StatementAccount;
|
||||
use App\Models\StatementTransaction;
|
||||
use Exception;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
|
||||
class ImportCiefLiteStatementLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Import Cief Lite Statement Transactions Details',
|
||||
'message' => 'You have successfully updated the Cief Lite Statement Transactions Details'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
|
||||
$object = new DocumentObject('', $request->input('files'), '', ApprovalStatus::APPROVED, 'imports');
|
||||
foreach ($object->getFiles() as $file){
|
||||
$collection = Excel::toCollection(null, json_decode($file)->file_info->original->file, null, null, true);
|
||||
|
||||
$sheet = $collection->first()->skip(1);
|
||||
|
||||
$dateTo = $sheet->first()[10];
|
||||
$dateFrom = $sheet->last()[10];
|
||||
$totalTransaction = $sheet->count();
|
||||
|
||||
$offset = 1;
|
||||
do {
|
||||
$dateFrom = $sheet->offsetGet($sheet->count() - $offset)[10];
|
||||
$offset += 1;
|
||||
} while(!$dateFrom);
|
||||
|
||||
|
||||
$dateFrom = carbon::parse($dateFrom);
|
||||
$dateTo = carbon::parse($dateTo);
|
||||
|
||||
$statement = AccountStatement::whereDate('date_from', $dateFrom)
|
||||
->whereDate('date_to', $dateTo)
|
||||
->where('total_amount', $totalTransaction)
|
||||
->first();
|
||||
|
||||
if(!$statement){
|
||||
$statement = new AccountStatement([
|
||||
'date_from' => $dateFrom,
|
||||
'date_to' => $dateTo,
|
||||
'total_amount' => $totalTransaction,
|
||||
]);
|
||||
}
|
||||
|
||||
$account = StatementAccount::where("name", "CIEF LITE")->first();
|
||||
|
||||
if (!$account) {
|
||||
throw new Exception("Statement Account for CIEF LITE not found.");
|
||||
}
|
||||
|
||||
$account->statements()->save($statement);
|
||||
|
||||
$sheet->map(function ($row) use ($statement) {
|
||||
if (!$row[0]) {
|
||||
return;
|
||||
}
|
||||
$postingDate = $row[10];
|
||||
$transactionDescription = trim($row[1]);
|
||||
$description2 = trim($row[2]);
|
||||
$description3 = "Fee " . $row[6];
|
||||
$description4 = trim($row[8]);
|
||||
$transactionRef = trim($row[12]);
|
||||
$amount = ((float) str_replace(',', '', $row[7]));
|
||||
$transactionCode = $row[0];
|
||||
$transaction = new StatementTransaction([
|
||||
'posting_date' => $postingDate,
|
||||
'transaction_description' => $transactionDescription,
|
||||
'transaction_description_2' => $description2,
|
||||
'transaction_description_3' => $description3,
|
||||
'transaction_description_4' => $description4,
|
||||
'transaction_ref' => $transactionRef,
|
||||
'amount' => $amount,
|
||||
'transaction_code' => $transactionCode,
|
||||
]);
|
||||
|
||||
// Check if the transaction already exists for this statement
|
||||
$existingTransaction = StatementTransaction::where('transaction_ref', $transactionRef)
|
||||
->where('posting_date', $postingDate)
|
||||
->where('amount', $amount)
|
||||
->where('transaction_description', $transactionDescription)
|
||||
->where('transaction_code', $transactionCode)
|
||||
->first();
|
||||
|
||||
if (!$existingTransaction) {
|
||||
$statement->transactions()->save($transaction);
|
||||
}
|
||||
|
||||
return $transaction;
|
||||
});
|
||||
}
|
||||
|
||||
return $this->response([]);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,7 +3,9 @@
|
||||
namespace App\Http\Controllers\Accounting;
|
||||
|
||||
use App\Classes\Jobs\CreateBankStatementTransactionOwners;
|
||||
use App\Classes\Modules\Accounting\ControllersLogic\ImportAmbankStatementLogic;
|
||||
use App\Classes\Modules\Accounting\ControllersLogic\ImportBankStatementLogic;
|
||||
use App\Classes\Modules\Accounting\ControllersLogic\ImportCiefLiteStatementLogic;
|
||||
use App\Classes\Modules\Accounting\ControllersLogic\ListBankStatementDetailsLogic;
|
||||
use App\Classes\Modules\Accounting\ControllersLogic\ListBankStatementTransactionsLogic;
|
||||
use App\Classes\Modules\Accounting\ControllersLogic\UpdateBankStatementDetailLogic;
|
||||
@@ -87,6 +89,16 @@ class BankStatementController extends Controller
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
public function importAmbank(Request $request, ImportAmbankStatementLogic $logic): JsonResponse
|
||||
{
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
public function importCiefLite(Request $request, ImportCiefLiteStatementLogic $logic): JsonResponse
|
||||
{
|
||||
return $logic->execute($request);
|
||||
}
|
||||
|
||||
public function rerun()
|
||||
{
|
||||
foreach (StatementTransaction::doesntMapStatement()->get()->chunk(30) as $key => $transaction) {
|
||||
|
||||
@@ -10,7 +10,9 @@
|
||||
<div class="col">
|
||||
<file-input-component :validator="$v.parameters.files" v-model="parameters.files">
|
||||
<template slot="label">
|
||||
<div class="font-heading fs-11 text-primary all-caps">Import Bank Statement CSV</div>
|
||||
<div class="font-heading fs-11 text-primary all-caps" v-if="statementType.includes('568603010762')">Import Bank Statement CSV</div>
|
||||
<div class="font-heading fs-11 text-primary all-caps" v-if="statementType.includes('8881040198515')">Import Ambank Statement CSV</div>
|
||||
<div class="font-heading fs-11 text-primary all-caps" v-if="statementType.includes('LITE')">Import Cief Lite Statement CSV</div>
|
||||
</template>
|
||||
</file-input-component>
|
||||
</div>
|
||||
@@ -35,6 +37,16 @@
|
||||
import { required } from "vuelidate/lib/validators";
|
||||
import formHandler from '../../../general/mixins/formHandler';
|
||||
export default {
|
||||
props: {
|
||||
section:{
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
statementType:{
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
},
|
||||
data(){
|
||||
return {
|
||||
parameters: {
|
||||
@@ -51,7 +63,13 @@ export default {
|
||||
},
|
||||
methods: {
|
||||
submitForm(){
|
||||
if (this.statementType.includes('568603010762')) {
|
||||
this.submit(this.route('api.accounting.statement.import'), 'post', this.section, true, false)
|
||||
} else if (this.statementType.includes('8881040198515')) {
|
||||
this.submit(this.route('api.accounting.statement.import.ambank'), 'post', this.section, true, false)
|
||||
} else if (this.statementType.includes('LITE')) {
|
||||
this.submit(this.route('api.accounting.statement.import.cief.lite'), 'post', this.section, true, false)
|
||||
}
|
||||
}
|
||||
},
|
||||
mixins: [formHandler]
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
<template>
|
||||
<div class="row">
|
||||
<div class="col padding-0">
|
||||
<div class="col">
|
||||
<validation-wrapper-component selectable :validator="$v.bankStatementType">
|
||||
<label>Bank Statement Type</label>
|
||||
<select-component :options="['CIEF WORLDWIDE SDN. BHD. (568603010762)', 'CIEF WORLDWIDE SDN. BHD. AMBANK (8881040198515)', 'CIEF LITE']" v-model="bankStatementType"></select-component>
|
||||
</validation-wrapper-component>
|
||||
</div>
|
||||
<div class="col">
|
||||
<import-statement-form-component section="importStatementFrom" :statementType="bankStatementType"></import-statement-form-component>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
<script>
|
||||
export default {
|
||||
data() {
|
||||
return {
|
||||
bankStatementType: "CIEF WORLDWIDE SDN. BHD. (568603010762)",
|
||||
}
|
||||
},
|
||||
validations: {
|
||||
bankStatementType: { },
|
||||
},
|
||||
methods: {
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
</script>
|
||||
@@ -149,11 +149,7 @@
|
||||
<div class="col bg-white padding-25">
|
||||
<div class="row tabsContainer tabContent active" tab-name="bankStatements">
|
||||
<div class="col-4">
|
||||
<div class="row mb-5">
|
||||
<div class="col">
|
||||
<import-statement-form-component section="importStatementFrom"></import-statement-form-component>
|
||||
</div>
|
||||
</div>
|
||||
<import-statement-section-component></import-statement-section-component>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
<table class="table">
|
||||
|
||||
@@ -4,6 +4,8 @@ use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::group(['prefix' => 'accounting', 'as' => 'accounting.', 'namespace' => 'Accounting'], function () {
|
||||
Route::post('/import', 'BankStatementController@import')->name('statement.import');
|
||||
Route::post('/import-ambank', 'BankStatementController@importAmbank')->name('statement.import.ambank');
|
||||
Route::post('/import-cief-lite', 'BankStatementController@importCiefLite')->name('statement.import.cief.lite');
|
||||
Route::get('/bank_account', 'BankStatementController@transactions')->name('bank.transaction');
|
||||
Route::group(['prefix' => 'statements/{id}', 'as' => 'statement.'], function () {
|
||||
Route::get('/details', 'BankStatementController@fetch')->name('details');
|
||||
|
||||
Reference in New Issue
Block a user