@@ -28,1644 +28,1644 @@ |
||
28 | 28 | */ |
29 | 29 | class Thirdparties extends DolibarrApi |
30 | 30 | { |
31 | - /** |
|
32 | - * |
|
33 | - * @var array $FIELDS Mandatory fields, checked when create and update object |
|
34 | - */ |
|
35 | - static $FIELDS = array( |
|
36 | - 'name' |
|
37 | - ); |
|
38 | - |
|
39 | - /** |
|
40 | - * @var Societe $company {@type Societe} |
|
41 | - */ |
|
42 | - public $company; |
|
43 | - |
|
44 | - /** |
|
45 | - * Constructor |
|
46 | - */ |
|
47 | - function __construct() |
|
48 | - { |
|
49 | - global $db, $conf; |
|
50 | - $this->db = $db; |
|
51 | - |
|
52 | - require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; |
|
53 | - require_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php'; |
|
54 | - require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; |
|
55 | - require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php'; |
|
56 | - |
|
57 | - $this->company = new Societe($this->db); |
|
58 | - |
|
59 | - if (! empty($conf->global->SOCIETE_EMAIL_MANDATORY)) { |
|
60 | - static::$FIELDS[] = 'email'; |
|
61 | - } |
|
62 | - } |
|
63 | - |
|
64 | - /** |
|
65 | - * Get properties of a thirdparty object |
|
66 | - * |
|
67 | - * Return an array with thirdparty informations |
|
68 | - * |
|
69 | - * @param int $id ID of thirdparty |
|
70 | - * @return array|mixed data without useless information |
|
71 | - * |
|
72 | - * @throws RestException |
|
73 | - */ |
|
74 | - function get($id) |
|
75 | - { |
|
76 | - if(! DolibarrApiAccess::$user->rights->societe->lire) { |
|
77 | - throw new RestException(401); |
|
78 | - } |
|
79 | - |
|
80 | - $result = $this->company->fetch($id); |
|
81 | - if( ! $result ) { |
|
82 | - throw new RestException(404, 'Thirdparty not found'); |
|
83 | - } |
|
84 | - |
|
85 | - if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { |
|
86 | - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
87 | - } |
|
88 | - |
|
89 | - if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { |
|
90 | - $filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice |
|
91 | - $filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice |
|
92 | - } else { |
|
93 | - $filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')"; |
|
94 | - $filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')"; |
|
95 | - } |
|
96 | - |
|
97 | - $absolute_discount = $this->company->getAvailableDiscounts('', $filterabsolutediscount); |
|
98 | - $absolute_creditnote = $this->company->getAvailableDiscounts('', $filtercreditnote); |
|
99 | - $this->company->absolute_discount = price2num($absolute_discount, 'MT'); |
|
100 | - $this->company->absolute_creditnote = price2num($absolute_creditnote, 'MT'); |
|
101 | - |
|
102 | - return $this->_cleanObjectDatas($this->company); |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * List thirdparties |
|
107 | - * |
|
108 | - * Get a list of thirdparties |
|
109 | - * |
|
110 | - * @param string $sortfield Sort field |
|
111 | - * @param string $sortorder Sort order |
|
112 | - * @param int $limit Limit for list |
|
113 | - * @param int $page Page number |
|
114 | - * @param int $mode Set to 1 to show only customers |
|
115 | - * Set to 2 to show only prospects |
|
116 | - * Set to 3 to show only those are not customer neither prospect |
|
117 | - * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.nom:like:'TheCompany%') and (t.date_creation:<:'20160101')" |
|
118 | - * @return array Array of thirdparty objects |
|
119 | - */ |
|
120 | - function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $mode=0, $sqlfilters = '') |
|
31 | + /** |
|
32 | + * |
|
33 | + * @var array $FIELDS Mandatory fields, checked when create and update object |
|
34 | + */ |
|
35 | + static $FIELDS = array( |
|
36 | + 'name' |
|
37 | + ); |
|
38 | + |
|
39 | + /** |
|
40 | + * @var Societe $company {@type Societe} |
|
41 | + */ |
|
42 | + public $company; |
|
43 | + |
|
44 | + /** |
|
45 | + * Constructor |
|
46 | + */ |
|
47 | + function __construct() |
|
121 | 48 | { |
122 | - global $db, $conf; |
|
123 | - |
|
124 | - $obj_ret = array(); |
|
125 | - |
|
126 | - // case of external user, we force socids |
|
127 | - $socids = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : ''; |
|
128 | - |
|
129 | - // If the internal user must only see his customers, force searching by him |
|
130 | - $search_sale = 0; |
|
131 | - if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id; |
|
132 | - |
|
133 | - $sql = "SELECT t.rowid"; |
|
134 | - if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) |
|
135 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe as t"; |
|
136 | - |
|
137 | - if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale |
|
138 | - $sql.= ", ".MAIN_DB_PREFIX."c_stcomm as st"; |
|
139 | - $sql.= " WHERE t.fk_stcomm = st.id"; |
|
140 | - if ($mode == 1) $sql.= " AND t.client IN (1, 3)"; |
|
141 | - if ($mode == 2) $sql.= " AND t.client IN (2, 3)"; |
|
142 | - if ($mode == 3) $sql.= " AND t.client IN (0)"; |
|
143 | - $sql.= ' AND t.entity IN ('.getEntity('societe').')'; |
|
144 | - if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc"; |
|
145 | - //if ($email != NULL) $sql.= " AND s.email = \"".$email."\""; |
|
146 | - if ($socid) $sql.= " AND t.rowid IN (".$socids.")"; |
|
147 | - if ($search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale |
|
148 | - // Insert sale filter |
|
149 | - if ($search_sale > 0) |
|
150 | - { |
|
151 | - $sql .= " AND sc.fk_user = ".$search_sale; |
|
152 | - } |
|
153 | - // Add sql filters |
|
154 | - if ($sqlfilters) |
|
155 | - { |
|
156 | - if (! DolibarrApi::_checkFilters($sqlfilters)) |
|
157 | - { |
|
158 | - throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); |
|
159 | - } |
|
160 | - $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
161 | - $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
162 | - } |
|
163 | - |
|
164 | - $sql.= $db->order($sortfield, $sortorder); |
|
165 | - |
|
166 | - if ($limit) { |
|
167 | - if ($page < 0) |
|
168 | - { |
|
169 | - $page = 0; |
|
170 | - } |
|
171 | - $offset = $limit * $page; |
|
172 | - |
|
173 | - $sql.= $db->plimit($limit + 1, $offset); |
|
174 | - } |
|
175 | - |
|
176 | - $result = $db->query($sql); |
|
177 | - if ($result) |
|
178 | - { |
|
179 | - $num = $db->num_rows($result); |
|
180 | - $min = min($num, ($limit <= 0 ? $num : $limit)); |
|
181 | - while ($i < $min) |
|
182 | - { |
|
183 | - $obj = $db->fetch_object($result); |
|
184 | - $soc_static = new Societe($db); |
|
185 | - if($soc_static->fetch($obj->rowid)) { |
|
186 | - $obj_ret[] = $this->_cleanObjectDatas($soc_static); |
|
187 | - } |
|
188 | - $i++; |
|
189 | - } |
|
190 | - } |
|
191 | - else { |
|
192 | - throw new RestException(503, 'Error when retrieve thirdparties : '.$db->lasterror()); |
|
193 | - } |
|
194 | - if( ! count($obj_ret)) { |
|
195 | - throw new RestException(404, 'Thirdparties not found'); |
|
196 | - } |
|
197 | - return $obj_ret; |
|
198 | - } |
|
199 | - |
|
200 | - /** |
|
201 | - * Create thirdparty object |
|
202 | - * |
|
203 | - * @param array $request_data Request datas |
|
204 | - * @return int ID of thirdparty |
|
205 | - */ |
|
206 | - function post($request_data = null) |
|
207 | - { |
|
208 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
209 | - throw new RestException(401); |
|
210 | - } |
|
211 | - // Check mandatory fields |
|
212 | - $result = $this->_validate($request_data); |
|
213 | - |
|
214 | - foreach($request_data as $field => $value) { |
|
215 | - $this->company->$field = $value; |
|
216 | - } |
|
217 | - if ($this->company->create(DolibarrApiAccess::$user) < 0) |
|
218 | - throw new RestException(500, 'Error creating thirdparty', array_merge(array($this->company->error), $this->company->errors)); |
|
219 | - |
|
220 | - return $this->company->id; |
|
221 | - } |
|
222 | - |
|
223 | - /** |
|
224 | - * Update thirdparty |
|
225 | - * |
|
226 | - * @param int $id Id of thirdparty to update |
|
227 | - * @param array $request_data Datas |
|
228 | - * @return int |
|
229 | - */ |
|
230 | - function put($id, $request_data = null) |
|
231 | - { |
|
232 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
233 | - throw new RestException(401); |
|
234 | - } |
|
235 | - |
|
236 | - $result = $this->company->fetch($id); |
|
237 | - if( ! $result ) { |
|
238 | - throw new RestException(404, 'Thirdparty not found'); |
|
239 | - } |
|
240 | - |
|
241 | - if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { |
|
242 | - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
243 | - } |
|
244 | - |
|
245 | - foreach($request_data as $field => $value) { |
|
246 | - if ($field == 'id') continue; |
|
247 | - $this->company->$field = $value; |
|
248 | - } |
|
249 | - |
|
250 | - if($this->company->update($id, DolibarrApiAccess::$user,1,'','','update')) |
|
251 | - return $this->get($id); |
|
252 | - |
|
253 | - return false; |
|
254 | - } |
|
255 | - |
|
256 | - /** |
|
257 | - * Merge a thirdparty into another one. |
|
258 | - * |
|
259 | - * Merge content (properties, notes) and objects (like invoices, events, orders, proposals, ...) of a thirdparty into a target thirdparty, |
|
260 | - * then delete the merged thirdparty. |
|
261 | - * If a property has a defined value both in thirdparty to delete and thirdparty to keep, the value into the thirdparty to |
|
262 | - * delete will be ignored, the value of target thirdparty will remain, except for notes (content is concatenated). |
|
263 | - * |
|
264 | - * @param int $id ID of thirdparty to keep (the target thirdparty) |
|
265 | - * @param int $idtodelete ID of thirdparty to remove (the thirdparty to delete), once data has been merged into the target thirdparty. |
|
266 | - * @return int |
|
267 | - * |
|
268 | - * @url PUT {id}/merge/{idtodelete} |
|
269 | - */ |
|
270 | - function merge($id, $idtodelete) |
|
271 | - { |
|
272 | - global $db, $hookmanager; |
|
273 | - |
|
274 | - $error = 0; |
|
275 | - |
|
276 | - if ($id == $idtodelete) |
|
277 | - { |
|
278 | - throw new RestException(400, 'Try to merge a thirdparty into itself'); |
|
279 | - } |
|
280 | - |
|
281 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
282 | - throw new RestException(401); |
|
283 | - } |
|
284 | - |
|
285 | - $result = $this->company->fetch($id); // include the fetch of extra fields |
|
286 | - if( ! $result ) { |
|
287 | - throw new RestException(404, 'Thirdparty not found'); |
|
288 | - } |
|
289 | - |
|
290 | - if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { |
|
291 | - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
292 | - } |
|
293 | - |
|
294 | - $this->companytoremove = new Societe($db); |
|
295 | - |
|
296 | - $result = $this->companytoremove->fetch($idtodelete); // include the fetch of extra fields |
|
297 | - if( ! $result ) { |
|
298 | - throw new RestException(404, 'Thirdparty not found'); |
|
299 | - } |
|
300 | - |
|
301 | - if( ! DolibarrApi::_checkAccessToResource('societe',$this->companytoremove->id)) { |
|
302 | - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
303 | - } |
|
304 | - |
|
305 | - $soc_origin = $this->companytoremove; |
|
306 | - $object = $this->company; |
|
307 | - $user = DolibarrApiAccess::$user; |
|
308 | - |
|
309 | - |
|
310 | - // Call same code than into action 'confirm_merge' |
|
311 | - |
|
312 | - |
|
313 | - $db->begin(); |
|
314 | - |
|
315 | - // Recopy some data |
|
316 | - $object->client = $object->client | $soc_origin->client; |
|
317 | - $object->fournisseur = $object->fournisseur | $soc_origin->fournisseur; |
|
318 | - $listofproperties=array( |
|
319 | - 'address', 'zip', 'town', 'state_id', 'country_id', 'phone', 'phone_pro', 'fax', 'email', 'skype', 'url', 'barcode', |
|
320 | - 'idprof1', 'idprof2', 'idprof3', 'idprof4', 'idprof5', 'idprof6', |
|
321 | - 'tva_intra', 'effectif_id', 'forme_juridique', 'remise_percent', 'remise_supplier_percent', 'mode_reglement_supplier_id', 'cond_reglement_supplier_id', 'name_bis', |
|
322 | - 'stcomm_id', 'outstanding_limit', 'price_level', 'parent', 'default_lang', 'ref', 'ref_ext', 'import_key', 'fk_incoterms', 'fk_multicurrency', |
|
323 | - 'code_client', 'code_fournisseur', 'code_compta', 'code_compta_fournisseur', |
|
324 | - 'model_pdf', 'fk_projet' |
|
325 | - ); |
|
326 | - foreach ($listofproperties as $property) |
|
327 | - { |
|
328 | - if (empty($object->$property)) $object->$property = $soc_origin->$property; |
|
329 | - } |
|
330 | - |
|
331 | - // Concat some data |
|
332 | - $listofproperties=array( |
|
333 | - 'note_public', 'note_private' |
|
334 | - ); |
|
335 | - foreach ($listofproperties as $property) |
|
336 | - { |
|
337 | - $object->$property = dol_concatdesc($object->$property, $soc_origin->$property); |
|
338 | - } |
|
339 | - |
|
340 | - // Merge extrafields |
|
341 | - if (is_array($soc_origin->array_options)) |
|
342 | - { |
|
343 | - foreach ($soc_origin->array_options as $key => $val) |
|
344 | - { |
|
345 | - if (empty($object->array_options[$key])) $object->array_options[$key] = $val; |
|
346 | - } |
|
347 | - } |
|
348 | - |
|
349 | - // Merge categories |
|
350 | - $static_cat = new Categorie($db); |
|
351 | - $custcats = $static_cat->containing($soc_origin->id, 'customer', 'id'); |
|
352 | - $object->setCategories($custcats, 'customer'); |
|
353 | - $suppcats = $static_cat->containing($soc_origin->id, 'supplier', 'id'); |
|
354 | - $object->setCategories($suppcats, 'supplier'); |
|
355 | - |
|
356 | - // If thirdparty has a new code that is same than origin, we clean origin code to avoid duplicate key from database unique keys. |
|
357 | - if ($soc_origin->code_client == $object->code_client |
|
358 | - || $soc_origin->code_fournisseur == $object->code_fournisseur |
|
359 | - || $soc_origin->barcode == $object->barcode) |
|
360 | - { |
|
361 | - dol_syslog("We clean customer and supplier code so we will be able to make the update of target"); |
|
362 | - $soc_origin->code_client = ''; |
|
363 | - $soc_origin->code_fournisseur = ''; |
|
364 | - $soc_origin->barcode = ''; |
|
365 | - $soc_origin->update($soc_origin->id, $user, 0, 1, 1, 'merge'); |
|
366 | - } |
|
367 | - |
|
368 | - // Update |
|
369 | - $result = $object->update($object->id, $user, 0, 1, 1, 'merge'); |
|
370 | - if ($result < 0) |
|
371 | - { |
|
372 | - $error++; |
|
373 | - } |
|
374 | - |
|
375 | - // Move links |
|
376 | - if (! $error) |
|
377 | - { |
|
378 | - $objects = array( |
|
379 | - 'Adherent' => '/adherents/class/adherent.class.php', |
|
380 | - 'Societe' => '/societe/class/societe.class.php', |
|
381 | - 'Categorie' => '/categories/class/categorie.class.php', |
|
382 | - 'ActionComm' => '/comm/action/class/actioncomm.class.php', |
|
383 | - 'Propal' => '/comm/propal/class/propal.class.php', |
|
384 | - 'Commande' => '/commande/class/commande.class.php', |
|
385 | - 'Facture' => '/compta/facture/class/facture.class.php', |
|
386 | - 'FactureRec' => '/compta/facture/class/facture-rec.class.php', |
|
387 | - 'LignePrelevement' => '/compta/prelevement/class/ligneprelevement.class.php', |
|
388 | - 'Contact' => '/contact/class/contact.class.php', |
|
389 | - 'Contrat' => '/contrat/class/contrat.class.php', |
|
390 | - 'Expedition' => '/expedition/class/expedition.class.php', |
|
391 | - 'Fichinter' => '/fichinter/class/fichinter.class.php', |
|
392 | - 'CommandeFournisseur' => '/fourn/class/fournisseur.commande.class.php', |
|
393 | - 'FactureFournisseur' => '/fourn/class/fournisseur.facture.class.php', |
|
394 | - 'SupplierProposal' => '/supplier_proposal/class/supplier_proposal.class.php', |
|
395 | - 'ProductFournisseur' => '/fourn/class/fournisseur.product.class.php', |
|
396 | - 'Livraison' => '/livraison/class/livraison.class.php', |
|
397 | - 'Product' => '/product/class/product.class.php', |
|
398 | - 'Project' => '/projet/class/project.class.php', |
|
399 | - 'User' => '/user/class/user.class.php', |
|
400 | - ); |
|
401 | - |
|
402 | - //First, all core objects must update their tables |
|
403 | - foreach ($objects as $object_name => $object_file) |
|
404 | - { |
|
405 | - require_once DOL_DOCUMENT_ROOT.$object_file; |
|
406 | - |
|
407 | - if (!$errors && !$object_name::replaceThirdparty($db, $soc_origin->id, $object->id)) |
|
408 | - { |
|
409 | - $errors++; |
|
410 | - //setEventMessages($db->lasterror(), null, 'errors'); |
|
411 | - } |
|
412 | - } |
|
413 | - } |
|
414 | - |
|
415 | - // External modules should update their ones too |
|
416 | - if (!$errors) |
|
417 | - { |
|
418 | - $reshook = $hookmanager->executeHooks('replaceThirdparty', array( |
|
419 | - 'soc_origin' => $soc_origin->id, |
|
420 | - 'soc_dest' => $object->id |
|
421 | - ), $soc_dest, $action); |
|
422 | - |
|
423 | - if ($reshook < 0) |
|
424 | - { |
|
425 | - //setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
|
426 | - $errors++; |
|
427 | - } |
|
428 | - } |
|
429 | - |
|
430 | - |
|
431 | - if (! $error) |
|
432 | - { |
|
433 | - $object->context=array('merge'=>1, 'mergefromid'=>$soc_origin->id); |
|
434 | - |
|
435 | - // Call trigger |
|
436 | - $result=$object->call_trigger('COMPANY_MODIFY',$user); |
|
437 | - if ($result < 0) |
|
438 | - { |
|
439 | - //setEventMessages($object->error, $object->errors, 'errors'); |
|
440 | - $error++; |
|
441 | - } |
|
442 | - // End call triggers |
|
443 | - } |
|
444 | - |
|
445 | - if (! $error) |
|
446 | - { |
|
447 | - //We finally remove the old thirdparty |
|
448 | - if ($soc_origin->delete($soc_origin->id, $user) < 1) |
|
449 | - { |
|
450 | - $errors++; |
|
451 | - } |
|
452 | - } |
|
453 | - |
|
454 | - // End of merge |
|
455 | - |
|
456 | - if ($error) |
|
457 | - { |
|
458 | - $db->rollback(); |
|
459 | - |
|
460 | - throw new RestException(500, 'Error failed to merged thirdparty '.$this->companytoremove->id.' into '.$id.'. Enable and read log file for more information.'); |
|
461 | - } |
|
462 | - else |
|
463 | - { |
|
464 | - $db->commit(); |
|
465 | - } |
|
466 | - |
|
467 | - return $this->get($id); |
|
468 | - } |
|
469 | - |
|
470 | - /** |
|
471 | - * Delete thirdparty |
|
472 | - * |
|
473 | - * @param int $id Thirparty ID |
|
474 | - * @return integer |
|
475 | - */ |
|
476 | - function delete($id) |
|
477 | - { |
|
478 | - if(! DolibarrApiAccess::$user->rights->societe->supprimer) { |
|
479 | - throw new RestException(401); |
|
480 | - } |
|
481 | - $result = $this->company->fetch($id); |
|
482 | - if( ! $result ) { |
|
483 | - throw new RestException(404, 'Thirdparty not found'); |
|
484 | - } |
|
485 | - if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { |
|
486 | - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
487 | - } |
|
488 | - return $this->company->delete($id); |
|
489 | - } |
|
490 | - |
|
491 | - /** |
|
492 | - * Get customer categories for a thirdparty |
|
493 | - * |
|
494 | - * @param int $id ID of thirdparty |
|
495 | - * @param string $sortfield Sort field |
|
496 | - * @param string $sortorder Sort order |
|
497 | - * @param int $limit Limit for list |
|
498 | - * @param int $page Page number |
|
499 | - * |
|
500 | - * @return mixed |
|
501 | - * |
|
502 | - * @url GET {id}/categories |
|
503 | - */ |
|
504 | - function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) |
|
505 | - { |
|
506 | - if (! DolibarrApiAccess::$user->rights->categorie->lire) { |
|
507 | - throw new RestException(401); |
|
508 | - } |
|
509 | - |
|
510 | - $result = $this->company->fetch($id); |
|
511 | - if( ! $result ) |
|
512 | - { |
|
513 | - throw new RestException(404, 'Thirdparty not found'); |
|
514 | - } |
|
515 | - |
|
516 | - $categories = new Categorie($this->db); |
|
517 | - |
|
518 | - $result = $categories->getListForItem($id, 'customer', $sortfield, $sortorder, $limit, $page); |
|
519 | - |
|
520 | - if (is_numeric($result) && $result < 0) |
|
521 | - { |
|
522 | - throw new RestException(503, 'Error when retrieve category list : '.$categories->error); |
|
523 | - } |
|
524 | - |
|
525 | - if (is_numeric($result) && $result == 0) // To fix a return of 0 instead of empty array of method getListForItem |
|
526 | - { |
|
527 | - return array(); |
|
528 | - } |
|
529 | - |
|
530 | - return $result; |
|
531 | - } |
|
532 | - |
|
533 | - /** |
|
534 | - * Add a customer category to a thirdparty |
|
535 | - * |
|
536 | - * @param int $id Id of thirdparty |
|
537 | - * @param int $category_id Id of category |
|
538 | - * |
|
539 | - * @return mixed |
|
540 | - * |
|
541 | - * @url POST {id}/categories/{category_id} |
|
542 | - */ |
|
543 | - function addCategory($id, $category_id) |
|
544 | - { |
|
545 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
546 | - throw new RestException(401); |
|
547 | - } |
|
548 | - |
|
549 | - $result = $this->company->fetch($id); |
|
550 | - if( ! $result ) { |
|
551 | - throw new RestException(404, 'Thirdparty not found'); |
|
552 | - } |
|
553 | - $category = new Categorie($this->db); |
|
554 | - $result = $category->fetch($category_id); |
|
555 | - if( ! $result ) { |
|
556 | - throw new RestException(404, 'category not found'); |
|
557 | - } |
|
558 | - |
|
559 | - if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { |
|
560 | - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
561 | - } |
|
562 | - if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) { |
|
563 | - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
564 | - } |
|
565 | - |
|
566 | - $category->add_type($this->company,'customer'); |
|
567 | - |
|
568 | - return $this->_cleanObjectDatas($this->company); |
|
569 | - } |
|
570 | - |
|
571 | - /** |
|
572 | - * Remove the link between a customer category and the thirdparty |
|
573 | - * |
|
574 | - * @param int $id Id of thirdparty |
|
575 | - * @param int $category_id Id of category |
|
576 | - * |
|
577 | - * @return mixed |
|
578 | - * |
|
579 | - * @url DELETE {id}/categories/{category_id} |
|
580 | - */ |
|
581 | - function deleteCategory($id, $category_id) |
|
582 | - { |
|
583 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
584 | - throw new RestException(401); |
|
585 | - } |
|
586 | - |
|
587 | - $result = $this->company->fetch($id); |
|
588 | - if( ! $result ) { |
|
589 | - throw new RestException(404, 'Thirdparty not found'); |
|
590 | - } |
|
591 | - $category = new Categorie($this->db); |
|
592 | - $result = $category->fetch($category_id); |
|
593 | - if( ! $result ) { |
|
594 | - throw new RestException(404, 'category not found'); |
|
595 | - } |
|
596 | - |
|
597 | - if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { |
|
598 | - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
599 | - } |
|
600 | - if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) { |
|
601 | - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
602 | - } |
|
603 | - |
|
604 | - $category->del_type($this->company,'customer'); |
|
605 | - |
|
606 | - return $this->_cleanObjectDatas($this->company); |
|
607 | - } |
|
608 | - |
|
609 | - /** |
|
610 | - * Get supplier categories for a thirdparty |
|
611 | - * |
|
612 | - * @param int $id ID of thirdparty |
|
613 | - * @param string $sortfield Sort field |
|
614 | - * @param string $sortorder Sort order |
|
615 | - * @param int $limit Limit for list |
|
616 | - * @param int $page Page number |
|
617 | - * |
|
618 | - * @return mixed |
|
619 | - * |
|
620 | - * @url GET {id}/supplier_categories |
|
621 | - */ |
|
622 | - function getSupplierCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) |
|
623 | - { |
|
624 | - if (! DolibarrApiAccess::$user->rights->categorie->lire) { |
|
625 | - throw new RestException(401); |
|
626 | - } |
|
627 | - |
|
628 | - $result = $this->company->fetch($id); |
|
629 | - if( ! $result ) |
|
630 | - { |
|
631 | - throw new RestException(404, 'Thirdparty not found'); |
|
632 | - } |
|
633 | - |
|
634 | - $categories = new Categorie($this->db); |
|
635 | - |
|
636 | - $result = $categories->getListForItem($id, 'supplier', $sortfield, $sortorder, $limit, $page); |
|
637 | - |
|
638 | - if (is_numeric($result) && $result < 0) |
|
639 | - { |
|
640 | - throw new RestException(503, 'Error when retrieve category list : '.$categories->error); |
|
641 | - } |
|
642 | - |
|
643 | - if (is_numeric($result) && $result == 0) // To fix a return of 0 instead of empty array of method getListForItem |
|
644 | - { |
|
645 | - return array(); |
|
646 | - } |
|
647 | - |
|
648 | - return $result; |
|
649 | - } |
|
650 | - |
|
651 | - /** |
|
652 | - * Add a supplier category to a thirdparty |
|
653 | - * |
|
654 | - * @param int $id Id of thirdparty |
|
655 | - * @param int $category_id Id of category |
|
656 | - * |
|
657 | - * @return mixed |
|
658 | - * |
|
659 | - * @url POST {id}/supplier_categories/{category_id} |
|
660 | - */ |
|
661 | - function addSupplierCategory($id, $category_id) |
|
662 | - { |
|
663 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
664 | - throw new RestException(401); |
|
665 | - } |
|
666 | - |
|
667 | - $result = $this->company->fetch($id); |
|
668 | - if( ! $result ) { |
|
669 | - throw new RestException(404, 'Thirdparty not found'); |
|
670 | - } |
|
671 | - $category = new Categorie($this->db); |
|
672 | - $result = $category->fetch($category_id); |
|
673 | - if( ! $result ) { |
|
674 | - throw new RestException(404, 'category not found'); |
|
675 | - } |
|
676 | - |
|
677 | - if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { |
|
678 | - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
679 | - } |
|
680 | - if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) { |
|
681 | - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
682 | - } |
|
683 | - |
|
684 | - $category->add_type($this->company,'supplier'); |
|
685 | - |
|
686 | - return $this->_cleanObjectDatas($this->company); |
|
687 | - } |
|
688 | - |
|
689 | - /** |
|
690 | - * Remove the link between a category and the thirdparty |
|
691 | - * |
|
692 | - * @param int $id Id of thirdparty |
|
693 | - * @param int $category_id Id of category |
|
694 | - * |
|
695 | - * @return mixed |
|
696 | - * |
|
697 | - * @url DELETE {id}/supplier_categories/{category_id} |
|
698 | - */ |
|
699 | - function deleteSupplierCategory($id, $category_id) |
|
700 | - { |
|
701 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
702 | - throw new RestException(401); |
|
703 | - } |
|
704 | - |
|
705 | - $result = $this->company->fetch($id); |
|
706 | - if( ! $result ) { |
|
707 | - throw new RestException(404, 'Thirdparty not found'); |
|
708 | - } |
|
709 | - $category = new Categorie($this->db); |
|
710 | - $result = $category->fetch($category_id); |
|
711 | - if( ! $result ) { |
|
712 | - throw new RestException(404, 'category not found'); |
|
713 | - } |
|
714 | - |
|
715 | - if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { |
|
716 | - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
717 | - } |
|
718 | - if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) { |
|
719 | - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
720 | - } |
|
721 | - |
|
722 | - $category->del_type($this->company,'supplier'); |
|
723 | - |
|
724 | - return $this->_cleanObjectDatas($this->company); |
|
725 | - } |
|
726 | - |
|
727 | - |
|
728 | - /** |
|
729 | - * Get outstanding proposals of thirdparty |
|
730 | - * |
|
731 | - * @param int $id ID of the thirdparty |
|
732 | - * @param string $mode 'customer' or 'supplier' |
|
733 | - * |
|
734 | - * @url GET {id}/outstandingproposals |
|
735 | - * |
|
736 | - * @return array List of outstandings proposals of thirdparty |
|
737 | - * |
|
738 | - * @throws 400 |
|
739 | - * @throws 401 |
|
740 | - * @throws 404 |
|
741 | - */ |
|
742 | - function getOutStandingProposals($id, $mode='customer') |
|
743 | - { |
|
744 | - $obj_ret = array(); |
|
745 | - |
|
746 | - if(! DolibarrApiAccess::$user->rights->societe->lire) { |
|
747 | - throw new RestException(401); |
|
748 | - } |
|
749 | - |
|
750 | - if(empty($id)) { |
|
751 | - throw new RestException(400, 'Thirdparty ID is mandatory'); |
|
752 | - } |
|
753 | - |
|
754 | - if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { |
|
755 | - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
756 | - } |
|
757 | - |
|
758 | - $result = $this->company->fetch($id); |
|
759 | - if( ! $result ) { |
|
760 | - throw new RestException(404, 'Thirdparty not found'); |
|
761 | - } |
|
762 | - |
|
763 | - $result = $this->company->getOutstandingProposals($mode); |
|
764 | - |
|
765 | - unset($result['total_ht']); |
|
766 | - unset($result['total_ttc']); |
|
767 | - |
|
768 | - return $result; |
|
769 | - } |
|
770 | - |
|
771 | - |
|
772 | - /** |
|
773 | - * Get outstanding orders of thirdparty |
|
774 | - * |
|
775 | - * @param int $id ID of the thirdparty |
|
776 | - * @param string $mode 'customer' or 'supplier' |
|
777 | - * |
|
778 | - * @url GET {id}/outstandingorders |
|
779 | - * |
|
780 | - * @return array List of outstandings orders of thirdparty |
|
781 | - * |
|
782 | - * @throws 400 |
|
783 | - * @throws 401 |
|
784 | - * @throws 404 |
|
785 | - */ |
|
786 | - function getOutStandingOrder($id, $mode='customer') |
|
787 | - { |
|
788 | - $obj_ret = array(); |
|
789 | - |
|
790 | - if(! DolibarrApiAccess::$user->rights->societe->lire) { |
|
791 | - throw new RestException(401); |
|
792 | - } |
|
793 | - |
|
794 | - if(empty($id)) { |
|
795 | - throw new RestException(400, 'Thirdparty ID is mandatory'); |
|
796 | - } |
|
797 | - |
|
798 | - if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { |
|
799 | - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
800 | - } |
|
801 | - |
|
802 | - $result = $this->company->fetch($id); |
|
803 | - if( ! $result ) { |
|
804 | - throw new RestException(404, 'Thirdparty not found'); |
|
805 | - } |
|
806 | - |
|
807 | - $result = $this->company->getOutstandingOrders($mode); |
|
808 | - |
|
809 | - unset($result['total_ht']); |
|
810 | - unset($result['total_ttc']); |
|
811 | - |
|
812 | - return $result; |
|
813 | - } |
|
814 | - |
|
815 | - /** |
|
816 | - * Get outstanding invoices of thirdparty |
|
817 | - * |
|
818 | - * @param int $id ID of the thirdparty |
|
819 | - * @param string $mode 'customer' or 'supplier' |
|
820 | - * |
|
821 | - * @url GET {id}/outstandinginvoices |
|
822 | - * |
|
823 | - * @return array List of outstandings invoices of thirdparty |
|
824 | - * |
|
825 | - * @throws 400 |
|
826 | - * @throws 401 |
|
827 | - * @throws 404 |
|
828 | - */ |
|
829 | - function getOutStandingInvoices($id, $mode='customer') |
|
830 | - { |
|
831 | - $obj_ret = array(); |
|
832 | - |
|
833 | - if(! DolibarrApiAccess::$user->rights->societe->lire) { |
|
834 | - throw new RestException(401); |
|
835 | - } |
|
836 | - |
|
837 | - if(empty($id)) { |
|
838 | - throw new RestException(400, 'Thirdparty ID is mandatory'); |
|
839 | - } |
|
840 | - |
|
841 | - if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { |
|
842 | - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
843 | - } |
|
844 | - |
|
845 | - $result = $this->company->fetch($id); |
|
846 | - if( ! $result ) { |
|
847 | - throw new RestException(404, 'Thirdparty not found'); |
|
848 | - } |
|
849 | - |
|
850 | - $result = $this->company->getOutstandingBills($mode); |
|
851 | - |
|
852 | - unset($result['total_ht']); |
|
853 | - unset($result['total_ttc']); |
|
854 | - |
|
855 | - return $result; |
|
856 | - } |
|
857 | - |
|
858 | - /** |
|
859 | - * Get fixed amount discount of a thirdparty (all sources: deposit, credit note, commercial offers...) |
|
860 | - * |
|
861 | - * @param int $id ID of the thirdparty |
|
862 | - * @param string $filter Filter exceptional discount. "none" will return every discount, "available" returns unapplied discounts, "used" returns applied discounts {@choice none,available,used} |
|
863 | - * @param string $sortfield Sort field |
|
864 | - * @param string $sortorder Sort order |
|
865 | - * |
|
866 | - * @url GET {id}/fixedamountdiscounts |
|
867 | - * |
|
868 | - * @return array List of fixed discount of thirdparty |
|
869 | - * |
|
870 | - * @throws 400 |
|
871 | - * @throws 401 |
|
872 | - * @throws 404 |
|
873 | - * @throws 503 |
|
874 | - */ |
|
875 | - function getFixedAmountDiscounts($id, $filter="none", $sortfield = "f.type", $sortorder = 'ASC') |
|
876 | - { |
|
877 | - $obj_ret = array(); |
|
878 | - |
|
879 | - if(! DolibarrApiAccess::$user->rights->societe->lire) { |
|
880 | - throw new RestException(401); |
|
881 | - } |
|
882 | - |
|
883 | - if(empty($id)) { |
|
884 | - throw new RestException(400, 'Thirdparty ID is mandatory'); |
|
885 | - } |
|
886 | - |
|
887 | - if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { |
|
888 | - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
889 | - } |
|
890 | - |
|
891 | - $result = $this->company->fetch($id); |
|
892 | - if( ! $result ) { |
|
893 | - throw new RestException(404, 'Thirdparty not found'); |
|
894 | - } |
|
895 | - |
|
896 | - |
|
897 | - $sql = "SELECT f.ref, f.type as factype, re.fk_facture_source, re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc, re.description, re.fk_facture, re.fk_facture_line"; |
|
898 | - $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f"; |
|
899 | - $sql .= " WHERE f.rowid = re.fk_facture_source AND re.fk_soc = ".$id; |
|
900 | - if ($filter == "available") $sql .= " AND re.fk_facture IS NULL AND re.fk_facture_line IS NULL"; |
|
901 | - if ($filter == "used") $sql .= " AND (re.fk_facture IS NOT NULL OR re.fk_facture_line IS NOT NULL)"; |
|
902 | - |
|
903 | - $sql.= $this->db->order($sortfield, $sortorder); |
|
904 | - |
|
905 | - $result = $this->db->query($sql); |
|
906 | - if( ! $result ) { |
|
907 | - throw new RestException(503, $this->db->lasterror()); |
|
908 | - } else { |
|
909 | - $num = $this->db->num_rows($result); |
|
910 | - while ( $obj = $this->db->fetch_object($result) ) { |
|
911 | - $obj_ret[] = $obj; |
|
912 | - } |
|
913 | - } |
|
914 | - |
|
915 | - return $obj_ret; |
|
916 | - } |
|
917 | - |
|
918 | - |
|
919 | - |
|
920 | - /** |
|
921 | - * Return list of invoices qualified to be replaced by another invoice. |
|
922 | - * |
|
923 | - * @param int $id Id of thirdparty |
|
924 | - * |
|
925 | - * @url GET {id}/getinvoicesqualifiedforreplacement |
|
926 | - * |
|
927 | - * @return array |
|
928 | - * @throws 400 |
|
929 | - * @throws 401 |
|
930 | - * @throws 404 |
|
931 | - * @throws 405 |
|
932 | - */ |
|
933 | - function getInvoicesQualifiedForReplacement($id) |
|
49 | + global $db, $conf; |
|
50 | + $this->db = $db; |
|
51 | + |
|
52 | + require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; |
|
53 | + require_once DOL_DOCUMENT_ROOT.'/societe/class/societeaccount.class.php'; |
|
54 | + require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; |
|
55 | + require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php'; |
|
56 | + |
|
57 | + $this->company = new Societe($this->db); |
|
58 | + |
|
59 | + if (! empty($conf->global->SOCIETE_EMAIL_MANDATORY)) { |
|
60 | + static::$FIELDS[] = 'email'; |
|
61 | + } |
|
62 | + } |
|
63 | + |
|
64 | + /** |
|
65 | + * Get properties of a thirdparty object |
|
66 | + * |
|
67 | + * Return an array with thirdparty informations |
|
68 | + * |
|
69 | + * @param int $id ID of thirdparty |
|
70 | + * @return array|mixed data without useless information |
|
71 | + * |
|
72 | + * @throws RestException |
|
73 | + */ |
|
74 | + function get($id) |
|
75 | + { |
|
76 | + if(! DolibarrApiAccess::$user->rights->societe->lire) { |
|
77 | + throw new RestException(401); |
|
78 | + } |
|
79 | + |
|
80 | + $result = $this->company->fetch($id); |
|
81 | + if( ! $result ) { |
|
82 | + throw new RestException(404, 'Thirdparty not found'); |
|
83 | + } |
|
84 | + |
|
85 | + if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { |
|
86 | + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
87 | + } |
|
88 | + |
|
89 | + if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { |
|
90 | + $filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice |
|
91 | + $filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice |
|
92 | + } else { |
|
93 | + $filterabsolutediscount = "fk_facture_source IS NULL OR (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%')"; |
|
94 | + $filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')"; |
|
95 | + } |
|
96 | + |
|
97 | + $absolute_discount = $this->company->getAvailableDiscounts('', $filterabsolutediscount); |
|
98 | + $absolute_creditnote = $this->company->getAvailableDiscounts('', $filtercreditnote); |
|
99 | + $this->company->absolute_discount = price2num($absolute_discount, 'MT'); |
|
100 | + $this->company->absolute_creditnote = price2num($absolute_creditnote, 'MT'); |
|
101 | + |
|
102 | + return $this->_cleanObjectDatas($this->company); |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * List thirdparties |
|
107 | + * |
|
108 | + * Get a list of thirdparties |
|
109 | + * |
|
110 | + * @param string $sortfield Sort field |
|
111 | + * @param string $sortorder Sort order |
|
112 | + * @param int $limit Limit for list |
|
113 | + * @param int $page Page number |
|
114 | + * @param int $mode Set to 1 to show only customers |
|
115 | + * Set to 2 to show only prospects |
|
116 | + * Set to 3 to show only those are not customer neither prospect |
|
117 | + * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.nom:like:'TheCompany%') and (t.date_creation:<:'20160101')" |
|
118 | + * @return array Array of thirdparty objects |
|
119 | + */ |
|
120 | + function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $mode=0, $sqlfilters = '') |
|
121 | + { |
|
122 | + global $db, $conf; |
|
123 | + |
|
124 | + $obj_ret = array(); |
|
125 | + |
|
126 | + // case of external user, we force socids |
|
127 | + $socids = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : ''; |
|
128 | + |
|
129 | + // If the internal user must only see his customers, force searching by him |
|
130 | + $search_sale = 0; |
|
131 | + if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id; |
|
132 | + |
|
133 | + $sql = "SELECT t.rowid"; |
|
134 | + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) |
|
135 | + $sql.= " FROM ".MAIN_DB_PREFIX."societe as t"; |
|
136 | + |
|
137 | + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale |
|
138 | + $sql.= ", ".MAIN_DB_PREFIX."c_stcomm as st"; |
|
139 | + $sql.= " WHERE t.fk_stcomm = st.id"; |
|
140 | + if ($mode == 1) $sql.= " AND t.client IN (1, 3)"; |
|
141 | + if ($mode == 2) $sql.= " AND t.client IN (2, 3)"; |
|
142 | + if ($mode == 3) $sql.= " AND t.client IN (0)"; |
|
143 | + $sql.= ' AND t.entity IN ('.getEntity('societe').')'; |
|
144 | + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc"; |
|
145 | + //if ($email != NULL) $sql.= " AND s.email = \"".$email."\""; |
|
146 | + if ($socid) $sql.= " AND t.rowid IN (".$socids.")"; |
|
147 | + if ($search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale |
|
148 | + // Insert sale filter |
|
149 | + if ($search_sale > 0) |
|
150 | + { |
|
151 | + $sql .= " AND sc.fk_user = ".$search_sale; |
|
152 | + } |
|
153 | + // Add sql filters |
|
154 | + if ($sqlfilters) |
|
155 | + { |
|
156 | + if (! DolibarrApi::_checkFilters($sqlfilters)) |
|
157 | + { |
|
158 | + throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); |
|
159 | + } |
|
160 | + $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
161 | + $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
162 | + } |
|
163 | + |
|
164 | + $sql.= $db->order($sortfield, $sortorder); |
|
165 | + |
|
166 | + if ($limit) { |
|
167 | + if ($page < 0) |
|
168 | + { |
|
169 | + $page = 0; |
|
170 | + } |
|
171 | + $offset = $limit * $page; |
|
172 | + |
|
173 | + $sql.= $db->plimit($limit + 1, $offset); |
|
174 | + } |
|
175 | + |
|
176 | + $result = $db->query($sql); |
|
177 | + if ($result) |
|
178 | + { |
|
179 | + $num = $db->num_rows($result); |
|
180 | + $min = min($num, ($limit <= 0 ? $num : $limit)); |
|
181 | + while ($i < $min) |
|
182 | + { |
|
183 | + $obj = $db->fetch_object($result); |
|
184 | + $soc_static = new Societe($db); |
|
185 | + if($soc_static->fetch($obj->rowid)) { |
|
186 | + $obj_ret[] = $this->_cleanObjectDatas($soc_static); |
|
187 | + } |
|
188 | + $i++; |
|
189 | + } |
|
190 | + } |
|
191 | + else { |
|
192 | + throw new RestException(503, 'Error when retrieve thirdparties : '.$db->lasterror()); |
|
193 | + } |
|
194 | + if( ! count($obj_ret)) { |
|
195 | + throw new RestException(404, 'Thirdparties not found'); |
|
196 | + } |
|
197 | + return $obj_ret; |
|
198 | + } |
|
199 | + |
|
200 | + /** |
|
201 | + * Create thirdparty object |
|
202 | + * |
|
203 | + * @param array $request_data Request datas |
|
204 | + * @return int ID of thirdparty |
|
205 | + */ |
|
206 | + function post($request_data = null) |
|
207 | + { |
|
208 | + if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
209 | + throw new RestException(401); |
|
210 | + } |
|
211 | + // Check mandatory fields |
|
212 | + $result = $this->_validate($request_data); |
|
213 | + |
|
214 | + foreach($request_data as $field => $value) { |
|
215 | + $this->company->$field = $value; |
|
216 | + } |
|
217 | + if ($this->company->create(DolibarrApiAccess::$user) < 0) |
|
218 | + throw new RestException(500, 'Error creating thirdparty', array_merge(array($this->company->error), $this->company->errors)); |
|
219 | + |
|
220 | + return $this->company->id; |
|
221 | + } |
|
222 | + |
|
223 | + /** |
|
224 | + * Update thirdparty |
|
225 | + * |
|
226 | + * @param int $id Id of thirdparty to update |
|
227 | + * @param array $request_data Datas |
|
228 | + * @return int |
|
229 | + */ |
|
230 | + function put($id, $request_data = null) |
|
231 | + { |
|
232 | + if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
233 | + throw new RestException(401); |
|
234 | + } |
|
235 | + |
|
236 | + $result = $this->company->fetch($id); |
|
237 | + if( ! $result ) { |
|
238 | + throw new RestException(404, 'Thirdparty not found'); |
|
239 | + } |
|
240 | + |
|
241 | + if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { |
|
242 | + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
243 | + } |
|
244 | + |
|
245 | + foreach($request_data as $field => $value) { |
|
246 | + if ($field == 'id') continue; |
|
247 | + $this->company->$field = $value; |
|
248 | + } |
|
249 | + |
|
250 | + if($this->company->update($id, DolibarrApiAccess::$user,1,'','','update')) |
|
251 | + return $this->get($id); |
|
252 | + |
|
253 | + return false; |
|
254 | + } |
|
255 | + |
|
256 | + /** |
|
257 | + * Merge a thirdparty into another one. |
|
258 | + * |
|
259 | + * Merge content (properties, notes) and objects (like invoices, events, orders, proposals, ...) of a thirdparty into a target thirdparty, |
|
260 | + * then delete the merged thirdparty. |
|
261 | + * If a property has a defined value both in thirdparty to delete and thirdparty to keep, the value into the thirdparty to |
|
262 | + * delete will be ignored, the value of target thirdparty will remain, except for notes (content is concatenated). |
|
263 | + * |
|
264 | + * @param int $id ID of thirdparty to keep (the target thirdparty) |
|
265 | + * @param int $idtodelete ID of thirdparty to remove (the thirdparty to delete), once data has been merged into the target thirdparty. |
|
266 | + * @return int |
|
267 | + * |
|
268 | + * @url PUT {id}/merge/{idtodelete} |
|
269 | + */ |
|
270 | + function merge($id, $idtodelete) |
|
271 | + { |
|
272 | + global $db, $hookmanager; |
|
273 | + |
|
274 | + $error = 0; |
|
275 | + |
|
276 | + if ($id == $idtodelete) |
|
277 | + { |
|
278 | + throw new RestException(400, 'Try to merge a thirdparty into itself'); |
|
279 | + } |
|
280 | + |
|
281 | + if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
282 | + throw new RestException(401); |
|
283 | + } |
|
284 | + |
|
285 | + $result = $this->company->fetch($id); // include the fetch of extra fields |
|
286 | + if( ! $result ) { |
|
287 | + throw new RestException(404, 'Thirdparty not found'); |
|
288 | + } |
|
289 | + |
|
290 | + if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { |
|
291 | + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
292 | + } |
|
293 | + |
|
294 | + $this->companytoremove = new Societe($db); |
|
295 | + |
|
296 | + $result = $this->companytoremove->fetch($idtodelete); // include the fetch of extra fields |
|
297 | + if( ! $result ) { |
|
298 | + throw new RestException(404, 'Thirdparty not found'); |
|
299 | + } |
|
300 | + |
|
301 | + if( ! DolibarrApi::_checkAccessToResource('societe',$this->companytoremove->id)) { |
|
302 | + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
303 | + } |
|
304 | + |
|
305 | + $soc_origin = $this->companytoremove; |
|
306 | + $object = $this->company; |
|
307 | + $user = DolibarrApiAccess::$user; |
|
308 | + |
|
309 | + |
|
310 | + // Call same code than into action 'confirm_merge' |
|
311 | + |
|
312 | + |
|
313 | + $db->begin(); |
|
314 | + |
|
315 | + // Recopy some data |
|
316 | + $object->client = $object->client | $soc_origin->client; |
|
317 | + $object->fournisseur = $object->fournisseur | $soc_origin->fournisseur; |
|
318 | + $listofproperties=array( |
|
319 | + 'address', 'zip', 'town', 'state_id', 'country_id', 'phone', 'phone_pro', 'fax', 'email', 'skype', 'url', 'barcode', |
|
320 | + 'idprof1', 'idprof2', 'idprof3', 'idprof4', 'idprof5', 'idprof6', |
|
321 | + 'tva_intra', 'effectif_id', 'forme_juridique', 'remise_percent', 'remise_supplier_percent', 'mode_reglement_supplier_id', 'cond_reglement_supplier_id', 'name_bis', |
|
322 | + 'stcomm_id', 'outstanding_limit', 'price_level', 'parent', 'default_lang', 'ref', 'ref_ext', 'import_key', 'fk_incoterms', 'fk_multicurrency', |
|
323 | + 'code_client', 'code_fournisseur', 'code_compta', 'code_compta_fournisseur', |
|
324 | + 'model_pdf', 'fk_projet' |
|
325 | + ); |
|
326 | + foreach ($listofproperties as $property) |
|
327 | + { |
|
328 | + if (empty($object->$property)) $object->$property = $soc_origin->$property; |
|
329 | + } |
|
330 | + |
|
331 | + // Concat some data |
|
332 | + $listofproperties=array( |
|
333 | + 'note_public', 'note_private' |
|
334 | + ); |
|
335 | + foreach ($listofproperties as $property) |
|
336 | + { |
|
337 | + $object->$property = dol_concatdesc($object->$property, $soc_origin->$property); |
|
338 | + } |
|
339 | + |
|
340 | + // Merge extrafields |
|
341 | + if (is_array($soc_origin->array_options)) |
|
342 | + { |
|
343 | + foreach ($soc_origin->array_options as $key => $val) |
|
344 | + { |
|
345 | + if (empty($object->array_options[$key])) $object->array_options[$key] = $val; |
|
346 | + } |
|
347 | + } |
|
348 | + |
|
349 | + // Merge categories |
|
350 | + $static_cat = new Categorie($db); |
|
351 | + $custcats = $static_cat->containing($soc_origin->id, 'customer', 'id'); |
|
352 | + $object->setCategories($custcats, 'customer'); |
|
353 | + $suppcats = $static_cat->containing($soc_origin->id, 'supplier', 'id'); |
|
354 | + $object->setCategories($suppcats, 'supplier'); |
|
355 | + |
|
356 | + // If thirdparty has a new code that is same than origin, we clean origin code to avoid duplicate key from database unique keys. |
|
357 | + if ($soc_origin->code_client == $object->code_client |
|
358 | + || $soc_origin->code_fournisseur == $object->code_fournisseur |
|
359 | + || $soc_origin->barcode == $object->barcode) |
|
360 | + { |
|
361 | + dol_syslog("We clean customer and supplier code so we will be able to make the update of target"); |
|
362 | + $soc_origin->code_client = ''; |
|
363 | + $soc_origin->code_fournisseur = ''; |
|
364 | + $soc_origin->barcode = ''; |
|
365 | + $soc_origin->update($soc_origin->id, $user, 0, 1, 1, 'merge'); |
|
366 | + } |
|
367 | + |
|
368 | + // Update |
|
369 | + $result = $object->update($object->id, $user, 0, 1, 1, 'merge'); |
|
370 | + if ($result < 0) |
|
371 | + { |
|
372 | + $error++; |
|
373 | + } |
|
374 | + |
|
375 | + // Move links |
|
376 | + if (! $error) |
|
377 | + { |
|
378 | + $objects = array( |
|
379 | + 'Adherent' => '/adherents/class/adherent.class.php', |
|
380 | + 'Societe' => '/societe/class/societe.class.php', |
|
381 | + 'Categorie' => '/categories/class/categorie.class.php', |
|
382 | + 'ActionComm' => '/comm/action/class/actioncomm.class.php', |
|
383 | + 'Propal' => '/comm/propal/class/propal.class.php', |
|
384 | + 'Commande' => '/commande/class/commande.class.php', |
|
385 | + 'Facture' => '/compta/facture/class/facture.class.php', |
|
386 | + 'FactureRec' => '/compta/facture/class/facture-rec.class.php', |
|
387 | + 'LignePrelevement' => '/compta/prelevement/class/ligneprelevement.class.php', |
|
388 | + 'Contact' => '/contact/class/contact.class.php', |
|
389 | + 'Contrat' => '/contrat/class/contrat.class.php', |
|
390 | + 'Expedition' => '/expedition/class/expedition.class.php', |
|
391 | + 'Fichinter' => '/fichinter/class/fichinter.class.php', |
|
392 | + 'CommandeFournisseur' => '/fourn/class/fournisseur.commande.class.php', |
|
393 | + 'FactureFournisseur' => '/fourn/class/fournisseur.facture.class.php', |
|
394 | + 'SupplierProposal' => '/supplier_proposal/class/supplier_proposal.class.php', |
|
395 | + 'ProductFournisseur' => '/fourn/class/fournisseur.product.class.php', |
|
396 | + 'Livraison' => '/livraison/class/livraison.class.php', |
|
397 | + 'Product' => '/product/class/product.class.php', |
|
398 | + 'Project' => '/projet/class/project.class.php', |
|
399 | + 'User' => '/user/class/user.class.php', |
|
400 | + ); |
|
401 | + |
|
402 | + //First, all core objects must update their tables |
|
403 | + foreach ($objects as $object_name => $object_file) |
|
404 | + { |
|
405 | + require_once DOL_DOCUMENT_ROOT.$object_file; |
|
406 | + |
|
407 | + if (!$errors && !$object_name::replaceThirdparty($db, $soc_origin->id, $object->id)) |
|
408 | + { |
|
409 | + $errors++; |
|
410 | + //setEventMessages($db->lasterror(), null, 'errors'); |
|
411 | + } |
|
412 | + } |
|
413 | + } |
|
414 | + |
|
415 | + // External modules should update their ones too |
|
416 | + if (!$errors) |
|
417 | + { |
|
418 | + $reshook = $hookmanager->executeHooks('replaceThirdparty', array( |
|
419 | + 'soc_origin' => $soc_origin->id, |
|
420 | + 'soc_dest' => $object->id |
|
421 | + ), $soc_dest, $action); |
|
422 | + |
|
423 | + if ($reshook < 0) |
|
424 | + { |
|
425 | + //setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
|
426 | + $errors++; |
|
427 | + } |
|
428 | + } |
|
429 | + |
|
430 | + |
|
431 | + if (! $error) |
|
432 | + { |
|
433 | + $object->context=array('merge'=>1, 'mergefromid'=>$soc_origin->id); |
|
434 | + |
|
435 | + // Call trigger |
|
436 | + $result=$object->call_trigger('COMPANY_MODIFY',$user); |
|
437 | + if ($result < 0) |
|
438 | + { |
|
439 | + //setEventMessages($object->error, $object->errors, 'errors'); |
|
440 | + $error++; |
|
441 | + } |
|
442 | + // End call triggers |
|
443 | + } |
|
444 | + |
|
445 | + if (! $error) |
|
446 | + { |
|
447 | + //We finally remove the old thirdparty |
|
448 | + if ($soc_origin->delete($soc_origin->id, $user) < 1) |
|
449 | + { |
|
450 | + $errors++; |
|
451 | + } |
|
452 | + } |
|
453 | + |
|
454 | + // End of merge |
|
455 | + |
|
456 | + if ($error) |
|
457 | + { |
|
458 | + $db->rollback(); |
|
459 | + |
|
460 | + throw new RestException(500, 'Error failed to merged thirdparty '.$this->companytoremove->id.' into '.$id.'. Enable and read log file for more information.'); |
|
461 | + } |
|
462 | + else |
|
463 | + { |
|
464 | + $db->commit(); |
|
465 | + } |
|
466 | + |
|
467 | + return $this->get($id); |
|
468 | + } |
|
469 | + |
|
470 | + /** |
|
471 | + * Delete thirdparty |
|
472 | + * |
|
473 | + * @param int $id Thirparty ID |
|
474 | + * @return integer |
|
475 | + */ |
|
476 | + function delete($id) |
|
934 | 477 | { |
935 | - if(! DolibarrApiAccess::$user->rights->facture->lire) { |
|
936 | - throw new RestException(401); |
|
937 | - } |
|
938 | - if(empty($id)) { |
|
939 | - throw new RestException(400, 'Thirdparty ID is mandatory'); |
|
940 | - } |
|
941 | - |
|
942 | - if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { |
|
943 | - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
944 | - } |
|
945 | - |
|
946 | - /*$result = $this->thirdparty->fetch($id); |
|
478 | + if(! DolibarrApiAccess::$user->rights->societe->supprimer) { |
|
479 | + throw new RestException(401); |
|
480 | + } |
|
481 | + $result = $this->company->fetch($id); |
|
482 | + if( ! $result ) { |
|
483 | + throw new RestException(404, 'Thirdparty not found'); |
|
484 | + } |
|
485 | + if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { |
|
486 | + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
487 | + } |
|
488 | + return $this->company->delete($id); |
|
489 | + } |
|
490 | + |
|
491 | + /** |
|
492 | + * Get customer categories for a thirdparty |
|
493 | + * |
|
494 | + * @param int $id ID of thirdparty |
|
495 | + * @param string $sortfield Sort field |
|
496 | + * @param string $sortorder Sort order |
|
497 | + * @param int $limit Limit for list |
|
498 | + * @param int $page Page number |
|
499 | + * |
|
500 | + * @return mixed |
|
501 | + * |
|
502 | + * @url GET {id}/categories |
|
503 | + */ |
|
504 | + function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) |
|
505 | + { |
|
506 | + if (! DolibarrApiAccess::$user->rights->categorie->lire) { |
|
507 | + throw new RestException(401); |
|
508 | + } |
|
509 | + |
|
510 | + $result = $this->company->fetch($id); |
|
511 | + if( ! $result ) |
|
512 | + { |
|
513 | + throw new RestException(404, 'Thirdparty not found'); |
|
514 | + } |
|
515 | + |
|
516 | + $categories = new Categorie($this->db); |
|
517 | + |
|
518 | + $result = $categories->getListForItem($id, 'customer', $sortfield, $sortorder, $limit, $page); |
|
519 | + |
|
520 | + if (is_numeric($result) && $result < 0) |
|
521 | + { |
|
522 | + throw new RestException(503, 'Error when retrieve category list : '.$categories->error); |
|
523 | + } |
|
524 | + |
|
525 | + if (is_numeric($result) && $result == 0) // To fix a return of 0 instead of empty array of method getListForItem |
|
526 | + { |
|
527 | + return array(); |
|
528 | + } |
|
529 | + |
|
530 | + return $result; |
|
531 | + } |
|
532 | + |
|
533 | + /** |
|
534 | + * Add a customer category to a thirdparty |
|
535 | + * |
|
536 | + * @param int $id Id of thirdparty |
|
537 | + * @param int $category_id Id of category |
|
538 | + * |
|
539 | + * @return mixed |
|
540 | + * |
|
541 | + * @url POST {id}/categories/{category_id} |
|
542 | + */ |
|
543 | + function addCategory($id, $category_id) |
|
544 | + { |
|
545 | + if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
546 | + throw new RestException(401); |
|
547 | + } |
|
548 | + |
|
549 | + $result = $this->company->fetch($id); |
|
550 | + if( ! $result ) { |
|
551 | + throw new RestException(404, 'Thirdparty not found'); |
|
552 | + } |
|
553 | + $category = new Categorie($this->db); |
|
554 | + $result = $category->fetch($category_id); |
|
555 | + if( ! $result ) { |
|
556 | + throw new RestException(404, 'category not found'); |
|
557 | + } |
|
558 | + |
|
559 | + if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { |
|
560 | + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
561 | + } |
|
562 | + if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) { |
|
563 | + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
564 | + } |
|
565 | + |
|
566 | + $category->add_type($this->company,'customer'); |
|
567 | + |
|
568 | + return $this->_cleanObjectDatas($this->company); |
|
569 | + } |
|
570 | + |
|
571 | + /** |
|
572 | + * Remove the link between a customer category and the thirdparty |
|
573 | + * |
|
574 | + * @param int $id Id of thirdparty |
|
575 | + * @param int $category_id Id of category |
|
576 | + * |
|
577 | + * @return mixed |
|
578 | + * |
|
579 | + * @url DELETE {id}/categories/{category_id} |
|
580 | + */ |
|
581 | + function deleteCategory($id, $category_id) |
|
582 | + { |
|
583 | + if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
584 | + throw new RestException(401); |
|
585 | + } |
|
586 | + |
|
587 | + $result = $this->company->fetch($id); |
|
588 | + if( ! $result ) { |
|
589 | + throw new RestException(404, 'Thirdparty not found'); |
|
590 | + } |
|
591 | + $category = new Categorie($this->db); |
|
592 | + $result = $category->fetch($category_id); |
|
593 | + if( ! $result ) { |
|
594 | + throw new RestException(404, 'category not found'); |
|
595 | + } |
|
596 | + |
|
597 | + if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { |
|
598 | + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
599 | + } |
|
600 | + if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) { |
|
601 | + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
602 | + } |
|
603 | + |
|
604 | + $category->del_type($this->company,'customer'); |
|
605 | + |
|
606 | + return $this->_cleanObjectDatas($this->company); |
|
607 | + } |
|
608 | + |
|
609 | + /** |
|
610 | + * Get supplier categories for a thirdparty |
|
611 | + * |
|
612 | + * @param int $id ID of thirdparty |
|
613 | + * @param string $sortfield Sort field |
|
614 | + * @param string $sortorder Sort order |
|
615 | + * @param int $limit Limit for list |
|
616 | + * @param int $page Page number |
|
617 | + * |
|
618 | + * @return mixed |
|
619 | + * |
|
620 | + * @url GET {id}/supplier_categories |
|
621 | + */ |
|
622 | + function getSupplierCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) |
|
623 | + { |
|
624 | + if (! DolibarrApiAccess::$user->rights->categorie->lire) { |
|
625 | + throw new RestException(401); |
|
626 | + } |
|
627 | + |
|
628 | + $result = $this->company->fetch($id); |
|
629 | + if( ! $result ) |
|
630 | + { |
|
631 | + throw new RestException(404, 'Thirdparty not found'); |
|
632 | + } |
|
633 | + |
|
634 | + $categories = new Categorie($this->db); |
|
635 | + |
|
636 | + $result = $categories->getListForItem($id, 'supplier', $sortfield, $sortorder, $limit, $page); |
|
637 | + |
|
638 | + if (is_numeric($result) && $result < 0) |
|
639 | + { |
|
640 | + throw new RestException(503, 'Error when retrieve category list : '.$categories->error); |
|
641 | + } |
|
642 | + |
|
643 | + if (is_numeric($result) && $result == 0) // To fix a return of 0 instead of empty array of method getListForItem |
|
644 | + { |
|
645 | + return array(); |
|
646 | + } |
|
647 | + |
|
648 | + return $result; |
|
649 | + } |
|
650 | + |
|
651 | + /** |
|
652 | + * Add a supplier category to a thirdparty |
|
653 | + * |
|
654 | + * @param int $id Id of thirdparty |
|
655 | + * @param int $category_id Id of category |
|
656 | + * |
|
657 | + * @return mixed |
|
658 | + * |
|
659 | + * @url POST {id}/supplier_categories/{category_id} |
|
660 | + */ |
|
661 | + function addSupplierCategory($id, $category_id) |
|
662 | + { |
|
663 | + if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
664 | + throw new RestException(401); |
|
665 | + } |
|
666 | + |
|
667 | + $result = $this->company->fetch($id); |
|
668 | + if( ! $result ) { |
|
669 | + throw new RestException(404, 'Thirdparty not found'); |
|
670 | + } |
|
671 | + $category = new Categorie($this->db); |
|
672 | + $result = $category->fetch($category_id); |
|
673 | + if( ! $result ) { |
|
674 | + throw new RestException(404, 'category not found'); |
|
675 | + } |
|
676 | + |
|
677 | + if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { |
|
678 | + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
679 | + } |
|
680 | + if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) { |
|
681 | + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
682 | + } |
|
683 | + |
|
684 | + $category->add_type($this->company,'supplier'); |
|
685 | + |
|
686 | + return $this->_cleanObjectDatas($this->company); |
|
687 | + } |
|
688 | + |
|
689 | + /** |
|
690 | + * Remove the link between a category and the thirdparty |
|
691 | + * |
|
692 | + * @param int $id Id of thirdparty |
|
693 | + * @param int $category_id Id of category |
|
694 | + * |
|
695 | + * @return mixed |
|
696 | + * |
|
697 | + * @url DELETE {id}/supplier_categories/{category_id} |
|
698 | + */ |
|
699 | + function deleteSupplierCategory($id, $category_id) |
|
700 | + { |
|
701 | + if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
702 | + throw new RestException(401); |
|
703 | + } |
|
704 | + |
|
705 | + $result = $this->company->fetch($id); |
|
706 | + if( ! $result ) { |
|
707 | + throw new RestException(404, 'Thirdparty not found'); |
|
708 | + } |
|
709 | + $category = new Categorie($this->db); |
|
710 | + $result = $category->fetch($category_id); |
|
711 | + if( ! $result ) { |
|
712 | + throw new RestException(404, 'category not found'); |
|
713 | + } |
|
714 | + |
|
715 | + if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { |
|
716 | + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
717 | + } |
|
718 | + if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) { |
|
719 | + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
720 | + } |
|
721 | + |
|
722 | + $category->del_type($this->company,'supplier'); |
|
723 | + |
|
724 | + return $this->_cleanObjectDatas($this->company); |
|
725 | + } |
|
726 | + |
|
727 | + |
|
728 | + /** |
|
729 | + * Get outstanding proposals of thirdparty |
|
730 | + * |
|
731 | + * @param int $id ID of the thirdparty |
|
732 | + * @param string $mode 'customer' or 'supplier' |
|
733 | + * |
|
734 | + * @url GET {id}/outstandingproposals |
|
735 | + * |
|
736 | + * @return array List of outstandings proposals of thirdparty |
|
737 | + * |
|
738 | + * @throws 400 |
|
739 | + * @throws 401 |
|
740 | + * @throws 404 |
|
741 | + */ |
|
742 | + function getOutStandingProposals($id, $mode='customer') |
|
743 | + { |
|
744 | + $obj_ret = array(); |
|
745 | + |
|
746 | + if(! DolibarrApiAccess::$user->rights->societe->lire) { |
|
747 | + throw new RestException(401); |
|
748 | + } |
|
749 | + |
|
750 | + if(empty($id)) { |
|
751 | + throw new RestException(400, 'Thirdparty ID is mandatory'); |
|
752 | + } |
|
753 | + |
|
754 | + if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { |
|
755 | + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
756 | + } |
|
757 | + |
|
758 | + $result = $this->company->fetch($id); |
|
759 | + if( ! $result ) { |
|
760 | + throw new RestException(404, 'Thirdparty not found'); |
|
761 | + } |
|
762 | + |
|
763 | + $result = $this->company->getOutstandingProposals($mode); |
|
764 | + |
|
765 | + unset($result['total_ht']); |
|
766 | + unset($result['total_ttc']); |
|
767 | + |
|
768 | + return $result; |
|
769 | + } |
|
770 | + |
|
771 | + |
|
772 | + /** |
|
773 | + * Get outstanding orders of thirdparty |
|
774 | + * |
|
775 | + * @param int $id ID of the thirdparty |
|
776 | + * @param string $mode 'customer' or 'supplier' |
|
777 | + * |
|
778 | + * @url GET {id}/outstandingorders |
|
779 | + * |
|
780 | + * @return array List of outstandings orders of thirdparty |
|
781 | + * |
|
782 | + * @throws 400 |
|
783 | + * @throws 401 |
|
784 | + * @throws 404 |
|
785 | + */ |
|
786 | + function getOutStandingOrder($id, $mode='customer') |
|
787 | + { |
|
788 | + $obj_ret = array(); |
|
789 | + |
|
790 | + if(! DolibarrApiAccess::$user->rights->societe->lire) { |
|
791 | + throw new RestException(401); |
|
792 | + } |
|
793 | + |
|
794 | + if(empty($id)) { |
|
795 | + throw new RestException(400, 'Thirdparty ID is mandatory'); |
|
796 | + } |
|
797 | + |
|
798 | + if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { |
|
799 | + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
800 | + } |
|
801 | + |
|
802 | + $result = $this->company->fetch($id); |
|
803 | + if( ! $result ) { |
|
804 | + throw new RestException(404, 'Thirdparty not found'); |
|
805 | + } |
|
806 | + |
|
807 | + $result = $this->company->getOutstandingOrders($mode); |
|
808 | + |
|
809 | + unset($result['total_ht']); |
|
810 | + unset($result['total_ttc']); |
|
811 | + |
|
812 | + return $result; |
|
813 | + } |
|
814 | + |
|
815 | + /** |
|
816 | + * Get outstanding invoices of thirdparty |
|
817 | + * |
|
818 | + * @param int $id ID of the thirdparty |
|
819 | + * @param string $mode 'customer' or 'supplier' |
|
820 | + * |
|
821 | + * @url GET {id}/outstandinginvoices |
|
822 | + * |
|
823 | + * @return array List of outstandings invoices of thirdparty |
|
824 | + * |
|
825 | + * @throws 400 |
|
826 | + * @throws 401 |
|
827 | + * @throws 404 |
|
828 | + */ |
|
829 | + function getOutStandingInvoices($id, $mode='customer') |
|
830 | + { |
|
831 | + $obj_ret = array(); |
|
832 | + |
|
833 | + if(! DolibarrApiAccess::$user->rights->societe->lire) { |
|
834 | + throw new RestException(401); |
|
835 | + } |
|
836 | + |
|
837 | + if(empty($id)) { |
|
838 | + throw new RestException(400, 'Thirdparty ID is mandatory'); |
|
839 | + } |
|
840 | + |
|
841 | + if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { |
|
842 | + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
843 | + } |
|
844 | + |
|
845 | + $result = $this->company->fetch($id); |
|
846 | + if( ! $result ) { |
|
847 | + throw new RestException(404, 'Thirdparty not found'); |
|
848 | + } |
|
849 | + |
|
850 | + $result = $this->company->getOutstandingBills($mode); |
|
851 | + |
|
852 | + unset($result['total_ht']); |
|
853 | + unset($result['total_ttc']); |
|
854 | + |
|
855 | + return $result; |
|
856 | + } |
|
857 | + |
|
858 | + /** |
|
859 | + * Get fixed amount discount of a thirdparty (all sources: deposit, credit note, commercial offers...) |
|
860 | + * |
|
861 | + * @param int $id ID of the thirdparty |
|
862 | + * @param string $filter Filter exceptional discount. "none" will return every discount, "available" returns unapplied discounts, "used" returns applied discounts {@choice none,available,used} |
|
863 | + * @param string $sortfield Sort field |
|
864 | + * @param string $sortorder Sort order |
|
865 | + * |
|
866 | + * @url GET {id}/fixedamountdiscounts |
|
867 | + * |
|
868 | + * @return array List of fixed discount of thirdparty |
|
869 | + * |
|
870 | + * @throws 400 |
|
871 | + * @throws 401 |
|
872 | + * @throws 404 |
|
873 | + * @throws 503 |
|
874 | + */ |
|
875 | + function getFixedAmountDiscounts($id, $filter="none", $sortfield = "f.type", $sortorder = 'ASC') |
|
876 | + { |
|
877 | + $obj_ret = array(); |
|
878 | + |
|
879 | + if(! DolibarrApiAccess::$user->rights->societe->lire) { |
|
880 | + throw new RestException(401); |
|
881 | + } |
|
882 | + |
|
883 | + if(empty($id)) { |
|
884 | + throw new RestException(400, 'Thirdparty ID is mandatory'); |
|
885 | + } |
|
886 | + |
|
887 | + if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { |
|
888 | + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
889 | + } |
|
890 | + |
|
891 | + $result = $this->company->fetch($id); |
|
892 | + if( ! $result ) { |
|
893 | + throw new RestException(404, 'Thirdparty not found'); |
|
894 | + } |
|
895 | + |
|
896 | + |
|
897 | + $sql = "SELECT f.ref, f.type as factype, re.fk_facture_source, re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc, re.description, re.fk_facture, re.fk_facture_line"; |
|
898 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f"; |
|
899 | + $sql .= " WHERE f.rowid = re.fk_facture_source AND re.fk_soc = ".$id; |
|
900 | + if ($filter == "available") $sql .= " AND re.fk_facture IS NULL AND re.fk_facture_line IS NULL"; |
|
901 | + if ($filter == "used") $sql .= " AND (re.fk_facture IS NOT NULL OR re.fk_facture_line IS NOT NULL)"; |
|
902 | + |
|
903 | + $sql.= $this->db->order($sortfield, $sortorder); |
|
904 | + |
|
905 | + $result = $this->db->query($sql); |
|
906 | + if( ! $result ) { |
|
907 | + throw new RestException(503, $this->db->lasterror()); |
|
908 | + } else { |
|
909 | + $num = $this->db->num_rows($result); |
|
910 | + while ( $obj = $this->db->fetch_object($result) ) { |
|
911 | + $obj_ret[] = $obj; |
|
912 | + } |
|
913 | + } |
|
914 | + |
|
915 | + return $obj_ret; |
|
916 | + } |
|
917 | + |
|
918 | + |
|
919 | + |
|
920 | + /** |
|
921 | + * Return list of invoices qualified to be replaced by another invoice. |
|
922 | + * |
|
923 | + * @param int $id Id of thirdparty |
|
924 | + * |
|
925 | + * @url GET {id}/getinvoicesqualifiedforreplacement |
|
926 | + * |
|
927 | + * @return array |
|
928 | + * @throws 400 |
|
929 | + * @throws 401 |
|
930 | + * @throws 404 |
|
931 | + * @throws 405 |
|
932 | + */ |
|
933 | + function getInvoicesQualifiedForReplacement($id) |
|
934 | + { |
|
935 | + if(! DolibarrApiAccess::$user->rights->facture->lire) { |
|
936 | + throw new RestException(401); |
|
937 | + } |
|
938 | + if(empty($id)) { |
|
939 | + throw new RestException(400, 'Thirdparty ID is mandatory'); |
|
940 | + } |
|
941 | + |
|
942 | + if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { |
|
943 | + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
944 | + } |
|
945 | + |
|
946 | + /*$result = $this->thirdparty->fetch($id); |
|
947 | 947 | if( ! $result ) { |
948 | 948 | throw new RestException(404, 'Thirdparty not found'); |
949 | 949 | }*/ |
950 | 950 | |
951 | - $invoice = new Facture($this->db); |
|
952 | - $result = $invoice->list_replacable_invoices($id); |
|
953 | - if( $result < 0) { |
|
954 | - throw new RestException(405, $this->thirdparty->error); |
|
955 | - } |
|
956 | - |
|
957 | - return $result; |
|
958 | - } |
|
959 | - |
|
960 | - /** |
|
961 | - * Return list of invoices qualified to be corrected by a credit note. |
|
962 | - * Invoices matching the following rules are returned |
|
963 | - * (validated + payment on process) or classified (payed completely or payed partialy) + not already replaced + not already a credit note |
|
964 | - * |
|
965 | - * @param int $id Id of thirdparty |
|
966 | - * |
|
967 | - * @url GET {id}/getinvoicesqualifiedforcreditnote |
|
968 | - * |
|
969 | - * @return array |
|
970 | - * @throws 400 |
|
971 | - * @throws 401 |
|
972 | - * @throws 404 |
|
973 | - * @throws 405 |
|
974 | - */ |
|
975 | - function getInvoicesQualifiedForCreditNote($id) |
|
951 | + $invoice = new Facture($this->db); |
|
952 | + $result = $invoice->list_replacable_invoices($id); |
|
953 | + if( $result < 0) { |
|
954 | + throw new RestException(405, $this->thirdparty->error); |
|
955 | + } |
|
956 | + |
|
957 | + return $result; |
|
958 | + } |
|
959 | + |
|
960 | + /** |
|
961 | + * Return list of invoices qualified to be corrected by a credit note. |
|
962 | + * Invoices matching the following rules are returned |
|
963 | + * (validated + payment on process) or classified (payed completely or payed partialy) + not already replaced + not already a credit note |
|
964 | + * |
|
965 | + * @param int $id Id of thirdparty |
|
966 | + * |
|
967 | + * @url GET {id}/getinvoicesqualifiedforcreditnote |
|
968 | + * |
|
969 | + * @return array |
|
970 | + * @throws 400 |
|
971 | + * @throws 401 |
|
972 | + * @throws 404 |
|
973 | + * @throws 405 |
|
974 | + */ |
|
975 | + function getInvoicesQualifiedForCreditNote($id) |
|
976 | 976 | { |
977 | - if(! DolibarrApiAccess::$user->rights->facture->lire) { |
|
978 | - throw new RestException(401); |
|
979 | - } |
|
980 | - if(empty($id)) { |
|
981 | - throw new RestException(400, 'Thirdparty ID is mandatory'); |
|
982 | - } |
|
983 | - |
|
984 | - if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { |
|
985 | - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
986 | - } |
|
987 | - |
|
988 | - /*$result = $this->thirdparty->fetch($id); |
|
977 | + if(! DolibarrApiAccess::$user->rights->facture->lire) { |
|
978 | + throw new RestException(401); |
|
979 | + } |
|
980 | + if(empty($id)) { |
|
981 | + throw new RestException(400, 'Thirdparty ID is mandatory'); |
|
982 | + } |
|
983 | + |
|
984 | + if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { |
|
985 | + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
986 | + } |
|
987 | + |
|
988 | + /*$result = $this->thirdparty->fetch($id); |
|
989 | 989 | if( ! $result ) { |
990 | 990 | throw new RestException(404, 'Thirdparty not found'); |
991 | 991 | }*/ |
992 | 992 | |
993 | - $invoice = new Facture($this->db); |
|
994 | - $result = $invoice->list_qualified_avoir_invoices($id); |
|
995 | - if( $result < 0) { |
|
996 | - throw new RestException(405, $this->thirdparty->error); |
|
997 | - } |
|
998 | - |
|
999 | - return $result; |
|
1000 | - } |
|
1001 | - |
|
1002 | - /** |
|
1003 | - * Get CompanyBankAccount objects for thirdparty |
|
1004 | - * |
|
1005 | - * @param int $id ID of thirdparty |
|
1006 | - * |
|
1007 | - * @return array |
|
1008 | - * |
|
1009 | - * @url GET {id}/bankaccounts |
|
1010 | - */ |
|
1011 | - function getCompanyBankAccount($id) |
|
993 | + $invoice = new Facture($this->db); |
|
994 | + $result = $invoice->list_qualified_avoir_invoices($id); |
|
995 | + if( $result < 0) { |
|
996 | + throw new RestException(405, $this->thirdparty->error); |
|
997 | + } |
|
998 | + |
|
999 | + return $result; |
|
1000 | + } |
|
1001 | + |
|
1002 | + /** |
|
1003 | + * Get CompanyBankAccount objects for thirdparty |
|
1004 | + * |
|
1005 | + * @param int $id ID of thirdparty |
|
1006 | + * |
|
1007 | + * @return array |
|
1008 | + * |
|
1009 | + * @url GET {id}/bankaccounts |
|
1010 | + */ |
|
1011 | + function getCompanyBankAccount($id) |
|
1012 | + { |
|
1013 | + global $db, $conf; |
|
1014 | + |
|
1015 | + if(! DolibarrApiAccess::$user->rights->facture->lire) { |
|
1016 | + throw new RestException(401); |
|
1017 | + } |
|
1018 | + if(empty($id)) { |
|
1019 | + throw new RestException(400, 'Thirdparty ID is mandatory'); |
|
1020 | + } |
|
1021 | + |
|
1022 | + if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { |
|
1023 | + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
1024 | + } |
|
1025 | + |
|
1026 | + /** |
|
1027 | + * We select all the records that match the socid |
|
1028 | + */ |
|
1029 | + |
|
1030 | + $sql = "SELECT rowid, fk_soc, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,"; |
|
1031 | + $sql.= " owner_address, default_rib, label, datec, tms as datem, rum, frstrecur"; |
|
1032 | + $sql.= " FROM ".MAIN_DB_PREFIX."societe_rib"; |
|
1033 | + if ($id) $sql.= " WHERE fk_soc = ".$id." "; |
|
1034 | + |
|
1035 | + |
|
1036 | + $result = $db->query($sql); |
|
1037 | + |
|
1038 | + if($result->num_rows == 0 ){ |
|
1039 | + throw new RestException(404, 'Account not found'); |
|
1040 | + } |
|
1041 | + |
|
1042 | + $i=0; |
|
1043 | + |
|
1044 | + $accounts =[]; |
|
1045 | + |
|
1046 | + if ($result) |
|
1047 | + { |
|
1048 | + $num = $db->num_rows($result); |
|
1049 | + while ($i < $num) |
|
1050 | + { |
|
1051 | + $obj = $db->fetch_object($result); |
|
1052 | + $account = new CompanyBankAccount($db); |
|
1053 | + if($account->fetch($obj->rowid)) { |
|
1054 | + $accounts[] = $account; |
|
1055 | + } |
|
1056 | + $i++; |
|
1057 | + } |
|
1058 | + } |
|
1059 | + else{ |
|
1060 | + throw new RestException(404, 'Account not found'); |
|
1061 | + } |
|
1062 | + |
|
1063 | + |
|
1064 | + $fields = ['socid', 'default_rib', 'frstrecur', '1000110000001', 'datec', 'datem', 'label', 'bank', 'bic', 'iban', 'id', 'rum']; |
|
1065 | + |
|
1066 | + $returnAccounts = []; |
|
1067 | + |
|
1068 | + foreach($accounts as $account){ |
|
1069 | + $object= []; |
|
1070 | + foreach($account as $key => $value) |
|
1071 | + if(in_array($key, $fields)){ |
|
1072 | + $object[$key] = $value; |
|
1073 | + } |
|
1074 | + $returnAccounts[] = $object; |
|
1075 | + } |
|
1076 | + |
|
1077 | + return $returnAccounts; |
|
1078 | + } |
|
1079 | + |
|
1080 | + /** |
|
1081 | + * Create CompanyBankAccount object for thirdparty |
|
1082 | + * @param int $id ID of thirdparty |
|
1083 | + * @param array $request_data Request data |
|
1084 | + * |
|
1085 | + * @return object ID of thirdparty |
|
1086 | + * |
|
1087 | + * @url POST {id}/bankaccounts |
|
1088 | + */ |
|
1089 | + function createCompanyBankAccount($id, $request_data = null) |
|
1090 | + { |
|
1091 | + if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
1092 | + throw new RestException(401); |
|
1093 | + } |
|
1094 | + |
|
1095 | + $account = new CompanyBankAccount($this->db); |
|
1096 | + |
|
1097 | + $account->socid = $id; |
|
1098 | + |
|
1099 | + foreach($request_data as $field => $value) { |
|
1100 | + $account->$field = $value; |
|
1101 | + } |
|
1102 | + |
|
1103 | + if ($account->create(DolibarrApiAccess::$user) < 0) |
|
1104 | + throw new RestException(500, 'Error creating Company Bank account'); |
|
1105 | + |
|
1106 | + |
|
1107 | + if ($account->update(DolibarrApiAccess::$user) < 0) |
|
1108 | + throw new RestException(500, 'Error updating values'); |
|
1109 | + |
|
1110 | + return $account; |
|
1111 | + } |
|
1112 | + |
|
1113 | + /** |
|
1114 | + * Update CompanyBankAccount object for thirdparty |
|
1115 | + * |
|
1116 | + * @param int $id ID of thirdparty |
|
1117 | + * @param int $bankaccount_id ID of CompanyBankAccount |
|
1118 | + * @param array $request_data Request data |
|
1119 | + * |
|
1120 | + * @return object ID of thirdparty |
|
1121 | + * |
|
1122 | + * @url PUT {id}/bankaccounts/{bankaccount_id} |
|
1123 | + */ |
|
1124 | + function updateCompanyBankAccount($id, $bankaccount_id, $request_data = null) |
|
1125 | + { |
|
1126 | + if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
1127 | + throw new RestException(401); |
|
1128 | + } |
|
1129 | + |
|
1130 | + $account = new CompanyBankAccount($this->db); |
|
1131 | + |
|
1132 | + $account->fetch($bankaccount_id, $id, -1, ''); |
|
1133 | + |
|
1134 | + if($account->socid != $id){ |
|
1135 | + throw new RestException(401); |
|
1136 | + } |
|
1137 | + |
|
1138 | + |
|
1139 | + foreach($request_data as $field => $value) { |
|
1140 | + $account->$field = $value; |
|
1141 | + } |
|
1142 | + |
|
1143 | + if ($account->update(DolibarrApiAccess::$user) < 0) |
|
1144 | + throw new RestException(500, 'Error updating values'); |
|
1145 | + |
|
1146 | + return $account; |
|
1147 | + } |
|
1148 | + |
|
1149 | + /** |
|
1150 | + * Delete a bank account attached to a thirdparty |
|
1151 | + * |
|
1152 | + * @param int $id ID of thirdparty |
|
1153 | + * @param int $bankaccount_id ID of CompanyBankAccount |
|
1154 | + * |
|
1155 | + * @return int -1 if error 1 if correct deletion |
|
1156 | + * |
|
1157 | + * @url DELETE {id}/bankaccounts/{bankaccount_id} |
|
1158 | + */ |
|
1159 | + function deleteCompanyBankAccount($id, $bankaccount_id) |
|
1160 | + { |
|
1161 | + if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
1162 | + throw new RestException(401); |
|
1163 | + } |
|
1164 | + |
|
1165 | + $account = new CompanyBankAccount($this->db); |
|
1166 | + |
|
1167 | + $account->fetch($bankaccount_id); |
|
1168 | + |
|
1169 | + if(!$account->socid == $id) |
|
1170 | + throw new RestException(401); |
|
1171 | + |
|
1172 | + return $account->delete(DolibarrApiAccess::$user); |
|
1173 | + } |
|
1174 | + |
|
1175 | + /** |
|
1176 | + * Generate a Document from a bank account record (like SEPA mandate) |
|
1177 | + * |
|
1178 | + * @param int $id Thirdparty id |
|
1179 | + * @param int $companybankid Companybank id |
|
1180 | + * @param string $model Model of document to generate |
|
1181 | + * @return void |
|
1182 | + * |
|
1183 | + * @url GET {id}/generateBankAccountDocument/{companybankid}/{model} |
|
1184 | + */ |
|
1185 | + public function generateBankAccountDocument($id, $companybankid = null, $model = 'sepamandate') |
|
1186 | + { |
|
1187 | + global $conf; |
|
1188 | + |
|
1189 | + $this->langs->loadLangs(array("main","dict","commercial","products","companies","banks","bills","withdrawals")); |
|
1190 | + |
|
1191 | + $this->company->fetch($id); |
|
1192 | + |
|
1193 | + $action = 'builddoc'; |
|
1194 | + if(! DolibarrApiAccess::$user->rights->societe->creer) |
|
1195 | + throw new RestException(401); |
|
1196 | + |
|
1197 | + $this->company->setDocModel(DolibarrApiAccess::$user, $model); |
|
1198 | + |
|
1199 | + $this->company->fk_bank = $this->company->fk_account; |
|
1200 | + |
|
1201 | + $outputlangs = $this->langs; |
|
1202 | + $newlang=''; |
|
1203 | + |
|
1204 | + if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09'); |
|
1205 | + if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->thirdparty->default_lang)) $newlang=$this->company->thirdparty->default_lang; // for proposal, order, invoice, ... |
|
1206 | + if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->default_lang)) $newlang=$this->company->default_lang; // for thirdparty |
|
1207 | + if (! empty($newlang)) { |
|
1208 | + $outputlangs = new Translate("",$conf); |
|
1209 | + $outputlangs->setDefaultLang($newlang); |
|
1210 | + } |
|
1211 | + |
|
1212 | + // To be sure vars is defined |
|
1213 | + $hidedetails = $hidedesc = $hideref = 0; |
|
1214 | + $moreparams=null; |
|
1215 | + if (empty($hidedetails)) $hidedetails=0; |
|
1216 | + if (empty($hidedesc)) $hidedesc=0; |
|
1217 | + if (empty($hideref)) $hideref=0; |
|
1218 | + if (empty($moreparams)) $moreparams=null; |
|
1219 | + |
|
1220 | + |
|
1221 | + $sql = "SELECT rowid"; |
|
1222 | + $sql.= " FROM ".MAIN_DB_PREFIX."societe_rib"; |
|
1223 | + if ($id) $sql.= " WHERE fk_soc = ".$id." "; |
|
1224 | + if ($companybankid) $sql.= " AND id = ".$companybankid.""; |
|
1225 | + |
|
1226 | + $i=0; |
|
1227 | + $accounts=array(); |
|
1228 | + |
|
1229 | + $result = $this->db->query($sql); |
|
1230 | + if ($result) |
|
1231 | + { |
|
1232 | + if ($result->num_rows == 0) { |
|
1233 | + throw new RestException(404, 'Bank account not found'); |
|
1234 | + } |
|
1235 | + |
|
1236 | + $num = $this->db->num_rows($result); |
|
1237 | + while ($i < $num) |
|
1238 | + { |
|
1239 | + $obj = $this->db->fetch_object($result); |
|
1240 | + |
|
1241 | + $account = new CompanyBankAccount($this->db); |
|
1242 | + if ($account->fetch($obj->rowid)) { |
|
1243 | + $accounts[] = $account; |
|
1244 | + } |
|
1245 | + $i++; |
|
1246 | + } |
|
1247 | + } |
|
1248 | + else |
|
1249 | + { |
|
1250 | + throw new RestException(404, 'Bank account not found'); |
|
1251 | + } |
|
1252 | + |
|
1253 | + $moreparams = array( |
|
1254 | + 'use_companybankid'=>$accounts[0]->id, |
|
1255 | + 'force_dir_output'=>$this->conf->societe->multidir_output[$this->company->entity].'/'.dol_sanitizeFileName($this->company->id) |
|
1256 | + ); |
|
1257 | + |
|
1258 | + $result = 0; |
|
1259 | + |
|
1260 | + $result = $this->company->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); |
|
1261 | + |
|
1262 | + if ($result > 0) |
|
1263 | + { |
|
1264 | + return array("success" => $result); |
|
1265 | + } |
|
1266 | + else |
|
1267 | + { |
|
1268 | + throw new RestException(500); |
|
1269 | + } |
|
1270 | + } |
|
1271 | + |
|
1272 | + /** |
|
1273 | + * Get a specific gateway attached to a thirdparty (by specifying the site key) |
|
1274 | + * |
|
1275 | + * @param int $id ID of thirdparty |
|
1276 | + * @param string $site Site key |
|
1277 | + * |
|
1278 | + * @return SocieteAccount[] |
|
1279 | + * @throws 401 Unauthorized: User does not have permission to read thirdparties |
|
1280 | + * @throws 404 Not Found: Specified thirdparty ID does not belongs to an existing thirdparty |
|
1281 | + * |
|
1282 | + * @url GET {id}/gateways/ |
|
1283 | + */ |
|
1284 | + function getSocieteAccounts($id, $site=null) |
|
1285 | + { |
|
1286 | + global $db, $conf; |
|
1287 | + |
|
1288 | + if(!DolibarrApiAccess::$user->rights->societe->lire) { |
|
1289 | + throw new RestException(401); |
|
1290 | + } |
|
1291 | + |
|
1292 | + if(!DolibarrApi::_checkAccessToResource('societe',$id)) { |
|
1293 | + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
1294 | + } |
|
1295 | + |
|
1296 | + /** |
|
1297 | + * We select all the records that match the socid |
|
1298 | + */ |
|
1299 | + $sql = "SELECT rowid, fk_soc, key_account, site, date_creation, tms FROM ".MAIN_DB_PREFIX."societe_account"; |
|
1300 | + $sql.= " WHERE fk_soc = $id"; |
|
1301 | + if($site) $sql .= " AND site ='$site'"; |
|
1302 | + |
|
1303 | + $result = $db->query($sql); |
|
1304 | + |
|
1305 | + if($result->num_rows == 0){ |
|
1306 | + throw new RestException(404, 'This thirdparty does not have any gateway attached or does not exist.'); |
|
1307 | + } |
|
1308 | + |
|
1309 | + $i=0; |
|
1310 | + |
|
1311 | + $accounts =[]; |
|
1312 | + |
|
1313 | + $num = $db->num_rows($result); |
|
1314 | + while ($i < $num) |
|
1315 | + { |
|
1316 | + $obj = $db->fetch_object($result); |
|
1317 | + $account = new SocieteAccount($db); |
|
1318 | + |
|
1319 | + if($account->fetch($obj->rowid)) { |
|
1320 | + $accounts[] = $account; |
|
1321 | + } |
|
1322 | + $i++; |
|
1323 | + } |
|
1324 | + |
|
1325 | + $fields = ['id', 'fk_soc', 'key_account', 'site', 'date_creation', 'tms']; |
|
1326 | + |
|
1327 | + $returnAccounts = []; |
|
1328 | + |
|
1329 | + foreach($accounts as $account){ |
|
1330 | + $object= []; |
|
1331 | + foreach($account as $key => $value) |
|
1332 | + if(in_array($key, $fields)){ |
|
1333 | + $object[$key] = $value; |
|
1334 | + } |
|
1335 | + $returnAccounts[] = $object; |
|
1336 | + } |
|
1337 | + |
|
1338 | + return $returnAccounts; |
|
1339 | + } |
|
1340 | + |
|
1341 | + /** |
|
1342 | + * Create and attach a new gateway to an existing thirdparty |
|
1343 | + * |
|
1344 | + * Possible fields for request_data (request body) are specified in <code>llx_societe_account</code> table.<br> |
|
1345 | + * See <a href="https://wiki.dolibarr.org/index.php/Table_llx_societe_account">Table llx_societe_account</a> wiki page for more information<br><br> |
|
1346 | + * <u>Example body payload :</u> <pre>{"key_account": "cus_DAVkLSs1LYyYI", "site": "stripe"}</pre> |
|
1347 | + * |
|
1348 | + * @param int $id ID of thirdparty |
|
1349 | + * @param array $request_data Request data |
|
1350 | + * |
|
1351 | + * @return SocieteAccount |
|
1352 | + * @throws 401 Unauthorized: User does not have permission to read thirdparties |
|
1353 | + * @throws 409 Conflict: A SocieteAccount entity (gateway) already exists for this company and site. |
|
1354 | + * @throws 422 Unprocessable Entity: You must pass the site attribute in your request data ! |
|
1355 | + * @throws 500 Internal Server Error: Error creating SocieteAccount account |
|
1356 | + * @status 201 |
|
1357 | + * |
|
1358 | + * @url POST {id}/gateways |
|
1359 | + */ |
|
1360 | + function createSocieteAccount($id, $request_data = null) |
|
1361 | + { |
|
1362 | + global $db; |
|
1363 | + |
|
1364 | + if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
1365 | + throw new RestException(401); |
|
1366 | + } |
|
1367 | + |
|
1368 | + if(!isset($request_data['site'])) { |
|
1369 | + throw new RestException(422, 'Unprocessable Entity: You must pass the site attribute in your request data !'); |
|
1370 | + } |
|
1371 | + |
|
1372 | + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".$id." AND site = '". $request_data['site']."' "; |
|
1373 | + $result = $db->query($sql); |
|
1374 | + |
|
1375 | + if($result->num_rows == 0 ){ |
|
1376 | + $account = new SocieteAccount($this->db); |
|
1377 | + if(!isset($request_data['login'])) { |
|
1378 | + $account->login = ""; |
|
1379 | + } |
|
1380 | + $account->fk_soc = $id; |
|
1381 | + |
|
1382 | + foreach($request_data as $field => $value) { |
|
1383 | + $account->$field = $value; |
|
1384 | + } |
|
1385 | + |
|
1386 | + if ($account->create(DolibarrApiAccess::$user) < 0) |
|
1387 | + throw new RestException(500, 'Error creating SocieteAccount entity. Ensure that the ID of thirdparty provided does exist!'); |
|
1388 | + |
|
1389 | + $this->_cleanObjectDatas($account); |
|
1390 | + |
|
1391 | + return $account; |
|
1392 | + } else { |
|
1393 | + throw new RestException(409, 'A SocieteAccount entity already exists for this company and site.'); |
|
1394 | + } |
|
1395 | + } |
|
1396 | + |
|
1397 | + /** |
|
1398 | + * Create and attach a new (or replace an existing) specific site gateway to a thirdparty |
|
1399 | + * |
|
1400 | + * You <strong>MUST</strong> pass all values to keep (otherwise, they will be deleted) !<br> |
|
1401 | + * If you just need to update specific fields prefer <code>PATCH /thirdparties/{id}/gateways/{site}</code> endpoint.<br><br> |
|
1402 | + * When a <strong>SocieteAccount</strong> entity does not exist for the <code>id</code> and <code>site</code> |
|
1403 | + * supplied, a new one will be created. In that case <code>fk_soc</code> and <code>site</code> members form |
|
1404 | + * request body payload will be ignored and <code>id</code> and <code>site</code> query strings parameters |
|
1405 | + * will be used instead. |
|
1406 | + * |
|
1407 | + * @param int $id ID of thirdparty |
|
1408 | + * @param string $site Site key |
|
1409 | + * @param array $request_data Request data |
|
1410 | + * |
|
1411 | + * @return SocieteAccount |
|
1412 | + * @throws 401 Unauthorized: User does not have permission to read thirdparties |
|
1413 | + * @throws 422 Unprocessable Entity: You must pass the site attribute in your request data ! |
|
1414 | + * @throws 500 Internal Server Error: Error updating SocieteAccount entity |
|
1415 | + * |
|
1416 | + * @throws RestException |
|
1417 | + * @url PUT {id}/gateways/{site} |
|
1418 | + */ |
|
1419 | + function putSocieteAccount($id, $site, $request_data = null) |
|
1012 | 1420 | { |
1013 | - global $db, $conf; |
|
1014 | - |
|
1015 | - if(! DolibarrApiAccess::$user->rights->facture->lire) { |
|
1016 | - throw new RestException(401); |
|
1017 | - } |
|
1018 | - if(empty($id)) { |
|
1019 | - throw new RestException(400, 'Thirdparty ID is mandatory'); |
|
1020 | - } |
|
1021 | - |
|
1022 | - if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { |
|
1023 | - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
1024 | - } |
|
1025 | - |
|
1026 | - /** |
|
1027 | - * We select all the records that match the socid |
|
1028 | - */ |
|
1029 | - |
|
1030 | - $sql = "SELECT rowid, fk_soc, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,"; |
|
1031 | - $sql.= " owner_address, default_rib, label, datec, tms as datem, rum, frstrecur"; |
|
1032 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe_rib"; |
|
1033 | - if ($id) $sql.= " WHERE fk_soc = ".$id." "; |
|
1034 | - |
|
1035 | - |
|
1036 | - $result = $db->query($sql); |
|
1037 | - |
|
1038 | - if($result->num_rows == 0 ){ |
|
1039 | - throw new RestException(404, 'Account not found'); |
|
1040 | - } |
|
1041 | - |
|
1042 | - $i=0; |
|
1043 | - |
|
1044 | - $accounts =[]; |
|
1045 | - |
|
1046 | - if ($result) |
|
1047 | - { |
|
1048 | - $num = $db->num_rows($result); |
|
1049 | - while ($i < $num) |
|
1050 | - { |
|
1051 | - $obj = $db->fetch_object($result); |
|
1052 | - $account = new CompanyBankAccount($db); |
|
1053 | - if($account->fetch($obj->rowid)) { |
|
1054 | - $accounts[] = $account; |
|
1055 | - } |
|
1056 | - $i++; |
|
1057 | - } |
|
1058 | - } |
|
1059 | - else{ |
|
1060 | - throw new RestException(404, 'Account not found'); |
|
1061 | - } |
|
1062 | - |
|
1063 | - |
|
1064 | - $fields = ['socid', 'default_rib', 'frstrecur', '1000110000001', 'datec', 'datem', 'label', 'bank', 'bic', 'iban', 'id', 'rum']; |
|
1065 | - |
|
1066 | - $returnAccounts = []; |
|
1067 | - |
|
1068 | - foreach($accounts as $account){ |
|
1069 | - $object= []; |
|
1070 | - foreach($account as $key => $value) |
|
1071 | - if(in_array($key, $fields)){ |
|
1072 | - $object[$key] = $value; |
|
1073 | - } |
|
1074 | - $returnAccounts[] = $object; |
|
1075 | - } |
|
1076 | - |
|
1077 | - return $returnAccounts; |
|
1078 | - } |
|
1079 | - |
|
1080 | - /** |
|
1081 | - * Create CompanyBankAccount object for thirdparty |
|
1082 | - * @param int $id ID of thirdparty |
|
1083 | - * @param array $request_data Request data |
|
1084 | - * |
|
1085 | - * @return object ID of thirdparty |
|
1086 | - * |
|
1087 | - * @url POST {id}/bankaccounts |
|
1088 | - */ |
|
1089 | - function createCompanyBankAccount($id, $request_data = null) |
|
1090 | - { |
|
1091 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
1092 | - throw new RestException(401); |
|
1093 | - } |
|
1094 | - |
|
1095 | - $account = new CompanyBankAccount($this->db); |
|
1096 | - |
|
1097 | - $account->socid = $id; |
|
1098 | - |
|
1099 | - foreach($request_data as $field => $value) { |
|
1100 | - $account->$field = $value; |
|
1101 | - } |
|
1102 | - |
|
1103 | - if ($account->create(DolibarrApiAccess::$user) < 0) |
|
1104 | - throw new RestException(500, 'Error creating Company Bank account'); |
|
1105 | - |
|
1106 | - |
|
1107 | - if ($account->update(DolibarrApiAccess::$user) < 0) |
|
1108 | - throw new RestException(500, 'Error updating values'); |
|
1109 | - |
|
1110 | - return $account; |
|
1111 | - } |
|
1112 | - |
|
1113 | - /** |
|
1114 | - * Update CompanyBankAccount object for thirdparty |
|
1115 | - * |
|
1116 | - * @param int $id ID of thirdparty |
|
1117 | - * @param int $bankaccount_id ID of CompanyBankAccount |
|
1118 | - * @param array $request_data Request data |
|
1119 | - * |
|
1120 | - * @return object ID of thirdparty |
|
1121 | - * |
|
1122 | - * @url PUT {id}/bankaccounts/{bankaccount_id} |
|
1123 | - */ |
|
1124 | - function updateCompanyBankAccount($id, $bankaccount_id, $request_data = null) |
|
1125 | - { |
|
1126 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
1127 | - throw new RestException(401); |
|
1128 | - } |
|
1129 | - |
|
1130 | - $account = new CompanyBankAccount($this->db); |
|
1131 | - |
|
1132 | - $account->fetch($bankaccount_id, $id, -1, ''); |
|
1133 | - |
|
1134 | - if($account->socid != $id){ |
|
1135 | - throw new RestException(401); |
|
1136 | - } |
|
1137 | - |
|
1138 | - |
|
1139 | - foreach($request_data as $field => $value) { |
|
1140 | - $account->$field = $value; |
|
1141 | - } |
|
1142 | - |
|
1143 | - if ($account->update(DolibarrApiAccess::$user) < 0) |
|
1144 | - throw new RestException(500, 'Error updating values'); |
|
1145 | - |
|
1146 | - return $account; |
|
1147 | - } |
|
1148 | - |
|
1149 | - /** |
|
1150 | - * Delete a bank account attached to a thirdparty |
|
1151 | - * |
|
1152 | - * @param int $id ID of thirdparty |
|
1153 | - * @param int $bankaccount_id ID of CompanyBankAccount |
|
1154 | - * |
|
1155 | - * @return int -1 if error 1 if correct deletion |
|
1156 | - * |
|
1157 | - * @url DELETE {id}/bankaccounts/{bankaccount_id} |
|
1158 | - */ |
|
1159 | - function deleteCompanyBankAccount($id, $bankaccount_id) |
|
1421 | + global $db; |
|
1422 | + |
|
1423 | + if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
1424 | + throw new RestException(401); |
|
1425 | + } |
|
1426 | + |
|
1427 | + $sql = "SELECT rowid, fk_user_creat, date_creation FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = $id AND site = '$site' "; |
|
1428 | + $result = $db->query($sql); |
|
1429 | + |
|
1430 | + // We do not found an existing SocieteAccount entity for this fk_soc and site ; we then create a new one. |
|
1431 | + if($result->num_rows == 0 ){ |
|
1432 | + if(!isset($request_data['key_account'])) { |
|
1433 | + throw new RestException(422, 'Unprocessable Entity: You must pass the key_account attribute in your request data !'); |
|
1434 | + } |
|
1435 | + $account = new SocieteAccount($this->db); |
|
1436 | + if(!isset($request_data['login'])) { |
|
1437 | + $account->login = ""; |
|
1438 | + } |
|
1439 | + |
|
1440 | + foreach($request_data as $field => $value) { |
|
1441 | + $account->$field = $value; |
|
1442 | + } |
|
1443 | + |
|
1444 | + $account->fk_soc = $id; |
|
1445 | + $account->site = $site; |
|
1446 | + |
|
1447 | + if ($account->create(DolibarrApiAccess::$user) < 0) |
|
1448 | + throw new RestException(500, 'Error creating SocieteAccount entity.'); |
|
1449 | + // We found an existing SocieteAccount entity, we are replacing it |
|
1450 | + } else { |
|
1451 | + |
|
1452 | + if(isset($request_data['site']) && $request_data['site'] !== $site) { |
|
1453 | + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".$id." AND site = '". $request_data['site']."' "; |
|
1454 | + $result = $db->query($sql); |
|
1455 | + |
|
1456 | + if($result->num_rows !== 0) |
|
1457 | + throw new RestException(409, "You are trying to update this thirdparty SocieteAccount (gateway record) from $site to ".$request_data['site'] . " but another SocieteAccount entity already exists with this site key."); |
|
1458 | + } |
|
1459 | + |
|
1460 | + $obj = $db->fetch_object($result); |
|
1461 | + |
|
1462 | + $account = new SocieteAccount($this->db); |
|
1463 | + $account->id = $obj->rowid; |
|
1464 | + $account->fk_soc = $id; |
|
1465 | + $account->site = $site; |
|
1466 | + if(!isset($request_data['login'])) { |
|
1467 | + $account->login = ""; |
|
1468 | + } |
|
1469 | + $account->fk_user_creat = $obj->fk_user_creat; |
|
1470 | + $account->date_creation = $obj->date_creation; |
|
1471 | + |
|
1472 | + foreach($request_data as $field => $value) { |
|
1473 | + $account->$field = $value; |
|
1474 | + } |
|
1475 | + |
|
1476 | + if ($account->update(DolibarrApiAccess::$user) < 0) |
|
1477 | + throw new RestException(500, 'Error updating SocieteAccount entity.'); |
|
1478 | + } |
|
1479 | + |
|
1480 | + $this->_cleanObjectDatas($account); |
|
1481 | + |
|
1482 | + return $account; |
|
1483 | + } |
|
1484 | + |
|
1485 | + /** |
|
1486 | + * Update specified values of a specific site gateway attached to a thirdparty |
|
1487 | + * |
|
1488 | + * @param int $id Id of thirdparty |
|
1489 | + * @param string $site Site key |
|
1490 | + * @param array $request_data Request data |
|
1491 | + * |
|
1492 | + * @return SocieteAccount |
|
1493 | + * @throws 401 Unauthorized: User does not have permission to read thirdparties |
|
1494 | + * @throws 404 Not Found: Specified thirdparty ID does not belongs to an existing thirdparty |
|
1495 | + * @throws 409 Conflict: Another SocieteAccount entity already exists for this thirdparty with this site key. |
|
1496 | + * @throws 500 Internal Server Error: Error updating SocieteAccount entity |
|
1497 | + * |
|
1498 | + * @url PATCH {id}/gateways/{site} |
|
1499 | + */ |
|
1500 | + function patchSocieteAccount($id, $site, $request_data = null) |
|
1160 | 1501 | { |
1161 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
1162 | - throw new RestException(401); |
|
1163 | - } |
|
1164 | - |
|
1165 | - $account = new CompanyBankAccount($this->db); |
|
1166 | - |
|
1167 | - $account->fetch($bankaccount_id); |
|
1168 | - |
|
1169 | - if(!$account->socid == $id) |
|
1170 | - throw new RestException(401); |
|
1171 | - |
|
1172 | - return $account->delete(DolibarrApiAccess::$user); |
|
1173 | - } |
|
1174 | - |
|
1175 | - /** |
|
1176 | - * Generate a Document from a bank account record (like SEPA mandate) |
|
1177 | - * |
|
1178 | - * @param int $id Thirdparty id |
|
1179 | - * @param int $companybankid Companybank id |
|
1180 | - * @param string $model Model of document to generate |
|
1181 | - * @return void |
|
1182 | - * |
|
1183 | - * @url GET {id}/generateBankAccountDocument/{companybankid}/{model} |
|
1184 | - */ |
|
1185 | - public function generateBankAccountDocument($id, $companybankid = null, $model = 'sepamandate') |
|
1186 | - { |
|
1187 | - global $conf; |
|
1188 | - |
|
1189 | - $this->langs->loadLangs(array("main","dict","commercial","products","companies","banks","bills","withdrawals")); |
|
1190 | - |
|
1191 | - $this->company->fetch($id); |
|
1192 | - |
|
1193 | - $action = 'builddoc'; |
|
1194 | - if(! DolibarrApiAccess::$user->rights->societe->creer) |
|
1195 | - throw new RestException(401); |
|
1196 | - |
|
1197 | - $this->company->setDocModel(DolibarrApiAccess::$user, $model); |
|
1198 | - |
|
1199 | - $this->company->fk_bank = $this->company->fk_account; |
|
1200 | - |
|
1201 | - $outputlangs = $this->langs; |
|
1202 | - $newlang=''; |
|
1203 | - |
|
1204 | - if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09'); |
|
1205 | - if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->thirdparty->default_lang)) $newlang=$this->company->thirdparty->default_lang; // for proposal, order, invoice, ... |
|
1206 | - if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->default_lang)) $newlang=$this->company->default_lang; // for thirdparty |
|
1207 | - if (! empty($newlang)) { |
|
1208 | - $outputlangs = new Translate("",$conf); |
|
1209 | - $outputlangs->setDefaultLang($newlang); |
|
1210 | - } |
|
1211 | - |
|
1212 | - // To be sure vars is defined |
|
1213 | - $hidedetails = $hidedesc = $hideref = 0; |
|
1214 | - $moreparams=null; |
|
1215 | - if (empty($hidedetails)) $hidedetails=0; |
|
1216 | - if (empty($hidedesc)) $hidedesc=0; |
|
1217 | - if (empty($hideref)) $hideref=0; |
|
1218 | - if (empty($moreparams)) $moreparams=null; |
|
1219 | - |
|
1220 | - |
|
1221 | - $sql = "SELECT rowid"; |
|
1222 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe_rib"; |
|
1223 | - if ($id) $sql.= " WHERE fk_soc = ".$id." "; |
|
1224 | - if ($companybankid) $sql.= " AND id = ".$companybankid.""; |
|
1225 | - |
|
1226 | - $i=0; |
|
1227 | - $accounts=array(); |
|
1228 | - |
|
1229 | - $result = $this->db->query($sql); |
|
1230 | - if ($result) |
|
1231 | - { |
|
1232 | - if ($result->num_rows == 0) { |
|
1233 | - throw new RestException(404, 'Bank account not found'); |
|
1234 | - } |
|
1235 | - |
|
1236 | - $num = $this->db->num_rows($result); |
|
1237 | - while ($i < $num) |
|
1238 | - { |
|
1239 | - $obj = $this->db->fetch_object($result); |
|
1240 | - |
|
1241 | - $account = new CompanyBankAccount($this->db); |
|
1242 | - if ($account->fetch($obj->rowid)) { |
|
1243 | - $accounts[] = $account; |
|
1244 | - } |
|
1245 | - $i++; |
|
1246 | - } |
|
1247 | - } |
|
1248 | - else |
|
1249 | - { |
|
1250 | - throw new RestException(404, 'Bank account not found'); |
|
1251 | - } |
|
1252 | - |
|
1253 | - $moreparams = array( |
|
1254 | - 'use_companybankid'=>$accounts[0]->id, |
|
1255 | - 'force_dir_output'=>$this->conf->societe->multidir_output[$this->company->entity].'/'.dol_sanitizeFileName($this->company->id) |
|
1256 | - ); |
|
1257 | - |
|
1258 | - $result = 0; |
|
1259 | - |
|
1260 | - $result = $this->company->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams); |
|
1261 | - |
|
1262 | - if ($result > 0) |
|
1263 | - { |
|
1264 | - return array("success" => $result); |
|
1265 | - } |
|
1266 | - else |
|
1267 | - { |
|
1268 | - throw new RestException(500); |
|
1269 | - } |
|
1502 | + global $db; |
|
1503 | + |
|
1504 | + if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
1505 | + throw new RestException(401); |
|
1506 | + } |
|
1507 | + |
|
1508 | + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = $id AND site = '$site' "; |
|
1509 | + $result = $db->query($sql); |
|
1510 | + |
|
1511 | + if($result->num_rows == 0 ){ |
|
1512 | + throw new RestException(404, "This thirdparty does not have $site gateway attached or does not exist."); |
|
1513 | + } else { |
|
1514 | + |
|
1515 | + // If the user tries to edit the site member, we check first if |
|
1516 | + if(isset($request_data['site']) && $request_data['site'] !== $site) { |
|
1517 | + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".$id." AND site = '". $request_data['site']."' "; |
|
1518 | + $result = $db->query($sql); |
|
1519 | + |
|
1520 | + if($result->num_rows !== 0) |
|
1521 | + throw new RestException(409, "You are trying to update this thirdparty SocieteAccount (gateway record) site member from $site to ".$request_data['site'] . " but another SocieteAccount entity already exists for this thirdparty with this site key."); |
|
1522 | + } |
|
1523 | + |
|
1524 | + $obj = $db->fetch_object($result); |
|
1525 | + $account = new SocieteAccount($this->db); |
|
1526 | + $account->fetch($obj->rowid); |
|
1527 | + |
|
1528 | + foreach($request_data as $field => $value) { |
|
1529 | + $account->$field = $value; |
|
1530 | + } |
|
1531 | + |
|
1532 | + if ($account->update(DolibarrApiAccess::$user) < 0) |
|
1533 | + throw new RestException(500, 'Error updating SocieteAccount account'); |
|
1534 | + |
|
1535 | + $this->_cleanObjectDatas($account); |
|
1536 | + |
|
1537 | + return $account; |
|
1538 | + } |
|
1270 | 1539 | } |
1271 | 1540 | |
1272 | - /** |
|
1273 | - * Get a specific gateway attached to a thirdparty (by specifying the site key) |
|
1274 | - * |
|
1275 | - * @param int $id ID of thirdparty |
|
1276 | - * @param string $site Site key |
|
1277 | - * |
|
1278 | - * @return SocieteAccount[] |
|
1279 | - * @throws 401 Unauthorized: User does not have permission to read thirdparties |
|
1280 | - * @throws 404 Not Found: Specified thirdparty ID does not belongs to an existing thirdparty |
|
1281 | - * |
|
1282 | - * @url GET {id}/gateways/ |
|
1283 | - */ |
|
1284 | - function getSocieteAccounts($id, $site=null) |
|
1541 | + /** |
|
1542 | + * Delete a specific site gateway attached to a thirdparty (by gateway id) |
|
1543 | + * |
|
1544 | + * @param int $id ID of thirdparty |
|
1545 | + * @param int $site Site key |
|
1546 | + * |
|
1547 | + * @return void |
|
1548 | + * @throws 401 Unauthorized: User does not have permission to delete thirdparties gateways |
|
1549 | + * @throws 404 Not Found: Specified thirdparty ID does not belongs to an existing thirdparty |
|
1550 | + * @throws 500 Internal Server Error: Error deleting SocieteAccount entity |
|
1551 | + * |
|
1552 | + * @url DELETE {id}/gateways/{site} |
|
1553 | + */ |
|
1554 | + function deleteSocieteAccount($id, $site) |
|
1285 | 1555 | { |
1286 | - global $db, $conf; |
|
1287 | - |
|
1288 | - if(!DolibarrApiAccess::$user->rights->societe->lire) { |
|
1289 | - throw new RestException(401); |
|
1290 | - } |
|
1291 | - |
|
1292 | - if(!DolibarrApi::_checkAccessToResource('societe',$id)) { |
|
1293 | - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
|
1294 | - } |
|
1295 | - |
|
1296 | - /** |
|
1297 | - * We select all the records that match the socid |
|
1298 | - */ |
|
1299 | - $sql = "SELECT rowid, fk_soc, key_account, site, date_creation, tms FROM ".MAIN_DB_PREFIX."societe_account"; |
|
1300 | - $sql.= " WHERE fk_soc = $id"; |
|
1301 | - if($site) $sql .= " AND site ='$site'"; |
|
1302 | - |
|
1303 | - $result = $db->query($sql); |
|
1304 | - |
|
1305 | - if($result->num_rows == 0){ |
|
1306 | - throw new RestException(404, 'This thirdparty does not have any gateway attached or does not exist.'); |
|
1307 | - } |
|
1308 | - |
|
1309 | - $i=0; |
|
1310 | - |
|
1311 | - $accounts =[]; |
|
1312 | - |
|
1313 | - $num = $db->num_rows($result); |
|
1314 | - while ($i < $num) |
|
1315 | - { |
|
1316 | - $obj = $db->fetch_object($result); |
|
1317 | - $account = new SocieteAccount($db); |
|
1318 | - |
|
1319 | - if($account->fetch($obj->rowid)) { |
|
1320 | - $accounts[] = $account; |
|
1321 | - } |
|
1322 | - $i++; |
|
1323 | - } |
|
1324 | - |
|
1325 | - $fields = ['id', 'fk_soc', 'key_account', 'site', 'date_creation', 'tms']; |
|
1326 | - |
|
1327 | - $returnAccounts = []; |
|
1328 | - |
|
1329 | - foreach($accounts as $account){ |
|
1330 | - $object= []; |
|
1331 | - foreach($account as $key => $value) |
|
1332 | - if(in_array($key, $fields)){ |
|
1333 | - $object[$key] = $value; |
|
1334 | - } |
|
1335 | - $returnAccounts[] = $object; |
|
1336 | - } |
|
1337 | - |
|
1338 | - return $returnAccounts; |
|
1339 | - } |
|
1340 | - |
|
1341 | - /** |
|
1342 | - * Create and attach a new gateway to an existing thirdparty |
|
1343 | - * |
|
1344 | - * Possible fields for request_data (request body) are specified in <code>llx_societe_account</code> table.<br> |
|
1345 | - * See <a href="https://wiki.dolibarr.org/index.php/Table_llx_societe_account">Table llx_societe_account</a> wiki page for more information<br><br> |
|
1346 | - * <u>Example body payload :</u> <pre>{"key_account": "cus_DAVkLSs1LYyYI", "site": "stripe"}</pre> |
|
1347 | - * |
|
1348 | - * @param int $id ID of thirdparty |
|
1349 | - * @param array $request_data Request data |
|
1350 | - * |
|
1351 | - * @return SocieteAccount |
|
1352 | - * @throws 401 Unauthorized: User does not have permission to read thirdparties |
|
1353 | - * @throws 409 Conflict: A SocieteAccount entity (gateway) already exists for this company and site. |
|
1354 | - * @throws 422 Unprocessable Entity: You must pass the site attribute in your request data ! |
|
1355 | - * @throws 500 Internal Server Error: Error creating SocieteAccount account |
|
1356 | - * @status 201 |
|
1357 | - * |
|
1358 | - * @url POST {id}/gateways |
|
1359 | - */ |
|
1360 | - function createSocieteAccount($id, $request_data = null) |
|
1361 | - { |
|
1362 | - global $db; |
|
1363 | - |
|
1364 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
1365 | - throw new RestException(401); |
|
1366 | - } |
|
1367 | - |
|
1368 | - if(!isset($request_data['site'])) { |
|
1369 | - throw new RestException(422, 'Unprocessable Entity: You must pass the site attribute in your request data !'); |
|
1370 | - } |
|
1371 | - |
|
1372 | - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".$id." AND site = '". $request_data['site']."' "; |
|
1373 | - $result = $db->query($sql); |
|
1374 | - |
|
1375 | - if($result->num_rows == 0 ){ |
|
1376 | - $account = new SocieteAccount($this->db); |
|
1377 | - if(!isset($request_data['login'])) { |
|
1378 | - $account->login = ""; |
|
1379 | - } |
|
1380 | - $account->fk_soc = $id; |
|
1381 | - |
|
1382 | - foreach($request_data as $field => $value) { |
|
1383 | - $account->$field = $value; |
|
1384 | - } |
|
1385 | - |
|
1386 | - if ($account->create(DolibarrApiAccess::$user) < 0) |
|
1387 | - throw new RestException(500, 'Error creating SocieteAccount entity. Ensure that the ID of thirdparty provided does exist!'); |
|
1388 | - |
|
1389 | - $this->_cleanObjectDatas($account); |
|
1390 | - |
|
1391 | - return $account; |
|
1392 | - } else { |
|
1393 | - throw new RestException(409, 'A SocieteAccount entity already exists for this company and site.'); |
|
1394 | - } |
|
1395 | - } |
|
1396 | - |
|
1397 | - /** |
|
1398 | - * Create and attach a new (or replace an existing) specific site gateway to a thirdparty |
|
1399 | - * |
|
1400 | - * You <strong>MUST</strong> pass all values to keep (otherwise, they will be deleted) !<br> |
|
1401 | - * If you just need to update specific fields prefer <code>PATCH /thirdparties/{id}/gateways/{site}</code> endpoint.<br><br> |
|
1402 | - * When a <strong>SocieteAccount</strong> entity does not exist for the <code>id</code> and <code>site</code> |
|
1403 | - * supplied, a new one will be created. In that case <code>fk_soc</code> and <code>site</code> members form |
|
1404 | - * request body payload will be ignored and <code>id</code> and <code>site</code> query strings parameters |
|
1405 | - * will be used instead. |
|
1406 | - * |
|
1407 | - * @param int $id ID of thirdparty |
|
1408 | - * @param string $site Site key |
|
1409 | - * @param array $request_data Request data |
|
1410 | - * |
|
1411 | - * @return SocieteAccount |
|
1412 | - * @throws 401 Unauthorized: User does not have permission to read thirdparties |
|
1413 | - * @throws 422 Unprocessable Entity: You must pass the site attribute in your request data ! |
|
1414 | - * @throws 500 Internal Server Error: Error updating SocieteAccount entity |
|
1415 | - * |
|
1416 | - * @throws RestException |
|
1417 | - * @url PUT {id}/gateways/{site} |
|
1418 | - */ |
|
1419 | - function putSocieteAccount($id, $site, $request_data = null) |
|
1420 | - { |
|
1421 | - global $db; |
|
1422 | - |
|
1423 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
1424 | - throw new RestException(401); |
|
1425 | - } |
|
1426 | - |
|
1427 | - $sql = "SELECT rowid, fk_user_creat, date_creation FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = $id AND site = '$site' "; |
|
1428 | - $result = $db->query($sql); |
|
1429 | - |
|
1430 | - // We do not found an existing SocieteAccount entity for this fk_soc and site ; we then create a new one. |
|
1431 | - if($result->num_rows == 0 ){ |
|
1432 | - if(!isset($request_data['key_account'])) { |
|
1433 | - throw new RestException(422, 'Unprocessable Entity: You must pass the key_account attribute in your request data !'); |
|
1434 | - } |
|
1435 | - $account = new SocieteAccount($this->db); |
|
1436 | - if(!isset($request_data['login'])) { |
|
1437 | - $account->login = ""; |
|
1438 | - } |
|
1439 | - |
|
1440 | - foreach($request_data as $field => $value) { |
|
1441 | - $account->$field = $value; |
|
1442 | - } |
|
1443 | - |
|
1444 | - $account->fk_soc = $id; |
|
1445 | - $account->site = $site; |
|
1446 | - |
|
1447 | - if ($account->create(DolibarrApiAccess::$user) < 0) |
|
1448 | - throw new RestException(500, 'Error creating SocieteAccount entity.'); |
|
1449 | - // We found an existing SocieteAccount entity, we are replacing it |
|
1450 | - } else { |
|
1451 | - |
|
1452 | - if(isset($request_data['site']) && $request_data['site'] !== $site) { |
|
1453 | - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".$id." AND site = '". $request_data['site']."' "; |
|
1454 | - $result = $db->query($sql); |
|
1455 | - |
|
1456 | - if($result->num_rows !== 0) |
|
1457 | - throw new RestException(409, "You are trying to update this thirdparty SocieteAccount (gateway record) from $site to ".$request_data['site'] . " but another SocieteAccount entity already exists with this site key."); |
|
1458 | - } |
|
1459 | - |
|
1460 | - $obj = $db->fetch_object($result); |
|
1461 | - |
|
1462 | - $account = new SocieteAccount($this->db); |
|
1463 | - $account->id = $obj->rowid; |
|
1464 | - $account->fk_soc = $id; |
|
1465 | - $account->site = $site; |
|
1466 | - if(!isset($request_data['login'])) { |
|
1467 | - $account->login = ""; |
|
1468 | - } |
|
1469 | - $account->fk_user_creat = $obj->fk_user_creat; |
|
1470 | - $account->date_creation = $obj->date_creation; |
|
1471 | - |
|
1472 | - foreach($request_data as $field => $value) { |
|
1473 | - $account->$field = $value; |
|
1474 | - } |
|
1475 | - |
|
1476 | - if ($account->update(DolibarrApiAccess::$user) < 0) |
|
1477 | - throw new RestException(500, 'Error updating SocieteAccount entity.'); |
|
1478 | - } |
|
1479 | - |
|
1480 | - $this->_cleanObjectDatas($account); |
|
1481 | - |
|
1482 | - return $account; |
|
1483 | - } |
|
1484 | - |
|
1485 | - /** |
|
1486 | - * Update specified values of a specific site gateway attached to a thirdparty |
|
1487 | - * |
|
1488 | - * @param int $id Id of thirdparty |
|
1489 | - * @param string $site Site key |
|
1490 | - * @param array $request_data Request data |
|
1491 | - * |
|
1492 | - * @return SocieteAccount |
|
1493 | - * @throws 401 Unauthorized: User does not have permission to read thirdparties |
|
1494 | - * @throws 404 Not Found: Specified thirdparty ID does not belongs to an existing thirdparty |
|
1495 | - * @throws 409 Conflict: Another SocieteAccount entity already exists for this thirdparty with this site key. |
|
1496 | - * @throws 500 Internal Server Error: Error updating SocieteAccount entity |
|
1497 | - * |
|
1498 | - * @url PATCH {id}/gateways/{site} |
|
1499 | - */ |
|
1500 | - function patchSocieteAccount($id, $site, $request_data = null) |
|
1501 | - { |
|
1502 | - global $db; |
|
1503 | - |
|
1504 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
1505 | - throw new RestException(401); |
|
1506 | - } |
|
1507 | - |
|
1508 | - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = $id AND site = '$site' "; |
|
1509 | - $result = $db->query($sql); |
|
1510 | - |
|
1511 | - if($result->num_rows == 0 ){ |
|
1512 | - throw new RestException(404, "This thirdparty does not have $site gateway attached or does not exist."); |
|
1513 | - } else { |
|
1514 | - |
|
1515 | - // If the user tries to edit the site member, we check first if |
|
1516 | - if(isset($request_data['site']) && $request_data['site'] !== $site) { |
|
1517 | - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".$id." AND site = '". $request_data['site']."' "; |
|
1518 | - $result = $db->query($sql); |
|
1519 | - |
|
1520 | - if($result->num_rows !== 0) |
|
1521 | - throw new RestException(409, "You are trying to update this thirdparty SocieteAccount (gateway record) site member from $site to ".$request_data['site'] . " but another SocieteAccount entity already exists for this thirdparty with this site key."); |
|
1522 | - } |
|
1523 | - |
|
1524 | - $obj = $db->fetch_object($result); |
|
1525 | - $account = new SocieteAccount($this->db); |
|
1526 | - $account->fetch($obj->rowid); |
|
1527 | - |
|
1528 | - foreach($request_data as $field => $value) { |
|
1529 | - $account->$field = $value; |
|
1530 | - } |
|
1531 | - |
|
1532 | - if ($account->update(DolibarrApiAccess::$user) < 0) |
|
1533 | - throw new RestException(500, 'Error updating SocieteAccount account'); |
|
1534 | - |
|
1535 | - $this->_cleanObjectDatas($account); |
|
1536 | - |
|
1537 | - return $account; |
|
1538 | - } |
|
1539 | - } |
|
1540 | - |
|
1541 | - /** |
|
1542 | - * Delete a specific site gateway attached to a thirdparty (by gateway id) |
|
1543 | - * |
|
1544 | - * @param int $id ID of thirdparty |
|
1545 | - * @param int $site Site key |
|
1546 | - * |
|
1547 | - * @return void |
|
1548 | - * @throws 401 Unauthorized: User does not have permission to delete thirdparties gateways |
|
1549 | - * @throws 404 Not Found: Specified thirdparty ID does not belongs to an existing thirdparty |
|
1550 | - * @throws 500 Internal Server Error: Error deleting SocieteAccount entity |
|
1551 | - * |
|
1552 | - * @url DELETE {id}/gateways/{site} |
|
1553 | - */ |
|
1554 | - function deleteSocieteAccount($id, $site) |
|
1556 | + global /** @var Database $db */ |
|
1557 | + $db; |
|
1558 | + |
|
1559 | + if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
1560 | + throw new RestException(401); |
|
1561 | + } |
|
1562 | + |
|
1563 | + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = $id AND site = '$site' "; |
|
1564 | + $result = $db->query($sql); |
|
1565 | + |
|
1566 | + if($result->num_rows == 0 ){ |
|
1567 | + throw new RestException(404); |
|
1568 | + } else { |
|
1569 | + $obj = $db->fetch_object($result); |
|
1570 | + $account = new SocieteAccount($this->db); |
|
1571 | + $account->fetch($obj->rowid); |
|
1572 | + |
|
1573 | + if($account->delete(DolibarrApiAccess::$user) < 0) { |
|
1574 | + throw new RestException(500, "Error while deleting $site gateway attached to this third party"); |
|
1575 | + } |
|
1576 | + } |
|
1577 | + } |
|
1578 | + |
|
1579 | + /** |
|
1580 | + * Delete all gateways attached to a thirdparty |
|
1581 | + * |
|
1582 | + * @param int $id ID of thirdparty |
|
1583 | + * |
|
1584 | + * @return void |
|
1585 | + * @throws 401 Unauthorized: User does not have permission to delete thirdparties gateways |
|
1586 | + * @throws 404 Not Found: Specified thirdparty ID does not belongs to an existing thirdparty |
|
1587 | + * @throws 500 Internal Server Error: Error deleting SocieteAccount entity |
|
1588 | + * |
|
1589 | + * @url DELETE {id}/gateways |
|
1590 | + */ |
|
1591 | + function deleteSocieteAccounts($id) |
|
1555 | 1592 | { |
1556 | - global /** @var Database $db */ |
|
1557 | - $db; |
|
1558 | - |
|
1559 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
1560 | - throw new RestException(401); |
|
1561 | - } |
|
1562 | - |
|
1563 | - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = $id AND site = '$site' "; |
|
1564 | - $result = $db->query($sql); |
|
1565 | - |
|
1566 | - if($result->num_rows == 0 ){ |
|
1567 | - throw new RestException(404); |
|
1568 | - } else { |
|
1569 | - $obj = $db->fetch_object($result); |
|
1570 | - $account = new SocieteAccount($this->db); |
|
1571 | - $account->fetch($obj->rowid); |
|
1572 | - |
|
1573 | - if($account->delete(DolibarrApiAccess::$user) < 0) { |
|
1574 | - throw new RestException(500, "Error while deleting $site gateway attached to this third party"); |
|
1575 | - } |
|
1576 | - } |
|
1577 | - } |
|
1578 | - |
|
1579 | - /** |
|
1580 | - * Delete all gateways attached to a thirdparty |
|
1581 | - * |
|
1582 | - * @param int $id ID of thirdparty |
|
1583 | - * |
|
1584 | - * @return void |
|
1585 | - * @throws 401 Unauthorized: User does not have permission to delete thirdparties gateways |
|
1586 | - * @throws 404 Not Found: Specified thirdparty ID does not belongs to an existing thirdparty |
|
1587 | - * @throws 500 Internal Server Error: Error deleting SocieteAccount entity |
|
1588 | - * |
|
1589 | - * @url DELETE {id}/gateways |
|
1590 | - */ |
|
1591 | - function deleteSocieteAccounts($id) |
|
1593 | + global /** @var Database $db */ |
|
1594 | + $db; |
|
1595 | + |
|
1596 | + if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
1597 | + throw new RestException(401); |
|
1598 | + } |
|
1599 | + |
|
1600 | + /** |
|
1601 | + * We select all the records that match the socid |
|
1602 | + */ |
|
1603 | + |
|
1604 | + $sql = "SELECT rowid, fk_soc, key_account, site, date_creation, tms"; |
|
1605 | + $sql.= " FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = $id "; |
|
1606 | + |
|
1607 | + $result = $db->query($sql); |
|
1608 | + |
|
1609 | + if($result->num_rows == 0 ){ |
|
1610 | + throw new RestException(404, 'This third party does not have any gateway attached or does not exist.'); |
|
1611 | + } else { |
|
1612 | + $i=0; |
|
1613 | + |
|
1614 | + $num = $db->num_rows($result); |
|
1615 | + while ($i < $num) |
|
1616 | + { |
|
1617 | + $obj = $db->fetch_object($result); |
|
1618 | + $account = new SocieteAccount($db); |
|
1619 | + $account->fetch($obj->rowid); |
|
1620 | + |
|
1621 | + if($account->delete(DolibarrApiAccess::$user) < 0) { |
|
1622 | + throw new RestException(500, 'Error while deleting gateways attached to this third party'); |
|
1623 | + } |
|
1624 | + $i++; |
|
1625 | + } |
|
1626 | + } |
|
1627 | + } |
|
1628 | + |
|
1629 | + /** |
|
1630 | + * Clean sensible object datas |
|
1631 | + * |
|
1632 | + * @param object $object Object to clean |
|
1633 | + * @return array Array of cleaned object properties |
|
1634 | + */ |
|
1635 | + function _cleanObjectDatas($object) |
|
1592 | 1636 | { |
1593 | - global /** @var Database $db */ |
|
1594 | - $db; |
|
1595 | - |
|
1596 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
1597 | - throw new RestException(401); |
|
1598 | - } |
|
1599 | - |
|
1600 | - /** |
|
1601 | - * We select all the records that match the socid |
|
1602 | - */ |
|
1603 | - |
|
1604 | - $sql = "SELECT rowid, fk_soc, key_account, site, date_creation, tms"; |
|
1605 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = $id "; |
|
1606 | - |
|
1607 | - $result = $db->query($sql); |
|
1608 | - |
|
1609 | - if($result->num_rows == 0 ){ |
|
1610 | - throw new RestException(404, 'This third party does not have any gateway attached or does not exist.'); |
|
1611 | - } else { |
|
1612 | - $i=0; |
|
1613 | - |
|
1614 | - $num = $db->num_rows($result); |
|
1615 | - while ($i < $num) |
|
1616 | - { |
|
1617 | - $obj = $db->fetch_object($result); |
|
1618 | - $account = new SocieteAccount($db); |
|
1619 | - $account->fetch($obj->rowid); |
|
1620 | - |
|
1621 | - if($account->delete(DolibarrApiAccess::$user) < 0) { |
|
1622 | - throw new RestException(500, 'Error while deleting gateways attached to this third party'); |
|
1623 | - } |
|
1624 | - $i++; |
|
1625 | - } |
|
1626 | - } |
|
1627 | - } |
|
1628 | - |
|
1629 | - /** |
|
1630 | - * Clean sensible object datas |
|
1631 | - * |
|
1632 | - * @param object $object Object to clean |
|
1633 | - * @return array Array of cleaned object properties |
|
1634 | - */ |
|
1635 | - function _cleanObjectDatas($object) |
|
1637 | + $object = parent::_cleanObjectDatas($object); |
|
1638 | + |
|
1639 | + unset($object->nom); // ->name already defined and nom deprecated |
|
1640 | + |
|
1641 | + unset($object->total_ht); |
|
1642 | + unset($object->total_tva); |
|
1643 | + unset($object->total_localtax1); |
|
1644 | + unset($object->total_localtax2); |
|
1645 | + unset($object->total_ttc); |
|
1646 | + |
|
1647 | + unset($object->lines); |
|
1648 | + unset($object->thirdparty); |
|
1649 | + |
|
1650 | + return $object; |
|
1651 | + } |
|
1652 | + |
|
1653 | + /** |
|
1654 | + * Validate fields before create or update object |
|
1655 | + * |
|
1656 | + * @param array $data Datas to validate |
|
1657 | + * @return array |
|
1658 | + * |
|
1659 | + * @throws RestException |
|
1660 | + */ |
|
1661 | + function _validate($data) |
|
1636 | 1662 | { |
1637 | - $object = parent::_cleanObjectDatas($object); |
|
1638 | - |
|
1639 | - unset($object->nom); // ->name already defined and nom deprecated |
|
1640 | - |
|
1641 | - unset($object->total_ht); |
|
1642 | - unset($object->total_tva); |
|
1643 | - unset($object->total_localtax1); |
|
1644 | - unset($object->total_localtax2); |
|
1645 | - unset($object->total_ttc); |
|
1646 | - |
|
1647 | - unset($object->lines); |
|
1648 | - unset($object->thirdparty); |
|
1649 | - |
|
1650 | - return $object; |
|
1651 | - } |
|
1652 | - |
|
1653 | - /** |
|
1654 | - * Validate fields before create or update object |
|
1655 | - * |
|
1656 | - * @param array $data Datas to validate |
|
1657 | - * @return array |
|
1658 | - * |
|
1659 | - * @throws RestException |
|
1660 | - */ |
|
1661 | - function _validate($data) |
|
1662 | - { |
|
1663 | - $thirdparty = array(); |
|
1664 | - foreach (Thirdparties::$FIELDS as $field) { |
|
1665 | - if (!isset($data[$field])) |
|
1666 | - throw new RestException(400, "$field field missing"); |
|
1667 | - $thirdparty[$field] = $data[$field]; |
|
1668 | - } |
|
1669 | - return $thirdparty; |
|
1670 | - } |
|
1663 | + $thirdparty = array(); |
|
1664 | + foreach (Thirdparties::$FIELDS as $field) { |
|
1665 | + if (!isset($data[$field])) |
|
1666 | + throw new RestException(400, "$field field missing"); |
|
1667 | + $thirdparty[$field] = $data[$field]; |
|
1668 | + } |
|
1669 | + return $thirdparty; |
|
1670 | + } |
|
1671 | 1671 | } |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | |
57 | 57 | $this->company = new Societe($this->db); |
58 | 58 | |
59 | - if (! empty($conf->global->SOCIETE_EMAIL_MANDATORY)) { |
|
59 | + if (!empty($conf->global->SOCIETE_EMAIL_MANDATORY)) { |
|
60 | 60 | static::$FIELDS[] = 'email'; |
61 | 61 | } |
62 | 62 | } |
@@ -73,20 +73,20 @@ discard block |
||
73 | 73 | */ |
74 | 74 | function get($id) |
75 | 75 | { |
76 | - if(! DolibarrApiAccess::$user->rights->societe->lire) { |
|
76 | + if (!DolibarrApiAccess::$user->rights->societe->lire) { |
|
77 | 77 | throw new RestException(401); |
78 | 78 | } |
79 | 79 | |
80 | 80 | $result = $this->company->fetch($id); |
81 | - if( ! $result ) { |
|
81 | + if (!$result) { |
|
82 | 82 | throw new RestException(404, 'Thirdparty not found'); |
83 | 83 | } |
84 | 84 | |
85 | - if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { |
|
85 | + if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) { |
|
86 | 86 | throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
87 | 87 | } |
88 | 88 | |
89 | - if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { |
|
89 | + if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) { |
|
90 | 90 | $filterabsolutediscount = "fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice |
91 | 91 | $filtercreditnote = "fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice |
92 | 92 | } else { |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.nom:like:'TheCompany%') and (t.date_creation:<:'20160101')" |
118 | 118 | * @return array Array of thirdparty objects |
119 | 119 | */ |
120 | - function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $mode=0, $sqlfilters = '') |
|
120 | + function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $mode = 0, $sqlfilters = '') |
|
121 | 121 | { |
122 | 122 | global $db, $conf; |
123 | 123 | |
@@ -128,23 +128,23 @@ discard block |
||
128 | 128 | |
129 | 129 | // If the internal user must only see his customers, force searching by him |
130 | 130 | $search_sale = 0; |
131 | - if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id; |
|
131 | + if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id; |
|
132 | 132 | |
133 | 133 | $sql = "SELECT t.rowid"; |
134 | 134 | if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) |
135 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe as t"; |
|
136 | - |
|
137 | - if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale |
|
138 | - $sql.= ", ".MAIN_DB_PREFIX."c_stcomm as st"; |
|
139 | - $sql.= " WHERE t.fk_stcomm = st.id"; |
|
140 | - if ($mode == 1) $sql.= " AND t.client IN (1, 3)"; |
|
141 | - if ($mode == 2) $sql.= " AND t.client IN (2, 3)"; |
|
142 | - if ($mode == 3) $sql.= " AND t.client IN (0)"; |
|
143 | - $sql.= ' AND t.entity IN ('.getEntity('societe').')'; |
|
144 | - if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc"; |
|
135 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe as t"; |
|
136 | + |
|
137 | + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale |
|
138 | + $sql .= ", ".MAIN_DB_PREFIX."c_stcomm as st"; |
|
139 | + $sql .= " WHERE t.fk_stcomm = st.id"; |
|
140 | + if ($mode == 1) $sql .= " AND t.client IN (1, 3)"; |
|
141 | + if ($mode == 2) $sql .= " AND t.client IN (2, 3)"; |
|
142 | + if ($mode == 3) $sql .= " AND t.client IN (0)"; |
|
143 | + $sql .= ' AND t.entity IN ('.getEntity('societe').')'; |
|
144 | + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc"; |
|
145 | 145 | //if ($email != NULL) $sql.= " AND s.email = \"".$email."\""; |
146 | - if ($socid) $sql.= " AND t.rowid IN (".$socids.")"; |
|
147 | - if ($search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale |
|
146 | + if ($socid) $sql .= " AND t.rowid IN (".$socids.")"; |
|
147 | + if ($search_sale > 0) $sql .= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale |
|
148 | 148 | // Insert sale filter |
149 | 149 | if ($search_sale > 0) |
150 | 150 | { |
@@ -153,15 +153,15 @@ discard block |
||
153 | 153 | // Add sql filters |
154 | 154 | if ($sqlfilters) |
155 | 155 | { |
156 | - if (! DolibarrApi::_checkFilters($sqlfilters)) |
|
156 | + if (!DolibarrApi::_checkFilters($sqlfilters)) |
|
157 | 157 | { |
158 | 158 | throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); |
159 | 159 | } |
160 | - $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
161 | - $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
160 | + $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
161 | + $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
|
162 | 162 | } |
163 | 163 | |
164 | - $sql.= $db->order($sortfield, $sortorder); |
|
164 | + $sql .= $db->order($sortfield, $sortorder); |
|
165 | 165 | |
166 | 166 | if ($limit) { |
167 | 167 | if ($page < 0) |
@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | } |
171 | 171 | $offset = $limit * $page; |
172 | 172 | |
173 | - $sql.= $db->plimit($limit + 1, $offset); |
|
173 | + $sql .= $db->plimit($limit + 1, $offset); |
|
174 | 174 | } |
175 | 175 | |
176 | 176 | $result = $db->query($sql); |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | { |
183 | 183 | $obj = $db->fetch_object($result); |
184 | 184 | $soc_static = new Societe($db); |
185 | - if($soc_static->fetch($obj->rowid)) { |
|
185 | + if ($soc_static->fetch($obj->rowid)) { |
|
186 | 186 | $obj_ret[] = $this->_cleanObjectDatas($soc_static); |
187 | 187 | } |
188 | 188 | $i++; |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | else { |
192 | 192 | throw new RestException(503, 'Error when retrieve thirdparties : '.$db->lasterror()); |
193 | 193 | } |
194 | - if( ! count($obj_ret)) { |
|
194 | + if (!count($obj_ret)) { |
|
195 | 195 | throw new RestException(404, 'Thirdparties not found'); |
196 | 196 | } |
197 | 197 | return $obj_ret; |
@@ -205,13 +205,13 @@ discard block |
||
205 | 205 | */ |
206 | 206 | function post($request_data = null) |
207 | 207 | { |
208 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
208 | + if (!DolibarrApiAccess::$user->rights->societe->creer) { |
|
209 | 209 | throw new RestException(401); |
210 | 210 | } |
211 | 211 | // Check mandatory fields |
212 | 212 | $result = $this->_validate($request_data); |
213 | 213 | |
214 | - foreach($request_data as $field => $value) { |
|
214 | + foreach ($request_data as $field => $value) { |
|
215 | 215 | $this->company->$field = $value; |
216 | 216 | } |
217 | 217 | if ($this->company->create(DolibarrApiAccess::$user) < 0) |
@@ -229,25 +229,25 @@ discard block |
||
229 | 229 | */ |
230 | 230 | function put($id, $request_data = null) |
231 | 231 | { |
232 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
232 | + if (!DolibarrApiAccess::$user->rights->societe->creer) { |
|
233 | 233 | throw new RestException(401); |
234 | 234 | } |
235 | 235 | |
236 | 236 | $result = $this->company->fetch($id); |
237 | - if( ! $result ) { |
|
237 | + if (!$result) { |
|
238 | 238 | throw new RestException(404, 'Thirdparty not found'); |
239 | 239 | } |
240 | 240 | |
241 | - if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { |
|
241 | + if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) { |
|
242 | 242 | throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
243 | 243 | } |
244 | 244 | |
245 | - foreach($request_data as $field => $value) { |
|
245 | + foreach ($request_data as $field => $value) { |
|
246 | 246 | if ($field == 'id') continue; |
247 | 247 | $this->company->$field = $value; |
248 | 248 | } |
249 | 249 | |
250 | - if($this->company->update($id, DolibarrApiAccess::$user,1,'','','update')) |
|
250 | + if ($this->company->update($id, DolibarrApiAccess::$user, 1, '', '', 'update')) |
|
251 | 251 | return $this->get($id); |
252 | 252 | |
253 | 253 | return false; |
@@ -278,27 +278,27 @@ discard block |
||
278 | 278 | throw new RestException(400, 'Try to merge a thirdparty into itself'); |
279 | 279 | } |
280 | 280 | |
281 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
281 | + if (!DolibarrApiAccess::$user->rights->societe->creer) { |
|
282 | 282 | throw new RestException(401); |
283 | 283 | } |
284 | 284 | |
285 | - $result = $this->company->fetch($id); // include the fetch of extra fields |
|
286 | - if( ! $result ) { |
|
285 | + $result = $this->company->fetch($id); // include the fetch of extra fields |
|
286 | + if (!$result) { |
|
287 | 287 | throw new RestException(404, 'Thirdparty not found'); |
288 | 288 | } |
289 | 289 | |
290 | - if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { |
|
290 | + if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) { |
|
291 | 291 | throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
292 | 292 | } |
293 | 293 | |
294 | 294 | $this->companytoremove = new Societe($db); |
295 | 295 | |
296 | - $result = $this->companytoremove->fetch($idtodelete); // include the fetch of extra fields |
|
297 | - if( ! $result ) { |
|
296 | + $result = $this->companytoremove->fetch($idtodelete); // include the fetch of extra fields |
|
297 | + if (!$result) { |
|
298 | 298 | throw new RestException(404, 'Thirdparty not found'); |
299 | 299 | } |
300 | 300 | |
301 | - if( ! DolibarrApi::_checkAccessToResource('societe',$this->companytoremove->id)) { |
|
301 | + if (!DolibarrApi::_checkAccessToResource('societe', $this->companytoremove->id)) { |
|
302 | 302 | throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
303 | 303 | } |
304 | 304 | |
@@ -315,7 +315,7 @@ discard block |
||
315 | 315 | // Recopy some data |
316 | 316 | $object->client = $object->client | $soc_origin->client; |
317 | 317 | $object->fournisseur = $object->fournisseur | $soc_origin->fournisseur; |
318 | - $listofproperties=array( |
|
318 | + $listofproperties = array( |
|
319 | 319 | 'address', 'zip', 'town', 'state_id', 'country_id', 'phone', 'phone_pro', 'fax', 'email', 'skype', 'url', 'barcode', |
320 | 320 | 'idprof1', 'idprof2', 'idprof3', 'idprof4', 'idprof5', 'idprof6', |
321 | 321 | 'tva_intra', 'effectif_id', 'forme_juridique', 'remise_percent', 'remise_supplier_percent', 'mode_reglement_supplier_id', 'cond_reglement_supplier_id', 'name_bis', |
@@ -329,7 +329,7 @@ discard block |
||
329 | 329 | } |
330 | 330 | |
331 | 331 | // Concat some data |
332 | - $listofproperties=array( |
|
332 | + $listofproperties = array( |
|
333 | 333 | 'note_public', 'note_private' |
334 | 334 | ); |
335 | 335 | foreach ($listofproperties as $property) |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | } |
374 | 374 | |
375 | 375 | // Move links |
376 | - if (! $error) |
|
376 | + if (!$error) |
|
377 | 377 | { |
378 | 378 | $objects = array( |
379 | 379 | 'Adherent' => '/adherents/class/adherent.class.php', |
@@ -428,12 +428,12 @@ discard block |
||
428 | 428 | } |
429 | 429 | |
430 | 430 | |
431 | - if (! $error) |
|
431 | + if (!$error) |
|
432 | 432 | { |
433 | - $object->context=array('merge'=>1, 'mergefromid'=>$soc_origin->id); |
|
433 | + $object->context = array('merge'=>1, 'mergefromid'=>$soc_origin->id); |
|
434 | 434 | |
435 | 435 | // Call trigger |
436 | - $result=$object->call_trigger('COMPANY_MODIFY',$user); |
|
436 | + $result = $object->call_trigger('COMPANY_MODIFY', $user); |
|
437 | 437 | if ($result < 0) |
438 | 438 | { |
439 | 439 | //setEventMessages($object->error, $object->errors, 'errors'); |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | // End call triggers |
443 | 443 | } |
444 | 444 | |
445 | - if (! $error) |
|
445 | + if (!$error) |
|
446 | 446 | { |
447 | 447 | //We finally remove the old thirdparty |
448 | 448 | if ($soc_origin->delete($soc_origin->id, $user) < 1) |
@@ -475,14 +475,14 @@ discard block |
||
475 | 475 | */ |
476 | 476 | function delete($id) |
477 | 477 | { |
478 | - if(! DolibarrApiAccess::$user->rights->societe->supprimer) { |
|
478 | + if (!DolibarrApiAccess::$user->rights->societe->supprimer) { |
|
479 | 479 | throw new RestException(401); |
480 | 480 | } |
481 | 481 | $result = $this->company->fetch($id); |
482 | - if( ! $result ) { |
|
482 | + if (!$result) { |
|
483 | 483 | throw new RestException(404, 'Thirdparty not found'); |
484 | 484 | } |
485 | - if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { |
|
485 | + if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) { |
|
486 | 486 | throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
487 | 487 | } |
488 | 488 | return $this->company->delete($id); |
@@ -503,12 +503,12 @@ discard block |
||
503 | 503 | */ |
504 | 504 | function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) |
505 | 505 | { |
506 | - if (! DolibarrApiAccess::$user->rights->categorie->lire) { |
|
506 | + if (!DolibarrApiAccess::$user->rights->categorie->lire) { |
|
507 | 507 | throw new RestException(401); |
508 | 508 | } |
509 | 509 | |
510 | 510 | $result = $this->company->fetch($id); |
511 | - if( ! $result ) |
|
511 | + if (!$result) |
|
512 | 512 | { |
513 | 513 | throw new RestException(404, 'Thirdparty not found'); |
514 | 514 | } |
@@ -542,28 +542,28 @@ discard block |
||
542 | 542 | */ |
543 | 543 | function addCategory($id, $category_id) |
544 | 544 | { |
545 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
545 | + if (!DolibarrApiAccess::$user->rights->societe->creer) { |
|
546 | 546 | throw new RestException(401); |
547 | 547 | } |
548 | 548 | |
549 | 549 | $result = $this->company->fetch($id); |
550 | - if( ! $result ) { |
|
550 | + if (!$result) { |
|
551 | 551 | throw new RestException(404, 'Thirdparty not found'); |
552 | 552 | } |
553 | 553 | $category = new Categorie($this->db); |
554 | 554 | $result = $category->fetch($category_id); |
555 | - if( ! $result ) { |
|
555 | + if (!$result) { |
|
556 | 556 | throw new RestException(404, 'category not found'); |
557 | 557 | } |
558 | 558 | |
559 | - if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { |
|
559 | + if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) { |
|
560 | 560 | throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
561 | 561 | } |
562 | - if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) { |
|
562 | + if (!DolibarrApi::_checkAccessToResource('category', $category->id)) { |
|
563 | 563 | throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
564 | 564 | } |
565 | 565 | |
566 | - $category->add_type($this->company,'customer'); |
|
566 | + $category->add_type($this->company, 'customer'); |
|
567 | 567 | |
568 | 568 | return $this->_cleanObjectDatas($this->company); |
569 | 569 | } |
@@ -580,28 +580,28 @@ discard block |
||
580 | 580 | */ |
581 | 581 | function deleteCategory($id, $category_id) |
582 | 582 | { |
583 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
583 | + if (!DolibarrApiAccess::$user->rights->societe->creer) { |
|
584 | 584 | throw new RestException(401); |
585 | 585 | } |
586 | 586 | |
587 | 587 | $result = $this->company->fetch($id); |
588 | - if( ! $result ) { |
|
588 | + if (!$result) { |
|
589 | 589 | throw new RestException(404, 'Thirdparty not found'); |
590 | 590 | } |
591 | 591 | $category = new Categorie($this->db); |
592 | 592 | $result = $category->fetch($category_id); |
593 | - if( ! $result ) { |
|
593 | + if (!$result) { |
|
594 | 594 | throw new RestException(404, 'category not found'); |
595 | 595 | } |
596 | 596 | |
597 | - if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { |
|
597 | + if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) { |
|
598 | 598 | throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
599 | 599 | } |
600 | - if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) { |
|
600 | + if (!DolibarrApi::_checkAccessToResource('category', $category->id)) { |
|
601 | 601 | throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
602 | 602 | } |
603 | 603 | |
604 | - $category->del_type($this->company,'customer'); |
|
604 | + $category->del_type($this->company, 'customer'); |
|
605 | 605 | |
606 | 606 | return $this->_cleanObjectDatas($this->company); |
607 | 607 | } |
@@ -621,12 +621,12 @@ discard block |
||
621 | 621 | */ |
622 | 622 | function getSupplierCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) |
623 | 623 | { |
624 | - if (! DolibarrApiAccess::$user->rights->categorie->lire) { |
|
624 | + if (!DolibarrApiAccess::$user->rights->categorie->lire) { |
|
625 | 625 | throw new RestException(401); |
626 | 626 | } |
627 | 627 | |
628 | 628 | $result = $this->company->fetch($id); |
629 | - if( ! $result ) |
|
629 | + if (!$result) |
|
630 | 630 | { |
631 | 631 | throw new RestException(404, 'Thirdparty not found'); |
632 | 632 | } |
@@ -660,28 +660,28 @@ discard block |
||
660 | 660 | */ |
661 | 661 | function addSupplierCategory($id, $category_id) |
662 | 662 | { |
663 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
663 | + if (!DolibarrApiAccess::$user->rights->societe->creer) { |
|
664 | 664 | throw new RestException(401); |
665 | 665 | } |
666 | 666 | |
667 | 667 | $result = $this->company->fetch($id); |
668 | - if( ! $result ) { |
|
668 | + if (!$result) { |
|
669 | 669 | throw new RestException(404, 'Thirdparty not found'); |
670 | 670 | } |
671 | 671 | $category = new Categorie($this->db); |
672 | 672 | $result = $category->fetch($category_id); |
673 | - if( ! $result ) { |
|
673 | + if (!$result) { |
|
674 | 674 | throw new RestException(404, 'category not found'); |
675 | 675 | } |
676 | 676 | |
677 | - if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { |
|
677 | + if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) { |
|
678 | 678 | throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
679 | 679 | } |
680 | - if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) { |
|
680 | + if (!DolibarrApi::_checkAccessToResource('category', $category->id)) { |
|
681 | 681 | throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
682 | 682 | } |
683 | 683 | |
684 | - $category->add_type($this->company,'supplier'); |
|
684 | + $category->add_type($this->company, 'supplier'); |
|
685 | 685 | |
686 | 686 | return $this->_cleanObjectDatas($this->company); |
687 | 687 | } |
@@ -698,28 +698,28 @@ discard block |
||
698 | 698 | */ |
699 | 699 | function deleteSupplierCategory($id, $category_id) |
700 | 700 | { |
701 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
701 | + if (!DolibarrApiAccess::$user->rights->societe->creer) { |
|
702 | 702 | throw new RestException(401); |
703 | 703 | } |
704 | 704 | |
705 | 705 | $result = $this->company->fetch($id); |
706 | - if( ! $result ) { |
|
706 | + if (!$result) { |
|
707 | 707 | throw new RestException(404, 'Thirdparty not found'); |
708 | 708 | } |
709 | 709 | $category = new Categorie($this->db); |
710 | 710 | $result = $category->fetch($category_id); |
711 | - if( ! $result ) { |
|
711 | + if (!$result) { |
|
712 | 712 | throw new RestException(404, 'category not found'); |
713 | 713 | } |
714 | 714 | |
715 | - if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { |
|
715 | + if (!DolibarrApi::_checkAccessToResource('societe', $this->company->id)) { |
|
716 | 716 | throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
717 | 717 | } |
718 | - if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) { |
|
718 | + if (!DolibarrApi::_checkAccessToResource('category', $category->id)) { |
|
719 | 719 | throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
720 | 720 | } |
721 | 721 | |
722 | - $category->del_type($this->company,'supplier'); |
|
722 | + $category->del_type($this->company, 'supplier'); |
|
723 | 723 | |
724 | 724 | return $this->_cleanObjectDatas($this->company); |
725 | 725 | } |
@@ -739,24 +739,24 @@ discard block |
||
739 | 739 | * @throws 401 |
740 | 740 | * @throws 404 |
741 | 741 | */ |
742 | - function getOutStandingProposals($id, $mode='customer') |
|
742 | + function getOutStandingProposals($id, $mode = 'customer') |
|
743 | 743 | { |
744 | 744 | $obj_ret = array(); |
745 | 745 | |
746 | - if(! DolibarrApiAccess::$user->rights->societe->lire) { |
|
746 | + if (!DolibarrApiAccess::$user->rights->societe->lire) { |
|
747 | 747 | throw new RestException(401); |
748 | 748 | } |
749 | 749 | |
750 | - if(empty($id)) { |
|
750 | + if (empty($id)) { |
|
751 | 751 | throw new RestException(400, 'Thirdparty ID is mandatory'); |
752 | 752 | } |
753 | 753 | |
754 | - if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { |
|
754 | + if (!DolibarrApi::_checkAccessToResource('societe', $id)) { |
|
755 | 755 | throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
756 | 756 | } |
757 | 757 | |
758 | 758 | $result = $this->company->fetch($id); |
759 | - if( ! $result ) { |
|
759 | + if (!$result) { |
|
760 | 760 | throw new RestException(404, 'Thirdparty not found'); |
761 | 761 | } |
762 | 762 | |
@@ -783,24 +783,24 @@ discard block |
||
783 | 783 | * @throws 401 |
784 | 784 | * @throws 404 |
785 | 785 | */ |
786 | - function getOutStandingOrder($id, $mode='customer') |
|
786 | + function getOutStandingOrder($id, $mode = 'customer') |
|
787 | 787 | { |
788 | 788 | $obj_ret = array(); |
789 | 789 | |
790 | - if(! DolibarrApiAccess::$user->rights->societe->lire) { |
|
790 | + if (!DolibarrApiAccess::$user->rights->societe->lire) { |
|
791 | 791 | throw new RestException(401); |
792 | 792 | } |
793 | 793 | |
794 | - if(empty($id)) { |
|
794 | + if (empty($id)) { |
|
795 | 795 | throw new RestException(400, 'Thirdparty ID is mandatory'); |
796 | 796 | } |
797 | 797 | |
798 | - if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { |
|
798 | + if (!DolibarrApi::_checkAccessToResource('societe', $id)) { |
|
799 | 799 | throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
800 | 800 | } |
801 | 801 | |
802 | 802 | $result = $this->company->fetch($id); |
803 | - if( ! $result ) { |
|
803 | + if (!$result) { |
|
804 | 804 | throw new RestException(404, 'Thirdparty not found'); |
805 | 805 | } |
806 | 806 | |
@@ -826,24 +826,24 @@ discard block |
||
826 | 826 | * @throws 401 |
827 | 827 | * @throws 404 |
828 | 828 | */ |
829 | - function getOutStandingInvoices($id, $mode='customer') |
|
829 | + function getOutStandingInvoices($id, $mode = 'customer') |
|
830 | 830 | { |
831 | 831 | $obj_ret = array(); |
832 | 832 | |
833 | - if(! DolibarrApiAccess::$user->rights->societe->lire) { |
|
833 | + if (!DolibarrApiAccess::$user->rights->societe->lire) { |
|
834 | 834 | throw new RestException(401); |
835 | 835 | } |
836 | 836 | |
837 | - if(empty($id)) { |
|
837 | + if (empty($id)) { |
|
838 | 838 | throw new RestException(400, 'Thirdparty ID is mandatory'); |
839 | 839 | } |
840 | 840 | |
841 | - if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { |
|
841 | + if (!DolibarrApi::_checkAccessToResource('societe', $id)) { |
|
842 | 842 | throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
843 | 843 | } |
844 | 844 | |
845 | 845 | $result = $this->company->fetch($id); |
846 | - if( ! $result ) { |
|
846 | + if (!$result) { |
|
847 | 847 | throw new RestException(404, 'Thirdparty not found'); |
848 | 848 | } |
849 | 849 | |
@@ -872,24 +872,24 @@ discard block |
||
872 | 872 | * @throws 404 |
873 | 873 | * @throws 503 |
874 | 874 | */ |
875 | - function getFixedAmountDiscounts($id, $filter="none", $sortfield = "f.type", $sortorder = 'ASC') |
|
875 | + function getFixedAmountDiscounts($id, $filter = "none", $sortfield = "f.type", $sortorder = 'ASC') |
|
876 | 876 | { |
877 | 877 | $obj_ret = array(); |
878 | 878 | |
879 | - if(! DolibarrApiAccess::$user->rights->societe->lire) { |
|
879 | + if (!DolibarrApiAccess::$user->rights->societe->lire) { |
|
880 | 880 | throw new RestException(401); |
881 | 881 | } |
882 | 882 | |
883 | - if(empty($id)) { |
|
883 | + if (empty($id)) { |
|
884 | 884 | throw new RestException(400, 'Thirdparty ID is mandatory'); |
885 | 885 | } |
886 | 886 | |
887 | - if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { |
|
887 | + if (!DolibarrApi::_checkAccessToResource('societe', $id)) { |
|
888 | 888 | throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
889 | 889 | } |
890 | 890 | |
891 | 891 | $result = $this->company->fetch($id); |
892 | - if( ! $result ) { |
|
892 | + if (!$result) { |
|
893 | 893 | throw new RestException(404, 'Thirdparty not found'); |
894 | 894 | } |
895 | 895 | |
@@ -900,14 +900,14 @@ discard block |
||
900 | 900 | if ($filter == "available") $sql .= " AND re.fk_facture IS NULL AND re.fk_facture_line IS NULL"; |
901 | 901 | if ($filter == "used") $sql .= " AND (re.fk_facture IS NOT NULL OR re.fk_facture_line IS NOT NULL)"; |
902 | 902 | |
903 | - $sql.= $this->db->order($sortfield, $sortorder); |
|
903 | + $sql .= $this->db->order($sortfield, $sortorder); |
|
904 | 904 | |
905 | 905 | $result = $this->db->query($sql); |
906 | - if( ! $result ) { |
|
906 | + if (!$result) { |
|
907 | 907 | throw new RestException(503, $this->db->lasterror()); |
908 | 908 | } else { |
909 | 909 | $num = $this->db->num_rows($result); |
910 | - while ( $obj = $this->db->fetch_object($result) ) { |
|
910 | + while ($obj = $this->db->fetch_object($result)) { |
|
911 | 911 | $obj_ret[] = $obj; |
912 | 912 | } |
913 | 913 | } |
@@ -932,14 +932,14 @@ discard block |
||
932 | 932 | */ |
933 | 933 | function getInvoicesQualifiedForReplacement($id) |
934 | 934 | { |
935 | - if(! DolibarrApiAccess::$user->rights->facture->lire) { |
|
935 | + if (!DolibarrApiAccess::$user->rights->facture->lire) { |
|
936 | 936 | throw new RestException(401); |
937 | 937 | } |
938 | - if(empty($id)) { |
|
938 | + if (empty($id)) { |
|
939 | 939 | throw new RestException(400, 'Thirdparty ID is mandatory'); |
940 | 940 | } |
941 | 941 | |
942 | - if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { |
|
942 | + if (!DolibarrApi::_checkAccessToResource('societe', $id)) { |
|
943 | 943 | throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
944 | 944 | } |
945 | 945 | |
@@ -950,7 +950,7 @@ discard block |
||
950 | 950 | |
951 | 951 | $invoice = new Facture($this->db); |
952 | 952 | $result = $invoice->list_replacable_invoices($id); |
953 | - if( $result < 0) { |
|
953 | + if ($result < 0) { |
|
954 | 954 | throw new RestException(405, $this->thirdparty->error); |
955 | 955 | } |
956 | 956 | |
@@ -974,14 +974,14 @@ discard block |
||
974 | 974 | */ |
975 | 975 | function getInvoicesQualifiedForCreditNote($id) |
976 | 976 | { |
977 | - if(! DolibarrApiAccess::$user->rights->facture->lire) { |
|
977 | + if (!DolibarrApiAccess::$user->rights->facture->lire) { |
|
978 | 978 | throw new RestException(401); |
979 | 979 | } |
980 | - if(empty($id)) { |
|
980 | + if (empty($id)) { |
|
981 | 981 | throw new RestException(400, 'Thirdparty ID is mandatory'); |
982 | 982 | } |
983 | 983 | |
984 | - if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { |
|
984 | + if (!DolibarrApi::_checkAccessToResource('societe', $id)) { |
|
985 | 985 | throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
986 | 986 | } |
987 | 987 | |
@@ -992,7 +992,7 @@ discard block |
||
992 | 992 | |
993 | 993 | $invoice = new Facture($this->db); |
994 | 994 | $result = $invoice->list_qualified_avoir_invoices($id); |
995 | - if( $result < 0) { |
|
995 | + if ($result < 0) { |
|
996 | 996 | throw new RestException(405, $this->thirdparty->error); |
997 | 997 | } |
998 | 998 | |
@@ -1012,14 +1012,14 @@ discard block |
||
1012 | 1012 | { |
1013 | 1013 | global $db, $conf; |
1014 | 1014 | |
1015 | - if(! DolibarrApiAccess::$user->rights->facture->lire) { |
|
1015 | + if (!DolibarrApiAccess::$user->rights->facture->lire) { |
|
1016 | 1016 | throw new RestException(401); |
1017 | 1017 | } |
1018 | - if(empty($id)) { |
|
1018 | + if (empty($id)) { |
|
1019 | 1019 | throw new RestException(400, 'Thirdparty ID is mandatory'); |
1020 | 1020 | } |
1021 | 1021 | |
1022 | - if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { |
|
1022 | + if (!DolibarrApi::_checkAccessToResource('societe', $id)) { |
|
1023 | 1023 | throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
1024 | 1024 | } |
1025 | 1025 | |
@@ -1028,20 +1028,20 @@ discard block |
||
1028 | 1028 | */ |
1029 | 1029 | |
1030 | 1030 | $sql = "SELECT rowid, fk_soc, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,"; |
1031 | - $sql.= " owner_address, default_rib, label, datec, tms as datem, rum, frstrecur"; |
|
1032 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe_rib"; |
|
1033 | - if ($id) $sql.= " WHERE fk_soc = ".$id." "; |
|
1031 | + $sql .= " owner_address, default_rib, label, datec, tms as datem, rum, frstrecur"; |
|
1032 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe_rib"; |
|
1033 | + if ($id) $sql .= " WHERE fk_soc = ".$id." "; |
|
1034 | 1034 | |
1035 | 1035 | |
1036 | 1036 | $result = $db->query($sql); |
1037 | 1037 | |
1038 | - if($result->num_rows == 0 ){ |
|
1038 | + if ($result->num_rows == 0) { |
|
1039 | 1039 | throw new RestException(404, 'Account not found'); |
1040 | 1040 | } |
1041 | 1041 | |
1042 | - $i=0; |
|
1042 | + $i = 0; |
|
1043 | 1043 | |
1044 | - $accounts =[]; |
|
1044 | + $accounts = []; |
|
1045 | 1045 | |
1046 | 1046 | if ($result) |
1047 | 1047 | { |
@@ -1050,13 +1050,13 @@ discard block |
||
1050 | 1050 | { |
1051 | 1051 | $obj = $db->fetch_object($result); |
1052 | 1052 | $account = new CompanyBankAccount($db); |
1053 | - if($account->fetch($obj->rowid)) { |
|
1053 | + if ($account->fetch($obj->rowid)) { |
|
1054 | 1054 | $accounts[] = $account; |
1055 | 1055 | } |
1056 | 1056 | $i++; |
1057 | 1057 | } |
1058 | 1058 | } |
1059 | - else{ |
|
1059 | + else { |
|
1060 | 1060 | throw new RestException(404, 'Account not found'); |
1061 | 1061 | } |
1062 | 1062 | |
@@ -1065,10 +1065,10 @@ discard block |
||
1065 | 1065 | |
1066 | 1066 | $returnAccounts = []; |
1067 | 1067 | |
1068 | - foreach($accounts as $account){ |
|
1069 | - $object= []; |
|
1070 | - foreach($account as $key => $value) |
|
1071 | - if(in_array($key, $fields)){ |
|
1068 | + foreach ($accounts as $account) { |
|
1069 | + $object = []; |
|
1070 | + foreach ($account as $key => $value) |
|
1071 | + if (in_array($key, $fields)) { |
|
1072 | 1072 | $object[$key] = $value; |
1073 | 1073 | } |
1074 | 1074 | $returnAccounts[] = $object; |
@@ -1088,7 +1088,7 @@ discard block |
||
1088 | 1088 | */ |
1089 | 1089 | function createCompanyBankAccount($id, $request_data = null) |
1090 | 1090 | { |
1091 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
1091 | + if (!DolibarrApiAccess::$user->rights->societe->creer) { |
|
1092 | 1092 | throw new RestException(401); |
1093 | 1093 | } |
1094 | 1094 | |
@@ -1096,7 +1096,7 @@ discard block |
||
1096 | 1096 | |
1097 | 1097 | $account->socid = $id; |
1098 | 1098 | |
1099 | - foreach($request_data as $field => $value) { |
|
1099 | + foreach ($request_data as $field => $value) { |
|
1100 | 1100 | $account->$field = $value; |
1101 | 1101 | } |
1102 | 1102 | |
@@ -1123,7 +1123,7 @@ discard block |
||
1123 | 1123 | */ |
1124 | 1124 | function updateCompanyBankAccount($id, $bankaccount_id, $request_data = null) |
1125 | 1125 | { |
1126 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
1126 | + if (!DolibarrApiAccess::$user->rights->societe->creer) { |
|
1127 | 1127 | throw new RestException(401); |
1128 | 1128 | } |
1129 | 1129 | |
@@ -1131,12 +1131,12 @@ discard block |
||
1131 | 1131 | |
1132 | 1132 | $account->fetch($bankaccount_id, $id, -1, ''); |
1133 | 1133 | |
1134 | - if($account->socid != $id){ |
|
1134 | + if ($account->socid != $id) { |
|
1135 | 1135 | throw new RestException(401); |
1136 | 1136 | } |
1137 | 1137 | |
1138 | 1138 | |
1139 | - foreach($request_data as $field => $value) { |
|
1139 | + foreach ($request_data as $field => $value) { |
|
1140 | 1140 | $account->$field = $value; |
1141 | 1141 | } |
1142 | 1142 | |
@@ -1158,7 +1158,7 @@ discard block |
||
1158 | 1158 | */ |
1159 | 1159 | function deleteCompanyBankAccount($id, $bankaccount_id) |
1160 | 1160 | { |
1161 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
1161 | + if (!DolibarrApiAccess::$user->rights->societe->creer) { |
|
1162 | 1162 | throw new RestException(401); |
1163 | 1163 | } |
1164 | 1164 | |
@@ -1166,7 +1166,7 @@ discard block |
||
1166 | 1166 | |
1167 | 1167 | $account->fetch($bankaccount_id); |
1168 | 1168 | |
1169 | - if(!$account->socid == $id) |
|
1169 | + if (!$account->socid == $id) |
|
1170 | 1170 | throw new RestException(401); |
1171 | 1171 | |
1172 | 1172 | return $account->delete(DolibarrApiAccess::$user); |
@@ -1186,12 +1186,12 @@ discard block |
||
1186 | 1186 | { |
1187 | 1187 | global $conf; |
1188 | 1188 | |
1189 | - $this->langs->loadLangs(array("main","dict","commercial","products","companies","banks","bills","withdrawals")); |
|
1189 | + $this->langs->loadLangs(array("main", "dict", "commercial", "products", "companies", "banks", "bills", "withdrawals")); |
|
1190 | 1190 | |
1191 | 1191 | $this->company->fetch($id); |
1192 | 1192 | |
1193 | 1193 | $action = 'builddoc'; |
1194 | - if(! DolibarrApiAccess::$user->rights->societe->creer) |
|
1194 | + if (!DolibarrApiAccess::$user->rights->societe->creer) |
|
1195 | 1195 | throw new RestException(401); |
1196 | 1196 | |
1197 | 1197 | $this->company->setDocModel(DolibarrApiAccess::$user, $model); |
@@ -1199,32 +1199,32 @@ discard block |
||
1199 | 1199 | $this->company->fk_bank = $this->company->fk_account; |
1200 | 1200 | |
1201 | 1201 | $outputlangs = $this->langs; |
1202 | - $newlang=''; |
|
1202 | + $newlang = ''; |
|
1203 | 1203 | |
1204 | - if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09'); |
|
1205 | - if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->thirdparty->default_lang)) $newlang=$this->company->thirdparty->default_lang; // for proposal, order, invoice, ... |
|
1206 | - if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->default_lang)) $newlang=$this->company->default_lang; // for thirdparty |
|
1207 | - if (! empty($newlang)) { |
|
1208 | - $outputlangs = new Translate("",$conf); |
|
1204 | + if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); |
|
1205 | + if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->thirdparty->default_lang)) $newlang = $this->company->thirdparty->default_lang; // for proposal, order, invoice, ... |
|
1206 | + if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->default_lang)) $newlang = $this->company->default_lang; // for thirdparty |
|
1207 | + if (!empty($newlang)) { |
|
1208 | + $outputlangs = new Translate("", $conf); |
|
1209 | 1209 | $outputlangs->setDefaultLang($newlang); |
1210 | 1210 | } |
1211 | 1211 | |
1212 | 1212 | // To be sure vars is defined |
1213 | 1213 | $hidedetails = $hidedesc = $hideref = 0; |
1214 | - $moreparams=null; |
|
1215 | - if (empty($hidedetails)) $hidedetails=0; |
|
1216 | - if (empty($hidedesc)) $hidedesc=0; |
|
1217 | - if (empty($hideref)) $hideref=0; |
|
1218 | - if (empty($moreparams)) $moreparams=null; |
|
1214 | + $moreparams = null; |
|
1215 | + if (empty($hidedetails)) $hidedetails = 0; |
|
1216 | + if (empty($hidedesc)) $hidedesc = 0; |
|
1217 | + if (empty($hideref)) $hideref = 0; |
|
1218 | + if (empty($moreparams)) $moreparams = null; |
|
1219 | 1219 | |
1220 | 1220 | |
1221 | 1221 | $sql = "SELECT rowid"; |
1222 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe_rib"; |
|
1223 | - if ($id) $sql.= " WHERE fk_soc = ".$id." "; |
|
1224 | - if ($companybankid) $sql.= " AND id = ".$companybankid.""; |
|
1222 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe_rib"; |
|
1223 | + if ($id) $sql .= " WHERE fk_soc = ".$id." "; |
|
1224 | + if ($companybankid) $sql .= " AND id = ".$companybankid.""; |
|
1225 | 1225 | |
1226 | - $i=0; |
|
1227 | - $accounts=array(); |
|
1226 | + $i = 0; |
|
1227 | + $accounts = array(); |
|
1228 | 1228 | |
1229 | 1229 | $result = $this->db->query($sql); |
1230 | 1230 | if ($result) |
@@ -1281,15 +1281,15 @@ discard block |
||
1281 | 1281 | * |
1282 | 1282 | * @url GET {id}/gateways/ |
1283 | 1283 | */ |
1284 | - function getSocieteAccounts($id, $site=null) |
|
1284 | + function getSocieteAccounts($id, $site = null) |
|
1285 | 1285 | { |
1286 | 1286 | global $db, $conf; |
1287 | 1287 | |
1288 | - if(!DolibarrApiAccess::$user->rights->societe->lire) { |
|
1288 | + if (!DolibarrApiAccess::$user->rights->societe->lire) { |
|
1289 | 1289 | throw new RestException(401); |
1290 | 1290 | } |
1291 | 1291 | |
1292 | - if(!DolibarrApi::_checkAccessToResource('societe',$id)) { |
|
1292 | + if (!DolibarrApi::_checkAccessToResource('societe', $id)) { |
|
1293 | 1293 | throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); |
1294 | 1294 | } |
1295 | 1295 | |
@@ -1297,18 +1297,18 @@ discard block |
||
1297 | 1297 | * We select all the records that match the socid |
1298 | 1298 | */ |
1299 | 1299 | $sql = "SELECT rowid, fk_soc, key_account, site, date_creation, tms FROM ".MAIN_DB_PREFIX."societe_account"; |
1300 | - $sql.= " WHERE fk_soc = $id"; |
|
1301 | - if($site) $sql .= " AND site ='$site'"; |
|
1300 | + $sql .= " WHERE fk_soc = $id"; |
|
1301 | + if ($site) $sql .= " AND site ='$site'"; |
|
1302 | 1302 | |
1303 | 1303 | $result = $db->query($sql); |
1304 | 1304 | |
1305 | - if($result->num_rows == 0){ |
|
1305 | + if ($result->num_rows == 0) { |
|
1306 | 1306 | throw new RestException(404, 'This thirdparty does not have any gateway attached or does not exist.'); |
1307 | 1307 | } |
1308 | 1308 | |
1309 | - $i=0; |
|
1309 | + $i = 0; |
|
1310 | 1310 | |
1311 | - $accounts =[]; |
|
1311 | + $accounts = []; |
|
1312 | 1312 | |
1313 | 1313 | $num = $db->num_rows($result); |
1314 | 1314 | while ($i < $num) |
@@ -1316,7 +1316,7 @@ discard block |
||
1316 | 1316 | $obj = $db->fetch_object($result); |
1317 | 1317 | $account = new SocieteAccount($db); |
1318 | 1318 | |
1319 | - if($account->fetch($obj->rowid)) { |
|
1319 | + if ($account->fetch($obj->rowid)) { |
|
1320 | 1320 | $accounts[] = $account; |
1321 | 1321 | } |
1322 | 1322 | $i++; |
@@ -1326,10 +1326,10 @@ discard block |
||
1326 | 1326 | |
1327 | 1327 | $returnAccounts = []; |
1328 | 1328 | |
1329 | - foreach($accounts as $account){ |
|
1330 | - $object= []; |
|
1331 | - foreach($account as $key => $value) |
|
1332 | - if(in_array($key, $fields)){ |
|
1329 | + foreach ($accounts as $account) { |
|
1330 | + $object = []; |
|
1331 | + foreach ($account as $key => $value) |
|
1332 | + if (in_array($key, $fields)) { |
|
1333 | 1333 | $object[$key] = $value; |
1334 | 1334 | } |
1335 | 1335 | $returnAccounts[] = $object; |
@@ -1361,25 +1361,25 @@ discard block |
||
1361 | 1361 | { |
1362 | 1362 | global $db; |
1363 | 1363 | |
1364 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
1364 | + if (!DolibarrApiAccess::$user->rights->societe->creer) { |
|
1365 | 1365 | throw new RestException(401); |
1366 | 1366 | } |
1367 | 1367 | |
1368 | - if(!isset($request_data['site'])) { |
|
1368 | + if (!isset($request_data['site'])) { |
|
1369 | 1369 | throw new RestException(422, 'Unprocessable Entity: You must pass the site attribute in your request data !'); |
1370 | 1370 | } |
1371 | 1371 | |
1372 | - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".$id." AND site = '". $request_data['site']."' "; |
|
1372 | + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".$id." AND site = '".$request_data['site']."' "; |
|
1373 | 1373 | $result = $db->query($sql); |
1374 | 1374 | |
1375 | - if($result->num_rows == 0 ){ |
|
1375 | + if ($result->num_rows == 0) { |
|
1376 | 1376 | $account = new SocieteAccount($this->db); |
1377 | - if(!isset($request_data['login'])) { |
|
1377 | + if (!isset($request_data['login'])) { |
|
1378 | 1378 | $account->login = ""; |
1379 | 1379 | } |
1380 | 1380 | $account->fk_soc = $id; |
1381 | 1381 | |
1382 | - foreach($request_data as $field => $value) { |
|
1382 | + foreach ($request_data as $field => $value) { |
|
1383 | 1383 | $account->$field = $value; |
1384 | 1384 | } |
1385 | 1385 | |
@@ -1420,7 +1420,7 @@ discard block |
||
1420 | 1420 | { |
1421 | 1421 | global $db; |
1422 | 1422 | |
1423 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
1423 | + if (!DolibarrApiAccess::$user->rights->societe->creer) { |
|
1424 | 1424 | throw new RestException(401); |
1425 | 1425 | } |
1426 | 1426 | |
@@ -1428,16 +1428,16 @@ discard block |
||
1428 | 1428 | $result = $db->query($sql); |
1429 | 1429 | |
1430 | 1430 | // We do not found an existing SocieteAccount entity for this fk_soc and site ; we then create a new one. |
1431 | - if($result->num_rows == 0 ){ |
|
1432 | - if(!isset($request_data['key_account'])) { |
|
1431 | + if ($result->num_rows == 0) { |
|
1432 | + if (!isset($request_data['key_account'])) { |
|
1433 | 1433 | throw new RestException(422, 'Unprocessable Entity: You must pass the key_account attribute in your request data !'); |
1434 | 1434 | } |
1435 | 1435 | $account = new SocieteAccount($this->db); |
1436 | - if(!isset($request_data['login'])) { |
|
1436 | + if (!isset($request_data['login'])) { |
|
1437 | 1437 | $account->login = ""; |
1438 | 1438 | } |
1439 | 1439 | |
1440 | - foreach($request_data as $field => $value) { |
|
1440 | + foreach ($request_data as $field => $value) { |
|
1441 | 1441 | $account->$field = $value; |
1442 | 1442 | } |
1443 | 1443 | |
@@ -1449,12 +1449,12 @@ discard block |
||
1449 | 1449 | // We found an existing SocieteAccount entity, we are replacing it |
1450 | 1450 | } else { |
1451 | 1451 | |
1452 | - if(isset($request_data['site']) && $request_data['site'] !== $site) { |
|
1453 | - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".$id." AND site = '". $request_data['site']."' "; |
|
1452 | + if (isset($request_data['site']) && $request_data['site'] !== $site) { |
|
1453 | + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".$id." AND site = '".$request_data['site']."' "; |
|
1454 | 1454 | $result = $db->query($sql); |
1455 | 1455 | |
1456 | - if($result->num_rows !== 0) |
|
1457 | - throw new RestException(409, "You are trying to update this thirdparty SocieteAccount (gateway record) from $site to ".$request_data['site'] . " but another SocieteAccount entity already exists with this site key."); |
|
1456 | + if ($result->num_rows !== 0) |
|
1457 | + throw new RestException(409, "You are trying to update this thirdparty SocieteAccount (gateway record) from $site to ".$request_data['site']." but another SocieteAccount entity already exists with this site key."); |
|
1458 | 1458 | } |
1459 | 1459 | |
1460 | 1460 | $obj = $db->fetch_object($result); |
@@ -1463,13 +1463,13 @@ discard block |
||
1463 | 1463 | $account->id = $obj->rowid; |
1464 | 1464 | $account->fk_soc = $id; |
1465 | 1465 | $account->site = $site; |
1466 | - if(!isset($request_data['login'])) { |
|
1466 | + if (!isset($request_data['login'])) { |
|
1467 | 1467 | $account->login = ""; |
1468 | 1468 | } |
1469 | 1469 | $account->fk_user_creat = $obj->fk_user_creat; |
1470 | 1470 | $account->date_creation = $obj->date_creation; |
1471 | 1471 | |
1472 | - foreach($request_data as $field => $value) { |
|
1472 | + foreach ($request_data as $field => $value) { |
|
1473 | 1473 | $account->$field = $value; |
1474 | 1474 | } |
1475 | 1475 | |
@@ -1501,31 +1501,31 @@ discard block |
||
1501 | 1501 | { |
1502 | 1502 | global $db; |
1503 | 1503 | |
1504 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
1504 | + if (!DolibarrApiAccess::$user->rights->societe->creer) { |
|
1505 | 1505 | throw new RestException(401); |
1506 | 1506 | } |
1507 | 1507 | |
1508 | 1508 | $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = $id AND site = '$site' "; |
1509 | 1509 | $result = $db->query($sql); |
1510 | 1510 | |
1511 | - if($result->num_rows == 0 ){ |
|
1511 | + if ($result->num_rows == 0) { |
|
1512 | 1512 | throw new RestException(404, "This thirdparty does not have $site gateway attached or does not exist."); |
1513 | 1513 | } else { |
1514 | 1514 | |
1515 | 1515 | // If the user tries to edit the site member, we check first if |
1516 | - if(isset($request_data['site']) && $request_data['site'] !== $site) { |
|
1517 | - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".$id." AND site = '". $request_data['site']."' "; |
|
1516 | + if (isset($request_data['site']) && $request_data['site'] !== $site) { |
|
1517 | + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".$id." AND site = '".$request_data['site']."' "; |
|
1518 | 1518 | $result = $db->query($sql); |
1519 | 1519 | |
1520 | - if($result->num_rows !== 0) |
|
1521 | - throw new RestException(409, "You are trying to update this thirdparty SocieteAccount (gateway record) site member from $site to ".$request_data['site'] . " but another SocieteAccount entity already exists for this thirdparty with this site key."); |
|
1520 | + if ($result->num_rows !== 0) |
|
1521 | + throw new RestException(409, "You are trying to update this thirdparty SocieteAccount (gateway record) site member from $site to ".$request_data['site']." but another SocieteAccount entity already exists for this thirdparty with this site key."); |
|
1522 | 1522 | } |
1523 | 1523 | |
1524 | 1524 | $obj = $db->fetch_object($result); |
1525 | 1525 | $account = new SocieteAccount($this->db); |
1526 | 1526 | $account->fetch($obj->rowid); |
1527 | 1527 | |
1528 | - foreach($request_data as $field => $value) { |
|
1528 | + foreach ($request_data as $field => $value) { |
|
1529 | 1529 | $account->$field = $value; |
1530 | 1530 | } |
1531 | 1531 | |
@@ -1556,21 +1556,21 @@ discard block |
||
1556 | 1556 | global /** @var Database $db */ |
1557 | 1557 | $db; |
1558 | 1558 | |
1559 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
1559 | + if (!DolibarrApiAccess::$user->rights->societe->creer) { |
|
1560 | 1560 | throw new RestException(401); |
1561 | 1561 | } |
1562 | 1562 | |
1563 | 1563 | $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = $id AND site = '$site' "; |
1564 | 1564 | $result = $db->query($sql); |
1565 | 1565 | |
1566 | - if($result->num_rows == 0 ){ |
|
1566 | + if ($result->num_rows == 0) { |
|
1567 | 1567 | throw new RestException(404); |
1568 | 1568 | } else { |
1569 | 1569 | $obj = $db->fetch_object($result); |
1570 | 1570 | $account = new SocieteAccount($this->db); |
1571 | 1571 | $account->fetch($obj->rowid); |
1572 | 1572 | |
1573 | - if($account->delete(DolibarrApiAccess::$user) < 0) { |
|
1573 | + if ($account->delete(DolibarrApiAccess::$user) < 0) { |
|
1574 | 1574 | throw new RestException(500, "Error while deleting $site gateway attached to this third party"); |
1575 | 1575 | } |
1576 | 1576 | } |
@@ -1593,7 +1593,7 @@ discard block |
||
1593 | 1593 | global /** @var Database $db */ |
1594 | 1594 | $db; |
1595 | 1595 | |
1596 | - if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
1596 | + if (!DolibarrApiAccess::$user->rights->societe->creer) { |
|
1597 | 1597 | throw new RestException(401); |
1598 | 1598 | } |
1599 | 1599 | |
@@ -1602,14 +1602,14 @@ discard block |
||
1602 | 1602 | */ |
1603 | 1603 | |
1604 | 1604 | $sql = "SELECT rowid, fk_soc, key_account, site, date_creation, tms"; |
1605 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = $id "; |
|
1605 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = $id "; |
|
1606 | 1606 | |
1607 | 1607 | $result = $db->query($sql); |
1608 | 1608 | |
1609 | - if($result->num_rows == 0 ){ |
|
1609 | + if ($result->num_rows == 0) { |
|
1610 | 1610 | throw new RestException(404, 'This third party does not have any gateway attached or does not exist.'); |
1611 | 1611 | } else { |
1612 | - $i=0; |
|
1612 | + $i = 0; |
|
1613 | 1613 | |
1614 | 1614 | $num = $db->num_rows($result); |
1615 | 1615 | while ($i < $num) |
@@ -1618,7 +1618,7 @@ discard block |
||
1618 | 1618 | $account = new SocieteAccount($db); |
1619 | 1619 | $account->fetch($obj->rowid); |
1620 | 1620 | |
1621 | - if($account->delete(DolibarrApiAccess::$user) < 0) { |
|
1621 | + if ($account->delete(DolibarrApiAccess::$user) < 0) { |
|
1622 | 1622 | throw new RestException(500, 'Error while deleting gateways attached to this third party'); |
1623 | 1623 | } |
1624 | 1624 | $i++; |
@@ -1636,7 +1636,7 @@ discard block |
||
1636 | 1636 | { |
1637 | 1637 | $object = parent::_cleanObjectDatas($object); |
1638 | 1638 | |
1639 | - unset($object->nom); // ->name already defined and nom deprecated |
|
1639 | + unset($object->nom); // ->name already defined and nom deprecated |
|
1640 | 1640 | |
1641 | 1641 | unset($object->total_ht); |
1642 | 1642 | unset($object->total_tva); |
@@ -128,23 +128,44 @@ discard block |
||
128 | 128 | |
129 | 129 | // If the internal user must only see his customers, force searching by him |
130 | 130 | $search_sale = 0; |
131 | - if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id; |
|
131 | + if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) { |
|
132 | + $search_sale = DolibarrApiAccess::$user->id; |
|
133 | + } |
|
132 | 134 | |
133 | 135 | $sql = "SELECT t.rowid"; |
134 | - if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) |
|
136 | + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) { |
|
137 | + $sql .= ", sc.fk_soc, sc.fk_user"; |
|
138 | + } |
|
139 | + // We need these fields in order to filter by sale (including the case where the user can only see his prospects) |
|
135 | 140 | $sql.= " FROM ".MAIN_DB_PREFIX."societe as t"; |
136 | 141 | |
137 | - if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale |
|
142 | + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) { |
|
143 | + $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; |
|
144 | + } |
|
145 | + // We need this table joined to the select in order to filter by sale |
|
138 | 146 | $sql.= ", ".MAIN_DB_PREFIX."c_stcomm as st"; |
139 | 147 | $sql.= " WHERE t.fk_stcomm = st.id"; |
140 | - if ($mode == 1) $sql.= " AND t.client IN (1, 3)"; |
|
141 | - if ($mode == 2) $sql.= " AND t.client IN (2, 3)"; |
|
142 | - if ($mode == 3) $sql.= " AND t.client IN (0)"; |
|
148 | + if ($mode == 1) { |
|
149 | + $sql.= " AND t.client IN (1, 3)"; |
|
150 | + } |
|
151 | + if ($mode == 2) { |
|
152 | + $sql.= " AND t.client IN (2, 3)"; |
|
153 | + } |
|
154 | + if ($mode == 3) { |
|
155 | + $sql.= " AND t.client IN (0)"; |
|
156 | + } |
|
143 | 157 | $sql.= ' AND t.entity IN ('.getEntity('societe').')'; |
144 | - if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc"; |
|
158 | + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) { |
|
159 | + $sql.= " AND t.rowid = sc.fk_soc"; |
|
160 | + } |
|
145 | 161 | //if ($email != NULL) $sql.= " AND s.email = \"".$email."\""; |
146 | - if ($socid) $sql.= " AND t.rowid IN (".$socids.")"; |
|
147 | - if ($search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale |
|
162 | + if ($socid) { |
|
163 | + $sql.= " AND t.rowid IN (".$socids.")"; |
|
164 | + } |
|
165 | + if ($search_sale > 0) { |
|
166 | + $sql.= " AND t.rowid = sc.fk_soc"; |
|
167 | + } |
|
168 | + // Join for the needed table to filter by sale |
|
148 | 169 | // Insert sale filter |
149 | 170 | if ($search_sale > 0) |
150 | 171 | { |
@@ -187,8 +208,7 @@ discard block |
||
187 | 208 | } |
188 | 209 | $i++; |
189 | 210 | } |
190 | - } |
|
191 | - else { |
|
211 | + } else { |
|
192 | 212 | throw new RestException(503, 'Error when retrieve thirdparties : '.$db->lasterror()); |
193 | 213 | } |
194 | 214 | if( ! count($obj_ret)) { |
@@ -214,8 +234,9 @@ discard block |
||
214 | 234 | foreach($request_data as $field => $value) { |
215 | 235 | $this->company->$field = $value; |
216 | 236 | } |
217 | - if ($this->company->create(DolibarrApiAccess::$user) < 0) |
|
218 | - throw new RestException(500, 'Error creating thirdparty', array_merge(array($this->company->error), $this->company->errors)); |
|
237 | + if ($this->company->create(DolibarrApiAccess::$user) < 0) { |
|
238 | + throw new RestException(500, 'Error creating thirdparty', array_merge(array($this->company->error), $this->company->errors)); |
|
239 | + } |
|
219 | 240 | |
220 | 241 | return $this->company->id; |
221 | 242 | } |
@@ -243,12 +264,15 @@ discard block |
||
243 | 264 | } |
244 | 265 | |
245 | 266 | foreach($request_data as $field => $value) { |
246 | - if ($field == 'id') continue; |
|
267 | + if ($field == 'id') { |
|
268 | + continue; |
|
269 | + } |
|
247 | 270 | $this->company->$field = $value; |
248 | 271 | } |
249 | 272 | |
250 | - if($this->company->update($id, DolibarrApiAccess::$user,1,'','','update')) |
|
251 | - return $this->get($id); |
|
273 | + if($this->company->update($id, DolibarrApiAccess::$user,1,'','','update')) { |
|
274 | + return $this->get($id); |
|
275 | + } |
|
252 | 276 | |
253 | 277 | return false; |
254 | 278 | } |
@@ -325,7 +349,9 @@ discard block |
||
325 | 349 | ); |
326 | 350 | foreach ($listofproperties as $property) |
327 | 351 | { |
328 | - if (empty($object->$property)) $object->$property = $soc_origin->$property; |
|
352 | + if (empty($object->$property)) { |
|
353 | + $object->$property = $soc_origin->$property; |
|
354 | + } |
|
329 | 355 | } |
330 | 356 | |
331 | 357 | // Concat some data |
@@ -342,7 +368,9 @@ discard block |
||
342 | 368 | { |
343 | 369 | foreach ($soc_origin->array_options as $key => $val) |
344 | 370 | { |
345 | - if (empty($object->array_options[$key])) $object->array_options[$key] = $val; |
|
371 | + if (empty($object->array_options[$key])) { |
|
372 | + $object->array_options[$key] = $val; |
|
373 | + } |
|
346 | 374 | } |
347 | 375 | } |
348 | 376 | |
@@ -458,8 +486,7 @@ discard block |
||
458 | 486 | $db->rollback(); |
459 | 487 | |
460 | 488 | throw new RestException(500, 'Error failed to merged thirdparty '.$this->companytoremove->id.' into '.$id.'. Enable and read log file for more information.'); |
461 | - } |
|
462 | - else |
|
489 | + } else |
|
463 | 490 | { |
464 | 491 | $db->commit(); |
465 | 492 | } |
@@ -522,10 +549,12 @@ discard block |
||
522 | 549 | throw new RestException(503, 'Error when retrieve category list : '.$categories->error); |
523 | 550 | } |
524 | 551 | |
525 | - if (is_numeric($result) && $result == 0) // To fix a return of 0 instead of empty array of method getListForItem |
|
552 | + if (is_numeric($result) && $result == 0) { |
|
553 | + // To fix a return of 0 instead of empty array of method getListForItem |
|
526 | 554 | { |
527 | 555 | return array(); |
528 | 556 | } |
557 | + } |
|
529 | 558 | |
530 | 559 | return $result; |
531 | 560 | } |
@@ -640,10 +669,12 @@ discard block |
||
640 | 669 | throw new RestException(503, 'Error when retrieve category list : '.$categories->error); |
641 | 670 | } |
642 | 671 | |
643 | - if (is_numeric($result) && $result == 0) // To fix a return of 0 instead of empty array of method getListForItem |
|
672 | + if (is_numeric($result) && $result == 0) { |
|
673 | + // To fix a return of 0 instead of empty array of method getListForItem |
|
644 | 674 | { |
645 | 675 | return array(); |
646 | 676 | } |
677 | + } |
|
647 | 678 | |
648 | 679 | return $result; |
649 | 680 | } |
@@ -897,8 +928,12 @@ discard block |
||
897 | 928 | $sql = "SELECT f.ref, f.type as factype, re.fk_facture_source, re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc, re.description, re.fk_facture, re.fk_facture_line"; |
898 | 929 | $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f"; |
899 | 930 | $sql .= " WHERE f.rowid = re.fk_facture_source AND re.fk_soc = ".$id; |
900 | - if ($filter == "available") $sql .= " AND re.fk_facture IS NULL AND re.fk_facture_line IS NULL"; |
|
901 | - if ($filter == "used") $sql .= " AND (re.fk_facture IS NOT NULL OR re.fk_facture_line IS NOT NULL)"; |
|
931 | + if ($filter == "available") { |
|
932 | + $sql .= " AND re.fk_facture IS NULL AND re.fk_facture_line IS NULL"; |
|
933 | + } |
|
934 | + if ($filter == "used") { |
|
935 | + $sql .= " AND (re.fk_facture IS NOT NULL OR re.fk_facture_line IS NOT NULL)"; |
|
936 | + } |
|
902 | 937 | |
903 | 938 | $sql.= $this->db->order($sortfield, $sortorder); |
904 | 939 | |
@@ -1030,7 +1065,9 @@ discard block |
||
1030 | 1065 | $sql = "SELECT rowid, fk_soc, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,"; |
1031 | 1066 | $sql.= " owner_address, default_rib, label, datec, tms as datem, rum, frstrecur"; |
1032 | 1067 | $sql.= " FROM ".MAIN_DB_PREFIX."societe_rib"; |
1033 | - if ($id) $sql.= " WHERE fk_soc = ".$id." "; |
|
1068 | + if ($id) { |
|
1069 | + $sql.= " WHERE fk_soc = ".$id." "; |
|
1070 | + } |
|
1034 | 1071 | |
1035 | 1072 | |
1036 | 1073 | $result = $db->query($sql); |
@@ -1055,8 +1092,7 @@ discard block |
||
1055 | 1092 | } |
1056 | 1093 | $i++; |
1057 | 1094 | } |
1058 | - } |
|
1059 | - else{ |
|
1095 | + } else{ |
|
1060 | 1096 | throw new RestException(404, 'Account not found'); |
1061 | 1097 | } |
1062 | 1098 | |
@@ -1067,9 +1103,10 @@ discard block |
||
1067 | 1103 | |
1068 | 1104 | foreach($accounts as $account){ |
1069 | 1105 | $object= []; |
1070 | - foreach($account as $key => $value) |
|
1071 | - if(in_array($key, $fields)){ |
|
1106 | + foreach($account as $key => $value) { |
|
1107 | + if(in_array($key, $fields)){ |
|
1072 | 1108 | $object[$key] = $value; |
1109 | + } |
|
1073 | 1110 | } |
1074 | 1111 | $returnAccounts[] = $object; |
1075 | 1112 | } |
@@ -1100,12 +1137,14 @@ discard block |
||
1100 | 1137 | $account->$field = $value; |
1101 | 1138 | } |
1102 | 1139 | |
1103 | - if ($account->create(DolibarrApiAccess::$user) < 0) |
|
1104 | - throw new RestException(500, 'Error creating Company Bank account'); |
|
1140 | + if ($account->create(DolibarrApiAccess::$user) < 0) { |
|
1141 | + throw new RestException(500, 'Error creating Company Bank account'); |
|
1142 | + } |
|
1105 | 1143 | |
1106 | 1144 | |
1107 | - if ($account->update(DolibarrApiAccess::$user) < 0) |
|
1108 | - throw new RestException(500, 'Error updating values'); |
|
1145 | + if ($account->update(DolibarrApiAccess::$user) < 0) { |
|
1146 | + throw new RestException(500, 'Error updating values'); |
|
1147 | + } |
|
1109 | 1148 | |
1110 | 1149 | return $account; |
1111 | 1150 | } |
@@ -1140,8 +1179,9 @@ discard block |
||
1140 | 1179 | $account->$field = $value; |
1141 | 1180 | } |
1142 | 1181 | |
1143 | - if ($account->update(DolibarrApiAccess::$user) < 0) |
|
1144 | - throw new RestException(500, 'Error updating values'); |
|
1182 | + if ($account->update(DolibarrApiAccess::$user) < 0) { |
|
1183 | + throw new RestException(500, 'Error updating values'); |
|
1184 | + } |
|
1145 | 1185 | |
1146 | 1186 | return $account; |
1147 | 1187 | } |
@@ -1166,8 +1206,9 @@ discard block |
||
1166 | 1206 | |
1167 | 1207 | $account->fetch($bankaccount_id); |
1168 | 1208 | |
1169 | - if(!$account->socid == $id) |
|
1170 | - throw new RestException(401); |
|
1209 | + if(!$account->socid == $id) { |
|
1210 | + throw new RestException(401); |
|
1211 | + } |
|
1171 | 1212 | |
1172 | 1213 | return $account->delete(DolibarrApiAccess::$user); |
1173 | 1214 | } |
@@ -1191,8 +1232,9 @@ discard block |
||
1191 | 1232 | $this->company->fetch($id); |
1192 | 1233 | |
1193 | 1234 | $action = 'builddoc'; |
1194 | - if(! DolibarrApiAccess::$user->rights->societe->creer) |
|
1195 | - throw new RestException(401); |
|
1235 | + if(! DolibarrApiAccess::$user->rights->societe->creer) { |
|
1236 | + throw new RestException(401); |
|
1237 | + } |
|
1196 | 1238 | |
1197 | 1239 | $this->company->setDocModel(DolibarrApiAccess::$user, $model); |
1198 | 1240 | |
@@ -1201,9 +1243,17 @@ discard block |
||
1201 | 1243 | $outputlangs = $this->langs; |
1202 | 1244 | $newlang=''; |
1203 | 1245 | |
1204 | - if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09'); |
|
1205 | - if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->thirdparty->default_lang)) $newlang=$this->company->thirdparty->default_lang; // for proposal, order, invoice, ... |
|
1206 | - if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->default_lang)) $newlang=$this->company->default_lang; // for thirdparty |
|
1246 | + if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id','aZ09')) { |
|
1247 | + $newlang=GETPOST('lang_id','aZ09'); |
|
1248 | + } |
|
1249 | + if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->thirdparty->default_lang)) { |
|
1250 | + $newlang=$this->company->thirdparty->default_lang; |
|
1251 | + } |
|
1252 | + // for proposal, order, invoice, ... |
|
1253 | + if ($this->conf->global->MAIN_MULTILANGS && empty($newlang) && isset($this->company->default_lang)) { |
|
1254 | + $newlang=$this->company->default_lang; |
|
1255 | + } |
|
1256 | + // for thirdparty |
|
1207 | 1257 | if (! empty($newlang)) { |
1208 | 1258 | $outputlangs = new Translate("",$conf); |
1209 | 1259 | $outputlangs->setDefaultLang($newlang); |
@@ -1212,16 +1262,28 @@ discard block |
||
1212 | 1262 | // To be sure vars is defined |
1213 | 1263 | $hidedetails = $hidedesc = $hideref = 0; |
1214 | 1264 | $moreparams=null; |
1215 | - if (empty($hidedetails)) $hidedetails=0; |
|
1216 | - if (empty($hidedesc)) $hidedesc=0; |
|
1217 | - if (empty($hideref)) $hideref=0; |
|
1218 | - if (empty($moreparams)) $moreparams=null; |
|
1265 | + if (empty($hidedetails)) { |
|
1266 | + $hidedetails=0; |
|
1267 | + } |
|
1268 | + if (empty($hidedesc)) { |
|
1269 | + $hidedesc=0; |
|
1270 | + } |
|
1271 | + if (empty($hideref)) { |
|
1272 | + $hideref=0; |
|
1273 | + } |
|
1274 | + if (empty($moreparams)) { |
|
1275 | + $moreparams=null; |
|
1276 | + } |
|
1219 | 1277 | |
1220 | 1278 | |
1221 | 1279 | $sql = "SELECT rowid"; |
1222 | 1280 | $sql.= " FROM ".MAIN_DB_PREFIX."societe_rib"; |
1223 | - if ($id) $sql.= " WHERE fk_soc = ".$id." "; |
|
1224 | - if ($companybankid) $sql.= " AND id = ".$companybankid.""; |
|
1281 | + if ($id) { |
|
1282 | + $sql.= " WHERE fk_soc = ".$id." "; |
|
1283 | + } |
|
1284 | + if ($companybankid) { |
|
1285 | + $sql.= " AND id = ".$companybankid.""; |
|
1286 | + } |
|
1225 | 1287 | |
1226 | 1288 | $i=0; |
1227 | 1289 | $accounts=array(); |
@@ -1244,8 +1306,7 @@ discard block |
||
1244 | 1306 | } |
1245 | 1307 | $i++; |
1246 | 1308 | } |
1247 | - } |
|
1248 | - else |
|
1309 | + } else |
|
1249 | 1310 | { |
1250 | 1311 | throw new RestException(404, 'Bank account not found'); |
1251 | 1312 | } |
@@ -1262,8 +1323,7 @@ discard block |
||
1262 | 1323 | if ($result > 0) |
1263 | 1324 | { |
1264 | 1325 | return array("success" => $result); |
1265 | - } |
|
1266 | - else |
|
1326 | + } else |
|
1267 | 1327 | { |
1268 | 1328 | throw new RestException(500); |
1269 | 1329 | } |
@@ -1298,7 +1358,9 @@ discard block |
||
1298 | 1358 | */ |
1299 | 1359 | $sql = "SELECT rowid, fk_soc, key_account, site, date_creation, tms FROM ".MAIN_DB_PREFIX."societe_account"; |
1300 | 1360 | $sql.= " WHERE fk_soc = $id"; |
1301 | - if($site) $sql .= " AND site ='$site'"; |
|
1361 | + if($site) { |
|
1362 | + $sql .= " AND site ='$site'"; |
|
1363 | + } |
|
1302 | 1364 | |
1303 | 1365 | $result = $db->query($sql); |
1304 | 1366 | |
@@ -1328,9 +1390,10 @@ discard block |
||
1328 | 1390 | |
1329 | 1391 | foreach($accounts as $account){ |
1330 | 1392 | $object= []; |
1331 | - foreach($account as $key => $value) |
|
1332 | - if(in_array($key, $fields)){ |
|
1393 | + foreach($account as $key => $value) { |
|
1394 | + if(in_array($key, $fields)){ |
|
1333 | 1395 | $object[$key] = $value; |
1396 | + } |
|
1334 | 1397 | } |
1335 | 1398 | $returnAccounts[] = $object; |
1336 | 1399 | } |
@@ -1383,8 +1446,9 @@ discard block |
||
1383 | 1446 | $account->$field = $value; |
1384 | 1447 | } |
1385 | 1448 | |
1386 | - if ($account->create(DolibarrApiAccess::$user) < 0) |
|
1387 | - throw new RestException(500, 'Error creating SocieteAccount entity. Ensure that the ID of thirdparty provided does exist!'); |
|
1449 | + if ($account->create(DolibarrApiAccess::$user) < 0) { |
|
1450 | + throw new RestException(500, 'Error creating SocieteAccount entity. Ensure that the ID of thirdparty provided does exist!'); |
|
1451 | + } |
|
1388 | 1452 | |
1389 | 1453 | $this->_cleanObjectDatas($account); |
1390 | 1454 | |
@@ -1444,8 +1508,9 @@ discard block |
||
1444 | 1508 | $account->fk_soc = $id; |
1445 | 1509 | $account->site = $site; |
1446 | 1510 | |
1447 | - if ($account->create(DolibarrApiAccess::$user) < 0) |
|
1448 | - throw new RestException(500, 'Error creating SocieteAccount entity.'); |
|
1511 | + if ($account->create(DolibarrApiAccess::$user) < 0) { |
|
1512 | + throw new RestException(500, 'Error creating SocieteAccount entity.'); |
|
1513 | + } |
|
1449 | 1514 | // We found an existing SocieteAccount entity, we are replacing it |
1450 | 1515 | } else { |
1451 | 1516 | |
@@ -1453,8 +1518,9 @@ discard block |
||
1453 | 1518 | $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".$id." AND site = '". $request_data['site']."' "; |
1454 | 1519 | $result = $db->query($sql); |
1455 | 1520 | |
1456 | - if($result->num_rows !== 0) |
|
1457 | - throw new RestException(409, "You are trying to update this thirdparty SocieteAccount (gateway record) from $site to ".$request_data['site'] . " but another SocieteAccount entity already exists with this site key."); |
|
1521 | + if($result->num_rows !== 0) { |
|
1522 | + throw new RestException(409, "You are trying to update this thirdparty SocieteAccount (gateway record) from $site to ".$request_data['site'] . " but another SocieteAccount entity already exists with this site key."); |
|
1523 | + } |
|
1458 | 1524 | } |
1459 | 1525 | |
1460 | 1526 | $obj = $db->fetch_object($result); |
@@ -1473,8 +1539,9 @@ discard block |
||
1473 | 1539 | $account->$field = $value; |
1474 | 1540 | } |
1475 | 1541 | |
1476 | - if ($account->update(DolibarrApiAccess::$user) < 0) |
|
1477 | - throw new RestException(500, 'Error updating SocieteAccount entity.'); |
|
1542 | + if ($account->update(DolibarrApiAccess::$user) < 0) { |
|
1543 | + throw new RestException(500, 'Error updating SocieteAccount entity.'); |
|
1544 | + } |
|
1478 | 1545 | } |
1479 | 1546 | |
1480 | 1547 | $this->_cleanObjectDatas($account); |
@@ -1517,8 +1584,9 @@ discard block |
||
1517 | 1584 | $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_account WHERE fk_soc = ".$id." AND site = '". $request_data['site']."' "; |
1518 | 1585 | $result = $db->query($sql); |
1519 | 1586 | |
1520 | - if($result->num_rows !== 0) |
|
1521 | - throw new RestException(409, "You are trying to update this thirdparty SocieteAccount (gateway record) site member from $site to ".$request_data['site'] . " but another SocieteAccount entity already exists for this thirdparty with this site key."); |
|
1587 | + if($result->num_rows !== 0) { |
|
1588 | + throw new RestException(409, "You are trying to update this thirdparty SocieteAccount (gateway record) site member from $site to ".$request_data['site'] . " but another SocieteAccount entity already exists for this thirdparty with this site key."); |
|
1589 | + } |
|
1522 | 1590 | } |
1523 | 1591 | |
1524 | 1592 | $obj = $db->fetch_object($result); |
@@ -1529,8 +1597,9 @@ discard block |
||
1529 | 1597 | $account->$field = $value; |
1530 | 1598 | } |
1531 | 1599 | |
1532 | - if ($account->update(DolibarrApiAccess::$user) < 0) |
|
1533 | - throw new RestException(500, 'Error updating SocieteAccount account'); |
|
1600 | + if ($account->update(DolibarrApiAccess::$user) < 0) { |
|
1601 | + throw new RestException(500, 'Error updating SocieteAccount account'); |
|
1602 | + } |
|
1534 | 1603 | |
1535 | 1604 | $this->_cleanObjectDatas($account); |
1536 | 1605 | |
@@ -1662,8 +1731,9 @@ discard block |
||
1662 | 1731 | { |
1663 | 1732 | $thirdparty = array(); |
1664 | 1733 | foreach (Thirdparties::$FIELDS as $field) { |
1665 | - if (!isset($data[$field])) |
|
1666 | - throw new RestException(400, "$field field missing"); |
|
1734 | + if (!isset($data[$field])) { |
|
1735 | + throw new RestException(400, "$field field missing"); |
|
1736 | + } |
|
1667 | 1737 | $thirdparty[$field] = $data[$field]; |
1668 | 1738 | } |
1669 | 1739 | return $thirdparty; |
@@ -54,60 +54,60 @@ discard block |
||
54 | 54 | |
55 | 55 | if ($action == 'addcontact' && $user->rights->societe->creer) |
56 | 56 | { |
57 | - $result = $object->fetch($id); |
|
57 | + $result = $object->fetch($id); |
|
58 | 58 | |
59 | 59 | if ($result > 0 && $id > 0) |
60 | 60 | { |
61 | - $contactid = (GETPOST('userid','int') ? GETPOST('userid','int') : GETPOST('contactid','int')); |
|
62 | - $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]); |
|
61 | + $contactid = (GETPOST('userid','int') ? GETPOST('userid','int') : GETPOST('contactid','int')); |
|
62 | + $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]); |
|
63 | 63 | } |
64 | 64 | |
65 | - if ($result >= 0) |
|
66 | - { |
|
67 | - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); |
|
68 | - exit; |
|
69 | - } |
|
70 | - else |
|
71 | - { |
|
72 | - if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') |
|
73 | - { |
|
74 | - $langs->load("errors"); |
|
75 | - $mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>'; |
|
76 | - } |
|
77 | - else |
|
78 | - { |
|
79 | - $mesg = '<div class="error">'.$object->error.'</div>'; |
|
80 | - } |
|
81 | - } |
|
65 | + if ($result >= 0) |
|
66 | + { |
|
67 | + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); |
|
68 | + exit; |
|
69 | + } |
|
70 | + else |
|
71 | + { |
|
72 | + if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') |
|
73 | + { |
|
74 | + $langs->load("errors"); |
|
75 | + $mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>'; |
|
76 | + } |
|
77 | + else |
|
78 | + { |
|
79 | + $mesg = '<div class="error">'.$object->error.'</div>'; |
|
80 | + } |
|
81 | + } |
|
82 | 82 | } |
83 | 83 | |
84 | 84 | // bascule du statut d'un contact |
85 | 85 | else if ($action == 'swapstatut' && $user->rights->societe->creer) |
86 | 86 | { |
87 | - if ($object->fetch($id)) |
|
88 | - { |
|
89 | - $result=$object->swapContactStatus(GETPOST('ligne')); |
|
90 | - } |
|
91 | - else |
|
92 | - { |
|
93 | - dol_print_error($db); |
|
94 | - } |
|
87 | + if ($object->fetch($id)) |
|
88 | + { |
|
89 | + $result=$object->swapContactStatus(GETPOST('ligne')); |
|
90 | + } |
|
91 | + else |
|
92 | + { |
|
93 | + dol_print_error($db); |
|
94 | + } |
|
95 | 95 | } |
96 | 96 | |
97 | 97 | // Efface un contact |
98 | 98 | else if ($action == 'deletecontact' && $user->rights->societe->creer) |
99 | 99 | { |
100 | - $object->fetch($id); |
|
101 | - $result = $object->delete_contact($_GET["lineid"]); |
|
102 | - |
|
103 | - if ($result >= 0) |
|
104 | - { |
|
105 | - header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); |
|
106 | - exit; |
|
107 | - } |
|
108 | - else { |
|
109 | - dol_print_error($db); |
|
110 | - } |
|
100 | + $object->fetch($id); |
|
101 | + $result = $object->delete_contact($_GET["lineid"]); |
|
102 | + |
|
103 | + if ($result >= 0) |
|
104 | + { |
|
105 | + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); |
|
106 | + exit; |
|
107 | + } |
|
108 | + else { |
|
109 | + dol_print_error($db); |
|
110 | + } |
|
111 | 111 | } |
112 | 112 | /* |
113 | 113 | else if ($action == 'setaddress' && $user->rights->societe->creer) |
@@ -141,28 +141,28 @@ discard block |
||
141 | 141 | |
142 | 142 | if ($id > 0 || ! empty($ref)) |
143 | 143 | { |
144 | - if ($object->fetch($id, $ref) > 0) |
|
145 | - { |
|
146 | - $soc = new Societe($db); |
|
147 | - $soc->fetch($object->socid); |
|
144 | + if ($object->fetch($id, $ref) > 0) |
|
145 | + { |
|
146 | + $soc = new Societe($db); |
|
147 | + $soc->fetch($object->socid); |
|
148 | 148 | |
149 | - $head = societe_prepare_head($object); |
|
150 | - dol_fiche_head($head, 'contact', $langs->trans("ThirdParty"), -1, 'company'); |
|
149 | + $head = societe_prepare_head($object); |
|
150 | + dol_fiche_head($head, 'contact', $langs->trans("ThirdParty"), -1, 'company'); |
|
151 | 151 | |
152 | - print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">'; |
|
153 | - print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
152 | + print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">'; |
|
153 | + print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
|
154 | 154 | |
155 | 155 | $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>'; |
156 | 156 | |
157 | 157 | dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom'); |
158 | 158 | |
159 | - print '<div class="fichecenter">'; |
|
159 | + print '<div class="fichecenter">'; |
|
160 | 160 | |
161 | 161 | print '<div class="underbanner clearboth"></div>'; |
162 | - print '<table class="border centpercent">'; |
|
162 | + print '<table class="border centpercent">'; |
|
163 | 163 | |
164 | - // Prospect/Customer |
|
165 | - /*print '<tr><td class="titlefield">'.$langs->trans('ProspectCustomer').'</td><td>'; |
|
164 | + // Prospect/Customer |
|
165 | + /*print '<tr><td class="titlefield">'.$langs->trans('ProspectCustomer').'</td><td>'; |
|
166 | 166 | print $object->getLibCustProspStatut(); |
167 | 167 | print '</td></tr>'; |
168 | 168 | |
@@ -171,175 +171,175 @@ discard block |
||
171 | 171 | print yn($object->fournisseur); |
172 | 172 | print '</td></tr>';*/ |
173 | 173 | |
174 | - if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field |
|
175 | - { |
|
176 | - print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>'; |
|
177 | - } |
|
178 | - |
|
179 | - if ($object->client) |
|
180 | - { |
|
181 | - print '<tr><td class="titlefield">'; |
|
182 | - print $langs->trans('CustomerCode').'</td><td colspan="3">'; |
|
183 | - print $object->code_client; |
|
184 | - if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>'; |
|
185 | - print '</td></tr>'; |
|
186 | - } |
|
187 | - |
|
188 | - if ($object->fournisseur) |
|
189 | - { |
|
190 | - print '<tr><td class="titlefield">'; |
|
191 | - print $langs->trans('SupplierCode').'</td><td colspan="3">'; |
|
192 | - print $object->code_fournisseur; |
|
193 | - if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>'; |
|
194 | - print '</td></tr>'; |
|
195 | - } |
|
196 | - print '</table>'; |
|
197 | - |
|
198 | - print '</div>'; |
|
199 | - |
|
200 | - print '</form>'; |
|
201 | - print '<br>'; |
|
202 | - |
|
203 | - // Contacts lines (modules that overwrite templates must declare this into descriptor) |
|
204 | - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); |
|
205 | - foreach($dirtpls as $reldir) |
|
206 | - { |
|
207 | - $res=@include dol_buildpath($reldir.'/contacts.tpl.php'); |
|
208 | - if ($res) break; |
|
209 | - } |
|
210 | - |
|
211 | - // additionnal list with adherents of company |
|
212 | - if (! empty($conf->adherent->enabled) && $user->rights->adherent->lire) |
|
213 | - { |
|
214 | - require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; |
|
215 | - require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php'; |
|
216 | - |
|
217 | - $membertypestatic=new AdherentType($db); |
|
218 | - $memberstatic=new Adherent($db); |
|
219 | - |
|
220 | - $langs->load("members"); |
|
221 | - $sql = "SELECT d.rowid, d.login, d.lastname, d.firstname, d.societe as company, d.fk_soc,"; |
|
222 | - $sql.= " d.datefin,"; |
|
223 | - $sql.= " d.email, d.fk_adherent_type as type_id, d.morphy, d.statut,"; |
|
224 | - $sql.= " t.libelle as type, t.subscription"; |
|
225 | - $sql.= " FROM ".MAIN_DB_PREFIX."adherent as d"; |
|
226 | - $sql.= ", ".MAIN_DB_PREFIX."adherent_type as t"; |
|
227 | - $sql.= " WHERE d.fk_soc = ".$id; |
|
228 | - $sql.= " AND d.fk_adherent_type = t.rowid"; |
|
229 | - |
|
230 | - dol_syslog("get list sql=".$sql); |
|
231 | - $resql = $db->query($sql); |
|
232 | - if ($resql) |
|
233 | - { |
|
234 | - $num = $db->num_rows($resql); |
|
235 | - |
|
236 | - if ($num > 0 ) |
|
237 | - { |
|
238 | - $titre=$langs->trans("MembersListOfTiers"); |
|
239 | - print '<br>'; |
|
240 | - |
|
241 | - print_barre_liste($titre,$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecords,''); |
|
242 | - |
|
243 | - print "<table class=\"noborder\" width=\"100%\">"; |
|
244 | - print '<tr class="liste_titre">'; |
|
245 | - print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"d.rowid",$param,"","",$sortfield,$sortorder); |
|
246 | - print_liste_field_titre( $langs->trans("Name")." / ".$langs->trans("Company"),$_SERVER["PHP_SELF"],"d.lastname",$param,"","",$sortfield,$sortorder); |
|
247 | - print_liste_field_titre("Login",$_SERVER["PHP_SELF"],"d.login",$param,"","",$sortfield,$sortorder); |
|
248 | - print_liste_field_titre("Type",$_SERVER["PHP_SELF"],"t.libelle",$param,"","",$sortfield,$sortorder); |
|
249 | - print_liste_field_titre("Person",$_SERVER["PHP_SELF"],"d.morphy",$param,"","",$sortfield,$sortorder); |
|
250 | - print_liste_field_titre("EMail",$_SERVER["PHP_SELF"],"d.email",$param,"","",$sortfield,$sortorder); |
|
251 | - print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"d.statut,d.datefin",$param,"","",$sortfield,$sortorder); |
|
252 | - print_liste_field_titre("EndSubscription",$_SERVER["PHP_SELF"],"d.datefin",$param,"",'align="center"',$sortfield,$sortorder); |
|
253 | - print "</tr>\n"; |
|
254 | - |
|
255 | - $i=0; |
|
256 | - while ($i < $num && $i < $conf->liste_limit) |
|
257 | - { |
|
258 | - $objp = $db->fetch_object($resql); |
|
259 | - |
|
260 | - $datefin=$db->jdate($objp->datefin); |
|
261 | - $memberstatic->id=$objp->rowid; |
|
262 | - $memberstatic->ref=$objp->rowid; |
|
263 | - $memberstatic->lastname=$objp->lastname; |
|
264 | - $memberstatic->firstname=$objp->firstname; |
|
265 | - $memberstatic->statut=$objp->statut; |
|
266 | - $memberstatic->datefin=$db->jdate($objp->datefin); |
|
267 | - |
|
268 | - $companyname=$objp->company; |
|
269 | - |
|
270 | - print '<tr class="oddeven">'; |
|
271 | - |
|
272 | - // Ref |
|
273 | - print "<td>"; |
|
274 | - print $memberstatic->getNomUrl(1); |
|
275 | - print "</td>\n"; |
|
276 | - |
|
277 | - // Lastname |
|
278 | - print "<td><a href=\"card.php?rowid=$objp->rowid\">"; |
|
279 | - print ((! empty($objp->lastname) || ! empty($objp->firstname)) ? dol_trunc($memberstatic->getFullName($langs)) : ''); |
|
280 | - print (((! empty($objp->lastname) || ! empty($objp->firstname)) && ! empty($companyname)) ? ' / ' : ''); |
|
281 | - print (! empty($companyname) ? dol_trunc($companyname, 32) : ''); |
|
282 | - print "</a></td>\n"; |
|
283 | - |
|
284 | - // Login |
|
285 | - print "<td>".$objp->login."</td>\n"; |
|
286 | - |
|
287 | - // Type |
|
288 | - $membertypestatic->id=$objp->type_id; |
|
289 | - $membertypestatic->libelle=$objp->type; |
|
290 | - print '<td class="nowrap">'; |
|
291 | - print $membertypestatic->getNomUrl(1,32); |
|
292 | - print '</td>'; |
|
293 | - |
|
294 | - // Moral/Physique |
|
295 | - print "<td>".$memberstatic->getmorphylib($objp->morphy)."</td>\n"; |
|
296 | - |
|
297 | ||
298 | - print "<td>".dol_print_email($objp->email,0,0,1)."</td>\n"; |
|
299 | - |
|
300 | - // Statut |
|
301 | - print '<td class="nowrap">'; |
|
302 | - print $memberstatic->LibStatut($objp->statut,$objp->subscription,$datefin,2); |
|
303 | - print "</td>"; |
|
304 | - |
|
305 | - // End of subscription date |
|
306 | - if ($datefin) |
|
307 | - { |
|
308 | - print '<td align="center" class="nowrap">'; |
|
309 | - print dol_print_date($datefin,'day'); |
|
310 | - if ($memberstatic->hasDelay()) { |
|
311 | - print " ".img_warning($langs->trans("SubscriptionLate")); |
|
312 | - } |
|
313 | - print '</td>'; |
|
314 | - } |
|
315 | - else |
|
316 | - { |
|
317 | - print '<td align="left" class="nowrap">'; |
|
318 | - if ($objp->subscription == 'yes') |
|
319 | - { |
|
320 | - print $langs->trans("SubscriptionNotReceived"); |
|
321 | - if ($objp->statut > 0) print " ".img_warning(); |
|
322 | - } |
|
323 | - else |
|
324 | - { |
|
325 | - print ' '; |
|
326 | - } |
|
327 | - print '</td>'; |
|
328 | - } |
|
329 | - |
|
330 | - print "</tr>\n"; |
|
331 | - $i++; |
|
332 | - } |
|
333 | - print "</table>\n"; |
|
334 | - } |
|
335 | - } |
|
336 | - } |
|
337 | - } |
|
338 | - else |
|
339 | - { |
|
340 | - // Contrat non trouve |
|
341 | - print "ErrorRecordNotFound"; |
|
342 | - } |
|
174 | + if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field |
|
175 | + { |
|
176 | + print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>'; |
|
177 | + } |
|
178 | + |
|
179 | + if ($object->client) |
|
180 | + { |
|
181 | + print '<tr><td class="titlefield">'; |
|
182 | + print $langs->trans('CustomerCode').'</td><td colspan="3">'; |
|
183 | + print $object->code_client; |
|
184 | + if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>'; |
|
185 | + print '</td></tr>'; |
|
186 | + } |
|
187 | + |
|
188 | + if ($object->fournisseur) |
|
189 | + { |
|
190 | + print '<tr><td class="titlefield">'; |
|
191 | + print $langs->trans('SupplierCode').'</td><td colspan="3">'; |
|
192 | + print $object->code_fournisseur; |
|
193 | + if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>'; |
|
194 | + print '</td></tr>'; |
|
195 | + } |
|
196 | + print '</table>'; |
|
197 | + |
|
198 | + print '</div>'; |
|
199 | + |
|
200 | + print '</form>'; |
|
201 | + print '<br>'; |
|
202 | + |
|
203 | + // Contacts lines (modules that overwrite templates must declare this into descriptor) |
|
204 | + $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); |
|
205 | + foreach($dirtpls as $reldir) |
|
206 | + { |
|
207 | + $res=@include dol_buildpath($reldir.'/contacts.tpl.php'); |
|
208 | + if ($res) break; |
|
209 | + } |
|
210 | + |
|
211 | + // additionnal list with adherents of company |
|
212 | + if (! empty($conf->adherent->enabled) && $user->rights->adherent->lire) |
|
213 | + { |
|
214 | + require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; |
|
215 | + require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php'; |
|
216 | + |
|
217 | + $membertypestatic=new AdherentType($db); |
|
218 | + $memberstatic=new Adherent($db); |
|
219 | + |
|
220 | + $langs->load("members"); |
|
221 | + $sql = "SELECT d.rowid, d.login, d.lastname, d.firstname, d.societe as company, d.fk_soc,"; |
|
222 | + $sql.= " d.datefin,"; |
|
223 | + $sql.= " d.email, d.fk_adherent_type as type_id, d.morphy, d.statut,"; |
|
224 | + $sql.= " t.libelle as type, t.subscription"; |
|
225 | + $sql.= " FROM ".MAIN_DB_PREFIX."adherent as d"; |
|
226 | + $sql.= ", ".MAIN_DB_PREFIX."adherent_type as t"; |
|
227 | + $sql.= " WHERE d.fk_soc = ".$id; |
|
228 | + $sql.= " AND d.fk_adherent_type = t.rowid"; |
|
229 | + |
|
230 | + dol_syslog("get list sql=".$sql); |
|
231 | + $resql = $db->query($sql); |
|
232 | + if ($resql) |
|
233 | + { |
|
234 | + $num = $db->num_rows($resql); |
|
235 | + |
|
236 | + if ($num > 0 ) |
|
237 | + { |
|
238 | + $titre=$langs->trans("MembersListOfTiers"); |
|
239 | + print '<br>'; |
|
240 | + |
|
241 | + print_barre_liste($titre,$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecords,''); |
|
242 | + |
|
243 | + print "<table class=\"noborder\" width=\"100%\">"; |
|
244 | + print '<tr class="liste_titre">'; |
|
245 | + print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"d.rowid",$param,"","",$sortfield,$sortorder); |
|
246 | + print_liste_field_titre( $langs->trans("Name")." / ".$langs->trans("Company"),$_SERVER["PHP_SELF"],"d.lastname",$param,"","",$sortfield,$sortorder); |
|
247 | + print_liste_field_titre("Login",$_SERVER["PHP_SELF"],"d.login",$param,"","",$sortfield,$sortorder); |
|
248 | + print_liste_field_titre("Type",$_SERVER["PHP_SELF"],"t.libelle",$param,"","",$sortfield,$sortorder); |
|
249 | + print_liste_field_titre("Person",$_SERVER["PHP_SELF"],"d.morphy",$param,"","",$sortfield,$sortorder); |
|
250 | + print_liste_field_titre("EMail",$_SERVER["PHP_SELF"],"d.email",$param,"","",$sortfield,$sortorder); |
|
251 | + print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"d.statut,d.datefin",$param,"","",$sortfield,$sortorder); |
|
252 | + print_liste_field_titre("EndSubscription",$_SERVER["PHP_SELF"],"d.datefin",$param,"",'align="center"',$sortfield,$sortorder); |
|
253 | + print "</tr>\n"; |
|
254 | + |
|
255 | + $i=0; |
|
256 | + while ($i < $num && $i < $conf->liste_limit) |
|
257 | + { |
|
258 | + $objp = $db->fetch_object($resql); |
|
259 | + |
|
260 | + $datefin=$db->jdate($objp->datefin); |
|
261 | + $memberstatic->id=$objp->rowid; |
|
262 | + $memberstatic->ref=$objp->rowid; |
|
263 | + $memberstatic->lastname=$objp->lastname; |
|
264 | + $memberstatic->firstname=$objp->firstname; |
|
265 | + $memberstatic->statut=$objp->statut; |
|
266 | + $memberstatic->datefin=$db->jdate($objp->datefin); |
|
267 | + |
|
268 | + $companyname=$objp->company; |
|
269 | + |
|
270 | + print '<tr class="oddeven">'; |
|
271 | + |
|
272 | + // Ref |
|
273 | + print "<td>"; |
|
274 | + print $memberstatic->getNomUrl(1); |
|
275 | + print "</td>\n"; |
|
276 | + |
|
277 | + // Lastname |
|
278 | + print "<td><a href=\"card.php?rowid=$objp->rowid\">"; |
|
279 | + print ((! empty($objp->lastname) || ! empty($objp->firstname)) ? dol_trunc($memberstatic->getFullName($langs)) : ''); |
|
280 | + print (((! empty($objp->lastname) || ! empty($objp->firstname)) && ! empty($companyname)) ? ' / ' : ''); |
|
281 | + print (! empty($companyname) ? dol_trunc($companyname, 32) : ''); |
|
282 | + print "</a></td>\n"; |
|
283 | + |
|
284 | + // Login |
|
285 | + print "<td>".$objp->login."</td>\n"; |
|
286 | + |
|
287 | + // Type |
|
288 | + $membertypestatic->id=$objp->type_id; |
|
289 | + $membertypestatic->libelle=$objp->type; |
|
290 | + print '<td class="nowrap">'; |
|
291 | + print $membertypestatic->getNomUrl(1,32); |
|
292 | + print '</td>'; |
|
293 | + |
|
294 | + // Moral/Physique |
|
295 | + print "<td>".$memberstatic->getmorphylib($objp->morphy)."</td>\n"; |
|
296 | + |
|
297 | ||
298 | + print "<td>".dol_print_email($objp->email,0,0,1)."</td>\n"; |
|
299 | + |
|
300 | + // Statut |
|
301 | + print '<td class="nowrap">'; |
|
302 | + print $memberstatic->LibStatut($objp->statut,$objp->subscription,$datefin,2); |
|
303 | + print "</td>"; |
|
304 | + |
|
305 | + // End of subscription date |
|
306 | + if ($datefin) |
|
307 | + { |
|
308 | + print '<td align="center" class="nowrap">'; |
|
309 | + print dol_print_date($datefin,'day'); |
|
310 | + if ($memberstatic->hasDelay()) { |
|
311 | + print " ".img_warning($langs->trans("SubscriptionLate")); |
|
312 | + } |
|
313 | + print '</td>'; |
|
314 | + } |
|
315 | + else |
|
316 | + { |
|
317 | + print '<td align="left" class="nowrap">'; |
|
318 | + if ($objp->subscription == 'yes') |
|
319 | + { |
|
320 | + print $langs->trans("SubscriptionNotReceived"); |
|
321 | + if ($objp->statut > 0) print " ".img_warning(); |
|
322 | + } |
|
323 | + else |
|
324 | + { |
|
325 | + print ' '; |
|
326 | + } |
|
327 | + print '</td>'; |
|
328 | + } |
|
329 | + |
|
330 | + print "</tr>\n"; |
|
331 | + $i++; |
|
332 | + } |
|
333 | + print "</table>\n"; |
|
334 | + } |
|
335 | + } |
|
336 | + } |
|
337 | + } |
|
338 | + else |
|
339 | + { |
|
340 | + // Contrat non trouve |
|
341 | + print "ErrorRecordNotFound"; |
|
342 | + } |
|
343 | 343 | } |
344 | 344 | |
345 | 345 | // End of page |
@@ -39,7 +39,9 @@ discard block |
||
39 | 39 | $action=GETPOST('action','alpha'); |
40 | 40 | |
41 | 41 | // Security check |
42 | -if ($user->societe_id) $socid=$user->societe_id; |
|
42 | +if ($user->societe_id) { |
|
43 | + $socid=$user->societe_id; |
|
44 | +} |
|
43 | 45 | $result = restrictedArea($user, 'societe', $id,''); |
44 | 46 | |
45 | 47 | $object = new Societe($db); |
@@ -66,15 +68,13 @@ discard block |
||
66 | 68 | { |
67 | 69 | header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); |
68 | 70 | exit; |
69 | - } |
|
70 | - else |
|
71 | + } else |
|
71 | 72 | { |
72 | 73 | if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') |
73 | 74 | { |
74 | 75 | $langs->load("errors"); |
75 | 76 | $mesg = '<div class="error">'.$langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType").'</div>'; |
76 | - } |
|
77 | - else |
|
77 | + } else |
|
78 | 78 | { |
79 | 79 | $mesg = '<div class="error">'.$object->error.'</div>'; |
80 | 80 | } |
@@ -87,8 +87,7 @@ discard block |
||
87 | 87 | if ($object->fetch($id)) |
88 | 88 | { |
89 | 89 | $result=$object->swapContactStatus(GETPOST('ligne')); |
90 | - } |
|
91 | - else |
|
90 | + } else |
|
92 | 91 | { |
93 | 92 | dol_print_error($db); |
94 | 93 | } |
@@ -104,8 +103,7 @@ discard block |
||
104 | 103 | { |
105 | 104 | header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); |
106 | 105 | exit; |
107 | - } |
|
108 | - else { |
|
106 | + } else { |
|
109 | 107 | dol_print_error($db); |
110 | 108 | } |
111 | 109 | } |
@@ -171,17 +169,21 @@ discard block |
||
171 | 169 | print yn($object->fournisseur); |
172 | 170 | print '</td></tr>';*/ |
173 | 171 | |
174 | - if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field |
|
172 | + if (! empty($conf->global->SOCIETE_USEPREFIX)) { |
|
173 | + // Old not used prefix field |
|
175 | 174 | { |
176 | 175 | print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>'; |
177 | 176 | } |
177 | + } |
|
178 | 178 | |
179 | 179 | if ($object->client) |
180 | 180 | { |
181 | 181 | print '<tr><td class="titlefield">'; |
182 | 182 | print $langs->trans('CustomerCode').'</td><td colspan="3">'; |
183 | 183 | print $object->code_client; |
184 | - if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>'; |
|
184 | + if ($object->check_codeclient() <> 0) { |
|
185 | + print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>'; |
|
186 | + } |
|
185 | 187 | print '</td></tr>'; |
186 | 188 | } |
187 | 189 | |
@@ -190,7 +192,9 @@ discard block |
||
190 | 192 | print '<tr><td class="titlefield">'; |
191 | 193 | print $langs->trans('SupplierCode').'</td><td colspan="3">'; |
192 | 194 | print $object->code_fournisseur; |
193 | - if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>'; |
|
195 | + if ($object->check_codefournisseur() <> 0) { |
|
196 | + print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>'; |
|
197 | + } |
|
194 | 198 | print '</td></tr>'; |
195 | 199 | } |
196 | 200 | print '</table>'; |
@@ -205,7 +209,9 @@ discard block |
||
205 | 209 | foreach($dirtpls as $reldir) |
206 | 210 | { |
207 | 211 | $res=@include dol_buildpath($reldir.'/contacts.tpl.php'); |
208 | - if ($res) break; |
|
212 | + if ($res) { |
|
213 | + break; |
|
214 | + } |
|
209 | 215 | } |
210 | 216 | |
211 | 217 | // additionnal list with adherents of company |
@@ -311,16 +317,16 @@ discard block |
||
311 | 317 | print " ".img_warning($langs->trans("SubscriptionLate")); |
312 | 318 | } |
313 | 319 | print '</td>'; |
314 | - } |
|
315 | - else |
|
320 | + } else |
|
316 | 321 | { |
317 | 322 | print '<td align="left" class="nowrap">'; |
318 | 323 | if ($objp->subscription == 'yes') |
319 | 324 | { |
320 | 325 | print $langs->trans("SubscriptionNotReceived"); |
321 | - if ($objp->statut > 0) print " ".img_warning(); |
|
322 | - } |
|
323 | - else |
|
326 | + if ($objp->statut > 0) { |
|
327 | + print " ".img_warning(); |
|
328 | + } |
|
329 | + } else |
|
324 | 330 | { |
325 | 331 | print ' '; |
326 | 332 | } |
@@ -334,8 +340,7 @@ discard block |
||
334 | 340 | } |
335 | 341 | } |
336 | 342 | } |
337 | - } |
|
338 | - else |
|
343 | + } else |
|
339 | 344 | { |
340 | 345 | // Contrat non trouve |
341 | 346 | print "ErrorRecordNotFound"; |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | |
30 | 30 | // Copyright (C) 2018 Alxarafe/Alixar <[email protected]> |
31 | 31 | defined('BASE_PATH') or die('Single entry point through the index.php of the main folder'); |
32 | -require DOL_BASE_PATH . '/main.inc.php'; |
|
32 | +require DOL_BASE_PATH.'/main.inc.php'; |
|
33 | 33 | |
34 | 34 | require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
35 | 35 | require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; |
@@ -38,18 +38,18 @@ discard block |
||
38 | 38 | |
39 | 39 | $langs->loadLangs(array("orders", "companies")); |
40 | 40 | |
41 | -$id=GETPOST('id','int')?GETPOST('id','int'):GETPOST('socid','int'); |
|
42 | -$ref=GETPOST('ref','alpha'); |
|
43 | -$action=GETPOST('action','alpha'); |
|
41 | +$id = GETPOST('id', 'int') ?GETPOST('id', 'int') : GETPOST('socid', 'int'); |
|
42 | +$ref = GETPOST('ref', 'alpha'); |
|
43 | +$action = GETPOST('action', 'alpha'); |
|
44 | 44 | |
45 | 45 | // Security check |
46 | -if ($user->societe_id) $socid=$user->societe_id; |
|
47 | -$result = restrictedArea($user, 'societe', $id,''); |
|
46 | +if ($user->societe_id) $socid = $user->societe_id; |
|
47 | +$result = restrictedArea($user, 'societe', $id, ''); |
|
48 | 48 | |
49 | 49 | $object = new Societe($db); |
50 | 50 | |
51 | 51 | // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context |
52 | -$hookmanager->initHooks(array('contactthirdparty','globalcard')); |
|
52 | +$hookmanager->initHooks(array('contactthirdparty', 'globalcard')); |
|
53 | 53 | |
54 | 54 | |
55 | 55 | /* |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | |
63 | 63 | if ($result > 0 && $id > 0) |
64 | 64 | { |
65 | - $contactid = (GETPOST('userid','int') ? GETPOST('userid','int') : GETPOST('contactid','int')); |
|
65 | + $contactid = (GETPOST('userid', 'int') ? GETPOST('userid', 'int') : GETPOST('contactid', 'int')); |
|
66 | 66 | $result = $object->add_contact($contactid, $_POST["type"], $_POST["source"]); |
67 | 67 | } |
68 | 68 | |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | { |
91 | 91 | if ($object->fetch($id)) |
92 | 92 | { |
93 | - $result=$object->swapContactStatus(GETPOST('ligne')); |
|
93 | + $result = $object->swapContactStatus(GETPOST('ligne')); |
|
94 | 94 | } |
95 | 95 | else |
96 | 96 | { |
@@ -126,15 +126,15 @@ discard block |
||
126 | 126 | * View |
127 | 127 | */ |
128 | 128 | |
129 | -$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; |
|
130 | -llxHeader('',$langs->trans("ThirdParty"),$help_url); |
|
129 | +$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; |
|
130 | +llxHeader('', $langs->trans("ThirdParty"), $help_url); |
|
131 | 131 | |
132 | 132 | |
133 | 133 | $form = new Form($db); |
134 | 134 | $formcompany = new FormCompany($db); |
135 | 135 | $formother = new FormOther($db); |
136 | -$contactstatic=new Contact($db); |
|
137 | -$userstatic=new User($db); |
|
136 | +$contactstatic = new Contact($db); |
|
137 | +$userstatic = new User($db); |
|
138 | 138 | |
139 | 139 | |
140 | 140 | /* *************************************************************************** */ |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | /* */ |
144 | 144 | /* *************************************************************************** */ |
145 | 145 | |
146 | -if ($id > 0 || ! empty($ref)) |
|
146 | +if ($id > 0 || !empty($ref)) |
|
147 | 147 | { |
148 | 148 | if ($object->fetch($id, $ref) > 0) |
149 | 149 | { |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | |
159 | 159 | $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>'; |
160 | 160 | |
161 | - dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom'); |
|
161 | + dol_banner_tab($object, 'socid', $linkback, ($user->societe_id ? 0 : 1), 'rowid', 'nom'); |
|
162 | 162 | |
163 | 163 | print '<div class="fichecenter">'; |
164 | 164 | |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | print yn($object->fournisseur); |
176 | 176 | print '</td></tr>';*/ |
177 | 177 | |
178 | - if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field |
|
178 | + if (!empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field |
|
179 | 179 | { |
180 | 180 | print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>'; |
181 | 181 | } |
@@ -205,31 +205,31 @@ discard block |
||
205 | 205 | print '<br>'; |
206 | 206 | |
207 | 207 | // Contacts lines (modules that overwrite templates must declare this into descriptor) |
208 | - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl')); |
|
209 | - foreach($dirtpls as $reldir) |
|
208 | + $dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl')); |
|
209 | + foreach ($dirtpls as $reldir) |
|
210 | 210 | { |
211 | - $res=@include dol_buildpath($reldir.'/contacts.tpl.php'); |
|
211 | + $res = @include dol_buildpath($reldir.'/contacts.tpl.php'); |
|
212 | 212 | if ($res) break; |
213 | 213 | } |
214 | 214 | |
215 | 215 | // additionnal list with adherents of company |
216 | - if (! empty($conf->adherent->enabled) && $user->rights->adherent->lire) |
|
216 | + if (!empty($conf->adherent->enabled) && $user->rights->adherent->lire) |
|
217 | 217 | { |
218 | 218 | require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; |
219 | 219 | require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php'; |
220 | 220 | |
221 | - $membertypestatic=new AdherentType($db); |
|
222 | - $memberstatic=new Adherent($db); |
|
221 | + $membertypestatic = new AdherentType($db); |
|
222 | + $memberstatic = new Adherent($db); |
|
223 | 223 | |
224 | 224 | $langs->load("members"); |
225 | 225 | $sql = "SELECT d.rowid, d.login, d.lastname, d.firstname, d.societe as company, d.fk_soc,"; |
226 | - $sql.= " d.datefin,"; |
|
227 | - $sql.= " d.email, d.fk_adherent_type as type_id, d.morphy, d.statut,"; |
|
228 | - $sql.= " t.libelle as type, t.subscription"; |
|
229 | - $sql.= " FROM ".MAIN_DB_PREFIX."adherent as d"; |
|
230 | - $sql.= ", ".MAIN_DB_PREFIX."adherent_type as t"; |
|
231 | - $sql.= " WHERE d.fk_soc = ".$id; |
|
232 | - $sql.= " AND d.fk_adherent_type = t.rowid"; |
|
226 | + $sql .= " d.datefin,"; |
|
227 | + $sql .= " d.email, d.fk_adherent_type as type_id, d.morphy, d.statut,"; |
|
228 | + $sql .= " t.libelle as type, t.subscription"; |
|
229 | + $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d"; |
|
230 | + $sql .= ", ".MAIN_DB_PREFIX."adherent_type as t"; |
|
231 | + $sql .= " WHERE d.fk_soc = ".$id; |
|
232 | + $sql .= " AND d.fk_adherent_type = t.rowid"; |
|
233 | 233 | |
234 | 234 | dol_syslog("get list sql=".$sql); |
235 | 235 | $resql = $db->query($sql); |
@@ -237,39 +237,39 @@ discard block |
||
237 | 237 | { |
238 | 238 | $num = $db->num_rows($resql); |
239 | 239 | |
240 | - if ($num > 0 ) |
|
240 | + if ($num > 0) |
|
241 | 241 | { |
242 | - $titre=$langs->trans("MembersListOfTiers"); |
|
242 | + $titre = $langs->trans("MembersListOfTiers"); |
|
243 | 243 | print '<br>'; |
244 | 244 | |
245 | - print_barre_liste($titre,$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecords,''); |
|
245 | + print_barre_liste($titre, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, ''); |
|
246 | 246 | |
247 | 247 | print "<table class=\"noborder\" width=\"100%\">"; |
248 | 248 | print '<tr class="liste_titre">'; |
249 | - print_liste_field_titre("Ref",$_SERVER["PHP_SELF"],"d.rowid",$param,"","",$sortfield,$sortorder); |
|
250 | - print_liste_field_titre( $langs->trans("Name")." / ".$langs->trans("Company"),$_SERVER["PHP_SELF"],"d.lastname",$param,"","",$sortfield,$sortorder); |
|
251 | - print_liste_field_titre("Login",$_SERVER["PHP_SELF"],"d.login",$param,"","",$sortfield,$sortorder); |
|
252 | - print_liste_field_titre("Type",$_SERVER["PHP_SELF"],"t.libelle",$param,"","",$sortfield,$sortorder); |
|
253 | - print_liste_field_titre("Person",$_SERVER["PHP_SELF"],"d.morphy",$param,"","",$sortfield,$sortorder); |
|
254 | - print_liste_field_titre("EMail",$_SERVER["PHP_SELF"],"d.email",$param,"","",$sortfield,$sortorder); |
|
255 | - print_liste_field_titre("Status",$_SERVER["PHP_SELF"],"d.statut,d.datefin",$param,"","",$sortfield,$sortorder); |
|
256 | - print_liste_field_titre("EndSubscription",$_SERVER["PHP_SELF"],"d.datefin",$param,"",'align="center"',$sortfield,$sortorder); |
|
249 | + print_liste_field_titre("Ref", $_SERVER["PHP_SELF"], "d.rowid", $param, "", "", $sortfield, $sortorder); |
|
250 | + print_liste_field_titre($langs->trans("Name")." / ".$langs->trans("Company"), $_SERVER["PHP_SELF"], "d.lastname", $param, "", "", $sortfield, $sortorder); |
|
251 | + print_liste_field_titre("Login", $_SERVER["PHP_SELF"], "d.login", $param, "", "", $sortfield, $sortorder); |
|
252 | + print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "t.libelle", $param, "", "", $sortfield, $sortorder); |
|
253 | + print_liste_field_titre("Person", $_SERVER["PHP_SELF"], "d.morphy", $param, "", "", $sortfield, $sortorder); |
|
254 | + print_liste_field_titre("EMail", $_SERVER["PHP_SELF"], "d.email", $param, "", "", $sortfield, $sortorder); |
|
255 | + print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "d.statut,d.datefin", $param, "", "", $sortfield, $sortorder); |
|
256 | + print_liste_field_titre("EndSubscription", $_SERVER["PHP_SELF"], "d.datefin", $param, "", 'align="center"', $sortfield, $sortorder); |
|
257 | 257 | print "</tr>\n"; |
258 | 258 | |
259 | - $i=0; |
|
259 | + $i = 0; |
|
260 | 260 | while ($i < $num && $i < $conf->liste_limit) |
261 | 261 | { |
262 | 262 | $objp = $db->fetch_object($resql); |
263 | 263 | |
264 | - $datefin=$db->jdate($objp->datefin); |
|
265 | - $memberstatic->id=$objp->rowid; |
|
266 | - $memberstatic->ref=$objp->rowid; |
|
267 | - $memberstatic->lastname=$objp->lastname; |
|
268 | - $memberstatic->firstname=$objp->firstname; |
|
269 | - $memberstatic->statut=$objp->statut; |
|
270 | - $memberstatic->datefin=$db->jdate($objp->datefin); |
|
264 | + $datefin = $db->jdate($objp->datefin); |
|
265 | + $memberstatic->id = $objp->rowid; |
|
266 | + $memberstatic->ref = $objp->rowid; |
|
267 | + $memberstatic->lastname = $objp->lastname; |
|
268 | + $memberstatic->firstname = $objp->firstname; |
|
269 | + $memberstatic->statut = $objp->statut; |
|
270 | + $memberstatic->datefin = $db->jdate($objp->datefin); |
|
271 | 271 | |
272 | - $companyname=$objp->company; |
|
272 | + $companyname = $objp->company; |
|
273 | 273 | |
274 | 274 | print '<tr class="oddeven">'; |
275 | 275 | |
@@ -280,37 +280,37 @@ discard block |
||
280 | 280 | |
281 | 281 | // Lastname |
282 | 282 | print "<td><a href=\"card.php?rowid=$objp->rowid\">"; |
283 | - print ((! empty($objp->lastname) || ! empty($objp->firstname)) ? dol_trunc($memberstatic->getFullName($langs)) : ''); |
|
284 | - print (((! empty($objp->lastname) || ! empty($objp->firstname)) && ! empty($companyname)) ? ' / ' : ''); |
|
285 | - print (! empty($companyname) ? dol_trunc($companyname, 32) : ''); |
|
283 | + print ((!empty($objp->lastname) || !empty($objp->firstname)) ? dol_trunc($memberstatic->getFullName($langs)) : ''); |
|
284 | + print (((!empty($objp->lastname) || !empty($objp->firstname)) && !empty($companyname)) ? ' / ' : ''); |
|
285 | + print (!empty($companyname) ? dol_trunc($companyname, 32) : ''); |
|
286 | 286 | print "</a></td>\n"; |
287 | 287 | |
288 | 288 | // Login |
289 | 289 | print "<td>".$objp->login."</td>\n"; |
290 | 290 | |
291 | 291 | // Type |
292 | - $membertypestatic->id=$objp->type_id; |
|
293 | - $membertypestatic->libelle=$objp->type; |
|
292 | + $membertypestatic->id = $objp->type_id; |
|
293 | + $membertypestatic->libelle = $objp->type; |
|
294 | 294 | print '<td class="nowrap">'; |
295 | - print $membertypestatic->getNomUrl(1,32); |
|
295 | + print $membertypestatic->getNomUrl(1, 32); |
|
296 | 296 | print '</td>'; |
297 | 297 | |
298 | 298 | // Moral/Physique |
299 | 299 | print "<td>".$memberstatic->getmorphylib($objp->morphy)."</td>\n"; |
300 | 300 | |
301 | 301 | |
302 | - print "<td>".dol_print_email($objp->email,0,0,1)."</td>\n"; |
|
302 | + print "<td>".dol_print_email($objp->email, 0, 0, 1)."</td>\n"; |
|
303 | 303 | |
304 | 304 | // Statut |
305 | 305 | print '<td class="nowrap">'; |
306 | - print $memberstatic->LibStatut($objp->statut,$objp->subscription,$datefin,2); |
|
306 | + print $memberstatic->LibStatut($objp->statut, $objp->subscription, $datefin, 2); |
|
307 | 307 | print "</td>"; |
308 | 308 | |
309 | 309 | // End of subscription date |
310 | 310 | if ($datefin) |
311 | 311 | { |
312 | 312 | print '<td align="center" class="nowrap">'; |
313 | - print dol_print_date($datefin,'day'); |
|
313 | + print dol_print_date($datefin, 'day'); |
|
314 | 314 | if ($memberstatic->hasDelay()) { |
315 | 315 | print " ".img_warning($langs->trans("SubscriptionLate")); |
316 | 316 | } |
@@ -62,23 +62,23 @@ discard block |
||
62 | 62 | |
63 | 63 | if ($socid) |
64 | 64 | { |
65 | - require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; |
|
66 | - require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; |
|
65 | + require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; |
|
66 | + require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; |
|
67 | 67 | |
68 | - $langs->load("companies"); |
|
68 | + $langs->load("companies"); |
|
69 | 69 | |
70 | 70 | |
71 | - $object = new Societe($db); |
|
72 | - $result = $object->fetch($socid); |
|
71 | + $object = new Societe($db); |
|
72 | + $result = $object->fetch($socid); |
|
73 | 73 | |
74 | - $title=$langs->trans("Projects"); |
|
75 | - if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title; |
|
76 | - llxHeader('',$title); |
|
74 | + $title=$langs->trans("Projects"); |
|
75 | + if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title; |
|
76 | + llxHeader('',$title); |
|
77 | 77 | |
78 | - if (! empty($conf->notification->enabled)) $langs->load("mails"); |
|
79 | - $head = societe_prepare_head($object); |
|
78 | + if (! empty($conf->notification->enabled)) $langs->load("mails"); |
|
79 | + $head = societe_prepare_head($object); |
|
80 | 80 | |
81 | - dol_fiche_head($head, 'project', $langs->trans("ThirdParty"), -1, 'company'); |
|
81 | + dol_fiche_head($head, 'project', $langs->trans("ThirdParty"), -1, 'company'); |
|
82 | 82 | |
83 | 83 | $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>'; |
84 | 84 | |
@@ -87,36 +87,36 @@ discard block |
||
87 | 87 | print '<div class="fichecenter">'; |
88 | 88 | |
89 | 89 | print '<div class="underbanner clearboth"></div>'; |
90 | - print '<table class="border centpercent">'; |
|
90 | + print '<table class="border centpercent">'; |
|
91 | 91 | |
92 | 92 | if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field |
93 | 93 | { |
94 | 94 | print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>'; |
95 | 95 | } |
96 | 96 | |
97 | - if ($object->client) |
|
98 | - { |
|
99 | - print '<tr><td class="titlefield">'; |
|
100 | - print $langs->trans('CustomerCode').'</td><td colspan="3">'; |
|
101 | - print $object->code_client; |
|
102 | - if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>'; |
|
103 | - print '</td></tr>'; |
|
104 | - } |
|
97 | + if ($object->client) |
|
98 | + { |
|
99 | + print '<tr><td class="titlefield">'; |
|
100 | + print $langs->trans('CustomerCode').'</td><td colspan="3">'; |
|
101 | + print $object->code_client; |
|
102 | + if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>'; |
|
103 | + print '</td></tr>'; |
|
104 | + } |
|
105 | 105 | |
106 | - if ($object->fournisseur) |
|
107 | - { |
|
108 | - print '<tr><td class="titlefield">'; |
|
109 | - print $langs->trans('SupplierCode').'</td><td colspan="3">'; |
|
110 | - print $object->code_fournisseur; |
|
111 | - if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>'; |
|
112 | - print '</td></tr>'; |
|
113 | - } |
|
106 | + if ($object->fournisseur) |
|
107 | + { |
|
108 | + print '<tr><td class="titlefield">'; |
|
109 | + print $langs->trans('SupplierCode').'</td><td colspan="3">'; |
|
110 | + print $object->code_fournisseur; |
|
111 | + if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>'; |
|
112 | + print '</td></tr>'; |
|
113 | + } |
|
114 | 114 | |
115 | - print '</table>'; |
|
115 | + print '</table>'; |
|
116 | 116 | |
117 | - print '</div>'; |
|
117 | + print '</div>'; |
|
118 | 118 | |
119 | - dol_fiche_end(); |
|
119 | + dol_fiche_end(); |
|
120 | 120 | |
121 | 121 | |
122 | 122 | /* |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | { |
130 | 130 | if (! empty($conf->projet->enabled) && ! empty($user->rights->projet->creer)) |
131 | 131 | {*/ |
132 | - $addbutton = '<a href="'.DOL_URL_ROOT.'/projet/card.php?action=create&socid='.$object->id.'&backtopage='.urlencode($backtopage).'">'.$langs->trans("AddProject").'</a>'; |
|
132 | + $addbutton = '<a href="'.DOL_URL_ROOT.'/projet/card.php?action=create&socid='.$object->id.'&backtopage='.urlencode($backtopage).'">'.$langs->trans("AddProject").'</a>'; |
|
133 | 133 | /* } |
134 | 134 | else |
135 | 135 | { |
@@ -142,8 +142,8 @@ discard block |
||
142 | 142 | print '<br>'; |
143 | 143 | |
144 | 144 | |
145 | - // Projects list |
|
146 | - $result=show_projects($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id, 1, $addbutton); |
|
145 | + // Projects list |
|
146 | + $result=show_projects($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id, 1, $addbutton); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | // End of page |
@@ -35,7 +35,9 @@ discard block |
||
35 | 35 | |
36 | 36 | // Security check |
37 | 37 | $socid = GETPOST('socid','int'); |
38 | -if ($user->societe_id) $socid=$user->societe_id; |
|
38 | +if ($user->societe_id) { |
|
39 | + $socid=$user->societe_id; |
|
40 | +} |
|
39 | 41 | $result = restrictedArea($user, 'societe', $socid, '&societe'); |
40 | 42 | |
41 | 43 | // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context |
@@ -48,7 +50,9 @@ discard block |
||
48 | 50 | |
49 | 51 | $parameters=array('id'=>$socid); |
50 | 52 | $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
51 | -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
|
53 | +if ($reshook < 0) { |
|
54 | + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
|
55 | +} |
|
52 | 56 | |
53 | 57 | |
54 | 58 | |
@@ -72,10 +76,14 @@ discard block |
||
72 | 76 | $result = $object->fetch($socid); |
73 | 77 | |
74 | 78 | $title=$langs->trans("Projects"); |
75 | - if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title; |
|
79 | + if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) { |
|
80 | + $title=$object->name." - ".$title; |
|
81 | + } |
|
76 | 82 | llxHeader('',$title); |
77 | 83 | |
78 | - if (! empty($conf->notification->enabled)) $langs->load("mails"); |
|
84 | + if (! empty($conf->notification->enabled)) { |
|
85 | + $langs->load("mails"); |
|
86 | + } |
|
79 | 87 | $head = societe_prepare_head($object); |
80 | 88 | |
81 | 89 | dol_fiche_head($head, 'project', $langs->trans("ThirdParty"), -1, 'company'); |
@@ -89,17 +97,21 @@ discard block |
||
89 | 97 | print '<div class="underbanner clearboth"></div>'; |
90 | 98 | print '<table class="border centpercent">'; |
91 | 99 | |
92 | - if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field |
|
100 | + if (! empty($conf->global->SOCIETE_USEPREFIX)) { |
|
101 | + // Old not used prefix field |
|
93 | 102 | { |
94 | 103 | print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>'; |
95 | 104 | } |
105 | + } |
|
96 | 106 | |
97 | 107 | if ($object->client) |
98 | 108 | { |
99 | 109 | print '<tr><td class="titlefield">'; |
100 | 110 | print $langs->trans('CustomerCode').'</td><td colspan="3">'; |
101 | 111 | print $object->code_client; |
102 | - if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>'; |
|
112 | + if ($object->check_codeclient() <> 0) { |
|
113 | + print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>'; |
|
114 | + } |
|
103 | 115 | print '</td></tr>'; |
104 | 116 | } |
105 | 117 | |
@@ -108,7 +120,9 @@ discard block |
||
108 | 120 | print '<tr><td class="titlefield">'; |
109 | 121 | print $langs->trans('SupplierCode').'</td><td colspan="3">'; |
110 | 122 | print $object->code_fournisseur; |
111 | - if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>'; |
|
123 | + if ($object->check_codefournisseur() <> 0) { |
|
124 | + print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>'; |
|
125 | + } |
|
112 | 126 | print '</td></tr>'; |
113 | 127 | } |
114 | 128 |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | |
31 | 31 | // Copyright (C) 2018 Alxarafe/Alixar <[email protected]> |
32 | 32 | defined('BASE_PATH') or die('Single entry point through the index.php of the main folder'); |
33 | -require DOL_BASE_PATH . '/main.inc.php'; |
|
33 | +require DOL_BASE_PATH.'/main.inc.php'; |
|
34 | 34 | |
35 | 35 | require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
36 | 36 | require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | $langs->loadLangs(array("companies", "projects")); |
39 | 39 | |
40 | 40 | // Security check |
41 | -$socid = GETPOST('socid','int'); |
|
42 | -if ($user->societe_id) $socid=$user->societe_id; |
|
41 | +$socid = GETPOST('socid', 'int'); |
|
42 | +if ($user->societe_id) $socid = $user->societe_id; |
|
43 | 43 | $result = restrictedArea($user, 'societe', $socid, '&societe'); |
44 | 44 | |
45 | 45 | // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context |
@@ -50,8 +50,8 @@ discard block |
||
50 | 50 | * Actions |
51 | 51 | */ |
52 | 52 | |
53 | -$parameters=array('id'=>$socid); |
|
54 | -$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
53 | +$parameters = array('id'=>$socid); |
|
54 | +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
|
55 | 55 | if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
56 | 56 | |
57 | 57 | |
@@ -75,25 +75,25 @@ discard block |
||
75 | 75 | $object = new Societe($db); |
76 | 76 | $result = $object->fetch($socid); |
77 | 77 | |
78 | - $title=$langs->trans("Projects"); |
|
79 | - if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title; |
|
80 | - llxHeader('',$title); |
|
78 | + $title = $langs->trans("Projects"); |
|
79 | + if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) $title = $object->name." - ".$title; |
|
80 | + llxHeader('', $title); |
|
81 | 81 | |
82 | - if (! empty($conf->notification->enabled)) $langs->load("mails"); |
|
82 | + if (!empty($conf->notification->enabled)) $langs->load("mails"); |
|
83 | 83 | $head = societe_prepare_head($object); |
84 | 84 | |
85 | 85 | dol_fiche_head($head, 'project', $langs->trans("ThirdParty"), -1, 'company'); |
86 | 86 | |
87 | 87 | $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>'; |
88 | 88 | |
89 | - dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom'); |
|
89 | + dol_banner_tab($object, 'socid', $linkback, ($user->societe_id ? 0 : 1), 'rowid', 'nom'); |
|
90 | 90 | |
91 | 91 | print '<div class="fichecenter">'; |
92 | 92 | |
93 | 93 | print '<div class="underbanner clearboth"></div>'; |
94 | 94 | print '<table class="border centpercent">'; |
95 | 95 | |
96 | - if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field |
|
96 | + if (!empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field |
|
97 | 97 | { |
98 | 98 | print '<tr><td>'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>'; |
99 | 99 | } |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | |
148 | 148 | |
149 | 149 | // Projects list |
150 | - $result=show_projects($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id, 1, $addbutton); |
|
150 | + $result = show_projects($conf, $langs, $db, $object, $_SERVER["PHP_SELF"].'?socid='.$object->id, 1, $addbutton); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | // End of page |
@@ -78,12 +78,12 @@ discard block |
||
78 | 78 | { |
79 | 79 | if (empty($contactid)) |
80 | 80 | { |
81 | - setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Contact")), null, 'errors'); |
|
81 | + setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Contact")), null, 'errors'); |
|
82 | 82 | $error++; |
83 | 83 | } |
84 | 84 | if ($actionid <= 0) |
85 | 85 | { |
86 | - setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Action")), null, 'errors'); |
|
86 | + setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Action")), null, 'errors'); |
|
87 | 87 | $error++; |
88 | 88 | } |
89 | 89 | |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | print '<br>'.$langs->trans("NotificationsDescUser"); |
213 | 213 | print '<br>'.$langs->trans("NotificationsDescContact"); |
214 | 214 | print '<br>'.$langs->trans("NotificationsDescGlobal"); |
215 | - print '</div>'; |
|
215 | + print '</div>'; |
|
216 | 216 | |
217 | 217 | print '<br><br>'."\n"; |
218 | 218 | |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | print_liste_field_titre("Action",$_SERVER["PHP_SELF"],"",'',$param,'"width="35%"',$sortfield,$sortorder); |
234 | 234 | print_liste_field_titre("Type",$_SERVER["PHP_SELF"],"n.type",'',$param,'"width="10%"',$sortfield,$sortorder); |
235 | 235 | print_liste_field_titre(''); |
236 | - print "</tr>\n"; |
|
236 | + print "</tr>\n"; |
|
237 | 237 | |
238 | 238 | $var=false; |
239 | 239 | $listofemails=$object->thirdparty_and_contact_email_array(); |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | |
248 | 248 | foreach($listofmanagedeventfornotification as $managedeventfornotification) |
249 | 249 | { |
250 | - $label=($langs->trans("Notify_".$managedeventfornotification['code'])!="Notify_".$managedeventfornotification['code']?$langs->trans("Notify_".$managedeventfornotification['code']):$managedeventfornotification['label']); |
|
250 | + $label=($langs->trans("Notify_".$managedeventfornotification['code'])!="Notify_".$managedeventfornotification['code']?$langs->trans("Notify_".$managedeventfornotification['code']):$managedeventfornotification['label']); |
|
251 | 251 | $actions[$managedeventfornotification['rowid']]=$label; |
252 | 252 | } |
253 | 253 | print '<tr class="oddeven"><td class="maxwidthonsmartphone">'; |
@@ -310,8 +310,8 @@ discard block |
||
310 | 310 | print_liste_field_titre('','',''); |
311 | 311 | print '</tr>'; |
312 | 312 | |
313 | - $langs->load("errors"); |
|
314 | - $langs->load("other"); |
|
313 | + $langs->load("errors"); |
|
314 | + $langs->load("other"); |
|
315 | 315 | |
316 | 316 | if ($num) |
317 | 317 | { |
@@ -431,8 +431,8 @@ discard block |
||
431 | 431 | $nbtotalofrecords = $db->num_rows($result); |
432 | 432 | if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0 |
433 | 433 | { |
434 | - $page = 0; |
|
435 | - $offset = 0; |
|
434 | + $page = 0; |
|
435 | + $offset = 0; |
|
436 | 436 | } |
437 | 437 | } |
438 | 438 | |
@@ -487,15 +487,15 @@ discard block |
||
487 | 487 | print '<tr class="oddeven"><td>'; |
488 | 488 | if ($obj->id > 0) |
489 | 489 | { |
490 | - $contactstatic->id=$obj->id; |
|
491 | - $contactstatic->lastname=$obj->lastname; |
|
492 | - $contactstatic->firstname=$obj->firstname; |
|
493 | - print $contactstatic->getNomUrl(1); |
|
494 | - print $obj->email?' <'.$obj->email.'>':$langs->trans("NoMail"); |
|
490 | + $contactstatic->id=$obj->id; |
|
491 | + $contactstatic->lastname=$obj->lastname; |
|
492 | + $contactstatic->firstname=$obj->firstname; |
|
493 | + print $contactstatic->getNomUrl(1); |
|
494 | + print $obj->email?' <'.$obj->email.'>':$langs->trans("NoMail"); |
|
495 | 495 | } |
496 | 496 | else |
497 | - { |
|
498 | - print $obj->email; |
|
497 | + { |
|
498 | + print $obj->email; |
|
499 | 499 | } |
500 | 500 | print '</td>'; |
501 | 501 | print '<td>'; |
@@ -38,15 +38,21 @@ discard block |
||
38 | 38 | $actionid=GETPOST('actionid'); |
39 | 39 | |
40 | 40 | // Security check |
41 | -if ($user->societe_id) $socid=$user->societe_id; |
|
41 | +if ($user->societe_id) { |
|
42 | + $socid=$user->societe_id; |
|
43 | +} |
|
42 | 44 | $result = restrictedArea($user, 'societe','',''); |
43 | 45 | |
44 | 46 | $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; |
45 | 47 | $sortfield=GETPOST("sortfield",'alpha'); |
46 | 48 | $sortorder=GETPOST("sortorder",'alpha'); |
47 | 49 | $page=GETPOST("page",'int'); |
48 | -if (! $sortorder) $sortorder="DESC"; |
|
49 | -if (! $sortfield) $sortfield="n.daten"; |
|
50 | +if (! $sortorder) { |
|
51 | + $sortorder="DESC"; |
|
52 | +} |
|
53 | +if (! $sortfield) { |
|
54 | + $sortfield="n.daten"; |
|
55 | +} |
|
50 | 56 | if (empty($page) || $page == -1) { $page = 0; } |
51 | 57 | $offset = $limit * $page; |
52 | 58 | $pageprev = $page - 1; |
@@ -67,7 +73,9 @@ discard block |
||
67 | 73 | |
68 | 74 | $parameters=array('id'=>$socid); |
69 | 75 | $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
70 | -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
|
76 | +if ($reshook < 0) { |
|
77 | + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
|
78 | +} |
|
71 | 79 | |
72 | 80 | if (empty($reshook)) |
73 | 81 | { |
@@ -103,8 +111,7 @@ discard block |
||
103 | 111 | $error++; |
104 | 112 | dol_print_error($db); |
105 | 113 | } |
106 | - } |
|
107 | - else |
|
114 | + } else |
|
108 | 115 | { |
109 | 116 | dol_print_error($db); |
110 | 117 | } |
@@ -112,8 +119,7 @@ discard block |
||
112 | 119 | if (! $error) |
113 | 120 | { |
114 | 121 | $db->commit(); |
115 | - } |
|
116 | - else |
|
122 | + } else |
|
117 | 123 | { |
118 | 124 | $db->rollback(); |
119 | 125 | } |
@@ -140,7 +146,9 @@ discard block |
||
140 | 146 | $result=$object->fetch($socid); |
141 | 147 | |
142 | 148 | $title=$langs->trans("ThirdParty").' - '.$langs->trans("Notification"); |
143 | -if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name.' - '.$langs->trans("Notification"); |
|
149 | +if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) { |
|
150 | + $title=$object->name.' - '.$langs->trans("Notification"); |
|
151 | +} |
|
144 | 152 | $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; |
145 | 153 | llxHeader('',$title,$help_url); |
146 | 154 | |
@@ -163,17 +171,21 @@ discard block |
||
163 | 171 | print '<table class="border centpercent">'; |
164 | 172 | |
165 | 173 | // Prefix |
166 | - if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field |
|
174 | + if (! empty($conf->global->SOCIETE_USEPREFIX)) { |
|
175 | + // Old not used prefix field |
|
167 | 176 | { |
168 | 177 | print '<tr><td class="titlefield">'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>'; |
169 | 178 | } |
179 | + } |
|
170 | 180 | |
171 | 181 | if ($object->client) |
172 | 182 | { |
173 | 183 | print '<tr><td class="titlefield">'; |
174 | 184 | print $langs->trans('CustomerCode').'</td><td colspan="3">'; |
175 | 185 | print $object->code_client; |
176 | - if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>'; |
|
186 | + if ($object->check_codeclient() <> 0) { |
|
187 | + print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>'; |
|
188 | + } |
|
177 | 189 | print '</td></tr>'; |
178 | 190 | } |
179 | 191 | |
@@ -182,7 +194,9 @@ discard block |
||
182 | 194 | print '<tr><td class="titlefield">'; |
183 | 195 | print $langs->trans('SupplierCode').'</td><td colspan="3">'; |
184 | 196 | print $object->code_fournisseur; |
185 | - if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>'; |
|
197 | + if ($object->check_codefournisseur() <> 0) { |
|
198 | + print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>'; |
|
199 | + } |
|
186 | 200 | print '</td></tr>'; |
187 | 201 | } |
188 | 202 | |
@@ -262,8 +276,7 @@ discard block |
||
262 | 276 | print '</td>'; |
263 | 277 | print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>'; |
264 | 278 | print '</tr>'; |
265 | - } |
|
266 | - else |
|
279 | + } else |
|
267 | 280 | { |
268 | 281 | print '<tr class="oddeven"><td colspan="4" class="opacitymedium">'; |
269 | 282 | print $langs->trans("YouMustCreateContactFirst"); |
@@ -292,8 +305,7 @@ discard block |
||
292 | 305 | if ($resql) |
293 | 306 | { |
294 | 307 | $num = $db->num_rows($resql); |
295 | - } |
|
296 | - else |
|
308 | + } else |
|
297 | 309 | { |
298 | 310 | dol_print_error($db); |
299 | 311 | } |
@@ -332,8 +344,7 @@ discard block |
||
332 | 344 | if (isValidEmail($obj->email)) |
333 | 345 | { |
334 | 346 | print ' <'.$obj->email.'>'; |
335 | - } |
|
336 | - else |
|
347 | + } else |
|
337 | 348 | { |
338 | 349 | $langs->load("errors"); |
339 | 350 | print ' '.img_warning().' '.$langs->trans("ErrorBadEMail",$obj->email); |
@@ -345,8 +356,12 @@ discard block |
||
345 | 356 | print $label; |
346 | 357 | print '</td>'; |
347 | 358 | print '<td>'; |
348 | - if ($obj->type == 'email') print $langs->trans("Email"); |
|
349 | - if ($obj->type == 'sms') print $langs->trans("SMS"); |
|
359 | + if ($obj->type == 'email') { |
|
360 | + print $langs->trans("Email"); |
|
361 | + } |
|
362 | + if ($obj->type == 'sms') { |
|
363 | + print $langs->trans("SMS"); |
|
364 | + } |
|
350 | 365 | print '</td>'; |
351 | 366 | print '<td align="right"><a href="card.php?socid='.$socid.'&action=delete&actid='.$obj->rowid.'">'.img_delete().'</a></td>'; |
352 | 367 | print '</tr>'; |
@@ -429,9 +444,11 @@ discard block |
||
429 | 444 | { |
430 | 445 | $result = $db->query($sql); |
431 | 446 | $nbtotalofrecords = $db->num_rows($result); |
432 | - if (($page * $limit) > $nbtotalofrecords) // if total resultset is smaller then paging size (filtering), goto and load page 0 |
|
447 | + if (($page * $limit) > $nbtotalofrecords) { |
|
448 | + // if total resultset is smaller then paging size (filtering), goto and load page 0 |
|
433 | 449 | { |
434 | 450 | $page = 0; |
451 | + } |
|
435 | 452 | $offset = 0; |
436 | 453 | } |
437 | 454 | } |
@@ -442,18 +459,23 @@ discard block |
||
442 | 459 | if ($resql) |
443 | 460 | { |
444 | 461 | $num = $db->num_rows($resql); |
445 | - } |
|
446 | - else |
|
462 | + } else |
|
447 | 463 | { |
448 | 464 | dol_print_error($db); |
449 | 465 | } |
450 | 466 | |
451 | 467 | $param='&socid='.$object->id; |
452 | - if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; |
|
453 | - if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; |
|
468 | + if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { |
|
469 | + $param.='&contextpage='.$contextpage; |
|
470 | + } |
|
471 | + if ($limit > 0 && $limit != $conf->liste_limit) { |
|
472 | + $param.='&limit='.$limit; |
|
473 | + } |
|
454 | 474 | |
455 | 475 | print '<form method="post" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">'; |
456 | - if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">'; |
|
476 | + if ($optioncss != '') { |
|
477 | + print '<input type="hidden" name="optioncss" value="'.$optioncss.'">'; |
|
478 | + } |
|
457 | 479 | print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
458 | 480 | print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">'; |
459 | 481 | print '<input type="hidden" name="sortfield" value="'.$sortfield.'">'; |
@@ -492,8 +514,7 @@ discard block |
||
492 | 514 | $contactstatic->firstname=$obj->firstname; |
493 | 515 | print $contactstatic->getNomUrl(1); |
494 | 516 | print $obj->email?' <'.$obj->email.'>':$langs->trans("NoMail"); |
495 | - } |
|
496 | - else |
|
517 | + } else |
|
497 | 518 | { |
498 | 519 | print $obj->email; |
499 | 520 | } |
@@ -503,8 +524,12 @@ discard block |
||
503 | 524 | print $label; |
504 | 525 | print '</td>'; |
505 | 526 | print '<td>'; |
506 | - if ($obj->type == 'email') print $langs->trans("Email"); |
|
507 | - if ($obj->type == 'sms') print $langs->trans("Sms"); |
|
527 | + if ($obj->type == 'email') { |
|
528 | + print $langs->trans("Email"); |
|
529 | + } |
|
530 | + if ($obj->type == 'sms') { |
|
531 | + print $langs->trans("Sms"); |
|
532 | + } |
|
508 | 533 | print '</td>'; |
509 | 534 | // TODO Add link to object here for other types |
510 | 535 | /*print '<td>'; |
@@ -526,8 +551,9 @@ discard block |
||
526 | 551 | print '</table>'; |
527 | 552 | |
528 | 553 | print '</form>'; |
554 | +} else { |
|
555 | + dol_print_error('','RecordNotFound'); |
|
529 | 556 | } |
530 | -else dol_print_error('','RecordNotFound'); |
|
531 | 557 | |
532 | 558 | // End of page |
533 | 559 | llxFooter(); |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | |
28 | 28 | // Copyright (C) 2018 Alxarafe/Alixar <[email protected]> |
29 | 29 | defined('BASE_PATH') or die('Single entry point through the index.php of the main folder'); |
30 | -require DOL_BASE_PATH . '/main.inc.php'; |
|
30 | +require DOL_BASE_PATH.'/main.inc.php'; |
|
31 | 31 | require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php'; |
32 | 32 | require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; |
33 | 33 | require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
@@ -35,32 +35,32 @@ discard block |
||
35 | 35 | |
36 | 36 | $langs->loadLangs(array("companies", "mails", "admin", "other")); |
37 | 37 | |
38 | -$socid = GETPOST("socid",'int'); |
|
39 | -$action = GETPOST('action','aZ09'); |
|
40 | -$contactid=GETPOST('contactid'); // May be an int or 'thirdparty' |
|
41 | -$actionid=GETPOST('actionid'); |
|
38 | +$socid = GETPOST("socid", 'int'); |
|
39 | +$action = GETPOST('action', 'aZ09'); |
|
40 | +$contactid = GETPOST('contactid'); // May be an int or 'thirdparty' |
|
41 | +$actionid = GETPOST('actionid'); |
|
42 | 42 | |
43 | 43 | // Security check |
44 | -if ($user->societe_id) $socid=$user->societe_id; |
|
45 | -$result = restrictedArea($user, 'societe','',''); |
|
46 | - |
|
47 | -$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; |
|
48 | -$sortfield=GETPOST("sortfield",'alpha'); |
|
49 | -$sortorder=GETPOST("sortorder",'alpha'); |
|
50 | -$page=GETPOST("page",'int'); |
|
51 | -if (! $sortorder) $sortorder="DESC"; |
|
52 | -if (! $sortfield) $sortfield="n.daten"; |
|
44 | +if ($user->societe_id) $socid = $user->societe_id; |
|
45 | +$result = restrictedArea($user, 'societe', '', ''); |
|
46 | + |
|
47 | +$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; |
|
48 | +$sortfield = GETPOST("sortfield", 'alpha'); |
|
49 | +$sortorder = GETPOST("sortorder", 'alpha'); |
|
50 | +$page = GETPOST("page", 'int'); |
|
51 | +if (!$sortorder) $sortorder = "DESC"; |
|
52 | +if (!$sortfield) $sortfield = "n.daten"; |
|
53 | 53 | if (empty($page) || $page == -1) { $page = 0; } |
54 | 54 | $offset = $limit * $page; |
55 | 55 | $pageprev = $page - 1; |
56 | 56 | $pagenext = $page + 1; |
57 | 57 | |
58 | -$now=dol_now(); |
|
58 | +$now = dol_now(); |
|
59 | 59 | |
60 | 60 | $object = new Societe($db); |
61 | 61 | |
62 | 62 | // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context |
63 | -$hookmanager->initHooks(array('thirdpartynotification','globalcard')); |
|
63 | +$hookmanager->initHooks(array('thirdpartynotification', 'globalcard')); |
|
64 | 64 | |
65 | 65 | |
66 | 66 | |
@@ -68,29 +68,29 @@ discard block |
||
68 | 68 | * Actions |
69 | 69 | */ |
70 | 70 | |
71 | -$parameters=array('id'=>$socid); |
|
72 | -$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
71 | +$parameters = array('id'=>$socid); |
|
72 | +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
|
73 | 73 | if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
74 | 74 | |
75 | 75 | if (empty($reshook)) |
76 | 76 | { |
77 | - $error=0; |
|
77 | + $error = 0; |
|
78 | 78 | |
79 | 79 | // Add a notification |
80 | 80 | if ($action == 'add') |
81 | 81 | { |
82 | 82 | if (empty($contactid)) |
83 | 83 | { |
84 | - setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Contact")), null, 'errors'); |
|
84 | + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Contact")), null, 'errors'); |
|
85 | 85 | $error++; |
86 | 86 | } |
87 | 87 | if ($actionid <= 0) |
88 | 88 | { |
89 | - setEventMessages($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Action")), null, 'errors'); |
|
89 | + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Action")), null, 'errors'); |
|
90 | 90 | $error++; |
91 | 91 | } |
92 | 92 | |
93 | - if (! $error) |
|
93 | + if (!$error) |
|
94 | 94 | { |
95 | 95 | $db->begin(); |
96 | 96 | |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify_def (datec,fk_soc, fk_contact, fk_action)"; |
102 | 102 | $sql .= " VALUES ('".$db->idate($now)."',".$socid.",".$contactid.",".$actionid.")"; |
103 | 103 | |
104 | - if (! $db->query($sql)) |
|
104 | + if (!$db->query($sql)) |
|
105 | 105 | { |
106 | 106 | $error++; |
107 | 107 | dol_print_error($db); |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | dol_print_error($db); |
113 | 113 | } |
114 | 114 | |
115 | - if (! $error) |
|
115 | + if (!$error) |
|
116 | 116 | { |
117 | 117 | $db->commit(); |
118 | 118 | } |
@@ -140,12 +140,12 @@ discard block |
||
140 | 140 | $form = new Form($db); |
141 | 141 | |
142 | 142 | $object = new Societe($db); |
143 | -$result=$object->fetch($socid); |
|
143 | +$result = $object->fetch($socid); |
|
144 | 144 | |
145 | -$title=$langs->trans("ThirdParty").' - '.$langs->trans("Notification"); |
|
146 | -if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name.' - '.$langs->trans("Notification"); |
|
147 | -$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; |
|
148 | -llxHeader('',$title,$help_url); |
|
145 | +$title = $langs->trans("ThirdParty").' - '.$langs->trans("Notification"); |
|
146 | +if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) $title = $object->name.' - '.$langs->trans("Notification"); |
|
147 | +$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; |
|
148 | +llxHeader('', $title, $help_url); |
|
149 | 149 | |
150 | 150 | |
151 | 151 | if ($result > 0) |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | |
159 | 159 | $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>'; |
160 | 160 | |
161 | - dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom'); |
|
161 | + dol_banner_tab($object, 'socid', $linkback, ($user->societe_id ? 0 : 1), 'rowid', 'nom'); |
|
162 | 162 | |
163 | 163 | print '<div class="fichecenter">'; |
164 | 164 | |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | print '<table class="border centpercent">'; |
167 | 167 | |
168 | 168 | // Prefix |
169 | - if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field |
|
169 | + if (!empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field |
|
170 | 170 | { |
171 | 171 | print '<tr><td class="titlefield">'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>'; |
172 | 172 | } |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | print '</td></tr>'; |
181 | 181 | } |
182 | 182 | |
183 | - if (! empty($conf->fournisseur->enabled) && $object->fournisseur && ! empty($user->rights->fournisseur->lire)) |
|
183 | + if (!empty($conf->fournisseur->enabled) && $object->fournisseur && !empty($user->rights->fournisseur->lire)) |
|
184 | 184 | { |
185 | 185 | print '<tr><td class="titlefield">'; |
186 | 186 | print $langs->trans('SupplierCode').'</td><td colspan="3">'; |
@@ -221,37 +221,37 @@ discard block |
||
221 | 221 | |
222 | 222 | |
223 | 223 | // Add notification form |
224 | - print load_fiche_titre($langs->trans("AddNewNotification"),'',''); |
|
224 | + print load_fiche_titre($langs->trans("AddNewNotification"), '', ''); |
|
225 | 225 | |
226 | 226 | print '<form action="'.$_SERVER["PHP_SELF"].'?socid='.$socid.'" method="post">'; |
227 | 227 | print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
228 | 228 | print '<input type="hidden" name="action" value="add">'; |
229 | 229 | |
230 | - $param="&socid=".$socid; |
|
230 | + $param = "&socid=".$socid; |
|
231 | 231 | |
232 | 232 | // Line with titles |
233 | 233 | print '<table width="100%" class="noborder">'; |
234 | 234 | print '<tr class="liste_titre">'; |
235 | - print_liste_field_titre("Target",$_SERVER["PHP_SELF"],"c.lastname,c.firstname",'',$param,'"width="45%"',$sortfield,$sortorder); |
|
236 | - print_liste_field_titre("Action",$_SERVER["PHP_SELF"],"",'',$param,'"width="35%"',$sortfield,$sortorder); |
|
237 | - print_liste_field_titre("Type",$_SERVER["PHP_SELF"],"n.type",'',$param,'"width="10%"',$sortfield,$sortorder); |
|
235 | + print_liste_field_titre("Target", $_SERVER["PHP_SELF"], "c.lastname,c.firstname", '', $param, '"width="45%"', $sortfield, $sortorder); |
|
236 | + print_liste_field_titre("Action", $_SERVER["PHP_SELF"], "", '', $param, '"width="35%"', $sortfield, $sortorder); |
|
237 | + print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "n.type", '', $param, '"width="10%"', $sortfield, $sortorder); |
|
238 | 238 | print_liste_field_titre(''); |
239 | 239 | print "</tr>\n"; |
240 | 240 | |
241 | - $var=false; |
|
242 | - $listofemails=$object->thirdparty_and_contact_email_array(); |
|
241 | + $var = false; |
|
242 | + $listofemails = $object->thirdparty_and_contact_email_array(); |
|
243 | 243 | if (count($listofemails) > 0) |
244 | 244 | { |
245 | - $actions=array(); |
|
245 | + $actions = array(); |
|
246 | 246 | |
247 | 247 | // Load array of available notifications |
248 | - $notificationtrigger=new InterfaceNotification($db); |
|
249 | - $listofmanagedeventfornotification=$notificationtrigger->getListOfManagedEvents(); |
|
248 | + $notificationtrigger = new InterfaceNotification($db); |
|
249 | + $listofmanagedeventfornotification = $notificationtrigger->getListOfManagedEvents(); |
|
250 | 250 | |
251 | - foreach($listofmanagedeventfornotification as $managedeventfornotification) |
|
251 | + foreach ($listofmanagedeventfornotification as $managedeventfornotification) |
|
252 | 252 | { |
253 | - $label=($langs->trans("Notify_".$managedeventfornotification['code'])!="Notify_".$managedeventfornotification['code']?$langs->trans("Notify_".$managedeventfornotification['code']):$managedeventfornotification['label']); |
|
254 | - $actions[$managedeventfornotification['rowid']]=$label; |
|
253 | + $label = ($langs->trans("Notify_".$managedeventfornotification['code']) != "Notify_".$managedeventfornotification['code'] ? $langs->trans("Notify_".$managedeventfornotification['code']) : $managedeventfornotification['label']); |
|
254 | + $actions[$managedeventfornotification['rowid']] = $label; |
|
255 | 255 | } |
256 | 256 | print '<tr class="oddeven"><td class="maxwidthonsmartphone">'; |
257 | 257 | print $form->selectarray("contactid", $listofemails, '', 0, 0, 0, '', 0, 0, 0, '', 'maxwidthonsmartphone'); |
@@ -260,8 +260,8 @@ discard block |
||
260 | 260 | print $form->selectarray("actionid", $actions, '', 1, 0, 0, '', 0, 0, 0, '', 'maxwidthonsmartphone'); |
261 | 261 | print '</td>'; |
262 | 262 | print '<td>'; |
263 | - $type=array('email'=>$langs->trans("EMail")); |
|
264 | - print $form->selectarray("typeid",$type); |
|
263 | + $type = array('email'=>$langs->trans("EMail")); |
|
264 | + print $form->selectarray("typeid", $type); |
|
265 | 265 | print '</td>'; |
266 | 266 | print '<td align="right"><input type="submit" class="button" value="'.$langs->trans("Add").'"></td>'; |
267 | 267 | print '</tr>'; |
@@ -282,16 +282,16 @@ discard block |
||
282 | 282 | |
283 | 283 | // List of notifications enabled for contacts |
284 | 284 | $sql = "SELECT n.rowid, n.type,"; |
285 | - $sql.= " a.code, a.label,"; |
|
286 | - $sql.= " c.rowid as contactid, c.lastname, c.firstname, c.email"; |
|
287 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,"; |
|
288 | - $sql.= " ".MAIN_DB_PREFIX."notify_def as n,"; |
|
289 | - $sql.= " ".MAIN_DB_PREFIX."socpeople c"; |
|
290 | - $sql.= " WHERE a.rowid = n.fk_action"; |
|
291 | - $sql.= " AND c.rowid = n.fk_contact"; |
|
292 | - $sql.= " AND c.fk_soc = ".$object->id; |
|
293 | - |
|
294 | - $resql=$db->query($sql); |
|
285 | + $sql .= " a.code, a.label,"; |
|
286 | + $sql .= " c.rowid as contactid, c.lastname, c.firstname, c.email"; |
|
287 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,"; |
|
288 | + $sql .= " ".MAIN_DB_PREFIX."notify_def as n,"; |
|
289 | + $sql .= " ".MAIN_DB_PREFIX."socpeople c"; |
|
290 | + $sql .= " WHERE a.rowid = n.fk_action"; |
|
291 | + $sql .= " AND c.rowid = n.fk_contact"; |
|
292 | + $sql .= " AND c.fk_soc = ".$object->id; |
|
293 | + |
|
294 | + $resql = $db->query($sql); |
|
295 | 295 | if ($resql) |
296 | 296 | { |
297 | 297 | $num = $db->num_rows($resql); |
@@ -302,15 +302,15 @@ discard block |
||
302 | 302 | } |
303 | 303 | |
304 | 304 | // List of active notifications |
305 | - print load_fiche_titre($langs->trans("ListOfActiveNotifications").' ('.$num.')','',''); |
|
305 | + print load_fiche_titre($langs->trans("ListOfActiveNotifications").' ('.$num.')', '', ''); |
|
306 | 306 | |
307 | 307 | // Line with titles |
308 | 308 | print '<table width="100%" class="noborder">'; |
309 | 309 | print '<tr class="liste_titre">'; |
310 | - print_liste_field_titre("Target",$_SERVER["PHP_SELF"],"c.lastname,c.firstname",'',$param,'"width="45%"',$sortfield,$sortorder); |
|
311 | - print_liste_field_titre("Action",$_SERVER["PHP_SELF"],"",'',$param,'"width="35%"',$sortfield,$sortorder); |
|
312 | - print_liste_field_titre("Type",$_SERVER["PHP_SELF"],"n.type",'',$param,'"width="10%"',$sortfield,$sortorder); |
|
313 | - print_liste_field_titre('','',''); |
|
310 | + print_liste_field_titre("Target", $_SERVER["PHP_SELF"], "c.lastname,c.firstname", '', $param, '"width="45%"', $sortfield, $sortorder); |
|
311 | + print_liste_field_titre("Action", $_SERVER["PHP_SELF"], "", '', $param, '"width="35%"', $sortfield, $sortorder); |
|
312 | + print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "n.type", '', $param, '"width="10%"', $sortfield, $sortorder); |
|
313 | + print_liste_field_titre('', '', ''); |
|
314 | 314 | print '</tr>'; |
315 | 315 | |
316 | 316 | $langs->load("errors"); |
@@ -320,15 +320,15 @@ discard block |
||
320 | 320 | { |
321 | 321 | $i = 0; |
322 | 322 | |
323 | - $contactstatic=new Contact($db); |
|
323 | + $contactstatic = new Contact($db); |
|
324 | 324 | |
325 | 325 | while ($i < $num) |
326 | 326 | { |
327 | 327 | $obj = $db->fetch_object($resql); |
328 | 328 | |
329 | - $contactstatic->id=$obj->contactid; |
|
330 | - $contactstatic->lastname=$obj->lastname; |
|
331 | - $contactstatic->firstname=$obj->firstname; |
|
329 | + $contactstatic->id = $obj->contactid; |
|
330 | + $contactstatic->lastname = $obj->lastname; |
|
331 | + $contactstatic->firstname = $obj->firstname; |
|
332 | 332 | print '<tr class="oddeven"><td>'.$contactstatic->getNomUrl(1); |
333 | 333 | if ($obj->type == 'email') |
334 | 334 | { |
@@ -339,12 +339,12 @@ discard block |
||
339 | 339 | else |
340 | 340 | { |
341 | 341 | $langs->load("errors"); |
342 | - print ' '.img_warning().' '.$langs->trans("ErrorBadEMail",$obj->email); |
|
342 | + print ' '.img_warning().' '.$langs->trans("ErrorBadEMail", $obj->email); |
|
343 | 343 | } |
344 | 344 | } |
345 | 345 | print '</td>'; |
346 | 346 | print '<td>'; |
347 | - $label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label); |
|
347 | + $label = ($langs->trans("Notify_".$obj->code) != "Notify_".$obj->code ? $langs->trans("Notify_".$obj->code) : $obj->label); |
|
348 | 348 | print $label; |
349 | 349 | print '</td>'; |
350 | 350 | print '<td>'; |
@@ -417,14 +417,14 @@ discard block |
||
417 | 417 | |
418 | 418 | // List |
419 | 419 | $sql = "SELECT n.rowid, n.daten, n.email, n.objet_type as object_type, n.objet_id as object_id, n.type,"; |
420 | - $sql.= " c.rowid as id, c.lastname, c.firstname, c.email as contactemail,"; |
|
421 | - $sql.= " a.code, a.label"; |
|
422 | - $sql.= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,"; |
|
423 | - $sql.= " ".MAIN_DB_PREFIX."notify as n "; |
|
424 | - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as c ON n.fk_contact = c.rowid"; |
|
425 | - $sql.= " WHERE a.rowid = n.fk_action"; |
|
426 | - $sql.= " AND n.fk_soc = ".$object->id; |
|
427 | - $sql.= $db->order($sortfield, $sortorder); |
|
420 | + $sql .= " c.rowid as id, c.lastname, c.firstname, c.email as contactemail,"; |
|
421 | + $sql .= " a.code, a.label"; |
|
422 | + $sql .= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,"; |
|
423 | + $sql .= " ".MAIN_DB_PREFIX."notify as n "; |
|
424 | + $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as c ON n.fk_contact = c.rowid"; |
|
425 | + $sql .= " WHERE a.rowid = n.fk_action"; |
|
426 | + $sql .= " AND n.fk_soc = ".$object->id; |
|
427 | + $sql .= $db->order($sortfield, $sortorder); |
|
428 | 428 | |
429 | 429 | // Count total nb of records |
430 | 430 | $nbtotalofrecords = ''; |
@@ -439,9 +439,9 @@ discard block |
||
439 | 439 | } |
440 | 440 | } |
441 | 441 | |
442 | - $sql.= $db->plimit($limit+1, $offset); |
|
442 | + $sql .= $db->plimit($limit + 1, $offset); |
|
443 | 443 | |
444 | - $resql=$db->query($sql); |
|
444 | + $resql = $db->query($sql); |
|
445 | 445 | if ($resql) |
446 | 446 | { |
447 | 447 | $num = $db->num_rows($resql); |
@@ -451,9 +451,9 @@ discard block |
||
451 | 451 | dol_print_error($db); |
452 | 452 | } |
453 | 453 | |
454 | - $param='&socid='.$object->id; |
|
455 | - if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; |
|
456 | - if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; |
|
454 | + $param = '&socid='.$object->id; |
|
455 | + if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.$contextpage; |
|
456 | + if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit; |
|
457 | 457 | |
458 | 458 | print '<form method="post" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">'; |
459 | 459 | if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">'; |
@@ -470,18 +470,18 @@ discard block |
||
470 | 470 | // Line with titles |
471 | 471 | print '<table width="100%" class="noborder">'; |
472 | 472 | print '<tr class="liste_titre">'; |
473 | - print_liste_field_titre("Target",$_SERVER["PHP_SELF"],"c.lastname,c.firstname",'',$param,'',$sortfield,$sortorder); |
|
474 | - print_liste_field_titre("Action",$_SERVER["PHP_SELF"],"",'',$param,'',$sortfield,$sortorder); |
|
475 | - print_liste_field_titre("Type",$_SERVER["PHP_SELF"],"n.type",'',$param,'',$sortfield,$sortorder); |
|
473 | + print_liste_field_titre("Target", $_SERVER["PHP_SELF"], "c.lastname,c.firstname", '', $param, '', $sortfield, $sortorder); |
|
474 | + print_liste_field_titre("Action", $_SERVER["PHP_SELF"], "", '', $param, '', $sortfield, $sortorder); |
|
475 | + print_liste_field_titre("Type", $_SERVER["PHP_SELF"], "n.type", '', $param, '', $sortfield, $sortorder); |
|
476 | 476 | //print_liste_field_titre("Object",$_SERVER["PHP_SELF"],"",'',$param,'"',$sortfield,$sortorder); |
477 | - print_liste_field_titre("Date",$_SERVER["PHP_SELF"],"n.daten",'',$param,'align="right"',$sortfield,$sortorder); |
|
477 | + print_liste_field_titre("Date", $_SERVER["PHP_SELF"], "n.daten", '', $param, 'align="right"', $sortfield, $sortorder); |
|
478 | 478 | print '</tr>'; |
479 | 479 | |
480 | 480 | if ($num > 0) |
481 | 481 | { |
482 | 482 | $i = 0; |
483 | 483 | |
484 | - $contactstatic=new Contact($db); |
|
484 | + $contactstatic = new Contact($db); |
|
485 | 485 | |
486 | 486 | while ($i < $num) |
487 | 487 | { |
@@ -490,11 +490,11 @@ discard block |
||
490 | 490 | print '<tr class="oddeven"><td>'; |
491 | 491 | if ($obj->id > 0) |
492 | 492 | { |
493 | - $contactstatic->id=$obj->id; |
|
494 | - $contactstatic->lastname=$obj->lastname; |
|
495 | - $contactstatic->firstname=$obj->firstname; |
|
493 | + $contactstatic->id = $obj->id; |
|
494 | + $contactstatic->lastname = $obj->lastname; |
|
495 | + $contactstatic->firstname = $obj->firstname; |
|
496 | 496 | print $contactstatic->getNomUrl(1); |
497 | - print $obj->email?' <'.$obj->email.'>':$langs->trans("NoMail"); |
|
497 | + print $obj->email ? ' <'.$obj->email.'>' : $langs->trans("NoMail"); |
|
498 | 498 | } |
499 | 499 | else |
500 | 500 | { |
@@ -502,7 +502,7 @@ discard block |
||
502 | 502 | } |
503 | 503 | print '</td>'; |
504 | 504 | print '<td>'; |
505 | - $label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label); |
|
505 | + $label = ($langs->trans("Notify_".$obj->code) != "Notify_".$obj->code ? $langs->trans("Notify_".$obj->code) : $obj->label); |
|
506 | 506 | print $label; |
507 | 507 | print '</td>'; |
508 | 508 | print '<td>'; |
@@ -530,7 +530,7 @@ discard block |
||
530 | 530 | |
531 | 531 | print '</form>'; |
532 | 532 | } |
533 | -else dol_print_error('','RecordNotFound'); |
|
533 | +else dol_print_error('', 'RecordNotFound'); |
|
534 | 534 | |
535 | 535 | // End of page |
536 | 536 | llxFooter(); |
@@ -28,17 +28,17 @@ discard block |
||
28 | 28 | // S�curit� acc�s client |
29 | 29 | if ($user->societe_id > 0) |
30 | 30 | { |
31 | - $action = ''; |
|
32 | - $socid = $user->societe_id; |
|
31 | + $action = ''; |
|
32 | + $socid = $user->societe_id; |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | if ($sortorder == "") |
36 | 36 | { |
37 | - $sortorder="ASC"; |
|
37 | + $sortorder="ASC"; |
|
38 | 38 | } |
39 | 39 | if ($sortfield == "") |
40 | 40 | { |
41 | - $sortfield="s.nom"; |
|
41 | + $sortfield="s.nom"; |
|
42 | 42 | } |
43 | 43 | |
44 | 44 | if ($page == -1 || $page == null) { $page = 0 ; } |
@@ -72,36 +72,36 @@ discard block |
||
72 | 72 | $result = $db->query($sql); |
73 | 73 | if ($result) |
74 | 74 | { |
75 | - $num = $db->num_rows($result); |
|
76 | - $i = 0; |
|
77 | - |
|
78 | - $paramlist=''; |
|
79 | - print_barre_liste($langs->trans("ListOfNotificationsDone"), $page, $_SERVER["PHP_SELF"], $paramlist, $sortfield,$sortorder,'',$num); |
|
80 | - |
|
81 | - print '<table class="noborder" width="100%">'; |
|
82 | - print '<tr class="liste_titre">'; |
|
83 | - print_liste_field_titre("Company",$_SERVER["PHP_SELF"],"s.nom","","",'valign="center"',$sortfield,$sortorder); |
|
84 | - print_liste_field_titre("Contact",$_SERVER["PHP_SELF"],"c.lastname","","",'valign="center"',$sortfield,$sortorder); |
|
85 | - print_liste_field_titre("Action",$_SERVER["PHP_SELF"],"a.titre","","",'valign="center"',$sortfield,$sortorder); |
|
86 | - print "</tr>\n"; |
|
87 | - |
|
88 | - while ($i < $num) |
|
89 | - { |
|
90 | - $obj = $db->fetch_object($result); |
|
91 | - |
|
92 | - print '<tr class="oddeven">'; |
|
93 | - print "<td><a href=\"card.php?socid=".$obj->socid."\">".$obj->name."</a></td>\n"; |
|
94 | - print "<td>".dolGetFirstLastname($obj->firstname, $obj->lastname)."</td>\n"; |
|
95 | - print "<td>".$obj->titre."</td>\n"; |
|
96 | - print "</tr>\n"; |
|
97 | - $i++; |
|
98 | - } |
|
99 | - print "</table>"; |
|
100 | - $db->free(); |
|
75 | + $num = $db->num_rows($result); |
|
76 | + $i = 0; |
|
77 | + |
|
78 | + $paramlist=''; |
|
79 | + print_barre_liste($langs->trans("ListOfNotificationsDone"), $page, $_SERVER["PHP_SELF"], $paramlist, $sortfield,$sortorder,'',$num); |
|
80 | + |
|
81 | + print '<table class="noborder" width="100%">'; |
|
82 | + print '<tr class="liste_titre">'; |
|
83 | + print_liste_field_titre("Company",$_SERVER["PHP_SELF"],"s.nom","","",'valign="center"',$sortfield,$sortorder); |
|
84 | + print_liste_field_titre("Contact",$_SERVER["PHP_SELF"],"c.lastname","","",'valign="center"',$sortfield,$sortorder); |
|
85 | + print_liste_field_titre("Action",$_SERVER["PHP_SELF"],"a.titre","","",'valign="center"',$sortfield,$sortorder); |
|
86 | + print "</tr>\n"; |
|
87 | + |
|
88 | + while ($i < $num) |
|
89 | + { |
|
90 | + $obj = $db->fetch_object($result); |
|
91 | + |
|
92 | + print '<tr class="oddeven">'; |
|
93 | + print "<td><a href=\"card.php?socid=".$obj->socid."\">".$obj->name."</a></td>\n"; |
|
94 | + print "<td>".dolGetFirstLastname($obj->firstname, $obj->lastname)."</td>\n"; |
|
95 | + print "<td>".$obj->titre."</td>\n"; |
|
96 | + print "</tr>\n"; |
|
97 | + $i++; |
|
98 | + } |
|
99 | + print "</table>"; |
|
100 | + $db->free(); |
|
101 | 101 | } |
102 | 102 | else |
103 | 103 | { |
104 | - dol_print_error($db); |
|
104 | + dol_print_error($db); |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | // End of page |
@@ -64,7 +64,9 @@ discard block |
||
64 | 64 | $sql.= " AND a.rowid = n.fk_action"; |
65 | 65 | $sql.= " AND n.fk_soc = s.rowid"; |
66 | 66 | $sql.= " AND s.entity IN (".getEntity('societe').")"; |
67 | -if ($socid > 0) $sql.= " AND s.rowid = " . $user->societe_id; |
|
67 | +if ($socid > 0) { |
|
68 | + $sql.= " AND s.rowid = " . $user->societe_id; |
|
69 | +} |
|
68 | 70 | |
69 | 71 | $sql.= $db->order($sortfield,$sortorder); |
70 | 72 | $sql.= $db->plimit($conf->liste_limit, $offset); |
@@ -98,8 +100,7 @@ discard block |
||
98 | 100 | } |
99 | 101 | print "</table>"; |
100 | 102 | $db->free(); |
101 | -} |
|
102 | -else |
|
103 | +} else |
|
103 | 104 | { |
104 | 105 | dol_print_error($db); |
105 | 106 | } |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | |
26 | 26 | // Copyright (C) 2018 Alxarafe/Alixar <[email protected]> |
27 | 27 | defined('BASE_PATH') or die('Single entry point through the index.php of the main folder'); |
28 | -require DOL_BASE_PATH . '/main.inc.php'; |
|
28 | +require DOL_BASE_PATH.'/main.inc.php'; |
|
29 | 29 | $langs->loadLangs(array("companies", "banks")); |
30 | 30 | |
31 | 31 | // S�curit� acc�s client |
@@ -37,16 +37,16 @@ discard block |
||
37 | 37 | |
38 | 38 | if ($sortorder == "") |
39 | 39 | { |
40 | - $sortorder="ASC"; |
|
40 | + $sortorder = "ASC"; |
|
41 | 41 | } |
42 | 42 | if ($sortfield == "") |
43 | 43 | { |
44 | - $sortfield="s.nom"; |
|
44 | + $sortfield = "s.nom"; |
|
45 | 45 | } |
46 | 46 | |
47 | -if ($page == -1 || $page == null) { $page = 0 ; } |
|
47 | +if ($page == -1 || $page == null) { $page = 0; } |
|
48 | 48 | |
49 | -$offset = $conf->liste_limit * $page ; |
|
49 | +$offset = $conf->liste_limit * $page; |
|
50 | 50 | $pageprev = $page - 1; |
51 | 51 | $pagenext = $page + 1; |
52 | 52 | |
@@ -59,18 +59,18 @@ discard block |
||
59 | 59 | llxHeader(); |
60 | 60 | |
61 | 61 | $sql = "SELECT s.nom as name, s.rowid as socid, c.lastname, c.firstname, a.label, n.rowid"; |
62 | -$sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c,"; |
|
63 | -$sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,"; |
|
64 | -$sql.= " ".MAIN_DB_PREFIX."notify_def as n,"; |
|
65 | -$sql.= " ".MAIN_DB_PREFIX."societe as s"; |
|
66 | -$sql.= " WHERE n.fk_contact = c.rowid"; |
|
67 | -$sql.= " AND a.rowid = n.fk_action"; |
|
68 | -$sql.= " AND n.fk_soc = s.rowid"; |
|
69 | -$sql.= " AND s.entity IN (".getEntity('societe').")"; |
|
70 | -if ($socid > 0) $sql.= " AND s.rowid = " . $user->societe_id; |
|
71 | - |
|
72 | -$sql.= $db->order($sortfield,$sortorder); |
|
73 | -$sql.= $db->plimit($conf->liste_limit, $offset); |
|
62 | +$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as c,"; |
|
63 | +$sql .= " ".MAIN_DB_PREFIX."c_action_trigger as a,"; |
|
64 | +$sql .= " ".MAIN_DB_PREFIX."notify_def as n,"; |
|
65 | +$sql .= " ".MAIN_DB_PREFIX."societe as s"; |
|
66 | +$sql .= " WHERE n.fk_contact = c.rowid"; |
|
67 | +$sql .= " AND a.rowid = n.fk_action"; |
|
68 | +$sql .= " AND n.fk_soc = s.rowid"; |
|
69 | +$sql .= " AND s.entity IN (".getEntity('societe').")"; |
|
70 | +if ($socid > 0) $sql .= " AND s.rowid = ".$user->societe_id; |
|
71 | + |
|
72 | +$sql .= $db->order($sortfield, $sortorder); |
|
73 | +$sql .= $db->plimit($conf->liste_limit, $offset); |
|
74 | 74 | |
75 | 75 | $result = $db->query($sql); |
76 | 76 | if ($result) |
@@ -78,14 +78,14 @@ discard block |
||
78 | 78 | $num = $db->num_rows($result); |
79 | 79 | $i = 0; |
80 | 80 | |
81 | - $paramlist=''; |
|
82 | - print_barre_liste($langs->trans("ListOfNotificationsDone"), $page, $_SERVER["PHP_SELF"], $paramlist, $sortfield,$sortorder,'',$num); |
|
81 | + $paramlist = ''; |
|
82 | + print_barre_liste($langs->trans("ListOfNotificationsDone"), $page, $_SERVER["PHP_SELF"], $paramlist, $sortfield, $sortorder, '', $num); |
|
83 | 83 | |
84 | 84 | print '<table class="noborder" width="100%">'; |
85 | 85 | print '<tr class="liste_titre">'; |
86 | - print_liste_field_titre("Company",$_SERVER["PHP_SELF"],"s.nom","","",'valign="center"',$sortfield,$sortorder); |
|
87 | - print_liste_field_titre("Contact",$_SERVER["PHP_SELF"],"c.lastname","","",'valign="center"',$sortfield,$sortorder); |
|
88 | - print_liste_field_titre("Action",$_SERVER["PHP_SELF"],"a.titre","","",'valign="center"',$sortfield,$sortorder); |
|
86 | + print_liste_field_titre("Company", $_SERVER["PHP_SELF"], "s.nom", "", "", 'valign="center"', $sortfield, $sortorder); |
|
87 | + print_liste_field_titre("Contact", $_SERVER["PHP_SELF"], "c.lastname", "", "", 'valign="center"', $sortfield, $sortorder); |
|
88 | + print_liste_field_titre("Action", $_SERVER["PHP_SELF"], "a.titre", "", "", 'valign="center"', $sortfield, $sortorder); |
|
89 | 89 | print "</tr>\n"; |
90 | 90 | |
91 | 91 | while ($i < $num) |
@@ -52,18 +52,18 @@ discard block |
||
52 | 52 | // Generation liste des societes |
53 | 53 | if (GETPOST('newcompany') || GETPOST('socid','int') || GETPOST('id_fourn')) |
54 | 54 | { |
55 | - $return_arr = array(); |
|
56 | - |
|
57 | - // Define filter on text typed |
|
58 | - $socid = $_GET['newcompany']?$_GET['newcompany']:''; |
|
59 | - if (! $socid) $socid = $_GET['socid']?$_GET['socid']:''; |
|
60 | - if (! $socid) $socid = $_GET['id_fourn']?$_GET['id_fourn']:''; |
|
61 | - |
|
62 | - $sql = "SELECT rowid, nom"; |
|
63 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
64 | - $sql.= " WHERE s.entity IN (".getEntity('societe').")"; |
|
65 | - if ($socid) |
|
66 | - { |
|
55 | + $return_arr = array(); |
|
56 | + |
|
57 | + // Define filter on text typed |
|
58 | + $socid = $_GET['newcompany']?$_GET['newcompany']:''; |
|
59 | + if (! $socid) $socid = $_GET['socid']?$_GET['socid']:''; |
|
60 | + if (! $socid) $socid = $_GET['id_fourn']?$_GET['id_fourn']:''; |
|
61 | + |
|
62 | + $sql = "SELECT rowid, nom"; |
|
63 | + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
64 | + $sql.= " WHERE s.entity IN (".getEntity('societe').")"; |
|
65 | + if ($socid) |
|
66 | + { |
|
67 | 67 | $sql.=" AND ("; |
68 | 68 | // Add criteria on name/code |
69 | 69 | if (! empty($conf->global->COMPANY_DONOTSEARCH_ANYWHERE)) // Can use index |
@@ -74,37 +74,37 @@ discard block |
||
74 | 74 | } |
75 | 75 | else |
76 | 76 | { |
77 | - $sql.="nom LIKE '%" . $db->escape($socid) . "%'"; |
|
78 | - $sql.=" OR code_client LIKE '%" . $db->escape($socid) . "%'"; |
|
79 | - $sql.=" OR code_fournisseur LIKE '%" . $db->escape($socid) . "%'"; |
|
77 | + $sql.="nom LIKE '%" . $db->escape($socid) . "%'"; |
|
78 | + $sql.=" OR code_client LIKE '%" . $db->escape($socid) . "%'"; |
|
79 | + $sql.=" OR code_fournisseur LIKE '%" . $db->escape($socid) . "%'"; |
|
80 | 80 | } |
81 | - if (! empty($conf->global->SOCIETE_ALLOW_SEARCH_ON_ROWID)) $sql.=" OR rowid = '" . $db->escape($socid) . "'"; |
|
82 | - $sql.=")"; |
|
83 | - } |
|
84 | - if (GETPOST("filter")) $sql.= " AND ".GETPOST("filter","alpha"); // Add other filters |
|
85 | - $sql.= " ORDER BY nom ASC"; |
|
86 | - |
|
87 | - //dol_syslog("ajaxcompanies", LOG_DEBUG); |
|
88 | - $resql=$db->query($sql); |
|
89 | - if ($resql) |
|
90 | - { |
|
91 | - while ($row = $db->fetch_array($resql)) |
|
92 | - { |
|
93 | - $label=$row['nom']; |
|
94 | - if ($socid) $label=preg_replace('/('.preg_quote($socid,'/').')/i','<strong>$1</strong>',$label,1); |
|
95 | - $row_array['label'] = $label; |
|
96 | - $row_array['value'] = $row['nom']; |
|
97 | - $row_array['key'] = $row['rowid']; |
|
98 | - |
|
99 | - array_push($return_arr,$row_array); |
|
100 | - } |
|
101 | - |
|
102 | - echo json_encode($return_arr); |
|
103 | - } |
|
104 | - else |
|
105 | - { |
|
106 | - echo json_encode(array('nom'=>'Error','label'=>'Error','key'=>'Error','value'=>'Error')); |
|
107 | - } |
|
81 | + if (! empty($conf->global->SOCIETE_ALLOW_SEARCH_ON_ROWID)) $sql.=" OR rowid = '" . $db->escape($socid) . "'"; |
|
82 | + $sql.=")"; |
|
83 | + } |
|
84 | + if (GETPOST("filter")) $sql.= " AND ".GETPOST("filter","alpha"); // Add other filters |
|
85 | + $sql.= " ORDER BY nom ASC"; |
|
86 | + |
|
87 | + //dol_syslog("ajaxcompanies", LOG_DEBUG); |
|
88 | + $resql=$db->query($sql); |
|
89 | + if ($resql) |
|
90 | + { |
|
91 | + while ($row = $db->fetch_array($resql)) |
|
92 | + { |
|
93 | + $label=$row['nom']; |
|
94 | + if ($socid) $label=preg_replace('/('.preg_quote($socid,'/').')/i','<strong>$1</strong>',$label,1); |
|
95 | + $row_array['label'] = $label; |
|
96 | + $row_array['value'] = $row['nom']; |
|
97 | + $row_array['key'] = $row['rowid']; |
|
98 | + |
|
99 | + array_push($return_arr,$row_array); |
|
100 | + } |
|
101 | + |
|
102 | + echo json_encode($return_arr); |
|
103 | + } |
|
104 | + else |
|
105 | + { |
|
106 | + echo json_encode(array('nom'=>'Error','label'=>'Error','key'=>'Error','value'=>'Error')); |
|
107 | + } |
|
108 | 108 | } |
109 | 109 | else |
110 | 110 | { |
@@ -23,12 +23,25 @@ discard block |
||
23 | 23 | * \brief File to return Ajax response on third parties request |
24 | 24 | */ |
25 | 25 | |
26 | -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); // Disables token renewal |
|
27 | -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); |
|
28 | -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); |
|
29 | -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); |
|
30 | -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); |
|
31 | -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1'); |
|
26 | +if (! defined('NOTOKENRENEWAL')) { |
|
27 | + define('NOTOKENRENEWAL',1); |
|
28 | +} |
|
29 | +// Disables token renewal |
|
30 | +if (! defined('NOREQUIREMENU')) { |
|
31 | + define('NOREQUIREMENU','1'); |
|
32 | +} |
|
33 | +if (! defined('NOREQUIREHTML')) { |
|
34 | + define('NOREQUIREHTML','1'); |
|
35 | +} |
|
36 | +if (! defined('NOREQUIREAJAX')) { |
|
37 | + define('NOREQUIREAJAX','1'); |
|
38 | +} |
|
39 | +if (! defined('NOREQUIRESOC')) { |
|
40 | + define('NOREQUIRESOC','1'); |
|
41 | +} |
|
42 | +if (! defined('NOCSRFCHECK')) { |
|
43 | + define('NOCSRFCHECK','1'); |
|
44 | +} |
|
32 | 45 | |
33 | 46 | |
34 | 47 | // Copyright (C) 2018 Alxarafe/Alixar <[email protected]> |
@@ -60,8 +73,12 @@ discard block |
||
60 | 73 | |
61 | 74 | // Define filter on text typed |
62 | 75 | $socid = $_GET['newcompany']?$_GET['newcompany']:''; |
63 | - if (! $socid) $socid = $_GET['socid']?$_GET['socid']:''; |
|
64 | - if (! $socid) $socid = $_GET['id_fourn']?$_GET['id_fourn']:''; |
|
76 | + if (! $socid) { |
|
77 | + $socid = $_GET['socid']?$_GET['socid']:''; |
|
78 | + } |
|
79 | + if (! $socid) { |
|
80 | + $socid = $_GET['id_fourn']?$_GET['id_fourn']:''; |
|
81 | + } |
|
65 | 82 | |
66 | 83 | $sql = "SELECT rowid, nom"; |
67 | 84 | $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; |
@@ -70,22 +87,28 @@ discard block |
||
70 | 87 | { |
71 | 88 | $sql.=" AND ("; |
72 | 89 | // Add criteria on name/code |
73 | - if (! empty($conf->global->COMPANY_DONOTSEARCH_ANYWHERE)) // Can use index |
|
90 | + if (! empty($conf->global->COMPANY_DONOTSEARCH_ANYWHERE)) { |
|
91 | + // Can use index |
|
74 | 92 | { |
75 | 93 | $sql.="nom LIKE '" . $db->escape($socid) . "%'"; |
94 | + } |
|
76 | 95 | $sql.=" OR code_client LIKE '" . $db->escape($socid) . "%'"; |
77 | 96 | $sql.=" OR code_fournisseur LIKE '" . $db->escape($socid) . "%'"; |
78 | - } |
|
79 | - else |
|
97 | + } else |
|
80 | 98 | { |
81 | 99 | $sql.="nom LIKE '%" . $db->escape($socid) . "%'"; |
82 | 100 | $sql.=" OR code_client LIKE '%" . $db->escape($socid) . "%'"; |
83 | 101 | $sql.=" OR code_fournisseur LIKE '%" . $db->escape($socid) . "%'"; |
84 | 102 | } |
85 | - if (! empty($conf->global->SOCIETE_ALLOW_SEARCH_ON_ROWID)) $sql.=" OR rowid = '" . $db->escape($socid) . "'"; |
|
103 | + if (! empty($conf->global->SOCIETE_ALLOW_SEARCH_ON_ROWID)) { |
|
104 | + $sql.=" OR rowid = '" . $db->escape($socid) . "'"; |
|
105 | + } |
|
86 | 106 | $sql.=")"; |
87 | 107 | } |
88 | - if (GETPOST("filter")) $sql.= " AND ".GETPOST("filter","alpha"); // Add other filters |
|
108 | + if (GETPOST("filter")) { |
|
109 | + $sql.= " AND ".GETPOST("filter","alpha"); |
|
110 | + } |
|
111 | + // Add other filters |
|
89 | 112 | $sql.= " ORDER BY nom ASC"; |
90 | 113 | |
91 | 114 | //dol_syslog("ajaxcompanies", LOG_DEBUG); |
@@ -95,7 +118,9 @@ discard block |
||
95 | 118 | while ($row = $db->fetch_array($resql)) |
96 | 119 | { |
97 | 120 | $label=$row['nom']; |
98 | - if ($socid) $label=preg_replace('/('.preg_quote($socid,'/').')/i','<strong>$1</strong>',$label,1); |
|
121 | + if ($socid) { |
|
122 | + $label=preg_replace('/('.preg_quote($socid,'/').')/i','<strong>$1</strong>',$label,1); |
|
123 | + } |
|
99 | 124 | $row_array['label'] = $label; |
100 | 125 | $row_array['value'] = $row['nom']; |
101 | 126 | $row_array['key'] = $row['rowid']; |
@@ -104,13 +129,11 @@ discard block |
||
104 | 129 | } |
105 | 130 | |
106 | 131 | echo json_encode($return_arr); |
107 | - } |
|
108 | - else |
|
132 | + } else |
|
109 | 133 | { |
110 | 134 | echo json_encode(array('nom'=>'Error','label'=>'Error','key'=>'Error','value'=>'Error')); |
111 | 135 | } |
112 | -} |
|
113 | -else |
|
136 | +} else |
|
114 | 137 | { |
115 | 138 | echo json_encode(array('nom'=>'ErrorBadParameter','label'=>'ErrorBadParameter','key'=>'ErrorBadParameter','value'=>'ErrorBadParameter')); |
116 | 139 | } |
@@ -23,17 +23,17 @@ discard block |
||
23 | 23 | * \brief File to return Ajax response on third parties request |
24 | 24 | */ |
25 | 25 | |
26 | -if (! defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL',1); // Disables token renewal |
|
27 | -if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); |
|
28 | -if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); |
|
29 | -if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); |
|
30 | -if (! defined('NOREQUIRESOC')) define('NOREQUIRESOC','1'); |
|
31 | -if (! defined('NOCSRFCHECK')) define('NOCSRFCHECK','1'); |
|
26 | +if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', 1); // Disables token renewal |
|
27 | +if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1'); |
|
28 | +if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1'); |
|
29 | +if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1'); |
|
30 | +if (!defined('NOREQUIRESOC')) define('NOREQUIRESOC', '1'); |
|
31 | +if (!defined('NOCSRFCHECK')) define('NOCSRFCHECK', '1'); |
|
32 | 32 | |
33 | 33 | |
34 | 34 | // Copyright (C) 2018 Alxarafe/Alixar <[email protected]> |
35 | 35 | defined('BASE_PATH') or die('Single entry point through the index.php of the main folder'); |
36 | -require DOL_BASE_PATH . '/main.inc.php'; |
|
36 | +require DOL_BASE_PATH.'/main.inc.php'; |
|
37 | 37 | |
38 | 38 | |
39 | 39 | |
@@ -50,67 +50,67 @@ discard block |
||
50 | 50 | |
51 | 51 | //print '<!-- Ajax page called with url '.dol_escape_htmltag($_SERVER["PHP_SELF"]).'?'.dol_escape_htmltag($_SERVER["QUERY_STRING"]).' -->'."\n"; |
52 | 52 | |
53 | -dol_syslog(join(',',$_GET)); |
|
53 | +dol_syslog(join(',', $_GET)); |
|
54 | 54 | |
55 | 55 | |
56 | 56 | // Generation liste des societes |
57 | -if (GETPOST('newcompany') || GETPOST('socid','int') || GETPOST('id_fourn')) |
|
57 | +if (GETPOST('newcompany') || GETPOST('socid', 'int') || GETPOST('id_fourn')) |
|
58 | 58 | { |
59 | 59 | $return_arr = array(); |
60 | 60 | |
61 | 61 | // Define filter on text typed |
62 | - $socid = $_GET['newcompany']?$_GET['newcompany']:''; |
|
63 | - if (! $socid) $socid = $_GET['socid']?$_GET['socid']:''; |
|
64 | - if (! $socid) $socid = $_GET['id_fourn']?$_GET['id_fourn']:''; |
|
62 | + $socid = $_GET['newcompany'] ? $_GET['newcompany'] : ''; |
|
63 | + if (!$socid) $socid = $_GET['socid'] ? $_GET['socid'] : ''; |
|
64 | + if (!$socid) $socid = $_GET['id_fourn'] ? $_GET['id_fourn'] : ''; |
|
65 | 65 | |
66 | 66 | $sql = "SELECT rowid, nom"; |
67 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
68 | - $sql.= " WHERE s.entity IN (".getEntity('societe').")"; |
|
67 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
68 | + $sql .= " WHERE s.entity IN (".getEntity('societe').")"; |
|
69 | 69 | if ($socid) |
70 | 70 | { |
71 | - $sql.=" AND ("; |
|
71 | + $sql .= " AND ("; |
|
72 | 72 | // Add criteria on name/code |
73 | - if (! empty($conf->global->COMPANY_DONOTSEARCH_ANYWHERE)) // Can use index |
|
73 | + if (!empty($conf->global->COMPANY_DONOTSEARCH_ANYWHERE)) // Can use index |
|
74 | 74 | { |
75 | - $sql.="nom LIKE '" . $db->escape($socid) . "%'"; |
|
76 | - $sql.=" OR code_client LIKE '" . $db->escape($socid) . "%'"; |
|
77 | - $sql.=" OR code_fournisseur LIKE '" . $db->escape($socid) . "%'"; |
|
75 | + $sql .= "nom LIKE '".$db->escape($socid)."%'"; |
|
76 | + $sql .= " OR code_client LIKE '".$db->escape($socid)."%'"; |
|
77 | + $sql .= " OR code_fournisseur LIKE '".$db->escape($socid)."%'"; |
|
78 | 78 | } |
79 | 79 | else |
80 | 80 | { |
81 | - $sql.="nom LIKE '%" . $db->escape($socid) . "%'"; |
|
82 | - $sql.=" OR code_client LIKE '%" . $db->escape($socid) . "%'"; |
|
83 | - $sql.=" OR code_fournisseur LIKE '%" . $db->escape($socid) . "%'"; |
|
81 | + $sql .= "nom LIKE '%".$db->escape($socid)."%'"; |
|
82 | + $sql .= " OR code_client LIKE '%".$db->escape($socid)."%'"; |
|
83 | + $sql .= " OR code_fournisseur LIKE '%".$db->escape($socid)."%'"; |
|
84 | 84 | } |
85 | - if (! empty($conf->global->SOCIETE_ALLOW_SEARCH_ON_ROWID)) $sql.=" OR rowid = '" . $db->escape($socid) . "'"; |
|
86 | - $sql.=")"; |
|
85 | + if (!empty($conf->global->SOCIETE_ALLOW_SEARCH_ON_ROWID)) $sql .= " OR rowid = '".$db->escape($socid)."'"; |
|
86 | + $sql .= ")"; |
|
87 | 87 | } |
88 | - if (GETPOST("filter")) $sql.= " AND ".GETPOST("filter","alpha"); // Add other filters |
|
89 | - $sql.= " ORDER BY nom ASC"; |
|
88 | + if (GETPOST("filter")) $sql .= " AND ".GETPOST("filter", "alpha"); // Add other filters |
|
89 | + $sql .= " ORDER BY nom ASC"; |
|
90 | 90 | |
91 | 91 | //dol_syslog("ajaxcompanies", LOG_DEBUG); |
92 | - $resql=$db->query($sql); |
|
92 | + $resql = $db->query($sql); |
|
93 | 93 | if ($resql) |
94 | 94 | { |
95 | 95 | while ($row = $db->fetch_array($resql)) |
96 | 96 | { |
97 | - $label=$row['nom']; |
|
98 | - if ($socid) $label=preg_replace('/('.preg_quote($socid,'/').')/i','<strong>$1</strong>',$label,1); |
|
97 | + $label = $row['nom']; |
|
98 | + if ($socid) $label = preg_replace('/('.preg_quote($socid, '/').')/i', '<strong>$1</strong>', $label, 1); |
|
99 | 99 | $row_array['label'] = $label; |
100 | 100 | $row_array['value'] = $row['nom']; |
101 | 101 | $row_array['key'] = $row['rowid']; |
102 | 102 | |
103 | - array_push($return_arr,$row_array); |
|
103 | + array_push($return_arr, $row_array); |
|
104 | 104 | } |
105 | 105 | |
106 | 106 | echo json_encode($return_arr); |
107 | 107 | } |
108 | 108 | else |
109 | 109 | { |
110 | - echo json_encode(array('nom'=>'Error','label'=>'Error','key'=>'Error','value'=>'Error')); |
|
110 | + echo json_encode(array('nom'=>'Error', 'label'=>'Error', 'key'=>'Error', 'value'=>'Error')); |
|
111 | 111 | } |
112 | 112 | } |
113 | 113 | else |
114 | 114 | { |
115 | - echo json_encode(array('nom'=>'ErrorBadParameter','label'=>'ErrorBadParameter','key'=>'ErrorBadParameter','value'=>'ErrorBadParameter')); |
|
115 | + echo json_encode(array('nom'=>'ErrorBadParameter', 'label'=>'ErrorBadParameter', 'key'=>'ErrorBadParameter', 'value'=>'ErrorBadParameter')); |
|
116 | 116 | } |
@@ -18,8 +18,8 @@ discard block |
||
18 | 18 | // Protection to avoid direct call of template |
19 | 19 | if (empty($conf) || ! is_object($conf)) |
20 | 20 | { |
21 | - print "Error, template page can't be called as URL"; |
|
22 | - exit; |
|
21 | + print "Error, template page can't be called as URL"; |
|
22 | + exit; |
|
23 | 23 | } |
24 | 24 | |
25 | 25 | // Sale representative |
@@ -32,20 +32,20 @@ discard block |
||
32 | 32 | $nbofsalesrepresentative=count($listsalesrepresentatives); |
33 | 33 | if ($nbofsalesrepresentative > 0) |
34 | 34 | { |
35 | - $userstatic=new User($db); |
|
36 | - foreach($listsalesrepresentatives as $val) |
|
37 | - { |
|
38 | - $userstatic->id=$val['id']; |
|
39 | - $userstatic->login=$val['login']; |
|
40 | - $userstatic->lastname=$val['lastname']; |
|
41 | - $userstatic->firstname=$val['firstname']; |
|
42 | - $userstatic->statut=$val['statut']; |
|
43 | - $userstatic->photo=$val['photo']; |
|
44 | - $userstatic->email=$val['email']; |
|
45 | - $userstatic->entity=$val['entity']; |
|
46 | - print $userstatic->getNomUrl(-1); |
|
47 | - print ' '; |
|
48 | - } |
|
35 | + $userstatic=new User($db); |
|
36 | + foreach($listsalesrepresentatives as $val) |
|
37 | + { |
|
38 | + $userstatic->id=$val['id']; |
|
39 | + $userstatic->login=$val['login']; |
|
40 | + $userstatic->lastname=$val['lastname']; |
|
41 | + $userstatic->firstname=$val['firstname']; |
|
42 | + $userstatic->statut=$val['statut']; |
|
43 | + $userstatic->photo=$val['photo']; |
|
44 | + $userstatic->email=$val['email']; |
|
45 | + $userstatic->entity=$val['entity']; |
|
46 | + print $userstatic->getNomUrl(-1); |
|
47 | + print ' '; |
|
48 | + } |
|
49 | 49 | } |
50 | 50 | else print '<span class="opacitymedium">'.$langs->trans("NoSalesRepresentativeAffected").'</span>'; |
51 | 51 | print '</td></tr>'; |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | */ |
17 | 17 | |
18 | 18 | // Protection to avoid direct call of template |
19 | -if (empty($conf) || ! is_object($conf)) |
|
19 | +if (empty($conf) || !is_object($conf)) |
|
20 | 20 | { |
21 | 21 | print "Error, template page can't be called as URL"; |
22 | 22 | exit; |
@@ -28,21 +28,21 @@ discard block |
||
28 | 28 | print '</td>'; |
29 | 29 | print '<td>'; |
30 | 30 | |
31 | -$listsalesrepresentatives=$object->getSalesRepresentatives($user); |
|
32 | -$nbofsalesrepresentative=count($listsalesrepresentatives); |
|
31 | +$listsalesrepresentatives = $object->getSalesRepresentatives($user); |
|
32 | +$nbofsalesrepresentative = count($listsalesrepresentatives); |
|
33 | 33 | if ($nbofsalesrepresentative > 0) |
34 | 34 | { |
35 | - $userstatic=new User($db); |
|
36 | - foreach($listsalesrepresentatives as $val) |
|
35 | + $userstatic = new User($db); |
|
36 | + foreach ($listsalesrepresentatives as $val) |
|
37 | 37 | { |
38 | - $userstatic->id=$val['id']; |
|
39 | - $userstatic->login=$val['login']; |
|
40 | - $userstatic->lastname=$val['lastname']; |
|
41 | - $userstatic->firstname=$val['firstname']; |
|
42 | - $userstatic->statut=$val['statut']; |
|
43 | - $userstatic->photo=$val['photo']; |
|
44 | - $userstatic->email=$val['email']; |
|
45 | - $userstatic->entity=$val['entity']; |
|
38 | + $userstatic->id = $val['id']; |
|
39 | + $userstatic->login = $val['login']; |
|
40 | + $userstatic->lastname = $val['lastname']; |
|
41 | + $userstatic->firstname = $val['firstname']; |
|
42 | + $userstatic->statut = $val['statut']; |
|
43 | + $userstatic->photo = $val['photo']; |
|
44 | + $userstatic->email = $val['email']; |
|
45 | + $userstatic->entity = $val['entity']; |
|
46 | 46 | print $userstatic->getNomUrl(-1); |
47 | 47 | print ' '; |
48 | 48 | } |
@@ -46,7 +46,8 @@ |
||
46 | 46 | print $userstatic->getNomUrl(-1); |
47 | 47 | print ' '; |
48 | 48 | } |
49 | +} else { |
|
50 | + print '<span class="opacitymedium">'.$langs->trans("NoSalesRepresentativeAffected").'</span>'; |
|
49 | 51 | } |
50 | -else print '<span class="opacitymedium">'.$langs->trans("NoSalesRepresentativeAffected").'</span>'; |
|
51 | 52 | print '</td></tr>'; |
52 | 53 |
@@ -100,8 +100,8 @@ discard block |
||
100 | 100 | |
101 | 101 | if (empty($socid)) |
102 | 102 | { |
103 | - dol_print_error($db); |
|
104 | - exit; |
|
103 | + dol_print_error($db); |
|
104 | + exit; |
|
105 | 105 | } |
106 | 106 | |
107 | 107 | $head = societe_prepare_head($object); |
@@ -118,50 +118,50 @@ discard block |
||
118 | 118 | |
119 | 119 | if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field |
120 | 120 | { |
121 | - print '<tr><td class="titlefield">'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>'; |
|
121 | + print '<tr><td class="titlefield">'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>'; |
|
122 | 122 | } |
123 | 123 | |
124 | 124 | //if ($conf->agenda->enabled && $user->rights->agenda->myactions->read) $elementTypeArray['action']=$langs->transnoentitiesnoconv('Events'); |
125 | 125 | |
126 | 126 | if ($object->client) |
127 | 127 | { |
128 | - print '<tr><td class="titlefield">'; |
|
129 | - print $langs->trans('CustomerCode').'</td><td colspan="3">'; |
|
130 | - print $object->code_client; |
|
131 | - if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>'; |
|
132 | - print '</td></tr>'; |
|
133 | - $sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."facture where fk_soc = ".$socid; |
|
134 | - $resql=$db->query($sql); |
|
135 | - if (!$resql) dol_print_error($db); |
|
136 | - |
|
137 | - $obj = $db->fetch_object($resql); |
|
138 | - $nbFactsClient = $obj->nb; |
|
139 | - $thirdTypeArray['customer']=$langs->trans("customer"); |
|
140 | - if ($conf->propal->enabled && $user->rights->propal->lire) $elementTypeArray['propal']=$langs->transnoentitiesnoconv('Proposals'); |
|
141 | - if ($conf->commande->enabled && $user->rights->commande->lire) $elementTypeArray['order']=$langs->transnoentitiesnoconv('Orders'); |
|
142 | - if ($conf->facture->enabled && $user->rights->facture->lire) $elementTypeArray['invoice']=$langs->transnoentitiesnoconv('Invoices'); |
|
143 | - if ($conf->contrat->enabled && $user->rights->contrat->lire) $elementTypeArray['contract']=$langs->transnoentitiesnoconv('Contracts'); |
|
128 | + print '<tr><td class="titlefield">'; |
|
129 | + print $langs->trans('CustomerCode').'</td><td colspan="3">'; |
|
130 | + print $object->code_client; |
|
131 | + if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>'; |
|
132 | + print '</td></tr>'; |
|
133 | + $sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."facture where fk_soc = ".$socid; |
|
134 | + $resql=$db->query($sql); |
|
135 | + if (!$resql) dol_print_error($db); |
|
136 | + |
|
137 | + $obj = $db->fetch_object($resql); |
|
138 | + $nbFactsClient = $obj->nb; |
|
139 | + $thirdTypeArray['customer']=$langs->trans("customer"); |
|
140 | + if ($conf->propal->enabled && $user->rights->propal->lire) $elementTypeArray['propal']=$langs->transnoentitiesnoconv('Proposals'); |
|
141 | + if ($conf->commande->enabled && $user->rights->commande->lire) $elementTypeArray['order']=$langs->transnoentitiesnoconv('Orders'); |
|
142 | + if ($conf->facture->enabled && $user->rights->facture->lire) $elementTypeArray['invoice']=$langs->transnoentitiesnoconv('Invoices'); |
|
143 | + if ($conf->contrat->enabled && $user->rights->contrat->lire) $elementTypeArray['contract']=$langs->transnoentitiesnoconv('Contracts'); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | if ($conf->ficheinter->enabled && $user->rights->ficheinter->lire) $elementTypeArray['fichinter']=$langs->transnoentitiesnoconv('Interventions'); |
147 | 147 | |
148 | 148 | if ($object->fournisseur) |
149 | 149 | { |
150 | - print '<tr><td class="titlefield">'; |
|
151 | - print $langs->trans('SupplierCode').'</td><td colspan="3">'; |
|
152 | - print $object->code_fournisseur; |
|
153 | - if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>'; |
|
154 | - print '</td></tr>'; |
|
155 | - $sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."commande_fournisseur where fk_soc = ".$socid; |
|
156 | - $resql=$db->query($sql); |
|
157 | - if (!$resql) dol_print_error($db); |
|
158 | - |
|
159 | - $obj = $db->fetch_object($resql); |
|
160 | - $nbCmdsFourn = $obj->nb; |
|
161 | - $thirdTypeArray['supplier']=$langs->trans("supplier"); |
|
162 | - if ($conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire) $elementTypeArray['supplier_invoice']=$langs->transnoentitiesnoconv('SuppliersInvoices'); |
|
163 | - if ($conf->fournisseur->enabled && $user->rights->fournisseur->commande->lire) $elementTypeArray['supplier_order']=$langs->transnoentitiesnoconv('SuppliersOrders'); |
|
164 | - if ($conf->fournisseur->enabled && $user->rights->supplier_proposal->lire) $elementTypeArray['supplier_proposal']=$langs->transnoentitiesnoconv('SupplierProposals'); |
|
150 | + print '<tr><td class="titlefield">'; |
|
151 | + print $langs->trans('SupplierCode').'</td><td colspan="3">'; |
|
152 | + print $object->code_fournisseur; |
|
153 | + if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>'; |
|
154 | + print '</td></tr>'; |
|
155 | + $sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."commande_fournisseur where fk_soc = ".$socid; |
|
156 | + $resql=$db->query($sql); |
|
157 | + if (!$resql) dol_print_error($db); |
|
158 | + |
|
159 | + $obj = $db->fetch_object($resql); |
|
160 | + $nbCmdsFourn = $obj->nb; |
|
161 | + $thirdTypeArray['supplier']=$langs->trans("supplier"); |
|
162 | + if ($conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire) $elementTypeArray['supplier_invoice']=$langs->transnoentitiesnoconv('SuppliersInvoices'); |
|
163 | + if ($conf->fournisseur->enabled && $user->rights->fournisseur->commande->lire) $elementTypeArray['supplier_order']=$langs->transnoentitiesnoconv('SuppliersOrders'); |
|
164 | + if ($conf->fournisseur->enabled && $user->rights->supplier_proposal->lire) $elementTypeArray['supplier_proposal']=$langs->transnoentitiesnoconv('SupplierProposals'); |
|
165 | 165 | } |
166 | 166 | print '</table>'; |
167 | 167 | |
@@ -187,66 +187,66 @@ discard block |
||
187 | 187 | }*/ |
188 | 188 | if ($type_element == 'fichinter') |
189 | 189 | { // Customer : show products from invoices |
190 | - require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php'; |
|
191 | - $documentstatic=new Fichinter($db); |
|
192 | - $sql_select = 'SELECT f.rowid as doc_id, f.ref as doc_number, \'1\' as doc_type, f.datec as dateprint, f.fk_statut as status, '; |
|
193 | - $tables_from = MAIN_DB_PREFIX."fichinter as f LEFT JOIN ".MAIN_DB_PREFIX."fichinterdet as d ON d.fk_fichinter = f.rowid"; // Must use left join to work also with option that disable usage of lines. |
|
194 | - $where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".$socid; |
|
195 | - $where.= " AND f.entity = ".$conf->entity; |
|
196 | - $dateprint = 'f.datec'; |
|
197 | - $doc_number='f.ref'; |
|
190 | + require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php'; |
|
191 | + $documentstatic=new Fichinter($db); |
|
192 | + $sql_select = 'SELECT f.rowid as doc_id, f.ref as doc_number, \'1\' as doc_type, f.datec as dateprint, f.fk_statut as status, '; |
|
193 | + $tables_from = MAIN_DB_PREFIX."fichinter as f LEFT JOIN ".MAIN_DB_PREFIX."fichinterdet as d ON d.fk_fichinter = f.rowid"; // Must use left join to work also with option that disable usage of lines. |
|
194 | + $where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".$socid; |
|
195 | + $where.= " AND f.entity = ".$conf->entity; |
|
196 | + $dateprint = 'f.datec'; |
|
197 | + $doc_number='f.ref'; |
|
198 | 198 | } |
199 | 199 | if ($type_element == 'invoice') |
200 | 200 | { // Customer : show products from invoices |
201 | - require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
|
202 | - $documentstatic=new Facture($db); |
|
203 | - $sql_select = 'SELECT f.rowid as doc_id, f.ref as doc_number, f.type as doc_type, f.datef as dateprint, f.fk_statut as status, f.paye as paid, '; |
|
204 | - $tables_from = MAIN_DB_PREFIX."facture as f,".MAIN_DB_PREFIX."facturedet as d"; |
|
205 | - $where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".$socid; |
|
206 | - $where.= " AND d.fk_facture = f.rowid"; |
|
207 | - $where.= " AND f.entity = ".$conf->entity; |
|
208 | - $dateprint = 'f.datef'; |
|
209 | - $doc_number='f.ref'; |
|
210 | - $thirdTypeSelect='customer'; |
|
201 | + require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
|
202 | + $documentstatic=new Facture($db); |
|
203 | + $sql_select = 'SELECT f.rowid as doc_id, f.ref as doc_number, f.type as doc_type, f.datef as dateprint, f.fk_statut as status, f.paye as paid, '; |
|
204 | + $tables_from = MAIN_DB_PREFIX."facture as f,".MAIN_DB_PREFIX."facturedet as d"; |
|
205 | + $where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".$socid; |
|
206 | + $where.= " AND d.fk_facture = f.rowid"; |
|
207 | + $where.= " AND f.entity = ".$conf->entity; |
|
208 | + $dateprint = 'f.datef'; |
|
209 | + $doc_number='f.ref'; |
|
210 | + $thirdTypeSelect='customer'; |
|
211 | 211 | } |
212 | 212 | if ($type_element == 'propal') |
213 | 213 | { |
214 | - require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; |
|
215 | - $documentstatic=new Propal($db); |
|
216 | - $sql_select = 'SELECT c.rowid as doc_id, c.ref as doc_number, \'1\' as doc_type, c.datep as dateprint, c.fk_statut as status, '; |
|
217 | - $tables_from = MAIN_DB_PREFIX."propal as c,".MAIN_DB_PREFIX."propaldet as d"; |
|
218 | - $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".$socid; |
|
219 | - $where.= " AND d.fk_propal = c.rowid"; |
|
220 | - $where.= " AND c.entity = ".$conf->entity; |
|
221 | - $datePrint = 'c.datep'; |
|
222 | - $doc_number='c.ref'; |
|
223 | - $thirdTypeSelect='customer'; |
|
214 | + require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; |
|
215 | + $documentstatic=new Propal($db); |
|
216 | + $sql_select = 'SELECT c.rowid as doc_id, c.ref as doc_number, \'1\' as doc_type, c.datep as dateprint, c.fk_statut as status, '; |
|
217 | + $tables_from = MAIN_DB_PREFIX."propal as c,".MAIN_DB_PREFIX."propaldet as d"; |
|
218 | + $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".$socid; |
|
219 | + $where.= " AND d.fk_propal = c.rowid"; |
|
220 | + $where.= " AND c.entity = ".$conf->entity; |
|
221 | + $datePrint = 'c.datep'; |
|
222 | + $doc_number='c.ref'; |
|
223 | + $thirdTypeSelect='customer'; |
|
224 | 224 | } |
225 | 225 | if ($type_element == 'order') |
226 | 226 | { |
227 | - require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; |
|
228 | - $documentstatic=new Commande($db); |
|
229 | - $sql_select = 'SELECT c.rowid as doc_id, c.ref as doc_number, \'1\' as doc_type, c.date_commande as dateprint, c.fk_statut as status, '; |
|
230 | - $tables_from = MAIN_DB_PREFIX."commande as c,".MAIN_DB_PREFIX."commandedet as d"; |
|
231 | - $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".$socid; |
|
232 | - $where.= " AND d.fk_commande = c.rowid"; |
|
233 | - $where.= " AND c.entity = ".$conf->entity; |
|
234 | - $dateprint = 'c.date_commande'; |
|
235 | - $doc_number='c.ref'; |
|
236 | - $thirdTypeSelect='customer'; |
|
227 | + require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; |
|
228 | + $documentstatic=new Commande($db); |
|
229 | + $sql_select = 'SELECT c.rowid as doc_id, c.ref as doc_number, \'1\' as doc_type, c.date_commande as dateprint, c.fk_statut as status, '; |
|
230 | + $tables_from = MAIN_DB_PREFIX."commande as c,".MAIN_DB_PREFIX."commandedet as d"; |
|
231 | + $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".$socid; |
|
232 | + $where.= " AND d.fk_commande = c.rowid"; |
|
233 | + $where.= " AND c.entity = ".$conf->entity; |
|
234 | + $dateprint = 'c.date_commande'; |
|
235 | + $doc_number='c.ref'; |
|
236 | + $thirdTypeSelect='customer'; |
|
237 | 237 | } |
238 | 238 | if ($type_element == 'supplier_invoice') |
239 | 239 | { // Supplier : Show products from invoices. |
240 | - require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; |
|
241 | - $documentstatic=new FactureFournisseur($db); |
|
242 | - $sql_select = 'SELECT f.rowid as doc_id, f.ref as doc_number, \'1\' as doc_type, f.datef as dateprint, f.fk_statut as status, f.paye as paid, '; |
|
243 | - $tables_from = MAIN_DB_PREFIX."facture_fourn as f,".MAIN_DB_PREFIX."facture_fourn_det as d"; |
|
244 | - $where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".$socid; |
|
245 | - $where.= " AND d.fk_facture_fourn = f.rowid"; |
|
246 | - $where.= " AND f.entity = ".$conf->entity; |
|
247 | - $dateprint = 'f.datef'; |
|
248 | - $doc_number='f.ref'; |
|
249 | - $thirdTypeSelect='supplier'; |
|
240 | + require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; |
|
241 | + $documentstatic=new FactureFournisseur($db); |
|
242 | + $sql_select = 'SELECT f.rowid as doc_id, f.ref as doc_number, \'1\' as doc_type, f.datef as dateprint, f.fk_statut as status, f.paye as paid, '; |
|
243 | + $tables_from = MAIN_DB_PREFIX."facture_fourn as f,".MAIN_DB_PREFIX."facture_fourn_det as d"; |
|
244 | + $where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".$socid; |
|
245 | + $where.= " AND d.fk_facture_fourn = f.rowid"; |
|
246 | + $where.= " AND f.entity = ".$conf->entity; |
|
247 | + $dateprint = 'f.datef'; |
|
248 | + $doc_number='f.ref'; |
|
249 | + $thirdTypeSelect='supplier'; |
|
250 | 250 | } |
251 | 251 | if ($type_element == 'supplier_proposal') |
252 | 252 | { |
@@ -263,30 +263,30 @@ discard block |
||
263 | 263 | } |
264 | 264 | if ($type_element == 'supplier_order') |
265 | 265 | { // Supplier : Show products from orders. |
266 | - require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; |
|
267 | - $documentstatic=new CommandeFournisseur($db); |
|
268 | - $sql_select = 'SELECT c.rowid as doc_id, c.ref as doc_number, \'1\' as doc_type, c.date_valid as dateprint, c.fk_statut as status, '; |
|
269 | - $tables_from = MAIN_DB_PREFIX."commande_fournisseur as c,".MAIN_DB_PREFIX."commande_fournisseurdet as d"; |
|
270 | - $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".$socid; |
|
271 | - $where.= " AND d.fk_commande = c.rowid"; |
|
272 | - $where.= " AND c.entity = ".$conf->entity; |
|
273 | - $dateprint = 'c.date_valid'; |
|
274 | - $doc_number='c.ref'; |
|
275 | - $thirdTypeSelect='supplier'; |
|
266 | + require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; |
|
267 | + $documentstatic=new CommandeFournisseur($db); |
|
268 | + $sql_select = 'SELECT c.rowid as doc_id, c.ref as doc_number, \'1\' as doc_type, c.date_valid as dateprint, c.fk_statut as status, '; |
|
269 | + $tables_from = MAIN_DB_PREFIX."commande_fournisseur as c,".MAIN_DB_PREFIX."commande_fournisseurdet as d"; |
|
270 | + $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".$socid; |
|
271 | + $where.= " AND d.fk_commande = c.rowid"; |
|
272 | + $where.= " AND c.entity = ".$conf->entity; |
|
273 | + $dateprint = 'c.date_valid'; |
|
274 | + $doc_number='c.ref'; |
|
275 | + $thirdTypeSelect='supplier'; |
|
276 | 276 | } |
277 | 277 | if ($type_element == 'contract') |
278 | 278 | { // Order |
279 | - require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php'; |
|
280 | - $documentstatic=new Contrat($db); |
|
281 | - $documentstaticline=new ContratLigne($db); |
|
282 | - $sql_select = 'SELECT c.rowid as doc_id, c.ref as doc_number, \'1\' as doc_type, c.date_contrat as dateprint, d.statut as status, '; |
|
283 | - $tables_from = MAIN_DB_PREFIX."contrat as c,".MAIN_DB_PREFIX."contratdet as d"; |
|
284 | - $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".$socid; |
|
285 | - $where.= " AND d.fk_contrat = c.rowid"; |
|
286 | - $where.= " AND c.entity = ".$conf->entity; |
|
287 | - $dateprint = 'c.date_valid'; |
|
288 | - $doc_number='c.ref'; |
|
289 | - $thirdTypeSelect='customer'; |
|
279 | + require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php'; |
|
280 | + $documentstatic=new Contrat($db); |
|
281 | + $documentstaticline=new ContratLigne($db); |
|
282 | + $sql_select = 'SELECT c.rowid as doc_id, c.ref as doc_number, \'1\' as doc_type, c.date_contrat as dateprint, d.statut as status, '; |
|
283 | + $tables_from = MAIN_DB_PREFIX."contrat as c,".MAIN_DB_PREFIX."contratdet as d"; |
|
284 | + $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".$socid; |
|
285 | + $where.= " AND d.fk_contrat = c.rowid"; |
|
286 | + $where.= " AND c.entity = ".$conf->entity; |
|
287 | + $dateprint = 'c.date_valid'; |
|
288 | + $doc_number='c.ref'; |
|
289 | + $thirdTypeSelect='customer'; |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | $parameters=array(); |
@@ -294,45 +294,45 @@ discard block |
||
294 | 294 | |
295 | 295 | if (!empty($sql_select)) |
296 | 296 | { |
297 | - $sql = $sql_select; |
|
298 | - $sql.= ' d.description as description,'; |
|
299 | - if ($type_element != 'fichinter' && $type_element != 'contract' && $type_element != 'supplier_proposal') $sql.= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_start, d.date_end, d.qty, d.qty as prod_qty, d.total_ht as total_ht, '; |
|
300 | - if ($type_element == 'supplier_proposal') $sql.= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.qty, d.qty as prod_qty, d.total_ht as total_ht, '; |
|
301 | - if ($type_element == 'contract') $sql.= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_ouverture as date_start, d.date_cloture as date_end, d.qty, d.qty as prod_qty, d.total_ht as total_ht, '; |
|
302 | - if ($type_element != 'fichinter') $sql.= ' p.ref as ref, p.rowid as prod_id, p.rowid as fk_product, p.fk_product_type as prod_type, p.fk_product_type as fk_product_type, p.entity as pentity,'; |
|
303 | - $sql.= " s.rowid as socid "; |
|
304 | - if ($type_element != 'fichinter') $sql.= ", p.ref as prod_ref, p.label as product_label"; |
|
305 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".$tables_from; |
|
306 | - if ($type_element != 'fichinter') $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON d.fk_product = p.rowid '; |
|
307 | - $sql.= $where; |
|
308 | - if ($month > 0) { |
|
309 | - if ($year > 0) { |
|
310 | - $start = dol_mktime(0, 0, 0, $month, 1, $year); |
|
311 | - $end = dol_time_plus_duree($start,1,'m') - 1; |
|
312 | - $sql.= " AND ".$dateprint." BETWEEN '".$db->idate($start)."' AND '".$db->idate($end)."'"; |
|
313 | - } else { |
|
314 | - $sql.= " AND date_format(".$dateprint.", '%m') = '".sprintf('%02d',$month)."'"; |
|
315 | - } |
|
316 | - } else if ($year > 0) { |
|
317 | - $start = dol_mktime(0, 0, 0, 1, 1, $year); |
|
318 | - $end = dol_time_plus_duree($start,1,'y') - 1; |
|
319 | - $sql.= " AND ".$dateprint." BETWEEN '".$db->idate($start)."' AND '".$db->idate($end)."'"; |
|
320 | - } |
|
321 | - if ($sref) $sql.= " AND ".$doc_number." LIKE '%".$db->escape($sref)."%'"; |
|
322 | - if ($sprod_fulldescr) |
|
323 | - { |
|
324 | - $sql.= " AND (d.description LIKE '%".$db->escape($sprod_fulldescr)."%'"; |
|
325 | - if (GETPOST('type_element') != 'fichinter') $sql.= " OR p.ref LIKE '%".$db->escape($sprod_fulldescr)."%'"; |
|
326 | - if (GETPOST('type_element') != 'fichinter') $sql.= " OR p.label LIKE '%".$db->escape($sprod_fulldescr)."%'"; |
|
327 | - $sql.=")"; |
|
328 | - } |
|
329 | - $sql.= $db->order($sortfield,$sortorder); |
|
330 | - |
|
331 | - $resql=$db->query($sql); |
|
332 | - $totalnboflines = $db->num_rows($resql); |
|
333 | - |
|
334 | - $sql.= $db->plimit($limit + 1, $offset); |
|
335 | - //print $sql; |
|
297 | + $sql = $sql_select; |
|
298 | + $sql.= ' d.description as description,'; |
|
299 | + if ($type_element != 'fichinter' && $type_element != 'contract' && $type_element != 'supplier_proposal') $sql.= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_start, d.date_end, d.qty, d.qty as prod_qty, d.total_ht as total_ht, '; |
|
300 | + if ($type_element == 'supplier_proposal') $sql.= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.qty, d.qty as prod_qty, d.total_ht as total_ht, '; |
|
301 | + if ($type_element == 'contract') $sql.= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_ouverture as date_start, d.date_cloture as date_end, d.qty, d.qty as prod_qty, d.total_ht as total_ht, '; |
|
302 | + if ($type_element != 'fichinter') $sql.= ' p.ref as ref, p.rowid as prod_id, p.rowid as fk_product, p.fk_product_type as prod_type, p.fk_product_type as fk_product_type, p.entity as pentity,'; |
|
303 | + $sql.= " s.rowid as socid "; |
|
304 | + if ($type_element != 'fichinter') $sql.= ", p.ref as prod_ref, p.label as product_label"; |
|
305 | + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".$tables_from; |
|
306 | + if ($type_element != 'fichinter') $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON d.fk_product = p.rowid '; |
|
307 | + $sql.= $where; |
|
308 | + if ($month > 0) { |
|
309 | + if ($year > 0) { |
|
310 | + $start = dol_mktime(0, 0, 0, $month, 1, $year); |
|
311 | + $end = dol_time_plus_duree($start,1,'m') - 1; |
|
312 | + $sql.= " AND ".$dateprint." BETWEEN '".$db->idate($start)."' AND '".$db->idate($end)."'"; |
|
313 | + } else { |
|
314 | + $sql.= " AND date_format(".$dateprint.", '%m') = '".sprintf('%02d',$month)."'"; |
|
315 | + } |
|
316 | + } else if ($year > 0) { |
|
317 | + $start = dol_mktime(0, 0, 0, 1, 1, $year); |
|
318 | + $end = dol_time_plus_duree($start,1,'y') - 1; |
|
319 | + $sql.= " AND ".$dateprint." BETWEEN '".$db->idate($start)."' AND '".$db->idate($end)."'"; |
|
320 | + } |
|
321 | + if ($sref) $sql.= " AND ".$doc_number." LIKE '%".$db->escape($sref)."%'"; |
|
322 | + if ($sprod_fulldescr) |
|
323 | + { |
|
324 | + $sql.= " AND (d.description LIKE '%".$db->escape($sprod_fulldescr)."%'"; |
|
325 | + if (GETPOST('type_element') != 'fichinter') $sql.= " OR p.ref LIKE '%".$db->escape($sprod_fulldescr)."%'"; |
|
326 | + if (GETPOST('type_element') != 'fichinter') $sql.= " OR p.label LIKE '%".$db->escape($sprod_fulldescr)."%'"; |
|
327 | + $sql.=")"; |
|
328 | + } |
|
329 | + $sql.= $db->order($sortfield,$sortorder); |
|
330 | + |
|
331 | + $resql=$db->query($sql); |
|
332 | + $totalnboflines = $db->num_rows($resql); |
|
333 | + |
|
334 | + $sql.= $db->plimit($limit + 1, $offset); |
|
335 | + //print $sql; |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | $disabled=0; |
@@ -359,19 +359,19 @@ discard block |
||
359 | 359 | |
360 | 360 | if ($sql_select) |
361 | 361 | { |
362 | - $resql=$db->query($sql); |
|
363 | - if (!$resql) dol_print_error($db); |
|
362 | + $resql=$db->query($sql); |
|
363 | + if (!$resql) dol_print_error($db); |
|
364 | 364 | |
365 | - $num = $db->num_rows($resql); |
|
365 | + $num = $db->num_rows($resql); |
|
366 | 366 | |
367 | - $param="&socid=".$socid."&type_element=".$type_element; |
|
367 | + $param="&socid=".$socid."&type_element=".$type_element; |
|
368 | 368 | if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; |
369 | - if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; |
|
370 | - if ($sprod_fulldescr) $param.= "&sprod_fulldescr=".urlencode($sprod_fulldescr); |
|
371 | - if ($sref) $param.= "&sref=".urlencode($sref); |
|
372 | - if ($month) $param.= "&month=".$month; |
|
373 | - if ($year) $param.= "&year=".$year; |
|
374 | - if ($optioncss != '') $param.='&optioncss='.$optioncss; |
|
369 | + if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; |
|
370 | + if ($sprod_fulldescr) $param.= "&sprod_fulldescr=".urlencode($sprod_fulldescr); |
|
371 | + if ($sref) $param.= "&sref=".urlencode($sref); |
|
372 | + if ($month) $param.= "&month=".$month; |
|
373 | + if ($year) $param.= "&year=".$year; |
|
374 | + if ($optioncss != '') $param.='&optioncss='.$optioncss; |
|
375 | 375 | |
376 | 376 | print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder,'',$num, $totalnboflines, '', 0, '', '', $limit); |
377 | 377 | |
@@ -414,167 +414,167 @@ discard block |
||
414 | 414 | print "</tr>\n"; |
415 | 415 | |
416 | 416 | |
417 | - $i = 0; |
|
418 | - while (($objp = $db->fetch_object($resql)) && $i < min($num, $limit)) |
|
419 | - { |
|
420 | - $documentstatic->id=$objp->doc_id; |
|
421 | - $documentstatic->ref=$objp->doc_number; |
|
422 | - $documentstatic->type=$objp->doc_type; |
|
423 | - $documentstatic->fk_statut=$objp->status; |
|
424 | - $documentstatic->fk_status=$objp->status; |
|
425 | - $documentstatic->statut=$objp->status; |
|
426 | - $documentstatic->status=$objp->status; |
|
427 | - $documentstatic->paye=$objp->paid; |
|
428 | - |
|
429 | - if (is_object($documentstaticline)) $documentstaticline->statut=$objp->status; |
|
430 | - |
|
431 | - print '<tr class="oddeven">'; |
|
432 | - print '<td class="nobordernopadding nowrap" width="100">'; |
|
433 | - print $documentstatic->getNomUrl(1); |
|
434 | - print '</td>'; |
|
435 | - print '<td align="center" width="80">'.dol_print_date($db->jdate($objp->dateprint),'day').'</td>'; |
|
436 | - |
|
437 | - // Status |
|
438 | - print '<td align="center">'; |
|
439 | - if ($type_element == 'contract') |
|
440 | - { |
|
441 | - print $documentstaticline->getLibStatut(2); |
|
442 | - } |
|
443 | - else |
|
444 | - { |
|
445 | - print $documentstatic->getLibStatut(2); |
|
446 | - } |
|
447 | - print '</td>'; |
|
448 | - |
|
449 | - print '<td>'; |
|
450 | - |
|
451 | - // Define text, description and type |
|
452 | - $text=''; $description=''; $type=0; |
|
453 | - |
|
454 | - // Code to show product duplicated from commonobject->printObjectLine |
|
455 | - if ($objp->fk_product > 0) |
|
456 | - { |
|
457 | - $product_static = new Product($db); |
|
458 | - |
|
459 | - $product_static->type=$objp->fk_product_type; |
|
460 | - $product_static->id=$objp->fk_product; |
|
461 | - $product_static->ref=$objp->ref; |
|
462 | - $product_static->entity=$objp->pentity; |
|
463 | - $text=$product_static->getNomUrl(1); |
|
464 | - } |
|
465 | - |
|
466 | - // Product |
|
467 | - if ($objp->fk_product > 0) |
|
468 | - { |
|
469 | - // Define output language |
|
470 | - if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) |
|
471 | - { |
|
472 | - $prod = new Product($db); |
|
473 | - $prod->fetch($objp->fk_product); |
|
474 | - |
|
475 | - $outputlangs = $langs; |
|
476 | - $newlang=''; |
|
477 | - if (empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09'); |
|
478 | - if (empty($newlang)) $newlang=$object->default_lang; |
|
479 | - if (! empty($newlang)) |
|
480 | - { |
|
481 | - $outputlangs = new Translate("",$conf); |
|
482 | - $outputlangs->setDefaultLang($newlang); |
|
483 | - } |
|
484 | - |
|
485 | - $label = (! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $objp->product_label; |
|
486 | - } |
|
487 | - else |
|
488 | - { |
|
489 | - $label = $objp->product_label; |
|
490 | - } |
|
491 | - |
|
492 | - $text.= ' - '.(! empty($objp->label)?$objp->label:$label); |
|
493 | - $description=(! empty($conf->global->PRODUIT_DESC_IN_FORM)?'':dol_htmlentitiesbr($objp->description)); |
|
494 | - } |
|
495 | - |
|
496 | - if (($objp->info_bits & 2) == 2) { ?> |
|
417 | + $i = 0; |
|
418 | + while (($objp = $db->fetch_object($resql)) && $i < min($num, $limit)) |
|
419 | + { |
|
420 | + $documentstatic->id=$objp->doc_id; |
|
421 | + $documentstatic->ref=$objp->doc_number; |
|
422 | + $documentstatic->type=$objp->doc_type; |
|
423 | + $documentstatic->fk_statut=$objp->status; |
|
424 | + $documentstatic->fk_status=$objp->status; |
|
425 | + $documentstatic->statut=$objp->status; |
|
426 | + $documentstatic->status=$objp->status; |
|
427 | + $documentstatic->paye=$objp->paid; |
|
428 | + |
|
429 | + if (is_object($documentstaticline)) $documentstaticline->statut=$objp->status; |
|
430 | + |
|
431 | + print '<tr class="oddeven">'; |
|
432 | + print '<td class="nobordernopadding nowrap" width="100">'; |
|
433 | + print $documentstatic->getNomUrl(1); |
|
434 | + print '</td>'; |
|
435 | + print '<td align="center" width="80">'.dol_print_date($db->jdate($objp->dateprint),'day').'</td>'; |
|
436 | + |
|
437 | + // Status |
|
438 | + print '<td align="center">'; |
|
439 | + if ($type_element == 'contract') |
|
440 | + { |
|
441 | + print $documentstaticline->getLibStatut(2); |
|
442 | + } |
|
443 | + else |
|
444 | + { |
|
445 | + print $documentstatic->getLibStatut(2); |
|
446 | + } |
|
447 | + print '</td>'; |
|
448 | + |
|
449 | + print '<td>'; |
|
450 | + |
|
451 | + // Define text, description and type |
|
452 | + $text=''; $description=''; $type=0; |
|
453 | + |
|
454 | + // Code to show product duplicated from commonobject->printObjectLine |
|
455 | + if ($objp->fk_product > 0) |
|
456 | + { |
|
457 | + $product_static = new Product($db); |
|
458 | + |
|
459 | + $product_static->type=$objp->fk_product_type; |
|
460 | + $product_static->id=$objp->fk_product; |
|
461 | + $product_static->ref=$objp->ref; |
|
462 | + $product_static->entity=$objp->pentity; |
|
463 | + $text=$product_static->getNomUrl(1); |
|
464 | + } |
|
465 | + |
|
466 | + // Product |
|
467 | + if ($objp->fk_product > 0) |
|
468 | + { |
|
469 | + // Define output language |
|
470 | + if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) |
|
471 | + { |
|
472 | + $prod = new Product($db); |
|
473 | + $prod->fetch($objp->fk_product); |
|
474 | + |
|
475 | + $outputlangs = $langs; |
|
476 | + $newlang=''; |
|
477 | + if (empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09'); |
|
478 | + if (empty($newlang)) $newlang=$object->default_lang; |
|
479 | + if (! empty($newlang)) |
|
480 | + { |
|
481 | + $outputlangs = new Translate("",$conf); |
|
482 | + $outputlangs->setDefaultLang($newlang); |
|
483 | + } |
|
484 | + |
|
485 | + $label = (! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $objp->product_label; |
|
486 | + } |
|
487 | + else |
|
488 | + { |
|
489 | + $label = $objp->product_label; |
|
490 | + } |
|
491 | + |
|
492 | + $text.= ' - '.(! empty($objp->label)?$objp->label:$label); |
|
493 | + $description=(! empty($conf->global->PRODUIT_DESC_IN_FORM)?'':dol_htmlentitiesbr($objp->description)); |
|
494 | + } |
|
495 | + |
|
496 | + if (($objp->info_bits & 2) == 2) { ?> |
|
497 | 497 | <a href="<?php echo DOL_URL_ROOT.'/comm/remx.php?id='.$object->id; ?>"> |
498 | 498 | <?php |
499 | - $txt=''; |
|
500 | - print img_object($langs->trans("ShowReduc"),'reduc').' '; |
|
501 | - if ($objp->description == '(DEPOSIT)') $txt=$langs->trans("Deposit"); |
|
502 | - elseif ($objp->description == '(EXCESS RECEIVED)') $txt=$langs->trans("ExcessReceived"); |
|
503 | - elseif ($objp->description == '(EXCESS PAID)') $txt=$langs->trans("ExcessPaid"); |
|
504 | - //else $txt=$langs->trans("Discount"); |
|
505 | - print $txt; |
|
506 | - ?> |
|
499 | + $txt=''; |
|
500 | + print img_object($langs->trans("ShowReduc"),'reduc').' '; |
|
501 | + if ($objp->description == '(DEPOSIT)') $txt=$langs->trans("Deposit"); |
|
502 | + elseif ($objp->description == '(EXCESS RECEIVED)') $txt=$langs->trans("ExcessReceived"); |
|
503 | + elseif ($objp->description == '(EXCESS PAID)') $txt=$langs->trans("ExcessPaid"); |
|
504 | + //else $txt=$langs->trans("Discount"); |
|
505 | + print $txt; |
|
506 | + ?> |
|
507 | 507 | </a> |
508 | 508 | <?php |
509 | - if ($objp->description) |
|
510 | - { |
|
511 | - if ($objp->description == '(CREDIT_NOTE)' && $objp->fk_remise_except > 0) |
|
512 | - { |
|
513 | - $discount=new DiscountAbsolute($db); |
|
514 | - $discount->fetch($objp->fk_remise_except); |
|
515 | - echo ($txt?' - ':'').$langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0)); |
|
516 | - } |
|
517 | - if ($objp->description == '(EXCESS RECEIVED)' && $objp->fk_remise_except > 0) |
|
518 | - { |
|
519 | - $discount=new DiscountAbsolute($db); |
|
520 | - $discount->fetch($objp->fk_remise_except); |
|
521 | - echo ($txt?' - ':'').$langs->transnoentities("DiscountFromExcessReceived",$discount->getNomUrl(0)); |
|
522 | - } |
|
523 | - elseif ($objp->description == '(EXCESS PAID)' && $objp->fk_remise_except > 0) |
|
524 | - { |
|
525 | - $discount=new DiscountAbsolute($db); |
|
526 | - $discount->fetch($objp->fk_remise_except); |
|
527 | - echo ($txt?' - ':'').$langs->transnoentities("DiscountFromExcessPaid",$discount->getNomUrl(0)); |
|
528 | - } |
|
529 | - elseif ($objp->description == '(DEPOSIT)' && $objp->fk_remise_except > 0) |
|
530 | - { |
|
531 | - $discount=new DiscountAbsolute($db); |
|
532 | - $discount->fetch($objp->fk_remise_except); |
|
533 | - echo ($txt?' - ':'').$langs->transnoentities("DiscountFromDeposit",$discount->getNomUrl(0)); |
|
534 | - // Add date of deposit |
|
535 | - if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) echo ' ('.dol_print_date($discount->datec).')'; |
|
536 | - } |
|
537 | - else |
|
538 | - { |
|
539 | - echo ($txt?' - ':'').dol_htmlentitiesbr($objp->description); |
|
540 | - } |
|
541 | - } |
|
542 | - } |
|
543 | - else |
|
544 | - { |
|
545 | - if ($objp->fk_product > 0) { |
|
546 | - |
|
547 | - echo $form->textwithtooltip($text,$description,3,'','',$i,0,''); |
|
548 | - |
|
549 | - // Show range |
|
550 | - echo get_date_range($objp->date_start, $objp->date_end); |
|
551 | - |
|
552 | - // Add description in form |
|
553 | - if (! empty($conf->global->PRODUIT_DESC_IN_FORM)) |
|
554 | - { |
|
555 | - print (! empty($objp->description) && $objp->description!=$objp->product_label)?'<br>'.dol_htmlentitiesbr($objp->description):''; |
|
556 | - } |
|
557 | - } else { |
|
558 | - |
|
559 | - if (! empty($objp->label) || ! empty($objp->description)) |
|
560 | - { |
|
561 | - if ($type==1) $text = img_object($langs->trans('Service'),'service'); |
|
562 | - else $text = img_object($langs->trans('Product'),'product'); |
|
563 | - |
|
564 | - if (! empty($objp->label)) { |
|
565 | - $text.= ' <strong>'.$objp->label.'</strong>'; |
|
566 | - echo $form->textwithtooltip($text,dol_htmlentitiesbr($objp->description),3,'','',$i,0,''); |
|
567 | - } else { |
|
568 | - echo $text.' '.dol_htmlentitiesbr($objp->description); |
|
569 | - } |
|
570 | - } |
|
571 | - |
|
572 | - // Show range |
|
573 | - echo get_date_range($objp->date_start,$objp->date_end); |
|
574 | - } |
|
575 | - } |
|
576 | - |
|
577 | - /* |
|
509 | + if ($objp->description) |
|
510 | + { |
|
511 | + if ($objp->description == '(CREDIT_NOTE)' && $objp->fk_remise_except > 0) |
|
512 | + { |
|
513 | + $discount=new DiscountAbsolute($db); |
|
514 | + $discount->fetch($objp->fk_remise_except); |
|
515 | + echo ($txt?' - ':'').$langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0)); |
|
516 | + } |
|
517 | + if ($objp->description == '(EXCESS RECEIVED)' && $objp->fk_remise_except > 0) |
|
518 | + { |
|
519 | + $discount=new DiscountAbsolute($db); |
|
520 | + $discount->fetch($objp->fk_remise_except); |
|
521 | + echo ($txt?' - ':'').$langs->transnoentities("DiscountFromExcessReceived",$discount->getNomUrl(0)); |
|
522 | + } |
|
523 | + elseif ($objp->description == '(EXCESS PAID)' && $objp->fk_remise_except > 0) |
|
524 | + { |
|
525 | + $discount=new DiscountAbsolute($db); |
|
526 | + $discount->fetch($objp->fk_remise_except); |
|
527 | + echo ($txt?' - ':'').$langs->transnoentities("DiscountFromExcessPaid",$discount->getNomUrl(0)); |
|
528 | + } |
|
529 | + elseif ($objp->description == '(DEPOSIT)' && $objp->fk_remise_except > 0) |
|
530 | + { |
|
531 | + $discount=new DiscountAbsolute($db); |
|
532 | + $discount->fetch($objp->fk_remise_except); |
|
533 | + echo ($txt?' - ':'').$langs->transnoentities("DiscountFromDeposit",$discount->getNomUrl(0)); |
|
534 | + // Add date of deposit |
|
535 | + if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) echo ' ('.dol_print_date($discount->datec).')'; |
|
536 | + } |
|
537 | + else |
|
538 | + { |
|
539 | + echo ($txt?' - ':'').dol_htmlentitiesbr($objp->description); |
|
540 | + } |
|
541 | + } |
|
542 | + } |
|
543 | + else |
|
544 | + { |
|
545 | + if ($objp->fk_product > 0) { |
|
546 | + |
|
547 | + echo $form->textwithtooltip($text,$description,3,'','',$i,0,''); |
|
548 | + |
|
549 | + // Show range |
|
550 | + echo get_date_range($objp->date_start, $objp->date_end); |
|
551 | + |
|
552 | + // Add description in form |
|
553 | + if (! empty($conf->global->PRODUIT_DESC_IN_FORM)) |
|
554 | + { |
|
555 | + print (! empty($objp->description) && $objp->description!=$objp->product_label)?'<br>'.dol_htmlentitiesbr($objp->description):''; |
|
556 | + } |
|
557 | + } else { |
|
558 | + |
|
559 | + if (! empty($objp->label) || ! empty($objp->description)) |
|
560 | + { |
|
561 | + if ($type==1) $text = img_object($langs->trans('Service'),'service'); |
|
562 | + else $text = img_object($langs->trans('Product'),'product'); |
|
563 | + |
|
564 | + if (! empty($objp->label)) { |
|
565 | + $text.= ' <strong>'.$objp->label.'</strong>'; |
|
566 | + echo $form->textwithtooltip($text,dol_htmlentitiesbr($objp->description),3,'','',$i,0,''); |
|
567 | + } else { |
|
568 | + echo $text.' '.dol_htmlentitiesbr($objp->description); |
|
569 | + } |
|
570 | + } |
|
571 | + |
|
572 | + // Show range |
|
573 | + echo get_date_range($objp->date_start,$objp->date_end); |
|
574 | + } |
|
575 | + } |
|
576 | + |
|
577 | + /* |
|
578 | 578 | $prodreftxt=''; |
579 | 579 | if ($objp->prod_id > 0) |
580 | 580 | { |
@@ -592,35 +592,35 @@ discard block |
||
592 | 592 | $prodreftxt .= (! empty($objp->description) && $objp->description!=$objp->product_label)?'<br>'.dol_htmlentitiesbr($objp->description):''; |
593 | 593 | } |
594 | 594 | */ |
595 | - print '</td>'; |
|
595 | + print '</td>'; |
|
596 | 596 | |
597 | - //print '<td align="left">'.$prodreftxt.'</td>'; |
|
597 | + //print '<td align="left">'.$prodreftxt.'</td>'; |
|
598 | 598 | |
599 | - print '<td align="right">'.$objp->prod_qty.'</td>'; |
|
600 | - $total_qty+=$objp->prod_qty; |
|
599 | + print '<td align="right">'.$objp->prod_qty.'</td>'; |
|
600 | + $total_qty+=$objp->prod_qty; |
|
601 | 601 | |
602 | - print '<td align="right">'.price($objp->total_ht).'</td>'; |
|
603 | - $total_ht+=$objp->total_ht; |
|
602 | + print '<td align="right">'.price($objp->total_ht).'</td>'; |
|
603 | + $total_ht+=$objp->total_ht; |
|
604 | 604 | |
605 | - print '<td align="right">'.price($objp->total_ht/(empty($objp->prod_qty)?1:$objp->prod_qty)).'</td>'; |
|
605 | + print '<td align="right">'.price($objp->total_ht/(empty($objp->prod_qty)?1:$objp->prod_qty)).'</td>'; |
|
606 | 606 | |
607 | - print "</tr>\n"; |
|
608 | - $i++; |
|
609 | - } |
|
607 | + print "</tr>\n"; |
|
608 | + $i++; |
|
609 | + } |
|
610 | 610 | |
611 | - print '<tr class="liste_total">'; |
|
612 | - print '<td>' . $langs->trans('Total') . '</td>'; |
|
613 | - print '<td colspan="3"></td>'; |
|
614 | - print '<td align="right">' . $total_qty . '</td>'; |
|
615 | - print '<td align="right">' . price($total_ht) . '</td>'; |
|
616 | - print '<td align="right">' . price($total_ht/(empty($total_qty)?1:$total_qty)) . '</td>'; |
|
617 | - print "</table>"; |
|
618 | - print '</div>'; |
|
611 | + print '<tr class="liste_total">'; |
|
612 | + print '<td>' . $langs->trans('Total') . '</td>'; |
|
613 | + print '<td colspan="3"></td>'; |
|
614 | + print '<td align="right">' . $total_qty . '</td>'; |
|
615 | + print '<td align="right">' . price($total_ht) . '</td>'; |
|
616 | + print '<td align="right">' . price($total_ht/(empty($total_qty)?1:$total_qty)) . '</td>'; |
|
617 | + print "</table>"; |
|
618 | + print '</div>'; |
|
619 | 619 | |
620 | - if ($num > $limit) { |
|
621 | - print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder,'',$num); |
|
622 | - } |
|
623 | - $db->free($resql); |
|
620 | + if ($num > $limit) { |
|
621 | + print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder,'',$num); |
|
622 | + } |
|
623 | + $db->free($resql); |
|
624 | 624 | } |
625 | 625 | else if (empty($type_element) || $type_element == -1) |
626 | 626 | { |
@@ -636,18 +636,18 @@ discard block |
||
636 | 636 | print_liste_field_titre('Quantity',$_SERVER['PHP_SELF'],'prod_qty','',$param,'align="right"',$sortfield,$sortorder); |
637 | 637 | print "</tr>\n"; |
638 | 638 | |
639 | - print '<tr class="oddeven"><td class="opacitymedium" colspan="5">'.$langs->trans("SelectElementAndClick", $langs->transnoentitiesnoconv("Search")).'</td></tr>'; |
|
639 | + print '<tr class="oddeven"><td class="opacitymedium" colspan="5">'.$langs->trans("SelectElementAndClick", $langs->transnoentitiesnoconv("Search")).'</td></tr>'; |
|
640 | 640 | |
641 | - print "</table>"; |
|
641 | + print "</table>"; |
|
642 | 642 | } |
643 | 643 | else { |
644 | 644 | print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder,'',$num, '', ''); |
645 | 645 | |
646 | 646 | print '<table class="liste" width="100%">'."\n"; |
647 | 647 | |
648 | - print '<tr class="oddeven"><td class="opacitymedium" colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>'; |
|
648 | + print '<tr class="oddeven"><td class="opacitymedium" colspan="5">'.$langs->trans("FeatureNotYetAvailable").'</td></tr>'; |
|
649 | 649 | |
650 | - print "</table>"; |
|
650 | + print "</table>"; |
|
651 | 651 | } |
652 | 652 | |
653 | 653 | print "</form>"; |
@@ -33,10 +33,14 @@ discard block |
||
33 | 33 | |
34 | 34 | // Security check |
35 | 35 | $socid = GETPOST('socid','int'); |
36 | -if ($user->societe_id) $socid=$user->societe_id; |
|
36 | +if ($user->societe_id) { |
|
37 | + $socid=$user->societe_id; |
|
38 | +} |
|
37 | 39 | $result = restrictedArea($user, 'societe', $socid, '&societe'); |
38 | 40 | $object = new Societe($db); |
39 | -if ($socid > 0) $object->fetch($socid); |
|
41 | +if ($socid > 0) { |
|
42 | + $object->fetch($socid); |
|
43 | +} |
|
40 | 44 | |
41 | 45 | // Sort & Order fields |
42 | 46 | $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; |
@@ -47,8 +51,12 @@ discard block |
||
47 | 51 | $offset = $limit * $page; |
48 | 52 | $pageprev = $page - 1; |
49 | 53 | $pagenext = $page + 1; |
50 | -if (! $sortorder) $sortorder='DESC'; |
|
51 | -if (! $sortfield) $sortfield='dateprint'; |
|
54 | +if (! $sortorder) { |
|
55 | + $sortorder='DESC'; |
|
56 | +} |
|
57 | +if (! $sortfield) { |
|
58 | + $sortfield='dateprint'; |
|
59 | +} |
|
52 | 60 | |
53 | 61 | // Search fields |
54 | 62 | $sref=GETPOST("sref"); |
@@ -57,9 +65,11 @@ discard block |
||
57 | 65 | $year = GETPOST('year','int'); |
58 | 66 | |
59 | 67 | // Clean up on purge search criteria ? |
60 | -if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // Both test are required to be compatible with all browsers |
|
68 | +if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) { |
|
69 | + // Both test are required to be compatible with all browsers |
|
61 | 70 | { |
62 | 71 | $sref=''; |
72 | +} |
|
63 | 73 | $sprod_fulldescr=''; |
64 | 74 | $year=''; |
65 | 75 | $month=''; |
@@ -81,7 +91,9 @@ discard block |
||
81 | 91 | |
82 | 92 | $parameters=array('id'=>$socid); |
83 | 93 | $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
84 | -if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
|
94 | +if ($reshook < 0) { |
|
95 | + setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
|
96 | +} |
|
85 | 97 | |
86 | 98 | |
87 | 99 | |
@@ -94,7 +106,9 @@ discard block |
||
94 | 106 | $productstatic=new Product($db); |
95 | 107 | |
96 | 108 | $title = $langs->trans("Referers",$object->name); |
97 | -if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title; |
|
109 | +if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) { |
|
110 | + $title=$object->name." - ".$title; |
|
111 | +} |
|
98 | 112 | $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; |
99 | 113 | llxHeader('',$title,$help_url); |
100 | 114 | |
@@ -116,10 +130,12 @@ discard block |
||
116 | 130 | print '<div class="underbanner clearboth"></div>'; |
117 | 131 | print '<table class="border" width="100%">'; |
118 | 132 | |
119 | -if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field |
|
133 | +if (! empty($conf->global->SOCIETE_USEPREFIX)) { |
|
134 | + // Old not used prefix field |
|
120 | 135 | { |
121 | 136 | print '<tr><td class="titlefield">'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>'; |
122 | 137 | } |
138 | +} |
|
123 | 139 | |
124 | 140 | //if ($conf->agenda->enabled && $user->rights->agenda->myactions->read) $elementTypeArray['action']=$langs->transnoentitiesnoconv('Events'); |
125 | 141 | |
@@ -128,41 +144,65 @@ discard block |
||
128 | 144 | print '<tr><td class="titlefield">'; |
129 | 145 | print $langs->trans('CustomerCode').'</td><td colspan="3">'; |
130 | 146 | print $object->code_client; |
131 | - if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>'; |
|
147 | + if ($object->check_codeclient() <> 0) { |
|
148 | + print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>'; |
|
149 | + } |
|
132 | 150 | print '</td></tr>'; |
133 | 151 | $sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."facture where fk_soc = ".$socid; |
134 | 152 | $resql=$db->query($sql); |
135 | - if (!$resql) dol_print_error($db); |
|
153 | + if (!$resql) { |
|
154 | + dol_print_error($db); |
|
155 | + } |
|
136 | 156 | |
137 | 157 | $obj = $db->fetch_object($resql); |
138 | 158 | $nbFactsClient = $obj->nb; |
139 | 159 | $thirdTypeArray['customer']=$langs->trans("customer"); |
140 | - if ($conf->propal->enabled && $user->rights->propal->lire) $elementTypeArray['propal']=$langs->transnoentitiesnoconv('Proposals'); |
|
141 | - if ($conf->commande->enabled && $user->rights->commande->lire) $elementTypeArray['order']=$langs->transnoentitiesnoconv('Orders'); |
|
142 | - if ($conf->facture->enabled && $user->rights->facture->lire) $elementTypeArray['invoice']=$langs->transnoentitiesnoconv('Invoices'); |
|
143 | - if ($conf->contrat->enabled && $user->rights->contrat->lire) $elementTypeArray['contract']=$langs->transnoentitiesnoconv('Contracts'); |
|
144 | -} |
|
160 | + if ($conf->propal->enabled && $user->rights->propal->lire) { |
|
161 | + $elementTypeArray['propal']=$langs->transnoentitiesnoconv('Proposals'); |
|
162 | + } |
|
163 | + if ($conf->commande->enabled && $user->rights->commande->lire) { |
|
164 | + $elementTypeArray['order']=$langs->transnoentitiesnoconv('Orders'); |
|
165 | + } |
|
166 | + if ($conf->facture->enabled && $user->rights->facture->lire) { |
|
167 | + $elementTypeArray['invoice']=$langs->transnoentitiesnoconv('Invoices'); |
|
168 | + } |
|
169 | + if ($conf->contrat->enabled && $user->rights->contrat->lire) { |
|
170 | + $elementTypeArray['contract']=$langs->transnoentitiesnoconv('Contracts'); |
|
171 | + } |
|
172 | + } |
|
145 | 173 | |
146 | -if ($conf->ficheinter->enabled && $user->rights->ficheinter->lire) $elementTypeArray['fichinter']=$langs->transnoentitiesnoconv('Interventions'); |
|
174 | +if ($conf->ficheinter->enabled && $user->rights->ficheinter->lire) { |
|
175 | + $elementTypeArray['fichinter']=$langs->transnoentitiesnoconv('Interventions'); |
|
176 | +} |
|
147 | 177 | |
148 | 178 | if ($object->fournisseur) |
149 | 179 | { |
150 | 180 | print '<tr><td class="titlefield">'; |
151 | 181 | print $langs->trans('SupplierCode').'</td><td colspan="3">'; |
152 | 182 | print $object->code_fournisseur; |
153 | - if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>'; |
|
183 | + if ($object->check_codefournisseur() <> 0) { |
|
184 | + print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>'; |
|
185 | + } |
|
154 | 186 | print '</td></tr>'; |
155 | 187 | $sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."commande_fournisseur where fk_soc = ".$socid; |
156 | 188 | $resql=$db->query($sql); |
157 | - if (!$resql) dol_print_error($db); |
|
189 | + if (!$resql) { |
|
190 | + dol_print_error($db); |
|
191 | + } |
|
158 | 192 | |
159 | 193 | $obj = $db->fetch_object($resql); |
160 | 194 | $nbCmdsFourn = $obj->nb; |
161 | 195 | $thirdTypeArray['supplier']=$langs->trans("supplier"); |
162 | - if ($conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire) $elementTypeArray['supplier_invoice']=$langs->transnoentitiesnoconv('SuppliersInvoices'); |
|
163 | - if ($conf->fournisseur->enabled && $user->rights->fournisseur->commande->lire) $elementTypeArray['supplier_order']=$langs->transnoentitiesnoconv('SuppliersOrders'); |
|
164 | - if ($conf->fournisseur->enabled && $user->rights->supplier_proposal->lire) $elementTypeArray['supplier_proposal']=$langs->transnoentitiesnoconv('SupplierProposals'); |
|
165 | -} |
|
196 | + if ($conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire) { |
|
197 | + $elementTypeArray['supplier_invoice']=$langs->transnoentitiesnoconv('SuppliersInvoices'); |
|
198 | + } |
|
199 | + if ($conf->fournisseur->enabled && $user->rights->fournisseur->commande->lire) { |
|
200 | + $elementTypeArray['supplier_order']=$langs->transnoentitiesnoconv('SuppliersOrders'); |
|
201 | + } |
|
202 | + if ($conf->fournisseur->enabled && $user->rights->supplier_proposal->lire) { |
|
203 | + $elementTypeArray['supplier_proposal']=$langs->transnoentitiesnoconv('SupplierProposals'); |
|
204 | + } |
|
205 | + } |
|
166 | 206 | print '</table>'; |
167 | 207 | |
168 | 208 | print '</div>'; |
@@ -296,14 +336,26 @@ discard block |
||
296 | 336 | { |
297 | 337 | $sql = $sql_select; |
298 | 338 | $sql.= ' d.description as description,'; |
299 | - if ($type_element != 'fichinter' && $type_element != 'contract' && $type_element != 'supplier_proposal') $sql.= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_start, d.date_end, d.qty, d.qty as prod_qty, d.total_ht as total_ht, '; |
|
300 | - if ($type_element == 'supplier_proposal') $sql.= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.qty, d.qty as prod_qty, d.total_ht as total_ht, '; |
|
301 | - if ($type_element == 'contract') $sql.= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_ouverture as date_start, d.date_cloture as date_end, d.qty, d.qty as prod_qty, d.total_ht as total_ht, '; |
|
302 | - if ($type_element != 'fichinter') $sql.= ' p.ref as ref, p.rowid as prod_id, p.rowid as fk_product, p.fk_product_type as prod_type, p.fk_product_type as fk_product_type, p.entity as pentity,'; |
|
339 | + if ($type_element != 'fichinter' && $type_element != 'contract' && $type_element != 'supplier_proposal') { |
|
340 | + $sql.= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_start, d.date_end, d.qty, d.qty as prod_qty, d.total_ht as total_ht, '; |
|
341 | + } |
|
342 | + if ($type_element == 'supplier_proposal') { |
|
343 | + $sql.= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.qty, d.qty as prod_qty, d.total_ht as total_ht, '; |
|
344 | + } |
|
345 | + if ($type_element == 'contract') { |
|
346 | + $sql.= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_ouverture as date_start, d.date_cloture as date_end, d.qty, d.qty as prod_qty, d.total_ht as total_ht, '; |
|
347 | + } |
|
348 | + if ($type_element != 'fichinter') { |
|
349 | + $sql.= ' p.ref as ref, p.rowid as prod_id, p.rowid as fk_product, p.fk_product_type as prod_type, p.fk_product_type as fk_product_type, p.entity as pentity,'; |
|
350 | + } |
|
303 | 351 | $sql.= " s.rowid as socid "; |
304 | - if ($type_element != 'fichinter') $sql.= ", p.ref as prod_ref, p.label as product_label"; |
|
352 | + if ($type_element != 'fichinter') { |
|
353 | + $sql.= ", p.ref as prod_ref, p.label as product_label"; |
|
354 | + } |
|
305 | 355 | $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".$tables_from; |
306 | - if ($type_element != 'fichinter') $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON d.fk_product = p.rowid '; |
|
356 | + if ($type_element != 'fichinter') { |
|
357 | + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON d.fk_product = p.rowid '; |
|
358 | + } |
|
307 | 359 | $sql.= $where; |
308 | 360 | if ($month > 0) { |
309 | 361 | if ($year > 0) { |
@@ -318,12 +370,18 @@ discard block |
||
318 | 370 | $end = dol_time_plus_duree($start,1,'y') - 1; |
319 | 371 | $sql.= " AND ".$dateprint." BETWEEN '".$db->idate($start)."' AND '".$db->idate($end)."'"; |
320 | 372 | } |
321 | - if ($sref) $sql.= " AND ".$doc_number." LIKE '%".$db->escape($sref)."%'"; |
|
373 | + if ($sref) { |
|
374 | + $sql.= " AND ".$doc_number." LIKE '%".$db->escape($sref)."%'"; |
|
375 | + } |
|
322 | 376 | if ($sprod_fulldescr) |
323 | 377 | { |
324 | 378 | $sql.= " AND (d.description LIKE '%".$db->escape($sprod_fulldescr)."%'"; |
325 | - if (GETPOST('type_element') != 'fichinter') $sql.= " OR p.ref LIKE '%".$db->escape($sprod_fulldescr)."%'"; |
|
326 | - if (GETPOST('type_element') != 'fichinter') $sql.= " OR p.label LIKE '%".$db->escape($sprod_fulldescr)."%'"; |
|
379 | + if (GETPOST('type_element') != 'fichinter') { |
|
380 | + $sql.= " OR p.ref LIKE '%".$db->escape($sprod_fulldescr)."%'"; |
|
381 | + } |
|
382 | + if (GETPOST('type_element') != 'fichinter') { |
|
383 | + $sql.= " OR p.label LIKE '%".$db->escape($sprod_fulldescr)."%'"; |
|
384 | + } |
|
327 | 385 | $sql.=")"; |
328 | 386 | } |
329 | 387 | $sql.= $db->order($sortfield,$sortorder); |
@@ -360,18 +418,34 @@ discard block |
||
360 | 418 | if ($sql_select) |
361 | 419 | { |
362 | 420 | $resql=$db->query($sql); |
363 | - if (!$resql) dol_print_error($db); |
|
421 | + if (!$resql) { |
|
422 | + dol_print_error($db); |
|
423 | + } |
|
364 | 424 | |
365 | 425 | $num = $db->num_rows($resql); |
366 | 426 | |
367 | 427 | $param="&socid=".$socid."&type_element=".$type_element; |
368 | - if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; |
|
369 | - if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; |
|
370 | - if ($sprod_fulldescr) $param.= "&sprod_fulldescr=".urlencode($sprod_fulldescr); |
|
371 | - if ($sref) $param.= "&sref=".urlencode($sref); |
|
372 | - if ($month) $param.= "&month=".$month; |
|
373 | - if ($year) $param.= "&year=".$year; |
|
374 | - if ($optioncss != '') $param.='&optioncss='.$optioncss; |
|
428 | + if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) { |
|
429 | + $param.='&contextpage='.$contextpage; |
|
430 | + } |
|
431 | + if ($limit > 0 && $limit != $conf->liste_limit) { |
|
432 | + $param.='&limit='.$limit; |
|
433 | + } |
|
434 | + if ($sprod_fulldescr) { |
|
435 | + $param.= "&sprod_fulldescr=".urlencode($sprod_fulldescr); |
|
436 | + } |
|
437 | + if ($sref) { |
|
438 | + $param.= "&sref=".urlencode($sref); |
|
439 | + } |
|
440 | + if ($month) { |
|
441 | + $param.= "&month=".$month; |
|
442 | + } |
|
443 | + if ($year) { |
|
444 | + $param.= "&year=".$year; |
|
445 | + } |
|
446 | + if ($optioncss != '') { |
|
447 | + $param.='&optioncss='.$optioncss; |
|
448 | + } |
|
375 | 449 | |
376 | 450 | print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder,'',$num, $totalnboflines, '', 0, '', '', $limit); |
377 | 451 | |
@@ -426,7 +500,9 @@ discard block |
||
426 | 500 | $documentstatic->status=$objp->status; |
427 | 501 | $documentstatic->paye=$objp->paid; |
428 | 502 | |
429 | - if (is_object($documentstaticline)) $documentstaticline->statut=$objp->status; |
|
503 | + if (is_object($documentstaticline)) { |
|
504 | + $documentstaticline->statut=$objp->status; |
|
505 | + } |
|
430 | 506 | |
431 | 507 | print '<tr class="oddeven">'; |
432 | 508 | print '<td class="nobordernopadding nowrap" width="100">'; |
@@ -439,8 +515,7 @@ discard block |
||
439 | 515 | if ($type_element == 'contract') |
440 | 516 | { |
441 | 517 | print $documentstaticline->getLibStatut(2); |
442 | - } |
|
443 | - else |
|
518 | + } else |
|
444 | 519 | { |
445 | 520 | print $documentstatic->getLibStatut(2); |
446 | 521 | } |
@@ -474,8 +549,12 @@ discard block |
||
474 | 549 | |
475 | 550 | $outputlangs = $langs; |
476 | 551 | $newlang=''; |
477 | - if (empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09'); |
|
478 | - if (empty($newlang)) $newlang=$object->default_lang; |
|
552 | + if (empty($newlang) && GETPOST('lang_id','aZ09')) { |
|
553 | + $newlang=GETPOST('lang_id','aZ09'); |
|
554 | + } |
|
555 | + if (empty($newlang)) { |
|
556 | + $newlang=$object->default_lang; |
|
557 | + } |
|
479 | 558 | if (! empty($newlang)) |
480 | 559 | { |
481 | 560 | $outputlangs = new Translate("",$conf); |
@@ -483,8 +562,7 @@ discard block |
||
483 | 562 | } |
484 | 563 | |
485 | 564 | $label = (! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $objp->product_label; |
486 | - } |
|
487 | - else |
|
565 | + } else |
|
488 | 566 | { |
489 | 567 | $label = $objp->product_label; |
490 | 568 | } |
@@ -498,9 +576,13 @@ discard block |
||
498 | 576 | <?php |
499 | 577 | $txt=''; |
500 | 578 | print img_object($langs->trans("ShowReduc"),'reduc').' '; |
501 | - if ($objp->description == '(DEPOSIT)') $txt=$langs->trans("Deposit"); |
|
502 | - elseif ($objp->description == '(EXCESS RECEIVED)') $txt=$langs->trans("ExcessReceived"); |
|
503 | - elseif ($objp->description == '(EXCESS PAID)') $txt=$langs->trans("ExcessPaid"); |
|
579 | + if ($objp->description == '(DEPOSIT)') { |
|
580 | + $txt=$langs->trans("Deposit"); |
|
581 | + } elseif ($objp->description == '(EXCESS RECEIVED)') { |
|
582 | + $txt=$langs->trans("ExcessReceived"); |
|
583 | + } elseif ($objp->description == '(EXCESS PAID)') { |
|
584 | + $txt=$langs->trans("ExcessPaid"); |
|
585 | + } |
|
504 | 586 | //else $txt=$langs->trans("Discount"); |
505 | 587 | print $txt; |
506 | 588 | ?> |
@@ -519,28 +601,26 @@ discard block |
||
519 | 601 | $discount=new DiscountAbsolute($db); |
520 | 602 | $discount->fetch($objp->fk_remise_except); |
521 | 603 | echo ($txt?' - ':'').$langs->transnoentities("DiscountFromExcessReceived",$discount->getNomUrl(0)); |
522 | - } |
|
523 | - elseif ($objp->description == '(EXCESS PAID)' && $objp->fk_remise_except > 0) |
|
604 | + } elseif ($objp->description == '(EXCESS PAID)' && $objp->fk_remise_except > 0) |
|
524 | 605 | { |
525 | 606 | $discount=new DiscountAbsolute($db); |
526 | 607 | $discount->fetch($objp->fk_remise_except); |
527 | 608 | echo ($txt?' - ':'').$langs->transnoentities("DiscountFromExcessPaid",$discount->getNomUrl(0)); |
528 | - } |
|
529 | - elseif ($objp->description == '(DEPOSIT)' && $objp->fk_remise_except > 0) |
|
609 | + } elseif ($objp->description == '(DEPOSIT)' && $objp->fk_remise_except > 0) |
|
530 | 610 | { |
531 | 611 | $discount=new DiscountAbsolute($db); |
532 | 612 | $discount->fetch($objp->fk_remise_except); |
533 | 613 | echo ($txt?' - ':'').$langs->transnoentities("DiscountFromDeposit",$discount->getNomUrl(0)); |
534 | 614 | // Add date of deposit |
535 | - if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) echo ' ('.dol_print_date($discount->datec).')'; |
|
536 | - } |
|
537 | - else |
|
615 | + if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) { |
|
616 | + echo ' ('.dol_print_date($discount->datec).')'; |
|
617 | + } |
|
618 | + } else |
|
538 | 619 | { |
539 | 620 | echo ($txt?' - ':'').dol_htmlentitiesbr($objp->description); |
540 | 621 | } |
541 | 622 | } |
542 | - } |
|
543 | - else |
|
623 | + } else |
|
544 | 624 | { |
545 | 625 | if ($objp->fk_product > 0) { |
546 | 626 | |
@@ -558,8 +638,11 @@ discard block |
||
558 | 638 | |
559 | 639 | if (! empty($objp->label) || ! empty($objp->description)) |
560 | 640 | { |
561 | - if ($type==1) $text = img_object($langs->trans('Service'),'service'); |
|
562 | - else $text = img_object($langs->trans('Product'),'product'); |
|
641 | + if ($type==1) { |
|
642 | + $text = img_object($langs->trans('Service'),'service'); |
|
643 | + } else { |
|
644 | + $text = img_object($langs->trans('Product'),'product'); |
|
645 | + } |
|
563 | 646 | |
564 | 647 | if (! empty($objp->label)) { |
565 | 648 | $text.= ' <strong>'.$objp->label.'</strong>'; |
@@ -621,8 +704,7 @@ discard block |
||
621 | 704 | print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder,'',$num); |
622 | 705 | } |
623 | 706 | $db->free($resql); |
624 | -} |
|
625 | -else if (empty($type_element) || $type_element == -1) |
|
707 | +} else if (empty($type_element) || $type_element == -1) |
|
626 | 708 | { |
627 | 709 | print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder,'',$num, '', ''); |
628 | 710 | |
@@ -639,8 +721,7 @@ discard block |
||
639 | 721 | print '<tr class="oddeven"><td class="opacitymedium" colspan="5">'.$langs->trans("SelectElementAndClick", $langs->transnoentitiesnoconv("Search")).'</td></tr>'; |
640 | 722 | |
641 | 723 | print "</table>"; |
642 | -} |
|
643 | -else { |
|
724 | +} else { |
|
644 | 725 | print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder,'',$num, '', ''); |
645 | 726 | |
646 | 727 | print '<table class="liste" width="100%">'."\n"; |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * \brief Add a tab on thirpdarty view to list all products/services bought or sells by thirdparty |
27 | 27 | */ |
28 | 28 | |
29 | -require DOL_BASE_PATH . '/main.inc.php'; |
|
29 | +require DOL_BASE_PATH.'/main.inc.php'; |
|
30 | 30 | |
31 | 31 | require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; |
32 | 32 | require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; |
@@ -34,41 +34,41 @@ discard block |
||
34 | 34 | require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php'; |
35 | 35 | |
36 | 36 | // Security check |
37 | -$socid = GETPOST('socid','int'); |
|
38 | -if ($user->societe_id) $socid=$user->societe_id; |
|
37 | +$socid = GETPOST('socid', 'int'); |
|
38 | +if ($user->societe_id) $socid = $user->societe_id; |
|
39 | 39 | $result = restrictedArea($user, 'societe', $socid, '&societe'); |
40 | 40 | $object = new Societe($db); |
41 | 41 | if ($socid > 0) $object->fetch($socid); |
42 | 42 | |
43 | 43 | // Sort & Order fields |
44 | -$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; |
|
45 | -$sortfield = GETPOST("sortfield",'alpha'); |
|
46 | -$sortorder = GETPOST("sortorder",'alpha'); |
|
47 | -$page = GETPOST("page",'int'); |
|
44 | +$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit; |
|
45 | +$sortfield = GETPOST("sortfield", 'alpha'); |
|
46 | +$sortorder = GETPOST("sortorder", 'alpha'); |
|
47 | +$page = GETPOST("page", 'int'); |
|
48 | 48 | if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 |
49 | 49 | $offset = $limit * $page; |
50 | 50 | $pageprev = $page - 1; |
51 | 51 | $pagenext = $page + 1; |
52 | -if (! $sortorder) $sortorder='DESC'; |
|
53 | -if (! $sortfield) $sortfield='dateprint'; |
|
52 | +if (!$sortorder) $sortorder = 'DESC'; |
|
53 | +if (!$sortfield) $sortfield = 'dateprint'; |
|
54 | 54 | |
55 | 55 | // Search fields |
56 | -$sref=GETPOST("sref"); |
|
57 | -$sprod_fulldescr=GETPOST("sprod_fulldescr"); |
|
58 | -$month = GETPOST('month','int'); |
|
59 | -$year = GETPOST('year','int'); |
|
56 | +$sref = GETPOST("sref"); |
|
57 | +$sprod_fulldescr = GETPOST("sprod_fulldescr"); |
|
58 | +$month = GETPOST('month', 'int'); |
|
59 | +$year = GETPOST('year', 'int'); |
|
60 | 60 | |
61 | 61 | // Clean up on purge search criteria ? |
62 | -if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // Both test are required to be compatible with all browsers |
|
62 | +if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // Both test are required to be compatible with all browsers |
|
63 | 63 | { |
64 | - $sref=''; |
|
65 | - $sprod_fulldescr=''; |
|
66 | - $year=''; |
|
67 | - $month=''; |
|
64 | + $sref = ''; |
|
65 | + $sprod_fulldescr = ''; |
|
66 | + $year = ''; |
|
67 | + $month = ''; |
|
68 | 68 | } |
69 | 69 | // Customer or supplier selected in drop box |
70 | 70 | $thirdTypeSelect = GETPOST("third_select_id"); |
71 | -$type_element = GETPOST('type_element')?GETPOST('type_element'):''; |
|
71 | +$type_element = GETPOST('type_element') ?GETPOST('type_element') : ''; |
|
72 | 72 | |
73 | 73 | // Load translation files required by the page |
74 | 74 | $langs->loadLangs(array("companies", "bills", "orders", "suppliers", "propal", "interventions", "contracts", "products")); |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | * Actions |
82 | 82 | */ |
83 | 83 | |
84 | -$parameters=array('id'=>$socid); |
|
85 | -$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks |
|
84 | +$parameters = array('id'=>$socid); |
|
85 | +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks |
|
86 | 86 | if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); |
87 | 87 | |
88 | 88 | |
@@ -93,12 +93,12 @@ discard block |
||
93 | 93 | |
94 | 94 | $form = new Form($db); |
95 | 95 | $formother = new FormOther($db); |
96 | -$productstatic=new Product($db); |
|
96 | +$productstatic = new Product($db); |
|
97 | 97 | |
98 | -$title = $langs->trans("Referers",$object->name); |
|
99 | -if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name." - ".$title; |
|
100 | -$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; |
|
101 | -llxHeader('',$title,$help_url); |
|
98 | +$title = $langs->trans("Referers", $object->name); |
|
99 | +if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) $title = $object->name." - ".$title; |
|
100 | +$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; |
|
101 | +llxHeader('', $title, $help_url); |
|
102 | 102 | |
103 | 103 | if (empty($socid)) |
104 | 104 | { |
@@ -111,14 +111,14 @@ discard block |
||
111 | 111 | |
112 | 112 | $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>'; |
113 | 113 | |
114 | -dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom'); |
|
114 | +dol_banner_tab($object, 'socid', $linkback, ($user->societe_id ? 0 : 1), 'rowid', 'nom'); |
|
115 | 115 | |
116 | 116 | print '<div class="fichecenter">'; |
117 | 117 | |
118 | 118 | print '<div class="underbanner clearboth"></div>'; |
119 | 119 | print '<table class="border" width="100%">'; |
120 | 120 | |
121 | -if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field |
|
121 | +if (!empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field |
|
122 | 122 | { |
123 | 123 | print '<tr><td class="titlefield">'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>'; |
124 | 124 | } |
@@ -133,19 +133,19 @@ discard block |
||
133 | 133 | if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>'; |
134 | 134 | print '</td></tr>'; |
135 | 135 | $sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."facture where fk_soc = ".$socid; |
136 | - $resql=$db->query($sql); |
|
136 | + $resql = $db->query($sql); |
|
137 | 137 | if (!$resql) dol_print_error($db); |
138 | 138 | |
139 | 139 | $obj = $db->fetch_object($resql); |
140 | 140 | $nbFactsClient = $obj->nb; |
141 | - $thirdTypeArray['customer']=$langs->trans("customer"); |
|
142 | - if ($conf->propal->enabled && $user->rights->propal->lire) $elementTypeArray['propal']=$langs->transnoentitiesnoconv('Proposals'); |
|
143 | - if ($conf->commande->enabled && $user->rights->commande->lire) $elementTypeArray['order']=$langs->transnoentitiesnoconv('Orders'); |
|
144 | - if ($conf->facture->enabled && $user->rights->facture->lire) $elementTypeArray['invoice']=$langs->transnoentitiesnoconv('Invoices'); |
|
145 | - if ($conf->contrat->enabled && $user->rights->contrat->lire) $elementTypeArray['contract']=$langs->transnoentitiesnoconv('Contracts'); |
|
141 | + $thirdTypeArray['customer'] = $langs->trans("customer"); |
|
142 | + if ($conf->propal->enabled && $user->rights->propal->lire) $elementTypeArray['propal'] = $langs->transnoentitiesnoconv('Proposals'); |
|
143 | + if ($conf->commande->enabled && $user->rights->commande->lire) $elementTypeArray['order'] = $langs->transnoentitiesnoconv('Orders'); |
|
144 | + if ($conf->facture->enabled && $user->rights->facture->lire) $elementTypeArray['invoice'] = $langs->transnoentitiesnoconv('Invoices'); |
|
145 | + if ($conf->contrat->enabled && $user->rights->contrat->lire) $elementTypeArray['contract'] = $langs->transnoentitiesnoconv('Contracts'); |
|
146 | 146 | } |
147 | 147 | |
148 | -if ($conf->ficheinter->enabled && $user->rights->ficheinter->lire) $elementTypeArray['fichinter']=$langs->transnoentitiesnoconv('Interventions'); |
|
148 | +if ($conf->ficheinter->enabled && $user->rights->ficheinter->lire) $elementTypeArray['fichinter'] = $langs->transnoentitiesnoconv('Interventions'); |
|
149 | 149 | |
150 | 150 | if ($object->fournisseur) |
151 | 151 | { |
@@ -155,15 +155,15 @@ discard block |
||
155 | 155 | if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>'; |
156 | 156 | print '</td></tr>'; |
157 | 157 | $sql = "SELECT count(*) as nb from ".MAIN_DB_PREFIX."commande_fournisseur where fk_soc = ".$socid; |
158 | - $resql=$db->query($sql); |
|
158 | + $resql = $db->query($sql); |
|
159 | 159 | if (!$resql) dol_print_error($db); |
160 | 160 | |
161 | 161 | $obj = $db->fetch_object($resql); |
162 | 162 | $nbCmdsFourn = $obj->nb; |
163 | - $thirdTypeArray['supplier']=$langs->trans("supplier"); |
|
164 | - if ($conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire) $elementTypeArray['supplier_invoice']=$langs->transnoentitiesnoconv('SuppliersInvoices'); |
|
165 | - if ($conf->fournisseur->enabled && $user->rights->fournisseur->commande->lire) $elementTypeArray['supplier_order']=$langs->transnoentitiesnoconv('SuppliersOrders'); |
|
166 | - if ($conf->fournisseur->enabled && $user->rights->supplier_proposal->lire) $elementTypeArray['supplier_proposal']=$langs->transnoentitiesnoconv('SupplierProposals'); |
|
163 | + $thirdTypeArray['supplier'] = $langs->trans("supplier"); |
|
164 | + if ($conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire) $elementTypeArray['supplier_invoice'] = $langs->transnoentitiesnoconv('SuppliersInvoices'); |
|
165 | + if ($conf->fournisseur->enabled && $user->rights->fournisseur->commande->lire) $elementTypeArray['supplier_order'] = $langs->transnoentitiesnoconv('SuppliersOrders'); |
|
166 | + if ($conf->fournisseur->enabled && $user->rights->supplier_proposal->lire) $elementTypeArray['supplier_proposal'] = $langs->transnoentitiesnoconv('SupplierProposals'); |
|
167 | 167 | } |
168 | 168 | print '</table>'; |
169 | 169 | |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'?socid='.$socid.'">'; |
177 | 177 | print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; |
178 | 178 | |
179 | -$sql_select=''; |
|
179 | +$sql_select = ''; |
|
180 | 180 | /*if ($type_element == 'action') |
181 | 181 | { // Customer : show products from invoices |
182 | 182 | require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; |
@@ -190,192 +190,192 @@ discard block |
||
190 | 190 | if ($type_element == 'fichinter') |
191 | 191 | { // Customer : show products from invoices |
192 | 192 | require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php'; |
193 | - $documentstatic=new Fichinter($db); |
|
193 | + $documentstatic = new Fichinter($db); |
|
194 | 194 | $sql_select = 'SELECT f.rowid as doc_id, f.ref as doc_number, \'1\' as doc_type, f.datec as dateprint, f.fk_statut as status, '; |
195 | - $tables_from = MAIN_DB_PREFIX."fichinter as f LEFT JOIN ".MAIN_DB_PREFIX."fichinterdet as d ON d.fk_fichinter = f.rowid"; // Must use left join to work also with option that disable usage of lines. |
|
195 | + $tables_from = MAIN_DB_PREFIX."fichinter as f LEFT JOIN ".MAIN_DB_PREFIX."fichinterdet as d ON d.fk_fichinter = f.rowid"; // Must use left join to work also with option that disable usage of lines. |
|
196 | 196 | $where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".$socid; |
197 | - $where.= " AND f.entity = ".$conf->entity; |
|
197 | + $where .= " AND f.entity = ".$conf->entity; |
|
198 | 198 | $dateprint = 'f.datec'; |
199 | - $doc_number='f.ref'; |
|
199 | + $doc_number = 'f.ref'; |
|
200 | 200 | } |
201 | 201 | if ($type_element == 'invoice') |
202 | 202 | { // Customer : show products from invoices |
203 | 203 | require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; |
204 | - $documentstatic=new Facture($db); |
|
204 | + $documentstatic = new Facture($db); |
|
205 | 205 | $sql_select = 'SELECT f.rowid as doc_id, f.ref as doc_number, f.type as doc_type, f.datef as dateprint, f.fk_statut as status, f.paye as paid, '; |
206 | 206 | $tables_from = MAIN_DB_PREFIX."facture as f,".MAIN_DB_PREFIX."facturedet as d"; |
207 | 207 | $where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".$socid; |
208 | - $where.= " AND d.fk_facture = f.rowid"; |
|
209 | - $where.= " AND f.entity = ".$conf->entity; |
|
208 | + $where .= " AND d.fk_facture = f.rowid"; |
|
209 | + $where .= " AND f.entity = ".$conf->entity; |
|
210 | 210 | $dateprint = 'f.datef'; |
211 | - $doc_number='f.ref'; |
|
212 | - $thirdTypeSelect='customer'; |
|
211 | + $doc_number = 'f.ref'; |
|
212 | + $thirdTypeSelect = 'customer'; |
|
213 | 213 | } |
214 | 214 | if ($type_element == 'propal') |
215 | 215 | { |
216 | 216 | require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; |
217 | - $documentstatic=new Propal($db); |
|
217 | + $documentstatic = new Propal($db); |
|
218 | 218 | $sql_select = 'SELECT c.rowid as doc_id, c.ref as doc_number, \'1\' as doc_type, c.datep as dateprint, c.fk_statut as status, '; |
219 | 219 | $tables_from = MAIN_DB_PREFIX."propal as c,".MAIN_DB_PREFIX."propaldet as d"; |
220 | 220 | $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".$socid; |
221 | - $where.= " AND d.fk_propal = c.rowid"; |
|
222 | - $where.= " AND c.entity = ".$conf->entity; |
|
221 | + $where .= " AND d.fk_propal = c.rowid"; |
|
222 | + $where .= " AND c.entity = ".$conf->entity; |
|
223 | 223 | $datePrint = 'c.datep'; |
224 | - $doc_number='c.ref'; |
|
225 | - $thirdTypeSelect='customer'; |
|
224 | + $doc_number = 'c.ref'; |
|
225 | + $thirdTypeSelect = 'customer'; |
|
226 | 226 | } |
227 | 227 | if ($type_element == 'order') |
228 | 228 | { |
229 | 229 | require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; |
230 | - $documentstatic=new Commande($db); |
|
230 | + $documentstatic = new Commande($db); |
|
231 | 231 | $sql_select = 'SELECT c.rowid as doc_id, c.ref as doc_number, \'1\' as doc_type, c.date_commande as dateprint, c.fk_statut as status, '; |
232 | 232 | $tables_from = MAIN_DB_PREFIX."commande as c,".MAIN_DB_PREFIX."commandedet as d"; |
233 | 233 | $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".$socid; |
234 | - $where.= " AND d.fk_commande = c.rowid"; |
|
235 | - $where.= " AND c.entity = ".$conf->entity; |
|
234 | + $where .= " AND d.fk_commande = c.rowid"; |
|
235 | + $where .= " AND c.entity = ".$conf->entity; |
|
236 | 236 | $dateprint = 'c.date_commande'; |
237 | - $doc_number='c.ref'; |
|
238 | - $thirdTypeSelect='customer'; |
|
237 | + $doc_number = 'c.ref'; |
|
238 | + $thirdTypeSelect = 'customer'; |
|
239 | 239 | } |
240 | 240 | if ($type_element == 'supplier_invoice') |
241 | 241 | { // Supplier : Show products from invoices. |
242 | 242 | require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; |
243 | - $documentstatic=new FactureFournisseur($db); |
|
243 | + $documentstatic = new FactureFournisseur($db); |
|
244 | 244 | $sql_select = 'SELECT f.rowid as doc_id, f.ref as doc_number, \'1\' as doc_type, f.datef as dateprint, f.fk_statut as status, f.paye as paid, '; |
245 | 245 | $tables_from = MAIN_DB_PREFIX."facture_fourn as f,".MAIN_DB_PREFIX."facture_fourn_det as d"; |
246 | 246 | $where = " WHERE f.fk_soc = s.rowid AND s.rowid = ".$socid; |
247 | - $where.= " AND d.fk_facture_fourn = f.rowid"; |
|
248 | - $where.= " AND f.entity = ".$conf->entity; |
|
247 | + $where .= " AND d.fk_facture_fourn = f.rowid"; |
|
248 | + $where .= " AND f.entity = ".$conf->entity; |
|
249 | 249 | $dateprint = 'f.datef'; |
250 | - $doc_number='f.ref'; |
|
251 | - $thirdTypeSelect='supplier'; |
|
250 | + $doc_number = 'f.ref'; |
|
251 | + $thirdTypeSelect = 'supplier'; |
|
252 | 252 | } |
253 | 253 | if ($type_element == 'supplier_proposal') |
254 | 254 | { |
255 | 255 | require_once DOL_DOCUMENT_ROOT.'/supplier_proposal/class/supplier_proposal.class.php'; |
256 | - $documentstatic=new SupplierProposal($db); |
|
256 | + $documentstatic = new SupplierProposal($db); |
|
257 | 257 | $sql_select = 'SELECT c.rowid as doc_id, c.ref as doc_number, \'1\' as doc_type, c.date_valid as dateprint, c.fk_statut as status, '; |
258 | 258 | $tables_from = MAIN_DB_PREFIX."supplier_proposal as c,".MAIN_DB_PREFIX."supplier_proposaldet as d"; |
259 | 259 | $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".$socid; |
260 | - $where.= " AND d.fk_supplier_proposal = c.rowid"; |
|
261 | - $where.= " AND c.entity = ".$conf->entity; |
|
260 | + $where .= " AND d.fk_supplier_proposal = c.rowid"; |
|
261 | + $where .= " AND c.entity = ".$conf->entity; |
|
262 | 262 | $dateprint = 'c.date_valid'; |
263 | - $doc_number='c.ref'; |
|
264 | - $thirdTypeSelect='supplier'; |
|
263 | + $doc_number = 'c.ref'; |
|
264 | + $thirdTypeSelect = 'supplier'; |
|
265 | 265 | } |
266 | 266 | if ($type_element == 'supplier_order') |
267 | 267 | { // Supplier : Show products from orders. |
268 | 268 | require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; |
269 | - $documentstatic=new CommandeFournisseur($db); |
|
269 | + $documentstatic = new CommandeFournisseur($db); |
|
270 | 270 | $sql_select = 'SELECT c.rowid as doc_id, c.ref as doc_number, \'1\' as doc_type, c.date_valid as dateprint, c.fk_statut as status, '; |
271 | 271 | $tables_from = MAIN_DB_PREFIX."commande_fournisseur as c,".MAIN_DB_PREFIX."commande_fournisseurdet as d"; |
272 | 272 | $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".$socid; |
273 | - $where.= " AND d.fk_commande = c.rowid"; |
|
274 | - $where.= " AND c.entity = ".$conf->entity; |
|
273 | + $where .= " AND d.fk_commande = c.rowid"; |
|
274 | + $where .= " AND c.entity = ".$conf->entity; |
|
275 | 275 | $dateprint = 'c.date_valid'; |
276 | - $doc_number='c.ref'; |
|
277 | - $thirdTypeSelect='supplier'; |
|
276 | + $doc_number = 'c.ref'; |
|
277 | + $thirdTypeSelect = 'supplier'; |
|
278 | 278 | } |
279 | 279 | if ($type_element == 'contract') |
280 | 280 | { // Order |
281 | 281 | require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php'; |
282 | - $documentstatic=new Contrat($db); |
|
283 | - $documentstaticline=new ContratLigne($db); |
|
282 | + $documentstatic = new Contrat($db); |
|
283 | + $documentstaticline = new ContratLigne($db); |
|
284 | 284 | $sql_select = 'SELECT c.rowid as doc_id, c.ref as doc_number, \'1\' as doc_type, c.date_contrat as dateprint, d.statut as status, '; |
285 | 285 | $tables_from = MAIN_DB_PREFIX."contrat as c,".MAIN_DB_PREFIX."contratdet as d"; |
286 | 286 | $where = " WHERE c.fk_soc = s.rowid AND s.rowid = ".$socid; |
287 | - $where.= " AND d.fk_contrat = c.rowid"; |
|
288 | - $where.= " AND c.entity = ".$conf->entity; |
|
287 | + $where .= " AND d.fk_contrat = c.rowid"; |
|
288 | + $where .= " AND c.entity = ".$conf->entity; |
|
289 | 289 | $dateprint = 'c.date_valid'; |
290 | - $doc_number='c.ref'; |
|
291 | - $thirdTypeSelect='customer'; |
|
290 | + $doc_number = 'c.ref'; |
|
291 | + $thirdTypeSelect = 'customer'; |
|
292 | 292 | } |
293 | 293 | |
294 | -$parameters=array(); |
|
295 | -$reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook |
|
294 | +$parameters = array(); |
|
295 | +$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook |
|
296 | 296 | |
297 | 297 | if (!empty($sql_select)) |
298 | 298 | { |
299 | 299 | $sql = $sql_select; |
300 | - $sql.= ' d.description as description,'; |
|
301 | - if ($type_element != 'fichinter' && $type_element != 'contract' && $type_element != 'supplier_proposal') $sql.= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_start, d.date_end, d.qty, d.qty as prod_qty, d.total_ht as total_ht, '; |
|
302 | - if ($type_element == 'supplier_proposal') $sql.= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.qty, d.qty as prod_qty, d.total_ht as total_ht, '; |
|
303 | - if ($type_element == 'contract') $sql.= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_ouverture as date_start, d.date_cloture as date_end, d.qty, d.qty as prod_qty, d.total_ht as total_ht, '; |
|
304 | - if ($type_element != 'fichinter') $sql.= ' p.ref as ref, p.rowid as prod_id, p.rowid as fk_product, p.fk_product_type as prod_type, p.fk_product_type as fk_product_type, p.entity as pentity,'; |
|
305 | - $sql.= " s.rowid as socid "; |
|
306 | - if ($type_element != 'fichinter') $sql.= ", p.ref as prod_ref, p.label as product_label"; |
|
307 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".$tables_from; |
|
308 | - if ($type_element != 'fichinter') $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON d.fk_product = p.rowid '; |
|
309 | - $sql.= $where; |
|
300 | + $sql .= ' d.description as description,'; |
|
301 | + if ($type_element != 'fichinter' && $type_element != 'contract' && $type_element != 'supplier_proposal') $sql .= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_start, d.date_end, d.qty, d.qty as prod_qty, d.total_ht as total_ht, '; |
|
302 | + if ($type_element == 'supplier_proposal') $sql .= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.qty, d.qty as prod_qty, d.total_ht as total_ht, '; |
|
303 | + if ($type_element == 'contract') $sql .= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_ouverture as date_start, d.date_cloture as date_end, d.qty, d.qty as prod_qty, d.total_ht as total_ht, '; |
|
304 | + if ($type_element != 'fichinter') $sql .= ' p.ref as ref, p.rowid as prod_id, p.rowid as fk_product, p.fk_product_type as prod_type, p.fk_product_type as fk_product_type, p.entity as pentity,'; |
|
305 | + $sql .= " s.rowid as socid "; |
|
306 | + if ($type_element != 'fichinter') $sql .= ", p.ref as prod_ref, p.label as product_label"; |
|
307 | + $sql .= " FROM ".MAIN_DB_PREFIX."societe as s, ".$tables_from; |
|
308 | + if ($type_element != 'fichinter') $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON d.fk_product = p.rowid '; |
|
309 | + $sql .= $where; |
|
310 | 310 | if ($month > 0) { |
311 | 311 | if ($year > 0) { |
312 | 312 | $start = dol_mktime(0, 0, 0, $month, 1, $year); |
313 | - $end = dol_time_plus_duree($start,1,'m') - 1; |
|
314 | - $sql.= " AND ".$dateprint." BETWEEN '".$db->idate($start)."' AND '".$db->idate($end)."'"; |
|
313 | + $end = dol_time_plus_duree($start, 1, 'm') - 1; |
|
314 | + $sql .= " AND ".$dateprint." BETWEEN '".$db->idate($start)."' AND '".$db->idate($end)."'"; |
|
315 | 315 | } else { |
316 | - $sql.= " AND date_format(".$dateprint.", '%m') = '".sprintf('%02d',$month)."'"; |
|
316 | + $sql .= " AND date_format(".$dateprint.", '%m') = '".sprintf('%02d', $month)."'"; |
|
317 | 317 | } |
318 | 318 | } else if ($year > 0) { |
319 | 319 | $start = dol_mktime(0, 0, 0, 1, 1, $year); |
320 | - $end = dol_time_plus_duree($start,1,'y') - 1; |
|
321 | - $sql.= " AND ".$dateprint." BETWEEN '".$db->idate($start)."' AND '".$db->idate($end)."'"; |
|
320 | + $end = dol_time_plus_duree($start, 1, 'y') - 1; |
|
321 | + $sql .= " AND ".$dateprint." BETWEEN '".$db->idate($start)."' AND '".$db->idate($end)."'"; |
|
322 | 322 | } |
323 | - if ($sref) $sql.= " AND ".$doc_number." LIKE '%".$db->escape($sref)."%'"; |
|
323 | + if ($sref) $sql .= " AND ".$doc_number." LIKE '%".$db->escape($sref)."%'"; |
|
324 | 324 | if ($sprod_fulldescr) |
325 | 325 | { |
326 | - $sql.= " AND (d.description LIKE '%".$db->escape($sprod_fulldescr)."%'"; |
|
327 | - if (GETPOST('type_element') != 'fichinter') $sql.= " OR p.ref LIKE '%".$db->escape($sprod_fulldescr)."%'"; |
|
328 | - if (GETPOST('type_element') != 'fichinter') $sql.= " OR p.label LIKE '%".$db->escape($sprod_fulldescr)."%'"; |
|
329 | - $sql.=")"; |
|
326 | + $sql .= " AND (d.description LIKE '%".$db->escape($sprod_fulldescr)."%'"; |
|
327 | + if (GETPOST('type_element') != 'fichinter') $sql .= " OR p.ref LIKE '%".$db->escape($sprod_fulldescr)."%'"; |
|
328 | + if (GETPOST('type_element') != 'fichinter') $sql .= " OR p.label LIKE '%".$db->escape($sprod_fulldescr)."%'"; |
|
329 | + $sql .= ")"; |
|
330 | 330 | } |
331 | - $sql.= $db->order($sortfield,$sortorder); |
|
331 | + $sql .= $db->order($sortfield, $sortorder); |
|
332 | 332 | |
333 | - $resql=$db->query($sql); |
|
333 | + $resql = $db->query($sql); |
|
334 | 334 | $totalnboflines = $db->num_rows($resql); |
335 | 335 | |
336 | - $sql.= $db->plimit($limit + 1, $offset); |
|
336 | + $sql .= $db->plimit($limit + 1, $offset); |
|
337 | 337 | //print $sql; |
338 | 338 | } |
339 | 339 | |
340 | -$disabled=0; |
|
341 | -$showempty=2; |
|
342 | -if (empty($elementTypeArray) && ! $object->client && ! $object->fournisseur) |
|
340 | +$disabled = 0; |
|
341 | +$showempty = 2; |
|
342 | +if (empty($elementTypeArray) && !$object->client && !$object->fournisseur) |
|
343 | 343 | { |
344 | - $showempty=$langs->trans("ThirdpartyNotCustomerNotSupplierSoNoRef"); |
|
345 | - $disabled=1; |
|
344 | + $showempty = $langs->trans("ThirdpartyNotCustomerNotSupplierSoNoRef"); |
|
345 | + $disabled = 1; |
|
346 | 346 | } |
347 | 347 | |
348 | 348 | // Define type of elements |
349 | 349 | $typeElementString = $form->selectarray("type_element", $elementTypeArray, GETPOST('type_element'), $showempty, 0, 0, '', 0, 0, $disabled, '', 'maxwidth150onsmartphone'); |
350 | 350 | $button = '<input type="submit" class="button" name="button_third" value="'.dol_escape_htmltag($langs->trans("Search")).'" title="'.dol_escape_htmltag($langs->trans("Search")).'">'; |
351 | 351 | |
352 | -$param=''; |
|
353 | -$param.="&sref=".urlencode($sref); |
|
354 | -$param.="&month=".urlencode($month); |
|
355 | -$param.="&year=".urlencode($year); |
|
356 | -$param.="&sprod_fulldescr=".urlencode($sprod_fulldescr); |
|
357 | -$param.="&socid=".urlencode($socid); |
|
358 | -$param.="&type_element=".urlencode($type_element); |
|
352 | +$param = ''; |
|
353 | +$param .= "&sref=".urlencode($sref); |
|
354 | +$param .= "&month=".urlencode($month); |
|
355 | +$param .= "&year=".urlencode($year); |
|
356 | +$param .= "&sprod_fulldescr=".urlencode($sprod_fulldescr); |
|
357 | +$param .= "&socid=".urlencode($socid); |
|
358 | +$param .= "&type_element=".urlencode($type_element); |
|
359 | 359 | |
360 | -$total_qty=0; |
|
360 | +$total_qty = 0; |
|
361 | 361 | |
362 | 362 | if ($sql_select) |
363 | 363 | { |
364 | - $resql=$db->query($sql); |
|
364 | + $resql = $db->query($sql); |
|
365 | 365 | if (!$resql) dol_print_error($db); |
366 | 366 | |
367 | 367 | $num = $db->num_rows($resql); |
368 | 368 | |
369 | - $param="&socid=".$socid."&type_element=".$type_element; |
|
370 | - if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage; |
|
371 | - if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; |
|
372 | - if ($sprod_fulldescr) $param.= "&sprod_fulldescr=".urlencode($sprod_fulldescr); |
|
373 | - if ($sref) $param.= "&sref=".urlencode($sref); |
|
374 | - if ($month) $param.= "&month=".$month; |
|
375 | - if ($year) $param.= "&year=".$year; |
|
376 | - if ($optioncss != '') $param.='&optioncss='.$optioncss; |
|
369 | + $param = "&socid=".$socid."&type_element=".$type_element; |
|
370 | + if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.$contextpage; |
|
371 | + if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.$limit; |
|
372 | + if ($sprod_fulldescr) $param .= "&sprod_fulldescr=".urlencode($sprod_fulldescr); |
|
373 | + if ($sref) $param .= "&sref=".urlencode($sref); |
|
374 | + if ($month) $param .= "&month=".$month; |
|
375 | + if ($year) $param .= "&year=".$year; |
|
376 | + if ($optioncss != '') $param .= '&optioncss='.$optioncss; |
|
377 | 377 | |
378 | - print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder,'',$num, $totalnboflines, '', 0, '', '', $limit); |
|
378 | + print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $totalnboflines, '', 0, '', '', $limit); |
|
379 | 379 | |
380 | 380 | print '<div class="div-table-responsive-no-min">'; |
381 | 381 | print '<table class="liste" width="100%">'."\n"; |
@@ -386,8 +386,8 @@ discard block |
||
386 | 386 | print '<input class="flat" type="text" name="sref" size="8" value="'.$sref.'">'; |
387 | 387 | print '</td>'; |
388 | 388 | print '<td class="liste_titre nowrap center">'; // date |
389 | - print $formother->select_month($month?$month:-1, 'month', 1, 0, 'valignmiddle'); |
|
390 | - $formother->select_year($year?$year:-1,'year',1, 20, 1); |
|
389 | + print $formother->select_month($month ? $month : -1, 'month', 1, 0, 'valignmiddle'); |
|
390 | + $formother->select_year($year ? $year : -1, 'year', 1, 20, 1); |
|
391 | 391 | print '</td>'; |
392 | 392 | print '<td class="liste_titre" align="center">'; |
393 | 393 | print '</td>'; |
@@ -399,42 +399,42 @@ discard block |
||
399 | 399 | print '<td class="liste_titre" align="center">'; |
400 | 400 | print '</td>'; |
401 | 401 | print '<td class="liste_titre" align="right">'; |
402 | - $searchpicto=$form->showFilterAndCheckAddButtons(0); |
|
402 | + $searchpicto = $form->showFilterAndCheckAddButtons(0); |
|
403 | 403 | print $searchpicto; |
404 | 404 | print '</td>'; |
405 | 405 | print '</tr>'; |
406 | 406 | |
407 | 407 | // Titles with sort buttons |
408 | 408 | print '<tr class="liste_titre">'; |
409 | - print_liste_field_titre('Ref',$_SERVER['PHP_SELF'],'doc_number','',$param,'align="left"',$sortfield,$sortorder); |
|
410 | - print_liste_field_titre('Date',$_SERVER['PHP_SELF'],'dateprint','',$param,'align="center" width="150"',$sortfield,$sortorder); |
|
411 | - print_liste_field_titre('Status',$_SERVER['PHP_SELF'],'fk_statut','',$param,'align="center"',$sortfield,$sortorder); |
|
412 | - print_liste_field_titre('Product',$_SERVER['PHP_SELF'],'','',$param,'align="left"',$sortfield,$sortorder); |
|
413 | - print_liste_field_titre('Quantity',$_SERVER['PHP_SELF'],'prod_qty','',$param,'align="right"',$sortfield,$sortorder); |
|
414 | - print_liste_field_titre('TotalHT',$_SERVER['PHP_SELF'],'total_ht','',$param,'align="right"',$sortfield,$sortorder); |
|
415 | - print_liste_field_titre('UnitPrice',$_SERVER['PHP_SELF'],'','',$param,'align="right"',$sortfield,$sortorder); |
|
409 | + print_liste_field_titre('Ref', $_SERVER['PHP_SELF'], 'doc_number', '', $param, 'align="left"', $sortfield, $sortorder); |
|
410 | + print_liste_field_titre('Date', $_SERVER['PHP_SELF'], 'dateprint', '', $param, 'align="center" width="150"', $sortfield, $sortorder); |
|
411 | + print_liste_field_titre('Status', $_SERVER['PHP_SELF'], 'fk_statut', '', $param, 'align="center"', $sortfield, $sortorder); |
|
412 | + print_liste_field_titre('Product', $_SERVER['PHP_SELF'], '', '', $param, 'align="left"', $sortfield, $sortorder); |
|
413 | + print_liste_field_titre('Quantity', $_SERVER['PHP_SELF'], 'prod_qty', '', $param, 'align="right"', $sortfield, $sortorder); |
|
414 | + print_liste_field_titre('TotalHT', $_SERVER['PHP_SELF'], 'total_ht', '', $param, 'align="right"', $sortfield, $sortorder); |
|
415 | + print_liste_field_titre('UnitPrice', $_SERVER['PHP_SELF'], '', '', $param, 'align="right"', $sortfield, $sortorder); |
|
416 | 416 | print "</tr>\n"; |
417 | 417 | |
418 | 418 | |
419 | 419 | $i = 0; |
420 | 420 | while (($objp = $db->fetch_object($resql)) && $i < min($num, $limit)) |
421 | 421 | { |
422 | - $documentstatic->id=$objp->doc_id; |
|
423 | - $documentstatic->ref=$objp->doc_number; |
|
424 | - $documentstatic->type=$objp->doc_type; |
|
425 | - $documentstatic->fk_statut=$objp->status; |
|
426 | - $documentstatic->fk_status=$objp->status; |
|
427 | - $documentstatic->statut=$objp->status; |
|
428 | - $documentstatic->status=$objp->status; |
|
429 | - $documentstatic->paye=$objp->paid; |
|
422 | + $documentstatic->id = $objp->doc_id; |
|
423 | + $documentstatic->ref = $objp->doc_number; |
|
424 | + $documentstatic->type = $objp->doc_type; |
|
425 | + $documentstatic->fk_statut = $objp->status; |
|
426 | + $documentstatic->fk_status = $objp->status; |
|
427 | + $documentstatic->statut = $objp->status; |
|
428 | + $documentstatic->status = $objp->status; |
|
429 | + $documentstatic->paye = $objp->paid; |
|
430 | 430 | |
431 | - if (is_object($documentstaticline)) $documentstaticline->statut=$objp->status; |
|
431 | + if (is_object($documentstaticline)) $documentstaticline->statut = $objp->status; |
|
432 | 432 | |
433 | 433 | print '<tr class="oddeven">'; |
434 | 434 | print '<td class="nobordernopadding nowrap" width="100">'; |
435 | 435 | print $documentstatic->getNomUrl(1); |
436 | 436 | print '</td>'; |
437 | - print '<td align="center" width="80">'.dol_print_date($db->jdate($objp->dateprint),'day').'</td>'; |
|
437 | + print '<td align="center" width="80">'.dol_print_date($db->jdate($objp->dateprint), 'day').'</td>'; |
|
438 | 438 | |
439 | 439 | // Status |
440 | 440 | print '<td align="center">'; |
@@ -451,58 +451,58 @@ discard block |
||
451 | 451 | print '<td>'; |
452 | 452 | |
453 | 453 | // Define text, description and type |
454 | - $text=''; $description=''; $type=0; |
|
454 | + $text = ''; $description = ''; $type = 0; |
|
455 | 455 | |
456 | 456 | // Code to show product duplicated from commonobject->printObjectLine |
457 | 457 | if ($objp->fk_product > 0) |
458 | 458 | { |
459 | 459 | $product_static = new Product($db); |
460 | 460 | |
461 | - $product_static->type=$objp->fk_product_type; |
|
462 | - $product_static->id=$objp->fk_product; |
|
463 | - $product_static->ref=$objp->ref; |
|
464 | - $product_static->entity=$objp->pentity; |
|
465 | - $text=$product_static->getNomUrl(1); |
|
461 | + $product_static->type = $objp->fk_product_type; |
|
462 | + $product_static->id = $objp->fk_product; |
|
463 | + $product_static->ref = $objp->ref; |
|
464 | + $product_static->entity = $objp->pentity; |
|
465 | + $text = $product_static->getNomUrl(1); |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | // Product |
469 | 469 | if ($objp->fk_product > 0) |
470 | 470 | { |
471 | 471 | // Define output language |
472 | - if (! empty($conf->global->MAIN_MULTILANGS) && ! empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) |
|
472 | + if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) |
|
473 | 473 | { |
474 | 474 | $prod = new Product($db); |
475 | 475 | $prod->fetch($objp->fk_product); |
476 | 476 | |
477 | 477 | $outputlangs = $langs; |
478 | - $newlang=''; |
|
479 | - if (empty($newlang) && GETPOST('lang_id','aZ09')) $newlang=GETPOST('lang_id','aZ09'); |
|
480 | - if (empty($newlang)) $newlang=$object->default_lang; |
|
481 | - if (! empty($newlang)) |
|
478 | + $newlang = ''; |
|
479 | + if (empty($newlang) && GETPOST('lang_id', 'aZ09')) $newlang = GETPOST('lang_id', 'aZ09'); |
|
480 | + if (empty($newlang)) $newlang = $object->default_lang; |
|
481 | + if (!empty($newlang)) |
|
482 | 482 | { |
483 | - $outputlangs = new Translate("",$conf); |
|
483 | + $outputlangs = new Translate("", $conf); |
|
484 | 484 | $outputlangs->setDefaultLang($newlang); |
485 | 485 | } |
486 | 486 | |
487 | - $label = (! empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $objp->product_label; |
|
487 | + $label = (!empty($prod->multilangs[$outputlangs->defaultlang]["label"])) ? $prod->multilangs[$outputlangs->defaultlang]["label"] : $objp->product_label; |
|
488 | 488 | } |
489 | 489 | else |
490 | 490 | { |
491 | 491 | $label = $objp->product_label; |
492 | 492 | } |
493 | 493 | |
494 | - $text.= ' - '.(! empty($objp->label)?$objp->label:$label); |
|
495 | - $description=(! empty($conf->global->PRODUIT_DESC_IN_FORM)?'':dol_htmlentitiesbr($objp->description)); |
|
494 | + $text .= ' - '.(!empty($objp->label) ? $objp->label : $label); |
|
495 | + $description = (!empty($conf->global->PRODUIT_DESC_IN_FORM) ? '' : dol_htmlentitiesbr($objp->description)); |
|
496 | 496 | } |
497 | 497 | |
498 | 498 | if (($objp->info_bits & 2) == 2) { ?> |
499 | 499 | <a href="<?php echo DOL_URL_ROOT.'/comm/remx.php?id='.$object->id; ?>"> |
500 | 500 | <?php |
501 | - $txt=''; |
|
502 | - print img_object($langs->trans("ShowReduc"),'reduc').' '; |
|
503 | - if ($objp->description == '(DEPOSIT)') $txt=$langs->trans("Deposit"); |
|
504 | - elseif ($objp->description == '(EXCESS RECEIVED)') $txt=$langs->trans("ExcessReceived"); |
|
505 | - elseif ($objp->description == '(EXCESS PAID)') $txt=$langs->trans("ExcessPaid"); |
|
501 | + $txt = ''; |
|
502 | + print img_object($langs->trans("ShowReduc"), 'reduc').' '; |
|
503 | + if ($objp->description == '(DEPOSIT)') $txt = $langs->trans("Deposit"); |
|
504 | + elseif ($objp->description == '(EXCESS RECEIVED)') $txt = $langs->trans("ExcessReceived"); |
|
505 | + elseif ($objp->description == '(EXCESS PAID)') $txt = $langs->trans("ExcessPaid"); |
|
506 | 506 | //else $txt=$langs->trans("Discount"); |
507 | 507 | print $txt; |
508 | 508 | ?> |
@@ -512,33 +512,33 @@ discard block |
||
512 | 512 | { |
513 | 513 | if ($objp->description == '(CREDIT_NOTE)' && $objp->fk_remise_except > 0) |
514 | 514 | { |
515 | - $discount=new DiscountAbsolute($db); |
|
515 | + $discount = new DiscountAbsolute($db); |
|
516 | 516 | $discount->fetch($objp->fk_remise_except); |
517 | - echo ($txt?' - ':'').$langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0)); |
|
517 | + echo ($txt ? ' - ' : '').$langs->transnoentities("DiscountFromCreditNote", $discount->getNomUrl(0)); |
|
518 | 518 | } |
519 | 519 | if ($objp->description == '(EXCESS RECEIVED)' && $objp->fk_remise_except > 0) |
520 | 520 | { |
521 | - $discount=new DiscountAbsolute($db); |
|
521 | + $discount = new DiscountAbsolute($db); |
|
522 | 522 | $discount->fetch($objp->fk_remise_except); |
523 | - echo ($txt?' - ':'').$langs->transnoentities("DiscountFromExcessReceived",$discount->getNomUrl(0)); |
|
523 | + echo ($txt ? ' - ' : '').$langs->transnoentities("DiscountFromExcessReceived", $discount->getNomUrl(0)); |
|
524 | 524 | } |
525 | 525 | elseif ($objp->description == '(EXCESS PAID)' && $objp->fk_remise_except > 0) |
526 | 526 | { |
527 | - $discount=new DiscountAbsolute($db); |
|
527 | + $discount = new DiscountAbsolute($db); |
|
528 | 528 | $discount->fetch($objp->fk_remise_except); |
529 | - echo ($txt?' - ':'').$langs->transnoentities("DiscountFromExcessPaid",$discount->getNomUrl(0)); |
|
529 | + echo ($txt ? ' - ' : '').$langs->transnoentities("DiscountFromExcessPaid", $discount->getNomUrl(0)); |
|
530 | 530 | } |
531 | 531 | elseif ($objp->description == '(DEPOSIT)' && $objp->fk_remise_except > 0) |
532 | 532 | { |
533 | - $discount=new DiscountAbsolute($db); |
|
533 | + $discount = new DiscountAbsolute($db); |
|
534 | 534 | $discount->fetch($objp->fk_remise_except); |
535 | - echo ($txt?' - ':'').$langs->transnoentities("DiscountFromDeposit",$discount->getNomUrl(0)); |
|
535 | + echo ($txt ? ' - ' : '').$langs->transnoentities("DiscountFromDeposit", $discount->getNomUrl(0)); |
|
536 | 536 | // Add date of deposit |
537 | - if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) echo ' ('.dol_print_date($discount->datec).')'; |
|
537 | + if (!empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) echo ' ('.dol_print_date($discount->datec).')'; |
|
538 | 538 | } |
539 | 539 | else |
540 | 540 | { |
541 | - echo ($txt?' - ':'').dol_htmlentitiesbr($objp->description); |
|
541 | + echo ($txt ? ' - ' : '').dol_htmlentitiesbr($objp->description); |
|
542 | 542 | } |
543 | 543 | } |
544 | 544 | } |
@@ -546,33 +546,33 @@ discard block |
||
546 | 546 | { |
547 | 547 | if ($objp->fk_product > 0) { |
548 | 548 | |
549 | - echo $form->textwithtooltip($text,$description,3,'','',$i,0,''); |
|
549 | + echo $form->textwithtooltip($text, $description, 3, '', '', $i, 0, ''); |
|
550 | 550 | |
551 | 551 | // Show range |
552 | 552 | echo get_date_range($objp->date_start, $objp->date_end); |
553 | 553 | |
554 | 554 | // Add description in form |
555 | - if (! empty($conf->global->PRODUIT_DESC_IN_FORM)) |
|
555 | + if (!empty($conf->global->PRODUIT_DESC_IN_FORM)) |
|
556 | 556 | { |
557 | - print (! empty($objp->description) && $objp->description!=$objp->product_label)?'<br>'.dol_htmlentitiesbr($objp->description):''; |
|
557 | + print (!empty($objp->description) && $objp->description != $objp->product_label) ? '<br>'.dol_htmlentitiesbr($objp->description) : ''; |
|
558 | 558 | } |
559 | 559 | } else { |
560 | 560 | |
561 | - if (! empty($objp->label) || ! empty($objp->description)) |
|
561 | + if (!empty($objp->label) || !empty($objp->description)) |
|
562 | 562 | { |
563 | - if ($type==1) $text = img_object($langs->trans('Service'),'service'); |
|
564 | - else $text = img_object($langs->trans('Product'),'product'); |
|
563 | + if ($type == 1) $text = img_object($langs->trans('Service'), 'service'); |
|
564 | + else $text = img_object($langs->trans('Product'), 'product'); |
|
565 | 565 | |
566 | - if (! empty($objp->label)) { |
|
567 | - $text.= ' <strong>'.$objp->label.'</strong>'; |
|
568 | - echo $form->textwithtooltip($text,dol_htmlentitiesbr($objp->description),3,'','',$i,0,''); |
|
566 | + if (!empty($objp->label)) { |
|
567 | + $text .= ' <strong>'.$objp->label.'</strong>'; |
|
568 | + echo $form->textwithtooltip($text, dol_htmlentitiesbr($objp->description), 3, '', '', $i, 0, ''); |
|
569 | 569 | } else { |
570 | 570 | echo $text.' '.dol_htmlentitiesbr($objp->description); |
571 | 571 | } |
572 | 572 | } |
573 | 573 | |
574 | 574 | // Show range |
575 | - echo get_date_range($objp->date_start,$objp->date_end); |
|
575 | + echo get_date_range($objp->date_start, $objp->date_end); |
|
576 | 576 | } |
577 | 577 | } |
578 | 578 | |
@@ -599,43 +599,43 @@ discard block |
||
599 | 599 | //print '<td align="left">'.$prodreftxt.'</td>'; |
600 | 600 | |
601 | 601 | print '<td align="right">'.$objp->prod_qty.'</td>'; |
602 | - $total_qty+=$objp->prod_qty; |
|
602 | + $total_qty += $objp->prod_qty; |
|
603 | 603 | |
604 | 604 | print '<td align="right">'.price($objp->total_ht).'</td>'; |
605 | - $total_ht+=$objp->total_ht; |
|
605 | + $total_ht += $objp->total_ht; |
|
606 | 606 | |
607 | - print '<td align="right">'.price($objp->total_ht/(empty($objp->prod_qty)?1:$objp->prod_qty)).'</td>'; |
|
607 | + print '<td align="right">'.price($objp->total_ht / (empty($objp->prod_qty) ? 1 : $objp->prod_qty)).'</td>'; |
|
608 | 608 | |
609 | 609 | print "</tr>\n"; |
610 | 610 | $i++; |
611 | 611 | } |
612 | 612 | |
613 | 613 | print '<tr class="liste_total">'; |
614 | - print '<td>' . $langs->trans('Total') . '</td>'; |
|
614 | + print '<td>'.$langs->trans('Total').'</td>'; |
|
615 | 615 | print '<td colspan="3"></td>'; |
616 | - print '<td align="right">' . $total_qty . '</td>'; |
|
617 | - print '<td align="right">' . price($total_ht) . '</td>'; |
|
618 | - print '<td align="right">' . price($total_ht/(empty($total_qty)?1:$total_qty)) . '</td>'; |
|
616 | + print '<td align="right">'.$total_qty.'</td>'; |
|
617 | + print '<td align="right">'.price($total_ht).'</td>'; |
|
618 | + print '<td align="right">'.price($total_ht / (empty($total_qty) ? 1 : $total_qty)).'</td>'; |
|
619 | 619 | print "</table>"; |
620 | 620 | print '</div>'; |
621 | 621 | |
622 | 622 | if ($num > $limit) { |
623 | - print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder,'',$num); |
|
623 | + print_barre_liste('', $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num); |
|
624 | 624 | } |
625 | 625 | $db->free($resql); |
626 | 626 | } |
627 | 627 | else if (empty($type_element) || $type_element == -1) |
628 | 628 | { |
629 | - print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder,'',$num, '', ''); |
|
629 | + print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, '', ''); |
|
630 | 630 | |
631 | 631 | print '<table class="liste" width="100%">'."\n"; |
632 | 632 | // Titles with sort buttons |
633 | 633 | print '<tr class="liste_titre">'; |
634 | - print_liste_field_titre('Ref',$_SERVER['PHP_SELF'],'doc_number','',$param,'align="left"',$sortfield,$sortorder); |
|
635 | - print_liste_field_titre('Date',$_SERVER['PHP_SELF'],'dateprint','',$param,'align="center" width="150"',$sortfield,$sortorder); |
|
636 | - print_liste_field_titre('Status',$_SERVER['PHP_SELF'],'fk_status','',$param,'align="center"',$sortfield,$sortorder); |
|
637 | - print_liste_field_titre('Product',$_SERVER['PHP_SELF'],'','',$param,'align="left"',$sortfield,$sortorder); |
|
638 | - print_liste_field_titre('Quantity',$_SERVER['PHP_SELF'],'prod_qty','',$param,'align="right"',$sortfield,$sortorder); |
|
634 | + print_liste_field_titre('Ref', $_SERVER['PHP_SELF'], 'doc_number', '', $param, 'align="left"', $sortfield, $sortorder); |
|
635 | + print_liste_field_titre('Date', $_SERVER['PHP_SELF'], 'dateprint', '', $param, 'align="center" width="150"', $sortfield, $sortorder); |
|
636 | + print_liste_field_titre('Status', $_SERVER['PHP_SELF'], 'fk_status', '', $param, 'align="center"', $sortfield, $sortorder); |
|
637 | + print_liste_field_titre('Product', $_SERVER['PHP_SELF'], '', '', $param, 'align="left"', $sortfield, $sortorder); |
|
638 | + print_liste_field_titre('Quantity', $_SERVER['PHP_SELF'], 'prod_qty', '', $param, 'align="right"', $sortfield, $sortorder); |
|
639 | 639 | print "</tr>\n"; |
640 | 640 | |
641 | 641 | print '<tr class="oddeven"><td class="opacitymedium" colspan="5">'.$langs->trans("SelectElementAndClick", $langs->transnoentitiesnoconv("Search")).'</td></tr>'; |
@@ -643,7 +643,7 @@ discard block |
||
643 | 643 | print "</table>"; |
644 | 644 | } |
645 | 645 | else { |
646 | - print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder,'',$num, '', ''); |
|
646 | + print_barre_liste($langs->trans('ProductsIntoElements').' '.$typeElementString.' '.$button, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, '', ''); |
|
647 | 647 | |
648 | 648 | print '<table class="liste" width="100%">'."\n"; |
649 | 649 |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | // Security check |
43 | 43 | if ($user->societe_id > 0) |
44 | 44 | { |
45 | - unset($action); |
|
46 | - $socid = $user->societe_id; |
|
45 | + unset($action); |
|
46 | + $socid = $user->societe_id; |
|
47 | 47 | } |
48 | 48 | $result = restrictedArea($user, 'societe', $id, '&societe'); |
49 | 49 | |
@@ -61,10 +61,10 @@ discard block |
||
61 | 61 | $object = new Societe($db); |
62 | 62 | if ($id > 0 || ! empty($ref)) |
63 | 63 | { |
64 | - $result = $object->fetch($id, $ref); |
|
64 | + $result = $object->fetch($id, $ref); |
|
65 | 65 | |
66 | - $upload_dir = $conf->societe->multidir_output[$object->entity] . "/" . $object->id ; |
|
67 | - $courrier_dir = $conf->societe->multidir_output[$object->entity] . "/courrier/" . get_exdir($object->id,0,0,0,$object,'thirdparty'); |
|
66 | + $upload_dir = $conf->societe->multidir_output[$object->entity] . "/" . $object->id ; |
|
67 | + $courrier_dir = $conf->societe->multidir_output[$object->entity] . "/courrier/" . get_exdir($object->id,0,0,0,$object,'thirdparty'); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context |
@@ -92,24 +92,24 @@ discard block |
||
92 | 92 | |
93 | 93 | if ($object->id) |
94 | 94 | { |
95 | - /* |
|
95 | + /* |
|
96 | 96 | * Show tabs |
97 | 97 | */ |
98 | - if (! empty($conf->notification->enabled)) $langs->load("mails"); |
|
99 | - $head = societe_prepare_head($object); |
|
98 | + if (! empty($conf->notification->enabled)) $langs->load("mails"); |
|
99 | + $head = societe_prepare_head($object); |
|
100 | 100 | |
101 | - $form=new Form($db); |
|
101 | + $form=new Form($db); |
|
102 | 102 | |
103 | - dol_fiche_head($head, 'document', $langs->trans("ThirdParty"), -1, 'company'); |
|
103 | + dol_fiche_head($head, 'document', $langs->trans("ThirdParty"), -1, 'company'); |
|
104 | 104 | |
105 | 105 | |
106 | - // Build file list |
|
107 | - $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); |
|
108 | - $totalsize=0; |
|
109 | - foreach($filearray as $key => $file) |
|
110 | - { |
|
111 | - $totalsize+=$file['size']; |
|
112 | - } |
|
106 | + // Build file list |
|
107 | + $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); |
|
108 | + $totalsize=0; |
|
109 | + foreach($filearray as $key => $file) |
|
110 | + { |
|
111 | + $totalsize+=$file['size']; |
|
112 | + } |
|
113 | 113 | |
114 | 114 | $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>'; |
115 | 115 | |
@@ -118,53 +118,53 @@ discard block |
||
118 | 118 | print '<div class="fichecenter">'; |
119 | 119 | |
120 | 120 | print '<div class="underbanner clearboth"></div>'; |
121 | - print '<table class="border centpercent">'; |
|
122 | - |
|
123 | - // Prefix |
|
124 | - if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field |
|
125 | - { |
|
126 | - print '<tr><td class="titlefield">'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>'; |
|
127 | - } |
|
128 | - |
|
129 | - if ($object->client) |
|
130 | - { |
|
131 | - print '<tr><td class="titlefield">'; |
|
132 | - print $langs->trans('CustomerCode').'</td><td colspan="3">'; |
|
133 | - print $object->code_client; |
|
134 | - if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>'; |
|
135 | - print '</td></tr>'; |
|
136 | - } |
|
137 | - |
|
138 | - if ($object->fournisseur) |
|
139 | - { |
|
140 | - print '<tr><td class="titlefield">'; |
|
141 | - print $langs->trans('SupplierCode').'</td><td colspan="3">'; |
|
142 | - print $object->code_fournisseur; |
|
143 | - if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>'; |
|
144 | - print '</td></tr>'; |
|
145 | - } |
|
146 | - |
|
147 | - // Number of files |
|
148 | - print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>'; |
|
149 | - |
|
150 | - // Total size |
|
151 | - print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize,1,1).'</td></tr>'; |
|
152 | - |
|
153 | - print '</table>'; |
|
154 | - |
|
155 | - print '</div>'; |
|
156 | - |
|
157 | - dol_fiche_end(); |
|
158 | - |
|
159 | - $modulepart = 'societe'; |
|
160 | - $permission = $user->rights->societe->creer; |
|
161 | - $permtoedit = $user->rights->societe->creer; |
|
162 | - $param = '&id=' . $object->id; |
|
163 | - include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; |
|
121 | + print '<table class="border centpercent">'; |
|
122 | + |
|
123 | + // Prefix |
|
124 | + if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field |
|
125 | + { |
|
126 | + print '<tr><td class="titlefield">'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>'; |
|
127 | + } |
|
128 | + |
|
129 | + if ($object->client) |
|
130 | + { |
|
131 | + print '<tr><td class="titlefield">'; |
|
132 | + print $langs->trans('CustomerCode').'</td><td colspan="3">'; |
|
133 | + print $object->code_client; |
|
134 | + if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>'; |
|
135 | + print '</td></tr>'; |
|
136 | + } |
|
137 | + |
|
138 | + if ($object->fournisseur) |
|
139 | + { |
|
140 | + print '<tr><td class="titlefield">'; |
|
141 | + print $langs->trans('SupplierCode').'</td><td colspan="3">'; |
|
142 | + print $object->code_fournisseur; |
|
143 | + if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>'; |
|
144 | + print '</td></tr>'; |
|
145 | + } |
|
146 | + |
|
147 | + // Number of files |
|
148 | + print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>'; |
|
149 | + |
|
150 | + // Total size |
|
151 | + print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize,1,1).'</td></tr>'; |
|
152 | + |
|
153 | + print '</table>'; |
|
154 | + |
|
155 | + print '</div>'; |
|
156 | + |
|
157 | + dol_fiche_end(); |
|
158 | + |
|
159 | + $modulepart = 'societe'; |
|
160 | + $permission = $user->rights->societe->creer; |
|
161 | + $permtoedit = $user->rights->societe->creer; |
|
162 | + $param = '&id=' . $object->id; |
|
163 | + include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; |
|
164 | 164 | } |
165 | 165 | else |
166 | 166 | { |
167 | - accessforbidden('',0,0); |
|
167 | + accessforbidden('',0,0); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | // End of page |
@@ -55,8 +55,12 @@ discard block |
||
55 | 55 | $offset = $conf->liste_limit * $page; |
56 | 56 | $pageprev = $page - 1; |
57 | 57 | $pagenext = $page + 1; |
58 | -if (! $sortorder) $sortorder="ASC"; |
|
59 | -if (! $sortfield) $sortfield="position_name"; |
|
58 | +if (! $sortorder) { |
|
59 | + $sortorder="ASC"; |
|
60 | +} |
|
61 | +if (! $sortfield) { |
|
62 | + $sortfield="position_name"; |
|
63 | +} |
|
60 | 64 | |
61 | 65 | $object = new Societe($db); |
62 | 66 | if ($id > 0 || ! empty($ref)) |
@@ -86,7 +90,9 @@ discard block |
||
86 | 90 | $form = new Form($db); |
87 | 91 | |
88 | 92 | $title=$langs->trans("ThirdParty").' - '.$langs->trans("Files"); |
89 | -if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name.' - '.$langs->trans("Files"); |
|
93 | +if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) { |
|
94 | + $title=$object->name.' - '.$langs->trans("Files"); |
|
95 | +} |
|
90 | 96 | $help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; |
91 | 97 | llxHeader('',$title,$help_url); |
92 | 98 | |
@@ -95,7 +101,9 @@ discard block |
||
95 | 101 | /* |
96 | 102 | * Show tabs |
97 | 103 | */ |
98 | - if (! empty($conf->notification->enabled)) $langs->load("mails"); |
|
104 | + if (! empty($conf->notification->enabled)) { |
|
105 | + $langs->load("mails"); |
|
106 | + } |
|
99 | 107 | $head = societe_prepare_head($object); |
100 | 108 | |
101 | 109 | $form=new Form($db); |
@@ -121,17 +129,21 @@ discard block |
||
121 | 129 | print '<table class="border centpercent">'; |
122 | 130 | |
123 | 131 | // Prefix |
124 | - if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field |
|
132 | + if (! empty($conf->global->SOCIETE_USEPREFIX)) { |
|
133 | + // Old not used prefix field |
|
125 | 134 | { |
126 | 135 | print '<tr><td class="titlefield">'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>'; |
127 | 136 | } |
137 | + } |
|
128 | 138 | |
129 | 139 | if ($object->client) |
130 | 140 | { |
131 | 141 | print '<tr><td class="titlefield">'; |
132 | 142 | print $langs->trans('CustomerCode').'</td><td colspan="3">'; |
133 | 143 | print $object->code_client; |
134 | - if ($object->check_codeclient() <> 0) print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>'; |
|
144 | + if ($object->check_codeclient() <> 0) { |
|
145 | + print ' <font class="error">('.$langs->trans("WrongCustomerCode").')</font>'; |
|
146 | + } |
|
135 | 147 | print '</td></tr>'; |
136 | 148 | } |
137 | 149 | |
@@ -140,7 +152,9 @@ discard block |
||
140 | 152 | print '<tr><td class="titlefield">'; |
141 | 153 | print $langs->trans('SupplierCode').'</td><td colspan="3">'; |
142 | 154 | print $object->code_fournisseur; |
143 | - if ($object->check_codefournisseur() <> 0) print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>'; |
|
155 | + if ($object->check_codefournisseur() <> 0) { |
|
156 | + print ' <font class="error">('.$langs->trans("WrongSupplierCode").')</font>'; |
|
157 | + } |
|
144 | 158 | print '</td></tr>'; |
145 | 159 | } |
146 | 160 | |
@@ -161,8 +175,7 @@ discard block |
||
161 | 175 | $permtoedit = $user->rights->societe->creer; |
162 | 176 | $param = '&id=' . $object->id; |
163 | 177 | include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; |
164 | -} |
|
165 | -else |
|
178 | +} else |
|
166 | 179 | { |
167 | 180 | accessforbidden('',0,0); |
168 | 181 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | |
30 | 30 | // Copyright (C) 2018 Alxarafe/Alixar <[email protected]> |
31 | 31 | defined('BASE_PATH') or die('Single entry point through the index.php of the main folder'); |
32 | -require DOL_BASE_PATH . '/main.inc.php'; |
|
32 | +require DOL_BASE_PATH.'/main.inc.php'; |
|
33 | 33 | |
34 | 34 | require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; |
35 | 35 | require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; |
@@ -38,9 +38,9 @@ discard block |
||
38 | 38 | |
39 | 39 | $langs->loadLangs(array("companies", "other")); |
40 | 40 | |
41 | -$action=GETPOST('action','aZ09'); |
|
42 | -$confirm=GETPOST('confirm'); |
|
43 | -$id=(GETPOST('socid','int') ? GETPOST('socid','int') : GETPOST('id','int')); |
|
41 | +$action = GETPOST('action', 'aZ09'); |
|
42 | +$confirm = GETPOST('confirm'); |
|
43 | +$id = (GETPOST('socid', 'int') ? GETPOST('socid', 'int') : GETPOST('id', 'int')); |
|
44 | 44 | $ref = GETPOST('ref', 'alpha'); |
45 | 45 | |
46 | 46 | // Security check |
@@ -52,27 +52,27 @@ discard block |
||
52 | 52 | $result = restrictedArea($user, 'societe', $id, '&societe'); |
53 | 53 | |
54 | 54 | // Get parameters |
55 | -$sortfield = GETPOST("sortfield",'alpha'); |
|
56 | -$sortorder = GETPOST("sortorder",'alpha'); |
|
57 | -$page = GETPOST("page",'int'); |
|
55 | +$sortfield = GETPOST("sortfield", 'alpha'); |
|
56 | +$sortorder = GETPOST("sortorder", 'alpha'); |
|
57 | +$page = GETPOST("page", 'int'); |
|
58 | 58 | if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1 |
59 | 59 | $offset = $conf->liste_limit * $page; |
60 | 60 | $pageprev = $page - 1; |
61 | 61 | $pagenext = $page + 1; |
62 | -if (! $sortorder) $sortorder="ASC"; |
|
63 | -if (! $sortfield) $sortfield="position_name"; |
|
62 | +if (!$sortorder) $sortorder = "ASC"; |
|
63 | +if (!$sortfield) $sortfield = "position_name"; |
|
64 | 64 | |
65 | 65 | $object = new Societe($db); |
66 | -if ($id > 0 || ! empty($ref)) |
|
66 | +if ($id > 0 || !empty($ref)) |
|
67 | 67 | { |
68 | 68 | $result = $object->fetch($id, $ref); |
69 | 69 | |
70 | - $upload_dir = $conf->societe->multidir_output[$object->entity] . "/" . $object->id ; |
|
71 | - $courrier_dir = $conf->societe->multidir_output[$object->entity] . "/courrier/" . get_exdir($object->id,0,0,0,$object,'thirdparty'); |
|
70 | + $upload_dir = $conf->societe->multidir_output[$object->entity]."/".$object->id; |
|
71 | + $courrier_dir = $conf->societe->multidir_output[$object->entity]."/courrier/".get_exdir($object->id, 0, 0, 0, $object, 'thirdparty'); |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context |
75 | -$hookmanager->initHooks(array('thirdpartydocument','globalcard')); |
|
75 | +$hookmanager->initHooks(array('thirdpartydocument', 'globalcard')); |
|
76 | 76 | |
77 | 77 | |
78 | 78 | |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * Actions |
81 | 81 | */ |
82 | 82 | |
83 | -include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php'; |
|
83 | +include_once DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php'; |
|
84 | 84 | |
85 | 85 | |
86 | 86 | /* |
@@ -89,35 +89,35 @@ discard block |
||
89 | 89 | |
90 | 90 | $form = new Form($db); |
91 | 91 | |
92 | -$title=$langs->trans("ThirdParty").' - '.$langs->trans("Files"); |
|
93 | -if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name.' - '.$langs->trans("Files"); |
|
94 | -$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; |
|
95 | -llxHeader('',$title,$help_url); |
|
92 | +$title = $langs->trans("ThirdParty").' - '.$langs->trans("Files"); |
|
93 | +if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) $title = $object->name.' - '.$langs->trans("Files"); |
|
94 | +$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; |
|
95 | +llxHeader('', $title, $help_url); |
|
96 | 96 | |
97 | 97 | if ($object->id) |
98 | 98 | { |
99 | 99 | /* |
100 | 100 | * Show tabs |
101 | 101 | */ |
102 | - if (! empty($conf->notification->enabled)) $langs->load("mails"); |
|
102 | + if (!empty($conf->notification->enabled)) $langs->load("mails"); |
|
103 | 103 | $head = societe_prepare_head($object); |
104 | 104 | |
105 | - $form=new Form($db); |
|
105 | + $form = new Form($db); |
|
106 | 106 | |
107 | 107 | dol_fiche_head($head, 'document', $langs->trans("ThirdParty"), -1, 'company'); |
108 | 108 | |
109 | 109 | |
110 | 110 | // Build file list |
111 | - $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); |
|
112 | - $totalsize=0; |
|
113 | - foreach($filearray as $key => $file) |
|
111 | + $filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1); |
|
112 | + $totalsize = 0; |
|
113 | + foreach ($filearray as $key => $file) |
|
114 | 114 | { |
115 | - $totalsize+=$file['size']; |
|
115 | + $totalsize += $file['size']; |
|
116 | 116 | } |
117 | 117 | |
118 | 118 | $linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>'; |
119 | 119 | |
120 | - dol_banner_tab($object, 'socid', $linkback, ($user->societe_id?0:1), 'rowid', 'nom'); |
|
120 | + dol_banner_tab($object, 'socid', $linkback, ($user->societe_id ? 0 : 1), 'rowid', 'nom'); |
|
121 | 121 | |
122 | 122 | print '<div class="fichecenter">'; |
123 | 123 | |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | print '<table class="border centpercent">'; |
126 | 126 | |
127 | 127 | // Prefix |
128 | - if (! empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field |
|
128 | + if (!empty($conf->global->SOCIETE_USEPREFIX)) // Old not used prefix field |
|
129 | 129 | { |
130 | 130 | print '<tr><td class="titlefield">'.$langs->trans('Prefix').'</td><td colspan="3">'.$object->prefix_comm.'</td></tr>'; |
131 | 131 | } |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>'; |
153 | 153 | |
154 | 154 | // Total size |
155 | - print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize,1,1).'</td></tr>'; |
|
155 | + print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>'; |
|
156 | 156 | |
157 | 157 | print '</table>'; |
158 | 158 | |
@@ -163,12 +163,12 @@ discard block |
||
163 | 163 | $modulepart = 'societe'; |
164 | 164 | $permission = $user->rights->societe->creer; |
165 | 165 | $permtoedit = $user->rights->societe->creer; |
166 | - $param = '&id=' . $object->id; |
|
167 | - include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; |
|
166 | + $param = '&id='.$object->id; |
|
167 | + include_once DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php'; |
|
168 | 168 | } |
169 | 169 | else |
170 | 170 | { |
171 | - accessforbidden('',0,0); |
|
171 | + accessforbidden('', 0, 0); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | // End of page |