From 5aad5f172970ebc08c1cf29e9f2e70a00da56748 Mon Sep 17 00:00:00 2001 From: edmondlang Date: Sat, 6 May 2023 18:51:58 +0800 Subject: [PATCH] merge master --- routes/web.php | 102 +++++++++++++++++++------------------------------ 1 file changed, 39 insertions(+), 63 deletions(-) diff --git a/routes/web.php b/routes/web.php index d532cae9..5fc91252 100644 --- a/routes/web.php +++ b/routes/web.php @@ -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 '

List of customers active between '. Carbon::parse($active_start)->format('d/m/Y'). ' - '. Carbon::parse($active_end)->format('d/m/Y').' & inactive between '. Carbon::parse($inactive_start)->format('d/m/Y'). ' - '. Carbon::parse($inactive_end)->format('d/m/Y').'

'; echo ' @@ -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 . "

"; - } - }else{ - echo "billplz error
"; - } - } -}); - 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(){ '; -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 ''; - // echo ''; - // echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; - echo ''; -} -echo '
Invoices
' . $transaction->owner_type . '' . $transaction->owner_id . '' . $transaction->receiver . '' . ''. $order_reference .'' . '' . $transactionType[$transaction->type] . '' . count($transactionIds) . ''; - foreach ($duplicatedInvoice as $invoice) { - echo '

ID: ' . $invoice->id . '. Status: ' . $approvalStatusArray[$invoice->status] . '. Amount: ' . $invoice->amount . '

'; + if ($transaction->type == TransactionType::PAYMENT) { + $order_reference = $duplicatedInvoice->first()->owner->owner->owner->reference ?? null; } - echo'
'; + + echo ''; + // echo '' . $transaction->owner_type . ''; + // echo '' . $transaction->owner_id . ''; + echo '' . $transaction->receiver . ''; + echo '' . ''. $order_reference .'' . ''; + echo '' . $transactionType[$transaction->type] . ''; + echo '' . count($transactionIds) . ''; + echo ''; + foreach ($duplicatedInvoice as $invoice) { + echo '

ID: ' . $invoice->id . '. Status: ' . $approvalStatusArray[$invoice->status] . '. Amount: ' . $invoice->amount . '

'; + } + echo''; + echo ''; + } + echo ''; }); +