42require_once DOL_DOCUMENT_ROOT.
'/core/class/commonorder.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.orderline.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/subtotals/class/commonsubtotal.class.php';
48 require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
62 public $element =
'order_supplier';
67 public $table_element =
'commande_fournisseur';
72 public $table_element_line =
'commande_fournisseurdet';
77 public $class_element_line =
'CommandeFournisseurLigne';
82 public $fk_element =
'fk_commande';
87 public $picto =
'supplier_order';
93 public $restrictiononfksoc = 1;
113 public $ref_supplier;
161 public $date_approve;
167 public $date_approve2;
172 public $date_commande;
178 public $remise_percent;
182 public $methode_commande_id;
186 public $methode_commande;
191 public $delivery_date;
206 public $total_localtax1;
211 public $total_localtax2;
226 public $cond_reglement_id;
231 public $cond_reglement_code;
236 public $cond_reglement_label;
241 public $cond_reglement_doc;
247 public $deposit_percent;
257 public $mode_reglement_id;
262 public $mode_reglement_code;
267 public $mode_reglement;
272 public $user_author_id;
277 public $user_approve_id;
283 public $user_approve_id2;
298 public $extraparams = array();
303 public $lines = array();
323 public $date_lim_reglement;
328 public $receptions = array();
334 public $fk_multicurrency;
339 public $multicurrency_code;
344 public $multicurrency_tx;
349 public $multicurrency_total_ht;
354 public $multicurrency_total_tva;
359 public $multicurrency_total_ttc;
389 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => 0,
'notnull' => 1,
'position' => 10),
390 'ref' => array(
'type' =>
'varchar(255)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => 1,
'showoncombobox' => 1,
'position' => 25,
'searchall' => 1),
391 'ref_ext' => array(
'type' =>
'varchar(255)',
'label' =>
'RefExt',
'enabled' => 1,
'visible' => 0,
'position' => 35),
392 'ref_supplier' => array(
'type' =>
'varchar(255)',
'label' =>
'RefOrderSupplierShort',
'enabled' => 1,
'visible' => 1,
'position' => 40,
'searchall' => 1),
393 'fk_projet' => array(
'type' =>
'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)',
'label' =>
'Project',
'enabled' =>
"isModEnabled('project')",
'visible' => -1,
'position' => 45),
394 'date_valid' => array(
'type' =>
'datetime',
'label' =>
'DateValidation',
'enabled' => 1,
'visible' => -1,
'position' => 710),
395 'date_approve' => array(
'type' =>
'datetime',
'label' =>
'DateApprove',
'enabled' => 1,
'visible' => -1,
'position' => 720),
396 'date_approve2' => array(
'type' =>
'datetime',
'label' =>
'DateApprove2',
'enabled' => 1,
'visible' => 3,
'position' => 725),
397 'date_commande' => array(
'type' =>
'date',
'label' =>
'OrderDateShort',
'enabled' => 1,
'visible' => 1,
'position' => 70),
398 'date_livraison' => array(
'type' =>
'datetime',
'label' =>
'DeliveryDate',
'enabled' =>
'getDolGlobalInt("ORDER_DISABLE_DELIVERY_DATE") ? 0 : 1',
'visible' => 1,
'position' => 74),
399 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'visible' => 3,
'position' => 41),
400 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => 3,
'notnull' => -1,
'position' => 80),
401 'fk_user_valid' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserValidation',
'enabled' => 1,
'visible' => 3,
'position' => 711),
402 'fk_user_approve' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserApproval',
'enabled' => 1,
'visible' => 3,
'position' => 721),
403 'fk_user_approve2' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserApproval2',
'enabled' => 1,
'visible' => 3,
'position' => 726),
404 'source' => array(
'type' =>
'smallint(6)',
'label' =>
'Source',
'enabled' => 1,
'visible' => 3,
'notnull' => 1,
'position' => 100),
405 'billed' => array(
'type' =>
'smallint(6)',
'label' =>
'Billed',
'enabled' => 1,
'visible' => 1,
'position' => 710),
406 'total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'AmountHT',
'enabled' => 1,
'visible' => 1,
'position' => 130,
'isameasure' => 1),
407 'total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'AmountVAT',
'enabled' => 1,
'visible' => 1,
'position' => 135,
'isameasure' => 1),
408 'localtax1' => array(
'type' =>
'double(24,8)',
'label' =>
'LT1',
'enabled' => 1,
'visible' => 3,
'position' => 140,
'isameasure' => 1),
409 'localtax2' => array(
'type' =>
'double(24,8)',
'label' =>
'LT2',
'enabled' => 1,
'visible' => 3,
'position' => 145,
'isameasure' => 1),
410 'total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'AmountTTC',
'enabled' => 1,
'visible' => -1,
'position' => 150,
'isameasure' => 1),
411 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 750,
'searchall' => 1),
412 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 760,
'searchall' => 1),
413 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'ModelPDF',
'enabled' => 1,
'visible' => 0,
'position' => 165),
414 'fk_input_method' => array(
'type' =>
'integer',
'label' =>
'OrderMode',
'enabled' => 1,
'visible' => 3,
'position' => 170),
415 'fk_cond_reglement' => array(
'type' =>
'integer',
'label' =>
'PaymentTerm',
'enabled' => 1,
'visible' => 3,
'position' => 175),
416 'deposit_percent' => array(
'type' =>
'varchar(63)',
'label' =>
'DepositPercent',
'enabled' => 1,
'visible' => -1,
'position' => 176),
417 'fk_mode_reglement' => array(
'type' =>
'integer',
'label' =>
'PaymentMode',
'enabled' => 1,
'visible' => 3,
'position' => 180),
418 'extraparams' => array(
'type' =>
'varchar(255)',
'label' =>
'Extraparams',
'enabled' => 1,
'visible' => 0,
'position' => 190),
419 'fk_account' => array(
'type' =>
'integer',
'label' =>
'BankAccount',
'enabled' =>
'isModEnabled("bank")',
'visible' => 3,
'position' => 200),
420 'fk_incoterms' => array(
'type' =>
'integer',
'label' =>
'IncotermCode',
'enabled' => 1,
'visible' => 3,
'position' => 205),
421 'location_incoterms' => array(
'type' =>
'varchar(255)',
'label' =>
'IncotermLocation',
'enabled' => 1,
'visible' => 3,
'position' => 210),
422 'fk_multicurrency' => array(
'type' =>
'integer',
'label' =>
'Fk multicurrency',
'enabled' => 1,
'visible' => 0,
'position' => 215),
423 'multicurrency_code' => array(
'type' =>
'varchar(255)',
'label' =>
'Currency',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 220),
424 'multicurrency_tx' => array(
'type' =>
'double(24,8)',
'label' =>
'CurrencyRate',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 225),
425 'multicurrency_total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountHT',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 230),
426 'multicurrency_total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountVAT',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 235),
427 'multicurrency_total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountTTC',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 240),
428 'date_creation' => array(
'type' =>
'datetime',
'label' =>
'Date creation',
'enabled' => 1,
'visible' => -1,
'position' => 500),
429 'fk_soc' => array(
'type' =>
'integer:Societe:societe/class/societe.class.php',
'label' =>
'ThirdParty',
'enabled' =>
'isModEnabled("societe")',
'visible' => 1,
'notnull' => 1,
'position' => 50),
430 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => 0,
'notnull' => 1,
'position' => 1000,
'index' => 1),
431 'tms' => array(
'type' =>
'datetime',
'label' =>
"DateModificationShort",
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 501),
432 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'LastMainDoc',
'enabled' => 1,
'visible' => 0,
'position' => 700),
433 'fk_statut' => array(
'type' =>
'smallint(6)',
'label' =>
'Status',
'enabled' => 1,
'visible' => 1,
'position' => 701),
434 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => 0,
'position' => 900),
498 $this->ismultientitymanaged = 1;
509 public function fetch($id, $ref =
'')
512 if (empty($id) && empty($ref)) {
516 $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,";
517 $sql .=
" c.localtax1, c.localtax2, ";
518 $sql .=
" c.date_creation, c.date_valid, c.date_approve, c.date_approve2,";
519 $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,";
520 $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,";
521 $sql .=
" c.fk_account,";
522 $sql .=
" c.note_private, c.note_public, c.model_pdf, c.last_main_doc, c.extraparams, c.billed,";
523 $sql .=
" c.fk_multicurrency, c.multicurrency_code, c.multicurrency_tx, c.multicurrency_total_ht, c.multicurrency_total_tva, c.multicurrency_total_ttc,";
524 $sql .=
" cm.libelle as methode_commande,";
525 $sql .=
" cr.code as cond_reglement_code, cr.libelle as cond_reglement_label, cr.libelle_facture as cond_reglement_doc, c.deposit_percent,";
526 $sql .=
" p.code as mode_reglement_code, p.libelle as mode_reglement_libelle";
527 $sql .=
', c.fk_incoterms, c.location_incoterms';
528 $sql .=
', c.last_main_doc';
529 $sql .=
', i.libelle as label_incoterms';
530 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as c";
531 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_payment_term as cr ON c.fk_cond_reglement = cr.rowid";
532 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_paiement as p ON c.fk_mode_reglement = p.id";
533 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_input_method as cm ON cm.rowid = c.fk_input_method";
534 $sql .=
' LEFT JOIN '.$this->db->prefix().
'c_incoterms as i ON c.fk_incoterms = i.rowid';
537 $sql .=
" WHERE c.entity IN (".getEntity(
'supplier_order').
")";
539 $sql .=
" WHERE c.rowid=".((int) $id);
543 $sql .=
" AND c.ref='".$this->db->escape($ref).
"'";
546 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
547 $resql = $this->db->query($sql);
549 $obj = $this->db->fetch_object($resql);
551 $this->error =
'Bill with id '.$id.
' not found';
552 dol_syslog(get_class($this).
'::fetch '.$this->error);
556 $this->
id = $obj->rowid;
557 $this->entity = $obj->entity;
559 $this->
ref = $obj->ref;
560 $this->ref_supplier = $obj->ref_supplier;
562 $this->socid = $obj->fk_soc;
563 $this->thirdparty =
null;
565 $this->fourn_id = $obj->fk_soc;
566 $this->statut = $obj->status;
567 $this->
status = $obj->status;
568 $this->billed = $obj->billed;
569 $this->last_main_doc = $obj->last_main_doc;
570 $this->user_author_id = $obj->user_author_id;
571 $this->user_validation_id = $obj->user_validation_id;
572 $this->user_approve_id = $obj->user_approve_id;
573 $this->user_approve_id2 = $obj->user_approve_id2;
574 $this->total_ht = $obj->total_ht;
575 $this->total_tva = $obj->total_tva;
576 $this->total_localtax1 = $obj->localtax1;
577 $this->total_localtax2 = $obj->localtax2;
578 $this->total_ttc = $obj->total_ttc;
579 $this->date_creation = $this->db->jdate($obj->date_creation);
580 $this->date_valid = $this->db->jdate($obj->date_valid);
581 $this->date_approve = $this->db->jdate($obj->date_approve);
582 $this->date_approve2 = $this->db->jdate($obj->date_approve2);
583 $this->date_commande = $this->db->jdate($obj->date_commande);
584 if (isset($obj->date_commande)) {
585 $this->
date = $this->date_commande;
587 $this->
date = $this->date_creation;
589 $this->delivery_date = $this->db->jdate($obj->delivery_date);
590 $this->remise_percent = $obj->remise_percent;
591 $this->methode_commande_id = $obj->fk_input_method;
592 $this->methode_commande = $obj->methode_commande;
594 $this->source = $obj->source;
595 $this->fk_project = $obj->fk_project;
596 $this->cond_reglement_id = $obj->fk_cond_reglement;
597 $this->cond_reglement_code = $obj->cond_reglement_code;
598 $this->cond_reglement_label = $obj->cond_reglement_label;
599 $this->cond_reglement_doc = $obj->cond_reglement_doc;
600 $this->deposit_percent = $obj->deposit_percent;
601 $this->fk_account = $obj->fk_account;
602 $this->mode_reglement_id = $obj->fk_mode_reglement;
603 $this->mode_reglement_code = $obj->mode_reglement_code;
604 $this->mode_reglement = $obj->mode_reglement_libelle;
605 $this->note = $obj->note_private;
606 $this->note_private = $obj->note_private;
607 $this->note_public = $obj->note_public;
608 $this->model_pdf = $obj->model_pdf;
609 $this->last_main_doc = $obj->last_main_doc;
612 $this->fk_incoterms = $obj->fk_incoterms;
613 $this->location_incoterms = $obj->location_incoterms;
614 $this->label_incoterms = $obj->label_incoterms;
617 $this->fk_multicurrency = $obj->fk_multicurrency;
618 $this->multicurrency_code = $obj->multicurrency_code;
619 $this->multicurrency_tx = $obj->multicurrency_tx;
620 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
621 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
622 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
624 $this->extraparams = isset($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
626 $this->db->free($resql);
641 $this->error = $this->db->error().
" sql=".$sql;
657 $this->lines = array();
659 $sql =
"SELECT l.rowid, l.fk_commande, l.ref as ref_supplier, l.fk_product, l.product_type, l.label, l.description, l.qty,";
660 $sql .=
" l.vat_src_code, l.tva_tx, l.remise_percent, l.subprice, l.subprice_ttc,";
661 $sql .=
" l.localtax1_tx, l. localtax2_tx, l.localtax1_type, l. localtax2_type, l.total_localtax1, l.total_localtax2,";
662 $sql .=
" l.total_ht, l.total_tva, l.total_ttc, l.info_bits, l.special_code, l.fk_parent_line, l.rang,";
663 $sql .=
" p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.description as product_desc, p.tobatch as product_tobatch, p.barcode as product_barcode, p.stockable_product,";
664 $sql .=
" l.fk_unit, l.extraparams,";
665 $sql .=
" l.date_start, l.date_end,";
666 $sql .=
' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_subprice_ttc, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc';
667 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseurdet as l";
668 $sql .=
' LEFT JOIN '.$this->db->prefix().
'product as p ON l.fk_product = p.rowid';
669 $sql .=
" WHERE l.fk_commande = ".((int) $this->
id);
671 $sql .=
' AND p.fk_product_type = 0';
673 $sql .=
" ORDER BY l.rang, l.rowid";
676 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
678 $result = $this->db->query($sql);
680 $num = $this->db->num_rows($result);
684 $objp = $this->db->fetch_object($result);
688 $line->id = $objp->rowid;
689 $line->fk_commande = $objp->fk_commande;
690 $line->desc = $objp->description;
691 $line->description = $objp->description;
692 $line->qty = $objp->qty;
693 $line->tva_tx = $objp->tva_tx;
694 $line->localtax1_tx = $objp->localtax1_tx;
695 $line->localtax2_tx = $objp->localtax2_tx;
696 $line->localtax1_type = $objp->localtax1_type;
697 $line->localtax2_type = $objp->localtax2_type;
698 $line->subprice = $objp->subprice;
699 $line->pu_ht = $objp->subprice;
700 $line->subprice_ttc = $objp->subprice_ttc;
701 $line->pu_ttc = $objp->subprice_ttc;
702 $line->remise_percent = $objp->remise_percent;
704 $line->vat_src_code = $objp->vat_src_code;
705 $line->total_ht = $objp->total_ht;
706 $line->total_tva = $objp->total_tva;
707 $line->total_localtax1 = $objp->total_localtax1;
708 $line->total_localtax2 = $objp->total_localtax2;
709 $line->total_ttc = $objp->total_ttc;
710 $line->product_type = $objp->product_type;
712 $line->fk_product = $objp->fk_product;
714 $line->libelle = $objp->product_label;
715 $line->product_label = $objp->product_label;
716 $line->product_desc = $objp->product_desc;
717 $line->product_tobatch = $objp->product_tobatch;
718 $line->product_barcode = $objp->product_barcode;
719 $line->stockable_product = $objp->stockable_product;
721 $line->ref = $objp->product_ref;
722 $line->product_ref = $objp->product_ref;
723 $line->ref_fourn = $objp->ref_supplier;
724 $line->ref_supplier = $objp->ref_supplier;
731 $sqlsearchpackage =
'SELECT rowid, packaging FROM '.$this->db->prefix().
"product_fournisseur_price";
732 $sqlsearchpackage .=
' WHERE entity IN ('.getEntity(
'productsupplierprice').
")";
733 $sqlsearchpackage .=
" AND fk_product = ".((int) $objp->fk_product);
734 $sqlsearchpackage .=
" AND ref_fourn = '".$this->db->escape($objp->ref_supplier).
"'";
735 $sqlsearchpackage .=
" AND quantity <= ".abs((
float) $objp->qty);
736 $sqlsearchpackage .=
" AND (packaging IS NULL OR packaging = 0 OR packaging <= ".abs((
float) $objp->qty).
")";
737 $sqlsearchpackage .=
" AND fk_soc = ".((int) $this->socid);
738 $sqlsearchpackage .=
" ORDER BY packaging ASC";
739 $sqlsearchpackage .=
" LIMIT 1";
741 $resqlsearchpackage = $this->db->query($sqlsearchpackage);
742 if ($resqlsearchpackage) {
743 $objsearchpackage = $this->db->fetch_object($resqlsearchpackage);
744 if ($objsearchpackage) {
745 $line->fk_fournprice = $objsearchpackage->rowid;
746 $line->packaging = (float) $objsearchpackage->packaging;
749 $this->error = $this->db->lasterror();
754 $line->date_start = $this->db->jdate($objp->date_start);
755 $line->date_end = $this->db->jdate($objp->date_end);
756 $line->fk_unit = $objp->fk_unit;
758 $line->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams,
true) : array();
761 $line->fk_multicurrency = $objp->fk_multicurrency;
762 $line->multicurrency_code = $objp->multicurrency_code;
763 $line->multicurrency_subprice = $objp->multicurrency_subprice;
764 $line->multicurrency_subprice_ttc = $objp->multicurrency_subprice_ttc;
765 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
766 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
767 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
769 $line->info_bits = $objp->info_bits;
770 $line->special_code = $objp->special_code;
771 $line->fk_parent_line = $objp->fk_parent_line;
773 $line->rang = $objp->rang;
777 $line->fetch_optionals();
779 $this->lines[$i] = $line;
783 $this->db->free($result);
787 $this->error = $this->db->error().
" sql=".$sql;
800 public function valid($user, $idwarehouse = 0, $notrigger = 0)
803 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
809 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")))
810 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"fournisseur",
"supplier_order_advance",
"validate"))) {
814 dol_syslog(get_class($this).
"::valid checkActiveProductInLines ".$this->error, LOG_INFO);
819 $soc->fetch((
int) $this->fourn_id);
822 if (preg_match(
'/^[\(]?PROV/i', (
string) $this->
ref) || empty($this->ref)) {
823 $num = $this->getNextNumRef($soc);
825 $num = (
string) $this->ref;
829 $sql =
'UPDATE '.$this->db->prefix().
"commande_fournisseur";
830 $sql .=
" SET ref='".$this->db->escape($num).
"',";
831 $sql .=
" fk_statut = ".((int) self::STATUS_VALIDATED).
",";
832 $sql .=
" date_valid='".$this->db->idate(
dol_now()).
"',";
833 $sql .=
" fk_user_valid = ".((int) $user->id);
834 $sql .=
" WHERE rowid = ".((int) $this->
id);
835 $sql .=
" AND fk_statut = ".((int) self::STATUS_DRAFT);
837 $resql = $this->db->query($sql);
843 if (!$error && !$notrigger) {
845 $result = $this->call_trigger(
'ORDER_SUPPLIER_VALIDATE', $user);
853 $this->oldref = $this->ref;
856 if (preg_match(
'/^[\(]?PROV/i', $this->ref)) {
858 $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).
"'";
859 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->ref).
"%' AND filepath = 'fournisseur/commande/".$this->db->escape($this->ref).
"' and entity = ".((int)
$conf->entity);
860 $resql = $this->db->query($sql);
863 $this->error = $this->db->lasterror();
865 $sql =
'UPDATE '.$this->db->prefix().
"ecm_files set filepath = 'fournisseur/commande/".$this->db->escape($this->newref).
"'";
866 $sql .=
" WHERE filepath = 'fournisseur/commande/".$this->db->escape($this->ref).
"' and entity = ".((int)
$conf->entity);
867 $resql = $this->db->query($sql);
870 $this->error = $this->db->lasterror();
876 $dirsource =
$conf->fournisseur->commande->dir_output.
'/'.$oldref;
877 $dirdest =
$conf->fournisseur->commande->dir_output.
'/'.$newref;
878 if (!$error && file_exists($dirsource)) {
879 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
881 if (@rename($dirsource, $dirdest)) {
884 $listoffiles =
dol_dir_list(
$conf->fournisseur->commande->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
885 foreach ($listoffiles as $fileentry) {
886 $dirsource = $fileentry[
'name'];
887 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
888 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
889 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
890 @rename($dirsource, $dirdest);
908 $this->db->rollback();
912 $this->error =
'NotAuthorized';
913 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
938 public function LibStatut($status, $mode = 0, $billed = 0)
941 global $langs, $hookmanager;
943 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
944 $langs->load(
'orders');
946 $this->labelStatus[0] =
'StatusSupplierOrderDraft';
947 $this->labelStatus[1] =
'StatusSupplierOrderValidated';
948 $this->labelStatus[2] =
'StatusSupplierOrderApproved';
950 $this->labelStatus[3] =
'StatusSupplierOrderOnProcess';
952 $this->labelStatus[3] =
'StatusSupplierOrderOnProcessWithValidation';
954 $this->labelStatus[4] =
'StatusSupplierOrderReceivedPartially';
955 $this->labelStatus[5] =
'StatusSupplierOrderReceivedAll';
956 $this->labelStatus[6] =
'StatusSupplierOrderCanceled';
957 $this->labelStatus[7] =
'StatusSupplierOrderCanceled';
958 $this->labelStatus[9] =
'StatusSupplierOrderRefused';
961 $this->labelStatusShort[0] =
'StatusSupplierOrderDraftShort';
962 $this->labelStatusShort[1] =
'StatusSupplierOrderValidatedShort';
963 $this->labelStatusShort[2] =
'StatusSupplierOrderApprovedShort';
964 $this->labelStatusShort[3] =
'StatusSupplierOrderOnProcessShort';
965 $this->labelStatusShort[4] =
'StatusSupplierOrderReceivedPartiallyShort';
966 $this->labelStatusShort[5] =
'StatusSupplierOrderReceivedAllShort';
967 $this->labelStatusShort[6] =
'StatusSupplierOrderCanceledShort';
968 $this->labelStatusShort[7] =
'StatusSupplierOrderCanceledShort';
969 $this->labelStatusShort[9] =
'StatusSupplierOrderRefusedShort';
972 $statustrans = array(
984 $statusClass =
'status0';
985 if (!empty($statustrans[$status])) {
986 $statusClass = $statustrans[$status];
991 $billedtext =
' - '.$langs->trans(
"Billed");
993 if ($status == 5 && $billed) {
994 $statusClass =
'status6';
997 $statusLong = $langs->transnoentitiesnoconv($this->labelStatus[$status]).$billedtext;
998 $statusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
1000 $parameters = array(
'status' => $status,
'mode' => $mode,
'billed' => $billed);
1001 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
1003 return $hookmanager->resPrint;
1006 return dolGetStatus($statusLong, $statusShort,
'', $statusClass, $mode);
1017 global
$conf, $langs, $user;
1019 $langs->loadLangs([
'bills',
'orders']);
1022 $nofetch = !empty($params[
'nofetch']);
1024 if ($user->hasRight(
"fournisseur",
"commande",
"read")) {
1025 $datas[
'picto'] =
'<u class="paddingrightonly">'.$langs->trans(
"SupplierOrder").
'</u>';
1027 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
1029 if (!empty($this->
ref)) {
1030 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1032 if (!empty($this->ref_supplier)) {
1033 $datas[
'refsupplier'] =
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.$this->ref_supplier;
1036 $langs->load(
'companies');
1037 if (empty($this->thirdparty)) {
1040 $datas[
'supplier'] =
'<br><b>'.$langs->trans(
'Supplier').
':</b> '.$this->thirdparty->getNomUrl(1,
'', 0, 1);
1042 if (!empty($this->total_ht)) {
1043 $datas[
'totalht'] =
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1,
$conf->currency);
1045 if (!empty($this->total_tva)) {
1046 $datas[
'totaltva'] =
'<br><b>'.$langs->trans(
'VAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1,
$conf->currency);
1048 if (!empty($this->total_ttc)) {
1049 $datas[
'totalttc'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency);
1051 if (!empty($this->
date)) {
1052 $datas[
'date'] =
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->
date,
'day');
1054 if (!empty($this->delivery_date)) {
1055 $langs->load(
"sendings");
1056 $datas[
'deliverydate'] =
'<br><b>'.$langs->trans(
'DeliveryDate').
':</b> '.
dol_print_date($this->delivery_date,
'dayhour');
1072 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = 0)
1074 global $langs, $user, $hookmanager;
1079 'objecttype' => $this->element,
1080 'option' => $option,
1083 $classfortooltip =
'classfortooltip';
1086 $classfortooltip =
'classforajaxtooltip';
1087 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1093 $url = DOL_URL_ROOT.
'/fourn/commande/card.php?id='.$this->id;
1095 if ($option !==
'nolink') {
1097 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1098 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1099 $add_save_lastsearch_values = 1;
1101 if ($add_save_lastsearch_values) {
1102 $url .=
'&save_lastsearch_values=1';
1107 if (empty($notooltip)) {
1109 $label = $langs->trans(
"ShowOrder");
1110 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1112 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1113 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
1116 $linkstart =
'<a href="'.$url.
'"';
1117 $linkstart .= $linkclose.
'>';
1120 $result .= $linkstart;
1122 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
1124 if ($withpicto != 2) {
1125 $result .= $this->ref;
1127 $result .= $linkend;
1129 if ($addlinktonotes) {
1130 $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
1133 $result .=
' <span class="note inline-block">';
1134 $result .=
'<a href="'.DOL_URL_ROOT.
'/fourn/commande/note.php?id='.$this->
id.
'" class="classfortooltip" title="'.
dol_escape_htmltag($notetoshow).
'">';
1139 $result .=
'</span>';
1144 $hookmanager->initHooks(array($this->element .
'dao'));
1145 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1146 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1148 $result = $hookmanager->resPrint;
1150 $result .= $hookmanager->resPrint;
1163 public function getNextNumRef($soc)
1165 global $langs,
$conf;
1166 $langs->load(
"orders");
1175 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
1177 foreach ($dirmodels as $reldir) {
1178 $dir =
dol_buildpath($reldir.
"core/modules/supplier_order/");
1181 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1189 $obj =
new $classname();
1190 '@phan-var-force ModeleNumRefSuppliersOrders $obj';
1192 $numref = $obj->getNextValue($soc, $this);
1194 if ($numref !=
"") {
1197 $this->error = $obj->error;
1201 $this->error =
"Error_COMMANDE_SUPPLIER_ADDON_NotDefined";
1216 if ($this->billed) {
1222 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur SET billed = 1';
1225 if ($this->db->query($sql)) {
1227 $result = $this->call_trigger(
'ORDER_SUPPLIER_CLASSIFY_BILLED', $user);
1236 $this->db->commit();
1239 $this->db->rollback();
1245 $this->db->rollback();
1259 if (empty($this->billed)) {
1265 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur SET billed = 0';
1269 if (!$this->db->query($sql)) {
1271 $this->db->rollback();
1276 $result = $this->call_trigger(
'ORDER_SUPPLIER_CLASSIFY_UNBILLED', $user);
1278 $this->db->rollback();
1284 $this->db->commit();
1297 public function approve($user, $idwarehouse = 0, $secondlevel = 0)
1301 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1307 if ($user->hasRight(
"fournisseur",
"commande",
"approuver")) {
1313 $soc =
new Societe($this->db);
1314 $soc->fetch((
int) $this->fourn_id);
1317 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
1318 $num = $this->getNextNumRef($soc);
1325 $movetoapprovestatus =
true;
1328 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1329 $sql .=
" SET ref='".$this->db->escape($num).
"',";
1330 if (empty($secondlevel)) {
1331 $sql .=
" date_approve='".$this->db->idate($now).
"',";
1332 $sql .=
" fk_user_approve = ".((int) $user->id);
1334 if (empty($this->user_approve_id2)) {
1335 $movetoapprovestatus =
false;
1336 $comment =
' (first level)';
1340 $sql .=
" date_approve2='".$this->db->idate($now).
"',";
1341 $sql .=
" fk_user_approve2 = ".((int) $user->id);
1342 if (empty($this->user_approve_id)) {
1343 $movetoapprovestatus =
false;
1345 $comment =
' (second level)';
1348 if ($movetoapprovestatus) {
1349 $sql .=
", fk_statut = ".self::STATUS_ACCEPTED;
1351 $sql .=
", fk_statut = ".self::STATUS_VALIDATED;
1353 $sql .=
" WHERE rowid = ".((int) $this->
id);
1354 $sql .=
" AND fk_statut = ".self::STATUS_VALIDATED;
1356 if ($this->db->query($sql)) {
1358 $result = $this->
add_contact($user->id,
'SALESREPFOLL',
'internal', 1);
1359 if ($result < 0 && $result != -2) {
1366 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1367 $langs->load(
"agenda");
1369 $cpt = count($this->lines);
1370 for ($i = 0; $i < $cpt; $i++) {
1372 if ($this->lines[$i]->fk_product > 0) {
1373 $this->line = $this->lines[$i];
1375 $mouvP->origin = &$this;
1376 $mouvP->setOrigin($this->element, $this->
id);
1378 $up_ht_disc = $this->lines[$i]->subprice;
1379 if (!empty($this->lines[$i]->remise_percent) && !
getDolGlobalString(
'STOCK_EXCLUDE_DISCOUNT_FOR_PMP')) {
1380 $up_ht_disc =
price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100,
'MU');
1382 $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans(
"OrderApprovedInDolibarr", $this->ref));
1393 $result = $this->call_trigger(
'ORDER_SUPPLIER_APPROVE', $user);
1401 $this->
ref = $this->newref;
1403 if ($movetoapprovestatus) {
1410 if (empty($secondlevel)) {
1411 $this->date_approve = $now;
1412 $this->user_approve_id = $user->id;
1414 $this->date_approve2 = $now;
1415 $this->user_approve_id2 = $user->id;
1418 $this->db->commit();
1421 $this->db->rollback();
1425 $this->db->rollback();
1426 $this->error = $this->db->lasterror();
1430 dol_syslog(get_class($this).
"::approve Not Authorized", LOG_ERR);
1447 if ($user->hasRight(
"fournisseur",
"commande",
"approuver")) {
1450 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur SET fk_statut = ".
self::STATUS_REFUSED;
1451 $sql .=
" WHERE rowid = ".((int) $this->
id);
1453 if ($this->db->query($sql)) {
1458 $result = $this->call_trigger(
'ORDER_SUPPLIER_REFUSE', $user);
1461 $this->db->rollback();
1463 $this->db->commit();
1468 $this->db->rollback();
1469 $this->error = $this->db->lasterror();
1470 dol_syslog(get_class($this).
"::refuse Error -1");
1474 dol_syslog(get_class($this).
"::refuse Not Authorized");
1488 public function cancel($user, $idwarehouse = -1)
1495 if ($user->hasRight(
"fournisseur",
"commande",
"commander")) {
1500 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur SET fk_statut = ".((int) $statut);
1501 $sql .=
" WHERE rowid = ".((int) $this->
id);
1502 dol_syslog(get_class($this).
"::cancel", LOG_DEBUG);
1503 if ($this->db->query($sql)) {
1507 $result = $this->call_trigger(
'ORDER_SUPPLIER_CANCEL', $user);
1514 $this->db->commit();
1517 $this->db->rollback();
1521 $this->db->rollback();
1522 $this->error = $this->db->lasterror();
1523 dol_syslog(get_class($this).
"::cancel ".$this->error);
1527 dol_syslog(get_class($this).
"::cancel Not Authorized");
1541 public function commande($user, $date, $methode, $comment =
'')
1546 if ($user->hasRight(
"fournisseur",
"commande",
"commander")) {
1549 $newnoteprivate = $this->note_private;
1551 $newnoteprivate =
dol_concatdesc($newnoteprivate, $langs->trans(
"Comment").
': '.$comment);
1554 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1555 $sql .=
" SET fk_statut=".self::STATUS_ORDERSENT.
", fk_input_method=".((int) $methode).
", date_commande='".$this->db->idate($date).
"', ";
1556 $sql .=
" note_private='".$this->db->escape((
string) $newnoteprivate).
"'";
1557 $sql .=
" WHERE rowid=".((int) $this->
id);
1559 dol_syslog(get_class($this).
"::commande", LOG_DEBUG);
1560 if ($this->db->query($sql)) {
1563 $this->methode_commande_id = $methode;
1564 $this->date_commande = $date;
1565 $this->context[
'comments'] = $comment;
1568 $result = $this->call_trigger(
'ORDER_SUPPLIER_SUBMIT', $user);
1575 $this->error = $this->db->lasterror();
1576 $this->errors[] = $this->db->lasterror();
1580 $this->db->commit();
1582 $this->db->rollback();
1586 $this->error = $langs->trans(
'NotAuthorized');
1587 $this->errors[] = $langs->trans(
'NotAuthorized');
1588 dol_syslog(get_class($this).
"::commande User not Authorized", LOG_WARNING);
1591 return ($error ? -1 : 1);
1601 public function create($user, $notrigger = 0)
1611 $date = ($this->date_commande ? $this->date_commande : $this->date);
1615 $delivery_date = $this->delivery_date;
1618 if (empty($this->source)) {
1623 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
1628 if (empty($this->fk_multicurrency)) {
1629 $this->multicurrency_code =
$conf->currency;
1630 $this->fk_multicurrency = 0;
1631 $this->multicurrency_tx = 1;
1639 $sql =
"INSERT INTO ".$this->db->prefix().
"commande_fournisseur (";
1641 $sql .=
", ref_supplier";
1642 $sql .=
", note_private";
1643 $sql .=
", note_public";
1646 $sql .=
", fk_projet";
1647 $sql .=
", date_creation";
1648 $sql .=
", date_livraison";
1649 $sql .=
", fk_user_author";
1650 $sql .=
", fk_statut";
1652 $sql .=
", model_pdf";
1653 $sql .=
", fk_mode_reglement";
1654 $sql .=
", deposit_percent";
1655 $sql .=
", fk_cond_reglement";
1656 $sql .=
", fk_account";
1657 $sql .=
", fk_incoterms, location_incoterms";
1658 $sql .=
", fk_multicurrency";
1659 $sql .=
", multicurrency_code";
1660 $sql .=
", multicurrency_tx";
1662 $sql .=
" VALUES (";
1664 $sql .=
", ".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"NULL");
1665 $sql .=
", '".$this->db->escape($this->note_private).
"'";
1666 $sql .=
", '".$this->db->escape($this->note_public).
"'";
1667 $sql .=
", ".((int) $this->entity);
1668 $sql .=
", ".((int) $this->socid);
1669 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
1670 $sql .=
", '".$this->db->idate($date).
"'";
1671 $sql .=
", ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
"null");
1672 $sql .=
", ".((int) $user->id);
1673 $sql .=
", ".self::STATUS_DRAFT;
1674 $sql .=
", ".((int) $this->source);
1675 $sql .=
", '".$this->db->escape(
getDolGlobalString(
'COMMANDE_SUPPLIER_ADDON_PDF')).
"'";
1676 $sql .=
", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) :
'null');
1677 $sql .=
", ".(!empty($this->deposit_percent) ?
"'" . $this->db->escape($this->deposit_percent) .
"'" :
"null");
1678 $sql .=
", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) :
'null');
1679 $sql .=
", ".($this->fk_account > 0 ? ((int) $this->fk_account) :
'NULL');
1680 $sql .=
", ".(int) $this->fk_incoterms;
1681 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
1682 $sql .=
", ".(int) $this->fk_multicurrency;
1683 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1684 $sql .=
", ".(float) $this->multicurrency_tx;
1687 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1688 if ($this->db->query($sql)) {
1689 $this->
id = $this->db->last_insert_id($this->db->prefix().
"commande_fournisseur");
1692 $num = count($this->lines);
1695 for ($i = 0; $i < $num; $i++) {
1696 $line = $this->lines[$i];
1697 if (!is_object($line)) {
1698 $line = (object) $line;
1705 (
string) $line->desc,
1706 (
float) $line->subprice,
1709 (
float) $line->localtax1_tx,
1710 (
float) $line->localtax2_tx,
1711 (
int) $line->fk_product,
1713 (
string) ($line->ref_supplier ? $line->ref_supplier : $line->ref_fourn),
1714 (
float) $line->remise_percent,
1716 (float) $line->subprice_ttc,
1717 (
int) $line->product_type,
1718 (int) $line->info_bits,
1720 $line->date_start ??
null,
1721 $line->date_end ??
null,
1722 $line->array_options ?? [],
1723 $line->fk_unit ??
null,
1724 (
float) $line->multicurrency_subprice,
1726 (
int) $line->origin_id,
1727 (int) ($line->rang ?? -1),
1728 (int) $line->special_code,
1729 isset($line->product_label) ? $line->product_label :
''
1732 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
1733 $this->db->rollback();
1738 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1739 $sql .=
" SET ref='(PROV".((int) $this->
id).
")'";
1740 $sql .=
" WHERE rowid=".((int) $this->
id);
1742 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1743 if ($this->db->query($sql)) {
1746 $this->
ref =
"(PROV".$this->id.
")";
1748 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
1749 $this->linked_objects = $this->linkedObjectsIds;
1753 if (!empty($this->linked_objects) && is_array($this->linked_objects)) {
1754 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
1755 if (is_array($tmp_origin_id)) {
1756 foreach ($tmp_origin_id as $origin_id) {
1764 $origin_id = $tmp_origin_id;
1782 if (!$error && !$notrigger) {
1784 $result = $this->call_trigger(
'ORDER_SUPPLIER_CREATE', $user);
1786 $this->db->rollback();
1793 $this->db->commit();
1796 $this->error = $this->db->lasterror();
1797 $this->db->rollback();
1802 $this->error =
'Failed to get ID of inserted line';
1807 $this->error = $this->db->lasterror();
1808 $this->db->rollback();
1826 if (isset($this->
ref)) {
1827 $this->
ref = trim($this->
ref);
1829 if (isset($this->ref_supplier)) {
1830 $this->ref_supplier = trim($this->ref_supplier);
1832 if (isset($this->note_private)) {
1833 $this->note_private = trim($this->note_private);
1835 if (isset($this->note_public)) {
1836 $this->note_public = trim($this->note_public);
1838 if (isset($this->model_pdf)) {
1839 $this->model_pdf = trim($this->model_pdf);
1841 if (isset($this->import_key)) {
1842 $this->import_key = trim($this->import_key);
1846 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
1848 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1849 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
1850 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1851 $sql .=
" fk_soc=".(isset($this->socid) ? ((int) $this->socid) :
"null").
",";
1852 $sql .=
" date_commande=".(strval($this->date_commande) !=
'' ?
"'".$this->db->idate($this->date_commande).
"'" :
'null').
",";
1853 $sql .=
" date_valid=".(strval($this->date_validation) !=
'' ?
"'".$this->db->idate($this->date_validation).
"'" :
'null').
",";
1854 $sql .=
" total_tva=".(isset($this->total_tva) ? ((float) $this->total_tva) :
"null").
",";
1855 $sql .=
" localtax1=".(isset($this->total_localtax1) ? ((float) $this->total_localtax1) :
"null").
",";
1856 $sql .=
" localtax2=".(isset($this->total_localtax2) ? ((float) $this->total_localtax2) :
"null").
",";
1857 $sql .=
" total_ht=".(isset($this->total_ht) ? ((float) $this->total_ht) :
"null").
",";
1858 $sql .=
" total_ttc=".(isset($this->total_ttc) ? ((float) $this->total_ttc) :
"null").
",";
1859 $sql .=
" fk_statut=".(isset($this->
status) ? ((int) $this->
status) :
"null").
",";
1860 $sql .=
" fk_user_author=".(isset($this->user_author_id) ? ((int) $this->user_author_id) :
"null").
",";
1861 $sql .=
" fk_user_valid=".(isset($this->user_validation_id) && $this->user_validation_id > 0 ? ((int) $this->user_validation_id) :
"null").
",";
1862 $sql .=
" fk_projet=".((!empty($this->fk_project) && $this->fk_project > 0) ? ((
int) $this->fk_project) :
"null").
",";
1863 $sql .=
" fk_cond_reglement=".(isset($this->cond_reglement_id) ? ((int) $this->cond_reglement_id) :
"null").
",";
1864 $sql .=
" deposit_percent=".(!empty($this->deposit_percent) ?
"'".$this->db->escape($this->deposit_percent).
"'" :
"null").
",";
1865 $sql .=
" fk_mode_reglement=".(isset($this->mode_reglement_id) ? ((int) $this->mode_reglement_id) :
"null").
",";
1866 $sql .=
" date_livraison=".(strval($this->delivery_date) !=
'' ?
"'".$this->db->idate($this->delivery_date).
"'" :
'null').
",";
1868 $sql .=
" fk_account=".($this->fk_account > 0 ? ((int) $this->fk_account) :
"null").
",";
1870 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1871 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1872 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1873 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
1875 $sql .=
" WHERE rowid=".((int) $this->
id);
1879 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1880 $resql = $this->db->query($sql);
1883 $this->errors[] =
"Error ".$this->db->lasterror();
1893 if (!$error && !$notrigger) {
1895 $result = $this->call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
1904 foreach ($this->errors as $errmsg) {
1905 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1906 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1908 $this->db->rollback();
1911 $this->db->commit();
1926 global
$conf, $user, $hookmanager;
1933 foreach ($this->lines as $line) {
1934 $line->fetch_optionals();
1938 $objFrom = clone $this;
1941 if (!empty($socid) && $socid != $this->socid) {
1942 $objsoc =
new Societe($this->db);
1944 if ($objsoc->fetch($socid) > 0) {
1945 $this->socid = $objsoc->id;
1946 $this->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1947 $this->deposit_percent = (!empty($objsoc->deposit_percent) ? $objsoc->deposit_percent :
'0');
1948 $this->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1949 $this->fk_project = 0;
1950 $this->fk_delivery_address = 0;
1961 $this->user_author_id = $user->id;
1962 $this->user_validation_id = 0;
1965 $this->date_creation = 0;
1966 $this->date_validation = 0;
1967 $this->date_commande =
null;
1968 $this->ref_supplier =
'';
1969 $this->user_approve_id = 0;
1970 $this->user_approve_id2 = 0;
1971 $this->date_approve = 0;
1972 $this->date_approve2 = 0;
1975 $this->context[
'createfromclone'] =
'createfromclone';
1976 $result = $this->
create($user, $notrigger);
1983 if (is_object($hookmanager)) {
1984 $parameters = array(
'objFrom' => $objFrom);
1986 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1994 unset($this->context[
'createfromclone']);
1998 $this->db->commit();
2001 $this->db->rollback();
2036 public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0.0, $txlocaltax2 = 0.0, $fk_product = 0, $fk_prod_fourn_price = 0, $ref_supplier =
'', $remise_percent = 0.0, $price_base_type =
'HT', $pu_ttc = 0.0, $type = 0, $info_bits = 0, $notrigger = 0,
$date_start =
null, $date_end =
null, $array_options = [], $fk_unit =
null, $pu_ht_devise = 0, $origin =
'', $origin_id = 0, $rang = -1, $special_code = 0, $label =
'')
2040 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");
2041 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2043 if ($this->
status == self::STATUS_DRAFT) {
2044 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2053 if (empty($txtva)) {
2059 if (empty($txlocaltax1)) {
2062 if (empty($txlocaltax2)) {
2065 if (empty($remise_percent)) {
2066 $remise_percent = 0;
2069 $remise_percent =
price2num($remise_percent);
2072 $pu_ht_devise =
price2num($pu_ht_devise);
2074 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
2079 if ($price_base_type ==
'HT') {
2085 $label = trim((
string) $label);
2086 $desc = trim((
string) $desc);
2087 if ($desc ===
'' && $label !==
'') {
2092 if ($qty < 0 && !$fk_product) {
2093 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Product"));
2100 $langs->load(
"errors");
2101 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
2108 $product_type = $type;
2111 if ($fk_product > 0) {
2112 if (
getDolGlobalInt(
'SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY') == 1) {
2114 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);
2116 if (
$prod->fetch($fk_product) > 0) {
2117 $product_type =
$prod->type;
2118 $label =
$prod->label;
2122 $result =
$prod->get_buyprice($fk_prod_fourn_price, (
float) $qty, $fk_product,
'none', (isset($this->fk_soc) ? $this->fk_soc : $this->socid));
2126 if ($result > 0 && ($origin ==
'commande' || $pu ===
'')) {
2127 $pu =
$prod->fourn_pu;
2128 $ref_supplier =
$prod->ref_supplier;
2130 if ($remise_percent == 0 &&
$prod->remise_percent != 0) {
2131 $remise_percent =
$prod->remise_percent;
2135 $langs->load(
"errors");
2136 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
2137 $this->db->rollback();
2138 dol_syslog(get_class($this).
"::addline we did not found supplier price, so we can't guess unit price");
2143 if ($result == -1) {
2144 $langs->load(
"errors");
2145 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
2146 $this->db->rollback();
2147 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_DEBUG);
2151 $this->error =
$prod->error;
2152 $this->db->rollback();
2153 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_ERR);
2157 $this->error =
$prod->error;
2158 $this->db->rollback();
2166 $prod->get_buyprice($fk_prod_fourn_price, (
float) $qty, $fk_product,
'none', (empty($this->fk_soc) ? $this->socid : $this->fk_soc));
2171 if ($newqty != $qty) {
2173 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'warnings');
2181 if (!empty(
$prod->fourn_qty) && (
float) $qty > 0 && (
float) $qty < (
float)
$prod->fourn_qty) {
2182 if (!empty(
$prod->packaging) && (
float)
price2num(fmod((
float)
$prod->fourn_qty, (
float)
$prod->packaging),
'MS')) {
2183 $coeff = intval((
float)
$prod->fourn_qty / (
float)
$prod->packaging) + 1;
2184 $qty = (float)
price2num((
float)
$prod->packaging * $coeff,
'MS');
2186 $qty = (float)
$prod->fourn_qty;
2188 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'mesgs');
2193 if (
isModEnabled(
"multicurrency") && $pu_ht_devise > 0) {
2202 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
2203 $vat_src_code = $reg[1];
2204 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
2211 $tabprice =
calcul_price_total((
float) $qty, $pu, (
float) $remise_percent, $txtva, (
float) $txlocaltax1, (
float) $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx, (
float) $pu_ht_devise);
2213 $total_ht = $tabprice[0];
2214 $total_tva = $tabprice[1];
2215 $total_ttc = $tabprice[2];
2216 $total_localtax1 = $tabprice[9];
2217 $total_localtax2 = $tabprice[10];
2218 $pu = $pu_ht = $tabprice[3];
2219 $pu_tva = $tabprice[4];
2220 $pu_ttc = $tabprice[5];
2223 $multicurrency_total_ht = $tabprice[16];
2224 $multicurrency_total_tva = $tabprice[17];
2225 $multicurrency_total_ttc = $tabprice[18];
2226 $pu_ht_devise = $tabprice[19];
2227 $multicurrency_pu_ttc = $tabprice[21];
2229 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2230 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2234 $rang = $rangmax + 1;
2240 $this->line->context = $this->context;
2242 $this->line->fk_commande = $this->id;
2243 $this->line->label = $label;
2244 $this->line->ref_fourn = $ref_supplier;
2245 $this->line->ref_supplier = $ref_supplier;
2246 $this->line->desc = $desc;
2247 $this->line->qty = $qty;
2248 $this->line->tva_tx = $txtva;
2249 $this->line->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0);
2250 $this->line->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0);
2251 $this->line->localtax1_type = $localtax1_type;
2252 $this->line->localtax2_type = $localtax2_type;
2253 $this->line->fk_product = $fk_product;
2254 $this->line->product_type = $product_type;
2255 $this->line->remise_percent = $remise_percent;
2256 $this->line->subprice = (float) $pu_ht;
2257 $this->line->subprice_ttc = (float) $pu_ttc;
2259 $this->line->rang = $rang;
2260 $this->line->info_bits = $info_bits;
2262 $this->line->vat_src_code = $vat_src_code;
2263 $this->line->total_ht = (float) $total_ht;
2264 $this->line->total_tva = (float) $total_tva;
2265 $this->line->total_localtax1 = (float) $total_localtax1;
2266 $this->line->total_localtax2 = (float) $total_localtax2;
2267 $this->line->total_ttc = (float) $total_ttc;
2268 $this->line->product_type = $type;
2269 $this->line->special_code = (!empty($special_code) ? $special_code : 0);
2270 $this->line->origin = $origin;
2271 $this->line->origin_type = $origin;
2272 $this->line->origin_id = $origin_id;
2273 $this->line->fk_unit = $fk_unit;
2276 $this->line->date_end = $date_end;
2279 $this->line->fk_multicurrency = $this->fk_multicurrency;
2280 $this->line->multicurrency_code = $this->multicurrency_code;
2281 $this->line->multicurrency_subprice = (float) $pu_ht_devise;
2282 $this->line->multicurrency_subprice_ttc = (float) $multicurrency_pu_ttc;
2283 $this->line->multicurrency_total_ht = (float) $multicurrency_total_ht;
2284 $this->line->multicurrency_total_tva = (float) $multicurrency_total_tva;
2285 $this->line->multicurrency_total_ttc = (float) $multicurrency_total_ttc;
2287 $this->line->subprice = (float) $pu_ht;
2288 $this->line->price = $this->line->subprice;
2290 $this->line->remise_percent = $remise_percent;
2292 if (is_array($array_options) && count($array_options) > 0) {
2293 $this->line->array_options = $array_options;
2296 $result = $this->line->insert($notrigger);
2299 $result = $this->
update_price(1,
'auto', 0, $this->thirdparty);
2302 if (!isset($this->context[
'createfromclone'])) {
2303 if (!empty($this->line->fk_parent_line)) {
2306 } elseif ($rang > 0 && $rang <= count($this->lines)) {
2308 $linecount = count($this->lines);
2309 for ($ii = $rang; $ii <= $linecount; $ii++) {
2314 $this->lines[] = $this->line;
2316 foreach ($this->lines as $line) {
2317 if ($line->id == $origin_id) {
2318 $this->line->extraparams = $line->extraparams;
2319 $this->line->setExtraParameters();
2324 $this->db->commit();
2325 return $this->line->id;
2327 $this->db->rollback();
2332 dol_syslog(get_class($this).
"::addline error=".$this->error, LOG_ERR);
2333 $this->db->rollback();
2358 public function dispatchProduct($user, $product, $qty, $entrepot, $price = 0, $comment =
'', $eatby =
'', $sellby =
'', $batch =
'', $fk_commandefourndet = 0, $notrigger = 0, $fk_reception = 0)
2360 global
$conf, $langs;
2363 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2366 if ($entrepot <= 0) {
2367 $this->error =
'ErrorBadValueForParameterWarehouse';
2371 $this->error =
'ErrorBadValueForParameterQty';
2375 $dispatchstatus = 1;
2377 $dispatchstatus = 0;
2384 if (($this->
status == self::STATUS_ORDERSENT || $this->
status == self::STATUS_RECEIVED_PARTIALLY || $this->
status == self::STATUS_RECEIVED_COMPLETELY)) {
2387 $sql =
"INSERT INTO ".$this->db->prefix().
"receptiondet_batch";
2388 $sql .=
" (fk_element, fk_product, qty, fk_entrepot, fk_user, datec, fk_elementdet, status, comment, eatby, sellby, batch, fk_reception) VALUES";
2389 $sql .=
" ('".((int) $this->
id).
"','".((int) $product).
"','".((float) $qty).
"',".($entrepot > 0 ?
"'".((int) $entrepot).
"'" :
"null").
",'".((
int) $user->id).
"','".$this->db->idate($now).
"','".((int) $fk_commandefourndet).
"', ".((int) $dispatchstatus).
", '".$this->db->escape($comment).
"', ";
2390 $sql .= ($eatby ?
"'".$this->db->idate($eatby).
"'" :
"null").
", ".($sellby ?
"'".$this->db->idate($sellby).
"'" :
"null").
", ".($batch ?
"'".$this->db->escape($batch).
"'" :
"null").
", ".($fk_reception > 0 ?
"'".$this->db->escape((
string) $fk_reception).
"'" :
"null");
2393 dol_syslog(get_class($this).
"::dispatchProduct", LOG_DEBUG);
2394 $resql = $this->db->query($sql);
2397 global
$conf, $langs, $user;
2399 $result = $this->call_trigger(
'LINEORDER_SUPPLIER_DISPATCH', $user);
2406 $this->error = $this->db->lasterror();
2415 $mouv->origin = &$this;
2416 $mouv->setOrigin($this->element, $this->
id);
2419 if (
getDolGlobalString(
'SUPPLIER_ORDER_ALLOW_NEGATIVE_QTY_FOR_SUPPLIER_ORDER_RETURN') && $qty < 0) {
2420 $result = $mouv->livraison($user, $product, $entrepot, $qty * (-1), $price, $comment, $now, $eatby, $sellby, $batch, 0, $inventorycode);
2422 $result = $mouv->reception($user, $product, $entrepot, $qty, $price, $comment, $eatby, $sellby, $batch,
'', 0, $inventorycode);
2426 $this->error = $mouv->error;
2427 $this->errors = $mouv->errors;
2428 dol_syslog(get_class($this).
"::dispatchProduct ".$this->error.
" ".implode(
',', $this->errors), LOG_ERR);
2435 $this->db->commit();
2438 $this->db->rollback();
2442 $this->error =
'BadStatusForObject';
2458 if ($this->
status == 0) {
2461 if ($line->fetch($idline) <= 0) {
2464 if ($this->
id > 0 && (
int) $line->fk_commande !== (
int) $this->id) {
2465 $this->error =
'ErrorLineIDDoesNotMatchWithObjectID';
2471 foreach ($dispatchedLines as $dispatchLine) {
2472 if ($dispatchLine[
'orderlineid'] == $idline) {
2473 $this->error =
"LineAlreadyDispatched";
2474 $this->errors[] = $this->error;
2479 if ($line->delete($user, $notrigger) > 0) {
2498 public function delete(
User $user, $notrigger = 0)
2500 global $langs,
$conf;
2501 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2507 if (empty($notrigger)) {
2509 $result = $this->call_trigger(
'ORDER_SUPPLIER_DELETE', $user);
2511 $this->errors[] =
'ErrorWhenRunningTrigger';
2512 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2513 $this->db->rollback();
2521 if (!empty($this->linkedObjects) && array_key_exists(
'reception', $this->linkedObjects)) {
2522 foreach ($this->linkedObjects[
'reception'] as $element) {
2523 if ($element->statut >= 0) {
2524 $this->errors[] = $langs->trans(
'ReceptionExist');
2533 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_supplier_order";
2534 $sql .=
" WHERE fk_supplier_order = ".((int) $this->
id);
2536 $result = $this->db->query($sql);
2539 $this->errors[] = $this->db->lasterror();
2543 $main = $this->db->prefix().
'commande_fournisseurdet';
2546 $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).
")";
2547 dol_syslog(__METHOD__.
" linked order lines", LOG_DEBUG);
2548 if (!$this->db->query($sql1)) {
2550 $this->error = $this->db->lasterror();
2551 $this->errors[] = $this->db->lasterror();
2556 $ef = $main.
"_extrafields";
2557 $sql =
"DELETE FROM ".$this->db->sanitize($ef).
" WHERE fk_object IN (SELECT rowid FROM ".$this->db->sanitize($main).
" WHERE fk_commande = ".((int) $this->
id).
")";
2558 dol_syslog(get_class($this).
"::delete extrafields lines", LOG_DEBUG);
2559 if (!$this->db->query($sql)) {
2560 $this->error = $this->db->lasterror();
2561 $this->errors[] = $this->db->lasterror();
2567 $sql =
"DELETE FROM ".$this->db->prefix().
"commande_fournisseurdet WHERE fk_commande = ".((int) $this->
id);
2568 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2569 if (!$this->db->query($sql)) {
2570 $this->error = $this->db->lasterror();
2571 $this->errors[] = $this->db->lasterror();
2577 $sql =
"DELETE FROM ".$this->db->prefix().
"commande_fournisseur WHERE rowid = ".((int) $this->
id);
2578 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2579 if ($resql = $this->db->query($sql)) {
2580 if ($this->db->affected_rows($resql) < 1) {
2581 $this->error = $this->db->lasterror();
2582 $this->errors[] = $this->db->lasterror();
2586 $this->error = $this->db->lasterror();
2587 $this->errors[] = $this->db->lasterror();
2596 $this->error =
'FailToDeleteExtraFields';
2597 $this->errors[] =
'FailToDeleteExtraFields';
2599 dol_syslog(get_class($this).
"::delete error -4 ".$this->error, LOG_ERR);
2606 $this->error =
'FailToDeleteObjectLinked';
2607 $this->errors[] =
'FailToDeleteObjectLinked';
2618 if ($conf->fournisseur->commande->dir_output && !empty($ref)) {
2619 $dir =
$conf->fournisseur->commande->dir_output.
"/".$ref;
2620 $file = $dir.
"/".$ref.
".pdf";
2621 if (file_exists($file)) {
2623 $this->error =
'ErrorFailToDeleteFile';
2624 $this->errors[] =
'ErrorFailToDeleteFile';
2628 if (file_exists($dir)) {
2631 $this->error =
'ErrorFailToDeleteDir';
2632 $this->errors[] =
'ErrorFailToDeleteDir';
2640 dol_syslog(get_class($this).
"::delete $this->id by $user->id", LOG_DEBUG);
2641 $this->db->commit();
2644 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2645 $this->db->rollback();
2664 $sql =
"SELECT p.ref, p.label,";
2665 $sql .=
" e.rowid as warehouse_id, e.ref as entrepot,";
2666 $sql .=
" cfd.rowid as dispatchedlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status, cfd.fk_elementdet";
2667 $sql .=
" FROM ".$this->db->prefix().
"product as p,";
2668 $sql .=
" ".$this->db->prefix().
"receptiondet_batch as cfd";
2669 $sql .=
" LEFT JOIN ".$this->db->prefix().
"entrepot as e ON cfd.fk_entrepot = e.rowid";
2670 $sql .=
" WHERE cfd.fk_element = ".((int) $this->
id);
2671 $sql .=
" AND cfd.fk_product = p.rowid";
2673 $sql .=
" AND cfd.status = ".((int) $status);
2675 $sql .=
" ORDER BY cfd.rowid ASC";
2677 $resql = $this->db->query($sql);
2679 $num = $this->db->num_rows($resql);
2683 $objp = $this->db->fetch_object($resql);
2686 'id' => $objp->dispatchedlineid,
2687 'productid' => $objp->fk_product,
2688 'warehouseid' => $objp->warehouse_id,
2689 'qty' => $objp->qty,
2690 'orderlineid' => $objp->fk_elementdet
2697 dol_print_error($this->db,
'Failed to execute request to get dispatched lines');
2720 $dispatchedlinearray = array();
2724 $usercanreceive = 0;
2726 $usercanreceive = $user->hasRight(
"fournisseur",
"commande",
"receptionner");
2728 $usercanreceive = $user->hasRight(
"reception",
"creer");
2731 if ($usercanreceive) {
2733 if ($type ==
'par') {
2735 } elseif ($type ==
'tot') {
2737 } elseif ($type ==
'nev') {
2739 } elseif ($type ==
'can') {
2743 dol_syslog(get_class($this).
"::Livraison Error -2", LOG_ERR);
2750 if ($type ==
'tot') {
2752 if (count($dispatchedlinearray) > 0) {
2755 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove';
2756 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove', LOG_DEBUG);
2759 if (!$error &&
getDolGlobalString(
'SUPPLIER_ORDER_USE_DISPATCH_STATUS_NEED_APPROVE') && ($type ==
'tot')) {
2761 if (count($dispatcheddenied) > 0) {
2764 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied';
2765 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied', LOG_DEBUG);
2772 if (empty($error)) {
2775 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2776 $sql .=
" SET fk_statut = ".((int) $statut);
2777 $sql .=
" WHERE rowid = ".((int) $this->
id);
2778 $sql .=
" AND fk_statut IN (".self::STATUS_ORDERSENT.
",".self::STATUS_RECEIVED_PARTIALLY.
")";
2780 dol_syslog(get_class($this).
"::Livraison", LOG_DEBUG);
2781 $resql = $this->db->query($sql);
2784 $old_statut = $this->status;
2786 $this->context[
'actionmsg2'] = $comment;
2789 $result_trigger = $this->call_trigger(
'ORDER_SUPPLIER_RECEIVE', $user);
2790 if ($result_trigger < 0) {
2795 if (empty($error)) {
2796 $this->db->commit();
2798 $this->
status = $old_statut;
2799 $this->db->rollback();
2800 $this->error = $this->db->lasterror();
2804 $this->db->rollback();
2805 $this->error = $this->db->lasterror();
2810 $this->error = $langs->trans(
'NotAuthorized');
2811 $this->errors[] = $langs->trans(
'NotAuthorized');
2812 dol_syslog(get_class($this).
"::Livraison Not Authorized");
2844 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
2849 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2850 $sql .=
" SET date_livraison = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2851 $sql .=
" WHERE rowid = ".((int) $this->
id);
2854 $resql = $this->db->query($sql);
2856 $this->errors[] = $this->db->error();
2861 $this->oldcopy = clone $this;
2862 $this->delivery_date = $delivery_date;
2865 if (!$notrigger && empty($error)) {
2867 $result = $this->call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2875 $this->db->commit();
2878 foreach ($this->errors as $errmsg) {
2879 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2880 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2882 $this->db->rollback();
2898 if (in_array($this->
status, [1, 2, 3, 4, 5, 6, 7, 9])) {
2899 if ($this->
status == 1) {
2901 } elseif ($this->
status == 2) {
2903 } elseif ($this->
status == 3) {
2905 } elseif ($this->
status == 4) {
2907 } elseif ($this->
status == 5) {
2913 } elseif ($this->
status == 6) {
2915 } elseif ($this->
status == 7) {
2917 } elseif ($this->
status == 9) {
2925 $result = $this->
setStatus($user, $newStatus);
2927 if ($newStatus == 0) {
2928 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur';
2929 $sql .=
' SET fk_user_approve = null, fk_user_approve2 = null, date_approve = null, date_approve2 = null';
2930 $sql .=
' WHERE rowid = '.((int) $this->
id);
2932 $this->db->query($sql);
2935 $this->db->commit();
2939 $this->db->rollback();
2960 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
2965 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2966 $sql .=
" SET fk_projet = ".($id_projet > 0 ? (int) $id_projet :
'null');
2967 $sql .=
" WHERE rowid = ".((int) $this->
id);
2970 $resql = $this->db->query($sql);
2972 $this->errors[] = $this->db->error();
2977 $this->oldcopy = clone $this;
2978 $this->fk_projet = $id_projet;
2979 $this->fk_project = $id_projet;
2982 if (!$notrigger && empty($error)) {
2984 $result = $this->call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2992 $this->db->commit();
2995 foreach ($this->errors as $errmsg) {
2996 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2997 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2999 $this->db->rollback();
3017 $comclient =
new Commande($this->db);
3018 $comclient->fetch($comclientid);
3022 $this->lines = array();
3024 $num = count($comclient->lines);
3025 for ($i = 0; $i < $num; $i++) {
3029 if (
$prod->fetch($comclient->lines[$i]->fk_product) > 0) {
3030 $label =
$prod->label;
3034 $sql =
"INSERT INTO ".$this->db->prefix().
"commande_fournisseurdet";
3035 $sql .=
" (fk_commande, label, description, fk_product, price, qty, tva_tx, localtax1_tx, localtax2_tx, remise_percent, subprice, remise, ref)";
3036 $sql .=
" VALUES (".((int) $idc).
", '".$this->db->escape($label).
"', '".$this->db->escape($comclient->lines[$i]->desc).
"'";
3037 $sql .=
",".((int) $comclient->lines[$i]->fk_product).
", ".
price2num($comclient->lines[$i]->price,
'MU');
3038 $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);
3039 $sql .=
", '".price2num($comclient->lines[$i]->subprice,
'MT').
"','0', '".$this->db->escape($ref).
"');";
3040 if ($this->db->query($sql)) {
3061 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur';
3062 $sql .=
" SET fk_statut = ".((int) $status);
3063 $sql .=
" WHERE rowid = ".((int) $this->
id);
3065 dol_syslog(get_class($this).
"::setStatus", LOG_DEBUG);
3066 $resql = $this->db->query($sql);
3069 $triggerName = array();
3070 $triggerName[0] =
'DRAFT';
3071 $triggerName[1] =
'VALIDATED';
3072 $triggerName[2] =
'APPROVED';
3073 $triggerName[3] =
'ORDERED';
3074 $triggerName[4] =
'RECEIVED_PARTIALLY';
3075 $triggerName[5] =
'RECEIVED_COMPLETELY';
3076 $triggerName[6] =
'CANCELED';
3077 $triggerName[7] =
'CANCELED';
3078 $triggerName[9] =
'REFUSED';
3081 $result = $this->call_trigger(
"ORDER_SUPPLIER_STATUS_".$triggerName[$status], $user);
3088 $this->error = $this->db->lasterror();
3089 dol_syslog(get_class($this).
"::setStatus ".$this->error);
3094 $this->db->commit();
3097 $this->db->rollback();
3115 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
3116 return parent::setCategoriesCommon($categories, Categorie::TYPE_SUPPLIER_ORDER);
3142 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 =
'')
3147 $this->error =
'ErrorLineIDDoesNotMatchWithObjectID';
3151 dol_syslog(get_class($this).
"::updateline $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $type, $fk_unit");
3152 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
3156 if ($this->
status == self::STATUS_DRAFT) {
3161 if (empty($info_bits)) {
3164 if (empty($txtva)) {
3167 if (empty($txlocaltax1)) {
3170 if (empty($txlocaltax2)) {
3173 if (empty($remise_percent)) {
3174 $remise_percent = 0;
3177 $remise_percent = (float)
price2num($remise_percent);
3183 $pu_ht_devise =
price2num($pu_ht_devise);
3184 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
3187 $txlocaltax1 = (float)
price2num($txlocaltax1);
3188 $txlocaltax2 = (float)
price2num($txlocaltax2);
3195 $langs->load(
"errors");
3196 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
3211 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
3212 $vat_src_code = $reg[1];
3213 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
3220 if ($tmpline->fetch($rowid) > 0) {
3222 if ($newqty != $qty) {
3224 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'warnings');
3229 $tabprice =
calcul_price_total($qty, (
float) $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, (
float) $this->multicurrency_tx, (
float) $pu_ht_devise);
3230 $total_ht = $tabprice[0];
3231 $total_tva = $tabprice[1];
3232 $total_ttc = $tabprice[2];
3233 $total_localtax1 = $tabprice[9];
3234 $total_localtax2 = $tabprice[10];
3235 $pu_ht = $tabprice[3];
3236 $pu_tva = $tabprice[4];
3237 $pu_ttc = $tabprice[5];
3240 $multicurrency_total_ht = $tabprice[16];
3241 $multicurrency_total_tva = $tabprice[17];
3242 $multicurrency_total_ttc = $tabprice[18];
3243 $pu_ht_devise = $tabprice[19];
3244 $multicurrency_pu_ttc = $tabprice[21];
3246 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
3247 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
3251 $this->line->fetch($rowid);
3253 $oldline = clone $this->line;
3254 $this->line->oldline = $oldline;
3256 $this->line->context = $this->context;
3258 $this->line->fk_commande = $this->id;
3260 $this->line->desc = $desc;
3263 $this->line->qty = $qty;
3264 $this->line->ref_supplier = $ref_supplier;
3266 $this->line->vat_src_code = $vat_src_code;
3267 $this->line->tva_tx = $txtva;
3268 $this->line->localtax1_tx = $txlocaltax1;
3269 $this->line->localtax2_tx = $txlocaltax2;
3270 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
3271 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
3272 $this->line->remise_percent = $remise_percent;
3273 $this->line->subprice = (float) $pu_ht;
3274 $this->line->subprice_ttc = (float) $pu_ttc;
3275 $this->line->info_bits = $info_bits;
3276 $this->line->total_ht = (float) $total_ht;
3277 $this->line->total_tva = (float) $total_tva;
3278 $this->line->total_localtax1 = (float) $total_localtax1;
3279 $this->line->total_localtax2 = (float) $total_localtax2;
3280 $this->line->total_ttc = (float) $total_ttc;
3281 $this->line->product_type = $type;
3282 $this->line->special_code = $oldline->special_code;
3283 $this->line->rang = $oldline->rang;
3284 $this->line->origin = $this->origin;
3285 $this->line->fk_unit = $fk_unit;
3288 $this->line->date_end = $date_end;
3291 $this->line->fk_multicurrency = $this->fk_multicurrency;
3292 $this->line->multicurrency_code = $this->multicurrency_code;
3293 $this->line->multicurrency_subprice = (float) $pu_ht_devise;
3294 $this->line->multicurrency_subprice_ttc = (float) $multicurrency_pu_ttc;
3295 $this->line->multicurrency_total_ht = (float) $multicurrency_total_ht;
3296 $this->line->multicurrency_total_tva = (float) $multicurrency_total_tva;
3297 $this->line->multicurrency_total_ttc = (float) $multicurrency_total_ttc;
3299 $this->line->subprice = (float) $pu_ht;
3300 $this->line->subprice_ttc = (float) $pu_ttc;
3301 $this->line->price = $this->line->subprice;
3303 $this->line->remise_percent = $remise_percent;
3305 if (is_array($array_options) && count($array_options) > 0) {
3307 foreach ($array_options as $key => $value) {
3308 $this->line->array_options[$key] = $array_options[$key];
3312 $result = $this->line->update($notrigger);
3318 $this->db->commit();
3321 $this->errors[] = $this->line->error;
3322 $this->errors = array_merge($this->errors, $this->line->errors);
3323 $this->error = $this->db->lasterror();
3324 $this->db->rollback();
3328 $this->error =
"Order status makes operation forbidden";
3329 dol_syslog(get_class($this).
"::updateline ".$this->error, LOG_ERR);
3344 global $user, $langs,
$conf;
3346 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
3348 dol_syslog(get_class($this).
"::initAsSpecimen");
3355 $sql =
"SELECT rowid";
3356 $sql .=
" FROM ".$this->db->prefix().
"product";
3357 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
3358 $sql .= $this->db->order(
"rowid",
"ASC");
3359 $sql .= $this->db->plimit(1);
3360 $resql = $this->db->query($sql);
3361 if ($resql && $this->db->num_rows($resql)) {
3362 $obj = $this->db->fetch_object($resql);
3363 $prodid = $obj->rowid;
3368 $this->
ref =
'SPECIMEN';
3369 $this->specimen = 1;
3372 $this->date_commande = $now;
3373 $this->date_lim_reglement = $this->
date + 3600 * 24 * 30;
3374 $this->cond_reglement_code =
'RECEP';
3375 $this->mode_reglement_code =
'CHQ';
3377 $this->note_public =
'This is a comment (public)';
3378 $this->note_private =
'This is a comment (private)';
3380 $this->multicurrency_tx = 1;
3381 $this->multicurrency_code =
$conf->currency;
3389 while ($xnbp < $nbp) {
3391 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
3393 $line->subprice = 100;
3394 $line->tva_tx = 19.6;
3395 $line->localtax1_tx = 0;
3396 $line->localtax2_tx = 0;
3398 $line->total_ht = 50;
3399 $line->total_ttc = 59.8;
3400 $line->total_tva = 9.8;
3401 $line->remise_percent = 50;
3403 $line->total_ht = 100;
3404 $line->total_ttc = 119.6;
3405 $line->total_tva = 19.6;
3406 $line->remise_percent = 00;
3408 $line->fk_product = $prodid;
3410 $this->lines[$xnbp] = $line;
3412 $this->total_ht += $line->total_ht;
3413 $this->total_tva += $line->total_tva;
3414 $this->total_ttc += $line->total_ttc;
3430 $sql =
'SELECT c.rowid, date_creation as datec, tms as datem, date_valid as date_validation, date_approve as datea, date_approve2 as datea2,';
3431 $sql .=
' fk_user_author, fk_user_modif, fk_user_valid, fk_user_approve, fk_user_approve2';
3432 $sql .=
' FROM '.$this->db->prefix().
'commande_fournisseur as c';
3433 $sql .=
' WHERE c.rowid = '.((int) $id);
3435 $result = $this->db->query($sql);
3437 if ($this->db->num_rows($result)) {
3438 $obj = $this->db->fetch_object($result);
3440 $this->
id = $obj->rowid;
3442 $this->user_creation_id = $obj->fk_user_author;
3443 $this->user_validation_id = $obj->fk_user_valid;
3444 $this->user_modification_id = $obj->fk_user_modif;
3445 $this->user_approve_id = $obj->fk_user_approve;
3446 $this->user_approve_id2 = $obj->fk_user_approve2;
3448 $this->date_creation = $this->db->jdate($obj->datec);
3449 $this->date_modification = $this->db->jdate($obj->datem);
3450 $this->date_approve = $this->db->jdate($obj->datea);
3451 $this->date_approve2 = $this->db->jdate($obj->datea2);
3452 $this->date_validation = $this->db->jdate($obj->date_validation);
3454 $this->db->free($result);
3469 $this->nb = array();
3470 $sanitizedclause =
"WHERE";
3472 $sql =
"SELECT count(co.rowid) as nb";
3473 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as co";
3474 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe as s ON co.fk_soc = s.rowid";
3475 if (empty($user->socid) && !$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3476 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
3477 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
3478 $sanitizedclause =
"AND";
3480 $sql .=
" ".$sanitizedclause.
" co.entity IN (".
getEntity(
'supplier_order').
")";
3482 $resql = $this->db->query($sql);
3484 while ($obj = $this->db->fetch_object($resql)) {
3485 $this->nb[
"supplier_orders"] = $obj->nb;
3487 $this->db->free($resql);
3491 $this->error = $this->db->error();
3507 global
$conf, $langs;
3509 $sql =
"SELECT c.rowid, c.date_creation as datec, c.date_commande, c.fk_statut, c.date_livraison as delivery_date, c.total_ht";
3510 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as c";
3511 if (empty($user->socid) && !$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3512 $sql .=
" JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
3514 $sql .=
" WHERE c.entity = ".((int)
$conf->entity);
3515 if ($mode ===
'awaiting') {
3516 $sql .=
" AND c.fk_statut IN (".self::STATUS_ORDERSENT.
", ".self::STATUS_RECEIVED_PARTIALLY.
")";
3518 $sql .=
" AND c.fk_statut IN (".self::STATUS_VALIDATED.
", ".self::STATUS_ACCEPTED.
")";
3521 $sql .=
" AND c.fk_soc = ".((int) $user->socid);
3524 $resql = $this->db->query($sql);
3529 $response->warning_delay =
$conf->commande->fournisseur->warning_delay / 60 / 60 / 24;
3530 $response->label = $langs->trans(
"SuppliersOrdersToProcess");
3531 $response->labelShort = $langs->trans(
"Opened");
3532 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=1,2&mainmenu=commercial&leftmenu=orders_suppliers';
3533 $response->url_late = DOL_URL_ROOT.
'/fourn/commande/list.php?mainmenu=commercial&leftmenu=orders_suppliers&search_option=late';
3536 if ($mode ===
'awaiting') {
3537 $response->label = $langs->trans(
"SuppliersOrdersAwaitingReception");
3538 $response->labelShort = $langs->trans(
"AwaitingReception");
3539 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=3,4&mainmenu=commercial&leftmenu=orders_suppliers';
3540 $response->url_late = DOL_URL_ROOT.
'/fourn/commande/list.php?mainmenu=commercial&leftmenu=orders_suppliers&search_option=recv_late';
3543 while ($obj = $this->db->fetch_object($resql)) {
3544 $commandestatic->delivery_date = $this->db->jdate($obj->delivery_date);
3545 $commandestatic->date_commande = $this->db->jdate($obj->date_commande);
3546 $commandestatic->statut = $obj->fk_statut;
3547 $commandestatic->status = $obj->fk_statut;
3549 $response->nbtodo++;
3550 $response->total += $obj->total_ht;
3552 if ($commandestatic->hasDelay()) {
3553 $response->nbtodolate++;
3559 $this->error = $this->db->error();
3574 if ($this->methode_commande_id > 0) {
3575 $sql =
"SELECT rowid, code, libelle as label";
3576 $sql .=
" FROM ".$this->db->prefix().
'c_input_method';
3577 $sql .=
" WHERE active=1 AND rowid = ".((int) $this->methode_commande_id);
3579 $resql = $this->db->query($sql);
3581 if ($this->db->num_rows($resql)) {
3582 $obj = $this->db->fetch_object($resql);
3584 $string = $langs->trans($obj->code);
3585 if ($string == $obj->code) {
3586 $string = $obj->label !=
'-' ? $obj->label :
'';
3609 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3616 if (!empty($this->model_pdf)) {
3617 $modele = $this->model_pdf;
3623 if (empty($modele)) {
3626 $langs->load(
"suppliers");
3627 $outputlangs->load(
"products");
3629 $modelpath =
"core/modules/supplier_order/doc/";
3630 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3643 if (empty($this->lines)) {
3650 foreach ($this->lines as $line) {
3651 if ($line->fk_product > 0) {
3653 $idp = $tmpproductfourn->find_min_price_product_fournisseur($line->fk_product, $line->qty, $this->thirdparty->id);
3656 if ($tmpproductfourn->delivery_time_days > $nb) {
3657 $nb = $tmpproductfourn->delivery_time_days;
3666 return $nb.
' '.$langs->trans(
'days');
3679 return $user->hasRight(
"fournisseur",
"commande");
3694 'commande_fournisseur'
3711 'commande_fournisseurdet'
3728 if ($this->
status == self::STATUS_ORDERSENT || $this->
status == self::STATUS_RECEIVED_PARTIALLY) {
3730 if (!empty($this->delivery_date)) {
3731 $date_to_test = $this->delivery_date;
3732 return $date_to_test && $date_to_test < ($now -
$conf->commande->fournisseur->warning_delay);
3740 $date_to_test = $this->date_commande;
3742 return ($this->
status > 0 && $this->
status < 5) && $date_to_test && $date_to_test < ($now -
$conf->commande->fournisseur->warning_delay);
3755 global
$conf, $langs;
3757 $langs->load(
'orders');
3761 if ($this->
status == self::STATUS_ORDERSENT || $this->
status == self::STATUS_RECEIVED_PARTIALLY) {
3762 if (!empty($this->delivery_date)) {
3763 $text = $langs->trans(
"DeliveryDate").
' '.
dol_print_date($this->delivery_date,
'day');
3765 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3768 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3771 $text .=
' '.($conf->commande->fournisseur->warning_delay > 0 ?
'+' :
'-').
' '.round(abs(
$conf->commande->fournisseur->warning_delay) / 3600 / 24, 1).
' '.$langs->trans(
"days").
' < '.$langs->trans(
"Today");
3789 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
3791 $qtydelivered = array();
3792 $qtywished = array();
3796 $filter = array(
't.fk_element' => $this->
id);
3798 $filter[
't.status'] = 1;
3801 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
3803 $this->error = $supplierorderdispatch->error;
3804 $this->errors = $supplierorderdispatch->errors;
3807 if (is_array($supplierorderdispatch->lines) && count($supplierorderdispatch->lines) > 0) {
3808 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
3812 foreach ($supplierorderdispatch->lines as $line) {
3813 if (array_key_exists($line->fk_product, $qtydelivered)) {
3814 $qtydelivered[$line->fk_product] += $line->qty;
3816 $qtydelivered[$line->fk_product] = $line->qty;
3819 foreach ($this->lines as $line) {
3821 if (empty($line->fk_product)) {
3825 if ($line->product_type > 0 && (!
getDolGlobalString(
'STOCK_SUPPORTS_SERVICES') || empty($line->stockable_product))) {
3828 if (array_key_exists($line->fk_product, $qtywished)) {
3829 $qtywished[$line->fk_product] += $line->qty;
3831 $qtywished[$line->fk_product] = $line->qty;
3836 $diff_array = array_diff_assoc($qtydelivered, $qtywished);
3837 $keysinwishednotindelivered = array_diff(array_keys($qtywished), array_keys($qtydelivered));
3838 $keysindeliverednotinwished = array_diff(array_keys($qtydelivered), array_keys($qtywished));
3846 if (count($diff_array) == 0 && count($keysinwishednotindelivered) == 0 && count($keysindeliverednotinwished) == 0) {
3847 if ($closeopenorder) {
3849 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3857 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3868 if (count($diff_array) > 0) {
3872 foreach ($diff_array as $key => $value) {
3874 if ($qtydelivered[$key] >= $qtywished[$key]) {
3881 if ($close == count($diff_array)) {
3883 if ($closeopenorder) {
3884 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3891 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3899 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3907 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3929 $this->receptions = array();
3931 dol_syslog(get_class($this).
"::loadReceptions", LOG_DEBUG);
3933 $sql =
'SELECT cd.rowid, cd.fk_product,';
3934 $sql .=
' sum(cfd.qty) as qty';
3935 $sql .=
' FROM '.$this->db->prefix().
'receptiondet_batch as cfd,';
3936 if ($filtre_statut >= 0) {
3937 $sql .=
' '.$this->db->prefix().
'reception as e,';
3939 $sql .=
' '.$this->db->prefix().
'commande_fournisseurdet as cd';
3941 if ($filtre_statut >= 0) {
3942 $sql .=
' cfd.fk_reception = e.rowid AND';
3944 $sql .=
' cfd.fk_elementdet = cd.rowid';
3945 $sql .=
' AND cd.fk_commande ='.((int) $this->
id);
3946 if (isset($this->fk_product) && !empty($this->fk_product) > 0) {
3947 $sql .=
' AND cd.fk_product = '.((int) $this->fk_product);
3949 if ($filtre_statut >= 0) {
3950 $sql .=
' AND e.fk_statut >= '.((int) $filtre_statut);
3952 $sql .=
' GROUP BY cd.rowid, cd.fk_product';
3954 $resql = $this->db->query($sql);
3956 $num = $this->db->num_rows($resql);
3959 $obj = $this->db->fetch_object($resql);
3960 if (empty($this->receptions[$obj->rowid])) {
3961 $this->receptions[$obj->rowid] = (float) $obj->qty;
3963 $this->receptions[$obj->rowid] += (float) $obj->qty;
3967 $this->db->free($resql);
3971 $this->error = $this->db->lasterror();
3987 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3989 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3990 $return .=
'<div class="info-box info-box-sm">';
3991 $return .=
'<span class="info-box-icon bg-infobox-action">';
3993 $return .=
'</span>';
3994 $return .=
'<div class="info-box-content">';
3995 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
3996 if ($selected >= 0) {
3997 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3999 if (!empty($arraydata[
'thirdparty'])) {
4000 $return .=
'<br><span class="info-box-label">'.$arraydata[
'thirdparty'].
'</span>';
4002 if (!empty($this->
date)) {
4003 $return .=
'<br><span class="info-box-label">'.dol_print_date($this->
date,
'day').
'</span>';
4005 if (!empty($this->total_ht)) {
4006 $return .=
' <span class="info-box-label amount" title="'.dol_escape_htmltag($langs->trans(
"AmountHT")).
'">'.
price($this->total_ht);
4007 $return .=
' '.$langs->trans(
"HT");
4008 $return .=
'</span>';
4010 if (method_exists($this,
'getLibStatut')) {
4011 $return .=
'<br><span class="info-box-status">'.$this->getLibStatut(3).
'</span>';
4013 if (property_exists($this,
'billed')) {
4014 $return .=
' <span class="opacitymedium">'.$langs->trans(
"Billed").
': </span><span class="info-box-label">'.
yn($this->billed).
'</span>';
4016 $return .=
'</div>';
4017 $return .=
'</div>';
4018 $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.
cancel($user, $idwarehouse=-1)
Cancel an approved order.
setReopen(User $user)
Reopen supplier order.
loadStateBoard()
Load the indicators this->nb for the state board.
calcAndSetStatusDispatch(User $user, $closeopenorder=1, $comment='')
Calc status regarding to dispatched stock.
set_id_projet($user, $id_projet, $notrigger=0)
Set the id projet.
const STATUS_DRAFT
Draft status.
showDelay()
Show the customer delayed info.
getTooltipContentArray($params)
getTooltipContentArray
classifyUnBilled(User $user)
Classify not billed.
approve($user, $idwarehouse=0, $secondlevel=0)
Approve a supplier order.
__construct($db)
Constructor.
addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0.0, $txlocaltax2=0.0, $fk_product=0, $fk_prod_fourn_price=0, $ref_supplier='', $remise_percent=0.0, $price_base_type='HT', $pu_ttc=0.0, $type=0, $info_bits=0, $notrigger=0, $date_start=null, $date_end=null, $array_options=[], $fk_unit=null, $pu_ht_devise=0, $origin='', $origin_id=0, $rang=-1, $special_code=0, $label='')
Add order line.
dispatchProduct($user, $product, $qty, $entrepot, $price=0, $comment='', $eatby='', $sellby='', $batch='', $fk_commandefourndet=0, $notrigger=0, $fk_reception=0)
Save a receiving into the tracking table of receiving (receptiondet_batch) and add product into stock...
valid($user, $idwarehouse=0, $notrigger=0)
Validate an order.
create($user, $notrigger=0)
Create order with draft status.
update(User $user, $notrigger=0)
Update Supplier Order.
createFromClone(User $user, $socid=0, $notrigger=0)
Load an object from its id and create a new one in database.
updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $type=0, $notrigger=0, $date_start=0, $date_end=0, $array_options=[], $fk_unit=null, $pu_ht_devise=0, $ref_supplier='')
Update line.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template model.
const STATUS_ACCEPTED
Accepted.
const STATUS_ORDERSENT
Order sent, shipment on process.
commande($user, $date, $methode, $comment='')
Submit a supplier order to supplier.
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.
setCategories($categories)
Sets object to given categories.
setStatus($user, $status)
Tag order with a particular status.
const STATUS_REFUSED
Refused.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
getLibStatut($mode=0)
Return label of the status of object.
hasDelay()
Is the supplier order delayed? We suppose a purchase ordered as late if a the purchase order has been...
LibStatut($status, $mode=0, $billed=0)
Return label of a status.
Class to manage line orders.
Class to manage customers orders.
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
line_order($renum=false, $rowidorder='ASC', $fk_parent_line=true)
Save a new position (field rang) for details lines.
deleteEcmFiles($mode=0)
Delete related files of object in database.
update_price($exclspec=0, $roundingadjust='auto', $nodatabaseupdate=0, $seller=null)
Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines).
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
roundQtyToPackaging($qty, $packaging)
Round a quantity up to the next multiple of a packaging quantity (options PRODUCT_USE_CUSTOMER_PACKAG...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
setErrorsFromObject($object)
setErrorsFromObject
isLineOfObject($lineid)
Check that a line belongs to this object, using $this->table_element_line and $this->fk_element.
updateRangOfLine($rowid, $rang)
Update position of line (rang)
checkActiveProductInLines($status='onsale')
Check if all products have the right status (on sale, on buy) called during validation of propal,...
deleteExtraFields()
Delete all extra fields values for the current object.
fetchObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $clause='OR', $alsosametype=1, $orderby='sourcetype', $loadalsoobjects=1)
Fetch array of objects linked to current object (object of enabled modules only).
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
static commonReplaceProduct(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
line_max($fk_parent_line=0)
Get max value used for position of line (rang)
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
add_contact($fk_socpeople, $type_contact, $source='external', $notrigger=0)
Add a link between element $this->element and a contact.
Superclass for orders classes.
Class to manage Dolibarr database access.
Class to manage stock movements.
static getIdAndTxFromCode($dbs, $code, $date_document=0)
Get id and rate of currency from code.
static getIdFromCode($dbs, $code)
Get id of currency from code.
Class to manage predefined suppliers products.
Class to manage products or services.
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.
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
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)
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)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
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.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalBool($key, $default=false)
Return a Dolibarr global constant boolean value.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_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...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $notused, $price_base_type, $info_bits, $type, $seller=null, $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date