diff --git a/app/Classes/General/Eloquent/Filters/HasPendingVerifyTransaction.php b/app/Classes/General/Eloquent/Filters/HasPendingVerifyTransaction.php new file mode 100644 index 00000000..c97af23c --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/HasPendingVerifyTransaction.php @@ -0,0 +1,23 @@ +whereHas('transactions', function ($q) { + $q->where('status', ApprovalStatus::PENDING_VERIFICATION); + }); + } +} \ No newline at end of file diff --git a/app/Classes/General/Eloquent/Filters/WithoutBillGroup.php b/app/Classes/General/Eloquent/Filters/WithoutBillGroup.php new file mode 100644 index 00000000..6d6794e8 --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/WithoutBillGroup.php @@ -0,0 +1,22 @@ +whereDoesntHave('billGroup'); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/ControllersLogic/ApproveBillGroupPaymentVerificationLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/ApproveBillGroupPaymentVerificationLogic.php new file mode 100644 index 00000000..f12060b4 --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/ApproveBillGroupPaymentVerificationLogic.php @@ -0,0 +1,93 @@ +fetchesTransaction = $fetchesTransaction; + $this->updatesTransactionStatus = $updatesTransactionStatus; + $this->approvesDocument = $approvesDocument; + $this->rejectsDocument = $rejectsDocument; + $this->calculatesBillGroupPaymentAmount = $calculatesBillGroupPaymentAmount; + } + + /** + * @return array + */ + protected function notification():array { + return [ + 'title' => 'Payment Status', + 'message' => 'You have successfully updated the payment status' + ]; + } + + /** @var FetchesTransaction */ + private $fetchesTransaction; + + /** @var UpdatesTransactionStatus */ + private $updatesTransactionStatus; + + /** @var ApprovesDocument */ + private $approvesDocument; + + /** @var RejectsDocument */ + private $rejectsDocument; + + /** @var CalculatesBillGroupPaymentAmount */ + private $calculatesBillGroupPaymentAmount; + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + $status = $request->route('status'); + + $transaction = $this->fetchesTransaction->execute(['id' => $request->route('id')]); + + $status === 'approve' ? $this->approvesDocument->execute($transaction->documents()->first()) : $this->rejectsDocument->execute($transaction->documents()->first()); + + $this->updatesTransactionStatus->execute($transaction, $status === 'approve' ? ApprovalStatus::APPROVED : ApprovalStatus::REJECTED); + + $billGroup = $transaction->owner; + $billGroupPayment = $this->calculatesBillGroupPaymentAmount->execute($billGroup); + + if ($status === 'reject') { + $billGroup->status = ApprovalStatus::PENDING_SUBMISSION; + $billGroup->save(); + } else { + if ($billGroupPayment['outstanding_amount'] <= 0) { + $billGroup->status = ApprovalStatus::APPROVED; + $billGroup->save(); + } + } + + return $this->response([]); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateBillGroupPaymentProofDocumentLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateBillGroupPaymentProofDocumentLogic.php new file mode 100644 index 00000000..79e01eb0 --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateBillGroupPaymentProofDocumentLogic.php @@ -0,0 +1,94 @@ + 'Payment Proof Document', + 'message' => 'You have successfully submitted your payment proof document' + ]; + } + + /** @var FetchesTransaction */ + private $fetchesTransaction; + + /** @var CreatesDocument */ + private $createsDocument; + + /** @var CreatesFiles */ + private $createsFile; + + /** @var UpdatesTransactionStatus */ + private $updatesTransactionStatus; + + /** @var CalculatesBillGroupPaymentAmount */ + private $calculatesBillGroupPaymentAmount; + + /** + * CreateBillGroupPaymentProofDocumentLogic constructor. + * @param FetchesTransaction $fetchesTransaction + * @param CreatesDocument $createsDocument + * @param CreatesFiles $createsFile + * @param UpdatesTransactionStatus $updatesTransactionStatus + * @param CalculatesBillGroupPaymentAmount $calculatesBillGroupPaymentAmount + */ + public function __construct(FetchesTransaction $fetchesTransaction, CreatesDocument $createsDocument, CreatesFiles $createsFile, UpdatesTransactionStatus $updatesTransactionStatus, CalculatesBillGroupPaymentAmount $calculatesBillGroupPaymentAmount) + { + $this->fetchesTransaction = $fetchesTransaction; + $this->createsDocument = $createsDocument; + $this->createsFile = $createsFile; + $this->updatesTransactionStatus = $updatesTransactionStatus; + $this->calculatesBillGroupPaymentAmount = $calculatesBillGroupPaymentAmount; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + + $transaction = $this->fetchesTransaction->execute(['id' => $request->route('id')]); + + $object = new DocumentObject(DocumentType::BILL_GROUP_PAYMENT_PROOF, $request->input('files'), '', ApprovalStatus::PENDING_VERIFICATION, 'bill_group_payments'); + + /** @var Document $document */ + $document = $this->createsDocument->execute($transaction, $object); + + $this->createsFile->execute($document, $object); + + $this->updatesTransactionStatus->execute($transaction, ApprovalStatus::PENDING_VERIFICATION); + + $billGroup = $transaction->owner; + $billGroupPayment = $this->calculatesBillGroupPaymentAmount->execute($billGroup); + + if ($billGroupPayment['outstanding_amount'] <= 0) { + $billGroup->status = ApprovalStatus::PENDING_VERIFICATION; + $billGroup->save(); + } + + return $this->response([]); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateBillGroupPaymentTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateBillGroupPaymentTransactionLogic.php new file mode 100644 index 00000000..5c1ae1bf --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateBillGroupPaymentTransactionLogic.php @@ -0,0 +1,84 @@ + 'Create Bill Group Payment Transaction', + 'message' => 'You have successfully created payment for this Bill Group' + ]; + } + + /** @var FetchesBillGroup */ + private $fetchesBillGroup; + + /** @var GeneratesTransactionBillNumber */ + private $generatesTransactionBillNumber; + + /** @var CreatesTransaction */ + private $createsTransaction; + + /** @var CalculatesBillGroupPaymentAmount */ + private $calculatesBillGroupPaymentAmount; + + /** + * CreateBillGroupPaymentTransactionLogic constructor. + * @param FetchesBillGroup $fetchesBillGroup + * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber + * @param CreatesTransaction $createsTransaction + * @param CalculatesBillGroupPaymentAmount $calculatesBillGroupPaymentAmount + */ + public function __construct(FetchesBillGroup $fetchesBillGroup, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesTransaction $createsTransaction, CalculatesBillGroupPaymentAmount $calculatesBillGroupPaymentAmount) + { + $this->fetchesBillGroup = $fetchesBillGroup; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + $this->createsTransaction = $createsTransaction; + $this->calculatesBillGroupPaymentAmount = $calculatesBillGroupPaymentAmount; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + $billGroup = $this->fetchesBillGroup->execute(['id' => $request->route('id')]); + + $billGroupPayment = $this->calculatesBillGroupPaymentAmount->execute($billGroup); + $outstanding_amount = $billGroupPayment['outstanding_amount']; + + $payAmount = floatval(str_replace(',', '', $request->input('payAmount'))); + if($payAmount > round($outstanding_amount, 2)) throw new MalformedRequestException('Your payment must not be greater than '. $outstanding_amount .'.'); + + $billNumber = $this->generatesTransactionBillNumber->execute('SPLR-PYMT-'); + $transaction_object = new TransactionObject($billNumber, TransactionType::SUPPLIER_PAYMENT, $billGroup->issuer, + $billGroup->receiver, $billGroup->issuerCompany->banks()->where('default', true)->first()->id, PaymentMethodType::CASH, + $payAmount, $payAmount, 1, 1, 1, + 0, 0, null, ApprovalStatus::PENDING_SUBMISSION, [], ''); + $this->createsTransaction->execute($billGroup, $transaction_object); + + return $this->resourceResponse(new BillGroupResource($billGroup)); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierBillGroupLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierBillGroupLogic.php new file mode 100644 index 00000000..0a425c16 --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierBillGroupLogic.php @@ -0,0 +1,117 @@ + 'Create Supplier White Form Order', + 'message' => 'You have successfully created currency supplier white form order' + ]; + } + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** @var CreatesTransaction */ + private $createsTransaction; + + /** @var CreatesDocument */ + private $createsDocument; + + /** @var CreatesFiles */ + private $createsFile; + + /** @var GeneratesTransactionBillNumber */ + private $generatesTransactionBillNumber; + + + /** + * CreateSupplierBillGroupLogic constructor. + * @param FetchesCompany $fetchesCompany + * @param CreatesTransaction $createsTransaction + * @param CreatesDocument $createsDocument + * @param CreatesFiles $createsFile + * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber + */ + public function __construct(FetchesCompany $fetchesCompany, CreatesTransaction $createsTransaction, CreatesDocument $createsDocument, CreatesFiles $createsFile, GeneratesTransactionBillNumber $generatesTransactionBillNumber) + { + $this->fetchesCompany = $fetchesCompany; + $this->createsTransaction = $createsTransaction; + $this->createsDocument = $createsDocument; + $this->createsFile = $createsFile; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + } + + public function logic(Request $request) : JsonResponse + { + + $supplier = $this->fetchesCompany->execute(['id' => $request->route('id')]); + + throw new MalformedRequestException('testing only'); + dd("pass through"); + + $service_charges = round(floatval(str_replace(',', '', $request->input('service_charges'))), 2); + + $payments = $request->input('payments'); + + $amount = 0; + $original_amount = 0; + + foreach ($payments as $payment) { + $amount += round($payment['amount'], 2); + $original_amount += round($payment['original_amount'], 2); + } + + $rate = $original_amount / $amount; + + $billGroup = new BillGroup(); + $billGroup->issuer = $supplier->id; + $billGroup->receiver = 1; + $billGroup->reference = $this->generatesTransactionBillNumber->execute('BSPO-'); + $billGroup->amount = $amount; + $billGroup->original_amount = $original_amount; + $billGroup->currency_id = 1; + $billGroup->original_currency_id = $payments[0]['original_currency']['id']; + $billGroup->currency_rate = $rate; + $billGroup->tax = 0; + $billGroup->service_charge = $service_charges; + $billGroup->status = ApprovalStatus::PENDING_SUBMISSION; + $billGroup->save(); + + foreach ($payments as $payment) { + $billGroup->groups()->sync($payment['id'], false); + } + + return $this->response([]); + } +} diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php index 2dcbd0f7..5dd7ab82 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php @@ -105,6 +105,10 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic $service_charge += $row->service_charge; } + $transferFee = (float)$this->createSupplierTransactionProcessor->getTransferTransactions()->sum('service_charge'); + $original_amount += $transferFee; + $amount += $transferFee / $currency_rate; + $group->issuer = $issuer; $group->receiver = $receiver; $group->reference = $this->generatesTransactionBillNumber->execute('SPO-'); diff --git a/app/Classes/Modules/Transactions/ControllersLogic/DeleteBillGroupLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/DeleteBillGroupLogic.php new file mode 100644 index 00000000..56464409 --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/DeleteBillGroupLogic.php @@ -0,0 +1,68 @@ + 'Delete Bill Group Transaction', + 'message' => 'You have successfully deleted this Bill Group Transaction' + ]; + } + + /** @var FetchesBillGroup */ + private $fetchesBillGroup; + + /** @var DeletesTransaction */ + private $deletesTransaction; + + /** + * DeleteBillGroupLogic constructor. + * @param FetchesBillGroup $fetchesBillGroup + * @param DeletesTransaction $deletesTransaction + */ + public function __construct(FetchesBillGroup $fetchesBillGroup, DeletesTransaction $deletesTransaction) + { + $this->fetchesBillGroup = $fetchesBillGroup; + $this->deletesTransaction = $deletesTransaction; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + $billGroup = $this->fetchesBillGroup->execute(['id' => $request->route('id')]); + + $transactions = $billGroup->transactions()->get(); + + foreach($transactions as $transaction) { + $this->deletesTransaction->execute($transaction); + } + + $groups = $billGroup->groups()->get(); + + foreach($groups as $group) { + $billGroup->groups()->detach($group->id); + } + + $billGroup->delete(); + + return $this->resourceResponse(new BillGroupResource($billGroup)); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/ControllersLogic/ListBillGroupsLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/ListBillGroupsLogic.php new file mode 100644 index 00000000..0e39585b --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/ListBillGroupsLogic.php @@ -0,0 +1,42 @@ +listsBillGroups = $listsBillGroups; + } + + /** + * @return array + */ + protected function notification():array { + return [ + 'title' => 'Retrieved Bill Groups', + 'message' => 'You have successfully retrieved a list of bill groups' + ]; + } + + /** @var ListsBillGroups */ + private $listsBillGroups; + + public function logic(Request $request) : JsonResponse + { + $query = $this->listsBillGroups->execute($this->listsBillGroups->deserializeFilters($request->input('filters'))); + + return $this->collectionResponse(BillGroupResource::collection($query)); + } + +} diff --git a/app/Classes/Modules/Transactions/Services/CalculatesBillGroupPaymentAmount.php b/app/Classes/Modules/Transactions/Services/CalculatesBillGroupPaymentAmount.php new file mode 100644 index 00000000..812f8a3c --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/CalculatesBillGroupPaymentAmount.php @@ -0,0 +1,22 @@ +transactions()->whereIn('status', [ApprovalStatus::PENDING_SUBMISSION, ApprovalStatus::PENDING_VERIFICATION])->sum('amount')); + $paid_amount = floatval($billGroup->transactions()->where('status', ApprovalStatus::APPROVED)->sum('amount')); + $outstanding_amount = $billGroup->amount - $paid_amount - $floating_amount + $billGroup->service_charge; + + return [ + 'floating_amount' => $floating_amount, + 'paid_amount' => $paid_amount, + 'outstanding_amount' => $outstanding_amount, + ]; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Services/FetchesBillGroup.php b/app/Classes/Modules/Transactions/Services/FetchesBillGroup.php new file mode 100644 index 00000000..55e5eb11 --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/FetchesBillGroup.php @@ -0,0 +1,31 @@ +repository = $repository; + } + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} diff --git a/app/Classes/Modules/Transactions/Services/ListsBillGroups.php b/app/Classes/Modules/Transactions/Services/ListsBillGroups.php new file mode 100644 index 00000000..26379706 --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/ListsBillGroups.php @@ -0,0 +1,31 @@ +repository = $repository; + } + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} diff --git a/app/Classes/ValueObjects/Constants/DocumentType.php b/app/Classes/ValueObjects/Constants/DocumentType.php index 23f9a94a..42f8222b 100644 --- a/app/Classes/ValueObjects/Constants/DocumentType.php +++ b/app/Classes/ValueObjects/Constants/DocumentType.php @@ -25,4 +25,6 @@ final class DocumentType { public const INVOICE = 'INVOICE'; public const SUPPLIER_DELIVER_ORDER = 'SUPPLIER_DELIVER_ORDER'; public const BULK_PURCHASE_ORDER = 'BULK_PURCHASE_ORDER'; + + public const BILL_GROUP_PAYMENT_PROOF = 'BILL_GROUP_PAYMENT_PROOF'; } diff --git a/app/Classes/ValueObjects/Constants/TransactionType.php b/app/Classes/ValueObjects/Constants/TransactionType.php index 026f25ba..fbab3119 100644 --- a/app/Classes/ValueObjects/Constants/TransactionType.php +++ b/app/Classes/ValueObjects/Constants/TransactionType.php @@ -31,4 +31,6 @@ final class TransactionType { public const TRANSFER_FEE = 12; public const CASH_BACK = 13; + + public const SUPPLIER_PAYMENT = 14; } diff --git a/app/Console/Commands/UpdateGroupWithTransferFee.php b/app/Console/Commands/UpdateGroupWithTransferFee.php index be71d129..dec74d5c 100644 --- a/app/Console/Commands/UpdateGroupWithTransferFee.php +++ b/app/Console/Commands/UpdateGroupWithTransferFee.php @@ -49,9 +49,6 @@ class UpdateGroupWithTransferFee extends Command ini_set('max_execution_time', 0); set_time_limit(0); $groups = Group::whereDate('updated_at', '<', Carbon::now())->get(); - $this->info($groups->count()); - - // $groups = Group::where('id', 999)->get(); foreach ($groups as $group) { $originalTransferFees = (float)Transaction::where('type', TransactionType::TRANSFER_FEE)->whereIn('owner_id', $group->transactions->pluck('id'))->sum('service_charge'); @@ -62,14 +59,10 @@ class UpdateGroupWithTransferFee extends Command $correctAmount += $transferFees; if ($group->original_amount != $correctOriginalAmount) { - // $group->original_amount = $correctOriginalAmount; - // $group->amount = $correctAmount; - // $group->save(); - $this->info("Update group id: " . $group->id . " correct original amount is: " . $correctOriginalAmount . " transfer fee is " . $originalTransferFees); - } else { - $this->info("No update for group id: " . $group->id); + $group->original_amount = $correctOriginalAmount; + $group->amount = $correctAmount; + $group->save(); } } - $this->info(Carbon::now() . ' : ' . 'updateGroupWithTransferFee ------ completed'); } } diff --git a/app/Http/Controllers/Transactions/ApproveBillGroupPaymentVerificationController.php b/app/Http/Controllers/Transactions/ApproveBillGroupPaymentVerificationController.php new file mode 100644 index 00000000..fbae0c1a --- /dev/null +++ b/app/Http/Controllers/Transactions/ApproveBillGroupPaymentVerificationController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Transactions/CreateBillGroupPaymentProofDocumentController.php b/app/Http/Controllers/Transactions/CreateBillGroupPaymentProofDocumentController.php new file mode 100644 index 00000000..dab95ed8 --- /dev/null +++ b/app/Http/Controllers/Transactions/CreateBillGroupPaymentProofDocumentController.php @@ -0,0 +1,21 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Transactions/CreateBillGroupPaymentTransactionController.php b/app/Http/Controllers/Transactions/CreateBillGroupPaymentTransactionController.php new file mode 100644 index 00000000..7e94c84e --- /dev/null +++ b/app/Http/Controllers/Transactions/CreateBillGroupPaymentTransactionController.php @@ -0,0 +1,20 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Transactions/CreateSupplierBillGroupController.php b/app/Http/Controllers/Transactions/CreateSupplierBillGroupController.php new file mode 100644 index 00000000..7ab2f48a --- /dev/null +++ b/app/Http/Controllers/Transactions/CreateSupplierBillGroupController.php @@ -0,0 +1,21 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Transactions/DeleteBillGroupController.php b/app/Http/Controllers/Transactions/DeleteBillGroupController.php new file mode 100644 index 00000000..2b76632b --- /dev/null +++ b/app/Http/Controllers/Transactions/DeleteBillGroupController.php @@ -0,0 +1,20 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Transactions/ListBillGroupsController.php b/app/Http/Controllers/Transactions/ListBillGroupsController.php new file mode 100644 index 00000000..94dbd5e1 --- /dev/null +++ b/app/Http/Controllers/Transactions/ListBillGroupsController.php @@ -0,0 +1,21 @@ +execute($request); + } +} diff --git a/app/Http/Resources/BillGroupResource.php b/app/Http/Resources/BillGroupResource.php new file mode 100644 index 00000000..6f61aeb7 --- /dev/null +++ b/app/Http/Resources/BillGroupResource.php @@ -0,0 +1,63 @@ +make(CalculatesBillGroupPaymentAmount::class))->execute($this->resource); + $floating_amount = $billGroupPayment['floating_amount']; + $paid_amount = $billGroupPayment['paid_amount']; + $outstanding_amount = $billGroupPayment['outstanding_amount']; + + return [ + 'id' => $this->id, + 'reference' => $this->reference, + 'original_amount' => (float) $this->original_amount, + 'original_currency' => new CurrencyResource($this->original_currency), + 'issuer_name' => $this->issuerCompany->name, + 'issuer_id' => $this->issuerCompany->id, + 'amount' => (float) $this->amount, + 'service_charge' => (float) $this->service_charge, + 'currency' => new CurrencyResource($this->currency), + 'created_at' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A'), + 'updated_at' => Carbon::parse($this->updated_at)->format('d-m-Y h:i:s A'), + 'currency_rate' => (float) $this->currency_rate, + 'status' => $this->status, + 'groups' => GroupResource::collection($this->groups), + 'floating_amount' => $floating_amount, + 'paid_amount' => $paid_amount, + 'outstanding_amount' => $outstanding_amount, + 'payment_history' => $this->transactions->map(function ($transaction) { + return [ + 'id' => $transaction->id, + 'type' => (int) $transaction->type, + 'bill_no' => $transaction->bill_no, + 'payment_method' => (float) $transaction->payment_method, + 'amount' => (double) $transaction->amount, + 'original_amount' => (double) $transaction->original_amount, + 'currency' => new CurrencyResource($transaction->currency), + 'original_currency' => new CurrencyResource($transaction->original_currency), + 'service_charge' => (double) $transaction->service_charge, + 'tax' => (double) $transaction->tax, + 'status' => (int) $transaction->status, + 'statusText' => ApprovalStatus::APPROVAL_STATUS_ID[(int) $transaction->status], + 'documents' => $transaction->documents()->first() ? new DocumentResource($transaction->documents()->first()) : null, + 'updated_at' => Carbon::parse($transaction->updated_at)->format('d-m-Y h:i:s A'), + ]; + }), + ]; + } +} diff --git a/app/Models/BillGroup.php b/app/Models/BillGroup.php new file mode 100644 index 00000000..6986ee52 --- /dev/null +++ b/app/Models/BillGroup.php @@ -0,0 +1,68 @@ +MorphMany(Transaction::class, 'owner'); + } + + /** + * @return MorphMany + */ + public function documents(): morphMany + { + return $this->morphMany(Document::class, 'owner'); + } + + /** + * @return BelongsTo + */ + public function currency(): BelongsTo + { + return $this->BelongsTo(Currency::class, 'currency_id', 'id'); + } + + /** + * @return BelongsTo + */ + public function issuerCompany(): BelongsTo + { + return $this->BelongsTo( Company::class, 'issuer', 'id'); + } + + /** + * @return BelongsTo + */ + public function original_currency(): BelongsTo + { + return $this->BelongsTo(Currency::class, 'original_currency_id', 'id'); + } + + public function groups() + { + return $this->belongsToMany(Group::class, BillGroupPayment::class, 'bill_group_id', 'group_id'); + } +} diff --git a/app/Models/BillGroupPayment.php b/app/Models/BillGroupPayment.php new file mode 100644 index 00000000..e34f692c --- /dev/null +++ b/app/Models/BillGroupPayment.php @@ -0,0 +1,27 @@ +BelongsTo(BillGroup::class, 'bill_group_id', 'id'); + } + + /** + * @return BelongsTo + */ + public function group(): BelongsTo + { + return $this->BelongsTo(Group::class, 'group_id', 'id'); + } +} diff --git a/app/Models/Group.php b/app/Models/Group.php index 01dd257e..8cb6cd8a 100644 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -6,6 +6,7 @@ use App\Classes\General\Traits\LogData; use Illuminate\Database\Eloquent\Model; use App\Classes\General\Interfaces\Documentable; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\MorphMany; use Staudenmeir\EloquentHasManyDeep\HasManyDeep; use Staudenmeir\EloquentHasManyDeep\HasRelationships; @@ -60,4 +61,12 @@ class Group extends Model implements Documentable { return $this->BelongsTo(Currency::class, 'original_currency_id', 'id'); } + + /** + * @return BelongsToMany + */ + public function billGroup(): BelongsToMany + { + return $this->belongsToMany(BillGroup::class, BillGroupPayment::class, 'group_id', 'bill_group_id'); + } } diff --git a/database/migrations/2023_12_04_224416_create_bill_groups_table.php b/database/migrations/2023_12_04_224416_create_bill_groups_table.php new file mode 100644 index 00000000..e5fd986c --- /dev/null +++ b/database/migrations/2023_12_04_224416_create_bill_groups_table.php @@ -0,0 +1,44 @@ +id(); + $table->string('reference')->unique(); + $table->foreignId('issuer')->unsigned(); + $table->foreignId('receiver')->unsigned(); + $table->decimal('amount', 14, 5)->default(0.00); + $table->decimal('original_amount', 14, 5)->default(0.00); + $table->foreignId('currency_id')->unsigned(); + $table->foreignId('original_currency_id')->unsigned(); + $table->decimal('currency_rate', 14, 5)->default(0.00); + $table->decimal('tax', 14, 5)->default(0.00); + $table->decimal('service_charge', 14, 5)->default(0.00); + $table->integer('status')->default(ApprovalStatus::PENDING_VERIFICATION); + $table->softDeletes(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('bill_groups'); + } +} diff --git a/database/migrations/2023_12_04_224509_create_bill_group_payments_table.php b/database/migrations/2023_12_04_224509_create_bill_group_payments_table.php new file mode 100644 index 00000000..5e0d2aa2 --- /dev/null +++ b/database/migrations/2023_12_04_224509_create_bill_group_payments_table.php @@ -0,0 +1,34 @@ +id(); + $table->foreignId('bill_group_id')->constrained('bill_groups'); + $table->foreignId('group_id')->constrained('groups'); + $table->softDeletes(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('bill_group_payments'); + } +} diff --git a/resources/assets/vue/components/bookings/elements/BillGroupComponent.vue b/resources/assets/vue/components/bookings/elements/BillGroupComponent.vue new file mode 100644 index 00000000..42727055 --- /dev/null +++ b/resources/assets/vue/components/bookings/elements/BillGroupComponent.vue @@ -0,0 +1,254 @@ + + + diff --git a/resources/assets/vue/components/bookings/elements/BillGroupPaymentSummaryComponent.vue b/resources/assets/vue/components/bookings/elements/BillGroupPaymentSummaryComponent.vue new file mode 100644 index 00000000..9ad4f1d3 --- /dev/null +++ b/resources/assets/vue/components/bookings/elements/BillGroupPaymentSummaryComponent.vue @@ -0,0 +1,154 @@ + + + \ No newline at end of file diff --git a/resources/assets/vue/components/bookings/elements/TransactionGroupPaymentComponent.vue b/resources/assets/vue/components/bookings/elements/TransactionGroupPaymentComponent.vue new file mode 100644 index 00000000..b86cdce7 --- /dev/null +++ b/resources/assets/vue/components/bookings/elements/TransactionGroupPaymentComponent.vue @@ -0,0 +1,140 @@ + + + diff --git a/resources/assets/vue/components/bookings/forms/BillGroupPaymentProofFormComponent.vue b/resources/assets/vue/components/bookings/forms/BillGroupPaymentProofFormComponent.vue new file mode 100644 index 00000000..1adac911 --- /dev/null +++ b/resources/assets/vue/components/bookings/forms/BillGroupPaymentProofFormComponent.vue @@ -0,0 +1,80 @@ + + + \ No newline at end of file diff --git a/resources/assets/vue/components/bookings/forms/SupplierWhiteFormPlaceOrderFormComponent.vue b/resources/assets/vue/components/bookings/forms/SupplierWhiteFormPlaceOrderFormComponent.vue new file mode 100644 index 00000000..206a9daf --- /dev/null +++ b/resources/assets/vue/components/bookings/forms/SupplierWhiteFormPlaceOrderFormComponent.vue @@ -0,0 +1,201 @@ + + + \ No newline at end of file diff --git a/resources/assets/vue/components/bookings/sections/BillGroupListSectionComponent.vue b/resources/assets/vue/components/bookings/sections/BillGroupListSectionComponent.vue new file mode 100644 index 00000000..18aa285f --- /dev/null +++ b/resources/assets/vue/components/bookings/sections/BillGroupListSectionComponent.vue @@ -0,0 +1,136 @@ + + + \ No newline at end of file diff --git a/resources/assets/vue/components/bookings/sections/SupplierPendingOrderPaymentSectionComponent.vue b/resources/assets/vue/components/bookings/sections/SupplierPendingOrderPaymentSectionComponent.vue new file mode 100644 index 00000000..eba9fde5 --- /dev/null +++ b/resources/assets/vue/components/bookings/sections/SupplierPendingOrderPaymentSectionComponent.vue @@ -0,0 +1,113 @@ + + + \ No newline at end of file diff --git a/resources/assets/vue/components/general/forms/GeneralConfirmationFormComponent.vue b/resources/assets/vue/components/general/forms/GeneralConfirmationFormComponent.vue index cdb477ee..6d6ad557 100644 --- a/resources/assets/vue/components/general/forms/GeneralConfirmationFormComponent.vue +++ b/resources/assets/vue/components/general/forms/GeneralConfirmationFormComponent.vue @@ -57,7 +57,16 @@ submitForm() { if (this.params) this.parameters = this.params; return this.submit(this.apiRoute, this.apiMethod, this.section, true, true); - } + }, + successHandler(){ + this.closeModal(); + this.formHandler(); + if (this.section && (this.section === 'paymentInProgressBillGroupList' || this.section === 'paymentVerificationBillGroupList')) { + this.$store.dispatch('toggleSection', {name: 'paymentInProgressBillGroupList', status: !this.$store.getters.isShowing('paymentInProgressBillGroupList')}); + this.$store.dispatch('toggleSection', {name: 'paymentVerificationBillGroupList', status: !this.$store.getters.isShowing('paymentVerificationBillGroupList')}); + this.$store.dispatch('toggleSection', {name: 'paidBillGroupList', status: !this.$store.getters.isShowing('paidBillGroupList')}); + } + }, }, mixins: [componentHandler, ModalFormHandler] diff --git a/resources/views/pages/supplier-payments.blade.php b/resources/views/pages/supplier-payments.blade.php new file mode 100644 index 00000000..c94051e7 --- /dev/null +++ b/resources/views/pages/supplier-payments.blade.php @@ -0,0 +1,138 @@ +@extends('layouts.base_portal') +@section('inner_content') +
+
+
+
+
+
+
+
+ Supplier Currency Orders +
+
+
+
+
+
+
+
+ +
+
+
+
+
Pending Payment
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
Payment In Progress
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
Payment Verification
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
Paid Currency Order
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+@endsection \ No newline at end of file diff --git a/resources/views/partials/header.blade.php b/resources/views/partials/header.blade.php index b618e334..eaeeaec7 100644 --- a/resources/views/partials/header.blade.php +++ b/resources/views/partials/header.blade.php @@ -38,6 +38,11 @@
Currency Orders
+
+ +
Supplier Currency Orders
+
+
Transfers
diff --git a/routes/transaction.php b/routes/transaction.php index e714d6b7..1996b012 100644 --- a/routes/transaction.php +++ b/routes/transaction.php @@ -8,6 +8,7 @@ Route::group(['prefix' => 'transactions', 'namespace' => 'Transactions', 'as' => Route::delete('/suspend/{id}', 'SuspendTransactionController@suspend')->name('suspend'); route::post('/supplier/{id}/bill/create', 'CreateSupplierTransactionController@create')->name('supplier.create'); + route::post('/supplier/{id}/bill/group/create', 'CreateSupplierBillGroupController@create')->name('supplier.bill_group.create'); route::post('{id}/bill/verification', 'CreatePaymentProofDocumentController@verify')->name('bill.verification'); route::post('{id}/bill/pay', 'CreatePaymentProofDocumentController@pay')->name('bill.pay'); Route::put('/{id}/bill/{status}', 'UpdatePaymentTransactionStatusController@update')->where('status', 'pending|complete')->name('bill.status'); @@ -33,5 +34,14 @@ Route::group(['prefix' => 'transactions', 'namespace' => 'Transactions', 'as' => Route::put('/{id}/update', 'UpdateGroupController@update')->name('update'); Route::post('/{id}/approve', 'CreateBulkPurchaseOrderDocumentController@aprove')->name('approve'); Route::post('/bulk/po', 'CreateBulkPurchaseOrderDocumentController@create')->name('bulk.po'); + + Route::group(['prefix' => 'bills', 'as' => 'bill.'], function () { + Route::get('/list', 'ListBillGroupsController@list')->name('list'); + Route::post('/transaction/{id}', 'CreateBillGroupPaymentProofDocumentController@create')->name('payment_proof.create'); + Route::post('/transaction/{id}/approval/{status}', 'ApproveBillGroupPaymentVerificationController@approve')->where('status', 'approve|reject')->name('payment_proof.approval'); + Route::delete('/{id}/delete', 'DeleteBillGroupController@delete')->name('delete'); + Route::post('/{id}/pay', 'CreateBillGroupPaymentTransactionController@pay')->name('pay'); + // Route::post('/bulk/po', 'CreateBulkPurchaseOrderDocumentController@create')->name('bulk.po'); + }); }); }); \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index ead4b3d2..41b1f7dd 100644 --- a/routes/web.php +++ b/routes/web.php @@ -88,6 +88,10 @@ Route::get('/payments', function () { return view('pages.payments'); })->name('payments'); +Route::get('/supplier-payments', function () { + return view('pages.supplier-payments'); +})->name('supplier.payments'); + Route::get('/billings', function () { return view('pages.billings'); })->name('billings');