mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 12:34:18 +00:00
Compare commits
159 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| acfd16a4b1 | |||
| c493b3786c | |||
| 99f4699260 | |||
| 0ea52048e1 | |||
| a47bb95e50 | |||
| 431aed18d3 | |||
| 6ab289057b | |||
| c55a8e7af9 | |||
| fbf097eb62 | |||
| 30c2673fdf | |||
| fd3709e103 | |||
| 08473d85ab | |||
| 489974ca5a | |||
| 6a6a0f0ee7 | |||
| 402f64364b | |||
| a3bff9d079 | |||
| 2a7a448059 | |||
| 7d855064da | |||
| efc0a3b94e | |||
| 01654ee0d3 | |||
| 23c2f92e6d | |||
| 3945c47f52 | |||
| 51ab6ce48b | |||
| ca8140a1ba | |||
| a84580c1dd | |||
| 63b212a66c | |||
| 7979d89997 | |||
| bc603fc125 | |||
| b55fd49830 | |||
| 60ceac645f | |||
| 90c599049b | |||
| f538fb7f2f | |||
| a45105f5ae | |||
| 2f1a8ee648 | |||
| aacf4ea53d | |||
| 1fa2b60871 | |||
| 203dc0c230 | |||
| fcc4da1a56 | |||
| c5a49bbc44 | |||
| f8131b3a1e | |||
| 336cc0b37f | |||
| 42f096b09c | |||
| 614167cac5 | |||
| e5421f8810 | |||
| 8dc84baee0 | |||
| a413533975 | |||
| 0a98f8a8c6 | |||
| aceed5f754 | |||
| 761d191c1d | |||
| d769be137e | |||
| d6a5dd56c6 | |||
| f279d39ddb | |||
| 2e1e8875b4 | |||
| c30c5a36f2 | |||
| 7d3901ee48 | |||
| 463398945f | |||
| d619862e63 | |||
| 9665a0e242 | |||
| 7ed6c11f37 | |||
| 3eaee0d122 | |||
| b7816873fe | |||
| 8809caa046 | |||
| b8b6910a45 | |||
| 64bfbac4f7 | |||
| a5b7e79964 | |||
| 03c9bec256 | |||
| 06134e006c | |||
| 7563b455ba | |||
| 26edb3bebd | |||
| 55e1a6ad02 | |||
| 381425c6bc | |||
| 09ab95faf8 | |||
| 8bb6f0317a | |||
| fe95db2605 | |||
| 02640e6ae8 | |||
| 104dd19a6f | |||
| 89117c0706 | |||
| bc650b0816 | |||
| a6a239c489 | |||
| 45b78465da | |||
| 71edeca994 | |||
| cd229c6a8f | |||
| ebc3e588ca | |||
| 80471acc5b | |||
| ea08774111 | |||
| 4a1f05e62a | |||
| 840fb86192 | |||
| 7a171685f6 | |||
| 096e039ffb | |||
| 2319393758 | |||
| 85ba9d66d5 | |||
| 626dff6137 | |||
| 99efce22db | |||
| 4a9e89c752 | |||
| 39e3398f8e | |||
| 7db77d619b | |||
| 8f390311af | |||
| 6502957021 | |||
| d6ddf6d607 | |||
| b368b1c0d1 | |||
| a2ef3ed1b1 | |||
| e1b712ad10 | |||
| ddbfc5fdfd | |||
| 1cdd511f67 | |||
| f7d0fe117e | |||
| 4dede50156 | |||
| 0d555eedc9 | |||
| 7f73ec14a5 | |||
| 408397e20e | |||
| ef37f1ebbe | |||
| 914e9a6f0f | |||
| 525e7a5dd1 | |||
| a3cad7816c | |||
| 2100c4a14a | |||
| 0d090b4eaf | |||
| 73801a5acd | |||
| 2c0eeab84e | |||
| 40c4a39927 | |||
| 866df52e52 | |||
| b34d909a09 | |||
| 26b3e968e9 | |||
| 7b127b2cba | |||
| 7488313a0e | |||
| 7589b5c553 | |||
| d8391fe479 | |||
| c01e8d6eb2 | |||
| 5aad5f1729 | |||
| 485a6e2e82 | |||
| e7c0e17ee4 | |||
| 569273c058 | |||
| 80f229c6ec | |||
| 56b6b59967 | |||
| 299d5fd4fe | |||
| d56abc78f7 | |||
| b3b7b67c66 | |||
| d6f29976c7 | |||
| 842614700a | |||
| a0ca37ec16 | |||
| 08b2ba1c63 | |||
| c7f8831555 | |||
| df31b801f3 | |||
| 946c9b6e3d | |||
| bafc23bf6f | |||
| 2d13f69be6 | |||
| cb184c8f50 | |||
| b2a986b838 | |||
| 160fa2b2d9 | |||
| e0d0dccb4c | |||
| f47c7ebc50 | |||
| f30a0cf7ee | |||
| f2a02230c7 | |||
| 2978eed61d | |||
| c76c50466d | |||
| b4437c8907 | |||
| e7942731ad | |||
| 5db9d79cc1 | |||
| dff001c9b5 | |||
| 2353c637d7 | |||
| eea8708b76 |
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class BillNo implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('bill_no', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class DoesNotHaveGroups implements Filter
|
||||
{
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->whereDoesntHave('groups');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class DoesNotHavePaymentStatusIn implements Filter
|
||||
{
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->whereDoesntHave('transactions', function (Builder $query) use($value) {
|
||||
$query->where('type', TransactionType::PAYMENT)->whereIn('status', $value);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ class DoesNotHaveTransactionType implements Filter
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->whereDoesntHave('transactions', function (Builder $query) use($value) {
|
||||
$query->where('type', $value)->whereIn('status', [0,1,2,3]);
|
||||
$query->where('type', $value)->whereIn('status', [0,1,2,3,5]);
|
||||
})->whereHas('containers', function ($query){
|
||||
return $query->whereDate('loading_date', '>=', Carbon::parse('20-09-2022'));
|
||||
});
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class HavePaymentStatusNotIn implements Filter
|
||||
{
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->whereHas('transactions', function (Builder $query) use($value) {
|
||||
$query->where('type', TransactionType::PAYMENT)->whereNotIn('status', $value);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class PaymentMethodNotIn implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->whereNotIn('payment_method', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -24,12 +24,11 @@ class Helper
|
||||
return array_slice(get_class_methods($className), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @param $log
|
||||
* @return none
|
||||
*/
|
||||
static function debugLoggerForPerfexCRM($log){
|
||||
if($log){
|
||||
static function debugLogger($log){
|
||||
if($log && isset($log['message'])){
|
||||
$message = $log['message'];
|
||||
$substring = 'No data were found';
|
||||
if (isset($message)) {
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
namespace App\Classes\Jobs;
|
||||
|
||||
use App\Classes\Modules\PerfexCRM\Processors\UpdatePerfexCRMProcessor;
|
||||
use App\Classes\Modules\PerfexCRM\Processors\FetchPerfexCRMInvoiceProcessor;
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
@@ -10,6 +12,8 @@ use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMObject;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMInvoiceObject;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\FetchPerfexCRMInvoiceObject;
|
||||
|
||||
|
||||
class UpdatePerfexCRM implements ShouldQueue
|
||||
{
|
||||
@@ -18,37 +22,51 @@ class UpdatePerfexCRM implements ShouldQueue
|
||||
/** @var UpdatePerfexCRMObject */
|
||||
private $updatePerfexCRMObject;
|
||||
|
||||
/** @var UpdatePerfexCRMInvoice */
|
||||
private $nextJob;
|
||||
|
||||
/** @var */
|
||||
private $transaction;
|
||||
|
||||
/** @var bool|null */
|
||||
private $shouldCreateInvoice;
|
||||
|
||||
/**
|
||||
* UpdatePerfexCRM constructor.
|
||||
* @param UpdatePerfexCRMObject $updatePerfexCRMObject
|
||||
* @param UpdatePerfexCRMInvoice $nextJob
|
||||
* @param $transaction
|
||||
* @param Transaction $transaction
|
||||
* @param bool|null $shouldCreateInvoice
|
||||
*/
|
||||
public function __construct(UpdatePerfexCRMObject $updatePerfexCRMObject, $transaction, $nextJob)
|
||||
public function __construct(UpdatePerfexCRMObject $updatePerfexCRMObject, $transaction, ?bool $shouldCreateInvoice = false)
|
||||
{
|
||||
$this->updatePerfexCRMObject = $updatePerfexCRMObject;
|
||||
$this->nextJob = $nextJob;
|
||||
$this->transaction = $transaction;
|
||||
$this->shouldCreateInvoice = $shouldCreateInvoice;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
//To use invoice as a reference to decide whether more tasks should be created
|
||||
$this->updatePerfexCRMObject->setInvoiceId($this->getInvoiceIdOrCreateInvoice());
|
||||
|
||||
$result = (App()->make(UpdatePerfexCRMProcessor::class))->execute($this->updatePerfexCRMObject);
|
||||
if($this->nextJob != null && $this->transaction != null){
|
||||
if($this->transaction != null && $this->shouldCreateInvoice){
|
||||
$updatePerfexCRMInvoiceOject = new UpdatePerfexCRMInvoiceObject(
|
||||
$this->updatePerfexCRMObject->getContactEmail(),
|
||||
$result->projectId,
|
||||
$this->transaction,
|
||||
true
|
||||
);
|
||||
/** @var UpdatePerfexCRMInvoice $nextJob */
|
||||
$this->nextJob::dispatch($updatePerfexCRMInvoiceOject);
|
||||
UpdatePerfexCRMInvoice::dispatch($updatePerfexCRMInvoiceOject);
|
||||
}
|
||||
}
|
||||
|
||||
private function getInvoiceIdOrCreateInvoice(){
|
||||
if($this->transaction != null){
|
||||
$fetchPerfexCRMInvoiceObject = new FetchPerfexCRMInvoiceObject(
|
||||
$this->updatePerfexCRMObject->getContactEmail(),
|
||||
$this->transaction
|
||||
);
|
||||
$invoiceId = (App()->make(FetchPerfexCRMInvoiceProcessor::class))->execute($fetchPerfexCRMInvoiceObject);
|
||||
return $invoiceId;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ class UpdatePerfexCRMInvoice implements ShouldQueue
|
||||
|
||||
/**
|
||||
* CreatePerfexCRMSingleTask constructor.
|
||||
* @param UpdatePerfexCRMInvoiceObject $createTaskPerfexCRMObject
|
||||
* @param UpdatePerfexCRMInvoiceObject $updatePerfexCRMInvoiceObject
|
||||
*/
|
||||
public function __construct(UpdatePerfexCRMInvoiceObject $updatePerfexCRMInvoiceObject)
|
||||
{
|
||||
@@ -47,7 +47,7 @@ class UpdatePerfexCRMInvoice implements ShouldQueue
|
||||
$invoiceId = 0;
|
||||
$invoiceStatus = 0;
|
||||
$invoice = (App()->make(FetchesPerfexCRMInvoice::class))->execute($customer->userid,"INV-", $transaction->owner->bill_no);
|
||||
Log::error(json_encode('UpdatePerfexCRMInvoice debug $transaction->owner->bill_no: '.$transaction->owner->bill_no));
|
||||
Log::error('UpdatePerfexCRMInvoice debug bill_no: ' . $transaction->owner->bill_no . ', Project Id: ' . $this->updatePerfexCRMInvoiceObject->getProjectId());
|
||||
|
||||
if(is_null($invoice)){
|
||||
$result = (App()->make(CreatePerfexCRMInvoiceProcessor::class))->execute($transaction->owner, $this->updatePerfexCRMInvoiceObject->getIsPaid());
|
||||
@@ -55,7 +55,7 @@ class UpdatePerfexCRMInvoice implements ShouldQueue
|
||||
$invoiceId = $result->payload['id'];
|
||||
} else {
|
||||
// Log::error(json_encode('UpdatePerfexCRMInvoice CreatePerfexCRMInvoiceProcessor failed'));
|
||||
Helper::debugLoggerForPerfexCRM('UpdatePerfexCRMInvoice CreatePerfexCRMInvoiceProcessor failed');
|
||||
Helper::debugLogger('UpdatePerfexCRMInvoice CreatePerfexCRMInvoiceProcessor failed');
|
||||
}
|
||||
}
|
||||
else{
|
||||
@@ -64,7 +64,6 @@ class UpdatePerfexCRMInvoice implements ShouldQueue
|
||||
|
||||
//This only run when invoice already exist and the invoice does not have a PAID status
|
||||
if($invoiceStatus != PerfexCRMInvoiceStatus::PAID){
|
||||
Log::error(json_encode('UpdatePerfexCRMInvoice debug $this->updatePerfexCRMInvoiceObject->getProjectId(): '.$this->updatePerfexCRMInvoiceObject->getProjectId()));
|
||||
//update invoice
|
||||
(App()->make(UpdatesPerfexCRMInvoice::class))->execute($invoice, $this->updatePerfexCRMInvoiceObject->getProjectId());
|
||||
}
|
||||
|
||||
@@ -27,27 +27,22 @@ class UpdatePerfexCRMPrelude implements ShouldQueue
|
||||
/** @var UpdatePerfexCRMObject */
|
||||
private $updatePerfexCRMObject;
|
||||
|
||||
/** @var UpdatePerfexCRM */
|
||||
private $nextJob1;
|
||||
|
||||
/** @var UpdatePerfexCRMInvoice */
|
||||
private $nextJob2;
|
||||
/** @var bool|null */
|
||||
private $shouldCreateInvoice;
|
||||
|
||||
/**
|
||||
* UpdatePerfexCRMPrelude constructor.
|
||||
* @param $packingList
|
||||
* @param $transaction
|
||||
* @param Transaction $transaction
|
||||
* @param UpdatePerfexCRMObject $updatePerfexCRMObject
|
||||
* @param UpdatePerfexCRM $nextJob1
|
||||
* @param UpdatePerfexCRMInvoice $nextJob2
|
||||
* @param bool|null $shouldCreateInvoice
|
||||
*/
|
||||
public function __construct($packingList, $transaction, UpdatePerfexCRMObject $updatePerfexCRMObject, $nextJob1, $nextJob2)
|
||||
public function __construct($packingList, $transaction, UpdatePerfexCRMObject $updatePerfexCRMObject, ?bool $shouldCreateInvoice = false)
|
||||
{
|
||||
$this->packingList = $packingList;
|
||||
$this->transaction = $transaction;
|
||||
$this->updatePerfexCRMObject = $updatePerfexCRMObject;
|
||||
$this->nextJob1 = $nextJob1;
|
||||
$this->nextJob2 = $nextJob2;
|
||||
$this->shouldCreateInvoice = $shouldCreateInvoice;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
@@ -69,9 +64,7 @@ class UpdatePerfexCRMPrelude implements ShouldQueue
|
||||
|
||||
$result = $this->replacePlaceholders($this->updatePerfexCRMObject->getTasks(), $data);
|
||||
$this->updatePerfexCRMObject->setTasks($result);
|
||||
/** @var UpdatePerfexCRM $nextJob1 */
|
||||
/** @var UpdatePerfexCRMInvoice $nextJob2 */
|
||||
$this->nextJob1::dispatch($this->updatePerfexCRMObject, $this->transaction, $this->nextJob2);
|
||||
UpdatePerfexCRM::dispatch($this->updatePerfexCRMObject, $this->transaction, $this->shouldCreateInvoice);
|
||||
}
|
||||
|
||||
function replacePlaceholders($template, $data, $prefix = '')
|
||||
|
||||
@@ -4,29 +4,24 @@ namespace App\Classes\Modules\Billplzs\ControllersLogic;
|
||||
|
||||
use App\Classes\Modules\Orders\Processors\UpdateDoFromVTPortalProcessor;
|
||||
use App\Classes\Modules\Orders\Processors\UpdateDoFromYDPortalProcessor;
|
||||
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
|
||||
use App\Classes\Modules\Wallets\Services\UpdatesWallet;
|
||||
|
||||
use App\Classes\Exceptions\ResourceNotFoundException;
|
||||
use App\Classes\Modules\Wallets\Services\UpdatesWalletBalance;
|
||||
use App\Http\Resources\TransactionResource;
|
||||
use App\Models\Booking;
|
||||
use App\Models\User;
|
||||
use App\Models\Wallet;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\Modules\Billplzs\Services\GetBillplzBill;
|
||||
use App\Classes\Modules\Billplzs\DataTransferObjects\BillplzXSignatureObject;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||
use App\Classes\Modules\Transactions\Processors\CreatePaymentTransactionProcessor;
|
||||
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Models\Group;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CallbackBillplzLogic
|
||||
{
|
||||
@@ -45,6 +40,12 @@ class CallbackBillplzLogic
|
||||
/** @var UpdateDoFromYDPortalProcessor */
|
||||
private $updateDoFromYDPortalProcessor ;
|
||||
|
||||
/** @var UpdatesWalletBalance */
|
||||
private $updatesWalletBalance;
|
||||
|
||||
/** @var CreatePaymentTransactionProcessor */
|
||||
private $createPaymentTransactionProcessor;
|
||||
|
||||
/**
|
||||
* CallbackBillplzLogic constructor.
|
||||
* @param GetBillplzBill $getBillplzBill
|
||||
@@ -52,14 +53,17 @@ class CallbackBillplzLogic
|
||||
* @param UpdatesTransactionStatus $updatesTransactionStatus
|
||||
* @param UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor
|
||||
* @param UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor
|
||||
* @param CreatePaymentTransactionProcessor $createPaymentTransactionProcessor
|
||||
*/
|
||||
public function __construct(GetBillplzBill $getBillplzBill, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor, UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor)
|
||||
public function __construct(GetBillplzBill $getBillplzBill, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor, UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor, UpdatesWalletBalance $updatesWalletBalance, CreatePaymentTransactionProcessor $createPaymentTransactionProcessor)
|
||||
{
|
||||
$this->getBillplzBill = $getBillplzBill;
|
||||
$this->fetchesTransaction = $fetchesTransaction;
|
||||
$this->updatesTransactionStatus = $updatesTransactionStatus;
|
||||
$this->updateDoFromVTPortalProcessor = $updateDoFromVTPortalProcessor;
|
||||
$this->updateDoFromYDPortalProcessor = $updateDoFromYDPortalProcessor;
|
||||
$this->updatesWalletBalance = $updatesWalletBalance;
|
||||
$this->createPaymentTransactionProcessor = $createPaymentTransactionProcessor;
|
||||
}
|
||||
|
||||
|
||||
@@ -102,25 +106,51 @@ class CallbackBillplzLogic
|
||||
$token = Auth::fromUser(User::find(1));
|
||||
$request->headers->set('Authorization', 'Bearer '.$token);
|
||||
|
||||
// check if is wallet top up
|
||||
if($transaction->owner instanceof Wallet && $status === ApprovalStatus::APPROVED &&!in_array($transaction->status, [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])) {
|
||||
$this->updatesWalletBalance->execute($transaction->owner, $transaction->amount);
|
||||
}
|
||||
|
||||
// group payment
|
||||
if ($transaction->type == TransactionType::GROUP_PAYMENT && $status === ApprovalStatus::APPROVED &&!in_array($transaction->status, [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])) {
|
||||
$group = Group::where('reference', $billplzXSignatureObject->getBillPlzId())->first();
|
||||
|
||||
foreach($group->groupTransactions as $groupTransaction) {
|
||||
$invoice = $groupTransaction->transaction;
|
||||
$this->createPaymentTransactionProcessor->execute($invoice, PaymentMethodType::WALLET, null);
|
||||
}
|
||||
|
||||
$group->status = $status;
|
||||
$group->save();
|
||||
}
|
||||
|
||||
$this->updatesTransactionStatus->execute($transaction, $status);
|
||||
|
||||
$totalPaidAmount = $invoice->transactions->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->sum('amount');
|
||||
if (!$transaction->owner instanceof Wallet) {
|
||||
$totalPaidAmount = $invoice->transactions->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->sum('amount');
|
||||
|
||||
if(($invoice->amount - $totalPaidAmount) < 0.01) {
|
||||
$this->updatesTransactionStatus->execute($invoice, ApprovalStatus::COMPLETED);
|
||||
|
||||
$packingList->status = ApprovalStatus::APPROVED;
|
||||
$packingList->save();
|
||||
|
||||
if(app()->environment('production')){
|
||||
$this->updateDoFromVTPortalProcessor->execute($packingList);
|
||||
$this->updateDoFromYDPortalProcessor->execute($packingList);
|
||||
if(($invoice->amount - $totalPaidAmount) < 0.01) {
|
||||
$this->updatesTransactionStatus->execute($invoice, ApprovalStatus::COMPLETED);
|
||||
|
||||
$packingList->status = ApprovalStatus::APPROVED;
|
||||
$packingList->save();
|
||||
|
||||
if(app()->environment('production')){
|
||||
$this->updateDoFromVTPortalProcessor->execute($packingList);
|
||||
$this->updateDoFromYDPortalProcessor->execute($packingList);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$company_module_marking = $transaction->owner->owner->connections? $transaction->owner->owner->connections->first()->invitee_reference: null;
|
||||
|
||||
if ($transaction->owner instanceof Wallet) {
|
||||
$company_module_marking = $transaction->owner->owner->connections? $transaction->owner->owner->connections->first()->invitee_reference: null;
|
||||
} else {
|
||||
|
||||
$company_module_marking = $order->companyModule->connections? $order->companyModule->connections->first()->invitee_reference: null;
|
||||
}
|
||||
|
||||
return $request->method() === 'POST' ? true : view('pages.payments_redirect', ['marking' => $order->reference, 'transaction' => $transaction, 'status' => $status]);
|
||||
return $request->method() === 'POST' ? true : view('pages.payments_redirect', ['marking' => $order->reference ?? null, 'company_module_marking' => $company_module_marking ?? null, 'transaction' => $transaction, 'status' => $status]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace App\Classes\Modules\Billplzs\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use Illuminate\Support\Facades\App;
|
||||
|
||||
class CreatesBillplzBill
|
||||
{
|
||||
@@ -25,7 +26,7 @@ class CreatesBillplzBill
|
||||
$response = Http::withBasicAuth(config('billplz.api_key').':', '')->post(config('billplz.base_url').'/api/v3/bills', [
|
||||
'collection_id' => config('billplz.collection_id'),
|
||||
'name' => $name,
|
||||
'email' => $email,
|
||||
'email' => App::environment('production') ? $email : 'development@cief-malaysia.com',
|
||||
'description' => $description,
|
||||
'amount' => $this->finalizeAmount($amount),
|
||||
'redirect_url' => route('online_payment.redirect'),
|
||||
|
||||
@@ -15,9 +15,17 @@ use App\Classes\ValueObjects\Constants\OrderRoleTypes;
|
||||
|
||||
class ExportsArrivedParcel implements WithHeadings, WithHeadingRow, WithMapping, ShouldAutoSize, FromQuery
|
||||
{
|
||||
|
||||
use Exportable;
|
||||
|
||||
private $start_date;
|
||||
private $end_date;
|
||||
|
||||
public function __construct($start_date = null, $end_date = null)
|
||||
{
|
||||
$this->start_date = $start_date;
|
||||
$this->end_date = $end_date;
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
@@ -26,48 +34,66 @@ class ExportsArrivedParcel implements WithHeadings, WithHeadingRow, WithMapping,
|
||||
'Warehouse',
|
||||
'Cbm',
|
||||
'Description',
|
||||
'quantity',
|
||||
'Quantity',
|
||||
'Received Date',
|
||||
'Recorded On',
|
||||
'Days to Record',
|
||||
'Remarks'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection|mixed
|
||||
*/
|
||||
public function query()
|
||||
{
|
||||
return PackingList::where('type', '=', 1)->where('status', '=', 2)->where('owner_type', Order::class);
|
||||
$query = PackingList::with([
|
||||
// 'owner.companyModule.inviters',
|
||||
// 'owner.orderRoles',
|
||||
'packages',
|
||||
'transports'
|
||||
])
|
||||
->where('type', '=', 1);
|
||||
// ->where('status', '=', 2)
|
||||
// ->where('owner_type', Order::class);
|
||||
|
||||
if (!is_null($this->start_date) && !is_null($this->end_date)) {
|
||||
$query->whereHas('transports', function ($q) {
|
||||
$q->whereBetween('drop_date', [
|
||||
Carbon::parse($this->start_date)->startOfDay(),
|
||||
Carbon::parse($this->end_date)->endOfDay()
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $packingList
|
||||
* @return array
|
||||
*/
|
||||
public function map($packingList): array
|
||||
{
|
||||
$order = $packingList->owner;
|
||||
|
||||
$connection = $order->companyModule()->first()->inviters()->withPivot('invitee_reference')->first();
|
||||
$marking = $connection ? $connection->pivot->invitee_reference:'';
|
||||
|
||||
$warehouse = $order->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->appointee;
|
||||
|
||||
$cbm = $packingList->packages->sum(function($package){
|
||||
return (($package->width / 100) * ($package->height / 100) * ($package->length / 100)) * $package->quantity;
|
||||
$order = null;
|
||||
$marking = null;
|
||||
$warehouse = null;
|
||||
if ($packingList->owner instanceof Order) {
|
||||
$order = $packingList->owner;
|
||||
$marking = $order->companyModule->getMarking();
|
||||
$warehouse = $order->orderRoles->firstWhere('role_id', '=', OrderRoleTypes::ORIGIN_WAREHOUSE)->appointee;
|
||||
}
|
||||
$cbm = $packingList->packages->sum(function ($package) {
|
||||
return (($package->width / 100) * ($package->height / 100) * ($package->length / 100)) * $package->quantity;
|
||||
});
|
||||
|
||||
$arrival_date = $packingList->transports()->first()->drop_date->format('d-m-Y');
|
||||
$arrival_date = $packingList->transports->first()->drop_date->format('d-m-Y');
|
||||
$recorded_on = $packingList->created_at->format('d-m-Y');
|
||||
$days_to_record = Carbon::parse($arrival_date)->diffInDays(Carbon::parse($recorded_on));
|
||||
|
||||
return [
|
||||
$packingList->owner->reference,
|
||||
$marking,
|
||||
$warehouse->reference,
|
||||
$order ? $order->reference : 'Unclaimed',
|
||||
$marking ? $marking : 'Unclaimed',
|
||||
$warehouse ? $warehouse->reference : 'Unclaimed',
|
||||
$cbm,
|
||||
$packingList->packages->implode('description', ', '),
|
||||
$packingList->packages->sum('quantity'),
|
||||
$arrival_date,
|
||||
$recorded_on,
|
||||
$days_to_record,
|
||||
''
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ class ExportsPaymentTransactions implements FromQuery, WithHeadings, WithHeading
|
||||
'DocNo',
|
||||
'DocDate',
|
||||
'DebtorCode',
|
||||
'Ref',
|
||||
'ShipInfo',
|
||||
'AccNo',
|
||||
'DetailDescription',
|
||||
@@ -126,6 +127,7 @@ class ExportsPaymentTransactions implements FromQuery, WithHeadings, WithHeading
|
||||
$transaction->created_at->format('m/d/Y H:m'),
|
||||
$company->debtor,
|
||||
$order->reference,
|
||||
$order->reference,
|
||||
'500-0000',
|
||||
'X1 Freight Service Charge',
|
||||
$furtherDescription,
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Groups\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class GroupObject implements DataTransferObject
|
||||
{
|
||||
|
||||
/** @var int */
|
||||
private $issuer;
|
||||
|
||||
/** @var int */
|
||||
private $receiver;
|
||||
|
||||
/** @var float */
|
||||
private $amount;
|
||||
|
||||
/** @var float */
|
||||
private $originalAmount;
|
||||
|
||||
/** @var int */
|
||||
private $currencyId;
|
||||
|
||||
/** @var int */
|
||||
private $originalCurrencyId;
|
||||
|
||||
/** @var float */
|
||||
private $currencyRate;
|
||||
|
||||
/** @var float */
|
||||
private $tax;
|
||||
|
||||
/** @var float */
|
||||
private $serviceCharge;
|
||||
|
||||
/** @var int|null */
|
||||
private $status;
|
||||
|
||||
/** @var string */
|
||||
private $reference;
|
||||
|
||||
/** @var int */
|
||||
private $paymentMethod;
|
||||
|
||||
/**
|
||||
* GroupObject constructor.
|
||||
* @param int $issuer
|
||||
* @param int $receiver
|
||||
* @param float $amount
|
||||
* @param float $originalAmount
|
||||
* @param int $currencyId
|
||||
* @param int $originalCurrencyId
|
||||
* @param float $currencyRate
|
||||
* @param float $tax
|
||||
* @param float $serviceCharge
|
||||
* @param string $reference
|
||||
* @param int|null $status
|
||||
* @param int $paymentMethod
|
||||
*/
|
||||
public function __construct(
|
||||
int $issuer,
|
||||
int $receiver,
|
||||
float $amount,
|
||||
float $originalAmount,
|
||||
int $currencyId,
|
||||
int $originalCurrencyId,
|
||||
float $currencyRate,
|
||||
float $tax,
|
||||
float $serviceCharge,
|
||||
int $paymentMethod,
|
||||
?string $reference,
|
||||
?int $status = ApprovalStatus::PENDING_SUBMISSION
|
||||
)
|
||||
{
|
||||
$this->issuer = $issuer;
|
||||
$this->receiver = $receiver;
|
||||
$this->amount = $amount;
|
||||
$this->originalAmount = $originalAmount;
|
||||
$this->currencyId = $currencyId;
|
||||
$this->originalCurrencyId = $originalCurrencyId;
|
||||
$this->currencyRate = $currencyRate;
|
||||
$this->tax = $tax;
|
||||
$this->serviceCharge = $serviceCharge;
|
||||
$this->paymentMethod = $paymentMethod;
|
||||
$this->reference = $reference;
|
||||
$this->status = $status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getIssuer(): int
|
||||
{
|
||||
return $this->issuer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getReceiver(): int
|
||||
{
|
||||
return $this->receiver;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getAmount(): float
|
||||
{
|
||||
return $this->amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getOriginalAmount(): float
|
||||
{
|
||||
return $this->originalAmount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCurrencyId(): int
|
||||
{
|
||||
return $this->currencyId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getOriginalCurrencyId(): int
|
||||
{
|
||||
return $this->originalCurrencyId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getCurrencyRate(): float
|
||||
{
|
||||
return $this->currencyRate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getTax(): float
|
||||
{
|
||||
return $this->tax;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getServiceCharge(): float
|
||||
{
|
||||
return $this->serviceCharge;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getStatus(): ?int
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getReference(): ?string
|
||||
{
|
||||
return $this->reference;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getPaymentMethod(): int
|
||||
{
|
||||
return $this->paymentMethod;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Groups\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Groups\DataTransferObjects\GroupObject;
|
||||
use App\Models\Group;
|
||||
|
||||
class CreatesGroup extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param GroupObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(GroupObject $object) {
|
||||
$model = new Group();
|
||||
$model->issuer = $object->getIssuer();
|
||||
$model->receiver = $object->getReceiver();
|
||||
$model->amount = $object->getAmount();
|
||||
$model->original_amount = $object->getOriginalAmount();
|
||||
$model->currency_id = $object->getCurrencyId();
|
||||
$model->original_currency_id = $object->getOriginalCurrencyId();
|
||||
$model->currency_rate = $object->getCurrencyRate();
|
||||
$model->tax = $object->getTax();
|
||||
$model->service_charge = $object->getServiceCharge();
|
||||
$model->status = $object->getStatus();
|
||||
$model->reference = $object->getReference();
|
||||
$model->payment_method = $object->getPaymentMethod();
|
||||
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -83,11 +83,10 @@ class CreateOrderLogic extends AbstractControllerLogic
|
||||
} else {
|
||||
$originWarehouse = $this->fetchesCompanyModule->execute(['id' => $request->input('warehouse_id')]);
|
||||
|
||||
if (!in_array($company->companyModules()->importers()->first()->id, WarehouseReferences::YD_EXEMPT_LIST)) {
|
||||
$originWarehouse = $this->fetchesCompanyModule->execute(['reference' => $originWarehouse->reference === WarehouseReferences::VT_GUANG_ZHOU ? WarehouseReferences::YD_GUANG_ZHOU : WarehouseReferences::YD_YIWU]);
|
||||
}
|
||||
$originWarehouse = $this->fetchesCompanyModule->execute(['reference' => $originWarehouse->reference === WarehouseReferences::VT_GUANG_ZHOU ? WarehouseReferences::YD_GUANG_ZHOU : WarehouseReferences::YD_YIWU]);
|
||||
// if (!in_array($company->companyModules()->importers()->first()->id, WarehouseReferences::YD_EXEMPT_LIST))
|
||||
}
|
||||
|
||||
|
||||
if($originWarehouse->reference === WarehouseReferences::YD_YIWU && in_array($address->state_id, [5, 13, 14])) {
|
||||
throw new RequestValidationException('Our Yiwu warehouse is unable to ship goods to Sabah & Sarawak at the moment. you can select our Guangzhou warehouse as an alternative.');
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ class FetchesDataFromYDPortal
|
||||
$content = str_replace("\r",'', $content);
|
||||
$content = str_replace("\n",'', $content);
|
||||
$content = str_replace("\t",'', $content);
|
||||
$content = str_replace('"data":}', '"data":""}', $content);
|
||||
return json_decode($content);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\ControllersLogic;
|
||||
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\PackingLists\Processors\CreatePackingListProcessor;
|
||||
use App\Classes\Modules\PackingLists\Processors\CreatePackageProcessor;
|
||||
use App\Classes\Modules\Transports\Services\CreatesTransport;
|
||||
use App\Classes\Modules\PackingLists\Services\GeneratesPackingListReferenceNumber;
|
||||
use App\Classes\Modules\Schedules\Services\CreatesSchedule;
|
||||
use App\Classes\Modules\PackingLists\DataTransferObjects\PackingListObject;
|
||||
use App\Classes\Modules\PackingLists\DataTransferObjects\PackageObject;
|
||||
use App\Classes\Modules\PackingLists\Services\FetchesPackingList;
|
||||
use App\Classes\Modules\Transports\DataTransferObjects\TransportObject;
|
||||
use App\Classes\Modules\Schedules\DataTransferObjects\ScheduleObject;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\OrderRoleTypes;
|
||||
use App\Classes\ValueObjects\Constants\PackingListType;
|
||||
use App\Classes\ValueObjects\Constants\TransportType;
|
||||
use App\Http\Resources\PackingListResource;
|
||||
use App\Models\PackingList;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class CreateWarehouseTransportLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'Created Warehouse PackingList',
|
||||
'message' => 'You have successfully created a Warehouse PackingList'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var FetchesPackingList */
|
||||
private $fetchesPackingList;
|
||||
|
||||
/** @var CreatePackingListProcessor */
|
||||
private $createPackingListProcessor;
|
||||
|
||||
/** @var GeneratesPackingListReferenceNumber */
|
||||
private $generatesPackingListReferenceNumber;
|
||||
|
||||
/** @var CreatesTransport */
|
||||
private $createsTransport;
|
||||
|
||||
/** @var CreatePackageProcessor */
|
||||
private $createPackageProcessor;
|
||||
|
||||
/** @var CreatesSchedule */
|
||||
private $createsSchedule;
|
||||
|
||||
public function __construct(
|
||||
FetchesPackingList $fetchesPackingList,
|
||||
CreatePackingListProcessor $createPackingListProcessor,
|
||||
CreatesTransport $createsTransport,
|
||||
CreatesSchedule $createsSchedule,
|
||||
CreatePackageProcessor $createPackageProcessor,
|
||||
GeneratesPackingListReferenceNumber $generatesPackingListReferenceNumber
|
||||
) {
|
||||
$this->fetchesPackingList = $fetchesPackingList;
|
||||
$this->createPackingListProcessor = $createPackingListProcessor;
|
||||
$this->createsTransport = $createsTransport;
|
||||
$this->createsSchedule = $createsSchedule;
|
||||
$this->createPackageProcessor = $createPackageProcessor;
|
||||
$this->generatesPackingListReferenceNumber = $generatesPackingListReferenceNumber;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
{
|
||||
$packing_list = $this->fetchesPackingList->execute([
|
||||
'id' => $request->route('id'),
|
||||
]);
|
||||
|
||||
$count_warehouse_packing_list = PackingList::where('reference', $packing_list->reference)->where('type', PackingListType::WAREHOUSE_RECEIVE_LIST)->count();
|
||||
|
||||
if ($count_warehouse_packing_list) {
|
||||
throw new MalformedRequestException('Warehouse Receive List Exists');
|
||||
}
|
||||
|
||||
$order = $packing_list->owner;
|
||||
|
||||
$reference_number = $this->generatesPackingListReferenceNumber->execute();
|
||||
|
||||
$packingListObject = new PackingListObject(
|
||||
$packing_list->reference,
|
||||
$order->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->appointee->id,
|
||||
PackingListType::WAREHOUSE_RECEIVE_LIST,
|
||||
ApprovalStatus::PENDING_SUBMISSION
|
||||
);
|
||||
$packingList = $this->createPackingListProcessor->execute($packingListObject, $order);
|
||||
|
||||
$transportObject = new TransportObject(TransportType::LAND, null, $request->input('tracking'), Carbon::parse($request->input('receive_date')), Carbon::parse($request->input('receive_date')), ApprovalStatus::APPROVED);
|
||||
$transport = $this->createsTransport->execute($transportObject, $packingList);
|
||||
|
||||
$scheduleObject = new ScheduleObject(Carbon::parse($request->input('receive_date')), Carbon::parse($request->input('receive_date')), ApprovalStatus::APPROVED);
|
||||
$schedule = $this->createsSchedule->execute($transport, $scheduleObject);
|
||||
|
||||
$packages = $packing_list->packages;
|
||||
|
||||
foreach ($packages as $key => $row) {
|
||||
$packageObject = new PackageObject(
|
||||
$row['type'],
|
||||
$row['description'],
|
||||
$row['width'],
|
||||
$row['height'],
|
||||
$row['length'],
|
||||
$row['weight'],
|
||||
$row['quantity'],
|
||||
ApprovalStatus::APPROVED,
|
||||
$row['reference'],
|
||||
);
|
||||
$this->createPackageProcessor->execute($packageObject, $packingList);
|
||||
}
|
||||
|
||||
return $this->resourceResponse(new PackingListResource($packingList));
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,7 @@ use App\Classes\Modules\PackingLists\Standards\Rules\CanCreatePackingList;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\OrderRoleTypes;
|
||||
use App\Classes\ValueObjects\Constants\PackingListType;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMTasksYDStages;
|
||||
use App\Classes\ValueObjects\Constants\WarehouseReferences;
|
||||
use App\Models\Order;
|
||||
use App\Models\PackingList;
|
||||
@@ -65,7 +66,7 @@ class CreatePackingListProcessor
|
||||
$this->createsPackingList->execute($object, $packingList);
|
||||
|
||||
if(config('perfexcrm.is_enabled') == 'true'){
|
||||
$this->packingListToPerfexCRMProcessor->execute($packingList);
|
||||
$this->packingListToPerfexCRMProcessor->execute($packingList, PerfexCRMTasksYDStages::DEFAULT);
|
||||
}
|
||||
|
||||
return $packingList;
|
||||
|
||||
+14
-2
@@ -26,6 +26,7 @@ use App\Classes\Modules\Unity\Processors\AssignContractEntityProcessor;
|
||||
use App\Classes\Modules\Unity\Processors\CreateContractEntityProcessor;
|
||||
use App\Classes\Modules\Unity\Services\CreatesContract;
|
||||
use App\Classes\Modules\Unity\Services\UpdatesContractObligation;
|
||||
use App\Classes\Modules\PerfexCRM\Processors\PackingListToPerfexCRMProcessor;
|
||||
use App\Classes\Notifications\ShipmentDepartureEmail;
|
||||
use App\Classes\Notifications\ShipmentRescheduleEmail;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
@@ -35,6 +36,7 @@ use App\Classes\ValueObjects\Constants\PackageType;
|
||||
use App\Classes\ValueObjects\Constants\PackingListType;
|
||||
use App\Classes\ValueObjects\Constants\TransportType;
|
||||
use App\Classes\ValueObjects\Constants\WarehouseReferences;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMTasksYDStages;
|
||||
use App\Models\Container;
|
||||
use App\Models\Order;
|
||||
use App\Models\PackingList;
|
||||
@@ -62,20 +64,25 @@ class FetchContainersFromYdPortalProcessor
|
||||
/** @var CreateContainerProcessor */
|
||||
private $createContainerProcessor;
|
||||
|
||||
/** @var PackingListToPerfexCRMProcessor */
|
||||
private $packingListToPerfexCRMProcessor;
|
||||
|
||||
/**
|
||||
* @param FetchesDataFromYDPortal $fetchesDataFRomYDPortal
|
||||
* @param CreatesTransport $createsTransport
|
||||
* @param CreatesSchedule $createsSchedule
|
||||
* @param FetchesContainer $fetchesContainer
|
||||
* @param CreateContainerProcessor $createContainerProcessor
|
||||
* @param PackingListToPerfexCRMProcessor $packingListToPerfexCRMProcessor
|
||||
*/
|
||||
public function __construct(FetchesDataFromYDPortal $fetchesDataFRomYDPortal, CreatesTransport $createsTransport, CreatesSchedule $createsSchedule, FetchesContainer $fetchesContainer, CreateContainerProcessor $createContainerProcessor)
|
||||
public function __construct(FetchesDataFromYDPortal $fetchesDataFRomYDPortal, CreatesTransport $createsTransport, CreatesSchedule $createsSchedule, FetchesContainer $fetchesContainer, CreateContainerProcessor $createContainerProcessor, PackingListToPerfexCRMProcessor $packingListToPerfexCRMProcessor)
|
||||
{
|
||||
$this->fetchesDataFRomYDPortal = $fetchesDataFRomYDPortal;
|
||||
$this->createsTransport = $createsTransport;
|
||||
$this->createsSchedule = $createsSchedule;
|
||||
$this->fetchesContainer = $fetchesContainer;
|
||||
$this->createContainerProcessor = $createContainerProcessor;
|
||||
$this->packingListToPerfexCRMProcessor = $packingListToPerfexCRMProcessor;
|
||||
}
|
||||
|
||||
|
||||
@@ -87,7 +94,8 @@ class FetchContainersFromYdPortalProcessor
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$packingLists = PackingList::where('type', PackingListType::SHIPPING_PACKING_LIST)->doesntHave('containers')->get();
|
||||
$maxFetchTime = Carbon::now()->subMonths(4);
|
||||
$packingLists = PackingList::where('type', PackingListType::SHIPPING_PACKING_LIST)->whereDate('created_at', '>=', $maxFetchTime)->doesntHave('containers')->get();
|
||||
|
||||
foreach ($packingLists as $packingList) {
|
||||
$time_start = microtime(true);
|
||||
@@ -137,6 +145,10 @@ class FetchContainersFromYdPortalProcessor
|
||||
$container->packingLists()->detach($packingList);
|
||||
$container->packingLists()->attach($packingList);
|
||||
|
||||
if(config('perfexcrm.is_enabled') == 'true'){
|
||||
$this->packingListToPerfexCRMProcessor->execute($packingList, PerfexCRMTasksYDStages::LOAD_CONTAINER);
|
||||
}
|
||||
|
||||
$transport = $container->transports()->first();
|
||||
|
||||
if(!$transport){
|
||||
|
||||
+43
-4
@@ -8,9 +8,11 @@ use App\Classes\Modules\Orders\Services\FetchesDataFromYDPortal;
|
||||
use App\Classes\Modules\Schedules\DataTransferObjects\ScheduleObject;
|
||||
use App\Classes\Modules\Schedules\Services\CreatesSchedule;
|
||||
use App\Classes\Modules\Unity\Services\UpdatesContractObligation;
|
||||
use App\Classes\Modules\PerfexCRM\Processors\PackingListToPerfexCRMProcessor;
|
||||
use App\Classes\Notifications\ShipmentRescheduleEmail;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\OrderRoleTypes;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMTasksYDStages;
|
||||
use App\Models\Container;
|
||||
use App\Models\Order;
|
||||
use App\Models\PackingList;
|
||||
@@ -27,16 +29,21 @@ class FetchContainersUpdatesFromYdPortalProcessor
|
||||
/** @var CreatesSchedule */
|
||||
private $createsSchedule;
|
||||
|
||||
/** @var PackingListToPerfexCRMProcessor */
|
||||
private $packingListToPerfexCRMProcessor;
|
||||
|
||||
/**
|
||||
* @param FetchesDataFromYDPortal $fetchesDataFRomYDPortal
|
||||
* @param UpdatesContractObligation $updatesContractObligations
|
||||
* @param CreatesSchedule $createsSchedule
|
||||
* @param PackingListToPerfexCRMProcessor $packingListToPerfexCRMProcessor
|
||||
*/
|
||||
public function __construct(FetchesDataFromYDPortal $fetchesDataFRomYDPortal, UpdatesContractObligation $updatesContractObligations, CreatesSchedule $createsSchedule)
|
||||
public function __construct(FetchesDataFromYDPortal $fetchesDataFRomYDPortal, UpdatesContractObligation $updatesContractObligations, CreatesSchedule $createsSchedule, PackingListToPerfexCRMProcessor $packingListToPerfexCRMProcessor)
|
||||
{
|
||||
$this->fetchesDataFRomYDPortal = $fetchesDataFRomYDPortal;
|
||||
$this->updatesContractObligations = $updatesContractObligations;
|
||||
$this->createsSchedule = $createsSchedule;
|
||||
$this->packingListToPerfexCRMProcessor = $packingListToPerfexCRMProcessor;
|
||||
}
|
||||
|
||||
|
||||
@@ -51,7 +58,7 @@ class FetchContainersUpdatesFromYdPortalProcessor
|
||||
foreach ($containers as $container) {
|
||||
$time_start = microtime(true);
|
||||
|
||||
$packingList = $container->packingLists()->random();
|
||||
$packingList = $container->packingLists()->first();
|
||||
|
||||
$trackingRequest = $this->fetchesDataFRomYDPortal->clientRequest('http://www.yd-wl.com/api/ApiTracking.ashx', 'GET', [
|
||||
'trakingno' => $packingList->reference
|
||||
@@ -65,10 +72,14 @@ class FetchContainersUpdatesFromYdPortalProcessor
|
||||
|
||||
$unstuffingDate = null;
|
||||
$delayDate = null;
|
||||
$checkShipSailDate = null;
|
||||
$checkShipArrivalDate = null;
|
||||
|
||||
foreach (array_reverse($rows->data) as $trackingRow) {
|
||||
$rescheduleETD = strpos($trackingRow->remark, '开') || strpos($trackingRow->remark, '到港');
|
||||
$rescheduleETA = strpos($trackingRow->remark, '到港');
|
||||
|
||||
|
||||
if (($rescheduleETD !== false || $rescheduleETA !== false) && strpos($trackingRow->tracking, '货物装柜完成。') === false) {
|
||||
preg_match_all('/([0-9]+.{3})/', $trackingRow->remark, $matches);
|
||||
$dates = collect();
|
||||
@@ -97,10 +108,12 @@ class FetchContainersUpdatesFromYdPortalProcessor
|
||||
|
||||
if ($trackingRow->tracking === '到港') {
|
||||
$delayDate = Carbon::parse($trackingRow->trackingtime);
|
||||
$checkShipArrivalDate = Carbon::parse($trackingRow->trackingtime);
|
||||
}
|
||||
|
||||
if ($trackingRow->tracking === '已开船') {
|
||||
$delayDate = Carbon::parse($trackingRow->trackingtime)->addDays('5');
|
||||
$checkShipSailDate = Carbon::parse($trackingRow->trackingtime);
|
||||
}
|
||||
|
||||
if ($trackingRow->tracking === '货物已进目的港仓库') {
|
||||
@@ -108,7 +121,32 @@ class FetchContainersUpdatesFromYdPortalProcessor
|
||||
}
|
||||
}
|
||||
|
||||
dump($delayDate, $unstuffingDate);
|
||||
|
||||
if($checkShipSailDate){
|
||||
//check if ship has sailed
|
||||
if($checkShipSailDate->isPast()){
|
||||
foreach ($container->packingLists as $packingList){
|
||||
if(config('perfexcrm.is_enabled') == 'true'){
|
||||
$this->packingListToPerfexCRMProcessor->execute($packingList, PerfexCRMTasksYDStages::SHIP_SAILED);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($checkShipArrivalDate){
|
||||
//check if ship has arrived at destination
|
||||
if($checkShipArrivalDate->isPast()){
|
||||
foreach ($container->packingLists as $packingList){
|
||||
if(config('perfexcrm.is_enabled') == 'true'){
|
||||
$this->packingListToPerfexCRMProcessor->execute($packingList, PerfexCRMTasksYDStages::SHIP_ARRIVED);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if($delayDate){
|
||||
|
||||
$delayDate = $delayDate->addDays(2);
|
||||
$transport = $container->transports()->first();
|
||||
|
||||
@@ -124,7 +162,6 @@ class FetchContainersUpdatesFromYdPortalProcessor
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if($unstuffingDate){
|
||||
@@ -146,7 +183,9 @@ class FetchContainersUpdatesFromYdPortalProcessor
|
||||
$this->updatesContractObligations->execute($signature, $step->obligation_hash_id);
|
||||
$step->update(['status' => ApprovalStatus::COMPLETED]);
|
||||
}
|
||||
|
||||
if(config('perfexcrm.is_enabled') == 'true'){
|
||||
$this->packingListToPerfexCRMProcessor->execute($packingList, PerfexCRMTasksYDStages::UNSTUFFING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+11
-1
@@ -8,6 +8,8 @@ use App\Classes\Modules\Schedules\Services\CreatesSchedule;
|
||||
use App\Classes\Modules\Transports\DataTransferObjects\TransportObject;
|
||||
use App\Classes\Modules\Transports\Services\CreatesTransport;
|
||||
use App\Classes\Modules\Unity\Services\UpdatesContractObligation;
|
||||
use App\Classes\Modules\PerfexCRM\Processors\PackingListToPerfexCRMProcessor;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMTasksYDStages;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\OrderRoleTypes;
|
||||
use App\Classes\ValueObjects\Constants\PackingListType;
|
||||
@@ -34,16 +36,21 @@ class FetchDeliveryUpdatesFromYdPortalProcessor
|
||||
/** @var CreatesSchedule */
|
||||
private $createsSchedule;
|
||||
|
||||
/** @var PackingListToPerfexCRMProcessor */
|
||||
private $packingListToPerfexCRMProcessor;
|
||||
|
||||
/**
|
||||
* @param UpdatesContractObligation $updatesContractObligations
|
||||
* @param CreatesTransport $createsTransport
|
||||
* @param CreatesSchedule $createsSchedule
|
||||
* @param PackingListToPerfexCRMProcessor $packingListToPerfexCRMProcessor
|
||||
*/
|
||||
public function __construct(UpdatesContractObligation $updatesContractObligations, CreatesTransport $createsTransport, CreatesSchedule $createsSchedule)
|
||||
public function __construct(UpdatesContractObligation $updatesContractObligations, CreatesTransport $createsTransport, CreatesSchedule $createsSchedule, PackingListToPerfexCRMProcessor $packingListToPerfexCRMProcessor)
|
||||
{
|
||||
$this->updatesContractObligations = $updatesContractObligations;
|
||||
$this->createsTransport = $createsTransport;
|
||||
$this->createsSchedule = $createsSchedule;
|
||||
$this->packingListToPerfexCRMProcessor = $packingListToPerfexCRMProcessor;
|
||||
}
|
||||
|
||||
|
||||
@@ -99,6 +106,9 @@ class FetchDeliveryUpdatesFromYdPortalProcessor
|
||||
$this->updatesContractObligations->execute($signature, $deliveryStep->obligation_hash_id);
|
||||
$deliveryStep->update(['status' => ApprovalStatus::COMPLETED]);
|
||||
|
||||
if(config('perfexcrm.is_enabled') == 'true'){
|
||||
$this->packingListToPerfexCRMProcessor->execute($packingList, PerfexCRMTasksYDStages::DELIVERY);
|
||||
}
|
||||
}
|
||||
|
||||
$time_end = microtime(true);
|
||||
|
||||
@@ -121,6 +121,7 @@ class FetchPackingListsFromYdPortalProcessor
|
||||
}
|
||||
|
||||
$endDate = Carbon::today()->subDays($x - 1);
|
||||
|
||||
$orderRequest = $this->fetchesDataFRomYDPortal->clientRequest('http://www.yd-wl.com/api/GetOrderList.ashx', 'GET', [
|
||||
'begintime' => $startDate->timestamp,
|
||||
'endtime' => $endDate->timestamp,
|
||||
@@ -131,6 +132,7 @@ class FetchPackingListsFromYdPortalProcessor
|
||||
if(!$rows->data) continue;
|
||||
|
||||
foreach($rows->data as $row){
|
||||
if(!is_numeric($row->goodcount)) continue;
|
||||
|
||||
$time_start = microtime(true);
|
||||
|
||||
|
||||
@@ -42,7 +42,10 @@ class CreateTaskPerfexCRMObject implements DataTransferObject
|
||||
/** @var string */
|
||||
private $duedate;
|
||||
|
||||
public function __construct(string $email, string $name, string $description, string $leadId, string $projectId, string $milestoneId, string $reference, string $onTaskCompletion, string $status, string $department, string $priority, string $duedate)
|
||||
/** @var int */
|
||||
private $invoiceId;
|
||||
|
||||
public function __construct(string $email, string $name, string $description, string $leadId, string $projectId, string $milestoneId, string $reference, string $onTaskCompletion, string $status, string $department, string $priority, string $duedate, int $invoiceId)
|
||||
{
|
||||
$this->email = $email;
|
||||
$this->name = $name;
|
||||
@@ -56,6 +59,7 @@ class CreateTaskPerfexCRMObject implements DataTransferObject
|
||||
$this->department = $department;
|
||||
$this->priority = $priority;
|
||||
$this->duedate = $duedate;
|
||||
$this->invoiceId = $invoiceId;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -158,4 +162,12 @@ class CreateTaskPerfexCRMObject implements DataTransferObject
|
||||
{
|
||||
return $this->duedate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getInvoiceId(): int
|
||||
{
|
||||
return $this->invoiceId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PerfexCRM\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
use App\Models\Transaction;
|
||||
|
||||
class FetchPerfexCRMInvoiceObject implements DataTransferObject
|
||||
{
|
||||
/** @var string */
|
||||
private $email;
|
||||
|
||||
/** @var Transaction */
|
||||
private $transaction;
|
||||
|
||||
|
||||
public function __construct(string $email, Transaction $transaction)
|
||||
{
|
||||
$this->email = $email;
|
||||
$this->transaction = $transaction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getEmail(): string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Transaction
|
||||
*/
|
||||
public function getTransaction(): Transaction
|
||||
{
|
||||
return $this->transaction;
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,9 @@ class UpdatePerfexCRMObject implements DataTransferObject
|
||||
/** @var int */
|
||||
private $projectStatus;
|
||||
|
||||
/** @var int */
|
||||
private $invoiceId = 0;
|
||||
|
||||
/** @var array */
|
||||
private $milestoneNames;
|
||||
|
||||
@@ -35,7 +38,7 @@ class UpdatePerfexCRMObject implements DataTransferObject
|
||||
private $tasks;
|
||||
|
||||
|
||||
public function __construct(string $companyName, string $companyReference, string $contactName, string $contactEmail, string $bookingMarking, string $projectName, int $projectStatus, array $milestoneNames, array $tasks)
|
||||
public function __construct(string $companyName, string $companyReference, string $contactName, string $contactEmail, string $bookingMarking, string $projectName, int $projectStatus, int $invoiceId, array $milestoneNames, array $tasks)
|
||||
{
|
||||
|
||||
$this->companyName = $companyName;
|
||||
@@ -45,6 +48,7 @@ class UpdatePerfexCRMObject implements DataTransferObject
|
||||
$this->bookingMarking = $bookingMarking;
|
||||
$this->projectName = $projectName;
|
||||
$this->projectStatus = $projectStatus;
|
||||
$this->$invoiceId = $invoiceId;
|
||||
$this->milestoneNames = $milestoneNames;
|
||||
$this->tasks = $tasks;
|
||||
}
|
||||
@@ -105,6 +109,14 @@ class UpdatePerfexCRMObject implements DataTransferObject
|
||||
return $this->projectStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getInvoiceId(): int
|
||||
{
|
||||
return $this->invoiceId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
@@ -125,4 +137,9 @@ class UpdatePerfexCRMObject implements DataTransferObject
|
||||
{
|
||||
$this->tasks = $tasks;
|
||||
}
|
||||
|
||||
public function setInvoiceId($invoiceId)
|
||||
{
|
||||
$this->invoiceId = $invoiceId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -151,7 +151,8 @@ class CreatePerfexCRMInvoiceProcessor
|
||||
array_push($invoiceItems, $invoiceSingleItem);
|
||||
}
|
||||
|
||||
$total = $transaction->amount;
|
||||
// $total = $transaction->amount;
|
||||
$total = number_format($transaction->amount, 2,'.','') * 1;
|
||||
|
||||
//This setting is similar to Setup > Leads > Sources, Setup > Leads > Statuses
|
||||
//Can be found at Finance > Payment Modes
|
||||
|
||||
@@ -25,19 +25,7 @@ class CreatePerfexCRMTaskProcessor
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(CreateTaskPerfexCRMObject $createTaskPerfexCRMObject) {
|
||||
$this->createsPerfexCRMTask->execute(
|
||||
$createTaskPerfexCRMObject->getName(),
|
||||
$createTaskPerfexCRMObject->getDescription(),
|
||||
$createTaskPerfexCRMObject->getLeadId(),
|
||||
$createTaskPerfexCRMObject->getMilestoneId(),
|
||||
$createTaskPerfexCRMObject->getProjectId(),
|
||||
$createTaskPerfexCRMObject->getReference(),
|
||||
$createTaskPerfexCRMObject->getOnTaskCompletion(),
|
||||
$createTaskPerfexCRMObject->getDepartment(),
|
||||
$createTaskPerfexCRMObject->getStatus(),
|
||||
$createTaskPerfexCRMObject->getPriority(),
|
||||
$createTaskPerfexCRMObject->getDuedate()
|
||||
);
|
||||
$this->createsPerfexCRMTask->execute($createTaskPerfexCRMObject);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PerfexCRM\Processors;
|
||||
|
||||
|
||||
use App\Classes\Modules\PerfexCRM\Processors\CreatePerfexCRMInvoiceProcessor;
|
||||
use App\Classes\Modules\PerfexCRM\Services\FetchesPerfexCRMCustomer;
|
||||
use App\Classes\Modules\PerfexCRM\Services\FetchesPerfexCRMInvoice;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\FetchPerfexCRMInvoiceObject;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Classes\General\Helper;
|
||||
|
||||
class FetchPerfexCRMInvoiceProcessor
|
||||
{
|
||||
private $fetchesPerfexCRMCustomer;
|
||||
/** @var FetchesPerfexCRMCustomer */
|
||||
|
||||
/** @var FetchesPerfexCRMInvoice */
|
||||
private $fetchesPerfexCRMInvoice;
|
||||
|
||||
/** @var CreatePerfexCRMInvoiceProcessor */
|
||||
private $createPerfexCRMInvoiceProcessor;
|
||||
|
||||
/**
|
||||
*
|
||||
* FetchPerfexCRMInvoiceProcessor constructor.
|
||||
* @param FetchesPerfexCRMCustomer $fetchesPerfexCRMCustomer
|
||||
* @param FetchesPerfexCRMInvoice $fetchesPerfexCRMInvoice
|
||||
* @param CreatePerfexCRMInvoiceProcessor $createPerfexCRMInvoiceProcessor
|
||||
*/
|
||||
public function __construct(FetchesPerfexCRMCustomer $fetchesPerfexCRMCustomer,
|
||||
FetchesPerfexCRMInvoice $fetchesPerfexCRMInvoice,
|
||||
CreatePerfexCRMInvoiceProcessor $createPerfexCRMInvoiceProcessor)
|
||||
{
|
||||
$this->fetchesPerfexCRMCustomer = $fetchesPerfexCRMCustomer;
|
||||
$this->fetchesPerfexCRMInvoice = $fetchesPerfexCRMInvoice;
|
||||
$this->createPerfexCRMInvoiceProcessor = $createPerfexCRMInvoiceProcessor;
|
||||
}
|
||||
|
||||
public function execute(FetchPerfexCRMInvoiceObject $fetchPerfexCRMInvoiceObject)
|
||||
{
|
||||
//invoiceId to be returned - fetch or create
|
||||
$invoiceId = 0;
|
||||
|
||||
//get the client id
|
||||
$customer = $this->fetchesPerfexCRMCustomer->execute($fetchPerfexCRMInvoiceObject->getEmail());
|
||||
$transaction = $fetchPerfexCRMInvoiceObject->getTransaction();
|
||||
|
||||
$number = $transaction->owner->bill_no;
|
||||
|
||||
$prefix = "INV-";
|
||||
//This will remove the prefix if prefix already exist in the string
|
||||
if (substr($number, 0, strlen($prefix)) == $prefix) {
|
||||
$number = substr($number, strlen($prefix));
|
||||
}
|
||||
|
||||
$invoice = $this->fetchesPerfexCRMInvoice->execute($customer->userid,"INV-", $number);
|
||||
if(is_null($invoice)){
|
||||
$result = $this->createPerfexCRMInvoiceProcessor->execute($transaction->owner);
|
||||
if ($result) {
|
||||
$invoiceId = $result->payload['id'];
|
||||
} else {
|
||||
$log['message'] = 'FetchPerfexCRMInvoiceProcessor failed for transaction > bill_no: '.$number;
|
||||
Helper::debugLogger($log);
|
||||
}
|
||||
}
|
||||
else{
|
||||
$invoiceId = $invoice->id;
|
||||
}
|
||||
|
||||
return $invoiceId;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,8 @@ use App\Classes\Jobs\CreatePerfexCRMSingleTask;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMTaskPriority;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMTasks;
|
||||
use App\Models\Company;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
|
||||
class NewLeadTaskToPerfexCRMProcessor
|
||||
{
|
||||
@@ -17,26 +19,32 @@ class NewLeadTaskToPerfexCRMProcessor
|
||||
*/
|
||||
public function execute(Company $company)
|
||||
{
|
||||
$companyModule = $company->companyModules()->first();
|
||||
$employee = $companyModule->employees()->first();
|
||||
$contactEmail = $employee->email;
|
||||
try {
|
||||
$companyModule = $company->companyModules()->first();
|
||||
$employee = $companyModule->employees()->first();
|
||||
$contactEmail = $employee->email;
|
||||
|
||||
$createTaskPerfexCRMObject = new CreateTaskPerfexCRMObject(
|
||||
$contactEmail,
|
||||
PerfexCRMTasks::TASK_IDENTIFICATION_1['name'],
|
||||
PerfexCRMTasks::TASK_IDENTIFICATION_1['description'],
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
PerfexCRMTasks::TASK_IDENTIFICATION_1['status'],
|
||||
PerfexCRMTasks::TASK_IDENTIFICATION_1['department'],
|
||||
PerfexCRMTaskPriority::DEFAULT,
|
||||
"0"
|
||||
);
|
||||
$createTaskPerfexCRMObject = new CreateTaskPerfexCRMObject(
|
||||
$contactEmail,
|
||||
PerfexCRMTasks::TASK_IDENTIFICATION_1['name'],
|
||||
PerfexCRMTasks::TASK_IDENTIFICATION_1['description'],
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
"",
|
||||
PerfexCRMTasks::TASK_IDENTIFICATION_1['status'],
|
||||
PerfexCRMTasks::TASK_IDENTIFICATION_1['department'],
|
||||
PerfexCRMTaskPriority::DEFAULT,
|
||||
"0",
|
||||
0
|
||||
);
|
||||
|
||||
CreatePerfexCRMSingleTask::dispatch($createTaskPerfexCRMObject);
|
||||
CreatePerfexCRMSingleTask::dispatch($createTaskPerfexCRMObject);
|
||||
|
||||
} catch (\Exception $exception){
|
||||
Log::error($exception);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,57 +4,160 @@ namespace App\Classes\Modules\PerfexCRM\Processors;
|
||||
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMObject;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMTasks;
|
||||
use App\Classes\Jobs\UpdatePerfexCRM;
|
||||
use App\Classes\Jobs\UpdatePerfexCRMPrelude;
|
||||
use App\Models\PackingList;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMProjectStatus;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMTasksYDStages;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMTaskStatus;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class PackingListToPerfexCRMProcessor
|
||||
{
|
||||
/**
|
||||
* @param PackingList $packingList
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(PackingList $packingList)
|
||||
public function execute(PackingList $packingList, int $stage = PerfexCRMTasksYDStages::DEFAULT): bool
|
||||
{
|
||||
try {
|
||||
if($packingList->owner instanceof \App\Models\Order) {
|
||||
$order = $packingList->owner;
|
||||
$companyModule = $order->companyModule()->first();
|
||||
$connection = $companyModule->inviters()->withPivot('invitee_reference')->first();
|
||||
$companyName = $companyModule->name;
|
||||
$companyReference = $connection ? $connection->pivot->invitee_reference:'';
|
||||
$employee = $companyModule->employees()->first();
|
||||
$contactEmail = $employee->email;
|
||||
$contactName = $employee->name;
|
||||
|
||||
$orderReference = $packingList->owner->reference;
|
||||
$packingListReference = $packingList->reference;
|
||||
$projectName = 'IZYIM | X1 Shipping | '.$orderReference.' | '.$packingListReference;
|
||||
$info = $this->extractInfo($packingList);
|
||||
$tasks = $this->defineTasks($stage);
|
||||
|
||||
$updatePerfexCRMObject = new UpdatePerfexCRMObject(
|
||||
$companyName,
|
||||
$companyReference,
|
||||
$contactName,
|
||||
$contactEmail,
|
||||
"",
|
||||
$projectName,
|
||||
$info['companyName'],
|
||||
$info['companyReference'],
|
||||
$info['contactName'],
|
||||
$info['contactEmail'],
|
||||
$info['bookingMarking'], //For Exchange-2.0
|
||||
$info['projectName'],
|
||||
PerfexCRMProjectStatus::NOT_STARTED,
|
||||
0,
|
||||
[],
|
||||
[
|
||||
PerfexCRMTasks::TASK_LOADED_CONTAINER_1,
|
||||
PerfexCRMTasks::TASK_LOADED_CONTAINER_2,
|
||||
]
|
||||
$tasks
|
||||
);
|
||||
UpdatePerfexCRMPrelude::dispatch($packingList, null, $updatePerfexCRMObject, UpdatePerfexCRM::class, null);
|
||||
$this->dispatchUpdateJob($packingList, $updatePerfexCRMObject);
|
||||
}
|
||||
} catch (\Exception $exception){
|
||||
Log::error(json_encode('PackingListToPerfexCRMProcessor debug:'));
|
||||
Log::error(json_encode($packingList));
|
||||
Log::error('PackingListToPerfexCRMProcessor: ' . json_encode($packingList));
|
||||
Log::error($exception);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//Level 1
|
||||
private function extractInfo(PackingList $packingList): array
|
||||
{
|
||||
$order = $packingList->owner;
|
||||
$companyModule = $order->companyModule()->first();
|
||||
$employee = $companyModule->employees()->first();
|
||||
|
||||
$info = [];
|
||||
$info['companyName'] = $companyModule->name;
|
||||
$info['companyReference'] = $companyModule->inviters()->withPivot('invitee_reference')->first()->pivot->invitee_reference;
|
||||
$info['contactName'] = $employee->name;
|
||||
$info['contactEmail'] = $employee->email;
|
||||
$info['bookingMarking'] = ''; //For Exchange-2.0
|
||||
$info['projectName'] = 'IZYIM | X1 Shipping | '.$packingList->owner->reference.' | '.$packingList->reference;
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
private function defineTasks(int $stage): array
|
||||
{
|
||||
$tasks = [];
|
||||
|
||||
if ($stage === PerfexCRMTasksYDStages::DEFAULT) {
|
||||
$tasks = $this->defineAllYDStagesTasks();
|
||||
}
|
||||
else if ($stage === PerfexCRMTasksYDStages::LOAD_CONTAINER) {
|
||||
$tasks = $this->updateLoadContainerTasks();
|
||||
}
|
||||
else if ($stage === PerfexCRMTasksYDStages::SHIP_SAILED) {
|
||||
$tasks = $this->updateShipSailedTasks();
|
||||
}
|
||||
else if ($stage === PerfexCRMTasksYDStages::SHIP_ARRIVED) {
|
||||
$tasks = $this->updateShipArrivedTasks();
|
||||
}
|
||||
else if ($stage === PerfexCRMTasksYDStages::UNSTUFFING) {
|
||||
$tasks = $this->updateUnstuffingTasks();
|
||||
}
|
||||
else if ($stage === PerfexCRMTasksYDStages::DELIVERY) {
|
||||
$tasks = $this->updateDeliveryTasks();
|
||||
}
|
||||
|
||||
return $tasks;
|
||||
}
|
||||
|
||||
private function dispatchUpdateJob(PackingList $packingList, UpdatePerfexCRMObject $updatePerfexCRMObject)
|
||||
{
|
||||
UpdatePerfexCRMPrelude::dispatch($packingList, null, $updatePerfexCRMObject, false);
|
||||
}
|
||||
|
||||
|
||||
//Level Others: Nested
|
||||
private function defineAllYDStagesTasks(): array
|
||||
{
|
||||
$tasks = [
|
||||
PerfexCRMTasks::TASK_YD_LOADED_CONTAINER_1,
|
||||
PerfexCRMTasks::TASK_YD_LOADED_CONTAINER_2,
|
||||
PerfexCRMTasks::TASK_YD_LOADED_CONTAINER_3,
|
||||
PerfexCRMTasks::TASK_YD_SHIPPING_1,
|
||||
PerfexCRMTasks::TASK_YD_UNSTUFFING_1,
|
||||
PerfexCRMTasks::TASK_YD_DELIVERY_1,
|
||||
];
|
||||
|
||||
return $tasks;
|
||||
}
|
||||
|
||||
private function updateLoadContainerTasks(): array
|
||||
{
|
||||
$tasks = [];
|
||||
$tasks = $this->completeTask(null, PerfexCRMTasks::TASK_YD_LOADED_CONTAINER_3);
|
||||
return $tasks;
|
||||
}
|
||||
|
||||
private function updateShipSailedTasks(): array
|
||||
{
|
||||
$tasks = [];
|
||||
$tasks = $this->completeTask(PerfexCRMTasks::TASK_YD_LOADED_CONTAINER_3, PerfexCRMTasks::TASK_YD_SHIPPING_1);
|
||||
return $tasks;
|
||||
}
|
||||
|
||||
private function updateShipArrivedTasks(): array
|
||||
{
|
||||
$tasks = [];
|
||||
$tasks = $this->completeTask(PerfexCRMTasks::TASK_YD_SHIPPING_1, PerfexCRMTasks::TASK_YD_UNSTUFFING_1);
|
||||
return $tasks;
|
||||
}
|
||||
|
||||
private function updateUnstuffingTasks(): array
|
||||
{
|
||||
$tasks = [];
|
||||
$tasks = $this->completeTask(PerfexCRMTasks::TASK_YD_UNSTUFFING_1, PerfexCRMTasks::TASK_YD_DELIVERY_1);
|
||||
return $tasks;
|
||||
}
|
||||
|
||||
private function updateDeliveryTasks(): array
|
||||
{
|
||||
$tasks = [];
|
||||
$tasks = $this->completeTask(PerfexCRMTasks::TASK_YD_DELIVERY_1, null);
|
||||
return $tasks;
|
||||
}
|
||||
|
||||
private function completeTask($startTask, $endTask) {
|
||||
$resultArray = [];
|
||||
if($startTask){
|
||||
$startTask['status'] = PerfexCRMTaskStatus::COMPLETED;
|
||||
array_push($resultArray, $startTask);
|
||||
}
|
||||
if($endTask){
|
||||
$endTask['status'] = PerfexCRMTaskStatus::IN_PROGRESS;
|
||||
array_push($resultArray, $endTask);
|
||||
}
|
||||
|
||||
return $resultArray;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PerfexCRM\Processors;
|
||||
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMObject;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMTasks;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMProjectStatus;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\Jobs\UpdatePerfexCRMInvoice;
|
||||
use App\Classes\Jobs\UpdatePerfexCRM;
|
||||
use App\Classes\Jobs\UpdatePerfexCRMPrelude;
|
||||
use App\Classes\Jobs\CreatePerfexCRMInvoice;
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class TransactionToPerfexCRMProcessor
|
||||
{
|
||||
/**
|
||||
* @param Transaction $model
|
||||
* @param int $status
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Transaction $model, int $status)
|
||||
{
|
||||
try
|
||||
{
|
||||
if($model->owner instanceof \App\Models\Transaction && $status == ApprovalStatus::APPROVED)
|
||||
{
|
||||
$packingList = $model->owner->owner;
|
||||
$order = $packingList->owner()->first();
|
||||
$companyModule = $order->companyModule()->first();
|
||||
$companyName = $companyModule->name;
|
||||
$companyReference = $companyModule->inviters()->withPivot('invitee_reference')->first()->pivot->invitee_reference;
|
||||
$employee = $companyModule->employees()->first();
|
||||
$contactEmail = $employee->email;
|
||||
$contactName = $employee->name;
|
||||
|
||||
$orderReference = $order->reference;
|
||||
$packingListReference = $packingList->reference;
|
||||
$projectName = 'IZYIM | X1 Shipping | '.$orderReference.' | '.$packingListReference;
|
||||
|
||||
$bookingMarking = $packingList->id."-".$packingList->owner->id;
|
||||
$updatePerfexCRMObject = new UpdatePerfexCRMObject(
|
||||
$companyName,
|
||||
$companyReference,
|
||||
$contactName,
|
||||
$contactEmail,
|
||||
$bookingMarking,
|
||||
$projectName,
|
||||
PerfexCRMProjectStatus::IN_PROGRESS,
|
||||
[],
|
||||
[
|
||||
PerfexCRMTasks::TASK_1,
|
||||
PerfexCRMTasks::TASK_POST_PAYMENT_1,
|
||||
PerfexCRMTasks::TASK_POST_PAYMENT_2,
|
||||
PerfexCRMTasks::TASK_POST_PAYMENT_3,
|
||||
PerfexCRMTasks::TASK_POST_PAYMENT_4,
|
||||
]
|
||||
);
|
||||
|
||||
UpdatePerfexCRMPrelude::dispatch(null, $model, $updatePerfexCRMObject, UpdatePerfexCRM::class, UpdatePerfexCRMInvoice::class);
|
||||
}
|
||||
else if($model->owner instanceof \App\Models\PackingList && $model->status == ApprovalStatus::PENDING_SUBMISSION && $status == ApprovalStatus::APPROVED)
|
||||
{
|
||||
CreatePerfexCRMInvoice::dispatch($model);
|
||||
}
|
||||
}
|
||||
catch (\Exception $exception) {
|
||||
Log::error('TransactionToPerfexCRMProcessor debug:');
|
||||
Log::error($exception);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,145 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PerfexCRM\Processors;
|
||||
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMObject;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMTasks;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMProjectStatus;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMTaskStatus;
|
||||
use App\Classes\Jobs\UpdatePerfexCRMPrelude;
|
||||
use App\Classes\Jobs\CreatePerfexCRMInvoice;
|
||||
use App\Models\Booking;
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class TransactionToPerfexCRMV2Processor
|
||||
{
|
||||
public function execute(Transaction $model, int $status)
|
||||
{
|
||||
try {
|
||||
if($model->owner instanceof \App\Models\Transaction && in_array($model->type, [TransactionType::PAYMENT])) {
|
||||
//
|
||||
$transaction = $model;
|
||||
$info = $this->extractInfo($transaction);
|
||||
$tasks = $this->defineTasks($model, $status);
|
||||
|
||||
//if(count($tasks) > 0) { //commented, otherwise when customer paid, invoice payment will not get created at crm because there is no tasks attached
|
||||
$updatePerfexCRMObject = new UpdatePerfexCRMObject(
|
||||
$info['companyName'],
|
||||
$info['companyReference'],
|
||||
$info['contactName'],
|
||||
$info['contactEmail'],
|
||||
$info['bookingMarking'],
|
||||
$info['projectName'],
|
||||
PerfexCRMProjectStatus::IN_PROGRESS,
|
||||
0, //invoiceId
|
||||
[], //milestoneNames
|
||||
$tasks
|
||||
);
|
||||
|
||||
$this->dispatchUpdateJob($transaction, $status, $updatePerfexCRMObject);
|
||||
//}
|
||||
}
|
||||
else if($model->owner instanceof \App\Models\PackingList && $model->status == ApprovalStatus::PENDING_SUBMISSION && $status == ApprovalStatus::APPROVED)
|
||||
{
|
||||
CreatePerfexCRMInvoice::dispatch($model);
|
||||
}
|
||||
} catch (\Exception $exception) {
|
||||
Log::error($exception);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
//Level 1
|
||||
private function extractInfo(Transaction $model): array
|
||||
{
|
||||
$packingList = $model->owner->owner;
|
||||
$order = $packingList->owner()->first();
|
||||
$companyModule = $order->companyModule()->first();
|
||||
$employee = $companyModule->employees()->first();
|
||||
|
||||
$info = [];
|
||||
$info['companyName'] = $companyModule->name;
|
||||
$info['companyReference'] = $companyModule->inviters()->withPivot('invitee_reference')->first()->pivot->invitee_reference;
|
||||
$info['contactName'] = $employee->name;
|
||||
$info['contactEmail'] = $employee->email;
|
||||
$info['bookingMarking'] = $packingList->id."-".$packingList->owner->id;
|
||||
$info['projectName'] = 'IZYIM | X1 Shipping | '.$order->reference.' | '.$packingList->reference;
|
||||
|
||||
return $info;
|
||||
}
|
||||
|
||||
private function defineTasks(Transaction $model, int $status): array
|
||||
{
|
||||
$tasks = [];
|
||||
|
||||
if ($status === ApprovalStatus::PENDING_SUBMISSION) {
|
||||
$tasks = $this->defineTasks_handlePendingVerificationStatus($model);
|
||||
} elseif ($status === ApprovalStatus::APPROVED) {
|
||||
$tasks = $this->defineTasks_handleApprovedStatus($model);
|
||||
}
|
||||
|
||||
return $tasks;
|
||||
}
|
||||
|
||||
private function dispatchUpdateJob(Transaction $model, int $status, UpdatePerfexCRMObject $updatePerfexCRMObject)
|
||||
{
|
||||
$withInvoice = ($model->type === TransactionType::PAYMENT && $model->owner instanceof \App\Models\Transaction && $status == ApprovalStatus::APPROVED);
|
||||
UpdatePerfexCRMPrelude::dispatch(null, $model, $updatePerfexCRMObject, $withInvoice);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//Level Others: Nested
|
||||
private function defineTasks_handlePendingVerificationStatus(Transaction $model): array
|
||||
{
|
||||
$tasks = [];
|
||||
switch($model->type) {
|
||||
case TransactionType::PAYMENT:
|
||||
$tasks = $this->definePaymentTasks($model);
|
||||
break;
|
||||
}
|
||||
|
||||
return $tasks;
|
||||
}
|
||||
|
||||
private function defineTasks_handleApprovedStatus(Transaction $model): array
|
||||
{
|
||||
$tasks = [];
|
||||
switch($model->type) {
|
||||
case TransactionType::PAYMENT:
|
||||
$tasks = $this->defineTasks_handleApprovedStatus_handlePaymentApprovedStatus();
|
||||
break;
|
||||
}
|
||||
|
||||
return $tasks;
|
||||
}
|
||||
|
||||
|
||||
private function definePaymentTasks(Transaction $model): array //cief todo: to comfirm what tasks need to be created
|
||||
{
|
||||
$tasks = [];
|
||||
return $tasks;
|
||||
}
|
||||
|
||||
private function defineTasks_handleApprovedStatus_handlePaymentApprovedStatus(): array //cief todo: to comfirm what tasks need to be created
|
||||
{
|
||||
$tasks = [];
|
||||
// $tasks = [
|
||||
// PerfexCRMTasks::TASK_POST_PAYMENT_1,
|
||||
// PerfexCRMTasks::TASK_POST_PAYMENT_2,
|
||||
// PerfexCRMTasks::TASK_POST_PAYMENT_3,
|
||||
// PerfexCRMTasks::TASK_POST_PAYMENT_4,
|
||||
// ];
|
||||
return $tasks;
|
||||
}
|
||||
|
||||
private function completeTask($startTask, $endTask) {
|
||||
$startTask['status'] = PerfexCRMTaskStatus::COMPLETED;
|
||||
$endTask['status'] = PerfexCRMTaskStatus::IN_PROGRESS;
|
||||
return [$startTask, $endTask];
|
||||
}
|
||||
}
|
||||
@@ -15,10 +15,11 @@ use App\Classes\Modules\PerfexCRM\Services\UpdatesPerfexCRMTask;
|
||||
use App\Classes\Modules\PerfexCRM\Services\UpdatesPerfexCRMCustomer;
|
||||
use App\Classes\Modules\PerfexCRM\Services\UpdatesPerfexCRMProject;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\CustomerContactObject;
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMObject;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\CreateTaskPerfexCRMObject;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMTaskStatus;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMProjectStatus;
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -207,18 +208,46 @@ class UpdatePerfexCRMProcessor
|
||||
}
|
||||
|
||||
// Get existing or create task
|
||||
$result = $this->fetchesPerfexCRMTask->execute($tasks[$count]['name'], $milestoneId, 'project', $projectId);
|
||||
$taskName = $tasks[$count]['name'];
|
||||
$taskReference = $tasks[$count]['reference'];
|
||||
$taskOnTaskCompletion = $tasks[$count]['on_task_completion'];
|
||||
$taskIsAllowMultiple = $tasks[$count]['is_allow_multiple'];
|
||||
$taskIsOnTaskCompletionUpdate = $tasks[$count]['is_on_task_completion_update'];
|
||||
if($updatePerfexCRMObject->getInvoiceId() != 0 && $taskIsAllowMultiple){
|
||||
$taskName = $taskName." (".$updatePerfexCRMObject->getInvoiceId().")";
|
||||
$taskReference = $taskReference."_".$updatePerfexCRMObject->getInvoiceId();
|
||||
if($taskOnTaskCompletion && $taskIsOnTaskCompletionUpdate){
|
||||
$taskOnTaskCompletion = $taskOnTaskCompletion."_".$updatePerfexCRMObject->getInvoiceId();
|
||||
}
|
||||
}
|
||||
|
||||
$result = $this->fetchesPerfexCRMTask->execute($taskName, $milestoneId, 'project', $projectId, $updatePerfexCRMObject->getInvoiceId());
|
||||
|
||||
if(isset($result->payload)){
|
||||
break; //Breaking the rest of the tasks in array assuming that they are all created as a batch previously
|
||||
//The following are code not needed at Shipping Portal, Exchange need certain task's status to be updated dynamically
|
||||
// if($taskStatus != PerfexCRMTaskStatus::NOT_STARTED && $result->payload[0]['status'] == PerfexCRMTaskStatus::NOT_STARTED)
|
||||
// {
|
||||
// $task = $result->payload[0];
|
||||
// $result = $this->updatesPerfexCRMTask->execute($task['id'], $task['name'], $task['milestone'], $task['rel_id'], $taskStatus, $task['startdate'], is_null($task['duedate']) ? '': $task['duedate']);
|
||||
// }
|
||||
//Check to make sure that task that is already completed do not get updated again
|
||||
if($taskStatus != PerfexCRMTaskStatus::NOT_STARTED && $result->payload[0]['status'] != PerfexCRMTaskStatus::COMPLETED && $result->payload[0]['status'] != $taskStatus)
|
||||
{
|
||||
$task = $result->payload[0];
|
||||
$result = $this->updatesPerfexCRMTask->execute($task['id'], $task['name'], $task['milestone'], $task['rel_id'], $taskStatus, $task['startdate'], is_null($task['duedate']) ? '': $task['duedate']);
|
||||
}
|
||||
}
|
||||
else{
|
||||
$result = $this->createsPerfexCRMTask->execute($tasks[$count]['name'], $tasks[$count]['description'], '', $milestoneId, $projectId, $tasks[$count]['reference'], $tasks[$count]['on_task_completion'], $tasks[$count]['department'], $taskStatus, $tasks[$count]['priority'], $tasks[$count]['duedate']);
|
||||
$createTaskPerfexCRMObject = new CreateTaskPerfexCRMObject(
|
||||
"",
|
||||
$taskName,
|
||||
$tasks[$count]['description'],
|
||||
"",
|
||||
$projectId,
|
||||
$milestoneId,
|
||||
$taskReference,
|
||||
$taskOnTaskCompletion,
|
||||
$taskStatus,
|
||||
$tasks[$count]['department'],
|
||||
$tasks[$count]['priority'],
|
||||
$tasks[$count]['duedate'],
|
||||
$updatePerfexCRMObject->getInvoiceId()
|
||||
);
|
||||
$result = $this->createsPerfexCRMTask->execute($createTaskPerfexCRMObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class ConvertsPerfexCRMLeadToCustomer
|
||||
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::error($response);
|
||||
Log::error('ConvertsPerfexCRMLeadToCustomer: '.$response);
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
|
||||
@@ -27,7 +27,7 @@ class CreatesPerfexCRMCustomer
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::error($response);
|
||||
Log::error('CreatesPerfexCRMCustomer: '.$response);
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
|
||||
@@ -34,7 +34,7 @@ class CreatesPerfexCRMCustomerContact
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::error($response);
|
||||
Log::error('CreatesPerfexCRMCustomerContact: '.$response);
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
|
||||
@@ -33,7 +33,7 @@ class CreatesPerfexCRMCustomerProject
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::error($response);
|
||||
Log::error('CreatesPerfexCRMCustomerProject: '.$response);
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
|
||||
@@ -53,7 +53,7 @@ class CreatesPerfexCRMInvoice
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::error($response);
|
||||
Log::error('CreatesPerfexCRMInvoice: '.$response);
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
|
||||
@@ -33,7 +33,7 @@ class CreatesPerfexCRMInvoicePayment
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::error($response);
|
||||
Log::error('CreatesPerfexCRMInvoicePayment: '.$response);
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
|
||||
@@ -40,7 +40,7 @@ class CreatesPerfexCRMLead
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::error($response);
|
||||
Log::error('CreatesPerfexCRMLead: '.$response);
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
|
||||
@@ -36,7 +36,7 @@ class CreatesPerfexCRMMilestone
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::error($response);
|
||||
Log::error('CreatesPerfexCRMMilestone: '.$response);
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
|
||||
@@ -6,67 +6,47 @@ use Illuminate\Support\Facades\Http;
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use App\Classes\ValueObjects\Constants\PerfexCRMCustomFields;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\CreateTaskPerfexCRMObject;
|
||||
|
||||
class CreatesPerfexCRMTask
|
||||
{
|
||||
/**
|
||||
* @param string $taskName
|
||||
* @param string $taskDescription
|
||||
* @param string $leadId
|
||||
* @param string $milestoneId
|
||||
* @param string $projectId
|
||||
* @param string $reference
|
||||
* @param string $on_task_completion
|
||||
* @param string $department
|
||||
* @param string $status
|
||||
* @param string $priority
|
||||
* @param string $duedate
|
||||
* @param CreateTaskPerfexCRMObject $createTaskPerfexCRMObject
|
||||
* @return null|object
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function execute(string $taskName, string $taskDescription, string $leadId, string $milestoneId, string $projectId, string $reference, string $on_task_completion, string $department, string $status, string $priority, string $duedate) {
|
||||
|
||||
public function execute(CreateTaskPerfexCRMObject $createTaskPerfexCRMObject) {
|
||||
try{
|
||||
$custom_fields = [];
|
||||
if($department != ""){
|
||||
if($createTaskPerfexCRMObject->getDepartment() != ""){
|
||||
$custom_fields = [
|
||||
"tasks" => [
|
||||
PerfexCRMCustomFields::TASKS_DEPARTMENT => $department
|
||||
PerfexCRMCustomFields::TASKS_DEPARTMENT => $createTaskPerfexCRMObject->getDepartment()
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
$data = [
|
||||
'name' => $taskName,
|
||||
'description' => $taskDescription,
|
||||
'milestone' => $milestoneId,
|
||||
'name' => $createTaskPerfexCRMObject->getName(),
|
||||
'description' => $createTaskPerfexCRMObject->getDescription(),
|
||||
'milestone' => $createTaskPerfexCRMObject->getMilestoneId(),
|
||||
'startdate' => date('Y-m-d'),
|
||||
'rel_type' => 'project',
|
||||
'rel_id' => $projectId,
|
||||
'status' => $status,
|
||||
'rel_id' => $createTaskPerfexCRMObject->getProjectId(),
|
||||
'status' => $createTaskPerfexCRMObject->getStatus(),
|
||||
'is_system_created' => 1,
|
||||
'reference' => $reference,
|
||||
'on_task_completion' => $on_task_completion,
|
||||
'reference' => $createTaskPerfexCRMObject->getReference(),
|
||||
'on_task_completion' => $createTaskPerfexCRMObject->getOnTaskCompletion(),
|
||||
'custom_fields' => $custom_fields,
|
||||
'priority' => $priority,
|
||||
'duedate' => date('Y-m-d', strtotime('+' . $duedate . ' days')),
|
||||
'priority' => $createTaskPerfexCRMObject->getPriority(),
|
||||
'duedate' => date('Y-m-d', strtotime('+' . $createTaskPerfexCRMObject->getDuedate() . ' days')),
|
||||
'invoice_id' => $createTaskPerfexCRMObject->getInvoiceId(),
|
||||
];
|
||||
|
||||
if($leadId != '') {
|
||||
$data = [
|
||||
'name' => $taskName,
|
||||
'description' => $taskDescription,
|
||||
'milestone' => $milestoneId,
|
||||
'startdate' => date('Y-m-d'),
|
||||
'rel_type' => 'lead',
|
||||
'rel_id' => $leadId,
|
||||
'status' => $status,
|
||||
'is_system_created' => 1,
|
||||
'reference' => $reference,
|
||||
'on_task_completion' => $on_task_completion,
|
||||
'custom_fields' => $custom_fields,
|
||||
'priority' => $priority,
|
||||
'duedate' => date('Y-m-d', strtotime('+' . $duedate . ' days')),
|
||||
];
|
||||
if($createTaskPerfexCRMObject->getLeadId() != '') {
|
||||
$data['rel_type'] = 'lead';
|
||||
$data['rel_id'] = $createTaskPerfexCRMObject->getLeadId();
|
||||
}
|
||||
|
||||
$response = Http::asForm()->withHeaders([
|
||||
@@ -77,7 +57,7 @@ class CreatesPerfexCRMTask
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::error($response);
|
||||
Log::error('CreatesPerfexCRMTask: '.$response);
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
|
||||
@@ -24,7 +24,7 @@ class FetchesPerfexCRMCustomer
|
||||
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::error($response);
|
||||
Log::error('FetchesPerfexCRMCustomer: '.$response);
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
|
||||
@@ -26,7 +26,7 @@ class FetchesPerfexCRMInvoice
|
||||
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::error($response);
|
||||
Log::error('FetchesPerfexCRMInvoice: '.$response);
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
|
||||
@@ -24,7 +24,7 @@ class FetchesPerfexCRMLead
|
||||
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::error($response);
|
||||
Log::error('FetchesPerfexCRMLead: '.$response);
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
|
||||
@@ -30,7 +30,7 @@ class FetchesPerfexCRMMilestone
|
||||
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::error($response);
|
||||
Log::error('FetchesPerfexCRMMilestone: '.$response);
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
|
||||
@@ -30,7 +30,7 @@ class FetchesPerfexCRMProject
|
||||
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::error($response);
|
||||
Log::error('FetchesPerfexCRMProject: '.$response);
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
|
||||
@@ -17,7 +17,7 @@ class FetchesPerfexCRMTask
|
||||
* @return null|object
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function execute(string $taskName, string $milestoneId, string $relType, string $relId) {
|
||||
public function execute(string $taskName, string $milestoneId, string $relType, string $relId, string $invoiceId) {
|
||||
try{
|
||||
$data = [
|
||||
'name' => $taskName,
|
||||
@@ -30,6 +30,11 @@ class FetchesPerfexCRMTask
|
||||
$data = array_merge($data, $newItem);
|
||||
}
|
||||
|
||||
if($invoiceId != 0) {
|
||||
$newItem = ['invoice_id' => $invoiceId ];
|
||||
$data = array_merge($data, $newItem);
|
||||
}
|
||||
|
||||
$response = Http::asForm()->withHeaders([
|
||||
'authtoken' => config('perfexcrm.api_key')])
|
||||
->post(config('perfexcrm.base_url').'/api/tasks/customsearch', $data);
|
||||
@@ -39,7 +44,7 @@ class FetchesPerfexCRMTask
|
||||
|
||||
return (object) $data;
|
||||
}else{
|
||||
Helper::debugLoggerForPerfexCRM($response);
|
||||
Helper::debugLogger($response);
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
|
||||
@@ -38,7 +38,7 @@ class UpdatesPerfexCRMCustomer
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
Helper::debugLoggerForPerfexCRM($response);
|
||||
// Helper::debugLogger($response);
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
|
||||
@@ -60,7 +60,7 @@ class UpdatesPerfexCRMInvoice
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::error($response);
|
||||
Log::error('UpdatesPerfexCRMInvoice: '.$response);
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
|
||||
@@ -41,7 +41,7 @@ class UpdatesPerfexCRMLead
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::error($response);
|
||||
Log::error('UpdatesPerfexCRMLead: '.$response);
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
|
||||
@@ -33,7 +33,7 @@ class UpdatesPerfexCRMProject
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::error($response);
|
||||
Log::error('UpdatesPerfexCRMProject: '.$response);
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
|
||||
@@ -38,7 +38,7 @@ class UpdatesPerfexCRMTask
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::error($response);
|
||||
Log::error('UpdatesPerfexCRMTask: '.$response);
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
|
||||
@@ -29,7 +29,8 @@ class UpdateConstantPostcodeLogic extends AbstractControllerLogic
|
||||
* @param UpdatePostcodeSegmentProcessor $updatePostcodeSegmentProcessor
|
||||
*/
|
||||
public function __construct(
|
||||
UpdatePostcodeSegmentProcessor $updatePostcodeSegmentProcessor)
|
||||
UpdatePostcodeSegmentProcessor $updatePostcodeSegmentProcessor
|
||||
)
|
||||
{
|
||||
$this->updatePostcodeSegmentProcessor = $updatePostcodeSegmentProcessor;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||
use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompanyModule;
|
||||
use App\Classes\Modules\Groups\DataTransferObjects\GroupObject;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Classes\Modules\Transactions\Processors\CreatePaymentTransactionProcessor;
|
||||
use App\Models\Group;
|
||||
use App\Classes\Modules\Groups\Services\CreatesGroup;
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Classes\Modules\Wallets\Processors\CreateWalletTopUpTransactionProcessor;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Models\GroupTransaction;
|
||||
use App\Http\Resources\WalletTransactionResource;
|
||||
use App\Models\Wallet;
|
||||
|
||||
class CreateGroupsLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Create Group Transaction',
|
||||
'message' => 'You have successfully created a group transaction'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var FetchesTransaction */
|
||||
private $fetchesTransaction;
|
||||
|
||||
/** @var GeneratesTransactionBillNumber */
|
||||
private $generatesTransactionBillNumber;
|
||||
|
||||
|
||||
/** @var FetchesCompanyModule */
|
||||
private $fetchesCompanyModule;
|
||||
|
||||
/** @var CreateWalletTopUpTransactionProcessor */
|
||||
private $createWalletTopUpTransactionProcessor;
|
||||
|
||||
/** @var CreatePaymentTransactionProcessor */
|
||||
private $createPaymentTransactionProcessor;
|
||||
|
||||
/** @var CreatesGroup */
|
||||
private $createsGroup;
|
||||
|
||||
public function __construct(
|
||||
FetchesTransaction $fetchesTransaction,
|
||||
GeneratesTransactionBillNumber $generatesTransactionBillNumber,
|
||||
FetchesCompanyModule $fetchesCompanyModule,
|
||||
CreateWalletTopUpTransactionProcessor $createWalletTopUpTransactionProcessor,
|
||||
CreatePaymentTransactionProcessor $createPaymentTransactionProcessor,
|
||||
CreatesGroup $createsGroup
|
||||
)
|
||||
{
|
||||
$this->fetchesTransaction = $fetchesTransaction;
|
||||
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
|
||||
$this->fetchesCompanyModule = $fetchesCompanyModule;
|
||||
$this->createWalletTopUpTransactionProcessor = $createWalletTopUpTransactionProcessor;
|
||||
$this->createPaymentTransactionProcessor = $createPaymentTransactionProcessor;
|
||||
$this->createsGroup = $createsGroup;
|
||||
}
|
||||
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$payment_method = PaymentMethodType::PAYMENT_METHODS[$request->input('payment_method')];
|
||||
$groupPyamentStatus = ApprovalStatus::PENDING_VERIFICATION;
|
||||
|
||||
$invoice_ids = json_decode($request->route('transaction_ids'));
|
||||
$billNumber = $this->generatesTransactionBillNumber->execute('PYMT-');
|
||||
|
||||
// todo-new: check why is this not working
|
||||
// $invoices = $this->fetchesTransaction->execute(['id_in' => $invoice_ids]);
|
||||
$invoices = Transaction::whereIn('id', $invoice_ids)->get();
|
||||
|
||||
if ($payment_method == PaymentMethodType::WALLET) {
|
||||
|
||||
$companyModuleId = $invoices->first()->receiver;
|
||||
|
||||
$wallet = Wallet::where('owner_id', $companyModuleId)->first();
|
||||
|
||||
// todo-new: verify currently checking wallet amount based on 'amount' value passed by frontend
|
||||
if((float) number_format(($wallet->amount - $request->input('amount')),2) < 0){
|
||||
throw new MalformedRequestException('Insufficient wallet balance. Please Top up your wallet.');
|
||||
}
|
||||
|
||||
$groupPyamentStatus = ApprovalStatus::APPROVED;
|
||||
}
|
||||
|
||||
$issuer = 0;
|
||||
$receiver = 0;
|
||||
$amount = 0;
|
||||
$original_amount = 0;
|
||||
$currency_id = 0;
|
||||
$original_currency_id = 0;
|
||||
$currency_rate = 0;
|
||||
$tax = 0;
|
||||
$service_charge = 0;
|
||||
|
||||
$group = new GroupObject(
|
||||
$issuer,
|
||||
$receiver,
|
||||
$amount,
|
||||
$original_amount,
|
||||
$currency_id,
|
||||
$original_currency_id,
|
||||
$currency_rate,
|
||||
$tax,
|
||||
$service_charge,
|
||||
$payment_method,
|
||||
'-',
|
||||
$groupPyamentStatus,
|
||||
);
|
||||
|
||||
$group = $this->createsGroup->execute($group);
|
||||
|
||||
foreach ($invoices as $invoice) {
|
||||
if ($payment_method == PaymentMethodType::WALLET) {
|
||||
$this->createPaymentTransactionProcessor->execute($invoice, PaymentMethodType::WALLET, $request->input('bank_code'));
|
||||
}
|
||||
|
||||
$issuer = $invoice->issuer;
|
||||
$receiver = $invoice->receiver;
|
||||
$amount += $invoice->amount;
|
||||
$original_amount += $invoice->original_amount;
|
||||
$currency_id = $invoice->currency_id;
|
||||
$original_currency_id = $invoice->original_currency_id;
|
||||
$currency_rate = $invoice->currency_rate;
|
||||
$tax += $invoice->tax;
|
||||
$service_charge += $invoice->service_charge;
|
||||
|
||||
// creates group transaction
|
||||
$groupTransaction = new GroupTransaction();
|
||||
$groupTransaction->group_id = $group->id;
|
||||
$groupTransaction->transaction_id = $invoice->id;
|
||||
$groupTransaction->save();
|
||||
}
|
||||
|
||||
if (in_array($payment_method, [PaymentMethodType::PAYMENT_GATEWAY, PaymentMethodType::CASH])) {
|
||||
// create only one billplz payment for wallet top up
|
||||
$amount = floatval(str_replace(',', '', $request->input('amount')));
|
||||
$companyModuleId = $invoice->receiver;
|
||||
$companyModule = $this->fetchesCompanyModule->execute(['id' => $companyModuleId]);
|
||||
|
||||
$topUpTransaction = $this->createWalletTopUpTransactionProcessor->execute($companyModule, $amount, $request->input('bank_code'), true, $payment_method);
|
||||
}
|
||||
|
||||
$group->issuer = $issuer;
|
||||
$group->receiver = $receiver;
|
||||
$group->reference = $payment_method === PaymentMethodType::PAYMENT_GATEWAY ? $topUpTransaction->payment_reference : $billNumber;
|
||||
$group->amount = $amount;
|
||||
$group->original_amount = $original_amount;
|
||||
$group->currency_id = $currency_id;
|
||||
$group->original_currency_id = $original_currency_id;
|
||||
$group->currency_rate = $currency_rate;
|
||||
$group->tax = $tax;
|
||||
$group->service_charge = $service_charge;
|
||||
$group->status = $groupPyamentStatus;
|
||||
$group->save();
|
||||
|
||||
if ($payment_method === PaymentMethodType::PAYMENT_GATEWAY) {
|
||||
return $this->resourceResponse(new WalletTransactionResource($topUpTransaction));
|
||||
|
||||
} else {
|
||||
return $this->response([]);
|
||||
}
|
||||
}
|
||||
}
|
||||
+20
-79
@@ -5,30 +5,15 @@ namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||
use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
|
||||
use App\Classes\Modules\Transactions\Services\CreatesPaymentTransaction;
|
||||
use App\Classes\Modules\Transactions\Services\CreatesTransactionDetail;
|
||||
use App\Classes\Modules\Billplzs\Services\CreatesBillplzBill;
|
||||
|
||||
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
|
||||
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionDetailObject;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\OrderRoleTypes;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
|
||||
use App\Http\Resources\TransactionResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
|
||||
use App\Classes\Modules\Transactions\Processors\CreatePaymentTransactionProcessor;
|
||||
|
||||
class CreatePaymentTransactionLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
@@ -42,83 +27,39 @@ class CreatePaymentTransactionLogic extends AbstractControllerLogic
|
||||
/** @var FetchesTransaction */
|
||||
private $fetchesTransaction;
|
||||
|
||||
/** @var FetchesSegmentConstant */
|
||||
private $fetchesSegmentConstant;
|
||||
|
||||
/** @var GeneratesTransactionBillNumber */
|
||||
private $generatesTransactionBillNumber;
|
||||
|
||||
/** @var CreatesPaymentTransaction */
|
||||
private $createsPaymentTransaction;
|
||||
|
||||
/** @var CreatesBillplzBill */
|
||||
private $createsBillplzBill;
|
||||
|
||||
/** @var CreatesTransactionDetail */
|
||||
private $createsTransactionDetail;
|
||||
/** @var CreatePaymentTransactionProcessor */
|
||||
private $createPaymentTransactionProcessor;
|
||||
|
||||
public function __construct(
|
||||
FetchesTransaction $fetchesTransaction,
|
||||
GeneratesTransactionBillNumber $generatesTransactionBillNumber,
|
||||
CreatesPaymentTransaction $createsPaymentTransaction,
|
||||
CreatesTransactionDetail $createsTransactionDetail,
|
||||
CreatesBillplzBill $createsBillplzBill
|
||||
FetchesTransaction $fetchesTransaction,
|
||||
CreatePaymentTransactionProcessor $createPaymentTransactionProcessor
|
||||
)
|
||||
{
|
||||
$this->fetchesTransaction = $fetchesTransaction;
|
||||
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
|
||||
$this->createsPaymentTransaction = $createsPaymentTransaction;
|
||||
$this->createsTransactionDetail = $createsTransactionDetail;
|
||||
$this->createsBillplzBill = $createsBillplzBill;
|
||||
$this->createPaymentTransactionProcessor = $createPaymentTransactionProcessor;
|
||||
}
|
||||
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$payment_method = PaymentMethodType::PAYMENT_METHODS[$request->input('payment_method')];
|
||||
|
||||
$invoice_transaction = $this->fetchesTransaction->execute(['id' => $request->input('transaction_id')]);
|
||||
$amount = $request->input('amount');
|
||||
$company_module = $invoice_transaction->owner()->first()->owner()->first()->companyModule()->first();
|
||||
|
||||
$billNumber = $this->generatesTransactionBillNumber->execute('PYMT-');
|
||||
$payment_reference = null;
|
||||
if ($request->input('payment_method') == 5) {
|
||||
$payment_method = PaymentMethodType::PAYMENT_GATEWAY;
|
||||
$billPlzBill = $this->createsBillplzBill->execute(
|
||||
$company_module->name,
|
||||
(app()->environment(['production'])) ? $company_module->employees()->first()->email : 'uldvstar@gmail.com',
|
||||
'This payment is for the invoice number . ' . $invoice_transaction->bill_no,
|
||||
$amount,
|
||||
$billNumber,
|
||||
$request->input('bank_code'),
|
||||
true
|
||||
);
|
||||
$payment_transaction = $this->createPaymentTransactionProcessor->execute($invoice_transaction, $payment_method , $request->input('bank_code'));
|
||||
|
||||
$payment_reference = $billPlzBill->id;
|
||||
}
|
||||
else {
|
||||
$payment_method = PaymentMethodType::CASH;
|
||||
}
|
||||
//cief todo: at exchange there is a transition step
|
||||
// if(PaymentMethodType::PAYMENT_METHODS[$request->input('payment_method')] == PaymentMethodType::PAYMENT_GATEWAY){
|
||||
// $this->updatesTransactionStatus->execute($transaction, ApprovalStatus::PENDING_VERIFICATION);
|
||||
// }
|
||||
|
||||
$object = new TransactionObject(
|
||||
$billNumber,
|
||||
TransactionType::PAYMENT,
|
||||
$company_module->id,
|
||||
1,
|
||||
1,
|
||||
$payment_method,
|
||||
$request->input('amount'),
|
||||
$request->input('amount'),
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
null,
|
||||
ApprovalStatus::PENDING_SUBMISSION,
|
||||
null,
|
||||
$payment_reference
|
||||
);
|
||||
// if(config('perfexcrm.is_enabled') == 'true'){
|
||||
// $this->transactionToPerfexCRMV2Processor->execute($transaction, $status);
|
||||
// }
|
||||
|
||||
//To use
|
||||
//ApprovalStatus::PENDING_VERIFICATION;
|
||||
//use this to trigger $this->transactionToPerfexCRMV2Processor->execute > defineTasks > defineTasks_handlePendingVerificationStatus > definePaymentTasks
|
||||
|
||||
$payment_transaction = $this->createsPaymentTransaction->execute($invoice_transaction, $object);
|
||||
|
||||
return $this->resourceResponse(new TransactionResource($payment_transaction));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Transactions\Services\FetchesGroup;
|
||||
use App\Classes\Modules\Transactions\Services\DeletesTransaction;
|
||||
use App\Classes\Modules\Transactions\Services\DeletesGroup;
|
||||
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class DeleteGroupLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Delete Group Transaction',
|
||||
'message' => 'You have successfully deleted this Group Transaction'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var FetchesGroup */
|
||||
private $fetchesGroup;
|
||||
|
||||
/** @var DeletesGroup */
|
||||
private $deletesGroup;
|
||||
|
||||
/**
|
||||
* DeleteGroupLogic constructor.
|
||||
* @param updatesTransactionStatus $updatesTransactionStatus
|
||||
* @param FetchesGroup $fetchesGroup
|
||||
* @param DeletesTransaction $deletesTransaction
|
||||
*/
|
||||
public function __construct(FetchesGroup $fetchesGroup, DeletesGroup $deletesGroup)
|
||||
{
|
||||
$this->fetchesGroup = $fetchesGroup;
|
||||
$this->deletesGroup = $deletesGroup;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$group = $this->fetchesGroup->execute(['id' => $request->route('id')]);
|
||||
|
||||
$this->deletesGroup->execute($group);
|
||||
|
||||
return $this->response([]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompanyModule;
|
||||
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
|
||||
class GenerateCreditNotePdfLogic
|
||||
{
|
||||
|
||||
/** @var FetchesTransaction */
|
||||
private $fetchesTransaction;
|
||||
|
||||
/** @var FetchesCompanyModule */
|
||||
private $fetchesCompanyModule;
|
||||
|
||||
/**
|
||||
* GenerateCreditNotePdfLogic constructor.
|
||||
* @param FetchesTransaction $fetchesTransaction
|
||||
* @param FetchesCompany $fetchesCompany
|
||||
*/
|
||||
public function __construct(FetchesTransaction $fetchesTransaction, FetchesCompanyModule $fetchesCompanyModule)
|
||||
{
|
||||
$this->fetchesTransaction = $fetchesTransaction;
|
||||
$this->fetchesCompanyModule = $fetchesCompanyModule;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return string|\Symfony\Component\HttpFoundation\Response
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Request $request)
|
||||
{
|
||||
$transaction = $this->fetchesTransaction->execute(['id' => $request->route('id')]);
|
||||
|
||||
$supplier = $this->fetchesCompanyModule->execute(['id' => $transaction->receiver]);
|
||||
|
||||
$pdf = LaravelMpdf::loadView('pages.pdfs.credit_note', ['transaction' => $transaction, 'supplier' => $supplier]);
|
||||
|
||||
return $pdf->stream('CreditNote.pdf');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Transactions\Services\ListsGroups;
|
||||
use App\Http\Resources\GroupResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ListGroupsLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* ListTransactionsLogic constructor.
|
||||
* @param ListsGroups $listsGroups
|
||||
*/
|
||||
public function __construct(ListsGroups $listsGroups)
|
||||
{
|
||||
$this->listsGroups = $listsGroups;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Groups',
|
||||
'message' => 'You have successfully retrieved a list of groups'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var ListsGroups */
|
||||
private $listsGroups;
|
||||
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$query = $this->listsGroups->execute($this->listsGroups->deserializeFilters($request->input('filters')));
|
||||
|
||||
return $this->collectionResponse(GroupResource::collection($query));
|
||||
}
|
||||
|
||||
}
|
||||
+56
@@ -0,0 +1,56 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Transactions\Services\ListsTransactions;
|
||||
use App\Http\Resources\MappableTransactionWithDetailsResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class ListMappableTransactionWithDetailsLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Transactions With Details',
|
||||
'message' => 'You have successfully retrieved a list of transactions'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/** @var ListsTransactions */
|
||||
private $listsTransactions;
|
||||
|
||||
/**
|
||||
* ListTransactionsLogic constructor.
|
||||
* @param ListsTransactions $listsTransactions
|
||||
*/
|
||||
public function __construct(ListsTransactions $listsTransactions)
|
||||
{
|
||||
$this->listsTransactions = $listsTransactions;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$filePath = storage_path('logs/list_mappable_transaction_with_details.log');
|
||||
$textToAppend = Carbon::now()->format('[Y-m-d H:i:s]') . ' ' . $request->input('filters') . PHP_EOL;
|
||||
|
||||
file_put_contents($filePath, $textToAppend, FILE_APPEND);
|
||||
|
||||
$query = $this->listsTransactions->execute($this->listsTransactions->deserializeFilters($request->input('filters')));
|
||||
|
||||
return $this->collectionResponse(MappableTransactionWithDetailsResource::collection($query));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Transactions\Services\ListsTransactions;
|
||||
use App\Http\Resources\BookingResource;
|
||||
use App\Http\Resources\MappableTransactionResource;
|
||||
use App\Http\Resources\TransactionResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ListMappableTransactionsLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Transactions',
|
||||
'message' => 'You have successfully retrieved a list of transactions'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/** @var ListsTransactions */
|
||||
private $listsTransactions;
|
||||
|
||||
/**
|
||||
* ListTransactionsLogic constructor.
|
||||
* @param ListsTransactions $listsTransactions
|
||||
*/
|
||||
public function __construct(ListsTransactions $listsTransactions)
|
||||
{
|
||||
$this->listsTransactions = $listsTransactions;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
|
||||
$query = $this->listsTransactions->execute($this->listsTransactions->deserializeFilters($request->input('filters')));
|
||||
|
||||
return $this->collectionResponse(MappableTransactionResource::collection($query));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Models\Order;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
|
||||
use App\Classes\Modules\Documents\Services\CreatesDocument;
|
||||
use App\Classes\Modules\Documents\Services\CreatesFiles;
|
||||
use App\Models\Document;
|
||||
|
||||
class RegenerateShippingInvoiceTransactionLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Regenerate Shipping Invoice',
|
||||
'message' => 'You have successfully regenerated shipping invoice'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CreatesDocument */
|
||||
private $createsDocument;
|
||||
|
||||
/** @var CreatesFiles */
|
||||
private $createsFiles;
|
||||
|
||||
/**
|
||||
* @param CreatesDocument $createsDocument
|
||||
*/
|
||||
public function __construct(CreatesDocument $createsDocument, CreatesFiles $createsFiles)
|
||||
{
|
||||
$this->createsDocument = $createsDocument;
|
||||
$this->createsFiles = $createsFiles;
|
||||
}
|
||||
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
|
||||
$orders = Order::where('company_module_id', $request->route('company_module_id'))->get();
|
||||
|
||||
foreach ($orders as $order){
|
||||
$invoices = $order->transactions()->where('transactions.type', TransactionType::SHIPPING_INVOICE)->get();
|
||||
foreach ($invoices as $invoice){
|
||||
|
||||
$invoice->documents()->delete();
|
||||
|
||||
$transaction_invoice_pdf = LaravelMpdf::loadView('pages.pdfs.shipping_invoice', ['invoice_transaction' => $invoice]);
|
||||
|
||||
$document_object = new DocumentObject(
|
||||
DocumentType::SHIPPING_INVOICE,
|
||||
[chunk_split('data:application/pdf;base64,'.base64_encode($transaction_invoice_pdf->output()))],
|
||||
'',
|
||||
ApprovalStatus::COMPLETED,
|
||||
'shipping_invoice'
|
||||
);
|
||||
|
||||
$document =$this->createsDocument->execute($invoice, $document_object);
|
||||
|
||||
$this->createsFiles->execute($document, $document_object);
|
||||
|
||||
// dump($document);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->response([]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,185 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
||||
use App\Classes\Modules\Documents\Services\CreatesDocument;
|
||||
use App\Classes\Modules\Documents\Services\CreatesFiles;
|
||||
use App\Classes\ValueObjects\Constants\DocumentType;
|
||||
use App\Http\Resources\GroupResource;
|
||||
use App\Models\Document;
|
||||
use App\Models\SegmentConstant;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompany;
|
||||
use App\Classes\Modules\Transactions\Services\CalculatesTransactionServiceCharge;
|
||||
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
|
||||
use App\Classes\Modules\Transactions\Services\FetchesGroup;
|
||||
use App\Classes\Modules\Transactions\Services\UpdatesTransaction;
|
||||
use App\Classes\Modules\Transactions\Services\CalculatesTransactionTransferFee;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Classes\ValueObjects\Constants\SegmentConstants;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use ErrorException;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
|
||||
|
||||
class UpdateGroupLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Update Group Transaction',
|
||||
'message' => 'You have successfully updated this Group Transaction'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var FetchesGroup */
|
||||
private $fetchesGroup;
|
||||
|
||||
/** @var FetchesCompany */
|
||||
private $fetchesCompany;
|
||||
|
||||
/** @var CalculatesTransactionServiceCharge */
|
||||
private $calculatesTransactionServiceCharge;
|
||||
|
||||
/** @var UpdatesTransaction */
|
||||
private $updatesTransaction;
|
||||
|
||||
/** @var CalculatesTransactionTransferFee */
|
||||
private $calculatesTransactionTransferFee;
|
||||
|
||||
/** @var CreatesDocument */
|
||||
private $createsDocument;
|
||||
|
||||
/** @var CreatesFiles */
|
||||
private $createsFile;
|
||||
|
||||
/**
|
||||
* UpdateGroupLogic constructor.
|
||||
* @param FetchesGroup $fetchesGroup
|
||||
* @param FetchesCompany $fetchesCompany
|
||||
* @param CalculatesTransactionServiceCharge $calculatesTransactionServiceCharge
|
||||
* @param UpdatesTransaction $updatesTransaction
|
||||
* @param CalculatesTransactionTransferFee $calculatesTransactionTransferFee
|
||||
* @param CreatesDocument $createsDocument
|
||||
* @param CreatesFiles $createsFile
|
||||
*/
|
||||
public function __construct(FetchesGroup $fetchesGroup, FetchesCompany $fetchesCompany, CalculatesTransactionServiceCharge $calculatesTransactionServiceCharge, UpdatesTransaction $updatesTransaction, CalculatesTransactionTransferFee $calculatesTransactionTransferFee, CreatesDocument $createsDocument, CreatesFiles $createsFile)
|
||||
{
|
||||
$this->fetchesGroup = $fetchesGroup;
|
||||
$this->fetchesCompany = $fetchesCompany;
|
||||
$this->calculatesTransactionServiceCharge = $calculatesTransactionServiceCharge;
|
||||
$this->updatesTransaction = $updatesTransaction;
|
||||
$this->calculatesTransactionTransferFee = $calculatesTransactionTransferFee;
|
||||
$this->createsDocument = $createsDocument;
|
||||
$this->createsFile = $createsFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$group = $this->fetchesGroup->execute(['id' => $request->route('id')]);
|
||||
|
||||
$transactions = $group->transactions()->get();
|
||||
|
||||
$rate = $request->input('rate');
|
||||
|
||||
$supplier = $this->fetchesCompany->execute(['id' => $request->input('supplier_id')]);
|
||||
|
||||
// $group->transactions()->update(['issuer' => $supplier->id, 'currency_rate' => $rate]);
|
||||
// $group->transactions()->update(['amount' => DB::raw('(original_amount * (1 / currency_rate)) + service_charge + tax')]);
|
||||
|
||||
|
||||
foreach($transactions as $transaction) {
|
||||
|
||||
$constant = SegmentConstant::where('reference', SegmentConstants::SERVICE_CHARGE)->where('detail->id', $supplier->id)->first();
|
||||
$serviceCharge = $this->calculatesTransactionServiceCharge->execute($transaction->original_amount, $rate, $constant);
|
||||
|
||||
$object = new TransactionObject(
|
||||
$transaction->bill_no,
|
||||
TransactionType::BILL,
|
||||
$supplier->id,
|
||||
1,
|
||||
$supplier->banks()->where('default', true)->first()->id,
|
||||
PaymentMethodType::CASH,
|
||||
$transaction->original_amount * (1 / $rate),
|
||||
$transaction->original_amount,
|
||||
1,
|
||||
$transaction->original_currency_id,
|
||||
$rate,
|
||||
0,
|
||||
$serviceCharge,
|
||||
null,
|
||||
ApprovalStatus::PENDING_VERIFICATION
|
||||
);
|
||||
|
||||
$billTransaction = $this->updatesTransaction->execute($transaction, $object);
|
||||
|
||||
$transferTransaction = $transaction->transactions()->where('type', TransactionType::TRANSFER_FEE)->first();
|
||||
|
||||
$transferFee = $this->calculatesTransactionTransferFee->execute($billTransaction->original_amount, $constant);
|
||||
|
||||
$object = new TransactionObject(
|
||||
$transferTransaction->bill_no,
|
||||
TransactionType::TRANSFER_FEE,
|
||||
$supplier->id,
|
||||
1,
|
||||
$supplier->banks()->where('default', true)->first()->id,
|
||||
PaymentMethodType::CASH,
|
||||
$transaction->original_amount,
|
||||
$transaction->original_amount,
|
||||
$transaction->original_currency_id,
|
||||
$transaction->original_currency_id,
|
||||
1,
|
||||
0,
|
||||
$transferFee,
|
||||
null,
|
||||
ApprovalStatus::PENDING_VERIFICATION
|
||||
);
|
||||
|
||||
$this->updatesTransaction->execute($transferTransaction, $object);
|
||||
}
|
||||
|
||||
$group->issuer = $supplier->id;
|
||||
$group->amount = $group->transactions()->sum('amount');
|
||||
$group->currency_rate = $rate;
|
||||
$group->tax = $group->transactions()->sum('tax');
|
||||
$group->service_charge = $group->transactions()->sum('service_charge');
|
||||
|
||||
$group->save();
|
||||
|
||||
$group->documents()->delete();
|
||||
|
||||
$transferFeeTransactions = $group->transactions()->with([
|
||||
'transactions' => function ($transaction) {
|
||||
return $transaction->where('type', TransactionType::TRANSFER_FEE);
|
||||
}])->get()->pluck('transactions')->flatten();
|
||||
|
||||
$pdf = LaravelMpdf::loadView('pages.pdfs.currency_vendor_order', ['transactions' => $group->transactions, 'transferFeeTransactions' => $transferFeeTransactions, 'supplier' => $supplier]);
|
||||
|
||||
$object = new DocumentObject(
|
||||
DocumentType::CURRENCY_VENDOR_ORDER,
|
||||
[chunk_split('data:application/pdf;base64,'.base64_encode($pdf->output()))],
|
||||
'',
|
||||
ApprovalStatus::COMPLETED,
|
||||
'currency_vendor_order'
|
||||
);
|
||||
|
||||
/** @var Document $document */
|
||||
$document = $this->createsDocument->execute($group, $object);
|
||||
$this->createsFile->execute($document, $object);
|
||||
|
||||
return $this->resourceResponse(new GroupResource($group));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,175 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Transactions\Processors;
|
||||
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||
use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
|
||||
use App\Classes\Modules\Transactions\Services\CreatesPaymentTransaction;
|
||||
use App\Classes\Modules\Transactions\Services\CreatesTransactionDetail;
|
||||
use App\Classes\Modules\Billplzs\Services\CreatesBillplzBill;
|
||||
use App\Classes\Modules\Transactions\Services\CreatesTransactionableTransaction;
|
||||
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\Modules\Wallets\Services\UpdatesWalletBalance;
|
||||
use App\Models\Transaction;
|
||||
use App\Models\Wallet;
|
||||
use App\Classes\Modules\Orders\Processors\UpdateDoFromVTPortalProcessor;
|
||||
use App\Classes\Modules\Orders\Processors\UpdateDoFromYDPortalProcessor;
|
||||
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CreatePaymentTransactionProcessor
|
||||
{
|
||||
|
||||
/** @var GeneratesTransactionBillNumber */
|
||||
private $generatesTransactionBillNumber;
|
||||
|
||||
/** @var CreatesPaymentTransaction */
|
||||
private $createsPaymentTransaction;
|
||||
|
||||
/** @var CreatesBillplzBill */
|
||||
private $createsBillplzBill;
|
||||
|
||||
/** @var CreatesTransactionableTransaction */
|
||||
private $createsTransactionableTransaction;
|
||||
|
||||
/** @var UpdatesWalletBalance */
|
||||
private $updatesWalletBalance;
|
||||
|
||||
/** @var UpdateDoFromVTPortalProcessor */
|
||||
private $updateDoFromVTPortalProcessor;
|
||||
|
||||
/** @var UpdateDoFromYDPortalProcessor */
|
||||
private $updateDoFromYDPortalProcessor ;
|
||||
|
||||
/** @var UpdatesTransactionStatus */
|
||||
private $updatesTransactionStatus ;
|
||||
|
||||
/**
|
||||
* @param FetchesTransaction $fetchesTransaction,
|
||||
* @param GeneratesTransactionBillNumber $generatesTransactionBillNumber,
|
||||
* @param CreatesPaymentTransaction $createsPaymentTransaction
|
||||
* @param CreatesTransactionDetail $createsTransactionDetail
|
||||
* @param CreatesBillplzBill $createsBillplzBil
|
||||
* @param CreatesTransactionableTransaction $createsTransactionableTransaction
|
||||
* @param UpdatesWalletBalance $updatesWalletBalance
|
||||
* @param UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor
|
||||
* @param UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor
|
||||
* @param UpdatesTransactionStatus $updatesTransactionStatus
|
||||
*/
|
||||
public function __construct(
|
||||
GeneratesTransactionBillNumber $generatesTransactionBillNumber,
|
||||
CreatesPaymentTransaction $createsPaymentTransaction,
|
||||
CreatesBillplzBill $createsBillplzBill,
|
||||
CreatesTransactionableTransaction $createsTransactionableTransaction,
|
||||
UpdatesWalletBalance $updatesWalletBalance,
|
||||
UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor,
|
||||
UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor,
|
||||
UpdatesTransactionStatus $updatesTransactionStatus
|
||||
)
|
||||
{
|
||||
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
|
||||
$this->createsPaymentTransaction = $createsPaymentTransaction;
|
||||
$this->createsBillplzBill = $createsBillplzBill;
|
||||
$this->createsTransactionableTransaction = $createsTransactionableTransaction;
|
||||
$this->updatesWalletBalance = $updatesWalletBalance;
|
||||
$this->updateDoFromVTPortalProcessor = $updateDoFromVTPortalProcessor;
|
||||
$this->updateDoFromYDPortalProcessor = $updateDoFromYDPortalProcessor;
|
||||
$this->updatesTransactionStatus = $updatesTransactionStatus;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function execute(Transaction $invoice, $payment_method, $bank_code)
|
||||
{
|
||||
$amount = $invoice->amount;
|
||||
Log::info($invoice->owner);
|
||||
$company_module = $invoice->owner->owner->companyModule()->first();
|
||||
$approvalStatus = ApprovalStatus::PENDING_SUBMISSION;
|
||||
$billNumber = $this->generatesTransactionBillNumber->execute('PYMT-');
|
||||
$payment_reference = null;
|
||||
|
||||
if ($payment_method == PaymentMethodType::PAYMENT_GATEWAY) {
|
||||
|
||||
// create billplz transaction
|
||||
$payment_method = PaymentMethodType::PAYMENT_GATEWAY;
|
||||
$billPlzBill = $this->createsBillplzBill->execute(
|
||||
$company_module->name,
|
||||
(app()->environment(['production'])) ? $company_module->employees()->first()->email : 'uldvstar@gmail.com',
|
||||
'This payment is for the invoice number . ' . $billNumber,
|
||||
$amount,
|
||||
$billNumber,
|
||||
$bank_code,
|
||||
true
|
||||
);
|
||||
|
||||
$payment_reference = $billPlzBill->id;
|
||||
}
|
||||
else if ($payment_method === PaymentMethodType::WALLET) {
|
||||
/** @var Wallet $wallet */
|
||||
$wallet = $company_module->wallets()->first();
|
||||
|
||||
if((float) number_format(($wallet->amount - $amount),2) < 0){
|
||||
throw new MalformedRequestException('Insufficient wallet balance. Please Top up your wallet.');
|
||||
}
|
||||
|
||||
$walletPaymentBillNumber = $this->generatesTransactionBillNumber->execute('PYMT-');
|
||||
|
||||
$transaction_object = new TransactionObject($walletPaymentBillNumber, TransactionType::PAYMENT, 1, $company_module->id, 1, PaymentMethodType::WALLET, $amount, $amount, 1, 1, 1, 0, 0, null, ApprovalStatus::APPROVED, [], '');
|
||||
$transaction = $this->createsTransactionableTransaction->execute($wallet, $transaction_object);
|
||||
|
||||
$payment_reference = $walletPaymentBillNumber;
|
||||
|
||||
$this->updatesWalletBalance->execute($wallet, ($amount * -1));
|
||||
|
||||
$packingList = $invoice->owner;
|
||||
$order = $packingList->owner;
|
||||
$packingList->status = ApprovalStatus::APPROVED;
|
||||
$packingList->save();
|
||||
|
||||
if(app()->environment('production')){
|
||||
$this->updateDoFromVTPortalProcessor->execute($packingList);
|
||||
$this->updateDoFromYDPortalProcessor->execute($packingList);
|
||||
}
|
||||
|
||||
// later use this variabke to create a approved payment transaction
|
||||
$approvalStatus = ApprovalStatus::APPROVED;
|
||||
|
||||
// update invoice to completed
|
||||
$this->updatesTransactionStatus->execute($invoice, ApprovalStatus::COMPLETED);
|
||||
|
||||
}
|
||||
else {
|
||||
$payment_method = PaymentMethodType::CASH;
|
||||
}
|
||||
|
||||
$object = new TransactionObject(
|
||||
$billNumber,
|
||||
TransactionType::PAYMENT,
|
||||
$company_module->id,
|
||||
1,
|
||||
1,
|
||||
$payment_method,
|
||||
$amount,
|
||||
$amount,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
null,
|
||||
$approvalStatus,
|
||||
null,
|
||||
$payment_reference
|
||||
);
|
||||
|
||||
$payment_transaction = $this->createsPaymentTransaction->execute($invoice, $object);
|
||||
|
||||
return $payment_transaction;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Transactions\Processors;
|
||||
|
||||
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
|
||||
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||
use App\Classes\Modules\Wallets\Services\FetchesWallet;
|
||||
use App\Classes\Modules\Wallets\Services\UpdatesWallet;
|
||||
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
|
||||
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Models\Wallet;
|
||||
|
||||
class UpdateWalletTransactionProcessor
|
||||
{
|
||||
/** @var CreatesWalletTransaction */
|
||||
private $createsWalletTransaction;
|
||||
|
||||
/** @var FetchesTransaction */
|
||||
private $fetchesTransaction;
|
||||
|
||||
/** @var ListWallet */
|
||||
private $fetchesWallet;
|
||||
|
||||
/** @var UpdatesTransactionStatus */
|
||||
private $updatesTransactionStatus;
|
||||
|
||||
/** @var UpdatesWallet */
|
||||
private $updatesWallet;
|
||||
|
||||
public function __construct(FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, UpdatesWallet $updatesWallet)
|
||||
{
|
||||
$this->fetchesTransaction = $fetchesTransaction;
|
||||
$this->updatesTransactionStatus = $updatesTransactionStatus;
|
||||
$this->updatesWallet = $updatesWallet;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Booking $booking
|
||||
* @return void
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(int $transactionId, int $transactionStatus)
|
||||
{
|
||||
|
||||
$transaction = $this->fetchesTransaction->execute(['id' => $transactionId]);
|
||||
$wallet = $transaction->wallet;
|
||||
|
||||
switch($transaction->type){
|
||||
case TransactionType::TOP_UP:
|
||||
$updateWalletAmount = $transaction->amount + $wallet->amount;
|
||||
break;
|
||||
case TransactionType::WITHDRAW:
|
||||
$updateWalletAmount = $wallet->amount - $transaction->amount;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
$walletOject = new WalletObject( $wallet->company->id, $wallet->currency_id, $wallet->code, $updateWalletAmount);
|
||||
|
||||
$this->updatesTransactionStatus->execute($transaction, $transactionStatus);
|
||||
|
||||
$this->updatesWallet->execute($wallet, $walletOject);
|
||||
|
||||
return $wallet;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Transactions\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
|
||||
use App\Classes\General\Interfaces\Transactionable;
|
||||
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
|
||||
use App\Models\Transaction;
|
||||
|
||||
class CreatesTransactionableTransaction extends AbstractUpdateRelationshipRecord
|
||||
{
|
||||
/**
|
||||
* @param Transactionable $transactionable
|
||||
* @param TransactionObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Transactionable $transactionable, TransactionObject $object) {
|
||||
$model = new Transaction();
|
||||
$model->bill_no = $object->getBillNo();
|
||||
$model->type = $object->getTransactionType();
|
||||
$model->issuer = $object->getIssuer();
|
||||
$model->receiver = $object->getReceiver();
|
||||
$model->recipient_bank_account_id = $object->getRecipientBankAccountId();
|
||||
$model->payment_method = $object->getPaymentMethod();
|
||||
$model->amount = $object->getAmount();
|
||||
$model->original_amount = $object->getOriginalAmount();
|
||||
$model->currency_id = $object->getCurrencyId();
|
||||
$model->original_currency_id = $object->getOriginalCurrencyId();
|
||||
$model->currency_rate = $object->getCurrencyRate();
|
||||
$model->tax = $object->getTax();
|
||||
$model->service_charge = $object->getServiceCharge();
|
||||
$model->expires_on = $object->getExpiresOn();
|
||||
$model->status = $object->getStatus();
|
||||
$model->payment_reference = $object->getPaymentReference();
|
||||
|
||||
return $this->handler($transactionable->transactions(), $model);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Transactions\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractDeleteRecord;
|
||||
use App\Models\Group;
|
||||
|
||||
class DeletesGroup extends AbstractDeleteRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Group $model
|
||||
* @return mixed
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Group $model) {
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Transactions\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractFetchRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\Group;
|
||||
|
||||
class FetchesGroup extends AbstractFetchRecord
|
||||
{
|
||||
|
||||
/** @var Transaction */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* FetchesTransaction constructor.
|
||||
* @param Transaction $repository
|
||||
*/
|
||||
public function __construct(Group $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
public function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Transactions\Services;
|
||||
|
||||
use App\Models\Group;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Classes\General\Eloquent\AbstractListRecord;
|
||||
|
||||
class ListsGroups extends AbstractListRecord
|
||||
{
|
||||
/** @var Group */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* ListsBookings constructor.
|
||||
* @param Group $repository
|
||||
*/
|
||||
public function __construct(Group $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
public function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -4,20 +4,20 @@ namespace App\Classes\Modules\Transactions\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Models\Transaction;
|
||||
use App\Classes\Modules\PerfexCRM\Processors\TransactionToPerfexCRMProcessor;
|
||||
use App\Classes\Modules\PerfexCRM\Processors\TransactionToPerfexCRMV2Processor;
|
||||
|
||||
class UpdatesTransactionStatus extends AbstractUpdateRecord
|
||||
{
|
||||
/** @var TransactionToPerfexCRMProcessor */
|
||||
private $transactionToPerfexCRMProcessor;
|
||||
/** @var TransactionToPerfexCRMV2Processor */
|
||||
private $transactionToPerfexCRMV2Processor;
|
||||
|
||||
/**
|
||||
* UpdatesTransactionStatus constructor.
|
||||
* @param TransactionToPerfexCRMProcessor $transactionToPerfexCRMProcessor
|
||||
* @param TransactionToPerfexCRMProcessor $transactionToPerfexCRMV2Processor
|
||||
*/
|
||||
public function __construct(TransactionToPerfexCRMProcessor $transactionToPerfexCRMProcessor)
|
||||
public function __construct(TransactionToPerfexCRMV2Processor $transactionToPerfexCRMV2Processor)
|
||||
{
|
||||
$this->transactionToPerfexCRMProcessor = $transactionToPerfexCRMProcessor;
|
||||
$this->transactionToPerfexCRMV2Processor = $transactionToPerfexCRMV2Processor;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -33,7 +33,7 @@ class UpdatesTransactionStatus extends AbstractUpdateRecord
|
||||
$result = $this->handler($model);
|
||||
|
||||
if(config('perfexcrm.is_enabled') == 'true'){
|
||||
$this->transactionToPerfexCRMProcessor->execute($transaction, $status);
|
||||
$this->transactionToPerfexCRMV2Processor->execute($transaction, $status);
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Wallets\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
|
||||
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
|
||||
use App\Classes\Modules\Wallets\Services\CreatesWallet;
|
||||
use App\Classes\Modules\Wallets\Services\GeneratesWalletCode;
|
||||
use App\Classes\Modules\Wallets\Standards\Rules\CanCreateCompanyWallet;
|
||||
use App\Http\Resources\WalletResource;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompanyModule;
|
||||
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CreateWalletLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Created Company Wallet',
|
||||
'message' => 'You have successfully created a company wallet'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CreatesWallet */
|
||||
private $createsWallet;
|
||||
|
||||
/** @var GeneratesWalletCode */
|
||||
private $generatesWalletCode;
|
||||
|
||||
/** @var CanCreateCompanyWallet */
|
||||
private $canCreateCompanyWallet;
|
||||
|
||||
/** @var FetchesCompanyModule */
|
||||
private $fetchesCompanyModule;
|
||||
|
||||
/**
|
||||
* CreateWalletLogic constructor.
|
||||
* @param CreatesWallet $createsWallet
|
||||
* @param GeneratesWalletCode $generatesWalletCode
|
||||
* @param CanCreateCompanyWallet $canCreateCompanyWallet
|
||||
*/
|
||||
public function __construct(CreatesWallet $createsWallet, GeneratesWalletCode $generatesWalletCode, CanCreateCompanyWallet $canCreateCompanyWallet, FetchesCompanyModule $fetchesCompanyModule)
|
||||
{
|
||||
$this->fetchesCompanyModule = $fetchesCompanyModule;
|
||||
$this->createsWallet = $createsWallet;
|
||||
$this->generatesWalletCode = $generatesWalletCode;
|
||||
$this->canCreateCompanyWallet = $canCreateCompanyWallet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$object = new WalletObject($request->input('company_module_id'), $request->input('currency_id'), $this->generatesWalletCode->execute());
|
||||
|
||||
$this->canCreateCompanyWallet->passes($object);
|
||||
|
||||
$company_module = $this->fetchesCompanyModule->execute(['id' => $request->input('company_id')]);
|
||||
|
||||
$wallet = $this->createsWallet->execute($object, $company_module);
|
||||
|
||||
return $this->resourceResponse(new WalletResource($wallet));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Wallets\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
|
||||
use App\Classes\Modules\Wallets\Standards\Rules\CanCreateWalletTransaction;
|
||||
use App\Classes\Modules\Wallets\DataTransferObjects\WalletTransactionObject;
|
||||
use App\Classes\Modules\Wallets\Services\CreatesWalletTransaction;
|
||||
use App\Classes\Modules\Wallets\Services\GeneratesWalletTransactionBillNo;
|
||||
use App\Http\Resources\WalletTransactionResource;
|
||||
use App\Classes\Modules\Wallets\Services\FetchesWallet;
|
||||
|
||||
use App\Classes\Modules\Currencies\Services\FetchesCurrency;
|
||||
use App\Classes\Modules\Currencies\Services\RateCalculatesCurrency;
|
||||
/*
|
||||
use App\Classes\Modules\Accounts\Standards\Rules\CanCreateUser;
|
||||
use App\Classes\Modules\Accounts\Services\CreatesUser;
|
||||
use App\Classes\Modules\Accounts\DataTransferObjects\UserObject;
|
||||
use App\Http\Resources\UserResource;
|
||||
|
||||
use App\Classes\Modules\Companies\Standards\Rules\CanCreateCompany;
|
||||
use App\Classes\Modules\Companies\Services\CreatesCompany;
|
||||
use App\Classes\Modules\Companies\DataTransferObjects\CompanyObject;
|
||||
|
||||
use App\Classes\Modules\Contacts\Standards\Rules\CanCreateContact;
|
||||
use App\Classes\Modules\Contacts\Services\CreatesContact;
|
||||
use App\Classes\Modules\Contacts\DataTransferObjects\ContactObject;
|
||||
|
||||
use App\Classes\Modules\Companies\Standards\Rules\CanCreateCompanyEmployee;
|
||||
use App\Classes\Modules\Companies\Services\CreatesCompanyEmployee;
|
||||
use App\Classes\Modules\Companies\DataTransferObjects\CompanyEmployeeObject;
|
||||
|
||||
use App\Classes\Modules\SegmentCompanies\Standards\Rules\CanCreateSegmentCompany;
|
||||
use App\Classes\Modules\SegmentCompanies\Services\CreatesSegmentCompany;
|
||||
use App\Classes\Modules\SegmentCompanies\DataTransferObjects\SegmentCompanyObject;
|
||||
*/
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class CreateWalletTransactionLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Created Wallet Transaction',
|
||||
'message' => 'You have successfully created a wallet transaction'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CreatesWalletTransaction */
|
||||
private $createsWalletTransaction;
|
||||
|
||||
/** @var GeneratesWalletTransactionBillNo */
|
||||
private $generatesWalletTransactionBillNo;
|
||||
|
||||
/** @var CanCreateWalletTransaction */
|
||||
private $canCreateWalletTransaction;
|
||||
|
||||
private $fetchesCurrency;
|
||||
|
||||
private $rateCalculatesCurrency;
|
||||
|
||||
private $fetchesWallet;
|
||||
|
||||
/**
|
||||
* CreateWalletLogic constructor.
|
||||
* @param CreatesWalletTransaction $createsWalletTransaction
|
||||
* @param GeneratesWalletTransactionBillNo $generatesWalletTransactionBillNo
|
||||
* @param CanCreateWalletTransaction $canCreateWalletTransaction
|
||||
* @param FetchesCurrency $fetchesCurrency
|
||||
* @param RateCalculatesCurrency $rateCalculatesCurrency
|
||||
* @param FetchesWallet $fetchesWallet
|
||||
*/
|
||||
public function __construct(
|
||||
CreatesWalletTransaction $createsWalletTransaction, GeneratesWalletTransactionBillNo $generatesWalletTransactionBillNo, CanCreateWalletTransaction $canCreateWalletTransaction,
|
||||
FetchesCurrency $fetchesCurrency,RateCalculatesCurrency $rateCalculatesCurrency, FetchesWallet $fetchesWallet
|
||||
)
|
||||
{
|
||||
$this->createsWalletTransaction = $createsWalletTransaction;
|
||||
$this->generatesWalletTransactionBillNo = $generatesWalletTransactionBillNo;
|
||||
$this->canCreateWalletTransaction = $canCreateWalletTransaction;
|
||||
$this->fetchesCurrency = $fetchesCurrency;
|
||||
$this->rateCalculatesCurrency = $rateCalculatesCurrency;
|
||||
$this->fetchesWallet = $fetchesWallet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
try {
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$wallet = $this->fetchesWallet->execute(['id' => $request->route('id')]);
|
||||
$conversion_currency = $this->fetchesCurrency->execute(['id' => $request->input('currency_id')]);
|
||||
$convertable_currency = $this->fetchesCurrency->execute(['id' => $wallet->currency_id]);//MYR
|
||||
|
||||
$convert_amount = $this->rateCalculatesCurrency->execute($conversion_currency, $convertable_currency, $request->input('amount'));
|
||||
$convert_rate = $this->rateCalculatesCurrency->execute_rate($conversion_currency, $convertable_currency);
|
||||
|
||||
|
||||
$object = new WalletTransactionObject(
|
||||
$wallet->id, $this->generatesWalletTransactionBillNo->execute(),$request->input('trans_type'),
|
||||
number_format( (float) $convert_amount, 5, '.', ''), $wallet->currency_id , number_format( (float) $request->input('amount'), 5, '.', ''),
|
||||
$request->input('currency_id'),number_format( (float) $convert_rate, 5, '.', '')
|
||||
);
|
||||
|
||||
$this->canCreateWalletTransaction->passes($object);
|
||||
|
||||
$wallet_transaction = $this->createsWalletTransaction->execute($object);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return $this->resourceResponse(new WalletTransactionResource($wallet_transaction));
|
||||
|
||||
} catch (\Exception $exception) {
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Wallets\ControllersLogic;
|
||||
|
||||
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\UpdatesWallet;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompany;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompanyModule;
|
||||
use App\Classes\Modules\Wallets\Services\GeneratesWalletCode;
|
||||
|
||||
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
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Credit into Company Wallet',
|
||||
'message' => 'You have successfully credit company wallet'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/** @var FetchesCompanyModule */
|
||||
private $fetchesCompanyModule;
|
||||
|
||||
/** @var FetchesCompany */
|
||||
private $fetchesCompany;
|
||||
|
||||
/** @var GeneratesWalletCode */
|
||||
private $generatesWalletCode;
|
||||
|
||||
/** @var CreatesWallet */
|
||||
private $createsWallet;
|
||||
|
||||
/** @var GeneratesTransactionBillNumber */
|
||||
private $generatesTransactionBillNumber;
|
||||
|
||||
/** @var CreatesTransaction */
|
||||
private $createsTransaction;
|
||||
|
||||
/** @var UpdatesWallet */
|
||||
private $updatesWallet;
|
||||
|
||||
/** @var CreditWalletProcessor */
|
||||
private $creditWalletProcessor;
|
||||
|
||||
/**
|
||||
* CreateWalletLogic constructor.
|
||||
* @param FetchesCompany $fetchesCompany
|
||||
* @param GeneratesWalletCode $generatesWalletCode
|
||||
* @param CreatesWallet $createsWallet
|
||||
* @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
|
||||
* @param CreatesTransaction $createsTransaction
|
||||
* @param UpdatesWallet $updatesWallet
|
||||
* @param CreditWalletProcessor $creditWalletProcessor
|
||||
*/
|
||||
public function __construct(
|
||||
FetchesCompany $fetchesCompany,
|
||||
FetchesCompanyModule $fetchesCompanyModule,
|
||||
GeneratesWalletCode $generatesWalletCode,
|
||||
CreatesWallet $createsWallet,
|
||||
GeneratesTransactionBillNumber $generatesTransactionBillNumber,
|
||||
CreatesTransaction $createsTransaction,
|
||||
UpdatesWallet $updatesWallet,
|
||||
CreditWalletProcessor $creditWalletProcessor
|
||||
)
|
||||
{
|
||||
$this->fetchesCompany = $fetchesCompany;
|
||||
$this->fetchesCompanyModule = $fetchesCompanyModule;
|
||||
$this->generatesWalletCode = $generatesWalletCode;
|
||||
$this->createsWallet = $createsWallet;
|
||||
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
|
||||
$this->createsTransaction = $createsTransaction;
|
||||
$this->updatesWallet = $updatesWallet;
|
||||
$this->creditWalletProcessor = $creditWalletProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$amount = floatval(str_replace(',', '', $request->input('amount')));
|
||||
|
||||
$companyModule = $this->fetchesCompanyModule->execute(['id' => $request->input('company_module_id')]);
|
||||
|
||||
$reference = $request->input('reference');
|
||||
|
||||
$type = $request->input('transaction_type');
|
||||
|
||||
$wallet = $this->creditWalletProcessor->execute($companyModule, $type, $amount, $reference);
|
||||
|
||||
return $this->resourceResponse(new WalletResource($wallet));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
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 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 ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class DebitWalletLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Debit into Company Wallet',
|
||||
'message' => 'You have successfully debit company wallet'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/** @var FetchesCompany */
|
||||
private $fetchesCompany;
|
||||
|
||||
/** @var GeneratesTransactionBillNumber */
|
||||
private $generatesTransactionBillNumber;
|
||||
|
||||
/** @var CreatesTransaction */
|
||||
private $createsTransaction;
|
||||
|
||||
/** @var UpdatesWallet */
|
||||
private $updatesWallet;
|
||||
|
||||
/**
|
||||
* CreateWalletLogic constructor.
|
||||
* @param FetchesCompany $fetchesCompany
|
||||
* @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
|
||||
* @param CreatesTransaction $createsTransaction
|
||||
* @param UpdatesWallet $updatesWallet
|
||||
*/
|
||||
public function __construct(
|
||||
FetchesCompany $fetchesCompany,
|
||||
GeneratesTransactionBillNumber $generatesTransactionBillNumber,
|
||||
CreatesTransaction $createsTransaction,
|
||||
UpdatesWallet $updatesWallet
|
||||
)
|
||||
{
|
||||
$this->fetchesCompany = $fetchesCompany;
|
||||
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
|
||||
$this->createsTransaction = $createsTransaction;
|
||||
$this->updatesWallet = $updatesWallet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$amount = floatval(str_replace(',', '', $request->input('amount')));
|
||||
$company = $this->fetchesCompany->execute(['id' => $request->input('company_id')]);
|
||||
$reference = $request->input('reference');
|
||||
|
||||
if (!$company->wallets()->first()) {
|
||||
$object = new WalletObject($company->id, 1, $this->generatesWalletCode->execute());
|
||||
$wallet = $this->createsWallet->execute($object, $company);
|
||||
}
|
||||
|
||||
$wallet = $company->wallets()->first();
|
||||
|
||||
$billNumber = $this->generatesTransactionBillNumber->execute('DEBIT-NOTE-');
|
||||
|
||||
$transaction_object = new TransactionObject(
|
||||
$billNumber,
|
||||
TransactionType::DEBIT_NOTE,
|
||||
1,
|
||||
$wallet->company->id,
|
||||
1,
|
||||
PaymentMethodType::CASH,
|
||||
$amount,
|
||||
$amount,
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
null,
|
||||
ApprovalStatus::APPROVED,
|
||||
[],
|
||||
$reference
|
||||
);
|
||||
|
||||
$transaction = $this->createsTransaction->execute($wallet, $transaction_object);
|
||||
$updateWalletAmount = $wallet->amount - $transaction->amount;
|
||||
|
||||
$walletOject = new WalletObject($wallet->company->id, $wallet->currency_id, $wallet->code, $updateWalletAmount);
|
||||
|
||||
$wallet = $this->updatesWallet->execute($wallet, $walletOject);
|
||||
|
||||
return $this->resourceResponse(new WalletResource($wallet));
|
||||
}
|
||||
}
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Wallets\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
|
||||
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
|
||||
use App\Classes\Modules\Wallets\Services\CreatesWallet;
|
||||
use App\Classes\Modules\Wallets\Services\GeneratesWalletCode;
|
||||
use App\Classes\Modules\Wallets\Standards\Rules\CanCreateCompanyWallet;
|
||||
use App\Http\Resources\WalletResource;
|
||||
use App\Classes\Modules\Wallets\Services\FetchesWallet;
|
||||
use App\Models\Wallet;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompanyModule;
|
||||
|
||||
class FetchWalletByCompanyModuleControllerLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Wallet',
|
||||
'message' => 'You have successfully retrieved a wallet'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var FetchesWallet */
|
||||
private $fetchesWallet;
|
||||
|
||||
/** @var CreatesWallet */
|
||||
private $createsWallet;
|
||||
|
||||
/** @var GeneratesWalletCode */
|
||||
private $generatesWalletCode;
|
||||
|
||||
/** @var CanCreateCompanyWallet */
|
||||
private $canCreateCompanyWallet;
|
||||
|
||||
/** @var FetchesCompanyModule */
|
||||
private $fetchesCompanyModule;
|
||||
|
||||
|
||||
/**
|
||||
* CreateWalletLogic constructor.
|
||||
* @param FetchesWallet $fetchesWallet
|
||||
*/
|
||||
public function __construct(FetchesWallet $fetchesWallet, CreatesWallet $createsWallet, GeneratesWalletCode $generatesWalletCode, CanCreateCompanyWallet $canCreateCompanyWallet, FetchesCompanyModule $fetchesCompanyModule)
|
||||
{
|
||||
$this->fetchesWallet = $fetchesWallet;
|
||||
$this->fetchesCompanyModule = $fetchesCompanyModule;
|
||||
$this->createsWallet = $createsWallet;
|
||||
$this->generatesWalletCode = $generatesWalletCode;
|
||||
$this->canCreateCompanyWallet = $canCreateCompanyWallet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
// $this->canFetchWallet->passes();
|
||||
|
||||
if (!count(Wallet::where('owner_id', $request->route('company_module_id'))->get())) {
|
||||
$object = new WalletObject($request->route('company_module_id'), $request->input('currency_id') ?? 1, $this->generatesWalletCode->execute());
|
||||
|
||||
$this->canCreateCompanyWallet->passes($object);
|
||||
|
||||
$company_module = $this->fetchesCompanyModule->execute(['id' => $request->route('company_module_id')]);
|
||||
|
||||
$wallet = $this->createsWallet->execute($object, $company_module);
|
||||
|
||||
return $this->resourceResponse(new WalletResource($wallet));
|
||||
}
|
||||
|
||||
$filters = $this->fetchesWallet->deserializeFilters($request->input('filters'));
|
||||
|
||||
$filters['owner_id'] = $request->route('company_module_id');
|
||||
|
||||
$query = $this->fetchesWallet->execute($filters);
|
||||
|
||||
return $this->resourceResponse(new WalletResource($query));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Wallets\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
|
||||
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
|
||||
use App\Classes\Modules\Wallets\Services\ListsWallet;
|
||||
use App\Classes\Modules\Wallets\Standards\Rules\CanListWallet;
|
||||
use App\Http\Resources\WalletResource;
|
||||
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class ListWalletLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'List Company Wallet',
|
||||
'message' => 'You have successfully list company wallet'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var ListWallet */
|
||||
private $listsWallet;
|
||||
|
||||
/** @var CanCreateCompanyWallet */
|
||||
private $canListWallet;
|
||||
|
||||
/**
|
||||
* CreateWalletLogic constructor.
|
||||
* @param CreatesWallet $createsWallet
|
||||
* @param GeneratesWalletCode $generatesWalletCode
|
||||
* @param CanCreateCompanyWallet $canCreateCompanyWallet
|
||||
*/
|
||||
public function __construct(CanListWallet $canListWallet, ListsWallet $listsWallet)
|
||||
{
|
||||
$this->canListWallet = $canListWallet;
|
||||
$this->listsWallet = $listsWallet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
//$this->canListWallet->passes();
|
||||
|
||||
$query = $this->listsWallet->execute($this->listsWallet->deserializeFilters($request->input('filters')));
|
||||
|
||||
return $this->collectionResponse(WalletResource::collection($query));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Wallets\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompanyModule;
|
||||
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\Billplzs\Services\CreatesBillplzBill;
|
||||
use App\Classes\Modules\Transactions\Services\CreatesTransactionableTransaction;
|
||||
use App\Classes\Modules\Wallets\Processors\CreateWalletTopUpTransactionProcessor;
|
||||
use App\Http\Resources\WalletTransactionResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class TopUpWalletLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'TopUp into Company Wallet',
|
||||
'message' => 'You have successfully created a topup request for company\'s wallet'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/** @var FetchesCompanyModule */
|
||||
private $fetchesCompanyModule;
|
||||
|
||||
/** @var GeneratesWalletCode */
|
||||
private $generatesWalletCode;
|
||||
|
||||
/** @var CreatesWallet */
|
||||
private $createsWallet;
|
||||
|
||||
/** @var GeneratesTransactionBillNumber */
|
||||
private $generatesTransactionBillNumber;
|
||||
|
||||
/** @var CreatesBillplzBill */
|
||||
private $createsBillplzBill;
|
||||
|
||||
/** @var CreatesTransactionableTransaction */
|
||||
private $createsTransactionableTransaction;
|
||||
|
||||
/** @var CreateWalletTopUpTransactionProcessor */
|
||||
private $createWalletTopUpTransactionProcessor;
|
||||
|
||||
|
||||
/**
|
||||
* TopUpWalletLogic constructor.
|
||||
* @param FetchesCompanyModule $fetchesCompanyModule
|
||||
* @param GeneratesWalletCode $generatesWalletCode
|
||||
* @param CreatesWallet $createsWallet
|
||||
* @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
|
||||
* @param CreatesBillplzBill $createsBillplzBill
|
||||
* @param CreatesTransaction $createsTransaction
|
||||
* @param CreateWalletTopUpTransactionProcessor $createWalletTopUpTransactionProcessor
|
||||
*/
|
||||
public function __construct(FetchesCompanyModule $fetchesCompanyModule, GeneratesWalletCode $generatesWalletCode, CreatesWallet $createsWallet, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatesBillplzBill $createsBillplzBill, CreatesTransactionableTransaction $createsTransactionableTransaction, CreateWalletTopUpTransactionProcessor $createWalletTopUpTransactionProcessor)
|
||||
{
|
||||
$this->fetchesCompanyModule = $fetchesCompanyModule;
|
||||
$this->generatesWalletCode = $generatesWalletCode;
|
||||
$this->createsWallet = $createsWallet;
|
||||
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
|
||||
$this->createsBillplzBill = $createsBillplzBill;
|
||||
$this->createsTransactionableTransaction = $createsTransactionableTransaction;
|
||||
$this->createWalletTopUpTransactionProcessor = $createWalletTopUpTransactionProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$amount = floatval(str_replace(',', '', $request->input('amount')));
|
||||
$companyModule = $this->fetchesCompanyModule->execute(['id' => $request->input('company_module_id')]);
|
||||
|
||||
$transaction = $this->createWalletTopUpTransactionProcessor->execute($companyModule, $amount, $request->input('bank_code'));
|
||||
|
||||
return $this->resourceResponse(new WalletTransactionResource($transaction));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Wallets\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
|
||||
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
|
||||
use App\Classes\Modules\Wallets\Services\ListsWallet;
|
||||
use App\Classes\Modules\Wallets\Services\FetchesWallet;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
|
||||
use App\Classes\Modules\Wallets\Standards\Rules\CanListWallet;
|
||||
use App\Http\Resources\WalletResource;
|
||||
use App\Classes\Modules\Transactions\Processors\UpdateWalletTransactionProcessor;
|
||||
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class UpdateStatusWalletLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Update Status Transaction Company Wallet',
|
||||
'message' => 'You have successfully status transaction company wallet'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var ListWallet */
|
||||
private $fetchesWallet;
|
||||
|
||||
/** @var CanCreateCompanyWallet */
|
||||
private $canListWallet;
|
||||
|
||||
/** @var UpdateWalletTransactionProcessor */
|
||||
private $updateWalletTransactionProcessor;
|
||||
|
||||
/**
|
||||
* CreateWalletLogic constructor.
|
||||
* @param CreatesWallet $createsWallet
|
||||
* @param GeneratesWalletCode $generatesWalletCode
|
||||
* @param CanCreateCompanyWallet $canCreateCompanyWallet
|
||||
*/
|
||||
public function __construct(FetchesWallet $fetchesWallet, UpdateWalletTransactionProcessor $updateWalletTransactionProcessor)
|
||||
{
|
||||
$this->fetchesWallet = $fetchesWallet;
|
||||
$this->updateWalletTransactionProcessor = $updateWalletTransactionProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$status = ($request->route('status')=='approve') ? 2 : 4;
|
||||
|
||||
$wallet = $this->updateWalletTransactionProcessor->execute($request->route('transaction_id'), $status);
|
||||
|
||||
return $this->resourceResponse(new WalletResource($wallet));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Wallets\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
|
||||
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
|
||||
use App\Classes\Modules\Wallets\Services\ListsWallet;
|
||||
use App\Classes\Modules\Wallets\Services\FetchesWallet;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
|
||||
use App\Classes\Modules\Wallets\Standards\Rules\CanWithdrawWallet;
|
||||
use App\Http\Resources\WalletResource;
|
||||
use App\Classes\Modules\Transactions\Processors\CreateWalletTransactionProcessor;
|
||||
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class WithdrawWalletLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Withdraw from Company Wallet',
|
||||
'message' => 'You have successfully withdraw company wallet'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var FetchesWallet */
|
||||
private $fetchesWallet;
|
||||
|
||||
/** @var CanWithdrawWallet */
|
||||
private $canWithdrawWallet;
|
||||
|
||||
/** @var CreateWalletTransactionProcessor */
|
||||
private $createWalletTransactionProcessor;
|
||||
|
||||
/**
|
||||
* CreateWalletLogic constructor.
|
||||
* @param CreatesWallet $createsWallet
|
||||
* @param GeneratesWalletCode $generatesWalletCode
|
||||
* @param CanCreateCompanyWallet $canCreateCompanyWallet
|
||||
*/
|
||||
public function __construct(CanWithdrawWallet $canWithdrawWallet, FetchesWallet $fetchesWallet, CreateWalletTransactionProcessor $createWalletTransactionProcessor)
|
||||
{
|
||||
$this->canWithdrawWallet = $canWithdrawWallet;
|
||||
$this->fetchesWallet = $fetchesWallet;
|
||||
$this->createWalletTransactionProcessor = $createWalletTransactionProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$wallet = $this->fetchesWallet->execute(['id' => $request->input('wallet_id')]);
|
||||
|
||||
$walletOject = new WalletObject( $wallet->company->id, $wallet->currency_id, $wallet->code, $request->input('amount'));
|
||||
|
||||
$this->canWithdrawWallet->passes($walletOject);
|
||||
|
||||
$transaction = $this->createWalletTransactionProcessor->execute($wallet, $walletOject, TransactionType::WITHDRAW);
|
||||
|
||||
return $this->resourceResponse(new WalletResource($wallet));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Wallets\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class WalletObject implements DataTransferObject
|
||||
{
|
||||
|
||||
/** @var int */
|
||||
private $company_module_id;
|
||||
|
||||
/** @var int */
|
||||
private $currency_id;
|
||||
|
||||
/** @var int */
|
||||
private $code;
|
||||
|
||||
private $amount;
|
||||
|
||||
/**
|
||||
* WalletObject constructor.
|
||||
* @param int $company_module_id
|
||||
* @param int $currency
|
||||
* @param int $code
|
||||
*/
|
||||
public function __construct(int $company_module_id, int $currency, int $code, float $amount=0)
|
||||
{
|
||||
$this->company_module_id = $company_module_id;
|
||||
$this->currency_id = $currency;
|
||||
$this->code = $code;
|
||||
$this->amount = $amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCompanyModuleId(): int
|
||||
{
|
||||
return $this->company_module_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCurrency(): int
|
||||
{
|
||||
return $this->currency_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCode(): int
|
||||
{
|
||||
return $this->code;
|
||||
}
|
||||
|
||||
public function getAmount(): float
|
||||
{
|
||||
return $this->amount;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Wallets\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class WalletTransactionObject implements DataTransferObject
|
||||
{
|
||||
|
||||
private $wallet_id;
|
||||
|
||||
private $bill_no;
|
||||
|
||||
private $trans_type;
|
||||
|
||||
private $amount;
|
||||
|
||||
private $currency_id;
|
||||
|
||||
private $original_amount;
|
||||
|
||||
private $original_currency_id;
|
||||
|
||||
private $currency_rate;
|
||||
|
||||
public function __construct(
|
||||
int $wallet_id, int $bill_no,int $trans_type,
|
||||
float $amount, int $currency_id, int $original_amount,
|
||||
int $original_currency_id, float $currency_rate
|
||||
){
|
||||
$this->wallet_id = $wallet_id;
|
||||
$this->bill_no = $bill_no;
|
||||
$this->trans_type = $trans_type;
|
||||
$this->amount= $amount;
|
||||
$this->currency_id = $currency_id;
|
||||
$this->original_amount = $original_amount;
|
||||
$this->original_currency_id = $original_currency_id;
|
||||
$this->currency_rate = $currency_rate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getWalletId(): int
|
||||
{
|
||||
return $this->wallet_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getBillNo(): int
|
||||
{
|
||||
return $this->bill_no;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getTransType(): int
|
||||
{
|
||||
return $this->trans_type;
|
||||
}
|
||||
|
||||
|
||||
public function getAmount(): float
|
||||
{
|
||||
return $this->amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getCurrency(): int
|
||||
{
|
||||
return $this->currency_id;
|
||||
}
|
||||
|
||||
|
||||
public function getOriginalAmount(): float
|
||||
{
|
||||
return $this->original_amount;
|
||||
}
|
||||
|
||||
public function getOriginalCurrency(): int
|
||||
{
|
||||
return $this->original_currency_id;
|
||||
}
|
||||
|
||||
public function getCurrencyRate(): float
|
||||
{
|
||||
return $this->currency_rate;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Wallets\Processors;
|
||||
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
|
||||
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompanyModule;
|
||||
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\Billplzs\Services\CreatesBillplzBill;
|
||||
use App\Classes\Modules\Transactions\Services\CreatesTransactionableTransaction;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Models\CompanyModule;
|
||||
use App\Models\Wallet;
|
||||
use PhpOffice\PhpSpreadsheet\Calculation\Logical\Boolean;
|
||||
|
||||
class CreateWalletTopUpTransactionProcessor
|
||||
{
|
||||
/** @var GeneratesWalletCode */
|
||||
private $generatesWalletCode;
|
||||
|
||||
/** @var CreatesWallet */
|
||||
private $createsWallet;
|
||||
|
||||
/** @var GeneratesTransactionBillNumber */
|
||||
private $generatesTransactionBillNumber;
|
||||
|
||||
/** @var CreatesBillplzBill */
|
||||
private $createsBillplzBill;
|
||||
|
||||
/** @var CreatesTransactionableTransaction */
|
||||
private $createsTransactionableTransaction;
|
||||
|
||||
/**
|
||||
* @param GeneratesWalletCode $generatesWalletCode
|
||||
* @param CreatesWallet $createsWallet
|
||||
* @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
|
||||
* @param CreatesBillplzBill $createsBillplzBill
|
||||
* @param CreatesTransaction $createsTransaction
|
||||
*/
|
||||
public function __construct(
|
||||
GeneratesWalletCode $generatesWalletCode,
|
||||
CreatesWallet $createsWallet,
|
||||
GeneratesTransactionBillNumber $generatesTransactionBillNumber,
|
||||
CreatesBillplzBill $createsBillplzBill,
|
||||
CreatesTransactionableTransaction $createsTransactionableTransaction
|
||||
)
|
||||
{
|
||||
$this->generatesWalletCode = $generatesWalletCode;
|
||||
$this->createsWallet = $createsWallet;
|
||||
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
|
||||
$this->createsBillplzBill = $createsBillplzBill;
|
||||
$this->createsTransactionableTransaction = $createsTransactionableTransaction;
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function execute(CompanyModule $companyModule, $amount, $bank_code, ?bool $groupTransaction = false)
|
||||
{
|
||||
/** @var Wallet $wallet */
|
||||
$wallet = $companyModule->wallets()->first();
|
||||
|
||||
if (!$wallet) {
|
||||
$object = new WalletObject($companyModule->id, 1, $this->generatesWalletCode->execute());
|
||||
/** @var Wallet $wallet */
|
||||
$wallet = $this->createsWallet->execute($object, $companyModule);
|
||||
}
|
||||
|
||||
$user = $companyModule->employees()->first();
|
||||
$billNumber = $this->generatesTransactionBillNumber->execute('TOPUP-');
|
||||
|
||||
if($amount < 0) {
|
||||
throw new MalformedRequestException('Top up credit value must be greater than zero.');
|
||||
}
|
||||
|
||||
$billPlzBill = $this->createsBillplzBill->execute($companyModule->name, $user->email, 'This payment is credit topup for company ref. ' . $companyModule->reference, $amount, $billNumber, $bank_code, true);
|
||||
|
||||
// IF $groupTransaction, transaction type is GROUP_PAYMENT
|
||||
$transaction_object = new TransactionObject($billNumber, $groupTransaction? TransactionType::GROUP_PAYMENT: TransactionType::TOP_UP, 1, $companyModule->id, 1, PaymentMethodType::PAYMENT_GATEWAY, $amount, $amount, 1, 1, 1, 0, 0, null, ApprovalStatus::PENDING_SUBMISSION, [], $billPlzBill->id);
|
||||
|
||||
$transaction = $this->createsTransactionableTransaction->execute($wallet, $transaction_object);
|
||||
|
||||
return $transaction;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Wallets\Processors;
|
||||
|
||||
use App\Models\Wallet;
|
||||
use App\Models\Company;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\Modules\Wallets\Services\CreatesWallet;
|
||||
use App\Classes\Modules\Wallets\Services\UpdatesWallet;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Classes\Modules\Wallets\Services\GeneratesWalletCode;
|
||||
use App\Classes\Modules\Transactions\Services\CreatesTransaction;
|
||||
use App\Classes\Modules\Transactions\Services\CreatesTransactionableTransaction;
|
||||
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
|
||||
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
|
||||
use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
|
||||
use App\Models\CompanyModule;
|
||||
|
||||
class CreditWalletProcessor
|
||||
{
|
||||
/** @var GeneratesWalletCode */
|
||||
private $generatesWalletCode;
|
||||
|
||||
/** @var CreatesWallet */
|
||||
private $createsWallet;
|
||||
|
||||
/** @var GeneratesTransactionBillNumber */
|
||||
private $generatesTransactionBillNumber;
|
||||
|
||||
/** @var CreatesTransaction */
|
||||
private $createsTransaction;
|
||||
|
||||
/** @var CreatesTransactionableTransaction */
|
||||
private $createsTransactionableTransaction;
|
||||
|
||||
/** @var UpdatesWallet */
|
||||
private $updatesWallet;
|
||||
|
||||
/**
|
||||
* CreateWalletLogic constructor.
|
||||
* @param GeneratesWalletCode $generatesWalletCode
|
||||
* @param CreatesWallet $createsWallet
|
||||
* @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
|
||||
* @param CreatesTransaction $createsTransaction
|
||||
* @param CreatesTransactionableTransaction $createsTransactionableTransaction
|
||||
* @param UpdatesWallet $updatesWallet
|
||||
*/
|
||||
public function __construct(
|
||||
GeneratesWalletCode $generatesWalletCode,
|
||||
CreatesWallet $createsWallet,
|
||||
GeneratesTransactionBillNumber $generatesTransactionBillNumber,
|
||||
CreatesTransaction $createsTransaction,
|
||||
CreatesTransactionableTransaction $createsTransactionableTransaction,
|
||||
UpdatesWallet $updatesWallet
|
||||
)
|
||||
{
|
||||
$this->generatesWalletCode = $generatesWalletCode;
|
||||
$this->createsWallet = $createsWallet;
|
||||
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
|
||||
$this->createsTransaction = $createsTransaction;
|
||||
$this->createsTransactionableTransaction = $createsTransactionableTransaction;
|
||||
$this->updatesWallet = $updatesWallet;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param CompanyModule $companyModule
|
||||
* @param int $transactionType
|
||||
* @param float $amount
|
||||
* @param string $reference
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(CompanyModule $companyModule, int $transactionType, float $amount, string $reference)
|
||||
{
|
||||
if (!$companyModule->wallets()->first()) {
|
||||
$object = new WalletObject($companyModule->id, 1, $this->generatesWalletCode->execute());
|
||||
$this->createsWallet->execute($object, $companyModule);
|
||||
}
|
||||
|
||||
/** @var Wallet $wallet */
|
||||
$wallet = $companyModule->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->createsTransactionableTransaction->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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Wallets\Services;
|
||||
|
||||
|
||||
use App\Models\Wallet;
|
||||
|
||||
class ChecksIfWalletCodeExists
|
||||
{
|
||||
|
||||
/** @var wallet */
|
||||
private $repository;
|
||||
|
||||
|
||||
/**
|
||||
* ChecksIfWalletCodeExists constructor.
|
||||
* @param Wallet $repository
|
||||
*/
|
||||
public function __construct(wallet $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
public function execute(int $code): bool {
|
||||
return $this->repository->where('code', $code)->exists();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Wallets\Services;
|
||||
|
||||
|
||||
use App\Models\WalletTransaction;
|
||||
|
||||
class ChecksIfWalletTransactionBillNoExists
|
||||
{
|
||||
|
||||
private $repository;
|
||||
|
||||
public function __construct(WalletTransaction $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
public function execute(int $bill_no): bool {
|
||||
return $this->repository->where('bill_no', $bill_no)->exists();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Wallets\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
|
||||
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
|
||||
use App\Models\Wallet;
|
||||
use App\Models\Company;
|
||||
use App\Models\CompanyModule;
|
||||
|
||||
class CreatesWallet extends AbstractUpdateRelationshipRecord
|
||||
{
|
||||
/**
|
||||
* @param WalletObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(WalletObject $object, CompanyModule $companyModule) {
|
||||
$model = new Wallet();
|
||||
// $model->company_module_id = $object->getCompanyModuleId();
|
||||
$model->code = $object->getCode();
|
||||
$model->currency_id = $object->getCurrency();
|
||||
|
||||
return $this->handler($companyModule->wallets(), $model);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Wallets\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Wallets\DataTransferObjects\WalletTransactionObject;
|
||||
use App\Models\WalletTransaction;
|
||||
|
||||
class CreatesWalletTransaction extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param WalletTransactionObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(WalletTransactionObject $object) {
|
||||
$model = new WalletTransaction();
|
||||
$model->wallet_id = $object->getWalletId();
|
||||
$model->bill_no = $object->getBillNo();
|
||||
$model->trans_type = $object->getTransType();
|
||||
$model->amount = $object->getAmount();
|
||||
$model->currency_id = $object->getCurrency();
|
||||
$model->original_amount = $object->getOriginalAmount();
|
||||
$model->original_currency_id = $object->getOriginalCurrency();
|
||||
$model->currency_rate = $object->getCurrencyRate();
|
||||
|
||||
return $this->handler($model);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Wallets\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractFetchRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\Wallet;
|
||||
|
||||
class FetchesWallet extends AbstractFetchRecord
|
||||
{
|
||||
|
||||
/** @var Wallet */
|
||||
private $repository;
|
||||
|
||||
|
||||
/**
|
||||
* FetchesWallet constructor.
|
||||
* @param Wallet $repository
|
||||
*/
|
||||
public function __construct(Wallet $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
public function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Wallets\Services;
|
||||
|
||||
|
||||
class GeneratesWalletCode
|
||||
{
|
||||
|
||||
/** @var ChecksIfWalletCodeExists */
|
||||
private $walletCodeExists;
|
||||
|
||||
/**
|
||||
* GeneratesWalletCode constructor.
|
||||
* @param ChecksIfWalletCodeExists $walletCodeExists
|
||||
*/
|
||||
public function __construct(ChecksIfWalletCodeExists $walletCodeExists)
|
||||
{
|
||||
$this->walletCodeExists = $walletCodeExists;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function execute(): int {
|
||||
|
||||
$code = mt_rand(100000001, 999999999);
|
||||
return !$this->walletCodeExists->execute($code) ? $code : self::execute();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Wallets\Services;
|
||||
|
||||
|
||||
class GeneratesWalletTransactionBillNo
|
||||
{
|
||||
|
||||
|
||||
private $walletTransationBillNoExists;
|
||||
|
||||
|
||||
public function __construct(ChecksIfWalletTransactionBillNoExists $walletTransationBillNoExists)
|
||||
{
|
||||
$this->walletTransationBillNoExists = $walletTransationBillNoExists;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public function execute(): int {
|
||||
|
||||
$code = mt_rand(100000001, 999999999);
|
||||
return !$this->walletTransationBillNoExists->execute($code) ? $code : self::execute();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Wallets\Services;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Classes\General\Eloquent\AbstractListRecord;
|
||||
use App\Models\Wallet;
|
||||
|
||||
class ListsWallet extends AbstractListRecord
|
||||
{
|
||||
/** @var Booking */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* ListsBookings constructor.
|
||||
* @param Booking $repository
|
||||
*/
|
||||
public function __construct(Wallet $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
public function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Wallets\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
|
||||
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
|
||||
use App\Models\Wallet;
|
||||
use App\Models\Company;
|
||||
|
||||
class UpdatesWallet extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param WalletObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Wallet $model, WalletObject $object) {
|
||||
$model->amount = $object->getAmount();
|
||||
$model->code = $object->getCode();
|
||||
$model->currency_id = $object->getCurrency();
|
||||
|
||||
|
||||
return $this->handler($model);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Wallets\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRelationshipRecord;
|
||||
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
|
||||
use App\Models\Wallet;
|
||||
use App\Models\Company;
|
||||
|
||||
class UpdatesWalletBalance extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param Wallet $model
|
||||
* @param $amount
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(Wallet $model, $amount) {
|
||||
|
||||
$model->amount = $model->amount + $amount;
|
||||
return $this->handler($model);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Wallets\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
|
||||
use App\Classes\Modules\Wallets\Standards\Validators\CompanyWalletValidation;
|
||||
|
||||
class CanCreateCompanyWallet extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var CompanyWalletValidation */
|
||||
private $companyWalletValidation;
|
||||
|
||||
/**
|
||||
* CanCreateCompanyWallet constructor.
|
||||
* @param CompanyWalletValidation $companyWalletValidation
|
||||
*/
|
||||
public function __construct(CompanyWalletValidation $companyWalletValidation)
|
||||
{
|
||||
$this->companyWalletValidation = $companyWalletValidation;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WalletObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->companyWalletValidation->validate($object);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param WalletObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Wallets\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Wallets\DataTransferObjects\WalletTransactionObject;
|
||||
use App\Classes\Modules\Wallets\Standards\Validators\WalletTransactionValidation;
|
||||
|
||||
class CanCreateWalletTransaction extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var WalletTransactionValidation */
|
||||
private $walletTransactionValidation;
|
||||
|
||||
|
||||
public function __construct(WalletTransactionValidation $walletTransactionValidation)
|
||||
{
|
||||
$this->walletTransactionValidation = $walletTransactionValidation;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WalletTransactionObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->walletTransactionValidation->validate($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WalletTransactionObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Wallets\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
|
||||
use App\Classes\Modules\Wallets\Standards\Validators\ListWalletValidation;
|
||||
|
||||
class CanListWallet extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var ListWalletValidation */
|
||||
private $listWalletValidation;
|
||||
|
||||
|
||||
public function __construct(ListWalletValidation $listWalletValidation)
|
||||
{
|
||||
$this->listWalletValidation = $listWalletValidation;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WalletObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->listWalletValidation->validate($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WalletTransactionObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Wallets\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
|
||||
use App\Classes\Modules\Wallets\Standards\Validators\TopUpWalletValidation;
|
||||
|
||||
class CanTopUpWallet extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var TopUpWalletValidation */
|
||||
private $topUpWalletValidation;
|
||||
|
||||
|
||||
public function __construct(TopUpWalletValidation $topUpWalletValidation)
|
||||
{
|
||||
$this->topUpWalletValidation = $topUpWalletValidation;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WalletObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->topUpWalletValidation->validate($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WalletTransactionObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Wallets\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
|
||||
use App\Classes\Modules\Wallets\Standards\Validators\WithdrawWalletValidation;
|
||||
|
||||
class CanWithdrawWallet extends AbstractRule
|
||||
{
|
||||
|
||||
/** @var WithdrawWalletValidation */
|
||||
private $witdrawWalletValidation;
|
||||
|
||||
|
||||
public function __construct(WithdrawWalletValidation $witdrawWalletValidation)
|
||||
{
|
||||
$this->witdrawWalletValidation = $witdrawWalletValidation;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WalletObject $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return $this->witdrawWalletValidation->validate($object);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param WalletTransactionObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user