Added fixed asset related db changes in upgrade class.
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Wed, 2 Dec 2015 10:17:04 +0000 (11:17 +0100)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Mon, 7 Dec 2015 10:51:24 +0000 (11:51 +0100)
admin/includes/fa_patch.class.inc
includes/access_levels.inc
includes/ui/ui_lists.inc
sql/alter2.4rc1.php [new file with mode: 0644]
sql/alter2.4rc1.sql [new file with mode: 0644]

index 99aa0824265aac70f7ca087dd4990513deb633b9..91e13f1ab51048bea228b4af886352a068c1dab8 100644 (file)
@@ -48,6 +48,38 @@ class fa_patch {
                return false;
        }
 
+       /*
+               Selectively extends access to selected security areas/sections.
+       */
+       function update_security_roles($sec_updates)
+       {
+               global $security_areas, $security_sections;
+
+               $roles = db_query("SELECT * FROM ".TB_PREF."security_roles");
+
+               while($role = db_fetch($roles))
+               {
+                       $role['areas'] = explode(';', $role['areas']);
+                       $role['sections'] = explode(';', $role['sections']);
+                       foreach($sec_updates as $has => $add)
+                       {
+                               if (in_array($security_areas[$has][0], $role['areas']))
+                               {
+                                       $sections = array();
+                                       foreach($add as $area)
+                                       {
+                                               $role['areas'][] = $security_areas[$area][0];
+                                               $role['sections'][] = $security_areas[$area][0]&~0xff;
+                                       }
+                                       sort($role['areas']);
+                                       update_security_role($role['id'], $role['role'], $role['description'], 
+                                               array_values($role['sections']), array_values($role['areas']));
+                               }
+                       }
+               }
+               return true;
+       }
+
        /*
                Check and disable incompatible extensions.
        */
