@@ -40,550 +40,550 @@ |
||
40 | 40 | */ |
41 | 41 | class doc_generic_shipment_odt extends ModelePdfExpedition |
42 | 42 | { |
43 | - /** |
|
44 | - * Issuer |
|
45 | - * @var Societe |
|
46 | - */ |
|
47 | - public $emetteur; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var array() Minimum version of PHP required by module. |
|
51 | - * e.g.: PHP ≥ 5.4 = array(5, 4) |
|
52 | - */ |
|
53 | - public $phpmin = array(5, 4); |
|
54 | - |
|
55 | - /** |
|
43 | + /** |
|
44 | + * Issuer |
|
45 | + * @var Societe |
|
46 | + */ |
|
47 | + public $emetteur; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var array() Minimum version of PHP required by module. |
|
51 | + * e.g.: PHP ≥ 5.4 = array(5, 4) |
|
52 | + */ |
|
53 | + public $phpmin = array(5, 4); |
|
54 | + |
|
55 | + /** |
|
56 | 56 | * Dolibarr version of the loaded document |
57 | 57 | * @public string |
58 | 58 | */ |
59 | - public $version = 'dolibarr'; |
|
59 | + public $version = 'dolibarr'; |
|
60 | 60 | |
61 | 61 | |
62 | - /** |
|
63 | - * Constructor |
|
64 | - * |
|
65 | - * @param DoliDB $db Database handler |
|
66 | - */ |
|
67 | - function __construct($db) |
|
68 | - { |
|
69 | - global $conf, $langs, $mysoc; |
|
62 | + /** |
|
63 | + * Constructor |
|
64 | + * |
|
65 | + * @param DoliDB $db Database handler |
|
66 | + */ |
|
67 | + function __construct($db) |
|
68 | + { |
|
69 | + global $conf, $langs, $mysoc; |
|
70 | 70 | |
71 | - // Load translation files required by the page |
|
71 | + // Load translation files required by the page |
|
72 | 72 | $langs->loadLangs(array("main","companies")); |
73 | 73 | |
74 | - $this->db = $db; |
|
75 | - $this->name = "ODT templates"; |
|
76 | - $this->description = $langs->trans("DocumentModelOdt"); |
|
77 | - $this->scandir = 'EXPEDITION_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan |
|
78 | - |
|
79 | - // Dimension page pour format A4 |
|
80 | - $this->type = 'odt'; |
|
81 | - $this->page_largeur = 0; |
|
82 | - $this->page_hauteur = 0; |
|
83 | - $this->format = array($this->page_largeur,$this->page_hauteur); |
|
84 | - $this->marge_gauche=0; |
|
85 | - $this->marge_droite=0; |
|
86 | - $this->marge_haute=0; |
|
87 | - $this->marge_basse=0; |
|
88 | - |
|
89 | - $this->option_logo = 1; // Affiche logo |
|
90 | - $this->option_tva = 0; // Gere option tva EXPEDITION_TVAOPTION |
|
91 | - $this->option_modereg = 0; // Affiche mode reglement |
|
92 | - $this->option_condreg = 0; // Affiche conditions reglement |
|
93 | - $this->option_codeproduitservice = 0; // Affiche code produit-service |
|
94 | - $this->option_multilang = 1; // Dispo en plusieurs langues |
|
95 | - $this->option_escompte = 0; // Affiche si il y a eu escompte |
|
96 | - $this->option_credit_note = 0; // Support credit notes |
|
97 | - $this->option_freetext = 1; // Support add of a personalised text |
|
98 | - $this->option_draft_watermark = 0; // Support add of a watermark on drafts |
|
99 | - |
|
100 | - // Recupere emetteur |
|
101 | - $this->emetteur=$mysoc; |
|
102 | - if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default if not defined |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * Return description of a module |
|
108 | - * |
|
109 | - * @param Translate $langs Lang object to use for output |
|
110 | - * @return string Description |
|
111 | - */ |
|
112 | - function info($langs) |
|
113 | - { |
|
114 | - global $conf,$langs; |
|
115 | - |
|
116 | - // Load translation files required by the page |
|
74 | + $this->db = $db; |
|
75 | + $this->name = "ODT templates"; |
|
76 | + $this->description = $langs->trans("DocumentModelOdt"); |
|
77 | + $this->scandir = 'EXPEDITION_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan |
|
78 | + |
|
79 | + // Dimension page pour format A4 |
|
80 | + $this->type = 'odt'; |
|
81 | + $this->page_largeur = 0; |
|
82 | + $this->page_hauteur = 0; |
|
83 | + $this->format = array($this->page_largeur,$this->page_hauteur); |
|
84 | + $this->marge_gauche=0; |
|
85 | + $this->marge_droite=0; |
|
86 | + $this->marge_haute=0; |
|
87 | + $this->marge_basse=0; |
|
88 | + |
|
89 | + $this->option_logo = 1; // Affiche logo |
|
90 | + $this->option_tva = 0; // Gere option tva EXPEDITION_TVAOPTION |
|
91 | + $this->option_modereg = 0; // Affiche mode reglement |
|
92 | + $this->option_condreg = 0; // Affiche conditions reglement |
|
93 | + $this->option_codeproduitservice = 0; // Affiche code produit-service |
|
94 | + $this->option_multilang = 1; // Dispo en plusieurs langues |
|
95 | + $this->option_escompte = 0; // Affiche si il y a eu escompte |
|
96 | + $this->option_credit_note = 0; // Support credit notes |
|
97 | + $this->option_freetext = 1; // Support add of a personalised text |
|
98 | + $this->option_draft_watermark = 0; // Support add of a watermark on drafts |
|
99 | + |
|
100 | + // Recupere emetteur |
|
101 | + $this->emetteur=$mysoc; |
|
102 | + if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default if not defined |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * Return description of a module |
|
108 | + * |
|
109 | + * @param Translate $langs Lang object to use for output |
|
110 | + * @return string Description |
|
111 | + */ |
|
112 | + function info($langs) |
|
113 | + { |
|
114 | + global $conf,$langs; |
|
115 | + |
|
116 | + // Load translation files required by the page |
|
117 | 117 | $langs->loadLangs(array("errors","companies")); |
118 | 118 | |
119 | - $form = new Form($this->db); |
|
120 | - |
|
121 | - $texte = $this->description.".<br>\n"; |
|
122 | - $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
123 | - $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
124 | - $texte.= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
125 | - $texte.= '<input type="hidden" name="param1" value="EXPEDITION_ADDON_PDF_ODT_PATH">'; |
|
126 | - $texte.= '<table class="nobordernopadding" width="100%">'; |
|
127 | - |
|
128 | - // List of directories area |
|
129 | - $texte.= '<tr><td>'; |
|
130 | - $texttitle=$langs->trans("ListOfDirectories"); |
|
131 | - $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->EXPEDITION_ADDON_PDF_ODT_PATH))); |
|
132 | - $listoffiles=array(); |
|
133 | - foreach($listofdir as $key=>$tmpdir) |
|
134 | - { |
|
135 | - $tmpdir=trim($tmpdir); |
|
136 | - $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); |
|
137 | - if (! $tmpdir) { |
|
138 | - unset($listofdir[$key]); continue; |
|
139 | - } |
|
140 | - if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); |
|
141 | - else |
|
142 | - { |
|
143 | - $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)'); |
|
144 | - if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
145 | - } |
|
146 | - } |
|
147 | - $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT"); |
|
148 | - // Add list of substitution keys |
|
149 | - $texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>'; |
|
150 | - $texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it |
|
151 | - |
|
152 | - $texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1); |
|
153 | - $texte.= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">'; |
|
154 | - $texte.= '<textarea class="flat" cols="60" name="value1">'; |
|
155 | - $texte.=$conf->global->EXPEDITION_ADDON_PDF_ODT_PATH; |
|
156 | - $texte.= '</textarea>'; |
|
157 | - $texte.= '</div><div style="display: inline-block; vertical-align: middle;">'; |
|
158 | - $texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">'; |
|
159 | - $texte.= '<br></div></div>'; |
|
160 | - |
|
161 | - // Scan directories |
|
162 | - $nbofiles=count($listoffiles); |
|
163 | - if (! empty($conf->global->EXPEDITION_ADDON_PDF_ODT_PATH)) |
|
164 | - { |
|
165 | - $texte.=$langs->trans("NumberOfModelFilesFound").': <b>'; |
|
166 | - //$texte.=$nbofiles?'<a id="a_'.get_class($this).'" href="#">':''; |
|
167 | - $texte.=count($listoffiles); |
|
168 | - //$texte.=$nbofiles?'</a>':''; |
|
169 | - $texte.='</b>'; |
|
170 | - } |
|
171 | - if ($nbofiles) |
|
172 | - { |
|
173 | - $texte.='<div id="div_'.get_class($this).'" class="hidden">'; |
|
174 | - foreach($listoffiles as $file) |
|
175 | - { |
|
119 | + $form = new Form($this->db); |
|
120 | + |
|
121 | + $texte = $this->description.".<br>\n"; |
|
122 | + $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
123 | + $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
124 | + $texte.= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
125 | + $texte.= '<input type="hidden" name="param1" value="EXPEDITION_ADDON_PDF_ODT_PATH">'; |
|
126 | + $texte.= '<table class="nobordernopadding" width="100%">'; |
|
127 | + |
|
128 | + // List of directories area |
|
129 | + $texte.= '<tr><td>'; |
|
130 | + $texttitle=$langs->trans("ListOfDirectories"); |
|
131 | + $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->EXPEDITION_ADDON_PDF_ODT_PATH))); |
|
132 | + $listoffiles=array(); |
|
133 | + foreach($listofdir as $key=>$tmpdir) |
|
134 | + { |
|
135 | + $tmpdir=trim($tmpdir); |
|
136 | + $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); |
|
137 | + if (! $tmpdir) { |
|
138 | + unset($listofdir[$key]); continue; |
|
139 | + } |
|
140 | + if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); |
|
141 | + else |
|
142 | + { |
|
143 | + $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)'); |
|
144 | + if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
145 | + } |
|
146 | + } |
|
147 | + $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT"); |
|
148 | + // Add list of substitution keys |
|
149 | + $texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>'; |
|
150 | + $texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it |
|
151 | + |
|
152 | + $texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1); |
|
153 | + $texte.= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">'; |
|
154 | + $texte.= '<textarea class="flat" cols="60" name="value1">'; |
|
155 | + $texte.=$conf->global->EXPEDITION_ADDON_PDF_ODT_PATH; |
|
156 | + $texte.= '</textarea>'; |
|
157 | + $texte.= '</div><div style="display: inline-block; vertical-align: middle;">'; |
|
158 | + $texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">'; |
|
159 | + $texte.= '<br></div></div>'; |
|
160 | + |
|
161 | + // Scan directories |
|
162 | + $nbofiles=count($listoffiles); |
|
163 | + if (! empty($conf->global->EXPEDITION_ADDON_PDF_ODT_PATH)) |
|
164 | + { |
|
165 | + $texte.=$langs->trans("NumberOfModelFilesFound").': <b>'; |
|
166 | + //$texte.=$nbofiles?'<a id="a_'.get_class($this).'" href="#">':''; |
|
167 | + $texte.=count($listoffiles); |
|
168 | + //$texte.=$nbofiles?'</a>':''; |
|
169 | + $texte.='</b>'; |
|
170 | + } |
|
171 | + if ($nbofiles) |
|
172 | + { |
|
173 | + $texte.='<div id="div_'.get_class($this).'" class="hidden">'; |
|
174 | + foreach($listoffiles as $file) |
|
175 | + { |
|
176 | 176 | $texte.=$file['name'].'<br>'; |
177 | - } |
|
178 | - $texte.='<div id="div_'.get_class($this).'">'; |
|
179 | - } |
|
177 | + } |
|
178 | + $texte.='<div id="div_'.get_class($this).'">'; |
|
179 | + } |
|
180 | 180 | |
181 | - $texte.= '</td>'; |
|
181 | + $texte.= '</td>'; |
|
182 | 182 | |
183 | - $texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">'; |
|
184 | - $texte.= $langs->trans("ExampleOfDirectoriesForModelGen"); |
|
185 | - $texte.= '</td>'; |
|
186 | - $texte.= '</tr>'; |
|
183 | + $texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">'; |
|
184 | + $texte.= $langs->trans("ExampleOfDirectoriesForModelGen"); |
|
185 | + $texte.= '</td>'; |
|
186 | + $texte.= '</tr>'; |
|
187 | 187 | |
188 | - $texte.= '</table>'; |
|
189 | - $texte.= '</form>'; |
|
188 | + $texte.= '</table>'; |
|
189 | + $texte.= '</form>'; |
|
190 | 190 | |
191 | - return $texte; |
|
192 | - } |
|
191 | + return $texte; |
|
192 | + } |
|
193 | 193 | |
194 | 194 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
195 | - /** |
|
196 | - * Function to build a document on disk using the generic odt module. |
|
197 | - * |
|
198 | - * @param Expedition $object Object source to build document |
|
199 | - * @param Translate $outputlangs Lang output object |
|
200 | - * @param string $srctemplatepath Full path of source filename for generator using a template file |
|
201 | - * @param int $hidedetails Do not show line details |
|
202 | - * @param int $hidedesc Do not show desc |
|
203 | - * @param int $hideref Do not show ref |
|
204 | - * @return int 1 if OK, <=0 if KO |
|
205 | - */ |
|
206 | - function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0) |
|
207 | - { |
|
195 | + /** |
|
196 | + * Function to build a document on disk using the generic odt module. |
|
197 | + * |
|
198 | + * @param Expedition $object Object source to build document |
|
199 | + * @param Translate $outputlangs Lang output object |
|
200 | + * @param string $srctemplatepath Full path of source filename for generator using a template file |
|
201 | + * @param int $hidedetails Do not show line details |
|
202 | + * @param int $hidedesc Do not show desc |
|
203 | + * @param int $hideref Do not show ref |
|
204 | + * @return int 1 if OK, <=0 if KO |
|
205 | + */ |
|
206 | + function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0) |
|
207 | + { |
|
208 | 208 | // phpcs:enable |
209 | - global $user,$langs,$conf,$mysoc,$hookmanager; |
|
210 | - |
|
211 | - if (empty($srctemplatepath)) |
|
212 | - { |
|
213 | - dol_syslog("doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING); |
|
214 | - return -1; |
|
215 | - } |
|
216 | - |
|
217 | - // Add odtgeneration hook |
|
218 | - if (! is_object($hookmanager)) |
|
219 | - { |
|
220 | - include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; |
|
221 | - $hookmanager=new HookManager($this->db); |
|
222 | - } |
|
223 | - $hookmanager->initHooks(array('odtgeneration')); |
|
224 | - global $action; |
|
225 | - |
|
226 | - if (! is_object($outputlangs)) $outputlangs=$langs; |
|
227 | - $sav_charset_output=$outputlangs->charset_output; |
|
228 | - $outputlangs->charset_output='UTF-8'; |
|
229 | - |
|
230 | - // Load traductions files requiredby by page |
|
231 | - $outputlangs->loadLangs(array("main", "dict", "companies", "bills")); |
|
232 | - |
|
233 | - if ($conf->expedition->dir_output."/sending") |
|
234 | - { |
|
235 | - // If $object is id instead of object |
|
236 | - if (! is_object($object)) |
|
237 | - { |
|
238 | - $id = $object; |
|
239 | - $object = new Expedition($this->db); |
|
240 | - $result=$object->fetch($id); |
|
241 | - if ($result < 0) |
|
242 | - { |
|
243 | - dol_print_error($this->db,$object->error); |
|
244 | - return -1; |
|
245 | - } |
|
246 | - } |
|
247 | - |
|
248 | - $dir = $conf->expedition->dir_output."/sending"; |
|
249 | - $objectref = dol_sanitizeFileName($object->ref); |
|
250 | - if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref; |
|
251 | - $file = $dir . "/" . $objectref . ".odt"; |
|
252 | - |
|
253 | - if (! file_exists($dir)) |
|
254 | - { |
|
255 | - if (dol_mkdir($dir) < 0) |
|
256 | - { |
|
257 | - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
258 | - return -1; |
|
259 | - } |
|
260 | - } |
|
261 | - |
|
262 | - if (file_exists($dir)) |
|
263 | - { |
|
264 | - //print "srctemplatepath=".$srctemplatepath; // Src filename |
|
265 | - $newfile=basename($srctemplatepath); |
|
266 | - $newfiletmp=preg_replace('/\.od(t|s)/i','',$newfile); |
|
267 | - $newfiletmp=preg_replace('/template_/i','',$newfiletmp); |
|
268 | - $newfiletmp=preg_replace('/modele_/i','',$newfiletmp); |
|
269 | - $newfiletmp=$objectref.'_'.$newfiletmp; |
|
270 | - //$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt'; |
|
271 | - // Get extension (ods or odt) |
|
272 | - $newfileformat=substr($newfile, strrpos($newfile, '.')+1); |
|
273 | - if ( ! empty($conf->global->MAIN_DOC_USE_TIMING)) |
|
274 | - { |
|
275 | - $format=$conf->global->MAIN_DOC_USE_TIMING; |
|
276 | - if ($format == '1') $format='%Y%m%d%H%M%S'; |
|
277 | - $filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat; |
|
278 | - } |
|
279 | - else |
|
280 | - { |
|
281 | - $filename=$newfiletmp.'.'.$newfileformat; |
|
282 | - } |
|
283 | - $file=$dir.'/'.$filename; |
|
284 | - //print "newdir=".$dir; |
|
285 | - //print "newfile=".$newfile; |
|
286 | - //print "file=".$file; |
|
287 | - //print "conf->societe->dir_temp=".$conf->societe->dir_temp; |
|
288 | - |
|
289 | - dol_mkdir($conf->expedition->dir_temp); |
|
290 | - |
|
291 | - |
|
292 | - // If SHIPMENT contact defined on invoice, we use it |
|
293 | - $usecontact=false; |
|
294 | - $arrayidcontact=$object->getIdContact('external','SHIPPING'); |
|
295 | - if (count($arrayidcontact) > 0) |
|
296 | - { |
|
297 | - $usecontact=true; |
|
298 | - $result=$object->fetch_contact($arrayidcontact[0]); |
|
299 | - } |
|
300 | - |
|
301 | - // Recipient name |
|
302 | - $contactobject = null; |
|
303 | - if (! empty($usecontact)) { |
|
304 | - // On peut utiliser le nom de la societe du contact |
|
305 | - if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) |
|
306 | - $socobject = $object->contact; |
|
307 | - else { |
|
308 | - $socobject = $object->thirdparty; |
|
309 | - // if we have a SHIIPPING contact and we dont use it as recipient we store the contact object for later use |
|
310 | - $contactobject = $object->contact; |
|
311 | - } |
|
312 | - } else { |
|
313 | - $socobject = $object->thirdparty; |
|
314 | - } |
|
315 | - |
|
316 | - // Make substitution |
|
317 | - $substitutionarray=array( |
|
318 | - '__FROM_NAME__' => $this->emetteur->name, |
|
319 | - '__FROM_EMAIL__' => $this->emetteur->email, |
|
320 | - '__TOTAL_TTC__' => $object->total_ttc, |
|
321 | - '__TOTAL_HT__' => $object->total_ht, |
|
322 | - '__TOTAL_VAT__' => $object->total_vat |
|
323 | - ); |
|
324 | - complete_substitutions_array($substitutionarray, $langs, $object); |
|
325 | - // Call the ODTSubstitution hook |
|
326 | - $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray); |
|
327 | - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
328 | - |
|
329 | - // Line of free text |
|
330 | - $newfreetext=''; |
|
331 | - $paramfreetext='EXPEDITION_FREE_TEXT'; |
|
332 | - if (! empty($conf->global->$paramfreetext)) |
|
333 | - { |
|
334 | - $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray); |
|
335 | - } |
|
336 | - |
|
337 | - // Open and load template |
|
338 | - require_once ODTPHP_PATH.'odf.php'; |
|
339 | - try { |
|
340 | - $odfHandler = new odf( |
|
341 | - $srctemplatepath, |
|
342 | - array( |
|
343 | - 'PATH_TO_TMP' => $conf->expedition->dir_temp, |
|
344 | - 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. |
|
345 | - 'DELIMITER_LEFT' => '{', |
|
346 | - 'DELIMITER_RIGHT' => '}' |
|
347 | - ) |
|
348 | - ); |
|
349 | - } |
|
350 | - catch(Exception $e) |
|
351 | - { |
|
352 | - $this->error=$e->getMessage(); |
|
353 | - dol_syslog($e->getMessage(), LOG_INFO); |
|
354 | - return -1; |
|
355 | - } |
|
356 | - // After construction $odfHandler->contentXml contains content and |
|
357 | - // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by |
|
358 | - // [!-- BEGIN lines --]*[!-- END lines --] |
|
359 | - //print html_entity_decode($odfHandler->__toString()); |
|
360 | - //print exit; |
|
361 | - |
|
362 | - |
|
363 | - // Make substitutions into odt of freetext |
|
364 | - try { |
|
365 | - $odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8'); |
|
366 | - } |
|
367 | - catch(OdfException $e) |
|
368 | - { |
|
369 | - dol_syslog($e->getMessage(), LOG_INFO); |
|
370 | - } |
|
371 | - |
|
372 | - // Make substitutions into odt of user info |
|
373 | - $tmparray=$this->get_substitutionarray_user($user,$outputlangs); |
|
374 | - //var_dump($tmparray); exit; |
|
375 | - foreach($tmparray as $key=>$value) |
|
376 | - { |
|
377 | - try { |
|
378 | - if (preg_match('/logo$/',$key)) // Image |
|
379 | - { |
|
380 | - //var_dump($value);exit; |
|
381 | - if (file_exists($value)) $odfHandler->setImage($key, $value); |
|
382 | - else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
|
383 | - } |
|
384 | - else // Text |
|
385 | - { |
|
386 | - $odfHandler->setVars($key, $value, true, 'UTF-8'); |
|
387 | - } |
|
388 | - } |
|
389 | - catch (OdfException $e) |
|
390 | - { |
|
209 | + global $user,$langs,$conf,$mysoc,$hookmanager; |
|
210 | + |
|
211 | + if (empty($srctemplatepath)) |
|
212 | + { |
|
213 | + dol_syslog("doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING); |
|
214 | + return -1; |
|
215 | + } |
|
216 | + |
|
217 | + // Add odtgeneration hook |
|
218 | + if (! is_object($hookmanager)) |
|
219 | + { |
|
220 | + include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; |
|
221 | + $hookmanager=new HookManager($this->db); |
|
222 | + } |
|
223 | + $hookmanager->initHooks(array('odtgeneration')); |
|
224 | + global $action; |
|
225 | + |
|
226 | + if (! is_object($outputlangs)) $outputlangs=$langs; |
|
227 | + $sav_charset_output=$outputlangs->charset_output; |
|
228 | + $outputlangs->charset_output='UTF-8'; |
|
229 | + |
|
230 | + // Load traductions files requiredby by page |
|
231 | + $outputlangs->loadLangs(array("main", "dict", "companies", "bills")); |
|
232 | + |
|
233 | + if ($conf->expedition->dir_output."/sending") |
|
234 | + { |
|
235 | + // If $object is id instead of object |
|
236 | + if (! is_object($object)) |
|
237 | + { |
|
238 | + $id = $object; |
|
239 | + $object = new Expedition($this->db); |
|
240 | + $result=$object->fetch($id); |
|
241 | + if ($result < 0) |
|
242 | + { |
|
243 | + dol_print_error($this->db,$object->error); |
|
244 | + return -1; |
|
245 | + } |
|
246 | + } |
|
247 | + |
|
248 | + $dir = $conf->expedition->dir_output."/sending"; |
|
249 | + $objectref = dol_sanitizeFileName($object->ref); |
|
250 | + if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref; |
|
251 | + $file = $dir . "/" . $objectref . ".odt"; |
|
252 | + |
|
253 | + if (! file_exists($dir)) |
|
254 | + { |
|
255 | + if (dol_mkdir($dir) < 0) |
|
256 | + { |
|
257 | + $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
258 | + return -1; |
|
259 | + } |
|
260 | + } |
|
261 | + |
|
262 | + if (file_exists($dir)) |
|
263 | + { |
|
264 | + //print "srctemplatepath=".$srctemplatepath; // Src filename |
|
265 | + $newfile=basename($srctemplatepath); |
|
266 | + $newfiletmp=preg_replace('/\.od(t|s)/i','',$newfile); |
|
267 | + $newfiletmp=preg_replace('/template_/i','',$newfiletmp); |
|
268 | + $newfiletmp=preg_replace('/modele_/i','',$newfiletmp); |
|
269 | + $newfiletmp=$objectref.'_'.$newfiletmp; |
|
270 | + //$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt'; |
|
271 | + // Get extension (ods or odt) |
|
272 | + $newfileformat=substr($newfile, strrpos($newfile, '.')+1); |
|
273 | + if ( ! empty($conf->global->MAIN_DOC_USE_TIMING)) |
|
274 | + { |
|
275 | + $format=$conf->global->MAIN_DOC_USE_TIMING; |
|
276 | + if ($format == '1') $format='%Y%m%d%H%M%S'; |
|
277 | + $filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat; |
|
278 | + } |
|
279 | + else |
|
280 | + { |
|
281 | + $filename=$newfiletmp.'.'.$newfileformat; |
|
282 | + } |
|
283 | + $file=$dir.'/'.$filename; |
|
284 | + //print "newdir=".$dir; |
|
285 | + //print "newfile=".$newfile; |
|
286 | + //print "file=".$file; |
|
287 | + //print "conf->societe->dir_temp=".$conf->societe->dir_temp; |
|
288 | + |
|
289 | + dol_mkdir($conf->expedition->dir_temp); |
|
290 | + |
|
291 | + |
|
292 | + // If SHIPMENT contact defined on invoice, we use it |
|
293 | + $usecontact=false; |
|
294 | + $arrayidcontact=$object->getIdContact('external','SHIPPING'); |
|
295 | + if (count($arrayidcontact) > 0) |
|
296 | + { |
|
297 | + $usecontact=true; |
|
298 | + $result=$object->fetch_contact($arrayidcontact[0]); |
|
299 | + } |
|
300 | + |
|
301 | + // Recipient name |
|
302 | + $contactobject = null; |
|
303 | + if (! empty($usecontact)) { |
|
304 | + // On peut utiliser le nom de la societe du contact |
|
305 | + if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) |
|
306 | + $socobject = $object->contact; |
|
307 | + else { |
|
308 | + $socobject = $object->thirdparty; |
|
309 | + // if we have a SHIIPPING contact and we dont use it as recipient we store the contact object for later use |
|
310 | + $contactobject = $object->contact; |
|
311 | + } |
|
312 | + } else { |
|
313 | + $socobject = $object->thirdparty; |
|
314 | + } |
|
315 | + |
|
316 | + // Make substitution |
|
317 | + $substitutionarray=array( |
|
318 | + '__FROM_NAME__' => $this->emetteur->name, |
|
319 | + '__FROM_EMAIL__' => $this->emetteur->email, |
|
320 | + '__TOTAL_TTC__' => $object->total_ttc, |
|
321 | + '__TOTAL_HT__' => $object->total_ht, |
|
322 | + '__TOTAL_VAT__' => $object->total_vat |
|
323 | + ); |
|
324 | + complete_substitutions_array($substitutionarray, $langs, $object); |
|
325 | + // Call the ODTSubstitution hook |
|
326 | + $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray); |
|
327 | + $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
328 | + |
|
329 | + // Line of free text |
|
330 | + $newfreetext=''; |
|
331 | + $paramfreetext='EXPEDITION_FREE_TEXT'; |
|
332 | + if (! empty($conf->global->$paramfreetext)) |
|
333 | + { |
|
334 | + $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray); |
|
335 | + } |
|
336 | + |
|
337 | + // Open and load template |
|
338 | + require_once ODTPHP_PATH.'odf.php'; |
|
339 | + try { |
|
340 | + $odfHandler = new odf( |
|
341 | + $srctemplatepath, |
|
342 | + array( |
|
343 | + 'PATH_TO_TMP' => $conf->expedition->dir_temp, |
|
344 | + 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. |
|
345 | + 'DELIMITER_LEFT' => '{', |
|
346 | + 'DELIMITER_RIGHT' => '}' |
|
347 | + ) |
|
348 | + ); |
|
349 | + } |
|
350 | + catch(Exception $e) |
|
351 | + { |
|
352 | + $this->error=$e->getMessage(); |
|
353 | + dol_syslog($e->getMessage(), LOG_INFO); |
|
354 | + return -1; |
|
355 | + } |
|
356 | + // After construction $odfHandler->contentXml contains content and |
|
357 | + // [!-- BEGIN row.lines --]*[!-- END row.lines --] has been replaced by |
|
358 | + // [!-- BEGIN lines --]*[!-- END lines --] |
|
359 | + //print html_entity_decode($odfHandler->__toString()); |
|
360 | + //print exit; |
|
361 | + |
|
362 | + |
|
363 | + // Make substitutions into odt of freetext |
|
364 | + try { |
|
365 | + $odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8'); |
|
366 | + } |
|
367 | + catch(OdfException $e) |
|
368 | + { |
|
369 | + dol_syslog($e->getMessage(), LOG_INFO); |
|
370 | + } |
|
371 | + |
|
372 | + // Make substitutions into odt of user info |
|
373 | + $tmparray=$this->get_substitutionarray_user($user,$outputlangs); |
|
374 | + //var_dump($tmparray); exit; |
|
375 | + foreach($tmparray as $key=>$value) |
|
376 | + { |
|
377 | + try { |
|
378 | + if (preg_match('/logo$/',$key)) // Image |
|
379 | + { |
|
380 | + //var_dump($value);exit; |
|
381 | + if (file_exists($value)) $odfHandler->setImage($key, $value); |
|
382 | + else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
|
383 | + } |
|
384 | + else // Text |
|
385 | + { |
|
386 | + $odfHandler->setVars($key, $value, true, 'UTF-8'); |
|
387 | + } |
|
388 | + } |
|
389 | + catch (OdfException $e) |
|
390 | + { |
|
391 | 391 | dol_syslog($e->getMessage(), LOG_INFO); |
392 | - } |
|
393 | - } |
|
394 | - // Make substitutions into odt of mysoc |
|
395 | - $tmparray=$this->get_substitutionarray_mysoc($mysoc,$outputlangs); |
|
396 | - //var_dump($tmparray); exit; |
|
397 | - foreach($tmparray as $key=>$value) |
|
398 | - { |
|
399 | - try { |
|
400 | - if (preg_match('/logo$/',$key)) // Image |
|
401 | - { |
|
402 | - //var_dump($value);exit; |
|
403 | - if (file_exists($value)) $odfHandler->setImage($key, $value); |
|
404 | - else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
|
405 | - } |
|
406 | - else // Text |
|
407 | - { |
|
408 | - $odfHandler->setVars($key, $value, true, 'UTF-8'); |
|
409 | - } |
|
410 | - } |
|
411 | - catch (OdfException $e) |
|
412 | - { |
|
392 | + } |
|
393 | + } |
|
394 | + // Make substitutions into odt of mysoc |
|
395 | + $tmparray=$this->get_substitutionarray_mysoc($mysoc,$outputlangs); |
|
396 | + //var_dump($tmparray); exit; |
|
397 | + foreach($tmparray as $key=>$value) |
|
398 | + { |
|
399 | + try { |
|
400 | + if (preg_match('/logo$/',$key)) // Image |
|
401 | + { |
|
402 | + //var_dump($value);exit; |
|
403 | + if (file_exists($value)) $odfHandler->setImage($key, $value); |
|
404 | + else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
|
405 | + } |
|
406 | + else // Text |
|
407 | + { |
|
408 | + $odfHandler->setVars($key, $value, true, 'UTF-8'); |
|
409 | + } |
|
410 | + } |
|
411 | + catch (OdfException $e) |
|
412 | + { |
|
413 | 413 | dol_syslog($e->getMessage(), LOG_INFO); |
414 | - } |
|
415 | - } |
|
416 | - // Make substitutions into odt of thirdparty |
|
417 | - $tmparray=$this->get_substitutionarray_thirdparty($socobject,$outputlangs); |
|
418 | - foreach($tmparray as $key=>$value) |
|
419 | - { |
|
420 | - try { |
|
421 | - if (preg_match('/logo$/',$key)) // Image |
|
422 | - { |
|
423 | - if (file_exists($value)) $odfHandler->setImage($key, $value); |
|
424 | - else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
|
425 | - } |
|
426 | - else // Text |
|
427 | - { |
|
428 | - $odfHandler->setVars($key, $value, true, 'UTF-8'); |
|
429 | - } |
|
430 | - } |
|
431 | - catch (OdfException $e) |
|
432 | - { |
|
414 | + } |
|
415 | + } |
|
416 | + // Make substitutions into odt of thirdparty |
|
417 | + $tmparray=$this->get_substitutionarray_thirdparty($socobject,$outputlangs); |
|
418 | + foreach($tmparray as $key=>$value) |
|
419 | + { |
|
420 | + try { |
|
421 | + if (preg_match('/logo$/',$key)) // Image |
|
422 | + { |
|
423 | + if (file_exists($value)) $odfHandler->setImage($key, $value); |
|
424 | + else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
|
425 | + } |
|
426 | + else // Text |
|
427 | + { |
|
428 | + $odfHandler->setVars($key, $value, true, 'UTF-8'); |
|
429 | + } |
|
430 | + } |
|
431 | + catch (OdfException $e) |
|
432 | + { |
|
433 | 433 | dol_syslog($e->getMessage(), LOG_INFO); |
434 | - } |
|
435 | - } |
|
436 | - |
|
437 | - if ($usecontact && is_object($contactobject)) { |
|
438 | - $tmparray=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact'); |
|
439 | - foreach($tmparray as $key=>$value) |
|
440 | - { |
|
441 | - try { |
|
442 | - if (preg_match('/logo$/',$key)) // Image |
|
443 | - { |
|
444 | - if (file_exists($value)) $odfHandler->setImage($key, $value); |
|
445 | - else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
|
446 | - } |
|
447 | - else // Text |
|
448 | - { |
|
449 | - $odfHandler->setVars($key, $value, true, 'UTF-8'); |
|
450 | - } |
|
451 | - } |
|
452 | - catch(OdfException $e) |
|
453 | - { |
|
434 | + } |
|
435 | + } |
|
436 | + |
|
437 | + if ($usecontact && is_object($contactobject)) { |
|
438 | + $tmparray=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact'); |
|
439 | + foreach($tmparray as $key=>$value) |
|
440 | + { |
|
441 | + try { |
|
442 | + if (preg_match('/logo$/',$key)) // Image |
|
443 | + { |
|
444 | + if (file_exists($value)) $odfHandler->setImage($key, $value); |
|
445 | + else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
|
446 | + } |
|
447 | + else // Text |
|
448 | + { |
|
449 | + $odfHandler->setVars($key, $value, true, 'UTF-8'); |
|
450 | + } |
|
451 | + } |
|
452 | + catch(OdfException $e) |
|
453 | + { |
|
454 | 454 | dol_syslog($e->getMessage(), LOG_INFO); |
455 | - } |
|
456 | - } |
|
457 | - } |
|
458 | - |
|
459 | - // Replace tags of object + external modules |
|
460 | - $tmparray=$this->get_substitutionarray_shipment($object,$outputlangs); |
|
461 | - complete_substitutions_array($tmparray, $outputlangs, $object); |
|
462 | - // Call the ODTSubstitution hook |
|
463 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
464 | - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
465 | - foreach($tmparray as $key=>$value) |
|
466 | - { |
|
467 | - try { |
|
468 | - if (preg_match('/logo$/',$key)) // Image |
|
469 | - { |
|
470 | - if (file_exists($value)) $odfHandler->setImage($key, $value); |
|
471 | - else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
|
472 | - } |
|
473 | - else // Text |
|
474 | - { |
|
475 | - $odfHandler->setVars($key, $value, true, 'UTF-8'); |
|
476 | - } |
|
477 | - } |
|
478 | - catch(OdfException $e) |
|
479 | - { |
|
455 | + } |
|
456 | + } |
|
457 | + } |
|
458 | + |
|
459 | + // Replace tags of object + external modules |
|
460 | + $tmparray=$this->get_substitutionarray_shipment($object,$outputlangs); |
|
461 | + complete_substitutions_array($tmparray, $outputlangs, $object); |
|
462 | + // Call the ODTSubstitution hook |
|
463 | + $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
464 | + $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
465 | + foreach($tmparray as $key=>$value) |
|
466 | + { |
|
467 | + try { |
|
468 | + if (preg_match('/logo$/',$key)) // Image |
|
469 | + { |
|
470 | + if (file_exists($value)) $odfHandler->setImage($key, $value); |
|
471 | + else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
|
472 | + } |
|
473 | + else // Text |
|
474 | + { |
|
475 | + $odfHandler->setVars($key, $value, true, 'UTF-8'); |
|
476 | + } |
|
477 | + } |
|
478 | + catch(OdfException $e) |
|
479 | + { |
|
480 | + dol_syslog($e->getMessage(), LOG_INFO); |
|
481 | + } |
|
482 | + } |
|
483 | + // Replace tags of lines |
|
484 | + try |
|
485 | + { |
|
486 | + $foundtagforlines = 1; |
|
487 | + try { |
|
488 | + $listlines = $odfHandler->setSegment('lines'); |
|
489 | + } |
|
490 | + catch(OdfException $e) |
|
491 | + { |
|
492 | + // We may arrive here if tags for lines not present into template |
|
493 | + $foundtagforlines = 0; |
|
480 | 494 | dol_syslog($e->getMessage(), LOG_INFO); |
481 | - } |
|
482 | - } |
|
483 | - // Replace tags of lines |
|
484 | - try |
|
485 | - { |
|
486 | - $foundtagforlines = 1; |
|
487 | - try { |
|
488 | - $listlines = $odfHandler->setSegment('lines'); |
|
489 | - } |
|
490 | - catch(OdfException $e) |
|
491 | - { |
|
492 | - // We may arrive here if tags for lines not present into template |
|
493 | - $foundtagforlines = 0; |
|
494 | - dol_syslog($e->getMessage(), LOG_INFO); |
|
495 | - } |
|
496 | - if ($foundtagforlines) |
|
497 | - { |
|
498 | - foreach ($object->lines as $line) |
|
499 | - { |
|
500 | - $tmparray=$this->get_substitutionarray_shipment_lines($line,$outputlangs); |
|
501 | - complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines"); |
|
502 | - // Call the ODTSubstitutionLine hook |
|
503 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line); |
|
504 | - $reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
505 | - foreach($tmparray as $key => $val) |
|
506 | - { |
|
507 | - try |
|
508 | - { |
|
509 | - $listlines->setVars($key, $val, true, 'UTF-8'); |
|
510 | - } |
|
511 | - catch(OdfException $e) |
|
512 | - { |
|
513 | - dol_syslog($e->getMessage(), LOG_INFO); |
|
514 | - } |
|
515 | - catch(SegmentException $e) |
|
516 | - { |
|
517 | - dol_syslog($e->getMessage(), LOG_INFO); |
|
518 | - } |
|
519 | - } |
|
520 | - $listlines->merge(); |
|
521 | - } |
|
522 | - $odfHandler->mergeSegment($listlines); |
|
523 | - } |
|
524 | - } |
|
525 | - catch (OdfException $e) |
|
526 | - { |
|
527 | - $this->error=$e->getMessage(); |
|
528 | - dol_syslog($this->error, LOG_WARNING); |
|
529 | - return -1; |
|
530 | - } |
|
531 | - |
|
532 | - // Replace labels translated |
|
533 | - $tmparray=$outputlangs->get_translations_for_substitutions(); |
|
534 | - foreach($tmparray as $key=>$value) |
|
535 | - { |
|
536 | - try { |
|
537 | - $odfHandler->setVars($key, $value, true, 'UTF-8'); |
|
538 | - } |
|
539 | - catch (OdfException $e) |
|
540 | - { |
|
495 | + } |
|
496 | + if ($foundtagforlines) |
|
497 | + { |
|
498 | + foreach ($object->lines as $line) |
|
499 | + { |
|
500 | + $tmparray=$this->get_substitutionarray_shipment_lines($line,$outputlangs); |
|
501 | + complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines"); |
|
502 | + // Call the ODTSubstitutionLine hook |
|
503 | + $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line); |
|
504 | + $reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
505 | + foreach($tmparray as $key => $val) |
|
506 | + { |
|
507 | + try |
|
508 | + { |
|
509 | + $listlines->setVars($key, $val, true, 'UTF-8'); |
|
510 | + } |
|
511 | + catch(OdfException $e) |
|
512 | + { |
|
513 | + dol_syslog($e->getMessage(), LOG_INFO); |
|
514 | + } |
|
515 | + catch(SegmentException $e) |
|
516 | + { |
|
517 | + dol_syslog($e->getMessage(), LOG_INFO); |
|
518 | + } |
|
519 | + } |
|
520 | + $listlines->merge(); |
|
521 | + } |
|
522 | + $odfHandler->mergeSegment($listlines); |
|
523 | + } |
|
524 | + } |
|
525 | + catch (OdfException $e) |
|
526 | + { |
|
527 | + $this->error=$e->getMessage(); |
|
528 | + dol_syslog($this->error, LOG_WARNING); |
|
529 | + return -1; |
|
530 | + } |
|
531 | + |
|
532 | + // Replace labels translated |
|
533 | + $tmparray=$outputlangs->get_translations_for_substitutions(); |
|
534 | + foreach($tmparray as $key=>$value) |
|
535 | + { |
|
536 | + try { |
|
537 | + $odfHandler->setVars($key, $value, true, 'UTF-8'); |
|
538 | + } |
|
539 | + catch (OdfException $e) |
|
540 | + { |
|
541 | 541 | dol_syslog($e->getMessage(), LOG_INFO); |
542 | - } |
|
543 | - } |
|
544 | - |
|
545 | - // Call the beforeODTSave hook |
|
546 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
547 | - $reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
548 | - |
|
549 | - // Write new file |
|
550 | - if (!empty($conf->global->MAIN_ODT_AS_PDF)) { |
|
551 | - try { |
|
552 | - $odfHandler->exportAsAttachedPDF($file); |
|
553 | - } catch (Exception $e) { |
|
554 | - $this->error=$e->getMessage(); |
|
542 | + } |
|
543 | + } |
|
544 | + |
|
545 | + // Call the beforeODTSave hook |
|
546 | + $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
547 | + $reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
548 | + |
|
549 | + // Write new file |
|
550 | + if (!empty($conf->global->MAIN_ODT_AS_PDF)) { |
|
551 | + try { |
|
552 | + $odfHandler->exportAsAttachedPDF($file); |
|
553 | + } catch (Exception $e) { |
|
554 | + $this->error=$e->getMessage(); |
|
555 | 555 | dol_syslog($e->getMessage(), LOG_INFO); |
556 | - return -1; |
|
557 | - } |
|
558 | - } |
|
559 | - else { |
|
560 | - try { |
|
561 | - $odfHandler->saveToDisk($file); |
|
562 | - } catch (Exception $e) { |
|
563 | - $this->error=$e->getMessage(); |
|
556 | + return -1; |
|
557 | + } |
|
558 | + } |
|
559 | + else { |
|
560 | + try { |
|
561 | + $odfHandler->saveToDisk($file); |
|
562 | + } catch (Exception $e) { |
|
563 | + $this->error=$e->getMessage(); |
|
564 | 564 | dol_syslog($e->getMessage(), LOG_INFO); |
565 | - return -1; |
|
566 | - } |
|
567 | - } |
|
568 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
569 | - $reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
570 | - |
|
571 | - if (! empty($conf->global->MAIN_UMASK)) |
|
572 | - @chmod($file, octdec($conf->global->MAIN_UMASK)); |
|
573 | - |
|
574 | - $odfHandler=null; // Destroy object |
|
575 | - |
|
576 | - $this->result = array('fullpath'=>$file); |
|
577 | - |
|
578 | - return 1; // Success |
|
579 | - } |
|
580 | - else |
|
581 | - { |
|
582 | - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
583 | - return -1; |
|
584 | - } |
|
585 | - } |
|
586 | - |
|
587 | - return -1; |
|
588 | - } |
|
565 | + return -1; |
|
566 | + } |
|
567 | + } |
|
568 | + $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
569 | + $reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
570 | + |
|
571 | + if (! empty($conf->global->MAIN_UMASK)) |
|
572 | + @chmod($file, octdec($conf->global->MAIN_UMASK)); |
|
573 | + |
|
574 | + $odfHandler=null; // Destroy object |
|
575 | + |
|
576 | + $this->result = array('fullpath'=>$file); |
|
577 | + |
|
578 | + return 1; // Success |
|
579 | + } |
|
580 | + else |
|
581 | + { |
|
582 | + $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
583 | + return -1; |
|
584 | + } |
|
585 | + } |
|
586 | + |
|
587 | + return -1; |
|
588 | + } |
|
589 | 589 | } |
@@ -69,37 +69,37 @@ discard block |
||
69 | 69 | global $conf, $langs, $mysoc; |
70 | 70 | |
71 | 71 | // Load translation files required by the page |
72 | - $langs->loadLangs(array("main","companies")); |
|
72 | + $langs->loadLangs(array("main", "companies")); |
|
73 | 73 | |
74 | 74 | $this->db = $db; |
75 | 75 | $this->name = "ODT templates"; |
76 | 76 | $this->description = $langs->trans("DocumentModelOdt"); |
77 | - $this->scandir = 'EXPEDITION_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan |
|
77 | + $this->scandir = 'EXPEDITION_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan |
|
78 | 78 | |
79 | 79 | // Dimension page pour format A4 |
80 | 80 | $this->type = 'odt'; |
81 | 81 | $this->page_largeur = 0; |
82 | 82 | $this->page_hauteur = 0; |
83 | - $this->format = array($this->page_largeur,$this->page_hauteur); |
|
84 | - $this->marge_gauche=0; |
|
85 | - $this->marge_droite=0; |
|
86 | - $this->marge_haute=0; |
|
87 | - $this->marge_basse=0; |
|
88 | - |
|
89 | - $this->option_logo = 1; // Affiche logo |
|
90 | - $this->option_tva = 0; // Gere option tva EXPEDITION_TVAOPTION |
|
91 | - $this->option_modereg = 0; // Affiche mode reglement |
|
92 | - $this->option_condreg = 0; // Affiche conditions reglement |
|
93 | - $this->option_codeproduitservice = 0; // Affiche code produit-service |
|
94 | - $this->option_multilang = 1; // Dispo en plusieurs langues |
|
95 | - $this->option_escompte = 0; // Affiche si il y a eu escompte |
|
96 | - $this->option_credit_note = 0; // Support credit notes |
|
97 | - $this->option_freetext = 1; // Support add of a personalised text |
|
98 | - $this->option_draft_watermark = 0; // Support add of a watermark on drafts |
|
83 | + $this->format = array($this->page_largeur, $this->page_hauteur); |
|
84 | + $this->marge_gauche = 0; |
|
85 | + $this->marge_droite = 0; |
|
86 | + $this->marge_haute = 0; |
|
87 | + $this->marge_basse = 0; |
|
88 | + |
|
89 | + $this->option_logo = 1; // Affiche logo |
|
90 | + $this->option_tva = 0; // Gere option tva EXPEDITION_TVAOPTION |
|
91 | + $this->option_modereg = 0; // Affiche mode reglement |
|
92 | + $this->option_condreg = 0; // Affiche conditions reglement |
|
93 | + $this->option_codeproduitservice = 0; // Affiche code produit-service |
|
94 | + $this->option_multilang = 1; // Dispo en plusieurs langues |
|
95 | + $this->option_escompte = 0; // Affiche si il y a eu escompte |
|
96 | + $this->option_credit_note = 0; // Support credit notes |
|
97 | + $this->option_freetext = 1; // Support add of a personalised text |
|
98 | + $this->option_draft_watermark = 0; // Support add of a watermark on drafts |
|
99 | 99 | |
100 | 100 | // Recupere emetteur |
101 | - $this->emetteur=$mysoc; |
|
102 | - if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default if not defined |
|
101 | + $this->emetteur = $mysoc; |
|
102 | + if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // By default if not defined |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | |
@@ -111,82 +111,82 @@ discard block |
||
111 | 111 | */ |
112 | 112 | function info($langs) |
113 | 113 | { |
114 | - global $conf,$langs; |
|
114 | + global $conf, $langs; |
|
115 | 115 | |
116 | 116 | // Load translation files required by the page |
117 | - $langs->loadLangs(array("errors","companies")); |
|
117 | + $langs->loadLangs(array("errors", "companies")); |
|
118 | 118 | |
119 | 119 | $form = new Form($this->db); |
120 | 120 | |
121 | 121 | $texte = $this->description.".<br>\n"; |
122 | - $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
123 | - $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
124 | - $texte.= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
125 | - $texte.= '<input type="hidden" name="param1" value="EXPEDITION_ADDON_PDF_ODT_PATH">'; |
|
126 | - $texte.= '<table class="nobordernopadding" width="100%">'; |
|
122 | + $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
123 | + $texte .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
124 | + $texte .= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
125 | + $texte .= '<input type="hidden" name="param1" value="EXPEDITION_ADDON_PDF_ODT_PATH">'; |
|
126 | + $texte .= '<table class="nobordernopadding" width="100%">'; |
|
127 | 127 | |
128 | 128 | // List of directories area |
129 | - $texte.= '<tr><td>'; |
|
130 | - $texttitle=$langs->trans("ListOfDirectories"); |
|
131 | - $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->EXPEDITION_ADDON_PDF_ODT_PATH))); |
|
132 | - $listoffiles=array(); |
|
133 | - foreach($listofdir as $key=>$tmpdir) |
|
129 | + $texte .= '<tr><td>'; |
|
130 | + $texttitle = $langs->trans("ListOfDirectories"); |
|
131 | + $listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->EXPEDITION_ADDON_PDF_ODT_PATH))); |
|
132 | + $listoffiles = array(); |
|
133 | + foreach ($listofdir as $key=>$tmpdir) |
|
134 | 134 | { |
135 | - $tmpdir=trim($tmpdir); |
|
136 | - $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); |
|
137 | - if (! $tmpdir) { |
|
135 | + $tmpdir = trim($tmpdir); |
|
136 | + $tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir); |
|
137 | + if (!$tmpdir) { |
|
138 | 138 | unset($listofdir[$key]); continue; |
139 | 139 | } |
140 | - if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); |
|
140 | + if (!is_dir($tmpdir)) $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0); |
|
141 | 141 | else |
142 | 142 | { |
143 | - $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)'); |
|
144 | - if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
143 | + $tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.(ods|odt)'); |
|
144 | + if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles); |
|
145 | 145 | } |
146 | 146 | } |
147 | - $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT"); |
|
147 | + $texthelp = $langs->trans("ListOfDirectoriesForModelGenODT"); |
|
148 | 148 | // Add list of substitution keys |
149 | - $texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>'; |
|
150 | - $texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it |
|
151 | - |
|
152 | - $texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1); |
|
153 | - $texte.= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">'; |
|
154 | - $texte.= '<textarea class="flat" cols="60" name="value1">'; |
|
155 | - $texte.=$conf->global->EXPEDITION_ADDON_PDF_ODT_PATH; |
|
156 | - $texte.= '</textarea>'; |
|
157 | - $texte.= '</div><div style="display: inline-block; vertical-align: middle;">'; |
|
158 | - $texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">'; |
|
159 | - $texte.= '<br></div></div>'; |
|
149 | + $texthelp .= '<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>'; |
|
150 | + $texthelp .= $langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it |
|
151 | + |
|
152 | + $texte .= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1); |
|
153 | + $texte .= '<div><div style="display: inline-block; min-width: 100px; vertical-align: middle;">'; |
|
154 | + $texte .= '<textarea class="flat" cols="60" name="value1">'; |
|
155 | + $texte .= $conf->global->EXPEDITION_ADDON_PDF_ODT_PATH; |
|
156 | + $texte .= '</textarea>'; |
|
157 | + $texte .= '</div><div style="display: inline-block; vertical-align: middle;">'; |
|
158 | + $texte .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">'; |
|
159 | + $texte .= '<br></div></div>'; |
|
160 | 160 | |
161 | 161 | // Scan directories |
162 | - $nbofiles=count($listoffiles); |
|
163 | - if (! empty($conf->global->EXPEDITION_ADDON_PDF_ODT_PATH)) |
|
162 | + $nbofiles = count($listoffiles); |
|
163 | + if (!empty($conf->global->EXPEDITION_ADDON_PDF_ODT_PATH)) |
|
164 | 164 | { |
165 | - $texte.=$langs->trans("NumberOfModelFilesFound").': <b>'; |
|
165 | + $texte .= $langs->trans("NumberOfModelFilesFound").': <b>'; |
|
166 | 166 | //$texte.=$nbofiles?'<a id="a_'.get_class($this).'" href="#">':''; |
167 | - $texte.=count($listoffiles); |
|
167 | + $texte .= count($listoffiles); |
|
168 | 168 | //$texte.=$nbofiles?'</a>':''; |
169 | - $texte.='</b>'; |
|
169 | + $texte .= '</b>'; |
|
170 | 170 | } |
171 | 171 | if ($nbofiles) |
172 | 172 | { |
173 | - $texte.='<div id="div_'.get_class($this).'" class="hidden">'; |
|
174 | - foreach($listoffiles as $file) |
|
173 | + $texte .= '<div id="div_'.get_class($this).'" class="hidden">'; |
|
174 | + foreach ($listoffiles as $file) |
|
175 | 175 | { |
176 | - $texte.=$file['name'].'<br>'; |
|
176 | + $texte .= $file['name'].'<br>'; |
|
177 | 177 | } |
178 | - $texte.='<div id="div_'.get_class($this).'">'; |
|
178 | + $texte .= '<div id="div_'.get_class($this).'">'; |
|
179 | 179 | } |
180 | 180 | |
181 | - $texte.= '</td>'; |
|
181 | + $texte .= '</td>'; |
|
182 | 182 | |
183 | - $texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">'; |
|
184 | - $texte.= $langs->trans("ExampleOfDirectoriesForModelGen"); |
|
185 | - $texte.= '</td>'; |
|
186 | - $texte.= '</tr>'; |
|
183 | + $texte .= '<td valign="top" rowspan="2" class="hideonsmartphone">'; |
|
184 | + $texte .= $langs->trans("ExampleOfDirectoriesForModelGen"); |
|
185 | + $texte .= '</td>'; |
|
186 | + $texte .= '</tr>'; |
|
187 | 187 | |
188 | - $texte.= '</table>'; |
|
189 | - $texte.= '</form>'; |
|
188 | + $texte .= '</table>'; |
|
189 | + $texte .= '</form>'; |
|
190 | 190 | |
191 | 191 | return $texte; |
192 | 192 | } |
@@ -203,10 +203,10 @@ discard block |
||
203 | 203 | * @param int $hideref Do not show ref |
204 | 204 | * @return int 1 if OK, <=0 if KO |
205 | 205 | */ |
206 | - function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0) |
|
206 | + function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0) |
|
207 | 207 | { |
208 | 208 | // phpcs:enable |
209 | - global $user,$langs,$conf,$mysoc,$hookmanager; |
|
209 | + global $user, $langs, $conf, $mysoc, $hookmanager; |
|
210 | 210 | |
211 | 211 | if (empty($srctemplatepath)) |
212 | 212 | { |
@@ -215,17 +215,17 @@ discard block |
||
215 | 215 | } |
216 | 216 | |
217 | 217 | // Add odtgeneration hook |
218 | - if (! is_object($hookmanager)) |
|
218 | + if (!is_object($hookmanager)) |
|
219 | 219 | { |
220 | 220 | include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; |
221 | - $hookmanager=new HookManager($this->db); |
|
221 | + $hookmanager = new HookManager($this->db); |
|
222 | 222 | } |
223 | 223 | $hookmanager->initHooks(array('odtgeneration')); |
224 | 224 | global $action; |
225 | 225 | |
226 | - if (! is_object($outputlangs)) $outputlangs=$langs; |
|
227 | - $sav_charset_output=$outputlangs->charset_output; |
|
228 | - $outputlangs->charset_output='UTF-8'; |
|
226 | + if (!is_object($outputlangs)) $outputlangs = $langs; |
|
227 | + $sav_charset_output = $outputlangs->charset_output; |
|
228 | + $outputlangs->charset_output = 'UTF-8'; |
|
229 | 229 | |
230 | 230 | // Load traductions files requiredby by page |
231 | 231 | $outputlangs->loadLangs(array("main", "dict", "companies", "bills")); |
@@ -233,28 +233,28 @@ discard block |
||
233 | 233 | if ($conf->expedition->dir_output."/sending") |
234 | 234 | { |
235 | 235 | // If $object is id instead of object |
236 | - if (! is_object($object)) |
|
236 | + if (!is_object($object)) |
|
237 | 237 | { |
238 | 238 | $id = $object; |
239 | 239 | $object = new Expedition($this->db); |
240 | - $result=$object->fetch($id); |
|
240 | + $result = $object->fetch($id); |
|
241 | 241 | if ($result < 0) |
242 | 242 | { |
243 | - dol_print_error($this->db,$object->error); |
|
243 | + dol_print_error($this->db, $object->error); |
|
244 | 244 | return -1; |
245 | 245 | } |
246 | 246 | } |
247 | 247 | |
248 | 248 | $dir = $conf->expedition->dir_output."/sending"; |
249 | 249 | $objectref = dol_sanitizeFileName($object->ref); |
250 | - if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref; |
|
251 | - $file = $dir . "/" . $objectref . ".odt"; |
|
250 | + if (!preg_match('/specimen/i', $objectref)) $dir .= "/".$objectref; |
|
251 | + $file = $dir."/".$objectref.".odt"; |
|
252 | 252 | |
253 | - if (! file_exists($dir)) |
|
253 | + if (!file_exists($dir)) |
|
254 | 254 | { |
255 | 255 | if (dol_mkdir($dir) < 0) |
256 | 256 | { |
257 | - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
257 | + $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); |
|
258 | 258 | return -1; |
259 | 259 | } |
260 | 260 | } |
@@ -262,25 +262,25 @@ discard block |
||
262 | 262 | if (file_exists($dir)) |
263 | 263 | { |
264 | 264 | //print "srctemplatepath=".$srctemplatepath; // Src filename |
265 | - $newfile=basename($srctemplatepath); |
|
266 | - $newfiletmp=preg_replace('/\.od(t|s)/i','',$newfile); |
|
267 | - $newfiletmp=preg_replace('/template_/i','',$newfiletmp); |
|
268 | - $newfiletmp=preg_replace('/modele_/i','',$newfiletmp); |
|
269 | - $newfiletmp=$objectref.'_'.$newfiletmp; |
|
265 | + $newfile = basename($srctemplatepath); |
|
266 | + $newfiletmp = preg_replace('/\.od(t|s)/i', '', $newfile); |
|
267 | + $newfiletmp = preg_replace('/template_/i', '', $newfiletmp); |
|
268 | + $newfiletmp = preg_replace('/modele_/i', '', $newfiletmp); |
|
269 | + $newfiletmp = $objectref.'_'.$newfiletmp; |
|
270 | 270 | //$file=$dir.'/'.$newfiletmp.'.'.dol_print_date(dol_now(),'%Y%m%d%H%M%S').'.odt'; |
271 | 271 | // Get extension (ods or odt) |
272 | - $newfileformat=substr($newfile, strrpos($newfile, '.')+1); |
|
273 | - if ( ! empty($conf->global->MAIN_DOC_USE_TIMING)) |
|
272 | + $newfileformat = substr($newfile, strrpos($newfile, '.') + 1); |
|
273 | + if (!empty($conf->global->MAIN_DOC_USE_TIMING)) |
|
274 | 274 | { |
275 | - $format=$conf->global->MAIN_DOC_USE_TIMING; |
|
276 | - if ($format == '1') $format='%Y%m%d%H%M%S'; |
|
277 | - $filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat; |
|
275 | + $format = $conf->global->MAIN_DOC_USE_TIMING; |
|
276 | + if ($format == '1') $format = '%Y%m%d%H%M%S'; |
|
277 | + $filename = $newfiletmp.'-'.dol_print_date(dol_now(), $format).'.'.$newfileformat; |
|
278 | 278 | } |
279 | 279 | else |
280 | 280 | { |
281 | - $filename=$newfiletmp.'.'.$newfileformat; |
|
281 | + $filename = $newfiletmp.'.'.$newfileformat; |
|
282 | 282 | } |
283 | - $file=$dir.'/'.$filename; |
|
283 | + $file = $dir.'/'.$filename; |
|
284 | 284 | //print "newdir=".$dir; |
285 | 285 | //print "newfile=".$newfile; |
286 | 286 | //print "file=".$file; |
@@ -290,19 +290,19 @@ discard block |
||
290 | 290 | |
291 | 291 | |
292 | 292 | // If SHIPMENT contact defined on invoice, we use it |
293 | - $usecontact=false; |
|
294 | - $arrayidcontact=$object->getIdContact('external','SHIPPING'); |
|
293 | + $usecontact = false; |
|
294 | + $arrayidcontact = $object->getIdContact('external', 'SHIPPING'); |
|
295 | 295 | if (count($arrayidcontact) > 0) |
296 | 296 | { |
297 | - $usecontact=true; |
|
298 | - $result=$object->fetch_contact($arrayidcontact[0]); |
|
297 | + $usecontact = true; |
|
298 | + $result = $object->fetch_contact($arrayidcontact[0]); |
|
299 | 299 | } |
300 | 300 | |
301 | 301 | // Recipient name |
302 | 302 | $contactobject = null; |
303 | - if (! empty($usecontact)) { |
|
303 | + if (!empty($usecontact)) { |
|
304 | 304 | // On peut utiliser le nom de la societe du contact |
305 | - if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) |
|
305 | + if (!empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) |
|
306 | 306 | $socobject = $object->contact; |
307 | 307 | else { |
308 | 308 | $socobject = $object->thirdparty; |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | } |
315 | 315 | |
316 | 316 | // Make substitution |
317 | - $substitutionarray=array( |
|
317 | + $substitutionarray = array( |
|
318 | 318 | '__FROM_NAME__' => $this->emetteur->name, |
319 | 319 | '__FROM_EMAIL__' => $this->emetteur->email, |
320 | 320 | '__TOTAL_TTC__' => $object->total_ttc, |
@@ -323,15 +323,15 @@ discard block |
||
323 | 323 | ); |
324 | 324 | complete_substitutions_array($substitutionarray, $langs, $object); |
325 | 325 | // Call the ODTSubstitution hook |
326 | - $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$substitutionarray); |
|
327 | - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
326 | + $parameters = array('file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$substitutionarray); |
|
327 | + $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
328 | 328 | |
329 | 329 | // Line of free text |
330 | - $newfreetext=''; |
|
331 | - $paramfreetext='EXPEDITION_FREE_TEXT'; |
|
332 | - if (! empty($conf->global->$paramfreetext)) |
|
330 | + $newfreetext = ''; |
|
331 | + $paramfreetext = 'EXPEDITION_FREE_TEXT'; |
|
332 | + if (!empty($conf->global->$paramfreetext)) |
|
333 | 333 | { |
334 | - $newfreetext=make_substitutions($conf->global->$paramfreetext,$substitutionarray); |
|
334 | + $newfreetext = make_substitutions($conf->global->$paramfreetext, $substitutionarray); |
|
335 | 335 | } |
336 | 336 | |
337 | 337 | // Open and load template |
@@ -341,15 +341,15 @@ discard block |
||
341 | 341 | $srctemplatepath, |
342 | 342 | array( |
343 | 343 | 'PATH_TO_TMP' => $conf->expedition->dir_temp, |
344 | - 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. |
|
344 | + 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. |
|
345 | 345 | 'DELIMITER_LEFT' => '{', |
346 | 346 | 'DELIMITER_RIGHT' => '}' |
347 | 347 | ) |
348 | 348 | ); |
349 | 349 | } |
350 | - catch(Exception $e) |
|
350 | + catch (Exception $e) |
|
351 | 351 | { |
352 | - $this->error=$e->getMessage(); |
|
352 | + $this->error = $e->getMessage(); |
|
353 | 353 | dol_syslog($e->getMessage(), LOG_INFO); |
354 | 354 | return -1; |
355 | 355 | } |
@@ -364,18 +364,18 @@ discard block |
||
364 | 364 | try { |
365 | 365 | $odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8'); |
366 | 366 | } |
367 | - catch(OdfException $e) |
|
367 | + catch (OdfException $e) |
|
368 | 368 | { |
369 | 369 | dol_syslog($e->getMessage(), LOG_INFO); |
370 | 370 | } |
371 | 371 | |
372 | 372 | // Make substitutions into odt of user info |
373 | - $tmparray=$this->get_substitutionarray_user($user,$outputlangs); |
|
373 | + $tmparray = $this->get_substitutionarray_user($user, $outputlangs); |
|
374 | 374 | //var_dump($tmparray); exit; |
375 | - foreach($tmparray as $key=>$value) |
|
375 | + foreach ($tmparray as $key=>$value) |
|
376 | 376 | { |
377 | 377 | try { |
378 | - if (preg_match('/logo$/',$key)) // Image |
|
378 | + if (preg_match('/logo$/', $key)) // Image |
|
379 | 379 | { |
380 | 380 | //var_dump($value);exit; |
381 | 381 | if (file_exists($value)) $odfHandler->setImage($key, $value); |
@@ -392,12 +392,12 @@ discard block |
||
392 | 392 | } |
393 | 393 | } |
394 | 394 | // Make substitutions into odt of mysoc |
395 | - $tmparray=$this->get_substitutionarray_mysoc($mysoc,$outputlangs); |
|
395 | + $tmparray = $this->get_substitutionarray_mysoc($mysoc, $outputlangs); |
|
396 | 396 | //var_dump($tmparray); exit; |
397 | - foreach($tmparray as $key=>$value) |
|
397 | + foreach ($tmparray as $key=>$value) |
|
398 | 398 | { |
399 | 399 | try { |
400 | - if (preg_match('/logo$/',$key)) // Image |
|
400 | + if (preg_match('/logo$/', $key)) // Image |
|
401 | 401 | { |
402 | 402 | //var_dump($value);exit; |
403 | 403 | if (file_exists($value)) $odfHandler->setImage($key, $value); |
@@ -414,11 +414,11 @@ discard block |
||
414 | 414 | } |
415 | 415 | } |
416 | 416 | // Make substitutions into odt of thirdparty |
417 | - $tmparray=$this->get_substitutionarray_thirdparty($socobject,$outputlangs); |
|
418 | - foreach($tmparray as $key=>$value) |
|
417 | + $tmparray = $this->get_substitutionarray_thirdparty($socobject, $outputlangs); |
|
418 | + foreach ($tmparray as $key=>$value) |
|
419 | 419 | { |
420 | 420 | try { |
421 | - if (preg_match('/logo$/',$key)) // Image |
|
421 | + if (preg_match('/logo$/', $key)) // Image |
|
422 | 422 | { |
423 | 423 | if (file_exists($value)) $odfHandler->setImage($key, $value); |
424 | 424 | else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
@@ -435,11 +435,11 @@ discard block |
||
435 | 435 | } |
436 | 436 | |
437 | 437 | if ($usecontact && is_object($contactobject)) { |
438 | - $tmparray=$this->get_substitutionarray_contact($contactobject,$outputlangs,'contact'); |
|
439 | - foreach($tmparray as $key=>$value) |
|
438 | + $tmparray = $this->get_substitutionarray_contact($contactobject, $outputlangs, 'contact'); |
|
439 | + foreach ($tmparray as $key=>$value) |
|
440 | 440 | { |
441 | 441 | try { |
442 | - if (preg_match('/logo$/',$key)) // Image |
|
442 | + if (preg_match('/logo$/', $key)) // Image |
|
443 | 443 | { |
444 | 444 | if (file_exists($value)) $odfHandler->setImage($key, $value); |
445 | 445 | else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
@@ -449,7 +449,7 @@ discard block |
||
449 | 449 | $odfHandler->setVars($key, $value, true, 'UTF-8'); |
450 | 450 | } |
451 | 451 | } |
452 | - catch(OdfException $e) |
|
452 | + catch (OdfException $e) |
|
453 | 453 | { |
454 | 454 | dol_syslog($e->getMessage(), LOG_INFO); |
455 | 455 | } |
@@ -457,15 +457,15 @@ discard block |
||
457 | 457 | } |
458 | 458 | |
459 | 459 | // Replace tags of object + external modules |
460 | - $tmparray=$this->get_substitutionarray_shipment($object,$outputlangs); |
|
460 | + $tmparray = $this->get_substitutionarray_shipment($object, $outputlangs); |
|
461 | 461 | complete_substitutions_array($tmparray, $outputlangs, $object); |
462 | 462 | // Call the ODTSubstitution hook |
463 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
464 | - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
465 | - foreach($tmparray as $key=>$value) |
|
463 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); |
|
464 | + $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
465 | + foreach ($tmparray as $key=>$value) |
|
466 | 466 | { |
467 | 467 | try { |
468 | - if (preg_match('/logo$/',$key)) // Image |
|
468 | + if (preg_match('/logo$/', $key)) // Image |
|
469 | 469 | { |
470 | 470 | if (file_exists($value)) $odfHandler->setImage($key, $value); |
471 | 471 | else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
@@ -475,7 +475,7 @@ discard block |
||
475 | 475 | $odfHandler->setVars($key, $value, true, 'UTF-8'); |
476 | 476 | } |
477 | 477 | } |
478 | - catch(OdfException $e) |
|
478 | + catch (OdfException $e) |
|
479 | 479 | { |
480 | 480 | dol_syslog($e->getMessage(), LOG_INFO); |
481 | 481 | } |
@@ -487,7 +487,7 @@ discard block |
||
487 | 487 | try { |
488 | 488 | $listlines = $odfHandler->setSegment('lines'); |
489 | 489 | } |
490 | - catch(OdfException $e) |
|
490 | + catch (OdfException $e) |
|
491 | 491 | { |
492 | 492 | // We may arrive here if tags for lines not present into template |
493 | 493 | $foundtagforlines = 0; |
@@ -497,22 +497,22 @@ discard block |
||
497 | 497 | { |
498 | 498 | foreach ($object->lines as $line) |
499 | 499 | { |
500 | - $tmparray=$this->get_substitutionarray_shipment_lines($line,$outputlangs); |
|
500 | + $tmparray = $this->get_substitutionarray_shipment_lines($line, $outputlangs); |
|
501 | 501 | complete_substitutions_array($tmparray, $outputlangs, $object, $line, "completesubstitutionarray_lines"); |
502 | 502 | // Call the ODTSubstitutionLine hook |
503 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray,'line'=>$line); |
|
504 | - $reshook=$hookmanager->executeHooks('ODTSubstitutionLine',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
505 | - foreach($tmparray as $key => $val) |
|
503 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray, 'line'=>$line); |
|
504 | + $reshook = $hookmanager->executeHooks('ODTSubstitutionLine', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
505 | + foreach ($tmparray as $key => $val) |
|
506 | 506 | { |
507 | 507 | try |
508 | 508 | { |
509 | 509 | $listlines->setVars($key, $val, true, 'UTF-8'); |
510 | 510 | } |
511 | - catch(OdfException $e) |
|
511 | + catch (OdfException $e) |
|
512 | 512 | { |
513 | 513 | dol_syslog($e->getMessage(), LOG_INFO); |
514 | 514 | } |
515 | - catch(SegmentException $e) |
|
515 | + catch (SegmentException $e) |
|
516 | 516 | { |
517 | 517 | dol_syslog($e->getMessage(), LOG_INFO); |
518 | 518 | } |
@@ -524,14 +524,14 @@ discard block |
||
524 | 524 | } |
525 | 525 | catch (OdfException $e) |
526 | 526 | { |
527 | - $this->error=$e->getMessage(); |
|
527 | + $this->error = $e->getMessage(); |
|
528 | 528 | dol_syslog($this->error, LOG_WARNING); |
529 | 529 | return -1; |
530 | 530 | } |
531 | 531 | |
532 | 532 | // Replace labels translated |
533 | - $tmparray=$outputlangs->get_translations_for_substitutions(); |
|
534 | - foreach($tmparray as $key=>$value) |
|
533 | + $tmparray = $outputlangs->get_translations_for_substitutions(); |
|
534 | + foreach ($tmparray as $key=>$value) |
|
535 | 535 | { |
536 | 536 | try { |
537 | 537 | $odfHandler->setVars($key, $value, true, 'UTF-8'); |
@@ -543,15 +543,15 @@ discard block |
||
543 | 543 | } |
544 | 544 | |
545 | 545 | // Call the beforeODTSave hook |
546 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
547 | - $reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
546 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); |
|
547 | + $reshook = $hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
548 | 548 | |
549 | 549 | // Write new file |
550 | 550 | if (!empty($conf->global->MAIN_ODT_AS_PDF)) { |
551 | 551 | try { |
552 | 552 | $odfHandler->exportAsAttachedPDF($file); |
553 | 553 | } catch (Exception $e) { |
554 | - $this->error=$e->getMessage(); |
|
554 | + $this->error = $e->getMessage(); |
|
555 | 555 | dol_syslog($e->getMessage(), LOG_INFO); |
556 | 556 | return -1; |
557 | 557 | } |
@@ -560,26 +560,26 @@ discard block |
||
560 | 560 | try { |
561 | 561 | $odfHandler->saveToDisk($file); |
562 | 562 | } catch (Exception $e) { |
563 | - $this->error=$e->getMessage(); |
|
563 | + $this->error = $e->getMessage(); |
|
564 | 564 | dol_syslog($e->getMessage(), LOG_INFO); |
565 | 565 | return -1; |
566 | 566 | } |
567 | 567 | } |
568 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
569 | - $reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
568 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); |
|
569 | + $reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
570 | 570 | |
571 | - if (! empty($conf->global->MAIN_UMASK)) |
|
571 | + if (!empty($conf->global->MAIN_UMASK)) |
|
572 | 572 | @chmod($file, octdec($conf->global->MAIN_UMASK)); |
573 | 573 | |
574 | - $odfHandler=null; // Destroy object |
|
574 | + $odfHandler = null; // Destroy object |
|
575 | 575 | |
576 | 576 | $this->result = array('fullpath'=>$file); |
577 | 577 | |
578 | - return 1; // Success |
|
578 | + return 1; // Success |
|
579 | 579 | } |
580 | 580 | else |
581 | 581 | { |
582 | - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
582 | + $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); |
|
583 | 583 | return -1; |
584 | 584 | } |
585 | 585 | } |
@@ -99,7 +99,10 @@ discard block |
||
99 | 99 | |
100 | 100 | // Recupere emetteur |
101 | 101 | $this->emetteur=$mysoc; |
102 | - if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default if not defined |
|
102 | + if (! $this->emetteur->country_code) { |
|
103 | + $this->emetteur->country_code=substr($langs->defaultlang,-2); |
|
104 | + } |
|
105 | + // By default if not defined |
|
103 | 106 | } |
104 | 107 | |
105 | 108 | |
@@ -137,11 +140,14 @@ discard block |
||
137 | 140 | if (! $tmpdir) { |
138 | 141 | unset($listofdir[$key]); continue; |
139 | 142 | } |
140 | - if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); |
|
141 | - else |
|
143 | + if (! is_dir($tmpdir)) { |
|
144 | + $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); |
|
145 | + } else |
|
142 | 146 | { |
143 | 147 | $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.(ods|odt)'); |
144 | - if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
148 | + if (count($tmpfiles)) { |
|
149 | + $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
150 | + } |
|
145 | 151 | } |
146 | 152 | } |
147 | 153 | $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT"); |
@@ -223,7 +229,9 @@ discard block |
||
223 | 229 | $hookmanager->initHooks(array('odtgeneration')); |
224 | 230 | global $action; |
225 | 231 | |
226 | - if (! is_object($outputlangs)) $outputlangs=$langs; |
|
232 | + if (! is_object($outputlangs)) { |
|
233 | + $outputlangs=$langs; |
|
234 | + } |
|
227 | 235 | $sav_charset_output=$outputlangs->charset_output; |
228 | 236 | $outputlangs->charset_output='UTF-8'; |
229 | 237 | |
@@ -247,7 +255,9 @@ discard block |
||
247 | 255 | |
248 | 256 | $dir = $conf->expedition->dir_output."/sending"; |
249 | 257 | $objectref = dol_sanitizeFileName($object->ref); |
250 | - if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref; |
|
258 | + if (! preg_match('/specimen/i',$objectref)) { |
|
259 | + $dir.= "/" . $objectref; |
|
260 | + } |
|
251 | 261 | $file = $dir . "/" . $objectref . ".odt"; |
252 | 262 | |
253 | 263 | if (! file_exists($dir)) |
@@ -273,10 +283,11 @@ discard block |
||
273 | 283 | if ( ! empty($conf->global->MAIN_DOC_USE_TIMING)) |
274 | 284 | { |
275 | 285 | $format=$conf->global->MAIN_DOC_USE_TIMING; |
276 | - if ($format == '1') $format='%Y%m%d%H%M%S'; |
|
286 | + if ($format == '1') { |
|
287 | + $format='%Y%m%d%H%M%S'; |
|
288 | + } |
|
277 | 289 | $filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat; |
278 | - } |
|
279 | - else |
|
290 | + } else |
|
280 | 291 | { |
281 | 292 | $filename=$newfiletmp.'.'.$newfileformat; |
282 | 293 | } |
@@ -302,9 +313,9 @@ discard block |
||
302 | 313 | $contactobject = null; |
303 | 314 | if (! empty($usecontact)) { |
304 | 315 | // On peut utiliser le nom de la societe du contact |
305 | - if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) |
|
306 | - $socobject = $object->contact; |
|
307 | - else { |
|
316 | + if (! empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) { |
|
317 | + $socobject = $object->contact; |
|
318 | + } else { |
|
308 | 319 | $socobject = $object->thirdparty; |
309 | 320 | // if we have a SHIIPPING contact and we dont use it as recipient we store the contact object for later use |
310 | 321 | $contactobject = $object->contact; |
@@ -346,8 +357,7 @@ discard block |
||
346 | 357 | 'DELIMITER_RIGHT' => '}' |
347 | 358 | ) |
348 | 359 | ); |
349 | - } |
|
350 | - catch(Exception $e) |
|
360 | + } catch(Exception $e) |
|
351 | 361 | { |
352 | 362 | $this->error=$e->getMessage(); |
353 | 363 | dol_syslog($e->getMessage(), LOG_INFO); |
@@ -363,8 +373,7 @@ discard block |
||
363 | 373 | // Make substitutions into odt of freetext |
364 | 374 | try { |
365 | 375 | $odfHandler->setVars('free_text', $newfreetext, true, 'UTF-8'); |
366 | - } |
|
367 | - catch(OdfException $e) |
|
376 | + } catch(OdfException $e) |
|
368 | 377 | { |
369 | 378 | dol_syslog($e->getMessage(), LOG_INFO); |
370 | 379 | } |
@@ -375,18 +384,19 @@ discard block |
||
375 | 384 | foreach($tmparray as $key=>$value) |
376 | 385 | { |
377 | 386 | try { |
378 | - if (preg_match('/logo$/',$key)) // Image |
|
387 | + if (preg_match('/logo$/',$key)) { |
|
388 | + // Image |
|
379 | 389 | { |
380 | 390 | //var_dump($value);exit; |
381 | 391 | if (file_exists($value)) $odfHandler->setImage($key, $value); |
382 | - else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
|
383 | - } |
|
384 | - else // Text |
|
392 | + } else { |
|
393 | + $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
|
394 | + } |
|
395 | + } else // Text |
|
385 | 396 | { |
386 | 397 | $odfHandler->setVars($key, $value, true, 'UTF-8'); |
387 | 398 | } |
388 | - } |
|
389 | - catch (OdfException $e) |
|
399 | + } catch (OdfException $e) |
|
390 | 400 | { |
391 | 401 | dol_syslog($e->getMessage(), LOG_INFO); |
392 | 402 | } |
@@ -397,18 +407,19 @@ discard block |
||
397 | 407 | foreach($tmparray as $key=>$value) |
398 | 408 | { |
399 | 409 | try { |
400 | - if (preg_match('/logo$/',$key)) // Image |
|
410 | + if (preg_match('/logo$/',$key)) { |
|
411 | + // Image |
|
401 | 412 | { |
402 | 413 | //var_dump($value);exit; |
403 | 414 | if (file_exists($value)) $odfHandler->setImage($key, $value); |
404 | - else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
|
405 | - } |
|
406 | - else // Text |
|
415 | + } else { |
|
416 | + $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
|
417 | + } |
|
418 | + } else // Text |
|
407 | 419 | { |
408 | 420 | $odfHandler->setVars($key, $value, true, 'UTF-8'); |
409 | 421 | } |
410 | - } |
|
411 | - catch (OdfException $e) |
|
422 | + } catch (OdfException $e) |
|
412 | 423 | { |
413 | 424 | dol_syslog($e->getMessage(), LOG_INFO); |
414 | 425 | } |
@@ -418,17 +429,18 @@ discard block |
||
418 | 429 | foreach($tmparray as $key=>$value) |
419 | 430 | { |
420 | 431 | try { |
421 | - if (preg_match('/logo$/',$key)) // Image |
|
432 | + if (preg_match('/logo$/',$key)) { |
|
433 | + // Image |
|
422 | 434 | { |
423 | 435 | if (file_exists($value)) $odfHandler->setImage($key, $value); |
424 | - else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
|
425 | - } |
|
426 | - else // Text |
|
436 | + } else { |
|
437 | + $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
|
438 | + } |
|
439 | + } else // Text |
|
427 | 440 | { |
428 | 441 | $odfHandler->setVars($key, $value, true, 'UTF-8'); |
429 | 442 | } |
430 | - } |
|
431 | - catch (OdfException $e) |
|
443 | + } catch (OdfException $e) |
|
432 | 444 | { |
433 | 445 | dol_syslog($e->getMessage(), LOG_INFO); |
434 | 446 | } |
@@ -439,17 +451,18 @@ discard block |
||
439 | 451 | foreach($tmparray as $key=>$value) |
440 | 452 | { |
441 | 453 | try { |
442 | - if (preg_match('/logo$/',$key)) // Image |
|
454 | + if (preg_match('/logo$/',$key)) { |
|
455 | + // Image |
|
443 | 456 | { |
444 | 457 | if (file_exists($value)) $odfHandler->setImage($key, $value); |
445 | - else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
|
446 | - } |
|
447 | - else // Text |
|
458 | + } else { |
|
459 | + $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
|
460 | + } |
|
461 | + } else // Text |
|
448 | 462 | { |
449 | 463 | $odfHandler->setVars($key, $value, true, 'UTF-8'); |
450 | 464 | } |
451 | - } |
|
452 | - catch(OdfException $e) |
|
465 | + } catch(OdfException $e) |
|
453 | 466 | { |
454 | 467 | dol_syslog($e->getMessage(), LOG_INFO); |
455 | 468 | } |
@@ -465,17 +478,18 @@ discard block |
||
465 | 478 | foreach($tmparray as $key=>$value) |
466 | 479 | { |
467 | 480 | try { |
468 | - if (preg_match('/logo$/',$key)) // Image |
|
481 | + if (preg_match('/logo$/',$key)) { |
|
482 | + // Image |
|
469 | 483 | { |
470 | 484 | if (file_exists($value)) $odfHandler->setImage($key, $value); |
471 | - else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
|
472 | - } |
|
473 | - else // Text |
|
485 | + } else { |
|
486 | + $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
|
487 | + } |
|
488 | + } else // Text |
|
474 | 489 | { |
475 | 490 | $odfHandler->setVars($key, $value, true, 'UTF-8'); |
476 | 491 | } |
477 | - } |
|
478 | - catch(OdfException $e) |
|
492 | + } catch(OdfException $e) |
|
479 | 493 | { |
480 | 494 | dol_syslog($e->getMessage(), LOG_INFO); |
481 | 495 | } |
@@ -486,8 +500,7 @@ discard block |
||
486 | 500 | $foundtagforlines = 1; |
487 | 501 | try { |
488 | 502 | $listlines = $odfHandler->setSegment('lines'); |
489 | - } |
|
490 | - catch(OdfException $e) |
|
503 | + } catch(OdfException $e) |
|
491 | 504 | { |
492 | 505 | // We may arrive here if tags for lines not present into template |
493 | 506 | $foundtagforlines = 0; |
@@ -507,12 +520,10 @@ discard block |
||
507 | 520 | try |
508 | 521 | { |
509 | 522 | $listlines->setVars($key, $val, true, 'UTF-8'); |
510 | - } |
|
511 | - catch(OdfException $e) |
|
523 | + } catch(OdfException $e) |
|
512 | 524 | { |
513 | 525 | dol_syslog($e->getMessage(), LOG_INFO); |
514 | - } |
|
515 | - catch(SegmentException $e) |
|
526 | + } catch(SegmentException $e) |
|
516 | 527 | { |
517 | 528 | dol_syslog($e->getMessage(), LOG_INFO); |
518 | 529 | } |
@@ -521,8 +532,7 @@ discard block |
||
521 | 532 | } |
522 | 533 | $odfHandler->mergeSegment($listlines); |
523 | 534 | } |
524 | - } |
|
525 | - catch (OdfException $e) |
|
535 | + } catch (OdfException $e) |
|
526 | 536 | { |
527 | 537 | $this->error=$e->getMessage(); |
528 | 538 | dol_syslog($this->error, LOG_WARNING); |
@@ -535,8 +545,7 @@ discard block |
||
535 | 545 | { |
536 | 546 | try { |
537 | 547 | $odfHandler->setVars($key, $value, true, 'UTF-8'); |
538 | - } |
|
539 | - catch (OdfException $e) |
|
548 | + } catch (OdfException $e) |
|
540 | 549 | { |
541 | 550 | dol_syslog($e->getMessage(), LOG_INFO); |
542 | 551 | } |
@@ -555,8 +564,7 @@ discard block |
||
555 | 564 | dol_syslog($e->getMessage(), LOG_INFO); |
556 | 565 | return -1; |
557 | 566 | } |
558 | - } |
|
559 | - else { |
|
567 | + } else { |
|
560 | 568 | try { |
561 | 569 | $odfHandler->saveToDisk($file); |
562 | 570 | } catch (Exception $e) { |
@@ -568,16 +576,16 @@ discard block |
||
568 | 576 | $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
569 | 577 | $reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
570 | 578 | |
571 | - if (! empty($conf->global->MAIN_UMASK)) |
|
572 | - @chmod($file, octdec($conf->global->MAIN_UMASK)); |
|
579 | + if (! empty($conf->global->MAIN_UMASK)) { |
|
580 | + @chmod($file, octdec($conf->global->MAIN_UMASK)); |
|
581 | + } |
|
573 | 582 | |
574 | 583 | $odfHandler=null; // Destroy object |
575 | 584 | |
576 | 585 | $this->result = array('fullpath'=>$file); |
577 | 586 | |
578 | 587 | return 1; // Success |
579 | - } |
|
580 | - else |
|
588 | + } else |
|
581 | 589 | { |
582 | 590 | $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
583 | 591 | return -1; |
@@ -29,125 +29,125 @@ |
||
29 | 29 | */ |
30 | 30 | class mod_expedition_ribera extends ModelNumRefExpedition |
31 | 31 | { |
32 | - /** |
|
32 | + /** |
|
33 | 33 | * Dolibarr version of the loaded document |
34 | 34 | * @public string |
35 | 35 | */ |
36 | - public $version = 'dolibarr'; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var string Error message |
|
40 | - */ |
|
41 | - public $error = ''; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var string Nom du modele |
|
45 | - * @deprecated |
|
46 | - * @see name |
|
47 | - */ |
|
48 | - public $nom='Ribera'; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var string model name |
|
52 | - */ |
|
53 | - public $name='Ribera'; |
|
54 | - |
|
55 | - /** |
|
56 | - * Return default description of numbering model |
|
57 | - * |
|
58 | - * @return string text description |
|
59 | - */ |
|
60 | - function info() |
|
36 | + public $version = 'dolibarr'; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var string Error message |
|
40 | + */ |
|
41 | + public $error = ''; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var string Nom du modele |
|
45 | + * @deprecated |
|
46 | + * @see name |
|
47 | + */ |
|
48 | + public $nom='Ribera'; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var string model name |
|
52 | + */ |
|
53 | + public $name='Ribera'; |
|
54 | + |
|
55 | + /** |
|
56 | + * Return default description of numbering model |
|
57 | + * |
|
58 | + * @return string text description |
|
59 | + */ |
|
60 | + function info() |
|
61 | 61 | { |
62 | - global $conf, $langs; |
|
62 | + global $conf, $langs; |
|
63 | 63 | |
64 | - $langs->load("bills"); |
|
64 | + $langs->load("bills"); |
|
65 | 65 | |
66 | - $form = new Form($this->db); |
|
66 | + $form = new Form($this->db); |
|
67 | 67 | |
68 | - $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n"; |
|
69 | - $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
70 | - $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
71 | - $texte.= '<input type="hidden" name="action" value="updateMask">'; |
|
72 | - $texte.= '<input type="hidden" name="maskconstexpedition" value="EXPEDITION_RIBERA_MASK">'; |
|
73 | - $texte.= '<table class="nobordernopadding" width="100%">'; |
|
68 | + $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n"; |
|
69 | + $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
70 | + $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
71 | + $texte.= '<input type="hidden" name="action" value="updateMask">'; |
|
72 | + $texte.= '<input type="hidden" name="maskconstexpedition" value="EXPEDITION_RIBERA_MASK">'; |
|
73 | + $texte.= '<table class="nobordernopadding" width="100%">'; |
|
74 | 74 | |
75 | - $tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("Shipment"),$langs->transnoentities("Shipment")); |
|
76 | - $tooltip.=$langs->trans("GenericMaskCodes2"); |
|
77 | - $tooltip.=$langs->trans("GenericMaskCodes3"); |
|
78 | - $tooltip.=$langs->trans("GenericMaskCodes4a",$langs->transnoentities("Shipment"),$langs->transnoentities("Shipment")); |
|
79 | - $tooltip.=$langs->trans("GenericMaskCodes5"); |
|
75 | + $tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("Shipment"),$langs->transnoentities("Shipment")); |
|
76 | + $tooltip.=$langs->trans("GenericMaskCodes2"); |
|
77 | + $tooltip.=$langs->trans("GenericMaskCodes3"); |
|
78 | + $tooltip.=$langs->trans("GenericMaskCodes4a",$langs->transnoentities("Shipment"),$langs->transnoentities("Shipment")); |
|
79 | + $tooltip.=$langs->trans("GenericMaskCodes5"); |
|
80 | 80 | |
81 | - $texte.= '<tr><td>'.$langs->trans("Mask").':</td>'; |
|
82 | - $texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskexpedition" value="'.$conf->global->EXPEDITION_RIBERA_MASK.'">',$tooltip,1,1).'</td>'; |
|
83 | - $texte.= '<td align="left" rowspan="2"> <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>'; |
|
84 | - $texte.= '</tr>'; |
|
85 | - $texte.= '</table>'; |
|
86 | - $texte.= '</form>'; |
|
81 | + $texte.= '<tr><td>'.$langs->trans("Mask").':</td>'; |
|
82 | + $texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskexpedition" value="'.$conf->global->EXPEDITION_RIBERA_MASK.'">',$tooltip,1,1).'</td>'; |
|
83 | + $texte.= '<td align="left" rowspan="2"> <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>'; |
|
84 | + $texte.= '</tr>'; |
|
85 | + $texte.= '</table>'; |
|
86 | + $texte.= '</form>'; |
|
87 | 87 | |
88 | - return $texte; |
|
88 | + return $texte; |
|
89 | 89 | } |
90 | 90 | |
91 | - /** |
|
92 | - * Return numbering example |
|
93 | - * |
|
94 | - * @return string Example |
|
95 | - */ |
|
91 | + /** |
|
92 | + * Return numbering example |
|
93 | + * |
|
94 | + * @return string Example |
|
95 | + */ |
|
96 | 96 | function getExample() |
97 | 97 | { |
98 | - global $conf,$langs,$mysoc; |
|
99 | - |
|
100 | - $old_code_client=$mysoc->code_client; |
|
101 | - $old_code_type=$mysoc->typent_code; |
|
102 | - $mysoc->code_client='CCCCCCCCCC'; |
|
103 | - $mysoc->typent_code='TTTTTTTTTT'; |
|
104 | - $numExample = $this->getNextValue($mysoc,''); |
|
105 | - $mysoc->code_client=$old_code_client; |
|
106 | - $mysoc->typent_code=$old_code_type; |
|
107 | - |
|
108 | - if (! $numExample) |
|
109 | - { |
|
110 | - $numExample = $langs->trans('NotConfigured'); |
|
111 | - } |
|
112 | - return $numExample; |
|
98 | + global $conf,$langs,$mysoc; |
|
99 | + |
|
100 | + $old_code_client=$mysoc->code_client; |
|
101 | + $old_code_type=$mysoc->typent_code; |
|
102 | + $mysoc->code_client='CCCCCCCCCC'; |
|
103 | + $mysoc->typent_code='TTTTTTTTTT'; |
|
104 | + $numExample = $this->getNextValue($mysoc,''); |
|
105 | + $mysoc->code_client=$old_code_client; |
|
106 | + $mysoc->typent_code=$old_code_type; |
|
107 | + |
|
108 | + if (! $numExample) |
|
109 | + { |
|
110 | + $numExample = $langs->trans('NotConfigured'); |
|
111 | + } |
|
112 | + return $numExample; |
|
113 | 113 | } |
114 | 114 | |
115 | - /** |
|
116 | - * Return next value |
|
117 | - * |
|
118 | - * @param Societe $objsoc Third party object |
|
119 | - * @param Object $shipment Shipment object |
|
120 | - * @return string Value if OK, 0 if KO |
|
121 | - */ |
|
115 | + /** |
|
116 | + * Return next value |
|
117 | + * |
|
118 | + * @param Societe $objsoc Third party object |
|
119 | + * @param Object $shipment Shipment object |
|
120 | + * @return string Value if OK, 0 if KO |
|
121 | + */ |
|
122 | 122 | function getNextValue($objsoc,$shipment) |
123 | 123 | { |
124 | - global $db,$conf; |
|
124 | + global $db,$conf; |
|
125 | 125 | |
126 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php'; |
|
126 | + require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php'; |
|
127 | 127 | |
128 | - $mask=$conf->global->EXPEDITION_RIBERA_MASK; |
|
128 | + $mask=$conf->global->EXPEDITION_RIBERA_MASK; |
|
129 | 129 | |
130 | - if (! $mask) |
|
131 | - { |
|
132 | - $this->error='NotConfigured'; |
|
133 | - return 0; |
|
134 | - } |
|
130 | + if (! $mask) |
|
131 | + { |
|
132 | + $this->error='NotConfigured'; |
|
133 | + return 0; |
|
134 | + } |
|
135 | 135 | |
136 | - $date = $shipment->date_expedition; |
|
136 | + $date = $shipment->date_expedition; |
|
137 | 137 | |
138 | - $numFinal=get_next_value($db,$mask,'expedition','ref','',$objsoc,$date); |
|
138 | + $numFinal=get_next_value($db,$mask,'expedition','ref','',$objsoc,$date); |
|
139 | 139 | |
140 | - return $numFinal; |
|
141 | - } |
|
140 | + return $numFinal; |
|
141 | + } |
|
142 | 142 | |
143 | 143 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
144 | - /** |
|
145 | - * Return next free value |
|
146 | - * |
|
147 | - * @param Societe $objsoc Third party object |
|
148 | - * @param Object $objforref Shipment object |
|
149 | - * @return string Next free value |
|
150 | - */ |
|
144 | + /** |
|
145 | + * Return next free value |
|
146 | + * |
|
147 | + * @param Societe $objsoc Third party object |
|
148 | + * @param Object $objforref Shipment object |
|
149 | + * @return string Next free value |
|
150 | + */ |
|
151 | 151 | function expedition_get_num($objsoc,$objforref) |
152 | 152 | { |
153 | 153 | // phpcs:enable |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * \brief File of class to manage expedition numbering rules Ribera |
23 | 23 | */ |
24 | 24 | |
25 | -require_once DOL_DOCUMENT_ROOT .'/core/modules/expedition/modules_expedition.php'; |
|
25 | +require_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php'; |
|
26 | 26 | |
27 | 27 | /** |
28 | 28 | * Class to manage expedition numbering rules Ribera |
@@ -45,12 +45,12 @@ discard block |
||
45 | 45 | * @deprecated |
46 | 46 | * @see name |
47 | 47 | */ |
48 | - public $nom='Ribera'; |
|
48 | + public $nom = 'Ribera'; |
|
49 | 49 | |
50 | 50 | /** |
51 | 51 | * @var string model name |
52 | 52 | */ |
53 | - public $name='Ribera'; |
|
53 | + public $name = 'Ribera'; |
|
54 | 54 | |
55 | 55 | /** |
56 | 56 | * Return default description of numbering model |
@@ -66,24 +66,24 @@ discard block |
||
66 | 66 | $form = new Form($this->db); |
67 | 67 | |
68 | 68 | $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n"; |
69 | - $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
70 | - $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
71 | - $texte.= '<input type="hidden" name="action" value="updateMask">'; |
|
72 | - $texte.= '<input type="hidden" name="maskconstexpedition" value="EXPEDITION_RIBERA_MASK">'; |
|
73 | - $texte.= '<table class="nobordernopadding" width="100%">'; |
|
74 | - |
|
75 | - $tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("Shipment"),$langs->transnoentities("Shipment")); |
|
76 | - $tooltip.=$langs->trans("GenericMaskCodes2"); |
|
77 | - $tooltip.=$langs->trans("GenericMaskCodes3"); |
|
78 | - $tooltip.=$langs->trans("GenericMaskCodes4a",$langs->transnoentities("Shipment"),$langs->transnoentities("Shipment")); |
|
79 | - $tooltip.=$langs->trans("GenericMaskCodes5"); |
|
80 | - |
|
81 | - $texte.= '<tr><td>'.$langs->trans("Mask").':</td>'; |
|
82 | - $texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskexpedition" value="'.$conf->global->EXPEDITION_RIBERA_MASK.'">',$tooltip,1,1).'</td>'; |
|
83 | - $texte.= '<td align="left" rowspan="2"> <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>'; |
|
84 | - $texte.= '</tr>'; |
|
85 | - $texte.= '</table>'; |
|
86 | - $texte.= '</form>'; |
|
69 | + $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
70 | + $texte .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
71 | + $texte .= '<input type="hidden" name="action" value="updateMask">'; |
|
72 | + $texte .= '<input type="hidden" name="maskconstexpedition" value="EXPEDITION_RIBERA_MASK">'; |
|
73 | + $texte .= '<table class="nobordernopadding" width="100%">'; |
|
74 | + |
|
75 | + $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("Shipment"), $langs->transnoentities("Shipment")); |
|
76 | + $tooltip .= $langs->trans("GenericMaskCodes2"); |
|
77 | + $tooltip .= $langs->trans("GenericMaskCodes3"); |
|
78 | + $tooltip .= $langs->trans("GenericMaskCodes4a", $langs->transnoentities("Shipment"), $langs->transnoentities("Shipment")); |
|
79 | + $tooltip .= $langs->trans("GenericMaskCodes5"); |
|
80 | + |
|
81 | + $texte .= '<tr><td>'.$langs->trans("Mask").':</td>'; |
|
82 | + $texte .= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="maskexpedition" value="'.$conf->global->EXPEDITION_RIBERA_MASK.'">', $tooltip, 1, 1).'</td>'; |
|
83 | + $texte .= '<td align="left" rowspan="2"> <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"></td>'; |
|
84 | + $texte .= '</tr>'; |
|
85 | + $texte .= '</table>'; |
|
86 | + $texte .= '</form>'; |
|
87 | 87 | |
88 | 88 | return $texte; |
89 | 89 | } |
@@ -95,17 +95,17 @@ discard block |
||
95 | 95 | */ |
96 | 96 | function getExample() |
97 | 97 | { |
98 | - global $conf,$langs,$mysoc; |
|
98 | + global $conf, $langs, $mysoc; |
|
99 | 99 | |
100 | - $old_code_client=$mysoc->code_client; |
|
101 | - $old_code_type=$mysoc->typent_code; |
|
102 | - $mysoc->code_client='CCCCCCCCCC'; |
|
103 | - $mysoc->typent_code='TTTTTTTTTT'; |
|
104 | - $numExample = $this->getNextValue($mysoc,''); |
|
105 | - $mysoc->code_client=$old_code_client; |
|
106 | - $mysoc->typent_code=$old_code_type; |
|
100 | + $old_code_client = $mysoc->code_client; |
|
101 | + $old_code_type = $mysoc->typent_code; |
|
102 | + $mysoc->code_client = 'CCCCCCCCCC'; |
|
103 | + $mysoc->typent_code = 'TTTTTTTTTT'; |
|
104 | + $numExample = $this->getNextValue($mysoc, ''); |
|
105 | + $mysoc->code_client = $old_code_client; |
|
106 | + $mysoc->typent_code = $old_code_type; |
|
107 | 107 | |
108 | - if (! $numExample) |
|
108 | + if (!$numExample) |
|
109 | 109 | { |
110 | 110 | $numExample = $langs->trans('NotConfigured'); |
111 | 111 | } |
@@ -119,23 +119,23 @@ discard block |
||
119 | 119 | * @param Object $shipment Shipment object |
120 | 120 | * @return string Value if OK, 0 if KO |
121 | 121 | */ |
122 | - function getNextValue($objsoc,$shipment) |
|
122 | + function getNextValue($objsoc, $shipment) |
|
123 | 123 | { |
124 | - global $db,$conf; |
|
124 | + global $db, $conf; |
|
125 | 125 | |
126 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php'; |
|
126 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; |
|
127 | 127 | |
128 | - $mask=$conf->global->EXPEDITION_RIBERA_MASK; |
|
128 | + $mask = $conf->global->EXPEDITION_RIBERA_MASK; |
|
129 | 129 | |
130 | - if (! $mask) |
|
130 | + if (!$mask) |
|
131 | 131 | { |
132 | - $this->error='NotConfigured'; |
|
132 | + $this->error = 'NotConfigured'; |
|
133 | 133 | return 0; |
134 | 134 | } |
135 | 135 | |
136 | 136 | $date = $shipment->date_expedition; |
137 | 137 | |
138 | - $numFinal=get_next_value($db,$mask,'expedition','ref','',$objsoc,$date); |
|
138 | + $numFinal = get_next_value($db, $mask, 'expedition', 'ref', '', $objsoc, $date); |
|
139 | 139 | |
140 | 140 | return $numFinal; |
141 | 141 | } |
@@ -148,9 +148,9 @@ discard block |
||
148 | 148 | * @param Object $objforref Shipment object |
149 | 149 | * @return string Next free value |
150 | 150 | */ |
151 | - function expedition_get_num($objsoc,$objforref) |
|
151 | + function expedition_get_num($objsoc, $objforref) |
|
152 | 152 | { |
153 | 153 | // phpcs:enable |
154 | - return $this->getNextValue($objsoc,$objforref); |
|
154 | + return $this->getNextValue($objsoc, $objforref); |
|
155 | 155 | } |
156 | 156 | } |
@@ -28,139 +28,139 @@ |
||
28 | 28 | */ |
29 | 29 | class mod_expedition_safor extends ModelNumRefExpedition |
30 | 30 | { |
31 | - /** |
|
31 | + /** |
|
32 | 32 | * Dolibarr version of the loaded document |
33 | 33 | * @public string |
34 | 34 | */ |
35 | - public $version = 'dolibarr'; |
|
35 | + public $version = 'dolibarr'; |
|
36 | 36 | |
37 | - public $prefix='SH'; |
|
37 | + public $prefix='SH'; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @var string Error code (or message) |
|
41 | - */ |
|
42 | - public $error=''; |
|
39 | + /** |
|
40 | + * @var string Error code (or message) |
|
41 | + */ |
|
42 | + public $error=''; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @var string Nom du modele |
|
46 | - * @deprecated |
|
47 | - * @see name |
|
48 | - */ |
|
49 | - public $nom='Safor'; |
|
44 | + /** |
|
45 | + * @var string Nom du modele |
|
46 | + * @deprecated |
|
47 | + * @see name |
|
48 | + */ |
|
49 | + public $nom='Safor'; |
|
50 | 50 | |
51 | - /** |
|
52 | - * @var string model name |
|
53 | - */ |
|
54 | - public $name='Safor'; |
|
51 | + /** |
|
52 | + * @var string model name |
|
53 | + */ |
|
54 | + public $name='Safor'; |
|
55 | 55 | |
56 | 56 | |
57 | - /** |
|
58 | - * Return default description of numbering model |
|
59 | - * |
|
60 | - * @return string text description |
|
61 | - */ |
|
57 | + /** |
|
58 | + * Return default description of numbering model |
|
59 | + * |
|
60 | + * @return string text description |
|
61 | + */ |
|
62 | 62 | function info() |
63 | 63 | { |
64 | - global $langs; |
|
65 | - return $langs->trans("SimpleNumRefModelDesc",$this->prefix); |
|
64 | + global $langs; |
|
65 | + return $langs->trans("SimpleNumRefModelDesc",$this->prefix); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | |
69 | - /** |
|
70 | - * Return numbering example |
|
71 | - * |
|
72 | - * @return string Example |
|
73 | - */ |
|
74 | - function getExample() |
|
75 | - { |
|
76 | - return $this->prefix."0501-0001"; |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * Test if existing numbers make problems with numbering |
|
82 | - * |
|
83 | - * @return boolean false if conflit, true if ok |
|
84 | - */ |
|
85 | - function canBeActivated() |
|
86 | - { |
|
87 | - global $conf,$langs,$db; |
|
88 | - |
|
89 | - $coyymm=''; $max=''; |
|
90 | - |
|
91 | - $posindice=8; |
|
92 | - $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; |
|
93 | - $sql.= " FROM ".MAIN_DB_PREFIX."expedition"; |
|
94 | - $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; |
|
95 | - $sql.= " AND entity = ".$conf->entity; |
|
96 | - |
|
97 | - $resql=$db->query($sql); |
|
98 | - if ($resql) |
|
99 | - { |
|
100 | - $row = $db->fetch_row($resql); |
|
101 | - if ($row) { $coyymm = substr($row[0],0,6); $max=$row[0]; } |
|
102 | - } |
|
103 | - if ($coyymm && ! preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i',$coyymm)) |
|
104 | - { |
|
105 | - $langs->load("errors"); |
|
106 | - $this->error=$langs->trans('ErrorNumRefModel', $max); |
|
107 | - return false; |
|
108 | - } |
|
109 | - |
|
110 | - return true; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * Return next value |
|
115 | - * |
|
116 | - * @param Societe $objsoc Third party object |
|
117 | - * @param Object $shipment Shipment object |
|
118 | - * @return string Value if OK, 0 if KO |
|
119 | - */ |
|
120 | - function getNextValue($objsoc,$shipment) |
|
121 | - { |
|
122 | - global $db,$conf; |
|
123 | - |
|
124 | - $posindice=8; |
|
125 | - $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; |
|
126 | - $sql.= " FROM ".MAIN_DB_PREFIX."expedition"; |
|
127 | - $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; |
|
128 | - $sql.= " AND entity = ".$conf->entity; |
|
129 | - |
|
130 | - $resql=$db->query($sql); |
|
131 | - if ($resql) |
|
132 | - { |
|
133 | - $obj = $db->fetch_object($resql); |
|
134 | - if ($obj) $max = intval($obj->max); |
|
135 | - else $max=0; |
|
136 | - } |
|
137 | - else |
|
138 | - { |
|
139 | - dol_syslog("mod_expedition_safor::getNextValue", LOG_DEBUG); |
|
140 | - return -1; |
|
141 | - } |
|
142 | - |
|
143 | - $date=time(); |
|
144 | - $yymm = strftime("%y%m",$date); |
|
145 | - |
|
146 | - 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 |
|
147 | - else $num = sprintf("%04s",$max+1); |
|
148 | - |
|
149 | - dol_syslog("mod_expedition_safor::getNextValue return ".$this->prefix.$yymm."-".$num); |
|
150 | - return $this->prefix.$yymm."-".$num; |
|
151 | - } |
|
69 | + /** |
|
70 | + * Return numbering example |
|
71 | + * |
|
72 | + * @return string Example |
|
73 | + */ |
|
74 | + function getExample() |
|
75 | + { |
|
76 | + return $this->prefix."0501-0001"; |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * Test if existing numbers make problems with numbering |
|
82 | + * |
|
83 | + * @return boolean false if conflit, true if ok |
|
84 | + */ |
|
85 | + function canBeActivated() |
|
86 | + { |
|
87 | + global $conf,$langs,$db; |
|
88 | + |
|
89 | + $coyymm=''; $max=''; |
|
90 | + |
|
91 | + $posindice=8; |
|
92 | + $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; |
|
93 | + $sql.= " FROM ".MAIN_DB_PREFIX."expedition"; |
|
94 | + $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; |
|
95 | + $sql.= " AND entity = ".$conf->entity; |
|
96 | + |
|
97 | + $resql=$db->query($sql); |
|
98 | + if ($resql) |
|
99 | + { |
|
100 | + $row = $db->fetch_row($resql); |
|
101 | + if ($row) { $coyymm = substr($row[0],0,6); $max=$row[0]; } |
|
102 | + } |
|
103 | + if ($coyymm && ! preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i',$coyymm)) |
|
104 | + { |
|
105 | + $langs->load("errors"); |
|
106 | + $this->error=$langs->trans('ErrorNumRefModel', $max); |
|
107 | + return false; |
|
108 | + } |
|
109 | + |
|
110 | + return true; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * Return next value |
|
115 | + * |
|
116 | + * @param Societe $objsoc Third party object |
|
117 | + * @param Object $shipment Shipment object |
|
118 | + * @return string Value if OK, 0 if KO |
|
119 | + */ |
|
120 | + function getNextValue($objsoc,$shipment) |
|
121 | + { |
|
122 | + global $db,$conf; |
|
123 | + |
|
124 | + $posindice=8; |
|
125 | + $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; |
|
126 | + $sql.= " FROM ".MAIN_DB_PREFIX."expedition"; |
|
127 | + $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; |
|
128 | + $sql.= " AND entity = ".$conf->entity; |
|
129 | + |
|
130 | + $resql=$db->query($sql); |
|
131 | + if ($resql) |
|
132 | + { |
|
133 | + $obj = $db->fetch_object($resql); |
|
134 | + if ($obj) $max = intval($obj->max); |
|
135 | + else $max=0; |
|
136 | + } |
|
137 | + else |
|
138 | + { |
|
139 | + dol_syslog("mod_expedition_safor::getNextValue", LOG_DEBUG); |
|
140 | + return -1; |
|
141 | + } |
|
142 | + |
|
143 | + $date=time(); |
|
144 | + $yymm = strftime("%y%m",$date); |
|
145 | + |
|
146 | + 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 |
|
147 | + else $num = sprintf("%04s",$max+1); |
|
148 | + |
|
149 | + dol_syslog("mod_expedition_safor::getNextValue return ".$this->prefix.$yymm."-".$num); |
|
150 | + return $this->prefix.$yymm."-".$num; |
|
151 | + } |
|
152 | 152 | |
153 | 153 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
154 | - /** |
|
155 | - * Return next free value |
|
156 | - * |
|
157 | - * @param Societe $objsoc Third party object |
|
158 | - * @param Object $objforref Shipment object |
|
159 | - * @return string Next free value |
|
160 | - */ |
|
161 | - function expedition_get_num($objsoc,$objforref) |
|
162 | - { |
|
154 | + /** |
|
155 | + * Return next free value |
|
156 | + * |
|
157 | + * @param Societe $objsoc Third party object |
|
158 | + * @param Object $objforref Shipment object |
|
159 | + * @return string Next free value |
|
160 | + */ |
|
161 | + function expedition_get_num($objsoc,$objforref) |
|
162 | + { |
|
163 | 163 | // phpcs:enable |
164 | - return $this->getNextValue($objsoc,$objforref); |
|
165 | - } |
|
164 | + return $this->getNextValue($objsoc,$objforref); |
|
165 | + } |
|
166 | 166 | } |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * \ingroup expedition |
22 | 22 | * \brief File of class to manage shipments numbering rules Safor |
23 | 23 | */ |
24 | -require_once DOL_DOCUMENT_ROOT .'/core/modules/expedition/modules_expedition.php'; |
|
24 | +require_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php'; |
|
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Class to manage expedition numbering rules Safor |
@@ -34,24 +34,24 @@ discard block |
||
34 | 34 | */ |
35 | 35 | public $version = 'dolibarr'; |
36 | 36 | |
37 | - public $prefix='SH'; |
|
37 | + public $prefix = 'SH'; |
|
38 | 38 | |
39 | 39 | /** |
40 | 40 | * @var string Error code (or message) |
41 | 41 | */ |
42 | - public $error=''; |
|
42 | + public $error = ''; |
|
43 | 43 | |
44 | 44 | /** |
45 | 45 | * @var string Nom du modele |
46 | 46 | * @deprecated |
47 | 47 | * @see name |
48 | 48 | */ |
49 | - public $nom='Safor'; |
|
49 | + public $nom = 'Safor'; |
|
50 | 50 | |
51 | 51 | /** |
52 | 52 | * @var string model name |
53 | 53 | */ |
54 | - public $name='Safor'; |
|
54 | + public $name = 'Safor'; |
|
55 | 55 | |
56 | 56 | |
57 | 57 | /** |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | function info() |
63 | 63 | { |
64 | 64 | global $langs; |
65 | - return $langs->trans("SimpleNumRefModelDesc",$this->prefix); |
|
65 | + return $langs->trans("SimpleNumRefModelDesc", $this->prefix); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | |
@@ -84,26 +84,26 @@ discard block |
||
84 | 84 | */ |
85 | 85 | function canBeActivated() |
86 | 86 | { |
87 | - global $conf,$langs,$db; |
|
87 | + global $conf, $langs, $db; |
|
88 | 88 | |
89 | - $coyymm=''; $max=''; |
|
89 | + $coyymm = ''; $max = ''; |
|
90 | 90 | |
91 | - $posindice=8; |
|
91 | + $posindice = 8; |
|
92 | 92 | $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; |
93 | - $sql.= " FROM ".MAIN_DB_PREFIX."expedition"; |
|
94 | - $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; |
|
95 | - $sql.= " AND entity = ".$conf->entity; |
|
93 | + $sql .= " FROM ".MAIN_DB_PREFIX."expedition"; |
|
94 | + $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; |
|
95 | + $sql .= " AND entity = ".$conf->entity; |
|
96 | 96 | |
97 | - $resql=$db->query($sql); |
|
97 | + $resql = $db->query($sql); |
|
98 | 98 | if ($resql) |
99 | 99 | { |
100 | 100 | $row = $db->fetch_row($resql); |
101 | - if ($row) { $coyymm = substr($row[0],0,6); $max=$row[0]; } |
|
101 | + if ($row) { $coyymm = substr($row[0], 0, 6); $max = $row[0]; } |
|
102 | 102 | } |
103 | - if ($coyymm && ! preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i',$coyymm)) |
|
103 | + if ($coyymm && !preg_match('/'.$this->prefix.'[0-9][0-9][0-9][0-9]/i', $coyymm)) |
|
104 | 104 | { |
105 | 105 | $langs->load("errors"); |
106 | - $this->error=$langs->trans('ErrorNumRefModel', $max); |
|
106 | + $this->error = $langs->trans('ErrorNumRefModel', $max); |
|
107 | 107 | return false; |
108 | 108 | } |
109 | 109 | |
@@ -117,22 +117,22 @@ discard block |
||
117 | 117 | * @param Object $shipment Shipment object |
118 | 118 | * @return string Value if OK, 0 if KO |
119 | 119 | */ |
120 | - function getNextValue($objsoc,$shipment) |
|
120 | + function getNextValue($objsoc, $shipment) |
|
121 | 121 | { |
122 | - global $db,$conf; |
|
122 | + global $db, $conf; |
|
123 | 123 | |
124 | - $posindice=8; |
|
124 | + $posindice = 8; |
|
125 | 125 | $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; |
126 | - $sql.= " FROM ".MAIN_DB_PREFIX."expedition"; |
|
127 | - $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; |
|
128 | - $sql.= " AND entity = ".$conf->entity; |
|
126 | + $sql .= " FROM ".MAIN_DB_PREFIX."expedition"; |
|
127 | + $sql .= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; |
|
128 | + $sql .= " AND entity = ".$conf->entity; |
|
129 | 129 | |
130 | - $resql=$db->query($sql); |
|
130 | + $resql = $db->query($sql); |
|
131 | 131 | if ($resql) |
132 | 132 | { |
133 | 133 | $obj = $db->fetch_object($resql); |
134 | 134 | if ($obj) $max = intval($obj->max); |
135 | - else $max=0; |
|
135 | + else $max = 0; |
|
136 | 136 | } |
137 | 137 | else |
138 | 138 | { |
@@ -140,11 +140,11 @@ discard block |
||
140 | 140 | return -1; |
141 | 141 | } |
142 | 142 | |
143 | - $date=time(); |
|
144 | - $yymm = strftime("%y%m",$date); |
|
143 | + $date = time(); |
|
144 | + $yymm = strftime("%y%m", $date); |
|
145 | 145 | |
146 | - 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 |
|
147 | - else $num = sprintf("%04s",$max+1); |
|
146 | + 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 |
|
147 | + else $num = sprintf("%04s", $max + 1); |
|
148 | 148 | |
149 | 149 | dol_syslog("mod_expedition_safor::getNextValue return ".$this->prefix.$yymm."-".$num); |
150 | 150 | return $this->prefix.$yymm."-".$num; |
@@ -158,9 +158,9 @@ discard block |
||
158 | 158 | * @param Object $objforref Shipment object |
159 | 159 | * @return string Next free value |
160 | 160 | */ |
161 | - function expedition_get_num($objsoc,$objforref) |
|
161 | + function expedition_get_num($objsoc, $objforref) |
|
162 | 162 | { |
163 | 163 | // phpcs:enable |
164 | - return $this->getNextValue($objsoc,$objforref); |
|
164 | + return $this->getNextValue($objsoc, $objforref); |
|
165 | 165 | } |
166 | 166 | } |
@@ -131,10 +131,12 @@ discard block |
||
131 | 131 | if ($resql) |
132 | 132 | { |
133 | 133 | $obj = $db->fetch_object($resql); |
134 | - if ($obj) $max = intval($obj->max); |
|
135 | - else $max=0; |
|
136 | - } |
|
137 | - else |
|
134 | + if ($obj) { |
|
135 | + $max = intval($obj->max); |
|
136 | + } else { |
|
137 | + $max=0; |
|
138 | + } |
|
139 | + } else |
|
138 | 140 | { |
139 | 141 | dol_syslog("mod_expedition_safor::getNextValue", LOG_DEBUG); |
140 | 142 | return -1; |
@@ -143,8 +145,13 @@ discard block |
||
143 | 145 | $date=time(); |
144 | 146 | $yymm = strftime("%y%m",$date); |
145 | 147 | |
146 | - 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 |
|
147 | - else $num = sprintf("%04s",$max+1); |
|
148 | + if ($max >= (pow(10, 4) - 1)) { |
|
149 | + $num=$max+1; |
|
150 | + } |
|
151 | + // If counter > 9999, we do not format on 4 chars, we take number as it is |
|
152 | + else { |
|
153 | + $num = sprintf("%04s",$max+1); |
|
154 | + } |
|
148 | 155 | |
149 | 156 | dol_syslog("mod_expedition_safor::getNextValue return ".$this->prefix.$yymm."-".$num); |
150 | 157 | return $this->prefix.$yymm."-".$num; |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | * \brief File that contains parent class for sending receipts models |
30 | 30 | * and parent class for sending receipts numbering models |
31 | 31 | */ |
32 | - require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php'; |
|
32 | + require_once DOL_DOCUMENT_ROOT.'/core/class/commondocgenerator.class.php'; |
|
33 | 33 | |
34 | 34 | /** |
35 | 35 | * Parent class of sending receipts models |
@@ -37,32 +37,32 @@ discard block |
||
37 | 37 | abstract class ModelePdfExpedition extends CommonDocGenerator |
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 | // 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='shipping'; |
|
59 | - $liste=array(); |
|
58 | + $type='shipping'; |
|
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 | |
@@ -71,81 +71,81 @@ discard block |
||
71 | 71 | */ |
72 | 72 | abstract class ModelNumRefExpedition |
73 | 73 | { |
74 | - /** |
|
75 | - * @var string Error code (or message) |
|
76 | - */ |
|
77 | - public $error=''; |
|
78 | - |
|
79 | - /** Return if a model can be used or not |
|
80 | - * |
|
81 | - * @return boolean true if model can be used |
|
82 | - */ |
|
83 | - function isEnabled() |
|
84 | - { |
|
85 | - return true; |
|
86 | - } |
|
87 | - |
|
88 | - /** |
|
89 | - * Return default description of numbering model |
|
90 | - * |
|
91 | - * @return string text description |
|
92 | - */ |
|
93 | - function info() |
|
94 | - { |
|
95 | - global $langs; |
|
96 | - $langs->load("sendings"); |
|
97 | - return $langs->trans("NoDescription"); |
|
98 | - } |
|
99 | - |
|
100 | - /** |
|
101 | - * Returns numbering example |
|
102 | - * |
|
103 | - * @return string Example |
|
104 | - */ |
|
105 | - function getExample() |
|
106 | - { |
|
107 | - global $langs; |
|
108 | - $langs->load("sendings"); |
|
109 | - return $langs->trans("NoExample"); |
|
110 | - } |
|
111 | - |
|
112 | - /** |
|
113 | - * Test if existing numbers make problems with numbering |
|
114 | - * |
|
115 | - * @return boolean false if conflit, true if ok |
|
116 | - */ |
|
117 | - function canBeActivated() |
|
118 | - { |
|
119 | - return true; |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Returns next value assigned |
|
124 | - * |
|
125 | - * @param Societe $objsoc Third party object |
|
126 | - * @param Object $shipment Shipment object |
|
127 | - * @return string Value |
|
128 | - */ |
|
129 | - function getNextValue($objsoc, $shipment) |
|
130 | - { |
|
131 | - global $langs; |
|
132 | - return $langs->trans("NotAvailable"); |
|
133 | - } |
|
134 | - |
|
135 | - /** |
|
136 | - * Returns version of the numbering model |
|
137 | - * |
|
138 | - * @return string Value |
|
139 | - */ |
|
140 | - function getVersion() |
|
141 | - { |
|
142 | - global $langs; |
|
143 | - $langs->load("admin"); |
|
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; |
|
149 | - return $langs->trans("NotAvailable"); |
|
150 | - } |
|
74 | + /** |
|
75 | + * @var string Error code (or message) |
|
76 | + */ |
|
77 | + public $error=''; |
|
78 | + |
|
79 | + /** Return if a model can be used or not |
|
80 | + * |
|
81 | + * @return boolean true if model can be used |
|
82 | + */ |
|
83 | + function isEnabled() |
|
84 | + { |
|
85 | + return true; |
|
86 | + } |
|
87 | + |
|
88 | + /** |
|
89 | + * Return default description of numbering model |
|
90 | + * |
|
91 | + * @return string text description |
|
92 | + */ |
|
93 | + function info() |
|
94 | + { |
|
95 | + global $langs; |
|
96 | + $langs->load("sendings"); |
|
97 | + return $langs->trans("NoDescription"); |
|
98 | + } |
|
99 | + |
|
100 | + /** |
|
101 | + * Returns numbering example |
|
102 | + * |
|
103 | + * @return string Example |
|
104 | + */ |
|
105 | + function getExample() |
|
106 | + { |
|
107 | + global $langs; |
|
108 | + $langs->load("sendings"); |
|
109 | + return $langs->trans("NoExample"); |
|
110 | + } |
|
111 | + |
|
112 | + /** |
|
113 | + * Test if existing numbers make problems with numbering |
|
114 | + * |
|
115 | + * @return boolean false if conflit, true if ok |
|
116 | + */ |
|
117 | + function canBeActivated() |
|
118 | + { |
|
119 | + return true; |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Returns next value assigned |
|
124 | + * |
|
125 | + * @param Societe $objsoc Third party object |
|
126 | + * @param Object $shipment Shipment object |
|
127 | + * @return string Value |
|
128 | + */ |
|
129 | + function getNextValue($objsoc, $shipment) |
|
130 | + { |
|
131 | + global $langs; |
|
132 | + return $langs->trans("NotAvailable"); |
|
133 | + } |
|
134 | + |
|
135 | + /** |
|
136 | + * Returns version of the numbering model |
|
137 | + * |
|
138 | + * @return string Value |
|
139 | + */ |
|
140 | + function getVersion() |
|
141 | + { |
|
142 | + global $langs; |
|
143 | + $langs->load("admin"); |
|
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; |
|
149 | + return $langs->trans("NotAvailable"); |
|
150 | + } |
|
151 | 151 | } |
@@ -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 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
@@ -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='shipping'; |
|
59 | - $liste=array(); |
|
58 | + $type = 'shipping'; |
|
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 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | /** |
75 | 75 | * @var string Error code (or message) |
76 | 76 | */ |
77 | - public $error=''; |
|
77 | + public $error = ''; |
|
78 | 78 | |
79 | 79 | /** Return if a model can be used or not |
80 | 80 | * |
@@ -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 | } |
@@ -36,103 +36,103 @@ discard block |
||
36 | 36 | */ |
37 | 37 | class doc_generic_odt extends ModeleThirdPartyDoc |
38 | 38 | { |
39 | - /** |
|
40 | - * Issuer |
|
41 | - * @var Societe |
|
42 | - */ |
|
43 | - public $emetteur; |
|
39 | + /** |
|
40 | + * Issuer |
|
41 | + * @var Societe |
|
42 | + */ |
|
43 | + public $emetteur; |
|
44 | 44 | |
45 | - /** |
|
45 | + /** |
|
46 | 46 | * @var array() Minimum version of PHP required by module. |
47 | - * e.g.: PHP ≥ 5.4 = array(5, 4) |
|
47 | + * e.g.: PHP ≥ 5.4 = array(5, 4) |
|
48 | 48 | */ |
49 | - public $phpmin = array(5, 4); |
|
49 | + public $phpmin = array(5, 4); |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * Constructor |
|
54 | - * |
|
55 | - * @param DoliDB $db Database handler |
|
56 | - */ |
|
57 | - function __construct($db) |
|
58 | - { |
|
59 | - global $conf, $langs, $mysoc; |
|
52 | + /** |
|
53 | + * Constructor |
|
54 | + * |
|
55 | + * @param DoliDB $db Database handler |
|
56 | + */ |
|
57 | + function __construct($db) |
|
58 | + { |
|
59 | + global $conf, $langs, $mysoc; |
|
60 | 60 | |
61 | - // Load translation files required by the page |
|
61 | + // Load translation files required by the page |
|
62 | 62 | $langs->loadLangs(array("main","companies")); |
63 | 63 | |
64 | - $this->db = $db; |
|
65 | - $this->name = "ODT templates"; |
|
66 | - $this->description = $langs->trans("DocumentModelOdt"); |
|
67 | - $this->scandir = 'COMPANY_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan |
|
68 | - |
|
69 | - // Dimension page pour format A4 |
|
70 | - $this->type = 'odt'; |
|
71 | - $this->page_largeur = 0; |
|
72 | - $this->page_hauteur = 0; |
|
73 | - $this->format = array($this->page_largeur,$this->page_hauteur); |
|
74 | - $this->marge_gauche=0; |
|
75 | - $this->marge_droite=0; |
|
76 | - $this->marge_haute=0; |
|
77 | - $this->marge_basse=0; |
|
78 | - |
|
79 | - $this->option_logo = 1; // Affiche logo |
|
80 | - |
|
81 | - // Recupere emmetteur |
|
82 | - $this->emetteur=$mysoc; |
|
83 | - if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // Par defaut, si n'etait pas defini |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * Return description of a module |
|
89 | - * |
|
90 | - * @param Translate $langs Object language |
|
91 | - * @return string Description |
|
92 | - */ |
|
93 | - function info($langs) |
|
94 | - { |
|
95 | - global $conf,$langs; |
|
96 | - |
|
97 | - // Load traductions files requiredby by page |
|
98 | - $langs->loadLangs(array("companies", "errors")); |
|
99 | - |
|
100 | - $form = new Form($this->db); |
|
101 | - |
|
102 | - $texte = $this->description.".<br>\n"; |
|
103 | - $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
104 | - $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
105 | - $texte.= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
106 | - $texte.= '<input type="hidden" name="param1" value="COMPANY_ADDON_PDF_ODT_PATH">'; |
|
107 | - $texte.= '<table class="nobordernopadding" width="100%">'; |
|
108 | - |
|
109 | - // List of directories area |
|
110 | - $texte.= '<tr><td>'; |
|
111 | - $texttitle=$langs->trans("ListOfDirectories"); |
|
112 | - $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->COMPANY_ADDON_PDF_ODT_PATH))); |
|
113 | - $listoffiles=array(); |
|
114 | - foreach($listofdir as $key=>$tmpdir) |
|
115 | - { |
|
116 | - $tmpdir=trim($tmpdir); |
|
117 | - $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); |
|
118 | - if (! $tmpdir) { unset($listofdir[$key]); continue; } |
|
119 | - if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); |
|
120 | - else |
|
121 | - { |
|
122 | - $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.od(s|t)$','','name',SORT_ASC,0,true); // Disable hook for the moment |
|
123 | - if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
124 | - } |
|
125 | - } |
|
126 | - $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT"); |
|
127 | - // Add list of substitution keys |
|
128 | - $texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>'; |
|
129 | - $texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it |
|
130 | - |
|
131 | - $texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1); |
|
64 | + $this->db = $db; |
|
65 | + $this->name = "ODT templates"; |
|
66 | + $this->description = $langs->trans("DocumentModelOdt"); |
|
67 | + $this->scandir = 'COMPANY_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan |
|
68 | + |
|
69 | + // Dimension page pour format A4 |
|
70 | + $this->type = 'odt'; |
|
71 | + $this->page_largeur = 0; |
|
72 | + $this->page_hauteur = 0; |
|
73 | + $this->format = array($this->page_largeur,$this->page_hauteur); |
|
74 | + $this->marge_gauche=0; |
|
75 | + $this->marge_droite=0; |
|
76 | + $this->marge_haute=0; |
|
77 | + $this->marge_basse=0; |
|
78 | + |
|
79 | + $this->option_logo = 1; // Affiche logo |
|
80 | + |
|
81 | + // Recupere emmetteur |
|
82 | + $this->emetteur=$mysoc; |
|
83 | + if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // Par defaut, si n'etait pas defini |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * Return description of a module |
|
89 | + * |
|
90 | + * @param Translate $langs Object language |
|
91 | + * @return string Description |
|
92 | + */ |
|
93 | + function info($langs) |
|
94 | + { |
|
95 | + global $conf,$langs; |
|
96 | + |
|
97 | + // Load traductions files requiredby by page |
|
98 | + $langs->loadLangs(array("companies", "errors")); |
|
99 | + |
|
100 | + $form = new Form($this->db); |
|
101 | + |
|
102 | + $texte = $this->description.".<br>\n"; |
|
103 | + $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
104 | + $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
105 | + $texte.= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
106 | + $texte.= '<input type="hidden" name="param1" value="COMPANY_ADDON_PDF_ODT_PATH">'; |
|
107 | + $texte.= '<table class="nobordernopadding" width="100%">'; |
|
108 | + |
|
109 | + // List of directories area |
|
110 | + $texte.= '<tr><td>'; |
|
111 | + $texttitle=$langs->trans("ListOfDirectories"); |
|
112 | + $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->COMPANY_ADDON_PDF_ODT_PATH))); |
|
113 | + $listoffiles=array(); |
|
114 | + foreach($listofdir as $key=>$tmpdir) |
|
115 | + { |
|
116 | + $tmpdir=trim($tmpdir); |
|
117 | + $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); |
|
118 | + if (! $tmpdir) { unset($listofdir[$key]); continue; } |
|
119 | + if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); |
|
120 | + else |
|
121 | + { |
|
122 | + $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.od(s|t)$','','name',SORT_ASC,0,true); // Disable hook for the moment |
|
123 | + if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
124 | + } |
|
125 | + } |
|
126 | + $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT"); |
|
127 | + // Add list of substitution keys |
|
128 | + $texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>'; |
|
129 | + $texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it |
|
130 | + |
|
131 | + $texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1); |
|
132 | 132 | $texte.= '<table><tr><td>'; |
133 | - $texte.= '<textarea class="flat" cols="60" name="value1">'; |
|
134 | - $texte.=$conf->global->COMPANY_ADDON_PDF_ODT_PATH; |
|
135 | - $texte.= '</textarea>'; |
|
133 | + $texte.= '<textarea class="flat" cols="60" name="value1">'; |
|
134 | + $texte.=$conf->global->COMPANY_ADDON_PDF_ODT_PATH; |
|
135 | + $texte.= '</textarea>'; |
|
136 | 136 | $texte.= '</td>'; |
137 | 137 | $texte.= '<td align="center"> '; |
138 | 138 | $texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">'; |
@@ -140,62 +140,62 @@ discard block |
||
140 | 140 | $texte.= '</tr>'; |
141 | 141 | $texte.= '</table>'; |
142 | 142 | |
143 | - // Scan directories |
|
144 | - $nbofiles=count($listoffiles); |
|
145 | - if (! empty($conf->global->COMPANY_ADDON_PDF_ODT_PATH)) |
|
146 | - { |
|
147 | - $texte.=$langs->trans("NumberOfModelFilesFound").': <b>'; |
|
148 | - //$texte.=$nbofiles?'<a id="a_'.get_class($this).'" href="#">':''; |
|
149 | - $texte.=$nbofiles; |
|
150 | - //$texte.=$nbofiles?'</a>':''; |
|
151 | - $texte.='</b>'; |
|
152 | - } |
|
153 | - |
|
154 | - if ($nbofiles) |
|
155 | - { |
|
156 | - $texte.='<div id="div_'.get_class($this).'" class="hidden">'; |
|
157 | - foreach($listoffiles as $file) |
|
158 | - { |
|
143 | + // Scan directories |
|
144 | + $nbofiles=count($listoffiles); |
|
145 | + if (! empty($conf->global->COMPANY_ADDON_PDF_ODT_PATH)) |
|
146 | + { |
|
147 | + $texte.=$langs->trans("NumberOfModelFilesFound").': <b>'; |
|
148 | + //$texte.=$nbofiles?'<a id="a_'.get_class($this).'" href="#">':''; |
|
149 | + $texte.=$nbofiles; |
|
150 | + //$texte.=$nbofiles?'</a>':''; |
|
151 | + $texte.='</b>'; |
|
152 | + } |
|
153 | + |
|
154 | + if ($nbofiles) |
|
155 | + { |
|
156 | + $texte.='<div id="div_'.get_class($this).'" class="hidden">'; |
|
157 | + foreach($listoffiles as $file) |
|
158 | + { |
|
159 | 159 | $texte.=$file['name'].'<br>'; |
160 | - } |
|
161 | - $texte.='<div id="div_'.get_class($this).'">'; |
|
162 | - } |
|
160 | + } |
|
161 | + $texte.='<div id="div_'.get_class($this).'">'; |
|
162 | + } |
|
163 | 163 | |
164 | - $texte.= '</td>'; |
|
164 | + $texte.= '</td>'; |
|
165 | 165 | |
166 | - $texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">'; |
|
167 | - $texte.= $langs->trans("ExampleOfDirectoriesForModelGen"); |
|
168 | - $texte.= '</td>'; |
|
169 | - $texte.= '</tr>'; |
|
166 | + $texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">'; |
|
167 | + $texte.= $langs->trans("ExampleOfDirectoriesForModelGen"); |
|
168 | + $texte.= '</td>'; |
|
169 | + $texte.= '</tr>'; |
|
170 | 170 | |
171 | - $texte.= '</table>'; |
|
172 | - $texte.= '</form>'; |
|
171 | + $texte.= '</table>'; |
|
172 | + $texte.= '</form>'; |
|
173 | 173 | |
174 | - return $texte; |
|
175 | - } |
|
174 | + return $texte; |
|
175 | + } |
|
176 | 176 | |
177 | 177 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
178 | - /** |
|
179 | - * Function to build a document on disk using the generic odt module. |
|
180 | - * |
|
181 | - * @param Societe $object Object source to build document |
|
182 | - * @param Translate $outputlangs Lang output object |
|
183 | - * @param string $srctemplatepath Full path of source filename for generator using a template file |
|
178 | + /** |
|
179 | + * Function to build a document on disk using the generic odt module. |
|
180 | + * |
|
181 | + * @param Societe $object Object source to build document |
|
182 | + * @param Translate $outputlangs Lang output object |
|
183 | + * @param string $srctemplatepath Full path of source filename for generator using a template file |
|
184 | 184 | * @param int $hidedetails Do not show line details |
185 | 185 | * @param int $hidedesc Do not show desc |
186 | 186 | * @param int $hideref Do not show ref |
187 | - * @return int 1 if OK, <=0 if KO |
|
188 | - */ |
|
189 | - function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0) |
|
190 | - { |
|
187 | + * @return int 1 if OK, <=0 if KO |
|
188 | + */ |
|
189 | + function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0) |
|
190 | + { |
|
191 | 191 | // phpcs:enable |
192 | - global $user,$langs,$conf,$mysoc,$hookmanager; |
|
192 | + global $user,$langs,$conf,$mysoc,$hookmanager; |
|
193 | 193 | |
194 | - if (empty($srctemplatepath)) |
|
195 | - { |
|
196 | - dol_syslog("doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING); |
|
197 | - return -1; |
|
198 | - } |
|
194 | + if (empty($srctemplatepath)) |
|
195 | + { |
|
196 | + dol_syslog("doc_generic_odt::write_file parameter srctemplatepath empty", LOG_WARNING); |
|
197 | + return -1; |
|
198 | + } |
|
199 | 199 | |
200 | 200 | // Add odtgeneration hook |
201 | 201 | if (! is_object($hookmanager)) |
@@ -206,82 +206,82 @@ discard block |
||
206 | 206 | $hookmanager->initHooks(array('odtgeneration')); |
207 | 207 | global $action; |
208 | 208 | |
209 | - if (! is_object($outputlangs)) $outputlangs=$langs; |
|
210 | - $sav_charset_output=$outputlangs->charset_output; |
|
211 | - $outputlangs->charset_output='UTF-8'; |
|
212 | - |
|
213 | - // Load translation files required by the page |
|
214 | - $outputlangs->loadLangs(array("main", "dict", "companies", "projects")); |
|
215 | - |
|
216 | - if ($conf->societe->multidir_output[$object->entity]) |
|
217 | - { |
|
218 | - $dir = $conf->societe->multidir_output[$object->entity]; |
|
219 | - $objectref = dol_sanitizeFileName($object->id); |
|
220 | - if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref; |
|
221 | - |
|
222 | - if (! file_exists($dir)) |
|
223 | - { |
|
224 | - if (dol_mkdir($dir) < 0) |
|
225 | - { |
|
226 | - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
227 | - return -1; |
|
228 | - } |
|
229 | - } |
|
230 | - |
|
231 | - if (file_exists($dir)) |
|
232 | - { |
|
233 | - //print "srctemplatepath=".$srctemplatepath; // Src filename |
|
234 | - $newfile=basename($srctemplatepath); |
|
235 | - $newfiletmp=preg_replace('/\.od(s|t)/i','',$newfile); |
|
236 | - $newfiletmp=preg_replace('/template_/i','',$newfiletmp); |
|
237 | - $newfiletmp=preg_replace('/modele_/i','',$newfiletmp); |
|
238 | - // Get extension (ods or odt) |
|
239 | - $newfileformat=substr($newfile, strrpos($newfile, '.')+1); |
|
240 | - if ( ! empty($conf->global->MAIN_DOC_USE_OBJECT_THIRDPARTY_NAME)) |
|
241 | - { |
|
242 | - $newfiletmp = dol_sanitizeFileName(dol_string_nospecial($object->name)).'-'.$newfiletmp; |
|
243 | - } |
|
244 | - if ( ! empty($conf->global->MAIN_DOC_USE_TIMING)) |
|
245 | - { |
|
246 | - $format=$conf->global->MAIN_DOC_USE_TIMING; |
|
247 | - if ($format == '1') $format='%Y%m%d%H%M%S'; |
|
248 | - $filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat; |
|
249 | - } |
|
250 | - else |
|
251 | - { |
|
252 | - $filename=$newfiletmp.'.'.$newfileformat; |
|
253 | - } |
|
254 | - $file=$dir.'/'.$filename; |
|
255 | - $object->builddoc_filename=$filename; // For triggers |
|
256 | - //print "newfileformat=".$newfileformat; |
|
257 | - //print "newdir=".$dir; |
|
258 | - //print "newfile=".$newfile; |
|
259 | - //print "file=".$file; |
|
260 | - //print "conf->societe->dir_temp=".$conf->societe->dir_temp; |
|
261 | - //exit; |
|
262 | - |
|
263 | - dol_mkdir($conf->societe->multidir_temp[$object->entity]); |
|
264 | - |
|
265 | - // Open and load template |
|
266 | - require_once ODTPHP_PATH.'odf.php'; |
|
267 | - try { |
|
268 | - $odfHandler = new odf( |
|
269 | - $srctemplatepath, |
|
270 | - array( |
|
271 | - 'PATH_TO_TMP' => $conf->societe->multidir_temp[$object->entity], |
|
272 | - 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. |
|
273 | - 'DELIMITER_LEFT' => '{', |
|
274 | - 'DELIMITER_RIGHT' => '}' |
|
275 | - ) |
|
276 | - ); |
|
277 | - } |
|
278 | - catch(Exception $e) |
|
279 | - { |
|
280 | - $this->error=$e->getMessage(); |
|
281 | - dol_syslog($e->getMessage(), LOG_INFO); |
|
282 | - return -1; |
|
283 | - } |
|
284 | - //print $odfHandler->__toString()."\n"; |
|
209 | + if (! is_object($outputlangs)) $outputlangs=$langs; |
|
210 | + $sav_charset_output=$outputlangs->charset_output; |
|
211 | + $outputlangs->charset_output='UTF-8'; |
|
212 | + |
|
213 | + // Load translation files required by the page |
|
214 | + $outputlangs->loadLangs(array("main", "dict", "companies", "projects")); |
|
215 | + |
|
216 | + if ($conf->societe->multidir_output[$object->entity]) |
|
217 | + { |
|
218 | + $dir = $conf->societe->multidir_output[$object->entity]; |
|
219 | + $objectref = dol_sanitizeFileName($object->id); |
|
220 | + if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref; |
|
221 | + |
|
222 | + if (! file_exists($dir)) |
|
223 | + { |
|
224 | + if (dol_mkdir($dir) < 0) |
|
225 | + { |
|
226 | + $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
227 | + return -1; |
|
228 | + } |
|
229 | + } |
|
230 | + |
|
231 | + if (file_exists($dir)) |
|
232 | + { |
|
233 | + //print "srctemplatepath=".$srctemplatepath; // Src filename |
|
234 | + $newfile=basename($srctemplatepath); |
|
235 | + $newfiletmp=preg_replace('/\.od(s|t)/i','',$newfile); |
|
236 | + $newfiletmp=preg_replace('/template_/i','',$newfiletmp); |
|
237 | + $newfiletmp=preg_replace('/modele_/i','',$newfiletmp); |
|
238 | + // Get extension (ods or odt) |
|
239 | + $newfileformat=substr($newfile, strrpos($newfile, '.')+1); |
|
240 | + if ( ! empty($conf->global->MAIN_DOC_USE_OBJECT_THIRDPARTY_NAME)) |
|
241 | + { |
|
242 | + $newfiletmp = dol_sanitizeFileName(dol_string_nospecial($object->name)).'-'.$newfiletmp; |
|
243 | + } |
|
244 | + if ( ! empty($conf->global->MAIN_DOC_USE_TIMING)) |
|
245 | + { |
|
246 | + $format=$conf->global->MAIN_DOC_USE_TIMING; |
|
247 | + if ($format == '1') $format='%Y%m%d%H%M%S'; |
|
248 | + $filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat; |
|
249 | + } |
|
250 | + else |
|
251 | + { |
|
252 | + $filename=$newfiletmp.'.'.$newfileformat; |
|
253 | + } |
|
254 | + $file=$dir.'/'.$filename; |
|
255 | + $object->builddoc_filename=$filename; // For triggers |
|
256 | + //print "newfileformat=".$newfileformat; |
|
257 | + //print "newdir=".$dir; |
|
258 | + //print "newfile=".$newfile; |
|
259 | + //print "file=".$file; |
|
260 | + //print "conf->societe->dir_temp=".$conf->societe->dir_temp; |
|
261 | + //exit; |
|
262 | + |
|
263 | + dol_mkdir($conf->societe->multidir_temp[$object->entity]); |
|
264 | + |
|
265 | + // Open and load template |
|
266 | + require_once ODTPHP_PATH.'odf.php'; |
|
267 | + try { |
|
268 | + $odfHandler = new odf( |
|
269 | + $srctemplatepath, |
|
270 | + array( |
|
271 | + 'PATH_TO_TMP' => $conf->societe->multidir_temp[$object->entity], |
|
272 | + 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. |
|
273 | + 'DELIMITER_LEFT' => '{', |
|
274 | + 'DELIMITER_RIGHT' => '}' |
|
275 | + ) |
|
276 | + ); |
|
277 | + } |
|
278 | + catch(Exception $e) |
|
279 | + { |
|
280 | + $this->error=$e->getMessage(); |
|
281 | + dol_syslog($e->getMessage(), LOG_INFO); |
|
282 | + return -1; |
|
283 | + } |
|
284 | + //print $odfHandler->__toString()."\n"; |
|
285 | 285 | |
286 | 286 | // Replace tags of lines for contacts |
287 | 287 | $contact_arrray=array(); |
@@ -297,52 +297,52 @@ discard block |
||
297 | 297 | { |
298 | 298 | require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
299 | 299 | |
300 | - $i=0; |
|
301 | - $contactstatic = new Contact($this->db); |
|
300 | + $i=0; |
|
301 | + $contactstatic = new Contact($this->db); |
|
302 | 302 | |
303 | - while($i < $num) |
|
304 | - { |
|
305 | - $obj = $this->db->fetch_object($result); |
|
303 | + while($i < $num) |
|
304 | + { |
|
305 | + $obj = $this->db->fetch_object($result); |
|
306 | 306 | |
307 | - $contact_arrray[$i] = $obj->rowid; |
|
308 | - $i++; |
|
309 | - } |
|
307 | + $contact_arrray[$i] = $obj->rowid; |
|
308 | + $i++; |
|
309 | + } |
|
310 | 310 | } |
311 | 311 | if((is_array($contact_arrray) && count($contact_arrray) > 0)) |
312 | 312 | { |
313 | - try |
|
314 | - { |
|
315 | - $listlines = $odfHandler->setSegment('companycontacts'); |
|
316 | - |
|
317 | - foreach($contact_arrray as $array_key => $contact_id) |
|
318 | - { |
|
319 | - $res_contact = $contactstatic->fetch($contact_id); |
|
320 | - $tmparray=$this->get_substitutionarray_contact($contactstatic,$outputlangs,'contact'); |
|
321 | - foreach($tmparray as $key => $val) |
|
322 | - { |
|
323 | - try |
|
324 | - { |
|
325 | - $listlines->setVars($key, $val, true, 'UTF-8'); |
|
326 | - } |
|
327 | - catch(OdfException $e) |
|
328 | - { |
|
329 | - dol_syslog($e->getMessage(), LOG_INFO); |
|
330 | - } |
|
331 | - catch(SegmentException $e) |
|
332 | - { |
|
333 | - dol_syslog($e->getMessage(), LOG_INFO); |
|
334 | - } |
|
335 | - } |
|
336 | - $listlines->merge(); |
|
337 | - } |
|
338 | - $odfHandler->mergeSegment($listlines); |
|
339 | - } |
|
340 | - catch(OdfException $e) |
|
341 | - { |
|
342 | - $this->error=$e->getMessage(); |
|
343 | - dol_syslog($this->error, LOG_WARNING); |
|
344 | - //return -1; |
|
345 | - } |
|
313 | + try |
|
314 | + { |
|
315 | + $listlines = $odfHandler->setSegment('companycontacts'); |
|
316 | + |
|
317 | + foreach($contact_arrray as $array_key => $contact_id) |
|
318 | + { |
|
319 | + $res_contact = $contactstatic->fetch($contact_id); |
|
320 | + $tmparray=$this->get_substitutionarray_contact($contactstatic,$outputlangs,'contact'); |
|
321 | + foreach($tmparray as $key => $val) |
|
322 | + { |
|
323 | + try |
|
324 | + { |
|
325 | + $listlines->setVars($key, $val, true, 'UTF-8'); |
|
326 | + } |
|
327 | + catch(OdfException $e) |
|
328 | + { |
|
329 | + dol_syslog($e->getMessage(), LOG_INFO); |
|
330 | + } |
|
331 | + catch(SegmentException $e) |
|
332 | + { |
|
333 | + dol_syslog($e->getMessage(), LOG_INFO); |
|
334 | + } |
|
335 | + } |
|
336 | + $listlines->merge(); |
|
337 | + } |
|
338 | + $odfHandler->mergeSegment($listlines); |
|
339 | + } |
|
340 | + catch(OdfException $e) |
|
341 | + { |
|
342 | + $this->error=$e->getMessage(); |
|
343 | + dol_syslog($this->error, LOG_WARNING); |
|
344 | + //return -1; |
|
345 | + } |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | // Make substitutions into odt |
@@ -356,95 +356,95 @@ discard block |
||
356 | 356 | |
357 | 357 | // Call the ODTSubstitution hook |
358 | 358 | $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
359 | - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
359 | + $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
360 | 360 | |
361 | 361 | // Replace variables into document |
362 | - foreach($tmparray as $key=>$value) |
|
363 | - { |
|
364 | - try { |
|
365 | - if (preg_match('/logo$/',$key)) // Image |
|
366 | - { |
|
367 | - if (file_exists($value)) $odfHandler->setImage($key, $value); |
|
368 | - else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
|
369 | - } |
|
370 | - else // Text |
|
371 | - { |
|
372 | - $odfHandler->setVars($key, $value, true, 'UTF-8'); |
|
373 | - } |
|
374 | - } |
|
375 | - catch (OdfException $e) |
|
376 | - { |
|
377 | - // setVars failed, probably because key not found |
|
362 | + foreach($tmparray as $key=>$value) |
|
363 | + { |
|
364 | + try { |
|
365 | + if (preg_match('/logo$/',$key)) // Image |
|
366 | + { |
|
367 | + if (file_exists($value)) $odfHandler->setImage($key, $value); |
|
368 | + else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
|
369 | + } |
|
370 | + else // Text |
|
371 | + { |
|
372 | + $odfHandler->setVars($key, $value, true, 'UTF-8'); |
|
373 | + } |
|
374 | + } |
|
375 | + catch (OdfException $e) |
|
376 | + { |
|
377 | + // setVars failed, probably because key not found |
|
378 | 378 | dol_syslog($e->getMessage(), LOG_INFO); |
379 | - } |
|
380 | - } |
|
381 | - |
|
382 | - // Replace labels translated |
|
383 | - $tmparray=$outputlangs->get_translations_for_substitutions(); |
|
384 | - foreach($tmparray as $key=>$value) |
|
385 | - { |
|
386 | - try { |
|
387 | - $odfHandler->setVars($key, $value, true, 'UTF-8'); |
|
388 | - } |
|
389 | - catch (OdfException $e) |
|
390 | - { |
|
379 | + } |
|
380 | + } |
|
381 | + |
|
382 | + // Replace labels translated |
|
383 | + $tmparray=$outputlangs->get_translations_for_substitutions(); |
|
384 | + foreach($tmparray as $key=>$value) |
|
385 | + { |
|
386 | + try { |
|
387 | + $odfHandler->setVars($key, $value, true, 'UTF-8'); |
|
388 | + } |
|
389 | + catch (OdfException $e) |
|
390 | + { |
|
391 | 391 | dol_syslog($e->getMessage(), LOG_INFO); |
392 | - } |
|
393 | - } |
|
394 | - |
|
395 | - // Call the beforeODTSave hook |
|
396 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
397 | - $reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
398 | - |
|
399 | - // Write new file |
|
400 | - if (!empty($conf->global->MAIN_ODT_AS_PDF)) { |
|
401 | - try { |
|
402 | - $odfHandler->exportAsAttachedPDF($file); |
|
403 | - } catch (Exception $e) { |
|
404 | - $this->error=$e->getMessage(); |
|
392 | + } |
|
393 | + } |
|
394 | + |
|
395 | + // Call the beforeODTSave hook |
|
396 | + $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
397 | + $reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
398 | + |
|
399 | + // Write new file |
|
400 | + if (!empty($conf->global->MAIN_ODT_AS_PDF)) { |
|
401 | + try { |
|
402 | + $odfHandler->exportAsAttachedPDF($file); |
|
403 | + } catch (Exception $e) { |
|
404 | + $this->error=$e->getMessage(); |
|
405 | 405 | dol_syslog($e->getMessage(), LOG_INFO); |
406 | - return -1; |
|
407 | - } |
|
408 | - } |
|
409 | - else { |
|
410 | - try { |
|
411 | - $odfHandler->creator = $user->getFullName($outputlangs); |
|
412 | - $odfHandler->title = $object->builddoc_filename; |
|
413 | - $odfHandler->subject = $object->builddoc_filename; |
|
414 | - |
|
415 | - if (! empty($conf->global->ODT_ADD_DOLIBARR_ID)) |
|
416 | - { |
|
417 | - $odfHandler->userdefined['dol_id'] = $object->id; |
|
418 | - $odfHandler->userdefined['dol_element'] = $object->element; |
|
419 | - } |
|
420 | - |
|
421 | - $odfHandler->saveToDisk($file); |
|
422 | - }catch (Exception $e){ |
|
423 | - $this->error=$e->getMessage(); |
|
406 | + return -1; |
|
407 | + } |
|
408 | + } |
|
409 | + else { |
|
410 | + try { |
|
411 | + $odfHandler->creator = $user->getFullName($outputlangs); |
|
412 | + $odfHandler->title = $object->builddoc_filename; |
|
413 | + $odfHandler->subject = $object->builddoc_filename; |
|
414 | + |
|
415 | + if (! empty($conf->global->ODT_ADD_DOLIBARR_ID)) |
|
416 | + { |
|
417 | + $odfHandler->userdefined['dol_id'] = $object->id; |
|
418 | + $odfHandler->userdefined['dol_element'] = $object->element; |
|
419 | + } |
|
420 | + |
|
421 | + $odfHandler->saveToDisk($file); |
|
422 | + }catch (Exception $e){ |
|
423 | + $this->error=$e->getMessage(); |
|
424 | 424 | dol_syslog($e->getMessage(), LOG_INFO); |
425 | - return -1; |
|
426 | - } |
|
427 | - } |
|
428 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
429 | - $reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
430 | - |
|
431 | - if (! empty($conf->global->MAIN_UMASK)) |
|
432 | - @chmod($file, octdec($conf->global->MAIN_UMASK)); |
|
433 | - |
|
434 | - $odfHandler=null; // Destroy object |
|
435 | - |
|
436 | - $this->result = array('fullpath'=>$file); |
|
437 | - |
|
438 | - return 1; // Success |
|
439 | - } |
|
440 | - else |
|
441 | - { |
|
442 | - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
443 | - return -1; |
|
444 | - } |
|
445 | - } |
|
446 | - |
|
447 | - $this->error='UnknownError'; |
|
448 | - return -1; |
|
449 | - } |
|
425 | + return -1; |
|
426 | + } |
|
427 | + } |
|
428 | + $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
429 | + $reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
430 | + |
|
431 | + if (! empty($conf->global->MAIN_UMASK)) |
|
432 | + @chmod($file, octdec($conf->global->MAIN_UMASK)); |
|
433 | + |
|
434 | + $odfHandler=null; // Destroy object |
|
435 | + |
|
436 | + $this->result = array('fullpath'=>$file); |
|
437 | + |
|
438 | + return 1; // Success |
|
439 | + } |
|
440 | + else |
|
441 | + { |
|
442 | + $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
443 | + return -1; |
|
444 | + } |
|
445 | + } |
|
446 | + |
|
447 | + $this->error='UnknownError'; |
|
448 | + return -1; |
|
449 | + } |
|
450 | 450 | } |
@@ -59,28 +59,28 @@ discard block |
||
59 | 59 | global $conf, $langs, $mysoc; |
60 | 60 | |
61 | 61 | // Load translation files required by the page |
62 | - $langs->loadLangs(array("main","companies")); |
|
62 | + $langs->loadLangs(array("main", "companies")); |
|
63 | 63 | |
64 | 64 | $this->db = $db; |
65 | 65 | $this->name = "ODT templates"; |
66 | 66 | $this->description = $langs->trans("DocumentModelOdt"); |
67 | - $this->scandir = 'COMPANY_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan |
|
67 | + $this->scandir = 'COMPANY_ADDON_PDF_ODT_PATH'; // Name of constant that is used to save list of directories to scan |
|
68 | 68 | |
69 | 69 | // Dimension page pour format A4 |
70 | 70 | $this->type = 'odt'; |
71 | 71 | $this->page_largeur = 0; |
72 | 72 | $this->page_hauteur = 0; |
73 | - $this->format = array($this->page_largeur,$this->page_hauteur); |
|
74 | - $this->marge_gauche=0; |
|
75 | - $this->marge_droite=0; |
|
76 | - $this->marge_haute=0; |
|
77 | - $this->marge_basse=0; |
|
73 | + $this->format = array($this->page_largeur, $this->page_hauteur); |
|
74 | + $this->marge_gauche = 0; |
|
75 | + $this->marge_droite = 0; |
|
76 | + $this->marge_haute = 0; |
|
77 | + $this->marge_basse = 0; |
|
78 | 78 | |
79 | - $this->option_logo = 1; // Affiche logo |
|
79 | + $this->option_logo = 1; // Affiche logo |
|
80 | 80 | |
81 | 81 | // Recupere emmetteur |
82 | - $this->emetteur=$mysoc; |
|
83 | - if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // Par defaut, si n'etait pas defini |
|
82 | + $this->emetteur = $mysoc; |
|
83 | + if (!$this->emetteur->country_code) $this->emetteur->country_code = substr($langs->defaultlang, -2); // Par defaut, si n'etait pas defini |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | |
@@ -92,7 +92,7 @@ discard block |
||
92 | 92 | */ |
93 | 93 | function info($langs) |
94 | 94 | { |
95 | - global $conf,$langs; |
|
95 | + global $conf, $langs; |
|
96 | 96 | |
97 | 97 | // Load traductions files requiredby by page |
98 | 98 | $langs->loadLangs(array("companies", "errors")); |
@@ -100,76 +100,76 @@ discard block |
||
100 | 100 | $form = new Form($this->db); |
101 | 101 | |
102 | 102 | $texte = $this->description.".<br>\n"; |
103 | - $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
104 | - $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
105 | - $texte.= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
106 | - $texte.= '<input type="hidden" name="param1" value="COMPANY_ADDON_PDF_ODT_PATH">'; |
|
107 | - $texte.= '<table class="nobordernopadding" width="100%">'; |
|
103 | + $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
104 | + $texte .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
105 | + $texte .= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
106 | + $texte .= '<input type="hidden" name="param1" value="COMPANY_ADDON_PDF_ODT_PATH">'; |
|
107 | + $texte .= '<table class="nobordernopadding" width="100%">'; |
|
108 | 108 | |
109 | 109 | // List of directories area |
110 | - $texte.= '<tr><td>'; |
|
111 | - $texttitle=$langs->trans("ListOfDirectories"); |
|
112 | - $listofdir=explode(',',preg_replace('/[\r\n]+/',',',trim($conf->global->COMPANY_ADDON_PDF_ODT_PATH))); |
|
113 | - $listoffiles=array(); |
|
114 | - foreach($listofdir as $key=>$tmpdir) |
|
110 | + $texte .= '<tr><td>'; |
|
111 | + $texttitle = $langs->trans("ListOfDirectories"); |
|
112 | + $listofdir = explode(',', preg_replace('/[\r\n]+/', ',', trim($conf->global->COMPANY_ADDON_PDF_ODT_PATH))); |
|
113 | + $listoffiles = array(); |
|
114 | + foreach ($listofdir as $key=>$tmpdir) |
|
115 | 115 | { |
116 | - $tmpdir=trim($tmpdir); |
|
117 | - $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); |
|
118 | - if (! $tmpdir) { unset($listofdir[$key]); continue; } |
|
119 | - if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); |
|
116 | + $tmpdir = trim($tmpdir); |
|
117 | + $tmpdir = preg_replace('/DOL_DATA_ROOT/', DOL_DATA_ROOT, $tmpdir); |
|
118 | + if (!$tmpdir) { unset($listofdir[$key]); continue; } |
|
119 | + if (!is_dir($tmpdir)) $texttitle .= img_warning($langs->trans("ErrorDirNotFound", $tmpdir), 0); |
|
120 | 120 | else |
121 | 121 | { |
122 | - $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.od(s|t)$','','name',SORT_ASC,0,true); // Disable hook for the moment |
|
123 | - if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
122 | + $tmpfiles = dol_dir_list($tmpdir, 'files', 0, '\.od(s|t)$', '', 'name', SORT_ASC, 0, true); // Disable hook for the moment |
|
123 | + if (count($tmpfiles)) $listoffiles = array_merge($listoffiles, $tmpfiles); |
|
124 | 124 | } |
125 | 125 | } |
126 | - $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT"); |
|
126 | + $texthelp = $langs->trans("ListOfDirectoriesForModelGenODT"); |
|
127 | 127 | // Add list of substitution keys |
128 | - $texthelp.='<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>'; |
|
129 | - $texthelp.=$langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it |
|
130 | - |
|
131 | - $texte.= $form->textwithpicto($texttitle,$texthelp,1,'help','',1); |
|
132 | - $texte.= '<table><tr><td>'; |
|
133 | - $texte.= '<textarea class="flat" cols="60" name="value1">'; |
|
134 | - $texte.=$conf->global->COMPANY_ADDON_PDF_ODT_PATH; |
|
135 | - $texte.= '</textarea>'; |
|
136 | - $texte.= '</td>'; |
|
137 | - $texte.= '<td align="center"> '; |
|
138 | - $texte.= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">'; |
|
139 | - $texte.= '</td>'; |
|
140 | - $texte.= '</tr>'; |
|
141 | - $texte.= '</table>'; |
|
128 | + $texthelp .= '<br>'.$langs->trans("FollowingSubstitutionKeysCanBeUsed").'<br>'; |
|
129 | + $texthelp .= $langs->transnoentitiesnoconv("FullListOnOnlineDocumentation"); // This contains an url, we don't modify it |
|
130 | + |
|
131 | + $texte .= $form->textwithpicto($texttitle, $texthelp, 1, 'help', '', 1); |
|
132 | + $texte .= '<table><tr><td>'; |
|
133 | + $texte .= '<textarea class="flat" cols="60" name="value1">'; |
|
134 | + $texte .= $conf->global->COMPANY_ADDON_PDF_ODT_PATH; |
|
135 | + $texte .= '</textarea>'; |
|
136 | + $texte .= '</td>'; |
|
137 | + $texte .= '<td align="center"> '; |
|
138 | + $texte .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button">'; |
|
139 | + $texte .= '</td>'; |
|
140 | + $texte .= '</tr>'; |
|
141 | + $texte .= '</table>'; |
|
142 | 142 | |
143 | 143 | // Scan directories |
144 | - $nbofiles=count($listoffiles); |
|
145 | - if (! empty($conf->global->COMPANY_ADDON_PDF_ODT_PATH)) |
|
144 | + $nbofiles = count($listoffiles); |
|
145 | + if (!empty($conf->global->COMPANY_ADDON_PDF_ODT_PATH)) |
|
146 | 146 | { |
147 | - $texte.=$langs->trans("NumberOfModelFilesFound").': <b>'; |
|
147 | + $texte .= $langs->trans("NumberOfModelFilesFound").': <b>'; |
|
148 | 148 | //$texte.=$nbofiles?'<a id="a_'.get_class($this).'" href="#">':''; |
149 | - $texte.=$nbofiles; |
|
149 | + $texte .= $nbofiles; |
|
150 | 150 | //$texte.=$nbofiles?'</a>':''; |
151 | - $texte.='</b>'; |
|
151 | + $texte .= '</b>'; |
|
152 | 152 | } |
153 | 153 | |
154 | 154 | if ($nbofiles) |
155 | 155 | { |
156 | - $texte.='<div id="div_'.get_class($this).'" class="hidden">'; |
|
157 | - foreach($listoffiles as $file) |
|
156 | + $texte .= '<div id="div_'.get_class($this).'" class="hidden">'; |
|
157 | + foreach ($listoffiles as $file) |
|
158 | 158 | { |
159 | - $texte.=$file['name'].'<br>'; |
|
159 | + $texte .= $file['name'].'<br>'; |
|
160 | 160 | } |
161 | - $texte.='<div id="div_'.get_class($this).'">'; |
|
161 | + $texte .= '<div id="div_'.get_class($this).'">'; |
|
162 | 162 | } |
163 | 163 | |
164 | - $texte.= '</td>'; |
|
164 | + $texte .= '</td>'; |
|
165 | 165 | |
166 | - $texte.= '<td valign="top" rowspan="2" class="hideonsmartphone">'; |
|
167 | - $texte.= $langs->trans("ExampleOfDirectoriesForModelGen"); |
|
168 | - $texte.= '</td>'; |
|
169 | - $texte.= '</tr>'; |
|
166 | + $texte .= '<td valign="top" rowspan="2" class="hideonsmartphone">'; |
|
167 | + $texte .= $langs->trans("ExampleOfDirectoriesForModelGen"); |
|
168 | + $texte .= '</td>'; |
|
169 | + $texte .= '</tr>'; |
|
170 | 170 | |
171 | - $texte.= '</table>'; |
|
172 | - $texte.= '</form>'; |
|
171 | + $texte .= '</table>'; |
|
172 | + $texte .= '</form>'; |
|
173 | 173 | |
174 | 174 | return $texte; |
175 | 175 | } |
@@ -186,10 +186,10 @@ discard block |
||
186 | 186 | * @param int $hideref Do not show ref |
187 | 187 | * @return int 1 if OK, <=0 if KO |
188 | 188 | */ |
189 | - function write_file($object,$outputlangs,$srctemplatepath,$hidedetails=0,$hidedesc=0,$hideref=0) |
|
189 | + function write_file($object, $outputlangs, $srctemplatepath, $hidedetails = 0, $hidedesc = 0, $hideref = 0) |
|
190 | 190 | { |
191 | 191 | // phpcs:enable |
192 | - global $user,$langs,$conf,$mysoc,$hookmanager; |
|
192 | + global $user, $langs, $conf, $mysoc, $hookmanager; |
|
193 | 193 | |
194 | 194 | if (empty($srctemplatepath)) |
195 | 195 | { |
@@ -198,17 +198,17 @@ discard block |
||
198 | 198 | } |
199 | 199 | |
200 | 200 | // Add odtgeneration hook |
201 | - if (! is_object($hookmanager)) |
|
201 | + if (!is_object($hookmanager)) |
|
202 | 202 | { |
203 | 203 | include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; |
204 | - $hookmanager=new HookManager($this->db); |
|
204 | + $hookmanager = new HookManager($this->db); |
|
205 | 205 | } |
206 | 206 | $hookmanager->initHooks(array('odtgeneration')); |
207 | 207 | global $action; |
208 | 208 | |
209 | - if (! is_object($outputlangs)) $outputlangs=$langs; |
|
210 | - $sav_charset_output=$outputlangs->charset_output; |
|
211 | - $outputlangs->charset_output='UTF-8'; |
|
209 | + if (!is_object($outputlangs)) $outputlangs = $langs; |
|
210 | + $sav_charset_output = $outputlangs->charset_output; |
|
211 | + $outputlangs->charset_output = 'UTF-8'; |
|
212 | 212 | |
213 | 213 | // Load translation files required by the page |
214 | 214 | $outputlangs->loadLangs(array("main", "dict", "companies", "projects")); |
@@ -217,13 +217,13 @@ discard block |
||
217 | 217 | { |
218 | 218 | $dir = $conf->societe->multidir_output[$object->entity]; |
219 | 219 | $objectref = dol_sanitizeFileName($object->id); |
220 | - if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref; |
|
220 | + if (!preg_match('/specimen/i', $objectref)) $dir .= "/".$objectref; |
|
221 | 221 | |
222 | - if (! file_exists($dir)) |
|
222 | + if (!file_exists($dir)) |
|
223 | 223 | { |
224 | 224 | if (dol_mkdir($dir) < 0) |
225 | 225 | { |
226 | - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
226 | + $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); |
|
227 | 227 | return -1; |
228 | 228 | } |
229 | 229 | } |
@@ -231,28 +231,28 @@ discard block |
||
231 | 231 | if (file_exists($dir)) |
232 | 232 | { |
233 | 233 | //print "srctemplatepath=".$srctemplatepath; // Src filename |
234 | - $newfile=basename($srctemplatepath); |
|
235 | - $newfiletmp=preg_replace('/\.od(s|t)/i','',$newfile); |
|
236 | - $newfiletmp=preg_replace('/template_/i','',$newfiletmp); |
|
237 | - $newfiletmp=preg_replace('/modele_/i','',$newfiletmp); |
|
234 | + $newfile = basename($srctemplatepath); |
|
235 | + $newfiletmp = preg_replace('/\.od(s|t)/i', '', $newfile); |
|
236 | + $newfiletmp = preg_replace('/template_/i', '', $newfiletmp); |
|
237 | + $newfiletmp = preg_replace('/modele_/i', '', $newfiletmp); |
|
238 | 238 | // Get extension (ods or odt) |
239 | - $newfileformat=substr($newfile, strrpos($newfile, '.')+1); |
|
240 | - if ( ! empty($conf->global->MAIN_DOC_USE_OBJECT_THIRDPARTY_NAME)) |
|
239 | + $newfileformat = substr($newfile, strrpos($newfile, '.') + 1); |
|
240 | + if (!empty($conf->global->MAIN_DOC_USE_OBJECT_THIRDPARTY_NAME)) |
|
241 | 241 | { |
242 | 242 | $newfiletmp = dol_sanitizeFileName(dol_string_nospecial($object->name)).'-'.$newfiletmp; |
243 | 243 | } |
244 | - if ( ! empty($conf->global->MAIN_DOC_USE_TIMING)) |
|
244 | + if (!empty($conf->global->MAIN_DOC_USE_TIMING)) |
|
245 | 245 | { |
246 | - $format=$conf->global->MAIN_DOC_USE_TIMING; |
|
247 | - if ($format == '1') $format='%Y%m%d%H%M%S'; |
|
248 | - $filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat; |
|
246 | + $format = $conf->global->MAIN_DOC_USE_TIMING; |
|
247 | + if ($format == '1') $format = '%Y%m%d%H%M%S'; |
|
248 | + $filename = $newfiletmp.'-'.dol_print_date(dol_now(), $format).'.'.$newfileformat; |
|
249 | 249 | } |
250 | 250 | else |
251 | 251 | { |
252 | - $filename=$newfiletmp.'.'.$newfileformat; |
|
252 | + $filename = $newfiletmp.'.'.$newfileformat; |
|
253 | 253 | } |
254 | - $file=$dir.'/'.$filename; |
|
255 | - $object->builddoc_filename=$filename; // For triggers |
|
254 | + $file = $dir.'/'.$filename; |
|
255 | + $object->builddoc_filename = $filename; // For triggers |
|
256 | 256 | //print "newfileformat=".$newfileformat; |
257 | 257 | //print "newdir=".$dir; |
258 | 258 | //print "newfile=".$newfile; |
@@ -269,22 +269,22 @@ discard block |
||
269 | 269 | $srctemplatepath, |
270 | 270 | array( |
271 | 271 | 'PATH_TO_TMP' => $conf->societe->multidir_temp[$object->entity], |
272 | - 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. |
|
272 | + 'ZIP_PROXY' => 'PclZipProxy', // PhpZipProxy or PclZipProxy. Got "bad compression method" error when using PhpZipProxy. |
|
273 | 273 | 'DELIMITER_LEFT' => '{', |
274 | 274 | 'DELIMITER_RIGHT' => '}' |
275 | 275 | ) |
276 | 276 | ); |
277 | 277 | } |
278 | - catch(Exception $e) |
|
278 | + catch (Exception $e) |
|
279 | 279 | { |
280 | - $this->error=$e->getMessage(); |
|
280 | + $this->error = $e->getMessage(); |
|
281 | 281 | dol_syslog($e->getMessage(), LOG_INFO); |
282 | 282 | return -1; |
283 | 283 | } |
284 | 284 | //print $odfHandler->__toString()."\n"; |
285 | 285 | |
286 | 286 | // Replace tags of lines for contacts |
287 | - $contact_arrray=array(); |
|
287 | + $contact_arrray = array(); |
|
288 | 288 | |
289 | 289 | $sql = "SELECT p.rowid"; |
290 | 290 | $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p"; |
@@ -297,10 +297,10 @@ discard block |
||
297 | 297 | { |
298 | 298 | require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
299 | 299 | |
300 | - $i=0; |
|
300 | + $i = 0; |
|
301 | 301 | $contactstatic = new Contact($this->db); |
302 | 302 | |
303 | - while($i < $num) |
|
303 | + while ($i < $num) |
|
304 | 304 | { |
305 | 305 | $obj = $this->db->fetch_object($result); |
306 | 306 | |
@@ -308,27 +308,27 @@ discard block |
||
308 | 308 | $i++; |
309 | 309 | } |
310 | 310 | } |
311 | - if((is_array($contact_arrray) && count($contact_arrray) > 0)) |
|
311 | + if ((is_array($contact_arrray) && count($contact_arrray) > 0)) |
|
312 | 312 | { |
313 | 313 | try |
314 | 314 | { |
315 | 315 | $listlines = $odfHandler->setSegment('companycontacts'); |
316 | 316 | |
317 | - foreach($contact_arrray as $array_key => $contact_id) |
|
317 | + foreach ($contact_arrray as $array_key => $contact_id) |
|
318 | 318 | { |
319 | 319 | $res_contact = $contactstatic->fetch($contact_id); |
320 | - $tmparray=$this->get_substitutionarray_contact($contactstatic,$outputlangs,'contact'); |
|
321 | - foreach($tmparray as $key => $val) |
|
320 | + $tmparray = $this->get_substitutionarray_contact($contactstatic, $outputlangs, 'contact'); |
|
321 | + foreach ($tmparray as $key => $val) |
|
322 | 322 | { |
323 | 323 | try |
324 | 324 | { |
325 | 325 | $listlines->setVars($key, $val, true, 'UTF-8'); |
326 | 326 | } |
327 | - catch(OdfException $e) |
|
327 | + catch (OdfException $e) |
|
328 | 328 | { |
329 | 329 | dol_syslog($e->getMessage(), LOG_INFO); |
330 | 330 | } |
331 | - catch(SegmentException $e) |
|
331 | + catch (SegmentException $e) |
|
332 | 332 | { |
333 | 333 | dol_syslog($e->getMessage(), LOG_INFO); |
334 | 334 | } |
@@ -337,32 +337,32 @@ discard block |
||
337 | 337 | } |
338 | 338 | $odfHandler->mergeSegment($listlines); |
339 | 339 | } |
340 | - catch(OdfException $e) |
|
340 | + catch (OdfException $e) |
|
341 | 341 | { |
342 | - $this->error=$e->getMessage(); |
|
342 | + $this->error = $e->getMessage(); |
|
343 | 343 | dol_syslog($this->error, LOG_WARNING); |
344 | 344 | //return -1; |
345 | 345 | } |
346 | 346 | } |
347 | 347 | |
348 | 348 | // Make substitutions into odt |
349 | - $array_user=$this->get_substitutionarray_user($user,$outputlangs); |
|
350 | - $array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs); |
|
351 | - $array_thirdparty=$this->get_substitutionarray_thirdparty($object,$outputlangs); |
|
352 | - $array_other=$this->get_substitutionarray_other($outputlangs); |
|
349 | + $array_user = $this->get_substitutionarray_user($user, $outputlangs); |
|
350 | + $array_soc = $this->get_substitutionarray_mysoc($mysoc, $outputlangs); |
|
351 | + $array_thirdparty = $this->get_substitutionarray_thirdparty($object, $outputlangs); |
|
352 | + $array_other = $this->get_substitutionarray_other($outputlangs); |
|
353 | 353 | |
354 | - $tmparray = array_merge($array_user,$array_soc,$array_thirdparty,$array_other); |
|
354 | + $tmparray = array_merge($array_user, $array_soc, $array_thirdparty, $array_other); |
|
355 | 355 | complete_substitutions_array($tmparray, $outputlangs, $object); |
356 | 356 | |
357 | 357 | // Call the ODTSubstitution hook |
358 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
359 | - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
358 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); |
|
359 | + $reshook = $hookmanager->executeHooks('ODTSubstitution', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
360 | 360 | |
361 | 361 | // Replace variables into document |
362 | - foreach($tmparray as $key=>$value) |
|
362 | + foreach ($tmparray as $key=>$value) |
|
363 | 363 | { |
364 | 364 | try { |
365 | - if (preg_match('/logo$/',$key)) // Image |
|
365 | + if (preg_match('/logo$/', $key)) // Image |
|
366 | 366 | { |
367 | 367 | if (file_exists($value)) $odfHandler->setImage($key, $value); |
368 | 368 | else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
@@ -380,8 +380,8 @@ discard block |
||
380 | 380 | } |
381 | 381 | |
382 | 382 | // Replace labels translated |
383 | - $tmparray=$outputlangs->get_translations_for_substitutions(); |
|
384 | - foreach($tmparray as $key=>$value) |
|
383 | + $tmparray = $outputlangs->get_translations_for_substitutions(); |
|
384 | + foreach ($tmparray as $key=>$value) |
|
385 | 385 | { |
386 | 386 | try { |
387 | 387 | $odfHandler->setVars($key, $value, true, 'UTF-8'); |
@@ -393,15 +393,15 @@ discard block |
||
393 | 393 | } |
394 | 394 | |
395 | 395 | // Call the beforeODTSave hook |
396 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
397 | - $reshook=$hookmanager->executeHooks('beforeODTSave',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
396 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); |
|
397 | + $reshook = $hookmanager->executeHooks('beforeODTSave', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
398 | 398 | |
399 | 399 | // Write new file |
400 | 400 | if (!empty($conf->global->MAIN_ODT_AS_PDF)) { |
401 | 401 | try { |
402 | 402 | $odfHandler->exportAsAttachedPDF($file); |
403 | 403 | } catch (Exception $e) { |
404 | - $this->error=$e->getMessage(); |
|
404 | + $this->error = $e->getMessage(); |
|
405 | 405 | dol_syslog($e->getMessage(), LOG_INFO); |
406 | 406 | return -1; |
407 | 407 | } |
@@ -412,39 +412,39 @@ discard block |
||
412 | 412 | $odfHandler->title = $object->builddoc_filename; |
413 | 413 | $odfHandler->subject = $object->builddoc_filename; |
414 | 414 | |
415 | - if (! empty($conf->global->ODT_ADD_DOLIBARR_ID)) |
|
415 | + if (!empty($conf->global->ODT_ADD_DOLIBARR_ID)) |
|
416 | 416 | { |
417 | 417 | $odfHandler->userdefined['dol_id'] = $object->id; |
418 | 418 | $odfHandler->userdefined['dol_element'] = $object->element; |
419 | 419 | } |
420 | 420 | |
421 | 421 | $odfHandler->saveToDisk($file); |
422 | - }catch (Exception $e){ |
|
423 | - $this->error=$e->getMessage(); |
|
422 | + } catch (Exception $e) { |
|
423 | + $this->error = $e->getMessage(); |
|
424 | 424 | dol_syslog($e->getMessage(), LOG_INFO); |
425 | 425 | return -1; |
426 | 426 | } |
427 | 427 | } |
428 | - $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
|
429 | - $reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
|
428 | + $parameters = array('odfHandler'=>&$odfHandler, 'file'=>$file, 'object'=>$object, 'outputlangs'=>$outputlangs, 'substitutionarray'=>&$tmparray); |
|
429 | + $reshook = $hookmanager->executeHooks('afterODTCreation', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks |
|
430 | 430 | |
431 | - if (! empty($conf->global->MAIN_UMASK)) |
|
431 | + if (!empty($conf->global->MAIN_UMASK)) |
|
432 | 432 | @chmod($file, octdec($conf->global->MAIN_UMASK)); |
433 | 433 | |
434 | - $odfHandler=null; // Destroy object |
|
434 | + $odfHandler = null; // Destroy object |
|
435 | 435 | |
436 | 436 | $this->result = array('fullpath'=>$file); |
437 | 437 | |
438 | - return 1; // Success |
|
438 | + return 1; // Success |
|
439 | 439 | } |
440 | 440 | else |
441 | 441 | { |
442 | - $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
|
442 | + $this->error = $langs->transnoentities("ErrorCanNotCreateDir", $dir); |
|
443 | 443 | return -1; |
444 | 444 | } |
445 | 445 | } |
446 | 446 | |
447 | - $this->error='UnknownError'; |
|
447 | + $this->error = 'UnknownError'; |
|
448 | 448 | return -1; |
449 | 449 | } |
450 | 450 | } |
@@ -80,7 +80,10 @@ discard block |
||
80 | 80 | |
81 | 81 | // Recupere emmetteur |
82 | 82 | $this->emetteur=$mysoc; |
83 | - if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // Par defaut, si n'etait pas defini |
|
83 | + if (! $this->emetteur->country_code) { |
|
84 | + $this->emetteur->country_code=substr($langs->defaultlang,-2); |
|
85 | + } |
|
86 | + // Par defaut, si n'etait pas defini |
|
84 | 87 | } |
85 | 88 | |
86 | 89 | |
@@ -116,11 +119,14 @@ discard block |
||
116 | 119 | $tmpdir=trim($tmpdir); |
117 | 120 | $tmpdir=preg_replace('/DOL_DATA_ROOT/',DOL_DATA_ROOT,$tmpdir); |
118 | 121 | if (! $tmpdir) { unset($listofdir[$key]); continue; } |
119 | - if (! is_dir($tmpdir)) $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); |
|
120 | - else |
|
122 | + if (! is_dir($tmpdir)) { |
|
123 | + $texttitle.=img_warning($langs->trans("ErrorDirNotFound",$tmpdir),0); |
|
124 | + } else |
|
121 | 125 | { |
122 | 126 | $tmpfiles=dol_dir_list($tmpdir,'files',0,'\.od(s|t)$','','name',SORT_ASC,0,true); // Disable hook for the moment |
123 | - if (count($tmpfiles)) $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
127 | + if (count($tmpfiles)) { |
|
128 | + $listoffiles=array_merge($listoffiles,$tmpfiles); |
|
129 | + } |
|
124 | 130 | } |
125 | 131 | } |
126 | 132 | $texthelp=$langs->trans("ListOfDirectoriesForModelGenODT"); |
@@ -206,7 +212,9 @@ discard block |
||
206 | 212 | $hookmanager->initHooks(array('odtgeneration')); |
207 | 213 | global $action; |
208 | 214 | |
209 | - if (! is_object($outputlangs)) $outputlangs=$langs; |
|
215 | + if (! is_object($outputlangs)) { |
|
216 | + $outputlangs=$langs; |
|
217 | + } |
|
210 | 218 | $sav_charset_output=$outputlangs->charset_output; |
211 | 219 | $outputlangs->charset_output='UTF-8'; |
212 | 220 | |
@@ -217,7 +225,9 @@ discard block |
||
217 | 225 | { |
218 | 226 | $dir = $conf->societe->multidir_output[$object->entity]; |
219 | 227 | $objectref = dol_sanitizeFileName($object->id); |
220 | - if (! preg_match('/specimen/i',$objectref)) $dir.= "/" . $objectref; |
|
228 | + if (! preg_match('/specimen/i',$objectref)) { |
|
229 | + $dir.= "/" . $objectref; |
|
230 | + } |
|
221 | 231 | |
222 | 232 | if (! file_exists($dir)) |
223 | 233 | { |
@@ -244,10 +254,11 @@ discard block |
||
244 | 254 | if ( ! empty($conf->global->MAIN_DOC_USE_TIMING)) |
245 | 255 | { |
246 | 256 | $format=$conf->global->MAIN_DOC_USE_TIMING; |
247 | - if ($format == '1') $format='%Y%m%d%H%M%S'; |
|
257 | + if ($format == '1') { |
|
258 | + $format='%Y%m%d%H%M%S'; |
|
259 | + } |
|
248 | 260 | $filename=$newfiletmp.'-'.dol_print_date(dol_now(),$format).'.'.$newfileformat; |
249 | - } |
|
250 | - else |
|
261 | + } else |
|
251 | 262 | { |
252 | 263 | $filename=$newfiletmp.'.'.$newfileformat; |
253 | 264 | } |
@@ -274,8 +285,7 @@ discard block |
||
274 | 285 | 'DELIMITER_RIGHT' => '}' |
275 | 286 | ) |
276 | 287 | ); |
277 | - } |
|
278 | - catch(Exception $e) |
|
288 | + } catch(Exception $e) |
|
279 | 289 | { |
280 | 290 | $this->error=$e->getMessage(); |
281 | 291 | dol_syslog($e->getMessage(), LOG_INFO); |
@@ -323,12 +333,10 @@ discard block |
||
323 | 333 | try |
324 | 334 | { |
325 | 335 | $listlines->setVars($key, $val, true, 'UTF-8'); |
326 | - } |
|
327 | - catch(OdfException $e) |
|
336 | + } catch(OdfException $e) |
|
328 | 337 | { |
329 | 338 | dol_syslog($e->getMessage(), LOG_INFO); |
330 | - } |
|
331 | - catch(SegmentException $e) |
|
339 | + } catch(SegmentException $e) |
|
332 | 340 | { |
333 | 341 | dol_syslog($e->getMessage(), LOG_INFO); |
334 | 342 | } |
@@ -336,8 +344,7 @@ discard block |
||
336 | 344 | $listlines->merge(); |
337 | 345 | } |
338 | 346 | $odfHandler->mergeSegment($listlines); |
339 | - } |
|
340 | - catch(OdfException $e) |
|
347 | + } catch(OdfException $e) |
|
341 | 348 | { |
342 | 349 | $this->error=$e->getMessage(); |
343 | 350 | dol_syslog($this->error, LOG_WARNING); |
@@ -362,17 +369,18 @@ discard block |
||
362 | 369 | foreach($tmparray as $key=>$value) |
363 | 370 | { |
364 | 371 | try { |
365 | - if (preg_match('/logo$/',$key)) // Image |
|
372 | + if (preg_match('/logo$/',$key)) { |
|
373 | + // Image |
|
366 | 374 | { |
367 | 375 | if (file_exists($value)) $odfHandler->setImage($key, $value); |
368 | - else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
|
369 | - } |
|
370 | - else // Text |
|
376 | + } else { |
|
377 | + $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); |
|
378 | + } |
|
379 | + } else // Text |
|
371 | 380 | { |
372 | 381 | $odfHandler->setVars($key, $value, true, 'UTF-8'); |
373 | 382 | } |
374 | - } |
|
375 | - catch (OdfException $e) |
|
383 | + } catch (OdfException $e) |
|
376 | 384 | { |
377 | 385 | // setVars failed, probably because key not found |
378 | 386 | dol_syslog($e->getMessage(), LOG_INFO); |
@@ -385,8 +393,7 @@ discard block |
||
385 | 393 | { |
386 | 394 | try { |
387 | 395 | $odfHandler->setVars($key, $value, true, 'UTF-8'); |
388 | - } |
|
389 | - catch (OdfException $e) |
|
396 | + } catch (OdfException $e) |
|
390 | 397 | { |
391 | 398 | dol_syslog($e->getMessage(), LOG_INFO); |
392 | 399 | } |
@@ -405,8 +412,7 @@ discard block |
||
405 | 412 | dol_syslog($e->getMessage(), LOG_INFO); |
406 | 413 | return -1; |
407 | 414 | } |
408 | - } |
|
409 | - else { |
|
415 | + } else { |
|
410 | 416 | try { |
411 | 417 | $odfHandler->creator = $user->getFullName($outputlangs); |
412 | 418 | $odfHandler->title = $object->builddoc_filename; |
@@ -419,7 +425,7 @@ discard block |
||
419 | 425 | } |
420 | 426 | |
421 | 427 | $odfHandler->saveToDisk($file); |
422 | - }catch (Exception $e){ |
|
428 | + } catch (Exception $e){ |
|
423 | 429 | $this->error=$e->getMessage(); |
424 | 430 | dol_syslog($e->getMessage(), LOG_INFO); |
425 | 431 | return -1; |
@@ -428,16 +434,16 @@ discard block |
||
428 | 434 | $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); |
429 | 435 | $reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks |
430 | 436 | |
431 | - if (! empty($conf->global->MAIN_UMASK)) |
|
432 | - @chmod($file, octdec($conf->global->MAIN_UMASK)); |
|
437 | + if (! empty($conf->global->MAIN_UMASK)) { |
|
438 | + @chmod($file, octdec($conf->global->MAIN_UMASK)); |
|
439 | + } |
|
433 | 440 | |
434 | 441 | $odfHandler=null; // Destroy object |
435 | 442 | |
436 | 443 | $this->result = array('fullpath'=>$file); |
437 | 444 | |
438 | 445 | return 1; // Success |
439 | - } |
|
440 | - else |
|
446 | + } else |
|
441 | 447 | { |
442 | 448 | $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); |
443 | 449 | return -1; |
@@ -34,9 +34,9 @@ discard block |
||
34 | 34 | abstract class ModeleThirdPartyDoc extends CommonDocGenerator |
35 | 35 | { |
36 | 36 | /** |
37 | - * @var string Error code (or message) |
|
38 | - */ |
|
39 | - public $error=''; |
|
37 | + * @var string Error code (or message) |
|
38 | + */ |
|
39 | + public $error=''; |
|
40 | 40 | |
41 | 41 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
42 | 42 | /** |
@@ -69,8 +69,8 @@ discard block |
||
69 | 69 | { |
70 | 70 | /** |
71 | 71 | * @var string Error code (or message) |
72 | - */ |
|
73 | - public $error=''; |
|
72 | + */ |
|
73 | + public $error=''; |
|
74 | 74 | |
75 | 75 | /** Renvoi la description par defaut du modele de numerotation |
76 | 76 | * |
@@ -246,10 +246,10 @@ discard block |
||
246 | 246 | } |
247 | 247 | |
248 | 248 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
249 | - /** |
|
250 | - * Check if mask/numbering use prefix |
|
251 | - * |
|
252 | - * @return int 0=no, 1=yes |
|
249 | + /** |
|
250 | + * Check if mask/numbering use prefix |
|
251 | + * |
|
252 | + * @return int 0=no, 1=yes |
|
253 | 253 | */ |
254 | 254 | function verif_prefixIsUsed() |
255 | 255 | { |
@@ -266,9 +266,9 @@ discard block |
||
266 | 266 | abstract class ModeleAccountancyCode |
267 | 267 | { |
268 | 268 | /** |
269 | - * @var string Error code (or message) |
|
270 | - */ |
|
271 | - public $error=''; |
|
269 | + * @var string Error code (or message) |
|
270 | + */ |
|
271 | + public $error=''; |
|
272 | 272 | |
273 | 273 | |
274 | 274 | /** Return description of module |
@@ -397,7 +397,7 @@ discard block |
||
397 | 397 | function thirdparty_doc_create(DoliDB $db, Societe $object, $message, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0) |
398 | 398 | { |
399 | 399 | // phpcs:enable |
400 | - dol_syslog(__METHOD__ . " is deprecated", LOG_WARNING); |
|
400 | + dol_syslog(__METHOD__ . " is deprecated", LOG_WARNING); |
|
401 | 401 | |
402 | - return $object->generateDocument($modele, $outputlangs, $hidedetails, $hidedesc, $hideref); |
|
402 | + return $object->generateDocument($modele, $outputlangs, $hidedetails, $hidedesc, $hideref); |
|
403 | 403 | } |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | /** |
37 | 37 | * @var string Error code (or message) |
38 | 38 | */ |
39 | - public $error=''; |
|
39 | + public $error = ''; |
|
40 | 40 | |
41 | 41 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
42 | 42 | /** |
@@ -46,16 +46,16 @@ discard block |
||
46 | 46 | * @param integer $maxfilenamelength Max length of value to show |
47 | 47 | * @return array List of templates |
48 | 48 | */ |
49 | - static function liste_modeles($db,$maxfilenamelength=0) |
|
49 | + static function liste_modeles($db, $maxfilenamelength = 0) |
|
50 | 50 | { |
51 | 51 | // phpcs:enable |
52 | 52 | global $conf; |
53 | 53 | |
54 | - $type='company'; |
|
55 | - $liste=array(); |
|
54 | + $type = 'company'; |
|
55 | + $liste = array(); |
|
56 | 56 | |
57 | 57 | include_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; |
58 | - $liste = getListOfModels($db,$type,$maxfilenamelength); |
|
58 | + $liste = getListOfModels($db, $type, $maxfilenamelength); |
|
59 | 59 | |
60 | 60 | return $liste; |
61 | 61 | } |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | /** |
71 | 71 | * @var string Error code (or message) |
72 | 72 | */ |
73 | - public $error=''; |
|
73 | + public $error = ''; |
|
74 | 74 | |
75 | 75 | /** Renvoi la description par defaut du modele de numerotation |
76 | 76 | * |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | * @param int $type Type |
123 | 123 | * @return string Value |
124 | 124 | */ |
125 | - function getNextValue($objsoc=0,$type=-1) |
|
125 | + function getNextValue($objsoc = 0, $type = -1) |
|
126 | 126 | { |
127 | 127 | global $langs; |
128 | 128 | return $langs->trans("Function_getNextValue_InModuleNotWorking"); |
@@ -153,11 +153,11 @@ discard block |
||
153 | 153 | * @param integer $maxfilenamelength Max length of value to show |
154 | 154 | * @return array List of numbers |
155 | 155 | */ |
156 | - static function liste_modeles($db,$maxfilenamelength=0) |
|
156 | + static function liste_modeles($db, $maxfilenamelength = 0) |
|
157 | 157 | { |
158 | 158 | // phpcs:enable |
159 | - $liste=array(); |
|
160 | - $sql =""; |
|
159 | + $liste = array(); |
|
160 | + $sql = ""; |
|
161 | 161 | |
162 | 162 | $resql = $db->query($sql); |
163 | 163 | if ($resql) |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | while ($i < $num) |
168 | 168 | { |
169 | 169 | $row = $db->fetch_row($resql); |
170 | - $liste[$row[0]]=$row[1]; |
|
170 | + $liste[$row[0]] = $row[1]; |
|
171 | 171 | $i++; |
172 | 172 | } |
173 | 173 | } |
@@ -186,61 +186,61 @@ discard block |
||
186 | 186 | * @param int $type -1=Nothing, 0=Customer, 1=Supplier |
187 | 187 | * @return string HTML translated description |
188 | 188 | */ |
189 | - function getToolTip($langs,$soc,$type) |
|
189 | + function getToolTip($langs, $soc, $type) |
|
190 | 190 | { |
191 | 191 | global $conf; |
192 | 192 | |
193 | 193 | $langs->load("admin"); |
194 | 194 | |
195 | - $s=''; |
|
196 | - if ($type == -1) $s.=$langs->trans("Name").': <b>'.$this->getNom($langs).'</b><br>'; |
|
197 | - if ($type == -1) $s.=$langs->trans("Version").': <b>'.$this->getVersion().'</b><br>'; |
|
198 | - if ($type == 0) $s.=$langs->trans("CustomerCodeDesc").'<br>'; |
|
199 | - if ($type == 1) $s.=$langs->trans("SupplierCodeDesc").'<br>'; |
|
200 | - if ($type != -1) $s.=$langs->trans("ValidityControledByModule").': <b>'.$this->getNom($langs).'</b><br>'; |
|
201 | - $s.='<br>'; |
|
202 | - $s.='<u>'.$langs->trans("ThisIsModuleRules").':</u><br>'; |
|
195 | + $s = ''; |
|
196 | + if ($type == -1) $s .= $langs->trans("Name").': <b>'.$this->getNom($langs).'</b><br>'; |
|
197 | + if ($type == -1) $s .= $langs->trans("Version").': <b>'.$this->getVersion().'</b><br>'; |
|
198 | + if ($type == 0) $s .= $langs->trans("CustomerCodeDesc").'<br>'; |
|
199 | + if ($type == 1) $s .= $langs->trans("SupplierCodeDesc").'<br>'; |
|
200 | + if ($type != -1) $s .= $langs->trans("ValidityControledByModule").': <b>'.$this->getNom($langs).'</b><br>'; |
|
201 | + $s .= '<br>'; |
|
202 | + $s .= '<u>'.$langs->trans("ThisIsModuleRules").':</u><br>'; |
|
203 | 203 | if ($type == 0) |
204 | 204 | { |
205 | - $s.=$langs->trans("RequiredIfCustomer").': '; |
|
206 | - if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='<strike>'; |
|
207 | - $s.=yn(!$this->code_null,1,2); |
|
208 | - if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='</strike> '.yn(1,1,2).' ('.$langs->trans("ForcedToByAModule",$langs->transnoentities("yes")).')'; |
|
209 | - $s.='<br>'; |
|
205 | + $s .= $langs->trans("RequiredIfCustomer").': '; |
|
206 | + if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '<strike>'; |
|
207 | + $s .= yn(!$this->code_null, 1, 2); |
|
208 | + if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')'; |
|
209 | + $s .= '<br>'; |
|
210 | 210 | } |
211 | 211 | if ($type == 1) |
212 | 212 | { |
213 | - $s.=$langs->trans("RequiredIfSupplier").': '; |
|
214 | - if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='<strike>'; |
|
215 | - $s.=yn(!$this->code_null,1,2); |
|
216 | - if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='</strike> '.yn(1,1,2).' ('.$langs->trans("ForcedToByAModule",$langs->transnoentities("yes")).')'; |
|
217 | - $s.='<br>'; |
|
213 | + $s .= $langs->trans("RequiredIfSupplier").': '; |
|
214 | + if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '<strike>'; |
|
215 | + $s .= yn(!$this->code_null, 1, 2); |
|
216 | + if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')'; |
|
217 | + $s .= '<br>'; |
|
218 | 218 | } |
219 | 219 | if ($type == -1) |
220 | 220 | { |
221 | - $s.=$langs->trans("Required").': '; |
|
222 | - if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='<strike>'; |
|
223 | - $s.=yn(!$this->code_null,1,2); |
|
224 | - if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='</strike> '.yn(1,1,2).' ('.$langs->trans("ForcedToByAModule",$langs->transnoentities("yes")).')'; |
|
225 | - $s.='<br>'; |
|
221 | + $s .= $langs->trans("Required").': '; |
|
222 | + if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '<strike>'; |
|
223 | + $s .= yn(!$this->code_null, 1, 2); |
|
224 | + if (!empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && !empty($this->code_null)) $s .= '</strike> '.yn(1, 1, 2).' ('.$langs->trans("ForcedToByAModule", $langs->transnoentities("yes")).')'; |
|
225 | + $s .= '<br>'; |
|
226 | 226 | } |
227 | - $s.=$langs->trans("CanBeModifiedIfOk").': '; |
|
228 | - $s.=yn($this->code_modifiable,1,2); |
|
229 | - $s.='<br>'; |
|
230 | - $s.=$langs->trans("CanBeModifiedIfKo").': '.yn($this->code_modifiable_invalide,1,2).'<br>'; |
|
231 | - $s.=$langs->trans("AutomaticCode").': '.yn($this->code_auto,1,2).'<br>'; |
|
232 | - $s.='<br>'; |
|
227 | + $s .= $langs->trans("CanBeModifiedIfOk").': '; |
|
228 | + $s .= yn($this->code_modifiable, 1, 2); |
|
229 | + $s .= '<br>'; |
|
230 | + $s .= $langs->trans("CanBeModifiedIfKo").': '.yn($this->code_modifiable_invalide, 1, 2).'<br>'; |
|
231 | + $s .= $langs->trans("AutomaticCode").': '.yn($this->code_auto, 1, 2).'<br>'; |
|
232 | + $s .= '<br>'; |
|
233 | 233 | if ($type == 0 || $type == -1) |
234 | 234 | { |
235 | - $nextval=$this->getNextValue($soc,0); |
|
236 | - if (empty($nextval)) $nextval=$langs->trans("Undefined"); |
|
237 | - $s.=$langs->trans("NextValue").($type == -1?' ('.$langs->trans("Customer").')':'').': <b>'.$nextval.'</b><br>'; |
|
235 | + $nextval = $this->getNextValue($soc, 0); |
|
236 | + if (empty($nextval)) $nextval = $langs->trans("Undefined"); |
|
237 | + $s .= $langs->trans("NextValue").($type == -1 ? ' ('.$langs->trans("Customer").')' : '').': <b>'.$nextval.'</b><br>'; |
|
238 | 238 | } |
239 | 239 | if ($type == 1 || $type == -1) |
240 | 240 | { |
241 | - $nextval=$this->getNextValue($soc,1); |
|
242 | - if (empty($nextval)) $nextval=$langs->trans("Undefined"); |
|
243 | - $s.=$langs->trans("NextValue").($type == -1?' ('.$langs->trans("Supplier").')':'').': <b>'.$nextval.'</b>'; |
|
241 | + $nextval = $this->getNextValue($soc, 1); |
|
242 | + if (empty($nextval)) $nextval = $langs->trans("Undefined"); |
|
243 | + $s .= $langs->trans("NextValue").($type == -1 ? ' ('.$langs->trans("Supplier").')' : '').': <b>'.$nextval.'</b>'; |
|
244 | 244 | } |
245 | 245 | return $s; |
246 | 246 | } |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | /** |
269 | 269 | * @var string Error code (or message) |
270 | 270 | */ |
271 | - public $error=''; |
|
271 | + public $error = ''; |
|
272 | 272 | |
273 | 273 | |
274 | 274 | /** Return description of module |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | * @param int $type Type of third party (1:customer, 2:supplier, -1:autodetect) |
290 | 290 | * @return string Example |
291 | 291 | */ |
292 | - function getExample($langs,$objsoc=0,$type=-1) |
|
292 | + function getExample($langs, $objsoc = 0, $type = -1) |
|
293 | 293 | { |
294 | 294 | $langs->load("bills"); |
295 | 295 | return $langs->trans("NoExample"); |
@@ -329,31 +329,31 @@ discard block |
||
329 | 329 | * @param int $type -1=Nothing, 0=Customer, 1=Supplier |
330 | 330 | * @return string HTML translated description |
331 | 331 | */ |
332 | - function getToolTip($langs,$soc,$type) |
|
332 | + function getToolTip($langs, $soc, $type) |
|
333 | 333 | { |
334 | - global $conf,$db; |
|
334 | + global $conf, $db; |
|
335 | 335 | |
336 | 336 | $langs->load("admin"); |
337 | 337 | |
338 | - $s=''; |
|
339 | - if ($type == -1) $s.=$langs->trans("Name").': <b>'.$this->nom.'</b><br>'; |
|
340 | - if ($type == -1) $s.=$langs->trans("Version").': <b>'.$this->getVersion().'</b><br>'; |
|
338 | + $s = ''; |
|
339 | + if ($type == -1) $s .= $langs->trans("Name").': <b>'.$this->nom.'</b><br>'; |
|
340 | + if ($type == -1) $s .= $langs->trans("Version").': <b>'.$this->getVersion().'</b><br>'; |
|
341 | 341 | //$s.='<br>'; |
342 | 342 | //$s.='<u>'.$langs->trans("ThisIsModuleRules").':</u><br>'; |
343 | - $s.='<br>'; |
|
343 | + $s .= '<br>'; |
|
344 | 344 | if ($type == 0 || $type == -1) |
345 | 345 | { |
346 | - $result=$this->get_code($db,$soc,'customer'); |
|
347 | - $nextval=$this->code; |
|
348 | - if (empty($nextval)) $nextval=$langs->trans("Undefined"); |
|
349 | - $s.=$langs->trans("NextValue").($type == -1?' ('.$langs->trans("Customer").')':'').': <b>'.$nextval.'</b><br>'; |
|
346 | + $result = $this->get_code($db, $soc, 'customer'); |
|
347 | + $nextval = $this->code; |
|
348 | + if (empty($nextval)) $nextval = $langs->trans("Undefined"); |
|
349 | + $s .= $langs->trans("NextValue").($type == -1 ? ' ('.$langs->trans("Customer").')' : '').': <b>'.$nextval.'</b><br>'; |
|
350 | 350 | } |
351 | 351 | if ($type == 1 || $type == -1) |
352 | 352 | { |
353 | - $result=$this->get_code($db,$soc,'supplier'); |
|
354 | - $nextval=$this->code; |
|
355 | - if (empty($nextval)) $nextval=$langs->trans("Undefined"); |
|
356 | - $s.=$langs->trans("NextValue").($type == -1?' ('.$langs->trans("Supplier").')':'').': <b>'.$nextval.'</b>'; |
|
353 | + $result = $this->get_code($db, $soc, 'supplier'); |
|
354 | + $nextval = $this->code; |
|
355 | + if (empty($nextval)) $nextval = $langs->trans("Undefined"); |
|
356 | + $s .= $langs->trans("NextValue").($type == -1 ? ' ('.$langs->trans("Supplier").')' : '').': <b>'.$nextval.'</b>'; |
|
357 | 357 | } |
358 | 358 | return $s; |
359 | 359 | } |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | * @param int $type 'customer' or 'supplier' |
368 | 368 | * @return int >=0 if OK, <0 if KO |
369 | 369 | */ |
370 | - function get_code($db, $societe, $type='') |
|
370 | + function get_code($db, $societe, $type = '') |
|
371 | 371 | { |
372 | 372 | // phpcs:enable |
373 | 373 | global $langs; |
@@ -394,10 +394,10 @@ discard block |
||
394 | 394 | * @deprecated Use the new function generateDocument of Facture class |
395 | 395 | * @see Societe::generateDocument() |
396 | 396 | */ |
397 | -function thirdparty_doc_create(DoliDB $db, Societe $object, $message, $modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0) |
|
397 | +function thirdparty_doc_create(DoliDB $db, Societe $object, $message, $modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0) |
|
398 | 398 | { |
399 | 399 | // phpcs:enable |
400 | - dol_syslog(__METHOD__ . " is deprecated", LOG_WARNING); |
|
400 | + dol_syslog(__METHOD__." is deprecated", LOG_WARNING); |
|
401 | 401 | |
402 | 402 | return $object->generateDocument($modele, $outputlangs, $hidedetails, $hidedesc, $hideref); |
403 | 403 | } |
@@ -138,10 +138,18 @@ discard block |
||
138 | 138 | global $langs; |
139 | 139 | $langs->load("admin"); |
140 | 140 | |
141 | - if ($this->version == 'development') return $langs->trans("VersionDevelopment"); |
|
142 | - if ($this->version == 'experimental') return $langs->trans("VersionExperimental"); |
|
143 | - if ($this->version == 'dolibarr') return DOL_VERSION; |
|
144 | - if ($this->version) return $this->version; |
|
141 | + if ($this->version == 'development') { |
|
142 | + return $langs->trans("VersionDevelopment"); |
|
143 | + } |
|
144 | + if ($this->version == 'experimental') { |
|
145 | + return $langs->trans("VersionExperimental"); |
|
146 | + } |
|
147 | + if ($this->version == 'dolibarr') { |
|
148 | + return DOL_VERSION; |
|
149 | + } |
|
150 | + if ($this->version) { |
|
151 | + return $this->version; |
|
152 | + } |
|
145 | 153 | return $langs->trans("NotAvailable"); |
146 | 154 | } |
147 | 155 | |
@@ -170,8 +178,7 @@ discard block |
||
170 | 178 | $liste[$row[0]]=$row[1]; |
171 | 179 | $i++; |
172 | 180 | } |
173 | - } |
|
174 | - else |
|
181 | + } else |
|
175 | 182 | { |
176 | 183 | return -1; |
177 | 184 | } |
@@ -193,35 +200,57 @@ discard block |
||
193 | 200 | $langs->load("admin"); |
194 | 201 | |
195 | 202 | $s=''; |
196 | - if ($type == -1) $s.=$langs->trans("Name").': <b>'.$this->getNom($langs).'</b><br>'; |
|
197 | - if ($type == -1) $s.=$langs->trans("Version").': <b>'.$this->getVersion().'</b><br>'; |
|
198 | - if ($type == 0) $s.=$langs->trans("CustomerCodeDesc").'<br>'; |
|
199 | - if ($type == 1) $s.=$langs->trans("SupplierCodeDesc").'<br>'; |
|
200 | - if ($type != -1) $s.=$langs->trans("ValidityControledByModule").': <b>'.$this->getNom($langs).'</b><br>'; |
|
203 | + if ($type == -1) { |
|
204 | + $s.=$langs->trans("Name").': <b>'.$this->getNom($langs).'</b><br>'; |
|
205 | + } |
|
206 | + if ($type == -1) { |
|
207 | + $s.=$langs->trans("Version").': <b>'.$this->getVersion().'</b><br>'; |
|
208 | + } |
|
209 | + if ($type == 0) { |
|
210 | + $s.=$langs->trans("CustomerCodeDesc").'<br>'; |
|
211 | + } |
|
212 | + if ($type == 1) { |
|
213 | + $s.=$langs->trans("SupplierCodeDesc").'<br>'; |
|
214 | + } |
|
215 | + if ($type != -1) { |
|
216 | + $s.=$langs->trans("ValidityControledByModule").': <b>'.$this->getNom($langs).'</b><br>'; |
|
217 | + } |
|
201 | 218 | $s.='<br>'; |
202 | 219 | $s.='<u>'.$langs->trans("ThisIsModuleRules").':</u><br>'; |
203 | 220 | if ($type == 0) |
204 | 221 | { |
205 | 222 | $s.=$langs->trans("RequiredIfCustomer").': '; |
206 | - if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='<strike>'; |
|
223 | + if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) { |
|
224 | + $s.='<strike>'; |
|
225 | + } |
|
207 | 226 | $s.=yn(!$this->code_null,1,2); |
208 | - if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='</strike> '.yn(1,1,2).' ('.$langs->trans("ForcedToByAModule",$langs->transnoentities("yes")).')'; |
|
227 | + if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) { |
|
228 | + $s.='</strike> '.yn(1,1,2).' ('.$langs->trans("ForcedToByAModule",$langs->transnoentities("yes")).')'; |
|
229 | + } |
|
209 | 230 | $s.='<br>'; |
210 | 231 | } |
211 | 232 | if ($type == 1) |
212 | 233 | { |
213 | 234 | $s.=$langs->trans("RequiredIfSupplier").': '; |
214 | - if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='<strike>'; |
|
235 | + if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) { |
|
236 | + $s.='<strike>'; |
|
237 | + } |
|
215 | 238 | $s.=yn(!$this->code_null,1,2); |
216 | - if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='</strike> '.yn(1,1,2).' ('.$langs->trans("ForcedToByAModule",$langs->transnoentities("yes")).')'; |
|
239 | + if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) { |
|
240 | + $s.='</strike> '.yn(1,1,2).' ('.$langs->trans("ForcedToByAModule",$langs->transnoentities("yes")).')'; |
|
241 | + } |
|
217 | 242 | $s.='<br>'; |
218 | 243 | } |
219 | 244 | if ($type == -1) |
220 | 245 | { |
221 | 246 | $s.=$langs->trans("Required").': '; |
222 | - if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='<strike>'; |
|
247 | + if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) { |
|
248 | + $s.='<strike>'; |
|
249 | + } |
|
223 | 250 | $s.=yn(!$this->code_null,1,2); |
224 | - if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) $s.='</strike> '.yn(1,1,2).' ('.$langs->trans("ForcedToByAModule",$langs->transnoentities("yes")).')'; |
|
251 | + if (! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED) && ! empty($this->code_null)) { |
|
252 | + $s.='</strike> '.yn(1,1,2).' ('.$langs->trans("ForcedToByAModule",$langs->transnoentities("yes")).')'; |
|
253 | + } |
|
225 | 254 | $s.='<br>'; |
226 | 255 | } |
227 | 256 | $s.=$langs->trans("CanBeModifiedIfOk").': '; |
@@ -233,13 +262,17 @@ discard block |
||
233 | 262 | if ($type == 0 || $type == -1) |
234 | 263 | { |
235 | 264 | $nextval=$this->getNextValue($soc,0); |
236 | - if (empty($nextval)) $nextval=$langs->trans("Undefined"); |
|
265 | + if (empty($nextval)) { |
|
266 | + $nextval=$langs->trans("Undefined"); |
|
267 | + } |
|
237 | 268 | $s.=$langs->trans("NextValue").($type == -1?' ('.$langs->trans("Customer").')':'').': <b>'.$nextval.'</b><br>'; |
238 | 269 | } |
239 | 270 | if ($type == 1 || $type == -1) |
240 | 271 | { |
241 | 272 | $nextval=$this->getNextValue($soc,1); |
242 | - if (empty($nextval)) $nextval=$langs->trans("Undefined"); |
|
273 | + if (empty($nextval)) { |
|
274 | + $nextval=$langs->trans("Undefined"); |
|
275 | + } |
|
243 | 276 | $s.=$langs->trans("NextValue").($type == -1?' ('.$langs->trans("Supplier").')':'').': <b>'.$nextval.'</b>'; |
244 | 277 | } |
245 | 278 | return $s; |
@@ -314,10 +347,18 @@ discard block |
||
314 | 347 | global $langs; |
315 | 348 | $langs->load("admin"); |
316 | 349 | |
317 | - if ($this->version == 'development') return $langs->trans("VersionDevelopment"); |
|
318 | - if ($this->version == 'experimental') return $langs->trans("VersionExperimental"); |
|
319 | - if ($this->version == 'dolibarr') return DOL_VERSION; |
|
320 | - if ($this->version) return $this->version; |
|
350 | + if ($this->version == 'development') { |
|
351 | + return $langs->trans("VersionDevelopment"); |
|
352 | + } |
|
353 | + if ($this->version == 'experimental') { |
|
354 | + return $langs->trans("VersionExperimental"); |
|
355 | + } |
|
356 | + if ($this->version == 'dolibarr') { |
|
357 | + return DOL_VERSION; |
|
358 | + } |
|
359 | + if ($this->version) { |
|
360 | + return $this->version; |
|
361 | + } |
|
321 | 362 | return $langs->trans("NotAvailable"); |
322 | 363 | } |
323 | 364 | |
@@ -336,8 +377,12 @@ discard block |
||
336 | 377 | $langs->load("admin"); |
337 | 378 | |
338 | 379 | $s=''; |
339 | - if ($type == -1) $s.=$langs->trans("Name").': <b>'.$this->nom.'</b><br>'; |
|
340 | - if ($type == -1) $s.=$langs->trans("Version").': <b>'.$this->getVersion().'</b><br>'; |
|
380 | + if ($type == -1) { |
|
381 | + $s.=$langs->trans("Name").': <b>'.$this->nom.'</b><br>'; |
|
382 | + } |
|
383 | + if ($type == -1) { |
|
384 | + $s.=$langs->trans("Version").': <b>'.$this->getVersion().'</b><br>'; |
|
385 | + } |
|
341 | 386 | //$s.='<br>'; |
342 | 387 | //$s.='<u>'.$langs->trans("ThisIsModuleRules").':</u><br>'; |
343 | 388 | $s.='<br>'; |
@@ -345,14 +390,18 @@ discard block |
||
345 | 390 | { |
346 | 391 | $result=$this->get_code($db,$soc,'customer'); |
347 | 392 | $nextval=$this->code; |
348 | - if (empty($nextval)) $nextval=$langs->trans("Undefined"); |
|
393 | + if (empty($nextval)) { |
|
394 | + $nextval=$langs->trans("Undefined"); |
|
395 | + } |
|
349 | 396 | $s.=$langs->trans("NextValue").($type == -1?' ('.$langs->trans("Customer").')':'').': <b>'.$nextval.'</b><br>'; |
350 | 397 | } |
351 | 398 | if ($type == 1 || $type == -1) |
352 | 399 | { |
353 | 400 | $result=$this->get_code($db,$soc,'supplier'); |
354 | 401 | $nextval=$this->code; |
355 | - if (empty($nextval)) $nextval=$langs->trans("Undefined"); |
|
402 | + if (empty($nextval)) { |
|
403 | + $nextval=$langs->trans("Undefined"); |
|
404 | + } |
|
356 | 405 | $s.=$langs->trans("NextValue").($type == -1?' ('.$langs->trans("Supplier").')':'').': <b>'.$nextval.'</b>'; |
357 | 406 | } |
358 | 407 | return $s; |
@@ -34,319 +34,319 @@ |
||
34 | 34 | */ |
35 | 35 | class mod_codeclient_elephant extends ModeleThirdPartyCode |
36 | 36 | { |
37 | - /** |
|
38 | - * @var string Nom du modele |
|
39 | - * @deprecated |
|
40 | - * @see name |
|
41 | - */ |
|
42 | - public $nom='Elephant'; |
|
37 | + /** |
|
38 | + * @var string Nom du modele |
|
39 | + * @deprecated |
|
40 | + * @see name |
|
41 | + */ |
|
42 | + public $nom='Elephant'; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @var string model name |
|
46 | - */ |
|
47 | - public $name='Elephant'; |
|
44 | + /** |
|
45 | + * @var string model name |
|
46 | + */ |
|
47 | + public $name='Elephant'; |
|
48 | 48 | |
49 | - public $code_modifiable; // Code modifiable |
|
49 | + public $code_modifiable; // Code modifiable |
|
50 | 50 | |
51 | - public $code_modifiable_invalide; // Code modifiable si il est invalide |
|
51 | + public $code_modifiable_invalide; // Code modifiable si il est invalide |
|
52 | 52 | |
53 | - public $code_modifiable_null; // Code modifiables si il est null |
|
53 | + public $code_modifiable_null; // Code modifiables si il est null |
|
54 | 54 | |
55 | - public $code_null; // Code facultatif |
|
55 | + public $code_null; // Code facultatif |
|
56 | 56 | |
57 | - /** |
|
57 | + /** |
|
58 | 58 | * Dolibarr version of the loaded document |
59 | 59 | * @public string |
60 | 60 | */ |
61 | - public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' |
|
62 | - |
|
63 | - public $code_auto; // Numerotation automatique |
|
64 | - |
|
65 | - public $searchcode; // String de recherche |
|
66 | - |
|
67 | - public $numbitcounter; // Nombre de chiffres du compteur |
|
68 | - |
|
69 | - public $prefixIsRequired; // Le champ prefix du tiers doit etre renseigne quand on utilise {pre} |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * Constructor |
|
74 | - */ |
|
75 | - function __construct() |
|
76 | - { |
|
77 | - $this->code_null = 0; |
|
78 | - $this->code_modifiable = 1; |
|
79 | - $this->code_modifiable_invalide = 1; |
|
80 | - $this->code_modifiable_null = 1; |
|
81 | - $this->code_auto = 1; |
|
82 | - $this->prefixIsRequired = 0; |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** Return description of module |
|
87 | - * |
|
88 | - * @param Translate $langs Object langs |
|
89 | - * @return string Description of module |
|
90 | - */ |
|
91 | - function info($langs) |
|
92 | - { |
|
93 | - global $conf, $mc; |
|
94 | - global $form; |
|
95 | - |
|
96 | - $langs->load("companies"); |
|
97 | - |
|
98 | - $disabled = ((! empty($mc->sharings['referent']) && $mc->sharings['referent'] != $conf->entity) ? ' disabled' : ''); |
|
99 | - |
|
100 | - $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n"; |
|
101 | - $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
102 | - $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
103 | - $texte.= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
104 | - $texte.= '<input type="hidden" name="param1" value="COMPANY_ELEPHANT_MASK_CUSTOMER">'; |
|
105 | - $texte.= '<input type="hidden" name="param2" value="COMPANY_ELEPHANT_MASK_SUPPLIER">'; |
|
106 | - $texte.= '<table class="nobordernopadding" width="100%">'; |
|
107 | - |
|
108 | - $tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("ThirdParty"),$langs->transnoentities("ThirdParty")); |
|
109 | - //$tooltip.=$langs->trans("GenericMaskCodes2"); Not required for third party numbering |
|
110 | - $tooltip.=$langs->trans("GenericMaskCodes3"); |
|
111 | - $tooltip.=$langs->trans("GenericMaskCodes4b"); |
|
112 | - $tooltip.=$langs->trans("GenericMaskCodes5"); |
|
113 | - |
|
114 | - // Parametrage du prefix customers |
|
115 | - $texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("CustomerCodeModel").'):</td>'; |
|
116 | - $texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="value1" value="'.$conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER.'"'.$disabled.'>',$tooltip,1,1).'</td>'; |
|
117 | - |
|
118 | - $texte.= '<td align="left" rowspan="2"> <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"'.$disabled.'></td>'; |
|
119 | - |
|
120 | - $texte.= '</tr>'; |
|
121 | - |
|
122 | - // Parametrage du prefix suppliers |
|
123 | - $texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("SupplierCodeModel").'):</td>'; |
|
124 | - $texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="value2" value="'.$conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER.'"'.$disabled.'>',$tooltip,1,1).'</td>'; |
|
125 | - $texte.= '</tr>'; |
|
126 | - |
|
127 | - $texte.= '</table>'; |
|
128 | - $texte.= '</form>'; |
|
129 | - |
|
130 | - return $texte; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * Return an example of result returned by getNextValue |
|
136 | - * |
|
137 | - * @param Translate $langs Object langs |
|
138 | - * @param societe $objsoc Object thirdparty |
|
139 | - * @param int $type Type of third party (1:customer, 2:supplier, -1:autodetect) |
|
140 | - * @return string Return string example |
|
141 | - */ |
|
142 | - function getExample($langs,$objsoc=0,$type=-1) |
|
143 | - { |
|
144 | - if ($type == 0 || $type == -1) |
|
145 | - { |
|
146 | - $examplecust = $this->getNextValue($objsoc,0); |
|
147 | - if (! $examplecust) |
|
148 | - { |
|
149 | - $examplecust = $langs->trans('NotConfigured'); |
|
150 | - } |
|
151 | - if($examplecust=="ErrorBadMask") |
|
152 | - { |
|
153 | - $langs->load("errors"); |
|
154 | - $examplecust=$langs->trans($examplecust); |
|
155 | - } |
|
156 | - if($examplecust=="ErrorCantUseRazIfNoYearInMask") |
|
157 | - { |
|
158 | - $langs->load("errors"); |
|
159 | - $examplecust=$langs->trans($examplecust); |
|
160 | - } |
|
161 | - if($examplecust=="ErrorCantUseRazInStartedYearIfNoYearMonthInMask") |
|
162 | - { |
|
163 | - $langs->load("errors"); |
|
164 | - $examplecust=$langs->trans($examplecust); |
|
165 | - } |
|
166 | - } |
|
167 | - if ($type == 1 || $type == -1) |
|
168 | - { |
|
169 | - $examplesup = $this->getNextValue($objsoc,1); |
|
170 | - if (! $examplesup) |
|
171 | - { |
|
172 | - $examplesup = $langs->trans('NotConfigured'); |
|
173 | - } |
|
174 | - if($examplesup=="ErrorBadMask") |
|
175 | - { |
|
176 | - $langs->load("errors"); |
|
177 | - $examplesup=$langs->trans($examplesup); |
|
178 | - } |
|
179 | - if($examplesup=="ErrorCantUseRazIfNoYearInMask") |
|
180 | - { |
|
181 | - $langs->load("errors"); |
|
182 | - $examplesup=$langs->trans($examplesup); |
|
183 | - } |
|
184 | - if($examplesup=="ErrorCantUseRazInStartedYearIfNoYearMonthInMask") |
|
185 | - { |
|
186 | - $langs->load("errors"); |
|
187 | - $examplesup=$langs->trans($examplesup); |
|
188 | - } |
|
189 | - } |
|
190 | - |
|
191 | - if ($type == 0) return $examplecust; |
|
192 | - if ($type == 1) return $examplesup; |
|
193 | - return $examplecust.'<br>'.$examplesup; |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * Return next value |
|
198 | - * |
|
199 | - * @param Societe $objsoc Object third party |
|
200 | - * @param int $type Client ou fournisseur (0:customer, 1:supplier) |
|
201 | - * @return string Value if OK, '' if module not configured, <0 if KO |
|
202 | - */ |
|
203 | - function getNextValue($objsoc=0,$type=-1) |
|
204 | - { |
|
205 | - global $db,$conf; |
|
206 | - |
|
207 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php'; |
|
208 | - |
|
209 | - // Get Mask value |
|
210 | - $mask = ''; |
|
211 | - if ($type==0) $mask = $conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER; |
|
212 | - if ($type==1) $mask = $conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER; |
|
213 | - if (! $mask) |
|
214 | - { |
|
215 | - $this->error='NotConfigured'; |
|
216 | - return ''; |
|
217 | - } |
|
218 | - |
|
219 | - $field='';$where=''; |
|
220 | - if ($type == 0) |
|
221 | - { |
|
222 | - $field = 'code_client'; |
|
223 | - //$where = ' AND client in (1,2)'; |
|
224 | - } |
|
225 | - else if ($type == 1) |
|
226 | - { |
|
227 | - $field = 'code_fournisseur'; |
|
228 | - //$where = ' AND fournisseur = 1'; |
|
229 | - } |
|
230 | - else return -1; |
|
231 | - |
|
232 | - $now=dol_now(); |
|
233 | - |
|
234 | - $numFinal=get_next_value($db,$mask,'societe',$field,$where,'',$now); |
|
235 | - |
|
236 | - return $numFinal; |
|
237 | - } |
|
61 | + public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' |
|
62 | + |
|
63 | + public $code_auto; // Numerotation automatique |
|
64 | + |
|
65 | + public $searchcode; // String de recherche |
|
66 | + |
|
67 | + public $numbitcounter; // Nombre de chiffres du compteur |
|
68 | + |
|
69 | + public $prefixIsRequired; // Le champ prefix du tiers doit etre renseigne quand on utilise {pre} |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * Constructor |
|
74 | + */ |
|
75 | + function __construct() |
|
76 | + { |
|
77 | + $this->code_null = 0; |
|
78 | + $this->code_modifiable = 1; |
|
79 | + $this->code_modifiable_invalide = 1; |
|
80 | + $this->code_modifiable_null = 1; |
|
81 | + $this->code_auto = 1; |
|
82 | + $this->prefixIsRequired = 0; |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** Return description of module |
|
87 | + * |
|
88 | + * @param Translate $langs Object langs |
|
89 | + * @return string Description of module |
|
90 | + */ |
|
91 | + function info($langs) |
|
92 | + { |
|
93 | + global $conf, $mc; |
|
94 | + global $form; |
|
95 | + |
|
96 | + $langs->load("companies"); |
|
97 | + |
|
98 | + $disabled = ((! empty($mc->sharings['referent']) && $mc->sharings['referent'] != $conf->entity) ? ' disabled' : ''); |
|
99 | + |
|
100 | + $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n"; |
|
101 | + $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
102 | + $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
103 | + $texte.= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
104 | + $texte.= '<input type="hidden" name="param1" value="COMPANY_ELEPHANT_MASK_CUSTOMER">'; |
|
105 | + $texte.= '<input type="hidden" name="param2" value="COMPANY_ELEPHANT_MASK_SUPPLIER">'; |
|
106 | + $texte.= '<table class="nobordernopadding" width="100%">'; |
|
107 | + |
|
108 | + $tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("ThirdParty"),$langs->transnoentities("ThirdParty")); |
|
109 | + //$tooltip.=$langs->trans("GenericMaskCodes2"); Not required for third party numbering |
|
110 | + $tooltip.=$langs->trans("GenericMaskCodes3"); |
|
111 | + $tooltip.=$langs->trans("GenericMaskCodes4b"); |
|
112 | + $tooltip.=$langs->trans("GenericMaskCodes5"); |
|
113 | + |
|
114 | + // Parametrage du prefix customers |
|
115 | + $texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("CustomerCodeModel").'):</td>'; |
|
116 | + $texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="value1" value="'.$conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER.'"'.$disabled.'>',$tooltip,1,1).'</td>'; |
|
117 | + |
|
118 | + $texte.= '<td align="left" rowspan="2"> <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"'.$disabled.'></td>'; |
|
119 | + |
|
120 | + $texte.= '</tr>'; |
|
121 | + |
|
122 | + // Parametrage du prefix suppliers |
|
123 | + $texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("SupplierCodeModel").'):</td>'; |
|
124 | + $texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="value2" value="'.$conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER.'"'.$disabled.'>',$tooltip,1,1).'</td>'; |
|
125 | + $texte.= '</tr>'; |
|
126 | + |
|
127 | + $texte.= '</table>'; |
|
128 | + $texte.= '</form>'; |
|
129 | + |
|
130 | + return $texte; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * Return an example of result returned by getNextValue |
|
136 | + * |
|
137 | + * @param Translate $langs Object langs |
|
138 | + * @param societe $objsoc Object thirdparty |
|
139 | + * @param int $type Type of third party (1:customer, 2:supplier, -1:autodetect) |
|
140 | + * @return string Return string example |
|
141 | + */ |
|
142 | + function getExample($langs,$objsoc=0,$type=-1) |
|
143 | + { |
|
144 | + if ($type == 0 || $type == -1) |
|
145 | + { |
|
146 | + $examplecust = $this->getNextValue($objsoc,0); |
|
147 | + if (! $examplecust) |
|
148 | + { |
|
149 | + $examplecust = $langs->trans('NotConfigured'); |
|
150 | + } |
|
151 | + if($examplecust=="ErrorBadMask") |
|
152 | + { |
|
153 | + $langs->load("errors"); |
|
154 | + $examplecust=$langs->trans($examplecust); |
|
155 | + } |
|
156 | + if($examplecust=="ErrorCantUseRazIfNoYearInMask") |
|
157 | + { |
|
158 | + $langs->load("errors"); |
|
159 | + $examplecust=$langs->trans($examplecust); |
|
160 | + } |
|
161 | + if($examplecust=="ErrorCantUseRazInStartedYearIfNoYearMonthInMask") |
|
162 | + { |
|
163 | + $langs->load("errors"); |
|
164 | + $examplecust=$langs->trans($examplecust); |
|
165 | + } |
|
166 | + } |
|
167 | + if ($type == 1 || $type == -1) |
|
168 | + { |
|
169 | + $examplesup = $this->getNextValue($objsoc,1); |
|
170 | + if (! $examplesup) |
|
171 | + { |
|
172 | + $examplesup = $langs->trans('NotConfigured'); |
|
173 | + } |
|
174 | + if($examplesup=="ErrorBadMask") |
|
175 | + { |
|
176 | + $langs->load("errors"); |
|
177 | + $examplesup=$langs->trans($examplesup); |
|
178 | + } |
|
179 | + if($examplesup=="ErrorCantUseRazIfNoYearInMask") |
|
180 | + { |
|
181 | + $langs->load("errors"); |
|
182 | + $examplesup=$langs->trans($examplesup); |
|
183 | + } |
|
184 | + if($examplesup=="ErrorCantUseRazInStartedYearIfNoYearMonthInMask") |
|
185 | + { |
|
186 | + $langs->load("errors"); |
|
187 | + $examplesup=$langs->trans($examplesup); |
|
188 | + } |
|
189 | + } |
|
190 | + |
|
191 | + if ($type == 0) return $examplecust; |
|
192 | + if ($type == 1) return $examplesup; |
|
193 | + return $examplecust.'<br>'.$examplesup; |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * Return next value |
|
198 | + * |
|
199 | + * @param Societe $objsoc Object third party |
|
200 | + * @param int $type Client ou fournisseur (0:customer, 1:supplier) |
|
201 | + * @return string Value if OK, '' if module not configured, <0 if KO |
|
202 | + */ |
|
203 | + function getNextValue($objsoc=0,$type=-1) |
|
204 | + { |
|
205 | + global $db,$conf; |
|
206 | + |
|
207 | + require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php'; |
|
208 | + |
|
209 | + // Get Mask value |
|
210 | + $mask = ''; |
|
211 | + if ($type==0) $mask = $conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER; |
|
212 | + if ($type==1) $mask = $conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER; |
|
213 | + if (! $mask) |
|
214 | + { |
|
215 | + $this->error='NotConfigured'; |
|
216 | + return ''; |
|
217 | + } |
|
218 | + |
|
219 | + $field='';$where=''; |
|
220 | + if ($type == 0) |
|
221 | + { |
|
222 | + $field = 'code_client'; |
|
223 | + //$where = ' AND client in (1,2)'; |
|
224 | + } |
|
225 | + else if ($type == 1) |
|
226 | + { |
|
227 | + $field = 'code_fournisseur'; |
|
228 | + //$where = ' AND fournisseur = 1'; |
|
229 | + } |
|
230 | + else return -1; |
|
231 | + |
|
232 | + $now=dol_now(); |
|
233 | + |
|
234 | + $numFinal=get_next_value($db,$mask,'societe',$field,$where,'',$now); |
|
235 | + |
|
236 | + return $numFinal; |
|
237 | + } |
|
238 | 238 | |
239 | 239 | |
240 | 240 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
241 | - /** |
|
242 | - * Check if mask/numbering use prefix |
|
243 | - * |
|
244 | - * @return int 0 or 1 |
|
245 | - */ |
|
246 | - function verif_prefixIsUsed() |
|
247 | - { |
|
241 | + /** |
|
242 | + * Check if mask/numbering use prefix |
|
243 | + * |
|
244 | + * @return int 0 or 1 |
|
245 | + */ |
|
246 | + function verif_prefixIsUsed() |
|
247 | + { |
|
248 | 248 | // phpcs:enable |
249 | - global $conf; |
|
250 | - |
|
251 | - $mask = $conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER; |
|
252 | - if (preg_match('/\{pre\}/i',$mask)) return 1; |
|
253 | - |
|
254 | - $mask = $conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER; |
|
255 | - if (preg_match('/\{pre\}/i',$mask)) return 1; |
|
256 | - |
|
257 | - return 0; |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - /** |
|
262 | - * Check validity of code according to its rules |
|
263 | - * |
|
264 | - * @param DoliDB $db Database handler |
|
265 | - * @param string $code Code to check/correct |
|
266 | - * @param Societe $soc Object third party |
|
267 | - * @param int $type 0 = customer/prospect , 1 = supplier |
|
268 | - * @return int 0 if OK |
|
269 | - * -1 ErrorBadCustomerCodeSyntax |
|
270 | - * -2 ErrorCustomerCodeRequired |
|
271 | - * -3 ErrorCustomerCodeAlreadyUsed |
|
272 | - * -4 ErrorPrefixRequired |
|
273 | - * -5 Other (see this->error) |
|
274 | - */ |
|
275 | - function verif($db, &$code, $soc, $type) |
|
276 | - { |
|
277 | - global $conf; |
|
278 | - |
|
279 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php'; |
|
280 | - |
|
281 | - $result=0; |
|
282 | - $code = strtoupper(trim($code)); |
|
283 | - |
|
284 | - if (empty($code) && $this->code_null && empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) |
|
285 | - { |
|
286 | - $result=0; |
|
287 | - } |
|
288 | - else if (empty($code) && (! $this->code_null || ! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) ) |
|
289 | - { |
|
290 | - $result=-2; |
|
291 | - } |
|
292 | - else |
|
293 | - { |
|
294 | - // Get Mask value |
|
295 | - $mask = ''; |
|
296 | - if ($type==0) $mask = empty($conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER)?'':$conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER; |
|
297 | - if ($type==1) $mask = empty($conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER)?'':$conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER; |
|
298 | - if (! $mask) |
|
299 | - { |
|
300 | - $this->error='NotConfigured'; |
|
301 | - return -5; |
|
302 | - } |
|
303 | - |
|
304 | - $result=check_value($mask,$code); |
|
305 | - if (is_string($result)) |
|
306 | - { |
|
307 | - $this->error = $result; |
|
308 | - return -5; |
|
309 | - } |
|
310 | - } |
|
311 | - |
|
312 | - dol_syslog("mod_codeclient_elephant::verif type=".$type." result=".$result); |
|
313 | - return $result; |
|
314 | - } |
|
249 | + global $conf; |
|
250 | + |
|
251 | + $mask = $conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER; |
|
252 | + if (preg_match('/\{pre\}/i',$mask)) return 1; |
|
253 | + |
|
254 | + $mask = $conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER; |
|
255 | + if (preg_match('/\{pre\}/i',$mask)) return 1; |
|
256 | + |
|
257 | + return 0; |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + /** |
|
262 | + * Check validity of code according to its rules |
|
263 | + * |
|
264 | + * @param DoliDB $db Database handler |
|
265 | + * @param string $code Code to check/correct |
|
266 | + * @param Societe $soc Object third party |
|
267 | + * @param int $type 0 = customer/prospect , 1 = supplier |
|
268 | + * @return int 0 if OK |
|
269 | + * -1 ErrorBadCustomerCodeSyntax |
|
270 | + * -2 ErrorCustomerCodeRequired |
|
271 | + * -3 ErrorCustomerCodeAlreadyUsed |
|
272 | + * -4 ErrorPrefixRequired |
|
273 | + * -5 Other (see this->error) |
|
274 | + */ |
|
275 | + function verif($db, &$code, $soc, $type) |
|
276 | + { |
|
277 | + global $conf; |
|
278 | + |
|
279 | + require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php'; |
|
280 | + |
|
281 | + $result=0; |
|
282 | + $code = strtoupper(trim($code)); |
|
283 | + |
|
284 | + if (empty($code) && $this->code_null && empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) |
|
285 | + { |
|
286 | + $result=0; |
|
287 | + } |
|
288 | + else if (empty($code) && (! $this->code_null || ! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) ) |
|
289 | + { |
|
290 | + $result=-2; |
|
291 | + } |
|
292 | + else |
|
293 | + { |
|
294 | + // Get Mask value |
|
295 | + $mask = ''; |
|
296 | + if ($type==0) $mask = empty($conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER)?'':$conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER; |
|
297 | + if ($type==1) $mask = empty($conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER)?'':$conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER; |
|
298 | + if (! $mask) |
|
299 | + { |
|
300 | + $this->error='NotConfigured'; |
|
301 | + return -5; |
|
302 | + } |
|
303 | + |
|
304 | + $result=check_value($mask,$code); |
|
305 | + if (is_string($result)) |
|
306 | + { |
|
307 | + $this->error = $result; |
|
308 | + return -5; |
|
309 | + } |
|
310 | + } |
|
311 | + |
|
312 | + dol_syslog("mod_codeclient_elephant::verif type=".$type." result=".$result); |
|
313 | + return $result; |
|
314 | + } |
|
315 | 315 | |
316 | 316 | |
317 | 317 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
318 | - /** |
|
319 | - * Renvoi si un code est pris ou non (par autre tiers) |
|
320 | - * |
|
321 | - * @param DoliDB $db Handler acces base |
|
322 | - * @param string $code Code a verifier |
|
323 | - * @param Societe $soc Objet societe |
|
324 | - * @param int $type 0 = customer/prospect , 1 = supplier |
|
325 | - * @return int 0 if available, <0 if KO |
|
326 | - */ |
|
327 | - function verif_dispo($db, $code, $soc, $type=0) |
|
328 | - { |
|
318 | + /** |
|
319 | + * Renvoi si un code est pris ou non (par autre tiers) |
|
320 | + * |
|
321 | + * @param DoliDB $db Handler acces base |
|
322 | + * @param string $code Code a verifier |
|
323 | + * @param Societe $soc Objet societe |
|
324 | + * @param int $type 0 = customer/prospect , 1 = supplier |
|
325 | + * @return int 0 if available, <0 if KO |
|
326 | + */ |
|
327 | + function verif_dispo($db, $code, $soc, $type=0) |
|
328 | + { |
|
329 | 329 | // phpcs:enable |
330 | - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe"; |
|
331 | - if ($type == 1) $sql.= " WHERE code_fournisseur = '".$code."'"; |
|
332 | - else $sql.= " WHERE code_client = '".$code."'"; |
|
333 | - if ($soc->id > 0) $sql.= " AND rowid <> ".$soc->id; |
|
334 | - |
|
335 | - $resql=$db->query($sql); |
|
336 | - if ($resql) |
|
337 | - { |
|
338 | - if ($db->num_rows($resql) == 0) |
|
339 | - { |
|
340 | - return 0; |
|
341 | - } |
|
342 | - else |
|
343 | - { |
|
344 | - return -1; |
|
345 | - } |
|
346 | - } |
|
347 | - else |
|
348 | - { |
|
349 | - return -2; |
|
350 | - } |
|
351 | - } |
|
330 | + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe"; |
|
331 | + if ($type == 1) $sql.= " WHERE code_fournisseur = '".$code."'"; |
|
332 | + else $sql.= " WHERE code_client = '".$code."'"; |
|
333 | + if ($soc->id > 0) $sql.= " AND rowid <> ".$soc->id; |
|
334 | + |
|
335 | + $resql=$db->query($sql); |
|
336 | + if ($resql) |
|
337 | + { |
|
338 | + if ($db->num_rows($resql) == 0) |
|
339 | + { |
|
340 | + return 0; |
|
341 | + } |
|
342 | + else |
|
343 | + { |
|
344 | + return -1; |
|
345 | + } |
|
346 | + } |
|
347 | + else |
|
348 | + { |
|
349 | + return -2; |
|
350 | + } |
|
351 | + } |
|
352 | 352 | } |
@@ -39,28 +39,28 @@ discard block |
||
39 | 39 | * @deprecated |
40 | 40 | * @see name |
41 | 41 | */ |
42 | - public $nom='Elephant'; |
|
42 | + public $nom = 'Elephant'; |
|
43 | 43 | |
44 | 44 | /** |
45 | 45 | * @var string model name |
46 | 46 | */ |
47 | - public $name='Elephant'; |
|
47 | + public $name = 'Elephant'; |
|
48 | 48 | |
49 | - public $code_modifiable; // Code modifiable |
|
49 | + public $code_modifiable; // Code modifiable |
|
50 | 50 | |
51 | - public $code_modifiable_invalide; // Code modifiable si il est invalide |
|
51 | + public $code_modifiable_invalide; // Code modifiable si il est invalide |
|
52 | 52 | |
53 | - public $code_modifiable_null; // Code modifiables si il est null |
|
53 | + public $code_modifiable_null; // Code modifiables si il est null |
|
54 | 54 | |
55 | - public $code_null; // Code facultatif |
|
55 | + public $code_null; // Code facultatif |
|
56 | 56 | |
57 | 57 | /** |
58 | 58 | * Dolibarr version of the loaded document |
59 | 59 | * @public string |
60 | 60 | */ |
61 | - public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' |
|
61 | + public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' |
|
62 | 62 | |
63 | - public $code_auto; // Numerotation automatique |
|
63 | + public $code_auto; // Numerotation automatique |
|
64 | 64 | |
65 | 65 | public $searchcode; // String de recherche |
66 | 66 | |
@@ -95,37 +95,37 @@ discard block |
||
95 | 95 | |
96 | 96 | $langs->load("companies"); |
97 | 97 | |
98 | - $disabled = ((! empty($mc->sharings['referent']) && $mc->sharings['referent'] != $conf->entity) ? ' disabled' : ''); |
|
98 | + $disabled = ((!empty($mc->sharings['referent']) && $mc->sharings['referent'] != $conf->entity) ? ' disabled' : ''); |
|
99 | 99 | |
100 | 100 | $texte = $langs->trans('GenericNumRefModelDesc')."<br>\n"; |
101 | - $texte.= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
102 | - $texte.= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
103 | - $texte.= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
104 | - $texte.= '<input type="hidden" name="param1" value="COMPANY_ELEPHANT_MASK_CUSTOMER">'; |
|
105 | - $texte.= '<input type="hidden" name="param2" value="COMPANY_ELEPHANT_MASK_SUPPLIER">'; |
|
106 | - $texte.= '<table class="nobordernopadding" width="100%">'; |
|
107 | - |
|
108 | - $tooltip=$langs->trans("GenericMaskCodes",$langs->transnoentities("ThirdParty"),$langs->transnoentities("ThirdParty")); |
|
101 | + $texte .= '<form action="'.$_SERVER["PHP_SELF"].'" method="POST">'; |
|
102 | + $texte .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
103 | + $texte .= '<input type="hidden" name="action" value="setModuleOptions">'; |
|
104 | + $texte .= '<input type="hidden" name="param1" value="COMPANY_ELEPHANT_MASK_CUSTOMER">'; |
|
105 | + $texte .= '<input type="hidden" name="param2" value="COMPANY_ELEPHANT_MASK_SUPPLIER">'; |
|
106 | + $texte .= '<table class="nobordernopadding" width="100%">'; |
|
107 | + |
|
108 | + $tooltip = $langs->trans("GenericMaskCodes", $langs->transnoentities("ThirdParty"), $langs->transnoentities("ThirdParty")); |
|
109 | 109 | //$tooltip.=$langs->trans("GenericMaskCodes2"); Not required for third party numbering |
110 | - $tooltip.=$langs->trans("GenericMaskCodes3"); |
|
111 | - $tooltip.=$langs->trans("GenericMaskCodes4b"); |
|
112 | - $tooltip.=$langs->trans("GenericMaskCodes5"); |
|
110 | + $tooltip .= $langs->trans("GenericMaskCodes3"); |
|
111 | + $tooltip .= $langs->trans("GenericMaskCodes4b"); |
|
112 | + $tooltip .= $langs->trans("GenericMaskCodes5"); |
|
113 | 113 | |
114 | 114 | // Parametrage du prefix customers |
115 | - $texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("CustomerCodeModel").'):</td>'; |
|
116 | - $texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="value1" value="'.$conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER.'"'.$disabled.'>',$tooltip,1,1).'</td>'; |
|
115 | + $texte .= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("CustomerCodeModel").'):</td>'; |
|
116 | + $texte .= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="value1" value="'.$conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER.'"'.$disabled.'>', $tooltip, 1, 1).'</td>'; |
|
117 | 117 | |
118 | - $texte.= '<td align="left" rowspan="2"> <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"'.$disabled.'></td>'; |
|
118 | + $texte .= '<td align="left" rowspan="2"> <input type="submit" class="button" value="'.$langs->trans("Modify").'" name="Button"'.$disabled.'></td>'; |
|
119 | 119 | |
120 | - $texte.= '</tr>'; |
|
120 | + $texte .= '</tr>'; |
|
121 | 121 | |
122 | 122 | // Parametrage du prefix suppliers |
123 | - $texte.= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("SupplierCodeModel").'):</td>'; |
|
124 | - $texte.= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="value2" value="'.$conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER.'"'.$disabled.'>',$tooltip,1,1).'</td>'; |
|
125 | - $texte.= '</tr>'; |
|
123 | + $texte .= '<tr><td>'.$langs->trans("Mask").' ('.$langs->trans("SupplierCodeModel").'):</td>'; |
|
124 | + $texte .= '<td align="right">'.$form->textwithpicto('<input type="text" class="flat" size="24" name="value2" value="'.$conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER.'"'.$disabled.'>', $tooltip, 1, 1).'</td>'; |
|
125 | + $texte .= '</tr>'; |
|
126 | 126 | |
127 | - $texte.= '</table>'; |
|
128 | - $texte.= '</form>'; |
|
127 | + $texte .= '</table>'; |
|
128 | + $texte .= '</form>'; |
|
129 | 129 | |
130 | 130 | return $texte; |
131 | 131 | } |
@@ -139,52 +139,52 @@ discard block |
||
139 | 139 | * @param int $type Type of third party (1:customer, 2:supplier, -1:autodetect) |
140 | 140 | * @return string Return string example |
141 | 141 | */ |
142 | - function getExample($langs,$objsoc=0,$type=-1) |
|
142 | + function getExample($langs, $objsoc = 0, $type = -1) |
|
143 | 143 | { |
144 | 144 | if ($type == 0 || $type == -1) |
145 | 145 | { |
146 | - $examplecust = $this->getNextValue($objsoc,0); |
|
147 | - if (! $examplecust) |
|
146 | + $examplecust = $this->getNextValue($objsoc, 0); |
|
147 | + if (!$examplecust) |
|
148 | 148 | { |
149 | 149 | $examplecust = $langs->trans('NotConfigured'); |
150 | 150 | } |
151 | - if($examplecust=="ErrorBadMask") |
|
151 | + if ($examplecust == "ErrorBadMask") |
|
152 | 152 | { |
153 | 153 | $langs->load("errors"); |
154 | - $examplecust=$langs->trans($examplecust); |
|
154 | + $examplecust = $langs->trans($examplecust); |
|
155 | 155 | } |
156 | - if($examplecust=="ErrorCantUseRazIfNoYearInMask") |
|
156 | + if ($examplecust == "ErrorCantUseRazIfNoYearInMask") |
|
157 | 157 | { |
158 | 158 | $langs->load("errors"); |
159 | - $examplecust=$langs->trans($examplecust); |
|
159 | + $examplecust = $langs->trans($examplecust); |
|
160 | 160 | } |
161 | - if($examplecust=="ErrorCantUseRazInStartedYearIfNoYearMonthInMask") |
|
161 | + if ($examplecust == "ErrorCantUseRazInStartedYearIfNoYearMonthInMask") |
|
162 | 162 | { |
163 | 163 | $langs->load("errors"); |
164 | - $examplecust=$langs->trans($examplecust); |
|
164 | + $examplecust = $langs->trans($examplecust); |
|
165 | 165 | } |
166 | 166 | } |
167 | 167 | if ($type == 1 || $type == -1) |
168 | 168 | { |
169 | - $examplesup = $this->getNextValue($objsoc,1); |
|
170 | - if (! $examplesup) |
|
169 | + $examplesup = $this->getNextValue($objsoc, 1); |
|
170 | + if (!$examplesup) |
|
171 | 171 | { |
172 | 172 | $examplesup = $langs->trans('NotConfigured'); |
173 | 173 | } |
174 | - if($examplesup=="ErrorBadMask") |
|
174 | + if ($examplesup == "ErrorBadMask") |
|
175 | 175 | { |
176 | 176 | $langs->load("errors"); |
177 | - $examplesup=$langs->trans($examplesup); |
|
177 | + $examplesup = $langs->trans($examplesup); |
|
178 | 178 | } |
179 | - if($examplesup=="ErrorCantUseRazIfNoYearInMask") |
|
179 | + if ($examplesup == "ErrorCantUseRazIfNoYearInMask") |
|
180 | 180 | { |
181 | 181 | $langs->load("errors"); |
182 | - $examplesup=$langs->trans($examplesup); |
|
182 | + $examplesup = $langs->trans($examplesup); |
|
183 | 183 | } |
184 | - if($examplesup=="ErrorCantUseRazInStartedYearIfNoYearMonthInMask") |
|
184 | + if ($examplesup == "ErrorCantUseRazInStartedYearIfNoYearMonthInMask") |
|
185 | 185 | { |
186 | 186 | $langs->load("errors"); |
187 | - $examplesup=$langs->trans($examplesup); |
|
187 | + $examplesup = $langs->trans($examplesup); |
|
188 | 188 | } |
189 | 189 | } |
190 | 190 | |
@@ -200,23 +200,23 @@ discard block |
||
200 | 200 | * @param int $type Client ou fournisseur (0:customer, 1:supplier) |
201 | 201 | * @return string Value if OK, '' if module not configured, <0 if KO |
202 | 202 | */ |
203 | - function getNextValue($objsoc=0,$type=-1) |
|
203 | + function getNextValue($objsoc = 0, $type = -1) |
|
204 | 204 | { |
205 | - global $db,$conf; |
|
205 | + global $db, $conf; |
|
206 | 206 | |
207 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php'; |
|
207 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; |
|
208 | 208 | |
209 | 209 | // Get Mask value |
210 | 210 | $mask = ''; |
211 | - if ($type==0) $mask = $conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER; |
|
212 | - if ($type==1) $mask = $conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER; |
|
213 | - if (! $mask) |
|
211 | + if ($type == 0) $mask = $conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER; |
|
212 | + if ($type == 1) $mask = $conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER; |
|
213 | + if (!$mask) |
|
214 | 214 | { |
215 | - $this->error='NotConfigured'; |
|
215 | + $this->error = 'NotConfigured'; |
|
216 | 216 | return ''; |
217 | 217 | } |
218 | 218 | |
219 | - $field='';$where=''; |
|
219 | + $field = ''; $where = ''; |
|
220 | 220 | if ($type == 0) |
221 | 221 | { |
222 | 222 | $field = 'code_client'; |
@@ -229,9 +229,9 @@ discard block |
||
229 | 229 | } |
230 | 230 | else return -1; |
231 | 231 | |
232 | - $now=dol_now(); |
|
232 | + $now = dol_now(); |
|
233 | 233 | |
234 | - $numFinal=get_next_value($db,$mask,'societe',$field,$where,'',$now); |
|
234 | + $numFinal = get_next_value($db, $mask, 'societe', $field, $where, '', $now); |
|
235 | 235 | |
236 | 236 | return $numFinal; |
237 | 237 | } |
@@ -249,10 +249,10 @@ discard block |
||
249 | 249 | global $conf; |
250 | 250 | |
251 | 251 | $mask = $conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER; |
252 | - if (preg_match('/\{pre\}/i',$mask)) return 1; |
|
252 | + if (preg_match('/\{pre\}/i', $mask)) return 1; |
|
253 | 253 | |
254 | 254 | $mask = $conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER; |
255 | - if (preg_match('/\{pre\}/i',$mask)) return 1; |
|
255 | + if (preg_match('/\{pre\}/i', $mask)) return 1; |
|
256 | 256 | |
257 | 257 | return 0; |
258 | 258 | } |
@@ -276,32 +276,32 @@ discard block |
||
276 | 276 | { |
277 | 277 | global $conf; |
278 | 278 | |
279 | - require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php'; |
|
279 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; |
|
280 | 280 | |
281 | - $result=0; |
|
281 | + $result = 0; |
|
282 | 282 | $code = strtoupper(trim($code)); |
283 | 283 | |
284 | 284 | if (empty($code) && $this->code_null && empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) |
285 | 285 | { |
286 | - $result=0; |
|
286 | + $result = 0; |
|
287 | 287 | } |
288 | - else if (empty($code) && (! $this->code_null || ! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) ) |
|
288 | + else if (empty($code) && (!$this->code_null || !empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED))) |
|
289 | 289 | { |
290 | - $result=-2; |
|
290 | + $result = -2; |
|
291 | 291 | } |
292 | 292 | else |
293 | 293 | { |
294 | 294 | // Get Mask value |
295 | 295 | $mask = ''; |
296 | - if ($type==0) $mask = empty($conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER)?'':$conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER; |
|
297 | - if ($type==1) $mask = empty($conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER)?'':$conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER; |
|
298 | - if (! $mask) |
|
296 | + if ($type == 0) $mask = empty($conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER) ? '' : $conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER; |
|
297 | + if ($type == 1) $mask = empty($conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER) ? '' : $conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER; |
|
298 | + if (!$mask) |
|
299 | 299 | { |
300 | - $this->error='NotConfigured'; |
|
300 | + $this->error = 'NotConfigured'; |
|
301 | 301 | return -5; |
302 | 302 | } |
303 | 303 | |
304 | - $result=check_value($mask,$code); |
|
304 | + $result = check_value($mask, $code); |
|
305 | 305 | if (is_string($result)) |
306 | 306 | { |
307 | 307 | $this->error = $result; |
@@ -324,15 +324,15 @@ discard block |
||
324 | 324 | * @param int $type 0 = customer/prospect , 1 = supplier |
325 | 325 | * @return int 0 if available, <0 if KO |
326 | 326 | */ |
327 | - function verif_dispo($db, $code, $soc, $type=0) |
|
327 | + function verif_dispo($db, $code, $soc, $type = 0) |
|
328 | 328 | { |
329 | 329 | // phpcs:enable |
330 | 330 | $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe"; |
331 | - if ($type == 1) $sql.= " WHERE code_fournisseur = '".$code."'"; |
|
332 | - else $sql.= " WHERE code_client = '".$code."'"; |
|
333 | - if ($soc->id > 0) $sql.= " AND rowid <> ".$soc->id; |
|
331 | + if ($type == 1) $sql .= " WHERE code_fournisseur = '".$code."'"; |
|
332 | + else $sql .= " WHERE code_client = '".$code."'"; |
|
333 | + if ($soc->id > 0) $sql .= " AND rowid <> ".$soc->id; |
|
334 | 334 | |
335 | - $resql=$db->query($sql); |
|
335 | + $resql = $db->query($sql); |
|
336 | 336 | if ($resql) |
337 | 337 | { |
338 | 338 | if ($db->num_rows($resql) == 0) |
@@ -188,8 +188,12 @@ discard block |
||
188 | 188 | } |
189 | 189 | } |
190 | 190 | |
191 | - if ($type == 0) return $examplecust; |
|
192 | - if ($type == 1) return $examplesup; |
|
191 | + if ($type == 0) { |
|
192 | + return $examplecust; |
|
193 | + } |
|
194 | + if ($type == 1) { |
|
195 | + return $examplesup; |
|
196 | + } |
|
193 | 197 | return $examplecust.'<br>'.$examplesup; |
194 | 198 | } |
195 | 199 | |
@@ -208,8 +212,12 @@ discard block |
||
208 | 212 | |
209 | 213 | // Get Mask value |
210 | 214 | $mask = ''; |
211 | - if ($type==0) $mask = $conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER; |
|
212 | - if ($type==1) $mask = $conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER; |
|
215 | + if ($type==0) { |
|
216 | + $mask = $conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER; |
|
217 | + } |
|
218 | + if ($type==1) { |
|
219 | + $mask = $conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER; |
|
220 | + } |
|
213 | 221 | if (! $mask) |
214 | 222 | { |
215 | 223 | $this->error='NotConfigured'; |
@@ -221,13 +229,13 @@ discard block |
||
221 | 229 | { |
222 | 230 | $field = 'code_client'; |
223 | 231 | //$where = ' AND client in (1,2)'; |
224 | - } |
|
225 | - else if ($type == 1) |
|
232 | + } else if ($type == 1) |
|
226 | 233 | { |
227 | 234 | $field = 'code_fournisseur'; |
228 | 235 | //$where = ' AND fournisseur = 1'; |
236 | + } else { |
|
237 | + return -1; |
|
229 | 238 | } |
230 | - else return -1; |
|
231 | 239 | |
232 | 240 | $now=dol_now(); |
233 | 241 | |
@@ -249,10 +257,14 @@ discard block |
||
249 | 257 | global $conf; |
250 | 258 | |
251 | 259 | $mask = $conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER; |
252 | - if (preg_match('/\{pre\}/i',$mask)) return 1; |
|
260 | + if (preg_match('/\{pre\}/i',$mask)) { |
|
261 | + return 1; |
|
262 | + } |
|
253 | 263 | |
254 | 264 | $mask = $conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER; |
255 | - if (preg_match('/\{pre\}/i',$mask)) return 1; |
|
265 | + if (preg_match('/\{pre\}/i',$mask)) { |
|
266 | + return 1; |
|
267 | + } |
|
256 | 268 | |
257 | 269 | return 0; |
258 | 270 | } |
@@ -284,17 +296,19 @@ discard block |
||
284 | 296 | if (empty($code) && $this->code_null && empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) |
285 | 297 | { |
286 | 298 | $result=0; |
287 | - } |
|
288 | - else if (empty($code) && (! $this->code_null || ! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) ) |
|
299 | + } else if (empty($code) && (! $this->code_null || ! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) ) |
|
289 | 300 | { |
290 | 301 | $result=-2; |
291 | - } |
|
292 | - else |
|
302 | + } else |
|
293 | 303 | { |
294 | 304 | // Get Mask value |
295 | 305 | $mask = ''; |
296 | - if ($type==0) $mask = empty($conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER)?'':$conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER; |
|
297 | - if ($type==1) $mask = empty($conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER)?'':$conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER; |
|
306 | + if ($type==0) { |
|
307 | + $mask = empty($conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER)?'':$conf->global->COMPANY_ELEPHANT_MASK_CUSTOMER; |
|
308 | + } |
|
309 | + if ($type==1) { |
|
310 | + $mask = empty($conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER)?'':$conf->global->COMPANY_ELEPHANT_MASK_SUPPLIER; |
|
311 | + } |
|
298 | 312 | if (! $mask) |
299 | 313 | { |
300 | 314 | $this->error='NotConfigured'; |
@@ -328,9 +342,14 @@ discard block |
||
328 | 342 | { |
329 | 343 | // phpcs:enable |
330 | 344 | $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe"; |
331 | - if ($type == 1) $sql.= " WHERE code_fournisseur = '".$code."'"; |
|
332 | - else $sql.= " WHERE code_client = '".$code."'"; |
|
333 | - if ($soc->id > 0) $sql.= " AND rowid <> ".$soc->id; |
|
345 | + if ($type == 1) { |
|
346 | + $sql.= " WHERE code_fournisseur = '".$code."'"; |
|
347 | + } else { |
|
348 | + $sql.= " WHERE code_client = '".$code."'"; |
|
349 | + } |
|
350 | + if ($soc->id > 0) { |
|
351 | + $sql.= " AND rowid <> ".$soc->id; |
|
352 | + } |
|
334 | 353 | |
335 | 354 | $resql=$db->query($sql); |
336 | 355 | if ($resql) |
@@ -338,13 +357,11 @@ discard block |
||
338 | 357 | if ($db->num_rows($resql) == 0) |
339 | 358 | { |
340 | 359 | return 0; |
341 | - } |
|
342 | - else |
|
360 | + } else |
|
343 | 361 | { |
344 | 362 | return -1; |
345 | 363 | } |
346 | - } |
|
347 | - else |
|
364 | + } else |
|
348 | 365 | { |
349 | 366 | return -2; |
350 | 367 | } |
@@ -32,259 +32,259 @@ |
||
32 | 32 | */ |
33 | 33 | class mod_codeclient_monkey extends ModeleThirdPartyCode |
34 | 34 | { |
35 | - /** |
|
36 | - * @var string Nom du modele |
|
37 | - * @deprecated |
|
38 | - * @see name |
|
39 | - */ |
|
40 | - public $nom='Monkey'; |
|
35 | + /** |
|
36 | + * @var string Nom du modele |
|
37 | + * @deprecated |
|
38 | + * @see name |
|
39 | + */ |
|
40 | + public $nom='Monkey'; |
|
41 | 41 | |
42 | - /** |
|
43 | - * @var string model name |
|
44 | - */ |
|
45 | - public $name='Monkey'; |
|
42 | + /** |
|
43 | + * @var string model name |
|
44 | + */ |
|
45 | + public $name='Monkey'; |
|
46 | 46 | |
47 | - public $code_modifiable; // Code modifiable |
|
47 | + public $code_modifiable; // Code modifiable |
|
48 | 48 | |
49 | - public $code_modifiable_invalide; // Code modifiable si il est invalide |
|
49 | + public $code_modifiable_invalide; // Code modifiable si il est invalide |
|
50 | 50 | |
51 | - public $code_modifiable_null; // Code modifiables si il est null |
|
51 | + public $code_modifiable_null; // Code modifiables si il est null |
|
52 | 52 | |
53 | - public $code_null; // Code facultatif |
|
53 | + public $code_null; // Code facultatif |
|
54 | 54 | |
55 | - /** |
|
55 | + /** |
|
56 | 56 | * Dolibarr version of the loaded document |
57 | 57 | * @public string |
58 | 58 | */ |
59 | - public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' |
|
60 | - |
|
61 | - public $code_auto; // Numerotation automatique |
|
62 | - |
|
63 | - public $prefixcustomer='CU'; |
|
64 | - |
|
65 | - public $prefixsupplier='SU'; |
|
66 | - |
|
67 | - public $prefixIsRequired; // Le champ prefix du tiers doit etre renseigne quand on utilise {pre} |
|
68 | - |
|
69 | - |
|
70 | - /** |
|
71 | - * Constructor |
|
72 | - */ |
|
73 | - function __construct() |
|
74 | - { |
|
75 | - $this->nom = "Monkey"; |
|
76 | - $this->name = "Monkey"; |
|
77 | - $this->version = "dolibarr"; |
|
78 | - $this->code_null = 1; |
|
79 | - $this->code_modifiable = 1; |
|
80 | - $this->code_modifiable_invalide = 1; |
|
81 | - $this->code_modifiable_null = 1; |
|
82 | - $this->code_auto = 1; |
|
83 | - $this->prefixIsRequired = 0; |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** Return description of module |
|
88 | - * |
|
89 | - * @param Translate $langs Object langs |
|
90 | - * @return string Description of module |
|
91 | - */ |
|
92 | - function info($langs) |
|
93 | - { |
|
94 | - return $langs->trans("MonkeyNumRefModelDesc",$this->prefixcustomer,$this->prefixsupplier); |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * Return an example of result returned by getNextValue |
|
100 | - * |
|
101 | - * @param Translate $langs Object langs |
|
102 | - * @param societe $objsoc Object thirdparty |
|
103 | - * @param int $type Type of third party (1:customer, 2:supplier, -1:autodetect) |
|
104 | - * @return string Return string example |
|
105 | - */ |
|
106 | - function getExample($langs,$objsoc=0,$type=-1) |
|
107 | - { |
|
108 | - return $this->prefixcustomer.'0901-00001<br>'.$this->prefixsupplier.'0901-00001'; |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * Return next value |
|
114 | - * |
|
115 | - * @param Societe $objsoc Object third party |
|
116 | - * @param int $type Client ou fournisseur (1:client, 2:fournisseur) |
|
117 | - * @return string Value if OK, '' if module not configured, <0 if KO |
|
118 | - */ |
|
119 | - function getNextValue($objsoc=0,$type=-1) |
|
120 | - { |
|
121 | - global $db, $conf, $mc; |
|
122 | - |
|
123 | - $field=''; |
|
59 | + public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' |
|
60 | + |
|
61 | + public $code_auto; // Numerotation automatique |
|
62 | + |
|
63 | + public $prefixcustomer='CU'; |
|
64 | + |
|
65 | + public $prefixsupplier='SU'; |
|
66 | + |
|
67 | + public $prefixIsRequired; // Le champ prefix du tiers doit etre renseigne quand on utilise {pre} |
|
68 | + |
|
69 | + |
|
70 | + /** |
|
71 | + * Constructor |
|
72 | + */ |
|
73 | + function __construct() |
|
74 | + { |
|
75 | + $this->nom = "Monkey"; |
|
76 | + $this->name = "Monkey"; |
|
77 | + $this->version = "dolibarr"; |
|
78 | + $this->code_null = 1; |
|
79 | + $this->code_modifiable = 1; |
|
80 | + $this->code_modifiable_invalide = 1; |
|
81 | + $this->code_modifiable_null = 1; |
|
82 | + $this->code_auto = 1; |
|
83 | + $this->prefixIsRequired = 0; |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** Return description of module |
|
88 | + * |
|
89 | + * @param Translate $langs Object langs |
|
90 | + * @return string Description of module |
|
91 | + */ |
|
92 | + function info($langs) |
|
93 | + { |
|
94 | + return $langs->trans("MonkeyNumRefModelDesc",$this->prefixcustomer,$this->prefixsupplier); |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * Return an example of result returned by getNextValue |
|
100 | + * |
|
101 | + * @param Translate $langs Object langs |
|
102 | + * @param societe $objsoc Object thirdparty |
|
103 | + * @param int $type Type of third party (1:customer, 2:supplier, -1:autodetect) |
|
104 | + * @return string Return string example |
|
105 | + */ |
|
106 | + function getExample($langs,$objsoc=0,$type=-1) |
|
107 | + { |
|
108 | + return $this->prefixcustomer.'0901-00001<br>'.$this->prefixsupplier.'0901-00001'; |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * Return next value |
|
114 | + * |
|
115 | + * @param Societe $objsoc Object third party |
|
116 | + * @param int $type Client ou fournisseur (1:client, 2:fournisseur) |
|
117 | + * @return string Value if OK, '' if module not configured, <0 if KO |
|
118 | + */ |
|
119 | + function getNextValue($objsoc=0,$type=-1) |
|
120 | + { |
|
121 | + global $db, $conf, $mc; |
|
122 | + |
|
123 | + $field=''; |
|
124 | 124 | $prefix = ''; |
125 | - if ($type == 0) { |
|
126 | - $field = 'code_client'; |
|
125 | + if ($type == 0) { |
|
126 | + $field = 'code_client'; |
|
127 | 127 | $prefix = $this->prefixcustomer; |
128 | - } elseif ($type == 1) { |
|
129 | - $field = 'code_fournisseur'; |
|
128 | + } elseif ($type == 1) { |
|
129 | + $field = 'code_fournisseur'; |
|
130 | 130 | $prefix = $this->prefixsupplier; |
131 | - } else { |
|
131 | + } else { |
|
132 | 132 | return -1; |
133 | 133 | } |
134 | 134 | |
135 | 135 | // D'abord on recupere la valeur max (reponse immediate car champ indexe) |
136 | - $posindice=8; |
|
136 | + $posindice=8; |
|
137 | 137 | $sql = "SELECT MAX(CAST(SUBSTRING(".$field." FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL |
138 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe"; |
|
139 | - $sql.= " WHERE ".$field." LIKE '".$prefix."____-%'"; |
|
140 | - $sql.= " AND entity IN (".getEntity('societe').")"; |
|
141 | - |
|
142 | - dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG); |
|
143 | - |
|
144 | - $resql=$db->query($sql); |
|
145 | - if ($resql) |
|
146 | - { |
|
147 | - $obj = $db->fetch_object($resql); |
|
148 | - if ($obj) $max = intval($obj->max); |
|
149 | - else $max=0; |
|
150 | - } |
|
151 | - else |
|
152 | - { |
|
153 | - return -1; |
|
154 | - } |
|
155 | - |
|
156 | - $date = dol_now(); |
|
157 | - $yymm = strftime("%y%m",$date); |
|
158 | - |
|
159 | - if ($max >= (pow(10, 5) - 1)) $num=$max+1; // If counter > 99999, we do not format on 5 chars, we take number as it is |
|
160 | - else $num = sprintf("%05s",$max+1); |
|
161 | - |
|
162 | - dol_syslog(get_class($this)."::getNextValue return ".$prefix.$yymm."-".$num); |
|
163 | - return $prefix.$yymm."-".$num; |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * Check validity of code according to its rules |
|
169 | - * |
|
170 | - * @param DoliDB $db Database handler |
|
171 | - * @param string $code Code to check/correct |
|
172 | - * @param Societe $soc Object third party |
|
173 | - * @param int $type 0 = customer/prospect , 1 = supplier |
|
174 | - * @return int 0 if OK |
|
175 | - * -1 ErrorBadCustomerCodeSyntax |
|
176 | - * -2 ErrorCustomerCodeRequired |
|
177 | - * -3 ErrorCustomerCodeAlreadyUsed |
|
178 | - * -4 ErrorPrefixRequired |
|
179 | - */ |
|
180 | - function verif($db, &$code, $soc, $type) |
|
181 | - { |
|
182 | - global $conf; |
|
183 | - |
|
184 | - $result=0; |
|
185 | - $code = strtoupper(trim($code)); |
|
186 | - |
|
187 | - if (empty($code) && $this->code_null && empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) |
|
188 | - { |
|
189 | - $result=0; |
|
190 | - } |
|
191 | - else if (empty($code) && (! $this->code_null || ! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) ) |
|
192 | - { |
|
193 | - $result=-2; |
|
194 | - } |
|
195 | - else |
|
196 | - { |
|
197 | - if ($this->verif_syntax($code) >= 0) |
|
198 | - { |
|
199 | - $is_dispo = $this->verif_dispo($db, $code, $soc, $type); |
|
200 | - if ($is_dispo <> 0) |
|
201 | - { |
|
202 | - $result=-3; |
|
203 | - } |
|
204 | - else |
|
205 | - { |
|
206 | - $result=0; |
|
207 | - } |
|
208 | - } |
|
209 | - else |
|
210 | - { |
|
211 | - if (dol_strlen($code) == 0) |
|
212 | - { |
|
213 | - $result=-2; |
|
214 | - } |
|
215 | - else |
|
216 | - { |
|
217 | - $result=-1; |
|
218 | - } |
|
219 | - } |
|
220 | - } |
|
221 | - |
|
222 | - dol_syslog(get_class($this)."::verif code=".$code." type=".$type." result=".$result); |
|
223 | - return $result; |
|
224 | - } |
|
138 | + $sql.= " FROM ".MAIN_DB_PREFIX."societe"; |
|
139 | + $sql.= " WHERE ".$field." LIKE '".$prefix."____-%'"; |
|
140 | + $sql.= " AND entity IN (".getEntity('societe').")"; |
|
141 | + |
|
142 | + dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG); |
|
143 | + |
|
144 | + $resql=$db->query($sql); |
|
145 | + if ($resql) |
|
146 | + { |
|
147 | + $obj = $db->fetch_object($resql); |
|
148 | + if ($obj) $max = intval($obj->max); |
|
149 | + else $max=0; |
|
150 | + } |
|
151 | + else |
|
152 | + { |
|
153 | + return -1; |
|
154 | + } |
|
155 | + |
|
156 | + $date = dol_now(); |
|
157 | + $yymm = strftime("%y%m",$date); |
|
158 | + |
|
159 | + if ($max >= (pow(10, 5) - 1)) $num=$max+1; // If counter > 99999, we do not format on 5 chars, we take number as it is |
|
160 | + else $num = sprintf("%05s",$max+1); |
|
161 | + |
|
162 | + dol_syslog(get_class($this)."::getNextValue return ".$prefix.$yymm."-".$num); |
|
163 | + return $prefix.$yymm."-".$num; |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * Check validity of code according to its rules |
|
169 | + * |
|
170 | + * @param DoliDB $db Database handler |
|
171 | + * @param string $code Code to check/correct |
|
172 | + * @param Societe $soc Object third party |
|
173 | + * @param int $type 0 = customer/prospect , 1 = supplier |
|
174 | + * @return int 0 if OK |
|
175 | + * -1 ErrorBadCustomerCodeSyntax |
|
176 | + * -2 ErrorCustomerCodeRequired |
|
177 | + * -3 ErrorCustomerCodeAlreadyUsed |
|
178 | + * -4 ErrorPrefixRequired |
|
179 | + */ |
|
180 | + function verif($db, &$code, $soc, $type) |
|
181 | + { |
|
182 | + global $conf; |
|
183 | + |
|
184 | + $result=0; |
|
185 | + $code = strtoupper(trim($code)); |
|
186 | + |
|
187 | + if (empty($code) && $this->code_null && empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) |
|
188 | + { |
|
189 | + $result=0; |
|
190 | + } |
|
191 | + else if (empty($code) && (! $this->code_null || ! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) ) |
|
192 | + { |
|
193 | + $result=-2; |
|
194 | + } |
|
195 | + else |
|
196 | + { |
|
197 | + if ($this->verif_syntax($code) >= 0) |
|
198 | + { |
|
199 | + $is_dispo = $this->verif_dispo($db, $code, $soc, $type); |
|
200 | + if ($is_dispo <> 0) |
|
201 | + { |
|
202 | + $result=-3; |
|
203 | + } |
|
204 | + else |
|
205 | + { |
|
206 | + $result=0; |
|
207 | + } |
|
208 | + } |
|
209 | + else |
|
210 | + { |
|
211 | + if (dol_strlen($code) == 0) |
|
212 | + { |
|
213 | + $result=-2; |
|
214 | + } |
|
215 | + else |
|
216 | + { |
|
217 | + $result=-1; |
|
218 | + } |
|
219 | + } |
|
220 | + } |
|
221 | + |
|
222 | + dol_syslog(get_class($this)."::verif code=".$code." type=".$type." result=".$result); |
|
223 | + return $result; |
|
224 | + } |
|
225 | 225 | |
226 | 226 | |
227 | 227 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
228 | - /** |
|
229 | - * Renvoi si un code est pris ou non (par autre tiers) |
|
230 | - * |
|
231 | - * @param DoliDB $db Handler acces base |
|
232 | - * @param string $code Code a verifier |
|
233 | - * @param Societe $soc Objet societe |
|
234 | - * @param int $type 0 = customer/prospect , 1 = supplier |
|
235 | - * @return int 0 if available, <0 if KO |
|
236 | - */ |
|
237 | - function verif_dispo($db, $code, $soc, $type=0) |
|
238 | - { |
|
228 | + /** |
|
229 | + * Renvoi si un code est pris ou non (par autre tiers) |
|
230 | + * |
|
231 | + * @param DoliDB $db Handler acces base |
|
232 | + * @param string $code Code a verifier |
|
233 | + * @param Societe $soc Objet societe |
|
234 | + * @param int $type 0 = customer/prospect , 1 = supplier |
|
235 | + * @return int 0 if available, <0 if KO |
|
236 | + */ |
|
237 | + function verif_dispo($db, $code, $soc, $type=0) |
|
238 | + { |
|
239 | 239 | // phpcs:enable |
240 | - global $conf, $mc; |
|
241 | - |
|
242 | - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe"; |
|
243 | - if ($type == 1) $sql.= " WHERE code_fournisseur = '".$code."'"; |
|
244 | - else $sql.= " WHERE code_client = '".$code."'"; |
|
245 | - $sql.= " AND entity IN (".getEntity('societe').")"; |
|
246 | - if ($soc->id > 0) $sql.= " AND rowid <> ".$soc->id; |
|
247 | - |
|
248 | - dol_syslog(get_class($this)."::verif_dispo", LOG_DEBUG); |
|
249 | - $resql=$db->query($sql); |
|
250 | - if ($resql) |
|
251 | - { |
|
252 | - if ($db->num_rows($resql) == 0) |
|
253 | - { |
|
254 | - return 0; |
|
255 | - } |
|
256 | - else |
|
257 | - { |
|
258 | - return -1; |
|
259 | - } |
|
260 | - } |
|
261 | - else |
|
262 | - { |
|
263 | - return -2; |
|
264 | - } |
|
265 | - } |
|
240 | + global $conf, $mc; |
|
241 | + |
|
242 | + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe"; |
|
243 | + if ($type == 1) $sql.= " WHERE code_fournisseur = '".$code."'"; |
|
244 | + else $sql.= " WHERE code_client = '".$code."'"; |
|
245 | + $sql.= " AND entity IN (".getEntity('societe').")"; |
|
246 | + if ($soc->id > 0) $sql.= " AND rowid <> ".$soc->id; |
|
247 | + |
|
248 | + dol_syslog(get_class($this)."::verif_dispo", LOG_DEBUG); |
|
249 | + $resql=$db->query($sql); |
|
250 | + if ($resql) |
|
251 | + { |
|
252 | + if ($db->num_rows($resql) == 0) |
|
253 | + { |
|
254 | + return 0; |
|
255 | + } |
|
256 | + else |
|
257 | + { |
|
258 | + return -1; |
|
259 | + } |
|
260 | + } |
|
261 | + else |
|
262 | + { |
|
263 | + return -2; |
|
264 | + } |
|
265 | + } |
|
266 | 266 | |
267 | 267 | |
268 | 268 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
269 | - /** |
|
270 | - * Renvoi si un code respecte la syntaxe |
|
271 | - * |
|
272 | - * @param string $code Code a verifier |
|
273 | - * @return int 0 si OK, <0 si KO |
|
274 | - */ |
|
275 | - function verif_syntax($code) |
|
276 | - { |
|
269 | + /** |
|
270 | + * Renvoi si un code respecte la syntaxe |
|
271 | + * |
|
272 | + * @param string $code Code a verifier |
|
273 | + * @return int 0 si OK, <0 si KO |
|
274 | + */ |
|
275 | + function verif_syntax($code) |
|
276 | + { |
|
277 | 277 | // phpcs:enable |
278 | - $res = 0; |
|
279 | - |
|
280 | - if (dol_strlen($code) < 11) |
|
281 | - { |
|
282 | - $res = -1; |
|
283 | - } |
|
284 | - else |
|
285 | - { |
|
286 | - $res = 0; |
|
287 | - } |
|
288 | - return $res; |
|
289 | - } |
|
278 | + $res = 0; |
|
279 | + |
|
280 | + if (dol_strlen($code) < 11) |
|
281 | + { |
|
282 | + $res = -1; |
|
283 | + } |
|
284 | + else |
|
285 | + { |
|
286 | + $res = 0; |
|
287 | + } |
|
288 | + return $res; |
|
289 | + } |
|
290 | 290 | } |
@@ -37,32 +37,32 @@ discard block |
||
37 | 37 | * @deprecated |
38 | 38 | * @see name |
39 | 39 | */ |
40 | - public $nom='Monkey'; |
|
40 | + public $nom = 'Monkey'; |
|
41 | 41 | |
42 | 42 | /** |
43 | 43 | * @var string model name |
44 | 44 | */ |
45 | - public $name='Monkey'; |
|
45 | + public $name = 'Monkey'; |
|
46 | 46 | |
47 | - public $code_modifiable; // Code modifiable |
|
47 | + public $code_modifiable; // Code modifiable |
|
48 | 48 | |
49 | - public $code_modifiable_invalide; // Code modifiable si il est invalide |
|
49 | + public $code_modifiable_invalide; // Code modifiable si il est invalide |
|
50 | 50 | |
51 | - public $code_modifiable_null; // Code modifiables si il est null |
|
51 | + public $code_modifiable_null; // Code modifiables si il est null |
|
52 | 52 | |
53 | - public $code_null; // Code facultatif |
|
53 | + public $code_null; // Code facultatif |
|
54 | 54 | |
55 | 55 | /** |
56 | 56 | * Dolibarr version of the loaded document |
57 | 57 | * @public string |
58 | 58 | */ |
59 | - public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' |
|
59 | + public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' |
|
60 | 60 | |
61 | - public $code_auto; // Numerotation automatique |
|
61 | + public $code_auto; // Numerotation automatique |
|
62 | 62 | |
63 | - public $prefixcustomer='CU'; |
|
63 | + public $prefixcustomer = 'CU'; |
|
64 | 64 | |
65 | - public $prefixsupplier='SU'; |
|
65 | + public $prefixsupplier = 'SU'; |
|
66 | 66 | |
67 | 67 | public $prefixIsRequired; // Le champ prefix du tiers doit etre renseigne quand on utilise {pre} |
68 | 68 | |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | */ |
92 | 92 | function info($langs) |
93 | 93 | { |
94 | - return $langs->trans("MonkeyNumRefModelDesc",$this->prefixcustomer,$this->prefixsupplier); |
|
94 | + return $langs->trans("MonkeyNumRefModelDesc", $this->prefixcustomer, $this->prefixsupplier); |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | * @param int $type Type of third party (1:customer, 2:supplier, -1:autodetect) |
104 | 104 | * @return string Return string example |
105 | 105 | */ |
106 | - function getExample($langs,$objsoc=0,$type=-1) |
|
106 | + function getExample($langs, $objsoc = 0, $type = -1) |
|
107 | 107 | { |
108 | 108 | return $this->prefixcustomer.'0901-00001<br>'.$this->prefixsupplier.'0901-00001'; |
109 | 109 | } |
@@ -116,11 +116,11 @@ discard block |
||
116 | 116 | * @param int $type Client ou fournisseur (1:client, 2:fournisseur) |
117 | 117 | * @return string Value if OK, '' if module not configured, <0 if KO |
118 | 118 | */ |
119 | - function getNextValue($objsoc=0,$type=-1) |
|
119 | + function getNextValue($objsoc = 0, $type = -1) |
|
120 | 120 | { |
121 | 121 | global $db, $conf, $mc; |
122 | 122 | |
123 | - $field=''; |
|
123 | + $field = ''; |
|
124 | 124 | $prefix = ''; |
125 | 125 | if ($type == 0) { |
126 | 126 | $field = 'code_client'; |
@@ -133,20 +133,20 @@ discard block |
||
133 | 133 | } |
134 | 134 | |
135 | 135 | // D'abord on recupere la valeur max (reponse immediate car champ indexe) |
136 | - $posindice=8; |
|
137 | - $sql = "SELECT MAX(CAST(SUBSTRING(".$field." FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL |
|
138 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe"; |
|
139 | - $sql.= " WHERE ".$field." LIKE '".$prefix."____-%'"; |
|
140 | - $sql.= " AND entity IN (".getEntity('societe').")"; |
|
136 | + $posindice = 8; |
|
137 | + $sql = "SELECT MAX(CAST(SUBSTRING(".$field." FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL |
|
138 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe"; |
|
139 | + $sql .= " WHERE ".$field." LIKE '".$prefix."____-%'"; |
|
140 | + $sql .= " AND entity IN (".getEntity('societe').")"; |
|
141 | 141 | |
142 | 142 | dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG); |
143 | 143 | |
144 | - $resql=$db->query($sql); |
|
144 | + $resql = $db->query($sql); |
|
145 | 145 | if ($resql) |
146 | 146 | { |
147 | 147 | $obj = $db->fetch_object($resql); |
148 | 148 | if ($obj) $max = intval($obj->max); |
149 | - else $max=0; |
|
149 | + else $max = 0; |
|
150 | 150 | } |
151 | 151 | else |
152 | 152 | { |
@@ -154,10 +154,10 @@ discard block |
||
154 | 154 | } |
155 | 155 | |
156 | 156 | $date = dol_now(); |
157 | - $yymm = strftime("%y%m",$date); |
|
157 | + $yymm = strftime("%y%m", $date); |
|
158 | 158 | |
159 | - if ($max >= (pow(10, 5) - 1)) $num=$max+1; // If counter > 99999, we do not format on 5 chars, we take number as it is |
|
160 | - else $num = sprintf("%05s",$max+1); |
|
159 | + if ($max >= (pow(10, 5) - 1)) $num = $max + 1; // If counter > 99999, we do not format on 5 chars, we take number as it is |
|
160 | + else $num = sprintf("%05s", $max + 1); |
|
161 | 161 | |
162 | 162 | dol_syslog(get_class($this)."::getNextValue return ".$prefix.$yymm."-".$num); |
163 | 163 | return $prefix.$yymm."-".$num; |
@@ -181,16 +181,16 @@ discard block |
||
181 | 181 | { |
182 | 182 | global $conf; |
183 | 183 | |
184 | - $result=0; |
|
184 | + $result = 0; |
|
185 | 185 | $code = strtoupper(trim($code)); |
186 | 186 | |
187 | 187 | if (empty($code) && $this->code_null && empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) |
188 | 188 | { |
189 | - $result=0; |
|
189 | + $result = 0; |
|
190 | 190 | } |
191 | - else if (empty($code) && (! $this->code_null || ! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) ) |
|
191 | + else if (empty($code) && (!$this->code_null || !empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED))) |
|
192 | 192 | { |
193 | - $result=-2; |
|
193 | + $result = -2; |
|
194 | 194 | } |
195 | 195 | else |
196 | 196 | { |
@@ -199,22 +199,22 @@ discard block |
||
199 | 199 | $is_dispo = $this->verif_dispo($db, $code, $soc, $type); |
200 | 200 | if ($is_dispo <> 0) |
201 | 201 | { |
202 | - $result=-3; |
|
202 | + $result = -3; |
|
203 | 203 | } |
204 | 204 | else |
205 | 205 | { |
206 | - $result=0; |
|
206 | + $result = 0; |
|
207 | 207 | } |
208 | 208 | } |
209 | 209 | else |
210 | 210 | { |
211 | 211 | if (dol_strlen($code) == 0) |
212 | 212 | { |
213 | - $result=-2; |
|
213 | + $result = -2; |
|
214 | 214 | } |
215 | 215 | else |
216 | 216 | { |
217 | - $result=-1; |
|
217 | + $result = -1; |
|
218 | 218 | } |
219 | 219 | } |
220 | 220 | } |
@@ -234,19 +234,19 @@ discard block |
||
234 | 234 | * @param int $type 0 = customer/prospect , 1 = supplier |
235 | 235 | * @return int 0 if available, <0 if KO |
236 | 236 | */ |
237 | - function verif_dispo($db, $code, $soc, $type=0) |
|
237 | + function verif_dispo($db, $code, $soc, $type = 0) |
|
238 | 238 | { |
239 | 239 | // phpcs:enable |
240 | 240 | global $conf, $mc; |
241 | 241 | |
242 | 242 | $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe"; |
243 | - if ($type == 1) $sql.= " WHERE code_fournisseur = '".$code."'"; |
|
244 | - else $sql.= " WHERE code_client = '".$code."'"; |
|
245 | - $sql.= " AND entity IN (".getEntity('societe').")"; |
|
246 | - if ($soc->id > 0) $sql.= " AND rowid <> ".$soc->id; |
|
243 | + if ($type == 1) $sql .= " WHERE code_fournisseur = '".$code."'"; |
|
244 | + else $sql .= " WHERE code_client = '".$code."'"; |
|
245 | + $sql .= " AND entity IN (".getEntity('societe').")"; |
|
246 | + if ($soc->id > 0) $sql .= " AND rowid <> ".$soc->id; |
|
247 | 247 | |
248 | 248 | dol_syslog(get_class($this)."::verif_dispo", LOG_DEBUG); |
249 | - $resql=$db->query($sql); |
|
249 | + $resql = $db->query($sql); |
|
250 | 250 | if ($resql) |
251 | 251 | { |
252 | 252 | if ($db->num_rows($resql) == 0) |
@@ -145,10 +145,12 @@ discard block |
||
145 | 145 | if ($resql) |
146 | 146 | { |
147 | 147 | $obj = $db->fetch_object($resql); |
148 | - if ($obj) $max = intval($obj->max); |
|
149 | - else $max=0; |
|
150 | - } |
|
151 | - else |
|
148 | + if ($obj) { |
|
149 | + $max = intval($obj->max); |
|
150 | + } else { |
|
151 | + $max=0; |
|
152 | + } |
|
153 | + } else |
|
152 | 154 | { |
153 | 155 | return -1; |
154 | 156 | } |
@@ -156,8 +158,13 @@ discard block |
||
156 | 158 | $date = dol_now(); |
157 | 159 | $yymm = strftime("%y%m",$date); |
158 | 160 | |
159 | - if ($max >= (pow(10, 5) - 1)) $num=$max+1; // If counter > 99999, we do not format on 5 chars, we take number as it is |
|
160 | - else $num = sprintf("%05s",$max+1); |
|
161 | + if ($max >= (pow(10, 5) - 1)) { |
|
162 | + $num=$max+1; |
|
163 | + } |
|
164 | + // If counter > 99999, we do not format on 5 chars, we take number as it is |
|
165 | + else { |
|
166 | + $num = sprintf("%05s",$max+1); |
|
167 | + } |
|
161 | 168 | |
162 | 169 | dol_syslog(get_class($this)."::getNextValue return ".$prefix.$yymm."-".$num); |
163 | 170 | return $prefix.$yymm."-".$num; |
@@ -187,12 +194,10 @@ discard block |
||
187 | 194 | if (empty($code) && $this->code_null && empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) |
188 | 195 | { |
189 | 196 | $result=0; |
190 | - } |
|
191 | - else if (empty($code) && (! $this->code_null || ! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) ) |
|
197 | + } else if (empty($code) && (! $this->code_null || ! empty($conf->global->MAIN_COMPANY_CODE_ALWAYS_REQUIRED)) ) |
|
192 | 198 | { |
193 | 199 | $result=-2; |
194 | - } |
|
195 | - else |
|
200 | + } else |
|
196 | 201 | { |
197 | 202 | if ($this->verif_syntax($code) >= 0) |
198 | 203 | { |
@@ -200,19 +205,16 @@ discard block |
||
200 | 205 | if ($is_dispo <> 0) |
201 | 206 | { |
202 | 207 | $result=-3; |
203 | - } |
|
204 | - else |
|
208 | + } else |
|
205 | 209 | { |
206 | 210 | $result=0; |
207 | 211 | } |
208 | - } |
|
209 | - else |
|
212 | + } else |
|
210 | 213 | { |
211 | 214 | if (dol_strlen($code) == 0) |
212 | 215 | { |
213 | 216 | $result=-2; |
214 | - } |
|
215 | - else |
|
217 | + } else |
|
216 | 218 | { |
217 | 219 | $result=-1; |
218 | 220 | } |
@@ -240,10 +242,15 @@ discard block |
||
240 | 242 | global $conf, $mc; |
241 | 243 | |
242 | 244 | $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe"; |
243 | - if ($type == 1) $sql.= " WHERE code_fournisseur = '".$code."'"; |
|
244 | - else $sql.= " WHERE code_client = '".$code."'"; |
|
245 | + if ($type == 1) { |
|
246 | + $sql.= " WHERE code_fournisseur = '".$code."'"; |
|
247 | + } else { |
|
248 | + $sql.= " WHERE code_client = '".$code."'"; |
|
249 | + } |
|
245 | 250 | $sql.= " AND entity IN (".getEntity('societe').")"; |
246 | - if ($soc->id > 0) $sql.= " AND rowid <> ".$soc->id; |
|
251 | + if ($soc->id > 0) { |
|
252 | + $sql.= " AND rowid <> ".$soc->id; |
|
253 | + } |
|
247 | 254 | |
248 | 255 | dol_syslog(get_class($this)."::verif_dispo", LOG_DEBUG); |
249 | 256 | $resql=$db->query($sql); |
@@ -252,13 +259,11 @@ discard block |
||
252 | 259 | if ($db->num_rows($resql) == 0) |
253 | 260 | { |
254 | 261 | return 0; |
255 | - } |
|
256 | - else |
|
262 | + } else |
|
257 | 263 | { |
258 | 264 | return -1; |
259 | 265 | } |
260 | - } |
|
261 | - else |
|
266 | + } else |
|
262 | 267 | { |
263 | 268 | return -2; |
264 | 269 | } |
@@ -280,8 +285,7 @@ discard block |
||
280 | 285 | if (dol_strlen($code) < 11) |
281 | 286 | { |
282 | 287 | $res = -1; |
283 | - } |
|
284 | - else |
|
288 | + } else |
|
285 | 289 | { |
286 | 290 | $res = 0; |
287 | 291 | } |
@@ -30,76 +30,76 @@ |
||
30 | 30 | */ |
31 | 31 | class mod_codecompta_panicum extends ModeleAccountancyCode |
32 | 32 | { |
33 | - /** |
|
34 | - * @var string Nom du modele |
|
35 | - * @deprecated |
|
36 | - * @see name |
|
37 | - */ |
|
38 | - public $nom='Panicum'; |
|
33 | + /** |
|
34 | + * @var string Nom du modele |
|
35 | + * @deprecated |
|
36 | + * @see name |
|
37 | + */ |
|
38 | + public $nom='Panicum'; |
|
39 | 39 | |
40 | - /** |
|
41 | - * @var string model name |
|
42 | - */ |
|
43 | - public $name='Panicum'; |
|
40 | + /** |
|
41 | + * @var string model name |
|
42 | + */ |
|
43 | + public $name='Panicum'; |
|
44 | 44 | |
45 | - /** |
|
45 | + /** |
|
46 | 46 | * Dolibarr version of the loaded document |
47 | 47 | * @public string |
48 | 48 | */ |
49 | - public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' |
|
49 | + public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * Constructor |
|
54 | - */ |
|
55 | - function __construct() |
|
56 | - { |
|
57 | - } |
|
52 | + /** |
|
53 | + * Constructor |
|
54 | + */ |
|
55 | + function __construct() |
|
56 | + { |
|
57 | + } |
|
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * Return description of module |
|
62 | - * |
|
63 | - * @param Translate $langs Object langs |
|
64 | - * @return string Description of module |
|
65 | - */ |
|
66 | - function info($langs) |
|
67 | - { |
|
68 | - return $langs->trans("ModuleCompanyCode".$this->name); |
|
69 | - } |
|
60 | + /** |
|
61 | + * Return description of module |
|
62 | + * |
|
63 | + * @param Translate $langs Object langs |
|
64 | + * @return string Description of module |
|
65 | + */ |
|
66 | + function info($langs) |
|
67 | + { |
|
68 | + return $langs->trans("ModuleCompanyCode".$this->name); |
|
69 | + } |
|
70 | 70 | |
71 | - /** |
|
72 | - * Return an example of result returned by getNextValue |
|
73 | - * |
|
74 | - * @param Translate $langs Object langs |
|
75 | - * @param Societe $objsoc Object thirdparty |
|
76 | - * @param int $type Type of third party (1:customer, 2:supplier, -1:autodetect) |
|
77 | - * @return string Example |
|
78 | - */ |
|
79 | - function getExample($langs,$objsoc=0,$type=-1) |
|
80 | - { |
|
81 | - return ''; |
|
82 | - } |
|
71 | + /** |
|
72 | + * Return an example of result returned by getNextValue |
|
73 | + * |
|
74 | + * @param Translate $langs Object langs |
|
75 | + * @param Societe $objsoc Object thirdparty |
|
76 | + * @param int $type Type of third party (1:customer, 2:supplier, -1:autodetect) |
|
77 | + * @return string Example |
|
78 | + */ |
|
79 | + function getExample($langs,$objsoc=0,$type=-1) |
|
80 | + { |
|
81 | + return ''; |
|
82 | + } |
|
83 | 83 | |
84 | 84 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
85 | - /** |
|
86 | - * Set accountancy account code for a third party into this->code |
|
87 | - * |
|
88 | - * @param DoliDB $db Database handler |
|
89 | - * @param Societe $societe Third party object |
|
90 | - * @param int $type 'customer' or 'supplier' |
|
91 | - * @return int >=0 if OK, <0 if KO |
|
92 | - */ |
|
93 | - function get_code($db, $societe, $type='') |
|
94 | - { |
|
85 | + /** |
|
86 | + * Set accountancy account code for a third party into this->code |
|
87 | + * |
|
88 | + * @param DoliDB $db Database handler |
|
89 | + * @param Societe $societe Third party object |
|
90 | + * @param int $type 'customer' or 'supplier' |
|
91 | + * @return int >=0 if OK, <0 if KO |
|
92 | + */ |
|
93 | + function get_code($db, $societe, $type='') |
|
94 | + { |
|
95 | 95 | // phpcs:enable |
96 | - $this->code=''; |
|
96 | + $this->code=''; |
|
97 | 97 | |
98 | - if (is_object($societe)) { |
|
99 | - if ($type == 'supplier') $this->code = (! empty($societe->code_compta_fournisseur)?$societe->code_compta_fournisseur:''); |
|
100 | - else $this->code = (! empty($societe->code_compta)?$societe->code_compta:''); |
|
101 | - } |
|
98 | + if (is_object($societe)) { |
|
99 | + if ($type == 'supplier') $this->code = (! empty($societe->code_compta_fournisseur)?$societe->code_compta_fournisseur:''); |
|
100 | + else $this->code = (! empty($societe->code_compta)?$societe->code_compta:''); |
|
101 | + } |
|
102 | 102 | |
103 | - return 0; // return ok |
|
104 | - } |
|
103 | + return 0; // return ok |
|
104 | + } |
|
105 | 105 | } |
@@ -35,18 +35,18 @@ discard block |
||
35 | 35 | * @deprecated |
36 | 36 | * @see name |
37 | 37 | */ |
38 | - public $nom='Panicum'; |
|
38 | + public $nom = 'Panicum'; |
|
39 | 39 | |
40 | 40 | /** |
41 | 41 | * @var string model name |
42 | 42 | */ |
43 | - public $name='Panicum'; |
|
43 | + public $name = 'Panicum'; |
|
44 | 44 | |
45 | 45 | /** |
46 | 46 | * Dolibarr version of the loaded document |
47 | 47 | * @public string |
48 | 48 | */ |
49 | - public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' |
|
49 | + public $version = 'dolibarr'; // 'development', 'experimental', 'dolibarr' |
|
50 | 50 | |
51 | 51 | |
52 | 52 | /** |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | * @param int $type Type of third party (1:customer, 2:supplier, -1:autodetect) |
77 | 77 | * @return string Example |
78 | 78 | */ |
79 | - function getExample($langs,$objsoc=0,$type=-1) |
|
79 | + function getExample($langs, $objsoc = 0, $type = -1) |
|
80 | 80 | { |
81 | 81 | return ''; |
82 | 82 | } |
@@ -90,14 +90,14 @@ discard block |
||
90 | 90 | * @param int $type 'customer' or 'supplier' |
91 | 91 | * @return int >=0 if OK, <0 if KO |
92 | 92 | */ |
93 | - function get_code($db, $societe, $type='') |
|
93 | + function get_code($db, $societe, $type = '') |
|
94 | 94 | { |
95 | 95 | // phpcs:enable |
96 | - $this->code=''; |
|
96 | + $this->code = ''; |
|
97 | 97 | |
98 | 98 | if (is_object($societe)) { |
99 | - if ($type == 'supplier') $this->code = (! empty($societe->code_compta_fournisseur)?$societe->code_compta_fournisseur:''); |
|
100 | - else $this->code = (! empty($societe->code_compta)?$societe->code_compta:''); |
|
99 | + if ($type == 'supplier') $this->code = (!empty($societe->code_compta_fournisseur) ? $societe->code_compta_fournisseur : ''); |
|
100 | + else $this->code = (!empty($societe->code_compta) ? $societe->code_compta : ''); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | return 0; // return ok |
@@ -96,8 +96,11 @@ |
||
96 | 96 | $this->code=''; |
97 | 97 | |
98 | 98 | if (is_object($societe)) { |
99 | - if ($type == 'supplier') $this->code = (! empty($societe->code_compta_fournisseur)?$societe->code_compta_fournisseur:''); |
|
100 | - else $this->code = (! empty($societe->code_compta)?$societe->code_compta:''); |
|
99 | + if ($type == 'supplier') { |
|
100 | + $this->code = (! empty($societe->code_compta_fournisseur)?$societe->code_compta_fournisseur:''); |
|
101 | + } else { |
|
102 | + $this->code = (! empty($societe->code_compta)?$societe->code_compta:''); |
|
103 | + } |
|
101 | 104 | } |
102 | 105 | |
103 | 106 | return 0; // return ok |