2011-09-21 18:40:52 +02:00
< ? php
2011-09-21 15:05:32 +02:00
/* Copyright ( C ) 2003 - 2005 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2016-02-25 02:22:40 +01:00
* Copyright ( C ) 2004 - 2016 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2011 Regis Houssin < regis . houssin @ inodbox . com >
2011-09-21 15:05:32 +02:00
* Copyright ( C ) 2011 Juanjo Menent < jmenent @ 2 byte . es >
2013-03-17 12:56:54 +01:00
* Copyright ( C ) 2013 Philippe Grand < philippe . grand @ atoo - net . com >
2011-09-21 15:05:32 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
2013-01-16 15:36:08 +01:00
* the Free Software Foundation ; either version 3 of the License , or
2011-09-21 15:05:32 +02:00
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2011-09-21 15:05:32 +02:00
*/
/**
* \defgroup expedition Module shipping
* \brief Module pour gerer les expeditions de produits
2011-10-24 14:11:49 +02:00
* \file htdocs / core / modules / modExpedition . class . php
2011-09-21 15:05:32 +02:00
* \ingroup expedition
2021-03-20 13:55:43 +01:00
* \brief Description and activation file for the module Expedition
2011-09-21 15:05:32 +02:00
*/
2019-11-28 12:36:20 +01:00
include_once DOL_DOCUMENT_ROOT . '/core/modules/DolibarrModules.class.php' ;
2011-09-21 15:05:32 +02:00
/**
2015-09-07 15:55:26 +02:00
* Class to describe and enable module Expedition
2011-09-21 15:05:32 +02:00
*/
class modExpedition extends DolibarrModules
{
/**
2011-09-26 16:22:35 +02:00
* Constructor . Define names , constants , directories , boxes , permissions
*
2012-01-04 21:23:50 +01:00
* @ param DoliDB $db Database handler
2011-09-21 15:05:32 +02:00
*/
2019-02-25 20:35:59 +01:00
public function __construct ( $db )
2011-09-21 15:05:32 +02:00
{
2016-06-06 16:21:05 +02:00
global $conf , $user ;
2012-11-18 15:24:01 +01:00
2012-01-04 21:23:50 +01:00
$this -> db = $db ;
$this -> numero = 80 ;
2011-09-21 15:05:32 +02:00
$this -> family = " crm " ;
2018-10-06 11:57:53 +02:00
$this -> module_position = '40' ;
2011-09-21 15:05:32 +02:00
// Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module)
2019-01-27 11:55:16 +01:00
$this -> name = preg_replace ( '/^mod/i' , '' , get_class ( $this ));
2011-09-21 15:05:32 +02:00
$this -> description = " Gestion des expeditions " ;
// Possible values for version are: 'development', 'experimental', 'dolibarr' or version
$this -> version = 'dolibarr' ;
$this -> const_name = 'MAIN_MODULE_' . strtoupper ( $this -> name );
2020-04-20 18:38:25 +02:00
$this -> picto = " dolly " ;
2011-09-21 15:05:32 +02:00
// Data directories to create when module is enabled
$this -> dirs = array ( " /expedition/temp " ,
" /expedition/sending " ,
2020-10-31 14:32:18 +01:00
" /expedition/sending/temp " ,
" /expedition/receipt " ,
" /expedition/receipt/temp " ,
2020-01-13 15:32:11 +01:00
" /doctemplates/shipments " ,
" /doctemplates/deliveries "
2020-10-31 14:32:18 +01:00
);
2011-09-21 15:05:32 +02:00
// Config pages
$this -> config_page_url = array ( " confexped.php " );
2015-09-07 15:29:51 +02:00
// Dependencies
2011-09-21 15:05:32 +02:00
$this -> depends = array ( " modCommande " );
$this -> requiredby = array ();
2012-11-18 15:24:01 +01:00
$this -> conflictwith = array ();
2019-11-28 12:36:20 +01:00
$this -> langfiles = array ( 'deliveries' , 'sendings' );
2011-09-21 15:05:32 +02:00
2015-09-07 15:40:55 +02:00
// Constants
2011-09-21 15:05:32 +02:00
$this -> const = array ();
2019-11-28 12:36:20 +01:00
$r = 0 ;
2016-05-17 09:02:22 +02:00
2011-09-21 15:05:32 +02:00
$this -> const [ $r ][ 0 ] = " EXPEDITION_ADDON_PDF " ;
$this -> const [ $r ][ 1 ] = " chaine " ;
$this -> const [ $r ][ 2 ] = " rouget " ;
$this -> const [ $r ][ 3 ] = 'Nom du gestionnaire de generation des bons expeditions en PDF' ;
$this -> const [ $r ][ 4 ] = 0 ;
$r ++ ;
2012-08-25 15:21:34 +02:00
$this -> const [ $r ][ 0 ] = " EXPEDITION_ADDON_NUMBER " ;
$this -> const [ $r ][ 1 ] = " chaine " ;
$this -> const [ $r ][ 2 ] = " mod_expedition_safor " ;
2017-02-07 00:54:54 +01:00
$this -> const [ $r ][ 3 ] = 'Name for numbering manager for shipments' ;
2012-08-25 15:21:34 +02:00
$this -> const [ $r ][ 4 ] = 0 ;
2011-09-21 15:05:32 +02:00
$r ++ ;
2013-08-06 13:22:00 +02:00
2013-07-10 15:54:28 +02:00
$this -> const [ $r ][ 0 ] = " EXPEDITION_ADDON_PDF_ODT_PATH " ;
$this -> const [ $r ][ 1 ] = " chaine " ;
2020-01-13 15:32:11 +01:00
$this -> const [ $r ][ 2 ] = " DOL_DATA_ROOT/doctemplates/shipments " ;
2013-07-10 15:54:28 +02:00
$this -> const [ $r ][ 3 ] = " " ;
$this -> const [ $r ][ 4 ] = 0 ;
2014-05-21 20:34:52 +02:00
$r ++ ;
2014-05-07 09:33:56 +02:00
2020-10-06 13:32:02 +02:00
$this -> const [ $r ][ 0 ] = " DELIVERY_ADDON_PDF " ;
2011-09-21 15:05:32 +02:00
$this -> const [ $r ][ 1 ] = " chaine " ;
$this -> const [ $r ][ 2 ] = " typhon " ;
$this -> const [ $r ][ 3 ] = 'Nom du gestionnaire de generation des bons de reception en PDF' ;
$this -> const [ $r ][ 4 ] = 0 ;
$r ++ ;
2020-10-06 13:32:02 +02:00
$this -> const [ $r ][ 0 ] = " DELIVERY_ADDON_NUMBER " ;
2011-09-21 15:05:32 +02:00
$this -> const [ $r ][ 1 ] = " chaine " ;
2020-10-06 13:32:02 +02:00
$this -> const [ $r ][ 2 ] = " mod_delivery_jade " ;
2011-09-21 15:05:32 +02:00
$this -> const [ $r ][ 3 ] = 'Nom du gestionnaire de numerotation des bons de reception' ;
$this -> const [ $r ][ 4 ] = 0 ;
$r ++ ;
2013-08-06 13:22:00 +02:00
2020-10-06 13:32:02 +02:00
$this -> const [ $r ][ 0 ] = " DELIVERY_ADDON_PDF_ODT_PATH " ;
2013-07-10 15:54:28 +02:00
$this -> const [ $r ][ 1 ] = " chaine " ;
2020-01-13 15:32:11 +01:00
$this -> const [ $r ][ 2 ] = " DOL_DATA_ROOT/doctemplates/deliveries " ;
2013-07-10 15:54:28 +02:00
$this -> const [ $r ][ 3 ] = " " ;
$this -> const [ $r ][ 4 ] = 0 ;
2016-02-12 12:19:32 +01:00
$r ++ ;
2016-05-17 09:02:22 +02:00
2016-02-12 12:19:32 +01:00
$this -> const [ $r ][ 0 ] = " MAIN_SUBMODULE_EXPEDITION " ;
$this -> const [ $r ][ 1 ] = " chaine " ;
$this -> const [ $r ][ 2 ] = " 1 " ;
2020-01-13 15:32:11 +01:00
$this -> const [ $r ][ 3 ] = " Enable delivery receipts " ;
2016-02-12 12:19:32 +01:00
$this -> const [ $r ][ 4 ] = 0 ;
$r ++ ;
2016-05-17 09:02:22 +02:00
2011-09-21 15:05:32 +02:00
// Boxes
2019-11-21 07:50:44 +01:00
$this -> boxes = array (
2019-11-28 12:36:20 +01:00
0 => array ( 'file' => 'box_shipments.php' , 'enabledbydefaulton' => 'Home' ),
2019-11-21 07:50:44 +01:00
);
2011-09-21 15:05:32 +02:00
// Permissions
$this -> rights = array ();
$this -> rights_class = 'expedition' ;
2019-11-28 12:36:20 +01:00
$r = 0 ;
2011-09-21 15:05:32 +02:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = 101 ;
$this -> rights [ $r ][ 1 ] = 'Lire les expeditions' ;
$this -> rights [ $r ][ 2 ] = 'r' ;
2016-06-04 12:16:30 +02:00
$this -> rights [ $r ][ 3 ] = 0 ;
2011-09-21 15:05:32 +02:00
$this -> rights [ $r ][ 4 ] = 'lire' ;
$r ++ ;
$this -> rights [ $r ][ 0 ] = 102 ;
$this -> rights [ $r ][ 1 ] = 'Creer modifier les expeditions' ;
$this -> rights [ $r ][ 2 ] = 'w' ;
$this -> rights [ $r ][ 3 ] = 0 ;
$this -> rights [ $r ][ 4 ] = 'creer' ;
$r ++ ;
$this -> rights [ $r ][ 0 ] = 104 ;
$this -> rights [ $r ][ 1 ] = 'Valider les expeditions' ;
$this -> rights [ $r ][ 2 ] = 'd' ;
$this -> rights [ $r ][ 3 ] = 0 ;
2015-01-25 21:32:40 +01:00
$this -> rights [ $r ][ 4 ] = 'shipping_advance' ;
$this -> rights [ $r ][ 5 ] = 'validate' ;
2011-09-21 15:05:32 +02:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = 105 ; // id de la permission
$this -> rights [ $r ][ 1 ] = 'Envoyer les expeditions aux clients' ; // libelle de la permission
$this -> rights [ $r ][ 2 ] = 'd' ; // type de la permission (deprecie a ce jour)
$this -> rights [ $r ][ 3 ] = 0 ; // La permission est-elle une permission par defaut
$this -> rights [ $r ][ 4 ] = 'shipping_advance' ;
2020-10-31 14:32:18 +01:00
$this -> rights [ $r ][ 5 ] = 'send' ;
2011-09-21 15:05:32 +02:00
2012-11-18 15:24:01 +01:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = 106 ;
$this -> rights [ $r ][ 1 ] = 'Exporter les expeditions' ;
$this -> rights [ $r ][ 2 ] = 'r' ;
$this -> rights [ $r ][ 3 ] = 0 ;
$this -> rights [ $r ][ 4 ] = 'shipment' ;
$this -> rights [ $r ][ 5 ] = 'export' ;
2011-09-21 15:05:32 +02:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = 109 ;
$this -> rights [ $r ][ 1 ] = 'Supprimer les expeditions' ;
$this -> rights [ $r ][ 2 ] = 'd' ;
$this -> rights [ $r ][ 3 ] = 0 ;
$this -> rights [ $r ][ 4 ] = 'supprimer' ;
$r ++ ;
$this -> rights [ $r ][ 0 ] = 1101 ;
2019-11-24 18:34:07 +01:00
$this -> rights [ $r ][ 1 ] = 'Read delivery receipts' ;
2011-09-21 15:05:32 +02:00
$this -> rights [ $r ][ 2 ] = 'r' ;
2016-06-04 12:16:30 +02:00
$this -> rights [ $r ][ 3 ] = 0 ;
2020-10-06 16:10:48 +02:00
$this -> rights [ $r ][ 4 ] = 'delivery' ;
2011-09-21 15:05:32 +02:00
$this -> rights [ $r ][ 5 ] = 'lire' ;
$r ++ ;
$this -> rights [ $r ][ 0 ] = 1102 ;
2019-11-24 18:34:07 +01:00
$this -> rights [ $r ][ 1 ] = 'Create/modify delivery receipts' ;
2011-09-21 15:05:32 +02:00
$this -> rights [ $r ][ 2 ] = 'w' ;
$this -> rights [ $r ][ 3 ] = 0 ;
2020-10-06 16:10:48 +02:00
$this -> rights [ $r ][ 4 ] = 'delivery' ;
2011-09-21 15:05:32 +02:00
$this -> rights [ $r ][ 5 ] = 'creer' ;
$r ++ ;
$this -> rights [ $r ][ 0 ] = 1104 ;
2019-11-24 18:34:07 +01:00
$this -> rights [ $r ][ 1 ] = 'Validate delivery receipts' ;
2011-09-21 15:05:32 +02:00
$this -> rights [ $r ][ 2 ] = 'd' ;
$this -> rights [ $r ][ 3 ] = 0 ;
2020-10-06 16:10:48 +02:00
$this -> rights [ $r ][ 4 ] = 'delivery_advance' ;
2015-01-25 21:32:40 +01:00
$this -> rights [ $r ][ 5 ] = 'validate' ;
2011-09-21 15:05:32 +02:00
$r ++ ;
$this -> rights [ $r ][ 0 ] = 1109 ;
2019-11-24 18:34:07 +01:00
$this -> rights [ $r ][ 1 ] = 'Delete delivery receipts' ;
2011-09-21 15:05:32 +02:00
$this -> rights [ $r ][ 2 ] = 'd' ;
$this -> rights [ $r ][ 3 ] = 0 ;
2020-10-06 16:10:48 +02:00
$this -> rights [ $r ][ 4 ] = 'delivery' ;
2011-09-21 15:05:32 +02:00
$this -> rights [ $r ][ 5 ] = 'supprimer' ;
2016-09-30 13:02:13 +02:00
// Menus
//-------
2019-11-28 12:36:20 +01:00
$this -> menu = 1 ; // This module add menu entries. They are coded into menu manager.
2018-02-25 10:55:02 +01:00
2012-11-20 12:11:19 +01:00
// Exports
//--------
2019-11-28 12:36:20 +01:00
$r = 0 ;
2012-11-20 12:11:19 +01:00
2016-02-25 15:46:14 +01:00
include_once DOL_DOCUMENT_ROOT . '/commande/class/commande.class.php' ;
2019-11-28 12:36:20 +01:00
$shipment = new Commande ( $this -> db );
$contact_arrays = $shipment -> liste_type_contact ( 'external' , '' , 0 , 0 , '' );
if ( is_array ( $contact_arrays ) && count ( $contact_arrays ) > 0 ) {
$idcontacts = join ( ',' , array_keys ( $shipment -> liste_type_contact ( 'external' , '' , 0 , 0 , '' )));
2016-05-17 09:02:22 +02:00
} else {
2019-11-28 12:36:20 +01:00
$idcontacts = 0 ;
2016-05-17 09:02:22 +02:00
}
2012-11-20 12:11:19 +01:00
$r ++ ;
2019-11-28 12:36:20 +01:00
$this -> export_code [ $r ] = $this -> rights_class . '_' . $r ;
$this -> export_label [ $r ] = 'Shipments' ; // Translation key (used only if key ExportDataset_xxx_z not found)
$this -> export_permission [ $r ] = array ( array ( " expedition " , " shipment " , " export " ));
$this -> export_fields_array [ $r ] = array (
's.rowid' => " IdCompany " , 's.nom' => 'ThirdParty' , 's.address' => 'Address' , 's.zip' => 'Zip' , 's.town' => 'Town' , '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' , 'c.rowid' => " Id " , 'c.ref' => " Ref " , 'c.ref_customer' => " RefCustomer " , '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' , 'cd.description' => 'Description' , 'ed.qty' => " Qty " , 'p.rowid' => 'ProductId' , 'p.ref' => 'ProductRef' , 'p.label' => 'ProductLabel' ,
'p.weight' => 'ProductWeight' , 'p.weight_units' => 'WeightUnits' , 'p.volume' => 'ProductVolume' , 'p.volume_units' => 'VolumeUnits'
2018-05-27 15:04:12 +02:00
);
2021-02-23 22:03:23 +01:00
if ( $idcontacts && ! empty ( $conf -> global -> SHIPMENT_ADD_CONTACTS_IN_EXPORT )) {
$this -> export_fields_array [ $r ] += array ( 'sp.rowid' => 'IdContact' , 'sp.lastname' => 'Lastname' , 'sp.firstname' => 'Firstname' , 'sp.note_public' => 'NotePublic' );
}
2018-05-27 15:04:12 +02:00
//$this->export_TypeFields_array[$r]=array(
// 's.rowid'=>"List:societe:nom",'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"
//);
2019-11-28 12:36:20 +01:00
$this -> export_TypeFields_array [ $r ] = array (
'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_customer' => " 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 " , 'ed.qty' => " Numeric " , 'd.nom' => 'Text'
2018-05-27 15:04:12 +02:00
);
2019-11-28 12:36:20 +01:00
$this -> export_entities_array [ $r ] = array (
's.rowid' => " company " , 's.nom' => 'company' , 's.address' => 'company' , 's.zip' => 'company' , 's.town' => 'company' , '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' , 'c.rowid' => " shipment " , 'c.ref' => " shipment " , 'c.ref_customer' => " shipment " , 'c.fk_soc' => " shipment " ,
'c.date_creation' => " shipment " , 'c.date_delivery' => " shipment " , 'c.tracking_number' => 'shipment' , 'c.height' => " shipment " , 'c.width' => " shipment " ,
'c.size' => 'shipment' , 'c.size_units' => 'shipment' , 'c.weight' => " shipment " , 'c.weight_units' => 'shipment' , 'c.fk_statut' => " shipment " , 'c.note_public' => " shipment " ,
'ed.rowid' => 'shipment_line' , 'cd.description' => 'shipment_line' , 'ed.qty' => " shipment_line " , 'p.rowid' => 'product' , 'p.ref' => 'product' , 'p.label' => 'product' ,
'p.weight' => 'product' , 'p.weight_units' => 'product' , 'p.volume' => 'product' , 'p.volume_units' => 'product'
2018-05-27 15:04:12 +02:00
);
2021-02-23 22:03:23 +01:00
if ( $idcontacts && ! empty ( $conf -> global -> SHIPMENT_ADD_CONTACTS_IN_EXPORT )) {
$this -> export_entities_array [ $r ] += array ( 'sp.rowid' => 'contact' , 'sp.lastname' => 'contact' , 'sp.firstname' => 'contact' , 'sp.note_public' => 'contact' );
}
2019-11-28 12:36:20 +01:00
$this -> export_dependencies_array [ $r ] = array ( 'shipment_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
2021-02-23 22:03:23 +01:00
if ( $idcontacts && ! empty ( $conf -> global -> SHIPMENT_ADD_CONTACTS_IN_EXPORT )) {
2021-03-01 20:37:16 +01:00
$keyforselect = 'socpeople' ;
$keyforelement = 'contact' ;
$keyforaliasextra = 'extra3' ;
2020-10-31 14:32:18 +01:00
include DOL_DOCUMENT_ROOT . '/core/extrafieldsinexport.inc.php' ;
2016-02-25 15:46:14 +01:00
}
2021-03-01 20:37:16 +01:00
$keyforselect = 'expedition' ;
$keyforelement = 'shipment' ;
$keyforaliasextra = 'extra' ;
2016-02-25 15:46:14 +01:00
include DOL_DOCUMENT_ROOT . '/core/extrafieldsinexport.inc.php' ;
2021-03-01 20:37:16 +01:00
$keyforselect = 'expeditiondet' ;
$keyforelement = 'shipment_line' ;
$keyforaliasextra = 'extra2' ;
2016-02-25 15:46:14 +01:00
include DOL_DOCUMENT_ROOT . '/core/extrafieldsinexport.inc.php' ;
2021-03-01 20:37:16 +01:00
$keyforselect = 'product' ;
$keyforelement = 'product' ;
$keyforaliasextra = 'extraprod' ;
2019-03-07 15:00:48 +01:00
include DOL_DOCUMENT_ROOT . '/core/extrafieldsinexport.inc.php' ;
2012-11-20 12:11:19 +01:00
2019-11-28 12:36:20 +01:00
$this -> export_sql_start [ $r ] = 'SELECT DISTINCT ' ;
$this -> export_sql_end [ $r ] = ' FROM ' . MAIN_DB_PREFIX . 'expedition as c' ;
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'expedition_extrafields as extra ON c.rowid = extra.fk_object,' ;
$this -> export_sql_end [ $r ] .= ' ' . MAIN_DB_PREFIX . 'societe as s' ;
2021-02-23 22:03:23 +01:00
if ( empty ( $user -> rights -> societe -> client -> voir )) {
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'societe_commerciaux as sc ON sc.fk_soc = s.rowid' ;
}
2019-11-28 12:36:20 +01:00
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_departements as d ON s.fk_departement = d.rowid' ;
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'c_country as co ON s.fk_pays = co.rowid,' ;
$this -> export_sql_end [ $r ] .= ' ' . MAIN_DB_PREFIX . 'expeditiondet as ed' ;
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'expeditiondet_extrafields as extra2 ON ed.rowid = extra2.fk_object' ;
$this -> export_sql_end [ $r ] .= ' , ' . MAIN_DB_PREFIX . 'commandedet as cd' ;
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product as p on cd.fk_product = p.rowid' ;
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product_extrafields as extraprod ON p.rowid = extraprod.fk_object' ;
if ( $idcontacts && ! empty ( $conf -> global -> SHIPMENT_ADD_CONTACTS_IN_EXPORT )) {
2021-03-22 12:00:41 +01:00
$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 ) . ')' ;
2020-10-31 14:32:18 +01:00
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'socpeople as sp ON sp.rowid = ee.fk_socpeople' ;
$this -> export_sql_end [ $r ] .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'socpeople_extrafields as extra3 ON sp.rowid = extra3.fk_object' ;
2016-02-25 15:46:14 +01:00
}
2019-11-28 12:36:20 +01:00
$this -> export_sql_end [ $r ] .= ' WHERE c.fk_soc = s.rowid AND c.rowid = ed.fk_expedition AND ed.fk_origin_line = cd.rowid' ;
$this -> export_sql_end [ $r ] .= ' AND c.entity IN (' . getEntity ( 'expedition' ) . ')' ;
2021-02-23 22:03:23 +01:00
if ( empty ( $user -> rights -> societe -> client -> voir )) {
$this -> export_sql_end [ $r ] .= ' AND sc.fk_user = ' . ( empty ( $user ) ? 0 : $user -> id );
}
2011-09-21 15:05:32 +02:00
}
/**
2019-02-26 21:13:07 +01:00
* Function called when module is enabled .
* The init function add constants , boxes , permissions and menus ( defined in constructor ) into Dolibarr database .
* It also creates data directories
2012-01-04 21:23:50 +01:00
*
2020-10-31 14:32:18 +01:00
* @ param string $options Options when enabling module ( '' , 'noboxes' )
2019-02-26 21:13:07 +01:00
* @ return int 1 if OK , 0 if KO
2011-09-21 15:05:32 +02:00
*/
2019-02-26 21:13:07 +01:00
public function init ( $options = '' )
2011-09-21 15:05:32 +02:00
{
2019-11-28 12:36:20 +01:00
global $conf , $langs ;
2011-09-21 15:05:32 +02:00
// Permissions
2012-03-03 17:37:45 +01:00
$this -> remove ( $options );
2013-08-06 13:22:00 +02:00
2013-07-10 15:54:28 +02:00
//ODT template
2020-01-13 15:32:11 +01:00
$src = DOL_DOCUMENT_ROOT . '/install/doctemplates/shipments/template_shipment.odt' ;
$dirodt = DOL_DATA_ROOT . '/doctemplates/shipments' ;
2019-11-28 12:36:20 +01:00
$dest = $dirodt . '/template_shipment.odt' ;
2013-07-10 15:54:28 +02:00
2021-02-23 22:03:23 +01:00
if ( file_exists ( $src ) && ! file_exists ( $dest )) {
2013-07-10 15:54:28 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php' ;
dol_mkdir ( $dirodt );
2019-11-28 12:36:20 +01:00
$result = dol_copy ( $src , $dest , 0 , 0 );
2021-02-23 22:03:23 +01:00
if ( $result < 0 ) {
2013-07-10 15:54:28 +02:00
$langs -> load ( " errors " );
2019-11-28 12:36:20 +01:00
$this -> error = $langs -> trans ( 'ErrorFailToCopyFile' , $src , $dest );
2013-07-10 15:54:28 +02:00
return 0 ;
}
}
2011-09-21 15:05:32 +02:00
$sql = array ();
$sql = array (
2021-08-27 22:42:04 +02:00
" DELETE FROM " . MAIN_DB_PREFIX . " document_model WHERE nom = ' " . $this -> db -> escape ( $this -> const [ 0 ][ 2 ]) . " ' AND type = 'shipping' AND entity = " . (( int ) $conf -> entity ),
" INSERT INTO " . MAIN_DB_PREFIX . " document_model (nom, type, entity) VALUES(' " . $this -> db -> escape ( $this -> const [ 0 ][ 2 ]) . " ','shipping', " . (( int ) $conf -> entity ) . " ) " ,
" DELETE FROM " . MAIN_DB_PREFIX . " document_model WHERE nom = ' " . $this -> db -> escape ( $this -> const [ 3 ][ 2 ]) . " ' AND type = 'delivery' AND entity = " . (( int ) $conf -> entity ),
" INSERT INTO " . MAIN_DB_PREFIX . " document_model (nom, type, entity) VALUES(' " . $this -> db -> escape ( $this -> const [ 3 ][ 2 ]) . " ','delivery', " . (( int ) $conf -> entity ) . " ) " ,
2011-09-21 15:05:32 +02:00
);
2019-01-27 11:55:16 +01:00
return $this -> _init ( $sql , $options );
2011-09-21 15:05:32 +02:00
}
}