Manual Invoice / BA

This commit is contained in:
Dillon Ngo
2025-11-10 13:46:37 +08:00
parent 334dfd7b92
commit 22aa3e79c9
13 changed files with 684 additions and 35 deletions
+1 -1
View File
@@ -84,7 +84,7 @@ class Helper
$ringgitWords = $numberTransformer->toWords((int)$ringgit);
$centsWords = $numberTransformer->toWords((int)$cents);
return strtoupper('ringgit ' . $ringgitWords . ' and ' . $centsWords . ' cents only');
return strtoupper('ringgit malaysia ' . $ringgitWords . ' and ' . $centsWords . ' cents only');
}
public static function getLHDNStateCodeByName($name)
@@ -0,0 +1,71 @@
<?php
namespace App\Classes\Modules\Bookings\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Bookings\Services\FetchesBooking;
use App\Classes\Modules\Bookings\Standards\Rules\CanFetchBooking;
use App\Classes\Modules\Transactions\Processors\CreateBankingInvoiceTransactionProcessor;
use App\Http\Resources\BookingResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class CreateBankingInvoiceTransactionLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Create Banking Invoice Transaction',
'message' => 'You have successfully create banking invoice transaction'
];
}
/** @var CanFetchBooking */
private $canFetchBooking;
/** @var FetchesBooking */
private $fetchesBooking;
/** @var CreateBankingInvoiceTransactionProcessor */
private $createBankingInvoiceTransactionProcessor;
/**
* CreateBankingInvoiceTransactionLogic constructor.
* @param CanFetchBooking $canFetchBooking
* @param FetchesBooking $fetchesBooking
* @param CreateBankingInvoiceTransactionProcessor $createBankingInvoiceTransactionProcessor
*/
public function __construct(
CanFetchBooking $canFetchBooking,
FetchesBooking $fetchesBooking,
CreateBankingInvoiceTransactionProcessor $createBankingInvoiceTransactionProcessor
)
{
$this->canFetchBooking = $canFetchBooking;
$this->fetchesBooking = $fetchesBooking;
$this->createBankingInvoiceTransactionProcessor = $createBankingInvoiceTransactionProcessor;
}
/**
* @param Request $request
* @return JsonResponse
* @throws \App\Classes\Exceptions\AccessForbiddenException
* @throws \App\Classes\Exceptions\MalformedRequestException
* @throws \App\Classes\Exceptions\RequestValidationException
*/
public function logic(Request $request) : JsonResponse
{
// $this->canFetchBooking->passes();
$booking = $this->fetchesBooking->execute(['id' => $request->route('id')]);
$this->createBankingInvoiceTransactionProcessor->execute($booking);
return $this->resourceResponse(new BookingResource($booking));
}
}
@@ -0,0 +1,233 @@
<?php
namespace App\Classes\Modules\Transactions\Processors;
use App\Classes\Modules\Bookings\Services\CalculatesBookingOutstanding;
use App\Classes\Modules\Bookings\Services\FetchesBookingQuotation;
use App\Classes\Modules\Companies\Services\FetchesCompanyPaymentAttemptLimit;
use App\Classes\Modules\Currencies\DataTransferObjects\CurrencyConversionObject;
use App\Classes\Modules\Transactions\Services\CreatesTransaction;
use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Classes\Modules\Documents\Services\CreatesDocument;
use App\Classes\Modules\Documents\Services\CreatesFiles;
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\PaymentMethodType;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Classes\ValueObjects\Constants\DocumentType;
use App\Models\Booking;
use App\Models\Document;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
class CreateBankingInvoiceTransactionProcessor
{
/** @var CreatesTransaction */
private $createsTransaction;
/** @var GeneratesTransactionBillNumber */
private $generatesTransactionBillNumber;
/** @var FetchesCompany */
private $fetchesCompany;
/** @var CreatesDocument */
private $createsDocument;
/** @var CreatesFiles */
private $createsFile;
/** @var CalculatesBookingOutstanding */
private $calculatesBookingOutstanding;
/** @var FetchesBookingQuotation */
private $fetchesBookingQuotation;
/** @var FetchesCompanyPaymentAttemptLimit */
private $fetchesCompanyPaymentAttemptLimit;
/**
* CreateBankingInvoiceTransactionProcessor constructor.
* @param CreatesTransaction $createsTransaction
* @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
* @param FetchesCompany $fetchesCompany
* @param CreatesDocument $createsDocument
* @param CreatesFiles $createsFile
* @param CalculatesBookingOutstanding $calculatesBookingOutstanding
* @param FetchesBookingQuotation $fetchesBookingQuotation
* @param FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit
*/
public function __construct(CreatesTransaction $createsTransaction, GeneratesTransactionBillNumber $generatesTransactionBillNumber, FetchesCompany $fetchesCompany, CreatesDocument $createsDocument, CreatesFiles $createsFile, CalculatesBookingOutstanding $calculatesBookingOutstanding, FetchesBookingQuotation $fetchesBookingQuotation, FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit)
{
$this->createsTransaction = $createsTransaction;
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
$this->fetchesCompany = $fetchesCompany;
$this->createsDocument = $createsDocument;
$this->createsFile = $createsFile;
$this->calculatesBookingOutstanding = $calculatesBookingOutstanding;
$this->fetchesBookingQuotation = $fetchesBookingQuotation;
$this->fetchesCompanyPaymentAttemptLimit = $fetchesCompanyPaymentAttemptLimit;
}
/**
* @param Booking $booking
* @return void
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(Booking $booking)
{
$po_order_transaction = $booking->transactions()
->where('type', TransactionType::PURCHASE_ORDER)
->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED])
->first();
$transaction = $booking->transactions()
->where('type', TransactionType::PAYMENT)
->whereNotIn('status', [ApprovalStatus::SUSPENDED])
->first();
if (!$transaction) {
$outstanding = $this->calculatesBookingOutstanding->execute($booking);
$conversionObject = new CurrencyConversionObject(floatval(str_replace(',', '', $outstanding)), $booking->convertible_currency_id, $booking->service_id, $booking->fix_currency_id === 1 ? 0 : 1, PaymentMethodType::CASH);
$configurations = $this->fetchesBookingQuotation->execute($booking->company, $conversionObject); //cief todo: 76
$paymentAttemptLimit = $this->fetchesCompanyPaymentAttemptLimit->execute($booking->company);
$billNumber = $this->generatesTransactionBillNumber->execute('PYMT-');
$object = new TransactionObject(
$billNumber,
TransactionType::PAYMENT,
1,
$booking->company->id,
$configurations->getConfigurations()->getBankId(),
$configurations->getConversionObject()->getPaymentMethod(),
$configurations->getTotal(),
$configurations->getForeignTotal(),
1,
$configurations->getConversionObject()->getCurrencyId(),
$configurations->getConfigurations()->getRate(),
$configurations->getTax(),
$configurations->getServiceCharge(),
Carbon::now()->addMinutes($paymentAttemptLimit),
ApprovalStatus::PENDING_SUBMISSION,
[],
isset($billPlzBill) ? $billPlzBill->id : NULL
);
$this->createsTransaction->execute($booking, $object);
}
$billNumber = $this->generatesTransactionBillNumber->execute('BI-');
$payable_amount = $booking->transactions()->payments()->where(function ($query) {
return $query->where(function ($query) {
// return $query->where('status', ApprovalStatus::PENDING_SUBMISSION)->whereDate('expires_on', '>=', Carbon::now())->where('expires_on', '>', Carbon::now()->toTimeString());
return $query->where('status', ApprovalStatus::PENDING_SUBMISSION)->where('expires_on', '>=', Carbon::now());
})->orWhere(function ($query) {
return $query->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
});
})->sum('amount');
$booking_amount = $booking->fix_amount;
$transaction = $booking->transactions()
->where('type', TransactionType::PAYMENT)
->first();
$paymentAmount = $booking->transactions()->payments()->where(function ($query) {
return $query->where(function ($query) {
return $query->where('status', ApprovalStatus::PENDING_SUBMISSION)->where('expires_on', '>=', Carbon::now());
})->orWhere(function ($query) {
return $query->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
});
})->selectRaw('sum(amount - service_charge - tax) as sub_total')->get()->sum('sub_total');
$booking_currency_average_rate = $booking_amount / $paymentAmount;
$total_service_charge = $booking->transactions()
->where('type', TransactionType::PAYMENT)
->whereNotIn('status', [ApprovalStatus::REJECTED, ApprovalStatus::SUSPENDED])
->sum('service_charge');
$total_tax = $booking->transactions()
->where('type', TransactionType::PAYMENT)
->whereIn('status', [ApprovalStatus::REJECTED, ApprovalStatus::SUSPENDED])
->sum('tax');
// delete prev banking transactions
$booking->transactions()
->where('type', TransactionType::BANKING)
->delete();
$transaction_object = new TransactionObject(
$billNumber,
TransactionType::BANKING,
$transaction->issuer,
$transaction->receiver,
$transaction->recipient_bank_account_id,
$transaction->payment_method,
$payable_amount,
$booking_amount,
$transaction->currency_id,
$transaction->original_currency_id,
$booking_currency_average_rate,
$total_tax,
$total_service_charge,
null,
ApprovalStatus::APPROVED
);
$banking_transaction = $this->createsTransaction->execute($po_order_transaction->booking, $transaction_object);
$supplier = $this->fetchesCompany->execute(['id' => $transaction->receiver]);
$brn = $supplier->documents()->where('document_type', DocumentType::SSM_REGISTRATION)->latest()->first();
// PDF 1 - Banking Invoice
$purchase_order_pdf = LaravelMpdf::loadView('pages.pdfs.banking_invoice',
[
'transaction' => $banking_transaction,
'po_order_transaction' => $po_order_transaction,
'supplier' => $supplier,
'brn' => $brn,
]);
$document_object = new DocumentObject(
DocumentType::BANKING_INVOICE,
[chunk_split('data:application/pdf;base64,' . base64_encode($purchase_order_pdf->output()))],
'',
ApprovalStatus::COMPLETED,
'banking_invoices'
);
/** @var Document $document */
$document = $this->createsDocument->execute($po_order_transaction->booking, $document_object);
$this->createsFile->execute($document, $document_object);
// PDF 2 - Banking Delivery Order
$purchase_order_pdf = LaravelMpdf::loadView('pages.pdfs.deliver_order_banking',
[
'transaction' => $banking_transaction,
'po_order_transaction' => $po_order_transaction,
'supplier' => $supplier,
'brn' => $brn,
]);
$document_object = new DocumentObject(
DocumentType::DELIVER_ORDER_BANKING,
[chunk_split('data:application/pdf;base64,' . base64_encode($purchase_order_pdf->output()))],
'',
ApprovalStatus::COMPLETED,
'banking_invoices'
);
/** @var Document $document */
$document = $this->createsDocument->execute($po_order_transaction->booking, $document_object);
$this->createsFile->execute($document, $document_object);
}
}
@@ -30,4 +30,7 @@ final class DocumentType {
public const RECEIPT_VOUCHER = 'RECEIPT_VOUCHER';
public const EINVOICE = 'E_INVOICE';
public const BANKING_INVOICE = 'BANKING_INVOICE';
public const DELIVER_ORDER_BANKING = 'DELIVER_ORDER_BANKING';
}
@@ -40,6 +40,8 @@ final class TransactionType {
public const RECEIPT_VOUCHER = 17;
public const BANKING = 18;
public const ID_TO_NAME = [
self::PAYMENT_ATTEMPT => "PAYMENT_ATTEMPT",
self::PAYMENT => "PAYMENT",
@@ -57,6 +59,7 @@ final class TransactionType {
self::CASH_BACK => "CASH_BACK",
self::SUPPLIER_PAYMENT => "SUPPLIER_PAYMENT",
self::SUPPLIER_REFUND => "SUPPLIER_REFUND",
self::BANKING => "BANKING",
];
}
@@ -0,0 +1,20 @@
<?php
namespace App\Http\Controllers\Bookings;
use App\Classes\Modules\Bookings\ControllersLogic\CreateBankingInvoiceTransactionLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class CreateBankingInvoiceTransactionController
{
/**
* @param Request $request
* @param CreateBankingInvoiceTransactionLogic $logic
* @return JsonResponse
*/
public function create(Request $request, CreateBankingInvoiceTransactionLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
+2
View File
@@ -65,6 +65,8 @@ class BookingResource extends JsonResource
'supplier_delivery_order' => new DocumentResource($this->documents()->where('document_type', DocumentType::SUPPLIER_DELIVER_ORDER)->first()),
'proforma_invoice' => new DocumentResource($this->documents()->where('document_type', DocumentType::PROFORMA_INVOICE)->whereNotIn('status', [ApprovalStatus::REJECTED, ApprovalStatus::EXPIRED])->orderByDesc('id')->first()),
'ecommerce_purchase_order' => new DocumentResource($this->documents()->where('document_type', DocumentType::ECOMMERCE_PURCHASE_ORDER)->first()),
'banking_invoice' => new DocumentResource($this->documents()->where('document_type', DocumentType::BANKING_INVOICE)->whereNotIn('status', [ApprovalStatus::REJECTED, ApprovalStatus::EXPIRED])->orderByDesc('id')->first()),
'delivery_order_banking' => new DocumentResource($this->documents()->where('document_type', DocumentType::DELIVER_ORDER_BANKING)->orderByDesc('id')->first()),
],
'order_reference_no' => $this->modelAttributes()->where('name', BookingAttributeNames::ORDER_REFERENCE_NO)->get()->map(function ($attr) {
return [
File diff suppressed because one or more lines are too long
@@ -16,6 +16,12 @@
<div class="col">
<input class="form-control" type="text" name="booking_reference" placeholder="Booking Reference" value="{{$bookingReference}}">
</div>
<div class="col">
<input class="form-control" type="text" name="bill_no" placeholder="Bill No" value="">
</div>
<div class="col">
<input class="form-control" type="text" name="autocount_docno_invoice" placeholder="Autocount Invoice Number" value="">
</div>
<div class="col-auto">
<button class="btn btn-complete" type="submit">Search</button>
</div>
@@ -0,0 +1,97 @@
@extends('layouts.base_pdf')
@section('inner_content')
<br>
<htmlpageheader name="page-header">
<br><br>
<div class="separator"><strong><i>{{ $transaction->bill_no }}</i></strong></div>
</htmlpageheader>
<table>
<!-- Header Section -->
<tr>
<td class="header-logo">
<img src="{{ asset('images/ri_1.png') }}" alt="logo" id="logo" class="logo">
</td>
<td class="header-cief-address">
<span class="company-name"><strong>CIEF WORLDWIDE SDN BHD</strong></span>
<span class="company-reg">(1134596-M)</span><br>
No. 72-3, Jalan Jalil 1,<br>
The Earth Bukit Jalil,<br>
57000 Kuala Lumpur<br>
Tel: 03-8082 1252<br>
TIN: C23880226040, MSIC: 46909<br>
SST: W10-2403-32000643
</td>
<td class="header-details">
<div class="title"><strong>Invoice</strong></div>
<div class="number">EBI#: {{ $transaction->bill_no }}</div>
<div class="ref">Ref# {{ $transaction->booking->marking }}</div>
<div class="date">Date: {{ $po_order_transaction->booking->created_at }}</div>
<div class="ref">Terms: C.O.D</div>
<div>&nbsp;</div>
</td>
</tr>
<tr>
<td colspan="3" class="bill-to">
<span class="sub-title">Bill To</span>
</td>
</tr>
<tr>
<td colspan="3" class="address">
<div class="label">
{{ $supplier->name }}
@if ($brn)
(ROC: {{ $brn->reference }})
@endif
</div>
<div class="address">
@php
$billingAddress = $supplier->addresses()->where('billing', '=', true)->first();
@endphp
{{ $billingAddress->street_one }}
{{ $billingAddress->street_two }},
{{ $billingAddress->district()->first()->name }},
{{ $billingAddress->postcode }}
{{ $billingAddress->state()->first()->name }},
{{ $billingAddress->country()->first()->name }}
</div>
<div>Phone: {{ $supplier->contacts()->first()->phone }}</div>
</td>
</tr>
</table>
<br>
<br>
<?php
$voucher_redemption = $voucher_redemption ?? null;
?>
<!-- Invoice Table -->
@include('pages.pdfs.purchase_order_table_v2')
<br>
<br>
<br>
<div class="note">
<p><strong><span>{{ \App\Classes\General\Helper::convert(round($transaction->amount, 2)) }}</span></strong></p>
<strong>Notes:</strong><br>
1. All cheques should be crossed and made payable to CIEF WORLDWIDE SDN. BHD. (MAYBANK) MBB-568603010762<br>
2. Goods sold are neither returnable nor refundable. Otherwise a cancellation fee of 20% on purchase price will be imposed.<br>
3. Interest rate 2% per month will be charged on all overdue bills.<br>
4. Price offered on invoice is based on present as at the current invoice date.<br><br>
No any price amendment will be allowed after invoice being chop & sign.<br>
CIEF WORLDWIDE SDN. BHD.<br>
</div>
<br><br>
<htmlpagefooter name="page-footer">
<table width="100%">
<tr>
<td style="text-align: right; ">This is generated by computer. No signature required.</td>
<td style="text-align: right; ">Page {PAGENO} of {nbpg}</td>
</tr>
</table>
</htmlpagefooter>
@endsection
@@ -0,0 +1,113 @@
@extends('layouts.base_pdf')
@section('inner_content')
<br>
<htmlpageheader name="page-header">
<br><br>
<div class="separator"><strong><i>{{ str_replace(['BI-'], 'BDO-', $transaction->bill_no) }}</i></strong></div>
</htmlpageheader>
<table>
<tr>
<td class="header-logo">
<img src="{{ asset('images/ri_1.png') }}" alt="logo" id="logo" class="logo">
</td>
<td class="header-cief-address">
<span class="company-name"><strong>CIEF WORLDWIDE SDN BHD</strong></span>
<span class="company-reg">(1134596-M)</span><br>
No. 72-3, Jalan Jalil 1,<br>
The Earth Bukit Jalil,<br>
57000 Kuala Lumpur<br>
Tel: 03-8082 1252<br>
TIN: C23880226040, MSIC: 46909<br>
SST: W10-2403-32000643
</td>
<td class="header-details">
<div class="title">
<strong>
Delivery Order
</strong>
</div>
<div class="number">EBDO#: {{ str_replace(['BI-'], 'BDO-', $transaction->bill_no) }}</div>
<div class="ref">Ref#: {{ $transaction->booking->marking }}</div>
<div class="date">Date: {{
$supplier->segments->whereIn('id', [23])->first() ? \Carbon\Carbon::now() : $po_order_transaction->created_at }}</div>
<div>&nbsp;</div>
</td>
<tr>
<td colspan="3" class="bill-to">
<span class="sub-title">
Bill To
</span>
</td>
</tr>
<tr>
<td colspan="3" class="address">
<div class="label">
{{ $supplier->name }}
@if ($brn)
(ROC: {{ $brn->reference }})
@endif
</div>
<div class="address">
@php
$billingAddress = $supplier->addresses()->where('billing', '=', true)->first();
@endphp
{{ $billingAddress->street_one }}
{{ $billingAddress->street_two }} ,
{{ $billingAddress->district()->first()->name }},
{{ $billingAddress->postcode }}
{{ $billingAddress->state()->first()->name }},
{{ $billingAddress->country()->first()->name }}
</div>
<div>
Phone: {{ $supplier->contacts()->first()->phone }}
</div>
</td>
</tr>
</table>
<br>
<br>
<?php
$voucher_redemption = $voucher_redemption ?? null;
?>
@include('pages.pdfs.purchase_order_table_v2')
<table style="width: 100%; border-spacing: 0;">
<tbody>
<tr style="border-spacing: 2em;">
<td width="60%">
</td>
<td width="40%" valign="top">
E & O.E<br>
Receive In Good Order & Condition<br>
</td>
</tr>
</tbody>
</table>
<table style="width: 100%; border-spacing: 0;">
<tbody>
<tr style="border-spacing: 2em;">
<td width="60%">
CIEF WORLDWIDE SDN BHD<br>
</td>
<td width="40%" valign="top">
</td>
</tr>
</tbody>
</table>
<htmlpagefooter name="page-footer">
<table width="100%">
<tr>
<td style="text-align: right; ">This is generated by computer. No signature required.</td>
<td style="text-align: right; ">Page {PAGENO} of {nbpg}</td>
</tr>
</table>
</htmlpagefooter>
@endsection
+3
View File
@@ -3,6 +3,7 @@
use App\Http\Controllers\Bookings\RegenerateBookingPaymentRVController;
use App\Http\Controllers\Bookings\RegenerateBookingEInvoiceController;
use App\Http\Controllers\Bookings\UpdateBookingAmountController;
use App\Http\Controllers\Bookings\CreateBankingInvoiceTransactionController;
use Illuminate\Support\Facades\Route;
Route::group(['prefix' => 'booking', 'as' => 'booking.', 'namespace' => 'Bookings'], function () {
@@ -43,6 +44,8 @@ Route::group(['prefix' => 'booking', 'as' => 'booking.', 'namespace' => 'Booking
Route::post('/merge', 'MergeBookingController@merge')->name('merge');
Route::post('{id}/proforma/create', 'CreateProformaInvoiceTransaction@create')->name('proforma.create');
Route::post('{id}/banking/create', [CreateBankingInvoiceTransactionController::class, 'create'])->name('banking.create');
Route::group(['prefix' => '{id}/receipt', 'as' => 'receipt.'], function () {
Route::post('/', [RegenerateBookingPaymentRVController::class, 'regenerate'])->name('regenerate');
+15
View File
@@ -36,7 +36,9 @@ use App\Classes\Modules\Transactions\Processors\CreateInvoiceTransactionV2Proces
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use App\Classes\General\AWSS3Helper;
use App\Classes\ValueObjects\Constants\KVPKey;
use App\Http\Controllers\Reports\UnfinishedPaymentOrders;
use App\Models\KeyValuePair;
use Illuminate\Support\Facades\File;
@@ -215,6 +217,8 @@ Route::post('/support', function (Request $request) {
$marking = $request->input('marking');
$email = $request->input('customer_email');
$bookingReference = $request->input('booking_reference');
$billNo = $request->input('bill_no');
$autocountDocNoInvoice = $request->input('autocount_docno_invoice');
$company = null;
$booking = null;
@@ -234,6 +238,17 @@ Route::post('/support', function (Request $request) {
$company = $booking->company;
}
if($billNo) {
$transaction = Transaction::where('bill_no', $billNo)->first();
$booking = $transaction->booking;
}
if($autocountDocNoInvoice) {
$kvp = KeyValuePair::where('key', KVPKey::AUTOCOUNT_DOCNO_INVOICE)->where('value', $autocountDocNoInvoice)->first();
$transaction = $kvp->owner()->withTrashed()->first();
$booking = $transaction ? $transaction->booking : null;
}
return view('pages.customer_support', [
'marking' => $marking,
'email' => $email,