modFournisseur.class.php 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906
  1. <?php
  2. /* Copyright (C) 2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2013-2015 Philippe Grand <philippe.grand@atoo-net.com>
  7. * Copyright (C) 2020 Ahmad Jamaly Rabib <rabib@metroworks.co.jp>
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 3 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  21. */
  22. /**
  23. * \defgroup fournisseur Module suppliers
  24. * \file htdocs/core/modules/modFournisseur.class.php
  25. * \ingroup fournisseur
  26. * \brief Description and activation file for the module Supplier
  27. */
  28. include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
  29. /**
  30. * Description and activation class for module Fournisseur
  31. */
  32. class modFournisseur extends DolibarrModules
  33. {
  34. /**
  35. * Constructor. Define names, constants, directories, boxes, permissions
  36. *
  37. * @param DoliDB $db Database handler
  38. */
  39. public function __construct($db)
  40. {
  41. global $conf, $user;
  42. $this->db = $db;
  43. $this->numero = 40;
  44. // Family can be 'crm','financial','hr','projects','product','ecm','technic','other'
  45. // It is used to group modules in module setup page
  46. $this->family = "srm";
  47. $this->module_position = '12';
  48. // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
  49. $this->name = preg_replace('/^mod/i', '', get_class($this));
  50. $this->description = "Gestion des fournisseurs";
  51. // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
  52. $this->version = 'dolibarr';
  53. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  54. $this->picto = 'company';
  55. // Data directories to create when module is enabled
  56. $this->dirs = array(
  57. "/fournisseur/temp",
  58. "/fournisseur/commande",
  59. "/fournisseur/commande/temp",
  60. "/fournisseur/facture",
  61. "/fournisseur/facture/temp"
  62. );
  63. // Dependencies
  64. $this->depends = array("modSociete");
  65. $this->requiredby = array("modSupplierProposal");
  66. $this->langfiles = array('bills', 'companies', 'suppliers', 'orders', 'sendings');
  67. // Config pages
  68. $this->config_page_url = array("supplier_order.php");
  69. // Constants
  70. $this->const = array();
  71. $r = 0;
  72. $this->const[$r][0] = "COMMANDE_SUPPLIER_ADDON_PDF";
  73. $this->const[$r][1] = "chaine";
  74. $this->const[$r][2] = "muscadet";
  75. $this->const[$r][3] = 'Nom du gestionnaire de generation des bons de commande en PDF';
  76. $this->const[$r][4] = 0;
  77. $r++;
  78. $this->const[$r][0] = "COMMANDE_SUPPLIER_ADDON_NUMBER";
  79. $this->const[$r][1] = "chaine";
  80. $this->const[$r][2] = "mod_commande_fournisseur_muguet";
  81. $this->const[$r][3] = 'Nom du gestionnaire de numerotation des commandes fournisseur';
  82. $this->const[$r][4] = 0;
  83. $r++;
  84. /* For supplier invoice, we must not have default pdf template on. In most cases, we need to join PDF from supplier, not have a document generated.
  85. $this->const[$r][0] = "INVOICE_SUPPLIER_ADDON_PDF";
  86. $this->const[$r][1] = "chaine";
  87. $this->const[$r][2] = "canelle";
  88. $this->const[$r][3] = 'Nom du gestionnaire de generation des factures fournisseur en PDF';
  89. $this->const[$r][4] = 0;
  90. $r++;
  91. */
  92. $this->const[$r][0] = "INVOICE_SUPPLIER_ADDON_NUMBER";
  93. $this->const[$r][1] = "chaine";
  94. $this->const[$r][2] = "mod_facture_fournisseur_cactus";
  95. $this->const[$r][3] = 'Nom du gestionnaire de numerotation des factures fournisseur';
  96. $this->const[$r][4] = 0;
  97. $r++;
  98. $this->const[$r][0] = "SUPPLIER_ORDER_ADDON_PDF_ODT_PATH";
  99. $this->const[$r][1] = "chaine";
  100. $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/supplier_orders";
  101. $this->const[$r][3] = '';
  102. $this->const[$r][4] = 0;
  103. $r++;
  104. // Boxes
  105. $this->boxes = array(
  106. 0=>array('file'=>'box_graph_invoices_supplier_permonth.php', 'enabledbydefaulton'=>'Home'),
  107. 1=>array('file'=>'box_graph_orders_supplier_permonth.php', 'enabledbydefaulton'=>'Home'),
  108. 2=>array('file'=>'box_fournisseurs.php', 'enabledbydefaulton'=>'Home'),
  109. 3=>array('file'=>'box_factures_fourn_imp.php', 'enabledbydefaulton'=>'Home'),
  110. 4=>array('file'=>'box_factures_fourn.php', 'enabledbydefaulton'=>'Home'),
  111. 5=>array('file'=>'box_supplier_orders.php', 'enabledbydefaulton'=>'Home'),
  112. 6=>array('file'=>'box_supplier_orders_awaiting_reception.php', 'enabledbydefaulton'=>'Home'),
  113. );
  114. $arraydate = dol_getdate(dol_now());
  115. $datestart = dol_mktime(23, 0, 0, $arraydate['mon'], $arraydate['mday'], $arraydate['year']);
  116. $this->cronjobs = array(
  117. 0 => array(
  118. 'label'=>'RecurringSupplierInvoicesJob',
  119. 'jobtype'=>'method',
  120. 'class'=>'fourn/class/fournisseur.facture-rec.class.php',
  121. 'objectname'=>'FactureFournisseurRec',
  122. 'method'=>'createRecurringInvoices',
  123. 'parameters'=>'',
  124. 'comment'=>'Generate recurring supplier invoices',
  125. 'frequency'=>1,
  126. 'unitfrequency'=>3600 * 24,
  127. 'priority'=>51,
  128. 'status'=>1,
  129. 'datestart'=>$datestart
  130. ));
  131. // Permissions
  132. $this->rights = array();
  133. $this->rights_class = 'fournisseur';
  134. $r = 0;
  135. $r++;
  136. $this->rights[$r][0] = 1181;
  137. $this->rights[$r][1] = 'Consulter les fournisseurs';
  138. $this->rights[$r][2] = 'r';
  139. $this->rights[$r][3] = 0;
  140. $this->rights[$r][4] = 'lire';
  141. $r++;
  142. $this->rights[$r][0] = 1182;
  143. $this->rights[$r][1] = 'Consulter les commandes fournisseur';
  144. $this->rights[$r][2] = 'r';
  145. $this->rights[$r][3] = 0;
  146. $this->rights[$r][4] = 'commande';
  147. $this->rights[$r][5] = 'lire';
  148. $r++;
  149. $this->rights[$r][0] = 1183;
  150. $this->rights[$r][1] = 'Creer une commande fournisseur';
  151. $this->rights[$r][2] = 'w';
  152. $this->rights[$r][3] = 0;
  153. $this->rights[$r][4] = 'commande';
  154. $this->rights[$r][5] = 'creer';
  155. $r++;
  156. $this->rights[$r][0] = 1184;
  157. $this->rights[$r][1] = 'Valider une commande fournisseur';
  158. $this->rights[$r][2] = 'w';
  159. $this->rights[$r][3] = 0;
  160. $this->rights[$r][4] = 'supplier_order_advance';
  161. $this->rights[$r][5] = 'validate';
  162. $r++;
  163. $this->rights[$r][0] = 1185;
  164. $this->rights[$r][1] = 'Approuver une commande fournisseur';
  165. $this->rights[$r][2] = 'w';
  166. $this->rights[$r][3] = 0;
  167. $this->rights[$r][4] = 'commande';
  168. $this->rights[$r][5] = 'approuver';
  169. $r++;
  170. $this->rights[$r][0] = 1186;
  171. $this->rights[$r][1] = 'Commander une commande fournisseur';
  172. $this->rights[$r][2] = 'w';
  173. $this->rights[$r][3] = 0;
  174. $this->rights[$r][4] = 'commande';
  175. $this->rights[$r][5] = 'commander';
  176. $r++;
  177. $this->rights[$r][0] = 1187;
  178. $this->rights[$r][1] = 'Receptionner une commande fournisseur';
  179. $this->rights[$r][2] = 'd';
  180. $this->rights[$r][3] = 0;
  181. $this->rights[$r][4] = 'commande';
  182. $this->rights[$r][5] = 'receptionner';
  183. $r++;
  184. $this->rights[$r][0] = 1189;
  185. $this->rights[$r][1] = 'Check/Uncheck a supplier order reception';
  186. $this->rights[$r][2] = 'w';
  187. $this->rights[$r][3] = 0;
  188. $this->rights[$r][4] = 'commande_advance';
  189. $this->rights[$r][5] = 'check';
  190. $r++;
  191. $this->rights[$r][0] = 1188;
  192. $this->rights[$r][1] = 'Supprimer une commande fournisseur';
  193. $this->rights[$r][2] = 'd';
  194. $this->rights[$r][3] = 0;
  195. $this->rights[$r][4] = 'commande';
  196. $this->rights[$r][5] = 'supprimer';
  197. if (!empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED)) {
  198. $r++;
  199. $this->rights[$r][0] = 1190;
  200. $this->rights[$r][1] = 'Approve supplier order (second level)'; // $langs->trans("Permission1190");
  201. $this->rights[$r][2] = 'w';
  202. $this->rights[$r][3] = 0;
  203. $this->rights[$r][4] = 'commande';
  204. $this->rights[$r][5] = 'approve2';
  205. }
  206. $r++;
  207. $this->rights[$r][0] = 1191;
  208. $this->rights[$r][1] = 'Exporter les commande fournisseurs, attributs';
  209. $this->rights[$r][2] = 'r';
  210. $this->rights[$r][3] = 0;
  211. $this->rights[$r][4] = 'commande';
  212. $this->rights[$r][5] = 'export';
  213. $r++;
  214. $this->rights[$r][0] = 1231;
  215. $this->rights[$r][1] = 'Consulter les factures fournisseur';
  216. $this->rights[$r][2] = 'r';
  217. $this->rights[$r][3] = 0;
  218. $this->rights[$r][4] = 'facture';
  219. $this->rights[$r][5] = 'lire';
  220. $r++;
  221. $this->rights[$r][0] = 1232;
  222. $this->rights[$r][1] = 'Creer une facture fournisseur';
  223. $this->rights[$r][2] = 'w';
  224. $this->rights[$r][3] = 0;
  225. $this->rights[$r][4] = 'facture';
  226. $this->rights[$r][5] = 'creer';
  227. $r++;
  228. $this->rights[$r][0] = 1233;
  229. $this->rights[$r][1] = 'Valider une facture fournisseur';
  230. $this->rights[$r][2] = 'w';
  231. $this->rights[$r][3] = 0;
  232. $this->rights[$r][4] = 'supplier_invoice_advance';
  233. $this->rights[$r][5] = 'validate';
  234. $r++;
  235. $this->rights[$r][0] = 1234;
  236. $this->rights[$r][1] = 'Supprimer une facture fournisseur';
  237. $this->rights[$r][2] = 'd';
  238. $this->rights[$r][3] = 0;
  239. $this->rights[$r][4] = 'facture';
  240. $this->rights[$r][5] = 'supprimer';
  241. $r++;
  242. $this->rights[$r][0] = 1235;
  243. $this->rights[$r][1] = 'Envoyer les factures par mail';
  244. $this->rights[$r][2] = 'a';
  245. $this->rights[$r][3] = 0;
  246. $this->rights[$r][4] = 'supplier_invoice_advance';
  247. $this->rights[$r][5] = 'send';
  248. $r++;
  249. $this->rights[$r][0] = 1236;
  250. $this->rights[$r][1] = 'Exporter les factures fournisseurs, attributs et reglements';
  251. $this->rights[$r][2] = 'r';
  252. $this->rights[$r][3] = 0;
  253. $this->rights[$r][4] = 'facture';
  254. $this->rights[$r][5] = 'export';
  255. // Menus
  256. //-------
  257. $this->menu = 1; // This module add menu entries. They are coded into menu manager.
  258. // Exports
  259. //--------
  260. $r = 0;
  261. $r++;
  262. $this->export_code[$r] = $this->rights_class.'_'.$r;
  263. $this->export_label[$r] = 'Vendor invoices and lines of invoices';
  264. $this->export_icon[$r] = 'invoice';
  265. $this->export_permission[$r] = array(array("fournisseur", "facture", "export"));
  266. $this->export_fields_array[$r] = array(
  267. 's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 'ps.nom'=>'ParentCompany', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode', 's.phone'=>'Phone',
  268. 's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.idprof5'=>'ProfId5', 's.idprof6'=>'ProfId6',
  269. 's.code_compta'=>'CustomerAccountancyCode', 's.code_compta_fournisseur'=>'SupplierAccountancyCode', 's.tva_intra'=>'VATIntra',
  270. 'f.rowid'=>"InvoiceId", 'f.ref'=>"InvoiceRef", 'f.ref_supplier'=>"RefSupplier", 'f.datec'=>"InvoiceDateCreation", 'f.datef'=>"DateInvoice", 'f.date_lim_reglement'=>'DateMaxPayment',
  271. 'f.total_ht'=>"TotalHT", 'f.total_ttc'=>"TotalTTC", 'f.total_tva'=>"TotalVAT", 'f.paye'=>"InvoicePaid", 'f.fk_statut'=>'InvoiceStatus', 'f.note_public'=>"InvoiceNote",
  272. 'fd.rowid'=>'LineId', 'fd.description'=>"LineDescription", 'fd.tva_tx'=>"LineVATRate", 'fd.qty'=>"LineQty", 'fd.remise_percent'=>"Discount", 'fd.total_ht'=>"LineTotalHT",
  273. 'fd.total_ttc'=>"LineTotalTTC", 'fd.tva'=>"LineTotalVAT", 'fd.date_start'=>"DateStart", 'fd.date_end'=>"DateEnd", 'fd.special_code'=>'SpecialCode',
  274. 'fd.product_type'=>'TypeOfLineServiceOrProduct', 'fd.fk_product'=>'ProductId',
  275. 'p.ref'=>'ProductRef', 'p.label'=>'ProductLabel', 'p.accountancy_code_buy'=>'ProductAccountancyBuyCode', 'project.rowid'=>'ProjectId',
  276. 'project.ref'=>'ProjectRef', 'project.title'=>'ProjectLabel'
  277. );
  278. if (!empty($conf->multicurrency->enabled)) {
  279. $this->export_fields_array[$r]['f.multicurrency_code'] = 'Currency';
  280. $this->export_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
  281. $this->export_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
  282. $this->export_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
  283. $this->export_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
  284. }
  285. //$this->export_TypeFields_array[$r]=array(
  286. // 's.rowid'=>"Numeric",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text','s.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text',
  287. // 's.ape'=>'Text','s.idprof4'=>'Text','s.tva_intra'=>'Text','f.ref'=>"Text",'f.datec'=>"Date",'f.datef'=>"Date",'f.total_ht'=>"Numeric",'f.total_ttc'=>"Numeric",'f.total_tva'=>"Numeric",
  288. // 'f.paye'=>"Boolean",'f.fk_statut'=>'Status','f.note_public'=>"Text",'fd.description'=>"Text",'fd.tva_tx'=>"Text",'fd.qty'=>"Numeric",'fd.total_ht'=>"Numeric",'fd.total_ttc'=>"Numeric",
  289. // 'fd.tva'=>"Numeric",'fd.product_type'=>'Numeric','fd.fk_product'=>'List:product:label','p.ref'=>'Text','p.label'=>'Text'
  290. //);
  291. $this->export_TypeFields_array[$r] = array(
  292. 's.nom'=>'Text', 'ps.nom'=>'Text', 's.address'=>'Text', 's.zip'=>'Text', 's.town'=>'Text', 'c.code'=>'Text', 's.phone'=>'Text', 's.siren'=>'Text', 's.siret'=>'Text', 's.ape'=>'Text', 's.idprof4'=>'Text', 's.idprof5'=>'Text', 's.idprof6'=>'Text',
  293. 's.code_compta'=>'Text', 's.code_compta_fournisseur'=>'Text', 's.tva_intra'=>'Text', 'f.ref'=>"Text", 'f.ref_supplier'=>"Text", 'f.datec'=>"Date", 'f.datef'=>"Date", 'f.date_lim_reglement'=>'Date',
  294. 'f.total_ht'=>"Numeric", 'f.total_ttc'=>"Numeric", 'f.total_tva'=>"Numeric", 'f.paye'=>"Boolean", 'f.fk_statut'=>'Status', 'f.note_public'=>"Text", 'fd.description'=>"Text", 'fd.tva_tx'=>"Text",
  295. 'fd.qty'=>"Numeric", 'fd.total_ht'=>"Numeric", 'fd.total_ttc'=>"Numeric", 'fd.tva'=>"Numeric", 'fd.date_start'=>"Date", 'fd.date_end'=>"Date", 'fd.special_code'=>"Numeric",
  296. 'fd.product_type'=>'Numeric', 'fd.fk_product'=>'List:product:label',
  297. 'p.ref'=>'Text', 'p.label'=>'Text', 'project.ref'=>'Text', 'project.title'=>'Text'
  298. );
  299. $this->export_entities_array[$r] = array(
  300. 's.rowid'=>"company", 's.nom'=>'company', 'ps.nom'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company', 'c.code'=>'company', 's.phone'=>'company', 's.siren'=>'company', 's.siret'=>'company',
  301. 's.ape'=>'company', 's.idprof4'=>'company', 's.idprof5'=>'company', 's.idprof6'=>'company', 's.code_compta'=>'company', 's.code_compta_fournisseur'=>'company', 's.tva_intra'=>'company', 'f.rowid'=>"invoice",
  302. 'f.ref'=>"invoice", 'f.ref_supplier'=>"invoice", 'f.datec'=>"invoice", 'f.datef'=>"invoice", 'f.date_lim_reglement'=>'invoice', 'f.total_ht'=>"invoice", 'f.total_ttc'=>"invoice", 'f.total_tva'=>"invoice",
  303. 'f.paye'=>"invoice", 'f.fk_statut'=>'invoice', 'f.note_public'=>"invoice", 'fd.rowid'=>'invoice_line', 'fd.description'=>"invoice_line", 'fd.tva_tx'=>"invoice_line", 'fd.qty'=>"invoice_line",
  304. 'fd.remise_percent'=>"invoice_line", 'fd.total_ht'=>"invoice_line", 'fd.total_ttc'=>"invoice_line", 'fd.tva'=>"invoice_line", 'fd.date_start'=>"invoice_line", 'fd.date_end'=>"invoice_line", 'fd.special_code'=>"invoice_line",
  305. 'fd.product_type'=>'invoice_line', 'fd.fk_product'=>'product',
  306. 'p.ref'=>'product', 'p.label'=>'product', 'p.accountancy_code_buy'=>'product', 'project.rowid'=>'project', 'project.ref'=>'project', 'project.title'=>'project'
  307. );
  308. $this->export_dependencies_array[$r] = array('invoice_line'=>'fd.rowid', 'product'=>'fd.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
  309. // Add extra fields object
  310. $keyforselect = 'facture_fourn';
  311. $keyforelement = 'invoice';
  312. $keyforaliasextra = 'extra';
  313. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  314. $keyforselect = 'facture_fourn_det';
  315. $keyforelement = 'invoice_line';
  316. $keyforaliasextra = 'extraline';
  317. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  318. // End add extra fields line
  319. $this->export_sql_start[$r] = 'SELECT DISTINCT ';
  320. $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
  321. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as ps ON ps.rowid = s.parent';
  322. if (is_object($user) && empty($user->rights->societe->client->voir)) {
  323. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
  324. }
  325. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
  326. $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'facture_fourn as f';
  327. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
  328. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_extrafields as extra ON f.rowid = extra.fk_object';
  329. $this->export_sql_end[$r] .= ' , '.MAIN_DB_PREFIX.'facture_fourn_det as fd';
  330. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_det_extrafields as extraline ON fd.rowid = extraline.fk_object';
  331. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
  332. $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture_fourn';
  333. $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('supplier_invoice').')';
  334. if (is_object($user) && empty($user->rights->societe->client->voir)) {
  335. $this->export_sql_end[$r] .= ' AND sc.fk_user = '.((int) $user->id);
  336. }
  337. $r++;
  338. $this->export_code[$r] = $this->rights_class.'_'.$r;
  339. $this->export_label[$r] = 'Factures fournisseurs et reglements';
  340. $this->export_icon[$r] = 'invoice';
  341. $this->export_permission[$r] = array(array("fournisseur", "facture", "export"));
  342. $this->export_fields_array[$r] = array(
  343. 's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode', 's.phone'=>'Phone',
  344. 's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.idprof5'=>'ProfId5', 's.idprof6'=>'ProfId6',
  345. 's.code_compta'=>'CustomerAccountancyCode', 's.code_compta_fournisseur'=>'SupplierAccountancyCode', 's.tva_intra'=>'VATIntra',
  346. 'f.rowid'=>"InvoiceId", 'f.ref'=>"InvoiceRef", 'f.ref_supplier'=>"RefSupplier", 'f.datec'=>"InvoiceDateCreation",
  347. 'f.datef'=>"DateInvoice", 'f.total_ht'=>"TotalHT", 'f.total_ttc'=>"TotalTTC", 'f.total_tva'=>"TotalVAT", 'f.paye'=>"InvoicePaid",
  348. 'f.fk_statut'=>'InvoiceStatus', 'f.note_public'=>"InvoiceNote", 'p.rowid'=>'PaymentId', 'pf.amount'=>'AmountPayment',
  349. 'p.datep'=>'DatePayment', 'p.num_paiement'=>'PaymentNumber', 'p.fk_bank'=>'IdTransaction', 'project.rowid'=>'ProjectId', 'project.ref'=>'ProjectRef', 'project.title'=>'ProjectLabel'
  350. );
  351. if (!empty($conf->multicurrency->enabled)) {
  352. $this->export_fields_array[$r]['f.multicurrency_code'] = 'Currency';
  353. $this->export_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
  354. $this->export_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
  355. $this->export_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
  356. $this->export_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
  357. }
  358. //$this->export_TypeFields_array[$r]=array(
  359. // 's.rowid'=>"Numeric",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text','s.phone'=>'Text',
  360. // 's.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','s.tva_intra'=>'Text','f.ref'=>"Text",'f.datec'=>"Date",'f.datef'=>"Date",
  361. // 'f.total_ht'=>"Numeric",'f.total_ttc'=>"Numeric",'f.total_tva'=>"Numeric",'f.paye'=>"Boolean",'f.fk_statut'=>'Status','f.note_public'=>"Text",
  362. // 'pf.amount'=>'Numeric','p.datep'=>'Date','p.num_paiement'=>'Numeric'
  363. //);
  364. $this->export_TypeFields_array[$r] = array(
  365. 's.nom'=>'Text', 's.address'=>'Text', 's.zip'=>'Text', 's.town'=>'Text', 'c.code'=>'Text', 's.phone'=>'Text', 's.siren'=>'Text', 's.siret'=>'Text', 's.ape'=>'Text',
  366. 's.idprof4'=>'Text', 's.code_compta'=>'Text', 's.code_compta_fournisseur'=>'Text', 's.tva_intra'=>'Text', 'f.ref'=>"Text", 'f.ref_supplier'=>"Text", 'f.datec'=>"Date", 'f.datef'=>"Date", 'f.total_ht'=>"Numeric",
  367. 'f.total_ttc'=>"Numeric", 'f.total_tva'=>"Numeric", 'f.paye'=>"Boolean", 'f.fk_statut'=>'Status', 'f.note_public'=>"Text", 'pf.amount'=>'Numeric',
  368. 'p.datep'=>'Date', 'p.num_paiement'=>'Numeric', 'p.fk_bank'=>'Numeric', 'project.ref'=>'Text', 'project.title'=>'Text'
  369. );
  370. $this->export_entities_array[$r] = array(
  371. 's.rowid'=>"company", 's.nom'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company', 'c.code'=>'company', 's.phone'=>'company',
  372. 's.siren'=>'company', 's.siret'=>'company', 's.ape'=>'company', 's.idprof4'=>'company', 's.idprof5'=>'company', 's.idprof6'=>'company',
  373. 's.code_compta'=>'company', 's.code_compta_fournisseur'=>'company', 's.tva_intra'=>'company',
  374. 'f.rowid'=>"invoice", 'f.ref'=>"invoice", 'f.ref_supplier'=>"invoice", 'f.datec'=>"invoice", 'f.datef'=>"invoice", 'f.total_ht'=>"invoice",
  375. 'f.total_ttc'=>"invoice", 'f.total_tva'=>"invoice", 'f.paye'=>"invoice", 'f.fk_statut'=>'invoice', 'f.note_public'=>"invoice", 'p.rowid'=>'payment', 'pf.amount'=>'payment',
  376. 'p.datep'=>'payment', 'p.num_paiement'=>'payment', 'p.fk_bank'=>'account', 'project.rowid'=>'project', 'project.ref'=>'project', 'project.title'=>'project');
  377. $this->export_dependencies_array[$r] = array('payment'=>'p.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
  378. // Add extra fields object
  379. $keyforselect = 'facture_fourn';
  380. $keyforelement = 'invoice';
  381. $keyforaliasextra = 'extra';
  382. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  383. // End add extra fields object
  384. $this->export_sql_start[$r] = 'SELECT DISTINCT ';
  385. $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
  386. if (is_object($user) && empty($user->rights->societe->client->voir)) {
  387. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
  388. }
  389. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
  390. $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'facture_fourn as f';
  391. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
  392. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_extrafields as extra ON f.rowid = extra.fk_object';
  393. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid';
  394. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn as p ON pf.fk_paiementfourn = p.rowid';
  395. $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid';
  396. $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('supplier_invoice').')';
  397. if (is_object($user) && empty($user->rights->societe->client->voir)) {
  398. $this->export_sql_end[$r] .= ' AND sc.fk_user = '.((int) $user->id);
  399. }
  400. // Order
  401. $r++;
  402. $this->export_code[$r] = $this->rights_class.'_'.$r;
  403. $this->export_label[$r] = 'Purchase Orders and lines of purchase orders';
  404. $this->export_icon[$r] = 'order';
  405. $this->export_permission[$r] = array(array("fournisseur", "commande", "export"));
  406. $this->export_fields_array[$r] = array(
  407. 's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 'ps.nom'=>'ParentCompany', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode', 's.phone'=>'Phone',
  408. 's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.idprof5'=>'ProfId5', 's.idprof6'=>'ProfId6', 's.tva_intra'=>'VATIntra',
  409. 'f.rowid'=>"OrderId", 'f.ref'=>"Ref", 'f.ref_supplier'=>"RefSupplier", 'f.date_creation'=>"DateCreation", 'f.date_commande'=>"OrderDate", 'f.date_livraison'=>"DateDeliveryPlanned",
  410. 'f.total_ht'=>"TotalHT", 'f.total_ttc'=>"TotalTTC", 'f.total_tva'=>"TotalVAT", 'f.fk_statut'=>'Status', 'f.date_valid'=>'DateValidation', 'f.date_approve'=>'DateApprove', 'f.date_approve2'=>'DateApprove2',
  411. 'f.note_public'=>"NotePublic", 'f.note_private'=>"NotePrivate", 'uv.login'=>'UserValidation', 'ua1.login'=>'ApprovedBy', 'ua2.login'=>'ApprovedBy2', 'fd.rowid'=>'LineId', 'fd.description'=>"LineDescription",
  412. 'fd.tva_tx'=>"LineVATRate", 'fd.qty'=>"LineQty", 'fd.remise_percent'=>"Discount", 'fd.total_ht'=>"LineTotalHT", 'fd.total_ttc'=>"LineTotalTTC",
  413. 'fd.total_tva'=>"LineTotalVAT", 'fd.date_start'=>"DateStart", 'fd.date_end'=>"DateEnd", 'fd.special_code'=>'SpecialCode',
  414. 'fd.product_type'=>'TypeOfLineServiceOrProduct', 'fd.ref'=>'RefSupplier', 'fd.fk_product'=>'ProductId',
  415. // Added by MMI Mathieu Moulin iProspective : add BarCodeValue
  416. 'p.barcode'=>'BarcodeValue',
  417. 'p.ref'=>'ProductRef', 'p.label'=>'ProductLabel', 'project.rowid'=>'ProjectId', 'project.ref'=>'ProjectRef', 'project.title'=>'ProjectLabel'
  418. );
  419. if (!empty($conf->multicurrency->enabled)) {
  420. $this->export_fields_array[$r]['f.multicurrency_code'] = 'Currency';
  421. $this->export_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
  422. $this->export_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
  423. $this->export_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
  424. $this->export_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
  425. }
  426. if (empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED)) {
  427. unset($this->export_fields_array['f.date_approve2']);
  428. unset($this->export_fields_array['ua2.login']);
  429. }
  430. $this->export_TypeFields_array[$r] = array(
  431. 's.rowid'=>"company", 's.nom'=>'Text', 'ps.nom'=>'Text', 's.address'=>'Text', 's.cp'=>'Text', 's.ville'=>'Text', 'c.code'=>'Text', 's.tel'=>'Text', 's.siren'=>'Text',
  432. 's.siret'=>'Text', 's.ape'=>'Text', 's.idprof4'=>'Text', 's.idprof5'=>'Text', 's.idprof6'=>'Text', 's.tva_intra'=>'Text', 'f.ref'=>"Text", 'f.ref_supplier'=>"Text",
  433. 'f.date_creation'=>"Date", 'f.date_commande'=>"Date", 'f.date_livraison'=>"Date", 'f.total_ht'=>"Numeric", 'f.total_ttc'=>"Numeric", 'f.total_tva'=>"Numeric",
  434. 'f.fk_statut'=>'Status', 'f.date_valid'=>'Date', 'f.date_approve'=>'Date', 'f.date_approve2'=>'Date', 'f.note_public'=>"Text", 'f.note_private'=>"Text", 'fd.description'=>"Text",
  435. 'fd.tva_tx'=>"Numeric", 'fd.qty'=>"Numeric", 'fd.remise_percent'=>"Numeric", 'fd.total_ht'=>"Numeric", 'fd.total_ttc'=>"Numeric", 'fd.total_tva'=>"Numeric",
  436. 'fd.date_start'=>"Date", 'fd.date_end'=>"Date", 'fd.special_code'=>"Numeric",
  437. // Added by MMI Mathieu Moulin iProspective : add BarCodeValue
  438. 'p.barcode'=>'Text',
  439. 'fd.product_type'=>'Numeric', 'fd.ref'=>'Text', 'fd.fk_product'=>'List:product:label', 'p.ref'=>'Text', 'p.label'=>'Text', 'project.ref'=>'Text', 'project.title'=>'Text'
  440. );
  441. $this->export_entities_array[$r] = array(
  442. 's.rowid'=>"company", 's.nom'=>'company', 'ps.nom'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company', 'c.code'=>'company', 's.phone'=>'company', 's.siren'=>'company',
  443. 's.siret'=>'company', 's.ape'=>'company', 's.idprof4'=>'company', 's.idprof5'=>'company', 's.idprof6'=>'company', 's.tva_intra'=>'company', 'uv.login'=>'user', 'ua1.login'=>'user',
  444. 'ua2.login'=>'user', 'fd.rowid'=>'order_line', 'fd.description'=>"order_line", 'fd.tva_tx'=>"order_line", 'fd.qty'=>"order_line", 'fd.remise_percent'=>"order_line",
  445. 'fd.total_ht'=>"order_line", 'fd.total_ttc'=>"order_line", 'fd.total_tva'=>"order_line", 'fd.date_start'=>"order_line", 'fd.date_end'=>"order_line", 'fd.special_code'=>"order_line",
  446. 'fd.product_type'=>'order_line', 'fd.ref'=>'order_line', 'fd.fk_product'=>'product',
  447. // Added by MMI Mathieu Moulin iProspective : add BarCodeValue
  448. 'p.barcode'=>'product',
  449. 'p.ref'=>'product', 'p.label'=>'product', 'project.rowid'=>'project', 'project.ref'=>'project', 'project.title'=>'project'
  450. );
  451. $this->export_dependencies_array[$r] = array('order_line'=>'fd.rowid', 'product'=>'fd.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
  452. // Add extra fields object
  453. $keyforselect = 'commande_fournisseur';
  454. $keyforelement = 'order';
  455. $keyforaliasextra = 'extra';
  456. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  457. // End add extra fields object
  458. // Add extra fields line
  459. $keyforselect = 'commande_fournisseurdet';
  460. $keyforelement = 'order_line';
  461. $keyforaliasextra = 'extraline';
  462. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  463. // End add extra fields line
  464. $this->export_sql_start[$r] = 'SELECT DISTINCT ';
  465. $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
  466. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as ps ON ps.rowid = s.parent';
  467. if (is_object($user) && empty($user->rights->societe->client->voir)) {
  468. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
  469. }
  470. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
  471. $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'commande_fournisseur as f';
  472. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
  473. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON uv.rowid = f.fk_user_valid';
  474. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as ua1 ON ua1.rowid = f.fk_user_approve';
  475. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as ua2 ON ua2.rowid = f.fk_user_approve2';
  476. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseur_extrafields as extra ON f.rowid = extra.fk_object,';
  477. $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'commande_fournisseurdet as fd';
  478. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseurdet_extrafields as extraline ON fd.rowid = extraline.fk_object';
  479. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
  480. $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_commande';
  481. $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('supplier_order').')';
  482. if (is_object($user) && empty($user->rights->societe->client->voir)) {
  483. $this->export_sql_end[$r] .= ' AND sc.fk_user = '.((int) $user->id);
  484. }
  485. //Import Supplier Invoice
  486. //--------
  487. $r = 0;
  488. $r++;
  489. $this->import_code[$r] = $this->rights_class.'_'.$r;
  490. $this->import_label[$r] = "SupplierInvoices"; // Translation key
  491. $this->import_icon[$r] = $this->picto;
  492. $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
  493. $this->import_tables_array[$r] = array('f' => MAIN_DB_PREFIX.'facture_fourn', 'extra' => MAIN_DB_PREFIX.'facture_fourn_extrafields');
  494. $this->import_tables_creator_array[$r] = array('f' => 'fk_user_author'); // Fields to store import user id
  495. $this->import_fields_array[$r] = array(
  496. 'f.ref' => 'InvoiceRef*',
  497. 'f.ref_supplier' => 'RefSupplier',
  498. 'f.type' => 'Type*',
  499. 'f.fk_soc' => 'Supplier/Vendor*',
  500. 'f.datec' => 'InvoiceDateCreation',
  501. 'f.datef' => 'DateInvoice',
  502. 'f.date_lim_reglement' => 'DateMaxPayment',
  503. 'f.total_ht' => 'TotalHT',
  504. 'f.total_ttc' => 'TotalTTC',
  505. 'f.total_tva' => 'TotalVAT',
  506. 'f.paye' => 'InvoicePaid',
  507. 'f.fk_statut' => 'InvoiceStatus',
  508. 'f.fk_user_modif' => 'Modifier Id',
  509. 'f.fk_user_valid' => 'Validator Id',
  510. 'f.fk_facture_source' => 'Invoice Source Id',
  511. 'f.fk_projet' => 'Project Id',
  512. 'f.fk_account' => 'Bank Account*',
  513. 'f.note_public' => 'InvoiceNote',
  514. 'f.note_private' => 'NotePrivate',
  515. 'f.fk_cond_reglement' => 'Payment Condition',
  516. 'f.fk_mode_reglement' => 'Payment Mode',
  517. 'f.model_pdf' => 'Model',
  518. 'f.date_valid' => 'Validation Date'
  519. );
  520. if (!empty($conf->multicurrency->enabled)) {
  521. $this->import_fields_array[$r]['f.multicurrency_code'] = 'Currency';
  522. $this->import_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
  523. $this->import_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
  524. $this->import_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
  525. $this->import_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
  526. }
  527. // Add extra fields
  528. $import_extrafield_sample = array();
  529. $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'facture_fourn' AND entity IN (0, ".$conf->entity.")";
  530. $resql = $this->db->query($sql);
  531. if ($resql) {
  532. while ($obj = $this->db->fetch_object($resql)) {
  533. $fieldname = 'extra.'.$obj->name;
  534. $fieldlabel = ucfirst($obj->label);
  535. $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
  536. $import_extrafield_sample[$fieldname] = $fieldlabel;
  537. }
  538. }
  539. // End add extra fields
  540. $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'facture_fourn');
  541. $this->import_regex_array[$r] = array('f.ref' => '(SI\d{4}-\d{4}|PROV.{1,32}$)', 'f.multicurrency_code' => 'code@'.MAIN_DB_PREFIX.'multicurrency');
  542. $import_sample = array(
  543. 'f.ref' => '(PROV001)',
  544. 'f.ref_supplier' => 'Supplier1',
  545. 'f.type' => '0',
  546. 'f.fk_soc' => 'Vendor1',
  547. 'f.datec' => '2021-01-01',
  548. 'f.datef' => '',
  549. 'f.date_lim_reglement' => '2021-01-30',
  550. 'f.total_ht' => '1000',
  551. 'f.total_ttc' => '1000',
  552. 'f.total_tva' => '0',
  553. 'f.paye' => '0',
  554. 'f.fk_statut' => '0',
  555. 'f.fk_user_modif' => '',
  556. 'f.fk_user_valid' => '',
  557. 'f.fk_facture_source' => '',
  558. 'f.fk_projet' => '',
  559. 'f.fk_account' => 'BANK1',
  560. 'f.note_public' => 'Note: ',
  561. 'f.note_private' => '',
  562. 'f.fk_cond_reglement' => '1',
  563. 'f.fk_mode_reglement' => '2',
  564. 'f.model_pdf' => 'crab',
  565. 'f.date_valid' => '',
  566. 'f.multicurrency_code' => 'USD',
  567. 'f.multicurrency_tx' => '1',
  568. 'f.multicurrency_total_ht' => '1000',
  569. 'f.multicurrency_total_tva' => '0',
  570. 'f.multicurrency_total_ttc' => '1000'
  571. );
  572. $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
  573. $this->import_updatekeys_array[$r] = array('f.ref' => 'Ref');
  574. $this->import_convertvalue_array[$r] = array(
  575. 'f.ref' => array(
  576. 'rule'=>'getrefifauto',
  577. 'class'=>(empty($conf->global->INVOICE_SUPPLIER_ADDON_NUMBER) ? 'mod_facture_fournisseur_cactus' : $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER),
  578. 'path'=>"/core/modules/supplier_invoice/".(empty($conf->global->INVOICE_SUPPLIER_ADDON_NUMBER) ? 'mod_facture_fournisseur_cactus' : $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER).'.php',
  579. 'classobject'=>'FactureFournisseur',
  580. 'pathobject'=>'/fourn/class/fournisseur.facture.class.php',
  581. ),
  582. 'f.fk_soc' => array('rule' => 'fetchidfromref', 'file' => '/societe/class/societe.class.php', 'class' => 'Societe', 'method' => 'fetch', 'element' => 'ThirdParty'),
  583. 'f.fk_account' => array('rule' => 'fetchidfromref', 'file' => '/compta/bank/class/account.class.php', 'class' => 'Account', 'method' => 'fetch', 'element' => 'bank_account'),
  584. );
  585. //Import Supplier Invoice Lines
  586. $r++;
  587. $this->import_code[$r] = $this->rights_class.'_'.$r;
  588. $this->import_label[$r] = "SupplierInvoiceLines"; // Translation key
  589. $this->import_icon[$r] = $this->picto;
  590. $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
  591. $this->import_tables_array[$r] = array('fd' => MAIN_DB_PREFIX.'facture_fourn_det', 'extra' => MAIN_DB_PREFIX.'facture_fourn_det_extrafields');
  592. $this->import_fields_array[$r] = array(
  593. 'fd.fk_facture_fourn' => 'InvoiceRef*',
  594. 'fd.fk_parent_line' => 'ParentLine',
  595. 'fd.fk_product' => 'IdProduct',
  596. 'fd.description' => 'LineDescription',
  597. 'fd.pu_ht' => 'PriceUHT',
  598. 'fd.pu_ttc' => 'PriceUTTC',
  599. 'fd.qty' => 'LineQty',
  600. 'fd.remise_percent' => 'Reduc.',
  601. 'fd.vat_src_code' => 'Vat Source Code',
  602. 'fd.product_type' => 'TypeOfLineServiceOrProduct',
  603. 'fd.tva_tx' => 'LineVATRate',
  604. 'fd.total_ht' => 'LineTotalHT',
  605. 'fd.tva' => 'LineTotalVAT',
  606. 'fd.total_ttc' => 'LineTotalTTC',
  607. 'fd.date_start' => 'Start Date',
  608. 'fd.date_end' => 'End Date',
  609. 'fd.fk_unit' => 'Unit'
  610. );
  611. if (!empty($conf->multicurrency->enabled)) {
  612. $this->import_fields_array[$r]['fd.multicurrency_code'] = 'Currency';
  613. $this->import_fields_array[$r]['fd.multicurrency_subprice'] = 'CurrencyRate';
  614. $this->import_fields_array[$r]['fd.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
  615. $this->import_fields_array[$r]['fd.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
  616. $this->import_fields_array[$r]['fd.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
  617. }
  618. // Add extra fields
  619. $import_extrafield_sample = array();
  620. $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'facture_fourn_det' AND entity IN (0, ".$conf->entity.")";
  621. $resql = $this->db->query($sql);
  622. if ($resql) {
  623. while ($obj = $this->db->fetch_object($resql)) {
  624. $fieldname = 'extra.'.$obj->name;
  625. $fieldlabel = ucfirst($obj->label);
  626. $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
  627. $import_extrafield_sample[$fieldname] = $fieldlabel;
  628. }
  629. }
  630. // End add extra fields
  631. $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'facture_fourn_det');
  632. $this->import_regex_array[$r] = array('fd.product_type' => '[0|1]$', 'fd.fk_product' => 'rowid@'.MAIN_DB_PREFIX.'product', 'fd.multicurrency_code' => 'code@'.MAIN_DB_PREFIX.'multicurrency');
  633. $import_sample = array(
  634. 'fd.fk_facture_fourn' => '(PROV001)',
  635. 'fd.fk_parent_line' => '',
  636. 'fd.fk_product' => '',
  637. 'fd.description' => 'Test Product',
  638. 'fd.pu_ht' => '50000',
  639. 'fd.pu_ttc' => '50000',
  640. 'fd.qty' => '1',
  641. 'fd.remise_percent' => '0',
  642. 'fd.vat_src_code' => '',
  643. 'fd.product_type' => '0',
  644. 'fd.tva_tx' => '0',
  645. 'fd.total_ht' => '50000',
  646. 'fd.tva' => '0',
  647. 'fd.total_ttc' => '50000',
  648. 'fd.date_start' => '',
  649. 'fd.date_end' => '',
  650. 'fd.fk_unit' => '',
  651. 'fd.multicurrency_code' => 'USD',
  652. 'fd.multicurrency_tx' => '0',
  653. 'fd.multicurrency_total_ht' => '50000',
  654. 'fd.multicurrency_total_tva' => '0',
  655. 'fd.multicurrency_total_ttc' => '50000'
  656. );
  657. $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
  658. $this->import_updatekeys_array[$r] = array('fd.rowid' => 'Row Id', 'fd.fk_facture_fourn' => 'Invoice Id', 'fd.fk_product' => 'Product Id');
  659. $this->import_convertvalue_array[$r] = array(
  660. 'fd.fk_facture_fourn' => array('rule' => 'fetchidfromref', 'file' => '/fourn/class/fournisseur.facture.class.php', 'class' => 'FactureFournisseur', 'method' => 'fetch'),
  661. );
  662. //Import Purchase Orders
  663. $r++;
  664. $this->import_code[$r] = 'commande_fournisseur_'.$r;
  665. $this->import_label[$r] = 'SuppliersOrders';
  666. $this->import_icon[$r] = $this->picto;
  667. $this->import_entities_array[$r] = array();
  668. $this->import_tables_array[$r] = array('c' => MAIN_DB_PREFIX.'commande_fournisseur', 'extra' => MAIN_DB_PREFIX.'commande_fournisseur_extrafields');
  669. $this->import_tables_creator_array[$r] = array('c' => 'fk_user_author'); // Fields to store import user id
  670. $this->import_fields_array[$r] = array(
  671. 'c.ref' => 'Ref*',
  672. 'c.ref_supplier' => 'RefSupplier',
  673. 'c.fk_soc' => 'ThirdPartyName*',
  674. 'c.fk_projet' => 'ProjectId',
  675. 'c.date_creation' => 'DateCreation',
  676. 'c.date_valid' => 'DateValid',
  677. 'c.date_approve' => 'DateApprove',
  678. 'c.date_commande' => 'DateOrder',
  679. 'c.fk_user_modif' => 'ModifiedById',
  680. 'c.fk_user_valid' => 'ValidatedById',
  681. 'c.fk_user_approve' => 'ApprovedById',
  682. 'c.source' => 'Source',
  683. 'c.fk_statut' => 'Status*',
  684. 'c.billed' => 'Billed(0/1)',
  685. 'c.total_tva' => 'TotalTVA',
  686. 'c.total_ht' => 'TotalHT',
  687. 'c.total_ttc' => 'TotalTTC',
  688. 'c.note_private' => 'NotePrivate',
  689. 'c.note_public' => 'Note',
  690. 'c.date_livraison' => 'DeliveryDate',
  691. 'c.fk_cond_reglement' => 'Payment Condition',
  692. 'c.fk_mode_reglement' => 'Payment Mode',
  693. 'c.model_pdf' => 'Model'
  694. );
  695. if (!empty($conf->multicurrency->enabled)) {
  696. $this->import_fields_array[$r]['c.multicurrency_code'] = 'Currency';
  697. $this->import_fields_array[$r]['c.multicurrency_tx'] = 'CurrencyRate';
  698. $this->import_fields_array[$r]['c.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
  699. $this->import_fields_array[$r]['c.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
  700. $this->import_fields_array[$r]['c.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
  701. }
  702. // Add extra fields
  703. $import_extrafield_sample = array();
  704. $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'commande_fournisseur' AND entity IN (0, ".$conf->entity.")";
  705. $resql = $this->db->query($sql);
  706. if ($resql) {
  707. while ($obj = $this->db->fetch_object($resql)) {
  708. $fieldname = 'extra.'.$obj->name;
  709. $fieldlabel = ucfirst($obj->label);
  710. $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
  711. $import_extrafield_sample[$fieldname] = $fieldlabel;
  712. }
  713. }
  714. // End add extra fields
  715. $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'commande_fournisseur');
  716. $this->import_regex_array[$r] = array(
  717. 'c.multicurrency_code' => 'code@'.MAIN_DB_PREFIX.'multicurrency'
  718. );
  719. $this->import_updatekeys_array[$r] = array('c.ref' => 'Ref');
  720. $this->import_convertvalue_array[$r] = array(
  721. 'c.ref' => array(
  722. 'rule'=>'getrefifauto',
  723. 'class'=>(empty($conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER) ? 'mod_commande_fournisseur_muguet' : $conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER),
  724. 'path'=>"/core/modules/supplier_order/".(empty($conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER) ? 'mod_commande_fournisseur_muguet' : $conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER).'.php',
  725. 'classobject'=>'CommandeFournisseur',
  726. 'pathobject'=>'/fourn/class/fournisseur.commande.class.php',
  727. ),
  728. 'c.fk_soc' => array(
  729. 'rule' => 'fetchidfromref',
  730. 'file' => '/societe/class/societe.class.php',
  731. 'class' => 'Societe',
  732. 'method' => 'fetch',
  733. 'element' => 'ThirdParty'
  734. ),
  735. 'c.fk_mode_reglement' => array(
  736. 'rule' => 'fetchidfromcodeorlabel',
  737. 'file' => '/compta/paiement/class/cpaiement.class.php',
  738. 'class' => 'Cpaiement',
  739. 'method' => 'fetch',
  740. 'element' => 'cpayment'
  741. ),
  742. 'c.source' => array('rule' => 'zeroifnull'),
  743. );
  744. // Import PO Lines
  745. $r++;
  746. $this->import_code[$r] = 'commande_fournisseurdet_'.$r;
  747. $this->import_label[$r] = 'PurchaseOrderLines';
  748. $this->import_icon[$r] = $this->picto;
  749. $this->import_entities_array[$r] = array();
  750. $this->import_tables_array[$r] = array('cd' => MAIN_DB_PREFIX.'commande_fournisseurdet', 'extra' => MAIN_DB_PREFIX.'commande_fournisseurdet_extrafields');
  751. $this->import_fields_array[$r] = array(
  752. 'cd.fk_commande' => 'PurchaseOrder*',
  753. 'cd.fk_parent_line' => 'ParentLine',
  754. 'cd.fk_product' => 'IdProduct',
  755. 'cd.description' => 'LineDescription',
  756. 'cd.tva_tx' => 'LineVATRate',
  757. 'cd.qty' => 'LineQty',
  758. 'cd.remise_percent' => 'Reduc. Percent',
  759. 'cd.subprice' => 'Sub Price',
  760. 'cd.total_ht' => 'LineTotalHT',
  761. 'cd.total_tva' => 'LineTotalVAT',
  762. 'cd.total_ttc' => 'LineTotalTTC',
  763. 'cd.product_type' => 'TypeOfLineServiceOrProduct',
  764. 'cd.date_start' => 'Start Date',
  765. 'cd.date_end' => 'End Date',
  766. 'cd.info_bits' => 'InfoBits',
  767. 'cd.special_code' => 'Special Code',
  768. 'cd.rang' => 'LinePosition',
  769. 'cd.fk_unit' => 'Unit'
  770. );
  771. if (!empty($conf->multicurrency->enabled)) {
  772. $this->import_fields_array[$r]['cd.multicurrency_code'] = 'Currency';
  773. $this->import_fields_array[$r]['cd.multicurrency_subprice'] = 'CurrencyRate';
  774. $this->import_fields_array[$r]['cd.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
  775. $this->import_fields_array[$r]['cd.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
  776. $this->import_fields_array[$r]['cd.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
  777. }
  778. // Add extra fields
  779. $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'commande_fournisseurdet' AND entity IN (0, ".$conf->entity.")";
  780. $resql = $this->db->query($sql);
  781. if ($resql) {
  782. while ($obj = $this->db->fetch_object($resql)) {
  783. $fieldname = 'extra.'.$obj->name;
  784. $fieldlabel = ucfirst($obj->label);
  785. $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
  786. }
  787. }
  788. // End add extra fields
  789. $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'commande_fournisseurdet');
  790. $this->import_regex_array[$r] = array(
  791. 'cd.product_type' => '[0|1]$',
  792. 'cd.fk_product' => 'rowid@'.MAIN_DB_PREFIX.'product',
  793. 'cd.multicurrency_code' => 'code@'.MAIN_DB_PREFIX.'multicurrency'
  794. );
  795. $this->import_updatekeys_array[$r] = array('cd.fk_commande' => 'Purchase Order Id');
  796. $this->import_convertvalue_array[$r] = array(
  797. 'cd.fk_commande' => array(
  798. 'rule' => 'fetchidfromref',
  799. 'file' => '/fourn/class/fournisseur.commande.class.php',
  800. 'class' => 'CommandeFournisseur',
  801. 'method' => 'fetch',
  802. 'element' => 'order_supplier'
  803. ),
  804. 'cd.info_bits' => array('rule' => 'zeroifnull'),
  805. 'cd.special_code' => array('rule' => 'zeroifnull'),
  806. );
  807. }
  808. /**
  809. * Function called when module is enabled.
  810. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  811. * It also creates data directories
  812. *
  813. * @param string $options Options when enabling module ('', 'noboxes')
  814. * @return int 1 if OK, 0 if KO
  815. */
  816. public function init($options = '')
  817. {
  818. global $conf, $langs;
  819. $this->remove($options);
  820. //ODT template
  821. $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/supplier_orders/template_supplier_order.odt';
  822. $dirodt = DOL_DATA_ROOT.'/doctemplates/supplier_orders';
  823. $dest = $dirodt.'/template_supplier_order.odt';
  824. if (file_exists($src) && !file_exists($dest)) {
  825. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  826. dol_mkdir($dirodt);
  827. $result = dol_copy($src, $dest, 0, 0);
  828. if ($result < 0) {
  829. $langs->load("errors");
  830. $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
  831. return 0;
  832. }
  833. }
  834. $sql = array(
  835. "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'order_supplier' AND entity = ".((int) $conf->entity),
  836. "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."', 'order_supplier', ".((int) $conf->entity).")",
  837. );
  838. return $this->_init($sql, $options);
  839. }
  840. }