40require_once DOL_DOCUMENT_ROOT.
'/core/class/commonorder.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.orderline.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
44if (isModEnabled(
'productbatch')) {
45 require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
57 public $element =
'order_supplier';
62 public $table_element =
'commande_fournisseur';
67 public $table_element_line =
'commande_fournisseurdet';
72 public $class_element_line =
'CommandeFournisseurLigne';
77 public $fk_element =
'fk_commande';
82 public $picto =
'supplier_order';
88 public $restrictiononfksoc = 1;
108 public $ref_supplier;
156 public $date_approve;
162 public $date_approve2;
167 public $date_commande;
173 public $remise_percent;
177 public $methode_commande_id;
181 public $methode_commande;
186 public $delivery_date;
201 public $total_localtax1;
206 public $total_localtax2;
226 public $cond_reglement_id;
231 public $cond_reglement_code;
236 public $cond_reglement_label;
241 public $cond_reglement_doc;
251 public $mode_reglement_id;
256 public $mode_reglement_code;
261 public $mode_reglement;
266 public $user_author_id;
271 public $user_approve_id;
277 public $user_approve_id2;
287 public $extraparams = array();
292 public $lines = array();
307 public $linked_objects = array();
312 public $date_lim_reglement;
316 public $receptions = array();
322 public $fk_multicurrency;
327 public $multicurrency_code;
332 public $multicurrency_tx;
337 public $multicurrency_total_ht;
342 public $multicurrency_total_tva;
347 public $multicurrency_total_ttc;
377 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => 0,
'notnull' => 1,
'position' => 10),
378 'ref' => array(
'type' =>
'varchar(255)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => 1,
'showoncombobox' => 1,
'position' => 25,
'searchall' => 1),
379 'ref_ext' => array(
'type' =>
'varchar(255)',
'label' =>
'RefExt',
'enabled' => 1,
'visible' => 0,
'position' => 35),
380 'ref_supplier' => array(
'type' =>
'varchar(255)',
'label' =>
'RefOrderSupplierShort',
'enabled' => 1,
'visible' => 1,
'position' => 40,
'searchall' => 1),
381 'fk_projet' => array(
'type' =>
'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)',
'label' =>
'Project',
'enabled' =>
"isModEnabled('project')",
'visible' => -1,
'position' => 45),
382 'date_valid' => array(
'type' =>
'datetime',
'label' =>
'DateValidation',
'enabled' => 1,
'visible' => -1,
'position' => 710),
383 'date_approve' => array(
'type' =>
'datetime',
'label' =>
'DateApprove',
'enabled' => 1,
'visible' => -1,
'position' => 720),
384 'date_approve2' => array(
'type' =>
'datetime',
'label' =>
'DateApprove2',
'enabled' => 1,
'visible' => 3,
'position' => 725),
385 'date_commande' => array(
'type' =>
'date',
'label' =>
'OrderDateShort',
'enabled' => 1,
'visible' => 1,
'position' => 70),
386 'date_livraison' => array(
'type' =>
'datetime',
'label' =>
'DeliveryDate',
'enabled' =>
'empty($conf->global->ORDER_DISABLE_DELIVERY_DATE)',
'visible' => 1,
'position' => 74),
387 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'visible' => 3,
'position' => 41),
388 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => 3,
'notnull' => -1,
'position' => 80),
389 'fk_user_valid' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserValidation',
'enabled' => 1,
'visible' => 3,
'position' => 711),
390 'fk_user_approve' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserApproval',
'enabled' => 1,
'visible' => 3,
'position' => 721),
391 'fk_user_approve2' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserApproval2',
'enabled' => 1,
'visible' => 3,
'position' => 726),
392 'source' => array(
'type' =>
'smallint(6)',
'label' =>
'Source',
'enabled' => 1,
'visible' => 3,
'notnull' => 1,
'position' => 100),
393 'billed' => array(
'type' =>
'smallint(6)',
'label' =>
'Billed',
'enabled' => 1,
'visible' => 1,
'position' => 710),
394 'total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'AmountHT',
'enabled' => 1,
'visible' => 1,
'position' => 130,
'isameasure' => 1),
395 'total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'AmountVAT',
'enabled' => 1,
'visible' => 1,
'position' => 135,
'isameasure' => 1),
396 'localtax1' => array(
'type' =>
'double(24,8)',
'label' =>
'LT1',
'enabled' => 1,
'visible' => 3,
'position' => 140,
'isameasure' => 1),
397 'localtax2' => array(
'type' =>
'double(24,8)',
'label' =>
'LT2',
'enabled' => 1,
'visible' => 3,
'position' => 145,
'isameasure' => 1),
398 'total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'AmountTTC',
'enabled' => 1,
'visible' => -1,
'position' => 150,
'isameasure' => 1),
399 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 750,
'searchall' => 1),
400 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 760,
'searchall' => 1),
401 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'ModelPDF',
'enabled' => 1,
'visible' => 0,
'position' => 165),
402 'fk_input_method' => array(
'type' =>
'integer',
'label' =>
'OrderMode',
'enabled' => 1,
'visible' => 3,
'position' => 170),
403 'fk_cond_reglement' => array(
'type' =>
'integer',
'label' =>
'PaymentTerm',
'enabled' => 1,
'visible' => 3,
'position' => 175),
404 'fk_mode_reglement' => array(
'type' =>
'integer',
'label' =>
'PaymentMode',
'enabled' => 1,
'visible' => 3,
'position' => 180),
405 'extraparams' => array(
'type' =>
'varchar(255)',
'label' =>
'Extraparams',
'enabled' => 1,
'visible' => 0,
'position' => 190),
406 'fk_account' => array(
'type' =>
'integer',
'label' =>
'BankAccount',
'enabled' =>
'isModEnabled("bank")',
'visible' => 3,
'position' => 200),
407 'fk_incoterms' => array(
'type' =>
'integer',
'label' =>
'IncotermCode',
'enabled' => 1,
'visible' => 3,
'position' => 205),
408 'location_incoterms' => array(
'type' =>
'varchar(255)',
'label' =>
'IncotermLocation',
'enabled' => 1,
'visible' => 3,
'position' => 210),
409 'fk_multicurrency' => array(
'type' =>
'integer',
'label' =>
'Fk multicurrency',
'enabled' => 1,
'visible' => 0,
'position' => 215),
410 'multicurrency_code' => array(
'type' =>
'varchar(255)',
'label' =>
'Currency',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 220),
411 'multicurrency_tx' => array(
'type' =>
'double(24,8)',
'label' =>
'CurrencyRate',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 225),
412 'multicurrency_total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountHT',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 230),
413 'multicurrency_total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountVAT',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 235),
414 'multicurrency_total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountTTC',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 240),
415 'date_creation' => array(
'type' =>
'datetime',
'label' =>
'Date creation',
'enabled' => 1,
'visible' => -1,
'position' => 500),
416 'fk_soc' => array(
'type' =>
'integer:Societe:societe/class/societe.class.php',
'label' =>
'ThirdParty',
'enabled' =>
'isModEnabled("societe")',
'visible' => 1,
'notnull' => 1,
'position' => 50),
417 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => 0,
'notnull' => 1,
'position' => 1000,
'index' => 1),
418 'tms' => array(
'type' =>
'datetime',
'label' =>
"DateModificationShort",
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 501),
419 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'LastMainDoc',
'enabled' => 1,
'visible' => 0,
'position' => 700),
420 'fk_statut' => array(
'type' =>
'smallint(6)',
'label' =>
'Status',
'enabled' => 1,
'visible' => 1,
'position' => 701),
421 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => 0,
'position' => 900),
485 $this->ismultientitymanaged = 1;
496 public function fetch($id, $ref =
'')
499 if (empty($id) && empty($ref)) {
503 $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,";
504 $sql .=
" c.localtax1, c.localtax2, ";
505 $sql .=
" c.date_creation, c.date_valid, c.date_approve, c.date_approve2,";
506 $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,";
507 $sql .=
" c.date_commande as date_commande, c.date_livraison as delivery_date, c.fk_cond_reglement, c.fk_mode_reglement, c.fk_projet as fk_project, c.remise_percent, c.source, c.fk_input_method,";
508 $sql .=
" c.fk_account,";
509 $sql .=
" c.note_private, c.note_public, c.model_pdf, c.extraparams, c.billed,";
510 $sql .=
" c.fk_multicurrency, c.multicurrency_code, c.multicurrency_tx, c.multicurrency_total_ht, c.multicurrency_total_tva, c.multicurrency_total_ttc,";
511 $sql .=
" cm.libelle as methode_commande,";
512 $sql .=
" cr.code as cond_reglement_code, cr.libelle as cond_reglement_label, cr.libelle_facture as cond_reglement_doc,";
513 $sql .=
" p.code as mode_reglement_code, p.libelle as mode_reglement_libelle";
514 $sql .=
', c.fk_incoterms, c.location_incoterms';
515 $sql .=
', c.last_main_doc';
516 $sql .=
', i.libelle as label_incoterms';
517 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as c";
518 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_payment_term as cr ON c.fk_cond_reglement = cr.rowid";
519 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_paiement as p ON c.fk_mode_reglement = p.id";
520 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_input_method as cm ON cm.rowid = c.fk_input_method";
521 $sql .=
' LEFT JOIN '.$this->db->prefix().
'c_incoterms as i ON c.fk_incoterms = i.rowid';
524 $sql .=
" WHERE c.entity IN (".getEntity(
'supplier_order').
")";
526 $sql .=
" WHERE c.rowid=".((int) $id);
530 $sql .=
" AND c.ref='".$this->db->escape($ref).
"'";
533 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
534 $resql = $this->db->query($sql);
536 $obj = $this->db->fetch_object($resql);
538 $this->error =
'Bill with id '.$id.
' not found';
539 dol_syslog(get_class($this).
'::fetch '.$this->error);
543 $this->
id = $obj->rowid;
544 $this->entity = $obj->entity;
546 $this->
ref = $obj->ref;
547 $this->ref_supplier = $obj->ref_supplier;
549 $this->socid = $obj->fk_soc;
550 $this->thirdparty =
null;
552 $this->fourn_id = $obj->fk_soc;
553 $this->statut = $obj->status;
554 $this->
status = $obj->status;
555 $this->billed = $obj->billed;
556 $this->last_main_doc = $obj->last_main_doc;
557 $this->user_author_id = $obj->user_author_id;
558 $this->user_validation_id = $obj->user_validation_id;
559 $this->user_approve_id = $obj->user_approve_id;
560 $this->user_approve_id2 = $obj->user_approve_id2;
561 $this->total_ht = $obj->total_ht;
562 $this->total_tva = $obj->total_tva;
563 $this->total_localtax1 = $obj->localtax1;
564 $this->total_localtax2 = $obj->localtax2;
565 $this->total_ttc = $obj->total_ttc;
566 $this->date_creation = $this->db->jdate($obj->date_creation);
567 $this->date_valid = $this->db->jdate($obj->date_valid);
568 $this->date_approve = $this->db->jdate($obj->date_approve);
569 $this->date_approve2 = $this->db->jdate($obj->date_approve2);
570 $this->date_commande = $this->db->jdate($obj->date_commande);
571 if (isset($obj->date_commande)) {
572 $this->date = $this->date_commande;
574 $this->date = $this->date_creation;
576 $this->delivery_date = $this->db->jdate($obj->delivery_date);
577 $this->remise_percent = $obj->remise_percent;
578 $this->methode_commande_id = $obj->fk_input_method;
579 $this->methode_commande = $obj->methode_commande;
581 $this->source = $obj->source;
582 $this->fk_project = $obj->fk_project;
583 $this->cond_reglement_id = $obj->fk_cond_reglement;
584 $this->cond_reglement_code = $obj->cond_reglement_code;
585 $this->cond_reglement = $obj->cond_reglement_label;
586 $this->cond_reglement_label = $obj->cond_reglement_label;
587 $this->cond_reglement_doc = $obj->cond_reglement_doc;
588 $this->fk_account = $obj->fk_account;
589 $this->mode_reglement_id = $obj->fk_mode_reglement;
590 $this->mode_reglement_code = $obj->mode_reglement_code;
591 $this->mode_reglement = $obj->mode_reglement_libelle;
592 $this->note = $obj->note_private;
593 $this->note_private = $obj->note_private;
594 $this->note_public = $obj->note_public;
595 $this->model_pdf = $obj->model_pdf;
598 $this->fk_incoterms = $obj->fk_incoterms;
599 $this->location_incoterms = $obj->location_incoterms;
600 $this->label_incoterms = $obj->label_incoterms;
603 $this->fk_multicurrency = $obj->fk_multicurrency;
604 $this->multicurrency_code = $obj->multicurrency_code;
605 $this->multicurrency_tx = $obj->multicurrency_tx;
606 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
607 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
608 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
610 $this->extraparams = isset($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
612 $this->db->free($resql);
627 $this->error = $this->db->error().
" sql=".$sql;
643 $this->lines = array();
645 $sql =
"SELECT l.rowid, l.fk_commande, l.ref as ref_supplier, l.fk_product, l.product_type, l.label, l.description, l.qty,";
646 $sql .=
" l.vat_src_code, l.tva_tx, l.remise_percent, l.subprice,";
647 $sql .=
" l.localtax1_tx, l. localtax2_tx, l.localtax1_type, l. localtax2_type, l.total_localtax1, l.total_localtax2,";
648 $sql .=
" l.total_ht, l.total_tva, l.total_ttc, l.info_bits, l.special_code, l.fk_parent_line, l.rang,";
649 $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,";
650 $sql .=
" l.fk_unit,";
651 $sql .=
" l.date_start, l.date_end,";
652 $sql .=
' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc';
653 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseurdet as l";
654 $sql .=
' LEFT JOIN '.$this->db->prefix().
'product as p ON l.fk_product = p.rowid';
655 $sql .=
" WHERE l.fk_commande = ".((int) $this->
id);
657 $sql .=
' AND p.fk_product_type = 0';
659 $sql .=
" ORDER BY l.rang, l.rowid";
662 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
664 $result = $this->db->query($sql);
666 $num = $this->db->num_rows($result);
670 $objp = $this->db->fetch_object($result);
674 $line->id = $objp->rowid;
675 $line->fk_commande = $objp->fk_commande;
676 $line->desc = $objp->description;
677 $line->description = $objp->description;
678 $line->qty = $objp->qty;
679 $line->tva_tx = $objp->tva_tx;
680 $line->localtax1_tx = $objp->localtax1_tx;
681 $line->localtax2_tx = $objp->localtax2_tx;
682 $line->localtax1_type = $objp->localtax1_type;
683 $line->localtax2_type = $objp->localtax2_type;
684 $line->subprice = $objp->subprice;
685 $line->pu_ht = $objp->subprice;
686 $line->remise_percent = $objp->remise_percent;
688 $line->vat_src_code = $objp->vat_src_code;
689 $line->total_ht = $objp->total_ht;
690 $line->total_tva = $objp->total_tva;
691 $line->total_localtax1 = $objp->total_localtax1;
692 $line->total_localtax2 = $objp->total_localtax2;
693 $line->total_ttc = $objp->total_ttc;
694 $line->product_type = $objp->product_type;
696 $line->fk_product = $objp->fk_product;
698 $line->libelle = $objp->product_label;
699 $line->product_label = $objp->product_label;
700 $line->product_desc = $objp->product_desc;
701 $line->product_tobatch = $objp->product_tobatch;
702 $line->product_barcode = $objp->product_barcode;
704 $line->ref = $objp->product_ref;
705 $line->product_ref = $objp->product_ref;
706 $line->ref_fourn = $objp->ref_supplier;
707 $line->ref_supplier = $objp->ref_supplier;
714 $sqlsearchpackage =
'SELECT rowid, packaging FROM '.$this->db->prefix().
"product_fournisseur_price";
715 $sqlsearchpackage .=
' WHERE entity IN ('.getEntity(
'product_fournisseur_price').
")";
716 $sqlsearchpackage .=
" AND fk_product = ".((int) $objp->fk_product);
717 $sqlsearchpackage .=
" AND ref_fourn = '".$this->db->escape($objp->ref_supplier).
"'";
718 $sqlsearchpackage .=
" AND quantity <= ".((float) $objp->qty);
719 $sqlsearchpackage .=
" AND (packaging IS NULL OR packaging = 0 OR packaging <= ".((float) $objp->qty).
")";
720 $sqlsearchpackage .=
" AND fk_soc = ".((int) $this->socid);
721 $sqlsearchpackage .=
" ORDER BY packaging ASC";
722 $sqlsearchpackage .=
" LIMIT 1";
724 $resqlsearchpackage = $this->db->query($sqlsearchpackage);
725 if ($resqlsearchpackage) {
726 $objsearchpackage = $this->db->fetch_object($resqlsearchpackage);
727 if ($objsearchpackage) {
728 $line->fk_fournprice = $objsearchpackage->rowid;
729 $line->packaging = $objsearchpackage->packaging;
732 $this->error = $this->db->lasterror();
737 $line->date_start = $this->db->jdate($objp->date_start);
738 $line->date_end = $this->db->jdate($objp->date_end);
739 $line->fk_unit = $objp->fk_unit;
742 $line->fk_multicurrency = $objp->fk_multicurrency;
743 $line->multicurrency_code = $objp->multicurrency_code;
744 $line->multicurrency_subprice = $objp->multicurrency_subprice;
745 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
746 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
747 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
749 $line->info_bits = $objp->info_bits;
750 $line->special_code = $objp->special_code;
751 $line->fk_parent_line = $objp->fk_parent_line;
753 $line->rang = $objp->rang;
757 $line->fetch_optionals();
759 $this->lines[$i] = $line;
763 $this->db->free($result);
767 $this->error = $this->db->error().
" sql=".$sql;
780 public function valid($user, $idwarehouse = 0, $notrigger = 0)
783 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
789 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")))
790 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"fournisseur",
"supplier_order_advance",
"validate"))) {
795 $soc->fetch($this->fourn_id);
798 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
799 $num = $this->getNextNumRef($soc);
805 $sql =
'UPDATE '.$this->db->prefix().
"commande_fournisseur";
806 $sql .=
" SET ref='".$this->db->escape($num).
"',";
807 $sql .=
" fk_statut = ".((int) self::STATUS_VALIDATED).
",";
808 $sql .=
" date_valid='".$this->db->idate(
dol_now()).
"',";
809 $sql .=
" fk_user_valid = ".((int) $user->id);
810 $sql .=
" WHERE rowid = ".((int) $this->
id);
811 $sql .=
" AND fk_statut = ".((int) self::STATUS_DRAFT);
813 $resql = $this->db->query($sql);
819 if (!$error && !$notrigger) {
821 $result = $this->
call_trigger(
'ORDER_SUPPLIER_VALIDATE', $user);
829 $this->oldref = $this->ref;
832 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
834 $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).
"'";
835 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'fournisseur/commande/".$this->db->escape($this->
ref).
"' and entity = ".((int)
$conf->entity);
836 $resql = $this->db->query($sql);
839 $this->error = $this->db->lasterror();
841 $sql =
'UPDATE '.$this->db->prefix().
"ecm_files set filepath = 'fournisseur/commande/".$this->db->escape($this->newref).
"'";
842 $sql .=
" WHERE filepath = 'fournisseur/commande/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
843 $resql = $this->db->query($sql);
846 $this->error = $this->db->lasterror();
852 $dirsource =
$conf->fournisseur->commande->dir_output.
'/'.$oldref;
853 $dirdest =
$conf->fournisseur->commande->dir_output.
'/'.$newref;
854 if (!$error && file_exists($dirsource)) {
855 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
857 if (@rename($dirsource, $dirdest)) {
860 $listoffiles =
dol_dir_list(
$conf->fournisseur->commande->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
861 foreach ($listoffiles as $fileentry) {
862 $dirsource = $fileentry[
'name'];
863 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
864 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
865 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
866 @rename($dirsource, $dirdest);
884 $this->db->rollback();
888 $this->error =
'NotAuthorized';
889 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
914 public function LibStatut($status, $mode = 0, $billed = 0)
917 global $langs, $hookmanager;
919 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
920 $langs->load(
'orders');
922 $this->labelStatus[0] =
'StatusSupplierOrderDraft';
923 $this->labelStatus[1] =
'StatusSupplierOrderValidated';
924 $this->labelStatus[2] =
'StatusSupplierOrderApproved';
926 $this->labelStatus[3] =
'StatusSupplierOrderOnProcess';
928 $this->labelStatus[3] =
'StatusSupplierOrderOnProcessWithValidation';
930 $this->labelStatus[4] =
'StatusSupplierOrderReceivedPartially';
931 $this->labelStatus[5] =
'StatusSupplierOrderReceivedAll';
932 $this->labelStatus[6] =
'StatusSupplierOrderCanceled';
933 $this->labelStatus[7] =
'StatusSupplierOrderCanceled';
934 $this->labelStatus[9] =
'StatusSupplierOrderRefused';
937 $this->labelStatusShort[0] =
'StatusSupplierOrderDraftShort';
938 $this->labelStatusShort[1] =
'StatusSupplierOrderValidatedShort';
939 $this->labelStatusShort[2] =
'StatusSupplierOrderApprovedShort';
940 $this->labelStatusShort[3] =
'StatusSupplierOrderOnProcessShort';
941 $this->labelStatusShort[4] =
'StatusSupplierOrderReceivedPartiallyShort';
942 $this->labelStatusShort[5] =
'StatusSupplierOrderReceivedAllShort';
943 $this->labelStatusShort[6] =
'StatusSupplierOrderCanceledShort';
944 $this->labelStatusShort[7] =
'StatusSupplierOrderCanceledShort';
945 $this->labelStatusShort[9] =
'StatusSupplierOrderRefusedShort';
948 $statustrans = array(
960 $statusClass =
'status0';
961 if (!empty($statustrans[$status])) {
962 $statusClass = $statustrans[$status];
967 $billedtext =
' - '.$langs->trans(
"Billed");
969 if ($status == 5 && $billed) {
970 $statusClass =
'status6';
973 $statusLong = $langs->transnoentitiesnoconv($this->labelStatus[$status]).$billedtext;
974 $statusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
976 $parameters = array(
'status' => $status,
'mode' => $mode,
'billed' => $billed);
977 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
979 return $hookmanager->resPrint;
982 return dolGetStatus($statusLong, $statusShort,
'', $statusClass, $mode);
993 global
$conf, $langs, $user;
995 $langs->loadLangs([
'bills',
'orders']);
998 $nofetch = !empty($params[
'nofetch']);
1000 if ($user->hasRight(
"fournisseur",
"commande",
"read")) {
1001 $datas[
'picto'] =
'<u class="paddingrightonly">'.$langs->trans(
"SupplierOrder").
'</u>';
1003 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
1005 if (!empty($this->
ref)) {
1006 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1008 if (!empty($this->ref_supplier)) {
1009 $datas[
'refsupplier'] =
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.$this->ref_supplier;
1012 $langs->load(
'companies');
1013 if (empty($this->thirdparty)) {
1016 $datas[
'supplier'] =
'<br><b>'.$langs->trans(
'Supplier').
':</b> '.$this->thirdparty->getNomUrl(1,
'', 0, 1);
1018 if (!empty($this->total_ht)) {
1019 $datas[
'totalht'] =
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1,
$conf->currency);
1021 if (!empty($this->total_tva)) {
1022 $datas[
'totaltva'] =
'<br><b>'.$langs->trans(
'VAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1,
$conf->currency);
1024 if (!empty($this->total_ttc)) {
1025 $datas[
'totalttc'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency);
1027 if (!empty($this->date)) {
1028 $datas[
'date'] =
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->date,
'day');
1030 if (!empty($this->delivery_date)) {
1031 $datas[
'deliverydate'] =
'<br><b>'.$langs->trans(
'DeliveryDate').
':</b> '.
dol_print_date($this->delivery_date,
'dayhour');
1047 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = 0)
1049 global $langs, $user, $hookmanager;
1054 'objecttype' => $this->element,
1055 'option' => $option,
1058 $classfortooltip =
'classfortooltip';
1061 $classfortooltip =
'classforajaxtooltip';
1062 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1068 $url = DOL_URL_ROOT.
'/fourn/commande/card.php?id='.$this->id;
1070 if ($option !==
'nolink') {
1072 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1073 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1074 $add_save_lastsearch_values = 1;
1076 if ($add_save_lastsearch_values) {
1077 $url .=
'&save_lastsearch_values=1';
1082 if (empty($notooltip)) {
1084 $label = $langs->trans(
"ShowOrder");
1085 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1087 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1088 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
1091 $linkstart =
'<a href="'.$url.
'"';
1092 $linkstart .= $linkclose.
'>';
1095 $result .= $linkstart;
1097 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
1099 if ($withpicto != 2) {
1100 $result .= $this->ref;
1102 $result .= $linkend;
1104 if ($addlinktonotes) {
1105 $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
1108 $result .=
' <span class="note inline-block">';
1109 $result .=
'<a href="'.DOL_URL_ROOT.
'/fourn/commande/note.php?id='.$this->
id.
'" class="classfortooltip" title="'.
dol_escape_htmltag($notetoshow).
'">';
1114 $result .=
'</span>';
1119 $hookmanager->initHooks(array($this->element .
'dao'));
1120 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1121 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1123 $result = $hookmanager->resPrint;
1125 $result .= $hookmanager->resPrint;
1138 public function getNextNumRef($soc)
1140 global $langs,
$conf;
1141 $langs->load(
"orders");
1150 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
1152 foreach ($dirmodels as $reldir) {
1153 $dir =
dol_buildpath($reldir.
"core/modules/supplier_order/");
1156 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1164 $obj =
new $classname();
1165 '@phan-var-force ModeleNumRefSuppliersOrders $obj';
1167 $numref = $obj->getNextValue($soc, $this);
1169 if ($numref !=
"") {
1172 $this->error = $obj->error;
1176 $this->error =
"Error_COMMANDE_SUPPLIER_ADDON_NotDefined";
1191 if ($this->billed) {
1197 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur SET billed = 1';
1200 if ($this->db->query($sql)) {
1203 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CLASSIFY_BILLED', $user);
1213 $this->db->commit();
1216 $this->db->rollback();
1222 $this->db->rollback();
1236 if (empty($this->billed)) {
1242 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur SET billed = 0';
1246 if (!$this->db->query($sql)) {
1248 $this->db->rollback();
1253 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CLASSIFY_UNBILLED', $user);
1255 $this->db->rollback();
1261 $this->db->commit();
1274 public function approve($user, $idwarehouse = 0, $secondlevel = 0)
1276 global $langs,
$conf;
1277 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1283 if ($user->hasRight(
"fournisseur",
"commande",
"approuver")) {
1289 $soc =
new Societe($this->db);
1290 $soc->fetch($this->fourn_id);
1293 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
1294 $num = $this->getNextNumRef($soc);
1301 $movetoapprovestatus =
true;
1304 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1305 $sql .=
" SET ref='".$this->db->escape($num).
"',";
1306 if (empty($secondlevel)) {
1307 $sql .=
" date_approve='".$this->db->idate($now).
"',";
1308 $sql .=
" fk_user_approve = ".((int) $user->id);
1310 if (empty($this->user_approve_id2)) {
1311 $movetoapprovestatus =
false;
1312 $comment =
' (first level)';
1316 $sql .=
" date_approve2='".$this->db->idate($now).
"',";
1317 $sql .=
" fk_user_approve2 = ".((int) $user->id);
1318 if (empty($this->user_approve_id)) {
1319 $movetoapprovestatus =
false;
1321 $comment =
' (second level)';
1324 if ($movetoapprovestatus) {
1325 $sql .=
", fk_statut = ".self::STATUS_ACCEPTED;
1327 $sql .=
", fk_statut = ".self::STATUS_VALIDATED;
1329 $sql .=
" WHERE rowid = ".((int) $this->
id);
1330 $sql .=
" AND fk_statut = ".self::STATUS_VALIDATED;
1332 if ($this->db->query($sql)) {
1334 $result = $this->
add_contact($user->id,
'SALESREPFOLL',
'internal', 1);
1335 if ($result < 0 && $result != -2) {
1341 if (!$error && $movetoapprovestatus && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER')) {
1342 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1343 $langs->load(
"agenda");
1345 $cpt = count($this->lines);
1346 for ($i = 0; $i < $cpt; $i++) {
1348 if ($this->lines[$i]->fk_product > 0) {
1349 $this->line = $this->lines[$i];
1351 $mouvP->origin = &$this;
1352 $mouvP->setOrigin($this->element, $this->
id);
1354 $up_ht_disc = $this->lines[$i]->subprice;
1355 if (!empty($this->lines[$i]->remise_percent) && !
getDolGlobalString(
'STOCK_EXCLUDE_DISCOUNT_FOR_PMP')) {
1356 $up_ht_disc =
price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100,
'MU');
1358 $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans(
"OrderApprovedInDolibarr", $this->ref));
1369 $result = $this->
call_trigger(
'ORDER_SUPPLIER_APPROVE', $user);
1377 $this->
ref = $this->newref;
1379 if ($movetoapprovestatus) {
1384 if (empty($secondlevel)) {
1385 $this->date_approve = $now;
1386 $this->user_approve_id = $user->id;
1388 $this->date_approve2 = $now;
1389 $this->user_approve_id2 = $user->id;
1392 $this->db->commit();
1395 $this->db->rollback();
1399 $this->db->rollback();
1400 $this->error = $this->db->lasterror();
1404 dol_syslog(get_class($this).
"::approve Not Authorized", LOG_ERR);
1417 global
$conf, $langs;
1423 if ($user->hasRight(
"fournisseur",
"commande",
"approuver")) {
1426 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur SET fk_statut = ".
self::STATUS_REFUSED;
1427 $sql .=
" WHERE rowid = ".((int) $this->
id);
1429 if ($this->db->query($sql)) {
1434 $result = $this->
call_trigger(
'ORDER_SUPPLIER_REFUSE', $user);
1437 $this->db->rollback();
1439 $this->db->commit();
1444 $this->db->rollback();
1445 $this->error = $this->db->lasterror();
1446 dol_syslog(get_class($this).
"::refuse Error -1");
1450 dol_syslog(get_class($this).
"::refuse Not Authorized");
1464 public function Cancel($user, $idwarehouse = -1)
1467 global $langs,
$conf;
1473 if ($user->hasRight(
"fournisseur",
"commande",
"commander")) {
1478 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur SET fk_statut = ".((int) $statut);
1479 $sql .=
" WHERE rowid = ".((int) $this->
id);
1480 dol_syslog(get_class($this).
"::cancel", LOG_DEBUG);
1481 if ($this->db->query($sql)) {
1485 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CANCEL', $user);
1492 $this->db->commit();
1495 $this->db->rollback();
1499 $this->db->rollback();
1500 $this->error = $this->db->lasterror();
1501 dol_syslog(get_class($this).
"::cancel ".$this->error);
1505 dol_syslog(get_class($this).
"::cancel Not Authorized");
1519 public function commande($user, $date, $methode, $comment =
'')
1524 if ($user->hasRight(
"fournisseur",
"commande",
"commander")) {
1527 $newnoteprivate = $this->note_private;
1529 $newnoteprivate =
dol_concatdesc($newnoteprivate, $langs->trans(
"Comment").
': '.$comment);
1532 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1533 $sql .=
" SET fk_statut=".self::STATUS_ORDERSENT.
", fk_input_method=".$methode.
", date_commande='".$this->db->idate($date).
"', ";
1534 $sql .=
" note_private='".$this->db->escape($newnoteprivate).
"'";
1535 $sql .=
" WHERE rowid=".((int) $this->
id);
1537 dol_syslog(get_class($this).
"::commande", LOG_DEBUG);
1538 if ($this->db->query($sql)) {
1540 $this->methode_commande_id = $methode;
1541 $this->date_commande = $date;
1542 $this->context = array(
'comments' => $comment);
1545 $result = $this->
call_trigger(
'ORDER_SUPPLIER_SUBMIT', $user);
1552 $this->error = $this->db->lasterror();
1553 $this->errors[] = $this->db->lasterror();
1557 $this->db->commit();
1559 $this->db->rollback();
1563 $this->error = $langs->trans(
'NotAuthorized');
1564 $this->errors[] = $langs->trans(
'NotAuthorized');
1565 dol_syslog(get_class($this).
"::commande User not Authorized", LOG_WARNING);
1568 return ($error ? -1 : 1);
1578 public function create($user, $notrigger = 0)
1580 global $langs,
$conf, $hookmanager;
1588 $date = ($this->date_commande ? $this->date_commande : $this->date);
1592 $delivery_date = $this->delivery_date;
1595 if (empty($this->source)) {
1600 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
1605 if (empty($this->fk_multicurrency)) {
1606 $this->multicurrency_code =
$conf->currency;
1607 $this->fk_multicurrency = 0;
1608 $this->multicurrency_tx = 1;
1616 $sql =
"INSERT INTO ".$this->db->prefix().
"commande_fournisseur (";
1618 $sql .=
", ref_supplier";
1619 $sql .=
", note_private";
1620 $sql .=
", note_public";
1623 $sql .=
", fk_projet";
1624 $sql .=
", date_creation";
1625 $sql .=
", date_livraison";
1626 $sql .=
", fk_user_author";
1627 $sql .=
", fk_statut";
1629 $sql .=
", model_pdf";
1630 $sql .=
", fk_mode_reglement";
1631 $sql .=
", fk_cond_reglement";
1632 $sql .=
", fk_account";
1633 $sql .=
", fk_incoterms, location_incoterms";
1634 $sql .=
", fk_multicurrency";
1635 $sql .=
", multicurrency_code";
1636 $sql .=
", multicurrency_tx";
1638 $sql .=
" VALUES (";
1640 $sql .=
", ".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"NULL");
1641 $sql .=
", '".$this->db->escape($this->note_private).
"'";
1642 $sql .=
", '".$this->db->escape($this->note_public).
"'";
1643 $sql .=
", ".((int) $this->entity);
1644 $sql .=
", ".((int) $this->socid);
1645 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
1646 $sql .=
", '".$this->db->idate($date).
"'";
1647 $sql .=
", ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
"null");
1648 $sql .=
", ".((int) $user->id);
1649 $sql .=
", ".self::STATUS_DRAFT;
1650 $sql .=
", ".((int) $this->source);
1651 $sql .=
", '".$this->db->escape(
getDolGlobalString(
'COMMANDE_SUPPLIER_ADDON_PDF')).
"'";
1652 $sql .=
", ".($this->mode_reglement_id > 0 ? $this->mode_reglement_id :
'null');
1653 $sql .=
", ".($this->cond_reglement_id > 0 ? $this->cond_reglement_id :
'null');
1654 $sql .=
", ".($this->fk_account > 0 ? $this->fk_account :
'NULL');
1655 $sql .=
", ".(int) $this->fk_incoterms;
1656 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
1657 $sql .=
", ".(int) $this->fk_multicurrency;
1658 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1659 $sql .=
", ".(float) $this->multicurrency_tx;
1662 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1663 if ($this->db->query($sql)) {
1664 $this->
id = $this->db->last_insert_id($this->db->prefix().
"commande_fournisseur");
1667 $num = count($this->lines);
1670 for ($i = 0; $i < $num; $i++) {
1671 $line = $this->lines[$i];
1672 if (!is_object($line)) {
1673 $line = (object) $line;
1684 $line->localtax1_tx,
1685 $line->localtax2_tx,
1689 $line->remise_percent,
1692 $line->product_type,
1697 $line->array_options,
1699 $line->multicurrency_subprice,
1706 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
1707 $this->db->rollback();
1712 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1713 $sql .=
" SET ref='(PROV".$this->id.
")'";
1714 $sql .=
" WHERE rowid=".((int) $this->
id);
1716 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1717 if ($this->db->query($sql)) {
1720 $this->
ref =
"(PROV".$this->id.
")";
1722 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
1723 $this->linked_objects = $this->linkedObjectsIds;
1727 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
1728 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
1729 if (is_array($tmp_origin_id)) {
1730 foreach ($tmp_origin_id as $origin_id) {
1738 $origin_id = $tmp_origin_id;
1756 if (!$error && !$notrigger) {
1758 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CREATE', $user);
1760 $this->db->rollback();
1767 $this->db->commit();
1770 $this->error = $this->db->lasterror();
1771 $this->db->rollback();
1776 $this->error =
'Failed to get ID of inserted line';
1781 $this->error = $this->db->lasterror();
1782 $this->db->rollback();
1802 if (isset($this->
ref)) {
1803 $this->
ref = trim($this->
ref);
1805 if (isset($this->ref_supplier)) {
1806 $this->ref_supplier = trim($this->ref_supplier);
1808 if (isset($this->note_private)) {
1809 $this->note_private = trim($this->note_private);
1811 if (isset($this->note_public)) {
1812 $this->note_public = trim($this->note_public);
1814 if (isset($this->model_pdf)) {
1815 $this->model_pdf = trim($this->model_pdf);
1817 if (isset($this->import_key)) {
1818 $this->import_key = trim($this->import_key);
1822 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
1824 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1825 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
1826 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1827 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
1828 $sql .=
" date_commande=".(strval($this->date_commande) !=
'' ?
"'".$this->db->idate($this->date_commande).
"'" :
'null').
",";
1829 $sql .=
" date_valid=".(strval($this->date_validation) !=
'' ?
"'".$this->db->idate($this->date_validation).
"'" :
'null').
",";
1830 $sql .=
" total_tva=".(isset($this->total_tva) ? $this->total_tva :
"null").
",";
1831 $sql .=
" localtax1=".(isset($this->total_localtax1) ? $this->total_localtax1 :
"null").
",";
1832 $sql .=
" localtax2=".(isset($this->total_localtax2) ? $this->total_localtax2 :
"null").
",";
1833 $sql .=
" total_ht=".(isset($this->total_ht) ? $this->total_ht :
"null").
",";
1834 $sql .=
" total_ttc=".(isset($this->total_ttc) ? $this->total_ttc :
"null").
",";
1835 $sql .=
" fk_statut=".(isset($this->statut) ? $this->statut :
"null").
",";
1836 $sql .=
" fk_user_author=".(isset($this->user_author_id) ? $this->user_author_id :
"null").
",";
1837 $sql .=
" fk_user_valid=".(isset($this->user_validation_id) && $this->user_validation_id > 0 ? $this->user_validation_id :
"null").
",";
1838 $sql .=
" fk_projet=".(isset($this->fk_project) ? $this->fk_project :
"null").
",";
1839 $sql .=
" fk_cond_reglement=".(isset($this->cond_reglement_id) ? $this->cond_reglement_id :
"null").
",";
1840 $sql .=
" fk_mode_reglement=".(isset($this->mode_reglement_id) ? $this->mode_reglement_id :
"null").
",";
1841 $sql .=
" date_livraison=".(strval($this->delivery_date) !=
'' ?
"'".$this->db->idate($this->delivery_date).
"'" :
'null').
",";
1843 $sql .=
" fk_account=".($this->fk_account > 0 ? $this->fk_account :
"null").
",";
1845 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1846 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1847 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1848 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
1850 $sql .=
" WHERE rowid=".((int) $this->
id);
1854 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1855 $resql = $this->db->query($sql);
1858 $this->errors[] =
"Error ".$this->db->lasterror();
1868 if (!$error && !$notrigger) {
1870 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
1879 foreach ($this->errors as $errmsg) {
1880 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1881 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1883 $this->db->rollback();
1886 $this->db->commit();
1901 global
$conf, $user, $hookmanager;
1908 foreach ($this->lines as $line) {
1909 $line->fetch_optionals();
1913 $objFrom = clone $this;
1916 if (!empty($socid) && $socid != $this->socid) {
1917 $objsoc =
new Societe($this->db);
1919 if ($objsoc->fetch($socid) > 0) {
1920 $this->socid = $objsoc->id;
1921 $this->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1922 $this->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1923 $this->fk_project = 0;
1924 $this->fk_delivery_address = 0;
1934 $this->user_author_id = $user->id;
1935 $this->user_validation_id = 0;
1938 $this->date_creation = 0;
1939 $this->date_validation = 0;
1940 $this->date_commande = 0;
1941 $this->ref_supplier =
'';
1942 $this->user_approve_id = 0;
1943 $this->user_approve_id2 = 0;
1944 $this->date_approve = 0;
1945 $this->date_approve2 = 0;
1948 $this->context[
'createfromclone'] =
'createfromclone';
1949 $result = $this->
create($user, $notrigger);
1956 if (is_object($hookmanager)) {
1957 $parameters = array(
'objFrom' => $objFrom);
1959 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1967 unset($this->context[
'createfromclone']);
1971 $this->db->commit();
1974 $this->db->rollback();
2008 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)
2010 global $langs, $mysoc;
2012 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");
2013 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2015 if ($this->statut == self::STATUS_DRAFT) {
2016 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2025 if (empty($txtva)) {
2031 if (empty($txlocaltax1)) {
2034 if (empty($txlocaltax2)) {
2037 if (empty($remise_percent)) {
2038 $remise_percent = 0;
2041 $remise_percent =
price2num($remise_percent);
2044 $pu_ht_devise =
price2num($pu_ht_devise);
2046 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
2051 if ($price_base_type ==
'HT') {
2056 $desc = trim($desc);
2059 if ($qty < 0 && !$fk_product) {
2060 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Product"));
2066 if ($date_start && $date_end && $date_start > $date_end) {
2067 $langs->load(
"errors");
2068 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
2075 $product_type = $type;
2078 if ($fk_product > 0) {
2079 if (
getDolGlobalInt(
'SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY') == 1) {
2081 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);
2083 if ($prod->fetch($fk_product) > 0) {
2084 $product_type = $prod->type;
2085 $label = $prod->label;
2089 $result = $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', (isset($this->fk_soc) ? $this->fk_soc : $this->socid));
2093 if ($result > 0 && ($origin ==
'commande' || $pu ===
'')) {
2094 $pu = $prod->fourn_pu;
2095 $ref_supplier = $prod->ref_supplier;
2097 if ($remise_percent == 0 && $prod->remise_percent != 0) {
2098 $remise_percent = $prod->remise_percent;
2102 $langs->load(
"errors");
2103 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
2104 $this->db->rollback();
2105 dol_syslog(get_class($this).
"::addline we did not found supplier price, so we can't guess unit price");
2110 if ($result == -1) {
2111 $langs->load(
"errors");
2112 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
2113 $this->db->rollback();
2114 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_DEBUG);
2118 $this->error = $prod->error;
2119 $this->db->rollback();
2120 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_ERR);
2124 $this->error = $prod->error;
2125 $this->db->rollback();
2132 $prod =
new Product($this->db);
2133 $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', (empty($this->fk_soc) ? $this->socid : $this->fk_soc));
2135 if ($qty < $prod->packaging) {
2136 $qty = $prod->packaging;
2138 if (!empty($prod->packaging) && (fmod((
float) $qty, $prod->packaging) > 0.000001)) {
2139 $coeff = intval((
float) $qty / $prod->packaging) + 1;
2140 $qty = (float) $prod->packaging * $coeff;
2141 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'mesgs');
2147 if (isModEnabled(
"multicurrency") && $pu_ht_devise > 0) {
2156 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
2157 $vat_src_code = $reg[1];
2158 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
2166 $tabprice =
calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise);
2168 $total_ht = $tabprice[0];
2169 $total_tva = $tabprice[1];
2170 $total_ttc = $tabprice[2];
2171 $total_localtax1 = $tabprice[9];
2172 $total_localtax2 = $tabprice[10];
2173 $pu = $pu_ht = $tabprice[3];
2176 $multicurrency_total_ht = $tabprice[16];
2177 $multicurrency_total_tva = $tabprice[17];
2178 $multicurrency_total_ttc = $tabprice[18];
2179 $pu_ht_devise = $tabprice[19];
2181 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2182 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2186 $rang = $rangmax + 1;
2192 $this->line->context = $this->context;
2194 $this->line->fk_commande = $this->id;
2195 $this->line->label = $label;
2196 $this->line->ref_fourn = $ref_supplier;
2197 $this->line->ref_supplier = $ref_supplier;
2198 $this->line->desc = $desc;
2199 $this->line->qty = $qty;
2200 $this->line->tva_tx = $txtva;
2201 $this->line->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0);
2202 $this->line->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0);
2203 $this->line->localtax1_type = $localtax1_type;
2204 $this->line->localtax2_type = $localtax2_type;
2205 $this->line->fk_product = $fk_product;
2206 $this->line->product_type = $product_type;
2207 $this->line->remise_percent = $remise_percent;
2208 $this->line->subprice = (float) $pu_ht;
2209 $this->line->rang = $rang;
2210 $this->line->info_bits = $info_bits;
2212 $this->line->vat_src_code = $vat_src_code;
2213 $this->line->total_ht = (float) $total_ht;
2214 $this->line->total_tva = (float) $total_tva;
2215 $this->line->total_localtax1 = (float) $total_localtax1;
2216 $this->line->total_localtax2 = (float) $total_localtax2;
2217 $this->line->total_ttc = (float) $total_ttc;
2218 $this->line->product_type = $type;
2219 $this->line->special_code = (!empty($special_code) ? $special_code : 0);
2220 $this->line->origin = $origin;
2221 $this->line->origin_id = $origin_id;
2222 $this->line->fk_unit = $fk_unit;
2224 $this->line->date_start = $date_start;
2225 $this->line->date_end = $date_end;
2228 $this->line->fk_multicurrency = $this->fk_multicurrency;
2229 $this->line->multicurrency_code = $this->multicurrency_code;
2230 $this->line->multicurrency_subprice = (float) $pu_ht_devise;
2231 $this->line->multicurrency_total_ht = (float) $multicurrency_total_ht;
2232 $this->line->multicurrency_total_tva = (float) $multicurrency_total_tva;
2233 $this->line->multicurrency_total_ttc = (float) $multicurrency_total_ttc;
2235 $this->line->subprice = (float) $pu_ht;
2236 $this->line->price = $this->line->subprice;
2238 $this->line->remise_percent = $remise_percent;
2240 if (is_array($array_options) && count($array_options) > 0) {
2241 $this->line->array_options = $array_options;
2244 $result = $this->line->insert($notrigger);
2247 $result = $this->
update_price(1,
'auto', 0, $this->thirdparty);
2250 if (!isset($this->context[
'createfromclone'])) {
2251 if (!empty($this->line->fk_parent_line)) {
2254 } elseif ($rang > 0 && $rang <= count($this->lines)) {
2256 $linecount = count($this->lines);
2257 for ($ii = $rang; $ii <= $linecount; $ii++) {
2262 $this->lines[] = $this->line;
2265 $this->db->commit();
2266 return $this->line->id;
2268 $this->db->rollback();
2272 $this->error = $this->line->error;
2273 $this->errors = $this->line->errors;
2274 dol_syslog(get_class($this).
"::addline error=".$this->error, LOG_ERR);
2275 $this->db->rollback();
2300 public function dispatchProduct($user, $product, $qty, $entrepot, $price = 0, $comment =
'', $eatby =
'', $sellby =
'', $batch =
'', $fk_commandefourndet = 0, $notrigger = 0, $fk_reception = 0)
2302 global
$conf, $langs;
2305 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2308 if ($entrepot <= 0) {
2309 $this->error =
'ErrorBadValueForParameterWarehouse';
2313 $this->error =
'ErrorBadValueForParameterQty';
2317 $dispatchstatus = 1;
2319 $dispatchstatus = 0;
2326 if (($this->statut == self::STATUS_ORDERSENT || $this->statut == self::STATUS_RECEIVED_PARTIALLY || $this->statut == self::STATUS_RECEIVED_COMPLETELY)) {
2329 $sql =
"INSERT INTO ".$this->db->prefix().
"receptiondet_batch";
2330 $sql .=
" (fk_element, fk_product, qty, fk_entrepot, fk_user, datec, fk_elementdet, status, comment, eatby, sellby, batch, fk_reception) VALUES";
2331 $sql .=
" ('".$this->id.
"','".$product.
"','".$qty.
"',".($entrepot > 0 ?
"'".$entrepot.
"'" :
"null").
",'".$user->id.
"','".$this->db->idate($now).
"','".$fk_commandefourndet.
"', ".$dispatchstatus.
", '".$this->db->escape($comment).
"', ";
2332 $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($fk_reception).
"'" :
"null");
2335 dol_syslog(get_class($this).
"::dispatchProduct", LOG_DEBUG);
2336 $resql = $this->db->query($sql);
2339 global
$conf, $langs, $user;
2341 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_DISPATCH', $user);
2348 $this->error = $this->db->lasterror();
2353 if (!$error && $entrepot > 0 && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER')) {
2357 $mouv->origin = &$this;
2358 $mouv->setOrigin($this->element, $this->
id);
2361 if (
getDolGlobalString(
'SUPPLIER_ORDER_ALLOW_NEGATIVE_QTY_FOR_SUPPLIER_ORDER_RETURN') && $qty < 0) {
2362 $result = $mouv->livraison($user, $product, $entrepot, $qty * (-1), $price, $comment, $now, $eatby, $sellby, $batch, 0, $inventorycode);
2364 $result = $mouv->reception($user, $product, $entrepot, $qty, $price, $comment, $eatby, $sellby, $batch,
'', 0, $inventorycode);
2368 $this->error = $mouv->error;
2369 $this->errors = $mouv->errors;
2370 dol_syslog(get_class($this).
"::dispatchProduct ".$this->error.
" ".implode(
',', $this->errors), LOG_ERR);
2377 $this->db->commit();
2380 $this->db->rollback();
2384 $this->error =
'BadStatusForObject';
2400 if ($this->statut == 0) {
2403 if ($line->fetch($idline) <= 0) {
2409 foreach ($dispatchedLines as $dispatchLine) {
2410 if ($dispatchLine[
'orderlineid'] == $idline) {
2411 $this->error =
"LineAlreadyDispatched";
2412 $this->errors[] = $this->error;
2417 if ($line->delete($user, $notrigger) > 0) {
2436 public function delete(
User $user, $notrigger = 0)
2438 global $langs,
$conf;
2439 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2445 if (empty($notrigger)) {
2447 $result = $this->
call_trigger(
'ORDER_SUPPLIER_DELETE', $user);
2449 $this->errors[] =
'ErrorWhenRunningTrigger';
2450 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2451 $this->db->rollback();
2459 if (!empty($this->linkedObjects) && array_key_exists(
'reception', $this->linkedObjects)) {
2460 foreach ($this->linkedObjects[
'reception'] as $element) {
2461 if ($element->statut >= 0) {
2462 $this->errors[] = $langs->trans(
'ReceptionExist');
2469 $main = $this->db->prefix().
'commande_fournisseurdet';
2472 $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).
")";
2473 dol_syslog(__METHOD__.
" linked order lines", LOG_DEBUG);
2474 if (!$this->db->query($sql1)) {
2476 $this->error = $this->db->lasterror();
2477 $this->errors[] = $this->db->lasterror();
2482 $ef = $main.
"_extrafields";
2483 $sql =
"DELETE FROM ".$this->db->sanitize($ef).
" WHERE fk_object IN (SELECT rowid FROM ".$this->db->sanitize($main).
" WHERE fk_commande = ".((int) $this->
id).
")";
2484 dol_syslog(get_class($this).
"::delete extrafields lines", LOG_DEBUG);
2485 if (!$this->db->query($sql)) {
2486 $this->error = $this->db->lasterror();
2487 $this->errors[] = $this->db->lasterror();
2493 $sql =
"DELETE FROM ".$this->db->prefix().
"commande_fournisseurdet WHERE fk_commande = ".((int) $this->
id);
2494 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2495 if (!$this->db->query($sql)) {
2496 $this->error = $this->db->lasterror();
2497 $this->errors[] = $this->db->lasterror();
2503 $sql =
"DELETE FROM ".$this->db->prefix().
"commande_fournisseur WHERE rowid = ".((int) $this->
id);
2504 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2505 if ($resql = $this->db->query($sql)) {
2506 if ($this->db->affected_rows($resql) < 1) {
2507 $this->error = $this->db->lasterror();
2508 $this->errors[] = $this->db->lasterror();
2512 $this->error = $this->db->lasterror();
2513 $this->errors[] = $this->db->lasterror();
2522 $this->error =
'FailToDeleteExtraFields';
2523 $this->errors[] =
'FailToDeleteExtraFields';
2525 dol_syslog(get_class($this).
"::delete error -4 ".$this->error, LOG_ERR);
2532 $this->error =
'FailToDeleteObjectLinked';
2533 $this->errors[] =
'FailToDeleteObjectLinked';
2544 if ($conf->fournisseur->commande->dir_output) {
2545 $dir =
$conf->fournisseur->commande->dir_output.
"/".$ref;
2546 $file = $dir.
"/".$ref.
".pdf";
2547 if (file_exists($file)) {
2549 $this->error =
'ErrorFailToDeleteFile';
2550 $this->errors[] =
'ErrorFailToDeleteFile';
2554 if (file_exists($dir)) {
2557 $this->error =
'ErrorFailToDeleteDir';
2558 $this->errors[] =
'ErrorFailToDeleteDir';
2566 dol_syslog(get_class($this).
"::delete $this->id by $user->id", LOG_DEBUG);
2567 $this->db->commit();
2570 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2571 $this->db->rollback();
2590 $sql =
"SELECT p.ref, p.label,";
2591 $sql .=
" e.rowid as warehouse_id, e.ref as entrepot,";
2592 $sql .=
" cfd.rowid as dispatchedlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status, cfd.fk_elementdet";
2593 $sql .=
" FROM ".$this->db->prefix().
"product as p,";
2594 $sql .=
" ".$this->db->prefix().
"receptiondet_batch as cfd";
2595 $sql .=
" LEFT JOIN ".$this->db->prefix().
"entrepot as e ON cfd.fk_entrepot = e.rowid";
2596 $sql .=
" WHERE cfd.fk_element = ".((int) $this->
id);
2597 $sql .=
" AND cfd.fk_product = p.rowid";
2599 $sql .=
" AND cfd.status = ".((int) $status);
2601 $sql .=
" ORDER BY cfd.rowid ASC";
2603 $resql = $this->db->query($sql);
2605 $num = $this->db->num_rows($resql);
2609 $objp = $this->db->fetch_object($resql);
2612 'id' => $objp->dispatchedlineid,
2613 'productid' => $objp->fk_product,
2614 'warehouseid' => $objp->warehouse_id,
2615 'qty' => $objp->qty,
2616 'orderlineid' => $objp->fk_elementdet
2623 dol_print_error($this->db,
'Failed to execute request to get dispatched lines');
2642 global
$conf, $langs;
2646 $dispatchedlinearray = array();
2650 $usercanreceive = 0;
2651 if (!isModEnabled(
'reception')) {
2652 $usercanreceive = $user->hasRight(
"fournisseur",
"commande",
"receptionner");
2654 $usercanreceive = $user->hasRight(
"reception",
"creer");
2657 if ($usercanreceive) {
2659 if ($type ==
'par') {
2661 } elseif ($type ==
'tot') {
2663 } elseif ($type ==
'nev') {
2665 } elseif ($type ==
'can') {
2669 dol_syslog(get_class($this).
"::Livraison Error -2", LOG_ERR);
2676 if (!$error && ($type ==
'tot')) {
2678 if (count($dispatchedlinearray) > 0) {
2681 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove';
2682 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove', LOG_DEBUG);
2685 if (!$error &&
getDolGlobalString(
'SUPPLIER_ORDER_USE_DISPATCH_STATUS_NEED_APPROVE') && ($type ==
'tot')) {
2687 if (count($dispatchedlinearray) > 0) {
2690 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied';
2691 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied', LOG_DEBUG);
2698 if (empty($error)) {
2701 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2702 $sql .=
" SET fk_statut = ".((int) $statut);
2703 $sql .=
" WHERE rowid = ".((int) $this->
id);
2704 $sql .=
" AND fk_statut IN (".self::STATUS_ORDERSENT.
",".self::STATUS_RECEIVED_PARTIALLY.
")";
2706 dol_syslog(get_class($this).
"::Livraison", LOG_DEBUG);
2707 $resql = $this->db->query($sql);
2710 $old_statut = $this->statut;
2711 $this->statut = $statut;
2712 $this->context[
'actionmsg2'] = $comment;
2715 $result_trigger = $this->
call_trigger(
'ORDER_SUPPLIER_RECEIVE', $user);
2716 if ($result_trigger < 0) {
2721 if (empty($error)) {
2722 $this->db->commit();
2724 $this->statut = $old_statut;
2725 $this->db->rollback();
2726 $this->error = $this->db->lasterror();
2730 $this->db->rollback();
2731 $this->error = $this->db->lasterror();
2736 $this->error = $langs->trans(
'NotAuthorized');
2737 $this->errors[] = $langs->trans(
'NotAuthorized');
2738 dol_syslog(get_class($this).
"::Livraison Not Authorized");
2770 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
2775 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2776 $sql .=
" SET date_livraison = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2777 $sql .=
" WHERE rowid = ".((int) $this->
id);
2780 $resql = $this->db->query($sql);
2782 $this->errors[] = $this->db->error();
2787 $this->oldcopy = clone $this;
2788 $this->delivery_date = $delivery_date;
2791 if (!$notrigger && empty($error)) {
2793 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2801 $this->db->commit();
2804 foreach ($this->errors as $errmsg) {
2805 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2806 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2808 $this->db->rollback();
2828 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
2833 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2834 $sql .=
" SET fk_projet = ".($id_projet > 0 ? (int) $id_projet :
'null');
2835 $sql .=
" WHERE rowid = ".((int) $this->
id);
2838 $resql = $this->db->query($sql);
2840 $this->errors[] = $this->db->error();
2845 $this->oldcopy = clone $this;
2846 $this->fk_projet = $id_projet;
2847 $this->fk_project = $id_projet;
2850 if (!$notrigger && empty($error)) {
2852 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2860 $this->db->commit();
2863 foreach ($this->errors as $errmsg) {
2864 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2865 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2867 $this->db->rollback();
2885 $comclient =
new Commande($this->db);
2886 $comclient->fetch($comclientid);
2890 $this->lines = array();
2892 $num = count($comclient->lines);
2893 for ($i = 0; $i < $num; $i++) {
2894 $prod =
new Product($this->db);
2897 if ($prod->fetch($comclient->lines[$i]->fk_product) > 0) {
2898 $label = $prod->label;
2902 $sql =
"INSERT INTO ".$this->db->prefix().
"commande_fournisseurdet";
2903 $sql .=
" (fk_commande, label, description, fk_product, price, qty, tva_tx, localtax1_tx, localtax2_tx, remise_percent, subprice, remise, ref)";
2904 $sql .=
" VALUES (".((int) $idc).
", '".$this->db->escape($label).
"', '".$this->db->escape($comclient->lines[$i]->desc).
"'";
2905 $sql .=
",".$comclient->lines[$i]->fk_product.
", ".
price2num($comclient->lines[$i]->price,
'MU');
2906 $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);
2907 $sql .=
", '".price2num($comclient->lines[$i]->subprice,
'MT').
"','0', '".$this->db->escape($ref).
"');";
2908 if ($this->db->query($sql)) {
2925 global
$conf, $langs;
2930 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur';
2931 $sql .=
" SET fk_statut = ".$status;
2932 $sql .=
" WHERE rowid = ".((int) $this->
id);
2934 dol_syslog(get_class($this).
"::setStatus", LOG_DEBUG);
2935 $resql = $this->db->query($sql);
2938 $triggerName = array();
2939 $triggerName[0] =
'DRAFT';
2940 $triggerName[1] =
'VALIDATED';
2941 $triggerName[2] =
'APPROVED';
2942 $triggerName[3] =
'ORDERED';
2943 $triggerName[4] =
'RECEIVED_PARTIALLY';
2944 $triggerName[5] =
'RECEIVED_COMPLETELY';
2945 $triggerName[6] =
'CANCELED';
2946 $triggerName[7] =
'CANCELED';
2947 $triggerName[9] =
'REFUSED';
2950 $result = $this->
call_trigger(
"ORDER_SUPPLIER_STATUS_".$triggerName[$status], $user);
2957 $this->error = $this->db->lasterror();
2958 dol_syslog(get_class($this).
"::setStatus ".$this->error);
2962 $this->statut = $status;
2963 $this->db->commit();
2966 $this->db->rollback();
2994 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 =
'')
2996 global $mysoc,
$conf, $langs;
2997 dol_syslog(get_class($this).
"::updateline $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $type, $fk_unit");
2998 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
3002 if ($this->statut == self::STATUS_DRAFT) {
3007 if (empty($info_bits)) {
3010 if (empty($txtva)) {
3013 if (empty($txlocaltax1)) {
3016 if (empty($txlocaltax2)) {
3019 if (empty($remise_percent)) {
3020 $remise_percent = 0;
3023 $remise_percent = (float)
price2num($remise_percent);
3029 $pu_ht_devise =
price2num($pu_ht_devise);
3030 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
3033 $txlocaltax1 = (float)
price2num($txlocaltax1);
3034 $txlocaltax2 = (float)
price2num($txlocaltax2);
3040 if ($date_start && $date_end && $date_start > $date_end) {
3041 $langs->load(
"errors");
3042 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
3058 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
3059 $vat_src_code = $reg[1];
3060 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
3063 $tabprice =
calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise);
3064 $total_ht = $tabprice[0];
3065 $total_tva = $tabprice[1];
3066 $total_ttc = $tabprice[2];
3067 $total_localtax1 = $tabprice[9];
3068 $total_localtax2 = $tabprice[10];
3069 $pu_ht = $tabprice[3];
3070 $pu_tva = $tabprice[4];
3071 $pu_ttc = $tabprice[5];
3074 $multicurrency_total_ht = $tabprice[16];
3075 $multicurrency_total_tva = $tabprice[17];
3076 $multicurrency_total_ttc = $tabprice[18];
3077 $pu_ht_devise = $tabprice[19];
3079 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
3080 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
3084 $this->line->fetch($rowid);
3086 $oldline = clone $this->line;
3087 $this->line->oldline = $oldline;
3089 $this->line->context = $this->context;
3091 $this->line->fk_commande = $this->id;
3093 $this->line->desc = $desc;
3097 if ($qty < $this->line->packaging) {
3098 $qty = $this->line->packaging;
3100 if (!empty($this->line->packaging) && ($qty % $this->line->packaging) > 0) {
3101 $coeff = intval($qty / $this->line->packaging) + 1;
3102 $qty = $this->line->packaging * $coeff;
3103 setEventMessage($langs->trans(
'QtyRecalculatedWithPackaging'),
'mesgs');
3108 $this->line->qty = $qty;
3109 $this->line->ref_supplier = $ref_supplier;
3111 $this->line->vat_src_code = $vat_src_code;
3112 $this->line->tva_tx = $txtva;
3113 $this->line->localtax1_tx = $txlocaltax1;
3114 $this->line->localtax2_tx = $txlocaltax2;
3115 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
3116 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
3117 $this->line->remise_percent = $remise_percent;
3118 $this->line->subprice = (float) $pu_ht;
3119 $this->line->info_bits = $info_bits;
3120 $this->line->total_ht = (float) $total_ht;
3121 $this->line->total_tva = (float) $total_tva;
3122 $this->line->total_localtax1 = (float) $total_localtax1;
3123 $this->line->total_localtax2 = (float) $total_localtax2;
3124 $this->line->total_ttc = (float) $total_ttc;
3125 $this->line->product_type = $type;
3126 $this->line->special_code = $oldline->special_code;
3127 $this->line->rang = $oldline->rang;
3128 $this->line->origin = $this->origin;
3129 $this->line->fk_unit = $fk_unit;
3131 $this->line->date_start = $date_start;
3132 $this->line->date_end = $date_end;
3135 $this->line->fk_multicurrency = $this->fk_multicurrency;
3136 $this->line->multicurrency_code = $this->multicurrency_code;
3137 $this->line->multicurrency_subprice = (float) $pu_ht_devise;
3138 $this->line->multicurrency_total_ht = (float) $multicurrency_total_ht;
3139 $this->line->multicurrency_total_tva = (float) $multicurrency_total_tva;
3140 $this->line->multicurrency_total_ttc = (float) $multicurrency_total_ttc;
3142 $this->line->subprice = (float) $pu_ht;
3143 $this->line->price = $this->line->subprice;
3145 $this->line->remise_percent = $remise_percent;
3147 if (is_array($array_options) && count($array_options) > 0) {
3149 foreach ($array_options as $key => $value) {
3150 $this->line->array_options[$key] = $array_options[$key];
3154 $result = $this->line->update($notrigger);
3160 $this->db->commit();
3163 $this->errors[] = $this->line->error;
3164 $this->errors = array_merge($this->errors, $this->line->errors);
3165 $this->error = $this->db->lasterror();
3166 $this->db->rollback();
3170 $this->error =
"Order status makes operation forbidden";
3171 dol_syslog(get_class($this).
"::updateline ".$this->error, LOG_ERR);
3186 global $user, $langs,
$conf;
3188 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
3190 dol_syslog(get_class($this).
"::initAsSpecimen");
3197 $sql =
"SELECT rowid";
3198 $sql .=
" FROM ".$this->db->prefix().
"product";
3199 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
3200 $sql .= $this->db->order(
"rowid",
"ASC");
3201 $sql .= $this->db->plimit(1);
3202 $resql = $this->db->query($sql);
3203 if ($resql && $this->db->num_rows($resql)) {
3204 $obj = $this->db->fetch_object($resql);
3205 $prodid = $obj->rowid;
3210 $this->
ref =
'SPECIMEN';
3211 $this->specimen = 1;
3214 $this->date_commande = $now;
3215 $this->date_lim_reglement = $this->date + 3600 * 24 * 30;
3216 $this->cond_reglement_code =
'RECEP';
3217 $this->mode_reglement_code =
'CHQ';
3219 $this->note_public =
'This is a comment (public)';
3220 $this->note_private =
'This is a comment (private)';
3222 $this->multicurrency_tx = 1;
3223 $this->multicurrency_code =
$conf->currency;
3231 while ($xnbp < $nbp) {
3233 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
3235 $line->subprice = 100;
3236 $line->tva_tx = 19.6;
3237 $line->localtax1_tx = 0;
3238 $line->localtax2_tx = 0;
3240 $line->total_ht = 50;
3241 $line->total_ttc = 59.8;
3242 $line->total_tva = 9.8;
3243 $line->remise_percent = 50;
3245 $line->total_ht = 100;
3246 $line->total_ttc = 119.6;
3247 $line->total_tva = 19.6;
3248 $line->remise_percent = 00;
3250 $line->fk_product = $prodid;
3252 $this->lines[$xnbp] = $line;
3254 $this->total_ht += $line->total_ht;
3255 $this->total_tva += $line->total_tva;
3256 $this->total_ttc += $line->total_ttc;
3272 $sql =
'SELECT c.rowid, date_creation as datec, tms as datem, date_valid as date_validation, date_approve as datea, date_approve2 as datea2,';
3273 $sql .=
' fk_user_author, fk_user_modif, fk_user_valid, fk_user_approve, fk_user_approve2';
3274 $sql .=
' FROM '.$this->db->prefix().
'commande_fournisseur as c';
3275 $sql .=
' WHERE c.rowid = '.((int) $id);
3277 $result = $this->db->query($sql);
3279 if ($this->db->num_rows($result)) {
3280 $obj = $this->db->fetch_object($result);
3282 $this->
id = $obj->rowid;
3284 $this->user_creation_id = $obj->fk_user_author;
3285 $this->user_validation_id = $obj->fk_user_valid;
3286 $this->user_modification_id = $obj->fk_user_modif;
3287 $this->user_approve_id = $obj->fk_user_approve;
3288 $this->user_approve_id2 = $obj->fk_user_approve2;
3290 $this->date_creation = $this->db->jdate($obj->datec);
3291 $this->date_modification = $this->db->jdate($obj->datem);
3292 $this->date_approve = $this->db->jdate($obj->datea);
3293 $this->date_approve2 = $this->db->jdate($obj->datea2);
3294 $this->date_validation = $this->db->jdate($obj->date_validation);
3296 $this->db->free($result);
3309 global
$conf, $user;
3311 $this->nb = array();
3314 $sql =
"SELECT count(co.rowid) as nb";
3315 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as co";
3316 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe as s ON co.fk_soc = s.rowid";
3317 if (empty($user->socid) && !$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3318 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
3319 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
3322 $sql .=
" ".$clause.
" co.entity IN (".
getEntity(
'supplier_order').
")";
3324 $resql = $this->db->query($sql);
3326 while ($obj = $this->db->fetch_object($resql)) {
3327 $this->nb[
"supplier_orders"] = $obj->nb;
3329 $this->db->free($resql);
3333 $this->error = $this->db->error();
3349 global
$conf, $langs;
3351 $sql =
"SELECT c.rowid, c.date_creation as datec, c.date_commande, c.fk_statut, c.date_livraison as delivery_date, c.total_ht";
3352 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as c";
3353 if (empty($user->socid) && !$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3354 $sql .=
" JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
3356 $sql .=
" WHERE c.entity = ".$conf->entity;
3357 if ($mode ===
'awaiting') {
3358 $sql .=
" AND c.fk_statut IN (".self::STATUS_ORDERSENT.
", ".self::STATUS_RECEIVED_PARTIALLY.
")";
3360 $sql .=
" AND c.fk_statut IN (".self::STATUS_VALIDATED.
", ".self::STATUS_ACCEPTED.
")";
3363 $sql .=
" AND c.fk_soc = ".((int) $user->socid);
3366 $resql = $this->db->query($sql);
3371 $response->warning_delay =
$conf->commande->fournisseur->warning_delay / 60 / 60 / 24;
3372 $response->label = $langs->trans(
"SuppliersOrdersToProcess");
3373 $response->labelShort = $langs->trans(
"Opened");
3374 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=1,2&mainmenu=commercial&leftmenu=orders_suppliers';
3375 $response->url_late = DOL_URL_ROOT.
'/fourn/commande/list.php?mainmenu=commercial&leftmenu=orders_suppliers&search_option=late';
3378 if ($mode ===
'awaiting') {
3379 $response->label = $langs->trans(
"SuppliersOrdersAwaitingReception");
3380 $response->labelShort = $langs->trans(
"AwaitingReception");
3381 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=3,4&mainmenu=commercial&leftmenu=orders_suppliers';
3384 while ($obj = $this->db->fetch_object($resql)) {
3385 $commandestatic->delivery_date = $this->db->jdate($obj->delivery_date);
3386 $commandestatic->date_commande = $this->db->jdate($obj->date_commande);
3387 $commandestatic->statut = $obj->fk_statut;
3389 $response->nbtodo++;
3390 $response->total += $obj->total_ht;
3392 if ($commandestatic->hasDelay()) {
3393 $response->nbtodolate++;
3399 $this->error = $this->db->error();
3414 if ($this->methode_commande_id > 0) {
3415 $sql =
"SELECT rowid, code, libelle as label";
3416 $sql .=
" FROM ".$this->db->prefix().
'c_input_method';
3417 $sql .=
" WHERE active=1 AND rowid = ".((int) $this->methode_commande_id);
3419 $resql = $this->db->query($sql);
3421 if ($this->db->num_rows($resql)) {
3422 $obj = $this->db->fetch_object($resql);
3424 $string = $langs->trans($obj->code);
3425 if ($string == $obj->code) {
3426 $string = $obj->label !=
'-' ? $obj->label :
'';
3449 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3451 global
$conf, $langs;
3456 if (!empty($this->model_pdf)) {
3457 $modele = $this->model_pdf;
3463 if (empty($modele)) {
3466 $langs->load(
"suppliers");
3467 $outputlangs->load(
"products");
3469 $modelpath =
"core/modules/supplier_order/doc/";
3470 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3483 if (empty($this->lines)) {
3490 foreach ($this->lines as $line) {
3491 if ($line->fk_product > 0) {
3493 $idp = $tmpproductfourn->find_min_price_product_fournisseur($line->fk_product, $line->qty, $this->thirdparty->id);
3496 if ($tmpproductfourn->delivery_time_days > $nb) {
3497 $nb = $tmpproductfourn->delivery_time_days;
3506 return $nb.
' '.$langs->trans(
'days');
3519 return $user->hasRight(
"fournisseur",
"commande");
3534 'commande_fournisseur'
3551 'commande_fournisseurdet'
3568 if ($this->statut == self::STATUS_ORDERSENT || $this->statut == self::STATUS_RECEIVED_PARTIALLY) {
3570 if (!empty($this->delivery_date)) {
3571 $date_to_test = $this->delivery_date;
3572 return $date_to_test && $date_to_test < ($now -
$conf->commande->fournisseur->warning_delay);
3580 $date_to_test = $this->date_commande;
3582 return ($this->statut > 0 && $this->statut < 5) && $date_to_test && $date_to_test < ($now -
$conf->commande->fournisseur->warning_delay);
3595 global
$conf, $langs;
3597 $langs->load(
'orders');
3601 if ($this->statut == self::STATUS_ORDERSENT || $this->statut == self::STATUS_RECEIVED_PARTIALLY) {
3602 if (!empty($this->delivery_date)) {
3603 $text = $langs->trans(
"DeliveryDate").
' '.
dol_print_date($this->delivery_date,
'day');
3605 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3608 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3611 $text .=
' '.($conf->commande->fournisseur->warning_delay > 0 ?
'+' :
'-').
' '.round(abs(
$conf->commande->fournisseur->warning_delay) / 3600 / 24, 1).
' '.$langs->trans(
"days").
' < '.$langs->trans(
"Today");
3628 if (isModEnabled(
"supplier_order")) {
3629 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
3631 $qtydelivered = array();
3632 $qtywished = array();
3636 $filter = array(
't.fk_element' => $this->
id);
3638 $filter[
't.status'] = 1;
3641 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
3643 $this->error = $supplierorderdispatch->error;
3644 $this->errors = $supplierorderdispatch->errors;
3647 if (is_array($supplierorderdispatch->lines) && count($supplierorderdispatch->lines) > 0) {
3648 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
3652 foreach ($supplierorderdispatch->lines as $line) {
3653 if (array_key_exists($line->fk_product, $qtydelivered)) {
3654 $qtydelivered[$line->fk_product] += $line->qty;
3656 $qtydelivered[$line->fk_product] = $line->qty;
3659 foreach ($this->lines as $line) {
3664 if (array_key_exists($line->fk_product, $qtywished)) {
3665 $qtywished[$line->fk_product] += $line->qty;
3667 $qtywished[$line->fk_product] = $line->qty;
3672 $diff_array = array_diff_assoc($qtydelivered, $qtywished);
3673 $keysinwishednotindelivered = array_diff(array_keys($qtywished), array_keys($qtydelivered));
3674 $keysindeliverednotinwished = array_diff(array_keys($qtydelivered), array_keys($qtywished));
3682 if (count($diff_array) == 0 && count($keysinwishednotindelivered) == 0 && count($keysindeliverednotinwished) == 0) {
3683 if ($closeopenorder) {
3685 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3693 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3704 if (count($diff_array) > 0) {
3708 foreach ($diff_array as $key => $value) {
3710 if ($qtydelivered[$key] >= $qtywished[$key]) {
3717 if ($close == count($diff_array)) {
3719 if ($closeopenorder) {
3720 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3727 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3735 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3743 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3765 $this->receptions = array();
3767 dol_syslog(get_class($this).
"::loadReceptions", LOG_DEBUG);
3769 $sql =
'SELECT cd.rowid, cd.fk_product,';
3770 $sql .=
' sum(cfd.qty) as qty';
3771 $sql .=
' FROM '.$this->db->prefix().
'receptiondet_batch as cfd,';
3772 if ($filtre_statut >= 0) {
3773 $sql .=
' '.$this->db->prefix().
'reception as e,';
3775 $sql .=
' '.$this->db->prefix().
'commande_fournisseurdet as cd';
3777 if ($filtre_statut >= 0) {
3778 $sql .=
' cfd.fk_reception = e.rowid AND';
3780 $sql .=
' cfd.fk_elementdet = cd.rowid';
3781 $sql .=
' AND cd.fk_commande ='.((int) $this->
id);
3782 if (isset($this->fk_product) && !empty($this->fk_product) > 0) {
3783 $sql .=
' AND cd.fk_product = '.((int) $this->fk_product);
3785 if ($filtre_statut >= 0) {
3786 $sql .=
' AND e.fk_statut >= '.((int) $filtre_statut);
3788 $sql .=
' GROUP BY cd.rowid, cd.fk_product';
3790 $resql = $this->db->query($sql);
3792 $num = $this->db->num_rows($resql);
3795 $obj = $this->db->fetch_object($resql);
3796 empty($this->receptions[$obj->rowid]) ? $this->receptions[$obj->rowid] = $obj->qty : $this->receptions[$obj->rowid] += $obj->qty;
3799 $this->db->free($resql);
3803 $this->error = $this->db->lasterror();
3819 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3821 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3822 $return .=
'<div class="info-box info-box-sm">';
3823 $return .=
'<span class="info-box-icon bg-infobox-action">';
3825 $return .=
'</span>';
3826 $return .=
'<div class="info-box-content">';
3827 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
3828 if ($selected >= 0) {
3829 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3831 if (property_exists($this,
'socid') || property_exists($this,
'total_tva')) {
3832 $return .=
'<br><span class="info-box-label amount">'.$this->socid.
'</span>';
3834 if (property_exists($this,
'billed')) {
3835 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Billed").
' : </span><span class="info-box-label">'.
yn($this->billed).
'</span>';
3837 if (method_exists($this,
'getLibStatut')) {
3838 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
3840 $return .=
'</div>';
3841 $return .=
'</div>';
3842 $return .=
'</div>';
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.
const STATUS_RECEIVED_COMPLETELY
Received completely.
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)
Add order line.
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.
getTooltipContentArray($params)
getTooltipContentArray
classifyUnBilled(User $user)
Classify not billed.
approve($user, $idwarehouse=0, $secondlevel=0)
Approve a supplier order.
__construct($db)
Constructor.
Cancel($user, $idwarehouse=-1)
Cancel an approved order.
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.
getRights()
Returns the rights used for this class.
load_board($user, $mode='opened')
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
deleteLine($idline, $notrigger=0)
Delete line.
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.
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.
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.
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
updateRangOfLine($rowid, $rang)
Update position of line (rang)
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.
call_trigger($triggerName, $user)
Call trigger based on this instance.
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 getIdFromCode($dbs, $code)
Get id of currency from code.
static getIdAndTxFromCode($dbs, $code, $date_document='')
Get id and rate of currency from code.
Class to manage predefined suppliers products.
Class to manage products or services.
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_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.
getDolGlobalFloat($key, $default=0)
Return a Dolibarr global constant float value.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
setEntity($currentobject)
Set entity id to use when to create an object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message in dol_events session object.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
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.
dol_now($mode='auto')
Return date for now.
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_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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...
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0)
Clean a string to use it as a file name.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller='', $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.