From 3a94319805777c9d335c0e88f0373c2a4217b16f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihan=20=C5=9Eent=C3=BCrk?= Date: Mon, 9 Mar 2026 22:45:01 +0300 Subject: [PATCH] added code and description fields to category import and export models --- app/Exports/Settings/Categories.php | 2 ++ app/Imports/Purchases/Bills/Sheets/BillTransactions.php | 5 +++-- app/Imports/Sales/Invoices/Sheets/InvoiceTransactions.php | 5 +++-- app/Imports/Settings/Categories.php | 2 ++ app/Traits/Import.php | 8 ++++---- 5 files changed, 14 insertions(+), 8 deletions(-) diff --git a/app/Exports/Settings/Categories.php b/app/Exports/Settings/Categories.php index c4a486493..fe9fe8af2 100644 --- a/app/Exports/Settings/Categories.php +++ b/app/Exports/Settings/Categories.php @@ -25,9 +25,11 @@ class Categories extends Export public function fields(): array { return [ + 'code', 'name', 'type', 'color', + 'description', 'parent_name', 'enabled', ]; diff --git a/app/Imports/Purchases/Bills/Sheets/BillTransactions.php b/app/Imports/Purchases/Bills/Sheets/BillTransactions.php index 979a5b6e6..c962c6c29 100644 --- a/app/Imports/Purchases/Bills/Sheets/BillTransactions.php +++ b/app/Imports/Purchases/Bills/Sheets/BillTransactions.php @@ -5,6 +5,7 @@ namespace App\Imports\Purchases\Bills\Sheets; use App\Abstracts\Import; use App\Http\Requests\Banking\Transaction as Request; use App\Models\Banking\Transaction as Model; +use App\Models\Setting\Category; class BillTransactions extends Import { @@ -36,9 +37,9 @@ class BillTransactions extends Import $row = parent::map($row); - $row['type'] = 'expense'; + $row['type'] = Model::EXPENSE_TYPE; $row['account_id'] = $this->getAccountId($row); - $row['category_id'] = $this->getCategoryId($row, 'expense'); + $row['category_id'] = $this->getCategoryId($row, Category::EXPENSE_TYPE); $row['contact_id'] = $this->getContactId($row, 'vendor'); $row['currency_code'] = $this->getCurrencyCode($row); $row['document_id'] = $this->getDocumentId($row); diff --git a/app/Imports/Sales/Invoices/Sheets/InvoiceTransactions.php b/app/Imports/Sales/Invoices/Sheets/InvoiceTransactions.php index f8ac26af8..98a864ce9 100644 --- a/app/Imports/Sales/Invoices/Sheets/InvoiceTransactions.php +++ b/app/Imports/Sales/Invoices/Sheets/InvoiceTransactions.php @@ -5,6 +5,7 @@ namespace App\Imports\Sales\Invoices\Sheets; use App\Abstracts\Import; use App\Http\Requests\Banking\Transaction as Request; use App\Models\Banking\Transaction as Model; +use App\Models\Setting\Category; class InvoiceTransactions extends Import { @@ -37,10 +38,10 @@ class InvoiceTransactions extends Import $row = parent::map($row); - $row['type'] = 'income'; + $row['type'] = Model::INCOME_TYPE; $row['currency_code'] = $this->getCurrencyCode($row); $row['account_id'] = $this->getAccountId($row); - $row['category_id'] = $this->getCategoryId($row, 'income'); + $row['category_id'] = $this->getCategoryId($row, Category::INCOME_TYPE); $row['contact_id'] = $this->getContactId($row, 'customer'); $row['document_id'] = $this->getDocumentId($row); $row['number'] = $row['transaction_number']; diff --git a/app/Imports/Settings/Categories.php b/app/Imports/Settings/Categories.php index fca5af8fa..928c81ced 100644 --- a/app/Imports/Settings/Categories.php +++ b/app/Imports/Settings/Categories.php @@ -15,6 +15,8 @@ class Categories extends Import public $columns = [ 'name', 'type', + 'code', + 'description', ]; public function model(array $row) diff --git a/app/Traits/Import.php b/app/Traits/Import.php index 7db337881..827d1df7f 100644 --- a/app/Traits/Import.php +++ b/app/Traits/Import.php @@ -85,7 +85,7 @@ trait Import { $id = isset($row['category_id']) ? $row['category_id'] : null; - $type = !empty($type) ? $type : (!empty($row['type']) ? $row['type'] : 'income'); + $type = !empty($type) ? $type : (!empty($row['type']) ? $row['type'] : Category::INCOME_TYPE); if (empty($id) && !empty($row['category_name'])) { $id = $this->getCategoryIdFromName($row, $type); @@ -96,14 +96,14 @@ trait Import public function getCategoryType($type) { - return array_key_exists($type, config('type.category')) ? $type : 'other'; + return array_key_exists($type, config('type.category')) ? $type : Category::OTHER_TYPE; } public function getContactId($row, $type = null) { $id = isset($row['contact_id']) ? $row['contact_id'] : null; - $type = !empty($type) ? $type : (!empty($row['type']) ? (($row['type'] == 'income') ? 'customer' : 'vendor') : 'customer'); + $type = !empty($type) ? $type : (!empty($row['type']) ? (($row['type'] == Transaction::INCOME_TYPE) ? 'customer' : 'vendor') : 'customer'); if (empty($row['contact_id']) && !empty($row['contact_email'])) { $id = $this->getContactIdFromEmail($row, $type); @@ -180,7 +180,7 @@ trait Import } if (empty($id) && !empty($row['invoice_bill_number'])) { - if ($row['type'] == 'income') { + if ($row['type'] == Transaction::INCOME_TYPE) { $id = Document::invoice()->number($row['invoice_bill_number'])->pluck('id')->first(); } else { $id = Document::bill()->number($row['invoice_bill_number'])->pluck('id')->first();