link('expitem_expense_id', func_get_args()); } /** * Getter / Setter for $expitem_curr_id * * @param mixed (optional) value to assign * @access public */ public function curr() { return $this->link('expitem_curr_id', func_get_args()); } /** * Getter / Setter for $expitem_expcat_id * * @param mixed (optional) value to assign * @access public */ public function expcat() { return $this->link('expitem_expcat_id', func_get_args()); } /* the code above is auto generated do not remove the tag below */ ###END_AUTOCODE function beforeInsert($request,$roo) { if (!$this->expitem_expense_id) { $roo->jerr("no expense set - system error"); } $exp = $this->expense(); if ($exp->expense_posted || $exp->expense_status == 'Paid In Full') { $roo->jerr("you can not modify a posted expense"); } // user can only edit it if it's draft. if ($exp->expense_status != 'Draft' && !$roo->authUser->hasPerm('Xtuple.ExpensesAll', 'S')) { $roo->jerr("you can not modify an expense line unless it is status draft - ask for managment to reject the expense report."); } if (empty($this->expitem_expcat_id)) { $this->expitem_expcat_id = $this->sqlValue('NULL'); } $this->updateTotalLine(); } function beforeUpdate($old, $request,$roo) { $exp = $this->expense(); if ($exp ->expense_posted || $exp->expense_status == 'Paid In Full') { $roo->jerr("you can not modify a posted expense"); } if ($exp->expense_status != 'Draft' && !$roo->authUser->hasPerm('Xtuple.ExpensesAll', 'S')) { $roo->jerr("you can not modify an expense line unless it is status draft - ask for managment to reject the expense report."); } if (empty($this->expitem_expcat_id)) { $this->expitem_expcat_id = $this->sqlValue('NULL'); } $this->updateTotalLine(); } function updateTotalLine() { if (empty($this->expitem_date)) { return; } // ?? could this use pure sql, rather than values?? // use the total, rather than this.. $this->expitem_total = $this->sqlValue(" ROUND(currtobase({$this->expitem_curr_id}, {$this->expitem_amount_fc} + {$this->expitem_tax}, '{$this->expitem_date}'),2) "); } function onInsert() { $this->updateTotals(); } function onUpdate() { $this->updateTotals(); } function updateTotals() { $t = DB_DataObject::Factory('expense'); $t->query(" UPDATE expense SET expense_amount = (SELECT sum( expitem_total - currtobase(expitem_curr_id,expitem_tax, expitem_date )) FROM expitem where expitem_expense_id = {$this->expitem_expense_id}), expense_tax = (SELECT sum(currtobase(expitem_curr_id,expitem_tax, expitem_date )) FROM expitem where expitem_expense_id = {$this->expitem_expense_id}), expense_total = (SELECT sum( expitem_total ) FROM expitem where expitem_expense_id = {$this->expitem_expense_id}) WHERE expense_id = {$this->expitem_expense_id} "); } function beforeDelete($dependants_array, $roo) { $exp = $this->expense(); if ($exp ->expense_posted || $exp->expense_status == 'Paid In Full') { $roo->jerr("you can not modify a posted expense"); } if ($exp->expense_status != 'Draft' && !$roo->authUser->hasPerm('Xtuple.ExpensesAll', 'S')) { $roo->jerr("you can not modify an expense line unless it is status draft - ask for managment to reject the expense report."); } /// delete depenedants... } }