dolibarr 21.0.0-alpha
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' => -2, '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, 'css' => '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 close', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 50, 'css' => 'center'),
86 'month_close' => array('type' => 'integer', 'label' => 'Month close', 'enabled' => 1, 'visible' => 1, 'position' => 55, 'css' => 'center'),
87 'day_close' => array('type' => 'integer', 'label' => 'Day close', '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 public $label;
102 public $opening;
103 public $status;
104 public $year_close;
105 public $month_close;
106 public $day_close;
107 public $posmodule;
108 public $posnumber;
109 public $cash;
110 public $cheque;
111 public $card;
112
113 public $fk_user_creat;
114
118 public $date_valid;
119 public $fk_user_valid;
120
121
122 const STATUS_DRAFT = 0;
123 const STATUS_VALIDATED = 1;
124 const STATUS_CLOSED = 1; // For the moment CLOSED = VALIDATED
125
126
132 public function __construct(DoliDB $db)
133 {
134 $this->db = $db;
135
136 $this->ismultientitymanaged = 1;
137 $this->isextrafieldmanaged = 0;
138 }
139
140
148 public function create(User $user, $notrigger = 0)
149 {
150 global $conf;
151
152 $error = 0;
153
154 // Clean data
155 if (empty($this->cash)) {
156 $this->cash = 0;
157 }
158 if (empty($this->cheque)) {
159 $this->cheque = 0;
160 }
161 if (empty($this->card)) {
162 $this->card = 0;
163 }
164
165 // Insert request
166 $sql = "INSERT INTO ".MAIN_DB_PREFIX."pos_cash_fence (";
167 $sql .= "entity";
168 //$sql .= ", ref";
169 $sql .= ", opening";
170 $sql .= ", status";
171 $sql .= ", date_creation";
172 $sql .= ", posmodule";
173 $sql .= ", posnumber";
174 $sql .= ", day_close";
175 $sql .= ", month_close";
176 $sql .= ", year_close";
177 $sql .= ", cash";
178 $sql .= ", cheque";
179 $sql .= ", card";
180 $sql .= ") VALUES (";
181 //$sql .= "'(PROV)', ";
182 $sql .= ((int) $conf->entity);
183 $sql .= ", ".(is_numeric($this->opening) ? price2num($this->opening, 'MT') : 0);
184 $sql .= ", 0"; // Draft by default
185 $sql .= ", '".$this->db->idate(dol_now())."'";
186 $sql .= ", '".$this->db->escape($this->posmodule)."'";
187 $sql .= ", '".$this->db->escape($this->posnumber)."'";
188 $sql .= ", ".($this->day_close > 0 ? $this->day_close : "null");
189 $sql .= ", ".($this->month_close > 0 ? $this->month_close : "null");
190 $sql .= ", ".((int) $this->year_close);
191 $sql .= ", ".price2num($this->cash, 'MT');
192 $sql .= ", ".price2num($this->cheque, 'MT');
193 $sql .= ", ".price2num($this->card, 'MT');
194 $sql .= ")";
195
196 $this->db->begin();
197
198 dol_syslog(get_class($this)."::create", LOG_DEBUG);
199 $resql = $this->db->query($sql);
200 if (!$resql) {
201 $error++;
202 $this->errors[] = "Error ".$this->db->lasterror();
203 }
204
205 if (!$error) {
206 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."pos_cash_fence");
207
208 $sql = 'UPDATE '.MAIN_DB_PREFIX.'pos_cash_fence SET ref = rowid where rowid = '.((int) $this->id);
209 $this->db->query($sql);
210 }
211
212 // Commit or rollback
213 if ($error) {
214 foreach ($this->errors as $errmsg) {
215 dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
216 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
217 }
218 $this->db->rollback();
219 return -1 * $error;
220 } else {
221 $this->db->commit();
222 return $this->id;
223 }
224 }
225
233 public function valid(User $user, $notrigger = 0)
234 {
235 global $conf, $langs;
236 require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
237
238 $error = 0;
239
240 // Protection
241 if ($this->status == self::STATUS_VALIDATED) {
242 dol_syslog(get_class($this)."::valid action abandoned: already validated", LOG_WARNING);
243 return 0;
244 }
245
246 $now = dol_now();
247
248 // Update request
249 $sql = "UPDATE ".MAIN_DB_PREFIX."pos_cash_fence";
250 $sql .= " SET status = ".self::STATUS_VALIDATED.",";
251 $sql .= " date_valid='".$this->db->idate($now)."',";
252 $sql .= " fk_user_valid = ".$user->id;
253 $sql .= " WHERE rowid=".((int) $this->id);
254
255 $this->db->begin();
256
257 dol_syslog(get_class($this)."::close", LOG_DEBUG);
258 $resql = $this->db->query($sql);
259 if (!$resql) {
260 $error++;
261 $this->errors[] = "Error ".$this->db->lasterror();
262 }
263
264 if (!$error) {
265 $this->status = self::STATUS_VALIDATED;
266 $this->date_valid = $now;
267 $this->fk_user_valid = $user->id;
268 }
269
270 if (!$error && !$notrigger) {
271 // Call trigger
272 $result = $this->call_trigger('CASHCONTROL_VALIDATE', $user);
273 if ($result < 0) {
274 $error++;
275 }
276 // End call triggers
277 }
278
279 // Commit or rollback
280 if ($error) {
281 foreach ($this->errors as $errmsg) {
282 dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
283 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
284 }
285 $this->db->rollback();
286 return -1 * $error;
287 } else {
288 $this->db->commit();
289 return $this->id;
290 }
291 }
292
293
301 public function fetch($id, $ref = null)
302 {
303 $result = $this->fetchCommon($id, $ref);
304 //if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines();
305 return $result;
306 }
307
315 public function update(User $user, $notrigger = 0)
316 {
317 return $this->updateCommon($user, $notrigger);
318 }
319
327 public function delete(User $user, $notrigger = 0)
328 {
329 return $this->deleteCommon($user, $notrigger);
330 //return $this->deleteCommon($user, $notrigger, 1);
331 }
332
339 public function getLibStatut($mode = 0)
340 {
341 return $this->LibStatut($this->status, $mode);
342 }
343
344 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
352 public function LibStatut($status, $mode = 0)
353 {
354 // phpcs:enable
355 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
356 global $langs;
357 //$langs->load("mymodule");
358 $this->labelStatus[0] = $langs->transnoentitiesnoconv('Draft');
359 $this->labelStatus[1] = $langs->transnoentitiesnoconv('Closed');
360 $this->labelStatusShort[0] = $langs->transnoentitiesnoconv('Draft');
361 $this->labelStatusShort[1] = $langs->transnoentitiesnoconv('Closed');
362 }
363
364 $statusType = 'status0';
365 if ($status == self::STATUS_VALIDATED) {
366 $statusType = 'status6';
367 }
368
369 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status], '', $statusType, $mode);
370 }
371
382 public function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
383 {
384 global $conf, $langs, $hookmanager;
385
386 if (!empty($conf->dol_no_mouse_hover)) {
387 $notooltip = 1; // Force disable tooltips
388 }
389
390 $result = '';
391
392 $newref = ($this->ref ? $this->ref : $this->id);
393
394 $label = '<u>'.$langs->trans("CashControl").'</u>';
395 $label .= '<br>';
396 $label .= '<b>'.$langs->trans('Ref').':</b> '.($this->ref ? $this->ref : $this->id);
397
398 $url = DOL_URL_ROOT.'/compta/cashcontrol/cashcontrol_card.php?id='.$this->id;
399
400 if ($option != 'nolink') {
401 // Add param to save lastsearch_values or not
402 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
403 if ($save_lastsearch_value == -1 && isset($_SERVER["PHP_SELF"]) && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) {
404 $add_save_lastsearch_values = 1;
405 }
406 if ($add_save_lastsearch_values) {
407 $url .= '&save_lastsearch_values=1';
408 }
409 }
410
411 $linkclose = '';
412 if (empty($notooltip)) {
413 if (getDolGlobalString('MAIN_OPTIMIZEFORTEXTBROWSER')) {
414 $label = $langs->trans("ShowMyObject");
415 $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
416 }
417 $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
418 $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
419 } else {
420 $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
421 }
422
423 $linkstart = '<a href="'.$url.'"';
424 $linkstart .= $linkclose.'>';
425 $linkend = '</a>';
426
427 $result .= $linkstart;
428 if ($withpicto) {
429 $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);
430 }
431 if ($withpicto != 2) {
432 $result .= $this->ref;
433 }
434 $result .= $linkend;
435 //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
436
437 global $action;
438 $hookmanager->initHooks(array('cashfencedao'));
439 $parameters = array('id' => $this->id, 'getnomurl' => &$result);
440 $reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
441 if ($reshook > 0) {
442 $result = $hookmanager->resPrint;
443 } else {
444 $result .= $hookmanager->resPrint;
445 }
446
447 return $result;
448 }
449
457 public function getKanbanView($option = '', $arraydata = null)
458 {
459 global $langs;
460
461 $selected = (empty($arraydata['selected']) ? 0 : $arraydata['selected']);
462
463 $return = '<div class="box-flex-item box-flex-grow-zero">';
464 $return .= '<div class="info-box info-box-sm">';
465 $return .= '<span class="info-box-icon bg-infobox-action">';
466 $return .= img_picto('', $this->picto);
467 //var_dump($this->fields['rowid']);exit;
468 $return .= '</span>';
469 $return .= '<div class="info-box-content">';
470 $return .= '<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this, 'getNomUrl') ? $this->getNomUrl(1, 1) : $this->ref).'</span>';
471 if ($selected >= 0) {
472 $return .= '<input id="cb'.$this->id.'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->id.'"'.($selected ? ' checked="checked"' : '').'>';
473 }
474 if (property_exists($this, 'posmodule')) {
475 $return .= '<br><span class="opacitymedium">'.substr($langs->trans("Module/Application"), 0, 12).'</span> : <span class="info-box-label">'.$this->posmodule.'</span>';
476 }
477 if (property_exists($this, 'year_close')) {
478 $return .= '<br><span class="info-box-label opacitymedium" >'.$langs->trans("Year").'</span> : <span>'.$this->year_close.'</span>';
479 }
480 if (method_exists($this, 'getLibStatut')) {
481 $return .= '<br><div class="info-box-status">'.$this->getLibStatut(3).'</div>';
482 }
483 $return .= '</div>';
484 $return .= '</div>';
485 $return .= '</div>';
486 return $return;
487 }
488}
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition security.php:626
$object ref
Definition info.php:79
Class to manage cash fence.
getKanbanView($option='', $arraydata=null)
Return clicable 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 clicable 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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
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 '.
dol_now($mode='auto')
Return date for now.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.