dolibarr 18.0.6
card.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2020 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2004 Christophe Combelles <ccomb@free.fr>
5 * Copyright (C) 2005 Marc Barilley <marc@ocebo.fr>
6 * Copyright (C) 2005-2013 Regis Houssin <regis.houssin@inodbox.com>
7 * Copyright (C) 2010-2023 Juanjo Menent <jmenent@simnandez.es>
8 * Copyright (C) 2013-2022 Philippe Grand <philippe.grand@atoo-net.com>
9 * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
10 * Copyright (C) 2014-2016 Marcos García <marcosgdf@gmail.com>
11 * Copyright (C) 2016-2023 Alexandre Spangaro <aspangaro@open-dsi.fr>
12 * Copyright (C) 2018-2023 Frédéric France <frederic.france@netlogic.fr>
13 * Copyright (C) 2019 Ferran Marcet <fmarcet@2byte.es>
14 * Copyright (C) 2022 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <https://www.gnu.org/licenses/>.
28 */
29
36// Load Dolibarr environment
37require '../../main.inc.php';
38require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
39require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
40require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_invoice/modules_facturefournisseur.php';
41require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
42require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture-rec.class.php';
43require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
44require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
45require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
46require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
47require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
48require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
49if (isModEnabled("product")) {
50 require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
51 require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
52}
53if (isModEnabled('project')) {
54 require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
55 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
56}
57
58if (isModEnabled('variants')) {
59 require_once DOL_DOCUMENT_ROOT.'/variants/class/ProductCombination.class.php';
60}
61if (isModEnabled('accounting')) {
62 require_once DOL_DOCUMENT_ROOT.'/accountancy/class/accountingjournal.class.php';
63}
64
65
66$langs->loadLangs(array('bills', 'compta', 'suppliers', 'companies', 'products', 'banks', 'admin'));
67if (isModEnabled('incoterm')) {
68 $langs->load('incoterm');
69}
70
71$id = (GETPOST('facid', 'int') ? GETPOST('facid', 'int') : GETPOST('id', 'int'));
72
73$action = GETPOST('action', 'aZ09');
74$confirm = GETPOST("confirm");
75$ref = GETPOST('ref', 'alpha');
76$cancel = GETPOST('cancel', 'alpha');
77$backtopage = GETPOST('backtopage', 'alpha');
78$backtopageforcancel = '';
79
80$lineid = GETPOST('lineid', 'int');
81$projectid = GETPOST('projectid', 'int');
82$origin = GETPOST('origin', 'alpha');
83$originid = GETPOST('originid', 'int');
84$fac_recid = GETPOST('fac_rec', 'int');
85$rank = (GETPOST('rank', 'int') > 0) ? GETPOST('rank', 'int') : -1;
86
87// PDF
88$hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
89$hidedesc = (GETPOST('hidedesc', 'int') ? GETPOST('hidedesc', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
90$hideref = (GETPOST('hideref', 'int') ? GETPOST('hideref', 'int') : (!empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
91
92// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
93$hookmanager->initHooks(array('invoicesuppliercard', 'globalcard'));
94
95$object = new FactureFournisseur($db);
96$extrafields = new ExtraFields($db);
97
98// fetch optionals attributes and labels
99$extrafields->fetch_name_optionals_label($object->table_element);
100
101// Load object
102if ($id > 0 || !empty($ref)) {
103 $ret = $object->fetch($id, $ref);
104 if ($ret < 0) {
105 dol_print_error($db, $object->error);
106 }
107 $ret = $object->fetch_thirdparty();
108 if ($ret < 0) {
109 dol_print_error($db, $object->error);
110 }
111}
112
113// Security check
114$socid = GETPOST('socid', 'int');
115if (!empty($user->socid)) {
116 $socid = $user->socid;
117}
118
119$isdraft = (($object->statut == FactureFournisseur::STATUS_DRAFT) ? 1 : 0);
120$result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture', 'fk_soc', 'rowid', $isdraft);
121
122// Common permissions
123$usercanread = ($user->hasRight("fournisseur", "facture", "lire") || $user->hasRight("supplier_invoice", "lire"));
124$usercancreate = ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"));
125$usercandelete = ($user->hasRight("fournisseur", "facture", "supprimer") || $user->hasRight("supplier_invoice", "supprimer"));
126
127// Advanced permissions
128$usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($usercancreate)) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->hasRight("fournisseur", "supplier_invoice_advance", "validate")));
129$usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->hasRight("fournisseur", "supplier_invoice_advance", "send"));
130
131// Permissions for includes
132$permissionnote = $usercancreate; // Used by the include of actions_setnotes.inc.php
133$permissiondellink = $usercancreate; // Used by the include of actions_dellink.inc.php
134$permissiontoedit = $usercancreate; // Used by the include of actions_lineupdown.inc.php
135$permissiontoadd = $usercancreate; // Used by the include of actions_addupdatedelete.inc.php and actions_lineupdown.inc.php
136
137$error = 0;
138
139
140/*
141 * Actions
142 */
143
144$parameters = array('socid'=>$socid);
145$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
146if ($reshook < 0) {
147 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
148}
149
150if (empty($reshook)) {
151 $backurlforlist = DOL_URL_ROOT.'/fourn/facture/list.php';
152
153 if (empty($backtopage) || ($cancel && empty($id))) {
154 if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
155 if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
156 $backtopage = $backurlforlist;
157 } else {
158 $backtopage = DOL_URL_ROOT.'/fourn/facture/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
159 }
160 }
161 }
162
163 if ($cancel) {
164 if (!empty($backtopageforcancel)) {
165 header("Location: ".$backtopageforcancel);
166 exit;
167 } elseif (!empty($backtopage)) {
168 header("Location: ".$backtopage);
169 exit;
170 }
171 $action = '';
172 }
173
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 // Link invoice to order
181 if (GETPOST('linkedOrder') && empty($cancel) && $id > 0) {
182 $object->fetch($id);
183 $object->fetch_thirdparty();
184 $result = $object->add_object_linked('order_supplier', GETPOST('linkedOrder'));
185 }
186
187 // Action clone object
188 if ($action == 'confirm_clone' && $confirm == 'yes' && $permissiontoadd) {
189 $objectutil = dol_clone($object, 1); // To avoid to denaturate loaded object when setting some properties for clone. We use native clone to keep this->db valid.
190
191 if (GETPOST('newsupplierref', 'alphanohtml')) {
192 $objectutil->ref_supplier = GETPOST('newsupplierref', 'alphanohtml');
193 }
194 $objectutil->date = dol_mktime(12, 0, 0, GETPOST('newdatemonth', 'int'), GETPOST('newdateday', 'int'), GETPOST('newdateyear', 'int'));
195
196 $result = $objectutil->createFromClone($user, $id);
197 if ($result > 0) {
198 header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
199 exit;
200 } else {
201 $langs->load("errors");
202 setEventMessages($objectutil->error, $objectutil->errors, 'errors');
203 $action = '';
204 }
205 } elseif ($action == 'confirm_valid' && $confirm == 'yes' && $usercanvalidate) {
206 $idwarehouse = GETPOST('idwarehouse');
207
208 $object->fetch($id);
209 $object->fetch_thirdparty();
210
211 $qualified_for_stock_change = 0;
212 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
213 $qualified_for_stock_change = $object->hasProductsOrServices(2);
214 } else {
215 $qualified_for_stock_change = $object->hasProductsOrServices(1);
216 }
217
218 // Check parameters
219 if (isModEnabled('stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) {
220 $langs->load("stocks");
221 if (!$idwarehouse || $idwarehouse == -1) {
222 $error++;
223 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
224 $action = '';
225 }
226 }
227
228 if (!$error) {
229 $db->begin();
230
231 $result = $object->validate($user, '', $idwarehouse);
232 if ($result < 0) {
233 $db->rollback();
234
235 setEventMessages($object->error, $object->errors, 'errors');
236 } else {
237 $db->commit();
238
239 // Define output language
240 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
241 $outputlangs = $langs;
242 $newlang = '';
243 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
244 $newlang = GETPOST('lang_id', 'aZ09');
245 }
246 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
247 $newlang = $object->thirdparty->default_lang;
248 }
249 if (!empty($newlang)) {
250 $outputlangs = new Translate("", $conf);
251 $outputlangs->setDefaultLang($newlang);
252 }
253 $model = $object->model_pdf;
254 $ret = $object->fetch($id); // Reload to get new records
255
256 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
257 if ($result < 0) {
258 dol_print_error($db, $result);
259 }
260 }
261 }
262 }
263 } elseif ($action == 'confirm_delete' && $confirm == 'yes') {
264 $object->fetch($id);
265 $object->fetch_thirdparty();
266
267 $isErasable = $object->is_erasable();
268
269 if (($usercandelete && $isErasable > 0) || ($usercancreate && $isErasable == 1)) {
270 $result = $object->delete($user);
271 if ($result > 0) {
272 header('Location: list.php?restore_lastsearch_values=1');
273 exit;
274 } else {
275 setEventMessages($object->error, $object->errors, 'errors');
276 }
277 }
278 } elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $usercancreate) {
279 // Remove a product line
280 $result = $object->deleteline($lineid);
281 if ($result > 0) {
282 // reorder lines
283 $object->line_order(true);
284 // Define output language
285 /*$outputlangs = $langs;
286 $newlang = '';
287 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id','aZ09'))
288 $newlang = GETPOST('lang_id','aZ09');
289 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang))
290 $newlang = $object->thirdparty->default_lang;
291 if (!empty($newlang)) {
292 $outputlangs = new Translate("", $conf);
293 $outputlangs->setDefaultLang($newlang);
294 }
295 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
296 $ret = $object->fetch($object->id); // Reload to get new records
297 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
298 }*/
299
300 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
301 exit;
302 } else {
303 setEventMessages($object->error, $object->errors, 'errors');
304 /* Fix bug 1485 : Reset action to avoid asking again confirmation on failure */
305 $action = '';
306 }
307 } elseif ($action == 'unlinkdiscount' && $usercancreate) {
308 // Delete link of credit note to invoice
309 $discount = new DiscountAbsolute($db);
310 $result = $discount->fetch(GETPOSTINT("discountid"));
311 $discount->unlink_invoice();
312 } elseif ($action == 'confirm_paid' && $confirm == 'yes' && $usercancreate) {
313 $object->fetch($id);
314 $result = $object->setPaid($user);
315 if ($result < 0) {
316 setEventMessages($object->error, $object->errors, 'errors');
317 }
318 } elseif ($action == 'confirm_paid_partially' && $confirm == 'yes') {
319 // Classif "paid partialy"
320 $object->fetch($id);
321 $close_code = GETPOST("close_code", 'restricthtml');
322 $close_note = GETPOST("close_note", 'restricthtml');
323 if ($close_code) {
324 $result = $object->setPaid($user, $close_code, $close_note);
325 if ($result < 0) {
326 setEventMessages($object->error, $object->errors, 'errors');
327 }
328 } else {
329 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Reason")), null, 'errors');
330 }
331 } elseif ($action == 'confirm_canceled' && $confirm == 'yes') {
332 // Classify "abandoned"
333 $object->fetch($id);
334 $close_code = GETPOST("close_code", 'restricthtml');
335 $close_note = GETPOST("close_note", 'restricthtml');
336 if ($close_code) {
337 $result = $object->setCanceled($user, $close_code, $close_note);
338 if ($result < 0) {
339 setEventMessages($object->error, $object->errors, 'errors');
340 }
341 } else {
342 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Reason")), null, 'errors');
343 }
344 }
345
346 // Set supplier ref
347 if ($action == 'setref_supplier' && $usercancreate) {
348 $object->ref_supplier = GETPOST('ref_supplier', 'alpha');
349
350 if ($object->update($user) < 0) {
351 setEventMessages($object->error, $object->errors, 'errors');
352 } else {
353 // Define output language
354 $outputlangs = $langs;
355 $newlang = '';
356 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
357 $newlang = GETPOST('lang_id', 'aZ09');
358 }
359 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
360 $newlang = $object->thirdparty->default_lang;
361 }
362 if (!empty($newlang)) {
363 $outputlangs = new Translate("", $conf);
364 $outputlangs->setDefaultLang($newlang);
365 }
366 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
367 $ret = $object->fetch($object->id); // Reload to get new records
368 $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
369 }
370 }
371 }
372
373 // payments conditions
374 if ($action == 'setconditions' && $usercancreate) {
375 $object->fetch($id);
376 $object->cond_reglement_code = 0; // To clean property
377 $object->cond_reglement_id = 0; // To clean property
378
379 $error = 0;
380
381 $db->begin();
382
383 if (!$error) {
384 $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int'));
385 if ($result < 0) {
386 $error++;
387 setEventMessages($object->error, $object->errors, 'errors');
388 }
389 }
390
391 if (!$error) {
392 $new_date_echeance = $object->calculate_date_lim_reglement();
393 if ($new_date_echeance) {
394 $object->date_echeance = $new_date_echeance;
395 }
396 if ($object->date_echeance < $object->date) {
397 $object->date_echeance = $object->date;
398 }
399 $result = $object->update($user);
400 if ($result < 0) {
401 $error++;
402 setEventMessages($object->error, $object->errors, 'errors');
403 }
404 }
405
406 if ($error) {
407 $db->rollback();
408 } else {
409 $db->commit();
410 }
411 } elseif ($action == 'set_incoterms' && isModEnabled('incoterm')) {
412 // Set incoterm
413 $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha'));
414 } elseif ($action == 'setmode' && $usercancreate) {
415 // payment mode
416 $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int'));
417 } elseif ($action == 'setmulticurrencycode' && $usercancreate) {
418 // Multicurrency Code
419 $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha'));
420 } elseif ($action == 'setmulticurrencyrate' && $usercancreate) {
421 // Multicurrency rate
422 $result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx', 'alpha')), GETPOST('calculation_mode', 'int'));
423 } elseif ($action == 'setbankaccount' && $usercancreate) {
424 // bank account
425 $result = $object->setBankAccount(GETPOST('fk_account', 'int'));
426 } elseif ($action == 'setvatreversecharge' && $usercancreate) {
427 // vat reverse charge
428 $vatreversecharge = GETPOST('vat_reverse_charge') == 'on' ? 1 : 0;
429 $result = $object->setVATReverseCharge($vatreversecharge);
430 }
431
432 if ($action == 'settransportmode' && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"))) {
433 // transport mode
434 $result = $object->setTransportMode(GETPOST('transport_mode_id', 'int'));
435 } elseif ($action == 'setlabel' && $usercancreate) {
436 // Set label
437 $object->fetch($id);
438 $object->label = GETPOST('label');
439 $result = $object->update($user);
440 if ($result < 0) {
441 dol_print_error($db);
442 }
443 } elseif ($action == 'setdatef' && $usercancreate) {
444 $newdate = dol_mktime(0, 0, 0, GETPOST('datefmonth', 'int'), GETPOST('datefday', 'int'), GETPOST('datefyear', 'int'), 'tzserver');
445 if ($newdate > (dol_now('tzuserrel') + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
446 if (empty($conf->global->INVOICE_MAX_FUTURE_DELAY)) {
447 setEventMessages($langs->trans("WarningInvoiceDateInFuture"), null, 'warnings');
448 } else {
449 setEventMessages($langs->trans("WarningInvoiceDateTooFarInFuture"), null, 'warnings');
450 }
451 }
452
453 $object->fetch($id);
454
455 $object->date = $newdate;
456 $date_echence_calc = $object->calculate_date_lim_reglement();
457 if (!empty($object->date_echeance)) {
458 $object->date_echeance = $date_echence_calc;
459 }
460 if ($object->date_echeance && $object->date_echeance < $object->date) {
461 $object->date_echeance = $object->date;
462 }
463
464 $result = $object->update($user);
465 if ($result < 0) {
466 dol_print_error($db, $object->error);
467 }
468 } elseif ($action == 'setdate_lim_reglement' && $usercancreate) {
469 $object->fetch($id);
470 $object->date_echeance = dol_mktime(12, 0, 0, GETPOST('date_lim_reglementmonth', 'int'), GETPOST('date_lim_reglementday', 'int'), GETPOST('date_lim_reglementyear', 'int'));
471 if (!empty($object->date_echeance) && $object->date_echeance < $object->date) {
472 $object->date_echeance = $object->date;
473 setEventMessages($langs->trans("DatePaymentTermCantBeLowerThanObjectDate"), null, 'warnings');
474 }
475 $result = $object->update($user);
476 if ($result < 0) {
477 dol_print_error($db, $object->error);
478 }
479 } elseif ($action == "setabsolutediscount" && $usercancreate) {
480 // We use the credit to reduce amount of invoice
481 if (GETPOST("remise_id", "int")) {
482 $ret = $object->fetch($id);
483 if ($ret > 0) {
484 $result = $object->insert_discount(GETPOST("remise_id", "int"));
485 if ($result < 0) {
486 setEventMessages($object->error, $object->errors, 'errors');
487 }
488 } else {
489 dol_print_error($db, $object->error);
490 }
491 }
492 // We use the credit to reduce remain to pay
493 if (GETPOST("remise_id_for_payment", "int")) {
494 require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
495 $discount = new DiscountAbsolute($db);
496 $discount->fetch(GETPOST("remise_id_for_payment", "int"));
497
498 //var_dump($object->getRemainToPay(0));
499 //var_dump($discount->amount_ttc);exit;
500 if (price2num($discount->amount_ttc) > price2num($object->getRemainToPay(0))) {
501 // TODO Split the discount in 2 automatically
502 $error++;
503 setEventMessages($langs->trans("ErrorDiscountLargerThanRemainToPaySplitItBefore"), null, 'errors');
504 }
505
506 if (!$error) {
507 $result = $discount->link_to_invoice(0, $id);
508 if ($result < 0) {
509 setEventMessages($discount->error, $discount->errors, 'errors');
510 }
511 }
512 }
513
514 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
515 $outputlangs = $langs;
516 $newlang = '';
517 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
518 $newlang = GETPOST('lang_id', 'aZ09');
519 }
520 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
521 $newlang = $object->thirdparty->default_lang;
522 }
523 if (!empty($newlang)) {
524 $outputlangs = new Translate("", $conf);
525 $outputlangs->setDefaultLang($newlang);
526 }
527 $ret = $object->fetch($id); // Reload to get new records
528
529 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
530 if ($result < 0) {
531 setEventMessages($object->error, $object->errors, 'errors');
532 }
533 }
534 } elseif ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $usercancreate) {
535 // Convertir en reduc
536 $object->fetch($id);
537 $object->fetch_thirdparty();
538 //$object->fetch_lines(); // Already done into fetch
539
540 // Check if there is already a discount (protection to avoid duplicate creation when resubmit post)
541 $discountcheck = new DiscountAbsolute($db);
542 $result = $discountcheck->fetch(0, 0, $object->id);
543
544 $canconvert = 0;
545 if ($object->type == FactureFournisseur::TYPE_DEPOSIT && empty($discountcheck->id)) {
546 $canconvert = 1; // we can convert deposit into discount if deposit is paid (completely, partially or not at all) and not already converted (see real condition into condition used to show button converttoreduc)
547 }
548 if (($object->type == FactureFournisseur::TYPE_CREDIT_NOTE || $object->type == FactureFournisseur::TYPE_STANDARD) && $object->paye == 0 && empty($discountcheck->id)) {
549 $canconvert = 1; // we can convert credit note into discount if credit note is not refunded completely and not already converted and amount of payment is 0 (see also the real condition used as the condition to show button converttoreduc)
550 }
551 if ($canconvert) {
552 $db->begin();
553
554 $amount_ht = $amount_tva = $amount_ttc = array();
555 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
556
557 // Loop on each vat rate
558 $i = 0;
559 foreach ($object->lines as $line) {
560 if ($line->product_type < 9 && $line->total_ht != 0) { // Remove lines with product_type greater than or equal to 9 and no need to create discount if amount is null
561 $keyforvatrate = $line->tva_tx.($line->vat_src_code ? ' ('.$line->vat_src_code.')' : '');
562
563 $amount_ht[$keyforvatrate] += $line->total_ht;
564 $amount_tva[$keyforvatrate] += $line->total_tva;
565 $amount_ttc[$keyforvatrate] += $line->total_ttc;
566 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
567 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
568 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
569 $i++;
570 }
571 }
572
573 // If some payments were already done, we change the amount to pay using same prorate
574 if (!empty($conf->global->SUPPLIER_INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED) && $object->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
575 $alreadypaid = $object->getSommePaiement(); // This can be not 0 if we allow to create credit to reuse from credit notes partially refunded.
576 if ($alreadypaid && abs($alreadypaid) < abs($object->total_ttc)) {
577 $ratio = abs(($object->total_ttc - $alreadypaid) / $object->total_ttc);
578 foreach ($amount_ht as $vatrate => $val) {
579 $amount_ht[$vatrate] = price2num($amount_ht[$vatrate] * $ratio, 'MU');
580 $amount_tva[$vatrate] = price2num($amount_tva[$vatrate] * $ratio, 'MU');
581 $amount_ttc[$vatrate] = price2num($amount_ttc[$vatrate] * $ratio, 'MU');
582 $multicurrency_amount_ht[$vatrate] = price2num($multicurrency_amount_ht[$vatrate] * $ratio, 'MU');
583 $multicurrency_amount_tva[$vatrate] = price2num($multicurrency_amount_tva[$vatrate] * $ratio, 'MU');
584 $multicurrency_amount_ttc[$vatrate] = price2num($multicurrency_amount_ttc[$vatrate] * $ratio, 'MU');
585 }
586 }
587 }
588 //var_dump($amount_ht);var_dump($amount_tva);var_dump($amount_ttc);exit;
589
590 // Insert one discount by VAT rate category
591 $discount = new DiscountAbsolute($db);
592 if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
593 $discount->description = '(CREDIT_NOTE)';
594 } elseif ($object->type == FactureFournisseur::TYPE_DEPOSIT) {
595 $discount->description = '(DEPOSIT)';
596 } elseif ($object->type == FactureFournisseur::TYPE_STANDARD || $object->type == FactureFournisseur::TYPE_REPLACEMENT || $object->type == FactureFournisseur::TYPE_SITUATION) {
597 $discount->description = '(EXCESS PAID)';
598 } else {
599 setEventMessages($langs->trans('CantConvertToReducAnInvoiceOfThisType'), null, 'errors');
600 }
601 $discount->discount_type = 1; // Supplier discount
602 $discount->fk_soc = $object->socid;
603 $discount->fk_invoice_supplier_source = $object->id;
604
605 $error = 0;
606
607 if ($object->type == FactureFournisseur::TYPE_STANDARD || $object->type == FactureFournisseur::TYPE_REPLACEMENT || $object->type == FactureFournisseur::TYPE_SITUATION) {
608 // If we're on a standard invoice, we have to get excess paid to create a discount in TTC without VAT
609
610 // Total payments
611 $sql = 'SELECT SUM(pf.amount) as total_paiements';
612 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf, '.MAIN_DB_PREFIX.'paiementfourn as p';
613 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id AND c.entity IN ('.getEntity('c_paiement').')';
614 $sql .= ' WHERE pf.fk_facturefourn = '.((int) $object->id);
615 $sql .= ' AND pf.fk_paiementfourn = p.rowid';
616 $sql .= ' AND p.entity IN ('.getEntity('invoice').')';
617
618 $resql = $db->query($sql);
619 if (!$resql) {
620 dol_print_error($db);
621 }
622
623 $res = $db->fetch_object($resql);
624 $total_paiements = $res->total_paiements;
625
626 // Total credit note and deposit
627 $total_creditnote_and_deposit = 0;
628 $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
629 $sql .= " re.description, re.fk_invoice_supplier_source";
630 $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re";
631 $sql .= " WHERE fk_invoice_supplier = ".((int) $object->id);
632 $resql = $db->query($sql);
633 if (!empty($resql)) {
634 while ($obj = $db->fetch_object($resql)) {
635 $total_creditnote_and_deposit += $obj->amount_ttc;
636 }
637 } else {
638 dol_print_error($db);
639 }
640
641 $discount->amount_ht = $discount->amount_ttc = $total_paiements + $total_creditnote_and_deposit - $object->total_ttc;
642 $discount->amount_tva = 0;
643 $discount->tva_tx = 0;
644 $discount->vat_src_code = '';
645
646 $result = $discount->create($user);
647 if ($result < 0) {
648 $error++;
649 }
650 }
651 if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE || $object->type == FactureFournisseur::TYPE_DEPOSIT) {
652 foreach ($amount_ht as $tva_tx => $xxx) {
653 $discount->amount_ht = abs($amount_ht[$tva_tx]);
654 $discount->amount_tva = abs($amount_tva[$tva_tx]);
655 $discount->amount_ttc = abs($amount_ttc[$tva_tx]);
656 $discount->multicurrency_amount_ht = abs($multicurrency_amount_ht[$tva_tx]);
657 $discount->multicurrency_amount_tva = abs($multicurrency_amount_tva[$tva_tx]);
658 $discount->multicurrency_amount_ttc = abs($multicurrency_amount_ttc[$tva_tx]);
659
660 // Clean vat code
661 $reg = array();
662 $vat_src_code = '';
663 if (preg_match('/\‍((.*)\‍)/', $tva_tx, $reg)) {
664 $vat_src_code = $reg[1];
665 $tva_tx = preg_replace('/\s*\‍(.*\‍)/', '', $tva_tx); // Remove code into vatrate.
666 }
667
668 $discount->tva_tx = abs($tva_tx);
669 $discount->vat_src_code = $vat_src_code;
670
671 $result = $discount->create($user);
672 if ($result < 0) {
673 $error++;
674 break;
675 }
676 }
677 }
678
679 if (empty($error)) {
680 if ($object->type != FactureFournisseur::TYPE_DEPOSIT) {
681 // Classe facture
682 $result = $object->setPaid($user);
683 if ($result >= 0) {
684 $db->commit();
685 } else {
686 setEventMessages($object->error, $object->errors, 'errors');
687 $db->rollback();
688 }
689 } else {
690 $db->commit();
691 }
692 } else {
693 setEventMessages($discount->error, $discount->errors, 'errors');
694 $db->rollback();
695 }
696 }
697 } elseif ($action == 'confirm_delete_paiement' && $confirm == 'yes' && $usercancreate) {
698 // Delete payment
699 $object->fetch($id);
700 if ($object->statut == FactureFournisseur::STATUS_VALIDATED && $object->paye == 0) {
701 $paiementfourn = new PaiementFourn($db);
702 $result = $paiementfourn->fetch(GETPOST('paiement_id'));
703 if ($result > 0) {
704 $result = $paiementfourn->delete();
705 if ($result > 0) {
706 header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
707 exit;
708 }
709 }
710 if ($result < 0) {
711 setEventMessages($paiementfourn->error, $paiementfourn->errors, 'errors');
712 }
713 }
714 } elseif ($action == 'add' && $usercancreate) {
715 // Insert new invoice in database
716 if ($socid > 0) {
717 $object->socid = GETPOST('socid', 'int');
718 }
719 $selectedLines = GETPOST('toselect', 'array');
720
721 $db->begin();
722
723 $error = 0;
724
725 // Fill array 'array_options' with data from add form
726 $ret = $extrafields->setOptionalsFromPost(null, $object);
727 if ($ret < 0) {
728 $error++;
729 }
730
731 $dateinvoice = dol_mktime(0, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'), 'tzserver'); // If we enter the 02 january, we need to save the 02 january for server
732 $datedue = dol_mktime(0, 0, 0, GETPOST('echmonth', 'int'), GETPOST('echday', 'int'), GETPOST('echyear', 'int'), 'tzserver');
733 //var_dump($dateinvoice.' '.dol_print_date($dateinvoice, 'dayhour'));
734 //var_dump(dol_now('tzuserrel').' '.dol_get_last_hour(dol_now('tzuserrel')).' '.dol_print_date(dol_now('tzuserrel'),'dayhour').' '.dol_print_date(dol_get_last_hour(dol_now('tzuserrel')), 'dayhour'));
735 //var_dump($db->idate($dateinvoice));
736 //exit;
737
738 // Replacement invoice
739 if (GETPOST('type', 'int') === '') {
740 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type")), null, 'errors');
741 $error++;
742 }
743
745 if (empty($dateinvoice)) {
746 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('DateInvoice')), null, 'errors');
747 $action = 'create';
748 $_GET['socid'] = $_POST['socid'];
749 $error++;
750 } elseif ($dateinvoice > (dol_get_last_hour(dol_now('tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
751 $error++;
752 setEventMessages($langs->trans("ErrorDateIsInFuture"), null, 'errors');
753 $action = 'create';
754 }
755
756 if (!(GETPOST('fac_replacement', 'int') > 0)) {
757 $error++;
758 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ReplaceInvoice")), null, 'errors');
759 }
760
761 if (!$error) {
762 // This is a replacement invoice
763 $result = $object->fetch(GETPOST('fac_replacement', 'int'));
764 $object->fetch_thirdparty();
765
766 $object->ref = GETPOST('ref', 'alphanohtml');
767 $object->ref_supplier = GETPOST('ref_supplier', 'alpha');
768 $object->socid = GETPOST('socid', 'int');
769 $object->libelle = GETPOST('label', 'alphanohtml');
770 $object->date = $dateinvoice;
771 $object->date_echeance = $datedue;
772 $object->note_public = GETPOST('note_public', 'restricthtml');
773 $object->note_private = GETPOST('note_private', 'restricthtml');
774 $object->cond_reglement_id = GETPOST('cond_reglement_id', 'int');
775 $object->mode_reglement_id = GETPOST('mode_reglement_id', 'int');
776 $object->fk_account = GETPOST('fk_account', 'int');
777 $object->vat_reverse_charge = GETPOST('vat_reverse_charge') == 'on' ? 1 : 0;
778 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
779 $object->fk_incoterms = GETPOST('incoterm_id', 'int');
780 $object->location_incoterms = GETPOST('location_incoterms', 'alpha');
781 $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
782 $object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int');
783 $object->transport_mode_id = GETPOST('transport_mode_id', 'int');
784
785 // Proprietes particulieres a facture de remplacement
786 $object->fk_facture_source = GETPOST('fac_replacement', 'int');
788
789 $id = $object->createFromCurrent($user);
790 if ($id <= 0) {
791 $error++;
792 setEventMessages($object->error, $object->errors, 'errors');
793 }
794 }
795 }
796
797 // Credit note invoice
799 $sourceinvoice = GETPOST('fac_avoir', 'int');
800 if (!($sourceinvoice > 0) && empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) {
801 $error++;
802 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("CorrectInvoice")), null, 'errors');
803 }
804 if (GETPOST('socid', 'int') < 1) {
805 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Supplier')), null, 'errors');
806 $action = 'create';
807 $error++;
808 }
809
810 if (empty($dateinvoice)) {
811 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('DateInvoice')), null, 'errors');
812 $action = 'create';
813 $_GET['socid'] = $_POST['socid'];
814 $error++;
815 } elseif ($dateinvoice > (dol_get_last_hour(dol_now('tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
816 $error++;
817 setEventMessages($langs->trans("ErrorDateIsInFuture"), null, 'errors');
818 $action = 'create';
819 }
820
821 if (!GETPOST('ref_supplier')) {
822 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('RefSupplier')), null, 'errors');
823 $action = 'create';
824 $_GET['socid'] = $_POST['socid'];
825 $error++;
826 }
827
828 if (!$error) {
829 $tmpproject = GETPOST('projectid', 'int');
830
831 // Creation facture
832 $object->ref = GETPOST('ref', 'alphanohtml');
833 $object->ref_supplier = GETPOST('ref_supplier', 'alphanohtml');
834 $object->socid = GETPOST('socid', 'int');
835 $object->libelle = GETPOST('label', 'alphanohtml');
836 $object->label = GETPOST('label', 'alphanohtml');
837 $object->date = $dateinvoice;
838 $object->date_echeance = $datedue;
839 $object->note_public = GETPOST('note_public', 'restricthtml');
840 $object->note_private = GETPOST('note_private', 'restricthtml');
841 $object->cond_reglement_id = GETPOST('cond_reglement_id');
842 $object->mode_reglement_id = GETPOST('mode_reglement_id');
843 $object->fk_account = GETPOST('fk_account', 'int');
844 $object->vat_reverse_charge = GETPOST('vat_reverse_charge') == 'on' ? 1 : 0;
845 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
846 $object->fk_incoterms = GETPOST('incoterm_id', 'int');
847 $object->location_incoterms = GETPOST('location_incoterms', 'alpha');
848 $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
849 $object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int');
850 $object->transport_mode_id = GETPOST('transport_mode_id', 'int');
851
852 // Proprietes particulieres a facture avoir
853 $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice : '';
855
856 $id = $object->create($user);
857
858 if ($id <= 0) {
859 $error++;
860 }
861
862 if (GETPOST('invoiceAvoirWithLines', 'int') == 1 && $id > 0) {
863 $facture_source = new FactureFournisseur($db); // fetch origin object
864 if ($facture_source->fetch($object->fk_facture_source) > 0) {
865 $fk_parent_line = 0;
866
867 foreach ($facture_source->lines as $line) {
868 // Reset fk_parent_line for no child products and special product
869 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
870 $fk_parent_line = 0;
871 }
872
873 $line->fk_facture_fourn = $object->id;
874 $line->fk_parent_line = $fk_parent_line;
875
876 $line->subprice = -$line->subprice; // invert price for object
877 $line->pa_ht = -$line->pa_ht;
878 $line->total_ht = -$line->total_ht;
879 $line->total_tva = -$line->total_tva;
880 $line->total_ttc = -$line->total_ttc;
881 $line->total_localtax1 = -$line->total_localtax1;
882 $line->total_localtax2 = -$line->total_localtax2;
883
884 $result = $line->insert();
885
886 $object->lines[] = $line; // insert new line in current object
887
888 // Defined the new fk_parent_line
889 if ($result > 0 && $line->product_type == 9) {
890 $fk_parent_line = $result;
891 }
892 }
893
894 $object->update_price(1);
895 }
896 }
897
898 if (GETPOST('invoiceAvoirWithPaymentRestAmount', 'int') == 1 && $id > 0) {
899 $facture_source = new FactureFournisseur($db); // fetch origin object if not previously defined
900 if ($facture_source->fetch($object->fk_facture_source) > 0) {
901 $totalpaid = $facture_source->getSommePaiement();
902 $totalcreditnotes = $facture_source->getSumCreditNotesUsed();
903 $totaldeposits = $facture_source->getSumDepositsUsed();
904 $remain_to_pay = abs($facture_source->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits);
905 $desc = $langs->trans('invoiceAvoirLineWithPaymentRestAmount');
906 $retAddLine = $object->addline($desc, $remain_to_pay, 0, 0, 0, 1, 0, 0, '', '', 0, '', 'TTC');
907
908 if ($retAddLine < 0) {
909 $error++;
910 }
911 }
912 }
913 }
914 } elseif ($fac_recid > 0 && (GETPOST('type') == FactureFournisseur::TYPE_STANDARD || GETPOST('type') == FactureFournisseur::TYPE_DEPOSIT)) {
915 // Standard invoice or Deposit invoice, created from a Predefined template invoice
916 if (empty($dateinvoice)) {
917 $error++;
918 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Date")), null, 'errors');
919 $action = 'create';
920 } elseif ($dateinvoice > (dol_get_last_hour(dol_now('tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
921 $error++;
922 setEventMessages($langs->trans("ErrorDateIsInFuture"), null, 'errors');
923 $action = 'create';
924 }
925
926 if (!$error) {
927 $object->socid = GETPOST('socid', 'int');
928 $object->type = GETPOST('type', 'alphanohtml');
929 $object->ref = GETPOST('ref', 'alphanohtml');
930 $object->date = $dateinvoice;
931 $object->note_public = trim(GETPOST('note_public', 'restricthtml'));
932 $object->note_private = trim(GETPOST('note_private', 'restricthtml'));
933 $object->ref_supplier = GETPOST('ref_supplier', 'alphanohtml');
934 $object->model_pdf = GETPOST('model', 'alphanohtml');
935 $object->fk_project = GETPOST('projectid', 'int');
936 $object->cond_reglement_id = (GETPOST('type') == 3 ? 1 : GETPOST('cond_reglement_id'));
937 $object->mode_reglement_id = GETPOST('mode_reglement_id', 'int');
938 $object->fk_account = GETPOST('fk_account', 'int');
939 $object->amount = price2num(GETPOST('amount'));
940 $object->remise_absolue = price2num(GETPOST('remise_absolue'), 'MU');
941 $object->remise_percent = price2num(GETPOST('remise_percent'), '', 2);
942 $object->fk_incoterms = GETPOST('incoterm_id', 'int');
943 $object->location_incoterms = GETPOST('location_incoterms', 'alpha');
944 $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
945 $object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int');
946
947 // Source facture
948 $object->fac_rec = $fac_recid;
949 $fac_rec = new FactureFournisseurRec($db);
950 $fac_rec->fetch($object->fac_rec);
951 $fac_rec->fetch_lines();
952 $object->lines = $fac_rec->lines;
953
954 $id = $object->create($user); // This include recopy of links from recurring invoice and recurring invoice lines
955 }
956 } elseif ($fac_recid <= 0 && (GETPOST('type') == FactureFournisseur::TYPE_STANDARD || GETPOST('type') == FactureFournisseur::TYPE_DEPOSIT)) {
957 // Standard invoice or Deposit invoice, not from a Predefined template invoice
958 if (GETPOST('socid', 'int') < 1) {
959 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('Supplier')), null, 'errors');
960 $action = 'create';
961 $error++;
962 }
963
964 if (empty($dateinvoice)) {
965 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('DateInvoice')), null, 'errors');
966 $action = 'create';
967 $_GET['socid'] = $_POST['socid'];
968 $error++;
969 } elseif ($dateinvoice > (dol_get_last_hour(dol_now('tzuserrel')) + (empty($conf->global->INVOICE_MAX_FUTURE_DELAY) ? 0 : $conf->global->INVOICE_MAX_FUTURE_DELAY))) {
970 $error++;
971 setEventMessages($langs->trans("ErrorDateIsInFuture"), null, 'errors');
972 $action = 'create';
973 }
974
975 if (!GETPOST('ref_supplier')) {
976 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentities('RefSupplier')), null, 'errors');
977 $action = 'create';
978 $_GET['socid'] = $_POST['socid'];
979 $error++;
980 }
981
982 if (!$error) {
983 $tmpproject = GETPOST('projectid', 'int');
984
985 // Creation invoice
986 $object->socid = GETPOST('socid', 'int');
987 $object->type = GETPOST('type', 'alphanohtml');
988 $object->ref = GETPOST('ref', 'alphanohtml');
989 $object->ref_supplier = GETPOST('ref_supplier', 'alphanohtml');
990 $object->socid = GETPOST('socid', 'int');
991 $object->libelle = GETPOST('label', 'alphanohtml'); // deprecated
992 $object->label = GETPOST('label', 'alphanohtml');
993 $object->date = $dateinvoice;
994 $object->date_echeance = $datedue;
995 $object->note_public = GETPOST('note_public', 'restricthtml');
996 $object->note_private = GETPOST('note_private', 'restricthtml');
997 $object->cond_reglement_id = GETPOST('cond_reglement_id');
998 $object->mode_reglement_id = GETPOST('mode_reglement_id');
999 $object->fk_account = GETPOST('fk_account', 'int');
1000 $object->vat_reverse_charge = GETPOST('vat_reverse_charge') == 'on' ? 1 : 0;
1001 $object->fk_project = ($tmpproject > 0) ? $tmpproject : null;
1002 $object->fk_incoterms = GETPOST('incoterm_id', 'int');
1003 $object->location_incoterms = GETPOST('location_incoterms', 'alpha');
1004 $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha');
1005 $object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int');
1006 $object->transport_mode_id = GETPOST('transport_mode_id');
1007
1008 // Auto calculation of date due if not filled by user
1009 if (empty($object->date_echeance)) {
1010 $object->date_echeance = $object->calculate_date_lim_reglement();
1011 }
1012
1013 $object->fetch_thirdparty();
1014
1015 // If creation from another object of another module
1016 if (!$error && GETPOST('origin', 'alpha') && GETPOST('originid')) {
1017 // Parse element/subelement (ex: project_task)
1018 $element = $subelement = GETPOST('origin', 'alpha');
1019 /*if (preg_match('/^([^_]+)_([^_]+)/i', GETPOST('origin'),$regs))
1020 {
1021 $element = $regs[1];
1022 $subelement = $regs[2];
1023 }*/
1024
1025 // For compatibility
1026 if ($element == 'order') {
1027 $element = $subelement = 'commande';
1028 }
1029 if ($element == 'propal') {
1030 $element = 'comm/propal'; $subelement = 'propal';
1031 }
1032 if ($element == 'contract') {
1033 $element = $subelement = 'contrat';
1034 }
1035 if ($element == 'order_supplier') {
1036 $element = 'fourn'; $subelement = 'fournisseur.commande';
1037 }
1038 if ($element == 'project') {
1039 $element = 'projet';
1040 }
1041 $object->origin = GETPOST('origin', 'alpha');
1042 $object->origin_id = GETPOST('originid', 'int');
1043
1044
1045 require_once DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php';
1046 $classname = ucfirst($subelement);
1047 if ($classname == 'Fournisseur.commande') {
1048 $classname = 'CommandeFournisseur';
1049 }
1050 $objectsrc = new $classname($db);
1051 $objectsrc->fetch($originid);
1052 $objectsrc->fetch_thirdparty();
1053
1054 if (!empty($object->origin) && !empty($object->origin_id)) {
1055 $object->linkedObjectsIds[$object->origin] = $object->origin_id;
1056 }
1057
1058 // Add also link with order if object is reception
1059 if ($object->origin == 'reception') {
1060 $objectsrc->fetchObjectLinked();
1061
1062 if (count($objectsrc->linkedObjectsIds['order_supplier']) > 0) {
1063 foreach ($objectsrc->linkedObjectsIds['order_supplier'] as $key => $value) {
1064 $object->linkedObjectsIds['order_supplier'] = $value;
1065 }
1066 }
1067 }
1068
1069 $id = $object->create($user);
1070
1071 // Add lines
1072 if ($id > 0) {
1073 require_once DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php';
1074 $classname = ucfirst($subelement);
1075 if ($classname == 'Fournisseur.commande') {
1076 $classname = 'CommandeFournisseur';
1077 }
1078 $srcobject = new $classname($db);
1079
1080 $result = $srcobject->fetch(GETPOST('originid', 'int'));
1081
1082 // If deposit invoice - down payment with 1 line (fixed amount or percent)
1083 $typeamount = GETPOST('typedeposit', 'alpha');
1084 if (GETPOST('type') == FactureFournisseur::TYPE_DEPOSIT && in_array($typeamount, array('amount', 'variable'))) {
1085 $valuedeposit = price2num(GETPOST('valuedeposit', 'alpha'), 'MU');
1086
1087 // Define the array $amountdeposit
1088 $amountdeposit = array();
1089 if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA)) {
1090 if ($typeamount == 'amount') {
1091 $amount = $valuedeposit;
1092 } else {
1093 $amount = $srcobject->total_ttc * ($valuedeposit / 100);
1094 }
1095
1096 $TTotalByTva = array();
1097 foreach ($srcobject->lines as &$line) {
1098 if (!empty($line->special_code)) {
1099 continue;
1100 }
1101 $TTotalByTva[$line->tva_tx] += $line->total_ttc;
1102 }
1103
1104 foreach ($TTotalByTva as $tva => &$total) {
1105 $coef = $total / $srcobject->total_ttc; // Calc coef
1106 $am = $amount * $coef;
1107 $amount_ttc_diff += $am;
1108 $amountdeposit[$tva] += $am / (1 + $tva / 100); // Convert into HT for the addline
1109 }
1110 } else {
1111 if ($typeamount == 'amount') {
1112 $amountdeposit[0] = $valuedeposit;
1113 } elseif ($typeamount == 'variable') {
1114 if ($result > 0) {
1115 $totalamount = 0;
1116 $lines = $srcobject->lines;
1117 $numlines = count($lines);
1118 for ($i = 0; $i < $numlines; $i++) {
1119 $qualified = 1;
1120 if (empty($lines[$i]->qty)) {
1121 $qualified = 0; // We discard qty=0, it is an option
1122 }
1123 if (!empty($lines[$i]->special_code)) {
1124 $qualified = 0; // We discard special_code (frais port, ecotaxe, option, ...)
1125 }
1126 if ($qualified) {
1127 $totalamount += $lines[$i]->total_ht; // Fixme : is it not for the customer ? Shouldn't we take total_ttc ?
1128 $tva_tx = $lines[$i]->tva_tx;
1129 $amountdeposit[$tva_tx] += ($lines[$i]->total_ht * $valuedeposit) / 100;
1130 }
1131 }
1132
1133 if ($totalamount == 0) {
1134 $amountdeposit[0] = 0;
1135 }
1136 } else {
1137 setEventMessages($srcobject->error, $srcobject->errors, 'errors');
1138 $error++;
1139 }
1140 }
1141
1142 $amount_ttc_diff = $amountdeposit[0];
1143 }
1144
1145 foreach ($amountdeposit as $tva => $amount) {
1146 if (empty($amount)) {
1147 continue;
1148 }
1149
1150 $arraylist = array(
1151 'amount' => 'FixAmount',
1152 'variable' => 'VarAmount'
1153 );
1154 $descline = '(DEPOSIT)';
1155 //$descline.= ' - '.$langs->trans($arraylist[$typeamount]);
1156 if ($typeamount == 'amount') {
1157 $descline .= ' ('.price($valuedeposit, '', $langs, 0, - 1, - 1, (!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency)).')';
1158 } elseif ($typeamount == 'variable') {
1159 $descline .= ' ('.$valuedeposit.'%)';
1160 }
1161
1162 $descline .= ' - '.$srcobject->ref;
1163 $result = $object->addline(
1164 $descline,
1165 $amount, // subprice
1166 $tva, // vat rate
1167 0, // localtax1_tx
1168 0, // localtax2_tx
1169 1, // quantity
1170 (empty($conf->global->INVOICE_PRODUCTID_DEPOSIT) ? 0 : $conf->global->INVOICE_PRODUCTID_DEPOSIT), // fk_product
1171 0, // remise_percent
1172 0, // date_start
1173 0, // date_end
1174 0,
1175 $lines[$i]->info_bits, // info_bits
1176 'HT',
1177 0, // product_type
1178 1,
1179 0,
1180 0,
1181 null,
1182 $object->origin,
1183 0,
1184 '',
1185 $lines[$i]->special_code,
1186 0,
1187 0
1188 //,$langs->trans('Deposit') //Deprecated
1189 );
1190 }
1191
1192 $diff = $object->total_ttc - $amount_ttc_diff;
1193
1194 if (!empty($conf->global->MAIN_DEPOSIT_MULTI_TVA) && $diff != 0) {
1195 $object->fetch_lines();
1196 $subprice_diff = $object->lines[0]->subprice - $diff / (1 + $object->lines[0]->tva_tx / 100);
1197 $object->updateline(
1198 $object->lines[0]->id,
1199 $object->lines[0]->desc,
1200 $subprice_diff,
1201 $object->lines[0]->tva_tx,
1202 $object->lines[0]->localtax1_tx,
1203 $object->lines[0]->localtax2_tx,
1204 $object->lines[0]->qty,
1205 $object->lines[0]->fk_product,
1206 'HT',
1207 $object->lines[0]->info_bits,
1208 $object->lines[0]->product_type,
1209 $object->lines[0]->remise_percent,
1210 0,
1211 $object->lines[0]->date_start,
1212 $object->lines[0]->date_end,
1213 0,
1214 0,
1215 0,
1216 '',
1217 100
1218 );
1219 }
1220 } elseif ($result > 0) {
1221 $lines = $srcobject->lines;
1222 if (empty($lines) && method_exists($srcobject, 'fetch_lines')) {
1223 $srcobject->fetch_lines();
1224 $lines = $srcobject->lines;
1225 }
1226
1227 $num = count($lines);
1228 for ($i = 0; $i < $num; $i++) { // TODO handle subprice < 0
1229 if (!in_array($lines[$i]->id, $selectedLines)) {
1230 continue; // Skip unselected lines
1231 }
1232
1233 $desc = ($lines[$i]->desc ? $lines[$i]->desc : $lines[$i]->libelle);
1234 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
1235
1236 // Extrafields
1237 if (method_exists($lines[$i], 'fetch_optionals')) {
1238 $lines[$i]->fetch_optionals();
1239 }
1240
1241 // Dates
1242 // TODO mutualiser
1243 $date_start = $lines[$i]->date_debut_prevue;
1244 if ($lines[$i]->date_debut_reel) {
1245 $date_start = $lines[$i]->date_debut_reel;
1246 }
1247 if ($lines[$i]->date_start) {
1248 $date_start = $lines[$i]->date_start;
1249 }
1250 $date_end = $lines[$i]->date_fin_prevue;
1251 if ($lines[$i]->date_fin_reel) {
1252 $date_end = $lines[$i]->date_fin_reel;
1253 }
1254 if ($lines[$i]->date_end) {
1255 $date_end = $lines[$i]->date_end;
1256 }
1257
1258 $tva_tx = $lines[$i]->tva_tx;
1259 if (!empty($lines[$i]->vat_src_code) && !preg_match('/\‍(/', $tva_tx)) {
1260 $tva_tx .= ' ('.$lines[$i]->vat_src_code.')';
1261 }
1262
1263 // FIXME Missing special_code into addline and updateline methods
1264 $object->special_code = $lines[$i]->special_code;
1265
1266 // FIXME If currency different from main currency, take multicurrency price
1267 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
1268 $pu = 0;
1269 $pu_currency = $lines[$i]->multicurrency_subprice;
1270 } else {
1271 $pu = $lines[$i]->subprice;
1272 $pu_currency = 0;
1273 }
1274
1275 // FIXME Missing $lines[$i]->ref_supplier and $lines[$i]->label into addline and updateline methods. They are filled when coming from order for example.
1276 $result = $object->addline(
1277 $desc,
1278 $pu,
1279 $tva_tx,
1280 $lines[$i]->localtax1_tx,
1281 $lines[$i]->localtax2_tx,
1282 $lines[$i]->qty,
1283 $lines[$i]->fk_product,
1284 $lines[$i]->remise_percent,
1285 $date_start,
1286 $date_end,
1287 0,
1288 $lines[$i]->info_bits,
1289 'HT',
1290 $product_type,
1291 $lines[$i]->rang,
1292 0,
1293 $lines[$i]->array_options,
1294 $lines[$i]->fk_unit,
1295 $lines[$i]->id,
1296 $pu_currency,
1297 $lines[$i]->ref_supplier,
1298 $lines[$i]->special_code
1299 );
1300
1301 if ($result < 0) {
1302 $error++;
1303 break;
1304 }
1305 }
1306
1307 // Now reload line
1308 $object->fetch_lines();
1309 } else {
1310 $error++;
1311 }
1312 } else {
1313 $error++;
1314 }
1315 } elseif (!$error) {
1316 $id = $object->create($user);
1317 if ($id < 0) {
1318 $error++;
1319 }
1320 }
1321 }
1322 }
1323
1324 if ($error) {
1325 $langs->load("errors");
1326 $db->rollback();
1327
1328 setEventMessages($object->error, $object->errors, 'errors');
1329 $action = 'create';
1330 $_GET['socid'] = $_POST['socid'];
1331 } else {
1332 $db->commit();
1333
1334 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1335 $outputlangs = $langs;
1336 $result = $object->generateDocument($object->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref);
1337 if ($result < 0) {
1338 dol_print_error($db, $object->error, $object->errors);
1339 exit;
1340 }
1341 }
1342
1343 header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
1344 exit;
1345 }
1346 } elseif ($action == 'updateline' && $usercancreate) {
1347 // Edit line
1348 $db->begin();
1349
1350 if (! $object->fetch($id) > 0) {
1351 dol_print_error($db);
1352 }
1353 $object->fetch_thirdparty();
1354
1355 $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0);
1356 $tva_tx = str_replace('*', '', $tva_tx);
1357
1358 if (GETPOST('price_ht') != '' || GETPOST('multicurrency_subprice') != '') {
1359 $up = price2num(GETPOST('price_ht'), '', 2);
1360 $price_base_type = 'HT';
1361 } else {
1362 $up = price2num(GETPOST('price_ttc'), '', 2);
1363 $price_base_type = 'TTC';
1364 }
1365
1366 if (GETPOST('productid') > 0) {
1367 $productsupplier = new ProductFournisseur($db);
1368 if (!empty($conf->global->SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY)) {
1369 if (GETPOST('productid') > 0 && $productsupplier->get_buyprice(0, price2num(GETPOST('qty')), GETPOST('productid', 'int'), 'restricthtml', GETPOST('socid', 'int')) < 0) {
1370 setEventMessages($langs->trans("ErrorQtyTooLowForThisSupplier"), null, 'warnings');
1371 }
1372 }
1373
1374 $prod = new Product($db);
1375 $prod->fetch(GETPOST('productid'));
1376 $label = $prod->description;
1377 if (trim(GETPOST('product_desc', 'restricthtml')) != trim($label)) {
1378 $label = GETPOST('product_desc', 'restricthtml');
1379 }
1380
1381 $type = $prod->type;
1382 } else {
1383 $label = GETPOST('product_desc', 'restricthtml');
1384 $type = GETPOST("type") ? GETPOST("type") : 0;
1385 }
1386
1387 $date_start = dol_mktime(GETPOST('date_starthour'), GETPOST('date_startmin'), GETPOST('date_startsec'), GETPOST('date_startmonth'), GETPOST('date_startday'), GETPOST('date_startyear'));
1388 $date_end = dol_mktime(GETPOST('date_endhour'), GETPOST('date_endmin'), GETPOST('date_endsec'), GETPOST('date_endmonth'), GETPOST('date_endday'), GETPOST('date_endyear'));
1389
1390 // Define info_bits
1391 $info_bits = 0;
1392 if (preg_match('/\*/', $tva_tx)) {
1393 $info_bits |= 0x01;
1394 }
1395
1396 // Define vat_rate
1397 $tva_tx = str_replace('*', '', $tva_tx);
1398 $localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
1399 $localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
1400
1401 $remise_percent = price2num(GETPOST('remise_percent'), '', 2);
1402 $pu_devise = price2num(GETPOST('multicurrency_subprice'), 'MU', 2);
1403
1404 // Extrafields Lines
1405 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1406 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line);
1407 // Unset extrafield POST Data
1408 if (is_array($extralabelsline)) {
1409 foreach ($extralabelsline as $key => $value) {
1410 unset($_POST["options_".$key]);
1411 }
1412 }
1413
1414 $result = $object->updateline(
1415 GETPOST('lineid', 'int'),
1416 $label,
1417 $up,
1418 $tva_tx,
1419 $localtax1_tx,
1420 $localtax2_tx,
1421 price2num(GETPOST('qty'), 'MS'),
1422 GETPOST('productid', 'int'),
1423 $price_base_type,
1424 $info_bits,
1425 $type,
1426 $remise_percent,
1427 0,
1428 $date_start,
1429 $date_end,
1430 $array_options,
1431 GETPOST('units', 'alpha'),
1432 $pu_devise,
1433 GETPOST('fourn_ref', 'alpha')
1434 );
1435 if ($result >= 0) {
1436 unset($_POST['label']);
1437 unset($_POST['fourn_ref']);
1438 unset($_POST['date_starthour']);
1439 unset($_POST['date_startmin']);
1440 unset($_POST['date_startsec']);
1441 unset($_POST['date_startday']);
1442 unset($_POST['date_startmonth']);
1443 unset($_POST['date_startyear']);
1444 unset($_POST['date_endhour']);
1445 unset($_POST['date_endmin']);
1446 unset($_POST['date_endsec']);
1447 unset($_POST['date_endday']);
1448 unset($_POST['date_endmonth']);
1449 unset($_POST['date_endyear']);
1450 unset($_POST['price_ttc']);
1451 unset($_POST['price_ht']);
1452
1453 $db->commit();
1454 } else {
1455 $db->rollback();
1456 setEventMessages($object->error, $object->errors, 'errors');
1457 }
1458 } elseif ($action == 'addline' && GETPOST('submitforalllines', 'aZ09') && GETPOST('vatforalllines', 'alpha') && $usercancreate) {
1459 // Define vat_rate
1460 $vat_rate = (GETPOST('vatforalllines') ? GETPOST('vatforalllines') : 0);
1461 $vat_rate = str_replace('*', '', $vat_rate);
1462 $localtax1_rate = get_localtax($vat_rate, 1, $object->thirdparty, $mysoc);
1463 $localtax2_rate = get_localtax($vat_rate, 2, $object->thirdparty, $mysoc);
1464 foreach ($object->lines as $line) {
1465 $result = $object->updateline($line->id, $line->desc, $line->subprice, $vat_rate, $localtax1_rate, $localtax2_rate, $line->qty, $line->fk_product, 'HT', $line->info_bits, $line->product_type, $line->remise_percent, 0, $line->date_start, $line->date_end, $line->array_options, $line->fk_unit, $line->multicurrency_subprice, $line->ref_supplier, $line->rang);
1466 }
1467 } elseif ($action == 'addline' && $usercancreate) {
1468 // Add a product line
1469 $db->begin();
1470
1471 $ret = $object->fetch($id);
1472 if ($ret < 0) {
1473 dol_print_error($db, $object->error);
1474 exit;
1475 }
1476 $ret = $object->fetch_thirdparty();
1477
1478 $langs->load('errors');
1479 $error = 0;
1480
1481 // Set if we used free entry or predefined product
1482 $predef = '';
1483 $product_desc = (GETPOSTISSET('dp_desc') ? GETPOST('dp_desc', 'restricthtml') : '');
1484 $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'));
1485 $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'));
1486
1487 $prod_entry_mode = GETPOST('prod_entry_mode');
1488 if ($prod_entry_mode == 'free') {
1489 $idprod = 0;
1490 } else {
1491 $idprod = GETPOST('idprod', 'int');
1492 }
1493
1494 $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); // Can be '1.2' or '1.2 (CODE)'
1495
1496 $price_ht = price2num(GETPOST('price_ht'), 'MU', 2);
1497 $price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU', 2);
1498 $price_ttc = price2num(GETPOST('price_ttc'), 'MU', 2);
1499 $price_ttc_devise = price2num(GETPOST('multicurrency_price_ttc'), 'CU', 2);
1500 $qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS');
1501
1502 $remise_percent = (GETPOSTISSET('remise_percent'.$predef) ? price2num(GETPOST('remise_percent'.$predef, 'alpha'), '', 2) : 0);
1503 if (empty($remise_percent)) {
1504 $remise_percent = 0;
1505 }
1506
1507 // Extrafields
1508 $extralabelsline = $extrafields->fetch_name_optionals_label($object->table_element_line);
1509 $array_options = $extrafields->getOptionalsFromPost($object->table_element_line, $predef);
1510 // Unset extrafield
1511 if (is_array($extralabelsline)) {
1512 // Get extra fields
1513 foreach ($extralabelsline as $key => $value) {
1514 unset($_POST["options_".$key]);
1515 }
1516 }
1517
1518 if ($prod_entry_mode == 'free' && GETPOST('price_ht') < 0 && $qty < 0) {
1519 setEventMessages($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPrice'), $langs->transnoentitiesnoconv('Qty')), null, 'errors');
1520 $error++;
1521 }
1522 if ($prod_entry_mode == 'free' && !GETPOST('idprodfournprice') && GETPOST('type') < 0) {
1523 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), null, 'errors');
1524 $error++;
1525 }
1526 if ($prod_entry_mode == 'free' && GETPOST('price_ht') === '' && GETPOST('price_ttc') === '' && $price_ht_devise === '') { // Unit price can be 0 but not ''
1527 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('UnitPrice')), null, 'errors');
1528 $error++;
1529 }
1530 if ($prod_entry_mode == 'free' && !GETPOST('dp_desc')) {
1531 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), null, 'errors');
1532 $error++;
1533 }
1534 if (!GETPOST('qty', 'alpha')) { // 0 is NOT allowed for invoices
1535 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
1536 $error++;
1537 }
1538
1539 if (!$error && isModEnabled('variants') && $prod_entry_mode != 'free') {
1540 if ($combinations = GETPOST('combinations', 'array')) {
1541 //Check if there is a product with the given combination
1542 $prodcomb = new ProductCombination($db);
1543
1544 if ($res = $prodcomb->fetchByProductCombination2ValuePairs($idprod, $combinations)) {
1545 $idprod = $res->fk_product_child;
1546 } else {
1547 setEventMessages($langs->trans('ErrorProductCombinationNotFound'), null, 'errors');
1548 $error++;
1549 }
1550 }
1551 }
1552
1553 if ($prod_entry_mode != 'free' && empty($error)) { // With combolist mode idprodfournprice is > 0 or -1. With autocomplete, idprodfournprice is > 0 or ''
1554 $productsupplier = new ProductFournisseur($db);
1555
1556 $idprod = 0;
1557 if (GETPOST('idprodfournprice', 'alpha') == -1 || GETPOST('idprodfournprice', 'alpha') == '') {
1558 $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, ...)
1559 }
1560
1561 $reg = array();
1562 if (preg_match('/^idprod_([0-9]+)$/', GETPOST('idprodfournprice', 'alpha'), $reg)) {
1563 $idprod = $reg[1];
1564 $res = $productsupplier->fetch($idprod); // Load product from its id
1565 // Call to init some price properties of $productsupplier
1566 // So if a supplier price already exists for another thirdparty (first one found), we use it as reference price
1567 if (!empty($conf->global->SUPPLIER_TAKE_FIRST_PRICE_IF_NO_PRICE_FOR_CURRENT_SUPPLIER)) {
1568 $fksoctosearch = 0;
1569 $productsupplier->get_buyprice(0, -1, $idprod, 'none', $fksoctosearch); // We force qty to -1 to be sure to find if a supplier price exist
1570 if ($productsupplier->fourn_socid != $socid) { // The price we found is for another supplier, so we clear supplier price
1571 $productsupplier->ref_supplier = '';
1572 }
1573 } else {
1574 $fksoctosearch = $object->thirdparty->id;
1575 $productsupplier->get_buyprice(0, -1, $idprod, 'none', $fksoctosearch); // We force qty to -1 to be sure to find if a supplier price exist
1576 }
1577 } elseif (GETPOST('idprodfournprice', 'alpha') > 0) {
1578 $qtytosearch = $qty; // Just to see if a price exists for the quantity. Not used to found vat.
1579 //$qtytosearch=-1; // We force qty to -1 to be sure to find if a supplier price exist
1580 $idprod = $productsupplier->get_buyprice(GETPOST('idprodfournprice', 'alpha'), $qtytosearch);
1581 $res = $productsupplier->fetch($idprod);
1582 }
1583
1584 if ($idprod > 0) {
1585 $label = $productsupplier->label;
1586 // Define output language
1587 if (getDolGlobalInt('MAIN_MULTILANGS') && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
1588 $outputlangs = $langs;
1589 $newlang = '';
1590 if (empty($newlang) && GETPOST('lang_id', 'aZ09')) {
1591 $newlang = GETPOST('lang_id', 'aZ09');
1592 }
1593 if (empty($newlang)) {
1594 $newlang = $object->thirdparty->default_lang;
1595 }
1596 if (!empty($newlang)) {
1597 $outputlangs = new Translate("", $conf);
1598 $outputlangs->setDefaultLang($newlang);
1599 }
1600 $desc = (!empty($productsupplier->multilangs[$outputlangs->defaultlang]["description"])) ? $productsupplier->multilangs[$outputlangs->defaultlang]["description"] : $productsupplier->description;
1601 } else {
1602 $desc = $productsupplier->description;
1603 }
1604 // if we use supplier description of the products
1605 if (!empty($productsupplier->desc_supplier) && !empty($conf->global->PRODUIT_FOURN_TEXTS)) {
1606 $desc = $productsupplier->desc_supplier;
1607 }
1608
1609 //If text set in desc is the same as product descpription (as now it's preloaded) whe add it only one time
1610 if (trim($product_desc) == trim($desc) && !empty($conf->global->PRODUIT_AUTOFILL_DESC)) {
1611 $product_desc = '';
1612 }
1613 if (!empty($product_desc) && !empty($conf->global->MAIN_NO_CONCAT_DESCRIPTION)) {
1614 $desc = $product_desc;
1615 }
1616 if (!empty($product_desc) && trim($product_desc) != trim($desc)) {
1617 $desc = dol_concatdesc($desc, $product_desc, '', !empty($conf->global->MAIN_CHANGE_ORDER_CONCAT_DESCRIPTION));
1618 }
1619
1620 $ref_supplier = $productsupplier->ref_supplier;
1621
1622 // Get vat rate
1623 if (!GETPOSTISSET('tva_tx')) { // If vat rate not provided from the form (the form has the priority)
1624 $tva_tx = get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice', 'alpha'));
1625 $tva_npr = get_default_npr($object->thirdparty, $mysoc, $productsupplier->id, GETPOST('idprodfournprice', 'alpha'));
1626 }
1627 if (empty($tva_tx)) {
1628 $tva_npr = 0;
1629 }
1630 $localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $object->thirdparty, $tva_npr);
1631 $localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $object->thirdparty, $tva_npr);
1632
1633 $type = $productsupplier->type;
1634 if (GETPOST('price_ht') != '' || GETPOST('multicurrency_price_ht') != '') {
1635 $price_base_type = 'HT';
1636 $pu = price2num($price_ht, 'MU');
1637 $pu_devise = price2num($price_ht_devise, 'CU');
1638 } elseif (GETPOST('price_ttc') != '' || GETPOST('multicurrency_price_ttc') != '') {
1639 $price_base_type = 'TTC';
1640 $pu = price2num($price_ttc, 'MU');
1641 $pu_devise = price2num($price_ttc_devise, 'CU');
1642 } else {
1643 $price_base_type = ($productsupplier->fourn_price_base_type ? $productsupplier->fourn_price_base_type : 'HT');
1644 if (empty($object->multicurrency_code) || ($productsupplier->fourn_multicurrency_code != $object->multicurrency_code)) { // If object is in a different currency and price not in this currency
1645 $pu = $productsupplier->fourn_pu;
1646 $pu_devise = 0;
1647 } else {
1648 $pu = $productsupplier->fourn_pu;
1649 $pu_devise = $productsupplier->fourn_multicurrency_unitprice;
1650 }
1651 }
1652
1653 $ref_supplier = $productsupplier->ref_supplier;
1654
1655 if (empty($pu)) {
1656 $pu = 0; // If pu is '' or null, we force to have a numeric value
1657 }
1658
1659 $result = $object->addline(
1660 $desc,
1661 $pu,
1662 $tva_tx,
1663 $localtax1_tx,
1664 $localtax2_tx,
1665 $qty,
1666 $idprod,
1667 $remise_percent,
1668 $date_start,
1669 $date_end,
1670 0,
1671 $tva_npr,
1672 $price_base_type,
1673 $type,
1674 min($rank, count($object->lines) + 1),
1675 0,
1676 $array_options,
1677 $productsupplier->fk_unit,
1678 0,
1679 $pu_devise,
1680 GETPOST('fourn_ref', 'alpha'),
1681 ''
1682 );
1683 }
1684 if ($idprod == -99 || $idprod == 0) {
1685 // Product not selected
1686 $error++;
1687 $langs->load("errors");
1688 setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("ProductOrService")), null, 'errors');
1689 }
1690 if ($idprod == -1) {
1691 // Quantity too low
1692 $error++;
1693 $langs->load("errors");
1694 setEventMessages($langs->trans("ErrorQtyTooLowForThisSupplier"), null, 'errors');
1695 }
1696 } elseif (empty($error)) { // $price_ht is already set
1697 $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0);
1698 $tva_tx = str_replace('*', '', $tva_tx);
1699 $label = (GETPOST('product_label') ? GETPOST('product_label') : '');
1700 $desc = $product_desc;
1701 $type = GETPOST('type');
1702 $ref_supplier = GETPOST('fourn_ref', 'alpha');
1703
1704 $fk_unit = GETPOST('units', 'alpha');
1705
1706 if (!preg_match('/\‍((.*)\‍)/', $tva_tx)) {
1707 $tva_tx = price2num($tva_tx); // $txtva can have format '5,1' or '5.1' or '5.1(XXX)', we must clean only if '5,1'
1708 }
1709
1710 // Local Taxes
1711 $localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
1712 $localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
1713
1714 if (GETPOST('price_ht') != '' || GETPOST('multicurrency_price_ht') != '') {
1715 $pu_ht = price2num($price_ht, 'MU'); // $pu_ht must be rounded according to settings
1716 } else {
1717 $pu_ttc = price2num(GETPOST('price_ttc'), 'MU');
1718 $pu_ht = price2num($pu_ttc / (1 + ($tva_tx / 100)), 'MU'); // $pu_ht must be rounded according to settings
1719 }
1720 $price_base_type = 'HT';
1721 $pu_devise = price2num($price_ht_devise, 'CU');
1722
1723 $result = $object->addline($product_desc, $pu_ht, $tva_tx, $localtax1_tx, $localtax2_tx, $qty, 0, $remise_percent, $date_start, $date_end, 0, $tva_npr, $price_base_type, $type, -1, 0, $array_options, $fk_unit, 0, $pu_devise, $ref_supplier);
1724 }
1725
1726 //print "xx".$tva_tx; exit;
1727 if (!$error && $result > 0) {
1728 $db->commit();
1729
1730 // Define output language
1731 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1732 $outputlangs = $langs;
1733 $newlang = '';
1734 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
1735 $newlang = GETPOST('lang_id', 'aZ09');
1736 }
1737 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1738 $newlang = $object->thirdparty->default_lang;
1739 }
1740 if (!empty($newlang)) {
1741 $outputlangs = new Translate("", $conf);
1742 $outputlangs->setDefaultLang($newlang);
1743 }
1744 $model = $object->model_pdf;
1745 $ret = $object->fetch($id); // Reload to get new records
1746
1747 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1748 if ($result < 0) {
1749 dol_print_error($db, $result);
1750 }
1751 }
1752
1753 unset($_POST ['prod_entry_mode']);
1754
1755 unset($_POST['qty']);
1756 unset($_POST['type']);
1757 unset($_POST['remise_percent']);
1758 unset($_POST['pu']);
1759 unset($_POST['price_ht']);
1760 unset($_POST['multicurrency_price_ht']);
1761 unset($_POST['price_ttc']);
1762 unset($_POST['fourn_ref']);
1763 unset($_POST['tva_tx']);
1764 unset($_POST['label']);
1765 unset($localtax1_tx);
1766 unset($localtax2_tx);
1767 unset($_POST['np_marginRate']);
1768 unset($_POST['np_markRate']);
1769 unset($_POST['dp_desc']);
1770 unset($_POST['idprodfournprice']);
1771 unset($_POST['units']);
1772
1773 unset($_POST['date_starthour']);
1774 unset($_POST['date_startmin']);
1775 unset($_POST['date_startsec']);
1776 unset($_POST['date_startday']);
1777 unset($_POST['date_startmonth']);
1778 unset($_POST['date_startyear']);
1779 unset($_POST['date_endhour']);
1780 unset($_POST['date_endmin']);
1781 unset($_POST['date_endsec']);
1782 unset($_POST['date_endday']);
1783 unset($_POST['date_endmonth']);
1784 unset($_POST['date_endyear']);
1785 } else {
1786 $db->rollback();
1787 setEventMessages($object->error, $object->errors, 'errors');
1788 }
1789
1790 $action = '';
1791 } elseif ($action == 'classin' && $usercancreate) {
1792 $object->fetch($id);
1793 $result = $object->setProject($projectid);
1794 } elseif ($action == 'confirm_edit' && $confirm == 'yes' && $usercancreate) {
1795 // Set invoice to draft status
1796 $object->fetch($id);
1797
1798 $totalpaid = $object->getSommePaiement();
1799 $resteapayer = $object->total_ttc - $totalpaid;
1800
1801 // We check that lines of invoices are exported in accountancy
1802 $ventilExportCompta = $object->getVentilExportCompta();
1803
1804 if (!$ventilExportCompta) {
1805 // On verifie si aucun paiement n'a ete effectue
1806 if ($resteapayer == price2num($object->total_ttc, 'MT', 1) && $object->statut == FactureFournisseur::STATUS_VALIDATED) {
1807 $idwarehouse = GETPOST('idwarehouse');
1808
1809 $object->fetch_thirdparty();
1810
1811 $qualified_for_stock_change = 0;
1812 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
1813 $qualified_for_stock_change = $object->hasProductsOrServices(2);
1814 } else {
1815 $qualified_for_stock_change = $object->hasProductsOrServices(1);
1816 }
1817
1818 // Check parameters
1819 if (isModEnabled('stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) {
1820 $langs->load("stocks");
1821 if (!$idwarehouse || $idwarehouse == -1) {
1822 $error++;
1823 setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
1824 $action = '';
1825 }
1826 }
1827
1828 $object->setDraft($user, $idwarehouse);
1829
1830 // Define output language
1831 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1832 $outputlangs = $langs;
1833 $newlang = '';
1834 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang) && GETPOST('lang_id', 'aZ09')) {
1835 $newlang = GETPOST('lang_id', 'aZ09');
1836 }
1837 if (getDolGlobalInt('MAIN_MULTILANGS') && empty($newlang)) {
1838 $newlang = $object->thirdparty->default_lang;
1839 }
1840 if (!empty($newlang)) {
1841 $outputlangs = new Translate("", $conf);
1842 $outputlangs->setDefaultLang($newlang);
1843 }
1844 $model = $object->model_pdf;
1845 $ret = $object->fetch($id); // Reload to get new records
1846
1847 $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1848 if ($result < 0) {
1849 dol_print_error($db, $result);
1850 }
1851 }
1852
1853 $action = '';
1854 }
1855 }
1856 } elseif ($action == 'reopen' && $usercancreate) {
1857 // Set invoice to validated/unpaid status
1858 $result = $object->fetch($id);
1859 if ($object->statut == FactureFournisseur::STATUS_CLOSED
1860 || ($object->statut == FactureFournisseur::STATUS_ABANDONED && $object->close_code != 'replaced')) {
1861 $result = $object->setUnpaid($user);
1862 if ($result > 0) {
1863 header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
1864 exit;
1865 } else {
1866 setEventMessages($object->error, $object->errors, 'errors');
1867 }
1868 }
1869 }
1870
1871 // Actions when printing a doc from card
1872 include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php';
1873
1874 // Actions to send emails
1875 $triggersendname = 'BILL_SUPPLIER_SENTBYMAIL';
1876 $paramname = 'id';
1877 $autocopy = 'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
1878 $trackid = 'sinv'.$object->id;
1879 include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
1880
1881 // Actions to build doc
1882 $upload_dir = $conf->fournisseur->facture->dir_output;
1883 $permissiontoadd = $usercancreate;
1884 include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
1885
1886 // Make calculation according to calculationrule
1887 if ($action == 'calculate') {
1888 $calculationrule = GETPOST('calculationrule');
1889
1890 $object->fetch($id);
1891 $object->fetch_thirdparty();
1892 $result = $object->update_price(0, (($calculationrule == 'totalofround') ? '0' : '1'), 0, $object->thirdparty);
1893 if ($result <= 0) {
1894 dol_print_error($db, $result);
1895 exit;
1896 }
1897 }
1898 if ($action == 'update_extras') {
1899 $object->oldcopy = dol_clone($object);
1900
1901 // Fill array 'array_options' with data from add form
1902 $ret = $extrafields->setOptionalsFromPost(null, $object, GETPOST('attribute', 'restricthtml'));
1903 if ($ret < 0) {
1904 $error++;
1905 }
1906
1907 if (!$error) {
1908 // Actions on extra fields
1909 if (!$error) {
1910 $result = $object->insertExtraFields('BILL_SUPPLIER_MODIFY');
1911 if ($result < 0) {
1912 $error++;
1913 }
1914 }
1915 }
1916
1917 if ($error) {
1918 $action = 'edit_extras';
1919 }
1920 }
1921
1922 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) {
1923 if ($action == 'addcontact') {
1924 $result = $object->fetch($id);
1925
1926 if ($result > 0 && $id > 0) {
1927 $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
1928 $typeid = (GETPOST('typecontact') ? GETPOST('typecontact') : GETPOST('type'));
1929 $result = $object->add_contact($contactid, $typeid, GETPOST("source", 'aZ09'));
1930 }
1931
1932 if ($result >= 0) {
1933 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
1934 exit;
1935 } else {
1936 if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
1937 $langs->load("errors");
1938 setEventMessages($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), null, 'errors');
1939 } else {
1940 setEventMessages($object->error, $object->errors, 'errors');
1941 }
1942 }
1943 } elseif ($action == 'swapstatut') {
1944 // bascule du statut d'un contact
1945 if ($object->fetch($id)) {
1946 $result = $object->swapContactStatus(GETPOST('ligne', 'int'));
1947 } else {
1948 dol_print_error($db);
1949 }
1950 } elseif ($action == 'deletecontact') {
1951 // Efface un contact
1952 $object->fetch($id);
1953 $result = $object->delete_contact(GETPOST("lineid", 'int'));
1954
1955 if ($result >= 0) {
1956 header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
1957 exit;
1958 } else {
1959 dol_print_error($db);
1960 }
1961 }
1962 }
1963}
1964
1965
1966/*
1967 * View
1968 */
1969
1970$form = new Form($db);
1971$formfile = new FormFile($db);
1972$bankaccountstatic = new Account($db);
1973$paymentstatic = new PaiementFourn($db);
1974if (isModEnabled('project')) {
1975 $formproject = new FormProjets($db);
1976}
1977
1978$now = dol_now();
1979
1980$title = $object->ref." - ".$langs->trans('Card');
1981if ($action == 'create') {
1982 $title = $langs->trans("NewSupplierInvoice");
1983}
1984$help_url = 'EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores|DE:Modul_Lieferantenrechnungen';
1985llxHeader('', $title, $help_url);
1986
1987// Mode creation
1988if ($action == 'create') {
1989 $facturestatic = new FactureFournisseur($db);
1990
1991 print load_fiche_titre($langs->trans('NewSupplierInvoice'), '', 'supplier_invoice');
1992
1994
1995 $currency_code = $conf->currency;
1996
1997 $societe = '';
1998 if (GETPOST('socid', 'int') > 0) {
1999 $societe = new Societe($db);
2000 $societe->fetch(GETPOST('socid', 'int'));
2001 if (isModEnabled("multicurrency") && !empty($societe->multicurrency_code)) {
2002 $currency_code = $societe->multicurrency_code;
2003 }
2004 }
2005
2006 if (!empty($origin) && !empty($originid)) {
2007 // Parse element/subelement (ex: project_task)
2008 $element = $subelement = $origin;
2009
2010 if ($element == 'project') {
2011 $projectid = $originid;
2012 $element = 'projet';
2013 }
2014
2015 // For compatibility
2016 if ($element == 'order') {
2017 $element = $subelement = 'commande';
2018 }
2019 if ($element == 'propal') {
2020 $element = 'comm/propal'; $subelement = 'propal';
2021 }
2022 if ($element == 'contract') {
2023 $element = $subelement = 'contrat';
2024 }
2025 if ($element == 'order_supplier') {
2026 $element = 'fourn'; $subelement = 'fournisseur.commande';
2027 }
2028
2029 require_once DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php';
2030 $classname = ucfirst($subelement);
2031 if ($classname == 'Fournisseur.commande') {
2032 $classname = 'CommandeFournisseur';
2033 }
2034 $objectsrc = new $classname($db);
2035 $objectsrc->fetch($originid);
2036 $objectsrc->fetch_thirdparty();
2037
2038 $projectid = (!empty($objectsrc->fk_project) ? $objectsrc->fk_project : '');
2039 //$ref_client = (!empty($objectsrc->ref_client)?$object->ref_client:'');
2040 $soc = $objectsrc->thirdparty;
2041
2042 $cond_reglement_id = 0;
2043 $mode_reglement_id = 0;
2044 $fk_account = 0;
2045 $remise_percent = 0;
2046 $remise_absolue = 0;
2047 $transport_mode_id = 0;
2048
2049 // set from object source
2050 if (!empty($objectsrc->cond_reglement_id)) {
2051 $cond_reglement_id = $objectsrc->cond_reglement_id;
2052 }
2053 if (!empty($objectsrc->mode_reglement_id)) {
2054 $mode_reglement_id = $objectsrc->mode_reglement_id;
2055 }
2056 if (!empty($objectsrc->fk_account)) {
2057 $fk_account = $objectsrc->fk_account;
2058 }
2059 if (!empty($objectsrc->remise_percent)) {
2060 $remise_percent = $objectsrc->remise_percent;
2061 }
2062 if (!empty($objectsrc->remise_absolue)) {
2063 $remise_absolue = $objectsrc->remise_absolue;
2064 }
2065 if (!empty($objectsrc->transport_mode_id)) {
2066 $transport_mode_id = $objectsrc->transport_mode_id;
2067 }
2068
2069 if (empty($cond_reglement_id)
2070 || empty($mode_reglement_id)
2071 || empty($fk_account)
2072 || empty($remise_percent)
2073 || empty($remise_absolue)
2074 || empty($transport_mode_id)
2075 ) {
2076 if ($origin == 'reception') {
2077 // try to get from source of reception (supplier order)
2078 if (!isset($objectsrc->supplier_order)) {
2079 $objectsrc->fetch_origin();
2080 }
2081
2082 if (!empty($objectsrc->commandeFournisseur)) {
2083 $supplierOrder = $objectsrc->commandeFournisseur;
2084 if (empty($cond_reglement_id) && !empty($supplierOrder->cond_reglement_id)) {
2085 $cond_reglement_id = $supplierOrder->cond_reglement_id;
2086 }
2087 if (empty($mode_reglement_id) && !empty($supplierOrder->mode_reglement_id)) {
2088 $mode_reglement_id = $supplierOrder->mode_reglement_id;
2089 }
2090 if (empty($fk_account) && !empty($supplierOrder->fk_account)) {
2091 $fk_account = $supplierOrder->fk_account;
2092 }
2093 if (empty($remise_percent) && !empty($supplierOrder->remise_percent)) {
2094 $remise_percent = $supplierOrder->remise_percent;
2095 }
2096 if (empty($remise_absolue) && !empty($supplierOrder->remise_absolue)) {
2097 $remise_absolue = $supplierOrder->remise_absolue;
2098 }
2099 if (empty($transport_mode_id) && !empty($supplierOrder->transport_mode_id)) {
2100 $transport_mode_id = $supplierOrder->transport_mode_id;
2101 }
2102 }
2103 }
2104
2105 // try to get from third-party of source object
2106 if (!empty($soc)) {
2107 if (empty($cond_reglement_id) && !empty($soc->cond_reglement_supplier_id)) {
2108 $cond_reglement_id = $soc->cond_reglement_supplier_id;
2109 }
2110 if (empty($mode_reglement_id) && !empty($soc->mode_reglement_supplier_id)) {
2111 $mode_reglement_id = $soc->mode_reglement_supplier_id;
2112 }
2113 if (empty($fk_account) && !empty($soc->fk_account)) {
2114 $fk_account = $soc->fk_account;
2115 }
2116 if (empty($remise_percent) && !empty($soc->remise_supplier_percent)) {
2117 $remise_percent = $soc->remise_supplier_percent;
2118 }
2119 if (empty($remise_absolue) && !empty($soc->remise_absolue)) {
2120 $remise_absolue = $soc->remise_absolue;
2121 }
2122 if (empty($transport_mode_id) && !empty($soc->transport_mode_id)) {
2123 $transport_mode_id = $soc->transport_mode_id;
2124 }
2125 }
2126 }
2127
2128 if (isModEnabled("multicurrency")) {
2129 if (!empty($objectsrc->multicurrency_code)) {
2130 $currency_code = $objectsrc->multicurrency_code;
2131 }
2132 if (!empty($conf->global->MULTICURRENCY_USE_ORIGIN_TX) && !empty($objectsrc->multicurrency_tx)) {
2133 $currency_tx = $objectsrc->multicurrency_tx;
2134 }
2135 }
2136
2137 $datetmp = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
2138 $dateinvoice = ($datetmp == '' ? (empty($conf->global->MAIN_AUTOFILL_DATE) ? -1 : '') : $datetmp);
2139 $datetmp = dol_mktime(12, 0, 0, GETPOST('echmonth', 'int'), GETPOST('echday', 'int'), GETPOST('echyear', 'int'));
2140 $datedue = ($datetmp == '' ?-1 : $datetmp);
2141
2142 // Replicate extrafields
2143 $objectsrc->fetch_optionals();
2144 $object->array_options = $objectsrc->array_options;
2145 } else {
2146 $cond_reglement_id = !empty($societe->cond_reglement_supplier_id) ? $societe->cond_reglement_supplier_id : 0;
2147 $mode_reglement_id = !empty($societe->mode_reglement_supplier_id) ? $societe->mode_reglement_supplier_id : 0;
2148 $vat_reverse_charge = $societe->vat_reverse_charge;
2149 $transport_mode_id = !empty($societe->transport_mode_supplier_id) ? $societe->transport_mode_supplier_id : 0;
2150 $fk_account = !empty($societe->fk_account) ? $societe->fk_account : 0;
2151 $datetmp = dol_mktime(12, 0, 0, GETPOST('remonth', 'int'), GETPOST('reday', 'int'), GETPOST('reyear', 'int'));
2152 $dateinvoice = ($datetmp == '' ? (empty($conf->global->MAIN_AUTOFILL_DATE) ?-1 : '') : $datetmp);
2153 $datetmp = dol_mktime(12, 0, 0, GETPOST('echmonth', 'int'), GETPOST('echday', 'int'), GETPOST('echyear', 'int'));
2154 $datedue = ($datetmp == '' ?-1 : $datetmp);
2155
2156 if (isModEnabled("multicurrency") && !empty($soc->multicurrency_code)) {
2157 $currency_code = $soc->multicurrency_code;
2158 }
2159 }
2160
2161 // when payment condition is empty (means not override by payment condition form a other object, like third-party), try to use default value
2162 if (empty($cond_reglement_id)) {
2163 $cond_reglement_id = GETPOST("cond_reglement_id");
2164 }
2165
2166 // when payment mode is empty (means not override by payment condition form a other object, like third-party), try to use default value
2167 if (empty($mode_reglement_id)) {
2168 $mode_reglement_id = GETPOST("mode_reglement_id");
2169 }
2170
2171 $note_public = $object->getDefaultCreateValueFor('note_public', ((!empty($origin) && !empty($originid) && is_object($objectsrc) && !empty($conf->global->FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM)) ? $objectsrc->note_public : null));
2172 $note_private = $object->getDefaultCreateValueFor('note_private', ((!empty($origin) && !empty($originid) && is_object($objectsrc) && !empty($conf->global->FACTUREFOURN_REUSE_NOTES_ON_CREATE_FROM)) ? $objectsrc->note_private : null));
2173
2174 print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" method="post">';
2175 print '<input type="hidden" name="token" value="'.newToken().'">';
2176 print '<input type="hidden" name="action" value="add">';
2177 if (!empty($societe->id) && $societe->id > 0) {
2178 print '<input type="hidden" name="socid" value="'.$societe->id.'">'."\n";
2179 }
2180 print '<input type="hidden" name="origin" value="'.$origin.'">';
2181 print '<input type="hidden" name="originid" value="'.$originid.'">';
2182 if (!empty($currency_tx)) {
2183 print '<input type="hidden" name="originmulticurrency_tx" value="'.$currency_tx.'">';
2184 }
2185 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
2186
2187 print dol_get_fiche_head();
2188
2189 print '<table class="border centpercent">';
2190
2191 // Ref
2192 print '<tr><td class="titlefieldcreate">'.$langs->trans('Ref').'</td><td>'.$langs->trans('Draft').'</td></tr>';
2193
2194 $exampletemplateinvoice = new FactureFournisseurRec($db);
2195 $invoice_predefined = new FactureFournisseurRec($db);
2196 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2197 $invoice_predefined->fetch($fac_recid);
2198 }
2199
2200 // Third party
2201 print '<tr><td class="fieldrequired">'.$langs->trans('Supplier').'</td>';
2202 print '<td>';
2203
2204 if (!empty($societe->id) && $societe->id > 0 && ($fac_recid <= 0 || !empty($invoice_predefined->frequency))) {
2205 $absolute_discount = $societe->getAvailableDiscounts('', '', 0, 1);
2206 print $societe->getNomUrl(1, 'supplier');
2207 print '<input type="hidden" name="socid" value="'.$societe->id.'">';
2208 } else {
2209 $filter = '((s.fournisseur:=:1) AND (s.status:=:1))';
2210 print img_picto('', 'company', 'class="pictofixedwidth"').$form->select_company(empty($societe->id) ? 0 : $societe->id, 'socid', $filter, 'SelectThirdParty', 1, 0, null, 0, 'minwidth175 widthcentpercentminusxx maxwidth500');
2211 // reload page to retrieve supplier informations
2212 if (empty($conf->global->RELOAD_PAGE_ON_SUPPLIER_CHANGE_DISABLED)) {
2213 print '<script type="text/javascript">
2214 $(document).ready(function() {
2215 $("#socid").change(function() {
2216 console.log("We have changed the company - Reload page");
2217 // reload page
2218 $("input[name=action]").val("create");
2219 $("form[name=add]").submit();
2220 });
2221 });
2222 </script>';
2223 }
2224 if ($fac_recid <= 0) {
2225 print ' <a href="'.DOL_URL_ROOT.'/societe/card.php?action=create&client=0&fournisseur=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create').'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddThirdParty").'"></span></a>';
2226 }
2227 }
2228 print '</td></tr>';
2229
2230 // Overwrite some values if creation of invoice is from a predefined invoice
2231 if (empty($origin) && empty($originid) && $fac_recid > 0) {
2232 $invoice_predefined->fetch($fac_recid);
2233
2234 $dateinvoice = $invoice_predefined->date_when; // To use next gen date by default later
2235 if (empty($projectid)) {
2236 $projectid = $invoice_predefined->fk_project;
2237 }
2238 $cond_reglement_id = $invoice_predefined->cond_reglement_id;
2239 $mode_reglement_id = $invoice_predefined->mode_reglement_id;
2240 $fk_account = $invoice_predefined->fk_account;
2241 $note_public = $invoice_predefined->note_public;
2242 $note_private = $invoice_predefined->note_private;
2243
2244 if (!empty($invoice_predefined->multicurrency_code)) {
2245 $currency_code = $invoice_predefined->multicurrency_code;
2246 }
2247 if (!empty($invoice_predefined->multicurrency_tx)) {
2248 $currency_tx = $invoice_predefined->multicurrency_tx;
2249 }
2250
2251 $sql = 'SELECT r.rowid, r.titre as title, r.total_ttc';
2252 $sql .= ' FROM '.MAIN_DB_PREFIX.'facture_fourn_rec as r';
2253 $sql .= ' WHERE r.fk_soc = '. (int) $invoice_predefined->socid;
2254
2255 $resql = $db->query($sql);
2256 if ($resql) {
2257 $num = $db->num_rows($resql);
2258 $i = 0;
2259
2260 if ($num > 0) {
2261 print '<tr><td>'.$langs->trans('CreateFromRepeatableInvoice').'</td><td>';
2262 //print '<input type="hidden" name="fac_rec" id="fac_rec" value="'.$fac_recid.'">';
2263 print '<select class="flat" id="fac_rec" name="fac_rec">'; // We may want to change the template to use
2264 print '<option value="0" selected></option>';
2265 while ($i < $num) {
2266 $objp = $db->fetch_object($resql);
2267 print '<option value="'.$objp->rowid.'"';
2268 if ($fac_recid == $objp->rowid) {
2269 print ' selected';
2270 $exampletemplateinvoice->fetch($fac_recid);
2271 }
2272 print '>'.$objp->title.' ('.price($objp->total_ttc).' '.$langs->trans("TTC").')</option>';
2273 $i++;
2274 }
2275 print '</select>';
2276 // Option to reload page to retrieve customer informations. Note, this clear other input
2277 if (empty($conf->global->RELOAD_PAGE_ON_TEMPLATE_CHANGE_DISABLED)) {
2278 print '<script type="text/javascript">
2279 $(document).ready(function() {
2280 $("#fac_rec").change(function() {
2281 console.log("We have changed the template invoice - Reload page");
2282 // reload page
2283 $("input[name=action]").val("create");
2284 $("form[name=add]").submit();
2285 });
2286 });
2287 </script>';
2288 }
2289 print '</td></tr>';
2290 }
2291 $db->free($resql);
2292 } else {
2293 dol_print_error($db);
2294 }
2295 }
2296
2297 // Ref supplier
2298 print '<tr><td class="fieldrequired">'.$langs->trans('RefSupplier').'</td><td><input name="ref_supplier" value="'.(GETPOSTISSET('ref_supplier') ? GETPOST('ref_supplier') : (!empty($objectsrc->ref_supplier) ? $objectsrc->ref_supplier : '')).'" type="text"';
2299 if (!empty($societe->id) && $societe->id > 0) {
2300 print ' autofocus';
2301 }
2302 print '></td>';
2303 print '</tr>';
2304
2305 print '<tr><td class="tdtop fieldrequired">'.$langs->trans('Type').'</td><td>';
2306
2307 print '<div class="tagtable">'."\n";
2308
2309 // Standard invoice
2310 print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2311 $tmp = '<input type="radio" id="radio_standard" name="type" value="0"'.(GETPOST('type', 'int')? '' : 'checked').'> ';
2312 $desc = $form->textwithpicto($tmp.'<label for="radio_standard">'.$langs->trans("InvoiceStandardAsk").'</label>', $langs->transnoentities("InvoiceStandardDesc"), 1, 'help', '', 0, 3);
2313 print $desc;
2314 print '</div></div>';
2315
2316 if (empty($origin) || ($origin == 'order_supplier' && !empty($originid))) {
2317 // Deposit - Down payment
2318 if (empty($conf->global->INVOICE_DISABLE_DEPOSIT)) {
2319 print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2320 $tmp='<input type="radio" id="radio_deposit" name="type" value="3"' . (GETPOST('type') == 3 ? ' checked' : '') . '> ';
2321 print '<script type="text/javascript">
2322 jQuery(document).ready(function() {
2323 jQuery("#typestandardinvoice, #valuestandardinvoice").click(function() {
2324 jQuery("#radio_standard").prop("checked", true);
2325 });
2326 jQuery("#typedeposit, #valuedeposit").click(function() {
2327 jQuery("#radio_deposit").prop("checked", true);
2328 });
2329 jQuery("#typedeposit").change(function() {
2330 console.log("We change type of down payment");
2331 jQuery("#radio_deposit").prop("checked", true);
2332 setRadioForTypeOfInvoice();
2333 });
2334 jQuery("#radio_standard, #radio_deposit, #radio_replacement, #radio_template").change(function() {
2335 setRadioForTypeOfInvoice();
2336 });
2337 function setRadioForTypeOfInvoice() {
2338 console.log("Change radio");
2339 if (jQuery("#radio_deposit").prop("checked") && (jQuery("#typedeposit").val() == \'amount\' || jQuery("#typedeposit").val() == \'variable\')) {
2340 jQuery(".checkforselect").prop("disabled", true);
2341 jQuery(".checkforselect").prop("checked", false);
2342 } else {
2343 jQuery(".checkforselect").prop("disabled", false);
2344 jQuery(".checkforselect").prop("checked", true);
2345 }
2346 }
2347 });
2348 </script>';
2349
2350 $tmp = $tmp.'<label for="radio_deposit" >'.$langs->trans("InvoiceDeposit").'</label>';
2351 $desc = $form->textwithpicto($tmp, $langs->transnoentities("InvoiceDepositDesc"), 1, 'help', '', 0, 3);
2352 print '<table class="nobordernopadding"><tr>';
2353 print '<td>';
2354 print $desc;
2355 print '</td>';
2356 if ($origin == 'order_supplier') {
2357 print '<td class="nowrap" style="padding-left: 15px">';
2358 $arraylist = array(
2359 'amount' => $langs->transnoentitiesnoconv('FixAmount', $langs->transnoentitiesnoconv('Deposit')),
2360 'variable' => $langs->transnoentitiesnoconv('VarAmountOneLine', $langs->transnoentitiesnoconv('Deposit')),
2361 'variablealllines' => $langs->transnoentitiesnoconv('VarAmountAllLines')
2362 );
2363 print $form->selectarray('typedeposit', $arraylist, GETPOST('typedeposit', 'aZ09'), 0, 0, 0, '', 1);
2364 print '</td>';
2365 print '<td class="nowrap" style="padding-left: 5px">';
2366 print '<span class="opacitymedium paddingleft">'.$langs->trans("AmountOrPercent").'</span><input type="text" id="valuedeposit" name="valuedeposit" class="width75 right" value="' . GETPOST('valuedeposit', 'int') . '"/>';
2367 print '</td>';
2368 }
2369 print '</tr></table>';
2370
2371 print '</div></div>';
2372 }
2373 }
2374
2375 /* Not yet supported for supplier
2376 if ($societe->id > 0)
2377 {
2378 // Replacement
2379 if (empty($conf->global->INVOICE_DISABLE_REPLACEMENT))
2380 {
2381 // Type invoice
2382 $facids = $facturestatic->list_replacable_supplier_invoices($societe->id);
2383 if ($facids < 0) {
2384 dol_print_error($db, $facturestatic->error, $facturestatic->errors);
2385 exit();
2386 }
2387 $options = "";
2388 foreach ($facids as $facparam)
2389 {
2390 $options .= '<option value="' . $facparam ['id'] . '"';
2391 if ($facparam ['id'] == GETPOST('fac_replacement') {
2392 $options .= ' selected';
2393 }
2394 $options .= '>' . $facparam ['ref'];
2395 $options .= ' (' . $facturestatic->LibStatut(0, $facparam ['status']) . ')';
2396 $options .= '</option>';
2397 }
2398
2399 print '<!-- replacement line -->';
2400 print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2401 $tmp='<input type="radio" name="type" id="radio_replacement" value="1"' . (GETPOST('type') == 1 ? ' checked' : '');
2402 if (! $options) $tmp.=' disabled';
2403 $tmp.='> ';
2404 print '<script type="text/javascript">
2405 jQuery(document).ready(function() {
2406 jQuery("#fac_replacement").change(function() {
2407 jQuery("#radio_replacement").prop("checked", true);
2408 });
2409 });
2410 </script>';
2411 $text = $tmp.$langs->trans("InvoiceReplacementAsk") . ' ';
2412 $text .= '<select class="flat" name="fac_replacement" id="fac_replacement"';
2413 if (! $options)
2414 $text .= ' disabled';
2415 $text .= '>';
2416 if ($options) {
2417 $text .= '<option value="-1">&nbsp;</option>';
2418 $text .= $options;
2419 } else {
2420 $text .= '<option value="-1">' . $langs->trans("NoReplacableInvoice") . '</option>';
2421 }
2422 $text .= '</select>';
2423 $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceReplacementDesc"), 1, 'help', '', 0, 3);
2424 print $desc;
2425 print '</div></div>';
2426 }
2427 }
2428 else
2429 {
2430 print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2431 $tmp='<input type="radio" name="type" id="radio_replacement" value="0" disabled> ';
2432 $text = $tmp.$langs->trans("InvoiceReplacement") . ' ';
2433 $text.= '('.$langs->trans("YouMustCreateInvoiceFromSupplierThird").') ';
2434 $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceReplacementDesc"), 1, 'help', '', 0, 3);
2435 print $desc;
2436 print '</div></div>';
2437 }
2438 */
2439
2440 if (empty($origin)) {
2441 if (!empty($societe->id) && $societe->id > 0) {
2442 // Credit note
2443 if (empty($conf->global->INVOICE_DISABLE_CREDIT_NOTE)) {
2444 // Show link for credit note
2445 $facids = $facturestatic->list_qualified_avoir_supplier_invoices($societe->id);
2446 if ($facids < 0) {
2447 dol_print_error($db, $facturestatic->error, $facturestatic->errors);
2448 exit;
2449 }
2450 $optionsav = "";
2451 $newinvoice_static = new FactureFournisseur($db);
2452 foreach ($facids as $key => $valarray) {
2453 $newinvoice_static->id = $key;
2454 $newinvoice_static->ref = $valarray ['ref'];
2455 $newinvoice_static->statut = $valarray ['status'];
2456 $newinvoice_static->type = $valarray ['type'];
2457 $newinvoice_static->paye = $valarray ['paye'];
2458
2459 $optionsav .= '<option value="'.$key.'"';
2460 if ($key == GETPOST('fac_avoir', 'int')) {
2461 $optionsav .= ' selected';
2462 }
2463 $optionsav .= '>';
2464 $optionsav .= $newinvoice_static->ref;
2465 $optionsav .= ' ('.$newinvoice_static->getLibStatut(1, $valarray ['paymentornot']).')';
2466 $optionsav .= '</option>';
2467 }
2468
2469 print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2470 $tmp = '<input type="radio" id="radio_creditnote" name="type" value="2"'.(GETPOST('type') == 2 ? ' checked' : '');
2471 if (!$optionsav && empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) {
2472 $tmp .= ' disabled';
2473 }
2474 $tmp .= '> ';
2475 // Show credit note options only if we checked credit note
2476 print '<script type="text/javascript">
2477 jQuery(document).ready(function() {
2478 if (! jQuery("#radio_creditnote").is(":checked"))
2479 {
2480 jQuery("#credit_note_options").hide();
2481 }
2482 jQuery("#radio_creditnote").click(function() {
2483 jQuery("#credit_note_options").show();
2484 });
2485 jQuery("#radio_standard, #radio_replacement, #radio_deposit").click(function() {
2486 jQuery("#credit_note_options").hide();
2487 });
2488 });
2489 </script>';
2490 $text = $tmp.'<label for="radio_creditnote">'.$langs->transnoentities("InvoiceAvoirAsk").'</label> ';
2491 // $text.='<input type="text" value="">';
2492 $text .= '<select class="flat valignmiddle" name="fac_avoir" id="fac_avoir"';
2493 if (!$optionsav) {
2494 $text .= ' disabled';
2495 }
2496 $text .= '>';
2497 if ($optionsav) {
2498 $text .= '<option value="-1"></option>';
2499 $text .= $optionsav;
2500 } else {
2501 $text .= '<option value="-1">'.$langs->trans("NoInvoiceToCorrect").'</option>';
2502 }
2503 $text .= '</select>';
2504 $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc"), 1, 'help', '', 0, 3);
2505 print $desc;
2506
2507 print '<div id="credit_note_options" class="clearboth">';
2508 print '&nbsp;&nbsp;&nbsp; <input type="checkbox" name="invoiceAvoirWithLines" id="invoiceAvoirWithLines" value="1" onclick="if($(this).is(\':checked\') ) { $(\'#radio_creditnote\').prop(\'checked\', true); $(\'#invoiceAvoirWithPaymentRestAmount\').removeAttr(\'checked\'); }" '.(GETPOST('invoiceAvoirWithLines', 'int') > 0 ? 'checked' : '').' /> ';
2509 print '<label for="invoiceAvoirWithLines">'.$langs->trans('invoiceAvoirWithLines')."</label>";
2510 print '<br>&nbsp;&nbsp;&nbsp; <input type="checkbox" name="invoiceAvoirWithPaymentRestAmount" id="invoiceAvoirWithPaymentRestAmount" value="1" onclick="if($(this).is(\':checked\') ) { $(\'#radio_creditnote\').prop(\'checked\', true); $(\'#invoiceAvoirWithLines\').removeAttr(\'checked\'); }" '.(GETPOST('invoiceAvoirWithPaymentRestAmount', 'int') > 0 ? 'checked' : '').' /> ';
2511 print '<label for="invoiceAvoirWithPaymentRestAmount">'.$langs->trans('invoiceAvoirWithPaymentRestAmount')."</label>";
2512 print '</div>';
2513
2514 print '</div></div>';
2515 }
2516 } else {
2517 print '<div class="tagtr listofinvoicetype"><div class="tagtd listofinvoicetype">';
2518 if (empty($conf->global->INVOICE_CREDIT_NOTE_STANDALONE)) {
2519 $tmp = '<input type="radio" name="type" id="radio_creditnote" value="0" disabled> ';
2520 } else {
2521 $tmp='<input type="radio" name="type" id="radio_creditnote" value="2"> ';
2522 }
2523 $text = $tmp.$langs->trans("InvoiceAvoir").' ';
2524 $text .= '<span class="opacitymedium">('.$langs->trans("YouMustCreateInvoiceFromSupplierThird").')</span> ';
2525 $desc = $form->textwithpicto($text, $langs->transnoentities("InvoiceAvoirDesc"), 1, 'help', '', 0, 3);
2526 print $desc;
2527 print '</div></div>'."\n";
2528 }
2529 }
2530
2531 print '</div>';
2532
2533 print '</td></tr>';
2534
2535 if (!empty($societe->id) && $societe->id > 0) {
2536 // Discounts for third party
2537 print '<tr><td>'.$langs->trans('Discounts').'</td><td>';
2538
2539 $thirdparty = $societe;
2540 $discount_type = 1;
2541 $backtopage = urlencode($_SERVER["PHP_SELF"].'?socid='.$societe->id.'&action='.$action.'&origin='.GETPOST('origin').'&originid='.GETPOST('originid'));
2542 include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
2543
2544 print '</td></tr>';
2545 }
2546
2547 // Label
2548 print '<tr><td>'.$langs->trans('Label').'</td><td><input class="minwidth200" name="label" value="'.dol_escape_htmltag(GETPOST('label')).'" type="text"></td></tr>';
2549
2550 // Date invoice
2551 print '<tr><td class="fieldrequired">'.$langs->trans('DateInvoice').'</td><td>';
2552 print img_picto('', 'action', 'class="pictofixedwidth"');
2553 print $form->selectDate($dateinvoice, '', '', '', '', "add", 1, 1);
2554 print '</td></tr>';
2555
2556 // Payment term
2557 print '<tr><td class="nowrap">'.$langs->trans('PaymentConditionsShort').'</td><td>';
2558 print img_picto('', 'payment', 'class="pictofixedwidth"');
2559 print $form->getSelectConditionsPaiements(GETPOSTISSET('cond_reglement_id') ?GETPOST('cond_reglement_id', 'int') : $cond_reglement_id, 'cond_reglement_id');
2560 print '</td></tr>';
2561
2562 // Due date
2563 print '<tr><td>'.$langs->trans('DateMaxPayment').'</td><td>';
2564 print img_picto('', 'action', 'class="pictofixedwidth"');
2565 print $form->selectDate($datedue, 'ech', '', '', '', "add", 1, 1);
2566 print '</td></tr>';
2567
2568 // Payment mode
2569 print '<tr><td>'.$langs->trans('PaymentMode').'</td><td>';
2570 print img_picto('', 'bank', 'class="pictofixedwidth"');
2571 $form->select_types_paiements(GETPOSTISSET('mode_reglement_id') ?GETPOST('mode_reglement_id', 'int') : $mode_reglement_id, 'mode_reglement_id', 'DBIT', 0, 1, 0, 0, 1, 'maxwidth200 widthcentpercentminusx');
2572 print '</td></tr>';
2573
2574 // Bank Account
2575 if (isModEnabled("banque")) {
2576 print '<tr><td>'.$langs->trans('BankAccount').'</td><td>';
2577 print img_picto('', 'bank_account', 'class="pictofixedwidth"').$form->select_comptes((GETPOSTISSET('fk_account') ?GETPOST('fk_account', 'alpha') : $fk_account), 'fk_account', 0, '', 1, '', 0, 'maxwidth200 widthcentpercentminusx', 1);
2578 print '</td></tr>';
2579 }
2580
2581 // Project
2582 if (isModEnabled('project')) {
2583 $formproject = new FormProjets($db);
2584
2585 $langs->load('projects');
2586 print '<tr><td>'.$langs->trans('Project').'</td><td>';
2587 print img_picto('', 'project', 'class="pictofixedwidth"').$formproject->select_projects((empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $societe->id : -1), $projectid, 'projectid', 0, 0, 1, 1, 0, 0, 0, '', 1, 0, 'maxwidth500 widthcentpercentminusxx');
2588 print ' <a href="'.DOL_URL_ROOT.'/projet/card.php?socid='.(!empty($soc->id) ? $soc->id : 0).'&action=create&status=1&backtopage='.urlencode($_SERVER["PHP_SELF"].'?action=create&socid='.(!empty($soc->id) ? $soc->id : 0).($fac_recid > 0 ? '&fac_rec='.$fac_recid : '')).'"><span class="fa fa-plus-circle valignmiddle" title="'.$langs->trans("AddProject").'"></span></a>';
2589 print '</td></tr>';
2590 }
2591
2592 // Incoterms
2593 if (isModEnabled('incoterm')) {
2594 print '<tr>';
2595 print '<td><label for="incoterm_id">'.$form->textwithpicto($langs->trans("IncotermLabel"), !empty($objectsrc->label_incoterms) ? $objectsrc->label_incoterms : '', 1).'</label></td>';
2596 print '<td colspan="3" class="maxwidthonsmartphone">';
2597 print img_picto('', 'incoterm', 'class="pictofixedwidth"');
2598 print $form->select_incoterms(GETPOSTISSET('incoterm_id') ? GETPOST('incoterm_id', 'alphanohtml') : (!empty($objectsrc->fk_incoterms) ? $objectsrc->fk_incoterms : ''), GETPOSTISSET('location_incoterms') ? GETPOST('location_incoterms', 'alphanohtml') : (!empty($objectsrc->location_incoterms) ? $objectsrc->location_incoterms : ''));
2599 print '</td></tr>';
2600 }
2601
2602 // Vat reverse-charge by default
2603 if (!empty($conf->global->ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE)) {
2604 require_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
2605 print '<tr><td>' . $langs->trans('VATReverseCharge') . '</td><td>';
2606 // Try to propose to use VAT reverse charge even if the VAT reverse charge is not activated in the supplier card, if this corresponds to the context of use, the activation is proposed
2607 if ($vat_reverse_charge == 1 || $societe->vat_reverse_charge == 1 || ($societe->country_code != 'FR' && isInEEC($societe) && !empty($societe->tva_intra))) {
2608 $vat_reverse_charge = 1;
2609 } else {
2610 $vat_reverse_charge = 0;
2611 }
2612
2613 print '<input type="checkbox" name="vat_reverse_charge"'. (!empty($vat_reverse_charge) ? ' checked ' : '') . '>';
2614 print '</td></tr>';
2615 }
2616
2617 // Multicurrency
2618 if (isModEnabled("multicurrency")) {
2619 print '<tr>';
2620 print '<td>'.$form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0).'</td>';
2621 print '<td class="maxwidthonsmartphone">';
2622 print img_picto('', 'currency', 'class="pictofixedwidth"');
2623 print $form->selectMultiCurrency((GETPOSTISSET('multicurrency_code') ?GETPOST('multicurrency_code', 'alpha') : $currency_code), 'multicurrency_code');
2624 print '</td></tr>';
2625 }
2626
2627 // Help of substitution key
2628 $htmltext = '';
2629 if ($fac_recid > 0) {
2630 $dateexample = $newdateinvoice ? $newdateinvoice : $dateinvoice;
2631 if (empty($dateexample)) {
2632 $dateexample = dol_now();
2633 }
2634 $substitutionarray = array(
2635 '__TOTAL_HT__' => $langs->trans("AmountHT").' ('.$langs->trans("Example").': '.price($exampletemplateinvoice->total_ht).')',
2636 '__TOTAL_TTC__' => $langs->trans("AmountTTC").' ('.$langs->trans("Example").': '.price($exampletemplateinvoice->total_ttc).')',
2637 '__INVOICE_PREVIOUS_MONTH__' => $langs->trans("PreviousMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, -1, 'm'), '%m').')',
2638 '__INVOICE_MONTH__' => $langs->trans("MonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($dateexample, '%m').')',
2639 '__INVOICE_NEXT_MONTH__' => $langs->trans("NextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, 1, 'm'), '%m').')',
2640 '__INVOICE_PREVIOUS_MONTH_TEXT__' => $langs->trans("TextPreviousMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, -1, 'm'), '%B').')',
2641 '__INVOICE_MONTH_TEXT__' => $langs->trans("TextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($dateexample, '%B').')',
2642 '__INVOICE_NEXT_MONTH_TEXT__' => $langs->trans("TextNextMonthOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, 1, 'm'), '%B').')',
2643 '__INVOICE_PREVIOUS_YEAR__' => $langs->trans("PreviousYearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, -1, 'y'), '%Y').')',
2644 '__INVOICE_YEAR__' => $langs->trans("YearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date($dateexample, '%Y').')',
2645 '__INVOICE_NEXT_YEAR__' => $langs->trans("NextYearOfInvoice").' ('.$langs->trans("Example").': '.dol_print_date(dol_time_plus_duree($dateexample, 1, 'y'), '%Y').')'
2646 );
2647
2648 $htmltext = '<i>'.$langs->trans("FollowingConstantsWillBeSubstituted").':<br>';
2649 foreach ($substitutionarray as $key => $val) {
2650 $htmltext .= $key.' = '.$langs->trans($val).'<br>';
2651 }
2652 $htmltext .= '</i>';
2653 }
2654
2655 // Intracomm report
2656 if (isModEnabled('intracommreport')) {
2657 $langs->loadLangs(array("intracommreport"));
2658 print '<tr><td>'.$langs->trans('IntracommReportTransportMode').'</td><td>';
2659 $form->selectTransportMode(GETPOSTISSET('transport_mode_id') ? GETPOST('transport_mode_id') : $transport_mode_id, 'transport_mode_id');
2660 print '</td></tr>';
2661 }
2662
2663 if (empty($reshook)) {
2664 print $object->showOptionals($extrafields, 'create');
2665 }
2666
2667 // Public note
2668 print '<tr><td>'.$langs->trans('NotePublic').'</td>';
2669 print '<td>';
2670 $doleditor = new DolEditor('note_public', (GETPOSTISSET('note_public') ?GETPOST('note_public', 'restricthtml') : $note_public), '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PUBLIC) ? 0 : 1, ROWS_3, '90%');
2671 print $doleditor->Create(1);
2672 print '</td>';
2673 // print '<td><textarea name="note" wrap="soft" cols="60" rows="'.ROWS_5.'"></textarea></td>';
2674 print '</tr>';
2675
2676 // Private note
2677 print '<tr><td>'.$langs->trans('NotePrivate').'</td>';
2678 print '<td>';
2679 $doleditor = new DolEditor('note_private', (GETPOSTISSET('note_private') ?GETPOST('note_private', 'restricthtml') : $note_private), '', 80, 'dolibarr_notes', 'In', 0, false, empty($conf->global->FCKEDITOR_ENABLE_NOTE_PRIVATE) ? 0 : 1, ROWS_3, '90%');
2680 print $doleditor->Create(1);
2681 print '</td>';
2682 // print '<td><textarea name="note" wrap="soft" cols="60" rows="'.ROWS_5.'"></textarea></td>';
2683 print '</tr>';
2684
2685
2686 if (!empty($objectsrc) && is_object($objectsrc)) {
2687 print "\n<!-- ".$classname." info -->";
2688 print "\n";
2689 print '<input type="hidden" name="amount" value="'.$objectsrc->total_ht.'">'."\n";
2690 print '<input type="hidden" name="total" value="'.$objectsrc->total_ttc.'">'."\n";
2691 print '<input type="hidden" name="tva" value="'.$objectsrc->total_tva.'">'."\n";
2692 print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
2693 print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
2694
2695 $txt = $langs->trans($classname);
2696 if ($classname == 'CommandeFournisseur') {
2697 $langs->load('orders');
2698 $txt = $langs->trans("SupplierOrder");
2699 }
2700 print '<tr><td>'.$txt.'</td><td>'.$objectsrc->getNomUrl(1);
2701 // We check if Origin document (id and type is known) has already at least one invoice attached to it
2702 $objectsrc->fetchObjectLinked($originid, $origin, '', 'invoice_supplier');
2703
2704 $invoice_supplier = $objectsrc->linkedObjects['invoice_supplier'];
2705
2706 // count function need a array as argument (Note: the array must implement Countable too)
2707 if (is_array($invoice_supplier)) {
2708 $cntinvoice = count($invoice_supplier);
2709
2710 if ($cntinvoice >= 1) {
2711 setEventMessages('WarningBillExist', null, 'warnings');
2712 echo ' ('.$langs->trans('LatestRelatedBill').end($invoice_supplier)->getNomUrl(1).')';
2713 }
2714 }
2715
2716 print '</td></tr>';
2717 print '<tr><td>'.$langs->trans('AmountHT').'</td><td>'.price($objectsrc->total_ht).'</td></tr>';
2718 print '<tr><td>'.$langs->trans('AmountVAT').'</td><td>'.price($objectsrc->total_tva)."</td></tr>";
2719 if ($mysoc->localtax1_assuj == "1" || $object->total_localtax1 != 0) { //Localtax1
2720 print '<tr><td>'.$langs->transcountry("AmountLT1", $mysoc->country_code).'</td><td>'.price($objectsrc->total_localtax1)."</td></tr>";
2721 }
2722
2723 if ($mysoc->localtax2_assuj == "1" || $object->total_localtax2 != 0) { //Localtax2
2724 print '<tr><td>'.$langs->transcountry("AmountLT2", $mysoc->country_code).'</td><td>'.price($objectsrc->total_localtax2)."</td></tr>";
2725 }
2726 print '<tr><td>'.$langs->trans('AmountTTC').'</td><td>'.price($objectsrc->total_ttc)."</td></tr>";
2727
2728 if (isModEnabled("multicurrency")) {
2729 print '<tr><td>'.$langs->trans('MulticurrencyAmountHT').'</td><td>'.price($objectsrc->multicurrency_total_ht).'</td></tr>';
2730 print '<tr><td>'.$langs->trans('MulticurrencyAmountVAT').'</td><td>'.price($objectsrc->multicurrency_total_tva)."</td></tr>";
2731 print '<tr><td>'.$langs->trans('MulticurrencyAmountTTC').'</td><td>'.price($objectsrc->multicurrency_total_ttc)."</td></tr>";
2732 }
2733 }
2734
2735 // Other options
2736 $parameters = array();
2737 $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2738 print $hookmanager->resPrint;
2739
2740
2741 print "</table>\n";
2742
2743 print dol_get_fiche_end();
2744
2745 print $form->buttonsSaveCancel("CreateDraft");
2746
2747 // Show origin lines
2748 if (!empty($objectsrc) && is_object($objectsrc)) {
2749 print '<br>';
2750
2751 $title = $langs->trans('ProductsAndServices');
2752 print load_fiche_titre($title);
2753
2754 print '<div class="div-table-responsive-no-min">';
2755 print '<table class="noborder centpercent">';
2756
2757 $objectsrc->printOriginLinesList('', $selectedLines);
2758
2759 print '</table>';
2760 print '</div>';
2761 }
2762
2763 print "</form>\n";
2764} else {
2765 if ($id > 0 || !empty($ref)) {
2766 //
2767 // View or edit mode
2768 //
2769 $now = dol_now();
2770
2771 $productstatic = new Product($db);
2772
2773 $result = $object->fetch($id, $ref);
2774 if ($result <= 0) {
2775 $langs->load("errors");
2776 print $langs->trans("ErrorRecordNotFound");
2777 llxFooter();
2778 $db->close();
2779 exit;
2780 }
2781
2782 $result = $object->fetch_thirdparty();
2783 if ($result < 0) {
2784 dol_print_error($db, $object->error, $object->errors);
2785 exit;
2786 }
2787
2788 $societe = $object->thirdparty;
2789
2790 $totalpaid = $object->getSommePaiement();
2791 $totalcreditnotes = $object->getSumCreditNotesUsed();
2792 $totaldeposits = $object->getSumDepositsUsed();
2793 // print "totalpaid=".$totalpaid." totalcreditnotes=".$totalcreditnotes." totaldeposts=".$totaldeposits."
2794 // selleruserrevenuestamp=".$selleruserevenustamp;
2795
2796 // We can also use bcadd to avoid pb with floating points
2797 // For example print 239.2 - 229.3 - 9.9; does not return 0.
2798 // $resteapayer=bcadd($object->total_ttc,$totalpaid,$conf->global->MAIN_MAX_DECIMALS_TOT);
2799 // $resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT);
2800 $resteapayer = price2num($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits, 'MT');
2801
2802 // Multicurrency
2803 $multicurrency_resteapayer = 0;
2804 if (isModEnabled("multicurrency")) {
2805 $multicurrency_totalpaid = $object->getSommePaiement(1);
2806 $multicurrency_totalcreditnotes = $object->getSumCreditNotesUsed(1);
2807 $multicurrency_totaldeposits = $object->getSumDepositsUsed(1);
2808 $multicurrency_resteapayer = price2num($object->multicurrency_total_ttc - $multicurrency_totalpaid - $multicurrency_totalcreditnotes - $multicurrency_totaldeposits, 'MT');
2809 // Code to fix case of corrupted data
2810 // TODO We should not need this. Also data comes from not reliable value of $object->multicurrency_total_ttc that may be wrong if it was
2811 // calculated by summing lines that were in a currency for some of them and into another for others (lines from discount/down payment into another currency for example)
2812 if ($resteapayer == 0 && $multicurrency_resteapayer != 0 && $object->multicurrency_code != $conf->currency) {
2813 $resteapayer = price2num($multicurrency_resteapayer / $object->multicurrency_tx, 'MT');
2814 }
2815 }
2816
2817 if ($object->paye) {
2818 $resteapayer = 0;
2819 }
2820 $resteapayeraffiche = $resteapayer;
2821
2822 if (!empty($conf->global->FACTURE_SUPPLIER_DEPOSITS_ARE_JUST_PAYMENTS)) { // Never use this
2823 $filterabsolutediscount = "fk_invoice_supplier_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
2824 $filtercreditnote = "fk_invoice_supplier_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
2825 } else {
2826 $filterabsolutediscount = "fk_invoice_supplier_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS PAID)%')";
2827 $filtercreditnote = "fk_invoice_supplier_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS PAID)%')";
2828 }
2829
2830 $absolute_discount = $societe->getAvailableDiscounts('', $filterabsolutediscount, 0, 1);
2831 $absolute_creditnote = $societe->getAvailableDiscounts('', $filtercreditnote, 0, 1);
2832 $absolute_discount = price2num($absolute_discount, 'MT');
2833 $absolute_creditnote = price2num($absolute_creditnote, 'MT');
2834
2835 /*
2836 * View card
2837 */
2838 $objectidnext = $object->getIdReplacingInvoice();
2839
2840 $head = facturefourn_prepare_head($object);
2841 $titre = $langs->trans('SupplierInvoice');
2842
2843 print dol_get_fiche_head($head, 'card', $titre, -1, 'supplier_invoice', 0, '', '', 0, '', 1);
2844
2845 $formconfirm = '';
2846
2847 // Confirmation de la conversion de l'avoir en reduc
2848 if ($action == 'converttoreduc') {
2849 $type_fac = '';
2850 if ($object->type == FactureFournisseur::TYPE_STANDARD) {
2851 $type_fac = 'ExcessPaid';
2852 } elseif ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
2853 $type_fac = 'CreditNote';
2854 } elseif ($object->type == FactureFournisseur::TYPE_DEPOSIT) {
2855 $type_fac = 'Deposit';
2856 }
2857 $text = $langs->trans('ConfirmConvertToReducSupplier', strtolower($langs->transnoentities($type_fac)));
2858 $text .= '<br>'.$langs->trans('ConfirmConvertToReducSupplier2');
2859 $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?facid='.$object->id, $langs->trans('ConvertToReduc'), $text, 'confirm_converttoreduc', '', "yes", 2);
2860 }
2861
2862 // Clone confirmation
2863 if ($action == 'clone') {
2864 // Create an array for form
2865 $formquestion = array(
2866 array('type' => 'text', 'name' => 'newsupplierref', 'label' => $langs->trans("RefSupplier"), 'value' => $langs->trans("CopyOf").' '.$object->ref_supplier),
2867 array('type' => 'date', 'name' => 'newdate', 'label' => $langs->trans("Date"), 'value' => dol_now())
2868 );
2869 // Ask confirmation to clone
2870 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ToClone'), $langs->trans('ConfirmCloneInvoice', $object->ref), 'confirm_clone', $formquestion, 'yes', 1, 250);
2871 }
2872
2873 // Confirmation of validation
2874 if ($action == 'valid') {
2875 // We check if number is temporary number
2876 if (preg_match('/^[\‍(]?PROV/i', $object->ref) || empty($object->ref)) {
2877 // empty should not happened, but when it occurs, the test save life
2878 $numref = $object->getNextNumRef($societe);
2879 } else {
2880 $numref = $object->ref;
2881 }
2882
2883 if ($numref < 0) {
2884 setEventMessages($object->error, $object->errors, 'errors');
2885 $action = '';
2886 } else {
2887 $text = $langs->trans('ConfirmValidateBill', $numref);
2888 /*if (isModEnabled('notification'))
2889 {
2890 require_once DOL_DOCUMENT_ROOT .'/core/class/notify.class.php';
2891 $notify=new Notify($db);
2892 $text.='<br>';
2893 $text.=$notify->confirmMessage('BILL_SUPPLIER_VALIDATE',$object->socid, $object);
2894 }*/
2895 $formquestion = array();
2896
2897 $qualified_for_stock_change = 0;
2898 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
2899 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2900 } else {
2901 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2902 }
2903
2904 if (isModEnabled('stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) {
2905 $langs->load("stocks");
2906 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
2907 $formproduct = new FormProduct($db);
2908 $warehouse = new Entrepot($db);
2909 $warehouse_array = $warehouse->list_array();
2910 if (count($warehouse_array) == 1) {
2911 $label = $object->type == FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans("WarehouseForStockDecrease", current($warehouse_array)) : $langs->trans("WarehouseForStockIncrease", current($warehouse_array));
2912 $value = '<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).'">';
2913 } else {
2914 $label = $object->type == FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans("SelectWarehouseForStockDecrease") : $langs->trans("SelectWarehouseForStockIncrease");
2915 $value = $formproduct->selectWarehouses(GETPOST('idwarehouse') ?GETPOST('idwarehouse') : 'ifone', 'idwarehouse', '', 1);
2916 }
2917 $formquestion = array(
2918 array('type' => 'other', 'name' => 'idwarehouse', 'label' => $label, 'value' => $value)
2919 );
2920 }
2921
2922 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateBill'), $text, 'confirm_valid', $formquestion, 1, 1);
2923 }
2924 }
2925
2926 // Confirmation edit (back to draft)
2927 if ($action == 'edit') {
2928 $formquestion = array();
2929
2930 $qualified_for_stock_change = 0;
2931 if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
2932 $qualified_for_stock_change = $object->hasProductsOrServices(2);
2933 } else {
2934 $qualified_for_stock_change = $object->hasProductsOrServices(1);
2935 }
2936 if (isModEnabled('stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) {
2937 $langs->load("stocks");
2938 require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
2939 $formproduct = new FormProduct($db);
2940 $warehouse = new Entrepot($db);
2941 $warehouse_array = $warehouse->list_array();
2942 if (count($warehouse_array) == 1) {
2943 $label = $object->type == FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans("WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans("WarehouseForStockDecrease", current($warehouse_array));
2944 $value = '<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).'">';
2945 } else {
2946 $label = $object->type == FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans("SelectWarehouseForStockIncrease") : $langs->trans("SelectWarehouseForStockDecrease");
2947 $value = $formproduct->selectWarehouses(GETPOST('idwarehouse') ?GETPOST('idwarehouse') : 'ifone', 'idwarehouse', '', 1);
2948 }
2949 $formquestion = array(
2950 array('type' => 'other', 'name' => 'idwarehouse', 'label' => $label, 'value' => $value)
2951 );
2952 }
2953 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('UnvalidateBill'), $langs->trans('ConfirmUnvalidateBill', $object->ref), 'confirm_edit', $formquestion, 1, 1);
2954 }
2955
2956 // Confirmation set paid
2957 if ($action == 'paid' && ($resteapayer <= 0 || (!empty($conf->global->SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) && $resteapayer == $object->total_ttc))) {
2958 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ClassifyPaid'), $langs->trans('ConfirmClassifyPaidBill', $object->ref), 'confirm_paid', '', 0, 1);
2959 }
2960
2961 if ($action == 'paid' && $resteapayer > 0 && (empty($conf->global->SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) || $resteapayer != $object->total_ttc)) {
2962 $close = array();
2963 // Code
2964 $i = 0;
2965 $close[$i]['code'] = 'discount_vat'; // escompte
2966 $i++;
2967 $close[$i]['code'] = 'badsupplier';
2968 $i++;
2969 $close[$i]['code'] = 'other';
2970 $i++;
2971 // Help
2972 $i = 0;
2973 $close[$i]['label'] = $langs->trans("HelpEscompte").'<br><br>'.$langs->trans("ConfirmClassifyPaidPartiallyReasonDiscountVatDesc");
2974 $i++;
2975 $close[$i]['label'] = $langs->trans("ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
2976 $i++;
2977 $close[$i]['label'] = $langs->trans("Other");
2978 $i++;
2979 // Text
2980 $i = 0;
2981 $close[$i]['reason'] = $form->textwithpicto($langs->transnoentities("ConfirmClassifyPaidPartiallyReasonDiscount", $resteapayer, $langs->trans("Currency".$conf->currency)), $close[$i]['label'], 1);
2982 $i++;
2983 $close[$i]['reason'] = $form->textwithpicto($langs->transnoentities("ConfirmClassifyPaidPartiallyReasonBadCustomer", $resteapayer, $langs->trans("Currency".$conf->currency)), $close[$i]['label'], 1);
2984 $i++;
2985 $close[$i]['reason'] = $form->textwithpicto($langs->transnoentities("Other"), $close[$i]['label'], 1);
2986 $i++;
2987 // arrayreasons[code]=reason
2988 foreach ($close as $key => $val) {
2989 $arrayreasons[$close[$key]['code']] = $close[$key]['reason'];
2990 }
2991
2992 // Create a form table
2993 $formquestion = array('text' => $langs->trans("ConfirmClassifyPaidPartiallyQuestion"), array('type' => 'radio', 'name' => 'close_code', 'label' => $langs->trans("Reason"), 'values' => $arrayreasons), array('type' => 'text', 'name' => 'close_note', 'label' => $langs->trans("Comment"), 'value' => '', 'morecss' => 'minwidth300'));
2994 // Incomplete payment. We ask if the reason is discount or other
2995 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?facid='.$object->id, $langs->trans('ClassifyPaid'), $langs->trans('ConfirmClassifyPaidPartially', $object->ref), 'confirm_paid_partially', $formquestion, "yes", 1, 310);
2996 }
2997
2998 // Confirmation of the abandoned classification
2999 if ($action == 'canceled') {
3000 // Code
3001 $close[1]['code'] = 'badsupplier';
3002 $close[2]['code'] = 'abandon';
3003 // Help
3004 $close[1]['label'] = $langs->trans("ConfirmClassifyPaidPartiallyReasonBadSupplierDesc");
3005 $close[2]['label'] = $langs->trans("ConfirmClassifyAbandonReasonOtherDesc");
3006 // Text
3007 $close[1]['reason'] = $form->textwithpicto($langs->transnoentities("ConfirmClassifyPaidPartiallyReasonBadSupplier", $object->ref), $close[1]['label'], 1);
3008 $close[2]['reason'] = $form->textwithpicto($langs->transnoentities("ConfirmClassifyAbandonReasonOther"), $close[2]['label'], 1);
3009 // arrayreasons
3010 $arrayreasons[$close[1]['code']] = $close[1]['reason'];
3011 $arrayreasons[$close[2]['code']] = $close[2]['reason'];
3012
3013 // Create a form table
3014 $formquestion = array('text' => $langs->trans("ConfirmCancelBillQuestion"), array('type' => 'radio', 'name' => 'close_code', 'label' => $langs->trans("Reason"), 'values' => $arrayreasons), array('type' => 'text', 'name' => 'close_note', 'label' => $langs->trans("Comment"), 'value' => '', 'morecss' => 'minwidth300'));
3015
3016 $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'].'?id='.$object->id, $langs->trans('CancelBill'), $langs->trans('ConfirmCancelBill', $object->ref), 'confirm_canceled', $formquestion, "yes", 1, 250);
3017 }
3018
3019 // Confirmation de la suppression de la facture fournisseur
3020 if ($action == 'delete') {
3021 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteBill'), $langs->trans('ConfirmDeleteBill'), 'confirm_delete', '', 0, 1);
3022 }
3023 if ($action == 'deletepayment') {
3024 $payment_id = GETPOST('paiement_id');
3025 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&paiement_id='.$payment_id, $langs->trans('DeletePayment'), $langs->trans('ConfirmDeletePayment'), 'confirm_delete_paiement', '', 0, 1);
3026 }
3027
3028 // Confirmation to delete line
3029 if ($action == 'ask_deleteline') {
3030 $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 0, 1);
3031 }
3032
3033 $parameters = array('formConfirm' => $formconfirm, 'lineid'=>$lineid);
3034 $reshook = $hookmanager->executeHooks('formConfirm', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
3035 if (empty($reshook)) {
3036 $formconfirm .= $hookmanager->resPrint;
3037 } elseif ($reshook > 0) {
3038 $formconfirm = $hookmanager->resPrint;
3039 }
3040
3041 // Print form confirm
3042 print $formconfirm;
3043
3044
3045 // Supplier invoice card
3046 $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/facture/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
3047
3048 $morehtmlref = '<div class="refidno">';
3049 // Ref supplier
3050 $morehtmlref .= $form->editfieldkey("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $usercancreate, 'string', '', 0, 1);
3051 $morehtmlref .= $form->editfieldval("RefSupplier", 'ref_supplier', $object->ref_supplier, $object, $usercancreate, 'string', '', null, null, '', 1);
3052 // Thirdparty
3053 $morehtmlref .= '<br>'.$object->thirdparty->getNomUrl(1, 'supplier');
3054 if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) {
3055 $morehtmlref .= ' <div class="inline-block valignmiddle">(<a class="valignmiddle" href="'.DOL_URL_ROOT.'/fourn/facture/list.php?socid='.((int) $object->thirdparty->id).'&search_company='.urlencode($object->thirdparty->name).'">'.$langs->trans("OtherBills").'</a>)</div>';
3056 }
3057 // Project
3058 if (isModEnabled('project')) {
3059 $langs->load("projects");
3060 $morehtmlref .= '<br>';
3061 if ($permissiontoadd) {
3062 $morehtmlref .= img_picto($langs->trans("Project"), 'project', 'class="pictofixedwidth"');
3063 if ($action != 'classify') {
3064 $morehtmlref .= '<a class="editfielda" href="'.$_SERVER['PHP_SELF'].'?action=classify&token='.newToken().'&id='.((int) $object->id).'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> ';
3065 }
3066 $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, (empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) ? $object->socid : -1), $object->fk_project, ($action == 'classify' ? 'projectid' : 'none'), 0, 0, 0, 1, '', 'maxwidth300');
3067 } else {
3068 if (!empty($object->fk_project)) {
3069 $proj = new Project($db);
3070 $proj->fetch($object->fk_project);
3071 $morehtmlref .= $proj->getNomUrl(1);
3072 if ($proj->title) {
3073 $morehtmlref .= '<span class="opacitymedium"> - '.dol_escape_htmltag($proj->title).'</span>';
3074 }
3075 }
3076 }
3077 }
3078 $morehtmlref .= '</div>';
3079
3080 $object->totalpaid = $totalpaid; // To give a chance to dol_banner_tab to use already paid amount to show correct status
3081
3082 dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
3083
3084 print '<div class="fichecenter">';
3085 print '<div class="fichehalfleft">';
3086 print '<div class="underbanner clearboth"></div>';
3087
3088 print '<table class="border tableforfield centpercent">';
3089
3090 // Type
3091 print '<tr><td class="titlefield">'.$langs->trans('Type').'</td><td>';
3092 print '<span class="badgeneutral">';
3093 print $object->getLibType();
3094 print '</span>';
3095 if ($object->type == FactureFournisseur::TYPE_REPLACEMENT) {
3096 $facreplaced = new FactureFournisseur($db);
3097 $facreplaced->fetch($object->fk_facture_source);
3098 print ' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities("ReplaceInvoice", $facreplaced->getNomUrl(1)).'</span>';
3099 }
3100 if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
3101 $facusing = new FactureFournisseur($db);
3102 if ($object->fk_facture_source > 0) {
3103 $facusing->fetch($object->fk_facture_source);
3104 print ' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities("CorrectInvoice", $facusing->getNomUrl(1)).'</span>';
3105 } else {
3106 $langs->load("errors");
3107 print ' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities("WarningCorrectedInvoiceNotFound").'</span>';
3108 }
3109 }
3110
3111 $facidavoir = $object->getListIdAvoirFromInvoice();
3112 if (count($facidavoir) > 0) {
3113 $invoicecredits = array();
3114 foreach ($facidavoir as $id) {
3115 $facavoir = new FactureFournisseur($db);
3116 $facavoir->fetch($id);
3117 $invoicecredits[] = $facavoir->getNomUrl(1);
3118 }
3119 print ' <span class="opacitymediumbycolor paddingleft">'.$langs->transnoentities("InvoiceHasAvoir") . (count($invoicecredits) ? ' ' : '') . implode(',', $invoicecredits);
3120 print '</span>';
3121 }
3122 if (isset($objectidnext) && $objectidnext > 0) {
3123 $facthatreplace = new FactureFournisseur($db);
3124
3125 $facthatreplace->fetch($objectidnext);
3126 print ' <span class="opacitymediumbycolor paddingleft">'.str_replace('{s1}', $facthatreplace->getNomUrl(1), $langs->transnoentities("ReplacedByInvoice", '{s1}')).'</span>';
3127 }
3128 if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE || $object->type == FactureFournisseur::TYPE_DEPOSIT) {
3129 $discount = new DiscountAbsolute($db);
3130 $result = $discount->fetch(0, 0, $object->id);
3131 if ($result > 0) {
3132 print ' <span class="opacitymediumbycolor paddingleft">';
3133 $s = $langs->trans("CreditNoteConvertedIntoDiscount", '{s1}', '{s2}');
3134 $s = str_replace('{s1}', $object->getLibType(1), $s);
3135 $s = str_replace('{s2}', $discount->getNomUrl(1, 'discount'), $s);
3136 print $s;
3137 print '</span><br>';
3138 }
3139 }
3140
3141 if ($object->fk_fac_rec_source > 0) {
3142 $tmptemplate = new FactureFournisseurRec($db);
3143 $result = $tmptemplate->fetch($object->fk_fac_rec_source);
3144 if ($result > 0) {
3145 print ' <span class="opacitymediumbycolor paddingleft">';
3146 $link = '<a href="'.DOL_URL_ROOT.'/fourn/facture/card-rec.php?facid='.$tmptemplate->id.'">'.dol_escape_htmltag($tmptemplate->titre).'</a>';
3147 $s = $langs->transnoentities("GeneratedFromSupplierTemplate", $link);
3148
3149 print $s;
3150 print '</span>';
3151 }
3152 }
3153 print '</td></tr>';
3154
3155
3156 // Relative and absolute discounts
3157 print '<!-- Discounts -->'."\n";
3158 print '<tr><td>'.$langs->trans('DiscountStillRemaining');
3159 print '</td><td>';
3160
3161 $thirdparty = $societe;
3162 $discount_type = 1;
3163 include DOL_DOCUMENT_ROOT.'/core/tpl/object_discounts.tpl.php';
3164
3165 print '</td></tr>';
3166
3167 // Label
3168 print '<tr>';
3169 print '<td>'.$form->editfieldkey("Label", 'label', $object->label, $object, $usercancreate).'</td>';
3170 print '<td>'.$form->editfieldval("Label", 'label', $object->label, $object, $usercancreate).'</td>';
3171 print '</tr>';
3172
3173 //$form_permission = ($object->statut < FactureFournisseur::STATUS_CLOSED) && $usercancreate && ($object->getSommePaiement() <= 0);
3174 $form_permission = ($object->statut < FactureFournisseur::STATUS_CLOSED) && $usercancreate;
3175
3176 // Date
3177 print '<tr><td>';
3178 print $form->editfieldkey("DateInvoice", 'datef', $object->datep, $object, $form_permission, 'datepicker');
3179 print '</td><td colspan="3">';
3180 print $form->editfieldval("Date", 'datef', $object->datep, $object, $form_permission, 'datepicker');
3181 print '</td>';
3182
3183 // Default terms of the settlement
3184 $langs->load('bills');
3185 print '<tr><td class="nowrap">';
3186 print '<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3187 print $langs->trans('PaymentConditions');
3188 print '<td>';
3189 if ($action != 'editconditions' && $form_permission) {
3190 print '<td class="right"><a class="editfielda reposition" href="'.$_SERVER["PHP_SELF"].'?action=editconditions&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetConditions'), 1).'</a></td>';
3191 }
3192 print '</tr></table>';
3193 print '</td><td>';
3194 if ($action == 'editconditions') {
3195 $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'cond_reglement_id');
3196 } else {
3197 $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->cond_reglement_id, 'none');
3198 }
3199 print "</td>";
3200 print '</tr>';
3201
3202 // Due date
3203 print '<tr><td>';
3204 print $form->editfieldkey("DateMaxPayment", 'date_lim_reglement', $object->date_echeance, $object, $form_permission, 'datepicker');
3205 print '</td><td>';
3206 print $form->editfieldval("DateMaxPayment", 'date_lim_reglement', $object->date_echeance, $object, $form_permission, 'datepicker');
3207 if ($action != 'editdate_lim_reglement' && $object->hasDelay()) {
3208 print img_warning($langs->trans('Late'));
3209 }
3210 print '</td>';
3211
3212 // Mode of payment
3213 $langs->load('bills');
3214 print '<tr><td class="nowrap">';
3215 print '<table class="nobordernopadding centpercent"><tr><td class="nowrap">';
3216 print $langs->trans('PaymentMode');
3217 print '</td>';
3218 if ($action != 'editmode' && $form_permission) {
3219 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmode&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->trans('SetMode'), 1).'</a></td>';
3220 }
3221 print '</tr></table>';
3222 print '</td><td>';
3223 if ($action == 'editmode') {
3224 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id', 'DBIT', 1, 1);
3225 } else {
3226 $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none');
3227 }
3228 print '</td></tr>';
3229
3230 // Multicurrency
3231 if (isModEnabled("multicurrency")) {
3232 // Multicurrency code
3233 print '<tr>';
3234 print '<td>';
3235 print '<table class="nobordernopadding" width="100%"><tr><td>';
3236 print $form->editfieldkey('Currency', 'multicurrency_code', '', $object, 0);
3237 print '</td>';
3238 if ($action != 'editmulticurrencycode' && $object->statut == $object::STATUS_DRAFT) {
3239 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmulticurrencycode&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1).'</a></td>';
3240 }
3241 print '</tr></table>';
3242 print '</td><td>';
3243 if ($action == 'editmulticurrencycode') {
3244 $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'multicurrency_code');
3245 } else {
3246 $form->form_multicurrency_code($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_code, 'none');
3247 }
3248 print '</td></tr>';
3249
3250 // Multicurrency rate
3251 if ($object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
3252 print '<tr>';
3253 print '<td>';
3254 print '<table class="nobordernopadding centpercent"><tr><td>';
3255 print $form->editfieldkey('CurrencyRate', 'multicurrency_tx', '', $object, 0);
3256 print '</td>';
3257 if ($action != 'editmulticurrencyrate' && $object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
3258 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editmulticurrencyrate&token='.newToken().'&id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1).'</a></td>';
3259 }
3260 print '</tr></table>';
3261 print '</td><td>';
3262 if ($action == 'editmulticurrencyrate' || $action == 'actualizemulticurrencyrate') {
3263 if ($action == 'actualizemulticurrencyrate') {
3264 list($object->fk_multicurrency, $object->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($object->db, $object->multicurrency_code);
3265 }
3266 $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'multicurrency_tx', $object->multicurrency_code);
3267 } else {
3268 $form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$object->id, $object->multicurrency_tx, 'none', $object->multicurrency_code);
3269 if ($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {
3270 print '<div class="inline-block"> &nbsp; &nbsp; &nbsp; &nbsp; ';
3271 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=actualizemulticurrencyrate">'.$langs->trans("ActualizeCurrency").'</a>';
3272 print '</div>';
3273 }
3274 }
3275 print '</td></tr>';
3276 }
3277 }
3278
3279 // Bank Account
3280 if (isModEnabled("banque")) {
3281 print '<tr><td class="nowrap">';
3282 print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3283 print $langs->trans('BankAccount');
3284 print '<td>';
3285 if ($action != 'editbankaccount' && $usercancreate) {
3286 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>';
3287 }
3288 print '</tr></table>';
3289 print '</td><td>';
3290 if ($action == 'editbankaccount') {
3291 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'fk_account', 1);
3292 } else {
3293 $form->formSelectAccount($_SERVER['PHP_SELF'].'?id='.$object->id, $object->fk_account, 'none');
3294 }
3295 print "</td>";
3296 print '</tr>';
3297 }
3298
3299 // Vat reverse-charge by default
3300 if (!empty($conf->global->ACCOUNTING_FORCE_ENABLE_VAT_REVERSE_CHARGE)) {
3301 print '<tr><td class="nowrap">';
3302 print '<table width="100%" class="nobordernopadding"><tr><td class="nowrap">';
3303 print $langs->trans('VATReverseCharge');
3304 print '<td>';
3305 if ($action != 'editvatreversecharge' && $usercancreate) {
3306 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=editvatreversecharge&amp;id='.$object->id.'">'.img_edit($langs->trans('SetVATReverseCharge'), 1).'</a></td>';
3307 }
3308 print '</tr></table>';
3309 print '</td><td>';
3310 if ($action == 'editvatreversecharge') {
3311 print '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
3312 print '<input type="hidden" name="action" value="setvatreversecharge">';
3313 print '<input type="hidden" name="token" value="'.newToken().'">';
3314
3315 print '<input type="checkbox" name="vat_reverse_charge"' . ($object->vat_reverse_charge == '1' ? ' checked ' : '') . '>';
3316
3317 print '<input type="submit" class="button valignmiddle" value="'.$langs->trans("Modify").'">';
3318 print '</form>';
3319 } else {
3320 print '<input type="checkbox" name="vat_reverse_charge"'. ($object->vat_reverse_charge == '1' ? ' checked ' : '') . ' disabled>';
3321 }
3322 print '</td></tr>';
3323 }
3324
3325 // Incoterms
3326 if (isModEnabled('incoterm')) {
3327 print '<tr><td>';
3328 print '<table width="100%" class="nobordernopadding"><tr><td>';
3329 print $langs->trans('IncotermLabel');
3330 print '<td><td class="right">';
3331 if ($usercancreate) {
3332 print '<a class="editfielda" href="'.DOL_URL_ROOT.'/fourn/facture/card.php?facid='.$object->id.'&action=editincoterm&token='.newToken().'">'.img_edit().'</a>';
3333 } else {
3334 print '&nbsp;';
3335 }
3336 print '</td></tr></table>';
3337 print '</td>';
3338 print '<td>';
3339 if ($action != 'editincoterm') {
3340 print $form->textwithpicto($object->display_incoterms(), $object->label_incoterms, 1);
3341 } else {
3342 print $form->select_incoterms((!empty($object->fk_incoterms) ? $object->fk_incoterms : ''), (!empty($object->location_incoterms) ? $object->location_incoterms : ''), $_SERVER['PHP_SELF'].'?id='.$object->id);
3343 }
3344 print '</td></tr>';
3345 }
3346
3347 // Intracomm report
3348 if (isModEnabled('intracommreport')) {
3349 $langs->loadLangs(array("intracommreport"));
3350 print '<tr><td>';
3351 print '<table class="nobordernopadding centpercent"><tr><td>';
3352 print $langs->trans('IntracommReportTransportMode');
3353 print '</td>';
3354 if ($action != 'edittransportmode' && ($user->hasRight("fournisseur", "facture", "creer") || $user->hasRight("supplier_invoice", "creer"))) {
3355 print '<td class="right"><a class="editfielda" href="'.$_SERVER["PHP_SELF"].'?action=edittransportmode&token='.newToken().'&id='.$object->id.'">'.img_edit().'</a></td>';
3356 }
3357 print '</tr></table>';
3358 print '</td>';
3359 print '<td>';
3360 if ($action == 'edittransportmode') {
3361 $form->formSelectTransportMode($_SERVER['PHP_SELF'].'?id='.$object->id, $object->transport_mode_id, 'transport_mode_id', 1, 1);
3362 } else {
3363 $form->formSelectTransportMode($_SERVER['PHP_SELF'].'?id='.$object->id, $object->transport_mode_id, 'none');
3364 }
3365 print '</td></tr>';
3366 }
3367
3368 // Other attributes
3369 $cols = 2;
3370 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
3371
3372 print '</table>';
3373 print '</div>';
3374
3375 print '<div class="fichehalfright">';
3376 print '<div class="underbanner clearboth"></div>';
3377
3378 print '<table class="border tableforfield centpercent">';
3379
3380 print '<tr>';
3381 print '<td class="titlefieldmiddle">' . $langs->trans('AmountHT') . '</td>';
3382 print '<td class="nowrap amountcard right">' . price($object->total_ht, '', $langs, 0, -1, -1, $conf->currency) . '</td>';
3383 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
3384 print '<td class="nowrap amountcard right">' . price($object->multicurrency_total_ht, '', $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
3385 }
3386 print '</tr>';
3387
3388 print '<tr>';
3389 print '<td>' . $langs->trans('AmountVAT') . '</td>';
3390 print '<td class="nowrap amountcard right">';
3391 if (GETPOST('calculationrule')) {
3392 $calculationrule = GETPOST('calculationrule', 'alpha');
3393 } else {
3394 $calculationrule = (empty($conf->global->MAIN_ROUNDOFTOTAL_NOT_TOTALOFROUND) ? 'totalofround' : 'roundoftotal');
3395 }
3396 if ($calculationrule == 'totalofround') {
3397 $calculationrulenum = 1;
3398 } else {
3399 $calculationrulenum = 2;
3400 }
3401 // Show link for "recalculate"
3402 if ($object->getVentilExportCompta() == 0) {
3403 $s = '<span class="hideonsmartphone opacitymedium">' . $langs->trans("ReCalculate") . ' </span>';
3404 $s .= '<a href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=calculate&calculationrule=totalofround">' . $langs->trans("Mode1") . '</a>';
3405 $s .= ' / ';
3406 $s .= '<a href="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&action=calculate&calculationrule=roundoftotal">' . $langs->trans("Mode2") . '</a>';
3407 print '<div class="inline-block">';
3408 print $form->textwithtooltip($s, $langs->trans("CalculationRuleDesc", $calculationrulenum) . '<br>' . $langs->trans("CalculationRuleDescSupplier"), 2, 1, img_picto('', 'help'), '', 3, '', 0, 'recalculate');
3409 print '&nbsp; &nbsp; &nbsp; &nbsp;';
3410 print '</div>';
3411 }
3412 print price($object->total_tva, 1, $langs, 0, -1, -1, $conf->currency);
3413 print '</td>';
3414 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
3415 print '<td class="nowrap amountcard right">' . price($object->multicurrency_total_tva, '', $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
3416 }
3417 print '</tr>';
3418
3419 if ($societe->localtax1_assuj == "1") { //Localtax1
3420 print '<tr>';
3421 print '<td>' . $langs->transcountry("AmountLT1", $societe->country_code) . '</td>';
3422 print '<td class="nowrap amountcard right">' . price($object->total_localtax1, 1, $langs, 0, -1, -1, $conf->currency) . '</td>';
3423 print '</tr>';
3424 }
3425 if ($societe->localtax2_assuj == "1") { //Localtax2
3426 print '<tr>';
3427 print '<td>' . $langs->transcountry("AmountLT2", $societe->country_code) . '</td>';
3428 print '<td class="nowrap amountcard right">' . price($object->total_localtax2, 1, $langs, 0, -1, -1, $conf->currency) . '</td>';
3429 print '</tr>';
3430 }
3431
3432 print '<tr>';
3433 print '<td>' . $langs->trans('AmountTTC') . '</td>';
3434 print '<td class="nowrap amountcard right">' . price($object->total_ttc, '', $langs, 0, -1, -1, $conf->currency) . '</td>';
3435 if (isModEnabled("multicurrency") && ($object->multicurrency_code && $object->multicurrency_code != $conf->currency)) {
3436 print '<td class="nowrap amountcard right">' . price($object->multicurrency_total_ttc, '', $langs, 0, -1, -1, $object->multicurrency_code) . '</td>';
3437 }
3438 print '</tr>';
3439
3440 print '</table>';
3441
3442
3443 // List of payments
3444
3445 $totalpaid = 0;
3446
3447 $sign = 1;
3448 if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
3449 $sign = - 1;
3450 }
3451
3452 $nbrows = 9; $nbcols = 3;
3453 if (isModEnabled('project')) {
3454 $nbrows++;
3455 }
3456 if (isModEnabled("banque")) {
3457 $nbrows++; $nbcols++;
3458 }
3459 if (isModEnabled('incoterm')) {
3460 $nbrows++;
3461 }
3462 if (isModEnabled("multicurrency")) {
3463 $nbrows += 5;
3464 }
3465
3466 // Local taxes
3467 if ($societe->localtax1_assuj == "1") {
3468 $nbrows++;
3469 }
3470 if ($societe->localtax2_assuj == "1") {
3471 $nbrows++;
3472 }
3473
3474 $sql = 'SELECT p.datep as dp, p.ref, p.num_paiement as num_payment, p.rowid, p.fk_bank,';
3475 $sql .= ' c.id as paiement_type, c.code as payment_code,';
3476 $sql .= ' pf.amount,';
3477 $sql .= ' ba.rowid as baid, ba.ref as baref, ba.label, ba.number as banumber, ba.account_number, ba.fk_accountancy_journal';
3478 $sql .= ' FROM '.MAIN_DB_PREFIX.'paiementfourn as p';
3479 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON p.fk_bank = b.rowid';
3480 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON b.fk_account = ba.rowid';
3481 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as c ON p.fk_paiement = c.id';
3482 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_paiementfourn = p.rowid';
3483 $sql .= ' WHERE pf.fk_facturefourn = '.((int) $object->id);
3484 $sql .= ' ORDER BY p.datep, p.tms';
3485
3486 $result = $db->query($sql);
3487 if ($result) {
3488 $num = $db->num_rows($result);
3489 $i = 0;
3490
3491 print '<div class="div-table-responsive-no-min">';
3492 print '<table class="noborder paymenttable centpercent">';
3493 print '<tr class="liste_titre">';
3494 print '<td class="liste_titre">'.($object->type == FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans("PaymentsBack") : $langs->trans('Payments')).'</td>';
3495 print '<td>'.$langs->trans('Date').'</td>';
3496 print '<td>'.$langs->trans('Type').'</td>';
3497 if (isModEnabled("banque")) {
3498 print '<td class="right">'.$langs->trans('BankAccount').'</td>';
3499 }
3500 print '<td class="right">'.$langs->trans('Amount').'</td>';
3501 print '<td width="18">&nbsp;</td>';
3502 print '</tr>';
3503
3504 if ($num > 0) {
3505 while ($i < $num) {
3506 $objp = $db->fetch_object($result);
3507
3508 $paymentstatic->id = $objp->rowid;
3509 $paymentstatic->datepaye = $db->jdate($objp->dp);
3510 $paymentstatic->ref = ($objp->ref ? $objp->ref : $objp->rowid);
3511 $paymentstatic->num_payment = $objp->num_payment;
3512
3513 $paymentstatic->paiementcode = $objp->payment_code;
3514 $paymentstatic->type_code = $objp->payment_code;
3515 $paymentstatic->type_label = $objp->payment_type;
3516
3517 print '<tr class="oddeven">';
3518 print '<td class="nowraponall">';
3519 print $paymentstatic->getNomUrl(1);
3520 print '</td>';
3521 print '<td>'.dol_print_date($db->jdate($objp->dp), 'day').'</td>';
3522 $s = $form->form_modes_reglement(null, $objp->paiement_type, 'none', '', 1, 0, '', 1).' '.$objp->num_payment;
3523 print '<td class="tdoverflowmax125" title="'.dol_escape_htmltag($s).'">';
3524 print $s;
3525 print '</td>';
3526 if (isModEnabled("banque")) {
3527 $bankaccountstatic->id = $objp->baid;
3528 $bankaccountstatic->ref = $objp->baref;
3529 $bankaccountstatic->label = $objp->baref;
3530 $bankaccountstatic->number = $objp->banumber;
3531
3532 if (isModEnabled('accounting')) {
3533 $bankaccountstatic->account_number = $objp->account_number;
3534
3535 $accountingjournal = new AccountingJournal($db);
3536 $accountingjournal->fetch($objp->fk_accountancy_journal);
3537 $bankaccountstatic->accountancy_journal = $accountingjournal->getNomUrl(0, 1, 1, '', 1);
3538 }
3539
3540 print '<td class="right">';
3541 if ($objp->baid > 0) {
3542 print $bankaccountstatic->getNomUrl(1, 'transactions');
3543 }
3544 print '</td>';
3545 }
3546 print '<td class="right">'.price($sign * $objp->amount).'</td>';
3547 print '<td class="center">';
3548
3549 $paiementfourn = new PaiementFourn($db);
3550 $paiementfourn->fetch($objp->rowid);
3551 if ($object->statut == FactureFournisseur::STATUS_VALIDATED && $object->paye == 0 && $user->socid == 0 && !$paiementfourn->isReconciled()) {
3552 print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=deletepayment&token='.newToken().'&paiement_id='.$objp->rowid.'">';
3553 print img_delete();
3554 print '</a>';
3555 }
3556 print '</td>';
3557 print '</tr>';
3558 $totalpaid += $objp->amount;
3559 $i++;
3560 }
3561 } else {
3562 print '<tr class="oddeven"><td colspan="'.$nbcols.'"><span class="opacitymedium">'.$langs->trans("None").'</span></td><td></td><td></td></tr>';
3563 }
3564
3565 /*
3566 if ($object->paye == 0)
3567 {
3568 print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans('AlreadyPaid').' :</td><td class="right">'.price($totalpaid).'</td><td></td></tr>';
3569 print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("Billed").' :</td><td class="right">'.price($object->total_ttc).'</td><td></td></tr>';
3570
3571 $resteapayer = $object->total_ttc - $totalpaid;
3572
3573 print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans('RemainderToPay').' :</td>';
3574 print '<td class="right'.($resteapayer?' amountremaintopay':'').'">'.price($resteapayer).'</td><td></td></tr>';
3575 }
3576 */
3577
3578 $db->free($result);
3579 } else {
3580 dol_print_error($db);
3581 }
3582
3583 if ($object->type != FactureFournisseur::TYPE_CREDIT_NOTE) {
3584 // Total already paid
3585 print '<tr><td colspan="'.$nbcols.'" class="right">';
3586 print '<span class="opacitymedium">';
3587 if ($object->type != FactureFournisseur::TYPE_DEPOSIT) {
3588 print $langs->trans('AlreadyPaidNoCreditNotesNoDeposits');
3589 } else {
3590 print $langs->trans('AlreadyPaid');
3591 }
3592 print '</span>';
3593 print '</td><td class="right"'.(($totalpaid > 0) ? ' class="amountalreadypaid"' : '').'>'.price($totalpaid).'</td><td>&nbsp;</td></tr>';
3594
3595 //$resteapayer = $object->total_ttc - $totalpaid;
3596 $resteapayeraffiche = $resteapayer;
3597
3598 $cssforamountpaymentcomplete = 'amountpaymentcomplete';
3599
3600 // Loop on each credit note or deposit amount applied
3601 $creditnoteamount = 0;
3602 $depositamount = 0;
3603
3604 $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,";
3605 $sql .= " re.description, re.fk_invoice_supplier_source";
3606 $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re";
3607 $sql .= " WHERE fk_invoice_supplier = ".((int) $object->id);
3608 $resql = $db->query($sql);
3609 if ($resql) {
3610 $num = $db->num_rows($resql);
3611 $i = 0;
3612 $invoice = new FactureFournisseur($db);
3613 while ($i < $num) {
3614 $obj = $db->fetch_object($resql);
3615 $invoice->fetch($obj->fk_invoice_supplier_source);
3616 print '<tr><td colspan="'.$nbcols.'" class="right">';
3617 if ($invoice->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
3618 print $langs->trans("CreditNote").' ';
3619 }
3620 if ($invoice->type == FactureFournisseur::TYPE_DEPOSIT) {
3621 print $langs->trans("Deposit").' ';
3622 }
3623 print $invoice->getNomUrl(0);
3624 print ' :</td>';
3625 print '<td class="right">'.price($obj->amount_ttc).'</td>';
3626 print '<td class="right">';
3627 print '<a href="'.$_SERVER["PHP_SELF"].'?facid='.$object->id.'&action=unlinkdiscount&discountid='.$obj->rowid.'">';
3628 print img_picto($langs->transnoentitiesnoconv("RemoveDiscount"), 'unlink');
3629 print '</a>';
3630 print '</td></tr>';
3631 $i++;
3632 if ($invoice->type == FactureFournisseur::TYPE_CREDIT_NOTE) {
3633 $creditnoteamount += $obj->amount_ttc;
3634 }
3635 if ($invoice->type == FactureFournisseur::TYPE_DEPOSIT) {
3636 $depositamount += $obj->amount_ttc;
3637 }
3638 }
3639 } else {
3640 dol_print_error($db);
3641 }
3642
3643 // Paye partiellement 'escompte'
3644 if (($object->statut == FactureFournisseur::STATUS_CLOSED || $object->statut == FactureFournisseur::STATUS_ABANDONED) && $object->close_code == 'discount_vat') {
3645 print '<tr><td colspan="'.$nbcols.'" class="right nowrap">';
3646 print '<span class="opacitymedium">';
3647 print $form->textwithpicto($langs->trans("Discount"), $langs->trans("HelpEscompte"), - 1);
3648 print '</span>';
3649 print '</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).'</td><td>&nbsp;</td></tr>';
3650 $resteapayeraffiche = 0;
3651 $cssforamountpaymentcomplete = 'amountpaymentneutral';
3652 }
3653 // Paye partiellement ou Abandon 'badsupplier'
3654 if (($object->statut == FactureFournisseur::STATUS_CLOSED || $object->statut == FactureFournisseur::STATUS_ABANDONED) && $object->close_code == 'badsupplier') {
3655 print '<tr><td colspan="'.$nbcols.'" class="right nowrap">';
3656 print '<span class="opacitymedium">';
3657 print $form->textwithpicto($langs->trans("Abandoned"), $langs->trans("HelpAbandonBadCustomer"), - 1);
3658 print '</span>';
3659 print '</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).'</td><td>&nbsp;</td></tr>';
3660 // $resteapayeraffiche=0;
3661 $cssforamountpaymentcomplete = 'amountpaymentneutral';
3662 }
3663 // Paye partiellement ou Abandon 'product_returned'
3664 if (($object->statut == FactureFournisseur::STATUS_CLOSED || $object->statut == FactureFournisseur::STATUS_ABANDONED) && $object->close_code == 'product_returned') {
3665 print '<tr><td colspan="'.$nbcols.'" class="right nowrap">';
3666 print '<span class="opacitymedium">';
3667 print $form->textwithpicto($langs->trans("ProductReturned"), $langs->trans("HelpAbandonProductReturned"), - 1);
3668 print '</span>';
3669 print '</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).'</td><td>&nbsp;</td></tr>';
3670 $resteapayeraffiche = 0;
3671 $cssforamountpaymentcomplete = 'amountpaymentneutral';
3672 }
3673 // Paye partiellement ou Abandon 'abandon'
3674 if (($object->statut == FactureFournisseur::STATUS_CLOSED || $object->statut == FactureFournisseur::STATUS_ABANDONED) && $object->close_code == 'abandon') {
3675 print '<tr><td colspan="'.$nbcols.'" class="right nowrap">';
3676 $text = $langs->trans("HelpAbandonOther");
3677 if ($object->close_note) {
3678 $text .= '<br><br><b>'.$langs->trans("Reason").'</b>:'.$object->close_note;
3679 }
3680 print '<span class="opacitymedium">';
3681 print $form->textwithpicto($langs->trans("Abandoned"), $text, - 1);
3682 print '</span>';
3683 print '</td><td class="right">'.price($object->total_ttc - $creditnoteamount - $depositamount - $totalpaid).'</td><td>&nbsp;</td></tr>';
3684 $resteapayeraffiche = 0;
3685 $cssforamountpaymentcomplete = 'amountpaymentneutral';
3686 }
3687
3688 // Billed
3689 print '<tr><td colspan="'.$nbcols.'" class="right">';
3690 print '<span class="opacitymedium">';
3691 print $langs->trans("Billed");
3692 print '</span>';
3693 print '</td><td class="right">'.price($object->total_ttc).'</td><td>&nbsp;</td></tr>';
3694
3695 // Remainder to pay
3696 print '<tr><td colspan="'.$nbcols.'" class="right">';
3697 print '<span class="opacitymedium">';
3698 print $langs->trans('RemainderToPay');
3699 if ($resteapayeraffiche < 0) {
3700 print ' ('.$langs->trans('NegativeIfExcessPaid').')';
3701 }
3702 print '</span>';
3703 print '</td>';
3704 print '<td class="right'.($resteapayeraffiche ? ' amountremaintopay' : (' '.$cssforamountpaymentcomplete)).'">'.price($resteapayeraffiche).'</td><td>&nbsp;</td></tr>';
3705
3706 // Remainder to pay Multicurrency
3707 if (isModEnabled('multicurreny') && $object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
3708 print '<tr><td colspan="'.$nbcols.'" class="right">';
3709 print '<span class="opacitymedium">';
3710 print $langs->trans('RemainderToPayMulticurrency');
3711 if ($resteapayeraffiche < 0) {
3712 print ' ('.$langs->trans('NegativeIfExcessPaid').')';
3713 }
3714 print '</span>';
3715 print '</td>';
3716 print '<td class="right'.($resteapayeraffiche ? ' amountremaintopay' : (' '.$cssforamountpaymentcomplete)).'">'.(!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency).' '.price(price2num($multicurrency_resteapayer, 'MT')).'</td><td>&nbsp;</td></tr>';
3717 }
3718 } else { // Credit note
3719 $cssforamountpaymentcomplete = 'amountpaymentneutral';
3720
3721 // Total already paid back
3722 print '<tr><td colspan="'.$nbcols.'" class="right">';
3723 print $langs->trans('AlreadyPaidBack');
3724 print ' :</td><td class="right">'.price($sign * $totalpaid).'</td><td>&nbsp;</td></tr>';
3725
3726 // Billed
3727 print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans("Billed").' :</td><td class="right">'.price($sign * $object->total_ttc).'</td><td>&nbsp;</td></tr>';
3728
3729 // Remainder to pay back
3730 print '<tr><td colspan="'.$nbcols.'" class="right">';
3731 print '<span class="opacitymedium">';
3732 print $langs->trans('RemainderToPayBack');
3733 if ($resteapayeraffiche > 0) {
3734 print ' ('.$langs->trans('NegativeIfExcessRefunded').')';
3735 }
3736 print '</td>';
3737 print '</span>';
3738 print '<td class="right'.($resteapayeraffiche ? ' amountremaintopay' : (' '.$cssforamountpaymentcomplete)).'">'.price($sign * $resteapayeraffiche).'</td><td>&nbsp;</td></tr>';
3739
3740 // Remainder to pay back Multicurrency
3741 if (isModEnabled('multicurreny') && $object->multicurrency_code != $conf->currency || $object->multicurrency_tx != 1) {
3742 print '<tr><td colspan="'.$nbcols.'" class="right">';
3743 print '<span class="opacitymedium">';
3744 print $langs->trans('RemainderToPayBackMulticurrency');
3745 if ($resteapayeraffiche> 0) {
3746 print ' ('.$langs->trans('NegativeIfExcessRefunded').')';
3747 }
3748 print '</span>';
3749 print '</td>';
3750 print '<td class="right'.($resteapayeraffiche ? ' amountremaintopay' : (' '.$cssforamountpaymentcomplete)).'">'.(!empty($object->multicurrency_code) ? $object->multicurrency_code : $conf->currency).' '.price(price2num($sign * $object->multicurrency_tx * $resteapayeraffiche, 'MT')).'</td><td>&nbsp;</td></tr>';
3751 }
3752
3753 // Sold credit note
3754 // print '<tr><td colspan="'.$nbcols.'" class="right">'.$langs->trans('TotalTTC').' :</td>';
3755 // print '<td class="right" style="border: 1px solid;" bgcolor="#f0f0f0"><b>'.price($sign *
3756 // $object->total_ttc).'</b></td><td>&nbsp;</td></tr>';
3757 }
3758
3759 print '</table>';
3760 print '</div>';
3761
3762 print '</div>';
3763 print '</div>';
3764
3765 print '<div class="clearboth"></div><br>';
3766
3767 if (!empty($conf->global->MAIN_DISABLE_CONTACTS_TAB)) {
3768 $blocname = 'contacts';
3769 $title = $langs->trans('ContactsAddresses');
3770 include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
3771 }
3772
3773 if (!empty($conf->global->MAIN_DISABLE_NOTES_TAB)) {
3774 $colwidth = 20;
3775 $blocname = 'notes';
3776 $title = $langs->trans('Notes');
3777 include DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php';
3778 }
3779
3780
3781 /*
3782 * Lines
3783 */
3784 print '<form name="addproduct" id="addproduct" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="POST">';
3785 print '<input type="hidden" name="token" value="'.newToken().'">';
3786 print '<input type="hidden" name="action" value="'.(($action != 'editline') ? 'addline' : 'updateline').'">';
3787 print '<input type="hidden" name="mode" value="">';
3788 print '<input type="hidden" name="page_y" value="">';
3789 print '<input type="hidden" name="id" value="'.$object->id.'">';
3790 print '<input type="hidden" name="socid" value="'.$societe->id.'">';
3791 print '<input type="hidden" name="backtopage" value="'.$backtopage.'">';
3792
3793 if (!empty($conf->use_javascript_ajax) && $object->statut == FactureFournisseur::STATUS_DRAFT) {
3794 include DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php';
3795 }
3796
3797 print '<div class="div-table-responsive-no-min">';
3798 print '<table id="tablelines" class="noborder noshadow centpercent">';
3799
3800 global $forceall, $senderissupplier, $dateSelector, $inputalsopricewithtax;
3801 $forceall = 1; $dateSelector = 0; $inputalsopricewithtax = 1;
3802 $senderissupplier = 2; // $senderissupplier=2 is same than 1 but disable test on minimum qty and disable autofill qty with minimum.
3803 //if (!empty($conf->global->SUPPLIER_INVOICE_WITH_NOPRICEDEFINED)) $senderissupplier=2;
3804 if (!empty($conf->global->SUPPLIER_INVOICE_WITH_PREDEFINED_PRICES_ONLY)) {
3805 $senderissupplier = 1;
3806 }
3807
3808 // Show object lines (result may vary according to hidden option MAIN_NO_INPUT_PRICE_WITH_TAX)
3809 if (!empty($object->lines)) {
3810 $object->printObjectLines($action, $societe, $mysoc, $lineid, 1);
3811 }
3812
3813 $num = count($object->lines);
3814
3815 // Form to add new line
3816 if ($object->statut == FactureFournisseur::STATUS_DRAFT && $usercancreate) {
3817 if ($action != 'editline') {
3818 // Add free products/services
3819
3820 $parameters = array();
3821 $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
3822 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
3823 if (empty($reshook))
3824 $object->formAddObjectLine(1, $societe, $mysoc);
3825 }
3826 }
3827
3828 print '</table>';
3829 print '</div>';
3830 print '</form>';
3831
3832 print dol_get_fiche_end();
3833
3834
3835 if ($action != 'presend') {
3836 /*
3837 * Buttons actions
3838 */
3839
3840 print '<div class="tabsAction">';
3841
3842 $parameters = array();
3843 $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been
3844 // modified by hook
3845 if (empty($reshook)) {
3846 // Modify a validated invoice with no payments
3847 if ($object->statut == FactureFournisseur::STATUS_VALIDATED && $action != 'confirm_edit' && $object->getSommePaiement() == 0 && $usercancreate) {
3848 // We check if lines of invoice are not already transfered into accountancy
3849 $ventilExportCompta = $object->getVentilExportCompta(); // Should be 0 since the sum of payments are zero. But we keep the protection.
3850
3851 if ($ventilExportCompta == 0) {
3852 print '<a class="butAction'.($conf->use_javascript_ajax ? ' reposition' : '').'" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit&token='.newToken().'">'.$langs->trans('Modify').'</a>';
3853 } else {
3854 print '<span class="butActionRefused classfortooltip" title="'.$langs->trans("DisabledBecauseDispatchedInBookkeeping").'">'.$langs->trans('Modify').'</span>';
3855 }
3856 }
3857
3858 $discount = new DiscountAbsolute($db);
3859 $result = $discount->fetch(0, 0, $object->id);
3860
3861 // Reopen a standard paid invoice
3862 if (($object->type == FactureFournisseur::TYPE_STANDARD || $object->type == FactureFournisseur::TYPE_REPLACEMENT
3863 || ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE && empty($discount->id))
3864 || ($object->type == FactureFournisseur::TYPE_DEPOSIT && empty($discount->id)))
3865 && ($object->statut == FactureFournisseur::STATUS_CLOSED || $object->statut == FactureFournisseur::STATUS_ABANDONED)) { // A paid invoice (partially or completely)
3866 if (!$objectidnext && $object->close_code != 'replaced' && $usercancreate) { // Not replaced by another invoice
3867 print '<a class="butAction'.($conf->use_javascript_ajax ? ' reposition' : '').'" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=reopen&token='.newToken().'">'.$langs->trans('ReOpen').'</a>';
3868 } else {
3869 if ($usercancreate) {
3870 print '<span class="butActionRefused classfortooltip" title="'.$langs->trans("DisabledBecauseReplacedInvoice").'">'.$langs->trans('ReOpen').'</span>';
3871 } elseif (empty($conf->global->MAIN_BUTTON_HIDE_UNAUTHORIZED)) {
3872 print '<span class="butActionRefused classfortooltip">'.$langs->trans('ReOpen').'</span>';
3873 }
3874 }
3875 }
3876
3877 // Validate
3878 if ($action != 'confirm_edit' && $object->statut == FactureFournisseur::STATUS_DRAFT) {
3879 if (count($object->lines)) {
3880 if ($usercanvalidate) {
3881 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=valid"';
3882 print '>'.$langs->trans('Validate').'</a>';
3883 } else {
3884 print '<a class="butActionRefused classfortooltip" href="#" title="'.dol_escape_htmltag($langs->trans("NotAllowed")).'"';
3885 print '>'.$langs->trans('Validate').'</a>';
3886 }
3887 }
3888 }
3889
3890 // Send by mail
3891 if (empty($user->socid)) {
3892 if (($object->statut == FactureFournisseur::STATUS_VALIDATED || $object->statut == FactureFournisseur::STATUS_CLOSED)) {
3893 if ($usercansend) {
3894 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=presend&mode=init#formmailbeforetitle">'.$langs->trans('SendMail').'</a>';
3895 } else {
3896 print '<span class="butActionRefused classfortooltip">'.$langs->trans('SendMail').'</span>';
3897 }
3898 }
3899 }
3900
3901 // Create payment
3902 if ($object->type != FactureFournisseur::TYPE_CREDIT_NOTE && $object->statut == FactureFournisseur::STATUS_VALIDATED && $object->paye == 0) {
3903 print '<a class="butAction'.($conf->use_javascript_ajax ? ' reposition' : '').'" href="'.DOL_URL_ROOT.'/fourn/facture/paiement.php?facid='.$object->id.'&amp;action=create'.($object->fk_account > 0 ? '&amp;accountid='.$object->fk_account : '').'">'.$langs->trans('DoPayment').'</a>'; // must use facid because id is for payment id not invoice
3904 }
3905
3906 // Reverse back money or convert to reduction
3907 if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE || $object->type == FactureFournisseur::TYPE_DEPOSIT || $object->type == FactureFournisseur::TYPE_STANDARD) {
3908 // For credit note only
3909 if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0) {
3910 if ($resteapayer == 0) {
3911 print '<span class="butActionRefused classfortooltip" title="'.$langs->trans("DisabledBecauseRemainderToPayIsZero").'">'.$langs->trans('DoPaymentBack').'</span>';
3912 } else {
3913 print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/facture/paiement.php?facid='.$object->id.'&amp;action=create&amp;accountid='.$object->fk_account.'">'.$langs->trans('DoPaymentBack').'</a>';
3914 }
3915 }
3916
3917 // For standard invoice with excess paid
3918 if ($object->type == FactureFournisseur::TYPE_STANDARD && empty($object->paye) && ($object->total_ttc - $totalpaid - $totalcreditnotes - $totaldeposits) < 0 && $usercancreate && empty($discount->id)) {
3919 print '<a class="butAction'.($conf->use_javascript_ajax ? ' reposition' : '').'" href="'.$_SERVER["PHP_SELF"].'?facid='.$object->id.'&amp;action=converttoreduc">'.$langs->trans('ConvertExcessPaidToReduc').'</a>';
3920 }
3921 // For credit note
3922 if ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $usercancreate
3923 && (!empty($conf->global->SUPPLIER_INVOICE_ALLOW_REUSE_OF_CREDIT_WHEN_PARTIALLY_REFUNDED) || $object->getSommePaiement() == 0)
3924 ) {
3925 print '<a class="butAction'.($conf->use_javascript_ajax ? ' reposition' : '').'" href="'.$_SERVER["PHP_SELF"].'?facid='.$object->id.'&amp;action=converttoreduc" title="'.dol_escape_htmltag($langs->trans("ConfirmConvertToReducSupplier2")).'">'.$langs->trans('ConvertToReduc').'</a>';
3926 }
3927 // For deposit invoice
3928 if ($object->type == FactureFournisseur::TYPE_DEPOSIT && $usercancreate && $object->statut > 0 && empty($discount->id)) {
3929 print '<a class="butAction'.($conf->use_javascript_ajax ? ' reposition' : '').'" href="'.$_SERVER["PHP_SELF"].'?facid='.$object->id.'&amp;action=converttoreduc">'.$langs->trans('ConvertToReduc').'</a>';
3930 }
3931 }
3932
3933 // Classify paid
3934 if ($object->statut == FactureFournisseur::STATUS_VALIDATED && $object->paye == 0 && (
3935 ($object->type != FactureFournisseur::TYPE_CREDIT_NOTE && $object->type != FactureFournisseur::TYPE_DEPOSIT && ($resteapayer <= 0 || (!empty($conf->global->SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) && $object->total_ttc == $resteapayer))) ||
3936 ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE && $resteapayer >= 0) ||
3937 ($object->type == FactureFournisseur::TYPE_DEPOSIT && $object->total_ttc > 0 && ($resteapayer == 0 || (!empty($conf->global->SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) && $object->total_ttc == $resteapayer)))
3938 )
3939 ) {
3940 print '<a class="butAction'.($conf->use_javascript_ajax ? ' reposition' : '').'" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=paid">'.$langs->trans('ClassifyPaid').'</a>';
3941 }
3942
3943 // Classify 'closed not completely paid' (possible if validated and not yet filed paid)
3944 if ($object->statut == FactureFournisseur::STATUS_VALIDATED && $object->paye == 0 && $resteapayer > 0 && (empty($conf->global->SUPPLIER_INVOICE_CAN_SET_PAID_EVEN_IF_PARTIALLY_PAID) || $object->total_ttc != $resteapayer)) {
3945 if ($totalpaid > 0 || $totalcreditnotes > 0) {
3946 // If one payment or one credit note was linked to this invoice
3947 print '<a class="butAction'.($conf->use_javascript_ajax ? ' reposition' : '').'" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=paid">'.$langs->trans('ClassifyPaidPartially').'</a>';
3948 } else {
3949 if (empty($conf->global->INVOICE_CAN_NEVER_BE_CANCELED)) {
3950 print '<a class="butAction'.($conf->use_javascript_ajax ? ' reposition' : '').'" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=canceled">'.$langs->trans('ClassifyCanceled').'</a>';
3951 }
3952 }
3953 }
3954
3955 // Create event
3956 /*if (isModEnabled('agenda') && !empty($conf->global->MAIN_ADD_EVENT_ON_ELEMENT_CARD)) // Add hidden condition because this is not a "workflow" action so should appears somewhere else on page.
3957 {
3958 print '<div class="inline-block divButAction"><a class="butAction" href="' . DOL_URL_ROOT . '/comm/action/card.php?action=create&amp;origin=' . $object->element . '&amp;originid=' . $object->id . '&amp;socid=' . $object->socid . '">' . $langs->trans("AddAction") . '</a></div>';
3959 }*/
3960
3961 // Create a credit note
3962 if (($object->type == FactureFournisseur::TYPE_STANDARD || $object->type == FactureFournisseur::TYPE_DEPOSIT) && $object->statut > 0 && $usercancreate) {
3963 if (!$objectidnext) {
3964 print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?socid='.$object->socid.'&amp;fac_avoir='.$object->id.'&amp;action=create&amp;type=2'.($object->fk_project > 0 ? '&amp;projectid='.$object->fk_project : '').'">'.$langs->trans("CreateCreditNote").'</a>';
3965 }
3966 }
3967
3968 // Clone
3969 if ($action != 'edit' && $usercancreate) {
3970 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&amp;action=clone&amp;socid='.$object->socid.'">'.$langs->trans('ToClone').'</a>';
3971 }
3972
3973 // Clone as predefined / Create template
3974 if (($object->type == FactureFournisseur::TYPE_STANDARD || $object->type == FactureFournisseur::TYPE_DEPOSIT) && $object->statut == 0 && $usercancreate) {
3975 if (!$objectidnext && count($object->lines) > 0) {
3976 print '<a class="butAction" href="'.DOL_URL_ROOT.'/fourn/facture/card-rec.php?facid='.$object->id.'&amp;action=create">'.$langs->trans("ChangeIntoRepeatableInvoice").'</a>';
3977 }
3978 }
3979
3980 // Delete
3981 $isErasable = $object->is_erasable();
3982 if ($action != 'confirm_edit' && ($usercandelete || ($usercancreate && $isErasable == 1))) { // isErasable = 1 means draft with temporary ref (draft can always be deleted with no need of permissions)
3983 $enableDelete = false;
3984 $htmltooltip = '';
3985 $params = (empty($conf->use_javascript_ajax) ? array() : array('attr' => array('class' => 'reposition')));
3986 //var_dump($isErasable); var_dump($params);
3987 if ($isErasable == -4) {
3988 $htmltooltip = $langs->trans("DisabledBecausePayments");
3989 } elseif ($isErasable == -3) { // Should never happen with supplier invoice
3990 $htmltooltip = $langs->trans("DisabledBecauseNotLastSituationInvoice");
3991 } elseif ($isErasable == -2) { // Should never happen with supplier invoice
3992 $htmltooltip = $langs->trans("DisabledBecauseNotLastInvoice");
3993 } elseif ($isErasable == -1) {
3994 $htmltooltip = $langs->trans("DisabledBecauseDispatchedInBookkeeping");
3995 } elseif ($isErasable <= 0) { // Any other cases
3996 $htmltooltip = $langs->trans("DisabledBecauseNotErasable");
3997 } else {
3998 $enableDelete = true;
3999 $htmltooltip = '';
4000 }
4001 print dolGetButtonAction($htmltooltip, $langs->trans("Delete"), 'delete', $_SERVER["PHP_SELF"].'?id='.$object->id.'&action=delete&token='.newToken(), $object->id, $enableDelete, $params);
4002 }
4003 print '</div>';
4004
4005 if ($action != 'confirm_edit') {
4006 print '<div class="fichecenter"><div class="fichehalfleft">';
4007
4008 /*
4009 * Generated documents
4010 */
4011 $ref = dol_sanitizeFileName($object->ref);
4012 $subdir = get_exdir($object->id, 2, 0, 0, $object, 'invoice_supplier').$ref;
4013 $filedir = $conf->fournisseur->facture->dir_output.'/'.$subdir;
4014 $urlsource = $_SERVER['PHP_SELF'].'?id='.$object->id;
4015 $genallowed = $usercanread;
4016 $delallowed = $usercancreate;
4017 $modelpdf = (!empty($object->model_pdf) ? $object->model_pdf : (empty($conf->global->INVOICE_SUPPLIER_ADDON_PDF) ? '' : $conf->global->INVOICE_SUPPLIER_ADDON_PDF));
4018
4019 print $formfile->showdocuments('facture_fournisseur', $subdir, $filedir, $urlsource, $genallowed, $delallowed, $modelpdf, 1, 0, 0, 40, 0, '', '', '', $societe->default_lang);
4020 $somethingshown = $formfile->numoffiles;
4021
4022 // Show links to link elements
4023 $linktoelem = $form->showLinkToObjectBlock($object, null, array('invoice_supplier'));
4024 $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
4025
4026 print '</div><div class="fichehalfright">';
4027
4028 // List of actions on element
4029 include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
4030 $formactions = new FormActions($db);
4031 $somethingshown = $formactions->showactions($object, 'invoice_supplier', $socid, 1, 'listaction'.($genallowed ? 'largetitle' : ''));
4032
4033 print '</div></div>';
4034 }
4035 }
4036 }
4037
4038 // Select mail models is same action as presend
4039 if (GETPOST('modelselected')) {
4040 $action = 'presend';
4041 }
4042
4043 // Presend form
4044 $modelmail = 'invoice_supplier_send';
4045 $defaulttopic = 'SendBillRef';
4046 $diroutput = $conf->fournisseur->facture->dir_output;
4047 $autocopy = 'MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO';
4048 $trackid = 'sinv'.$object->id;
4049
4050 include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
4051 }
4052}
4053
4054
4055// End of page
4056llxFooter();
4057$db->close();
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') elseif( $action=='specimen') elseif($action=='setmodel') elseif( $action=='del') elseif($action=='setdoc') $formactions
View.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:56
llxFooter()
Empty footer.
Definition wrapper.php:70
Class to manage bank accounts.
Class to manage accounting accounts.
const TYPE_SITUATION
Situation invoice.
Class to manage absolute discounts.
Class to manage a WYSIWYG editor.
Class to manage warehouses.
Class to manage standard extra fields.
Class to manage suppliers invoices.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
const TYPE_REPLACEMENT
Replacement invoice.
const STATUS_VALIDATED
Validated (need to be paid)
const TYPE_STANDARD
Standard invoice.
const STATUS_ABANDONED
Classified abandoned and no payment done.
const STATUS_CLOSED
Classified paid.
Class to manage invoice templates.
Class to manage building of HTML components.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class with static methods for building HTML components related to products Only components common to ...
Class to manage building of HTML components.
static getIdAndTxFromCode($dbs, $code, $date_document='')
Get id and rate of currency from code.
Class to manage payments for supplier invoices.
Class ProductCombination Used to represent a product combination.
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.
isInEEC($object)
Return if a country of an object is inside the EEC (European Economic Community)
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:624
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0)
Add a delay to a date.
Definition date.lib.php:123
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.
facturefourn_prepare_head(FactureFournisseur $object)
Prepare array with list of tabs.
Definition fourn.lib.php:35
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_delete($titlealt='default', $other='class="pictodelete"', $morecss='')
Show delete logo.
GETPOSTINT($paramname, $method=0)
Return value of a param into GET or POST supervariable.
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_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_clone($object, $native=0)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
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...
dol_htmloutput_events($disabledoutputofmessages=0)
Print formated messages to output (Used to show messages on html output).
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
get_localtax($vatrate, $local, $thirdparty_buyer="", $thirdparty_seller="", $vatnpr=0)
Return localtax rate for a particular vat, when selling a product with vat $vatrate,...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
img_edit($titlealt='default', $float=0, $other='')
Show logo editer/modifier 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_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
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...
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.