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;
548 $this->socid = $obj->fk_soc;
549 $this->fourn_id = $obj->fk_soc;
550 $this->statut = $obj->status;
551 $this->
status = $obj->status;
552 $this->billed = $obj->billed;
553 $this->last_main_doc = $obj->last_main_doc;
554 $this->user_author_id = $obj->user_author_id;
555 $this->user_validation_id = $obj->user_validation_id;
556 $this->user_approve_id = $obj->user_approve_id;
557 $this->user_approve_id2 = $obj->user_approve_id2;
558 $this->total_ht = $obj->total_ht;
559 $this->total_tva = $obj->total_tva;
560 $this->total_localtax1 = $obj->localtax1;
561 $this->total_localtax2 = $obj->localtax2;
562 $this->total_ttc = $obj->total_ttc;
563 $this->date_creation = $this->db->jdate($obj->date_creation);
564 $this->date_valid = $this->db->jdate($obj->date_valid);
565 $this->date_approve = $this->db->jdate($obj->date_approve);
566 $this->date_approve2 = $this->db->jdate($obj->date_approve2);
567 $this->date_commande = $this->db->jdate($obj->date_commande);
568 if (isset($obj->date_commande)) {
569 $this->date = $this->date_commande;
571 $this->date = $this->date_creation;
573 $this->delivery_date = $this->db->jdate($obj->delivery_date);
574 $this->remise_percent = $obj->remise_percent;
575 $this->methode_commande_id = $obj->fk_input_method;
576 $this->methode_commande = $obj->methode_commande;
578 $this->source = $obj->source;
579 $this->fk_project = $obj->fk_project;
580 $this->cond_reglement_id = $obj->fk_cond_reglement;
581 $this->cond_reglement_code = $obj->cond_reglement_code;
582 $this->cond_reglement = $obj->cond_reglement_label;
583 $this->cond_reglement_label = $obj->cond_reglement_label;
584 $this->cond_reglement_doc = $obj->cond_reglement_doc;
585 $this->fk_account = $obj->fk_account;
586 $this->mode_reglement_id = $obj->fk_mode_reglement;
587 $this->mode_reglement_code = $obj->mode_reglement_code;
588 $this->mode_reglement = $obj->mode_reglement_libelle;
589 $this->note = $obj->note_private;
590 $this->note_private = $obj->note_private;
591 $this->note_public = $obj->note_public;
592 $this->model_pdf = $obj->model_pdf;
595 $this->fk_incoterms = $obj->fk_incoterms;
596 $this->location_incoterms = $obj->location_incoterms;
597 $this->label_incoterms = $obj->label_incoterms;
600 $this->fk_multicurrency = $obj->fk_multicurrency;
601 $this->multicurrency_code = $obj->multicurrency_code;
602 $this->multicurrency_tx = $obj->multicurrency_tx;
603 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
604 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
605 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
607 $this->extraparams = isset($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
609 $this->db->free($resql);
624 $this->error = $this->db->error().
" sql=".$sql;
640 $this->lines = array();
642 $sql =
"SELECT l.rowid, l.fk_commande, l.ref as ref_supplier, l.fk_product, l.product_type, l.label, l.description, l.qty,";
643 $sql .=
" l.vat_src_code, l.tva_tx, l.remise_percent, l.subprice,";
644 $sql .=
" l.localtax1_tx, l. localtax2_tx, l.localtax1_type, l. localtax2_type, l.total_localtax1, l.total_localtax2,";
645 $sql .=
" l.total_ht, l.total_tva, l.total_ttc, l.info_bits, l.special_code, l.fk_parent_line, l.rang,";
646 $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,";
647 $sql .=
" l.fk_unit,";
648 $sql .=
" l.date_start, l.date_end,";
649 $sql .=
' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc';
650 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseurdet as l";
651 $sql .=
' LEFT JOIN '.$this->db->prefix().
'product as p ON l.fk_product = p.rowid';
652 $sql .=
" WHERE l.fk_commande = ".((int) $this->
id);
654 $sql .=
' AND p.fk_product_type = 0';
656 $sql .=
" ORDER BY l.rang, l.rowid";
659 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
661 $result = $this->db->query($sql);
663 $num = $this->db->num_rows($result);
667 $objp = $this->db->fetch_object($result);
671 $line->id = $objp->rowid;
672 $line->fk_commande = $objp->fk_commande;
673 $line->desc = $objp->description;
674 $line->description = $objp->description;
675 $line->qty = $objp->qty;
676 $line->tva_tx = $objp->tva_tx;
677 $line->localtax1_tx = $objp->localtax1_tx;
678 $line->localtax2_tx = $objp->localtax2_tx;
679 $line->localtax1_type = $objp->localtax1_type;
680 $line->localtax2_type = $objp->localtax2_type;
681 $line->subprice = $objp->subprice;
682 $line->pu_ht = $objp->subprice;
683 $line->remise_percent = $objp->remise_percent;
685 $line->vat_src_code = $objp->vat_src_code;
686 $line->total_ht = $objp->total_ht;
687 $line->total_tva = $objp->total_tva;
688 $line->total_localtax1 = $objp->total_localtax1;
689 $line->total_localtax2 = $objp->total_localtax2;
690 $line->total_ttc = $objp->total_ttc;
691 $line->product_type = $objp->product_type;
693 $line->fk_product = $objp->fk_product;
695 $line->libelle = $objp->product_label;
696 $line->product_label = $objp->product_label;
697 $line->product_desc = $objp->product_desc;
698 $line->product_tobatch = $objp->product_tobatch;
699 $line->product_barcode = $objp->product_barcode;
701 $line->ref = $objp->product_ref;
702 $line->product_ref = $objp->product_ref;
703 $line->ref_fourn = $objp->ref_supplier;
704 $line->ref_supplier = $objp->ref_supplier;
711 $sqlsearchpackage =
'SELECT rowid, packaging FROM '.$this->db->prefix().
"product_fournisseur_price";
712 $sqlsearchpackage .=
' WHERE entity IN ('.getEntity(
'product_fournisseur_price').
")";
713 $sqlsearchpackage .=
" AND fk_product = ".((int) $objp->fk_product);
714 $sqlsearchpackage .=
" AND ref_fourn = '".$this->db->escape($objp->ref_supplier).
"'";
715 $sqlsearchpackage .=
" AND quantity <= ".((float) $objp->qty);
716 $sqlsearchpackage .=
" AND (packaging IS NULL OR packaging = 0 OR packaging <= ".((float) $objp->qty).
")";
717 $sqlsearchpackage .=
" AND fk_soc = ".((int) $this->socid);
718 $sqlsearchpackage .=
" ORDER BY packaging ASC";
719 $sqlsearchpackage .=
" LIMIT 1";
721 $resqlsearchpackage = $this->db->query($sqlsearchpackage);
722 if ($resqlsearchpackage) {
723 $objsearchpackage = $this->db->fetch_object($resqlsearchpackage);
724 if ($objsearchpackage) {
725 $line->fk_fournprice = $objsearchpackage->rowid;
726 $line->packaging = $objsearchpackage->packaging;
729 $this->error = $this->db->lasterror();
734 $line->date_start = $this->db->jdate($objp->date_start);
735 $line->date_end = $this->db->jdate($objp->date_end);
736 $line->fk_unit = $objp->fk_unit;
739 $line->fk_multicurrency = $objp->fk_multicurrency;
740 $line->multicurrency_code = $objp->multicurrency_code;
741 $line->multicurrency_subprice = $objp->multicurrency_subprice;
742 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
743 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
744 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
746 $line->info_bits = $objp->info_bits;
747 $line->special_code = $objp->special_code;
748 $line->fk_parent_line = $objp->fk_parent_line;
750 $line->rang = $objp->rang;
754 $line->fetch_optionals();
756 $this->lines[$i] = $line;
760 $this->db->free($result);
764 $this->error = $this->db->error().
" sql=".$sql;
777 public function valid($user, $idwarehouse = 0, $notrigger = 0)
780 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
786 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")))
787 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"fournisseur",
"supplier_order_advance",
"validate"))) {
792 $soc->fetch($this->fourn_id);
795 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
796 $num = $this->getNextNumRef($soc);
802 $sql =
'UPDATE '.$this->db->prefix().
"commande_fournisseur";
803 $sql .=
" SET ref='".$this->db->escape($num).
"',";
804 $sql .=
" fk_statut = ".((int) self::STATUS_VALIDATED).
",";
805 $sql .=
" date_valid='".$this->db->idate(
dol_now()).
"',";
806 $sql .=
" fk_user_valid = ".((int) $user->id);
807 $sql .=
" WHERE rowid = ".((int) $this->
id);
808 $sql .=
" AND fk_statut = ".((int) self::STATUS_DRAFT);
810 $resql = $this->db->query($sql);
816 if (!$error && !$notrigger) {
818 $result = $this->
call_trigger(
'ORDER_SUPPLIER_VALIDATE', $user);
826 $this->oldref = $this->ref;
829 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
831 $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).
"'";
832 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'fournisseur/commande/".$this->db->escape($this->
ref).
"' and entity = ".((int)
$conf->entity);
833 $resql = $this->db->query($sql);
836 $this->error = $this->db->lasterror();
838 $sql =
'UPDATE '.$this->db->prefix().
"ecm_files set filepath = 'fournisseur/commande/".$this->db->escape($this->newref).
"'";
839 $sql .=
" WHERE filepath = 'fournisseur/commande/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
840 $resql = $this->db->query($sql);
843 $this->error = $this->db->lasterror();
849 $dirsource =
$conf->fournisseur->commande->dir_output.
'/'.$oldref;
850 $dirdest =
$conf->fournisseur->commande->dir_output.
'/'.$newref;
851 if (!$error && file_exists($dirsource)) {
852 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
854 if (@rename($dirsource, $dirdest)) {
857 $listoffiles =
dol_dir_list(
$conf->fournisseur->commande->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
858 foreach ($listoffiles as $fileentry) {
859 $dirsource = $fileentry[
'name'];
860 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
861 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
862 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
863 @rename($dirsource, $dirdest);
881 $this->db->rollback();
885 $this->error =
'NotAuthorized';
886 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
911 public function LibStatut($status, $mode = 0, $billed = 0)
914 global $langs, $hookmanager;
916 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
917 $langs->load(
'orders');
919 $this->labelStatus[0] =
'StatusSupplierOrderDraft';
920 $this->labelStatus[1] =
'StatusSupplierOrderValidated';
921 $this->labelStatus[2] =
'StatusSupplierOrderApproved';
923 $this->labelStatus[3] =
'StatusSupplierOrderOnProcess';
925 $this->labelStatus[3] =
'StatusSupplierOrderOnProcessWithValidation';
927 $this->labelStatus[4] =
'StatusSupplierOrderReceivedPartially';
928 $this->labelStatus[5] =
'StatusSupplierOrderReceivedAll';
929 $this->labelStatus[6] =
'StatusSupplierOrderCanceled';
930 $this->labelStatus[7] =
'StatusSupplierOrderCanceled';
931 $this->labelStatus[9] =
'StatusSupplierOrderRefused';
934 $this->labelStatusShort[0] =
'StatusSupplierOrderDraftShort';
935 $this->labelStatusShort[1] =
'StatusSupplierOrderValidatedShort';
936 $this->labelStatusShort[2] =
'StatusSupplierOrderApprovedShort';
937 $this->labelStatusShort[3] =
'StatusSupplierOrderOnProcessShort';
938 $this->labelStatusShort[4] =
'StatusSupplierOrderReceivedPartiallyShort';
939 $this->labelStatusShort[5] =
'StatusSupplierOrderReceivedAllShort';
940 $this->labelStatusShort[6] =
'StatusSupplierOrderCanceledShort';
941 $this->labelStatusShort[7] =
'StatusSupplierOrderCanceledShort';
942 $this->labelStatusShort[9] =
'StatusSupplierOrderRefusedShort';
945 $statustrans = array(
957 $statusClass =
'status0';
958 if (!empty($statustrans[$status])) {
959 $statusClass = $statustrans[$status];
964 $billedtext =
' - '.$langs->trans(
"Billed");
966 if ($status == 5 && $billed) {
967 $statusClass =
'status6';
970 $statusLong = $langs->transnoentitiesnoconv($this->labelStatus[$status]).$billedtext;
971 $statusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
973 $parameters = array(
'status' => $status,
'mode' => $mode,
'billed' => $billed);
974 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
976 return $hookmanager->resPrint;
979 return dolGetStatus($statusLong, $statusShort,
'', $statusClass, $mode);
990 global
$conf, $langs, $user;
992 $langs->loadLangs([
'bills',
'orders']);
995 $nofetch = !empty($params[
'nofetch']);
997 if ($user->hasRight(
"fournisseur",
"commande",
"read")) {
998 $datas[
'picto'] =
'<u class="paddingrightonly">'.$langs->trans(
"SupplierOrder").
'</u>';
1000 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
1002 if (!empty($this->
ref)) {
1003 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1005 if (!empty($this->ref_supplier)) {
1006 $datas[
'refsupplier'] =
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.$this->ref_supplier;
1009 $langs->load(
'companies');
1010 if (empty($this->thirdparty)) {
1013 $datas[
'supplier'] =
'<br><b>'.$langs->trans(
'Supplier').
':</b> '.$this->thirdparty->getNomUrl(1,
'', 0, 1);
1015 if (!empty($this->total_ht)) {
1016 $datas[
'totalht'] =
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1,
$conf->currency);
1018 if (!empty($this->total_tva)) {
1019 $datas[
'totaltva'] =
'<br><b>'.$langs->trans(
'VAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1,
$conf->currency);
1021 if (!empty($this->total_ttc)) {
1022 $datas[
'totalttc'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency);
1024 if (!empty($this->date)) {
1025 $datas[
'date'] =
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->date,
'day');
1027 if (!empty($this->delivery_date)) {
1028 $datas[
'deliverydate'] =
'<br><b>'.$langs->trans(
'DeliveryDate').
':</b> '.
dol_print_date($this->delivery_date,
'dayhour');
1044 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = 0)
1046 global $langs, $user, $hookmanager;
1051 'objecttype' => $this->element,
1052 'option' => $option,
1055 $classfortooltip =
'classfortooltip';
1058 $classfortooltip =
'classforajaxtooltip';
1059 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1065 $url = DOL_URL_ROOT.
'/fourn/commande/card.php?id='.$this->id;
1067 if ($option !==
'nolink') {
1069 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1070 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1071 $add_save_lastsearch_values = 1;
1073 if ($add_save_lastsearch_values) {
1074 $url .=
'&save_lastsearch_values=1';
1079 if (empty($notooltip)) {
1081 $label = $langs->trans(
"ShowOrder");
1082 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1084 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1085 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
1088 $linkstart =
'<a href="'.$url.
'"';
1089 $linkstart .= $linkclose.
'>';
1092 $result .= $linkstart;
1094 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
1096 if ($withpicto != 2) {
1097 $result .= $this->ref;
1099 $result .= $linkend;
1101 if ($addlinktonotes) {
1102 $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
1105 $result .=
' <span class="note inline-block">';
1106 $result .=
'<a href="'.DOL_URL_ROOT.
'/fourn/commande/note.php?id='.$this->
id.
'" class="classfortooltip" title="'.
dol_escape_htmltag($notetoshow).
'">';
1111 $result .=
'</span>';
1116 $hookmanager->initHooks(array($this->element .
'dao'));
1117 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1118 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1120 $result = $hookmanager->resPrint;
1122 $result .= $hookmanager->resPrint;
1135 public function getNextNumRef($soc)
1137 global $langs,
$conf;
1138 $langs->load(
"orders");
1147 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
1149 foreach ($dirmodels as $reldir) {
1150 $dir =
dol_buildpath($reldir.
"core/modules/supplier_order/");
1153 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1161 $obj =
new $classname();
1162 '@phan-var-force ModeleNumRefSuppliersOrders $obj';
1164 $numref = $obj->getNextValue($soc, $this);
1166 if ($numref !=
"") {
1169 $this->error = $obj->error;
1173 $this->error =
"Error_COMMANDE_SUPPLIER_ADDON_NotDefined";
1188 if ($this->billed) {
1194 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur SET billed = 1';
1197 if ($this->db->query($sql)) {
1200 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CLASSIFY_BILLED', $user);
1210 $this->db->commit();
1213 $this->db->rollback();
1219 $this->db->rollback();
1233 if (empty($this->billed)) {
1239 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur SET billed = 0';
1243 if (!$this->db->query($sql)) {
1245 $this->db->rollback();
1250 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CLASSIFY_UNBILLED', $user);
1252 $this->db->rollback();
1258 $this->db->commit();
1271 public function approve($user, $idwarehouse = 0, $secondlevel = 0)
1273 global $langs,
$conf;
1274 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1280 if ($user->hasRight(
"fournisseur",
"commande",
"approuver")) {
1286 $soc =
new Societe($this->db);
1287 $soc->fetch($this->fourn_id);
1290 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
1291 $num = $this->getNextNumRef($soc);
1298 $movetoapprovestatus =
true;
1301 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1302 $sql .=
" SET ref='".$this->db->escape($num).
"',";
1303 if (empty($secondlevel)) {
1304 $sql .=
" date_approve='".$this->db->idate($now).
"',";
1305 $sql .=
" fk_user_approve = ".((int) $user->id);
1307 if (empty($this->user_approve_id2)) {
1308 $movetoapprovestatus =
false;
1309 $comment =
' (first level)';
1313 $sql .=
" date_approve2='".$this->db->idate($now).
"',";
1314 $sql .=
" fk_user_approve2 = ".((int) $user->id);
1315 if (empty($this->user_approve_id)) {
1316 $movetoapprovestatus =
false;
1318 $comment =
' (second level)';
1321 if ($movetoapprovestatus) {
1322 $sql .=
", fk_statut = ".self::STATUS_ACCEPTED;
1324 $sql .=
", fk_statut = ".self::STATUS_VALIDATED;
1326 $sql .=
" WHERE rowid = ".((int) $this->
id);
1327 $sql .=
" AND fk_statut = ".self::STATUS_VALIDATED;
1329 if ($this->db->query($sql)) {
1331 $result = $this->
add_contact($user->id,
'SALESREPFOLL',
'internal', 1);
1332 if ($result < 0 && $result != -2) {
1338 if (!$error && $movetoapprovestatus && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER')) {
1339 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1340 $langs->load(
"agenda");
1342 $cpt = count($this->lines);
1343 for ($i = 0; $i < $cpt; $i++) {
1345 if ($this->lines[$i]->fk_product > 0) {
1346 $this->line = $this->lines[$i];
1348 $mouvP->origin = &$this;
1349 $mouvP->setOrigin($this->element, $this->
id);
1351 $up_ht_disc = $this->lines[$i]->subprice;
1352 if (!empty($this->lines[$i]->remise_percent) && !
getDolGlobalString(
'STOCK_EXCLUDE_DISCOUNT_FOR_PMP')) {
1353 $up_ht_disc =
price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100,
'MU');
1355 $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans(
"OrderApprovedInDolibarr", $this->ref));
1366 $result = $this->
call_trigger(
'ORDER_SUPPLIER_APPROVE', $user);
1374 $this->
ref = $this->newref;
1376 if ($movetoapprovestatus) {
1381 if (empty($secondlevel)) {
1382 $this->date_approve = $now;
1383 $this->user_approve_id = $user->id;
1385 $this->date_approve2 = $now;
1386 $this->user_approve_id2 = $user->id;
1389 $this->db->commit();
1392 $this->db->rollback();
1396 $this->db->rollback();
1397 $this->error = $this->db->lasterror();
1401 dol_syslog(get_class($this).
"::approve Not Authorized", LOG_ERR);
1414 global
$conf, $langs;
1420 if ($user->hasRight(
"fournisseur",
"commande",
"approuver")) {
1423 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur SET fk_statut = ".
self::STATUS_REFUSED;
1424 $sql .=
" WHERE rowid = ".((int) $this->
id);
1426 if ($this->db->query($sql)) {
1431 $result = $this->
call_trigger(
'ORDER_SUPPLIER_REFUSE', $user);
1434 $this->db->rollback();
1436 $this->db->commit();
1441 $this->db->rollback();
1442 $this->error = $this->db->lasterror();
1443 dol_syslog(get_class($this).
"::refuse Error -1");
1447 dol_syslog(get_class($this).
"::refuse Not Authorized");
1461 public function Cancel($user, $idwarehouse = -1)
1464 global $langs,
$conf;
1470 if ($user->hasRight(
"fournisseur",
"commande",
"commander")) {
1475 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur SET fk_statut = ".((int) $statut);
1476 $sql .=
" WHERE rowid = ".((int) $this->
id);
1477 dol_syslog(get_class($this).
"::cancel", LOG_DEBUG);
1478 if ($this->db->query($sql)) {
1482 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CANCEL', $user);
1489 $this->db->commit();
1492 $this->db->rollback();
1496 $this->db->rollback();
1497 $this->error = $this->db->lasterror();
1498 dol_syslog(get_class($this).
"::cancel ".$this->error);
1502 dol_syslog(get_class($this).
"::cancel Not Authorized");
1516 public function commande($user, $date, $methode, $comment =
'')
1521 if ($user->hasRight(
"fournisseur",
"commande",
"commander")) {
1524 $newnoteprivate = $this->note_private;
1526 $newnoteprivate =
dol_concatdesc($newnoteprivate, $langs->trans(
"Comment").
': '.$comment);
1529 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1530 $sql .=
" SET fk_statut=".self::STATUS_ORDERSENT.
", fk_input_method=".$methode.
", date_commande='".$this->db->idate($date).
"', ";
1531 $sql .=
" note_private='".$this->db->escape($newnoteprivate).
"'";
1532 $sql .=
" WHERE rowid=".((int) $this->
id);
1534 dol_syslog(get_class($this).
"::commande", LOG_DEBUG);
1535 if ($this->db->query($sql)) {
1537 $this->methode_commande_id = $methode;
1538 $this->date_commande = $date;
1539 $this->context = array(
'comments' => $comment);
1542 $result = $this->
call_trigger(
'ORDER_SUPPLIER_SUBMIT', $user);
1549 $this->error = $this->db->lasterror();
1550 $this->errors[] = $this->db->lasterror();
1554 $this->db->commit();
1556 $this->db->rollback();
1560 $this->error = $langs->trans(
'NotAuthorized');
1561 $this->errors[] = $langs->trans(
'NotAuthorized');
1562 dol_syslog(get_class($this).
"::commande User not Authorized", LOG_WARNING);
1565 return ($error ? -1 : 1);
1575 public function create($user, $notrigger = 0)
1577 global $langs,
$conf, $hookmanager;
1585 $date = ($this->date_commande ? $this->date_commande : $this->date);
1589 $delivery_date = $this->delivery_date;
1592 if (empty($this->source)) {
1597 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
1602 if (empty($this->fk_multicurrency)) {
1603 $this->multicurrency_code =
$conf->currency;
1604 $this->fk_multicurrency = 0;
1605 $this->multicurrency_tx = 1;
1613 $sql =
"INSERT INTO ".$this->db->prefix().
"commande_fournisseur (";
1615 $sql .=
", ref_supplier";
1616 $sql .=
", note_private";
1617 $sql .=
", note_public";
1620 $sql .=
", fk_projet";
1621 $sql .=
", date_creation";
1622 $sql .=
", date_livraison";
1623 $sql .=
", fk_user_author";
1624 $sql .=
", fk_statut";
1626 $sql .=
", model_pdf";
1627 $sql .=
", fk_mode_reglement";
1628 $sql .=
", fk_cond_reglement";
1629 $sql .=
", fk_account";
1630 $sql .=
", fk_incoterms, location_incoterms";
1631 $sql .=
", fk_multicurrency";
1632 $sql .=
", multicurrency_code";
1633 $sql .=
", multicurrency_tx";
1635 $sql .=
" VALUES (";
1637 $sql .=
", ".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"NULL");
1638 $sql .=
", '".$this->db->escape($this->note_private).
"'";
1639 $sql .=
", '".$this->db->escape($this->note_public).
"'";
1640 $sql .=
", ".((int) $this->entity);
1641 $sql .=
", ".((int) $this->socid);
1642 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
1643 $sql .=
", '".$this->db->idate($date).
"'";
1644 $sql .=
", ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
"null");
1645 $sql .=
", ".((int) $user->id);
1646 $sql .=
", ".self::STATUS_DRAFT;
1647 $sql .=
", ".((int) $this->source);
1648 $sql .=
", '".$this->db->escape(
getDolGlobalString(
'COMMANDE_SUPPLIER_ADDON_PDF')).
"'";
1649 $sql .=
", ".($this->mode_reglement_id > 0 ? $this->mode_reglement_id :
'null');
1650 $sql .=
", ".($this->cond_reglement_id > 0 ? $this->cond_reglement_id :
'null');
1651 $sql .=
", ".($this->fk_account > 0 ? $this->fk_account :
'NULL');
1652 $sql .=
", ".(int) $this->fk_incoterms;
1653 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
1654 $sql .=
", ".(int) $this->fk_multicurrency;
1655 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1656 $sql .=
", ".(float) $this->multicurrency_tx;
1659 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1660 if ($this->db->query($sql)) {
1661 $this->
id = $this->db->last_insert_id($this->db->prefix().
"commande_fournisseur");
1664 $num = count($this->lines);
1667 for ($i = 0; $i < $num; $i++) {
1668 $line = $this->lines[$i];
1669 if (!is_object($line)) {
1670 $line = (object) $line;
1681 $line->localtax1_tx,
1682 $line->localtax2_tx,
1686 $line->remise_percent,
1689 $line->product_type,
1694 $line->array_options,
1696 $line->multicurrency_subprice,
1703 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
1704 $this->db->rollback();
1709 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1710 $sql .=
" SET ref='(PROV".$this->id.
")'";
1711 $sql .=
" WHERE rowid=".((int) $this->
id);
1713 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1714 if ($this->db->query($sql)) {
1717 $this->
ref =
"(PROV".$this->id.
")";
1719 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
1720 $this->linked_objects = $this->linkedObjectsIds;
1724 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
1725 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
1726 if (is_array($tmp_origin_id)) {
1727 foreach ($tmp_origin_id as $origin_id) {
1735 $origin_id = $tmp_origin_id;
1753 if (!$error && !$notrigger) {
1755 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CREATE', $user);
1757 $this->db->rollback();
1764 $this->db->commit();
1767 $this->error = $this->db->lasterror();
1768 $this->db->rollback();
1773 $this->error =
'Failed to get ID of inserted line';
1778 $this->error = $this->db->lasterror();
1779 $this->db->rollback();
1799 if (isset($this->
ref)) {
1800 $this->
ref = trim($this->
ref);
1802 if (isset($this->ref_supplier)) {
1803 $this->ref_supplier = trim($this->ref_supplier);
1805 if (isset($this->note_private)) {
1806 $this->note_private = trim($this->note_private);
1808 if (isset($this->note_public)) {
1809 $this->note_public = trim($this->note_public);
1811 if (isset($this->model_pdf)) {
1812 $this->model_pdf = trim($this->model_pdf);
1814 if (isset($this->import_key)) {
1815 $this->import_key = trim($this->import_key);
1819 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
1821 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1822 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
1823 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1824 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
1825 $sql .=
" date_commande=".(strval($this->date_commande) !=
'' ?
"'".$this->db->idate($this->date_commande).
"'" :
'null').
",";
1826 $sql .=
" date_valid=".(strval($this->date_validation) !=
'' ?
"'".$this->db->idate($this->date_validation).
"'" :
'null').
",";
1827 $sql .=
" total_tva=".(isset($this->total_tva) ? $this->total_tva :
"null").
",";
1828 $sql .=
" localtax1=".(isset($this->total_localtax1) ? $this->total_localtax1 :
"null").
",";
1829 $sql .=
" localtax2=".(isset($this->total_localtax2) ? $this->total_localtax2 :
"null").
",";
1830 $sql .=
" total_ht=".(isset($this->total_ht) ? $this->total_ht :
"null").
",";
1831 $sql .=
" total_ttc=".(isset($this->total_ttc) ? $this->total_ttc :
"null").
",";
1832 $sql .=
" fk_statut=".(isset($this->statut) ? $this->statut :
"null").
",";
1833 $sql .=
" fk_user_author=".(isset($this->user_author_id) ? $this->user_author_id :
"null").
",";
1834 $sql .=
" fk_user_valid=".(isset($this->user_validation_id) && $this->user_validation_id > 0 ? $this->user_validation_id :
"null").
",";
1835 $sql .=
" fk_projet=".(isset($this->fk_project) ? $this->fk_project :
"null").
",";
1836 $sql .=
" fk_cond_reglement=".(isset($this->cond_reglement_id) ? $this->cond_reglement_id :
"null").
",";
1837 $sql .=
" fk_mode_reglement=".(isset($this->mode_reglement_id) ? $this->mode_reglement_id :
"null").
",";
1838 $sql .=
" date_livraison=".(strval($this->delivery_date) !=
'' ?
"'".$this->db->idate($this->delivery_date).
"'" :
'null').
",";
1840 $sql .=
" fk_account=".($this->fk_account > 0 ? $this->fk_account :
"null").
",";
1842 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1843 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1844 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1845 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
1847 $sql .=
" WHERE rowid=".((int) $this->
id);
1851 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1852 $resql = $this->db->query($sql);
1855 $this->errors[] =
"Error ".$this->db->lasterror();
1865 if (!$error && !$notrigger) {
1867 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
1876 foreach ($this->errors as $errmsg) {
1877 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1878 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1880 $this->db->rollback();
1883 $this->db->commit();
1898 global
$conf, $user, $hookmanager;
1905 foreach ($this->lines as $line) {
1906 $line->fetch_optionals();
1910 $objFrom = clone $this;
1913 if (!empty($socid) && $socid != $this->socid) {
1914 $objsoc =
new Societe($this->db);
1916 if ($objsoc->fetch($socid) > 0) {
1917 $this->socid = $objsoc->id;
1918 $this->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1919 $this->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1920 $this->fk_project = 0;
1921 $this->fk_delivery_address = 0;
1931 $this->user_author_id = $user->id;
1932 $this->user_validation_id = 0;
1935 $this->date_creation = 0;
1936 $this->date_validation = 0;
1937 $this->date_commande = 0;
1938 $this->ref_supplier =
'';
1939 $this->user_approve_id = 0;
1940 $this->user_approve_id2 = 0;
1941 $this->date_approve = 0;
1942 $this->date_approve2 = 0;
1945 $this->context[
'createfromclone'] =
'createfromclone';
1946 $result = $this->
create($user, $notrigger);
1953 if (is_object($hookmanager)) {
1954 $parameters = array(
'objFrom' => $objFrom);
1956 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1964 unset($this->context[
'createfromclone']);
1968 $this->db->commit();
1971 $this->db->rollback();
2005 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)
2007 global $langs, $mysoc;
2009 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");
2010 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2012 if ($this->statut == self::STATUS_DRAFT) {
2013 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2022 if (empty($txtva)) {
2028 if (empty($txlocaltax1)) {
2031 if (empty($txlocaltax2)) {
2034 if (empty($remise_percent)) {
2035 $remise_percent = 0;
2038 $remise_percent =
price2num($remise_percent);
2041 $pu_ht_devise =
price2num($pu_ht_devise);
2043 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
2048 if ($price_base_type ==
'HT') {
2053 $desc = trim($desc);
2056 if ($qty < 0 && !$fk_product) {
2057 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Product"));
2063 if ($date_start && $date_end && $date_start > $date_end) {
2064 $langs->load(
"errors");
2065 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
2072 $product_type = $type;
2075 if ($fk_product > 0) {
2076 if (
getDolGlobalInt(
'SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY') == 1) {
2078 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);
2080 if ($prod->fetch($fk_product) > 0) {
2081 $product_type = $prod->type;
2082 $label = $prod->label;
2086 $result = $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', (isset($this->fk_soc) ? $this->fk_soc : $this->socid));
2090 if ($result > 0 && ($origin ==
'commande' || $pu ===
'')) {
2091 $pu = $prod->fourn_pu;
2092 $ref_supplier = $prod->ref_supplier;
2094 if ($remise_percent == 0 && $prod->remise_percent != 0) {
2095 $remise_percent = $prod->remise_percent;
2099 $langs->load(
"errors");
2100 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
2101 $this->db->rollback();
2102 dol_syslog(get_class($this).
"::addline we did not found supplier price, so we can't guess unit price");
2107 if ($result == -1) {
2108 $langs->load(
"errors");
2109 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
2110 $this->db->rollback();
2111 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_DEBUG);
2115 $this->error = $prod->error;
2116 $this->db->rollback();
2117 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_ERR);
2121 $this->error = $prod->error;
2122 $this->db->rollback();
2129 $prod =
new Product($this->db);
2130 $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', (empty($this->fk_soc) ? $this->socid : $this->fk_soc));
2132 if ($qty < $prod->packaging) {
2133 $qty = $prod->packaging;
2135 if (!empty($prod->packaging) && (fmod((
float) $qty, $prod->packaging) > 0.000001)) {
2136 $coeff = intval((
float) $qty / $prod->packaging) + 1;
2137 $qty = (float) $prod->packaging * $coeff;
2138 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'mesgs');
2144 if (isModEnabled(
"multicurrency") && $pu_ht_devise > 0) {
2153 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
2154 $vat_src_code = $reg[1];
2155 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
2163 $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);
2165 $total_ht = $tabprice[0];
2166 $total_tva = $tabprice[1];
2167 $total_ttc = $tabprice[2];
2168 $total_localtax1 = $tabprice[9];
2169 $total_localtax2 = $tabprice[10];
2170 $pu = $pu_ht = $tabprice[3];
2173 $multicurrency_total_ht = $tabprice[16];
2174 $multicurrency_total_tva = $tabprice[17];
2175 $multicurrency_total_ttc = $tabprice[18];
2176 $pu_ht_devise = $tabprice[19];
2178 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2179 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2183 $rang = $rangmax + 1;
2189 $this->line->context = $this->context;
2191 $this->line->fk_commande = $this->id;
2192 $this->line->label = $label;
2193 $this->line->ref_fourn = $ref_supplier;
2194 $this->line->ref_supplier = $ref_supplier;
2195 $this->line->desc = $desc;
2196 $this->line->qty = $qty;
2197 $this->line->tva_tx = $txtva;
2198 $this->line->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0);
2199 $this->line->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0);
2200 $this->line->localtax1_type = $localtax1_type;
2201 $this->line->localtax2_type = $localtax2_type;
2202 $this->line->fk_product = $fk_product;
2203 $this->line->product_type = $product_type;
2204 $this->line->remise_percent = $remise_percent;
2205 $this->line->subprice = (float) $pu_ht;
2206 $this->line->rang = $rang;
2207 $this->line->info_bits = $info_bits;
2209 $this->line->vat_src_code = $vat_src_code;
2210 $this->line->total_ht = (float) $total_ht;
2211 $this->line->total_tva = (float) $total_tva;
2212 $this->line->total_localtax1 = (float) $total_localtax1;
2213 $this->line->total_localtax2 = (float) $total_localtax2;
2214 $this->line->total_ttc = (float) $total_ttc;
2215 $this->line->product_type = $type;
2216 $this->line->special_code = (!empty($special_code) ? $special_code : 0);
2217 $this->line->origin = $origin;
2218 $this->line->origin_id = $origin_id;
2219 $this->line->fk_unit = $fk_unit;
2221 $this->line->date_start = $date_start;
2222 $this->line->date_end = $date_end;
2225 $this->line->fk_multicurrency = $this->fk_multicurrency;
2226 $this->line->multicurrency_code = $this->multicurrency_code;
2227 $this->line->multicurrency_subprice = (float) $pu_ht_devise;
2228 $this->line->multicurrency_total_ht = (float) $multicurrency_total_ht;
2229 $this->line->multicurrency_total_tva = (float) $multicurrency_total_tva;
2230 $this->line->multicurrency_total_ttc = (float) $multicurrency_total_ttc;
2232 $this->line->subprice = (float) $pu_ht;
2233 $this->line->price = $this->line->subprice;
2235 $this->line->remise_percent = $remise_percent;
2237 if (is_array($array_options) && count($array_options) > 0) {
2238 $this->line->array_options = $array_options;
2241 $result = $this->line->insert($notrigger);
2244 $result = $this->
update_price(1,
'auto', 0, $this->thirdparty);
2247 if (!isset($this->context[
'createfromclone'])) {
2248 if (!empty($this->line->fk_parent_line)) {
2251 } elseif ($rang > 0 && $rang <= count($this->lines)) {
2253 $linecount = count($this->lines);
2254 for ($ii = $rang; $ii <= $linecount; $ii++) {
2259 $this->lines[] = $this->line;
2262 $this->db->commit();
2263 return $this->line->id;
2265 $this->db->rollback();
2269 $this->error = $this->line->error;
2270 $this->errors = $this->line->errors;
2271 dol_syslog(get_class($this).
"::addline error=".$this->error, LOG_ERR);
2272 $this->db->rollback();
2297 public function dispatchProduct($user, $product, $qty, $entrepot, $price = 0, $comment =
'', $eatby =
'', $sellby =
'', $batch =
'', $fk_commandefourndet = 0, $notrigger = 0, $fk_reception = 0)
2299 global
$conf, $langs;
2302 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2305 if ($entrepot <= 0) {
2306 $this->error =
'ErrorBadValueForParameterWarehouse';
2310 $this->error =
'ErrorBadValueForParameterQty';
2314 $dispatchstatus = 1;
2316 $dispatchstatus = 0;
2323 if (($this->statut == self::STATUS_ORDERSENT || $this->statut == self::STATUS_RECEIVED_PARTIALLY || $this->statut == self::STATUS_RECEIVED_COMPLETELY)) {
2326 $sql =
"INSERT INTO ".$this->db->prefix().
"receptiondet_batch";
2327 $sql .=
" (fk_element, fk_product, qty, fk_entrepot, fk_user, datec, fk_elementdet, status, comment, eatby, sellby, batch, fk_reception) VALUES";
2328 $sql .=
" ('".$this->id.
"','".$product.
"','".$qty.
"',".($entrepot > 0 ?
"'".$entrepot.
"'" :
"null").
",'".$user->id.
"','".$this->db->idate($now).
"','".$fk_commandefourndet.
"', ".$dispatchstatus.
", '".$this->db->escape($comment).
"', ";
2329 $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");
2332 dol_syslog(get_class($this).
"::dispatchProduct", LOG_DEBUG);
2333 $resql = $this->db->query($sql);
2336 global
$conf, $langs, $user;
2338 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_DISPATCH', $user);
2345 $this->error = $this->db->lasterror();
2350 if (!$error && $entrepot > 0 && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER')) {
2354 $mouv->origin = &$this;
2355 $mouv->setOrigin($this->element, $this->
id);
2358 if (
getDolGlobalString(
'SUPPLIER_ORDER_ALLOW_NEGATIVE_QTY_FOR_SUPPLIER_ORDER_RETURN') && $qty < 0) {
2359 $result = $mouv->livraison($user, $product, $entrepot, $qty * (-1), $price, $comment, $now, $eatby, $sellby, $batch, 0, $inventorycode);
2361 $result = $mouv->reception($user, $product, $entrepot, $qty, $price, $comment, $eatby, $sellby, $batch,
'', 0, $inventorycode);
2365 $this->error = $mouv->error;
2366 $this->errors = $mouv->errors;
2367 dol_syslog(get_class($this).
"::dispatchProduct ".$this->error.
" ".implode(
',', $this->errors), LOG_ERR);
2374 $this->db->commit();
2377 $this->db->rollback();
2381 $this->error =
'BadStatusForObject';
2397 if ($this->statut == 0) {
2400 if ($line->fetch($idline) <= 0) {
2406 foreach ($dispatchedLines as $dispatchLine) {
2407 if ($dispatchLine[
'orderlineid'] == $idline) {
2408 $this->error =
"LineAlreadyDispatched";
2409 $this->errors[] = $this->error;
2414 if ($line->delete($user, $notrigger) > 0) {
2433 public function delete(
User $user, $notrigger = 0)
2435 global $langs,
$conf;
2436 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2442 if (empty($notrigger)) {
2444 $result = $this->
call_trigger(
'ORDER_SUPPLIER_DELETE', $user);
2446 $this->errors[] =
'ErrorWhenRunningTrigger';
2447 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2448 $this->db->rollback();
2456 if (!empty($this->linkedObjects) && array_key_exists(
'reception', $this->linkedObjects)) {
2457 foreach ($this->linkedObjects[
'reception'] as $element) {
2458 if ($element->statut >= 0) {
2459 $this->errors[] = $langs->trans(
'ReceptionExist');
2466 $main = $this->db->prefix().
'commande_fournisseurdet';
2469 $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).
")";
2470 dol_syslog(__METHOD__.
" linked order lines", LOG_DEBUG);
2471 if (!$this->db->query($sql1)) {
2473 $this->error = $this->db->lasterror();
2474 $this->errors[] = $this->db->lasterror();
2479 $ef = $main.
"_extrafields";
2480 $sql =
"DELETE FROM ".$this->db->sanitize($ef).
" WHERE fk_object IN (SELECT rowid FROM ".$this->db->sanitize($main).
" WHERE fk_commande = ".((int) $this->
id).
")";
2481 dol_syslog(get_class($this).
"::delete extrafields lines", LOG_DEBUG);
2482 if (!$this->db->query($sql)) {
2483 $this->error = $this->db->lasterror();
2484 $this->errors[] = $this->db->lasterror();
2490 $sql =
"DELETE FROM ".$this->db->prefix().
"commande_fournisseurdet WHERE fk_commande = ".((int) $this->
id);
2491 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2492 if (!$this->db->query($sql)) {
2493 $this->error = $this->db->lasterror();
2494 $this->errors[] = $this->db->lasterror();
2500 $sql =
"DELETE FROM ".$this->db->prefix().
"commande_fournisseur WHERE rowid = ".((int) $this->
id);
2501 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2502 if ($resql = $this->db->query($sql)) {
2503 if ($this->db->affected_rows($resql) < 1) {
2504 $this->error = $this->db->lasterror();
2505 $this->errors[] = $this->db->lasterror();
2509 $this->error = $this->db->lasterror();
2510 $this->errors[] = $this->db->lasterror();
2519 $this->error =
'FailToDeleteExtraFields';
2520 $this->errors[] =
'FailToDeleteExtraFields';
2522 dol_syslog(get_class($this).
"::delete error -4 ".$this->error, LOG_ERR);
2529 $this->error =
'FailToDeleteObjectLinked';
2530 $this->errors[] =
'FailToDeleteObjectLinked';
2541 if ($conf->fournisseur->commande->dir_output) {
2542 $dir =
$conf->fournisseur->commande->dir_output.
"/".$ref;
2543 $file = $dir.
"/".$ref.
".pdf";
2544 if (file_exists($file)) {
2546 $this->error =
'ErrorFailToDeleteFile';
2547 $this->errors[] =
'ErrorFailToDeleteFile';
2551 if (file_exists($dir)) {
2554 $this->error =
'ErrorFailToDeleteDir';
2555 $this->errors[] =
'ErrorFailToDeleteDir';
2563 dol_syslog(get_class($this).
"::delete $this->id by $user->id", LOG_DEBUG);
2564 $this->db->commit();
2567 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2568 $this->db->rollback();
2587 $sql =
"SELECT p.ref, p.label,";
2588 $sql .=
" e.rowid as warehouse_id, e.ref as entrepot,";
2589 $sql .=
" cfd.rowid as dispatchedlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status, cfd.fk_elementdet";
2590 $sql .=
" FROM ".$this->db->prefix().
"product as p,";
2591 $sql .=
" ".$this->db->prefix().
"receptiondet_batch as cfd";
2592 $sql .=
" LEFT JOIN ".$this->db->prefix().
"entrepot as e ON cfd.fk_entrepot = e.rowid";
2593 $sql .=
" WHERE cfd.fk_element = ".((int) $this->
id);
2594 $sql .=
" AND cfd.fk_product = p.rowid";
2596 $sql .=
" AND cfd.status = ".((int) $status);
2598 $sql .=
" ORDER BY cfd.rowid ASC";
2600 $resql = $this->db->query($sql);
2602 $num = $this->db->num_rows($resql);
2606 $objp = $this->db->fetch_object($resql);
2609 'id' => $objp->dispatchedlineid,
2610 'productid' => $objp->fk_product,
2611 'warehouseid' => $objp->warehouse_id,
2612 'qty' => $objp->qty,
2613 'orderlineid' => $objp->fk_elementdet
2620 dol_print_error($this->db,
'Failed to execute request to get dispatched lines');
2639 global
$conf, $langs;
2643 $dispatchedlinearray = array();
2647 $usercanreceive = 0;
2648 if (!isModEnabled(
'reception')) {
2649 $usercanreceive = $user->hasRight(
"fournisseur",
"commande",
"receptionner");
2651 $usercanreceive = $user->hasRight(
"reception",
"creer");
2654 if ($usercanreceive) {
2656 if ($type ==
'par') {
2658 } elseif ($type ==
'tot') {
2660 } elseif ($type ==
'nev') {
2662 } elseif ($type ==
'can') {
2666 dol_syslog(get_class($this).
"::Livraison Error -2", LOG_ERR);
2673 if (!$error && ($type ==
'tot')) {
2675 if (count($dispatchedlinearray) > 0) {
2678 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove';
2679 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove', LOG_DEBUG);
2682 if (!$error &&
getDolGlobalString(
'SUPPLIER_ORDER_USE_DISPATCH_STATUS_NEED_APPROVE') && ($type ==
'tot')) {
2684 if (count($dispatchedlinearray) > 0) {
2687 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied';
2688 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied', LOG_DEBUG);
2695 if (empty($error)) {
2698 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2699 $sql .=
" SET fk_statut = ".((int) $statut);
2700 $sql .=
" WHERE rowid = ".((int) $this->
id);
2701 $sql .=
" AND fk_statut IN (".self::STATUS_ORDERSENT.
",".self::STATUS_RECEIVED_PARTIALLY.
")";
2703 dol_syslog(get_class($this).
"::Livraison", LOG_DEBUG);
2704 $resql = $this->db->query($sql);
2707 $old_statut = $this->statut;
2708 $this->statut = $statut;
2709 $this->context[
'actionmsg2'] = $comment;
2712 $result_trigger = $this->
call_trigger(
'ORDER_SUPPLIER_RECEIVE', $user);
2713 if ($result_trigger < 0) {
2718 if (empty($error)) {
2719 $this->db->commit();
2721 $this->statut = $old_statut;
2722 $this->db->rollback();
2723 $this->error = $this->db->lasterror();
2727 $this->db->rollback();
2728 $this->error = $this->db->lasterror();
2733 $this->error = $langs->trans(
'NotAuthorized');
2734 $this->errors[] = $langs->trans(
'NotAuthorized');
2735 dol_syslog(get_class($this).
"::Livraison Not Authorized");
2767 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
2772 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2773 $sql .=
" SET date_livraison = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2774 $sql .=
" WHERE rowid = ".((int) $this->
id);
2777 $resql = $this->db->query($sql);
2779 $this->errors[] = $this->db->error();
2784 $this->oldcopy = clone $this;
2785 $this->delivery_date = $delivery_date;
2788 if (!$notrigger && empty($error)) {
2790 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2798 $this->db->commit();
2801 foreach ($this->errors as $errmsg) {
2802 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2803 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2805 $this->db->rollback();
2825 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
2830 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2831 $sql .=
" SET fk_projet = ".($id_projet > 0 ? (int) $id_projet :
'null');
2832 $sql .=
" WHERE rowid = ".((int) $this->
id);
2835 $resql = $this->db->query($sql);
2837 $this->errors[] = $this->db->error();
2842 $this->oldcopy = clone $this;
2843 $this->fk_projet = $id_projet;
2844 $this->fk_project = $id_projet;
2847 if (!$notrigger && empty($error)) {
2849 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2857 $this->db->commit();
2860 foreach ($this->errors as $errmsg) {
2861 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2862 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2864 $this->db->rollback();
2882 $comclient =
new Commande($this->db);
2883 $comclient->fetch($comclientid);
2887 $this->lines = array();
2889 $num = count($comclient->lines);
2890 for ($i = 0; $i < $num; $i++) {
2891 $prod =
new Product($this->db);
2894 if ($prod->fetch($comclient->lines[$i]->fk_product) > 0) {
2895 $label = $prod->label;
2899 $sql =
"INSERT INTO ".$this->db->prefix().
"commande_fournisseurdet";
2900 $sql .=
" (fk_commande, label, description, fk_product, price, qty, tva_tx, localtax1_tx, localtax2_tx, remise_percent, subprice, remise, ref)";
2901 $sql .=
" VALUES (".((int) $idc).
", '".$this->db->escape($label).
"', '".$this->db->escape($comclient->lines[$i]->desc).
"'";
2902 $sql .=
",".$comclient->lines[$i]->fk_product.
", ".
price2num($comclient->lines[$i]->price,
'MU');
2903 $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);
2904 $sql .=
", '".price2num($comclient->lines[$i]->subprice,
'MT').
"','0', '".$this->db->escape($ref).
"');";
2905 if ($this->db->query($sql)) {
2922 global
$conf, $langs;
2927 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur';
2928 $sql .=
" SET fk_statut = ".$status;
2929 $sql .=
" WHERE rowid = ".((int) $this->
id);
2931 dol_syslog(get_class($this).
"::setStatus", LOG_DEBUG);
2932 $resql = $this->db->query($sql);
2935 $triggerName = array();
2936 $triggerName[0] =
'DRAFT';
2937 $triggerName[1] =
'VALIDATED';
2938 $triggerName[2] =
'APPROVED';
2939 $triggerName[3] =
'ORDERED';
2940 $triggerName[4] =
'RECEIVED_PARTIALLY';
2941 $triggerName[5] =
'RECEIVED_COMPLETELY';
2942 $triggerName[6] =
'CANCELED';
2943 $triggerName[7] =
'CANCELED';
2944 $triggerName[9] =
'REFUSED';
2947 $result = $this->
call_trigger(
"ORDER_SUPPLIER_STATUS_".$triggerName[$status], $user);
2954 $this->error = $this->db->lasterror();
2955 dol_syslog(get_class($this).
"::setStatus ".$this->error);
2959 $this->statut = $status;
2960 $this->db->commit();
2963 $this->db->rollback();
2991 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 =
'')
2993 global $mysoc,
$conf, $langs;
2994 dol_syslog(get_class($this).
"::updateline $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $type, $fk_unit");
2995 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2999 if ($this->statut == self::STATUS_DRAFT) {
3004 if (empty($info_bits)) {
3007 if (empty($txtva)) {
3010 if (empty($txlocaltax1)) {
3013 if (empty($txlocaltax2)) {
3016 if (empty($remise_percent)) {
3017 $remise_percent = 0;
3020 $remise_percent = (float)
price2num($remise_percent);
3026 $pu_ht_devise =
price2num($pu_ht_devise);
3027 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
3030 $txlocaltax1 = (float)
price2num($txlocaltax1);
3031 $txlocaltax2 = (float)
price2num($txlocaltax2);
3037 if ($date_start && $date_end && $date_start > $date_end) {
3038 $langs->load(
"errors");
3039 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
3055 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
3056 $vat_src_code = $reg[1];
3057 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
3060 $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);
3061 $total_ht = $tabprice[0];
3062 $total_tva = $tabprice[1];
3063 $total_ttc = $tabprice[2];
3064 $total_localtax1 = $tabprice[9];
3065 $total_localtax2 = $tabprice[10];
3066 $pu_ht = $tabprice[3];
3067 $pu_tva = $tabprice[4];
3068 $pu_ttc = $tabprice[5];
3071 $multicurrency_total_ht = $tabprice[16];
3072 $multicurrency_total_tva = $tabprice[17];
3073 $multicurrency_total_ttc = $tabprice[18];
3074 $pu_ht_devise = $tabprice[19];
3076 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
3077 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
3081 $this->line->fetch($rowid);
3083 $oldline = clone $this->line;
3084 $this->line->oldline = $oldline;
3086 $this->line->context = $this->context;
3088 $this->line->fk_commande = $this->id;
3090 $this->line->desc = $desc;
3094 if ($qty < $this->line->packaging) {
3095 $qty = $this->line->packaging;
3097 if (!empty($this->line->packaging) && ($qty % $this->line->packaging) > 0) {
3098 $coeff = intval($qty / $this->line->packaging) + 1;
3099 $qty = $this->line->packaging * $coeff;
3100 setEventMessage($langs->trans(
'QtyRecalculatedWithPackaging'),
'mesgs');
3105 $this->line->qty = $qty;
3106 $this->line->ref_supplier = $ref_supplier;
3108 $this->line->vat_src_code = $vat_src_code;
3109 $this->line->tva_tx = $txtva;
3110 $this->line->localtax1_tx = $txlocaltax1;
3111 $this->line->localtax2_tx = $txlocaltax2;
3112 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
3113 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
3114 $this->line->remise_percent = $remise_percent;
3115 $this->line->subprice = (float) $pu_ht;
3116 $this->line->info_bits = $info_bits;
3117 $this->line->total_ht = (float) $total_ht;
3118 $this->line->total_tva = (float) $total_tva;
3119 $this->line->total_localtax1 = (float) $total_localtax1;
3120 $this->line->total_localtax2 = (float) $total_localtax2;
3121 $this->line->total_ttc = (float) $total_ttc;
3122 $this->line->product_type = $type;
3123 $this->line->special_code = $oldline->special_code;
3124 $this->line->rang = $oldline->rang;
3125 $this->line->origin = $this->origin;
3126 $this->line->fk_unit = $fk_unit;
3128 $this->line->date_start = $date_start;
3129 $this->line->date_end = $date_end;
3132 $this->line->fk_multicurrency = $this->fk_multicurrency;
3133 $this->line->multicurrency_code = $this->multicurrency_code;
3134 $this->line->multicurrency_subprice = (float) $pu_ht_devise;
3135 $this->line->multicurrency_total_ht = (float) $multicurrency_total_ht;
3136 $this->line->multicurrency_total_tva = (float) $multicurrency_total_tva;
3137 $this->line->multicurrency_total_ttc = (float) $multicurrency_total_ttc;
3139 $this->line->subprice = (float) $pu_ht;
3140 $this->line->price = $this->line->subprice;
3142 $this->line->remise_percent = $remise_percent;
3144 if (is_array($array_options) && count($array_options) > 0) {
3146 foreach ($array_options as $key => $value) {
3147 $this->line->array_options[$key] = $array_options[$key];
3151 $result = $this->line->update($notrigger);
3157 $this->db->commit();
3160 $this->errors[] = $this->line->error;
3161 $this->errors = array_merge($this->errors, $this->line->errors);
3162 $this->error = $this->db->lasterror();
3163 $this->db->rollback();
3167 $this->error =
"Order status makes operation forbidden";
3168 dol_syslog(get_class($this).
"::updateline ".$this->error, LOG_ERR);
3183 global $user, $langs,
$conf;
3185 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
3187 dol_syslog(get_class($this).
"::initAsSpecimen");
3194 $sql =
"SELECT rowid";
3195 $sql .=
" FROM ".$this->db->prefix().
"product";
3196 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
3197 $sql .= $this->db->order(
"rowid",
"ASC");
3198 $sql .= $this->db->plimit(1);
3199 $resql = $this->db->query($sql);
3200 if ($resql && $this->db->num_rows($resql)) {
3201 $obj = $this->db->fetch_object($resql);
3202 $prodid = $obj->rowid;
3207 $this->
ref =
'SPECIMEN';
3208 $this->specimen = 1;
3211 $this->date_commande = $now;
3212 $this->date_lim_reglement = $this->date + 3600 * 24 * 30;
3213 $this->cond_reglement_code =
'RECEP';
3214 $this->mode_reglement_code =
'CHQ';
3216 $this->note_public =
'This is a comment (public)';
3217 $this->note_private =
'This is a comment (private)';
3219 $this->multicurrency_tx = 1;
3220 $this->multicurrency_code =
$conf->currency;
3228 while ($xnbp < $nbp) {
3230 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
3232 $line->subprice = 100;
3233 $line->tva_tx = 19.6;
3234 $line->localtax1_tx = 0;
3235 $line->localtax2_tx = 0;
3237 $line->total_ht = 50;
3238 $line->total_ttc = 59.8;
3239 $line->total_tva = 9.8;
3240 $line->remise_percent = 50;
3242 $line->total_ht = 100;
3243 $line->total_ttc = 119.6;
3244 $line->total_tva = 19.6;
3245 $line->remise_percent = 00;
3247 $line->fk_product = $prodid;
3249 $this->lines[$xnbp] = $line;
3251 $this->total_ht += $line->total_ht;
3252 $this->total_tva += $line->total_tva;
3253 $this->total_ttc += $line->total_ttc;
3269 $sql =
'SELECT c.rowid, date_creation as datec, tms as datem, date_valid as date_validation, date_approve as datea, date_approve2 as datea2,';
3270 $sql .=
' fk_user_author, fk_user_modif, fk_user_valid, fk_user_approve, fk_user_approve2';
3271 $sql .=
' FROM '.$this->db->prefix().
'commande_fournisseur as c';
3272 $sql .=
' WHERE c.rowid = '.((int) $id);
3274 $result = $this->db->query($sql);
3276 if ($this->db->num_rows($result)) {
3277 $obj = $this->db->fetch_object($result);
3279 $this->
id = $obj->rowid;
3281 $this->user_creation_id = $obj->fk_user_author;
3282 $this->user_validation_id = $obj->fk_user_valid;
3283 $this->user_modification_id = $obj->fk_user_modif;
3284 $this->user_approve_id = $obj->fk_user_approve;
3285 $this->user_approve_id2 = $obj->fk_user_approve2;
3287 $this->date_creation = $this->db->jdate($obj->datec);
3288 $this->date_modification = $this->db->jdate($obj->datem);
3289 $this->date_approve = $this->db->jdate($obj->datea);
3290 $this->date_approve2 = $this->db->jdate($obj->datea2);
3291 $this->date_validation = $this->db->jdate($obj->date_validation);
3293 $this->db->free($result);
3306 global
$conf, $user;
3308 $this->nb = array();
3311 $sql =
"SELECT count(co.rowid) as nb";
3312 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as co";
3313 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe as s ON co.fk_soc = s.rowid";
3314 if (empty($user->socid) && !$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3315 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
3316 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
3319 $sql .=
" ".$clause.
" co.entity IN (".
getEntity(
'supplier_order').
")";
3321 $resql = $this->db->query($sql);
3323 while ($obj = $this->db->fetch_object($resql)) {
3324 $this->nb[
"supplier_orders"] = $obj->nb;
3326 $this->db->free($resql);
3330 $this->error = $this->db->error();
3346 global
$conf, $langs;
3348 $sql =
"SELECT c.rowid, c.date_creation as datec, c.date_commande, c.fk_statut, c.date_livraison as delivery_date, c.total_ht";
3349 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as c";
3350 if (empty($user->socid) && !$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3351 $sql .=
" JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
3353 $sql .=
" WHERE c.entity = ".$conf->entity;
3354 if ($mode ===
'awaiting') {
3355 $sql .=
" AND c.fk_statut IN (".self::STATUS_ORDERSENT.
", ".self::STATUS_RECEIVED_PARTIALLY.
")";
3357 $sql .=
" AND c.fk_statut IN (".self::STATUS_VALIDATED.
", ".self::STATUS_ACCEPTED.
")";
3360 $sql .=
" AND c.fk_soc = ".((int) $user->socid);
3363 $resql = $this->db->query($sql);
3368 $response->warning_delay =
$conf->commande->fournisseur->warning_delay / 60 / 60 / 24;
3369 $response->label = $langs->trans(
"SuppliersOrdersToProcess");
3370 $response->labelShort = $langs->trans(
"Opened");
3371 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=1,2&mainmenu=commercial&leftmenu=orders_suppliers';
3372 $response->url_late = DOL_URL_ROOT.
'/fourn/commande/list.php?mainmenu=commercial&leftmenu=orders_suppliers&search_option=late';
3375 if ($mode ===
'awaiting') {
3376 $response->label = $langs->trans(
"SuppliersOrdersAwaitingReception");
3377 $response->labelShort = $langs->trans(
"AwaitingReception");
3378 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=3,4&mainmenu=commercial&leftmenu=orders_suppliers';
3381 while ($obj = $this->db->fetch_object($resql)) {
3382 $commandestatic->delivery_date = $this->db->jdate($obj->delivery_date);
3383 $commandestatic->date_commande = $this->db->jdate($obj->date_commande);
3384 $commandestatic->statut = $obj->fk_statut;
3386 $response->nbtodo++;
3387 $response->total += $obj->total_ht;
3389 if ($commandestatic->hasDelay()) {
3390 $response->nbtodolate++;
3396 $this->error = $this->db->error();
3411 if ($this->methode_commande_id > 0) {
3412 $sql =
"SELECT rowid, code, libelle as label";
3413 $sql .=
" FROM ".$this->db->prefix().
'c_input_method';
3414 $sql .=
" WHERE active=1 AND rowid = ".((int) $this->methode_commande_id);
3416 $resql = $this->db->query($sql);
3418 if ($this->db->num_rows($resql)) {
3419 $obj = $this->db->fetch_object($resql);
3421 $string = $langs->trans($obj->code);
3422 if ($string == $obj->code) {
3423 $string = $obj->label !=
'-' ? $obj->label :
'';
3446 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3448 global
$conf, $langs;
3453 if (!empty($this->model_pdf)) {
3454 $modele = $this->model_pdf;
3460 if (empty($modele)) {
3463 $langs->load(
"suppliers");
3464 $outputlangs->load(
"products");
3466 $modelpath =
"core/modules/supplier_order/doc/";
3467 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3480 if (empty($this->lines)) {
3487 foreach ($this->lines as $line) {
3488 if ($line->fk_product > 0) {
3490 $idp = $tmpproductfourn->find_min_price_product_fournisseur($line->fk_product, $line->qty, $this->thirdparty->id);
3493 if ($tmpproductfourn->delivery_time_days > $nb) {
3494 $nb = $tmpproductfourn->delivery_time_days;
3503 return $nb.
' '.$langs->trans(
'days');
3516 return $user->hasRight(
"fournisseur",
"commande");
3531 'commande_fournisseur'
3548 'commande_fournisseurdet'
3565 if ($this->statut == self::STATUS_ORDERSENT || $this->statut == self::STATUS_RECEIVED_PARTIALLY) {
3567 if (!empty($this->delivery_date)) {
3568 $date_to_test = $this->delivery_date;
3569 return $date_to_test && $date_to_test < ($now -
$conf->commande->fournisseur->warning_delay);
3577 $date_to_test = $this->date_commande;
3579 return ($this->statut > 0 && $this->statut < 5) && $date_to_test && $date_to_test < ($now -
$conf->commande->fournisseur->warning_delay);
3592 global
$conf, $langs;
3594 $langs->load(
'orders');
3598 if ($this->statut == self::STATUS_ORDERSENT || $this->statut == self::STATUS_RECEIVED_PARTIALLY) {
3599 if (!empty($this->delivery_date)) {
3600 $text = $langs->trans(
"DeliveryDate").
' '.
dol_print_date($this->delivery_date,
'day');
3602 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3605 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3608 $text .=
' '.($conf->commande->fournisseur->warning_delay > 0 ?
'+' :
'-').
' '.round(abs(
$conf->commande->fournisseur->warning_delay) / 3600 / 24, 1).
' '.$langs->trans(
"days").
' < '.$langs->trans(
"Today");
3625 if (isModEnabled(
"supplier_order")) {
3626 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
3628 $qtydelivered = array();
3629 $qtywished = array();
3633 $filter = array(
't.fk_element' => $this->
id);
3635 $filter[
't.status'] = 1;
3638 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
3640 $this->error = $supplierorderdispatch->error;
3641 $this->errors = $supplierorderdispatch->errors;
3644 if (is_array($supplierorderdispatch->lines) && count($supplierorderdispatch->lines) > 0) {
3645 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
3649 foreach ($supplierorderdispatch->lines as $line) {
3650 if (array_key_exists($line->fk_product, $qtydelivered)) {
3651 $qtydelivered[$line->fk_product] += $line->qty;
3653 $qtydelivered[$line->fk_product] = $line->qty;
3656 foreach ($this->lines as $line) {
3661 if (array_key_exists($line->fk_product, $qtywished)) {
3662 $qtywished[$line->fk_product] += $line->qty;
3664 $qtywished[$line->fk_product] = $line->qty;
3669 $diff_array = array_diff_assoc($qtydelivered, $qtywished);
3670 $keysinwishednotindelivered = array_diff(array_keys($qtywished), array_keys($qtydelivered));
3671 $keysindeliverednotinwished = array_diff(array_keys($qtydelivered), array_keys($qtywished));
3679 if (count($diff_array) == 0 && count($keysinwishednotindelivered) == 0 && count($keysindeliverednotinwished) == 0) {
3680 if ($closeopenorder) {
3682 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3690 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3701 if (count($diff_array) > 0) {
3705 foreach ($diff_array as $key => $value) {
3707 if ($qtydelivered[$key] >= $qtywished[$key]) {
3714 if ($close == count($diff_array)) {
3716 if ($closeopenorder) {
3717 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3724 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3732 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3740 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3762 $this->receptions = array();
3764 dol_syslog(get_class($this).
"::loadReceptions", LOG_DEBUG);
3766 $sql =
'SELECT cd.rowid, cd.fk_product,';
3767 $sql .=
' sum(cfd.qty) as qty';
3768 $sql .=
' FROM '.$this->db->prefix().
'receptiondet_batch as cfd,';
3769 if ($filtre_statut >= 0) {
3770 $sql .=
' '.$this->db->prefix().
'reception as e,';
3772 $sql .=
' '.$this->db->prefix().
'commande_fournisseurdet as cd';
3774 if ($filtre_statut >= 0) {
3775 $sql .=
' cfd.fk_reception = e.rowid AND';
3777 $sql .=
' cfd.fk_elementdet = cd.rowid';
3778 $sql .=
' AND cd.fk_commande ='.((int) $this->
id);
3779 if (isset($this->fk_product) && !empty($this->fk_product) > 0) {
3780 $sql .=
' AND cd.fk_product = '.((int) $this->fk_product);
3782 if ($filtre_statut >= 0) {
3783 $sql .=
' AND e.fk_statut >= '.((int) $filtre_statut);
3785 $sql .=
' GROUP BY cd.rowid, cd.fk_product';
3787 $resql = $this->db->query($sql);
3789 $num = $this->db->num_rows($resql);
3792 $obj = $this->db->fetch_object($resql);
3793 empty($this->receptions[$obj->rowid]) ? $this->receptions[$obj->rowid] = $obj->qty : $this->receptions[$obj->rowid] += $obj->qty;
3796 $this->db->free($resql);
3800 $this->error = $this->db->lasterror();
3816 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3818 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3819 $return .=
'<div class="info-box info-box-sm">';
3820 $return .=
'<span class="info-box-icon bg-infobox-action">';
3822 $return .=
'</span>';
3823 $return .=
'<div class="info-box-content">';
3824 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
3825 if ($selected >= 0) {
3826 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3828 if (property_exists($this,
'socid') || property_exists($this,
'total_tva')) {
3829 $return .=
'<br><span class="info-box-label amount">'.$this->socid.
'</span>';
3831 if (property_exists($this,
'billed')) {
3832 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Billed").
' : </span><span class="info-box-label">'.
yn($this->billed).
'</span>';
3834 if (method_exists($this,
'getLibStatut')) {
3835 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
3837 $return .=
'</div>';
3838 $return .=
'</div>';
3839 $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.