Merge branch 'tine20.com/2012.10'
authorPhilipp Schüle <p.schuele@metaways.de>
Wed, 27 Feb 2013 18:36:11 +0000 (19:36 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Wed, 27 Feb 2013 18:36:11 +0000 (19:36 +0100)
Conflicts:
tine20/HumanResources/Model/EmployeeFilter.php
tine20/HumanResources/Setup/Update/Release6.php
tine20/HumanResources/Setup/setup.xml
tine20/Tinebase/js/widgets/ContentTypeTreePanel.js

1  2 
tine20/HumanResources/Model/EmployeeFilter.php
tine20/HumanResources/Setup/Update/Release6.php
tine20/HumanResources/Setup/Update/Release7.php
tine20/HumanResources/Setup/setup.xml
tine20/HumanResources/js/EmployeeEditDialog.js
tine20/Tinebase/js/widgets/ContentTypeTreePanel.js

@@@ -58,7 -58,9 +58,10 @@@ class HumanResources_Model_EmployeeFilt
                  'controller'        => 'Sales_Controller_Division'
              )
          ),
-         
-         'is_employed' => array('filter' => 'HumanResources_Model_EmployeeEmployedFilter')
++        'is_employed' => array('filter' => 'HumanResources_Model_EmployeeEmployedFilter'),
+         'tag'            => array('filter' => 'Tinebase_Model_Filter_Tag', 'options' => array(
+             'idProperty' => 'humanresources_employee.id',
+             'applicationName' => 'HumanResources',
+         ))
      );
  }
