fix(items): validate item_number and skip receiving quantity default for temp items (#4621)

* fix(items): validate item_number and skip receiving quantity default for temp items

- Validate item_number against alpha_numeric_punct rule, return JSON error on failure
- Add item_number_invalid language string

* i18n: reorder Items language keys and add item_number_invalid string

Add item_number_invalid translation across all locale files and
resort surrounding keys alphabetically to match key ordering
convention.

* PSR-12 refactoring.

- Change local variable to camelCase.
- Use single quote in language files.

* i18n: translate item_number_invalid string in ta, th, tl, zh-Hans

Item_number_invalid key had English placeholder text in Tamil,
Thai, Tagalog, Chinese Simplified language files. Translate to
match each locale.

* fix(items): use FormatRules for item_number validation

* refactor(items): use camelCase for variable names

* refactor(items): use camelCase for variable names in Items controller
This commit is contained in:
objecttothis authored and GitHub committed 2026-08-18 02:51:42 +04:00
1 parent 0e8fc0963a
commit 8bd2a51cb5
47 files changed
+85 -8

No files matched your search

+3 -1
View File
@@ -41,7 +41,9 @@ This document provides guidance for AI agents working on the Open Source Point o
- When adding new keys to language files, add the key to all `app/Language/*/` variants
- **New keys must be inserted in alphabetical order** within the language array
- Non-English files must use an empty string (`''`) as the value when no translation is provided — CodeIgniter automatically falls back to the default (`en`) language
- Non-English files must use an empty string (`''`) as the value when no translation is provided — CodeIgniter automatically falls back to the default (`en`) language. This applies only when a translation genuinely isn't available yet.
- **When explicitly asked to translate a phrase for a non-English language file, always provide the actual translation** — never leave the value as an empty string, and never leave source English text in a non-English language file
- Never copy English text from a neighboring key as a value for a non-English language file, even if that neighboring key is already untranslated — evaluate each key independently
- Only `app/Language/en/` and `app/Language/en-GB/` should contain English strings
- Plugin language files (`app/Plugins/*/Language/`) follow the same localization rules as `app/Language/`
- Use `'` to encapsulate key and string values. If the value contains `'` then it should be escaped as `\'`
+37 -7
View File
@@ -17,6 +17,7 @@ use CodeIgniter\Database\BaseConnection;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\Images\Handlers\BaseHandler;
use CodeIgniter\HTTP\DownloadResponse;
use CodeIgniter\Validation\FormatRules;
use Config\Database;
use Config\OSPOS;
use Config\Services;
@@ -115,7 +116,7 @@ class Items extends Secure_Controller
$this->item_lib->set_item_location($this->request->getGet('stock_location'));
$definition_names = $this->attribute->getDefinitionsByFlags(Attribute::SHOW_IN_ITEMS);
$definitionNames = $this->attribute->getDefinitionsByFlags(Attribute::SHOW_IN_ITEMS);
$filters = [
'start_date' => $this->request->getGet('start_date'),
@@ -128,7 +129,7 @@ class Items extends Secure_Controller
'search_custom' => false,
'is_deleted' => false,
'temporary' => false,
'definition_ids' => array_keys($definition_names)
'definition_ids' => array_keys($definitionNames)
];
// Check if any filter is set in the multiselect dropdown
@@ -325,9 +326,9 @@ class Items extends Secure_Controller
if ($data['category_dropdown'] === '1') {
$categories = ['' => lang('Items.none')];
$category_options = $this->attribute->getDefinitionValues(CATEGORY_DEFINITION_ID);
$category_options = array_combine($category_options, $category_options); // Overwrite indexes with values for saving in items table instead of attributes
$data['categories'] = array_merge($categories, $category_options);
$categoryOptions = $this->attribute->getDefinitionValues(CATEGORY_DEFINITION_ID);
$categoryOptions = array_combine($categoryOptions, $categoryOptions); // Overwrite indexes with values for saving in items table instead of attributes
$data['categories'] = array_merge($categories, $categoryOptions);
$data['selected_category'] = $item_info->category;
}
@@ -622,6 +623,25 @@ class Items extends Secure_Controller
*/
public function postSave(int $itemId = NEW_ENTRY): ResponseInterface
{
$itemNumber = $this->request->getPost('item_number');
if (!empty($itemNumber)) {
$rules = [
'item_number' => 'alpha_numeric_punct',
];
$messages = [
'item_number' => [
'alpha_numeric_punct' => lang('Items.item_number_invalid'),
],
];
if (!$this->validate($rules, $messages)) {
$errors = $this->validator->getErrors();
return $this->response->setJSON(['success' => false, 'message' => reset($errors), 'id' => $itemId]);
}
}
$uploadData = $this->upload_image();
$uploadSuccess = empty($uploadData['error']);
@@ -965,8 +985,8 @@ class Items extends Secure_Controller
helper('importfile');
$name = 'import_items.csv';
$allowed_locations = $this->stock_location->get_allowed_locations();
$allowed_attributes = $this->attribute->getDefinitionNames();
$data = generate_import_items_csv($allowed_locations, $allowed_attributes);
$allowedAttributes = $this->attribute->getDefinitionNames();
$data = generate_import_items_csv($allowed_locations, $allowedAttributes);
return $this->response->download($name, $data);
}
@@ -1219,6 +1239,16 @@ class Items extends Secure_Controller
}
}
// Check item_number for disallowed characters
if (!empty($itemData['item_number'])) {
$formatRules = new FormatRules();
if (!$formatRules->alpha_numeric_punct($itemData['item_number'])) {
log_message('error', "invalid item_number: '{$itemData['item_number']}' contains disallowed characters");
return true;
}
}
// Check stock locations
$invalidLocations = $this->validateCSVStockLocations($row, $allowedStockLocations);
if (!empty($invalidLocations)) {
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "الباركود UPC/EAN/ISBN",
"item_number_duplicate" => "رقم الصنف موجود فى قاعدة البيانات من قبل.",
'item_number_invalid' => 'رقم الصنف يحتوي على أحرف غير مسموح بها.',
"kit" => "مجموعة اصناف",
"location" => "مكان",
"low_inventory_items" => "الأصناف التى لا يوجد لها مخزون",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "الباركود UPC/EAN/ISBN",
"item_number_duplicate" => "رقم الصنف موجود فى قاعدة البيانات من قبل.",
'item_number_invalid' => 'رقم الصنف يحتوي على أحرف غير مسموح بها.',
"kit" => "مجموعة اصناف",
"location" => "مكان",
"low_inventory_items" => "الأصناف التى لا يوجد لها مخزون",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "Barkod",
"item_number_duplicate" => "Malın Nömrəsi artiq Məlumat bazasında var.",
'item_number_invalid' => 'Malın Nömrəsində icazə verilməyən simvollar var.',
"kit" => "Dəst",
"location" => "Yer",
"low_inventory_items" => "Bitmış Mallar",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "Barcode",
"item_number_duplicate" => "Item Number is already present in the database.",
'item_number_invalid' => 'Item Number contains disallowed characters.',
"kit" => "Kit",
"location" => "Location",
"low_inventory_items" => "Out Of Stock Items",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "Barkod",
"item_number_duplicate" => "Broj artikla već postoji u bazi podataka.",
'item_number_invalid' => 'Broj artikla sadrži nedozvoljene znakove.',
"kit" => "Komplet",
"location" => "Mjesto",
"low_inventory_items" => "Prodaja artikala",
+1
View File
@@ -61,6 +61,7 @@ return [
'item_id' => "",
'item_number' => "باڕکۆد",
'item_number_duplicate' => "ژمارەی ئایتم پێشتر لە داتابەیسدا ئامادەبووە.",
'item_number_invalid' => 'ژمارەی ئایتم پیتی ڕێگەپێنەدراوی تێدایە.',
'kit' => "کیت",
'location' => "شوێن",
'low_inventory_items' => "ئایتمەکانی لە کۆگادا نەماون",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "Čárový kód",
"item_number_duplicate" => "Položka už je v databázi.",
'item_number_invalid' => 'Číslo položky obsahuje nepovolené znaky.',
"kit" => "Sada",
"location" => "Umístění",
"low_inventory_items" => "Položky co nejsou skladem",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "",
"item_number_duplicate" => "",
'item_number_invalid' => 'Varenummer indeholder ikke-tilladte tegn.',
"kit" => "",
"location" => "",
"low_inventory_items" => "",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "UPC/EAN/ISBN",
"item_number_duplicate" => "Die Artikelnummer existiert bereits in der Datenbank",
'item_number_invalid' => 'Die Artikelnummer enthält nicht zulässige Zeichen.',
"kit" => "",
"location" => "Ort",
"low_inventory_items" => "nicht am Lager",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "Barcode",
"item_number_duplicate" => "Die Artikelnummer existiert bereits in der Datenbank.",
'item_number_invalid' => 'Die Artikelnummer enthält nicht zulässige Zeichen.',
"kit" => "Satz",
"location" => "Ort",
"low_inventory_items" => "Nicht vorrätige Artikel",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "",
"item_number_duplicate" => "",
'item_number_invalid' => 'Ο αριθμός είδους περιέχει μη επιτρεπόμενους χαρακτήρες.',
"kit" => "",
"location" => "",
"low_inventory_items" => "",
+1
View File
@@ -60,6 +60,7 @@ return [
"item_id" => "",
"item_number" => "Barcode",
"item_number_duplicate" => "Item Number is already present in the database.",
'item_number_invalid' => 'Item Number contains disallowed characters.',
"kit" => "Kit",
"location" => "Location",
"low_inventory_items" => "Out Of Stock Items",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "Barcode",
"item_number_duplicate" => "Item Number is already present in the database.",
'item_number_invalid' => 'Item Number contains disallowed characters.',
"kit" => "Kit",
"location" => "Location",
"low_inventory_items" => "Out Of Stock Items",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "Id del Artículo",
"item_number" => "UPC/EAN/ISBN",
"item_number_duplicate" => "El número de artículo ya esta presente en la base de datos.",
'item_number_invalid' => 'El número de artículo contiene caracteres no permitidos.',
"kit" => "Kits de artículos",
"location" => "Ubicación",
"low_inventory_items" => "Artículos de Inventario Escaso",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "Código de barras",
"item_number_duplicate" => "El código del artículo ya está presente en la base de datos.",
'item_number_invalid' => 'El código del artículo contiene caracteres no permitidos.',
"kit" => "Kit",
"location" => "Ubicación",
"low_inventory_items" => "",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "بارکد",
"item_number_duplicate" => "شماره مورد در بانک اطلاعاتی موجود است.",
'item_number_invalid' => 'شماره مورد حاوی کاراکترهای غیرمجاز است.',
"kit" => "کیت",
"location" => "محل",
"low_inventory_items" => "موجودی غیر از سهام",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "Code à barre",
"item_number_duplicate" => "L'article existe déjà la base de données.",
'item_number_invalid' => 'Le code article contient des caractères non autorisés.',
"kit" => "Ensemble",
"location" => "Emplacement",
"low_inventory_items" => "Articles en rupture d'inventaire",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "ברקוד",
"item_number_duplicate" => "מספר הפריט כבר נמצא במסד הנתונים.",
'item_number_invalid' => 'מספר הפריט מכיל תווים אסורים.',
"kit" => "ערכה",
"location" => "מיקום",
"low_inventory_items" => "פריטים מחוץ למלאי",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "UPC/EAN/ISBN",
"item_number_duplicate" => "Broj stavke već postoji u bazi",
'item_number_invalid' => 'Broj stavke sadrži nedopuštene znakove.',
"kit" => "",
"location" => "Mjesto",
"low_inventory_items" => "Rasprodaja artikala",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "UPC/EAN/ISBN",
"item_number_duplicate" => "A termék száma már szerepel az adatbázisban",
'item_number_invalid' => 'A termék száma nem megengedett karaktereket tartalmaz.',
"kit" => "",
"location" => "Helyszín",
"low_inventory_items" => "Kifogyott term.",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "",
"item_number_duplicate" => "",
'item_number_invalid' => 'Իրի համարը պարունակում է անթույլատրելի նիշեր։',
"kit" => "",
"location" => "",
"low_inventory_items" => "",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "Kode Barang",
"item_number_duplicate" => "Nomor item telah ada pada basis data.",
'item_number_invalid' => 'Nomor item mengandung karakter yang tidak diizinkan.',
"kit" => "Perlengkapan",
"location" => "Lokasi Barang",
"low_inventory_items" => "Daftar Stock Rendah",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "Codice a Barre",
"item_number_duplicate" => "Numero Articolo è già presente nel database.",
'item_number_invalid' => 'Il numero articolo contiene caratteri non consentiti.',
"kit" => "Kit",
"location" => "Posizione",
"low_inventory_items" => "Articoli Fuori Stock",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "លេខកូត",
"item_number_duplicate" => "លេខរបស់ទំនិញមាននៅក្នុងទិន្នន័យរួចរាល់។",
'item_number_invalid' => 'លេខរបស់ទំនិញមានតួអក្សរដែលមិនត្រូវបានអនុញ្ញាត។',
"kit" => "កញ្ចប់",
"location" => "ទីតាំង",
"low_inventory_items" => "ទំនិញអស់ពីស្តុក",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "Barcode",
"item_number_duplicate" => "Item Number is already present in the database.",
'item_number_invalid' => 'Item Number contains disallowed characters.',
"kit" => "Kit",
"location" => "Location",
"low_inventory_items" => "Out Of Stock Items",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "",
"item_number_duplicate" => "",
'item_number_invalid' => 'ഇനം നമ്പറിൽ അനുവദനീയമല്ലാത്ത അക്ഷരങ്ങൾ അടങ്ങിയിരിക്കുന്നു.',
"kit" => "",
"location" => "",
"low_inventory_items" => "",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "",
"item_number_duplicate" => "",
'item_number_invalid' => 'Varenummer inneholder ikke-tillatte tegn.',
"kit" => "",
"location" => "",
"low_inventory_items" => "",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "UPC/EAN/ISBN",
"item_number_duplicate" => "Artikelnummer is reeds aanwezig in de database.",
'item_number_invalid' => 'Artikelnummer bevat niet-toegestane tekens.',
"kit" => "Set",
"location" => "Locatie",
"low_inventory_items" => "Niet in stock",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "Streepjescode",
"item_number_duplicate" => "Artikelnummer is al aanwezig in de database.",
'item_number_invalid' => 'Artikelnummer bevat niet-toegestane tekens.',
"kit" => "Set",
"location" => "Locatie",
"low_inventory_items" => "Artikelen niet voorradig",
+1
View File
@@ -61,6 +61,7 @@ return [
'item_id' => "",
'item_number' => "",
'item_number_duplicate' => "",
'item_number_invalid' => 'Numer przedmiotu zawiera niedozwolone znaki.',
'kit' => "",
'location' => "",
'low_inventory_items' => "",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "Cod. Barra",
"item_number_duplicate" => "O número do item já está presente na base de dados.",
'item_number_invalid' => 'O número do item contém caracteres não permitidos.',
"kit" => "Conjunto",
"location" => "Localização",
"low_inventory_items" => "Itens sem estoque",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "",
"item_number_duplicate" => "",
'item_number_invalid' => 'Numărul articolului conține caractere nepermise.',
"kit" => "",
"location" => "",
"low_inventory_items" => "",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "Штрих-код",
"item_number_duplicate" => "Товар с таким номером уже присутствует в базе данных.",
'item_number_invalid' => 'Номер товара содержит недопустимые символы.',
"kit" => "Комплект",
"location" => "Расположение",
"low_inventory_items" => "Товары не в наличии",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "Streckkod",
"item_number_duplicate" => "Artikelnummer finns redan i databasen.",
'item_number_invalid' => 'Artikelnumret innehåller otillåtna tecken.',
"kit" => "Kit",
"location" => "Lagerplats",
"low_inventory_items" => "Artikeln slutsåld",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "Msimbo wa Mstari",
"item_number_duplicate" => "namba ya Bidhaa tayari ipo kwenye Kanzidata.",
'item_number_invalid' => 'Namba ya Bidhaa ina herufi ambazo hairuhusiwi.',
"kit" => "Kifurushi",
"location" => "Mahali",
"low_inventory_items" => "Bidhaa Zilizokwisha Stoo",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "Msimbo wa Mstari",
"item_number_duplicate" => "namba ya Bidhaa tayari ipo kwenye Kanzidata.",
'item_number_invalid' => 'Namba ya Bidhaa ina herufi ambazo hairuhusiwi.',
"kit" => "Kifurushi",
"location" => "Mahali",
"low_inventory_items" => "Bidhaa Zilizokwisha Stoo",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "Barcode",
"item_number_duplicate" => "Item Number is already present in the database.",
'item_number_invalid' => 'பொருள் எண் அனுமதிக்கப்படாத எழுத்துக்களைக் கொண்டுள்ளது.',
"kit" => "Kit",
"location" => "Location",
"low_inventory_items" => "Out Of Stock Items",
+1
View File
@@ -61,6 +61,7 @@ return [
'item_id' => "",
'item_number' => "โค๊ด",
'item_number_duplicate' => "The item number is already present in the database",
'item_number_invalid' => 'หมายเลขสินค้าประกอบด้วยอักขระที่ไม่อนุญาต',
'kit' => "ชุด",
'location' => "ที่ตั้ง",
'low_inventory_items' => "สินค้าคงเหลือน้อย",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "Barcode",
"item_number_duplicate" => "Account Number is already present in the database.",
'item_number_invalid' => 'Ang numero ng item ay naglalaman ng hindi pinapayagang mga character.',
"kit" => "Kit",
"location" => "Location",
"low_inventory_items" => "Out Of Stock Items",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "UPC/EAN/ISBN",
"item_number_duplicate" => "Ürün numarası veritabanında zaten var.",
'item_number_invalid' => 'Ürün numarası izin verilmeyen karakterler içeriyor.',
"kit" => "Set",
"location" => "Yer",
"low_inventory_items" => "Stokta Olmayan Ürünler",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "Штрих-код",
"item_number_duplicate" => "Такий номер товару вже існує в базі даних.",
'item_number_invalid' => 'Номер товару містить недопустимі символи.',
"kit" => "Комплект",
"location" => "Місцерозташування",
"low_inventory_items" => "Товарів немає в наявності",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "",
"item_number_duplicate" => "",
'item_number_invalid' => 'آئٹم نمبر میں غیر مجاز حروف شامل ہیں۔',
"kit" => "",
"location" => "",
"low_inventory_items" => "",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "Mã vạch",
"item_number_duplicate" => "Số hàng hóa đã sẵn có trong cơ sở dữ liệu rồi.",
'item_number_invalid' => 'Số hàng hóa chứa ký tự không được phép.',
"kit" => "Kít",
"location" => "Vị trí",
"low_inventory_items" => "Hàng hóa hết hàng trong kho",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "UPC/EAN/ISBN",
"item_number_duplicate" => "The item number is already present in the database",
'item_number_invalid' => '项目编号包含不允许的字符。',
"kit" => "",
"location" => "位置",
"low_inventory_items" => "低庫存產品",
+1
View File
@@ -61,6 +61,7 @@ return [
"item_id" => "",
"item_number" => "UPC/EAN/ISBN",
"item_number_duplicate" => "項目編號已存在於數據庫中。",
'item_number_invalid' => '項目編號包含不允許的字符。',
"kit" => "成套工具",
"location" => "位置",
"low_inventory_items" => "低庫存產品",