dolibarr  20.0.0-beta
mod_takepos_ref_universal.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
5  * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
6  * Copyright (C) 2013 Juanjo Menent <jmenent@2byte.es>
7  * Copyright (C) 2020 Open-DSI <support@open-dsi.fr>
8  * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 3 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program. If not, see <https://www.gnu.org/licenses/>.
22  * or see https://www.gnu.org/
23  */
24 
31 dol_include_once('/core/modules/takepos/modules_takepos.php');
32 
37 {
42  public $version = 'dolibarr';
43 
47  public $error = '';
48 
53  public $nom = 'Universal';
54 
61  public function info($langs)
62  {
63  global $db, $langs;
64 
65  $langs->load('cashdesk@cashdesk');
66 
67  $form = new Form($db);
68 
69  $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n";
70  $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
71  $texte .= '<input type="hidden" name="token" value="'.newToken().'">';
72  $texte .= '<input type="hidden" name="action" value="updateMask">';
73  $texte .= '<input type="hidden" name="maskconst" value="TAKEPOS_REF_UNIVERSAL_MASK">';
74  $texte .= '<table class="nobordernopadding" width="100%">';
75 
76  $tooltip = $langs->trans('GenericMaskCodes', $langs->transnoentities('CashDesk'), $langs->transnoentities('CashDesk'));
77  $tooltip .= $langs->trans('GenericMaskCodes2');
78  $tooltip .= $langs->trans('GenericMaskCodes3');
79  $tooltip .= $langs->trans('GenericMaskCodes4a', $langs->transnoentities('CashDesk'), $langs->transnoentities('CashDesk'));
80  $tooltip .= $langs->trans('GenericMaskCodes5');
81  $tooltip .= $langs->trans('CashDeskGenericMaskCodes6');
82 
83  // Setting up the prefix
84  $texte .= '<tr><td>'.$langs->trans("Mask").':</td>';
85  $texte .= '<td class="right">'.$form->textwithpicto('<input type="text" class="flat minwidth175" name="maskvalue" value="'.getDolGlobalString('TAKEPOS_REF_UNIVERSAL_MASK').'">', $tooltip, 1, 1).'</td>';
86 
87  $texte .= '<td class="left" rowspan="2"><input type="submit" class="button button-edit reposition smallpaddingimp" name="Button"value="'.$langs->trans("Modify").'"></td>';
88 
89  $texte .= '</tr>';
90 
91  $texte .= '</table>';
92  $texte .= '</form>';
93 
94  return $texte;
95  }
96 
102  public function getExample()
103  {
104  global $conf, $langs, $mysoc;
105 
106  $old_code_client = $mysoc->code_client;
107  $mysoc->code_client = 'CCCCCCCCCC';
108  $numExample = $this->getNextValue($mysoc, '');
109  $mysoc->code_client = $old_code_client;
110 
111  if (!$numExample) {
112  $numExample = $langs->trans('NotConfigured');
113  }
114  return $numExample;
115  }
116 
125  public function getNextValue($objsoc = null, $invoice = null, $mode = 'next')
126  {
127  global $db;
128 
129  require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
130 
131  // We define search criteria counter
132  $mask = getDolGlobalString('TAKEPOS_REF_UNIVERSAL_MASK');
133 
134  if (!$mask) {
135  $this->error = 'NotConfigured';
136  return 0;
137  }
138 
139  // Get entities
140  $entity = getEntity('invoicenumber', 1, $invoice);
141 
142  $date = (empty($invoice->date) ? dol_now() : $invoice->date);
143  $pos_source = is_object($invoice) && $invoice->pos_source > 0 ? $invoice->pos_source : 0;
144  $mask = str_replace('{TN}', $pos_source, $mask);
145  $numFinal = get_next_value($db, $mask, 'facture', 'ref', '', $objsoc, $date, $mode, false, null, $entity);
146 
147  return $numFinal;
148  }
149 
150 
159  public function getNumRef($objsoc, $objforref)
160  {
161  return $this->getNextValue($objsoc, $objforref);
162  }
163 }
Class to manage generation of HTML components Only common components must be here.
Parent Class of the models to number the cash register receipts.
Class to manage ref numbering of takepos cards with rule universal.
getExample()
Return an example of numbering.
getNumRef($objsoc, $objforref)
Return next free value.
getNextValue($objsoc=null, $invoice=null, $mode='next')
Return next free value.
info($langs)
return description of the numbering model
get_next_value($db, $mask, $table, $field, $where='', $objsoc='', $date='', $mode='next', $bentityon=true, $objuser=null, $forceentity=null)
Return last or next value for a mask (according to area we should not reset)
if(!function_exists('dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
dol_now($mode='auto')
Return date for now.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.