mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-19 20:44:19 +00:00
Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 741ee423c7 | |||
| e1f5286b59 | |||
| abfd4758c4 | |||
| ba7f9a9efe |
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Exceptions;
|
||||
|
||||
use App\Classes\ValueObjects\Constants\HttpStatus;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
final class ConnectionErrorException extends ServiceApiException {
|
||||
public function __construct(?string $message = null, ?string $exceptionMessage = null, ?string $payload = null, ?string $exceptionTrace = null) {
|
||||
Log::error($message. ": ". $exceptionMessage);
|
||||
if($payload){
|
||||
Log::error('Payload: '.$payload);
|
||||
}
|
||||
if($exceptionTrace){
|
||||
Log::error($exceptionTrace);
|
||||
}
|
||||
parent::__construct($message ?? 'A connection error has occurred. Please check application logs for more information.',
|
||||
HttpStatus::SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Abstracts;
|
||||
|
||||
|
||||
use App\Classes\Exceptions\ErrorException;
|
||||
use App\Classes\Exceptions\InternalServerErrorException;
|
||||
use App\Classes\ValueObjects\Constants\Notifications;
|
||||
use App\Classes\ValueObjects\Constants\HttpStatus;
|
||||
use App\Classes\ValueObjects\Response\ApiResponseObject;
|
||||
use ErrorException as GeneralExceptions;
|
||||
use TypeError;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
abstract class Abstract2ControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
abstract protected function notification(): array;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getNotificationTitle():string {
|
||||
return $this->notification()['title'] ? $this->notification()['title']: Notifications::UNDEFINED['title'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
private function getNotificationMessage():string {
|
||||
return $this->notification()['message'] ? $this->notification()['message']: Notifications::UNDEFINED['message'];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return BinaryFileResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
abstract protected function logic(Request $request) : BinaryFileResponse;
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return BinaryFileResponse
|
||||
*/
|
||||
public function execute(Request $request) : BinaryFileResponse {
|
||||
|
||||
try {
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
$response = $this->logic($request);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return $response;
|
||||
|
||||
} catch (ErrorException|GeneralExceptions|TypeError $exception){
|
||||
abort(404, $exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|null $data
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function response(?array $data = []) : JsonResponse {
|
||||
|
||||
return (new ApiResponseObject($this->getNotificationTitle().' Successful',
|
||||
$this->getNotificationMessage(),
|
||||
HttpStatus::OK_WITH_MESSAGE, $data))->handler();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param JsonResource $resource
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function resourceResponse(JsonResource $resource){
|
||||
return $this->response(['data' => $resource]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ResourceCollection $collection
|
||||
* @return JsonResponse
|
||||
*/
|
||||
public function collectionResponse(ResourceCollection $collection){
|
||||
return $this->response(json_decode($collection->response()->getContent(), true));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,7 +10,7 @@ use App\Classes\General\Interfaces\DataTransferObject;
|
||||
abstract class AbstractRule
|
||||
{
|
||||
|
||||
abstract protected function authorized($object): bool;
|
||||
abstract protected function authorized(): bool;
|
||||
|
||||
abstract protected function validators($object): bool;
|
||||
|
||||
@@ -26,8 +26,8 @@ abstract class AbstractRule
|
||||
*/
|
||||
public function passes(?DataTransferObject $object = null): bool {
|
||||
try {
|
||||
if(!$this->authorized($object)){
|
||||
throw new AccessForbiddenException('You don\'t have permission to perform this action');
|
||||
if(!$this->authorized()){
|
||||
throw new AccessForbiddenException('You don\'t have permission to preform this action');
|
||||
}
|
||||
|
||||
$this->validators($object);
|
||||
@@ -36,11 +36,11 @@ abstract class AbstractRule
|
||||
return true;
|
||||
|
||||
} catch(AccessForbiddenException $exception){
|
||||
throw new AccessForbiddenException('You don\'t have permission to perform this action');
|
||||
throw new AccessForbiddenException('You don\'t have permission to preform this action');
|
||||
} catch(\Exception $exception){
|
||||
throw new RequestValidationException($exception->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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,22 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class HasQuestionnaireGroupIn implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->whereHas('question.questionnaire', function (Builder $query) use ($value) {
|
||||
$query->whereIn('group', $value);
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class IdNext implements Filter
|
||||
{
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('id', '>', $value);
|
||||
}
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class NextMainQuestion implements Filter
|
||||
{
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('next_main_question', $value);
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class PaymentMethodNotIn implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->whereNotIn('payment_method', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class QuestionId implements Filter
|
||||
{
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('question_id', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class QuestionNumber implements Filter
|
||||
{
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('question_number', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class QuestionnaireSetId implements Filter
|
||||
{
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('questionnaire_set_id', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class ShortUrl implements Filter
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('short_url', $value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -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,18 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\General\Eloquent\Filters;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
|
||||
class UserId implements Filter
|
||||
{
|
||||
/**
|
||||
* @param Builder $builder
|
||||
* @param $value
|
||||
* @return Builder|mixed
|
||||
*/
|
||||
public static function apply(Builder $builder, $value)
|
||||
{
|
||||
return $builder->where('user_id', $value);
|
||||
}
|
||||
}
|
||||
@@ -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']);
|
||||
}
|
||||
}
|
||||
@@ -24,11 +24,12 @@ class Helper
|
||||
return array_slice(get_class_methods($className), 1);
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* @param $log
|
||||
* @return none
|
||||
*/
|
||||
static function debugLogger($log){
|
||||
if($log && isset($log['message'])){
|
||||
static function debugLoggerForPerfexCRM($log){
|
||||
if($log){
|
||||
$message = $log['message'];
|
||||
$substring = 'No data were found';
|
||||
if (isset($message)) {
|
||||
|
||||
@@ -3,8 +3,6 @@
|
||||
namespace App\Classes\Jobs;
|
||||
|
||||
use App\Classes\Modules\PerfexCRM\Processors\UpdatePerfexCRMProcessor;
|
||||
use App\Classes\Modules\PerfexCRM\Processors\FetchPerfexCRMInvoiceProcessor;
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
@@ -12,8 +10,6 @@ use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMObject;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\UpdatePerfexCRMInvoiceObject;
|
||||
use App\Classes\Modules\PerfexCRM\DataTransferObjects\FetchPerfexCRMInvoiceObject;
|
||||
|
||||
|
||||
class UpdatePerfexCRM implements ShouldQueue
|
||||
{
|
||||
@@ -22,51 +18,37 @@ class UpdatePerfexCRM implements ShouldQueue
|
||||
/** @var UpdatePerfexCRMObject */
|
||||
private $updatePerfexCRMObject;
|
||||
|
||||
/** @var UpdatePerfexCRMInvoice */
|
||||
private $nextJob;
|
||||
|
||||
/** @var */
|
||||
private $transaction;
|
||||
|
||||
/** @var bool|null */
|
||||
private $shouldCreateInvoice;
|
||||
|
||||
/**
|
||||
* UpdatePerfexCRM constructor.
|
||||
* @param UpdatePerfexCRMObject $updatePerfexCRMObject
|
||||
* @param Transaction $transaction
|
||||
* @param bool|null $shouldCreateInvoice
|
||||
* @param UpdatePerfexCRMInvoice $nextJob
|
||||
* @param $transaction
|
||||
*/
|
||||
public function __construct(UpdatePerfexCRMObject $updatePerfexCRMObject, $transaction, ?bool $shouldCreateInvoice = false)
|
||||
public function __construct(UpdatePerfexCRMObject $updatePerfexCRMObject, $transaction, $nextJob)
|
||||
{
|
||||
$this->updatePerfexCRMObject = $updatePerfexCRMObject;
|
||||
$this->nextJob = $nextJob;
|
||||
$this->transaction = $transaction;
|
||||
$this->shouldCreateInvoice = $shouldCreateInvoice;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
{
|
||||
//To use invoice as a reference to decide whether more tasks should be created
|
||||
$this->updatePerfexCRMObject->setInvoiceId($this->getInvoiceIdOrCreateInvoice());
|
||||
|
||||
$result = (App()->make(UpdatePerfexCRMProcessor::class))->execute($this->updatePerfexCRMObject);
|
||||
if($this->transaction != null && $this->shouldCreateInvoice){
|
||||
if($this->nextJob != null && $this->transaction != null){
|
||||
$updatePerfexCRMInvoiceOject = new UpdatePerfexCRMInvoiceObject(
|
||||
$this->updatePerfexCRMObject->getContactEmail(),
|
||||
$result->projectId,
|
||||
$this->transaction,
|
||||
true
|
||||
);
|
||||
UpdatePerfexCRMInvoice::dispatch($updatePerfexCRMInvoiceOject);
|
||||
/** @var UpdatePerfexCRMInvoice $nextJob */
|
||||
$this->nextJob::dispatch($updatePerfexCRMInvoiceOject);
|
||||
}
|
||||
}
|
||||
|
||||
private function getInvoiceIdOrCreateInvoice(){
|
||||
if($this->transaction != null){
|
||||
$fetchPerfexCRMInvoiceObject = new FetchPerfexCRMInvoiceObject(
|
||||
$this->updatePerfexCRMObject->getContactEmail(),
|
||||
$this->transaction
|
||||
);
|
||||
$invoiceId = (App()->make(FetchPerfexCRMInvoiceProcessor::class))->execute($fetchPerfexCRMInvoiceObject);
|
||||
return $invoiceId;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ class UpdatePerfexCRMInvoice implements ShouldQueue
|
||||
|
||||
/**
|
||||
* CreatePerfexCRMSingleTask constructor.
|
||||
* @param UpdatePerfexCRMInvoiceObject $updatePerfexCRMInvoiceObject
|
||||
* @param UpdatePerfexCRMInvoiceObject $createTaskPerfexCRMObject
|
||||
*/
|
||||
public function __construct(UpdatePerfexCRMInvoiceObject $updatePerfexCRMInvoiceObject)
|
||||
{
|
||||
@@ -47,7 +47,7 @@ class UpdatePerfexCRMInvoice implements ShouldQueue
|
||||
$invoiceId = 0;
|
||||
$invoiceStatus = 0;
|
||||
$invoice = (App()->make(FetchesPerfexCRMInvoice::class))->execute($customer->userid,"INV-", $transaction->owner->bill_no);
|
||||
Log::error('UpdatePerfexCRMInvoice debug bill_no: ' . $transaction->owner->bill_no . ', Project Id: ' . $this->updatePerfexCRMInvoiceObject->getProjectId());
|
||||
Log::error(json_encode('UpdatePerfexCRMInvoice debug $transaction->owner->bill_no: '.$transaction->owner->bill_no));
|
||||
|
||||
if(is_null($invoice)){
|
||||
$result = (App()->make(CreatePerfexCRMInvoiceProcessor::class))->execute($transaction->owner, $this->updatePerfexCRMInvoiceObject->getIsPaid());
|
||||
@@ -55,7 +55,7 @@ class UpdatePerfexCRMInvoice implements ShouldQueue
|
||||
$invoiceId = $result->payload['id'];
|
||||
} else {
|
||||
// Log::error(json_encode('UpdatePerfexCRMInvoice CreatePerfexCRMInvoiceProcessor failed'));
|
||||
Helper::debugLogger('UpdatePerfexCRMInvoice CreatePerfexCRMInvoiceProcessor failed');
|
||||
Helper::debugLoggerForPerfexCRM('UpdatePerfexCRMInvoice CreatePerfexCRMInvoiceProcessor failed');
|
||||
}
|
||||
}
|
||||
else{
|
||||
@@ -64,6 +64,7 @@ class UpdatePerfexCRMInvoice implements ShouldQueue
|
||||
|
||||
//This only run when invoice already exist and the invoice does not have a PAID status
|
||||
if($invoiceStatus != PerfexCRMInvoiceStatus::PAID){
|
||||
Log::error(json_encode('UpdatePerfexCRMInvoice debug $this->updatePerfexCRMInvoiceObject->getProjectId(): '.$this->updatePerfexCRMInvoiceObject->getProjectId()));
|
||||
//update invoice
|
||||
(App()->make(UpdatesPerfexCRMInvoice::class))->execute($invoice, $this->updatePerfexCRMInvoiceObject->getProjectId());
|
||||
}
|
||||
|
||||
@@ -27,22 +27,27 @@ class UpdatePerfexCRMPrelude implements ShouldQueue
|
||||
/** @var UpdatePerfexCRMObject */
|
||||
private $updatePerfexCRMObject;
|
||||
|
||||
/** @var bool|null */
|
||||
private $shouldCreateInvoice;
|
||||
/** @var UpdatePerfexCRM */
|
||||
private $nextJob1;
|
||||
|
||||
/** @var UpdatePerfexCRMInvoice */
|
||||
private $nextJob2;
|
||||
|
||||
/**
|
||||
* UpdatePerfexCRMPrelude constructor.
|
||||
* @param $packingList
|
||||
* @param Transaction $transaction
|
||||
* @param $transaction
|
||||
* @param UpdatePerfexCRMObject $updatePerfexCRMObject
|
||||
* @param bool|null $shouldCreateInvoice
|
||||
* @param UpdatePerfexCRM $nextJob1
|
||||
* @param UpdatePerfexCRMInvoice $nextJob2
|
||||
*/
|
||||
public function __construct($packingList, $transaction, UpdatePerfexCRMObject $updatePerfexCRMObject, ?bool $shouldCreateInvoice = false)
|
||||
public function __construct($packingList, $transaction, UpdatePerfexCRMObject $updatePerfexCRMObject, $nextJob1, $nextJob2)
|
||||
{
|
||||
$this->packingList = $packingList;
|
||||
$this->transaction = $transaction;
|
||||
$this->updatePerfexCRMObject = $updatePerfexCRMObject;
|
||||
$this->shouldCreateInvoice = $shouldCreateInvoice;
|
||||
$this->nextJob1 = $nextJob1;
|
||||
$this->nextJob2 = $nextJob2;
|
||||
}
|
||||
|
||||
public function handle()
|
||||
@@ -64,7 +69,9 @@ class UpdatePerfexCRMPrelude implements ShouldQueue
|
||||
|
||||
$result = $this->replacePlaceholders($this->updatePerfexCRMObject->getTasks(), $data);
|
||||
$this->updatePerfexCRMObject->setTasks($result);
|
||||
UpdatePerfexCRM::dispatch($this->updatePerfexCRMObject, $this->transaction, $this->shouldCreateInvoice);
|
||||
/** @var UpdatePerfexCRM $nextJob1 */
|
||||
/** @var UpdatePerfexCRMInvoice $nextJob2 */
|
||||
$this->nextJob1::dispatch($this->updatePerfexCRMObject, $this->transaction, $this->nextJob2);
|
||||
}
|
||||
|
||||
function replacePlaceholders($template, $data, $prefix = '')
|
||||
|
||||
@@ -26,7 +26,7 @@ class CanAuthenticateUser extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -54,4 +54,4 @@ class CanAuthenticateUser extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ class CanCreateUser extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -54,4 +54,4 @@ class CanCreateUser extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ class CanCrossAuthenticateUser extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -51,4 +51,4 @@ class CanCrossAuthenticateUser extends AbstractRule
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ class CanDeleteUser extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -37,4 +37,4 @@ class CanDeleteUser extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ class CanFetchUser extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -39,4 +39,4 @@ class CanFetchUser extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -33,7 +33,7 @@ class CanGeneratePasswordReset extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -62,4 +62,4 @@ class CanGeneratePasswordReset extends AbstractRule
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ class CanListUsers extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -39,4 +39,4 @@ class CanListUsers extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ class CanRegisterUser extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -48,4 +48,4 @@ class CanRegisterUser extends AbstractRule
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ class CanResetPassword extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -62,4 +62,4 @@ class CanResetPassword extends AbstractRule
|
||||
return $this->passwordResetTokenExists->execute($object->getToken());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ class CanUpdateUser extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -54,4 +54,4 @@ class CanUpdateUser extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ class CanCreateAddress extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -54,4 +54,4 @@ class CanCreateAddress extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ class CanDeleteAddress extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -40,4 +40,4 @@ class CanDeleteAddress extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ class CanFetchAddress extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -40,4 +40,4 @@ class CanFetchAddress extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ class CanListAddresses extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -40,4 +40,4 @@ class CanListAddresses extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ class CanUpdateAddress extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -54,4 +54,4 @@ class CanUpdateAddress extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ class CanAssignSegment extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -37,4 +37,4 @@ class CanAssignSegment extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ class CanCreateAnnouncement extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -47,4 +47,4 @@ class CanCreateAnnouncement extends AbstractRule
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ class CanDeleteAnnouncement extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -37,4 +37,4 @@ class CanDeleteAnnouncement extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ class CanListAnnouncements extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -26,7 +26,7 @@ class CanUpdateAnnouncement extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -51,4 +51,4 @@ class CanUpdateAnnouncement extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ class CanCreateBank extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -47,4 +47,4 @@ class CanCreateBank extends AbstractRule
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ class CanDeleteBank extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -37,4 +37,4 @@ class CanDeleteBank extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -12,7 +12,7 @@ class CanListBanks extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
@@ -34,4 +34,4 @@ class CanListBanks extends AbstractRule
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ class CanUpdateBank extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -51,4 +51,4 @@ class CanUpdateBank extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,6 @@ 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;
|
||||
@@ -47,9 +46,6 @@ class CallbackBillplzLogic
|
||||
/** @var CreatePaymentTransactionProcessor */
|
||||
private $createPaymentTransactionProcessor;
|
||||
|
||||
/** @var CallbackBillplzProcessor */
|
||||
private $callbackBillplzProcessor;
|
||||
|
||||
/**
|
||||
* CallbackBillplzLogic constructor.
|
||||
* @param GetBillplzBill $getBillplzBill
|
||||
@@ -58,9 +54,8 @@ class CallbackBillplzLogic
|
||||
* @param UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor
|
||||
* @param UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor
|
||||
* @param CreatePaymentTransactionProcessor $createPaymentTransactionProcessor
|
||||
* @param CallbackBillplzProcessor $callbackBillplzProcessor
|
||||
*/
|
||||
public function __construct(GetBillplzBill $getBillplzBill, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor, UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor, UpdatesWalletBalance $updatesWalletBalance, CreatePaymentTransactionProcessor $createPaymentTransactionProcessor, CallbackBillplzProcessor $callbackBillplzProcessor)
|
||||
public function __construct(GetBillplzBill $getBillplzBill, FetchesTransaction $fetchesTransaction, UpdatesTransactionStatus $updatesTransactionStatus, UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor, UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor, UpdatesWalletBalance $updatesWalletBalance, CreatePaymentTransactionProcessor $createPaymentTransactionProcessor)
|
||||
{
|
||||
$this->getBillplzBill = $getBillplzBill;
|
||||
$this->fetchesTransaction = $fetchesTransaction;
|
||||
@@ -69,7 +64,6 @@ class CallbackBillplzLogic
|
||||
$this->updateDoFromYDPortalProcessor = $updateDoFromYDPortalProcessor;
|
||||
$this->updatesWalletBalance = $updatesWalletBalance;
|
||||
$this->createPaymentTransactionProcessor = $createPaymentTransactionProcessor;
|
||||
$this->callbackBillplzProcessor = $callbackBillplzProcessor;
|
||||
}
|
||||
|
||||
|
||||
@@ -112,7 +106,41 @@ class CallbackBillplzLogic
|
||||
$token = Auth::fromUser(User::find(1));
|
||||
$request->headers->set('Authorization', 'Bearer '.$token);
|
||||
|
||||
$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;
|
||||
|
||||
|
||||
@@ -1,98 +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\TransactionType;
|
||||
use App\Classes\ValueObjects\Constants\PaymentMethodType;
|
||||
use App\Classes\Modules\Transactions\Processors\CreatePaymentTransactionProcessor;
|
||||
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;
|
||||
|
||||
class CallbackBillplzProcessor
|
||||
{
|
||||
/** @var UpdatesTransactionStatus */
|
||||
private $updatesTransactionStatus;
|
||||
|
||||
/** @var UpdateDoFromVTPortalProcessor */
|
||||
private $updateDoFromVTPortalProcessor;
|
||||
|
||||
/** @var UpdateDoFromYDPortalProcessor */
|
||||
private $updateDoFromYDPortalProcessor;
|
||||
|
||||
/** @var UpdatesWalletBalance */
|
||||
private $updatesWalletBalance;
|
||||
|
||||
/** @var CreatePaymentTransactionProcessor */
|
||||
private $createPaymentTransactionProcessor;
|
||||
|
||||
/**
|
||||
* CreateUserProcessor constructor.
|
||||
* @param UpdatesTransactionStatus $updatesTransactionStatus
|
||||
* @param UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor
|
||||
* @param UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor
|
||||
* @param UpdatesWalletBalance $updatesWalletBalance
|
||||
* @param CreatePaymentTransactionProcessor $createPaymentTransactionProcessor
|
||||
*/
|
||||
public function __construct(UpdatesTransactionStatus $updatesTransactionStatus, UpdateDoFromVTPortalProcessor $updateDoFromVTPortalProcessor, UpdateDoFromYDPortalProcessor $updateDoFromYDPortalProcessor, UpdatesWalletBalance $updatesWalletBalance, CreatePaymentTransactionProcessor $createPaymentTransactionProcessor)
|
||||
{
|
||||
$this->updatesTransactionStatus = $updatesTransactionStatus;
|
||||
$this->updateDoFromVTPortalProcessor = $updateDoFromVTPortalProcessor;
|
||||
$this->updateDoFromYDPortalProcessor = $updateDoFromYDPortalProcessor;
|
||||
$this->updatesWalletBalance = $updatesWalletBalance;
|
||||
$this->createPaymentTransactionProcessor = $createPaymentTransactionProcessor;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute($transaction, $status)
|
||||
{
|
||||
$invoice = $transaction->owner;
|
||||
$packingList = $invoice->owner;
|
||||
|
||||
$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;
|
||||
$this->createPaymentTransactionProcessor->execute($invoice, PaymentMethodType::WALLET, null);
|
||||
}
|
||||
|
||||
$group->status = $status;
|
||||
$group->save();
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ class CanAssignEmployee extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -51,4 +51,4 @@ class CanAssignEmployee extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ class CanAssignSegment extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -37,4 +37,4 @@ class CanAssignSegment extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ class CanCreateCompany extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -48,4 +48,4 @@ class CanCreateCompany extends AbstractRule
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ class CanCreateCompanyModule extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
|
||||
@@ -13,7 +13,7 @@ class CanFetchCompany extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -40,4 +40,4 @@ class CanFetchCompany extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ class CanListCompanies extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -40,4 +40,4 @@ class CanListCompanies extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ class CanUpdateCompany extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -48,4 +48,4 @@ class CanUpdateCompany extends AbstractRule
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ class CanCreateContact extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -51,4 +51,4 @@ class CanCreateContact extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ class CanCreateCurrency extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -48,4 +48,4 @@ class CanCreateCurrency extends AbstractRule
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ class CanDeleteCurrency extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -36,4 +36,4 @@ class CanDeleteCurrency extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ class CanFetchCurrency extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -37,4 +37,4 @@ class CanFetchCurrency extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ class CanListCurrency extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
|
||||
@@ -38,4 +38,4 @@ class CanListCurrency extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ class CanUpdateCurrency extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -51,4 +51,4 @@ class CanUpdateCurrency extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -24,7 +24,7 @@ class CanCreateRate extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
if (!\Auth::user()->can('add currency_rate')) {
|
||||
@@ -52,4 +52,4 @@ class CanCreateRate extends AbstractRule
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ class CanDeleteRate extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
|
||||
@@ -42,4 +42,4 @@ class CanDeleteRate extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,7 @@ class CanFetchRate extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -40,4 +40,4 @@ class CanFetchRate extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ class CanListRates extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
|
||||
@@ -42,4 +42,4 @@ class CanListRates extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ class CanUpdateRate extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
|
||||
@@ -55,4 +55,4 @@ class CanUpdateRate extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Documents\Processors;
|
||||
|
||||
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
|
||||
use App\Classes\Modules\Documents\Services\CreatesDocument;
|
||||
use App\Classes\Modules\Documents\Services\CreatesFiles;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Models\Document;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\QAUserAnswerSelected;
|
||||
|
||||
class UploadDocumentForHelpMenuProcessor
|
||||
{
|
||||
|
||||
/** @var CreatesDocument */
|
||||
private $createsDocument;
|
||||
|
||||
/** @var CreatesFiles */
|
||||
private $createsFiles;
|
||||
|
||||
/**
|
||||
* UploadDocumentForHelpMenuProcessor constructor.
|
||||
* @param CreatesDocument $createsDocument
|
||||
* @param CreatesFiles $createsFiles
|
||||
*/
|
||||
public function __construct(CreatesDocument $createsDocument, CreatesFiles $createsFiles)
|
||||
{
|
||||
$this->createsDocument = $createsDocument;
|
||||
$this->createsFiles = $createsFiles;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $filesUpload
|
||||
* @param QAUserAnswerSelected qaUserAnswerSelected
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute($filesUpload, QAUserAnswerSelected $qaUserAnswerSelected) {
|
||||
$object = new DocumentObject("HELP_MENU", $filesUpload,
|
||||
'123456', ApprovalStatus::PENDING_VERIFICATION, 'help_menu'); //cief todo: 123456 cannot be hardcoded
|
||||
|
||||
/** @var Document $document */
|
||||
$document = $this->createsDocument->execute($qaUserAnswerSelected, $object);
|
||||
|
||||
$result = $this->createsFiles->execute($document, $object);
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -12,7 +12,7 @@ class CanApproveDocument extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -36,4 +36,4 @@ class CanApproveDocument extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ class CanCreateDocument extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -50,4 +50,4 @@ class CanCreateDocument extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ class CanCreateFile extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -50,4 +50,4 @@ class CanCreateFile extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ class CanListDocuments extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
|
||||
/*
|
||||
@@ -44,4 +44,4 @@ class CanListDocuments extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ class CanRenderDocument extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -36,4 +36,4 @@ class CanRenderDocument extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@ class CanUpdateDocument extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -50,4 +50,4 @@ class CanUpdateDocument extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ class CanUpdateDocumentReference extends AbstractRule
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
protected function authorized(): bool
|
||||
{
|
||||
// TODO Set Authorization rules
|
||||
return true;
|
||||
@@ -36,4 +36,4 @@ class CanUpdateDocumentReference extends AbstractRule
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Exports\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\Abstract2ControllerLogic;
|
||||
use App\Classes\Modules\Exports\Services\ExportsFeedback;
|
||||
use App\Classes\Modules\Exports\Standards\Rules\CanExportFeedback;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Maatwebsite\Excel\Excel;
|
||||
|
||||
class ExportFeedbackDataLogic extends Abstract2ControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Feedback',
|
||||
'message' => 'You have successfully exported feedback data'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var ExportsFeedback */
|
||||
private $exportsFeedback;
|
||||
|
||||
/** @var CanExportFeedback */
|
||||
private $canExportFeedback;
|
||||
|
||||
/**
|
||||
* ExportFeedbackDataLogic constructor.
|
||||
* @param ExportsFeedback $exportsFeedback
|
||||
* @param CanExportFeedback $canExportFeedback
|
||||
*/
|
||||
public function __construct(ExportsFeedback $exportsFeedback, CanExportFeedback $canExportFeedback)
|
||||
{
|
||||
$this->exportsFeedback = $exportsFeedback;
|
||||
$this->canExportFeedback = $canExportFeedback;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function logic(Request $request) : BinaryFileResponse
|
||||
{
|
||||
$this->canExportFeedback->passes();
|
||||
|
||||
$response = $this->exportsFeedback->download('feedback.xls', Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
|
||||
ob_end_clean();
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,68 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Exports\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\Abstract2ControllerLogic;
|
||||
use App\Classes\Modules\Exports\Standards\Rules\CanExportPackingList;
|
||||
use App\Classes\Modules\Exports\Services\ExportsOnHoldPackingList;
|
||||
use App\Classes\Modules\Exports\Services\ExportsPendingArrangementDeliveryList;
|
||||
use Illuminate\Http\Request;
|
||||
use Symfony\Component\HttpFoundation\BinaryFileResponse;
|
||||
use Maatwebsite\Excel\Excel;
|
||||
|
||||
class ExportPackingListLogic extends Abstract2ControllerLogic
|
||||
{
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved PackingList',
|
||||
'message' => 'You have successfully exported PackingList'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var ExportsOnHoldPackingList */
|
||||
private $exportsOnHoldPackingList;
|
||||
|
||||
/** @var ExportsPendingArrangementDeliveryList */
|
||||
private $exportsPendingArrangementDeliveryList;
|
||||
|
||||
/** @var CanExportPackingList */
|
||||
private $canExportPackingList;
|
||||
|
||||
/**
|
||||
* ExportPackingListLogic constructor.
|
||||
* @param ExportsPendingArrangementDeliveryList $exportsPendingArrangementDeliveryList
|
||||
* @param ExportsOnHoldPackingList $exportsOnHoldPackingList
|
||||
* @param CanExportPackingList $canExportPackingList
|
||||
*/
|
||||
public function __construct(ExportsPendingArrangementDeliveryList $exportsPendingArrangementDeliveryList, ExportsOnHoldPackingList $exportsOnHoldPackingList, CanExportPackingList $canExportPackingList)
|
||||
{
|
||||
$this->exportsPendingArrangementDeliveryList = $exportsPendingArrangementDeliveryList;
|
||||
$this->exportsOnHoldPackingList = $exportsOnHoldPackingList;
|
||||
$this->canExportPackingList = $canExportPackingList;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return Response
|
||||
*/
|
||||
public function logic(Request $request) : BinaryFileResponse
|
||||
{
|
||||
$this->canExportPackingList->passes();
|
||||
$isSetPendingArrangement = $request->header('PendingArrangement');
|
||||
if($isSetPendingArrangement){
|
||||
$response = $this->exportsPendingArrangementDeliveryList->download('packing-list-delivery.xls', Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
|
||||
}
|
||||
else {
|
||||
$response = $this->exportsOnHoldPackingList->download('packing-list-on-hold.xls', Excel::XLS, ['Content-Type' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']);
|
||||
}
|
||||
|
||||
ob_end_clean();
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,17 +15,9 @@ use App\Classes\ValueObjects\Constants\OrderRoleTypes;
|
||||
|
||||
class ExportsArrivedParcel implements WithHeadings, WithHeadingRow, WithMapping, ShouldAutoSize, FromQuery
|
||||
{
|
||||
|
||||
use Exportable;
|
||||
|
||||
private $start_date;
|
||||
private $end_date;
|
||||
|
||||
public function __construct($start_date = null, $end_date = null)
|
||||
{
|
||||
$this->start_date = $start_date;
|
||||
$this->end_date = $end_date;
|
||||
}
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
@@ -34,49 +26,38 @@ class ExportsArrivedParcel implements WithHeadings, WithHeadingRow, WithMapping,
|
||||
'Warehouse',
|
||||
'Cbm',
|
||||
'Description',
|
||||
'Quantity',
|
||||
'quantity',
|
||||
'Received Date',
|
||||
'Recorded On',
|
||||
'Days to Record',
|
||||
'Remarks'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection|mixed
|
||||
*/
|
||||
public function query()
|
||||
{
|
||||
$query = PackingList::with([
|
||||
'owner.companyModule.inviters',
|
||||
'owner.orderRoles',
|
||||
'packages',
|
||||
'transports'
|
||||
])
|
||||
->where('type', '=', 1)
|
||||
->where('status', '=', 2)
|
||||
->where('owner_type', Order::class);
|
||||
|
||||
if (!is_null($this->start_date) && !is_null($this->end_date)) {
|
||||
$query->whereHas('transports', function ($q) {
|
||||
$q->whereBetween('drop_date', [
|
||||
Carbon::parse($this->start_date)->startOfDay(),
|
||||
Carbon::parse($this->end_date)->endOfDay()
|
||||
]);
|
||||
});
|
||||
}
|
||||
|
||||
return $query;
|
||||
return PackingList::where('type', '=', 1)->where('status', '=', 2)->where('owner_type', Order::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $packingList
|
||||
* @return array
|
||||
*/
|
||||
public function map($packingList): array
|
||||
{
|
||||
$order = $packingList->owner;
|
||||
$marking = $order->companyModule->getMarking();
|
||||
$warehouse = $order->orderRoles->firstWhere('role_id', '=', OrderRoleTypes::ORIGIN_WAREHOUSE)->appointee;
|
||||
$cbm = $packingList->packages->sum(function ($package) {
|
||||
return (($package->width / 100) * ($package->height / 100) * ($package->length / 100)) * $package->quantity;
|
||||
|
||||
$connection = $order->companyModule()->first()->inviters()->withPivot('invitee_reference')->first();
|
||||
$marking = $connection ? $connection->pivot->invitee_reference:'';
|
||||
|
||||
$warehouse = $order->orderRoles()->where('role_id', '=', OrderRoleTypes::ORIGIN_WAREHOUSE)->first()->appointee;
|
||||
|
||||
$cbm = $packingList->packages->sum(function($package){
|
||||
return (($package->width / 100) * ($package->height / 100) * ($package->length / 100)) * $package->quantity;
|
||||
});
|
||||
$arrival_date = $packingList->transports->first()->drop_date->format('d-m-Y');
|
||||
$recorded_on = $packingList->created_at->format('d-m-Y');
|
||||
$days_to_record = Carbon::parse($arrival_date)->diffInDays(Carbon::parse($recorded_on));
|
||||
|
||||
$arrival_date = $packingList->transports()->first()->drop_date->format('d-m-Y');
|
||||
|
||||
return [
|
||||
$packingList->owner->reference,
|
||||
@@ -86,9 +67,7 @@ class ExportsArrivedParcel implements WithHeadings, WithHeadingRow, WithMapping,
|
||||
$packingList->packages->implode('description', ', '),
|
||||
$packingList->packages->sum('quantity'),
|
||||
$arrival_date,
|
||||
$recorded_on,
|
||||
$days_to_record,
|
||||
''
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,108 +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:
|
||||
$booking = Transaction::where('payment_reference', $transaction->bill_no)->first()->owner;
|
||||
|
||||
if (!$booking) {
|
||||
$description = 'Payment for unknown booking, please contact tech support.';
|
||||
break;
|
||||
}
|
||||
|
||||
$marking = $booking->marking;
|
||||
$description = 'Payment For booking refs' . $marking;
|
||||
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, '.', ',')
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Exports\Services;
|
||||
|
||||
use App\Models\QAUserAnswerSelected;
|
||||
use Maatwebsite\Excel\Concerns\Exportable;
|
||||
use Maatwebsite\Excel\Concerns\FromQuery;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadingRow;
|
||||
use Maatwebsite\Excel\Concerns\WithMapping;
|
||||
use Maatwebsite\Excel\Concerns\WithHeadings;
|
||||
use Maatwebsite\Excel\Concerns\ShouldAutoSize;
|
||||
use App\Classes\ValueObjects\Constants\QASystemSourceType;
|
||||
use Carbon\Carbon;
|
||||
|
||||
class ExportsFeedback implements FromQuery, WithHeadings, WithHeadingRow, WithMapping, ShouldAutoSize
|
||||
{
|
||||
|
||||
use Exportable;
|
||||
|
||||
public function headings(): array
|
||||
{
|
||||
return [
|
||||
'Question Set',
|
||||
'Question Text',
|
||||
'Answer',
|
||||
'Source System',
|
||||
'Source Marking',
|
||||
'Source Email',
|
||||
'Created Date'
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Illuminate\Support\Collection|mixed
|
||||
*/
|
||||
public function query()
|
||||
{
|
||||
return QAUserAnswerSelected::whereHas('question', function ($query) {
|
||||
$query->whereHas('questionnaire', function ($innerQuery) {
|
||||
$innerQuery->where('group', 'feedback');
|
||||
})->where('created_at', '>', Carbon::now()->subMonths(1));
|
||||
})->orderBy('created_at', 'desc');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param QAUserAnswerSelected $userAnswer
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function map($userAnswer): array
|
||||
{
|
||||
$source = $userAnswer->userSource;
|
||||
$user = $userAnswer->source_id === 0 ? $userAnswer->user : null;
|
||||
$user_marking = '';
|
||||
if($user){
|
||||
$companyModule = $user->companyModule()->first();
|
||||
$user_marking = $companyModule ? $companyModule->inviters()->withPivot('invitee_reference')->first()->pivot->invitee_reference : "";
|
||||
}
|
||||
|
||||
return [
|
||||
$userAnswer->question->questionnaire->description,
|
||||
$userAnswer->question->question_text,
|
||||
$userAnswer->free_text_answer,
|
||||
$user ? QASystemSourceType::getText(QASystemSourceType::IZYIM) : QASystemSourceType::getText($source->system),
|
||||
$user ? $user_marking : $source->marking,
|
||||
$user ? $user->email : $source->email,
|
||||
Carbon::parse($userAnswer->created_at)->format('d-m-Y'),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,6 @@ class ExportsPaymentTransactions implements FromQuery, WithHeadings, WithHeading
|
||||
'DocNo',
|
||||
'DocDate',
|
||||
'DebtorCode',
|
||||
'Ref',
|
||||
'ShipInfo',
|
||||
'AccNo',
|
||||
'DetailDescription',
|
||||
@@ -127,7 +126,6 @@ class ExportsPaymentTransactions implements FromQuery, WithHeadings, WithHeading
|
||||
$transaction->created_at->format('m/d/Y H:m'),
|
||||
$company->debtor,
|
||||
$order->reference,
|
||||
$order->reference,
|
||||
'500-0000',
|
||||
'X1 Freight Service Charge',
|
||||
$furtherDescription,
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Exports\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\ValueObjects\Constants\RoleTypes;
|
||||
|
||||
class CanExportFeedback extends AbstractRule
|
||||
{
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
if(Auth()->user()){
|
||||
$roleToCheck = Auth()->user()->type;
|
||||
if (in_array($roleToCheck, RoleTypes::ADMIN_ROLES)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Exports\Standards\Rules;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractRule;
|
||||
use App\Classes\ValueObjects\Constants\RoleTypes;
|
||||
|
||||
class CanExportPackingList extends AbstractRule
|
||||
{
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
protected function authorized($object): bool
|
||||
{
|
||||
if(Auth()->user()){
|
||||
$roleToCheck = Auth()->user()->type;
|
||||
if (in_array($roleToCheck, RoleTypes::ADMIN_ROLES)) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function validators($object): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $object
|
||||
* @return bool
|
||||
*/
|
||||
protected function criteria($object): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,62 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\HelpMenu\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\HelpMenu\Standards\Rules\CanFetchHelpMenuQuestion;
|
||||
use App\Classes\Modules\HelpMenu\Processors\FetchFirstQuestionQAProcessor;
|
||||
use App\Http\Resources\HelpMenuQuestionResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
class FetchQuestionQALogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Help Menu First Question',
|
||||
'message' => 'You have successfully retrieved a Help Menu First Question'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanFetchHelpMenuQuestion */
|
||||
private $canFetchHelpMenuQuestion;
|
||||
|
||||
/** @var FetchFirstQuestionQAProcessor */
|
||||
private $fetchFirstQuestionQAProcessor;
|
||||
|
||||
/**
|
||||
* FetchQuestionQALogic constructor.
|
||||
* @param CanFetchHelpMenuQuestion $canFetchHelpMenuQuestion
|
||||
* @param FetchFirstQuestionQAProcessor $fetchFirstQuestionQAProcessor
|
||||
*/
|
||||
public function __construct(CanFetchHelpMenuQuestion $canFetchHelpMenuQuestion, FetchFirstQuestionQAProcessor $fetchFirstQuestionQAProcessor)
|
||||
{
|
||||
$this->canFetchHelpMenuQuestion = $canFetchHelpMenuQuestion;
|
||||
$this->fetchFirstQuestionQAProcessor = $fetchFirstQuestionQAProcessor;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$this->canFetchHelpMenuQuestion->passes();
|
||||
|
||||
$userId = Auth::user()->id;
|
||||
|
||||
$query = $this->fetchFirstQuestionQAProcessor->execute($request);
|
||||
|
||||
return $this->resourceResponse(new HelpMenuQuestionResource($query, $userId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,75 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\HelpMenu\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\HelpMenu\DataTransferObjects\UrlObject;
|
||||
use App\Classes\Modules\HelpMenu\Standards\Rules\CanGenerateFeedbackUrl;
|
||||
use App\Classes\Modules\HelpMenu\Services\CreatesUrl;
|
||||
use App\Classes\Modules\HelpMenu\DataTransferObjects\GenerateFeedbackUrlObject;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class GenerateFeedbackUrlLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Generate Feedback Url',
|
||||
'message' => 'You have successfully generated a feedback url'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanGenerateFeedbackUrl */
|
||||
private $canGenerateFeedbackUrl;
|
||||
|
||||
/** @var CreatesUrl */
|
||||
private $createsUrl;
|
||||
|
||||
/**
|
||||
* GenerateFeedbackUrlLogic constructor.
|
||||
* @param CanGenerateFeedbackUrl $canGenerateFeedbackUrl
|
||||
* @param CreatesUrl $createsUrl
|
||||
*/
|
||||
public function __construct(CanGenerateFeedbackUrl $canGenerateFeedbackUrl, CreatesUrl $createsUrl)
|
||||
{
|
||||
$this->canGenerateFeedbackUrl = $canGenerateFeedbackUrl;
|
||||
$this->createsUrl = $createsUrl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$apiKey = "";
|
||||
if($request->get('apiKeyExist'))
|
||||
{
|
||||
$apiKey = $request->get('apiKeyExist');
|
||||
}
|
||||
$object = new GenerateFeedbackUrlObject($apiKey, $request->input('system'), $request->input('customer_marking'), $request->input('email'), $request->input('question_set'));
|
||||
$this->canGenerateFeedbackUrl->passes($object);
|
||||
|
||||
$shortUrl = Str::random(20);
|
||||
$originalText = $object->getSystem() . '|' . $object->getCustomerMarking(). '|' . $object->getEmail(). '|' . $object->getQuestionSet() . '|' . $shortUrl;
|
||||
$originalUrl = Crypt::encryptString($originalText);
|
||||
|
||||
|
||||
$url = $this->createsUrl->execute(new UrlObject('feedback', $shortUrl, $originalUrl));
|
||||
$resource = ['token' => $url->short_url];
|
||||
|
||||
return $this->response(['data' => $resource]);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\HelpMenu\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\HelpMenu\Services\ListsHelpMenuUserAnswerSelected;
|
||||
use App\Classes\Modules\HelpMenu\Standards\Rules\CanListHelpMenuQuestions;
|
||||
use App\Http\Resources\HelpMenuQuestionsAnswersResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ListQuestionsAnswersQALogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Questions Answers',
|
||||
'message' => 'You have successfully retrieved a list of questions and answers'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanListHelpMenuQuestions */
|
||||
private $canListHelpMenuQuestions;
|
||||
|
||||
/** @var ListsHelpMenuUserAnswerSelected */
|
||||
private $listsHelpMenuUserAnswerSelected;
|
||||
|
||||
/**
|
||||
* ListQuestionsAnswersQALogic constructor.
|
||||
* @param CanListHelpMenuQuestions $canListHelpMenuQuestions
|
||||
* @param ListsHelpMenuUserAnswerSelected $listsHelpMenuUserAnswerSelected
|
||||
*/
|
||||
public function __construct(CanListHelpMenuQuestions $canListHelpMenuQuestions, ListsHelpMenuUserAnswerSelected $listsHelpMenuUserAnswerSelected)
|
||||
{
|
||||
$this->canListHelpMenuQuestions = $canListHelpMenuQuestions;
|
||||
$this->listsHelpMenuUserAnswerSelected = $listsHelpMenuUserAnswerSelected;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @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->canListHelpMenuQuestions->passes();
|
||||
|
||||
$query = $this->listsHelpMenuUserAnswerSelected->execute($this->listsHelpMenuUserAnswerSelected->deserializeFilters($request->input('filters')));
|
||||
|
||||
return $this->collectionResponse(HelpMenuQuestionsAnswersResource::collection($query));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\HelpMenu\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\HelpMenu\Services\ListsHelpMenuQuestions;
|
||||
use App\Classes\Modules\HelpMenu\Services\FetchesUrl;
|
||||
use App\Http\Resources\HelpMenuQuestionResource;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
use App\Classes\Exceptions\ResourceNotFoundException;
|
||||
|
||||
class ListQuestionsQALogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Questions',
|
||||
'message' => 'You have successfully retrieved a list of Questions'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var ListsHelpMenuQuestions */
|
||||
private $listsHelpMenuQuestions;
|
||||
|
||||
/** @var FetchesUrl */
|
||||
private $fetchesUrl;
|
||||
|
||||
/**
|
||||
* ListQuestionsQALogic constructor.
|
||||
* @param ListsHelpMenuQuestions $listsHelpMenuQuestions
|
||||
* @param FetchesUrl $fetchesUrl
|
||||
*/
|
||||
public function __construct(ListsHelpMenuQuestions $listsHelpMenuQuestions, FetchesUrl $fetchesUrl)
|
||||
{
|
||||
$this->listsHelpMenuQuestions = $listsHelpMenuQuestions;
|
||||
$this->fetchesUrl = $fetchesUrl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws \App\Classes\Exceptions\AccessForbiddenException
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
* @throws \App\Classes\Exceptions\RequestValidationException
|
||||
* @throws \App\Classes\Exceptions\ResourceNotFoundException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$url = $this->fetchesUrl->execute(['short_url' => $request->input('token')]);
|
||||
$token = $url->original_url;
|
||||
$decriptedToken = Crypt::decryptString($token);
|
||||
$delimiter = "|";
|
||||
$parts = explode($delimiter, $decriptedToken);
|
||||
$questionSet = $parts[3];
|
||||
$query = $this->listsHelpMenuQuestions->execute(['questionnaire_set_id' => $questionSet]);
|
||||
return $this->collectionResponse(HelpMenuQuestionResource::collection($query));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,89 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\HelpMenu\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\HelpMenu\Processors\SaveAnswerProcessor;
|
||||
use App\Classes\Modules\HelpMenu\Processors\UserSourceForQAProcessor;
|
||||
use App\Classes\Modules\HelpMenu\Services\FetchesUrl;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Crypt;
|
||||
|
||||
class SubmitQAQuestionsLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Feedback Submission',
|
||||
'message' => 'You have successfully submitted yours answers'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var SaveAnswerProcessor */
|
||||
private $saveAnswerProcessor;
|
||||
|
||||
/** @var UserSourceForQAProcessor */
|
||||
private $userSourceForQAProcessor;
|
||||
|
||||
/** @var FetchesUrl */
|
||||
private $fetchesUrl;
|
||||
|
||||
/**
|
||||
* SubmitQAQuestionsLogic constructor.
|
||||
* @param SaveAnswerProcessor $saveAnswerProcessor
|
||||
* @param UserSourceForQAProcessor $userSourceForQAProcessor
|
||||
* @param FetchesUrl $fetchesUrl
|
||||
*/
|
||||
public function __construct(SaveAnswerProcessor $saveAnswerProcessor, UserSourceForQAProcessor $userSourceForQAProcessor, FetchesUrl $fetchesUrl)
|
||||
{
|
||||
$this->saveAnswerProcessor = $saveAnswerProcessor;
|
||||
$this->userSourceForQAProcessor = $userSourceForQAProcessor;
|
||||
$this->fetchesUrl = $fetchesUrl;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws ErrorException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$originalToken = '';
|
||||
$shortToken = $request->input('token');
|
||||
$userId = 0;
|
||||
$sourceId = 0;
|
||||
try {
|
||||
$url = $this->fetchesUrl->execute(['short_url' => $shortToken]);
|
||||
$originalToken = $url->original_url;
|
||||
$decriptedToken = Crypt::decryptString($originalToken);
|
||||
$delimiter = "|";
|
||||
$parts = explode($delimiter, $decriptedToken);
|
||||
$system = $parts[0];
|
||||
$customerMarking = $parts[1];
|
||||
$email = $parts[2];
|
||||
|
||||
$result = $this->userSourceForQAProcessor->execute($system, $customerMarking, $email);
|
||||
$userId = $result['userId'];
|
||||
$sourceId = $result['sourceId'];
|
||||
|
||||
} catch (\Throwable $e) {
|
||||
Log::error($e);
|
||||
}
|
||||
|
||||
$answers = $request->input('answers');
|
||||
foreach ($answers as $answer) {
|
||||
$filesUpload = $request->input('files');
|
||||
$this->saveAnswerProcessor->execute($userId, $sourceId, $answer['questionId'], $answer['answer'], $answer['answerId'], $filesUpload, $shortToken);
|
||||
}
|
||||
|
||||
$response = ['message' => 'Thank you for your feedback.'];
|
||||
return $this->response(['data' => $response]);
|
||||
}
|
||||
}
|
||||
@@ -1,131 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\HelpMenu\ControllersLogic;
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\PerfexCRM\Services\CreatesPerfexCRMSupportTicket;
|
||||
use App\Classes\Modules\PerfexCRM\Services\FetchesPerfexCRMCustomer;
|
||||
use App\Classes\Modules\HelpMenu\Standards\Rules\CanFetchHelpMenuQuestion;
|
||||
use App\Classes\Modules\HelpMenu\Processors\SaveAnswerProcessor;
|
||||
use App\Classes\Modules\HelpMenu\Processors\DeleteAnswerQAProcessor;
|
||||
use App\Classes\Modules\HelpMenu\Processors\FetchNextQuestionQAProcessor;
|
||||
use App\Classes\Modules\HelpMenu\Processors\FetchFirstQuestionQAProcessor;
|
||||
use App\Http\Resources\HelpMenuQuestionResource;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Classes\ValueObjects\Constants\QAType;
|
||||
|
||||
class UpdateNextQuestionQALogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Retrieved Help Menu Next Question',
|
||||
'message' => 'You have successfully retrieved a Help Menu Next Question'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanFetchHelpMenuQuestion */
|
||||
private $canFetchHelpMenuQuestion;
|
||||
|
||||
/** @var SaveAnswerProcessor */
|
||||
private $saveAnswerProcessor;
|
||||
|
||||
/** @var DeleteAnswerQAProcessor */
|
||||
private $deleteAnswerQAProcessor;
|
||||
|
||||
/** @var FetchNextQuestionQAProcessor */
|
||||
private $fetchNextQuestionQAProcessor;
|
||||
|
||||
/** @var FetchFirstQuestionQAProcessor */
|
||||
private $fetchFirstQuestionQAProcessor;
|
||||
|
||||
/** @var CreatesPerfexCRMSupportTicket */
|
||||
private $createsPerfexCRMSupportTicket;
|
||||
|
||||
/** @var FetchesPerfexCRMCustomer */
|
||||
private $fetchesPerfexCRMCustomer;
|
||||
|
||||
/**
|
||||
* UpdateNextQuestionQALogic constructor.
|
||||
* @param CanFetchHelpMenuQuestion $canFetchHelpMenuQuestion
|
||||
* @param SaveAnswerProcessor $saveAnswerProcessor
|
||||
* @param FetchNextQuestionQAProcessor $fetchNextQuestionQAProcessor
|
||||
* @param FetchFirstQuestionQAProcessor $fetchFirstQuestionQAProcessor
|
||||
* @param DeleteAnswerQAProcessor $deleteAnswerQAProcessor
|
||||
*/
|
||||
public function __construct(CanFetchHelpMenuQuestion $canFetchHelpMenuQuestion, SaveAnswerProcessor $saveAnswerProcessor, FetchNextQuestionQAProcessor $fetchNextQuestionQAProcessor, FetchFirstQuestionQAProcessor $fetchFirstQuestionQAProcessor, CreatesPerfexCRMSupportTicket $createsPerfexCRMSupportTicket, FetchesPerfexCRMCustomer $fetchesPerfexCRMCustomer, DeleteAnswerQAProcessor $deleteAnswerQAProcessor)
|
||||
{
|
||||
$this->canFetchHelpMenuQuestion = $canFetchHelpMenuQuestion;
|
||||
$this->saveAnswerProcessor = $saveAnswerProcessor;
|
||||
$this->fetchNextQuestionQAProcessor = $fetchNextQuestionQAProcessor;
|
||||
$this->fetchFirstQuestionQAProcessor = $fetchFirstQuestionQAProcessor;
|
||||
$this->createsPerfexCRMSupportTicket = $createsPerfexCRMSupportTicket;
|
||||
$this->fetchesPerfexCRMCustomer = $fetchesPerfexCRMCustomer;
|
||||
$this->deleteAnswerQAProcessor = $deleteAnswerQAProcessor;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Request $request
|
||||
* @return JsonResponse
|
||||
* @throws MalformedRequestException
|
||||
* @throws ResourceNotFoundException
|
||||
*/
|
||||
public function logic(Request $request) : JsonResponse
|
||||
{
|
||||
$questionId = 0;
|
||||
$userId = Auth::user()->id;
|
||||
$currentQuestion = $request->question;
|
||||
$questionId = $currentQuestion['id'];
|
||||
$questionType = $currentQuestion['question_type'];
|
||||
|
||||
$this->canFetchHelpMenuQuestion->passes();
|
||||
|
||||
//Delete answer
|
||||
$this->deleteAnswerQAProcessor->execute($userId, $questionId, $request);
|
||||
|
||||
//Save answer given by user
|
||||
if (!$request->has('isPrevious')) {
|
||||
$filesUpload = $request->input('files');
|
||||
$answerOptionId = 0;
|
||||
if ($request->has('answerObj')) {
|
||||
$answerOptionId = intval($request->answerObj['id']);
|
||||
}
|
||||
$answerInText = $request->answer;
|
||||
$this->saveAnswerProcessor->execute($userId, 0, $questionId, $answerInText, $answerOptionId, $filesUpload);
|
||||
}
|
||||
|
||||
//Create ticket at crm
|
||||
if (!$request->has('isPrevious')) {
|
||||
if($questionType == QAType::TICKET_CRM){
|
||||
$email = Auth::user()->email;
|
||||
$customer = $this->fetchesPerfexCRMCustomer->execute($email);
|
||||
$subject = "test subject 3";
|
||||
$department = 1;
|
||||
$contactid = 0;
|
||||
$userid = 0;
|
||||
if($customer){
|
||||
$contactid = $customer->id;
|
||||
$userid = $customer->userid;
|
||||
}
|
||||
$this->createsPerfexCRMSupportTicket->execute($subject, $department, $contactid, $userid);
|
||||
}
|
||||
}
|
||||
|
||||
//Get returned question (previous or next)
|
||||
$returnQuestion = $this->fetchNextQuestionQAProcessor->execute($request);
|
||||
//When a questionnaire ended, return back the first question
|
||||
if(is_null($returnQuestion)){
|
||||
$returnQuestion = $this->fetchFirstQuestionQAProcessor->execute($request);
|
||||
}
|
||||
|
||||
return $this->resourceResponse(new HelpMenuQuestionResource($returnQuestion, $userId));
|
||||
}
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\HelpMenu\DataTransferObjects;
|
||||
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class GenerateFeedbackUrlObject implements DataTransferObject
|
||||
{
|
||||
|
||||
/** @var string */
|
||||
private $apiKey;
|
||||
|
||||
/** @var string */
|
||||
private $system;
|
||||
|
||||
/** @var string */
|
||||
private $customerMarking;
|
||||
|
||||
/** @var string */
|
||||
private $email;
|
||||
|
||||
/** @var string */
|
||||
private $questionSet;
|
||||
|
||||
/**
|
||||
* GenerateFeedbackUrlObject constructor.
|
||||
* @param string $apiKey
|
||||
*/
|
||||
public function __construct(string $apiKey = "", ?string $system, ?string $customerMarking, ?string $email, ?string $questionSet)
|
||||
{
|
||||
$this->apiKey = $apiKey;
|
||||
$this->system = $system;
|
||||
$this->customerMarking = $customerMarking;
|
||||
$this->email = $email;
|
||||
$this->questionSet = $questionSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getApiKey(): string
|
||||
{
|
||||
return $this->apiKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSystem(): ?string
|
||||
{
|
||||
return $this->system;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getCustomerMarking(): ?string
|
||||
{
|
||||
return $this->customerMarking;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getEmail(): ?string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getQuestionSet(): ?string
|
||||
{
|
||||
return $this->questionSet;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\HelpMenu\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class QAUserSourceObject implements DataTransferObject
|
||||
{
|
||||
/** @var string */
|
||||
private $system;
|
||||
|
||||
/** @var string */
|
||||
private $marking;
|
||||
|
||||
/** @var string */
|
||||
private $email;
|
||||
|
||||
/**
|
||||
* QAUserSourceObject constructor.
|
||||
* @param string $system
|
||||
* @param string $marking
|
||||
* @param string $email
|
||||
*/
|
||||
public function __construct(string $system, string $marking, string $email)
|
||||
{
|
||||
$this->system = $system;
|
||||
$this->marking = $marking;
|
||||
$this->email = $email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getSystem(): string
|
||||
{
|
||||
return $this->system;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getMarking(): string
|
||||
{
|
||||
return $this->marking;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getEmail(): string
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\HelpMenu\DataTransferObjects;
|
||||
|
||||
use App\Classes\General\Interfaces\DataTransferObject;
|
||||
|
||||
class UrlObject implements DataTransferObject
|
||||
{
|
||||
/** @var string */
|
||||
private $type;
|
||||
|
||||
/** @var string */
|
||||
private $shortUrl;
|
||||
|
||||
/** @var string */
|
||||
private $originalUrl;
|
||||
|
||||
/**
|
||||
* UrlObject constructor.
|
||||
* @param string $type
|
||||
* @param string $shortUrl
|
||||
* @param string $originalUrl
|
||||
*/
|
||||
public function __construct(string $type, string $shortUrl, string $originalUrl)
|
||||
{
|
||||
$this->type = $type;
|
||||
$this->shortUrl = $shortUrl;
|
||||
$this->originalUrl = $originalUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getType(): string
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getShortUrl(): string
|
||||
{
|
||||
return $this->shortUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getOriginalUrl(): string
|
||||
{
|
||||
return $this->originalUrl;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\HelpMenu\Processors;
|
||||
|
||||
use App\Models\QAUserAnswerSelected;
|
||||
use App\Classes\Modules\HelpMenu\Services\FetchesHelpMenuUserAnswerSelected;
|
||||
use App\Classes\Modules\HelpMenu\Services\ListsHelpMenuUserAnswerSelected;
|
||||
|
||||
class DeleteAnswerQAProcessor
|
||||
{
|
||||
/** @var FetchesHelpMenuUserAnswerSelected */
|
||||
private $fetchesHelpMenuUserAnswerSelected;
|
||||
|
||||
/** @var ListsHelpMenuUserAnswerSelected */
|
||||
private $listsHelpMenuUserAnswerSelected;
|
||||
|
||||
/**
|
||||
* DeleteAnswerQAProcessor constructor.
|
||||
* @param FetchesHelpMenuUserAnswerSelected $fetchesHelpMenuUserAnswerSelected
|
||||
* @param ListsHelpMenuUserAnswerSelected $listsHelpMenuUserAnswerSelected
|
||||
*/
|
||||
public function __construct(FetchesHelpMenuUserAnswerSelected $fetchesHelpMenuUserAnswerSelected, ListsHelpMenuUserAnswerSelected $listsHelpMenuUserAnswerSelected)
|
||||
{
|
||||
$this->fetchesHelpMenuUserAnswerSelected = $fetchesHelpMenuUserAnswerSelected;
|
||||
$this->listsHelpMenuUserAnswerSelected = $listsHelpMenuUserAnswerSelected;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $userId
|
||||
* @param int $questionId
|
||||
* @param Request $request
|
||||
* @return void
|
||||
* @throws ResourceNotFoundException
|
||||
*/
|
||||
public function execute($userId, $questionId, $request){
|
||||
if ($request->has('isPrevious')) {
|
||||
//Get current and previous question's answer
|
||||
try{
|
||||
$selectedAnswer = $this->listsHelpMenuUserAnswerSelected->execute(['user_id' => $userId, 'question_id' => $questionId, 'order_by' => (object)['column' => 'id','DESC' => true]])[0];
|
||||
} catch (\Exception $exception){
|
||||
$selectedAnswer = null;
|
||||
}
|
||||
|
||||
if($selectedAnswer)
|
||||
{
|
||||
$this->fetchesHelpMenuUserAnswerSelected->execute(['id' => $selectedAnswer['id']])->delete();
|
||||
}
|
||||
}
|
||||
else{
|
||||
//Delete all answer's belongs to the user
|
||||
$currentQuestion = $request->question;
|
||||
$isStart = $currentQuestion['is_start'];
|
||||
if($isStart){
|
||||
QAUserAnswerSelected::where('user_id', $userId)->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\HelpMenu\Processors;
|
||||
|
||||
use App\Classes\Modules\HelpMenu\Services\FetchesHelpMenuQuestion;
|
||||
use ErrorException;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
|
||||
class FetchFirstQuestionQAProcessor
|
||||
{
|
||||
/** @var FetchesHelpMenuQuestion */
|
||||
private $fetchesHelpMenuQuestion;
|
||||
|
||||
/**
|
||||
* FetchFirstQuestionQAProcessor constructor.
|
||||
* @param FetchesHelpMenuQuestion $fetchesHelpMenuQuestion
|
||||
*/
|
||||
public function __construct(FetchesHelpMenuQuestion $fetchesHelpMenuQuestion)
|
||||
{
|
||||
$this->fetchesHelpMenuQuestion = $fetchesHelpMenuQuestion;
|
||||
}
|
||||
|
||||
public function execute(Request $request){
|
||||
try {
|
||||
$query = $this->fetchesHelpMenuQuestion->execute(['questionnaire_set_id' => $request->route('set_id')]);
|
||||
return $query;
|
||||
} catch (\Exception $exception){
|
||||
throw new ErrorException($exception->getMessage(), $exception->getCode());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,96 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\HelpMenu\Processors;
|
||||
|
||||
use App\Classes\Modules\HelpMenu\Services\FetchesHelpMenuQuestion;
|
||||
use App\Classes\Modules\HelpMenu\Services\FetchesHelpMenuUserAnswerSelected;
|
||||
use App\Classes\Modules\HelpMenu\Services\ListsHelpMenuUserAnswerSelected;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\Classes\ValueObjects\Constants\QAType;
|
||||
|
||||
class FetchNextQuestionQAProcessor
|
||||
{
|
||||
/** @var FetchesHelpMenuQuestion */
|
||||
private $fetchesHelpMenuQuestion;
|
||||
|
||||
/** @var FetchesHelpMenuUserAnswerSelected */
|
||||
private $fetchesHelpMenuUserAnswerSelected;
|
||||
|
||||
/** @var ListsHelpMenuUserAnswerSelected */
|
||||
private $listsHelpMenuUserAnswerSelected;
|
||||
/**
|
||||
* FetchNextQuestionQAProcessor constructor.
|
||||
* @param FetchesHelpMenuQuestion $fetchesHelpMenuQuestion
|
||||
* @param FetchesHelpMenuUserAnswerSelected $fetchesHelpMenuUserAnswerSelected
|
||||
* @param ListsHelpMenuUserAnswerSelected $listsHelpMenuUserAnswerSelected
|
||||
*/
|
||||
public function __construct(FetchesHelpMenuQuestion $fetchesHelpMenuQuestion, FetchesHelpMenuUserAnswerSelected $fetchesHelpMenuUserAnswerSelected, ListsHelpMenuUserAnswerSelected $listsHelpMenuUserAnswerSelected)
|
||||
{
|
||||
$this->fetchesHelpMenuQuestion = $fetchesHelpMenuQuestion;
|
||||
$this->fetchesHelpMenuUserAnswerSelected = $fetchesHelpMenuUserAnswerSelected;
|
||||
$this->listsHelpMenuUserAnswerSelected = $listsHelpMenuUserAnswerSelected;
|
||||
}
|
||||
|
||||
public function execute(Request $request){
|
||||
$isEnd = 0;
|
||||
$questionId = 0;
|
||||
$nextQuestionNumber = 0;
|
||||
$nextNestedQuestion = 0;
|
||||
$nextMainQuestion= 0;
|
||||
$questionnaireSetId = 0;
|
||||
$currentQuestion = $request->question;
|
||||
$questionType = QAType::DEFAULT;
|
||||
$returnQuestion = null;
|
||||
|
||||
if ($currentQuestion && array_key_exists('id', $currentQuestion)) {
|
||||
$questionId = $currentQuestion['id'];
|
||||
$isEnd = $currentQuestion['is_end'];
|
||||
$questionType = $currentQuestion['question_type'];
|
||||
$nextNestedQuestion = $currentQuestion['next_nested_question'];
|
||||
$nextMainQuestion = $currentQuestion['next_main_question'];
|
||||
$questionnaireSetId = $currentQuestion['questionnaire_set_id'];
|
||||
}
|
||||
|
||||
if ($request->has('answerObj')) {
|
||||
$nextQuestionNumber = $request->answerObj['next_question_number'];
|
||||
}
|
||||
|
||||
if ($request->has('isPrevious')) {
|
||||
$userId = Auth::user()->id;
|
||||
$previousAnswer = $this->listsHelpMenuUserAnswerSelected->execute(['user_id' => $userId, 'order_by' => (object)['column' => 'id','DESC' => true]])[0];
|
||||
|
||||
//Get previous question
|
||||
$previousQuestion = $this->fetchesHelpMenuQuestion->execute(['questionnaire_set_id' => $questionnaireSetId, 'id' => $previousAnswer['question_id']]);
|
||||
$returnQuestion = $previousQuestion;
|
||||
}
|
||||
else{
|
||||
//Get next question
|
||||
$nextQuestion = null;
|
||||
$question_number = 0;
|
||||
if($nextQuestionNumber != 0){
|
||||
$question_number = $nextQuestionNumber;
|
||||
}
|
||||
else if($nextNestedQuestion != 0){
|
||||
$question_number = $nextNestedQuestion;
|
||||
}
|
||||
else {
|
||||
$question_number = $nextMainQuestion;
|
||||
}
|
||||
|
||||
if($isEnd){
|
||||
$returnQuestion = null;
|
||||
}
|
||||
else if($question_number != 0){
|
||||
$nextQuestion = $this->fetchesHelpMenuQuestion->execute(['questionnaire_set_id' => $questionnaireSetId, 'question_number' => $question_number]);
|
||||
$returnQuestion = $nextQuestion;
|
||||
}
|
||||
else if (array_key_exists('id', $request->input('question'))) {
|
||||
$nextQuestion = $this->fetchesHelpMenuQuestion->execute(['questionnaire_set_id' => $questionnaireSetId, 'id_next' => $questionId, 'next_main_question' => null]);
|
||||
$returnQuestion = $nextQuestion;
|
||||
}
|
||||
}
|
||||
|
||||
return $returnQuestion;
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\HelpMenu\Processors;
|
||||
|
||||
use App\Models\QAUserAnswerSelected;
|
||||
use App\Classes\Modules\HelpMenu\Services\FetchesHelpMenuUserAnswerSelected;
|
||||
use App\Classes\Modules\Documents\Processors\UploadDocumentForHelpMenuProcessor;
|
||||
|
||||
|
||||
class SaveAnswerProcessor
|
||||
{
|
||||
/** @var FetchesHelpMenuUserAnswerSelected */
|
||||
private $fetchesHelpMenuUserAnswerSelected;
|
||||
|
||||
/** @var UploadDocumentForHelpMenuProcessor */
|
||||
private $uploadDocumentForHelpMenuProcessor;
|
||||
|
||||
/**
|
||||
* SaveAnswerProcessor constructor.
|
||||
* @param FetchesHelpMenuUserAnswerSelected $fetchesHelpMenuUserAnswerSelected
|
||||
* @param UploadDocumentForHelpMenuProcessor $uploadDocumentForHelpMenuProcessor
|
||||
*/
|
||||
public function __construct(FetchesHelpMenuUserAnswerSelected $fetchesHelpMenuUserAnswerSelected, UploadDocumentForHelpMenuProcessor $uploadDocumentForHelpMenuProcessor)
|
||||
{
|
||||
$this->fetchesHelpMenuUserAnswerSelected = $fetchesHelpMenuUserAnswerSelected;
|
||||
$this->uploadDocumentForHelpMenuProcessor = $uploadDocumentForHelpMenuProcessor;
|
||||
}
|
||||
|
||||
public function execute($userId, $sourceId, $questionId, $answerInText, $answerOptionId, $filesUpload, $reference = null){
|
||||
|
||||
$answer = null;
|
||||
// try{
|
||||
// // $answer = $this->fetchesHelpMenuUserAnswerSelected->execute(['user_id' => $userId, 'question_id' => $questionId, 'order_by' => ['column' => 'id','DESC' => 1]]);
|
||||
// $answer = $this->fetchesHelpMenuUserAnswerSelected->execute(['user_id' => $userId, 'user_id' => $sourceId, 'question_id' => $questionId]);
|
||||
// } catch (\Exception $exception){
|
||||
// $answer = null;
|
||||
// }
|
||||
|
||||
if(is_null($answer))
|
||||
{
|
||||
$answer = new QAUserAnswerSelected;
|
||||
}
|
||||
$answer->user_id = $userId;
|
||||
$answer->source_id = $sourceId;
|
||||
$answer->question_id = $questionId;
|
||||
$answer->answer_option_id = intval($answerOptionId);
|
||||
$answer->free_text_answer = $answerInText;
|
||||
if($reference){
|
||||
$answer->reference = $reference;
|
||||
}
|
||||
$answer->save();
|
||||
|
||||
if($filesUpload){
|
||||
$result = $this->uploadDocumentForHelpMenuProcessor->execute($filesUpload, $answer);
|
||||
$newData = array_map(function ($item) {
|
||||
return [
|
||||
'document_id' => $item->document_id,
|
||||
'file_id' => $item->id,
|
||||
];
|
||||
}, $result);
|
||||
$answer->free_text_answer = json_encode($newData);
|
||||
$answer->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\HelpMenu\Processors;
|
||||
|
||||
use App\Classes\Modules\Accounts\Services\FetchesUser;
|
||||
use App\Classes\Modules\HelpMenu\Services\FetchesQAUserSource;
|
||||
use App\Classes\Modules\HelpMenu\Services\CreatesQAUserSource;
|
||||
use App\Classes\ValueObjects\Constants\QASystemSourceType;
|
||||
use App\Classes\Exceptions\ResourceNotFoundException;
|
||||
use App\Classes\Modules\HelpMenu\DataTransferObjects\QAUserSourceObject;
|
||||
|
||||
class UserSourceForQAProcessor
|
||||
{
|
||||
/** @var FetchesUser */
|
||||
private $fetchesUser;
|
||||
|
||||
/** @var FetchesQAUserSource */
|
||||
private $fetchesQAUserSource;
|
||||
|
||||
/** @var CreatesQAUserSource */
|
||||
private $createsQAUserSource;
|
||||
|
||||
|
||||
/**
|
||||
* UserSourceForQAProcessor constructor.
|
||||
* @param FetchesUser $fetchesUser
|
||||
* @param FetchesQAUserSource $fetchesQAUserSource
|
||||
* @param CreatesQAUserSource $createsQAUserSource
|
||||
*/
|
||||
public function __construct(FetchesUser $fetchesUser, FetchesQAUserSource $fetchesQAUserSource, CreatesQAUserSource $createsQAUserSource)
|
||||
{
|
||||
$this->fetchesUser = $fetchesUser;
|
||||
$this->fetchesQAUserSource = $fetchesQAUserSource;
|
||||
$this->createsQAUserSource = $createsQAUserSource;
|
||||
}
|
||||
|
||||
public function execute($system, $customerMarking, $email){
|
||||
$result = [];
|
||||
$isFound = false;
|
||||
if((int)$system === QASystemSourceType::IZYIM){
|
||||
try{
|
||||
$query = $this->fetchesUser->execute(['email' => $email]);
|
||||
$result['userId'] = $query->id;
|
||||
$result['sourceId'] = 0;
|
||||
$isFound = true;
|
||||
} catch (ResourceNotFoundException $exception){
|
||||
$isFound = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(!$isFound){
|
||||
try{
|
||||
$query = $this->fetchesQAUserSource->execute(['email' => $email]);
|
||||
$result['userId'] = 0;
|
||||
$result['sourceId'] = $query->id;
|
||||
} catch (ResourceNotFoundException $exception){
|
||||
$result['sourceId'] = 0;
|
||||
}
|
||||
|
||||
if($result['sourceId'] === 0){
|
||||
$new_object = new QAUserSourceObject($system, $customerMarking, $email);
|
||||
$query = $this->createsQAUserSource->execute($new_object);
|
||||
$result['userId'] = 0;
|
||||
$result['sourceId'] = $query->id;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\HelpMenu\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\HelpMenu\DataTransferObjects\QAUserSourceObject;
|
||||
use App\Models\QAUserSource;
|
||||
|
||||
class CreatesQAUserSource extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param QAUserSourceObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(QAUserSourceObject $object) {
|
||||
$model = new QAUserSource();
|
||||
$model->system = $object->getSystem();
|
||||
$model->marking = $object->getMarking();
|
||||
$model->email = $object->getEmail();
|
||||
|
||||
return $this->handler($model);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\HelpMenu\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractUpdateRecord;
|
||||
use App\Classes\Modules\HelpMenu\DataTransferObjects\UrlObject;
|
||||
use App\Models\Url;
|
||||
|
||||
class CreatesUrl extends AbstractUpdateRecord
|
||||
{
|
||||
/**
|
||||
* @param UrlObject $object
|
||||
* @return \Illuminate\Database\Eloquent\Model
|
||||
* @throws \App\Classes\Exceptions\MalformedRequestException
|
||||
*/
|
||||
public function execute(UrlObject $object) {
|
||||
$model = new Url();
|
||||
$model->type = $object->getType();
|
||||
$model->short_url = $object->getShortUrl();
|
||||
$model->original_url = $object->getOriginalUrl();
|
||||
|
||||
return $this->handler($model);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\HelpMenu\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractFetchRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\QAQuestions;
|
||||
|
||||
class FetchesHelpMenuQuestion extends AbstractFetchRecord
|
||||
{
|
||||
|
||||
/** @var QAQuestions */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* FetchesHelpMenuQuestion constructor.
|
||||
* @param QAQuestions $repository
|
||||
*/
|
||||
public function __construct(QAQuestions $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
public function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\HelpMenu\Services;
|
||||
|
||||
use App\Classes\General\Eloquent\AbstractFetchRecord;
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use App\Models\QAUserAnswerSelected;
|
||||
|
||||
class FetchesHelpMenuUserAnswerSelected extends AbstractFetchRecord
|
||||
{
|
||||
|
||||
/** @var QAUserAnswerSelected */
|
||||
private $repository;
|
||||
|
||||
/**
|
||||
* FetchesHelpMenuUserAnswerSelected constructor.
|
||||
* @param QAUserAnswerSelected $repository
|
||||
*/
|
||||
public function __construct(QAUserAnswerSelected $repository)
|
||||
{
|
||||
$this->repository = $repository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Builder
|
||||
*/
|
||||
public function getRepository(): Builder
|
||||
{
|
||||
return $this->repository->newQuery();
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user