mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-22 22:13:59 +00:00
Merge branch 'master' of gitlab.com:CIEFWorldwideSdnBhd/exchange-2.0 into import-ambank-cief-lite-statement
update import cief lite
This commit is contained in:
+1
-1
@@ -62,7 +62,7 @@ class GroupApproveStatementTransactionLogic extends AbstractControllerLogic
|
||||
$statementTransactions = $this->listsBankStatementTransactions->execute($filters);
|
||||
|
||||
foreach ($statementTransactions as $statementTransaction) {
|
||||
$owners = $statementTransaction->owners;
|
||||
$owners = $statementTransaction->owners()->where('status', ApprovalStatus::PENDING_VERIFICATION)->get();
|
||||
|
||||
if (count($owners)) {
|
||||
$this->updatesBankStatementTransactionOwnerStatus->execute($owners->first(), ApprovalStatus::APPROVED);
|
||||
|
||||
@@ -7,6 +7,7 @@ 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\Classes\ValueObjects\Constants\StatementTransactionOwnerType;
|
||||
use App\Models\AccountStatement;
|
||||
use App\Models\StatementAccount;
|
||||
use App\Models\StatementTransaction;
|
||||
@@ -45,77 +46,28 @@ class ImportCiefLiteStatementLogic extends AbstractControllerLogic
|
||||
|
||||
$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]) {
|
||||
$sheet->map(function ($row) {
|
||||
if (!$row[0] || trim($row[8]) !== "已审核") {
|
||||
return;
|
||||
}
|
||||
$postingDate = $row[10];
|
||||
$transactionDescription = trim($row[1]);
|
||||
$description2 = trim($row[2]);
|
||||
$description3 = "Fee " . $row[6];
|
||||
$description4 = trim($row[8]);
|
||||
$transactionRef = trim($row[12]);
|
||||
$postingDate =date('Y-m-d', strtotime($row[10]));
|
||||
$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,
|
||||
]);
|
||||
|
||||
$statementTransaction = StatementTransaction::whereHas('account', function($query) {
|
||||
$query->where('statement_accounts.number', 8881040198515);
|
||||
})->whereDate('posting_date', $postingDate)->where('amount', $amount)->first();
|
||||
|
||||
// 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);
|
||||
if (!$statementTransaction) {
|
||||
return;
|
||||
}
|
||||
|
||||
return $transaction;
|
||||
$owner = $statementTransaction->owners()->firstOrCreate([
|
||||
'type' => StatementTransactionOwnerType::WALLET_TOP_UP,
|
||||
'system' => 'LITE',
|
||||
'owner_reference'=> $row[0],
|
||||
]);
|
||||
|
||||
return $owner;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -63,7 +63,7 @@ class UpdateStatementTransactionStatusLogic extends AbstractControllerLogic
|
||||
{
|
||||
$statementTrasaction = $this->fetchesBankStatementTransaction->execute(['id' => $request->route('id')]);
|
||||
|
||||
$statementTrasactionOwner = $statementTrasaction->owners->first();
|
||||
$statementTrasactionOwner = $statementTrasaction->owners()->where('status', '!=', ApprovalStatus::REJECTED)->first();
|
||||
|
||||
$this->updatesBankStatementTransactionOwnerStatus->execute($statementTrasactionOwner, $request->route('status') == 'approve' ? ApprovalStatus::APPROVED : ApprovalStatus::REJECTED);
|
||||
|
||||
|
||||
@@ -2,32 +2,35 @@
|
||||
|
||||
namespace App\Http\Controllers\Imports;
|
||||
|
||||
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
||||
use App\Classes\Modules\Imports\Services\GenericImport;
|
||||
use App\Classes\Modules\Segments\DataTransferObjects\SeasonalSegmentObject;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Models\Segment;
|
||||
use App\Models\User;
|
||||
use Carbon\Carbon;
|
||||
use DateTime;
|
||||
use Illuminate\Http\Request;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use App\Classes\Modules\Segments\Services\CreatesSeasonalSegment;
|
||||
use App\Classes\Modules\Companies\Processors\AssignSegmentProcessor;
|
||||
use Carbon\Carbon;
|
||||
use App\Models\User;
|
||||
use App\Models\Company;
|
||||
use App\Models\SeasonalSegment;
|
||||
use App\Models\Segment;
|
||||
use App\Models\Transaction;
|
||||
use App\Models\TransactionMappingLog;
|
||||
use App\Classes\ValueObjects\Response\ApiResponseObject;
|
||||
use App\Classes\ValueObjects\Constants\HttpStatus;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\SeasonalSegment;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Maatwebsite\Excel\Facades\Excel;
|
||||
use App\Models\TransactionMappingLog;
|
||||
use App\Models\StatementTransactionOwner;
|
||||
use App\Classes\ValueObjects\Constants\HttpStatus;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\Modules\Imports\Services\GenericImport;
|
||||
use App\Classes\ValueObjects\Response\ApiResponseObject;
|
||||
use App\Classes\Modules\Segments\Services\CreatesSeasonalSegment;
|
||||
use App\Classes\Modules\Companies\Processors\AssignSegmentProcessor;
|
||||
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
||||
use App\Classes\Modules\Segments\DataTransferObjects\SeasonalSegmentObject;
|
||||
|
||||
class ImportStatementReceiptsController
|
||||
{
|
||||
private $responseTitle;
|
||||
private $responseMessage;
|
||||
|
||||
private $removeStr = 'Payment for ';
|
||||
|
||||
public function __construct() {
|
||||
$this->responseTitle = 'Import Receipt Mapping';
|
||||
$this->responseMessage = 'You have successfully imported receipt mapping';
|
||||
@@ -56,11 +59,13 @@ class ImportStatementReceiptsController
|
||||
$row['mapped_status'] = 'failed';
|
||||
$row['date'] = in_array(gettype($row['doc_date']), ['integer', 'double']) ? $this->changeExcelDate($row['doc_date']) : date('Y-m-d', strtotime($row['doc_date']));
|
||||
|
||||
$returnReference = $this->mappingExchange($row);
|
||||
if ($returnReference) {
|
||||
$row['mapped_result_reference'] = $returnReference;
|
||||
$row['mapped_status'] = 'success';
|
||||
}
|
||||
if ($invRefer = $this->getInvoiceReference($row['description'])) {
|
||||
$returnReference = $this->mappingExchange($invRefer, $row['doc_no']);
|
||||
if ($returnReference) {
|
||||
$row['mapped_result_reference'] = $returnReference;
|
||||
$row['mapped_status'] = 'success';
|
||||
}
|
||||
}
|
||||
|
||||
TransactionMappingLog::create([
|
||||
'imported_date'=>$importDate,
|
||||
@@ -75,28 +80,26 @@ class ImportStatementReceiptsController
|
||||
}
|
||||
}
|
||||
|
||||
private function getInvoiceReference($invRefer) {
|
||||
$arrStr = explode($this->removeStr, $invRefer);
|
||||
if (isset($arrStr[1])) return $arrStr[1];
|
||||
return null;
|
||||
}
|
||||
|
||||
public function response(String $responseTitle, String $responseMessage, int $httpStatus, ?array $data = []) : JsonResponse {
|
||||
return (new ApiResponseObject($responseTitle, $responseMessage, $httpStatus, $data))->handler();
|
||||
}
|
||||
|
||||
private function mappingExchange(Array $row) {
|
||||
$date = $row['date'];
|
||||
$transactions = Transaction::getReceiverWithJoinStatementTransactionAndOwner($row)->select('transactions.*')->where('statement_transactions.amount', $row['payment_amount'])->whereRaw("DATE(posting_date) = '$date'")->get();
|
||||
private function mappingExchange($invRefer, $docNo) {
|
||||
$transactionOwner = StatementTransactionOwner::where('invoice_reference',$invRefer)->whereNull('receipt_reference')->where('status', ApprovalStatus::COMPLETED)->first();
|
||||
|
||||
if ($transactions && $transactions->count() == 0) {
|
||||
$transactions = Transaction::getReceiverWithJoinStatementTransactionAndOwner($row)->select('transactions.*')->where(DB::raw('FLOOR(statement_transactions.amount)'), floor($row['payment_amount']))->whereRaw("DATE(posting_date) = '$date'")->get();
|
||||
}
|
||||
|
||||
if ($transactions && $transactions->count() == 1) {
|
||||
foreach ($transactions as $key => $transaction) {
|
||||
return $this->updateTransactionOwnerReference($transaction, $row['doc_no']);
|
||||
}
|
||||
if ($transactionOwner) {
|
||||
return $this->updateTransactionOwnerReference($transactionOwner, $docNo);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function updateTransactionOwnerReference($transaction, String $docNo) {
|
||||
$transactionOwner = $transaction->transaction_owner;
|
||||
public function updateTransactionOwnerReference($transactionOwner, String $docNo) {
|
||||
if ($transactionOwner) {
|
||||
$transactionOwner->update([
|
||||
'receipt_reference'=>$docNo,
|
||||
|
||||
+19
-7
@@ -109,7 +109,7 @@ class Company extends AbstractModel implements Documentable
|
||||
{
|
||||
return $this->hasManyDeep(Transaction::class, [Booking::class], ['company_id', 'owner_id'], ['id', 'id']);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return HasMany
|
||||
*/
|
||||
@@ -130,13 +130,25 @@ class Company extends AbstractModel implements Documentable
|
||||
* @return Builder
|
||||
*/
|
||||
public function services(): Builder {
|
||||
return ServiceType::where('status', ApprovalStatus::APPROVED)->whereHas('constants', function($query) {
|
||||
$query->Where(function($query){
|
||||
$query->where('reference', SegmentConstants::SERVICE_TYPE)->where('detail->is_active', true);
|
||||
})->orWhere(function($query) {
|
||||
$query->where('reference', SegmentConstants::CUSTOM_SERVICE_TYPE)->where('detail->is_active', true)->whereIn('segment_id', $this->segments->pluck('id'));
|
||||
|
||||
if ($this->business_type === 3) {
|
||||
return ServiceType::where('status', ApprovalStatus::APPROVED)->whereHas('constants', function($query) {
|
||||
$query->where(function($query) {
|
||||
$query->where('reference', SegmentConstants::SERVICE_TYPE)->where('detail->is_active', true);
|
||||
})->orWhere(function($query) {
|
||||
$query->where('reference', SegmentConstants::CUSTOM_SERVICE_TYPE)->where('detail->is_active', true);
|
||||
});
|
||||
});
|
||||
});
|
||||
} else {
|
||||
// Existing logic for other company types
|
||||
return ServiceType::where('status', ApprovalStatus::APPROVED)->whereHas('constants', function($query) {
|
||||
$query->Where(function($query){
|
||||
$query->where('reference', SegmentConstants::SERVICE_TYPE)->where('detail->is_active', true);
|
||||
})->orWhere(function($query) {
|
||||
$query->where('reference', SegmentConstants::CUSTOM_SERVICE_TYPE)->where('detail->is_active', true)->whereIn('segment_id', $this->segments->pluck('id'));
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public function servicesConfigurations(): Collection {
|
||||
|
||||
@@ -56,7 +56,9 @@ class StatementTransaction extends Model
|
||||
|
||||
public function scopeDoesntMapStatement($query)
|
||||
{
|
||||
$query->whereDoesntHave('owners', function($query){
|
||||
$query->whereHas('account', function($query) {
|
||||
$query->where('statement_accounts.number', 568603010762);
|
||||
})->whereDoesntHave('owners', function($query){
|
||||
return $query->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
|
||||
})->orderBy('posting_date');
|
||||
}
|
||||
|
||||
+1
-1
@@ -136,7 +136,7 @@
|
||||
case 'Sales':
|
||||
return ['Exchange', 'Izyim', 'Lite', 'Cntr', 'Probashi', 'Pets'];
|
||||
case 'Top Up':
|
||||
return ['Exchange', 'Izyim'];
|
||||
return ['Exchange', 'Izyim', 'Lite'];
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
|
||||
+6
-1
@@ -4,11 +4,14 @@
|
||||
<div class="row p-b-10 b-b b-grey">
|
||||
<div class="col-2">{{ item.posting_date }}</div>
|
||||
<div class="col-2">{{ item.transaction_description_1 + ' - ' + item.transaction_description_2 }}</div>
|
||||
|
||||
<!-- Mapping Approval tab -->
|
||||
<div class="col-5" v-if="item.owners.pending_verification.length === 1">
|
||||
<div class="row">
|
||||
<div class="col">{{item.owners.pending_verification[0].system}}</div>
|
||||
<div class="col">{{ typeString(item.owners.pending_verification[0].type) }}</div>
|
||||
<div class="col"><a :href="item.owners.pending_verification[0].reference_link" target="_blank">{{item.owners.pending_verification[0].reference}}</a></div>
|
||||
<div class="col" v-if="item.owners.pending_verification[0].system === 'LITE' && typeString(item.owners.pending_verification[0].type) == 'Wallet Top Up'"><a :href="'https://lite.cief-malaysia.com/admin/index.php?route=sale/topup&filter_topup_id=' + item.owners.pending_verification[0].reference" target="_blank">{{item.owners.pending_verification[0].reference}}</a></div>
|
||||
<div class="col" v-else><a :href="item.owners.pending_verification[0].reference_link" target="_blank">{{item.owners.pending_verification[0].reference}}</a></div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -51,6 +54,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Mapping Review tab -->
|
||||
<div class="col-5" v-if="item.owners.pending_verification.length > 1">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
@@ -93,6 +97,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- unknow tab -->
|
||||
<div class="col-5" v-if="!item.owners.pending_verification.length && !item.owners.approved.length">
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col d-none d-lg-block" v-if="$store.getters.isAdmin">
|
||||
<div class="col-auto d-none d-lg-block" v-if="$store.getters.isAdmin">
|
||||
<div class="font-heading fs-10 muted all-caps">Marking</div>
|
||||
<div class="font-heading">
|
||||
<a :href="route('customer.profile', item.company.reference)">{{this.item.company.reference}}</a>
|
||||
@@ -34,7 +34,7 @@
|
||||
<span class="flag-icon" :class="'flag-icon-'+item.convertible_currency.country.short_code.toLowerCase()"></span> {{this.item.convertible_currency.short_code}}
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-auto d-none d-lg-block">
|
||||
<div class="col-3 d-none d-lg-block">
|
||||
<div class="font-heading fs-10 muted all-caps">Transfer Type</div>
|
||||
<div class="font-heading fs-12">{{this.item.service.name}}</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user