Merge branch 'dillon/90-e-invoice-b' into vapor/development

This commit is contained in:
Dillon Ngo
2025-05-20 00:36:26 +08:00
34 changed files with 711 additions and 108 deletions
@@ -0,0 +1,51 @@
<?php
namespace App\Classes\Modules\Addresses\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Addresses\Services\ListsStates;
use App\Classes\Modules\Addresses\Standards\Rules\CanListAddresses;
use App\Http\Resources\StateResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class ListStatesLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Retrieved States',
'message' => 'You have successfully retrieved a list of States'
];
}
/** @var ListsStates */
private $listsStates;
/**
* ListStatesLogic constructor.
* @param ListsStates $listsStates
*/
public function __construct(ListsStates $listsStates)
{
$this->listsStates = $listsStates;
}
/**
* @param Request $request
* @return JsonResponse
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function logic(Request $request) : JsonResponse
{
$query = $this->listsStates->execute($this->listsStates->deserializeFilters($request->input('filters')));
return $this->collectionResponse(StateResource::collection($query));
}
}
@@ -0,0 +1,33 @@
<?php
namespace App\Classes\Modules\Addresses\Services;
use App\Classes\General\Eloquent\AbstractListRecord;
use App\Models\State;
use Illuminate\Database\Eloquent\Builder;
class ListsStates extends AbstractListRecord
{
/** @var State */
private $repository;
/**
* ListsStates constructor.
* @param State $repository
*/
public function __construct(State $repository)
{
$this->repository = $repository;
}
/**
* @return Builder
*/
function getRepository(): Builder
{
return $this->repository->newQuery();
}
}
@@ -17,14 +17,15 @@ use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
use App\Classes\Modules\Wallets\Services\UpdatesWalletBalance;
use App\Classes\Modules\Currencies\DataTransferObjects\CurrencyConversionObject;
use App\Classes\Modules\Bookings\Services\CalculatesBookingRefundAmount;
use App\Classes\Modules\Rules\DataTransferObjects\ConfirmBookingDTO;
use App\Classes\Modules\Rules\Standards\Rules\CanProceedEInvoicePromptedRule;
use App\Classes\Modules\Rules\Standards\Rules\CanProceedPurchaseOrderRule;
use App\Classes\Modules\Rules\Standards\Rules\CanProceedTINRule;
use App\Classes\Modules\Bookings\DataTransferObjects\ConfirmBookingDTO;
use App\Classes\Modules\Rules\Standards\Rules\CanPassEInvoicePromptedRule;
use App\Classes\Modules\Rules\Standards\Rules\CanPassPurchaseOrderRule;
use App\Classes\Modules\Rules\Standards\Rules\CanPassTINRule;
use App\Classes\Modules\Transactions\Processors\CreateCashBackTransactionProcessor;
use App\Classes\Modules\Vouchers\Processors\Voucherify\BookingToVoucherifyProcessor;
use App\Classes\Modules\Wallets\Services\RecalculatesWalletBalance;
use App\Classes\Modules\Rules\Services\RuleEvaluator;
use App\Classes\Modules\Rules\Standards\Rules\CanPassOrderDurationLimitRule;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\PaymentMethodType;
use App\Classes\ValueObjects\Constants\TransactionType;
@@ -126,9 +127,10 @@ class CreateBookingPaymentLogic extends AbstractControllerLogic
{
$dto = new ConfirmBookingDTO($request->all());
$result = $this->ruleEvaluator->evaluate([
App()->make(CanProceedEInvoicePromptedRule::class),
App()->make(CanProceedTINRule::class),
App()->make(CanProceedPurchaseOrderRule::class),
App()->make(CanPassOrderDurationLimitRule::class),
App()->make(CanPassEInvoicePromptedRule::class),
App()->make(CanPassTINRule::class),
App()->make(CanPassPurchaseOrderRule::class),
], $dto);
if ($result->failed()) {
@@ -1,6 +1,6 @@
<?php
namespace App\Classes\Modules\Rules\DataTransferObjects;
namespace App\Classes\Modules\Bookings\DataTransferObjects;
use App\Classes\General\Interfaces\DataTransferObject;
@@ -118,7 +118,7 @@ class UpdateCompanyDetailsLogic extends AbstractControllerLogic
//Update EInvoice Related Info
if($company->e_invoice){
$district = $this->fetchesDistrict->execute(['id' => $dto->districtId]);
$addObj = new AddressObject($dto->streetOne, $dto->streetTwo, $district->country_id, $district->state_id, $district->id, $dto->postCode);
$addObj = new AddressObject($dto->streetOne, $dto->streetTwo, $district->country_id, $dto->stateId, $district->id, $dto->postCode);
$this->canCreateAddress->passes($addObj);
$address = $this->upsertsAddress->execute($company, $addObj, $dto->addressId);
@@ -12,9 +12,9 @@ use App\Classes\Modules\Addresses\Standards\Rules\CanCreateAddress;
use App\Classes\Modules\Addresses\DataTransferObjects\AddressObject;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Classes\Modules\Companies\Services\UpdatesCompanyEInvoiceInfo;
use App\Classes\Modules\Rules\DataTransferObjects\EInvoiceInfoDTO;
use App\Classes\Modules\Companies\DataTransferObjects\EInvoiceInfoDTO;
use App\Classes\Modules\Rules\Services\RuleEvaluator;
use App\Classes\Modules\Rules\Standards\Rules\CanProceedEInvoicePromptedRule;
use App\Classes\Modules\Rules\Standards\Rules\CanPassEInvoicePromptedRule;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -85,7 +85,7 @@ class UpdateCompanyEInvoiceInfoLogic extends AbstractControllerLogic
{
$dto = new EInvoiceInfoDTO($request->all());
$result = $this->ruleEvaluator->evaluate([
App()->make(CanProceedEInvoicePromptedRule::class),
App()->make(CanPassEInvoicePromptedRule::class),
], $dto);
if ($result->failed()) {
@@ -93,7 +93,7 @@ class UpdateCompanyEInvoiceInfoLogic extends AbstractControllerLogic
}
$district = $this->fetchesDistrict->execute(['id' => $dto->districtId]);
$object = new AddressObject($dto->streetOne, $dto->streetTwo, $district->country_id, $district->state_id, $district->id, $dto->postCode);
$object = new AddressObject($dto->streetOne, $dto->streetTwo, $district->country_id, $dto->stateId, $district->id, $dto->postCode);
//Update Address
$this->canCreateAddress->passes($object);
@@ -6,7 +6,7 @@ namespace App\Classes\Modules\Companies\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Companies\Services\UpdatesCompanyEInvoiceRequest;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Classes\Modules\Rules\DataTransferObjects\EInvoiceRequestDTO;
use App\Classes\Modules\Companies\DataTransferObjects\EInvoiceRequestDTO;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -1,14 +1,15 @@
<?php
namespace App\Classes\Modules\Rules\DataTransferObjects;
namespace App\Classes\Modules\Companies\DataTransferObjects;
use App\Classes\General\Interfaces\DataTransferObject;
class EInvoiceInfoDTO implements DataTransferObject
{
public int $tin;
public string $tin;
public int $msicCode;
public int $districtId;
public int $stateId;
public int $companyId;
public string $streetOne;
public string $streetTwo;
@@ -16,13 +17,14 @@ class EInvoiceInfoDTO implements DataTransferObject
public function __construct(array $data)
{
$this->tin = (int) ($data['tin'] ?? '');
$this->msicCode = (int) ($data['msic_code'] ?? '');
$this->districtId = (int) ($data['district_id'] ?? '');
$this->companyId = (int) ($data['company_id'] ?? '');
$this->tin = (string) ($data['tin'] ?? '');
$this->msicCode = (int) ($data['msic_code'] ?? 0);
$this->districtId = (int) ($data['district_id'] ?? 0);
$this->stateId = (int) ($data['state_id'] ?? 0);
$this->companyId = (int) ($data['company_id'] ?? 0);
$this->streetOne = (string) ($data['street_one'] ?? '');
$this->streetTwo = (string) ($data['street_two'] ?? '');
$this->postCode = (int) ($data['post_code'] ?? '');
$this->postCode = (int) ($data['post_code'] ?? 0);
}
public function toArray(): array
@@ -31,6 +33,7 @@ class EInvoiceInfoDTO implements DataTransferObject
'tin' => $this->tin,
'msic_code' => $this->msicCode,
'district_id' => $this->districtId,
'state_id' => $this->stateId,
'company_id' => $this->companyId,
'street_one' => $this->streetOne,
'street_two' => $this->streetTwo,
@@ -1,6 +1,6 @@
<?php
namespace App\Classes\Modules\Rules\DataTransferObjects;
namespace App\Classes\Modules\Companies\DataTransferObjects;
use App\Classes\General\Interfaces\DataTransferObject;
@@ -12,10 +12,11 @@ class UpdateCompanyDetailsDTO implements DataTransferObject
public string $reference;
public int $type;
public int $tin;
public string $tin;
public int $msicCode;
public int $addressId;
public int $districtId;
public int $stateId;
public int $companyId;
public string $streetOne;
public string $streetTwo;
@@ -29,10 +30,11 @@ class UpdateCompanyDetailsDTO implements DataTransferObject
$this->reference = (string) ($data['reference'] ?? '');
$this->type = (int) ($data['type'] ?? 0);
$this->tin = (int) ($data['tin'] ?? 0);
$this->tin = (string) ($data['tin'] ?? 0);
$this->msicCode = (int) ($data['msic_code'] ?? 0);
$this->addressId = (int) ($data['address_id'] ?? 0);
$this->districtId = (int) ($data['district_id'] ?? 0);
$this->stateId = (int) ($data['state_id'] ?? 0);
$this->companyId = (int) ($data['company_id'] ?? 0);
$this->streetOne = (string) ($data['street_one'] ?? '');
$this->streetTwo = (string) ($data['street_two'] ?? '');
@@ -52,6 +54,7 @@ class UpdateCompanyDetailsDTO implements DataTransferObject
'msic_code' => $this->msicCode,
'address_id' => $this->addressId,
'district_id' => $this->districtId,
'state_id' => $this->stateId,
'company_id' => $this->companyId,
'street_one' => $this->streetOne,
'street_two' => $this->streetTwo,
@@ -7,8 +7,8 @@ use App\Classes\Exceptions\CriteriaNotFulfilledException;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Rules\DataTransferObjects\CheckEInvoiceRuleDTO;
use App\Classes\Modules\Rules\Services\RuleEvaluator;
use App\Classes\Modules\Rules\Standards\Rules\CanProceedEInvoicePromptedRule;
use App\Classes\Modules\Rules\Standards\Rules\CanProceedTINRule;
use App\Classes\Modules\Rules\Standards\Rules\CanPassEInvoicePromptedRule;
use App\Classes\Modules\Rules\Standards\Rules\CanPassTINRule;
use App\Http\Resources\RuleResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -49,8 +49,8 @@ class CheckEInvoiceRuleLogic extends AbstractControllerLogic
$dto = new CheckEInvoiceRuleDTO($request->all());
$result = $this->ruleEvaluator->evaluate([
App()->make(CanProceedEInvoicePromptedRule::class),
App()->make(CanProceedTINRule::class),
App()->make(CanPassEInvoicePromptedRule::class),
App()->make(CanPassTINRule::class),
], $dto);
if ($result->failed()) {
@@ -7,8 +7,9 @@ use App\Classes\Exceptions\CriteriaNotFulfilledException;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Rules\DataTransferObjects\CheckPurchaseOrderRuleDTO;
use App\Classes\Modules\Rules\Services\RuleEvaluator;
use App\Classes\Modules\Rules\Standards\Rules\CanProceedEInvoicePromptedRule;
use App\Classes\Modules\Rules\Standards\Rules\CanProceedPurchaseOrderRule;
use App\Classes\Modules\Rules\Standards\Rules\CanPassEInvoicePromptedRule;
use App\Classes\Modules\Rules\Standards\Rules\CanPassOrderDurationLimitRule;
use App\Classes\Modules\Rules\Standards\Rules\CanPassPurchaseOrderRule;
use App\Http\Resources\RuleResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -49,8 +50,9 @@ class CheckPurchaseOrderRuleLogic extends AbstractControllerLogic
$dto = new CheckPurchaseOrderRuleDTO($request->all());
$result = $this->ruleEvaluator->evaluate([
App()->make(CanProceedEInvoicePromptedRule::class),
App()->make(CanProceedPurchaseOrderRule::class),
App()->make(CanPassOrderDurationLimitRule::class),
App()->make(CanPassEInvoicePromptedRule::class),
App()->make(CanPassPurchaseOrderRule::class),
], $dto);
if ($result->failed()) {
@@ -0,0 +1,60 @@
<?php
namespace App\Classes\Modules\Rules\ControllersLogic;
use App\Classes\Exceptions\CriteriaNotFulfilledException;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Rules\DataTransferObjects\CheckTransferRuleDTO;
use App\Classes\Modules\Rules\Services\RuleEvaluator;
use App\Classes\Modules\Rules\Standards\Rules\CanPassOrderDurationLimitRule;
use App\Http\Resources\RuleResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class CheckTransferRuleLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Rule Check Transfer',
'message' => 'You have successfully passed all rules evaluated'
];
}
/** @var RuleEvaluator */
private $ruleEvaluator;
/**
* CheckTransferRuleLogic constructor.
*/
public function __construct(RuleEvaluator $ruleEvaluator)
{
$this->ruleEvaluator = $ruleEvaluator;
}
/**
* @param Request $request
* @return JsonResponse
* @throws \App\Classes\Exceptions\AccessForbiddenException
* @throws \App\Classes\Exceptions\MalformedRequestException
* @throws \App\Classes\Exceptions\RequestValidationException
* @throws \App\Classes\Exceptions\CriteriaNotFulfilledException
*/
public function logic(Request $request) : JsonResponse
{
$dto = new CheckTransferRuleDTO($request->all());
$result = $this->ruleEvaluator->evaluate([
App()->make(CanPassOrderDurationLimitRule::class),
], $dto);
if ($result->failed()) {
throw new CriteriaNotFulfilledException("- " . implode("<br>- ", $result->messages()));
}
return $this->resourceResponse(new RuleResource((object)$result));
}
}
@@ -0,0 +1,25 @@
<?php
namespace App\Classes\Modules\Rules\DataTransferObjects;
use App\Classes\General\Interfaces\DataTransferObject;
class CheckTransferRuleDTO implements DataTransferObject
{
public int $bookingId;
public int $companyId;
public function __construct(array $data)
{
$this->bookingId = $data['booking_id'];
$this->companyId = $data['company_id'];
}
public function toArray(): array
{
return [
'booking_id' => $this->bookingId,
'company_id' => $this->companyId,
];
}
}
@@ -6,14 +6,14 @@ use App\Classes\Exceptions\CriteriaNotFulfilledException;
use App\Classes\General\Abstracts\AbstractRule;
use App\Classes\Modules\Companies\Services\FetchesCompany;
class CanProceedEInvoicePromptedRule extends AbstractRule
class CanPassEInvoicePromptedRule extends AbstractRule
{
/** @var FetchesCompany */
private $fetchesCompany;
/**
* CanProceedEInvoicePromptedRule constructor.
* CanPassEInvoicePromptedRule constructor.
* @param FetchesCompany $fetchesCompany
*/
public function __construct(FetchesCompany $fetchesCompany)
@@ -48,7 +48,7 @@ class CanProceedEInvoicePromptedRule extends AbstractRule
//Check if account requires E-Invoice
$company = $this->fetchesCompany->execute(['id' => $object->companyId]);
if($company->e_invoice === null){
throw new CriteriaNotFulfilledException("Please refresh page to answer question related to E-Invoice.");
throw new CriteriaNotFulfilledException("Please refresh page and click 'Make Payment' first to answer question related to E-Invoice.");
}
return true;
}
@@ -0,0 +1,67 @@
<?php
namespace App\Classes\Modules\Rules\Standards\Rules;
use App\Classes\Exceptions\CriteriaNotFulfilledException;
use App\Classes\General\Abstracts\AbstractRule;
use App\Classes\Modules\Bookings\Services\FetchesBooking;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Classes\Modules\Bookings\Services\CalculatesBookingPayableAmount;
use App\Classes\Modules\Bookings\Services\CalculatesBookingRefundAmount;
use App\Classes\ValueObjects\Constants\TransactionType;
class CanPassEditingPORule extends AbstractRule
{
/** @var FetchesBooking */
private $fetchesBooking;
/** @var FetchesCompany */
private $fetchesCompany;
/**
* CanPassEditingPORule constructor.
* @param FetchesBooking $fetchesBooking
* @param FetchesCompany $fetchesCompany
*/
public function __construct(FetchesBooking $fetchesBooking, FetchesCompany $fetchesCompany)
{
$this->fetchesBooking = $fetchesBooking;
$this->fetchesCompany = $fetchesCompany;
}
/**
* @return bool
*/
protected function authorized($object): bool
{
return true;
}
/**
* @return bool
*/
protected function validators($object): bool
{
return true;
}
/**
* @return bool
*/
protected function criteria($object): bool
{
//Check if user is allow to edit purchase order
$booking = $this->fetchesBooking->execute(['id' => $object->bookingId]);
$paidAmount = floatval((App()->make(CalculatesBookingPayableAmount::class))->execute($booking, $booking->fix_currency_id)) - floatval((App()->make(CalculatesBookingRefundAmount::class))->execute($booking, $booking->fix_currency_id));
if($paidAmount > 0){
throw new CriteriaNotFulfilledException("Purchase order form is no longer allow to be edited.");
}
return true;
}
}
@@ -0,0 +1,113 @@
<?php
namespace App\Classes\Modules\Rules\Standards\Rules;
use App\Classes\Exceptions\CriteriaNotFulfilledException;
use App\Classes\General\Abstracts\AbstractRule;
use App\Classes\Modules\Bookings\Services\FetchesBooking;
use App\Classes\Modules\Companies\Services\FetchesCompanyPaymentAttemptLimit;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
class CanPassOrderDurationLimitRule extends AbstractRule
{
/** @var FetchesBooking */
private $fetchesBooking;
/** @var FetchesCompanyPaymentAttemptLimit */
private $fetchesCompanyPaymentAttemptLimit;
/**
* CanPassOrderDurationLimitRule constructor.
* @param FetchesBooking $fetchesBooking
* @param FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit
*/
public function __construct(FetchesBooking $fetchesBooking, FetchesCompanyPaymentAttemptLimit $fetchesCompanyPaymentAttemptLimit)
{
$this->fetchesBooking = $fetchesBooking;
$this->fetchesCompanyPaymentAttemptLimit = $fetchesCompanyPaymentAttemptLimit;
}
/**
* @return bool
*/
protected function authorized($object): bool
{
return true;
}
/**
* @return bool
*/
protected function validators($object): bool
{
return true;
}
/**
* @return bool
*/
protected function criteria($object): bool
{
//Check if order is still valid (within duration limit, reused PAYMENT_ATTEMPT_DURATION_LIMIT)
$isExpired = false;
$booking = $this->fetchesBooking->execute(['id' => $object->bookingId]);
$paymentAttemptLimit = $this->fetchesCompanyPaymentAttemptLimit->execute($booking->company);
// $paymentAttemptLimit = 5; //Manual testing must pay in minutes
$createdAt = Carbon::parse($booking->created_at);
$bookingExpiresAt = $createdAt->addMinutes($paymentAttemptLimit);
$now = Carbon::now();
if ($now->greaterThan($bookingExpiresAt)) {
$isExpired = true;
}
$allPayments = $booking->transactions()
->payments()
->get();
if ($isExpired) {
$filteredPayments = $allPayments->filter(function ($payment) use ($bookingExpiresAt) {
return Carbon::parse($payment->created_at)->lessThanOrEqualTo($bookingExpiresAt);
});
if ($filteredPayments->isNotEmpty()) {
// Use the earlier payment to recalculate bookingExpiresAt
$earliestPayment = $filteredPayments->sortBy('created_at')->first();
$newBookingExpiresAt = Carbon::parse($earliestPayment->created_at)->addMinutes($paymentAttemptLimit);
$logDetails = [
'booking_id' => $booking->id,
'initial_created_at' => $booking->created_at,
'original_expiry' => $bookingExpiresAt->toDateTimeString(),
'new_expiry' => $newBookingExpiresAt->toDateTimeString(),
'valid_payments' => []
];
foreach ($filteredPayments as $payment) {
$logDetails['valid_payments'][] = [
'payment_id' => $payment->id,
'created_at' => $payment->created_at,
'amount' => $payment->amount,
];
}
Log::info("Booking initially expired, but found valid pending payment(s).", $logDetails);
$bookingExpiresAt = $newBookingExpiresAt;
$isExpired = Carbon::now()->greaterThan($bookingExpiresAt);
} else {
Log::info("Booking expired and no valid pending payments for booking ID: {$booking->id}");
}
}
if($isExpired){
throw new CriteriaNotFulfilledException("Transfer has already expired.");
}
return true;
}
}
@@ -13,7 +13,7 @@ use App\Classes\ValueObjects\Constants\TransactionType;
use App\Models\ServiceType;
use Illuminate\Support\Facades\Log;
class CanProceedPurchaseOrderRule extends AbstractRule
class CanPassPurchaseOrderRule extends AbstractRule
{
/** @var FetchesBooking */
@@ -23,7 +23,7 @@ class CanProceedPurchaseOrderRule extends AbstractRule
private $fetchesCompany;
/**
* CanProceedPurchaseOrderRule constructor.
* CanPassPurchaseOrderRule constructor.
* @param FetchesBooking $fetchesBooking
* @param FetchesCompany $fetchesCompany
*/
@@ -7,14 +7,14 @@ use App\Classes\Exceptions\CriteriaNotFulfilledException;
use App\Classes\General\Abstracts\AbstractRule;
use App\Classes\Modules\Companies\Services\FetchesCompany;
class CanProceedTINRule extends AbstractRule
class CanPassTINRule extends AbstractRule
{
/** @var FetchesCompany */
private $fetchesCompany;
/**
* CanProceedTINRule constructor.
* CanPassTINRule constructor.
* @param FetchesCompany $fetchesCompany
*/
public function __construct(FetchesCompany $fetchesCompany)
@@ -3,9 +3,11 @@
namespace App\Classes\Modules\Transactions\ControllersLogic;
use App\Classes\Exceptions\CriteriaNotFulfilledException;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Bookings\Services\FetchesBooking;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Classes\Modules\Transactions\DataTransferObjects\CreatePurchaseOrderDTO;
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
use App\Classes\Modules\Transactions\Processors\CreatePurchaseOrderTransactionProcessor;
use App\Classes\Modules\Transactions\Services\CreatesTransaction;
@@ -15,14 +17,18 @@ use App\Classes\Modules\Transactions\Services\FetchesTransaction;
use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
use App\Classes\Modules\Transactions\Services\UpdatesTransaction;
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
use App\Classes\Modules\Rules\Services\RuleEvaluator;
use App\Classes\Modules\Rules\Standards\Rules\CanPassEditingPORule;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\PaymentMethodType;
use App\Classes\ValueObjects\Constants\RoleTypes;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Http\Resources\TransactionResource;
use App\Models\Booking;
use App\Models\Transaction;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class CreatePurchaseOrderTransactionLogic extends AbstractControllerLogic
{
@@ -46,17 +52,27 @@ class CreatePurchaseOrderTransactionLogic extends AbstractControllerLogic
/** @var CreatePurchaseOrderTransactionProcessor */
private $createPurchaseOrderTransactionProcessor;
/** @var RuleEvaluator */
private $ruleEvaluator;
/** @var CanPassEditingPORule */
private $canPassEditingPORule;
/**
* CreatePurchaseOrderTransactionLogic constructor.
* @param FetchesBooking $fetchesBooking
* @param GeneratesTransactionBillNumber $generatesTransactionBillNumber
* @param CreatePurchaseOrderTransactionProcessor $createPurchaseOrderTransactionProcessor
* @param RuleEvaluator $ruleEvaluator
* @param CanPassEditingPORule $canPassEditingPORule
*/
public function __construct(FetchesBooking $fetchesBooking, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatePurchaseOrderTransactionProcessor $createPurchaseOrderTransactionProcessor)
public function __construct(FetchesBooking $fetchesBooking, GeneratesTransactionBillNumber $generatesTransactionBillNumber, CreatePurchaseOrderTransactionProcessor $createPurchaseOrderTransactionProcessor, RuleEvaluator $ruleEvaluator, CanPassEditingPORule $canPassEditingPORule)
{
$this->fetchesBooking = $fetchesBooking;
$this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
$this->createPurchaseOrderTransactionProcessor = $createPurchaseOrderTransactionProcessor;
$this->ruleEvaluator = $ruleEvaluator;
$this->canPassEditingPORule = $canPassEditingPORule;
}
/**
@@ -64,9 +80,21 @@ class CreatePurchaseOrderTransactionLogic extends AbstractControllerLogic
* @param string $id
* @return JsonResponse
* @throws \App\Classes\Exceptions\MalformedRequestException
* @throws \App\Classes\Exceptions\CriteriaNotFulfilledException
*/
public function logic(Request $request, $id = '') : JsonResponse
{
if(!in_array(Auth::user()->type, RoleTypes::ADMIN_ROLES)){
$dto = new CreatePurchaseOrderDTO($request->all());
$result = $this->ruleEvaluator->evaluate([
$this->canPassEditingPORule
], $dto);
if ($result->failed()) {
throw new CriteriaNotFulfilledException("- " . implode("<br>- ", $result->messages()));
}
}
/** @var Booking $booking */
$booking = $this->fetchesBooking->execute(['id' => $request->route('id') ?? $id]);
@@ -105,7 +133,4 @@ class CreatePurchaseOrderTransactionLogic extends AbstractControllerLogic
return $this->resourceResponse(new TransactionResource($transaction));
}
}
@@ -0,0 +1,25 @@
<?php
namespace App\Classes\Modules\Transactions\DataTransferObjects;
use App\Classes\General\Interfaces\DataTransferObject;
class CreatePurchaseOrderDTO implements DataTransferObject
{
public int $bookingId;
public int $companyId;
public function __construct(array $data)
{
$this->bookingId = $data['booking_id'];
$this->companyId = $data['company_id'];
}
public function toArray(): array
{
return [
'booking_id' => $this->bookingId,
'company_id' => $this->companyId,
];
}
}
@@ -0,0 +1,19 @@
<?php
namespace App\Http\Controllers\Addresses;
use App\Classes\Modules\Addresses\ControllersLogic\ListStatesLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class ListStatesController
{
/**
* @param Request $request
* @param ListStatesLogic $logic
* @return JsonResponse
*/
public function list(Request $request, ListStatesLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
@@ -4,6 +4,7 @@ namespace App\Http\Controllers\Rules;
use App\Classes\Modules\Rules\ControllersLogic\CheckEInvoiceRuleLogic;
use App\Classes\Modules\Rules\ControllersLogic\CheckPurchaseOrderRuleLogic;
use App\Classes\Modules\Rules\ControllersLogic\CheckTransferRuleLogic;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -26,4 +27,13 @@ class CheckRuleController
public function checkPurchaseOrderRule(Request $request, CheckPurchaseOrderRuleLogic $logic): JsonResponse {
return $logic->execute($request);
}
/**
* @param Request $request
* @param CheckTransferRuleLogic $logic
* @return JsonResponse
*/
public function checkTransferRule(Request $request, CheckTransferRuleLogic $logic): JsonResponse {
return $logic->execute($request);
}
}
+1 -1
View File
@@ -24,7 +24,7 @@ class EInvoiceInfoResource extends JsonResource
'country' => $this->country,
'billing' => (int) $this->billing,
'msic_code' => (int) $this->msic_code,
'tin' => (int) $this->tin,
'tin' => (string) $this->tin,
'e_invoice' => (int) $this->e_invoice,
];
}
+22
View File
@@ -0,0 +1,22 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class StateResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'state' => $this->name,
];
}
}
+7 -3
View File
@@ -53,15 +53,19 @@ class BookingV2Resource extends JsonResource
'created_at' => Carbon::parse($this->created_at)->format('d-m-Y'),
'created_at_with_time' => Carbon::parse($this->created_at)->format('d-m-Y h:i:s A'),
$this->mergeWhen($this->relationLoaded('transactions'), [
'purchase_order' => new V2\TransactionV2Resource($this->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first()),
'purchase_order' => new V2\TransactionV2Resource(
$this->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first()),
'payment_attempts' => V2\TransactionV2Resource::collection(
$this->transactions()
->payments()->where('status', ApprovalStatus::PENDING_SUBMISSION)
->whereDate('expires_on', '>=', Carbon::now())
->get()
),
'expired_payment_attempts' => V2\TransactionV2Resource::collection($this->transactions()->payments()->where('status', ApprovalStatus::PENDING_SUBMISSION)->whereDate('expires_on', '>=', Carbon::now())->where('expires_on', '>', Carbon::now()->toTimeString())->get()),
'payment_history' => V2\TransactionV2Resource::collection($this->transactions()->where(function($query){
'expired_payment_attempts' => V2\TransactionV2Resource::collection(
$this->transactions()->payments()->where('status', ApprovalStatus::PENDING_SUBMISSION)->whereDate('expires_on', '>=', Carbon::now())->where('expires_on', '>', Carbon::now()->toTimeString())->get()
),
'payment_history' => V2\TransactionV2Resource::collection(
$this->transactions()->where(function($query){
$query->where(function($query){
$query->payments()->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::COMPLETED, ApprovalStatus::REJECTED]);
})->orWhere(function($query){
@@ -32,7 +32,7 @@
<div class="row m-b-15">
<div class="col">
<validation-wrapper-component :validator="$v.parameters.street_one">
<label>Address Line 1</label>
<label>Billing Address Line 1</label>
<input class="form-control" name="street_one" v-model="parameters.street_one">
</validation-wrapper-component>
</div>
@@ -40,7 +40,7 @@
<div class="row m-b-15">
<div class="col">
<validation-wrapper-component :validator="$v.parameters.street_two">
<label>Address Line 2</label>
<label>Billing Address Line 2</label>
<input class="form-control" name="street_two" v-model="parameters.street_two">
</validation-wrapper-component>
</div>
@@ -59,6 +59,14 @@
</validation-wrapper-component>
</div>
</div>
<div class="row m-b-15">
<div class="col-6 p-r-5">
<validation-wrapper-component selectable :validator="$v.parameters.state_id">
<label>State</label>
<selectable-component :endpoint="route('api.address.state.list')" section="stateListSection" valueColumn="id" :labelColumn="['state']" v-model="parameters.state_id"></selectable-component>
</validation-wrapper-component>
</div>
</div>
</div>
</div>
<div class="row m-b-15">
@@ -103,7 +111,7 @@
<div class="col">
<div class="padding-15 bg-master-lightest">
<p class="muted">Billing Address</p>
<p class="m-b-0">{{parameters.street_one}} {{parameters.street_two}}, {{districts[parseFloat(parameters.district_id) - 1].city}} {{parameters.post_code}} {{districts[parseFloat(parameters.district_id) - 1].state.name}}, {{districts[parseFloat(parameters.district_id) - 1].country.name}}</p>
<p class="m-b-0">{{parameters.street_one}} {{parameters.street_two}}, {{districts[parseFloat(parameters.district_id) - 1].city}} {{parameters.post_code}} {{states[parseFloat(parameters.state_id) - 1].state}}, {{districts[parseFloat(parameters.district_id) - 1].country.name}}</p>
</div>
</div>
</div>
@@ -128,68 +136,105 @@
</template>
<script>
import ModalFormHandler from '../../../general/mixins/modalFormHandler';
import { required, helpers } from 'vuelidate/lib/validators'
import { required, minLength, maxLength, alphaNum, helpers } from 'vuelidate/lib/validators'
function mustContainLetterAndNumber(value) {
if (!value) return true;
const hasLetter = /[a-zA-Z]/.test(value);
const hasNumber = /\d/.test(value);
return hasLetter && hasNumber;
}
function notZero(value) {
return value !== 0 && value !== '0' && value !== null && value !== undefined
}
function fiveDigits(value) {
return /^\d{5}$/.test(value)
}
export default {
props: {
id: {
companyId: {
type: Number,
required: true
},
companyType: {
type: Number,
required: true
},
},
watch: {
'id': function() {
this.parameters.company_id = this.id;
this.parameters.company_id = this.companyId;
},
'eInvoiceData': function() {
this.resetForm();
this.parameters = {
company_id: this.id,
street_one: this.eInvoiceData.street_one,
street_two: this.eInvoiceData.street_two,
district_id: this.eInvoiceData.district.id,
post_code: this.eInvoiceData.post_code,
tin: this.eInvoiceData.tin,
msic_code: this.eInvoiceData.msic_code,
}
}
// 'eInvoiceData': function() { //cief todo: 90
// this.resetForm();
// this.parameters = {
// company_id: this.companyId,
// street_one: this.eInvoiceData.street_one,
// street_two: this.eInvoiceData.street_two,
// district_id: this.eInvoiceData.district.id,
// state_id: this.eInvoiceData.state.id,
// post_code: this.eInvoiceData.post_code,
// tin: this.eInvoiceData.tin,
// msic_code: this.eInvoiceData.msic_code,
// }
// }
},
computed: {
districts () {
districts () { //cief todo: 90
return this.$store.getters.getSelectableList('original_districtListSection');
},
states () {
return this.$store.getters.getSelectableList('original_stateListSection');
}
},
data() {
return {
step: 1,
parameters : {
company_id: this.id,
company_id: this.companyId,
street_one: '',
street_two: '',
district_id: '',
state_id: '',
post_code: 0,
tin: '',
msic_code: 0,
}
}
},
validations: {
parameters: {
street_one: { required },
street_two: {},
district_id: { required },
post_code: {
required,
notZero
},
tin: { required },
msic_code: {
required,
notZero
validations() {
const companyType = this.companyType
return {
parameters: {
street_one: { required },
street_two: {},
district_id: { required },
state_id: { required },
post_code: { required, notZero},
tin: {
...(companyType === 0
? {
required,
alphaNum,
minLength: minLength(11),
maxLength: maxLength(13)
}
: {}),
...(companyType === 1
? {
required,
alphaNum,
minLength: minLength(10),
maxLength: maxLength(12)
}
: {})
},
msic_code: {
notZero, fiveDigits
}
}
}
},
@@ -19,7 +19,7 @@
<div class="padding-15 bg-master-lightest">
<p class="muted">Billing Address</p>
<p class="mb-0">
<a class="ml-2" data-toggle="collapse" href="#billingDetails" role="button" aria-expanded="false" aria-controls="billingDetails">
<a data-toggle="collapse" href="#billingDetails" role="button" aria-expanded="false" aria-controls="billingDetails">
{{eInvoiceData.street_one}} {{eInvoiceData.street_two}}, {{eInvoiceData.district.name}}, {{eInvoiceData.post_code}} {{eInvoiceData.state.name}}, {{eInvoiceData.country.name}}
</a>
</p>
@@ -163,7 +163,8 @@
styleType="fill-in" type="requestEInvoiceB" size="large">
<e-invoice-info-form-component
:section="section"
:id="data.company.id"
:company-id="data.company.id"
:company-type="data.company.type"
v-on:eInvoiceInfoUpdated="updatedEInvoiceInfo($event)"
v-on:close="createAddress = !createAddress">
</e-invoice-info-form-component>
@@ -708,7 +709,10 @@
this.calculation = null;
},
successHandler(response, section){ //E-Invoice
if(section === this.section + 'CheckEInvoiceRule'){
if(section === this.section + 'CheckTransferRule'){
this.checkEInvoiceRule();
}
else if(section === this.section + 'CheckEInvoiceRule'){
if(response.payload.data.isPassed){
this.amount = (Math.round((this.data.outstanding_amount + Number.EPSILON) * 100) / 100).toFixed(2);
this.expandPayment = true;
@@ -751,7 +755,8 @@
$('#modal-einvoice-request').modal('show');
}
else{
this.checkEInvoiceRule();
this.checkTransferRule();
// this.checkEInvoiceRule();
}
},
cancelQuotation(){
@@ -799,6 +804,14 @@
}
},
//E-Invoice - Starts
checkTransferRule(){
this.error = '';
this.parameters = {
booking_id: this.data.id,
company_id: this.data.company.id,
};
this.submit(route('api.rule.check.transfer'), 'post', this.section + 'CheckTransferRule', false, true);
},
checkEInvoiceRule(){
this.error = '';
this.parameters = {
@@ -807,7 +820,6 @@
this.submit(route('api.rule.check.einvoice'), 'post', this.section + 'CheckEInvoiceRule', false, true);
},
checkPurchaseOrderRule(){
this.error = '';
this.error = '';
this.parameters = {
booking_id: this.data.id,
@@ -188,12 +188,13 @@
<div class="col" v-if="submitted">
<div class="alert alert-success padding-15" role="alert">
<div class="font-heading fs-12 all-caps bold m-b-15">Your Purchase Order {{data.purchase_order.status === 1 ? 'is Being Processed for Verification' : 'has been Approved' }}</div>
<div class="row m-b-15">
<div class="row m-b-15" v-if="(Math.round((data.paid_amount + Number.EPSILON) * 100) / 100) === 0">
<div class="col">
<div class="font-heading fs-10">If you would like to still edit your Purchase Order you can do that by clicking on the edit button below, but your purchase order verification request will be reset.</div>
</div>
</div>
<button class="btn btn-xs all-caps b-rad-none btn-default bg-master-lightest w-100" @click="submitted = false">Edit Purchase Order</button>
<button class="btn btn-xs all-caps b-rad-none btn-default bg-master-lightest w-100" @click="submitted = false" v-if="(Math.round((data.paid_amount + Number.EPSILON) * 100) / 100) === 0">Edit Purchase Order</button>
<!-- <button class="btn btn-xs all-caps b-rad-none btn-default bg-master-lightest w-100" @click="submitted = false" >Edit Purchase Order</button> -->
<button class="btn btn-xs all-caps b-rad-none btn-complete w-100 m-t-5" v-if="!data.documents.proforma_invoice && data.outstanding_amount != 0" @click="submit(route('api.booking.proforma.create', data.id), 'post', section, true, true)">Generate Proforma Invoice</button>
</div>
</div>
@@ -281,7 +282,9 @@
submitForm(){
this.uploadFiles = false;
this.parameters = {
products: this.products
products: this.products,
booking_id: this.data.id,
company_id: this.data.company.id,
};
this.$emit('update-parameters', {
parameters: this.parameters,
@@ -22,7 +22,7 @@
</validation-wrapper-component>
</div>
</div>
<div class="row m-b-5" v-if="data.e_invoice && data.tin">
<div class="row m-b-5" v-if="data.e_invoice !== null">
<div class="col">
E-Invoice Info
<div class="row m-b-15">
@@ -47,7 +47,7 @@
<div class="row m-b-15">
<div class="col">
<validation-wrapper-component :validator="$v.parameters.street_one">
<label class="text-primary">Address Line 1</label>
<label class="text-primary">Billing Address Line 1</label>
<input class="form-control" name="street_one" v-model="parameters.street_one">
</validation-wrapper-component>
</div>
@@ -55,7 +55,7 @@
<div class="row m-b-15">
<div class="col">
<validation-wrapper-component :validator="$v.parameters.street_two">
<label class="text-primary">Address Line 2</label>
<label class="text-primary">Billing Address Line 2</label>
<input class="form-control" name="street_two" v-model="parameters.street_two">
</validation-wrapper-component>
</div>
@@ -74,6 +74,14 @@
</validation-wrapper-component>
</div>
</div>
<div class="row m-b-15">
<div class="col-6 p-r-5">
<validation-wrapper-component selectable :validator="$v.parameters.state_id">
<label>State</label>
<selectable-component :endpoint="route('api.address.state.list')" section="stateListSection" valueColumn="id" :labelColumn="['state']" v-model="parameters.state_id"></selectable-component>
</validation-wrapper-component>
</div>
</div>
</div>
</div>
@@ -90,23 +98,79 @@
</template>
<script>
import modalFormHandler from '../../../general/mixins/modalFormHandler';
import { required, minLength } from "vuelidate/lib/validators";
import { required, minLength, maxLength, alphaNum, helpers } from 'vuelidate/lib/validators'
function mustContainLetterAndNumber(value) {
if (!value) return true;
const hasLetter = /[a-zA-Z]/.test(value);
const hasNumber = /\d/.test(value);
return hasLetter && hasNumber;
}
function notZero(value) {
return value !== 0 && value !== '0' && value !== null && value !== undefined
}
function fiveDigits(value) {
return /^\d{5}$/.test(value)
}
export default {
validations: {
parameters: {
name: {
required,
},
debtor: {},
tin: {},
msic_code: {},
// validations: {
// parameters: {
// name: {
// required,
// },
// debtor: {},
// tin: {},
// msic_code: {},
address_id: {},
street_one: {},
street_two: {},
district_id: {},
post_code: {},
// address_id: {},
// street_one: {},
// street_two: {},
// district_id: {},
// state_id: {},
// post_code: {},
// }
// },
validations() {
const companyType = this.data.type
return {
parameters: {
name: {
required,
},
debtor: {},
tin: {
...(companyType === 0
? {
required,
alphaNum,
minLength: minLength(11),
maxLength: maxLength(13)
}
: {}),
...(companyType === 1
? {
required,
alphaNum,
minLength: minLength(10),
maxLength: maxLength(12)
}
: {})
},
msic_code: {
notZero, fiveDigits
},
address_id: {},
street_one: { required },
street_two: {},
district_id: { required },
state_id: { required },
post_code: { required, notZero},
}
}
},
created() {
@@ -116,17 +180,19 @@
this.parameters.street_one = this.data.address_einvoice.street_one;
this.parameters.street_two = this.data.address_einvoice.street_two;
this.parameters.district_id = this.data.address_einvoice.district.id;
this.parameters.state_id = this.data.address_einvoice.state.id;
this.parameters.post_code = this.data.address_einvoice.post_code;
}
}
},
watch: {
'data': function(newData) {
'data': function(newData) { //cief todo: 90
if (newData && newData.address_einvoice) {
this.parameters.address_id = newData.address_einvoice.id;
this.parameters.street_one = newData.address_einvoice.street_one;
this.parameters.street_two = newData.address_einvoice.street_two;
this.parameters.district_id = newData.address_einvoice.district.id;
this.parameters.state_id = newData.address_einvoice.state.id;
this.parameters.post_code = newData.address_einvoice.post_code;
}
}
@@ -2,9 +2,14 @@
<div v-if="validator.$error" class="text-danger fs-10">
<small class="bold" v-for="(object, param) in validator.$params">
<span class="btn-block" v-if="object && object.type === 'required'">{{errorMessages[param]}}</span>
<span class="btn-block" v-if="object && object.type === 'maxLength'">{{errorMessages[param]}} {{object.max}} characters</span>
<span class="btn-block" v-if="object && object.type === 'minLength'">{{errorMessages[param]}} {{object.min}} characters</span>
<span class="btn-block" v-if="object && object.type === 'sameAs'">{{errorMessages[param]}} {{object.eq}} field</span>
<span class="btn-block" v-if="object && object.type === 'maxValue'">{{errorMessages[param]}} {{object.max}}</span>
<span class="btn-block" v-if="object && object.type === 'alphaNum'">{{errorMessages[param]}}</span>
<span class="btn-block" v-if="['fiveDigits'].includes(param)">
{{ errorMessages[param] }}
</span>
</small>
</div>
</template>
@@ -14,16 +19,20 @@
props: {
validator: {
required: true
}
},
},
data(){
return {
errorMessages:{
required: 'this field is required',
email: 'enter a valid email address',
maxLength: 'this field must have at most',
minLength: 'this field must have at least',
sameAs: 'this field must match the',
maxValue: 'this value must not exceeds'
maxValue: 'this value must not exceeds',
alphaNum: 'this value must be alphanumeric',
fiveDigits: 'this value must be exactly 5 digits', //custom
// notZero: 'this value cannot be zero',
},
}
},
+3
View File
@@ -1,5 +1,7 @@
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Addresses\ListStatesController;
Route::group(['prefix' => 'address', 'as' => 'address.', 'namespace' => 'Addresses'], function () {
@@ -7,6 +9,7 @@ Route::group(['prefix' => 'address', 'as' => 'address.', 'namespace' => 'Address
Route::get('/list', 'ListAddressesController@list')->name('list');
Route::get('district/list', 'ListDistrictsController@list')->name('district.list');
Route::get('state/list', [ListStatesController::class, 'list'])->name('state.list');
Route::post('/create', 'CreateAddressController@create')->name('create');
+1
View File
@@ -8,4 +8,5 @@ Route::prefix('rule')
->group(function () {
Route::post('/check/eInvoice', [CheckRuleController::class, 'checkEInvoiceRule'])->name('check.einvoice');
Route::post('/check/purchase-order', [CheckRuleController::class, 'checkPurchaseOrderRule'])->name('check.purchase.order');
Route::post('/check/tranfer', [CheckRuleController::class, 'checkTransferRule'])->name('check.transfer');
});