supplier_invoice.php 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. <?php
  2. /* Copyright (C) 2003-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2011 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
  6. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  7. * Copyright (C) 2010-2013 Juanjo Menent <jmenent@2byte.es>
  8. * Copyright (C) 2011-2018 Philippe Grand <philippe.grand@atoo-net.com>
  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 3 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/supplier_invoice.php
  25. * \ingroup fournisseur
  26. * \brief Setup to admin supplier invoices
  27. */
  28. require '../main.inc.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php';
  32. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
  34. // Load translation files required by the page
  35. $langs->loadLangs(array("admin", "other", "orders"));
  36. if (!$user->admin)
  37. accessforbidden();
  38. $type=GETPOST('type', 'alpha');
  39. $value=GETPOST('value', 'alpha');
  40. $action=GETPOST('action', 'alpha');
  41. $scandir = GETPOST('scan_dir','alpha');
  42. $specimenthirdparty=new Societe($db);
  43. $specimenthirdparty->initAsSpecimen();
  44. /*
  45. * Actions
  46. */
  47. if ($action == 'updateMask')
  48. {
  49. $maskconstinvoice=GETPOST('maskconstinvoice','alpha');
  50. $maskconstcredit=GETPOST('maskconstcredit','alpha');
  51. $maskinvoice=GETPOST('maskinvoice','alpha');
  52. $maskcredit=GETPOST('maskcredit','alpha');
  53. if ($maskconstinvoice) $res = dolibarr_set_const($db,$maskconstinvoice,$maskinvoice,'chaine',0,'',$conf->entity);
  54. if ($maskconstcredit) $res = dolibarr_set_const($db,$maskconstcredit,$maskcredit,'chaine',0,'',$conf->entity);
  55. if (! $res > 0) $error++;
  56. if (! $error)
  57. {
  58. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  59. }
  60. else
  61. {
  62. setEventMessages($langs->trans("Error"), null, 'errors');
  63. }
  64. }
  65. if ($action == 'specimen') // For invoices
  66. {
  67. $modele=GETPOST('module','alpha');
  68. $facture = new FactureFournisseur($db);
  69. $facture->initAsSpecimen();
  70. $facture->thirdparty=$specimenthirdparty; // Define who should has build the invoice (so the supplier)
  71. // Search template files
  72. $file=''; $classname=''; $filefound=0;
  73. $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
  74. foreach($dirmodels as $reldir)
  75. {
  76. $file=dol_buildpath($reldir."core/modules/supplier_invoice/pdf/pdf_".$modele.".modules.php",0);
  77. if (file_exists($file))
  78. {
  79. $filefound=1;
  80. $classname = "pdf_".$modele;
  81. break;
  82. }
  83. }
  84. if ($filefound)
  85. {
  86. require_once $file;
  87. $module = new $classname($db,$facture);
  88. if ($module->write_file($facture,$langs) > 0)
  89. {
  90. header("Location: ".DOL_URL_ROOT."/document.php?modulepart=facture_fournisseur&file=SPECIMEN.pdf");
  91. return;
  92. }
  93. else
  94. {
  95. setEventMessages($module->error, $module->errors, 'errors');
  96. dol_syslog($module->error, LOG_ERR);
  97. }
  98. }
  99. else
  100. {
  101. setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
  102. dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
  103. }
  104. }
  105. // Activate a model
  106. elseif ($action == 'set')
  107. {
  108. $ret = addDocumentModel($value, $type, $label, $scandir);
  109. }
  110. elseif ($action == 'del')
  111. {
  112. $ret = delDocumentModel($value, $type);
  113. if ($ret > 0)
  114. {
  115. if ($conf->global->INVOICE_SUPPLIER_ADDON_PDF == "$value") dolibarr_del_const($db, 'INVOICE_SUPPLIER_ADDON_PDF',$conf->entity);
  116. }
  117. }
  118. // Set default model
  119. elseif ($action == 'setdoc')
  120. {
  121. if (dolibarr_set_const($db, "INVOICE_SUPPLIER_ADDON_PDF",$value,'chaine',0,'',$conf->entity))
  122. {
  123. // La constante qui a ete lue en avant du nouveau set
  124. // on passe donc par une variable pour avoir un affichage coherent
  125. $conf->global->INVOICE_SUPPLIER_ADDON_PDF = $value;
  126. }
  127. // On active le modele
  128. $ret = delDocumentModel($value, $type);
  129. if ($ret > 0)
  130. {
  131. $ret = addDocumentModel($value, $type, $label, $scandir);
  132. }
  133. }
  134. elseif ($action == 'unsetdoc')
  135. {
  136. dolibarr_del_const($db, "INVOICE_SUPPLIER_ADDON_PDF", $conf->entity);
  137. }
  138. if ($action == 'setmod')
  139. {
  140. // TODO Verifier si module numerotation choisi peut etre active
  141. // par appel methode canBeActivated
  142. dolibarr_set_const($db, "INVOICE_SUPPLIER_ADDON_NUMBER",$value,'chaine',0,'',$conf->entity);
  143. }
  144. if ($action == 'addcat')
  145. {
  146. $fourn = new Fournisseur($db);
  147. $fourn->CreateCategory($user,$_POST["cat"]);
  148. }
  149. if ($action == 'set_SUPPLIER_INVOICE_FREE_TEXT')
  150. {
  151. $freetext = GETPOST('SUPPLIER_INVOICE_FREE_TEXT','none'); // No alpha here, we want exact string
  152. $res = dolibarr_set_const($db, "SUPPLIER_INVOICE_FREE_TEXT",$freetext,'chaine',0,'',$conf->entity);
  153. if (! $res > 0) $error++;
  154. if (! $error)
  155. {
  156. setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
  157. }
  158. else
  159. {
  160. setEventMessages($langs->trans("Error"), null, 'errors');
  161. }
  162. }
  163. /*
  164. * View
  165. */
  166. $dirmodels=array_merge(array('/'),(array) $conf->modules_parts['models']);
  167. llxHeader("","");
  168. $form=new Form($db);
  169. $linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
  170. print load_fiche_titre($langs->trans("SuppliersSetup"),$linkback,'title_setup');
  171. print "<br>";
  172. $head = supplierorder_admin_prepare_head();
  173. dol_fiche_head($head, 'invoice', $langs->trans("Suppliers"), -1, 'company');
  174. // Supplier invoice numbering module
  175. print load_fiche_titre($langs->trans("SuppliersInvoiceNumberingModel"),'','');
  176. print '<table class="noborder" width="100%">';
  177. print '<tr class="liste_titre">';
  178. print '<td width="100">'.$langs->trans("Name").'</td>';
  179. print '<td>'.$langs->trans("Description").'</td>';
  180. print '<td>'.$langs->trans("Example").'</td>';
  181. print '<td align="center" width="60">'.$langs->trans("Status").'</td>';
  182. print '<td align="center" width="16">'.$langs->trans("ShortInfo").'</td>';
  183. print "</tr>\n";
  184. clearstatcache();
  185. foreach ($dirmodels as $reldir)
  186. {
  187. $dir = dol_buildpath($reldir."core/modules/supplier_invoice/");
  188. if (is_dir($dir))
  189. {
  190. $handle = opendir($dir);
  191. if (is_resource($handle))
  192. {
  193. while (($file = readdir($handle))!==false)
  194. {
  195. if (substr($file, 0, 24) == 'mod_facture_fournisseur_' && substr($file, dol_strlen($file)-3, 3) == 'php')
  196. {
  197. $file = substr($file, 0, dol_strlen($file)-4);
  198. require_once $dir.$file.'.php';
  199. $module = new $file;
  200. if ($module->isEnabled())
  201. {
  202. // Show modules according to features level
  203. if ($module->version == 'development' && $conf->global->MAIN_FEATURES_LEVEL < 2) continue;
  204. if ($module->version == 'experimental' && $conf->global->MAIN_FEATURES_LEVEL < 1) continue;
  205. print '<tr class="oddeven"><td>'.$module->nom."</td><td>\n";
  206. print $module->info();
  207. print '</td>';
  208. // Show example of numbering model
  209. print '<td class="nowrap">';
  210. $tmp=$module->getExample();
  211. if (preg_match('/^Error/',$tmp)) {
  212. $langs->load("errors"); print '<div class="error">'.$langs->trans($tmp).'</div>';
  213. }
  214. elseif ($tmp=='NotConfigured') print $langs->trans($tmp);
  215. else print $tmp;
  216. print '</td>'."\n";
  217. print '<td align="center">';
  218. if ($conf->global->INVOICE_SUPPLIER_ADDON_NUMBER == "$file")
  219. {
  220. print img_picto($langs->trans("Activated"),'switch_on');
  221. }
  222. else
  223. {
  224. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setmod&amp;value='.$file.'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
  225. }
  226. print '</td>';
  227. $invoice=new FactureFournisseur($db);
  228. $invoice->initAsSpecimen();
  229. // Info
  230. $htmltooltip='';
  231. $htmltooltip.=''.$langs->trans("Version").': <b>'.$module->getVersion().'</b><br>';
  232. $nextval=$module->getNextValue($mysoc,$invoice);
  233. if ("$nextval" != $langs->trans("NotAvailable")) { // Keep " on nextval
  234. $htmltooltip.=''.$langs->trans("NextValue").': ';
  235. if ($nextval) {
  236. if (preg_match('/^Error/',$nextval) || $nextval=='NotConfigured')
  237. $nextval = $langs->trans($nextval);
  238. $htmltooltip.=$nextval.'<br>';
  239. } else {
  240. $htmltooltip.=$langs->trans($module->error).'<br>';
  241. }
  242. }
  243. print '<td align="center">';
  244. print $form->textwithpicto('',$htmltooltip,1,0);
  245. print '</td>';
  246. print '</tr>';
  247. }
  248. }
  249. }
  250. closedir($handle);
  251. }
  252. }
  253. }
  254. print '</table><br>';
  255. /*
  256. * Modeles documents for supplier invoices
  257. */
  258. print load_fiche_titre($langs->trans("BillsPDFModules"),'','');
  259. // Defini tableau def de modele
  260. $def = array();
  261. $sql = "SELECT nom";
  262. $sql.= " FROM ".MAIN_DB_PREFIX."document_model";
  263. $sql.= " WHERE type = 'invoice_supplier'";
  264. $sql.= " AND entity = ".$conf->entity;
  265. $resql=$db->query($sql);
  266. if ($resql)
  267. {
  268. $i = 0;
  269. $num_rows=$db->num_rows($resql);
  270. while ($i < $num_rows)
  271. {
  272. $array = $db->fetch_array($resql);
  273. array_push($def, $array[0]);
  274. $i++;
  275. }
  276. }
  277. else
  278. {
  279. dol_print_error($db);
  280. }
  281. print '<table class="noborder" width="100%">'."\n";
  282. print '<tr class="liste_titre">'."\n";
  283. print '<td width="100">'.$langs->trans("Name").'</td>'."\n";
  284. print '<td>'.$langs->trans("Description").'</td>'."\n";
  285. print '<td align="center" width="60">'.$langs->trans("Status").'</td>'."\n";
  286. print '<td align="center" width="60">'.$langs->trans("Default").'</td>'."\n";
  287. print '<td align="center" width="40">'.$langs->trans("ShortInfo").'</td>';
  288. print '<td align="center" width="40">'.$langs->trans("Preview").'</td>';
  289. print '</tr>'."\n";
  290. clearstatcache();
  291. foreach ($dirmodels as $reldir)
  292. {
  293. $dir = dol_buildpath($reldir."core/modules/supplier_invoice/pdf/");
  294. if (is_dir($dir))
  295. {
  296. $handle=opendir($dir);
  297. if (is_resource($handle))
  298. {
  299. while (($file = readdir($handle))!==false)
  300. {
  301. if (preg_match('/\.modules\.php$/i',$file) && preg_match('/^(pdf_|doc_)/',$file))
  302. {
  303. $name = substr($file, 4, dol_strlen($file) -16);
  304. $classname = substr($file, 0, dol_strlen($file) -12);
  305. require_once $dir.'/'.$file;
  306. $module = new $classname($db, new FactureFournisseur($db));
  307. print "<tr class=\"oddeven\">\n";
  308. print "<td>";
  309. print (empty($module->name)?$name:$module->name);
  310. print "</td>\n";
  311. print "<td>\n";
  312. require_once $dir.$file;
  313. $module = new $classname($db,$specimenthirdparty);
  314. if (method_exists($module,'info')) print $module->info($langs);
  315. else print $module->description;
  316. print "</td>\n";
  317. // Active
  318. if (in_array($name, $def))
  319. {
  320. print '<td align="center">'."\n";
  321. //if ($conf->global->INVOICE_SUPPLIER_ADDON_PDF != "$name")
  322. //{
  323. // Even if choice is the default value, we allow to disable it: For supplier invoice, we accept to have no doc generation at all
  324. print '<a href="'.$_SERVER["PHP_SELF"].'?action=del&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'&amp;type=invoice_supplier">';
  325. print img_picto($langs->trans("Enabled"),'switch_on');
  326. print '</a>';
  327. /*}
  328. else
  329. {
  330. print img_picto($langs->trans("Enabled"),'switch_on');
  331. }*/
  332. print "</td>";
  333. }
  334. else
  335. {
  336. print '<td align="center">'."\n";
  337. print '<a href="'.$_SERVER["PHP_SELF"].'?action=set&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'&amp;type=invoice_supplier">'.img_picto($langs->trans("Disabled"),'switch_off').'</a>';
  338. print "</td>";
  339. }
  340. // Default
  341. print '<td align="center">';
  342. if ($conf->global->INVOICE_SUPPLIER_ADDON_PDF == "$name")
  343. {
  344. //print img_picto($langs->trans("Default"),'on');
  345. // Even if choice is the default value, we allow to disable it: For supplier invoice, we accept to have no doc generation at all
  346. print '<a href="'.$_SERVER["PHP_SELF"].'?action=unsetdoc&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'&amp;type=invoice_supplier"" alt="'.$langs->trans("Disable").'">'.img_picto($langs->trans("Enabled"),'on').'</a>';
  347. }
  348. else
  349. {
  350. print '<a href="'.$_SERVER["PHP_SELF"].'?action=setdoc&amp;value='.$name.'&amp;scan_dir='.$module->scandir.'&amp;label='.urlencode($module->name).'&amp;type=invoice_supplier"" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
  351. }
  352. print '</td>';
  353. // Info
  354. $htmltooltip = ''.$langs->trans("Name").': '.$module->name;
  355. $htmltooltip.='<br>'.$langs->trans("Type").': '.($module->type?$module->type:$langs->trans("Unknown"));
  356. $htmltooltip.='<br>'.$langs->trans("Width").'/'.$langs->trans("Height").': '.$module->page_largeur.'/'.$module->page_hauteur;
  357. $htmltooltip.='<br><br><u>'.$langs->trans("FeaturesSupported").':</u>';
  358. $htmltooltip.='<br>'.$langs->trans("Logo").': '.yn($module->option_logo,1,1);
  359. $htmltooltip.='<br>'.$langs->trans("PaymentMode").': '.yn($module->option_modereg,1,1);
  360. $htmltooltip.='<br>'.$langs->trans("PaymentConditions").': '.yn($module->option_condreg,1,1);
  361. print '<td align="center">';
  362. print $form->textwithpicto('',$htmltooltip,1,0);
  363. print '</td>';
  364. print '<td align="center">';
  365. print '<a href="'.$_SERVER["PHP_SELF"].'?action=specimen&amp;module='.$name.'">'.img_object($langs->trans("Preview"),'order').'</a>';
  366. print '</td>';
  367. print "</tr>\n";
  368. }
  369. }
  370. closedir($handle);
  371. }
  372. }
  373. }
  374. print '</table><br>';
  375. /*
  376. * Other options
  377. */
  378. print '<form action="'.$_SERVER["PHP_SELF"].'" method="post">';
  379. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  380. print '<input type="hidden" name="action" value="set_SUPPLIER_INVOICE_FREE_TEXT">';
  381. print load_fiche_titre($langs->trans("OtherOptions"),'','');
  382. print '<table class="noborder" width="100%">';
  383. print '<tr class="liste_titre">';
  384. print '<td>'.$langs->trans("Parameter").'</td>';
  385. print '<td align="center" width="60">'.$langs->trans("Value").'</td>';
  386. print '<td width="80">&nbsp;</td>';
  387. print "</tr>\n";
  388. $substitutionarray=pdf_getSubstitutionArray($langs, null, null, 2);
  389. $substitutionarray['__(AnyTranslationKey)__']=$langs->trans("Translation");
  390. $htmltext = '<i>'.$langs->trans("AvailableVariables").':<br>';
  391. foreach($substitutionarray as $key => $val) $htmltext.=$key.'<br>';
  392. $htmltext.='</i>';
  393. print '<tr class="oddeven"><td colspan="2">';
  394. print $form->textwithpicto($langs->trans("FreeLegalTextOnInvoices"), $langs->trans("AddCRIfTooLong").'<br><br>'.$htmltext, 1, 'help', '', 0, 2, 'freetexttooltip').'<br>';
  395. $variablename='SUPPLIER_INVOICE_FREE_TEXT';
  396. if (empty($conf->global->PDF_ALLOW_HTML_FOR_FREE_TEXT))
  397. {
  398. print '<textarea name="'.$variablename.'" class="flat" cols="120">'.$conf->global->$variablename.'</textarea>';
  399. }
  400. else
  401. {
  402. include_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  403. $doleditor=new DolEditor($variablename, $conf->global->$variablename,'',80,'dolibarr_notes');
  404. print $doleditor->Create();
  405. }
  406. print '</td><td class="right">';
  407. print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
  408. print "</td></tr>\n";
  409. print '</table><br>';
  410. print '</form>';
  411. /*
  412. * Notifications
  413. */
  414. print load_fiche_titre($langs->trans("Notifications"),'','');
  415. print '<table class="noborder" width="100%">';
  416. print '<tr class="liste_titre">';
  417. print '<td>'.$langs->trans("Parameter").'</td>';
  418. print '<td align="center" width="60"></td>';
  419. print '<td width="80">&nbsp;</td>';
  420. print "</tr>\n";
  421. print '<tr class="oddeven"><td colspan="2">';
  422. print $langs->trans("YouMayFindNotificationsFeaturesIntoModuleNotification").'<br>';
  423. print '</td><td class="right">';
  424. print "</td></tr>\n";
  425. print '</table>';
  426. // End of page
  427. llxFooter();
  428. $db->close();