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/Banks/ControllersLogic/UpdateBankLogic.php b/app/Classes/Modules/Banks/ControllersLogic/UpdateBankLogic.php index 85e3449c..9cb8fdd2 100644 --- a/app/Classes/Modules/Banks/ControllersLogic/UpdateBankLogic.php +++ b/app/Classes/Modules/Banks/ControllersLogic/UpdateBankLogic.php @@ -39,7 +39,6 @@ class UpdateBankLogic extends AbstractControllerLogic /** @var FetchesBank */ private $fetchesBank; - /** * UpdateBankLogic constructor. * @param CanUpdateBank $canUpdateBank @@ -66,11 +65,18 @@ class UpdateBankLogic extends AbstractControllerLogic */ public function logic(Request $request) : JsonResponse { - - $bankObject = new BankObject($request->input('company_id'), $request->input('country_id'), - $request->input('reference'), $request->input('bank_name'), $request->input('holder_name'), - $request->input('account_no')); - + $bankObject = new BankObject( + $request->input('company_id'), + $request->input('account_type'), + $request->input('bank_name'), + $request->input('holder_name'), + $request->input('account_no'), + $request->input('bank_branch'), + $request->input('swift'), + $request->input('snap'), + $request->input('country_id'), + $request->input('reference') + ); $bank = $this->fetchesBank->execute(['id' => $request->route('id')]); diff --git a/app/Classes/Modules/Banks/ControllersLogic/UpdateBankStatusLogic.php b/app/Classes/Modules/Banks/ControllersLogic/UpdateBankStatusLogic.php new file mode 100644 index 00000000..09ee2796 --- /dev/null +++ b/app/Classes/Modules/Banks/ControllersLogic/UpdateBankStatusLogic.php @@ -0,0 +1,62 @@ + 'Update Bank Account Status', + 'message' => 'You have successfully updated the Bank Account Status' + ]; + } + + /** @var FetchesBank */ + private $fetchesBank; + + /** @var UpdatesBankStatus */ + private $updatesBankStatus; + + /** + * UpdateBankStatusLogic constructor. + * @param FetchesBank $fetchesBank + * @param UpdatesBankStatus $updatesBankStatus + */ + public function __construct( + FetchesBank $fetchesBank, + UpdatesBankStatus $updatesBankStatus + ) + { + $this->fetchesBank = $fetchesBank; + $this->updatesBankStatus = $updatesBankStatus; + } + + /** + * @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 + { + $bank = $this->fetchesBank->execute(['id' => $request->route('id')]); + + $bank_query = $this->updatesBankStatus->execute($bank, $request->input('status')); + + return $this->resourceResponse(new BankResource($bank_query)); + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Banks/Services/UpdatesBank.php b/app/Classes/Modules/Banks/Services/UpdatesBank.php index 6367a6aa..69e8347a 100644 --- a/app/Classes/Modules/Banks/Services/UpdatesBank.php +++ b/app/Classes/Modules/Banks/Services/UpdatesBank.php @@ -23,7 +23,7 @@ class UpdatesBank extends AbstractUpdateRecord $model->bank_branch = $object->getBankBranch(); $model->swift = $object->getSwift(); $model->snap = $object->getSnap(); - $model->default = $object->getDefault(); + $model->reference = $object->getReference(); return $this->handler($model); } diff --git a/app/Classes/Modules/Banks/Services/UpdatesBankStatus.php b/app/Classes/Modules/Banks/Services/UpdatesBankStatus.php new file mode 100644 index 00000000..c080ad56 --- /dev/null +++ b/app/Classes/Modules/Banks/Services/UpdatesBankStatus.php @@ -0,0 +1,22 @@ +status = $status; + return $this->handler($model); + } +} \ 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..74e92fa6 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/CreateBookingRefundLogic.php @@ -78,31 +78,27 @@ class CreateBookingRefundLogic extends AbstractControllerLogic public function logic(Request $request) : JsonResponse { - $booking = Booking::find($request->route('id')); - $transaction = $this->fetchesTransaction->execute(['id' => $request->route('payment_id')]); + $booking = $transaction->owner; + $billNumber = $this->generatesTransactionBillNumber->execute('RFD-'); - if((int) $transaction->type === TransactionType::BILL){ - $customerBooking = $booking->transactions()->payments()->complete()->where('original_amount', '=', $transaction->original_amount)->where('id', '<', $transaction->id)->orderByDesc('id')->first(); - } - $refund = $this->calculatesBookingRefundAmount->execute($booking, $booking->fix_currency_id, $transaction->bill_no); - dd($refund); + $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, (int) $transaction->type === TransactionType::BILL ? $customerBooking : $transaction, $request->input('amount')); + $transactionRefundCalculationObject = new TransactionRefundCalculationObject($booking, $transaction, $request->input('amount')); $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); - $transaction = $this->createsTransaction->execute($booking, $object); + $transaction = $this->createsTransaction->execute($transaction, $object); return $this->resourceResponse(new TransactionResource($transaction)); } diff --git a/app/Classes/Modules/Bookings/ControllersLogic/FetchBookingPaymentQuotationLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/FetchBookingPaymentQuotationLogic.php index 5885d560..eaac0adc 100644 --- a/app/Classes/Modules/Bookings/ControllersLogic/FetchBookingPaymentQuotationLogic.php +++ b/app/Classes/Modules/Bookings/ControllersLogic/FetchBookingPaymentQuotationLogic.php @@ -72,7 +72,8 @@ class FetchBookingPaymentQuotationLogic extends AbstractControllerLogic return $this->response(['data' => $this->generatesBookingQuotation->execute( $this->fetchBookingQuotation->execute($booking->company, $conversionObject), - $this->fetchesCompanyPaymentAttemptLimit->execute($booking->company) + $this->fetchesCompanyPaymentAttemptLimit->execute($booking->company), + $conversionObject )]); } diff --git a/app/Classes/Modules/Bookings/Services/GeneratesBookingQuotation.php b/app/Classes/Modules/Bookings/Services/GeneratesBookingQuotation.php index 8f40187b..34f58d3a 100644 --- a/app/Classes/Modules/Bookings/Services/GeneratesBookingQuotation.php +++ b/app/Classes/Modules/Bookings/Services/GeneratesBookingQuotation.php @@ -4,6 +4,7 @@ namespace App\Classes\Modules\Bookings\Services; use App\Classes\Modules\Bookings\DataTransferObjects\CalculationObject; +use App\Classes\Modules\Currencies\DataTransferObjects\CurrencyConversionObject; use App\Http\Resources\BankResource; use App\Models\Bank; use Carbon\Carbon; @@ -12,12 +13,14 @@ use Carbon\CarbonInterval; class GeneratesBookingQuotation { - public function execute(CalculationObject $calculationObject, ?int $paymentAttemptLimit = 0){ + public function execute(CalculationObject $calculationObject, ?int $paymentAttemptLimit = 0, ?CurrencyConversionObject $currencyConversionObject = null){ $date = Carbon::now(); $days = $date->diffInDays($date->copy()->addMinutes($paymentAttemptLimit)); $hours = $date->diffInHours($date->copy()->addMinutes($paymentAttemptLimit)->subDays($days)) ; $minutes = $date->diffInMinutes($date->copy()->addMinutes($paymentAttemptLimit)->subDays($days)->subHours($hours)); + $receive_date = $currencyConversionObject ? Carbon::now()->endOfDay()->addWeekdays($currencyConversionObject->getServiceId() === 3 ? 4 : 2)->timezone('Asia/Singapore')->format('4:00 \P\M, jS M, Y \G\M\T T') : null; + return [ 'bank' => new BankResource(Bank::find($calculationObject->getConfigurations()->getBankId())), 'rate' => $calculationObject->getConfigurations()->getRate(), @@ -30,6 +33,7 @@ class GeneratesBookingQuotation 'sub_total' => $calculationObject->getSubTotal(), 'total' => $calculationObject->getTotal(), 'date' => Carbon::now()->timezone('Asia/Singapore')->format('h:i a, jS M, Y \G\M\T T'), + 'receive_date' => $receive_date, 'payment_attempt_limit' => CarbonInterval::days($days)->hours($hours)->minutes($minutes)->forHumans() ]; } diff --git a/app/Classes/Modules/Companies/ControllersLogic/FetchCompanyBookingQuotationLogic.php b/app/Classes/Modules/Companies/ControllersLogic/FetchCompanyBookingQuotationLogic.php index 37225631..926acaae 100644 --- a/app/Classes/Modules/Companies/ControllersLogic/FetchCompanyBookingQuotationLogic.php +++ b/app/Classes/Modules/Companies/ControllersLogic/FetchCompanyBookingQuotationLogic.php @@ -14,6 +14,7 @@ use App\Models\Company; use App\Models\Currency; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use Carbon\Carbon; class FetchCompanyBookingQuotationLogic extends AbstractControllerLogic { @@ -71,7 +72,7 @@ class FetchCompanyBookingQuotationLogic extends AbstractControllerLogic if($calculationObject->getConvertibleTotal() < $calculationObject->getConfigurations()->getMinLimit()) throw new RequestValidationException('Your transfer is below the minimum amount allowed of '.$calculationObject->getConfigurations()->getMinLimit().' '.$currency->short_code); //TODO add po limit validation - return $this->response(['data' => $this->generatesBookingQuotation->execute($calculationObject)]); + return $this->response(['data' => $this->generatesBookingQuotation->execute($calculationObject, 0, $conversionObject)]); } 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..189070ae --- /dev/null +++ b/app/Classes/Modules/Exports/Services/ExportsNullDebtors.php @@ -0,0 +1,109 @@ + ['font' => ['bold' => true]] + ]; + } + + public function headings(): array + { + return [ + 'Code', + 'CompanyName', + 'Desc2', + 'AreaCode', + 'SalesAgent', + 'DebtorType', + 'DisplayTerm', + 'AgingOn', + 'StatementType', + 'CurrencyCode', + 'RegisterNo', + 'Address1', + 'Address2', + 'Address3', + 'Address4', + 'PostCode', + 'DeliverAddr1', + 'DeliverAddr2', + 'DeliverAddr3', + 'DeliverAddr4', + 'DeliverPostCode', + 'Attention', + 'Phone1', + 'Phone2', + 'Fax1', + 'Fax2', + 'ExemptNo', + 'ExpiryDate', + 'PriceCategory', + ]; + } + + /** + * @return \Illuminate\Support\Collection|mixed + */ + public function query() + { + return Company::where('debtor', '=', null)->where('business_type', BusinessType::IMPORTER); + } + + /** + * @param Company $company + * + * @return array + */ + public function map($company): array + { + return [ + $company->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..c232ab5f --- /dev/null +++ b/app/Classes/Modules/Exports/Services/ExportsPaymentTransactions.php @@ -0,0 +1,116 @@ +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)->where('payment_method', '!=', PaymentMethodType::WALLET); + $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/Exports/Services/ExportsWalletTransactions.php b/app/Classes/Modules/Exports/Services/ExportsWalletTransactions.php new file mode 100644 index 00000000..626e8a9d --- /dev/null +++ b/app/Classes/Modules/Exports/Services/ExportsWalletTransactions.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::TOP_UP); + $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 + { + $company = $transaction->owner->owner; + + return [ + '<>', + $transaction->updated_at, + $company->debtor, + '', + '', + $company->reference, + '', + '500-0000', + 'BUYING CREDIT REF.' . $company->reference, + '', + '', + '', + '', + '', + 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..1cf71643 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php @@ -3,31 +3,19 @@ namespace App\Classes\Modules\Transactions\ControllersLogic; +use App\Classes\Modules\Transactions\Processors\CreateSupplierTransactionProcessor; +use App\Models\Document; +use Illuminate\Http\Request; +use Illuminate\Http\JsonResponse; +use Meneses\LaravelMpdf\Facades\LaravelMpdf; +use App\Classes\ValueObjects\Constants\DocumentType; +use App\Classes\ValueObjects\Constants\ApprovalStatus; +use App\Classes\Modules\Documents\Services\CreatesFiles; 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 Meneses\LaravelLaravelMpdf\Facades\LaravelLaravelMpdf; -use Meneses\LaravelMpdf\Facades\LaravelMpdf; +use App\Classes\Modules\Documents\Services\CreatesDocument; +use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject; class CreateSupplierTransactionLogic extends AbstractControllerLogic { @@ -46,14 +34,8 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic /** @var FetchesCompany */ private $fetchesCompany; - /** @var FetchesTransaction */ - private $fetchesTransaction; - - /** @var UpdatesTransactionStatus */ - private $updatesTransactionStatus; - - /** @var CreatesTransaction */ - private $createsTransaction; + /** @var CreateSupplierTransactionProcessor */ + private $createSupplierTransactionProcessor; /** @var CreatesDocument */ private $createsDocument; @@ -61,32 +43,19 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic /** @var CreatesFiles */ private $createsFile; - /** @var GeneratesTransactionBillNumber */ - private $generatesTransactionBillNumber; - - /** @var PDF */ - private $pdf; - /** * CreateSupplierTransactionLogic constructor. * @param FetchesCompany $fetchesCompany - * @param FetchesTransaction $fetchesTransaction - * @param UpdatesTransactionStatus $updatesTransactionStatus - * @param CreatesTransaction $createsTransaction - * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber - * @param PDF $pdf + * @param CreateSupplierTransactionProcessor $createSupplierTransactionProcessor + * @param CreatesDocument $createsDocument + * @param CreatesFiles $createsFile */ - public function __construct(FetchesCompany $fetchesCompany, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, CreatesTransaction $createsTransaction, CreatesDocument $createsDocument, CreatesFiles $createsFile, GeneratesTransactionBillNumber $generatesTransactionBillNumber, PDF $pdf) + public function __construct(FetchesCompany $fetchesCompany, CreateSupplierTransactionProcessor $createSupplierTransactionProcessor, CreatesDocument $createsDocument, CreatesFiles $createsFile) { - $this->fetchesCompany = $fetchesCompany; - $this->fetchesTransaction = $fetchesTransaction; - $this->updatesTransactionStatus = $updatesTransactionStatus; - $this->createsTransaction = $createsTransaction; + $this->createSupplierTransactionProcessor = $createSupplierTransactionProcessor; $this->createsDocument = $createsDocument; $this->createsFile = $createsFile; - $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; - $this->pdf = $pdf; } public function logic(Request $request) : JsonResponse @@ -96,30 +65,13 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic $rate = $request->input('rate'); - $transactions = collect(); + $payments = $request->input('payments'); - foreach($request->input('payments') as $payment){ + $this->createSupplierTransactionProcessor->execute($supplier, $rate, $payments); - /** @var Transaction $payment */ - $payment = $this->fetchesTransaction->execute(['id' => $payment['id']]); - - if($payment->status !== ApprovalStatus::APPROVED) continue; + if(!count($this->createSupplierTransactionProcessor->getBills())) return $this->response([]); - $this->updatesTransactionStatus->execute($payment, ApprovalStatus::COMPLETED); - $billNumber = $this->generatesTransactionBillNumber->execute('SPLR-'); - $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); - - $transactions[] = $this->createsTransaction->execute($payment, $object); - } - - if(!count($transactions)) return $this->response([]); - - $pdf = LaravelMpdf::loadView('pages.pdfs.currency_vendor_order', ['transactions' => $transactions, 'supplier' => $supplier]); - - $path = Str::studly($supplier->name).'_'.Carbon::now()->format('Y_m_d_h_s_i').'.pdf'; + $pdf = LaravelMpdf::loadView('pages.pdfs.currency_vendor_order', ['transactions' => $this->createSupplierTransactionProcessor->getBills(), 'transferFeeTransactions' => $this->createSupplierTransactionProcessor->getTransferTransactions(), 'supplier' => $supplier]); $object = new DocumentObject( DocumentType::CURRENCY_VENDOR_ORDER, diff --git a/app/Classes/Modules/Transactions/ControllersLogic/DownloadMockUpWhiteFormPdfLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/DownloadMockUpWhiteFormPdfLogic.php new file mode 100644 index 00000000..e1875f0a --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/DownloadMockUpWhiteFormPdfLogic.php @@ -0,0 +1,62 @@ +fetchesCompany = $fetchesCompany; + $this->createSupplierTransactionProcessor = $createSupplierTransactionProcessor; + } + + + /** + * @param Request $request + * @return string|\Symfony\Component\HttpFoundation\Response + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function execute(Request $request) + { + + $supplier = $this->fetchesCompany->execute(['id' => $request->route('id')]); + + $rate = $request->input('rate'); + + $payments = array_map(function($value){ + return ['id' => $value]; + }, json_decode($request->input('payments'))); + + DB::beginTransaction(); + + $this->createSupplierTransactionProcessor->execute($supplier, $rate, $payments); + + if(!count($this->createSupplierTransactionProcessor->getBills())) return 'unexpected error'; + + $pdf = LaravelMpdf::loadView('pages.pdfs.currency_vendor_order', ['transactions' => $this->createSupplierTransactionProcessor->getBills(), 'transferFeeTransactions' => $this->createSupplierTransactionProcessor->getTransferTransactions(), 'supplier' => $supplier]); + + DB::rollBack(); + + return $pdf->stream('MockUpWhiteForm.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..b86e4878 --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/UpdateRefundTransactionStatusLogic.php @@ -0,0 +1,86 @@ + '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')); + + $booking = $transaction->owner->owner; + + $reference = 'Credit Voucher for Overpaid for Ref. '.$booking->marking; + + if ($transaction->status == ApprovalStatus::APPROVED) { + $this->creditWalletProcessor->execute($booking->company, $transaction->type, $transaction->amount, $reference); + } + + + + return $this->response([]); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Processors/CreateSupplierTransactionProcessor.php b/app/Classes/Modules/Transactions/Processors/CreateSupplierTransactionProcessor.php new file mode 100644 index 00000000..75516fdf --- /dev/null +++ b/app/Classes/Modules/Transactions/Processors/CreateSupplierTransactionProcessor.php @@ -0,0 +1,143 @@ +fetchesTransaction = $fetchesTransaction; + $this->updatesTransactionStatus = $updatesTransactionStatus; + $this->createsTransaction = $createsTransaction; + $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + $this->calculatesTransactionServiceCharge = $calculatesTransactionServiceCharge; + $this->calculatesTransactionTransferFee = $calculatesTransactionTransferFee; + $this->bills = collect(); + $this->transferFee = collect(); + } + + /** + * @param Company $supplier + * @param String $rate + * @param array $payments + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function execute(Company $supplier, String $rate, Array $payments) { + + foreach($payments as $payment){ + + /** @var Transaction $payment */ + $payment = $this->fetchesTransaction->execute(['id' => $payment['id']]); + + if($payment->status !== ApprovalStatus::APPROVED) continue; + + $this->updatesTransactionStatus->execute($payment, ApprovalStatus::COMPLETED); + $billNumber = $this->generatesTransactionBillNumber->execute('SPLR-'); + $constant = SegmentConstant::where('reference', SegmentConstants::SERVICE_CHARGE)->where('detail->id', $supplier->id)->first(); + + $serviceCharge = $this->calculatesTransactionServiceCharge->execute($payment->original_amount, $rate, $constant); + + $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, $serviceCharge, null, ApprovalStatus::PENDING_VERIFICATION); + + /** @var Transaction $billTransaction */ + $billTransaction = $this->createsTransaction->execute($payment, $object); + $this->pushBill($billTransaction); + + $transferFeeNumber = $this->generatesTransactionBillNumber->execute('TRFR-'); + $transferFee = $this->calculatesTransactionTransferFee->execute($payment->original_amount, $constant); + $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, $transferFee, null, ApprovalStatus::PENDING_VERIFICATION); + + $this->pushTransferFee($this->createsTransaction->execute($billTransaction, $object)); + } + + } + + /** + * @return Collection + */ + public function getBills(): Collection + { + return $this->bills; + } + + /** + * @return Collection + */ + public function getTransferTransactions(): Collection + { + return $this->transferFee; + } + + /** + * @param $bill + */ + private function pushBill($bill): void + { + $this->bills->push($bill); + } + + /** + * @param $transferFee + */ + private function pushTransferFee($transferFee): void + { + $this->transferFee->push($transferFee); + } + +} \ 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..e04edee2 --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/CalculatesTransactionServiceCharge.php @@ -0,0 +1,39 @@ +calculatesTransactionTransferFee = $calculatesTransactionTransferFee; + } + + + /** + * @param float $amount + * @param float $rate + * @param SegmentConstant|null $service_charge + * @return float + */ + public function execute(float $amount, float $rate, ?SegmentConstant $service_charge) { + + if(!$service_charge) { + return 0; + } + + $transfer_fee = $this->calculatesTransactionTransferFee->execute($amount, $service_charge); + return $service_charge->detail->amount->type === 'percentage' ? (($amount + $transfer_fee) * ( (float) $service_charge->detail->amount->value /100) * (1/$rate)) : (float) $service_charge->detail->amount->value; + + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Services/CalculatesTransactionTransferFee.php b/app/Classes/Modules/Transactions/Services/CalculatesTransactionTransferFee.php new file mode 100644 index 00000000..5a02a394 --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/CalculatesTransactionTransferFee.php @@ -0,0 +1,24 @@ +detail->transferFee->type === 'percentage' ? $amount * ((float) $service_charge->detail->transferFee->value /100) : (float) $service_charge->detail->transferFee->value; + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Transactions/Services/GeneratesBankBalanceAccount.php b/app/Classes/Modules/Transactions/Services/GeneratesBankBalanceAccount.php new file mode 100644 index 00000000..39b49276 --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/GeneratesBankBalanceAccount.php @@ -0,0 +1,52 @@ +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..d86a4465 --- /dev/null +++ b/app/Classes/Modules/Wallets/Processors/CreditWalletProcessor.php @@ -0,0 +1,90 @@ +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()); + $this->createsWallet->execute($object, $company); + } + + /** @var Wallet $wallet */ + $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/BankAccountType.php b/app/Classes/ValueObjects/Constants/BankAccountType.php index 13a36fde..c1ae288e 100644 --- a/app/Classes/ValueObjects/Constants/BankAccountType.php +++ b/app/Classes/ValueObjects/Constants/BankAccountType.php @@ -8,4 +8,6 @@ final class BankAccountType { public const EXTERNAL = 2; + public const ALIPAY= 3; + } 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/Banks/UpdateBankStatusController.php b/app/Http/Controllers/Banks/UpdateBankStatusController.php new file mode 100644 index 00000000..e5faffa5 --- /dev/null +++ b/app/Http/Controllers/Banks/UpdateBankStatusController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file 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..2a22422f 100644 --- a/app/Http/Controllers/Exports/ExportCustomersToExcelController.php +++ b/app/Http/Controllers/Exports/ExportCustomersToExcelController.php @@ -5,6 +5,10 @@ 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\Classes\Modules\Exports\Services\ExportsWalletTransactions; use App\Models\User; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; @@ -13,15 +17,35 @@ use Maatwebsite\Excel\Excel; class ExportCustomersToExcelController { - public function export(ExportsCustomers $exportsCustomers, Request $request){ + /** + * ExportCustomersToExcelController constructor. + * @param Request $request + */ + public function __construct(Request $request) + { $token = Auth::fromUser(User::find(1)); $request->headers->set('Authorization', 'Bearer '.$token); + } + + public function export(ExportsCustomers $exportsCustomers, Request $request){ return $exportsCustomers->download('customers.csv', Excel::CSV, ['Content-Type' => 'text/csv']); } public function transactions(ExportsTransactions $exportsTransactions, Request $request){ - $token = Auth::fromUser(User::find(1)); - $request->headers->set('Authorization', 'Bearer '.$token); return $exportsTransactions->download('transactions.csv', Excel::CSV, ['Content-Type' => 'text/csv']); } + + public function nullDebtor(ExportsNullDebtors $exportsNullDebtors, Request $request){ + return $exportsNullDebtors->download('nullDebtor.csv', Excel::CSV, ['Content-Type' => 'text/csv']); + } + + public function paymentTransactions(Request $request){ + $exportsTransactions = new ExportsPaymentTransactions($request); + return $exportsTransactions->download('payment-transactions.csv', Excel::CSV, ['Content-Type' => 'text/csv']); + } + + public function walletTransactions(Request $request){ + $exportsTransactions = new ExportsWalletTransactions($request); + return $exportsTransactions->download('wallet-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/DownloadMockUpWhiteFormPdfController.php b/app/Http/Controllers/Transactions/DownloadMockUpWhiteFormPdfController.php new file mode 100644 index 00000000..e94c9484 --- /dev/null +++ b/app/Http/Controllers/Transactions/DownloadMockUpWhiteFormPdfController.php @@ -0,0 +1,15 @@ +execute($request); + } +} 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/BookingResource.php b/app/Http/Resources/BookingResource.php index dd951fff..0eeb9670 100644 --- a/app/Http/Resources/BookingResource.php +++ b/app/Http/Resources/BookingResource.php @@ -46,6 +46,7 @@ class BookingResource extends JsonResource ], 'status' => $this->status, 'created_at' => Carbon::parse($this->created_at)->format('d-m-Y'), + 'created_at_with_time' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A'), $this->mergeWhen($this->relationLoaded('transactions'), [ 'purchase_order' => new TransactionResource($this->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first()), 'payment_attempts' => TransactionResource::collection( diff --git a/app/Http/Resources/CompanyResource.php b/app/Http/Resources/CompanyResource.php index 902c30bd..fceab5bc 100644 --- a/app/Http/Resources/CompanyResource.php +++ b/app/Http/Resources/CompanyResource.php @@ -30,6 +30,9 @@ class CompanyResource extends JsonResource $lastPayment = $this->transactions()->where('transactions.type', TransactionType::PAYMENT)->whereIn('transactions.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->orderBy('id', 'DESC')->first(); $totalPayments = $this->transactions()->where('transactions.type', TransactionType::PAYMENT)->whereIn('transactions.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->sum('amount'); + $segment = SegmentConstant::where('reference', SegmentConstants::SUPPLIER_CURRENCIES)->where('detail->id', $this->id)->first(); + $serviceCharge = SegmentConstant::where('reference', SegmentConstants::SERVICE_CHARGE)->where('detail->id', $this->id)->first(); + return [ 'id' => $this->id, 'name' => $this->name, @@ -58,12 +61,13 @@ class CompanyResource extends JsonResource ], 'segments' => SegmentResource::collection($this->segments), '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(); - return $segment ? CurrencyResource::collection(Currency::whereIn('id', $segment->detail->currencies)->get()) : []; - }), 'wallet' => new WalletResource($this->wallets()->first()), - 'created_at' => $this->created_at->format('d-m-Y') + 'created_at' => $this->created_at->format('d-m-Y'), + $this->mergeWhen($this->business_type === BusinessType::CURRENCY_VENDOR, [ + 'currencies' => $segment ? CurrencyResource::collection(Currency::whereIn('id', $segment->detail->currencies)->get()) : [], + 'service_charge' => $serviceCharge + ]) + ]; } } diff --git a/app/Http/Resources/TransactionResource.php b/app/Http/Resources/TransactionResource.php index 35c29908..7680e6e1 100644 --- a/app/Http/Resources/TransactionResource.php +++ b/app/Http/Resources/TransactionResource.php @@ -3,6 +3,7 @@ namespace App\Http\Resources; use App\Classes\ValueObjects\Constants\TransactionType; +use App\Models\Booking; use Carbon\Carbon; use Illuminate\Http\Resources\Json\JsonResource; @@ -17,8 +18,8 @@ class TransactionResource extends JsonResource public function toArray($request) { - $booking = (int)$this->type === TransactionType::BILL ? $this->owner->owner : $this->booking; - $days = $this->updated_at->endOfDay()->addWeekdays($booking->service_id === 1 ? 1 : 3); + $booking = in_array((int)$this->type, [TransactionType::BILL, TransactionType::REFUND])? $this->owner->owner : $this->owner; + $days = $this->updated_at->endOfDay()->addWeekdays($booking->service_id === 3 ? 3 : 1); return [ 'id' => $this->id, @@ -39,7 +40,8 @@ class TransactionResource extends JsonResource 'status' => (int) $this->status, 'details' => TransactionDetailResource::collection($this->transactionDetails), 'documents' => new DocumentResource($this->documents()->first()), - 'transaction_bill' => new TransactionResource($this->when((int) $this->type === TransactionType::PAYMENT, $this->transactions()->first())), + 'transaction_bill' => new TransactionResource($this->when((int) $this->type === TransactionType::PAYMENT, $this->transactions()->bills()->first())), + 'transaction_refunds' => TransactionResource::collection($this->when((int) $this->type === TransactionType::PAYMENT, $this->transactions()->refunds()->get())), 'expires_on' => Carbon::parse($this->expires_on)->format('d-m-Y h:i:s A'), 'updated_at' => Carbon::parse($this->updated_at)->format('d-m-Y h:i:s A'), 'interval' => [ 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/database/seeds/UpdateTransactionBillOwnerSeeder.php b/database/seeds/UpdateTransactionBillOwnerSeeder.php index cd8eebcf..1ced925d 100644 --- a/database/seeds/UpdateTransactionBillOwnerSeeder.php +++ b/database/seeds/UpdateTransactionBillOwnerSeeder.php @@ -1,5 +1,6 @@ get(); + $bookings = Booking::all(); - foreach ($transaction as $key => $row) { - $key = 0; - $bills = $row->booking->transactions()->bills()->where('original_amount', '=', $row->original_amount)->get(); - if(count($bills) > 1){ $key = $bills->search(function($bill)use($row){ return $bill->id === $row->id; }); } - $paymentTransaction = $row->booking->transactions()->payments()->complete()->where('original_amount', '=', $row->original_amount)->skip($key)->first(); + foreach ($bookings as $booking) { - $row->owner_type = Transaction::class; - $row->owner_id = $paymentTransaction->id; - $row->update(); + $transactions = $booking->transactions()->bills()->get(); + foreach ($transactions as $row) { + $key = 0; + $bills = $booking->transactions()->bills()->where('original_amount', '=', $row->original_amount)->get(); + if(count($bills) > 1){ $key = $bills->search(function($bill)use($row){ return $bill->id === $row->id; }); } + $paymentTransaction = $booking->transactions()->payments()->complete()->where('original_amount', '=', $row->original_amount)->skip($key)->first(); + + $row->owner_type = Transaction::class; + $row->owner_id = $paymentTransaction->id; + $row->updated_at = $row->updated_at; + $row->update(); + } } DB::commit(); diff --git a/resources/assets/vue/components/accounts/sections/OnboardingSectionComponent.vue b/resources/assets/vue/components/accounts/sections/OnboardingSectionComponent.vue index 8b9e6171..5f2fb8e9 100644 --- a/resources/assets/vue/components/accounts/sections/OnboardingSectionComponent.vue +++ b/resources/assets/vue/components/accounts/sections/OnboardingSectionComponent.vue @@ -10,14 +10,14 @@
-
+
-
+
diff --git a/resources/assets/vue/components/banks/forms/BankAccountFormComponent.vue b/resources/assets/vue/components/banks/forms/BankAccountFormComponent.vue index c91cf482..7a187cc6 100644 --- a/resources/assets/vue/components/banks/forms/BankAccountFormComponent.vue +++ b/resources/assets/vue/components/banks/forms/BankAccountFormComponent.vue @@ -33,13 +33,13 @@
- +
-
-
+
+
@@ -117,6 +117,11 @@ country_id: { type: Number, default: 1 + }, + serviceType: { + type: Object, + required: false, + default: null } }, data(){ diff --git a/resources/assets/vue/components/banks/forms/PhoneAccountFormComponent.vue b/resources/assets/vue/components/banks/forms/PhoneAccountFormComponent.vue new file mode 100644 index 00000000..dfec0ddb --- /dev/null +++ b/resources/assets/vue/components/banks/forms/PhoneAccountFormComponent.vue @@ -0,0 +1,154 @@ + + \ No newline at end of file diff --git a/resources/assets/vue/components/banks/forms/SuspendBankAccountFormComponent.vue b/resources/assets/vue/components/banks/forms/SuspendBankAccountFormComponent.vue new file mode 100644 index 00000000..ab09aff6 --- /dev/null +++ b/resources/assets/vue/components/banks/forms/SuspendBankAccountFormComponent.vue @@ -0,0 +1,45 @@ + + \ No newline at end of file diff --git a/resources/assets/vue/components/bookings/elements/BillingComponent.vue b/resources/assets/vue/components/bookings/elements/BillingComponent.vue index 617b06dc..83a2cb78 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/BookingConfirmationComponent.vue b/resources/assets/vue/components/bookings/elements/BookingConfirmationComponent.vue index dbb106e5..f9253307 100644 --- a/resources/assets/vue/components/bookings/elements/BookingConfirmationComponent.vue +++ b/resources/assets/vue/components/bookings/elements/BookingConfirmationComponent.vue @@ -9,7 +9,7 @@
-
+
{{this.data.serviceType.name}}
@@ -20,7 +20,6 @@
Service Type
-
@@ -79,7 +78,7 @@
- +
@@ -124,7 +123,8 @@
- + +
diff --git a/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue b/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue index af7eab83..51352679 100644 --- a/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue +++ b/resources/assets/vue/components/bookings/elements/PaymentHistoryComponent.vue @@ -4,13 +4,16 @@
-
+
Status
{{ item.status === 1 ? 'Pending Verification' : item.status === 4 ? 'Rejected' : 'Processing Payment'}}
+
+ {{ item.status === 1 ? 'Pending Verification' : item.status === 4 ? 'Rejected' : 'Processing Payment'}} +
Payment Amount
@@ -18,6 +21,12 @@ {{item.currency.short_code}} {{(Math.round((item.amount + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}}
+
+
Refunded Amount
+
+ {{item.original_currency.short_code}} {{(Math.round((totalRefunds + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}} +
+
@@ -25,7 +34,7 @@
-
+
@@ -54,7 +63,15 @@
Payment Amount
- {{item.transaction_bill.original_currency.short_code}} {{(Math.round((item.transaction_bill.original_amount + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}} + {{item.original_currency.short_code}} {{(Math.round((item.original_amount + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}} +
+
+
+
+
Refunded Amount
+
+
+
{{item.original_currency.short_code}} {{(Math.round((totalRefunds + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}}
@@ -101,6 +118,22 @@
{{item.original_currency.short_code}} {{(item.original_amount).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}}
+
+
+
Requested Refund Amount
+
+
+
{{item.original_currency.short_code}} {{(Math.round((totalRequestedRefund + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}}
+
+
+
+
+
Refunded Amount
+
+
+
{{item.original_currency.short_code}} {{(Math.round((totalRefunds + Number.EPSILON) * 100) / 100).toFixed(2).toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")}}
+
+
Rate
@@ -161,6 +194,11 @@
Our Payment Proof
+
+
+

Payment proof will be uploaded {{ (parseFloat(item.interval.duration) + 1) <= 0 ? 'today' : (parseFloat(item.interval.duration) + 1) === 2 ? 'tomorrow' : 'in '+(parseFloat(item.interval.duration) + 1)+' days'}} at 4:00 PM

+
+
@@ -174,114 +212,23 @@
+
+
+

Payment proof will be uploaded {{ (parseFloat(item.interval.duration) + 1) <= 0 ? 'today' : (parseFloat(item.interval.duration) + 1) === 2 ? 'tomorrow' : 'in '+(parseFloat(item.interval.duration) + 1)+' days'}} at 4:00 PM

+
+
-
-
- +
+
+ - +
- -
-
-
-
-
Refund Type:
-
-
-
- {{refundMethod.name}} -
-
-
-
- -
-
-
-
-
-
-
-
-
-
-
-
-
-
Fully Refund
-
-
-
-
-
-
-
-
-
Partially Refund
-
-
-
-
-
-
-
-
-
-
-
-
- - - - -
-
-
-
-
{{''}}
-
-
-
-
-
-
- - - - -
-
-
-
-
{{''}}
-
-
-
-
-
-
-
- - -
-
-
-
-
- -
-
- -
-
-
-
@@ -292,41 +239,33 @@ data(){ return { expandPaymentDetails: false, - expandRefund: false, - refundMethod: { - name: 'Fully Refund', - status: false - }, amount: (Math.round(1000 * 100) / 100).toFixed(2), parameters: { amount: (Math.round(1000 * 100) / 100).toFixed(2), bank_id: 1 }, - expanded: false, section: 'bookingDetailSection', } }, + computed: { + totalRequestedRefund() { + var TotalRequestedRefund = 0; + this.data.transaction_refunds.forEach(function(refunds) { + TotalRequestedRefund += refunds.status === 1 ? refunds.original_amount : 0; + }); + return TotalRequestedRefund; + }, + totalRefunds() { + var TotalRequestedRefund = 0; + this.data.transaction_refunds.forEach(function(refunds) { + TotalRequestedRefund += refunds.status === 2 ? refunds.original_amount : 0; + }); + return TotalRequestedRefund; + } + }, methods: { - submitForm(){ - this.submit(this.route('api.booking.refund.create', this.data.booking.id, this.data.id), 'post', this.section, true, true); - }, - requestRefund(){ - this.expandRefund = !this.expandRefund; - this.expandPaymentDetails = !this.expandPaymentDetails; - }, clickExpand(){ - if (this.expandPaymentDetails === false && this.expandRefund === false) { - this.expandPaymentDetails = !this.expandPaymentDetails; - } else { - this.expandRefund = false; - this.expandPaymentDetails = false; - } - }, - updateRefundType(refund){ - this.refundMethod = { - name: refund.name, - status: !this.refundMethod.status - } + this.expandPaymentDetails = !this.expandPaymentDetails; }, }, mixins: [componentHandler] diff --git a/resources/assets/vue/components/bookings/elements/PaymentProofComponent.vue b/resources/assets/vue/components/bookings/elements/PaymentProofComponent.vue index 59484c81..5af5548c 100644 --- a/resources/assets/vue/components/bookings/elements/PaymentProofComponent.vue +++ b/resources/assets/vue/components/bookings/elements/PaymentProofComponent.vue @@ -47,13 +47,24 @@
-
-
- Cancel this order? +
+
+
*This Bank Account has been suspended. Please notify customer to update their Bank Account.*
+
+
+ Suspend this Bank Account ?
- - + + + +
+
+ Cancel this order? +
+
+ +
diff --git a/resources/assets/vue/components/bookings/elements/RefundConfirmationComponent.vue b/resources/assets/vue/components/bookings/elements/RefundConfirmationComponent.vue index 9a810def..de2cd48f 100644 --- a/resources/assets/vue/components/bookings/elements/RefundConfirmationComponent.vue +++ b/resources/assets/vue/components/bookings/elements/RefundConfirmationComponent.vue @@ -1,5 +1,5 @@