From 77b2d21e68300a1501935dce090e14980b843d23 Mon Sep 17 00:00:00 2001 From: ahmedsophyudden Date: Sun, 2 Jan 2022 15:01:52 +0800 Subject: [PATCH 1/7] add calculation service charge for transaction bill --- .../CreateSupplierTransactionLogic.php | 49 +++++++++++-------- .../CalculatesTransactionServiceCharge.php | 19 +++++++ .../pdfs/currency_vendor_order.blade.php | 22 ++++++++- 3 files changed, 68 insertions(+), 22 deletions(-) create mode 100644 app/Classes/Modules/Transactions/Services/CalculatesTransactionServiceCharge.php diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php index f496ab4f..20dfa9da 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php @@ -3,31 +3,32 @@ namespace App\Classes\Modules\Transactions\ControllersLogic; +use Carbon\Carbon; +use App\Models\Document; +use Barryvdh\DomPDF\PDF; +use App\Models\Transaction; +use Illuminate\Support\Str; +use Illuminate\Http\Request; +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\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 Meneses\LaravelLaravelMpdf\Facades\LaravelLaravelMpdf; +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\Transactions\Services\GeneratesTransactionBillNumber; +use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject; 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\Transactions\DataTransferObjects\TransactionObject; +use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber; +use App\Classes\Modules\Transactions\Services\CalculatesTransactionServiceCharge; class CreateSupplierTransactionLogic extends AbstractControllerLogic { @@ -64,6 +65,9 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic /** @var GeneratesTransactionBillNumber */ private $generatesTransactionBillNumber; + /** @var CalculatesTransactionServiceCharge */ + private $calculatesTransactionServiceCharge; + /** @var PDF */ private $pdf; @@ -74,9 +78,10 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic * @param UpdatesTransactionStatus $updatesTransactionStatus * @param CreatesTransaction $createsTransaction * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber + * @param CalculatesTransactionServiceCharge $calculatesTransactionServiceCharge * @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, UpdatesTransactionStatus $updatesTransactionStatus, CreatesTransaction $createsTransaction, CreatesDocument $createsDocument, CreatesFiles $createsFile, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CalculatesTransactionServiceCharge $calculatesTransactionServiceCharge, PDF $pdf) { $this->fetchesCompany = $fetchesCompany; @@ -86,6 +91,7 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic $this->createsDocument = $createsDocument; $this->createsFile = $createsFile; $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; + $this->calculatesTransactionServiceCharge = $calculatesTransactionServiceCharge; $this->pdf = $pdf; } @@ -106,10 +112,11 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic $this->updatesTransactionStatus->execute($payment, ApprovalStatus::COMPLETED); $billNumber = $this->generatesTransactionBillNumber->execute('SPLR-'); + $serviceCharge = $this->calculatesTransactionServiceCharge->execute($payment->original_amount, $rate); $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->booking, $object); } diff --git a/app/Classes/Modules/Transactions/Services/CalculatesTransactionServiceCharge.php b/app/Classes/Modules/Transactions/Services/CalculatesTransactionServiceCharge.php new file mode 100644 index 00000000..3dbabc30 --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/CalculatesTransactionServiceCharge.php @@ -0,0 +1,19 @@ + - Total amount: + Sub total booking amount: + RMB {{number_format((float)$transactions->sum('original_amount'), 2, '.', '')}} + + + Transfer fee (0.002%): + RMB {{number_format((float)$transactions->sum('original_amount') * 0.002 / 100, 2, '.', '')}} + + + Total booking amount: + RMB {{number_format((float) ($transactions->sum('original_amount') +($transactions->sum('original_amount') * 0.002 / 100)), 2, '.', '')}} + + + Sub total amount: MYR {{number_format((float)$transactions->sum('amount'), 2, '.', '')}} + + Service charge ({{ $supplier->id == 2 ? 0 : '0.75%' }}): + MYR {{number_format((float)$transactions->sum('service_charge'), 2, '.', '')}} + + + Total amount: + MYR {{number_format((float) ($transactions->sum('amount') + $transactions->sum('service_charge')), 2, '.', '')}} + From d2d92f668e7d56d462c9dc2e3d6a681274c6def9 Mon Sep 17 00:00:00 2001 From: ahmedsophyudden Date: Sat, 8 Jan 2022 03:28:18 +0800 Subject: [PATCH 2/7] add transfer fee transaction and fixed currency_vendor_order pdf calculation --- .../CreateSupplierTransactionLogic.php | 20 ++- .../CalculatesTransactionServiceCharge.php | 6 +- .../CalculatesTransactionTransferFee.php | 17 +++ .../Constants/TransactionType.php | 2 + .../pdfs/currency_vendor_order.blade.php | 115 +++++++++++------- 5 files changed, 109 insertions(+), 51 deletions(-) create mode 100644 app/Classes/Modules/Transactions/Services/CalculatesTransactionTransferFee.php diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php index 20dfa9da..6b5110ec 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php @@ -28,6 +28,7 @@ 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 @@ -68,6 +69,9 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic /** @var CalculatesTransactionServiceCharge */ private $calculatesTransactionServiceCharge; + /** @var CalculatesTransactionTransferFee */ + private $calculatesTransactionTransferFee; + /** @var PDF */ private $pdf; @@ -79,9 +83,10 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic * @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, CalculatesTransactionServiceCharge $calculatesTransactionServiceCharge, PDF $pdf) + public function __construct(FetchesCompany $fetchesCompany, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, CreatesTransaction $createsTransaction, CreatesDocument $createsDocument, CreatesFiles $createsFile, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CalculatesTransactionServiceCharge $calculatesTransactionServiceCharge, CalculatesTransactionTransferFee $calculatesTransactionTransferFee, PDF $pdf) { $this->fetchesCompany = $fetchesCompany; @@ -92,6 +97,7 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic $this->createsFile = $createsFile; $this->generatesTransactionBillNumber = $generatesTransactionBillNumber; $this->calculatesTransactionServiceCharge = $calculatesTransactionServiceCharge; + $this->calculatesTransactionTransferFee = $calculatesTransactionTransferFee; $this->pdf = $pdf; } @@ -102,6 +108,7 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic $rate = $request->input('rate'); $transactions = collect(); + $transferFeeTransactions = collect(); foreach($request->input('payments') as $payment){ @@ -119,11 +126,20 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic $rate, 0, $supplier->id == 2 ? 0 : $serviceCharge, null, ApprovalStatus::PENDING_VERIFICATION); $transactions[] = $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($payment->booking, $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/Services/CalculatesTransactionServiceCharge.php b/app/Classes/Modules/Transactions/Services/CalculatesTransactionServiceCharge.php index 3dbabc30..641e3903 100644 --- a/app/Classes/Modules/Transactions/Services/CalculatesTransactionServiceCharge.php +++ b/app/Classes/Modules/Transactions/Services/CalculatesTransactionServiceCharge.php @@ -8,12 +8,12 @@ class CalculatesTransactionServiceCharge /** * @param float $amount * @param float $rate - * @param float $transfer_fee * @param float $service_charge + * @param float $transfer_fee * @return float */ - public function execute(float $amount, float $rate, ?float $transfer_fee = 0.002, ?float $service_charge = 0.75) { - return (($amount + ($amount * $transfer_fee/100)) * (1/$rate)) * $service_charge / 100; + public function execute(float $amount, float $rate, ?float $service_charge = 0.75, ?float $transfer_fee = 0.00) { + return (($amount + $transfer_fee) * (1/$rate)) * $service_charge / 100; } } \ 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..14f77b84 --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/CalculatesTransactionTransferFee.php @@ -0,0 +1,17 @@ + - table, th, td { - border: 1px solid black; - border-collapse: collapse; - } - th, td { - padding: 15px; - } - + +
+
- -
- - +
+ - -
{{$supplier->name}} {{\Carbon\Carbon::now('Asia/Singapore')->format('d-m-Y h:s')}}
-
-
- - + +
+
+
+ + @@ -32,50 +36,69 @@ @foreach($transactions as $transaction) - - - - - - - + + + + + + + @endforeach - -
Reference MarkingBank in Details
{{$transaction->booking->marking}}{{$transaction->booking->company->reference}}{{$transaction->currency_rate}}{{$transaction->currency->short_code}} {{number_format((float)$transaction->amount, 2, '.', '')}}Account Holder Name: {{$transaction->booking->bank->holder_name}}
{{$transaction->booking->bank->bank_name}}: {{$transaction->booking->bank->account_no}} -
Branch: {{$transaction->booking->bank->bank_branch}}
Bank in Amount: {{$transaction->original_currency->short_code}} {{$transaction->original_amount}}
{{$transaction->booking->marking}}{{$transaction->booking->company->reference}}{{$transaction->currency_rate}}{{$transaction->currency->short_code}} {{number_format((float)$transaction->amount, 2, '.', '')}}Account Holder Name: {{$transaction->booking->bank->holder_name}}
{{$transaction->booking->bank->bank_name}}: {{$transaction->booking->bank->account_no}} +
Branch: {{$transaction->booking->bank->bank_branch}}
Bank in Amount: {{$transaction->original_currency->short_code}} {{$transaction->original_amount}} +
- - + +
+ + - + @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 {{number_format((float)$transactions->sum('original_amount'), 2, '.', '')}}RMB {{$sub_total_booking_amount}}
Transfer fee (0.002%): RMB {{number_format((float)$transactions->sum('original_amount') * 0.002 / 100, 2, '.', '')}}RMB {{$transfer_fee}}
Total booking amount: RMB {{number_format((float) ($transactions->sum('original_amount') +($transactions->sum('original_amount') * 0.002 / 100)), 2, '.', '')}}RMB {{$total_booking_amount}}
Sub total amount: MYR {{number_format((float)$transactions->sum('amount'), 2, '.', '')}}MYR {{$sub_total_amount}}
Service charge ({{ $supplier->id == 2 ? 0 : '0.75%' }}): MYR {{number_format((float)$transactions->sum('service_charge'), 2, '.', '')}}Service charge ({{ $supplier->id == 2 ? '0.00' : '0.75%' }}): MYR {{$service_charge}}
Total amount: MYR {{number_format((float) ($transactions->sum('amount') + $transactions->sum('service_charge')), 2, '.', '')}}MYR {{$total_amount}}
+ + + + -
Page {PAGENO} of {nbpg}
- - - - - -
Page {PAGENO} of {nbpg}
-
+
@endsection \ No newline at end of file From 36c659c84e58cc8982e68d8ffe169e4460ca0c3f Mon Sep 17 00:00:00 2001 From: ahmedsophyudden Date: Tue, 11 Jan 2022 23:07:49 +0800 Subject: [PATCH 3/7] Transfer Fee Transaction - Company Balance Account API --- .../CreateSupplierTransactionLogic.php | 4 +- .../FetchCompanyAccountBalanceLogic.php | 46 +++++++++++++++++++ .../GeneratesCompanyBalanceAccount.php | 41 +++++++++++++++++ .../FetchCompanyAccountBalanceController.php | 21 +++++++++ app/Models/Company.php | 7 +++ app/Models/Transaction.php | 11 ++++- routes/transaction.php | 1 + 7 files changed, 128 insertions(+), 3 deletions(-) create mode 100644 app/Classes/Modules/Transactions/ControllersLogic/FetchCompanyAccountBalanceLogic.php create mode 100644 app/Classes/Modules/Transactions/Services/GeneratesCompanyBalanceAccount.php create mode 100644 app/Http/Controllers/Transactions/FetchCompanyAccountBalanceController.php diff --git a/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php index 6b5110ec..b524b3e9 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php @@ -125,7 +125,7 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic $payment->original_amount * (1 / $rate), $payment->original_amount, 1, $payment->original_currency_id, $rate, 0, $supplier->id == 2 ? 0 : $serviceCharge, null, ApprovalStatus::PENDING_VERIFICATION); - $transactions[] = $this->createsTransaction->execute($payment->booking, $object); + $transactions[] = $billTransaction = $this->createsTransaction->execute($payment->booking, $object); $transferFeeNumber = $this->generatesTransactionBillNumber->execute('TRFR-'); $trasferFee = $this->calculatesTransactionTransferFee->execute($payment->original_amount); @@ -134,7 +134,7 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic $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($payment->booking, $object); + $transferFeeTransactions[] = $this->createsTransaction->execute($billTransaction, $object); } if(!count($transactions)) return $this->response([]); 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/GeneratesCompanyBalanceAccount.php b/app/Classes/Modules/Transactions/Services/GeneratesCompanyBalanceAccount.php new file mode 100644 index 00000000..51c71cb1 --- /dev/null +++ b/app/Classes/Modules/Transactions/Services/GeneratesCompanyBalanceAccount.php @@ -0,0 +1,41 @@ +checksIfTransactionBillNumberExists = $checksIfTransactionBillNumberExists; + } + + + /** + * @param Company $company + */ + public function execute(Company $company) { + $transferFeeTransactions = $company->issuerTransactions()->where('transactions.type', TransactionType::TRANSFER_FEE)->whereIn('transactions.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->orderBy('id', 'DESC')->get(); + return [ + 'company' => new CompanyResource($company), + 'transferFeeTransactions' => $transferFeeTransactions, + 'account_balance' => $transferFeeTransactions->sum('amount'), + ]; + + } + +} \ No newline at end of file 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/Models/Company.php b/app/Models/Company.php index 7b8e4387..e18bbf85 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -101,6 +101,13 @@ 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/Transaction.php b/app/Models/Transaction.php index a3e16c79..450d9545 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -3,6 +3,7 @@ namespace App\Models; use App\Classes\General\Interfaces\Documentable; +use App\Classes\General\Interfaces\Transactionable; use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Classes\ValueObjects\Constants\TransactionType; use Carbon\Carbon; @@ -16,7 +17,7 @@ use Illuminate\Database\Eloquent\Relations\MorphMany; use Illuminate\Database\Eloquent\Relations\MorphTo; -class Transaction extends AbstractModel implements Documentable +class Transaction extends AbstractModel implements Documentable, Transactionable { use SoftDeletes; @@ -27,6 +28,14 @@ class Transaction extends AbstractModel implements Documentable return $this->morphTo(); } + /** + * @return MorphMany + */ + public function transactions(): MorphMany + { + return $this->MorphMany(Transaction::class, 'owner'); + } + /** * @return MorphMany */ diff --git a/routes/transaction.php b/routes/transaction.php index 578b02c2..d3ce05b2 100644 --- a/routes/transaction.php +++ b/routes/transaction.php @@ -16,4 +16,5 @@ Route::group(['prefix' => 'transactions', 'namespace' => 'Transactions', 'as' => Route::post('booking/{id}/details/update', 'CreatePurchaseOrderTransactionController@create')->name('po.create'); + Route::get('/company/{id}/account/balance', 'FetchCompanyAccountBalanceController@fetch')->name('company.account.balance'); }); \ No newline at end of file From 6a2d0dc2a42c5a614404c0d4af27f5390bf840c0 Mon Sep 17 00:00:00 2001 From: ahmedsophyudden Date: Thu, 27 Jan 2022 22:46:36 +0800 Subject: [PATCH 4/7] Fixed transfer fee count (status == approve only and deduct credit note) --- .../Services/GeneratesCompanyBalanceAccount.php | 13 +++++++++++-- app/Models/Transaction.php | 8 ++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/Classes/Modules/Transactions/Services/GeneratesCompanyBalanceAccount.php b/app/Classes/Modules/Transactions/Services/GeneratesCompanyBalanceAccount.php index 51c71cb1..cfbe8ee2 100644 --- a/app/Classes/Modules/Transactions/Services/GeneratesCompanyBalanceAccount.php +++ b/app/Classes/Modules/Transactions/Services/GeneratesCompanyBalanceAccount.php @@ -8,6 +8,7 @@ use App\Http\Resources\CompanyResource; use App\Classes\ValueObjects\Constants\ApprovalStatus; use App\Classes\ValueObjects\Constants\TransactionType; use App\Classes\Modules\Transactions\Services\ChecksIfTransactionBillNumberExists; +use Illuminate\Database\Eloquent\Collection; class GeneratesCompanyBalanceAccount { @@ -29,11 +30,19 @@ class GeneratesCompanyBalanceAccount * @param Company $company */ public function execute(Company $company) { - $transferFeeTransactions = $company->issuerTransactions()->where('transactions.type', TransactionType::TRANSFER_FEE)->whereIn('transactions.status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->orderBy('id', 'DESC')->get(); + $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, - 'account_balance' => $transferFeeTransactions->sum('amount'), + 'creditNoteTransactions' => $creditNoteTransactions, + 'account_balance' => $transferFeeTransactions->sum('amount') - $creditNoteTransactions->sum('amount'), ]; } diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index 450d9545..730da377 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -36,6 +36,14 @@ class Transaction extends AbstractModel implements Documentable, Transactionable return $this->MorphMany(Transaction::class, 'owner'); } + /** + * @return MorphOne + */ + public function creditNoteTransaction() + { + return $this->MorphOne(Transaction::class, 'owner')->where('type', TransactionType::CREDIT_NOTE); + } + /** * @return MorphMany */ From 592024d4622b09dd6c5b71ab670ee8a123db81c6 Mon Sep 17 00:00:00 2001 From: ahmedsophyudden Date: Tue, 22 Feb 2022 11:35:12 +0800 Subject: [PATCH 5/7] Create api to get bank account balance by bank id --- .../FetchBankAccountBalanceLogic.php | 46 ++++++++++++++++ .../Services/GeneratesBankBalanceAccount.php | 52 +++++++++++++++++++ .../FetchBankAccountBalanceController.php | 21 ++++++++ app/Models/Bank.php | 13 ++++- app/Models/Company.php | 1 + routes/transaction.php | 2 + 6 files changed, 133 insertions(+), 2 deletions(-) create mode 100644 app/Classes/Modules/Transactions/ControllersLogic/FetchBankAccountBalanceLogic.php create mode 100644 app/Classes/Modules/Transactions/Services/GeneratesBankBalanceAccount.php create mode 100644 app/Http/Controllers/Transactions/FetchBankAccountBalanceController.php 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/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/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/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 e18bbf85..def72720 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -101,6 +101,7 @@ class Company extends AbstractModel implements Documentable { return $this->hasManyDeep(Transaction::class, [Booking::class], ['company_id', 'owner_id'], ['id', 'id']); } + /** * @return HasMany */ diff --git a/routes/transaction.php b/routes/transaction.php index d3ce05b2..83392e4e 100644 --- a/routes/transaction.php +++ b/routes/transaction.php @@ -17,4 +17,6 @@ Route::group(['prefix' => 'transactions', 'namespace' => 'Transactions', 'as' => Route::post('booking/{id}/details/update', 'CreatePurchaseOrderTransactionController@create')->name('po.create'); 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 From dd0b1422383890a56e99fe6332f50e8a82915bee Mon Sep 17 00:00:00 2001 From: ahmedsophyudden Date: Sun, 27 Feb 2022 12:51:21 +0800 Subject: [PATCH 6/7] Create api to create and update service change setting --- app/Classes/ValueObjects/Constants/BusinessType.php | 2 ++ app/Classes/ValueObjects/Constants/SegmentConstants.php | 4 ++++ 2 files changed, 6 insertions(+) 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 From af3ff46a20b5eb693bd933b2e2b4e0c4f13f0d08 Mon Sep 17 00:00:00 2001 From: ahmedsophyudden Date: Mon, 28 Feb 2022 22:40:16 +0800 Subject: [PATCH 7/7] Grab service charge from setting for calculate supplier transaction --- .../Eloquent/Filters/ServiceCharge.php | 21 +++++ .../CreateSegmentConstantLogic.php | 70 +++++++++++++++ .../FetchSegmentConstantLogic.php | 51 +++++++++++ .../UpdateSegmentConstantLogic.php | 88 +++++++++++++++++++ .../CreateSupplierTransactionLogic.php | 15 +++- .../CreateSegmentConstantController.php | 19 ++++ .../FetchSegmentConstantController.php | 20 +++++ .../UpdateSegmentConstantController.php | 20 +++++ app/Http/Resources/CompanyResource.php | 1 + app/Models/SegmentConstant.php | 4 + routes/api.php | 2 + routes/segment_constant.php | 17 ++-- 12 files changed, 317 insertions(+), 11 deletions(-) create mode 100644 app/Classes/General/Eloquent/Filters/ServiceCharge.php create mode 100644 app/Classes/Modules/SegmentConstants/ControllersLogic/CreateSegmentConstantLogic.php create mode 100644 app/Classes/Modules/SegmentConstants/ControllersLogic/FetchSegmentConstantLogic.php create mode 100644 app/Classes/Modules/SegmentConstants/ControllersLogic/UpdateSegmentConstantLogic.php create mode 100644 app/Http/Controllers/SegmentConstants/CreateSegmentConstantController.php create mode 100644 app/Http/Controllers/SegmentConstants/FetchSegmentConstantController.php create mode 100644 app/Http/Controllers/SegmentConstants/UpdateSegmentConstantController.php 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 b524b3e9..9cb671a8 100644 --- a/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php +++ b/app/Classes/Modules/Transactions/ControllersLogic/CreateSupplierTransactionLogic.php @@ -3,12 +3,14 @@ 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; @@ -16,16 +18,18 @@ 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\Segments\Services\FetchesConstant; use Meneses\LaravelLaravelMpdf\Facades\LaravelLaravelMpdf; 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; @@ -79,6 +83,7 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic * CreateSupplierTransactionLogic constructor. * @param FetchesCompany $fetchesCompany * @param FetchesTransaction $fetchesTransaction + * @param FetchesConstant $fetchesConstant * @param UpdatesTransactionStatus $updatesTransactionStatus * @param CreatesTransaction $createsTransaction * @param GeneratesTransactionBillNumber $generatesTransactionBillNumber @@ -86,11 +91,12 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic * @param CalculatesTransactionTransferFee $calculatesTransactionTransferFee * @param PDF $pdf */ - public function __construct(FetchesCompany $fetchesCompany, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, CreatesTransaction $createsTransaction, CreatesDocument $createsDocument, CreatesFiles $createsFile, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CalculatesTransactionServiceCharge $calculatesTransactionServiceCharge, CalculatesTransactionTransferFee $calculatesTransactionTransferFee, 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; @@ -119,7 +125,10 @@ class CreateSupplierTransactionLogic extends AbstractControllerLogic $this->updatesTransactionStatus->execute($payment, ApprovalStatus::COMPLETED); $billNumber = $this->generatesTransactionBillNumber->execute('SPLR-'); - $serviceCharge = $this->calculatesTransactionServiceCharge->execute($payment->original_amount, $rate); + // $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, 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/Resources/CompanyResource.php b/app/Http/Resources/CompanyResource.php index 54ab047d..50a2da9c 100644 --- a/app/Http/Resources/CompanyResource.php +++ b/app/Http/Resources/CompanyResource.php @@ -55,6 +55,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/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/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'); });