diff --git a/app/Classes/ValueObjects/Constants/BankAccountType.php b/app/Classes/ValueObjects/Constants/BankAccountType.php index f6ef447b..0393091f 100644 --- a/app/Classes/ValueObjects/Constants/BankAccountType.php +++ b/app/Classes/ValueObjects/Constants/BankAccountType.php @@ -8,7 +8,7 @@ final class BankAccountType { public const EXTERNAL = 2; - public const ALIPAY= 3; + public const ALIPAY_1688 = 3; public const ALIPAY_RECIPIENT = 4; diff --git a/app/Console/Commands/DeleteDuplicate1688BankAccount.php b/app/Console/Commands/DeleteDuplicate1688BankAccount.php new file mode 100644 index 00000000..57b65733 --- /dev/null +++ b/app/Console/Commands/DeleteDuplicate1688BankAccount.php @@ -0,0 +1,75 @@ +get(); + + $groupedBanks = $records->groupBy(function($item, $key) { + return $item['company_id'] . '-' . $item['account_no']; + }); + + foreach ($groupedBanks as $key => $banksWithSameUserAndAccountNo) { + // Sort banks by created_at or updated_at to find the latest one + $sortedBanks = $banksWithSameUserAndAccountNo->sortByDesc('created_at'); + + // Retain the latest bank + $latestBank = $sortedBanks->first(); + + // Get all IDs except the latest one + $idsToDelete = $sortedBanks->pluck('id')->slice(1); + + foreach ($idsToDelete as $id) { + Booking::where('bank_id', $id)->update([ + 'bank_id' => $latestBank->id + ]); + } + + $this->info('for company id: ' . $latestBank->company_id . ', account no: ' . $latestBank->account_no . ', duplicated id: ' . $idsToDelete); + // Delete the rest + Bank::whereIn('id', $idsToDelete)->delete(); + } + } +} diff --git a/app/Http/Resources/CompanyResource.php b/app/Http/Resources/CompanyResource.php index bbafbefc..a8103e8b 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_RECIPIENT])), + 'accounts' => BankResource::collection($this->banks->whereIn('type', [BankAccountType::EXTERNAL, BankAccountType::ALIPAY_1688, BankAccountType::ALIPAY_RECIPIENT])), 'default' => new BankResource($this->banks->where('type', BankAccountType::EXTERNAL)->where('default', true)->first()) ], 'segments' => SegmentResource::collection($this->segments), diff --git a/resources/assets/vue/components/bookings/elements/BookingConfirmationComponent.vue b/resources/assets/vue/components/bookings/elements/BookingConfirmationComponent.vue index 29e664f0..3e19e8e3 100644 --- a/resources/assets/vue/components/bookings/elements/BookingConfirmationComponent.vue +++ b/resources/assets/vue/components/bookings/elements/BookingConfirmationComponent.vue @@ -100,7 +100,7 @@ -