dolibarr 21.0.3
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-2016 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 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-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
10 * Copyright (C) 2016 Meziane Sof <virtualsof@yahoo.fr>
11 * Copyright (C) 2017-2024 Frédéric France <frederic.france@free.fr>
12 * Copyright (C) 2023-2024 Nick Fragoulis
13 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 3 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program. If not, see <https://www.gnu.org/licenses/>.
27 */
28
35// Load Dolibarr environment
36require '../../main.inc.php';
37require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture-rec.class.php';
38require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.product.class.php';
39require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
40require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php';
41if (isModEnabled('project')) {
42 include_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
43}
44require_once DOL_DOCUMENT_ROOT . '/core/class/html.formprojet.class.php';
45require_once DOL_DOCUMENT_ROOT . '/core/class/doleditor.class.php';
46require_once DOL_DOCUMENT_ROOT . '/core/lib/invoice.lib.php';
47require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
48
58// Load translation files required by the page
59$langs->loadLangs(array('bills', 'companies', 'compta', 'admin', 'other', 'products', 'banks', 'suppliers'));
60
61$action = GETPOST('action', 'alpha');
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');
67$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'supplierinvoicetemplatelist'; // To manage different context of search
68
69$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
70$sortfield = GETPOST("sortfield", 'alpha');
71$sortorder = GETPOST("sortorder", 'alpha');
72$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
73
74// Security check
75$id = (GETPOSTINT('facid') ? GETPOSTINT('facid') : GETPOSTINT('id'));
76$lineid = GETPOSTINT('lineid');
77$title = GETPOST('title', 'alpha');
78$libelle = GETPOST('libelle', 'alpha');
79$ref_supplier = GETPOST('ref_supplier', 'alpha');
80$projectid = GETPOSTINT('projectid');
81$year_date_when = GETPOST('year_date_when');
82$month_date_when = GETPOST('month_date_when');
83// Security check
84$socid = GETPOSTINT('socid');
85if ($user->socid) {
86 $socid = $user->socid;
87}
88$objecttype = 'facture_fourn_rec';
89if ($action == "create" || $action == "add") {
90 $objecttype = '';
91}
92
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
107if (($id > 0 || $title) && $action != 'create' && $action != 'add') {
108 $ret = $object->fetch($id, $title);
109 if (! $ret) {
110 setEventMessages($langs->trans("ErrorRecordNotFound"), null, 'errors');
111 }
112}
113
114// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
115$hookmanager->initHooks(array('supplierinvoicereccard', 'globalcard'));
116$extrafields = new ExtraFields($db);
117
118// fetch optionals attributes and labels
119$extrafields->fetch_name_optionals_label($object->table_element);
120
121$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
122
123$permissionnote = $user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"); // Used by the include of actions_setnotes.inc.php
124$permissiondellink = $user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"); // Used by the include of actions_dellink.inc.php
125$permissiontoedit = $user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"); // Used by the include of actions_lineupdonw.inc.php
126$permissiontoadd = $user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer");
127$permissiontodelete = ($user->hasRight("fournisseur", "facture", "supprimer") || $user->hasRight("supplier_invoice", "supprimer"));
128
129$usercanread = $user->hasRight("fournisseur", "facture", "lire") || $user->hasRight("supplier_invoice", "lire");
130$usercancreate = $user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer");
131$usercandelete = $user->hasRight("fournisseur", "facture", "supprimer") || $user->hasRight("supplier_invoice", "supprimer");
132$usercanvalidate = ((!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !empty($usercancreate)) || (getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && $user->hasRight("fournisseur", "supplier_invoice_advance", "validate")));
133$usercansend = (!getDolGlobalString('MAIN_USE_ADVANCED_PERMS') || $user->hasRight("fournisseur", "supplier_invoice_advance", "send"));
134
135$usercanproductignorepricemin = ((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight("produit", "ignore_price_min_advance")) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS'));
136$usercancreatemargin = $user->hasRight("margins", "creer");
137$usercanreadallmargin = $user->hasRight("margins", "liretous");
138$usercancreatewithdrarequest = $user->hasRight("prelevement", "bons", "creer");
139
140$now = dol_now();
141
142$error = 0;
143
144$result = restrictedArea($user, 'supplier_invoicerec', $object->id, $objecttype);
145
146
147/*
148 * Actions
149 */
150
151if (GETPOST('cancel', 'alpha')) {
152 $action = 'list';
153 $massaction = '';
154}
155if (! GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
156 $massaction = '';
157}
158
159$parameters = array('socid' => $socid);
160$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
161if ($reshook < 0) {
162 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
163}
164
165if (empty($reshook)) {
166 if (GETPOST('cancel', 'alpha')) {
167 $action = '';
168 }
169
170 // Selection of new fields
171 include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php';
172
173 // Set note
174 include DOL_DOCUMENT_ROOT . '/core/actions_setnotes.inc.php'; // Must be 'include', not 'include_once'
175
176 include DOL_DOCUMENT_ROOT . '/core/actions_dellink.inc.php'; // Must be 'include', not 'include_once'
177
178 include DOL_DOCUMENT_ROOT . '/core/actions_lineupdown.inc.php'; // Must be 'include', not 'include_once'
179
180 // Create predefined invoice
181 if ($action == 'add' && $permissiontoadd) {
182 if (! GETPOST('title', 'alphanohtml')) {
183 setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("Title")), null, 'errors');
184 $action = "create";
185 $error++;
186 }
187
188 $frequency = GETPOSTINT('frequency');
189 $reyear = GETPOSTINT('reyear');
190 $remonth = GETPOSTINT('remonth');
191 $reday = GETPOSTINT('reday');
192 $rehour = GETPOSTINT('rehour');
193 $remin = GETPOSTINT('remin');
194 $nb_gen_max = GETPOSTINT('nb_gen_max');
195 //if (empty($nb_gen_max)) $nb_gen_max =0;
196
197 if (GETPOSTINT('frequency')) {
198 if (empty($reyear) || empty($remonth) || empty($reday)) {
199 setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->trans("Date")), null, 'errors');
200 $action = "create";
201 $error++;
202 }
203 }
204
205 if (! $error) {
206 $object->subtype = GETPOSTINT('subtype');
207 $object->title = GETPOST('title', 'alphanohtml');
208 $object->libelle = GETPOST('libelle', 'alpha'); // deprecated
209 $object->label = GETPOST('libelle', 'alpha');
210 $object->fk_project = GETPOSTINT('projectid');
211 $object->ref_supplier = GETPOST('ref_supplier', 'alphanohtml');
212
213 $object->note_private = GETPOST('note_private', 'restricthtml');
214 $object->note_public = GETPOST('note_public', 'restricthtml');
215 $object->model_pdf = GETPOST('modelpdf', 'alpha');
216 $object->usenewprice = GETPOSTINT('usenewprice');
217
218 $object->frequency = $frequency;
219 $object->unit_frequency = GETPOST('unit_frequency', 'alpha');
220 $object->nb_gen_max = $nb_gen_max;
221 $object->auto_validate = GETPOSTINT('auto_validate');
222 $object->generate_pdf = GETPOSTINT('generate_pdf');
223
224 $date_next_execution = dol_mktime($rehour, $remin, 0, $remonth, $reday, $reyear);
225 $object->date_when = $date_next_execution;
226
227 $ret = $extrafields->setOptionalsFromPost(null, $object);
228 if ($ret < 0) {
229 $error++;
230 }
231
232
233 $db->begin();
234
235 $oldinvoice = new FactureFournisseur($db);
236 $oldinvoice->fetch(GETPOSTINT('facid'));
237
238
239 $result = $object->create($user, $oldinvoice->id);
240
241 if ($result > 0) {
242 $result = $oldinvoice->delete($user, 1);
243 if ($result < 0) {
244 $error++;
245 setEventMessages($oldinvoice->error, $oldinvoice->errors, 'errors');
246 $action = "create";
247 }
248 } else {
249 $error++;
250 setEventMessages($object->error, $object->errors, 'errors');
251 $action = "create";
252 }
253
254 if (! $error) {
255 $db->commit();
256
257 header("Location: " . $_SERVER['PHP_SELF'] . '?facid=' . $object->id);
258 exit;
259 } else {
260 $db->rollback();
261
262 $error++;
263 setEventMessages($object->error, $object->errors, 'errors');
264 $action = "create";
265 }
266 }
267 }
268
269 // Delete
270 //TODO : Droits
271 if ($action == 'confirm_deleteinvoice' && $confirm == 'yes' && $permissiontodelete) {
272 $object->delete($user);
273
274 header('Location: ' . DOL_URL_ROOT . '/fourn/facture/list-rec.php');
275 exit;
276 }
277
278 // Update field
279 // Set condition
280 if ($action == 'setconditions' && $usercancreate) {
281 $result = $object->setPaymentTerms(GETPOSTINT('cond_reglement_id'));
282 } elseif ($action == 'setmode' && $usercancreate) {
283 // Set mode
284 $result = $object->setPaymentMethods(GETPOSTINT('mode_reglement_id'));
285 } elseif ($action == 'classin' && $usercancreate) {
286 // Set project
287 $object->setProject(GETPOSTINT('projectid'));
288 } elseif ($action == 'setref_supplier' && $usercancreate) {
289 $result = $object->setValueFrom('ref_supplier', $ref_supplier, '', null, 'text', '', $user);
290
291 if ($result <= 0) {
292 $error++;
293 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
294 $langs->load("errors");
295 setEventMessages($langs->trans('ErrorRefAlreadyExists', $ref_supplier), null, 'errors');
296 } else {
297 setEventMessages($object->error, $object->errors, 'errors');
298 }
299 }
300 } elseif ($action == 'settitle' && $permissiontoadd) {
301 $result = $object->setValueFrom('titre', $title, '', null, 'text', '', $user);
302
303 if ($result > 0) {
304 $object->titre = $title; // deprecated
305 $object->title = $title;
306 $object->ref = $object->title;
307 } else {
308 $error++;
309 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
310 $langs->load("errors");
311 setEventMessages($langs->trans('ErrorTitreAlreadyExists', $title), null, 'errors');
312 } else {
313 setEventMessages($object->error, $object->errors, 'errors');
314 }
315 }
316 } elseif ($action == 'setbankaccount' && $permissiontoadd) {
317 // Set bank account
318 $result = $object->setBankAccount(GETPOSTINT('fk_account'));
319 } elseif ($action == 'setfrequency' && $permissiontoadd) {
320 // Set frequency and unit frequency
321 $object->setFrequencyAndUnit(GETPOST('frequency', 'int'), GETPOST('unit_frequency', 'alpha'));
322 } elseif ($action == 'setdate_when' && $permissiontoadd) {
323 // Set next date of execution
324 $date = dol_mktime(GETPOST('date_whenhour'), GETPOST('date_whenmin'), 0, GETPOST('date_whenmonth'), GETPOST('date_whenday'), GETPOST('date_whenyear'));
325 if (!empty($date)) {
326 $object->setNextDate($date);
327 }
328 } elseif ($action == 'setnb_gen_max' && $permissiontoadd) {
329 // Set max period
330 $object->setMaxPeriod(GETPOSTINT('nb_gen_max'));
331 } elseif ($action == 'setauto_validate' && $permissiontoadd) {
332 // Set auto validate
333 $object->setAutoValidate(GETPOSTINT('auto_validate'));
334 } elseif ($action == 'setgenerate_pdf' && $permissiontoadd) {
335 // Set generate pdf
336 $object->setGeneratepdf(GETPOSTINT('generate_pdf'));
337 } elseif ($action == 'setmodelpdf' && $permissiontoadd) {
338 // Set model pdf
339 $object->setModelpdf(GETPOST('modelpdf', 'alpha'));
340 } elseif ($action == 'disable' && $permissiontoadd) {
341 // Set status disabled
342 $db->begin();
343
344 $object->fetch($id);
345
346 $res = $object->setValueFrom('suspended', 1);
347 if ($res <= 0) {
348 $error++;
349 }
350
351 if (! $error) {
352 $db->commit();
353 } else {
354 $db->rollback();
355 setEventMessages($object->error, $object->errors, 'errors');
356 }
357 } elseif ($action == 'enable' && $permissiontoadd) {
358 // Set status enabled
359 $db->begin();
360
361 $object->fetch($id);
362
363 $res = $object->setValueFrom('suspended', 0);
364 if ($res <= 0) {
365 $error++;
366 }
367
368 if (! $error) {
369 $db->commit();
370 } else {
371 $db->rollback();
372 setEventMessages($object->error, $object->errors, 'errors');
373 }
374 } elseif ($action == 'setmulticurrencycode' && $permissiontoadd) {
375 // Multicurrency Code
376 $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha'));
377 } elseif ($action == 'setmulticurrencyrate' && $permissiontoadd) {
378 // Multicurrency rate
379 $result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx')), GETPOSTINT('calculation_mode'));
380 } elseif ($action == 'setlibelle' && $permissiontoadd) {
381 // Set label
382 $object->fetch($id);
383 $object->libelle = GETPOST('libelle');
384 $object->label = GETPOST('libelle');
385 $result = $object->update($user);
386
387 if ($result < 0) {
388 dol_print_error($db);
389 }
390 }
391
392 // Delete line
393 if ($action == 'confirm_deleteline' && $confirm == 'yes' && $permissiontoadd) {
394 $object->fetch($id);
395 $object->fetch_thirdparty();
396
397 $db->begin();
398
399 $line = new FactureFournisseurLigneRec($db);
400
401 // For triggers
402 $line->id = $lineid;
403
404 if ($line->delete($user) > 0) {
405 $result = $object->update_price(1);
406
407 if ($result > 0) {
408 $db->commit();
409 $object->fetch($object->id); // Reload lines
410 } else {
411 $db->rollback();
412 setEventMessages($db->lasterror(), null, 'errors');
413 }
414 } else {
415 $db->rollback();
416 setEventMessages($line->error, $line->errors, 'errors');
417 }
418 } elseif ($action == 'update_extras' && $permissiontoadd) {
419 $object->oldcopy = dol_clone($object, 2);
420
421 // Fill array 'array_options' with data from update form
422 $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
423 if ($ret < 0) {
424 $error++;
425 }
426
427 if (! $error) {
428 $result = $object->insertExtraFields('BILLREC_MODIFY');
429 if ($result < 0) {
430 setEventMessages($object->error, $object->errors, 'errors');
431 $error++;
432 }
433 }
434 }
435
436 // Add a new line
437 if ($action == 'addline' && $permissiontoadd) {
438 $langs->load('errors');
439 $error = 0;
440
441 // Set if we used free entry or predefined product
442
443 $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : '');
444 $price_ht = price2num(GETPOST('price_ht'), 'MU', 2);
445 $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU', 2);
446 $prod_entry_mode = GETPOST('prod_entry_mode', 'alpha');
447 if ($prod_entry_mode == 'free') {
448 $idprod = 0;
449 $tva_tx = (GETPOST('tva_tx', 'alpha') ? GETPOST('tva_tx', 'alpha') : 0);
450 $ref_fournisseur = (GETPOSTISSET('fourn_ref') ? GETPOST('fourn_ref', 'restricthtml') : '');
451 } else {
452 $idprod = GETPOSTINT('idprod');
453 $tva_tx = '';
454 }
455
456 $qty = price2num(GETPOST('qty' . $predef, 'alpha'), 'MS', 2);
457 $remise_percent = price2num(GETPOST('remise_percent' . $predef), '', 2);
458
459 // Extrafields
460 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
461 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
462 // Unset extrafield
463 if (is_array($extralabelsline)) {
464 // Get extra fields
465 foreach ($extralabelsline as $key => $value) {
466 unset($_POST["options_" . $key . $predef]);
467 }
468 }
469
470 if ((empty($idprod) || $idprod < 0) && ($price_ht < 0) && ($qty < 0)) {
471 setEventMessages($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPriceHT'), $langs->transnoentitiesnoconv('Qty')), null, 'errors');
472 $error++;
473 }
474 if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && GETPOST('type') < 0) {
475 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), null, 'errors');
476 $error++;
477 }
478 if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && (! ($price_ht >= 0) || $price_ht == '')) { // Unit price can be 0 but not ''
479 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPriceHT")), null, 'errors');
480 $error++;
481 }
482 if ($qty == '') {
483 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
484 $error++;
485 }
486 if ($prod_entry_mode == 'free' && (empty($idprod) || $idprod < 0) && empty($product_desc)) {
487 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), null, 'errors');
488 $error++;
489 }
490 if ($qty < 0) {
491 $langs->load("errors");
492 setEventMessages($langs->trans('ErrorQtyForSupplierInvoiceCantBeNegative'), null, 'errors');
493 $error++;
494 }
495
496 if ($prod_entry_mode != 'free' && empty($error)) { // With combolist mode idprodfournprice is > 0 or -1. With autocomplete, idprodfournprice is > 0 or ''
497 $productsupplier = new ProductFournisseur($db);
498
499 $idprod = 0;
500 if (GETPOST('idprodfournprice', 'alpha') == -1 || GETPOST('idprodfournprice', 'alpha') == '') {
501 $idprod = -99; // Same behaviour than with combolist. When not select idprodfournprice is now -99 (to avoid conflict with next action that may return -1, -2, ...)
502 }
503 $reg = array();
504 if (preg_match('/^idprod_([0-9]+)$/', GETPOST('idprodfournprice', 'alpha'), $reg)) {
505 $idprod = (int) $reg[1];
506 $res = $productsupplier->fetch($idprod); // Load product from its id
507 // Call to init some price properties of $productsupplier
508 // So if a supplier price already exists for another thirdparty (first one found), we use it as reference price
509 if (getDolGlobalString('SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER')) {
510 $fksoctosearch = 0;
511 $productsupplier->get_buyprice(0, -1, $idprod, 'none', $fksoctosearch); // We force qty to -1 to be sure to find if a supplier price exist
512 if ($productsupplier->fourn_socid != $socid) { // The price we found is for another supplier, so we clear supplier price
513 $productsupplier->ref_supplier = '';
514 }
515 } else {
516 $fksoctosearch = $object->thirdparty->id;
517 $productsupplier->get_buyprice(0, -1, $idprod, 'none', $fksoctosearch); // We force qty to -1 to be sure to find if a supplier price exist
518 }
519 } elseif (GETPOST('idprodfournprice', 'alpha') > 0) {
520 $qtytosearch = $qty; // Just to see if a price exists for the quantity. Not used to found vat.
521 $idprod = $productsupplier->get_buyprice(GETPOST('idprodfournprice', 'alpha'), $qtytosearch);
522 $res = $productsupplier->fetch($idprod);
523 $ref_fournisseur = $productsupplier->ref_supplier;
524 }
525 }
526
527 if (! $error && ($qty >= 0) && (!empty($product_desc) || (!empty($idprod) && $idprod > 0))) {
528 $ret = $object->fetch($id);
529 if ($ret < 0) {
530 dol_print_error($db, $object->error);
531 exit();
532 }
533 $ret = $object->fetch_thirdparty();
534
535 // Clean parameters
536 $date_start = dol_mktime(GETPOST('date_start' . $predef . 'hour'), GETPOST('date_start' . $predef . 'min'), GETPOST('date_start' . $predef . 'sec'), GETPOST('date_start' . $predef . 'month'), GETPOST('date_start' . $predef . 'day'), GETPOST('date_start' . $predef . 'year'));
537 $date_end = dol_mktime(GETPOST('date_end' . $predef . 'hour'), GETPOST('date_end' . $predef . 'min'), GETPOST('date_end' . $predef . 'sec'), GETPOST('date_end' . $predef . 'month'), GETPOST('date_end' . $predef . 'day'), GETPOST('date_end' . $predef . 'year'));
538 $price_base_type = (GETPOST('price_base_type', 'alpha') ? GETPOST('price_base_type', 'alpha') : 'HT');
539
540 // Define special_code for special lines
541 $special_code = 0;
542 // if (!GETPOST('qty')) $special_code=3; // Options should not exists on invoices
543
544 // Ecrase $pu par celui du produit
545 // Ecrase $desc par celui du produit
546 // Ecrase $tva_tx par celui du produit
547 // Ecrase $base_price_type par celui du produit
548 // Replaces $fk_unit with the product's
549 if (!empty($idprod) && $idprod > 0) {
550 $prod = new Product($db);
551 $prod->fetch($idprod);
552
553 $label = ((GETPOST('product_label') && GETPOST('product_label') != $prod->label) ? GETPOST('product_label') : '');
554
555 // Update if prices fields are defined
556 $tva_tx = get_default_tva($object->thirdparty, $mysoc, $prod->id);
557 $tva_npr = get_default_npr($object->thirdparty, $mysoc, $prod->id);
558 if (empty($tva_tx)) {
559 $tva_npr = 0;
560 }
561
562 // Search the correct price into loaded array product_price_by_qty using id of array retrieved into POST['pqp'].
563 $pqp = (GETPOSTINT('pbq') ? GETPOSTINT('pbq') : 0);
564
565 $datapriceofproduct = $prod->getSellPrice($object->thirdparty, $mysoc, $pqp);
566
567 $pu_ht = $datapriceofproduct['pu_ht'];
568 $pu_ttc = $datapriceofproduct['pu_ttc'];
569 $price_min = $datapriceofproduct['price_min'];
570 $price_base_type = empty($datapriceofproduct['price_base_type']) ? 'HT' : $datapriceofproduct['price_base_type'];
571 $tva_tx = $datapriceofproduct['tva_tx'];
572 $tva_npr = $datapriceofproduct['tva_npr'];
573
574 $tmpvat = price2num(preg_replace('/\s*\‍(.*\‍)/', '', (string) $tva_tx));
575 $tmpprodvat = price2num(preg_replace('/\s*\‍(.*\‍)/', '', (string) $prod->tva_tx));
576
577 // if price ht was forced (ie: from gui when calculated by margin rate and cost price). TODO Why this ?
578 if (!empty($price_ht)) {
579 $pu_ht = price2num($price_ht, 'MU');
580 $pu_ttc = price2num((float) $pu_ht * (1 + ((float) $tmpvat / 100)), 'MU');
581 } elseif ($tmpvat != $tmpprodvat) {
582 // On reevalue prix selon taux tva car taux tva transaction peut etre different
583 // de ceux du produit par default (par example si pays different entre vendeur et acheteur).
584 if ($price_base_type != 'HT') {
585 $pu_ht = price2num($pu_ttc / (1 + ((float) $tmpvat / 100)), 'MU');
586 } else {
587 $pu_ttc = price2num($pu_ht * (1 + ((float) $tmpvat / 100)), 'MU');
588 }
589 }
590
591 $desc = '';
592
593 // Define output language
594 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
595 $outputlangs = $langs;
596 $newlang = '';
597 if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
598 $newlang = GETPOST('lang_id', 'aZ09');
599 }
600 if (empty($newlang)) {
601 $newlang = $object->thirdparty->default_lang;
602 }
603 if (!empty($newlang)) {
604 $outputlangs = new Translate("", $conf);
605 $outputlangs->setDefaultLang($newlang);
606 }
607
608 $desc = (!empty($prod->multilangs [$outputlangs->defaultlang] ["description"])) ? $prod->multilangs [$outputlangs->defaultlang] ["description"] : $prod->description;
609 } else {
610 $desc = $prod->description;
611 }
612
613 $desc = dol_concatdesc($desc, $product_desc);
614
615 // Add custom code and origin country into description
616 if (!getDolGlobalString('MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE') && (!empty($prod->customcode) || !empty($prod->country_code))) {
617 $tmptxt = '(';
618 // Define output language
619 if (getDolGlobalInt('MAIN_MULTILANGS') && getDolGlobalString('PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE')) {
620 $outputlangs = $langs;
621 $newlang = '';
622 if (empty($newlang) && GETPOST('lang_id', 'alpha')) {
623 $newlang = GETPOST('lang_id', 'alpha');
624 }
625 if (empty($newlang)) {
626 $newlang = $object->thirdparty->default_lang;
627 }
628 if (!empty($newlang)) {
629 $outputlangs = new Translate("", $conf);
630 $outputlangs->setDefaultLang($newlang);
631 $outputlangs->load('products');
632 }
633 if (!empty($prod->customcode)) {
634 $tmptxt .= $outputlangs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode;
635 }
636 if (!empty($prod->customcode) && !empty($prod->country_code)) {
637 $tmptxt .= ' - ';
638 }
639 if (!empty($prod->country_code)) {
640 $tmptxt .= $outputlangs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, '', $db, $outputlangs, 0);
641 }
642 } else {
643 if (!empty($prod->customcode)) {
644 $tmptxt .= $langs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode;
645 }
646 if (!empty($prod->customcode) && !empty($prod->country_code)) {
647 $tmptxt .= ' - ';
648 }
649 if (!empty($prod->country_code)) {
650 $tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, '', $db, $langs, 0);
651 }
652 }
653 $tmptxt .= ')';
654 $desc = dol_concatdesc($desc, $tmptxt);
655 }
656
657 $type = $prod->type;
658 $fk_unit = $prod->fk_unit;
659 } else {
660 $pu_ht = price2num($price_ht, 'MU');
661 $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
662 $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
663 $tva_tx = str_replace('*', '', $tva_tx);
664 if (empty($tva_tx)) {
665 $tva_npr = 0;
666 }
667 $desc = $product_desc;
668 $type = GETPOST('type');
669 $fk_unit = GETPOST('units', 'alpha');
670 }
671
672 $date_start_fill = !empty(GETPOSTINT('date_start_fill')) ? GETPOSTINT('date_start_fill') : null;
673 $date_end_fill = !empty(GETPOSTINT('date_end_fill')) ? GETPOSTINT('date_end_fill') : null;
674
675 // Margin
676 $fournprice = price2num(GETPOST('fournprice' . $predef) ? GETPOST('fournprice' . $predef) : '');
677 $buyingprice = price2num(GETPOST('buying_price' . $predef) != '' ? GETPOST('buying_price' . $predef) : ''); // If buying_price is '0', we must keep this value
678
679 // Local Taxes
680 $localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $object->thirdparty, $tva_npr);
681 $localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $object->thirdparty, $tva_npr);
682 $info_bits = 0;
683 if ($tva_npr) {
684 $info_bits |= 0x01;
685 }
686
687 //To set vars in float type to avoid non-numeric warnings
688 $pu_ht = (float) price2num($pu_ht);
689 $remise_percent = (float) price2num($remise_percent);
690
691 $price_min = (float) price2num($price_min);
692 if ($usercanproductignorepricemin && (!empty($price_min) && ($pu_ht * (1 - $remise_percent / 100) < $price_min))) {
693 $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency));
694 setEventMessages($mesg, null, 'errors');
695 } else {
696 // Insert line
697 $result = $object->addline($idprod, $ref_fournisseur, $label, $desc, $pu_ht, $pu_ttc, $qty, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, $price_base_type, $type, $date_start_fill, $date_end_fill, $info_bits, $special_code, -1, $fk_unit);
698
699 if ($result > 0) {
700 $object->fetch($object->id); // Reload lines
701
702 unset($_POST['prod_entry_mode']);
703 unset($_POST['qty']);
704 unset($_POST['type']);
705 unset($_POST['remise_percent']);
706 unset($_POST['price_ht']);
707 unset($_POST['multicurrency_price_ht']);
708 unset($_POST['price_ttc']);
709 unset($_POST['tva_tx']);
710 unset($_POST['product_ref']);
711 unset($_POST['product_label']);
712 unset($_POST['product_desc']);
713 unset($_POST['fournprice']);
714 unset($_POST['buying_price']);
715 unset($_POST['np_marginRate']);
716 unset($_POST['np_markRate']);
717 unset($_POST['dp_desc']);
718 unset($_POST['idprod']);
719 unset($_POST['units']);
720 unset($_POST['date_starthour']);
721 unset($_POST['date_startmin']);
722 unset($_POST['date_startsec']);
723 unset($_POST['date_startday']);
724 unset($_POST['date_startmonth']);
725 unset($_POST['date_startyear']);
726 unset($_POST['date_endhour']);
727 unset($_POST['date_endmin']);
728 unset($_POST['date_endsec']);
729 unset($_POST['date_endday']);
730 unset($_POST['date_endmonth']);
731 unset($_POST['date_endyear']);
732 unset($_POST['date_start_fill']);
733 unset($_POST['date_end_fill']);
734 unset($_POST['situations']);
735 unset($_POST['progress']);
736 unset($_POST['fourn_ref']);
737 } else {
738 setEventMessages($object->error, $object->errors, 'errors');
739 }
740
741 $action = '';
742 }
743 }
744 } elseif ($action == 'updateline' && $permissiontoadd && ! GETPOST('cancel', 'alpha')) {
745 if (! $object->fetch($id) > 0) {
746 dol_print_error($db);
747 }
748 $object->fetch_thirdparty();
749
750 // Clean parameters
751 $date_start = '';
752 $date_end = '';
753 $description = dol_htmlcleanlastbr(GETPOST('product_desc', 'restricthtml') ? GETPOST('product_desc', 'restricthtml') : GETPOST('desc', 'restricthtml'));
754 $ref_fourn = GETPOST('fourn_ref', 'alpha');
755 $pu_ht = price2num(GETPOST('price_ht'), '', 2);
756 $vat_rate = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
757 $qty = GETPOST('qty');
758 $pu_ht_devise = price2num(GETPOST('multicurrency_subprice'), '', 2);
759
760 // Define info_bits
761 $info_bits = 0;
762 if (preg_match('/\*/', $vat_rate)) {
763 $info_bits |= 0x01;
764 }
765
766 // Define vat_rate
767 $vat_rate = str_replace('*', '', $vat_rate);
768 $localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty);
769 $localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty);
770
771 // Extrafields
772 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
773 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
774
775 $objectline = new FactureFournisseurLigneRec($db);
776 if ($objectline->fetch(GETPOSTINT('lineid'))) {
777 $objectline->array_options = $array_options;
778 $result = $objectline->insertExtraFields();
779 if ($result < 0) {
780 setEventMessages($langs->trans('Error') . $result, null, 'errors');
781 }
782 }
783
784 $position = ($objectline->rang >= 0 ? $objectline->rang : 0);
785
786 // Unset extrafield
787 if (is_array($extralabelsline)) {
788 // Get extra fields
789 foreach ($extralabelsline as $key => $value) {
790 unset($_POST["options_" . $key]);
791 }
792 }
793
794 // Define special_code for special lines
795 $special_code = GETPOSTINT('special_code');
796 if (! GETPOST('qty', 'alpha')) {
797 $special_code = 3;
798 }
799
800 $remise_percent = price2num(GETPOST('remise_percent'), '', 2) ?: 0;
801
802 // Check minimum price
803 $productid = GETPOSTINT('productid');
804 if (!empty($productid)) {
805 $product = new Product($db);
806 $product->fetch($productid);
807
808 $type = $product->type;
809
810 $price_min = $product->price_min;
811 if (getDolGlobalString('PRODUIT_MULTIPRICES') && !empty($object->thirdparty->price_level)) {
812 $price_min = $product->multiprices_min[$object->thirdparty->price_level];
813 }
814
815 $label = $product->label;
816
817 // Check price is not lower than minimum (check is done only for standard or replacement invoices)
818 if (((getDolGlobalString('MAIN_USE_ADVANCED_PERMS') && !$user->hasRight("produit", "ignore_price_min_advance")) || !getDolGlobalString('MAIN_USE_ADVANCED_PERMS')) && $price_min && ((float) price2num($pu_ht) * (1 - (float) $remise_percent / 100) < (float) price2num($price_min))) {
819 setEventMessages($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, -1, $conf->currency)), null, 'errors');
820 $error++;
821 }
822 } else {
823 $type = GETPOSTINT('type');
824 $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
825
826 // Check parameters
827 if (GETPOSTINT('type') < 0) {
828 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
829 $error++;
830 }
831 }
832 if ($qty < 0) {
833 $langs->load("errors");
834 setEventMessages($langs->trans('ErrorQtyForSupplierInvoiceCantBeNegative'), null, 'errors');
835 $error++;
836 }
837
838 $date_start_fill = !empty(GETPOSTINT('date_start_fill')) ? GETPOSTINT('date_start_fill') : 'NULL';
839 $date_end_fill = !empty(GETPOSTINT('date_end_fill')) ? GETPOSTINT('date_end_fill') : 'NULL';
840
841 // Update line
842 if (! $error) {
843 $result = $object->updateline(GETPOSTINT('lineid'), GETPOSTINT('productid'), $ref_fourn, $label, $description, $pu_ht, $qty, $remise_percent, $vat_rate, $localtax1_rate, $localtax1_rate, 'HT', $type, $date_start_fill, $date_end_fill, $info_bits, $special_code, -1);
844 if ($result >= 0) {
845 $object->fetch($object->id); // Reload lines
846
847 unset($_POST['qty']);
848 unset($_POST['type']);
849 unset($_POST['productid']);
850 unset($_POST['remise_percent']);
851 unset($_POST['price_ht']);
852 unset($_POST['multicurrency_price_ht']);
853 unset($_POST['price_ttc']);
854 unset($_POST['tva_tx']);
855 unset($_POST['product_ref']);
856 unset($_POST['product_label']);
857 unset($_POST['product_desc']);
858 unset($_POST['fournprice']);
859 unset($_POST['buying_price']);
860 unset($_POST['np_marginRate']);
861 unset($_POST['np_markRate']);
862 unset($_POST['dp_desc']);
863 unset($_POST['idprod']);
864 unset($_POST['units']);
865 unset($_POST['date_starthour']);
866 unset($_POST['date_startmin']);
867 unset($_POST['date_startsec']);
868 unset($_POST['date_startday']);
869 unset($_POST['date_startmonth']);
870 unset($_POST['date_startyear']);
871 unset($_POST['date_endhour']);
872 unset($_POST['date_endmin']);
873 unset($_POST['date_endsec']);
874 unset($_POST['date_endday']);
875 unset($_POST['date_endmonth']);
876 unset($_POST['date_endyear']);
877 unset($_POST['situations']);
878 unset($_POST['progress']);
879 unset($_POST['fourn_ref']);
880 } else {
881 setEventMessages($object->error, $object->errors, 'errors');
882 }
883 }
884 }
885}
886
887
888/*
889 * View
890 */
891
892$help_url = '';
893llxHeader('', $langs->trans("RepeatableSupplierInvoice"), $help_url, '', 0, 0, '', '', '', 'mod-fourn-facture page-card-rec');
894
895$form = new Form($db);
896$formother = new FormOther($db);
897if (isModEnabled('project')) {
898 $formproject = new FormProjets($db);
899}
900$companystatic = new Societe($db);
901$invoicerectmp = new FactureFournisseurRec($db);
902
903$now = dol_now();
904$nowlasthour = dol_get_last_hour($now);
905
906// Create mode
907
908if ($action == 'create') {
909 print load_fiche_titre($langs->trans("CreateRepeatableInvoice"), '', 'bill');
910
911 $object = new FactureFournisseur($db); // Source invoice
912 $product_static = new Product($db);
913
914 if ($object->fetch($id) > 0) {
915 $result = $object->fetch_lines();
916
917 print '<form action="' . $_SERVER["PHP_SELF"] . '" method="POST">';
918 print '<input type="hidden" name="token" value="' . newToken() . '">';
919 print '<input type="hidden" name="action" value="add">';
920 print '<input type="hidden" name="facid" value="' . $object->id . '">';
921
922 print dol_get_fiche_head([], '', '', 0);
923
924 $rowspan = 4;
925 if (isModEnabled('project')) {
926 $rowspan++;
927 }
928 if ($object->fk_account > 0) {
929 $rowspan++;
930 }
931
932 print '<table class="border centpercent">';
933
934 $object->fetch_thirdparty();
935
936 // Title
937 print '<tr><td class="titlefieldcreate fieldrequired">' . $langs->trans("Title") . '</td><td>';
938 print '<input class="flat quatrevingtpercent" type="text" name="title" value="' . dol_escape_htmltag(GETPOST("title", 'alphanohtml')) . '" autofocus>';
939 print '</td></tr>';
940
941 // Ref supplier
942 print '<tr><td class="titlefieldcreate fieldrequired">' . $langs->trans("RefSupplier") . '</td><td>';
943 print '<input class="flat maxwidth500" type="text" name="ref_supplier" value="' . $object->ref_supplier . '">';
944 print '</td></tr>';
945
946 // Third party
947 print '<tr><td class="titlefieldcreate">' . $langs->trans("Supplier") . '</td><td>' . $object->thirdparty->getNomUrl(1, 'supplier') . '</td>';
948 print '</tr>';
949
950 // Invoice subtype
951 if (getDolGlobalInt('INVOICE_SUBTYPE_ENABLED')) {
952 print "<tr><td>".$langs->trans("InvoiceSubtype")."</td><td>";
953 print $form->getSelectInvoiceSubtype(GETPOSTISSET('subtype') ? GETPOST('subtype') : $object->subtype, 'subtype', 0, 0, '');
954 print "</td></tr>";
955 }
956
957 $note_public = GETPOSTISSET('note_public') ? GETPOST('note_public', 'restricthtml') : $object->note_public;
958 $note_private = GETPOSTISSET('note_private') ? GETPOST('note_private', 'restricthtml') : $object->note_private;
959
960 // Help for substitution key
961 $substitutionarray = getCommonSubstitutionArray($langs, 2, null, $object);
962
963 $substitutionarray['__INVOICE_PREVIOUS_MONTH__'] = $langs->trans("PreviousMonthOfInvoice") . ' (' . $langs->trans("Example") . ': ' . dol_print_date(dol_time_plus_duree($object->date, -1, 'm'), '%m') . ')';
964 $substitutionarray['__INVOICE_MONTH__'] = $langs->trans("MonthOfInvoice") . ' (' . $langs->trans("Example") . ': ' . dol_print_date($object->date, '%m') . ')';
965 $substitutionarray['__INVOICE_NEXT_MONTH__'] = $langs->trans("NextMonthOfInvoice") . ' (' . $langs->trans("Example") . ': ' . dol_print_date(dol_time_plus_duree($object->date, 1, 'm'), '%m') . ')';
966 $substitutionarray['__INVOICE_PREVIOUS_MONTH_TEXT__'] = $langs->trans("TextPreviousMonthOfInvoice") . ' (' . $langs->trans("Example") . ': ' . dol_print_date(dol_time_plus_duree($object->date, -1, 'm'), '%B') . ')';
967 $substitutionarray['__INVOICE_MONTH_TEXT__'] = $langs->trans("TextMonthOfInvoice") . ' (' . $langs->trans("Example") . ': ' . dol_print_date($object->date, '%B') . ')';
968 $substitutionarray['__INVOICE_NEXT_MONTH_TEXT__'] = $langs->trans("TextNextMonthOfInvoice") . ' (' . $langs->trans("Example") . ': ' . dol_print_date(dol_time_plus_duree($object->date, 1, 'm'), '%B') . ')';
969 $substitutionarray['__INVOICE_PREVIOUS_YEAR__'] = $langs->trans("PreviousYearOfInvoice") . ' (' . $langs->trans("Example") . ': ' . dol_print_date(dol_time_plus_duree($object->date, -1, 'y'), '%Y') . ')';
970 $substitutionarray['__INVOICE_YEAR__'] = $langs->trans("YearOfInvoice") . ' (' . $langs->trans("Example") . ': ' . dol_print_date($object->date, '%Y') . ')';
971 $substitutionarray['__INVOICE_NEXT_YEAR__'] = $langs->trans("NextYearOfInvoice") . ' (' . $langs->trans("Example") . ': ' . dol_print_date(dol_time_plus_duree($object->date, 1, 'y'), '%Y') . ')';
972 // Only on template invoices
973 $substitutionarray['__INVOICE_DATE_NEXT_INVOICE_BEFORE_GEN__'] = $langs->trans("DateNextInvoiceBeforeGen") . (isset($object->date_when) ? ' (' . $langs->trans("Example") . ': ' .dol_print_date($object->date_when, 'dayhour') . ')' : '');
974 $substitutionarray['__INVOICE_DATE_NEXT_INVOICE_AFTER_GEN__'] = $langs->trans("DateNextInvoiceAfterGen") . (isset($object->date_when) ? ' (' . $langs->trans("Example") . ': ' . dol_print_date(dol_time_plus_duree($object->date_when, $object->frequency, $object->unit_frequency), 'dayhour') . ')' : '');
975 $substitutionarray['__INVOICE_COUNTER_CURRENT__'] = $langs->trans("Count");
976 $substitutionarray['__INVOICE_COUNTER_MAX__'] = $langs->trans("MaxPeriodNumber");
977
978 $htmltext = '<i>' . $langs->trans("FollowingConstantsWillBeSubstituted") . ':<br>';
979 foreach ($substitutionarray as $key => $val) {
980 $htmltext .= $key . ' = ' . $langs->trans($val) . '<br>';
981 }
982 $htmltext .= '</i>';
983
984 // Label
985 print '<tr><td class="titlefieldcreate">' . $langs->trans("Label") . '</td><td>';
986 print '<input class="flat quatrevingtpercent" type="text" name="libelle" value="' . $object->label . '">';
987 print '</td></tr>';
988
989 // Author
990 print "<tr><td>" . $langs->trans("Author") . "</td><td>" . $user->getFullName($langs) . "</td></tr>";
991
992 // Payment term
993 print "<tr><td>" . $langs->trans("PaymentConditions") . "</td><td>";
994 print $form->getSelectConditionsPaiements(GETPOSTISSET('cond_reglement_id') ? GETPOST('cond_reglement_id', 'int') : $object->cond_reglement_id, 'cond_reglement_id', -1, 0, 0, '');
995 print "</td></tr>";
996
997 // Payment mode
998 print "<tr><td>" . $langs->trans("PaymentMode") . "</td><td>";
999 print img_picto('', 'payment', 'class="pictofixedwidth"');
1000 print $form->select_types_paiements(GETPOSTISSET('mode_reglement_id') ? GETPOST('mode_reglement_id', 'int') : $object->mode_reglement_id, 'mode_reglement_id', '', 0, 1, 0, 0, 1, '', 1);
1001 print "</td></tr>";
1002
1003 // Project
1004 if (isModEnabled('project') && is_object($object->thirdparty) && $object->thirdparty->id > 0) {
1005 $projectid = GETPOST('projectid') ? GETPOST('projectid') : $object->fk_project;
1006 $langs->load('projects');
1007 print '<tr><td>' . $langs->trans('Project') . '</td><td>';
1008 $numprojet = $formproject->select_projects($object->thirdparty->id, $projectid, 'projectid', 0, 0, 1, 0, 0, 0, 0, '', 0, 0, '');
1009 print ' &nbsp; <a href="' . DOL_URL_ROOT . '/projet/card.php?socid=' . $object->thirdparty->id . '&action=create&status=1&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?action=create&socid=' . $object->thirdparty->id . (!empty($id) ? '&id=' . $id : '')) . '">' . $langs->trans("AddProject") . '</a>';
1010 print '</td></tr>';
1011 }
1012
1013 // Bank account
1014 if ($object->fk_account > 0) {
1015 print "<tr><td>" . $langs->trans('BankAccount') . "</td><td>";
1016 $form->formSelectAccount($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->fk_account, 'none');
1017 print "</td></tr>";
1018 }
1019
1020 //extrafields
1021 $draft = new FactureFournisseur($db);
1022 $draft->fetch(GETPOST('facid', 'int'));
1023
1024 $extralabels = new ExtraFields($db);
1025 $extralabels = $extrafields->fetch_name_optionals_label($draft->table_element);
1026 if ($draft->fetch_optionals() > 0) {
1027 $object->array_options = array_merge($object->array_options, $draft->array_options);
1028 }
1029
1030 print $object->showOptionals($extrafields, 'create', $parameters);
1031
1032 // Model pdf
1033 print "<tr><td>" . $langs->trans('Model') . "</td><td>";
1034 include_once DOL_DOCUMENT_ROOT . '/core/modules/supplier_invoice/modules_facturefournisseur.php';
1036 print $form->selectarray('modelpdf', $list, $conf->global->INVOICE_SUPPLIER_ADDON_PDF);
1037 print "</td></tr>";
1038
1039 // Public note
1040 print '<tr>';
1041 print '<td class="tdtop">';
1042 print $form->textwithpicto($langs->trans('NotePublic'), $htmltext, 1, 'help', '', 0, 2, 'notepublic');
1043 print '</td>';
1044 print '<td>';
1045 $doleditor = new DolEditor('note_public', $note_public, '', 80, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PUBLIC') ? 0 : 1, ROWS_3, '90%');
1046 print $doleditor->Create(1);
1047
1048 // Private note
1049 if (empty($user->socid)) {
1050 print '<tr>';
1051 print '<td class="tdtop">';
1052 print $form->textwithpicto($langs->trans('NotePrivate'), $htmltext, 1, 'help', '', 0, 2, 'noteprivate');
1053 print '</td>';
1054 print '<td>';
1055 $doleditor = new DolEditor('note_private', $note_private, '', 80, 'dolibarr_notes', 'In', false, false, !getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE') ? 0 : 1, ROWS_3, '90%');
1056 print $doleditor->Create(1);
1057 print '</td></tr>';
1058 }
1059
1060 print "</table>";
1061
1062 print dol_get_fiche_end();
1063
1064 // Autogeneration
1065 $title = $langs->trans("Recurrence");
1066 print load_fiche_titre(img_picto('', 'recurring', 'class="pictofixedwidth"') . $title, '', '');
1067
1068 print '<span class="opacitymedium">'.$langs->trans("ToCreateARecurringInvoiceGeneAuto", $langs->transnoentitiesnoconv('Module2300Name')).'</span><br><br>';
1069
1070 print dol_get_fiche_head([], '', '', 0);
1071
1072 print '<table class="border centpercent">';
1073
1074 // Frequency + unit
1075 print '<tr><td class="titlefieldcreate">' . $form->textwithpicto($langs->trans("Frequency"), $langs->transnoentitiesnoconv('toolTipFrequency')) . "</td><td>";
1076 print "<input type='text' name='frequency' value='" . GETPOSTINT('frequency') . "' size='4' />&nbsp;" . $form->selectarray('unit_frequency', array('d' => $langs->trans('Day'), 'm' => $langs->trans('Month'), 'y' => $langs->trans('Year')), (GETPOST('unit_frequency') ? GETPOST('unit_frequency') : 'm'));
1077 print "</td></tr>";
1078
1079 // Date next run
1080 print "<tr><td>" . $langs->trans('NextDateToExecution') . "</td><td>";
1081 $date_next_execution = isset($date_next_execution) ? $date_next_execution : (GETPOST('remonth') ? dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')) : -1);
1082 print $form->selectDate($date_next_execution, '', 1, 1, 0, "add", 1, 1);
1083 print "</td></tr>";
1084
1085 // Number max of generation
1086 print "<tr><td>" . $langs->trans("MaxPeriodNumber") . "</td><td>";
1087 print '<input type="text" name="nb_gen_max" value="' . GETPOST('nb_gen_max') . '" size="5" />';
1088 print "</td></tr>";
1089
1090 // Auto validate the invoice
1091 print "<tr><td>" . $langs->trans("StatusOfAutoGeneratedInvoices") . "</td><td>";
1092 $select = array('0' => $langs->trans('BillStatusDraft'), '1' => $langs->trans('BillStatusValidated'));
1093 print $form->selectarray('auto_validate', $select, GETPOST('auto_validate'));
1094 print "</td></tr>";
1095
1096 // Auto generate document
1097 if (getDolGlobalString('INVOICE_REC_CAN_DISABLE_DOCUMENT_FILE_GENERATION')) {
1098 print "<tr><td>" . $langs->trans("StatusOfGeneratedDocuments") . "</td><td>";
1099 $select = array('0' => $langs->trans('DoNotGenerateDoc'), '1' => $langs->trans('AutoGenerateDoc'));
1100 print $form->selectarray('generate_pdf', $select, GETPOST('generate_pdf'));
1101 print "</td></tr>";
1102 } else {
1103 print '<input type="hidden" name="generate_pdf" value="1">';
1104 }
1105
1106 print "</table>";
1107
1108 print dol_get_fiche_end();
1109
1110 $title = $langs->trans("ProductsAndServices");
1111 if (!isModEnabled("service")) {
1112 $title = $langs->trans("Products");
1113 } elseif (!isModEnabled("product")) {
1114 $title = $langs->trans("Services");
1115 }
1116
1117 print load_fiche_titre($title, '', '');
1118
1119 /*
1120 * Invoice lines
1121 */
1122 print '<div class="div-table-responsive-no-min">';
1123 print '<table id="tablelines" class="noborder noshadow" width="100%">';
1124 // Show object lines
1125 if (!empty($object->lines)) {
1126 $disableedit = 1;
1127 $disablemove = 1;
1128 $disableremove = 1;
1129 $object->printObjectLines('', $object->thirdparty, $mysoc, $lineid, 0); // No date selector for template invoice
1130 }
1131
1132 print "</table>\n";
1133 print '<div>';
1134 print '</td></tr>';
1135 print "</table>\n";
1136
1137 print $form->buttonsSaveCancel("Create");
1138
1139 print "</form>\n";
1140 } else {
1141 dol_print_error(null, "Error, no invoice " . $object->id);
1142 }
1143} else {
1144 // View mode
1145 if ($object->id > 0) {
1146 $object->fetch($object->id);
1147 $object->fetch_thirdparty();
1148
1149 $formconfirm = '';
1150
1151 // Confirmation de la suppression d'une ligne produit
1152 if ($action == 'ask_deleteline') {
1153 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id . '&lineid=' . $lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 'no', 1);
1154 }
1155
1156 // Confirm delete of repeatable invoice
1157 if ($action == 'ask_deleteinvoice') {
1158 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id, $langs->trans('DeleteRepeatableInvoice'), $langs->trans('ConfirmDeleteRepeatableInvoice'), 'confirm_deleteinvoice', '', 'no', 1);
1159 }
1160
1161 print $formconfirm;
1162
1163 $author = new User($db);
1164 $author->fetch($object->user_author);
1165
1166 $head = supplier_invoice_rec_prepare_head($object);
1167
1168 print dol_get_fiche_head($head, 'card', $langs->trans('RepeatableInvoice'), -1, 'bill'); // Add a div
1169
1170 // Recurring invoice content
1171
1172 $linkback = '<a href="' . DOL_URL_ROOT . '/fourn/facture/list-rec.php?restore_lastsearch_values=1' . (!empty($socid) ? '&socid=' . $socid : '') . '">' . $langs->trans('BackToList') . '</a>';
1173
1174 $morehtmlref = '';
1175 if ($action != 'edittitle') {
1176 $morehtmlref .= $form->editfieldkey($object->title, 'title', $object->title, $object, $usercancreate, '', '', 0, 2);
1177 } else {
1178 $morehtmlref .= $form->editfieldval('', 'title', $object->title, $object, $usercancreate, 'string');
1179 }
1180 $morehtmlref .= '<div class="refidno">';
1181 //Ref supplier
1182 $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $usercancreate, 'string', '', 0, 1);
1183 $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $usercancreate, 'string', '', null, null, '', 1);
1184 // Thirdparty
1185 $morehtmlref .= '<br>' . $langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
1186
1187 // Project
1188 if (isModEnabled('project')) {
1189 $langs->load('projects');
1190 $morehtmlref .= '<br>' . $langs->trans('Project') . ' ';
1191 if ($usercancreate) {
1192 if ($action != 'classify') {
1193 $morehtmlref .= '<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token=' . newToken() . '&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
1194 }
1195 if ($action == 'classify') {
1196 $morehtmlref .= '<form method="post" action="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '">';
1197 $morehtmlref .= '<input type="hidden" name="action" value="classin">';
1198 $morehtmlref .= '<input type="hidden" name="token" value="' . newToken() . '">';
1199 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
1200 $morehtmlref .= '<input type="submit" class="button valignmiddle" value="' . $langs->trans("Modify") . '">';
1201 $morehtmlref .= '</form>';
1202 } else {
1203 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1, '', 'maxwidth300');
1204 }
1205 } else {
1206 if (!empty($object->fk_project)) {
1207 $project = new Project($db);
1208 $project->fetch($object->fk_project);
1209 $morehtmlref .= ' : ' . $project->getNomUrl(1);
1210 if ($project->title) {
1211 $morehtmlref .= ' - ' . $project->title;
1212 }
1213 } else {
1214 $morehtmlref .= '';
1215 }
1216 }
1217 }
1218 $morehtmlref .= '</div>';
1219
1220 $morehtmlstatus = '';
1221
1222 dol_banner_tab($object, 'ref', $linkback, 1, 'title', 'none', $morehtmlref, '', 0, '', $morehtmlstatus);
1223
1224 print '<div class="fichecenter">';
1225 print '<div class="fichehalfleft">';
1226 print '<div class="underbanner clearboth"></div>';
1227
1228 print '<table class="border centpercent tableforfield">';
1229
1230 // Invoice subtype
1231 if (getDolGlobalInt('INVOICE_SUBTYPE_ENABLED')) {
1232 print "<tr><td>".$langs->trans("InvoiceSubtype")."</td><td>";
1233 print $object->getSubtypeLabel('facture_fourn_rec');
1234 print "</td></tr>";
1235 }
1236
1237 print '<tr><td class="titlefield">' . $langs->trans('Author') . '</td><td>';
1238 print $author->getNomUrl(-1);
1239 print "</td></tr>";
1240
1241 // Label
1242 print '<tr>';
1243 print '<td>' . $form->editfieldkey("Label", 'libelle', $object->libelle, $object, $usercancreate) . '</td>';
1244 print '<td>' . $form->editfieldval("Label", 'libelle', $object->libelle, $object, $usercancreate) . '</td>';
1245 print '</tr>';
1246
1247 print '<tr><td>' . $langs->trans('AmountHT') . '</td>';
1248 print '<td>' . price($object->total_ht, 0, $langs, 1, -1, -1, $conf->currency) . '</td>';
1249 print '</tr>';
1250
1251 print '<tr><td>' . $langs->trans("AmountVAT") . '</td><td>' . price($object->total_tva, 0, $langs, 1, -1, -1, $conf->currency) . '</td>';
1252 print '</tr>';
1253
1254 // Amount Local Taxes
1255 if (($mysoc->localtax1_assuj == "1" && $mysoc->useLocalTax(1)) || $object->total_localtax1 != 0) { // Localtax1
1256 print '<tr><td>' . $langs->transcountry("AmountLT1", $mysoc->country_code) . '</td>';
1257 print '<td class="nowrap">' . price($object->total_localtax1, 1, '', 1, -1, -1, $conf->currency) . '</td></tr>';
1258 }
1259 if (($mysoc->localtax2_assuj == "1" && $mysoc->useLocalTax(2)) || $object->total_localtax2 != 0) { // Localtax2
1260 print '<tr><td>' . $langs->transcountry("AmountLT2", $mysoc->country_code) . '</td>';
1261 print '<td class=nowrap">' . price($object->total_localtax2, 1, '', 1, -1, -1, $conf->currency) . '</td></tr>';
1262 }
1263
1264 print '<tr><td>' . $langs->trans("AmountTTC") . '</td><td colspan="3">' . price($object->total_ttc, 0, $langs, 1, -1, -1, $conf->currency) . '</td>';
1265 print '</tr>';
1266
1267 // Payment term
1268 print '<tr><td>';
1269 print '<table class="nobordernopadding centpercent"><tr><td>';
1270 print $langs->trans('PaymentConditionsShort');
1271 print '</td>';
1272 if ($action != 'editconditions' && $usercancreate) {
1273 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>';
1274 }
1275 print '</tr></table>';
1276 print '</td><td>';
1277 if ($action == 'editconditions') {
1278 $form->form_conditions_reglement($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $object->cond_reglement_id, 'cond_reglement_id');
1279 } else {
1280 $form->form_conditions_reglement($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $object->cond_reglement_id, 'none');
1281 }
1282
1283 print '</td></tr>';
1284
1285 // Payment mode
1286 print '<tr><td>';
1287 print '<table class="nobordernopadding" width="100%"><tr><td>';
1288 print $langs->trans('PaymentMode');
1289 print '</td>';
1290 if ($action != 'editmode' && $usercancreate) {
1291 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>';
1292 }
1293 print '</tr></table>';
1294 print '</td><td>';
1295 if ($action == 'editmode') {
1296 $form->form_modes_reglement($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $object->mode_reglement_id, 'mode_reglement_id', 'CRDT', 1, 1);
1297 } else {
1298 $form->form_modes_reglement($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $object->mode_reglement_id, 'none');
1299 }
1300 print '</td></tr>';
1301
1302 // Bank Account
1303 print '<tr><td class="nowrap">';
1304 print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
1305 print $langs->trans('BankAccount');
1306 print '<td>';
1307 if ($action != 'editbankaccount' && $usercancreate && $object->statut == FactureFournisseurRec::STATUS_NOTSUSPENDED) {
1308 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>';
1309 }
1310 print '</tr></table>';
1311 print '</td><td>';
1312 if ($action == 'editbankaccount') {
1313 $form->formSelectAccount($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->fk_account, 'fk_account', 1);
1314 } else {
1315 $form->formSelectAccount($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->fk_account, 'none');
1316 }
1317 print "</td>";
1318 print '</tr>';
1319
1320 // Extrafields
1321 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1322
1323 // Model pdf
1324 print '<tr><td class="nowrap">';
1325 print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
1326 print $langs->trans('Model');
1327 print '<td>';
1328 if ($action != 'editmodelpdf' && $usercancreate && $object->statut == FactureFournisseurRec::STATUS_NOTSUSPENDED) {
1329 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>';
1330 }
1331 print '</tr></table>';
1332 print '</td><td>';
1333 if ($action == 'editmodelpdf') {
1334 include_once DOL_DOCUMENT_ROOT . '/core/modules/supplier_invoice/modules_facturefournisseur.php';
1335 $list = array();
1337 foreach ($models as $k => $model) {
1338 $list[] = str_replace(':', '|', $k) . ':' . $model;
1339 }
1340 $select = 'select;' . implode(',', $list);
1341 //TODO : Droits
1342 print $form->editfieldval($langs->trans('Model'), 'modelpdf', $object->model_pdf, $object, $usercancreate, $select);
1343 } else {
1344 print $object->model_pdf;
1345 }
1346 print "</td>";
1347 print '</tr>';
1348
1349 // Other attributes
1350 $cols = 2;
1351
1352 print '</table>';
1353
1354 print '</div>';
1355 print '<div class="fichehalfright">';
1356 print '<div class="underbanner clearboth"></div>';
1357
1358 /*
1359 * Recurrence
1360 */
1361 $title = $langs->trans("Recurrence");
1362 //print load_fiche_titre($title, '', 'calendar');
1363
1364 print '<table class="border centpercent tableforfield">';
1365
1366 include DOL_DOCUMENT_ROOT.'/core/tpl/object_currency_amount.tpl.php';
1367
1368 print '<tr><td colspan="2">' . img_picto('', 'recurring', 'class="pictofixedwidth"') . $title . '</td></tr>';
1369
1370 // if "frequency" is empty or = 0, the recurrence is disabled
1371 print '<tr><td style="width: 50%">';
1372 print '<table class="nobordernopadding" width="100%"><tr><td>';
1373 print $langs->trans('Frequency');
1374 print '</td>';
1375 if ($action != 'editfrequency' && $usercancreate) {
1376 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>';
1377 }
1378 print '</tr></table>';
1379 print '</td><td>';
1380 if ($action == 'editfrequency') {
1381 print '<form method="post" action="' . $_SERVER["PHP_SELF"] . '?facid=' . $object->id . '">';
1382 print '<input type="hidden" name="action" value="setfrequency">';
1383 print '<input type="hidden" name="token" value="' . newToken() . '">';
1384 print '<table class="nobordernopadding">';
1385 print '<tr><td>';
1386 print "<input type='text' name='frequency' value='" . $object->frequency . "' size='5' />&nbsp;" . $form->selectarray('unit_frequency', array('d' => $langs->trans('Day'), 'm' => $langs->trans('Month'), 'y' => $langs->trans('Year')), ($object->unit_frequency ? $object->unit_frequency : 'm'));
1387 print '</td>';
1388 print '<td class="left"><input type="submit" class="button button-edit" value="' . $langs->trans("Modify") . '"></td>';
1389 print '</tr></table></form>';
1390 } else {
1391 if ($object->frequency > 0) {
1392 print $langs->trans('FrequencyPer_' . $object->unit_frequency, $object->frequency);
1393 } else {
1394 print $langs->trans("NotARecurringInvoiceTemplate");
1395 }
1396 }
1397 print '</td></tr>';
1398
1399 // Date when (next invoice generation)
1400 print '<tr><td>';
1401 if ($action == 'date_when' || $object->frequency > 0) {
1402 print $form->editfieldkey($langs->trans("NextDateToExecution"), 'date_when', $object->date_when, $object, $usercancreate, 'day');
1403 } else {
1404 print $langs->trans("NextDateToExecution");
1405 }
1406 print '</td><td>';
1407 if ($action == 'date_when' || $object->frequency > 0) {
1408 print $form->editfieldval($langs->trans("NextDateToExecution"), 'date_when', $object->date_when, $object, $usercancreate, 'day', $object->date_when, null, '', '', 0, 'strikeIfMaxNbGenReached');
1409 }
1410 //var_dump(dol_print_date($object->date_when+60, 'dayhour').' - '.dol_print_date($now, 'dayhour'));
1411 if (! $object->isMaxNbGenReached()) {
1412 if (! $object->suspended && $action != 'editdate_when' && $object->frequency > 0 && $object->date_when && $object->date_when < $now) {
1413 print img_warning($langs->trans("Late"));
1414 }
1415 } else {
1416 print img_info($langs->trans("MaxNumberOfGenerationReached"));
1417 }
1418 print '</td>';
1419 print '</tr>';
1420
1421 // Max period / Rest period
1422 print '<tr><td>';
1423 if ($action == 'nb_gen_max' || $object->frequency > 0) {
1424 print $form->editfieldkey($langs->trans("MaxPeriodNumber"), 'nb_gen_max', $object->nb_gen_max, $object, $usercancreate);
1425 } else {
1426 print $langs->trans("MaxPeriodNumber");
1427 }
1428 print '</td><td>';
1429 if ($action == 'nb_gen_max' || $object->frequency > 0) {
1430 print $form->editfieldval($langs->trans("MaxPeriodNumber"), 'nb_gen_max', $object->nb_gen_max ? $object->nb_gen_max : '', $object, $usercancreate);
1431 } else {
1432 print '';
1433 }
1434 print '</td>';
1435 print '</tr>';
1436
1437 // Status of generated invoices
1438 print '<tr><td>';
1439 if ($action == 'auto_validate' || $object->frequency > 0) {
1440 print $form->editfieldkey($langs->trans("StatusOfAutoGeneratedInvoices"), 'auto_validate', $object->auto_validate, $object, $usercancreate);
1441 } else {
1442 print $langs->trans("StatusOfAutoGeneratedInvoices");
1443 }
1444 print '</td><td>';
1445 $select = 'select;0:' . $langs->trans('BillStatusDraft') . ',1:' . $langs->trans('BillStatusValidated');
1446 if ($action == 'auto_validate' || $object->frequency > 0) {
1447 print $form->editfieldval($langs->trans("StatusOfAutoGeneratedInvoices"), 'auto_validate', $object->auto_validate, $object, $usercancreate, $select);
1448 }
1449 print '</td>';
1450 // Auto generate documents
1451 if (getDolGlobalString('INVOICE_REC_CAN_DISABLE_DOCUMENT_FILE_GENERATION')) {
1452 print '<tr>';
1453 print '<td>';
1454 if ($action == 'generate_pdf' || $object->frequency > 0) {
1455 print $form->editfieldkey($langs->trans("StatusOfGeneratedDocuments"), 'generate_pdf', $object->generate_pdf, $object, $usercancreate);
1456 } else {
1457 print $langs->trans("StatusOfGeneratedDocuments");
1458 }
1459 print '</td>';
1460 print '<td>';
1461 $select = 'select;0:' . $langs->trans('DoNotGenerateDoc') . ',1:' . $langs->trans('AutogenerateDoc');
1462 if ($action == 'generate_pdf' || $object->frequency > 0) {
1463 print $form->editfieldval($langs->trans("StatusOfGeneratedDocuments"), 'generate_pdf', $object->generate_pdf, $object, $usercancreate, $select);
1464 }
1465 print '</td>';
1466 print '</tr>';
1467 } else {
1468 print '<input type="hidden" name="generate_pdf" value="1">';
1469 }
1470
1471 print '</table>';
1472
1473 // Frequencry/Recurring section
1474 if ($object->frequency > 0) {
1475 print '<br>';
1476
1477 if (empty($conf->cron->enabled)) {
1478 print info_admin($langs->trans("EnableAndSetupModuleCron", $langs->transnoentitiesnoconv("Module2300Name")));
1479 }
1480
1481 print '<div class="underbanner clearboth"></div>';
1482 print '<table class="border centpercent tableforfield">';
1483
1484 // Nb of generation already done
1485 print '<tr><td style="width: 50%">' . $langs->trans("NbOfGenerationDone") . '</td>';
1486 print '<td>';
1487 print $object->nb_gen_done ? $object->nb_gen_done : '0';
1488 print '</td>';
1489 print '</tr>';
1490
1491 // Date last
1492 print '<tr><td>';
1493 print $langs->trans("DateLastGeneration");
1494 print '</td><td>';
1495 print dol_print_date($object->date_last_gen, 'dayhour');
1496 print '</td>';
1497 print '</tr>';
1498
1499 print '</table>';
1500
1501 print '<br>';
1502 }
1503
1504 print '</div>';
1505 print '</div>';
1506
1507 print '<div class="clearboth"></div><br>';
1508
1509 // Lines
1510 print ' <form name="addproduct" id="addproduct" action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . (($action != 'editline') ? '#add' : '#line_' . GETPOSTINT('lineid')) . '" method="POST">
1511 <input type="hidden" name="token" value="' . newToken() . '">
1512 <input type="hidden" name="action" value="' . (($action != 'editline') ? 'addline' : 'updateline') . '">
1513 <input type="hidden" name="mode" value="">
1514 <input type="hidden" name="id" value="' . $object->id . '">
1515 ';
1516
1517 if (!empty($conf->use_javascript_ajax) && $object->statut == 0) {
1518 include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php';
1519 }
1520
1521 print '<div class="div-table-responsive-no-min">';
1522 print '<table id="tablelines" class="noborder noshadow" width="100%">';
1523 $object->fetch_lines();
1524 // Show object lines
1525 if (!empty($object->lines)) {
1526 $canchangeproduct = 1;
1527 // To set ref for getNomURL function
1528 foreach ($object->lines as $line) {
1529 $line->ref = $line->label;
1530 $line->product_label = $line->label;
1531 $line->subprice = $line->pu_ht;
1532 }
1533
1534 global $canchangeproduct;
1535 $canchangeproduct = 0;
1536
1537 $object->statut = $object->suspended;
1538 $object->printObjectLines($action, $object->thirdparty, $mysoc, $lineid, 0); // No date selector for template invoice
1539 }
1540
1541 // Form to add new line
1542 //TODO : Droits
1543 if ($object->statut == $object::STATUS_DRAFT && $usercancreate && $action != 'valid' && $action != 'editline') {
1544 if ($action != 'editline') {
1545 // Add free products/services
1546
1547 $parameters = array();
1548 $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1549 if ($reshook < 0) {
1550 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
1551 }
1552 if (empty($reshook)) {
1553 global $senderissupplier;
1554 }
1555 $senderissupplier = 2;
1556 $object->formAddObjectLine(0, $object->thirdparty, $mysoc); // No date selector for template invoice
1557 }
1558 }
1559
1560 print "</table>\n";
1561 print '</div>';
1562
1563 print "</form>\n";
1564
1565 print dol_get_fiche_end();
1566
1567 /*
1568 * Action bar
1569 */
1570 print '<div class="tabsAction">';
1571
1572 if (empty($object->suspended)) {
1573 if ($usercancreate) {
1574 if (!empty($object->frequency) && $object->nb_gen_max > 0 && ($object->nb_gen_done >= $object->nb_gen_max)) {
1575 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag($langs->trans("MaxGenerationReached")) . '">' . $langs->trans("CreateBill") . '</a></div>';
1576 } else {
1577 if (empty($object->frequency) || $object->date_when <= $nowlasthour) {
1578 print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/fourn/facture/card.php?action=create&socid=' . $object->thirdparty->id . '&fac_rec=' . $object->id . '">' . $langs->trans("CreateBill") . '</a></div>';
1579 } else {
1580 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#" title="' . dol_escape_htmltag($langs->trans("DateIsNotEnough")) . '">' . $langs->trans("CreateBill") . '</a></div>';
1581 }
1582 }
1583 } else {
1584 print '<div class="inline-block divButAction"><a class="butActionRefused classfortooltip" href="#">' . $langs->trans("CreateBill") . '</a></div>';
1585 }
1586 }
1587
1588 if ($usercancreate) {
1589 if (empty($object->suspended)) {
1590 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>';
1591 } else {
1592 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>';
1593 }
1594 }
1595
1596 // Delete
1597 print dolGetButtonAction($langs->trans("Delete"), '', 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=ask_deleteinvoice&token='.newToken(), 'delete', ($user->hasRight("fournisseur", "facture", "supprimer") || $user->hasRight("supplier_invoice", "supprimer")));
1598
1599 print '</div>';
1600
1601 print '<div class="fichecenter"><div class="fichehalfleft">';
1602 print '<a name="builddoc"></a>'; // ancre
1603
1604 // Show links to link elements
1605 $tmparray = $form->showLinkToObjectBlock($object, array(), array('invoice'), 1);
1606 $linktoelem = $tmparray['linktoelem'];
1607 $htmltoenteralink = $tmparray['htmltoenteralink'];
1608 print $htmltoenteralink;
1609
1610 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
1611
1612 print '</div></div>';
1613 }
1614}
1615
1616// End of page
1617llxFooter();
1618$db->close();
$id
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:66
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
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:71
Class to manage a WYSIWYG editor.
Class to manage standard extra fields.
Class to manage suppliers invoices.
Class to manage supplier invoice lines of templates.
Class to manage invoice templates.
Class to manage generation of HTML components Only common components must be here.
Class permettant la generation de composants html autre 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 predefined suppliers products.
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.
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:646
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:125
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.
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...
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
dol_htmlcleanlastbr($stringtodecode)
This function remove all ending and br at end.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that returns whether VAT must be recoverable collected VAT (e.g.: VAT NPR in France)
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...
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_clone($object, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null, $include=null)
Return array of possible common substitutions.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='', $picto='')
Show information in HTML for admin users or standard users.
img_edit($titlealt='default', $float=0, $other='')
Show logo edit/modify fiche.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
img_info($titlealt='default')
Show info logo.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
supplier_invoice_rec_prepare_head($object)
Return array head with list of tabs to view object information.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.