index 4e3bb1ab5c197535de435d44b0876793a412c382..62a71cb61d4f334cefe22364f91cc618b936331a 100644 (file)
@@ -204,7 +204,7 @@ $security_areas =array(
        'SA_ASSETSTRANSVIEW' => array(SS_ASSETS|1, _("Fixed Asset transactions view")),
        'SA_ASSETTRANSFER' => array(SS_ASSETS|2, _("Fixed Asset location transfers")),
        'SA_ASSETDISPOSAL' => array(SS_ASSETS|3, _("Fixed Asset disposals")),
-  'SA_DEPRECIATION' => array(SS_ASSETS|4, _("Depreciation")),
+    'SA_DEPRECIATION' => array(SS_ASSETS|4, _("Depreciation")),
 
        'SA_ASSETSANALYTIC' => array(SS_ASSETS_A|1, _("Fixed Asset analytical reports and inquiries")),
 
index d62b84361993f676f4cd013efd7b8ce73bcb5c36..910ad6534a853c40ed4cc0d10b5f4b3465385ca6 100644 (file)
@@ -1653,7 +1653,10 @@ function stock_categories_list_row($label, $name, $selected_id=null, $spec_opt=f
 //-----------------------------------------------------------------------------------------------
 function fixed_asset_classes_list($name, $selected_id=null, $spec_opt=false, $submit_on_change=false)
 {
-       $sql = "SELECT c.fa_class_id, CONCAT(c.fa_class_id,' - ',c.description) `desc`, CONCAT(p.fa_class_id,' - ',p.description), c.inactive FROM ".TB_PREF."stock_fa_class c, ".TB_PREF."stock_fa_class p WHERE c.parent_id=p.fa_class_id";
+       $sql = "SELECT c.fa_class_id, CONCAT(c.fa_class_id,' - ',c.description) `desc`, CONCAT(p.fa_class_id,' - ',p.description), c.inactive FROM "
+               .TB_PREF."stock_fa_class c, "
+               .TB_PREF."stock_fa_class p 
+       WHERE c.parent_id=p.fa_class_id";
 
        return combo_input($name, $selected_id, $sql, 'c.fa_class_id', 'desc',
                array('order'=>'c.fa_class_id',
diff --git a/sql/alter2.4rc1.php b/sql/alter2.4rc1.php
new file mode 100644 (file)
index 0000000..75ed0d0
--- /dev/null
@@ -0,0 +1,53 @@
+<?php
+/**********************************************************************
+    Copyright (C) FrontAccounting, LLC.
+       Released under the terms of the GNU General Public License, GPL, 
+       as published by the Free Software Foundation, either version 3 
+       of the License, or (at your option) any later version.
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
+    See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
+***********************************************************************/
+
+class fa2_4rc1 extends fa_patch {
+       var $previous = '2.4.0';                // applicable database version
+       var $version = '2.4.1'; // version installed
+       var $description;
+       var $sql = ''; // 'alter2.4rc1.sql';
+       var $preconf = true;
+
+       function fa2_4rc1() {
+               parent::fa_patch();
+               $this->description = _('Upgrade from version 2.4beta to 2.4rc1');
+       }
+
+       //
+       //      Install procedure. All additional changes 
+       //      not included in sql file should go here.
+       //
+       function install($company, $force=false)
+       {
+               // key 
+               $sec_updates = array(
+                       'SA_SETUPCOMPANY' => array(
+                               'SA_ASSET', 'SA_ASSETCATEGORY', 'SA_ASSETCLASS',
+                               'SA_ASSETSTRANSVIEW','SA_ASSETTRANSFER', 'SA_ASSETDISPOSAL',
+                               'SA_DEPRECIATION', 'SA_ASSETSANALYTIC'),
+               );
+               $result = $this->update_security_roles($sec_updates);
+               return $result;
+       }
+
+       //
+       // optional procedure done after upgrade fail, before backup is restored
+       //
+       function post_fail($company)
+       {
+               $pref = $this->companies[$company]['tbpref'];
+               db_query("DROP TABLE IF EXISTS " . $pref . 'stock_fa_class');
+       }
+
+}
+
+$install = new fa2_4rc1;
diff --git a/sql/alter2.4rc1.sql b/sql/alter2.4rc1.sql
new file mode 100644 (file)
index 0000000..df967f4
--- /dev/null
@@ -0,0 +1,24 @@
+ALTER TABLE `0_locations` ADD COLUMN `fixed_asset` tinyint(1) NOT NULL DEFAULT '0' after `contact`;
+
+DROP TABLE IF EXISTS `0_stock_fa_class`;
+CREATE TABLE `0_stock_fa_class` (
+  `fa_class_id` varchar(20) NOT NULL DEFAULT '',
+  `parent_id` varchar(20) NOT NULL DEFAULT '',
+  `description` varchar(200) NOT NULL DEFAULT '',
+  `long_description` tinytext NOT NULL,
+  `depreciation_method` char(1) NOT NULL DEFAULT 'D',
+  `depreciation_rate` double NOT NULL DEFAULT '0',
+  `depreciation_period` tinyint(1) NOT NULL DEFAULT '0',
+  `inactive` tinyint(1) NOT NULL DEFAULT '0',
+  PRIMARY KEY (`fa_class_id`)
+) ENGINE=InnoDB;
+
+ALTER TABLE `0_stock_master` ADD COLUMN `depreciation_method` char(1) NOT NULL DEFAULT 'D' AFTER `editable`;
+ALTER TABLE `0_stock_master` ADD COLUMN `depreciation_rate` double NOT NULL DEFAULT '0' AFTER `depreciation_method`;
+ALTER TABLE `0_stock_master` ADD COLUMN `depreciation_start` date NOT NULL DEFAULT '0000-00-00' AFTER `depreciation_rate`;
+ALTER TABLE `0_stock_master` ADD COLUMN `depreciation_date` date NOT NULL DEFAULT '0000-00-00' AFTER `depreciation_start`;
+ALTER TABLE `0_stock_master` ADD COLUMN `fa_class_id` varchar(20) NOT NULL DEFAULT '' AFTER `depreciation_date`;
+
+INSERT INTO `0_sys_prefs` VALUES ('default_loss_on_asset_disposal_act', 'glsetup.items', 'varchar', '15', '5660');
+INSERT INTO `0_sys_prefs` VALUES ('depreciation_period', 'glsetup.company', 'tinyint', '1', '1');
+