mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 12:34:18 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d90644e8d6 |
@@ -59,7 +59,3 @@ YD_API_CODE=''
|
||||
PERFEXCRM_BASE_URL=""
|
||||
PERFEXCRM_API_KEY=""
|
||||
PERFEXCRM_IS_ENABLED="false"
|
||||
|
||||
|
||||
STORAGE_FEE_LAUNCH_DATE="2023-12-11 00:00:00"
|
||||
SST_START_DATE="2024-04-01 00:00:00"
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Exceptions;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\HttpStatus;
|
||||
|
||||
final class JobResourceNotFoundException extends ServiceApiException {
|
||||
public function __construct(?string $message = null) {
|
||||
parent::__construct($message ?? 'Unable to find the requested resource', HttpStatus::RESOURCE_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
@@ -15,8 +15,6 @@ use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Classes\Exceptions\JobResourceNotFoundException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
abstract class AbstractControllerLogic
|
||||
{
|
||||
@@ -64,19 +62,6 @@ abstract class AbstractControllerLogic
|
||||
return $response;
|
||||
|
||||
} catch (ErrorException|GeneralExceptions|TypeError $exception){
|
||||
if ($exception instanceof JobResourceNotFoundException) {
|
||||
Log::channel('vue_polling')->info(sprintf(
|
||||
"Uncaught exception '%s' with message '%s' in %s:%d",
|
||||
get_class($exception),
|
||||
$exception->getMessage(),
|
||||
$exception->getTrace()[0]['file'],
|
||||
$exception->getTrace()[0]['line']
|
||||
));
|
||||
}
|
||||
else{
|
||||
Log::error($exception);
|
||||
}
|
||||
|
||||
return (new ApiResponseObject($this->getNotificationTitle().' failed', $exception->getMessage(),
|
||||
!in_array($exception->getCode(), [0, 42000]) ? $exception->getCode() : HttpStatus::SERVER_ERROR))->handler();
|
||||
|
||||
|
||||
@@ -6,8 +6,6 @@ namespace App\Classes\General\Eloquent;
|
||||
use App\Classes\Exceptions\ResourceNotFoundException;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Classes\Exceptions\JobResourceNotFoundException;
|
||||
|
||||
|
||||
abstract class AbstractFetchRecord extends AbstractGetRecord
|
||||
{
|
||||
@@ -28,18 +26,12 @@ abstract class AbstractFetchRecord extends AbstractGetRecord
|
||||
* @return Model
|
||||
* @throws ResourceNotFoundException
|
||||
*/
|
||||
public function getResults(Builder $query, array $param = []): Model {
|
||||
public function getResults(Builder $query): Model {
|
||||
if(!$query->exists()){
|
||||
$table = $query->getModel()->getTable();
|
||||
if($table ==='job_results'){
|
||||
throw new JobResourceNotFoundException('Unable to find any job based on the criteria provided');
|
||||
}
|
||||
else{
|
||||
throw new ResourceNotFoundException('Unable to find any record based on the criteria provided');
|
||||
}
|
||||
throw new ResourceNotFoundException('Unable to find any record based on the criteria provided');
|
||||
}
|
||||
|
||||
return $query->first();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -50,9 +50,9 @@ abstract class AbstractGetRecord
|
||||
* @param array $filters
|
||||
* @return mixed
|
||||
*/
|
||||
public function handler(array $filters, array $params = []){
|
||||
public function handler(array $filters){
|
||||
$this->filters = collect($filters);
|
||||
return $this->getResults($this->applyFiltersToQuery(), $params);
|
||||
return $this->getResults($this->applyFiltersToQuery());
|
||||
}
|
||||
|
||||
|
||||
@@ -65,6 +65,6 @@ abstract class AbstractGetRecord
|
||||
* @param Builder $query
|
||||
* @return mixed
|
||||
*/
|
||||
abstract function getResults(Builder $query, array $params = []);
|
||||
abstract function getResults(Builder $query);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -16,10 +16,11 @@ abstract class AbstractListRecord extends AbstractGetRecord
|
||||
* @return mixed
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function execute(array $filters = [], array $param = []){
|
||||
public function execute(array $filters = []){
|
||||
|
||||
try{
|
||||
return $this->handler($filters, $param);
|
||||
|
||||
return $this->handler($filters);
|
||||
|
||||
} catch (QueryException $exception){
|
||||
throw new MalformedRequestException('Unable to fetch the list of records due to unexpected error');
|
||||
@@ -31,7 +32,7 @@ abstract class AbstractListRecord extends AbstractGetRecord
|
||||
* @param Builder $query
|
||||
* @return mixed
|
||||
*/
|
||||
public function getResults(Builder $query, array $param = []) {
|
||||
public function getResults(Builder $query) {
|
||||
$filters = $this->getDecorationFilters();
|
||||
|
||||
if($filters->has('order_by')){
|
||||
@@ -43,12 +44,8 @@ abstract class AbstractListRecord extends AbstractGetRecord
|
||||
}
|
||||
|
||||
//dd($query->toSql());
|
||||
if(!empty($param)){
|
||||
return $filters->has('per_page') ? $query->paginate($filters->get('per_page'), ['*'], 'page', $param['page']) : $query->get(); //page data from query parameters e.g ?page=1
|
||||
}
|
||||
else{
|
||||
return $filters->has('per_page') ? $query->paginate($filters->get('per_page')) : $query->get();
|
||||
}
|
||||
return $filters->has('per_page') ? $query->paginate($filters->get('per_page')) : $query->get();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class CompanySegmentsIn implements Filter
|
||||
{
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->whereHas('companyModules', function ($module) use ($value) {
|
||||
$module->whereHas('connections', function ($connection) use ($value) {
|
||||
$connection->whereHas('connectionSegments', function ($segment) use ($value) {
|
||||
$segment->whereIn('segment_id', $value);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class CreatedAfterOrEqual implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
$table = $builder->getModel()->getTable();
|
||||
$startDate = Carbon::createFromFormat('d-m-Y', $value)->startOfDay();
|
||||
return $builder->where("{$table}.created_at", '>=', $startDate);
|
||||
}
|
||||
}
|
||||
@@ -1,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class CreatedBeforeOrEqual implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
$table = $builder->getModel()->getTable();
|
||||
$endDate = Carbon::createFromFormat('d-m-Y', $value)->endOfDay();
|
||||
return $builder->where("{$table}.created_at", '<=', $endDate);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class JobId implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('job_id', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class OrderByIdDesc implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->orderBy('id', 'desc');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class OrderByUpdatedAtDesc implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->orderBy('updated_at', 'desc');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,8 +14,7 @@ class OwnerId implements Filter
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
$table = $builder->getModel()->getTable();
|
||||
return $builder->where("{$table}.owner_id", $value);
|
||||
return $builder->where('owner_id', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class OwnerType implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
$table = $builder->getModel()->getTable();
|
||||
return $builder->where("{$table}.owner_type", $value);
|
||||
}
|
||||
|
||||
}
|
||||
-32
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\SegmentConstants;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Models\PackingList;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class PackingListLimitOneByTypeOrderedByInvoiceDate implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->select('packing_lists.*')->join('transactions', function($join){
|
||||
$join->on('transactions.owner_id', '=', 'packing_lists.id');
|
||||
$join->where('transactions.owner_type', '=', PackingList::class);
|
||||
$join->where('transactions.status', '=', ApprovalStatus::APPROVED);
|
||||
$join->whereRaw('(transactions.type <> 16 OR transactions.id = (
|
||||
SELECT id FROM transactions WHERE owner_id = packing_lists.id AND type = 16 LIMIT 1
|
||||
))');
|
||||
})->orderBy('transactions.updated_at', 'DESC');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class PostcodeLike implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('postcode', 'LIKE', '%'.$value.'%');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class RequestSignature implements Filter
|
||||
{
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('request_signature', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ResultNotNull implements Filter
|
||||
{
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->whereNotNull('result');
|
||||
}
|
||||
}
|
||||
@@ -14,8 +14,7 @@ class StatusIn implements Filter
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
$table = $builder->getModel()->getTable();
|
||||
return $builder->whereIn("{$table}.status", $value);
|
||||
return $builder->whereIn('status', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class WithAgingColumn implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
$today = Carbon::now();
|
||||
return $builder->select('packing_lists.*')
|
||||
->addSelect(DB::raw("DATEDIFF('$today', transactions.updated_at) as days_over_duedate"))
|
||||
->addSelect(DB::raw("CASE
|
||||
WHEN DATEDIFF('$today', transactions.updated_at) <= 0 THEN 0
|
||||
WHEN DATEDIFF('$today', transactions.updated_at) > 0 AND DATEDIFF('$today', transactions.updated_at) <= 30 THEN 1
|
||||
WHEN DATEDIFF('$today', transactions.updated_at) > 30 AND DATEDIFF('$today', transactions.updated_at) <= 60 THEN 2
|
||||
WHEN DATEDIFF('$today', transactions.updated_at) > 60 AND DATEDIFF('$today', transactions.updated_at) <= 90 THEN 3
|
||||
ELSE 4
|
||||
END AS due_date_number"));
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class WithContainersPackages implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
// Log::info('WithContainersPackages: '.$value);
|
||||
// return $builder->with(['containers', 'packages']);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class WithOrderReferenceLike implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->join('transactions as t2', 't2.payment_reference', '=', 'transactions.bill_no')
|
||||
->join('transactions as t3', 't3.id', '=', 't2.owner_id')
|
||||
->join('packing_lists', 'packing_lists.id', '=', 't3.owner_id')
|
||||
->join('orders', function ($join) use ($value) {
|
||||
$join->on('orders.id', '=', 'packing_lists.owner_id')
|
||||
->where('orders.reference', 'LIKE', '%'.$value.'%');
|
||||
})
|
||||
->addSelect(['transactions.*', 't2.id as paymentTransactionId', 't3.id as invoiceTransactionId', 'packing_lists.id as packingListId', 'orders.reference as orderReference']);
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class WithTrashed implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->withTrashed();
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace App\Classes\General;
|
||||
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
@@ -41,12 +40,4 @@ class Helper
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ResourceCollection $collection
|
||||
* @return array
|
||||
*/
|
||||
static function collectionResponse(ResourceCollection $collection){
|
||||
return json_decode($collection->response()->getContent(), true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,6 @@ use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class FetchOrdersFromYDPortalJob implements ShouldQueue
|
||||
{
|
||||
@@ -30,17 +29,12 @@ class FetchOrdersFromYDPortalJob implements ShouldQueue
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
Log::info('FetchOrdersFromYDPortalJob starts');
|
||||
Log::info('FetchPackingListsFromYdPortalProcessor starts');
|
||||
(App()->make(FetchPackingListsFromYdPortalProcessor::class))->execute();
|
||||
Log::info('FetchContainersFromYdPortalProcessor starts');
|
||||
(App()->make(FetchContainersFromYdPortalProcessor::class))->execute();
|
||||
Log::info('FetchContainersUpdatesFromYdPortalProcessor starts');
|
||||
(App()->make(FetchContainersUpdatesFromYdPortalProcessor::class))->execute();
|
||||
Log::info('FetchDeliveryUpdatesFromYdPortalProcessor starts');
|
||||
(App()->make(FetchDeliveryUpdatesFromYdPortalProcessor::class))->execute();
|
||||
Log::info('FetchOrdersFromYDPortalJob ends');
|
||||
// (App()->make(FetchOrderListsFromYdPortalProcessor::class))->execute();
|
||||
|
||||
// (App()->make(FetchOrderListsFromYdPortalProcessor::class))->execute();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Jobs;
|
||||
|
||||
use App\Classes\Modules\PackingLists\Processors\ListPackingListsJobProcessor;
|
||||
use App\Classes\Modules\Jobs\DataTransferObjects\ListGenericJobObject;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
|
||||
class ListPackingListsJob implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $timeout = 900;
|
||||
|
||||
/** @var ListGenericJobObject */
|
||||
private $listGenericJobObject;
|
||||
|
||||
/**
|
||||
* ListPackingListsJob constructor.
|
||||
* @param ListGenericJobObject $listGenericJobObject
|
||||
*/
|
||||
public function __construct(ListGenericJobObject $listGenericJobObject)
|
||||
{
|
||||
$this->listGenericJobObject = $listGenericJobObject;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$rawPayload = $this->job->payload();
|
||||
if(isset($rawPayload['data']['commandName'])){
|
||||
$this->listGenericJobObject->setJobCommandName($rawPayload['data']['commandName']);
|
||||
}
|
||||
|
||||
if(isset($rawPayload['data']['command'])){
|
||||
$this->listGenericJobObject->setJobCommand($rawPayload['data']['command']);
|
||||
}
|
||||
|
||||
$result = (App()->make(ListPackingListsJobProcessor::class))->execute($this->listGenericJobObject);
|
||||
}
|
||||
}
|
||||
@@ -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::channel('perfex_crm')->info('UpdatePerfexCRMInvoice debug bill_no: ' . $transaction->owner->bill_no . ', Project Id: ' . $this->updatePerfexCRMInvoiceObject->getProjectId());
|
||||
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'));
|
||||
Log::channel('perfex_crm')->info('UpdatePerfexCRMInvoice CreatePerfexCRMInvoiceProcessor failed');
|
||||
Helper::debugLogger('UpdatePerfexCRMInvoice CreatePerfexCRMInvoiceProcessor failed');
|
||||
}
|
||||
}
|
||||
else{
|
||||
|
||||
@@ -36,8 +36,6 @@ use App\Models\User;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CreateCustomerLogic extends AbstractControllerLogic
|
||||
{
|
||||
@@ -169,19 +167,6 @@ class CreateCustomerLogic extends AbstractControllerLogic
|
||||
CreatePerfexCRMCustomer::dispatch($createLeadPerfexCRMObject);
|
||||
}
|
||||
|
||||
if(app()->environment(['production'])){
|
||||
// call wac webhook
|
||||
$url = config('wagWebhookUrl.account_registration_url');
|
||||
$payload = [
|
||||
'name' => $request->input('name'),
|
||||
'email' => $request->input('email'),
|
||||
'phone' => $request->input('phone'),
|
||||
'portal' => 'izyim'
|
||||
];
|
||||
$response = Http::post($url, $payload);
|
||||
Log::channel('wac_webhook')->info('Register Account: ' . json_encode($response));
|
||||
}
|
||||
|
||||
// $this->generateEmailVerificationAttemptProcessor->execute($user);
|
||||
|
||||
return $this->response($this->authenticationProcessor->execute($request));
|
||||
|
||||
@@ -14,17 +14,14 @@ 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\Modules\Billplzs\Processors\CallbackBillplzProcessor;
|
||||
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||
use App\Classes\Modules\Transactions\Processors\CreatePaymentTransactionProcessor;
|
||||
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
|
||||
use App\Classes\Modules\Transactions\Processors\CheckStorageInvoiceTransactionProcessor;
|
||||
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
|
||||
{
|
||||
@@ -49,12 +46,6 @@ class CallbackBillplzLogic
|
||||
/** @var CreatePaymentTransactionProcessor */
|
||||
private $createPaymentTransactionProcessor;
|
||||
|
||||
/** @var CallbackBillplzProcessor */
|
||||
private $callbackBillplzProcessor;
|
||||
|
||||
/** @var CheckStorageInvoiceTransactionProcessor */
|
||||
private $storageInvoiceTransactionProcessor;
|
||||
|
||||
/**
|
||||
* CallbackBillplzLogic constructor.
|
||||
* @param GetBillplzBill $getBillplzBill
|
||||
@@ -63,10 +54,8 @@ class CallbackBillplzLogic
|
||||
* @param UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor
|
||||
* @param UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor
|
||||
* @param CreatePaymentTransactionProcessor $createPaymentTransactionProcessor
|
||||
* @param CallbackBillplzProcessor $callbackBillplzProcessor
|
||||
* @param CheckStorageInvoiceTransactionProcessor $storageInvoiceTransactionProcessor
|
||||
*/
|
||||
public function __construct(GetBillplzBill $getBillplzBill, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor, UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor, UpdatesWalletBalance $updatesWalletBalance, CreatePaymentTransactionProcessor $createPaymentTransactionProcessor, CallbackBillplzProcessor $callbackBillplzProcessor, CheckStorageInvoiceTransactionProcessor $storageInvoiceTransactionProcessor)
|
||||
public function __construct(GetBillplzBill $getBillplzBill, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor, UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor, UpdatesWalletBalance $updatesWalletBalance, CreatePaymentTransactionProcessor $createPaymentTransactionProcessor)
|
||||
{
|
||||
$this->getBillplzBill = $getBillplzBill;
|
||||
$this->fetchesTransaction = $fetchesTransaction;
|
||||
@@ -75,8 +64,6 @@ class CallbackBillplzLogic
|
||||
$this->updateDoFromYDPortalProcessor = $updateDoFromYDPortalProcessor;
|
||||
$this->updatesWalletBalance = $updatesWalletBalance;
|
||||
$this->createPaymentTransactionProcessor = $createPaymentTransactionProcessor;
|
||||
$this->callbackBillplzProcessor = $callbackBillplzProcessor;
|
||||
$this->storageInvoiceTransactionProcessor = $storageInvoiceTransactionProcessor;
|
||||
}
|
||||
|
||||
|
||||
@@ -116,13 +103,44 @@ class CallbackBillplzLogic
|
||||
$status = $billplzXSignatureObject->getStatus() === 'failed' ? ApprovalStatus::REJECTED : ApprovalStatus::PENDING_VERIFICATION;
|
||||
}
|
||||
|
||||
Log::info('Debug billPlz status: '.$status);
|
||||
|
||||
$token = Auth::fromUser(User::find(1));
|
||||
$request->headers->set('Authorization', 'Bearer '.$token);
|
||||
|
||||
$this->storageInvoiceBackDoorPreventionCheck($transaction, $status);
|
||||
$result = $this->callbackBillplzProcessor->execute($transaction, $status);
|
||||
// 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);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$company_module_marking = $transaction->owner->owner->connections? $transaction->owner->owner->connections->first()->invitee_reference: null;
|
||||
|
||||
@@ -133,22 +151,6 @@ class CallbackBillplzLogic
|
||||
$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 ?? null, 'company_module_marking' => $company_module_marking ?? null, 'transaction' => $transaction, 'status' => $status, 'result' => $result]);
|
||||
}
|
||||
|
||||
private function storageInvoiceBackDoorPreventionCheck($transaction, $status){
|
||||
if ($transaction->owner instanceof Wallet && $status === ApprovalStatus::APPROVED) {
|
||||
$group = Group::where('reference', $transaction->payment_reference)->first();
|
||||
if ($group) {
|
||||
foreach ($group->groupTransactions as $groupTransaction) {
|
||||
$invoice = $groupTransaction->transaction;
|
||||
$pL = $invoice->owner;
|
||||
$order = $pL->owner;
|
||||
if($order){
|
||||
$this->storageInvoiceTransactionProcessor->executeOrder($order);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $request->method() === 'POST' ? true : view('pages.payments_redirect', ['marking' => $order->reference ?? null, 'company_module_marking' => $company_module_marking ?? null, 'transaction' => $transaction, 'status' => $status]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,131 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Billplzs\Processors;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Wallet;
|
||||
use App\Models\Group;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Classes\Modules\Transactions\Processors\CreatePaymentTransactionProcessor;
|
||||
use App\Classes\Modules\Transactions\Processors\ReleaseGoodsToCustomerProcessor;
|
||||
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
|
||||
use App\Classes\Modules\Wallets\Services\UpdatesWalletBalance;
|
||||
use App\Classes\Modules\Orders\Processors\UpdateDoFromVTPortalProcessor;
|
||||
use App\Classes\Modules\Orders\Processors\UpdateDoFromYDPortalProcessor;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class CallbackBillplzProcessor
|
||||
{
|
||||
/** @var UpdatesTransactionStatus */
|
||||
private $updatesTransactionStatus;
|
||||
|
||||
/** @var UpdateDoFromVTPortalProcessor */
|
||||
private $updateDoFromVTPortalProcessor;
|
||||
|
||||
/** @var UpdateDoFromYDPortalProcessor */
|
||||
private $updateDoFromYDPortalProcessor;
|
||||
|
||||
/** @var UpdatesWalletBalance */
|
||||
private $updatesWalletBalance;
|
||||
|
||||
/** @var CreatePaymentTransactionProcessor */
|
||||
private $createPaymentTransactionProcessor;
|
||||
|
||||
/** @var ReleaseGoodsToCustomerProcessor */
|
||||
private $releaseGoodsToCustomerProcessor;
|
||||
|
||||
/**
|
||||
* CreateUserProcessor constructor.
|
||||
* @param UpdatesTransactionStatus $updatesTransactionStatus
|
||||
* @param UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor
|
||||
* @param UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor
|
||||
* @param UpdatesWalletBalance $updatesWalletBalance
|
||||
* @param CreatePaymentTransactionProcessor $createPaymentTransactionProcessor
|
||||
* @param ReleaseGoodsToCustomerProcessor $releaseGoodsToCustomerProcessor
|
||||
*/
|
||||
public function __construct(UpdatesTransactionStatus $updatesTransactionStatus, UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor, UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor, UpdatesWalletBalance $updatesWalletBalance, CreatePaymentTransactionProcessor $createPaymentTransactionProcessor, ReleaseGoodsToCustomerProcessor $releaseGoodsToCustomerProcessor)
|
||||
{
|
||||
$this->updatesTransactionStatus = $updatesTransactionStatus;
|
||||
$this->updateDoFromVTPortalProcessor = $updateDoFromVTPortalProcessor;
|
||||
$this->updateDoFromYDPortalProcessor = $updateDoFromYDPortalProcessor;
|
||||
$this->updatesWalletBalance = $updatesWalletBalance;
|
||||
$this->createPaymentTransactionProcessor = $createPaymentTransactionProcessor;
|
||||
$this->releaseGoodsToCustomerProcessor = $releaseGoodsToCustomerProcessor;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute($transaction, $status)
|
||||
{
|
||||
$invoice = $transaction->owner;
|
||||
$packingList = $invoice->owner;
|
||||
|
||||
$proceed = $this->checkForGroupPayment($transaction);
|
||||
if(!$proceed) return false;
|
||||
|
||||
$this->updatesTransactionStatus->execute($transaction, $status);
|
||||
|
||||
// check if is wallet top up
|
||||
if ($transaction->owner instanceof Wallet && $status === ApprovalStatus::APPROVED) {
|
||||
|
||||
$this->updatesWalletBalance->execute($transaction->owner, $transaction->amount);
|
||||
|
||||
$group = Group::where('reference', $transaction->payment_reference)->first();
|
||||
|
||||
// check if is group payment
|
||||
if ($group) {
|
||||
foreach ($group->groupTransactions as $groupTransaction) {
|
||||
$invoice = $groupTransaction->transaction;
|
||||
if($invoice->status !== ApprovalStatus::COMPLETED){
|
||||
$paymentTransaction = $this->createPaymentTransactionProcessor->execute($invoice, PaymentMethodType::WALLET, null, false);
|
||||
|
||||
if($paymentTransaction && $paymentTransaction->status == ApprovalStatus::APPROVED){
|
||||
$pL = $invoice->owner;
|
||||
$this->releaseGoodsToCustomerProcessor->execute($pL, $invoice);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$group->status = $status;
|
||||
$group->save();
|
||||
}
|
||||
}
|
||||
|
||||
if (!$transaction->owner instanceof Wallet) {
|
||||
$this->releaseGoodsToCustomerProcessor->execute($packingList, $invoice);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function checkForGroupPayment($transaction){
|
||||
//This check is targetting group payment that expired and soft deleted
|
||||
//command:check-storage-invoices must already run for this part of the code to work properly
|
||||
$group = Group::withTrashed()->where('reference', $transaction->payment_reference)->first();
|
||||
if ($group) {
|
||||
$totalAmountToBePaid = 0;
|
||||
$actualAmountPaid = $transaction->amount;
|
||||
|
||||
foreach ($group->groupTransactions as $groupTransaction) {
|
||||
$invoice = $groupTransaction->transaction;
|
||||
if($invoice->status !== ApprovalStatus::COMPLETED){
|
||||
$totalAmountToBePaid += $invoice->amount;
|
||||
}
|
||||
}
|
||||
|
||||
if(($totalAmountToBePaid - $actualAmountPaid) < 0.01){
|
||||
|
||||
}
|
||||
else{
|
||||
Log::channel('storage_invoices')->info('Total amount from current transaction: '.$totalAmountToBePaid); //cief todo: to be removed
|
||||
Log::channel('storage_invoices')->info('Total amount from paid transaction: '.$transaction->amount); //cief todo: to be removed
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Billplzs\Services;
|
||||
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Classes\Exceptions\MalformedRequestException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class DeletesBillplzBill
|
||||
{
|
||||
|
||||
/**
|
||||
* @param string $billID
|
||||
* @throws MalformedRequestException
|
||||
*/
|
||||
public function execute(string $billID) {
|
||||
try{
|
||||
$response = Http::withBasicAuth(config('billplz.api_key').':', '')->delete(config('billplz.base_url').'/api/v3/bills/'.$billID);
|
||||
Log::channel('storage_invoices')->info('DeletesBillplzBill response: '.json_encode($response));
|
||||
|
||||
if($response->successful()){
|
||||
$data = $response->json();
|
||||
|
||||
// $data['url'] = $data['url'].'?auto_submit=true';
|
||||
|
||||
return (object) $data;
|
||||
}else{
|
||||
return null;
|
||||
}
|
||||
}catch(\Exception $exception){
|
||||
throw new MalformedRequestException('Unable to get correct response from billplz server: ' . $exception->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-13
@@ -7,8 +7,6 @@ use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Companies\Processors\AssignConnectionSegmentProcessor;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompany;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompanyConnection;
|
||||
use App\Classes\Modules\Contacts\DataTransferObjects\ContactObject;
|
||||
use App\Classes\Modules\Contacts\Processors\CreateContactProcessor;
|
||||
use App\Http\Resources\CompanyResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -35,22 +33,17 @@ class AssignCompanyConnectionToConnectionSegmentLogic extends AbstractController
|
||||
/** @var AssignConnectionSegmentProcessor */
|
||||
private $assignCompanyConnectionToConnectionSegmentProcessor;
|
||||
|
||||
/** @var CreateContactProcessor */
|
||||
private $createContactProcessor;
|
||||
|
||||
/**
|
||||
* AssignCompanyToSegmentLogic constructor.
|
||||
* @param FetchesCompany $fetchesCompany
|
||||
* @param FetchesCompanyConnection $fetchesCompanyConnection
|
||||
* @param AssignConnectionSegmentProcessor $assignCompanyConnectionToConnectionSegmentProcessor
|
||||
* @param CreateContactProcessor $createContactProcessor
|
||||
*/
|
||||
public function __construct(FetchesCompany $fetchesCompany, FetchesCompanyConnection $fetchesCompanyConnection, AssignConnectionSegmentProcessor $assignCompanyConnectionToConnectionSegmentProcessor, CreateContactProcessor $createContactProcessor)
|
||||
public function __construct(FetchesCompany $fetchesCompany, FetchesCompanyConnection $fetchesCompanyConnection, AssignConnectionSegmentProcessor $assignCompanyConnectionToConnectionSegmentProcessor)
|
||||
{
|
||||
$this->fetchesCompany = $fetchesCompany;
|
||||
$this->fetchesCompanyConnection = $fetchesCompanyConnection;
|
||||
$this->assignCompanyConnectionToConnectionSegmentProcessor = $assignCompanyConnectionToConnectionSegmentProcessor;
|
||||
$this->createContactProcessor = $createContactProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -69,11 +62,6 @@ class AssignCompanyConnectionToConnectionSegmentLogic extends AbstractController
|
||||
|
||||
$this->assignCompanyConnectionToConnectionSegmentProcessor->execute($companyConnection, $request->input('segment_id'));
|
||||
|
||||
if ($request->input('segment_id') == 10 || $request->input('segment_id') == 11) {
|
||||
$contactObject = new ContactObject('Whatsapp: ' . $request->input('name'), $request->input('phone'), null, null);
|
||||
$this->createContactProcessor->execute($contactObject, $company);
|
||||
}
|
||||
|
||||
return $this->resourceResponse(new CompanyResource($company));
|
||||
}
|
||||
}
|
||||
-121
@@ -1,121 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Companies\Services\FetchesCompany;
|
||||
use App\Classes\Modules\Companies\Services\UpdatesCompanyModuleIsCreditTerm;
|
||||
use App\Classes\Modules\Companies\Standards\Rules\CanUpdateCompanyModule;
|
||||
use App\Classes\Modules\Transactions\Services\ListsTransactions;
|
||||
use App\Classes\Modules\Transactions\Services\UpdatesTransactionIsWaived;
|
||||
use App\Classes\Modules\Transactions\Processors\CheckStorageInvoiceTransactionProcessor;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Models\Order;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class UpdateCompanyCreditTermStatusLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Update Company Credit Term Status',
|
||||
'message' => 'You have successfully updated Company Credit Term Status'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var FetchesCompany */
|
||||
private $fetchesCompany;
|
||||
|
||||
/** @var UpdatesCompanyModuleIsCreditTerm */
|
||||
private $updatesCompanyModuleIsCreditTerm;
|
||||
|
||||
/** @var CanUpdateCompanyModule */
|
||||
private $canUpdateCompanyModule;
|
||||
|
||||
/** @var ListsTransactions */
|
||||
private $listsTransactions;
|
||||
|
||||
/** @var UpdatesTransactionIsWaived */
|
||||
private $updatesTransactionIsWaived;
|
||||
|
||||
/** @var CheckStorageInvoiceTransactionProcessor */
|
||||
private $storageInvoiceTransactionProcessor;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* UpdateCompanyCreditTermStatusLogic constructor.
|
||||
* @param FetchesCompany $fetchesCompany
|
||||
* @param UpdatesCompanyModuleIsCreditTerm $updatesCompanyModuleIsCreditTerm
|
||||
* @param CanUpdateCompanyModule $canUpdateCompanyModule
|
||||
* @param UpdatesTransactionIsWaived $updatesTransactionIsWaived
|
||||
* @param ListsTransactions $listsTransactions
|
||||
* @param CheckStorageInvoiceTransactionProcessor $storageInvoiceTransactionProcessor
|
||||
*/
|
||||
public function __construct(FetchesCompany $fetchesCompany, UpdatesCompanyModuleIsCreditTerm $updatesCompanyModuleIsCreditTerm, CanUpdateCompanyModule $canUpdateCompanyModule, UpdatesTransactionIsWaived $updatesTransactionIsWaived, ListsTransactions $listsTransactions, CheckStorageInvoiceTransactionProcessor $storageInvoiceTransactionProcessor)
|
||||
{
|
||||
$this->fetchesCompany = $fetchesCompany;
|
||||
$this->updatesCompanyModuleIsCreditTerm = $updatesCompanyModuleIsCreditTerm;
|
||||
$this->canUpdateCompanyModule = $canUpdateCompanyModule;
|
||||
$this->listsTransactions = $listsTransactions;
|
||||
$this->updatesTransactionIsWaived = $updatesTransactionIsWaived;
|
||||
$this->storageInvoiceTransactionProcessor = $storageInvoiceTransactionProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
{
|
||||
$this->canUpdateCompanyModule->passes();
|
||||
|
||||
$company = $this->fetchesCompany->execute(['id' => $request->route('id')]);
|
||||
$companyModule = $company->companyModules()->first();
|
||||
$isCreditTerm = $companyModule->connections()->first()->is_credit_term;
|
||||
|
||||
if ($isCreditTerm == 1) {
|
||||
$isCreditTerm = 0;
|
||||
} else {
|
||||
$isCreditTerm = 1;
|
||||
}
|
||||
|
||||
if($isCreditTerm === 1){
|
||||
//{"per_page":10,"order_by":{"column":"id","DESC":true},"status_in":[2],"receiver":190,"type_in":[1],"does_not_have_payment_status_in":[0,1],"does_not_have_groups":1,"check_for_storage_invoice":1}
|
||||
|
||||
$filters = [
|
||||
'status_in' => [2],
|
||||
'receiver' => $companyModule->id,
|
||||
'type_in' => [TransactionType::STORAGE_INVOICE]
|
||||
];
|
||||
|
||||
$transactions = $this->listsTransactions->execute($filters);
|
||||
foreach($transactions as $transaction){
|
||||
$this->updatesTransactionIsWaived->execute($transaction);
|
||||
$packingList = $transaction->owner()->first();
|
||||
if($packingList){
|
||||
$order = $packingList->owner()->first();
|
||||
if($order instanceof Order){
|
||||
$storages = $this->storageInvoiceTransactionProcessor->executeOrder($order);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->updatesCompanyModuleIsCreditTerm->execute($company->companyModules()->first()->connections()->first(), $isCreditTerm);
|
||||
Log::info(Auth::user()->email." updated credit term status for customer with id: " .$request->route('id'). " to status " . $isCreditTerm);
|
||||
|
||||
$result = ['is_credit_term' => $isCreditTerm];
|
||||
return $this->response(['data' => $result]);
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Models\CompanyConnection;
|
||||
|
||||
class UpdatesCompanyModuleIsCreditTerm extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param CompanyConnection $model
|
||||
* @param int $isCreditTerm
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(CompanyConnection $model, int $isCreditTerm)
|
||||
{
|
||||
$model->is_credit_term = $isCreditTerm;
|
||||
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Companies\Standards\Rules;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\Modules\Companies\DataTransferObjects\CompanyObject;
|
||||
use App\Classes\ValueObjects\Constants\RoleTypes;
|
||||
|
||||
class CanUpdateCompanyModule extends AbstractRule
|
||||
{
|
||||
|
||||
/**
|
||||
* CanUpdateCompanyModule constructor.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
$user = Auth()->user();
|
||||
if($user){
|
||||
$roleToCheck = Auth()->user()->type;
|
||||
if (in_array($roleToCheck, RoleTypes::ADMIN_ROLES)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $object
|
||||
* @return bool
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param CompanyObject $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,98 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Exports\Services;
|
||||
|
||||
use App\Models\Order;
|
||||
use App\Models\PackingList;
|
||||
use Maatwebsite\Excel\Concerns\FromQuery;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
use App\Classes\General\Eloquent\ApplyFiltersToQuery;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use DateTime;
|
||||
|
||||
class ExportsAgingList implements WithHeadings, WithHeadingRow, WithMapping, ShouldAutoSize, FromQuery
|
||||
{
|
||||
use Exportable;
|
||||
|
||||
private $filters;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->filters = [
|
||||
"has_invoice_status_in" => [2],
|
||||
"packing_list_ordered_by_invoice_date" => true,
|
||||
"with_aging_column" => true
|
||||
];
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'Company Name',
|
||||
'Customer Marking',
|
||||
'Order Number',
|
||||
'Invoice No',
|
||||
'Invoice Date',
|
||||
'Days',
|
||||
'Amount',
|
||||
];
|
||||
}
|
||||
|
||||
public function query()
|
||||
{
|
||||
return (new ApplyFiltersToQuery())->execute(PackingList::query(), $this->filters);
|
||||
}
|
||||
|
||||
public function map($list): array
|
||||
{
|
||||
$marking = null;
|
||||
$orderNo = null;
|
||||
$name = null;
|
||||
$invDate = 'n/a';
|
||||
$invNo = 'n/a';
|
||||
$days = 'n/a';
|
||||
|
||||
if ($list->owner instanceof Order) {
|
||||
$inviterPivotInviteeReference = $list->owner->companyModule->inviters()->withPivot('invitee_reference')->first();
|
||||
|
||||
if ($inviterPivotInviteeReference) {
|
||||
$marking = $inviterPivotInviteeReference->pivot->invitee_reference;
|
||||
$orderNo = $list->owner->reference;
|
||||
}
|
||||
$name = $list->owner->companyModule->company->name;
|
||||
}
|
||||
|
||||
$transaction = $list->transactions()->whereIn('status', [ApprovalStatus::APPROVED])->first();
|
||||
if ($transaction) {
|
||||
|
||||
$invoiceDate = $transaction->created_at;
|
||||
$invDate = date_format($invoiceDate, 'd-m-Y');
|
||||
$invNo = $transaction->bill_no;
|
||||
$amt = number_format($transaction->amount, 2);
|
||||
|
||||
$currentDate = new DateTime();
|
||||
$interval = $currentDate->diff($invoiceDate);
|
||||
$days = $interval->format('%a');
|
||||
}
|
||||
|
||||
return [
|
||||
$name,
|
||||
$marking,
|
||||
$orderNo,
|
||||
$invNo,
|
||||
$invDate,
|
||||
$days,
|
||||
$amt,
|
||||
];
|
||||
}
|
||||
|
||||
private function dueDateColumn($colNum, $dueDateNumber, $amt)
|
||||
{
|
||||
if ($colNum == $dueDateNumber) return $amt;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,124 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Exports\Services;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Models\Transaction;
|
||||
use App\Models\Company;
|
||||
use App\Models\Wallet;
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\FromQuery;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
|
||||
class ExportsCustomersWalletTransactionHistory implements FromQuery, WithHeadings, WithHeadingRow, WithMapping, ShouldAutoSize
|
||||
{
|
||||
use Exportable;
|
||||
|
||||
private $request;
|
||||
private $runningBalance = 0;
|
||||
|
||||
public function __construct(Request $request)
|
||||
{
|
||||
$this->request = $request;
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'Date',
|
||||
'Description',
|
||||
'Incoming',
|
||||
'Outgoing',
|
||||
'Balance',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection|mixed
|
||||
*/
|
||||
public function query()
|
||||
{
|
||||
$wallet = Wallet::find($this->request->route('wallet_id'));
|
||||
$transactions = $wallet->transactions()->whereIn('transactions.status', [2, 3])->orderBy('id');
|
||||
|
||||
return $transactions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Transaction $transaction
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function map($transaction): array
|
||||
{
|
||||
$decimals = $this->request->route('is_precise') == 'true' ? 5 : 2;
|
||||
|
||||
$description = '';
|
||||
switch ((int) $transaction->type) {
|
||||
case TransactionType::TOP_UP:
|
||||
$description = (float) $transaction->amount . ' Credit Top up';
|
||||
break;
|
||||
case TransactionType::GROUP_PAYMENT:
|
||||
$description = (float) $transaction->amount . ' Credit Top up';
|
||||
break;
|
||||
case TransactionType::CREDIT_NOTE:
|
||||
$description = 'Credit Voucher for ' . $transaction->payment_reference;
|
||||
break;
|
||||
case TransactionType::PAYMENT:
|
||||
$payment = Transaction::where('payment_reference', $transaction->bill_no)->first();
|
||||
if (!$payment) {
|
||||
$description = 'Payment not found, please contact tech support.';
|
||||
break;
|
||||
}
|
||||
|
||||
$invoice = $payment->owner;
|
||||
if (!$invoice) {
|
||||
$description = 'Invoice not found, please contact tech support.';
|
||||
break;
|
||||
}
|
||||
|
||||
$packingList = $invoice->owner;
|
||||
if (!$packingList) {
|
||||
$description = 'Packing List not found, please contact tech support.';
|
||||
break;
|
||||
}
|
||||
|
||||
$order = $packingList->owner;
|
||||
if (!$order) {
|
||||
$description = 'Order not found, please contact tech support.';
|
||||
break;
|
||||
}
|
||||
|
||||
$description = 'Payment For booking refs ' . $order->reference;
|
||||
break;
|
||||
case TransactionType::DEBIT_NOTE:
|
||||
$description = 'Debit Voucher for ' . $transaction->payment_reference;
|
||||
break;
|
||||
}
|
||||
|
||||
$incoming = $outgoing = '';
|
||||
|
||||
if (in_array($transaction->type, [TransactionType::TOP_UP, TransactionType::CREDIT_NOTE, TransactionType::GROUP_PAYMENT])) {
|
||||
$incoming = number_format($transaction->amount, $decimals, '.', ',');
|
||||
$this->runningBalance += $transaction->amount;
|
||||
}
|
||||
|
||||
if (in_array($transaction->type, [TransactionType::PAYMENT, TransactionType::DEBIT_NOTE])) {
|
||||
$outgoing = number_format($transaction->amount, $decimals, '.', ',');
|
||||
$this->runningBalance -= $transaction->amount;
|
||||
}
|
||||
|
||||
return [
|
||||
Carbon::parse($transaction->created_at)->format('d-m-Y h:i:s A'),
|
||||
$description,
|
||||
$incoming,
|
||||
$outgoing,
|
||||
number_format($this->runningBalance, $decimals, '.', ',')
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -20,11 +20,9 @@ class ExportsFeedback implements FromQuery, WithHeadings, WithHeadingRow, WithMa
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'Version',
|
||||
'Question Set',
|
||||
'Question Text',
|
||||
'Answer Text',
|
||||
'Answer Value',
|
||||
'Answer',
|
||||
'Source System',
|
||||
'Source Marking',
|
||||
'Source Email',
|
||||
@@ -40,7 +38,7 @@ class ExportsFeedback implements FromQuery, WithHeadings, WithHeadingRow, WithMa
|
||||
return QAUserAnswerSelected::whereHas('question', function ($query) {
|
||||
$query->whereHas('questionnaire', function ($innerQuery) {
|
||||
$innerQuery->where('group', 'feedback');
|
||||
}); //->where('created_at', '>', Carbon::now()->subMonths(1));
|
||||
})->where('created_at', '>', Carbon::now()->subMonths(1));
|
||||
})->orderBy('created_at', 'desc');
|
||||
}
|
||||
|
||||
@@ -58,14 +56,11 @@ class ExportsFeedback implements FromQuery, WithHeadings, WithHeadingRow, WithMa
|
||||
$companyModule = $user->companyModule()->first();
|
||||
$user_marking = $companyModule ? $companyModule->inviters()->withPivot('invitee_reference')->first()->pivot->invitee_reference : "";
|
||||
}
|
||||
$answer = $userAnswer->answer;
|
||||
|
||||
return [
|
||||
$userAnswer->question->questionnaire->version,
|
||||
$userAnswer->question->questionnaire->description,
|
||||
$userAnswer->question->question_text,
|
||||
$answer->display_text,
|
||||
$answer->value,
|
||||
$userAnswer->free_text_answer,
|
||||
$user ? QASystemSourceType::getText(QASystemSourceType::IZYIM) : QASystemSourceType::getText($source->system),
|
||||
$user ? $user_marking : $source->marking,
|
||||
$user ? $user->email : $source->email,
|
||||
|
||||
@@ -31,7 +31,6 @@ class ExportsPaymentTransactions implements FromQuery, WithHeadings, WithHeading
|
||||
return [
|
||||
'DocNo',
|
||||
'DocDate',
|
||||
'PaymentDate',
|
||||
'DebtorCode',
|
||||
'Ref',
|
||||
'ShipInfo',
|
||||
@@ -42,9 +41,6 @@ class ExportsPaymentTransactions implements FromQuery, WithHeadings, WithHeading
|
||||
'DeptNo',
|
||||
'Qty',
|
||||
'UnitPrice',
|
||||
'TaxType',
|
||||
'TaxableAmt',
|
||||
'TaxRate',
|
||||
// 'marking',
|
||||
// 'contact person',
|
||||
// 'contact number',
|
||||
@@ -60,12 +56,12 @@ class ExportsPaymentTransactions implements FromQuery, WithHeadings, WithHeading
|
||||
{
|
||||
$start_date = $this->request->input('startDate', null);
|
||||
if ($start_date) {
|
||||
$start_date = Carbon::parse($start_date)->startOfDay();
|
||||
$start_date = Carbon::parse($this->request->input('startDate'))->format('Y-m-d');
|
||||
}
|
||||
|
||||
$end_date = $this->request->input('endDate', null);
|
||||
if ($end_date) {
|
||||
$end_date = Carbon::parse($end_date)->endOfDay();
|
||||
$end_date = Carbon::parse($this->request->input('endDate'))->format('Y-m-d');
|
||||
}
|
||||
|
||||
$query = Transaction::query();
|
||||
@@ -78,42 +74,35 @@ class ExportsPaymentTransactions implements FromQuery, WithHeadings, WithHeading
|
||||
$approvalStatus = ApprovalStatus::APPROVED;
|
||||
}
|
||||
|
||||
// Adjusted the query to include both types and status
|
||||
$query->whereIn('type', [TransactionType::SHIPPING_INVOICE, TransactionType::STORAGE_INVOICE])
|
||||
->where('status', $approvalStatus);
|
||||
$query->where('type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [$approvalStatus]);
|
||||
|
||||
if ($start_date && $end_date) {
|
||||
$query->whereHas('transactions', function($transaction) use ($start_date, $end_date) {
|
||||
$transaction->where('type', TransactionType::PAYMENT)
|
||||
->whereBetween('updated_at', [$start_date, $end_date]);
|
||||
});
|
||||
} elseif ($start_date) {
|
||||
if($start_date && $end_date) {
|
||||
$query->whereBetween('updated_at', [
|
||||
Carbon::parse($start_date)->format('Y-m-d 0:00:00'),
|
||||
Carbon::parse($end_date)->format('Y-m-d 23:59:59')
|
||||
]);
|
||||
}
|
||||
elseif($start_date && !$end_date) {
|
||||
$query->whereHas('transactions', function($transaction) use ($start_date) {
|
||||
$transaction->where('type', TransactionType::PAYMENT)
|
||||
->where('updated_at', '>=', $start_date);
|
||||
$transaction->where('type', TransactionType::PAYMENT)->where('updated_at', '>=', Carbon::parse($start_date)->format('Y-m-d 0:00:00'));
|
||||
});
|
||||
} elseif ($end_date) {
|
||||
|
||||
}
|
||||
elseif(!$start_date && $end_date) {
|
||||
$query->whereHas('transactions', function($transaction) use ($end_date) {
|
||||
$transaction->where('type', TransactionType::PAYMENT)
|
||||
->where('updated_at', '<=', $end_date);
|
||||
$transaction->where('type', TransactionType::PAYMENT)->where('updated_at', '>=', Carbon::parse($end_date)->format('Y-m-d 0:00:00'));
|
||||
});
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
||||
public function map($transaction): array
|
||||
{
|
||||
$container = $transaction->owner->containers()->first();
|
||||
$order = $transaction->owner->owner;
|
||||
$company = $order->companyModule->company;
|
||||
if($transaction->type === TransactionType::STORAGE_INVOICE){
|
||||
$shippingTransactionDetails = $transaction->transactionDetails()->where('reference', 'STORAGE_FEE')->first();
|
||||
}
|
||||
else{
|
||||
$shippingTransactionDetails = $transaction->transactionDetails()->where('reference', 'SHIPPING_FEE')->first();
|
||||
}
|
||||
$shippingTransactionDetails = $transaction->transactionDetails()->where('reference', 'SHIPPING_FEE')->first();
|
||||
$marking = $order->companyModule->inviters()->withPivot('invitee_reference')->first()->pivot->invitee_reference;
|
||||
$contact = $order->companyModule->company->contacts->first();
|
||||
$userName = $order->companyModule->employees()->first();
|
||||
@@ -129,47 +118,13 @@ class ExportsPaymentTransactions implements FromQuery, WithHeadings, WithHeading
|
||||
$furtherDescription .= $item->name.' '.$item->quantity.' CBM'."\n";
|
||||
elseif($item->reference === 'MIN_CBM_CHARGES')
|
||||
$furtherDescription .= $item->name.' '.$item->quantity.' CBM'."\n";
|
||||
elseif($item->reference === 'STORAGE_FEE')
|
||||
$furtherDescription .= str_replace('<br>', ' | ', $item->name).' '."\n";
|
||||
else
|
||||
$furtherDescription .= $item->name.' '.$item->quantity.' X '.$item->price."\n";
|
||||
}
|
||||
|
||||
$transactionDetails = $transaction->transactionDetails;
|
||||
|
||||
$firstItem = true;
|
||||
$rows = [];
|
||||
foreach ($transactionDetails as $detail) {
|
||||
// Prepare each row based on the transaction detail
|
||||
$rows[] = [
|
||||
$firstItem ? '<<New>>' : '',
|
||||
$transaction->created_at->format('m/d/Y H:m'),
|
||||
$transaction->transactions()->where('type', TransactionType::PAYMENT)->first()->updated_at->format('m/d/Y H:m'),
|
||||
$company->debtor,
|
||||
$order->reference,
|
||||
$order->reference,
|
||||
'500-0000',
|
||||
str_replace('<br>', ' ', $detail->name),
|
||||
'',
|
||||
$container->reference,
|
||||
'CIEF',
|
||||
$detail->quantity,
|
||||
$detail->price,
|
||||
floatval($detail->tax_percentage) > 0 ? 'SV-6' : '',
|
||||
floatval($detail->tax_percentage) > 0 ? $detail->amount : '0',
|
||||
$detail->tax_percentage,
|
||||
];
|
||||
|
||||
if($firstItem) {
|
||||
$firstItem = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $rows;
|
||||
|
||||
return [
|
||||
'<<New>>',
|
||||
$transaction->transactions()->where('type', TransactionType::PAYMENT)->first()->updated_at->format('m/d/Y H:m'),
|
||||
$transaction->created_at->format('m/d/Y H:m'),
|
||||
$company->debtor,
|
||||
$order->reference,
|
||||
$order->reference,
|
||||
|
||||
@@ -59,7 +59,7 @@ class ListQuestionsQALogic extends AbstractControllerLogic
|
||||
$delimiter = "|";
|
||||
$parts = explode($delimiter, $decriptedToken);
|
||||
$questionSet = $parts[3];
|
||||
$query = $this->listsHelpMenuQuestions->execute(['questionnaire_set_id' => $questionSet, 'order_by' => (object)['column' => 'order','DESC' => false]]);
|
||||
$query = $this->listsHelpMenuQuestions->execute(['questionnaire_set_id' => $questionSet]);
|
||||
return $this->collectionResponse(HelpMenuQuestionResource::collection($query));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Imports\Services;
|
||||
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
use Illuminate\Support\Collection;
|
||||
use Maatwebsite\Excel\Concerns\ToCollection;
|
||||
|
||||
|
||||
class GenericImport implements ToCollection, WithHeadingRow
|
||||
{
|
||||
function headingRow(): int { return 1; }
|
||||
|
||||
public $rows;
|
||||
|
||||
/**
|
||||
* @param Collection $collection
|
||||
*/
|
||||
public function collection(Collection $collection)
|
||||
{
|
||||
$this->rows = $collection;
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Jobs\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Jobs\Processors\FetchesJobResultProcessor;
|
||||
use App\Http\Resources\JobResultResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class FetchJobResultLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Data',
|
||||
'message' => 'You have successfully retrieved data'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var FetchesJobResultProcessor */
|
||||
private $fetchesJobResultProcessor;
|
||||
|
||||
/**
|
||||
* FetchJobResultLogic constructor.
|
||||
* @param FetchesJobResultProcessor $fetchesJobResultProcessor
|
||||
*/
|
||||
public function __construct(FetchesJobResultProcessor $fetchesJobResultProcessor)
|
||||
{
|
||||
$this->fetchesJobResultProcessor = $fetchesJobResultProcessor;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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
|
||||
{
|
||||
$query = $this->fetchesJobResultProcessor->execute($request);
|
||||
|
||||
return $this->resourceResponse(new JobResultResource($query));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,118 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Jobs\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class ListGenericJobObject implements DataTransferObject
|
||||
{
|
||||
/** @var string */
|
||||
private $name;
|
||||
|
||||
/** @var array */
|
||||
private $payload;
|
||||
|
||||
/** @var string */
|
||||
private $jobId;
|
||||
|
||||
/** @var string */
|
||||
private $requestSignature;
|
||||
|
||||
/** @var string */
|
||||
private $resultSignature;
|
||||
|
||||
/** @var object */
|
||||
private $userInfo;
|
||||
|
||||
/** @var string */
|
||||
private $jobCommandName;
|
||||
|
||||
/** @var string */
|
||||
private $jobCommand;
|
||||
|
||||
public function __construct(string $name, array $payload, string $requestSignature, ?string $resultSignature, string $jobId, object $userInfo = null)
|
||||
{
|
||||
$this->name = $name;
|
||||
$this->payload = $payload;
|
||||
$this->jobId = $jobId;
|
||||
$this->requestSignature = $requestSignature;
|
||||
$this->resultSignature = $resultSignature;
|
||||
$this->userInfo = $userInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getPayload(): array
|
||||
{
|
||||
return $this->payload;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getJobId(): string
|
||||
{
|
||||
return $this->jobId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getRequestSignature(): string
|
||||
{
|
||||
return $this->requestSignature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getResultSignature(): ?string
|
||||
{
|
||||
return $this->resultSignature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return object
|
||||
*/
|
||||
public function getUserInfo(): object
|
||||
{
|
||||
return $this->userInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getJobCommandName(): string
|
||||
{
|
||||
return $this->jobCommandName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getJobCommand(): string
|
||||
{
|
||||
return $this->jobCommand;
|
||||
}
|
||||
|
||||
|
||||
public function setJobCommandName(string $jobCommandName)
|
||||
{
|
||||
$this->jobCommandName = $jobCommandName;
|
||||
}
|
||||
|
||||
public function setJobCommand(string $jobCommand)
|
||||
{
|
||||
$this->jobCommand = $jobCommand;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Jobs\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class UpdateJobResultObject implements DataTransferObject
|
||||
{
|
||||
/** @var string */
|
||||
private $result;
|
||||
|
||||
/** @var string */
|
||||
private $resultSignature;
|
||||
|
||||
/** @var string */
|
||||
private $jobCommandName;
|
||||
|
||||
/** @var string */
|
||||
private $jobCommand;
|
||||
|
||||
public function __construct(string $result, string $resultSignature, string $jobCommandName, string $jobCommand)
|
||||
{
|
||||
$this->result = $result;
|
||||
$this->resultSignature = $resultSignature;
|
||||
$this->jobCommandName = $jobCommandName;
|
||||
$this->jobCommand = $jobCommand;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getResult(): string
|
||||
{
|
||||
return $this->result;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getResultSignature(): string
|
||||
{
|
||||
return $this->resultSignature;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getJobCommandName(): string
|
||||
{
|
||||
return $this->jobCommandName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getJobCommand(): string
|
||||
{
|
||||
return $this->jobCommand;
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Jobs\Processors;
|
||||
|
||||
use App\Classes\Exceptions\JobResourceNotFoundException;
|
||||
use App\Classes\Modules\Jobs\Services\FetchesJobResult;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
class FetchesJobResultProcessor
|
||||
{
|
||||
/** @var FetchesJobResult */
|
||||
private $fetchesJobResult;
|
||||
|
||||
|
||||
/**
|
||||
* FetchesJobResultProcessor constructor.
|
||||
* @param FetchesJobResult $fetchesJobResult
|
||||
*/
|
||||
public function __construct(FetchesJobResult $fetchesJobResult)
|
||||
{
|
||||
$this->fetchesJobResult = $fetchesJobResult;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\JobResourceNotFoundException
|
||||
* @throws \App\Classes\Exceptions\ResourceNotFoundException
|
||||
*/
|
||||
public function execute(Request $request){
|
||||
|
||||
$res1 = $this->fetchesJobResult->execute(['job_id' => $request->route('job_id')]);
|
||||
if($request->route('is_last')){
|
||||
$res2 = $this->fetchesJobResult->execute(['request_signature' => $res1->request_signature, 'result_not_null' => true, 'order_by_id_desc' => true]);
|
||||
return $res2;
|
||||
}
|
||||
|
||||
if(!$res1->result){
|
||||
throw new JobResourceNotFoundException('Unable to find any job based on the criteria provided');
|
||||
}
|
||||
|
||||
return $res1;
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Jobs\Processors;
|
||||
|
||||
|
||||
use App\Classes\Modules\Jobs\Services\UpdatesJobResult;
|
||||
use App\Classes\Modules\Jobs\Services\FetchesJobResult;
|
||||
use App\Classes\Exceptions\JobResourceNotFoundException;
|
||||
use App\Classes\Modules\Jobs\DataTransferObjects\ListGenericJobObject;
|
||||
use App\Classes\Modules\Jobs\DataTransferObjects\UpdateJobResultObject;
|
||||
|
||||
class UpdateJobResultProcessor
|
||||
{
|
||||
|
||||
/** @var FetchesJobResult */
|
||||
private $fetchesJobResult;
|
||||
|
||||
/** @var UpdatesJobResult */
|
||||
private $updatesJobResult;
|
||||
|
||||
/**
|
||||
* UpdateJobResultProcessor constructor.
|
||||
* @param FetchesJobResult $fetchesJobResult
|
||||
* @param UpdatesJobResult $updatesJobResult
|
||||
*/
|
||||
public function __construct(FetchesJobResult $fetchesJobResult, UpdatesJobResult $updatesJobResult)
|
||||
{
|
||||
$this->fetchesJobResult = $fetchesJobResult;
|
||||
$this->updatesJobResult = $updatesJobResult;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ListGenericJobObject $listGenericJobObject
|
||||
* @param array $resultCurrent
|
||||
* @return void
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\JobResourceNotFoundException
|
||||
*/
|
||||
public function execute(ListGenericJobObject $listGenericJobObject, $resultCurrent) {
|
||||
$jobResultCurrent = $this->fetchesJobResult->execute(['job_id' => $listGenericJobObject->getJobId()]);
|
||||
$resultCurrentJson = json_encode($resultCurrent);
|
||||
$resultSignatureCurrent = md5($resultCurrentJson);
|
||||
|
||||
try{
|
||||
$jobResultExisting = $this->fetchesJobResult->execute(['request_signature' => $jobResultCurrent->request_signature, 'result_not_null' => true, 'order_by_id_desc' => true]);
|
||||
$resultSignatureExisting = $jobResultExisting->result_signature;
|
||||
//if($resultSignatureExisting != $resultSignatureCurrent){
|
||||
$this->updateJobResult($jobResultCurrent, $resultCurrentJson, $resultSignatureCurrent, $listGenericJobObject->getJobCommandName(), $listGenericJobObject->getJobCommand());
|
||||
//}
|
||||
} catch (JobResourceNotFoundException $exception){
|
||||
$this->updateJobResult($jobResultCurrent, $resultCurrentJson, $resultSignatureCurrent, $listGenericJobObject->getJobCommandName(), $listGenericJobObject->getJobCommand());
|
||||
}
|
||||
}
|
||||
|
||||
private function updateJobResult($jobResultCurrent, $resultCurrentJson, $resultSignatureCurrent, $jobCommandName, $jobCommand){
|
||||
$updateJobResultObject = new UpdateJobResultObject(
|
||||
$resultCurrentJson,
|
||||
$resultSignatureCurrent,
|
||||
$jobCommandName,
|
||||
$jobCommand
|
||||
);
|
||||
$create = $this->updatesJobResult->execute($jobResultCurrent, $updateJobResultObject);
|
||||
}
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Jobs\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Models\JobResult;
|
||||
use App\Classes\Modules\Jobs\DataTransferObjects\ListGenericJobObject;
|
||||
|
||||
class CreatesJobResult extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param ListGenericJobObject $listGenericJobObject
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(ListGenericJobObject $listGenericJobObject)
|
||||
{
|
||||
$model = new JobResult();
|
||||
$model->job_id = $listGenericJobObject->getJobId();
|
||||
$model->request_signature = $listGenericJobObject->getRequestSignature();
|
||||
$model->result_signature = $listGenericJobObject->getResultSignature();
|
||||
$model->url = $listGenericJobObject->getName();
|
||||
|
||||
return $this->handler($model);
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Jobs\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractFetchRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\JobResult;
|
||||
|
||||
class FetchesJobResult extends AbstractFetchRecord
|
||||
{
|
||||
|
||||
/** @var JobResult */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* FetchesJobResult constructor.
|
||||
* @param JobResult $repository
|
||||
*/
|
||||
public function __construct(JobResult $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
public function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Jobs\Services;
|
||||
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractListRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\JobResult;
|
||||
|
||||
class ListsJobResult extends AbstractListRecord
|
||||
{
|
||||
|
||||
/** @var JobResult */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* ListsJobResult constructor.
|
||||
* @param JobResult $repository
|
||||
*/
|
||||
public function __construct(JobResult $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Jobs\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\Jobs\DataTransferObjects\UpdateJobResultObject;
|
||||
use App\Models\JobResult;
|
||||
|
||||
class UpdatesJobResult extends AbstractUpdateRecord
|
||||
{
|
||||
|
||||
/**
|
||||
* @param JobResult $model
|
||||
* @param UpdateJobResultObject $updateJobResultObject
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(JobResult $model, UpdateJobResultObject $updateJobResultObject) {
|
||||
|
||||
$model->result = $updateJobResultObject->getResult();
|
||||
$model->result_signature = $updateJobResultObject->getResultSignature();
|
||||
$model->job_command_name = $updateJobResultObject->getJobCommandName();
|
||||
$model->job_command = $updateJobResultObject->getJobCommand();
|
||||
|
||||
return $this->handler($model);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -53,12 +53,8 @@ class FetchOrderV2Logic extends AbstractControllerLogic
|
||||
|
||||
$query = $this->fetchesOrder->execute(['reference' => $request->route('id'), 'with_packing_lists' => true]);
|
||||
|
||||
if($request->input('storages')){
|
||||
$query->storages = $request->input('storages'); //from middleware
|
||||
}
|
||||
|
||||
return $this->resourceResponse(new OrderV2Resource($query));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -9,8 +9,6 @@ use App\Classes\Modules\Addresses\Services\FetchesAddress;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Models\PackingList;
|
||||
use GuzzleHttp\Exception\GuzzleException;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class UpdateDoFromVTPortalProcessor
|
||||
{
|
||||
/** @var FetchesDataFromVTPortal */
|
||||
@@ -38,8 +36,6 @@ class UpdateDoFromVTPortalProcessor
|
||||
*/
|
||||
public function execute(PackingList $packing_list) {
|
||||
|
||||
Log::info('Trying to Call UpdateDoFromVTPortalProcessor');
|
||||
|
||||
if(!app()->environment(['production'])){
|
||||
return [];
|
||||
}
|
||||
|
||||
@@ -37,9 +37,6 @@ class UpdateDoFromYDPortalProcessor
|
||||
* @throws InternalServerErrorException
|
||||
*/
|
||||
public function execute(PackingList $packingList) {
|
||||
Log::info('Trying to Call UpdateDoFromYDPortalProcessor');
|
||||
Log::channel('storage_invoices')->info('UpdateDoFromYDPortalProcessor: '.json_encode($packingList));
|
||||
|
||||
if(!app()->environment(['production'])){
|
||||
return;
|
||||
}
|
||||
@@ -73,7 +70,6 @@ class UpdateDoFromYDPortalProcessor
|
||||
|
||||
|
||||
} catch (\Exception $exception){
|
||||
log::debug($exception);
|
||||
throw new InternalServerErrorException('failed to approve address due to an error related to YD portal');
|
||||
}
|
||||
}
|
||||
|
||||
+17
-11
@@ -56,21 +56,27 @@ class RescheduleContainerLogic extends AbstractControllerLogic
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$container = $this->fetchesContainer->execute(['id' => $request->route('id')]);
|
||||
$transport = $container->transports()->first();
|
||||
try {
|
||||
$container = $this->fetchesContainer->execute(['id' => $request->route('id')]);
|
||||
$transport = $container->transports()->first();
|
||||
|
||||
$old_schedule = $transport->schedules()->delete();
|
||||
$old_sechedule = $transport->schedules()->first();
|
||||
|
||||
// $this->updatesScheduleStatus->execute($old_schedule, ApprovalStatus::REJECTED);
|
||||
$this->updatesScheduleStatus->execute($old_sechedule, ApprovalStatus::REJECTED);
|
||||
|
||||
$scheduleObject = new ScheduleObject(
|
||||
Carbon::parse($request->input('etd')),
|
||||
Carbon::parse($request->input('eta')),
|
||||
ApprovalStatus::APPROVED
|
||||
);
|
||||
$schedule = $this->createsSchedule->execute($transport, $scheduleObject);
|
||||
$scheduleObject = new ScheduleObject(
|
||||
Carbon::parse($request->input('etd')),
|
||||
Carbon::parse($request->input('eta')),
|
||||
ApprovalStatus::APPROVED
|
||||
);
|
||||
$schedule = $this->createsSchedule->execute($transport, $scheduleObject);
|
||||
|
||||
return $this->resourceResponse(new ContainerResource($container));
|
||||
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
|
||||
return $this->resourceResponse(new ContainerResource($container));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,78 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Jobs\ListPackingListsJob;
|
||||
use App\Classes\Modules\Jobs\DataTransferObjects\ListGenericJobObject;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Classes\Modules\Jobs\Services\CreatesJobResult;
|
||||
|
||||
class ListPackingListsJobLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Job Retrieving PackingLists',
|
||||
'message' => 'You have successfully submit a job to retrieve a list of PackingLists'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CreatesJobResult */
|
||||
private $createsJobResult;
|
||||
|
||||
/**
|
||||
* ListPackingListsJobLogic constructor.
|
||||
* @param CreatesJobResult $createsJobResult
|
||||
*/
|
||||
public function __construct(CreatesJobResult $createsJobResult)
|
||||
{
|
||||
$this->createsJobResult = $createsJobResult;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$jobId = uniqid();
|
||||
|
||||
$user = Auth::user();
|
||||
$userInfo = (object) [
|
||||
// 'email' => $user->email,
|
||||
'type' => $user->type,
|
||||
];
|
||||
|
||||
|
||||
$userInfoJson = json_encode($userInfo);
|
||||
$requestSignature = md5($userInfoJson . $request->fullUrl());
|
||||
|
||||
|
||||
$listGenericJobObject = new ListGenericJobObject(
|
||||
$request->fullUrl(),
|
||||
$request->all(),
|
||||
$requestSignature,
|
||||
null,
|
||||
$jobId,
|
||||
$userInfo
|
||||
);
|
||||
|
||||
ListPackingListsJob::dispatch($listGenericJobObject)->onQueue('high_priority');
|
||||
|
||||
$result = [];
|
||||
$result['job_id'] = $jobId;
|
||||
|
||||
|
||||
$this->createsJobResult->execute($listGenericJobObject);
|
||||
|
||||
return $this->response(['data' => $result]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,8 +6,8 @@ namespace App\Classes\Modules\PackingLists\ControllersLogic;
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\PackingLists\Services\ListsPackingLists;
|
||||
use App\Classes\Modules\PackingLists\Standards\Rules\CanListPackingLists;
|
||||
use App\Http\Resources\PackingListNullOrderResource;
|
||||
use App\Http\Resources\PackingListResource;
|
||||
use App\Http\Resources\PackingListWithStorageResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -54,14 +54,7 @@ class ListPackingListsLogic extends AbstractControllerLogic
|
||||
|
||||
$query = $this->listsPackingLists->execute($this->listsPackingLists->deserializeFilters($request->input('filters')));
|
||||
|
||||
if($request->input('storages')){
|
||||
foreach ($query->items() as $item) {
|
||||
$item['storages'] = $request->input('storages');
|
||||
}
|
||||
return $this->collectionResponse(PackingListWithStorageResource::collection($query));
|
||||
}
|
||||
else{
|
||||
return $this->collectionResponse(PackingListResource::collection($query));
|
||||
}
|
||||
return $this->collectionResponse(PackingListResource::collection($query));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -121,7 +121,7 @@ class FetchContainersFromYdPortalProcessor
|
||||
$containerReference = explode('预计到港时间', $tracking[1])[0];
|
||||
$loadingDate = Carbon::parse($trackingRow->trackingtime);
|
||||
$etd = Carbon::parse($tracking[2])->subDays(5);
|
||||
$eta = Carbon::parse($tracking[2]);
|
||||
$eta = Carbon::parse($tracking[2])->addDays(2);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
@@ -147,6 +147,7 @@ class FetchContainersUpdatesFromYdPortalProcessor
|
||||
|
||||
if($delayDate){
|
||||
|
||||
$delayDate = $delayDate->addDays(2);
|
||||
$transport = $container->transports()->first();
|
||||
|
||||
if(!$transport->schedules()->whereDate('eta', '>=', $delayDate)->first()) {
|
||||
|
||||
+1
-2
@@ -76,7 +76,6 @@ class FetchDeliveryUpdatesFromYdPortalProcessor
|
||||
try {
|
||||
$client = new \GuzzleHttp\Client(['cookies' => true, 'headers' => ['Cookie' => 'utc_offset=480']]);
|
||||
|
||||
Log::info('Delivery tracking sTrackingNo: '. $packingList->reference);
|
||||
$request = $client->request('get', 'https://main.universe.com.my/Tracking/User/Paging?sEcho=1&sTrackingNo='.$packingList->reference.'&sOrgId=sti', ['timeout' => 3]);
|
||||
$deliveryTracking = json_decode($request->getBody()->getContents());
|
||||
foreach (array_reverse($deliveryTracking->aaData) as $trackingRow) {
|
||||
@@ -120,7 +119,7 @@ class FetchDeliveryUpdatesFromYdPortalProcessor
|
||||
}
|
||||
|
||||
}
|
||||
Log::info('FetchDeliveryUpdatesFromYdPortalProcessor ends');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -162,7 +162,7 @@ class FetchLoadedContainersFromVTPortalProcessor
|
||||
$container = $this->createContainerProcessor->execute($containerObject, $originWarehouse);
|
||||
}
|
||||
|
||||
$eta = Carbon::parse($containerInfo[4]);
|
||||
$eta = Carbon::parse($containerInfo[4])->addDays(2);
|
||||
$etd = Carbon::parse($eta)->subDays(7);
|
||||
|
||||
$delayDate = $containerInfo[7];
|
||||
@@ -183,7 +183,7 @@ class FetchLoadedContainersFromVTPortalProcessor
|
||||
}
|
||||
|
||||
if($delayDate){
|
||||
$delayDate = Carbon::parse($delayDate);
|
||||
$delayDate = Carbon::parse($delayDate)->addDays(2);
|
||||
$transport = $container->transports()->first();
|
||||
|
||||
if(!$transport->schedules()->where('eta', '=', $delayDate)->first()) {
|
||||
|
||||
+2
-2
@@ -199,7 +199,7 @@ class FetchOrderListsFromYdPortalProcessor
|
||||
$containerReference = explode('预计到港时间', $tracking[1])[0];
|
||||
$loadingDate = Carbon::parse($trackingRow->trackingtime);
|
||||
$etd = Carbon::parse($tracking[2])->subDays(5);
|
||||
$eta = Carbon::parse($tracking[2]);
|
||||
$eta = Carbon::parse($tracking[2])->addDays(2);
|
||||
}
|
||||
|
||||
$rescheduleETD = strpos($trackingRow->remark, '开') || strpos($trackingRow->remark, '到港');
|
||||
@@ -415,7 +415,7 @@ class FetchOrderListsFromYdPortalProcessor
|
||||
}
|
||||
|
||||
if($delayDate){
|
||||
$delayDate = $delayDate;
|
||||
$delayDate = $delayDate->addDays(2);
|
||||
$transport = $container->transports()->first();
|
||||
|
||||
if(!$transport->schedules()->whereDate('eta', '>=', $delayDate)->first()) {
|
||||
|
||||
+1
-7
@@ -138,13 +138,7 @@ class FetchPackingListsFromYdPortalProcessor
|
||||
|
||||
$receiveDate = Carbon::parse(substr(preg_replace("/[^0-9]/", "", $row->expressno), 0, 8));
|
||||
|
||||
$customerno = $row->customerno;
|
||||
// Check if $customerno contains '正确唛头YD' and extract the part after it
|
||||
if (strpos($customerno, '正确唛头YD') !== false) {
|
||||
$customerno = explode('正确唛头YD', $customerno)[1];
|
||||
}
|
||||
|
||||
$customerno = preg_split('/[-()\/]/', $customerno);
|
||||
$customerno = preg_split('(-|\(|\)|\/)', $row->customerno);
|
||||
|
||||
$orderNumber = $customerno[array_key_last($customerno)];
|
||||
$allow_contract = true;
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\PackingLists\Processors;
|
||||
|
||||
|
||||
use App\Classes\Modules\PackingLists\Services\ListsPackingLists;
|
||||
use App\Classes\Modules\Jobs\Processors\UpdateJobResultProcessor;
|
||||
use App\Classes\General\Helper;
|
||||
use App\Classes\Modules\Jobs\DataTransferObjects\ListGenericJobObject;
|
||||
use App\Http\Middleware\CheckForStorageInvoiceByPackingLists;
|
||||
use App\Http\Resources\ListPackingListJobResource;
|
||||
use App\Http\Resources\ListPackingListDetailsJobResource;
|
||||
use App\Http\Resources\ListPackingListJobWithStorageResource;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ListPackingListsJobProcessor
|
||||
{
|
||||
|
||||
/** @var ListsPackingLists */
|
||||
private $listsPackingLists;
|
||||
|
||||
/** @var UpdateJobResultProcessor */
|
||||
private $updateJobResultProcessor;
|
||||
|
||||
/** @var CheckForStorageInvoiceByPackingLists */
|
||||
private $checkForStorageInvoiceByPackingLists;
|
||||
|
||||
/**
|
||||
* ListPackingListsJobProcessor constructor.
|
||||
* @param ListsPackingLists $listsPackingLists
|
||||
* @param UpdateJobResultProcessor $updateJobResultProcessor
|
||||
*/
|
||||
public function __construct(ListsPackingLists $listsPackingLists, UpdateJobResultProcessor $updateJobResultProcessor, CheckForStorageInvoiceByPackingLists $checkForStorageInvoiceByPackingLists)
|
||||
{
|
||||
$this->listsPackingLists = $listsPackingLists;
|
||||
$this->updateJobResultProcessor = $updateJobResultProcessor;
|
||||
$this->checkForStorageInvoiceByPackingLists = $checkForStorageInvoiceByPackingLists;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ListGenericJobObject $listGenericJobObject
|
||||
* @return void
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\JobResourceNotFoundException
|
||||
*/
|
||||
public function execute(ListGenericJobObject $listGenericJobObject) {
|
||||
// $query = $this->listsPackingLists->execute($this->listsPackingLists->deserializeFilters($listGenericJobObject->getPayload()['filters']), ['page' => $listGenericJobObject->getPayload()['page'], 'with_containers_packages' => true]);
|
||||
$query = $this->listsPackingLists->execute($this->listsPackingLists->deserializeFilters($listGenericJobObject->getPayload()['filters']), ['page' => $listGenericJobObject->getPayload()['page']]);
|
||||
// $query = $this->listsPackingLists->execute(array_merge($this->listsPackingLists->deserializeFilters($listGenericJobObject->getPayload()['filters']), ['page' => $listGenericJobObject->getPayload()['page'], 'with_containers_packages' => true]));
|
||||
|
||||
$filtersArray = json_decode($listGenericJobObject->getPayload()['filters'], true);
|
||||
|
||||
$storages = [];
|
||||
if(isset($filtersArray['check_for_storage_invoice']))
|
||||
{
|
||||
$myRequest = new \Illuminate\Http\Request();
|
||||
$myRequest->setMethod('POST');
|
||||
$myRequest->request->add($listGenericJobObject->getPayload());
|
||||
$next = function ($request) {
|
||||
return $request;
|
||||
};
|
||||
|
||||
$response = $this->checkForStorageInvoiceByPackingLists->handle($myRequest, $next);
|
||||
$storages = $response->input('storages');
|
||||
}
|
||||
|
||||
foreach ($query->items() as &$item) {
|
||||
$item['userInfo'] = $listGenericJobObject->getUserInfo();
|
||||
$item['storages'] = $storages;
|
||||
}
|
||||
|
||||
if(isset($filtersArray['does_not_have_transaction_type'])){ //For Payment and Billing page > Pending Invoice tab
|
||||
$resultCurrent = Helper::collectionResponse(ListPackingListDetailsJobResource::collection($query));
|
||||
$this->updateJobResultProcessor->execute($listGenericJobObject, $resultCurrent);
|
||||
}
|
||||
else{
|
||||
if($storages){ //For Payment and Billing page > Pending Payment tab, Paid Invoice tab
|
||||
$resultCurrent = Helper::collectionResponse(ListPackingListJobWithStorageResource::collection($query));
|
||||
$this->updateJobResultProcessor->execute($listGenericJobObject, $resultCurrent);
|
||||
}
|
||||
else{
|
||||
$resultCurrent = Helper::collectionResponse(ListPackingListJobResource::collection($query));
|
||||
$this->updateJobResultProcessor->execute($listGenericJobObject, $resultCurrent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,7 @@ class FetchPerfexCRMInvoiceProcessor
|
||||
$invoiceId = $result->payload['id'];
|
||||
} else {
|
||||
$log['message'] = 'FetchPerfexCRMInvoiceProcessor failed for transaction > bill_no: '.$number;
|
||||
Log::channel('perfex_crm')->info($log);
|
||||
Helper::debugLogger($log);
|
||||
}
|
||||
}
|
||||
else{
|
||||
|
||||
@@ -25,7 +25,7 @@ class ConvertsPerfexCRMLeadToCustomer
|
||||
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::channel('perfex_crm')->info('ConvertsPerfexCRMLeadToCustomer: '.$response);
|
||||
Log::error('ConvertsPerfexCRMLeadToCustomer: '.$response);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ class CreatesPerfexCRMCustomer
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::channel('perfex_crm')->info('CreatesPerfexCRMCustomer: '.$response);
|
||||
Log::error('CreatesPerfexCRMCustomer: '.$response);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ class CreatesPerfexCRMCustomerContact
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::channel('perfex_crm')->info('CreatesPerfexCRMCustomerContact: '.$response);
|
||||
Log::error('CreatesPerfexCRMCustomerContact: '.$response);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class CreatesPerfexCRMCustomerProject
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::channel('perfex_crm')->info('CreatesPerfexCRMCustomerProject: '.$response);
|
||||
Log::error('CreatesPerfexCRMCustomerProject: '.$response);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ class CreatesPerfexCRMInvoice
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::channel('perfex_crm')->info('CreatesPerfexCRMInvoice: '.$response);
|
||||
Log::error('CreatesPerfexCRMInvoice: '.$response);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class CreatesPerfexCRMInvoicePayment
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::channel('perfex_crm')->info('CreatesPerfexCRMInvoicePayment: '.$response);
|
||||
Log::error('CreatesPerfexCRMInvoicePayment: '.$response);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ class CreatesPerfexCRMLead
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::channel('perfex_crm')->info('CreatesPerfexCRMLead: '.$response);
|
||||
Log::error('CreatesPerfexCRMLead: '.$response);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ class CreatesPerfexCRMMilestone
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::channel('perfex_crm')->info('CreatesPerfexCRMMilestone: '.$response);
|
||||
Log::error('CreatesPerfexCRMMilestone: '.$response);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class CreatesPerfexCRMSupportTicket
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::channel('perfex_crm')->info($response);
|
||||
Log::error($response);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ class CreatesPerfexCRMTask
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::channel('perfex_crm')->info('CreatesPerfexCRMTask: '.$response);
|
||||
Log::error('CreatesPerfexCRMTask: '.$response);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class FetchesPerfexCRMCustomer
|
||||
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::channel('perfex_crm')->info('FetchesPerfexCRMCustomer: '.$response);
|
||||
Log::error('FetchesPerfexCRMCustomer: '.$response);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ class FetchesPerfexCRMInvoice
|
||||
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::channel('perfex_crm')->info('FetchesPerfexCRMInvoice: '.$response);
|
||||
Log::error('FetchesPerfexCRMInvoice: '.$response);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ class FetchesPerfexCRMLead
|
||||
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::channel('perfex_crm')->info('FetchesPerfexCRMLead: '.$response);
|
||||
Log::error('FetchesPerfexCRMLead: '.$response);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class FetchesPerfexCRMMilestone
|
||||
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::channel('perfex_crm')->info('FetchesPerfexCRMMilestone: '.$response);
|
||||
Log::error('FetchesPerfexCRMMilestone: '.$response);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class FetchesPerfexCRMProject
|
||||
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::channel('perfex_crm')->info('FetchesPerfexCRMProject: '.$response);
|
||||
Log::error('FetchesPerfexCRMProject: '.$response);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class FetchesPerfexCRMTask
|
||||
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::channel('perfex_crm')->info($response);
|
||||
Helper::debugLogger($response);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ class UpdatesPerfexCRMCustomer
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
// Log::channel('perfex_crm')->info($response);
|
||||
// Helper::debugLogger($response);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,7 +61,7 @@ class UpdatesPerfexCRMInvoice
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::channel('perfex_crm')->info('UpdatesPerfexCRMInvoice: '.$response);
|
||||
Log::error('UpdatesPerfexCRMInvoice: '.$response);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ class UpdatesPerfexCRMLead
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::channel('perfex_crm')->info('UpdatesPerfexCRMLead: '.$response);
|
||||
Log::error('UpdatesPerfexCRMLead: '.$response);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ class UpdatesPerfexCRMProject
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::channel('perfex_crm')->info('UpdatesPerfexCRMProject: '.$response);
|
||||
Log::error('UpdatesPerfexCRMProject: '.$response);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ class UpdatesPerfexCRMTask
|
||||
$data = $response->json();
|
||||
return (object) $data;
|
||||
}else{
|
||||
Log::channel('perfex_crm')->info('UpdatesPerfexCRMTask: '.$response);
|
||||
Log::error('UpdatesPerfexCRMTask: '.$response);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+31
-10
@@ -4,15 +4,18 @@ namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Billplzs\Processors\CallbackBillplzProcessor;
|
||||
|
||||
|
||||
use App\Classes\Modules\Documents\Services\ApprovesDocument;
|
||||
use App\Classes\Modules\Documents\Services\FetchesDocument;
|
||||
use App\Classes\Modules\Documents\Services\RejectsDocument;
|
||||
use App\Classes\Modules\Orders\Processors\UpdateDoFromVTPortalProcessor;
|
||||
use App\Classes\Modules\Orders\Processors\UpdateDoFromYDPortalProcessor;
|
||||
use App\Classes\Modules\Transactions\Processors\CreatePaymentTransactionProcessor;
|
||||
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
@@ -26,15 +29,15 @@ class ApprovePaymentTransactionLogic extends AbstractControllerLogic
|
||||
* @param RejectsDocument $rejectsDocument
|
||||
* @param UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor
|
||||
* @param UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor
|
||||
* @param CreatePaymentTransactionProcessor $createPaymentTransactionProcessor
|
||||
*/
|
||||
public function __construct(FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, ApprovesDocument $approvesDocument, RejectsDocument $rejectsDocument, CallbackBillplzProcessor $callbackBillplzProcessor)
|
||||
public function __construct(FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, ApprovesDocument $approvesDocument, RejectsDocument $rejectsDocument, UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor, UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor)
|
||||
{
|
||||
$this->fetchesTransaction = $fetchesTransaction;
|
||||
$this->updatesTransactionStatus = $updatesTransactionStatus;
|
||||
$this->approvesDocument = $approvesDocument;
|
||||
$this->rejectsDocument = $rejectsDocument;
|
||||
$this->callbackBillplzProcessor = $callbackBillplzProcessor;
|
||||
$this->updateDoFromVTPortalProcessor = $updateDoFromVTPortalProcessor;
|
||||
$this->updateDoFromYDPortalProcessor = $updateDoFromYDPortalProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -59,8 +62,11 @@ class ApprovePaymentTransactionLogic extends AbstractControllerLogic
|
||||
/** @var RejectsDocument */
|
||||
private $rejectsDocument;
|
||||
|
||||
/** @var CallbackBillplzProcessor */
|
||||
private $callbackBillplzProcessor;
|
||||
/** @var UpdateDoFromVTPortalProcessor */
|
||||
private $updateDoFromVTPortalProcessor;
|
||||
|
||||
/** @var UpdateDoFromYDPortalProcessor */
|
||||
private $updateDoFromYDPortalProcessor ;
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
@@ -76,14 +82,29 @@ class ApprovePaymentTransactionLogic extends AbstractControllerLogic
|
||||
|
||||
$transaction = $this->fetchesTransaction->execute(['id' => $request->route('transaction_id')]);
|
||||
|
||||
$status === 'approve' ? $this->approvesDocument->execute($transaction->documents()->where('status', ApprovalStatus::PENDING_VERIFICATION)->first()) : $this->rejectsDocument->execute($transaction->documents()->where('status', ApprovalStatus::PENDING_VERIFICATION)->first());
|
||||
$status === 'approve' ? $this->approvesDocument->execute($transaction->documents()->first()) : $this->rejectsDocument->execute($transaction->documents()->first());
|
||||
|
||||
$this->updatesTransactionStatus->execute($transaction, $status === 'approve' ? ApprovalStatus::APPROVED : ApprovalStatus::REJECTED);
|
||||
|
||||
if ($status === 'approve') {
|
||||
$this->callbackBillplzProcessor->execute($transaction, ApprovalStatus::APPROVED);
|
||||
if($transaction->status === ApprovalStatus::APPROVED){
|
||||
$invoice = $transaction->owner;
|
||||
$packingList = $invoice->owner;
|
||||
|
||||
if(($invoice->amount - $transaction->amount) < 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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
return $this->response([]);
|
||||
}
|
||||
|
||||
|
||||
@@ -21,8 +21,6 @@ use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Models\GroupTransaction;
|
||||
use App\Http\Resources\WalletTransactionResource;
|
||||
use App\Models\Wallet;
|
||||
use App\Classes\Modules\Transactions\Processors\ReleaseGoodsToCustomerProcessor;
|
||||
|
||||
|
||||
class CreateGroupsLogic extends AbstractControllerLogic
|
||||
{
|
||||
@@ -57,18 +55,13 @@ class CreateGroupsLogic extends AbstractControllerLogic
|
||||
/** @var CreatesGroup */
|
||||
private $createsGroup;
|
||||
|
||||
/** @var ReleaseGoodsToCustomerProcessor */
|
||||
private $releaseGoodsToCustomerProcessor;
|
||||
|
||||
|
||||
public function __construct(
|
||||
FetchesTransaction $fetchesTransaction,
|
||||
GeneratesTransactionBillNumber $generatesTransactionBillNumber,
|
||||
FetchesTransaction $fetchesTransaction,
|
||||
GeneratesTransactionBillNumber $generatesTransactionBillNumber,
|
||||
FetchesCompanyModule $fetchesCompanyModule,
|
||||
CreateWalletTopUpTransactionProcessor $createWalletTopUpTransactionProcessor,
|
||||
CreatePaymentTransactionProcessor $createPaymentTransactionProcessor,
|
||||
CreatesGroup $createsGroup,
|
||||
ReleaseGoodsToCustomerProcessor $releaseGoodsToCustomerProcessor
|
||||
CreatesGroup $createsGroup
|
||||
)
|
||||
{
|
||||
$this->fetchesTransaction = $fetchesTransaction;
|
||||
@@ -77,58 +70,19 @@ class CreateGroupsLogic extends AbstractControllerLogic
|
||||
$this->createWalletTopUpTransactionProcessor = $createWalletTopUpTransactionProcessor;
|
||||
$this->createPaymentTransactionProcessor = $createPaymentTransactionProcessor;
|
||||
$this->createsGroup = $createsGroup;
|
||||
$this->releaseGoodsToCustomerProcessor = $releaseGoodsToCustomerProcessor;
|
||||
}
|
||||
|
||||
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();
|
||||
$isInvoicesApprove = $this->checkIfInvoicesAreApprove($invoices);
|
||||
if(!$isInvoicesApprove){
|
||||
$response = ['message' => 'One of the transactions might be suspended; please check if there are any disputes in progress.'];
|
||||
return $this->response(['data' => $response]);
|
||||
}
|
||||
else{
|
||||
$paymentMethodStr = $request->input('payment_method');
|
||||
$paymentMethod = PaymentMethodType::PAYMENT_METHODS[$paymentMethodStr];
|
||||
$amount = $request->input('amount');
|
||||
$bankCode = $request->input('bank_code');
|
||||
$result = $this->processInvoices($invoices, $paymentMethodStr, $amount, $bankCode);
|
||||
|
||||
if ($paymentMethod === PaymentMethodType::PAYMENT_GATEWAY) {
|
||||
return $this->resourceResponse(new WalletTransactionResource($result));
|
||||
}
|
||||
}
|
||||
return $this->response([]);
|
||||
}
|
||||
|
||||
private function processInvoices($invoices, $reqPaymentMethod, $reqAmount, $reqBankCode){
|
||||
$result = [];
|
||||
$payment_method = PaymentMethodType::PAYMENT_METHODS[$reqPaymentMethod];
|
||||
$groupPyamentStatus = ApprovalStatus::PENDING_VERIFICATION;
|
||||
$billNumber = $this->generatesTransactionBillNumber->execute('PYMT-');
|
||||
foreach ($invoices as $invoice) {
|
||||
$order = null;
|
||||
if ($invoice->owner instanceof Transaction) {
|
||||
if ($invoice->owner) {
|
||||
if ($invoice->owner->owner) {
|
||||
$order = $invoice->owner->owner->owner;
|
||||
}
|
||||
}
|
||||
} else if (!($invoice->owner instanceof Transaction) && !($invoice->owner instanceof Wallet)) {
|
||||
if ($invoice->owner) {
|
||||
$order = $invoice->owner->owner;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$order) {
|
||||
throw new MalformedRequestException("There is an error while paying for invoice {$invoice->bill_no}");
|
||||
}
|
||||
}
|
||||
|
||||
if ($payment_method == PaymentMethodType::WALLET) {
|
||||
|
||||
@@ -137,7 +91,7 @@ class CreateGroupsLogic extends AbstractControllerLogic
|
||||
$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 - $reqAmount),2) < 0){
|
||||
if((float) number_format(($wallet->amount - $request->input('amount')),2) < 0){
|
||||
throw new MalformedRequestException('Insufficient wallet balance. Please Top up your wallet.');
|
||||
}
|
||||
|
||||
@@ -173,12 +127,7 @@ class CreateGroupsLogic extends AbstractControllerLogic
|
||||
|
||||
foreach ($invoices as $invoice) {
|
||||
if ($payment_method == PaymentMethodType::WALLET) {
|
||||
$paymentTransaction = $this->createPaymentTransactionProcessor->execute($invoice, PaymentMethodType::WALLET, $reqBankCode, false);
|
||||
|
||||
if($paymentTransaction && $paymentTransaction->status == ApprovalStatus::APPROVED){
|
||||
$pL = $invoice->owner;
|
||||
$this->releaseGoodsToCustomerProcessor->execute($pL, $invoice);
|
||||
}
|
||||
$this->createPaymentTransactionProcessor->execute($invoice, PaymentMethodType::WALLET, $request->input('bank_code'));
|
||||
}
|
||||
|
||||
$issuer = $invoice->issuer;
|
||||
@@ -200,12 +149,11 @@ class CreateGroupsLogic extends AbstractControllerLogic
|
||||
|
||||
if (in_array($payment_method, [PaymentMethodType::PAYMENT_GATEWAY, PaymentMethodType::CASH])) {
|
||||
// create only one billplz payment for wallet top up
|
||||
$amount = floatval(str_replace(',', '', $reqAmount));
|
||||
$amount = floatval(str_replace(',', '', $request->input('amount')));
|
||||
$companyModuleId = $invoice->receiver;
|
||||
$companyModule = $this->fetchesCompanyModule->execute(['id' => $companyModuleId]);
|
||||
|
||||
$topUpTransaction = $this->createWalletTopUpTransactionProcessor->execute($companyModule, $amount, $reqBankCode, $payment_method, $billNumber, true);
|
||||
$result = $topUpTransaction;
|
||||
$topUpTransaction = $this->createWalletTopUpTransactionProcessor->execute($companyModule, $amount, $request->input('bank_code'), true, $payment_method);
|
||||
}
|
||||
|
||||
$group->issuer = $issuer;
|
||||
@@ -221,15 +169,11 @@ class CreateGroupsLogic extends AbstractControllerLogic
|
||||
$group->status = $groupPyamentStatus;
|
||||
$group->save();
|
||||
|
||||
return $result;
|
||||
}
|
||||
if ($payment_method === PaymentMethodType::PAYMENT_GATEWAY) {
|
||||
return $this->resourceResponse(new WalletTransactionResource($topUpTransaction));
|
||||
|
||||
private function checkIfInvoicesAreApprove($invoices){
|
||||
foreach ($invoices as $invoice) {
|
||||
if($invoice->status !== ApprovalStatus::APPROVED && $invoice->status !== ApprovalStatus::COMPLETED){
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return $this->response([]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+16
-21
@@ -10,8 +10,6 @@ use App\Http\Resources\TransactionResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Classes\Modules\Transactions\Processors\CreatePaymentTransactionProcessor;
|
||||
use App\Classes\Modules\Transactions\Processors\ReleaseGoodsToCustomerProcessor;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
|
||||
class CreatePaymentTransactionLogic extends AbstractControllerLogic
|
||||
{
|
||||
@@ -32,18 +30,13 @@ class CreatePaymentTransactionLogic extends AbstractControllerLogic
|
||||
/** @var CreatePaymentTransactionProcessor */
|
||||
private $createPaymentTransactionProcessor;
|
||||
|
||||
/** @var ReleaseGoodsToCustomerProcessor */
|
||||
private $releaseGoodsToCustomerProcessor;
|
||||
|
||||
public function __construct(
|
||||
FetchesTransaction $fetchesTransaction,
|
||||
CreatePaymentTransactionProcessor $createPaymentTransactionProcessor,
|
||||
ReleaseGoodsToCustomerProcessor $releaseGoodsToCustomerProcessor
|
||||
CreatePaymentTransactionProcessor $createPaymentTransactionProcessor
|
||||
)
|
||||
{
|
||||
$this->fetchesTransaction = $fetchesTransaction;
|
||||
$this->createPaymentTransactionProcessor = $createPaymentTransactionProcessor;
|
||||
$this->releaseGoodsToCustomerProcessor = $releaseGoodsToCustomerProcessor;
|
||||
}
|
||||
|
||||
public function logic(Request $request) : JsonResponse
|
||||
@@ -52,20 +45,22 @@ class CreatePaymentTransactionLogic extends AbstractControllerLogic
|
||||
|
||||
$invoice_transaction = $this->fetchesTransaction->execute(['id' => $request->input('transaction_id')]);
|
||||
|
||||
if($invoice_transaction->status === ApprovalStatus::APPROVED){
|
||||
$payment_transaction = $this->createPaymentTransactionProcessor->execute($invoice_transaction, $payment_method , $request->input('bank_code'), false);
|
||||
$payment_transaction = $this->createPaymentTransactionProcessor->execute($invoice_transaction, $payment_method , $request->input('bank_code'));
|
||||
|
||||
if($payment_transaction && $payment_transaction->status === ApprovalStatus::APPROVED){
|
||||
$pL = $invoice_transaction->owner;
|
||||
$this->releaseGoodsToCustomerProcessor->execute($pL, $invoice_transaction);
|
||||
}
|
||||
return $this->resourceResponse(new TransactionResource($payment_transaction));
|
||||
}
|
||||
//cief todo: at exchange there is a transition step - starts
|
||||
// if(PaymentMethodType::PAYMENT_METHODS[$request->input('payment_method')] == PaymentMethodType::PAYMENT_GATEWAY){
|
||||
// $this->updatesTransactionStatus->execute($transaction, ApprovalStatus::PENDING_VERIFICATION);
|
||||
// }
|
||||
|
||||
$response = ['message' => 'A transaction might be suspended; please check if there is any dispute in progress.'];
|
||||
return $this->response(['data' => $response]);
|
||||
// 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
|
||||
//cief todo: at exchange there is a transition step - ends
|
||||
|
||||
return $this->resourceResponse(new TransactionResource($payment_transaction));
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -48,15 +48,8 @@ class DeleteGroupLogic extends AbstractControllerLogic
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
ini_set('memory_limit', '-1');
|
||||
|
||||
$group = $this->fetchesGroup->execute(['id' => $request->route('id')]);
|
||||
|
||||
foreach ($group->groupTransactions as $groupTransaction) {
|
||||
// $groupTransaction->transaction->delete();
|
||||
$groupTransaction->delete();
|
||||
}
|
||||
|
||||
$this->deletesGroup->execute($group);
|
||||
|
||||
return $this->response([]);
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\General\Eloquent\Filters\PaymentMethod;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
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 App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class DeletePaidGroupLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'Delete Paid 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')]);
|
||||
|
||||
foreach ($group->groupTransactions as $groupTransaction) {
|
||||
$invoice = $groupTransaction->transaction;
|
||||
$paymentTransaction = $invoice->transactions()->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->first();
|
||||
|
||||
if ($paymentTransaction->payment_method == PaymentMethodType::WALLET) {
|
||||
// Store the transaction ID before deleting
|
||||
$transactionId = Transaction::where('bill_no', $paymentTransaction->payment_reference)->first()->id;
|
||||
|
||||
// Delete the transaction
|
||||
Transaction::where('id', $transactionId)->first()->delete();
|
||||
|
||||
// Now you have the transaction ID available in $transactionId
|
||||
Log::channel('deletePaidGroupOrder')->info("Deleted payment reference transaction ID: " . $transactionId);
|
||||
} else {
|
||||
Log::channel('deletePaidGroupOrder')->info("no transaction found. Invoice Id ->" . $invoice->id);
|
||||
}
|
||||
|
||||
// Store the transaction ID before deleting
|
||||
$transactionId = $paymentTransaction->id;
|
||||
|
||||
// Delete the payment transaction
|
||||
$paymentTransaction->delete();
|
||||
Log::channel('deletePaidGroupOrder')->info("Deleted payment transaction ID: " . $transactionId);
|
||||
}
|
||||
|
||||
Log::channel('deletePaidGroupOrder')->info("Deleted Group -> " . $group->id);
|
||||
$this->deletesGroup->execute($group);
|
||||
|
||||
return $this->response([]);
|
||||
}
|
||||
}
|
||||
@@ -1,78 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
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\UpdatesTransactionStatus;
|
||||
use App\Classes\Modules\Transactions\Services\FetchesGroup;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Models\Transaction;
|
||||
use App\Models\Wallet;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class DeletePaymentTransactionLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Delete Payment Transaction',
|
||||
'message' => 'You have successfully deleted the payment transaction'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var FetchesGroup */
|
||||
private $fetchesGroup;
|
||||
|
||||
/** @var FetchesTransaction */
|
||||
private $fetchesTransaction;
|
||||
|
||||
/** @var UpdatesTransactionStatus */
|
||||
private $updatesTransactionStatus;
|
||||
|
||||
|
||||
/**
|
||||
* SuspendTransactionLogic constructor.
|
||||
* @param FetchesTransaction $fetchesTransaction
|
||||
* @param UpdatesTransactionStatus $updatesTransactionStatus
|
||||
* @param FetchesGroup $fetchesGroup
|
||||
*/
|
||||
public function __construct(FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, FetchesGroup $fetchesGroup)
|
||||
{
|
||||
$this->fetchesTransaction = $fetchesTransaction;
|
||||
$this->updatesTransactionStatus = $updatesTransactionStatus;
|
||||
$this->fetchesGroup = $fetchesGroup;
|
||||
}
|
||||
|
||||
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$transaction = $this->fetchesTransaction->execute(['id' => $request->route('id')]);
|
||||
|
||||
if($transaction->owner instanceof Wallet){
|
||||
try{
|
||||
$group = $this->fetchesGroup->execute(['reference' => $transaction->payment_reference]);
|
||||
$group->status = ApprovalStatus::SUSPENDED;
|
||||
$group->save();
|
||||
}
|
||||
catch(\Exception $excaption){
|
||||
Log::info('No group associated with transaction with payment_reference - '.$transaction->payment_reference);
|
||||
}
|
||||
}
|
||||
|
||||
$transaction->delete();
|
||||
|
||||
$invoice = $transaction->owner;
|
||||
if ($invoice instanceof Transaction) {
|
||||
$this->updatesTransactionStatus->execute($invoice, ApprovalStatus::APPROVED);
|
||||
}
|
||||
|
||||
return $this->response([]);
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,7 @@ class DeleteTransactionLogic extends AbstractControllerLogic
|
||||
|
||||
|
||||
/**
|
||||
* DeleteTransactionLogic constructor.
|
||||
* SuspendTransactionLogic constructor.
|
||||
* @param FetchesTransaction $fetchesTransaction
|
||||
* @param UpdatesTransactionStatus $updatesTransactionStatus
|
||||
*/
|
||||
|
||||
@@ -5,12 +5,10 @@ namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Transactions\Services\ListsTransactions;
|
||||
use App\Http\Resources\TransactionWithStorageResource;
|
||||
use App\Http\Resources\BookingResource;
|
||||
use App\Http\Resources\TransactionResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
|
||||
class ListTransactionsLogic extends AbstractControllerLogic
|
||||
{
|
||||
@@ -40,21 +38,13 @@ class ListTransactionsLogic extends AbstractControllerLogic
|
||||
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
|
||||
$query = $this->listsTransactions->execute($this->listsTransactions->deserializeFilters($request->input('filters')));
|
||||
|
||||
if($request->input('storages')){
|
||||
foreach ($query->items() as $item) {
|
||||
$transactionId = $item['id'];
|
||||
$filteredStorages = array_filter($request->input('storages'), function ($storage) use ($transactionId) {
|
||||
return isset($storage['parentInvoiceId']) && $storage['parentInvoiceId'] == $transactionId;
|
||||
});
|
||||
$item['storages'] = $filteredStorages;
|
||||
}
|
||||
//return $this->collectionResponse(TransactionWithStorageResource::collection($query));
|
||||
}
|
||||
// else{
|
||||
// return $this->collectionResponse(TransactionResource::collection($query));
|
||||
//
|
||||
return $this->collectionResponse(TransactionWithStorageResource::collection($query));
|
||||
return $this->collectionResponse(TransactionResource::collection($query));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,79 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Transactions\Services\ListsTransactions;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use App\Http\Resources\WalletTransactionResource ;
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ListWalletTransactionsLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* ListTransactionsLogic constructor.
|
||||
* @param ListsTransactions $listsTransactions
|
||||
*/
|
||||
public function __construct(ListsTransactions $listsTransactions)
|
||||
{
|
||||
$this->listsTransactions = $listsTransactions;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Wallet Transactions',
|
||||
'message' => 'You have successfully retrieved a list of transactions'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var ListsTransactions */
|
||||
private $listsTransactions;
|
||||
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$query = $this->listsTransactions->execute($this->listsTransactions->deserializeFilters($request->input('filters')));
|
||||
|
||||
if (str_contains($request->input('filters'), "owner_id") && $query->count() > 0) {
|
||||
$wallet_total_incoming = Transaction::where('owner_type', $query->first()->owner_type)
|
||||
->where('owner_id', $query->first()->owner_id)
|
||||
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
|
||||
->whereIn('type', [TransactionType::TOP_UP, TransactionType::CREDIT_NOTE, TransactionType::GROUP_PAYMENT])
|
||||
->sum('amount');
|
||||
|
||||
$wallet_total_outgoing = Transaction::where('owner_type', $query->first()->owner_type)
|
||||
->where('owner_id', $query->first()->owner_id)
|
||||
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
|
||||
->whereIn('type', [TransactionType::PAYMENT, TransactionType::DEBIT_NOTE])
|
||||
->sum('amount');
|
||||
|
||||
$currentWalletBalance = $wallet_total_incoming - $wallet_total_outgoing;
|
||||
$incoming = Transaction::where('owner_type', $query->first()->owner_type)
|
||||
->where('owner_id', $query->first()->owner_id)
|
||||
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
|
||||
->whereIn('type', [TransactionType::TOP_UP, TransactionType::CREDIT_NOTE, TransactionType::GROUP_PAYMENT])
|
||||
->where('id', '>', $query->first()->id)
|
||||
->sum('amount');
|
||||
$outgoing = Transaction::where('owner_type', $query->first()->owner_type)
|
||||
->where('owner_id', $query->first()->owner_id)
|
||||
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])
|
||||
->whereIn('type', [TransactionType::PAYMENT, TransactionType::DEBIT_NOTE])
|
||||
->where('id', '>', $query->first()->id)
|
||||
->sum('amount');
|
||||
$runningBalanceInReverse = $currentWalletBalance - $incoming + $outgoing;
|
||||
$request['running_balance'] = $runningBalanceInReverse;
|
||||
}
|
||||
|
||||
return $this->collectionResponse(WalletTransactionResource::collection($query));
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
+7
-15
@@ -15,7 +15,6 @@ use Mccarlosen\LaravelMpdf\Facades\LaravelMpdf;
|
||||
use App\Classes\Modules\Documents\Services\CreatesDocument;
|
||||
use App\Classes\Modules\Documents\Services\CreatesFiles;
|
||||
use App\Models\Document;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class RegenerateShippingInvoiceTransactionLogic extends AbstractControllerLogic
|
||||
{
|
||||
@@ -52,18 +51,11 @@ class RegenerateShippingInvoiceTransactionLogic extends AbstractControllerLogic
|
||||
foreach ($orders as $order){
|
||||
$invoices = $order->transactions()->where('transactions.type', TransactionType::SHIPPING_INVOICE)->get();
|
||||
foreach ($invoices as $invoice){
|
||||
|
||||
|
||||
$invoice->documents()->delete();
|
||||
|
||||
$view = 'pages.pdfs.shipping_invoice';
|
||||
$dateToCompare = Carbon::parse(env('SST_START_DATE', '2024-04-01 00:00:00'));
|
||||
$shippingInvoiceTransactionCreatedDate = Carbon::parse($invoice->created_at);
|
||||
if ($shippingInvoiceTransactionCreatedDate->isAfter($dateToCompare) && $invoice->tax > 0) {
|
||||
$view = 'pages.pdfs.shipping_invoice_sst';
|
||||
}
|
||||
|
||||
$transaction_invoice_pdf = LaravelMpdf::loadView($view, ['invoice_transaction' => $invoice]);
|
||||
|
||||
|
||||
$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()))],
|
||||
@@ -71,11 +63,11 @@ class RegenerateShippingInvoiceTransactionLogic extends AbstractControllerLogic
|
||||
ApprovalStatus::COMPLETED,
|
||||
'shipping_invoice'
|
||||
);
|
||||
|
||||
|
||||
$document =$this->createsDocument->execute($invoice, $document_object);
|
||||
|
||||
|
||||
$this->createsFiles->execute($document, $document_object);
|
||||
|
||||
|
||||
// dump($document);
|
||||
}
|
||||
}
|
||||
|
||||
-84
@@ -1,84 +0,0 @@
|
||||
<?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\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||
use App\Models\Document;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class RegenerateSingleShippingInvoiceTransactionLogic 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;
|
||||
|
||||
/** @var FetchesTransaction */
|
||||
private $fetchesTransaction;
|
||||
|
||||
/**
|
||||
* @param CreatesDocument $createsDocument
|
||||
*/
|
||||
public function __construct(CreatesDocument $createsDocument, CreatesFiles $createsFiles, FetchesTransaction $fetchesTransaction)
|
||||
{
|
||||
$this->createsDocument = $createsDocument;
|
||||
$this->createsFiles = $createsFiles;
|
||||
$this->fetchesTransaction = $fetchesTransaction;
|
||||
}
|
||||
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$invoice = $this->fetchesTransaction->execute(['id' => $request->route('invoice_id')]);
|
||||
|
||||
$invoice->documents()->delete();
|
||||
|
||||
$view = 'pages.pdfs.shipping_invoice';
|
||||
$dateToCompare = Carbon::parse(env('SST_START_DATE', '2024-04-01 00:00:00'));
|
||||
$shippingInvoiceTransactionCreatedDate = Carbon::parse($invoice->created_at);
|
||||
if ($shippingInvoiceTransactionCreatedDate->isAfter($dateToCompare) && $invoice->tax > 0) {
|
||||
$view = 'pages.pdfs.shipping_invoice_sst';
|
||||
}
|
||||
|
||||
$transaction_invoice_pdf = LaravelMpdf::loadView($view, ['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([]);
|
||||
}
|
||||
|
||||
}
|
||||
-67
@@ -1,67 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Classes\Modules\Documents\Services\CreatesDocument;
|
||||
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||
use App\Classes\Modules\Transactions\Processors\CreateStorageInvoiceDocTransactionFixProcessor;
|
||||
use App\Classes\Modules\Transactions\Standards\Rules\CanRegenerateStorageInvoice;
|
||||
use App\Classes\ValueObjects\Constants\TransactionType;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class RegenerateSingleStorageInvoiceTransactionLogic extends AbstractControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Regenerate Storage Invoice',
|
||||
'message' => 'You have successfully regenerated storage invoice'
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
/** @var FetchesTransaction */
|
||||
private $fetchesTransaction;
|
||||
|
||||
/** @var CreateStorageInvoiceDocTransactionFixProcessor */
|
||||
private $createStorageInvoiceDocTransactionProcessor;
|
||||
|
||||
/** @var CanRegenerateStorageInvoice */
|
||||
private $canRegenerateStorageInvoice;
|
||||
|
||||
/**
|
||||
* @param CreatesDocument $createsDocument
|
||||
*/
|
||||
public function __construct(FetchesTransaction $fetchesTransaction, CreateStorageInvoiceDocTransactionFixProcessor $createStorageInvoiceDocTransactionProcessor, CanRegenerateStorageInvoice $canRegenerateStorageInvoice)
|
||||
{
|
||||
$this->fetchesTransaction = $fetchesTransaction;
|
||||
$this->createStorageInvoiceDocTransactionProcessor = $createStorageInvoiceDocTransactionProcessor;
|
||||
$this->canRegenerateStorageInvoice = $canRegenerateStorageInvoice;
|
||||
}
|
||||
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$this->canRegenerateStorageInvoice->passes();
|
||||
|
||||
$invoice = $this->fetchesTransaction->execute(['id' => $request->route('invoice_id')]);
|
||||
$packingList = $invoice->owner;
|
||||
$order = $packingList->owner;
|
||||
$invoices = $order->transactions()->where('transactions.type', TransactionType::STORAGE_INVOICE)->get();
|
||||
foreach ($invoices as $invoice){
|
||||
$invoice->documents()->delete();
|
||||
}
|
||||
|
||||
$this->createStorageInvoiceDocTransactionProcessor->execute($packingList, true);
|
||||
Log::info(Auth::user()->email." regenerate storage invoice for transaction with id ".$request->route('invoice_id'));
|
||||
|
||||
return $this->response([]);
|
||||
}
|
||||
|
||||
}
|
||||
+12
-28
@@ -25,8 +25,6 @@ use App\Classes\Modules\Transactions\Services\DeletesTransactionDetails;
|
||||
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
|
||||
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionDetailObject;
|
||||
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||
use App\Classes\ValueObjects\Constants\TaxPercentage;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class UpdateShippingInvoiceTransactionLogic extends AbstractControllerLogic
|
||||
{
|
||||
@@ -62,9 +60,9 @@ class UpdateShippingInvoiceTransactionLogic extends AbstractControllerLogic
|
||||
|
||||
/** @var DeletesTransactionDetails */
|
||||
private $deletesTransactionDetails;
|
||||
|
||||
|
||||
public function __construct(
|
||||
FetchesPackingList $fetchesPackingList,
|
||||
FetchesPackingList $fetchesPackingList,
|
||||
FetchesTransaction $fetchesTransaction,
|
||||
UpdatesTransaction $updatesTransaction,
|
||||
FetchesTransactionDetail $fetchesTransactionDetail,
|
||||
@@ -107,25 +105,11 @@ class UpdateShippingInvoiceTransactionLogic extends AbstractControllerLogic
|
||||
$transaction_detail = (object) $transaction_detail;
|
||||
|
||||
if(!in_array($transaction_detail->reference, ['SHIPPING_FEE', 'OVER_WEIGHT_CHARGES', 'MIN_CBM_CHARGES'])){
|
||||
$reference = 'CUSTOM_CHARGES';
|
||||
$taxPercentage = TaxPercentage::DEFAULT;
|
||||
|
||||
$dateToCompare = Carbon::parse(env('SST_START_DATE', '2024-04-01 00:00:00'));
|
||||
$shippingInvoiceTransactionCreatedDate = Carbon::parse($invoice_transaction->created_at);
|
||||
if ($shippingInvoiceTransactionCreatedDate->isAfter($dateToCompare)) {
|
||||
$taxPercentage = TaxPercentage::SIX_PERCENT;
|
||||
}
|
||||
|
||||
if($transaction_detail->reference === "PAY_ON_BEHALF"){
|
||||
$reference = "PAY_ON_BEHALF";
|
||||
$taxPercentage = TaxPercentage::NO_TAX;
|
||||
}
|
||||
$object_detail = new TransactionDetailObject(
|
||||
$reference,
|
||||
'CUSTOM_CHARGES',
|
||||
isset($transaction_detail->name) ? $transaction_detail->name : TransactionDetailType::CUSTOM_CHARGES,
|
||||
$transaction_detail->quantity,
|
||||
$transaction_detail->price,
|
||||
$taxPercentage
|
||||
$transaction_detail->price
|
||||
);
|
||||
|
||||
if(isset($transaction_detail->id)){
|
||||
@@ -137,20 +121,20 @@ class UpdateShippingInvoiceTransactionLogic extends AbstractControllerLogic
|
||||
}
|
||||
|
||||
$object = new TransactionObject(
|
||||
$invoice_transaction->bill_no,
|
||||
TransactionType::SHIPPING_INVOICE,
|
||||
1,
|
||||
$invoice_transaction->bill_no,
|
||||
TransactionType::SHIPPING_INVOICE,
|
||||
1,
|
||||
$invoice_transaction->issuer,
|
||||
1,
|
||||
1,
|
||||
PaymentMethodType::CASH,
|
||||
$invoice_transaction->transactionDetails()->sum('amount'),
|
||||
$invoice_transaction->transactionDetails()->sum('amount'),
|
||||
1,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
$invoice_transaction->transactionDetails()->sum('tax_amount'),
|
||||
0,
|
||||
null,
|
||||
null,
|
||||
ApprovalStatus::PENDING_VERIFICATION
|
||||
);
|
||||
|
||||
|
||||
@@ -1,65 +0,0 @@
|
||||
<?php
|
||||
|
||||
|
||||
namespace App\Classes\Modules\Transactions\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Transactions\DataTransferObjects\WaiveTransactionObject;
|
||||
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
|
||||
use App\Classes\Modules\Transactions\Services\UpdatesTransactionIsWaived;
|
||||
use App\Classes\Modules\Transactions\Standards\Rules\CanWaiveTransaction;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class WaiveTransactionLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Waive Transaction',
|
||||
'message' => 'You have successfully waived the transaction'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var FetchesTransaction */
|
||||
private $fetchesTransaction;
|
||||
|
||||
/** @var UpdatesTransactionIsWaived */
|
||||
private $updatesTransactionIsWaived;
|
||||
|
||||
/** @var CanWaiveTransaction */
|
||||
private $canWaiveTransaction;
|
||||
|
||||
|
||||
/**
|
||||
* WaiveTransactionLogic constructor.
|
||||
* @param FetchesTransaction $fetchesTransaction
|
||||
* @param UpdatesTransactionIsWaived $updatesTransactionIsWaived
|
||||
* @param CanWaiveTransaction $canWaiveTransaction
|
||||
*/
|
||||
public function __construct(FetchesTransaction $fetchesTransaction, UpdatesTransactionIsWaived $updatesTransactionIsWaived, CanWaiveTransaction $canWaiveTransaction)
|
||||
{
|
||||
$this->fetchesTransaction = $fetchesTransaction;
|
||||
$this->updatesTransactionIsWaived = $updatesTransactionIsWaived;
|
||||
$this->canWaiveTransaction = $canWaiveTransaction;
|
||||
}
|
||||
|
||||
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$transaction = $this->fetchesTransaction->execute(['id' => $request->route('id')]);
|
||||
|
||||
$object = new WaiveTransactionObject($transaction->id, $transaction->bill_no, $transaction->type, $transaction->status);
|
||||
$this->canWaiveTransaction->passes($object);
|
||||
|
||||
$this->updatesTransactionIsWaived->execute($transaction);
|
||||
Log::info(Auth::user()->email." waive storage invoice charges with bill_no: ".$transaction->bill_no);
|
||||
|
||||
return $this->response([]);
|
||||
}
|
||||
}
|
||||
@@ -18,25 +18,19 @@ class TransactionDetailObject implements DataTransferObject
|
||||
/** @var float|null */
|
||||
private $price;
|
||||
|
||||
/** @var float|null */
|
||||
private $taxPercentage;
|
||||
|
||||
|
||||
/**
|
||||
* TransactionDetailObject constructor.
|
||||
* @param string $reference
|
||||
* @param string $name
|
||||
* @param float $quantity
|
||||
* @param float $price
|
||||
* @param float $taxPercentage
|
||||
*/
|
||||
public function __construct(?string $reference, ?string $name , ?float $quantity, ?float $price, ?float $taxPercentage)
|
||||
public function __construct(?string $reference, ?string $name , ?float $quantity, ?float $price)
|
||||
{
|
||||
$this->reference = $reference;
|
||||
$this->name = $name;
|
||||
$this->quantity = $quantity;
|
||||
$this->price = $price;
|
||||
$this->taxPercentage = $taxPercentage;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,28 +65,9 @@ class TransactionDetailObject implements DataTransferObject
|
||||
return $this->price;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getAmount(): float
|
||||
{
|
||||
return ($this->getQuantity() * $this->getPrice()) + $this->getTaxAmount();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getTaxPercentage(): ?float
|
||||
{
|
||||
return $this->taxPercentage;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
public function getTaxAmount(): float
|
||||
{
|
||||
return ($this->getQuantity() * $this->getPrice()) * $this->getTaxPercentage() / 100;
|
||||
return $this->getQuantity() * $this->getPrice();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user