dolibarr 21.0.4
cashcontrol.class.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2008 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2009 Regis Houssin <regis.houssin@capnetworks.com>
4 * Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
5 * Copyright (C) 2018 Andreu Bisquerra <jove@bisquerra.com>
6 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
33{
37 public $element = 'cashcontrol';
38
42 public $table_element = 'pos_cash_fence';
43
47 public $picto = 'cash-register';
48
74 public $fields = array(
75 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 10),
76 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'position' => 15),
77 'ref' => array('type' => 'varchar(64)', 'label' => 'Ref', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 18),
78 'posmodule' => array('type' => 'varchar(30)', 'label' => 'Module', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 19),
79 'posnumber' => array('type' => 'varchar(30)', 'label' => 'Terminal', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 20, 'csslist' => 'width50 center'),
80 'label' => array('type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'visible' => 0, 'position' => 24),
81 'opening' => array('type' => 'price', 'label' => 'Opening', 'enabled' => 1, 'visible' => 1, 'position' => 25, 'csslist' => 'amount'),
82 'cash' => array('type' => 'price', 'label' => 'Cash', 'enabled' => 1, 'visible' => 1, 'position' => 30, 'csslist' => 'amount'),
83 'cheque' => array('type' => 'price', 'label' => 'Cheque', 'enabled' => 1, 'visible' => 1, 'position' => 33, 'csslist' => 'amount'),
84 'card' => array('type' => 'price', 'label' => 'CreditCard', 'enabled' => 1, 'visible' => 1, 'position' => 36, 'csslist' => 'amount'),
85 'year_close' => array('type' => 'integer', 'label' => 'Year', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 50, 'css' => 'center'),
86 'month_close' => array('type' => 'integer', 'label' => 'Month', 'enabled' => 1, 'visible' => 1, 'position' => 55, 'css' => 'center'),
87 'day_close' => array('type' => 'integer', 'label' => 'Day', 'enabled' => 1, 'visible' => 1, 'position' => 60, 'css' => 'center'),
88 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 500),
89 'date_valid' => array('type' => 'datetime', 'label' => 'DateValidation', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 502),
90 'tms' => array('type' => 'timestamp', 'label' => 'Tms', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'position' => 505),
91 'fk_user_creat' => array('type' => 'integer:User', 'label' => 'UserCreation', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 600),
92 'fk_user_valid' => array('type' => 'integer:User', 'label' => 'UserValidation', 'enabled' => 1, 'visible' => -1, 'notnull' => 1, 'position' => 602),
93 'import_key' => array('type' => 'varchar(14)', 'label' => 'Import key', 'enabled' => 1, 'visible' => 0, 'position' => 700),
94 'status' => array('type' => 'integer', 'label' => 'Status', 'enabled' => 1, 'visible' => 1, 'position' => 1000, 'notnull' => 1, 'index' => 1, 'arrayofkeyval' => array('0' => 'Draft', '1' => 'Validated')),
95 );
96
100 public $id;
101
105 public $label;
106
110 public $opening;
111
115 public $status;
116
120 public $year_close;
121
125 public $month_close;
126
130 public $day_close;
131
135 public $posmodule;
136
140 public $posnumber;
141
145 public $cash;
146
150 public $cheque;
151
155 public $card;
156
160 public $fk_user_creat;
161
165 public $date_valid;
166
170 public $fk_user_valid;
171
172
173 const STATUS_DRAFT = 0;
174 const STATUS_VALIDATED = 1;
175 const STATUS_CLOSED = 1; // For the moment CLOSED = VALIDATED
176
177
183 public function __construct(DoliDB $db)
184 {
185 $this->db = $db;
186
187 $this->ismultientitymanaged = 1;
188 $this->isextrafieldmanaged = 0;
189 }
190
191
199 public function create(User $user, $notrigger = 0)
200 {
201 global $conf;
202
203 $error = 0;
204
205 // Clean data
206 if (empty($this->cash)) {
207 $this->cash = 0;
208 }
209 if (empty($this->cheque)) {
210 $this->cheque = 0;
211 }
212 if (empty($this->card)) {
213 $this->card = 0;
214 }
215
216 // Insert request
217 $sql = "INSERT INTO ".MAIN_DB_PREFIX."pos_cash_fence (";
218 $sql .= "entity";
219 //$sql .= ", ref";
220 $sql .= ", opening";
221 $sql .= ", status";
222 $sql .= ", date_creation";
223 $sql .= ", posmodule";
224 $sql .= ", posnumber";
225 $sql .= ", day_close";
226 $sql .= ", month_close";
227 $sql .= ", year_close";
228 $sql .= ", cash";
229 $sql .= ", cheque";
230 $sql .= ", card";
231 $sql .= ", fk_user_creat";
232 $sql .= ") VALUES (";
233 //$sql .= "'(PROV)', ";
234 $sql .= ((int) $conf->entity);
235 $sql .= ", ".(is_numeric($this->opening) ? price2num($this->opening, 'MT') : 0);
236 $sql .= ", 0"; // Draft by default
237 $sql .= ", '".$this->db->idate(dol_now())."'";
238 $sql .= ", '".$this->db->escape($this->posmodule)."'";
239 $sql .= ", '".$this->db->escape($this->posnumber)."'";
240 $sql .= ", ".($this->day_close > 0 ? $this->day_close : "null");
241 $sql .= ", ".($this->month_close > 0 ? $this->month_close : "null");
242 $sql .= ", ".((int) $this->year_close);
243 $sql .= ", ".price2num($this->cash, 'MT');
244 $sql .= ", ".price2num($this->cheque, 'MT');
245 $sql .= ", ".price2num($this->card, 'MT');
246 $sql .= ", ".((int) $user->id);
247 $sql .= ")";
248
249 $this->db->begin();
250
251 dol_syslog(get_class($this)."::create", LOG_DEBUG);
252 $resql = $this->db->query($sql);
253 if (!$resql) {
254 $error++;
255 $this->errors[] = "Error ".$this->db->lasterror();
256 }
257
258 if (!$error) {
259 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."pos_cash_fence");
260
261 $sql = 'UPDATE '.MAIN_DB_PREFIX.'pos_cash_fence SET ref = rowid where rowid = '.((int) $this->id);
262 $this->db->query($sql);
263 }
264
265 // Commit or rollback
266 if ($error) {
267 foreach ($this->errors as $errmsg) {
268 dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
269 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
270 }
271 $this->db->rollback();
272 return -1 * $error;
273 } else {
274 $this->db->commit();
275 return $this->id;
276 }
277 }
278
286 public function valid(User $user, $notrigger = 0)
287 {
288 global $conf, $langs;
289 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
290
291 $error = 0;
292
293 // Protection
294 if ($this->status == self::STATUS_VALIDATED) {
295 dol_syslog(get_class($this)."::valid action abandoned: already validated", LOG_WARNING);
296 return 0;
297 }
298
299 $now = dol_now();
300
301 // Update request
302 $sql = "UPDATE ".MAIN_DB_PREFIX."pos_cash_fence";
303 $sql .= " SET status = ".self::STATUS_VALIDATED.",";
304 $sql .= " date_valid='".$this->db->idate($now)."',";
305 $sql .= " fk_user_valid = ".((int) $user->id);
306 $sql .= " WHERE rowid=".((int) $this->id);
307
308 $this->db->begin();
309
310 dol_syslog(get_class($this)."::close", LOG_DEBUG);
311 $resql = $this->db->query($sql);
312 if (!$resql) {
313 $error++;
314 $this->errors[] = "Error ".$this->db->lasterror();
315 }
316
317 if (!$error) {
318 $this->status = self::STATUS_VALIDATED;
319 $this->date_valid = $now;
320 $this->fk_user_valid = $user->id;
321 }
322
323 if (!$error && !$notrigger) {
324 // Call trigger
325 $result = $this->call_trigger('CASHCONTROL_VALIDATE', $user);
326 if ($result < 0) {
327 $error++;
328 }
329 // End call triggers
330 }
331
332 // Commit or rollback
333 if ($error) {
334 foreach ($this->errors as $errmsg) {
335 dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
336 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
337 }
338 $this->db->rollback();
339 return -1 * $error;
340 } else {
341 $this->db->commit();
342 return $this->id;
343 }
344 }
345
346
354 public function fetch($id, $ref = null)
355 {
356 $result = $this->fetchCommon($id, $ref);
357 //if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines();
358 return $result;
359 }
360
368 public function update(User $user, $notrigger = 0)
369 {
370 return $this->updateCommon($user, $notrigger);
371 }
372
380 public function delete(User $user, $notrigger = 0)
381 {
382 return $this->deleteCommon($user, $notrigger);
383 //return $this->deleteCommon($user, $notrigger, 1);
384 }
385
392 public function getLibStatut($mode = 0)
393 {
394 return $this->LibStatut($this->status, $mode);
395 }
396
397 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
405 public function LibStatut($status, $mode = 0)
406 {
407 // phpcs:enable
408 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
409 global $langs;
410 //$langs->load("mymodule");
411 $this->labelStatus[0] = $langs->transnoentitiesnoconv('Draft');
412 $this->labelStatus[1] = $langs->transnoentitiesnoconv('Closed');
413 $this->labelStatusShort[0] = $langs->transnoentitiesnoconv('Draft');
414 $this->labelStatusShort[1] = $langs->transnoentitiesnoconv('Closed');
415 }
416
417 $statusType = 'status0';
418 if ($status == self::STATUS_VALIDATED) {
419 $statusType = 'status6';
420 }
421
422 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
423 }
424
435 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
436 {
437 global $conf, $langs, $hookmanager;
438
439 if (!empty($conf->dol_no_mouse_hover)) {
440 $notooltip = 1; // Force disable tooltips
441 }
442
443 $result = '';
444
445 $newref = ($this->ref ? $this->ref : $this->id);
446
447 $label = '<u>'.$langs->trans("CashControl").'</u>';
448 $label .= '<br>';
449 $label .= '<b>'.$langs->trans('Ref').':</b> '.($this->ref ? $this->ref : $this->id);
450
451 $url = DOL_URL_ROOT.'/compta/cashcontrol/cashcontrol_card.php?id='.$this->id;
452
453 if ($option != 'nolink') {
454 // Add param to save lastsearch_values or not
455 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
456 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
457 $add_save_lastsearch_values = 1;
458 }
459 if ($add_save_lastsearch_values) {
460 $url .= '&save_lastsearch_values=1';
461 }
462 }
463
464 $linkclose = '';
465 if (empty($notooltip)) {
466 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
467 $label = $langs->trans("ShowMyObject");
468 $linkclose .= ' alt="'.dolPrintHTMLForAttribute($label).'"';
469 }
470 $linkclose .= ' title="'.dolPrintHTMLForAttribute($label).'"';
471 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
472 } else {
473 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
474 }
475
476 $linkstart = '<a href="'.$url.'"';
477 $linkstart .= $linkclose.'>';
478 $linkend = '</a>';
479
480 $result .= $linkstart;
481 if ($withpicto) {
482 $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
483 }
484 if ($withpicto != 2) {
485 $result .= $this->ref;
486 }
487 $result .= $linkend;
488 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
489
490 global $action;
491 $hookmanager->initHooks(array('cashfencedao'));
492 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
493 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
494 if ($reshook > 0) {
495 $result = $hookmanager->resPrint;
496 } else {
497 $result .= $hookmanager->resPrint;
498 }
499
500 return $result;
501 }
502
510 public function getKanbanView($option = '', $arraydata = null)
511 {
512 global $langs;
513
514 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
515
516 $return = '<div class="box-flex-item box-flex-grow-zero">';
517 $return .= '<div class="info-box info-box-sm">';
518 $return .= '<span class="info-box-icon bg-infobox-action">';
519 $return .= img_picto('', $this->picto);
520 //var_dump($this->fields['rowid']);exit;
521 $return .= '</span>';
522 $return .= '<div class="info-box-content">';
523 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1, '', 1) : $this->ref).'</span>';
524 if ($selected >= 0) {
525 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
526 }
527 if (property_exists($this, 'posmodule')) {
528 $return .= '<br><span class="opacitymedium">'.substr($langs->trans("Module/Application"), 0, 12).'</span> : <span class="info-box-label">'.$this->posmodule.'</span>';
529 }
530 if (property_exists($this, 'year_close')) {
531 $return .= '<br><span class="info-box-label opacitymedium" >'.$langs->trans("Year").'</span> : <span>'.$this->year_close.'</span>';
532 }
533 if (method_exists($this, 'getLibStatut')) {
534 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
535 }
536 $return .= '</div>';
537 $return .= '</div>';
538 $return .= '</div>';
539 return $return;
540 }
541}
$object ref
Definition info.php:89
Class to manage cash fence.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
LibStatut($status, $mode=0)
Return the status.
valid(User $user, $notrigger=0)
Validate cash fence.
update(User $user, $notrigger=0)
Update object into database.
getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
Return clickable link of object (with eventually picto)
$fields
'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]',...
create(User $user, $notrigger=0)
Create in database.
getLibStatut($mode=0)
Return label of the status.
__construct(DoliDB $db)
Constructor.
fetch($id, $ref=null)
Load object in memory from the database.
Parent class of all other business classes (invoices, contracts, proposals, orders,...
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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
Class to manage Dolibarr database access.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:171
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_now($mode='auto')
Return date for now.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79