modFournisseur.class.php 47 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939
  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, $langs, $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] = "cornas";
  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. // Add ability ODT for Supplier orders
  99. $this->const[$r][0] = "SUPPLIER_ORDER_ADDON_PDF_ODT_PATH";
  100. $this->const[$r][1] = "chaine";
  101. $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/supplier_orders";
  102. $this->const[$r][3] = '';
  103. $this->const[$r][4] = 0;
  104. $r++;
  105. // Add ability ODT for Supplier Invoices
  106. $this->const[$r][0] = "SUPPLIER_INVOICE_ADDON_PDF_ODT_PATH";
  107. $this->const[$r][1] = "chaine";
  108. $this->const[$r][2] = "";
  109. $this->const[$r][3] = "";
  110. $this->const[$r][4] = 0;
  111. $r++;
  112. // Boxes
  113. $this->boxes = array(
  114. 0=>array('file'=>'box_graph_invoices_supplier_permonth.php', 'enabledbydefaulton'=>'Home'),
  115. 1=>array('file'=>'box_graph_orders_supplier_permonth.php', 'enabledbydefaulton'=>'Home'),
  116. 2=>array('file'=>'box_fournisseurs.php', 'enabledbydefaulton'=>'Home'),
  117. 3=>array('file'=>'box_factures_fourn_imp.php', 'enabledbydefaulton'=>'Home'),
  118. 4=>array('file'=>'box_factures_fourn.php', 'enabledbydefaulton'=>'Home'),
  119. 5=>array('file'=>'box_supplier_orders.php', 'enabledbydefaulton'=>'Home'),
  120. 6=>array('file'=>'box_supplier_orders_awaiting_reception.php', 'enabledbydefaulton'=>'Home'),
  121. );
  122. $arraydate = dol_getdate(dol_now());
  123. $datestart = dol_mktime(23, 0, 0, $arraydate['mon'], $arraydate['mday'], $arraydate['year']);
  124. $this->cronjobs = array(
  125. 0 => array(
  126. 'label'=>'RecurringSupplierInvoicesJob',
  127. 'jobtype'=>'method',
  128. 'class'=>'fourn/class/fournisseur.facture-rec.class.php',
  129. 'objectname'=>'FactureFournisseurRec',
  130. 'method'=>'createRecurringInvoices',
  131. 'parameters'=>'',
  132. 'comment'=>'Generate recurring supplier invoices',
  133. 'frequency'=>1,
  134. 'unitfrequency'=>3600 * 24,
  135. 'priority'=>51,
  136. 'status'=>1,
  137. 'datestart'=>$datestart
  138. ));
  139. // Permissions
  140. $this->rights = array();
  141. $this->rights_class = 'fournisseur';
  142. $r = 0;
  143. $r++;
  144. $this->rights[$r][0] = 1181;
  145. $this->rights[$r][1] = 'Consulter les fournisseurs';
  146. $this->rights[$r][2] = 'r';
  147. $this->rights[$r][3] = 0;
  148. $this->rights[$r][4] = 'lire';
  149. $r++;
  150. $this->rights[$r][0] = 1182;
  151. $this->rights[$r][1] = 'Consulter les commandes fournisseur';
  152. $this->rights[$r][2] = 'r';
  153. $this->rights[$r][3] = 0;
  154. $this->rights[$r][4] = 'commande';
  155. $this->rights[$r][5] = 'lire';
  156. $r++;
  157. $this->rights[$r][0] = 1183;
  158. $this->rights[$r][1] = 'Creer une commande fournisseur';
  159. $this->rights[$r][2] = 'w';
  160. $this->rights[$r][3] = 0;
  161. $this->rights[$r][4] = 'commande';
  162. $this->rights[$r][5] = 'creer';
  163. $r++;
  164. $this->rights[$r][0] = 1184;
  165. $this->rights[$r][1] = 'Valider une commande fournisseur';
  166. $this->rights[$r][2] = 'w';
  167. $this->rights[$r][3] = 0;
  168. $this->rights[$r][4] = 'supplier_order_advance';
  169. $this->rights[$r][5] = 'validate';
  170. $r++;
  171. $this->rights[$r][0] = 1185;
  172. $this->rights[$r][1] = 'Approuver une commande fournisseur';
  173. $this->rights[$r][2] = 'w';
  174. $this->rights[$r][3] = 0;
  175. $this->rights[$r][4] = 'commande';
  176. $this->rights[$r][5] = 'approuver';
  177. $r++;
  178. $this->rights[$r][0] = 1186;
  179. $this->rights[$r][1] = 'Commander une commande fournisseur';
  180. $this->rights[$r][2] = 'w';
  181. $this->rights[$r][3] = 0;
  182. $this->rights[$r][4] = 'commande';
  183. $this->rights[$r][5] = 'commander';
  184. $r++;
  185. $this->rights[$r][0] = 1187;
  186. $this->rights[$r][1] = 'Receptionner une commande fournisseur';
  187. $this->rights[$r][2] = 'd';
  188. $this->rights[$r][3] = 0;
  189. $this->rights[$r][4] = 'commande';
  190. $this->rights[$r][5] = 'receptionner';
  191. $r++;
  192. $this->rights[$r][0] = 1189;
  193. $this->rights[$r][1] = 'Check/Uncheck a supplier order reception';
  194. $this->rights[$r][2] = 'w';
  195. $this->rights[$r][3] = 0;
  196. $this->rights[$r][4] = 'commande_advance';
  197. $this->rights[$r][5] = 'check';
  198. $r++;
  199. $this->rights[$r][0] = 1188;
  200. $this->rights[$r][1] = 'Supprimer une commande fournisseur';
  201. $this->rights[$r][2] = 'd';
  202. $this->rights[$r][3] = 0;
  203. $this->rights[$r][4] = 'commande';
  204. $this->rights[$r][5] = 'supprimer';
  205. if (!empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED)) {
  206. $r++;
  207. $this->rights[$r][0] = 1190;
  208. $this->rights[$r][1] = 'Approve supplier order (second level)'; // $langs->trans("Permission1190");
  209. $this->rights[$r][2] = 'w';
  210. $this->rights[$r][3] = 0;
  211. $this->rights[$r][4] = 'commande';
  212. $this->rights[$r][5] = 'approve2';
  213. }
  214. $r++;
  215. $this->rights[$r][0] = 1191;
  216. $this->rights[$r][1] = 'Exporter les commande fournisseurs, attributs';
  217. $this->rights[$r][2] = 'r';
  218. $this->rights[$r][3] = 0;
  219. $this->rights[$r][4] = 'commande';
  220. $this->rights[$r][5] = 'export';
  221. $r++;
  222. $this->rights[$r][0] = 1231;
  223. $this->rights[$r][1] = 'Consulter les factures fournisseur';
  224. $this->rights[$r][2] = 'r';
  225. $this->rights[$r][3] = 0;
  226. $this->rights[$r][4] = 'facture';
  227. $this->rights[$r][5] = 'lire';
  228. $r++;
  229. $this->rights[$r][0] = 1232;
  230. $this->rights[$r][1] = 'Creer une facture fournisseur';
  231. $this->rights[$r][2] = 'w';
  232. $this->rights[$r][3] = 0;
  233. $this->rights[$r][4] = 'facture';
  234. $this->rights[$r][5] = 'creer';
  235. $r++;
  236. $this->rights[$r][0] = 1233;
  237. $this->rights[$r][1] = 'Valider une facture fournisseur';
  238. $this->rights[$r][2] = 'w';
  239. $this->rights[$r][3] = 0;
  240. $this->rights[$r][4] = 'supplier_invoice_advance';
  241. $this->rights[$r][5] = 'validate';
  242. $r++;
  243. $this->rights[$r][0] = 1234;
  244. $this->rights[$r][1] = 'Supprimer une facture fournisseur';
  245. $this->rights[$r][2] = 'd';
  246. $this->rights[$r][3] = 0;
  247. $this->rights[$r][4] = 'facture';
  248. $this->rights[$r][5] = 'supprimer';
  249. $r++;
  250. $this->rights[$r][0] = 1235;
  251. $this->rights[$r][1] = 'Envoyer les factures par mail';
  252. $this->rights[$r][2] = 'a';
  253. $this->rights[$r][3] = 0;
  254. $this->rights[$r][4] = 'supplier_invoice_advance';
  255. $this->rights[$r][5] = 'send';
  256. $r++;
  257. $this->rights[$r][0] = 1236;
  258. $this->rights[$r][1] = 'Exporter les factures fournisseurs, attributs et reglements';
  259. $this->rights[$r][2] = 'r';
  260. $this->rights[$r][3] = 0;
  261. $this->rights[$r][4] = 'facture';
  262. $this->rights[$r][5] = 'export';
  263. // Menus
  264. //-------
  265. $this->menu = 1; // This module add menu entries. They are coded into menu manager.
  266. // Exports
  267. //--------
  268. $r = 0;
  269. $langs->loadLangs(array("suppliers", "multicurrency"));
  270. $r++;
  271. $this->export_code[$r] = $this->rights_class.'_'.$r;
  272. $this->export_label[$r] = 'Vendor invoices and lines of invoices';
  273. $this->export_icon[$r] = 'invoice';
  274. $this->export_permission[$r] = array(array("fournisseur", "facture", "export"));
  275. $this->export_fields_array[$r] = array(
  276. 's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 'ps.nom'=>'ParentCompany', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode', 's.phone'=>'Phone',
  277. 's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.idprof5'=>'ProfId5', 's.idprof6'=>'ProfId6',
  278. 's.code_compta'=>'CustomerAccountancyCode', 's.code_compta_fournisseur'=>'SupplierAccountancyCode', 's.tva_intra'=>'VATIntra',
  279. 'f.rowid'=>"InvoiceId", 'f.ref'=>"InvoiceRef", 'f.ref_supplier'=>"RefSupplier", 'f.datec'=>"InvoiceDateCreation", 'f.datef'=>"DateInvoice", 'f.date_lim_reglement'=>'DateMaxPayment',
  280. 'f.total_ht'=>"TotalHT", 'f.total_ttc'=>"TotalTTC", 'f.total_tva'=>"TotalVAT", 'f.paye'=>"InvoicePaid", 'f.fk_statut'=>'InvoiceStatus', 'f.note_public'=>"InvoiceNote",
  281. 'fd.rowid'=>'LineId', 'fd.description'=>"LineDescription", 'fd.tva_tx'=>"LineVATRate", 'fd.qty'=>"LineQty", 'fd.remise_percent'=>"Discount", 'fd.total_ht'=>"LineTotalHT",
  282. 'fd.total_ttc'=>"LineTotalTTC", 'fd.tva'=>"LineTotalVAT", 'fd.date_start'=>"DateStart", 'fd.date_end'=>"DateEnd", 'fd.special_code'=>'SpecialCode',
  283. 'fd.product_type'=>'TypeOfLineServiceOrProduct', 'fd.fk_product'=>'ProductId',
  284. 'p.ref'=>'ProductRef', 'p.label'=>'ProductLabel', 'p.accountancy_code_buy'=>'ProductAccountancyBuyCode', 'project.rowid'=>'ProjectId',
  285. 'project.ref'=>'ProjectRef', 'project.title'=>'ProjectLabel'
  286. );
  287. if (isModEnabled("multicurrency")) {
  288. $this->export_fields_array[$r]['f.multicurrency_code'] = 'Currency';
  289. $this->export_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
  290. $this->export_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
  291. $this->export_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
  292. $this->export_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
  293. }
  294. //$this->export_TypeFields_array[$r]=array(
  295. // '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',
  296. // '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",
  297. // '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",
  298. // 'fd.tva'=>"Numeric",'fd.product_type'=>'Numeric','fd.fk_product'=>'List:product:label','p.ref'=>'Text','p.label'=>'Text'
  299. //);
  300. $this->export_TypeFields_array[$r] = array(
  301. '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',
  302. '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',
  303. '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",
  304. '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",
  305. 'fd.product_type'=>'Numeric', 'fd.fk_product'=>'List:product:label',
  306. 'p.ref'=>'Text', 'p.label'=>'Text', 'project.ref'=>'Text', 'project.title'=>'Text'
  307. );
  308. $this->export_entities_array[$r] = array(
  309. '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',
  310. '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",
  311. '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",
  312. '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",
  313. '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",
  314. 'fd.product_type'=>'invoice_line', 'fd.fk_product'=>'product',
  315. 'p.ref'=>'product', 'p.label'=>'product', 'p.accountancy_code_buy'=>'product', 'project.rowid'=>'project', 'project.ref'=>'project', 'project.title'=>'project'
  316. );
  317. $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
  318. // Add extra fields object
  319. $keyforselect = 'facture_fourn';
  320. $keyforelement = 'invoice';
  321. $keyforaliasextra = 'extra';
  322. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  323. $keyforselect = 'facture_fourn_det';
  324. $keyforelement = 'invoice_line';
  325. $keyforaliasextra = 'extraline';
  326. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  327. // End add extra fields line
  328. $this->export_sql_start[$r] = 'SELECT DISTINCT ';
  329. $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
  330. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as ps ON ps.rowid = s.parent';
  331. if (is_object($user) && empty($user->rights->societe->client->voir)) {
  332. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
  333. }
  334. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
  335. $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'facture_fourn as f';
  336. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
  337. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_extrafields as extra ON f.rowid = extra.fk_object';
  338. $this->export_sql_end[$r] .= ' , '.MAIN_DB_PREFIX.'facture_fourn_det as fd';
  339. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_det_extrafields as extraline ON fd.rowid = extraline.fk_object';
  340. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
  341. $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture_fourn';
  342. $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('supplier_invoice').')';
  343. if (is_object($user) && empty($user->rights->societe->client->voir)) {
  344. $this->export_sql_end[$r] .= ' AND sc.fk_user = '.((int) $user->id);
  345. }
  346. $r++;
  347. $this->export_code[$r] = $this->rights_class.'_'.$r;
  348. $this->export_label[$r] = 'Factures fournisseurs et reglements';
  349. $this->export_icon[$r] = 'invoice';
  350. $this->export_permission[$r] = array(array("fournisseur", "facture", "export"));
  351. $this->export_fields_array[$r] = array(
  352. 's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode', 's.phone'=>'Phone',
  353. 's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.idprof5'=>'ProfId5', 's.idprof6'=>'ProfId6',
  354. 's.code_compta'=>'CustomerAccountancyCode', 's.code_compta_fournisseur'=>'SupplierAccountancyCode', 's.tva_intra'=>'VATIntra',
  355. 'f.rowid'=>"InvoiceId", 'f.ref'=>"InvoiceRef", 'f.ref_supplier'=>"RefSupplier", 'f.datec'=>"InvoiceDateCreation",
  356. 'f.datef'=>"DateInvoice", 'f.total_ht'=>"TotalHT", 'f.total_ttc'=>"TotalTTC", 'f.total_tva'=>"TotalVAT", 'f.paye'=>"InvoicePaid",
  357. 'f.fk_statut'=>'InvoiceStatus', 'f.note_public'=>"InvoiceNote", 'p.rowid'=>'PaymentId', 'pf.amount'=>'AmountPayment',
  358. 'p.datep'=>'DatePayment', 'p.num_paiement'=>'PaymentNumber', 'p.fk_bank'=>'IdTransaction', 'project.rowid'=>'ProjectId', 'project.ref'=>'ProjectRef', 'project.title'=>'ProjectLabel'
  359. );
  360. if (isModEnabled("multicurrency")) {
  361. $this->export_fields_array[$r]['f.multicurrency_code'] = 'Currency';
  362. $this->export_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
  363. $this->export_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
  364. $this->export_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
  365. $this->export_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
  366. }
  367. //$this->export_TypeFields_array[$r]=array(
  368. // 's.rowid'=>"Numeric",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text','s.phone'=>'Text',
  369. // '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",
  370. // 'f.total_ht'=>"Numeric",'f.total_ttc'=>"Numeric",'f.total_tva'=>"Numeric",'f.paye'=>"Boolean",'f.fk_statut'=>'Status','f.note_public'=>"Text",
  371. // 'pf.amount'=>'Numeric','p.datep'=>'Date','p.num_paiement'=>'Numeric'
  372. //);
  373. $this->export_TypeFields_array[$r] = array(
  374. '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',
  375. '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",
  376. 'f.total_ttc'=>"Numeric", 'f.total_tva'=>"Numeric", 'f.paye'=>"Boolean", 'f.fk_statut'=>'Status', 'f.note_public'=>"Text", 'pf.amount'=>'Numeric',
  377. 'p.datep'=>'Date', 'p.num_paiement'=>'Numeric', 'p.fk_bank'=>'Numeric', 'project.ref'=>'Text', 'project.title'=>'Text'
  378. );
  379. $this->export_entities_array[$r] = array(
  380. 's.rowid'=>"company", 's.nom'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company', 'c.code'=>'company', 's.phone'=>'company',
  381. 's.siren'=>'company', 's.siret'=>'company', 's.ape'=>'company', 's.idprof4'=>'company', 's.idprof5'=>'company', 's.idprof6'=>'company',
  382. 's.code_compta'=>'company', 's.code_compta_fournisseur'=>'company', 's.tva_intra'=>'company',
  383. 'f.rowid'=>"invoice", 'f.ref'=>"invoice", 'f.ref_supplier'=>"invoice", 'f.datec'=>"invoice", 'f.datef'=>"invoice", 'f.total_ht'=>"invoice",
  384. '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',
  385. 'p.datep'=>'payment', 'p.num_paiement'=>'payment', 'p.fk_bank'=>'account', 'project.rowid'=>'project', 'project.ref'=>'project', 'project.title'=>'project');
  386. $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
  387. // Add extra fields object
  388. $keyforselect = 'facture_fourn';
  389. $keyforelement = 'invoice';
  390. $keyforaliasextra = 'extra';
  391. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  392. // End add extra fields object
  393. $this->export_sql_start[$r] = 'SELECT DISTINCT ';
  394. $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
  395. if (is_object($user) && empty($user->rights->societe->client->voir)) {
  396. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
  397. }
  398. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
  399. $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'facture_fourn as f';
  400. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
  401. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_fourn_extrafields as extra ON f.rowid = extra.fk_object';
  402. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn_facturefourn as pf ON pf.fk_facturefourn = f.rowid';
  403. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn as p ON pf.fk_paiementfourn = p.rowid';
  404. $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid';
  405. $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('supplier_invoice').')';
  406. if (is_object($user) && empty($user->rights->societe->client->voir)) {
  407. $this->export_sql_end[$r] .= ' AND sc.fk_user = '.((int) $user->id);
  408. }
  409. // Order
  410. $r++;
  411. $this->export_code[$r] = $this->rights_class.'_'.$r;
  412. $this->export_label[$r] = 'Purchase Orders and lines of purchase orders';
  413. $this->export_icon[$r] = 'order';
  414. $this->export_permission[$r] = array(array("fournisseur", "commande", "export"));
  415. $this->export_fields_array[$r] = array(
  416. 's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 'ps.nom'=>'ParentCompany', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode', 's.phone'=>'Phone',
  417. 's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.idprof5'=>'ProfId5', 's.idprof6'=>'ProfId6', 's.tva_intra'=>'VATIntra',
  418. 'f.rowid'=>"OrderId", 'f.ref'=>"Ref", 'f.ref_supplier'=>"RefSupplier", 'f.date_creation'=>"DateCreation", 'f.date_commande'=>"OrderDate", 'f.date_livraison'=>"DateDeliveryPlanned",
  419. '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',
  420. 'f.note_public'=>"NotePublic", 'f.note_private'=>"NotePrivate", 'uv.login'=>'UserValidation', 'ua1.login'=>'ApprovedBy', 'ua2.login'=>'ApprovedBy2', 'fd.rowid'=>'LineId', 'fd.description'=>"LineDescription",
  421. 'fd.tva_tx'=>"LineVATRate", 'fd.qty'=>"LineQty", 'fd.remise_percent'=>"Discount", 'fd.total_ht'=>"LineTotalHT", 'fd.total_ttc'=>"LineTotalTTC",
  422. 'fd.total_tva'=>"LineTotalVAT", 'fd.date_start'=>"DateStart", 'fd.date_end'=>"DateEnd", 'fd.special_code'=>'SpecialCode',
  423. 'fd.product_type'=>'TypeOfLineServiceOrProduct', 'fd.ref'=>'RefSupplier', 'fd.fk_product'=>'ProductId',
  424. 'p.ref'=>'ProductRef', 'p.label'=>'ProductLabel', 'project.rowid'=>'ProjectId', 'project.ref'=>'ProjectRef', 'project.title'=>'ProjectLabel'
  425. );
  426. if (isModEnabled("multicurrency")) {
  427. $this->export_fields_array[$r]['f.multicurrency_code'] = 'Currency';
  428. $this->export_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
  429. $this->export_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
  430. $this->export_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
  431. $this->export_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
  432. }
  433. if (empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED)) {
  434. unset($this->export_fields_array['f.date_approve2']);
  435. unset($this->export_fields_array['ua2.login']);
  436. }
  437. $this->export_TypeFields_array[$r] = array(
  438. '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',
  439. '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",
  440. 'f.date_creation'=>"Date", 'f.date_commande'=>"Date", 'f.date_livraison'=>"Date", 'f.total_ht'=>"Numeric", 'f.total_ttc'=>"Numeric", 'f.total_tva'=>"Numeric",
  441. '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",
  442. 'fd.tva_tx'=>"Numeric", 'fd.qty'=>"Numeric", 'fd.remise_percent'=>"Numeric", 'fd.total_ht'=>"Numeric", 'fd.total_ttc'=>"Numeric", 'fd.total_tva'=>"Numeric",
  443. 'fd.date_start'=>"Date", 'fd.date_end'=>"Date", 'fd.special_code'=>"Numeric",
  444. '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'
  445. );
  446. $this->export_entities_array[$r] = array(
  447. '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',
  448. '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',
  449. '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",
  450. '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",
  451. 'fd.product_type'=>'order_line', 'fd.ref'=>'order_line', 'fd.fk_product'=>'product',
  452. 'p.ref'=>'product', 'p.label'=>'product', 'project.rowid'=>'project', 'project.ref'=>'project', 'project.title'=>'project'
  453. );
  454. $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
  455. // Add extra fields object
  456. $keyforselect = 'commande_fournisseur';
  457. $keyforelement = 'order';
  458. $keyforaliasextra = 'extra';
  459. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  460. // End add extra fields object
  461. // Add extra fields line
  462. $keyforselect = 'commande_fournisseurdet';
  463. $keyforelement = 'order_line';
  464. $keyforaliasextra = 'extraline';
  465. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  466. // End add extra fields line
  467. $this->export_sql_start[$r] = 'SELECT DISTINCT ';
  468. $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s';
  469. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as ps ON ps.rowid = s.parent';
  470. if (is_object($user) && empty($user->rights->societe->client->voir)) {
  471. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
  472. }
  473. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,';
  474. $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'commande_fournisseur as f';
  475. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)';
  476. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON uv.rowid = f.fk_user_valid';
  477. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as ua1 ON ua1.rowid = f.fk_user_approve';
  478. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as ua2 ON ua2.rowid = f.fk_user_approve2';
  479. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseur_extrafields as extra ON f.rowid = extra.fk_object,';
  480. $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'commande_fournisseurdet as fd';
  481. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseurdet_extrafields as extraline ON fd.rowid = extraline.fk_object';
  482. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)';
  483. $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_commande';
  484. $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('supplier_order').')';
  485. if (is_object($user) && empty($user->rights->societe->client->voir)) {
  486. $this->export_sql_end[$r] .= ' AND sc.fk_user = '.((int) $user->id);
  487. }
  488. //Import Supplier Invoice
  489. //--------
  490. $r = 0;
  491. $r++;
  492. $this->import_code[$r] = $this->rights_class.'_'.$r;
  493. $this->import_label[$r] = "SupplierInvoices"; // Translation key
  494. $this->import_icon[$r] = $this->picto;
  495. $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
  496. $this->import_tables_array[$r] = array('f' => MAIN_DB_PREFIX.'facture_fourn', 'extra' => MAIN_DB_PREFIX.'facture_fourn_extrafields');
  497. $this->import_tables_creator_array[$r] = array('f' => 'fk_user_author'); // Fields to store import user id
  498. $this->import_fields_array[$r] = array(
  499. 'f.ref' => 'InvoiceRef*',
  500. 'f.ref_supplier' => 'RefSupplier',
  501. 'f.type' => 'Type*',
  502. 'f.fk_soc' => 'Supplier/Vendor*',
  503. 'f.datec' => 'InvoiceDateCreation',
  504. 'f.datef' => 'DateInvoice',
  505. 'f.date_lim_reglement' => 'DateMaxPayment',
  506. 'f.total_ht' => 'TotalHT',
  507. 'f.total_ttc' => 'TotalTTC',
  508. 'f.total_tva' => 'TotalVAT',
  509. 'f.paye' => 'InvoicePaid',
  510. 'f.fk_statut' => 'InvoiceStatus',
  511. 'f.fk_user_modif' => 'Modifier Id',
  512. 'f.fk_user_valid' => 'Validator Id',
  513. 'f.fk_facture_source' => 'Invoice Source Id',
  514. 'f.fk_projet' => 'Project Id',
  515. 'f.fk_account' => 'Bank Account*',
  516. 'f.note_public' => 'InvoiceNote',
  517. 'f.note_private' => 'NotePrivate',
  518. 'f.fk_cond_reglement' => 'Payment Condition',
  519. 'f.fk_mode_reglement' => 'Payment Mode',
  520. 'f.model_pdf' => 'Model',
  521. 'f.date_valid' => 'Validation Date'
  522. );
  523. if (isModEnabled("multicurrency")) {
  524. $this->import_fields_array[$r]['f.multicurrency_code'] = 'Currency';
  525. $this->import_fields_array[$r]['f.multicurrency_tx'] = 'CurrencyRate';
  526. $this->import_fields_array[$r]['f.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
  527. $this->import_fields_array[$r]['f.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
  528. $this->import_fields_array[$r]['f.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
  529. }
  530. // Add extra fields
  531. $import_extrafield_sample = array();
  532. $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'facture_fourn' AND entity IN (0, ".$conf->entity.")";
  533. $resql = $this->db->query($sql);
  534. if ($resql) {
  535. while ($obj = $this->db->fetch_object($resql)) {
  536. $fieldname = 'extra.'.$obj->name;
  537. $fieldlabel = ucfirst($obj->label);
  538. $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
  539. $import_extrafield_sample[$fieldname] = $fieldlabel;
  540. }
  541. }
  542. // End add extra fields
  543. $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'facture_fourn');
  544. if (empty($conf->multicurrency->enabled)) {
  545. $this->import_fieldshidden_array[$r]['f.multicurrency_code'] = 'const-'.$conf->currency;
  546. }
  547. $this->import_regex_array[$r] = array('f.multicurrency_code' => 'code@'.MAIN_DB_PREFIX.'multicurrency');
  548. $import_sample = array(
  549. 'f.ref' => '(PROV001)',
  550. 'f.ref_supplier' => 'Supplier1',
  551. 'f.type' => '0',
  552. 'f.fk_soc' => 'Vendor1',
  553. 'f.datec' => '2021-01-01',
  554. 'f.datef' => '',
  555. 'f.date_lim_reglement' => '2021-01-30',
  556. 'f.total_ht' => '1000',
  557. 'f.total_ttc' => '1000',
  558. 'f.total_tva' => '0',
  559. 'f.paye' => '0',
  560. 'f.fk_statut' => '0',
  561. 'f.fk_user_modif' => '',
  562. 'f.fk_user_valid' => '',
  563. 'f.fk_facture_source' => '',
  564. 'f.fk_projet' => '',
  565. 'f.fk_account' => 'BANK1',
  566. 'f.note_public' => 'Note: ',
  567. 'f.note_private' => '',
  568. 'f.fk_cond_reglement' => '1',
  569. 'f.fk_mode_reglement' => '2',
  570. 'f.model_pdf' => 'crab',
  571. 'f.date_valid' => '',
  572. 'f.multicurrency_code' => 'USD',
  573. 'f.multicurrency_tx' => '1',
  574. 'f.multicurrency_total_ht' => '1000',
  575. 'f.multicurrency_total_tva' => '0',
  576. 'f.multicurrency_total_ttc' => '1000'
  577. );
  578. $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
  579. $this->import_updatekeys_array[$r] = array('f.ref' => 'Ref');
  580. $this->import_convertvalue_array[$r] = array(
  581. 'f.ref' => array(
  582. 'rule'=>'getrefifauto',
  583. 'class'=>(empty($conf->global->INVOICE_SUPPLIER_ADDON_NUMBER) ? 'mod_facture_fournisseur_cactus' : $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER),
  584. 'path'=>"/core/modules/supplier_invoice/".(empty($conf->global->INVOICE_SUPPLIER_ADDON_NUMBER) ? 'mod_facture_fournisseur_cactus' : $conf->global->INVOICE_SUPPLIER_ADDON_NUMBER).'.php',
  585. 'classobject'=>'FactureFournisseur',
  586. 'pathobject'=>'/fourn/class/fournisseur.facture.class.php',
  587. ),
  588. 'f.fk_soc' => array('rule' => 'fetchidfromref', 'file' => '/societe/class/societe.class.php', 'class' => 'Societe', 'method' => 'fetch', 'element' => 'ThirdParty'),
  589. 'f.fk_account' => array('rule' => 'fetchidfromref', 'file' => '/compta/bank/class/account.class.php', 'class' => 'Account', 'method' => 'fetch', 'element' => 'bank_account'),
  590. );
  591. //Import Supplier Invoice Lines
  592. $r++;
  593. $this->import_code[$r] = $this->rights_class.'_'.$r;
  594. $this->import_label[$r] = "SupplierInvoiceLines"; // Translation key
  595. $this->import_icon[$r] = $this->picto;
  596. $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
  597. $this->import_tables_array[$r] = array('fd' => MAIN_DB_PREFIX.'facture_fourn_det', 'extra' => MAIN_DB_PREFIX.'facture_fourn_det_extrafields');
  598. $this->import_fields_array[$r] = array(
  599. 'fd.fk_facture_fourn' => 'InvoiceRef*',
  600. 'fd.fk_parent_line' => 'ParentLine',
  601. 'fd.fk_product' => 'IdProduct',
  602. 'fd.description' => 'LineDescription',
  603. 'fd.pu_ht' => 'PriceUHT',
  604. 'fd.pu_ttc' => 'PriceUTTC',
  605. 'fd.qty' => 'LineQty',
  606. 'fd.remise_percent' => 'Reduc.',
  607. 'fd.vat_src_code' => 'Vat Source Code',
  608. 'fd.product_type' => 'TypeOfLineServiceOrProduct',
  609. 'fd.tva_tx' => 'LineVATRate',
  610. 'fd.total_ht' => 'LineTotalHT',
  611. 'fd.tva' => 'LineTotalVAT',
  612. 'fd.total_ttc' => 'LineTotalTTC',
  613. 'fd.date_start' => 'Start Date',
  614. 'fd.date_end' => 'End Date',
  615. 'fd.fk_unit' => 'Unit'
  616. );
  617. if (isModEnabled("multicurrency")) {
  618. $this->import_fields_array[$r]['fd.multicurrency_code'] = 'Currency';
  619. $this->import_fields_array[$r]['fd.multicurrency_subprice'] = 'CurrencyRate';
  620. $this->import_fields_array[$r]['fd.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
  621. $this->import_fields_array[$r]['fd.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
  622. $this->import_fields_array[$r]['fd.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
  623. }
  624. // Add extra fields
  625. $import_extrafield_sample = array();
  626. $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'facture_fourn_det' AND entity IN (0, ".$conf->entity.")";
  627. $resql = $this->db->query($sql);
  628. if ($resql) {
  629. while ($obj = $this->db->fetch_object($resql)) {
  630. $fieldname = 'extra.'.$obj->name;
  631. $fieldlabel = ucfirst($obj->label);
  632. $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
  633. $import_extrafield_sample[$fieldname] = $fieldlabel;
  634. }
  635. }
  636. // End add extra fields
  637. $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'facture_fourn_det');
  638. $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');
  639. $import_sample = array(
  640. 'fd.fk_facture_fourn' => '(PROV001)',
  641. 'fd.fk_parent_line' => '',
  642. 'fd.fk_product' => '',
  643. 'fd.description' => 'Test Product',
  644. 'fd.pu_ht' => '50000',
  645. 'fd.pu_ttc' => '50000',
  646. 'fd.qty' => '1',
  647. 'fd.remise_percent' => '0',
  648. 'fd.vat_src_code' => '',
  649. 'fd.product_type' => '0',
  650. 'fd.tva_tx' => '0',
  651. 'fd.total_ht' => '50000',
  652. 'fd.tva' => '0',
  653. 'fd.total_ttc' => '50000',
  654. 'fd.date_start' => '',
  655. 'fd.date_end' => '',
  656. 'fd.fk_unit' => '',
  657. 'fd.multicurrency_code' => 'USD',
  658. 'fd.multicurrency_tx' => '0',
  659. 'fd.multicurrency_total_ht' => '50000',
  660. 'fd.multicurrency_total_tva' => '0',
  661. 'fd.multicurrency_total_ttc' => '50000'
  662. );
  663. $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
  664. $this->import_updatekeys_array[$r] = array('fd.rowid' => 'Row Id', 'fd.fk_facture_fourn' => 'Invoice Id', 'fd.fk_product' => 'Product Id');
  665. $this->import_convertvalue_array[$r] = array(
  666. 'fd.fk_facture_fourn' => array('rule' => 'fetchidfromref', 'file' => '/fourn/class/fournisseur.facture.class.php', 'class' => 'FactureFournisseur', 'method' => 'fetch'),
  667. );
  668. //Import Purchase Orders
  669. $r++;
  670. $this->import_code[$r] = 'commande_fournisseur_'.$r;
  671. $this->import_label[$r] = 'SuppliersOrders';
  672. $this->import_icon[$r] = $this->picto;
  673. $this->import_entities_array[$r] = array();
  674. $this->import_tables_array[$r] = array('c' => MAIN_DB_PREFIX.'commande_fournisseur', 'extra' => MAIN_DB_PREFIX.'commande_fournisseur_extrafields');
  675. $this->import_tables_creator_array[$r] = array('c' => 'fk_user_author'); // Fields to store import user id
  676. $this->import_fields_array[$r] = array(
  677. 'c.ref' => 'Ref*',
  678. 'c.ref_supplier' => 'RefSupplier',
  679. 'c.fk_soc' => 'ThirdPartyName*',
  680. 'c.fk_projet' => 'ProjectId',
  681. 'c.date_creation' => 'DateCreation',
  682. 'c.date_valid' => 'DateValid',
  683. 'c.date_approve' => 'DateApprove',
  684. 'c.date_commande' => 'DateOrder',
  685. 'c.fk_user_modif' => 'ModifiedById',
  686. 'c.fk_user_valid' => 'ValidatedById',
  687. 'c.fk_user_approve' => 'ApprovedById',
  688. 'c.source' => 'Source',
  689. 'c.fk_statut' => 'Status*',
  690. 'c.billed' => 'Billed(0/1)',
  691. 'c.total_tva' => 'TotalTVA',
  692. 'c.total_ht' => 'TotalHT',
  693. 'c.total_ttc' => 'TotalTTC',
  694. 'c.note_private' => 'NotePrivate',
  695. 'c.note_public' => 'Note',
  696. 'c.date_livraison' => 'DeliveryDate',
  697. 'c.fk_cond_reglement' => 'Payment Condition',
  698. 'c.fk_mode_reglement' => 'Payment Mode',
  699. 'c.model_pdf' => 'Model'
  700. );
  701. if (isModEnabled("multicurrency")) {
  702. $this->import_fields_array[$r]['c.multicurrency_code'] = 'Currency';
  703. $this->import_fields_array[$r]['c.multicurrency_tx'] = 'CurrencyRate';
  704. $this->import_fields_array[$r]['c.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
  705. $this->import_fields_array[$r]['c.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
  706. $this->import_fields_array[$r]['c.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
  707. }
  708. // Add extra fields
  709. $import_extrafield_sample = array();
  710. $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'commande_fournisseur' AND entity IN (0, ".$conf->entity.")";
  711. $resql = $this->db->query($sql);
  712. if ($resql) {
  713. while ($obj = $this->db->fetch_object($resql)) {
  714. $fieldname = 'extra.'.$obj->name;
  715. $fieldlabel = ucfirst($obj->label);
  716. $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
  717. $import_extrafield_sample[$fieldname] = $fieldlabel;
  718. }
  719. }
  720. // End add extra fields
  721. $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'commande_fournisseur');
  722. $this->import_regex_array[$r] = array(
  723. 'c.multicurrency_code' => 'code@'.MAIN_DB_PREFIX.'multicurrency'
  724. );
  725. $this->import_updatekeys_array[$r] = array('c.ref' => 'Ref');
  726. $this->import_convertvalue_array[$r] = array(
  727. 'c.ref' => array(
  728. 'rule'=>'getrefifauto',
  729. 'class'=>(empty($conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER) ? 'mod_commande_fournisseur_muguet' : $conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER),
  730. 'path'=>"/core/modules/supplier_order/".(empty($conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER) ? 'mod_commande_fournisseur_muguet' : $conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER).'.php',
  731. 'classobject'=>'CommandeFournisseur',
  732. 'pathobject'=>'/fourn/class/fournisseur.commande.class.php',
  733. ),
  734. 'c.fk_soc' => array(
  735. 'rule' => 'fetchidfromref',
  736. 'file' => '/societe/class/societe.class.php',
  737. 'class' => 'Societe',
  738. 'method' => 'fetch',
  739. 'element' => 'ThirdParty'
  740. ),
  741. 'c.fk_mode_reglement' => array(
  742. 'rule' => 'fetchidfromcodeorlabel',
  743. 'file' => '/compta/paiement/class/cpaiement.class.php',
  744. 'class' => 'Cpaiement',
  745. 'method' => 'fetch',
  746. 'element' => 'cpayment'
  747. ),
  748. 'c.source' => array('rule' => 'zeroifnull'),
  749. );
  750. // Import PO Lines
  751. $r++;
  752. $this->import_code[$r] = 'commande_fournisseurdet_'.$r;
  753. $this->import_label[$r] = 'PurchaseOrderLines';
  754. $this->import_icon[$r] = $this->picto;
  755. $this->import_entities_array[$r] = array();
  756. $this->import_tables_array[$r] = array('cd' => MAIN_DB_PREFIX.'commande_fournisseurdet', 'extra' => MAIN_DB_PREFIX.'commande_fournisseurdet_extrafields');
  757. $this->import_fields_array[$r] = array(
  758. 'cd.fk_commande' => 'PurchaseOrder*',
  759. 'cd.fk_parent_line' => 'ParentLine',
  760. 'cd.fk_product' => 'IdProduct',
  761. 'cd.description' => 'LineDescription',
  762. 'cd.tva_tx' => 'LineVATRate',
  763. 'cd.qty' => 'LineQty',
  764. 'cd.remise_percent' => 'Reduc. Percent',
  765. 'cd.subprice' => 'Sub Price',
  766. 'cd.total_ht' => 'LineTotalHT',
  767. 'cd.total_tva' => 'LineTotalVAT',
  768. 'cd.total_ttc' => 'LineTotalTTC',
  769. 'cd.product_type' => 'TypeOfLineServiceOrProduct',
  770. 'cd.date_start' => 'Start Date',
  771. 'cd.date_end' => 'End Date',
  772. 'cd.info_bits' => 'InfoBits',
  773. 'cd.special_code' => 'Special Code',
  774. 'cd.rang' => 'LinePosition',
  775. 'cd.fk_unit' => 'Unit'
  776. );
  777. if (isModEnabled("multicurrency")) {
  778. $this->import_fields_array[$r]['cd.multicurrency_code'] = 'Currency';
  779. $this->import_fields_array[$r]['cd.multicurrency_subprice'] = 'CurrencyRate';
  780. $this->import_fields_array[$r]['cd.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
  781. $this->import_fields_array[$r]['cd.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
  782. $this->import_fields_array[$r]['cd.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
  783. }
  784. // Add extra fields
  785. $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'commande_fournisseurdet' AND entity IN (0, ".$conf->entity.")";
  786. $resql = $this->db->query($sql);
  787. if ($resql) {
  788. while ($obj = $this->db->fetch_object($resql)) {
  789. $fieldname = 'extra.'.$obj->name;
  790. $fieldlabel = ucfirst($obj->label);
  791. $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
  792. }
  793. }
  794. // End add extra fields
  795. $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'commande_fournisseurdet');
  796. $this->import_regex_array[$r] = array(
  797. 'cd.product_type' => '[0|1]$',
  798. 'cd.fk_product' => 'rowid@'.MAIN_DB_PREFIX.'product',
  799. 'cd.multicurrency_code' => 'code@'.MAIN_DB_PREFIX.'multicurrency'
  800. );
  801. $this->import_updatekeys_array[$r] = array('cd.fk_commande' => 'Purchase Order Id');
  802. $this->import_convertvalue_array[$r] = array(
  803. 'cd.fk_commande' => array(
  804. 'rule' => 'fetchidfromref',
  805. 'file' => '/fourn/class/fournisseur.commande.class.php',
  806. 'class' => 'CommandeFournisseur',
  807. 'method' => 'fetch',
  808. 'element' => 'order_supplier'
  809. ),
  810. 'cd.info_bits' => array('rule' => 'zeroifnull'),
  811. 'cd.special_code' => array('rule' => 'zeroifnull'),
  812. );
  813. }
  814. /**
  815. * Function called when module is enabled.
  816. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  817. * It also creates data directories
  818. *
  819. * @param string $options Options when enabling module ('', 'noboxes')
  820. * @return int 1 if OK, 0 if KO
  821. */
  822. public function init($options = '')
  823. {
  824. global $conf, $langs;
  825. $this->remove($options);
  826. //ODT template for Supplier Orders
  827. $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/supplier_orders/template_supplier_order.odt';
  828. $dirodt = DOL_DATA_ROOT.'/doctemplates/supplier_orders';
  829. $dest = $dirodt.'/template_supplier_order.odt';
  830. if (file_exists($src) && !file_exists($dest)) {
  831. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  832. dol_mkdir($dirodt);
  833. $result = dol_copy($src, $dest, 0, 0);
  834. if ($result < 0) {
  835. $langs->load("errors");
  836. $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
  837. return 0;
  838. }
  839. }
  840. $sql_order = array(
  841. "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),
  842. "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."', 'order_supplier', ".((int) $conf->entity).")",
  843. );
  844. //ODT template for Supplier Invoice
  845. $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/supplier_invoices/template_supplier_invoices.odt';
  846. $dirodt = DOL_DATA_ROOT.'/doctemplates/supplier_invoices';
  847. $dest = $dirodt.'/template_supplier_invoices.odt';
  848. if (file_exists($src) && !file_exists($dest)) {
  849. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  850. dol_mkdir($dirodt);
  851. $result = dol_copy($src, $dest, 0, 0);
  852. if ($result < 0) {
  853. $langs->load("errors");
  854. $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
  855. return 0;
  856. }
  857. }
  858. /*
  859. $sql_invoice = array(
  860. "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[2][2])."' AND type = 'invoice_supplier' AND entity = ".((int) $conf->entity),
  861. "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[2][2])."', 'invoice_supplier', ".((int) $conf->entity).")",
  862. );
  863. $sql = array_merge($sql_order, $sql_invoice);
  864. */
  865. $sql = $sql_order;
  866. return $this->_init($sql, $options);
  867. }
  868. }