mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 04:23:55 +00:00
E-Invoice - Automapping Issues, Receive Payment for Booking Report (Export)
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Exports\Services;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\KVPKey;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Transaction;
|
||||
use App\Models\Wallet;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\FromQuery;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ExportsReceivePaymentForBookingReport implements FromQuery, WithHeadings, WithHeadingRow, WithMapping, ShouldAutoSize
|
||||
{
|
||||
use Exportable;
|
||||
|
||||
protected $startDate;
|
||||
protected $endDate;
|
||||
|
||||
public function __construct($startDate = null, $endDate = null) {
|
||||
$this->startDate = $startDate ? Carbon::parse($startDate)->startOfDay() : Carbon::now()->subMonths(1);
|
||||
$this->endDate = $endDate ? Carbon::parse($endDate)->endOfDay() : Carbon::now();
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'DocNo',
|
||||
'Docdate',
|
||||
'DebtorCode',
|
||||
'Description',
|
||||
'DeptNo',
|
||||
'PaymentMethod',
|
||||
'PaymentAmt',
|
||||
'KnockOffDocNo',
|
||||
'KnockOffAmt',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection|mixed
|
||||
*/
|
||||
public function query()
|
||||
{
|
||||
$type = TransactionType::PAYMENT;
|
||||
$query = Transaction::query();
|
||||
// $query->where('owner_type', '!=', Wallet::class);
|
||||
$query->where('type', $type);
|
||||
$query->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
|
||||
$query->whereBetween('created_at', [$this->startDate, $this->endDate]);
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Transaction $transaction
|
||||
* @return array
|
||||
*/
|
||||
public function map($transaction): array
|
||||
{
|
||||
$autoCountSalesInvoiceId = null;
|
||||
$formattedDocumentDate = Carbon::parse($transaction->created_at)->format('m/d/Y');
|
||||
$owner = $transaction->owner;
|
||||
$booking = null;
|
||||
if($owner instanceof Booking){
|
||||
$booking = $owner;
|
||||
$company = $booking->company;
|
||||
}
|
||||
else{
|
||||
$company = $owner->owner;
|
||||
}
|
||||
|
||||
if($booking){
|
||||
$metadata = $booking->attributesKVP()->where('key', KVPKey::AUTOCOUNT_DOCNO)->first();
|
||||
if($metadata){
|
||||
$autoCountSalesInvoiceId = $metadata->value;
|
||||
}
|
||||
}
|
||||
|
||||
if($transaction->payment_method == PaymentMethodType::WALLET){
|
||||
if($owner instanceof Wallet){
|
||||
return[];
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
'<<New>>', //DocNo
|
||||
$formattedDocumentDate, //DocDate
|
||||
$company ? $company->debtor : '', //DebtorCode
|
||||
'Payment for ' . $autoCountSalesInvoiceId ?? '', //Description
|
||||
'C', //DeptNo
|
||||
'SALES DEPOSIT - EXC', //PaymentMethod
|
||||
number_format($transaction->amount, 2), //PaymentAmt
|
||||
$autoCountSalesInvoiceId ?? '', //KnockOffDocNo
|
||||
number_format($transaction->amount, 2), //KnockOffAmt
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -11,148 +11,76 @@ use App\Classes\General\AWSS3Helper;
|
||||
use App\Classes\Modules\Exports\Services\ExportsARCreditNoteReport;
|
||||
use App\Classes\Modules\Exports\Services\ExportsCompanies;
|
||||
use App\Classes\Modules\Exports\Services\ExportsReceivePaymentDepositEntryReport;
|
||||
use App\Classes\Modules\Exports\Services\ExportsReceivePaymentForBookingReport;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class ExportController
|
||||
{
|
||||
public function salesInvoices(Request $request){
|
||||
$validated = $request->validate([
|
||||
'startDate' => 'nullable|date_format:d-m-Y',
|
||||
'endDate' => 'nullable|date_format:d-m-Y|after_or_equal:startDate',
|
||||
]);
|
||||
|
||||
$startDate = null;
|
||||
$endDate = null;
|
||||
|
||||
if (isset($validated['startDate']) && $validated['startDate']) {
|
||||
$startDate = Carbon::createFromFormat('d-m-Y', $validated['startDate'])->startOfDay();
|
||||
} else {
|
||||
$startDate = Carbon::now()->subMonths(1)->startOfDay();
|
||||
}
|
||||
|
||||
if (isset($validated['endDate']) && $validated['endDate']) {
|
||||
$endDate = Carbon::createFromFormat('d-m-Y', $validated['endDate'])->endOfDay();
|
||||
} else {
|
||||
$endDate = Carbon::now()->endOfDay();
|
||||
}
|
||||
|
||||
|
||||
$exportsTransactions = new ExportsSalesInvoiceReport($startDate, $endDate);
|
||||
|
||||
$exportFileName = 'Exchange - Sales Invoice Report.xls';
|
||||
$filesystemDriver = Storage::getDefaultDriver();
|
||||
if($filesystemDriver === 's3'){
|
||||
return response([ 'src' => AWSS3Helper::S3Exportable($exportFileName, $exportsTransactions) ]);
|
||||
}
|
||||
else{
|
||||
$response = $exportsTransactions->download($exportFileName, Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
|
||||
ob_end_clean();
|
||||
}
|
||||
return $response;
|
||||
[$startDate, $endDate] = $this->getValidatedDates($request);
|
||||
$exporter = new ExportsSalesInvoiceReport($startDate, $endDate);
|
||||
return $this->handleExport($exporter, 'Exchange - Sales Invoice Report.xls');
|
||||
}
|
||||
|
||||
public function companies(Request $request){
|
||||
[$startDate, $endDate] = $this->getValidatedDates($request);
|
||||
$exporter = new ExportsCompanies($startDate, $endDate);
|
||||
return $this->handleExport($exporter, 'Exchange - Customers Data Report.xls');
|
||||
}
|
||||
|
||||
public function arCreditNote(Request $request){
|
||||
[$startDate, $endDate] = $this->getValidatedDates($request);
|
||||
$exporter = new ExportsARCreditNoteReport($startDate, $endDate);
|
||||
return $this->handleExport($exporter, 'Exchange - AR Credit Note Report.xls');
|
||||
}
|
||||
|
||||
public function receivePaymentDepositEntry(Request $request){
|
||||
[$startDate, $endDate] = $this->getValidatedDates($request);
|
||||
$exporter = new ExportsReceivePaymentDepositEntryReport($startDate, $endDate);
|
||||
return $this->handleExport($exporter, '01D - EXCHANGE - RECEIVE PAYMENT (FULL PAYMENT) [AR DEPOSIT ENTRY].xls');
|
||||
}
|
||||
|
||||
public function receivePaymentDepositForBooking(Request $request){
|
||||
[$startDate, $endDate] = $this->getValidatedDates($request);
|
||||
$exporter = new ExportsReceivePaymentForBookingReport($startDate, $endDate);
|
||||
return $this->handleExport($exporter, '01R- RECEIVE PAYMENT (FULL PAYMENT) [AR RECEIVE PAYMENT].xls');
|
||||
}
|
||||
|
||||
private function getValidatedDates(Request $request): array
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'startDate' => 'nullable|date_format:d-m-Y',
|
||||
'endDate' => 'nullable|date_format:d-m-Y|after_or_equal:startDate',
|
||||
]);
|
||||
|
||||
$startDate = null;
|
||||
$endDate = null;
|
||||
$startDate = isset($validated['startDate']) && $validated['startDate']
|
||||
? Carbon::createFromFormat('d-m-Y', $validated['startDate'])->startOfDay()
|
||||
: Carbon::now()->subMonth()->startOfDay();
|
||||
|
||||
if (isset($validated['startDate']) && $validated['startDate']) {
|
||||
$startDate = Carbon::createFromFormat('d-m-Y', $validated['startDate'])->startOfDay();
|
||||
} else {
|
||||
$startDate = Carbon::now()->subMonths(1)->startOfDay();
|
||||
}
|
||||
$endDate = isset($validated['endDate']) && $validated['endDate']
|
||||
? Carbon::createFromFormat('d-m-Y', $validated['endDate'])->endOfDay()
|
||||
: Carbon::now()->endOfDay();
|
||||
|
||||
if (isset($validated['endDate']) && $validated['endDate']) {
|
||||
$endDate = Carbon::createFromFormat('d-m-Y', $validated['endDate'])->endOfDay();
|
||||
} else {
|
||||
$endDate = Carbon::now()->endOfDay();
|
||||
}
|
||||
|
||||
$exportsCompanies = new ExportsCompanies($startDate, $endDate);
|
||||
|
||||
$exportFileName = 'Exchange - Customers Data Report.xls';
|
||||
$filesystemDriver = Storage::getDefaultDriver();
|
||||
if($filesystemDriver === 's3'){
|
||||
return response([ 'src' => AWSS3Helper::S3Exportable($exportFileName, $exportsCompanies) ]);
|
||||
}
|
||||
else{
|
||||
$response = $exportsCompanies->download($exportFileName, Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
|
||||
ob_end_clean();
|
||||
}
|
||||
return $response;
|
||||
return [$startDate, $endDate];
|
||||
}
|
||||
|
||||
public function arCreditNote(Request $request){
|
||||
$validated = $request->validate([
|
||||
'startDate' => 'nullable|date_format:d-m-Y',
|
||||
'endDate' => 'nullable|date_format:d-m-Y|after_or_equal:startDate',
|
||||
]);
|
||||
|
||||
$startDate = null;
|
||||
$endDate = null;
|
||||
|
||||
if (isset($validated['startDate']) && $validated['startDate']) {
|
||||
$startDate = Carbon::createFromFormat('d-m-Y', $validated['startDate'])->startOfDay();
|
||||
} else {
|
||||
$startDate = Carbon::now()->subMonths(1)->startOfDay();
|
||||
}
|
||||
|
||||
if (isset($validated['endDate']) && $validated['endDate']) {
|
||||
$endDate = Carbon::createFromFormat('d-m-Y', $validated['endDate'])->endOfDay();
|
||||
} else {
|
||||
$endDate = Carbon::now()->endOfDay();
|
||||
}
|
||||
|
||||
$exportsTransactions = new ExportsARCreditNoteReport($startDate, $endDate);
|
||||
|
||||
$exportFileName = 'Exchange - AR Credit Note Report.xls';
|
||||
private function handleExport($exporter, string $exportFileName)
|
||||
{
|
||||
$filesystemDriver = Storage::getDefaultDriver();
|
||||
if($filesystemDriver === 's3'){
|
||||
return response([ 'src' => AWSS3Helper::S3Exportable($exportFileName, $exportsTransactions) ]);
|
||||
}
|
||||
else{
|
||||
$response = $exportsTransactions->download($exportFileName, Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
|
||||
ob_end_clean();
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
|
||||
public function receivePaymentDepositEntry(Request $request){
|
||||
$validated = $request->validate([
|
||||
'startDate' => 'nullable|date_format:d-m-Y',
|
||||
'endDate' => 'nullable|date_format:d-m-Y|after_or_equal:startDate',
|
||||
]);
|
||||
|
||||
$startDate = null;
|
||||
$endDate = null;
|
||||
|
||||
if (isset($validated['startDate']) && $validated['startDate']) {
|
||||
$startDate = Carbon::createFromFormat('d-m-Y', $validated['startDate'])->startOfDay();
|
||||
} else {
|
||||
$startDate = Carbon::now()->subMonths(1)->startOfDay();
|
||||
if ($filesystemDriver === 's3') {
|
||||
return response([
|
||||
'src' => AWSS3Helper::S3Exportable($exportFileName, $exporter)
|
||||
]);
|
||||
}
|
||||
|
||||
if (isset($validated['endDate']) && $validated['endDate']) {
|
||||
$endDate = Carbon::createFromFormat('d-m-Y', $validated['endDate'])->endOfDay();
|
||||
} else {
|
||||
$endDate = Carbon::now()->endOfDay();
|
||||
}
|
||||
$response = $exporter->download(
|
||||
$exportFileName,
|
||||
Excel::XLS,
|
||||
['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']
|
||||
);
|
||||
|
||||
$exportsTransactions = new ExportsReceivePaymentDepositEntryReport($startDate, $endDate);
|
||||
|
||||
$exportFileName = '01D - EXCHANGE - RECEIVE PAYMENT (FULL PAYMENT) [AR DEPOSIT ENTRY].xls';
|
||||
$filesystemDriver = Storage::getDefaultDriver();
|
||||
if($filesystemDriver === 's3'){
|
||||
return response([ 'src' => AWSS3Helper::S3Exportable($exportFileName, $exportsTransactions) ]);
|
||||
}
|
||||
else{
|
||||
$response = $exportsTransactions->download($exportFileName, Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
|
||||
ob_end_clean();
|
||||
}
|
||||
ob_end_clean(); // prevent corrupt download in some environments
|
||||
return $response;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,6 +116,7 @@ export default {
|
||||
'Sales Invoice Report',
|
||||
'Customers Report',
|
||||
'01D - RECEIVE PAYMENT (FULL PAYMENT) [AR DEPOSIT ENTRY]',
|
||||
'01R - RECEIVE PAYMENT (FULL PAYMENT) [AR RECEIVE PAYMENT]',
|
||||
'Credit Note Report',
|
||||
];
|
||||
},
|
||||
@@ -125,10 +126,11 @@ export default {
|
||||
const reportType = this.parameters.reportType;
|
||||
|
||||
const routesMap = {
|
||||
'Sales Invoice Report': route('api.export.bookings.sales-invoices'),
|
||||
'Customers Report': route('api.export.companies.customers-data'),
|
||||
'01D - RECEIVE PAYMENT (FULL PAYMENT) [AR DEPOSIT ENTRY]': route('api.export.transactions.receive-payment-deposit-entry'),
|
||||
'Credit Note Report': route('api.export.transactions.ar-credit-note'),
|
||||
'Sales Invoice Report': route('api.export.bookings.sales_invoices'),
|
||||
'Customers Report': route('api.export.companies.customers_data'),
|
||||
'01D - RECEIVE PAYMENT (FULL PAYMENT) [AR DEPOSIT ENTRY]': route('api.export.transactions.receive_payment_deposit_entry'),
|
||||
'01R - RECEIVE PAYMENT (FULL PAYMENT) [AR RECEIVE PAYMENT]': route('api.export.transactions.receive_payment_for_booking'),
|
||||
'Credit Note Report': route('api.export.transactions.ar_credit_note'),
|
||||
};
|
||||
|
||||
let url = `${routesMap[reportType]}?startDate=${this.parameters.startDate}&endDate=${this.parameters.endDate}`;
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
report_type: this.reportType
|
||||
};
|
||||
|
||||
this.submit(this.route('api.import.sales-invoices'), 'post', this.section, true, true);
|
||||
this.submit(this.route('api.import.sales_invoices'), 'post', this.section, true, true);
|
||||
}
|
||||
},
|
||||
mixins: [ModalFromHandler]
|
||||
|
||||
+6
-5
@@ -7,17 +7,18 @@ use Illuminate\Support\Facades\Route;
|
||||
|
||||
Route::group(['prefix' => 'export', 'as' => 'export.', 'namespace' => 'Exports'], function () {
|
||||
Route::group(['prefix' => 'bookings', 'as' => 'bookings.'], function () {
|
||||
Route::get('/sales-invoices', [ExportController::class, 'salesInvoices'])->name('sales-invoices');
|
||||
Route::get('/sales-invoices', [ExportController::class, 'salesInvoices'])->name('sales_invoices');
|
||||
});
|
||||
Route::group(['prefix' => 'companies', 'as' => 'companies.'], function () {
|
||||
Route::get('/customers-data', [ExportController::class, 'companies'])->name('customers-data');
|
||||
Route::get('/customers-data', [ExportController::class, 'companies'])->name('customers_data');
|
||||
});
|
||||
Route::group(['prefix' => 'transactions', 'as' => 'transactions.'], function () {
|
||||
Route::get('/ar-credit-note', [ExportController::class, 'arCreditNote'])->name('ar-credit-note');
|
||||
Route::get('/receive-payment-deposit-entry', [ExportController::class, 'receivePaymentDepositEntry'])->name('receive-payment-deposit-entry');
|
||||
Route::get('/ar-credit-note', [ExportController::class, 'arCreditNote'])->name('ar_credit_note');
|
||||
Route::get('/receive-payment-deposit-entry', [ExportController::class, 'receivePaymentDepositEntry'])->name('receive_payment_deposit_entry');
|
||||
Route::get('/receive-payment-for-booking', [ExportController::class, 'receivePaymentDepositForBooking'])->name('receive_payment_for_booking');
|
||||
});
|
||||
});
|
||||
|
||||
Route::group(['prefix' => 'import', 'as' => 'import.', 'namespace' => 'Imports'], function () {
|
||||
Route::post('/import', [ImportController::class, 'salesInvoices'])->name('sales-invoices');
|
||||
Route::post('/import', [ImportController::class, 'salesInvoices'])->name('sales_invoices');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user