@@ -37,32 +37,32 @@ discard block |
||
37 | 37 | */ |
38 | 38 | abstract class ModelePDFFactures extends CommonDocGenerator |
39 | 39 | { |
40 | - /** |
|
41 | - * @var string Error code (or message) |
|
42 | - */ |
|
43 | - public $error=''; |
|
40 | + /** |
|
41 | + * @var string Error code (or message) |
|
42 | + */ |
|
43 | + public $error=''; |
|
44 | 44 | |
45 | 45 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
46 | - /** |
|
47 | - * Return list of active generation modules |
|
48 | - * |
|
46 | + /** |
|
47 | + * Return list of active generation modules |
|
48 | + * |
|
49 | 49 | * @param DoliDB $db Database handler |
50 | 50 | * @param integer $maxfilenamelength Max length of value to show |
51 | 51 | * @return array List of templates |
52 | - */ |
|
53 | - static function liste_modeles($db,$maxfilenamelength=0) |
|
54 | - { |
|
52 | + */ |
|
53 | + static function liste_modeles($db,$maxfilenamelength=0) |
|
54 | + { |
|
55 | 55 | // phpcs:enable |
56 | - global $conf; |
|
56 | + global $conf; |
|
57 | 57 | |
58 | - $type='invoice'; |
|
59 | - $liste=array(); |
|
58 | + $type='invoice'; |
|
59 | + $liste=array(); |
|
60 | 60 | |
61 | - include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; |
|
62 | - $liste=getListOfModels($db,$type,$maxfilenamelength); |
|
61 | + include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; |
|
62 | + $liste=getListOfModels($db,$type,$maxfilenamelength); |
|
63 | 63 | |
64 | - return $liste; |
|
65 | - } |
|
64 | + return $liste; |
|
65 | + } |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | /** |
@@ -70,83 +70,83 @@ discard block |
||
70 | 70 | */ |
71 | 71 | abstract class ModeleNumRefFactures |
72 | 72 | { |
73 | - /** |
|
74 | - * @var string Error code (or message) |
|
75 | - */ |
|
76 | - public $error=''; |
|
77 | - |
|
78 | - /** |
|
79 | - * Return if a module can be used or not |
|
80 | - * |
|
81 | - * @return boolean true if module can be used |
|
82 | - */ |
|
83 | - function isEnabled() |
|
84 | - { |
|
85 | - return true; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Renvoi la description par defaut du modele de numerotation |
|
90 | - * |
|
91 | - * @return string Texte descripif |
|
92 | - */ |
|
93 | - function info() |
|
94 | - { |
|
95 | - global $langs; |
|
96 | - $langs->load("bills"); |
|
97 | - return $langs->trans("NoDescription"); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Renvoi un exemple de numerotation |
|
102 | - * |
|
103 | - * @return string Example |
|
104 | - */ |
|
105 | - function getExample() |
|
106 | - { |
|
107 | - global $langs; |
|
108 | - $langs->load("bills"); |
|
109 | - return $langs->trans("NoExample"); |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Test si les numeros deja en vigueur dans la base ne provoquent pas |
|
114 | - * de conflits qui empecheraient cette numerotation de fonctionner. |
|
115 | - * |
|
116 | - * @return boolean false si conflit, true si ok |
|
117 | - */ |
|
118 | - function canBeActivated() |
|
119 | - { |
|
120 | - return true; |
|
121 | - } |
|
122 | - |
|
123 | - /** |
|
124 | - * Renvoi prochaine valeur attribuee |
|
125 | - * |
|
126 | - * @param Societe $objsoc Objet societe |
|
127 | - * @param Facture $facture Objet facture |
|
128 | - * @return string Value |
|
129 | - */ |
|
130 | - function getNextValue($objsoc,$facture) |
|
131 | - { |
|
132 | - global $langs; |
|
133 | - return $langs->trans("NotAvailable"); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Renvoi version du modele de numerotation |
|
138 | - * |
|
139 | - * @return string Valeur |
|
140 | - */ |
|
141 | - function getVersion() |
|
142 | - { |
|
143 | - global $langs; |
|
144 | - $langs->load("admin"); |
|
145 | - |
|
146 | - if ($this->version == 'development') return $langs->trans("VersionDevelopment"); |
|
147 | - if ($this->version == 'experimental') return $langs->trans("VersionExperimental"); |
|
148 | - if ($this->version == 'dolibarr') return DOL_VERSION; |
|
149 | - if ($this->version) return $this->version; |
|
150 | - return $langs->trans("NotAvailable"); |
|
151 | - } |
|
73 | + /** |
|
74 | + * @var string Error code (or message) |
|
75 | + */ |
|
76 | + public $error=''; |
|
77 | + |
|
78 | + /** |
|
79 | + * Return if a module can be used or not |
|
80 | + * |
|
81 | + * @return boolean true if module can be used |
|
82 | + */ |
|
83 | + function isEnabled() |
|
84 | + { |
|
85 | + return true; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Renvoi la description par defaut du modele de numerotation |
|
90 | + * |
|
91 | + * @return string Texte descripif |
|
92 | + */ |
|
93 | + function info() |
|
94 | + { |
|
95 | + global $langs; |
|
96 | + $langs->load("bills"); |
|
97 | + return $langs->trans("NoDescription"); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Renvoi un exemple de numerotation |
|
102 | + * |
|
103 | + * @return string Example |
|
104 | + */ |
|
105 | + function getExample() |
|
106 | + { |
|
107 | + global $langs; |
|
108 | + $langs->load("bills"); |
|
109 | + return $langs->trans("NoExample"); |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Test si les numeros deja en vigueur dans la base ne provoquent pas |
|
114 | + * de conflits qui empecheraient cette numerotation de fonctionner. |
|
115 | + * |
|
116 | + * @return boolean false si conflit, true si ok |
|
117 | + */ |
|
118 | + function canBeActivated() |
|
119 | + { |
|
120 | + return true; |
|
121 | + } |
|
122 | + |
|
123 | + /** |
|
124 | + * Renvoi prochaine valeur attribuee |
|
125 | + * |
|
126 | + * @param Societe $objsoc Objet societe |
|
127 | + * @param Facture $facture Objet facture |
|
128 | + * @return string Value |
|
129 | + */ |
|
130 | + function getNextValue($objsoc,$facture) |
|
131 | + { |
|
132 | + global $langs; |
|
133 | + return $langs->trans("NotAvailable"); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Renvoi version du modele de numerotation |
|
138 | + * |
|
139 | + * @return string Valeur |
|
140 | + */ |
|
141 | + function getVersion() |
|
142 | + { |
|
143 | + global $langs; |
|
144 | + $langs->load("admin"); |
|
145 | + |
|
146 | + if ($this->version == 'development') return $langs->trans("VersionDevelopment"); |
|
147 | + if ($this->version == 'experimental') return $langs->trans("VersionExperimental"); |
|
148 | + if ($this->version == 'dolibarr') return DOL_VERSION; |
|
149 | + if ($this->version) return $this->version; |
|
150 | + return $langs->trans("NotAvailable"); |
|
151 | + } |
|
152 | 152 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | |
30 | 30 | require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php'; |
31 | 31 | require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; |
32 | -require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; // Requis car utilise dans les classes qui heritent |
|
32 | +require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; // Requis car utilise dans les classes qui heritent |
|
33 | 33 | |
34 | 34 | |
35 | 35 | /** |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | /** |
41 | 41 | * @var string Error code (or message) |
42 | 42 | */ |
43 | - public $error=''; |
|
43 | + public $error = ''; |
|
44 | 44 | |
45 | 45 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
46 | 46 | /** |
@@ -50,16 +50,16 @@ discard block |
||
50 | 50 | * @param integer $maxfilenamelength Max length of value to show |
51 | 51 | * @return array List of templates |
52 | 52 | */ |
53 | - static function liste_modeles($db,$maxfilenamelength=0) |
|
53 | + static function liste_modeles($db, $maxfilenamelength = 0) |
|
54 | 54 | { |
55 | 55 | // phpcs:enable |
56 | 56 | global $conf; |
57 | 57 | |
58 | - $type='invoice'; |
|
59 | - $liste=array(); |
|
58 | + $type = 'invoice'; |
|
59 | + $liste = array(); |
|
60 | 60 | |
61 | 61 | include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; |
62 | - $liste=getListOfModels($db,$type,$maxfilenamelength); |
|
62 | + $liste = getListOfModels($db, $type, $maxfilenamelength); |
|
63 | 63 | |
64 | 64 | return $liste; |
65 | 65 | } |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | /** |
74 | 74 | * @var string Error code (or message) |
75 | 75 | */ |
76 | - public $error=''; |
|
76 | + public $error = ''; |
|
77 | 77 | |
78 | 78 | /** |
79 | 79 | * Return if a module can be used or not |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | * @param Facture $facture Objet facture |
128 | 128 | * @return string Value |
129 | 129 | */ |
130 | - function getNextValue($objsoc,$facture) |
|
130 | + function getNextValue($objsoc, $facture) |
|
131 | 131 | { |
132 | 132 | global $langs; |
133 | 133 | return $langs->trans("NotAvailable"); |
@@ -142,10 +142,18 @@ |
||
142 | 142 | global $langs; |
143 | 143 | $langs->load("admin"); |
144 | 144 | |
145 | - if ($this->version == 'development') return $langs->trans("VersionDevelopment"); |
|
146 | - if ($this->version == 'experimental') return $langs->trans("VersionExperimental"); |
|
147 | - if ($this->version == 'dolibarr') return DOL_VERSION; |
|
148 | - if ($this->version) return $this->version; |
|
145 | + if ($this->version == 'development') { |
|
146 | + return $langs->trans("VersionDevelopment"); |
|
147 | + } |
|
148 | + if ($this->version == 'experimental') { |
|
149 | + return $langs->trans("VersionExperimental"); |
|
150 | + } |
|
151 | + if ($this->version == 'dolibarr') { |
|
152 | + return DOL_VERSION; |
|
153 | + } |
|
154 | + if ($this->version) { |
|
155 | + return $this->version; |
|
156 | + } |
|
149 | 157 | return $langs->trans("NotAvailable"); |
150 | 158 | } |
151 | 159 | } |
@@ -29,176 +29,176 @@ discard block |
||
29 | 29 | */ |
30 | 30 | class mod_facture_terre extends ModeleNumRefFactures |
31 | 31 | { |
32 | - /** |
|
32 | + /** |
|
33 | 33 | * Dolibarr version of the loaded document |
34 | 34 | * @public string |
35 | 35 | */ |
36 | - public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' |
|
37 | - |
|
38 | - public $prefixinvoice='FA'; |
|
39 | - |
|
40 | - public $prefixcreditnote='AV'; |
|
41 | - |
|
42 | - public $prefixdeposit='AC'; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var string Error code (or message) |
|
46 | - */ |
|
47 | - public $error=''; |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * Constructor |
|
52 | - */ |
|
53 | - function __construct() |
|
54 | - { |
|
55 | - if (! empty($conf->global->INVOICE_NUMBERING_TERRE_FORCE_PREFIX)) |
|
56 | - { |
|
57 | - $this->prefixinvoice = $conf->global->INVOICE_NUMBERING_TERRE_FORCE_PREFIX; |
|
58 | - } |
|
59 | - } |
|
60 | - |
|
61 | - /** |
|
62 | - * Renvoi la description du modele de numerotation |
|
63 | - * |
|
64 | - * @return string Texte descripif |
|
65 | - */ |
|
66 | - function info() |
|
67 | - { |
|
68 | - global $langs; |
|
69 | - $langs->load("bills"); |
|
70 | - return $langs->trans('TerreNumRefModelDesc1',$this->prefixinvoice,$this->prefixcreditnote,$this->prefixdeposit); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * Renvoi un exemple de numerotation |
|
75 | - * |
|
76 | - * @return string Example |
|
77 | - */ |
|
78 | - function getExample() |
|
79 | - { |
|
80 | - return $this->prefixinvoice."0501-0001"; |
|
81 | - } |
|
82 | - |
|
83 | - /** |
|
84 | - * Test si les numeros deja en vigueur dans la base ne provoquent pas de |
|
85 | - * de conflits qui empechera cette numerotation de fonctionner. |
|
86 | - * |
|
87 | - * @return boolean false si conflit, true si ok |
|
88 | - */ |
|
89 | - function canBeActivated() |
|
90 | - { |
|
91 | - global $langs,$conf,$db; |
|
92 | - |
|
93 | - $langs->load("bills"); |
|
94 | - |
|
95 | - // Check invoice num |
|
96 | - $fayymm=''; $max=''; |
|
97 | - |
|
98 | - $posindice=8; |
|
99 | - $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL |
|
100 | - $sql.= " FROM ".MAIN_DB_PREFIX."facture"; |
|
101 | - $sql.= " WHERE ref LIKE '".$db->escape($this->prefixinvoice)."____-%'"; |
|
102 | - $sql.= " AND entity = ".$conf->entity; |
|
103 | - |
|
104 | - $resql=$db->query($sql); |
|
105 | - if ($resql) |
|
106 | - { |
|
107 | - $row = $db->fetch_row($resql); |
|
108 | - if ($row) { $fayymm = substr($row[0],0,6); $max=$row[0]; } |
|
109 | - } |
|
110 | - if ($fayymm && ! preg_match('/'.$this->prefixinvoice.'[0-9][0-9][0-9][0-9]/i',$fayymm)) |
|
111 | - { |
|
112 | - $langs->load("errors"); |
|
113 | - $this->error=$langs->trans('ErrorNumRefModel',$max); |
|
114 | - return false; |
|
115 | - } |
|
116 | - |
|
117 | - // Check credit note num |
|
118 | - $fayymm=''; |
|
119 | - |
|
120 | - $posindice=8; |
|
121 | - $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL |
|
122 | - $sql.= " FROM ".MAIN_DB_PREFIX."facture"; |
|
123 | - $sql.= " WHERE ref LIKE '".$db->escape($this->prefixcreditnote)."____-%'"; |
|
124 | - $sql.= " AND entity = ".$conf->entity; |
|
125 | - |
|
126 | - $resql=$db->query($sql); |
|
127 | - if ($resql) |
|
128 | - { |
|
129 | - $row = $db->fetch_row($resql); |
|
130 | - if ($row) { $fayymm = substr($row[0],0,6); $max=$row[0]; } |
|
131 | - } |
|
132 | - if ($fayymm && ! preg_match('/'.$this->prefixcreditnote.'[0-9][0-9][0-9][0-9]/i',$fayymm)) |
|
133 | - { |
|
134 | - $this->error=$langs->trans('ErrorNumRefModel',$max); |
|
135 | - return false; |
|
136 | - } |
|
137 | - |
|
138 | - // Check deposit num |
|
139 | - $fayymm=''; |
|
140 | - |
|
141 | - $posindice=8; |
|
142 | - $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL |
|
143 | - $sql.= " FROM ".MAIN_DB_PREFIX."facture"; |
|
144 | - $sql.= " WHERE ref LIKE '".$db->escape($this->prefixdeposit)."____-%'"; |
|
145 | - $sql.= " AND entity = ".$conf->entity; |
|
146 | - |
|
147 | - $resql=$db->query($sql); |
|
148 | - if ($resql) |
|
149 | - { |
|
150 | - $row = $db->fetch_row($resql); |
|
151 | - if ($row) { $fayymm = substr($row[0],0,6); $max=$row[0]; } |
|
152 | - } |
|
153 | - if ($fayymm && ! preg_match('/'.$this->prefixdeposit.'[0-9][0-9][0-9][0-9]/i',$fayymm)) |
|
154 | - { |
|
155 | - $this->error=$langs->trans('ErrorNumRefModel',$max); |
|
156 | - return false; |
|
157 | - } |
|
158 | - |
|
159 | - return true; |
|
160 | - } |
|
161 | - |
|
162 | - /** |
|
163 | - * Return next value not used or last value used |
|
164 | - * |
|
165 | - * @param Societe $objsoc Object third party |
|
166 | - * @param Facture $invoice Object invoice |
|
36 | + public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' |
|
37 | + |
|
38 | + public $prefixinvoice='FA'; |
|
39 | + |
|
40 | + public $prefixcreditnote='AV'; |
|
41 | + |
|
42 | + public $prefixdeposit='AC'; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var string Error code (or message) |
|
46 | + */ |
|
47 | + public $error=''; |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * Constructor |
|
52 | + */ |
|
53 | + function __construct() |
|
54 | + { |
|
55 | + if (! empty($conf->global->INVOICE_NUMBERING_TERRE_FORCE_PREFIX)) |
|
56 | + { |
|
57 | + $this->prefixinvoice = $conf->global->INVOICE_NUMBERING_TERRE_FORCE_PREFIX; |
|
58 | + } |
|
59 | + } |
|
60 | + |
|
61 | + /** |
|
62 | + * Renvoi la description du modele de numerotation |
|
63 | + * |
|
64 | + * @return string Texte descripif |
|
65 | + */ |
|
66 | + function info() |
|
67 | + { |
|
68 | + global $langs; |
|
69 | + $langs->load("bills"); |
|
70 | + return $langs->trans('TerreNumRefModelDesc1',$this->prefixinvoice,$this->prefixcreditnote,$this->prefixdeposit); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * Renvoi un exemple de numerotation |
|
75 | + * |
|
76 | + * @return string Example |
|
77 | + */ |
|
78 | + function getExample() |
|
79 | + { |
|
80 | + return $this->prefixinvoice."0501-0001"; |
|
81 | + } |
|
82 | + |
|
83 | + /** |
|
84 | + * Test si les numeros deja en vigueur dans la base ne provoquent pas de |
|
85 | + * de conflits qui empechera cette numerotation de fonctionner. |
|
86 | + * |
|
87 | + * @return boolean false si conflit, true si ok |
|
88 | + */ |
|
89 | + function canBeActivated() |
|
90 | + { |
|
91 | + global $langs,$conf,$db; |
|
92 | + |
|
93 | + $langs->load("bills"); |
|
94 | + |
|
95 | + // Check invoice num |
|
96 | + $fayymm=''; $max=''; |
|
97 | + |
|
98 | + $posindice=8; |
|
99 | + $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL |
|
100 | + $sql.= " FROM ".MAIN_DB_PREFIX."facture"; |
|
101 | + $sql.= " WHERE ref LIKE '".$db->escape($this->prefixinvoice)."____-%'"; |
|
102 | + $sql.= " AND entity = ".$conf->entity; |
|
103 | + |
|
104 | + $resql=$db->query($sql); |
|
105 | + if ($resql) |
|
106 | + { |
|
107 | + $row = $db->fetch_row($resql); |
|
108 | + if ($row) { $fayymm = substr($row[0],0,6); $max=$row[0]; } |
|
109 | + } |
|
110 | + if ($fayymm && ! preg_match('/'.$this->prefixinvoice.'[0-9][0-9][0-9][0-9]/i',$fayymm)) |
|
111 | + { |
|
112 | + $langs->load("errors"); |
|
113 | + $this->error=$langs->trans('ErrorNumRefModel',$max); |
|
114 | + return false; |
|
115 | + } |
|
116 | + |
|
117 | + // Check credit note num |
|
118 | + $fayymm=''; |
|
119 | + |
|
120 | + $posindice=8; |
|
121 | + $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL |
|
122 | + $sql.= " FROM ".MAIN_DB_PREFIX."facture"; |
|
123 | + $sql.= " WHERE ref LIKE '".$db->escape($this->prefixcreditnote)."____-%'"; |
|
124 | + $sql.= " AND entity = ".$conf->entity; |
|
125 | + |
|
126 | + $resql=$db->query($sql); |
|
127 | + if ($resql) |
|
128 | + { |
|
129 | + $row = $db->fetch_row($resql); |
|
130 | + if ($row) { $fayymm = substr($row[0],0,6); $max=$row[0]; } |
|
131 | + } |
|
132 | + if ($fayymm && ! preg_match('/'.$this->prefixcreditnote.'[0-9][0-9][0-9][0-9]/i',$fayymm)) |
|
133 | + { |
|
134 | + $this->error=$langs->trans('ErrorNumRefModel',$max); |
|
135 | + return false; |
|
136 | + } |
|
137 | + |
|
138 | + // Check deposit num |
|
139 | + $fayymm=''; |
|
140 | + |
|
141 | + $posindice=8; |
|
142 | + $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL |
|
143 | + $sql.= " FROM ".MAIN_DB_PREFIX."facture"; |
|
144 | + $sql.= " WHERE ref LIKE '".$db->escape($this->prefixdeposit)."____-%'"; |
|
145 | + $sql.= " AND entity = ".$conf->entity; |
|
146 | + |
|
147 | + $resql=$db->query($sql); |
|
148 | + if ($resql) |
|
149 | + { |
|
150 | + $row = $db->fetch_row($resql); |
|
151 | + if ($row) { $fayymm = substr($row[0],0,6); $max=$row[0]; } |
|
152 | + } |
|
153 | + if ($fayymm && ! preg_match('/'.$this->prefixdeposit.'[0-9][0-9][0-9][0-9]/i',$fayymm)) |
|
154 | + { |
|
155 | + $this->error=$langs->trans('ErrorNumRefModel',$max); |
|
156 | + return false; |
|
157 | + } |
|
158 | + |
|
159 | + return true; |
|
160 | + } |
|
161 | + |
|
162 | + /** |
|
163 | + * Return next value not used or last value used |
|
164 | + * |
|
165 | + * @param Societe $objsoc Object third party |
|
166 | + * @param Facture $invoice Object invoice |
|
167 | 167 | * @param string $mode 'next' for next value or 'last' for last value |
168 | - * @return string Value |
|
169 | - */ |
|
170 | - function getNextValue($objsoc, $invoice, $mode='next') |
|
171 | - { |
|
172 | - global $db; |
|
173 | - |
|
174 | - if ($invoice->type == 2) $prefix=$this->prefixcreditnote; |
|
175 | - else if ($invoice->type == 3) $prefix=$this->prefixdeposit; |
|
176 | - else $prefix=$this->prefixinvoice; |
|
177 | - |
|
178 | - // D'abord on recupere la valeur max |
|
179 | - $posindice=8; |
|
180 | - $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL |
|
181 | - $sql.= " FROM ".MAIN_DB_PREFIX."facture"; |
|
182 | - $sql.= " WHERE ref LIKE '".$prefix."____-%'"; |
|
183 | - $sql.= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")"; |
|
184 | - |
|
185 | - $resql=$db->query($sql); |
|
186 | - dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG); |
|
187 | - if ($resql) |
|
188 | - { |
|
189 | - $obj = $db->fetch_object($resql); |
|
190 | - if ($obj) $max = intval($obj->max); |
|
191 | - else $max=0; |
|
192 | - } |
|
193 | - else |
|
194 | - { |
|
195 | - return -1; |
|
196 | - } |
|
197 | - |
|
198 | - if ($mode == 'last') |
|
199 | - { |
|
200 | - if ($max >= (pow(10, 4) - 1)) $num=$max; // If counter > 9999, we do not format on 4 chars, we take number as it is |
|
201 | - else $num = sprintf("%04s",$max); |
|
168 | + * @return string Value |
|
169 | + */ |
|
170 | + function getNextValue($objsoc, $invoice, $mode='next') |
|
171 | + { |
|
172 | + global $db; |
|
173 | + |
|
174 | + if ($invoice->type == 2) $prefix=$this->prefixcreditnote; |
|
175 | + else if ($invoice->type == 3) $prefix=$this->prefixdeposit; |
|
176 | + else $prefix=$this->prefixinvoice; |
|
177 | + |
|
178 | + // D'abord on recupere la valeur max |
|
179 | + $posindice=8; |
|
180 | + $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL |
|
181 | + $sql.= " FROM ".MAIN_DB_PREFIX."facture"; |
|
182 | + $sql.= " WHERE ref LIKE '".$prefix."____-%'"; |
|
183 | + $sql.= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")"; |
|
184 | + |
|
185 | + $resql=$db->query($sql); |
|
186 | + dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG); |
|
187 | + if ($resql) |
|
188 | + { |
|
189 | + $obj = $db->fetch_object($resql); |
|
190 | + if ($obj) $max = intval($obj->max); |
|
191 | + else $max=0; |
|
192 | + } |
|
193 | + else |
|
194 | + { |
|
195 | + return -1; |
|
196 | + } |
|
197 | + |
|
198 | + if ($mode == 'last') |
|
199 | + { |
|
200 | + if ($max >= (pow(10, 4) - 1)) $num=$max; // If counter > 9999, we do not format on 4 chars, we take number as it is |
|
201 | + else $num = sprintf("%04s",$max); |
|
202 | 202 | |
203 | 203 | $ref=''; |
204 | 204 | $sql = "SELECT ref as ref"; |
@@ -216,32 +216,32 @@ discard block |
||
216 | 216 | else dol_print_error($db); |
217 | 217 | |
218 | 218 | return $ref; |
219 | - } |
|
220 | - else if ($mode == 'next') |
|
221 | - { |
|
222 | - $date=$invoice->date; // This is invoice date (not creation date) |
|
223 | - $yymm = strftime("%y%m",$date); |
|
224 | - |
|
225 | - if ($max >= (pow(10, 4) - 1)) $num=$max+1; // If counter > 9999, we do not format on 4 chars, we take number as it is |
|
226 | - else $num = sprintf("%04s",$max+1); |
|
227 | - |
|
228 | - dol_syslog(get_class($this)."::getNextValue return ".$prefix.$yymm."-".$num); |
|
229 | - return $prefix.$yymm."-".$num; |
|
230 | - } |
|
231 | - else dol_print_error('','Bad parameter for getNextValue'); |
|
232 | - } |
|
233 | - |
|
234 | - /** |
|
235 | - * Return next free value |
|
236 | - * |
|
219 | + } |
|
220 | + else if ($mode == 'next') |
|
221 | + { |
|
222 | + $date=$invoice->date; // This is invoice date (not creation date) |
|
223 | + $yymm = strftime("%y%m",$date); |
|
224 | + |
|
225 | + if ($max >= (pow(10, 4) - 1)) $num=$max+1; // If counter > 9999, we do not format on 4 chars, we take number as it is |
|
226 | + else $num = sprintf("%04s",$max+1); |
|
227 | + |
|
228 | + dol_syslog(get_class($this)."::getNextValue return ".$prefix.$yymm."-".$num); |
|
229 | + return $prefix.$yymm."-".$num; |
|
230 | + } |
|
231 | + else dol_print_error('','Bad parameter for getNextValue'); |
|
232 | + } |
|
233 | + |
|
234 | + /** |
|
235 | + * Return next free value |
|
236 | + * |
|
237 | 237 | * @param Societe $objsoc Object third party |
238 | 238 | * @param string $objforref Object for number to search |
239 | 239 | * @param string $mode 'next' for next value or 'last' for last value |
240 | 240 | * @return string Next free value |
241 | - */ |
|
242 | - function getNumRef($objsoc,$objforref,$mode='next') |
|
243 | - { |
|
244 | - return $this->getNextValue($objsoc,$objforref,$mode); |
|
245 | - } |
|
241 | + */ |
|
242 | + function getNumRef($objsoc,$objforref,$mode='next') |
|
243 | + { |
|
244 | + return $this->getNextValue($objsoc,$objforref,$mode); |
|
245 | + } |
|
246 | 246 | } |
247 | 247 |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * \ingroup facture |
23 | 23 | * \brief File containing class for numbering module Terre |
24 | 24 | */ |
25 | -require_once DOL_DOCUMENT_ROOT .'/core/modules/facture/modules_facture.php'; |
|
25 | +require_once DOL_DOCUMENT_ROOT.'/core/modules/facture/modules_facture.php'; |
|
26 | 26 | |
27 | 27 | /** \class mod_facture_terre |
28 | 28 | * \brief Classe du modele de numerotation de reference de facture Terre |
@@ -33,18 +33,18 @@ discard block |
||
33 | 33 | * Dolibarr version of the loaded document |
34 | 34 | * @public string |
35 | 35 | */ |
36 | - public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' |
|
36 | + public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' |
|
37 | 37 | |
38 | - public $prefixinvoice='FA'; |
|
38 | + public $prefixinvoice = 'FA'; |
|
39 | 39 | |
40 | - public $prefixcreditnote='AV'; |
|
40 | + public $prefixcreditnote = 'AV'; |
|
41 | 41 | |
42 | - public $prefixdeposit='AC'; |
|
42 | + public $prefixdeposit = 'AC'; |
|
43 | 43 | |
44 | 44 | /** |
45 | 45 | * @var string Error code (or message) |
46 | 46 | */ |
47 | - public $error=''; |
|
47 | + public $error = ''; |
|
48 | 48 | |
49 | 49 | |
50 | 50 | /** |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | */ |
53 | 53 | function __construct() |
54 | 54 | { |
55 | - if (! empty($conf->global->INVOICE_NUMBERING_TERRE_FORCE_PREFIX)) |
|
55 | + if (!empty($conf->global->INVOICE_NUMBERING_TERRE_FORCE_PREFIX)) |
|
56 | 56 | { |
57 | 57 | $this->prefixinvoice = $conf->global->INVOICE_NUMBERING_TERRE_FORCE_PREFIX; |
58 | 58 | } |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | { |
68 | 68 | global $langs; |
69 | 69 | $langs->load("bills"); |
70 | - return $langs->trans('TerreNumRefModelDesc1',$this->prefixinvoice,$this->prefixcreditnote,$this->prefixdeposit); |
|
70 | + return $langs->trans('TerreNumRefModelDesc1', $this->prefixinvoice, $this->prefixcreditnote, $this->prefixdeposit); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | /** |
@@ -88,71 +88,71 @@ discard block |
||
88 | 88 | */ |
89 | 89 | function canBeActivated() |
90 | 90 | { |
91 | - global $langs,$conf,$db; |
|
91 | + global $langs, $conf, $db; |
|
92 | 92 | |
93 | 93 | $langs->load("bills"); |
94 | 94 | |
95 | 95 | // Check invoice num |
96 | - $fayymm=''; $max=''; |
|
96 | + $fayymm = ''; $max = ''; |
|
97 | 97 | |
98 | - $posindice=8; |
|
99 | - $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL |
|
100 | - $sql.= " FROM ".MAIN_DB_PREFIX."facture"; |
|
101 | - $sql.= " WHERE ref LIKE '".$db->escape($this->prefixinvoice)."____-%'"; |
|
102 | - $sql.= " AND entity = ".$conf->entity; |
|
98 | + $posindice = 8; |
|
99 | + $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL |
|
100 | + $sql .= " FROM ".MAIN_DB_PREFIX."facture"; |
|
101 | + $sql .= " WHERE ref LIKE '".$db->escape($this->prefixinvoice)."____-%'"; |
|
102 | + $sql .= " AND entity = ".$conf->entity; |
|
103 | 103 | |
104 | - $resql=$db->query($sql); |
|
104 | + $resql = $db->query($sql); |
|
105 | 105 | if ($resql) |
106 | 106 | { |
107 | 107 | $row = $db->fetch_row($resql); |
108 | - if ($row) { $fayymm = substr($row[0],0,6); $max=$row[0]; } |
|
108 | + if ($row) { $fayymm = substr($row[0], 0, 6); $max = $row[0]; } |
|
109 | 109 | } |
110 | - if ($fayymm && ! preg_match('/'.$this->prefixinvoice.'[0-9][0-9][0-9][0-9]/i',$fayymm)) |
|
110 | + if ($fayymm && !preg_match('/'.$this->prefixinvoice.'[0-9][0-9][0-9][0-9]/i', $fayymm)) |
|
111 | 111 | { |
112 | 112 | $langs->load("errors"); |
113 | - $this->error=$langs->trans('ErrorNumRefModel',$max); |
|
113 | + $this->error = $langs->trans('ErrorNumRefModel', $max); |
|
114 | 114 | return false; |
115 | 115 | } |
116 | 116 | |
117 | 117 | // Check credit note num |
118 | - $fayymm=''; |
|
118 | + $fayymm = ''; |
|
119 | 119 | |
120 | - $posindice=8; |
|
121 | - $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL |
|
122 | - $sql.= " FROM ".MAIN_DB_PREFIX."facture"; |
|
123 | - $sql.= " WHERE ref LIKE '".$db->escape($this->prefixcreditnote)."____-%'"; |
|
124 | - $sql.= " AND entity = ".$conf->entity; |
|
120 | + $posindice = 8; |
|
121 | + $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL |
|
122 | + $sql .= " FROM ".MAIN_DB_PREFIX."facture"; |
|
123 | + $sql .= " WHERE ref LIKE '".$db->escape($this->prefixcreditnote)."____-%'"; |
|
124 | + $sql .= " AND entity = ".$conf->entity; |
|
125 | 125 | |
126 | - $resql=$db->query($sql); |
|
126 | + $resql = $db->query($sql); |
|
127 | 127 | if ($resql) |
128 | 128 | { |
129 | 129 | $row = $db->fetch_row($resql); |
130 | - if ($row) { $fayymm = substr($row[0],0,6); $max=$row[0]; } |
|
130 | + if ($row) { $fayymm = substr($row[0], 0, 6); $max = $row[0]; } |
|
131 | 131 | } |
132 | - if ($fayymm && ! preg_match('/'.$this->prefixcreditnote.'[0-9][0-9][0-9][0-9]/i',$fayymm)) |
|
132 | + if ($fayymm && !preg_match('/'.$this->prefixcreditnote.'[0-9][0-9][0-9][0-9]/i', $fayymm)) |
|
133 | 133 | { |
134 | - $this->error=$langs->trans('ErrorNumRefModel',$max); |
|
134 | + $this->error = $langs->trans('ErrorNumRefModel', $max); |
|
135 | 135 | return false; |
136 | 136 | } |
137 | 137 | |
138 | 138 | // Check deposit num |
139 | - $fayymm=''; |
|
139 | + $fayymm = ''; |
|
140 | 140 | |
141 | - $posindice=8; |
|
142 | - $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL |
|
143 | - $sql.= " FROM ".MAIN_DB_PREFIX."facture"; |
|
144 | - $sql.= " WHERE ref LIKE '".$db->escape($this->prefixdeposit)."____-%'"; |
|
145 | - $sql.= " AND entity = ".$conf->entity; |
|
141 | + $posindice = 8; |
|
142 | + $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL |
|
143 | + $sql .= " FROM ".MAIN_DB_PREFIX."facture"; |
|
144 | + $sql .= " WHERE ref LIKE '".$db->escape($this->prefixdeposit)."____-%'"; |
|
145 | + $sql .= " AND entity = ".$conf->entity; |
|
146 | 146 | |
147 | - $resql=$db->query($sql); |
|
147 | + $resql = $db->query($sql); |
|
148 | 148 | if ($resql) |
149 | 149 | { |
150 | 150 | $row = $db->fetch_row($resql); |
151 | - if ($row) { $fayymm = substr($row[0],0,6); $max=$row[0]; } |
|
151 | + if ($row) { $fayymm = substr($row[0], 0, 6); $max = $row[0]; } |
|
152 | 152 | } |
153 | - if ($fayymm && ! preg_match('/'.$this->prefixdeposit.'[0-9][0-9][0-9][0-9]/i',$fayymm)) |
|
153 | + if ($fayymm && !preg_match('/'.$this->prefixdeposit.'[0-9][0-9][0-9][0-9]/i', $fayymm)) |
|
154 | 154 | { |
155 | - $this->error=$langs->trans('ErrorNumRefModel',$max); |
|
155 | + $this->error = $langs->trans('ErrorNumRefModel', $max); |
|
156 | 156 | return false; |
157 | 157 | } |
158 | 158 | |
@@ -167,28 +167,28 @@ discard block |
||
167 | 167 | * @param string $mode 'next' for next value or 'last' for last value |
168 | 168 | * @return string Value |
169 | 169 | */ |
170 | - function getNextValue($objsoc, $invoice, $mode='next') |
|
170 | + function getNextValue($objsoc, $invoice, $mode = 'next') |
|
171 | 171 | { |
172 | 172 | global $db; |
173 | 173 | |
174 | - if ($invoice->type == 2) $prefix=$this->prefixcreditnote; |
|
175 | - else if ($invoice->type == 3) $prefix=$this->prefixdeposit; |
|
176 | - else $prefix=$this->prefixinvoice; |
|
174 | + if ($invoice->type == 2) $prefix = $this->prefixcreditnote; |
|
175 | + else if ($invoice->type == 3) $prefix = $this->prefixdeposit; |
|
176 | + else $prefix = $this->prefixinvoice; |
|
177 | 177 | |
178 | 178 | // D'abord on recupere la valeur max |
179 | - $posindice=8; |
|
180 | - $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL |
|
181 | - $sql.= " FROM ".MAIN_DB_PREFIX."facture"; |
|
182 | - $sql.= " WHERE ref LIKE '".$prefix."____-%'"; |
|
183 | - $sql.= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")"; |
|
179 | + $posindice = 8; |
|
180 | + $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL |
|
181 | + $sql .= " FROM ".MAIN_DB_PREFIX."facture"; |
|
182 | + $sql .= " WHERE ref LIKE '".$prefix."____-%'"; |
|
183 | + $sql .= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")"; |
|
184 | 184 | |
185 | - $resql=$db->query($sql); |
|
185 | + $resql = $db->query($sql); |
|
186 | 186 | dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG); |
187 | 187 | if ($resql) |
188 | 188 | { |
189 | 189 | $obj = $db->fetch_object($resql); |
190 | 190 | if ($obj) $max = intval($obj->max); |
191 | - else $max=0; |
|
191 | + else $max = 0; |
|
192 | 192 | } |
193 | 193 | else |
194 | 194 | { |
@@ -197,17 +197,17 @@ discard block |
||
197 | 197 | |
198 | 198 | if ($mode == 'last') |
199 | 199 | { |
200 | - if ($max >= (pow(10, 4) - 1)) $num=$max; // If counter > 9999, we do not format on 4 chars, we take number as it is |
|
201 | - else $num = sprintf("%04s",$max); |
|
200 | + if ($max >= (pow(10, 4) - 1)) $num = $max; // If counter > 9999, we do not format on 4 chars, we take number as it is |
|
201 | + else $num = sprintf("%04s", $max); |
|
202 | 202 | |
203 | - $ref=''; |
|
203 | + $ref = ''; |
|
204 | 204 | $sql = "SELECT ref as ref"; |
205 | - $sql.= " FROM ".MAIN_DB_PREFIX."facture"; |
|
206 | - $sql.= " WHERE ref LIKE '".$prefix."____-".$num."'"; |
|
207 | - $sql.= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")"; |
|
205 | + $sql .= " FROM ".MAIN_DB_PREFIX."facture"; |
|
206 | + $sql .= " WHERE ref LIKE '".$prefix."____-".$num."'"; |
|
207 | + $sql .= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")"; |
|
208 | 208 | |
209 | 209 | dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG); |
210 | - $resql=$db->query($sql); |
|
210 | + $resql = $db->query($sql); |
|
211 | 211 | if ($resql) |
212 | 212 | { |
213 | 213 | $obj = $db->fetch_object($resql); |
@@ -219,16 +219,16 @@ discard block |
||
219 | 219 | } |
220 | 220 | else if ($mode == 'next') |
221 | 221 | { |
222 | - $date=$invoice->date; // This is invoice date (not creation date) |
|
223 | - $yymm = strftime("%y%m",$date); |
|
222 | + $date = $invoice->date; // This is invoice date (not creation date) |
|
223 | + $yymm = strftime("%y%m", $date); |
|
224 | 224 | |
225 | - if ($max >= (pow(10, 4) - 1)) $num=$max+1; // If counter > 9999, we do not format on 4 chars, we take number as it is |
|
226 | - else $num = sprintf("%04s",$max+1); |
|
225 | + if ($max >= (pow(10, 4) - 1)) $num = $max + 1; // If counter > 9999, we do not format on 4 chars, we take number as it is |
|
226 | + else $num = sprintf("%04s", $max + 1); |
|
227 | 227 | |
228 | 228 | dol_syslog(get_class($this)."::getNextValue return ".$prefix.$yymm."-".$num); |
229 | 229 | return $prefix.$yymm."-".$num; |
230 | 230 | } |
231 | - else dol_print_error('','Bad parameter for getNextValue'); |
|
231 | + else dol_print_error('', 'Bad parameter for getNextValue'); |
|
232 | 232 | } |
233 | 233 | |
234 | 234 | /** |
@@ -239,9 +239,9 @@ discard block |
||
239 | 239 | * @param string $mode 'next' for next value or 'last' for last value |
240 | 240 | * @return string Next free value |
241 | 241 | */ |
242 | - function getNumRef($objsoc,$objforref,$mode='next') |
|
242 | + function getNumRef($objsoc, $objforref, $mode = 'next') |
|
243 | 243 | { |
244 | - return $this->getNextValue($objsoc,$objforref,$mode); |
|
244 | + return $this->getNextValue($objsoc, $objforref, $mode); |
|
245 | 245 | } |
246 | 246 | } |
247 | 247 |
@@ -171,9 +171,13 @@ discard block |
||
171 | 171 | { |
172 | 172 | global $db; |
173 | 173 | |
174 | - if ($invoice->type == 2) $prefix=$this->prefixcreditnote; |
|
175 | - else if ($invoice->type == 3) $prefix=$this->prefixdeposit; |
|
176 | - else $prefix=$this->prefixinvoice; |
|
174 | + if ($invoice->type == 2) { |
|
175 | + $prefix=$this->prefixcreditnote; |
|
176 | + } else if ($invoice->type == 3) { |
|
177 | + $prefix=$this->prefixdeposit; |
|
178 | + } else { |
|
179 | + $prefix=$this->prefixinvoice; |
|
180 | + } |
|
177 | 181 | |
178 | 182 | // D'abord on recupere la valeur max |
179 | 183 | $posindice=8; |
@@ -187,18 +191,25 @@ discard block |
||
187 | 191 | if ($resql) |
188 | 192 | { |
189 | 193 | $obj = $db->fetch_object($resql); |
190 | - if ($obj) $max = intval($obj->max); |
|
191 | - else $max=0; |
|
192 | - } |
|
193 | - else |
|
194 | + if ($obj) { |
|
195 | + $max = intval($obj->max); |
|
196 | + } else { |
|
197 | + $max=0; |
|
198 | + } |
|
199 | + } else |
|
194 | 200 | { |
195 | 201 | return -1; |
196 | 202 | } |
197 | 203 | |
198 | 204 | if ($mode == 'last') |
199 | 205 | { |
200 | - if ($max >= (pow(10, 4) - 1)) $num=$max; // If counter > 9999, we do not format on 4 chars, we take number as it is |
|
201 | - else $num = sprintf("%04s",$max); |
|
206 | + if ($max >= (pow(10, 4) - 1)) { |
|
207 | + $num=$max; |
|
208 | + } |
|
209 | + // If counter > 9999, we do not format on 4 chars, we take number as it is |
|
210 | + else { |
|
211 | + $num = sprintf("%04s",$max); |
|
212 | + } |
|
202 | 213 | |
203 | 214 | $ref=''; |
204 | 215 | $sql = "SELECT ref as ref"; |
@@ -211,24 +222,32 @@ discard block |
||
211 | 222 | if ($resql) |
212 | 223 | { |
213 | 224 | $obj = $db->fetch_object($resql); |
214 | - if ($obj) $ref = $obj->ref; |
|
225 | + if ($obj) { |
|
226 | + $ref = $obj->ref; |
|
227 | + } |
|
228 | + } else { |
|
229 | + dol_print_error($db); |
|
215 | 230 | } |
216 | - else dol_print_error($db); |
|
217 | 231 | |
218 | 232 | return $ref; |
219 | - } |
|
220 | - else if ($mode == 'next') |
|
233 | + } else if ($mode == 'next') |
|
221 | 234 | { |
222 | 235 | $date=$invoice->date; // This is invoice date (not creation date) |
223 | 236 | $yymm = strftime("%y%m",$date); |
224 | 237 | |
225 | - if ($max >= (pow(10, 4) - 1)) $num=$max+1; // If counter > 9999, we do not format on 4 chars, we take number as it is |
|
226 | - else $num = sprintf("%04s",$max+1); |
|
238 | + if ($max >= (pow(10, 4) - 1)) { |
|
239 | + $num=$max+1; |
|
240 | + } |
|
241 | + // If counter > 9999, we do not format on 4 chars, we take number as it is |
|
242 | + else { |
|
243 | + $num = sprintf("%04s",$max+1); |
|
244 | + } |
|
227 | 245 | |
228 | 246 | dol_syslog(get_class($this)."::getNextValue return ".$prefix.$yymm."-".$num); |
229 | 247 | return $prefix.$yymm."-".$num; |
248 | + } else { |
|
249 | + dol_print_error('','Bad parameter for getNextValue'); |
|
230 | 250 | } |
231 | - else dol_print_error('','Bad parameter for getNextValue'); |
|
232 | 251 | } |
233 | 252 | |
234 | 253 | /** |
@@ -31,121 +31,121 @@ discard block |
||
31 | 31 | */ |
32 | 32 | class modDav extends DolibarrModules |
33 | 33 | { |
34 | - /** |
|
35 | - * Constructor. Define names, constants, directories, boxes, permissions |
|
36 | - * |
|
37 | - * @param DoliDB $db Database handler |
|
38 | - */ |
|
39 | - public function __construct($db) |
|
40 | - { |
|
34 | + /** |
|
35 | + * Constructor. Define names, constants, directories, boxes, permissions |
|
36 | + * |
|
37 | + * @param DoliDB $db Database handler |
|
38 | + */ |
|
39 | + public function __construct($db) |
|
40 | + { |
|
41 | 41 | global $langs,$conf; |
42 | 42 | |
43 | 43 | $this->db = $db; |
44 | 44 | |
45 | - // Id for module (must be unique). |
|
46 | - // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id). |
|
47 | - $this->numero = 50310; |
|
48 | - // Key text used to identify module (for permissions, menus, etc...) |
|
49 | - $this->rights_class = 'dav'; |
|
50 | - |
|
51 | - // Family can be 'base' (core modules),'crm','financial','hr','projects','products','ecm','technic' (transverse modules),'interface' (link with external tools),'other','...' |
|
52 | - // It is used to group modules by family in module setup page |
|
53 | - $this->family = "interface"; |
|
54 | - // Module position in the family on 2 digits ('01', '10', '20', ...) |
|
55 | - $this->module_position = '75'; |
|
56 | - // Gives the possibility to the module, to provide his own family info and position of this family (Overwrite $this->family and $this->module_position. Avoid this) |
|
57 | - //$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily"))); |
|
58 | - |
|
59 | - // Module label (no space allowed), used if translation string 'ModuledavName' not found (MyModue is name of module). |
|
60 | - $this->name = preg_replace('/^mod/i','',get_class($this)); |
|
61 | - // Module description, used if translation string 'ModuledavDesc' not found (MyModue is name of module). |
|
62 | - $this->description = "davDescription"; |
|
63 | - // Used only if file README.md and README-LL.md not found. |
|
64 | - $this->descriptionlong = "davDescription"; |
|
65 | - |
|
66 | - // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z' |
|
67 | - $this->version = 'dolibarr'; |
|
68 | - // Key used in llx_const table to save module status enabled/disabled (where DAV is value of property name of module in uppercase) |
|
69 | - $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); |
|
70 | - // Name of image file used for this module. |
|
71 | - // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue' |
|
72 | - // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module' |
|
73 | - $this->picto='generic'; |
|
74 | - |
|
75 | - // Defined all module parts (triggers, login, substitutions, menus, css, etc...) |
|
76 | - // for default path (eg: /dav/core/xxxxx) (0=disable, 1=enable) |
|
77 | - // for specific path of parts (eg: /dav/core/modules/barcode) |
|
78 | - // for specific css file (eg: /dav/css/dav.css.php) |
|
79 | - $this->module_parts = array(); |
|
80 | - |
|
81 | - // Data directories to create when module is enabled. |
|
82 | - // Example: this->dirs = array("/dav/temp","/dav/subdir"); |
|
83 | - $this->dirs = array("/dav/temp","/dav/public","/dav/private"); |
|
84 | - |
|
85 | - // Config pages. Put here list of php page, stored into dav/admin directory, to use to setup module. |
|
86 | - $this->config_page_url = array("dav.php"); |
|
87 | - |
|
88 | - // Dependencies |
|
89 | - $this->hidden = false; // A condition to hide module |
|
90 | - $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled |
|
91 | - $this->requiredby = array(); // List of module ids to disable if this one is disabled |
|
92 | - $this->conflictwith = array(); // List of module class names as string this module is in conflict with |
|
93 | - $this->langfiles = array("admin"); |
|
94 | - $this->phpmin = array(5,6); // Minimum version of PHP required by module |
|
95 | - $this->need_dolibarr_version = array(7,0); // Minimum version of Dolibarr required by module |
|
96 | - $this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','ES'='textes'...) |
|
97 | - $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...) |
|
98 | - //$this->automatic_activation = array('FR'=>'davWasAutomaticallyActivatedBecauseOfYourCountryChoice'); |
|
99 | - //$this->always_enabled = true; // If true, can't be disabled |
|
100 | - |
|
101 | - // Constants |
|
102 | - // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive) |
|
103 | - // Example: $this->const=array(0=>array('DAV_MYNEWCONST1','chaine','myvalue','This is a constant to add',1), |
|
104 | - // 1=>array('DAV_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1) |
|
105 | - // ); |
|
106 | - $this->const = array( |
|
107 | - //1=>array('DAV_MYCONSTANT', 'chaine', 'avalue', 'This is a constant to add', 1, 'allentities', 1) |
|
108 | - ); |
|
109 | - |
|
110 | - |
|
111 | - if (! isset($conf->dav) || ! isset($conf->dav->enabled)) |
|
112 | - { |
|
113 | - $conf->dav=new stdClass(); |
|
114 | - $conf->dav->enabled=0; |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - // Array to add new pages in new tabs |
|
45 | + // Id for module (must be unique). |
|
46 | + // Use here a free id (See in Home -> System information -> Dolibarr for list of used modules id). |
|
47 | + $this->numero = 50310; |
|
48 | + // Key text used to identify module (for permissions, menus, etc...) |
|
49 | + $this->rights_class = 'dav'; |
|
50 | + |
|
51 | + // Family can be 'base' (core modules),'crm','financial','hr','projects','products','ecm','technic' (transverse modules),'interface' (link with external tools),'other','...' |
|
52 | + // It is used to group modules by family in module setup page |
|
53 | + $this->family = "interface"; |
|
54 | + // Module position in the family on 2 digits ('01', '10', '20', ...) |
|
55 | + $this->module_position = '75'; |
|
56 | + // Gives the possibility to the module, to provide his own family info and position of this family (Overwrite $this->family and $this->module_position. Avoid this) |
|
57 | + //$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily"))); |
|
58 | + |
|
59 | + // Module label (no space allowed), used if translation string 'ModuledavName' not found (MyModue is name of module). |
|
60 | + $this->name = preg_replace('/^mod/i','',get_class($this)); |
|
61 | + // Module description, used if translation string 'ModuledavDesc' not found (MyModue is name of module). |
|
62 | + $this->description = "davDescription"; |
|
63 | + // Used only if file README.md and README-LL.md not found. |
|
64 | + $this->descriptionlong = "davDescription"; |
|
65 | + |
|
66 | + // Possible values for version are: 'development', 'experimental', 'dolibarr', 'dolibarr_deprecated' or a version string like 'x.y.z' |
|
67 | + $this->version = 'dolibarr'; |
|
68 | + // Key used in llx_const table to save module status enabled/disabled (where DAV is value of property name of module in uppercase) |
|
69 | + $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); |
|
70 | + // Name of image file used for this module. |
|
71 | + // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue' |
|
72 | + // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module' |
|
73 | + $this->picto='generic'; |
|
74 | + |
|
75 | + // Defined all module parts (triggers, login, substitutions, menus, css, etc...) |
|
76 | + // for default path (eg: /dav/core/xxxxx) (0=disable, 1=enable) |
|
77 | + // for specific path of parts (eg: /dav/core/modules/barcode) |
|
78 | + // for specific css file (eg: /dav/css/dav.css.php) |
|
79 | + $this->module_parts = array(); |
|
80 | + |
|
81 | + // Data directories to create when module is enabled. |
|
82 | + // Example: this->dirs = array("/dav/temp","/dav/subdir"); |
|
83 | + $this->dirs = array("/dav/temp","/dav/public","/dav/private"); |
|
84 | + |
|
85 | + // Config pages. Put here list of php page, stored into dav/admin directory, to use to setup module. |
|
86 | + $this->config_page_url = array("dav.php"); |
|
87 | + |
|
88 | + // Dependencies |
|
89 | + $this->hidden = false; // A condition to hide module |
|
90 | + $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled |
|
91 | + $this->requiredby = array(); // List of module ids to disable if this one is disabled |
|
92 | + $this->conflictwith = array(); // List of module class names as string this module is in conflict with |
|
93 | + $this->langfiles = array("admin"); |
|
94 | + $this->phpmin = array(5,6); // Minimum version of PHP required by module |
|
95 | + $this->need_dolibarr_version = array(7,0); // Minimum version of Dolibarr required by module |
|
96 | + $this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','ES'='textes'...) |
|
97 | + $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...) |
|
98 | + //$this->automatic_activation = array('FR'=>'davWasAutomaticallyActivatedBecauseOfYourCountryChoice'); |
|
99 | + //$this->always_enabled = true; // If true, can't be disabled |
|
100 | + |
|
101 | + // Constants |
|
102 | + // List of particular constants to add when module is enabled (key, 'chaine', value, desc, visible, 'current' or 'allentities', deleteonunactive) |
|
103 | + // Example: $this->const=array(0=>array('DAV_MYNEWCONST1','chaine','myvalue','This is a constant to add',1), |
|
104 | + // 1=>array('DAV_MYNEWCONST2','chaine','myvalue','This is another constant to add',0, 'current', 1) |
|
105 | + // ); |
|
106 | + $this->const = array( |
|
107 | + //1=>array('DAV_MYCONSTANT', 'chaine', 'avalue', 'This is a constant to add', 1, 'allentities', 1) |
|
108 | + ); |
|
109 | + |
|
110 | + |
|
111 | + if (! isset($conf->dav) || ! isset($conf->dav->enabled)) |
|
112 | + { |
|
113 | + $conf->dav=new stdClass(); |
|
114 | + $conf->dav->enabled=0; |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + // Array to add new pages in new tabs |
|
119 | 119 | $this->tabs = array(); |
120 | - // Example: |
|
121 | - // $this->tabs[] = array('data'=>'objecttype:+tabname1:Title1:mylangfile@dav:$user->rights->dav->read:/dav/mynewtab1.php?id=__ID__'); // To add a new tab identified by code tabname1 |
|
120 | + // Example: |
|
121 | + // $this->tabs[] = array('data'=>'objecttype:+tabname1:Title1:mylangfile@dav:$user->rights->dav->read:/dav/mynewtab1.php?id=__ID__'); // To add a new tab identified by code tabname1 |
|
122 | 122 | // $this->tabs[] = array('data'=>'objecttype:+tabname2:SUBSTITUTION_Title2:mylangfile@dav:$user->rights->othermodule->read:/dav/mynewtab2.php?id=__ID__', // To add another new tab identified by code tabname2. Label will be result of calling all substitution functions on 'Title2' key. |
123 | 123 | // $this->tabs[] = array('data'=>'objecttype:-tabname:NU:conditiontoremove'); // To remove an existing tab identified by code tabname |
124 | 124 | // |
125 | 125 | // Where objecttype can be |
126 | - // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member) |
|
127 | - // 'contact' to add a tab in contact view |
|
128 | - // 'contract' to add a tab in contract view |
|
129 | - // 'group' to add a tab in group view |
|
130 | - // 'intervention' to add a tab in intervention view |
|
131 | - // 'invoice' to add a tab in customer invoice view |
|
132 | - // 'invoice_supplier' to add a tab in supplier invoice view |
|
133 | - // 'member' to add a tab in fundation member view |
|
134 | - // 'opensurveypoll' to add a tab in opensurvey poll view |
|
135 | - // 'order' to add a tab in customer order view |
|
136 | - // 'order_supplier' to add a tab in supplier order view |
|
137 | - // 'payment' to add a tab in payment view |
|
138 | - // 'payment_supplier' to add a tab in supplier payment view |
|
139 | - // 'product' to add a tab in product view |
|
140 | - // 'propal' to add a tab in propal view |
|
141 | - // 'project' to add a tab in project view |
|
142 | - // 'stock' to add a tab in stock view |
|
143 | - // 'thirdparty' to add a tab in third party view |
|
144 | - // 'user' to add a tab in user view |
|
126 | + // 'categories_x' to add a tab in category view (replace 'x' by type of category (0=product, 1=supplier, 2=customer, 3=member) |
|
127 | + // 'contact' to add a tab in contact view |
|
128 | + // 'contract' to add a tab in contract view |
|
129 | + // 'group' to add a tab in group view |
|
130 | + // 'intervention' to add a tab in intervention view |
|
131 | + // 'invoice' to add a tab in customer invoice view |
|
132 | + // 'invoice_supplier' to add a tab in supplier invoice view |
|
133 | + // 'member' to add a tab in fundation member view |
|
134 | + // 'opensurveypoll' to add a tab in opensurvey poll view |
|
135 | + // 'order' to add a tab in customer order view |
|
136 | + // 'order_supplier' to add a tab in supplier order view |
|
137 | + // 'payment' to add a tab in payment view |
|
138 | + // 'payment_supplier' to add a tab in supplier payment view |
|
139 | + // 'product' to add a tab in product view |
|
140 | + // 'propal' to add a tab in propal view |
|
141 | + // 'project' to add a tab in project view |
|
142 | + // 'stock' to add a tab in stock view |
|
143 | + // 'thirdparty' to add a tab in third party view |
|
144 | + // 'user' to add a tab in user view |
|
145 | 145 | |
146 | 146 | |
147 | 147 | // Dictionaries |
148 | - $this->dictionaries=array(); |
|
148 | + $this->dictionaries=array(); |
|
149 | 149 | /* Example: |
150 | 150 | $this->dictionaries=array( |
151 | 151 | 'langs'=>'mylangfile@dav', |
@@ -163,28 +163,28 @@ discard block |
||
163 | 163 | |
164 | 164 | |
165 | 165 | // Boxes/Widgets |
166 | - // Add here list of php file(s) stored in dav/core/boxes that contains class to show a widget. |
|
166 | + // Add here list of php file(s) stored in dav/core/boxes that contains class to show a widget. |
|
167 | 167 | $this->boxes = array( |
168 | - //0=>array('file'=>'davwidget1.php@dav','note'=>'Widget provided by dav','enabledbydefaulton'=>'Home'), |
|
169 | - //1=>array('file'=>'davwidget2.php@dav','note'=>'Widget provided by dav'), |
|
170 | - //2=>array('file'=>'davwidget3.php@dav','note'=>'Widget provided by dav') |
|
168 | + //0=>array('file'=>'davwidget1.php@dav','note'=>'Widget provided by dav','enabledbydefaulton'=>'Home'), |
|
169 | + //1=>array('file'=>'davwidget2.php@dav','note'=>'Widget provided by dav'), |
|
170 | + //2=>array('file'=>'davwidget3.php@dav','note'=>'Widget provided by dav') |
|
171 | 171 | ); |
172 | 172 | |
173 | 173 | |
174 | - // Cronjobs (List of cron jobs entries to add when module is enabled) |
|
175 | - // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week |
|
176 | - //$this->cronjobs = array( |
|
177 | - //0=>array('label'=>'MyJob label', 'jobtype'=>'method', 'class'=>'/dav/class/myobject.class.php', 'objectname'=>'MyObject', 'method'=>'doScheduledJob', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>2, 'unitfrequency'=>3600, 'status'=>0, 'test'=>true) |
|
178 | - //); |
|
179 | - // Example: $this->cronjobs=array(0=>array('label'=>'My label', 'jobtype'=>'method', 'class'=>'/dir/class/file.class.php', 'objectname'=>'MyClass', 'method'=>'myMethod', 'parameters'=>'param1, param2', 'comment'=>'Comment', 'frequency'=>2, 'unitfrequency'=>3600, 'status'=>0, 'test'=>true), |
|
180 | - // 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'param1, param2', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24, 'status'=>0, 'test'=>true) |
|
181 | - // ); |
|
174 | + // Cronjobs (List of cron jobs entries to add when module is enabled) |
|
175 | + // unit_frequency must be 60 for minute, 3600 for hour, 86400 for day, 604800 for week |
|
176 | + //$this->cronjobs = array( |
|
177 | + //0=>array('label'=>'MyJob label', 'jobtype'=>'method', 'class'=>'/dav/class/myobject.class.php', 'objectname'=>'MyObject', 'method'=>'doScheduledJob', 'parameters'=>'', 'comment'=>'Comment', 'frequency'=>2, 'unitfrequency'=>3600, 'status'=>0, 'test'=>true) |
|
178 | + //); |
|
179 | + // Example: $this->cronjobs=array(0=>array('label'=>'My label', 'jobtype'=>'method', 'class'=>'/dir/class/file.class.php', 'objectname'=>'MyClass', 'method'=>'myMethod', 'parameters'=>'param1, param2', 'comment'=>'Comment', 'frequency'=>2, 'unitfrequency'=>3600, 'status'=>0, 'test'=>true), |
|
180 | + // 1=>array('label'=>'My label', 'jobtype'=>'command', 'command'=>'', 'parameters'=>'param1, param2', 'comment'=>'Comment', 'frequency'=>1, 'unitfrequency'=>3600*24, 'status'=>0, 'test'=>true) |
|
181 | + // ); |
|
182 | 182 | |
183 | 183 | |
184 | - // Permissions |
|
185 | - $this->rights = array(); // Permission array used by this module |
|
184 | + // Permissions |
|
185 | + $this->rights = array(); // Permission array used by this module |
|
186 | 186 | |
187 | - /* |
|
187 | + /* |
|
188 | 188 | $r=0; |
189 | 189 | $this->rights[$r][0] = $this->numero + $r; // Permission id (must not be already used) |
190 | 190 | $this->rights[$r][1] = 'Read myobject of dav'; // Permission label |
@@ -207,14 +207,14 @@ discard block |
||
207 | 207 | $this->rights[$r][5] = ''; // In php code, permission will be checked by test if ($user->rights->dav->level1->level2) |
208 | 208 | */ |
209 | 209 | |
210 | - // Main menu entries |
|
211 | - $this->menu = array(); // List of menus to add |
|
212 | - $r=0; |
|
210 | + // Main menu entries |
|
211 | + $this->menu = array(); // List of menus to add |
|
212 | + $r=0; |
|
213 | 213 | |
214 | - // Add here entries to declare new menus |
|
214 | + // Add here entries to declare new menus |
|
215 | 215 | |
216 | - /* BEGIN MODULEBUILDER TOPMENU */ |
|
217 | - /*$this->menu[$r++]=array('fk_menu'=>'', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode |
|
216 | + /* BEGIN MODULEBUILDER TOPMENU */ |
|
217 | + /*$this->menu[$r++]=array('fk_menu'=>'', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode |
|
218 | 218 | 'type'=>'top', // This is a Top menu entry |
219 | 219 | 'titre'=>'dav', |
220 | 220 | 'mainmenu'=>'dav', |
@@ -227,9 +227,9 @@ discard block |
||
227 | 227 | 'target'=>'', |
228 | 228 | 'user'=>2); // 0=Menu for internal users, 1=external users, 2=both |
229 | 229 | */ |
230 | - /* END MODULEBUILDER TOPMENU */ |
|
230 | + /* END MODULEBUILDER TOPMENU */ |
|
231 | 231 | |
232 | - /* BEGIN MODULEBUILDER LEFTMENU MYOBJECT |
|
232 | + /* BEGIN MODULEBUILDER LEFTMENU MYOBJECT |
|
233 | 233 | $this->menu[$r++]=array( 'fk_menu'=>'fk_mainmenu=dav', // '' if this is a top menu. For left menu, use 'fk_mainmenu=xxx' or 'fk_mainmenu=xxx,fk_leftmenu=yyy' where xxx is mainmenucode and yyy is a leftmenucode |
234 | 234 | 'type'=>'left', // This is a Left menu entry |
235 | 235 | 'titre'=>'List MyObject', |
@@ -257,11 +257,11 @@ discard block |
||
257 | 257 | END MODULEBUILDER LEFTMENU MYOBJECT */ |
258 | 258 | |
259 | 259 | |
260 | - // Exports |
|
261 | - $r=1; |
|
260 | + // Exports |
|
261 | + $r=1; |
|
262 | 262 | |
263 | - /* BEGIN MODULEBUILDER EXPORT MYOBJECT */ |
|
264 | - /* |
|
263 | + /* BEGIN MODULEBUILDER EXPORT MYOBJECT */ |
|
264 | + /* |
|
265 | 265 | $langs->load("dav@dav"); |
266 | 266 | $this->export_code[$r]=$this->rights_class.'_'.$r; |
267 | 267 | $this->export_label[$r]='MyObjectLines'; // Translation key (used only if key ExportDataset_xxx_z not found) |
@@ -276,48 +276,48 @@ discard block |
||
276 | 276 | $this->export_sql_end[$r] .=' WHERE 1 = 1'; |
277 | 277 | $this->export_sql_end[$r] .=' AND t.entity IN ('.getEntity('myobject').')'; |
278 | 278 | $r++; */ |
279 | - /* END MODULEBUILDER EXPORT MYOBJECT */ |
|
280 | - } |
|
281 | - |
|
282 | - /** |
|
283 | - * Function called when module is enabled. |
|
284 | - * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. |
|
285 | - * It also creates data directories |
|
286 | - * |
|
279 | + /* END MODULEBUILDER EXPORT MYOBJECT */ |
|
280 | + } |
|
281 | + |
|
282 | + /** |
|
283 | + * Function called when module is enabled. |
|
284 | + * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. |
|
285 | + * It also creates data directories |
|
286 | + * |
|
287 | + * @param string $options Options when enabling module ('', 'noboxes') |
|
288 | + * @return int 1 if OK, 0 if KO |
|
289 | + */ |
|
290 | + public function init($options='') |
|
291 | + { |
|
292 | + //$this->_load_tables('/dav/sql/'); |
|
293 | + |
|
294 | + // Create extrafields |
|
295 | + include_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
296 | + $extrafields = new ExtraFields($this->db); |
|
297 | + |
|
298 | + //$result1=$extrafields->addExtraField('myattr1', "New Attr 1 label", 'boolean', 1, 3, 'thirdparty', 0, 0, '', '', 1, '', 0, 0, '', '', 'dav@dav', '$conf->dav->enabled'); |
|
299 | + //$result2=$extrafields->addExtraField('myattr2', "New Attr 2 label", 'varchar', 1, 10, 'project', 0, 0, '', '', 1, '', 0, 0, '', '', 'dav@dav', '$conf->dav->enabled'); |
|
300 | + //$result3=$extrafields->addExtraField('myattr3', "New Attr 3 label", 'varchar', 1, 10, 'bank_account', 0, 0, '', '', 1, '', 0, 0, '', '', 'dav@dav', '$conf->dav->enabled'); |
|
301 | + //$result4=$extrafields->addExtraField('myattr4', "New Attr 4 label", 'select', 1, 3, 'thirdparty', 0, 1, '', array('options'=>array('code1'=>'Val1','code2'=>'Val2','code3'=>'Val3')), 1 '', 0, 0, '', '', 'dav@dav', '$conf->dav->enabled'); |
|
302 | + //$result5=$extrafields->addExtraField('myattr5', "New Attr 5 label", 'text', 1, 10, 'user', 0, 0, '', '', 1, '', 0, 0, '', '', 'dav@dav', '$conf->dav->enabled'); |
|
303 | + |
|
304 | + $sql = array(); |
|
305 | + |
|
306 | + return $this->_init($sql, $options); |
|
307 | + } |
|
308 | + |
|
309 | + /** |
|
310 | + * Function called when module is disabled. |
|
311 | + * Remove from database constants, boxes and permissions from Dolibarr database. |
|
312 | + * Data directories are not deleted |
|
313 | + * |
|
287 | 314 | * @param string $options Options when enabling module ('', 'noboxes') |
288 | - * @return int 1 if OK, 0 if KO |
|
289 | - */ |
|
290 | - public function init($options='') |
|
291 | - { |
|
292 | - //$this->_load_tables('/dav/sql/'); |
|
293 | - |
|
294 | - // Create extrafields |
|
295 | - include_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; |
|
296 | - $extrafields = new ExtraFields($this->db); |
|
297 | - |
|
298 | - //$result1=$extrafields->addExtraField('myattr1', "New Attr 1 label", 'boolean', 1, 3, 'thirdparty', 0, 0, '', '', 1, '', 0, 0, '', '', 'dav@dav', '$conf->dav->enabled'); |
|
299 | - //$result2=$extrafields->addExtraField('myattr2', "New Attr 2 label", 'varchar', 1, 10, 'project', 0, 0, '', '', 1, '', 0, 0, '', '', 'dav@dav', '$conf->dav->enabled'); |
|
300 | - //$result3=$extrafields->addExtraField('myattr3', "New Attr 3 label", 'varchar', 1, 10, 'bank_account', 0, 0, '', '', 1, '', 0, 0, '', '', 'dav@dav', '$conf->dav->enabled'); |
|
301 | - //$result4=$extrafields->addExtraField('myattr4', "New Attr 4 label", 'select', 1, 3, 'thirdparty', 0, 1, '', array('options'=>array('code1'=>'Val1','code2'=>'Val2','code3'=>'Val3')), 1 '', 0, 0, '', '', 'dav@dav', '$conf->dav->enabled'); |
|
302 | - //$result5=$extrafields->addExtraField('myattr5', "New Attr 5 label", 'text', 1, 10, 'user', 0, 0, '', '', 1, '', 0, 0, '', '', 'dav@dav', '$conf->dav->enabled'); |
|
303 | - |
|
304 | - $sql = array(); |
|
305 | - |
|
306 | - return $this->_init($sql, $options); |
|
307 | - } |
|
308 | - |
|
309 | - /** |
|
310 | - * Function called when module is disabled. |
|
311 | - * Remove from database constants, boxes and permissions from Dolibarr database. |
|
312 | - * Data directories are not deleted |
|
313 | - * |
|
314 | - * @param string $options Options when enabling module ('', 'noboxes') |
|
315 | - * @return int 1 if OK, 0 if KO |
|
316 | - */ |
|
317 | - public function remove($options = '') |
|
318 | - { |
|
319 | - $sql = array(); |
|
320 | - |
|
321 | - return $this->_remove($sql, $options); |
|
322 | - } |
|
315 | + * @return int 1 if OK, 0 if KO |
|
316 | + */ |
|
317 | + public function remove($options = '') |
|
318 | + { |
|
319 | + $sql = array(); |
|
320 | + |
|
321 | + return $this->_remove($sql, $options); |
|
322 | + } |
|
323 | 323 | } |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | * \ingroup dav |
24 | 24 | * \brief Description and activation file for module dav |
25 | 25 | */ |
26 | -include_once DOL_DOCUMENT_ROOT .'/core/modules/DolibarrModules.class.php'; |
|
26 | +include_once DOL_DOCUMENT_ROOT.'/core/modules/DolibarrModules.class.php'; |
|
27 | 27 | |
28 | 28 | |
29 | 29 | /** |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | */ |
39 | 39 | public function __construct($db) |
40 | 40 | { |
41 | - global $langs,$conf; |
|
41 | + global $langs, $conf; |
|
42 | 42 | |
43 | 43 | $this->db = $db; |
44 | 44 | |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | //$this->familyinfo = array('myownfamily' => array('position' => '01', 'label' => $langs->trans("MyOwnFamily"))); |
58 | 58 | |
59 | 59 | // Module label (no space allowed), used if translation string 'ModuledavName' not found (MyModue is name of module). |
60 | - $this->name = preg_replace('/^mod/i','',get_class($this)); |
|
60 | + $this->name = preg_replace('/^mod/i', '', get_class($this)); |
|
61 | 61 | // Module description, used if translation string 'ModuledavDesc' not found (MyModue is name of module). |
62 | 62 | $this->description = "davDescription"; |
63 | 63 | // Used only if file README.md and README-LL.md not found. |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | // Name of image file used for this module. |
71 | 71 | // If file is in theme/yourtheme/img directory under name object_pictovalue.png, use this->picto='pictovalue' |
72 | 72 | // If file is in module/img directory under name object_pictovalue.png, use this->picto='pictovalue@module' |
73 | - $this->picto='generic'; |
|
73 | + $this->picto = 'generic'; |
|
74 | 74 | |
75 | 75 | // Defined all module parts (triggers, login, substitutions, menus, css, etc...) |
76 | 76 | // for default path (eg: /dav/core/xxxxx) (0=disable, 1=enable) |
@@ -80,21 +80,21 @@ discard block |
||
80 | 80 | |
81 | 81 | // Data directories to create when module is enabled. |
82 | 82 | // Example: this->dirs = array("/dav/temp","/dav/subdir"); |
83 | - $this->dirs = array("/dav/temp","/dav/public","/dav/private"); |
|
83 | + $this->dirs = array("/dav/temp", "/dav/public", "/dav/private"); |
|
84 | 84 | |
85 | 85 | // Config pages. Put here list of php page, stored into dav/admin directory, to use to setup module. |
86 | 86 | $this->config_page_url = array("dav.php"); |
87 | 87 | |
88 | 88 | // Dependencies |
89 | - $this->hidden = false; // A condition to hide module |
|
90 | - $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled |
|
91 | - $this->requiredby = array(); // List of module ids to disable if this one is disabled |
|
92 | - $this->conflictwith = array(); // List of module class names as string this module is in conflict with |
|
89 | + $this->hidden = false; // A condition to hide module |
|
90 | + $this->depends = array(); // List of module class names as string that must be enabled if this module is enabled |
|
91 | + $this->requiredby = array(); // List of module ids to disable if this one is disabled |
|
92 | + $this->conflictwith = array(); // List of module class names as string this module is in conflict with |
|
93 | 93 | $this->langfiles = array("admin"); |
94 | - $this->phpmin = array(5,6); // Minimum version of PHP required by module |
|
95 | - $this->need_dolibarr_version = array(7,0); // Minimum version of Dolibarr required by module |
|
96 | - $this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','ES'='textes'...) |
|
97 | - $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...) |
|
94 | + $this->phpmin = array(5, 6); // Minimum version of PHP required by module |
|
95 | + $this->need_dolibarr_version = array(7, 0); // Minimum version of Dolibarr required by module |
|
96 | + $this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='textfr','ES'='textes'...) |
|
97 | + $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='textfr','ES'='textes'...) |
|
98 | 98 | //$this->automatic_activation = array('FR'=>'davWasAutomaticallyActivatedBecauseOfYourCountryChoice'); |
99 | 99 | //$this->always_enabled = true; // If true, can't be disabled |
100 | 100 | |
@@ -108,10 +108,10 @@ discard block |
||
108 | 108 | ); |
109 | 109 | |
110 | 110 | |
111 | - if (! isset($conf->dav) || ! isset($conf->dav->enabled)) |
|
111 | + if (!isset($conf->dav) || !isset($conf->dav->enabled)) |
|
112 | 112 | { |
113 | - $conf->dav=new stdClass(); |
|
114 | - $conf->dav->enabled=0; |
|
113 | + $conf->dav = new stdClass(); |
|
114 | + $conf->dav->enabled = 0; |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | |
@@ -145,7 +145,7 @@ discard block |
||
145 | 145 | |
146 | 146 | |
147 | 147 | // Dictionaries |
148 | - $this->dictionaries=array(); |
|
148 | + $this->dictionaries = array(); |
|
149 | 149 | /* Example: |
150 | 150 | $this->dictionaries=array( |
151 | 151 | 'langs'=>'mylangfile@dav', |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | |
183 | 183 | |
184 | 184 | // Permissions |
185 | - $this->rights = array(); // Permission array used by this module |
|
185 | + $this->rights = array(); // Permission array used by this module |
|
186 | 186 | |
187 | 187 | /* |
188 | 188 | $r=0; |
@@ -208,8 +208,8 @@ discard block |
||
208 | 208 | */ |
209 | 209 | |
210 | 210 | // Main menu entries |
211 | - $this->menu = array(); // List of menus to add |
|
212 | - $r=0; |
|
211 | + $this->menu = array(); // List of menus to add |
|
212 | + $r = 0; |
|
213 | 213 | |
214 | 214 | // Add here entries to declare new menus |
215 | 215 | |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | |
259 | 259 | |
260 | 260 | // Exports |
261 | - $r=1; |
|
261 | + $r = 1; |
|
262 | 262 | |
263 | 263 | /* BEGIN MODULEBUILDER EXPORT MYOBJECT */ |
264 | 264 | /* |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | * @param string $options Options when enabling module ('', 'noboxes') |
288 | 288 | * @return int 1 if OK, 0 if KO |
289 | 289 | */ |
290 | - public function init($options='') |
|
290 | + public function init($options = '') |
|
291 | 291 | { |
292 | 292 | //$this->_load_tables('/dav/sql/'); |
293 | 293 |
@@ -35,70 +35,70 @@ discard block |
||
35 | 35 | class modFacture extends DolibarrModules |
36 | 36 | { |
37 | 37 | |
38 | - /** |
|
39 | - * Constructor. Define names, constants, directories, boxes, permissions |
|
40 | - * |
|
41 | - * @param DoliDB $db Database handler |
|
42 | - */ |
|
43 | - function __construct($db) |
|
44 | - { |
|
45 | - global $conf, $user; |
|
46 | - |
|
47 | - $this->db = $db; |
|
48 | - $this->numero = 30; |
|
49 | - |
|
50 | - $this->family = "financial"; |
|
51 | - $this->module_position = '10'; |
|
52 | - // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) |
|
53 | - $this->name = preg_replace('/^mod/i', '', get_class($this)); |
|
54 | - $this->description = "Gestion des factures"; |
|
55 | - |
|
56 | - // Possible values for version are: 'development', 'experimental', 'dolibarr' or version |
|
57 | - $this->version = 'dolibarr'; |
|
58 | - |
|
59 | - $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); |
|
60 | - $this->picto = 'bill'; |
|
61 | - |
|
62 | - // Data directories to create when module is enabled |
|
63 | - $this->dirs = array("/facture/temp"); |
|
64 | - |
|
65 | - // Dependencies |
|
66 | - $this->depends = array('always'=>"modSociete"); |
|
67 | - $this->requiredby = array("modComptabilite", "modAccounting"); |
|
68 | - $this->conflictwith = array(); |
|
69 | - $this->langfiles = array("bills", "companies", "compta", "products"); |
|
70 | - $this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='text') |
|
71 | - $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='text') |
|
72 | - |
|
73 | - // Config pages |
|
74 | - $this->config_page_url = array("facture.php"); |
|
75 | - |
|
76 | - // Constants |
|
77 | - $this->const = array(); |
|
78 | - $r = 0; |
|
79 | - |
|
80 | - $this->const[$r][0] = "FACTURE_ADDON"; |
|
81 | - $this->const[$r][1] = "chaine"; |
|
82 | - $this->const[$r][2] = "mod_facture_terre"; |
|
83 | - $this->const[$r][3] = 'Name of numbering numerotation rules of invoice'; |
|
84 | - $this->const[$r][4] = 0; |
|
85 | - $r++; |
|
86 | - |
|
87 | - $this->const[$r][0] = "FACTURE_ADDON_PDF"; |
|
88 | - $this->const[$r][1] = "chaine"; |
|
89 | - $this->const[$r][2] = "crabe"; |
|
90 | - $this->const[$r][3] = 'Name of PDF model of invoice'; |
|
91 | - $this->const[$r][4] = 0; |
|
92 | - $r++; |
|
93 | - |
|
94 | - $this->const[$r][0] = "FACTURE_ADDON_PDF_ODT_PATH"; |
|
95 | - $this->const[$r][1] = "chaine"; |
|
96 | - $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/invoices"; |
|
97 | - $this->const[$r][3] = ""; |
|
98 | - $this->const[$r][4] = 0; |
|
99 | - $r++; |
|
100 | - |
|
101 | - /*$this->const[$r][0] = "FACTURE_DRAFT_WATERMARK"; |
|
38 | + /** |
|
39 | + * Constructor. Define names, constants, directories, boxes, permissions |
|
40 | + * |
|
41 | + * @param DoliDB $db Database handler |
|
42 | + */ |
|
43 | + function __construct($db) |
|
44 | + { |
|
45 | + global $conf, $user; |
|
46 | + |
|
47 | + $this->db = $db; |
|
48 | + $this->numero = 30; |
|
49 | + |
|
50 | + $this->family = "financial"; |
|
51 | + $this->module_position = '10'; |
|
52 | + // Module label (no space allowed), used if translation string 'ModuleXXXName' not found (where XXX is value of numeric property 'numero' of module) |
|
53 | + $this->name = preg_replace('/^mod/i', '', get_class($this)); |
|
54 | + $this->description = "Gestion des factures"; |
|
55 | + |
|
56 | + // Possible values for version are: 'development', 'experimental', 'dolibarr' or version |
|
57 | + $this->version = 'dolibarr'; |
|
58 | + |
|
59 | + $this->const_name = 'MAIN_MODULE_'.strtoupper($this->name); |
|
60 | + $this->picto = 'bill'; |
|
61 | + |
|
62 | + // Data directories to create when module is enabled |
|
63 | + $this->dirs = array("/facture/temp"); |
|
64 | + |
|
65 | + // Dependencies |
|
66 | + $this->depends = array('always'=>"modSociete"); |
|
67 | + $this->requiredby = array("modComptabilite", "modAccounting"); |
|
68 | + $this->conflictwith = array(); |
|
69 | + $this->langfiles = array("bills", "companies", "compta", "products"); |
|
70 | + $this->warnings_activation = array(); // Warning to show when we activate module. array('always'='text') or array('FR'='text') |
|
71 | + $this->warnings_activation_ext = array(); // Warning to show when we activate an external module. array('always'='text') or array('FR'='text') |
|
72 | + |
|
73 | + // Config pages |
|
74 | + $this->config_page_url = array("facture.php"); |
|
75 | + |
|
76 | + // Constants |
|
77 | + $this->const = array(); |
|
78 | + $r = 0; |
|
79 | + |
|
80 | + $this->const[$r][0] = "FACTURE_ADDON"; |
|
81 | + $this->const[$r][1] = "chaine"; |
|
82 | + $this->const[$r][2] = "mod_facture_terre"; |
|
83 | + $this->const[$r][3] = 'Name of numbering numerotation rules of invoice'; |
|
84 | + $this->const[$r][4] = 0; |
|
85 | + $r++; |
|
86 | + |
|
87 | + $this->const[$r][0] = "FACTURE_ADDON_PDF"; |
|
88 | + $this->const[$r][1] = "chaine"; |
|
89 | + $this->const[$r][2] = "crabe"; |
|
90 | + $this->const[$r][3] = 'Name of PDF model of invoice'; |
|
91 | + $this->const[$r][4] = 0; |
|
92 | + $r++; |
|
93 | + |
|
94 | + $this->const[$r][0] = "FACTURE_ADDON_PDF_ODT_PATH"; |
|
95 | + $this->const[$r][1] = "chaine"; |
|
96 | + $this->const[$r][2] = "DOL_DATA_ROOT/doctemplates/invoices"; |
|
97 | + $this->const[$r][3] = ""; |
|
98 | + $this->const[$r][4] = 0; |
|
99 | + $r++; |
|
100 | + |
|
101 | + /*$this->const[$r][0] = "FACTURE_DRAFT_WATERMARK"; |
|
102 | 102 | $this->const[$r][1] = "chaine"; |
103 | 103 | $this->const[$r][2] = "__(Draft)__"; |
104 | 104 | $this->const[$r][3] = 'Watermark to show on draft invoices'; |
@@ -106,264 +106,264 @@ discard block |
||
106 | 106 | $r++;*/ |
107 | 107 | |
108 | 108 | |
109 | - // Boxes |
|
110 | - //$this->boxes = array(0=>array(1=>'box_factures_imp.php'),1=>array(1=>'box_factures.php')); |
|
111 | - $this->boxes = array( |
|
112 | - 0=>array('file'=>'box_factures_imp.php', 'enabledbydefaulton'=>'Home'), |
|
113 | - 1=>array('file'=>'box_factures.php', 'enabledbydefaulton'=>'Home'), |
|
114 | - 2=>array('file'=>'box_graph_invoices_permonth.php', 'enabledbydefaulton'=>'Home') |
|
115 | - ); |
|
116 | - |
|
117 | - // Cronjobs |
|
118 | - $arraydate=dol_getdate(dol_now()); |
|
119 | - $datestart=dol_mktime(23, 0, 0, $arraydate['mon'], $arraydate['mday'], $arraydate['year']); |
|
120 | - $this->cronjobs = array( |
|
121 | - 0=>array('label'=>'RecurringInvoices', 'jobtype'=>'method', 'class'=>'compta/facture/class/facture-rec.class.php', 'objectname'=>'FactureRec', 'method'=>'createRecurringInvoices', 'parameters'=>'', 'comment'=>'Generate recurring invoices', 'frequency'=>1, 'unitfrequency'=>3600 * 24, 'priority'=>50, 'status'=>1, 'test'=>'$conf->facture->enabled', 'datestart'=>$datestart), |
|
122 | - ); |
|
123 | - |
|
124 | - // Permissions |
|
125 | - $this->rights = array(); |
|
126 | - $this->rights_class = 'facture'; |
|
127 | - $r = 0; |
|
128 | - |
|
129 | - $r++; |
|
130 | - $this->rights[$r][0] = 11; |
|
131 | - $this->rights[$r][1] = 'Read invoices'; |
|
132 | - $this->rights[$r][2] = 'a'; |
|
133 | - $this->rights[$r][3] = 0; |
|
134 | - $this->rights[$r][4] = 'lire'; |
|
135 | - |
|
136 | - $r++; |
|
137 | - $this->rights[$r][0] = 12; |
|
138 | - $this->rights[$r][1] = 'Create and update invoices'; |
|
139 | - $this->rights[$r][2] = 'a'; |
|
140 | - $this->rights[$r][3] = 0; |
|
141 | - $this->rights[$r][4] = 'creer'; |
|
142 | - |
|
143 | - // There is a particular permission for unvalidate because this may be not forbidden by some laws |
|
144 | - $r++; |
|
145 | - $this->rights[$r][0] = 13; |
|
146 | - $this->rights[$r][1] = 'Devalidate invoices'; |
|
147 | - $this->rights[$r][2] = 'a'; |
|
148 | - $this->rights[$r][3] = 0; |
|
109 | + // Boxes |
|
110 | + //$this->boxes = array(0=>array(1=>'box_factures_imp.php'),1=>array(1=>'box_factures.php')); |
|
111 | + $this->boxes = array( |
|
112 | + 0=>array('file'=>'box_factures_imp.php', 'enabledbydefaulton'=>'Home'), |
|
113 | + 1=>array('file'=>'box_factures.php', 'enabledbydefaulton'=>'Home'), |
|
114 | + 2=>array('file'=>'box_graph_invoices_permonth.php', 'enabledbydefaulton'=>'Home') |
|
115 | + ); |
|
116 | + |
|
117 | + // Cronjobs |
|
118 | + $arraydate=dol_getdate(dol_now()); |
|
119 | + $datestart=dol_mktime(23, 0, 0, $arraydate['mon'], $arraydate['mday'], $arraydate['year']); |
|
120 | + $this->cronjobs = array( |
|
121 | + 0=>array('label'=>'RecurringInvoices', 'jobtype'=>'method', 'class'=>'compta/facture/class/facture-rec.class.php', 'objectname'=>'FactureRec', 'method'=>'createRecurringInvoices', 'parameters'=>'', 'comment'=>'Generate recurring invoices', 'frequency'=>1, 'unitfrequency'=>3600 * 24, 'priority'=>50, 'status'=>1, 'test'=>'$conf->facture->enabled', 'datestart'=>$datestart), |
|
122 | + ); |
|
123 | + |
|
124 | + // Permissions |
|
125 | + $this->rights = array(); |
|
126 | + $this->rights_class = 'facture'; |
|
127 | + $r = 0; |
|
128 | + |
|
129 | + $r++; |
|
130 | + $this->rights[$r][0] = 11; |
|
131 | + $this->rights[$r][1] = 'Read invoices'; |
|
132 | + $this->rights[$r][2] = 'a'; |
|
133 | + $this->rights[$r][3] = 0; |
|
134 | + $this->rights[$r][4] = 'lire'; |
|
135 | + |
|
136 | + $r++; |
|
137 | + $this->rights[$r][0] = 12; |
|
138 | + $this->rights[$r][1] = 'Create and update invoices'; |
|
139 | + $this->rights[$r][2] = 'a'; |
|
140 | + $this->rights[$r][3] = 0; |
|
141 | + $this->rights[$r][4] = 'creer'; |
|
142 | + |
|
143 | + // There is a particular permission for unvalidate because this may be not forbidden by some laws |
|
144 | + $r++; |
|
145 | + $this->rights[$r][0] = 13; |
|
146 | + $this->rights[$r][1] = 'Devalidate invoices'; |
|
147 | + $this->rights[$r][2] = 'a'; |
|
148 | + $this->rights[$r][3] = 0; |
|
149 | + $this->rights[$r][4] = 'invoice_advance'; |
|
150 | + $this->rights[$r][5] = 'unvalidate'; |
|
151 | + |
|
152 | + $r++; |
|
153 | + $this->rights[$r][0] = 14; |
|
154 | + $this->rights[$r][1] = 'Validate invoices'; |
|
155 | + $this->rights[$r][2] = 'a'; |
|
156 | + $this->rights[$r][3] = 0; |
|
157 | + $this->rights[$r][4] = 'invoice_advance'; |
|
158 | + $this->rights[$r][5] = 'validate'; |
|
159 | + |
|
160 | + $r++; |
|
161 | + $this->rights[$r][0] = 15; |
|
162 | + $this->rights[$r][1] = 'Send invoices by email'; |
|
163 | + $this->rights[$r][2] = 'a'; |
|
164 | + $this->rights[$r][3] = 0; |
|
149 | 165 | $this->rights[$r][4] = 'invoice_advance'; |
150 | - $this->rights[$r][5] = 'unvalidate'; |
|
151 | - |
|
152 | - $r++; |
|
153 | - $this->rights[$r][0] = 14; |
|
154 | - $this->rights[$r][1] = 'Validate invoices'; |
|
155 | - $this->rights[$r][2] = 'a'; |
|
156 | - $this->rights[$r][3] = 0; |
|
157 | - $this->rights[$r][4] = 'invoice_advance'; |
|
158 | - $this->rights[$r][5] = 'validate'; |
|
159 | - |
|
160 | - $r++; |
|
161 | - $this->rights[$r][0] = 15; |
|
162 | - $this->rights[$r][1] = 'Send invoices by email'; |
|
163 | - $this->rights[$r][2] = 'a'; |
|
164 | - $this->rights[$r][3] = 0; |
|
165 | - $this->rights[$r][4] = 'invoice_advance'; |
|
166 | 166 | $this->rights[$r][5] = 'send'; |
167 | 167 | |
168 | - $r++; |
|
169 | - $this->rights[$r][0] = 16; |
|
170 | - $this->rights[$r][1] = 'Issue payments on invoices'; |
|
171 | - $this->rights[$r][2] = 'a'; |
|
172 | - $this->rights[$r][3] = 0; |
|
173 | - $this->rights[$r][4] = 'paiement'; |
|
174 | - |
|
175 | - $r++; |
|
176 | - $this->rights[$r][0] = 19; |
|
177 | - $this->rights[$r][1] = 'Delete invoices'; |
|
178 | - $this->rights[$r][2] = 'a'; |
|
179 | - $this->rights[$r][3] = 0; |
|
180 | - $this->rights[$r][4] = 'supprimer'; |
|
181 | - |
|
182 | - $r++; |
|
183 | - $this->rights[$r][0] = 1321; |
|
184 | - $this->rights[$r][1] = 'Export customer invoices, attributes and payments'; |
|
185 | - $this->rights[$r][2] = 'r'; |
|
186 | - $this->rights[$r][3] = 0; |
|
187 | - $this->rights[$r][4] = 'facture'; |
|
188 | - $this->rights[$r][5] = 'export'; |
|
189 | - |
|
190 | - $r++; |
|
191 | - $this->rights[$r][0] = 1322; |
|
192 | - $this->rights[$r][1] = 'Re-open a fully paid invoice'; |
|
193 | - $this->rights[$r][2] = 'r'; |
|
194 | - $this->rights[$r][3] = 0; |
|
195 | - $this->rights[$r][4] = 'invoice_advance'; |
|
196 | - $this->rights[$r][5] = 'reopen'; |
|
197 | - |
|
198 | - |
|
199 | - // Menus |
|
200 | - //------- |
|
201 | - $this->menu = 1; // This module add menu entries. They are coded into menu manager. |
|
202 | - |
|
203 | - |
|
204 | - // Exports |
|
205 | - //-------- |
|
206 | - $r = 1; |
|
207 | - |
|
208 | - $this->export_code[$r] = $this->rights_class.'_'.$r; |
|
209 | - $this->export_label[$r] = 'CustomersInvoicesAndInvoiceLines'; // Translation key (used only if key ExportDataset_xxx_z not found) |
|
210 | - $this->export_icon[$r] = 'invoice'; |
|
211 | - $this->export_permission[$r] = array(array("facture", "facture", "export", "other")); |
|
212 | - $this->export_fields_array[$r] = array( |
|
213 | - 's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 's.code_client'=>'CustomerCode', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode', 's.phone'=>'Phone', |
|
214 | - 's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.code_compta'=>'CustomerAccountancyCode', |
|
215 | - 's.code_compta_fournisseur'=>'SupplierAccountancyCode', 's.tva_intra'=>'VATIntra', |
|
216 | - 'f.rowid'=>"InvoiceId", 'f.ref'=>"InvoiceRef", 'f.ref_client'=>'RefCustomer', |
|
217 | - 'f.type'=>"Type", 'f.datec'=>"InvoiceDateCreation", 'f.datef'=>"DateInvoice", 'f.date_lim_reglement'=>"DateDue", 'f.total'=>"TotalHT", |
|
218 | - 'f.total_ttc'=>"TotalTTC", 'f.tva'=>"TotalVAT", 'none.rest'=>'Rest', 'f.paye'=>"InvoicePaid", 'f.fk_statut'=>'InvoiceStatus', |
|
219 | - 'f.note_private'=>"NotePrivate", 'f.note_public'=>"NotePublic", 'f.fk_user_author'=>'CreatedById', 'uc.login'=>'CreatedByLogin', |
|
220 | - 'f.fk_user_valid'=>'ValidatedById', 'uv.login'=>'ValidatedByLogin', 'pj.ref'=>'ProjectRef', 'fd.rowid'=>'LineId', 'fd.description'=>"LineDescription", |
|
221 | - 'fd.subprice'=>"LineUnitPrice", 'fd.tva_tx'=>"LineVATRate", 'fd.qty'=>"LineQty", 'fd.total_ht'=>"LineTotalHT", 'fd.total_tva'=>"LineTotalVAT", |
|
222 | - 'fd.total_ttc'=>"LineTotalTTC", 'fd.date_start'=>"DateStart", 'fd.date_end'=>"DateEnd", 'fd.special_code'=>'SpecialCode', |
|
223 | - 'fd.product_type'=>"TypeOfLineServiceOrProduct", 'fd.fk_product'=>'ProductId', 'p.ref'=>'ProductRef', 'p.label'=>'ProductLabel', |
|
224 | - 'p.accountancy_code_sell'=>'ProductAccountancySellCode' |
|
225 | - ); |
|
226 | - $this->export_TypeFields_array[$r] = array( |
|
227 | - 's.rowid'=>'Numeric', 's.nom'=>'Text', 's.code_client'=>'Text', 's.address'=>'Text', 's.zip'=>'Text', 's.town'=>'Text', 'c.code'=>'Text', 's.phone'=>'Text', 's.siren'=>'Text', |
|
228 | - 's.siret'=>'Text', 's.ape'=>'Text', 's.idprof4'=>'Text', 's.code_compta'=>'Text', 's.code_compta_fournisseur'=>'Text', 's.tva_intra'=>'Text', |
|
229 | - 'f.rowid'=>'Numeric', 'f.ref'=>"Text", 'f.ref_client'=>'Text', 'f.type'=>"Numeric", 'f.datec'=>"Date", 'f.datef'=>"Date", 'f.date_lim_reglement'=>"Date", |
|
230 | - 'f.total'=>"Numeric", 'f.total_ttc'=>"Numeric", 'f.tva'=>"Numeric", 'none.rest'=>"NumericCompute", 'f.paye'=>"Boolean", 'f.fk_statut'=>'Numeric', |
|
231 | - 'f.note_private'=>"Text", 'f.note_public'=>"Text", 'f.fk_user_author'=>'Numeric', 'uc.login'=>'Text', 'f.fk_user_valid'=>'Numeric', 'uv.login'=>'Text', |
|
232 | - 'pj.ref'=>'Text', 'fd.rowid'=>'Numeric', 'fd.label'=>'Text', 'fd.description'=>"Text", 'fd.subprice'=>"Numeric", 'fd.tva_tx'=>"Numeric", |
|
233 | - 'fd.qty'=>"Numeric", 'fd.total_ht'=>"Numeric", 'fd.total_tva'=>"Numeric", 'fd.total_ttc'=>"Numeric", 'fd.date_start'=>"Date", 'fd.date_end'=>"Date", |
|
234 | - 'fd.special_code'=>'Numeric', 'fd.product_type'=>"Numeric", 'fd.fk_product'=>'List:product:label', 'p.ref'=>'Text', 'p.label'=>'Text', |
|
235 | - 'p.accountancy_code_sell'=>'Text' |
|
236 | - ); |
|
237 | - $this->export_entities_array[$r] = array( |
|
238 | - 's.rowid'=>"company", 's.nom'=>'company', 's.code_client'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company', 'c.code'=>'company', 's.phone'=>'company', |
|
239 | - 's.siren'=>'company', 's.siret'=>'company', 's.ape'=>'company', 's.idprof4'=>'company', 's.code_compta'=>'company', 's.code_compta_fournisseur'=>'company', |
|
240 | - 's.tva_intra'=>'company', 'pj.ref'=>'project', 'fd.rowid'=>'invoice_line', 'fd.label'=>"invoice_line", 'fd.description'=>"invoice_line", |
|
241 | - 'fd.subprice'=>"invoice_line", 'fd.total_ht'=>"invoice_line", 'fd.total_tva'=>"invoice_line", 'fd.total_ttc'=>"invoice_line", 'fd.tva_tx'=>"invoice_line", |
|
242 | - 'fd.qty'=>"invoice_line", 'fd.date_start'=>"invoice_line", 'fd.date_end'=>"invoice_line", 'fd.special_code'=>'invoice_line', |
|
243 | - 'fd.product_type'=>'invoice_line', 'fd.fk_product'=>'product', 'p.ref'=>'product', 'p.label'=>'product', 'p.accountancy_code_sell'=>'product', |
|
244 | - 'f.fk_user_author'=>'user', 'uc.login'=>'user', 'f.fk_user_valid'=>'user', 'uv.login'=>'user' |
|
245 | - ); |
|
246 | - $this->export_special_array[$r] = array('none.rest'=>'getRemainToPay'); |
|
247 | - $this->export_dependencies_array[$r] = array('invoice_line'=>'fd.rowid', 'product'=>'fd.rowid', 'none.rest'=>array('f.rowid', 'f.total_ttc')); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them |
|
248 | - $keyforselect = 'facture'; $keyforelement = 'invoice'; $keyforaliasextra = 'extra'; |
|
249 | - include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; |
|
250 | - $keyforselect = 'facturedet'; $keyforelement = 'invoice_line'; $keyforaliasextra = 'extra2'; |
|
251 | - include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; |
|
252 | - $keyforselect = 'product'; $keyforelement = 'product'; $keyforaliasextra = 'extra3'; |
|
253 | - include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; |
|
254 | - $this->export_sql_start[$r] = 'SELECT DISTINCT '; |
|
255 | - $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s'; |
|
256 | - 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'; |
|
257 | - $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid,'; |
|
258 | - $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'facture as f'; |
|
259 | - $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON f.fk_projet = pj.rowid'; |
|
260 | - $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uc ON f.fk_user_author = uc.rowid'; |
|
261 | - $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON f.fk_user_valid = uv.rowid'; |
|
262 | - $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_extrafields as extra ON f.rowid = extra.fk_object'; |
|
263 | - $this->export_sql_end[$r] .= ' , '.MAIN_DB_PREFIX.'facturedet as fd'; |
|
264 | - $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet_extrafields as extra2 on fd.rowid = extra2.fk_object'; |
|
265 | - $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)'; |
|
266 | - $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra3 on p.rowid = extra3.fk_object'; |
|
267 | - $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture'; |
|
268 | - $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('invoice').')'; |
|
269 | - if (isset($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' AND sc.fk_user = '.$user->id; |
|
270 | - $r++; |
|
271 | - |
|
272 | - $this->export_code[$r] = $this->rights_class.'_'.$r; |
|
273 | - $this->export_label[$r] = 'CustomersInvoicesAndPayments'; // Translation key (used only if key ExportDataset_xxx_z not found) |
|
274 | - $this->export_icon[$r] = 'invoice'; |
|
275 | - $this->export_permission[$r] = array(array("facture", "facture", "export")); |
|
276 | - $this->export_fields_array[$r] = array( |
|
277 | - 's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 's.code_client'=>'CustomerCode', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode', 's.phone'=>'Phone', |
|
278 | - 's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.code_compta'=>'CustomerAccountancyCode', |
|
279 | - 's.code_compta_fournisseur'=>'SupplierAccountancyCode', 's.tva_intra'=>'VATIntra', |
|
280 | - 'f.rowid'=>"InvoiceId", 'f.ref'=>"InvoiceRef", 'f.ref_client'=>'RefCustomer', |
|
281 | - 'f.type'=>"Type", 'f.datec'=>"InvoiceDateCreation", 'f.datef'=>"DateInvoice", 'f.date_lim_reglement'=>"DateDue", 'f.total'=>"TotalHT", |
|
282 | - 'f.total_ttc'=>"TotalTTC", 'f.tva'=>"TotalVAT", 'none.rest'=>'Rest', 'f.paye'=>"InvoicePaid", 'f.fk_statut'=>'InvoiceStatus', |
|
283 | - 'f.note_private'=>"NotePrivate", 'f.note_public'=>"NotePublic", 'f.fk_user_author'=>'CreatedById', 'uc.login'=>'CreatedByLogin', |
|
284 | - 'f.fk_user_valid'=>'ValidatedById', 'uv.login'=>'ValidatedByLogin', 'pj.ref'=>'ProjectRef', 'p.rowid'=>'PaymentId', 'p.ref'=>'PaymentRef', |
|
285 | - 'p.amount'=>'AmountPayment', 'pf.amount'=>'AmountPaymentDistributedOnInvoice', 'p.datep'=>'DatePayment', 'p.num_paiement'=>'PaymentNumber', |
|
286 | - 'pt.code'=>'CodePaymentMode', 'pt.libelle'=>'LabelPaymentMode', 'p.note'=>'PaymentNote', 'p.fk_bank'=>'IdTransaction', 'ba.ref'=>'AccountRef' |
|
287 | - ); |
|
288 | - $this->export_TypeFields_array[$r] = array( |
|
289 | - 's.rowid'=>'Numeric', 's.nom'=>'Text', 's.code_client'=>'Text', 's.address'=>'Text', 's.zip'=>'Text', 's.town'=>'Text', 'c.code'=>'Text', 's.phone'=>'Text', 's.siren'=>'Text', |
|
290 | - 's.siret'=>'Text', 's.ape'=>'Text', 's.idprof4'=>'Text', 's.code_compta'=>'Text', 's.code_compta_fournisseur'=>'Text', 's.tva_intra'=>'Text', |
|
291 | - 'f.rowid'=>"Numeric", 'f.ref'=>"Text", 'f.ref_client'=>'Text', 'f.type'=>"Numeric", 'f.datec'=>"Date", 'f.datef'=>"Date", 'f.date_lim_reglement'=>"Date", |
|
292 | - 'f.total'=>"Numeric", 'f.total_ttc'=>"Numeric", 'f.tva'=>"Numeric", 'none.rest'=>'NumericCompute', 'f.paye'=>"Boolean", 'f.fk_statut'=>'Status', |
|
293 | - 'f.note_private'=>"Text", 'f.note_public'=>"Text", 'f.fk_user_author'=>'Numeric', 'uc.login'=>'Text', 'f.fk_user_valid'=>'Numeric', 'uv.login'=>'Text', |
|
294 | - 'pj.ref'=>'Text', 'p.amount'=>'Numeric', 'pf.amount'=>'Numeric', 'p.rowid'=>'Numeric', 'p.ref'=>'Text', 'p.datep'=>'Date', 'p.num_paiement'=>'Numeric', |
|
295 | - 'p.fk_bank'=>'Numeric', 'p.note'=>'Text', 'pt.code'=>'Text', 'pt.libelle'=>'text', 'ba.ref'=>'Text' |
|
296 | - ); |
|
297 | - $this->export_entities_array[$r] = array( |
|
298 | - 's.rowid'=>"company", 's.nom'=>'company', 's.code_client'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company', 'c.code'=>'company', 's.phone'=>'company', |
|
299 | - 's.siren'=>'company', 's.siret'=>'company', 's.ape'=>'company', 's.idprof4'=>'company', 's.code_compta'=>'company', 's.code_compta_fournisseur'=>'company', |
|
300 | - 's.tva_intra'=>'company', 'pj.ref'=>'project', 'p.rowid'=>'payment', 'p.ref'=>'payment', 'p.amount'=>'payment', 'pf.amount'=>'payment', 'p.datep'=>'payment', |
|
301 | - 'p.num_paiement'=>'payment', 'pt.code'=>'payment', 'pt.libelle'=>'payment', 'p.note'=>'payment', 'f.fk_user_author'=>'user', 'uc.login'=>'user', |
|
302 | - 'f.fk_user_valid'=>'user', 'uv.login'=>'user', 'p.fk_bank'=>'account', 'ba.ref'=>'account' |
|
303 | - ); |
|
304 | - $this->export_special_array[$r] = array('none.rest'=>'getRemainToPay'); |
|
305 | - $this->export_dependencies_array[$r] = array('payment'=>'p.rowid', 'none.rest'=>array('f.rowid', 'f.total_ttc')); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them |
|
306 | - $keyforselect = 'facture'; $keyforelement = 'invoice'; $keyforaliasextra = 'extra'; |
|
307 | - include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; |
|
308 | - $this->export_sql_start[$r]='SELECT DISTINCT '; |
|
309 | - $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s'; |
|
310 | - 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'; |
|
311 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid,'; |
|
312 | - $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'facture as f'; |
|
313 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON f.fk_projet = pj.rowid'; |
|
314 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as uc ON f.fk_user_author = uc.rowid'; |
|
315 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON f.fk_user_valid = uv.rowid'; |
|
316 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'facture_extrafields as extra ON f.rowid = extra.fk_object'; |
|
317 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid'; |
|
318 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiement as p ON pf.fk_paiement = p.rowid'; |
|
319 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as pt ON pt.id = p.fk_paiement'; |
|
320 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON b.rowid = p.fk_bank'; |
|
321 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON ba.rowid = b.fk_account'; |
|
322 | - $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid'; |
|
323 | - $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('invoice').')'; |
|
324 | - if (isset($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id; |
|
325 | - $r++; |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * Function called when module is enabled. |
|
331 | - * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. |
|
332 | - * It also creates data directories |
|
333 | - * |
|
168 | + $r++; |
|
169 | + $this->rights[$r][0] = 16; |
|
170 | + $this->rights[$r][1] = 'Issue payments on invoices'; |
|
171 | + $this->rights[$r][2] = 'a'; |
|
172 | + $this->rights[$r][3] = 0; |
|
173 | + $this->rights[$r][4] = 'paiement'; |
|
174 | + |
|
175 | + $r++; |
|
176 | + $this->rights[$r][0] = 19; |
|
177 | + $this->rights[$r][1] = 'Delete invoices'; |
|
178 | + $this->rights[$r][2] = 'a'; |
|
179 | + $this->rights[$r][3] = 0; |
|
180 | + $this->rights[$r][4] = 'supprimer'; |
|
181 | + |
|
182 | + $r++; |
|
183 | + $this->rights[$r][0] = 1321; |
|
184 | + $this->rights[$r][1] = 'Export customer invoices, attributes and payments'; |
|
185 | + $this->rights[$r][2] = 'r'; |
|
186 | + $this->rights[$r][3] = 0; |
|
187 | + $this->rights[$r][4] = 'facture'; |
|
188 | + $this->rights[$r][5] = 'export'; |
|
189 | + |
|
190 | + $r++; |
|
191 | + $this->rights[$r][0] = 1322; |
|
192 | + $this->rights[$r][1] = 'Re-open a fully paid invoice'; |
|
193 | + $this->rights[$r][2] = 'r'; |
|
194 | + $this->rights[$r][3] = 0; |
|
195 | + $this->rights[$r][4] = 'invoice_advance'; |
|
196 | + $this->rights[$r][5] = 'reopen'; |
|
197 | + |
|
198 | + |
|
199 | + // Menus |
|
200 | + //------- |
|
201 | + $this->menu = 1; // This module add menu entries. They are coded into menu manager. |
|
202 | + |
|
203 | + |
|
204 | + // Exports |
|
205 | + //-------- |
|
206 | + $r = 1; |
|
207 | + |
|
208 | + $this->export_code[$r] = $this->rights_class.'_'.$r; |
|
209 | + $this->export_label[$r] = 'CustomersInvoicesAndInvoiceLines'; // Translation key (used only if key ExportDataset_xxx_z not found) |
|
210 | + $this->export_icon[$r] = 'invoice'; |
|
211 | + $this->export_permission[$r] = array(array("facture", "facture", "export", "other")); |
|
212 | + $this->export_fields_array[$r] = array( |
|
213 | + 's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 's.code_client'=>'CustomerCode', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode', 's.phone'=>'Phone', |
|
214 | + 's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.code_compta'=>'CustomerAccountancyCode', |
|
215 | + 's.code_compta_fournisseur'=>'SupplierAccountancyCode', 's.tva_intra'=>'VATIntra', |
|
216 | + 'f.rowid'=>"InvoiceId", 'f.ref'=>"InvoiceRef", 'f.ref_client'=>'RefCustomer', |
|
217 | + 'f.type'=>"Type", 'f.datec'=>"InvoiceDateCreation", 'f.datef'=>"DateInvoice", 'f.date_lim_reglement'=>"DateDue", 'f.total'=>"TotalHT", |
|
218 | + 'f.total_ttc'=>"TotalTTC", 'f.tva'=>"TotalVAT", 'none.rest'=>'Rest', 'f.paye'=>"InvoicePaid", 'f.fk_statut'=>'InvoiceStatus', |
|
219 | + 'f.note_private'=>"NotePrivate", 'f.note_public'=>"NotePublic", 'f.fk_user_author'=>'CreatedById', 'uc.login'=>'CreatedByLogin', |
|
220 | + 'f.fk_user_valid'=>'ValidatedById', 'uv.login'=>'ValidatedByLogin', 'pj.ref'=>'ProjectRef', 'fd.rowid'=>'LineId', 'fd.description'=>"LineDescription", |
|
221 | + 'fd.subprice'=>"LineUnitPrice", 'fd.tva_tx'=>"LineVATRate", 'fd.qty'=>"LineQty", 'fd.total_ht'=>"LineTotalHT", 'fd.total_tva'=>"LineTotalVAT", |
|
222 | + 'fd.total_ttc'=>"LineTotalTTC", 'fd.date_start'=>"DateStart", 'fd.date_end'=>"DateEnd", 'fd.special_code'=>'SpecialCode', |
|
223 | + 'fd.product_type'=>"TypeOfLineServiceOrProduct", 'fd.fk_product'=>'ProductId', 'p.ref'=>'ProductRef', 'p.label'=>'ProductLabel', |
|
224 | + 'p.accountancy_code_sell'=>'ProductAccountancySellCode' |
|
225 | + ); |
|
226 | + $this->export_TypeFields_array[$r] = array( |
|
227 | + 's.rowid'=>'Numeric', 's.nom'=>'Text', 's.code_client'=>'Text', 's.address'=>'Text', 's.zip'=>'Text', 's.town'=>'Text', 'c.code'=>'Text', 's.phone'=>'Text', 's.siren'=>'Text', |
|
228 | + 's.siret'=>'Text', 's.ape'=>'Text', 's.idprof4'=>'Text', 's.code_compta'=>'Text', 's.code_compta_fournisseur'=>'Text', 's.tva_intra'=>'Text', |
|
229 | + 'f.rowid'=>'Numeric', 'f.ref'=>"Text", 'f.ref_client'=>'Text', 'f.type'=>"Numeric", 'f.datec'=>"Date", 'f.datef'=>"Date", 'f.date_lim_reglement'=>"Date", |
|
230 | + 'f.total'=>"Numeric", 'f.total_ttc'=>"Numeric", 'f.tva'=>"Numeric", 'none.rest'=>"NumericCompute", 'f.paye'=>"Boolean", 'f.fk_statut'=>'Numeric', |
|
231 | + 'f.note_private'=>"Text", 'f.note_public'=>"Text", 'f.fk_user_author'=>'Numeric', 'uc.login'=>'Text', 'f.fk_user_valid'=>'Numeric', 'uv.login'=>'Text', |
|
232 | + 'pj.ref'=>'Text', 'fd.rowid'=>'Numeric', 'fd.label'=>'Text', 'fd.description'=>"Text", 'fd.subprice'=>"Numeric", 'fd.tva_tx'=>"Numeric", |
|
233 | + 'fd.qty'=>"Numeric", 'fd.total_ht'=>"Numeric", 'fd.total_tva'=>"Numeric", 'fd.total_ttc'=>"Numeric", 'fd.date_start'=>"Date", 'fd.date_end'=>"Date", |
|
234 | + 'fd.special_code'=>'Numeric', 'fd.product_type'=>"Numeric", 'fd.fk_product'=>'List:product:label', 'p.ref'=>'Text', 'p.label'=>'Text', |
|
235 | + 'p.accountancy_code_sell'=>'Text' |
|
236 | + ); |
|
237 | + $this->export_entities_array[$r] = array( |
|
238 | + 's.rowid'=>"company", 's.nom'=>'company', 's.code_client'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company', 'c.code'=>'company', 's.phone'=>'company', |
|
239 | + 's.siren'=>'company', 's.siret'=>'company', 's.ape'=>'company', 's.idprof4'=>'company', 's.code_compta'=>'company', 's.code_compta_fournisseur'=>'company', |
|
240 | + 's.tva_intra'=>'company', 'pj.ref'=>'project', 'fd.rowid'=>'invoice_line', 'fd.label'=>"invoice_line", 'fd.description'=>"invoice_line", |
|
241 | + 'fd.subprice'=>"invoice_line", 'fd.total_ht'=>"invoice_line", 'fd.total_tva'=>"invoice_line", 'fd.total_ttc'=>"invoice_line", 'fd.tva_tx'=>"invoice_line", |
|
242 | + 'fd.qty'=>"invoice_line", 'fd.date_start'=>"invoice_line", 'fd.date_end'=>"invoice_line", 'fd.special_code'=>'invoice_line', |
|
243 | + 'fd.product_type'=>'invoice_line', 'fd.fk_product'=>'product', 'p.ref'=>'product', 'p.label'=>'product', 'p.accountancy_code_sell'=>'product', |
|
244 | + 'f.fk_user_author'=>'user', 'uc.login'=>'user', 'f.fk_user_valid'=>'user', 'uv.login'=>'user' |
|
245 | + ); |
|
246 | + $this->export_special_array[$r] = array('none.rest'=>'getRemainToPay'); |
|
247 | + $this->export_dependencies_array[$r] = array('invoice_line'=>'fd.rowid', 'product'=>'fd.rowid', 'none.rest'=>array('f.rowid', 'f.total_ttc')); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them |
|
248 | + $keyforselect = 'facture'; $keyforelement = 'invoice'; $keyforaliasextra = 'extra'; |
|
249 | + include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; |
|
250 | + $keyforselect = 'facturedet'; $keyforelement = 'invoice_line'; $keyforaliasextra = 'extra2'; |
|
251 | + include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; |
|
252 | + $keyforselect = 'product'; $keyforelement = 'product'; $keyforaliasextra = 'extra3'; |
|
253 | + include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; |
|
254 | + $this->export_sql_start[$r] = 'SELECT DISTINCT '; |
|
255 | + $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s'; |
|
256 | + 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'; |
|
257 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid,'; |
|
258 | + $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'facture as f'; |
|
259 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON f.fk_projet = pj.rowid'; |
|
260 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uc ON f.fk_user_author = uc.rowid'; |
|
261 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON f.fk_user_valid = uv.rowid'; |
|
262 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_extrafields as extra ON f.rowid = extra.fk_object'; |
|
263 | + $this->export_sql_end[$r] .= ' , '.MAIN_DB_PREFIX.'facturedet as fd'; |
|
264 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facturedet_extrafields as extra2 on fd.rowid = extra2.fk_object'; |
|
265 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)'; |
|
266 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra3 on p.rowid = extra3.fk_object'; |
|
267 | + $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture'; |
|
268 | + $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('invoice').')'; |
|
269 | + if (isset($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' AND sc.fk_user = '.$user->id; |
|
270 | + $r++; |
|
271 | + |
|
272 | + $this->export_code[$r] = $this->rights_class.'_'.$r; |
|
273 | + $this->export_label[$r] = 'CustomersInvoicesAndPayments'; // Translation key (used only if key ExportDataset_xxx_z not found) |
|
274 | + $this->export_icon[$r] = 'invoice'; |
|
275 | + $this->export_permission[$r] = array(array("facture", "facture", "export")); |
|
276 | + $this->export_fields_array[$r] = array( |
|
277 | + 's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 's.code_client'=>'CustomerCode', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode', 's.phone'=>'Phone', |
|
278 | + 's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.code_compta'=>'CustomerAccountancyCode', |
|
279 | + 's.code_compta_fournisseur'=>'SupplierAccountancyCode', 's.tva_intra'=>'VATIntra', |
|
280 | + 'f.rowid'=>"InvoiceId", 'f.ref'=>"InvoiceRef", 'f.ref_client'=>'RefCustomer', |
|
281 | + 'f.type'=>"Type", 'f.datec'=>"InvoiceDateCreation", 'f.datef'=>"DateInvoice", 'f.date_lim_reglement'=>"DateDue", 'f.total'=>"TotalHT", |
|
282 | + 'f.total_ttc'=>"TotalTTC", 'f.tva'=>"TotalVAT", 'none.rest'=>'Rest', 'f.paye'=>"InvoicePaid", 'f.fk_statut'=>'InvoiceStatus', |
|
283 | + 'f.note_private'=>"NotePrivate", 'f.note_public'=>"NotePublic", 'f.fk_user_author'=>'CreatedById', 'uc.login'=>'CreatedByLogin', |
|
284 | + 'f.fk_user_valid'=>'ValidatedById', 'uv.login'=>'ValidatedByLogin', 'pj.ref'=>'ProjectRef', 'p.rowid'=>'PaymentId', 'p.ref'=>'PaymentRef', |
|
285 | + 'p.amount'=>'AmountPayment', 'pf.amount'=>'AmountPaymentDistributedOnInvoice', 'p.datep'=>'DatePayment', 'p.num_paiement'=>'PaymentNumber', |
|
286 | + 'pt.code'=>'CodePaymentMode', 'pt.libelle'=>'LabelPaymentMode', 'p.note'=>'PaymentNote', 'p.fk_bank'=>'IdTransaction', 'ba.ref'=>'AccountRef' |
|
287 | + ); |
|
288 | + $this->export_TypeFields_array[$r] = array( |
|
289 | + 's.rowid'=>'Numeric', 's.nom'=>'Text', 's.code_client'=>'Text', 's.address'=>'Text', 's.zip'=>'Text', 's.town'=>'Text', 'c.code'=>'Text', 's.phone'=>'Text', 's.siren'=>'Text', |
|
290 | + 's.siret'=>'Text', 's.ape'=>'Text', 's.idprof4'=>'Text', 's.code_compta'=>'Text', 's.code_compta_fournisseur'=>'Text', 's.tva_intra'=>'Text', |
|
291 | + 'f.rowid'=>"Numeric", 'f.ref'=>"Text", 'f.ref_client'=>'Text', 'f.type'=>"Numeric", 'f.datec'=>"Date", 'f.datef'=>"Date", 'f.date_lim_reglement'=>"Date", |
|
292 | + 'f.total'=>"Numeric", 'f.total_ttc'=>"Numeric", 'f.tva'=>"Numeric", 'none.rest'=>'NumericCompute', 'f.paye'=>"Boolean", 'f.fk_statut'=>'Status', |
|
293 | + 'f.note_private'=>"Text", 'f.note_public'=>"Text", 'f.fk_user_author'=>'Numeric', 'uc.login'=>'Text', 'f.fk_user_valid'=>'Numeric', 'uv.login'=>'Text', |
|
294 | + 'pj.ref'=>'Text', 'p.amount'=>'Numeric', 'pf.amount'=>'Numeric', 'p.rowid'=>'Numeric', 'p.ref'=>'Text', 'p.datep'=>'Date', 'p.num_paiement'=>'Numeric', |
|
295 | + 'p.fk_bank'=>'Numeric', 'p.note'=>'Text', 'pt.code'=>'Text', 'pt.libelle'=>'text', 'ba.ref'=>'Text' |
|
296 | + ); |
|
297 | + $this->export_entities_array[$r] = array( |
|
298 | + 's.rowid'=>"company", 's.nom'=>'company', 's.code_client'=>'company', 's.address'=>'company', 's.zip'=>'company', 's.town'=>'company', 'c.code'=>'company', 's.phone'=>'company', |
|
299 | + 's.siren'=>'company', 's.siret'=>'company', 's.ape'=>'company', 's.idprof4'=>'company', 's.code_compta'=>'company', 's.code_compta_fournisseur'=>'company', |
|
300 | + 's.tva_intra'=>'company', 'pj.ref'=>'project', 'p.rowid'=>'payment', 'p.ref'=>'payment', 'p.amount'=>'payment', 'pf.amount'=>'payment', 'p.datep'=>'payment', |
|
301 | + 'p.num_paiement'=>'payment', 'pt.code'=>'payment', 'pt.libelle'=>'payment', 'p.note'=>'payment', 'f.fk_user_author'=>'user', 'uc.login'=>'user', |
|
302 | + 'f.fk_user_valid'=>'user', 'uv.login'=>'user', 'p.fk_bank'=>'account', 'ba.ref'=>'account' |
|
303 | + ); |
|
304 | + $this->export_special_array[$r] = array('none.rest'=>'getRemainToPay'); |
|
305 | + $this->export_dependencies_array[$r] = array('payment'=>'p.rowid', 'none.rest'=>array('f.rowid', 'f.total_ttc')); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them |
|
306 | + $keyforselect = 'facture'; $keyforelement = 'invoice'; $keyforaliasextra = 'extra'; |
|
307 | + include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; |
|
308 | + $this->export_sql_start[$r]='SELECT DISTINCT '; |
|
309 | + $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s'; |
|
310 | + 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'; |
|
311 | + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid,'; |
|
312 | + $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'facture as f'; |
|
313 | + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON f.fk_projet = pj.rowid'; |
|
314 | + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as uc ON f.fk_user_author = uc.rowid'; |
|
315 | + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON f.fk_user_valid = uv.rowid'; |
|
316 | + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'facture_extrafields as extra ON f.rowid = extra.fk_object'; |
|
317 | + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid'; |
|
318 | + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiement as p ON pf.fk_paiement = p.rowid'; |
|
319 | + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as pt ON pt.id = p.fk_paiement'; |
|
320 | + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON b.rowid = p.fk_bank'; |
|
321 | + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON ba.rowid = b.fk_account'; |
|
322 | + $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid'; |
|
323 | + $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('invoice').')'; |
|
324 | + if (isset($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id; |
|
325 | + $r++; |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * Function called when module is enabled. |
|
331 | + * The init function add constants, boxes, permissions and menus (defined in constructor) into Dolibarr database. |
|
332 | + * It also creates data directories |
|
333 | + * |
|
334 | 334 | * @param string $options Options when enabling module ('', 'newboxdefonly', 'noboxes') |
335 | - * @return int 1 if OK, 0 if KO |
|
336 | - */ |
|
337 | - function init($options = '') |
|
338 | - { |
|
339 | - global $conf, $langs; |
|
340 | - |
|
341 | - // Remove permissions and default values |
|
342 | - $this->remove($options); |
|
343 | - |
|
344 | - //ODT template |
|
345 | - $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/invoices/template_invoice.odt'; |
|
346 | - $dirodt = DOL_DATA_ROOT.'/doctemplates/invoices'; |
|
347 | - $dest = $dirodt.'/template_invoice.odt'; |
|
348 | - |
|
349 | - if (file_exists($src) && !file_exists($dest)) |
|
350 | - { |
|
351 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
352 | - dol_mkdir($dirodt); |
|
353 | - $result = dol_copy($src, $dest, 0, 0); |
|
354 | - if ($result < 0) |
|
355 | - { |
|
356 | - $langs->load("errors"); |
|
357 | - $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest); |
|
358 | - return 0; |
|
359 | - } |
|
360 | - } |
|
361 | - |
|
362 | - $sql = array( |
|
363 | - "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[1][2])."' AND type = 'invoice' AND entity = ".$conf->entity, |
|
364 | - "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[1][2])."','invoice',".$conf->entity.")" |
|
365 | - ); |
|
366 | - |
|
367 | - return $this->_init($sql, $options); |
|
368 | - } |
|
335 | + * @return int 1 if OK, 0 if KO |
|
336 | + */ |
|
337 | + function init($options = '') |
|
338 | + { |
|
339 | + global $conf, $langs; |
|
340 | + |
|
341 | + // Remove permissions and default values |
|
342 | + $this->remove($options); |
|
343 | + |
|
344 | + //ODT template |
|
345 | + $src = DOL_DOCUMENT_ROOT.'/install/doctemplates/invoices/template_invoice.odt'; |
|
346 | + $dirodt = DOL_DATA_ROOT.'/doctemplates/invoices'; |
|
347 | + $dest = $dirodt.'/template_invoice.odt'; |
|
348 | + |
|
349 | + if (file_exists($src) && !file_exists($dest)) |
|
350 | + { |
|
351 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
|
352 | + dol_mkdir($dirodt); |
|
353 | + $result = dol_copy($src, $dest, 0, 0); |
|
354 | + if ($result < 0) |
|
355 | + { |
|
356 | + $langs->load("errors"); |
|
357 | + $this->error = $langs->trans('ErrorFailToCopyFile', $src, $dest); |
|
358 | + return 0; |
|
359 | + } |
|
360 | + } |
|
361 | + |
|
362 | + $sql = array( |
|
363 | + "DELETE FROM ".MAIN_DB_PREFIX."document_model WHERE nom = '".$this->db->escape($this->const[1][2])."' AND type = 'invoice' AND entity = ".$conf->entity, |
|
364 | + "INSERT INTO ".MAIN_DB_PREFIX."document_model (nom, type, entity) VALUES('".$this->db->escape($this->const[1][2])."','invoice',".$conf->entity.")" |
|
365 | + ); |
|
366 | + |
|
367 | + return $this->_init($sql, $options); |
|
368 | + } |
|
369 | 369 | } |
@@ -115,8 +115,8 @@ discard block |
||
115 | 115 | ); |
116 | 116 | |
117 | 117 | // Cronjobs |
118 | - $arraydate=dol_getdate(dol_now()); |
|
119 | - $datestart=dol_mktime(23, 0, 0, $arraydate['mon'], $arraydate['mday'], $arraydate['year']); |
|
118 | + $arraydate = dol_getdate(dol_now()); |
|
119 | + $datestart = dol_mktime(23, 0, 0, $arraydate['mon'], $arraydate['mday'], $arraydate['year']); |
|
120 | 120 | $this->cronjobs = array( |
121 | 121 | 0=>array('label'=>'RecurringInvoices', 'jobtype'=>'method', 'class'=>'compta/facture/class/facture-rec.class.php', 'objectname'=>'FactureRec', 'method'=>'createRecurringInvoices', 'parameters'=>'', 'comment'=>'Generate recurring invoices', 'frequency'=>1, 'unitfrequency'=>3600 * 24, 'priority'=>50, 'status'=>1, 'test'=>'$conf->facture->enabled', 'datestart'=>$datestart), |
122 | 122 | ); |
@@ -277,7 +277,7 @@ discard block |
||
277 | 277 | 's.rowid'=>"IdCompany", 's.nom'=>'CompanyName', 's.code_client'=>'CustomerCode', 's.address'=>'Address', 's.zip'=>'Zip', 's.town'=>'Town', 'c.code'=>'CountryCode', 's.phone'=>'Phone', |
278 | 278 | 's.siren'=>'ProfId1', 's.siret'=>'ProfId2', 's.ape'=>'ProfId3', 's.idprof4'=>'ProfId4', 's.code_compta'=>'CustomerAccountancyCode', |
279 | 279 | 's.code_compta_fournisseur'=>'SupplierAccountancyCode', 's.tva_intra'=>'VATIntra', |
280 | - 'f.rowid'=>"InvoiceId", 'f.ref'=>"InvoiceRef", 'f.ref_client'=>'RefCustomer', |
|
280 | + 'f.rowid'=>"InvoiceId", 'f.ref'=>"InvoiceRef", 'f.ref_client'=>'RefCustomer', |
|
281 | 281 | 'f.type'=>"Type", 'f.datec'=>"InvoiceDateCreation", 'f.datef'=>"DateInvoice", 'f.date_lim_reglement'=>"DateDue", 'f.total'=>"TotalHT", |
282 | 282 | 'f.total_ttc'=>"TotalTTC", 'f.tva'=>"TotalVAT", 'none.rest'=>'Rest', 'f.paye'=>"InvoicePaid", 'f.fk_statut'=>'InvoiceStatus', |
283 | 283 | 'f.note_private'=>"NotePrivate", 'f.note_public'=>"NotePublic", 'f.fk_user_author'=>'CreatedById', 'uc.login'=>'CreatedByLogin', |
@@ -305,23 +305,23 @@ discard block |
||
305 | 305 | $this->export_dependencies_array[$r] = array('payment'=>'p.rowid', 'none.rest'=>array('f.rowid', 'f.total_ttc')); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them |
306 | 306 | $keyforselect = 'facture'; $keyforelement = 'invoice'; $keyforaliasextra = 'extra'; |
307 | 307 | include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; |
308 | - $this->export_sql_start[$r]='SELECT DISTINCT '; |
|
309 | - $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s'; |
|
310 | - 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'; |
|
311 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid,'; |
|
312 | - $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'facture as f'; |
|
313 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON f.fk_projet = pj.rowid'; |
|
314 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as uc ON f.fk_user_author = uc.rowid'; |
|
315 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON f.fk_user_valid = uv.rowid'; |
|
316 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'facture_extrafields as extra ON f.rowid = extra.fk_object'; |
|
317 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid'; |
|
318 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiement as p ON pf.fk_paiement = p.rowid'; |
|
319 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as pt ON pt.id = p.fk_paiement'; |
|
320 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON b.rowid = p.fk_bank'; |
|
321 | - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON ba.rowid = b.fk_account'; |
|
322 | - $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid'; |
|
323 | - $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('invoice').')'; |
|
324 | - if (isset($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id; |
|
308 | + $this->export_sql_start[$r] = 'SELECT DISTINCT '; |
|
309 | + $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s'; |
|
310 | + 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'; |
|
311 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid,'; |
|
312 | + $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'facture as f'; |
|
313 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON f.fk_projet = pj.rowid'; |
|
314 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uc ON f.fk_user_author = uc.rowid'; |
|
315 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as uv ON f.fk_user_valid = uv.rowid'; |
|
316 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'facture_extrafields as extra ON f.rowid = extra.fk_object'; |
|
317 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement_facture as pf ON pf.fk_facture = f.rowid'; |
|
318 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'paiement as p ON pf.fk_paiement = p.rowid'; |
|
319 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_paiement as pt ON pt.id = p.fk_paiement'; |
|
320 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank as b ON b.rowid = p.fk_bank'; |
|
321 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON ba.rowid = b.fk_account'; |
|
322 | + $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid'; |
|
323 | + $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('invoice').')'; |
|
324 | + if (isset($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' AND sc.fk_user = '.$user->id; |
|
325 | 325 | $r++; |
326 | 326 | } |
327 | 327 |
@@ -253,7 +253,9 @@ discard block |
||
253 | 253 | include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; |
254 | 254 | $this->export_sql_start[$r] = 'SELECT DISTINCT '; |
255 | 255 | $this->export_sql_end[$r] = ' FROM '.MAIN_DB_PREFIX.'societe as s'; |
256 | - 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'; |
|
256 | + if (empty($user->rights->societe->client->voir)) { |
|
257 | + $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; |
|
258 | + } |
|
257 | 259 | $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid,'; |
258 | 260 | $this->export_sql_end[$r] .= ' '.MAIN_DB_PREFIX.'facture as f'; |
259 | 261 | $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON f.fk_projet = pj.rowid'; |
@@ -266,7 +268,9 @@ discard block |
||
266 | 268 | $this->export_sql_end[$r] .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra3 on p.rowid = extra3.fk_object'; |
267 | 269 | $this->export_sql_end[$r] .= ' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture'; |
268 | 270 | $this->export_sql_end[$r] .= ' AND f.entity IN ('.getEntity('invoice').')'; |
269 | - if (isset($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .= ' AND sc.fk_user = '.$user->id; |
|
271 | + if (isset($user) && empty($user->rights->societe->client->voir)) { |
|
272 | + $this->export_sql_end[$r] .= ' AND sc.fk_user = '.$user->id; |
|
273 | + } |
|
270 | 274 | $r++; |
271 | 275 | |
272 | 276 | $this->export_code[$r] = $this->rights_class.'_'.$r; |
@@ -307,7 +311,9 @@ discard block |
||
307 | 311 | include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; |
308 | 312 | $this->export_sql_start[$r]='SELECT DISTINCT '; |
309 | 313 | $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s'; |
310 | - 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'; |
|
314 | + if (empty($user->rights->societe->client->voir)) { |
|
315 | + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; |
|
316 | + } |
|
311 | 317 | $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid,'; |
312 | 318 | $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'facture as f'; |
313 | 319 | $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON f.fk_projet = pj.rowid'; |
@@ -321,7 +327,9 @@ discard block |
||
321 | 327 | $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON ba.rowid = b.fk_account'; |
322 | 328 | $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid'; |
323 | 329 | $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('invoice').')'; |
324 | - if (isset($user) && empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id; |
|
330 | + if (isset($user) && empty($user->rights->societe->client->voir)) { |
|
331 | + $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id; |
|
332 | + } |
|
325 | 333 | $r++; |
326 | 334 | } |
327 | 335 |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | // Setup the credentials for the requests |
67 | 67 | $credentials = new Credentials( |
68 | 68 | $conf->global->OAUTH_STRIPE_TEST_ID, |
69 | - $conf->global->STRIPE_TEST_SECRET_KEY, |
|
69 | + $conf->global->STRIPE_TEST_SECRET_KEY, |
|
70 | 70 | $currentUri->getAbsoluteUri() |
71 | 71 | ); |
72 | 72 | |
@@ -109,10 +109,10 @@ discard block |
||
109 | 109 | |
110 | 110 | if (! empty($_GET['code'])) // We are coming from oauth provider page |
111 | 111 | { |
112 | - // We should have |
|
113 | - //$_GET=array('code' => string 'aaaaaaaaaaaaaa' (length=20), 'state' => string 'user,public_repo' (length=16)) |
|
112 | + // We should have |
|
113 | + //$_GET=array('code' => string 'aaaaaaaaaaaaaa' (length=20), 'state' => string 'user,public_repo' (length=16)) |
|
114 | 114 | |
115 | - dol_syslog("We are coming from the oauth provider page"); |
|
115 | + dol_syslog("We are coming from the oauth provider page"); |
|
116 | 116 | //llxHeader('',$langs->trans("OAuthSetup")); |
117 | 117 | |
118 | 118 | //$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>'; |
@@ -160,8 +160,8 @@ discard block |
||
160 | 160 | else |
161 | 161 | { |
162 | 162 | //$url = $apiService->getAuthorizationUri(); // Parameter state will be randomly generated |
163 | - //https://connect.stripe.com/oauth/authorize?response_type=code&client_id=ca_AX27ut70tJ1j6eyFCV3ObEXhNOo2jY6V&scope=read_write |
|
164 | - $url = 'https://connect.stripe.com/oauth/authorize?response_type=code&client_id='.$conf->global->OAUTH_STRIPE_TEST_ID.'&scope=read_write'; |
|
163 | + //https://connect.stripe.com/oauth/authorize?response_type=code&client_id=ca_AX27ut70tJ1j6eyFCV3ObEXhNOo2jY6V&scope=read_write |
|
164 | + $url = 'https://connect.stripe.com/oauth/authorize?response_type=code&client_id='.$conf->global->OAUTH_STRIPE_TEST_ID.'&scope=read_write'; |
|
165 | 165 | } |
166 | 166 | |
167 | 167 | // we go on oauth provider authorization page |
@@ -71,7 +71,10 @@ discard block |
||
71 | 71 | ); |
72 | 72 | |
73 | 73 | $requestedpermissionsarray=array(); |
74 | -if (GETPOST('state')) $requestedpermissionsarray=explode(',', GETPOST('state')); // Example: 'userinfo_email,userinfo_profile,cloud_print'. 'state' parameter is standard to retrieve some parameters back |
|
74 | +if (GETPOST('state')) { |
|
75 | + $requestedpermissionsarray=explode(',', GETPOST('state')); |
|
76 | +} |
|
77 | +// Example: 'userinfo_email,userinfo_profile,cloud_print'. 'state' parameter is standard to retrieve some parameters back |
|
75 | 78 | /*if ($action != 'delete' && empty($requestedpermissionsarray)) |
76 | 79 | { |
77 | 80 | print 'Error, parameter state is not defined'; |
@@ -107,12 +110,14 @@ discard block |
||
107 | 110 | exit(); |
108 | 111 | } |
109 | 112 | |
110 | -if (! empty($_GET['code'])) // We are coming from oauth provider page |
|
113 | +if (! empty($_GET['code'])) { |
|
114 | + // We are coming from oauth provider page |
|
111 | 115 | { |
112 | 116 | // We should have |
113 | 117 | //$_GET=array('code' => string 'aaaaaaaaaaaaaa' (length=20), 'state' => string 'user,public_repo' (length=16)) |
114 | 118 | |
115 | 119 | dol_syslog("We are coming from the oauth provider page"); |
120 | +} |
|
116 | 121 | //llxHeader('',$langs->trans("OAuthSetup")); |
117 | 122 | |
118 | 123 | //$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>'; |
@@ -146,8 +151,7 @@ discard block |
||
146 | 151 | } catch (Exception $e) { |
147 | 152 | print $e->getMessage(); |
148 | 153 | } |
149 | -} |
|
150 | -else // If entry on page with no parameter, we arrive here |
|
154 | +} else // If entry on page with no parameter, we arrive here |
|
151 | 155 | { |
152 | 156 | $_SESSION["backtourlsavedbeforeoauthjump"]=$backtourl; |
153 | 157 | |
@@ -156,8 +160,7 @@ discard block |
||
156 | 160 | if (GETPOST('state')) |
157 | 161 | { |
158 | 162 | $url = $apiService->getAuthorizationUri(array('state'=>GETPOST('state'))); |
159 | - } |
|
160 | - else |
|
163 | + } else |
|
161 | 164 | { |
162 | 165 | //$url = $apiService->getAuthorizationUri(); // Parameter state will be randomly generated |
163 | 166 | //https://connect.stripe.com/oauth/authorize?response_type=code&client_id=ca_AX27ut70tJ1j6eyFCV3ObEXhNOo2jY6V&scope=read_write |
@@ -25,15 +25,15 @@ discard block |
||
25 | 25 | |
26 | 26 | // Copyright (C) 2018 Alxarafe/Alixar <[email protected]> |
27 | 27 | defined('BASE_PATH') or die('Single entry point through the index.php of the main folder'); |
28 | -require DOL_BASE_PATH . '/main.inc.php'; |
|
28 | +require DOL_BASE_PATH.'/main.inc.php'; |
|
29 | 29 | require_once DOL_DOCUMENT_ROOT.'/includes/OAuth/bootstrap.php'; |
30 | 30 | use OAuth\Common\Storage\DoliStorage; |
31 | 31 | use OAuth\Common\Consumer\Credentials; |
32 | 32 | use OAuth\OAuth2\Service\GitHub; |
33 | 33 | |
34 | 34 | // Define $urlwithroot |
35 | -$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
36 | -$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
35 | +$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); |
|
36 | +$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
37 | 37 | //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
38 | 38 | |
39 | 39 | |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | $currentUri->getAbsoluteUri() |
74 | 74 | ); |
75 | 75 | |
76 | -$requestedpermissionsarray=array(); |
|
77 | -if (GETPOST('state')) $requestedpermissionsarray=explode(',', GETPOST('state')); // Example: 'userinfo_email,userinfo_profile,cloud_print'. 'state' parameter is standard to retrieve some parameters back |
|
76 | +$requestedpermissionsarray = array(); |
|
77 | +if (GETPOST('state')) $requestedpermissionsarray = explode(',', GETPOST('state')); // Example: 'userinfo_email,userinfo_profile,cloud_print'. 'state' parameter is standard to retrieve some parameters back |
|
78 | 78 | /*if ($action != 'delete' && empty($requestedpermissionsarray)) |
79 | 79 | { |
80 | 80 | print 'Error, parameter state is not defined'; |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | /** @var $apiService Service */ |
87 | 87 | //$apiService = $serviceFactory->createService('StripeTest', $credentials, $storage, $requestedpermissionsarray); |
88 | 88 | |
89 | -$sql="INSERT INTO ".MAIN_DB_PREFIX."oauth_token set service='StripeTest', entity=".$conf->entity; |
|
89 | +$sql = "INSERT INTO ".MAIN_DB_PREFIX."oauth_token set service='StripeTest', entity=".$conf->entity; |
|
90 | 90 | $db->query($sql); |
91 | 91 | |
92 | 92 | // access type needed to have oauth provider refreshing token |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | |
107 | 107 | setEventMessages($langs->trans('TokenDeleted'), null, 'mesgs'); |
108 | 108 | |
109 | - header('Location: ' . $backtourl); |
|
109 | + header('Location: '.$backtourl); |
|
110 | 110 | exit(); |
111 | 111 | } |
112 | 112 | |
113 | -if (! empty($_GET['code'])) // We are coming from oauth provider page |
|
113 | +if (!empty($_GET['code'])) // We are coming from oauth provider page |
|
114 | 114 | { |
115 | 115 | // We should have |
116 | 116 | //$_GET=array('code' => string 'aaaaaaaaaaaaaa' (length=20), 'state' => string 'user,public_repo' (length=16)) |
@@ -139,12 +139,12 @@ discard block |
||
139 | 139 | // parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri) |
140 | 140 | // has not the ending parameter to true like the Google class constructor. |
141 | 141 | |
142 | - setEventMessages($langs->trans('NewTokenStored'), null, 'mesgs'); // Stored into object managed by class DoliStorage so into table oauth_token |
|
142 | + setEventMessages($langs->trans('NewTokenStored'), null, 'mesgs'); // Stored into object managed by class DoliStorage so into table oauth_token |
|
143 | 143 | |
144 | 144 | $backtourl = $_SESSION["backtourlsavedbeforeoauthjump"]; |
145 | 145 | unset($_SESSION["backtourlsavedbeforeoauthjump"]); |
146 | 146 | |
147 | - header('Location: ' . $backtourl); |
|
147 | + header('Location: '.$backtourl); |
|
148 | 148 | exit(); |
149 | 149 | } catch (Exception $e) { |
150 | 150 | print $e->getMessage(); |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | } |
153 | 153 | else // If entry on page with no parameter, we arrive here |
154 | 154 | { |
155 | - $_SESSION["backtourlsavedbeforeoauthjump"]=$backtourl; |
|
155 | + $_SESSION["backtourlsavedbeforeoauthjump"] = $backtourl; |
|
156 | 156 | |
157 | 157 | // This may create record into oauth_state before the header redirect. |
158 | 158 | // Creation of record with state in this tables depend on the Provider used (see its constructor). |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | } |
169 | 169 | |
170 | 170 | // we go on oauth provider authorization page |
171 | - header('Location: ' . $url); |
|
171 | + header('Location: '.$url); |
|
172 | 172 | exit(); |
173 | 173 | } |
174 | 174 |
@@ -109,8 +109,8 @@ |
||
109 | 109 | |
110 | 110 | if (! empty($_GET['code'])) // We are coming from oauth provider page |
111 | 111 | { |
112 | - dol_syslog("We are coming from the oauth provider page"); |
|
113 | - //llxHeader('',$langs->trans("OAuthSetup")); |
|
112 | + dol_syslog("We are coming from the oauth provider page"); |
|
113 | + //llxHeader('',$langs->trans("OAuthSetup")); |
|
114 | 114 | |
115 | 115 | //$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>'; |
116 | 116 | //print load_fiche_titre($langs->trans("OAuthSetup"),$linkback,'title_setup'); |
@@ -71,7 +71,10 @@ discard block |
||
71 | 71 | ); |
72 | 72 | |
73 | 73 | $requestedpermissionsarray=array(); |
74 | -if (GETPOST('state')) $requestedpermissionsarray=explode(',', GETPOST('state')); // Example: 'userinfo_email,userinfo_profile,cloud_print'. 'state' parameter is standard to retrieve some parameters back |
|
74 | +if (GETPOST('state')) { |
|
75 | + $requestedpermissionsarray=explode(',', GETPOST('state')); |
|
76 | +} |
|
77 | +// Example: 'userinfo_email,userinfo_profile,cloud_print'. 'state' parameter is standard to retrieve some parameters back |
|
75 | 78 | if ($action != 'delete' && empty($requestedpermissionsarray)) |
76 | 79 | { |
77 | 80 | print 'Error, parameter state is not defined'; |
@@ -107,9 +110,11 @@ discard block |
||
107 | 110 | exit(); |
108 | 111 | } |
109 | 112 | |
110 | -if (! empty($_GET['code'])) // We are coming from oauth provider page |
|
113 | +if (! empty($_GET['code'])) { |
|
114 | + // We are coming from oauth provider page |
|
111 | 115 | { |
112 | 116 | dol_syslog("We are coming from the oauth provider page"); |
117 | +} |
|
113 | 118 | //llxHeader('',$langs->trans("OAuthSetup")); |
114 | 119 | |
115 | 120 | //$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>'; |
@@ -138,8 +143,7 @@ discard block |
||
138 | 143 | } catch (Exception $e) { |
139 | 144 | print $e->getMessage(); |
140 | 145 | } |
141 | -} |
|
142 | -else // If entry on page with no parameter, we arrive here |
|
146 | +} else // If entry on page with no parameter, we arrive here |
|
143 | 147 | { |
144 | 148 | $_SESSION["backtourlsavedbeforeoauthjump"]=$backtourl; |
145 | 149 | |
@@ -148,8 +152,7 @@ discard block |
||
148 | 152 | if (GETPOST('state')) |
149 | 153 | { |
150 | 154 | $url = $apiService->getAuthorizationUri(array('state'=>GETPOST('state'))); |
151 | - } |
|
152 | - else |
|
155 | + } else |
|
153 | 156 | { |
154 | 157 | $url = $apiService->getAuthorizationUri(); // Parameter state will be randomly generated |
155 | 158 | } |
@@ -25,15 +25,15 @@ discard block |
||
25 | 25 | |
26 | 26 | // Copyright (C) 2018 Alxarafe/Alixar <[email protected]> |
27 | 27 | defined('BASE_PATH') or die('Single entry point through the index.php of the main folder'); |
28 | -require DOL_BASE_PATH . '/main.inc.php'; |
|
28 | +require DOL_BASE_PATH.'/main.inc.php'; |
|
29 | 29 | require_once DOL_DOCUMENT_ROOT.'/includes/OAuth/bootstrap.php'; |
30 | 30 | use OAuth\Common\Storage\DoliStorage; |
31 | 31 | use OAuth\Common\Consumer\Credentials; |
32 | 32 | use OAuth\OAuth2\Service\Google; |
33 | 33 | |
34 | 34 | // Define $urlwithroot |
35 | -$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
36 | -$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
35 | +$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); |
|
36 | +$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
37 | 37 | //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
38 | 38 | |
39 | 39 | |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | $currentUri->getAbsoluteUri() |
74 | 74 | ); |
75 | 75 | |
76 | -$requestedpermissionsarray=array(); |
|
77 | -if (GETPOST('state')) $requestedpermissionsarray=explode(',', GETPOST('state')); // Example: 'userinfo_email,userinfo_profile,cloud_print'. 'state' parameter is standard to retrieve some parameters back |
|
76 | +$requestedpermissionsarray = array(); |
|
77 | +if (GETPOST('state')) $requestedpermissionsarray = explode(',', GETPOST('state')); // Example: 'userinfo_email,userinfo_profile,cloud_print'. 'state' parameter is standard to retrieve some parameters back |
|
78 | 78 | if ($action != 'delete' && empty($requestedpermissionsarray)) |
79 | 79 | { |
80 | 80 | print 'Error, parameter state is not defined'; |
@@ -106,11 +106,11 @@ discard block |
||
106 | 106 | |
107 | 107 | setEventMessages($langs->trans('TokenDeleted'), null, 'mesgs'); |
108 | 108 | |
109 | - header('Location: ' . $backtourl); |
|
109 | + header('Location: '.$backtourl); |
|
110 | 110 | exit(); |
111 | 111 | } |
112 | 112 | |
113 | -if (! empty($_GET['code'])) // We are coming from oauth provider page |
|
113 | +if (!empty($_GET['code'])) // We are coming from oauth provider page |
|
114 | 114 | { |
115 | 115 | dol_syslog("We are coming from the oauth provider page"); |
116 | 116 | //llxHeader('',$langs->trans("OAuthSetup")); |
@@ -131,12 +131,12 @@ discard block |
||
131 | 131 | |
132 | 132 | $token = $apiService->requestAccessToken($_GET['code'], $state); |
133 | 133 | |
134 | - setEventMessages($langs->trans('NewTokenStored'), null, 'mesgs'); // Stored into object managed by class DoliStorage so into table oauth_token |
|
134 | + setEventMessages($langs->trans('NewTokenStored'), null, 'mesgs'); // Stored into object managed by class DoliStorage so into table oauth_token |
|
135 | 135 | |
136 | 136 | $backtourl = $_SESSION["backtourlsavedbeforeoauthjump"]; |
137 | 137 | unset($_SESSION["backtourlsavedbeforeoauthjump"]); |
138 | 138 | |
139 | - header('Location: ' . $backtourl); |
|
139 | + header('Location: '.$backtourl); |
|
140 | 140 | exit(); |
141 | 141 | } catch (Exception $e) { |
142 | 142 | print $e->getMessage(); |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | } |
145 | 145 | else // If entry on page with no parameter, we arrive here |
146 | 146 | { |
147 | - $_SESSION["backtourlsavedbeforeoauthjump"]=$backtourl; |
|
147 | + $_SESSION["backtourlsavedbeforeoauthjump"] = $backtourl; |
|
148 | 148 | |
149 | 149 | // This may create record into oauth_state before the header redirect. |
150 | 150 | // Creation of record with state in this tables depend on the Provider used (see its constructor). |
@@ -154,11 +154,11 @@ discard block |
||
154 | 154 | } |
155 | 155 | else |
156 | 156 | { |
157 | - $url = $apiService->getAuthorizationUri(); // Parameter state will be randomly generated |
|
157 | + $url = $apiService->getAuthorizationUri(); // Parameter state will be randomly generated |
|
158 | 158 | } |
159 | 159 | |
160 | 160 | // we go on oauth provider authorization page |
161 | - header('Location: ' . $url); |
|
161 | + header('Location: '.$url); |
|
162 | 162 | exit(); |
163 | 163 | } |
164 | 164 |
@@ -106,10 +106,10 @@ |
||
106 | 106 | |
107 | 107 | if (! empty($_GET['code'])) // We are coming from oauth provider page |
108 | 108 | { |
109 | - // We should have |
|
110 | - //$_GET=array('code' => string 'aaaaaaaaaaaaaa' (length=20), 'state' => string 'user,public_repo' (length=16)) |
|
109 | + // We should have |
|
110 | + //$_GET=array('code' => string 'aaaaaaaaaaaaaa' (length=20), 'state' => string 'user,public_repo' (length=16)) |
|
111 | 111 | |
112 | - dol_syslog("We are coming from the oauth provider page"); |
|
112 | + dol_syslog("We are coming from the oauth provider page"); |
|
113 | 113 | //llxHeader('',$langs->trans("OAuthSetup")); |
114 | 114 | |
115 | 115 | //$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>'; |
@@ -71,7 +71,10 @@ discard block |
||
71 | 71 | ); |
72 | 72 | |
73 | 73 | $requestedpermissionsarray=array(); |
74 | -if (GETPOST('state')) $requestedpermissionsarray=explode(',', GETPOST('state')); // Example: 'userinfo_email,userinfo_profile,cloud_print'. 'state' parameter is standard to retrieve some parameters back |
|
74 | +if (GETPOST('state')) { |
|
75 | + $requestedpermissionsarray=explode(',', GETPOST('state')); |
|
76 | +} |
|
77 | +// Example: 'userinfo_email,userinfo_profile,cloud_print'. 'state' parameter is standard to retrieve some parameters back |
|
75 | 78 | if ($action != 'delete' && empty($requestedpermissionsarray)) |
76 | 79 | { |
77 | 80 | print 'Error, parameter state is not defined'; |
@@ -104,12 +107,14 @@ discard block |
||
104 | 107 | exit(); |
105 | 108 | } |
106 | 109 | |
107 | -if (! empty($_GET['code'])) // We are coming from oauth provider page |
|
110 | +if (! empty($_GET['code'])) { |
|
111 | + // We are coming from oauth provider page |
|
108 | 112 | { |
109 | 113 | // We should have |
110 | 114 | //$_GET=array('code' => string 'aaaaaaaaaaaaaa' (length=20), 'state' => string 'user,public_repo' (length=16)) |
111 | 115 | |
112 | 116 | dol_syslog("We are coming from the oauth provider page"); |
117 | +} |
|
113 | 118 | //llxHeader('',$langs->trans("OAuthSetup")); |
114 | 119 | |
115 | 120 | //$linkback='<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>'; |
@@ -143,8 +148,7 @@ discard block |
||
143 | 148 | } catch (Exception $e) { |
144 | 149 | print $e->getMessage(); |
145 | 150 | } |
146 | -} |
|
147 | -else // If entry on page with no parameter, we arrive here |
|
151 | +} else // If entry on page with no parameter, we arrive here |
|
148 | 152 | { |
149 | 153 | $_SESSION["backtourlsavedbeforeoauthjump"]=$backtourl; |
150 | 154 | |
@@ -153,8 +157,7 @@ discard block |
||
153 | 157 | if (GETPOST('state')) |
154 | 158 | { |
155 | 159 | $url = $apiService->getAuthorizationUri(array('state'=>GETPOST('state'))); |
156 | - } |
|
157 | - else |
|
160 | + } else |
|
158 | 161 | { |
159 | 162 | $url = $apiService->getAuthorizationUri(); // Parameter state will be randomly generated |
160 | 163 | } |
@@ -25,15 +25,15 @@ discard block |
||
25 | 25 | |
26 | 26 | // Copyright (C) 2018 Alxarafe/Alixar <[email protected]> |
27 | 27 | defined('BASE_PATH') or die('Single entry point through the index.php of the main folder'); |
28 | -require DOL_BASE_PATH . '/main.inc.php'; |
|
28 | +require DOL_BASE_PATH.'/main.inc.php'; |
|
29 | 29 | require_once DOL_DOCUMENT_ROOT.'/includes/OAuth/bootstrap.php'; |
30 | 30 | use OAuth\Common\Storage\DoliStorage; |
31 | 31 | use OAuth\Common\Consumer\Credentials; |
32 | 32 | use OAuth\OAuth2\Service\GitHub; |
33 | 33 | |
34 | 34 | // Define $urlwithroot |
35 | -$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
36 | -$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
35 | +$urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); |
|
36 | +$urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
37 | 37 | //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
38 | 38 | |
39 | 39 | |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | $currentUri->getAbsoluteUri() |
74 | 74 | ); |
75 | 75 | |
76 | -$requestedpermissionsarray=array(); |
|
77 | -if (GETPOST('state')) $requestedpermissionsarray=explode(',', GETPOST('state')); // Example: 'userinfo_email,userinfo_profile,cloud_print'. 'state' parameter is standard to retrieve some parameters back |
|
76 | +$requestedpermissionsarray = array(); |
|
77 | +if (GETPOST('state')) $requestedpermissionsarray = explode(',', GETPOST('state')); // Example: 'userinfo_email,userinfo_profile,cloud_print'. 'state' parameter is standard to retrieve some parameters back |
|
78 | 78 | if ($action != 'delete' && empty($requestedpermissionsarray)) |
79 | 79 | { |
80 | 80 | print 'Error, parameter state is not defined'; |
@@ -103,11 +103,11 @@ discard block |
||
103 | 103 | |
104 | 104 | setEventMessages($langs->trans('TokenDeleted'), null, 'mesgs'); |
105 | 105 | |
106 | - header('Location: ' . $backtourl); |
|
106 | + header('Location: '.$backtourl); |
|
107 | 107 | exit(); |
108 | 108 | } |
109 | 109 | |
110 | -if (! empty($_GET['code'])) // We are coming from oauth provider page |
|
110 | +if (!empty($_GET['code'])) // We are coming from oauth provider page |
|
111 | 111 | { |
112 | 112 | // We should have |
113 | 113 | //$_GET=array('code' => string 'aaaaaaaaaaaaaa' (length=20), 'state' => string 'user,public_repo' (length=16)) |
@@ -136,12 +136,12 @@ discard block |
||
136 | 136 | // parent::__construct($credentials, $httpClient, $storage, $scopes, $baseApiUri) |
137 | 137 | // has not the ending parameter to true like the Google class constructor. |
138 | 138 | |
139 | - setEventMessages($langs->trans('NewTokenStored'), null, 'mesgs'); // Stored into object managed by class DoliStorage so into table oauth_token |
|
139 | + setEventMessages($langs->trans('NewTokenStored'), null, 'mesgs'); // Stored into object managed by class DoliStorage so into table oauth_token |
|
140 | 140 | |
141 | 141 | $backtourl = $_SESSION["backtourlsavedbeforeoauthjump"]; |
142 | 142 | unset($_SESSION["backtourlsavedbeforeoauthjump"]); |
143 | 143 | |
144 | - header('Location: ' . $backtourl); |
|
144 | + header('Location: '.$backtourl); |
|
145 | 145 | exit(); |
146 | 146 | } catch (Exception $e) { |
147 | 147 | print $e->getMessage(); |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | } |
150 | 150 | else // If entry on page with no parameter, we arrive here |
151 | 151 | { |
152 | - $_SESSION["backtourlsavedbeforeoauthjump"]=$backtourl; |
|
152 | + $_SESSION["backtourlsavedbeforeoauthjump"] = $backtourl; |
|
153 | 153 | |
154 | 154 | // This may create record into oauth_state before the header redirect. |
155 | 155 | // Creation of record with state in this tables depend on the Provider used (see its constructor). |
@@ -159,11 +159,11 @@ discard block |
||
159 | 159 | } |
160 | 160 | else |
161 | 161 | { |
162 | - $url = $apiService->getAuthorizationUri(); // Parameter state will be randomly generated |
|
162 | + $url = $apiService->getAuthorizationUri(); // Parameter state will be randomly generated |
|
163 | 163 | } |
164 | 164 | |
165 | 165 | // we go on oauth provider authorization page |
166 | - header('Location: ' . $url); |
|
166 | + header('Location: '.$url); |
|
167 | 167 | exit(); |
168 | 168 | } |
169 | 169 |
@@ -37,9 +37,9 @@ discard block |
||
37 | 37 | public $db; |
38 | 38 | |
39 | 39 | /** |
40 | - * @var string Error code (or message) |
|
41 | - */ |
|
42 | - public $error=''; |
|
40 | + * @var string Error code (or message) |
|
41 | + */ |
|
42 | + public $error=''; |
|
43 | 43 | |
44 | 44 | |
45 | 45 | /** |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | * @param DoliDB $db Database handler |
59 | 59 | * @param integer $maxfilenamelength Max length of value to show |
60 | 60 | * @return array List of drivers |
61 | - */ |
|
61 | + */ |
|
62 | 62 | static function listDrivers($db,$maxfilenamelength=0) |
63 | 63 | { |
64 | 64 | global $conf; |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | /** |
40 | 40 | * @var string Error code (or message) |
41 | 41 | */ |
42 | - public $error=''; |
|
42 | + public $error = ''; |
|
43 | 43 | |
44 | 44 | |
45 | 45 | /** |
@@ -59,17 +59,17 @@ discard block |
||
59 | 59 | * @param integer $maxfilenamelength Max length of value to show |
60 | 60 | * @return array List of drivers |
61 | 61 | */ |
62 | - static function listDrivers($db,$maxfilenamelength=0) |
|
62 | + static function listDrivers($db, $maxfilenamelength = 0) |
|
63 | 63 | { |
64 | 64 | global $conf; |
65 | 65 | |
66 | 66 | $type = 'printing'; |
67 | 67 | $list = array(); |
68 | 68 | |
69 | - $moduledir=DOL_DOCUMENT_ROOT."/core/modules/printing/"; |
|
70 | - $tmpfiles=dol_dir_list($moduledir,'all',0,'\modules.php','','name',SORT_ASC,0); |
|
71 | - foreach($tmpfiles as $record) { |
|
72 | - $list[$record['fullname']]=str_replace('.modules.php', '',$record['name']); |
|
69 | + $moduledir = DOL_DOCUMENT_ROOT."/core/modules/printing/"; |
|
70 | + $tmpfiles = dol_dir_list($moduledir, 'all', 0, '\modules.php', '', 'name', SORT_ASC, 0); |
|
71 | + foreach ($tmpfiles as $record) { |
|
72 | + $list[$record['fullname']] = str_replace('.modules.php', '', $record['name']); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | return $list; |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | { |
85 | 85 | global $langs; |
86 | 86 | $langs->load("printing"); |
87 | - $transstring="PrintingModuleDesc".$this->name; |
|
87 | + $transstring = "PrintingModuleDesc".$this->name; |
|
88 | 88 | if ($langs->trans($transstring) != $transstring) return $langs->trans($transstring); |
89 | 89 | else return $this->desc; |
90 | 90 | } |
@@ -85,7 +85,10 @@ |
||
85 | 85 | global $langs; |
86 | 86 | $langs->load("printing"); |
87 | 87 | $transstring="PrintingModuleDesc".$this->name; |
88 | - if ($langs->trans($transstring) != $transstring) return $langs->trans($transstring); |
|
89 | - else return $this->desc; |
|
88 | + if ($langs->trans($transstring) != $transstring) { |
|
89 | + return $langs->trans($transstring); |
|
90 | + } else { |
|
91 | + return $this->desc; |
|
92 | + } |
|
90 | 93 | } |
91 | 94 | } |
@@ -89,47 +89,47 @@ |
||
89 | 89 | ); |
90 | 90 | } else { |
91 | 91 | |
92 | - $this->google_id = $conf->global->OAUTH_GOOGLE_ID; |
|
93 | - $this->google_secret = $conf->global->OAUTH_GOOGLE_SECRET; |
|
94 | - // Token storage |
|
95 | - $storage = new DoliStorage($this->db, $this->conf); |
|
96 | - //$storage->clearToken($this->OAUTH_SERVICENAME_GOOGLE); |
|
97 | - // Setup the credentials for the requests |
|
98 | - $credentials = new Credentials( |
|
99 | - $this->google_id, |
|
100 | - $this->google_secret, |
|
101 | - $urlwithroot.'/core/modules/oauth/google_oauthcallback.php' |
|
102 | - ); |
|
103 | - $access = ($storage->hasAccessToken($this->OAUTH_SERVICENAME_GOOGLE)?'HasAccessToken':'NoAccessToken'); |
|
104 | - $serviceFactory = new \OAuth\ServiceFactory(); |
|
105 | - $apiService = $serviceFactory->createService($this->OAUTH_SERVICENAME_GOOGLE, $credentials, $storage, array()); |
|
106 | - $token_ok=true; |
|
107 | - try { |
|
108 | - $token = $storage->retrieveAccessToken($this->OAUTH_SERVICENAME_GOOGLE); |
|
109 | - } catch (Exception $e) { |
|
110 | - $this->errors[] = $e->getMessage(); |
|
111 | - $token_ok = false; |
|
112 | - } |
|
113 | - //var_dump($this->errors);exit; |
|
114 | - |
|
115 | - $expire = false; |
|
116 | - // Is token expired or will token expire in the next 30 seconds |
|
117 | - if ($token_ok) { |
|
118 | - $expire = ($token->getEndOfLife() !== -9002 && $token->getEndOfLife() !== -9001 && time() > ($token->getEndOfLife() - 30)); |
|
119 | - } |
|
120 | - |
|
121 | - // Token expired so we refresh it |
|
122 | - if ($token_ok && $expire) { |
|
123 | - try { |
|
124 | - // il faut sauvegarder le refresh token car google ne le donne qu'une seule fois |
|
125 | - $refreshtoken = $token->getRefreshToken(); |
|
126 | - $token = $apiService->refreshAccessToken($token); |
|
127 | - $token->setRefreshToken($refreshtoken); |
|
128 | - $storage->storeAccessToken($this->OAUTH_SERVICENAME_GOOGLE, $token); |
|
129 | - } catch (Exception $e) { |
|
130 | - $this->errors[] = $e->getMessage(); |
|
131 | - } |
|
132 | - } |
|
92 | + $this->google_id = $conf->global->OAUTH_GOOGLE_ID; |
|
93 | + $this->google_secret = $conf->global->OAUTH_GOOGLE_SECRET; |
|
94 | + // Token storage |
|
95 | + $storage = new DoliStorage($this->db, $this->conf); |
|
96 | + //$storage->clearToken($this->OAUTH_SERVICENAME_GOOGLE); |
|
97 | + // Setup the credentials for the requests |
|
98 | + $credentials = new Credentials( |
|
99 | + $this->google_id, |
|
100 | + $this->google_secret, |
|
101 | + $urlwithroot.'/core/modules/oauth/google_oauthcallback.php' |
|
102 | + ); |
|
103 | + $access = ($storage->hasAccessToken($this->OAUTH_SERVICENAME_GOOGLE)?'HasAccessToken':'NoAccessToken'); |
|
104 | + $serviceFactory = new \OAuth\ServiceFactory(); |
|
105 | + $apiService = $serviceFactory->createService($this->OAUTH_SERVICENAME_GOOGLE, $credentials, $storage, array()); |
|
106 | + $token_ok=true; |
|
107 | + try { |
|
108 | + $token = $storage->retrieveAccessToken($this->OAUTH_SERVICENAME_GOOGLE); |
|
109 | + } catch (Exception $e) { |
|
110 | + $this->errors[] = $e->getMessage(); |
|
111 | + $token_ok = false; |
|
112 | + } |
|
113 | + //var_dump($this->errors);exit; |
|
114 | + |
|
115 | + $expire = false; |
|
116 | + // Is token expired or will token expire in the next 30 seconds |
|
117 | + if ($token_ok) { |
|
118 | + $expire = ($token->getEndOfLife() !== -9002 && $token->getEndOfLife() !== -9001 && time() > ($token->getEndOfLife() - 30)); |
|
119 | + } |
|
120 | + |
|
121 | + // Token expired so we refresh it |
|
122 | + if ($token_ok && $expire) { |
|
123 | + try { |
|
124 | + // il faut sauvegarder le refresh token car google ne le donne qu'une seule fois |
|
125 | + $refreshtoken = $token->getRefreshToken(); |
|
126 | + $token = $apiService->refreshAccessToken($token); |
|
127 | + $token->setRefreshToken($refreshtoken); |
|
128 | + $storage->storeAccessToken($this->OAUTH_SERVICENAME_GOOGLE, $token); |
|
129 | + } catch (Exception $e) { |
|
130 | + $this->errors[] = $e->getMessage(); |
|
131 | + } |
|
132 | + } |
|
133 | 133 | if ($this->google_id != '' && $this->google_secret != '') { |
134 | 134 | $this->conf[] = array('varname'=>'PRINTGCP_INFO', 'info'=>'GoogleAuthConfigured', 'type'=>'info'); |
135 | 135 | $this->conf[] = array( |
@@ -75,8 +75,8 @@ discard block |
||
75 | 75 | global $conf, $langs, $dolibarr_main_url_root; |
76 | 76 | |
77 | 77 | // Define $urlwithroot |
78 | - $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); |
|
79 | - $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
78 | + $urlwithouturlroot = preg_replace('/'.preg_quote(DOL_URL_ROOT, '/').'$/i', '', trim($dolibarr_main_url_root)); |
|
79 | + $urlwithroot = $urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file |
|
80 | 80 | //$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current |
81 | 81 | |
82 | 82 | $this->db = $db; |
@@ -100,10 +100,10 @@ discard block |
||
100 | 100 | $this->google_secret, |
101 | 101 | $urlwithroot.'/core/modules/oauth/google_oauthcallback.php' |
102 | 102 | ); |
103 | - $access = ($storage->hasAccessToken($this->OAUTH_SERVICENAME_GOOGLE)?'HasAccessToken':'NoAccessToken'); |
|
103 | + $access = ($storage->hasAccessToken($this->OAUTH_SERVICENAME_GOOGLE) ? 'HasAccessToken' : 'NoAccessToken'); |
|
104 | 104 | $serviceFactory = new \OAuth\ServiceFactory(); |
105 | 105 | $apiService = $serviceFactory->createService($this->OAUTH_SERVICENAME_GOOGLE, $credentials, $storage, array()); |
106 | - $token_ok=true; |
|
106 | + $token_ok = true; |
|
107 | 107 | try { |
108 | 108 | $token = $storage->retrieveAccessToken($this->OAUTH_SERVICENAME_GOOGLE); |
109 | 109 | } catch (Exception $e) { |
@@ -137,10 +137,10 @@ discard block |
||
137 | 137 | 'info'=>$access, |
138 | 138 | 'type'=>'info', |
139 | 139 | 'renew'=>$urlwithroot.'/core/modules/oauth/google_oauthcallback.php?state=userinfo_email,userinfo_profile,cloud_print&backtourl='.urlencode(DOL_URL_ROOT.'/printing/admin/printing.php?mode=setup&driver=printgcp'), |
140 | - 'delete'=>($storage->hasAccessToken($this->OAUTH_SERVICENAME_GOOGLE)?$urlwithroot.'/core/modules/oauth/google_oauthcallback.php?action=delete&backtourl='.urlencode(DOL_URL_ROOT.'/printing/admin/printing.php?mode=setup&driver=printgcp'):'') |
|
140 | + 'delete'=>($storage->hasAccessToken($this->OAUTH_SERVICENAME_GOOGLE) ? $urlwithroot.'/core/modules/oauth/google_oauthcallback.php?action=delete&backtourl='.urlencode(DOL_URL_ROOT.'/printing/admin/printing.php?mode=setup&driver=printgcp') : '') |
|
141 | 141 | ); |
142 | 142 | if ($token_ok) { |
143 | - $expiredat=''; |
|
143 | + $expiredat = ''; |
|
144 | 144 | |
145 | 145 | $refreshtoken = $token->getRefreshToken(); |
146 | 146 | |
@@ -156,11 +156,11 @@ discard block |
||
156 | 156 | } |
157 | 157 | else |
158 | 158 | { |
159 | - $expiredat=dol_print_date($endoflife, "dayhour"); |
|
159 | + $expiredat = dol_print_date($endoflife, "dayhour"); |
|
160 | 160 | } |
161 | 161 | |
162 | - $this->conf[] = array('varname'=>'TOKEN_REFRESH', 'info'=>((! empty($refreshtoken))?'Yes':'No'), 'type'=>'info'); |
|
163 | - $this->conf[] = array('varname'=>'TOKEN_EXPIRED', 'info'=>($expire?'Yes':'No'), 'type'=>'info'); |
|
162 | + $this->conf[] = array('varname'=>'TOKEN_REFRESH', 'info'=>((!empty($refreshtoken)) ? 'Yes' : 'No'), 'type'=>'info'); |
|
163 | + $this->conf[] = array('varname'=>'TOKEN_EXPIRED', 'info'=>($expire ? 'Yes' : 'No'), 'type'=>'info'); |
|
164 | 164 | $this->conf[] = array('varname'=>'TOKEN_EXPIRE_AT', 'info'=>($expiredat), 'type'=>'info'); |
165 | 165 | } |
166 | 166 | /* |
@@ -190,37 +190,37 @@ discard block |
||
190 | 190 | $langs->load('printing'); |
191 | 191 | |
192 | 192 | $html = '<tr class="liste_titre">'; |
193 | - $html.= '<td>'.$langs->trans('GCP_Name').'</td>'; |
|
194 | - $html.= '<td>'.$langs->trans('GCP_displayName').'</td>'; |
|
195 | - $html.= '<td>'.$langs->trans('GCP_Id').'</td>'; |
|
196 | - $html.= '<td>'.$langs->trans('GCP_OwnerName').'</td>'; |
|
197 | - $html.= '<td>'.$langs->trans('GCP_State').'</td>'; |
|
198 | - $html.= '<td>'.$langs->trans('GCP_connectionStatus').'</td>'; |
|
199 | - $html.= '<td>'.$langs->trans('GCP_Type').'</td>'; |
|
200 | - $html.= '<td align="center">'.$langs->trans("Select").'</td>'; |
|
201 | - $html.= '</tr>'."\n"; |
|
193 | + $html .= '<td>'.$langs->trans('GCP_Name').'</td>'; |
|
194 | + $html .= '<td>'.$langs->trans('GCP_displayName').'</td>'; |
|
195 | + $html .= '<td>'.$langs->trans('GCP_Id').'</td>'; |
|
196 | + $html .= '<td>'.$langs->trans('GCP_OwnerName').'</td>'; |
|
197 | + $html .= '<td>'.$langs->trans('GCP_State').'</td>'; |
|
198 | + $html .= '<td>'.$langs->trans('GCP_connectionStatus').'</td>'; |
|
199 | + $html .= '<td>'.$langs->trans('GCP_Type').'</td>'; |
|
200 | + $html .= '<td align="center">'.$langs->trans("Select").'</td>'; |
|
201 | + $html .= '</tr>'."\n"; |
|
202 | 202 | $list = $this->getlistAvailablePrinters(); |
203 | 203 | //$html.= '<td><pre>'.print_r($list,true).'</pre></td>'; |
204 | 204 | foreach ($list['available'] as $printer_det) |
205 | 205 | { |
206 | - $html.= '<tr class="oddeven">'; |
|
207 | - $html.= '<td>'.$printer_det['name'].'</td>'; |
|
208 | - $html.= '<td>'.$printer_det['displayName'].'</td>'; |
|
209 | - $html.= '<td>'.$printer_det['id'].'</td>'; // id to identify printer to use |
|
210 | - $html.= '<td>'.$printer_det['ownerName'].'</td>'; |
|
211 | - $html.= '<td>'.$printer_det['status'].'</td>'; |
|
212 | - $html.= '<td>'.$langs->trans('STATE_'.$printer_det['connectionStatus']).'</td>'; |
|
213 | - $html.= '<td>'.$langs->trans('TYPE_'.$printer_det['type']).'</td>'; |
|
206 | + $html .= '<tr class="oddeven">'; |
|
207 | + $html .= '<td>'.$printer_det['name'].'</td>'; |
|
208 | + $html .= '<td>'.$printer_det['displayName'].'</td>'; |
|
209 | + $html .= '<td>'.$printer_det['id'].'</td>'; // id to identify printer to use |
|
210 | + $html .= '<td>'.$printer_det['ownerName'].'</td>'; |
|
211 | + $html .= '<td>'.$printer_det['status'].'</td>'; |
|
212 | + $html .= '<td>'.$langs->trans('STATE_'.$printer_det['connectionStatus']).'</td>'; |
|
213 | + $html .= '<td>'.$langs->trans('TYPE_'.$printer_det['type']).'</td>'; |
|
214 | 214 | // Defaut |
215 | - $html.= '<td align="center">'; |
|
215 | + $html .= '<td align="center">'; |
|
216 | 216 | if ($conf->global->PRINTING_GCP_DEFAULT == $printer_det['id']) |
217 | 217 | { |
218 | - $html.= img_picto($langs->trans("Default"),'on'); |
|
218 | + $html .= img_picto($langs->trans("Default"), 'on'); |
|
219 | 219 | } |
220 | 220 | else |
221 | - $html.= '<a href="'.$_SERVER["PHP_SELF"].'?action=setvalue&mode=test&varname=PRINTING_GCP_DEFAULT&driver=printgcp&value='.urlencode($printer_det['id']).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>'; |
|
222 | - $html.= '</td>'; |
|
223 | - $html.= '</tr>'."\n"; |
|
221 | + $html .= '<a href="'.$_SERVER["PHP_SELF"].'?action=setvalue&mode=test&varname=PRINTING_GCP_DEFAULT&driver=printgcp&value='.urlencode($printer_det['id']).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"), 'off').'</a>'; |
|
222 | + $html .= '</td>'; |
|
223 | + $html .= '</tr>'."\n"; |
|
224 | 224 | } |
225 | 225 | $this->resprint = $html; |
226 | 226 | return $error; |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | $serviceFactory = new \OAuth\ServiceFactory(); |
246 | 246 | $apiService = $serviceFactory->createService($this->OAUTH_SERVICENAME_GOOGLE, $credentials, $storage, array()); |
247 | 247 | // Check if we have auth token |
248 | - $token_ok=true; |
|
248 | + $token_ok = true; |
|
249 | 249 | try { |
250 | 250 | $token = $storage->retrieveAccessToken($this->OAUTH_SERVICENAME_GOOGLE); |
251 | 251 | } catch (Exception $e) { |
@@ -275,18 +275,18 @@ discard block |
||
275 | 275 | $response = $apiService->request(self::PRINTERS_SEARCH_URL); |
276 | 276 | } catch (Exception $e) { |
277 | 277 | $this->errors[] = $e->getMessage(); |
278 | - print '<pre>'.print_r($e->getMessage(),true).'</pre>'; |
|
278 | + print '<pre>'.print_r($e->getMessage(), true).'</pre>'; |
|
279 | 279 | } |
280 | 280 | //print '<tr><td><pre>'.print_r($response, true).'</pre></td></tr>'; |
281 | 281 | $responsedata = json_decode($response, true); |
282 | 282 | $printers = $responsedata['printers']; |
283 | 283 | // Check if we have printers? |
284 | - if(count($printers)==0) { |
|
284 | + if (count($printers) == 0) { |
|
285 | 285 | // We dont have printers so return blank array |
286 | - $ret['available'] = array(); |
|
286 | + $ret['available'] = array(); |
|
287 | 287 | } else { |
288 | 288 | // We have printers so returns printers as array |
289 | - $ret['available'] = $printers; |
|
289 | + $ret['available'] = $printers; |
|
290 | 290 | } |
291 | 291 | return $ret; |
292 | 292 | } |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | * @param string $subdir subdir for file |
300 | 300 | * @return int 0 if OK, >0 if KO |
301 | 301 | */ |
302 | - public function printFile($file, $module, $subdir='') |
|
302 | + public function printFile($file, $module, $subdir = '') |
|
303 | 303 | { |
304 | 304 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
305 | 305 | |
@@ -307,10 +307,10 @@ discard block |
||
307 | 307 | $error = 0; |
308 | 308 | |
309 | 309 | $fileprint = $conf->{$module}->dir_output; |
310 | - if ($subdir!='') { |
|
311 | - $fileprint.='/'.$subdir; |
|
310 | + if ($subdir != '') { |
|
311 | + $fileprint .= '/'.$subdir; |
|
312 | 312 | } |
313 | - $fileprint.='/'.$file; |
|
313 | + $fileprint .= '/'.$file; |
|
314 | 314 | $mimetype = dol_mimetype($fileprint); |
315 | 315 | // select printer uri for module order, propal,... |
316 | 316 | $sql = "SELECT rowid, printer_id, copy FROM ".MAIN_DB_PREFIX."printing WHERE module='".$module."' AND driver='printgcp' AND userid=".$user->id; |
@@ -324,9 +324,9 @@ discard block |
||
324 | 324 | } |
325 | 325 | else |
326 | 326 | { |
327 | - if (! empty($conf->global->PRINTING_GCP_DEFAULT)) |
|
327 | + if (!empty($conf->global->PRINTING_GCP_DEFAULT)) |
|
328 | 328 | { |
329 | - $printer_id=$conf->global->PRINTING_GCP_DEFAULT; |
|
329 | + $printer_id = $conf->global->PRINTING_GCP_DEFAULT; |
|
330 | 330 | } |
331 | 331 | else |
332 | 332 | { |
@@ -340,7 +340,7 @@ discard block |
||
340 | 340 | |
341 | 341 | $ret = $this->sendPrintToPrinter($printer_id, $file, $fileprint, $mimetype); |
342 | 342 | $this->error = 'PRINTGCP: '.$ret['errormessage']; |
343 | - if ($ret['status']!=1) { |
|
343 | + if ($ret['status'] != 1) { |
|
344 | 344 | $error++; |
345 | 345 | } |
346 | 346 | return $error; |
@@ -358,13 +358,13 @@ discard block |
||
358 | 358 | public function sendPrintToPrinter($printerid, $printjobtitle, $filepath, $contenttype) |
359 | 359 | { |
360 | 360 | // Check if printer id |
361 | - if(empty($printerid)) { |
|
362 | - return array('status' =>0, 'errorcode' =>'','errormessage'=>'No provided printer ID'); |
|
361 | + if (empty($printerid)) { |
|
362 | + return array('status' =>0, 'errorcode' =>'', 'errormessage'=>'No provided printer ID'); |
|
363 | 363 | } |
364 | 364 | // Open the file which needs to be print |
365 | 365 | $handle = fopen($filepath, "rb"); |
366 | - if(!$handle) { |
|
367 | - return array('status' =>0, 'errorcode' =>'','errormessage'=>'Could not read the file.'); |
|
366 | + if (!$handle) { |
|
367 | + return array('status' =>0, 'errorcode' =>'', 'errormessage'=>'Could not read the file.'); |
|
368 | 368 | } |
369 | 369 | // Read file content |
370 | 370 | $contents = fread($handle, filesize($filepath)); |
@@ -389,7 +389,7 @@ discard block |
||
389 | 389 | $apiService = $serviceFactory->createService($this->OAUTH_SERVICENAME_GOOGLE, $credentials, $storage, array()); |
390 | 390 | |
391 | 391 | // Check if we have auth token and refresh it |
392 | - $token_ok=true; |
|
392 | + $token_ok = true; |
|
393 | 393 | try { |
394 | 394 | $token = $storage->retrieveAccessToken($this->OAUTH_SERVICENAME_GOOGLE); |
395 | 395 | } catch (Exception $e) { |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | $serviceFactory = new \OAuth\ServiceFactory(); |
438 | 438 | $apiService = $serviceFactory->createService($this->OAUTH_SERVICENAME_GOOGLE, $credentials, $storage, array()); |
439 | 439 | // Check if we have auth token |
440 | - $token_ok=true; |
|
440 | + $token_ok = true; |
|
441 | 441 | try { |
442 | 442 | $token = $storage->retrieveAccessToken($this->OAUTH_SERVICENAME_GOOGLE); |
443 | 443 | } catch (Exception $e) { |
@@ -149,12 +149,10 @@ discard block |
||
149 | 149 | if ($endoflife == $token::EOL_NEVER_EXPIRES) |
150 | 150 | { |
151 | 151 | $expiredat = $langs->trans("Never"); |
152 | - } |
|
153 | - elseif ($endoflife == $token::EOL_UNKNOWN) |
|
152 | + } elseif ($endoflife == $token::EOL_UNKNOWN) |
|
154 | 153 | { |
155 | 154 | $expiredat = $langs->trans("Unknown"); |
156 | - } |
|
157 | - else |
|
155 | + } else |
|
158 | 156 | { |
159 | 157 | $expiredat=dol_print_date($endoflife, "dayhour"); |
160 | 158 | } |
@@ -216,9 +214,9 @@ discard block |
||
216 | 214 | if ($conf->global->PRINTING_GCP_DEFAULT == $printer_det['id']) |
217 | 215 | { |
218 | 216 | $html.= img_picto($langs->trans("Default"),'on'); |
217 | + } else { |
|
218 | + $html.= '<a href="'.$_SERVER["PHP_SELF"].'?action=setvalue&mode=test&varname=PRINTING_GCP_DEFAULT&driver=printgcp&value='.urlencode($printer_det['id']).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>'; |
|
219 | 219 | } |
220 | - else |
|
221 | - $html.= '<a href="'.$_SERVER["PHP_SELF"].'?action=setvalue&mode=test&varname=PRINTING_GCP_DEFAULT&driver=printgcp&value='.urlencode($printer_det['id']).'" alt="'.$langs->trans("Default").'">'.img_picto($langs->trans("Disabled"),'off').'</a>'; |
|
222 | 220 | $html.= '</td>'; |
223 | 221 | $html.= '</tr>'."\n"; |
224 | 222 | } |
@@ -321,22 +319,21 @@ discard block |
||
321 | 319 | if ($obj) |
322 | 320 | { |
323 | 321 | $printer_id = $obj->printer_id; |
324 | - } |
|
325 | - else |
|
322 | + } else |
|
326 | 323 | { |
327 | 324 | if (! empty($conf->global->PRINTING_GCP_DEFAULT)) |
328 | 325 | { |
329 | 326 | $printer_id=$conf->global->PRINTING_GCP_DEFAULT; |
330 | - } |
|
331 | - else |
|
327 | + } else |
|
332 | 328 | { |
333 | 329 | $this->errors[] = 'NoDefaultPrinterDefined'; |
334 | 330 | $error++; |
335 | 331 | return $error; |
336 | 332 | } |
337 | 333 | } |
334 | + } else { |
|
335 | + dol_print_error($this->db); |
|
338 | 336 | } |
339 | - else dol_print_error($this->db); |
|
340 | 337 | |
341 | 338 | $ret = $this->sendPrintToPrinter($printer_id, $file, $fileprint, $mimetype); |
342 | 339 | $this->error = 'PRINTGCP: '.$ret['errormessage']; |
@@ -501,8 +498,7 @@ discard block |
||
501 | 498 | $html .= '<td> </td>'; |
502 | 499 | $html .= '</tr>'; |
503 | 500 | } |
504 | - } |
|
505 | - else |
|
501 | + } else |
|
506 | 502 | { |
507 | 503 | $html .= '<tr class="oddeven">'; |
508 | 504 | $html .= '<td colspan="7" class="opacitymedium">'.$langs->trans("None").'</td>'; |