diff --git a/app/Classes/Jobs/UpdatePerfexCRMPrelude.php b/app/Classes/Jobs/UpdatePerfexCRMPrelude.php index 3b05ac63..1bf9dede 100644 --- a/app/Classes/Jobs/UpdatePerfexCRMPrelude.php +++ b/app/Classes/Jobs/UpdatePerfexCRMPrelude.php @@ -41,7 +41,11 @@ class UpdatePerfexCRMPrelude implements ShouldQueue { $serviceTypeName = $this->transaction->owner->company->services()->where('id', $this->transaction->owner->service_id)->first()->name; $booking = $this->transaction->booking; - $bankDetails = $this->generateBankDetails($booking->bank); + $bank = $booking->bank; //cief todo: 66 + if($this->transaction->bank){ + $bank = $this->transaction->bank; + } + $bankDetails = $this->generateBankDetails($bank); $data = [ 'amount' => number_format($this->transaction->amount, 2, '.', ''), diff --git a/app/Classes/Modules/Accounts/Services/DeletesKeyValuePair.php b/app/Classes/Modules/Accounts/Services/DeletesKeyValuePair.php new file mode 100644 index 00000000..a52288af --- /dev/null +++ b/app/Classes/Modules/Accounts/Services/DeletesKeyValuePair.php @@ -0,0 +1,19 @@ +handler($model); + } +} diff --git a/app/Classes/Modules/Banks/ControllersLogic/UpdateBankLogic.php b/app/Classes/Modules/Banks/ControllersLogic/UpdateBankLogic.php index 8509ed6b..88172f47 100644 --- a/app/Classes/Modules/Banks/ControllersLogic/UpdateBankLogic.php +++ b/app/Classes/Modules/Banks/ControllersLogic/UpdateBankLogic.php @@ -3,21 +3,17 @@ namespace App\Classes\Modules\Banks\ControllersLogic; use App\Http\Resources\BankResource; - use App\Classes\General\Abstracts\AbstractControllerLogic; - use App\Classes\Modules\Banks\Services\FetchesBank; - use App\Classes\Modules\Banks\Standards\Rules\CanUpdateBank; use App\Classes\Modules\Banks\Services\UpdatesBank; +use App\Classes\Modules\Banks\Services\CreatesOrUpdateBank; use App\Classes\Modules\Banks\Services\CreatesBankLog; - +use App\Classes\Modules\Banks\Processors\UpdateBankProcessor; use App\Classes\Modules\Banks\DataTransferObjects\BankObject; - -use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -use Illuminate\Support\Facades\DB; + class UpdateBankLogic extends AbstractControllerLogic { @@ -44,24 +40,36 @@ class UpdateBankLogic extends AbstractControllerLogic /** @var CreatesBankLog */ private $createsBankLog; + /** @var CreatesOrUpdateBank */ + private $createsOrUpdateBank; + + /** @var UpdateBankProcessor */ + private $updateBankProcessor; + /** * UpdateBankLogic constructor. * @param CanUpdateBank $canUpdateBank * @param UpdatesBank $updatesBank * @param FetchesBank $fetchesBank * @param CreatesBankLog $createsBankLog + * @param CreatesOrUpdateBank $createsOrUpdateBank + * @param UpdateBankProcessor $updateBankProcessor */ public function __construct( CanUpdateBank $canUpdateBank, UpdatesBank $updatesBank, FetchesBank $fetchesBank, - CreatesBankLog $createsBankLog + CreatesBankLog $createsBankLog, + CreatesOrUpdateBank $createsOrUpdateBank, + UpdateBankProcessor $updateBankProcessor ) { $this->canUpdateBank = $canUpdateBank; $this->updatesBank = $updatesBank; $this->fetchesBank = $fetchesBank; $this->createsBankLog = $createsBankLog; + $this->createsOrUpdateBank = $createsOrUpdateBank; + $this->updateBankProcessor = $updateBankProcessor; } /** @@ -74,15 +82,15 @@ class UpdateBankLogic extends AbstractControllerLogic public function logic(Request $request) : JsonResponse { $bankObject = new BankObject( - $request->input('company_id'), + $request->input('company_id'), $request->input('account_type'), $request->input('bank_name'), - $request->input('holder_name'), + $request->input('holder_name'), $request->input('account_no'), - $request->input('bank_branch'), - $request->input('swift'), + $request->input('bank_branch'), + $request->input('swift'), $request->input('snap'), - $request->input('country_id'), + $request->input('country_id'), $request->input('reference') ); @@ -90,12 +98,10 @@ class UpdateBankLogic extends AbstractControllerLogic $this->canUpdateBank->passes($bankObject); - $bank_query = $this->updatesBank->execute($bank, $bankObject); - -// $bankLog = $this->createsBankLog->execute($bank_query); + $bank_query = $this->updateBankProcessor->execute($bankObject, $bank, $request->input('bill_no') ?? '', (int) $request->input('transaction_id') ?? 0 ); return $this->resourceResponse(new BankResource($bank_query)); } -} \ No newline at end of file +} diff --git a/app/Classes/Modules/Banks/ControllersLogic/UpdateBankMetadataLogic.php b/app/Classes/Modules/Banks/ControllersLogic/UpdateBankMetadataLogic.php new file mode 100644 index 00000000..1dc79f1a --- /dev/null +++ b/app/Classes/Modules/Banks/ControllersLogic/UpdateBankMetadataLogic.php @@ -0,0 +1,67 @@ + 'Update Bank Metadata', + 'message' => 'You have successfully updated the Bank metadata' + ]; + } + + /** @var CanUpdateBankMetadata */ + private $canUpdateBankMetadata; + + /** @var FetchesTransaction */ + private $fetchesTransaction; + + /** + * UpdateBankMetadataLogic constructor. + * @param CanUpdateBankMetadata $canUpdateBankMetadata + * @param FetchesTransaction $fetchesTransaction + */ + public function __construct( + CanUpdateBankMetadata $canUpdateBankMetadata, + FetchesTransaction $fetchesTransaction + ) + { + $this->canUpdateBankMetadata = $canUpdateBankMetadata; + $this->fetchesTransaction = $fetchesTransaction; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + $bankMetadataObject = new BankMetadataObject( + $request->input('transactionId'), + ); + + $this->canUpdateBankMetadata->passes($bankMetadataObject); + + $transaction = $this->fetchesTransaction->execute(['id' => $request->input('transactionId')]); + $transaction->attributes()->delete(); + + return $this->response([]); + } + +} diff --git a/app/Classes/Modules/Banks/DataTransferObjects/BankMetadataObject.php b/app/Classes/Modules/Banks/DataTransferObjects/BankMetadataObject.php new file mode 100644 index 00000000..dae7a61e --- /dev/null +++ b/app/Classes/Modules/Banks/DataTransferObjects/BankMetadataObject.php @@ -0,0 +1,29 @@ +transaction_id = $transaction_id; + } + + /** + * @return int + */ + public function getTransactionId(): int + { + return $this->transaction_id; + } +} diff --git a/app/Classes/Modules/Banks/Processors/UpdateBankProcessor.php b/app/Classes/Modules/Banks/Processors/UpdateBankProcessor.php new file mode 100644 index 00000000..a646cb95 --- /dev/null +++ b/app/Classes/Modules/Banks/Processors/UpdateBankProcessor.php @@ -0,0 +1,97 @@ +updatesBank = $updatesBank; + $this->createsOrUpdateBank = $createsOrUpdateBank; + $this->createsKeyValuePair = $createsKeyValuePair; + $this->fetchesTransaction = $fetchesTransaction; + } + + /** + * @param BankObject $bankObject + * @param Bank $bank + * @param string $billNo + * @param int $transactionId + * @return Model + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\JobResourceNotFoundException + */ + public function execute(BankObject $bankObject, Bank $bank, string $billNo, int $transactionId) { + $result = null; + if($billNo && $transactionId){ + $transaction = $this->fetchesTransaction->execute(['id' => $transactionId]); + //If payment transaction do not have a bank yet, create one + if(!$transaction->bank){ + $result = $this->createsOrUpdateBank->execute($bankObject); + + // if ($result->wasRecentlyCreated) { + //Key #1 for Bank + $kvp = $bank->attributes()->where('key', 'App\Models\Bank')->where('value', $result->id)->latest()->first(); + if(!$kvp){ + $keyValuePairObject = new KeyValuePairObject( + "App\Models\Bank", + $result->id + ); + $this->createsKeyValuePair->execute($bank, $keyValuePairObject); + } + + //Key #2 for Payment Transaction (owner type: booking) + $keyValuePairObject = new KeyValuePairObject( + "App\Models\Bank", + $result->id + ); + $this->createsKeyValuePair->execute($transaction, $keyValuePairObject); + // } + + } + else{ + $result = $this->updatesBank->execute($transaction->bank, $bankObject); + } + } + else{ + $result = $this->updatesBank->execute($bank, $bankObject); + } + + return $result; + } +} diff --git a/app/Classes/Modules/Banks/Services/CreatesOrUpdateBank.php b/app/Classes/Modules/Banks/Services/CreatesOrUpdateBank.php new file mode 100644 index 00000000..1c582229 --- /dev/null +++ b/app/Classes/Modules/Banks/Services/CreatesOrUpdateBank.php @@ -0,0 +1,44 @@ + $object->getCompanyId(), + 'account_no' => $object->getAccountNo(), + 'reference' => $object->getReference(), + 'bank_name' => $object->getBankName(), + 'holder_name' => $object->getHolderName(), + 'bank_branch' => $object->getBankBranch(), + 'type' => $object->getType(), + 'country_id' => $object->getCountryId(), + 'created_by' => Auth::id(), + 'creator_type' => in_array($user->type, RoleTypes::ADMIN_ROLES) ? RoleTypes::ADMIN : RoleTypes::USER, + ]; + + $values = [ + 'swift' => $object->getSwift(), + 'snap' => $object->getSnap(), + ]; + + $model = Bank::updateOrCreate($attributes, $values); //Bank::firstOrCreate($attributes, $values); + + return $model; + } +} diff --git a/app/Classes/Modules/Banks/Standards/Rules/CanUpdateBankMetadata.php b/app/Classes/Modules/Banks/Standards/Rules/CanUpdateBankMetadata.php new file mode 100644 index 00000000..7d4de3aa --- /dev/null +++ b/app/Classes/Modules/Banks/Standards/Rules/CanUpdateBankMetadata.php @@ -0,0 +1,66 @@ +validation = $validation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + //cief todo: 66 - temporary workaround + // if (!Auth::user()->can('update bank_metadata')) { + // return false; + // } + + // return true; + + if (in_array(Auth::user()->type, RoleTypes::ADMIN_ROLES)) { + return true; + } + + return false; + } + + /** + * @param BankMetadataObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->validation->validate($object); + } + + /** + * @param BankMetadataObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} diff --git a/app/Classes/Modules/Banks/Standards/Validators/BankMetadataValidation.php b/app/Classes/Modules/Banks/Standards/Validators/BankMetadataValidation.php new file mode 100644 index 00000000..37e134c4 --- /dev/null +++ b/app/Classes/Modules/Banks/Standards/Validators/BankMetadataValidation.php @@ -0,0 +1,38 @@ + $object->getTransactionId(), + ]; + } + + /** + * @return array + */ + protected function rules(): array + { + return [ + 'transaction_id' => 'required', + ]; + } + + /** + * @return array + */ + protected function messages(): array + { + return []; + } +} diff --git a/app/Classes/Modules/Exports/Services/ExportsAnalyticBillingTransactions.php b/app/Classes/Modules/Exports/Services/ExportsAnalyticBillingTransactions.php index af4c88c4..d368574f 100644 --- a/app/Classes/Modules/Exports/Services/ExportsAnalyticBillingTransactions.php +++ b/app/Classes/Modules/Exports/Services/ExportsAnalyticBillingTransactions.php @@ -65,8 +65,12 @@ class ExportsAnalyticBillingTransactions implements FromCollection, WithHeadings $bill = $transaction; $payment = $transaction->owner; $booking = $payment->owner; + $bank = $booking->bank; //cief todo: 66 + if($payment->bank){ + $bank = $payment->bank; + } $company = $booking->company; - $ecommerce = str::contains($booking->bank->bank_name, ['浙江网商银行']); + $ecommerce = str::contains($bank->bank_name, ['浙江网商银行']); return [ $booking->id, @@ -88,4 +92,4 @@ class ExportsAnalyticBillingTransactions implements FromCollection, WithHeadings $bill->created_at ]; } -} \ No newline at end of file +} diff --git a/app/Http/Controllers/Banks/UpdateBankMetadataController.php b/app/Http/Controllers/Banks/UpdateBankMetadataController.php new file mode 100644 index 00000000..3b89c1ff --- /dev/null +++ b/app/Http/Controllers/Banks/UpdateBankMetadataController.php @@ -0,0 +1,19 @@ +execute($request); + } +} diff --git a/app/Http/Resources/CompanyResource.php b/app/Http/Resources/CompanyResource.php index a8103e8b..82b4cf3e 100644 --- a/app/Http/Resources/CompanyResource.php +++ b/app/Http/Resources/CompanyResource.php @@ -56,7 +56,7 @@ class CompanyResource extends JsonResource 'last_payment' => $lastPayment ? $lastPayment->created_at->diffForHumans() : 'No Payments', 'personal_banks' => BankResource::collection($this->banks->where('type', BankAccountType::PERSONAL)), 'recipient_banks' => [ - 'accounts' => BankResource::collection($this->banks->whereIn('type', [BankAccountType::EXTERNAL, BankAccountType::ALIPAY_1688, BankAccountType::ALIPAY_RECIPIENT])), + 'accounts' => BankResource::collection($this->banks->whereIn('type', [BankAccountType::EXTERNAL, BankAccountType::ALIPAY_1688, BankAccountType::ALIPAY_RECIPIENT])->whereIn('creator_type', [null])), 'default' => new BankResource($this->banks->where('type', BankAccountType::EXTERNAL)->where('default', true)->first()) ], 'segments' => SegmentResource::collection($this->segments), diff --git a/app/Http/Resources/ListTransactionJobResource.php b/app/Http/Resources/ListTransactionJobResource.php index 6c4c0ece..b8908ee6 100644 --- a/app/Http/Resources/ListTransactionJobResource.php +++ b/app/Http/Resources/ListTransactionJobResource.php @@ -16,8 +16,16 @@ class ListTransactionJobResource extends JsonResource */ public function toArray($request) { - - $booking = in_array((int)$this->type, [TransactionType::BILL, TransactionType::REFUND])? $this->owner->owner : $this->owner; + $booking = null; //cief todo: 66 + $bank = null; + if(in_array((int)$this->type, [TransactionType::BILL, TransactionType::REFUND])){ + $booking = $this->owner->owner; + $bank = $this->owner->bank ?? $booking->bank; + } + else{ + $booking = $this->owner; + $bank = $this->bank ?? $booking->bank; + } $days = $this->created_at->endOfDay()->addWeekdays($booking->service_id === 3 ? 3 : 1); return [ @@ -27,7 +35,7 @@ class ListTransactionJobResource extends JsonResource 'bill_no' => $this->bill_no, 'payment_reference' => $this->payment_reference, 'payment_method' => (float) $this->payment_method, - 'recipient_bank_account' => new BankResource($booking->bank), + 'recipient_bank_account' => new BankResource($bank), 'issuer_name' => $this->issuerCompany->name, 'issuer_id' => $this->issuerCompany->id, 'amount' => (double) $this->amount, diff --git a/app/Http/Resources/PaymentTransactionResource.php b/app/Http/Resources/PaymentTransactionResource.php index 456ece3d..d0549c38 100644 --- a/app/Http/Resources/PaymentTransactionResource.php +++ b/app/Http/Resources/PaymentTransactionResource.php @@ -18,8 +18,16 @@ class PaymentTransactionResource extends JsonResource */ public function toArray($request) { - - $booking = in_array((int)$this->type, [TransactionType::BILL, TransactionType::REFUND])? $this->owner->owner : $this->owner; + $booking = null; //cief todo: 66 + $bank = null; + if(in_array((int)$this->type, [TransactionType::BILL, TransactionType::REFUND])){ + $booking = $this->owner->owner; + $bank = $this->owner->bank ?? $booking->bank; + } + else{ + $booking = $this->owner; + $bank = $this->bank ?? $booking->bank; + } $booking_marking = ''; switch ($this->owner_type) { @@ -38,7 +46,7 @@ class PaymentTransactionResource extends JsonResource 'bill_no' => $this->bill_no, 'payment_reference' => $this->payment_reference, 'payment_method' => (float) $this->payment_method, - 'recipient_bank_account' => new BankResource($booking->bank), + 'recipient_bank_account' => new BankResource($bank), 'issuer_name' => $this->issuerCompany->name, 'issuer_id' => $this->issuerCompany->id, 'amount' => (double) $this->amount, diff --git a/app/Http/Resources/TransactionResource.php b/app/Http/Resources/TransactionResource.php index d259d777..f8620f05 100644 --- a/app/Http/Resources/TransactionResource.php +++ b/app/Http/Resources/TransactionResource.php @@ -19,8 +19,16 @@ class TransactionResource extends JsonResource */ public function toArray($request) { - - $booking = in_array((int)$this->type, [TransactionType::BILL, TransactionType::REFUND, TransactionType::SUPPLIER_REFUND])? $this->owner->owner : $this->owner; + $booking = null; //cief todo: 66 + $bank = null; + if(in_array((int)$this->type, [TransactionType::BILL, TransactionType::REFUND, TransactionType::SUPPLIER_REFUND])){ + $booking = $this->owner->owner; + $bank = $this->owner->bank; + } + else{ + $booking = $this->owner; + $bank = $this->bank; + } $days = $this->created_at->endOfDay()->addWeekdays($booking->service_id === 3 ? 3 : 1); return [ @@ -30,7 +38,7 @@ class TransactionResource extends JsonResource 'bill_no' => $this->bill_no, 'payment_reference' => $this->payment_reference, 'payment_method' => (float) $this->payment_method, - 'recipient_bank_account' => new BankResource($booking->bank), + 'recipient_bank_account' => new BankResource($bank), 'issuer_name' => $this->issuerCompany->name, 'issuer_id' => $this->issuerCompany->id, 'amount' => (double) ($this->type === TransactionType::SUPPLIER_REFUND ? $this->amount - $this->transactions()->where('type', TransactionType::BILL_REFUND)->where('status', ApprovalStatus::APPROVED)->sum('amount') : $this->amount), @@ -54,7 +62,8 @@ class TransactionResource extends JsonResource 'duration' => $days->diff(Carbon::now())->format('%d'), ], 'remarks' => RemarkResource::collection($this->remarks), - 'redemption' => new VoucherRedemptionResource($this->voucherRedemption) + 'redemption' => new VoucherRedemptionResource($this->voucherRedemption), + 'bank' => ((int) $this->type === TransactionType::PAYMENT) ? new BankResource($bank) : null, //When a transaction (of type payment) has an override recipient bank details on booking, this is NOT null ]; } } diff --git a/app/Http/Resources/V2/CompanyV2Resource.php b/app/Http/Resources/V2/CompanyV2Resource.php index 64fca7c7..3f2cb4c2 100644 --- a/app/Http/Resources/V2/CompanyV2Resource.php +++ b/app/Http/Resources/V2/CompanyV2Resource.php @@ -82,7 +82,7 @@ class CompanyV2Resource extends JsonResource 'last_payment' => $lastPayment ? $lastPayment->created_at->diffForHumans() : 'No Payments', 'personal_banks' => V1\BankResource::collection($this->banks->where('type', BankAccountType::PERSONAL)), 'recipient_banks' => [ - 'accounts' => V1\BankResource::collection($this->banks->where('type', BankAccountType::EXTERNAL)), + 'accounts' => V1\BankResource::collection($this->banks->where('type', BankAccountType::EXTERNAL)->whereIn('creator_type', [null])), 'default' => new V1\BankResource($this->banks->where('type', BankAccountType::EXTERNAL)->where('default', true)->first()) ], 'segments' => V1\SegmentResource::collection($this->segments), diff --git a/app/Models/Bank.php b/app/Models/Bank.php index 3b0bb915..30a429ae 100644 --- a/app/Models/Bank.php +++ b/app/Models/Bank.php @@ -7,6 +7,8 @@ use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\MorphMany; +use App\Classes\General\Interfaces\KeyValueInterface; /** * Class Bank @@ -21,10 +23,29 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; * @property int default * @property int status */ -class Bank extends AbstractModel +class Bank extends AbstractModel implements KeyValueInterface { use SoftDeletes; - + + /** + * + * @var array + */ + protected $fillable = [ + 'company_id', + 'reference', + 'bank_name', + 'holder_name', + 'account_no', + 'bank_branch', + 'swift', + 'snap', + 'type', + 'country_id', + 'created_by', + 'creator_type', + ]; + protected $table = 'banks'; /** @@ -42,7 +63,7 @@ class Bank extends AbstractModel { return $this->BelongsTo(Company::class, 'company_id', 'id'); } - + /** * @return HasMany */ @@ -50,4 +71,12 @@ class Bank extends AbstractModel { return $this->HasMany(Transaction::class, 'recipient_bank_account_id'); } + + /** + * @return MorphMany + */ + public function attributes(): MorphMany + { + return $this->morphMany(KeyValuePair::class, 'owner'); + } } diff --git a/app/Models/KeyValuePair.php b/app/Models/KeyValuePair.php index 3ad6d6cd..8f8ddec8 100644 --- a/app/Models/KeyValuePair.php +++ b/app/Models/KeyValuePair.php @@ -2,10 +2,14 @@ namespace App\Models; use Illuminate\Database\Eloquent\Relations\MorphTo; - +use Illuminate\Database\Eloquent\SoftDeletes; class KeyValuePair extends AbstractModel { + use SoftDeletes; + + protected $dates = ['deleted_at']; + protected $table = 'key_value_pairs'; public function owner(): MorphTo diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index 31b67e69..dc18faa1 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -3,6 +3,7 @@ namespace App\Models; use App\Classes\General\Interfaces\Documentable; +use App\Classes\General\Interfaces\KeyValueInterface; use App\Classes\General\Interfaces\Remarkable; use App\Classes\General\Interfaces\Transactionable; use App\Classes\General\Interfaces\Voucherifiable; @@ -22,7 +23,7 @@ use Staudenmeir\EloquentHasManyDeep\HasTableAlias; use App\Models\StatementTransactionOwner; -class Transaction extends AbstractModel implements Documentable, Transactionable, Voucherifiable, Remarkable +class Transaction extends AbstractModel implements Documentable, Transactionable, Voucherifiable, Remarkable, KeyValueInterface { use HasTableAlias; use SoftDeletes; @@ -268,4 +269,25 @@ class Transaction extends AbstractModel implements Documentable, Transactionable return $this->morphMany(Remark::class, 'owner'); } + /** + * @return MorphMany + */ + public function attributes(): MorphMany + { + return $this->morphMany(KeyValuePair::class, 'owner'); + } + + /** + * + * @return Model|null + */ + public function getBankAttribute() + { + $keyValuePairs = $this->attributes()->where('key', 'App\Models\Bank')->latest()->first(); + if($keyValuePairs){ + $bank = Bank::where('id', $keyValuePairs->value)->first(); + return $bank; + } + return null; + } } diff --git a/database/migrations/2024_07_25_205651_add_created_by_and_creator_type_to_banks_table.php b/database/migrations/2024_07_25_205651_add_created_by_and_creator_type_to_banks_table.php new file mode 100644 index 00000000..1d99906f --- /dev/null +++ b/database/migrations/2024_07_25_205651_add_created_by_and_creator_type_to_banks_table.php @@ -0,0 +1,35 @@ +unsignedBigInteger('created_by')->nullable()->after('country_id'); + $table->unsignedInteger('creator_type')->nullable()->after('created_by'); // 'admin' or 'customer', see RoleTypes.php for more + $table->foreign('created_by')->references('id')->on('users')->onDelete('set null'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('banks', function (Blueprint $table) { + $table->dropForeign(['created_by']); + $table->dropColumn(['created_by', 'creator_type']); + }); + } +} diff --git a/database/migrations/2024_07_31_212359_add_deleted_at_to_key_value_pairs.php b/database/migrations/2024_07_31_212359_add_deleted_at_to_key_value_pairs.php new file mode 100644 index 00000000..df64b4a8 --- /dev/null +++ b/database/migrations/2024_07_31_212359_add_deleted_at_to_key_value_pairs.php @@ -0,0 +1,32 @@ +softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('key_value_pairs', function (Blueprint $table) { + $table->dropSoftDeletes(); + }); + } +} diff --git a/database/seeds/AdminUserPermissionsTableSeeder.php b/database/seeds/AdminUserPermissionsTableSeeder.php index 0c3d5acf..c111ab6a 100644 --- a/database/seeds/AdminUserPermissionsTableSeeder.php +++ b/database/seeds/AdminUserPermissionsTableSeeder.php @@ -71,6 +71,7 @@ class AdminUserPermissionsTableSeeder extends Seeder ['name' => 'delete milestone', 'guard_name' => 'web'], ['name' => 'delete reward', 'guard_name' => 'web'], + ['name' => 'update bank_metadata', 'guard_name' => 'web'], ]; foreach ($permissions as $permission){ diff --git a/resources/assets/vue/components/banks/forms/BankAccountFormComponent.vue b/resources/assets/vue/components/banks/forms/BankAccountFormComponent.vue index 80a3c94d..3bf4f46a 100644 --- a/resources/assets/vue/components/banks/forms/BankAccountFormComponent.vue +++ b/resources/assets/vue/components/banks/forms/BankAccountFormComponent.vue @@ -133,7 +133,7 @@
-
+
{{disabled ? 'Change Recipient Account' : 'Cancel'}}
@@ -186,6 +186,18 @@ isEditing: { type: Boolean, default: false + }, + isCancelButtonHidden: { + type: Boolean, + default: false + }, + billNo: { + type: String, + default: '' + }, + transactionId: { + type: Number, + default: 0 } }, data(){ @@ -201,6 +213,8 @@ swift: '', snap: '', country_id: this.country_id, + bill_no: this.billNo, + transaction_id: this.transactionId, } } }, @@ -234,6 +248,8 @@ if(this.isEditing){ this.parameters.company_id = this.company_id; this.parameters.account_type = this.type; + this.parameters.bill_no = this.billNo; + this.parameters.transaction_id = this.transactionId; this.submit(route('api.bank.update', this.parameters.id), 'put', this.section, true, false); } else{ @@ -242,7 +258,7 @@ }, successHandler(response){ if(this.isEditing){ - this.type !== 2 ? this.closeModal() : this.$emit('updatedBankDetails', response.payload.data); + this.type !== 2 ? this.closeModal() : this.$emit('updatedBankDetails', response.payload.data, this.transactionId); } else{ this.type !== 2 ? this.closeModal() : this.$emit('createdBank', response.payload.data); diff --git a/resources/assets/vue/components/banks/forms/PhoneAccountFormComponent.vue b/resources/assets/vue/components/banks/forms/PhoneAccountFormComponent.vue index cf589b25..dde77e9c 100644 --- a/resources/assets/vue/components/banks/forms/PhoneAccountFormComponent.vue +++ b/resources/assets/vue/components/banks/forms/PhoneAccountFormComponent.vue @@ -39,7 +39,7 @@
-
+
{{disabled ? 'Change Recipient Account' : 'Cancel'}}
@@ -87,6 +87,18 @@ isEditing: { type: Boolean, default: false + }, + isCancelButtonHidden: { + type: Boolean, + default: false + }, + billNo: { + type: String, + default: '' + }, + transactionId: { + type: Number, + default: 0 } }, data(){ @@ -100,6 +112,8 @@ account_no: '', bank_branch: '', country_id: this.country_id, + bill_no: this.billNo, + transaction_id: this.transactionId, }, englishTextWarning: false, confirmProceedEnglishText: false, @@ -125,6 +139,8 @@ if(this.isEditing){ this.parameters.company_id = this.company_id; this.parameters.account_type = this.type; + this.parameters.bill_no = this.billNo; + this.parameters.transaction_id = this.transactionId; this.submit(route('api.bank.update', this.parameters.id), 'put', this.section, true, false); } else{ @@ -133,7 +149,7 @@ }, successHandler(response){ if(this.isEditing){ - this.type !== 2 ? this.closeModal() : this.$emit('updatedBankDetails', response.payload.data); + this.type !== 2 ? this.closeModal() : this.$emit('updatedBankDetails', response.payload.data, this.transactionId); } else{ this.type !== 2 ? this.closeModal() : this.$emit('createdBank', response.payload.data); diff --git a/resources/assets/vue/components/bookings/elements/BookingPaymentRecipientEditComponent.vue b/resources/assets/vue/components/bookings/elements/BookingPaymentRecipientEditComponent.vue new file mode 100644 index 00000000..12b673af --- /dev/null +++ b/resources/assets/vue/components/bookings/elements/BookingPaymentRecipientEditComponent.vue @@ -0,0 +1,177 @@ + + + + + diff --git a/resources/assets/vue/components/bookings/elements/BookingRecipientEditComponent.vue b/resources/assets/vue/components/bookings/elements/BookingRecipientEditComponent.vue index 6240b629..8690d262 100644 --- a/resources/assets/vue/components/bookings/elements/BookingRecipientEditComponent.vue +++ b/resources/assets/vue/components/bookings/elements/BookingRecipientEditComponent.vue @@ -3,9 +3,12 @@
-
-
-
Recipient Details
+
+
+
Edit Recipient Bank Details ({{ data.billNo }})
+
+
+
Edit Recipient Bank Details (Default)
@@ -64,8 +67,31 @@
- - + + + +
@@ -84,9 +110,9 @@ diff --git a/resources/assets/vue/components/bookings/forms/RecipientBankDetailsComponent.vue b/resources/assets/vue/components/bookings/forms/RecipientBankDetailsComponent.vue new file mode 100644 index 00000000..a58a6fd5 --- /dev/null +++ b/resources/assets/vue/components/bookings/forms/RecipientBankDetailsComponent.vue @@ -0,0 +1,83 @@ + + diff --git a/resources/assets/vue/components/bookings/forms/UpdateBookingComponent.vue b/resources/assets/vue/components/bookings/forms/UpdateBookingComponent.vue index 16cae41c..1634e9d9 100644 --- a/resources/assets/vue/components/bookings/forms/UpdateBookingComponent.vue +++ b/resources/assets/vue/components/bookings/forms/UpdateBookingComponent.vue @@ -4,7 +4,7 @@
- +
diff --git a/resources/assets/vue/components/general/forms/GeneralConfirmationFormComponent.vue b/resources/assets/vue/components/general/forms/GeneralConfirmationFormComponent.vue index 0cb9435b..85526d4e 100644 --- a/resources/assets/vue/components/general/forms/GeneralConfirmationFormComponent.vue +++ b/resources/assets/vue/components/general/forms/GeneralConfirmationFormComponent.vue @@ -33,7 +33,7 @@ required: true }, params: { - type: Array, + type: Object, required: false }, modalType: { diff --git a/resources/views/pages/pdfs/currency_vendor_order.blade.php b/resources/views/pages/pdfs/currency_vendor_order.blade.php index df445998..7638f5c5 100644 --- a/resources/views/pages/pdfs/currency_vendor_order.blade.php +++ b/resources/views/pages/pdfs/currency_vendor_order.blade.php @@ -46,12 +46,18 @@ {{$transaction->currency_rate}} {{$transaction->currency->short_code}} {{number_format((float)$transaction->amount, 2, '.', '')}} - Account Holder Name: {{$transaction->owner->owner->bank->holder_name}} -
{{$transaction->owner->owner->bank->bank_name}}: {{$transaction->owner->owner->bank->account_no}} -
Branch: {{$transaction->owner->owner->bank->bank_branch}} + @php + $bank = $transaction->owner->owner->bank; + if($transaction->owner->bank){ + $bank = $transaction->owner->bank; + } + @endphp + Account Holder Name: {{$bank->holder_name}} +
{{$bank->bank_name}}: {{$bank->account_no}} +
Branch: {{$bank->bank_branch}} @if($transaction->original_currency->short_code === 'USD') -
Account Holder Address: {{$transaction->owner->owner->bank->reference}} -
Swift Code: {{$transaction->owner->owner->bank->swift}} +
Account Holder Address: {{$bank->reference}} +
Swift Code: {{$bank->swift}} @endif
Bank in Amount: {{$transaction->original_currency->short_code}} {{$transaction->original_amount}} @if ($order_reference_no) diff --git a/resources/views/pages/pdfs/currency_vendor_order_inner.blade.php b/resources/views/pages/pdfs/currency_vendor_order_inner.blade.php index e477c538..2d0c486f 100644 --- a/resources/views/pages/pdfs/currency_vendor_order_inner.blade.php +++ b/resources/views/pages/pdfs/currency_vendor_order_inner.blade.php @@ -19,12 +19,18 @@ @foreach($transactions as $transaction) + @php + $bank = $transaction->owner->owner->bank; + if($transaction->owner->bank){ + $bank = $transaction->owner->bank; + } + @endphp {{$transaction->owner->owner->marking}} {{$transaction->owner->owner->company->reference}} {{$transaction->currency_rate}} {{$transaction->currency->short_code}} {{number_format((float)$transaction->amount, 2, '.', '')}} - Account Holder Name: {{$transaction->owner->owner->bank->holder_name}}
{{$transaction->owner->owner->bank->bank_name}}: {{$transaction->owner->owner->bank->account_no}} -
Branch: {{$transaction->owner->owner->bank->bank_branch}}@if($transaction->original_currency->short_code === 'USD')
Swift Code: {{$transaction->owner->owner->bank->swift}}@endif
Bank in Amount: {{$transaction->original_currency->short_code}} {{$transaction->original_amount}} + Account Holder Name: {{$bank->holder_name}}
{{$bank->bank_name}}: {{$bank->account_no}} +
Branch: {{$bank->bank_branch}}@if($transaction->original_currency->short_code === 'USD')
Swift Code: {{$bank->swift}}@endif
Bank in Amount: {{$transaction->original_currency->short_code}} {{$transaction->original_amount}} @endforeach diff --git a/routes/api.php b/routes/api.php index 2d52b3ea..23adace3 100644 --- a/routes/api.php +++ b/routes/api.php @@ -60,7 +60,7 @@ Route::group(['middleware' => 'api', 'prefix' => 'v1', 'as' => 'api.'], function require __DIR__ . '/wallet.php'; require __DIR__ . '/voucher.php'; - + require __DIR__ . '/accounting.php'; require __DIR__ . '/reward.php'; @@ -69,8 +69,6 @@ Route::group(['middleware' => 'api', 'prefix' => 'v1', 'as' => 'api.'], function require __DIR__.'/remark.php'; - // require __DIR__ . '/accounting.php'; //cief todo: To check if this is needed - require __DIR__ . '/job.php'; // require __DIR__ . '/rate.php'; diff --git a/routes/bank.php b/routes/bank.php index 03c719e6..b7c7e96e 100644 --- a/routes/bank.php +++ b/routes/bank.php @@ -10,4 +10,6 @@ Route::group(['prefix' => 'bank', 'as' => 'bank.', 'namespace' => 'Banks'], func Route::delete('/delete/{id}', 'DeleteBankController@delete')->name('delete'); Route::put('/update/{id}/status', 'UpdateBankStatusController@update')->name('status.update'); -}); \ No newline at end of file + + Route::post('/metadata/update/{id}', 'UpdateBankMetadataController@delete')->name('update.metadata'); +}); diff --git a/routes/web.php b/routes/web.php index a7c87263..23c4239e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -406,16 +406,18 @@ Route::get('/pending_orders', function(){ $i = 0; foreach ($payments as $payment){ $booking = $payment->owner; + $bank = $payment->bank ?? $booking->bank; //cief todo: 66 + $original_refunds = floatval((App()->make(CalculatesBookingRefundAmount::class))->calculateRefundAmount($payment, $booking->fix_currency_id)); $refunds = $original_refunds / $payment->currency_rate; if(!$booking instanceof Booking){ dd($payment); } - $bankType = str::length($booking->bank->holder_name) > 4 ? 'Company' : 'Personal'; + $bankType = str::length($bank->holder_name) > 4 ? 'Company' : 'Personal'; - if (!preg_match('/[^A-Za-z0-9]/', $booking->bank->holder_name)) + if (!preg_match('/[^A-Za-z0-9]/', $bank->holder_name)) { - $bankType = str_word_count($booking->bank->holder_name) > 4 ? 'Company' : 'Personal'; + $bankType = str_word_count($bank->holder_name) > 4 ? 'Company' : 'Personal'; } echo ''; @@ -432,7 +434,7 @@ Route::get('/pending_orders', function(){ echo ''.$booking->service->name.''; echo ''.$payment->updated_at->diffForHumans().''; echo ''.$bankType.''; - echo ''.$booking->bank->holder_name.''; + echo ''.$bank->holder_name.''; echo ''; } echo ''; @@ -509,14 +511,16 @@ Route::get('/approve_refunds', function(Request $request){ foreach ($approve_refunds->orderBy('created_at', 'DESC')->get() as $index => $refund){ $payment = $refund->owner; $booking = $refund->owner->owner; + $bank = $payment->bank ?? $booking->bank; //cief todo: 66 + if(!$booking instanceof Booking){ dd($refund); } - $bankType = str::length($booking->bank->holder_name) > 4 ? 'Company' : 'Personal'; + $bankType = str::length($bank->holder_name) > 4 ? 'Company' : 'Personal'; - if (!preg_match('/[^A-Za-z0-9]/', $booking->bank->holder_name)) + if (!preg_match('/[^A-Za-z0-9]/', $bank->holder_name)) { - $bankType = str_word_count($booking->bank->holder_name) > 4 ? 'Company' : 'Personal'; + $bankType = str_word_count($bank->holder_name) > 4 ? 'Company' : 'Personal'; } $remark = $refund->original_amount === $refund->owner->original_amount ? 'Fully Refund' : 'Partial Refund'; @@ -545,7 +549,7 @@ Route::get('/approve_refunds', function(Request $request){ echo ''.$booking->service->name.''; echo ''.$payment->updated_at->diffForHumans().''; echo ''.$bankType.''; - echo ''.$booking->bank->holder_name.''; + echo ''.$bank->holder_name.''; echo ''.$noteRemark.''; echo ''; } @@ -563,10 +567,12 @@ Route::get('/group/text/{id}', function($id){ foreach ($group->transactions as $transaction){ $i++; $booking = $transaction->owner->owner; + $bank = $transaction->owner->bank ?? $booking->bank; //cief todo: 66 + echo 'No.'.$i.'
'; - echo 'Bank Details:'.$booking->bank->holder_name.'
'; - echo $booking->bank->bank_name.' '.$booking->bank->bank_branch.'
'; - echo 'Bank Account Number:'.$booking->bank->account_no.'
'; + echo 'Bank Details:'.$bank->holder_name.'
'; + echo $bank->bank_name.' '.$bank->bank_branch.'
'; + echo 'Bank Account Number:'.$bank->account_no.'
'; echo 'Order Amount:'.$transaction->original_currency->short_code.' '.(round($transaction->original_amount, 2) + 0).'

'; } @@ -576,7 +582,7 @@ Route::get('/group/invoice/{id}', function ($id) { $group = Group::findOrFail($id); - $supplier = $group->issuerCompany; + $supplier = $group->issuerCompany; $transferFeeTransactions = $group->transactions() ->with(['transactions' => function ($transaction) { @@ -588,8 +594,8 @@ Route::get('/group/invoice/{id}', function ($id) { $html = view('pages.pdfs.supplier_deliver_order_group_invoice', [ 'group'=> $group, - 'transactions' => $group->transactions, - 'transferFeeTransactions' => $transferFeeTransactions, + 'transactions' => $group->transactions, + 'transferFeeTransactions' => $transferFeeTransactions, 'supplier' => $supplier ])->render(); @@ -597,7 +603,7 @@ Route::get('/group/invoice/{id}', function ($id) { $dompdf->loadHtml($html); $dompdf->setPaper('A4', 'portrait'); $dompdf->render(); - + return $dompdf->stream("invoice_pdf_{$supplier->name}.pdf"); })->name('group.invoice'); @@ -1167,7 +1173,7 @@ Route::get('check-duplicate-refunds', function () { foreach ($results as $result) { $booking_ref_arr = explode(' ', $result->payment_reference); $booking_ref = end($booking_ref_arr); - + echo ''; echo "$result->owner_type"; echo "$result->owner_id"; @@ -1204,7 +1210,7 @@ Route::get('check-duplicate-refunds', function () { echo "" . ($refund ? $refund : '') . ""; echo ''; - + } echo ''; echo '';