diff --git a/.env.example b/.env.example index 78c079f5..b1273290 100644 --- a/.env.example +++ b/.env.example @@ -53,7 +53,7 @@ JWT_TTL=1440 IS_PRODUCTION=false BILLPLZ_BASE_URL="https://www.billplz-sandbox.com" -BILLPLZ_API_KEY="0fa4c710-761b-4a7a-a501-c2c2d02643d5" -BILLPLZ_X_SIGNATURE_KEY="S-pbNVthVRsvnPfZlgLwqqOg" -BILLPLZ_COLLECTION_ID="hev2wdjy" -BILLPLZ_WALLET_COLLECTION_ID="hev2wdjy" +BILLPLZ_API_KEY="c8a55af1-08ee-4ed6-bb18-6e5078300d9e" +BILLPLZ_X_SIGNATURE_KEY="S-hcT93TLVGAv9TYWfpTCcWQ" +BILLPLZ_COLLECTION_ID="t0cggbdd" +BILLPLZ_WALLET_COLLECTION_ID="t0cggbdd" diff --git a/.gitignore b/.gitignore index 95d268cf..476bf6a0 100644 --- a/.gitignore +++ b/.gitignore @@ -24,4 +24,7 @@ db/* docker-compose.yml package-lock.json public/* -/public/* \ No newline at end of file +/public/* +/storage/app/public +public +/storage/framework/laravel-excel diff --git a/app/Classes/General/Eloquent/Filters/ServiceCharge.php b/app/Classes/General/Eloquent/Filters/ServiceCharge.php new file mode 100644 index 00000000..de8cdded --- /dev/null +++ b/app/Classes/General/Eloquent/Filters/ServiceCharge.php @@ -0,0 +1,21 @@ +where('reference', SegmentConstants::SERVICE_CHARGE)->where('detail->id', $value); + } + +} \ No newline at end of file diff --git a/app/Classes/General/ExcelHandel.php b/app/Classes/General/ExcelHandel.php new file mode 100644 index 00000000..3060ed8b --- /dev/null +++ b/app/Classes/General/ExcelHandel.php @@ -0,0 +1,87 @@ +makeDirectory($path); + return $folder; + } + + public static function insertExcel($path = '', $base64Set = []) + { + $file_info = []; + $folder_path = ExcelHandel::generateFolder('excels/' . $path); + + foreach ($base64Set as $key => $row) { + + $exceldata = $row; + $filename = (string) Str::uuid(); + + $f = finfo_open(); + $mime_type = finfo_file($f, $exceldata, FILEINFO_MIME_TYPE); + + $extension = 'xls'; + + switch ($mime_type) { + case 'application/vnd.ms-excel': + $extension = 'xls'; + break; + case 'application/zip': + $extension = 'xlsx'; + break; + } + + if (empty($extension)) { + return false; + } + + $exceldata = explode('base64,', $exceldata); + $exceldata = base64_decode($exceldata[1]); + + $filename_with_ext = $filename . '.' . $extension; + + $file = ExcelHandel::generateExcel($path, $exceldata, $filename, $extension); + + $file_info[] = [ + 'path' => $path, + 'filename' => $filename_with_ext, + 'mime_type' => $mime_type, + 'extension' => $extension, + 'file_info' => empty($file) ? [] : $file, + ]; + } + + return $file_info; + } + + public static function generateExcel($path = '', $exceldata = '', $filename = '', $extension = '') + { + $file_info = []; + $file = \Storage::disk('public')->put('excels/' . $path . '/' . $filename . '.' . $extension, $exceldata); + $file_info['original']['file'] = storage_path('app/public/excels/' . $path . '/' . $filename . '.' . $extension); + + return $file_info; + } + + public static function removeExcel($excel_info = []) + { + $excel_info = json_decode(json_encode($excel_info), true); + foreach ($excel_info as $key => $row) { + if (!empty($row['path'])) { + \File::delete([$row['file_info']['original']['file']]); + } + } + return true; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php index 411b9163..75334583 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php @@ -89,7 +89,7 @@ class CreateBookingRefundLogic extends AbstractControllerLogic } $refund = $this->calculatesBookingRefundAmount->execute($booking, $booking->fix_currency_id, $transaction->bill_no); - dd($refund); + // dd($refund); if($refund + $request->input('amount') > $transaction->original_amount) throw new MalformedRequestException('Your refund must not be greater than '. $transaction->original_amount .'.'); @@ -97,7 +97,7 @@ class CreateBookingRefundLogic extends AbstractControllerLogic $transactionRefundCalculationObject->init(); $object = new TransactionObject($billNumber, TransactionType::REFUND, 1, $booking->company->id, - $request->input('bank_id'),$transactionRefundCalculationObject->getConversionObject()->getPaymentMethod(), + 1, $transactionRefundCalculationObject->getConversionObject()->getPaymentMethod(), $transactionRefundCalculationObject->getRefundTotalAmount(), $transactionRefundCalculationObject->getAmount(), 1, $transactionRefundCalculationObject->getConversionObject()->getCurrencyId(), $transactionRefundCalculationObject->getTransaction()->currency_rate, $transactionRefundCalculationObject->getRefundTax(), $transactionRefundCalculationObject->getRefundServiceCharge(), null, ApprovalStatus::PENDING_VERIFICATION, [], $transaction->bill_no); diff --git a/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyDebtorLogic.php b/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyDebtorLogic.php new file mode 100644 index 00000000..49938efd --- /dev/null +++ b/app/Classes/Modules/Companies/ControllersLogic/UpdateCompanyDebtorLogic.php @@ -0,0 +1,66 @@ + 'Updated Company', + 'message' => 'You have successfully updated the Company' + ]; + } + + /** @var CanUpdateCompany */ + private $canUpdateCompany; + + /** @var UpdatesCompanyDebtor */ + private $updatesCompanyDebtor; + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** + * UpdateCompanyControllersLogic constructor. + * @param CanUpdateCompany $canUpdateCompany + * @param UpdatesCompanyDebtor $updatesCompanyDebtor + * @param FetchesCompany $fetchesCompany + */ + public function __construct(CanUpdateCompany $canUpdateCompany, UpdatesCompanyDebtor $updatesCompanyDebtor, FetchesCompany $fetchesCompany) + { + $this->canUpdateCompany = $canUpdateCompany; + $this->updatesCompanyDebtor = $updatesCompanyDebtor; + $this->fetchesCompany = $fetchesCompany; + } + + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + $debtor = $request->input('debtor'); + + $query = $this->fetchesCompany->execute(['id' => $request->route('id')]); + + $query = $this->updatesCompanyDebtor->execute($query, $debtor); + + return $this->resourceResponse(new CompanyResource($query)); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Companies/Services/UpdatesCompanyDebtor.php b/app/Classes/Modules/Companies/Services/UpdatesCompanyDebtor.php new file mode 100644 index 00000000..4cb43a9f --- /dev/null +++ b/app/Classes/Modules/Companies/Services/UpdatesCompanyDebtor.php @@ -0,0 +1,23 @@ +debtor = $debtor; + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Exports/Services/ExportsNullDebtors.php b/app/Classes/Modules/Exports/Services/ExportsNullDebtors.php new file mode 100644 index 00000000..e585275c --- /dev/null +++ b/app/Classes/Modules/Exports/Services/ExportsNullDebtors.php @@ -0,0 +1,100 @@ +reference, //Code + $company->name, //CompanyName + '', //Desc2 + '', //AreaCode + '', //SalesAgent + '', //DebtorType + '', //DisplayTerm + '', //AgingOn + '', //StatementType + 'MYR', //CurrencyCode + $company->reference, //RegisterNo + '', //Address1 + '', //Address2 + '', //Address3 + '', //Address4 + '', //PostCode + '', //DeliverAddr1 + '', //DeliverAddr2 + '', //DeliverAddr3 + '', //DeliverAddr4 + '', //DeliverPostCode + '', //Attention + '', //Phone1 + '', //Phone2 + '', //Fax1 + '', //Fax2 + '', //ExemptNo + '', //ExpiryDate + '', //PriceCategory + ]; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Exports/Services/ExportsPaymentTransactions.php b/app/Classes/Modules/Exports/Services/ExportsPaymentTransactions.php new file mode 100644 index 00000000..606d3a76 --- /dev/null +++ b/app/Classes/Modules/Exports/Services/ExportsPaymentTransactions.php @@ -0,0 +1,115 @@ +request = $request; + } + + public function headings(): array + { + return [ + 'DocNo', + 'DocDate', + 'DebtorCode', + 'Ref', + 'Note', + 'ShipInfo', + 'Numbering', + 'AccNo', + 'DetailDescription', + 'FutherDEscription', + 'YourPONo', + 'YourPODate', + 'ProjNo', + 'UOM', + 'Qty', + 'UnitPrice', + 'SubTotal' + ]; + } + + /** + * @return \Illuminate\Support\Collection|mixed + */ + public function query() + { + $start_date = $this->request->input('start_date', null); + if ($start_date) { + $start_date = Carbon::parse($this->request->input('start_date'))->format('Y-m-d'); + } + + $end_date = $this->request->input('end_date', null); + if ($end_date) { + $end_date = Carbon::parse($this->request->input('end_date'))->format('Y-m-d'); + } + + $query = Transaction::query(); + + $query->where('type', TransactionType::PAYMENT); + $query->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]); + + if($start_date && $end_date) { + $query->whereBetween('created_at', [ + Carbon::parse($start_date)->format('Y-m-d 0:00:00'), + Carbon::parse($end_date)->format('Y-m-d 23:59:59') + ]); + } + elseif($start_date && !$end_date) { + $query->where('created_at', '>=', Carbon::parse($start_date)->format('Y-m-d 0:00:00')); + } + elseif(!$start_date && $end_date) { + $query->where('created_at', '<=', Carbon::parse($end_date)->format('Y-m-d 23:59:59')); + } + + return $query; + } + + /** + * @param Company $transaction + * + * @return array + */ + public function map($transaction): array + { + $booking = $transaction->owner()->first(); + $company = $booking->company()->first(); + + return [ + '<>', + $transaction->updated_at, + $company->debtor, + '', + '', + $booking->marking, + '', + '500-0000', + 'PLEASE REFER TO THE ATTACHED APPENDIX REF ' . $booking->marking, + '', + '', + '', + '', + '', + 1, + $transaction->amount, + $transaction->amount, + ]; + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Imports/Services/ImportsDebtor.php b/app/Classes/Modules/Imports/Services/ImportsDebtor.php new file mode 100644 index 00000000..ad91a689 --- /dev/null +++ b/app/Classes/Modules/Imports/Services/ImportsDebtor.php @@ -0,0 +1,44 @@ +first(); + + if ($company) { + $company->debtor = $debtor; + $company->update(); + } + + return []; + } + + public function batchSize(): int + { + return 100; + } + + public function rules(): array + { + return [ + + ]; + } +} diff --git a/app/Classes/Modules/SegmentConstants/ControllersLogic/CreateSegmentConstantLogic.php b/app/Classes/Modules/SegmentConstants/ControllersLogic/CreateSegmentConstantLogic.php new file mode 100644 index 00000000..12b26ad6 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/ControllersLogic/CreateSegmentConstantLogic.php @@ -0,0 +1,70 @@ + 'Created Segment Constant', + 'message' => 'You have successfully created a new Segment Constant' + ]; + } + + /** @var CanCreateConstant */ + private $canCreateConstant; + + /** @var CreatesConstant */ + private $createsConstant; + + /** @var FetchesSegment */ + private $fetchesSegment; + + + /** + * CreateSegmentLogic constructor. + * @param CanCreateConstant $canCreateConstant + * @param CreatesConstant $createsConstant + */ + public function __construct(CanCreateConstant $canCreateConstant, CreatesConstant $createsConstant, FetchesSegment $fetchesSegment) + { + $this->canCreateConstant = $canCreateConstant; + $this->createsConstant = $createsConstant; + $this->fetchesSegment = $fetchesSegment; + } + + /** + * @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 + { + $constant_object = new ConstantObject($request->input('name'), $request->input('reference'), $request->input('detail')); + + $segment = $this->fetchesSegment->execute(['id' => $request->input('segment_id')]); + + $this->canCreateConstant->passes($constant_object); + $constant = $this->createsConstant->execute($segment, $constant_object); + + return $this->resourceResponse(new ConstantResource($constant)); + + } +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/ControllersLogic/FetchSegmentConstantLogic.php b/app/Classes/Modules/SegmentConstants/ControllersLogic/FetchSegmentConstantLogic.php new file mode 100644 index 00000000..43c10039 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/ControllersLogic/FetchSegmentConstantLogic.php @@ -0,0 +1,51 @@ + 'Retrieved Segment Constant', + 'message' => 'You have successfully retrieved a segment constant' + ]; + } + + /** @var FetchesConstant */ + private $fetchesConstant; + + /** + * FetchSegmentLogic constructor. + * @param FetchesConstant $fetchesConstant + */ + public function __construct(FetchesConstant $fetchesConstant) + { + $this->fetchesConstant = $fetchesConstant; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + $query = $this->fetchesConstant->execute(['id' => $request->route('id')]); + + return $this->resourceResponse(new ConstantResource($query)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/SegmentConstants/ControllersLogic/UpdateSegmentConstantLogic.php b/app/Classes/Modules/SegmentConstants/ControllersLogic/UpdateSegmentConstantLogic.php new file mode 100644 index 00000000..49897e95 --- /dev/null +++ b/app/Classes/Modules/SegmentConstants/ControllersLogic/UpdateSegmentConstantLogic.php @@ -0,0 +1,88 @@ + 'Updated Segment Constant', + 'message' => 'You have successfully updated the Segment Constant' + ]; + } + + /** @var CanUpdateConstant */ + private $canUpdateConstant; + + /** @var UpdatesConstant */ + private $updatesConstant; + + /** @var FetchesConstant */ + private $fetchesConstant; + + + /** + * UpdateSegmentLogic constructor. + * @param CanUpdateConstant $canUpdateConstant + * @param UpdatesConstant $updatesConstant + * @param FetchesConstant $fetchesConstant + */ + public function __construct( + CanUpdateConstant $canUpdateConstant, + UpdatesConstant $updatesConstant, + FetchesConstant $fetchesConstant + ) + { + $this->canUpdateConstant = $canUpdateConstant; + $this->updatesConstant = $updatesConstant; + $this->fetchesConstant = $fetchesConstant; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + DB::beginTransaction(); + + $constant_query = $this->fetchesConstant->execute(['id' => $request->route('id')]); + + $constant_object = new ConstantObject( + $request->input('name', $constant_query->name), + $request->input('reference', $constant_query->reference), + $request->input('detail', (array) $constant_query->detail)); + $this->canUpdateConstant->passes($constant_object); + $constant_query = $this->updatesConstant->execute($constant_query, $constant_object); + + DB::commit(); + + return $this->resourceResponse(new ConstantResource($constant_query)); + + } catch (\Exception $exception){ + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + } + +} \ 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 16fc76d3..93caf8d1 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php @@ -3,31 +3,37 @@ namespace App\Classes\Modules\Transactions\ControllersLogic; +use DB; +use Carbon\Carbon; +use App\Models\Document; +use Barryvdh\DomPDF\PDF; +use App\Models\Transaction; +use Illuminate\Support\Str; +use Illuminate\Http\Request; +use App\Models\SegmentConstant; +use Illuminate\Http\JsonResponse; +use Illuminate\Support\Facades\Storage; +use Meneses\LaravelMpdf\Facades\LaravelMpdf; +use App\Classes\ValueObjects\Constants\DocumentType; +use App\Classes\ValueObjects\Constants\ApprovalStatus; +use App\Classes\ValueObjects\Constants\TransactionType; +use App\Classes\Modules\Documents\Services\CreatesFiles; +use App\Classes\ValueObjects\Constants\SegmentConstants; +use App\Classes\ValueObjects\Constants\PaymentMethodType; use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Companies\Services\FetchesCompany; -use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject; -use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject; -use App\Classes\Modules\Transactions\Services\CreatesTransaction; -use App\Classes\Modules\Transactions\Services\FetchesTransaction; -use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber; -use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus; -use App\Classes\Modules\Documents\Services\CreatesDocument; -use App\Classes\Modules\Documents\Services\CreatesFiles; -use App\Classes\ValueObjects\Constants\ApprovalStatus; -use App\Classes\ValueObjects\Constants\PaymentMethodType; -use App\Classes\ValueObjects\Constants\TransactionType; -use App\Classes\ValueObjects\Constants\DocumentType; -use App\Models\Document; -use App\Models\Transaction; -use Barryvdh\DomPDF\PDF; -use Carbon\Carbon; -use Illuminate\Http\JsonResponse; -use Illuminate\Http\Request; -use Illuminate\Support\Facades\Storage; -use Illuminate\Support\Str; - +use App\Classes\Modules\Segments\Services\FetchesConstant; use Meneses\LaravelLaravelMpdf\Facades\LaravelLaravelMpdf; -use Meneses\LaravelMpdf\Facades\LaravelMpdf; +use App\Classes\Modules\Documents\Services\CreatesDocument; +use App\Classes\Modules\Transactions\Services\CreatesTransaction; + +use App\Classes\Modules\Transactions\Services\FetchesTransaction; +use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject; +use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus; +use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject; +use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber; +use App\Classes\Modules\Transactions\Services\CalculatesTransactionTransferFee; +use App\Classes\Modules\Transactions\Services\CalculatesTransactionServiceCharge; class CreateSupplierTransactionLogic extends AbstractControllerLogic { @@ -64,6 +70,12 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic /** @var GeneratesTransactionBillNumber */ private $generatesTransactionBillNumber; + /** @var CalculatesTransactionServiceCharge */ + private $calculatesTransactionServiceCharge; + + /** @var CalculatesTransactionTransferFee */ + private $calculatesTransactionTransferFee; + /** @var PDF */ private $pdf; @@ -71,21 +83,27 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic * CreateSupplierTransactionLogic constructor. * @param FetchesCompany $fetchesCompany * @param FetchesTransaction $fetchesTransaction + * @param FetchesConstant $fetchesConstant * @param UpdatesTransactionStatus $updatesTransactionStatus * @param CreatesTransaction $createsTransaction * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber + * @param CalculatesTransactionServiceCharge $calculatesTransactionServiceCharge + * @param CalculatesTransactionTransferFee $calculatesTransactionTransferFee * @param PDF $pdf */ - public function __construct(FetchesCompany $fetchesCompany, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, CreatesTransaction $createsTransaction, CreatesDocument $createsDocument, CreatesFiles $createsFile, GeneratesTransactionBillNumber $generatesTransactionBillNumber, PDF $pdf) + public function __construct(FetchesCompany $fetchesCompany, FetchesTransaction $fetchesTransaction, FetchesConstant $fetchesConstant, UpdatesTransactionStatus $updatesTransactionStatus, CreatesTransaction $createsTransaction, CreatesDocument $createsDocument, CreatesFiles $createsFile, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CalculatesTransactionServiceCharge $calculatesTransactionServiceCharge, CalculatesTransactionTransferFee $calculatesTransactionTransferFee, PDF $pdf) { $this->fetchesCompany = $fetchesCompany; $this->fetchesTransaction = $fetchesTransaction; + $this->fetchesConstant = $fetchesConstant; $this->updatesTransactionStatus = $updatesTransactionStatus; $this->createsTransaction = $createsTransaction; $this->createsDocument = $createsDocument; $this->createsFile = $createsFile; $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + $this->calculatesTransactionServiceCharge = $calculatesTransactionServiceCharge; + $this->calculatesTransactionTransferFee = $calculatesTransactionTransferFee; $this->pdf = $pdf; } @@ -97,6 +115,7 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic $rate = $request->input('rate'); $transactions = collect(); + $transferFeeTransactions = collect(); foreach($request->input('payments') as $payment){ @@ -107,17 +126,30 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic $this->updatesTransactionStatus->execute($payment, ApprovalStatus::COMPLETED); $billNumber = $this->generatesTransactionBillNumber->execute('SPLR-'); + // $constant = $this->fetchesConstant->execute(['service_charge' => $supplier->id]); + $constant = SegmentConstant::where('reference', SegmentConstants::SERVICE_CHARGE)->where('detail->id', $supplier->id)->first(); + $serviceCharge = $this->calculatesTransactionServiceCharge->execute($payment->original_amount, $rate, $constant ? $constant->detail->service_charge->amount : 0); + $object = new TransactionObject($billNumber, TransactionType::BILL, $supplier->id, 1, $supplier->banks()->where('default', true)->first()->id, PaymentMethodType::CASH, $payment->original_amount * (1 / $rate), $payment->original_amount, 1, $payment->original_currency_id, - $rate, 0, 0, null, ApprovalStatus::PENDING_VERIFICATION); + $rate, 0, $supplier->id == 2 ? 0 : $serviceCharge, null, ApprovalStatus::PENDING_VERIFICATION); - $transactions[] = $this->createsTransaction->execute($payment, $object); + $transactions[] = $billTransaction = $this->createsTransaction->execute($payment->booking, $object); + + $transferFeeNumber = $this->generatesTransactionBillNumber->execute('TRFR-'); + $trasferFee = $this->calculatesTransactionTransferFee->execute($payment->original_amount); + $object = new TransactionObject($transferFeeNumber, TransactionType::TRANSFER_FEE, 1, $supplier->id, + $supplier->banks()->where('default', true)->first()->id, PaymentMethodType::CASH, + $payment->original_amount, $payment->original_amount, $payment->original_currency_id, $payment->original_currency_id, + 1, 0, $trasferFee, null, ApprovalStatus::PENDING_VERIFICATION); + + $transferFeeTransactions[] = $this->createsTransaction->execute($billTransaction, $object); } if(!count($transactions)) return $this->response([]); - $pdf = LaravelMpdf::loadView('pages.pdfs.currency_vendor_order', ['transactions' => $transactions, 'supplier' => $supplier]); + $pdf = LaravelMpdf::loadView('pages.pdfs.currency_vendor_order', ['transactions' => $transactions, 'transferFeeTransactions' => $transferFeeTransactions, 'supplier' => $supplier]); $path = Str::studly($supplier->name).'_'.Carbon::now()->format('Y_m_d_h_s_i').'.pdf'; diff --git a/app/Classes/Modules/Transactions/ControllersLogic/FetchBankAccountBalanceLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/FetchBankAccountBalanceLogic.php new file mode 100644 index 00000000..5ffa11bf --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/FetchBankAccountBalanceLogic.php @@ -0,0 +1,46 @@ + 'Retrieved Bank Balance Account', + 'message' => 'You have successfully retrieved bank balance account' + ]; + } + + /** @var GeneratesBankBalanceAccount */ + private $generatesBankBalanceAccount; + + /** + * FetchCompanyAccountBalanceLogic constructor. + * @param GeneratesBankBalanceAccount $generatesBankBalanceAccount + */ + public function __construct(GeneratesBankBalanceAccount $generatesBankBalanceAccount) + { + $this->generatesBankBalanceAccount = $generatesBankBalanceAccount; + } + + public function logic(Request $request) : JsonResponse + { + $bank = Bank::find($request->route('id')); + + return $this->response(['data' => $this->generatesBankBalanceAccount->execute($bank)]); + + } + + + +} diff --git a/app/Classes/Modules/Transactions/ControllersLogic/FetchCompanyAccountBalanceLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/FetchCompanyAccountBalanceLogic.php new file mode 100644 index 00000000..b73f5ca3 --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/FetchCompanyAccountBalanceLogic.php @@ -0,0 +1,46 @@ + 'Retrieved Company Balance Account', + 'message' => 'You have successfully retrieved company balance account' + ]; + } + + /** @var GeneratesCompanyBalanceAccount */ + private $generatesCompanyBalanceAccount; + + /** + * FetchCompanyAccountBalanceLogic constructor. + * @param GeneratesCompanyBalanceAccount $generatesCompanyBalanceAccount + */ + public function __construct(GeneratesCompanyBalanceAccount $generatesCompanyBalanceAccount) + { + $this->generatesCompanyBalanceAccount = $generatesCompanyBalanceAccount; + } + + public function logic(Request $request) : JsonResponse + { + $company = Company::find($request->route('id')); + + return $this->response(['data' => $this->generatesCompanyBalanceAccount->execute($company)]); + + } + + + +} diff --git a/app/Classes/Modules/Transactions/ControllersLogic/UpdateRefundTransactionStatusLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/UpdateRefundTransactionStatusLogic.php new file mode 100644 index 00000000..d760b05d --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/UpdateRefundTransactionStatusLogic.php @@ -0,0 +1,85 @@ + 'Updated Transaction', + 'message' => 'You have successfully updated a transaction' + ]; + } + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** @var FetchesTransaction */ + private $fetchesTransaction; + + /** @var UpdatesTransactionStatus */ + private $updatesTransactionStatus; + + /** @var DeletesDocument */ + private $deletesDocument; + + /** @var CreditWalletProcessor */ + private $creditWalletProcessor; + + /** + * CreatePaymentVerificationDocumentLogic constructor. + * @param FetchesCompany $fetchesCompany + * @param FetchesTransaction $fetchesTransaction + * @param UpdatesTransactionStatus $updatesTransactionStatus + * @param DeletesDocument $deletesDocument + * @param CreditWalletProcessor $creditWalletProcessor + */ + public function __construct(FetchesCompany $fetchesCompany, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, DeletesDocument $deletesDocument, CreditWalletProcessor $creditWalletProcessor) + { + $this->fetchesCompany = $fetchesCompany; + $this->fetchesTransaction = $fetchesTransaction; + $this->updatesTransactionStatus = $updatesTransactionStatus; + $this->deletesDocument = $deletesDocument; + $this->creditWalletProcessor = $creditWalletProcessor; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + $transaction = $this->fetchesTransaction->execute(['id' => $request->route('id')]); + + $transaction = $this->updatesTransactionStatus->execute($transaction, $request->input('status')); + + $company = $this->fetchesCompany->execute(['id' => $transaction->booking->company_id]); + + $reference = 'Refund for booking reference '.$transaction->booking->marking; + + if ($transaction->status == ApprovalStatus::APPROVED) { + // add to credit wallet + $this->creditWalletProcessor->execute($company, $transaction->type, $transaction->amount, $reference); + } + + return $this->response([]); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Services/CalculatesTransactionServiceCharge.php b/app/Classes/Modules/Transactions/Services/CalculatesTransactionServiceCharge.php new file mode 100644 index 00000000..641e3903 --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/CalculatesTransactionServiceCharge.php @@ -0,0 +1,19 @@ +checksIfTransactionBillNumberExists = $checksIfTransactionBillNumberExists; + } + + + /** + * @param Bank $bank + */ + public function execute(Bank $bank) { + $floatTransactions = $bank->recipientTransactions()->where('transactions.type', TransactionType::BILL)->whereIn('transactions.status', [ApprovalStatus::APPROVED])->orderBy('id', 'DESC')->get(); + $transferFeeTransactions = $bank->recipientTransactions()->where('transactions.type', TransactionType::TRANSFER_FEE)->whereIn('transactions.status', [ApprovalStatus::APPROVED])->orderBy('id', 'DESC')->get(); + + $creditNoteTransactions = []; + foreach($transferFeeTransactions as $transferFeeTransaction){ + $creditNoteTransactions[] = $transferFeeTransaction->creditNoteTransaction; + } + $creditNoteTransactions = new Collection($creditNoteTransactions); + + return [ + 'bank' => new BankResource($bank), + 'floatTransactions' => $floatTransactions, + 'transferFeeTransactions' => $transferFeeTransactions, + 'creditNoteTransactions' => $creditNoteTransactions, + 'account_balance' => $floatTransactions->sum('amount') + $transferFeeTransactions->sum('amount') - $creditNoteTransactions->sum('amount'), + ]; + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Services/GeneratesCompanyBalanceAccount.php b/app/Classes/Modules/Transactions/Services/GeneratesCompanyBalanceAccount.php new file mode 100644 index 00000000..cfbe8ee2 --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/GeneratesCompanyBalanceAccount.php @@ -0,0 +1,50 @@ +checksIfTransactionBillNumberExists = $checksIfTransactionBillNumberExists; + } + + + /** + * @param Company $company + */ + public function execute(Company $company) { + $transferFeeTransactions = $company->issuerTransactions()->where('transactions.type', TransactionType::TRANSFER_FEE)->whereIn('transactions.status', [ApprovalStatus::APPROVED])->orderBy('id', 'DESC')->get(); + + $creditNoteTransactions = []; + foreach($transferFeeTransactions as $transferFeeTransaction){ + $creditNoteTransactions[] = $transferFeeTransaction->creditNoteTransaction; + } + $creditNoteTransactions = new Collection($creditNoteTransactions); + + return [ + 'company' => new CompanyResource($company), + 'transferFeeTransactions' => $transferFeeTransactions, + 'creditNoteTransactions' => $creditNoteTransactions, + 'account_balance' => $transferFeeTransactions->sum('amount') - $creditNoteTransactions->sum('amount'), + ]; + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Wallets/ControllersLogic/CreditWalletLogic.php b/app/Classes/Modules/Wallets/ControllersLogic/CreditWalletLogic.php index 60dd95cb..8ed8aa08 100644 --- a/app/Classes/Modules/Wallets/ControllersLogic/CreditWalletLogic.php +++ b/app/Classes/Modules/Wallets/ControllersLogic/CreditWalletLogic.php @@ -2,25 +2,19 @@ namespace App\Classes\Modules\Wallets\ControllersLogic; -use App\Classes\General\Abstracts\AbstractControllerLogic; -use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject; -use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject; -use App\Classes\Modules\Companies\Services\FetchesCompany; +use Illuminate\Http\Request; +use Illuminate\Http\JsonResponse; +use App\Http\Resources\WalletResource; 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\Transactions\Services\CreatesTransaction; use App\Classes\Modules\Wallets\Services\UpdatesWallet; -use App\Classes\ValueObjects\Constants\TransactionType; -use App\Classes\ValueObjects\Constants\PaymentMethodType; -use App\Classes\ValueObjects\Constants\ApprovalStatus; -use App\Http\Resources\WalletResource; +use App\Classes\General\Abstracts\AbstractControllerLogic; +use App\Classes\Modules\Companies\Services\FetchesCompany; +use App\Classes\Modules\Wallets\Services\GeneratesWalletCode; -use ErrorException; -use Illuminate\Http\JsonResponse; -use Illuminate\Http\Request; -use Illuminate\Support\Facades\DB; +use App\Classes\Modules\Transactions\Services\CreatesTransaction; +use App\Classes\Modules\Wallets\Processors\CreditWalletProcessor; +use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber; class CreditWalletLogic extends AbstractControllerLogic { @@ -53,6 +47,9 @@ class CreditWalletLogic extends AbstractControllerLogic /** @var UpdatesWallet */ private $updatesWallet; + /** @var CreditWalletProcessor */ + private $creditWalletProcessor; + /** * CreateWalletLogic constructor. * @param FetchesCompany $fetchesCompany @@ -61,6 +58,7 @@ class CreditWalletLogic extends AbstractControllerLogic * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber * @param CreatesTransaction $createsTransaction * @param UpdatesWallet $updatesWallet + * @param CreditWalletProcessor $creditWalletProcessor */ public function __construct( FetchesCompany $fetchesCompany, @@ -68,7 +66,8 @@ class CreditWalletLogic extends AbstractControllerLogic CreatesWallet $createsWallet, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesTransaction $createsTransaction, - UpdatesWallet $updatesWallet + UpdatesWallet $updatesWallet, + CreditWalletProcessor $creditWalletProcessor ) { $this->fetchesCompany = $fetchesCompany; @@ -77,6 +76,7 @@ class CreditWalletLogic extends AbstractControllerLogic $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; $this->createsTransaction = $createsTransaction; $this->updatesWallet = $updatesWallet; + $this->creditWalletProcessor = $creditWalletProcessor; } /** @@ -94,23 +94,7 @@ class CreditWalletLogic extends AbstractControllerLogic $type = $request->input('transaction_type'); - if (!$company->wallets()->first()) { - $object = new WalletObject($company->id, 1, $this->generatesWalletCode->execute()); - $this->createsWallet->execute($object, $company); - } - - $wallet = $company->wallets()->first(); - - $billNumber = $this->generatesTransactionBillNumber->execute($type === 2 ? 'DEBIT-NOTE-' : 'CREDIT-NOTE-'); - - $transaction_object = new TransactionObject($billNumber, $type === 2 ? TransactionType::DEBIT_NOTE : TransactionType::CREDIT_NOTE, 1, $wallet->owner->id, 1, PaymentMethodType::CASH, $amount, $amount, 1, 1, 1, 0, 0, null, ApprovalStatus::APPROVED, [], $reference); - $transaction = $this->createsTransaction->execute($wallet, $transaction_object); - - $updateWalletAmount = $type === 2 ? ($wallet->amount - $transaction->amount) : ($wallet->amount + $transaction->amount); - - $walletObject = new WalletObject($wallet->owner->id, $wallet->currency_id, $wallet->code, $updateWalletAmount); - - $wallet = $this->updatesWallet->execute($wallet, $walletObject); + $wallet = $this->creditWalletProcessor->execute($company, $type, $amount, $reference); return $this->resourceResponse(new WalletResource($wallet)); } diff --git a/app/Classes/Modules/Wallets/Processors/CreditWalletProcessor.php b/app/Classes/Modules/Wallets/Processors/CreditWalletProcessor.php new file mode 100644 index 00000000..2b303938 --- /dev/null +++ b/app/Classes/Modules/Wallets/Processors/CreditWalletProcessor.php @@ -0,0 +1,89 @@ +generatesWalletCode = $generatesWalletCode; + $this->createsWallet = $createsWallet; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + $this->createsTransaction = $createsTransaction; + $this->updatesWallet = $updatesWallet; + } + + + /** + * @param Company $company + * @param int $transactionType + * @param float $amount + * @param string $reference + * @return \Illuminate\Database\Eloquent\Model + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function execute(Company $company, int $transactionType, float $amount, string $reference) + { + if (!$company->wallets()->first()) { + $object = new WalletObject($company->id, 1, $this->generatesWalletCode->execute()); + $wallet = $this->createsWallet->execute($object, $company); + } + + $wallet = $company->wallets()->first(); + + $billNumber = $this->generatesTransactionBillNumber->execute($transactionType === 2 ? 'DEBIT-NOTE-' : 'CREDIT-NOTE-'); + + $transaction_object = new TransactionObject($billNumber, $transactionType === 2 ? TransactionType::DEBIT_NOTE : TransactionType::CREDIT_NOTE, 1, $wallet->owner->id, 1, PaymentMethodType::CASH, $amount, $amount, 1, 1, 1, 0, 0, null, ApprovalStatus::APPROVED, [], $reference); + $transaction = $this->createsTransaction->execute($wallet, $transaction_object); + + $updateWalletAmount = $transactionType === 2 ? ($wallet->amount - $transaction->amount) : ($wallet->amount + $transaction->amount); + + $walletObject = new WalletObject($wallet->owner->id, $wallet->currency_id, $wallet->code, $updateWalletAmount); + + $wallet = $this->updatesWallet->execute($wallet, $walletObject); + + return $wallet; + } +} diff --git a/app/Classes/ValueObjects/Constants/BusinessType.php b/app/Classes/ValueObjects/Constants/BusinessType.php index d24b975d..831568e9 100644 --- a/app/Classes/ValueObjects/Constants/BusinessType.php +++ b/app/Classes/ValueObjects/Constants/BusinessType.php @@ -10,4 +10,6 @@ final class BusinessType { public const CURRENCY_VENDOR = 3; + public const TRANSFER_AGENT = 4; + } diff --git a/app/Classes/ValueObjects/Constants/SegmentConstants.php b/app/Classes/ValueObjects/Constants/SegmentConstants.php index 80e9cb71..dd6b093a 100644 --- a/app/Classes/ValueObjects/Constants/SegmentConstants.php +++ b/app/Classes/ValueObjects/Constants/SegmentConstants.php @@ -20,4 +20,8 @@ class SegmentConstants public const CUSTOM_SERVICE_TYPE = 'CUSTOM_SERVICE_TYPE'; + public const SERVICE_CHARGE = 'SERVICE_CHARGE'; + + public const TRANSFER_FEE = 'TRANSFER_FEE'; + } \ No newline at end of file diff --git a/app/Classes/ValueObjects/Constants/TransactionType.php b/app/Classes/ValueObjects/Constants/TransactionType.php index 040f63fa..107f2049 100644 --- a/app/Classes/ValueObjects/Constants/TransactionType.php +++ b/app/Classes/ValueObjects/Constants/TransactionType.php @@ -27,4 +27,6 @@ final class TransactionType { public const DEBIT_NOTE = 11; public const WITHDRAW = 10; + + public const TRANSFER_FEE = 11; } diff --git a/app/Http/Controllers/Companies/UpdateCompanyDebtorController.php b/app/Http/Controllers/Companies/UpdateCompanyDebtorController.php new file mode 100644 index 00000000..af62c4f9 --- /dev/null +++ b/app/Http/Controllers/Companies/UpdateCompanyDebtorController.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 cdd1c49a..3df1e004 100644 --- a/app/Http/Controllers/Exports/ExportCustomersToExcelController.php +++ b/app/Http/Controllers/Exports/ExportCustomersToExcelController.php @@ -5,6 +5,9 @@ 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\ExportsNullDebtors; +use App\Classes\Modules\Exports\Services\ExportsPaymentTransactions; + use App\Models\User; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; @@ -12,7 +15,6 @@ use Maatwebsite\Excel\Excel; class ExportCustomersToExcelController { - public function export(ExportsCustomers $exportsCustomers, Request $request){ $token = Auth::fromUser(User::find(1)); $request->headers->set('Authorization', 'Bearer '.$token); @@ -24,4 +26,17 @@ class ExportCustomersToExcelController $request->headers->set('Authorization', 'Bearer '.$token); return $exportsTransactions->download('transactions.csv', Excel::CSV, ['Content-Type' => 'text/csv']); } + + public function nullDebtor(ExportsNullDebtors $exportsNullDebtors, Request $request){ + $token = Auth::fromUser(User::find(1)); + $request->headers->set('Authorization', 'Bearer '.$token); + return $exportsNullDebtors->download('nullDebtor.csv', Excel::CSV, ['Content-Type' => 'text/csv']); + } + + public function paymentTransactions(Request $request){ + $token = Auth::fromUser(User::find(1)); + $request->headers->set('Authorization', 'Bearer '.$token); + $exportsTransactions = new ExportsPaymentTransactions($request); + return $exportsTransactions->download('payment-transactions.csv', Excel::CSV, ['Content-Type' => 'text/csv']); + } } \ No newline at end of file diff --git a/app/Http/Controllers/Imports/ImportUpdateDebtorController.php b/app/Http/Controllers/Imports/ImportUpdateDebtorController.php new file mode 100644 index 00000000..83d1effd --- /dev/null +++ b/app/Http/Controllers/Imports/ImportUpdateDebtorController.php @@ -0,0 +1,25 @@ +headers->set('Authorization', 'Bearer '.$token); + + $excel_file = $request->input('excel_file'); + + $excel_file = ExcelHandel::insertExcel('debtor', $excel_file); + + return $import = Excel::import(new ImportsDebtor(), $excel_file[0]['file_info']['original']['file']); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/SegmentConstants/CreateSegmentConstantController.php b/app/Http/Controllers/SegmentConstants/CreateSegmentConstantController.php new file mode 100644 index 00000000..7520e1d1 --- /dev/null +++ b/app/Http/Controllers/SegmentConstants/CreateSegmentConstantController.php @@ -0,0 +1,19 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/SegmentConstants/FetchSegmentConstantController.php b/app/Http/Controllers/SegmentConstants/FetchSegmentConstantController.php new file mode 100644 index 00000000..67532d3f --- /dev/null +++ b/app/Http/Controllers/SegmentConstants/FetchSegmentConstantController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/SegmentConstants/UpdateSegmentConstantController.php b/app/Http/Controllers/SegmentConstants/UpdateSegmentConstantController.php new file mode 100644 index 00000000..c34914dc --- /dev/null +++ b/app/Http/Controllers/SegmentConstants/UpdateSegmentConstantController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Transactions/FetchBankAccountBalanceController.php b/app/Http/Controllers/Transactions/FetchBankAccountBalanceController.php new file mode 100644 index 00000000..0d8c89b4 --- /dev/null +++ b/app/Http/Controllers/Transactions/FetchBankAccountBalanceController.php @@ -0,0 +1,21 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Transactions/FetchCompanyAccountBalanceController.php b/app/Http/Controllers/Transactions/FetchCompanyAccountBalanceController.php new file mode 100644 index 00000000..d36b0605 --- /dev/null +++ b/app/Http/Controllers/Transactions/FetchCompanyAccountBalanceController.php @@ -0,0 +1,21 @@ +execute($request); + } +} diff --git a/app/Http/Controllers/Transactions/UpdateRefundTransactionStatusController.php b/app/Http/Controllers/Transactions/UpdateRefundTransactionStatusController.php new file mode 100644 index 00000000..919fadd1 --- /dev/null +++ b/app/Http/Controllers/Transactions/UpdateRefundTransactionStatusController.php @@ -0,0 +1,14 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Resources/CompanyResource.php b/app/Http/Resources/CompanyResource.php index 902c30bd..929432e3 100644 --- a/app/Http/Resources/CompanyResource.php +++ b/app/Http/Resources/CompanyResource.php @@ -57,6 +57,7 @@ class CompanyResource extends JsonResource 'default' => new BankResource($this->banks->where('type', BankAccountType::EXTERNAL)->where('default', true)->first()) ], 'segments' => SegmentResource::collection($this->segments), + 'service_charges' => SegmentConstant::where('reference', SegmentConstants::SERVICE_CHARGE)->where('detail->id', $this->id)->first(), 'services' => (new FetchesCompanyServices())->getServices($this->servicesConfigurations()), 'currencies' => $this->when($this->business_type === BusinessType::CURRENCY_VENDOR, function(){ $segment = SegmentConstant::where('reference', SegmentConstants::SUPPLIER_CURRENCIES)->where('detail->id', $this->id)->first(); diff --git a/app/Models/Bank.php b/app/Models/Bank.php index 9381b94a..3b0bb915 100644 --- a/app/Models/Bank.php +++ b/app/Models/Bank.php @@ -2,11 +2,12 @@ namespace App\Models; -use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\SoftDeletes; - use Illuminate\Database\Eloquent\Relations\HasOne; +use Illuminate\Database\Eloquent\Relations\HasMany; +use Illuminate\Database\Eloquent\Relations\BelongsTo; + /** * Class Bank * @package App\Models @@ -41,4 +42,12 @@ class Bank extends AbstractModel { return $this->BelongsTo(Company::class, 'company_id', 'id'); } + + /** + * @return HasMany + */ + public function recipientTransactions(): HasMany + { + return $this->HasMany(Transaction::class, 'recipient_bank_account_id'); + } } diff --git a/app/Models/Company.php b/app/Models/Company.php index 7b8e4387..def72720 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -101,6 +101,14 @@ class Company extends AbstractModel implements Documentable { return $this->hasManyDeep(Transaction::class, [Booking::class], ['company_id', 'owner_id'], ['id', 'id']); } + + /** + * @return HasMany + */ + public function issuerTransactions(): HasMany + { + return $this->HasMany(Transaction::class, 'issuer'); + } /** * @return MorphMany diff --git a/app/Models/SegmentConstant.php b/app/Models/SegmentConstant.php index 08c8b2af..b7fda276 100644 --- a/app/Models/SegmentConstant.php +++ b/app/Models/SegmentConstant.php @@ -20,6 +20,10 @@ class SegmentConstant extends AbstractModel protected $table = 'segment_constants'; protected $dates = ['deleted_at']; + + // protected $casts = [ + // 'detail' => 'array', + // ]; public function getDetailAttribute($value) { diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index f583567c..429449a6 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -30,14 +30,6 @@ class Transaction extends AbstractModel implements Documentable, Transactionable return $this->morphTo(); } - /** - * @return MorphMany - */ - public function booking(): BelongsTo - { - return $this->BelongsTo(Booking::class, 'owner_id', 'id'); - } - /** * @return MorphMany */ @@ -46,6 +38,22 @@ class Transaction extends AbstractModel implements Documentable, Transactionable return $this->MorphMany(Transaction::class, 'owner'); } + /** + * @return \Illuminate\Database\Eloquent\Relations\MorphOne + */ + public function creditNoteTransaction() + { + return $this->MorphOne(Transaction::class, 'owner')->where('type', TransactionType::CREDIT_NOTE); + } + + /** + * @return BelongsTo + */ + public function booking(): BelongsTo + { + return $this->BelongsTo(Booking::class, 'owner_id', 'id'); + } + /** * @return BelongsTo */ diff --git a/database/migrations/2022_02_20_203803_add_debtor_to_companies_table.php b/database/migrations/2022_02_20_203803_add_debtor_to_companies_table.php new file mode 100644 index 00000000..2798b9e7 --- /dev/null +++ b/database/migrations/2022_02_20_203803_add_debtor_to_companies_table.php @@ -0,0 +1,32 @@ +string('debtor')->nullable()->after('reference'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('companies', function (Blueprint $table) { + + }); + } +} diff --git a/resources/assets/vue/components/bookings/elements/BillingComponent.vue b/resources/assets/vue/components/bookings/elements/BillingComponent.vue index bfa8b2d9..6e03c040 100644 --- a/resources/assets/vue/components/bookings/elements/BillingComponent.vue +++ b/resources/assets/vue/components/bookings/elements/BillingComponent.vue @@ -11,7 +11,7 @@
- {{parameters.type}} + {{parameters.type.replaceAll('_', ' ')}}
@@ -27,10 +27,10 @@
-
+
-
{{document}}
+
{{document.replaceAll('_', ' ')}}
diff --git a/resources/assets/vue/components/bookings/elements/BillingDocumentComponent.vue b/resources/assets/vue/components/bookings/elements/BillingDocumentComponent.vue index 64f96d0e..095f574f 100644 --- a/resources/assets/vue/components/bookings/elements/BillingDocumentComponent.vue +++ b/resources/assets/vue/components/bookings/elements/BillingDocumentComponent.vue @@ -40,11 +40,15 @@
{{item.owner.amount}} {{item.owner.fixed_currency.short_code}}
- - - +
+
+ + + +
+
diff --git a/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue b/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue index af7eab83..ab0bb5c4 100644 --- a/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue +++ b/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue @@ -176,9 +176,9 @@
-
+
- + @@ -294,7 +294,7 @@ expandPaymentDetails: false, expandRefund: false, refundMethod: { - name: 'Fully Refund', + name: 'Partially Refund', status: false }, amount: (Math.round(1000 * 100) / 100).toFixed(2), diff --git a/resources/assets/vue/components/bookings/elements/RefundConfirmationComponent.vue b/resources/assets/vue/components/bookings/elements/RefundConfirmationComponent.vue index 9a810def..c954a374 100644 --- a/resources/assets/vue/components/bookings/elements/RefundConfirmationComponent.vue +++ b/resources/assets/vue/components/bookings/elements/RefundConfirmationComponent.vue @@ -10,7 +10,7 @@
-
+
@@ -23,61 +23,21 @@
Refund Type:
- - -
-
- Fully Refund -
-
+
+
Partially Refund
+
+ Fully Refund +
-
+
- +
@@ -90,61 +50,6 @@
-
-
-
-
-
- - -
-
-
-
-
-
-
-
-
-
- -
-
-
-
-
-
{{bank.reference ? bank.reference + ' - ':''}}{{bank.holder_name}}
-
-
-
-
-
{{bank.account_no}} {{bank.bank_name}}
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- -
-
-
-
- - -
-
@@ -153,95 +58,11 @@
-
-
-
-
-
-
-
Amount you are Transferring
-
-
- -
short_code
-
-
- -
amount
-
-
-
-
-
Exchange Rate
-
-
-
-
-
- -
rate
-
-
-
-
-
Money Transfer Fee
-
-
-
MYR
-
-
- -
amount
-
-
-
-
-
Sub-Total
-
-
-
MYR
-
-
- -
Sub-Total
-
-
-
-
-
Tax
-
-
- -
some%
-
-
- -
some tax
-
-
-
-
-
Amount you are Paying
-
-
-
MYR
-
-
- -
payming amount
-
-
-
-
-
-
-
-
@@ -251,86 +72,46 @@ \ No newline at end of file diff --git a/resources/assets/vue/components/companies/sections/CustomerSectionComponent.vue b/resources/assets/vue/components/companies/sections/CustomerSectionComponent.vue index be864c9a..65bed7f7 100644 --- a/resources/assets/vue/components/companies/sections/CustomerSectionComponent.vue +++ b/resources/assets/vue/components/companies/sections/CustomerSectionComponent.vue @@ -16,20 +16,49 @@ +
+
+ + + + +
+
+ + + + +
+
+
+
+ + + + +
+
+ + + + +
+
-
- +
+ +
-
+