commande.php 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. <?php
  2. /* Copyright (C) 2003-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
  5. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  6. * Copyright (C) 2004 Andre Cianfarani <acianfa@free.fr>
  7. * Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
  8. * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/admin/commande.php
  25. * \ingroup commande
  26. * \brief Setup page of module Order
  27. */
  28. require("../main.inc.php");
  29. require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php");
  30. require_once(DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php');
  31. $langs->load("admin");
  32. $langs->load("bills");
  33. $langs->load("other");
  34. $langs->load("orders");
  35. if (!$user->admin)
  36. accessforbidden();
  37. /*
  38. * Actions
  39. */
  40. if ($_POST["action"] == 'updateMask')
  41. {
  42. $maskconstorder=$_POST['maskconstorder'];
  43. $maskorder=$_POST['maskorder'];
  44. if ($maskconstorder) dolibarr_set_const($db,$maskconstorder,$maskorder,'chaine',0,'',$conf->entity);
  45. }
  46. if ($_GET["action"] == 'specimen')
  47. {
  48. $modele=$_GET["module"];
  49. $commande = new Commande($db);
  50. $commande->initAsSpecimen();
  51. // Charge le modele
  52. $dir = DOL_DOCUMENT_ROOT . "/includes/modules/commande/";
  53. $file = "pdf_".$modele.".modules.php";
  54. if (file_exists($dir.$file))
  55. {
  56. $classname = "pdf_".$modele;
  57. require_once($dir.$file);
  58. $obj = new $classname($db);
  59. if ($obj->write_file($commande,$langs) > 0)
  60. {
  61. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=commande&file=SPECIMEN.pdf");
  62. return;
  63. }
  64. else
  65. {
  66. $mesg='<div class="error">'.$obj->error.'</div>';
  67. dol_syslog($obj->error, LOG_ERR);
  68. }
  69. }
  70. else
  71. {
  72. $mesg='<div class="error">'.$langs->trans("ErrorModuleNotFound").'</div>';
  73. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  74. }
  75. }
  76. if ($_GET["action"] == 'set')
  77. {
  78. $type='order';
  79. $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
  80. $sql.= " VALUES ('".$db->escape($_GET["value"])."','".$type."',".$conf->entity.", ";
  81. $sql.= ($_GET["label"]?"'".$db->escape($_GET["label"])."'":'null').", ";
  82. $sql.= (! empty($_GET["scandir"])?"'".$db->escape($_GET["scandir"])."'":"null");
  83. $sql.= ")";
  84. if ($db->query($sql))
  85. {
  86. }
  87. }
  88. if ($_GET["action"] == 'del')
  89. {
  90. $type='order';
  91. $sql = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
  92. $sql.= " WHERE nom = '".$_GET["value"]."'";
  93. $sql.= " AND type = '".$type."'";
  94. $sql.= " AND entity = ".$conf->entity;
  95. if ($db->query($sql))
  96. {
  97. }
  98. }
  99. if ($_GET["action"] == 'setdoc')
  100. {
  101. $db->begin();
  102. if (dolibarr_set_const($db, "COMMANDE_ADDON_PDF",$_GET["value"],'chaine',0,'',$conf->entity))
  103. {
  104. $conf->global->COMMANDE_ADDON_PDF = $_GET["value"];
  105. }
  106. // On active le modele
  107. $type='order';
  108. $sql_del = "DELETE FROM ".MAIN_DB_PREFIX."document_model";
  109. $sql_del.= " WHERE nom = '".$db->escape($_GET["value"])."'";
  110. $sql_del.= " AND type = '".$type."'";
  111. $sql_del.= " AND entity = ".$conf->entity;
  112. $result1=$db->query($sql_del);
  113. $sql = "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity, libelle, description)";
  114. $sql.= " VALUES ('".$_GET["value"]."', '".$type."', ".$conf->entity.", ";
  115. $sql.= ($_GET["label"]?"'".$db->escape($_GET["label"])."'":'null').", ";
  116. $sql.= (! empty($_GET["scandir"])?"'".$_GET["scandir"]."'":"null");
  117. $sql.= ")";
  118. $result2=$db->query($sql);
  119. if ($result1 && $result2)
  120. {
  121. $db->commit();
  122. }
  123. else
  124. {
  125. $db->rollback();
  126. }
  127. }
  128. if ($_GET["action"] == 'setmod')
  129. {
  130. // TODO Verifier si module numerotation choisi peut etre active
  131. // par appel methode canBeActivated
  132. dolibarr_set_const($db, "COMMANDE_ADDON",$_GET["value"],'chaine',0,'',$conf->entity);
  133. }
  134. if ($_POST["action"] == 'set_COMMANDE_DRAFT_WATERMARK')
  135. {
  136. dolibarr_set_const($db, "COMMANDE_DRAFT_WATERMARK",trim($_POST["COMMANDE_DRAFT_WATERMARK"]),'chaine',0,'',$conf->entity);
  137. }
  138. if ($_POST["action"] == 'set_COMMANDE_FREE_TEXT')
  139. {
  140. dolibarr_set_const($db, "COMMANDE_FREE_TEXT",$_POST["COMMANDE_FREE_TEXT"],'chaine',0,'',$conf->entity);
  141. }
  142. if ($_POST["action"] == 'setvalidorder')
  143. {
  144. dolibarr_set_const($db, "COMMANDE_VALID_AFTER_CLOSE_PROPAL",$_POST["validorder"],'chaine',0,'',$conf->entity);
  145. }
  146. if ($_POST["action"] == 'deliverycostline')
  147. {
  148. dolibarr_set_const($db, "COMMANDE_ADD_DELIVERY_COST_LINE",$_POST["addline"],'chaine',0,'',$conf->entity);
  149. }
  150. if ($_POST["action"] == 'set_use_customer_contact_as_recipient')
  151. {
  152. dolibarr_set_const($db, "COMMANDE_USE_CUSTOMER_CONTACT_AS_RECIPIENT",$_POST["use_customer_contact_as_recipient"],'chaine',0,'',$conf->entity);
  153. }
  154. /*
  155. * View
  156. */
  157. llxHeader();
  158. $html=new Form($db);
  159. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php">'.$langs->trans("BackToModuleList").'</a>';
  160. print_fiche_titre($langs->trans("OrdersSetup"),$linkback,'setup');
  161. print "<br>";
  162. /*
  163. * Numbering module
  164. */
  165. print_titre($langs->trans("OrdersNumberingModules"));
  166. print '<table class="noborder" width="100%">';
  167. print '<tr class="liste_titre">';
  168. print '<td width="100">'.$langs->trans("Name").'</td>';
  169. print '<td>'.$langs->trans("Description").'</td>';
  170. print '<td>'.$langs->trans("Example").'</td>';
  171. print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
  172. print '<td align="center" width="16">'.$langs->trans("Infos").'</td>';
  173. print "</tr>\n";
  174. clearstatcache();
  175. foreach ($conf->file->dol_document_root as $dirroot)
  176. {
  177. $dir = $dirroot . "/includes/modules/commande/";
  178. if (is_dir($dir))
  179. {
  180. $handle = opendir($dir);
  181. if (is_resource($handle))
  182. {
  183. $var=true;
  184. while (($file = readdir($handle))!==false)
  185. {
  186. if (substr($file, 0, 13) == 'mod_commande_' && substr($file, dol_strlen($file)-3, 3) == 'php')
  187. {
  188. $file = substr($file, 0, dol_strlen($file)-4);
  189. require_once(DOL_DOCUMENT_ROOT ."/includes/modules/commande/".$file.".php");
  190. $module = new $file;
  191. // Show modules according to features level
  192. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  193. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  194. if ($module->isEnabled())
  195. {
  196. $var=!$var;
  197. print '<tr '.$bc[$var].'><td>'.$module->nom."</td><td>\n";
  198. print $module->info();
  199. print '</td>';
  200. // Show example of numbering module
  201. print '<td nowrap="nowrap">';
  202. $tmp=$module->getExample();
  203. if (preg_match('/^Error/',$tmp)) print $langs->trans($tmp);
  204. else print $tmp;
  205. print '</td>'."\n";
  206. print '<td align="center">';
  207. if ($conf->global->COMMANDE_ADDON == "$file")
  208. {
  209. print img_picto($langs->trans("Activated"),'on');
  210. }
  211. else
  212. {
  213. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&amp;value='.$file.'">';
  214. print img_picto($langs->trans("Disabled"),'off');
  215. print '</a>';
  216. }
  217. print '</td>';
  218. $commande=new Commande($db);
  219. $commande->initAsSpecimen();
  220. // Info
  221. $htmltooltip='';
  222. $htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  223. $facture->type=0;
  224. $nextval=$module->getNextValue($mysoc,$commande);
  225. if ("$nextval" != $langs->trans("NotAvailable")) // Keep " on nextval
  226. {
  227. $htmltooltip.=''.$langs->trans("NextValue").': ';
  228. if ($nextval)
  229. {
  230. $htmltooltip.=$nextval.'<br>';
  231. }
  232. else
  233. {
  234. $htmltooltip.=$langs->trans($module->error).'<br>';
  235. }
  236. }
  237. print '<td align="center">';
  238. print $html->textwithpicto('',$htmltooltip,1,0);
  239. print '</td>';
  240. print '</tr>';
  241. }
  242. }
  243. }
  244. closedir($handle);
  245. }
  246. }
  247. }
  248. print '</table><br>';
  249. /*
  250. * Modeles de documents
  251. */
  252. print_titre($langs->trans("OrdersModelModule"));
  253. // Defini tableau def de modele
  254. $type='order';
  255. $def = array();
  256. $sql = "SELECT nom";
  257. $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
  258. $sql.= " WHERE type = '".$type."'";
  259. $sql.= " AND entity = ".$conf->entity;
  260. $resql=$db->query($sql);
  261. if ($resql)
  262. {
  263. $i = 0;
  264. $num_rows=$db->num_rows($resql);
  265. while ($i < $num_rows)
  266. {
  267. $array = $db->fetch_array($resql);
  268. array_push($def, $array[0]);
  269. $i++;
  270. }
  271. }
  272. else
  273. {
  274. dol_print_error($db);
  275. }
  276. print "<table class=\"noborder\" width=\"100%\">\n";
  277. print "<tr class=\"liste_titre\">\n";
  278. print ' <td width="100">'.$langs->trans("Name")."</td>\n";
  279. print " <td>".$langs->trans("Description")."</td>\n";
  280. print '<td align="center" width="40">'.$langs->trans("Status")."</td>\n";
  281. print '<td align="center" width="40">'.$langs->trans("Default")."</td>\n";
  282. print '<td align="center" width="40">'.$langs->trans("Infos").'</td>';
  283. print '<td align="center" width="40">'.$langs->trans("Preview").'</td>';
  284. print "</tr>\n";
  285. clearstatcache();
  286. foreach ($conf->file->dol_document_root as $dirroot)
  287. {
  288. $dir = $dirroot . "/includes/modules/commande/";
  289. if (is_dir($dir))
  290. {
  291. $handle = opendir($dir);
  292. if (is_resource($handle))
  293. {
  294. $var=true;
  295. while (($file = readdir($handle))!==false)
  296. {
  297. if (preg_match('/\.modules\.php$/i',$file) && substr($file,0,4) == 'pdf_')
  298. {
  299. $name = substr($file, 4, dol_strlen($file) -16);
  300. $classname = substr($file, 0, dol_strlen($file) -12);
  301. $var=!$var;
  302. print "<tr ".$bc[$var].">\n <td>";
  303. print "$name";
  304. print "</td>\n <td>\n";
  305. require_once($dir.$file);
  306. $module = new $classname($db);
  307. print $module->description;
  308. print "</td>\n";
  309. // Activated
  310. print "<td align=\"center\">\n";
  311. if (in_array($name, $def))
  312. {
  313. if ($conf->global->COMMANDE_ADDON_PDF != "$name")
  314. {
  315. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
  316. print img_picto($langs->trans("Activated"),'on');
  317. print '</a>';
  318. }
  319. else
  320. {
  321. print img_picto($langs->trans("Activated"),'on');
  322. }
  323. }
  324. else
  325. {
  326. print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
  327. print img_picto($langs->trans("Disabled"),'off');
  328. print '</a>';
  329. }
  330. print "</td>";
  331. // Defaut
  332. print "<td align=\"center\">";
  333. if ($conf->global->COMMANDE_ADDON_PDF == "$name")
  334. {
  335. print img_picto($langs->trans("Yes"),'on');
  336. }
  337. else
  338. {
  339. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&amp;value='.$name.'&amp;scandir='.$module->scandir.'&amp;label='.urlencode($module->name).'">';
  340. print img_picto($langs->trans("No"),'off');
  341. print '</a>';
  342. }
  343. print '</td>';
  344. // Info
  345. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  346. $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
  347. $htmltooltip.='<br>'.$langs->trans("Height").'/'.$langs->trans("Width").': '.$module->page_hauteur.'/'.$module->page_largeur;
  348. $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  349. $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
  350. $htmltooltip.='<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1);
  351. $htmltooltip.='<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1);
  352. $htmltooltip.='<br>'.$langs->trans("MultiLanguage").': '.yn($module->option_multilang,1,1);
  353. //$htmltooltip.='<br>'.$langs->trans("Escompte").': '.yn($module->option_escompte,1,1);
  354. //$htmltooltip.='<br>'.$langs->trans("CreditNote").': '.yn($module->option_credit_note,1,1);
  355. $htmltooltip.='<br>'.$langs->trans("WatermarkOnDraftOrders").': '.yn($module->option_draft_watermark,1,1);
  356. print '<td align="center">';
  357. print $html->textwithpicto('',$htmltooltip,1,0);
  358. print '</td>';
  359. print '<td align="center">';
  360. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&module='.$name.'">'.img_object($langs->trans("Preview"),'order').'</a>';
  361. print '</td>';
  362. print "</tr>\n";
  363. }
  364. }
  365. closedir($handle);
  366. }
  367. }
  368. }
  369. print '</table>';
  370. //Autres Options
  371. print "<br>";
  372. print_titre($langs->trans("OtherOptions"));
  373. print '<table class="noborder" width="100%">';
  374. print '<tr class="liste_titre">';
  375. print '<td>'.$langs->trans("Parameter").'</td>';
  376. print '<td align="center" width="60">'.$langs->trans("Value").'</td>';
  377. print "<td>&nbsp;</td>\n";
  378. print "</tr>\n";
  379. $var=true;
  380. // Valider la commande apres cloture de la propale
  381. // permet de na pas passer par l'option commande provisoire
  382. /*
  383. $var=! $var;
  384. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  385. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  386. print '<input type="hidden" name="action" value="setvalidorder">';
  387. print '<tr '.$bc[$var].'>';
  388. print '<td>'.$langs->trans("ValidOrderAfterPropalClosed").'</td>';
  389. print '<td width="60" align="center">'.$html->selectyesno("validorder",$conf->global->COMMANDE_VALID_AFTER_CLOSE_PROPAL,1).'</td>';
  390. print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  391. print '</tr>';
  392. print '</form>';
  393. */
  394. // Ajouter une ligne de frais port indiquant le poids de la commande
  395. /*
  396. $var=! $var;
  397. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  398. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  399. print '<input type="hidden" name="action" value="deliverycostline">';
  400. print '<tr '.$bc[$var].'>';
  401. print '<td>'.$langs->trans("AddDeliveryCostLine").'</td>';
  402. print '<td width="60" align="center">'.$html->selectyesno("addline",$conf->global->COMMANDE_ADD_DELIVERY_COST_LINE,1).'</td>';
  403. print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  404. print '</tr>';
  405. print '</form>';
  406. */
  407. // Utiliser le contact de la commande dans le document
  408. /*
  409. $var=! $var;
  410. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  411. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  412. print '<input type="hidden" name="action" value="set_use_customer_contact_as_recipient">';
  413. print '<tr '.$bc[$var].'>';
  414. print '<td>'.$langs->trans("UseCustomerContactAsOrderRecipientIfExist").'</td>';
  415. print '<td width="60" align="center">'.$html->selectyesno("use_customer_contact_as_recipient",$conf->global->COMMANDE_USE_CUSTOMER_CONTACT_AS_RECIPIENT,1).'</td>';
  416. print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Modify").'"></td>';
  417. print '</tr>';
  418. print '</form>';
  419. */
  420. $var=! $var;
  421. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  422. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  423. print '<input type="hidden" name="action" value="set_COMMANDE_FREE_TEXT">';
  424. print '<tr '.$bc[$var].'><td colspan="2">';
  425. print $langs->trans("FreeLegalTextOnOrders").' ('.$langs->trans("AddCRIfTooLong").')<br>';
  426. print '<textarea name="COMMANDE_FREE_TEXT" class="flat" cols="120">'.$conf->global->COMMANDE_FREE_TEXT.'</textarea>';
  427. print '</td><td align="right">';
  428. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  429. print "</td></tr>\n";
  430. print '</form>';
  431. //Use draft Watermark
  432. $var=!$var;
  433. print "<form method=\"post\" action=\"".$_SERVER["PHP_SELF"]."\">";
  434. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  435. print "<input type=\"hidden\" name=\"action\" value=\"set_COMMANDE_DRAFT_WATERMARK\">";
  436. print '<tr '.$bc[$var].'><td colspan="2">';
  437. print $langs->trans("WatermarkOnDraftOrders").'<br>';
  438. print '<input size="50" class="flat" type="text" name="COMMANDE_DRAFT_WATERMARK" value="'.$conf->global->COMMANDE_DRAFT_WATERMARK.'">';
  439. print '</td><td align="right">';
  440. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  441. print "</td></tr>\n";
  442. print '</form>';
  443. print '</table>';
  444. print '<br>';
  445. llxFooter();
  446. ?>