25require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
35 public $element =
'expenseik';
40 public $table_element =
'expensereport_ik';
45 public $fk_element =
'fk_expense_ik';
51 public $fk_c_exp_tax_cat;
76 public $fields = array(
77 'rowid'=>array(
'type'=>
'integer',
'index'=>
true)
78 ,
'fk_c_exp_tax_cat'=>array(
'type'=>
'integer',
'index'=>
true)
79 ,
'fk_range'=>array(
'type'=>
'integer',
'index'=>
true)
80 ,
'coef'=>array(
'type'=>
'double')
81 ,
'ikoffset'=>array(
'type'=>
'double')
109 return $resultcreate;
120 public function fetch($id, $ref =
null)
148 public function delete(
User $user, $notrigger =
false)
163 $categories = array();
165 $sql =
'SELECT rowid, label, entity, active';
166 $sql .=
' FROM '.MAIN_DB_PREFIX.
'c_exp_tax_cat';
167 $sql .=
' WHERE entity IN (0, '.getEntity($this->element).
')';
169 $sql .=
' AND active = 1';
170 } elseif ($mode == 2) {
171 $sql .=
'AND active = 0';
174 dol_syslog(get_called_class().
'::getTaxCategories', LOG_DEBUG);
176 $resql = $this->db->query($sql);
178 while ($obj = $this->db->fetch_object($resql)) {
179 $categories[$obj->rowid] = $obj;
197 $default_range = (int) $userauthor->default_range;
200 $indice = $default_range - 1;
202 if (empty($ranges) || $indice < 0 || !isset($ranges[$indice])) {
205 return $ranges[$indice];
220 dol_syslog(get_called_class().
'::getRangesByCategory for fk_c_exp_tax_cat='.$fk_c_exp_tax_cat, LOG_DEBUG);
222 $sql =
'SELECT r.rowid FROM '.MAIN_DB_PREFIX.
'c_exp_tax_range r';
224 $sql .=
' INNER JOIN '.MAIN_DB_PREFIX.
'c_exp_tax_cat c ON (r.fk_c_exp_tax_cat = c.rowid)';
226 $sql .=
' WHERE r.fk_c_exp_tax_cat = '.((int) $fk_c_exp_tax_cat);
227 $sql .=
" AND r.entity IN(0, ".getEntity($this->element).
")";
229 $sql .=
' AND r.active = 1 AND c.active = 1';
231 $sql .=
' ORDER BY r.range_ik';
233 $resql = $this->db->query($sql);
235 $num = $this->db->num_rows($resql);
237 while ($obj = $this->db->fetch_object($resql)) {
239 $object->fetch($obj->rowid);
260 $sql =
' SELECT r.rowid, r.fk_c_exp_tax_cat, r.range_ik, c.label, i.rowid as fk_expense_ik, r.active as range_active, c.active as cat_active';
261 $sql .=
' FROM '.MAIN_DB_PREFIX.
'c_exp_tax_range r';
262 $sql .=
' INNER JOIN '.MAIN_DB_PREFIX.
'c_exp_tax_cat c ON (r.fk_c_exp_tax_cat = c.rowid)';
263 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'expensereport_ik i ON (r.rowid = i.fk_range)';
264 $sql .=
' WHERE r.entity IN (0, '.getEntity($this->element).
')';
265 $sql .=
' ORDER BY r.fk_c_exp_tax_cat, r.range_ik';
267 dol_syslog(get_called_class().
'::getAllRanges', LOG_DEBUG);
269 $resql = $this->db->query($sql);
271 while ($obj = $this->db->fetch_object($resql)) {
273 if ($obj->fk_expense_ik > 0) {
274 $ik->fetch($obj->fk_expense_ik);
278 if (!isset($ranges[$obj->fk_c_exp_tax_cat])) {
279 $ranges[$obj->fk_c_exp_tax_cat] = array(
'label' => $obj->label,
'active' => $obj->cat_active,
'ranges' => array());
281 $ranges[$obj->fk_c_exp_tax_cat][
'ranges'][] = $obj;
298 $sql =
'SELECT MAX(counted) as nbRange FROM (';
299 $sql .=
' SELECT COUNT(*) as counted';
300 $sql .=
' FROM '.MAIN_DB_PREFIX.
'c_exp_tax_range r';
301 $sql .=
' WHERE r.entity IN (0, '.getEntity($this->element).
')';
302 if ($default_c_exp_tax_cat > 0) {
303 $sql .=
' AND r.fk_c_exp_tax_cat = '.((int) $default_c_exp_tax_cat);
305 $sql .=
' GROUP BY r.fk_c_exp_tax_cat';
306 $sql .=
') as counts';
308 dol_syslog(get_called_class().
'::getMaxRangeNumber', LOG_DEBUG);
309 $resql = $this->db->query($sql);
311 $obj = $this->db->fetch_object($resql);
312 return $obj->nbRange;
Parent class of all other business classes (invoices, contracts, proposals, orders,...
fetchCommon($id, $ref=null, $morewhere='')
Load object in memory from the database.
createCommon(User $user, $notrigger=false)
Create object into database.
deleteCommon(User $user, $notrigger=false, $forcechilddeletion=0)
Delete object in database.
updateCommon(User $user, $notrigger=false)
Update object into database.
Class to manage Dolibarr database access.
Class to manage inventories.
__construct(DoliDB $db)
Constructor.
create(User $user, $notrigger=false)
Create object into database.
update(User $user, $notrigger=false)
Update object into database.
getRangeByUser(User $userauthor, int $fk_c_exp_tax_cat)
Return an array of ranges for a user.
getTaxCategories($mode=1)
Return expense categories in array.
getAllRanges()
Return an array of ranges grouped by category.
getRangesByCategory(int $fk_c_exp_tax_cat, $active=1)
Return an array of ranges for a category.
fetch($id, $ref=null)
Load object in memory from the database.
getMaxRangeNumber($default_c_exp_tax_cat=0)
Return the max number of range by a category.
Class to manage Dolibarr users.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.