mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/shipping-portal.git
synced 2026-08-31 02:14:07 +00:00
multiple invoices with one payment SDEV-421
This commit is contained in:
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\Modules\Addresses\ControllersLogic;
|
||||
|
||||
|
||||
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
||||
use App\Classes\Modules\Addresses\Services\UpdatesAddress;
|
||||
use App\Classes\Modules\Addresses\Services\FetchesAddress;
|
||||
use App\Classes\Modules\Addresses\Services\FetchesDistrict;
|
||||
use App\Classes\Modules\Addresses\Standards\Rules\CanUpdateAddress;
|
||||
use App\Classes\Modules\Addresses\DataTransferObjects\AddressObject;
|
||||
use App\Classes\Modules\Contacts\DataTransferObjects\ContactObject;
|
||||
use App\Classes\Modules\Contacts\Processors\CreateContactProcessor;
|
||||
use App\Classes\Modules\Remarks\DataTransferObjects\RemarkObject;
|
||||
use App\Classes\Modules\Remarks\Processors\CreateRemarkProcessor;
|
||||
use App\Classes\ValueObjects\Constants\AddressType;
|
||||
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
||||
use App\Http\Resources\AddressResource;
|
||||
use App\Models\Address;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class UpdateAddressLogic extends AbstractControllerLogic
|
||||
{
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
protected function notification():array {
|
||||
return [
|
||||
'title' => 'Updated Address',
|
||||
'message' => 'You have successfully updated the Address'
|
||||
];
|
||||
}
|
||||
|
||||
/** @var CanUpdateAddress */
|
||||
private $canUpdateAddress;
|
||||
|
||||
/** @var UpdatesAddress */
|
||||
private $updatesAddress;
|
||||
|
||||
/** @var FetchesAddress */
|
||||
private $fetchesAddress;
|
||||
|
||||
/** @var FetchesDistrict */
|
||||
private $fetchesDistrict;
|
||||
|
||||
/** @var CreateContactProcessor */
|
||||
private $createContactProcessor;
|
||||
|
||||
/** @var CreateRemarkProcessor */
|
||||
private $createRemarkProcessor;
|
||||
|
||||
/**
|
||||
* UpdateAddressLogic constructor.
|
||||
* @param CanUpdateAddress $canUpdateAddress
|
||||
* @param UpdatesAddress $updatesAddress
|
||||
* @param FetchesAddress $fetchesAddress
|
||||
* @param FetchesDistrict $fetchesDistrict
|
||||
* @param CreateContactProcessor $createContactProcessor
|
||||
* @param CreateRemarkProcessor $createRemarkProcessor
|
||||
*/
|
||||
public function __construct(CanUpdateAddress $canUpdateAddress, UpdatesAddress $updatesAddress, FetchesAddress $fetchesAddress, FetchesDistrict $fetchesDistrict, CreateContactProcessor $createContactProcessor, CreateRemarkProcessor $createRemarkProcessor)
|
||||
{
|
||||
$this->canUpdateAddress = $canUpdateAddress;
|
||||
$this->updatesAddress = $updatesAddress;
|
||||
$this->fetchesAddress = $fetchesAddress;
|
||||
$this->fetchesDistrict = $fetchesDistrict;
|
||||
$this->createContactProcessor = $createContactProcessor;
|
||||
$this->createRemarkProcessor = $createRemarkProcessor;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
{
|
||||
$district = $this->fetchesDistrict->execute(['id' => $request->input('district_id')]);
|
||||
|
||||
$object = new AddressObject($request->input('street_one'), $request->input('street_two'), $district->country_id, $district->state_id, $district->id, $request->input('post_code'), AddressType::DELIVERY, ApprovalStatus::APPROVED, $request->input('reference'));
|
||||
|
||||
$this->canUpdateAddress->passes($object);
|
||||
|
||||
$address = $this->fetchesAddress->execute(['id' => $request->route('id')]);
|
||||
|
||||
/** @var Address $address */
|
||||
$address = $this->updatesAddress->execute($address, $object);
|
||||
|
||||
$address->contacts()->delete(); $address->remarks()->delete();
|
||||
|
||||
if($request->input('phone')){
|
||||
$contactObject = new ContactObject($request->input('person_in_charge'), $request->input('phone'), '', '');
|
||||
$this->createContactProcessor->execute($contactObject, $address);
|
||||
}
|
||||
|
||||
if($request->input('remark')){
|
||||
$remarkObject = new RemarkObject($request->input('remark'), Auth()->user()->id);
|
||||
$this->createRemarkProcessor->execute($address, $remarkObject);
|
||||
}
|
||||
|
||||
return $this->resourceResponse(new AddressResource($address));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user