mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-09-01 19:04:00 +00:00
E-Invoice - Partial completion of => Doc Delivery - E-INVOICE, E-CN, E-RN
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Classes\Modules\Wallets\Processors;
|
||||
|
||||
use App\Classes\Modules\Accounts\DataTransferObjects\KeyValuePairObject;
|
||||
use App\Models\Wallet;
|
||||
use App\Models\Company;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
@@ -14,6 +15,8 @@ use App\Classes\Modules\Transactions\Services\CreatesTransaction;
|
||||
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
|
||||
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
|
||||
use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
|
||||
use App\Classes\Modules\Accounts\Services\CreatesKeyValuePair;
|
||||
use App\Models\Transaction;
|
||||
|
||||
class CreditWalletProcessor
|
||||
{
|
||||
@@ -32,6 +35,9 @@ class CreditWalletProcessor
|
||||
/** @var UpdatesWallet */
|
||||
private $updatesWallet;
|
||||
|
||||
/** @var CreatesKeyValuePair */
|
||||
private $createsKeyValuePair;
|
||||
|
||||
/**
|
||||
* CreateWalletLogic constructor.
|
||||
* @param GeneratesWalletCode $generatesWalletCode
|
||||
@@ -39,13 +45,15 @@ class CreditWalletProcessor
|
||||
* @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
|
||||
* @param CreatesTransaction $createsTransaction
|
||||
* @param UpdatesWallet $updatesWallet
|
||||
* @param CreatesKeyValuePair $createsKeyValuePair
|
||||
*/
|
||||
public function __construct(
|
||||
GeneratesWalletCode $generatesWalletCode,
|
||||
CreatesWallet $createsWallet,
|
||||
GeneratesTransactionBillNumber $generatesTransactionBillNumber,
|
||||
CreatesTransaction $createsTransaction,
|
||||
UpdatesWallet $updatesWallet
|
||||
UpdatesWallet $updatesWallet,
|
||||
CreatesKeyValuePair $createsKeyValuePair
|
||||
)
|
||||
{
|
||||
$this->generatesWalletCode = $generatesWalletCode;
|
||||
@@ -53,6 +61,7 @@ class CreditWalletProcessor
|
||||
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
|
||||
$this->createsTransaction = $createsTransaction;
|
||||
$this->updatesWallet = $updatesWallet;
|
||||
$this->createsKeyValuePair = $createsKeyValuePair;
|
||||
}
|
||||
|
||||
|
||||
@@ -61,10 +70,11 @@ class CreditWalletProcessor
|
||||
* @param int $transactionType
|
||||
* @param float $amount
|
||||
* @param string $reference
|
||||
* @param $relatedTransaction
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Company $company, int $transactionType, float $amount, string $reference)
|
||||
public function execute(Company $company, int $transactionType, float $amount, string $reference, $relatedTransaction = null)
|
||||
{
|
||||
if (!$company->wallets()->first()) {
|
||||
$object = new WalletObject($company->id, 1, $this->generatesWalletCode->execute());
|
||||
@@ -75,16 +85,26 @@ class CreditWalletProcessor
|
||||
$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);
|
||||
|
||||
if($relatedTransaction && $relatedTransaction instanceof Transaction){
|
||||
$kvp = $relatedTransaction->attributesKVP()->where('key', 'App\Models\Transaction')->where('value', $transaction->id)->latest()->first();
|
||||
if(!$kvp){
|
||||
$keyValuePairObject = new KeyValuePairObject(
|
||||
"App\Models\Transaction",
|
||||
$transaction->id
|
||||
);
|
||||
$this->createsKeyValuePair->execute($relatedTransaction, $keyValuePairObject);
|
||||
}
|
||||
}
|
||||
return $wallet;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user