mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-19 12:33:56 +00:00
108 lines
4.2 KiB
PHP
108 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Transactions\ControllersLogic;
|
|
|
|
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
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\Transactions\Services\FetchesTransaction;
|
|
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use App\Classes\ValueObjects\Constants\CompanyType;
|
|
use App\Classes\ValueObjects\Constants\DocumentType;
|
|
use App\Classes\Jobs\SendUserPaymentProofUploadedEmail;
|
|
use App\Models\Company;
|
|
use App\Models\Document;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
|
|
use App\Classes\Modules\Transactions\Processors\CreateInvoiceTransactionProcessor;
|
|
|
|
|
|
class CreatePaymentProofDocumentLogic extends AbstractControllerLogic
|
|
{
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification():array {
|
|
return [
|
|
'title' => 'Payment Proof Document',
|
|
'message' => 'You have successfully submitted your payment proof document'
|
|
];
|
|
}
|
|
|
|
/** @var FetchesTransaction */
|
|
private $fetchesTransaction;
|
|
|
|
/** @var CreatesDocument */
|
|
private $createsDocument;
|
|
|
|
/** @var CreatesFiles */
|
|
private $createsFile;
|
|
|
|
/** @var UpdatesTransactionStatus */
|
|
private $updatesTransactionStatus;
|
|
|
|
/** @var CreateInvoiceTransactionProcessor */
|
|
private $createInvoiceTransactionProcessor;
|
|
|
|
/** @var SendUserPaymentProofUploadedEmail */
|
|
private $sendUserPaymentProofUploadedEmail;
|
|
|
|
/**
|
|
* CreatePaymentProofDocumentLogic constructor.
|
|
* @param FetchesTransaction $fetchesTransaction
|
|
* @param CreatesDocument $createsDocument
|
|
* @param CreatesFiles $createsFile
|
|
* @param UpdatesTransactionStatus $updatesTransactionStatus
|
|
* @param CreateInvoiceTransactionProcessor $createInvoiceTransactionProcessor
|
|
*/
|
|
public function __construct(FetchesTransaction $fetchesTransaction, CreatesDocument $createsDocument, CreatesFiles $createsFile, UpdatesTransactionStatus $updatesTransactionStatus, CreateInvoiceTransactionProcessor $createInvoiceTransactionProcessor, SendUserPaymentProofUploadedEmail $sendUserPaymentProofUploadedEmail)
|
|
{
|
|
$this->fetchesTransaction = $fetchesTransaction;
|
|
$this->createsDocument = $createsDocument;
|
|
$this->createsFile = $createsFile;
|
|
$this->updatesTransactionStatus = $updatesTransactionStatus;
|
|
$this->createInvoiceTransactionProcessor = $createInvoiceTransactionProcessor;
|
|
$this->sendUserPaymentProofUploadedEmail = $sendUserPaymentProofUploadedEmail;
|
|
}
|
|
|
|
/**
|
|
* @param Request $request
|
|
* @return JsonResponse
|
|
* @throws \App\Classes\Exceptions\MalformedRequestException
|
|
*/
|
|
public function logic(Request $request) : JsonResponse
|
|
{
|
|
|
|
$transaction = $this->fetchesTransaction->execute(['id' => $request->route('id')]);
|
|
|
|
$object = new DocumentObject(DocumentType::CURRENCY_VENDOR_PAYMENT_PROOF, $request->input('files'), '', ApprovalStatus::APPROVED, 'china_bank_slip');
|
|
|
|
/** @var Document $document */
|
|
$document = $this->createsDocument->execute($transaction, $object);
|
|
|
|
$file = $this->createsFile->execute($document, $object);
|
|
|
|
$this->updatesTransactionStatus->execute($transaction, ApprovalStatus::APPROVED);
|
|
|
|
$this->createInvoiceTransactionProcessor->execute($transaction->owner->booking);
|
|
|
|
// send email to customer
|
|
// todo: a function to send a proof to the receipiant, they have to give us a email of the receipiant and also need to submiited purchase order
|
|
$companyEmployee = $transaction->owner->booking->company->employees;
|
|
foreach ($companyEmployee as $employee) {
|
|
if (app()->environment('production') || in_array($employee->email, ['cief.enquirycntr@gmail.com', 'tech.ciefmalaysia@gmail.com'])) {
|
|
$this->sendUserPaymentProofUploadedEmail::dispatch($employee, $transaction->owner->booking, $file[0]);
|
|
}
|
|
}
|
|
|
|
return $this->response([]);
|
|
}
|
|
|
|
} |