diff --git a/app/Classes/Modules/Transactions/Processors/CreatePerformaInvoiceTransactionProcessor.php b/app/Classes/Modules/Transactions/Processors/CreatePerformaInvoiceTransactionProcessor.php
new file mode 100644
index 00000000..2a66a5c8
--- /dev/null
+++ b/app/Classes/Modules/Transactions/Processors/CreatePerformaInvoiceTransactionProcessor.php
@@ -0,0 +1,175 @@
+createsTransaction = $createsTransaction;
+ $this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
+ $this->calculatesBookingPayableAmount = $calculatesBookingPayableAmount;
+ $this->calculatesBookingCurrencyAverageRate = $calculatesBookingCurrencyAverageRate;
+ $this->fetchesCompany = $fetchesCompany;
+ $this->createsDocument = $createsDocument;
+ $this->createsFile = $createsFile;
+ $this->calculatesBookingOutstanding = $calculatesBookingOutstanding;
+ $this->generatesBookingQuotation = $generatesBookingQuotation;
+ $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)
+ ->complete()
+ ->first();
+
+ $billNumber = $this->generatesTransactionBillNumber->execute('PERFORMA-');
+
+ $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);
+ $this->generatesBookingQuotation->execute(
+ $this->fetchesBookingQuotation->execute($booking->company, $conversionObject),
+ $this->fetchesCompanyPaymentAttemptLimit->execute($booking->company)
+ );
+
+ $payable_amount = $this->calculatesBookingPayableAmount->execute($booking, $booking->fix_currency_id);
+ $booking_amount = $booking->fix_amount;
+
+ $transaction = $booking->transactions()
+ ->where('type', TransactionType::PAYMENT)
+ ->first();
+
+ $booking_currency_average_rate = $this->calculatesBookingCurrencyAverageRate->execute($booking, TransactionType::PAYMENT);
+
+ $total_service_charge = $booking->transactions()
+ ->where('type', TransactionType::PAYMENT)
+ ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
+ ->sum('service_charge');
+
+ $total_tax = $booking->transactions()
+ ->where('type', TransactionType::PAYMENT)
+ ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
+ ->sum('tax');
+
+ $transaction_object = new TransactionObject(
+ $billNumber,
+ TransactionType::PERFORMA,
+ $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
+ );
+
+ $perofrma_transaction = $this->createsTransaction->execute($po_order_transaction->booking, $transaction_object);
+
+ $supplier = $this->fetchesCompany->execute(['id' => $transaction->receiver]);
+
+ $purchase_order_pdf = LaravelMpdf::loadView('pages.pdfs.performa_invoice', ['invoice_transaction' => $perofrma_transaction, 'po_order_transaction' => $po_order_transaction, 'supplier' => $supplier]);
+ $document_object = new DocumentObject(
+ DocumentType::PERFORMA_INVOICE,
+ [chunk_split('data:application/pdf;base64,'.base64_encode($purchase_order_pdf->output()))],
+ '',
+ ApprovalStatus::COMPLETED,
+ 'performa_invoices'
+ );
+
+ /** @var Document $document */
+ $document = $this->createsDocument->execute($po_order_transaction->booking, $document_object);
+ $this->createsFile->execute($document, $document_object);
+
+
+ }
+}
diff --git a/app/Classes/ValueObjects/Constants/DocumentType.php b/app/Classes/ValueObjects/Constants/DocumentType.php
index 2b053163..3c5ed68b 100644
--- a/app/Classes/ValueObjects/Constants/DocumentType.php
+++ b/app/Classes/ValueObjects/Constants/DocumentType.php
@@ -17,6 +17,7 @@ final class DocumentType {
public const WALLET_TOP_UP_PAYMENT_PROOF = 'WALLET_TOP_UP_PAYMENT_PROOF';
public const WALLET_REFUND_PAYMENT_PROOF = 'WALLET_REFUND_PAYMENT_PROOF';
+ public const PERFORMA_INVOICE = 'PERFORMA_INVOICE';
public const PURCHASE_ORDER = 'PURCHASE_ORDER';
public const DELIVER_ORDER = 'DELIVER_ORDER';
public const INVOICE = 'INVOICE';
diff --git a/app/Models/Booking.php b/app/Models/Booking.php
index 17a50213..ea01b302 100644
--- a/app/Models/Booking.php
+++ b/app/Models/Booking.php
@@ -19,8 +19,8 @@ use Illuminate\Database\Eloquent\SoftDeletes;
* @property string marking
* @property string reference
* @property float fix_amount
- * @property \App\Models\Currency convertible_currency_id
- * @property \App\Models\Currency conversion_currency_id
+ * @property int convertible_currency_id
+ * @property int conversion_currency_id
*/
class Booking extends AbstractModel implements Documentable, Transactionable
{
diff --git a/resources/views/pages/pdfs/performa_invoice.blade.php b/resources/views/pages/pdfs/performa_invoice.blade.php
new file mode 100644
index 00000000..673d06d5
--- /dev/null
+++ b/resources/views/pages/pdfs/performa_invoice.blade.php
@@ -0,0 +1,174 @@
+@extends('layouts.base_pdf')
+@section('inner_content')
+
+
+
+
+ |
+
+
+
+ CIEF WORLDWIDE SDN BHD
+
+
+ (1134596-M) + Malaysian Global Innovation & Creativity Center + Level 1 CWS, Block 3730, Persiaran APEC, + 63000 Cyberjaya, Malaysian. + Tel: 018-2909252 + |
+
+
+
+ Performa Invoice
+
+
+
+ EI#: {{ $invoice_transaction->bill_no }}
+
+
+ Ref# {{ $po_order_transaction->booking->marking }}
+ Date: {{ $po_order_transaction->booking->created_at }}
+ |
+
| + + Bill To + + | +||
|
+
+ Company: {{ $supplier->name }}
+
+
+ @php
+ $addresses = $supplier->addresses()->first();
+ @endphp
+ {{ $addresses->street_one }}
+ {{ $addresses->street_two }} ,
+ {{ $addresses->district()->first()->name }},
+ {{ $addresses->postcode }}
+ {{ $addresses->state()->first()->name }},
+ {{ $addresses->country()->first()->name }}
+
+
+ Phone: {{ $supplier->contacts()->first()->phone }}
+
+ |
+ ||
| No | +Stock Code | +Description | +Quantity | +Unit Price (RM) | +Total Amount (RM) |
+
|---|---|---|---|---|---|
| {{ $key + 1 }} | +{{ $transaction_detail->product_code }} | +{{ $transaction_detail->product_name }} | +{{ $transaction_detail->quantity }} | ++ @if($invoice_transaction->booking()->first()->fix_currency_id !== 1) + {{ number_format( (1/$invoice_transaction->currency_rate) * $transaction_detail->price, 2) }} + @else + {{ number_format($transaction_detail->price, 2) }} + @endif + | ++ @if($invoice_transaction->booking()->first()->fix_currency_id !== 1) + + {{ number_format((float)number_format( (1/$invoice_transaction->currency_rate) * $transaction_detail->price, 2,'.','')*$transaction_detail->quantity,2) }} + + @php + $subtotal += number_format((float)number_format( (1/$invoice_transaction->currency_rate) * $transaction_detail->price, 2,'.','')*$transaction_detail->quantity,2,'.',''); + @endphp + @else + {{ number_format((float)number_format($transaction_detail->price, 2,'.','')*$transaction_detail->quantity,2) }} + + @php + $subtotal += number_format((float)number_format($transaction_detail->price, 2,'.','')*$transaction_detail->quantity,2,'.',''); + @endphp + @endif + | +
| + | Subtotal | ++ {{ number_format($subtotal, 2) }} + | +|||
| + | Service Charges | ++ {{ number_format($invoice_transaction->service_charge, 2) }} + | +|||
| + | Adjustment | ++ @if($invoice_transaction->booking()->first()->fix_currency_id !== 1) + {{ number_format((float)number_format( (1/$invoice_transaction->currency_rate) * $invoice_transaction->amount, 2,'.','') - (float)number_format($subtotal, 2,'.',''),2) }} + @else + {{ number_format((float)number_format($invoice_transaction->amount, 2,'.','') - (float)number_format($subtotal, 2,'.',''),2) }} + @endif + | +|||
| + | Tax | +{{ number_format($invoice_transaction->tax, 2) }} | +|||
| + | Total | ++ @if($invoice_transaction->booking()->first()->fix_currency_id !== 1) + {{ number_format( ((1/$invoice_transaction->currency_rate) * $invoice_transaction->amount) + $invoice_transaction->service_charge + $invoice_transaction->tax, 2) }} + @else + {{ number_format($invoice_transaction->amount + $invoice_transaction->service_charge + $invoice_transaction->tax, 2) }} + @endif + | +|||
| This is generated by computer. No signature required. | +Page {PAGENO} of {nbpg} | +