Files
exchange-2.0/routes/web.php
T
2022-11-08 19:06:25 +08:00

448 lines
19 KiB
PHP

<?php
use App\Classes\Modules\Bookings\Processors\CreatePurchaseOrderFor1688OrderProcessor;
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\Classes\ValueObjects\Constants\TransactionType;
use App\Models\Booking;
use App\Models\Company;
use App\Models\Transaction;
use App\Models\User;
use App\Models\Wallet;
use Carbon\Carbon;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use Maatwebsite\Excel\Excel;
use Meneses\LaravelMpdf\Facades\LaravelMpdf;
use Webklex\PDFMerger\Facades\PDFMergerFacade as PDFMerger;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('', function () {
return view('pages.accounts.login');
})->name('login');
Route::get('/signup', function () {
return view('pages.accounts.sign_up');
})->name('signup');
Route::get('/account/email/verification/{token}', function ($token) {
return view('pages.accounts.email_verified', ['token' => $token]);
})->name('account.email.verification');
Route::get('/account/password/reset/{token}', function ($token) {
return view('pages.accounts.reset_password', ['token' => $token]);
})->name('account.password.reset');
Route::get('/dashboard', function () {
return view('pages.dashboards.index');
})->name('dashboard');
Route::get('/banks', function () {
return view('pages.banks.index');
})->name('banks');
Route::get('/settings', function () {
return view('pages.settings');
})->name('settings');
Route::get('/customers', function () {
return view('pages.customers.index');
})->name('customers');
Route::get('/customer/{marking}', function ($marking) {
$id = \App\Models\Company::where('reference', '=', $marking)->first()->id;
return view('pages.customers.profile', ['id' => $id]);
})->name('customer.profile');
Route::get('/payments', function () {
return view('pages.payments');
})->name('payments');
Route::get('/billings', function () {
return view('pages.billings');
})->name('billings');
Route::get('/currency_orders', function () {
return view('pages.currency_orders');
})->name('currency_orders');
Route::get('/transfers', function () {
return view('pages.bookings.index');
})->name('bookings');
Route::get('/bookings/urgent', function () {
return view('pages.urgent_list');
})->name('bookings.urgent');
Route::get('/transfer/{marking}', function ($marking) {
return view('pages.bookings.profile', ['marking' => $marking]);
})->name('booking.details');
Route::get('/transfer/merge/{marking}', function ($marking) {
return view('pages.bookings.merge', ['marking' => $marking]);
})->name('booking.merge');
Route::get('/purchase_orders', function () {
return view('pages.purchase_orders');
})->name('purchase_orders');
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');
Route::get('/fix_bills', function () {
ini_set('max_execution_time', '1000000');
Auth()->login(User::find(1));
$bookings = \App\Models\Booking::where('status', 3)->whereHas('transactions', function ($query){
return $query->where('type', 1)->whereHas('transactions', function($query){
return $query->where('type', 3)->where('issuer', 2210);
});
})->get();
foreach ($bookings as $booking){
$booking->documents()->where('document_type', DocumentType::SUPPLIER_DELIVER_ORDER)->delete();
$po = $booking->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first();
$supplier_deliver_order_transaction = $booking->transactions()->where('type', TransactionType::SUPPLIER_DELIVER)->first();
$supplier = Company::find($booking->transactions()->where('type', TransactionType::PAYMENT)->where('status', 3)->first()->transactions()->first());
$supplier_order_pdf = LaravelMpdf::loadView('pages.pdfs.supplier_deliver_order', ['supplier_deliver_order_transaction' => $supplier_deliver_order_transaction, 'po_order_transaction' => $po, 'supplier' => $supplier]);
$document_object = new DocumentObject(
DocumentType::SUPPLIER_DELIVER_ORDER,
[chunk_split('data:application/pdf;base64,'.base64_encode($supplier_order_pdf->output()))],
'',
ApprovalStatus::COMPLETED,
'supplier_delivery_orders'
);
$document = (App()->make(CreatesDocument::class))->execute($booking, $document_object);
(App()->make(CreatesFiles::class))->execute($document, $document_object);
}
})->name('products.random');
Route::get('/wallet/{marking}/details', function ($marking) {
$id = \App\Models\Company::where('reference', '=', $marking)->first()->id;
return view('pages.wallet.index', ['id' => $id]);
})->name('wallet.details');
Route::get('/wallets', function () {
return view('pages.wallet.wallets');
})->name('wallet.wallets');
Route::get('/bookings/billplz', function () {
return view('pages.billplz_redirect');
})->name('bookings.billplz');
Route::get('/document/download', 'Bookings\DownloadBookingDocumentController@download')->name('documents.download');
Route::get('billplz/bills/{bill_no}', function($bill_no){
return redirect(env('BILLPLZ_BASE_URL').'/bills/'.$bill_no);
})->name('billplz.bill');
Route::get('/export/customers/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@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/wallet-transactions/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@walletTransactions')->name('walletTransactions.export');
Route::get('/export/booking-transactions', 'Exports\ExportCustomersToExcelController@bookingTransactions')->name('export.transactions.booking');
Route::get('/products', function (\App\Classes\Modules\Exports\Services\ExportsProducts $exportsProducts) {
$bookings = Booking::where(function($query){
return $query->whereMonth('created_at', 7)->orWhereMonth('created_at', 8)->orWhereMonth('created_at', 9)->orWhereMonth('created_at', 10)->orWhereMonth('created_at', 11)->orWhereMonth('created_at', 12);
})->whereDoesntHave('transactions', function($q){
$q->where('type', TransactionType::PURCHASE_ORDER);
$q->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED]);
})->get();
dd($bookings->count());
return $exportsProducts->download('products.csv', Excel::CSV, ['Content-Type' => 'text/csv']);
})->name('products.random');
Route::get('/auto-purchase-order-fill', 'Bookings\AutoPurchaseOrderFillController@auto')->name('assign');
Route::get('purchase/sensitive/', function(Request $request){
$keywords = json_decode($request->input('keywords'));
$items = \App\Models\TransactionDetail::query();
foreach ($keywords as $key => $keyword){
if(!$key){
$items->Where('product_name', 'like', '%'.$keyword.'%');
continue;
}
$items->orWhere('product_name', 'like', '%'.$keyword.'%');
}
$items = $items->get();
foreach ($items as $key => $item){
echo ($key+1).'. '.$item->product_name.' => <a href="'.\route('booking.details', $item->transaction->owner->marking).'" target="_blank">'.$item->transaction->owner->marking.'</a><br><br>';
}
});
Route::get('/transactions/supplier/{id}/mock_up', 'Transactions\DownloadMockUpWhiteFormPdfController@download')->name('whiteForm.mockUp');
Route::get('/notifications/list', 'Notifications\ListNotificationsController@list')->name('notifications.list');
Route::get('/supplier/pi/export', function(){
$groups = \App\Models\Group::where('issuer', 2729)->whereMonth('created_at', 9)->whereYear('created_at', 2022)->get();
echo '<table>';
$i = 0;
foreach ($groups as $group){
foreach ($group->transactions as $transaction){
$booking = $purchaseOrder = $transaction->owner->owner;
$purchaseOrder = $booking->transactions()->where('type', TransactionType::PURCHASE_ORDER)->where('status', ApprovalStatus::APPROVED)->first();
if(!$purchaseOrder) {
echo '<tr>';
echo '<td>-</td>';
echo '<td>'.$group->created_at.'</td>';
echo '<td style="color: red">warning, booking ref.'.$booking->marking.' doesn\'t have purchase order</td>';
echo '<td>0</td>';
echo '<td>0</td>';
echo '<td>0</td>';
echo '<td>'.$booking->marking.'</td>';
echo '</tr>';
continue;
}
foreach ($purchaseOrder->transactionDetails as $item){
$i++;
echo '<tr>';
echo '<td>'.$i.'</td>';
echo '<td>'.$group->created_at.'</td>';
echo '<td>'.$item->product_name.'</td>';
echo '<td>'.$item->quantity.'</td>';
echo '<td>'.$item->price * (1/$group->currency_rate).'</td>';
echo '<td>'.($item->price * $item->quantity) * (1/$group->currency_rate).'</td>';
echo '<td>'.$booking->marking.'</td>';
echo '</tr>';
}
}
}
echo '<tr><td>Service Charge</td><td>'.$groups->sum('service_charge').'</td></tr>';
echo '</table>';
});
Route::get('/segments', function (Request $request) {
$segment = null;
if ($request->has('id')) {
$segment = App\Models\Segment::find($request->id);
}
return view('pages.segments.index', compact('segment'));
})->name('segments');
Route::get('/pending_orders', function(){
$payments = Transaction::where('type', TransactionType::PAYMENT)->where('owner_type', Booking::class)->whereIn('status', [ApprovalStatus::APPROVED])->get();
echo '<table>';
$i = 0;
foreach ($payments as $payment){
$booking = $payment->owner;
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';
}
echo '<tr>';
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>'.$payment->amount.'</td>';
echo '<td>'.$booking->company->reference.'</td>';
echo '<td></td>';
echo '<td>'.$payment->original_currency->short_code.'</td>';
echo '<td>'.$payment->original_amount.'</td>';
echo '<td></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.pending');
Route::get('/group/text/{id}', function($id){
$group = \App\Models\Group::where('id', $id)->first();
echo 'RATE: '.$group->currency_rate.'<br>';
echo 'DATE: '.$group->created_at.'<br><br><br>';
$i = 0;
foreach ($group->transactions as $transaction){
$i++;
$booking = $transaction->owner->owner;
echo 'No.'.$i.'<br>';
echo 'Bank Details:'.$booking->bank->holder_name.'<br>';
echo $booking->bank->bank_name.' '.$booking->bank->bank_branch.'<br>';
echo 'Bank Account Number:'.$booking->bank->account_no.'<br>';
echo 'Order Amount:'.$transaction->original_currency->short_code.' '.(round($transaction->original_amount, 2) + 0).'<br><br>';
}
})->name('group.text');
Route::get('/wallet/audit', function (Request $request) {
$wallets = \App\Models\Wallet::all();
$i = 0;
foreach ($wallets as $wallet){
$topups = 0;
$credit = 0;
$payments = 0;
$debit = 0;
foreach ($wallet->transactions as $transaction){
if(!in_array((int) $transaction->status, [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])) continue;
if((int) $transaction->type === TransactionType::TOP_UP) {
$topups += (float) $transaction->amount;
// $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 {
// echo $transaction->id." => Fraud";
// }
// }else{
// echo "billplz error";
// }
}
if((int) $transaction->type === TransactionType::CREDIT_NOTE) $credit += (float) $transaction->amount;
if((int) $transaction->type === TransactionType::PAYMENT) $payments += (float) $transaction->amount;
if((int) $transaction->type === TransactionType::DEBIT_NOTE) $debit += (float) $transaction->amount;
}
if(round((float) $wallet->amount - (($topups + $credit) - ($payments + $debit)), 2) == 0) continue;
$i++;
echo $i.". Marking: ". $wallet->owner->reference ."(".$wallet->id.")<br>Current Balance: ". $wallet->amount ."<br>Audit Balance: ". (($topups + $credit) - ($payments + $debit)) ."<br>Difference: ". round((float) $wallet->amount - (($topups + $credit) - ($payments + $debit)), 2) ."<br><br><br>";
}
});
Route::get('/wallets/active', function(){
$wallets = Wallet::all();
echo '<table>';
foreach ($wallets as $wallet){
echo '<tr>';
echo '<td><a href="'.route('wallet.details', $wallet->owner->reference).'" target="_blank">'.$wallet->owner->reference.'</a></td>';
echo '<td>'.$wallet->amount.'</td>';
echo '</tr>';
}
echo '</table>';
});
Route::get('/payments/manual', function(){
$payments = Transaction::where('type', TransactionType::PAYMENT)->whereIn('payment_method', [\App\Classes\ValueObjects\Constants\PaymentMethodType::CASH, \App\Classes\ValueObjects\Constants\PaymentMethodType::BA, \App\Classes\ValueObjects\Constants\PaymentMethodType::CHEQUE])->where('owner_type', Booking::class)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->get();
$i = 0;
echo '<table>';
foreach ($payments as $payment){
$i++;
echo '<tr>';
echo '<td>'.$i.'</td>';
echo '<td>'.$payment->documents()->first()->created_at->format('d-m-Y').'</td>';
echo '<td><a href="'.route('booking.details', $payment->owner->marking).'" target="_blank">'.$payment->owner->marking.'</a></td>';
echo '<td>'.$payment->amount.'</td>';
echo '</tr>';
}
echo '</table>';
});
Route::get('/1688/fix/{reference}', function($reference){
$booking = Booking::where('marking', $reference)->first();
(App()->make(createPurchaseOrderFor1688OrderProcessor::class))->execute($booking);
// set_time_limit(1800);
// $purchaseOrderDocuments = \App\Models\Document::where('document_type', DocumentType::ECOMMERCE_PURCHASE_ORDER)->get();
//
// foreach($purchaseOrderDocuments as $document){
// $booking = $document->owner;
// $booking->status = ApprovalStatus::APPROVED;
// $booking->save();
//
// $booking->documents()->whereIn('document_type', [DocumentType::INVOICE, DocumentType::PURCHASE_ORDER, DocumentType::DELIVER_ORDER, DocumentType::SUPPLIER_DELIVER_ORDER])->delete();
//
// (App()->make(createPurchaseOrderFor1688OrderProcessor::class))->execute($document->owner);
// }
})->name('ecommerce.fix');
Route::get('/po/manual/fix', function(){
$bookings = Booking::whereIn('company_id', [199, 510])->whereHas('documents', function($query){
return $query->where('document_type', DocumentType::ECOMMERCE_PURCHASE_ORDER);
})->get();
foreach ($bookings as $booking){
$booking->status = ApprovalStatus::APPROVED;
$booking->save();
$booking->documents()->whereIn('document_type', [DocumentType::PURCHASE_ORDER, DocumentType::DELIVER_ORDER, DocumentType::INVOICE, DocumentType::SUPPLIER_DELIVER_ORDER])->delete();
$booking->transactions()->where('type', TransactionType::PURCHASE_ORDER)->update(['status' => ApprovalStatus::PENDING_SUBMISSION]);
}
})->name('ecommerce.fix');
Route::get('/payment/check', function(){
$transactions = Transaction::where('type', TransactionType::PAYMENT)->where('payment_method', \App\Classes\ValueObjects\Constants\PaymentMethodType::CASH)->whereDate('created_at', '=', Carbon::today())->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->get();
foreach ($transactions as $transaction){
$documents = $transaction->documents;
if(!count($documents)){
echo $transaction->owner->marking.'<br><br>';
continue;
}
echo $transaction->owner->marking.'. payment: '.$transaction->updated_at.' -> document: '.$documents[0]->created_at.'<br>';
}
})->name('payment.check');