From e4a1d2c078b95375678c05f258a262ee7e915b3c Mon Sep 17 00:00:00 2001 From: Thomas Kuschel Date: Mon, 23 Oct 2023 21:55:15 +0200 Subject: [PATCH] Adding views of stacks, manufacturers lists --- admin/forms/manufacturer.xml | 93 +++++++++++++++++++ admin/forms/stock.xml | 93 +++++++++++++++++++ admin/language/en-GB/com_depot.ini | 19 +++- admin/sql/install.mysql.utf8.sql | 21 +++-- admin/sql/updates/mysql/0.0.5.sql | 6 +- admin/sql/updates/mysql/0.9.0.sql | 2 +- .../src/Controller/ManufacturerController.php | 19 ++++ admin/src/Controller/StockController.php | 19 ++++ admin/src/Model/ManufacturerModel.php | 64 +++++++++++++ admin/src/Model/ManufacturersModel.php | 75 +++++++++++++++ admin/src/Model/StockModel.php | 64 +++++++++++++ admin/src/Model/StocksModel.php | 74 +++++++++++++++ admin/src/Table/ManufacturerTable.php | 74 +++++++++++++++ admin/src/Table/StockTable.php | 74 +++++++++++++++ admin/src/View/Manufacturer/HtmlView.php | 75 +++++++++++++++ admin/src/View/Manufacturers/HtmlView.php | 47 ++++++++++ admin/src/View/Stock/HtmlView.php | 74 +++++++++++++++ admin/src/View/Stocks/HtmlView.php | 47 ++++++++++ admin/tmpl/manufacturer/edit.php | 62 +++++++++++++ admin/tmpl/manufacturers/default.php | 73 +++++++++++++++ admin/tmpl/part/edit.php | 4 +- admin/tmpl/parts/default.php | 31 ++++++- admin/tmpl/stock/edit.php | 62 +++++++++++++ admin/tmpl/stocks/default.php | 71 ++++++++++++++ depot.xml | 14 ++- 25 files changed, 1234 insertions(+), 23 deletions(-) create mode 100644 admin/forms/manufacturer.xml create mode 100644 admin/forms/stock.xml create mode 100644 admin/src/Controller/ManufacturerController.php create mode 100644 admin/src/Controller/StockController.php create mode 100644 admin/src/Model/ManufacturerModel.php create mode 100644 admin/src/Model/ManufacturersModel.php create mode 100644 admin/src/Model/StockModel.php create mode 100644 admin/src/Model/StocksModel.php create mode 100644 admin/src/Table/ManufacturerTable.php create mode 100644 admin/src/Table/StockTable.php create mode 100644 admin/src/View/Manufacturer/HtmlView.php create mode 100644 admin/src/View/Manufacturers/HtmlView.php create mode 100644 admin/src/View/Stock/HtmlView.php create mode 100644 admin/src/View/Stocks/HtmlView.php create mode 100644 admin/tmpl/manufacturer/edit.php create mode 100644 admin/tmpl/manufacturers/default.php create mode 100644 admin/tmpl/stock/edit.php create mode 100644 admin/tmpl/stocks/default.php diff --git a/admin/forms/manufacturer.xml b/admin/forms/manufacturer.xml new file mode 100644 index 0000000..e2ff4ad --- /dev/null +++ b/admin/forms/manufacturer.xml @@ -0,0 +1,93 @@ + +
+
+ + + + + + + + + +
+
+ + + + + +
+
diff --git a/admin/forms/stock.xml b/admin/forms/stock.xml new file mode 100644 index 0000000..0dda35e --- /dev/null +++ b/admin/forms/stock.xml @@ -0,0 +1,93 @@ + +
+
+ + + + + + + + + +
+
+ + + + + +
+
diff --git a/admin/language/en-GB/com_depot.ini b/admin/language/en-GB/com_depot.ini index 58625d9..c160278 100644 --- a/admin/language/en-GB/com_depot.ini +++ b/admin/language/en-GB/com_depot.ini @@ -18,8 +18,13 @@ COM_DEPOT_FIELD_QUANTITY_EXP_LABEL="Quantity Exponent" COM_DEPOT_FIELD_QUANTITY_EXP_DESC="Exponent (10^x of the number, usually 0, i.e. 10⁰)" COM_DEPOT_FIELD_SELECT_MANUFACTURER="Manufacturer" COM_DEPOT_FIELD_SELECT_STOCK="Stock Location" -COM_DEPOT_LEGEND_DETAILS="Component Details" -COM_DEPOT_LEGEND_STATISTICS="Component Statistics" +COM_DEPOT_LEGEND_MANUFACTURER_DETAILS="Manufacturer Details" +COM_DEPOT_LEGEND_PART_DETAILS="Component Details" +COM_DEPOT_LEGEND_STOCK_DETAILS="Stock Location Details" +COM_DEPOT_LEGEND_STATISTICS="Statistics" +COM_DEPOT_MANAGER_MANUFACTURERS="Manager Manufacturers" +COM_DEPOT_MANAGER_PARTS="Manager Components" +COM_DEPOT_MANAGER_STOCKS="Manager Stock Locations" COM_DEPOT_N_ITEMS_DELETED_1="One component deleted" COM_DEPOT_N_ITEMS_DELETED_MORE="%d components deleted" COM_DEPOT_N_ITEMS_PUBLISHED_1="One component published" @@ -28,8 +33,16 @@ COM_DEPOT_N_ITEMS_UNPUBLISHED_1="One component unpublished" COM_DEPOT_N_ITEMS_UNPUBLISHED_MORE="%d components unpublished" COM_DEPOT_SELECT_YOUR_OPTION="Select your option" COM_DEPOT_TAB_NEW_PART="New Component" +COM_DEPOT_TAB_NEW_MANUFACTURER="New Manufacturer" COM_DEPOT_TAB_EDIT_PART="Component Details" -COM_DEPOT_TAB_STATISTICS="Component Statistics" +COM_DEPOT_TAB_EDIT_MANUFACTURER="Manufacturer Details" +COM_DEPOT_TAB_STATISTICS="Statistics" COM_DEPOT_TABLE_HEAD_ID="ID" COM_DEPOT_TABLE_HEAD_NAME="Component Name" +COM_DEPOT_TABLE_HEAD_MANUFACTURER="Manufacturer" +COM_DEPOT_TABLE_HEAD_MANUFACTURER_ACRONYM="Acronym" +COM_DEPOT_TABLE_HEAD_STOCK="Stock Location" +COM_DEPOT_TABLE_HEAD_QUANTITY="Quantity" +COM_DEPOT_TABLE_HEAD_QUANTITY_EXP="Exponent" +COM_DEPOT_TABLE_HEAD_DESCRIPTION="Description" COM_DEPOT_XML_DESCRIPTION="Depot, the component warehouse" diff --git a/admin/sql/install.mysql.utf8.sql b/admin/sql/install.mysql.utf8.sql index ac57fe6..5a38ea7 100644 --- a/admin/sql/install.mysql.utf8.sql +++ b/admin/sql/install.mysql.utf8.sql @@ -46,15 +46,16 @@ CREATE TABLE `#__depot` ( DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; INSERT INTO `#__depot` (`component_name`,`alias`,`description`,`quantity`,`created`, - `ordering`,`state`,`manufacturer_id`) VALUES - ('1N5404','1n5404','diode, rectifier 3A',9,'2023-09-25 15:00:00',1,1,1), - ('1N4148','1n4148','diode, general purpose',1234,'2023-09-25 15:15:15',2,1,2); + `ordering`,`state`,`manufacturer_id`,`stock_id`) VALUES + ('1N5404','1n5404','diode, rectifier 3A',9,'2023-09-25 15:00:00',1,1,1,1), + ('1N4148','1n4148','diode, general purpose',1234,'2023-09-25 15:15:15',2,1,2,1); DROP TABLE IF EXISTS `#__depot_manufacturer`; CREATE TABLE `#__depot_manufacturer` ( `id` SERIAL, `name_short` CHAR(25) CHARACTER SET ascii COLLATE ascii_general_ci NULL DEFAULT NULL COMMENT 'unique manufacturer name or abbriviation', + `alias` VARCHAR(127) NOT NULL DEFAULT '', `name_long` VARCHAR(1024) NOT NULL DEFAULT '', `url` VARCHAR(1024) NOT NULL DEFAULT '', `created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', @@ -74,17 +75,17 @@ CREATE TABLE `#__depot_manufacturer` ( DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; INSERT INTO `#__depot_manufacturer` (`name_short`, `name_long`, `url`, - `description`, `image`) VALUES + `description`, `image`, `state`) VALUES ('TSC','Taiwan Semiconductor','https://www.taiwansemi.com', - 'Diodes, ECAD Models, ICs, MOSFETs, Protection Devices, AEC-Q qualified',''), + 'Diodes, ECAD Models, ICs, MOSFETs, Protection Devices, AEC-Q qualified','',1), ('ST','STMicroelectronics','https://www.st.com', - 'Microprocessors, Audio ICs, OPamps, Diodes, Memories, MEMS, NFCs, Transistors, Wireless, Automotive electronics, etc.',''); + 'Microprocessors, Audio ICs, OPamps, Diodes, Memories, MEMS, NFCs, Transistors, Wireless, Automotive electronics, etc.','',1); -DROP TABLE IF EXISTS `#__jron_stock`; -CREATE TABLE `#__jron_stock` ( +DROP TABLE IF EXISTS `#__depot_stock`; +CREATE TABLE `#__depot_stock` ( `id` SERIAL, `name` VARCHAR(1024) NOT NULL DEFAULT '', - -- `alias` VARCHAR(1024) NOT NULL DEFAULT '', + `alias` VARCHAR(1024) NOT NULL DEFAULT '', `owner` INT(10) UNSIGNED NOT NULL DEFAULT 0, `created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', `created_by` INT(10) UNSIGNED NOT NULL DEFAULT 0, @@ -106,7 +107,7 @@ CREATE TABLE `#__jron_stock` ( AUTO_INCREMENT=0 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; -INSERT INTO `#__jron_stock`(`name`, `location`, `description`, `state`, `access`) VALUES +INSERT INTO `#__depot_stock`(`name`, `location`, `description`, `state`, `access`) VALUES ('Semiconductors workshop cabinet depot', 'Tom''s office, Martinstr. 58a, 3400 Klosterneuburg', 'MARS Svratka Workshop Depot 5x12 (60) compartments à 54 x 35 x 140 mm',1,0), ('Resistors workshop cabinet depot', 'Tom''s office, Martinstr. 58a, 3400 Klosterneuburg', diff --git a/admin/sql/updates/mysql/0.0.5.sql b/admin/sql/updates/mysql/0.0.5.sql index e5c5376..3d3236d 100644 --- a/admin/sql/updates/mysql/0.0.5.sql +++ b/admin/sql/updates/mysql/0.0.5.sql @@ -28,8 +28,8 @@ CREATE TABLE IF NOT EXISTS `#__depot_manufacturer` ( DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; INSERT INTO `#__depot_manufacturer` (`name_short`, `name_long`, `url`, - `description`, `image`) VALUES + `description`, `image`, `state`) VALUES ('TSC','Taiwan Semiconductor','https://www.taiwansemi.com', - 'Diodes, ECAD Models, ICs, MOSFETs, Protection Devices, AEC-Q qualified',''), + 'Diodes, ECAD Models, ICs, MOSFETs, Protection Devices, AEC-Q qualified','',1), ('ST','STMicroelectronics','https://www.st.com', - 'Microprocessors, Audio ICs, OPamps, Diodes, Memories, MEMS, NFCs, Transistors, Wireless, Automotive electronics, etc.',''); + 'Microprocessors, Audio ICs, OPamps, Diodes, Memories, MEMS, NFCs, Transistors, Wireless, Automotive electronics, etc.','',1); diff --git a/admin/sql/updates/mysql/0.9.0.sql b/admin/sql/updates/mysql/0.9.0.sql index d29ebbd..ce31d51 100644 --- a/admin/sql/updates/mysql/0.9.0.sql +++ b/admin/sql/updates/mysql/0.9.0.sql @@ -8,7 +8,7 @@ CREATE TABLE IF NOT EXISTS `#__depot_stock` ( `id` SERIAL, `name` VARCHAR(1024) NOT NULL DEFAULT '', - -- `alias` VARCHAR(1024) NOT NULL DEFAULT '', + `alias` VARCHAR(1024) NOT NULL DEFAULT '', `owner` INT(10) UNSIGNED NOT NULL DEFAULT 0, `created` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00', `created_by` INT(10) UNSIGNED NOT NULL DEFAULT 0, diff --git a/admin/src/Controller/ManufacturerController.php b/admin/src/Controller/ManufacturerController.php new file mode 100644 index 0000000..a383b36 --- /dev/null +++ b/admin/src/Controller/ManufacturerController.php @@ -0,0 +1,19 @@ + + * @copyright (C) 2023 KW4NZ, + * @license GNU General Public License version 2 or later; see LICENSE.md + * @since 0.9.1 + */ + +namespace KW4NZ\Component\Depot\Administrator\Controller; + +use Joomla\CMS\MVC\Controller\FormController; + +defined('_JEXEC') or die; + +class ManufacturerController extends FormController +{ +} \ No newline at end of file diff --git a/admin/src/Controller/StockController.php b/admin/src/Controller/StockController.php new file mode 100644 index 0000000..d307926 --- /dev/null +++ b/admin/src/Controller/StockController.php @@ -0,0 +1,19 @@ + + * @copyright (C) 2023 KW4NZ, + * @license GNU General Public License version 2 or later; see LICENSE.md + * @since 0.9.2 + */ + +namespace KW4NZ\Component\Depot\Administrator\Controller; + +use Joomla\CMS\MVC\Controller\FormController; + +defined('_JEXEC') or die; + +class StockController extends FormController +{ +} \ No newline at end of file diff --git a/admin/src/Model/ManufacturerModel.php b/admin/src/Model/ManufacturerModel.php new file mode 100644 index 0000000..518054d --- /dev/null +++ b/admin/src/Model/ManufacturerModel.php @@ -0,0 +1,64 @@ + + * @copyright (C) 2023 KW4NZ, + * @license GNU General Public License version 2 or later; see LICENSE.md + * @since 0.9.1 + */ + +namespace KW4NZ\Component\Depot\Administrator\Model; + +use Joomla\CMS\Application\ApplicationHelper; +use Joomla\CMS\Factory; +use Joomla\CMS\MVC\Model\AdminModel; + +\defined('_JEXEC') or die; + +class ManufacturerModel extends AdminModel +{ + public function getForm($data = [], $loadData = true) + { + $form = $this->loadForm('com_depot.manufacturer', 'manufacturer', ['control' => 'jform', 'load_data' => $loadData]); + + if (empty($form)) { + return false; + } + + return $form; + } + + protected function loadFormData() + { + $app = Factory::getApplication(); + $data = $app->getUserState('com_depot.edit.manufacturer.data', []); + + if (empty($data)) { + $data = $this->getItem(); + } + + return $data; + } + + public function save($data) + { + /* Add code to modify data before saving */ + + // if (Factory::getConfig()->get('unicodeslugs') == 1) { + // $data['alias'] = OutputFilter::stringURLUnicodeSlug($data['component_name']); + // } else { + // $data['alias'] = OutputFilter::stringURLSafe($data['component_name']); + // } + + /* replaced by: */ + if (empty($data['alias'])) { + $data['alias'] = ApplicationHelper::stringURLSafe($data['name_short']); + } + $result = parent::save($data); + // if ($result) { + // $this->getTable('', 'Administrator')->rebuild(1); + // } + return $result; + } +} \ No newline at end of file diff --git a/admin/src/Model/ManufacturersModel.php b/admin/src/Model/ManufacturersModel.php new file mode 100644 index 0000000..7808fa2 --- /dev/null +++ b/admin/src/Model/ManufacturersModel.php @@ -0,0 +1,75 @@ + + * @copyright (C) 2023 KW4NZ, + * @license GNU General Public License version 2 or later; see LICENSE.md + * @since 0.9.3 + */ + +namespace KW4NZ\Component\Depot\Administrator\Model; + +use Joomla\CMS\MVC\Model\ListModel; +use Joomla\CMS\Table\Table; + +\defined('_JEXEC') or die; + +class ManufacturersModel extends ListModel +{ + /** + * Build an SQL query to load the list data. + * + * @return \Joomla\Database\DatabaseQuery + * + * @since 1.6 + */ + protected function getListQuery() + { + $db = $this->getDatabase(); + $query = $db->getQuery(true); + + + // $query->select('*') +// ->from($db->quoteName('#__depot', 'd')); + + // order by +// $query->order('d.id ASC'); +// if (true) { +// return $query; +// } + + // select the required fields from the table + $query->select( + $this->getState( + 'list.select', + [ + $db->quoteName('m.id'), + $db->quoteName('m.name_short'), + $db->quoteName('m.name_long'), + $db->quoteName('m.alias'), + $db->quoteName('m.description'), + ] + ) + ) + ->select( + [ + $db->quoteName('u.name', 'creator'), + ] + ) + ->from($db->quoteName('#__depot_manufacturer', 'm')) + ->join('LEFT', $db->quoteName('#__users', 'u'), $db->quoteName('u.id') . ' = ' . $db->quoteName('m.checked_out')); + + // Filter by published state + $published = (string) $this->getState('filter.published'); + if (is_numeric($published)) { + $published = (int) $published; + $query->where($db->quoteName('m.state') . ' = :published') + ->bind(':published', $published, ParameterType::INTEGER); + } elseif ($published === '') { + $query->where($db->quoteName('m.state') . ' IN (0, 1)'); + } + + return $query; + } +} \ No newline at end of file diff --git a/admin/src/Model/StockModel.php b/admin/src/Model/StockModel.php new file mode 100644 index 0000000..31fdf59 --- /dev/null +++ b/admin/src/Model/StockModel.php @@ -0,0 +1,64 @@ + + * @copyright (C) 2023 KW4NZ, + * @license GNU General Public License version 2 or later; see LICENSE.md + * @since 0.9.2 + */ + +namespace KW4NZ\Component\Depot\Administrator\Model; + +use Joomla\CMS\Application\ApplicationHelper; +use Joomla\CMS\Factory; +use Joomla\CMS\MVC\Model\AdminModel; + +\defined('_JEXEC') or die; + +class StockModel extends AdminModel +{ + public function getForm($data = [], $loadData = true) + { + $form = $this->loadForm('com_depot.stock', 'stock', ['control' => 'jform', 'load_data' => $loadData]); + + if (empty($form)) { + return false; + } + + return $form; + } + + protected function loadFormData() + { + $app = Factory::getApplication(); + $data = $app->getUserState('com_depot.edit.stock.data', []); + + if (empty($data)) { + $data = $this->getItem(); + } + + return $data; + } + + public function save($data) + { + /* Add code to modify data before saving */ + + // if (Factory::getConfig()->get('unicodeslugs') == 1) { + // $data['alias'] = OutputFilter::stringURLUnicodeSlug($data['component_name']); + // } else { + // $data['alias'] = OutputFilter::stringURLSafe($data['component_name']); + // } + + /* replaced by: */ + if (empty($data['alias'])) { + $data['alias'] = ApplicationHelper::stringURLSafe($data['name_short']); + } + $result = parent::save($data); + // if ($result) { + // $this->getTable('', 'Administrator')->rebuild(1); + // } + return $result; + } +} \ No newline at end of file diff --git a/admin/src/Model/StocksModel.php b/admin/src/Model/StocksModel.php new file mode 100644 index 0000000..7896d13 --- /dev/null +++ b/admin/src/Model/StocksModel.php @@ -0,0 +1,74 @@ + + * @copyright (C) 2023 KW4NZ, + * @license GNU General Public License version 2 or later; see LICENSE.md + * @since 0.9.3 + */ + +namespace KW4NZ\Component\Depot\Administrator\Model; + +use Joomla\CMS\MVC\Model\ListModel; +use Joomla\CMS\Table\Table; + +\defined('_JEXEC') or die; + +class StocksModel extends ListModel +{ + /** + * Build an SQL query to load the list data. + * + * @return \Joomla\Database\DatabaseQuery + * + * @since 1.6 + */ + protected function getListQuery() + { + $db = $this->getDatabase(); + $query = $db->getQuery(true); + + + // $query->select('*') +// ->from($db->quoteName('#__depot', 'd')); + + // order by +// $query->order('d.id ASC'); +// if (true) { +// return $query; +// } + + // select the required fields from the table + $query->select( + $this->getState( + 'list.select', + [ + $db->quoteName('s.id'), + $db->quoteName('s.name'), + $db->quoteName('s.alias'), + $db->quoteName('s.description'), + ] + ) + ) + ->select( + [ + $db->quoteName('u.name', 'creator'), + ] + ) + ->from($db->quoteName('#__depot_stock', 's')) + ->join('LEFT', $db->quoteName('#__users', 'u'), $db->quoteName('u.id') . ' = ' . $db->quoteName('s.checked_out')); + + // Filter by published state + $published = (string) $this->getState('filter.published'); + if (is_numeric($published)) { + $published = (int) $published; + $query->where($db->quoteName('s.state') . ' = :published') + ->bind(':published', $published, ParameterType::INTEGER); + } elseif ($published === '') { + $query->where($db->quoteName('s.state') . ' IN (0, 1)'); + } + + return $query; + } +} \ No newline at end of file diff --git a/admin/src/Table/ManufacturerTable.php b/admin/src/Table/ManufacturerTable.php new file mode 100644 index 0000000..c9598fc --- /dev/null +++ b/admin/src/Table/ManufacturerTable.php @@ -0,0 +1,74 @@ + + * @copyright (C) 2023 KW4NZ, + * @license GNU General Public License version 2 or later; see LICENSE.md + * @since 0.9.1 + */ + +namespace KW4NZ\Component\Depot\Administrator\Table; + +use Joomla\CMS\Factory; +use Joomla\CMS\Table\Table; +use Joomla\Database\DatabaseDriver; + +\defined('_JEXEC') or die; + +class ManufacturerTable extends Table +{ + function __construct(DatabaseDriver $db) + { + parent::__construct('#__depot_manufacturer', 'id', $db); + + // add an alias for published: + $this->setColumnAlias('published', 'state'); + } + + public function store($updateNulls = true) + { + $app = Factory::getApplication(); + $date = Factory::getDate()->toSql(); + // $user = Factory::getUser(); + // $user = $this->getCurrentUser(); + $user = $app->getIdentity(); + + if (!$this->created) { + $this->created = $date; + } + + if (!$this->created_by) { + $this->created_by = $user->get('id'); + } + + if ($this->id) { + // existing item + $this->modified_by = $user->get('id'); + $this->modified = $date; + } else { + // set modified to created date if not set + if (!$this->modified) { + $this->modified = $this->created; + } + if (empty($this->modified_by)) { + $this->modified_by = $this->created_by; + } + } + + // Verify that the alias is unique + $table = $app->bootComponent('com_depot')->getMVCFactory()->createTable('Manufacturer', 'Administrator'); + if ($table->load(['alias' => $this->alias]) && ($table->id != $this->id || $this->id == 0)) { + $this->setError('Alias is not unique.'); + + if ($table->state == -2) { + $this->setError('Alias is not unique. The item is in Trash.'); + } + + return false; + } + + return parent::store($updateNulls); + } + +} \ No newline at end of file diff --git a/admin/src/Table/StockTable.php b/admin/src/Table/StockTable.php new file mode 100644 index 0000000..6dca676 --- /dev/null +++ b/admin/src/Table/StockTable.php @@ -0,0 +1,74 @@ + + * @copyright (C) 2023 KW4NZ, + * @license GNU General Public License version 2 or later; see LICENSE.md + * @since 0.9.2 + */ + +namespace KW4NZ\Component\Depot\Administrator\Table; + +use Joomla\CMS\Factory; +use Joomla\CMS\Table\Table; +use Joomla\Database\DatabaseDriver; + +\defined('_JEXEC') or die; + +class StockTable extends Table +{ + function __construct(DatabaseDriver $db) + { + parent::__construct('#__depot_stock', 'id', $db); + + // add an alias for published: + $this->setColumnAlias('published', 'state'); + } + + public function store($updateNulls = true) + { + $app = Factory::getApplication(); + $date = Factory::getDate()->toSql(); + // $user = Factory::getUser(); + // $user = $this->getCurrentUser(); + $user = $app->getIdentity(); + + if (!$this->created) { + $this->created = $date; + } + + if (!$this->created_by) { + $this->created_by = $user->get('id'); + } + + if ($this->id) { + // existing item + $this->modified_by = $user->get('id'); + $this->modified = $date; + } else { + // set modified to created date if not set + if (!$this->modified) { + $this->modified = $this->created; + } + if (empty($this->modified_by)) { + $this->modified_by = $this->created_by; + } + } + + // Verify that the alias is unique + $table = $app->bootComponent('com_depot')->getMVCFactory()->createTable('Stock', 'Administrator'); + if ($table->load(['alias' => $this->alias]) && ($table->id != $this->id || $this->id == 0)) { + $this->setError('Alias is not unique.'); + + if ($table->state == -2) { + $this->setError('Alias is not unique. The item is in Trash.'); + } + + return false; + } + + return parent::store($updateNulls); + } + +} \ No newline at end of file diff --git a/admin/src/View/Manufacturer/HtmlView.php b/admin/src/View/Manufacturer/HtmlView.php new file mode 100644 index 0000000..b115532 --- /dev/null +++ b/admin/src/View/Manufacturer/HtmlView.php @@ -0,0 +1,75 @@ + + * @copyright (C) 2023 KW4NZ, + * @license GNU General Public License version 2 or later; see LICENSE.md + * @since 0.9.1 + */ + +namespace KW4NZ\Component\Depot\Administrator\View\Manufacturer; + +use Joomla\CMS\Factory; +// use Joomla\CMS\MVC\View\GenericDataException; +use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; +use Joomla\CMS\Toolbar\Toolbar; +use Joomla\CMS\Toolbar\ToolbarHelper; + +\defined('_JEXEC') or die; + +/** + * View to edit an article. + * + * @since 1.6 + */ +class HtmlView extends BaseHtmlView +{ + /** + * The \JForm object + * + * @var \JForm + */ + protected $form; + + /** + * The active item + * + * @var object + */ + protected $item; + + /** + * Execute and display a template script. + * + * @param string $tpl The name of the template file to parse; automatically searches through the template paths. + * + * @return mixed A string if successful, otherwise an Error object. + * + * @throws \Exception + * @since 1.6 + */ + public function display($tpl = null) + { + $this->form = $this->get('Form'); + $this->item = $this->get('Item'); + + // if (count($errors = $this->get('Errors'))) { + // throw new GenericDataException(implode("\n", $errors), 500); + // } + $this->addToolbar(); + + return parent::display($tpl); + } + + protected function addToolbar() + { + Factory::getApplication()->getInput()->set('hidemainmenu', true); + + ToolbarHelper::title('Manufacturer: Add'); + + ToolbarHelper::apply('manufacturer.apply'); + ToolbarHelper::save('manufacturer.save'); + ToolbarHelper::cancel('manufacturer.cancel', 'JTOOLBAR_CLOSE'); + } +} \ No newline at end of file diff --git a/admin/src/View/Manufacturers/HtmlView.php b/admin/src/View/Manufacturers/HtmlView.php new file mode 100644 index 0000000..cc9342d --- /dev/null +++ b/admin/src/View/Manufacturers/HtmlView.php @@ -0,0 +1,47 @@ + + * @copyright (C) 2023 KW4NZ, + * @license GNU General Public License version 2 or later; see LICENSE.md + * @since 0.9.3 + */ + +namespace KW4NZ\Component\Depot\Administrator\View\Manufacturers; + +defined('_JEXEC') or die; + +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; +use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; +// use Joomla\CMS\Toolbar; +use Joomla\CMS\Toolbar\ToolbarHelper; + +// use Joomla\CMS\Language\Text; + + +class HtmlView extends BaseHtmlView +{ + public function display($tpl = null) + { + // Get application + $app = Factory::getApplication(); + + $this->items = $this->get('Items'); + + // set the toolbar + $this->addToolbar(); + + parent::display($tpl); + } + + protected function addToolbar() + { + ToolbarHelper::title(Text::_('COM_DEPOT_MANAGER_MANUFACTURERS')); + ToolbarHelper::addNew('manufacturer.add'); + ToolbarHelper::deleteList('JGLOBAL_CONFIRM_DELETE', 'manufacturers.delete'); + ToolbarHelper::publish('manufacturers.publish', 'JTOOLBAR_PUBLISH', true); + ToolbarHelper::unpublish('manufacturers.unpublish', 'JTOOLBAR_UNPUBLISH', true); + } +} \ No newline at end of file diff --git a/admin/src/View/Stock/HtmlView.php b/admin/src/View/Stock/HtmlView.php new file mode 100644 index 0000000..d5b57cd --- /dev/null +++ b/admin/src/View/Stock/HtmlView.php @@ -0,0 +1,74 @@ + + * @copyright (C) 2023 KW4NZ, + * @license GNU General Public License version 2 or later; see LICENSE.md + * @since 0.9.2 + */ + +namespace KW4NZ\Component\Depot\Administrator\View\Stock; + +use Joomla\CMS\Factory; +// use Joomla\CMS\MVC\View\GenericDataException; +use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; +use Joomla\CMS\Toolbar\Toolbar; +use Joomla\CMS\Toolbar\ToolbarHelper; + +\defined('_JEXEC') or die; + +/** + * View to edit an article. + * + * @since 1.6 + */ +class HtmlView extends BaseHtmlView +{ + /** + * The \JForm object + * + * @var \JForm + */ + protected $form; + + /** + * The active item + * + * @var object + */ + protected $item; + + /** + * Execute and display a template script. + * + * @param string $tpl The name of the template file to parse; automatically searches through the template paths. + * + * @return mixed A string if successful, otherwise an Error object. + * + * @throws \Exception + * @since 1.6 + */ + public function display($tpl = null) + { + $this->form = $this->get('Form'); + $this->item = $this->get('Item'); + + // if (count($errors = $this->get('Errors'))) { + // throw new GenericDataException(implode("\n", $errors), 500); + // } + $this->addToolbar(); + + return parent::display($tpl); + } + + protected function addToolbar() + { + Factory::getApplication()->getInput()->set('hidemainmenu', true); + + ToolbarHelper::title('Stock: Add'); + ToolbarHelper::apply('stock.apply'); + ToolbarHelper::save('stock.save'); + ToolbarHelper::cancel('stock.cancel', 'JTOOLBAR_CLOSE'); + } +} \ No newline at end of file diff --git a/admin/src/View/Stocks/HtmlView.php b/admin/src/View/Stocks/HtmlView.php new file mode 100644 index 0000000..9a3c9c6 --- /dev/null +++ b/admin/src/View/Stocks/HtmlView.php @@ -0,0 +1,47 @@ + + * @copyright (C) 2023 KW4NZ, + * @license GNU General Public License version 2 or later; see LICENSE.md + * @since 0.9.3 + */ + +namespace KW4NZ\Component\Depot\Administrator\View\Stocks; + +defined('_JEXEC') or die; + +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; +use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; +// use Joomla\CMS\Toolbar; +use Joomla\CMS\Toolbar\ToolbarHelper; + +// use Joomla\CMS\Language\Text; + + +class HtmlView extends BaseHtmlView +{ + public function display($tpl = null) + { + // Get application + $app = Factory::getApplication(); + + $this->items = $this->get('Items'); + + // set the toolbar + $this->addToolbar(); + + parent::display($tpl); + } + + protected function addToolbar() + { + ToolbarHelper::title(Text::_('COM_DEPOT_MANAGER_STOCKS')); + ToolbarHelper::addNew('stock.add'); + ToolbarHelper::deleteList('JGLOBAL_CONFIRM_DELETE', 'stocks.delete'); + ToolbarHelper::publish('stocks.publish', 'JTOOLBAR_PUBLISH', true); + ToolbarHelper::unpublish('stocks.unpublish', 'JTOOLBAR_UNPUBLISH', true); + } +} \ No newline at end of file diff --git a/admin/tmpl/manufacturer/edit.php b/admin/tmpl/manufacturer/edit.php new file mode 100644 index 0000000..9b2a2bc --- /dev/null +++ b/admin/tmpl/manufacturer/edit.php @@ -0,0 +1,62 @@ + + * @copyright (C) 2023 KW4NZ, + * @license GNU General Public License version 2 or later; see LICENSE.md + * @since 0.0.3 + */ +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Router\Route; + +/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */ +$wa = $this->document->getWebAssetManager(); +$wa->useScript('form.validate') + ->useScript('keepalive'); + +?> +
+ 'details']); ?> + item->id) ? Text::_('COM_DEPOT_TAB_NEW_MANUFACTURER') : + Text::_('COM_DEPOT_TAB_EDIT_MANUFACTURER') + ); ?> +
+ + + +
+
+ form->renderFieldset('details'); ?> +
+
+ form->getInput('description'); ?> +
+
+
+ + + +
+ + + +
+
+ form->renderFieldset('statistics'); ?> +
+
+
+ + + + + + +
\ No newline at end of file diff --git a/admin/tmpl/manufacturers/default.php b/admin/tmpl/manufacturers/default.php new file mode 100644 index 0000000..18756d1 --- /dev/null +++ b/admin/tmpl/manufacturers/default.php @@ -0,0 +1,73 @@ + + * @copyright (C) 2023 KW4NZ, + * @license GNU General Public License version 2 or later; see LICENSE.md + * @since 0.9.3 + */ + +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Router\Route; + +?> +
+ + items)): ?> +
+ + +
+ + + + + + + + + + + + + + items as $i => $item): ?> + + + + + + + + +
+ + + + + + + +
+ id); ?> + + id ?> + + + escape($item->name_short); ?> + + + escape($item->name_long); ?> +
+ + + + + + +
\ No newline at end of file diff --git a/admin/tmpl/part/edit.php b/admin/tmpl/part/edit.php index 80c3a53..bb95a91 100644 --- a/admin/tmpl/part/edit.php +++ b/admin/tmpl/part/edit.php @@ -5,7 +5,7 @@ * @author Thomas Kuschel * @copyright (C) 2023 KW4NZ, * @license GNU General Public License version 2 or later; see LICENSE.md - * @since 0.0.3 + * @since 0.9.2 */ use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Text; @@ -29,7 +29,7 @@ $wa->useScript('form.validate') ); ?>
- +
diff --git a/admin/tmpl/parts/default.php b/admin/tmpl/parts/default.php index 81258ba..841a11a 100644 --- a/admin/tmpl/parts/default.php +++ b/admin/tmpl/parts/default.php @@ -13,7 +13,6 @@ use Joomla\CMS\Language\Text; use Joomla\CMS\Router\Route; ?> -

