Files
exchange-2.0/app/Classes/Modules/Companies/ControllersLogic/CreateIdentificationDocumentLogic.php
2023-11-19 17:10:33 +08:00

125 lines
5.2 KiB
PHP

<?php
namespace App\Classes\Modules\Companies\ControllersLogic;
use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Companies\Processors\CreateIdentificationDocumentOnShippingProcessor;
use App\Classes\Modules\Companies\Services\FetchesCompany;
use App\Classes\Modules\Companies\Services\UpdatesCompanyStatus;
use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject;
use App\Classes\Modules\Documents\Services\CreatesDocument;
use App\Classes\Modules\Documents\Services\CreatesFiles;
use App\Classes\Modules\PerfexCRM\Processors\NewLeadTaskToPerfexCRMProcessor;
use App\Classes\Modules\Milestones\Processors\CheckMilestonesForRewardProcessor;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\CompanyType;
use App\Classes\ValueObjects\Constants\DocumentType;
use App\Classes\ValueObjects\Constants\Milestones;
use App\Models\Company;
use App\Models\Document;
use App\Models\ShippingCompanyConnection;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
class CreateIdentificationDocumentLogic extends AbstractControllerLogic
{
/**
* @return array
*/
protected function notification():array {
return [
'title' => 'Created Identification Document',
'message' => 'You have successfully created a new identification document'
];
}
/** @var FetchesCompany */
private $fetchesCompany;
/** @var CreatesDocument */
private $createsDocument;
/** @var CreatesFiles */
private $createsFile;
/** @var UpdatesCompanyStatus */
private $updatesCompanyStatus;
/** @var NewLeadTaskToPerfexCRMProcessor */
private $newLeadTaskToPerfexCRMProcessor;
/** @var CheckMilestonesForRewardProcessor */
private $checkMilestonesForRewardProcessor;
/** @var CreateIdentificationDocumentOnShippingProcessor */
private $createIdentificationDocumentOnShippingProcessor;
/**
* CreateIdentificationDocumentLogic constructor.
* @param FetchesCompany $fetchesCompany
* @param CreatesDocument $createsDocument
* @param CreatesFiles $createsFile
* @param UpdatesCompanyStatus $updatesCompanyStatus
* @param NewLeadTaskToPerfexCRMProcessor $newLeadTaskToPerfexCRMProcessor
* @param CheckMilestoneForRewardProcessor $checkMilestonesForRewardProcessor
* @param CreateIdentificationDocumentOnShippingProcessor $createIdentificationDocumentOnShippingProcessor
*/
public function __construct(FetchesCompany $fetchesCompany, CreatesDocument $createsDocument, CreatesFiles $createsFile, UpdatesCompanyStatus $updatesCompanyStatus, NewLeadTaskToPerfexCRMProcessor $newLeadTaskToPerfexCRMProcessor, CheckMilestonesForRewardProcessor $checkMilestonesForRewardProcessor, CreateIdentificationDocumentOnShippingProcessor $createIdentificationDocumentOnShippingProcessor)
{
$this->fetchesCompany = $fetchesCompany;
$this->createsDocument = $createsDocument;
$this->createsFile = $createsFile;
$this->updatesCompanyStatus = $updatesCompanyStatus;
$this->newLeadTaskToPerfexCRMProcessor = $newLeadTaskToPerfexCRMProcessor;
$this->checkMilestonesForRewardProcessor = $checkMilestonesForRewardProcessor;
$this->createIdentificationDocumentOnShippingProcessor = $createIdentificationDocumentOnShippingProcessor;
}
/**
* @param Request $request
* @return JsonResponse
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function logic(Request $request) : JsonResponse
{
if ($request->route('shipping_company_module_id')) {
$company = ShippingCompanyConnection::where('shipping_company_module_id', $request->route('shipping_company_module_id'))->first()->company;
$companyId = $company->id;
} else {
$companyId = $request->route('id');
}
/** @var Company $company */
$company = $this->fetchesCompany->execute(['id' => $companyId]);
$object = new DocumentObject($company->type === CompanyType::COMPANY_BUSINESS ?
DocumentType::SSM_REGISTRATION : DocumentType::IDENTITY_CARD, $request->input('files'),
$request->input('identification_no'), ApprovalStatus::PENDING_VERIFICATION, 'identifications');
/** @var Document $document */
$document = $this->createsDocument->execute($company, $object);
$this->createsFile->execute($document, $object);
$this->updatesCompanyStatus->execute($company, ApprovalStatus::PENDING_VERIFICATION);
if(config('perfexcrm.is_enabled') == 'true'){
$this->newLeadTaskToPerfexCRMProcessor->execute($company);
}
// create identification on shipping if this request not coming from shipping
if (!$request->route('shipping_company_module_id') && $company->shippingCompanyConnection()->first()) {
$this->createIdentificationDocumentOnShippingProcessor->execute($request, $company->id);
}
//cief todo: case study 2
// $user = $company->employees()->first();
// $this->checkMilestonesForRewardProcessor->execute($user, [Milestones::MILESTONE_2]);
return $this->response([]);
}
}