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/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..5a7e76b4 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.75); + $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/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/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/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/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..f89ae6ef 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -30,6 +30,22 @@ class Transaction extends AbstractModel implements Documentable, Transactionable return $this->morphTo(); } + /** + * @return MorphMany + */ + public function transactions(): MorphMany + { + return $this->MorphMany(Transaction::class, 'owner'); + } + + /** + * @return MorphOne + */ + public function creditNoteTransaction() + { + return $this->MorphOne(Transaction::class, 'owner')->where('type', TransactionType::CREDIT_NOTE); + } + /** * @return MorphMany */ diff --git a/resources/views/pages/pdfs/currency_vendor_order.blade.php b/resources/views/pages/pdfs/currency_vendor_order.blade.php index 9ca3b7be..cdac2d4e 100644 --- a/resources/views/pages/pdfs/currency_vendor_order.blade.php +++ b/resources/views/pages/pdfs/currency_vendor_order.blade.php @@ -1,29 +1,33 @@ @extends('layouts.base_pdf') @section('inner_content') - + +
+
- -
- - +
+ - -
{{$supplier->name}} {{\Carbon\Carbon::now('Asia/Singapore')->format('d-m-Y h:s')}}
-
-
- - + +
+
+
+ + @@ -41,21 +45,59 @@
Branch: {{$transaction->owner()->first()->booking->bank->bank_branch}}
Bank in Amount: {{$transaction->original_currency->short_code}} {{$transaction->original_amount}} @endforeach - -
Reference Marking
- - + +
+ + + + + @php + $sub_total_booking_amount = number_format((float)$transactions->sum('original_amount'), 2, '.', ''); + @endphp + + + + + @php + $transfer_fee = number_format((float)$transferFeeTransactions->sum('service_charge'), 2, '.', ''); + @endphp + + + + + @php + $total_booking_amount = number_format((float) ($transactions->sum('original_amount') + $transfer_fee), 2, '.', ''); + @endphp + + + + + @php + $sub_total_amount = number_format((float)$transactions->sum('amount') + ($transfer_fee * 1/$transactions[0]->currency_rate), 2, '.', ''); + @endphp + + + + + @php + $service_charge = number_format((float)$sub_total_amount * 0.75 / 100, 2, '.', ''); + @endphp + + - + @php + $total_amount = number_format((float)$sub_total_amount + $service_charge, 2, '.', ''); + @endphp + + + +
Sub total booking amount: RMB {{$sub_total_booking_amount}}
Transfer fee (0.002%): RMB {{$transfer_fee}}
Total booking amount: RMB {{$total_booking_amount}}
Sub total amount: MYR {{$sub_total_amount}}
Service charge ({{ $supplier->id == 2 ? '0.00' : '0.75%' }}): MYR {{$service_charge}}
Total amount: MYR {{number_format((float)$transactions->sum('amount'), 2, '.', '')}}MYR {{$total_amount}}
+ + + + -
Page {PAGENO} of {nbpg}
- - - - - -
Page {PAGENO} of {nbpg}
-
+
@endsection \ No newline at end of file diff --git a/routes/api.php b/routes/api.php index cf5838f3..10c0fb80 100644 --- a/routes/api.php +++ b/routes/api.php @@ -35,6 +35,8 @@ Route::group(['middleware' => 'api', 'prefix' => 'v1', 'as' => 'api.'], function require __DIR__ . '/segment.php'; + require __DIR__ . '/segment_constant.php'; + require __DIR__ . '/currency.php'; require __DIR__ . '/bank.php'; diff --git a/routes/segment_constant.php b/routes/segment_constant.php index e49e9e97..e393e3f3 100644 --- a/routes/segment_constant.php +++ b/routes/segment_constant.php @@ -2,19 +2,20 @@ use Illuminate\Support\Facades\Route; -Route::group(['namespace' => 'StandardSegmentConstants'], function () { - Route::group(['middleware' => 'valid.token'], function () { - Route::group(['prefix' => 'standard-segment-constant'], function () { - Route::get('/list', 'ListStandardSegmentConstantsController@list')->name('standard_segment.update'); - Route::put('/update/{id}', 'UpdateStandardSegmentConstantController@update')->name('standard_segment_constant.update'); - }); - }); -}); +// Route::group(['namespace' => 'StandardSegmentConstants'], function () { +// Route::group(['middleware' => 'valid.token'], function () { +// Route::group(['prefix' => 'standard-segment-constant'], function () { +// Route::get('/list', 'ListStandardSegmentConstantsController@list')->name('standard_segment.update'); +// Route::put('/update/{id}', 'UpdateStandardSegmentConstantController@update')->name('standard_segment_constant.update'); +// }); +// }); +// }); Route::group(['namespace' => 'SegmentConstants'], function () { Route::group(['middleware' => 'valid.token'], function () { Route::group(['prefix' => 'segment-constant'], function () { + Route::get('/{id}/show', 'FetchSegmentConstantController@fetch')->name('segment_constant.show'); Route::post('/create', 'CreateSegmentConstantController@create')->name('segment_constant.create'); Route::put('/update/{id}', 'UpdateSegmentConstantController@update')->name('segment_constant.update'); }); diff --git a/routes/transaction.php b/routes/transaction.php index 1a1bcfcd..2012a045 100644 --- a/routes/transaction.php +++ b/routes/transaction.php @@ -18,4 +18,7 @@ Route::group(['prefix' => 'transactions', 'namespace' => 'Transactions', 'as' => Route::get('wallet/list', 'ListWalletTransactionsController@list')->name('wallet.list'); + Route::get('/company/{id}/account/balance', 'FetchCompanyAccountBalanceController@fetch')->name('company.account.balance'); + + Route::get('/bank/{id}/account/balance', 'FetchBankAccountBalanceController@fetch')->name('bank.account.balance'); }); \ No newline at end of file