diff --git a/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php b/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php index 590497bc..8c763460 100644 --- a/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php +++ b/app/Classes/Modules/Billplzs/ControllersLogic/CallbackBillplzLogic.php @@ -2,6 +2,8 @@ namespace App\Classes\Modules\Billplzs\ControllersLogic; +use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject; +use App\Classes\Modules\Wallets\Services\UpdatesWallet; use App\Classes\Exceptions\ResourceNotFoundException; use App\Http\Resources\TransactionResource; @@ -32,6 +34,8 @@ class CallbackBillplzLogic /** @var UpdatesTransactionStatus */ private $updatesTransactionStatus; + /** @var UpdatesWallet */ + private $updatesWallet; /** * CreateBookingLogic constructor. @@ -39,11 +43,12 @@ class CallbackBillplzLogic * @param FetchesTransaction $fetchesTransaction * @param UpdatesTransactionStatus $updatesTransactionStatus */ - public function __construct(GetBillplzBill $getBillplzBill, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus) + public function __construct(GetBillplzBill $getBillplzBill, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, UpdatesWallet $updatesWallet) { $this->getBillplzBill = $getBillplzBill; $this->fetchesTransaction = $fetchesTransaction; $this->updatesTransactionStatus = $updatesTransactionStatus; + $this->updatesWallet = $updatesWallet; } @@ -55,7 +60,6 @@ class CallbackBillplzLogic */ public function execute(Request $request) { - $billplzXSignatureObject = new BillplzXSignatureObject($request); if(!$billplzXSignatureObject->isValidSignature()){ @@ -70,6 +74,16 @@ class CallbackBillplzLogic if($billPlz->state === 'paid') { $status = ApprovalStatus::APPROVED; + if ( + $transaction->owner_type == 'App\Models\Wallet' && + $transaction->status == ApprovalStatus::PENDING_VERIFICATION + ) { + $wallet = $transaction->owner; + $updateWalletAmount = $wallet->amount + $transaction->amount; + $walletOject = new WalletObject($wallet->company->id, $wallet->currency_id, $wallet->code, $updateWalletAmount); + $wallet = $this->updatesWallet->execute($wallet, $walletOject); + } + } if($billPlz->state === 'due') { diff --git a/app/Classes/Modules/Bookings/ControllersLogic/AutoPurchaseOrderFillLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/AutoPurchaseOrderFillLogic.php new file mode 100644 index 00000000..ed9ec6d8 --- /dev/null +++ b/app/Classes/Modules/Bookings/ControllersLogic/AutoPurchaseOrderFillLogic.php @@ -0,0 +1,113 @@ +generatesPurchaseOrderProducts = $generatesPurchaseOrderProducts; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + $this->createPurchaseOrderTransactionProcessor = $createPurchaseOrderTransactionProcessor; + } + + + /** + * @return array + */ + protected function notification():array { + return [ + 'title' => 'Purchase Order Approval', + 'message' => 'You have successfully updated the Purchase order status' + ]; + } + + /** @var GeneratesPurchaseOrderProducts */ + private $generatesPurchaseOrderProducts; + + /** @var GeneratesTransactionBillNumber */ + private $generatesTransactionBillNumber; + + /** @var CreatePurchaseOrderTransactionProcessor */ + private $createPurchaseOrderTransactionProcessor; + + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + $bookings = Booking::whereMonth('created_at', 7) + ->whereYear('created_at', 2021) + ->whereDoesntHave('transactions', function($q){ + $q->where('type', TransactionType::PURCHASE_ORDER); + $q->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED]); + })->get(); + foreach ($bookings as $booking) { + $po = Transaction::where('type', TransactionType::PURCHASE_ORDER) + ->where('status', ApprovalStatus::APPROVED)->where('issuer', $booking->company_id) + ->select('*', DB::raw('abs(amount - ' . $booking->fix_amount . ') as nearest_price'))->orderBy('nearest_price')->first(); + + + if (!$po) { + $po = Transaction::where('type', TransactionType::PURCHASE_ORDER) + ->where('status', ApprovalStatus::APPROVED)->select('*', DB::raw('abs(amount - ' . $booking->fix_amount . ') as nearest_price'))->orderBy('nearest_price')->first(); + } + + $products = $this->generatesPurchaseOrderProducts->execute($po, $booking->fix_amount); + + $deference = $booking->fix_amount - $products->sum('total'); + + if($deference > -150 && $deference < 150 && $deference != 0) { + + $products->push([ + 'description' => $deference < 0 ? 'Discount':'Shipping Fee', + 'quantity' => 1, + 'stockCode' => '', + 'total' => $deference, + 'unit_price' => $deference + ]); + } + + $billNumber = $this->generatesTransactionBillNumber->execute('XPO-'); + + $total = $products->sum('total'); + + $object = new TransactionObject($billNumber, TransactionType::PURCHASE_ORDER, $booking->company->id, 1, + 1, PaymentMethodType::CASH, + $total, $total, $booking->fix_currency_id, $booking->fix_currency_id, + 1, 0, 0, null, ApprovalStatus::PENDING_SUBMISSION, $products->toArray()); + + $this->createPurchaseOrderTransactionProcessor->execute($booking, $object); + } + + return $this->response([]); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreatePurchaseOrderTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreatePurchaseOrderTransactionLogic.php index aa4c6f4d..9bab107f 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/CreatePurchaseOrderTransactionLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreatePurchaseOrderTransactionLogic.php @@ -7,6 +7,7 @@ use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Bookings\Services\FetchesBooking; use App\Classes\Modules\Companies\Services\FetchesCompany; use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject; +use App\Classes\Modules\Transactions\Processors\CreatePurchaseOrderTransactionProcessor; use App\Classes\Modules\Transactions\Services\CreatesTransaction; use App\Classes\Modules\Transactions\Services\CreatesTransactionDetail; use App\Classes\Modules\Transactions\Services\DeletesTransactionDetails; @@ -25,26 +26,6 @@ use Illuminate\Http\Request; class CreatePurchaseOrderTransactionLogic extends AbstractControllerLogic { - /** - * CreatePurchaseOrderTransactionLogic constructor. - * @param FetchesBooking $fetchesBooking - * @param UpdatesTransactionStatus $updatesTransactionStatus - * @param CreatesTransaction $createsTransaction - * @param CreatesTransactionDetail $createsTransactionDetail - * @param UpdatesTransaction $updatesTransaction - * @param DeletesTransactionDetails $deletesTransactionDetails - * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber - */ - public function __construct(FetchesBooking $fetchesBooking, UpdatesTransactionStatus $updatesTransactionStatus, CreatesTransaction $createsTransaction, CreatesTransactionDetail $createsTransactionDetail, UpdatesTransaction $updatesTransaction, DeletesTransactionDetails $deletesTransactionDetails, GeneratesTransactionBillNumber $generatesTransactionBillNumber) - { - $this->fetchesBooking = $fetchesBooking; - $this->updatesTransactionStatus = $updatesTransactionStatus; - $this->createsTransaction = $createsTransaction; - $this->createsTransactionDetail = $createsTransactionDetail; - $this->updatesTransaction = $updatesTransaction; - $this->deletesTransactionDetails = $deletesTransactionDetails; - $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; - } /** * @return array @@ -59,37 +40,35 @@ class CreatePurchaseOrderTransactionLogic extends AbstractControllerLogic /** @var FetchesBooking */ private $fetchesBooking; - /** @var UpdatesTransactionStatus */ - private $updatesTransactionStatus; - - /** @var CreatesTransaction */ - private $createsTransaction; - - /** @var CreatesTransactionDetail */ - private $createsTransactionDetail; - - /** @var UpdatesTransaction */ - private $updatesTransaction; - - /** @var DeletesTransactionDetails */ - private $deletesTransactionDetails; - /** @var GeneratesTransactionBillNumber */ private $generatesTransactionBillNumber; + /** @var CreatePurchaseOrderTransactionProcessor */ + private $createPurchaseOrderTransactionProcessor; + + /** + * CreatePurchaseOrderTransactionLogic constructor. + * @param FetchesBooking $fetchesBooking + * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber + * @param CreatePurchaseOrderTransactionProcessor $createPurchaseOrderTransactionProcessor + */ + public function __construct(FetchesBooking $fetchesBooking, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatePurchaseOrderTransactionProcessor $createPurchaseOrderTransactionProcessor) + { + $this->fetchesBooking = $fetchesBooking; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + $this->createPurchaseOrderTransactionProcessor = $createPurchaseOrderTransactionProcessor; + } /** * @param Request $request + * @param string $id * @return JsonResponse * @throws \App\Classes\Exceptions\MalformedRequestException */ - public function logic(Request $request) : JsonResponse + public function logic(Request $request, $id = '') : JsonResponse { /** @var Booking $booking */ - $booking = $this->fetchesBooking->execute(['id' => $request->route('id')]); - - /** @var Transaction $transaction */ - $transaction = $booking->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first(); + $booking = $this->fetchesBooking->execute(['id' => $request->route('id') ?? $id]); $billNumber = $this->generatesTransactionBillNumber->execute('PO-'); @@ -102,15 +81,8 @@ class CreatePurchaseOrderTransactionLogic extends AbstractControllerLogic $total, $total, $booking->fix_currency_id, $booking->fix_currency_id, 1, 0, 0, null, ApprovalStatus::PENDING_SUBMISSION, $request->input('products')); - !$transaction ? $transaction = $this->createsTransaction->execute($booking, $object) : $transaction = $this->updatesTransaction->execute($transaction, $object); - $this->updatesTransactionStatus->execute($transaction, (float) number_format($total, 2, '.', '') === (float) number_format((float)$booking->fix_amount, 2, '.', '') ? ApprovalStatus::PENDING_VERIFICATION : ApprovalStatus::PENDING_SUBMISSION); - - $this->deletesTransactionDetails->execute($transaction); - - foreach ($object->getDetails() as $product){ - $this->createsTransactionDetail->execute($transaction, $product); - } + $transaction = $this->createPurchaseOrderTransactionProcessor->execute($booking, $object); return $this->resourceResponse(new TransactionResource($transaction)); diff --git a/app/Classes/Modules/Transactions/ControllersLogic/UpdatePaymentTransactionStatusLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/UpdatePaymentTransactionStatusLogic.php new file mode 100644 index 00000000..11f0a377 --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/UpdatePaymentTransactionStatusLogic.php @@ -0,0 +1,76 @@ + 'Updated Transaction', + 'message' => 'You have successfully updated a transaction' + ]; + } + + /** @var FetchesTransaction */ + private $fetchesTransaction; + + /** @var UpdatesTransactionStatus */ + private $updatesTransactionStatus; + + /** @var DeletesDocument */ + private $deletesDocument; + + /** + * CreatePaymentVerificationDocumentLogic constructor. + * @param FetchesTransaction $fetchesTransaction + * @param UpdatesTransactionStatus $updatesTransactionStatus + * @param DeletesDocument $deletesDocument + */ + public function __construct(FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, DeletesDocument $deletesDocument) + { + $this->fetchesTransaction = $fetchesTransaction; + $this->updatesTransactionStatus = $updatesTransactionStatus; + $this->deletesDocument = $deletesDocument; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + $transaction = $this->fetchesTransaction->execute(['id' => $request->route('id')]); + $status = $request->route('status'); + + $this->updatesTransactionStatus->execute($transaction, $status === 'pending' ? ApprovalStatus::PENDING_VERIFICATION : ApprovalStatus::COMPLETED); + + if ($status == 'pending') { + $document = $transaction->documents()->first(); + if ($document) { + $this->deletesDocument->execute($document); + } + } + + return $this->response([]); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Processors/CreatePurchaseOrderTransactionProcessor.php b/app/Classes/Modules/Transactions/Processors/CreatePurchaseOrderTransactionProcessor.php new file mode 100644 index 00000000..76773c75 --- /dev/null +++ b/app/Classes/Modules/Transactions/Processors/CreatePurchaseOrderTransactionProcessor.php @@ -0,0 +1,76 @@ +updatesTransactionStatus = $updatesTransactionStatus; + $this->createsTransaction = $createsTransaction; + $this->createsTransactionDetail = $createsTransactionDetail; + $this->updatesTransaction = $updatesTransaction; + $this->deletesTransactionDetails = $deletesTransactionDetails; + } + + + /** + * @param Booking $booking + * @param TransactionObject $object + * @return Transaction|\Illuminate\Database\Eloquent\Model + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function execute(Booking $booking, TransactionObject $object){ + /** @var Transaction $transaction */ + $transaction = $booking->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first(); + + !$transaction ? $transaction = $this->createsTransaction->execute($booking, $object) : $transaction = $this->updatesTransaction->execute($transaction, $object); + + $this->updatesTransactionStatus->execute($transaction, (float) number_format($object->getAmount(), 2, '.', '') === (float) number_format((float)$booking->fix_amount, 2, '.', '') ? ApprovalStatus::PENDING_VERIFICATION : ApprovalStatus::PENDING_SUBMISSION); + + $this->deletesTransactionDetails->execute($transaction); + + foreach ($object->getDetails() as $product){ + $this->createsTransactionDetail->execute($transaction, $product); + } + + return $transaction; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Services/GeneratesPurchaseOrderProducts.php b/app/Classes/Modules/Transactions/Services/GeneratesPurchaseOrderProducts.php new file mode 100644 index 00000000..16d162eb --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/GeneratesPurchaseOrderProducts.php @@ -0,0 +1,72 @@ +products = $products; + } + + + public function execute(Transaction $transaction, float $amount){ + + $products = collect(); + + $amountDifference = $amount - $transaction->amount; + $transactionDetails = $transaction->transactionDetails()->select('*', DB::raw('abs(price - '.abs($amountDifference).') as nearest_price'))->orderBy('nearest_price')->get(); + foreach ($transactionDetails as $product) { + $units = floor(abs($amountDifference) / $product->price); + $quantity = $product->quantity; + + if($product->price <= 0){ + $amountDifference = $amountDifference + ($product->price * $product->quantity); + continue; + } + + if($amountDifference > 0){ + $quantity = $product->quantity + $units; + $amountDifference = $amountDifference - ($product->price * $units); + } + + if($amountDifference < 0) { + $units = ceil(abs($amountDifference) / $product->price); + $quantity = $product->quantity - $units; + + if($quantity <= 0){ + $amountDifference = $amountDifference + ($product->price * $product->quantity); + continue; + } + + $amountDifference = $amountDifference + ($product->price * $quantity); + } + + $products->push([ + 'description' => $product->product_name, + 'quantity' => (int) $quantity, + 'stockCode' => $product->product_code, + 'total' => $product->price * $quantity, + 'unit_price' => (float) $product->price, + ]); + + } + + return $products; + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/ControllersLogic/CreditWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/CreditWalletLogic.php new file mode 100644 index 00000000..e2941c3c --- /dev/null +++ b/app/Classes/Modules/Wallets/ControllersLogic/CreditWalletLogic.php @@ -0,0 +1,107 @@ + 'Credit into Company Wallet', + 'message' => 'You have successfully credit company wallet' + ]; + } + + + /** @var FetchesWallet */ + private $fetchesWallet; + + /** @var GeneratesTransactionBillNumber */ + private $generatesTransactionBillNumber; + + /** @var CreatesTransaction */ + private $createsTransaction; + + /** @var UpdatesWallet */ + private $updatesWallet; + + /** + * CreateWalletLogic constructor. + * @param FetchesWallet $fetchesWallet + * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber + * @param CreatesTransaction $createsTransaction + * @param UpdatesWallet $updatesWallet + */ + public function __construct( + FetchesWallet $fetchesWallet, + GeneratesTransactionBillNumber $generatesTransactionBillNumber, + CreatesTransaction $createsTransaction, + UpdatesWallet $updatesWallet + ) + { + $this->fetchesWallet = $fetchesWallet; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + $this->createsTransaction = $createsTransaction; + $this->updatesWallet = $updatesWallet; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + $wallet = $this->fetchesWallet->execute(['id' => $request->input('wallet_id')]); + + $billNumber = $this->generatesTransactionBillNumber->execute('DEBIT-NOTE-'); + + $transaction_object = new TransactionObject( + $billNumber, + TransactionType::CREDIT_NOTE, + 1, + $wallet->company->id, + 1, + PaymentMethodType::WALLET, + $request->input('amount'), + $request->input('amount'), + 1, + 1, + 1, + 0, + 0, + null, + ApprovalStatus::PENDING_SUBMISSION, + [] + ); + + $transaction = $this->createsTransaction->execute($wallet, $transaction_object); + $updateWalletAmount = $wallet->amount + $transaction->amount; + + $walletOject = new WalletObject($wallet->company->id, $wallet->currency_id, $wallet->code, $updateWalletAmount); + + $wallet = $this->updatesWallet->execute($wallet, $walletOject); + + return $this->resourceResponse(new WalletResource($wallet)); + } +} diff --git a/app/Classes/Modules/Wallets/ControllersLogic/DebitWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/DebitWalletLogic.php new file mode 100644 index 00000000..9437b320 --- /dev/null +++ b/app/Classes/Modules/Wallets/ControllersLogic/DebitWalletLogic.php @@ -0,0 +1,107 @@ + 'Debit into Company Wallet', + 'message' => 'You have successfully debit company wallet' + ]; + } + + + /** @var FetchesWallet */ + private $fetchesWallet; + + /** @var GeneratesTransactionBillNumber */ + private $generatesTransactionBillNumber; + + /** @var CreatesTransaction */ + private $createsTransaction; + + /** @var UpdatesWallet */ + private $updatesWallet; + + /** + * CreateWalletLogic constructor. + * @param FetchesWallet $fetchesWallet + * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber + * @param CreatesTransaction $createsTransaction + * @param UpdatesWallet $updatesWallet + */ + public function __construct( + FetchesWallet $fetchesWallet, + GeneratesTransactionBillNumber $generatesTransactionBillNumber, + CreatesTransaction $createsTransaction, + UpdatesWallet $updatesWallet + ) + { + $this->fetchesWallet = $fetchesWallet; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + $this->createsTransaction = $createsTransaction; + $this->updatesWallet = $updatesWallet; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + $wallet = $this->fetchesWallet->execute(['id' => $request->input('wallet_id')]); + + $billNumber = $this->generatesTransactionBillNumber->execute('DEBIT-NOTE-'); + + $transaction_object = new TransactionObject( + $billNumber, + TransactionType::DEBIT_NOTE, + 1, + $wallet->company->id, + 1, + PaymentMethodType::WALLET, + $request->input('amount'), + $request->input('amount'), + 1, + 1, + 1, + 0, + 0, + null, + ApprovalStatus::PENDING_SUBMISSION, + [] + ); + + $transaction = $this->createsTransaction->execute($wallet, $transaction_object); + $updateWalletAmount = $wallet->amount - $transaction->amount; + + $walletOject = new WalletObject($wallet->company->id, $wallet->currency_id, $wallet->code, $updateWalletAmount); + + $wallet = $this->updatesWallet->execute($wallet, $walletOject); + + return $this->resourceResponse(new WalletResource($wallet)); + } +} diff --git a/app/Classes/Modules/Wallets/ControllersLogic/TopUpWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/TopUpWalletLogic.php index 8497ec32..6149d69d 100644 --- a/app/Classes/Modules/Wallets/ControllersLogic/TopUpWalletLogic.php +++ b/app/Classes/Modules/Wallets/ControllersLogic/TopUpWalletLogic.php @@ -3,16 +3,19 @@ namespace App\Classes\Modules\Wallets\ControllersLogic; use App\Classes\General\Abstracts\AbstractControllerLogic; - use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject; -use App\Classes\Modules\Wallets\Services\ListsWallet; -use App\Classes\Modules\Wallets\Services\FetchesWallet; +use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject; +use App\Classes\Modules\Companies\Services\FetchesCompany; +use App\Classes\Modules\Wallets\Services\CreatesWallet; +use App\Classes\Modules\Wallets\Services\GeneratesWalletCode; +use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber; +use App\Classes\Modules\Billplzs\Services\CreatesBillplzBill; +use App\Classes\Modules\Transactions\Services\CreatesTransaction; use App\Classes\ValueObjects\Constants\TransactionType; - -use App\Classes\Modules\Wallets\Standards\Rules\CanTopUpWallet; +use App\Classes\ValueObjects\Constants\PaymentMethodType; +use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Http\Resources\WalletResource; -use App\Classes\Modules\Transactions\Processors\CreateWalletTransactionProcessor; - +use App\Http\Resources\WalletTransactionResource; use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; @@ -30,26 +33,50 @@ class TopUpWalletLogic extends AbstractControllerLogic ]; } - /** @var FetchesWallet */ - private $fetchesWallet; - /** @var CanTopUpWallet */ - private $canTopUpWallet; + /** @var FetchesCompany */ + private $fetchesCompany; - /** @var CreateWalletTransactionProcessor */ - private $createWalletTransactionProcessor; + /** @var GeneratesWalletCode */ + private $generatesWalletCode; + + /** @var CreatesWallet */ + private $createsWallet; + + /** @var GeneratesTransactionBillNumber */ + private $generatesTransactionBillNumber; + + /** @var CreatesWalletTransaction */ + private $createsWalletTransaction; + + /** @var CreatesBillplzBill */ + private $createsBillplzBill; + + /** @var CreatesTransaction */ + private $createsTransaction; /** * CreateWalletLogic constructor. - * @param CreatesWallet $createsWallet + * @param FetchesCompany $fetchesCompany * @param GeneratesWalletCode $generatesWalletCode - * @param CanCreateCompanyWallet $canCreateCompanyWallet + * @param CreatesWallet $createsWallet + * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber */ - public function __construct(CanTopUpWallet $canTopUpWallet, FetchesWallet $fetchesWallet, CreateWalletTransactionProcessor $createWalletTransactionProcessor) + public function __construct( + FetchesCompany $fetchesCompany, + GeneratesWalletCode $generatesWalletCode, + CreatesWallet $createsWallet, + GeneratesTransactionBillNumber $generatesTransactionBillNumber, + CreatesBillplzBill $createsBillplzBill, + CreatesTransaction $createsTransaction + ) { - $this->canTopUpWallet = $canTopUpWallet; - $this->fetchesWallet = $fetchesWallet; - $this->createWalletTransactionProcessor = $createWalletTransactionProcessor; + $this->fetchesCompany = $fetchesCompany; + $this->generatesWalletCode = $generatesWalletCode; + $this->createsWallet = $createsWallet; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + $this->createsBillplzBill = $createsBillplzBill; + $this->createsTransaction = $createsTransaction; } /** @@ -59,14 +86,47 @@ class TopUpWalletLogic extends AbstractControllerLogic */ public function logic(Request $request) : JsonResponse { - $wallet = $this->fetchesWallet->execute(['id' => $request->input('wallet_id')]); + $amount = floatval(str_replace(',', '', $request->input('amount'))); + $company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]); + if (!$company->wallets()->first()) { + $object = new WalletObject($company->id, 1, $this->generatesWalletCode->execute()); + $wallet = $this->createsWallet->execute($object, $company); + } - $walletOject = new WalletObject( $wallet->company->id, $wallet->currency_id, $wallet->code, $request->input('amount')); + $user = $company->employees()->first(); + $billNumber = $this->generatesTransactionBillNumber->execute('TOPUP-'); + + $billPlzBill = $this->createsBillplzBill->execute( + $user->name, + $user->email, + 'This payment is made for wallet topup. ' . $company->reference, + $amount, + $billNumber, + $request->input('bank_code') + ); - $this->canTopUpWallet->passes($walletOject); + $transaction_object = new TransactionObject( + $billNumber, + TransactionType::TOP_UP, + 1, + $company->id, + 1, + PaymentMethodType::PAYMENT_GATEWAY, + $amount, + $amount, + 1, + 1, + 1, + 0, + 0, + null, + ApprovalStatus::PENDING_SUBMISSION, + [], + $billPlzBill->id + ); - $transaction = $this->createWalletTransactionProcessor->execute($wallet, $walletOject, TransactionType::TOP_UP); + $transaction = $this->createsTransaction->execute($company->wallets()->first(), $transaction_object); - return $this->resourceResponse(new WalletResource($wallet)); + return $this->resourceResponse(new WalletTransactionResource($transaction)); } } diff --git a/app/Classes/Modules/Wallets/Services/CreatesWallet.php b/app/Classes/Modules/Wallets/Services/CreatesWallet.php index c114b9de..2a927e6d 100644 --- a/app/Classes/Modules/Wallets/Services/CreatesWallet.php +++ b/app/Classes/Modules/Wallets/Services/CreatesWallet.php @@ -21,8 +21,6 @@ class CreatesWallet extends AbstractUpdateRelationshipRecord $model->code = $object->getCode(); $model->currency_id = $object->getCurrency(); - return $this->handler($company->wallets(), $model); - } } diff --git a/app/Classes/ValueObjects/Constants/TransactionType.php b/app/Classes/ValueObjects/Constants/TransactionType.php index 698abd76..040f63fa 100644 --- a/app/Classes/ValueObjects/Constants/TransactionType.php +++ b/app/Classes/ValueObjects/Constants/TransactionType.php @@ -24,5 +24,7 @@ final class TransactionType { public const CREDIT_NOTE = 9; + public const DEBIT_NOTE = 11; + public const WITHDRAW = 10; } diff --git a/app/Http/Controllers/Bookings/AutoPurchaseOrderFillController.php b/app/Http/Controllers/Bookings/AutoPurchaseOrderFillController.php new file mode 100644 index 00000000..c92900bd --- /dev/null +++ b/app/Http/Controllers/Bookings/AutoPurchaseOrderFillController.php @@ -0,0 +1,25 @@ +login(User::find(1)); + return $logic->execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Transactions/UpdatePaymentTransactionStatusController.php b/app/Http/Controllers/Transactions/UpdatePaymentTransactionStatusController.php new file mode 100644 index 00000000..047bc1dc --- /dev/null +++ b/app/Http/Controllers/Transactions/UpdatePaymentTransactionStatusController.php @@ -0,0 +1,14 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Wallets/CreditWalletController.php b/app/Http/Controllers/Wallets/CreditWalletController.php new file mode 100644 index 00000000..b3143588 --- /dev/null +++ b/app/Http/Controllers/Wallets/CreditWalletController.php @@ -0,0 +1,15 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Wallets/DebitWalletController.php b/app/Http/Controllers/Wallets/DebitWalletController.php new file mode 100644 index 00000000..7feafb39 --- /dev/null +++ b/app/Http/Controllers/Wallets/DebitWalletController.php @@ -0,0 +1,15 @@ +execute($request); + } +} diff --git a/app/Http/Resources/CompanyResource.php b/app/Http/Resources/CompanyResource.php index 54ab047d..5488df0e 100644 --- a/app/Http/Resources/CompanyResource.php +++ b/app/Http/Resources/CompanyResource.php @@ -60,10 +60,8 @@ class CompanyResource extends JsonResource $segment = SegmentConstant::where('reference', SegmentConstants::SUPPLIER_CURRENCIES)->where('detail->id', $this->id)->first(); return $segment ? CurrencyResource::collection(Currency::whereIn('id', $segment->detail->currencies)->get()) : []; }), + 'wallet' => WalletResource::collection($this->wallets), 'created_at' => $this->created_at->format('d-m-Y') - - ]; - } } diff --git a/app/Http/Resources/TransactionResource.php b/app/Http/Resources/TransactionResource.php index 58175802..6de5d391 100644 --- a/app/Http/Resources/TransactionResource.php +++ b/app/Http/Resources/TransactionResource.php @@ -43,7 +43,11 @@ class TransactionResource extends JsonResource })), 'expires_on' => Carbon::parse($this->expires_on)->format('d-m-Y h:i:s A'), - 'updated_at' => Carbon::parse($this->updated_at)->format('d-m-Y h:i:s A') + 'updated_at' => Carbon::parse($this->updated_at)->format('d-m-Y h:i:s A'), + 'interval' => [ + 'value' => (Carbon::parse($this->created_at)->addDays(3)->gt(Carbon::now()) ) ? '+' : '-' , + 'duration' => Carbon::parse($this->created_at)->addDays(3)->diff(Carbon::now())->format('%d'), + ], ]; } } diff --git a/app/Http/Resources/WalletResource.php b/app/Http/Resources/WalletResource.php index 37ff5dbd..39c634eb 100644 --- a/app/Http/Resources/WalletResource.php +++ b/app/Http/Resources/WalletResource.php @@ -2,6 +2,7 @@ namespace App\Http\Resources; +use App\Classes\ValueObjects\Constants\TransactionType; use Illuminate\Http\Resources\Json\JsonResource; class WalletResource extends JsonResource @@ -19,7 +20,17 @@ class WalletResource extends JsonResource 'code' => $this->code, 'currency_id' => $this->currency_id, 'amount' => (double) $this->amount, - 'company_id' => (int) $this->company_id + 'company_id' => (int) $this->owner->id, + 'transactions' => $this->transactions()->orderBy('id', 'DESC')->get(), + 'topup_transactions' => $this->transactions()->where('type', TransactionType::TOP_UP)->orderBy('id', 'DESC')->get(), + + // 'transaction' => $this->whenLoaded('transactions', function() { + // return [ + // 'topup' => $this->transactions + // ]; + // }), + // 'transaction' // all + // 'top_transaction' // only topup ]; } } diff --git a/app/Http/Resources/WalletTransactionResource.php b/app/Http/Resources/WalletTransactionResource.php index 1d0037fe..af634f3b 100644 --- a/app/Http/Resources/WalletTransactionResource.php +++ b/app/Http/Resources/WalletTransactionResource.php @@ -23,7 +23,8 @@ class WalletTransactionResource extends JsonResource 'currency_id' => (int) $this->currency_id, 'original_amount' => (double) $this->original_amount, 'original_currency_id' => (int) $this->original_currency_id, - 'currency_rate' => (double) $this->currency_rate + 'currency_rate' => (double) $this->currency_rate, + 'reference' => $this->payment_reference ]; } } diff --git a/app/Models/Wallet.php b/app/Models/Wallet.php index 52d8f718..29c3ddc9 100644 --- a/app/Models/Wallet.php +++ b/app/Models/Wallet.php @@ -2,13 +2,14 @@ namespace App\Models; +use App\Classes\General\Interfaces\Transactionable; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\MorphTo; use Illuminate\Database\Eloquent\SoftDeletes; use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\MorphMany; -class Wallet extends AbstractModel +class Wallet extends AbstractModel implements Transactionable { use SoftDeletes; diff --git a/resources/assets/vue/components/accounts/forms/TopUpAccountComponent.vue b/resources/assets/vue/components/accounts/forms/TopUpAccountComponent.vue deleted file mode 100644 index af8a43b7..00000000 --- a/resources/assets/vue/components/accounts/forms/TopUpAccountComponent.vue +++ /dev/null @@ -1,196 +0,0 @@ - - \ No newline at end of file diff --git a/resources/assets/vue/components/bookings/elements/PaymentProofComponent.vue b/resources/assets/vue/components/bookings/elements/PaymentProofComponent.vue index 494427cb..e197ab6a 100644 --- a/resources/assets/vue/components/bookings/elements/PaymentProofComponent.vue +++ b/resources/assets/vue/components/bookings/elements/PaymentProofComponent.vue @@ -41,6 +41,14 @@ +
+
+ Cancel this order? +
+
+ + + @@ -61,6 +69,20 @@ +
+ + + + + + + + +
diff --git a/resources/assets/vue/components/bookings/elements/PaymentVerificationComponent.vue b/resources/assets/vue/components/bookings/elements/PaymentVerificationComponent.vue index 9acdab65..24dcaea0 100644 --- a/resources/assets/vue/components/bookings/elements/PaymentVerificationComponent.vue +++ b/resources/assets/vue/components/bookings/elements/PaymentVerificationComponent.vue @@ -68,6 +68,14 @@ {{item.original_currency.short_code}} {{(Math.round((item.original_amount + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}} +
+
Service
+
+ {{item.booking.service.name}} +
+
+ +
+
+
Service
+
+ {{item.booking.service.name}} +
+
@@ -60,12 +66,20 @@ {{item.original_currency.short_code}}
-
+
Amount
{{(Math.round((item.original_amount + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}}
+
+
timer
+
+ {{item.interval.value}} + {{item.interval.duration}} + days +
+
diff --git a/resources/assets/vue/components/bookings/forms/ApprovePaymentTransactionFormComponent.vue b/resources/assets/vue/components/bookings/forms/ApprovePaymentTransactionFormComponent.vue new file mode 100644 index 00000000..7be579f2 --- /dev/null +++ b/resources/assets/vue/components/bookings/forms/ApprovePaymentTransactionFormComponent.vue @@ -0,0 +1,33 @@ + + \ No newline at end of file diff --git a/resources/assets/vue/components/bookings/forms/BookingPaymentQuotationComponent.vue b/resources/assets/vue/components/bookings/forms/BookingPaymentQuotationComponent.vue index acec8d4b..0c2ce14f 100644 --- a/resources/assets/vue/components/bookings/forms/BookingPaymentQuotationComponent.vue +++ b/resources/assets/vue/components/bookings/forms/BookingPaymentQuotationComponent.vue @@ -215,6 +215,21 @@ +
+
+
+
+ +
+

Wallet

+
+
+
+ +
@@ -228,11 +243,9 @@
-
-
-
+
Cancel
- - +
@@ -482,13 +494,12 @@ }, methods: { updatePaymentType(payment){ - this.paymentMethod = { name: payment.name, id: payment.id, status: false, } - + this.error = ''; }, selectOnlinePaymentBank(bankCode){ this.onlinePayment = { @@ -503,6 +514,13 @@ amount: this.amount }; + if (this.parameters.payment_method == 'wallet') { + if (!this.data.company.wallet.length || this.data.company.wallet[0].amount < this.parameters.amount) { + this.error = 'Insufficient wallet balance. Please Top up your wallet.'; + return; + } + } + this.submit(route('api.booking.payment.quotation', this.item.id), 'post', this.section, false, false) this.calculation = null; }, diff --git a/resources/assets/vue/components/bookings/forms/DeleteTransactionFormComponent.vue b/resources/assets/vue/components/bookings/forms/DeleteTransactionFormComponent.vue new file mode 100644 index 00000000..8ba13dba --- /dev/null +++ b/resources/assets/vue/components/bookings/forms/DeleteTransactionFormComponent.vue @@ -0,0 +1,33 @@ + + \ No newline at end of file diff --git a/resources/assets/vue/components/bookings/forms/RejectPaymentTransactionFormComponent.vue b/resources/assets/vue/components/bookings/forms/RejectPaymentTransactionFormComponent.vue new file mode 100644 index 00000000..ad43890c --- /dev/null +++ b/resources/assets/vue/components/bookings/forms/RejectPaymentTransactionFormComponent.vue @@ -0,0 +1,33 @@ + + \ No newline at end of file diff --git a/resources/assets/vue/components/bookings/sections/BookingDetailsSectionComponent.vue b/resources/assets/vue/components/bookings/sections/BookingDetailsSectionComponent.vue index edd9e114..fbc2f516 100644 --- a/resources/assets/vue/components/bookings/sections/BookingDetailsSectionComponent.vue +++ b/resources/assets/vue/components/bookings/sections/BookingDetailsSectionComponent.vue @@ -353,6 +353,7 @@
+
diff --git a/resources/assets/vue/components/bookings/sections/SupplierPendingOrdersSectionComponent.vue b/resources/assets/vue/components/bookings/sections/SupplierPendingOrdersSectionComponent.vue index 81e17c37..23e3116f 100644 --- a/resources/assets/vue/components/bookings/sections/SupplierPendingOrdersSectionComponent.vue +++ b/resources/assets/vue/components/bookings/sections/SupplierPendingOrdersSectionComponent.vue @@ -8,30 +8,30 @@
-
-
+
+
-
- {{selectedSupplier.name}} +
+ {{selectedService.name}}
-
+
- +
-
+
-
-
+
+
-
{{supplier.name}}
+
{{service.name}}
@@ -41,7 +41,7 @@
-
+
@@ -75,11 +75,46 @@
+
+
+
+
+
+ {{selectedSupplier.name}} +
+
+
+
+ +
+
+
+
+
+
+
+
+
+
+
+
+
+
{{supplier.name}}
+
+
+
+
+
+
+
+
+
+
- + @@ -124,6 +159,14 @@ currencyDropdownLaunch: { status: false }, + serviceDropdownLaunch: { + status: false + }, + selectedService: { + id: 1, + name: '', + status: false + }, payments: [] } }, @@ -135,6 +178,7 @@ this.suppliers = response.payload.data; this.updateSupplier(this.suppliers[0]); this.updateCurrency(this.suppliers[0].currencies[0]); + this.updateService(this.suppliers[0].services[0]); }, updateSupplier(supplier){ this.selectedSupplier = supplier; @@ -151,6 +195,10 @@ this.payments = []; }, + updateService(service){ + this.selectedService = service; + this.serviceDropdownLaunch.status = false; + }, updateOrder(payment){ this.payments.includes(payment) ? this.payments.splice(this.payments.indexOf(payment), 1) : this.payments.push(payment); } diff --git a/resources/assets/vue/components/companies/sections/CustomerProfileSectionComponent.vue b/resources/assets/vue/components/companies/sections/CustomerProfileSectionComponent.vue index 09876b9b..50ecbacd 100644 --- a/resources/assets/vue/components/companies/sections/CustomerProfileSectionComponent.vue +++ b/resources/assets/vue/components/companies/sections/CustomerProfileSectionComponent.vue @@ -138,7 +138,12 @@
-
+
+
+
+ +
+
diff --git a/resources/assets/vue/components/companies/sections/customerDashboardSectionComponent.vue b/resources/assets/vue/components/companies/sections/customerDashboardSectionComponent.vue index a67c333f..73099881 100644 --- a/resources/assets/vue/components/companies/sections/customerDashboardSectionComponent.vue +++ b/resources/assets/vue/components/companies/sections/customerDashboardSectionComponent.vue @@ -570,8 +570,8 @@
- + +
diff --git a/resources/assets/vue/components/wallets/elements/CustomerTransactionSectionComponent.vue b/resources/assets/vue/components/wallets/elements/CustomerTransactionSectionComponent.vue new file mode 100644 index 00000000..b94036db --- /dev/null +++ b/resources/assets/vue/components/wallets/elements/CustomerTransactionSectionComponent.vue @@ -0,0 +1,140 @@ + + diff --git a/resources/assets/vue/components/wallets/elements/WalletComponent.vue b/resources/assets/vue/components/wallets/elements/WalletComponent.vue new file mode 100644 index 00000000..92b2e275 --- /dev/null +++ b/resources/assets/vue/components/wallets/elements/WalletComponent.vue @@ -0,0 +1,66 @@ + + + \ No newline at end of file diff --git a/resources/assets/vue/components/wallets/elements/WalletTopUpHistoryComponent.vue b/resources/assets/vue/components/wallets/elements/WalletTopUpHistoryComponent.vue new file mode 100644 index 00000000..ff392682 --- /dev/null +++ b/resources/assets/vue/components/wallets/elements/WalletTopUpHistoryComponent.vue @@ -0,0 +1,75 @@ + + + diff --git a/resources/assets/vue/components/wallets/elements/WalletsComponent.vue b/resources/assets/vue/components/wallets/elements/WalletsComponent.vue new file mode 100644 index 00000000..8f0daa9c --- /dev/null +++ b/resources/assets/vue/components/wallets/elements/WalletsComponent.vue @@ -0,0 +1,178 @@ + + + diff --git a/resources/assets/vue/components/wallets/forms/WalletTopUpFormComponent.vue b/resources/assets/vue/components/wallets/forms/WalletTopUpFormComponent.vue new file mode 100644 index 00000000..6540c406 --- /dev/null +++ b/resources/assets/vue/components/wallets/forms/WalletTopUpFormComponent.vue @@ -0,0 +1,66 @@ + + + \ No newline at end of file diff --git a/resources/views/pages/wallet/index.blade.php b/resources/views/pages/wallet/index.blade.php new file mode 100644 index 00000000..7a9b49ef --- /dev/null +++ b/resources/views/pages/wallet/index.blade.php @@ -0,0 +1,4 @@ +@extends('layouts.base_portal') +@section('inner_content') + @include('pages.wallet.transactions') +@endsection diff --git a/resources/views/pages/wallet/transactions.blade.php b/resources/views/pages/wallet/transactions.blade.php new file mode 100644 index 00000000..ce31dec6 --- /dev/null +++ b/resources/views/pages/wallet/transactions.blade.php @@ -0,0 +1,5 @@ +
+
+ +
+
\ No newline at end of file diff --git a/resources/views/pages/wallet/wallets.blade.php b/resources/views/pages/wallet/wallets.blade.php new file mode 100644 index 00000000..1a876a4f --- /dev/null +++ b/resources/views/pages/wallet/wallets.blade.php @@ -0,0 +1,54 @@ + +@extends('layouts.base_portal') +@section('inner_content') +
+
+ +
+
+
+
+
Transaction History
+
+
+ +
+
Date
+
Description
+
Incoming
+
Outgoing
+
Balance
+
+ +
+
25/11/2015
+
Payment to bill #121221121
+
+
- 2,123
+
12,123
+
+ +
+
115/11/2015
+
Top Up
+
1,234
+
+
14,246
+
+
+
+
+
+
+
+
Top Up Records
+
+
+ +
+
+
+
+
+
+@endsection \ No newline at end of file diff --git a/resources/views/partials/header.blade.php b/resources/views/partials/header.blade.php index c8535af9..edd7c858 100644 --- a/resources/views/partials/header.blade.php +++ b/resources/views/partials/header.blade.php @@ -48,6 +48,11 @@
customers
+ @@ -64,14 +69,6 @@
-
-
-
-
MYR 0.00
-
- -
-
diff --git a/resources/views/partials/menu.blade.php b/resources/views/partials/menu.blade.php index 727a1fe4..40d5ff80 100644 --- a/resources/views/partials/menu.blade.php +++ b/resources/views/partials/menu.blade.php @@ -1,6 +1,6 @@
-
+
diff --git a/routes/booking.php b/routes/booking.php index 44767438..d83bb4af 100644 --- a/routes/booking.php +++ b/routes/booking.php @@ -31,4 +31,5 @@ Route::group(['prefix' => 'booking', 'as' => 'booking.', 'namespace' => 'Booking Route::post('/merge', 'MergeBookingController@merge')->name('merge'); Route::post('{id}/proforma/create', 'CreateProformaInvoiceTransaction@create')->name('proforma.create'); + }); \ No newline at end of file diff --git a/routes/transaction.php b/routes/transaction.php index 17502743..578b02c2 100644 --- a/routes/transaction.php +++ b/routes/transaction.php @@ -10,6 +10,8 @@ Route::group(['prefix' => 'transactions', 'namespace' => 'Transactions', 'as' => route::post('/supplier/{id}/bill/create', 'CreateSupplierTransactionController@create')->name('supplier.create'); route::post('{id}/bill/verification', 'CreatePaymentProofDocumentController@verify')->name('bill.verification'); route::post('{id}/bill/pay', 'CreatePaymentProofDocumentController@pay')->name('bill.pay'); + Route::put('/{id}/bill/{status}', 'UpdatePaymentTransactionStatusController@update')->where('status', 'pending|complete')->name('bill.status'); + route::delete('{id}/bill/delete', 'DeletePaymentProofDocumentController@delete')->name('bill.delete'); Route::post('booking/{id}/details/update', 'CreatePurchaseOrderTransactionController@create')->name('po.create'); diff --git a/routes/wallet.php b/routes/wallet.php index 7ad2a479..80290c52 100644 --- a/routes/wallet.php +++ b/routes/wallet.php @@ -5,8 +5,10 @@ use Illuminate\Support\Facades\Route; Route::group(['prefix' => 'wallets', 'namespace' => 'Wallets', 'as' => 'wallet.'], function () { Route::get('/', 'ListWalletController@list')->name('list'); Route::post('/create', 'CreateWalletController@create')->name('create'); - Route::post('/topup', 'TopUpWalletController@topUp')->name('topup'); - Route::post('/withdraw', 'WithdrawWalletController@withdraw')->name('withdraw'); - Route::put('/{transaction_id}/update-status/{status}', 'UpdateStatusWalletController@updateStatus')->where('status', 'approve|reject')->name('approval'); + Route::post('/topup', 'TopUpWalletController@topUp')->name('topup'); // user + Route::post('/debit', 'DebitWalletController@debit')->name('debit'); //admin - + Route::post('/credit', 'CreditWalletController@credit')->name('credit'); // admin + + + Route::put('/{transaction_id}/update-status/{status}', 'UpdateStatusWalletController@updateStatus')->where('status', 'approve|reject')->name('approval'); }); diff --git a/routes/web.php b/routes/web.php index 089d7f36..77026a89 100644 --- a/routes/web.php +++ b/routes/web.php @@ -93,4 +93,54 @@ Route::get('/products', function (\App\Classes\Modules\Exports\Services\ExportsP // $bookings = Booking::whereIn('id', [10391, 10275, 10109, 10108, 10070, 10066, 10063, 9801, 9166, 8895, 8790, 8544, 8264, 6957, 5409, 4717])->with('transactions')->pluck('marking'); // dd($bookings); // -//})->name('x2.data'); \ No newline at end of file +//})->name('x2.data'); +Route::get('/wallet/{id}/details', function ($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('/test', function(){ + +// Auth::login(User::findOrFail(1)); +// try { +// $zip_file = 'cief_jun_to_september_delivery_orders.zip'; // Name of our archive to download +// $zip = new ZipArchive(); +// if ($zip->open(storage_path().'/'.$zip_file, \ZipArchive::CREATE | \ZipArchive::OVERWRITE) === TRUE) { +// +// //whereMonth('created_at', 5)->whereYear('created_at', 2021)-> +// $bookings = \App\Models\Booking::where('status', \App\Classes\ValueObjects\Constants\ApprovalStatus::COMPLETED)->get(); +// +// foreach ($bookings as $booking) { +// $file = $booking->documents()->where('document_type', \App\Classes\ValueObjects\Constants\DocumentType::SUPPLIER_DELIVER_ORDER)->first()->files()->first(); +// if (! $zip->addFile(Storage::disk('documents')->path($file->file->file_info->original->file), Carbon::now()->format('d_m_Y').'_'.$booking->marking.'.pdf')) { +// echo 'Could not add file to ZIP: ' . $file; +// } +// } +// +// // Close ZipArchive +// $zip->close(); +// } else { +// echo 'Could not open ZIP file.'; +// } +// } catch (Exception $exception) { +// dd($exception); +// } + + +}); +Route::get('/bookings/billplz', function () { + return view('pages.billplz_redirect'); +})->name('bookings.billplz'); + + +Route::get('/export/customers/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@export'); +Route::get('/export/transactions/f614e339d7058904a831aad742e24d55', 'Exports\ExportCustomersToExcelController@transactions'); + +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('/auto-purchase-order-fill', 'Bookings\AutoPurchaseOrderFillController@auto')->name('assign');