mirror of
https://gitlab.com/CIEFWorldwideSdnBhd/exchange-2.0.git
synced 2026-08-23 06:24:03 +00:00
107 lines
4.7 KiB
PHP
107 lines
4.7 KiB
PHP
<?php
|
|
|
|
namespace App\Classes\Modules\Accounting\ControllersLogic;
|
|
|
|
use App\Classes\General\Abstracts\AbstractControllerLogic;
|
|
use App\Classes\Modules\Accounting\Services\FetchesBankStatementTransaction;
|
|
use App\Http\Resources\BankStatementTransactionResource;
|
|
use App\Classes\Modules\Accounting\Services\UpdatesBankStatementTransactionOwnerStatus;
|
|
use App\Classes\ValueObjects\Constants\ApprovalStatus;
|
|
use App\Classes\ValueObjects\Constants\StatementTransactionOwnerType;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use App\Classes\Modules\Transactions\Services\UpdatesTransactionStatus;
|
|
use App\Classes\Modules\Accounting\Services\FetchesBankStatementDetails;
|
|
use App\Classes\Modules\Accounting\Services\ListsBankStatementDetails;
|
|
use App\Models\StatementTransactionOwner;
|
|
|
|
class ApproveDuplicateBankStatementDetailsStatusLogic extends AbstractControllerLogic
|
|
{
|
|
|
|
/**
|
|
* @return array
|
|
*/
|
|
protected function notification(): array
|
|
{
|
|
return [
|
|
'title' => 'Update Duplicate Bank Statement Details Status',
|
|
'message' => 'You have successfully updated the Statement Transation Status'
|
|
];
|
|
}
|
|
|
|
/** @var ListsBankStatementDetails */
|
|
private $listsBankStatementDetails;
|
|
|
|
/** @var FetchesBankStatementDetails */
|
|
private $fetchesBankStatementDetails;
|
|
|
|
/** @var UpdatesBankStatementTransactionOwnerStatus */
|
|
private $updatesBankStatementTransactionOwnerStatus;
|
|
|
|
/** @var UpdatesTransactionStatus */
|
|
private $updatesTransactionStatus;
|
|
|
|
/**
|
|
* UpdateAnnouncementLogic constructor.
|
|
* @param ListsBankStatementDetails $listsBankStatementDetails
|
|
* @param FetchesBankStatementDetails $fetchesBankStatementDetails
|
|
* @param UpdatesBankStatementTransactionOwnerStatus $updatesBankStatementTransactionOwnerStatus
|
|
* @param UpdatesTransactionStatus $updatesTransactionStatus
|
|
*/
|
|
public function __construct(
|
|
listsBankStatementDetails $listsBankStatementDetails,
|
|
FetchesBankStatementDetails $fetchesBankStatementDetails,
|
|
UpdatesBankStatementTransactionOwnerStatus $updatesBankStatementTransactionOwnerStatus,
|
|
UpdatesTransactionStatus $updatesTransactionStatus
|
|
) {
|
|
$this->listsBankStatementDetails = $listsBankStatementDetails;
|
|
$this->fetchesBankStatementDetails = $fetchesBankStatementDetails;
|
|
$this->updatesBankStatementTransactionOwnerStatus = $updatesBankStatementTransactionOwnerStatus;
|
|
$this->updatesTransactionStatus = $updatesTransactionStatus;
|
|
}
|
|
|
|
/**
|
|
* @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
|
|
{
|
|
$bankSatementDetails = $this->fetchesBankStatementDetails->execute(['id' => $request->route('id')]);
|
|
|
|
$this->updatesBankStatementTransactionOwnerStatus->execute($bankSatementDetails, ApprovalStatus::APPROVED);
|
|
|
|
// todo-new: approve payments status, need to check the owner(if system is shipping, need to api with shipping portal)
|
|
// if ($bankSatementDetails->transaction->type === StatementTransactionOwnerType::SALES) {
|
|
// if ($bankSatementDetails->owner->status === ApprovalStatus::PENDING_VERIFICATION) {
|
|
// $this->updatesTransactionStatus->execute($bankSatementDetails->owner, ApprovalStatus::APPROVED);
|
|
// }
|
|
// }
|
|
|
|
$rejectedBankSatementDetails = $this->listsBankStatementDetails->execute(['id_not' => $request->route('id'), 'owner_id' => $bankSatementDetails->owner_id]);
|
|
|
|
if (count($rejectedBankSatementDetails) == 1) {
|
|
$otherBankStatement = $rejectedBankSatementDetails->first();
|
|
|
|
$otherSetBankStatement = StatementTransactionOwner::where('system', $otherBankStatement->system)->where('owner_type', $otherBankStatement->owner_type)->where('owner_id', $otherBankStatement->owner_id)->get();
|
|
dump($request->route('id'));
|
|
dd($otherSetBankStatement);
|
|
foreach ($otherSetBankStatement as $otherStatement) {
|
|
if ($otherStatement->id == $request->route('id')) {
|
|
$this->updatesBankStatementTransactionOwnerStatus->execute($otherStatement, ApprovalStatus::REJECTED);
|
|
} else {
|
|
$this->updatesBankStatementTransactionOwnerStatus->execute($otherStatement, ApprovalStatus::APPROVED);
|
|
}
|
|
}
|
|
}
|
|
|
|
foreach ($rejectedBankSatementDetails as $statement) {
|
|
$this->updatesBankStatementTransactionOwnerStatus->execute($statement, ApprovalStatus::REJECTED);
|
|
}
|
|
|
|
return $this->response([]);
|
|
}
|
|
}
|