diff --git a/app/Classes/General/Interfaces/Notifiable.php b/app/Classes/General/Interfaces/Notifiable.php new file mode 100644 index 00000000..e9d8f22d --- /dev/null +++ b/app/Classes/General/Interfaces/Notifiable.php @@ -0,0 +1,15 @@ +updatesWalletBalance->execute($wallet, ($amount * -1)); - - $cash_back_transaction = $this->createCashBackTransactionProcessor->execute($transaction); } $billNumber = $this->generatesTransactionBillNumber->execute('PYMT-'); @@ -153,6 +151,7 @@ class CreateBookingPaymentLogic extends AbstractControllerLogic /** @var Transaction $transaction */ $transaction = $this->createsTransaction->execute($booking, $object); + $cash_back_transaction = $this->createCashBackTransactionProcessor->execute($transaction); if(PaymentMethodType::PAYMENT_METHODS[$request->input('payment_method')] == PaymentMethodType::WALLET){ $this->updatesTransactionStatus->execute($transaction, ApprovalStatus::APPROVED); diff --git a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php index 74e92fa6..d31ee2ce 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php @@ -84,12 +84,14 @@ class CreateBookingRefundLogic extends AbstractControllerLogic $billNumber = $this->generatesTransactionBillNumber->execute('RFD-'); - $refund = $transaction->transactions()->refunds()->sum('amount'); if($refund + $request->input('amount') > $transaction->original_amount) throw new MalformedRequestException('Your refund must not be greater than '. $transaction->original_amount .'.'); - $transactionRefundCalculationObject = new TransactionRefundCalculationObject($booking, $transaction, $request->input('amount')); + $amount = $transaction->booking->fix_currency_id == 1 ? $request->input('amount') : $request->input('amount') / $transaction->currency_rate; + + + $transactionRefundCalculationObject = new TransactionRefundCalculationObject($booking, $transaction, $amount); $transactionRefundCalculationObject->init(); $object = new TransactionObject($billNumber, TransactionType::REFUND, 1, $booking->company->id, diff --git a/app/Classes/Modules/Bookings/ControllersLogic/DownloadBookingDocumentLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/DownloadBookingDocumentLogic.php index d8fdb0df..ff9427fe 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/DownloadBookingDocumentLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/DownloadBookingDocumentLogic.php @@ -14,6 +14,7 @@ use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Storage; use App\Classes\Exceptions\MalformedRequestException; use App\Classes\ValueObjects\Constants\ApprovalStatus; +use App\Classes\ValueObjects\Constants\DocumentType; class DownloadBookingDocumentLogic { @@ -26,9 +27,9 @@ class DownloadBookingDocumentLogic */ public function execute(Request $request) { - Auth::login(User::findOrFail(1)); - $zip_file = $request->input('type').'.zip'; + $document_type = str_replace(' ', '', $request->input('type')); + $zip_file = $document_type.'.zip'; $attachment = storage_path().'/app/documents/collections/' . $zip_file; $zip = new ZipArchive(); @@ -36,19 +37,42 @@ class DownloadBookingDocumentLogic $bookings = Booking::where('status', ApprovalStatus::COMPLETED) ->whereDate('created_at', '>=', Carbon::parse($request->input('startDate'))) - ->whereDate('created_at', '<=', Carbon::parse($request->input('endDate')))->whereHas('transactions', function ($query) use ($request){ + ->whereDate('created_at', '<=', Carbon::parse($request->input('endDate'))) + ->whereHas('transactions', function ($query) use ($request){ return $query->where('type', TransactionType::PAYMENT)->whereHas('transactions', function ($query) use ($request){ return $query->where('type', TransactionType::BILL)->where('issuer', $request->input('supplier')); }); })->get(); - if (!count($bookings)) throw new MalformedRequestException('No available file to download'); - foreach ($bookings as $booking) { - $file = $booking->documents()->where('document_type', $request->input('type'))->first()->files()->first(); - $zip->addFile(Storage::disk('documents')->path($file->file->file_info->original->file), $booking->created_at->format('d_m_Y') . '_' . $booking->marking . '.pdf'); + if (!count($bookings)) { + return response()->json(['no file to download']); } + foreach ($bookings as $booking) { + + if ($document_type == 'INVOICEPODO' || $document_type == 'INVOICEPODOSDO') { + $invoice_file = $booking->documents()->where('document_type', DocumentType::INVOICE)->first()->files()->first(); + $purchase_file = $booking->documents()->where('document_type', DocumentType::PURCHASE_ORDER)->first()->files()->first(); + $deliver_file = $booking->documents()->where('document_type', DocumentType::DELIVER_ORDER)->first()->files()->first(); + if ($document_type == 'INVOICEPODOSDO') { + $supplier_deliver_order_file = $booking->documents()->where('document_type', DocumentType::SUPPLIER_DELIVER_ORDER)->first()->files()->first(); + } + + $zip->addFile(Storage::disk('documents')->path($invoice_file->file->file_info->original->file), 'invoice-' . $booking->created_at->format('d_m_Y') . '_' . $booking->marking . '.pdf'); + + $zip->addFile(Storage::disk('documents')->path($purchase_file->file->file_info->original->file), 'purchase-order-' . $booking->created_at->format('d_m_Y') . '_' . $booking->marking . '.pdf'); + + $zip->addFile(Storage::disk('documents')->path($deliver_file->file->file_info->original->file), 'deliver-' . $booking->created_at->format('d_m_Y') . '_' . $booking->marking . '.pdf'); + + $zip->addFile(Storage::disk('documents')->path($supplier_deliver_order_file->file->file_info->original->file), 'supplier-deliver-order-' . $booking->created_at->format('d_m_Y') . '_' . $booking->marking . '.pdf'); + } + else { + $file = $booking->documents()->where('document_type', $document_type)->first()->files()->first(); + $zip->addFile(Storage::disk('documents')->path($file->file->file_info->original->file), $booking->created_at->format('d_m_Y') . '_' . $booking->marking . '.pdf'); + } + + } $zip->close(); while (ob_get_level()) { ob_end_clean(); diff --git a/app/Classes/Modules/Companies/ControllersLogic/ApproveIdentificationDocumentLogic.php b/app/Classes/Modules/Companies/ControllersLogic/ApproveIdentificationDocumentLogic.php index d5e052a9..cf894bfd 100644 --- a/app/Classes/Modules/Companies/ControllersLogic/ApproveIdentificationDocumentLogic.php +++ b/app/Classes/Modules/Companies/ControllersLogic/ApproveIdentificationDocumentLogic.php @@ -13,6 +13,9 @@ use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Documents\Services\FetchesDocument; use App\Classes\Modules\Documents\Services\ApprovesDocument; +use App\Classes\Modules\Notifications\DataTransferObjects\NotificationObject; +Use App\Classes\Modules\Notifications\Processors\CreateNotificationProcessor; +use App\Classes\General\Interfaces\Notifiable; use App\Models\Document; use Illuminate\Http\JsonResponse; @@ -46,6 +49,9 @@ class ApproveIdentificationDocumentLogic extends AbstractControllerLogic /** @var UpdatesCompanyStatus */ private $updatesCompanyStatus; + /** @var CreateNotificationProcessor */ + private $createNotificationProcessor; + /** * ApproveIdentificationDocumentLogic constructor. * @param CanApproveDocument $canApproveDocument @@ -53,14 +59,16 @@ class ApproveIdentificationDocumentLogic extends AbstractControllerLogic * @param RejectsDocument $rejectsDocument * @param FetchesDocument $fetchesDocument * @param UpdatesCompanyStatus $updatesCompanyStatus + * @param CreateNotificationProcessor $createNotificationProcessor */ - public function __construct(CanApproveDocument $canApproveDocument, ApprovesDocument $approvesDocument, RejectsDocument $rejectsDocument, FetchesDocument $fetchesDocument, UpdatesCompanyStatus $updatesCompanyStatus) + public function __construct(CanApproveDocument $canApproveDocument, ApprovesDocument $approvesDocument, RejectsDocument $rejectsDocument, FetchesDocument $fetchesDocument, UpdatesCompanyStatus $updatesCompanyStatus, CreateNotificationProcessor $createNotificationProcessor) { $this->canApproveDocument = $canApproveDocument; $this->approvesDocument = $approvesDocument; $this->rejectsDocument = $rejectsDocument; $this->fetchesDocument = $fetchesDocument; $this->updatesCompanyStatus = $updatesCompanyStatus; + $this->createNotificationProcessor = $createNotificationProcessor; } /** @@ -84,6 +92,16 @@ class ApproveIdentificationDocumentLogic extends AbstractControllerLogic $this->updatesCompanyStatus->execute($document->owner, $status === 'approve' ? ApprovalStatus::APPROVED : ApprovalStatus::REJECTED); + $object = new NotificationObject( + 'ID Verification ' . ( $status === 'approve' ? 'Approved' : 'Rejected' ), + ( $status === 'approve' ? 'Dear user, congratulations that your ' : 'Dear user, we are sorry to inform you that your ' ) . ( $document->type === 'IDENTITY_CARD' ? 'IC' : 'SSM' ) . ( $status === 'approve' ? ' has been approved. Start your first order now!' : ' has been rejected due to ' . ( $request->input('rejectRemark') ?? '' ) . ', please resubmit it for further action.' ), + $document->owner, + $document->owner->employees()->first(), + $document, + ); + + $this->createNotificationProcessor->execute($object); + return $this->resourceResponse(new DocumentResource($document)); } diff --git a/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyStatusLogic.php b/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyStatusLogic.php new file mode 100644 index 00000000..92278bef --- /dev/null +++ b/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyStatusLogic.php @@ -0,0 +1,62 @@ + 'Update Company Account Status', + 'message' => 'You have successfully updated the Company Account Status' + ]; + } + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** @var UpdatesCompanyStatus */ + private $updatesCompanyStatus; + + /** + * UpdateCompanyStatusLogic constructor. + * @param FetchesCompany $fetchesCompany + * @param UpdatesCompanyStatus $updatesCompanyStatus + */ + public function __construct( + FetchesCompany $fetchesCompany, + UpdatesCompanyStatus $updatesCompanyStatus + ) + { + $this->fetchesCompany = $fetchesCompany; + $this->updatesCompanyStatus = $updatesCompanyStatus; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + $company = $this->fetchesCompany->execute(['id' => $request->route('id')]); + + $company_query = $this->updatesCompanyStatus->execute($company, $request->input('status')); + + return $this->resourceResponse(new CompanyResource($company_query)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/Processors/CreateCompanyProcessor.php b/app/Classes/Modules/Companies/Processors/CreateCompanyProcessor.php index fc84e9cc..ad9abeb8 100644 --- a/app/Classes/Modules/Companies/Processors/CreateCompanyProcessor.php +++ b/app/Classes/Modules/Companies/Processors/CreateCompanyProcessor.php @@ -46,9 +46,10 @@ class CreateCompanyProcessor public function execute(Request $request, int $businessType = BusinessType::IMPORTER, ?int $companyType = CompanyType::COMPANY_BUSINESS, ?int $status = ApprovalStatus::PENDING_SUBMISSION): Model { $companyName = $companyType === CompanyType::COMPANY_BUSINESS ? $request->input('company_name') : $request->input('name'); + $companyReference = $request->input('company_reference') ? $request->input('company_reference') : mt_rand(1000, 9999).(new GeneratesInitials())->name($companyName)->length(3)->generate(); $company_object = new CompanyObject( $companyName, - mt_rand(1000, 9999).(new GeneratesInitials())->name($companyName)->length(3)->generate(), + $companyReference, $businessType, $companyType, $status); $this->canCreateCompany->passes($company_object); diff --git a/app/Classes/Modules/Exports/Services/ExportsBookingTransactions.php b/app/Classes/Modules/Exports/Services/ExportsBookingTransactions.php new file mode 100644 index 00000000..aed106ea --- /dev/null +++ b/app/Classes/Modules/Exports/Services/ExportsBookingTransactions.php @@ -0,0 +1,74 @@ +request = $request; + } + + public function headings(): array + { + return [ + 'Ref No', + 'Creted Date', + 'Amount', + 'Rate', + 'Supplier' + ]; + } + + /** + * @return \Illuminate\Support\Collection|mixed + */ + public function query() + { + $supplierIds = array_map(function($value){ + return ['id' => $value]; + }, json_decode($this->request->input('supplierIds'))); + + $dateFrom =Carbon::parse($this->request->input('startDate'))->format('Y-m-d'); + $dateTo =Carbon::parse($this->request->input('endDate'))->format('Y-m-d'); + + return Transaction::where('type', 3)->whereIn('issuer', $supplierIds)->whereBetween('created_at', [$dateFrom, $dateTo]); + } + + /** + * @param $transaction + * @return array + */ + public function map($transaction): array + { + $supplierName = Company::where('id', $transaction->issuer)->get()->first()->name; + $refNo = $transaction->owner->owner == null ? $transaction->owner->marking : $transaction->owner->owner->marking; + + $createdAt = $transaction->created_at->format('d-m-Y'); + $amount = $transaction->amount; + $rate = $transaction->currency_rate; + + return [ + $refNo, + $createdAt, + $amount, + $rate, + $supplierName + ]; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Exports/Services/ExportsTransactions.php b/app/Classes/Modules/Exports/Services/ExportsTransactions.php index 910fb79b..013286d1 100644 --- a/app/Classes/Modules/Exports/Services/ExportsTransactions.php +++ b/app/Classes/Modules/Exports/Services/ExportsTransactions.php @@ -13,8 +13,9 @@ use Maatwebsite\Excel\Concerns\Exportable; use Maatwebsite\Excel\Concerns\FromQuery; use Maatwebsite\Excel\Concerns\WithHeadingRow; use Maatwebsite\Excel\Concerns\WithMapping; +use Maatwebsite\Excel\Concerns\ShouldAutoSize; -class ExportsTransactions implements FromQuery, WithHeadingRow, WithMapping +class ExportsTransactions implements FromQuery, WithHeadingRow, WithMapping, ShouldAutoSize { use Exportable; @@ -80,6 +81,7 @@ class ExportsTransactions implements FromQuery, WithHeadingRow, WithMapping $transactionStatus[$transaction->status], \PhpOffice\PhpSpreadsheet\Shared\Date::dateTimeToExcel($transaction->created_at), \PhpOffice\PhpSpreadsheet\Shared\Date::dateTimeToExcel($transaction->updated_at), + $marking ]; } } \ No newline at end of file diff --git a/app/Classes/Modules/Notifications/ControllersLogic/ListNotificationsLogic.php b/app/Classes/Modules/Notifications/ControllersLogic/ListNotificationsLogic.php new file mode 100644 index 00000000..0fdbf6f9 --- /dev/null +++ b/app/Classes/Modules/Notifications/ControllersLogic/ListNotificationsLogic.php @@ -0,0 +1,61 @@ + 'Retrieve Notifications', + 'message' => 'You have successfully retrieved a list of Notifications' + ]; + } + + /** @var ListsNotification */ + private $listsNotification; + + /** + * ListNotificationsLogic constructor. + * @param ListsNotification $listsNotification + */ + public function __construct( + ListsNotification $listsNotification + ) + { + $this->listsNotification = $listsNotification; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + + $filters = [ + // 'target_id'=>auth()->user()->id, + // 'per_page'=>$request->route('per_page') + ]; + + $notifications = $this->listsNotification->execute($filters); + + return $this->collectionResponse(NotificationResource::collection($notifications)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Notifications/DataTransferObjects/NotificationObject.php b/app/Classes/Modules/Notifications/DataTransferObjects/NotificationObject.php new file mode 100644 index 00000000..40dc4f3c --- /dev/null +++ b/app/Classes/Modules/Notifications/DataTransferObjects/NotificationObject.php @@ -0,0 +1,101 @@ +title = $title; + $this->description = $description; + $this->subject = $subject; + $this->target = $target; + $this->causer = $causer; + $this->status = $status; + } + + /** + * @return int + */ + public function getTitle(): string + { + return $this->title; + } + + /** + * @return int + */ + public function getDescription(): string + { + return $this->description; + } + + /** + * @return Notifiable + */ + public function getSubject(): Notifiable + { + return $this->subject; + } + + /** + * @return Notifiable + */ + public function getTarget(): Notifiable + { + return $this->target; + } + + /** + * @return Notifiable + */ + public function getCauser(): Notifiable + { + return $this->causer; + } + + /** + * @return int + */ + public function getStatus(): int + { + return $this->status; + } + + +} diff --git a/app/Classes/Modules/Notifications/Processors/CreateNotificationProcessor.php b/app/Classes/Modules/Notifications/Processors/CreateNotificationProcessor.php new file mode 100644 index 00000000..d6b077f8 --- /dev/null +++ b/app/Classes/Modules/Notifications/Processors/CreateNotificationProcessor.php @@ -0,0 +1,27 @@ +createsNotification = $createsNotification; + } + + public function execute(NotificationObject $object) + { + $notification = $this->createsNotification->execute($object); + return $notification; + } +} diff --git a/app/Classes/Modules/Notifications/Services/CreatesNotification.php b/app/Classes/Modules/Notifications/Services/CreatesNotification.php new file mode 100644 index 00000000..4f5ca5fd --- /dev/null +++ b/app/Classes/Modules/Notifications/Services/CreatesNotification.php @@ -0,0 +1,30 @@ +title = $object->getTitle(); + $model->description = $object->getDescription(); + $model->status = $object->getStatus(); + $model->subject_type = get_class($object->getSubject()); + $model->subject_id = $object->getSubject()->id; + $model->target_type = get_class($object->getTarget()); + $model->target_id = $object->getTarget()->id; + $model->causer_type = get_class($object->getCauser()); + $model->causer_id = $object->getCauser()->id; + $model->save(); + + return $model; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Notifications/Services/ListsNotification.php b/app/Classes/Modules/Notifications/Services/ListsNotification.php new file mode 100644 index 00000000..707e7ae8 --- /dev/null +++ b/app/Classes/Modules/Notifications/Services/ListsNotification.php @@ -0,0 +1,33 @@ +repository = $repository; + } + + + /** + * @return Builder + */ + function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php index 3dde2e45..0aa0fb7f 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php @@ -87,7 +87,7 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic $service_charge = 0; foreach ($this->createSupplierTransactionProcessor->getBills() as $key => $row) { - $group->transaction()->sync($row->id, false); + $group->transactions()->sync($row->id, false); $issuer = $row->issuer; $receiver = $row->receiver; $amount += $row->amount; diff --git a/app/Classes/Modules/Transactions/ControllersLogic/DeleteGroupLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/DeleteGroupLogic.php new file mode 100644 index 00000000..b19a7159 --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/DeleteGroupLogic.php @@ -0,0 +1,72 @@ + 'Delete Group Transaction', + 'message' => 'You have successfully deleted this Group Transaction' + ]; + } + + /** @var UpdatesTransactionStatus */ + private $updatesTransactionStatus; + + /** @var FetchesGroup */ + private $fetchesGroup; + + /** @var DeletesTransaction */ + private $deletesTransaction; + + public function __construct( + UpdatesTransactionStatus $updatesTransactionStatus, + FetchesGroup $fetchesGroup, + DeletesTransaction $deletesTransaction + ) + { + $this->updatesTransactionStatus = $updatesTransactionStatus; + $this->fetchesGroup = $fetchesGroup; + $this->deletesTransaction = $deletesTransaction; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + $group = $this->fetchesGroup->execute(['id' => $request->route('id')]); + + $items = $group->transactions()->get(); + + foreach($items as $item) { + $bill = $item; + $payment = $bill->owner; + $group->transactions()->detach($bill->id); + $this->updatesTransactionStatus->execute($payment, ApprovalStatus::APPROVED); + $this->deletesTransaction->execute($bill); + } + + $group->delete(); + + return $this->resourceResponse(new GroupResource($group)); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/ControllersLogic/ListGroupsLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/ListGroupsLogic.php new file mode 100644 index 00000000..5cf99bbe --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/ListGroupsLogic.php @@ -0,0 +1,42 @@ +listsGroups = $listsGroups; + } + + /** + * @return array + */ + protected function notification():array { + return [ + 'title' => 'Retrieved Groups', + 'message' => 'You have successfully retrieved a list of groups' + ]; + } + + /** @var ListsGroups */ + private $listsGroups; + + public function logic(Request $request) : JsonResponse + { + $query = $this->listsGroups->execute($this->listsGroups->deserializeFilters($request->input('filters'))); + + return $this->collectionResponse(GroupResource::collection($query)); + } + +} diff --git a/app/Classes/Modules/Transactions/ControllersLogic/UpdateGroupLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/UpdateGroupLogic.php new file mode 100644 index 00000000..e353f06a --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/UpdateGroupLogic.php @@ -0,0 +1,141 @@ + 'Update Group Transaction', + 'message' => 'You have successfully updated this Group Transaction' + ]; + } + + /** @var FetchesGroup */ + private $fetchesGroup; + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** @var CalculatesTransactionServiceCharge */ + private $calculatesTransactionServiceCharge; + + /** @var UpdatesTransaction */ + private $updatesTransaction; + + /** @var CalculatesTransactionTransferFee */ + private $calculatesTransactionTransferFee; + + public function __construct( + FetchesGroup $fetchesGroup, + FetchesCompany $fetchesCompany, + CalculatesTransactionServiceCharge $calculatesTransactionServiceCharge, + UpdatesTransaction $updatesTransaction, + CalculatesTransactionTransferFee $calculatesTransactionTransferFee + ) + { + $this->fetchesGroup = $fetchesGroup; + $this->fetchesCompany = $fetchesCompany; + $this->calculatesTransactionServiceCharge = $calculatesTransactionServiceCharge; + $this->updatesTransaction = $updatesTransaction; + $this->calculatesTransactionTransferFee = $calculatesTransactionTransferFee; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + $group = $this->fetchesGroup->execute(['id' => $request->route('id')]); + + $transactions = $group->transactions()->get(); + + $rate = $request->input('rate'); + + $supplier = $this->fetchesCompany->execute(['id' => $request->input('supplier_id')]); + + foreach($transactions as $transaction) { + + $constant = SegmentConstant::where('reference', SegmentConstants::SERVICE_CHARGE)->where('detail->id', $supplier->id)->first(); + $serviceCharge = $this->calculatesTransactionServiceCharge->execute($transaction->original_amount, $rate, $constant); + + $object = new TransactionObject( + $transaction->bill_no, + TransactionType::BILL, + $supplier->id, + 1, + $supplier->banks()->where('default', true)->first()->id, + PaymentMethodType::CASH, + $transaction->original_amount * (1 / $rate), + $transaction->original_amount, + 1, + $transaction->original_currency_id, + $rate, + 0, + $serviceCharge, + null, + ApprovalStatus::PENDING_VERIFICATION + ); + + $billTransaction = $this->updatesTransaction->execute($transaction, $object); + + $transferTransaction = $transaction->transactions()->where('type', TransactionType::TRANSFER_FEE)->first(); + + $transferFee = $this->calculatesTransactionTransferFee->execute($billTransaction->amount, $constant); + + $object = new TransactionObject( + $transferTransaction->bill_no, + TransactionType::TRANSFER_FEE, + 1, + $supplier->id, + $supplier->banks()->where('default', true)->first()->id, + PaymentMethodType::CASH, + $transaction->original_amount, + $transaction->original_amount, + $transaction->original_currency_id, + $transaction->original_currency_id, + 1, + 0, + $transferFee, + null, + ApprovalStatus::PENDING_VERIFICATION + ); + + $this->updatesTransaction->execute($transferTransaction, $object); + } + + $group->issuer = $supplier; + $group->amount = $group->transactions()->sum('amount'); + $group->currency_rate = $rate; + $group->tax = $group->transactions()->sum('tax'); + $group->service_charge = $group->transactions()->sum('service_charge'); + + $group->save(); + + return $this->resourceResponse(new GroupResource($group)); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Processors/CreateInvoiceDocumentProcessor.php b/app/Classes/Modules/Transactions/Processors/CreateInvoiceDocumentProcessor.php new file mode 100644 index 00000000..39b42576 --- /dev/null +++ b/app/Classes/Modules/Transactions/Processors/CreateInvoiceDocumentProcessor.php @@ -0,0 +1,49 @@ +createsDocument = $createsDocument; + $this->createsFile = $createsFile; + } + + /** + * @return void + */ + public function execute($transaction, $purchaseOrder, $supplier, $document_type) + { + $lowercaseDocumentType = strtolower($document_type); + + $order_pdf = LaravelMpdf::loadView('pages.pdfs.' . $lowercaseDocumentType, ['transaction' => $transaction, 'po_order_transaction' => $purchaseOrder, 'supplier' => $supplier]); + $document_object = new DocumentObject( + $document_type, + [chunk_split('data:application/pdf;base64,' . base64_encode($order_pdf->output()))], + '', + ApprovalStatus::COMPLETED, + $lowercaseDocumentType . 's' + ); + + $document = $this->createsDocument->execute($purchaseOrder->booking, $document_object); + $this->createsFile->execute($document, $document_object); + } +} diff --git a/app/Classes/Modules/Transactions/Processors/CreateInvoiceTransactionProcessor.php b/app/Classes/Modules/Transactions/Processors/CreateInvoiceTransactionProcessor.php index 5a29a1a2..5b7987b4 100644 --- a/app/Classes/Modules/Transactions/Processors/CreateInvoiceTransactionProcessor.php +++ b/app/Classes/Modules/Transactions/Processors/CreateInvoiceTransactionProcessor.php @@ -11,20 +11,14 @@ use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber; use App\Classes\Modules\Bookings\Services\CalculatesBookingPaidAmount; use App\Classes\Modules\Bookings\Services\CalculatesBookingCurrencyAverageRate; use App\Classes\Modules\Companies\Services\FetchesCompany; -use App\Classes\Modules\Documents\Services\CreatesDocument; -use App\Classes\Modules\Documents\Services\CreatesFiles; use App\Classes\Modules\Bookings\Services\UpdatesBookingStatus; - use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject; -use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject; use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Classes\ValueObjects\Constants\SegmentConstants; use App\Classes\ValueObjects\Constants\TransactionType; use App\Classes\ValueObjects\Constants\DocumentType; use App\Models\Booking; -use App\Models\Document; use App\Models\SegmentConstant; -use Meneses\LaravelMpdf\Facades\LaravelMpdf; class CreateInvoiceTransactionProcessor { @@ -55,15 +49,12 @@ class CreateInvoiceTransactionProcessor /** @var FetchesCompany */ private $fetchesCompany; - /** @var CreatesDocument */ - private $createsDocument; - - /** @var CreatesFiles */ - private $createsFile; - /** @var UpdatesBookingStatus */ private $updatesBookingStatus; + /** @var CreateInvoiceDocumentProcessor */ + private $invoiceDocumentProcessor; + /** * CreateInvoiceTransactionProcessor constructor. * @param ListsTransactions $listsTransactions @@ -75,11 +66,10 @@ class CreateInvoiceTransactionProcessor * @param FetchesServiceConfigurations $fetchesServiceConfigurations * @param CalculatesBookingCurrencyAverageRate $calculatesBookingCurrencyAverageRate * @param FetchesCompany $fetchesCompany - * @param CreatesDocument $createsDocument - * @param CreatesFiles $createsFile * @param UpdatesBookingStatus $updatesBookingStatus + * @param CreateInvoiceDocumentProcessor $invoiceDocumentProcessor */ - public function __construct(ListsTransactions $listsTransactions, CreatesTransaction $createsTransaction, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CalculatesBookingPaidAmount $calculatesBookingPaidAmount, CalculatesBookingPayableAmount $calculatesBookingPayableAmount, CalculatesBookingTransferredAmount $calculatesBookingTransferredAmount, FetchesServiceConfigurations $fetchesServiceConfigurations, CalculatesBookingCurrencyAverageRate $calculatesBookingCurrencyAverageRate, FetchesCompany $fetchesCompany, CreatesDocument $createsDocument, CreatesFiles $createsFile, UpdatesBookingStatus $updatesBookingStatus) + public function __construct(ListsTransactions $listsTransactions, CreatesTransaction $createsTransaction, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CalculatesBookingPaidAmount $calculatesBookingPaidAmount, CalculatesBookingPayableAmount $calculatesBookingPayableAmount, CalculatesBookingTransferredAmount $calculatesBookingTransferredAmount, FetchesServiceConfigurations $fetchesServiceConfigurations, CalculatesBookingCurrencyAverageRate $calculatesBookingCurrencyAverageRate, FetchesCompany $fetchesCompany, UpdatesBookingStatus $updatesBookingStatus, CreateInvoiceTransactionProcessor $invoiceDocumentProcessor) { $this->listsTransactions = $listsTransactions; $this->createsTransaction = $createsTransaction; @@ -90,18 +80,16 @@ class CreateInvoiceTransactionProcessor $this->fetchesServiceConfigurations = $fetchesServiceConfigurations; $this->calculatesBookingCurrencyAverageRate = $calculatesBookingCurrencyAverageRate; $this->fetchesCompany = $fetchesCompany; - $this->createsDocument = $createsDocument; - $this->createsFile = $createsFile; $this->updatesBookingStatus = $updatesBookingStatus; + $this->invoiceDocumentProcessor = $invoiceDocumentProcessor; } - /** * @param Booking $booking * @return void * @throws \App\Classes\Exceptions\MalformedRequestException */ - public function execute(Booking $booking) + public function execute(Booking $booking) { if ($booking->status === ApprovalStatus::COMPLETED) { @@ -116,18 +104,18 @@ class CreateInvoiceTransactionProcessor return; } // confirm that all payments has been transferred - if($this->calculatesBookingTransferredAmount->execute($booking) !== $this->calculatesBookingPaidAmount->execute($booking)){ + if ($this->calculatesBookingTransferredAmount->execute($booking) !== $this->calculatesBookingPaidAmount->execute($booking)) { return; } - $po_order_transaction = $booking->transactions() + $purchaseOrder = $booking->transactions() ->where('type', TransactionType::PURCHASE_ORDER) ->complete() ->first(); $constants = SegmentConstant::where('reference', SegmentConstants::SERVICE_TYPE)->where('detail->id', $booking->service->id)->first(); - if($constants->detail->is_billable && !$po_order_transaction) { + if ($constants->detail->is_billable && !$purchaseOrder) { return; } @@ -166,46 +154,18 @@ class CreateInvoiceTransactionProcessor null, ApprovalStatus::APPROVED ); - $invoice_transaction = $this->createsTransaction->execute($po_order_transaction->booking, $transaction_object); + $invoice_transaction = $this->createsTransaction->execute($purchaseOrder->booking, $transaction_object); $supplier = $this->fetchesCompany->execute(['id' => $transaction->receiver]); - $purchase_order_pdf = LaravelMpdf::loadView('pages.pdfs.purchase_order', ['invoice_transaction' => $invoice_transaction, 'po_order_transaction' => $po_order_transaction, 'supplier' => $supplier]); - $document_object = new DocumentObject( - DocumentType::PURCHASE_ORDER, - [chunk_split('data:application/pdf;base64,'.base64_encode($purchase_order_pdf->output()))], - '', - ApprovalStatus::COMPLETED, - 'purchase_orders' - ); - /** @var Document $document */ - $document = $this->createsDocument->execute($po_order_transaction->booking, $document_object); - $this->createsFile->execute($document, $document_object); + // purchase order + $this->invoiceDocumentProcessor->execute($invoice_transaction, $purchaseOrder, $supplier, DocumentType::PURCHASE_ORDER); - $deliver_order_pdf = LaravelMpdf::loadView('pages.pdfs.deliver_order', ['invoice_transaction' => $invoice_transaction, 'po_order_transaction' => $po_order_transaction, 'supplier' => $supplier]); - $document_object = new DocumentObject( - DocumentType::DELIVER_ORDER, - [chunk_split('data:application/pdf;base64,'.base64_encode($deliver_order_pdf->output()))], - '', - ApprovalStatus::COMPLETED, - 'delivery_orders' - ); + // deliver order + $this->invoiceDocumentProcessor->execute($invoice_transaction, $purchaseOrder, $supplier, DocumentType::DELIVER_ORDER); - /** @var Document $document */ - $document = $this->createsDocument->execute($po_order_transaction->booking, $document_object); - $this->createsFile->execute($document, $document_object); - - - $invoice_pdf = LaravelMpdf::loadView('pages.pdfs.invoice', ['invoice_transaction' => $invoice_transaction, 'po_order_transaction' => $po_order_transaction, 'supplier' => $supplier]); - $document_object = new DocumentObject( - DocumentType::INVOICE, - [chunk_split('data:application/pdf;base64,'.base64_encode($invoice_pdf->output()))], - '', - ApprovalStatus::COMPLETED, - 'invoices' - ); - $document = $this->createsDocument->execute($po_order_transaction->booking, $document_object); - $this->createsFile->execute($document, $document_object); + // invoice + $this->invoiceDocumentProcessor->execute($invoice_transaction, $purchaseOrder, $supplier, DocumentType::INVOICE); $billNumber = $this->generatesTransactionBillNumber->execute('SPDO-'); @@ -231,18 +191,10 @@ class CreateInvoiceTransactionProcessor null, ApprovalStatus::APPROVED ); - $supplier_deliver_order_transaction = $this->createsTransaction->execute($po_order_transaction->booking, $transaction_object); + $supplier_deliver_order_transaction = $this->createsTransaction->execute($purchaseOrder->booking, $transaction_object); - $supplier_order_pdf = LaravelMpdf::loadView('pages.pdfs.supplier_deliver_order', ['supplier_deliver_order_transaction' => $supplier_deliver_order_transaction, 'po_order_transaction' => $po_order_transaction, '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 = $this->createsDocument->execute($po_order_transaction->booking, $document_object); - $this->createsFile->execute($document, $document_object); + // supply deliver order + $this->invoiceDocumentProcessor->execute($supplier_deliver_order_transaction, $purchaseOrder, $supplier, DocumentType::SUPPLIER_DELIVER_ORDER); $this->updatesBookingStatus->execute($booking, ApprovalStatus::COMPLETED); } diff --git a/app/Classes/Modules/Transactions/Services/FetchesGroup.php b/app/Classes/Modules/Transactions/Services/FetchesGroup.php new file mode 100644 index 00000000..6533664b --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/FetchesGroup.php @@ -0,0 +1,31 @@ +repository = $repository; + } + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} diff --git a/app/Classes/Modules/Transactions/Services/ListsGroups.php b/app/Classes/Modules/Transactions/Services/ListsGroups.php new file mode 100644 index 00000000..f9126739 --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/ListsGroups.php @@ -0,0 +1,31 @@ +repository = $repository; + } + + /** + * @return Builder + */ + public function getRepository(): Builder + { + return $this->repository->newQuery(); + } +} diff --git a/app/Http/Controllers/Bookings/DownloadBookingDocumentController.php b/app/Http/Controllers/Bookings/DownloadBookingDocumentController.php index d2a7d85c..95427363 100644 --- a/app/Http/Controllers/Bookings/DownloadBookingDocumentController.php +++ b/app/Http/Controllers/Bookings/DownloadBookingDocumentController.php @@ -15,7 +15,7 @@ class DownloadBookingDocumentController * @throws \App\Classes\Exceptions\MalformedRequestException */ public function download(Request $request, DownloadBookingDocumentLogic $logic) { - $logic->execute($request); + return $logic->execute($request); } } \ No newline at end of file diff --git a/app/Http/Controllers/Companies/UpdateCompanyStatusController.php b/app/Http/Controllers/Companies/UpdateCompanyStatusController.php new file mode 100644 index 00000000..43b3ba3c --- /dev/null +++ b/app/Http/Controllers/Companies/UpdateCompanyStatusController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Exports/ExportCustomersToExcelController.php b/app/Http/Controllers/Exports/ExportCustomersToExcelController.php index 39ea3dc5..8563f78a 100644 --- a/app/Http/Controllers/Exports/ExportCustomersToExcelController.php +++ b/app/Http/Controllers/Exports/ExportCustomersToExcelController.php @@ -5,6 +5,7 @@ namespace App\Http\Controllers\Exports; use App\Classes\Modules\Exports\Services\ExportsCustomers; use App\Classes\Modules\Exports\Services\ExportsTransactions; +use App\Classes\Modules\Exports\Services\ExportsBookingTransactions; use App\Classes\Modules\Exports\Services\ExportsNullDebtors; use App\Classes\Modules\Exports\Services\ExportsPaymentTransactions; @@ -54,4 +55,10 @@ class ExportCustomersToExcelController ob_end_clean(); return $response; } + + public function bookingTransactions(ExportsBookingTransactions $exportsBookingTransactions, Request $request){ + $response = $exportsBookingTransactions->download('bookingTransactions.xls', Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']); + ob_end_clean(); + return $response; + } } \ No newline at end of file diff --git a/app/Http/Controllers/Notifications/ListNotificationsController.php b/app/Http/Controllers/Notifications/ListNotificationsController.php new file mode 100644 index 00000000..58455fc2 --- /dev/null +++ b/app/Http/Controllers/Notifications/ListNotificationsController.php @@ -0,0 +1,19 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Transactions/DeleteGroupController.php b/app/Http/Controllers/Transactions/DeleteGroupController.php new file mode 100644 index 00000000..14ba54f9 --- /dev/null +++ b/app/Http/Controllers/Transactions/DeleteGroupController.php @@ -0,0 +1,20 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Transactions/ListGroupsController.php b/app/Http/Controllers/Transactions/ListGroupsController.php new file mode 100644 index 00000000..730633e9 --- /dev/null +++ b/app/Http/Controllers/Transactions/ListGroupsController.php @@ -0,0 +1,21 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Transactions/UpdateGroupController.php b/app/Http/Controllers/Transactions/UpdateGroupController.php new file mode 100644 index 00000000..db0b3a17 --- /dev/null +++ b/app/Http/Controllers/Transactions/UpdateGroupController.php @@ -0,0 +1,20 @@ +execute($request); + } +} diff --git a/app/Http/Resources/BookingResource.php b/app/Http/Resources/BookingResource.php index 0eeb9670..0adfa65d 100644 --- a/app/Http/Resources/BookingResource.php +++ b/app/Http/Resources/BookingResource.php @@ -31,6 +31,7 @@ class BookingResource extends JsonResource 'service' => new ServiceTypeResource($this->service), 'marking' => $this->marking, 'amount' => $this->fix_amount, + 'amount' => $this->fix_amount, 'floating_amount' => floatval((App()->make(CalculatesBookingFloatingAmount::class))->execute($this->resource, $this->fix_currency_id)), 'paid_amount' => floatval((App()->make(CalculatesBookingPayableAmount::class))->execute($this->resource, $this->fix_currency_id)) - floatval((App()->make(CalculatesBookingRefundAmount::class))->execute($this->resource, $this->fix_currency_id)), 'outstanding_amount' => floatval((App()->make(CalculatesBookingOutstanding::class))->execute($this->resource)) - floatval((App()->make(CalculatesBookingRefundAmount::class))->execute($this->resource, $this->fix_currency_id)), diff --git a/app/Http/Resources/GroupResource.php b/app/Http/Resources/GroupResource.php new file mode 100644 index 00000000..2d628d19 --- /dev/null +++ b/app/Http/Resources/GroupResource.php @@ -0,0 +1,29 @@ + $this->id, + 'original_amount' => (double) $this->original_amount, + 'original_currency' => new CurrencyResource($this->original_currency), + 'amount' => (double) $this->amount, + 'currency' => new CurrencyResource($this->currency), + 'created_at' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A'), + 'currency_rate' => (float) $this->currency_rate, + 'transactions' => TransactionResource::collection($this->transactions()->get()), + ]; + } +} diff --git a/app/Http/Resources/NotificationResource.php b/app/Http/Resources/NotificationResource.php new file mode 100644 index 00000000..564b7b31 --- /dev/null +++ b/app/Http/Resources/NotificationResource.php @@ -0,0 +1,30 @@ + $this->id, + 'title' => $this->title, + 'description' => $this->description, + 'long_ago' => $this->created_at->diffForHumans(), + 'created_at' => $this->created_at->format('d-m-Y') + ]; + + } +} diff --git a/app/Http/Resources/TransactionResource.php b/app/Http/Resources/TransactionResource.php index 30ba223c..e35dcc36 100644 --- a/app/Http/Resources/TransactionResource.php +++ b/app/Http/Resources/TransactionResource.php @@ -30,6 +30,7 @@ class TransactionResource extends JsonResource 'payment_method' => (float) $this->payment_method, 'recipient_bank_account' => new BankResource($booking->bank), 'issuer_name' => $this->issuerCompany->name, + 'issuer_id' => $this->issuerCompany->id, 'amount' => (double) $this->amount, 'original_amount' => (double) $this->original_amount, 'currency' => new CurrencyResource($this->currency), diff --git a/app/Models/AbstractModel.php b/app/Models/AbstractModel.php index 7a7c9c06..47d8754b 100644 --- a/app/Models/AbstractModel.php +++ b/app/Models/AbstractModel.php @@ -3,11 +3,37 @@ namespace App\Models; +use App\Classes\General\Interfaces\Notifiable; use Illuminate\Database\Eloquent\Model; use Spatie\Activitylog\Traits\LogsActivity; +use Illuminate\Database\Eloquent\Relations\MorphTo; -class AbstractModel extends Model +class AbstractModel extends Model implements Notifiable { use LogsActivity; protected static $logFillable = true; + + /** + * @return MorphTo + */ + public function subject(): MorphTo + { + return $this->MorphTo('subject'); + } + + /** + * @return MorphTo + */ + public function target(): MorphTo + { + return $this->MorphTo('target'); + } + + /** + * @return MorphTo + */ + public function causer(): MorphTo + { + return $this->MorphTo('causer'); + } } \ No newline at end of file diff --git a/app/Models/Group.php b/app/Models/Group.php index eff309e2..6e785faa 100644 --- a/app/Models/Group.php +++ b/app/Models/Group.php @@ -3,11 +3,28 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; class Group extends Model { - public function transaction() + public function transactions() { - return $this->belongsToMany('App\Models\Transaction', 'group_transaction'); + return $this->belongsToMany(Transaction::class, GroupTransaction::class); + } + + /** + * @return BelongsTo + */ + public function currency(): BelongsTo + { + return $this->BelongsTo(Currency::class, 'currency_id', 'id'); + } + + /** + * @return BelongsTo + */ + public function original_currency(): BelongsTo + { + return $this->BelongsTo(Currency::class, 'original_currency_id', 'id'); } } diff --git a/app/Models/GroupTransaction.php b/app/Models/GroupTransaction.php index c8622ef9..9ab72d18 100644 --- a/app/Models/GroupTransaction.php +++ b/app/Models/GroupTransaction.php @@ -3,8 +3,25 @@ namespace App\Models; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\BelongsTo; class GroupTransaction extends Model { - // + protected $table = 'group_transactions'; + + /** + * @return BelongsTo + */ + public function group(): BelongsTo + { + return $this->BelongsTo(Group::class, 'group_id', 'id'); + } + + /** + * @return BelongsTo + */ + public function transaction(): BelongsTo + { + return $this->BelongsTo(Transaction::class, 'transaction_id', 'id'); + } } diff --git a/app/Models/Notification.php b/app/Models/Notification.php new file mode 100644 index 00000000..06bd6024 --- /dev/null +++ b/app/Models/Notification.php @@ -0,0 +1,18 @@ +BelongsTo(Package::class, 'package_id', 'id'); + } +} diff --git a/database/migrations/2022_03_20_170641_create_group_transactions_table.php b/database/migrations/2022_03_20_170641_create_group_transactions_table.php index 6ce7cedc..53f33356 100644 --- a/database/migrations/2022_03_20_170641_create_group_transactions_table.php +++ b/database/migrations/2022_03_20_170641_create_group_transactions_table.php @@ -13,7 +13,8 @@ class CreateGroupTransactionsTable extends Migration */ public function up() { - Schema::create('group_transaction', function (Blueprint $table) { + Schema::create('group_transactions', function (Blueprint $table) { + $table->id(); $table->foreignId('group_id')->unsigned(); $table->foreignId('transaction_id')->unsigned(); }); @@ -26,6 +27,6 @@ class CreateGroupTransactionsTable extends Migration */ public function down() { - Schema::dropIfExists('group_transaction'); + Schema::dropIfExists('group_transactions'); } } diff --git a/database/migrations/2022_04_15_211421_create_notifications_table.php b/database/migrations/2022_04_15_211421_create_notifications_table.php new file mode 100644 index 00000000..d14cdc89 --- /dev/null +++ b/database/migrations/2022_04_15_211421_create_notifications_table.php @@ -0,0 +1,40 @@ +id(); + $table->string('title'); + $table->text('description'); + $table->morphs('subject'); + $table->morphs('target'); + $table->morphs('causer'); + $table->integer('status')->default(ApprovalStatus::APPROVED); + $table->softDeletes(); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('notifications'); + } +} diff --git a/resources/assets/sass/modules/_typography.scss b/resources/assets/sass/modules/_typography.scss index 605b8e7c..aa4506a9 100644 --- a/resources/assets/sass/modules/_typography.scss +++ b/resources/assets/sass/modules/_typography.scss @@ -316,6 +316,12 @@ hr{ background-color: $color-primary-lighter !important; } +.bg-primary-lighter-hover { + &:hover { + background-color: $color-primary-lighter !important; + } +} + /* Complete ------------------------------------ */ diff --git a/resources/assets/vue/components/bookings/elements/BillingComponent.vue b/resources/assets/vue/components/bookings/elements/BillingComponent.vue index 70f511ed..f24078ed 100644 --- a/resources/assets/vue/components/bookings/elements/BillingComponent.vue +++ b/resources/assets/vue/components/bookings/elements/BillingComponent.vue @@ -84,7 +84,14 @@ export default { type: 'INVOICE', supplier: null }, - documents: ['INVOICE', 'PURCHASE_ORDER', 'DELIVER_ORDER', 'SUPPLIER_DELIVER_ORDER'], + documents: [ + 'INVOICE', + 'PURCHASE_ORDER', + 'DELIVER_ORDER', + 'SUPPLIER_DELIVER_ORDER', + 'INVOICE + PO + DO', + 'INVOICE + PO + DO + SDO' + ], selectedDocumentStatus: false } }, diff --git a/resources/assets/vue/components/bookings/elements/BookingConfirmationComponent.vue b/resources/assets/vue/components/bookings/elements/BookingConfirmationComponent.vue index cf8b727e..f08ea597 100644 --- a/resources/assets/vue/components/bookings/elements/BookingConfirmationComponent.vue +++ b/resources/assets/vue/components/bookings/elements/BookingConfirmationComponent.vue @@ -148,7 +148,6 @@
| {{ $transaction_detail->product_name }} | {{ $transaction_detail->quantity }} | - @if($invoice_transaction->booking()->first()->fix_currency_id !== 1) - {{ number_format( (1/$invoice_transaction->currency_rate) * $transaction_detail->price, 2) }} + @if($transaction->booking()->first()->fix_currency_id !== 1) + {{ number_format( (1/$transaction->currency_rate) * $transaction_detail->price, 2) }} @else {{ number_format($transaction_detail->price, 2) }} @endif | - @if($invoice_transaction->booking()->first()->fix_currency_id !== 1) + @if($transaction->booking()->first()->fix_currency_id !== 1) - {{ number_format((float)number_format( (1/$invoice_transaction->currency_rate) * $transaction_detail->price, 2,'.','')*$transaction_detail->quantity,2) }} + {{ number_format((float)number_format( (1/$transaction->currency_rate) * $transaction_detail->price, 2,'.','')*$transaction_detail->quantity,2) }} @php - $subtotal += number_format((float)number_format( (1/$invoice_transaction->currency_rate) * $transaction_detail->price, 2,'.','')*$transaction_detail->quantity,2,'.',''); + $subtotal += number_format((float)number_format( (1/$transaction->currency_rate) * $transaction_detail->price, 2,'.','')*$transaction_detail->quantity,2,'.',''); @endphp @else {{ number_format((float)number_format($transaction_detail->price, 2,'.','')*$transaction_detail->quantity,2) }} @@ -130,35 +130,35 @@ | Service Charges | - {{ number_format($invoice_transaction->service_charge, 2) }} + {{ number_format($transaction->service_charge, 2) }} | ||||
| Adjustment | - @if($invoice_transaction->booking()->first()->fix_currency_id !== 1) - {{ number_format((float)number_format( (1/$invoice_transaction->currency_rate) * $invoice_transaction->amount, 2,'.','') - (float)number_format($subtotal, 2,'.',''),2) }} + @if($transaction->booking()->first()->fix_currency_id !== 1) + {{ number_format((float)number_format( (1/$transaction->currency_rate) * $transaction->amount, 2,'.','') - (float)number_format($subtotal, 2,'.',''),2) }} @else - {{ number_format((float)number_format($invoice_transaction->amount, 2,'.','') - (float)number_format($subtotal, 2,'.',''),2) }} + {{ number_format((float)number_format($transaction->amount, 2,'.','') - (float)number_format($subtotal, 2,'.',''),2) }} @endif | ||||||||
| Tax | -{{ number_format($invoice_transaction->tax, 2) }} | +{{ number_format($transaction->tax, 2) }} | |||||||
| Total | - @if($invoice_transaction->booking()->first()->fix_currency_id !== 1) - {{ number_format( ((1/$invoice_transaction->currency_rate) * $invoice_transaction->amount) + $invoice_transaction->service_charge + $invoice_transaction->tax, 2) }} + @if($transaction->booking()->first()->fix_currency_id !== 1) + {{ number_format( ((1/$transaction->currency_rate) * $transaction->amount) + $transaction->service_charge + $transaction->tax, 2) }} @else - {{ number_format($invoice_transaction->amount + $invoice_transaction->service_charge + $invoice_transaction->tax, 2) }} + {{ number_format($transaction->amount + $transaction->service_charge + $transaction->tax, 2) }} @endif | ||||||||
| {{ $transaction_detail->product_name }} | {{ $transaction_detail->quantity }} | - @if($invoice_transaction->booking()->first()->fix_currency_id !== 1) - {{ number_format( (1/$invoice_transaction->currency_rate) * $transaction_detail->price, 2) }} + @if($transaction->booking()->first()->fix_currency_id !== 1) + {{ number_format( (1/$transaction->currency_rate) * $transaction_detail->price, 2) }} @else {{ number_format($transaction_detail->price, 2) }} @endif | - @if($invoice_transaction->booking()->first()->fix_currency_id !== 1) + @if($transaction->booking()->first()->fix_currency_id !== 1) - {{ number_format((float)number_format( (1/$invoice_transaction->currency_rate) * $transaction_detail->price, 2,'.','')*$transaction_detail->quantity,2) }} + {{ number_format((float)number_format( (1/$transaction->currency_rate) * $transaction_detail->price, 2,'.','')*$transaction_detail->quantity,2) }} @php - $subtotal += number_format((float)number_format( (1/$invoice_transaction->currency_rate) * $transaction_detail->price, 2,'.','')*$transaction_detail->quantity,2,'.',''); + $subtotal += number_format((float)number_format( (1/$transaction->currency_rate) * $transaction_detail->price, 2,'.','')*$transaction_detail->quantity,2,'.',''); @endphp @else {{ number_format((float)number_format($transaction_detail->price, 2,'.','')*$transaction_detail->quantity,2) }} @@ -129,35 +129,35 @@ | Service Charges | - {{ number_format($invoice_transaction->service_charge, 2) }} + {{ number_format($transaction->service_charge, 2) }} | ||||
| Adjustment | - @if($invoice_transaction->booking()->first()->fix_currency_id !== 1) - {{ number_format((float)number_format( (1/$invoice_transaction->currency_rate) * $invoice_transaction->amount, 2,'.','') - (float)number_format($subtotal, 2,'.',''),2) }} + @if($transaction->booking()->first()->fix_currency_id !== 1) + {{ number_format((float)number_format( (1/$transaction->currency_rate) * $transaction->amount, 2,'.','') - (float)number_format($subtotal, 2,'.',''),2) }} @else - {{ number_format((float)number_format($invoice_transaction->amount, 2,'.','') - (float)number_format($subtotal, 2,'.',''),2) }} + {{ number_format((float)number_format($transaction->amount, 2,'.','') - (float)number_format($subtotal, 2,'.',''),2) }} @endif | ||||||||
| Tax | -{{ number_format($invoice_transaction->tax, 2) }} | +{{ number_format($transaction->tax, 2) }} | |||||||
| Total | - @if($invoice_transaction->booking()->first()->fix_currency_id !== 1) - {{ number_format( ((1/$invoice_transaction->currency_rate) * $invoice_transaction->amount) + $invoice_transaction->service_charge + $invoice_transaction->tax, 2) }} + @if($transaction->booking()->first()->fix_currency_id !== 1) + {{ number_format( ((1/$transaction->currency_rate) * $transaction->amount) + $transaction->service_charge + $transaction->tax, 2) }} @else - {{ number_format($invoice_transaction->amount + $invoice_transaction->service_charge + $invoice_transaction->tax, 2) }} + {{ number_format($transaction->amount + $transaction->service_charge + $transaction->tax, 2) }} @endif | {{ $transaction_detail->product_name }} | {{ $transaction_detail->quantity }} | - @if($invoice_transaction->booking()->first()->fix_currency_id !== 1) - {{ number_format( (1/$invoice_transaction->currency_rate) * $transaction_detail->price, 2) }} + @if($transaction->booking()->first()->fix_currency_id !== 1) + {{ number_format( (1/$transaction->currency_rate) * $transaction_detail->price, 2) }} @else {{ number_format($transaction_detail->price, 2) }} @endif | - @if($invoice_transaction->booking()->first()->fix_currency_id !== 1) + @if($transaction->booking()->first()->fix_currency_id !== 1) - {{ number_format((float)number_format( (1/$invoice_transaction->currency_rate) * $transaction_detail->price, 2,'.','')*$transaction_detail->quantity,2) }} + {{ number_format((float)number_format( (1/$transaction->currency_rate) * $transaction_detail->price, 2,'.','')*$transaction_detail->quantity,2) }} @php - $subtotal += number_format((float)number_format( (1/$invoice_transaction->currency_rate) * $transaction_detail->price, 2,'.','')*$transaction_detail->quantity,2,'.',''); + $subtotal += number_format((float)number_format( (1/$transaction->currency_rate) * $transaction_detail->price, 2,'.','')*$transaction_detail->quantity,2,'.',''); @endphp @else {{ number_format((float)number_format($transaction_detail->price, 2,'.','')*$transaction_detail->quantity,2) }} @@ -134,35 +134,35 @@ | Service Charges | - {{ number_format($invoice_transaction->service_charge, 2) }} + {{ number_format($transaction->service_charge, 2) }} | ||
| Adjustment | - @if($invoice_transaction->booking()->first()->fix_currency_id !== 1) - {{ number_format((float)number_format( (1/$invoice_transaction->currency_rate) * $invoice_transaction->amount, 2,'.','') - (float)number_format($subtotal, 2,'.',''),2) }} + @if($transaction->booking()->first()->fix_currency_id !== 1) + {{ number_format((float)number_format( (1/$transaction->currency_rate) * $transaction->amount, 2,'.','') - (float)number_format($subtotal, 2,'.',''),2) }} @else - {{ number_format((float)number_format($invoice_transaction->amount, 2,'.','') - (float)number_format($subtotal, 2,'.',''),2) }} + {{ number_format((float)number_format($transaction->amount, 2,'.','') - (float)number_format($subtotal, 2,'.',''),2) }} @endif | ||||||||
| Tax | -{{ number_format($invoice_transaction->tax, 2) }} | +{{ number_format($transaction->tax, 2) }} | |||||||
| Total | - @if($invoice_transaction->booking()->first()->fix_currency_id !== 1) - {{ number_format( ((1/$invoice_transaction->currency_rate) * $invoice_transaction->amount) + $invoice_transaction->service_charge + $invoice_transaction->tax, 2) }} + @if($transaction->booking()->first()->fix_currency_id !== 1) + {{ number_format( ((1/$transaction->currency_rate) * $transaction->amount) + $transaction->service_charge + $transaction->tax, 2) }} @else - {{ number_format($invoice_transaction->amount + $invoice_transaction->service_charge + $invoice_transaction->tax, 2) }} + {{ number_format($transaction->amount + $transaction->service_charge + $transaction->tax, 2) }} @endif | ||||||||
| - @if(in_array($supplier_deliver_order_transaction->issuer, [2, 1921])) + @if(in_array($transactions->issuer, [2, 1921])) Atvantic Import & Export Snd. Bhd (1309816-P) @endif - @if(in_array($supplier_deliver_order_transaction->issuer, [1937, 1970])) + @if(in_array($transactions->issuer, [1937, 1970])) BK Gemilang Sdn Bhd (1403513-U) @endif - @if(in_array($supplier_deliver_order_transaction->issuer, [2165, 2185])) + @if(in_array($transactions->issuer, [2165, 2185])) YSN SOLUTION TRADING SDN BHD (1393892-D) @endif - @if(in_array($supplier_deliver_order_transaction->issuer, [2210])) + @if(in_array($transactions->issuer, [2210])) RACK SOLUTION INDUSTRIES SDN BHD (954723-W) @endif | @@ -29,8 +29,8 @@ Delivery Order
- PO#: {{ $supplier_deliver_order_transaction->bill_no }} - Ref#: {{ $supplier_deliver_order_transaction->booking->marking }} + PO#: {{ $transactions->bill_no }} + Ref#: {{ $transactions->booking->marking }} Date: {{ $po_order_transaction->created_at }} |
{{ $transaction_detail->product_name }} | {{ $transaction_detail->quantity }} | - @if($supplier_deliver_order_transaction->booking()->first()->fix_currency_id !== 1) - {{ number_format( (1/$supplier_deliver_order_transaction->currency_rate) * $transaction_detail->price, 2) }} + @if($transactions->booking()->first()->fix_currency_id !== 1) + {{ number_format( (1/$transactions->currency_rate) * $transaction_detail->price, 2) }} @else {{ number_format($transaction_detail->price, 2) }} @endif | - @if($supplier_deliver_order_transaction->booking()->first()->fix_currency_id !== 1) + @if($transactions->booking()->first()->fix_currency_id !== 1) - {{ number_format((float)number_format( (1/$supplier_deliver_order_transaction->currency_rate) * $transaction_detail->price, 2,'.','')*$transaction_detail->quantity,2) }} + {{ number_format((float)number_format( (1/$transactions->currency_rate) * $transaction_detail->price, 2,'.','')*$transaction_detail->quantity,2) }} @php - $subtotal += number_format((float)number_format( (1/$supplier_deliver_order_transaction->currency_rate) * $transaction_detail->price, 2,'.','')*$transaction_detail->quantity,2,'.',''); + $subtotal += number_format((float)number_format( (1/$transactions->currency_rate) * $transaction_detail->price, 2,'.','')*$transaction_detail->quantity,2,'.',''); @endphp @else {{ number_format((float)number_format($transaction_detail->price, 2,'.','')*$transaction_detail->quantity,2) }} @@ -130,10 +130,10 @@ | Adjustment | - @if($supplier_deliver_order_transaction->booking()->first()->fix_currency_id !== 1) - {{ number_format((float)number_format( (1/$supplier_deliver_order_transaction->currency_rate) * $supplier_deliver_order_transaction->amount, 2,'.','') - (float)number_format($subtotal, 2,'.',''),2) }} + @if($transactions->booking()->first()->fix_currency_id !== 1) + {{ number_format((float)number_format( (1/$transactions->currency_rate) * $transactions->amount, 2,'.','') - (float)number_format($subtotal, 2,'.',''),2) }} @else - {{ number_format((float)number_format($supplier_deliver_order_transaction->amount, 2,'.','') - (float)number_format($subtotal, 2,'.',''),2) }} + {{ number_format((float)number_format($transactions->amount, 2,'.','') - (float)number_format($subtotal, 2,'.',''),2) }} @endif | @@ -141,10 +141,10 @@Total | - @if($supplier_deliver_order_transaction->booking()->first()->fix_currency_id !== 1) - {{ number_format( ((1/$supplier_deliver_order_transaction->currency_rate) * $supplier_deliver_order_transaction->amount), 2) }} + @if($transactions->booking()->first()->fix_currency_id !== 1) + {{ number_format( ((1/$transactions->currency_rate) * $transactions->amount), 2) }} @else - {{ number_format($supplier_deliver_order_transaction->amount, 2) }} + {{ number_format($transactions->amount, 2) }} @endif | diff --git a/resources/views/partials/header.blade.php b/resources/views/partials/header.blade.php index 0f9754ae..e616e80c 100644 --- a/resources/views/partials/header.blade.php +++ b/resources/views/partials/header.blade.php @@ -65,15 +65,8 @@ -