PageRenderTime 61ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/htdocs/comm/propal.php

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

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