27require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
37 public $module =
'accountancy';
42 public $element =
'accounting_transaction_template_det';
47 public $table_element =
'accounting_transaction_template_det';
52 public $ismultientitymanaged = 0;
57 public $isextrafieldmanaged = 0;
62 public $picto =
'fa-file';
93 public $fields = array(
94 "rowid" => array(
"type" =>
"integer",
"label" =>
"TechnicalID",
"enabled" => 1,
'position' => 1,
'notnull' => 1,
"visible" => 0,
"noteditable" => 1,
"index" => 1,
"css" =>
"left",
"comment" =>
"Id"),
95 "fk_transaction_template" => array(
"type" =>
"integer",
"label" =>
"Template",
"enabled" => 1,
'position' => 5,
'notnull' => 1,
"visible" => 0,
"noteditable" => 1,
"foreignkey" =>
"accounting_transaction_template.rowid"),
96 "general_account" => array(
"type" =>
"varchar(32)",
"label" =>
"AccountNumber",
"enabled" => 1,
'position' => 10,
'notnull' => 1,
"visible" => 1,
"css" =>
"minwidth100"),
97 "general_label" => array(
"type" =>
"varchar(255)",
"label" =>
"AccountLabel",
"enabled" => 1,
'position' => 20,
'notnull' => 1,
"visible" => 1,
"css" =>
"minwidth200"),
98 "subledger_account" => array(
"type" =>
"varchar(32)",
"label" =>
"SubledgerAccount",
"enabled" => 1,
'position' => 30,
'notnull' => 0,
"visible" => 1,
"css" =>
"minwidth100"),
99 "subledger_label" => array(
"type" =>
"varchar(255)",
"label" =>
"SubledgerLabel",
"enabled" => 1,
'position' => 40,
'notnull' => 0,
"visible" => 1,
"css" =>
"minwidth200"),
100 "operation_label" => array(
"type" =>
"varchar(255)",
"label" =>
"OperationLabel",
"enabled" => 1,
'position' => 50,
'notnull' => 0,
"visible" => 1,
"css" =>
"minwidth200"),
101 "debit" => array(
"type" =>
"double(24,8)",
"label" =>
"Debit",
"enabled" => 1,
'position' => 60,
'notnull' => 0,
"visible" => 1,
"css" =>
"maxwidth75 right"),
102 "credit" => array(
"type" =>
"double(24,8)",
"label" =>
"Credit",
"enabled" => 1,
'position' => 70,
'notnull' => 0,
"visible" => 1,
"css" =>
"maxwidth75 right"),
114 public $fk_transaction_template;
119 public $general_account;
124 public $general_label;
129 public $subledger_account;
134 public $subledger_label;
139 public $operation_label;
164 public $date_creation;
174 public $fk_user_creat;
179 public $fk_user_modif;
189 global
$conf, $langs;
193 if (!
getDolGlobalInt(
'MAIN_SHOW_TECHNICAL_ID') && isset($this->fields[
'rowid'])) {
194 $this->fields[
'rowid'][
'visible'] = 0;
198 foreach ($this->fields as $key => $val) {
199 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
200 unset($this->fields[$key]);
205 if (is_object($langs)) {
206 foreach ($this->fields as $key => $val) {
207 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
208 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
209 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
226 return $resultcreate;
236 public function fetch($id, $noextrafields = 0)
238 $result = $this->
fetchCommon($id,
'',
'', $noextrafields);
253 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
261 $sql .=
" FROM ".$this->db->prefix().$this->table_element.
" as t";
262 if (isset($this->isextrafieldmanaged) && $this->isextrafieldmanaged == 1) {
263 $sql .=
" LEFT JOIN ".$this->db->prefix().$this->table_element.
"_extrafields as te ON te.fk_object = t.rowid";
265 $sql .=
" WHERE 1 = 1";
269 if (count($filter) > 0) {
270 foreach ($filter as $key => $value) {
271 if ($key ===
'customsql') {
273 $sqlwhere[] = $value;
277 $columnName = preg_replace(
'/^t\./',
'', $key);
279 if (isset($this->fields[$columnName])) {
280 $type = $this->fields[$columnName][
'type'];
281 if (preg_match(
'/^integer/', $type)) {
282 if (is_int($value)) {
284 $sqlwhere[] = $key .
" = " . intval($value);
285 } elseif (is_array($value)) {
289 $sqlwhere[] = $key .
' IN (' . $this->db->sanitize(implode(
',', array_map(
'intval', $value))) .
')';
292 } elseif (in_array($type, array(
'date',
'datetime',
'timestamp'))) {
293 $sqlwhere[] = $key .
" = '" . $this->db->idate($value) .
"'";
299 if (is_array($value) && count($value)) {
300 $escapedValues = array();
301 foreach ($value as $v) {
302 $escapedValues[] = $this->db->escape($v);
304 $value = implode(
',', $escapedValues);
305 $sqlwhere[] = $key .
' IN (' . $this->db->sanitize($value, 1) .
')';
306 } elseif (is_scalar($value)) {
307 if (strpos($value,
'%') ===
false) {
308 $sqlwhere[] = $key .
" = '" . $this->db->sanitize($this->db->escape($value)) .
"'";
310 $sqlwhere[] = $key .
" LIKE '%" . $this->db->escape($this->db->escapeforlike($value)) .
"%'";
315 if (count($sqlwhere) > 0) {
316 $sql .=
" AND (".implode(
" ".$filtermode.
" ", $sqlwhere).
")";
319 if (!empty($sortfield)) {
320 $sql .= $this->db->order($sortfield, $sortorder);
322 if (!empty($limit)) {
323 $sql .= $this->db->plimit($limit, $offset);
326 $resql = $this->db->query($sql);
328 $num = $this->db->num_rows($resql);
330 while ($i < ($limit ? min($limit, $num) : $num)) {
331 $obj = $this->db->fetch_object($resql);
333 $record =
new self($this->db);
334 $record->setVarsFromFetchObj($obj);
336 $records[$record->id] = $record;
340 $this->db->free($resql);
344 $this->errors[] =
'Error '.$this->db->lasterror();
345 dol_syslog(__METHOD__.
' '.implode(
',', $this->errors), LOG_ERR);
370 public function delete(
User $user, $notrigger = 0)
Class for BookkeepingTemplateLine.
update(User $user, $notrigger=0)
Update object into database.
__construct(DoliDB $db)
Constructor.
create(User $user, $notrigger=0)
Create object into database.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter=array(), $filtermode='AND')
Load list of objects in memory from the database.
fetch($id, $noextrafields=0)
Load object in memory from the database.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
createCommon(User $user, $notrigger=0)
Create object in the database.
getFieldList($alias='', $excludefields=array())
Function to concat keys of fields.
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 Dolibarr users.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.