PageRenderTime 57ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/fourn/facture/fiche.php

https://bitbucket.org/speedealing/speedealing
PHP | 2050 lines | 1511 code | 265 blank | 274 comment | 411 complexity | 115b42541377c57293f0d9e88edc0235 MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2012 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-2012 Regis Houssin <regis.houssin@capnetworks.com>
  7. * Copyright (C) 2010-2012 Juanjo Menent <jmenent@2byte.es>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \file htdocs/fourn/facture/fiche.php
  24. * \ingroup facture, fournisseur
  25. * \brief Page for supplier invoice card (view, edit, validate)
  26. */
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  29. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_invoice/modules_facturefournisseur.php';
  31. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/fourn/class/paiementfourn.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
  34. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  35. if (! empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  36. $langs->load('bills');
  37. $langs->load('suppliers');
  38. $langs->load('companies');
  39. $mesg='';
  40. $errors=array();
  41. $id = (GETPOST('facid','int') ? GETPOST('facid','int') : GETPOST('id','int'));
  42. $action = GETPOST("action");
  43. $confirm = GETPOST("confirm");
  44. //PDF
  45. $hidedetails = (GETPOST('hidedetails','int') ? GETPOST('hidedetails','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
  46. $hidedesc = (GETPOST('hidedesc','int') ? GETPOST('hidedesc','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
  47. $hideref = (GETPOST('hideref','int') ? GETPOST('hideref','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
  48. // Security check
  49. $socid='';
  50. if (! empty($user->societe_id)) $socid=$user->societe_id;
  51. $result = restrictedArea($user, 'fournisseur', $id, 'facture_fourn', 'facture');
  52. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  53. $hookmanager->initHooks(array('invoicesuppliercard'));
  54. $object=new FactureFournisseur($db);
  55. /*
  56. * Actions
  57. */
  58. // Action clone object
  59. if ($action == 'confirm_clone' && $confirm == 'yes')
  60. {
  61. if (1==0 && empty($_REQUEST["clone_content"]) && empty($_REQUEST["clone_receivers"]))
  62. {
  63. $mesg='<div class="error">'.$langs->trans("NoCloneOptionsSpecified").'</div>';
  64. }
  65. else
  66. {
  67. $result=$object->createFromClone($id);
  68. if ($result > 0)
  69. {
  70. header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
  71. exit;
  72. }
  73. else
  74. {
  75. $langs->load("errors");
  76. $mesg='<div class="error">'.$langs->trans($object->error).'</div>';
  77. $action='';
  78. }
  79. }
  80. }
  81. elseif ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->fournisseur->facture->valider)
  82. {
  83. $idwarehouse=GETPOST('idwarehouse');
  84. $object->fetch($id);
  85. $object->fetch_thirdparty();
  86. // Check parameters
  87. if (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $object->hasProductsOrServices(1))
  88. {
  89. $langs->load("stocks");
  90. if (! $idwarehouse || $idwarehouse == -1)
  91. {
  92. $error++;
  93. $errors[]=$langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("Warehouse"));
  94. $action='';
  95. }
  96. }
  97. if (! $error)
  98. {
  99. $result = $object->validate($user,'',$idwarehouse);
  100. if ($result < 0)
  101. {
  102. $mesg='<div class="error">'.$object->error.'</div>';
  103. }
  104. }
  105. }
  106. elseif ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->fournisseur->facture->supprimer)
  107. {
  108. $object->fetch($id);
  109. $object->fetch_thirdparty();
  110. $result=$object->delete($id);
  111. if ($result > 0)
  112. {
  113. header('Location: index.php');
  114. exit;
  115. }
  116. else
  117. {
  118. $mesg='<div class="error">'.$object->error.'</div>';
  119. }
  120. }
  121. elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->fournisseur->facture->creer)
  122. {
  123. $object->fetch($id);
  124. $ret = $object->deleteline(GETPOST('lineid'));
  125. if ($ret > 0)
  126. {
  127. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
  128. exit;
  129. }
  130. else
  131. {
  132. $mesg='<div class="error">'.$object->error.'</div>';
  133. }
  134. }
  135. elseif ($action == 'confirm_paid' && $confirm == 'yes' && $user->rights->fournisseur->facture->creer)
  136. {
  137. $object->fetch($id);
  138. $result=$object->set_paid($user);
  139. }
  140. // Set supplier ref
  141. elseif ($action == 'setfacnumber' && $user->rights->fournisseur->facture->creer)
  142. {
  143. $object->fetch($id);
  144. $result=$object->set_ref_supplier($user, GETPOST('facnumber'));
  145. }
  146. // Set label
  147. elseif ($action == 'setlabel' && $user->rights->fournisseur->facture->creer)
  148. {
  149. $object->fetch($id);
  150. $object->label=$_POST['label'];
  151. $result=$object->update($user);
  152. if ($result < 0) dol_print_error($db);
  153. }
  154. elseif ($action == 'setdatef' && $user->rights->fournisseur->facture->creer)
  155. {
  156. $object->fetch($id);
  157. $object->date=dol_mktime(12,0,0,$_POST['datefmonth'],$_POST['datefday'],$_POST['datefyear']);
  158. if ($object->date_echeance < $object->date) $object->date_echeance=$object->date;
  159. $result=$object->update($user);
  160. if ($result < 0) dol_print_error($db,$object->error);
  161. }
  162. elseif ($action == 'setdate_lim_reglement' && $user->rights->fournisseur->facture->creer)
  163. {
  164. $object->fetch($id);
  165. $object->date_echeance=dol_mktime(12,0,0,$_POST['date_lim_reglementmonth'],$_POST['date_lim_reglementday'],$_POST['date_lim_reglementyear']);
  166. if ($object->date_echeance < $object->date) $object->date_echeance=$object->date;
  167. $result=$object->update($user);
  168. if ($result < 0) dol_print_error($db,$object->error);
  169. }
  170. elseif ($action == 'setnote_public' && $user->rights->fournisseur->facture->creer)
  171. {
  172. $object->fetch($id);
  173. $result=$object->update_note_public(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES));
  174. if ($result < 0) dol_print_error($db,$object->error);
  175. }
  176. elseif ($action == 'setnote' && $user->rights->fournisseur->facture->creer)
  177. {
  178. $object->fetch($id);
  179. $result=$object->update_note(dol_html_entity_decode(GETPOST('note'), ENT_QUOTES));
  180. if ($result < 0) dol_print_error($db,$object->error);
  181. }
  182. // Delete payment
  183. elseif ($action == 'deletepaiement')
  184. {
  185. $object->fetch($id);
  186. if ($object->statut == 1 && $object->paye == 0 && $user->societe_id == 0)
  187. {
  188. $paiementfourn = new PaiementFourn($db);
  189. $paiementfourn->fetch(GETPOST('paiement_id'));
  190. $result=$paiementfourn->delete();
  191. if ($result < 0) $mesg='<div class="error">'.$paiementfourn->error.'</div>';
  192. }
  193. }
  194. // Create
  195. elseif ($action == 'add' && $user->rights->fournisseur->facture->creer)
  196. {
  197. $error=0;
  198. $datefacture=dol_mktime(12,0,0,$_POST['remonth'],$_POST['reday'],$_POST['reyear']);
  199. $datedue=dol_mktime(12,0,0,$_POST['echmonth'],$_POST['echday'],$_POST['echyear']);
  200. if ($datefacture == '')
  201. {
  202. $mesg='<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('DateInvoice')).'</div>';
  203. $action='create';
  204. $_GET['socid']=$_POST['socid'];
  205. $error++;
  206. }
  207. if (! GETPOST('facnumber'))
  208. {
  209. $mesg='<div class="error">'.$langs->trans('ErrorFieldRequired',$langs->transnoentities('RefSupplier')).'</div>';
  210. $action='create';
  211. $_GET['socid']=$_POST['socid'];
  212. $error++;
  213. }
  214. if (! $error)
  215. {
  216. $db->begin();
  217. // Creation facture
  218. $object->ref = $_POST['facnumber'];
  219. $object->socid = $_POST['socid'];
  220. $object->libelle = $_POST['libelle'];
  221. $object->date = $datefacture;
  222. $object->date_echeance = $datedue;
  223. $object->note_public = $_POST['note'];
  224. // If creation from another object of another module
  225. if ($_POST['origin'] && $_POST['originid'])
  226. {
  227. // Parse element/subelement (ex: project_task)
  228. $element = $subelement = $_POST['origin'];
  229. /*if (preg_match('/^([^_]+)_([^_]+)/i',$_POST['origin'],$regs))
  230. {
  231. $element = $regs[1];
  232. $subelement = $regs[2];
  233. }*/
  234. // For compatibility
  235. if ($element == 'order') {
  236. $element = $subelement = 'commande';
  237. }
  238. if ($element == 'propal') {
  239. $element = 'comm/propal'; $subelement = 'propal';
  240. }
  241. if ($element == 'contract') {
  242. $element = $subelement = 'contrat';
  243. }
  244. if ($element == 'order_supplier') {
  245. $element = 'fourn'; $subelement = 'fournisseur.commande';
  246. }
  247. $object->origin = $_POST['origin'];
  248. $object->origin_id = $_POST['originid'];
  249. $id = $object->create($user);
  250. // Add lines
  251. if ($id > 0)
  252. {
  253. require_once DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php';
  254. $classname = ucfirst($subelement);
  255. if ($classname == 'Fournisseur.commande') $classname='CommandeFournisseur';
  256. $srcobject = new $classname($db);
  257. $result=$srcobject->fetch($_POST['originid']);
  258. if ($result > 0)
  259. {
  260. $lines = $srcobject->lines;
  261. if (empty($lines) && method_exists($srcobject,'fetch_lines')) $lines = $srcobject->fetch_lines();
  262. $num=count($lines);
  263. for ($i = 0; $i < $num; $i++)
  264. {
  265. $desc=($lines[$i]->desc?$lines[$i]->desc:$lines[$i]->libelle);
  266. $product_type=($lines[$i]->product_type?$lines[$i]->product_type:0);
  267. // Dates
  268. // TODO mutualiser
  269. $date_start=$lines[$i]->date_debut_prevue;
  270. if ($lines[$i]->date_debut_reel) $date_start=$lines[$i]->date_debut_reel;
  271. if ($lines[$i]->date_start) $date_start=$lines[$i]->date_start;
  272. $date_end=$lines[$i]->date_fin_prevue;
  273. if ($lines[$i]->date_fin_reel) $date_end=$lines[$i]->date_fin_reel;
  274. if ($lines[$i]->date_end) $date_end=$lines[$i]->date_end;
  275. $result = $object->addline(
  276. $desc,
  277. $lines[$i]->subprice,
  278. $lines[$i]->tva_tx,
  279. $lines[$i]->localtax1_tx,
  280. $lines[$i]->localtax2_tx,
  281. $lines[$i]->qty,
  282. $lines[$i]->fk_product,
  283. $lines[$i]->remise_percent,
  284. $date_start,
  285. $date_end,
  286. 0,
  287. $lines[$i]->info_bits,
  288. 'HT',
  289. $product_type
  290. );
  291. if ($result < 0)
  292. {
  293. $error++;
  294. break;
  295. }
  296. }
  297. }
  298. else
  299. {
  300. $error++;
  301. }
  302. }
  303. else
  304. {
  305. $error++;
  306. }
  307. }
  308. // If some invoice's lines already known
  309. else
  310. {
  311. $id = $object->create($user);
  312. if ($id < 0)
  313. {
  314. $error++;
  315. }
  316. if (! $error)
  317. {
  318. for ($i = 1 ; $i < 9 ; $i++)
  319. {
  320. $label = $_POST['label'.$i];
  321. $amountht = price2num($_POST['amount'.$i]);
  322. $amountttc = price2num($_POST['amountttc'.$i]);
  323. $tauxtva = price2num($_POST['tauxtva'.$i]);
  324. $qty = $_POST['qty'.$i];
  325. $fk_product = $_POST['fk_product'.$i];
  326. if ($label)
  327. {
  328. if ($amountht)
  329. {
  330. $price_base='HT'; $amount=$amountht;
  331. }
  332. else
  333. {
  334. $price_base='TTC'; $amount=$amountttc;
  335. }
  336. $atleastoneline=1;
  337. $product=new Product($db);
  338. $product->fetch($_POST['idprod'.$i]);
  339. $ret=$object->addline($label, $amount, $tauxtva, $product->localtax1_tx, $product->localtax2_tx, $qty, $fk_product, $remise_percent, '', '', '', 0, $price_base);
  340. if ($ret < 0) $error++;
  341. }
  342. }
  343. }
  344. }
  345. if ($error)
  346. {
  347. $langs->load("errors");
  348. $db->rollback();
  349. $mesg='<div class="error">'.$langs->trans($object->error).'</div>';
  350. $action='create';
  351. $_GET['socid']=$_POST['socid'];
  352. }
  353. else
  354. {
  355. $db->commit();
  356. header("Location: ".$_SERVER['PHP_SELF']."?id=".$id);
  357. exit;
  358. }
  359. }
  360. }
  361. // Modification d'une ligne
  362. elseif ($action == 'update_line')
  363. {
  364. if (GETPOST('etat') == '1' && ! GETPOST('cancel')) // si on valide la modification
  365. {
  366. $object->fetch($id);
  367. $object->fetch_thirdparty();
  368. if ($_POST['puht'])
  369. {
  370. $pu=$_POST['puht'];
  371. $price_base_type='HT';
  372. }
  373. if ($_POST['puttc'])
  374. {
  375. $pu=$_POST['puttc'];
  376. $price_base_type='TTC';
  377. }
  378. if (GETPOST('idprod'))
  379. {
  380. $prod = new Product($db);
  381. $prod->fetch($_POST['idprod']);
  382. $label = $prod->description;
  383. if (trim($_POST['desc']) != trim($label)) $label=$_POST['desc'];
  384. $type = $prod->type;
  385. }
  386. else
  387. {
  388. $label = $_POST['desc'];
  389. $type = $_POST["type"]?$_POST["type"]:0;
  390. }
  391. $localtax1tx= get_localtax($_POST['tauxtva'], 1, $object->thirdparty);
  392. $localtax2tx= get_localtax($_POST['tauxtva'], 2, $object->thirdparty);
  393. $remise_percent=GETPOST('remise_percent');
  394. $result=$object->updateline(GETPOST('lineid'), $label, $pu, GETPOST('tauxtva'), $localtax1tx, $localtax2tx, GETPOST('qty'), GETPOST('idprod'), $price_base_type, 0, $type, $remise_percent);
  395. if ($result >= 0)
  396. {
  397. unset($_POST['label']);
  398. }
  399. }
  400. }
  401. elseif ($action == 'addline')
  402. {
  403. $ret=$object->fetch($id);
  404. if ($ret < 0)
  405. {
  406. dol_print_error($db,$object->error);
  407. exit;
  408. }
  409. $ret=$object->fetch_thirdparty();
  410. if ($_POST['idprodfournprice']) // > 0 or -1
  411. {
  412. $product=new Product($db);
  413. $idprod=$product->get_buyprice($_POST['idprodfournprice'], $_POST['qty']); // Just to see if a price exists for the quantity. Not used to found vat
  414. if ($idprod > 0)
  415. {
  416. $result=$product->fetch($idprod);
  417. // cas special pour lequel on a les meme reference que le fournisseur
  418. // $label = '['.$product->ref.'] - '. $product->libelle;
  419. $label = $product->description;
  420. $label.= $product->description && $_POST['np_desc'] ? "\n" : "";
  421. $label.= $_POST['np_desc'];
  422. $tvatx=get_default_tva($object->thirdparty, $mysoc, $product->id, $_POST['idprodfournprice']);
  423. $localtax1tx= get_localtax($tvatx, 1, $object->thirdparty);
  424. $localtax2tx= get_localtax($tvatx, 2, $object->thirdparty);
  425. $remise_percent=GETPOST('remise_percent');
  426. $type = $product->type;
  427. $result=$object->addline($label, $product->fourn_pu, $tvatx, $localtax1tx, $localtax2tx, $_POST['qty'], $idprod, $remise_percent);
  428. }
  429. if ($idprod == -1)
  430. {
  431. // Quantity too low
  432. $langs->load("errors");
  433. $mesg='<div class="error">'.$langs->trans("ErrorQtyTooLowForThisSupplier").'</div>';
  434. }
  435. }
  436. else
  437. {
  438. $tauxtva = price2num($_POST['tauxtva']);
  439. $localtax1tx= get_localtax($tauxtva, 1, $object->thirdparty);
  440. $localtax2tx= get_localtax($tauxtva, 2, $object->thirdparty);
  441. $remise_percent=GETPOST('remise_percent');
  442. if (! $_POST['dp_desc'])
  443. {
  444. $mesg='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->transnoentities("Description")).'</div>';
  445. }
  446. else
  447. {
  448. $type = $_POST["type"];
  449. if (! empty($_POST['amount']))
  450. {
  451. $ht = price2num($_POST['amount']);
  452. $price_base_type = 'HT';
  453. //$desc, $pu, $txtva, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0)
  454. $result=$object->addline($_POST['dp_desc'], $ht, $tauxtva, $localtax1tx, $localtax2tx, $_POST['qty'], 0, $remise_percent, $datestart, $dateend, 0, 0, $price_base_type, $type);
  455. }
  456. else
  457. {
  458. $ttc = price2num($_POST['amountttc']);
  459. $ht = $ttc / (1 + ($tauxtva / 100));
  460. $price_base_type = 'HT';
  461. $result=$object->addline($_POST['dp_desc'], $ht, $tauxtva,$localtax1tx, $localtax2tx, $_POST['qty'], 0, $remise_percent, $datestart, $dateend, 0, 0, $price_base_type, $type);
  462. }
  463. }
  464. }
  465. //print "xx".$tva_tx; exit;
  466. if ($result > 0)
  467. {
  468. // Define output language
  469. $outputlangs = $langs;
  470. $newlang=GETPOST('lang_id','alpha');
  471. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  472. if (! empty($newlang))
  473. {
  474. $outputlangs = new Translate();
  475. $outputlangs->setDefaultLang($newlang);
  476. }
  477. //if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) supplier_invoice_pdf_create($db, $object->id, $object->modelpdf, $outputlangs);
  478. unset($_POST['qty']);
  479. unset($_POST['type']);
  480. unset($_POST['idprodfournprice']);
  481. unset($_POST['remise_percent']);
  482. unset($_POST['dp_desc']);
  483. unset($_POST['np_desc']);
  484. unset($_POST['pu']);
  485. unset($_POST['tva_tx']);
  486. unset($_POST['label']);
  487. unset($localtax1_tx);
  488. unset($localtax2_tx);
  489. }
  490. else if (empty($mesg))
  491. {
  492. $mesg='<div class="error">'.$object->error.'</div>';
  493. }
  494. $action = '';
  495. }
  496. elseif ($action == 'classin')
  497. {
  498. $object->fetch($id);
  499. $result=$object->setProject($_POST['projectid']);
  500. }
  501. // Set invoice to draft status
  502. elseif ($action == 'edit' && $user->rights->fournisseur->facture->creer)
  503. {
  504. $object->fetch($id);
  505. $totalpaye = $object->getSommePaiement();
  506. $resteapayer = $object->total_ttc - $totalpaye;
  507. // On verifie si les lignes de factures ont ete exportees en compta et/ou ventilees
  508. //$ventilExportCompta = $object->getVentilExportCompta();
  509. // On verifie si aucun paiement n'a ete effectue
  510. if ($resteapayer == $object->total_ttc && $object->paye == 0 && $ventilExportCompta == 0)
  511. {
  512. $object->set_draft($user);
  513. $outputlangs = $langs;
  514. if (! empty($_REQUEST['lang_id']))
  515. {
  516. $outputlangs = new Translate();
  517. $outputlangs->setDefaultLang($_REQUEST['lang_id']);
  518. }
  519. //if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) supplier_invoice_pdf_create($db, $object->id, $object->modelpdf, $outputlangs);
  520. }
  521. }
  522. // Set invoice to validated/unpaid status
  523. elseif ($action == 'reopen' && $user->rights->fournisseur->facture->creer)
  524. {
  525. $result = $object->fetch($id);
  526. if ($object->statut == 2
  527. || ($object->statut == 3 && $object->close_code != 'replaced'))
  528. {
  529. $result = $object->set_unpaid($user);
  530. if ($result > 0)
  531. {
  532. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
  533. exit;
  534. }
  535. else
  536. {
  537. $mesg='<div class="error">'.$object->error.'</div>';
  538. }
  539. }
  540. }
  541. // Add file in email form
  542. if (GETPOST('addfile'))
  543. {
  544. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  545. // Set tmp user directory TODO Use a dedicated directory for temp mails files
  546. $vardir=$conf->user->dir_output."/".$user->id;
  547. $upload_dir_tmp = $vardir.'/temp';
  548. dol_add_file_process($upload_dir_tmp,0,0);
  549. $action='presend';
  550. }
  551. // Remove file in email form
  552. if (! empty($_POST['removedfile']))
  553. {
  554. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  555. // Set tmp user directory
  556. $vardir=$conf->user->dir_output."/".$user->id;
  557. $upload_dir_tmp = $vardir.'/temp';
  558. // TODO Delete only files that was uploaded from email form
  559. dol_remove_file_process($_POST['removedfile'],0);
  560. $action='presend';
  561. }
  562. // Send mail
  563. if ($action == 'send' && ! $_POST['addfile'] && ! $_POST['removedfile'] && ! $_POST['cancel'])
  564. {
  565. $langs->load('mails');
  566. $object->fetch($id);
  567. $result=$object->fetch_thirdparty();
  568. if ($result > 0)
  569. {
  570. // $ref = dol_sanitizeFileName($object->ref);
  571. // $file = $conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref.'/'.$ref.'.pdf';
  572. // if (is_readable($file))
  573. // {
  574. if ($_POST['sendto'])
  575. {
  576. // Le destinataire a ete fourni via le champ libre
  577. $sendto = $_POST['sendto'];
  578. $sendtoid = 0;
  579. }
  580. elseif ($_POST['receiver'] != '-1')
  581. {
  582. // Recipient was provided from combo list
  583. if ($_POST['receiver'] == 'thirdparty') // Id of third party
  584. {
  585. $sendto = $object->client->email;
  586. $sendtoid = 0;
  587. }
  588. else // Id du contact
  589. {
  590. $sendto = $object->client->contact_get_property($_POST['receiver'],'email');
  591. $sendtoid = $_POST['receiver'];
  592. }
  593. }
  594. if (dol_strlen($sendto))
  595. {
  596. $langs->load("commercial");
  597. $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';
  598. $replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>';
  599. $message = $_POST['message'];
  600. $sendtocc = $_POST['sendtocc'];
  601. $deliveryreceipt = $_POST['deliveryreceipt'];
  602. if ($action == 'send')
  603. {
  604. if (dol_strlen($_POST['subject'])) $subject=$_POST['subject'];
  605. else $subject = $langs->transnoentities('CustomerOrder').' '.$object->ref;
  606. $actiontypecode='AC_SUP_ORD';
  607. $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n";
  608. if ($message)
  609. {
  610. $actionmsg.=$langs->transnoentities('MailTopic').": ".$subject."\n";
  611. $actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody').":\n";
  612. $actionmsg.=$message;
  613. }
  614. $actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
  615. }
  616. // Create form object
  617. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php';
  618. $formmail = new FormMail($db);
  619. $attachedfiles=$formmail->get_attached_files();
  620. $filepath = $attachedfiles['paths'];
  621. $filename = $attachedfiles['names'];
  622. $mimetype = $attachedfiles['mimes'];
  623. // Send mail
  624. require_once DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php';
  625. $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt);
  626. if ($mailfile->error)
  627. {
  628. $mesg='<div class="error">'.$mailfile->error.'</div>';
  629. }
  630. else
  631. {
  632. $result=$mailfile->sendfile();
  633. if ($result)
  634. {
  635. $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2)); // Must not contain "
  636. $error=0;
  637. // Initialisation donnees
  638. $object->sendtoid = $sendtoid;
  639. $object->actiontypecode = $actiontypecode;
  640. $object->actionmsg = $actionmsg;
  641. $object->actionmsg2 = $actionmsg2;
  642. $object->fk_element = $object->id;
  643. $object->elementtype = $object->element;
  644. // Appel des triggers
  645. include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
  646. $interface=new Interfaces($db);
  647. $result=$interface->run_triggers('BILL_SUPPLIER_SENTBYMAIL',$object,$user,$langs,$conf);
  648. if ($result < 0) {
  649. $error++; $this->errors=$interface->errors;
  650. }
  651. // Fin appel triggers
  652. if ($error)
  653. {
  654. dol_print_error($db);
  655. }
  656. else
  657. {
  658. // Redirect here
  659. // This avoid sending mail twice if going out and then back to page
  660. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.'&mesg='.urlencode($mesg));
  661. exit;
  662. }
  663. }
  664. else
  665. {
  666. $langs->load("other");
  667. $mesg='<div class="error">';
  668. if ($mailfile->error)
  669. {
  670. $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
  671. $mesg.='<br>'.$mailfile->error;
  672. }
  673. else
  674. {
  675. $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
  676. }
  677. $mesg.='</div>';
  678. }
  679. }
  680. }
  681. else
  682. {
  683. $langs->load("other");
  684. $mesg='<div class="error">'.$langs->trans('ErrorMailRecipientIsEmpty').'</div>';
  685. dol_syslog('Recipient email is empty');
  686. }
  687. /* }
  688. else
  689. {
  690. $langs->load("errors");
  691. $mesg='<div class="error">'.$langs->trans('ErrorCantReadFile',$file).'</div>';
  692. dol_syslog('Failed to read file: '.$file);
  693. }*/
  694. }
  695. else
  696. {
  697. $langs->load("other");
  698. $mesg='<div class="error">'.$langs->trans('ErrorFailedToReadEntity',$langs->trans("Invoice")).'</div>';
  699. dol_syslog('Unable to read data from the invoice. The invoice file has perhaps not been generated.');
  700. }
  701. //$action = 'presend';
  702. }
  703. // Build document
  704. elseif ($action == 'builddoc')
  705. {
  706. // Save modele used
  707. $object->fetch($id);
  708. $object->fetch_thirdparty();
  709. if ($_REQUEST['model'])
  710. {
  711. $object->setDocModel($user, $_REQUEST['model']);
  712. }
  713. $outputlangs = $langs;
  714. if (! empty($_REQUEST['lang_id']))
  715. {
  716. $outputlangs = new Translate();
  717. $outputlangs->setDefaultLang($_REQUEST['lang_id']);
  718. }
  719. $result=supplier_invoice_pdf_create($db,$object,$object->modelpdf,$outputlangs);
  720. if ($result <= 0)
  721. {
  722. dol_print_error($db,$result);
  723. exit;
  724. }
  725. else
  726. {
  727. header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
  728. exit;
  729. }
  730. }
  731. // Delete file in doc form
  732. elseif ($action == 'remove_file')
  733. {
  734. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  735. if ($object->fetch($id))
  736. {
  737. $object->fetch_thirdparty();
  738. $upload_dir = $conf->fournisseur->facture->dir_output . "/";
  739. $file = $upload_dir . '/' . GETPOST('file');
  740. $ret=dol_delete_file($file,0,0,0,$object);
  741. if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
  742. else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
  743. }
  744. }
  745. if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->fournisseur->facture->creer)
  746. {
  747. if ($action == 'addcontact')
  748. {
  749. $result = $object->fetch($id);
  750. if ($result > 0 && $id > 0)
  751. {
  752. $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
  753. $result = $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
  754. }
  755. if ($result >= 0)
  756. {
  757. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  758. exit;
  759. }
  760. else
  761. {
  762. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
  763. {
  764. $langs->load("errors");
  765. $mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>';
  766. }
  767. else
  768. {
  769. $mesg = '<div class="error">'.$object->error.'</div>';
  770. }
  771. }
  772. }
  773. // bascule du statut d'un contact
  774. else if ($action == 'swapstatut')
  775. {
  776. if ($object->fetch($id))
  777. {
  778. $result=$object->swapContactStatus(GETPOST('ligne'));
  779. }
  780. else
  781. {
  782. dol_print_error($db);
  783. }
  784. }
  785. // Efface un contact
  786. else if ($action == 'deletecontact')
  787. {
  788. $object->fetch($id);
  789. $result = $object->delete_contact($_GET["lineid"]);
  790. if ($result >= 0)
  791. {
  792. header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  793. exit;
  794. }
  795. else {
  796. dol_print_error($db);
  797. }
  798. }
  799. }
  800. /*
  801. * View
  802. */
  803. $form = new Form($db);
  804. $formfile = new FormFile($db);
  805. $bankaccountstatic=new Account($db);
  806. llxHeader('','','');
  807. // Mode creation
  808. if ($action == 'create')
  809. {
  810. print_fiche_titre($langs->trans('NewBill'));
  811. dol_htmloutput_mesg($mesg);
  812. $societe='';
  813. if ($_GET['socid'])
  814. {
  815. $societe=new Societe($db);
  816. $societe->fetch($_GET['socid']);
  817. }
  818. if (GETPOST('origin') && GETPOST('originid'))
  819. {
  820. // Parse element/subelement (ex: project_task)
  821. $element = $subelement = GETPOST('origin');
  822. if ($element == 'project')
  823. {
  824. $projectid=GETPOST('originid');
  825. }
  826. else if (in_array($element,array('order_supplier')))
  827. {
  828. // For compatibility
  829. if ($element == 'order') {
  830. $element = $subelement = 'commande';
  831. }
  832. if ($element == 'propal') {
  833. dol_htmloutput_errors('',$errors);
  834. $element = 'comm/propal'; $subelement = 'propal';
  835. }
  836. if ($element == 'contract') {
  837. $element = $subelement = 'contrat';
  838. }
  839. if ($element == 'order_supplier') {
  840. $element = 'fourn'; $subelement = 'fournisseur.commande';
  841. }
  842. require_once DOL_DOCUMENT_ROOT.'/'.$element.'/class/'.$subelement.'.class.php';
  843. $classname = ucfirst($subelement);
  844. if ($classname == 'Fournisseur.commande') $classname='CommandeFournisseur';
  845. $objectsrc = new $classname($db);
  846. $objectsrc->fetch(GETPOST('originid'));
  847. $objectsrc->fetch_thirdparty();
  848. $projectid = (!empty($objectsrc->fk_project)?$object->fk_project:'');
  849. //$ref_client = (!empty($objectsrc->ref_client)?$object->ref_client:'');
  850. $soc = $objectsrc->client;
  851. $cond_reglement_id = (!empty($objectsrc->cond_reglement_id)?$objectsrc->cond_reglement_id:(!empty($soc->cond_reglement_id)?$soc->cond_reglement_id:1));
  852. $mode_reglement_id = (!empty($objectsrc->mode_reglement_id)?$objectsrc->mode_reglement_id:(!empty($soc->mode_reglement_id)?$soc->mode_reglement_id:0));
  853. $remise_percent = (!empty($objectsrc->remise_percent)?$objectsrc->remise_percent:(!empty($soc->remise_percent)?$soc->remise_percent:0));
  854. $remise_absolue = (!empty($objectsrc->remise_absolue)?$objectsrc->remise_absolue:(!empty($soc->remise_absolue)?$soc->remise_absolue:0));
  855. $dateinvoice = empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0;
  856. $datetmp=dol_mktime(12,0,0,$_POST['remonth'],$_POST['reday'],$_POST['reyear']);
  857. $dateinvoice=($datetmp==''?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0):$datetmp);
  858. $datetmp=dol_mktime(12,0,0,$_POST['echmonth'],$_POST['echday'],$_POST['echyear']);
  859. $datedue=($datetmp==''?-1:$datetmp);
  860. }
  861. }
  862. else
  863. {
  864. $datetmp=dol_mktime(12,0,0,$_POST['remonth'],$_POST['reday'],$_POST['reyear']);
  865. $dateinvoice=($datetmp==''?(empty($conf->global->MAIN_AUTOFILL_DATE)?-1:0):$datetmp);
  866. $datetmp=dol_mktime(12,0,0,$_POST['echmonth'],$_POST['echday'],$_POST['echyear']);
  867. $datedue=($datetmp==''?-1:$datetmp);
  868. }
  869. print '<form name="add" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  870. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  871. print '<input type="hidden" name="action" value="add">';
  872. print '<input type="hidden" name="origin" value="'.GETPOST('origin').'">';
  873. print '<input type="hidden" name="originid" value="'.GETPOST('originid').'">';
  874. print '<table class="border" width="100%">';
  875. // Ref
  876. print '<tr><td>'.$langs->trans('Ref').'</td><td>'.$langs->trans('Draft').'</td></tr>';
  877. // Third party
  878. print '<tr><td class="fieldrequired">'.$langs->trans('Supplier').'</td>';
  879. print '<td>';
  880. if ($_REQUEST['socid'] > 0)
  881. {
  882. print $societe->getNomUrl(1);
  883. print '<input type="hidden" name="socid" value="'.$_GET['socid'].'">';
  884. }
  885. else
  886. {
  887. print $form->select_company((empty($_GET['socid'])?'':$_GET['socid']),'socid','s.fournisseur = 1',1);
  888. }
  889. print '</td>';
  890. // Ref supplier
  891. print '<tr><td class="fieldrequired">'.$langs->trans('RefSupplier').'</td><td><input name="facnumber" value="'.(isset($_POST['facnumber'])?$_POST['facnumber']:$fac_ori->ref).'" type="text"></td>';
  892. print '</tr>';
  893. print '<tr><td valign="top" class="fieldrequired">'.$langs->trans('Type').'</td><td colspan="2">';
  894. print '<table class="nobordernopadding">'."\n";
  895. // Standard invoice
  896. print '<tr height="18"><td width="16px" valign="middle">';
  897. print '<input type="radio" name="type" value="0"'.($_POST['type']==0?' checked="checked"':'').'>';
  898. print '</td><td valign="middle">';
  899. $desc=$form->textwithpicto($langs->trans("InvoiceStandardAsk"),$langs->transnoentities("InvoiceStandardDesc"),1);
  900. print $desc;
  901. print '</td></tr>'."\n";
  902. /*
  903. // Deposit
  904. print '<tr height="18"><td width="16px" valign="middle">';
  905. print '<input type="radio" name="type" value="3"'.($_POST['type']==3?' checked="checked"':'').'>';
  906. print '</td><td valign="middle">';
  907. $desc=$form->textwithpicto($langs->trans("InvoiceDeposit"),$langs->transnoentities("InvoiceDepositDesc"),1);
  908. print $desc;
  909. print '</td></tr>'."\n";
  910. // Proforma
  911. if (! empty($conf->global->FACTURE_USE_PROFORMAT))
  912. {
  913. print '<tr height="18"><td width="16px" valign="middle">';
  914. print '<input type="radio" name="type" value="4"'.($_POST['type']==4?' checked="checked"':'').'>';
  915. print '</td><td valign="middle">';
  916. $desc=$form->textwithpicto($langs->trans("InvoiceProForma"),$langs->transnoentities("InvoiceProFormaDesc"),1);
  917. print $desc;
  918. print '</td></tr>'."\n";
  919. }
  920. // Replacement
  921. print '<tr height="18"><td valign="middle">';
  922. print '<input type="radio" name="type" value="1"'.($_POST['type']==1?' checked="checked"':'');
  923. if (! $options) print ' disabled="disabled"';
  924. print '>';
  925. print '</td><td valign="middle">';
  926. $text=$langs->trans("InvoiceReplacementAsk").' ';
  927. $text.='<select class="flat" name="fac_replacement"';
  928. if (! $options) $text.=' disabled="disabled"';
  929. $text.='>';
  930. if ($options)
  931. {
  932. $text.='<option value="-1">&nbsp;</option>';
  933. $text.=$options;
  934. }
  935. else
  936. {
  937. $text.='<option value="-1">'.$langs->trans("NoReplacableInvoice").'</option>';
  938. }
  939. $text.='</select>';
  940. $desc=$form->textwithpicto($text,$langs->transnoentities("InvoiceReplacementDesc"),1);
  941. print $desc;
  942. print '</td></tr>';
  943. // Credit note
  944. print '<tr height="18"><td valign="middle">';
  945. print '<input type="radio" name="type" value="2"'.($_POST['type']==2?' checked=true':'');
  946. if (! $optionsav) print ' disabled="disabled"';
  947. print '>';
  948. print '</td><td valign="middle">';
  949. $text=$langs->transnoentities("InvoiceAvoirAsk").' ';
  950. // $text.='<input type="text" value="">';
  951. $text.='<select class="flat" name="fac_avoir"';
  952. if (! $optionsav) $text.=' disabled="disabled"';
  953. $text.='>';
  954. if ($optionsav)
  955. {
  956. $text.='<option value="-1">&nbsp;</option>';
  957. $text.=$optionsav;
  958. }
  959. else
  960. {
  961. $text.='<option value="-1">'.$langs->trans("NoInvoiceToCorrect").'</option>';
  962. }
  963. $text.='</select>';
  964. $desc=$form->textwithpicto($text,$langs->transnoentities("InvoiceAvoirDesc"),1);
  965. print $desc;
  966. print '</td></tr>'."\n";
  967. */
  968. print '</table>';
  969. print '</td></tr>';
  970. // Label
  971. print '<tr><td>'.$langs->trans('Label').'</td><td><input size="30" name="libelle" value="'.(isset($_POST['libelle'])?$_POST['libelle']:$fac_ori->libelle).'" type="text"></td></tr>';
  972. // Date invoice
  973. print '<tr><td class="fieldrequired">'.$langs->trans('DateInvoice').'</td><td>';
  974. $form->select_date($dateinvoice,'','','','',"add",1,1);
  975. print '</td></tr>';
  976. // Due date
  977. print '<tr><td>'.$langs->trans('DateMaxPayment').'</td><td>';
  978. $form->select_date($datedue,'ech','','','',"add",1,1);
  979. print '</td></tr>';
  980. print '<tr><td>'.$langs->trans('NotePublic').'</td>';
  981. print '<td><textarea name="note" wrap="soft" cols="60" rows="'.ROWS_5.'"></textarea></td>';
  982. print '</tr>';
  983. if (is_object($objectsrc))
  984. {
  985. print "\n<!-- ".$classname." info -->";
  986. print "\n";
  987. print '<input type="hidden" name="amount" value="'.$objectsrc->total_ht.'">'."\n";
  988. print '<input type="hidden" name="total" value="'.$objectsrc->total_ttc.'">'."\n";
  989. print '<input type="hidden" name="tva" value="'.$objectsrc->total_tva.'">'."\n";
  990. print '<input type="hidden" name="origin" value="'.$objectsrc->element.'">';
  991. print '<input type="hidden" name="originid" value="'.$objectsrc->id.'">';
  992. $txt=$langs->trans($classname);
  993. if ($classname=='CommandeFournisseur') $txt=$langs->trans("SupplierOrder");
  994. print '<tr><td>'.$txt.'</td><td colspan="2">'.$objectsrc->getNomUrl(1).'</td></tr>';
  995. print '<tr><td>'.$langs->trans('TotalHT').'</td><td colspan="2">'.price($objectsrc->total_ht).'</td></tr>';
  996. print '<tr><td>'.$langs->trans('TotalVAT').'</td><td colspan="2">'.price($objectsrc->total_tva)."</td></tr>";
  997. if ($mysoc->country_code=='ES')
  998. {
  999. if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
  1000. {
  1001. print '<tr><td>'.$langs->transcountry("AmountLT1",$mysoc->country_code).'</td><td colspan="2">'.price($objectsrc->total_localtax1)."</td></tr>";
  1002. }
  1003. if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
  1004. {
  1005. print '<tr><td>'.$langs->transcountry("AmountLT2",$mysoc->country_code).'</td><td colspan="2">'.price($objectsrc->total_localtax2)."</td></tr>";
  1006. }
  1007. }
  1008. print '<tr><td>'.$langs->trans('TotalTTC').'</td><td colspan="2">'.price($objectsrc->total_ttc)."</td></tr>";
  1009. }
  1010. else
  1011. {
  1012. // TODO more bugs
  1013. if (1==2 && ! empty($conf->global->PRODUCT_SHOW_WHEN_CREATE))
  1014. {
  1015. print '<tr class="liste_titre">';
  1016. print '<td>&nbsp;</td><td>'.$langs->trans('Label').'</td>';
  1017. print '<td align="right">'.$langs->trans('PriceUHT').'</td>';
  1018. print '<td align="right">'.$langs->trans('VAT').'</td>';
  1019. print '<td align="right">'.$langs->trans('Qty').'</td>';
  1020. print '<td align="right">'.$langs->trans('PriceUTTC').'</td>';
  1021. print '</tr>';
  1022. for ($i = 1 ; $i < 9 ; $i++)
  1023. {
  1024. $value_qty = '1';
  1025. $value_tauxtva = '';
  1026. print '<tr><td>'.$i.'</td>';
  1027. print '<td><input size="50" name="label'.$i.'" value="'.$value_label.'" type="text"></td>';
  1028. print '<td align="right"><input type="text" size="8" name="amount'.$i.'" value="'.$value_pu.'"></td>';
  1029. print '<td align="right">';
  1030. print $form->load_tva('tauxtva'.$i,$value_tauxtva,$societe,$mysoc);
  1031. print '</td>';
  1032. print '<td align="right"><input type="text" size="3" name="qty'.$i.'" value="'.$value_qty.'"></td>';
  1033. print '<td align="right"><input type="text" size="8" name="amountttc'.$i.'" value=""></td></tr>';
  1034. }
  1035. }
  1036. }
  1037. // Other options
  1038. $parameters=array();
  1039. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  1040. // Bouton "Create Draft"
  1041. print "</table>\n";
  1042. print '<br><center><input type="submit" class="button" name="bouton" value="'.$langs->trans('CreateDraft').'"></center>';
  1043. print "</form>\n";
  1044. // Show origin lines
  1045. if (is_object($objectsrc))
  1046. {
  1047. print '<br>';
  1048. $title=$langs->trans('ProductsAndServices');
  1049. print_titre($title);
  1050. print '<table class="noborder" width="100%">';
  1051. $objectsrc->printOriginLinesList();
  1052. print '</table>';
  1053. }
  1054. }
  1055. else
  1056. {
  1057. if ($id > 0)
  1058. {
  1059. /* *************************************************************************** */
  1060. /* */
  1061. /* Fiche en mode visu ou edition */
  1062. /* */
  1063. /* *************************************************************************** */
  1064. $now=dol_now();
  1065. $productstatic = new Product($db);
  1066. $object->fetch($id);
  1067. $societe = new Fournisseur($db);
  1068. $societe->fetch($object->socid);
  1069. /*
  1070. * View card
  1071. */
  1072. $head = facturefourn_prepare_head($object);
  1073. $titre=$langs->trans('SupplierInvoice');
  1074. dol_fiche_head($head, 'card', $titre, 0, 'bill');
  1075. dol_htmloutput_mesg($mesg);
  1076. dol_htmloutput_errors('',$errors);
  1077. // Confirmation de la suppression d'une ligne produit
  1078. if ($action == 'confirm_delete_line')
  1079. {
  1080. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$_GET["lineid"], $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 1, 1);
  1081. if ($ret == 'html') print '<br>';
  1082. }
  1083. // Clone confirmation
  1084. if ($action == 'clone')
  1085. {
  1086. // Create an array for form
  1087. $formquestion=array(
  1088. //'text' => $langs->trans("ConfirmClone"),
  1089. //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1)
  1090. );
  1091. // Paiement incomplet. On demande si motif = escompte ou autre
  1092. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('CloneInvoice'),$langs->trans('ConfirmCloneInvoice',$object->ref),'confirm_clone',$formquestion,'yes', 1);
  1093. if ($ret == 'html') print '<br>';
  1094. }
  1095. // Confirmation de la validation
  1096. if ($action == 'valid')
  1097. {
  1098. $formquestion=array();
  1099. if (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $object->hasProductsOrServices(1))
  1100. {
  1101. $langs->load("stocks");
  1102. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  1103. $formproduct=new FormProduct($db);
  1104. $formquestion=array(
  1105. //'text' => $langs->trans("ConfirmClone"),
  1106. //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  1107. //array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  1108. array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'),'idwarehouse','',1)));
  1109. }
  1110. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateBill'), $langs->trans('ConfirmValidateBill', $object->ref), 'confirm_valid', $formquestion, 1, 1, 240);
  1111. if ($ret == 'html') print '<br>';
  1112. }
  1113. // Confirmation set paid
  1114. if ($action == 'paid')
  1115. {
  1116. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ClassifyPaid'), $langs->trans('ConfirmClassifyPaidBill', $object->ref), 'confirm_paid', '', 0, 1);
  1117. if ($ret == 'html') print '<br>';
  1118. }
  1119. // Confirmation de la suppression de la facture fournisseur
  1120. if ($action == 'delete')
  1121. {
  1122. $ret=$form->form_confirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteBill'), $langs->trans('ConfirmDeleteBill'), 'confirm_delete', '', 0, 1);
  1123. if ($ret == 'html') print '<br>';
  1124. }
  1125. /**
  1126. * Invoice
  1127. */
  1128. print '<table class="border" width="100%">';
  1129. $linkback = '<a href="'.DOL_URL_ROOT.'/fourn/facture/index.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
  1130. // Ref
  1131. print '<tr><td nowrap="nowrap" width="20%">'.$langs->trans("Ref").'</td><td colspan="4">';
  1132. print $form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'ref');
  1133. print '</td>';
  1134. print "</tr>\n";
  1135. // Ref supplier
  1136. print '<tr><td>'.$form->editfieldkey("RefSupplier",'facnumber',$object->ref_supplier,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer)).'</td><td colspan="4">';
  1137. print $form->editfieldval("RefSupplier",'facnumber',$object->ref_supplier,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer));
  1138. print '</td></tr>';
  1139. // Third party
  1140. print '<tr><td>'.$langs->trans('Supplier').'</td><td colspan="4">'.$societe->getNomUrl(1);
  1141. print ' &nbsp; (<a href="'.DOL_URL_ROOT.'/fourn/facture/index.php?socid='.$object->socid.'">'.$langs->trans('OtherBills').'</a>)</td>';
  1142. print '</tr>';
  1143. // Type
  1144. print '<tr><td>'.$langs->trans('Type').'</td><td colspan="4">';
  1145. print $object->getLibType();
  1146. if ($object->type == 1)
  1147. {
  1148. $facreplaced=new FactureFournisseur($db);
  1149. $facreplaced->fetch($object->fk_facture_source);
  1150. print ' ('.$langs->transnoentities("ReplaceInvoice",$facreplaced->getNomUrl(1)).')';
  1151. }
  1152. if ($object->type == 2)
  1153. {
  1154. $facusing=new FactureFournisseur($db);
  1155. $facusing->fetch($object->fk_facture_source);
  1156. print ' ('.$langs->transnoentities("CorrectInvoice",$facusing->getNomUrl(1)).')';
  1157. }
  1158. $facidavoir=$object->getListIdAvoirFromInvoice();
  1159. if (count($facidavoir) > 0)
  1160. {
  1161. print ' ('.$langs->transnoentities("InvoiceHasAvoir");
  1162. $i=0;
  1163. foreach($facidavoir as $id)
  1164. {
  1165. if ($i==0) print ' ';
  1166. else print ',';
  1167. $facavoir=new FactureFournisseur($db);
  1168. $facavoir->fetch($id);
  1169. print $facavoir->getNomUrl(1);
  1170. }
  1171. print ')';
  1172. }
  1173. if (isset($facidnext) && $facidnext > 0)
  1174. {
  1175. $facthatreplace=new FactureFournisseur($db);
  1176. $facthatreplace->fetch($facidnext);
  1177. print ' ('.$langs->transnoentities("ReplacedByInvoice",$facthatreplace->getNomUrl(1)).')';
  1178. }
  1179. print '</td></tr>';
  1180. // Label
  1181. print '<tr><td>'.$form->editfieldkey("Label",'label',$object->label,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer)).'</td>';
  1182. print '<td colspan="3">'.$form->editfieldval("Label",'label',$object->label,$object,($object->statut<2 && $user->rights->fournisseur->facture->creer)).'</td>';
  1183. /*
  1184. * Li…

Large files files are truncated, but you can click here to view the full file