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 <= ".((float) $objp->qty);
728 $sqlsearchpackage .=
" AND (packaging IS NULL OR packaging = 0 OR packaging <= ".((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,
1714 $line->array_options,
1716 (
float) $line->multicurrency_subprice,
1717 (string) $line->origin,
1718 (
int) $line->origin_id,
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) ? $this->total_tva :
"null").
",";
1846 $sql .=
" localtax1=".(isset($this->total_localtax1) ? $this->total_localtax1 :
"null").
",";
1847 $sql .=
" localtax2=".(isset($this->total_localtax2) ? $this->total_localtax2 :
"null").
",";
1848 $sql .=
" total_ht=".(isset($this->total_ht) ? $this->total_ht :
"null").
",";
1849 $sql .=
" total_ttc=".(isset($this->total_ttc) ? $this->total_ttc :
"null").
",";
1850 $sql .=
" fk_statut=".(isset($this->
status) ? $this->
status :
"null").
",";
1851 $sql .=
" fk_user_author=".(isset($this->user_author_id) ? $this->user_author_id :
"null").
",";
1852 $sql .=
" fk_user_valid=".(isset($this->user_validation_id) && $this->user_validation_id > 0 ? $this->user_validation_id :
"null").
",";
1853 $sql .=
" fk_projet=".((!empty($this->fk_project) && $this->fk_project > 0) ? $this->fk_project :
"null").
",";
1854 $sql .=
" fk_cond_reglement=".(isset($this->cond_reglement_id) ? $this->cond_reglement_id :
"null").
",";
1855 $sql .=
" deposit_percent=".(!empty($this->deposit_percent) ? strval($this->deposit_percent) :
"null").
",";
1856 $sql .=
" fk_mode_reglement=".(isset($this->mode_reglement_id) ? $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 = 0;
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($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));
2155 if (abs((
float) $qty) < $prod->packaging) {
2156 $qty = (float) $prod->packaging;
2157 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'warnings');
2159 if (!empty($prod->packaging) && (
float)
price2num(fmod((
float) $qty, (
float) $prod->packaging),
'MS')) {
2160 $coeff = intval(abs((
float) $qty) / $prod->packaging) + 1;
2161 $qty =
price2num((
float) $prod->packaging * $coeff,
'MS');
2162 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'warnings');
2171 if (!empty($prod->fourn_qty) && abs((
float) $qty) < (
float) $prod->fourn_qty) {
2172 if (!empty($prod->packaging) && (
float)
price2num(fmod((
float) $prod->fourn_qty, (
float) $prod->packaging),
'MS')) {
2173 $coeff = intval((
float) $prod->fourn_qty / (
float) $prod->packaging) + 1;
2174 $qty = (float)
price2num((
float) $prod->packaging * $coeff,
'MS');
2176 $qty = (float) $prod->fourn_qty;
2178 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'mesgs');
2183 if (
isModEnabled(
"multicurrency") && $pu_ht_devise > 0) {
2192 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
2193 $vat_src_code = $reg[1];
2194 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
2202 $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);
2204 $total_ht = $tabprice[0];
2205 $total_tva = $tabprice[1];
2206 $total_ttc = $tabprice[2];
2207 $total_localtax1 = $tabprice[9];
2208 $total_localtax2 = $tabprice[10];
2209 $pu = $pu_ht = $tabprice[3];
2210 $pu_tva = $tabprice[4];
2211 $pu_ttc = $tabprice[5];
2214 $multicurrency_total_ht = $tabprice[16];
2215 $multicurrency_total_tva = $tabprice[17];
2216 $multicurrency_total_ttc = $tabprice[18];
2217 $pu_ht_devise = $tabprice[19];
2218 $multicurrency_pu_ttc = $tabprice[21];
2220 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2221 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2225 $rang = $rangmax + 1;
2231 $this->line->context = $this->context;
2233 $this->line->fk_commande = $this->id;
2234 $this->line->label = $label;
2235 $this->line->ref_fourn = $ref_supplier;
2236 $this->line->ref_supplier = $ref_supplier;
2237 $this->line->desc = $desc;
2238 $this->line->qty = $qty;
2239 $this->line->tva_tx = $txtva;
2240 $this->line->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0);
2241 $this->line->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0);
2242 $this->line->localtax1_type = $localtax1_type;
2243 $this->line->localtax2_type = $localtax2_type;
2244 $this->line->fk_product = $fk_product;
2245 $this->line->product_type = $product_type;
2246 $this->line->remise_percent = $remise_percent;
2247 $this->line->subprice = (float) $pu_ht;
2248 $this->line->subprice_ttc = (float) $pu_ttc;
2250 $this->line->rang = $rang;
2251 $this->line->info_bits = $info_bits;
2253 $this->line->vat_src_code = $vat_src_code;
2254 $this->line->total_ht = (float) $total_ht;
2255 $this->line->total_tva = (float) $total_tva;
2256 $this->line->total_localtax1 = (float) $total_localtax1;
2257 $this->line->total_localtax2 = (float) $total_localtax2;
2258 $this->line->total_ttc = (float) $total_ttc;
2259 $this->line->product_type = $type;
2260 $this->line->special_code = (!empty($special_code) ? $special_code : 0);
2261 $this->line->origin = $origin;
2262 $this->line->origin_type = $origin;
2263 $this->line->origin_id = $origin_id;
2264 $this->line->fk_unit = $fk_unit;
2266 $this->line->date_start = $date_start;
2267 $this->line->date_end = $date_end;
2270 $this->line->fk_multicurrency = $this->fk_multicurrency;
2271 $this->line->multicurrency_code = $this->multicurrency_code;
2272 $this->line->multicurrency_subprice = (float) $pu_ht_devise;
2273 $this->line->multicurrency_subprice_ttc = (float) $multicurrency_pu_ttc;
2274 $this->line->multicurrency_total_ht = (float) $multicurrency_total_ht;
2275 $this->line->multicurrency_total_tva = (float) $multicurrency_total_tva;
2276 $this->line->multicurrency_total_ttc = (float) $multicurrency_total_ttc;
2278 $this->line->subprice = (float) $pu_ht;
2279 $this->line->price = $this->line->subprice;
2281 $this->line->remise_percent = $remise_percent;
2283 if (is_array($array_options) && count($array_options) > 0) {
2284 $this->line->array_options = $array_options;
2287 $result = $this->line->insert($notrigger);
2290 $result = $this->
update_price(1,
'auto', 0, $this->thirdparty);
2293 if (!isset($this->context[
'createfromclone'])) {
2294 if (!empty($this->line->fk_parent_line)) {
2297 } elseif ($rang > 0 && $rang <= count($this->lines)) {
2299 $linecount = count($this->lines);
2300 for ($ii = $rang; $ii <= $linecount; $ii++) {
2305 $this->lines[] = $this->line;
2308 $this->db->commit();
2309 return $this->line->id;
2311 $this->db->rollback();
2316 dol_syslog(get_class($this).
"::addline error=".$this->error, LOG_ERR);
2317 $this->db->rollback();
2342 public function dispatchProduct($user, $product, $qty, $entrepot, $price = 0, $comment =
'', $eatby =
'', $sellby =
'', $batch =
'', $fk_commandefourndet = 0, $notrigger = 0, $fk_reception = 0)
2344 global $conf, $langs;
2347 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2350 if ($entrepot <= 0) {
2351 $this->error =
'ErrorBadValueForParameterWarehouse';
2355 $this->error =
'ErrorBadValueForParameterQty';
2359 $dispatchstatus = 1;
2361 $dispatchstatus = 0;
2368 if (($this->
status == self::STATUS_ORDERSENT || $this->
status == self::STATUS_RECEIVED_PARTIALLY || $this->
status == self::STATUS_RECEIVED_COMPLETELY)) {
2371 $sql =
"INSERT INTO ".$this->db->prefix().
"receptiondet_batch";
2372 $sql .=
" (fk_element, fk_product, qty, fk_entrepot, fk_user, datec, fk_elementdet, status, comment, eatby, sellby, batch, fk_reception) VALUES";
2373 $sql .=
" ('".$this->id.
"','".$product.
"','".$qty.
"',".($entrepot > 0 ?
"'".$entrepot.
"'" :
"null").
",'".$user->id.
"','".$this->db->idate($now).
"','".$fk_commandefourndet.
"', ".$dispatchstatus.
", '".$this->db->escape($comment).
"', ";
2374 $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");
2377 dol_syslog(get_class($this).
"::dispatchProduct", LOG_DEBUG);
2378 $resql = $this->db->query($sql);
2381 global $conf, $langs, $user;
2383 $result = $this->call_trigger(
'LINEORDER_SUPPLIER_DISPATCH', $user);
2390 $this->error = $this->db->lasterror();
2399 $mouv->origin = &$this;
2400 $mouv->setOrigin($this->element, $this->
id);
2403 if (
getDolGlobalString(
'SUPPLIER_ORDER_ALLOW_NEGATIVE_QTY_FOR_SUPPLIER_ORDER_RETURN') && $qty < 0) {
2404 $result = $mouv->livraison($user, $product, $entrepot, $qty * (-1), $price, $comment, $now, $eatby, $sellby, $batch, 0, $inventorycode);
2406 $result = $mouv->reception($user, $product, $entrepot, $qty, $price, $comment, $eatby, $sellby, $batch,
'', 0, $inventorycode);
2410 $this->error = $mouv->error;
2411 $this->errors = $mouv->errors;
2412 dol_syslog(get_class($this).
"::dispatchProduct ".$this->error.
" ".implode(
',', $this->errors), LOG_ERR);
2419 $this->db->commit();
2422 $this->db->rollback();
2426 $this->error =
'BadStatusForObject';
2442 if ($this->
status == 0) {
2445 if ($line->fetch($idline) <= 0) {
2451 foreach ($dispatchedLines as $dispatchLine) {
2452 if ($dispatchLine[
'orderlineid'] == $idline) {
2453 $this->error =
"LineAlreadyDispatched";
2454 $this->errors[] = $this->error;
2459 if ($line->delete($user, $notrigger) > 0) {
2478 public function delete(
User $user, $notrigger = 0)
2480 global $langs, $conf;
2481 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2487 if (empty($notrigger)) {
2489 $result = $this->call_trigger(
'ORDER_SUPPLIER_DELETE', $user);
2491 $this->errors[] =
'ErrorWhenRunningTrigger';
2492 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2493 $this->db->rollback();
2501 if (!empty($this->linkedObjects) && array_key_exists(
'reception', $this->linkedObjects)) {
2502 foreach ($this->linkedObjects[
'reception'] as $element) {
2503 if ($element->statut >= 0) {
2504 $this->errors[] = $langs->trans(
'ReceptionExist');
2513 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_supplier_order";
2514 $sql .=
" WHERE fk_supplier_order = ".((int) $this->
id);
2516 $result = $this->db->query($sql);
2519 $this->errors[] = $this->db->lasterror();
2523 $main = $this->db->prefix().
'commande_fournisseurdet';
2526 $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).
")";
2527 dol_syslog(__METHOD__.
" linked order lines", LOG_DEBUG);
2528 if (!$this->db->query($sql1)) {
2530 $this->error = $this->db->lasterror();
2531 $this->errors[] = $this->db->lasterror();
2536 $ef = $main.
"_extrafields";
2537 $sql =
"DELETE FROM ".$this->db->sanitize($ef).
" WHERE fk_object IN (SELECT rowid FROM ".$this->db->sanitize($main).
" WHERE fk_commande = ".((int) $this->
id).
")";
2538 dol_syslog(get_class($this).
"::delete extrafields lines", LOG_DEBUG);
2539 if (!$this->db->query($sql)) {
2540 $this->error = $this->db->lasterror();
2541 $this->errors[] = $this->db->lasterror();
2547 $sql =
"DELETE FROM ".$this->db->prefix().
"commande_fournisseurdet WHERE fk_commande = ".((int) $this->
id);
2548 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2549 if (!$this->db->query($sql)) {
2550 $this->error = $this->db->lasterror();
2551 $this->errors[] = $this->db->lasterror();
2557 $sql =
"DELETE FROM ".$this->db->prefix().
"commande_fournisseur WHERE rowid = ".((int) $this->
id);
2558 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2559 if ($resql = $this->db->query($sql)) {
2560 if ($this->db->affected_rows($resql) < 1) {
2561 $this->error = $this->db->lasterror();
2562 $this->errors[] = $this->db->lasterror();
2566 $this->error = $this->db->lasterror();
2567 $this->errors[] = $this->db->lasterror();
2576 $this->error =
'FailToDeleteExtraFields';
2577 $this->errors[] =
'FailToDeleteExtraFields';
2579 dol_syslog(get_class($this).
"::delete error -4 ".$this->error, LOG_ERR);
2586 $this->error =
'FailToDeleteObjectLinked';
2587 $this->errors[] =
'FailToDeleteObjectLinked';
2598 if ($conf->fournisseur->commande->dir_output) {
2599 $dir = $conf->fournisseur->commande->dir_output.
"/".$ref;
2600 $file = $dir.
"/".$ref.
".pdf";
2601 if (file_exists($file)) {
2603 $this->error =
'ErrorFailToDeleteFile';
2604 $this->errors[] =
'ErrorFailToDeleteFile';
2608 if (file_exists($dir)) {
2611 $this->error =
'ErrorFailToDeleteDir';
2612 $this->errors[] =
'ErrorFailToDeleteDir';
2620 dol_syslog(get_class($this).
"::delete $this->id by $user->id", LOG_DEBUG);
2621 $this->db->commit();
2624 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2625 $this->db->rollback();
2644 $sql =
"SELECT p.ref, p.label,";
2645 $sql .=
" e.rowid as warehouse_id, e.ref as entrepot,";
2646 $sql .=
" cfd.rowid as dispatchedlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status, cfd.fk_elementdet";
2647 $sql .=
" FROM ".$this->db->prefix().
"product as p,";
2648 $sql .=
" ".$this->db->prefix().
"receptiondet_batch as cfd";
2649 $sql .=
" LEFT JOIN ".$this->db->prefix().
"entrepot as e ON cfd.fk_entrepot = e.rowid";
2650 $sql .=
" WHERE cfd.fk_element = ".((int) $this->
id);
2651 $sql .=
" AND cfd.fk_product = p.rowid";
2653 $sql .=
" AND cfd.status = ".((int) $status);
2655 $sql .=
" ORDER BY cfd.rowid ASC";
2657 $resql = $this->db->query($sql);
2659 $num = $this->db->num_rows($resql);
2663 $objp = $this->db->fetch_object($resql);
2666 'id' => $objp->dispatchedlineid,
2667 'productid' => $objp->fk_product,
2668 'warehouseid' => $objp->warehouse_id,
2669 'qty' => $objp->qty,
2670 'orderlineid' => $objp->fk_elementdet
2677 dol_print_error($this->db,
'Failed to execute request to get dispatched lines');
2696 global $conf, $langs;
2700 $dispatchedlinearray = array();
2704 $usercanreceive = 0;
2706 $usercanreceive = $user->hasRight(
"fournisseur",
"commande",
"receptionner");
2708 $usercanreceive = $user->hasRight(
"reception",
"creer");
2711 if ($usercanreceive) {
2713 if ($type ==
'par') {
2715 } elseif ($type ==
'tot') {
2717 } elseif ($type ==
'nev') {
2719 } elseif ($type ==
'can') {
2723 dol_syslog(get_class($this).
"::Livraison Error -2", LOG_ERR);
2730 if ($type ==
'tot') {
2732 if (count($dispatchedlinearray) > 0) {
2735 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove';
2736 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove', LOG_DEBUG);
2739 if (!$error &&
getDolGlobalString(
'SUPPLIER_ORDER_USE_DISPATCH_STATUS_NEED_APPROVE') && ($type ==
'tot')) {
2741 if (count($dispatchedlinearray) > 0) {
2744 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied';
2745 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied', LOG_DEBUG);
2752 if (empty($error)) {
2755 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2756 $sql .=
" SET fk_statut = ".((int) $statut);
2757 $sql .=
" WHERE rowid = ".((int) $this->
id);
2758 $sql .=
" AND fk_statut IN (".self::STATUS_ORDERSENT.
",".self::STATUS_RECEIVED_PARTIALLY.
")";
2760 dol_syslog(get_class($this).
"::Livraison", LOG_DEBUG);
2761 $resql = $this->db->query($sql);
2764 $old_statut = $this->status;
2766 $this->context[
'actionmsg2'] = $comment;
2769 $result_trigger = $this->call_trigger(
'ORDER_SUPPLIER_RECEIVE', $user);
2770 if ($result_trigger < 0) {
2775 if (empty($error)) {
2776 $this->db->commit();
2778 $this->
status = $old_statut;
2779 $this->db->rollback();
2780 $this->error = $this->db->lasterror();
2784 $this->db->rollback();
2785 $this->error = $this->db->lasterror();
2790 $this->error = $langs->trans(
'NotAuthorized');
2791 $this->errors[] = $langs->trans(
'NotAuthorized');
2792 dol_syslog(get_class($this).
"::Livraison Not Authorized");
2824 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
2829 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2830 $sql .=
" SET date_livraison = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2831 $sql .=
" WHERE rowid = ".((int) $this->
id);
2834 $resql = $this->db->query($sql);
2836 $this->errors[] = $this->db->error();
2841 $this->oldcopy = clone $this;
2842 $this->delivery_date = $delivery_date;
2845 if (!$notrigger && empty($error)) {
2847 $result = $this->call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2855 $this->db->commit();
2858 foreach ($this->errors as $errmsg) {
2859 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2860 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2862 $this->db->rollback();
2878 if (in_array($this->
status, [1, 2, 3, 4, 5, 6, 7, 9])) {
2879 if ($this->
status == 1) {
2881 } elseif ($this->
status == 2) {
2883 } elseif ($this->
status == 3) {
2885 } elseif ($this->
status == 4) {
2887 } elseif ($this->
status == 5) {
2893 } elseif ($this->
status == 6) {
2895 } elseif ($this->
status == 7) {
2897 } elseif ($this->
status == 9) {
2905 $result = $this->
setStatus($user, $newStatus);
2907 if ($newStatus == 0) {
2908 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur';
2909 $sql .=
' SET fk_user_approve = null, fk_user_approve2 = null, date_approve = null, date_approve2 = null';
2910 $sql .=
' WHERE rowid = '.((int) $this->
id);
2912 $this->db->query($sql);
2915 $this->db->commit();
2919 $this->db->rollback();
2940 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
2945 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2946 $sql .=
" SET fk_projet = ".($id_projet > 0 ? (int) $id_projet :
'null');
2947 $sql .=
" WHERE rowid = ".((int) $this->
id);
2950 $resql = $this->db->query($sql);
2952 $this->errors[] = $this->db->error();
2957 $this->oldcopy = clone $this;
2958 $this->fk_projet = $id_projet;
2959 $this->fk_project = $id_projet;
2962 if (!$notrigger && empty($error)) {
2964 $result = $this->call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2972 $this->db->commit();
2975 foreach ($this->errors as $errmsg) {
2976 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2977 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2979 $this->db->rollback();
2997 $comclient =
new Commande($this->db);
2998 $comclient->fetch($comclientid);
3002 $this->lines = array();
3004 $num = count($comclient->lines);
3005 for ($i = 0; $i < $num; $i++) {
3006 $prod =
new Product($this->db);
3009 if ($prod->fetch($comclient->lines[$i]->fk_product) > 0) {
3010 $label = $prod->label;
3011 $ref = (string) $prod->ref;
3014 $sql =
"INSERT INTO ".$this->db->prefix().
"commande_fournisseurdet";
3015 $sql .=
" (fk_commande, label, description, fk_product, price, qty, tva_tx, localtax1_tx, localtax2_tx, remise_percent, subprice, remise, ref)";
3016 $sql .=
" VALUES (".((int) $idc).
", '".$this->db->escape($label).
"', '".$this->db->escape($comclient->lines[$i]->desc).
"'";
3017 $sql .=
",".((int) $comclient->lines[$i]->fk_product).
", ".
price2num($comclient->lines[$i]->price,
'MU');
3018 $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);
3019 $sql .=
", '".price2num($comclient->lines[$i]->subprice,
'MT').
"','0', '".$this->db->escape($ref).
"');";
3020 if ($this->db->query($sql)) {
3041 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur';
3042 $sql .=
" SET fk_statut = ".$status;
3043 $sql .=
" WHERE rowid = ".((int) $this->
id);
3045 dol_syslog(get_class($this).
"::setStatus", LOG_DEBUG);
3046 $resql = $this->db->query($sql);
3049 $triggerName = array();
3050 $triggerName[0] =
'DRAFT';
3051 $triggerName[1] =
'VALIDATED';
3052 $triggerName[2] =
'APPROVED';
3053 $triggerName[3] =
'ORDERED';
3054 $triggerName[4] =
'RECEIVED_PARTIALLY';
3055 $triggerName[5] =
'RECEIVED_COMPLETELY';
3056 $triggerName[6] =
'CANCELED';
3057 $triggerName[7] =
'CANCELED';
3058 $triggerName[9] =
'REFUSED';
3061 $result = $this->call_trigger(
"ORDER_SUPPLIER_STATUS_".$triggerName[$status], $user);
3068 $this->error = $this->db->lasterror();
3069 dol_syslog(get_class($this).
"::setStatus ".$this->error);
3074 $this->db->commit();
3077 $this->db->rollback();
3095 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
3096 return parent::setCategoriesCommon($categories, Categorie::TYPE_SUPPLIER_ORDER);
3122 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 =
'')
3124 global
$mysoc, $conf, $langs;
3125 dol_syslog(get_class($this).
"::updateline $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $type, $fk_unit");
3126 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
3130 if ($this->
status == self::STATUS_DRAFT) {
3135 if (empty($info_bits)) {
3138 if (empty($txtva)) {
3141 if (empty($txlocaltax1)) {
3144 if (empty($txlocaltax2)) {
3147 if (empty($remise_percent)) {
3148 $remise_percent = 0;
3151 $remise_percent = (float)
price2num($remise_percent);
3157 $pu_ht_devise =
price2num($pu_ht_devise);
3158 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
3161 $txlocaltax1 = (float)
price2num($txlocaltax1);
3162 $txlocaltax2 = (float)
price2num($txlocaltax2);
3168 if ($date_start && $date_end && $date_start > $date_end) {
3169 $langs->load(
"errors");
3170 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
3186 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
3187 $vat_src_code = $reg[1];
3188 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
3191 $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);
3192 $total_ht = $tabprice[0];
3193 $total_tva = $tabprice[1];
3194 $total_ttc = $tabprice[2];
3195 $total_localtax1 = $tabprice[9];
3196 $total_localtax2 = $tabprice[10];
3197 $pu_ht = $tabprice[3];
3198 $pu_tva = $tabprice[4];
3199 $pu_ttc = $tabprice[5];
3202 $multicurrency_total_ht = $tabprice[16];
3203 $multicurrency_total_tva = $tabprice[17];
3204 $multicurrency_total_ttc = $tabprice[18];
3205 $pu_ht_devise = $tabprice[19];
3206 $multicurrency_pu_ttc = $tabprice[21];
3208 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
3209 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
3213 $this->line->fetch($rowid);
3215 $oldline = clone $this->line;
3216 $this->line->oldline = $oldline;
3218 $this->line->context = $this->context;
3220 $this->line->fk_commande = $this->id;
3222 $this->line->desc = $desc;
3229 if (abs((
float) $qty) < $this->line->packaging) {
3230 $qty = $this->line->packaging;
3231 setEventMessage($langs->trans(
'QtyRecalculatedWithPackaging'),
'warnings');
3233 if (!empty($this->line->packaging) && is_numeric($this->line->packaging) && (
float) $this->line->packaging > 0
3234 && (
float)
price2num(fmod((
float) $qty, (
float) $this->line->packaging),
'MS')) {
3235 $coeff = intval(abs((
float) $qty) / $this->line->packaging) + 1;
3236 $qty =
price2num((
float) $this->line->packaging * $coeff,
'MS');
3237 setEventMessage($langs->trans(
'QtyRecalculatedWithPackaging'),
'warnings');
3242 $this->line->qty = $qty;
3243 $this->line->ref_supplier = $ref_supplier;
3245 $this->line->vat_src_code = $vat_src_code;
3246 $this->line->tva_tx = $txtva;
3247 $this->line->localtax1_tx = $txlocaltax1;
3248 $this->line->localtax2_tx = $txlocaltax2;
3249 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
3250 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
3251 $this->line->remise_percent = $remise_percent;
3252 $this->line->subprice = (float) $pu_ht;
3253 $this->line->subprice_ttc = (float) $pu_ttc;
3254 $this->line->info_bits = $info_bits;
3255 $this->line->total_ht = (float) $total_ht;
3256 $this->line->total_tva = (float) $total_tva;
3257 $this->line->total_localtax1 = (float) $total_localtax1;
3258 $this->line->total_localtax2 = (float) $total_localtax2;
3259 $this->line->total_ttc = (float) $total_ttc;
3260 $this->line->product_type = $type;
3261 $this->line->special_code = $oldline->special_code;
3262 $this->line->rang = $oldline->rang;
3263 $this->line->origin = $this->origin;
3264 $this->line->fk_unit = $fk_unit;
3266 $this->line->date_start = $date_start;
3267 $this->line->date_end = $date_end;
3270 $this->line->fk_multicurrency = $this->fk_multicurrency;
3271 $this->line->multicurrency_code = $this->multicurrency_code;
3272 $this->line->multicurrency_subprice = (float) $pu_ht_devise;
3273 $this->line->multicurrency_subprice_ttc = (float) $multicurrency_pu_ttc;
3274 $this->line->multicurrency_total_ht = (float) $multicurrency_total_ht;
3275 $this->line->multicurrency_total_tva = (float) $multicurrency_total_tva;
3276 $this->line->multicurrency_total_ttc = (float) $multicurrency_total_ttc;
3278 $this->line->subprice = (float) $pu_ht;
3279 $this->line->subprice_ttc = (float) $pu_ttc;
3280 $this->line->price = $this->line->subprice;
3282 $this->line->remise_percent = $remise_percent;
3284 if (is_array($array_options) && count($array_options) > 0) {
3286 foreach ($array_options as $key => $value) {
3287 $this->line->array_options[$key] = $array_options[$key];
3291 $result = $this->line->update($notrigger);
3297 $this->db->commit();
3300 $this->errors[] = $this->line->error;
3301 $this->errors = array_merge($this->errors, $this->line->errors);
3302 $this->error = $this->db->lasterror();
3303 $this->db->rollback();
3307 $this->error =
"Order status makes operation forbidden";
3308 dol_syslog(get_class($this).
"::updateline ".$this->error, LOG_ERR);
3323 global $user, $langs, $conf;
3325 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
3327 dol_syslog(get_class($this).
"::initAsSpecimen");
3334 $sql =
"SELECT rowid";
3335 $sql .=
" FROM ".$this->db->prefix().
"product";
3336 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
3337 $sql .= $this->db->order(
"rowid",
"ASC");
3338 $sql .= $this->db->plimit(1);
3339 $resql = $this->db->query($sql);
3340 if ($resql && $this->db->num_rows($resql)) {
3341 $obj = $this->db->fetch_object($resql);
3342 $prodid = $obj->rowid;
3347 $this->
ref =
'SPECIMEN';
3348 $this->specimen = 1;
3351 $this->date_commande = $now;
3352 $this->date_lim_reglement = $this->
date + 3600 * 24 * 30;
3353 $this->cond_reglement_code =
'RECEP';
3354 $this->mode_reglement_code =
'CHQ';
3356 $this->note_public =
'This is a comment (public)';
3357 $this->note_private =
'This is a comment (private)';
3359 $this->multicurrency_tx = 1;
3360 $this->multicurrency_code = $conf->currency;
3368 while ($xnbp < $nbp) {
3370 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
3372 $line->subprice = 100;
3373 $line->tva_tx = 19.6;
3374 $line->localtax1_tx = 0;
3375 $line->localtax2_tx = 0;
3377 $line->total_ht = 50;
3378 $line->total_ttc = 59.8;
3379 $line->total_tva = 9.8;
3380 $line->remise_percent = 50;
3382 $line->total_ht = 100;
3383 $line->total_ttc = 119.6;
3384 $line->total_tva = 19.6;
3385 $line->remise_percent = 00;
3387 $line->fk_product = $prodid;
3389 $this->lines[$xnbp] = $line;
3391 $this->total_ht += $line->total_ht;
3392 $this->total_tva += $line->total_tva;
3393 $this->total_ttc += $line->total_ttc;
3409 $sql =
'SELECT c.rowid, date_creation as datec, tms as datem, date_valid as date_validation, date_approve as datea, date_approve2 as datea2,';
3410 $sql .=
' fk_user_author, fk_user_modif, fk_user_valid, fk_user_approve, fk_user_approve2';
3411 $sql .=
' FROM '.$this->db->prefix().
'commande_fournisseur as c';
3412 $sql .=
' WHERE c.rowid = '.((int) $id);
3414 $result = $this->db->query($sql);
3416 if ($this->db->num_rows($result)) {
3417 $obj = $this->db->fetch_object($result);
3419 $this->
id = $obj->rowid;
3421 $this->user_creation_id = $obj->fk_user_author;
3422 $this->user_validation_id = $obj->fk_user_valid;
3423 $this->user_modification_id = $obj->fk_user_modif;
3424 $this->user_approve_id = $obj->fk_user_approve;
3425 $this->user_approve_id2 = $obj->fk_user_approve2;
3427 $this->date_creation = $this->db->jdate($obj->datec);
3428 $this->date_modification = $this->db->jdate($obj->datem);
3429 $this->date_approve = $this->db->jdate($obj->datea);
3430 $this->date_approve2 = $this->db->jdate($obj->datea2);
3431 $this->date_validation = $this->db->jdate($obj->date_validation);
3433 $this->db->free($result);
3446 global $conf, $user;
3448 $this->nb = array();
3451 $sql =
"SELECT count(co.rowid) as nb";
3452 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as co";
3453 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe as s ON co.fk_soc = s.rowid";
3454 if (empty($user->socid) && !$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3455 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
3456 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
3459 $sql .=
" ".$clause.
" co.entity IN (".
getEntity(
'supplier_order').
")";
3461 $resql = $this->db->query($sql);
3463 while ($obj = $this->db->fetch_object($resql)) {
3464 $this->nb[
"supplier_orders"] = $obj->nb;
3466 $this->db->free($resql);
3470 $this->error = $this->db->error();
3486 global $conf, $langs;
3488 $sql =
"SELECT c.rowid, c.date_creation as datec, c.date_commande, c.fk_statut, c.date_livraison as delivery_date, c.total_ht";
3489 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as c";
3490 if (empty($user->socid) && !$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3491 $sql .=
" JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
3493 $sql .=
" WHERE c.entity = ".$conf->entity;
3494 if ($mode ===
'awaiting') {
3495 $sql .=
" AND c.fk_statut IN (".self::STATUS_ORDERSENT.
", ".self::STATUS_RECEIVED_PARTIALLY.
")";
3497 $sql .=
" AND c.fk_statut IN (".self::STATUS_VALIDATED.
", ".self::STATUS_ACCEPTED.
")";
3500 $sql .=
" AND c.fk_soc = ".((int) $user->socid);
3503 $resql = $this->db->query($sql);
3508 $response->warning_delay = $conf->commande->fournisseur->warning_delay / 60 / 60 / 24;
3509 $response->label = $langs->trans(
"SuppliersOrdersToProcess");
3510 $response->labelShort = $langs->trans(
"Opened");
3511 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=1,2&mainmenu=commercial&leftmenu=orders_suppliers';
3512 $response->url_late = DOL_URL_ROOT.
'/fourn/commande/list.php?mainmenu=commercial&leftmenu=orders_suppliers&search_option=late';
3515 if ($mode ===
'awaiting') {
3516 $response->label = $langs->trans(
"SuppliersOrdersAwaitingReception");
3517 $response->labelShort = $langs->trans(
"AwaitingReception");
3518 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=3,4&mainmenu=commercial&leftmenu=orders_suppliers';
3519 $response->url_late = DOL_URL_ROOT.
'/fourn/commande/list.php?mainmenu=commercial&leftmenu=orders_suppliers&search_option=recv_late';
3522 while ($obj = $this->db->fetch_object($resql)) {
3523 $commandestatic->delivery_date = $this->db->jdate($obj->delivery_date);
3524 $commandestatic->date_commande = $this->db->jdate($obj->date_commande);
3525 $commandestatic->statut = $obj->fk_statut;
3526 $commandestatic->status = $obj->fk_statut;
3528 $response->nbtodo++;
3529 $response->total += $obj->total_ht;
3531 if ($commandestatic->hasDelay()) {
3532 $response->nbtodolate++;
3538 $this->error = $this->db->error();
3553 if ($this->methode_commande_id > 0) {
3554 $sql =
"SELECT rowid, code, libelle as label";
3555 $sql .=
" FROM ".$this->db->prefix().
'c_input_method';
3556 $sql .=
" WHERE active=1 AND rowid = ".((int) $this->methode_commande_id);
3558 $resql = $this->db->query($sql);
3560 if ($this->db->num_rows($resql)) {
3561 $obj = $this->db->fetch_object($resql);
3563 $string = $langs->trans($obj->code);
3564 if ($string == $obj->code) {
3565 $string = $obj->label !=
'-' ? $obj->label :
'';
3588 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3595 if (!empty($this->model_pdf)) {
3596 $modele = $this->model_pdf;
3602 if (empty($modele)) {
3605 $langs->load(
"suppliers");
3606 $outputlangs->load(
"products");
3608 $modelpath =
"core/modules/supplier_order/doc/";
3609 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3622 if (empty($this->lines)) {
3629 foreach ($this->lines as $line) {
3630 if ($line->fk_product > 0) {
3632 $idp = $tmpproductfourn->find_min_price_product_fournisseur($line->fk_product, $line->qty, $this->thirdparty->id);
3635 if ($tmpproductfourn->delivery_time_days > $nb) {
3636 $nb = $tmpproductfourn->delivery_time_days;
3645 return $nb.
' '.$langs->trans(
'days');
3658 return $user->hasRight(
"fournisseur",
"commande");
3673 'commande_fournisseur'
3690 'commande_fournisseurdet'
3707 if ($this->
status == self::STATUS_ORDERSENT || $this->
status == self::STATUS_RECEIVED_PARTIALLY) {
3709 if (!empty($this->delivery_date)) {
3710 $date_to_test = $this->delivery_date;
3711 return $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay);
3719 $date_to_test = $this->date_commande;
3721 return ($this->
status > 0 && $this->
status < 5) && $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay);
3734 global $conf, $langs;
3736 $langs->load(
'orders');
3740 if ($this->
status == self::STATUS_ORDERSENT || $this->
status == self::STATUS_RECEIVED_PARTIALLY) {
3741 if (!empty($this->delivery_date)) {
3742 $text = $langs->trans(
"DeliveryDate").
' '.
dol_print_date($this->delivery_date,
'day');
3744 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3747 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3750 $text .=
' '.($conf->commande->fournisseur->warning_delay > 0 ?
'+' :
'-').
' '.round(abs($conf->commande->fournisseur->warning_delay) / 3600 / 24, 1).
' '.$langs->trans(
"days").
' < '.$langs->trans(
"Today");
3768 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
3770 $qtydelivered = array();
3771 $qtywished = array();
3775 $filter = array(
't.fk_element' => $this->
id);
3777 $filter[
't.status'] = 1;
3780 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
3782 $this->error = $supplierorderdispatch->error;
3783 $this->errors = $supplierorderdispatch->errors;
3786 if (is_array($supplierorderdispatch->lines) && count($supplierorderdispatch->lines) > 0) {
3787 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
3791 foreach ($supplierorderdispatch->lines as $line) {
3792 if (array_key_exists($line->fk_product, $qtydelivered)) {
3793 $qtydelivered[$line->fk_product] += $line->qty;
3795 $qtydelivered[$line->fk_product] = $line->qty;
3798 foreach ($this->lines as $line) {
3803 if (array_key_exists($line->fk_product, $qtywished)) {
3804 $qtywished[$line->fk_product] += $line->qty;
3806 $qtywished[$line->fk_product] = $line->qty;
3811 $diff_array = array_diff_assoc($qtydelivered, $qtywished);
3812 $keysinwishednotindelivered = array_diff(array_keys($qtywished), array_keys($qtydelivered));
3813 $keysindeliverednotinwished = array_diff(array_keys($qtydelivered), array_keys($qtywished));
3821 if (count($diff_array) == 0 && count($keysinwishednotindelivered) == 0 && count($keysindeliverednotinwished) == 0) {
3822 if ($closeopenorder) {
3824 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3832 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3843 if (count($diff_array) > 0) {
3847 foreach ($diff_array as $key => $value) {
3849 if ($qtydelivered[$key] >= $qtywished[$key]) {
3856 if ($close == count($diff_array)) {
3858 if ($closeopenorder) {
3859 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3866 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3874 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3882 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3904 $this->receptions = array();
3906 dol_syslog(get_class($this).
"::loadReceptions", LOG_DEBUG);
3908 $sql =
'SELECT cd.rowid, cd.fk_product,';
3909 $sql .=
' sum(cfd.qty) as qty';
3910 $sql .=
' FROM '.$this->db->prefix().
'receptiondet_batch as cfd,';
3911 if ($filtre_statut >= 0) {
3912 $sql .=
' '.$this->db->prefix().
'reception as e,';
3914 $sql .=
' '.$this->db->prefix().
'commande_fournisseurdet as cd';
3916 if ($filtre_statut >= 0) {
3917 $sql .=
' cfd.fk_reception = e.rowid AND';
3919 $sql .=
' cfd.fk_elementdet = cd.rowid';
3920 $sql .=
' AND cd.fk_commande ='.((int) $this->
id);
3921 if (isset($this->fk_product) && !empty($this->fk_product) > 0) {
3922 $sql .=
' AND cd.fk_product = '.((int) $this->fk_product);
3924 if ($filtre_statut >= 0) {
3925 $sql .=
' AND e.fk_statut >= '.((int) $filtre_statut);
3927 $sql .=
' GROUP BY cd.rowid, cd.fk_product';
3929 $resql = $this->db->query($sql);
3931 $num = $this->db->num_rows($resql);
3934 $obj = $this->db->fetch_object($resql);
3935 empty($this->receptions[$obj->rowid]) ? $this->receptions[$obj->rowid] = $obj->qty : $this->receptions[$obj->rowid] += $obj->qty;
3938 $this->db->free($resql);
3942 $this->error = $this->db->lasterror();
3958 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3960 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3961 $return .=
'<div class="info-box info-box-sm">';
3962 $return .=
'<span class="info-box-icon bg-infobox-action">';
3964 $return .=
'</span>';
3965 $return .=
'<div class="info-box-content">';
3966 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
3967 if ($selected >= 0) {
3968 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3970 if (!empty($arraydata[
'thirdparty'])) {
3971 $return .=
'<br><span class="info-box-label">'.$arraydata[
'thirdparty'].
'</span>';
3973 if (!empty($this->
date)) {
3974 $return .=
'<br><span class="info-box-label">'.dol_print_date($this->
date,
'day').
'</span>';
3976 if (!empty($this->total_ht)) {
3977 $return .=
' <span class="info-box-label amount" title="'.dol_escape_htmltag($langs->trans(
"AmountHT")).
'">'.
price($this->total_ht);
3978 $return .=
' '.$langs->trans(
"HT");
3979 $return .=
'</span>';
3981 if (method_exists($this,
'getLibStatut')) {
3982 $return .=
'<br><span class="info-box-status">'.$this->getLibStatut(3).
'</span>';
3984 if (property_exists($this,
'billed')) {
3985 $return .=
' <span class="opacitymedium">'.$langs->trans(
"Billed").
': </span><span class="info-box-label">'.
yn($this->billed).
'</span>';
3987 $return .=
'</div>';
3988 $return .=
'</div>';
3989 $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.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
setErrorsFromObject($object)
setErrorsFromObject
updateRangOfLine($rowid, $rang)
Update position of line (rang)
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)
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message in dol_events session object.
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