dolibarr 23.0.3
receptionlinebatch.class.php
1<?php
2/* Copyright (C) 2015 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2014 Juanjo Menent <jmenent@2byte.es>
4 * Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
5 * Copyright (C) 2024 Christophe Battarel <christophe@altairis.fr>
6 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
7 * Copyright (C) 2025 Nick Fragoulis
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 */
22
30// Put here all includes required by your class file
31require_once DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php";
32require_once DOL_DOCUMENT_ROOT."/reception/class/reception.class.php";
33
34
39{
44 public $TRIGGER_PREFIX = 'LINERECEPTION'; // to be overridden in child class implementations, i.e. 'BILL', 'TASK', 'PROPAL', etc.
45
49 public $db;
50
54 public $element = 'receptionlinebatch';
55
59 public $table_element = 'receptiondet_batch';
60 public $lines = array();
61
65 public $id;
66
70 public $fk_reception;
71
75 public $fk_element;
76
80 public $origin_id;
81
85 public $fk_elementdet;
86
90 public $origin_line_id;
91
95 public $element_type;
96
100 public $fk_product;
101
105 public $qty;
106
110 public $qty_asked;
111
115 public $libelle;
119 public $label;
123 public $desc;
127 public $tva_tx;
131 public $vat_src_code;
135 public $ref_supplier;
136
140 public $fk_entrepot;
141
145 public $fk_user;
146
150 public $datec = '';
154 public $comment;
155
159 public $status;
160
164 public $batch;
168 public $eatby = null;
172 public $sellby = null;
176 public $cost_price = 0;
180 public $rang;
181
182
188 public function __construct($db)
189 {
190 $this->db = $db;
191
192 // List of language codes for status
193 $this->labelStatus[0] = 'Received';
194 $this->labelStatus[1] = 'Verified';
195 $this->labelStatus[2] = 'Denied';
196 $this->labelStatusShort[0] = 'Received';
197 $this->labelStatusShort[1] = 'Verified';
198 $this->labelStatusShort[2] = 'Denied';
199 }
200
201
209 public function create($user, $notrigger = 0)
210 {
211 $error = 0;
212
213 // Clean parameters
214 if (isset($this->fk_element)) {
215 $this->fk_element = (int) $this->fk_element;
216 }
217 if (isset($this->fk_product)) {
218 $this->fk_product = (int) $this->fk_product;
219 }
220 if (isset($this->fk_elementdet)) {
221 $this->fk_elementdet = (int) $this->fk_elementdet;
222 }
223 if (isset($this->qty)) {
224 $this->qty = (float) $this->qty;
225 }
226 if (isset($this->fk_entrepot)) {
227 $this->fk_entrepot = (int) $this->fk_entrepot;
228 }
229 if (isset($this->fk_user)) {
230 $this->fk_user = (int) $this->fk_user;
231 }
232 if (isset($this->comment)) {
233 $this->comment = trim($this->comment);
234 }
235 if (isset($this->status)) {
236 $this->status = (int) $this->status;
237 }
238 if (isset($this->batch)) {
239 $this->batch = trim($this->batch);
240 }
241 if (empty($this->datec)) {
242 $this->datec = dol_now();
243 }
244
245 // Check parameters
246 if (empty($this->fk_product)) {
247 $this->error = 'Error, property ->fk_product must not be empty to create a line of reception';
248 return -1;
249 }
250 if (empty($this->fk_reception)) {
251 $this->error = 'Error, property ->fk_reception must not be empty to create a line of reception';
252 return -1;
253 }
254
255
256 if (empty($this->rang)) {
257 $this->rang = 0;
258 }
259
260 // Rank to use
261 $ranktouse = $this->rang;
262 if ($ranktouse == -1) {
263 $rangmax = $this->line_max($this->fk_reception);
264 $ranktouse = $rangmax + 1;
265 }
266
267 // Insert request
268 $sql = "INSERT INTO ".MAIN_DB_PREFIX.$this->table_element."(";
269 $sql .= "fk_product,";
270 $sql .= "fk_element,";
271 $sql .= "fk_elementdet,";
272 $sql .= "element_type,";
273 $sql .= "qty,";
274 $sql .= "fk_entrepot,";
275 $sql .= "fk_user,";
276 $sql .= "datec,";
277 $sql .= "comment,";
278 $sql .= "status,";
279 $sql .= "batch,";
280 $sql .= "eatby,";
281 $sql .= "sellby,";
282 $sql .= "fk_unit,";
283 $sql .= "description,";
284 $sql .= "rang,";
285 $sql .= "fk_reception,";
286 $sql .= "cost_price";
287 $sql .= ") VALUES (";
288 $sql .= " ".(!isset($this->fk_product) ? 'NULL' : (int) $this->fk_product).",";
289 $sql .= " ".(!isset($this->fk_element) ? 'NULL' : (int) $this->fk_element).",";
290 $sql .= " ".(!isset($this->fk_elementdet) ? 'NULL' : (int) $this->fk_elementdet).",";
291 $sql .= " '".(!isset($this->element_type) ? "supplier_order" : $this->db->escape($this->element_type))."',";
292 $sql .= " ".(!isset($this->qty) ? 'NULL' : (float) $this->qty).",";
293 $sql .= " ".(!isset($this->fk_entrepot) ? 'NULL' : (int) $this->fk_entrepot).",";
294 $sql .= " ".(!isset($this->fk_user) ? 'NULL' : (int) $this->fk_user).",";
295 $sql .= " ".(!isset($this->datec) || dol_strlen($this->datec) == 0 ? 'NULL' : "'".$this->db->idate($this->datec)."'").",";
296 $sql .= " ".(!isset($this->comment) ? 'NULL' : "'".$this->db->escape($this->comment)."'").",";
297 $sql .= " ".(!isset($this->status) ? 'NULL' : (int) $this->status).",";
298 $sql .= " ".(!isset($this->batch) ? 'NULL' : "'".$this->db->escape($this->batch)."'").",";
299 $sql .= " ".(!isset($this->eatby) || dol_strlen((string) $this->eatby) == 0 ? 'NULL' : "'".$this->db->idate($this->eatby)."'").",";
300 $sql .= " ".(!isset($this->sellby) || dol_strlen((string) $this->sellby) == 0 ? 'NULL' : "'".$this->db->idate($this->sellby)."'").",";
301 $sql .= " ".((int) $this->fk_unit);
302 $sql .= ", '".(empty($this->description) ? '' : $this->db->escape($this->description))."'";
303 $sql .= ", ".((int) $ranktouse).",";
304 $sql .= " ".((int) $this->fk_reception).",";
305 $sql .= " ".(!isset($this->cost_price) ? '0' : (float) $this->cost_price);
306 $sql .= ")";
307
308 $this->db->begin();
309
310 dol_syslog(__METHOD__, LOG_DEBUG);
311 $resql = $this->db->query($sql);
312 if (!$resql) {
313 $error++;
314 $this->errors[] = "Error ".$this->db->lasterror();
315 }
316
317 if (!$error) {
318 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
319
320 if (!$notrigger) {
321 // Call triggers
322 $result = $this->call_trigger('LINERECEPTION_CREATE', $user);
323 if ($result < 0) {
324 $error++;
325 }
326 // End call triggers
327 }
328 }
329
330 // Create extrafields
331 if (!$error) {
332 $result = $this->insertExtraFields();
333 if ($result < 0) {
334 $error++;
335 }
336 }
337
338 // Commit or rollback
339 if ($error) {
340 foreach ($this->errors as $errmsg) {
341 dol_syslog(__METHOD__." ".$errmsg, LOG_ERR);
342 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
343 }
344 $this->db->rollback();
345 return -1 * $error;
346 } else {
347 $this->db->commit();
348 return $this->id;
349 }
350 }
351
352
360 public function insert($user = null, $notrigger = 0)
361 {
362 global $langs;
363 $error = 0;
364
365 // Check parameters
366 $origin_id = $this->origin_id;
367 if ($origin_id > 0) {
368 if ((empty($this->fk_reception)
369 || (empty($this->fk_elementdet))
370 || !is_numeric($this->qty))) {
371 $langs->load('errors');
372 $this->errors[] = $langs->trans('ErrorMandatoryParametersNotProvided');
373 return -1;
374 }
375 } else {
376 if (empty($this->fk_reception) || !is_numeric($this->qty)) {
377 $langs->load('errors');
378 $this->errors[] = $langs->trans('ErrorMandatoryParametersNotProvided');
379 return -1;
380 }
381 }
382 $this->db->begin();
383
384 if (empty($this->rang)) {
385 $this->rang = 0;
386 }
387
388 // Rank to use
389 $ranktouse = $this->rang;
390 if ($ranktouse == -1) {
391 $rangmax = $this->line_max($this->fk_reception);
392 $ranktouse = $rangmax + 1;
393 }
394
395 $sql = "INSERT INTO ".MAIN_DB_PREFIX."receptiondet_batch (";
396 $sql .= "fk_reception";
397 $sql .= ", fk_entrepot";
398 $sql .= ", fk_elementdet";
399 $sql .= ", fk_product";
400 $sql .= ", element_type";
401 $sql .= ", qty";
402 $sql .= ", fk_unit";
403 $sql .= ", description";
404 $sql .= ", rang";
405 $sql .= ") VALUES (";
406 $sql .= $this->fk_reception;
407 $sql .= ", ".(empty($this->fk_entrepot) ? 'NULL' : $this->fk_entrepot);
408 $sql .= ", ".(empty($this->fk_elementdet) ? 'NULL' : $this->fk_elementdet);
409 $sql .= ", ".(empty($this->fk_product) ? 'NULL' : $this->fk_product);
410 $sql .= ", '".(empty($this->element_type) ? 'order' : $this->db->escape($this->element_type))."'";
411 $sql .= ", ".price2num($this->qty, 'MS');
412 $sql .= ", ".((int) $this->fk_unit);
413 $sql .= ", '".(empty($this->description) ? '' : $this->db->escape($this->description))."'";
414 $sql .= ", ".((int) $ranktouse);
415 $sql .= ")";
416
417 dol_syslog(get_class($this)."::insert", LOG_DEBUG);
418 $resql = $this->db->query($sql);
419 if ($resql) {
420 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."receptiondet_batch");
421
422
423 $result = $this->insertExtraFields();
424 if ($result < 0) {
425 $error++;
426 }
427
428
429 if (!$error && !$notrigger) {
430 // Call trigger
431 $result = $this->call_trigger('LINERECEPTION_INSERT', $user);
432 if ($result < 0) {
433 $error++;
434 }
435 // End call triggers
436 }
437
438 if ($error) {
439 foreach ($this->errors as $errmsg) {
440 dol_syslog(__METHOD__.' '.$errmsg, LOG_ERR);
441 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
442 }
443 }
444 } else {
445 $error++;
446 }
447
448 if ($error) {
449 $this->db->rollback();
450 return -1;
451 } else {
452 $this->db->commit();
453 return $this->id;
454 }
455 }
456
464 public function fetch($id, $ref = '')
465 {
466 $sql = "SELECT";
467 $sql .= " t.rowid,";
468 $sql .= " t.fk_element,";
469 $sql .= " t.fk_elementdet,";
470 $sql .= " t.element_type,";
471 $sql .= " t.fk_product,";
472 $sql .= " t.qty,";
473 $sql .= " t.fk_entrepot,";
474 $sql .= " t.fk_user,";
475 $sql .= " t.datec,";
476 $sql .= " t.comment,";
477 $sql .= " t.status,";
478 $sql .= " t.tms,";
479 $sql .= " t.batch,";
480 $sql .= " t.eatby,";
481 $sql .= " t.sellby,";
482 $sql .= " t.fk_unit,";
483 $sql .= " t.description,";
484 $sql .= " t.rang,";
485 $sql .= " t.fk_reception";
486 $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
487 if ($ref) {
488 $sql .= " WHERE t.ref = '".$this->db->escape($ref)."'";
489 } else {
490 $sql .= " WHERE t.rowid = ".((int) $id);
491 }
492
493 dol_syslog(get_class($this)."::fetch");
494 $resql = $this->db->query($sql);
495 if ($resql) {
496 if ($this->db->num_rows($resql)) {
497 $obj = $this->db->fetch_object($resql);
498
499 $this->id = $obj->rowid;
500
501 $this->fk_element = $obj->fk_element;
502 $this->origin_id = $obj->fk_element;
503 $this->fk_elementdet = $obj->fk_elementdet;
504 $this->origin_line_id = $obj->fk_elementdet;
505 $this->element_type = $obj->element_type;
506 $this->origin_type = $obj->element_type;
507 $this->fk_product = $obj->fk_product;
508 $this->qty = $obj->qty;
509 $this->fk_entrepot = $obj->fk_entrepot;
510 $this->fk_user = $obj->fk_user;
511 $this->datec = $this->db->jdate($obj->datec);
512 $this->comment = $obj->comment;
513 $this->status = $obj->status;
514 $this->tms = $this->db->jdate($obj->tms);
515 $this->batch = $obj->batch;
516 $this->eatby = $this->db->jdate($obj->eatby);
517 $this->sellby = $this->db->jdate($obj->sellby);
518 $this->description = $obj->description;
519 $this->fk_unit = $obj->fk_unit;
520 $this->rang = $obj->rang;
521 $this->fk_reception = $obj->fk_reception;
522
523 $this->fetch_optionals();
524 }
525 $this->db->free($resql);
526
527 return 1;
528 } else {
529 $this->error = "Error ".$this->db->lasterror();
530 return -1;
531 }
532 }
533
534
542 public function update($user, $notrigger = 0)
543 {
544 $error = 0;
545
546 // Clean parameters
547
548 if (isset($this->fk_element)) {
549 $this->fk_element = (int) $this->fk_element;
550 }
551 if (isset($this->fk_product)) {
552 $this->fk_product = (int) $this->fk_product;
553 }
554 if (isset($this->fk_elementdet)) {
555 $this->fk_elementdet = (int) $this->fk_elementdet;
556 }
557 if (isset($this->qty)) {
558 $this->qty = (float) $this->qty;
559 }
560 if (isset($this->fk_entrepot)) {
561 $this->fk_entrepot = (int) $this->fk_entrepot;
562 }
563 if (isset($this->fk_user)) {
564 $this->fk_user = (int) $this->fk_user;
565 }
566 if (isset($this->comment)) {
567 $this->comment = trim($this->comment);
568 }
569 if (isset($this->status)) {
570 $this->status = (int) $this->status;
571 }
572 if (isset($this->batch)) {
573 $this->batch = trim($this->batch);
574 }
575
576
577 // Check parameters
578 // Put here code to add a control on parameters values
579
580 // Update request
581 $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET";
582 $sql .= " fk_element=".(isset($this->fk_element) ? $this->fk_element : "null").",";
583 $sql .= " fk_product=".(isset($this->fk_product) ? $this->fk_product : "null").",";
584 $sql .= " fk_elementdet=".(isset($this->fk_elementdet) ? $this->fk_elementdet : "null").",";
585 $sql .= " qty=".(isset($this->qty) ? $this->qty : "null").",";
586 $sql .= " fk_entrepot=".(isset($this->fk_entrepot) ? $this->fk_entrepot : "null").",";
587 $sql .= " fk_user=".(isset($this->fk_user) ? $this->fk_user : "null").",";
588 $sql .= " datec=".(dol_strlen($this->datec) != 0 ? "'".$this->db->idate($this->datec)."'" : 'null').",";
589 $sql .= " comment=".(isset($this->comment) ? "'".$this->db->escape($this->comment)."'" : "null").",";
590 $sql .= " status=".(isset($this->status) ? $this->status : "null").",";
591 $sql .= " tms=".(dol_strlen((string) $this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : 'null').",";
592 $sql .= " batch=".(isset($this->batch) ? "'".$this->db->escape($this->batch)."'" : "null").",";
593 $sql .= " eatby=".(dol_strlen((string) $this->eatby) != 0 ? "'".$this->db->idate((int) $this->eatby)."'" : 'null').",";
594 $sql .= " sellby=".(dol_strlen((string) $this->sellby) != 0 ? "'".$this->db->idate((int) $this->sellby)."'" : 'null').",";
595 $sql .= " fk_unit = ".((int) $this->fk_unit);
596 $sql .= " WHERE rowid=".((int) $this->id);
597
598 $this->db->begin();
599
600 dol_syslog(__METHOD__);
601 $resql = $this->db->query($sql);
602 if (!$resql) {
603 $error++;
604 $this->errors[] = "Error ".$this->db->lasterror();
605 }
606
607 if (!$error) {
608 if (empty($this->id) && !empty($this->rowid)) {
609 $this->id = $this->rowid;
610 }
611 $result = $this->insertExtraFields();
612 if ($result < 0) {
613 $error++;
614 }
615
616 if (!$notrigger) {
617 // Call triggers
618 $result = $this->call_trigger('LINERECEPTION_MODIFY', $user);
619 if ($result < 0) {
620 $error++;
621 }
622 // End call triggers
623 }
624 }
625
626 // Commit or rollback
627 if ($error) {
628 foreach ($this->errors as $errmsg) {
629 dol_syslog(__METHOD__." ".$errmsg, LOG_ERR);
630 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
631 }
632 $this->db->rollback();
633 return -1 * $error;
634 } else {
635 $this->db->commit();
636 return 1;
637 }
638 }
639
640
648 public function delete($user, $notrigger = 0)
649 {
650 $error = 0;
651
652 $this->db->begin();
653
654 if (!$notrigger) {
655 // Call triggers
656 $result = $this->call_trigger('LINERECEPTION_DELETE', $user);
657 if ($result < 0) {
658 $error++;
659 }
660 // End call triggers
661 }
662
663
664 // Remove extrafields
665 if (!$error) {
666 $result = $this->deleteExtraFields();
667 if ($result < 0) {
668 $error++;
669 dol_syslog(get_class($this)."::delete error deleteExtraFields ".$this->error, LOG_ERR);
670 }
671 }
672
673 if (!$error) {
674 $sql = "DELETE FROM ".MAIN_DB_PREFIX.$this->table_element;
675 $sql .= " WHERE rowid=".((int) $this->id);
676
677 dol_syslog(__METHOD__);
678 $resql = $this->db->query($sql);
679 if (!$resql) {
680 $error++;
681 $this->errors[] = "Error ".$this->db->lasterror();
682 }
683 }
684
685 // Commit or rollback
686 if ($error) {
687 foreach ($this->errors as $errmsg) {
688 dol_syslog(__METHOD__." ".$errmsg, LOG_ERR);
689 $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
690 }
691 $this->db->rollback();
692 return -1 * $error;
693 } else {
694 $this->db->commit();
695 return 1;
696 }
697 }
698
699
707 public function createFromClone(User $user, $fromid)
708 {
709 $error = 0;
710
711 $object = new ReceptionLineBatch($this->db);
712
713 $this->db->begin();
714
715 // Load source object
716 $object->fetch($fromid);
717 $object->id = 0;
718 $object->status = 0;
719 $object->statut = 0;
720
721 // Clear fields
722 // ...
723
724 // Create clone
725 $object->context['createfromclone'] = 'createfromclone';
726 $result = $object->create($user);
727
728 // Other options
729 if ($result < 0) {
731 $error++;
732 }
733
734 if (!$error) {
735 }
736
737 unset($object->context['createfromclone']);
738
739 // End
740 if (!$error) {
741 $this->db->commit();
742 return $object->id;
743 } else {
744 $this->db->rollback();
745 return -1;
746 }
747 }
748
749
756 public function getLibStatut($mode = 0)
757 {
758 return $this->LibStatut($this->status, $mode);
759 }
760
761 // phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
769 public function LibStatut($status, $mode = 0)
770 {
771 // phpcs:enable
772 global $langs;
773 $langs->load('orders');
774
775 if ($mode == 0) {
776 return $langs->trans($this->labelStatus[$status]);
777 } elseif ($mode == 1) {
778 return $langs->trans($this->labelStatusShort[$status]);
779 } elseif ($mode == 2) {
780 return $langs->trans($this->labelStatus[$status]);
781 } elseif ($mode == 3) {
782 if ($status == 0) {
783 return img_picto($langs->trans($this->labelStatus[$status]), 'statut0');
784 } elseif ($status == 1) {
785 return img_picto($langs->trans($this->labelStatus[$status]), 'statut4');
786 } elseif ($status == 2) {
787 return img_picto($langs->trans($this->labelStatus[$status]), 'statut8');
788 }
789 } elseif ($mode == 4) {
790 if ($status == 0) {
791 return img_picto($langs->trans($this->labelStatus[$status]), 'statut0').' '.$langs->trans($this->labelStatus[$status]);
792 } elseif ($status == 1) {
793 return img_picto($langs->trans($this->labelStatus[$status]), 'statut4').' '.$langs->trans($this->labelStatus[$status]);
794 } elseif ($status == 2) {
795 return img_picto($langs->trans($this->labelStatus[$status]), 'statut8').' '.$langs->trans($this->labelStatus[$status]);
796 }
797 } elseif ($mode == 5) {
798 if ($status == 0) {
799 return '<span class="hideonsmartphone">'.$langs->trans($this->labelStatusShort[$status]).' </span>'.img_picto($langs->trans($this->labelStatus[$status]), 'statut0');
800 } elseif ($status == 1) {
801 return '<span class="hideonsmartphone">'.$langs->trans($this->labelStatusShort[$status]).' </span>'.img_picto($langs->trans($this->labelStatus[$status]), 'statut4');
802 } elseif ($status == 2) {
803 return '<span class="hideonsmartphone">'.$langs->trans($this->labelStatusShort[$status]).' </span>'.img_picto($langs->trans($this->labelStatus[$status]), 'statut8');
804 }
805 }
806 return "";
807 }
808
809
816 public function initAsSpecimen()
817 {
818 $this->id = 0;
819
820 $this->fk_element = 0;
821 $this->fk_product = 0;
822 $this->fk_elementdet = 0;
823 $this->qty = 0;
824 $this->fk_entrepot = 0;
825 $this->fk_user = 0;
826 $this->datec = '';
827 $this->comment = '';
828 $this->status = 0;
829 $this->tms = dol_now();
830 $this->batch = '';
831 $this->eatby = null;
832 $this->sellby = null;
833
834 return 1;
835 }
836
837
849 public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, $filter = '', $filtermode = 'AND')
850 {
851 dol_syslog(__METHOD__, LOG_DEBUG);
852
853 $sql = "SELECT";
854 $sql .= " t.rowid,";
855 $sql .= " t.fk_element,";
856 $sql .= " t.fk_product,";
857 $sql .= " t.fk_elementdet,";
858 $sql .= " t.qty,";
859 $sql .= " t.fk_entrepot,";
860 $sql .= " t.fk_user,";
861 $sql .= " t.datec,";
862 $sql .= " t.comment,";
863 $sql .= " t.status,";
864 $sql .= " t.tms,";
865 $sql .= " t.batch,";
866 $sql .= " t.eatby,";
867 $sql .= " t.sellby,";
868 $sql .= " t.fk_unit,";
869 $sql .= " t.description,";
870 $sql .= " t.rang";
871 $sql .= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t";
872
873 // Manage filter
874 if (is_array($filter)) {
875 $sqlwhere = array();
876 if (count($filter) > 0) {
877 foreach ($filter as $key => $value) {
878 if ($key == 't.comment') {
879 $sqlwhere [] = $this->db->sanitize($key)." LIKE '%".$this->db->escape($this->db->escapeforlike($value))."%'";
880 } elseif ($key == 't.datec' || $key == 't.tms' || $key == 't.eatby' || $key == 't.sellby' || $key == 't.batch') {
881 $sqlwhere [] = $this->db->sanitize($key)." = '".$this->db->escape($value)."'";
882 } elseif ($key == 'qty') {
883 $sqlwhere [] = $this->db->sanitize($key)." = ".((float) $value);
884 } else {
885 $sqlwhere [] = $this->db->sanitize($key)." = ".((int) $value);
886 }
887 }
888 }
889 if (count($sqlwhere) > 0) {
890 $sql .= ' WHERE '.implode(' '.$this->db->escape($filtermode).' ', $sqlwhere);
891 }
892
893 $filter = '';
894 }
895
896 // Manage filter
897 $errormessage = '';
898 $sql .= forgeSQLFromUniversalSearchCriteria($filter, $errormessage);
899 if ($errormessage) {
900 $this->errors[] = $errormessage;
901 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
902 return -1;
903 }
904
905 if (!empty($sortfield)) {
906 $sql .= $this->db->order($sortfield, $sortorder);
907 }
908 if (!empty($limit)) {
909 $sql .= $this->db->plimit($limit, $offset);
910 }
911 $this->lines = array();
912
913 $resql = $this->db->query($sql);
914 if ($resql) {
915 $num = $this->db->num_rows($resql);
916
917 while ($obj = $this->db->fetch_object($resql)) {
918 $line = new self($this->db);
919
920 $line->id = $obj->rowid;
921
922 $line->fk_element = $obj->fk_element;
923 $line->fk_product = $obj->fk_product;
924 $line->fk_elementdet = $obj->fk_elementdet;
925 $line->qty = $obj->qty;
926 $line->fk_entrepot = $obj->fk_entrepot;
927 $line->fk_user = $obj->fk_user;
928 $line->datec = $this->db->jdate($obj->datec);
929 $line->comment = $obj->comment;
930 $line->status = $obj->status;
931 $line->tms = $this->db->jdate($obj->tms);
932 $line->batch = $obj->batch;
933 $line->eatby = $this->db->jdate($obj->eatby);
934 $line->sellby = $this->db->jdate($obj->sellby);
935 $line->description = $obj->description;
936 $line->fk_unit = $obj->fk_unit;
937 $line->rang = $obj->rang;
938 $line->fetch_optionals();
939
940 $this->lines[$line->id] = $line;
941 }
942 $this->db->free($resql);
943
944 return $num;
945 } else {
946 $this->errors[] = 'Error '.$this->db->lasterror();
947 dol_syslog(__METHOD__.' '.implode(',', $this->errors), LOG_ERR);
948
949 return -1;
950 }
951 }
952}
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
setErrorsFromObject($object)
setErrorsFromObject
deleteExtraFields()
Delete all extra fields values for the current object.
line_max($fk_parent_line=0)
Get max value used for position of line (rang)
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
Parent class for class inheritance lines of business objects This class is useless for the moment so ...
Class to manage table commandefournisseurdispatch.
initAsSpecimen()
Initialise object with example values Id must be 0 if object instance is a specimen.
insert($user=null, $notrigger=0)
Insert line into database.
createFromClone(User $user, $fromid)
Load an object from its id and create a new one in database.
update($user, $notrigger=0)
Update object into database.
LibStatut($status, $mode=0)
Return label of a status.
$table_element
Name of table without prefix where object is stored.
create($user, $notrigger=0)
Create object into database.
getLibStatut($mode=0)
Return label of the status of object.
fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter='', $filtermode='AND')
Load object in memory from the database.
fetch($id, $ref='')
Load object in memory from the database.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
Definition index.php:171
print $script_file $mode $langs defaultlang(is_numeric($duration_value) ? " delay=". $duration_value :"").(is_numeric($duration_value2) ? " after cd cd cd description as description
Only used if Module[ID]Desc translation string is not found.
dol_now($mode='gmt')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
forgeSQLFromUniversalSearchCriteria($filter, &$errorstr='', $noand=0, $nopar=0, $noerror=0)
forgeSQLFromUniversalSearchCriteria
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.