diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateBulkPurchaseOrderDocumentLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateBulkPurchaseOrderDocumentLogic.php
new file mode 100644
index 00000000..7acd778a
--- /dev/null
+++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateBulkPurchaseOrderDocumentLogic.php
@@ -0,0 +1,103 @@
+ 'Generate Bulk Purchase Order',
+ 'message' => 'You have successfully generated bulk purchase order'
+ ];
+ }
+
+ /** @var ListsGroups */
+ private $listsGroups;
+
+ /** @var FetchesGroup */
+ private $fetchesGroup;
+
+ /** @var FetchesCompany */
+ private $fetchesCompany;
+
+ /** @var CreatesDocument */
+ private $createsDocument;
+
+ /** @var CreatesFiles */
+ private $createsFile;
+
+ /**
+ * CreateBulkPurchaseOrderTransactionLogic constructor.
+ * @param ListsGroups $listsGroups
+ * @param FetchesGroup $fetchesGroup
+ * @param FetchesCompany $fetchesCompany
+ * @param CreatesDocument $createsDocument
+ * @param CreatesFiles $createsFile
+ */
+ public function __construct(ListsGroups $listsGroups, FetchesGroup $fetchesGroup, FetchesCompany $fetchesCompany, CreatesDocument $createsDocument, CreatesFiles $createsFile)
+ {
+ $this->listsGroups = $listsGroups;
+ $this->fetchesGroup = $fetchesGroup;
+ $this->fetchesCompany = $fetchesCompany;
+ $this->createsDocument = $createsDocument;
+ $this->createsFile = $createsFile;
+ }
+
+ /**
+ * @param Request $request
+ * @return JsonResponse
+ * @throws \App\Classes\Exceptions\MalformedRequestException
+ */
+ public function logic(Request $request): JsonResponse
+ {
+ $group = $this->fetchesGroup->execute(['id' => $request->route('id')]);
+
+ foreach ($group->transactions as $transaction) {
+ if ($transaction->owner()->owner()->transactions()->where('type', TransactionType::PURCHASE_ORDER)->where('status', '!=', ApprovalStatus::APPROVED)->exists()) {
+ throw new MalformedRequestException('You can\'t generate bulk purchased order if there in uncomplete transactions');
+ }
+ }
+
+ $supplier = $this->fetchesCompany->execute(['id' => $group->receiver]);
+
+ $document_type = DocumentType::BULK_PURCHASE_ORDER;
+
+ $lowercaseDocumentType = strtolower($document_type);
+
+ $order_pdf = LaravelMpdf::loadView('pages.pdfs.' . $lowercaseDocumentType, ['group' => $group, 'supplier' => $supplier]);
+ $document_object = new DocumentObject(
+ $document_type,
+ [chunk_split('data:application/pdf;base64,' . base64_encode($order_pdf->output()))],
+ '',
+ ApprovalStatus::COMPLETED,
+ $lowercaseDocumentType . 's'
+ );
+
+ $document = $this->createsDocument->execute($group, $document_object);
+ $this->createsFile->execute($document, $document_object);
+
+ return $this->response([]);
+ }
+}
diff --git a/app/Classes/ValueObjects/Constants/DocumentType.php b/app/Classes/ValueObjects/Constants/DocumentType.php
index 04edf25c..fea344fa 100644
--- a/app/Classes/ValueObjects/Constants/DocumentType.php
+++ b/app/Classes/ValueObjects/Constants/DocumentType.php
@@ -22,4 +22,5 @@ final class DocumentType {
public const DELIVER_ORDER = 'DELIVER_ORDER';
public const INVOICE = 'INVOICE';
public const SUPPLIER_DELIVER_ORDER = 'SUPPLIER_DELIVER_ORDER';
+ public const BULK_PURCHASE_ORDER = 'BULK_PURCHASE_ORDER';
}
diff --git a/app/Http/Controllers/Transactions/CreateBulkPurchaseOrderDocumentController.php b/app/Http/Controllers/Transactions/CreateBulkPurchaseOrderDocumentController.php
new file mode 100644
index 00000000..eeeff585
--- /dev/null
+++ b/app/Http/Controllers/Transactions/CreateBulkPurchaseOrderDocumentController.php
@@ -0,0 +1,21 @@
+execute($request);
+ }
+}
diff --git a/app/Models/Group.php b/app/Models/Group.php
index 6e785faa..bd5d5a38 100644
--- a/app/Models/Group.php
+++ b/app/Models/Group.php
@@ -3,15 +3,28 @@
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
+use App\Classes\General\Interfaces\Documentable;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
+use Illuminate\Database\Eloquent\Relations\MorphMany;
+use Staudenmeir\EloquentHasManyDeep\HasRelationships;
-class Group extends Model
+class Group extends Model implements Documentable
{
+ use HasRelationships;
+
public function transactions()
{
return $this->belongsToMany(Transaction::class, GroupTransaction::class);
}
+ /**
+ * @return MorphMany
+ */
+ public function documents(): morphMany
+ {
+ return $this->morphMany(Document::class, 'owner');
+ }
+
/**
* @return BelongsTo
*/
diff --git a/resources/views/pages/pdfs/bulk_purchase_order.blade.php b/resources/views/pages/pdfs/bulk_purchase_order.blade.php
new file mode 100644
index 00000000..8a50bc81
--- /dev/null
+++ b/resources/views/pages/pdfs/bulk_purchase_order.blade.php
@@ -0,0 +1,181 @@
+@extends('layouts.base_pdf')
+@section('inner_content')
+
+
+
+
| + Purchase Order + | +
+ PO#: {{ $group->transactions[0]->bill_no }} + Ref#: {{ $group->transactions[0]->owner()->first()->owner()->first()->marking }} + Date: {{ $group->transactions[0]->owner()->first()->owner()->first()->created_at }} + |
+
|
+
+ Buyer
+
+ + +
+ Marking#: {{ $group->transactions[0]->owner()->first()->owner()->first()->marking }}
+
+
+
+ {{ $supplier->name }}
+
+
+ {{-- {{ $supplier }} --}}
+
+ + + @php + $addresses = $supplier->addresses()->where('billing', '=', true)->first(); + @endphp + {{ $addresses->street_one }} + {{ $addresses->street_two }} + {{ $addresses->state()->first()->name }} + {{ $addresses->district()->first()->name }} + + + + Phone: {{ $supplier->contacts()->first()->phone }} + + |
+
+
+ Seller
+
+ + + CIEF Worldwide Sdn Bhd (1134596-M) + +
+ Malaysia Global Innovation & CreativityCentre, Level 1 CWS, Block 3730, PersiaranAPEC 63000 Cyberjaya
+
+
+ Phone: 0182909252
+
+ |
+
| 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($po_order_transaction->owner()->first()->booking()->first()->fix_currency_id !== 1) + {{ number_format( (1/$group->currency_rate) * $transaction_detail->price, 2) }} + @else + {{ number_format($transaction_detail->price, 2) }} + @endif + | ++ @if($po_order_transaction->owner()->first()->booking()->first()->fix_currency_id !== 1) + + {{ number_format((float)number_format( (1/$group->currency_rate) * $transaction_detail->price, 2,'.','')*$transaction_detail->quantity,2) }} + + @php + $subtotal += number_format((float)number_format( (1/$group->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($group->service_charge, 2) }} + | +|||
| + | Adjustment | ++ @if($group->transactions[0]->owner()->first()->owner()->first()->fix_currency_id !== 1) + {{ number_format((float)number_format( (1/$group->currency_rate) * $group->amount, 2,'.','') - (float)number_format($subtotal, 2,'.',''),2) }} + @else + {{ number_format((float)number_format($group->amount, 2,'.','') - (float)number_format($subtotal, 2,'.',''),2) }} + @endif + | +|||
| + | Tax | +{{ number_format($group->tax, 2) }} | +|||
| + | Total | ++ @if($group->transactions[0]->owner()->first()->owner()->first()->fix_currency_id !== 1) + {{ number_format( ((1/$group->currency_rate) * $group->amount) + $group->service_charge + $group->tax, 2) }} + @else + {{ number_format($group->amount + $group->service_charge + $group->tax, 2) }} + @endif + | +|||
| This is generated by computer. No signature required. | +Page {PAGENO} of {nbpg} | +