mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-23 14:33:59 +00:00
code for import receipts
This commit is contained in:
@@ -33,12 +33,19 @@ class ExportsInvoiceTransactions implements FromQuery, WithHeadings, WithHeading
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'DocNo',
|
||||
'DocDate',
|
||||
'DebtorCode',
|
||||
'Ref',
|
||||
'DebtorName',
|
||||
$header = [];
|
||||
if ($this->request->input('type') == 'invoices') {
|
||||
$header[] = 'DocNo';
|
||||
$header[] = 'DocDate';
|
||||
$header[] = 'DebtorCode';
|
||||
} else {
|
||||
$header[] = 'OrNo';
|
||||
$header[] = 'OrDate';
|
||||
$header[] = 'CreditorCode';
|
||||
}
|
||||
$header[] = 'Ref';
|
||||
$header[] = ($this->request->input('type') == 'invoices' ? 'DebtorName' : 'CreditorName');
|
||||
$header = array_merge($header, [
|
||||
'CurrencyCode',
|
||||
'ShipInfo',
|
||||
'ItemCode',
|
||||
@@ -48,7 +55,8 @@ class ExportsInvoiceTransactions implements FromQuery, WithHeadings, WithHeading
|
||||
'UnitPrice',
|
||||
'AccNo',
|
||||
'DeptNo'
|
||||
];
|
||||
]);
|
||||
return $header;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -61,7 +61,7 @@ class ExportCustomersToExcelController
|
||||
|
||||
public function invoiceTransactions(Request $request){
|
||||
$exportsTransactions = new ExportsInvoiceTransactions($request);
|
||||
$response = $exportsTransactions->download('invoice-transactions.xls', Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
|
||||
$response = $exportsTransactions->download(($request->input('type') == 'invoices' ? 'invoice-transactions' : 'receipt-transactions').'.xls', Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
|
||||
ob_end_clean();
|
||||
return $response;
|
||||
}
|
||||
@@ -79,7 +79,7 @@ class ExportCustomersToExcelController
|
||||
}
|
||||
|
||||
public function importedInvoiceMapped(ExportsImportedInvoiceMappeds $exportsImportedInvoiceMappeds, Request $request) {
|
||||
$response = $exportsImportedInvoiceMappeds->download('InvoiceMapped.xls', Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
|
||||
$response = $exportsImportedInvoiceMappeds->download($request->input('fileName').'.xls', Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
|
||||
ob_end_clean();
|
||||
return $response;
|
||||
}
|
||||
|
||||
@@ -17,9 +17,21 @@ 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;
|
||||
|
||||
class ImportStatementReceiptsController
|
||||
{
|
||||
private $responseTitle;
|
||||
private $responseMessage;
|
||||
|
||||
public function __construct() {
|
||||
$this->responseTitle = 'Import Receipt Mapping';
|
||||
$this->responseMessage = 'You have successfully imported receipt mapping';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return array
|
||||
@@ -27,6 +39,7 @@ 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;
|
||||
|
||||
@@ -35,10 +48,57 @@ class ImportStatementReceiptsController
|
||||
$excelRows = $import->rows;
|
||||
$excelRows = $excelRows->toArray();
|
||||
|
||||
$data = [];
|
||||
foreach ($excelRows as $row) {
|
||||
// if has date column
|
||||
// $transactionDate = $this->changeExcelDate($row['date']);
|
||||
$row['mapped_result_reference'] = null;
|
||||
$row['mapped_status'] = 'failed';
|
||||
$row['date'] = $this->changeExcelDate($row['doc_date']);
|
||||
|
||||
$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);
|
||||
}
|
||||
|
||||
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']);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function updateTransactionOwnerReference($transaction, String $docNo) {
|
||||
$transactionOwner = $transaction->transaction_owner;
|
||||
if ($transactionOwner) {
|
||||
$transactionOwner->update(['receipt_reference'=>$docNo]);
|
||||
return $transactionOwner->owner_reference;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public function changeExcelDate($date)
|
||||
|
||||
+26
-16
@@ -7,7 +7,7 @@
|
||||
<div class="col-12">
|
||||
<div class="card">
|
||||
<div class="card-header">
|
||||
<h3>Imported Invoice Mapped</h3>
|
||||
<h3>{{ componentTitle }}</h3>
|
||||
<div class="text-right">
|
||||
<button class="btn btn-xs btn-outline-success b-rad-none m-r-5" @click="downloadInvoiceMapped">
|
||||
Download Invoices Mapped
|
||||
@@ -19,16 +19,7 @@
|
||||
<table class="table table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>No</th>
|
||||
<th>Doc No</th>
|
||||
<th>Date</th>
|
||||
<th>Debtor Code</th>
|
||||
<th>Debtor Name</th>
|
||||
<th>Shipping Info</th>
|
||||
<th>Net Total</th>
|
||||
<th>Cancelled</th>
|
||||
<th>Mapped Status</th>
|
||||
<th>Mapped Reference No</th>
|
||||
<th v-for="item in tableHeaders">{{ item }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody v-show="!isLoading">
|
||||
@@ -65,11 +56,18 @@
|
||||
props: {
|
||||
files: {
|
||||
required: true
|
||||
}
|
||||
},
|
||||
type: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
section:{
|
||||
type: String,
|
||||
required: true
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
section: 'importInvoiceMapping',
|
||||
isLoading: false,
|
||||
importedDate: null,
|
||||
}
|
||||
@@ -87,16 +85,27 @@
|
||||
},
|
||||
},
|
||||
created(){
|
||||
this.appendComponentTitle();
|
||||
this.appendComponentTableHeader();
|
||||
this.$store.dispatch('updateListQueue', {'name': this.section});
|
||||
},
|
||||
methods: {
|
||||
appendComponentTitle() {
|
||||
this.componentTitle = this.section == 'importInvoiceMapping' ? 'Imported Invoices Mapped' : 'Imported Receipts Mapped';
|
||||
},
|
||||
appendComponentTableHeader() {
|
||||
if (this.section == 'importInvoiceMapping') {
|
||||
this.tableHeaders = ['No','Doc No','Date','Debtor Code','Debtor Name','Shipping Info','Net Total','Cancelled','Mapped Status','Mapped Reference No'];
|
||||
} else {
|
||||
this.tableHeaders = ['No','OR No','Date','Creditor Code','Creditor Name','Shipping Info','Net Total','Cancelled','Mapped Status','Mapped Reference No'];
|
||||
}
|
||||
},
|
||||
importInvoice(){
|
||||
this.isLoading = true;
|
||||
this.parameters = {
|
||||
files: this.files
|
||||
};
|
||||
|
||||
this.submit(this.route('api.import_invoices.upload'), 'post', this.section, true, false);
|
||||
this.submit(this.route('api.'+(this.section == 'importInvoiceMapping' ? 'import_invoices' : 'import_receipts')+'.upload'), 'post', this.section, true, false);
|
||||
},
|
||||
|
||||
successHandler(response){
|
||||
@@ -107,8 +116,9 @@
|
||||
|
||||
downloadInvoiceMapped() {
|
||||
var arrDateTime = this.importedDate.split(" ");
|
||||
const fileName = this.section == 'importInvoiceMapping' ? 'InvoiceMapped' : 'ReceiptMapped';
|
||||
|
||||
window.open(this.route('importedInvoiceMapped.export')+'?date='+arrDateTime[0]+'&time='+arrDateTime[1], '_blank');
|
||||
window.open(this.route('importedInvoiceMapped.export')+'?date='+arrDateTime[0]+'&time='+arrDateTime[1]+'&fileName='+fileName, '_blank');
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
+19
-10
@@ -138,7 +138,7 @@
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<modal-component class="animate__animated animate__fast animate__fadeIn" styleType="fill-in" type="ModalImportInvoice">
|
||||
<imported-invoice-mapped-component v-if="mappedTrue" :files="files"></imported-invoice-mapped-component>
|
||||
<imported-invoice-mapped-component section="importInvoiceMapping" v-if="mappedTrue" :files="files"></imported-invoice-mapped-component>
|
||||
</modal-component>
|
||||
</div>
|
||||
</div>
|
||||
@@ -146,7 +146,8 @@
|
||||
</div>
|
||||
<div class="row text-center m-t-50 m-b-50 p-t-50 p-b-50" v-show="exportStage === 2">
|
||||
<div class="col">
|
||||
<div class="btn btn-lg btn-primary" @click="exportStage++">Export Receipts To AutoCount</div>
|
||||
<div class="btn btn-lg btn-primary" @click="exportReceiptToAutoCount">Export Receipts To AutoCount</div>
|
||||
<!-- todo-new: delete later --><br><div class="btn btn-lg btn-primary m-t-20" @click="exportStage++">Nest Step</div>
|
||||
<br>
|
||||
<div class="row">
|
||||
<div class="col">
|
||||
@@ -165,7 +166,7 @@
|
||||
</file-input-component>
|
||||
</div>
|
||||
</div>
|
||||
<div class="btn btn-lg btn-primary m-t-20" @click="importReceipts">Import Receipts</div>
|
||||
<div class="btn btn-lg btn-primary m-t-20 requestModal" data-type="ModalImportInvoice" @click="importReceipts">Import Receipts</div>
|
||||
<!-- todo-new: delete later --><br><div class="btn btn-lg btn-primary m-t-20" @click="exportStage++">Nest Step</div>
|
||||
<br>
|
||||
<div class="row">
|
||||
@@ -173,6 +174,13 @@
|
||||
<a href="https://docs.google.com/presentation/d/1xMiWjU1hqPaihMhbgflFSDsu1sC_0Lk7OFmwDaXVt-w/edit?usp=sharing" target="_blank">Learn How to do this step?</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<modal-component class="animate__animated animate__fast animate__fadeIn" styleType="fill-in" type="ModalImportInvoice">
|
||||
<imported-invoice-mapped-component section="importReceiptMapping" v-if="mappedTrue" :files="files"></imported-invoice-mapped-component>
|
||||
</modal-component>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row text-center m-t-50 m-b-50 p-t-50 p-b-50" v-show="exportStage === 4">
|
||||
@@ -216,19 +224,20 @@ export default {
|
||||
this.mappedTrue = true;
|
||||
},
|
||||
importReceipts(){
|
||||
this.parameters = {
|
||||
files: this.files
|
||||
};
|
||||
this.submit(this.route('api.import_receipts.upload'), 'post', this.section, true, false);
|
||||
this.mappedTrue = true;
|
||||
},
|
||||
exportInvoiceToAutoCount(){
|
||||
window.open(this.route('invoiceTransactions.export')+'?bankStatementOwnerId='+this.getCheckedStatementOwners()+'&type=invoices', '_blank');
|
||||
},
|
||||
exportReceiptToAutoCount(){
|
||||
window.open(this.route('invoiceTransactions.export')+'?bankStatementOwnerId='+this.getCheckedStatementOwners()+'&type=receipts', '_blank');
|
||||
},
|
||||
getCheckedStatementOwners() {
|
||||
let bankStatementOwnerId = [];
|
||||
$('.request_export_item:checked').each(function() {
|
||||
bankStatementOwnerId.push($(this).val());
|
||||
});
|
||||
|
||||
bankStatementOwnerId = JSON.stringify(bankStatementOwnerId);
|
||||
window.open(this.route('invoiceTransactions.export')+'?bankStatementOwnerId='+bankStatementOwnerId, '_blank');
|
||||
return JSON.stringify(bankStatementOwnerId);
|
||||
},
|
||||
successHandler(){
|
||||
this.step += 1;
|
||||
|
||||
Reference in New Issue
Block a user