27require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
37 public $element =
'expenserule';
42 public $table_element =
'expensereport_rules';
47 public $fk_element =
'fk_expense_rule';
89 public $fk_c_type_fees;
95 public $code_expense_rules_type;
115 public $fields = array(
116 'rowid' => array(
'type' =>
'integer',
'index' => 1,
'label' =>
'ID',
'enabled' => 1,
'visible' => -1,
'position' => 10),
117 'dates' => array(
'type' =>
'date',
'label' =>
'Dates',
'enabled' => 1,
'visible' => -1,
'position' => 20),
118 'datee' => array(
'type' =>
'date',
'label' =>
'Datee',
'enabled' => 1,
'visible' => -1,
'position' => 30),
119 'amount' => array(
'type' =>
'double',
'label' =>
'Amount',
'enabled' => 1,
'visible' => -1,
'position' => 40),
120 'restrictive' => array(
'type' =>
'integer',
'label' =>
'Restrictive',
'enabled' => 1,
'visible' => -1,
'position' => 50),
121 'fk_user' => array(
'type' =>
'integer',
'label' =>
'User',
'enabled' => 1,
'visible' => -1,
'position' => 60),
122 'fk_usergroup' => array(
'type' =>
'integer',
'label' =>
'Usergroup',
'enabled' => 1,
'visible' => -1,
'position' => 70),
123 'fk_c_type_fees' => array(
'type' =>
'integer',
'label' =>
'Type fees',
'enabled' => 1,
'visible' => -1,
'position' => 80),
124 'code_expense_rules_type' => array(
'type' =>
'string',
'label' =>
'Expense rule code',
'enabled' => 1,
'visible' => -1,
'position' => 90),
125 'is_for_all' => array(
'type' =>
'integer',
'label' =>
'IsForAll',
'enabled' => 1,
'visible' => -1,
'position' => 100),
126 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'enabled' => 1,
'visible' => -2,
'position' => 110),
154 return $resultcreate;
165 public function fetch($id, $ref =
null)
189 public function delete(
User $user, $notrigger = 0)
204 public function getAllRule($fk_c_type_fees = 0, $date =
'', $fk_user = 0)
208 $sql =
'SELECT er.rowid';
209 $sql .=
' FROM '.MAIN_DB_PREFIX.
'expensereport_rules er';
210 $sql .=
' WHERE er.entity IN (0,'.getEntity($this->element).
')';
211 if (!empty($fk_c_type_fees)) {
212 $sql .=
' AND er.fk_c_type_fees IN (-1, '.((int) $fk_c_type_fees).
')';
215 $sql .=
" AND er.dates <= '".$this->db->idate($date).
"'";
216 $sql .=
" AND er.datee >= '".$this->db->idate($date).
"'";
219 $sql .=
' AND (er.is_for_all = 1';
220 $sql .=
' OR er.fk_user = '.((int) $fk_user);
221 $sql .=
' OR er.fk_usergroup IN (SELECT ugu.fk_usergroup FROM '.MAIN_DB_PREFIX.
'usergroup_user ugu WHERE ugu.fk_user = '.((int) $fk_user).
') )';
223 $sql .=
' ORDER BY er.is_for_all, er.fk_usergroup, er.fk_user';
227 $resql = $this->db->query($sql);
229 while ($obj = $this->db->fetch_object($resql)) {
231 if ($rule->fetch($obj->rowid) > 0) {
232 $rules[$rule->id] = $rule;
251 include_once DOL_DOCUMENT_ROOT.
'/user/class/usergroup.class.php';
253 if ($this->fk_usergroup > 0) {
255 if ($group->fetch($this->fk_usergroup) > 0) {
258 $this->error = $group->error;
259 $this->errors[] = $this->error;
273 include_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
275 if ($this->fk_user > 0) {
276 $u =
new User($this->db);
277 if ($u->fetch($this->fk_user) > 0) {
280 $this->error = $u->error;
281 $this->errors[] = $this->error;
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.
create(User $user, $notrigger=0)
Create object into database.
getGroupLabel()
Return the label of group for the current object.
getAllRule($fk_c_type_fees=0, $date='', $fk_user=0)
Return all rules or filtered by something.
fetch($id, $ref=null)
Load object in memory from the database.
getUserName()
Return the name of user for the current object.
update(User $user, $notrigger=0)
Update object into database.
__construct(DoliDB $db)
Constructor.
Class to manage user groups.
Class to manage Dolibarr users.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
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.