modPropale.class.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509
  1. <?php
  2. /* Copyright (C) 2003-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2004 Sebastien Di Cintio <sdicintio@ressource-toi.org>
  5. * Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
  6. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  7. * Copyright (C) 2012 Juanjo Menent <jmenent@2byte.es>
  8. * Copyright (C) 2020 Ahmad Jamaly Rabib <rabib@metroworks.co.jp>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \defgroup propale Module commercial proposals
  25. * \brief Module to manage commercial proposals
  26. * \file htdocs/core/modules/modPropale.class.php
  27. * \ingroup propale
  28. * \brief Description and activation file for the module customer proposal
  29. */
  30. include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
  31. /**
  32. * Class to describe and enable module Propale
  33. */
  34. class modPropale extends DolibarrModules
  35. {
  36. /**
  37. * Constructor. Define names, constants, directories, boxes, permissions
  38. *
  39. * @param DoliDB $db Database handler
  40. */
  41. public function __construct($db)
  42. {
  43. global $conf, $user;
  44. $this->db = $db;
  45. $this->numero = 20;
  46. $this->family = "crm";
  47. $this->module_position = '10';
  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 propositions commerciales";
  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 = 'propal';
  55. // Data directories to create when module is enabled
  56. $this->dirs = array("/propale/temp");
  57. // Dependencies
  58. $this->hidden = false; // A condition to hide module
  59. $this->depends = array("modSociete"); // List of module class names as string that must be enabled if this module is enabled
  60. $this->requiredby = array(); // List of module ids to disable if this one is disabled
  61. $this->conflictwith = array(); // List of module class names as string this module is in conflict with
  62. $this->phpmin = array(7, 0); // Minimum version of PHP required by module
  63. $this->config_page_url = array("propal.php");
  64. $this->langfiles = array("propal", "bills", "companies", "deliveries", "products");
  65. // Constants
  66. $this->const = array();
  67. $r = 0;
  68. $this->const[$r][0] = "PROPALE_ADDON_PDF";
  69. $this->const[$r][1] = "chaine";
  70. $this->const[$r][2] = "cyan";
  71. $this->const[$r][3] = 'Name of the proposal generation manager in PDF format';
  72. $this->const[$r][4] = 0;
  73. $r++;
  74. $this->const[$r][0] = "PROPALE_ADDON";
  75. $this->const[$r][1] = "chaine";
  76. $this->const[$r][2] = "mod_propale_marbre";
  77. $this->const[$r][3] = 'Name of proposal numbering manager';
  78. $this->const[$r][4] = 0;
  79. $r++;
  80. $this->const[$r][0] = "PROPALE_VALIDITY_DURATION";
  81. $this->const[$r][1] = "chaine";
  82. $this->const[$r][2] = "15";
  83. $this->const[$r][3] = 'Duration of validity of business proposals';
  84. $this->const[$r][4] = 0;
  85. $r++;
  86. $this->const[$r][0] = "PROPALE_ADDON_PDF_ODT_PATH";
  87. $this->const[$r][1] = "chaine";
  88. $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/proposals";
  89. $this->const[$r][3] = "";
  90. $this->const[$r][4] = 0;
  91. $r++;
  92. $this->const[$r][0] = "PROPOSAL_ALLOW_ONLINESIGN";
  93. $this->const[$r][1] = "chaine";
  94. $this->const[$r][2] = "1";
  95. $this->const[$r][3] = "";
  96. $this->const[$r][4] = 0;
  97. $r++;
  98. /*$this->const[$r][0] = "PROPALE_DRAFT_WATERMARK";
  99. $this->const[$r][2] = "__(Draft)__";
  100. $this->const[$r][3] = 'Watermark to show on draft proposals';
  101. $this->const[$r][4] = 0;
  102. $r++;*/
  103. // Boxes
  104. $this->boxes = array(
  105. 0=>array('file'=>'box_graph_propales_permonth.php', 'enabledbydefaulton'=>'Home'),
  106. 1=>array('file'=>'box_propales.php', 'enabledbydefaulton'=>'Home'),
  107. );
  108. // Permissions
  109. $this->rights = array();
  110. $this->rights_class = 'propale';
  111. $r = 0;
  112. $r++;
  113. $this->rights[$r][0] = 21; // id de la permission
  114. $this->rights[$r][1] = 'Read commercial proposals'; // libelle de la permission
  115. $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
  116. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  117. $this->rights[$r][4] = 'lire';
  118. $r++;
  119. $this->rights[$r][0] = 22; // id de la permission
  120. $this->rights[$r][1] = 'Create and update commercial proposals'; // libelle de la permission
  121. $this->rights[$r][2] = 'w'; // type de la permission (deprecie a ce jour)
  122. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  123. $this->rights[$r][4] = 'creer';
  124. $r++;
  125. $this->rights[$r][0] = 24; // id de la permission
  126. $this->rights[$r][1] = 'Validate commercial proposals'; // Validate proposal
  127. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  128. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  129. $this->rights[$r][4] = 'propal_advance';
  130. $this->rights[$r][5] = 'validate';
  131. $r++;
  132. $this->rights[$r][0] = 25; // id de la permission
  133. $this->rights[$r][1] = 'Send commercial proposals to customers'; // libelle de la permission
  134. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  135. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  136. $this->rights[$r][4] = 'propal_advance';
  137. $this->rights[$r][5] = 'send';
  138. $r++;
  139. $this->rights[$r][0] = 26; // id de la permission
  140. $this->rights[$r][1] = 'Close commercial proposals'; // Set proposal to signed or refused
  141. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  142. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  143. $this->rights[$r][4] = 'propal_advance';
  144. $this->rights[$r][5] = 'close';
  145. $r++;
  146. $this->rights[$r][0] = 27; // id de la permission
  147. $this->rights[$r][1] = 'Delete commercial proposals'; // libelle de la permission
  148. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  149. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  150. $this->rights[$r][4] = 'supprimer';
  151. $r++;
  152. $this->rights[$r][0] = 28; // id de la permission
  153. $this->rights[$r][1] = 'Exporting commercial proposals and attributes'; // libelle de la permission
  154. $this->rights[$r][2] = 'r'; // type de la permission (deprecie a ce jour)
  155. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  156. $this->rights[$r][4] = 'export';
  157. // Menus
  158. //-------
  159. $this->menu = 1; // This module add menu entries. They are coded into menu manager.
  160. // Exports
  161. //--------
  162. $r = 0;
  163. $r++;
  164. $this->export_code[$r] = $this->rights_class.'_'.$r;
  165. $this->export_label[$r] = 'ProposalsAndProposalsLines'; // Translation key (used only if key ExportDataset_xxx_z not found)
  166. $this->export_permission[$r] = array(array("propale", "export"));
  167. $this->export_fields_array[$r] = array(
  168. 's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 'ps.nom'=>'ParentCompany', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'co.code'=>'CountryCode', 's.phone'=>'Phone',
  169. 's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 'c.rowid'=>"Id", 'c.ref'=>"Ref", 'c.ref_client'=>"RefCustomer",
  170. 'c.fk_soc'=>"IdCompany", 'c.datec'=>"DateCreation", 'c.datep'=>"DatePropal", 'c.fin_validite'=>"DateEndPropal",
  171. 'c.total_ht'=>"TotalHT", 'c.total_ttc'=>"TotalTTC");
  172. if (isModEnabled("multicurrency")) {
  173. $this->export_fields_array[$r]['c.multicurrency_code'] = 'Currency';
  174. $this->export_fields_array[$r]['c.multicurrency_tx'] = 'CurrencyRate';
  175. $this->export_fields_array[$r]['c.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
  176. $this->export_fields_array[$r]['c.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
  177. $this->export_fields_array[$r]['c.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
  178. }
  179. $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
  180. 'c.fk_statut'=>'Status', 'c.note_public'=>"NotePublic", 'c.note_private'=>"NotePrivate", 'c.date_livraison'=>'DeliveryDate',
  181. 'c.fk_user_author'=>'CreatedById', 'uc.login'=>'CreatedByLogin',
  182. 'c.fk_user_valid'=>'ValidatedById', 'uv.login'=>'ValidatedByLogin'));
  183. if (isModEnabled("project")) {
  184. $this->export_fields_array[$r]['pj.ref'] = 'ProjectRef';
  185. }
  186. $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
  187. 'cd.rowid'=>'LineId', 'cd.description'=>"LineDescription", 'cd.product_type'=>'TypeOfLineServiceOrProduct',
  188. 'cd.tva_tx'=>"LineVATRate", 'cd.qty'=>"LineQty", 'cd.total_ht'=>"LineTotalHT", 'cd.total_tva'=>"LineTotalVAT", 'cd.total_ttc'=>"LineTotalTTC",
  189. ));
  190. $this->export_fields_array[$r] = array_merge($this->export_fields_array[$r], array(
  191. 'p.rowid'=>'ProductId', 'p.ref'=>'ProductRef', 'p.label'=>'ProductLabel'
  192. ));
  193. // Add multicompany field
  194. if (getDolGlobalString('MULTICOMPANY_ENTITY_IN_EXPORT_IF_SHARED')) {
  195. $nbofallowedentities = count(explode(',', getEntity('propal')));
  196. if (isModEnabled('multicompany') && $nbofallowedentities > 1) {
  197. $this->export_fields_array[$r]['c.entity'] = 'Entity';
  198. }
  199. }
  200. //$this->export_TypeFields_array[$r]=array(
  201. // 's.rowid'=>"Numeric",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','co.code'=>'Text','s.phone'=>'Text',
  202. // 's.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','c.ref'=>"Text",'c.ref_client'=>"Text",'c.datec'=>"Date",'c.datep'=>"Date",
  203. // 'c.fin_validite'=>"Date",'c.total_ht'=>"Numeric",'c.total_ttc'=>"Numeric",'c.fk_statut'=>'Status','c.note_public'=>"Text",'c.note_private'=>"Text",
  204. // 'c.date_livraison'=>'Date','cd.description'=>"Text",'cd.product_type'=>'Boolean','cd.tva_tx'=>"Numeric",'cd.qty'=>"Numeric",'cd.total_ht'=>"Numeric",
  205. // 'cd.total_tva'=>"Numeric",'cd.total_ttc'=>"Numeric",'p.rowid'=>'List:product:label','p.ref'=>'Text','p.label'=>'Text'
  206. //);
  207. $this->export_TypeFields_array[$r] = array(
  208. 's.nom'=>'Text', 'ps.nom'=>'Text', 's.address'=>'Text', 's.zip'=>'Text', 's.town'=>'Text', 'co.code'=>'Text', 's.phone'=>'Text', 's.siren'=>'Text', 's.siret'=>'Text',
  209. 's.ape'=>'Text', 's.idprof4'=>'Text', 'c.ref'=>"Text", 'c.ref_client'=>"Text", 'c.datec'=>"Date", 'c.datep'=>"Date", 'c.fin_validite'=>"Date",
  210. 'c.total_ht'=>"Numeric", 'c.total_ttc'=>"Numeric", 'c.fk_statut'=>'Status', 'c.note_public'=>"Text", 'c.note_private'=>"Text", 'c.date_livraison'=>'Date',
  211. 'pj.ref'=>'Text', 'cd.description'=>"Text", 'cd.product_type'=>'Boolean', 'cd.tva_tx'=>"Numeric", 'cd.qty'=>"Numeric", 'cd.total_ht'=>"Numeric",
  212. 'cd.total_tva'=>"Numeric", 'cd.total_ttc'=>"Numeric", 'p.ref'=>'Text', 'p.label'=>'Text',
  213. 'c.entity'=>'List:entity:label:rowid',
  214. );
  215. $this->export_entities_array[$r] = array(
  216. 's.rowid'=>"company", 's.nom'=>'company', 'ps.nom'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company', 'co.code'=>'company', 's.phone'=>'company',
  217. 's.siren'=>'company', 's.ape'=>'company', 's.idprof4'=>'company', 's.siret'=>'company', 'c.rowid'=>"propal", 'c.ref'=>"propal", 'c.ref_client'=>"propal",
  218. 'c.fk_soc'=>"propal", 'c.datec'=>"propal", 'c.datep'=>"propal", 'c.fin_validite'=>"propal", 'c.total_ht'=>"propal",
  219. 'c.total_ttc'=>"propal", 'c.fk_statut'=>"propal", 'c.note_public'=>"propal", 'c.note_private'=>"propal", 'c.date_livraison'=>"propal",
  220. 'c.fk_user_author'=>'user', 'uc.login'=>'user',
  221. 'c.fk_user_valid'=>'user', 'uv.login'=>'user',
  222. 'pj.ref'=>'project',
  223. 'cd.rowid'=>'propal_line',
  224. 'cd.description'=>"propal_line", 'cd.product_type'=>'propal_line', 'cd.tva_tx'=>"propal_line", 'cd.qty'=>"propal_line",
  225. 'cd.total_ht'=>"propal_line", 'cd.total_tva'=>"propal_line", 'cd.total_ttc'=>"propal_line", 'p.rowid'=>'product', 'p.ref'=>'product', 'p.label'=>'product'
  226. );
  227. $this->export_dependencies_array[$r] = array('propal_line'=>'cd.rowid', 'product'=>'cd.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
  228. $keyforselect = 'propal';
  229. $keyforelement = 'propal';
  230. $keyforaliasextra = 'extra';
  231. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  232. $keyforselect = 'propaldet';
  233. $keyforelement = 'propal_line';
  234. $keyforaliasextra = 'extra2';
  235. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  236. $keyforselect = 'product';
  237. $keyforelement = 'product';
  238. $keyforaliasextra = 'extra3';
  239. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  240. $keyforselect = 'societe';
  241. $keyforelement = 'company';
  242. $keyforaliasextra = 'extra4';
  243. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  244. $this->export_sql_start[$r] = 'SELECT DISTINCT ';
  245. $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s ';
  246. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_extrafields as extra4 ON s.rowid = extra4.fk_object';
  247. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as ps ON ps.rowid = s.parent';
  248. if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) {
  249. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
  250. }
  251. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON s.fk_pays = co.rowid,';
  252. $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'propal as c';
  253. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON c.fk_projet = pj.rowid';
  254. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uc ON c.fk_user_author = uc.rowid';
  255. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON c.fk_user_valid = uv.rowid';
  256. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'propal_extrafields as extra ON c.rowid = extra.fk_object';
  257. $this->export_sql_end[$r] .= ', '.MAIN_DB_PREFIX.'propaldet as cd';
  258. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'propaldet_extrafields as extra2 on cd.rowid = extra2.fk_object';
  259. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (cd.fk_product = p.rowid)';
  260. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra3 on p.rowid = extra3.fk_object';
  261. $this->export_sql_end[$r] .= ' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_propal';
  262. $this->export_sql_end[$r] .= ' AND c.entity IN ('.getEntity('propal').')';
  263. if (!empty($user) && !$user->hasRight('societe', 'client', 'voir')) {
  264. $this->export_sql_end[$r] .= ' AND sc.fk_user = '.(empty($user) ? 0 : $user->id);
  265. }
  266. // Imports
  267. //--------
  268. $r = 0;
  269. $r++;
  270. $this->import_code[$r] = $this->rights_class.'_'.$r;
  271. $this->import_label[$r] = 'Proposals'; // Translation key
  272. $this->import_icon[$r] = $this->picto;
  273. $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
  274. $this->import_tables_array[$r] = array('c' => MAIN_DB_PREFIX.'propal', 'extra' => MAIN_DB_PREFIX.'propal_extrafields');
  275. $this->import_tables_creator_array[$r] = array('c'=>'fk_user_author'); // Fields to store import user id
  276. $this->import_fields_array[$r] = array(
  277. 'c.ref' => 'Ref*',
  278. 'c.ref_client' => 'RefCustomer',
  279. 'c.fk_soc' => 'ThirdPartyName*',
  280. 'c.datec' => 'DateCreation',
  281. 'c.datep' => 'DatePropal',
  282. 'c.fin_validite' => 'DateEndPropal',
  283. 'c.total_ht' => 'TotalHT',
  284. 'c.total_ttc' => 'TotalTTC',
  285. 'c.fk_statut' => 'Status*',
  286. 'c.note_public' => 'NotePublic',
  287. 'c.note_private' => 'NotePrivate',
  288. 'c.date_livraison' => 'DeliveryDate',
  289. 'c.fk_user_valid' => 'ValidatedById'
  290. );
  291. if (isModEnabled("multicurrency")) {
  292. $this->import_fields_array[$r]['c.multicurrency_code'] = 'Currency';
  293. $this->import_fields_array[$r]['c.multicurrency_tx'] = 'CurrencyRate';
  294. $this->import_fields_array[$r]['c.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
  295. $this->import_fields_array[$r]['c.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
  296. $this->import_fields_array[$r]['c.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
  297. }
  298. // Add extra fields
  299. $import_extrafield_sample = array();
  300. $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'propal' AND entity IN (0, ".$conf->entity.")";
  301. $resql = $this->db->query($sql);
  302. if ($resql) {
  303. while ($obj = $this->db->fetch_object($resql)) {
  304. $fieldname = 'extra.'.$obj->name;
  305. $fieldlabel = ucfirst($obj->label);
  306. $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
  307. $import_extrafield_sample[$fieldname] = $fieldlabel;
  308. }
  309. }
  310. // End add extra fields
  311. $this->import_fieldshidden_array[$r] = ['extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'propal'];
  312. $this->import_regex_array[$r] = ['c.ref' => '[^ ]'];
  313. $import_sample = [
  314. 'c.ref' => 'PROV0077',
  315. 'c.ref_client' => 'Client1',
  316. 'c.fk_soc' => 'MyBigCompany',
  317. 'c.datec' => '2020-01-01',
  318. 'c.datep' => '2020-01-01',
  319. 'c.fin_validite' => '2020-01-01',
  320. 'c.total_ht' => '0',
  321. 'c.total_ttc' => '0',
  322. 'c.fk_statut' => '1',
  323. 'c.note_public' => '',
  324. 'c.note_private' => '',
  325. 'c.date_livraison' => '2020-01-01',
  326. 'c.fk_user_valid' => '1',
  327. 'c.multicurrency_code' => '',
  328. 'c.multicurrency_tx' => '1',
  329. 'c.multicurrency_total_ht' => '0',
  330. 'c.multicurrency_total_tva' => '0',
  331. 'c.multicurrency_total_ttc' => '0'
  332. ];
  333. $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
  334. $this->import_updatekeys_array[$r] = array('c.ref'=>'Ref');
  335. $this->import_convertvalue_array[$r] = array(
  336. 'c.ref' => array(
  337. 'rule'=>'getrefifauto',
  338. 'class'=>(!getDolGlobalString('PROPALE_ADDON') ? 'mod_propale_marbre' : $conf->global->PROPALE_ADDON),
  339. 'path'=>"/core/modules/propale/".(!getDolGlobalString('PROPALE_ADDON') ? 'mod_propale_marbre' : $conf->global->PROPALE_ADDON).'.php',
  340. 'classobject'=>'Propal',
  341. 'pathobject'=>'/comm/propal/class/propal.class.php',
  342. ),
  343. 'c.fk_soc' => array(
  344. 'rule' => 'fetchidfromref',
  345. 'file' => '/societe/class/societe.class.php',
  346. 'class' => 'Societe',
  347. 'method' => 'fetch',
  348. 'element' => 'ThirdParty'
  349. )
  350. );
  351. //Import Proposal Lines
  352. $r++;
  353. $this->import_code[$r] = $this->rights_class.'line_'.$r;
  354. $this->import_label[$r] = "ProposalLines"; // Translation key
  355. $this->import_icon[$r] = $this->picto;
  356. $this->import_entities_array[$r] = array(); // We define here only fields that use another icon that the one defined into import_icon
  357. $this->import_tables_array[$r] = array(
  358. 'cd' => MAIN_DB_PREFIX.'propaldet',
  359. 'extra' => MAIN_DB_PREFIX.'propaldet_extrafields'
  360. );
  361. $this->import_fields_array[$r] = array(
  362. 'cd.fk_propal' => 'Proposal*',
  363. 'cd.fk_parent_line' => 'ParentLine',
  364. 'cd.fk_product' => 'IdProduct',
  365. 'cd.description' => 'LineDescription',
  366. 'cd.product_type' => 'TypeOfLineServiceOrProduct',
  367. 'cd.tva_tx' => 'LineVATRate',
  368. 'cd.qty' => 'LineQty',
  369. 'cd.remise_percent' => 'Reduc. Percent',
  370. 'cd.price' => 'Price',
  371. 'cd.subprice' => 'Sub Price',
  372. 'cd.total_ht' => 'LineTotalHT',
  373. 'cd.total_tva' => 'LineTotalVAT',
  374. 'cd.total_ttc' => 'LineTotalTTC',
  375. 'cd.date_start' => 'Start Date',
  376. 'cd.date_end' => 'End Date',
  377. 'cd.buy_price_ht' => 'LineBuyPriceHT'
  378. );
  379. if (isModEnabled("multicurrency")) {
  380. $this->import_fields_array[$r]['cd.multicurrency_code'] = 'Currency';
  381. $this->import_fields_array[$r]['cd.multicurrency_subprice'] = 'CurrencyRate';
  382. $this->import_fields_array[$r]['cd.multicurrency_total_ht'] = 'MulticurrencyAmountHT';
  383. $this->import_fields_array[$r]['cd.multicurrency_total_tva'] = 'MulticurrencyAmountVAT';
  384. $this->import_fields_array[$r]['cd.multicurrency_total_ttc'] = 'MulticurrencyAmountTTC';
  385. }
  386. // Add extra fields
  387. $import_extrafield_sample = array();
  388. $sql = "SELECT name, label, fieldrequired FROM ".MAIN_DB_PREFIX."extrafields WHERE type <> 'separate' AND elementtype = 'propaldet' AND entity IN (0, ".$conf->entity.")";
  389. $resql = $this->db->query($sql);
  390. if ($resql) {
  391. while ($obj = $this->db->fetch_object($resql)) {
  392. $fieldname = 'extra.'.$obj->name;
  393. $fieldlabel = ucfirst($obj->label);
  394. $this->import_fields_array[$r][$fieldname] = $fieldlabel.($obj->fieldrequired ? '*' : '');
  395. $import_extrafield_sample[$fieldname] = $fieldlabel;
  396. }
  397. }
  398. // End add extra fields
  399. $this->import_fieldshidden_array[$r] = array('extra.fk_object' => 'lastrowid-'.MAIN_DB_PREFIX.'propaldet');
  400. $this->import_regex_array[$r] = array('cd.product_type' => '[0|1]$');
  401. $import_sample = array(
  402. 'cd.fk_propal' => 'PROV(0001)',
  403. 'cd.fk_parent_line' => '',
  404. 'cd.fk_product' => '',
  405. 'cd.description' => 'Line description',
  406. 'cd.product_type' => '1',
  407. 'cd.tva_tx' => '0',
  408. 'cd.qty' => '2',
  409. 'cd.remise_percent' => '0',
  410. 'cd.price' => '',
  411. 'cd.subprice' => '5000',
  412. 'cd.total_ht' => '10000',
  413. 'cd.total_tva' => '0',
  414. 'cd.total_ttc' => '10100',
  415. 'cd.date_start' => '',
  416. 'cd.date_end' => '',
  417. 'cd.buy_price_ht' => '7000',
  418. 'cd.multicurrency_code' => 'JPY',
  419. 'cd.multicurrency_tx' => '1',
  420. 'cd.multicurrency_total_ht' => '10000',
  421. 'cd.multicurrency_total_tva' => '0',
  422. 'cd.multicurrency_total_ttc' => '10100'
  423. );
  424. $this->import_examplevalues_array[$r] = array_merge($import_sample, $import_extrafield_sample);
  425. $this->import_updatekeys_array[$r] = array('cd.fk_propal' => 'Quotation Id', 'cd.fk_product' => 'Product Id');
  426. $this->import_convertvalue_array[$r] = array(
  427. 'cd.fk_propal' => array(
  428. 'rule'=>'fetchidfromref',
  429. 'file'=>'/comm/propal/class/propal.class.php',
  430. 'class'=>'Propal',
  431. 'method'=>'fetch'
  432. )
  433. );
  434. }
  435. /**
  436. * Function called when module is enabled.
  437. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  438. * It also creates data directories
  439. *
  440. * @param string $options Options when enabling module ('', 'noboxes')
  441. * @return int 1 if OK, 0 if KO
  442. */
  443. public function init($options = '')
  444. {
  445. global $conf, $langs;
  446. // Remove permissions and default values
  447. $this->remove($options);
  448. //ODT template
  449. $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/proposals/template_proposal.odt';
  450. $dirodt = DOL_DATA_ROOT.'/doctemplates/proposals';
  451. $dest = $dirodt.'/template_proposal.odt';
  452. if (file_exists($src) && !file_exists($dest)) {
  453. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  454. dol_mkdir($dirodt);
  455. $result = dol_copy($src, $dest, 0, 0);
  456. if ($result < 0) {
  457. $langs->load("errors");
  458. $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
  459. return 0;
  460. }
  461. }
  462. $sql = array(
  463. "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'propal' AND entity = ".((int) $conf->entity),
  464. "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','propal',".((int) $conf->entity).")",
  465. );
  466. return $this->_init($sql, $options);
  467. }
  468. }