27require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
37 public $element =
'expenseik';
42 public $table_element =
'expensereport_ik';
47 public $fk_element =
'fk_expense_ik';
53 public $fk_c_exp_tax_cat;
78 public $fields = array(
79 'rowid' => array(
'type' =>
'integer',
'label' =>
'ID',
'enabled' => 1,
'index' => 1,
'visible' => -1,
'position' => 10),
80 'fk_c_exp_tax_cat' => array(
'type' =>
'integer',
'label' =>
'Tax cat id',
'enabled' => 1,
'index' => 1,
'visible' => -1,
'position' => 20),
81 'fk_range' => array(
'type' =>
'integer',
'label' =>
'Tax range id',
'enabled' => 1,
'index' => 1,
'visible' => -1,
'position' => 30),
82 'coef' => array(
'type' =>
'double',
'label' =>
'Coef',
'enabled' => 1,
'visible' => -1,
'position' => 40),
83 'ikoffset' => array(
'type' =>
'double',
'label' =>
'Offset',
'enabled' => 1,
'visible' => -1,
'position' => 50),
111 return $resultcreate;
122 public function fetch($id, $ref =
null)
148 public function delete(
User $user, $notrigger = 0)
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)) {
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);
280 if (!isset($ranges[$obj->fk_c_exp_tax_cat])) {
281 $ranges[$obj->fk_c_exp_tax_cat] = array(
'label' => $obj->label,
'active' => $obj->cat_active,
'ranges' => array());
283 $ranges[$obj->fk_c_exp_tax_cat][
'ranges'][] = $obj;
300 $sql =
'SELECT MAX(counted) as nbRange FROM (';
301 $sql .=
' SELECT COUNT(*) as counted';
302 $sql .=
' FROM '.MAIN_DB_PREFIX.
'c_exp_tax_range r';
303 $sql .=
' WHERE r.entity IN (0, '.getEntity($this->element).
')';
304 if ($default_c_exp_tax_cat > 0) {
305 $sql .=
' AND r.fk_c_exp_tax_cat = '.((int) $default_c_exp_tax_cat);
307 $sql .=
' GROUP BY r.fk_c_exp_tax_cat';
308 $sql .=
') as counts';
310 dol_syslog(get_called_class().
'::getMaxRangeNumber', LOG_DEBUG);
311 $resql = $this->db->query($sql);
313 $obj = $this->db->fetch_object($resql);
314 return $obj->nbRange;
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Parent class of all other business classes (invoices, contracts, proposals, orders,...
createCommon(User $user, $notrigger=0)
Create object in the database.
updateCommon(User $user, $notrigger=0)
Update object into database.
fetchCommon($id, $ref=null, $morewhere='', $noextrafields=0)
Load object in memory from the database.
deleteCommon(User $user, $notrigger=0, $forcechilddeletion=0)
Delete object in database.
Class to manage Dolibarr database access.
Class to manage inventories.
__construct(DoliDB $db)
Constructor.
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.
create(User $user, $notrigger=0)
Create object into database.
update(User $user, $notrigger=0)
Update object into database.
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=null, $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.