'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 CreateInvoiceTransactionV2Processor */ private $createInvoiceTransactionProcessor; /** @var SendUserPaymentProofUploadedEmail */ private $sendUserPaymentProofUploadedEmail; /** * CreatePaymentProofDocumentLogic constructor. * @param FetchesTransaction $fetchesTransaction * @param CreatesDocument $createsDocument * @param CreatesFiles $createsFile * @param UpdatesTransactionStatus $updatesTransactionStatus * @param CreateInvoiceTransactionV2Processor $createInvoiceTransactionProcessor */ public function __construct(FetchesTransaction $fetchesTransaction, CreatesDocument $createsDocument, CreatesFiles $createsFile, UpdatesTransactionStatus $updatesTransactionStatus, CreateInvoiceTransactionV2Processor $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, "", null, [ 'generateEInvoice' => false, 'generateEInvoiceWithNormalInvoiceTemplate' => false, 'generateEInvoiceRefund' => false, 'bookingOriginalStatus' => ApprovalStatus::COMPLETED ] ); //cief todo: Prototype Period Lock - Starts $this->updateOrCreateKeyValuePair($transaction->owner->booking, KVPKey::BOOKING_IS_LOCKED, 1); //cief todo: Prototype Period Lock - Ends // 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([]); } private function updateOrCreateKeyValuePair($booking, $key, $value) { $booking->attributesKVP()->updateOrCreate( ['key' => $key], ['value' => $value] ); } }