dolibarr 25.0.0-alpha
card-rec.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2023 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
6 * Copyright (C) 2013-2023 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
8 * Copyright (C) 2012 Cedric Salvador <csalvador@gpcsolutions.fr>
9 * Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
10 * Copyright (C) 2016 Meziane Sof <virtualsof@yahoo.fr>
11 * Copyright (C) 2017-2026 Frédéric France <frederic.france@free.fr>
12 * Copyright (C) 2023 Nick Fragoulis
13 * Copyright (C) 2024-2026 MDW <mdeweerd@users.noreply.github.com>
14 * Copyright (C) 2026 Joris Le Blansch <ping@apio.systems>
15 * Copyright (C) 2026 Jose Martinez <jose.martinez@pichinov.com>
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 3 of the License, or
20 * (at your option) any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with this program. If not, see <https://www.gnu.org/licenses/>.
29 */
30
37// Load Dolibarr environment
38require '../../main.inc.php';
48require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php';
49require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
50require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
51if (isModEnabled('project')) {
52 include_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
53}
54require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
55require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
56require_once DOL_DOCUMENT_ROOT.'/core/lib/invoice.lib.php';
57
58// Load translation files required by the page
59$langs->loadLangs(array('bills', 'companies', 'compta', 'admin', 'other', 'products', 'banks'));
60
61$action = GETPOST('action', 'aZ09');
62$massaction = GETPOST('massaction', 'alpha');
63$show_files = GETPOSTINT('show_files');
64$confirm = GETPOST('confirm', 'alpha');
65$cancel = GETPOST('cancel', 'alpha');
66$toselect = GETPOST('toselect', 'array:int');
67$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'invoicetemplatelist'; // To manage different context of search
68$backtopage = GETPOST('backtopage', 'alpha'); // if not set, a default page will be used
69$backtopageforcancel = GETPOST('backtopageforcancel', 'alpha'); // if not set, $backtopage will be used
70
71
72$id = (GETPOSTINT('facid') ? GETPOSTINT('facid') : GETPOSTINT('id'));
73$lineid = GETPOSTINT('lineid');
74$ref = GETPOST('ref', 'alpha');
75$socid = 0;
76if ($user->socid) {
77 $socid = $user->socid;
78}
79$objecttype = 'facture_rec';
80if ($action == "create" || $action == "add") {
81 $objecttype = '';
82}
83$projectid = GETPOSTINT('projectid');
84
85$year_date_when = GETPOST('year_date_when');
86$month_date_when = GETPOST('month_date_when');
87$selectedLines = GETPOST('toselect', 'array:int');
88
89$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
90$sortfield = GETPOST('sortfield', 'aZ09comma');
91$sortorder = GETPOST('sortorder', 'aZ09comma');
92$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
93if (empty($page) || $page == -1) {
94 $page = 0;
95} // If $page is not defined, or '' or -1
96$offset = $limit * $page;
97if (!$sortorder) {
98 $sortorder = 'DESC';
99}
100if (!$sortfield) {
101 $sortfield = 'f.titre';
102}
103$pageprev = $page - 1;
104$pagenext = $page + 1;
105
106$object = new FactureRec($db);
107if (($id > 0 || $ref) && $action != 'create' && $action != 'add') {
108 $ret = $object->fetch($id, $ref);
109 if ($ret < 0) {
111 } elseif (! $ret) {
112 setEventMessages($langs->trans("ErrorRecordNotFound"), null, 'errors');
113 }
114}
115
116// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
117$hookmanager->initHooks(array('invoicereccard', 'globalcard'));
118
119// fetch optionals attributes and labels
120$extrafields->fetch_name_optionals_label($object->table_element);
121
122$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
123
124$permissiontoadd = $user->hasRight('facture', 'creer');
125$permissionnote = $user->hasRight('facture', 'creer'); // Used by the include of actions_setnotes.inc.php
126$permissiondellink = $user->hasRight('facture', 'creer'); // Used by the include of actions_dellink.inc.php
127$permissiontoedit = $user->hasRight('facture', 'creer'); // Used by the include of actions_lineupdonw.inc.php
128$permissiontoeditextra = $permissiontoadd;
129if (GETPOST('attribute', 'aZ09') && isset($extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')])) {
130 // For action 'update_extras', is there a specific permission set for the attribute to update
131 $permissiontoeditextra = dol_eval((string) $extrafields->attributes[$object->table_element]['perms'][GETPOST('attribute', 'aZ09')]);
132}
133
134$usercanread = $user->hasRight('facture', 'lire');
135$usercancreate = $user->hasRight('facture', 'creer');
136$usercanissuepayment = $user->hasRight('facture', 'paiement');
137$usercandelete = $user->hasRight('facture', 'supprimer');
138
139// Advanced permissions
140$usercanvalidate = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $usercancreate) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('facture', 'invoice_advance', 'validate')));
141$usercansend = (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || $user->hasRight('facture', 'invoice_advance', 'send'));
142$usercanreopen = (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || $user->hasRight('facture', 'invoice_advance', 'reopen'));
143$usercanunvalidate = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight('facture', 'invoice_advance', 'unvalidate')));
144$usermustrespectpricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('produit', 'ignore_price_min_advance')) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
145
146// Other permissions
147$usercanproductignorepricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight('produit', 'ignore_price_min_advance')) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
148$usercancreatemargin = $user->hasRight("margins", "creer");
149$usercanreadallmargin = $user->hasRight("margins", "liretous");
150$usercancreatewithdrarequest = $user->hasRight("prelevement", "bons", "creer");
151
152$now = dol_now();
153
154$error = 0;
155
156// Security check
157$result = restrictedArea($user, 'facture', $object->id, $objecttype);
158
159
160/*
161 * Actions
162 */
163
164if (GETPOST('cancel', 'alpha')) {
165 if ($action != 'updateline' && $action != 'setdate_when') {
166 $action = 'list';
167 $massaction = '';
168 } else {
169 $action = '';
170 $cancel = '';
171 }
172}
173if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
174 $massaction = '';
175}
176
177$parameters = array('socid' => $socid);
178$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
179if ($reshook < 0) {
180 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
181}
182
183if (empty($reshook)) {
184 $backurlforlist = DOL_URL_ROOT.'/compta/facture/invoicetemplate_list.php';
185
186 if (empty($backtopage) || ($cancel && empty($id))) {
187 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
188 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
189 $backtopage = $backurlforlist;
190 } else {
191 $backtopage = DOL_URL_ROOT.'/compta/facture/invoicetemplate_list.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
192 }
193 }
194 }
195
196 // include DOL_DOCUMENT_ROOT.'/core/actions_addupdatedelete.inc.php';
197 if ($cancel) {
198 /*var_dump($cancel);var_dump($backtopage);var_dump($backtopageforcancel);exit;*/
199 if (!empty($backtopageforcancel)) {
200 header("Location: ".$backtopageforcancel);
201 exit;
202 } elseif (!empty($backtopage)) {
203 header("Location: ".$backtopage);
204 exit;
205 }
206 $action = '';
207 }
208
209 // Selection of new fields
210 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
211
212 // Set note
213 include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be 'include', not 'include_once'
214
215 include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be 'include', not 'include_once'
216
217 include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be 'include', not 'include_once'
218
219 // Mass actions
220 /*$objectclass='MyObject';
221 $objectlabel='MyObject';
222 $uploaddir = $conf->mymodule->dir_output;
223 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';*/
224
225 // Create predefined invoice
226 if ($action == 'add' && $usercancreate) {
227 if (!GETPOST('title', 'alphanohtml')) {
228 setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("Title")), null, 'errors');
229 $action = "create";
230 $error++;
231 }
232
233 $frequency = GETPOSTINT('frequency');
234 $reyear = GETPOSTINT('reyear');
235 $remonth = GETPOSTINT('remonth');
236 $reday = GETPOSTINT('reday');
237 $rehour = GETPOSTINT('rehour');
238 $remin = GETPOSTINT('remin');
239 $nb_gen_max = GETPOSTINT('nb_gen_max');
240 //if (empty($nb_gen_max)) $nb_gen_max =0;
241
242 if (GETPOSTINT('frequency')) {
243 if (empty($reyear) || empty($remonth) || empty($reday)) {
244 setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("Date")), null, 'errors');
245 $action = "create";
246 $error++;
247 }
248 /*if ($nb_gen_max === '') {
249 setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("MaxPeriodNumber")), null, 'errors');
250 $action = "create";
251 $error++;
252 }*/
253 }
254
255 if (!$error) {
256 $object->subtype = GETPOSTINT('subtype');
257 $object->title = GETPOST('title', 'alphanohtml');
258
259 $object->note_private = GETPOST('note_private', 'restricthtml');
260 $object->note_public = GETPOST('note_public', 'restricthtml');
261 $object->model_pdf = GETPOST('modelpdf', 'alphanohtml');
262 $object->usenewprice = GETPOSTINT('usenewprice');
263
264 $object->mode_reglement_id = GETPOSTINT('mode_reglement_id');
265 $object->cond_reglement_id = GETPOSTINT('cond_reglement_id');
266 $object->fk_societe_rib = GETPOSTINT('accountcustomerid');
267 $object->rule_for_lines_dates = GETPOST('rule_for_lines_dates', 'alpha');
268
269 $object->frequency = $frequency;
270 $object->unit_frequency = GETPOST('unit_frequency', 'alpha');
271 $object->nb_gen_max = $nb_gen_max;
272 $object->auto_validate = GETPOSTINT('auto_validate');
273 $object->fk_email_template = GETPOSTINT('auto_send_model_mail');
274 $object->generate_pdf = GETPOSTINT('generate_pdf');
275 $object->fk_project = $projectid;
276
277 $date_next_execution = dol_mktime($rehour, $remin, 0, $remonth, $reday, $reyear);
278 $object->date_when = $date_next_execution;
279
280 $ret = $extrafields->setOptionalsFromPost(null, $object);
281 if ($ret < 0) {
282 setEventMessages($extrafields->error, $extrafields->errors, 'errors');
283 $error++;
284 }
285
286 // Get first contract linked to invoice (or order or proposal) used to generate template (facid is id of source invoice)
287 if (GETPOSTINT('facid') > 0) {
288 $srcObject = new Facture($db);
289 $srcObject->fetch(GETPOSTINT('facid'));
290
291 $srcObject->fetchObjectLinked();
292
293 if (!empty($srcObject->linkedObjectsIds['contrat'])) {
294 $contractidid = reset($srcObject->linkedObjectsIds['contrat']);
295
296 $object->origin_type = 'contrat';
297 $object->origin_id = $contractidid;
298 $object->linked_objects[$object->origin_type] = $object->origin_id;
299 } elseif (!empty($srcObject->linkedObjectsIds['commande'])) {
300 $orderid = reset($srcObject->linkedObjectsIds['commande']);
301
302 $object->linked_objects['commande'] = $orderid;
303 } elseif (!empty($srcObject->linkedObjectsIds['propal'])) {
304 $proposalid = reset($srcObject->linkedObjectsIds['propal']);
305 $object->linked_objects['propal'] = $proposalid;
306 }
307 }
308
309 $db->begin();
310
311 $oldinvoice = new Facture($db);
312 $oldinvoice->fetch(GETPOSTINT('facid'));
313
314 $onlylines = GETPOST('toselect', 'array:int');
315
316 $result = $object->create($user, $oldinvoice->id, 0, $onlylines);
317 if ($result > 0) {
318 $result = $oldinvoice->delete($user, 1);
319 if ($result < 0) {
320 $error++;
321 setEventMessages($oldinvoice->error, $oldinvoice->errors, 'errors');
322 $action = "create";
323 }
324 } else {
325 $error++;
326 setEventMessages($object->error, $object->errors, 'errors');
327 $action = "create";
328 }
329
330 if (!$error) {
331 $db->commit();
332
333 header("Location: ".$_SERVER['PHP_SELF'].'?facid='.$object->id);
334 exit;
335 } else {
336 $db->rollback();
337
338 $action = "create";
339 }
340 }
341 }
342
343 // Delete
344 if ($action == 'confirm_delete' && $confirm == 'yes' && $user->hasRight('facture', 'supprimer')) {
345 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
346 $result = $object->delete($user);
347 if ($result > 0) {
348 header("Location: ".DOL_URL_ROOT.'/compta/facture/invoicetemplate_list.php');
349 exit;
350 } else {
351 setEventMessages($object->error, $object->errors, 'errors');
352 }
353 }
354
355
356 // Update field
357 if ($action == 'setconditions' && $usercancreate) {
358 // Set condition
359 $object->context['actionmsg'] = $langs->trans("FieldXModified", $langs->transnoentitiesnoconv("PaymentTerm"));
360 $result = $object->setPaymentTerms(GETPOSTINT('cond_reglement_id'));
361 } elseif ($action == 'setmode' && $usercancreate) {
362 // Set mode
363 $object->context['actionmsg'] = $langs->trans("FieldXModified", $langs->transnoentitiesnoconv("PaymentMode"));
364 $object->setPaymentMethods(GETPOSTINT('mode_reglement_id'));
365 $object->setValueFrom('fk_societe_rib', 0);
366
367 //Need to reload to display bank customer account field
368 header("Location: ".$_SERVER['PHP_SELF'].'?facid='.$object->id);
369 exit;
370 } elseif ($action == 'classin' && $usercancreate) {
371 // Set project
372 $object->context['actionmsg'] = $langs->trans("FieldXModified", $langs->transnoentitiesnoconv("Project"));
373 $object->setProject(GETPOSTINT('projectid'));
374 } elseif ($action == 'setref' && $usercancreate) {
375 // Set bank account
376 $object->context['actionmsg'] = $langs->trans("FieldXModifiedFromYToZ", $langs->transnoentitiesnoconv("Title"), $object->title, $ref);
377 $result = $object->setValueFrom('titre', $ref, '', null, 'text', '', $user, 'BILLREC_MODIFY');
378 if ($result > 0) {
379 $object->title = $ref;
380 $object->ref = $object->title;
381 } else {
382 $error++;
383 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
384 $langs->load("errors");
385 setEventMessages($langs->trans('ErrorRefAlreadyExists', $ref), null, 'errors');
386 } else {
387 setEventMessages($object->error, $object->errors, 'errors');
388 }
389 }
390 } elseif ($action == 'setbankaccount' && $usercancreate) {
391 // Set bank account
392 $object->context['actionmsg'] = $langs->trans("FieldXModified", $langs->transnoentitiesnoconv("Bank"));
393 $result = $object->setBankAccount(GETPOSTINT('fk_account'));
394 } elseif ($action == 'setbankaccountcustomer' && $usercancreate) {
395 // Set bank account customer
396 $object->context['actionmsg'] = $langs->trans("FieldXModified", $langs->transnoentitiesnoconv("DebitBankAccount"));
397 $fk_societe_rib = (GETPOSTINT('accountcustomerid') != "-1") ? GETPOSTINT('accountcustomerid') : 0;
398 $result = $object->setValueFrom('fk_societe_rib', $fk_societe_rib);
399 } elseif ($action == 'setfrequency' && $usercancreate) {
400 // Set frequency and unit frequency
401 $object->context['actionmsg'] = $langs->trans("FieldXModified", $langs->transnoentitiesnoconv("Frequency"));
402 $object->setFrequencyAndUnit(GETPOSTINT('frequency'), GETPOST('unit_frequency'));
403 } elseif ($action == 'setdate_when' && $usercancreate) {
404 // Set next date of execution
405 $date = dol_mktime(GETPOSTINT('date_whenhour'), GETPOSTINT('date_whenmin'), 0, GETPOSTINT('date_whenmonth'), GETPOSTINT('date_whenday'), GETPOSTINT('date_whenyear'));
406 if (!empty($date)) {
407 $object->setNextDate($date);
408 }
409 } elseif ($action == 'setnb_gen_max' && $usercancreate) {
410 // Set max period
411 $object->setMaxPeriod(GETPOSTINT('nb_gen_max'));
412 } elseif ($action == 'setauto_validate' && $usercancreate) {
413 // Set auto validate
414 $object->setAutoValidate(GETPOSTINT('auto_validate'));
415 } elseif ($action == 'setEmailTemplate' && $usercancreate) {
416 // Set Email Template
417 $object->setMailTemplate(GETPOSTINT('auto_send_model_mail'));
418 } elseif ($action == 'setgenerate_pdf' && $usercancreate) {
419 // Set generate pdf
420 $object->setGeneratepdf(GETPOSTINT('generate_pdf'));
421 } elseif ($action == 'setmodelpdf' && $usercancreate) {
422 // Set model pdf
423 $object->setModelpdf(GETPOST('modelpdf', 'alpha'));
424 } elseif ($action == 'disable' && $usercancreate) {
425 // Set status disabled
426 $db->begin();
427
428 $object->context['actionmsg'] = $langs->trans("RecordDisabled");
429
430 $res = $object->setValueFrom('suspended', 1, '', null, 'text', '', $user, 'BILLREC_MODIFY');
431 if ($res <= 0) {
432 $error++;
433 }
434
435 if (!$error) {
436 $db->commit();
437 } else {
438 $db->rollback();
439 setEventMessages($object->error, $object->errors, 'errors');
440 }
441 } elseif ($action == 'enable' && $usercancreate) {
442 // Set status enabled
443 $db->begin();
444
445 $object->context['actionmsg'] = $langs->trans("RecordEnabled");
446
447 $res = $object->setValueFrom('suspended', 0, '', null, 'text', '', $user, 'BILLREC_MODIFY');
448 if ($res <= 0) {
449 $error++;
450 }
451
452 if (!$error) {
453 $db->commit();
454 } else {
455 $db->rollback();
456 setEventMessages($object->error, $object->errors, 'errors');
457 }
458 } elseif ($action == 'setmulticurrencycode' && $usercancreate) {
459 // Multicurrency Code
460 $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha'));
461 $object->fetch($object->id); // Reload all.
462 } elseif ($action == 'setmulticurrencyrate' && $usercancreate) {
463 // Multicurrency rate
464 if (!in_array(GETPOSTINT('calculation_mode'), array(1, 2))) {
465 $langs->load("compta");
466 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CalculationMode")), null, 'errors');
467 $action = 'editmulticurrencyrate';
468 } else {
469 $result = $object->setMulticurrencyRate(GETPOSTFLOAT('multicurrency_tx'), GETPOSTINT('calculation_mode'));
470 }
471 $object->fetch($object->id); // Reload all.
472 } elseif ($action == 'setruleforlinesdates' && $usercancreate) {
473 $object->context['actionmsg'] = $langs->trans("FieldXModified", $langs->transnoentitiesnoconv("RuleForLinesDates"));
474 $ruleForLinesDates = GETPOSTISSET('rule_for_lines_dates') ? GETPOST('rule_for_lines_dates', 'alpha') : 'prepaid';
475 $object->setValueFrom('rule_for_lines_dates', $ruleForLinesDates);
476 }
477
478 // Delete line
479 if ($action == 'confirm_deleteline' && $confirm == 'yes' && $usercancreate) {
480 $object->fetch($id);
481 $object->fetch_thirdparty();
482
483 $db->begin();
484
485 $line = new FactureLigneRec($db);
486
487 // For triggers
488 $line->id = $lineid;
489
490 if ($line->delete($user) > 0) {
491 $result = $object->update_price(1);
492
493 if ($result > 0) {
494 $db->commit();
495 $object->fetch($object->id); // Reload lines
496 } else {
497 $db->rollback();
498 setEventMessages($db->lasterror(), null, 'errors');
499 }
500 } else {
501 $db->rollback();
502 setEventMessages($line->error, $line->errors, 'errors');
503 }
504 } elseif ($action == 'confirm_delete_subtotalline' && $confirm == 'yes' && $usercancreate) {
505 // Delete line
506 $object->fetch($id);
507 $object->fetch_thirdparty();
508
509 $result = $object->deleteSubtotalLine($langs, GETPOSTINT('lineid'), (bool) GETPOST('deletecorrespondingsubtotalline'), $user);
510 if ($result > 0) {
511 $result = $object->update_price(1);
512
513 if ($result > 0) {
514 $db->commit();
515 $object->fetch($object->id); // Reload lines
516 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
517 exit();
518 } else {
519 $db->rollback();
520 setEventMessages($db->lasterror(), null, 'errors');
521 }
522 } else {
523 setEventMessages($object->error, $object->errors, 'errors');
524 $action = '';
525 }
526 } elseif ($action == 'update_extras' && $permissiontoeditextra) {
527 $object->oldcopy = dol_clone($object, 2); // @phan-suppress-current-line PhanTypeMismatchProperty
528
529 $attribute_name = GETPOST('attribute', 'aZ09');
530
531 // Fill array 'array_options' with data from update form
532 $ret = $extrafields->setOptionalsFromPost(null, $object, $attribute_name);
533 if ($ret < 0) {
534 $error++;
535 }
536
537 if (!$error) {
538 $result = $object->updateExtraField($attribute_name, 'BILLREC_MODIFY');
539 if ($result < 0) {
540 setEventMessages($object->error, $object->errors, 'errors');
541 $error++;
542 }
543 }
544
545 if ($error) {
546 $action = 'edit_extras';
547 }
548 }
549
550 // Add a new line
551 if ($action == 'addline' && $usercancreate) {
552 $langs->load('errors');
553 $error = 0;
554
555 // Set if we used free entry or predefined product
556 $predef = '';
557 $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : '');
558 $price_ht = price2num(GETPOST('price_ht'), 'MU', 2);
559 $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU', 2);
560 $prod_entry_mode = GETPOST('prod_entry_mode', 'alpha');
561 if ($prod_entry_mode == 'free') {
562 $idprod = 0;
563 } else {
564 $idprod = GETPOSTINT('idprod');
565
566 if (getDolGlobalString('MAIN_DISABLE_FREE_LINES') && $idprod <= 0) {
567 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProductOrService")), null, 'errors');
568 $error++;
569 }
570 }
571
572 $tva_tx = (GETPOST('tva_tx', 'alpha') ? GETPOST('tva_tx', 'alpha') : 0);
573
574 $qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS', 2);
575 $remise_percent = price2num(GETPOST('remise_percent'.$predef), '', 2);
576 if (empty($remise_percent)) {
577 $remise_percent = 0;
578 }
579
580 // Extrafields
581 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
582 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
583 // Unset extrafield
584 if (is_array($extralabelsline)) {
585 // Get extra fields
586 foreach ($extralabelsline as $key => $value) {
587 unset($_POST["options_".$key.$predef]);
588 }
589 }
590
591 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ((float) $qty < 0)) {
592 setEventMessages($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPriceHT'), $langs->transnoentitiesnoconv('Qty')), null, 'errors');
593 $error++;
594 }
595 if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && GETPOST('type') < 0) {
596 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), null, 'errors');
597 $error++;
598 }
599 if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && (!($price_ht >= 0) || $price_ht == '')) { // Unit price can be 0 but not ''
600 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPriceHT")), null, 'errors');
601 $error++;
602 }
603 if ($qty == '') {
604 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
605 $error++;
606 }
607 if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
608 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), null, 'errors');
609 $error++;
610 }
611 if ($qty < 0) {
612 $langs->load("errors");
613 setEventMessages($langs->trans('ErrorQtyForCustomerInvoiceCantBeNegative'), null, 'errors');
614 $error++;
615 }
616
617 if (!$error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
618 $ret = $object->fetch($id);
619 if ($ret < 0) {
620 dol_print_error($db, $object->error);
621 exit();
622 }
623 $ret = $object->fetch_thirdparty();
624
625 // Clean parameters
626 $date_start = dol_mktime(GETPOSTINT('date_start'.$predef.'hour'), GETPOSTINT('date_start'.$predef.'min'), GETPOSTINT('date_start'.$predef.'sec'), GETPOSTINT('date_start'.$predef.'month'), GETPOSTINT('date_start'.$predef.'day'), GETPOSTINT('date_start'.$predef.'year'));
627 $date_end = dol_mktime(GETPOSTINT('date_end'.$predef.'hour'), GETPOSTINT('date_end'.$predef.'min'), GETPOSTINT('date_end'.$predef.'sec'), GETPOSTINT('date_end'.$predef.'month'), GETPOSTINT('date_end'.$predef.'day'), GETPOSTINT('date_end'.$predef.'year'));
628 $price_base_type = (GETPOST('price_base_type', 'alpha') ? GETPOST('price_base_type', 'alpha') : 'HT');
629 $tva_npr = "";
630
631 // Define special_code for special lines
632 $special_code = 0;
633 // if (!GETPOST('qty')) $special_code=3; // Options should not exists on invoices
634
635 // Ecrase $pu par celui du produit
636 // Ecrase $desc par celui du produit
637 // Ecrase $base_price_type par celui du produit
638 // Replaces $fk_unit with the product's
639 if (!empty($idprod) && $idprod > 0) {
640 $prod = new Product($db);
641 $prod->fetch($idprod);
642
643 $label = ((GETPOST('product_label') && GETPOST('product_label') != $prod->label) ? GETPOST('product_label') : '');
644
645 // Update if prices fields are defined
646 //$tva_tx = get_default_tva($mysoc, $object->thirdparty, $prod->id);
647 //$tva_npr = get_default_npr($mysoc, $object->thirdparty, $prod->id);
648 //if (empty($tva_tx)) {
649 // $tva_npr = 0;
650 //}
651
652 // Search the correct price into loaded array product_price_by_qty using id of array retrieved into POST['pqp'].
653 $pqp = (GETPOSTINT('pbq') ? GETPOSTINT('pbq') : 0);
654
655 $datapriceofproduct = $prod->getSellPrice($mysoc, $object->thirdparty, $pqp);
656
657 $pu_ht = $datapriceofproduct['pu_ht'];
658 $pu_ttc = $datapriceofproduct['pu_ttc'];
659 $price_min = $datapriceofproduct['price_min'];
660 $price_base_type = empty($datapriceofproduct['price_base_type']) ? 'HT' : $datapriceofproduct['price_base_type'];
661 //$tva_tx = $datapriceofproduct['tva_tx'];
662 //$tva_npr = $datapriceofproduct['tva_npr'];
663
664 $tmpvat = (float) price2num(preg_replace('/\s*\‍(.*\‍)/', '', $tva_tx));
665 $tmpprodvat = price2num(preg_replace('/\s*\‍(.*\‍)/', '', (string) $prod->tva_tx));
666
667 // if price ht was forced (ie: from gui when calculated by margin rate and cost price). TODO Why this ?
668 if (!empty($price_ht)) {
669 $pu_ht = price2num($price_ht, 'MU');
670 $pu_ttc = price2num((float) $pu_ht * (1 + ($tmpvat / 100)), 'MU');
671 } elseif ($tmpvat != $tmpprodvat) {
672 // We reevaluate the price according to vat rate because vat rate of transactionmay differs from
673 // the one oth the product by default (for example when country of seller and buyer are different).
674 if ($price_base_type != 'HT') {
675 $pu_ht = price2num((float) $pu_ttc / (1 + ($tmpvat / 100)), 'MU');
676 } else {
677 $pu_ttc = price2num((float) $pu_ht * (1 + ($tmpvat / 100)), 'MU');
678 }
679 }
680
681 $outputlangs = $langs;
682 $newlang = '';
683 $desc = '';
684
685 // Define output language
686 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
687 if (/* empty($newlang) && */ GETPOST('lang_id', 'aZ09')) {
688 $newlang = GETPOST('lang_id', 'aZ09');
689 }
690 if (empty($newlang)) {
691 $newlang = $object->thirdparty->default_lang;
692 }
693 if (!empty($newlang)) {
694 $outputlangs = new Translate("", $conf);
695 $outputlangs->setDefaultLang($newlang);
696 $outputlangs->load('products');
697 }
698
699 $desc = (!empty($prod->multilangs [$outputlangs->defaultlang] ["description"])) ? $prod->multilangs [$outputlangs->defaultlang] ["description"] : $prod->description;
700 } else {
701 $desc = $prod->description;
702 }
703
704 // Add custom code and origin country into description
705 if (!getDolGlobalString('MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE') && (!empty($prod->customcode) || !empty($prod->country_code))) {
706 $tmptxt = '(';
707 // Define output language
708 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
709 if (!empty($prod->customcode)) {
710 $tmptxt .= $outputlangs->transnoentitiesnoconv("CustomsCode").': '.$prod->customcode;
711 }
712 if (!empty($prod->customcode) && !empty($prod->country_code)) {
713 $tmptxt .= ' - ';
714 }
715 if (!empty($prod->country_code)) {
716 $tmptxt .= $outputlangs->transnoentitiesnoconv("CountryOrigin").': '.getCountry($prod->country_code, '', $db, $outputlangs, 0);
717 }
718 } else {
719 if (!empty($prod->customcode)) {
720 $tmptxt .= $langs->transnoentitiesnoconv("CustomsCode").': '.$prod->customcode;
721 }
722 if (!empty($prod->customcode) && !empty($prod->country_code)) {
723 $tmptxt .= ' - ';
724 }
725 if (!empty($prod->country_code)) {
726 $tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin").': '.getCountry($prod->country_code, '', $db, $langs, 0);
727 }
728 }
729 $tmptxt .= ')';
730 $desc = dol_concatdesc($desc, $tmptxt);
731 }
732
733 $type = $prod->type;
734 $fk_unit = $prod->fk_unit;
735 } else {
736 $pu_ht = price2num($price_ht, 'MU');
737 $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
738 $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
739 $tva_tx = str_replace('*', '', $tva_tx);
740 if (empty($tva_tx)) {
741 $tva_npr = 0;
742 }
743 $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
744 $desc = $product_desc;
745 $type = GETPOST('type');
746 $fk_unit = GETPOSTINT('units');
747 }
748
749 $date_start_fill = GETPOSTINT('date_start_fill');
750 $date_end_fill = GETPOSTINT('date_end_fill');
751
752 // Margin
753 $fournprice = (int) (GETPOST('fournprice'.$predef) ? GETPOST('fournprice'.$predef) : ''); // This can be id of supplier price, or 'pmpprice' or 'costprice', or 'inputprice', we force to keep ID only
754 $buyingprice = price2num(GETPOST('buying_price'.$predef) != '' ? GETPOST('buying_price'.$predef) : ''); // If buying_price is '0', we must keep this value
755
756 // Local Taxes
757 $localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty, $mysoc, $tva_npr);
758 $localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty, $mysoc, $tva_npr);
759
760 $info_bits = 0;
761 if ($tva_npr) {
762 $info_bits |= 0x01;
763 }
764
765 $fk_parent_line = GETPOSTINT('fk_parent_line');
766
767 if ($usercanproductignorepricemin && (!empty($price_min) && ((float) price2num($pu_ht) * (1 - (float) price2num($remise_percent) / 100) < (float) price2num($price_min)))) {
768 $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
769 setEventMessages($mesg, null, 'errors');
770 } else {
771 // Insert line
772 $result = $object->addline($desc, $pu_ht, (float) $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $idprod, $remise_percent, $price_base_type, $info_bits, 0, $pu_ttc, $type, -1, $special_code, $label, (int) $fk_unit, 0, $date_start_fill, $date_end_fill, (int) $fournprice, (float) $buyingprice, $fk_parent_line);
773
774 if ($result > 0) {
775 // TODO add "insert" function into FactureLigneRec or add "invoicerecline.class.php" (same of "factureligne.class.php")
776 $objectline = new FactureLigneRec($db);
777 if ($objectline->fetch($result)) {
778 $objectline->array_options = $array_options;
779 $result = $objectline->insertExtraFields();
780 if ($result < 0) {
781 setEventMessages($langs->trans('Error').$result, null, 'errors');
782 }
783 }
784
785 // Define output language and generate document
786 /*if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
787 {
788 // Define output language
789 $outputlangs = $langs;
790 $newlang = '';
791 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang = GETPOST('lang_id','aZ09');
792 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) $newlang = $object->thirdparty->default_lang;
793 if (!empty($newlang)) {
794 $outputlangs = new Translate("", $conf);
795 $outputlangs->setDefaultLang($newlang);
796 }
797 $model=$object->model_pdf;
798 $ret = $object->fetch($id); // Reload to get new records
799
800 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
801 if ($result < 0) setEventMessages($object->error, $object->errors, 'errors');
802 }*/
803 $object->fetch($object->id); // Reload lines
804
805 unset($_POST['prod_entry_mode']);
806
807 unset($_POST['qty']);
808 unset($_POST['type']);
809 unset($_POST['remise_percent']);
810 unset($_POST['price_ht']);
811 unset($_POST['multicurrency_price_ht']);
812 unset($_POST['price_ttc']);
813 unset($_POST['tva_tx']);
814 unset($_POST['product_ref']);
815 unset($_POST['product_label']);
816 unset($_POST['product_desc']);
817 unset($_POST['fournprice']);
818 unset($_POST['buying_price']);
819 unset($_POST['np_marginRate']);
820 unset($_POST['np_markRate']);
821 unset($_POST['dp_desc']);
822 unset($_POST['idprod']);
823 unset($_POST['units']);
824
825 unset($_POST['date_starthour']);
826 unset($_POST['date_startmin']);
827 unset($_POST['date_startsec']);
828 unset($_POST['date_startday']);
829 unset($_POST['date_startmonth']);
830 unset($_POST['date_startyear']);
831 unset($_POST['date_endhour']);
832 unset($_POST['date_endmin']);
833 unset($_POST['date_endsec']);
834 unset($_POST['date_endday']);
835 unset($_POST['date_endmonth']);
836 unset($_POST['date_endyear']);
837
838 unset($_POST['date_start_fill']);
839 unset($_POST['date_end_fill']);
840
841 unset($_POST['situations']);
842 unset($_POST['progress']);
843 } else {
844 setEventMessages($object->error, $object->errors, 'errors');
845 }
846
847 $action = '';
848 }
849 }
850 } elseif ($action == 'confirm_addtextline' && $usercancreate) {
851 // Handling adding a new text line for subtotals module
852
853 $langs->load('subtotals');
854
855 $desc = GETPOST('subtotaltextcontent', 'restricthtml');
856
857 // Insert line
858 $result = $object->addSubtotalLine($langs, $desc, 0, array());
859
860 if ($result >= 0) {
861 if ($result == 0) {
862 setEventMessages($object->error, $object->errors, 'warnings');
863 }
864 $ret = $object->fetch($object->id); // Reload to get new records
865 $object->fetch_thirdparty();
866 } else {
867 setEventMessages($object->error, $object->errors, 'errors');
868 }
869 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
870 exit();
871 } elseif ($action == 'confirm_addtitleline' && $usercancreate) {
872 // Handling adding a new title line for subtotals module
873
874 $langs->load('subtotals');
875
876 $desc = GETPOST('subtotallinedesc', 'alphanohtml');
877 $depth = GETPOSTINT('subtotallinelevel') ?? 1;
878
879 $subtotal_options = array();
880
881 foreach (FactureRec::$TITLE_OPTIONS as $option) {
882 $value = GETPOST($option, 'alphanohtml');
883 if ($value) {
884 $subtotal_options[$option] = $value == 'on' ? 1 : $value;
885 }
886 }
887
888 // Insert line
889 $result = $object->addSubtotalLine($langs, $desc, (int) $depth, $subtotal_options);
890
891 if ($result >= 0) {
892 if ($result == 0) {
893 setEventMessages($object->error, $object->errors, 'warnings');
894 }
895 $ret = $object->fetch($object->id); // Reload to get new records
896 $object->fetch_thirdparty();
897 } else {
898 setEventMessages($object->error, $object->errors, 'errors');
899 }
900 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
901 exit();
902 } elseif ($action == 'confirm_addsubtotalline' && $usercancreate) {
903 // Handling adding a new subtotal line for subtotals module
904
905 $langs->load('subtotals');
906
907 $choosen_line = GETPOST('subtotaltitleline', 'alphanohtml');
908 foreach ($object->lines as $line) {
909 if ($line->desc == $choosen_line && $line->special_code == SUBTOTALS_SPECIAL_CODE) {
910 $desc = $line->desc;
911 $depth = -$line->qty;
912 }
913 }
914
915 $subtotal_options = array();
916
917 foreach (FactureRec::$SUBTOTAL_OPTIONS as $option) {
918 $value = GETPOST($option, 'alphanohtml');
919 if ($value) {
920 $subtotal_options[$option] = $value == 'on' ? 1 : $value;
921 }
922 }
923
924 // Insert line
925 if (isset($desc) && isset($depth)) {
926 $result = $object->addSubtotalLine($langs, $desc, (int) $depth, $subtotal_options);
927 } else {
928 $result = -1;
929 $object->errors[] = $langs->trans("CorrespondingTitleNotFound");
930 }
931
932 if ($result >= 0) {
933 $ret = $object->fetch($object->id); // Reload to get new records
934 $object->fetch_thirdparty();
935 } else {
936 setEventMessages($object->error, $object->errors, 'errors');
937 }
938 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
939 exit();
940 } elseif ($action == 'updateline' && $usercancreate && !GETPOST('cancel', 'alpha')) {
941 if (!$object->fetch($id) > 0) {
942 dol_print_error($db);
943 }
944 $object->fetch_thirdparty();
945
946 // Clean parameters
947 $date_start = '';
948 $date_end = '';
949 //$date_start = dol_mktime(GETPOSTINT('date_starthour'), GETPOSTINT('date_startmin'), GETPOSTINT('date_startsec'), GETPOSTINT('date_startmonth'), GETPOSTINT('date_startday'), GETPOSTINT('date_startyear'));
950 //$date_end = dol_mktime(GETPOSTINT('date_endhour'), GETPOSTINT('date_endmin'), GETPOSTINT('date_endsec'), GETPOSTINT('date_endmonth'), GETPOSTINT('date_endday'), GETPOSTINT('date_endyear'));
951 $description = dol_htmlcleanlastbr(GETPOST('product_desc', 'restricthtml') ? GETPOST('product_desc', 'restricthtml') : GETPOST('desc', 'restricthtml'));
952 $vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
953
954 $pu_ht = price2num(GETPOST('price_ht'), '', 2);
955 $pu_ttc = price2num(GETPOST('price_ttc'), '', 2);
956
957 $pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), '', 2);
958 $pu_ttc_devise = price2num(GETPOST('multicurrency_price_ttc'), '', 2);
959
960 $qty = (float) price2num(GETPOST('qty', 'alpha'), 'MS');
961
962 // Define info_bits
963 $info_bits = 0;
964 if (preg_match('/\*/', $vat_rate)) {
965 $info_bits |= 0x01;
966 }
967
968 // Define vat_rate
969 $vat_rate = str_replace('*', '', $vat_rate);
970 $localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty);
971 $localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty);
972
973 // Add buying price
974 $fournprice = (int) (GETPOST('fournprice') ? GETPOST('fournprice') : '');
975 $buyingprice = price2num(GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we must keep this value
976
977 // Prepare a price equivalent for minimum price check
978 $pu_equivalent = $pu_ht;
979 $pu_equivalent_ttc = $pu_ttc;
980
981 $currency_tx = $object->multicurrency_tx;
982
983 // Check if we have a foreign currency
984 // If so, we update the pu_equiv as the equivalent price in base currency
985 if ($pu_ht == '' && $pu_ht_devise != '' && $currency_tx != '' && !empty((float) $currency_tx)) {
986 $pu_equivalent = (float) $pu_ht_devise / (float) $currency_tx;
987 }
988 if ($pu_ttc == '' && $pu_ttc_devise != '' && $currency_tx != '' && !empty((float) $currency_tx)) {
989 $pu_equivalent_ttc = (float) $pu_ttc_devise / (float) $currency_tx;
990 }
991
992 // TODO $pu_equivalent or $pu_equivalent_ttc must be calculated from the one not null taking into account all taxes
993 /*
994 if ($pu_equivalent) {
995 $tmp = calcul_price_total(1, $pu_equivalent, 0, $vat_rate, -1, -1, 0, 'HT', $info_bits, $type);
996 $pu_equivalent_ttc = ...
997 } else {
998 $tmp = calcul_price_total(1, $pu_equivalent_ttc, 0, $vat_rate, -1, -1, 0, 'TTC', $info_bits, $type);
999 $pu_equivalent_ht = ...
1000 }
1001 */
1002
1003 // Extrafields
1004 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1005 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
1006
1007 $objectline = new FactureLigneRec($db);
1008 if ($objectline->fetch(GETPOSTINT('lineid'))) {
1009 $objectline->array_options = $array_options;
1010 $result = $objectline->insertExtraFields();
1011 if ($result < 0) {
1012 setEventMessages($langs->trans('Error').$result, null, 'errors');
1013 }
1014 }
1015 $position = ($objectline->rang >= 0 ? $objectline->rang : 0);
1016
1017 // Unset extrafield
1018 if (is_array($extralabelsline)) {
1019 // Get extra fields
1020 foreach ($extralabelsline as $key => $value) {
1021 unset($_POST["options_".$key]);
1022 }
1023 }
1024
1025 // Define special_code for special lines
1026 $special_code = GETPOSTINT('special_code');
1027 if ($special_code == 3) {
1028 $special_code = 0; // Options should not exists on invoices
1029 }
1030
1031 /*
1032 $line = new FactureLigne($db);
1033 $line->fetch(GETPOST('lineid', 'int'));
1034 $percent = $line->get_prev_progress($object->id);
1035
1036 ...
1037 */
1038
1039 $remise_percent = price2num(GETPOST('remise_percent'), '', 2);
1040 if (empty($remise_percent)) {
1041 $remise_percent = 0;
1042 }
1043
1044 $price_base_type = 'HT';
1045 $pu = $pu_ht;
1046 if (empty($pu) && !empty($pu_ttc)) {
1047 $pu = $pu_ttc;
1048 $price_base_type = 'TTC';
1049 }
1050
1051 // Only the unit price incl. tax in currency was entered: it becomes the reference price of the line.
1052 // updateline() reads the currency price in the price_base_type, so it receives the TTC currency amount.
1053 if (GETPOST('price_ht') === '' && GETPOST('price_ttc') === '' && GETPOST('multicurrency_subprice') === '' && GETPOST('multicurrency_price_ttc') !== '') {
1054 $pu = 0;
1055 $price_base_type = 'TTC';
1056 $pu_ht_devise = $pu_ttc_devise;
1057 }
1058
1059 // Check minimum price
1060 $productid = GETPOSTINT('productid');
1061 if (!empty($productid)) {
1062 $product = new Product($db);
1063 $product->fetch($productid);
1064
1065 $type = $product->type;
1066
1067 $price_min = $product->price_min;
1068 if ((getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) && !empty($object->thirdparty->price_level)) {
1069 $price_min = $product->multiprices_min[$object->thirdparty->price_level];
1070 }
1071 $price_min_ttc = $product->price_min_ttc;
1072 if ((getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) && !empty($object->thirdparty->price_level)) {
1073 $price_min_ttc = $product->multiprices_min_ttc[$object->thirdparty->price_level];
1074 }
1075
1076 $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : '');
1077
1078 $typeinvoice = Facture::TYPE_STANDARD;
1079
1080 // Check price is not lower than minimum (check is done only for standard or replacement invoices)
1081 if ($usermustrespectpricemin && ($typeinvoice == Facture::TYPE_STANDARD || $typeinvoice == Facture::TYPE_REPLACEMENT)) {
1082 if ($pu_equivalent && $price_min && (((float) price2num($pu_equivalent) * (1 - (float) $remise_percent / 100)) < (float) price2num($price_min)) && $price_base_type == 'HT') {
1083 $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1084 setEventMessages($mesg, null, 'errors');
1085 $error++;
1086 $action = 'editline';
1087 } elseif ($pu_equivalent_ttc && $price_min_ttc && (((float) price2num($pu_equivalent_ttc) * (1 - (float) $remise_percent / 100)) < (float) price2num($price_min_ttc)) && $price_base_type == 'TTC') {
1088 $mesg = $langs->trans("CantBeLessThanMinPriceInclTax", price(price2num($price_min_ttc, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
1089 setEventMessages($mesg, null, 'errors');
1090 $error++;
1091 $action = 'editline';
1092 }
1093 }
1094 } else {
1095 $type = GETPOSTINT('type');
1096 $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
1097
1098 // Check parameters
1099 if (GETPOSTINT('type') < 0) {
1100 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
1101 $error++;
1102 }
1103 }
1104 if ($qty < 0) {
1105 $langs->load("errors");
1106 setEventMessages($langs->trans('ErrorQtyForCustomerInvoiceCantBeNegative'), null, 'errors');
1107 $error++;
1108 }
1109
1110 $date_start_fill = GETPOSTINT('date_start_fill');
1111 $date_end_fill = GETPOSTINT('date_end_fill');
1112 $fk_parent_line = GETPOST('fk_parent_line', 'int');
1113
1114 // Update line
1115 if (!$error) {
1116 $result = $object->updateline(
1117 GETPOSTINT('lineid'),
1118 $description,
1119 (float) $pu_ht,
1120 (float) $qty,
1121 $vat_rate,
1122 $localtax1_rate,
1123 $localtax1_rate,
1124 GETPOSTINT('productid'),
1125 $remise_percent,
1126 'HT',
1127 $info_bits,
1128 0,
1129 0,
1130 $type,
1131 $position,
1132 $special_code,
1133 $label,
1134 GETPOSTINT('units'),
1135 (float) $pu_ht_devise,
1136 0,
1137 $date_start_fill,
1138 $date_end_fill,
1139 (int) $fournprice,
1140 (float) $buyingprice,
1141 (int) $fk_parent_line
1142 );
1143
1144 if ($result >= 0) {
1145 /*if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1146 // Define output language
1147 $outputlangs = $langs;
1148 $newlang = '';
1149 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id','aZ09')) {
1150 $newlang = GETPOST('lang_id','aZ09');
1151 }
1152 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1153 $newlang = $object->thirdparty->default_lang;
1154 }
1155 if (!empty($newlang)) {
1156 $outputlangs = new Translate("", $conf);
1157 $outputlangs->setDefaultLang($newlang);
1158 }
1159 $ret = $object->fetch($id); // Reload to get new records
1160 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1161 }*/
1162
1163 $object->fetch($object->id); // Reload lines
1164
1165 unset($_POST['qty']);
1166 unset($_POST['type']);
1167 unset($_POST['productid']);
1168 unset($_POST['remise_percent']);
1169 unset($_POST['price_ht']);
1170 unset($_POST['multicurrency_price_ht']);
1171 unset($_POST['price_ttc']);
1172 unset($_POST['tva_tx']);
1173 unset($_POST['product_ref']);
1174 unset($_POST['product_label']);
1175 unset($_POST['product_desc']);
1176 unset($_POST['fournprice']);
1177 unset($_POST['buying_price']);
1178 unset($_POST['np_marginRate']);
1179 unset($_POST['np_markRate']);
1180
1181 unset($_POST['dp_desc']);
1182 unset($_POST['idprod']);
1183 unset($_POST['units']);
1184
1185 unset($_POST['date_starthour']);
1186 unset($_POST['date_startmin']);
1187 unset($_POST['date_startsec']);
1188 unset($_POST['date_startday']);
1189 unset($_POST['date_startmonth']);
1190 unset($_POST['date_startyear']);
1191 unset($_POST['date_endhour']);
1192 unset($_POST['date_endmin']);
1193 unset($_POST['date_endsec']);
1194 unset($_POST['date_endday']);
1195 unset($_POST['date_endmonth']);
1196 unset($_POST['date_endyear']);
1197
1198 unset($_POST['situations']);
1199 unset($_POST['progress']);
1200 } else {
1201 setEventMessages($object->error, $object->errors, 'errors');
1202 }
1203 }
1204 } elseif ($action == 'updatetitleline' && GETPOSTISSET("save") && $usercancreate && !GETPOST('cancel', 'alpha')) {
1205 // Handling updating a title line for subtotals module
1206
1207 $langs->load('subtotals');
1208
1209 $desc = GETPOST('line_desc', 'alphanohtml') ?? $langs->trans("Title");
1210 $depth = GETPOSTINT('line_depth') ?? 1;
1211
1212 $subtotal_options = array();
1213
1214 foreach (Facture::$TITLE_OPTIONS as $option) {
1215 $value = GETPOST($option, 'alphanohtml');
1216 if ($value) {
1217 $subtotal_options[$option] = $value == 'on' ? 1 : $value;
1218 }
1219 }
1220
1221 // Update line
1222 $result = $object->updateSubtotalLine($langs, GETPOSTINT('lineid'), $desc, $depth, $subtotal_options);
1223
1224 if ($result >= 0) {
1225 if ($result == 0) {
1226 setEventMessages($object->error, $object->errors, 'warnings');
1227 }
1228 $ret = $object->fetch($object->id); // Reload to get new records
1229 $object->fetch_thirdparty();
1230 } else {
1231 setEventMessages($object->error, $object->errors, 'errors');
1232 }
1233 } elseif ($action == 'updatetextline' && GETPOSTISSET("save") && $usercancreate && !GETPOST('cancel', 'alpha')) {
1234 // Handling updating a text line for subtotals module
1235
1236 $langs->load('subtotals');
1237
1238 $desc = GETPOST('line_desc', 'restricthtml');
1239
1240 // Update line
1241 $result = $object->updateSubtotalLine($langs, GETPOSTINT('lineid'), $desc, 0, array());
1242
1243 if ($result >= 0) {
1244 if ($result == 0) {
1245 setEventMessages($object->error, $object->errors, 'warnings');
1246 }
1247 $ret = $object->fetch($object->id); // Reload to get new records
1248 $object->fetch_thirdparty();
1249 } else {
1250 setEventMessages($object->error, $object->errors, 'errors');
1251 }
1252 } elseif ($action == 'updatesubtotalline' && GETPOSTISSET("save") && $usercancreate && !GETPOST('cancel', 'alpha')) {
1253 // Handling updating a subtotal line for subtotals module
1254
1255 $langs->load('subtotals');
1256
1257 $desc = GETPOST('line_desc', 'alphanohtml');
1258 $depth = GETPOSTINT('line_depth');
1259
1260 $subtotal_options = array();
1261
1262 foreach (Facture::$SUBTOTAL_OPTIONS as $option) {
1263 $value = GETPOST($option, 'alphanohtml');
1264 if ($value) {
1265 $subtotal_options[$option] = $value == 'on' ? 1 : $value;
1266 }
1267 }
1268
1269 // Update line
1270 $result = $object->updateSubtotalLine($langs, GETPOSTINT('lineid'), $desc, $depth, $subtotal_options);
1271
1272 if ($result > 0) {
1273 $ret = $object->fetch($object->id); // Reload to get new records
1274 $object->fetch_thirdparty();
1275 } else {
1276 setEventMessages($object->error, $object->errors, 'errors');
1277 }
1278 }
1279}
1280
1281
1282/*
1283 * View
1284 */
1285
1286$title = $object->ref." - ".$langs->trans('Card');
1287$help_url = '';
1288
1289llxHeader('', $title, $help_url);
1290
1291$form = new Form($db);
1292$formother = new FormOther($db);
1293if (isModEnabled('project')) {
1294 $formproject = new FormProjets($db);
1295} else {
1296 $formproject = null;
1297}
1298$companystatic = new Societe($db);
1299$invoicerectmp = new FactureRec($db);
1300
1301$now = dol_now();
1302$nowlasthour = dol_get_last_hour($now);
1303
1304
1305// Create mode
1306if ($action == 'create') {
1307 print load_fiche_titre($langs->trans("CreateRepeatableInvoice"), '', 'bill');
1308
1309 $sourceInvoice = new Facture($db); // Source invoice
1310 $factureRec = new FactureRec($db);
1311 $product_static = new Product($db);
1312
1313 if ($sourceInvoice->fetch($id, $ref) > 0) {
1314 $result = $sourceInvoice->getLinesArray();
1315
1316 print '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">';
1317 print '<input type="hidden" name="token" value="'.newToken().'">';
1318 print '<input type="hidden" name="action" value="add">';
1319 print '<input type="hidden" name="facid" value="'.$sourceInvoice->id.'">';
1320
1321
1322 print dol_get_fiche_head([], '', '', 0);
1323
1324 $rowspan = 4;
1325 if (isModEnabled('project')) {
1326 $rowspan++;
1327 }
1328 if ($sourceInvoice->fk_account > 0) {
1329 $rowspan++;
1330 }
1331
1332 print '<table class="border centpercent">';
1333
1334 $sourceInvoice->fetch_thirdparty();
1335
1336 // Title
1337 print '<tr><td class="titlefieldcreate fieldrequired">'.$langs->trans("Title").'</td><td>';
1338 print '<input class="flat quatrevingtpercent" type="text" name="title" value="'.dol_escape_htmltag(GETPOST("title", 'alphanohtml')).'" autofocus>';
1339 print '</td></tr>';
1340
1341 // Third party
1342 print '<tr><td class="titlefieldcreate">'.$langs->trans("Customer").'</td><td>'.$sourceInvoice->thirdparty->getNomUrl(1, 'customer').'</td>';
1343 print '</tr>';
1344
1345 // Invoice subtype
1346 if (getDolGlobalInt('INVOICE_SUBTYPE_ENABLED')) {
1347 print "<tr><td>".$langs->trans("InvoiceSubtype")."</td><td>";
1348 print $form->getSelectInvoiceSubtype(GETPOSTISSET('subtype') ? GETPOSTINT('subtype') : $sourceInvoice->subtype, 'subtype', 0, 0, '');
1349 print "</td></tr>";
1350 }
1351
1352 $note_public = GETPOSTISSET('note_public') ? GETPOST('note_public', 'restricthtml') : $sourceInvoice->note_public;
1353 $note_private = GETPOSTISSET('note_private') ? GETPOST('note_private', 'restricthtml') : $sourceInvoice->note_private;
1354
1355 // Help of substitution key
1356 $substitutionarray = getCommonSubstitutionArray($langs, 2, null, $sourceInvoice);
1357
1358 $substitutionarray['__INVOICE_PREVIOUS_MONTH__'] = $langs->trans("PreviousMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($sourceInvoice->date, -1, 'm'), '%m').')';
1359 $substitutionarray['__INVOICE_MONTH__'] = $langs->trans("MonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($sourceInvoice->date, '%m').')';
1360 $substitutionarray['__INVOICE_NEXT_MONTH__'] = $langs->trans("NextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($sourceInvoice->date, 1, 'm'), '%m').')';
1361 $substitutionarray['__INVOICE_PREVIOUS_MONTH_TEXT__'] = $langs->trans("TextPreviousMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($sourceInvoice->date, -1, 'm'), '%B').')';
1362 $substitutionarray['__INVOICE_MONTH_TEXT__'] = $langs->trans("TextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($sourceInvoice->date, '%B').')';
1363 $substitutionarray['__INVOICE_NEXT_MONTH_TEXT__'] = $langs->trans("TextNextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($sourceInvoice->date, 1, 'm'), '%B').')';
1364 $substitutionarray['__INVOICE_PREVIOUS_YEAR__'] = $langs->trans("PreviousYearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($sourceInvoice->date, -1, 'y'), '%Y').')';
1365 $substitutionarray['__INVOICE_YEAR__'] = $langs->trans("YearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($sourceInvoice->date, '%Y').')';
1366 $substitutionarray['__INVOICE_NEXT_YEAR__'] = $langs->trans("NextYearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($sourceInvoice->date, 1, 'y'), '%Y').')';
1367 // Only on template invoices
1368 $substitutionarray['__INVOICE_DATE_NEXT_INVOICE_BEFORE_GEN__'] = $langs->trans("DateNextInvoiceBeforeGen").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($sourceInvoice->date, 1, 'm'), 'dayhour').')';
1369 $substitutionarray['__INVOICE_DATE_NEXT_INVOICE_AFTER_GEN__'] = $langs->trans("DateNextInvoiceAfterGen").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($sourceInvoice->date, 2, 'm'), 'dayhour').')';
1370 $substitutionarray['__INVOICE_COUNTER_CURRENT__'] = $langs->trans("Count");
1371 $substitutionarray['__INVOICE_COUNTER_MAX__'] = $langs->trans("MaxPeriodNumber");
1372
1373 $htmltext = '<i>'.$langs->trans("FollowingConstantsWillBeSubstituted").':<br>';
1374 foreach ($substitutionarray as $key => $val) {
1375 $htmltext .= $key.' = '.$langs->trans($val).'<br>';
1376 }
1377 $htmltext .= '</i>';
1378
1379 // Author
1380 print "<tr><td>".$langs->trans("Author")."</td><td>".$user->getFullName($langs)."</td></tr>";
1381
1382 // Payment term
1383 print "<tr><td>".$langs->trans("PaymentConditions")."</td><td>";
1384 print $form->getSelectConditionsPaiements(GETPOSTISSET('cond_reglement_id') ? GETPOSTINT('cond_reglement_id') : $sourceInvoice->cond_reglement_id, 'cond_reglement_id', -1, 0, 0, '');
1385 //$form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id');
1386 print "</td></tr>";
1387
1388 // Payment mode
1389 print "<tr><td>".$langs->trans("PaymentMode")."</td><td>";
1390 print img_picto('', 'payment', 'class="pictofixedwidth"');
1391 print $form->select_types_paiements((string) (GETPOSTISSET('mode_reglement_id') ? GETPOSTINT('mode_reglement_id') : $sourceInvoice->mode_reglement_id), 'mode_reglement_id', '', 0, 1, 0, 0, 1, '', 1);
1392 //$form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', '', 1);
1393 print "</td></tr>";
1394
1395 // Customer Bank Account
1396 print "<tr><td>".$langs->trans('DebitBankAccount')."</td><td>";
1397 $defaultRibId = $sourceInvoice->thirdparty->getDefaultRib();
1398 $form->selectRib(GETPOSTISSET('accountcustomerid') ? GETPOSTINT('accountcustomerid') : $defaultRibId, 'accountcustomerid', '(fk_soc:=:'.$sourceInvoice->socid.")", 1, '', 1);
1399 print "</td></tr>";
1400
1401 print '<script>
1402 $(document).ready(function() {
1403 if($("#selectmode_reglement_id option:selected").data("code") != "' . $factureRec::PAYMENTCODETOEDITSOCIETERIB . '") {
1404 hideselectfksocieterib();
1405 }
1406 $("#selectmode_reglement_id").change(function() {
1407 if($("#selectmode_reglement_id option:selected").data("code") != "'. $factureRec::PAYMENTCODETOEDITSOCIETERIB .'") {
1408 hideselectfksocieterib(1);
1409 } else {
1410 showselectfksocieterib();
1411 }
1412 });
1413 });
1414
1415 function hideselectfksocieterib(empty = 0){
1416 $("#selectaccountcustomerid").closest("tr").hide();
1417 if(empty == 1){
1418 $("#selectaccountcustomerid").val("-1").change();
1419 }
1420 }
1421
1422 function showselectfksocieterib(){
1423 $("#selectaccountcustomerid").closest("tr").show();
1424 }
1425 </script>';
1426
1427 // Bank account
1428 if ($sourceInvoice->fk_account > 0) {
1429 print "<tr><td>".$langs->trans('BankAccount')."</td><td>";
1430 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$sourceInvoice->id, (string) $sourceInvoice->fk_account, 'none');
1431 print "</td></tr>";
1432 }
1433
1434 // Rule for lines dates
1435 if (getDolGlobalInt("FACTUREREC_SUPPORT_RULE_FOR_LINES")) {
1436 print "<tr><td>".$langs->trans("RuleForLinesDates")."</td><td>";
1437 print $form->getSelectRuleForLinesDates(GETPOSTISSET('rule_for_lines_dates') ? GETPOST('rule_for_lines_dates', 'alpha') : $factureRec->rule_for_lines_dates);
1438 print "</td></tr>";
1439 }
1440
1441 //extrafields
1442 $draft = new Facture($db);
1443 $draft->fetch(GETPOSTINT('facid'));
1444
1445 $extralabels = $extrafields->fetch_name_optionals_label($draft->table_element);
1446 if ($draft->fetch_optionals() > 0) {
1447 $sourceInvoice->array_options = array_merge($sourceInvoice->array_options, $draft->array_options);
1448 }
1449
1450 print $sourceInvoice->showOptionals($extrafields, 'create', $parameters);
1451
1452 // Project
1453 if (isModEnabled('project') && is_object($sourceInvoice->thirdparty) && $sourceInvoice->thirdparty->id > 0 && is_object($formproject)) {
1454 $projectid = GETPOST('projectid') ? GETPOST('projectid') : $sourceInvoice->fk_project;
1455 $langs->load('projects');
1456 print '<tr><td>'.$langs->trans('Project').'</td><td>';
1457 print img_picto('', 'project', 'class="pictofixedwidth"');
1458 $numprojet = $formproject->select_projects($sourceInvoice->thirdparty->id, $projectid, 'projectid', 0, 0, 1, 0, 0, 0, 0, '', 0, 0, '');
1459 print ' &nbsp; <a href="'.DOL_URL_ROOT.'/projet/card.php?socid='.$sourceInvoice->thirdparty->id.'&action=create&status=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create&socid='.$sourceInvoice->thirdparty->id.(!empty($id) ? '&id='.$id : '')).'">'.img_object($langs->trans("AddProject"), 'add').'</a>';
1460 print '</td></tr>';
1461 }
1462
1463 // Model pdf
1464 print "<tr><td>".$langs->trans('Model')."</td><td>";
1465 include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
1467 print img_picto('', 'generic', 'class="pictofixedwidth"');
1468 // @phan-suppress-next-line PhanPluginSuspiciousParamOrder
1469 print $form->selectarray('modelpdf', $list, $conf->global->FACTURE_ADDON_PDF);
1470 print "</td></tr>";
1471
1472 // Public note
1473 print '<tr>';
1474 print '<td class="tdtop">';
1475 print $form->textwithpicto($langs->trans('NotePublic'), $htmltext, 1, 'help', '', 0, 2, 'notepublic');
1476 print '</td>';
1477 print '<td>';
1478 $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3, '90%');
1479 print $doleditor->Create(1);
1480
1481 // Private note
1482 if (empty($user->socid)) {
1483 print '<tr>';
1484 print '<td class="tdtop">';
1485 print $form->textwithpicto($langs->trans('NotePrivate'), $htmltext, 1, 'help', '', 0, 2, 'noteprivate');
1486 print '</td>';
1487 print '<td>';
1488 $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3, '90%');
1489 print $doleditor->Create(1);
1490 // print '<textarea name="note_private" wrap="soft" cols="70" rows="'.ROWS_3.'">'.$note_private.'.</textarea>
1491 print '</td></tr>';
1492 }
1493
1494 print "</table>";
1495
1496 print dol_get_fiche_end();
1497
1498 // Autogeneration
1499 $title = $langs->trans("Recurrence");
1500 print load_fiche_titre(img_picto('', 'recurring', 'class="pictofixedwidth"').$title, '', '');
1501
1502 print '<span class="opacitymedium">'.$langs->trans("ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv('Module2300Name')).'</span><br><br>';
1503
1504 print dol_get_fiche_head([], '', '', 0);
1505
1506 print '<table class="border centpercent">';
1507
1508 // Frequency + unit
1509 print '<tr><td class="titlefieldcreate">'.$form->textwithpicto($langs->trans("Frequency"), $langs->transnoentitiesnoconv('toolTipFrequency'))."</td><td>";
1510 print '<input type="text" class="width50" name="frequency" value="'.GETPOST('frequency', 'int').'">&nbsp;';
1511 print $form->selectarray('unit_frequency', array('d' => $langs->trans('Day'), 'm' => $langs->trans('Month'), 'y' => $langs->trans('Year')), (GETPOST('unit_frequency') ? GETPOST('unit_frequency') : 'm'));
1512 print "</td></tr>";
1513
1514 // Date next run
1515 print "<tr><td>".$form->textwithpicto($langs->trans('NextDateToExecution'), $langs->trans("NextDateToExecutionHelp"))."</td><td>";
1516 $date_next_execution = isset($date_next_execution) ? $date_next_execution : (GETPOSTINT('remonth') ? dol_mktime(12, 0, 0, GETPOSTINT('remonth'), GETPOSTINT('reday'), GETPOSTINT('reyear')) : -1);
1517 print $form->selectDate($date_next_execution, '', 1, 1, 0, "add", 1, 1);
1518 print "</td></tr>";
1519
1520 // Number max of generation
1521 print "<tr><td>".$langs->trans("MaxPeriodNumber")."</td><td>";
1522 print '<input type="text" class="width50" name="nb_gen_max" value="'.GETPOSTINT('nb_gen_max').'">';
1523 print "</td></tr>";
1524
1525 // Auto validate the invoice
1526 print "<tr><td>".$langs->trans("StatusOfAutoGeneratedInvoices")."</td><td>";
1527 $select = array('0' => $langs->trans('BillStatusDraft'), '1' => $langs->trans('BillStatusValidated'), '2' => $langs->trans('BillStatusValidatedWithSendind'));
1528 print $form->selectarray('auto_validate', $select, GETPOSTINT('auto_validate'));
1529 print "</td></tr>";
1530
1531 // Email template for auto sending invoices
1532 print "<tr id='col_auto_send_model_mail' class='".(GETPOSTINT('auto_validate') != 2 ? 'hidden' : '')."'><td>" . $langs->trans("EmailTemplateForAutoSend") . "</td><td>";
1533 print $form->selectModelMail("auto_send_", "facture_send", 1, 0, GETPOSTINT('auto_send_model_mail'));
1534 print "</td></tr>";
1535 print " <script>
1536 $(document).ready(function() {
1537 $('#auto_validate').on('change', function () {
1538 if(+$(this).val() === 2) {
1539 $('#col_auto_send_model_mail').show();
1540 } else {
1541 $('#col_auto_send_model_mail').hide();
1542 $('#select_auto_send_model_mail').val(0);
1543 }
1544 });
1545 });
1546 </script>";
1547
1548 // Auto generate document
1549 if (getDolGlobalString('INVOICE_REC_CAN_DISABLE_DOCUMENT_FILE_GENERATION')) {
1550 print "<tr><td>".$langs->trans("StatusOfGeneratedDocuments")."</td><td>";
1551 $select = array('0' => $langs->trans('DoNotGenerateDoc'), '1' => $langs->trans('AutoGenerateDoc'));
1552 print $form->selectarray('generate_pdf', $select, GETPOSTINT('generate_pdf'));
1553 print "</td></tr>";
1554 } else {
1555 print '<input type="hidden" name="generate_pdf" value="1">';
1556 }
1557
1558 print "</table>";
1559
1560 print dol_get_fiche_end();
1561
1562
1563 $title = $langs->trans("ProductsAndServices");
1564 if (!isModEnabled('service')) {
1565 $title = $langs->trans("Products");
1566 } elseif (!isModEnabled('product')) {
1567 $title = $langs->trans("Services");
1568 }
1569
1570 print load_fiche_titre($title, '', '');
1571
1572 /*
1573 * Invoice lines
1574 */
1575 print '<div class="div-table-responsive-no-min">';
1576 print '<table id="tablelines" class="noborder noshadow centpercent nomarginbottom">';
1577
1578 // Show object lines
1579 if (!empty($sourceInvoice->lines)) {
1580 $sourceInvoice->printOriginLinesList('', $selectedLines);
1581 }
1582
1583 print "</table>\n";
1584 print '<div>';
1585
1586 print '</td></tr>';
1587
1588 $flag_price_may_change = getDolGlobalString('INVOICE_REC_PRICE_MAY_CHANGE');
1589 if (!empty($flag_price_may_change)) {
1590 print '<tr><td colspan="3" class="left">';
1591 print '<select name="usenewprice" class="flat">';
1592 print '<option value="0">'.$langs->trans("AlwaysUseFixedPrice").'</option>';
1593 print '<option value="1" disabled>'.$langs->trans("AlwaysUseNewPrice").'</option>';
1594 print '</select>';
1595 print '</td></tr>';
1596 }
1597 print "</table>\n";
1598
1599 print '<br>';
1600
1601 print $form->buttonsSaveCancel("Create");
1602
1603 print "</form>\n";
1604 } else {
1605 dol_print_error(null, "Error, no invoice ".$sourceInvoice->id);
1606 }
1607} else {
1608 // View mode
1609 if ($object->id > 0) {
1610 $object->fetch_thirdparty();
1611
1612 $formconfirm = '';
1613 // Confirmation of deletion of product line
1614 if ($action == 'ask_deleteline') {
1615 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 'no', 1);
1616 }
1617 // Confirm delete of repeatable invoice
1618 if ($action == 'delete') {
1619 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteRepeatableInvoice'), $langs->trans('ConfirmDeleteRepeatableInvoice'), 'confirm_delete', '', 'no', 1);
1620 }
1621 // Confirmation of deletion of the subtotal line
1622 if ($action == 'ask_subtotal_deleteline') {
1623 $langs->load("subtotals");
1624 $title = "DeleteSubtotalLine";
1625 $question = "ConfirmDeleteSubtotalLine";
1626 if (GETPOST('type') == 'title') {
1627 $formconfirm = array(array('type' => 'checkbox', 'name' => 'deletecorrespondingsubtotalline', 'label' => $langs->trans("DeleteCorrespondingSubtotalLine"), 'value' => 0));
1628 $title = "DeleteTitleLine";
1629 $question = "ConfirmDeleteTitleLine";
1630 }
1631 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans($title), $langs->trans($question), 'confirm_delete_subtotalline', $formconfirm, 'no', 1);
1632 }
1633
1634 // Subtotal line form
1635 if ($action == 'add_title_line') {
1636 $langs->load('subtotals');
1637 $type = 'title';
1638 $depth_array = $object->getPossibleLevels($langs);
1639 require dol_buildpath('/core/tpl/subtotal_create.tpl.php');
1640 } elseif ($action == 'add_subtotal_line') {
1641 $langs->load('subtotals');
1642 $type = 'subtotal';
1643 $titles = $object->getPossibleTitles();
1644 require dol_buildpath('/core/tpl/subtotal_create.tpl.php');
1645 } elseif ($action == 'add_text_line') {
1646 $langs->load('subtotals');
1647 $type = 'text';
1648 require dol_buildpath('/core/tpl/subtotal_create.tpl.php');
1649 }
1650
1651 // Call Hook formConfirm
1652 $parameters = array('formConfirm' => $formconfirm, 'lineid' => $lineid);
1653 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1654 if (empty($reshook)) {
1655 $formconfirm .= $hookmanager->resPrint;
1656 } elseif ($reshook > 0) {
1657 $formconfirm = $hookmanager->resPrint;
1658 }
1659
1660 print $formconfirm;
1661
1662 $author = new User($db);
1663 $author->fetch($object->user_creation_id);
1664
1665 $head = invoice_rec_prepare_head($object);
1666
1667 print dol_get_fiche_head($head, 'card', $langs->trans("RepeatableInvoice"), -1, $object->picto); // Add a div
1668
1669 // Recurring invoice content
1670
1671 $linkback = '<a href="'.DOL_URL_ROOT.'/compta/facture/invoicetemplate_list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
1672
1673 $morehtmlref = '';
1674 if ($action != 'editref') {
1675 $morehtmlref .= $form->editfieldkey($object->ref, 'ref', $object->ref, $object, $user->hasRight('facture', 'creer'), '', '', 0, 2);
1676 } else {
1677 $morehtmlref .= $form->editfieldval('', 'ref', $object->ref, $object, $user->hasRight('facture', 'creer'), 'string');
1678 }
1679
1680 $morehtmlref .= '<div class="refidno">';
1681 // Ref customer
1682 //$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_customer, $object, $user->hasRight('facture', 'creer'), 'string', '', 0, 1);
1683 //$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_customer, $object, $user->hasRight('facture', 'creer'), 'string', '', null, null, '', 1);
1684 // Thirdparty
1685 $morehtmlref .= $object->thirdparty->getNomUrl(1, 'customer');
1686 // Project
1687 if (isModEnabled('project')) {
1688 $langs->load("projects");
1689 $morehtmlref .= '<br>';
1690 if ($user->hasRight('facture', 'creer')) {
1691 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
1692 if ($action != 'classify') {
1693 $morehtmlref .= '<a class="editfielda" href="'.dolBuildUrl($_SERVER['PHP_SELF'], ['action' => 'classify', 'id' => $object->id], true).'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
1694 }
1695 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, (string) $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
1696 } else {
1697 if (!empty($object->fk_project)) {
1698 $proj = new Project($db);
1699 $proj->fetch($object->fk_project);
1700 $morehtmlref .= ' : '.$proj->getNomUrl(1);
1701 if ($proj->title) {
1702 $morehtmlref .= ' - '.$proj->title;
1703 }
1704 } else {
1705 $morehtmlref .= '';
1706 }
1707 }
1708 }
1709 $morehtmlref .= '</div>';
1710
1711 $morehtmlstatus = '';
1712
1713 dol_banner_tab($object, 'ref', $linkback, 1, 'title', 'none', $morehtmlref, '', 0, '', $morehtmlstatus);
1714
1715 print '<div class="fichecenter">';
1716 print '<div class="fichehalfleft">';
1717 print '<div class="underbanner clearboth"></div>';
1718
1719 print '<table class="border centpercent tableforfield">';
1720
1721 // Invoice subtype
1722 if (getDolGlobalInt('INVOICE_SUBTYPE_ENABLED')) {
1723 print "<tr><td>".$langs->trans("InvoiceSubtype")."</td><td>";
1724 if ($object->subtype > 0) {
1725 print $object->getSubtypeLabel('facture_rec');
1726 }
1727 print "</td></tr>";
1728 }
1729
1730 // Author
1731 print '<tr><td class="titlefieldmiddle">'.$langs->trans("Author").'</td><td>';
1732 print $author->getNomUrl(-1);
1733 print "</td></tr>";
1734
1735 // Payment term
1736 print '<tr><td>';
1737 print '<table class="nobordernopadding centpercent"><tr><td>';
1738 print $langs->trans('PaymentConditionsShort');
1739 print '</td>';
1740 if ($action != 'editconditions' && $user->hasRight('facture', 'creer')) {
1741 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editconditions&token='.newToken().'&facid='.$object->id.'">'.img_edit($langs->trans('SetConditions'), 1).'</a></td>';
1742 }
1743 print '</tr></table>';
1744 print '</td><td>';
1745 if ($action == 'editconditions') {
1746 $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id, (string) $object->cond_reglement_id, 'cond_reglement_id');
1747 } else {
1748 $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id, (string) $object->cond_reglement_id, 'none');
1749 }
1750 print '</td></tr>';
1751
1752 // Payment mode
1753 print '<tr><td>';
1754 print '<table class="nobordernopadding" width="100%"><tr><td>';
1755 print $langs->trans('PaymentMode');
1756 print '</td>';
1757 if ($action != 'editmode' && $user->hasRight('facture', 'creer')) {
1758 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmode&token='.newToken().'&facid='.$object->id.'">'.img_edit($langs->trans('SetMode'), 1).'</a></td>';
1759 }
1760 print '</tr></table>';
1761 print '</td><td>';
1762 if ($action == 'editmode') {
1763 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id, (string) $object->mode_reglement_id, 'mode_reglement_id', 'CRDT', 1, 1);
1764 } else {
1765 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?facid='.$object->id, (string) $object->mode_reglement_id, 'none');
1766 }
1767 print '</td></tr>';
1768
1769
1770 // Bank Account Customer
1771 if ($object->mode_reglement_code == $object::PAYMENTCODETOEDITSOCIETERIB) {
1772 print '<tr><td class="nowrap">';
1773 print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
1774 print $langs->trans('DebitBankAccount');
1775 print '<td>';
1776
1777 if (($action != 'editbankaccountcustomer') && $user->hasRight('facture', 'creer') && $object->status == FactureRec::STATUS_DRAFT) {
1778 print '<td class="right"><a class="editfielda" href="' . $_SERVER["PHP_SELF"] . '?action=editbankaccountcustomer&token=' . newToken() . '&id=' . $object->id . '">' . img_edit($langs->trans('SetDebitBankAccount'), 1) . '</a></td>';
1779 }
1780 print '</tr></table>';
1781 print '</td><td>';
1782
1783 if ($action == 'editbankaccountcustomer') {
1784 $form->formRib($_SERVER['PHP_SELF'] . '?id=' . $object->id, (string) $object->fk_societe_rib, 'accountcustomerid', 'fk_soc='.$object->socid, 1, 1);
1785 } else {
1786 $form->formRib($_SERVER['PHP_SELF'] . '?id=' . $object->id, (string) $object->fk_societe_rib, 'none', '', 0, 1);
1787 }
1788 print "</td>";
1789 print '</tr>';
1790 }
1791
1792 // Bank Account
1793 print '<tr><td class="nowrap">';
1794 print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
1795 print $langs->trans('BankAccount');
1796 print '<td>';
1797 if (($action != 'editbankaccount') && $user->hasRight('facture', 'creer') && $object->status == FactureRec::STATUS_DRAFT) {
1798 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editbankaccount&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetBankAccount'), 1).'</a></td>';
1799 }
1800 print '</tr></table>';
1801 print '</td><td>';
1802 if ($action == 'editbankaccount') {
1803 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $object->fk_account, 'fk_account', 1);
1804 } else {
1805 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, (string) $object->fk_account, 'none');
1806 }
1807 print "</td>";
1808 print '</tr>';
1809
1810 // Rule for line date. Need a hidden const as this generate unexpected dates into substitution variables
1811 if (getDolGlobalInt("FACTUREREC_SUPPORT_RULE_FOR_LINES")) {
1812 print '<tr><td>';
1813 print '<table class="nobordernopadding centpercent"><tr><td>';
1814 print $langs->trans('RuleForLinesDates');
1815 print '</td>';
1816 if ($action != 'editruleforlinesdates' && $user->hasRight('facture', 'creer')) {
1817 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editruleforlinesdates&token='.newToken().'&facid='.$object->id.'">'.img_edit($langs->trans('SetRuleForLinesDates'), 1).'</a></td>';
1818 }
1819 print '</tr></table>';
1820 print '</td><td>';
1821 if ($action == 'editruleforlinesdates') {
1822 $form->form_rule_for_lines_dates($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->rule_for_lines_dates, 'rule_for_lines_dates');
1823 } else {
1824 $form->form_rule_for_lines_dates($_SERVER['PHP_SELF'].'?facid='.$object->id, $object->rule_for_lines_dates, 'none');
1825 }
1826 print '</td></tr>';
1827 }
1828
1829 // Extrafields
1830 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1831
1832 // Model pdf
1833 print '<tr><td class="nowrap">';
1834 print '<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
1835 print $langs->trans('Model');
1836 print '<td>';
1837 if (($action != 'editmodelpdf') && $user->hasRight('facture', 'creer') && $object->status == FactureRec::STATUS_DRAFT) {
1838 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmodelpdf&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetModel'), 1).'</a></td>';
1839 }
1840 print '</tr></table>';
1841 print '</td><td>';
1842 if ($action == 'editmodelpdf') {
1843 include_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php';
1844 $list = array();
1845 $models = ModelePDFFactures::liste_modeles($db);
1846 foreach ($models as $k => $model) {
1847 $list[] = str_replace(':', '|', $k).':'.$model;
1848 }
1849 $select = 'select;'.implode(',', $list);
1850 print $form->editfieldval($langs->trans("Model"), 'modelpdf', $object->model_pdf, $object, $user->hasRight('facture', 'creer'), $select);
1851 } else {
1852 print $object->model_pdf;
1853 }
1854 print "</td>";
1855 print '</tr>';
1856
1857 // Other attributes
1858 $cols = 2;
1859
1860
1861 print '</table>';
1862
1863 print '</div>';
1864 print '<div class="fichehalfright">';
1865
1866 print '<!-- amounts -->'."\n";
1867 print '<div class="underbanner clearboth"></div>'."\n";
1868
1869 // Recurrence
1870 $title = $langs->trans("Recurrence");
1871
1872 print '<table class="border tableforfield centpercent">';
1873
1874 include DOL_DOCUMENT_ROOT.'/core/tpl/object_currency_amount.tpl.php';
1875
1876 $sign = 1;
1877 if (getDolGlobalString('INVOICE_POSITIVE_CREDIT_NOTE_SCREEN') && $object->type == $object::TYPE_CREDIT_NOTE) {
1878 $sign = -1; // We invert sign for output
1879 }
1880
1881 // Amount (excl. tax)
1882 print '<tr><td class="titlefieldmiddle">'.$langs->trans("AmountHT").'</td>';
1883 print '<td class="nowraponall amountcard right">'.price($sign * $object->total_ht, 0, $langs, 1, -1, -1, $conf->currency).'</td>';
1884 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
1885 // Multicurrency Amount HT
1886 print '<td class="nowraponall amountcard right">' . price($sign * $object->multicurrency_total_ht, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
1887 }
1888 print '</tr>';
1889
1890 // Amount tax
1891 print '<tr><td>'.$langs->trans("AmountVAT").'</td>';
1892 print '<td class="nowrap amountcard right">'.price($sign * $object->total_tva, 0, $langs, 1, -1, -1, $conf->currency).'</td>';
1893 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
1894 // Multicurrency Amount VAT
1895 print '<td class="nowraponall amountcard right">' . price($sign * $object->multicurrency_total_tva, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
1896 }
1897 print '</tr>';
1898
1899 // Amount Local Taxes
1900 if (($mysoc->localtax1_assuj == "1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0) { // Localtax1
1901 print '<tr>';
1902 print '<td class="titlefieldmiddle">'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td>';
1903 print '<td class="nowraponall amountcard right">'.price($sign * $object->total_localtax1, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>';
1904 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
1905 $object->multicurrency_total_localtax1 = (float) price2num($object->total_localtax1 * $object->multicurrency_tx, 'MT');
1906
1907 print '<td class="nowraponall amountcard right">' . price($sign * $object->multicurrency_total_localtax1, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
1908 }
1909 print '</tr>';
1910 }
1911
1912 if (($mysoc->localtax2_assuj == "1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0) { // Localtax2
1913 print '<tr>';
1914 print '<td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td>';
1915 print '<td class=nowraponall amountcard right">'.price($sign * $object->total_localtax2, 1, '', 1, - 1, - 1, $conf->currency).'</td></tr>';
1916 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
1917 $object->multicurrency_total_localtax2 = (float) price2num($object->total_localtax2 * $object->multicurrency_tx, 'MT');
1918
1919 print '<td class="nowraponall amountcard right">' . price($sign * $object->multicurrency_total_localtax2, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
1920 }
1921 print '</tr>';
1922 }
1923
1924 // Add the revenue stamp
1925 /*
1926 if ($selleruserevenustamp) {
1927 print '<tr><td class="titlefieldmiddle">';
1928 print '<table class="nobordernopadding centpercent"><tr><td>';
1929 print $langs->trans('RevenueStamp');
1930 print '</td>';
1931 if ($action != 'editrevenuestamp' && $object->status == $object::STATUS_DRAFT && $usercancreate) {
1932 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editrevenuestamp&token='.newToken().'&facid='.$object->id.'">'.img_edit($langs->trans('SetRevenuStamp'), 1).'</a></td>';
1933 }
1934 print '</tr></table>';
1935 print '</td><td class="nowrap amountcard right">';
1936 if ($action == 'editrevenuestamp') {
1937 print '<form action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
1938 print '<input type="hidden" name="token" value="'.newToken().'">';
1939 print '<input type="hidden" name="action" value="setrevenuestamp">';
1940 print '<input type="hidden" name="revenuestamp" id="revenuestamp_val" value="'.price2num($object->revenuestamp).'">';
1941 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
1942 print $formother->select_revenue_stamp('', 'revenuestamp_type', $mysoc->country_code);
1943 print ' &rarr; <span id="revenuestamp_span"></span>';
1944 print ' <input type="submit" class="button buttongen button-save small" value="'.$langs->trans('Modify').'">';
1945 print '</form>';
1946 print " <script>
1947 $(document).ready(function(){
1948 js_recalculate_revenuestamp();
1949 $('select[name=revenuestamp_type]').on('change',function(){
1950 js_recalculate_revenuestamp();
1951 });
1952 });
1953 function js_recalculate_revenuestamp(){
1954 var valselected = $('select[name=revenuestamp_type]').val();
1955 console.log('Calculate revenue stamp from '+valselected);
1956 var revenue = 0;
1957 if (valselected.indexOf('%') == -1)
1958 {
1959 revenue = valselected;
1960 }
1961 else
1962 {
1963 var revenue_type = parseFloat(valselected);
1964 var amount_net = ".round($object->total_ht, 2).";
1965 revenue = revenue_type * amount_net / 100;
1966 revenue = revenue.toFixed(2);
1967 }
1968 $('#revenuestamp_val').val(revenue);
1969 $('#revenuestamp_span').html(revenue);
1970 }
1971 </script>";
1972 } else {
1973 print price($object->revenuestamp, 1, '', 1, -1, -1, $conf->currency);
1974 }
1975 print '</td></tr>';
1976 }
1977 */
1978
1979 // Amount TTC
1980 print '<tr><td>'.$langs->trans("AmountTTC").'</td><td class="nowraponall amountcard right">'.price($sign * $object->total_ttc, 0, $langs, 1, -1, -1, $conf->currency).'</td>';
1981 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
1982 // Multicurrency Amount TTC
1983 print '<td class="nowrap amountcard right">' . price($sign * $object->multicurrency_total_ttc, 0, $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
1984 }
1985 print '</tr>';
1986
1987 // Recurring info
1988 print '<tr class="liste_titre"><td class="liste_titre">'.img_picto('', 'recurring', 'class="pictofixedwidth"').$title.'</td>';
1989 print '<td></td>';
1990 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
1991 print '<td></td>';
1992 }
1993 print '</tr>';
1994
1995 // if "frequency" is empty or = 0, the recurrence is disabled
1996 print '<tr><td style="width: 50%">';
1997 print '<table class="nobordernopadding" width="100%"><tr><td>';
1998 print $langs->trans('Frequency');
1999 print '</td>';
2000 if ($action != 'editfrequency' && $user->hasRight('facture', 'creer')) {
2001 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editfrequency&token='.newToken().'&facid='.$object->id.'">'.img_edit($langs->trans('Edit'), 1).'</a></td>';
2002 }
2003 print '</tr></table>';
2004 print '</td><td>';
2005 if ($action == 'editfrequency') {
2006 print '<form method="post" action="'.$_SERVER["PHP_SELF"].'?facid='.$object->id.'">';
2007 print '<input type="hidden" name="action" value="setfrequency">';
2008 print '<input type="hidden" name="token" value="'.newToken().'">';
2009 print '<table class="nobordernopadding">';
2010 print '<tr><td>';
2011 print '<input type="text" name="frequency" class="width50 marginrightonly right" value="'.$object->frequency.'">';
2012 print $form->selectarray('unit_frequency', array('d' => $langs->trans('Day'), 'm' => $langs->trans('Month'), 'y' => $langs->trans('Year')), ($object->unit_frequency ? $object->unit_frequency : 'm'));
2013 print '</td>';
2014 print '<td class="left"><input type="submit" class="button button-edit smallpaddingimp" value="'.$langs->trans("Modify").'"></td>';
2015 print '</tr></table></form>';
2016 } else {
2017 if ($object->frequency > 0) {
2018 print $langs->trans('FrequencyPer_'.$object->unit_frequency, $object->frequency);
2019 } else {
2020 print '<span class="opacitymedium">'.$langs->trans("NotARecurringInvoiceTemplate").'</span>';
2021 }
2022 }
2023 print '</td>';
2024 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2025 print '<td></td>';
2026 }
2027 print '</tr>';
2028
2029 if ($object->frequency > 0) {
2030 // Date when (next invoice generation)
2031 print '<tr><td>';
2032 if ($action == 'date_when' || $object->frequency > 0) {
2033 print $form->editfieldkey($form->textwithpicto($langs->trans("NextDateToExecution"), $langs->trans("NextDateToExecutionHelp")), 'date_when', $object->date_when, $object, $user->hasRight('facture', 'creer'), 'day');
2034 } else {
2035 print $form->textwithpicto($langs->trans("NextDateToExecution"), $langs->trans("NextDateToExecutionHelp"));
2036 }
2037 print '</td><td'.(isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency) ? ' colspan="2"' : '').'>';
2038 if ($action == 'date_when' || $object->frequency > 0) {
2039 print $form->editfieldval($langs->trans("NextDateToExecution"), 'date_when', $object->date_when, $object, $user->hasRight('facture', 'creer'), 'day', $object->date_when, null, '', '', 0, 'strikeIfMaxNbGenReached');
2040 }
2041 //var_dump(dol_print_date($object->date_when+60, 'dayhour').' - '.dol_print_date($now, 'dayhour'));
2042 if (!$object->isMaxNbGenReached()) {
2043 if (!$object->suspended && $action != 'editdate_when' && $object->frequency > 0 && $object->date_when && $object->date_when < $now) {
2044 print img_warning($langs->trans("Late"));
2045 }
2046 } else {
2047 print img_info($langs->trans("MaxNumberOfGenerationReached"));
2048 }
2049 print '</td>';
2050 print '</tr>';
2051
2052 // Max period / Rest period
2053 print '<tr><td>';
2054 if ($action == 'nb_gen_max' || $object->frequency > 0) {
2055 print $form->editfieldkey($langs->trans("MaxPeriodNumber"), 'nb_gen_max', (string) $object->nb_gen_max, $object, $user->hasRight('facture', 'creer'));
2056 } else {
2057 print $langs->trans("MaxPeriodNumber");
2058 }
2059 print '</td><td>';
2060 if ($action == 'nb_gen_max' || $object->frequency > 0) {
2061 print $form->editfieldval($langs->trans("MaxPeriodNumber"), 'nb_gen_max', $object->nb_gen_max ? $object->nb_gen_max : '', $object, $user->hasRight('facture', 'creer'));
2062 } else {
2063 print '';
2064 }
2065 print '</td>';
2066 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2067 print '<td></td>';
2068 }
2069 print '</tr>';
2070
2071 // Status of auto generated invoices
2072 print '<tr><td>';
2073 if ($action == 'auto_validate' || $object->frequency > 0) {
2074 print $form->editfieldkey($langs->trans("StatusOfAutoGeneratedInvoices"), 'auto_validate', (string) $object->auto_validate, $object, $user->hasRight('facture', 'creer'));
2075 } else {
2076 print $langs->trans("StatusOfAutoGeneratedInvoices");
2077 }
2078 print '</td><td>';
2079 $select = 'select;0:' . $langs->trans('BillStatusDraft') . ',1:' . $langs->trans('BillStatusValidated') . ',2:' . $langs->trans('BillStatusValidatedWithSendind');
2080 if ($action == 'auto_validate' || $object->frequency > 0) {
2081 print $form->editfieldval($langs->trans("StatusOfAutoGeneratedInvoices"), 'auto_validate', $object->auto_validate, $object, $user->hasRight('facture', 'creer'), $select);
2082 }
2083 print '</td>';
2084 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2085 print '<td></td>';
2086 }
2087 print '</tr>';
2088
2089 // Email template for auto sending invoices
2090 if ($object->frequency > 0 && $object->auto_validate == 2) {
2091 print '<tr><td style="width: 50%">';
2092 print '<table class="nobordernopadding" width="100%"><tr><td>';
2093 print $langs->trans("EmailTemplateForAutoSend");
2094 print '</td>';
2095 if ($action != 'editEmailTemplate' && $user->hasRight('facture', 'creer')) {
2096 print '<td class="right"><a class="editfielda" href="' . $_SERVER["PHP_SELF"] . '?action=editEmailTemplate&token=' . newToken() . '&facid=' . $object->id . '">' . img_edit($langs->trans('Edit'), 1) . '</a></td>';
2097 }
2098 print '</tr></table>';
2099 print '</td><td>';
2100
2101 if ($action == 'editEmailTemplate') {
2102 // Edit
2103 print '<form method="POST" action="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '">';
2104 print '<input type="hidden" name="token" value="' . newToken() . '">';
2105 print '<input type="hidden" name="action" value="setEmailTemplate">';
2106 print $form->selectModelMail("auto_send_", "facture_send", 1, 0, $object->fk_email_template);
2107 print '<input type="submit" class="button valignmiddle smallpaddingimp" name="modify" value="' . $langs->trans("Modify") . '">';
2108 print '<input type="submit" class="button button-cancel valignmiddle smallpaddingimp" name="cancel" value="' . $langs->trans("Cancel") . '">';
2109 print '</form>';
2110 } else {
2111 // Show
2112 if (!empty($object->fk_email_template)) {
2113 $sql = "SELECT label
2114 FROM ".$db->prefix()."c_email_templates
2115 WHERE rowid = ".((int) $object->fk_email_template);
2116 $result = $db->query($sql);
2117 if ($result) {
2118 if ($obj = $db->fetch_object($result)) {
2119 print $obj->label;
2120 }
2121 }
2122 } else {
2123 print $langs->trans('DefaultMailModel');
2124 }
2125 }
2126
2127 print '</td>';
2128 print '</tr>';
2129 }
2130
2131 // Auto generate documents
2132 if (getDolGlobalString('INVOICE_REC_CAN_DISABLE_DOCUMENT_FILE_GENERATION')) {
2133 print '<tr>';
2134 print '<td>';
2135 if ($action == 'generate_pdf' || $object->frequency > 0) {
2136 print $form->editfieldkey($langs->trans("StatusOfGeneratedDocuments"), 'generate_pdf', (string) $object->generate_pdf, $object, $user->hasRight('facture', 'creer'));
2137 } else {
2138 print $langs->trans("StatusOfGeneratedDocuments");
2139 }
2140 print '</td>';
2141 print '<td>';
2142 $select = 'select;0:'.$langs->trans('DoNotGenerateDoc').',1:'.$langs->trans('AutogenerateDoc');
2143 if ($action == 'generate_pdf' || $object->frequency > 0) {
2144 print $form->editfieldval($langs->trans("StatusOfGeneratedDocuments"), 'generate_pdf', $object->generate_pdf, $object, $user->hasRight('facture', 'creer'), $select);
2145 }
2146 print '</td>';
2147 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
2148 print '<td></td>';
2149 }
2150 print '</tr>';
2151 } else {
2152 print '<input type="hidden" name="generate_pdf" value="1">';
2153 }
2154 }
2155
2156 print '</table>';
2157
2158 // Frequencry/Recurring section
2159 if ($object->frequency > 0) {
2160 print '<br>';
2161
2162 if (!isModEnabled('cron')) {
2163 print info_admin($langs->trans("EnableAndSetupModuleCron", $langs->transnoentitiesnoconv("Module2300Name")));
2164 }
2165
2166 print '<div class="underbanner clearboth"></div>';
2167 print '<table class="border centpercent tableforfield">';
2168
2169 // Nb of generation already done
2170 print '<tr><td style="width: 50%">'.$langs->trans("NbOfGenerationDone").'</td>';
2171 print '<td>';
2172 print $object->nb_gen_done ? $object->nb_gen_done : '0';
2173 print '</td>';
2174 print '</tr>';
2175
2176 // Date last
2177 print '<tr><td>';
2178 print $langs->trans("DateLastGeneration");
2179 print '</td><td>';
2180 print dol_print_date($object->date_last_gen, 'dayhour');
2181 print '</td>';
2182 print '</tr>';
2183
2184 print '</table>';
2185
2186 print '<br>';
2187 }
2188
2189 print '</div>';
2190 print '</div>';
2191
2192 print '<div class="clearboth"></div><br>';
2193
2194
2195 // Lines
2196 print '<form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.(($action != 'editline') ? '#add' : '#line_'.GETPOSTINT('lineid')).'" method="POST">';
2197 print '<input type="hidden" name="token" value="' . newToken().'">';
2198 print '<input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline').'">';
2199 print '<input type="hidden" name="mode" value="">';
2200 print '<input type="hidden" name="id" value="' . $object->id.'">';
2201 print '<input type="hidden" name="page_y" value="">';
2202
2203 if (!empty($conf->use_javascript_ajax) && $object->status == 0) {
2204 if (isModEnabled('subtotals')) {
2205 include DOL_DOCUMENT_ROOT.'/core/tpl/subtotal_ajaxrow.tpl.php';
2206 } else {
2207 include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php';
2208 }
2209 }
2210
2211 print '<div class="div-table-responsive-no-min">';
2212 print '<table id="tablelines" class="noborder noshadow centpercent nomarginbottom">';
2213 // Show object lines
2214 if (!empty($object->lines)) {
2215 $canchangeproduct = 1;
2216 $object->printObjectLines($action, $mysoc, $object->thirdparty, $lineid, 0); // No date selector for template invoice
2217 }
2218
2219 // Form to add new line
2220 if ($object->status == $object::STATUS_DRAFT && $user->hasRight('facture', 'creer') && $action != 'valid' && $action != 'editline') {
2221 if ($action != 'editline') {
2222 // Add free products/services
2223
2224 $parameters = array();
2225 $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2226 if ($reshook < 0) {
2227 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
2228 }
2229 if (empty($reshook)) {
2230 $object->formAddObjectLine(0, $mysoc, $object->thirdparty);
2231 } // No date selector for template invoice
2232 }
2233 }
2234
2235 print "</table>\n";
2236 print '</div>';
2237
2238 print "</form>\n";
2239
2240 print dol_get_fiche_end();
2241
2242
2243 /*
2244 * Action bar
2245 */
2246 print '<div class="tabsAction">';
2247
2248 $parameters = array();
2249 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2250 if (empty($reshook)) {
2251 $params = array(
2252 'attr' => array(
2253 'class' => 'classfortooltip',
2254 ),
2255 );
2256
2257 // Subtotal
2258 if (empty($object->suspended) && isModEnabled('subtotals')
2259 && (getDolGlobalInt('SUBTOTAL_TITLE_'.strtoupper($object->element)) || getDolGlobalInt('SUBTOTAL_'.strtoupper($object->element)) || getDolGlobalInt('SUBTOTAL_TEXT_'.strtoupper($object->element)))) {
2260 $langs->load("subtotals");
2261
2262 $url_button = array();
2263
2264 $url_button[] = array(
2265 'lang' => 'subtotals',
2266 'enabled' => (isModEnabled('invoice') && $object->status == Facture::STATUS_DRAFT && getDolGlobalInt('SUBTOTAL_TITLE_'.strtoupper($object->element))),
2267 'perm' => (bool) $usercancreate,
2268 'label' => $langs->trans('AddTitleLine'),
2269 'url' => '/compta/facture/card-rec.php?id='.$object->id.'&action=add_title_line&token='.newToken()
2270 );
2271
2272 $url_button[] = array(
2273 'lang' => 'subtotals',
2274 'enabled' => (isModEnabled('invoice') && $object->status == Facture::STATUS_DRAFT && getDolGlobalInt('SUBTOTAL_'.strtoupper($object->element))),
2275 'perm' => (bool) $usercancreate,
2276 'label' => $langs->trans('AddSubtotalLine'),
2277 'url' => '/compta/facture/card-rec.php?id='.$object->id.'&action=add_subtotal_line&token='.newToken()
2278 );
2279
2280 $url_button[] = array(
2281 'lang' => 'subtotals',
2282 'enabled' => (isModEnabled('invoice') && $object->status == Facture::STATUS_DRAFT && getDolGlobalInt('SUBTOTAL_TEXT_'.strtoupper($object->element))),
2283 'perm' => (bool) $usercancreate,
2284 'label' => $langs->trans('AddTextLine'),
2285 'url' => '/compta/facture/card-rec.php?id='.$object->id.'&action=add_text_line&token='.newToken()
2286 );
2287 print dolGetButtonAction('', $langs->trans('SubTotal'), 'default', $url_button, '', true);
2288 }
2289
2290 if (empty($object->suspended)) {
2291 if ($user->hasRight('facture', 'creer')) {
2292 if (!empty($object->frequency) && $object->nb_gen_max > 0 && ($object->nb_gen_done >= $object->nb_gen_max)) {
2293 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag($langs->trans("MaxGenerationReached")) . '">' . $langs->trans("CreateBill") . '</a></div>';
2294 } else {
2295 if (empty($object->frequency) || $object->date_when <= $nowlasthour) {
2296 print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/compta/facture/card.php?action=create&socid=' . $object->thirdparty->id . '&fac_rec=' . $object->id . '">' . $langs->trans("CreateBill") . '</a></div>';
2297 } else {
2298 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag($langs->trans("DateIsNotEnough")) . '">' . $langs->trans("CreateBill") . '</a></div>';
2299 }
2300 }
2301 } else {
2302 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">' . $langs->trans("CreateBill") . '</a></div>';
2303 }
2304 }
2305
2306 if ($user->hasRight('facture', 'creer')) {
2307 if (empty($object->suspended)) {
2308 print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER["PHP_SELF"].'?action=disable&id='.$object->id.'&token='.newToken().'">'.$langs->trans("Disable").'</a></div>';
2309 } else {
2310 print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=enable&id='.$object->id.'&token='.newToken().'">'.$langs->trans("Enable").'</a></div>';
2311 }
2312 }
2313
2314 // Delete
2315 print dolGetButtonAction($langs->trans("Delete"), $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=delete&token=' . newToken(), 'delete', $user->hasRight('facture', 'supprimer'), array('attr' => array('class' => 'reposition')))."\n";
2316 }
2317 print '</div>';
2318
2319
2320
2321 print '<div class="fichecenter"><div class="fichehalfleft">';
2322 print '<a name="builddoc"></a>'; // ancre
2323
2324
2325 // Show links to link elements
2326 $tmparray = $form->showLinkToObjectBlock($object, array(), array('invoice'), 1);
2327 $linktoelem = $tmparray['linktoelem'];
2328 $htmltoenteralink = $tmparray['htmltoenteralink'];
2329 print $htmltoenteralink;
2330
2331 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
2332
2333
2334 print '</div>';
2335 print '<div class="fichehalfright">';
2336
2337 $MAXEVENT = 10;
2338
2339 $morehtmlcenter = '<div class="nowraponall">';
2340 //$morehtmlcenter .= dolGetButtonTitle($langs->trans('FullConversation'), '', 'fa fa-comments imgforviewmode', DOL_URL_ROOT.'/compta/facture/messaging.php?id='.$object->id);
2341 $morehtmlcenter .= dolGetButtonTitle($langs->trans('FullList'), '', 'fa fa-bars imgforviewmode', DOL_URL_ROOT.'/compta/facture/agenda-rec.php?id='.$object->id);
2342 $morehtmlcenter .= '</div>';
2343
2344 // List of actions on element
2345 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
2346 $formactions = new FormActions($db);
2347 $somethingshown = $formactions->showactions($object, $object->element, (is_object($object->thirdparty) ? $object->thirdparty->id : 0), 1, '', $MAXEVENT, '', $morehtmlcenter);
2348
2349 print '</div>';
2350 print '</div>';
2351 } else {
2352 print $langs->trans("NoRecordFound");
2353 }
2354}
2355
2356// End of page
2357llxFooter();
2358$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
const STATUS_DRAFT
Draft status.
Class to manage a WYSIWYG editor.
Class to manage invoices.
const TYPE_REPLACEMENT
Replacement invoice.
const STATUS_DRAFT
Draft status.
const TYPE_STANDARD
Standard invoice.
Class to manage invoice lines of templates.
Class to manage invoice templates.
Class to manage building of HTML components.
Class to manage generation of HTML components Only common components must be here.
Class to help generate other html components Only common components are here.
Class to manage building of HTML components.
static liste_modeles($db, $maxfilenamelength=0)
Return list of active generation modules.
Class to manage products or services.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
global $mysoc
dol_get_last_hour($date, $gm='tzserver')
Return GMT time for last hour of a given GMT date (it replaces hours, min and second part to 23:59:59...
Definition date.lib.php:672
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0, $tz='')
Add a delay to a date.
Definition date.lib.php:127
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
recordNotFound($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Displays an error page when a record is not found.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular VAT rate, when selling a product with vat $vatrate,...
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:542
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='', $textonpictotooltip='', $cssfordropdown='info_admin')
Show information in HTML for admin users or standard users.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183
invoice_rec_prepare_head($object)
Return array head with list of tabs to view object information.
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
Check permissions of a user to show a page and an object.