Merge branch 'dillon/34.3-jenkins-vapor' into vapor/development

This commit is contained in:
Dillon Ngo
2024-05-17 14:57:02 +08:00
117 changed files with 5135 additions and 129 deletions
+193 -6
View File
@@ -2,6 +2,7 @@
use App\Classes\Modules\Transactions\Processors\CreateInvoiceTransactionProcessor;
use App\Http\Controllers\Accounting\BankStatementController;
use App\Models\Remark;
use Carbon\Carbon;
use App\Models\User;
use App\Models\Wallet;
@@ -31,6 +32,7 @@ use App\Classes\Modules\Transactions\Processors\CreateInvoiceTransactionWithInvo
use App\Classes\Modules\Transactions\Services\DeletesTransaction;
use Illuminate\Support\Facades\Log;
/*
|--------------------------------------------------------------------------
| Web Routes
@@ -93,6 +95,10 @@ Route::get('/payments', function () {
return view('pages.payments');
})->name('payments');
Route::get('/supplier-payments', function () {
return view('pages.supplier-payments');
})->name('supplier.payments');
Route::get('/billings', function () {
return view('pages.billings');
})->name('billings');
@@ -218,12 +224,6 @@ Route::post('/support', function (Request $request) {
Route::get('/online_payment/redirect', 'Billplz\CallbackBillplzController@callback')->name('online_payment.redirect');
Route::get('/export/customers/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@export');
Route::get('/export/transactions/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@transactions');
Route::get('/export/analytic/booking', 'Exports\ExportAnalyticToExcelController@bookingData');
Route::get('/export/analytic/bills', 'Exports\ExportAnalyticToExcelController@billingData');
Route::get('/export/customers/leads', 'Exports\ExportCustomersToExcelController@leadsData')->name('leads.export');
Route::get('/products', function (\App\Classes\Modules\Exports\Services\ExportsProducts $exportsProducts) {
return $exportsProducts->download('products.csv', Excel::CSV, ['Content-Type' => 'text/csv']);
})->name('products.random.1'); //duplicate name
@@ -286,12 +286,16 @@ Route::get('/export/customers/f614e339d7058904a831aad742e24d55', 'Exports\Export
Route::get('/export/transactions/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@transactions');
Route::get('/export/null-debtor/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@nullDebtor')->name('newDebtor.export');
Route::get('/export/payment-transactions/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@paymentTransactions')->name('paymentTransactions.export');
Route::get('/export/white-form-transactions/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@whiteFormTransactions')->name('whiteFormTransactions.export');
Route::get('/export/wallet-transactions/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@walletTransactions')->name('walletTransactions.export');
Route::get('/export/booking-transactions', 'Exports\ExportCustomersToExcelController@bookingTransactions')->name('export.transactions.booking');
Route::get('/export/invoice-transactions/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@invoiceTransactions')->name('invoiceTransactions.export');
Route::get('/export/receipt-transactions/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@receiptTransactions')->name('receiptTransactions.export');
Route::get('/export/imported-invoice-mapped', 'Exports\ExportCustomersToExcelController@importedInvoiceMapped')->name('importedInvoiceMapped.export');
Route::get('/export/imported-receipt-mapped', 'Exports\ExportCustomersToExcelController@importedReceiptMapped')->name('importedReceiptMapped.export');
Route::get('/export/analytic/booking', 'Exports\ExportAnalyticToExcelController@bookingData');
Route::get('/export/analytic/bills', 'Exports\ExportAnalyticToExcelController@billingData');
Route::get('/export/customers/leads', 'Exports\ExportCustomersToExcelController@leadsData')->name('leads.export');
Route::get('/products', function (\App\Classes\Modules\Exports\Services\ExportsProducts $exportsProducts) {
$bookings = Booking::where(function($query){
@@ -434,6 +438,90 @@ Route::get('/pending_orders', function(){
echo '</table>';
})->name('orders.pending');
Route::get('/approve_refunds', function(Request $request){
$type = $request->query('type');
$payments = Transaction::where('type', TransactionType::PAYMENT)->where('owner_type', Booking::class)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED, ApprovalStatus::REFUNDED])
->whereHas('transactions', function ($query) use ($type) {
$query->where('type', TransactionType::REFUND)->where('status', ApprovalStatus::APPROVED);
if (str_contains($type, 'partial')) {
$query->whereColumn('original_amount', '!=','transactions.original_amount');
} else {
$query->whereColumn('original_amount', 'transactions.original_amount');
}
});
if (str_contains($type, 'post')) {
$payments->whereHas('transactions', function($query) {
$query->where('type', TransactionType::SUPPLIER_REFUND);
});
} else {
$payments->whereDoesntHave('transactions', function($query) {
$query->where('type', TransactionType::SUPPLIER_REFUND);
});
}
echo '<table>';
echo '<tr>';
echo '<td>No.</td>';
echo '<td>Updated At</td>';
echo '<td>Marking</td>';
echo '<td>Payment Method</td>';
echo '<td colspan="2">Refunded Amount</td>';
echo '<td>Company Reference</td>';
echo '<td></td>';
echo '<td colspan="2">Refunded Original Amount</td>';
echo '<td></td>';
echo '<td>Remark</td>';
echo '<td>Service</td>';
echo '<td>Last Updated At</td>';
echo '<td>Bank Type</td>';
echo '<td>Bank Holder Name</td>';
echo '</tr>';
foreach ($payments->orderBy('updated_at', 'DESC')->get() as $index => $payment){
$booking = $payment->owner;
$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';
if (!preg_match('/[^A-Za-z0-9]/', $booking->bank->holder_name))
{
$bankType = str_word_count($booking->bank->holder_name) > 4 ? 'Company' : 'Personal';
}
$refundTransaction = $payment->transactions()->refunds()->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->first();
$remark = $refundTransaction->original_amount === $payment->original_amount ? 'Fully Refund' : 'Partial Refund';
if (str_contains($type, 'post')) {
$remark = 'Post ' . $remark;
} else {
$remark = 'Pre ' . $remark;
}
echo '<tr>';
echo '<td>'.($index + 1).'.</td>';
echo '<td>'.$payment->updated_at->format('d-M-y').'</td>';
echo '<td>'.$booking->marking.'</td>';
echo '<td>'.\App\Classes\ValueObjects\Constants\PaymentMethodType::PAYMENT_METHODS_ID[$payment->payment_method].'</td>';
echo '<td>'.$payment->currency->short_code.'</td>';
echo '<td>'.number_format($refunds, 5, '.', '').'</td>';
echo '<td>'.$booking->company->reference.'</td>';
echo '<td></td>';
echo '<td>'.$payment->original_currency->short_code.'</td>';
echo '<td>'.number_format($original_refunds, 5, '.', '').'</td>';
echo '<td></td>';
echo '<td>'.$remark.'</td>';
echo '<td>'.$booking->service->name.'</td>';
echo '<td>'.$payment->updated_at->diffForHumans().'</td>';
echo '<td>'.$bankType.'</td>';
echo '<td>'.$booking->bank->holder_name.'</td>';
echo '</tr>';
}
echo '</table>';
})->name('orders.refunds');
Route::get('/group/text/{id}', function($id){
$group = \App\Models\Group::where('id', $id)->first();
@@ -887,6 +975,105 @@ Route::get('/invoice/{marking}/{started_at}/{ended_at}/fix', function($marking,
Route::get('/booking/{marking}/track-shipping-order', 'Bookings\TrackBookingShipmentController@track')->name('booking.track_shipping_order');
route:: post('/transaction/{id}/create-remark',function ($transactionId) {
$transaction = Transaction::find($transactionId);
$remark = new Remark();
$remark->owner_type = get_class($transaction);
$remark->owner_id = $transaction->id;
$remark->content = request('content');
$remark->save();
return redirect()->back();
})->name('transaction.create-remark');
Route::get('/show-white-form-transactions-in-date-range/{from_date}/{to_date}', function ($from_date, $to_date) {
$approvedTransactions = Transaction::where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED])->where('owner_type', '!=', Wallet::class)->orderBy('status')->get();
echo '<h1>Pending Orders Payments</h1>';
echo '<table style="border-collapse: collapse;">';
echo '<thead>';
echo '<tr>';
echo '<th style="border: 1px solid black;">Booking</th>';
echo '<th style="border: 1px solid black;">Amount</th>';
echo '<th style="border: 1px solid black;">Payment Date</th>';
echo '<th style="border: 1px solid black;">Status</th>';
echo '</tr>';
echo '</thead>';
echo '<tbody>';
foreach ($approvedTransactions as $approvedTransaction) {
echo '<tr>';
echo '<td style="border: 1px solid black;"><a href="' . \route('booking.details', $approvedTransaction->owner->marking) . '" target="_blank">' . $approvedTransaction->owner->marking . '</a></td>';
echo '<td style="border: 1px solid black;">' . round($approvedTransaction->amount, 2) . '</td>';
echo '<td style="border: 1px solid black;">' . $approvedTransaction->created_at->format('d-m-Y h:i A') . '</td>';
echo '<td style="border: 1px solid black;">' . ApprovalStatus::APPROVAL_STATUS_ID[$approvedTransaction->status] . '</td>';
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
$startDate = Carbon::createFromFormat('d-m-Y', $from_date)->startOfDay();
$endDate = Carbon::createFromFormat('d-m-Y', $to_date)->endOfDay();
echo '<h1>Bills in the date range</h1>';
echo '<table style="border-collapse: collapse; width: 100%;">';
echo '<thead>';
echo '<tr>';
echo '<th style="border: 1px solid black;">Booking</th>';
echo '<th style="border: 1px solid black;">Amount</th>';
echo '<th style="border: 1px solid black;">Customer payment date</th>';
echo '<th style="border: 1px solid black;">White form date</th>';
echo '<th style="border: 1px solid black;">Supplier</th>';
echo '<th style="border: 1px solid black;">Upload bank slip Date</th>';
echo '<th style="border: 1px solid black;">PO submit date</th>';
echo '<th style="border: 1px solid black;">PO approve date</th>';
echo '<th style="border: 1px solid black;">Remark</th>';
echo '<th style="border: 1px solid black;">Add Remarks</th>';
echo '</tr>';
echo '</thead>';
echo '<tbody>';
$bills = Transaction::where('type', TransactionType::BILL)->whereBetween('created_at', [$startDate, $endDate])->get();
foreach ($bills as $bill) {
echo '<tr>';
$payment = $bill->owner;
$po = $payment->owner->transactions()->where('type', TransactionType::PURCHASE_ORDER)->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED])->first();
echo '<td style="border: 1px solid black;"><a href="' . \route('booking.details', $bill->owner->owner->marking) . '" target="_blank">' . $payment->owner->marking . '</a></td>';
echo '<td style="border: 1px solid black;">' . round($payment->amount, 2) . '</td>';
echo '<td style="border: 1px solid black;">' . $payment->created_at->format('d-m-Y h:i A') . '</td>';
echo '<td style="border: 1px solid black;">' . $bill->created_at->format('d-m-Y h:i A') . '</td>';
echo '<td style="border: 1px solid black;">' . $bill->issuerCompany->name . '</td>';
echo '<td style="border: 1px solid black; color: '.($bill->status === ApprovalStatus::APPROVED ? "green" : "red").';">' . ($bill->status === ApprovalStatus::APPROVED ? $bill->updated_at->format('d-m-Y h:i A') : 'Pending Upload') . '</td>';
echo '<td style="border: 1px solid black; color: '.($po ? "green" : "red").';">' . ($po ? $po->updated_at->format('d-m-Y h:i A') : 'Pending Submission') . '</td>';
echo '<td style="border: 1px solid black;">' . ($po ? ($po->status === ApprovalStatus::APPROVED ? $po->updated_at->format('d-m-Y h:i A') : '' ) : '' ). '</td>';
$remarks = $bill->remarks;
echo '<td style="border: 1px solid black;">';
foreach ($remarks as $remark) {
echo $remark->created_at->format('d-m-Y : h:i A') . ' - ';
echo $remark->content;
echo '<br>';
}
echo '</td>';
echo '<td style="border: 1px solid black;">' ;
echo '<form method="post" style="display:flex; margin: 10px" action="' . route('transaction.create-remark', ['id' => $bill->id]) . '">';
echo '<input type="text" name="content" placeholder="Enter remark" required>';
echo '<button type="submit">Add</button>';
echo csrf_field();
echo '</form>';
echo '</td>';
echo '</tr>';
}
echo '</tbody>';
echo '</table>';
});
//Laravel Vapor - Starts
Route::get('/aws-image-upload', 'AWS\AWSImageUploadController@imageUpload')->name('aws.image.upload');
Route::post('/aws-image-upload', 'AWS\AWSImageUploadController@imageUploadPost')->name('aws.image.upload.post');