Merge branch 'dillon/51-vue-polling-experimental-2' into dillon/34-jenkins-vapor

This commit is contained in:
Dillon Ngo
2023-12-30 18:48:00 +08:00
69 changed files with 2047 additions and 486 deletions
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Controllers\Bookings;
use App\Classes\Modules\Bookings\ControllersLogic\ExpireBookingPaymentControllerLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class ExpireBookingPaymentController
{
/**
* @param Request $request
* @param DeleteBookingPaymentControllerLogic $logic
* @return JsonResponse
*/
public function expire(Request $request, ExpireBookingPaymentControllerLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
@@ -17,6 +17,7 @@ use Illuminate\Support\Facades\Auth;
use Maatwebsite\Excel\Excel;
use App\Classes\Modules\Exports\Services\ExportsImportedInvoiceMappeds;
use App\Models\TransactionMappingLog;
use App\Classes\Modules\Exports\Services\ExportsReceiptTransactions;
class ExportCustomersToExcelController
{
@@ -61,7 +62,14 @@ class ExportCustomersToExcelController
public function invoiceTransactions(Request $request){
$exportsTransactions = new ExportsInvoiceTransactions($request);
$response = $exportsTransactions->download(($request->input('type') == 'invoices' ? 'invoice-transactions' : 'receipt-transactions').'.xls', Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
$response = $exportsTransactions->download('invoice-transactions.xls', Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
ob_end_clean();
return $response;
}
public function receiptTransactions(Request $request){
$exportsTransactions = new ExportsReceiptTransactions($request);
$response = $exportsTransactions->download('receipt-transactions.xls', Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
ob_end_clean();
return $response;
}
@@ -34,99 +34,123 @@ class ImportStatementInvoiceController
$this->responseMessage = 'You have successfully imported invoice mapping';
}
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, $transactionDate] = $this->mappingTopUp($row, $system);
if ($returnReference) {
// $row['mapped_result_reference'] = $data['owner_reference'];
// $row['payment_received_date'] = date('Y-m-d', strtotime($data['created_at']));
$row['mapped_result_reference'] = $returnReference;
$row['payment_received_date'] = $transactionDate ? date('d-m-Y', strtotime($transactionDate)) : null;
$row['mapped_status'] = 'success';
return $row;
}
}
}
[$returnReference, $transactionDate] = $this->mappingExchange($row);
if ($returnReference) {
$row['mapped_result_reference'] = $returnReference;
$row['payment_received_date'] = date('d-m-Y', strtotime($transactionDate));
$row['mapped_status'] = 'success';
return $row;
}
// 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;
}
/**
* @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;
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();
$import = new GenericImport();
Excel::import($import, $file);
$excelRows = $import->rows;
$excelRows = $excelRows->toArray();
$data = [];
foreach ($excelRows as $row) {
$row['mapped_result_reference'] = null;
$row['payment_received_date'] = 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
// ]);
$data = [];
foreach ($excelRows as $row) {
$row['mapped_result_reference'] = null;
$row['mapped_status'] = 'failed';
$row['date'] = $this->changeExcelDate($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);
if ($returnReference) {
$row['mapped_result_reference'] = $returnReference;
$row['mapped_status'] = 'success';
}
}
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));
}
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 mappingTopUp(Array $row, String $system) {
try {
if ($data = (App()->make(ChecksBillNumber::class))->execute($row['shipping_info'], $system)) {
if ($system == 'izyim' && isset($data['owner_reference'])) return $data['owner_reference'];
// if ($system == 'izyim' && isset($data['owner_reference'])) return $data;
if ($system == 'izyim' && isset($data['owner_reference'])) return [$data['owner_reference'], null];
if ($system == 'exchange') return $this->updateTransactionOwnerReference($data, $row['doc_no']);
}
@@ -137,33 +161,32 @@ class ImportStatementInvoiceController
private function mappingExchange(Array $row) {
$date = $row['date'];
$transactions = Transaction::where('original_amount', $row['net_total'])->whereRaw("DATE(created_at) = '$date'")
->whereHas('receiverCompany', function($q) use($row) {
$q->where('debtor',$row['debtor_code']);
})->get();
if ($transactions && $transactions->count() == 0) {
$transactions = Transaction::where(DB::raw('FLOOR(original_amount)'), floor($row['net_total']))->whereRaw("DATE(created_at) = '$date'")
->whereHas('receiverCompany', function($q) use($row) {
$q->where('debtor',$row['debtor_code']);
})->get();
$transaction = Transaction::getReceiverWithJoinStatementTransactionAndOwner($row)->select('transactions.*')->where('owner_reference', $row['shipping_info'])->first();
if ($transaction && $transaction->count() == 0) {
$transaction = Transaction::getReceiverWithJoinStatementTransactionAndOwner($row)->select('transactions.*')->where('statement_transactions.amount', $row['net_total'])->whereRaw("DATE(posting_date) = '$date'")->first();
}
if ($transactions && $transactions->count() == 1) {
foreach ($transactions as $key => $transaction) {
return $this->updateTransactionOwnerReference($transaction, $row['doc_no']);
}
if ($transaction && $transaction->count() == 0) {
$transaction = Transaction::getReceiverWithJoinStatementTransactionAndOwner($row)->select('transactions.*')->where(DB::raw('FLOOR(statement_transactions.amount)'), floor($row['net_total']))->whereRaw("DATE(posting_date) = '$date'")->first();
}
return false;
if ($transaction && $transaction->count() > 0) {
return $this->updateTransactionOwnerReference($transaction, $row['doc_no']);
}
return [false, false];
}
public function updateTransactionOwnerReference($transaction, String $docNo) {
$transactionOwner = $transaction->transaction_owner;
if ($transactionOwner) {
$transactionOwner->update(['invoice_reference'=>$docNo]);
return $transactionOwner->owner_reference;
$transactionOwner->update([
'invoice_reference'=>$docNo,
'status'=>ApprovalStatus::COMPLETED
]);
return [$transactionOwner->owner_reference, $transaction->created_at];
}
return false;
return [false, false];
}
public function changeExcelDate($date)
@@ -2,31 +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 Carbon\Carbon;
use App\Models\User;
use App\Models\Company;
use App\Models\Segment;
use App\Models\Transaction;
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\Models\Company;
use App\Models\SeasonalSegment;
use App\Models\Transaction;
use App\Models\TransactionMappingLog;
use App\Classes\ValueObjects\Response\ApiResponseObject;
use App\Classes\ValueObjects\Constants\HttpStatus;
use Illuminate\Http\JsonResponse;
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';
@@ -39,63 +43,68 @@ 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'] = $this->changeExcelDate($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';
}
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,
'data'=>$row,
]);
array_push($data, $row);
}
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();
}
private function mappingExchange(Array $row) {
$date = $row['date'];
$transactions = Transaction::where('original_amount', $row['local_payment_amount'])->whereRaw("DATE(created_at) = '$date'")
->whereHas('issuerCompany', function($q) use($row) {
$q->where('debtor',$row['debtor_code']);
})
->get();
if ($transactions && $transactions->count() == 1) {
foreach ($transactions as $key => $transaction) {
return $this->updateTransactionOwnerReference($transaction, $row['doc_no']);
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));
}
}
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($invRefer, $docNo) {
$transactionOwner = StatementTransactionOwner::where('invoice_reference',$invRefer)->whereNull('receipt_reference')->where('status', ApprovalStatus::COMPLETED)->first();
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]);
$transactionOwner->update([
'receipt_reference'=>$docNo,
'status'=>ApprovalStatus::COMPLETED
]);
return $transactionOwner->owner_reference;
}
return false;