merge master

This commit is contained in:
edmondlang
2023-05-06 18:51:58 +08:00
parent 485a6e2e82
commit 5aad5f1729
+39 -63
View File
@@ -495,18 +495,21 @@ Route::get('/customer/summary/{year}/monthly', function ($year) {
});
Route::get('/customers/active/{active_start}/{active_end}/{inactive_start?}/{inactive_end?}/{with_cbm?}', function ($active_start, $active_end, $inactive_start=null, $inactive_end=null, $with_cbm = false) {
$activeCompanies = CompanyModule::where('type', BusinessType::IMPORTER)->whereHas('orderPackingLists', function($query) use($inactive_start, $inactive_end) {
return $query->where('packing_lists.type', PackingListType::WAREHOUSE_RECEIVE_LIST)->whereHas('transports', function ($query) use ($inactive_start, $inactive_end) {
return $query->where('drop_date', '>=', Carbon::parse($inactive_start))->where('drop_date', '<=', Carbon::parse($inactive_end)->addDay());
});
})->pluck('id');
Route::get('/customers/active/{active_start}/{active_end}/{inactive_start?}/{inactive_end?}/{with_cbm?}', function ($active_start, $active_end, $inactive_start = null, $inactive_end = null, $with_cbm = false) {
/* $activeCompanies = CompanyModule::where('type', BusinessType::IMPORTER)->whereHas('orderPackingLists', function($query) use($inactive_start, $inactive_end) {
return $query->where('packing_lists.type', PackingListType::WAREHOUSE_RECEIVE_LIST)->whereHas('transports', function ($query) use ($inactive_start, $inactive_end) {
return $query->where('drop_date', '>=', Carbon::parse($inactive_start))->where('drop_date', '<=', Carbon::parse($inactive_end)->addDay());
});
})->pluck('id');
$companies = CompanyModule::where('type', BusinessType::IMPORTER)->whereHas('orderPackingLists', function($query) use($active_start, $active_end) {
return $query->where('packing_lists.type', PackingListType::WAREHOUSE_RECEIVE_LIST)->whereHas('transports', function ($query) use ($active_start, $active_end) {
return $query->whereDate('drop_date', '>=', Carbon::parse($active_start))->whereDate('drop_date', '<=', Carbon::parse($active_end)->addDay());
});
})->whereNotIn('id', $activeCompanies)->get();*/
$companies = getActiveCompanies($inactive_start, $inactive_end, $active_start, $active_end);
$companies = CompanyModule::where('type', BusinessType::IMPORTER)->whereHas('orderPackingLists', function($query) use($active_start, $active_end) {
return $query->where('packing_lists.type', PackingListType::WAREHOUSE_RECEIVE_LIST)->whereHas('transports', function ($query) use ($active_start, $active_end) {
return $query->whereDate('drop_date', '>=', Carbon::parse($active_start))->whereDate('drop_date', '<=', Carbon::parse($active_end)->addDay());
});
})->whereNotIn('id', $activeCompanies)->get();
echo '<h4>List of customers active between <span style="color: green; font-weight: bold">'. Carbon::parse($active_start)->format('d/m/Y'). ' - '. Carbon::parse($active_end)->format('d/m/Y').'</span> & inactive between <span style="color: red; font-weight: bold">'. Carbon::parse($inactive_start)->format('d/m/Y'). ' - '. Carbon::parse($inactive_end)->format('d/m/Y').'</span></h4>';
echo '<table>
@@ -1043,7 +1046,7 @@ Route::get('/wallet/{marking}/details', function ($marking) {
Route::get('/wallet/audit', function (Request $request) {
$wallets = \App\Models\Wallet::all();
$i = 0;
$i = 0;
foreach ($wallets as $wallet){
$topups = 0;
$credit = 0;
@@ -1067,34 +1070,6 @@ Route::get('/wallet/audit', function (Request $request) {
}
});
Route::get('/billplz/audit', function (Request $request) {
$transactions = Transaction::where('type', TransactionType::PAYMENT)->where('payment_method', PaymentMethodType::PAYMENT_GATEWAY)->whereIn('status', [ApprovalStatus::COMPLETED, ApprovalStatus::APPROVED])->get();
$i = 0;
$totalAmount = 0;
foreach ($transactions as $transaction){
$response = Http::withBasicAuth(config('billplz.api_key').':', '')->get(config('billplz.base_url').'/api/v3/bills/'.$transaction->payment_reference);
if($response->successful()){
$data = $response->json();
if($data['paid']){
} else {
$transaction->status = ApprovalStatus::REJECTED;
$transaction->save();
$invoice = $transaction->owner;
$invoice->status = ApprovalStatus::APPROVED;
$totalAmount += $transaction->amount;
echo 'Order: '. $transaction->owner->owner->owner->reference . ' - Date: '.$transaction->owner->created_at->format('d-m-Y').' - Amount: '. $transaction->amount . " </br></br>";
}
}else{
echo "billplz error</br>";
}
}
});
Route::get('/final-duplicated-invoice-debug', function(){
$duplicatedTransactions = Transaction::select(DB::raw('owner_type, owner_id, receiver, type, GROUP_CONCAT(id) as transaction_ids, COUNT(*) as count'))
->whereNotIn('status', [ApprovalStatus::REJECTED,ApprovalStatus::SUSPENDED,ApprovalStatus::EXPIRED])
@@ -1118,30 +1093,31 @@ Route::get('/final-duplicated-invoice-debug', function(){
<th style="border: 1px solid black" >Invoices</th>
</tr>';
foreach ($duplicatedTransactions as $transaction) {
$transactionIds = explode(',', $transaction->transaction_ids);
foreach ($duplicatedTransactions as $transaction) {
$transactionIds = explode(',', $transaction->transaction_ids);
$duplicatedInvoice = Transaction::whereIn('id', $transactionIds)->get();
$order_reference = $duplicatedInvoice->first()->owner->owner->reference ?? null;
$duplicatedInvoice = Transaction::whereIn('id', $transactionIds)->get();
$order_reference = $duplicatedInvoice->first()->owner->owner->reference ?? null;
if ($transaction->type == TransactionType::PAYMENT) {
$order_reference = $duplicatedInvoice->first()->owner->owner->owner->reference ?? null;
}
echo '<tr>';
// echo '<td style="border: 1px solid black">' . $transaction->owner_type . '</td>';
// echo '<td style="border: 1px solid black">' . $transaction->owner_id . '</td>';
echo '<td style="border: 1px solid black">' . $transaction->receiver . '</td>';
echo '<td style="border: 1px solid black">' . '<a target="_blank" href="'.route('order.show', $order_reference).'">'. $order_reference .'</a>' . '</td>';
echo '<td style="border: 1px solid black">' . $transactionType[$transaction->type] . '</td>';
echo '<td style="border: 1px solid black">' . count($transactionIds) . '</td>';
echo '<td style="border: 1px solid black; text-align: left">';
foreach ($duplicatedInvoice as $invoice) {
echo '<p>ID: ' . $invoice->id . '. Status: ' . $approvalStatusArray[$invoice->status] . '. Amount: ' . $invoice->amount . '</p>';
if ($transaction->type == TransactionType::PAYMENT) {
$order_reference = $duplicatedInvoice->first()->owner->owner->owner->reference ?? null;
}
echo'</td>';
echo '</tr>';
}
echo '</table>';
echo '<tr>';
// echo '<td style="border: 1px solid black">' . $transaction->owner_type . '</td>';
// echo '<td style="border: 1px solid black">' . $transaction->owner_id . '</td>';
echo '<td style="border: 1px solid black">' . $transaction->receiver . '</td>';
echo '<td style="border: 1px solid black">' . '<a target="_blank" href="'.route('order.show', $order_reference).'">'. $order_reference .'</a>' . '</td>';
echo '<td style="border: 1px solid black">' . $transactionType[$transaction->type] . '</td>';
echo '<td style="border: 1px solid black">' . count($transactionIds) . '</td>';
echo '<td style="border: 1px solid black; text-align: left">';
foreach ($duplicatedInvoice as $invoice) {
echo '<p>ID: ' . $invoice->id . '. Status: ' . $approvalStatusArray[$invoice->status] . '. Amount: ' . $invoice->amount . '</p>';
}
echo'</td>';
echo '</tr>';
}
echo '</table>';
});