44require_once DOL_DOCUMENT_ROOT.
'/core/class/commonorder.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.orderline.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
48require_once DOL_DOCUMENT_ROOT.
'/subtotals/class/commonsubtotal.class.php';
50 require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
64 public $element =
'order_supplier';
69 public $table_element =
'commande_fournisseur';
74 public $table_element_line =
'commande_fournisseurdet';
79 public $class_element_line =
'CommandeFournisseurLigne';
84 public $fk_element =
'fk_commande';
89 public $picto =
'supplier_order';
95 public $restrictiononfksoc = 1;
115 public $ref_supplier;
163 public $date_approve;
169 public $date_approve2;
174 public $date_commande;
180 public $remise_percent;
184 public $methode_commande_id;
188 public $methode_commande;
193 public $delivery_date;
198 public $fk_warehouse;
213 public $total_localtax1;
218 public $total_localtax2;
233 public $cond_reglement_id;
238 public $cond_reglement_code;
243 public $cond_reglement_label;
248 public $cond_reglement_doc;
254 public $deposit_percent;
264 public $mode_reglement_id;
269 public $mode_reglement_code;
274 public $mode_reglement;
279 public $user_author_id;
284 public $user_approve_id;
290 public $user_approve_id2;
305 public $extraparams = array();
310 public $lines = array();
330 public $date_lim_reglement;
335 public $receptions = array();
341 public $fk_multicurrency;
346 public $multicurrency_code;
351 public $multicurrency_tx;
356 public $multicurrency_total_ht;
361 public $multicurrency_total_tva;
366 public $multicurrency_total_ttc;
396 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => 0,
'notnull' => 1,
'position' => 10),
397 'ref' => array(
'type' =>
'varchar(255)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => 1,
'showoncombobox' => 1,
'position' => 25,
'searchall' => 1),
398 'ref_ext' => array(
'type' =>
'varchar(255)',
'label' =>
'RefExt',
'enabled' => 1,
'visible' => 0,
'position' => 35),
399 'ref_supplier' => array(
'type' =>
'varchar(255)',
'label' =>
'RefOrderSupplierShort',
'enabled' => 1,
'visible' => 1,
'position' => 40,
'searchall' => 1),
400 'fk_projet' => array(
'type' =>
'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)',
'label' =>
'Project',
'enabled' =>
"isModEnabled('project')",
'visible' => -1,
'position' => 45),
401 'date_valid' => array(
'type' =>
'datetime',
'label' =>
'DateValidation',
'enabled' => 1,
'visible' => -1,
'position' => 710),
402 'date_approve' => array(
'type' =>
'datetime',
'label' =>
'DateApprove',
'enabled' => 1,
'visible' => -1,
'position' => 720),
403 'date_approve2' => array(
'type' =>
'datetime',
'label' =>
'DateApprove2',
'enabled' => 1,
'visible' => 3,
'position' => 725),
404 'date_commande' => array(
'type' =>
'date',
'label' =>
'OrderDateShort',
'enabled' => 1,
'visible' => 1,
'position' => 70),
405 'date_livraison' => array(
'type' =>
'datetime',
'label' =>
'DeliveryDate',
'enabled' =>
'getDolGlobalInt("ORDER_DISABLE_DELIVERY_DATE") ? 0 : 1',
'visible' => 1,
'position' => 74),
406 'fk_warehouse' => array(
'type' =>
'integer:Entrepot:product/stock/class/entrepot.class.php',
'label' =>
'DefaultWarehouse',
'enabled' =>
'isModEnabled("stock")',
'visible' => -1,
'position' => 75,
'nodepth' => 1),
407 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'visible' => 3,
'position' => 41),
408 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => 3,
'notnull' => -1,
'position' => 80),
409 'fk_user_valid' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserValidation',
'enabled' => 1,
'visible' => 3,
'position' => 711),
410 'fk_user_approve' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserApproval',
'enabled' => 1,
'visible' => 3,
'position' => 721),
411 'fk_user_approve2' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserApproval2',
'enabled' => 1,
'visible' => 3,
'position' => 726),
412 'source' => array(
'type' =>
'smallint(6)',
'label' =>
'Source',
'enabled' => 1,
'visible' => 3,
'notnull' => 1,
'position' => 100),
413 'billed' => array(
'type' =>
'smallint(6)',
'label' =>
'Billed',
'enabled' => 1,
'visible' => 1,
'position' => 710),
414 'total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'AmountHT',
'enabled' => 1,
'visible' => 1,
'position' => 130,
'isameasure' => 1),
415 'total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'AmountVAT',
'enabled' => 1,
'visible' => 1,
'position' => 135,
'isameasure' => 1),
416 'localtax1' => array(
'type' =>
'double(24,8)',
'label' =>
'LT1',
'enabled' => 1,
'visible' => 3,
'position' => 140,
'isameasure' => 1),
417 'localtax2' => array(
'type' =>
'double(24,8)',
'label' =>
'LT2',
'enabled' => 1,
'visible' => 3,
'position' => 145,
'isameasure' => 1),
418 'total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'AmountTTC',
'enabled' => 1,
'visible' => -1,
'position' => 150,
'isameasure' => 1),
419 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 750,
'searchall' => 1),
420 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 760,
'searchall' => 1),
421 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'ModelPDF',
'enabled' => 1,
'visible' => 0,
'position' => 165),
422 'fk_input_method' => array(
'type' =>
'integer',
'label' =>
'OrderMode',
'enabled' => 1,
'visible' => 3,
'position' => 170),
423 'fk_cond_reglement' => array(
'type' =>
'integer',
'label' =>
'PaymentTerm',
'enabled' => 1,
'visible' => 3,
'position' => 175),
424 'deposit_percent' => array(
'type' =>
'varchar(63)',
'label' =>
'DepositPercent',
'enabled' => 1,
'visible' => -1,
'position' => 176),
425 'fk_mode_reglement' => array(
'type' =>
'integer',
'label' =>
'PaymentMode',
'enabled' => 1,
'visible' => 3,
'position' => 180),
426 'extraparams' => array(
'type' =>
'varchar(255)',
'label' =>
'Extraparams',
'enabled' => 1,
'visible' => 0,
'position' => 190),
427 'fk_account' => array(
'type' =>
'integer',
'label' =>
'BankAccount',
'enabled' =>
'isModEnabled("bank")',
'visible' => 3,
'position' => 200),
428 'fk_incoterms' => array(
'type' =>
'integer',
'label' =>
'IncotermCode',
'enabled' => 1,
'visible' => 3,
'position' => 205),
429 'location_incoterms' => array(
'type' =>
'varchar(255)',
'label' =>
'IncotermLocation',
'enabled' => 1,
'visible' => 3,
'position' => 210),
430 'fk_multicurrency' => array(
'type' =>
'integer',
'label' =>
'Currency',
'enabled' => 1,
'visible' => 0,
'position' => 215),
431 'multicurrency_code' => array(
'type' =>
'varchar(255)',
'label' =>
'Currency',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 220),
432 'multicurrency_tx' => array(
'type' =>
'double(24,8)',
'label' =>
'CurrencyRate',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 225),
433 'multicurrency_total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountHT',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 230),
434 'multicurrency_total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountVAT',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 235),
435 'multicurrency_total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountTTC',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 240),
436 'date_creation' => array(
'type' =>
'datetime',
'label' =>
'Date creation',
'enabled' => 1,
'visible' => -1,
'position' => 500),
437 'fk_soc' => array(
'type' =>
'integer:Societe:societe/class/societe.class.php',
'label' =>
'ThirdParty',
'enabled' =>
'isModEnabled("societe")',
'visible' => 1,
'notnull' => 1,
'position' => 50),
438 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => 0,
'notnull' => 1,
'position' => 1000,
'index' => 1),
439 'tms' => array(
'type' =>
'datetime',
'label' =>
"DateModificationShort",
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 501),
440 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'LastMainDoc',
'enabled' => 1,
'visible' => 0,
'position' => 700),
441 'fk_statut' => array(
'type' =>
'smallint(6)',
'label' =>
'Status',
'enabled' => 1,
'visible' => 1,
'position' => 701),
442 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => 0,
'position' => 900),
506 $this->ismultientitymanaged = 1;
517 public function fetch($id, $ref =
'')
520 if (empty($id) && empty($ref)) {
524 $sql =
"SELECT c.rowid, c.entity, c.ref, ref_supplier, c.fk_soc, c.fk_statut as status, c.amount_ht, c.total_ht, c.total_ttc, c.total_tva,";
525 $sql .=
" c.localtax1, c.localtax2, ";
526 $sql .=
" c.date_creation, c.date_valid, c.date_approve, c.date_approve2,";
527 $sql .=
" c.fk_user_author as user_author_id, c.fk_user_valid as user_validation_id, c.fk_user_approve as user_approve_id, c.fk_user_approve2 as user_approve_id2,";
528 $sql .=
" c.date_commande as date_commande, c.date_livraison as delivery_date, c.fk_warehouse, c.fk_cond_reglement, c.fk_mode_reglement, c.fk_projet as fk_project, c.remise_percent, c.source, c.fk_input_method,";
529 $sql .=
" c.fk_account,";
530 $sql .=
" c.note_private, c.note_public, c.model_pdf, c.last_main_doc, c.extraparams, c.billed,";
531 $sql .=
" c.fk_multicurrency, c.multicurrency_code, c.multicurrency_tx, c.multicurrency_total_ht, c.multicurrency_total_tva, c.multicurrency_total_ttc,";
532 $sql .=
" cm.libelle as methode_commande,";
533 $sql .=
" cr.code as cond_reglement_code, cr.libelle as cond_reglement_label, cr.libelle_facture as cond_reglement_doc, c.deposit_percent,";
534 $sql .=
" p.code as mode_reglement_code, p.libelle as mode_reglement_libelle";
535 $sql .=
', c.fk_incoterms, c.location_incoterms';
536 $sql .=
', c.last_main_doc';
537 $sql .=
', i.libelle as label_incoterms';
538 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as c";
539 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_payment_term as cr ON c.fk_cond_reglement = cr.rowid";
540 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_paiement as p ON c.fk_mode_reglement = p.id";
541 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_input_method as cm ON cm.rowid = c.fk_input_method";
542 $sql .=
' LEFT JOIN '.$this->db->prefix().
'c_incoterms as i ON c.fk_incoterms = i.rowid';
545 $sql .=
" WHERE c.entity IN (".getEntity(
'supplier_order').
")";
547 $sql .=
" WHERE c.rowid=".((int) $id);
551 $sql .=
" AND c.ref='".$this->db->escape($ref).
"'";
554 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
555 $resql = $this->db->query($sql);
557 $obj = $this->db->fetch_object($resql);
559 $this->error =
'Bill with id '.$id.
' not found';
560 dol_syslog(get_class($this).
'::fetch '.$this->error);
564 $this->
id = $obj->rowid;
565 $this->entity = $obj->entity;
567 $this->
ref = $obj->ref;
568 $this->ref_supplier = $obj->ref_supplier;
570 $this->socid = $obj->fk_soc;
571 $this->thirdparty =
null;
573 $this->fourn_id = $obj->fk_soc;
574 $this->statut = $obj->status;
575 $this->
status = $obj->status;
576 $this->billed = $obj->billed;
577 $this->last_main_doc = $obj->last_main_doc;
578 $this->user_author_id = $obj->user_author_id;
579 $this->user_validation_id = $obj->user_validation_id;
580 $this->user_approve_id = $obj->user_approve_id;
581 $this->user_approve_id2 = $obj->user_approve_id2;
582 $this->total_ht = $obj->total_ht;
583 $this->total_tva = $obj->total_tva;
584 $this->total_localtax1 = $obj->localtax1;
585 $this->total_localtax2 = $obj->localtax2;
586 $this->total_ttc = $obj->total_ttc;
587 $this->date_creation = $this->db->jdate($obj->date_creation);
588 $this->date_valid = $this->db->jdate($obj->date_valid);
589 $this->date_approve = $this->db->jdate($obj->date_approve);
590 $this->date_approve2 = $this->db->jdate($obj->date_approve2);
591 $this->date_commande = $this->db->jdate($obj->date_commande);
592 if (isset($obj->date_commande)) {
593 $this->
date = $this->date_commande;
595 $this->
date = $this->date_creation;
597 $this->delivery_date = $this->db->jdate($obj->delivery_date);
598 $this->fk_warehouse = $obj->fk_warehouse;
599 $this->remise_percent = $obj->remise_percent;
600 $this->methode_commande_id = $obj->fk_input_method;
601 $this->methode_commande = $obj->methode_commande;
603 $this->source = $obj->source;
604 $this->fk_project = $obj->fk_project;
605 $this->cond_reglement_id = $obj->fk_cond_reglement;
606 $this->cond_reglement_code = $obj->cond_reglement_code;
607 $this->cond_reglement_label = $obj->cond_reglement_label;
608 $this->cond_reglement_doc = $obj->cond_reglement_doc;
609 $this->deposit_percent = $obj->deposit_percent;
610 $this->fk_account = $obj->fk_account;
611 $this->mode_reglement_id = $obj->fk_mode_reglement;
612 $this->mode_reglement_code = $obj->mode_reglement_code;
613 $this->mode_reglement = $obj->mode_reglement_libelle;
614 $this->note = $obj->note_private;
615 $this->note_private = $obj->note_private;
616 $this->note_public = $obj->note_public;
617 $this->model_pdf = $obj->model_pdf;
618 $this->last_main_doc = $obj->last_main_doc;
621 $this->fk_incoterms = $obj->fk_incoterms;
622 $this->location_incoterms = $obj->location_incoterms;
623 $this->label_incoterms = $obj->label_incoterms;
626 $this->fk_multicurrency = $obj->fk_multicurrency;
627 $this->multicurrency_code = $obj->multicurrency_code;
628 $this->multicurrency_tx = $obj->multicurrency_tx;
629 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
630 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
631 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
633 $this->extraparams = isset($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
635 $this->db->free($resql);
650 $this->error = $this->db->error().
" sql=".$sql;
666 $this->lines = array();
668 $sql =
"SELECT l.rowid, l.fk_commande, l.ref as ref_supplier, l.fk_product, l.product_type, l.label, l.description, l.qty,";
669 $sql .=
" l.vat_src_code, l.tva_tx, l.remise_percent, l.subprice, l.subprice_ttc,";
670 $sql .=
" l.localtax1_tx, l. localtax2_tx, l.localtax1_type, l. localtax2_type, l.total_localtax1, l.total_localtax2,";
671 $sql .=
" l.total_ht, l.total_tva, l.total_ttc, l.info_bits, l.special_code, l.fk_parent_line, l.rang,";
672 $sql .=
" p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.description as product_desc, p.tobatch as product_tobatch, p.barcode as product_barcode, p.stockable_product,";
673 $sql .=
" l.fk_unit, l.extraparams,";
674 $sql .=
" l.date_start, l.date_end,";
675 $sql .=
' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_subprice_ttc, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc';
676 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseurdet as l";
677 $sql .=
' LEFT JOIN '.$this->db->prefix().
'product as p ON l.fk_product = p.rowid';
678 $sql .=
" WHERE l.fk_commande = ".((int) $this->
id);
680 $sql .=
' AND p.fk_product_type = 0';
682 $sql .=
" ORDER BY l.rang, l.rowid";
685 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
687 $result = $this->db->query($sql);
689 $num = $this->db->num_rows($result);
693 $objp = $this->db->fetch_object($result);
697 $line->id = $objp->rowid;
698 $line->fk_commande = $objp->fk_commande;
699 $line->desc = $objp->description;
700 $line->description = $objp->description;
701 $line->qty = $objp->qty;
702 $line->tva_tx = $objp->tva_tx;
703 $line->localtax1_tx = $objp->localtax1_tx;
704 $line->localtax2_tx = $objp->localtax2_tx;
705 $line->localtax1_type = $objp->localtax1_type;
706 $line->localtax2_type = $objp->localtax2_type;
707 $line->subprice = $objp->subprice;
708 $line->pu_ht = $objp->subprice;
709 $line->subprice_ttc = $objp->subprice_ttc;
710 $line->pu_ttc = $objp->subprice_ttc;
711 $line->remise_percent = $objp->remise_percent;
713 $line->vat_src_code = $objp->vat_src_code;
714 $line->total_ht = $objp->total_ht;
715 $line->total_tva = $objp->total_tva;
716 $line->total_localtax1 = $objp->total_localtax1;
717 $line->total_localtax2 = $objp->total_localtax2;
718 $line->total_ttc = $objp->total_ttc;
719 $line->product_type = $objp->product_type;
721 $line->fk_product = $objp->fk_product;
723 $line->libelle = $objp->product_label;
724 $line->product_label = $objp->product_label;
725 $line->product_desc = $objp->product_desc;
726 $line->product_tobatch = $objp->product_tobatch;
727 $line->product_barcode = $objp->product_barcode;
728 $line->stockable_product = $objp->stockable_product;
730 $line->ref = $objp->product_ref;
731 $line->product_ref = $objp->product_ref;
732 $line->ref_fourn = $objp->ref_supplier;
733 $line->ref_supplier = $objp->ref_supplier;
740 $sqlsearchpackage =
'SELECT rowid, packaging FROM '.$this->db->prefix().
"product_fournisseur_price";
741 $sqlsearchpackage .=
' WHERE entity IN ('.getEntity(
'productsupplierprice').
")";
742 $sqlsearchpackage .=
" AND fk_product = ".((int) $objp->fk_product);
743 $sqlsearchpackage .=
" AND ref_fourn = '".$this->db->escape($objp->ref_supplier).
"'";
744 $sqlsearchpackage .=
" AND quantity <= ".abs((
float) $objp->qty);
745 $sqlsearchpackage .=
" AND (packaging IS NULL OR packaging = 0 OR packaging <= ".abs((
float) $objp->qty).
")";
746 $sqlsearchpackage .=
" AND fk_soc = ".((int) $this->socid);
747 $sqlsearchpackage .=
" ORDER BY packaging ASC";
748 $sqlsearchpackage .=
" LIMIT 1";
750 $resqlsearchpackage = $this->db->query($sqlsearchpackage);
751 if ($resqlsearchpackage) {
752 $objsearchpackage = $this->db->fetch_object($resqlsearchpackage);
753 if ($objsearchpackage) {
754 $line->fk_fournprice = $objsearchpackage->rowid;
755 $line->packaging = (float) $objsearchpackage->packaging;
758 $this->error = $this->db->lasterror();
763 $line->date_start = $this->db->jdate($objp->date_start);
764 $line->date_end = $this->db->jdate($objp->date_end);
765 $line->fk_unit = $objp->fk_unit;
767 $line->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams,
true) : array();
770 $line->fk_multicurrency = $objp->fk_multicurrency;
771 $line->multicurrency_code = $objp->multicurrency_code;
772 $line->multicurrency_subprice = $objp->multicurrency_subprice;
773 $line->multicurrency_subprice_ttc = $objp->multicurrency_subprice_ttc;
774 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
775 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
776 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
778 $line->info_bits = $objp->info_bits;
779 $line->special_code = $objp->special_code;
780 $line->fk_parent_line = $objp->fk_parent_line;
782 $line->rang = $objp->rang;
786 $line->fetch_optionals();
788 $this->lines[$i] = $line;
792 $this->db->free($result);
796 $this->error = $this->db->error().
" sql=".$sql;
809 public function valid($user, $idwarehouse = 0, $notrigger = 0)
812 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
818 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")))
819 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"fournisseur",
"supplier_order_advance",
"validate"))) {
823 dol_syslog(get_class($this).
"::valid checkActiveProductInLines ".$this->error, LOG_INFO);
828 $soc->fetch((
int) $this->fourn_id);
831 if (preg_match(
'/^[\(]?PROV/i', (
string) $this->
ref) || empty($this->ref)) {
832 $num = $this->getNextNumRef($soc);
834 $num = (string) $this->ref;
838 $sql =
'UPDATE '.$this->db->prefix().
"commande_fournisseur";
839 $sql .=
" SET ref='".$this->db->escape($num).
"',";
840 $sql .=
" fk_statut = ".((int) self::STATUS_VALIDATED).
",";
841 $sql .=
" date_valid='".$this->db->idate(
dol_now()).
"',";
842 $sql .=
" fk_user_valid = ".((int) $user->id);
843 $sql .=
" WHERE rowid = ".((int) $this->
id);
844 $sql .=
" AND fk_statut = ".((int) self::STATUS_DRAFT);
846 $resql = $this->db->query($sql);
848 dol_print_error($this->db);
852 if (!$error && !$notrigger) {
854 $result = $this->call_trigger(
'ORDER_SUPPLIER_VALIDATE', $user);
862 $this->oldref = $this->ref;
865 if (preg_match(
'/^[\(]?PROV/i', $this->ref)) {
867 $sql =
'UPDATE '.$this->db->prefix().
"ecm_files set filename = CONCAT('".$this->db->escape($this->newref).
"', SUBSTR(filename, ".(strlen($this->ref) + 1).
")), filepath = 'fournisseur/commande/".$this->db->escape($this->newref).
"'";
868 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->ref).
"%' AND filepath = 'fournisseur/commande/".$this->db->escape($this->ref).
"' and entity = ".((int)
$conf->entity);
869 $resql = $this->db->query($sql);
872 $this->error = $this->db->lasterror();
874 $sql =
'UPDATE '.$this->db->prefix().
"ecm_files set filepath = 'fournisseur/commande/".$this->db->escape($this->newref).
"'";
875 $sql .=
" WHERE filepath = 'fournisseur/commande/".$this->db->escape($this->ref).
"' and entity = ".((int)
$conf->entity);
876 $resql = $this->db->query($sql);
879 $this->error = $this->db->lasterror();
885 $dirsource =
$conf->fournisseur->commande->dir_output.
'/'.$oldref;
886 $dirdest =
$conf->fournisseur->commande->dir_output.
'/'.$newref;
887 if (!$error && file_exists($dirsource)) {
888 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
890 if (@rename($dirsource, $dirdest)) {
893 $listoffiles =
dol_dir_list(
$conf->fournisseur->commande->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
894 foreach ($listoffiles as $fileentry) {
895 $dirsource = $fileentry[
'name'];
896 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
897 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
898 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
899 @rename($dirsource, $dirdest);
917 $this->db->rollback();
921 $this->error =
'NotAuthorized';
922 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
947 public function LibStatut($status, $mode = 0, $billed = 0)
950 global $langs, $hookmanager;
952 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
953 $langs->load(
'orders');
955 $this->labelStatus[0] =
'StatusSupplierOrderDraft';
956 $this->labelStatus[1] =
'StatusSupplierOrderValidated';
957 $this->labelStatus[2] =
'StatusSupplierOrderApproved';
959 $this->labelStatus[3] =
'StatusSupplierOrderOnProcess';
961 $this->labelStatus[3] =
'StatusSupplierOrderOnProcessWithValidation';
963 $this->labelStatus[4] =
'StatusSupplierOrderReceivedPartially';
964 $this->labelStatus[5] =
'StatusSupplierOrderReceivedAll';
965 $this->labelStatus[6] =
'StatusSupplierOrderCanceled';
966 $this->labelStatus[7] =
'StatusSupplierOrderCanceled';
967 $this->labelStatus[9] =
'StatusSupplierOrderRefused';
970 $this->labelStatusShort[0] =
'StatusSupplierOrderDraftShort';
971 $this->labelStatusShort[1] =
'StatusSupplierOrderValidatedShort';
972 $this->labelStatusShort[2] =
'StatusSupplierOrderApprovedShort';
973 $this->labelStatusShort[3] =
'StatusSupplierOrderOnProcessShort';
974 $this->labelStatusShort[4] =
'StatusSupplierOrderReceivedPartiallyShort';
975 $this->labelStatusShort[5] =
'StatusSupplierOrderReceivedAllShort';
976 $this->labelStatusShort[6] =
'StatusSupplierOrderCanceledShort';
977 $this->labelStatusShort[7] =
'StatusSupplierOrderCanceledShort';
978 $this->labelStatusShort[9] =
'StatusSupplierOrderRefusedShort';
981 $statustrans = array(
993 $statusClass =
'status0';
994 if (!empty($statustrans[$status])) {
995 $statusClass = $statustrans[$status];
1000 $billedtext =
' - '.$langs->trans(
"Billed");
1002 if ($status == 5 && $billed) {
1003 $statusClass =
'status6';
1006 $statusLong = $langs->transnoentitiesnoconv($this->labelStatus[$status]).$billedtext;
1007 $statusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
1009 $parameters = array(
'status' => $status,
'mode' => $mode,
'billed' => $billed);
1010 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
1012 return $hookmanager->resPrint;
1015 return dolGetStatus($statusLong, $statusShort,
'', $statusClass, $mode);
1026 global
$conf, $langs, $user;
1028 $langs->loadLangs([
'bills',
'orders']);
1031 $nofetch = !empty($params[
'nofetch']);
1033 if ($user->hasRight(
"fournisseur",
"commande",
"read")) {
1034 $datas[
'picto'] =
'<u class="paddingrightonly">'.$langs->trans(
"SupplierOrder").
'</u>';
1036 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
1038 if (!empty($this->
ref)) {
1039 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1041 if (!empty($this->ref_supplier)) {
1042 $datas[
'refsupplier'] =
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.$this->ref_supplier;
1045 $langs->load(
'companies');
1046 if (empty($this->thirdparty)) {
1049 $datas[
'supplier'] =
'<br><b>'.$langs->trans(
'Supplier').
':</b> '.$this->thirdparty->getNomUrl(1,
'', 0, 1);
1051 if (!empty($this->total_ht)) {
1052 $datas[
'totalht'] =
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1,
$conf->currency);
1054 if (!empty($this->total_tva)) {
1055 $datas[
'totaltva'] =
'<br><b>'.$langs->trans(
'VAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1,
$conf->currency);
1057 if (!empty($this->total_ttc)) {
1058 $datas[
'totalttc'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency);
1060 if (!empty($this->
date)) {
1061 $datas[
'date'] =
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->
date,
'day');
1063 if (!empty($this->delivery_date)) {
1064 $langs->load(
"sendings");
1065 $datas[
'deliverydate'] =
'<br><b>'.$langs->trans(
'DeliveryDate').
':</b> '.
dol_print_date($this->delivery_date,
'dayhour');
1081 $context = parent::getObjectLinesDisplayContext();
1083 require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
1084 $context[
'seller'] = (is_object($this->thirdparty) ? $this->thirdparty :
new Societe($this->db));
1085 $context[
'buyer'] =
$mysoc;
1086 $context[
'forceall'] = 1;
1087 $context[
'inputalsopricewithtax'] = 1;
1089 $context[
'senderissupplier'] = (
getDolGlobalInt(
'SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY') ?
getDolGlobalInt(
'SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY') : 2);
1104 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = 0)
1106 global $langs, $user, $hookmanager;
1111 'objecttype' => $this->element,
1112 'option' => $option,
1115 $classfortooltip =
'classfortooltip';
1118 $classfortooltip =
'classforajaxtooltip';
1119 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1125 $url = DOL_URL_ROOT.
'/fourn/commande/card.php?id='.$this->id;
1127 if ($option !==
'nolink') {
1129 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1130 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1131 $add_save_lastsearch_values = 1;
1133 if ($add_save_lastsearch_values) {
1134 $url .=
'&save_lastsearch_values=1';
1139 if (empty($notooltip)) {
1141 $label = $langs->trans(
"ShowOrder");
1142 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1144 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1145 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
1148 $linkstart =
'<a href="'.$url.
'"';
1149 $linkstart .= $linkclose.
'>';
1152 $result .= $linkstart;
1154 $result .= img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
1156 if ($withpicto != 2) {
1157 $result .= $this->ref;
1159 $result .= $linkend;
1161 if ($addlinktonotes) {
1162 $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
1165 $result .=
' <span class="note inline-block">';
1166 $result .=
'<a href="'.DOL_URL_ROOT.
'/fourn/commande/note.php?id='.$this->
id.
'" class="classfortooltip" title="'.
dol_escape_htmltag($notetoshow).
'">';
1167 $result .= img_picto(
'',
'note');
1171 $result .=
'</span>';
1176 $hookmanager->initHooks(array($this->element .
'dao'));
1177 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1178 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1180 $result = $hookmanager->resPrint;
1182 $result .= $hookmanager->resPrint;
1195 public function getNextNumRef($soc)
1197 global $langs,
$conf;
1198 $langs->load(
"orders");
1207 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
1209 foreach ($dirmodels as $reldir) {
1210 $dir =
dol_buildpath($reldir.
"core/modules/supplier_order/");
1213 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1217 dol_print_error(
null,
"Failed to include file ".$file);
1221 $obj =
new $classname();
1222 '@phan-var-force ModeleNumRefSuppliersOrders $obj';
1224 $numref = $obj->getNextValue($soc, $this);
1226 if ($numref !=
"") {
1229 $this->error = $obj->error;
1233 $this->error =
"Error_COMMANDE_SUPPLIER_ADDON_NotDefined";
1248 if ($this->billed) {
1254 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur SET billed = 1';
1257 if ($this->db->query($sql)) {
1259 $result = $this->call_trigger(
'ORDER_SUPPLIER_CLASSIFY_BILLED', $user);
1268 $this->db->commit();
1271 $this->db->rollback();
1275 dol_print_error($this->db);
1277 $this->db->rollback();
1291 if (empty($this->billed)) {
1297 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur SET billed = 0';
1301 if (!$this->db->query($sql)) {
1302 dol_print_error($this->db);
1303 $this->db->rollback();
1308 $result = $this->call_trigger(
'ORDER_SUPPLIER_CLASSIFY_UNBILLED', $user);
1310 $this->db->rollback();
1316 $this->db->commit();
1329 public function approve($user, $idwarehouse = 0, $secondlevel = 0)
1333 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1339 if ($user->hasRight(
"fournisseur",
"commande",
"approuver")) {
1345 $soc =
new Societe($this->db);
1346 $soc->fetch((
int) $this->fourn_id);
1349 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
1350 $num = $this->getNextNumRef($soc);
1352 $num = (string) $this->
ref;
1357 $movetoapprovestatus =
true;
1360 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1361 $sql .=
" SET ref='".$this->db->escape($num).
"',";
1362 if (empty($secondlevel)) {
1363 $sql .=
" date_approve='".$this->db->idate($now).
"',";
1364 $sql .=
" fk_user_approve = ".((int) $user->id);
1366 if (empty($this->user_approve_id2)) {
1367 $movetoapprovestatus =
false;
1368 $comment =
' (first level)';
1372 $sql .=
" date_approve2='".$this->db->idate($now).
"',";
1373 $sql .=
" fk_user_approve2 = ".((int) $user->id);
1374 if (empty($this->user_approve_id)) {
1375 $movetoapprovestatus =
false;
1377 $comment =
' (second level)';
1380 if ($movetoapprovestatus) {
1381 $sql .=
", fk_statut = ".self::STATUS_ACCEPTED;
1383 $sql .=
", fk_statut = ".self::STATUS_VALIDATED;
1385 $sql .=
" WHERE rowid = ".((int) $this->
id);
1386 $sql .=
" AND fk_statut = ".self::STATUS_VALIDATED;
1388 if ($this->db->query($sql)) {
1390 $result = $this->
add_contact($user->id,
'SALESREPFOLL',
'internal', 1);
1391 if ($result < 0 && $result != -2) {
1398 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1399 $langs->load(
"agenda");
1401 $cpt = count($this->lines);
1402 for ($i = 0; $i < $cpt; $i++) {
1404 if ($this->lines[$i]->fk_product > 0) {
1405 $this->line = $this->lines[$i];
1407 $mouvP->origin = &$this;
1408 $mouvP->setOrigin($this->element, $this->
id);
1410 $up_ht_disc = $this->lines[$i]->subprice;
1411 if (!empty($this->lines[$i]->remise_percent) && !
getDolGlobalString(
'STOCK_EXCLUDE_DISCOUNT_FOR_PMP')) {
1412 $up_ht_disc =
price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100,
'MU');
1414 $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->transnoentitiesnoconv(
"OrderApprovedInDolibarr", $this->ref));
1425 $result = $this->call_trigger(
'ORDER_SUPPLIER_APPROVE', $user);
1433 $this->
ref = $this->newref;
1435 if ($movetoapprovestatus) {
1442 if (empty($secondlevel)) {
1443 $this->date_approve = $now;
1444 $this->user_approve_id = $user->id;
1446 $this->date_approve2 = $now;
1447 $this->user_approve_id2 = $user->id;
1450 $this->db->commit();
1453 $this->db->rollback();
1457 $this->db->rollback();
1458 $this->error = $this->db->lasterror();
1462 dol_syslog(get_class($this).
"::approve Not Authorized", LOG_ERR);
1479 if ($user->hasRight(
"fournisseur",
"commande",
"approuver")) {
1482 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur SET fk_statut = ".
self::STATUS_REFUSED;
1483 $sql .=
" WHERE rowid = ".((int) $this->
id);
1485 if ($this->db->query($sql)) {
1490 $result = $this->call_trigger(
'ORDER_SUPPLIER_REFUSE', $user);
1493 $this->db->rollback();
1495 $this->db->commit();
1500 $this->db->rollback();
1501 $this->error = $this->db->lasterror();
1502 dol_syslog(get_class($this).
"::refuse Error -1");
1506 dol_syslog(get_class($this).
"::refuse Not Authorized");
1520 public function cancel($user, $idwarehouse = -1)
1527 if ($user->hasRight(
"fournisseur",
"commande",
"commander")) {
1532 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur SET fk_statut = ".((int) $statut);
1533 $sql .=
" WHERE rowid = ".((int) $this->
id);
1534 dol_syslog(get_class($this).
"::cancel", LOG_DEBUG);
1535 if ($this->db->query($sql)) {
1539 $result = $this->call_trigger(
'ORDER_SUPPLIER_CANCEL', $user);
1546 $this->db->commit();
1549 $this->db->rollback();
1553 $this->db->rollback();
1554 $this->error = $this->db->lasterror();
1555 dol_syslog(get_class($this).
"::cancel ".$this->error);
1559 dol_syslog(get_class($this).
"::cancel Not Authorized");
1573 public function commande($user, $date, $methode, $comment =
'')
1578 if ($user->hasRight(
"fournisseur",
"commande",
"commander")) {
1581 $newnoteprivate = $this->note_private;
1583 $newnoteprivate =
dol_concatdesc($newnoteprivate, $langs->trans(
"Comment").
': '.$comment);
1586 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1587 $sql .=
" SET fk_statut=".self::STATUS_ORDERSENT.
", fk_input_method=".((int) $methode).
", date_commande='".$this->db->idate($date).
"', ";
1588 $sql .=
" note_private='".$this->db->escape((
string) $newnoteprivate).
"'";
1589 $sql .=
" WHERE rowid=".((int) $this->
id);
1591 dol_syslog(get_class($this).
"::commande", LOG_DEBUG);
1592 if ($this->db->query($sql)) {
1595 $this->methode_commande_id = $methode;
1596 $this->date_commande = $date;
1597 $this->context[
'comments'] = $comment;
1600 $result = $this->call_trigger(
'ORDER_SUPPLIER_SUBMIT', $user);
1607 $this->error = $this->db->lasterror();
1608 $this->errors[] = $this->db->lasterror();
1612 $this->db->commit();
1614 $this->db->rollback();
1618 $this->error = $langs->trans(
'NotAuthorized');
1619 $this->errors[] = $langs->trans(
'NotAuthorized');
1620 dol_syslog(get_class($this).
"::commande User not Authorized", LOG_WARNING);
1623 return ($error ? -1 : 1);
1634 if (empty($this->thirdparty)) {
1640 $canproduct = $canservice = $user->hasRight(
'product',
'product_advance',
'write_supplier_prices');
1642 $canproduct = $user->hasRight(
'produit',
'creer');
1643 $canservice = $user->hasRight(
'service',
'creer');
1647 $withprice = array();
1648 $productids = array(0);
1649 foreach ($this->lines as $line) {
1650 $productids[] = (int) $line->fk_product;
1652 $sql =
"SELECT DISTINCT fk_product FROM ".$this->db->prefix().
"product_fournisseur_price";
1653 $sql .=
" WHERE fk_soc = ".((int) $this->socid).
" AND entity IN (".
getEntity(
'productsupplierprice').
") AND fk_product IN (".$this->db->sanitize(implode(
',', $productids)).
")";
1654 $resql = $this->db->query($sql);
1655 while ($resql && $obj = $this->db->fetch_object($resql)) {
1656 $withprice[(int) $obj->fk_product] = 1;
1660 foreach ($this->lines as $line) {
1661 if ($line->fk_product <= 0 || $line->qty <= 0 || $line->subprice <= 0 || ($line->product_type ==
Product::TYPE_SERVICE ? !$canservice : !$canproduct)) {
1667 if ($productsupplier->get_buyprice(0, $line->qty, $line->fk_product, $line->ref_supplier, (
int) $this->socid) > 0
1668 && $productsupplier->fetch_product_fournisseur_price($productsupplier->product_fourn_price_id) > 0
1669 && (
price2num($productsupplier->fourn_unitprice,
'MU') !=
price2num($line->subprice,
'MU') || (
float) $productsupplier->fourn_remise_percent != (
float) $line->remise_percent)) {
1670 $qty = $productsupplier->fourn_qty;
1671 $productsupplier->product_fourn_packaging = $productsupplier->packaging;
1672 $mcsubprice = (empty($line->multicurrency_subprice) ? $line->subprice : $line->multicurrency_subprice);
1673 $result = $productsupplier->update_buyprice($qty, $line->subprice * $qty, $user,
'HT', $this->thirdparty, $productsupplier->fk_availability, $productsupplier->ref_supplier, (
float) $productsupplier->fourn_tva_tx, (float) $productsupplier->fourn_charges, $line->remise_percent, $productsupplier->fourn_remise, $productsupplier->fourn_tva_npr, $productsupplier->delivery_time_days, $productsupplier->supplier_reputation, array(), $productsupplier->default_vat_code, $mcsubprice * $qty,
'HT', (float) $this->multicurrency_tx, $this->multicurrency_code, $productsupplier->desc_supplier, $productsupplier->supplier_barcode, (
int) $productsupplier->supplier_fk_barcode_type);
1684 if (empty($productsupplier->product_fourn_price_id) && empty($withprice[$line->fk_product]) && $newprice->fetch($line->fk_product) > 0) {
1685 $ref = ($line->ref_supplier ? (string) $line->ref_supplier : $newprice->ref);
1686 $result = $newprice->add_fournisseur($user, (
int) $this->socid, $ref, 1);
1688 $withprice[$line->fk_product] = 1;
1689 $result = $newprice->update_buyprice(1, (
float) $line->subprice, $user,
'HT', $this->thirdparty, 0, $ref, (float) $line->tva_tx, 0, $line->remise_percent, 0, 0, 0,
'', array(), (string) $line->vat_src_code, (
float) ($line->multicurrency_subprice ?: $line->subprice),
'HT', (
float) $this->multicurrency_tx, $this->multicurrency_code);
1692 if ($result < 0 && $result != -3) {
1699 $costprice =
price2num($line->subprice * (1 - $line->remise_percent / 100),
'MU');
1700 $product =
new Product($this->db);
1701 if ($product->fetch($line->fk_product) > 0 &&
price2num($product->cost_price,
'MU') != $costprice) {
1702 $result = $product->setValueFrom(
'cost_price', $costprice,
'',
null,
'text',
'', $user,
'PRODUCT_MODIFY');
1721 public function create($user, $notrigger = 0)
1731 $date = ($this->date_commande ? $this->date_commande : $this->date);
1735 $delivery_date = $this->delivery_date;
1738 if (empty($this->source)) {
1743 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
1748 if (empty($this->fk_multicurrency)) {
1749 $this->multicurrency_code =
$conf->currency;
1750 $this->fk_multicurrency = 0;
1751 $this->multicurrency_tx = 1;
1759 $sql =
"INSERT INTO ".$this->db->prefix().
"commande_fournisseur (";
1761 $sql .=
", ref_supplier";
1762 $sql .=
", note_private";
1763 $sql .=
", note_public";
1766 $sql .=
", fk_projet";
1767 $sql .=
", date_creation";
1768 $sql .=
", date_livraison";
1769 $sql .=
", fk_warehouse";
1770 $sql .=
", fk_user_author";
1771 $sql .=
", fk_statut";
1773 $sql .=
", model_pdf";
1774 $sql .=
", fk_mode_reglement";
1775 $sql .=
", deposit_percent";
1776 $sql .=
", fk_cond_reglement";
1777 $sql .=
", fk_account";
1778 $sql .=
", fk_incoterms, location_incoterms";
1779 $sql .=
", fk_multicurrency";
1780 $sql .=
", multicurrency_code";
1781 $sql .=
", multicurrency_tx";
1783 $sql .=
" VALUES (";
1785 $sql .=
", ".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"NULL");
1786 $sql .=
", '".$this->db->escape((
string) $this->note_private).
"'";
1787 $sql .=
", '".$this->db->escape((
string) $this->note_public).
"'";
1788 $sql .=
", ".((int) $this->entity);
1789 $sql .=
", ".((int) $this->socid);
1790 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
1791 $sql .=
", '".$this->db->idate($date).
"'";
1792 $sql .=
", ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
"null");
1793 $sql .=
", ".($this->fk_warehouse > 0 ? ((int) $this->fk_warehouse) :
"null");
1794 $sql .=
", ".((int) $user->id);
1795 $sql .=
", ".self::STATUS_DRAFT;
1796 $sql .=
", ".((int) $this->source);
1797 $sql .=
", '".$this->db->escape(
getDolGlobalString(
'COMMANDE_SUPPLIER_ADDON_PDF')).
"'";
1798 $sql .=
", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) :
'null');
1799 $sql .=
", ".(!empty($this->deposit_percent) ?
"'" . $this->db->escape($this->deposit_percent) .
"'" :
"null");
1800 $sql .=
", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) :
'null');
1801 $sql .=
", ".($this->fk_account > 0 ? ((int) $this->fk_account) :
'NULL');
1802 $sql .=
", ".(int) $this->fk_incoterms;
1803 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
1804 $sql .=
", ".(int) $this->fk_multicurrency;
1805 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1806 $sql .=
", ".(float) $this->multicurrency_tx;
1809 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1810 if ($this->db->query($sql)) {
1811 $this->
id = $this->db->last_insert_id($this->db->prefix().
"commande_fournisseur");
1814 $num = count($this->lines);
1817 for ($i = 0; $i < $num; $i++) {
1818 $line = $this->lines[$i];
1819 if (!is_object($line)) {
1823 foreach ($line as $key => $val) {
1824 $lineobj->$key = $val;
1827 $this->lines[$i] = $line;
1837 $line_price_base_type = $line->getPriceBaseType();
1838 $line_pu_devise = ($line_price_base_type ===
'TTC') ? 0 : (float) $line->multicurrency_subprice;
1840 (
string) $line->desc,
1841 (
float) $line->subprice,
1844 (
float) $line->localtax1_tx,
1845 (
float) $line->localtax2_tx,
1846 (
int) $line->fk_product,
1848 (
string) ($line->ref_supplier ? $line->ref_supplier : $line->ref_fourn),
1849 (
float) $line->remise_percent,
1850 $line_price_base_type,
1851 (float) $line->subprice_ttc,
1852 (
int) $line->product_type,
1853 (int) $line->info_bits,
1855 $line->date_start ??
null,
1856 $line->date_end ??
null,
1857 $line->array_options,
1858 $line->fk_unit ??
null,
1860 (
string) $line->origin,
1861 (int) $line->origin_id,
1862 (
int) ($line->rang > 0 ? $line->rang : -1),
1863 (
int) $line->special_code,
1864 isset($line->product_label) ? $line->product_label :
''
1867 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
1868 $this->db->rollback();
1873 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1874 $sql .=
" SET ref='(PROV".((int) $this->
id).
")'";
1875 $sql .=
" WHERE rowid=".((int) $this->
id);
1877 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1878 if ($this->db->query($sql)) {
1881 $this->
ref =
"(PROV".$this->id.
")";
1883 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
1884 $this->linked_objects = $this->linkedObjectsIds;
1888 if (!empty($this->linked_objects) && is_array($this->linked_objects)) {
1889 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
1890 if (is_array($tmp_origin_id)) {
1891 foreach ($tmp_origin_id as $origin_id) {
1894 dol_print_error($this->db);
1899 $origin_id = $tmp_origin_id;
1902 dol_print_error($this->db);
1917 if (!$error && !$notrigger) {
1919 $result = $this->call_trigger(
'ORDER_SUPPLIER_CREATE', $user);
1921 $this->db->rollback();
1928 $this->db->commit();
1931 $this->error = $this->db->lasterror();
1932 $this->db->rollback();
1937 $this->error =
'Failed to get ID of inserted line';
1942 $this->error = $this->db->lasterror();
1943 $this->db->rollback();
1961 if (isset($this->
ref)) {
1962 $this->
ref = trim($this->
ref);
1964 if (isset($this->ref_supplier)) {
1965 $this->ref_supplier = trim($this->ref_supplier);
1967 if (isset($this->note_private)) {
1968 $this->note_private = trim($this->note_private);
1970 if (isset($this->note_public)) {
1971 $this->note_public = trim($this->note_public);
1973 if (isset($this->model_pdf)) {
1974 $this->model_pdf = trim($this->model_pdf);
1976 if (isset($this->import_key)) {
1977 $this->import_key = trim($this->import_key);
1981 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
1983 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1984 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
1985 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1986 $sql .=
" fk_soc=".(isset($this->socid) ? ((int) $this->socid) :
"null").
",";
1987 $sql .=
" date_commande=".(strval($this->date_commande) !=
'' ?
"'".$this->db->idate($this->date_commande).
"'" :
'null').
",";
1988 $sql .=
" date_valid=".(strval($this->date_validation) !=
'' ?
"'".$this->db->idate($this->date_validation).
"'" :
'null').
",";
1989 $sql .=
" fk_warehouse=".($this->fk_warehouse > 0 ? ((int) $this->fk_warehouse) :
"null").
",";
1990 $sql .=
" total_tva=".(isset($this->total_tva) ? ((float) $this->total_tva) :
"null").
",";
1991 $sql .=
" localtax1=".(isset($this->total_localtax1) ? ((float) $this->total_localtax1) :
"null").
",";
1992 $sql .=
" localtax2=".(isset($this->total_localtax2) ? ((float) $this->total_localtax2) :
"null").
",";
1993 $sql .=
" total_ht=".(isset($this->total_ht) ? ((float) $this->total_ht) :
"null").
",";
1994 $sql .=
" total_ttc=".(isset($this->total_ttc) ? ((float) $this->total_ttc) :
"null").
",";
1995 $sql .=
" fk_statut=".(isset($this->
status) ? ((int) $this->
status) :
"null").
",";
1996 $sql .=
" fk_user_author=".(isset($this->user_author_id) ? ((int) $this->user_author_id) :
"null").
",";
1997 $sql .=
" fk_user_valid=".(isset($this->user_validation_id) && $this->user_validation_id > 0 ? ((int) $this->user_validation_id) :
"null").
",";
1998 $sql .=
" fk_projet=".((!empty($this->fk_project) && $this->fk_project > 0) ? ((
int) $this->fk_project) :
"null").
",";
1999 $sql .=
" fk_cond_reglement=".(isset($this->cond_reglement_id) ? ((int) $this->cond_reglement_id) :
"null").
",";
2000 $sql .=
" deposit_percent=".(!empty($this->deposit_percent) ?
"'".$this->db->escape($this->deposit_percent).
"'" :
"null").
",";
2001 $sql .=
" fk_mode_reglement=".(isset($this->mode_reglement_id) ? ((int) $this->mode_reglement_id) :
"null").
",";
2002 $sql .=
" date_livraison=".(strval($this->delivery_date) !=
'' ?
"'".$this->db->idate($this->delivery_date).
"'" :
'null').
",";
2004 $sql .=
" fk_account=".($this->fk_account > 0 ? ((int) $this->fk_account) :
"null").
",";
2006 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
2007 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
2008 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
2009 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
2011 $sql .=
" WHERE rowid=".((int) $this->
id);
2015 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
2016 $resql = $this->db->query($sql);
2019 $this->errors[] =
"Error ".$this->db->lasterror();
2029 if (!$error && !$notrigger) {
2031 $result = $this->call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2040 foreach ($this->errors as $errmsg) {
2041 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
2042 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2044 $this->db->rollback();
2047 $this->db->commit();
2062 global
$conf, $user, $hookmanager;
2069 foreach ($this->lines as $line) {
2070 $line->fetch_optionals();
2074 $objFrom = clone $this;
2077 if (!empty($socid) && $socid != $this->socid) {
2078 $objsoc =
new Societe($this->db);
2080 if ($objsoc->fetch($socid) > 0) {
2081 $this->socid = $objsoc->id;
2082 $this->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
2083 $this->deposit_percent = (!empty($objsoc->deposit_percent) ? $objsoc->deposit_percent :
'0');
2084 $this->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
2085 $this->fk_project = 0;
2086 $this->fk_delivery_address = 0;
2097 $this->user_author_id = $user->id;
2098 $this->user_validation_id = 0;
2101 $this->date_creation = 0;
2102 $this->date_validation = 0;
2103 $this->date_commande =
null;
2104 $this->ref_supplier =
'';
2105 $this->user_approve_id = 0;
2106 $this->user_approve_id2 = 0;
2107 $this->date_approve = 0;
2108 $this->date_approve2 = 0;
2111 $this->context[
'createfromclone'] =
'createfromclone';
2112 $result = $this->
create($user, $notrigger);
2119 if (is_object($hookmanager)) {
2120 $parameters = array(
'objFrom' => $objFrom);
2122 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
2130 unset($this->context[
'createfromclone']);
2134 $this->db->commit();
2137 $this->db->rollback();
2172 public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0.0, $txlocaltax2 = 0.0, $fk_product = 0, $fk_prod_fourn_price = 0, $ref_supplier =
'', $remise_percent = 0.0, $price_base_type =
'HT', $pu_ttc = 0.0, $type = 0, $info_bits = 0, $notrigger = 0,
$date_start =
null, $date_end =
null, $array_options = [], $fk_unit =
null, $pu_ht_devise = 0, $origin =
'', $origin_id = 0, $rang = -1, $special_code = 0, $label =
'')
2176 dol_syslog(get_class($this).
"::addline $desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $fk_prod_fourn_price, $ref_supplier, $remise_percent, $price_base_type, $pu_ttc, $type, $info_bits, $notrigger, $date_start, $date_end, $fk_unit, $pu_ht_devise, $origin, $origin_id");
2177 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2179 if ($this->
status == self::STATUS_DRAFT) {
2180 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2189 if (empty($txtva)) {
2195 if (empty($txlocaltax1)) {
2198 if (empty($txlocaltax2)) {
2201 if (empty($remise_percent)) {
2202 $remise_percent = 0;
2205 $remise_percent =
price2num($remise_percent);
2208 $pu_ht_devise =
price2num($pu_ht_devise);
2210 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
2215 if ($price_base_type ==
'HT') {
2221 $label = trim((
string) $label);
2222 $desc = trim((
string) $desc);
2223 if ($desc ===
'' && $label !==
'') {
2228 if ($qty < 0 && !$fk_product) {
2229 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Product"));
2236 $langs->load(
"errors");
2237 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
2244 $product_type = $type;
2247 if ($fk_product > 0) {
2248 if (
getDolGlobalInt(
'SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY') == 1) {
2250 dol_syslog(get_class($this).
"::addline we check supplier prices fk_product=".$fk_product.
" fk_prod_fourn_price=".$fk_prod_fourn_price.
" qty=".$qty.
" ref_supplier=".$ref_supplier);
2252 if ($prod->fetch($fk_product) > 0) {
2253 $product_type = $prod->type;
2254 $label = $prod->label;
2258 $result = $prod->get_buyprice($fk_prod_fourn_price, (
float) $qty, $fk_product,
'none', (isset($this->fk_soc) ? $this->fk_soc : $this->socid));
2262 if ($result > 0 && ($origin ==
'commande' || $pu ===
'')) {
2263 $pu = $prod->fourn_pu;
2264 $ref_supplier = $prod->ref_supplier;
2266 if ($remise_percent == 0 && $prod->remise_percent != 0) {
2267 $remise_percent = $prod->remise_percent;
2271 $langs->load(
"errors");
2272 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
2273 $this->db->rollback();
2274 dol_syslog(get_class($this).
"::addline we did not found supplier price, so we can't guess unit price");
2279 if ($result == -1) {
2280 $langs->load(
"errors");
2281 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
2282 $this->db->rollback();
2283 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_DEBUG);
2287 $this->error = $prod->error;
2288 $this->db->rollback();
2289 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_ERR);
2293 $this->error = $prod->error;
2294 $this->db->rollback();
2301 $prod =
new Product($this->db);
2302 $prod->get_buyprice($fk_prod_fourn_price, (
float) $qty, $fk_product,
'none', (empty($this->fk_soc) ? $this->socid : $this->fk_soc));
2307 if ($newqty != $qty) {
2309 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'warnings');
2317 if (!empty($prod->fourn_qty) && (
float) $qty > 0 && (
float) $qty < (
float) $prod->fourn_qty) {
2318 if (!empty($prod->packaging) && (
float)
price2num(fmod((
float) $prod->fourn_qty, (
float) $prod->packaging),
'MS')) {
2319 $coeff = intval((
float) $prod->fourn_qty / (
float) $prod->packaging) + 1;
2320 $qty = (float)
price2num((
float) $prod->packaging * $coeff,
'MS');
2322 $qty = (float) $prod->fourn_qty;
2324 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'mesgs');
2329 if (
isModEnabled(
"multicurrency") && $pu_ht_devise > 0) {
2338 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
2339 $vat_src_code = $reg[1];
2340 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
2347 $tabprice =
calcul_price_total((
float) $qty, $pu, (
float) $remise_percent, $txtva, (
float) $txlocaltax1, (
float) $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx, (
float) $pu_ht_devise, $this->multicurrency_code);
2349 $total_ht = $tabprice[0];
2350 $total_tva = $tabprice[1];
2351 $total_ttc = $tabprice[2];
2352 $total_localtax1 = $tabprice[9];
2353 $total_localtax2 = $tabprice[10];
2354 $pu = $pu_ht = $tabprice[3];
2355 $pu_tva = $tabprice[4];
2356 $pu_ttc = $tabprice[5];
2359 $multicurrency_total_ht = $tabprice[16];
2360 $multicurrency_total_tva = $tabprice[17];
2361 $multicurrency_total_ttc = $tabprice[18];
2362 $pu_ht_devise = $tabprice[19];
2363 $multicurrency_pu_ttc = $tabprice[21];
2365 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2366 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2370 $rang = $rangmax + 1;
2376 $this->line->context = $this->context;
2378 $this->line->fk_commande = $this->id;
2379 $this->line->label = $label;
2380 $this->line->ref_fourn = $ref_supplier;
2381 $this->line->ref_supplier = $ref_supplier;
2382 $this->line->desc = $desc;
2383 $this->line->qty = $qty;
2384 $this->line->tva_tx = $txtva;
2385 $this->line->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0);
2386 $this->line->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0);
2387 $this->line->localtax1_type = $localtax1_type;
2388 $this->line->localtax2_type = $localtax2_type;
2389 $this->line->fk_product = $fk_product;
2390 $this->line->product_type = $product_type;
2391 $this->line->remise_percent = $remise_percent;
2392 $this->line->subprice = (float) $pu_ht;
2393 $this->line->subprice_ttc = ($price_base_type ===
'TTC') ? (
float) $pu_ttc : 0;
2395 $this->line->rang = $rang;
2396 $this->line->info_bits = $info_bits;
2398 $this->line->vat_src_code = $vat_src_code;
2399 $this->line->total_ht = (float) $total_ht;
2400 $this->line->total_tva = (float) $total_tva;
2401 $this->line->total_localtax1 = (float) $total_localtax1;
2402 $this->line->total_localtax2 = (float) $total_localtax2;
2403 $this->line->total_ttc = (float) $total_ttc;
2404 $this->line->product_type = $type;
2405 $this->line->special_code = (!empty($special_code) ? $special_code : 0);
2406 $this->line->origin = $origin;
2407 $this->line->origin_type = $origin;
2408 $this->line->origin_id = $origin_id;
2409 $this->line->fk_unit = $fk_unit;
2412 $this->line->date_end = $date_end;
2415 $this->line->fk_multicurrency = $this->fk_multicurrency;
2416 $this->line->multicurrency_code = $this->multicurrency_code;
2417 $this->line->multicurrency_subprice = (float) $pu_ht_devise;
2418 $this->line->multicurrency_subprice_ttc = (float) $multicurrency_pu_ttc;
2419 $this->line->multicurrency_total_ht = (float) $multicurrency_total_ht;
2420 $this->line->multicurrency_total_tva = (float) $multicurrency_total_tva;
2421 $this->line->multicurrency_total_ttc = (float) $multicurrency_total_ttc;
2423 $this->line->subprice = (float) $pu_ht;
2424 $this->line->price = $this->line->subprice;
2426 $this->line->remise_percent = $remise_percent;
2428 if (is_array($array_options) && count($array_options) > 0) {
2429 $this->line->array_options = $array_options;
2432 $result = $this->line->insert($notrigger);
2435 $result = $this->
update_price(1,
'auto', 0, $this->thirdparty);
2438 if (!isset($this->context[
'createfromclone'])) {
2439 if (!empty($this->line->fk_parent_line)) {
2442 } elseif ($rang > 0 && $rang <= count($this->lines)) {
2444 $linecount = count($this->lines);
2445 for ($ii = $rang; $ii <= $linecount; $ii++) {
2450 $this->lines[] = $this->line;
2452 foreach ($this->lines as $line) {
2453 if ($line->id == $origin_id) {
2454 $this->line->extraparams = $line->extraparams;
2455 $this->line->setExtraParameters();
2460 $this->db->commit();
2461 return $this->line->id;
2463 $this->db->rollback();
2468 dol_syslog(get_class($this).
"::addline error=".$this->error, LOG_ERR);
2469 $this->db->rollback();
2494 public function dispatchProduct($user, $product, $qty, $entrepot, $price = 0, $comment =
'', $eatby =
'', $sellby =
'', $batch =
'', $fk_commandefourndet = 0, $notrigger = 0, $fk_reception = 0)
2496 global
$conf, $langs;
2499 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2502 if ($entrepot <= 0) {
2503 $this->error =
'ErrorBadValueForParameterWarehouse';
2507 $this->error =
'ErrorBadValueForParameterQty';
2511 $dispatchstatus = 1;
2513 $dispatchstatus = 0;
2520 if (($this->
status == self::STATUS_ORDERSENT || $this->
status == self::STATUS_RECEIVED_PARTIALLY || $this->
status == self::STATUS_RECEIVED_COMPLETELY)) {
2523 $sql =
"INSERT INTO ".$this->db->prefix().
"receptiondet_batch";
2524 $sql .=
" (fk_element, fk_product, qty, fk_entrepot, fk_user, datec, fk_elementdet, status, comment, eatby, sellby, batch, fk_reception) VALUES";
2525 $sql .=
" ('".((int) $this->
id).
"','".((int) $product).
"','".((float) $qty).
"',".($entrepot > 0 ?
"'".((int) $entrepot).
"'" :
"null").
",'".((
int) $user->id).
"','".$this->db->idate($now).
"','".((int) $fk_commandefourndet).
"', ".((int) $dispatchstatus).
", '".$this->db->escape($comment).
"', ";
2526 $sql .= ($eatby ?
"'".$this->db->idate($eatby).
"'" :
"null").
", ".($sellby ?
"'".$this->db->idate($sellby).
"'" :
"null").
", ".($batch ?
"'".$this->db->escape($batch).
"'" :
"null").
", ".($fk_reception > 0 ?
"'".$this->db->escape((
string) $fk_reception).
"'" :
"null");
2529 dol_syslog(get_class($this).
"::dispatchProduct", LOG_DEBUG);
2530 $resql = $this->db->query($sql);
2533 global
$conf, $langs, $user;
2535 $result = $this->call_trigger(
'LINEORDER_SUPPLIER_DISPATCH', $user);
2542 $this->error = $this->db->lasterror();
2551 $mouv->origin = &$this;
2552 $mouv->setOrigin($this->element, $this->
id);
2555 if (
getDolGlobalString(
'SUPPLIER_ORDER_ALLOW_NEGATIVE_QTY_FOR_SUPPLIER_ORDER_RETURN') && $qty < 0) {
2556 $result = $mouv->livraison($user, $product, $entrepot, $qty * (-1), $price, $comment, $now, $eatby, $sellby, $batch, 0, $inventorycode);
2558 $result = $mouv->reception($user, $product, $entrepot, $qty, $price, $comment, $eatby, $sellby, $batch,
'', 0, $inventorycode);
2562 $this->error = $mouv->error;
2563 $this->errors = $mouv->errors;
2564 dol_syslog(get_class($this).
"::dispatchProduct ".$this->error.
" ".implode(
',', $this->errors), LOG_ERR);
2571 $this->db->commit();
2574 $this->db->rollback();
2578 $this->error =
'BadStatusForObject';
2594 if ($this->
status == 0) {
2597 if ($line->fetch($idline) <= 0) {
2600 if ($this->
id > 0 && (
int) $line->fk_commande !== (
int) $this->id) {
2601 $this->error =
'ErrorLineIDDoesNotMatchWithObjectID';
2607 foreach ($dispatchedLines as $dispatchLine) {
2608 if ($dispatchLine[
'orderlineid'] == $idline) {
2609 $this->error =
"LineAlreadyDispatched";
2610 $this->errors[] = $this->error;
2615 if ($line->delete($user, $notrigger) > 0) {
2634 public function delete(
User $user, $notrigger = 0)
2636 global $langs,
$conf;
2637 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2643 if (empty($notrigger)) {
2645 $result = $this->call_trigger(
'ORDER_SUPPLIER_DELETE', $user);
2647 $this->errors[] =
'ErrorWhenRunningTrigger';
2648 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2649 $this->db->rollback();
2657 if (!empty($this->linkedObjects) && array_key_exists(
'reception', $this->linkedObjects)) {
2658 foreach ($this->linkedObjects[
'reception'] as $element) {
2659 if ($element->statut >= 0) {
2660 $this->errors[] = $langs->trans(
'ReceptionExist');
2669 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_supplier_order";
2670 $sql .=
" WHERE fk_supplier_order = ".((int) $this->
id);
2672 $result = $this->db->query($sql);
2675 $this->errors[] = $this->db->lasterror();
2679 $main = $this->db->prefix().
'commande_fournisseurdet';
2682 $sql1 =
"UPDATE ".$this->db->prefix().
"commandedet SET fk_commandefourndet = NULL WHERE fk_commandefourndet IN (SELECT rowid FROM ".$this->db->sanitize($main).
" WHERE fk_commande = ".((int) $this->
id).
")";
2683 dol_syslog(__METHOD__.
" linked order lines", LOG_DEBUG);
2684 if (!$this->db->query($sql1)) {
2686 $this->error = $this->db->lasterror();
2687 $this->errors[] = $this->db->lasterror();
2692 $ef = $main.
"_extrafields";
2693 $sql =
"DELETE FROM ".$this->db->sanitize($ef).
" WHERE fk_object IN (SELECT rowid FROM ".$this->db->sanitize($main).
" WHERE fk_commande = ".((int) $this->
id).
")";
2694 dol_syslog(get_class($this).
"::delete extrafields lines", LOG_DEBUG);
2695 if (!$this->db->query($sql)) {
2696 $this->error = $this->db->lasterror();
2697 $this->errors[] = $this->db->lasterror();
2703 $sql =
"DELETE FROM ".$this->db->prefix().
"commande_fournisseurdet WHERE fk_commande = ".((int) $this->
id);
2704 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2705 if (!$this->db->query($sql)) {
2706 $this->error = $this->db->lasterror();
2707 $this->errors[] = $this->db->lasterror();
2713 $sql =
"DELETE FROM ".$this->db->prefix().
"commande_fournisseur WHERE rowid = ".((int) $this->
id);
2714 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2715 if ($resql = $this->db->query($sql)) {
2716 if ($this->db->affected_rows($resql) < 1) {
2717 $this->error = $this->db->lasterror();
2718 $this->errors[] = $this->db->lasterror();
2722 $this->error = $this->db->lasterror();
2723 $this->errors[] = $this->db->lasterror();
2732 $this->error =
'FailToDeleteExtraFields';
2733 $this->errors[] =
'FailToDeleteExtraFields';
2735 dol_syslog(get_class($this).
"::delete error -4 ".$this->error, LOG_ERR);
2742 $this->error =
'FailToDeleteObjectLinked';
2743 $this->errors[] =
'FailToDeleteObjectLinked';
2754 if ($conf->fournisseur->commande->dir_output && !empty($ref)) {
2755 $dir =
$conf->fournisseur->commande->dir_output.
"/".$ref;
2756 $file = $dir.
"/".$ref.
".pdf";
2757 if (file_exists($file)) {
2759 $this->error =
'ErrorFailToDeleteFile';
2760 $this->errors[] =
'ErrorFailToDeleteFile';
2764 if (file_exists($dir)) {
2767 $this->error =
'ErrorFailToDeleteDir';
2768 $this->errors[] =
'ErrorFailToDeleteDir';
2776 dol_syslog(get_class($this).
"::delete $this->id by $user->id", LOG_DEBUG);
2777 $this->db->commit();
2780 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2781 $this->db->rollback();
2800 $sql =
"SELECT p.ref, p.label,";
2801 $sql .=
" e.rowid as warehouse_id, e.ref as entrepot,";
2802 $sql .=
" cfd.rowid as dispatchedlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status, cfd.fk_elementdet";
2803 $sql .=
" FROM ".$this->db->prefix().
"product as p,";
2804 $sql .=
" ".$this->db->prefix().
"receptiondet_batch as cfd";
2805 $sql .=
" LEFT JOIN ".$this->db->prefix().
"entrepot as e ON cfd.fk_entrepot = e.rowid";
2806 $sql .=
" WHERE cfd.fk_element = ".((int) $this->
id);
2807 $sql .=
" AND cfd.fk_product = p.rowid";
2809 $sql .=
" AND cfd.status = ".((int) $status);
2811 $sql .=
" ORDER BY cfd.rowid ASC";
2813 $resql = $this->db->query($sql);
2815 $num = $this->db->num_rows($resql);
2819 $objp = $this->db->fetch_object($resql);
2822 'id' => $objp->dispatchedlineid,
2823 'productid' => $objp->fk_product,
2824 'warehouseid' => $objp->warehouse_id,
2825 'qty' => $objp->qty,
2826 'orderlineid' => $objp->fk_elementdet
2833 dol_print_error($this->db,
'Failed to execute request to get dispatched lines');
2856 $dispatchedlinearray = array();
2860 $usercanreceive = 0;
2862 $usercanreceive = $user->hasRight(
"fournisseur",
"commande",
"receptionner");
2864 $usercanreceive = $user->hasRight(
"reception",
"creer");
2867 if ($usercanreceive) {
2869 if ($type ==
'par') {
2871 } elseif ($type ==
'tot') {
2873 } elseif ($type ==
'nev') {
2875 } elseif ($type ==
'can') {
2879 dol_syslog(get_class($this).
"::Livraison Error -2", LOG_ERR);
2886 if ($type ==
'tot') {
2888 if (count($dispatchedlinearray) > 0) {
2891 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove';
2892 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove', LOG_DEBUG);
2895 if (!$error &&
getDolGlobalString(
'SUPPLIER_ORDER_USE_DISPATCH_STATUS_NEED_APPROVE') && ($type ==
'tot')) {
2897 if (count($dispatcheddenied) > 0) {
2900 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied';
2901 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied', LOG_DEBUG);
2908 if (empty($error)) {
2911 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2912 $sql .=
" SET fk_statut = ".((int) $statut);
2913 $sql .=
" WHERE rowid = ".((int) $this->
id);
2914 $sql .=
" AND fk_statut IN (".self::STATUS_ORDERSENT.
",".self::STATUS_RECEIVED_PARTIALLY.
")";
2916 dol_syslog(get_class($this).
"::Livraison", LOG_DEBUG);
2917 $resql = $this->db->query($sql);
2920 $old_statut = $this->status;
2922 $this->context[
'actionmsg2'] = $comment;
2925 $result_trigger = $this->call_trigger(
'ORDER_SUPPLIER_RECEIVE', $user);
2926 if ($result_trigger < 0) {
2931 if (empty($error)) {
2932 $this->db->commit();
2934 $this->
status = $old_statut;
2935 $this->db->rollback();
2936 $this->error = $this->db->lasterror();
2940 $this->db->rollback();
2941 $this->error = $this->db->lasterror();
2946 $this->error = $langs->trans(
'NotAuthorized');
2947 $this->errors[] = $langs->trans(
'NotAuthorized');
2948 dol_syslog(get_class($this).
"::Livraison Not Authorized");
2980 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
2985 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2986 $sql .=
" SET date_livraison = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2987 $sql .=
" WHERE rowid = ".((int) $this->
id);
2990 $resql = $this->db->query($sql);
2992 $this->errors[] = $this->db->error();
2997 $this->oldcopy = clone $this;
2998 $this->delivery_date = $delivery_date;
3001 if (!$notrigger && empty($error)) {
3003 $result = $this->call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
3011 $this->db->commit();
3014 foreach ($this->errors as $errmsg) {
3015 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
3016 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3018 $this->db->rollback();
3034 if (in_array($this->
status, [1, 2, 3, 4, 5, 6, 7, 9])) {
3035 if ($this->
status == 1) {
3037 } elseif ($this->
status == 2) {
3039 } elseif ($this->
status == 3) {
3041 } elseif ($this->
status == 4) {
3043 } elseif ($this->
status == 5) {
3049 } elseif ($this->
status == 6) {
3051 } elseif ($this->
status == 7) {
3053 } elseif ($this->
status == 9) {
3061 $result = $this->
setStatus($user, $newStatus);
3063 if ($newStatus == 0) {
3064 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur';
3065 $sql .=
' SET fk_user_approve = null, fk_user_approve2 = null, date_approve = null, date_approve2 = null';
3066 $sql .=
' WHERE rowid = '.((int) $this->
id);
3068 $this->db->query($sql);
3071 $this->db->commit();
3075 $this->db->rollback();
3096 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
3101 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
3102 $sql .=
" SET fk_projet = ".($id_projet > 0 ? (int) $id_projet :
'null');
3103 $sql .=
" WHERE rowid = ".((int) $this->
id);
3106 $resql = $this->db->query($sql);
3108 $this->errors[] = $this->db->error();
3113 $this->oldcopy = clone $this;
3114 $this->fk_projet = $id_projet;
3115 $this->fk_project = $id_projet;
3118 if (!$notrigger && empty($error)) {
3120 $result = $this->call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
3128 $this->db->commit();
3131 foreach ($this->errors as $errmsg) {
3132 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
3133 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3135 $this->db->rollback();
3153 $comclient =
new Commande($this->db);
3154 $comclient->fetch($comclientid);
3158 $this->lines = array();
3160 $num = count($comclient->lines);
3161 for ($i = 0; $i < $num; $i++) {
3162 $prod =
new Product($this->db);
3165 if ($prod->fetch($comclient->lines[$i]->fk_product) > 0) {
3166 $label = $prod->label;
3167 $ref = (string) $prod->ref;
3170 $sql =
"INSERT INTO ".$this->db->prefix().
"commande_fournisseurdet";
3171 $sql .=
" (fk_commande, label, description, fk_product, price, qty, tva_tx, localtax1_tx, localtax2_tx, remise_percent, subprice, remise, ref)";
3172 $sql .=
" VALUES (".((int) $idc).
", '".$this->db->escape($label).
"', '".$this->db->escape($comclient->lines[$i]->desc).
"'";
3173 $sql .=
",".((int) $comclient->lines[$i]->fk_product).
", ".
price2num($comclient->lines[$i]->price,
'MU');
3174 $sql .=
", ".price2num($comclient->lines[$i]->qty,
'MS').
", ".
price2num($comclient->lines[$i]->tva_tx, 5).
", ".
price2num($comclient->lines[$i]->localtax1_tx, 5).
", ".
price2num($comclient->lines[$i]->localtax2_tx, 5).
", ".
price2num($comclient->lines[$i]->remise_percent, 3);
3175 $sql .=
", '".price2num($comclient->lines[$i]->subprice,
'MT').
"','0', '".$this->db->escape($ref).
"');";
3176 if ($this->db->query($sql)) {
3197 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur';
3198 $sql .=
" SET fk_statut = ".((int) $status);
3199 $sql .=
" WHERE rowid = ".((int) $this->
id);
3201 dol_syslog(get_class($this).
"::setStatus", LOG_DEBUG);
3202 $resql = $this->db->query($sql);
3205 $triggerName = array();
3206 $triggerName[0] =
'DRAFT';
3207 $triggerName[1] =
'VALIDATED';
3208 $triggerName[2] =
'APPROVED';
3209 $triggerName[3] =
'ORDERED';
3210 $triggerName[4] =
'RECEIVED_PARTIALLY';
3211 $triggerName[5] =
'RECEIVED_COMPLETELY';
3212 $triggerName[6] =
'CANCELED';
3213 $triggerName[7] =
'CANCELED';
3214 $triggerName[9] =
'REFUSED';
3217 $result = $this->call_trigger(
"ORDER_SUPPLIER_STATUS_".$triggerName[$status], $user);
3224 $this->error = $this->db->lasterror();
3225 dol_syslog(get_class($this).
"::setStatus ".$this->error);
3230 $this->db->commit();
3233 $this->db->rollback();
3251 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
3252 return parent::setCategoriesCommon($categories, Categorie::TYPE_SUPPLIER_ORDER);
3278 public function updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $price_base_type =
'HT', $info_bits = 0, $type = 0, $notrigger = 0,
$date_start = 0, $date_end = 0, $array_options = [], $fk_unit =
null, $pu_ht_devise = 0, $ref_supplier =
'')
3283 $this->error =
'ErrorLineIDDoesNotMatchWithObjectID';
3287 dol_syslog(get_class($this).
"::updateline $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $type, $fk_unit");
3288 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
3292 if ($this->
status == self::STATUS_DRAFT) {
3297 if (empty($info_bits)) {
3300 if (empty($txtva)) {
3303 if (empty($txlocaltax1)) {
3306 if (empty($txlocaltax2)) {
3309 if (empty($remise_percent)) {
3310 $remise_percent = 0;
3313 $remise_percent = (float)
price2num($remise_percent);
3319 $pu_ht_devise =
price2num($pu_ht_devise);
3320 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
3323 $txlocaltax1 = (float)
price2num($txlocaltax1);
3324 $txlocaltax2 = (float)
price2num($txlocaltax2);
3331 $langs->load(
"errors");
3332 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
3347 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
3348 $vat_src_code = $reg[1];
3349 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
3356 if ($tmpline->fetch($rowid) > 0) {
3358 if ($newqty != $qty) {
3360 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'warnings');
3365 $tabprice =
calcul_price_total($qty, (
float) $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, (
float) $this->multicurrency_tx, (
float) $pu_ht_devise, $this->multicurrency_code);
3366 $total_ht = $tabprice[0];
3367 $total_tva = $tabprice[1];
3368 $total_ttc = $tabprice[2];
3369 $total_localtax1 = $tabprice[9];
3370 $total_localtax2 = $tabprice[10];
3371 $pu_ht = $tabprice[3];
3372 $pu_tva = $tabprice[4];
3373 $pu_ttc = $tabprice[5];
3376 $multicurrency_total_ht = $tabprice[16];
3377 $multicurrency_total_tva = $tabprice[17];
3378 $multicurrency_total_ttc = $tabprice[18];
3379 $pu_ht_devise = $tabprice[19];
3380 $multicurrency_pu_ttc = $tabprice[21];
3382 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
3383 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
3387 $this->line->fetch($rowid);
3389 $oldline = clone $this->line;
3390 $this->line->oldline = $oldline;
3392 $this->line->context = $this->context;
3394 $this->line->fk_commande = $this->id;
3396 $this->line->desc = $desc;
3399 $this->line->qty = $qty;
3400 $this->line->ref_supplier = $ref_supplier;
3402 $this->line->vat_src_code = $vat_src_code;
3403 $this->line->tva_tx = $txtva;
3404 $this->line->localtax1_tx = $txlocaltax1;
3405 $this->line->localtax2_tx = $txlocaltax2;
3406 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
3407 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
3408 $this->line->remise_percent = $remise_percent;
3409 $this->line->subprice = (float) $pu_ht;
3410 $this->line->subprice_ttc = (float) $pu_ttc;
3411 $this->line->info_bits = $info_bits;
3412 $this->line->total_ht = (float) $total_ht;
3413 $this->line->total_tva = (float) $total_tva;
3414 $this->line->total_localtax1 = (float) $total_localtax1;
3415 $this->line->total_localtax2 = (float) $total_localtax2;
3416 $this->line->total_ttc = (float) $total_ttc;
3417 $this->line->product_type = $type;
3418 $this->line->special_code = $oldline->special_code;
3419 $this->line->rang = $oldline->rang;
3420 $this->line->origin = $this->origin;
3421 $this->line->fk_unit = $fk_unit;
3424 $this->line->date_end = $date_end;
3427 $this->line->fk_multicurrency = $this->fk_multicurrency;
3428 $this->line->multicurrency_code = $this->multicurrency_code;
3429 $this->line->multicurrency_subprice = (float) $pu_ht_devise;
3430 $this->line->multicurrency_subprice_ttc = (float) $multicurrency_pu_ttc;
3431 $this->line->multicurrency_total_ht = (float) $multicurrency_total_ht;
3432 $this->line->multicurrency_total_tva = (float) $multicurrency_total_tva;
3433 $this->line->multicurrency_total_ttc = (float) $multicurrency_total_ttc;
3435 $this->line->subprice = (float) $pu_ht;
3436 $this->line->subprice_ttc = ($price_base_type ===
'TTC') ? (
float) $pu_ttc : 0;
3437 $this->line->price = $this->line->subprice;
3439 $this->line->remise_percent = $remise_percent;
3441 if (is_array($array_options) && count($array_options) > 0) {
3443 foreach ($array_options as $key => $value) {
3444 $this->line->array_options[$key] = $array_options[$key];
3448 $result = $this->line->update($notrigger);
3454 $this->db->commit();
3457 $this->errors[] = $this->line->error;
3458 $this->errors = array_merge($this->errors, $this->line->errors);
3459 $this->error = $this->db->lasterror();
3460 $this->db->rollback();
3464 $this->error =
"Order status makes operation forbidden";
3465 dol_syslog(get_class($this).
"::updateline ".$this->error, LOG_ERR);
3480 global $user, $langs,
$conf;
3482 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
3484 dol_syslog(get_class($this).
"::initAsSpecimen");
3491 $sql =
"SELECT rowid";
3492 $sql .=
" FROM ".$this->db->prefix().
"product";
3493 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
3494 $sql .= $this->db->order(
"rowid",
"ASC");
3495 $sql .= $this->db->plimit(1);
3496 $resql = $this->db->query($sql);
3497 if ($resql && $this->db->num_rows($resql)) {
3498 $obj = $this->db->fetch_object($resql);
3499 $prodid = $obj->rowid;
3504 $this->
ref =
'SPECIMEN';
3505 $this->specimen = 1;
3508 $this->date_commande = $now;
3509 $this->date_lim_reglement = $this->
date + 3600 * 24 * 30;
3510 $this->cond_reglement_code =
'RECEP';
3511 $this->mode_reglement_code =
'CHQ';
3513 $this->note_public =
'This is a comment (public)';
3514 $this->note_private =
'This is a comment (private)';
3516 $this->multicurrency_tx = 1;
3517 $this->multicurrency_code =
$conf->currency;
3525 while ($xnbp < $nbp) {
3527 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
3529 $line->subprice = 100;
3530 $line->tva_tx = 19.6;
3531 $line->localtax1_tx = 0;
3532 $line->localtax2_tx = 0;
3534 $line->total_ht = 50;
3535 $line->total_ttc = 59.8;
3536 $line->total_tva = 9.8;
3537 $line->remise_percent = 50;
3539 $line->total_ht = 100;
3540 $line->total_ttc = 119.6;
3541 $line->total_tva = 19.6;
3542 $line->remise_percent = 00;
3544 $line->fk_product = $prodid;
3546 $this->lines[$xnbp] = $line;
3548 $this->total_ht += $line->total_ht;
3549 $this->total_tva += $line->total_tva;
3550 $this->total_ttc += $line->total_ttc;
3566 $sql =
'SELECT c.rowid, date_creation as datec, tms as datem, date_valid as date_validation, date_approve as datea, date_approve2 as datea2,';
3567 $sql .=
' fk_user_author, fk_user_modif, fk_user_valid, fk_user_approve, fk_user_approve2';
3568 $sql .=
' FROM '.$this->db->prefix().
'commande_fournisseur as c';
3569 $sql .=
' WHERE c.rowid = '.((int) $id);
3571 $result = $this->db->query($sql);
3573 if ($this->db->num_rows($result)) {
3574 $obj = $this->db->fetch_object($result);
3576 $this->
id = $obj->rowid;
3578 $this->user_creation_id = $obj->fk_user_author;
3579 $this->user_validation_id = $obj->fk_user_valid;
3580 $this->user_modification_id = $obj->fk_user_modif;
3581 $this->user_approve_id = $obj->fk_user_approve;
3582 $this->user_approve_id2 = $obj->fk_user_approve2;
3584 $this->date_creation = $this->db->jdate($obj->datec);
3585 $this->date_modification = $this->db->jdate($obj->datem);
3586 $this->date_approve = $this->db->jdate($obj->datea);
3587 $this->date_approve2 = $this->db->jdate($obj->datea2);
3588 $this->date_validation = $this->db->jdate($obj->date_validation);
3590 $this->db->free($result);
3592 dol_print_error($this->db);
3605 $this->nb = array();
3606 $sanitizedclause =
"WHERE";
3608 $sql =
"SELECT count(co.rowid) as nb";
3609 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as co";
3610 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe as s ON co.fk_soc = s.rowid";
3611 if (empty($user->socid) && !$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3612 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
3613 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
3614 $sanitizedclause =
"AND";
3616 $sql .=
" ".$sanitizedclause.
" co.entity IN (".
getEntity(
'supplier_order').
")";
3618 $resql = $this->db->query($sql);
3620 while ($obj = $this->db->fetch_object($resql)) {
3621 $this->nb[
"supplier_orders"] = $obj->nb;
3623 $this->db->free($resql);
3626 dol_print_error($this->db);
3627 $this->error = $this->db->error();
3643 global
$conf, $langs;
3645 $sql =
"SELECT c.rowid, c.date_creation as datec, c.date_commande, c.fk_statut, c.date_livraison as delivery_date, c.total_ht";
3646 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as c";
3647 if (empty($user->socid) && !$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3648 $sql .=
" JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
3650 $sql .=
" WHERE c.entity = ".((int)
$conf->entity);
3651 if ($mode ===
'awaiting') {
3652 $sql .=
" AND c.fk_statut IN (".self::STATUS_ORDERSENT.
", ".self::STATUS_RECEIVED_PARTIALLY.
")";
3654 $sql .=
" AND c.fk_statut IN (".self::STATUS_VALIDATED.
", ".self::STATUS_ACCEPTED.
")";
3657 $sql .=
" AND c.fk_soc = ".((int) $user->socid);
3660 $resql = $this->db->query($sql);
3665 $response->warning_delay =
$conf->commande->fournisseur->warning_delay / 60 / 60 / 24;
3666 $response->label = $langs->trans(
"SuppliersOrdersToProcess");
3667 $response->labelShort = $langs->trans(
"Opened");
3668 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=1,2&mainmenu=commercial&leftmenu=orders_suppliers';
3669 $response->url_late = DOL_URL_ROOT.
'/fourn/commande/list.php?mainmenu=commercial&leftmenu=orders_suppliers&search_option=late';
3670 $response->img = img_object(
'',
"order");
3672 if ($mode ===
'awaiting') {
3673 $response->label = $langs->trans(
"SuppliersOrdersAwaitingReception");
3674 $response->labelShort = $langs->trans(
"AwaitingReception");
3675 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=3,4&mainmenu=commercial&leftmenu=orders_suppliers';
3676 $response->url_late = DOL_URL_ROOT.
'/fourn/commande/list.php?mainmenu=commercial&leftmenu=orders_suppliers&search_option=recv_late';
3679 while ($obj = $this->db->fetch_object($resql)) {
3680 $commandestatic->delivery_date = $this->db->jdate($obj->delivery_date);
3681 $commandestatic->date_commande = $this->db->jdate($obj->date_commande);
3682 $commandestatic->statut = $obj->fk_statut;
3683 $commandestatic->status = $obj->fk_statut;
3685 $response->nbtodo++;
3686 $response->total += $obj->total_ht;
3688 if ($commandestatic->hasDelay()) {
3689 $response->nbtodolate++;
3695 $this->error = $this->db->error();
3710 if ($this->methode_commande_id > 0) {
3711 $sql =
"SELECT rowid, code, libelle as label";
3712 $sql .=
" FROM ".$this->db->prefix().
'c_input_method';
3713 $sql .=
" WHERE active=1 AND rowid = ".((int) $this->methode_commande_id);
3715 $resql = $this->db->query($sql);
3717 if ($this->db->num_rows($resql)) {
3718 $obj = $this->db->fetch_object($resql);
3720 $string = $langs->trans($obj->code);
3721 if ($string == $obj->code) {
3722 $string = $obj->label !=
'-' ? $obj->label :
'';
3727 dol_print_error($this->db);
3745 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3752 if (!empty($this->model_pdf)) {
3753 $modele = $this->model_pdf;
3759 if (empty($modele)) {
3762 $langs->load(
"suppliers");
3763 $outputlangs->load(
"products");
3765 $modelpath =
"core/modules/supplier_order/doc/";
3766 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3779 if (empty($this->lines)) {
3786 foreach ($this->lines as $line) {
3787 if ($line->fk_product > 0) {
3789 $idp = $tmpproductfourn->find_min_price_product_fournisseur($line->fk_product, $line->qty, $this->thirdparty->id);
3792 if ($tmpproductfourn->delivery_time_days > $nb) {
3793 $nb = $tmpproductfourn->delivery_time_days;
3802 return $nb.
' '.$langs->trans(
'days');
3815 if ($mode ==
'create') {
3818 if (!in_array($mode, array(
'read',
'write',
'delete'))) {
3822 return (
bool) $user->hasRight(
"fournisseur",
"commande", $mode);
3837 'commande_fournisseur'
3854 'commande_fournisseurdet'
3871 if ($this->
status == self::STATUS_ORDERSENT || $this->
status == self::STATUS_RECEIVED_PARTIALLY) {
3873 if (!empty($this->delivery_date)) {
3874 $date_to_test = $this->delivery_date;
3875 return $date_to_test && $date_to_test < ($now -
$conf->commande->fournisseur->warning_delay);
3883 $date_to_test = $this->date_commande;
3885 return ($this->
status > 0 && $this->
status < 5) && $date_to_test && $date_to_test < ($now -
$conf->commande->fournisseur->warning_delay);
3898 global
$conf, $langs;
3900 $langs->load(
'orders');
3904 if ($this->
status == self::STATUS_ORDERSENT || $this->
status == self::STATUS_RECEIVED_PARTIALLY) {
3905 if (!empty($this->delivery_date)) {
3906 $text = $langs->trans(
"DeliveryDate").
' '.
dol_print_date($this->delivery_date,
'day');
3908 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3911 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3914 $text .=
' '.($conf->commande->fournisseur->warning_delay > 0 ?
'+' :
'-').
' '.round(abs(
$conf->commande->fournisseur->warning_delay) / 3600 / 24, 1).
' '.$langs->trans(
"days").
' < '.$langs->trans(
"Today");
3932 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
3934 $qtydelivered = array();
3935 $qtywished = array();
3939 $filter = array(
't.fk_element' => $this->
id);
3941 $filter[
't.status'] = 1;
3944 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
3946 $this->error = $supplierorderdispatch->error;
3947 $this->errors = $supplierorderdispatch->errors;
3950 if (is_array($supplierorderdispatch->lines) && count($supplierorderdispatch->lines) > 0) {
3951 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
3955 foreach ($supplierorderdispatch->lines as $line) {
3956 if (array_key_exists($line->fk_product, $qtydelivered)) {
3957 $qtydelivered[$line->fk_product] += $line->qty;
3959 $qtydelivered[$line->fk_product] = $line->qty;
3962 foreach ($this->lines as $line) {
3964 if (empty($line->fk_product)) {
3968 if ($line->product_type > 0 && (!
getDolGlobalString(
'STOCK_SUPPORTS_SERVICES') || empty($line->stockable_product))) {
3971 if (array_key_exists($line->fk_product, $qtywished)) {
3972 $qtywished[$line->fk_product] += $line->qty;
3974 $qtywished[$line->fk_product] = $line->qty;
3979 $diff_array = array_diff_assoc($qtydelivered, $qtywished);
3980 $keysinwishednotindelivered = array_diff(array_keys($qtywished), array_keys($qtydelivered));
3981 $keysindeliverednotinwished = array_diff(array_keys($qtydelivered), array_keys($qtywished));
3989 if (count($diff_array) == 0 && count($keysinwishednotindelivered) == 0 && count($keysindeliverednotinwished) == 0) {
3990 if ($closeopenorder) {
3992 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
4000 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
4011 if (count($diff_array) > 0) {
4015 foreach ($diff_array as $key => $value) {
4017 if ($qtydelivered[$key] >= $qtywished[$key]) {
4024 if ($close == count($diff_array)) {
4026 if ($closeopenorder) {
4027 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
4034 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
4042 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
4050 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
4072 $this->receptions = array();
4074 dol_syslog(get_class($this).
"::loadReceptions", LOG_DEBUG);
4076 $sql =
'SELECT cd.rowid, cd.fk_product,';
4077 $sql .=
' sum(cfd.qty) as qty';
4078 $sql .=
' FROM '.$this->db->prefix().
'receptiondet_batch as cfd,';
4079 if ($filtre_statut >= 0) {
4080 $sql .=
' '.$this->db->prefix().
'reception as e,';
4082 $sql .=
' '.$this->db->prefix().
'commande_fournisseurdet as cd';
4084 if ($filtre_statut >= 0) {
4085 $sql .=
' cfd.fk_reception = e.rowid AND';
4087 $sql .=
' cfd.fk_elementdet = cd.rowid';
4088 $sql .=
' AND cd.fk_commande ='.((int) $this->
id);
4089 if ($filtre_statut >= 0) {
4090 $sql .=
' AND e.fk_statut >= '.((int) $filtre_statut);
4092 $sql .=
' GROUP BY cd.rowid, cd.fk_product';
4094 $resql = $this->db->query($sql);
4096 $num = $this->db->num_rows($resql);
4099 $obj = $this->db->fetch_object($resql);
4100 if (empty($this->receptions[$obj->rowid])) {
4101 $this->receptions[$obj->rowid] = (float) $obj->qty;
4103 $this->receptions[$obj->rowid] += (float) $obj->qty;
4107 $this->db->free($resql);
4111 $this->error = $this->db->lasterror();
4127 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
4129 $return =
'<div class="box-flex-item box-flex-grow-zero">';
4130 $return .=
'<div class="info-box info-box-sm">';
4131 $return .=
'<span class="info-box-icon bg-infobox-action">';
4132 $return .= img_picto(
'', $this->picto);
4133 $return .=
'</span>';
4134 $return .=
'<div class="info-box-content">';
4135 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
4136 if ($selected >= 0) {
4137 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
4139 if (!empty($arraydata[
'thirdparty'])) {
4140 $return .=
'<br><span class="info-box-label">'.$arraydata[
'thirdparty'].
'</span>';
4142 if (!empty($this->
date)) {
4143 $return .=
'<br><span class="info-box-label">'.dol_print_date($this->
date,
'day').
'</span>';
4145 if (!empty($this->total_ht)) {
4146 $return .=
' <span class="info-box-label amount" title="'.dol_escape_htmltag($langs->trans(
"AmountHT")).
'">'.
price($this->total_ht);
4147 $return .=
' '.$langs->trans(
"HT");
4148 $return .=
'</span>';
4150 if (method_exists($this,
'getLibStatut')) {
4151 $return .=
'<br><span class="info-box-status">'.$this->getLibStatut(3).
'</span>';
4153 if (property_exists($this,
'billed')) {
4154 $return .=
' <span class="opacitymedium">'.$langs->trans(
"Billed").
': </span><span class="info-box-label">'.yn($this->billed).
'</span>';
4156 $return .=
'</div>';
4157 $return .=
'</div>';
4158 $return .=
'</div>';
4182 global
$conf, $langs, $user;
4188 $blockingerrormsg =
'';
4191 $langs->load(
"agenda");
4192 $this->output = $langs->trans(
'ModuleNotEnabled', $langs->transnoentitiesnoconv(
"SupplierOrder"));
4196 $langs->loadLangs(array(
'main',
'orders'));
4202 $listofordersok = array();
4203 $listofordersko = array();
4205 $arraydaysbeforeend = explode(
';', $daysbeforeendlist);
4206 foreach ($arraydaysbeforeend as $daysbeforeend) {
4207 dol_syslog(__METHOD__.
' - Process delta = '.$daysbeforeend, LOG_DEBUG);
4209 if (!is_numeric($daysbeforeend)) {
4210 $blockingerrormsg =
"Value for delta is not a numeric value";
4216 $labelreminderok =
'sendReminderForLateSupplierDeliveriesOK (daysbeforeend='.$daysbeforeend.
')';
4219 $datetosearchfor =
dol_time_plus_duree(
dol_mktime(0, 0, 0, $tmp[
'mon'], $tmp[
'mday'], $tmp[
'year'],
'tzserver'), (
int) $daysbeforeend,
'd');
4220 $datetosearchforend =
dol_time_plus_duree(
dol_mktime(23, 59, 59, $tmp[
'mon'], $tmp[
'mday'], $tmp[
'year'],
'tzserver'), (
int) $daysbeforeend,
'd');
4222 $sql =
"SELECT c.rowid";
4223 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseur as c";
4224 $sql .=
" WHERE c.entity = ".((int)
$conf->entity);
4225 $sql .=
" AND c.fk_statut IN (".self::STATUS_ORDERSENT.
", ".self::STATUS_RECEIVED_PARTIALLY.
")";
4226 $sql .=
" AND c.date_livraison >= '".$this->db->idate($datetosearchfor).
"'";
4227 $sql .=
" AND c.date_livraison <= '".$this->db->idate($datetosearchforend).
"'";
4228 $sql .=
" AND NOT EXISTS (SELECT a.id FROM ".MAIN_DB_PREFIX.
"actioncomm as a";
4229 $sql .=
" WHERE a.elementtype = 'order_supplier' AND a.fk_element = c.rowid AND a.code = 'AC_EMAIL'";
4230 $sql .=
" AND a.label = '".$this->db->escape($labelreminderok).
"'";
4233 $resql = $this->db->query($sql);
4235 $num_rows = $this->db->num_rows($resql);
4237 require_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
4238 require_once DOL_DOCUMENT_ROOT.
'/user/class/user.class.php';
4239 $formmail =
new FormMail($this->db);
4242 while ($i < $num_rows) {
4243 $obj = $this->db->fetch_object($resql);
4246 $orderstatic->fetch($obj->rowid);
4248 $recipient =
new User($this->db);
4249 $recipientres = (!empty($orderstatic->user_author_id)) ? $recipient->fetch($orderstatic->user_author_id) : -1;
4251 if ($recipientres <= 0 || empty($recipient->email)) {
4253 $listofordersko[$orderstatic->id] = $orderstatic->id;
4255 $orderstatic->fetch_thirdparty();
4257 $arraydefaultmessage =
null;
4258 $labeltouse =
getDolGlobalString(
'SUPPLIER_ORDER_EMAIL_TEMPLATE_REMIND_LATE_DELIVERY');
4260 if (!empty($labeltouse)) {
4261 $arraydefaultmessage = $formmail->getEMailTemplate($this->db,
'order_supplier', $user, $langs, 0, 1, $labeltouse);
4264 if (!empty($labeltouse) && is_object($arraydefaultmessage) && $arraydefaultmessage->id > 0) {
4265 $substitutionarray = getCommonSubstitutionArray($langs, 0,
null, $orderstatic);
4267 $substitutionarray[
'__SUPPLIER_ORDER_DELIVERY_DATE__'] =
dol_print_date($orderstatic->delivery_date,
'day',
'tzuserrel', $langs);
4268 $substitutionarray[
'__SUPPLIER_ORDER_SUPPLIER_NAME__'] = (is_object($orderstatic->thirdparty) ? $orderstatic->thirdparty->name :
'');
4269 $substitutionarray[
'__SUPPLIER_ORDER_URL__'] = DOL_MAIN_URL_ROOT.
'/fourn/commande/card.php?id='.$orderstatic->id;
4271 $subject =
make_substitutions($arraydefaultmessage->topic, $substitutionarray, $langs);
4272 $msg =
make_substitutions($arraydefaultmessage->content, $substitutionarray, $langs);
4274 $to = (string) $recipient->email;
4276 $trackid =
'ord'.$orderstatic->id;
4277 $moreinheader =
'X-Dolibarr-Info: sendReminderForLateSupplierDeliveries'.
"\r\n";
4279 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
4280 $cmail =
new CMailFile($subject, $to, $email_from, $msg, array(), array(), array(),
'',
'', 0, 1,
'',
'', $trackid, $moreinheader);
4281 $result = $cmail->sendfile();
4284 $this->error .= $cmail->error.
' ';
4285 if (!is_null($cmail->errors)) {
4286 $this->errors = array_merge($this->errors, $cmail->errors);
4289 $listofordersko[$orderstatic->id] = $orderstatic->id;
4292 $listofordersok[$orderstatic->id] = $orderstatic->id;
4295 require_once DOL_DOCUMENT_ROOT.
'/comm/action/class/actioncomm.class.php';
4298 $actioncomm->type_code =
'AC_OTH_AUTO';
4299 $actioncomm->code =
'AC_EMAIL';
4300 $actioncomm->label = $labelreminderok;
4301 $actioncomm->note_private = $msg;
4302 $actioncomm->fk_project = $orderstatic->fk_project;
4303 $actioncomm->datep = $now;
4304 $actioncomm->datef = $now;
4305 $actioncomm->percentage = -1;
4306 $actioncomm->socid = (is_object($orderstatic->thirdparty) ? $orderstatic->thirdparty->id : 0);
4307 $actioncomm->contact_id = 0;
4308 $actioncomm->authorid = $user->id;
4309 $actioncomm->userownerid = $user->id;
4310 $actioncomm->email_msgid = $cmail->msgid;
4311 $actioncomm->email_from = $email_from;
4312 $actioncomm->email_sender =
'';
4313 $actioncomm->email_to = $to;
4314 $actioncomm->email_subject = $subject;
4316 $actioncomm->fk_element = $orderstatic->id;
4317 $actioncomm->elementid = $orderstatic->id;
4318 $actioncomm->elementtype = $orderstatic->element;
4320 $actioncomm->create($user);
4324 $this->error .=
"Can't find email template with label=".$labeltouse.
", to use for the reminding email ";
4327 $listofordersko[$orderstatic->id] = $orderstatic->id;
4337 $this->error = $this->db->lasterror();
4342 if ($blockingerrormsg) {
4343 $this->error = $blockingerrormsg;
4346 $this->output =
'Found '.($nbok + $nbko).
' orders to send reminder for.';
4347 $this->output .=
' Sent email successfully for '.$nbok.
' orders';
4349 $this->output .=
' - Canceled for '.$nbko.
' order(s) (no email for the order author, missing template, or send error)';
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage agenda events (actions)
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage table ReceptionLineBatch.
Class to manage predefined suppliers products.
const STATUS_CANCELED_AFTER_ORDER
Order canceled/never received.
const STATUS_RECEIVED_PARTIALLY
Received partially.
setDeliveryDate($user, $delivery_date, $notrigger=0)
Set the planned delivery date.
updateFromCommandeClient($user, $idc, $comclientid)
Update a supplier order from a sales order.
getNomUrl($withpicto=0, $option='', $notooltip=0, $save_lastsearch_value=-1, $addlinktonotes=0)
Return clickable name (with picto eventually)
loadReceptions($filtre_statut=-1)
Load array this->receptions of lines of shipments with nb of products sent for each order line Note: ...
static replaceProduct(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a product id with another one.
$fields
'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortf...
refuse($user)
Refuse an order.
set_date_livraison($user, $delivery_date, $notrigger=0)
Set delivery date.
getKanbanView($option='', $arraydata=null)
Return clickable link of object (with eventually picto)
info($id)
Charge les information d'ordre info dans l'objet facture.
const STATUS_CANCELED
Order canceled.
fetch_lines($only_product=0)
Load array lines.
getInputMethod()
Returns the translated input method of object (defined if $this->methode_commande_id > 0).
const STATUS_VALIDATED
Validated status.
sendReminderForLateSupplierDeliveries($daysbeforeendlist='0')
Send an internal reminder by email when a supplier order's expected delivery date has passed and the ...
const STATUS_RECEIVED_COMPLETELY
Received completely.
cancel($user, $idwarehouse=-1)
Cancel an approved order.
setReopen(User $user)
Reopen supplier order.
loadStateBoard()
Load the indicators this->nb for the state board.
calcAndSetStatusDispatch(User $user, $closeopenorder=1, $comment='')
Calc status regarding to dispatched stock.
set_id_projet($user, $id_projet, $notrigger=0)
Set the id projet.
const STATUS_DRAFT
Draft status.
showDelay()
Show the customer delayed info.
updateProductBuyPrices($user)
Save the price of the predefined product lines as supplier price (with its history,...
getTooltipContentArray($params)
getTooltipContentArray
classifyUnBilled(User $user)
Classify not billed.
approve($user, $idwarehouse=0, $secondlevel=0)
Approve a supplier order.
__construct($db)
Constructor.
addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0.0, $txlocaltax2=0.0, $fk_product=0, $fk_prod_fourn_price=0, $ref_supplier='', $remise_percent=0.0, $price_base_type='HT', $pu_ttc=0.0, $type=0, $info_bits=0, $notrigger=0, $date_start=null, $date_end=null, $array_options=[], $fk_unit=null, $pu_ht_devise=0, $origin='', $origin_id=0, $rang=-1, $special_code=0, $label='')
Add order line.
dispatchProduct($user, $product, $qty, $entrepot, $price=0, $comment='', $eatby='', $sellby='', $batch='', $fk_commandefourndet=0, $notrigger=0, $fk_reception=0)
Save a receiving into the tracking table of receiving (receptiondet_batch) and add product into stock...
valid($user, $idwarehouse=0, $notrigger=0)
Validate an order.
create($user, $notrigger=0)
Create order with draft status.
update(User $user, $notrigger=0)
Update Supplier Order.
createFromClone(User $user, $socid=0, $notrigger=0)
Load an object from its id and create a new one in database.
updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $type=0, $notrigger=0, $date_start=0, $date_end=0, $array_options=[], $fk_unit=null, $pu_ht_devise=0, $ref_supplier='')
Update line.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template model.
const STATUS_ACCEPTED
Accepted.
const STATUS_ORDERSENT
Order sent, shipment on process.
commande($user, $date, $methode, $comment='')
Submit a supplier order to supplier.
hasUserPermission(User $user, $mode='write')
Check if user has a permission on supplier orders.
load_board($user, $mode='opened')
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
deleteLine($idline, $notrigger=0)
Delete line.
getObjectLinesDisplayContext()
Return the display context of the lines, as defined by the card before printObjectLines() and formAdd...
getMaxDeliveryTimeDay($langs)
Return the max number delivery delay in day.
fetch($id, $ref='')
Get object and lines from database.
Livraison($user, $date, $type, $comment)
Set a delivery in database for this supplier order.
getDispachedLines($status=-1)
Return array of dispatched lines waiting to be approved for this order.
classifyBilled(User $user)
Class invoiced the supplier order.
initAsSpecimen()
Initialise an instance with random values.
const SOURCE_ID_REPLENISHMENT
The constant used into source field to track the order was generated by the replenishement feature.
setCategories($categories)
Sets object to given categories.
setStatus($user, $status)
Tag order with a particular status.
const STATUS_REFUSED
Refused.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
getLibStatut($mode=0)
Return label of the status of object.
hasDelay()
Is the supplier order delayed? We suppose a purchase ordered as late if a the purchase order has been...
LibStatut($status, $mode=0, $billed=0)
Return label of a status.
Class to manage line orders.
Class to manage customers orders.
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...
line_order($renum=false, $rowidorder='ASC', $fk_parent_line=true)
Save a new position (field rang) for details lines.
deleteEcmFiles($mode=0)
Delete related files of object in database.
getTooltipContent($params)
getTooltipContent
update_price($exclspec=0, $roundingadjust='auto', $nodatabaseupdate=0, $seller=null)
Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines).
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
roundQtyToPackaging($qty, $packaging)
Round a quantity up to the next multiple of a packaging quantity (options PRODUCT_USE_CUSTOMER_PACKAG...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
setErrorsFromObject($object)
setErrorsFromObject
isLineOfObject($lineid)
Check that a line belongs to this object, using $this->table_element_line and $this->fk_element.
updateRangOfLine($rowid, $rang)
Update position of line (rang)
checkActiveProductInLines($status='onsale')
Check if all products have the right status (on sale, on buy) called during validation of propal,...
deleteExtraFields()
Delete all extra fields values for the current object.
fetchObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $clause='OR', $alsosametype=1, $orderby='sourcetype', $loadalsoobjects=1)
Fetch array of objects linked to current object (object of enabled modules only).
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
static commonReplaceProduct(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
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.
add_contact($fk_socpeople, $type_contact, $source='external', $notrigger=0)
Add a link between element $this->element and a contact.
Superclass for orders classes.
Class to manage Dolibarr database access.
Class to manage stock movements.
static getIdAndTxFromCode($dbs, $code, $date_document=0)
Get id and rate of currency from code.
static getIdFromCode($dbs, $code)
Get id of currency from code.
Class to manage predefined suppliers products.
Class to manage products or services.
const TYPE_SERVICE
Service.
Class to manage third parties objects (customers, suppliers, prospects...)
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...
dol_get_first_hour($date, $gm='tzserver')
Return GMT time for first hour of a given GMT date (it removes hours, min and second part)
dol_time_plus_duree($time, $duration_value, $duration_unit, $ruleforendofmonth=0, $tz='')
Add a delay to a date.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
getDolGlobalFloat($key, $default=0)
Return a Dolibarr global constant float value.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
setEntity($currentobject)
Set entity id to use when to create an object.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dol_strlen($string, $stringencoding='UTF-8', $binarycount=0)
Make a strlen call.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalBool($key, $default=false)
Return a Dolibarr global constant boolean value.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $notused, $price_base_type, $info_bits, $type, $seller=null, $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date