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';
47 require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
59 public $element =
'order_supplier';
64 public $table_element =
'commande_fournisseur';
69 public $table_element_line =
'commande_fournisseurdet';
74 public $class_element_line =
'CommandeFournisseurLigne';
79 public $fk_element =
'fk_commande';
84 public $picto =
'supplier_order';
90 public $restrictiononfksoc = 1;
110 public $ref_supplier;
158 public $date_approve;
164 public $date_approve2;
169 public $date_commande;
175 public $remise_percent;
179 public $methode_commande_id;
183 public $methode_commande;
188 public $delivery_date;
203 public $total_localtax1;
208 public $total_localtax2;
223 public $cond_reglement_id;
228 public $cond_reglement_code;
233 public $cond_reglement_label;
238 public $cond_reglement_doc;
245 public $deposit_percent;
255 public $mode_reglement_id;
260 public $mode_reglement_code;
265 public $mode_reglement;
270 public $user_author_id;
275 public $user_approve_id;
281 public $user_approve_id2;
291 public $extraparams = array();
296 public $lines = array();
316 public $date_lim_reglement;
321 public $receptions = array();
327 public $fk_multicurrency;
332 public $multicurrency_code;
337 public $multicurrency_tx;
342 public $multicurrency_total_ht;
347 public $multicurrency_total_tva;
352 public $multicurrency_total_ttc;
382 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => 0,
'notnull' => 1,
'position' => 10),
383 'ref' => array(
'type' =>
'varchar(255)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => 1,
'showoncombobox' => 1,
'position' => 25,
'searchall' => 1),
384 'ref_ext' => array(
'type' =>
'varchar(255)',
'label' =>
'RefExt',
'enabled' => 1,
'visible' => 0,
'position' => 35),
385 'ref_supplier' => array(
'type' =>
'varchar(255)',
'label' =>
'RefOrderSupplierShort',
'enabled' => 1,
'visible' => 1,
'position' => 40,
'searchall' => 1),
386 'fk_projet' => array(
'type' =>
'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)',
'label' =>
'Project',
'enabled' =>
"isModEnabled('project')",
'visible' => -1,
'position' => 45),
387 'date_valid' => array(
'type' =>
'datetime',
'label' =>
'DateValidation',
'enabled' => 1,
'visible' => -1,
'position' => 710),
388 'date_approve' => array(
'type' =>
'datetime',
'label' =>
'DateApprove',
'enabled' => 1,
'visible' => -1,
'position' => 720),
389 'date_approve2' => array(
'type' =>
'datetime',
'label' =>
'DateApprove2',
'enabled' => 1,
'visible' => 3,
'position' => 725),
390 'date_commande' => array(
'type' =>
'date',
'label' =>
'OrderDateShort',
'enabled' => 1,
'visible' => 1,
'position' => 70),
391 'date_livraison' => array(
'type' =>
'datetime',
'label' =>
'DeliveryDate',
'enabled' =>
'getDolGlobalInt("ORDER_DISABLE_DELIVERY_DATE") ? 0 : 1',
'visible' => 1,
'position' => 74),
392 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'visible' => 3,
'position' => 41),
393 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => 3,
'notnull' => -1,
'position' => 80),
394 'fk_user_valid' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserValidation',
'enabled' => 1,
'visible' => 3,
'position' => 711),
395 'fk_user_approve' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserApproval',
'enabled' => 1,
'visible' => 3,
'position' => 721),
396 'fk_user_approve2' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserApproval2',
'enabled' => 1,
'visible' => 3,
'position' => 726),
397 'source' => array(
'type' =>
'smallint(6)',
'label' =>
'Source',
'enabled' => 1,
'visible' => 3,
'notnull' => 1,
'position' => 100),
398 'billed' => array(
'type' =>
'smallint(6)',
'label' =>
'Billed',
'enabled' => 1,
'visible' => 1,
'position' => 710),
399 'total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'AmountHT',
'enabled' => 1,
'visible' => 1,
'position' => 130,
'isameasure' => 1),
400 'total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'AmountVAT',
'enabled' => 1,
'visible' => 1,
'position' => 135,
'isameasure' => 1),
401 'localtax1' => array(
'type' =>
'double(24,8)',
'label' =>
'LT1',
'enabled' => 1,
'visible' => 3,
'position' => 140,
'isameasure' => 1),
402 'localtax2' => array(
'type' =>
'double(24,8)',
'label' =>
'LT2',
'enabled' => 1,
'visible' => 3,
'position' => 145,
'isameasure' => 1),
403 'total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'AmountTTC',
'enabled' => 1,
'visible' => -1,
'position' => 150,
'isameasure' => 1),
404 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 750,
'searchall' => 1),
405 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 760,
'searchall' => 1),
406 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'ModelPDF',
'enabled' => 1,
'visible' => 0,
'position' => 165),
407 'fk_input_method' => array(
'type' =>
'integer',
'label' =>
'OrderMode',
'enabled' => 1,
'visible' => 3,
'position' => 170),
408 'fk_cond_reglement' => array(
'type' =>
'integer',
'label' =>
'PaymentTerm',
'enabled' => 1,
'visible' => 3,
'position' => 175),
409 'deposit_percent' => array(
'type' =>
'varchar(63)',
'label' =>
'DepositPercent',
'enabled' => 1,
'visible' => -1,
'position' => 176),
410 'fk_mode_reglement' => array(
'type' =>
'integer',
'label' =>
'PaymentMode',
'enabled' => 1,
'visible' => 3,
'position' => 180),
411 'extraparams' => array(
'type' =>
'varchar(255)',
'label' =>
'Extraparams',
'enabled' => 1,
'visible' => 0,
'position' => 190),
412 'fk_account' => array(
'type' =>
'integer',
'label' =>
'BankAccount',
'enabled' =>
'isModEnabled("bank")',
'visible' => 3,
'position' => 200),
413 'fk_incoterms' => array(
'type' =>
'integer',
'label' =>
'IncotermCode',
'enabled' => 1,
'visible' => 3,
'position' => 205),
414 'location_incoterms' => array(
'type' =>
'varchar(255)',
'label' =>
'IncotermLocation',
'enabled' => 1,
'visible' => 3,
'position' => 210),
415 'fk_multicurrency' => array(
'type' =>
'integer',
'label' =>
'Fk multicurrency',
'enabled' => 1,
'visible' => 0,
'position' => 215),
416 'multicurrency_code' => array(
'type' =>
'varchar(255)',
'label' =>
'Currency',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 220),
417 'multicurrency_tx' => array(
'type' =>
'double(24,8)',
'label' =>
'CurrencyRate',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 225),
418 'multicurrency_total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountHT',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 230),
419 'multicurrency_total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountVAT',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 235),
420 'multicurrency_total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountTTC',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 240),
421 'date_creation' => array(
'type' =>
'datetime',
'label' =>
'Date creation',
'enabled' => 1,
'visible' => -1,
'position' => 500),
422 'fk_soc' => array(
'type' =>
'integer:Societe:societe/class/societe.class.php',
'label' =>
'ThirdParty',
'enabled' =>
'isModEnabled("societe")',
'visible' => 1,
'notnull' => 1,
'position' => 50),
423 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => 0,
'notnull' => 1,
'position' => 1000,
'index' => 1),
424 'tms' => array(
'type' =>
'datetime',
'label' =>
"DateModificationShort",
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 501),
425 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'LastMainDoc',
'enabled' => 1,
'visible' => 0,
'position' => 700),
426 'fk_statut' => array(
'type' =>
'smallint(6)',
'label' =>
'Status',
'enabled' => 1,
'visible' => 1,
'position' => 701),
427 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => 0,
'position' => 900),
491 $this->ismultientitymanaged = 1;
502 public function fetch($id, $ref =
'')
505 if (empty($id) && empty($ref)) {
509 $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,";
510 $sql .=
" c.localtax1, c.localtax2, ";
511 $sql .=
" c.date_creation, c.date_valid, c.date_approve, c.date_approve2,";
512 $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,";
513 $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,";
514 $sql .=
" c.fk_account,";
515 $sql .=
" c.note_private, c.note_public, c.model_pdf, c.last_main_doc, c.extraparams, c.billed,";
516 $sql .=
" c.fk_multicurrency, c.multicurrency_code, c.multicurrency_tx, c.multicurrency_total_ht, c.multicurrency_total_tva, c.multicurrency_total_ttc,";
517 $sql .=
" cm.libelle as methode_commande,";
518 $sql .=
" cr.code as cond_reglement_code, cr.libelle as cond_reglement_label, cr.libelle_facture as cond_reglement_doc, c.deposit_percent,";
519 $sql .=
" p.code as mode_reglement_code, p.libelle as mode_reglement_libelle";
520 $sql .=
', c.fk_incoterms, c.location_incoterms';
521 $sql .=
', c.last_main_doc';
522 $sql .=
', i.libelle as label_incoterms';
523 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as c";
524 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_payment_term as cr ON c.fk_cond_reglement = cr.rowid";
525 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_paiement as p ON c.fk_mode_reglement = p.id";
526 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_input_method as cm ON cm.rowid = c.fk_input_method";
527 $sql .=
' LEFT JOIN '.$this->db->prefix().
'c_incoterms as i ON c.fk_incoterms = i.rowid';
530 $sql .=
" WHERE c.entity IN (".getEntity(
'supplier_order').
")";
532 $sql .=
" WHERE c.rowid=".((int) $id);
536 $sql .=
" AND c.ref='".$this->db->escape($ref).
"'";
539 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
540 $resql = $this->db->query($sql);
542 $obj = $this->db->fetch_object($resql);
544 $this->error =
'Bill with id '.$id.
' not found';
545 dol_syslog(get_class($this).
'::fetch '.$this->error);
549 $this->
id = $obj->rowid;
550 $this->entity = $obj->entity;
552 $this->
ref = $obj->ref;
553 $this->ref_supplier = $obj->ref_supplier;
555 $this->socid = $obj->fk_soc;
556 $this->thirdparty =
null;
558 $this->fourn_id = $obj->fk_soc;
559 $this->statut = $obj->status;
560 $this->
status = $obj->status;
561 $this->billed = $obj->billed;
562 $this->last_main_doc = $obj->last_main_doc;
563 $this->user_author_id = $obj->user_author_id;
564 $this->user_validation_id = $obj->user_validation_id;
565 $this->user_approve_id = $obj->user_approve_id;
566 $this->user_approve_id2 = $obj->user_approve_id2;
567 $this->total_ht = $obj->total_ht;
568 $this->total_tva = $obj->total_tva;
569 $this->total_localtax1 = $obj->localtax1;
570 $this->total_localtax2 = $obj->localtax2;
571 $this->total_ttc = $obj->total_ttc;
572 $this->date_creation = $this->db->jdate($obj->date_creation);
573 $this->date_valid = $this->db->jdate($obj->date_valid);
574 $this->date_approve = $this->db->jdate($obj->date_approve);
575 $this->date_approve2 = $this->db->jdate($obj->date_approve2);
576 $this->date_commande = $this->db->jdate($obj->date_commande);
577 if (isset($obj->date_commande)) {
578 $this->
date = $this->date_commande;
580 $this->
date = $this->date_creation;
582 $this->delivery_date = $this->db->jdate($obj->delivery_date);
583 $this->remise_percent = $obj->remise_percent;
584 $this->methode_commande_id = $obj->fk_input_method;
585 $this->methode_commande = $obj->methode_commande;
587 $this->source = $obj->source;
588 $this->fk_project = $obj->fk_project;
589 $this->cond_reglement_id = $obj->fk_cond_reglement;
590 $this->cond_reglement_code = $obj->cond_reglement_code;
591 $this->cond_reglement_label = $obj->cond_reglement_label;
592 $this->cond_reglement_doc = $obj->cond_reglement_doc;
593 $this->deposit_percent = $obj->deposit_percent;
594 $this->fk_account = $obj->fk_account;
595 $this->mode_reglement_id = $obj->fk_mode_reglement;
596 $this->mode_reglement_code = $obj->mode_reglement_code;
597 $this->mode_reglement = $obj->mode_reglement_libelle;
598 $this->note = $obj->note_private;
599 $this->note_private = $obj->note_private;
600 $this->note_public = $obj->note_public;
601 $this->model_pdf = $obj->model_pdf;
602 $this->last_main_doc = $obj->last_main_doc;
605 $this->fk_incoterms = $obj->fk_incoterms;
606 $this->location_incoterms = $obj->location_incoterms;
607 $this->label_incoterms = $obj->label_incoterms;
610 $this->fk_multicurrency = $obj->fk_multicurrency;
611 $this->multicurrency_code = $obj->multicurrency_code;
612 $this->multicurrency_tx = $obj->multicurrency_tx;
613 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
614 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
615 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
617 $this->extraparams = isset($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
619 $this->db->free($resql);
634 $this->error = $this->db->error().
" sql=".$sql;
650 $this->lines = array();
652 $sql =
"SELECT l.rowid, l.fk_commande, l.ref as ref_supplier, l.fk_product, l.product_type, l.label, l.description, l.qty,";
653 $sql .=
" l.vat_src_code, l.tva_tx, l.remise_percent, l.subprice, l.subprice_ttc,";
654 $sql .=
" l.localtax1_tx, l. localtax2_tx, l.localtax1_type, l. localtax2_type, l.total_localtax1, l.total_localtax2,";
655 $sql .=
" l.total_ht, l.total_tva, l.total_ttc, l.info_bits, l.special_code, l.fk_parent_line, l.rang,";
656 $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,";
657 $sql .=
" l.fk_unit, l.extraparams,";
658 $sql .=
" l.date_start, l.date_end,";
659 $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';
660 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseurdet as l";
661 $sql .=
' LEFT JOIN '.$this->db->prefix().
'product as p ON l.fk_product = p.rowid';
662 $sql .=
" WHERE l.fk_commande = ".((int) $this->
id);
664 $sql .=
' AND p.fk_product_type = 0';
666 $sql .=
" ORDER BY l.rang, l.rowid";
669 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
671 $result = $this->db->query($sql);
673 $num = $this->db->num_rows($result);
677 $objp = $this->db->fetch_object($result);
681 $line->id = $objp->rowid;
682 $line->fk_commande = $objp->fk_commande;
683 $line->desc = $objp->description;
684 $line->description = $objp->description;
685 $line->qty = $objp->qty;
686 $line->tva_tx = $objp->tva_tx;
687 $line->localtax1_tx = $objp->localtax1_tx;
688 $line->localtax2_tx = $objp->localtax2_tx;
689 $line->localtax1_type = $objp->localtax1_type;
690 $line->localtax2_type = $objp->localtax2_type;
691 $line->subprice = $objp->subprice;
692 $line->pu_ht = $objp->subprice;
693 $line->subprice_ttc = $objp->subprice_ttc;
694 $line->pu_ttc = $objp->subprice_ttc;
695 $line->remise_percent = $objp->remise_percent;
697 $line->vat_src_code = $objp->vat_src_code;
698 $line->total_ht = $objp->total_ht;
699 $line->total_tva = $objp->total_tva;
700 $line->total_localtax1 = $objp->total_localtax1;
701 $line->total_localtax2 = $objp->total_localtax2;
702 $line->total_ttc = $objp->total_ttc;
703 $line->product_type = $objp->product_type;
705 $line->fk_product = $objp->fk_product;
707 $line->libelle = $objp->product_label;
708 $line->product_label = $objp->product_label;
709 $line->product_desc = $objp->product_desc;
710 $line->product_tobatch = $objp->product_tobatch;
711 $line->product_barcode = $objp->product_barcode;
713 $line->ref = $objp->product_ref;
714 $line->product_ref = $objp->product_ref;
715 $line->ref_fourn = $objp->ref_supplier;
716 $line->ref_supplier = $objp->ref_supplier;
723 $sqlsearchpackage =
'SELECT rowid, packaging FROM '.$this->db->prefix().
"product_fournisseur_price";
724 $sqlsearchpackage .=
' WHERE entity IN ('.getEntity(
'productsupplierprice').
")";
725 $sqlsearchpackage .=
" AND fk_product = ".((int) $objp->fk_product);
726 $sqlsearchpackage .=
" AND ref_fourn = '".$this->db->escape($objp->ref_supplier).
"'";
727 $sqlsearchpackage .=
" AND quantity <= ".abs((
float) $objp->qty);
728 $sqlsearchpackage .=
" AND (packaging IS NULL OR packaging = 0 OR packaging <= ".abs((
float) $objp->qty).
")";
729 $sqlsearchpackage .=
" AND fk_soc = ".((int) $this->socid);
730 $sqlsearchpackage .=
" ORDER BY packaging ASC";
731 $sqlsearchpackage .=
" LIMIT 1";
733 $resqlsearchpackage = $this->db->query($sqlsearchpackage);
734 if ($resqlsearchpackage) {
735 $objsearchpackage = $this->db->fetch_object($resqlsearchpackage);
736 if ($objsearchpackage) {
737 $line->fk_fournprice = $objsearchpackage->rowid;
738 $line->packaging = (float) $objsearchpackage->packaging;
741 $this->error = $this->db->lasterror();
746 $line->date_start = $this->db->jdate($objp->date_start);
747 $line->date_end = $this->db->jdate($objp->date_end);
748 $line->fk_unit = $objp->fk_unit;
750 $line->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams,
true) : array();
753 $line->fk_multicurrency = $objp->fk_multicurrency;
754 $line->multicurrency_code = $objp->multicurrency_code;
755 $line->multicurrency_subprice = $objp->multicurrency_subprice;
756 $line->multicurrency_subprice_ttc = $objp->multicurrency_subprice_ttc;
757 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
758 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
759 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
761 $line->info_bits = $objp->info_bits;
762 $line->special_code = $objp->special_code;
763 $line->fk_parent_line = $objp->fk_parent_line;
765 $line->rang = $objp->rang;
769 $line->fetch_optionals();
771 $this->lines[$i] = $line;
775 $this->db->free($result);
779 $this->error = $this->db->error().
" sql=".$sql;
792 public function valid($user, $idwarehouse = 0, $notrigger = 0)
795 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
801 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")))
802 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"fournisseur",
"supplier_order_advance",
"validate"))) {
806 dol_syslog(get_class($this).
"::valid checkActiveProductInLines ".$this->error, LOG_INFO);
811 $soc->fetch((
int) $this->fourn_id);
814 if (preg_match(
'/^[\(]?PROV/i', (
string) $this->
ref) || empty($this->ref)) {
815 $num = $this->getNextNumRef($soc);
817 $num = (string) $this->ref;
821 $sql =
'UPDATE '.$this->db->prefix().
"commande_fournisseur";
822 $sql .=
" SET ref='".$this->db->escape($num).
"',";
823 $sql .=
" fk_statut = ".((int) self::STATUS_VALIDATED).
",";
824 $sql .=
" date_valid='".$this->db->idate(
dol_now()).
"',";
825 $sql .=
" fk_user_valid = ".((int) $user->id);
826 $sql .=
" WHERE rowid = ".((int) $this->
id);
827 $sql .=
" AND fk_statut = ".((int) self::STATUS_DRAFT);
829 $resql = $this->db->query($sql);
835 if (!$error && !$notrigger) {
837 $result = $this->call_trigger(
'ORDER_SUPPLIER_VALIDATE', $user);
845 $this->oldref = $this->ref;
848 if (preg_match(
'/^[\(]?PROV/i', $this->ref)) {
850 $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).
"'";
851 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->ref).
"%' AND filepath = 'fournisseur/commande/".$this->db->escape($this->ref).
"' and entity = ".((int) $conf->entity);
852 $resql = $this->db->query($sql);
855 $this->error = $this->db->lasterror();
857 $sql =
'UPDATE '.$this->db->prefix().
"ecm_files set filepath = 'fournisseur/commande/".$this->db->escape($this->newref).
"'";
858 $sql .=
" WHERE filepath = 'fournisseur/commande/".$this->db->escape($this->ref).
"' and entity = ".$conf->entity;
859 $resql = $this->db->query($sql);
862 $this->error = $this->db->lasterror();
868 $dirsource = $conf->fournisseur->commande->dir_output.
'/'.$oldref;
869 $dirdest = $conf->fournisseur->commande->dir_output.
'/'.$newref;
870 if (!$error && file_exists($dirsource)) {
871 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
873 if (@rename($dirsource, $dirdest)) {
876 $listoffiles =
dol_dir_list($conf->fournisseur->commande->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
877 foreach ($listoffiles as $fileentry) {
878 $dirsource = $fileentry[
'name'];
879 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
880 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
881 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
882 @rename($dirsource, $dirdest);
900 $this->db->rollback();
904 $this->error =
'NotAuthorized';
905 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
930 public function LibStatut($status, $mode = 0, $billed = 0)
933 global $langs, $hookmanager;
935 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
936 $langs->load(
'orders');
938 $this->labelStatus[0] =
'StatusSupplierOrderDraft';
939 $this->labelStatus[1] =
'StatusSupplierOrderValidated';
940 $this->labelStatus[2] =
'StatusSupplierOrderApproved';
942 $this->labelStatus[3] =
'StatusSupplierOrderOnProcess';
944 $this->labelStatus[3] =
'StatusSupplierOrderOnProcessWithValidation';
946 $this->labelStatus[4] =
'StatusSupplierOrderReceivedPartially';
947 $this->labelStatus[5] =
'StatusSupplierOrderReceivedAll';
948 $this->labelStatus[6] =
'StatusSupplierOrderCanceled';
949 $this->labelStatus[7] =
'StatusSupplierOrderCanceled';
950 $this->labelStatus[9] =
'StatusSupplierOrderRefused';
953 $this->labelStatusShort[0] =
'StatusSupplierOrderDraftShort';
954 $this->labelStatusShort[1] =
'StatusSupplierOrderValidatedShort';
955 $this->labelStatusShort[2] =
'StatusSupplierOrderApprovedShort';
956 $this->labelStatusShort[3] =
'StatusSupplierOrderOnProcessShort';
957 $this->labelStatusShort[4] =
'StatusSupplierOrderReceivedPartiallyShort';
958 $this->labelStatusShort[5] =
'StatusSupplierOrderReceivedAllShort';
959 $this->labelStatusShort[6] =
'StatusSupplierOrderCanceledShort';
960 $this->labelStatusShort[7] =
'StatusSupplierOrderCanceledShort';
961 $this->labelStatusShort[9] =
'StatusSupplierOrderRefusedShort';
964 $statustrans = array(
976 $statusClass =
'status0';
977 if (!empty($statustrans[$status])) {
978 $statusClass = $statustrans[$status];
983 $billedtext =
' - '.$langs->trans(
"Billed");
985 if ($status == 5 && $billed) {
986 $statusClass =
'status6';
989 $statusLong = $langs->transnoentitiesnoconv($this->labelStatus[$status]).$billedtext;
990 $statusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
992 $parameters = array(
'status' => $status,
'mode' => $mode,
'billed' => $billed);
993 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
995 return $hookmanager->resPrint;
998 return dolGetStatus($statusLong, $statusShort,
'', $statusClass, $mode);
1009 global $conf, $langs, $user;
1011 $langs->loadLangs([
'bills',
'orders']);
1014 $nofetch = !empty($params[
'nofetch']);
1016 if ($user->hasRight(
"fournisseur",
"commande",
"read")) {
1017 $datas[
'picto'] =
'<u class="paddingrightonly">'.$langs->trans(
"SupplierOrder").
'</u>';
1019 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
1021 if (!empty($this->
ref)) {
1022 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
1024 if (!empty($this->ref_supplier)) {
1025 $datas[
'refsupplier'] =
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.$this->ref_supplier;
1028 $langs->load(
'companies');
1029 if (empty($this->thirdparty)) {
1032 $datas[
'supplier'] =
'<br><b>'.$langs->trans(
'Supplier').
':</b> '.$this->thirdparty->getNomUrl(1,
'', 0, 1);
1034 if (!empty($this->total_ht)) {
1035 $datas[
'totalht'] =
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
1037 if (!empty($this->total_tva)) {
1038 $datas[
'totaltva'] =
'<br><b>'.$langs->trans(
'VAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
1040 if (!empty($this->total_ttc)) {
1041 $datas[
'totalttc'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
1043 if (!empty($this->
date)) {
1044 $datas[
'date'] =
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->
date,
'day');
1046 if (!empty($this->delivery_date)) {
1047 $langs->load(
"sendings");
1048 $datas[
'deliverydate'] =
'<br><b>'.$langs->trans(
'DeliveryDate').
':</b> '.
dol_print_date($this->delivery_date,
'dayhour');
1064 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = 0)
1066 global $langs, $user, $hookmanager;
1071 'objecttype' => $this->element,
1072 'option' => $option,
1075 $classfortooltip =
'classfortooltip';
1078 $classfortooltip =
'classforajaxtooltip';
1079 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1085 $url = DOL_URL_ROOT.
'/fourn/commande/card.php?id='.$this->id;
1087 if ($option !==
'nolink') {
1089 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1090 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1091 $add_save_lastsearch_values = 1;
1093 if ($add_save_lastsearch_values) {
1094 $url .=
'&save_lastsearch_values=1';
1099 if (empty($notooltip)) {
1101 $label = $langs->trans(
"ShowOrder");
1102 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
1104 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
1105 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
1108 $linkstart =
'<a href="'.$url.
'"';
1109 $linkstart .= $linkclose.
'>';
1112 $result .= $linkstart;
1114 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
1116 if ($withpicto != 2) {
1117 $result .= $this->ref;
1119 $result .= $linkend;
1121 if ($addlinktonotes) {
1122 $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
1125 $result .=
' <span class="note inline-block">';
1126 $result .=
'<a href="'.DOL_URL_ROOT.
'/fourn/commande/note.php?id='.$this->
id.
'" class="classfortooltip" title="'.
dol_escape_htmltag($notetoshow).
'">';
1131 $result .=
'</span>';
1136 $hookmanager->initHooks(array($this->element .
'dao'));
1137 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1138 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1140 $result = $hookmanager->resPrint;
1142 $result .= $hookmanager->resPrint;
1155 public function getNextNumRef($soc)
1157 global $langs, $conf;
1158 $langs->load(
"orders");
1167 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
1169 foreach ($dirmodels as $reldir) {
1170 $dir =
dol_buildpath($reldir.
"core/modules/supplier_order/");
1173 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1181 $obj =
new $classname();
1182 '@phan-var-force ModeleNumRefSuppliersOrders $obj';
1184 $numref = $obj->getNextValue($soc, $this);
1186 if ($numref !=
"") {
1189 $this->error = $obj->error;
1193 $this->error =
"Error_COMMANDE_SUPPLIER_ADDON_NotDefined";
1208 if ($this->billed) {
1214 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur SET billed = 1';
1217 if ($this->db->query($sql)) {
1219 $result = $this->call_trigger(
'ORDER_SUPPLIER_CLASSIFY_BILLED', $user);
1228 $this->db->commit();
1231 $this->db->rollback();
1237 $this->db->rollback();
1251 if (empty($this->billed)) {
1257 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur SET billed = 0';
1261 if (!$this->db->query($sql)) {
1263 $this->db->rollback();
1268 $result = $this->call_trigger(
'ORDER_SUPPLIER_CLASSIFY_UNBILLED', $user);
1270 $this->db->rollback();
1276 $this->db->commit();
1289 public function approve($user, $idwarehouse = 0, $secondlevel = 0)
1293 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1299 if ($user->hasRight(
"fournisseur",
"commande",
"approuver")) {
1305 $soc =
new Societe($this->db);
1306 $soc->fetch((
int) $this->fourn_id);
1309 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
1310 $num = $this->getNextNumRef($soc);
1312 $num = (string) $this->
ref;
1317 $movetoapprovestatus =
true;
1320 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1321 $sql .=
" SET ref='".$this->db->escape($num).
"',";
1322 if (empty($secondlevel)) {
1323 $sql .=
" date_approve='".$this->db->idate($now).
"',";
1324 $sql .=
" fk_user_approve = ".((int) $user->id);
1326 if (empty($this->user_approve_id2)) {
1327 $movetoapprovestatus =
false;
1328 $comment =
' (first level)';
1332 $sql .=
" date_approve2='".$this->db->idate($now).
"',";
1333 $sql .=
" fk_user_approve2 = ".((int) $user->id);
1334 if (empty($this->user_approve_id)) {
1335 $movetoapprovestatus =
false;
1337 $comment =
' (second level)';
1340 if ($movetoapprovestatus) {
1341 $sql .=
", fk_statut = ".self::STATUS_ACCEPTED;
1343 $sql .=
", fk_statut = ".self::STATUS_VALIDATED;
1345 $sql .=
" WHERE rowid = ".((int) $this->
id);
1346 $sql .=
" AND fk_statut = ".self::STATUS_VALIDATED;
1348 if ($this->db->query($sql)) {
1350 $result = $this->
add_contact($user->id,
'SALESREPFOLL',
'internal', 1);
1351 if ($result < 0 && $result != -2) {
1358 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1359 $langs->load(
"agenda");
1361 $cpt = count($this->lines);
1362 for ($i = 0; $i < $cpt; $i++) {
1364 if ($this->lines[$i]->fk_product > 0) {
1365 $this->line = $this->lines[$i];
1367 $mouvP->origin = &$this;
1368 $mouvP->setOrigin($this->element, $this->
id);
1370 $up_ht_disc = $this->lines[$i]->subprice;
1371 if (!empty($this->lines[$i]->remise_percent) && !
getDolGlobalString(
'STOCK_EXCLUDE_DISCOUNT_FOR_PMP')) {
1372 $up_ht_disc =
price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100,
'MU');
1374 $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans(
"OrderApprovedInDolibarr", $this->ref));
1385 $result = $this->call_trigger(
'ORDER_SUPPLIER_APPROVE', $user);
1393 $this->
ref = $this->newref;
1395 if ($movetoapprovestatus) {
1402 if (empty($secondlevel)) {
1403 $this->date_approve = $now;
1404 $this->user_approve_id = $user->id;
1406 $this->date_approve2 = $now;
1407 $this->user_approve_id2 = $user->id;
1410 $this->db->commit();
1413 $this->db->rollback();
1417 $this->db->rollback();
1418 $this->error = $this->db->lasterror();
1422 dol_syslog(get_class($this).
"::approve Not Authorized", LOG_ERR);
1439 if ($user->hasRight(
"fournisseur",
"commande",
"approuver")) {
1442 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur SET fk_statut = ".
self::STATUS_REFUSED;
1443 $sql .=
" WHERE rowid = ".((int) $this->
id);
1445 if ($this->db->query($sql)) {
1450 $result = $this->call_trigger(
'ORDER_SUPPLIER_REFUSE', $user);
1453 $this->db->rollback();
1455 $this->db->commit();
1460 $this->db->rollback();
1461 $this->error = $this->db->lasterror();
1462 dol_syslog(get_class($this).
"::refuse Error -1");
1466 dol_syslog(get_class($this).
"::refuse Not Authorized");
1480 public function cancel($user, $idwarehouse = -1)
1487 if ($user->hasRight(
"fournisseur",
"commande",
"commander")) {
1492 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur SET fk_statut = ".((int) $statut);
1493 $sql .=
" WHERE rowid = ".((int) $this->
id);
1494 dol_syslog(get_class($this).
"::cancel", LOG_DEBUG);
1495 if ($this->db->query($sql)) {
1499 $result = $this->call_trigger(
'ORDER_SUPPLIER_CANCEL', $user);
1506 $this->db->commit();
1509 $this->db->rollback();
1513 $this->db->rollback();
1514 $this->error = $this->db->lasterror();
1515 dol_syslog(get_class($this).
"::cancel ".$this->error);
1519 dol_syslog(get_class($this).
"::cancel Not Authorized");
1533 public function commande($user, $date, $methode, $comment =
'')
1538 if ($user->hasRight(
"fournisseur",
"commande",
"commander")) {
1541 $newnoteprivate = $this->note_private;
1543 $newnoteprivate =
dol_concatdesc($newnoteprivate, $langs->trans(
"Comment").
': '.$comment);
1546 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1547 $sql .=
" SET fk_statut=".self::STATUS_ORDERSENT.
", fk_input_method=".$methode.
", date_commande='".$this->db->idate($date).
"', ";
1548 $sql .=
" note_private='".$this->db->escape((
string) $newnoteprivate).
"'";
1549 $sql .=
" WHERE rowid=".((int) $this->
id);
1551 dol_syslog(get_class($this).
"::commande", LOG_DEBUG);
1552 if ($this->db->query($sql)) {
1555 $this->methode_commande_id = $methode;
1556 $this->date_commande = $date;
1557 $this->context[
'comments'] = $comment;
1560 $result = $this->call_trigger(
'ORDER_SUPPLIER_SUBMIT', $user);
1567 $this->error = $this->db->lasterror();
1568 $this->errors[] = $this->db->lasterror();
1572 $this->db->commit();
1574 $this->db->rollback();
1578 $this->error = $langs->trans(
'NotAuthorized');
1579 $this->errors[] = $langs->trans(
'NotAuthorized');
1580 dol_syslog(get_class($this).
"::commande User not Authorized", LOG_WARNING);
1583 return ($error ? -1 : 1);
1593 public function create($user, $notrigger = 0)
1603 $date = ($this->date_commande ? $this->date_commande : $this->date);
1607 $delivery_date = $this->delivery_date;
1610 if (empty($this->source)) {
1615 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
1620 if (empty($this->fk_multicurrency)) {
1621 $this->multicurrency_code = $conf->currency;
1622 $this->fk_multicurrency = 0;
1623 $this->multicurrency_tx = 1;
1631 $sql =
"INSERT INTO ".$this->db->prefix().
"commande_fournisseur (";
1633 $sql .=
", ref_supplier";
1634 $sql .=
", note_private";
1635 $sql .=
", note_public";
1638 $sql .=
", fk_projet";
1639 $sql .=
", date_creation";
1640 $sql .=
", date_livraison";
1641 $sql .=
", fk_user_author";
1642 $sql .=
", fk_statut";
1644 $sql .=
", model_pdf";
1645 $sql .=
", fk_mode_reglement";
1646 $sql .=
", deposit_percent";
1647 $sql .=
", fk_cond_reglement";
1648 $sql .=
", fk_account";
1649 $sql .=
", fk_incoterms, location_incoterms";
1650 $sql .=
", fk_multicurrency";
1651 $sql .=
", multicurrency_code";
1652 $sql .=
", multicurrency_tx";
1654 $sql .=
" VALUES (";
1656 $sql .=
", ".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"NULL");
1657 $sql .=
", '".$this->db->escape($this->note_private).
"'";
1658 $sql .=
", '".$this->db->escape($this->note_public).
"'";
1659 $sql .=
", ".((int) $this->entity);
1660 $sql .=
", ".((int) $this->socid);
1661 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
1662 $sql .=
", '".$this->db->idate($date).
"'";
1663 $sql .=
", ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
"null");
1664 $sql .=
", ".((int) $user->id);
1665 $sql .=
", ".self::STATUS_DRAFT;
1666 $sql .=
", ".((int) $this->source);
1667 $sql .=
", '".$this->db->escape(
getDolGlobalString(
'COMMANDE_SUPPLIER_ADDON_PDF')).
"'";
1668 $sql .=
", ".($this->mode_reglement_id > 0 ? $this->mode_reglement_id :
'null');
1669 $sql .=
", ".(!empty($this->deposit_percent) ?
"'" . $this->db->escape($this->deposit_percent) .
"'" :
"null");
1670 $sql .=
", ".($this->cond_reglement_id > 0 ? $this->cond_reglement_id :
'null');
1671 $sql .=
", ".($this->fk_account > 0 ? $this->fk_account :
'NULL');
1672 $sql .=
", ".(int) $this->fk_incoterms;
1673 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
1674 $sql .=
", ".(int) $this->fk_multicurrency;
1675 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1676 $sql .=
", ".(float) $this->multicurrency_tx;
1679 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1680 if ($this->db->query($sql)) {
1681 $this->
id = $this->db->last_insert_id($this->db->prefix().
"commande_fournisseur");
1684 $num = count($this->lines);
1687 for ($i = 0; $i < $num; $i++) {
1688 $line = $this->lines[$i];
1689 if (!is_object($line)) {
1690 $line = (object) $line;
1697 (
string) $line->desc,
1698 (
float) $line->subprice,
1701 (
float) $line->localtax1_tx,
1702 (
float) $line->localtax2_tx,
1703 (
int) $line->fk_product,
1705 (
string) ($line->ref_supplier ? $line->ref_supplier : $line->ref_fourn),
1706 (
float) $line->remise_percent,
1708 (float) $line->subprice_ttc,
1709 (
int) $line->product_type,
1710 (int) $line->info_bits,
1712 $line->date_start ??
null,
1713 $line->date_end ??
null,
1714 $line->array_options ?? [],
1715 $line->fk_unit ??
null,
1716 (
float) $line->multicurrency_subprice,
1717 (string) $line->origin,
1718 (
int) $line->origin_id,
1719 (int) ($line->rang ?? -1),
1720 (int) $line->special_code
1723 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
1724 $this->db->rollback();
1729 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1730 $sql .=
" SET ref='(PROV".$this->id.
")'";
1731 $sql .=
" WHERE rowid=".((int) $this->
id);
1733 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1734 if ($this->db->query($sql)) {
1737 $this->
ref =
"(PROV".$this->id.
")";
1739 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
1740 $this->linked_objects = $this->linkedObjectsIds;
1744 if (!empty($this->linked_objects) && is_array($this->linked_objects)) {
1745 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
1746 if (is_array($tmp_origin_id)) {
1747 foreach ($tmp_origin_id as $origin_id) {
1755 $origin_id = $tmp_origin_id;
1773 if (!$error && !$notrigger) {
1775 $result = $this->call_trigger(
'ORDER_SUPPLIER_CREATE', $user);
1777 $this->db->rollback();
1784 $this->db->commit();
1787 $this->error = $this->db->lasterror();
1788 $this->db->rollback();
1793 $this->error =
'Failed to get ID of inserted line';
1798 $this->error = $this->db->lasterror();
1799 $this->db->rollback();
1817 if (isset($this->
ref)) {
1818 $this->
ref = trim($this->
ref);
1820 if (isset($this->ref_supplier)) {
1821 $this->ref_supplier = trim($this->ref_supplier);
1823 if (isset($this->note_private)) {
1824 $this->note_private = trim($this->note_private);
1826 if (isset($this->note_public)) {
1827 $this->note_public = trim($this->note_public);
1829 if (isset($this->model_pdf)) {
1830 $this->model_pdf = trim($this->model_pdf);
1832 if (isset($this->import_key)) {
1833 $this->import_key = trim($this->import_key);
1837 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
1839 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1840 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
1841 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1842 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
1843 $sql .=
" date_commande=".(strval($this->date_commande) !=
'' ?
"'".$this->db->idate($this->date_commande).
"'" :
'null').
",";
1844 $sql .=
" date_valid=".(strval($this->date_validation) !=
'' ?
"'".$this->db->idate($this->date_validation).
"'" :
'null').
",";
1845 $sql .=
" total_tva=".(isset($this->total_tva) ? (float) $this->total_tva :
"null").
",";
1846 $sql .=
" localtax1=".(isset($this->total_localtax1) ? (float) $this->total_localtax1 :
"null").
",";
1847 $sql .=
" localtax2=".(isset($this->total_localtax2) ? (float) $this->total_localtax2 :
"null").
",";
1848 $sql .=
" total_ht=".(isset($this->total_ht) ? (float) $this->total_ht :
"null").
",";
1849 $sql .=
" total_ttc=".(isset($this->total_ttc) ? (float) $this->total_ttc :
"null").
",";
1850 $sql .=
" fk_statut=".(isset($this->
status) ? (int) $this->
status :
"null").
",";
1851 $sql .=
" fk_user_author=".(isset($this->user_author_id) ? (int) $this->user_author_id :
"null").
",";
1852 $sql .=
" fk_user_valid=".(isset($this->user_validation_id) && $this->user_validation_id > 0 ? (int) $this->user_validation_id :
"null").
",";
1853 $sql .=
" fk_projet=".((!empty($this->fk_project) && $this->fk_project > 0) ? (
int) $this->fk_project :
"null").
",";
1854 $sql .=
" fk_cond_reglement=".(isset($this->cond_reglement_id) ? (int) $this->cond_reglement_id :
"null").
",";
1855 $sql .=
" deposit_percent=".(!empty($this->deposit_percent) ?
"'".$this->db->escape($this->deposit_percent).
"'" :
"null").
",";
1856 $sql .=
" fk_mode_reglement=".(isset($this->mode_reglement_id) ? (int) $this->mode_reglement_id :
"null").
",";
1857 $sql .=
" date_livraison=".(strval($this->delivery_date) !=
'' ?
"'".$this->db->idate($this->delivery_date).
"'" :
'null').
",";
1859 $sql .=
" fk_account=".($this->fk_account > 0 ? $this->fk_account :
"null").
",";
1861 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1862 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1863 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1864 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
1866 $sql .=
" WHERE rowid=".((int) $this->
id);
1870 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1871 $resql = $this->db->query($sql);
1874 $this->errors[] =
"Error ".$this->db->lasterror();
1884 if (!$error && !$notrigger) {
1886 $result = $this->call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
1895 foreach ($this->errors as $errmsg) {
1896 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1897 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1899 $this->db->rollback();
1902 $this->db->commit();
1917 global $conf, $user, $hookmanager;
1924 foreach ($this->lines as $line) {
1925 $line->fetch_optionals();
1929 $objFrom = clone $this;
1932 if (!empty($socid) && $socid != $this->socid) {
1933 $objsoc =
new Societe($this->db);
1935 if ($objsoc->fetch($socid) > 0) {
1936 $this->socid = $objsoc->id;
1937 $this->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1938 $this->deposit_percent = (!empty($objsoc->deposit_percent) ? $objsoc->deposit_percent :
'0');
1939 $this->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1940 $this->fk_project = 0;
1941 $this->fk_delivery_address = 0;
1952 $this->user_author_id = $user->id;
1953 $this->user_validation_id = 0;
1956 $this->date_creation = 0;
1957 $this->date_validation = 0;
1958 $this->date_commande =
null;
1959 $this->ref_supplier =
'';
1960 $this->user_approve_id = 0;
1961 $this->user_approve_id2 = 0;
1962 $this->date_approve = 0;
1963 $this->date_approve2 = 0;
1966 $this->context[
'createfromclone'] =
'createfromclone';
1967 $result = $this->
create($user, $notrigger);
1974 if (is_object($hookmanager)) {
1975 $parameters = array(
'objFrom' => $objFrom);
1977 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1985 unset($this->context[
'createfromclone']);
1989 $this->db->commit();
1992 $this->db->rollback();
2026 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)
2030 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");
2031 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2033 if ($this->
status == self::STATUS_DRAFT) {
2034 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2043 if (empty($txtva)) {
2049 if (empty($txlocaltax1)) {
2052 if (empty($txlocaltax2)) {
2055 if (empty($remise_percent)) {
2056 $remise_percent = 0;
2059 $remise_percent =
price2num($remise_percent);
2062 $pu_ht_devise =
price2num($pu_ht_devise);
2064 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
2069 if ($price_base_type ==
'HT') {
2074 $desc = trim((
string) $desc);
2077 if ($qty < 0 && !$fk_product) {
2078 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Product"));
2084 if ($date_start && $date_end && $date_start > $date_end) {
2085 $langs->load(
"errors");
2086 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
2093 $product_type = $type;
2096 if ($fk_product > 0) {
2097 if (
getDolGlobalInt(
'SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY') == 1) {
2099 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);
2101 if ($prod->fetch($fk_product) > 0) {
2102 $product_type = $prod->type;
2103 $label = $prod->label;
2107 $result = $prod->get_buyprice($fk_prod_fourn_price, (
float) $qty, $fk_product,
'none', (isset($this->fk_soc) ? $this->fk_soc : $this->socid));
2111 if ($result > 0 && ($origin ==
'commande' || $pu ===
'')) {
2112 $pu = $prod->fourn_pu;
2113 $ref_supplier = $prod->ref_supplier;
2115 if ($remise_percent == 0 && $prod->remise_percent != 0) {
2116 $remise_percent = $prod->remise_percent;
2120 $langs->load(
"errors");
2121 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
2122 $this->db->rollback();
2123 dol_syslog(get_class($this).
"::addline we did not found supplier price, so we can't guess unit price");
2128 if ($result == -1) {
2129 $langs->load(
"errors");
2130 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
2131 $this->db->rollback();
2132 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_DEBUG);
2136 $this->error = $prod->error;
2137 $this->db->rollback();
2138 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_ERR);
2142 $this->error = $prod->error;
2143 $this->db->rollback();
2150 $prod =
new Product($this->db);
2151 $prod->get_buyprice($fk_prod_fourn_price, (
float) $qty, $fk_product,
'none', (empty($this->fk_soc) ? $this->socid : $this->fk_soc));
2156 if ($newqty != $qty) {
2158 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'warnings');
2166 if (!empty($prod->fourn_qty) && (
float) $qty > 0 && (
float) $qty < (
float) $prod->fourn_qty) {
2167 if (!empty($prod->packaging) && (
float)
price2num(fmod((
float) $prod->fourn_qty, (
float) $prod->packaging),
'MS')) {
2168 $coeff = intval((
float) $prod->fourn_qty / (
float) $prod->packaging) + 1;
2169 $qty = (float)
price2num((
float) $prod->packaging * $coeff,
'MS');
2171 $qty = (float) $prod->fourn_qty;
2173 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'mesgs');
2178 if (
isModEnabled(
"multicurrency") && $pu_ht_devise > 0) {
2187 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
2188 $vat_src_code = $reg[1];
2189 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
2197 $tabprice =
calcul_price_total((
float) $qty, $pu, $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);
2199 $total_ht = $tabprice[0];
2200 $total_tva = $tabprice[1];
2201 $total_ttc = $tabprice[2];
2202 $total_localtax1 = $tabprice[9];
2203 $total_localtax2 = $tabprice[10];
2204 $pu = $pu_ht = $tabprice[3];
2205 $pu_tva = $tabprice[4];
2206 $pu_ttc = $tabprice[5];
2209 $multicurrency_total_ht = $tabprice[16];
2210 $multicurrency_total_tva = $tabprice[17];
2211 $multicurrency_total_ttc = $tabprice[18];
2212 $pu_ht_devise = $tabprice[19];
2213 $multicurrency_pu_ttc = $tabprice[21];
2215 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2216 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2220 $rang = $rangmax + 1;
2226 $this->line->context = $this->context;
2228 $this->line->fk_commande = $this->id;
2229 $this->line->label = $label;
2230 $this->line->ref_fourn = $ref_supplier;
2231 $this->line->ref_supplier = $ref_supplier;
2232 $this->line->desc = $desc;
2233 $this->line->qty = $qty;
2234 $this->line->tva_tx = $txtva;
2235 $this->line->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0);
2236 $this->line->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0);
2237 $this->line->localtax1_type = $localtax1_type;
2238 $this->line->localtax2_type = $localtax2_type;
2239 $this->line->fk_product = $fk_product;
2240 $this->line->product_type = $product_type;
2241 $this->line->remise_percent = $remise_percent;
2242 $this->line->subprice = (float) $pu_ht;
2243 $this->line->subprice_ttc = (float) $pu_ttc;
2245 $this->line->rang = $rang;
2246 $this->line->info_bits = $info_bits;
2248 $this->line->vat_src_code = $vat_src_code;
2249 $this->line->total_ht = (float) $total_ht;
2250 $this->line->total_tva = (float) $total_tva;
2251 $this->line->total_localtax1 = (float) $total_localtax1;
2252 $this->line->total_localtax2 = (float) $total_localtax2;
2253 $this->line->total_ttc = (float) $total_ttc;
2254 $this->line->product_type = $type;
2255 $this->line->special_code = (!empty($special_code) ? $special_code : 0);
2256 $this->line->origin = $origin;
2257 $this->line->origin_type = $origin;
2258 $this->line->origin_id = $origin_id;
2259 $this->line->fk_unit = $fk_unit;
2261 $this->line->date_start = $date_start;
2262 $this->line->date_end = $date_end;
2265 $this->line->fk_multicurrency = $this->fk_multicurrency;
2266 $this->line->multicurrency_code = $this->multicurrency_code;
2267 $this->line->multicurrency_subprice = (float) $pu_ht_devise;
2268 $this->line->multicurrency_subprice_ttc = (float) $multicurrency_pu_ttc;
2269 $this->line->multicurrency_total_ht = (float) $multicurrency_total_ht;
2270 $this->line->multicurrency_total_tva = (float) $multicurrency_total_tva;
2271 $this->line->multicurrency_total_ttc = (float) $multicurrency_total_ttc;
2273 $this->line->subprice = (float) $pu_ht;
2274 $this->line->price = $this->line->subprice;
2276 $this->line->remise_percent = $remise_percent;
2278 if (is_array($array_options) && count($array_options) > 0) {
2279 $this->line->array_options = $array_options;
2282 $result = $this->line->insert($notrigger);
2285 $result = $this->
update_price(1,
'auto', 0, $this->thirdparty);
2288 if (!isset($this->context[
'createfromclone'])) {
2289 if (!empty($this->line->fk_parent_line)) {
2292 } elseif ($rang > 0 && $rang <= count($this->lines)) {
2294 $linecount = count($this->lines);
2295 for ($ii = $rang; $ii <= $linecount; $ii++) {
2300 $this->lines[] = $this->line;
2303 $this->db->commit();
2304 return $this->line->id;
2306 $this->db->rollback();
2311 dol_syslog(get_class($this).
"::addline error=".$this->error, LOG_ERR);
2312 $this->db->rollback();
2337 public function dispatchProduct($user, $product, $qty, $entrepot, $price = 0, $comment =
'', $eatby =
'', $sellby =
'', $batch =
'', $fk_commandefourndet = 0, $notrigger = 0, $fk_reception = 0)
2339 global $conf, $langs;
2342 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2345 if ($entrepot <= 0) {
2346 $this->error =
'ErrorBadValueForParameterWarehouse';
2350 $this->error =
'ErrorBadValueForParameterQty';
2354 $dispatchstatus = 1;
2356 $dispatchstatus = 0;
2363 if (($this->
status == self::STATUS_ORDERSENT || $this->
status == self::STATUS_RECEIVED_PARTIALLY || $this->
status == self::STATUS_RECEIVED_COMPLETELY)) {
2366 $sql =
"INSERT INTO ".$this->db->prefix().
"receptiondet_batch";
2367 $sql .=
" (fk_element, fk_product, qty, fk_entrepot, fk_user, datec, fk_elementdet, status, comment, eatby, sellby, batch, fk_reception) VALUES";
2368 $sql .=
" ('".$this->id.
"','".$product.
"','".$qty.
"',".($entrepot > 0 ?
"'".$entrepot.
"'" :
"null").
",'".$user->id.
"','".$this->db->idate($now).
"','".$fk_commandefourndet.
"', ".$dispatchstatus.
", '".$this->db->escape($comment).
"', ";
2369 $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");
2372 dol_syslog(get_class($this).
"::dispatchProduct", LOG_DEBUG);
2373 $resql = $this->db->query($sql);
2376 global $conf, $langs, $user;
2378 $result = $this->call_trigger(
'LINEORDER_SUPPLIER_DISPATCH', $user);
2385 $this->error = $this->db->lasterror();
2394 $mouv->origin = &$this;
2395 $mouv->setOrigin($this->element, $this->
id);
2398 if (
getDolGlobalString(
'SUPPLIER_ORDER_ALLOW_NEGATIVE_QTY_FOR_SUPPLIER_ORDER_RETURN') && $qty < 0) {
2399 $result = $mouv->livraison($user, $product, $entrepot, $qty * (-1), $price, $comment, $now, $eatby, $sellby, $batch, 0, $inventorycode);
2401 $result = $mouv->reception($user, $product, $entrepot, $qty, $price, $comment, $eatby, $sellby, $batch,
'', 0, $inventorycode);
2405 $this->error = $mouv->error;
2406 $this->errors = $mouv->errors;
2407 dol_syslog(get_class($this).
"::dispatchProduct ".$this->error.
" ".implode(
',', $this->errors), LOG_ERR);
2414 $this->db->commit();
2417 $this->db->rollback();
2421 $this->error =
'BadStatusForObject';
2437 if ($this->
status == 0) {
2440 if ($line->fetch($idline) <= 0) {
2443 if ($this->
id > 0 && (
int) $line->fk_commande !== (
int) $this->id) {
2444 $this->error =
'ErrorLineIDDoesNotMatchWithObjectID';
2450 foreach ($dispatchedLines as $dispatchLine) {
2451 if ($dispatchLine[
'orderlineid'] == $idline) {
2452 $this->error =
"LineAlreadyDispatched";
2453 $this->errors[] = $this->error;
2458 if ($line->delete($user, $notrigger) > 0) {
2477 public function delete(
User $user, $notrigger = 0)
2479 global $langs, $conf;
2480 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2486 if (empty($notrigger)) {
2488 $result = $this->call_trigger(
'ORDER_SUPPLIER_DELETE', $user);
2490 $this->errors[] =
'ErrorWhenRunningTrigger';
2491 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2492 $this->db->rollback();
2500 if (!empty($this->linkedObjects) && array_key_exists(
'reception', $this->linkedObjects)) {
2501 foreach ($this->linkedObjects[
'reception'] as $element) {
2502 if ($element->statut >= 0) {
2503 $this->errors[] = $langs->trans(
'ReceptionExist');
2512 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_supplier_order";
2513 $sql .=
" WHERE fk_supplier_order = ".((int) $this->
id);
2515 $result = $this->db->query($sql);
2518 $this->errors[] = $this->db->lasterror();
2522 $main = $this->db->prefix().
'commande_fournisseurdet';
2525 $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).
")";
2526 dol_syslog(__METHOD__.
" linked order lines", LOG_DEBUG);
2527 if (!$this->db->query($sql1)) {
2529 $this->error = $this->db->lasterror();
2530 $this->errors[] = $this->db->lasterror();
2535 $ef = $main.
"_extrafields";
2536 $sql =
"DELETE FROM ".$this->db->sanitize($ef).
" WHERE fk_object IN (SELECT rowid FROM ".$this->db->sanitize($main).
" WHERE fk_commande = ".((int) $this->
id).
")";
2537 dol_syslog(get_class($this).
"::delete extrafields lines", LOG_DEBUG);
2538 if (!$this->db->query($sql)) {
2539 $this->error = $this->db->lasterror();
2540 $this->errors[] = $this->db->lasterror();
2546 $sql =
"DELETE FROM ".$this->db->prefix().
"commande_fournisseurdet WHERE fk_commande = ".((int) $this->
id);
2547 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2548 if (!$this->db->query($sql)) {
2549 $this->error = $this->db->lasterror();
2550 $this->errors[] = $this->db->lasterror();
2556 $sql =
"DELETE FROM ".$this->db->prefix().
"commande_fournisseur WHERE rowid = ".((int) $this->
id);
2557 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2558 if ($resql = $this->db->query($sql)) {
2559 if ($this->db->affected_rows($resql) < 1) {
2560 $this->error = $this->db->lasterror();
2561 $this->errors[] = $this->db->lasterror();
2565 $this->error = $this->db->lasterror();
2566 $this->errors[] = $this->db->lasterror();
2575 $this->error =
'FailToDeleteExtraFields';
2576 $this->errors[] =
'FailToDeleteExtraFields';
2578 dol_syslog(get_class($this).
"::delete error -4 ".$this->error, LOG_ERR);
2585 $this->error =
'FailToDeleteObjectLinked';
2586 $this->errors[] =
'FailToDeleteObjectLinked';
2597 if ($conf->fournisseur->commande->dir_output && !empty($ref)) {
2598 $dir = $conf->fournisseur->commande->dir_output.
"/".$ref;
2599 $file = $dir.
"/".$ref.
".pdf";
2600 if (file_exists($file)) {
2602 $this->error =
'ErrorFailToDeleteFile';
2603 $this->errors[] =
'ErrorFailToDeleteFile';
2607 if (file_exists($dir)) {
2610 $this->error =
'ErrorFailToDeleteDir';
2611 $this->errors[] =
'ErrorFailToDeleteDir';
2619 dol_syslog(get_class($this).
"::delete $this->id by $user->id", LOG_DEBUG);
2620 $this->db->commit();
2623 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2624 $this->db->rollback();
2643 $sql =
"SELECT p.ref, p.label,";
2644 $sql .=
" e.rowid as warehouse_id, e.ref as entrepot,";
2645 $sql .=
" cfd.rowid as dispatchedlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status, cfd.fk_elementdet";
2646 $sql .=
" FROM ".$this->db->prefix().
"product as p,";
2647 $sql .=
" ".$this->db->prefix().
"receptiondet_batch as cfd";
2648 $sql .=
" LEFT JOIN ".$this->db->prefix().
"entrepot as e ON cfd.fk_entrepot = e.rowid";
2649 $sql .=
" WHERE cfd.fk_element = ".((int) $this->
id);
2650 $sql .=
" AND cfd.fk_product = p.rowid";
2652 $sql .=
" AND cfd.status = ".((int) $status);
2654 $sql .=
" ORDER BY cfd.rowid ASC";
2656 $resql = $this->db->query($sql);
2658 $num = $this->db->num_rows($resql);
2662 $objp = $this->db->fetch_object($resql);
2665 'id' => $objp->dispatchedlineid,
2666 'productid' => $objp->fk_product,
2667 'warehouseid' => $objp->warehouse_id,
2668 'qty' => $objp->qty,
2669 'orderlineid' => $objp->fk_elementdet
2676 dol_print_error($this->db,
'Failed to execute request to get dispatched lines');
2695 global $conf, $langs;
2699 $dispatchedlinearray = array();
2703 $usercanreceive = 0;
2705 $usercanreceive = $user->hasRight(
"fournisseur",
"commande",
"receptionner");
2707 $usercanreceive = $user->hasRight(
"reception",
"creer");
2710 if ($usercanreceive) {
2712 if ($type ==
'par') {
2714 } elseif ($type ==
'tot') {
2716 } elseif ($type ==
'nev') {
2718 } elseif ($type ==
'can') {
2722 dol_syslog(get_class($this).
"::Livraison Error -2", LOG_ERR);
2729 if ($type ==
'tot') {
2731 if (count($dispatchedlinearray) > 0) {
2734 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove';
2735 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove', LOG_DEBUG);
2738 if (!$error &&
getDolGlobalString(
'SUPPLIER_ORDER_USE_DISPATCH_STATUS_NEED_APPROVE') && ($type ==
'tot')) {
2740 if (count($dispatchedlinearray) > 0) {
2743 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied';
2744 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied', LOG_DEBUG);
2751 if (empty($error)) {
2754 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2755 $sql .=
" SET fk_statut = ".((int) $statut);
2756 $sql .=
" WHERE rowid = ".((int) $this->
id);
2757 $sql .=
" AND fk_statut IN (".self::STATUS_ORDERSENT.
",".self::STATUS_RECEIVED_PARTIALLY.
")";
2759 dol_syslog(get_class($this).
"::Livraison", LOG_DEBUG);
2760 $resql = $this->db->query($sql);
2763 $old_statut = $this->status;
2765 $this->context[
'actionmsg2'] = $comment;
2768 $result_trigger = $this->call_trigger(
'ORDER_SUPPLIER_RECEIVE', $user);
2769 if ($result_trigger < 0) {
2774 if (empty($error)) {
2775 $this->db->commit();
2777 $this->
status = $old_statut;
2778 $this->db->rollback();
2779 $this->error = $this->db->lasterror();
2783 $this->db->rollback();
2784 $this->error = $this->db->lasterror();
2789 $this->error = $langs->trans(
'NotAuthorized');
2790 $this->errors[] = $langs->trans(
'NotAuthorized');
2791 dol_syslog(get_class($this).
"::Livraison Not Authorized");
2823 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
2828 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2829 $sql .=
" SET date_livraison = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2830 $sql .=
" WHERE rowid = ".((int) $this->
id);
2833 $resql = $this->db->query($sql);
2835 $this->errors[] = $this->db->error();
2840 $this->oldcopy = clone $this;
2841 $this->delivery_date = $delivery_date;
2844 if (!$notrigger && empty($error)) {
2846 $result = $this->call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2854 $this->db->commit();
2857 foreach ($this->errors as $errmsg) {
2858 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2859 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2861 $this->db->rollback();
2877 if (in_array($this->
status, [1, 2, 3, 4, 5, 6, 7, 9])) {
2878 if ($this->
status == 1) {
2880 } elseif ($this->
status == 2) {
2882 } elseif ($this->
status == 3) {
2884 } elseif ($this->
status == 4) {
2886 } elseif ($this->
status == 5) {
2892 } elseif ($this->
status == 6) {
2894 } elseif ($this->
status == 7) {
2896 } elseif ($this->
status == 9) {
2904 $result = $this->
setStatus($user, $newStatus);
2906 if ($newStatus == 0) {
2907 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur';
2908 $sql .=
' SET fk_user_approve = null, fk_user_approve2 = null, date_approve = null, date_approve2 = null';
2909 $sql .=
' WHERE rowid = '.((int) $this->
id);
2911 $this->db->query($sql);
2914 $this->db->commit();
2918 $this->db->rollback();
2939 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
2944 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2945 $sql .=
" SET fk_projet = ".($id_projet > 0 ? (int) $id_projet :
'null');
2946 $sql .=
" WHERE rowid = ".((int) $this->
id);
2949 $resql = $this->db->query($sql);
2951 $this->errors[] = $this->db->error();
2956 $this->oldcopy = clone $this;
2957 $this->fk_projet = $id_projet;
2958 $this->fk_project = $id_projet;
2961 if (!$notrigger && empty($error)) {
2963 $result = $this->call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2971 $this->db->commit();
2974 foreach ($this->errors as $errmsg) {
2975 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2976 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2978 $this->db->rollback();
2996 $comclient =
new Commande($this->db);
2997 $comclient->fetch($comclientid);
3001 $this->lines = array();
3003 $num = count($comclient->lines);
3004 for ($i = 0; $i < $num; $i++) {
3005 $prod =
new Product($this->db);
3008 if ($prod->fetch($comclient->lines[$i]->fk_product) > 0) {
3009 $label = $prod->label;
3010 $ref = (string) $prod->ref;
3013 $sql =
"INSERT INTO ".$this->db->prefix().
"commande_fournisseurdet";
3014 $sql .=
" (fk_commande, label, description, fk_product, price, qty, tva_tx, localtax1_tx, localtax2_tx, remise_percent, subprice, remise, ref)";
3015 $sql .=
" VALUES (".((int) $idc).
", '".$this->db->escape($label).
"', '".$this->db->escape($comclient->lines[$i]->desc).
"'";
3016 $sql .=
",".((int) $comclient->lines[$i]->fk_product).
", ".
price2num($comclient->lines[$i]->price,
'MU');
3017 $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);
3018 $sql .=
", '".price2num($comclient->lines[$i]->subprice,
'MT').
"','0', '".$this->db->escape($ref).
"');";
3019 if ($this->db->query($sql)) {
3040 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur';
3041 $sql .=
" SET fk_statut = ".$status;
3042 $sql .=
" WHERE rowid = ".((int) $this->
id);
3044 dol_syslog(get_class($this).
"::setStatus", LOG_DEBUG);
3045 $resql = $this->db->query($sql);
3048 $triggerName = array();
3049 $triggerName[0] =
'DRAFT';
3050 $triggerName[1] =
'VALIDATED';
3051 $triggerName[2] =
'APPROVED';
3052 $triggerName[3] =
'ORDERED';
3053 $triggerName[4] =
'RECEIVED_PARTIALLY';
3054 $triggerName[5] =
'RECEIVED_COMPLETELY';
3055 $triggerName[6] =
'CANCELED';
3056 $triggerName[7] =
'CANCELED';
3057 $triggerName[9] =
'REFUSED';
3060 $result = $this->call_trigger(
"ORDER_SUPPLIER_STATUS_".$triggerName[$status], $user);
3067 $this->error = $this->db->lasterror();
3068 dol_syslog(get_class($this).
"::setStatus ".$this->error);
3073 $this->db->commit();
3076 $this->db->rollback();
3094 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
3095 return parent::setCategoriesCommon($categories, Categorie::TYPE_SUPPLIER_ORDER);
3121 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 =
'')
3123 global
$mysoc, $conf, $langs;
3126 $this->error =
'ErrorLineIDDoesNotMatchWithObjectID';
3130 dol_syslog(get_class($this).
"::updateline $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $type, $fk_unit");
3131 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
3135 if ($this->
status == self::STATUS_DRAFT) {
3140 if (empty($info_bits)) {
3143 if (empty($txtva)) {
3146 if (empty($txlocaltax1)) {
3149 if (empty($txlocaltax2)) {
3152 if (empty($remise_percent)) {
3153 $remise_percent = 0;
3156 $remise_percent = (float)
price2num($remise_percent);
3162 $pu_ht_devise =
price2num($pu_ht_devise);
3163 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
3166 $txlocaltax1 = (float)
price2num($txlocaltax1);
3167 $txlocaltax2 = (float)
price2num($txlocaltax2);
3173 if ($date_start && $date_end && $date_start > $date_end) {
3174 $langs->load(
"errors");
3175 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
3191 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
3192 $vat_src_code = $reg[1];
3193 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
3200 if ($tmpline->fetch($rowid) > 0) {
3202 if ($newqty != $qty) {
3204 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'warnings');
3209 $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);
3210 $total_ht = $tabprice[0];
3211 $total_tva = $tabprice[1];
3212 $total_ttc = $tabprice[2];
3213 $total_localtax1 = $tabprice[9];
3214 $total_localtax2 = $tabprice[10];
3215 $pu_ht = $tabprice[3];
3216 $pu_tva = $tabprice[4];
3217 $pu_ttc = $tabprice[5];
3220 $multicurrency_total_ht = $tabprice[16];
3221 $multicurrency_total_tva = $tabprice[17];
3222 $multicurrency_total_ttc = $tabprice[18];
3223 $pu_ht_devise = $tabprice[19];
3224 $multicurrency_pu_ttc = $tabprice[21];
3226 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
3227 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
3231 $this->line->fetch($rowid);
3233 $oldline = clone $this->line;
3234 $this->line->oldline = $oldline;
3236 $this->line->context = $this->context;
3238 $this->line->fk_commande = $this->id;
3240 $this->line->desc = $desc;
3243 $this->line->qty = $qty;
3244 $this->line->ref_supplier = $ref_supplier;
3246 $this->line->vat_src_code = $vat_src_code;
3247 $this->line->tva_tx = $txtva;
3248 $this->line->localtax1_tx = $txlocaltax1;
3249 $this->line->localtax2_tx = $txlocaltax2;
3250 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
3251 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
3252 $this->line->remise_percent = $remise_percent;
3253 $this->line->subprice = (float) $pu_ht;
3254 $this->line->subprice_ttc = (float) $pu_ttc;
3255 $this->line->info_bits = $info_bits;
3256 $this->line->total_ht = (float) $total_ht;
3257 $this->line->total_tva = (float) $total_tva;
3258 $this->line->total_localtax1 = (float) $total_localtax1;
3259 $this->line->total_localtax2 = (float) $total_localtax2;
3260 $this->line->total_ttc = (float) $total_ttc;
3261 $this->line->product_type = $type;
3262 $this->line->special_code = $oldline->special_code;
3263 $this->line->rang = $oldline->rang;
3264 $this->line->origin = $this->origin;
3265 $this->line->fk_unit = $fk_unit;
3267 $this->line->date_start = $date_start;
3268 $this->line->date_end = $date_end;
3271 $this->line->fk_multicurrency = $this->fk_multicurrency;
3272 $this->line->multicurrency_code = $this->multicurrency_code;
3273 $this->line->multicurrency_subprice = (float) $pu_ht_devise;
3274 $this->line->multicurrency_subprice_ttc = (float) $multicurrency_pu_ttc;
3275 $this->line->multicurrency_total_ht = (float) $multicurrency_total_ht;
3276 $this->line->multicurrency_total_tva = (float) $multicurrency_total_tva;
3277 $this->line->multicurrency_total_ttc = (float) $multicurrency_total_ttc;
3279 $this->line->subprice = (float) $pu_ht;
3280 $this->line->subprice_ttc = (float) $pu_ttc;
3281 $this->line->price = $this->line->subprice;
3283 $this->line->remise_percent = $remise_percent;
3285 if (is_array($array_options) && count($array_options) > 0) {
3287 foreach ($array_options as $key => $value) {
3288 $this->line->array_options[$key] = $array_options[$key];
3292 $result = $this->line->update($notrigger);
3298 $this->db->commit();
3301 $this->errors[] = $this->line->error;
3302 $this->errors = array_merge($this->errors, $this->line->errors);
3303 $this->error = $this->db->lasterror();
3304 $this->db->rollback();
3308 $this->error =
"Order status makes operation forbidden";
3309 dol_syslog(get_class($this).
"::updateline ".$this->error, LOG_ERR);
3324 global $user, $langs, $conf;
3326 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
3328 dol_syslog(get_class($this).
"::initAsSpecimen");
3335 $sql =
"SELECT rowid";
3336 $sql .=
" FROM ".$this->db->prefix().
"product";
3337 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
3338 $sql .= $this->db->order(
"rowid",
"ASC");
3339 $sql .= $this->db->plimit(1);
3340 $resql = $this->db->query($sql);
3341 if ($resql && $this->db->num_rows($resql)) {
3342 $obj = $this->db->fetch_object($resql);
3343 $prodid = $obj->rowid;
3348 $this->
ref =
'SPECIMEN';
3349 $this->specimen = 1;
3352 $this->date_commande = $now;
3353 $this->date_lim_reglement = $this->
date + 3600 * 24 * 30;
3354 $this->cond_reglement_code =
'RECEP';
3355 $this->mode_reglement_code =
'CHQ';
3357 $this->note_public =
'This is a comment (public)';
3358 $this->note_private =
'This is a comment (private)';
3360 $this->multicurrency_tx = 1;
3361 $this->multicurrency_code = $conf->currency;
3369 while ($xnbp < $nbp) {
3371 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
3373 $line->subprice = 100;
3374 $line->tva_tx = 19.6;
3375 $line->localtax1_tx = 0;
3376 $line->localtax2_tx = 0;
3378 $line->total_ht = 50;
3379 $line->total_ttc = 59.8;
3380 $line->total_tva = 9.8;
3381 $line->remise_percent = 50;
3383 $line->total_ht = 100;
3384 $line->total_ttc = 119.6;
3385 $line->total_tva = 19.6;
3386 $line->remise_percent = 00;
3388 $line->fk_product = $prodid;
3390 $this->lines[$xnbp] = $line;
3392 $this->total_ht += $line->total_ht;
3393 $this->total_tva += $line->total_tva;
3394 $this->total_ttc += $line->total_ttc;
3410 $sql =
'SELECT c.rowid, date_creation as datec, tms as datem, date_valid as date_validation, date_approve as datea, date_approve2 as datea2,';
3411 $sql .=
' fk_user_author, fk_user_modif, fk_user_valid, fk_user_approve, fk_user_approve2';
3412 $sql .=
' FROM '.$this->db->prefix().
'commande_fournisseur as c';
3413 $sql .=
' WHERE c.rowid = '.((int) $id);
3415 $result = $this->db->query($sql);
3417 if ($this->db->num_rows($result)) {
3418 $obj = $this->db->fetch_object($result);
3420 $this->
id = $obj->rowid;
3422 $this->user_creation_id = $obj->fk_user_author;
3423 $this->user_validation_id = $obj->fk_user_valid;
3424 $this->user_modification_id = $obj->fk_user_modif;
3425 $this->user_approve_id = $obj->fk_user_approve;
3426 $this->user_approve_id2 = $obj->fk_user_approve2;
3428 $this->date_creation = $this->db->jdate($obj->datec);
3429 $this->date_modification = $this->db->jdate($obj->datem);
3430 $this->date_approve = $this->db->jdate($obj->datea);
3431 $this->date_approve2 = $this->db->jdate($obj->datea2);
3432 $this->date_validation = $this->db->jdate($obj->date_validation);
3434 $this->db->free($result);
3447 global $conf, $user;
3449 $this->nb = array();
3452 $sql =
"SELECT count(co.rowid) as nb";
3453 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as co";
3454 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe as s ON co.fk_soc = s.rowid";
3455 if (empty($user->socid) && !$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3456 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
3457 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
3460 $sql .=
" ".$clause.
" co.entity IN (".
getEntity(
'supplier_order').
")";
3462 $resql = $this->db->query($sql);
3464 while ($obj = $this->db->fetch_object($resql)) {
3465 $this->nb[
"supplier_orders"] = $obj->nb;
3467 $this->db->free($resql);
3471 $this->error = $this->db->error();
3487 global $conf, $langs;
3489 $sql =
"SELECT c.rowid, c.date_creation as datec, c.date_commande, c.fk_statut, c.date_livraison as delivery_date, c.total_ht";
3490 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as c";
3491 if (empty($user->socid) && !$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3492 $sql .=
" JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
3494 $sql .=
" WHERE c.entity = ".$conf->entity;
3495 if ($mode ===
'awaiting') {
3496 $sql .=
" AND c.fk_statut IN (".self::STATUS_ORDERSENT.
", ".self::STATUS_RECEIVED_PARTIALLY.
")";
3498 $sql .=
" AND c.fk_statut IN (".self::STATUS_VALIDATED.
", ".self::STATUS_ACCEPTED.
")";
3501 $sql .=
" AND c.fk_soc = ".((int) $user->socid);
3504 $resql = $this->db->query($sql);
3509 $response->warning_delay = $conf->commande->fournisseur->warning_delay / 60 / 60 / 24;
3510 $response->label = $langs->trans(
"SuppliersOrdersToProcess");
3511 $response->labelShort = $langs->trans(
"Opened");
3512 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=1,2&mainmenu=commercial&leftmenu=orders_suppliers';
3513 $response->url_late = DOL_URL_ROOT.
'/fourn/commande/list.php?mainmenu=commercial&leftmenu=orders_suppliers&search_option=late';
3516 if ($mode ===
'awaiting') {
3517 $response->label = $langs->trans(
"SuppliersOrdersAwaitingReception");
3518 $response->labelShort = $langs->trans(
"AwaitingReception");
3519 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=3,4&mainmenu=commercial&leftmenu=orders_suppliers';
3520 $response->url_late = DOL_URL_ROOT.
'/fourn/commande/list.php?mainmenu=commercial&leftmenu=orders_suppliers&search_option=recv_late';
3523 while ($obj = $this->db->fetch_object($resql)) {
3524 $commandestatic->delivery_date = $this->db->jdate($obj->delivery_date);
3525 $commandestatic->date_commande = $this->db->jdate($obj->date_commande);
3526 $commandestatic->statut = $obj->fk_statut;
3527 $commandestatic->status = $obj->fk_statut;
3529 $response->nbtodo++;
3530 $response->total += $obj->total_ht;
3532 if ($commandestatic->hasDelay()) {
3533 $response->nbtodolate++;
3539 $this->error = $this->db->error();
3554 if ($this->methode_commande_id > 0) {
3555 $sql =
"SELECT rowid, code, libelle as label";
3556 $sql .=
" FROM ".$this->db->prefix().
'c_input_method';
3557 $sql .=
" WHERE active=1 AND rowid = ".((int) $this->methode_commande_id);
3559 $resql = $this->db->query($sql);
3561 if ($this->db->num_rows($resql)) {
3562 $obj = $this->db->fetch_object($resql);
3564 $string = $langs->trans($obj->code);
3565 if ($string == $obj->code) {
3566 $string = $obj->label !=
'-' ? $obj->label :
'';
3589 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3596 if (!empty($this->model_pdf)) {
3597 $modele = $this->model_pdf;
3603 if (empty($modele)) {
3606 $langs->load(
"suppliers");
3607 $outputlangs->load(
"products");
3609 $modelpath =
"core/modules/supplier_order/doc/";
3610 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3623 if (empty($this->lines)) {
3630 foreach ($this->lines as $line) {
3631 if ($line->fk_product > 0) {
3633 $idp = $tmpproductfourn->find_min_price_product_fournisseur($line->fk_product, $line->qty, $this->thirdparty->id);
3636 if ($tmpproductfourn->delivery_time_days > $nb) {
3637 $nb = $tmpproductfourn->delivery_time_days;
3646 return $nb.
' '.$langs->trans(
'days');
3659 return $user->hasRight(
"fournisseur",
"commande");
3674 'commande_fournisseur'
3691 'commande_fournisseurdet'
3708 if ($this->
status == self::STATUS_ORDERSENT || $this->
status == self::STATUS_RECEIVED_PARTIALLY) {
3710 if (!empty($this->delivery_date)) {
3711 $date_to_test = $this->delivery_date;
3712 return $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay);
3720 $date_to_test = $this->date_commande;
3722 return ($this->
status > 0 && $this->
status < 5) && $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay);
3735 global $conf, $langs;
3737 $langs->load(
'orders');
3741 if ($this->
status == self::STATUS_ORDERSENT || $this->
status == self::STATUS_RECEIVED_PARTIALLY) {
3742 if (!empty($this->delivery_date)) {
3743 $text = $langs->trans(
"DeliveryDate").
' '.
dol_print_date($this->delivery_date,
'day');
3745 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3748 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3751 $text .=
' '.($conf->commande->fournisseur->warning_delay > 0 ?
'+' :
'-').
' '.round(abs($conf->commande->fournisseur->warning_delay) / 3600 / 24, 1).
' '.$langs->trans(
"days").
' < '.$langs->trans(
"Today");
3769 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
3771 $qtydelivered = array();
3772 $qtywished = array();
3776 $filter = array(
't.fk_element' => $this->
id);
3778 $filter[
't.status'] = 1;
3781 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
3783 $this->error = $supplierorderdispatch->error;
3784 $this->errors = $supplierorderdispatch->errors;
3787 if (is_array($supplierorderdispatch->lines) && count($supplierorderdispatch->lines) > 0) {
3788 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
3792 foreach ($supplierorderdispatch->lines as $line) {
3793 if (array_key_exists($line->fk_product, $qtydelivered)) {
3794 $qtydelivered[$line->fk_product] += $line->qty;
3796 $qtydelivered[$line->fk_product] = $line->qty;
3799 foreach ($this->lines as $line) {
3801 if (empty($line->fk_product)) {
3808 if (array_key_exists($line->fk_product, $qtywished)) {
3809 $qtywished[$line->fk_product] += $line->qty;
3811 $qtywished[$line->fk_product] = $line->qty;
3816 $diff_array = array_diff_assoc($qtydelivered, $qtywished);
3817 $keysinwishednotindelivered = array_diff(array_keys($qtywished), array_keys($qtydelivered));
3818 $keysindeliverednotinwished = array_diff(array_keys($qtydelivered), array_keys($qtywished));
3826 if (count($diff_array) == 0 && count($keysinwishednotindelivered) == 0 && count($keysindeliverednotinwished) == 0) {
3827 if ($closeopenorder) {
3829 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3837 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3848 if (count($diff_array) > 0) {
3852 foreach ($diff_array as $key => $value) {
3854 if ($qtydelivered[$key] >= $qtywished[$key]) {
3861 if ($close == count($diff_array)) {
3863 if ($closeopenorder) {
3864 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3871 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3879 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3887 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3909 $this->receptions = array();
3911 dol_syslog(get_class($this).
"::loadReceptions", LOG_DEBUG);
3913 $sql =
'SELECT cd.rowid, cd.fk_product,';
3914 $sql .=
' sum(cfd.qty) as qty';
3915 $sql .=
' FROM '.$this->db->prefix().
'receptiondet_batch as cfd,';
3916 if ($filtre_statut >= 0) {
3917 $sql .=
' '.$this->db->prefix().
'reception as e,';
3919 $sql .=
' '.$this->db->prefix().
'commande_fournisseurdet as cd';
3921 if ($filtre_statut >= 0) {
3922 $sql .=
' cfd.fk_reception = e.rowid AND';
3924 $sql .=
' cfd.fk_elementdet = cd.rowid';
3925 $sql .=
' AND cd.fk_commande ='.((int) $this->
id);
3926 if (isset($this->fk_product) && !empty($this->fk_product) > 0) {
3927 $sql .=
' AND cd.fk_product = '.((int) $this->fk_product);
3929 if ($filtre_statut >= 0) {
3930 $sql .=
' AND e.fk_statut >= '.((int) $filtre_statut);
3932 $sql .=
' GROUP BY cd.rowid, cd.fk_product';
3934 $resql = $this->db->query($sql);
3936 $num = $this->db->num_rows($resql);
3939 $obj = $this->db->fetch_object($resql);
3940 empty($this->receptions[$obj->rowid]) ? $this->receptions[$obj->rowid] = $obj->qty : $this->receptions[$obj->rowid] += $obj->qty;
3943 $this->db->free($resql);
3947 $this->error = $this->db->lasterror();
3963 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3965 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3966 $return .=
'<div class="info-box info-box-sm">';
3967 $return .=
'<span class="info-box-icon bg-infobox-action">';
3969 $return .=
'</span>';
3970 $return .=
'<div class="info-box-content">';
3971 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
3972 if ($selected >= 0) {
3973 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3975 if (!empty($arraydata[
'thirdparty'])) {
3976 $return .=
'<br><span class="info-box-label">'.$arraydata[
'thirdparty'].
'</span>';
3978 if (!empty($this->
date)) {
3979 $return .=
'<br><span class="info-box-label">'.dol_print_date($this->
date,
'day').
'</span>';
3981 if (!empty($this->total_ht)) {
3982 $return .=
' <span class="info-box-label amount" title="'.dol_escape_htmltag($langs->trans(
"AmountHT")).
'">'.
price($this->total_ht);
3983 $return .=
' '.$langs->trans(
"HT");
3984 $return .=
'</span>';
3986 if (method_exists($this,
'getLibStatut')) {
3987 $return .=
'<br><span class="info-box-status">'.$this->getLibStatut(3).
'</span>';
3989 if (property_exists($this,
'billed')) {
3990 $return .=
' <span class="opacitymedium">'.$langs->trans(
"Billed").
': </span><span class="info-box-label">'.
yn($this->billed).
'</span>';
3992 $return .=
'</div>';
3993 $return .=
'</div>';
3994 $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.
addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0.0, $txlocaltax2=0.0, $fk_product=0, $fk_prod_fourn_price=0, $ref_supplier='', $remise_percent=0.0, $price_base_type='HT', $pu_ttc=0.0, $type=0, $info_bits=0, $notrigger=0, $date_start=null, $date_end=null, $array_options=[], $fk_unit=null, $pu_ht_devise=0, $origin='', $origin_id=0, $rang=-1, $special_code=0)
Add order line.
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.
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.
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)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
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.
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...
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $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.
if(getDolGlobalString( 'TAKEPOS_SHOW_CUSTOMER')) print $langs trans('Date')." left 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 PaymentTypeShortLIQ right SELECT p pos_change as p datep as date