0012188: add copyOmitFields to modelconfig
[tine20] / tine20 / Timetracker / Model / Timesheet.php
1 <?php
2 /**
3  * class to hold Timesheet data
4  * 
5  * @package     Timetracker
6  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
7  * @author      Philipp Schuele <p.schuele@metaways.de>
8  * @copyright   Copyright (c) 2007-2016 Metaways Infosystems GmbH (http://www.metaways.de)
9  * 
10  */
11
12 /**
13  * class to hold Timesheet data
14  * 
15  * @package     Timetracker
16  */
17 class Timetracker_Model_Timesheet extends Tinebase_Record_Abstract implements Sales_Model_Billable_Interface
18 {
19     /**
20      * holds the configuration object (must be declared in the concrete class)
21      *
22      * @var Tinebase_ModelConfiguration
23      */
24     protected static $_configurationObject = NULL;
25
26     /**
27      * Holds the model configuration (must be assigned in the concrete class)
28      *
29      * @var array
30      */
31     protected static $_modelConfiguration = array(
32         'recordName'        => 'Timesheet',
33         'recordsName'       => 'Timesheets', // ngettext('Timesheet', 'Timesheets', n)
34         'hasRelations'      => TRUE,
35         'hasCustomFields'   => TRUE,
36         'hasNotes'          => TRUE,
37         'hasTags'           => TRUE,
38         'modlogActive'      => TRUE,
39         'hasAttachments'    => TRUE,
40         'createModule'      => TRUE,
41         'containerProperty' => NULL,
42
43         'titleProperty'     => 'title',
44         'appName'           => 'Timetracker',
45         'modelName'         => 'Timesheet',
46         'multipleEdit'      => TRUE,
47         'splitButton'       => TRUE,
48
49         'defaultFilter' => 'start_date',
50
51         'fields'            => array(
52             'account_id'            => array(
53                 'label'                 => 'Account', //_('Account')
54                 'duplicateCheckGroup'   => 'account',
55                 'type'                  => 'user',
56                 'validators'            => array(Zend_Filter_Input::ALLOW_EMPTY => false, 'presence'=>'required'),
57                 // TODO add filter: 'inputFilters'          => array('Zend_Filter_Empty' => CURRENT USER ACCOUNT ID),
58             ),
59             'timeaccount_id'        => array(
60                 'label'                 => 'Time Account (Number - Title)', //_('Time Account (Number - Title)')
61                 'type'                  => 'record',
62                 'validators'            => array(Zend_Filter_Input::ALLOW_EMPTY => false, 'presence'=>'required'),
63                 'config'                => array(
64                     'appName'               => 'Timetracker',
65                     'modelName'             => 'Timeaccount',
66                     'idProperty'            => 'id'
67                 ),
68                 // TODO ?????
69                 //'default'               => array('account_grants' => array('bookOwnGrant' => true)),
70                 'filterDefinition'      => array(
71                     'filter'                => 'Tinebase_Model_Filter_ForeignId',
72                     'options'               => array(
73                         'filtergroup'           => 'Timetracker_Model_TimeaccountFilter',
74                         'controller'            => 'Timetracker_Controller_Timeaccount',
75                         'useTimesheetAcl'       => TRUE,
76                         'showClosed'            => TRUE,
77                         'appName'               => 'Timetracker',
78                         'modelName'             => 'Timeaccount',
79                     ),
80                     'jsConfig'              => array('filtertype' => 'timetracker.timeaccount')
81                 ),
82             ),
83             'is_billable'           => array(
84                 'label'                 => NULL,
85                 'validators'            => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::DEFAULT_VALUE => 1),
86                 'type'                  => 'boolean',
87                 'default'               => 1,
88                 'shy'                   => TRUE
89             ),
90             'is_billable_combined'  => array(
91                 'label'                 => 'Billable', // _('Billable')
92                 'validators'            => array(Zend_Filter_Input::ALLOW_EMPTY => true),
93                 'type'                  => 'boolean',
94                 'filterDefinition'      => array(
95                     'filter'                => 'Tinebase_Model_Filter_Bool',
96                     'title'                 => 'Billable', // _('Billable')
97                     'options'               => array(
98                         'leftOperand'           => '(timetracker_timesheet.is_billable*timetracker_timeaccount.is_billable)',
99                         'requiredCols'          => array('is_billable_combined')
100                     ),
101                 ),
102             ),
103             'billed_in'             => array(
104                 'label'                 => 'Cleared in', // _('Cleared in')
105                 'validators'            => array(Zend_Filter_Input::ALLOW_EMPTY => true),
106                 'copyOmit'              => TRUE,
107                 'shy'                   => TRUE,
108                 'copyOmit'              => true,
109             ),
110             'invoice_id'            => array(
111                 'validators'            => array(Zend_Filter_Input::ALLOW_EMPTY => true),
112                 'label'                 => 'Invoice', // _('Invoice')
113                 'type'                  => 'record',
114                 'inputFilters'          => array('Zend_Filter_Empty' => NULL),
115                 'config'                => array(
116                     'appName'               => 'Sales',
117                     'modelName'             => 'Invoice',
118                     'idProperty'            => 'id'
119                 ),
120                 'copyOmit'              => true,
121             ),
122             'is_cleared'            => array(
123                 'label'                 => NULL,
124                 'validators'            => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::DEFAULT_VALUE => 0),
125                 'type'                  => 'boolean',
126                 'default'               => 0,
127                 'copyOmit'              => TRUE,
128                 'shy'                   => TRUE,
129                 'copyOmit'              => true,
130             ),
131             'is_cleared_combined'   => array(
132                 'label'                 => 'Cleared', // _('Cleared')
133                 'validators'            => array(Zend_Filter_Input::ALLOW_EMPTY => true),
134                 'type'                  => 'boolean',
135                 'filterDefinition'      => array(
136                     'filter'                => 'Tinebase_Model_Filter_Bool',
137                     'options'               => array(
138                         'leftOperand'           => "( (CASE WHEN timetracker_timesheet.is_cleared = '1' THEN 1 ELSE 0 END) | (CASE WHEN timetracker_timeaccount.status = 'billed' THEN 1 ELSE 0 END) )",
139                         'requiredCols'          => array('is_cleared_combined'),
140                     ),
141                 ),
142             ),
143             'start_date'            => array(
144                 'label'                 => 'Date', // _('Date')
145                 'validators'            => array(Zend_Filter_Input::ALLOW_EMPTY => false, 'presence'=>'required'),
146                 'type'                  => 'date',
147                 'default'               => 'today',
148                 // strip time information from datetime string
149                 'inputFilters'          => array('Zend_Filter_PregReplace' => array('/(\d{4}-\d{2}-\d{2}).*/', '$1'))
150             ),
151             'start_time'            => array(
152                 'label'                 => 'Start time', // _('Start time')
153                 'validators'            => array(Zend_Filter_Input::ALLOW_EMPTY => true),
154                 'inputFilters'          => array('Zend_Filter_Empty' => NULL),
155                 'type'                  => 'time',
156                 'shy'                   => TRUE
157             ),
158             'duration'              => array(
159                 'label'                 => 'Duration', // _('Duration')
160                 'validators'            => array(Zend_Filter_Input::ALLOW_EMPTY => false, 'presence'=>'required'),
161                 'type'                  => 'integer',
162                 'specialType'           => 'minutes',
163                 'default'               => '30'
164             ),
165             'description'           => array(
166                 'label'                 => 'Description', // _('Description')
167                 'type'                  => 'text',
168                 'validators'            => array(Zend_Filter_Input::ALLOW_EMPTY => false, 'presence'=>'required'),
169                 'queryFilter'           => TRUE
170             ),
171             // TODO ?????
172             /*
173             'timeaccount_closed' => array(
174                 'label' => 'Time Account closed', // _('Time Account closed')
175                 'validators' => array(Zend_Filter_Input::ALLOW_EMPTY => true),
176                 'type' => 'boolean',
177
178             ),*/
179         )
180     );
181     
182     /**
183      * returns the interval of this billable
184      *
185      * @return array
186      */
187     public function getInterval()
188     {
189         $startDate = clone new Tinebase_DateTime($this->start_date);
190         $startDate->setTimezone(Tinebase_Core::getUserTimezone());
191         $startDate->setDate($startDate->format('Y'), $startDate->format('n'), 1);
192         $startDate->setTime(0,0,0);
193         
194         $endDate = clone $startDate;
195         $endDate->addMonth(1)->subSecond(1);
196         
197         return array($startDate, $endDate);
198     }
199     
200     /**
201      * returns the quantity of this billable
202      *
203      * @return float
204      */
205     public function getQuantity()
206     {
207         return $this->duration / 60;
208     }
209     
210     /**
211      * returns the unit of this billable
212      *
213      * @return string
214      */
215     public function getUnit()
216     {
217         return 'hour'; // _('hour')
218     }
219 }