modReception.class.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <?php
  2. /* Copyright (C) 2018 Quentin Vial-Gouteyron <quentin.vial-gouteyron@atm-consulting.fr>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  16. */
  17. /**
  18. * \defgroup reception Module reception
  19. * \brief Module pour gerer les réceptions de produits
  20. * \file htdocs/core/modules/modReception.class.php
  21. * \ingroup reception
  22. * \brief Description and activation file for the module Reception
  23. */
  24. include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php';
  25. /**
  26. * Class to describe and enable module Reception
  27. */
  28. class modReception extends DolibarrModules
  29. {
  30. /**
  31. * Constructor. Define names, constants, directories, boxes, permissions
  32. *
  33. * @param DoliDB $db Database handler
  34. */
  35. public function __construct($db)
  36. {
  37. global $conf, $user;
  38. $this->db = $db;
  39. $this->numero = 94160;
  40. $this->family = "srm";
  41. $this->module_position = '40';
  42. // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
  43. $this->name = preg_replace('/^mod/i', '', get_class($this));
  44. $this->description = "ReceptionDescription";
  45. // Possible values for version are: 'development', 'experimental', 'dolibarr' or version
  46. $this->version = 'dolibarr';
  47. $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name);
  48. $this->picto = "dollyrevert";
  49. // Data directories to create when module is enabled
  50. $this->dirs = array("/reception/receipt",
  51. "/reception/receipt/temp",
  52. "/doctemplates/receptions"
  53. );
  54. // Config pages
  55. $this->config_page_url = array("reception_setup.php");
  56. // Dependencies
  57. $this->depends = array("modFournisseur");
  58. $this->requiredby = array();
  59. $this->conflictwith = array();
  60. $this->langfiles = array('receptions');
  61. // Constants
  62. $this->const = array();
  63. $r = 0;
  64. $this->const[$r][0] = "RECEPTION_ADDON_PDF";
  65. $this->const[$r][1] = "chaine";
  66. $this->const[$r][2] = "squille";
  67. $this->const[$r][3] = 'Nom du gestionnaire de generation des bons receptions en PDF';
  68. $this->const[$r][4] = 0;
  69. $r++;
  70. $this->const[$r][0] = "RECEPTION_ADDON_NUMBER";
  71. $this->const[$r][1] = "chaine";
  72. $this->const[$r][2] = "mod_reception_beryl";
  73. $this->const[$r][3] = 'Name for numbering manager for receptions';
  74. $this->const[$r][4] = 0;
  75. $r++;
  76. $this->const[$r][0] = "RECEPTION_ADDON_PDF_ODT_PATH";
  77. $this->const[$r][1] = "chaine";
  78. $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/receptions";
  79. $this->const[$r][3] = "";
  80. $this->const[$r][4] = 0;
  81. $r++;
  82. $this->const[$r][0] = "MAIN_SUBMODULE_RECEPTION";
  83. $this->const[$r][1] = "chaine";
  84. $this->const[$r][2] = "1";
  85. $this->const[$r][3] = "Enable receptions";
  86. $this->const[$r][4] = 0;
  87. $r++;
  88. // Boxes
  89. $this->boxes = array();
  90. // Permissions
  91. $this->rights = array();
  92. $this->rights_class = 'reception';
  93. $r = 0;
  94. $r++;
  95. $this->rights[$r][0] = $this->numero.$r;
  96. $this->rights[$r][1] = 'Lire les receptions';
  97. $this->rights[$r][2] = 'r';
  98. $this->rights[$r][3] = 0;
  99. $this->rights[$r][4] = 'lire';
  100. $r++;
  101. $this->rights[$r][0] = $this->numero.$r;
  102. $this->rights[$r][1] = 'Creer modifier les receptions';
  103. $this->rights[$r][2] = 'w';
  104. $this->rights[$r][3] = 0;
  105. $this->rights[$r][4] = 'creer';
  106. $r++;
  107. $this->rights[$r][0] = $this->numero.$r;
  108. $this->rights[$r][1] = 'Valider les receptions';
  109. $this->rights[$r][2] = 'd';
  110. $this->rights[$r][3] = 0;
  111. $this->rights[$r][4] = 'reception_advance';
  112. $this->rights[$r][5] = 'validate';
  113. $r++;
  114. $this->rights[$r][0] = $this->numero.$r; // id de la permission
  115. $this->rights[$r][1] = 'Envoyer les receptions aux clients'; // libelle de la permission
  116. $this->rights[$r][2] = 'd'; // type de la permission (deprecie a ce jour)
  117. $this->rights[$r][3] = 0; // La permission est-elle une permission par defaut
  118. $this->rights[$r][4] = 'reception_advance';
  119. $this->rights[$r][5] = 'send';
  120. $r++;
  121. $this->rights[$r][0] = $this->numero.$r;
  122. $this->rights[$r][1] = 'Exporter les receptions';
  123. $this->rights[$r][2] = 'r';
  124. $this->rights[$r][3] = 0;
  125. $this->rights[$r][4] = 'reception';
  126. $this->rights[$r][5] = 'export';
  127. $r++;
  128. $this->rights[$r][0] = $this->numero.$r;
  129. $this->rights[$r][1] = 'Supprimer les receptions';
  130. $this->rights[$r][2] = 'd';
  131. $this->rights[$r][3] = 0;
  132. $this->rights[$r][4] = 'supprimer';
  133. // Menus
  134. //-------
  135. $this->menu = 1; // This module add menu entries. They are coded into menu manager.
  136. // Exports
  137. //--------
  138. $r = 0;
  139. include_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php';
  140. $shipment = new CommandeFournisseur($this->db);
  141. $contact_arrays = $shipment->liste_type_contact('external', '', 0, 0, '');
  142. if (is_array($contact_arrays) && count($contact_arrays) > 0) {
  143. $idcontacts = join(',', array_keys($shipment->liste_type_contact('external', '', 0, 0, '')));
  144. } else {
  145. $idcontacts = 0;
  146. }
  147. $r++;
  148. $this->export_code[$r] = $this->rights_class.'_'.$r;
  149. $this->export_label[$r] = 'Receptions'; // Translation key (used only if key ExportDataset_xxx_z not found)
  150. $this->export_permission[$r] = array(array("reception", "reception", "export"));
  151. $this->export_fields_array[$r] = array(
  152. 's.rowid'=>"IdCompany", 's.nom'=>'ThirdParty', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town',
  153. 'd.nom'=>'State', 'co.label'=>'Country', 'co.code'=>'CountryCode', 's.phone'=>'Phone', 's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.idprof5'=>'ProfId5', 's.idprof6'=>'ProfId6',
  154. 'c.rowid'=>"Id", 'c.ref'=>"Ref", 'c.ref_supplier'=>"RefSupplier", 'c.fk_soc'=>"IdCompany", 'c.date_creation'=>"DateCreation", 'c.date_delivery'=>"DateDeliveryPlanned", 'c.tracking_number'=>"TrackingNumber", 'c.height'=>"Height", 'c.width'=>"Width", 'c.size'=>"Depth", 'c.size_units'=>'SizeUnits', 'c.weight'=>"Weight", 'c.weight_units'=>"WeightUnits", 'c.fk_statut'=>'Status', 'c.note_public'=>"NotePublic", 'ed.rowid'=>'LineId',
  155. 'ed.comment'=>'Description', 'ed.qty'=>"Qty",
  156. 'p.rowid'=>'ProductId', 'p.ref'=>'ProductRef', 'p.label'=>'ProductLabel', 'p.weight'=>'ProductWeight', 'p.weight_units'=>'WeightUnits', 'p.volume'=>'ProductVolume', 'p.volume_units'=>'VolumeUnits'
  157. );
  158. if ($idcontacts && !empty($conf->global->RECEPTION_ADD_CONTACTS_IN_EXPORT)) {
  159. $this->export_fields_array[$r] += array('sp.rowid'=>'IdContact', 'sp.lastname'=>'Lastname', 'sp.firstname'=>'Firstname', 'sp.note_public'=>'NotePublic');
  160. }
  161. //$this->export_TypeFields_array[$r]=array('s.rowid'=>"Numeric",'s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','co.label'=>'List:c_country:label:label','co.code'=>'Text','s.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','c.ref'=>"Text",'c.ref_client'=>"Text",'c.date_creation'=>"Date",'c.date_commande'=>"Date",'c.amount_ht'=>"Numeric",'c.remise_percent'=>"Numeric",'c.total_ht'=>"Numeric",'c.total_ttc'=>"Numeric",'c.facture'=>"Boolean",'c.fk_statut'=>'Status','c.note_public'=>"Text",'c.date_livraison'=>'Date','ed.qty'=>"Text");
  162. $this->export_TypeFields_array[$r] = array(
  163. 's.nom'=>'Text', 's.address'=>'Text', 's.zip'=>'Text', 's.town'=>'Text',
  164. 'co.label'=>'List:c_country:label:label', 'co.code'=>'Text', 's.phone'=>'Text', 's.siren'=>'Text', 's.siret'=>'Text', 's.ape'=>'Text', 's.idprof4'=>'Text',
  165. 'c.ref'=>"Text", 'c.ref_supplier'=>"Text", 'c.date_creation'=>"Date", 'c.date_delivery'=>"Date", 'c.tracking_number'=>"Numeric", 'c.height'=>"Numeric", 'c.width'=>"Numeric", 'c.weight'=>"Numeric", 'c.fk_statut'=>'Status', 'c.note_public'=>"Text",
  166. 'ed.qty'=>"Numeric", 'd.nom'=>'Text'
  167. );
  168. $this->export_entities_array[$r] = array(
  169. 's.rowid'=>"company", 's.nom'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company',
  170. 'd.nom'=>'company', 'co.label'=>'company', 'co.code'=>'company', 's.fk_pays'=>'company', 's.phone'=>'company', 's.siren'=>'company', 's.ape'=>'company', 's.siret'=>'company', 's.idprof4'=>'company', 's.idprof5'=>'company', 's.idprof6'=>'company',
  171. 'c.rowid'=>"reception", 'c.ref'=>"reception", 'c.ref_supplier'=>"reception", 'c.fk_soc'=>"reception", 'c.date_creation'=>"reception", 'c.date_delivery'=>"reception", 'c.tracking_number'=>'reception', 'c.height'=>"reception", 'c.width'=>"reception", 'c.size'=>'reception', 'c.size_units'=>'reception', 'c.weight'=>"reception", 'c.weight_units'=>'reception', 'c.fk_statut'=>"reception", 'c.note_public'=>"reception",
  172. 'ed.rowid'=>'reception_line', 'ed.comment'=>'reception_line', 'ed.qty'=>"reception_line",
  173. 'p.rowid'=>'product', 'p.ref'=>'product', 'p.label'=>'product', 'p.weight'=>'product', 'p.weight_units'=>'product', 'p.volume'=>'product', 'p.volume_units'=>'product'
  174. );
  175. if ($idcontacts && !empty($conf->global->RECEPTION_ADD_CONTACTS_IN_EXPORT)) {
  176. $this->export_entities_array[$r] += array('sp.rowid'=>'contact', 'sp.lastname'=>'contact', 'sp.firstname'=>'contact', 'sp.note_public'=>'contact');
  177. }
  178. $this->export_dependencies_array[$r] = array('reception_line'=>'ed.rowid', 'product'=>'ed.rowid'); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them
  179. if ($idcontacts && !empty($conf->global->RECEPTION_ADD_CONTACTS_IN_EXPORT)) {
  180. $keyforselect = 'socpeople';
  181. $keyforelement = 'contact';
  182. $keyforaliasextra = 'extra3';
  183. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  184. }
  185. $keyforselect = 'reception';
  186. $keyforelement = 'reception';
  187. $keyforaliasextra = 'extra';
  188. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  189. $keyforselect = 'commande_fournisseur_dispatch';
  190. $keyforelement = 'reception_line';
  191. $keyforaliasextra = 'extra2';
  192. include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php';
  193. $this->export_sql_start[$r] = 'SELECT DISTINCT ';
  194. $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'reception as c';
  195. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'reception_extrafields as extra ON c.rowid = extra.fk_object,';
  196. $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'societe as s';
  197. if (empty($user->rights->societe->client->voir)) {
  198. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid';
  199. }
  200. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid';
  201. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON s.fk_pays = co.rowid,';
  202. $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'commande_fournisseur_dispatch as ed';
  203. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'commande_fournisseur_dispatch_extrafields as extra2 ON ed.rowid = extra2.fk_object';
  204. $this->export_sql_end[$r] .= ' , '.MAIN_DB_PREFIX.'commande_fournisseurdet as cd';
  205. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on cd.fk_product = p.rowid';
  206. if ($idcontacts && !empty($conf->global->RECEPTION_ADD_CONTACTS_IN_EXPORT)) {
  207. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'element_contact as ee ON ee.element_id = cd.fk_commande AND ee.fk_c_type_contact IN ('.$this->db->sanitize($idcontacts).')';
  208. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople as sp ON sp.rowid = ee.fk_socpeople';
  209. $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople_extrafields as extra3 ON sp.rowid = extra3.fk_object';
  210. }
  211. $this->export_sql_end[$r] .= ' WHERE c.fk_soc = s.rowid AND c.rowid = ed.fk_reception AND ed.fk_commandefourndet = cd.rowid';
  212. $this->export_sql_end[$r] .= ' AND c.entity IN ('.getEntity('reception').')';
  213. if (empty($user->rights->societe->client->voir)) {
  214. $this->export_sql_end[$r] .= ' AND sc.fk_user = '.(empty($user) ? 0 : $user->id);
  215. }
  216. }
  217. /**
  218. * Function called when module is enabled.
  219. * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database.
  220. * It also creates data directories
  221. *
  222. * @param string $options Options when enabling module ('', 'noboxes')
  223. * @return int 1 if OK, 0 if KO
  224. */
  225. public function init($options = '')
  226. {
  227. global $conf, $langs;
  228. // Permissions
  229. $this->remove($options);
  230. //ODT template
  231. $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/reception/template_reception.odt';
  232. $dirodt = DOL_DATA_ROOT.'/doctemplates/reception';
  233. $dest = $dirodt.'/template_reception.odt';
  234. if (file_exists($src) && !file_exists($dest)) {
  235. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  236. dol_mkdir($dirodt);
  237. $result = dol_copy($src, $dest, 0, 0);
  238. if ($result < 0) {
  239. $langs->load("errors");
  240. $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest);
  241. return 0;
  242. }
  243. }
  244. $sql = array();
  245. $sql = array(
  246. "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[0][2])."' AND type = 'reception' AND entity = ".((int) $conf->entity),
  247. "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[0][2])."','reception',".((int) $conf->entity).")",
  248. );
  249. return $this->_init($sql, $options);
  250. }
  251. }