From 05ffa39c4e85727f43c7abe37976fb28a3f06a32 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Sun, 4 May 2025 08:37:33 +0800 Subject: [PATCH] E-Invoice - e-Invoice debtor report --- .../Services/ExportsEInvoiceDebtorSummary.php | 105 ++++++++++++++++++ .../Exports/Services/ExportsNullDebtors.php | 46 ++++---- .../ExportCustomersToExcelController.php | 23 +++- .../views/pages/downloads/index.blade.php | 27 ++++- routes/web.php | 19 ++-- 5 files changed, 182 insertions(+), 38 deletions(-) create mode 100644 app/Classes/Modules/Exports/Services/ExportsEInvoiceDebtorSummary.php diff --git a/app/Classes/Modules/Exports/Services/ExportsEInvoiceDebtorSummary.php b/app/Classes/Modules/Exports/Services/ExportsEInvoiceDebtorSummary.php new file mode 100644 index 00000000..69e237fb --- /dev/null +++ b/app/Classes/Modules/Exports/Services/ExportsEInvoiceDebtorSummary.php @@ -0,0 +1,105 @@ +whereNull('debtor')->orWhere('debtor', ''); + })->whereNotIn('id', [2207, 2248, 2029])->where('business_type', BusinessType::IMPORTER)->where('status', ApprovalStatus::APPROVED)->where(function($query){ + $query->whereHas('transactions', function($query){ + return $query->whereIn('type', [TransactionType::PAYMENT, TransactionType::TOP_UP])->whereIn('transactions.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED, ApprovalStatus::PENDING_VERIFICATION]); + })->orWhereHas('wallets', function($query){ + return $query->whereHas('transactions'); + }); + }); + } + + /** + * @param Company $company + * + * @return array + */ + public function map($company): array + { + return [ + '<>', // Code + 'TODO', // Need Tax INV? + 'TODO', // Request Date + 'TODO', // TIN NO. + '300-0000', // DebtorControlAcc + '300-0000', // ControlAccount + $company->name.' (PURCHASE)', // CompanyName + $company->reference, // Desc2 + '', // DebtorType + 'PIA', // DisplayTerm + 'MYR', // CurrencyCode + '', // RegisterNo + '', // Address1 + '', // Address2 + '', // Address3 + '', // PostCode + '', // DeliverAddr1 + '', // DeliverAddr2 + '', // DeliverAddr3 + '', // DeliverPostCode + '', // EmailAddress + '', // Attention + '', // Phone1 + '', // Phone2 + '', // Fax1 + ]; + } +} diff --git a/app/Classes/Modules/Exports/Services/ExportsNullDebtors.php b/app/Classes/Modules/Exports/Services/ExportsNullDebtors.php index 53a71772..11e48130 100644 --- a/app/Classes/Modules/Exports/Services/ExportsNullDebtors.php +++ b/app/Classes/Modules/Exports/Services/ExportsNullDebtors.php @@ -72,28 +72,28 @@ class ExportsNullDebtors implements FromQuery, WithHeadings, WithHeadingRow, Wit public function map($company): array { return [ - '<>', - '300-0000', - '300-0000', - $company->name.' (PURCHASE)', - $company->reference, - '', - 'PIA', - 'MYR', - '', - '', - '', - '', - '', - '', - '', - '', - '', - '',//EmailAddress - '', - '', - '', - '' + '<>', // Code + '300-0000', // DebtorControlAcc + '300-0000', // ControlAccount + $company->name.' (PURCHASE)', // CompanyName + $company->reference, // Desc2 + '', // DebtorType + 'PIA', // DisplayTerm + 'MYR', // CurrencyCode + '', // RegisterNo + '', // Address1 + '', // Address2 + '', // Address3 + '', // PostCode + '', // DeliverAddr1 + '', // DeliverAddr2 + '', // DeliverAddr3 + '', // DeliverPostCode + '', // EmailAddress + '', // Attention + '', // Phone1 + '', // Phone2 + '', // Fax1 ]; } -} \ No newline at end of file +} diff --git a/app/Http/Controllers/Exports/ExportCustomersToExcelController.php b/app/Http/Controllers/Exports/ExportCustomersToExcelController.php index b693f326..ddb1fb96 100644 --- a/app/Http/Controllers/Exports/ExportCustomersToExcelController.php +++ b/app/Http/Controllers/Exports/ExportCustomersToExcelController.php @@ -13,15 +13,16 @@ use App\Classes\Modules\Exports\Services\ExportsNullDebtors; use App\Classes\Modules\Exports\Services\ExportsPaymentTransactions; use App\Classes\Modules\Exports\Services\ExportsWalletTransactions; use App\Classes\Modules\Exports\Services\ExportsInvoiceTransactions; +use App\Classes\Modules\Exports\Services\ExportsReceiptTransactions; +use App\Classes\Modules\Exports\Services\ExportsImportedReceiptMappeds; +use App\Classes\Modules\Exports\Services\ExportsWhiteFormTransactions; +use App\Classes\Modules\Exports\Services\ExportsImportedInvoiceMappeds; +use App\Classes\Modules\Exports\Services\ExportsEInvoiceDebtorSummary; use App\Models\User; use Illuminate\Http\Request; 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; -use App\Classes\Modules\Exports\Services\ExportsImportedReceiptMappeds; -use App\Classes\Modules\Exports\Services\ExportsWhiteFormTransactions; use Illuminate\Support\Facades\Storage; use App\Classes\General\AWSS3Helper; use Illuminate\Support\Carbon; @@ -241,5 +242,17 @@ class ExportCustomersToExcelController return $response; } } -} + public function eInvoiceDebtorSummary(ExportsEInvoiceDebtorSummary $exportsEInvoiceDebtorSummary, Request $request){ + $exportFileName = 'EINV_DEBTOR_SUMMARY.xls'; + $filesystemDriver = Storage::getDefaultDriver(); + if($filesystemDriver === 's3'){ + return response([ 'src' => AWSS3Helper::S3Exportable($exportFileName, $exportsEInvoiceDebtorSummary) ]); + } + else{ + $response = $exportsEInvoiceDebtorSummary->download($exportFileName, Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']); + ob_end_clean(); + return $response; + } + } +} diff --git a/resources/views/pages/downloads/index.blade.php b/resources/views/pages/downloads/index.blade.php index bb03689d..57d39696 100644 --- a/resources/views/pages/downloads/index.blade.php +++ b/resources/views/pages/downloads/index.blade.php @@ -66,9 +66,34 @@
+
+
+
+ nullDebtor.xls +

