mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
fix bug in import invoices and unknow tabs for status not in rejected
This commit is contained in:
@@ -157,7 +157,7 @@ class UpdateBankStatementDetailLogic extends AbstractControllerLogic
|
||||
'owner_reference' => $owner_reference,
|
||||
];
|
||||
|
||||
return $bankStatementTransaction->owners()->firstOrCreate($ownerData);
|
||||
return $bankStatementTransaction->owners()->where('status','<>',ApprovalStatus::REJECTED)->firstOrCreate($ownerData);
|
||||
}
|
||||
|
||||
private function editAccountMapped(StatementTransactionOwner $owner){
|
||||
|
||||
@@ -34,93 +34,111 @@ class ImportStatementInvoiceController
|
||||
$this->responseMessage = 'You have successfully imported invoice mapping';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return array
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function import(Request $request) : JsonResponse
|
||||
{
|
||||
ini_set('memory_limit', '-1');
|
||||
$importDate = date('Y-m-d H:i:s');
|
||||
$object = new DocumentObject('', $request->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();
|
||||
|
||||
$data = [];
|
||||
foreach ($excelRows as $row) {
|
||||
$row['mapped_result_reference'] = null;
|
||||
$row['mapped_status'] = 'failed';
|
||||
$row['date'] = date('Y-m-d', strtotime($row['date']));
|
||||
|
||||
// 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
|
||||
foreach (['exchange','izyim'] as $system) {
|
||||
$returnReference = $this->mappingTopUp($row, $system);
|
||||
if ($returnReference) {
|
||||
$row['mapped_result_reference'] = $returnReference;
|
||||
$row['mapped_status'] = 'success';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$returnReference = $this->mappingExchange($row);
|
||||
public function mapping($row) {
|
||||
// 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
|
||||
foreach (['exchange','izyim'] as $system) {
|
||||
$returnReference = $this->mappingTopUp($row, $system);
|
||||
if ($returnReference) {
|
||||
$row['mapped_result_reference'] = $returnReference;
|
||||
$row['mapped_status'] = 'success';
|
||||
return $row;
|
||||
}
|
||||
}
|
||||
|
||||
TransactionMappingLog::create([
|
||||
'imported_date'=>$importDate,
|
||||
'data'=>$row,
|
||||
]);
|
||||
array_push($data, $row);
|
||||
|
||||
|
||||
// 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
|
||||
// ]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
$returnReference = $this->mappingExchange($row);
|
||||
if ($returnReference) {
|
||||
$row['mapped_result_reference'] = $returnReference;
|
||||
$row['mapped_status'] = 'success';
|
||||
return $row;
|
||||
}
|
||||
|
||||
return $this->response(['data'=>$data,'importedDate'=>$importDate]);
|
||||
// if still unable to map, will try to check the shipping_info without TOPUP
|
||||
foreach (['exchange','izyim'] as $system) {
|
||||
$returnReference = $this->mappingTopUp($row, $system);
|
||||
if ($returnReference) {
|
||||
$row['mapped_result_reference'] = $returnReference;
|
||||
$row['mapped_status'] = 'success';
|
||||
}
|
||||
}
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
||||
public function response(?array $data = []) : JsonResponse {
|
||||
return (new ApiResponseObject($this->responseTitle,
|
||||
$this->responseMessage,
|
||||
HttpStatus::OK_WITH_MESSAGE, $data))->handler();
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function import(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
ini_set('memory_limit', '-1');
|
||||
$importDate = date('Y-m-d H:i:s');
|
||||
$object = new DocumentObject('', $request->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();
|
||||
|
||||
$data = [];
|
||||
foreach ($excelRows as $row) {
|
||||
$row['mapped_result_reference'] = null;
|
||||
$row['mapped_status'] = 'failed';
|
||||
$row['date'] = in_array(gettype($row['date']), ['integer', 'double']) ? $this->changeExcelDate($row['date']) : date('Y-m-d', strtotime($row['date']));
|
||||
|
||||
$row = $this->mapping($row);
|
||||
|
||||
TransactionMappingLog::create([
|
||||
'imported_date'=>$importDate,
|
||||
'data'=>$row,
|
||||
]);
|
||||
array_push($data, $row);
|
||||
|
||||
|
||||
// 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
|
||||
// ]);
|
||||
|
||||
|
||||
}
|
||||
|
||||
return $this->response($this->responseTitle, $this->responseMessage, HttpStatus::OK_WITH_MESSAGE, ['data'=>$data,'importedDate'=>$importDate]);
|
||||
} catch (\Exception $exception){
|
||||
return $this->response('import invoice failed',$exception->getMessage(), ($exception->getCode()? $exception->getCode() : HttpStatus::SERVER_ERROR));
|
||||
}
|
||||
}
|
||||
|
||||
public function response(String $responseTitle, String $responseMessage, int $httpStatus, ?array $data = []) : JsonResponse {
|
||||
return (new ApiResponseObject($responseTitle, $responseMessage, $httpStatus, $data))->handler();
|
||||
}
|
||||
|
||||
private function mappingTopUp(Array $row, String $system) {
|
||||
@@ -162,4 +180,11 @@ class ImportStatementInvoiceController
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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'
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,41 +40,43 @@ class ImportStatementReceiptsController
|
||||
*/
|
||||
public function import(Request $request)
|
||||
{
|
||||
$importDate = date('Y-m-d H:i:s');
|
||||
$object = new DocumentObject('', $request->input('files'), '', ApprovalStatus::APPROVED, 'imports');
|
||||
$file = json_decode($object->getFiles()[0])->file_info->original->file;
|
||||
try {
|
||||
$importDate = date('Y-m-d H:i:s');
|
||||
$object = new DocumentObject('', $request->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();
|
||||
$import = new GenericImport();
|
||||
Excel::import($import, $file);
|
||||
$excelRows = $import->rows;
|
||||
$excelRows = $excelRows->toArray();
|
||||
|
||||
$data = [];
|
||||
foreach ($excelRows as $row) {
|
||||
$row['mapped_result_reference'] = null;
|
||||
$row['mapped_status'] = 'failed';
|
||||
$row['date'] = date('Y-m-d', strtotime($row['doc_date']));
|
||||
$data = [];
|
||||
foreach ($excelRows as $row) {
|
||||
$row['mapped_result_reference'] = null;
|
||||
$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';
|
||||
}
|
||||
$returnReference = $this->mappingExchange($row);
|
||||
if ($returnReference) {
|
||||
$row['mapped_result_reference'] = $returnReference;
|
||||
$row['mapped_status'] = 'success';
|
||||
}
|
||||
|
||||
TransactionMappingLog::create([
|
||||
'imported_date'=>$importDate,
|
||||
'data'=>$row,
|
||||
]);
|
||||
array_push($data, $row);
|
||||
TransactionMappingLog::create([
|
||||
'imported_date'=>$importDate,
|
||||
'data'=>$row,
|
||||
]);
|
||||
array_push($data, $row);
|
||||
}
|
||||
|
||||
return $this->response($this->responseTitle, $this->responseMessage, HttpStatus::OK_WITH_MESSAGE, ['data'=>$data,'importedDate'=>$importDate]);
|
||||
} catch (\Exception $exception){
|
||||
return $this->response('import invoice failed',$exception->getMessage(), ($exception->getCode()? $exception->getCode() : HttpStatus::SERVER_ERROR));
|
||||
}
|
||||
|
||||
return $this->response(['data'=>$data,'importedDate'=>$importDate]);
|
||||
}
|
||||
|
||||
public function response(?array $data = []) : JsonResponse {
|
||||
return (new ApiResponseObject($this->responseTitle,
|
||||
$this->responseMessage,
|
||||
HttpStatus::OK_WITH_MESSAGE, $data))->handler();
|
||||
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) {
|
||||
@@ -104,4 +106,11 @@ class ImportStatementReceiptsController
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
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'
|
||||
}
|
||||
}
|
||||
|
||||
+11
@@ -8,6 +8,11 @@
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h3>{{ componentTitle }}</h3>
|
||||
<div class="row m-b-10 animate__animated animate__fadeInUpBig animate__fast" v-if="error">
|
||||
<div class="col">
|
||||
<small class="bold fs-10 text-danger">{{error}}</small>
|
||||
</div>
|
||||
</div>
|
||||
<div class="text-right">
|
||||
<button class="btn btn-xs btn-outline-success b-rad-none m-r-5" @click="downloadInvoiceMapped">
|
||||
Download Invoices Mapped
|
||||
@@ -69,6 +74,7 @@
|
||||
data() {
|
||||
return {
|
||||
isLoading: false,
|
||||
error: '',
|
||||
importedDate: null,
|
||||
}
|
||||
},
|
||||
@@ -114,6 +120,11 @@
|
||||
this.isLoading = false;
|
||||
},
|
||||
|
||||
errorHandler(error){
|
||||
this.isLoading = false;
|
||||
this.error = error.message;
|
||||
},
|
||||
|
||||
downloadInvoiceMapped() {
|
||||
var arrDateTime = this.importedDate.split(" ");
|
||||
const fileName = this.section == 'importInvoiceMapping' ? 'InvoiceMapped' : 'ReceiptMapped';
|
||||
|
||||
Reference in New Issue
Block a user