Laravel Vapor - Sync V2 Commands with updates from latest changes in V1 Commands (also done on shipping portal)

This commit is contained in:
Dillon Ngo
2024-09-04 12:44:14 +08:00
parent fabc7522ae
commit e5038cb8b8
14 changed files with 816 additions and 65 deletions
@@ -0,0 +1,61 @@
<?php
namespace App\Classes\Jobs\Commands\V2;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use App\Models\Bank;
use App\Models\Booking;
class DeleteDuplicate1688BankAccountV2CommandJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function handle()
{
Log::info(Carbon::now() . ': Start job - Delete duplicate 1688 account in banks table.');
$start = new Carbon();
// account_no: 1688 LOGIN ID/EMAIL/PHONE
// holder_name: password
// bank_branch: 6-digit pin
$records = Bank::where('type', 3)->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
]);
}
Log::info('for company id: ' . $latestBank->company_id . ', account no: ' . $latestBank->account_no . ', duplicated id: ' . $idsToDelete);
// Delete the rest
Bank::whereIn('id', $idsToDelete)->delete();
}
$end = new Carbon();
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
Log::info(Carbon::now() . ': End job - Delete duplicate 1688 account in banks table. ElapsedTime: ' . $elapsedTime . '.');
}
}
@@ -25,41 +25,42 @@ class ExpiredBookingV2CommandJob implements ShouldQueue
Log::info(Carbon::now() . ': Start job - Expiring booking that do not have further action by user.');
$start = new Carbon();
// 1. Cancel booking without payment & purchase order (1 month)
$bookings = Booking::where('status', ApprovalStatus::APPROVED)
->where('created_at', '<', now()->subDays(30)->endOfDay())
->where(function ($query) {
$query->whereDoesntHave('transactions')
->orWhereDoesntHave('transactions', function($transaction) {
return $transaction->where('type', TransactionType::PURCHASE_ORDER)->orWhere(function ($q) {
$q->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
});
});
})->get();
// 1. Cancel booking without payment & purchase order (1 month)
$bookings = Booking::where('status', ApprovalStatus::APPROVED)
->where('created_at', '<', now()->subDays(30)->endOfDay())
->where('service_id', '!=', 4)
->where(function ($query) {
$query->whereDoesntHave('transactions')
->orWhereDoesntHave('transactions', function($transaction) {
return $transaction->where('type', TransactionType::PURCHASE_ORDER)->orWhere(function ($q) {
$q->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED, ApprovalStatus::REFUNDED]);
});
});
})->get();
foreach ($bookings as $booking) {
(App()->make(UpdatesBookingStatus::class))->execute($booking, ApprovalStatus::EXPIRED);
Log::info(Carbon::now() . " : Expired Booking without payment & purchase order, booking id: " . $booking->id);
$transactions = $booking->transactions;
Log::info(Carbon::now() . " : Expired Booking without payment & purchase order, booking id: " . $booking->id);
$transactions = $booking->transactions;
foreach ($transactions as $transaction) {
$prevStatus = $transaction->status;
$transaction->status = ApprovalStatus::EXPIRED;
$transaction->save();
Log::info(Carbon::now() . " : Expired Transaction id: {$transaction->id} from Booking id: {$booking->id}. Status before update: {$prevStatus}");
}
foreach ($transactions as $transaction) {
$prevStatus = $transaction->status;
$transaction->status = ApprovalStatus::EXPIRED;
$transaction->save();
Log::info(Carbon::now() . " : Expired Transaction id: {$transaction->id} from Booking id: {$booking->id}. Status before update: {$prevStatus}");
}
}
// 2. Cancel booking without payment but with purchase order (2 month)
$bookings = Booking::where('status', ApprovalStatus::APPROVED)
->where('created_at', '<', now()->subDays(60)->endOfDay())
->where(function ($query) {
$query->whereDoesntHave('transactions', function($transaction) {
return $transaction->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
})->whereHas('transactions', function($transaction) {
return $transaction->where('type', TransactionType::PURCHASE_ORDER);
});
})->get();
->where('created_at', '<', now()->subDays(60)->endOfDay())
->where(function ($query) {
$query->whereDoesntHave('transactions', function($transaction) {
return $transaction->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED, ApprovalStatus::REFUNDED]);
})->whereHas('transactions', function($transaction) {
return $transaction->where('type', TransactionType::PURCHASE_ORDER);
});
})->get();
foreach ($bookings as $booking) {
(App()->make(UpdatesBookingStatus::class))->execute($booking, ApprovalStatus::EXPIRED);
@@ -76,49 +76,84 @@ class ExpiredRefundedBookingV2CommandJob implements ShouldQueue
if (!$bookingPayment) {
$bookingPayment = $booking->transactions()->payments()->whereIn('status', [ApprovalStatus::SUSPENDED, ApprovalStatus::EXPIRED, ApprovalStatus::REJECTED])->orderBy('id', 'DESC')->first();
}
}
if ($bookingPayment) {
$status = ApprovalStatus::APPROVAL_STATUS_ID[$bookingPayment->status];
Log::info("Credit note transaction id: {$transaction->id}, the payment for the booking is in status {$status}");
}
$bookingPaymentAmount = $bookingPayment->amount;
// check if the booking is fully refund
$amountDifference = bcsub($transaction->amount, $bookingPaymentAmount, 7);
if (abs($amountDifference) < 0.01) {
// rejecting booking payment transaction
// $bookingPayment->status = ApprovalStatus::REJECTED;
// $bookingPayment->save();
$bookingPaymentAmount = $bookingPayment->amount;
// check if the booking is fully refund
$amountDifference = bcsub($transaction->amount, $bookingPaymentAmount, 7);
//expired booking
// $this->updatesBookingStatus->execute($booking, ApprovalStatus::EXPIRED);
Log::info("Credit note transaction id: {$transaction->id} is fully refunded, the refunded amount was {$transaction->amount} the payment reference is: {$transaction->payment_reference}");
// Log::info("Credit note transaction id: {$transaction->id}, Rejected Booking Transaction Payment id: {$bookingPayment->id}, the payment amount was {$bookingPayment->amount}");
// Log::info("Credit note transaction id: {$transaction->id}, Expired Booking id: {$booking->id}");
$isFullyRefund = false;
if (abs($amountDifference) < 0.01) {
$isFullyRefund = true;
// update fully refunded booking payment transaction
$bookingPayment->status = ApprovalStatus::REFUNDED;
$bookingPayment->save();
//expired booking
// $this->updatesBookingStatus->execute($booking, ApprovalStatus::EXPIRED);
Log::info("Credit note transaction id: {$transaction->id} is fully refunded, the refunded amount was {$transaction->amount} the payment reference is: {$transaction->payment_reference}");
// Log::info("Credit note transaction id: {$transaction->id}, Rejected Booking Transaction Payment id: {$bookingPayment->id}, the payment amount was {$bookingPayment->amount}");
// Log::info("Credit note transaction id: {$transaction->id}, Expired Booking id: {$booking->id}");
} else {
Log::info("Credit note transaction id: {$transaction->id} is not fully refunded, the refunded amount was {$transaction->amount}, the payment amount was {$bookingPayment->amount}, the payment reference is: {$transaction->payment_reference}");
}
$refund = $bookingPayment->transactions()->refunds()->where('amount', $transaction->amount)->where('status', ApprovalStatus::APPROVED)->first();
$bookingInWhiteForm = $bookingPayment->transactions()->bills()->first();
if ($refund) {
Log::info("Credit note transaction id: {$transaction->id}, already created same amount of refund transaction for same booking payment transaction");
}
if (!$refund) {
$billNumber = (App()->make(GeneratesTransactionBillNumber::class))->execute('RFD-');
$object = new TransactionObject($billNumber, TransactionType::REFUND, 1, $booking->company->id,
1, PaymentMethodType::CASH,
$transaction->amount, $isFullyRefund ? $bookingPayment->original_amount : $transaction->amount * $bookingPayment->currency_rate, 1,
$bookingPayment->original_currency_id, $bookingPayment->currency_rate,
0, 0, null, ApprovalStatus::APPROVED, [], $bookingPayment->bill_no);
$transaction = (App()->make(CreatesTransaction::class))->execute($bookingPayment, $object);
}
if ($bookingInWhiteForm) {
$original_amount = $isFullyRefund ? $bookingPayment->original_amount : bcmul($transaction->amount, $bookingPayment->currency_rate, 7);
$supplier_refund_amount = bcdiv($original_amount, $bookingInWhiteForm->currency_rate, 7);
Log::info("Credit note transaction id: {$transaction->id}, booking is in white form, white form currency rate is {$bookingInWhiteForm->currency_rate}");
// if ($isFullyRefund && $bookingInWhiteForm->currency_rate == 1) {
// dd ($bookingInWhiteForm->owner_id);
// }
$refund = $bookingPayment->transactions()->supplierRefunds()->where('original_amount', $original_amount)->first();
if (!$refund) {
$billNumber = (App()->make(GeneratesTransactionBillNumber::class))->execute('SRFD-');
$object = new TransactionObject($billNumber, TransactionType::SUPPLIER_REFUND, 1, $bookingInWhiteForm->issuer,
1, PaymentMethodType::CASH,
$supplier_refund_amount, $original_amount, 1,
$bookingPayment->original_currency_id, $bookingInWhiteForm->currency_rate,
0, 0, null, ApprovalStatus::APPROVED, [], $bookingPayment->bill_no);
$transaction = (App()->make(CreatesTransaction::class))->execute($bookingPayment, $object);
}
}
} else {
Log::info("Credit note transaction id: {$transaction->id} is not fully refunded, the refunded amount was {$transaction->amount}, the payment amount was {$bookingPayment->amount}, the payment reference is: {$transaction->payment_reference}");
}
// $bookingPayment = $booking->transactions()->payments()->where('status', ApprovalStatus::REFUNDED)->orderBy('id', 'DESC')->first();
$refund = $bookingPayment->transactions()->refunds()->where('amount', $transaction->amount)->where('status', ApprovalStatus::APPROVED)->first();
$bookingInWhiteForm = $bookingPayment->transactions()->bills()->first();
if ($refund) {
Log::info("Credit note transaction id: {$transaction->id}, already created same amount of refund transaction for same booking payment transaction");
}
if ($bookingInWhiteForm) {
Log::info("Credit note transaction id: {$transaction->id}, booking is in white form");
}
if (!$refund && !$bookingInWhiteForm) {
$billNumber = (App()->make(GeneratesTransactionBillNumber::class))->execute('RFD-');
$object = new TransactionObject($billNumber, TransactionType::REFUND, 1, $booking->company->id,
1, PaymentMethodType::CASH,
$transaction->amount, $transaction->amount * $bookingPayment->currency_rate, 1,
$bookingPayment->original_currency_id, $bookingPayment->currency_rate,
0, 0, null, ApprovalStatus::APPROVED, [], $bookingPayment->bill_no);
$transaction =(App()->make(CreatesTransaction::class))->execute($bookingPayment, $object);
// if ($bookingPayment) {
// Log::info("Credit note transaction id: {$transaction->id}, booking payment refunded");
// } else {
Log::info("Credit note transaction id: {$transaction->id}, booking payment not found, the payment reference is: {$transaction->payment_reference}");
// }
}
} else {
Log::info("Credit note transaction id: {$transaction->id}, booking marking not found, the payment reference is: {$transaction->payment_reference}");
@@ -129,7 +164,6 @@ class ExpiredRefundedBookingV2CommandJob implements ShouldQueue
}
$end = new Carbon();
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
Log::info(Carbon::now() . ': End job - Expiring refunded booking. ElapsedTime: ' . $elapsedTime . '.');
@@ -0,0 +1,54 @@
<?php
namespace App\Classes\Jobs\Commands\V2;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Models\Booking;
class FixExpiredBookingV2CommandJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function handle()
{
Log::info(Carbon::now() . ': Start job - Change the EXPIRED payment transaction of EXPIRED booking to REFUNDED if the payment transaction is fully refunded.');
$start = new Carbon();
$bookings = Booking::where('status', ApprovalStatus::EXPIRED)->whereHas('transactions', function ($q) {
$q->where('type', TransactionType::PAYMENT)->where('status', ApprovalStatus::EXPIRED)->whereHas('transactions', function ($q2) {
$q2->where('type', TransactionType::REFUND)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
});
})->get();
foreach ($bookings as $booking) {
$payment_transactions = $booking->transactions()->where('type', TransactionType::PAYMENT)->whereHas('transactions', function ($q2) {
$q2->where('type', TransactionType::REFUND)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
})->get();
foreach ($payment_transactions as $payment) {
$payment_original_amount = $payment->original_amount;
$refund_original_amount = $payment->transactions()->where('type', TransactionType::REFUND)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->sum('original_amount');
if ($payment_original_amount - $refund_original_amount < 0.01) {
Log::info("Updated booking id: $booking->id, payment transaction id: $payment->id, from EXPIRED to REFUNDED");
$payment->status = ApprovalStatus::REFUNDED;
$payment->save();
}
}
}
$end = new Carbon();
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
Log::info(Carbon::now() . ': End job - Change the EXPIRED payment transaction of EXPIRED booking to REFUNDED if the payment transaction is fully refunded. ElapsedTime: ' . $elapsedTime . '.');
}
}
@@ -0,0 +1,53 @@
<?php
namespace App\Classes\Jobs\Commands\V2;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use App\Models\User;
use App\Classes\ValueObjects\Constants\Vouchers;
use App\Classes\Jobs\SendWelcomeVoucherEmail;
use App\Classes\Modules\Vouchers\Services\FetchesVoucher;
use App\Classes\Jobs\SendUserVerificationEmail;
use App\Classes\Modules\Accounts\Services\GeneratesEmailVerificationAttempt;
use App\Classes\Jobs\SendResetPasswordEmail;
use App\Classes\Modules\Accounts\Services\GeneratesPasswordReset;
class OneTimeTestVoucherifyEmailV2CommandJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function handle()
{
Log::info(Carbon::now() . ': Start job - One time test sending voucherify email to see out of alignment issue.');
$start = new Carbon();
try{ //In case voucher got deleted unintentionally
$user = User::where('id', 3974)->first(); //5436, 3974
Log::info(json_encode($user));
$voucher = (App()->make(FetchesVoucher::class))->execute(['code' => Vouchers::WELCOME_50_PERCENT_OFF]);
Log::info(json_encode($voucher));
if($voucher) SendWelcomeVoucherEmail::dispatch($user, $voucher, 1);
// $attempt = (App()->make(GeneratesEmailVerificationAttempt::class))->execute($user);
// $this->sendUserVerificationEmail::dispatch($user, $attempt);
// $attempt = (App()->make(GeneratesPasswordReset::class))->execute($user);
// $this->sendResetPasswordEmail::dispatch($user, $attempt);
}
catch(\Exception $e){}
$end = new Carbon();
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
Log::info(Carbon::now() . ': End job - One time test sending voucherify email to see out of alignment issue. ElapsedTime: ' . $elapsedTime . '.');
}
}
@@ -0,0 +1,121 @@
<?php
namespace App\Classes\Jobs\Commands\V2;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use App\Classes\Modules\Transactions\ControllersLogic\UpdateGroupLogic;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Models\BillGroup;
use App\Models\Group;
use App\Models\Transaction;
use Illuminate\Http\Request;
use Illuminate\Routing\Route;
use Illuminate\Support\Facades\Route as FacadesRoute;
class UpdateBillGroupAndMoreV2CommandJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function handle()
{
Log::info(Carbon::now() . ': Start job - Update bill group and group to include transfer fee calculation.');
$start = new Carbon();
// update group to include transfer fee
$groups = Group::where('created_at', '>=', '2024-06-01')->get();
foreach ($groups as $group) {
$group_transfer_fee = 0;
$morph_transaction = $group->morphTransactions()->where('type', TransactionType::TRANSFER_FEE)->first();
if ($morph_transaction) {
$group_transfer_fee = $morph_transaction->original_amount;
}
$originalTransferFees = (float)Transaction::where('type', TransactionType::TRANSFER_FEE)->whereIn('owner_id', $group->transactions->pluck('id'))->sum('service_charge');
$correctOriginalAmount = $group->transactions()->sum('original_amount');
$correctOriginalAmount = $correctOriginalAmount + $originalTransferFees + $group_transfer_fee;
$correctAmount = $group->transactions()->sum('amount');
$transferFees = $originalTransferFees / $group->currency_rate;
$correctAmount = $correctAmount + $transferFees + ($group_transfer_fee / $group->currency_rate) + $group->service_charge;
if ($group->original_amount != $correctOriginalAmount || $group->amount != $correctAmount) {
$group->original_amount = $correctOriginalAmount;
$group->amount = $correctAmount;
$group->save();
Log::info("updated group id: {$group->id}, added transfer fee CNY {$correctOriginalAmount}");
}
}
// update group calculation to include individual group transfer fee
// $groups = Group::whereHas('morphTransactions', function ($q) {
// $q->where('type', TransactionType::TRANSFER_FEE);
// })->get();
// foreach ($groups as $group) {
// $route = FacadesRoute::getRoutes()->getByName('api.transaction.group.update');
// $request = Request::create(route('api.transaction.group.update', $group->id));
// $uri = $route->uri;
// $request->setRouteResolver(function () use ($request, $uri) {
// // Associate Route to request so we can access route parameters.
// return (new Route('PUT', $uri, []))->bind($request);
// });
// $request['rate'] = $group->currency_rate;
// $request['supplier_id'] = $group->issuer;
// $this->updateGroupLogic->execute($request);
// $group_transfer_fee = $group->morphTransactions()->where('type', TransactionType::TRANSFER_FEE)->first();
// Log::info("updated group id: {$group->id}, added transfer fee to individual white form CNY {$group_transfer_fee->original_amount}");
// }
// update bill group calculation to include individual group transfer fee
$billGroups = BillGroup::all();
foreach ($billGroups as $billGroup) {
// ignore those has bill group refund
if ($billGroup->billRefunds()->count() > 0) {
continue;
}
$totalOriginal = round($billGroup->groups()->sum('original_amount'), 2);
$total = round($billGroup->groups()->sum('amount') + $billGroup->service_charge, 2);
// update bill group payment transaction amount if there is only 1 payment transaction
$payment_transactions = $billGroup->transactions()->whereIn('status', [ApprovalStatus::PENDING_SUBMISSION, ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->get();
if ($payment_transactions->count() === 1) {
$payment_transaction = $payment_transactions->first();
if ($payment_transaction->amount - ($billGroup->amount + $billGroup->service_charge) < 0.01) {
$payment_transaction->original_amount = $total;
$payment_transaction->amount = $total;
$payment_transaction->save();
Log::info("updated bill group payment transaction id: {$payment_transaction->id}, update original amount to CNY {$totalOriginal}");
}
}
// update bill group amount and original amount
$billGroup->original_amount = $totalOriginal;
$billGroup->amount = $total;
$billGroup->save();
Log::info("updated bill group id: {$billGroup->id}, added transfer fee, final original amount is CNY {$totalOriginal}");
}
$end = new Carbon();
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
Log::info(Carbon::now() . ': End job - Update bill group and group to include transfer fee calculation. ElapsedTime: ' . $elapsedTime . '.');
}
}
@@ -0,0 +1,56 @@
<?php
namespace App\Classes\Jobs\Commands\V2;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Models\Booking;
use App\Models\Transaction;
use Illuminate\Console\Command;
class UpdateWrongFullyRefundPaymentReferenceV2CommandJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function handle()
{
Log::info(Carbon::now() . ': Start job - Update those payment reference that actually should be showing partially refund instead of fully refund.');
$start = new Carbon();
$transactions = Transaction::where('payment_reference', 'LIKE', '%Fully Refund%')->whereDate('created_at', '>=', Carbon::createFromDate(2024, 4, 2))->get();
foreach ($transactions as $transaction) {
$booking_marking = trim(explode('.', $transaction->payment_reference)[1]);
$booking = Booking::where('marking', $booking_marking)->first();
if ($booking) {
$payments = $booking->transactions()->payments()->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED, ApprovalStatus::REFUNDED])->get();
if ($payments->count() === 0) {
Log::info("Booking ID: {$booking->id}, payment not found");
} else if ($payments->count() > 1) {
Log::info("Booking ID: {$booking->id}, more than 1 payment found");
} else {
$payment = $payments->first();
if (!($payment->amount - $transaction->amount < 0.01)) {
$transaction->payment_reference = str_replace('Fully', 'Partially', $transaction->payment_reference);
$transaction->save();
Log::info("Updated Payment Reference of Transaction ID: {$transaction->id}, corrected from Fully Refund to Partially Refund");
}
}
}
}
$end = new Carbon();
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
Log::info(Carbon::now() . ': End job - Update those payment reference that actually should be showing partially refund instead of fully refund. ElapsedTime: ' . $elapsedTime . '.');
}
}
@@ -0,0 +1,106 @@
<?php
namespace App\Classes\Jobs\Commands\V2;
use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
use App\Classes\Modules\Documents\Services\CreatesDocument;
use App\Classes\Modules\Documents\Services\CreatesFiles;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\DocumentType;
use App\Models\Document;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Models\Group;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
class UpdateWrongGroupCurrencyRateV2CommandJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public function handle()
{
Log::info(Carbon::now() . ': Start job - Update those group with currency rate more than 100.');
$start = new Carbon();
$groups = Group::where('currency_rate', '>', 100)->get();
foreach ($groups as $group) {
$transactions = $group->transactions()->get();
$rate = DB::table('transaction_logs')->where('transaction_id', $transactions->first()->id)->latest('updated_at')->first()->currency_rate;
$supplier = $group->issuerCompany;
foreach ($transactions as $transaction) {
$transaction->currency_rate = $rate;
$transaction->amount = $transaction->original_amount / $rate;
$transaction->save();
$supplierRefundTransactions = $transaction->owner->transactions()->supplierRefunds()->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED])->get();
foreach ($supplierRefundTransactions as $supplierRefundTransaction) {
$claimBefore = $supplierRefundTransaction->transactions()->where('type', TransactionType::BILL_REFUND)->where('status', ApprovalStatus::APPROVED)->exists();
if (!$claimBefore) {
$supplierRefundTransaction->currency_rate = $rate;
$supplierRefundTransaction->amount = $supplierRefundTransaction->original_amount / $rate;
$supplierRefundTransaction->save();
}
}
}
$group_transfer_fee = $group->morphTransactions()->where('type', TransactionType::TRANSFER_FEE)->first();
$group_transfer_fee_original_amount = 0;
if ($group_transfer_fee) {
$group_transfer_fee_original_amount = $group_transfer_fee->original_amount;
}
$transferFeeTransactions = $group->transactions()->with([
'transactions' => function ($transaction) {
return $transaction->where('type', TransactionType::TRANSFER_FEE);
}
])->get()->pluck('transactions')->flatten();
$group->original_amount = $group->transactions()->sum('original_amount') + ((float)$transferFeeTransactions->sum('service_charge') + (float)$group_transfer_fee_original_amount);
$group->amount = $group->transactions()->sum('amount') + (((float)$transferFeeTransactions->sum('service_charge') + (float)$group_transfer_fee_original_amount) / $rate) + $group->transactions()->sum('service_charge');
$group->currency_rate = $rate;
$group->tax = $group->transactions()->sum('tax');
$group->service_charge = $group->transactions()->sum('service_charge');
$group->save();
$group->documents()->delete();
$pdf = LaravelMpdf::loadView('pages.pdfs.currency_vendor_order', ['transactions' => $group->transactions, 'transferFeeTransactions' => $transferFeeTransactions, 'supplier' => $supplier, 'groupTransferFeeOriginalAmount' => $group_transfer_fee_original_amount]);
$object = new DocumentObject(
DocumentType::CURRENCY_VENDOR_ORDER,
[chunk_split('data:application/pdf;base64,' . base64_encode($pdf->output()))],
'',
ApprovalStatus::COMPLETED,
'currency_vendor_order'
);
/** @var Document $document */
$document = (App()->make(CreatesDocument::class))->execute($group, $object);
(App()->make(CreatesFiles::class))->execute($document, $object);
Log::info("Group ID: {$group->id} updated to currency rate {$rate}");
}
$end = new Carbon();
$elapsedTime = $start->diff($end)->format('%H:%I:%S');
Log::info(Carbon::now() . ': End job - Update those group with currency rate more than 100. ElapsedTime: ' . $elapsedTime . '.');
}
}
@@ -0,0 +1,44 @@
<?php
namespace App\Console\Commands\V2;
use App\Classes\Jobs\Commands\V2\DeleteDuplicate1688BankAccountV2CommandJob;
use Illuminate\Console\Command;
class DeleteDuplicate1688BankAccountV2Command extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'banks-deleteDuplicate1688Account-command';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Delete duplicate 1688 account in banks table';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
DeleteDuplicate1688BankAccountV2CommandJob::dispatch();
}
}
@@ -0,0 +1,44 @@
<?php
namespace App\Console\Commands\V2;
use App\Classes\Jobs\Commands\V2\FixExpiredBookingV2CommandJob;
use Illuminate\Console\Command;
class FixExpiredBookingV2Command extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'fix-expired-payment-transaction-command';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Change the EXPIRED payment transaction of EXPIRED booking to REFUNDED if the payment transaction is fully refunded';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
FixExpiredBookingV2CommandJob::dispatch();
}
}
@@ -0,0 +1,47 @@
<?php
namespace App\Console\Commands\V2;
use App\Classes\Jobs\Commands\V2\OneTimeTestVoucherifyEmailV2CommandJob;
use Illuminate\Console\Command;
class OneTimeTestVoucherifyEmailV2Command extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'one-time-test-voucherify-email-command';
/**
* The console command description.
*
* @var string
*/
protected $description = 'One time test sending voucherify email to see out of alignment issue';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
OneTimeTestVoucherifyEmailV2CommandJob::dispatch();
}
}
@@ -0,0 +1,43 @@
<?php
namespace App\Console\Commands\V2;
use Illuminate\Console\Command;
use App\Classes\Jobs\Commands\V2\UpdateBillGroupAndMoreV2CommandJob;
class UpdateBillGroupAndMoreV2Command extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'update-bill-group-and-more-command';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Update bill group and group to include transfer fee calculation';
/**
* Create a new command instance.
*
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
UpdateBillGroupAndMoreV2CommandJob::dispatch();
}
}
@@ -0,0 +1,43 @@
<?php
namespace App\Console\Commands\V2;
use Illuminate\Console\Command;
use App\Classes\Jobs\Commands\V2\UpdateWrongFullyRefundPaymentReferenceV2CommandJob;
class UpdateWrongFullyRefundPaymentReferenceV2Command extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'payment-reference:update-wrong-fully-refund-command';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Update those payment reference that actually should be showing partially refund instead of fully refund';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
UpdateWrongFullyRefundPaymentReferenceV2CommandJob::dispatch();
}
}
@@ -0,0 +1,44 @@
<?php
namespace App\Console\Commands\V2;
use Illuminate\Console\Command;
use App\Classes\Jobs\Commands\V2\UpdateWrongGroupCurrencyRateV2CommandJob;
class UpdateWrongGroupCurrencyRateV2Command extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'group-update-wrong-currency-rate-command';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Update those group with currency rate more than 100';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return int
*/
public function handle()
{
UpdateWrongGroupCurrencyRateV2CommandJob::dispatch();
}
}