Merge branch 'dillon/90-e-invoice-e-1' into vapor/development

This commit is contained in:
Dillon Ngo
2025-08-26 07:49:45 +08:00
13 changed files with 125 additions and 18 deletions
@@ -82,18 +82,24 @@ class BatchBookingsGenerateEInvoiceLogic extends AbstractControllerLogic
$endDate = $endDate ? Carbon::parse($endDate)->endOfDay() : Carbon::now();
$bookings = Booking::where('status', ApprovalStatus::COMPLETED)
->whereBetween('created_at', [$startDate, $endDate])
// ->whereBetween('created_at', [$startDate, $endDate])
->whereHas('transactions', function ($query) use ($startDate, $endDate) {
$query->payments()
->complete()
->whereBetween('created_at', [$startDate, $endDate])
->latest('created_at');
})
->whereHas('attributesKVP', function (Builder $query) {
$query->where('key', KVPKey::AUTOCOUNT_DOCNO);
$query->where('key', KVPKey::AUTOCOUNT_DOCNO_INVOICE);
})
->with(['attributesKVP' => function ($query) {
$query->where('key', KVPKey::AUTOCOUNT_DOCNO);
$query->where('key', KVPKey::AUTOCOUNT_DOCNO_INVOICE);
}])
->get();
foreach ($bookings as $booking) {
// $autocountValue = optional($booking->attributesKVP->first())->value;
//Log::info('Booking ID: ' . $booking->marking . ' | AUTOCOUNT_DOCNO: ' . $autocountValue);
//$autocountValue = optional($booking->attributesKVP->first())->value;
//Log::info('Booking ID: ' . $booking->marking . ' | AUTOCOUNT_DOCNO_INVOICE: ' . $autocountValue);
// $this->regenerateInvoiceBookingProcessor->execute($booking);
ProcessBookingForEInvoiceV2CommandJob::dispatch($booking);
}
@@ -96,7 +96,7 @@ class ExportsARCreditNoteReport implements FromQuery, WithHeadings, WithHeadingR
}
$booking = $refundTransaction->owner->booking;
if($booking){
$metadata = $booking->attributesKVP()->where('key', KVPKey::AUTOCOUNT_DOCNO)->first();
$metadata = $booking->attributesKVP()->where('key', KVPKey::AUTOCOUNT_DOCNO_INVOICE)->first();
if($metadata){
$autoCountSalesInvoiceId = $metadata->value;
}
@@ -80,7 +80,7 @@ class ExportsReceivePaymentForBookingReport implements FromQuery, WithHeadings,
}
if($booking){
$metadata = $booking->attributesKVP()->where('key', KVPKey::AUTOCOUNT_DOCNO)->first();
$metadata = $booking->attributesKVP()->where('key', KVPKey::AUTOCOUNT_DOCNO_INVOICE)->first();
if($metadata){
$autoCountSalesInvoiceId = $metadata->value;
}
@@ -0,0 +1,81 @@
<?php
namespace App\Classes\Modules\Exports\Services;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
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 ExportsWalletTopUpDepositEntryReport 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',
'DebtorCode',
'DocDate',
'Description',
'DeptNo',
'DepositPaymentMethod',
'CurrencyCode',
'PaymentMethod',
'PaymentAmt',
];
}
/**
* @return \Illuminate\Support\Collection|mixed
*/
public function query()
{
$type = TransactionType::TOP_UP;
$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
{
$formattedDocumentDate = Carbon::parse($transaction->created_at)->format('m/d/Y');
$owner = $transaction->owner;
$company = $owner->owner;
return [
'<<New>>', //DocNo
$company ? $company->debtor : '', //DebtorCode
$formattedDocumentDate, //DocDate
'Wallet Deposit', //Description
'C', //DeptNo
'WALLET DEPOSIT - EXC', //DepositPaymentMethod
'MYR', //CurrencyCode
'MBB', //PaymentMethod
number_format($transaction->amount, 2), //PaymentAmt
];
}
}
@@ -185,7 +185,7 @@ class ImportExcelLogic extends AbstractControllerLogic
$booking = Booking::where('marking', $ref)->first();
if($booking){
if($docNo != "" && $docNo != "<<New>>"){
$this->updateOrCreateKeyValuePair($booking, KVPKey::AUTOCOUNT_DOCNO, $docNo);
$this->updateOrCreateKeyValuePair($booking, KVPKey::AUTOCOUNT_DOCNO_INVOICE, $docNo);
}
if($eInvoiceValidationLink){
$this->updateOrCreateKeyValuePair($booking, KVPKey::AUTOCOUNT_EINVOICE_VALIDATION_LINK, $eInvoiceValidationLink);
@@ -219,12 +219,12 @@ class ImportExcelLogic extends AbstractControllerLogic
if($knockOffDocNo)
{
$kvp = KeyValuePair::where('key', KVPKey::AUTOCOUNT_DOCNO)->where('value', $knockOffDocNo)->first();
$kvp = KeyValuePair::where('key', KVPKey::AUTOCOUNT_DOCNO_INVOICE)->where('value', $knockOffDocNo)->first();
if($kvp){
$booking = $kvp->owner;
if($booking){
if($docNo != "" && $docNo != "<<New>>"){
$this->updateOrCreateKeyValuePair($booking, KVPKey::AUTOCOUNT_OFFICIAL_RECEIPT_DOCNO, $docNo);
$this->updateOrCreateKeyValuePair($booking, KVPKey::AUTOCOUNT_DOCNO_OFFICIAL_RECEIPT, $docNo);
}
// if($eInvoiceValidationLink){
// $this->updateOrCreateKeyValuePair($booking, KVPKey::AUTOCOUNT_EINVOICE_VALIDATION_LINK, $eInvoiceValidationLink);
@@ -94,7 +94,7 @@ class GenerateCreditNotePdfV2Logic
$autoCountInvoiceId = '';
$autoCountEInvoiceValidationLink = '';
$metadata = $booking->attributesKVP()->where('key', KVPKey::AUTOCOUNT_DOCNO)->first();
$metadata = $booking->attributesKVP()->where('key', KVPKey::AUTOCOUNT_DOCNO_INVOICE)->first();
if($metadata){
$autoCountInvoiceId = $metadata->value;
}
@@ -69,7 +69,7 @@ class CreateInvoiceDocumentProcessor
}
if($document_type === DocumentType::EINVOICE){
$metadata = $booking->attributesKVP()->where('key', KVPKey::AUTOCOUNT_DOCNO)->first();
$metadata = $booking->attributesKVP()->where('key', KVPKey::AUTOCOUNT_DOCNO_INVOICE)->first();
if($metadata){
$autoCountInvoiceId = $metadata->value;
}
@@ -18,6 +18,7 @@ use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\SegmentConstants;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Classes\ValueObjects\Constants\DocumentType;
use App\Classes\ValueObjects\Constants\KVPKey;
use App\Models\Booking;
use App\Models\SegmentConstant;
use Carbon\Carbon;
@@ -136,7 +137,10 @@ class CreateInvoiceTransactionProcessor
if ($bookingCreatedDate->isAfter($eInvoiceStartDate) && $supplier->e_invoice === 1) {
$eInvoice = true;
}
// $eInvoice = true; //cief todo: 90 - for testing
$kvp = $booking->attributesKVP()->where('key', KVPKey::BOOKING_EINVOICE_ELIGIBLE)->first();
if($kvp){
$eInvoice = true;
}
if($isAllowNormalInvoice){
$invoiceNo = ""; //July 2025 workaround generate normal invoice instead of E-Invoice
@@ -6,9 +6,9 @@ namespace App\Classes\ValueObjects\Constants;
class KVPKey
{
public const AUTOCOUNT_DOCNO = 'AUTOCOUNT_DOCNO';
public const AUTOCOUNT_DOCNO_INVOICE = 'AUTOCOUNT_DOCNO_I';
public const AUTOCOUNT_OFFICIAL_RECEIPT_DOCNO = 'AUTOCOUNT_OR_DOCNO';
public const AUTOCOUNT_DOCNO_OFFICIAL_RECEIPT = 'AUTOCOUNT_DOCNO_OR';
public const AUTOCOUNT_EINVOICE_VALIDATION_LINK = 'AUTOCOUNT_EINVOICE_VALIDATION_LINK';
@@ -16,4 +16,6 @@ class KVPKey
public const TRANSACTION_MODEL_CLASS = 'App\Models\Transaction';
public const BOOKING_EINVOICE_ELIGIBLE = 'BOOKING_EINVOICE_ELIGIBLE';
}
@@ -12,6 +12,7 @@ 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 App\Classes\Modules\Exports\Services\ExportsWalletTopUpDepositEntryReport;
use Carbon\Carbon;
class ExportController
@@ -46,6 +47,12 @@ class ExportController
return $this->handleExport($exporter, '01R- RECEIVE PAYMENT (FULL PAYMENT) [AR RECEIVE PAYMENT].xls');
}
public function walletTopUpDepositEntry(Request $request){
[$startDate, $endDate] = $this->getValidatedDates($request);
$exporter = new ExportsWalletTopUpDepositEntryReport($startDate, $endDate);
return $this->handleExport($exporter, 'Exchange Wallet Top Up - AR Deposit Entry.xls');
}
private function getValidatedDates(Request $request): array
{
$validated = $request->validate([
+7 -3
View File
@@ -10,6 +10,7 @@ use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\BookingAttributeNames;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Classes\ValueObjects\Constants\DocumentType;
use App\Classes\ValueObjects\Constants\KVPKey;
use Carbon\Carbon;
use Illuminate\Http\Resources\Json\JsonResource;
@@ -32,9 +33,12 @@ class BookingResource extends JsonResource
if ($bookingCreatedDate->isAfter($eInvoiceStartDate) && $this->company->e_invoice === 1) { //&& $bookingCreatedDate->diffInMinutes($eInvoiceRequestedDate) <= 480 cief todo: 90
$eInvoice = true;
}
// if ($this->company->e_invoice === 1) {
// $eInvoice = true;
// }
$kvp = $this->attributesKVP()->where('key', KVPKey::BOOKING_EINVOICE_ELIGIBLE)->first();
if($kvp){
$eInvoice = true;
}
return [
'id' => $this->id,
'company' => new CompanyResource($this->company),
@@ -142,6 +142,7 @@ export default {
'01D - RECEIVE PAYMENT (FULL PAYMENT) [AR DEPOSIT ENTRY]',
'01R - RECEIVE PAYMENT (FULL PAYMENT) [AR RECEIVE PAYMENT]',
'Credit Note Report',
'Wallet Top Up Report',
];
},
handleExportClick(){
@@ -156,6 +157,7 @@ export default {
'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'),
'Wallet Top Up Report': route('api.export.transactions.wallet_top_up_deposit_entry'),
};
let url = `${routesMap[reportType]}?startDate=${this.parameters.startDate}&endDate=${this.parameters.endDate}`;
+1
View File
@@ -16,6 +16,7 @@ Route::group(['prefix' => 'export', 'as' => 'export.', 'namespace' => 'Exports']
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::get('/wallet-top-up-deposit-entry', [ExportController::class, 'walletTopUpDepositEntry'])->name('wallet_top_up_deposit_entry');
});
});