PageRenderTime 54ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/comm/propal.php

https://github.com/zeert/dolibarr
PHP | 1805 lines | 1415 code | 202 blank | 188 comment | 473 complexity | 4eb4e77b608832d8460bf16219554f26 MD5 | raw file
Possible License(s): LGPL-2.0

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

  1. <?php
  2. /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  5. * Copyright (C) 2005 Marc Barilley / Ocebo <marc@ocebo.com>
  6. * Copyright (C) 2005-2012 Regis Houssin <regis@dolibarr.fr>
  7. * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
  8. * Copyright (C) 2010-2012 Juanjo Menent <jmenent@2byte.es>
  9. * Copyright (C) 2010-2011 Philippe Grand <philippe.grand@atoo-net.com>
  10. * Copyright (C) 2012 Christophe Battarel <christophe.battarel@altairis.fr>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  24. */
  25. /**
  26. * \file htdocs/comm/propal.php
  27. * \ingroup propale
  28. * \brief Page of commercial proposals card and list
  29. */
  30. require("../main.inc.php");
  31. require_once(DOL_DOCUMENT_ROOT."/core/class/html.formother.class.php");
  32. require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php");
  33. require_once(DOL_DOCUMENT_ROOT."/core/class/html.formpropal.class.php");
  34. require_once(DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php');
  35. require_once(DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php');
  36. require_once(DOL_DOCUMENT_ROOT."/core/modules/propale/modules_propale.php");
  37. require_once(DOL_DOCUMENT_ROOT."/core/lib/propal.lib.php");
  38. require_once(DOL_DOCUMENT_ROOT."/core/lib/functions2.lib.php");
  39. if (! empty($conf->projet->enabled)) require_once(DOL_DOCUMENT_ROOT.'/projet/class/project.class.php');
  40. $langs->load('companies');
  41. $langs->load('propal');
  42. $langs->load('compta');
  43. $langs->load('bills');
  44. $langs->load('orders');
  45. $langs->load('products');
  46. if (! empty($conf->margin->enabled))
  47. $langs->load('margins');
  48. $id=GETPOST('id','int');
  49. $ref=GETPOST('ref','alpha');
  50. $socid=GETPOST('socid','int');
  51. $action=GETPOST('action','alpha');
  52. $confirm=GETPOST('confirm','alpha');
  53. $lineid=GETPOST('lineid','int');
  54. $search_ref=GETPOST('sf_ref')?GETPOST('sf_ref','alpha'):GETPOST('search_ref','alpha');
  55. $search_refcustomer=GETPOST('search_refcustomer','alpha');
  56. $search_societe=GETPOST('search_societe','alpha');
  57. $search_montant_ht=GETPOST('search_montant_ht','alpha');
  58. $sall=GETPOST("sall");
  59. $year=GETPOST("year");
  60. $month=GETPOST("month");
  61. //PDF
  62. $hidedetails = (GETPOST('hidedetails','int') ? GETPOST('hidedetails','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0));
  63. $hidedesc = (GETPOST('hidedesc','int') ? GETPOST('hidedesc','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DESC) ? 1 : 0));
  64. $hideref = (GETPOST('hideref','int') ? GETPOST('hideref','int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_REF) ? 1 : 0));
  65. // Nombre de ligne pour choix de produit/service predefinis
  66. $NBLINES=4;
  67. // Security check
  68. $module='propale';
  69. if (isset($socid))
  70. {
  71. $objectid=$socid;
  72. $module='societe';
  73. $dbtable='&societe';
  74. }
  75. else if (isset($id) && $id > 0)
  76. {
  77. $objectid=$id;
  78. $module='propale';
  79. $dbtable='propal';
  80. }
  81. if ($user->societe_id) $socid=$user->societe_id;
  82. $result = restrictedArea($user, $module, $objectid, $dbtable);
  83. $object = new Propal($db);
  84. // Load object
  85. if ($id > 0 || ! empty($ref))
  86. {
  87. $ret=$object->fetch($id, $ref);
  88. $object->fetch_thirdparty();
  89. }
  90. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  91. include_once(DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php');
  92. $hookmanager=new HookManager($db);
  93. $hookmanager->initHooks(array('propalcard'));
  94. /*
  95. * Actions
  96. */
  97. $parameters=array('socid'=>$socid);
  98. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  99. // Action clone object
  100. if ($action == 'confirm_clone' && $confirm == 'yes')
  101. {
  102. if (1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers'))
  103. {
  104. setEventMessage($langs->trans("NoCloneOptionsSpecified"), 'errors');
  105. }
  106. else
  107. {
  108. if ($object->id > 0)
  109. {
  110. $result=$object->createFromClone($socid, $hookmanager);
  111. if ($result > 0)
  112. {
  113. header("Location: ".$_SERVER['PHP_SELF'].'?id='.$result);
  114. exit;
  115. }
  116. else
  117. {
  118. setEventMessage($object->error, 'errors');
  119. $action='';
  120. }
  121. }
  122. }
  123. }
  124. // Suppression de la propale
  125. else if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->propale->supprimer)
  126. {
  127. $result=$object->delete($user);
  128. if ($result > 0)
  129. {
  130. Header('Location: '.DOL_URL_ROOT.'/comm/propal/list.php');
  131. exit;
  132. }
  133. else
  134. {
  135. $langs->load("errors");
  136. setEventMessage($langs->trans($object->error), 'errors');
  137. }
  138. }
  139. // Remove line
  140. else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->propale->creer)
  141. {
  142. $result = $object->deleteline($lineid);
  143. // reorder lines
  144. if ($result) $object->line_order(true);
  145. // Define output language
  146. $outputlangs = $langs;
  147. $newlang='';
  148. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id');
  149. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  150. if (! empty($newlang))
  151. {
  152. $outputlangs = new Translate("",$conf);
  153. $outputlangs->setDefaultLang($newlang);
  154. }
  155. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  156. {
  157. $ret=$object->fetch($id); // Reload to get new records
  158. propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager);
  159. }
  160. Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  161. exit;
  162. }
  163. // Validation
  164. else if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->propale->valider)
  165. {
  166. $result=$object->valid($user);
  167. if ($result >= 0)
  168. {
  169. // Define output language
  170. $outputlangs = $langs;
  171. $newlang='';
  172. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id');
  173. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  174. if (! empty($newlang))
  175. {
  176. $outputlangs = new Translate("",$conf);
  177. $outputlangs->setDefaultLang($newlang);
  178. }
  179. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  180. {
  181. $ret=$object->fetch($object->id); // Reload to get new records
  182. propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager);
  183. }
  184. }
  185. else
  186. {
  187. $langs->load("errors");
  188. setEventMessage($langs->trans($object->error), 'errors');
  189. }
  190. }
  191. else if ($action == 'setdate' && $user->rights->propale->creer)
  192. {
  193. $datep=dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
  194. if (empty($datep))
  195. {
  196. $error++;
  197. setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")), 'errors');
  198. }
  199. if (! $error)
  200. {
  201. $result=$object->set_date($user,$datep);
  202. if ($result < 0) dol_print_error($db,$object->error);
  203. }
  204. }
  205. else if ($action == 'setecheance' && $user->rights->propale->creer)
  206. {
  207. $result=$object->set_echeance($user,dol_mktime(12, 0, 0, $_POST['echmonth'], $_POST['echday'], $_POST['echyear']));
  208. if ($result < 0) dol_print_error($db,$object->error);
  209. }
  210. else if ($action == 'setdate_livraison' && $user->rights->propale->creer)
  211. {
  212. $result=$object->set_date_livraison($user,dol_mktime(12, 0, 0, $_POST['liv_month'], $_POST['liv_day'], $_POST['liv_year']));
  213. if ($result < 0) dol_print_error($db,$object->error);
  214. }
  215. // Positionne ref client
  216. else if ($action == 'set_ref_client' && $user->rights->propale->creer)
  217. {
  218. $object->set_ref_client($user, $_POST['ref_client']);
  219. }
  220. else if ($action == 'setnote_public' && $user->rights->propale->creer)
  221. {
  222. $result=$object->update_note_public(dol_html_entity_decode(GETPOST('note_public'), ENT_QUOTES));
  223. if ($result < 0) dol_print_error($db,$object->error);
  224. }
  225. else if ($action == 'setnote' && $user->rights->propale->creer)
  226. {
  227. $result=$object->update_note(dol_html_entity_decode(GETPOST('note'), ENT_QUOTES));
  228. if ($result < 0) dol_print_error($db,$object->error);
  229. }
  230. // Create proposal
  231. else if ($action == 'add' && $user->rights->propale->creer)
  232. {
  233. $object->socid=$socid;
  234. $object->fetch_thirdparty();
  235. $datep=dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear'));
  236. $date_delivery=dol_mktime(12, 0, 0, GETPOST('liv_month'), GETPOST('liv_day'), GETPOST('liv_year'));
  237. $duration=GETPOST('duree_validite');
  238. if (empty($datep))
  239. {
  240. setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Date")), 'errors');
  241. header("Location: ".DOL_URL_ROOT.'/comm/addpropal.php?socid='.$socid.'&action=create');
  242. exit;
  243. }
  244. if (empty($duration))
  245. {
  246. setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("ValidityDuration")), 'errors');
  247. header("Location: ".DOL_URL_ROOT.'/comm/addpropal.php?socid='.$socid.'&action=create');
  248. exit;
  249. }
  250. if (! $error)
  251. {
  252. $db->begin();
  253. // Si on a selectionne une propal a copier, on realise la copie
  254. if (GETPOST('createmode')=='copy' && GETPOST('copie_propal'))
  255. {
  256. if ($object->fetch(GETPOST('copie_propal')) > 0)
  257. {
  258. $object->ref = GETPOST('ref');
  259. $object->datep = $datep;
  260. $object->date_livraison = $date_delivery;
  261. $object->availability_id = GETPOST('availability_id');
  262. $object->demand_reason_id = GETPOST('demand_reason_id');
  263. $object->fk_delivery_address = GETPOST('fk_address');
  264. $object->duree_validite = $duration;
  265. $object->cond_reglement_id = GETPOST('cond_reglement_id');
  266. $object->mode_reglement_id = GETPOST('mode_reglement_id');
  267. $object->remise_percent = GETPOST('remise_percent');
  268. $object->remise_absolue = GETPOST('remise_absolue');
  269. $object->socid = GETPOST('socid');
  270. $object->contactid = GETPOST('contactidp');
  271. $object->fk_project = GETPOST('projectid');
  272. $object->modelpdf = GETPOST('model');
  273. $object->author = $user->id; // deprecated
  274. $object->note = GETPOST('note');
  275. $object->statut = 0;
  276. $id = $object->create_from($user);
  277. }
  278. else
  279. {
  280. setEventMessage($langs->trans("ErrorFailedToCopyProposal",GETPOST('copie_propal')), 'errors');
  281. }
  282. }
  283. else
  284. {
  285. $object->ref = GETPOST('ref');
  286. $object->ref_client = GETPOST('ref_client');
  287. $object->datep = $datep;
  288. $object->date_livraison = $date_delivery;
  289. $object->availability_id = GETPOST('availability_id');
  290. $object->demand_reason_id = GETPOST('demand_reason_id');
  291. $object->fk_delivery_address = GETPOST('fk_address');
  292. $object->duree_validite = GETPOST('duree_validite');
  293. $object->cond_reglement_id = GETPOST('cond_reglement_id');
  294. $object->mode_reglement_id = GETPOST('mode_reglement_id');
  295. $object->contactid = GETPOST('contactidp');
  296. $object->fk_project = GETPOST('projectid');
  297. $object->modelpdf = GETPOST('model');
  298. $object->author = $user->id; // deprecated
  299. $object->note = GETPOST('note');
  300. $object->origin = GETPOST('origin');
  301. $object->origin_id = GETPOST('originid');
  302. for ($i = 1 ; $i <= $conf->global->PRODUCT_SHOW_WHEN_CREATE; $i++)
  303. {
  304. if ($_POST['idprod'.$i])
  305. {
  306. $xid = 'idprod'.$i;
  307. $xqty = 'qty'.$i;
  308. $xremise = 'remise'.$i;
  309. $object->add_product($_POST[$xid],$_POST[$xqty],$_POST[$xremise]);
  310. }
  311. }
  312. $id = $object->create($user);
  313. }
  314. if ($id > 0)
  315. {
  316. // Insertion contact par defaut si defini
  317. if (GETPOST('contactidp'))
  318. {
  319. $result=$object->add_contact(GETPOST('contactidp'),'CUSTOMER','external');
  320. if ($result < 0)
  321. {
  322. $error++;
  323. setEventMessage($langs->trans("ErrorFailedToAddContact"), 'errors');
  324. }
  325. }
  326. if (! $error)
  327. {
  328. $db->commit();
  329. // Define output language
  330. $outputlangs = $langs;
  331. $newlang='';
  332. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
  333. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  334. if (! empty($newlang))
  335. {
  336. $outputlangs = new Translate("",$conf);
  337. $outputlangs->setDefaultLang($newlang);
  338. }
  339. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager);
  340. Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id);
  341. exit;
  342. }
  343. else
  344. {
  345. $db->rollback();
  346. }
  347. }
  348. else
  349. {
  350. dol_print_error($db,$object->error);
  351. $db->rollback();
  352. exit;
  353. }
  354. }
  355. }
  356. // Classify billed
  357. else if ($action == 'classifybilled' && $user->rights->propale->cloturer)
  358. {
  359. $object->cloture($user, 4, '');
  360. }
  361. // Reopen proposal
  362. else if ($action == 'confirm_reopen' && $user->rights->propale->cloturer && ! GETPOST('cancel'))
  363. {
  364. // prevent browser refresh from reopening proposal several times
  365. if ($object->statut==2 || $object->statut==3)
  366. {
  367. $object->setStatut(1);
  368. }
  369. }
  370. // Close proposal
  371. else if ($action == 'setstatut' && $user->rights->propale->cloturer && ! GETPOST('cancel'))
  372. {
  373. if (! GETPOST('statut'))
  374. {
  375. setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("CloseAs")), 'errors');
  376. $action='statut';
  377. }
  378. else
  379. {
  380. // prevent browser refresh from closing proposal several times
  381. if ($object->statut==1)
  382. {
  383. $object->cloture($user, GETPOST('statut'), GETPOST('note'));
  384. }
  385. }
  386. }
  387. /*
  388. * Add file in email form
  389. */
  390. if (GETPOST('addfile'))
  391. {
  392. require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
  393. // Set tmp user directory TODO Use a dedicated directory for temp mails files
  394. $vardir=$conf->user->dir_output."/".$user->id;
  395. $upload_dir_tmp = $vardir.'/temp';
  396. dol_add_file_process($upload_dir_tmp,0,0);
  397. $action='presend';
  398. }
  399. /*
  400. * Remove file in email form
  401. */
  402. if (GETPOST('removedfile'))
  403. {
  404. require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
  405. // Set tmp user directory
  406. $vardir=$conf->user->dir_output."/".$user->id;
  407. $upload_dir_tmp = $vardir.'/temp';
  408. // TODO Delete only files that was uploaded from email form
  409. dol_remove_file_process($_POST['removedfile'],0);
  410. $action='presend';
  411. }
  412. /*
  413. * Send mail
  414. */
  415. if ($action == 'send' && ! GETPOST('addfile') && ! GETPOST('removedfile') && ! GETPOST('cancel'))
  416. {
  417. $langs->load('mails');
  418. if ($object->id > 0)
  419. {
  420. if ($_POST['sendto'])
  421. {
  422. // Le destinataire a ete fourni via le champ libre
  423. $sendto = $_POST['sendto'];
  424. $sendtoid = 0;
  425. }
  426. elseif ($_POST['receiver'] != '-1')
  427. {
  428. // Recipient was provided from combo list
  429. if ($_POST['receiver'] == 'thirdparty') // Id of third party
  430. {
  431. $sendto = $object->client->email;
  432. $sendtoid = 0;
  433. }
  434. else // Id du contact
  435. {
  436. $sendto = $object->client->contact_get_property($_POST['receiver'],'email');
  437. $sendtoid = $_POST['receiver'];
  438. }
  439. }
  440. if (dol_strlen($sendto))
  441. {
  442. $langs->load("commercial");
  443. $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';
  444. $replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>';
  445. $message = $_POST['message'];
  446. $sendtocc = $_POST['sendtocc'];
  447. $deliveryreceipt = $_POST['deliveryreceipt'];
  448. if (dol_strlen($_POST['subject'])) $subject = $_POST['subject'];
  449. else $subject = $langs->transnoentities('Propal').' '.$object->ref;
  450. $actiontypecode='AC_PROP';
  451. $actionmsg = $langs->transnoentities('MailSentBy').' '.$from.' '.$langs->transnoentities('To').' '.$sendto.".\n";
  452. if ($message)
  453. {
  454. $actionmsg.=$langs->transnoentities('MailTopic').": ".$subject."\n";
  455. $actionmsg.=$langs->transnoentities('TextUsedInTheMessageBody').":\n";
  456. $actionmsg.=$message;
  457. }
  458. $actionmsg2=$langs->transnoentities('Action'.$actiontypecode);
  459. // Create form object
  460. include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formmail.class.php');
  461. $formmail = new FormMail($db);
  462. $attachedfiles=$formmail->get_attached_files();
  463. $filepath = $attachedfiles['paths'];
  464. $filename = $attachedfiles['names'];
  465. $mimetype = $attachedfiles['mimes'];
  466. // Envoi de la propal
  467. require_once(DOL_DOCUMENT_ROOT.'/core/class/CMailFile.class.php');
  468. $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc,'',$deliveryreceipt);
  469. if ($mailfile->error)
  470. {
  471. setEventMessage($mailfile->error, 'errors');
  472. }
  473. else
  474. {
  475. $result=$mailfile->sendfile();
  476. if ($result)
  477. {
  478. // Initialisation donnees
  479. $object->sendtoid = $sendtoid;
  480. $object->actiontypecode = $actiontypecode;
  481. $object->actionmsg = $actionmsg;
  482. $object->actionmsg2 = $actionmsg2;
  483. $object->fk_element = $object->id;
  484. $object->elementtype = $object->element;
  485. // Appel des triggers
  486. include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
  487. $interface=new Interfaces($db);
  488. $result=$interface->run_triggers('PROPAL_SENTBYMAIL',$object,$user,$langs,$conf);
  489. if ($result < 0) {
  490. $error++; $this->errors=$interface->errors;
  491. }
  492. // Fin appel triggers
  493. if (! $error)
  494. {
  495. // Redirect here
  496. // This avoid sending mail twice if going out and then back to page
  497. $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($from,2),$mailfile->getValidAddress($sendto,2));
  498. setEventMessage($mesg);
  499. Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id);
  500. exit;
  501. }
  502. else
  503. {
  504. dol_print_error($db);
  505. }
  506. }
  507. else
  508. {
  509. $langs->load("other");
  510. if ($mailfile->error)
  511. {
  512. $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto);
  513. $mesg.='<br>'.$mailfile->error;
  514. }
  515. else
  516. {
  517. $mesg.='No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS';
  518. }
  519. setEventMessage($mesg, 'errors');
  520. }
  521. }
  522. }
  523. else
  524. {
  525. $langs->load("other");
  526. setEventMessage($langs->trans('ErrorMailRecipientIsEmpty').'!', 'errors');
  527. dol_syslog($langs->trans('ErrorMailRecipientIsEmpty'));
  528. }
  529. }
  530. else
  531. {
  532. $langs->load("other");
  533. setEventMessage($langs->trans('ErrorFailedToReadEntity',$langs->trans("Proposal")), 'errors');
  534. dol_syslog($langs->trans('ErrorFailedToReadEntity',$langs->trans("Proposal")));
  535. }
  536. }
  537. // Go back to draft
  538. if ($action == 'modif' && $user->rights->propale->creer)
  539. {
  540. $object->set_draft($user);
  541. // Define output language
  542. $outputlangs = $langs;
  543. $newlang='';
  544. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
  545. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  546. if (! empty($newlang))
  547. {
  548. $outputlangs = new Translate("",$conf);
  549. $outputlangs->setDefaultLang($newlang);
  550. }
  551. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager);
  552. }
  553. else if ($action == "setabsolutediscount" && $user->rights->propale->creer)
  554. {
  555. if ($_POST["remise_id"])
  556. {
  557. if ($object->id > 0)
  558. {
  559. $result=$object->insert_discount($_POST["remise_id"]);
  560. if ($result < 0)
  561. {
  562. setEventMessage($object->error, 'errors');
  563. }
  564. }
  565. }
  566. }
  567. //Ajout d'une ligne produit dans la propale
  568. else if ($action == "addline" && $user->rights->propale->creer)
  569. {
  570. if (empty($_POST['idprod']) && GETPOST('type') < 0)
  571. {
  572. setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Type")), 'errors');
  573. $error++;
  574. }
  575. if (empty($_POST['idprod']) && (! isset($_POST["np_price"]) || $_POST["np_price"]=='')) // Unit price can be 0 but not ''
  576. {
  577. setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("UnitPriceHT")), 'errors');
  578. $error++;
  579. }
  580. if (! $error && isset($_POST['qty']) && ((GETPOST('np_price')!='' && (GETPOST('np_desc') || GETPOST('dp_desc'))) || GETPOST('idprod')))
  581. {
  582. $pu_ht=0;
  583. $pu_ttc=0;
  584. $price_min=0;
  585. $price_base_type = 'HT';
  586. // Ecrase $pu par celui du produit
  587. // Ecrase $desc par celui du produit
  588. // Ecrase $txtva par celui du produit
  589. if (GETPOST('idprod'))
  590. {
  591. $prod = new Product($db);
  592. $prod->fetch(GETPOST('idprod'));
  593. $tva_tx = get_default_tva($mysoc,$object->client,$prod->id);
  594. $localtax1_tx= get_localtax($tva_tx, 1, $object->client); //get_default_localtax($mysoc,$object->client,1,$prod->id);
  595. $localtax2_tx= get_localtax($tva_tx, 2, $object->client); //get_default_localtax($mysoc,$object->client,2,$prod->id);
  596. $tva_npr = get_default_npr($mysoc,$object->client,$prod->id);
  597. // On defini prix unitaire
  598. if (! empty($conf->global->PRODUIT_MULTIPRICES) && $object->client->price_level)
  599. {
  600. $pu_ht = $prod->multiprices[$object->client->price_level];
  601. $pu_ttc = $prod->multiprices_ttc[$object->client->price_level];
  602. $price_min = $prod->multiprices_min[$object->client->price_level];
  603. $price_base_type = $prod->multiprices_base_type[$object->client->price_level];
  604. }
  605. else
  606. {
  607. $pu_ht = $prod->price;
  608. $pu_ttc = $prod->price_ttc;
  609. $price_min = $prod->price_min;
  610. $price_base_type = $prod->price_base_type;
  611. }
  612. // On reevalue prix selon taux tva car taux tva transaction peut etre different
  613. // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur).
  614. if ($tva_tx != $prod->tva_tx)
  615. {
  616. if ($price_base_type != 'HT')
  617. {
  618. $pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU');
  619. }
  620. else
  621. {
  622. $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU');
  623. }
  624. }
  625. // Define output language
  626. if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE))
  627. {
  628. $outputlangs = $langs;
  629. $newlang='';
  630. if (empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id');
  631. if (empty($newlang)) $newlang=$object->client->default_lang;
  632. if (! empty($newlang))
  633. {
  634. $outputlangs = new Translate("",$conf);
  635. $outputlangs->setDefaultLang($newlang);
  636. }
  637. $desc = (! empty($prod->multilangs[$outputlangs->defaultlang]["description"])) ? $prod->multilangs[$outputlangs->defaultlang]["description"] : $prod->description;
  638. }
  639. else
  640. {
  641. $desc = $prod->description;
  642. }
  643. $desc.= ($desc && GETPOST('np_desc')) ? ((dol_textishtml($desc) || dol_textishtml(GETPOST('np_desc')))?"<br />\n":"\n") : "";
  644. $desc.= GETPOST('np_desc');
  645. $type = $prod->type;
  646. }
  647. else
  648. {
  649. $pu_ht=GETPOST('np_price');
  650. $tva_tx=str_replace('*','',GETPOST('np_tva_tx'));
  651. $tva_npr=preg_match('/\*/',GETPOST('np_tva_tx'))?1:0;
  652. $desc=GETPOST('dp_desc');
  653. $type=GETPOST('type');
  654. $localtax1_tx=get_localtax($tva_tx,1,$object->client);
  655. $localtax2_tx=get_localtax($tva_tx,2,$object->client);
  656. }
  657. $info_bits=0;
  658. if ($tva_npr) $info_bits |= 0x01;
  659. if (! empty($price_min) && (price2num($pu_ht)*(1-price2num(GETPOST('remise_percent'))/100) < price2num($price_min)))
  660. {
  661. $mesg = $langs->trans("CantBeLessThanMinPrice",price2num($price_min,'MU').' '.$langs->trans("Currency".$conf->currency));
  662. setEventMessage($mesg, 'errors');
  663. }
  664. else
  665. {
  666. // Insert line
  667. $result=$object->addline(
  668. $id,
  669. $desc,
  670. $pu_ht,
  671. GETPOST('qty'),
  672. $tva_tx,
  673. $localtax1_tx,
  674. $localtax2_tx,
  675. GETPOST('idprod'),
  676. GETPOST('remise_percent'),
  677. $price_base_type,
  678. $pu_ttc,
  679. $info_bits,
  680. $type,
  681. -1,
  682. 0,
  683. GETPOST('fk_parent_line'),
  684. GETPOST('np_fournprice'),
  685. GETPOST('np_buying_price')
  686. );
  687. if ($result > 0)
  688. {
  689. // Define output language
  690. $outputlangs = $langs;
  691. $newlang='';
  692. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
  693. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  694. if (! empty($newlang))
  695. {
  696. $outputlangs = new Translate("",$conf);
  697. $outputlangs->setDefaultLang($newlang);
  698. }
  699. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  700. {
  701. $ret=$object->fetch($id); // Reload to get new records
  702. propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager);
  703. }
  704. unset($_POST['qty']);
  705. unset($_POST['type']);
  706. unset($_POST['np_price']);
  707. unset($_POST['dp_desc']);
  708. unset($_POST['np_tva_tx']);
  709. unset($_POST['np_desc']);
  710. unset($_POST['np_buying_price']);
  711. }
  712. else
  713. {
  714. setEventMessage($object->error, 'errors');
  715. }
  716. }
  717. }
  718. }
  719. // Mise a jour d'une ligne dans la propale
  720. else if ($action == 'updateligne' && $user->rights->propale->creer && GETPOST('save') == $langs->trans("Save"))
  721. {
  722. // Define info_bits
  723. $info_bits=0;
  724. if (preg_match('/\*/',$_POST['tva_tx'])) $info_bits |= 0x01;
  725. // Define vat_rate
  726. $vat_rate=$_POST['tva_tx'];
  727. $vat_rate=str_replace('*','',$vat_rate);
  728. $localtax1_rate=get_localtax($vat_rate,1,$object->client);
  729. $localtax2_rate=get_localtax($vat_rate,2,$object->client);
  730. $pu_ht=GETPOST('pu')?GETPOST('pu'):GETPOST('subprice');
  731. // Define special_code for special lines
  732. $special_code=0;
  733. if (empty($_POST['qty'])) $special_code=3;
  734. // On verifie que le prix minimum est respecte
  735. $productid = $_POST['productid'] ;
  736. if ($productid)
  737. {
  738. $product = new Product($db);
  739. $res=$product->fetch($productid);
  740. $price_min = $product->price_min;
  741. if ($conf->global->PRODUIT_MULTIPRICES && $object->client->price_level) $price_min = $product->multiprices_min[$object->client->price_level];
  742. }
  743. if ($productid && $price_min && (price2num($pu_ht)*(1-price2num($_POST['remise_percent'])/100) < price2num($price_min)))
  744. {
  745. $mesg = $langs->trans("CantBeLessThanMinPrice",price2num($price_min,'MU').' '.$langs->trans("Currency".$conf->currency));
  746. setEventMessage($mesg, 'errors');
  747. }
  748. else
  749. {
  750. $result = $object->updateline(
  751. $_POST['lineid'],
  752. $pu_ht,
  753. $_POST['qty'],
  754. $_POST['remise_percent'],
  755. $vat_rate,
  756. $localtax1_rate,
  757. $localtax2_rate,
  758. $_POST['desc'],
  759. 'HT',
  760. $info_bits,
  761. $special_code,
  762. $_POST['fk_parent_line'],
  763. 0,
  764. GETPOST('fournprice'),
  765. GETPOST('buying_price')
  766. );
  767. // Define output language
  768. $outputlangs = $langs;
  769. $newlang='';
  770. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
  771. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  772. if (! empty($newlang))
  773. {
  774. $outputlangs = new Translate("",$conf);
  775. $outputlangs->setDefaultLang($newlang);
  776. }
  777. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE))
  778. {
  779. $ret=$object->fetch($id); // Reload to get new records
  780. propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager);
  781. unset($_POST['qty']);
  782. unset($_POST['type']);
  783. unset($_POST['np_price']);
  784. unset($_POST['dp_desc']);
  785. unset($_POST['np_tva_tx']);
  786. unset($_POST['np_buying_price']);
  787. }
  788. }
  789. }
  790. // Generation doc (depuis lien ou depuis cartouche doc)
  791. else if ($action == 'builddoc' && $user->rights->propale->creer)
  792. {
  793. if (GETPOST('model'))
  794. {
  795. $object->setDocModel($user, GETPOST('model'));
  796. }
  797. // Define output language
  798. $outputlangs = $langs;
  799. $newlang='';
  800. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
  801. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  802. if (! empty($newlang))
  803. {
  804. $outputlangs = new Translate("",$conf);
  805. $outputlangs->setDefaultLang($newlang);
  806. }
  807. $result=propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager);
  808. if ($result <= 0)
  809. {
  810. dol_print_error($db,$result);
  811. exit;
  812. }
  813. else
  814. {
  815. Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
  816. exit;
  817. }
  818. }
  819. // Remove file in doc form
  820. else if ($action == 'remove_file' && $user->rights->propale->creer)
  821. {
  822. if ($object->id > 0)
  823. {
  824. require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
  825. $langs->load("other");
  826. $upload_dir = $conf->propal->dir_output;
  827. $file = $upload_dir . '/' . GETPOST('file');
  828. $ret=dol_delete_file($file,0,0,0,$object);
  829. if ($ret) setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
  830. else setEventMessage($langs->trans("ErrorFailToDeleteFile", GETPOST('urlfile')), 'errors');
  831. }
  832. }
  833. // Set project
  834. else if ($action == 'classin' && $user->rights->propale->creer)
  835. {
  836. $object->setProject($_POST['projectid']);
  837. }
  838. // Delai de livraison
  839. else if ($action == 'setavailability' && $user->rights->propale->creer)
  840. {
  841. $result = $object->availability($_POST['availability_id']);
  842. }
  843. // Origine de la propale
  844. else if ($action == 'setdemandreason' && $user->rights->propale->creer)
  845. {
  846. $result = $object->demand_reason($_POST['demand_reason_id']);
  847. }
  848. // Conditions de reglement
  849. else if ($action == 'setconditions' && $user->rights->propale->creer)
  850. {
  851. $result = $object->setPaymentTerms(GETPOST('cond_reglement_id','int'));
  852. }
  853. else if ($action == 'setremisepercent' && $user->rights->propale->creer)
  854. {
  855. $result = $object->set_remise_percent($user, $_POST['remise_percent']);
  856. }
  857. else if ($action == 'setremiseabsolue' && $user->rights->propale->creer)
  858. {
  859. $result = $object->set_remise_absolue($user, $_POST['remise_absolue']);
  860. }
  861. // Mode de reglement
  862. else if ($action == 'setmode' && $user->rights->propale->creer)
  863. {
  864. $result = $object->setPaymentMethods(GETPOST('mode_reglement_id','int'));
  865. }
  866. /*
  867. * Ordonnancement des lignes
  868. */
  869. else if ($action == 'up' && $user->rights->propale->creer)
  870. {
  871. $object->line_up(GETPOST('rowid'));
  872. // Define output language
  873. $outputlangs = $langs;
  874. $newlang='';
  875. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id');
  876. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  877. if (! empty($newlang))
  878. {
  879. $outputlangs = new Translate("",$conf);
  880. $outputlangs->setDefaultLang($newlang);
  881. }
  882. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager);
  883. Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id.'#'.GETPOST('rowid'));
  884. exit;
  885. }
  886. else if ($action == 'down' && $user->rights->propale->creer)
  887. {
  888. $object->line_down(GETPOST('rowid'));
  889. // Define output language
  890. $outputlangs = $langs;
  891. $newlang='';
  892. if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id');
  893. if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
  894. if (! empty($newlang))
  895. {
  896. $outputlangs = new Translate("",$conf);
  897. $outputlangs->setDefaultLang($newlang);
  898. }
  899. if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) propale_pdf_create($db, $object, $object->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $hookmanager);
  900. Header('Location: '.$_SERVER["PHP_SELF"].'?id='.$id.'#'.GETPOST('rowid'));
  901. exit;
  902. }
  903. if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->propale->creer)
  904. {
  905. if ($action == 'addcontact')
  906. {
  907. if ($object->id > 0)
  908. {
  909. $contactid = (GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'));
  910. $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]);
  911. }
  912. if ($result >= 0)
  913. {
  914. Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  915. exit;
  916. }
  917. else
  918. {
  919. if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
  920. {
  921. $langs->load("errors");
  922. setEventMessage($langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"), 'errors');
  923. }
  924. else
  925. {
  926. setEventMessage($object->error, 'errors');
  927. }
  928. }
  929. }
  930. // Bascule du statut d'un contact
  931. else if ($action == 'swapstatut')
  932. {
  933. if ($object->fetch($id) > 0)
  934. {
  935. $result=$object->swapContactStatus(GETPOST('ligne'));
  936. }
  937. else
  938. {
  939. dol_print_error($db);
  940. }
  941. }
  942. // Efface un contact
  943. else if ($action == 'deletecontact')
  944. {
  945. $object->fetch($id);
  946. $result = $object->delete_contact($lineid);
  947. if ($result >= 0)
  948. {
  949. Header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
  950. exit;
  951. }
  952. else
  953. {
  954. dol_print_error($db);
  955. }
  956. }
  957. }
  958. /*
  959. * View
  960. */
  961. llxHeader('',$langs->trans('Proposal'),'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos');
  962. $form = new Form($db);
  963. $formother = new FormOther($db);
  964. $formfile = new FormFile($db);
  965. $formpropal = new FormPropal($db);
  966. $companystatic=new Societe($db);
  967. $now=dol_now();
  968. /*
  969. * Show object in view mode
  970. */
  971. $soc = new Societe($db);
  972. $soc->fetch($object->socid);
  973. $head = propal_prepare_head($object);
  974. dol_fiche_head($head, 'comm', $langs->trans('Proposal'), 0, 'propal');
  975. $formconfirm='';
  976. // Clone confirmation
  977. if ($action == 'clone')
  978. {
  979. // Create an array for form
  980. $formquestion=array(
  981. //'text' => $langs->trans("ConfirmClone"),
  982. //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
  983. //array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
  984. array('type' => 'other', 'name' => 'socid', 'label' => $langs->trans("SelectThirdParty"), 'value' => $form->select_company(GETPOST('socid','int'),'socid','(s.client=1 OR s.client=2 OR s.client=3)'))
  985. );
  986. // Paiement incomplet. On demande si motif = escompte ou autre
  987. $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id,$langs->trans('ClonePropal'),$langs->trans('ConfirmClonePropal',$object->ref),'confirm_clone',$formquestion,'yes',1);
  988. }
  989. // Confirm delete
  990. else if ($action == 'delete')
  991. {
  992. $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteProp'), $langs->trans('ConfirmDeleteProp',$object->ref), 'confirm_delete','',0,1);
  993. }
  994. // Confirm reopen
  995. else if ($action == 'reopen')
  996. {
  997. $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ReOpen'), $langs->trans('ConfirmReOpenProp',$object->ref), 'confirm_reopen','',0,1);
  998. }
  999. // Confirmation delete product/service line
  1000. else if ($action == 'ask_deleteline')
  1001. {
  1002. $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline','',0,1);
  1003. }
  1004. // Confirm validate proposal
  1005. else if ($action == 'validate')
  1006. {
  1007. $error=0;
  1008. // on verifie si l'objet est en numerotation provisoire
  1009. $ref = substr($object->ref, 1, 4);
  1010. if ($ref == 'PROV')
  1011. {
  1012. $numref = $object->getNextNumRef($soc);
  1013. if (empty($numref))
  1014. {
  1015. $error++;
  1016. dol_htmloutput_errors($object->error);
  1017. }
  1018. }
  1019. else
  1020. {
  1021. $numref = $object->ref;
  1022. }
  1023. $text=$langs->trans('ConfirmValidateProp',$numref);
  1024. if ($conf->notification->enabled)
  1025. {
  1026. require_once(DOL_DOCUMENT_ROOT ."/core/class/notify.class.php");
  1027. $notify=new Notify($db);
  1028. $text.='<br>';
  1029. $text.=$notify->confirmMessage('NOTIFY_VAL_PROPAL',$object->socid);
  1030. }
  1031. if (! $error) $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateProp'), $text, 'confirm_validate','',0,1);
  1032. }
  1033. if (! $formconfirm)
  1034. {
  1035. $parameters=array('lineid'=>$lineid);
  1036. $formconfirm=$hookmanager->executeHooks('formConfirm',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  1037. }
  1038. // Print form confirm
  1039. print $formconfirm;
  1040. print '<table class="border" width="100%">';
  1041. $linkback = '<a href="'.DOL_URL_ROOT.'/comm/propal/list.php'.(! empty($socid)?'?socid='.$socid:'').'">'.$langs->trans("BackToList").'</a>';
  1042. // Ref
  1043. print '<tr><td>'.$langs->trans('Ref').'</td><td colspan="5">';
  1044. print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', '');
  1045. print '</td></tr>';
  1046. // Ref client
  1047. print '<tr><td>';
  1048. print '<table class="nobordernopadding" width="100%"><tr><td nowrap="nowrap">';
  1049. print $langs->trans('RefCustomer').'</td><td align="left">';
  1050. print '</td>';
  1051. if ($action != 'refclient' && ! empty($object->brouillon)) print '<td align="right"><a href="'.$_SERVER['PHP_SELF'].'?action=refclient&amp;id='.$object->id.'">'.img_edit($langs->trans('Modify')).'</a></td>';
  1052. print '</tr></table>';
  1053. print '</td><td colspan="5">';
  1054. if ($user->rights->propale->creer && $action == 'refclient')
  1055. {
  1056. print '<form action="propal.php?id='.$object->id.'" method="post">';
  1057. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1058. print '<input type="hidden" name="action" value="set_ref_client">';
  1059. print '<input type="text" class="flat" size="20" name="ref_client" value="'.$object->ref_client.'">';
  1060. print ' <input type="submit" class="button" value="'.$langs->trans('Modify').'">';
  1061. print '</form>';
  1062. }
  1063. else
  1064. {
  1065. print $object->ref_client;
  1066. }
  1067. print '</td>';
  1068. print '</tr>';
  1069. // Company
  1070. print '<tr><td>'.$langs->trans('Company').'</td><td colspan="5">'.$soc->getNomUrl(1).'</td>';
  1071. print '</tr>';
  1072. // Ligne info remises tiers
  1073. print '<tr><td>'.$langs->trans('Discounts').'</td><td colspan="5">';
  1074. if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client);
  1075. else print $langs->trans("CompanyHasNoRelativeDiscount");
  1076. print '. ';
  1077. $absolute_discount=$soc->getAvailableDiscounts('','fk_facture_source IS NULL');
  1078. $absolute_creditnote=$soc->getAvailableDiscounts('','fk_facture_source IS NOT NULL');
  1079. $absolute_discount=price2num($absolute_discount,'MT');
  1080. $absolute_creditnote=price2num($absolute_creditnote,'MT');
  1081. if ($absolute_discount)
  1082. {
  1083. if ($object->statut > 0)
  1084. {
  1085. print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->currency));
  1086. }
  1087. else
  1088. {
  1089. // Remise dispo de type non avoir
  1090. $filter='fk_facture_source IS NULL';
  1091. print '<br>';
  1092. $form->form_remise_dispo($_SERVER["PHP_SELF"].'?id='.$object->id,0,'remise_id',$soc->id,$absolute_discount,$filter);
  1093. }
  1094. }
  1095. if ($absolute_creditnote)
  1096. {
  1097. print $langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->currency)).'. ';
  1098. }
  1099. if (! $absolute_discount && ! $absolute_creditnote) print $langs->trans("CompanyHasNoAbsoluteDiscount").'.';
  1100. print '</td></tr>';
  1101. // Date of proposal
  1102. print '<tr>';
  1103. print '<td>';
  1104. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1105. print $langs->trans('Date');
  1106. print '</td>';
  1107. if ($action != 'editdate' && ! empty($object->brouillon)) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdate&amp;id='.$object->id.'">'.img_edit($langs->trans('SetDate'),1).'</a></td>';
  1108. print '</tr></table>';
  1109. print '</td><td colspan="3">';
  1110. if (! empty($object->brouillon) && $action == 'editdate')
  1111. {
  1112. print '<form name="editdate" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
  1113. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1114. print '<input type="hidden" name="action" value="setdate">';
  1115. $form->select_date($object->date,'re','','',0,"editdate");
  1116. print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
  1117. print '</form>';
  1118. }
  1119. else
  1120. {
  1121. if ($object->date)
  1122. {
  1123. print dol_print_date($object->date,'daytext');
  1124. }
  1125. else
  1126. {
  1127. print '&nbsp;';
  1128. }
  1129. }
  1130. print '</td>';
  1131. // Date end proposal
  1132. print '<tr>';
  1133. print '<td>';
  1134. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1135. print $langs->trans('DateEndPropal');
  1136. print '</td>';
  1137. if ($action != 'editecheance' && ! empty($object->brouillon)) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editecheance&amp;id='.$object->id.'">'.img_edit($langs->trans('SetConditions'),1).'</a></td>';
  1138. print '</tr></table>';
  1139. print '</td><td colspan="3">';
  1140. if (! empty($object->brouillon) && $action == 'editecheance')
  1141. {
  1142. print '<form name="editecheance" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
  1143. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1144. print '<input type="hidden" name="action" value="setecheance">';
  1145. $form->select_date($object->fin_validite,'ech','','','',"editecheance");
  1146. print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
  1147. print '</form>';
  1148. }
  1149. else
  1150. {
  1151. if (! empty($object->fin_validite))
  1152. {
  1153. print dol_print_date($object->fin_validite,'daytext');
  1154. if ($object->statut == 1 && $object->fin_validite < ($now - $conf->propal->cloture->warning_delay)) print img_warning($langs->trans("Late"));
  1155. }
  1156. else
  1157. {
  1158. print '&nbsp;';
  1159. }
  1160. }
  1161. print '</td>';
  1162. print '</tr>';
  1163. // Payment term
  1164. print '<tr><td>';
  1165. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1166. print $langs->trans('PaymentConditionsShort');
  1167. print '</td>';
  1168. if ($action != 'editconditions' && ! empty($object->brouillon)) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editconditions&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetConditions'),1).'</a></td>';
  1169. print '</tr></table>';
  1170. print '</td><td colspan="3">';
  1171. if ($action == 'editconditions')
  1172. {
  1173. $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->cond_reglement_id,'cond_reglement_id');
  1174. }
  1175. else
  1176. {
  1177. $form->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->cond_reglement_id,'none');
  1178. }
  1179. print '</td>';
  1180. print '</tr>';
  1181. // Delivery date
  1182. $langs->load('deliveries');
  1183. print '<tr><td>';
  1184. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1185. print $langs->trans('DeliveryDate');
  1186. print '</td>';
  1187. if ($action != 'editdate_livraison' && ! empty($object->brouillon)) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdate_livraison&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetDeliveryDate'),1).'</a></td>';
  1188. print '</tr></table>';
  1189. print '</td><td colspan="3">';
  1190. if ($action == 'editdate_livraison')
  1191. {
  1192. print '<form name="editdate_livraison" action="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'" method="post">';
  1193. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1194. print '<input type="hidden" name="action" value="setdate_livraison">';
  1195. $form->select_date($object->date_livraison,'liv_','','','',"editdate_livraison");
  1196. print '<input type="submit" class="button" value="'.$langs->trans('Modify').'">';
  1197. print '</form>';
  1198. }
  1199. else
  1200. {
  1201. print dol_print_date($object->date_livraison,'daytext');
  1202. }
  1203. print '</td>';
  1204. print '</tr>';
  1205. // Delivery delay
  1206. print '<tr><td>';
  1207. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1208. print $langs->trans('AvailabilityPeriod');
  1209. if (! empty($conf->commande->enabled)) print ' ('.$langs->trans('AfterOrder').')';
  1210. print '</td>';
  1211. if ($action != 'editavailability' && ! empty($object->brouillon)) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editavailability&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetAvailability'),1).'</a></td>';
  1212. print '</tr></table>';
  1213. print '</td><td colspan="3">';
  1214. if ($action == 'editavailability')
  1215. {
  1216. $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id,$object->availability_id,'availability_id',1);
  1217. }
  1218. else
  1219. {
  1220. $form->form_availability($_SERVER['PHP_SELF'].'?id='.$object->id,$object->availability_id,'none',1);
  1221. }
  1222. print '</td>';
  1223. print '</tr>';
  1224. // Origin of demand
  1225. print '<tr><td>';
  1226. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1227. print $langs->trans('Source');
  1228. print '</td>';
  1229. if ($action != 'editdemandreason' && ! empty($object->brouillon)) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editdemandreason&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetDemandReason'),1).'</a></td>';
  1230. print '</tr></table>';
  1231. print '</td><td colspan="3">';
  1232. //print $object->demand_reason_id;
  1233. if ($action == 'editdemandreason')
  1234. {
  1235. $form->form_demand_reason($_SERVER['PHP_SELF'].'?id='.$object->id,$object->demand_reason_id,'demand_reason_id',1);
  1236. }
  1237. else
  1238. {
  1239. $form->form_demand_reason($_SERVER['PHP_SELF'].'?id='.$object->id,$object->demand_reason_id,'none');
  1240. }
  1241. print '</td>';
  1242. print '</tr>';
  1243. // Payment mode
  1244. print '<tr>';
  1245. print '<td width="25%">';
  1246. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1247. print $langs->trans('PaymentMode');
  1248. print '</td>';
  1249. if ($action != 'editmode' && ! empty($object->brouillon)) print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editmode&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetMode'),1).'</a></td>';
  1250. print '</tr></table>';
  1251. print '</td><td colspan="3">';
  1252. if ($action == 'editmode')
  1253. {
  1254. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'mode_reglement_id');
  1255. }
  1256. else
  1257. {
  1258. $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'none');
  1259. }
  1260. print '</td></tr>';
  1261. // Project
  1262. if (! empty($conf->projet->enabled))
  1263. {
  1264. $langs->load("projects");
  1265. print '<tr><td>';
  1266. print '<table class="nobordernopadding" width="100%"><tr><td>';
  1267. print $langs->trans('Project').'</td>';
  1268. if ($user->rights->propale->creer)
  1269. {
  1270. if ($action != 'classify') print '<td align="right"><a href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a></td>';
  1271. print '</tr></table>';
  1272. print '</td><td colspan="3">';
  1273. if ($action == 'classify')
  1274. {
  1275. $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'projectid');
  1276. }
  1277. else
  1278. {
  1279. $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none');
  1280. }
  1281. print '</td></tr>';
  1282. }
  1283. else
  1284. {
  1285. print '</td></tr></table>';
  1286. if (! empty($object->fk_project))
  1287. {
  1288. print '<td colspan="3">';
  1289. $proj = new Project($db);
  1290. $proj->fetch($object->fk_project);
  1291. print '<a href="../projet/fiche.php?id='.$object->fk_project.'" title="'.$langs->trans('ShowProject').'">';
  1292. print $proj->ref;
  1293. print '</a>';
  1294. print '</td>';
  1295. }
  1296. else {
  1297. print '<td colspan="3">&nbsp;</td>';
  1298. }
  1299. }
  1300. print '</tr>';
  1301. }
  1302. // Other attributes
  1303. $parameters=array('colspan' => ' colspan="3"');
  1304. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  1305. if (empty($reshook) && ! empty($extrafields->attribute_label))
  1306. {
  1307. foreach($extrafields->attribute_label as $key=>$label)
  1308. {
  1309. $value=(isset($_POST["options_".$key])?$_POST["options_".$key]:$object->array_options["options_".$key]);
  1310. print "<tr><td>".$label.'</td><td colspan="3">';
  1311. print $extrafields->showInputField($key,$value);
  1312. print '</td></tr>'."\n";
  1313. }
  1314. }
  1315. // Amount HT
  1316. print '<tr><td height="10">'.$langs->trans('AmountHT').'</td>';
  1317. print '<td align="right" nowrap><b>'.price($object->total_ht).'</b></td>';
  1318. print '<td>'.$langs->trans("Currency".$conf->currency).'</td>';
  1319. // Margin Infos
  1320. if (! empty($conf->margin->enabled)) {
  1321. print '<td valign="top" width="50%" rowspan="4">';
  1322. $object->displayMarginInfos();
  1323. print '</td>';
  1324. }
  1325. print '</tr>';
  1326. // Amount VAT
  1327. print '<tr><td height="10">'.$langs->trans('AmountVAT').'</td>';
  1328. print '<td align="right" nowrap>'.price($object->total_tva).'</td>';
  1329. print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
  1330. // Amount Local Taxes
  1331. if ($mysoc->country_code=='ES')
  1332. {
  1333. if ($mysoc->localtax1_assuj=="1") //Localtax1 RE
  1334. {
  1335. print '<tr><td height="10">'.$langs->transcountry("AmountLT1",$mysoc->country_code).'</td>';
  1336. print '<td align="right" nowrap>'.price($object->total_localtax1).'</td>';
  1337. print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
  1338. }
  1339. if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF
  1340. {
  1341. print '<tr><td height="10">'.$langs->transcountry("AmountLT2",$mysoc->country_code).'</td>';
  1342. print '<td align="right" nowrap>'.price($object->total_localtax2).'</td>';
  1343. print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
  1344. }
  1345. }
  1346. // Amount TTC
  1347. print '<tr><td height="10">'.$langs->trans('AmountTTC').'</td>';
  1348. print '<td align="right" nowrap>'.price($object->total_ttc).'</td>';
  1349. print '<td>'.$langs->trans("Currency".$conf->currency).'</td></tr>';
  1350. // Statut
  1351. print '<tr><td height="10">'.$langs->trans('Status').'</td><td align="left" colspan="2">'.$object->getLibStatut(4).'</td></tr>';
  1352. print '</table><br>';
  1353. if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
  1354. {
  1355. require_once(DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php');
  1356. $formcompany= new FormCompany($db);
  1357. $blocname = 'contacts';
  1358. $title = $langs->trans('ContactsAddresses');
  1359. include(DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php');
  1360. }
  1361. if (! empty($conf->global->MAIN_DISABLE_NOTES_TAB))
  1362. {
  1363. $blocname = 'notes';
  1364. $title = $langs->trans('Notes');
  1365. include(DOL_DOCUMENT_ROOT.'/core/tpl/bloc_showhide.tpl.php');
  1366. }
  1367. /*
  1368. * Lines
  1369. */
  1370. if ($conf->use_javascript_ajax && $object->statut == 0)
  1371. {
  1372. include(DOL_DOCUMENT_ROOT.'/core/tpl/ajaxrow.tpl.php');
  1373. }
  1374. print '<table id="tablelines" class="noborder" width="100%">';
  1375. // Show object lines
  1376. $result = $object->getLinesArray();
  1377. if (! empty($object->lines)) $object->printObjectLines($action,$mysoc,$soc,$lineid,0,$hookmanager);
  1378. /*
  1379. * Form to add new line
  1380. */
  1381. if ($object->statut == 0 && $user->rights->propale->creer)
  1382. {
  1383. if ($action != 'editline')
  1384. {
  1385. $var=true;
  1386. // Add free products/services
  1387. $object->formAddFreeProduct(0,$mysoc,$soc,$hookmanager);
  1388. // Add predefined products/services
  1389. if ($conf->product->ena

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