Welcome to my Depot Component!

@@ -37,6 +36,18 @@ use Joomla\CMS\Router\Route; + + + + + + + + + + + + @@ -54,6 +65,24 @@ use Joomla\CMS\Router\Route; escape($item->component_name); ?> + + escape($item->quantity); ?> + + + quantity_exp; ?> + + + + escape($item->manufacturer); ?> + + + + + escape($item->stock_name); ?> + + diff --git a/admin/tmpl/stock/edit.php b/admin/tmpl/stock/edit.php new file mode 100644 index 0000000..13d2cda --- /dev/null +++ b/admin/tmpl/stock/edit.php @@ -0,0 +1,62 @@ + + * @copyright (C) 2023 KW4NZ, + * @license GNU General Public License version 2 or later; see LICENSE.md + * @since 0.0.3 + */ +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Router\Route; + +/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */ +$wa = $this->document->getWebAssetManager(); +$wa->useScript('form.validate') + ->useScript('keepalive'); + +?> + + 'details']); ?> + item->id) ? Text::_('COM_DEPOT_TAB_NEW_STOCK') : + Text::_('COM_DEPOT_TAB_EDIT_STOCK') + ); ?> +
+ + + +
+
+ form->renderFieldset('details'); ?> +
+
+ form->getInput('description'); ?> +
+
+
+ + + +
+ + + +
+
+ form->renderFieldset('statistics'); ?> +
+
+
+ + + + + + + \ No newline at end of file diff --git a/admin/tmpl/stocks/default.php b/admin/tmpl/stocks/default.php new file mode 100644 index 0000000..879bc66 --- /dev/null +++ b/admin/tmpl/stocks/default.php @@ -0,0 +1,71 @@ + + * @copyright (C) 2023 KW4NZ, + * @license GNU General Public License version 2 or later; see LICENSE.md + * @since 0.9.3 + */ + +use Joomla\CMS\HTML\HTMLHelper; +use Joomla\CMS\Language\Text; +use Joomla\CMS\Router\Route; + +?> +
+ + items)): ?> +
+ + +
+ + + + + + + + + + + + + items as $i => $item): ?> + + + + + + + + +
+ + + + + + + +
+ id); ?> + + id ?> + + + escape($item->name); ?> + + + escape($item->description); ?> +
+ + + + + + +
\ No newline at end of file diff --git a/depot.xml b/depot.xml index 9f38c12..1e55132 100644 --- a/depot.xml +++ b/depot.xml @@ -7,7 +7,7 @@ GPL v2 +; see LICENSE.md thomas@kuschel.at https://kuschel.at - 0.9.0 + 0.9.3 COM_DEPOT_XML_DESCRIPTION KW4NZ\Component\Depot @@ -46,9 +46,17 @@ COM_DEPOT_MENU + COM_DEPOT_MENU_MANUFACTURERS + + COM_DEPOT_MENU_STOCKS