From 937145f1668ae5bef03f0b3047d45a5d09738af9 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sun, 28 May 2017 18:57:57 +0200 Subject: [PATCH] UI fixes --- Admin/Installer.php | 77 +++++++++++++ Models/Supplier.php | 168 ++++++++++++++++++++++++++++ Models/SupplierMapper.php | 165 +++++++++++++++++++++++++++ Theme/Backend/supplier-list.tpl.php | 51 +++++---- 4 files changed, 437 insertions(+), 24 deletions(-) create mode 100644 Models/Supplier.php create mode 100644 Models/SupplierMapper.php diff --git a/Admin/Installer.php b/Admin/Installer.php index 4712f37..18358c6 100644 --- a/Admin/Installer.php +++ b/Admin/Installer.php @@ -44,7 +44,84 @@ class Installer extends InstallerAbstract switch ($dbPool->get('core')->getType()) { case DatabaseType::MYSQL: + $dbPool->get('core')->con->beginTransaction(); + $dbPool->get('core')->con->prepare(/* todo: maybe add supplier logo? */ + 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'suppliermgmt_supplier` ( + `suppliermgmt_supplier_id` int(11) NOT NULL AUTO_INCREMENT, + `suppliermgmt_supplier_no` int(11) NOT NULL, + `suppliermgmt_supplier_no_reverse` varchar(25) DEFAULT NULL, + `suppliermgmt_supplier_status` tinyint(2) NOT NULL, + `suppliermgmt_supplier_type` tinyint(2) NOT NULL, + `suppliermgmt_supplier_taxid` varchar(50) DEFAULT NULL, + `suppliermgmt_supplier_info` text DEFAULT NULL, + `suppliermgmt_supplier_created_at` datetime NOT NULL, + `suppliermgmt_supplier_account` int(11) NOT NULL, + PRIMARY KEY (`suppliermgmt_supplier_id`), + KEY `suppliermgmt_supplier_account` (`suppliermgmt_supplier_account`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'ALTER TABLE `' . $dbPool->get('core')->prefix . 'suppliermgmt_supplier` + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'suppliermgmt_supplier_ibfk_1` FOREIGN KEY (`suppliermgmt_supplier_account`) REFERENCES `' . $dbPool->get('core')->prefix . 'profile_account` (`profile_account_id`);' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'suppliermgmt_supplier_address` ( + `suppliermgmt_supplier_address_id` int(11) NOT NULL AUTO_INCREMENT, + `suppliermgmt_supplier_address_supplier` int(11) NOT NULL, + `suppliermgmt_supplier_address_address` int(11) NOT NULL, + `suppliermgmt_supplier_address_type` tinyint(2) NOT NULL, + PRIMARY KEY (`suppliermgmt_supplier_address_id`), + KEY `suppliermgmt_supplier_address_supplier` (`suppliermgmt_supplier_address_supplier`), + KEY `suppliermgmt_supplier_address_address` (`suppliermgmt_supplier_address_address`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'ALTER TABLE `' . $dbPool->get('core')->prefix . 'suppliermgmt_supplier_address` + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'suppliermgmt_supplier_address_ibfk_1` FOREIGN KEY (`suppliermgmt_supplier_address_supplier`) REFERENCES `' . $dbPool->get('core')->prefix . 'suppliermgmt_supplier` (`suppliermgmt_supplier_id`), + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'suppliermgmt_supplier_address_ibfk_2` FOREIGN KEY (`suppliermgmt_supplier_address_address`) REFERENCES `' . $dbPool->get('core')->prefix . 'profile_address` (`profile_address_id`);' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'suppliermgmt_supplier_contactelement` ( + `suppliermgmt_supplier_contactelement_id` int(11) NOT NULL AUTO_INCREMENT, + `suppliermgmt_supplier_contactelement_dst` int(11) NOT NULL, + `suppliermgmt_supplier_contactelement_src` int(11) NOT NULL, + `suppliermgmt_supplier_contactelement_type` tinyint(2) NOT NULL, + PRIMARY KEY (`suppliermgmt_supplier_contactelement_id`), + KEY `suppliermgmt_supplier_contactelement_dst` (`suppliermgmt_supplier_contactelement_dst`), + KEY `suppliermgmt_supplier_contactelement_src` (`suppliermgmt_supplier_contactelement_src`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'ALTER TABLE `' . $dbPool->get('core')->prefix . 'suppliermgmt_supplier_contactelement` + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'suppliermgmt_supplier_contactelement_ibfk_1` FOREIGN KEY (`suppliermgmt_supplier_contactelement_src`) REFERENCES `' . $dbPool->get('core')->prefix . 'suppliermgmt_supplier` (`suppliermgmt_supplier_id`), + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'suppliermgmt_supplier_contactelement_ibfk_2` FOREIGN KEY (`suppliermgmt_supplier_contactelement_dst`) REFERENCES `' . $dbPool->get('core')->prefix . 'profile_contactelement` (`profile_contactelement_id`);' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'CREATE TABLE if NOT EXISTS `' . $dbPool->get('core')->prefix . 'suppliermgmt_supplier_media` ( + `suppliermgmt_supplier_media_id` int(11) NOT NULL AUTO_INCREMENT, + `suppliermgmt_supplier_media_dst` int(11) NOT NULL, + `suppliermgmt_supplier_media_src` int(11) NOT NULL, + `suppliermgmt_supplier_media_type` tinyint(2) NOT NULL, + PRIMARY KEY (`suppliermgmt_supplier_media_id`), + KEY `suppliermgmt_supplier_media_dst` (`suppliermgmt_supplier_media_dst`), + KEY `suppliermgmt_supplier_media_src` (`suppliermgmt_supplier_media_src`) + ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1;' + )->execute(); + + $dbPool->get('core')->con->prepare( + 'ALTER TABLE `' . $dbPool->get('core')->prefix . 'suppliermgmt_supplier_media` + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'suppliermgmt_supplier_media_ibfk_1` FOREIGN KEY (`suppliermgmt_supplier_media_src`) REFERENCES `' . $dbPool->get('core')->prefix . 'suppliermgmt_supplier` (`suppliermgmt_supplier_id`), + ADD CONSTRAINT `' . $dbPool->get('core')->prefix . 'suppliermgmt_supplier_media_ibfk_2` FOREIGN KEY (`suppliermgmt_supplier_media_dst`) REFERENCES `' . $dbPool->get('core')->prefix . 'media` (`media_id`);' + )->execute(); + + $dbPool->get('core')->con->commit(); break; } } diff --git a/Models/Supplier.php b/Models/Supplier.php new file mode 100644 index 0000000..258b957 --- /dev/null +++ b/Models/Supplier.php @@ -0,0 +1,168 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +declare(strict_types = 1); +namespace Modules\SupplierManagement\Models; + +use Modules\Media\Models\Media; +use Modules\Profile\Models\Profile; + +/** + * Account class. + * + * @category Modules + * @package Modules\Admin + * @author OMS Development Team + * @author Dennis Eichhorn + * @license OMS License 1.0 + * @link http://orange-management.com + * @since 1.0.0 + */ +class Supplier +{ + private $id = 0; + + private $number = 0; + + private $numberReverse = 0; + + private $status = 0; + + private $type = 0; + + private $taxId = ''; + + private $info = ''; + + private $createdAt = null; + + private $profile = null; + + private $files = []; + + private $contactElements = []; + + private $address = []; + + public function __construct(int $id = 0) + { + $this->createdAt = new \DateTime('now'); + $this->profile = new Profile(); + } + + public function getId() : int + { + return $this->id; + } + + public function getNumber() : int + { + return $this->number; + } + + public function setNumber(int $number) /* : void */ + { + $this->number = $number; + } + + public function getReverseNumber() + { + return $this->numberReverse; + } + + public function setReverseNumber($rev_no) /* : void */ + { + if (!is_scalar($rev_no)) { + throw new \Exception(); + } + + $this->numberReverse = $rev_no; + } + + public function getStatus() : int + { + return $this->status; + } + + public function setStatus(int $status) /* : void */ + { + $this->status = $status; + } + + public function getType() : int + { + return $this->type; + } + + public function setType(int $type) /* : void */ + { + $this->type = $type; + } + + public function getTaxId() : string + { + return $this->taxId; + } + + public function setTaxId(string $taxId) /* : void */ + { + $this->taxId = $taxId; + } + + public function getInfo() : string + { + return $this->info; + } + + public function setInfo(string $info) /* : void */ + { + $this->info = $info; + } + + public function getCreatedAt() : \DateTime + { + return $this->createdAt; + } + + public function getProfile() : Profile + { + return $this->profile; + } + + public function setProfile(Profile $profile) /* : void */ + { + $this->profile = $profile; + } + + public function getFiles() : array + { + return $this->files; + } + + public function addFile(Media $file) /* : void */ + { + $this->files[] = $file; + } + + public function getAddresses() : array + { + return $this->address; + } + + public function getContactElements() : array + { + return $this->contactElements; + } +} diff --git a/Models/SupplierMapper.php b/Models/SupplierMapper.php new file mode 100644 index 0000000..3aee392 --- /dev/null +++ b/Models/SupplierMapper.php @@ -0,0 +1,165 @@ + + * @author Dennis Eichhorn + * @copyright Dennis Eichhorn + * @license OMS License 1.0 + * @version 1.0.0 + * @link http://orange-management.com + */ +declare(strict_types=1); +namespace Modules\SupplierManagement\Models; + +use Modules\Media\Models\MediaMapper; +use Modules\Profile\Models\ProfileMapper; +use Modules\Profile\Models\ContactElement; +use Modules\Profile\Models\ContactElementMapper; +use Modules\Profile\Models\ContactMapper; +use phpOMS\DataStorage\Database\DataMapperAbstract; +use phpOMS\DataStorage\Database\Query\Builder; +use phpOMS\DataStorage\Database\Query\Column; +use phpOMS\DataStorage\Database\RelationType; + +class SupplierMapper extends DataMapperAbstract +{ + /** + * Columns. + * + * @var array + * @since 1.0.0 + */ + protected static $columns = [ + 'suppliermgmt_supplier_id' => ['name' => 'suppliermgmt_supplier_id', 'type' => 'int', 'internal' => 'id'], + 'suppliermgmt_supplier_no' => ['name' => 'suppliermgmt_supplier_no', 'type' => 'int', 'internal' => 'number'], + 'suppliermgmt_supplier_no_reverse' => ['name' => 'suppliermgmt_supplier_no_reverse', 'type' => 'string', 'internal' => 'numberReverse'], + 'suppliermgmt_supplier_status' => ['name' => 'suppliermgmt_supplier_status', 'type' => 'int', 'internal' => 'status'], + 'suppliermgmt_supplier_type' => ['name' => 'suppliermgmt_supplier_type', 'type' => 'int', 'internal' => 'type'], + 'suppliermgmt_supplier_taxid' => ['name' => 'suppliermgmt_supplier_taxid', 'type' => 'string', 'internal' => 'taxId'], + 'suppliermgmt_supplier_info' => ['name' => 'suppliermgmt_supplier_info', 'type' => 'string', 'internal' => 'info'], + 'suppliermgmt_supplier_created_at' => ['name' => 'suppliermgmt_supplier_created_at', 'type' => 'DateTime', 'internal' => 'createdAt'], + 'suppliermgmt_supplier_account' => ['name' => 'suppliermgmt_supplier_account', 'type' => 'int', 'internal' => 'profile'], + ]; + + /** + * Primary table. + * + * @var string + * @since 1.0.0 + */ + protected static $table = 'suppliermgmt_supplier'; + + /** + * Primary field name. + * + * @var string + * @since 1.0.0 + */ + protected static $primaryField = 'suppliermgmt_supplier_id'; + + /** + * Created at column + * + * @var string + * @since 1.0.0 + */ + protected static $createdAt = 'suppliermgmt_supplier_created_at'; + + /** + * Has one relation. + * + * @var array + * @since 1.0.0 + */ + protected static $ownsOne = [ + 'profile' => [ + 'mapper' => ProfileMapper::class, + 'src' => 'suppliermgmt_supplier_account', + ], + ]; + + protected static $hasMany = [ + 'files' => [ + 'mapper' => MediaMapper::class, /* mapper of the related object */ + 'table' => 'suppliermgmt_supplier_media', /* table of the related object, null if no relation table is used (many->1) */ + 'dst' => 'suppliermgmt_supplier_media_dst', + 'src' => 'suppliermgmt_supplier_media_src', + ], + 'contactElements' => [ + 'mapper' => ContactElementMapper::class, + 'table' => 'suppliermgmt_supplier_contactelement', + 'dst' => 'suppliermgmt_supplier_contactelement_dst', + 'src' => 'suppliermgmt_supplier_contactelement_src', + ], + ]; + + /** + * Create object. + * + * @param mixed $obj Object + * @param int $relations Behavior for relations creation + * + * @return mixed + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function create($obj, int $relations = RelationType::ALL) + { + try { + $objId = parent::create($obj, $relations); + + if($objId === null || !is_scalar($objId)) { + return $objId; + } + + $query = new Builder(self::$db); + + $query->prefix(self::$db->getPrefix()) + ->insert( + 'account_permission_account', + 'account_permission_from', + 'account_permission_for', + 'account_permission_id1', + 'account_permission_id2', + 'account_permission_r', + 'account_permission_w', + 'account_permission_m', + 'account_permission_d', + 'account_permission_p' + ) + ->into('account_permission') + ->values(1, 'suppliermgmt_supplier', 'suppliermgmt_supplier', 1, $objId, 1, 1, 1, 1, 1); + + self::$db->con->prepare($query->toSql())->execute(); + } catch (\Exception $e) { + var_dump($e->getMessage()); + + return false; + } + + return $objId; + } + + /** + * Get object. + * + * @param mixed $primaryKey Key + * @param int $relations Load relations + * @param mixed $fill Object to fill + * + * @return supplier + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public static function get($primaryKey, int $relations = RelationType::ALL, $fill = null) + { + return parent::get((int) $primaryKey, $relations, $fill); + } +} diff --git a/Theme/Backend/supplier-list.tpl.php b/Theme/Backend/supplier-list.tpl.php index daa1ce0..394f7f5 100644 --- a/Theme/Backend/supplier-list.tpl.php +++ b/Theme/Backend/supplier-list.tpl.php @@ -21,28 +21,31 @@ $footerView->setPage(1); echo $this->getData('nav')->render(); ?> - -
- - - - - - - - $value) : $count++; ?> - - -
getText('Suppliers') ?>
getText('ID', 0, 0); ?> - getText('Name1'); ?> - getText('Name2'); ?> - getText('Name3'); ?> - getText('City'); ?> - getText('Zip'); ?> - getText('Address'); ?> - getText('Country'); ?> -
render(); ?> -
getText('Empty', 0, 0); ?> - -
+
+
+
+ + + + + + + + $value) : $count++; ?> + + +
getText('Suppliers') ?>
getText('ID', 0, 0); ?> + getText('Name1'); ?> + getText('Name2'); ?> + getText('Name3'); ?> + getText('City'); ?> + getText('Zip'); ?> + getText('Address'); ?> + getText('Country'); ?> +
render(); ?> +
getText('Empty', 0, 0); ?> + +
+
+