diff --git a/app/Classes/Modules/Accounting/ControllersLogic/GroupApproveStatementTransactionLogic.php b/app/Classes/Modules/Accounting/ControllersLogic/GroupApproveStatementTransactionLogic.php index f9eb9c7b..7ae8a2ae 100644 --- a/app/Classes/Modules/Accounting/ControllersLogic/GroupApproveStatementTransactionLogic.php +++ b/app/Classes/Modules/Accounting/ControllersLogic/GroupApproveStatementTransactionLogic.php @@ -62,7 +62,7 @@ class GroupApproveStatementTransactionLogic extends AbstractControllerLogic $statementTransactions = $this->listsBankStatementTransactions->execute($filters); foreach ($statementTransactions as $statementTransaction) { - $owners = $statementTransaction->owners; + $owners = $statementTransaction->owners()->where('status', ApprovalStatus::PENDING_VERIFICATION)->get(); if (count($owners)) { $this->updatesBankStatementTransactionOwnerStatus->execute($owners->first(), ApprovalStatus::APPROVED); diff --git a/app/Classes/Modules/Accounting/ControllersLogic/ImportCiefLiteStatementLogic.php b/app/Classes/Modules/Accounting/ControllersLogic/ImportCiefLiteStatementLogic.php index 9a909d71..164cb142 100644 --- a/app/Classes/Modules/Accounting/ControllersLogic/ImportCiefLiteStatementLogic.php +++ b/app/Classes/Modules/Accounting/ControllersLogic/ImportCiefLiteStatementLogic.php @@ -7,6 +7,7 @@ use App\Classes\Exceptions\MalformedRequestException; use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject; use App\Classes\ValueObjects\Constants\ApprovalStatus; +use App\Classes\ValueObjects\Constants\StatementTransactionOwnerType; use App\Models\AccountStatement; use App\Models\StatementAccount; use App\Models\StatementTransaction; @@ -45,77 +46,28 @@ class ImportCiefLiteStatementLogic extends AbstractControllerLogic $sheet = $collection->first()->skip(1); - $dateTo = $sheet->first()[10]; - $dateFrom = $sheet->last()[10]; - $totalTransaction = $sheet->count(); - - $offset = 1; - do { - $dateFrom = $sheet->offsetGet($sheet->count() - $offset)[10]; - $offset += 1; - } while(!$dateFrom); - - - $dateFrom = carbon::parse($dateFrom); - $dateTo = carbon::parse($dateTo); - - $statement = AccountStatement::whereDate('date_from', $dateFrom) - ->whereDate('date_to', $dateTo) - ->where('total_amount', $totalTransaction) - ->first(); - - if(!$statement){ - $statement = new AccountStatement([ - 'date_from' => $dateFrom, - 'date_to' => $dateTo, - 'total_amount' => $totalTransaction, - ]); - } - - $account = StatementAccount::where("name", "CIEF LITE")->first(); - - if (!$account) { - throw new Exception("Statement Account for CIEF LITE not found."); - } - - $account->statements()->save($statement); - - $sheet->map(function ($row) use ($statement) { - if (!$row[0]) { + $sheet->map(function ($row) { + if (!$row[0] || trim($row[8]) !== "已审核") { return; } - $postingDate = $row[10]; - $transactionDescription = trim($row[1]); - $description2 = trim($row[2]); - $description3 = "Fee " . $row[6]; - $description4 = trim($row[8]); - $transactionRef = trim($row[12]); + $postingDate =date('Y-m-d', strtotime($row[10])); $amount = ((float) str_replace(',', '', $row[7])); - $transactionCode = $row[0]; - $transaction = new StatementTransaction([ - 'posting_date' => $postingDate, - 'transaction_description' => $transactionDescription, - 'transaction_description_2' => $description2, - 'transaction_description_3' => $description3, - 'transaction_description_4' => $description4, - 'transaction_ref' => $transactionRef, - 'amount' => $amount, - 'transaction_code' => $transactionCode, - ]); + + $statementTransaction = StatementTransaction::whereHas('account', function($query) { + $query->where('statement_accounts.number', 8881040198515); + })->whereDate('posting_date', $postingDate)->where('amount', $amount)->first(); - // Check if the transaction already exists for this statement - $existingTransaction = StatementTransaction::where('transaction_ref', $transactionRef) - ->where('posting_date', $postingDate) - ->where('amount', $amount) - ->where('transaction_description', $transactionDescription) - ->where('transaction_code', $transactionCode) - ->first(); - - if (!$existingTransaction) { - $statement->transactions()->save($transaction); + if (!$statementTransaction) { + return; } - return $transaction; + $owner = $statementTransaction->owners()->firstOrCreate([ + 'type' => StatementTransactionOwnerType::WALLET_TOP_UP, + 'system' => 'LITE', + 'owner_reference'=> $row[0], + ]); + + return $owner; }); } diff --git a/app/Classes/Modules/Accounting/ControllersLogic/UpdateStatementTransactionStatusLogic.php b/app/Classes/Modules/Accounting/ControllersLogic/UpdateStatementTransactionStatusLogic.php index 3a006e9e..55051959 100644 --- a/app/Classes/Modules/Accounting/ControllersLogic/UpdateStatementTransactionStatusLogic.php +++ b/app/Classes/Modules/Accounting/ControllersLogic/UpdateStatementTransactionStatusLogic.php @@ -63,7 +63,7 @@ class UpdateStatementTransactionStatusLogic extends AbstractControllerLogic { $statementTrasaction = $this->fetchesBankStatementTransaction->execute(['id' => $request->route('id')]); - $statementTrasactionOwner = $statementTrasaction->owners->first(); + $statementTrasactionOwner = $statementTrasaction->owners()->where('status', '!=', ApprovalStatus::REJECTED)->first(); $this->updatesBankStatementTransactionOwnerStatus->execute($statementTrasactionOwner, $request->route('status') == 'approve' ? ApprovalStatus::APPROVED : ApprovalStatus::REJECTED); diff --git a/app/Http/Controllers/Imports/ImportStatementReceiptsController.php b/app/Http/Controllers/Imports/ImportStatementReceiptsController.php index 2cafeac0..a43f2dda 100644 --- a/app/Http/Controllers/Imports/ImportStatementReceiptsController.php +++ b/app/Http/Controllers/Imports/ImportStatementReceiptsController.php @@ -2,32 +2,35 @@ namespace App\Http\Controllers\Imports; -use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject; -use App\Classes\Modules\Imports\Services\GenericImport; -use App\Classes\Modules\Segments\DataTransferObjects\SeasonalSegmentObject; -use App\Classes\ValueObjects\Constants\ApprovalStatus; -use App\Models\Segment; -use App\Models\User; -use Carbon\Carbon; use DateTime; -use Illuminate\Http\Request; -use Maatwebsite\Excel\Facades\Excel; -use App\Classes\Modules\Segments\Services\CreatesSeasonalSegment; -use App\Classes\Modules\Companies\Processors\AssignSegmentProcessor; +use Carbon\Carbon; +use App\Models\User; use App\Models\Company; -use App\Models\SeasonalSegment; +use App\Models\Segment; use App\Models\Transaction; -use App\Models\TransactionMappingLog; -use App\Classes\ValueObjects\Response\ApiResponseObject; -use App\Classes\ValueObjects\Constants\HttpStatus; +use Illuminate\Http\Request; +use App\Models\SeasonalSegment; use Illuminate\Http\JsonResponse; use Illuminate\Support\Facades\DB; +use Maatwebsite\Excel\Facades\Excel; +use App\Models\TransactionMappingLog; +use App\Models\StatementTransactionOwner; +use App\Classes\ValueObjects\Constants\HttpStatus; +use App\Classes\ValueObjects\Constants\ApprovalStatus; +use App\Classes\Modules\Imports\Services\GenericImport; +use App\Classes\ValueObjects\Response\ApiResponseObject; +use App\Classes\Modules\Segments\Services\CreatesSeasonalSegment; +use App\Classes\Modules\Companies\Processors\AssignSegmentProcessor; +use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject; +use App\Classes\Modules\Segments\DataTransferObjects\SeasonalSegmentObject; class ImportStatementReceiptsController { private $responseTitle; private $responseMessage; + private $removeStr = 'Payment for '; + public function __construct() { $this->responseTitle = 'Import Receipt Mapping'; $this->responseMessage = 'You have successfully imported receipt mapping'; @@ -56,11 +59,13 @@ class ImportStatementReceiptsController $row['mapped_status'] = 'failed'; $row['date'] = in_array(gettype($row['doc_date']), ['integer', 'double']) ? $this->changeExcelDate($row['doc_date']) : date('Y-m-d', strtotime($row['doc_date'])); - $returnReference = $this->mappingExchange($row); - if ($returnReference) { - $row['mapped_result_reference'] = $returnReference; - $row['mapped_status'] = 'success'; - } + if ($invRefer = $this->getInvoiceReference($row['description'])) { + $returnReference = $this->mappingExchange($invRefer, $row['doc_no']); + if ($returnReference) { + $row['mapped_result_reference'] = $returnReference; + $row['mapped_status'] = 'success'; + } + } TransactionMappingLog::create([ 'imported_date'=>$importDate, @@ -75,28 +80,26 @@ class ImportStatementReceiptsController } } + private function getInvoiceReference($invRefer) { + $arrStr = explode($this->removeStr, $invRefer); + if (isset($arrStr[1])) return $arrStr[1]; + return null; + } + public function response(String $responseTitle, String $responseMessage, int $httpStatus, ?array $data = []) : JsonResponse { return (new ApiResponseObject($responseTitle, $responseMessage, $httpStatus, $data))->handler(); } - private function mappingExchange(Array $row) { - $date = $row['date']; - $transactions = Transaction::getReceiverWithJoinStatementTransactionAndOwner($row)->select('transactions.*')->where('statement_transactions.amount', $row['payment_amount'])->whereRaw("DATE(posting_date) = '$date'")->get(); + private function mappingExchange($invRefer, $docNo) { + $transactionOwner = StatementTransactionOwner::where('invoice_reference',$invRefer)->whereNull('receipt_reference')->where('status', ApprovalStatus::COMPLETED)->first(); - if ($transactions && $transactions->count() == 0) { - $transactions = Transaction::getReceiverWithJoinStatementTransactionAndOwner($row)->select('transactions.*')->where(DB::raw('FLOOR(statement_transactions.amount)'), floor($row['payment_amount']))->whereRaw("DATE(posting_date) = '$date'")->get(); - } - - if ($transactions && $transactions->count() == 1) { - foreach ($transactions as $key => $transaction) { - return $this->updateTransactionOwnerReference($transaction, $row['doc_no']); - } + if ($transactionOwner) { + return $this->updateTransactionOwnerReference($transactionOwner, $docNo); } return false; } - public function updateTransactionOwnerReference($transaction, String $docNo) { - $transactionOwner = $transaction->transaction_owner; + public function updateTransactionOwnerReference($transactionOwner, String $docNo) { if ($transactionOwner) { $transactionOwner->update([ 'receipt_reference'=>$docNo, diff --git a/app/Models/Company.php b/app/Models/Company.php index 8b2e6081..54ae1e23 100644 --- a/app/Models/Company.php +++ b/app/Models/Company.php @@ -109,7 +109,7 @@ class Company extends AbstractModel implements Documentable { return $this->hasManyDeep(Transaction::class, [Booking::class], ['company_id', 'owner_id'], ['id', 'id']); } - + /** * @return HasMany */ @@ -130,13 +130,25 @@ class Company extends AbstractModel implements Documentable * @return Builder */ public function services(): Builder { - return ServiceType::where('status', ApprovalStatus::APPROVED)->whereHas('constants', function($query) { - $query->Where(function($query){ - $query->where('reference', SegmentConstants::SERVICE_TYPE)->where('detail->is_active', true); - })->orWhere(function($query) { - $query->where('reference', SegmentConstants::CUSTOM_SERVICE_TYPE)->where('detail->is_active', true)->whereIn('segment_id', $this->segments->pluck('id')); + + if ($this->business_type === 3) { + return ServiceType::where('status', ApprovalStatus::APPROVED)->whereHas('constants', function($query) { + $query->where(function($query) { + $query->where('reference', SegmentConstants::SERVICE_TYPE)->where('detail->is_active', true); + })->orWhere(function($query) { + $query->where('reference', SegmentConstants::CUSTOM_SERVICE_TYPE)->where('detail->is_active', true); + }); }); - }); + } else { + // Existing logic for other company types + return ServiceType::where('status', ApprovalStatus::APPROVED)->whereHas('constants', function($query) { + $query->Where(function($query){ + $query->where('reference', SegmentConstants::SERVICE_TYPE)->where('detail->is_active', true); + })->orWhere(function($query) { + $query->where('reference', SegmentConstants::CUSTOM_SERVICE_TYPE)->where('detail->is_active', true)->whereIn('segment_id', $this->segments->pluck('id')); + }); + }); + } } public function servicesConfigurations(): Collection { diff --git a/app/Models/StatementTransaction.php b/app/Models/StatementTransaction.php index 4bba7903..6f9013b7 100644 --- a/app/Models/StatementTransaction.php +++ b/app/Models/StatementTransaction.php @@ -56,7 +56,9 @@ class StatementTransaction extends Model public function scopeDoesntMapStatement($query) { - $query->whereDoesntHave('owners', function($query){ + $query->whereHas('account', function($query) { + $query->where('statement_accounts.number', 568603010762); + })->whereDoesntHave('owners', function($query){ return $query->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]); })->orderBy('posting_date'); } diff --git a/resources/assets/vue/components/accounting/elements/EditSingleItemInListComponent.vue b/resources/assets/vue/components/accounting/elements/EditSingleItemInListComponent.vue index 5d1341b1..3e077bbc 100644 --- a/resources/assets/vue/components/accounting/elements/EditSingleItemInListComponent.vue +++ b/resources/assets/vue/components/accounting/elements/EditSingleItemInListComponent.vue @@ -136,7 +136,7 @@ case 'Sales': return ['Exchange', 'Izyim', 'Lite', 'Cntr', 'Probashi', 'Pets']; case 'Top Up': - return ['Exchange', 'Izyim']; + return ['Exchange', 'Izyim', 'Lite']; default: return []; } diff --git a/resources/assets/vue/components/accounting/elements/StatementTransactionComponent.vue b/resources/assets/vue/components/accounting/elements/StatementTransactionComponent.vue index b09b9a56..f92fc5d7 100644 --- a/resources/assets/vue/components/accounting/elements/StatementTransactionComponent.vue +++ b/resources/assets/vue/components/accounting/elements/StatementTransactionComponent.vue @@ -4,11 +4,14 @@
{{ item.posting_date }}
{{ item.transaction_description_1 + ' - ' + item.transaction_description_2 }}
+ +
{{item.owners.pending_verification[0].system}}
{{ typeString(item.owners.pending_verification[0].type) }}
- + +
@@ -51,6 +54,7 @@
+
@@ -93,6 +97,7 @@
+
diff --git a/resources/assets/vue/components/bookings/elements/BookingComponent.vue b/resources/assets/vue/components/bookings/elements/BookingComponent.vue index 9ff3fe9c..7e675646 100644 --- a/resources/assets/vue/components/bookings/elements/BookingComponent.vue +++ b/resources/assets/vue/components/bookings/elements/BookingComponent.vue @@ -22,7 +22,7 @@
-
+
Marking
{{this.item.company.reference}} @@ -34,7 +34,7 @@ {{this.item.convertible_currency.short_code}}
-
+
Transfer Type
{{this.item.service.name}}