New Debtors Report from settings page

+
+ + Download + +
+
+
+ +
+
+
+
+
+ EINV_DEBTOR_SUMMARY.xls +

e-Invoice Debtor Summary Report

+
+ + Download + +
+
- diff --git a/routes/web.php b/routes/web.php index 1014aea6..7fd4d49c 100644 --- a/routes/web.php +++ b/routes/web.php @@ -326,6 +326,7 @@ Route::get('/export/analytic/booking', 'Exports\ExportAnalyticToExcelController@ Route::get('/export/analytic/bills', 'Exports\ExportAnalyticToExcelController@billingData')->name('billingData.export');; Route::get('/export/customers/leads', 'Exports\ExportCustomersToExcelController@leadsData')->name('leads.export'); route::get('/export/excel/{id}', 'Exports\ExportCustomersToExcelController@exportCurrencyVendorOrder')->name('group.excel'); +Route::get('/export/einv-debtor/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@eInvoiceDebtorSummary')->name('eInvoiceDebtorSummary.export'); Route::get('/products', function (\App\Classes\Modules\Exports\Services\ExportsProducts $exportsProducts) { $bookings = Booking::where(function($query){ @@ -1202,42 +1203,42 @@ Route::get('/show-white-form-transactions-in-date-range/{from_date}/{to_date}', const fileInput = form.querySelector("input[type=\'file\']"); const files = fileInput.files; const userToken = localStorage.getItem("user-token"); - + if (files.length === 0) { alert("Please select at least one file to upload."); return; } - + const fileReaders = []; let totalFiles = files.length; - + // Create a promise for each file to read it as Base64 Array.from(files).forEach((file) => { const reader = new FileReader(); - + // Create a promise that resolves when the file is read const fileReadPromise = new Promise((resolve, reject) => { reader.onload = (event) => { resolve(event.target.result); }; - + reader.onerror = (error) => { reject(error); }; - + reader.readAsDataURL(file); // Read the file as Data URL (Base64) }); - + fileReaders.push(fileReadPromise); }); - + // Wait for all files to be read Promise.all(fileReaders) .then((fileData) => { const payload = { files: fileData, // Array of objects with name, type, and Base64 content }; - + // Send the payload as JSON return fetch(`/api/v1/transactions/${billId}/bill/verification`, { method: "POST",