diff --git a/app/Classes/General/Eloquent/Filters/DoesNotHaveGroupTransactions.php b/app/Classes/General/Eloquent/Filters/DoesNotHaveGroupTransactions.php new file mode 100644 index 00000000..22a6b4d7 --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/DoesNotHaveGroupTransactions.php @@ -0,0 +1,18 @@ +whereDoesntHave('groupTransactions'); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Groups/DataTransferObjects/GroupObject.php b/app/Classes/Modules/Groups/DataTransferObjects/GroupObject.php index ef8e0121..050a8ef3 100644 --- a/app/Classes/Modules/Groups/DataTransferObjects/GroupObject.php +++ b/app/Classes/Modules/Groups/DataTransferObjects/GroupObject.php @@ -42,6 +42,9 @@ class GroupObject implements DataTransferObject /** @var string */ private $reference; + /** @var int */ + private $paymentMethod; + /** * GroupObject constructor. * @param int $issuer @@ -55,6 +58,7 @@ class GroupObject implements DataTransferObject * @param float $serviceCharge * @param string $reference * @param int|null $status + * @param int $paymentMethod */ public function __construct( int $issuer, @@ -66,6 +70,7 @@ class GroupObject implements DataTransferObject float $currencyRate, float $tax, float $serviceCharge, + int $paymentMethod, ?string $reference, ?int $status = ApprovalStatus::PENDING_SUBMISSION, ) @@ -79,6 +84,7 @@ class GroupObject implements DataTransferObject $this->currencyRate = $currencyRate; $this->tax = $tax; $this->serviceCharge = $serviceCharge; + $this->paymentMethod = $paymentMethod; $this->reference = $reference; $this->status = $status; } @@ -170,4 +176,12 @@ class GroupObject implements DataTransferObject { return $this->reference; } + + /** + * @return int + */ + public function getPaymentMethod(): int + { + return $this->paymentMethod; + } } \ No newline at end of file diff --git a/app/Classes/Modules/Groups/Services/CreatesGroup.php b/app/Classes/Modules/Groups/Services/CreatesGroup.php index 1aa2a298..bb5698d3 100644 --- a/app/Classes/Modules/Groups/Services/CreatesGroup.php +++ b/app/Classes/Modules/Groups/Services/CreatesGroup.php @@ -26,6 +26,7 @@ class CreatesGroup extends AbstractUpdateRecord $model->service_charge = $object->getServiceCharge(); $model->status = $object->getStatus(); $model->reference = $object->getReference(); + $model->payment_method = $object->getPaymentMethod(); return $this->handler($model); } diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateGroupsLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateGroupsLogic.php index 26fc48b7..ff7bf82c 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/CreateGroupsLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateGroupsLogic.php @@ -118,6 +118,7 @@ class CreateGroupsLogic extends AbstractControllerLogic $currency_rate, $tax, $service_charge, + $payment_method, '-', $groupPyamentStatus, ); @@ -146,13 +147,13 @@ class CreateGroupsLogic extends AbstractControllerLogic $groupTransaction->save(); } - if ($payment_method === PaymentMethodType::PAYMENT_GATEWAY) { - // create only one billplz payment + if (in_array($payment_method, [PaymentMethodType::PAYMENT_GATEWAY, PaymentMethodType::CASH])) { + // create only one billplz payment for wallet top up $amount = floatval(str_replace(',', '', $request->input('amount'))); $companyModuleId = $invoice->receiver; $companyModule = $this->fetchesCompanyModule->execute(['id' => $companyModuleId]); - $topUpTransaction = $this->createWalletTopUpTransactionProcessor->execute($companyModule, $amount, $request->input('bank_code'), true); + $topUpTransaction = $this->createWalletTopUpTransactionProcessor->execute($companyModule, $amount, $request->input('bank_code'), true, $payment_method); } $group->issuer = $issuer; diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentTransactionLogic.php index d85e976c..48e2de6a 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentTransactionLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreatePaymentTransactionLogic.php @@ -5,30 +5,15 @@ namespace App\Classes\Modules\Transactions\ControllersLogic; use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Transactions\Services\FetchesTransaction; -use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber; -use App\Classes\Modules\Transactions\Services\CreatesPaymentTransaction; -use App\Classes\Modules\Transactions\Services\CreatesTransactionDetail; -use App\Classes\Modules\Billplzs\Services\CreatesBillplzBill; - -use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject; -use App\Classes\Modules\Transactions\DataTransferObjects\TransactionDetailObject; - -use App\Classes\ValueObjects\Constants\OrderRoleTypes; -use App\Classes\ValueObjects\Constants\TransactionType; use App\Classes\ValueObjects\Constants\PaymentMethodType; -use App\Classes\ValueObjects\Constants\ApprovalStatus; - use App\Http\Resources\TransactionResource; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -use Illuminate\Support\Facades\Storage; -use Illuminate\Support\Str; -use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf; +use App\Classes\Modules\Transactions\Processors\CreatePaymentTransactionProcessor; class CreatePaymentTransactionLogic extends AbstractControllerLogic { - /** * @return array */ @@ -42,83 +27,25 @@ class CreatePaymentTransactionLogic extends AbstractControllerLogic /** @var FetchesTransaction */ private $fetchesTransaction; - /** @var FetchesSegmentConstant */ - private $fetchesSegmentConstant; - - /** @var GeneratesTransactionBillNumber */ - private $generatesTransactionBillNumber; - - /** @var CreatesPaymentTransaction */ - private $createsPaymentTransaction; - - /** @var CreatesBillplzBill */ - private $createsBillplzBill; - - /** @var CreatesTransactionDetail */ - private $createsTransactionDetail; + /** @var CreatePaymentTransactionProcessor */ + private $createPaymentTransactionProcessor; public function __construct( FetchesTransaction $fetchesTransaction, - GeneratesTransactionBillNumber $generatesTransactionBillNumber, - CreatesPaymentTransaction $createsPaymentTransaction, - CreatesTransactionDetail $createsTransactionDetail, - CreatesBillplzBill $createsBillplzBill + CreatePaymentTransactionProcessor $createPaymentTransactionProcessor ) { $this->fetchesTransaction = $fetchesTransaction; - $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; - $this->createsPaymentTransaction = $createsPaymentTransaction; - $this->createsTransactionDetail = $createsTransactionDetail; - $this->createsBillplzBill = $createsBillplzBill; + $this->createPaymentTransactionProcessor = $createPaymentTransactionProcessor; } public function logic(Request $request) : JsonResponse { + $payment_method = PaymentMethodType::PAYMENT_METHODS[$request->input('payment_method')]; + $invoice_transaction = $this->fetchesTransaction->execute(['id' => $request->input('transaction_id')]); - $amount = $request->input('amount'); - $company_module = $invoice_transaction->owner()->first()->owner()->first()->companyModule()->first(); - $billNumber = $this->generatesTransactionBillNumber->execute('PYMT-'); - $payment_reference = null; - if ($request->input('payment_method') == 5) { - $payment_method = PaymentMethodType::PAYMENT_GATEWAY; - $billPlzBill = $this->createsBillplzBill->execute( - $company_module->name, - (app()->environment(['production'])) ? $company_module->employees()->first()->email : 'uldvstar@gmail.com', - 'This payment is for the invoice number . ' . $invoice_transaction->bill_no, - $amount, - $billNumber, - $request->input('bank_code'), - true - ); - - $payment_reference = $billPlzBill->id; - } - else { - $payment_method = PaymentMethodType::CASH; - } - - $object = new TransactionObject( - $billNumber, - TransactionType::PAYMENT, - $company_module->id, - 1, - 1, - $payment_method, - $request->input('amount'), - $request->input('amount'), - 1, - 1, - 0, - 0, - 0, - null, - ApprovalStatus::PENDING_SUBMISSION, - null, - $payment_reference - ); - - $payment_transaction = $this->createsPaymentTransaction->execute($invoice_transaction, $object); + $payment_transaction = $this->createPaymentTransactionProcessor->execute($invoice_transaction, $payment_method , $request->input('bank_code')); return $this->resourceResponse(new TransactionResource($payment_transaction)); } diff --git a/app/Models/Group.php b/app/Models/Group.php index f67bf028..276b0aa5 100644 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -11,13 +11,14 @@ use Staudenmeir\EloquentHasManyDeep\HasManyDeep; use Staudenmeir\EloquentHasManyDeep\HasRelationships; use App\Classes\General\Interfaces\Transactionable; use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\SoftDeletes; class Group extends Model implements Documentable, Transactionable { use HasRelationships; use \Staudenmeir\EloquentHasManyDeep\HasTableAlias; - + use SoftDeletes; /** * @return MorphMany 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 db397f52..8dfe6f83 100644 --- a/database/migrations/2023_03_19_170628_create_groups_table.php +++ b/database/migrations/2023_03_19_170628_create_groups_table.php @@ -28,6 +28,7 @@ class CreateGroupsTable extends Migration $table->decimal('service_charge', 14, 5)->default(0.00); $table->integer('status')->default(ApprovalStatus::PENDING_VERIFICATION); $table->string('payment_method')->nullable(); + $table->softDeletes(); $table->timestamps(); }); } diff --git a/database/migrations/2023_03_19_170641_create_group_transactions_table.php b/database/migrations/2023_03_19_170641_create_group_transactions_table.php index 45c541c5..ccd4b32b 100644 --- a/database/migrations/2023_03_19_170641_create_group_transactions_table.php +++ b/database/migrations/2023_03_19_170641_create_group_transactions_table.php @@ -17,6 +17,7 @@ class CreateGroupTransactionsTable extends Migration $table->id(); $table->foreignId('group_id')->unsigned(); $table->foreignId('transaction_id')->unsigned(); + $table->softDeletes(); $table->timestamps(); }); } diff --git a/resources/assets/vue/components/companies/sections/CustomerPaymentBillingSectionComponent.vue b/resources/assets/vue/components/companies/sections/CustomerPaymentBillingSectionComponent.vue index 86bef424..30dd267e 100644 --- a/resources/assets/vue/components/companies/sections/CustomerPaymentBillingSectionComponent.vue +++ b/resources/assets/vue/components/companies/sections/CustomerPaymentBillingSectionComponent.vue @@ -84,12 +84,12 @@
- +
- +
diff --git a/resources/assets/vue/components/paymentsBilling/elements/GroupPaymentsBillingComponents.vue b/resources/assets/vue/components/paymentsBilling/elements/GroupPaymentsBillingComponents.vue index ffef7ce8..f32e39c7 100644 --- a/resources/assets/vue/components/paymentsBilling/elements/GroupPaymentsBillingComponents.vue +++ b/resources/assets/vue/components/paymentsBilling/elements/GroupPaymentsBillingComponents.vue @@ -27,6 +27,16 @@
+
+
+ +
+
+
+
+ +
+
+ + + @@ -65,12 +78,16 @@ return { expanded: false, selectedValue: false, + selected_id: '', } }, methods: { activate(){ this.select = !this.select; this.$emit('input', this.data); + }, + selectedID(id){ + this.selected_id = id; } }, computed: { diff --git a/resources/assets/vue/components/paymentsBilling/elements/PaymentsBillingComponents.vue b/resources/assets/vue/components/paymentsBilling/elements/PaymentsBillingComponents.vue index 83b1e002..337427de 100644 --- a/resources/assets/vue/components/paymentsBilling/elements/PaymentsBillingComponents.vue +++ b/resources/assets/vue/components/paymentsBilling/elements/PaymentsBillingComponents.vue @@ -4,7 +4,7 @@
-
+
diff --git a/resources/assets/vue/components/paymentsBilling/elements/ShippingTransactionComponent.vue b/resources/assets/vue/components/paymentsBilling/elements/ShippingTransactionComponent.vue index 56401dda..eb56a99e 100644 --- a/resources/assets/vue/components/paymentsBilling/elements/ShippingTransactionComponent.vue +++ b/resources/assets/vue/components/paymentsBilling/elements/ShippingTransactionComponent.vue @@ -37,7 +37,7 @@ - +
diff --git a/resources/assets/vue/components/paymentsBilling/forms/PaymentFormComponent.vue b/resources/assets/vue/components/paymentsBilling/forms/PaymentFormComponent.vue index f61ac040..712269be 100644 --- a/resources/assets/vue/components/paymentsBilling/forms/PaymentFormComponent.vue +++ b/resources/assets/vue/components/paymentsBilling/forms/PaymentFormComponent.vue @@ -134,7 +134,7 @@ }, methods:{ submitForm(){ - this.parameters.payment_method = this.paymentMethod.id === 'payment_gateway' ? 5 : ''; + this.parameters.payment_method = this.paymentMethod.id; this.submit(this.route('api.transaction.payment.create'), 'post', 'orderProfileSection', true, true); }, updatePaymentType(payment){