@@@ -280,187 -192,46 +280,189 @@@ class HumanResources_Setup_Update_Relea
              
          }
          
 -        try {
 -            $this->_backend->dropForeignKey('humanresources_employee', 'hr_employee::supervisor_id--accounts::id');
 -        } catch (Zend_Db_Statement_Exception $e) {
 -            
 +        // create type config
 +        $cb = new Tinebase_Backend_Sql(array(
 +            'modelName' => 'Tinebase_Model_Config',
 +            'tableName' => 'config',
 +        ));
 +        $appId = Tinebase_Application::getInstance()->getApplicationByName('HumanResources')->getId();
 +        
 +        // update vacation status config
 +        $kfc = $cb->getByProperty('freetimeStatus');
 +        $kfc->name = HumanResources_Config::VACATION_STATUS;
 +        $cb->update($kfc);
 +        
 +        // create sickness status config
 +        $sicknessStatusConfig = array(
 +            'name'    => HumanResources_Config::SICKNESS_STATUS,
 +            'records' => array(
 +                array('id' => 'EXCUSED',   'value' => 'Excused',   'icon' => 'images/oxygen/16x16/actions/smiley.png', 'system' => true),  //_('Excused')
 +                array('id' => 'UNEXCUSED', 'value' => 'Unexcused', 'icon' => 'images/oxygen/16x16/actions/tools-report-bug.png', 'system' => true),  //_('Unexcused')
 +            ),
 +        );
 +
 +        $cb->create(new Tinebase_Model_Config(array(
 +            'application_id'    => $appId,
 +            'name'              => HumanResources_Config::SICKNESS_STATUS,
 +            'value'             => json_encode($sicknessStatusConfig),
 +        )));
 +        
 +        // update sickness records, set status = excused
 +        $filter = new HumanResources_Model_FreeTimeFilter(array(
 +            array('field' => 'type', 'operator' => 'equals', 'value' => 'SICKNESS')
 +            ));
 +        
 +        $ftb = new HumanResources_Backend_FreeTime();
 +        $records = $ftb->search($filter);
 +        $ftb->updateMultiple($records->id, array('status' => 'EXCUSED'));
 +        
 +        // create persistenfilters
 +        
 +        $pfe = new Tinebase_PersistentFilter_Backend_Sql();
 +        
 +        $commonValues = array(
 +            'account_id'        => NULL,
 +            'application_id'    => Tinebase_Application::getInstance()->getApplicationByName('HumanResources')->getId(),
 +            'model'             => 'HumanResources_Model_EmployeeFilter',
 +        );
 +        
 +        $pfe->create(new Tinebase_Model_PersistentFilter(array_merge($commonValues, array(
 +            'name'              => "Currently employed", // _("Currently employed")
 +            'description'       => "Employees which are currently employed", // _("Employees which are currently employed")
 +            'filters'           => array(array('field' => 'is_employed', 'operator' => 'equals', 'value' => 1)),
 +        ))));
 +        
 +        // add workingtime json
 +        $field = '<field>
 +            <name>workingtime_json</name>
 +            <type>text</type>
 +            <length>1024</length>
 +            <notnull>true</notnull>
 +        </field>';
 +        
 +        $declaration = new Setup_Backend_Schema_Field_Xml($field);
 +        $this->_backend->addCol('humanresources_contract', $declaration);
 +        $this->setTableVersion('humanresources_contract', '4');
 +        
 +        // change freetime type field length
 +        $field = '<field>
 +                    <name>type</name>
 +                    <type>text</type>
 +                    <length>64</length>
 +                    <default>vacation</default>
 +                </field>';
 +        
 +        $declaration = new Setup_Backend_Schema_Field_Xml($field);
 +        $this->_backend->alterCol('humanresources_freetime', $declaration);
 +        $this->setTableVersion('humanresources_freetime', '3');
 +        
 +        // add vacation types
 +        $cb = new Tinebase_Backend_Sql(array(
 +            'modelName' => 'Tinebase_Model_Config',
 +            'tableName' => 'config',
 +            'modlogActive' => false
 +        ));
 +    
 +        $appId = Tinebase_Application::getInstance()->getApplicationByName('HumanResources')->getId();
 +        $filter = new Tinebase_Model_ConfigFilter(array(array('field' => 'name', 'operator' => 'equals', 'value' => HumanResources_Config::FREETIME_TYPE)));
 +        $ftt = $cb->search($filter)->getFirstRecord();
 +        
 +        $val = json_decode($ftt->value);
 +        
 +        $existing = $val->records;
 +        
 +        $existing[] = array('id' => 'VACATION_REMAINING',   'value' => 'Remaining Vacation', 'icon' => 'images/oxygen/16x16/actions/book2.png', 'system' => true);
 +        $existing[] = array('id' => 'VACATION_EXTRA',       'value' => 'Extra Vacation',     'icon' => 'images/oxygen/16x16/actions/book2.png', 'system' => true);
 +        
 +        $freeTimeTypeConfig = array(
 +            'name'    => HumanResources_Config::FREETIME_TYPE,
 +            'records' => $existing,
 +        );
 +
 +        $ftt->value = json_encode($freeTimeTypeConfig);
 +        $cb->update($ftt);
 +        
 +        // update json of workingtime models if they still exist
 +        
 +        $controller = HumanResources_Controller_WorkingTime::getInstance();
 +        $controller->modlogActive(false);
 +        
 +        $filter = new HumanResources_Model_WorkingTimeFilter(array());//array('field' => 'working_hours', 'operator' => 'equals', 'value' => '40')));
 +        $allWT = $controller->search($filter);
 +        
 +        $wt40 = $allWT->filter('working_hours', "40");
 +        foreach($wt40 as $wt) {
 +            $wt->json = '{"days":[8,8,8,8,8,0,0]}';
 +            $controller->update($wt);
          }
          
 -        $c = new HumanResources_Backend_Employee();
 -        $f = new HumanResources_Model_EmployeeFilter();
 +        $wt37 = $allWT->filter('working_hours', "37.5");
 +        foreach($wt37 as $wt) {
 +            $wt->json = '{"days":[8,8,8,8,5.5,0,0]}';
 +            $controller->update($wt);
 +        }
          
 -        $allEmployees = $c->search($f);
 -        $employees = clone $allEmployees;
 +        $wt20 = $allWT->filter('working_hours', "20");
 +        foreach($wt20 as $wt) {
 +            $wt->json = '{"days":[4,4,4,4,4,0,0]}';
 +            $controller->update($wt);
 +        }
          
 -        foreach($employees as $employee) {
 +        $this->setApplicationVersion('HumanResources', '6.7');
 +    }
 +    
 +    /**
 +     * update 7
 +     * 
 +     * - remove foreign keys for employee-account_id, -supervisor_id
 +     * - make supervisor_id hold an employee, not an account
 +     * 
 +     * @see 0007666: can't delete user that is linked to an employee
 +     */
 +    public function update_7($requiredTableVersion = 6)
 +    {
 +        if ($this->getTableVersion('humanresources_employee') == $requiredTableVersion) {
 +            try {
 +                $this->_backend->dropForeignKey('humanresources_employee', 'hr_employee::account_id--accounts::id');
 +            } catch (Zend_Db_Statement_Exception $e) {
 +                
 +            }
              
 -            $linkEmployee = $allEmployees->filter('account_id', $employee->supervisor_id)->getFirstRecord();
 +            try {
 +                $this->_backend->dropForeignKey('humanresources_employee', 'hr_employee::supervisor_id--accounts::id');
 +            } catch (Zend_Db_Statement_Exception $e) {
 +                
 +            }
 +            
 +            $c = new HumanResources_Backend_Employee();
 +            $f = new HumanResources_Model_EmployeeFilter();
              
 -            if ($linkEmployee) {
 -                $employee->supervisor_id = $linkEmployee->getId();
 -            } else {
 -                $employee->supervisor_id = NULL;
 +            $allEmployees = $c->search($f);
 +            $employees = clone $allEmployees;
 +            
 +            foreach ($employees as $employee) {
 +                $linkEmployee = $allEmployees->filter('account_id', $employee->supervisor_id)->getFirstRecord();
 +                if ($linkEmployee) {
 +                    $employee->supervisor_id = $linkEmployee->getId();
 +                    $c->update($employee);
 +                }
              }
 -            $c->update($employee);
 +            
 +            $this->setTableVersion('humanresources_employee', '7');
          }
 -        
 -        $this->setTableVersion('humanresources_employee', '7');
 -        $this->setApplicationVersion('HumanResources', '6.7');
 +        $this->setApplicationVersion('HumanResources', '6.8');
      }
 -
 -        
 +    
      /**
 -     * update 6.7 -> 6.8
 +     * update 6.8 -> 6.9
+      *
       * https://forge.tine20.org/mantisbt/view.php?id=7924
       * #7924: HR Modul - Description text not saved
       * - rename field freetime.remark to freetime.description
       * - add field employee.description
 -
+      * - resize health_insurance field to 128
       */
 -    public function update_7()
 +    public function update_8()
      {
          $field = '<field>
                      <name>description</name>
                  </field>';
  
          $declaration = new Setup_Backend_Schema_Field_Xml($field);
 -        $this->_backend->alterCol('humanresources_freetime', $declaration, 'remark');
          
 -        // add column to employe
 -        $this->_backend->addCol('humanresources_employee', $declaration);
 +        if (! $this->_backend->columnExists('description', 'humanresources_freetime')) {
 +            $this->_backend->alterCol('humanresources_freetime', $declaration, 'remark');
 +        }
          
 -        $this->setTableVersion('humanresources_employee', '8');
 -        $this->setTableVersion('humanresources_freetime', '3');
 +        // add column to employee
 +        if (! $this->_backend->columnExists('description', 'humanresources_employee')) {
 +            $this->_backend->addCol('humanresources_employee', $declaration);
 +        }
          
 -        $this->setApplicationVersion('HumanResources', '6.8');
 +        $this->setTableVersion('humanresources_freetime', '4');
 +        $this->setTableVersion('humanresources_employee', '8');
 +        $this->setApplicationVersion('HumanResources', '6.9');
      }
 -    public function update_8()
+     
+     /**
+      * update 6.8 -> 6.9
+      * 
+      * 0007922: can´t data save in HR modul
+      * https://forge.tine20.org/mantisbt/view.php?id=7922
+      * #7912: health_insurance needs maxLength configured in edit dialog
+      */
 -        $this->setApplicationVersion('HumanResources', '6.9');
++    public function update_9()
+     {
+         $field = '<field>
+                     <name>health_insurance</name>
+                     <type>text</type>
+                     <length>128</length>
+                 </field>';
+         $declaration = new Setup_Backend_Schema_Field_Xml($field);
+         $this->_backend->alterCol('humanresources_employee', $declaration);
+         
+         $this->setTableVersion('humanresources_employee', '9');
-     public function update_9()
++        $this->setApplicationVersion('HumanResources', '6.10');
++    }
 +
 +    /**
 +     * update to 7.0
 +     */
++    public function update_10()
 +    {
 +        $this->setApplicationVersion('HumanResources', '7.0');
      }
  }
index 16dfd70,0000000..68f7590
mode 100644,000000..100644
--- /dev/null
@@@ -1,106 -1,0 +1,121 @@@
 +<?php
 +/**
 + * Tine 2.0
 + *
 + * @package     HumanResources
 + * @subpackage  Setup
 + * @license     http://www.gnu.org/licenses/agpl.html AGPL3
 + * @copyright   Copyright (c) 2012 Metaways Infosystems GmbH (http://www.metaways.de)
 + * @author      Philipp Schüle <p.schuele@metaways.de>
 + */
 +class HumanResources_Setup_Update_Release7 extends Setup_Update_Abstract
 +{
 +    /**
 +     * update to 7.1
 +     * - add seq
 +     * 
 +     * @see 0000554: modlog: records can't be updated in less than 1 second intervals
 +     */
 +    public function update_0()
 +    {
 +        $seqModels = array(
 +            'HumanResources_Model_Contract'     => array('name' => 'humanresources_contract',    'version' => 3),
 +            'HumanResources_Model_Employee'     => array('name' => 'humanresources_employee',    'version' => 6),
 +            'HumanResources_Model_FreeTime'     => array('name' => 'humanresources_freetime',    'version' => 3),
 +            'HumanResources_Model_WorkingTime'  => array('name' => 'humanresources_workingtime', 'version' => 2),
 +        );
 +        
 +        $declaration = Tinebase_Setup_Update_Release7::getRecordSeqDeclaration();
 +        foreach ($seqModels as $model => $tableInfo) {
 +            try {
 +                $this->_backend->addCol($tableInfo['name'], $declaration);
 +            } catch (Zend_Db_Statement_Exception $zdse) {
 +                // ignore
 +            }
 +            $this->setTableVersion($tableInfo['name'], $tableInfo['version']);
 +            Tinebase_Setup_Update_Release7::updateModlogSeq($model, $tableInfo['name']);
 +        }
 +        
 +        $this->setApplicationVersion('HumanResources', '7.1');
 +    }
 +    
 +    /**
 +     * update 7.1 -> 7.2
 +     * 
 +     * - add index to contracts table
 +     *   @see 0007474: add primary key to humanresources_contract
 +     * - remove sales constrains
 +     */
 +    public function update_1()
 +    {
 +        $update6 = new HumanResources_Setup_Update_Release6($this->_backend);
 +        $update6->update_5();
 +        
 +        $this->setTableVersion('humanresources_employee', '7');
 +        $this->setTableVersion('humanresources_contract', '4');
 +        $this->setApplicationVersion('HumanResources', '7.2');
 +    }
 +
 +    /**
 +     * update 7.2 -> 7.3
 +     * 
 +     * - remove costcenter from contract, create costcenter-employee-mm table
 +     */
 +    public function update_2()
 +    {
 +        $update6 = new HumanResources_Setup_Update_Release6($this->_backend);
 +        if ($this->getTableVersion('humanresources_costcenter') === 0) {
 +            $update6->update_6();
 +            $this->setTableVersion('humanresources_contract', '5');
 +            $this->setTableVersion('humanresources_freetime', '4');
 +        }
 +        $this->setApplicationVersion('HumanResources', '7.3');
 +    }
 +
 +    /**
 +     * update 7.3 -> 7.4
 +     * 
 +     * - remove foreign keys for employee-account_id, -supervisor_id
 +     * - make supervisor_id hold an employee, not an account
 +     * 
 +     * @see 0007666: can't delete user that is linked to an employee
 +     */
 +    public function update_3()
 +    {
 +        $update6 = new HumanResources_Setup_Update_Release6($this->_backend);
 +        $update6->update_7(7);
 +        $this->setTableVersion('humanresources_employee', '8');
 +        $this->setApplicationVersion('HumanResources', '7.4');
 +    }
 +
 +    /**
 +     * update 7.4 -> 7.5
 +     * 
 +     * @see #7924: HR Modul - Description text not saved
 +     * - rename field freetime.remark to freetime.description
 +     * - add field employee.description
 +     */
 +    public function update_4()
 +    {
 +        $update6 = new HumanResources_Setup_Update_Release6($this->_backend);
 +        $update6->update_8();
 +        $this->setTableVersion('humanresources_employee', '9');
 +        $this->setTableVersion('humanresources_freetime', '5');
 +        $this->setApplicationVersion('HumanResources', '7.5');
 +    }
++
++    /**
++     * update 7.5 -> 7.6
++     * 
++     * @see #7924: HR Modul - Description text not saved
++     * - rename field freetime.remark to freetime.description
++     * - add field employee.description
++     */
++    public function update_5()
++    {
++        $update6 = new HumanResources_Setup_Update_Release6($this->_backend);
++        $update6->update_9();
++        $this->setTableVersion('humanresources_employee', '10');
++        $this->setApplicationVersion('HumanResources', '7.6');
++    }
 +}
@@@ -1,7 -1,7 +1,7 @@@
  <?xml version="1.0" encoding="utf-8"?>
  <application>
      <name>HumanResources</name>
-     <version>7.5</version>
 -    <version>6.9</version>
++    <version>7.6</version>
      <order>51</order>
      <depends>
          <application>Calendar</application>
@@@ -10,7 -10,7 +10,7 @@@
      <tables>
          <table>
              <name>humanresources_employee</name>
--            <version>9</version>
++            <version>10</version>
              <declaration>
                  <field>
                      <name>id</name>
@@@ -109,26 -80,10 +109,28 @@@ Ext.extend(Tine.widgets.ContentTypeTree
          Ext.each(this.contentTypes, function(ct) {
              var modelName = ct.meta ? ct.meta.modelName : ct.model; 
              var recordClass = Tine[this.app.appName].Model[modelName];
 +            var group = recordClass.getMeta('group');
 +            
 +            if (group) {
 +                if(! groupNodes[group]) {
 +                    groupNodes[group] = new Ext.tree.TreeNode({
 +                        id : 'modulenode-' + recordClass.getMeta('modelName'),
 +                        iconCls: this.app.appName + modelName,
 +                        text: this.app.i18n._hidden(group),
 +                        leaf : false,
 +                        expanded: false
 +                    });
 +                    treeRoot.appendChild(groupNodes[group]);
 +                }
 +                var parentNode = groupNodes[group];
 +            } else {
 +                var parentNode = treeRoot;
 +            }
 +            
              // check requiredRight if any
-             if (ct.requiredRight && (!Tine.Tinebase.common.hasRight(ct.requiredRight, this.app.appName, recordClass.getMeta('recordsName').toLowerCase()))) return true;
+             if (ct.requiredRight && (!Tine.Tinebase.common.hasRight(ct.requiredRight, this.app.appName, modelName.toLowerCase() + 's'))) {
+                 return true;
+             }
              var child = new Ext.tree.TreeNode({
                  id : 'treenode-' + recordClass.getMeta('modelName'),
                  iconCls: this.app.appName + modelName,