diff --git a/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php b/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php index d865de90..537352ec 100644 --- a/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php +++ b/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php @@ -111,6 +111,19 @@ class CallbackBillplzLogic $this->updatesWalletBalance->execute($transaction->owner, $transaction->amount); } + // group payment + if ($transaction->type == TransactionType::GROUP_PAYMENT && $status === ApprovalStatus::APPROVED &&!in_array($transaction->status, [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])) { + $group = Group::where('reference', $billplzXSignatureObject->getBillPlzId())->first(); + + foreach($group->groupTransactions as $groupTransaction) { + $invoice = $groupTransaction->transaction; + $this->createPaymentTransactionProcessor->execute($invoice, PaymentMethodType::WALLET, null); + } + + $group->status = $status; + $group->save(); + } + $this->updatesTransactionStatus->execute($transaction, $status); if (!$transaction->owner instanceof Wallet) { @@ -138,15 +151,6 @@ class CallbackBillplzLogic $company_module_marking = $order->companyModule->connections? $order->companyModule->connections->first()->invitee_reference: null; } - if ($transaction->type == TransactionType::GROUP_PAYMENT) { - $group = Group::where('reference', $billplzXSignatureObject->getBillPlzId())->first(); - - foreach($group->groupTransactions as $groupTransaction) { - $invoice = $groupTransaction->transaction; - $this->createPaymentTransactionProcessor->execute($invoice, PaymentMethodType::WALLET, null); - } - } - return $request->method() === 'POST' ? true : view('pages.payments_redirect', ['marking' => $order->reference ?? null, 'company_module_marking' => $company_module_marking ?? null, 'transaction' => $transaction, 'status' => $status]); } } diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateGroupsLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateGroupsLogic.php index 8c880ef8..dcc7f1c1 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/CreateGroupsLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateGroupsLogic.php @@ -15,6 +15,7 @@ use App\Models\Transaction; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use App\Classes\Modules\Wallets\Processors\CreateWalletTopUpTransactionProcessor; +use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Models\GroupTransaction; use App\Http\Resources\WalletTransactionResource; use App\Models\Wallet; @@ -67,7 +68,8 @@ class CreateGroupsLogic extends AbstractControllerLogic public function logic(Request $request) : JsonResponse { - $payment_method = PaymentMethodType::PAYMENT_METHODS[$request->input('payment_method')]; + $payment_method = PaymentMethodType::PAYMENT_METHODS[$request->input('payment_method')]; + $groupPyamentStatus = ApprovalStatus::PENDING_VERIFICATION; $invoice_ids = json_decode($request->route('transaction_ids')); $billNumber = $this->generatesTransactionBillNumber->execute('PYMT-'); @@ -86,6 +88,8 @@ class CreateGroupsLogic extends AbstractControllerLogic if((float) number_format(($wallet->amount - $request->input('amount')),2) < 0){ throw new MalformedRequestException('Insufficient wallet balance. Please Top up your wallet.'); } + + $groupPyamentStatus = ApprovalStatus::APPROVED; } $group = new Group(); @@ -108,6 +112,7 @@ class CreateGroupsLogic extends AbstractControllerLogic $group->currency_rate = $currency_rate; $group->tax = $tax; $group->service_charge = $service_charge; + $group->payment_method = $payment_method; $group->save(); foreach ($invoices as $invoice) { @@ -151,8 +156,7 @@ class CreateGroupsLogic extends AbstractControllerLogic $group->currency_rate = $currency_rate; $group->tax = $tax; $group->service_charge = $service_charge; - // todo-new: updates group status - // $group->status = $service_charge; + $group->status = $groupPyamentStatus; $group->save(); if ($payment_method === PaymentMethodType::PAYMENT_GATEWAY) { diff --git a/app/Http/Resources/GroupResource.php b/app/Http/Resources/GroupResource.php index abd017ec..d5a62aa9 100644 --- a/app/Http/Resources/GroupResource.php +++ b/app/Http/Resources/GroupResource.php @@ -3,12 +3,8 @@ namespace App\Http\Resources; use App\Classes\ValueObjects\Constants\ApprovalStatus; -use App\Classes\ValueObjects\Constants\DocumentType; -use App\Classes\ValueObjects\Constants\TransactionType; -use App\Models\Booking; -use App\Models\Transaction; +use App\Classes\ValueObjects\Constants\PaymentMethodType; use Carbon\Carbon; -use Illuminate\Database\Eloquent\Collection; use Illuminate\Http\Resources\Json\JsonResource; class GroupResource extends JsonResource @@ -22,9 +18,8 @@ class GroupResource extends JsonResource public function toArray($request) { - if(!$this->issuerCompany){ - dd($this->id); - } + // dd($this->groupTransactions); + return [ 'id' => $this->id, 'original_amount' => (float) $this->original_amount, @@ -36,18 +31,12 @@ class GroupResource extends JsonResource 'currency' => new CurrencyResource($this->currency), 'created_at' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A'), 'currency_rate' => (float) $this->currency_rate, - 'transactions' => $this->transactions()->get()->pluck('owner.owner.marking'), - 'complete_transactions' => $this->transactions()->whereHasMorph('owner', [Transaction::class], function($query){ - return $query->whereHas('booking', function($query){ - return $query->whereHas('transactions', function($query){ - return $query->where('type', TransactionType::PURCHASE_ORDER)->where('status', '=', ApprovalStatus::APPROVED); - }); - }); - })->get()->pluck('owner.owner.marking'), - 'documents' => [ - 'currency_order' => new DocumentResource($this->documents()->where('document_type', DocumentType::CURRENCY_VENDOR_ORDER)->first()), - 'purchase_order' => new DocumentResource($this->documents()->where('document_type', DocumentType::BULK_PURCHASE_ORDER)->first()) - ] + 'status' => $this->status, + 'status_name' => ApprovalStatus::APPROVAL_STATUS_ID[$this->status], + 'payment_method' => $this->payment_method, + 'payment_method_name' => ucwords(PaymentMethodType::PAYMENT_METHODS_ID[$this->payment_method]), + 'invoices' => GroupTransactionResource::collection($this->groupTransactions), + 'reference' => $this->reference, ]; } } diff --git a/app/Http/Resources/GroupTransactionResource.php b/app/Http/Resources/GroupTransactionResource.php new file mode 100644 index 00000000..ec56de52 --- /dev/null +++ b/app/Http/Resources/GroupTransactionResource.php @@ -0,0 +1,25 @@ +transaction); + } +} diff --git a/database/migrations/2023_03_19_170628_create_groups_table.php b/database/migrations/2023_03_19_170628_create_groups_table.php index 569627c2..db397f52 100644 --- a/database/migrations/2023_03_19_170628_create_groups_table.php +++ b/database/migrations/2023_03_19_170628_create_groups_table.php @@ -27,6 +27,7 @@ class CreateGroupsTable extends Migration $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->string('payment_method')->nullable(); $table->timestamps(); }); } diff --git a/resources/assets/vue/components/companies/elements/CustomerPaymentBillingInnerComponent.vue b/resources/assets/vue/components/companies/elements/CustomerPaymentBillingInnerComponent.vue index 0eeb1eb9..a147bf2a 100644 --- a/resources/assets/vue/components/companies/elements/CustomerPaymentBillingInnerComponent.vue +++ b/resources/assets/vue/components/companies/elements/CustomerPaymentBillingInnerComponent.vue @@ -4,14 +4,15 @@
- +
-
+
@@ -89,6 +90,10 @@ type: Number, required: true, }, + endpoint: { + type: String, + required: true + }, }, data(){ return { diff --git a/resources/assets/vue/components/companies/sections/CustomerPaymentBillingSectionComponent.vue b/resources/assets/vue/components/companies/sections/CustomerPaymentBillingSectionComponent.vue index b594b3a5..86bef424 100644 --- a/resources/assets/vue/components/companies/sections/CustomerPaymentBillingSectionComponent.vue +++ b/resources/assets/vue/components/companies/sections/CustomerPaymentBillingSectionComponent.vue @@ -27,7 +27,7 @@
-
+
-
Payment In Progress
+
Group Payment In Progress
+
+
+
+
+
+
+ + +
+
+
+
+
Paid Group Invoice
@@ -68,17 +84,22 @@
- +
-
+
- + +
+
+
+
+
- +
diff --git a/resources/assets/vue/components/paymentsBilling/elements/GroupPaymentsBillingComponents.vue b/resources/assets/vue/components/paymentsBilling/elements/GroupPaymentsBillingComponents.vue new file mode 100644 index 00000000..ffef7ce8 --- /dev/null +++ b/resources/assets/vue/components/paymentsBilling/elements/GroupPaymentsBillingComponents.vue @@ -0,0 +1,89 @@ + + diff --git a/resources/assets/vue/components/paymentsBilling/elements/PaymentsBillingComponents.vue b/resources/assets/vue/components/paymentsBilling/elements/PaymentsBillingComponents.vue index f00e8be4..83b1e002 100644 --- a/resources/assets/vue/components/paymentsBilling/elements/PaymentsBillingComponents.vue +++ b/resources/assets/vue/components/paymentsBilling/elements/PaymentsBillingComponents.vue @@ -4,7 +4,7 @@
-
+
@@ -23,7 +23,7 @@

Amount

MYR {{ item.amount.toFixed(2) }}
-
+

Payment Date

{{ item.payment_history[item.payment_history.length-1].created_at }}
diff --git a/resources/assets/vue/components/paymentsBilling/forms/GroupPaymentFormComponent.vue b/resources/assets/vue/components/paymentsBilling/forms/GroupPaymentFormComponent.vue index 3dee0077..f41de96d 100644 --- a/resources/assets/vue/components/paymentsBilling/forms/GroupPaymentFormComponent.vue +++ b/resources/assets/vue/components/paymentsBilling/forms/GroupPaymentFormComponent.vue @@ -196,7 +196,7 @@ methods:{ submitForm(){ this.parameters.payment_method = this.paymentMethod.id; - this.submit(this.route('api.transaction.group.create', JSON.stringify(this.selectedIds)), 'post', this.section, true, false); + this.submit(this.route('api.transaction.group.create', JSON.stringify(this.selectedIds)), 'post', this.section, true, true); }, updatePaymentType(payment){ this.paymentMethod = {