Files
exchange-2.0/app/Classes/Modules/Transactions/Processors/CreatePaymentProofDocumentProcessor.php
T

82 lines
3.4 KiB
PHP

<?php
namespace App\Classes\Modules\Transactions\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\Modules\Transactions\Services\UpdatesTransactionStatus;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\DocumentType;
use App\Classes\Jobs\SendUserPaymentProofUploadedEmail;
use App\Models\Transaction;
use App\Models\Document;
use App\Classes\Modules\Transactions\Processors\CreateInvoiceTransactionProcessor;
class CreatePaymentProofDocumentProcessor
{
/** @var CreatesDocument */
private $createsDocument;
/** @var CreatesFiles */
private $createsFile;
/** @var UpdatesTransactionStatus */
private $updatesTransactionStatus;
/** @var CreateInvoiceTransactionProcessor */
private $createInvoiceTransactionProcessor;
/** @var SendUserPaymentProofUploadedEmail */
private $sendUserPaymentProofUploadedEmail;
/**
* CreatePaymentProofDocumentProcessor constructor.
* @param CreatesDocument $createsDocument
* @param CreatesFiles $createsFile
* @param UpdatesTransactionStatus $updatesTransactionStatus
* @param CreateInvoiceTransactionProcessor $createInvoiceTransactionProcessor
* @param SendUserPaymentProofUploadedEmail $sendUserPaymentProofUploadedEmail
*/
public function __construct(CreatesDocument $createsDocument, CreatesFiles $createsFile, UpdatesTransactionStatus $updatesTransactionStatus, CreateInvoiceTransactionProcessor $createInvoiceTransactionProcessor, SendUserPaymentProofUploadedEmail $sendUserPaymentProofUploadedEmail)
{
$this->createsDocument = $createsDocument;
$this->createsFile = $createsFile;
$this->updatesTransactionStatus = $updatesTransactionStatus;
$this->createInvoiceTransactionProcessor = $createInvoiceTransactionProcessor;
$this->sendUserPaymentProofUploadedEmail = $sendUserPaymentProofUploadedEmail;
}
/**
* @param Transaction $transaction
* @param array $files
* @return void
* @throws \App\Classes\Exceptions\MalformedRequestException
*/
public function execute(Transaction $transaction, array $files)
{
$object = new DocumentObject(DocumentType::CURRENCY_VENDOR_PAYMENT_PROOF, $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]);
}
}
}
}