40require_once DOL_DOCUMENT_ROOT.
'/core/class/commonorder.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.orderline.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
44if (isModEnabled(
'productbatch')) {
45 require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
57 public $element =
'order_supplier';
62 public $table_element =
'commande_fournisseur';
67 public $table_element_line =
'commande_fournisseurdet';
72 public $class_element_line =
'CommandeFournisseurLigne';
77 public $fk_element =
'fk_commande';
82 public $picto =
'supplier_order';
88 public $restrictiononfksoc = 1;
108 public $ref_supplier;
151 public $date_approve;
157 public $date_approve2;
162 public $date_commande;
165 public $remise_percent;
166 public $methode_commande_id;
167 public $methode_commande;
172 public $delivery_date;
187 public $total_localtax1;
192 public $total_localtax2;
209 public $cond_reglement_id;
214 public $cond_reglement_code;
219 public $cond_reglement_label;
224 public $cond_reglement_doc;
234 public $mode_reglement_id;
239 public $mode_reglement_code;
244 public $mode_reglement;
249 public $user_author_id;
254 public $user_approve_id;
260 public $user_approve_id2;
267 public $extraparams = array();
272 public $lines = array();
282 public $linked_objects = array();
287 public $date_lim_reglement;
291 public $receptions = array();
297 public $fk_multicurrency;
302 public $multicurrency_code;
307 public $multicurrency_tx;
312 public $multicurrency_total_ht;
317 public $multicurrency_total_tva;
322 public $multicurrency_total_ttc;
352 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => 0,
'notnull' => 1,
'position' => 10),
353 'ref' => array(
'type' =>
'varchar(255)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => 1,
'showoncombobox' => 1,
'position' => 25,
'searchall' => 1),
354 'ref_ext' => array(
'type' =>
'varchar(255)',
'label' =>
'Ref ext',
'enabled' => 1,
'visible' => 0,
'position' => 35),
355 'ref_supplier' => array(
'type' =>
'varchar(255)',
'label' =>
'RefOrderSupplierShort',
'enabled' => 1,
'visible' => 1,
'position' => 40,
'searchall' => 1),
356 'fk_projet' => array(
'type' =>
'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)',
'label' =>
'Project',
'enabled' =>
"isModEnabled('project')",
'visible' => -1,
'position' => 45),
357 'date_valid' => array(
'type' =>
'datetime',
'label' =>
'DateValidation',
'enabled' => 1,
'visible' => -1,
'position' => 710),
358 'date_approve' => array(
'type' =>
'datetime',
'label' =>
'DateApprove',
'enabled' => 1,
'visible' => -1,
'position' => 720),
359 'date_approve2' => array(
'type' =>
'datetime',
'label' =>
'DateApprove2',
'enabled' => 1,
'visible' => 3,
'position' => 725),
360 'date_commande' => array(
'type' =>
'date',
'label' =>
'OrderDateShort',
'enabled' => 1,
'visible' => 1,
'position' => 70),
361 'date_livraison' => array(
'type' =>
'datetime',
'label' =>
'DeliveryDate',
'enabled' =>
'empty($conf->global->ORDER_DISABLE_DELIVERY_DATE)',
'visible' => 1,
'position' => 74),
362 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'visible' => 3,
'position' => 41),
363 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => 3,
'notnull' => -1,
'position' => 80),
364 'fk_user_valid' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserValidation',
'enabled' => 1,
'visible' => 3,
'position' => 711),
365 'fk_user_approve' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserApproval',
'enabled' => 1,
'visible' => 3,
'position' => 721),
366 'fk_user_approve2' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserApproval2',
'enabled' => 1,
'visible' => 3,
'position' => 726),
367 'source' => array(
'type' =>
'smallint(6)',
'label' =>
'Source',
'enabled' => 1,
'visible' => 3,
'notnull' => 1,
'position' => 100),
368 'billed' => array(
'type' =>
'smallint(6)',
'label' =>
'Billed',
'enabled' => 1,
'visible' => 1,
'position' => 710),
369 'total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'AmountHT',
'enabled' => 1,
'visible' => 1,
'position' => 130,
'isameasure' => 1),
370 'total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'AmountVAT',
'enabled' => 1,
'visible' => 1,
'position' => 135,
'isameasure' => 1),
371 'localtax1' => array(
'type' =>
'double(24,8)',
'label' =>
'LT1',
'enabled' => 1,
'visible' => 3,
'position' => 140,
'isameasure' => 1),
372 'localtax2' => array(
'type' =>
'double(24,8)',
'label' =>
'LT2',
'enabled' => 1,
'visible' => 3,
'position' => 145,
'isameasure' => 1),
373 'total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'AmountTTC',
'enabled' => 1,
'visible' => -1,
'position' => 150,
'isameasure' => 1),
374 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 750,
'searchall' => 1),
375 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 760,
'searchall' => 1),
376 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'ModelPDF',
'enabled' => 1,
'visible' => 0,
'position' => 165),
377 'fk_input_method' => array(
'type' =>
'integer',
'label' =>
'OrderMode',
'enabled' => 1,
'visible' => 3,
'position' => 170),
378 'fk_cond_reglement' => array(
'type' =>
'integer',
'label' =>
'PaymentTerm',
'enabled' => 1,
'visible' => 3,
'position' => 175),
379 'fk_mode_reglement' => array(
'type' =>
'integer',
'label' =>
'PaymentMode',
'enabled' => 1,
'visible' => 3,
'position' => 180),
380 'extraparams' => array(
'type' =>
'varchar(255)',
'label' =>
'Extraparams',
'enabled' => 1,
'visible' => 0,
'position' => 190),
381 'fk_account' => array(
'type' =>
'integer',
'label' =>
'BankAccount',
'enabled' =>
'isModEnabled("bank")',
'visible' => 3,
'position' => 200),
382 'fk_incoterms' => array(
'type' =>
'integer',
'label' =>
'IncotermCode',
'enabled' => 1,
'visible' => 3,
'position' => 205),
383 'location_incoterms' => array(
'type' =>
'varchar(255)',
'label' =>
'IncotermLocation',
'enabled' => 1,
'visible' => 3,
'position' => 210),
384 'fk_multicurrency' => array(
'type' =>
'integer',
'label' =>
'Fk multicurrency',
'enabled' => 1,
'visible' => 0,
'position' => 215),
385 'multicurrency_code' => array(
'type' =>
'varchar(255)',
'label' =>
'Currency',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 220),
386 'multicurrency_tx' => array(
'type' =>
'double(24,8)',
'label' =>
'CurrencyRate',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 225),
387 'multicurrency_total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountHT',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 230),
388 'multicurrency_total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountVAT',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 235),
389 'multicurrency_total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountTTC',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 240),
390 'date_creation' => array(
'type' =>
'datetime',
'label' =>
'Date creation',
'enabled' => 1,
'visible' => -1,
'position' => 500),
391 'fk_soc' => array(
'type' =>
'integer:Societe:societe/class/societe.class.php',
'label' =>
'ThirdParty',
'enabled' =>
'isModEnabled("societe")',
'visible' => 1,
'notnull' => 1,
'position' => 50),
392 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => 0,
'notnull' => 1,
'position' => 1000,
'index' => 1),
393 'tms' => array(
'type' =>
'datetime',
'label' =>
"DateModificationShort",
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 501),
394 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'LastMainDoc',
'enabled' => 1,
'visible' => 0,
'position' => 700),
395 'fk_statut' => array(
'type' =>
'smallint(6)',
'label' =>
'Status',
'enabled' => 1,
'visible' => 1,
'position' => 701),
396 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => 0,
'position' => 900),
460 $this->ismultientitymanaged = 1;
471 public function fetch($id, $ref =
'')
474 if (empty($id) && empty($ref)) {
478 $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,";
479 $sql .=
" c.localtax1, c.localtax2, ";
480 $sql .=
" c.date_creation, c.date_valid, c.date_approve, c.date_approve2,";
481 $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,";
482 $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,";
483 $sql .=
" c.fk_account,";
484 $sql .=
" c.note_private, c.note_public, c.model_pdf, c.extraparams, c.billed,";
485 $sql .=
" c.fk_multicurrency, c.multicurrency_code, c.multicurrency_tx, c.multicurrency_total_ht, c.multicurrency_total_tva, c.multicurrency_total_ttc,";
486 $sql .=
" cm.libelle as methode_commande,";
487 $sql .=
" cr.code as cond_reglement_code, cr.libelle as cond_reglement_label, cr.libelle_facture as cond_reglement_doc,";
488 $sql .=
" p.code as mode_reglement_code, p.libelle as mode_reglement_libelle";
489 $sql .=
', c.fk_incoterms, c.location_incoterms';
490 $sql .=
', i.libelle as label_incoterms';
491 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as c";
492 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_payment_term as cr ON c.fk_cond_reglement = cr.rowid";
493 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_paiement as p ON c.fk_mode_reglement = p.id";
494 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_input_method as cm ON cm.rowid = c.fk_input_method";
495 $sql .=
' LEFT JOIN '.$this->db->prefix().
'c_incoterms as i ON c.fk_incoterms = i.rowid';
498 $sql .=
" WHERE c.entity IN (".getEntity(
'supplier_order').
")";
500 $sql .=
" WHERE c.rowid=".((int) $id);
504 $sql .=
" AND c.ref='".$this->db->escape($ref).
"'";
507 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
508 $resql = $this->db->query($sql);
510 $obj = $this->db->fetch_object($resql);
512 $this->error =
'Bill with id '.$id.
' not found';
513 dol_syslog(get_class($this).
'::fetch '.$this->error);
517 $this->
id = $obj->rowid;
518 $this->entity = $obj->entity;
520 $this->
ref = $obj->ref;
521 $this->ref_supplier = $obj->ref_supplier;
522 $this->socid = $obj->fk_soc;
523 $this->fourn_id = $obj->fk_soc;
524 $this->statut = $obj->status;
525 $this->
status = $obj->status;
526 $this->billed = $obj->billed;
527 $this->user_author_id = $obj->user_author_id;
528 $this->user_validation_id = $obj->user_validation_id;
529 $this->user_approve_id = $obj->user_approve_id;
530 $this->user_approve_id2 = $obj->user_approve_id2;
531 $this->total_ht = $obj->total_ht;
532 $this->total_tva = $obj->total_tva;
533 $this->total_localtax1 = $obj->localtax1;
534 $this->total_localtax2 = $obj->localtax2;
535 $this->total_ttc = $obj->total_ttc;
536 $this->date_creation = $this->db->jdate($obj->date_creation);
537 $this->date_valid = $this->db->jdate($obj->date_valid);
538 $this->date_approve = $this->db->jdate($obj->date_approve);
539 $this->date_approve2 = $this->db->jdate($obj->date_approve2);
540 $this->date_commande = $this->db->jdate($obj->date_commande);
541 if (isset($obj->date_commande)) {
542 $this->date = $this->date_commande;
544 $this->date = $this->date_creation;
546 $this->delivery_date = $this->db->jdate($obj->delivery_date);
547 $this->remise_percent = $obj->remise_percent;
548 $this->methode_commande_id = $obj->fk_input_method;
549 $this->methode_commande = $obj->methode_commande;
551 $this->source = $obj->source;
552 $this->fk_project = $obj->fk_project;
553 $this->cond_reglement_id = $obj->fk_cond_reglement;
554 $this->cond_reglement_code = $obj->cond_reglement_code;
555 $this->cond_reglement = $obj->cond_reglement_label;
556 $this->cond_reglement_label = $obj->cond_reglement_label;
557 $this->cond_reglement_doc = $obj->cond_reglement_doc;
558 $this->fk_account = $obj->fk_account;
559 $this->mode_reglement_id = $obj->fk_mode_reglement;
560 $this->mode_reglement_code = $obj->mode_reglement_code;
561 $this->mode_reglement = $obj->mode_reglement_libelle;
562 $this->note = $obj->note_private;
563 $this->note_private = $obj->note_private;
564 $this->note_public = $obj->note_public;
565 $this->model_pdf = $obj->model_pdf;
568 $this->fk_incoterms = $obj->fk_incoterms;
569 $this->location_incoterms = $obj->location_incoterms;
570 $this->label_incoterms = $obj->label_incoterms;
573 $this->fk_multicurrency = $obj->fk_multicurrency;
574 $this->multicurrency_code = $obj->multicurrency_code;
575 $this->multicurrency_tx = $obj->multicurrency_tx;
576 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
577 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
578 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
580 $this->extraparams = isset($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
582 $this->db->free($resql);
597 $this->error = $this->db->error().
" sql=".$sql;
613 $this->lines = array();
615 $sql =
"SELECT l.rowid, l.fk_commande, l.ref as ref_supplier, l.fk_product, l.product_type, l.label, l.description, l.qty,";
616 $sql .=
" l.vat_src_code, l.tva_tx, l.remise_percent, l.subprice,";
617 $sql .=
" l.localtax1_tx, l. localtax2_tx, l.localtax1_type, l. localtax2_type, l.total_localtax1, l.total_localtax2,";
618 $sql .=
" l.total_ht, l.total_tva, l.total_ttc, l.info_bits, l.special_code, l.fk_parent_line, l.rang,";
619 $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,";
620 $sql .=
" l.fk_unit,";
621 $sql .=
" l.date_start, l.date_end,";
622 $sql .=
' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc';
623 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseurdet as l";
624 $sql .=
' LEFT JOIN '.$this->db->prefix().
'product as p ON l.fk_product = p.rowid';
625 $sql .=
" WHERE l.fk_commande = ".((int) $this->
id);
627 $sql .=
' AND p.fk_product_type = 0';
629 $sql .=
" ORDER BY l.rang, l.rowid";
632 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
634 $result = $this->db->query($sql);
636 $num = $this->db->num_rows($result);
640 $objp = $this->db->fetch_object($result);
644 $line->id = $objp->rowid;
645 $line->fk_commande = $objp->fk_commande;
646 $line->desc = $objp->description;
647 $line->description = $objp->description;
648 $line->qty = $objp->qty;
649 $line->tva_tx = $objp->tva_tx;
650 $line->localtax1_tx = $objp->localtax1_tx;
651 $line->localtax2_tx = $objp->localtax2_tx;
652 $line->localtax1_type = $objp->localtax1_type;
653 $line->localtax2_type = $objp->localtax2_type;
654 $line->subprice = $objp->subprice;
655 $line->pu_ht = $objp->subprice;
656 $line->remise_percent = $objp->remise_percent;
658 $line->vat_src_code = $objp->vat_src_code;
659 $line->total_ht = $objp->total_ht;
660 $line->total_tva = $objp->total_tva;
661 $line->total_localtax1 = $objp->total_localtax1;
662 $line->total_localtax2 = $objp->total_localtax2;
663 $line->total_ttc = $objp->total_ttc;
664 $line->product_type = $objp->product_type;
666 $line->fk_product = $objp->fk_product;
668 $line->libelle = $objp->product_label;
669 $line->product_label = $objp->product_label;
670 $line->product_desc = $objp->product_desc;
671 $line->product_tobatch = $objp->product_tobatch;
672 $line->product_barcode = $objp->product_barcode;
674 $line->ref = $objp->product_ref;
675 $line->product_ref = $objp->product_ref;
676 $line->ref_fourn = $objp->ref_supplier;
677 $line->ref_supplier = $objp->ref_supplier;
684 $sqlsearchpackage =
'SELECT rowid, packaging FROM '.$this->db->prefix().
"product_fournisseur_price";
685 $sqlsearchpackage .=
' WHERE entity IN ('.getEntity(
'product_fournisseur_price').
")";
686 $sqlsearchpackage .=
" AND fk_product = ".((int) $objp->fk_product);
687 $sqlsearchpackage .=
" AND ref_fourn = '".$this->db->escape($objp->ref_supplier).
"'";
688 $sqlsearchpackage .=
" AND quantity <= ".((float) $objp->qty);
689 $sqlsearchpackage .=
" AND (packaging IS NULL OR packaging = 0 OR packaging <= ".((float) $objp->qty).
")";
690 $sqlsearchpackage .=
" AND fk_soc = ".((int) $this->socid);
691 $sqlsearchpackage .=
" ORDER BY packaging ASC";
692 $sqlsearchpackage .=
" LIMIT 1";
694 $resqlsearchpackage = $this->db->query($sqlsearchpackage);
695 if ($resqlsearchpackage) {
696 $objsearchpackage = $this->db->fetch_object($resqlsearchpackage);
697 if ($objsearchpackage) {
698 $line->fk_fournprice = $objsearchpackage->rowid;
699 $line->packaging = $objsearchpackage->packaging;
702 $this->error = $this->db->lasterror();
707 $line->date_start = $this->db->jdate($objp->date_start);
708 $line->date_end = $this->db->jdate($objp->date_end);
709 $line->fk_unit = $objp->fk_unit;
712 $line->fk_multicurrency = $objp->fk_multicurrency;
713 $line->multicurrency_code = $objp->multicurrency_code;
714 $line->multicurrency_subprice = $objp->multicurrency_subprice;
715 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
716 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
717 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
719 $line->info_bits = $objp->info_bits;
720 $line->special_code = $objp->special_code;
721 $line->fk_parent_line = $objp->fk_parent_line;
723 $line->rang = $objp->rang;
727 $line->fetch_optionals();
729 $this->lines[$i] = $line;
733 $this->db->free($result);
737 $this->error = $this->db->error().
" sql=".$sql;
750 public function valid($user, $idwarehouse = 0, $notrigger = 0)
753 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
759 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")))
760 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"fournisseur",
"supplier_order_advance",
"validate"))) {
765 $soc->fetch($this->fourn_id);
768 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
775 $sql =
'UPDATE '.$this->db->prefix().
"commande_fournisseur";
776 $sql .=
" SET ref='".$this->db->escape($num).
"',";
777 $sql .=
" fk_statut = ".((int) self::STATUS_VALIDATED).
",";
778 $sql .=
" date_valid='".$this->db->idate(
dol_now()).
"',";
779 $sql .=
" fk_user_valid = ".((int) $user->id);
780 $sql .=
" WHERE rowid = ".((int) $this->
id);
781 $sql .=
" AND fk_statut = ".((int) self::STATUS_DRAFT);
783 $resql = $this->db->query($sql);
789 if (!$error && !$notrigger) {
791 $result = $this->
call_trigger(
'ORDER_SUPPLIER_VALIDATE', $user);
799 $this->oldref = $this->ref;
802 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
804 $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).
"'";
805 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'fournisseur/commande/".$this->db->escape($this->
ref).
"' and entity = ".((int) $conf->entity);
806 $resql = $this->db->query($sql);
809 $this->error = $this->db->lasterror();
811 $sql =
'UPDATE '.$this->db->prefix().
"ecm_files set filepath = 'fournisseur/commande/".$this->db->escape($this->newref).
"'";
812 $sql .=
" WHERE filepath = 'fournisseur/commande/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
813 $resql = $this->db->query($sql);
816 $this->error = $this->db->lasterror();
822 $dirsource = $conf->fournisseur->commande->dir_output.
'/'.$oldref;
823 $dirdest = $conf->fournisseur->commande->dir_output.
'/'.$newref;
824 if (!$error && file_exists($dirsource)) {
825 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
827 if (@rename($dirsource, $dirdest)) {
830 $listoffiles =
dol_dir_list($conf->fournisseur->commande->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
831 foreach ($listoffiles as $fileentry) {
832 $dirsource = $fileentry[
'name'];
833 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
834 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
835 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
836 @rename($dirsource, $dirdest);
854 $this->db->rollback();
858 $this->error =
'NotAuthorized';
859 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
872 return $this->
LibStatut($this->statut, $mode, $this->billed);
884 public function LibStatut($status, $mode = 0, $billed = 0)
887 global $langs, $hookmanager;
889 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
890 $langs->load(
'orders');
892 $this->labelStatus[0] =
'StatusSupplierOrderDraft';
893 $this->labelStatus[1] =
'StatusSupplierOrderValidated';
894 $this->labelStatus[2] =
'StatusSupplierOrderApproved';
896 $this->labelStatus[3] =
'StatusSupplierOrderOnProcess';
898 $this->labelStatus[3] =
'StatusSupplierOrderOnProcessWithValidation';
900 $this->labelStatus[4] =
'StatusSupplierOrderReceivedPartially';
901 $this->labelStatus[5] =
'StatusSupplierOrderReceivedAll';
902 $this->labelStatus[6] =
'StatusSupplierOrderCanceled';
903 $this->labelStatus[7] =
'StatusSupplierOrderCanceled';
904 $this->labelStatus[9] =
'StatusSupplierOrderRefused';
907 $this->labelStatusShort[0] =
'StatusSupplierOrderDraftShort';
908 $this->labelStatusShort[1] =
'StatusSupplierOrderValidatedShort';
909 $this->labelStatusShort[2] =
'StatusSupplierOrderApprovedShort';
910 $this->labelStatusShort[3] =
'StatusSupplierOrderOnProcessShort';
911 $this->labelStatusShort[4] =
'StatusSupplierOrderReceivedPartiallyShort';
912 $this->labelStatusShort[5] =
'StatusSupplierOrderReceivedAllShort';
913 $this->labelStatusShort[6] =
'StatusSupplierOrderCanceledShort';
914 $this->labelStatusShort[7] =
'StatusSupplierOrderCanceledShort';
915 $this->labelStatusShort[9] =
'StatusSupplierOrderRefusedShort';
918 $statustrans = array(
930 $statusClass =
'status0';
931 if (!empty($statustrans[$status])) {
932 $statusClass = $statustrans[$status];
937 $billedtext =
' - '.$langs->trans(
"Billed");
939 if ($status == 5 && $billed) {
940 $statusClass =
'status6';
943 $statusLong = $langs->transnoentitiesnoconv($this->labelStatus[$status]).$billedtext;
944 $statusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
946 $parameters = array(
'status' => $status,
'mode' => $mode,
'billed' => $billed);
947 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
949 return $hookmanager->resPrint;
952 return dolGetStatus($statusLong, $statusShort,
'', $statusClass, $mode);
963 global $conf, $langs, $user;
965 $langs->loadLangs([
'bills',
'orders']);
968 $nofetch = !empty($params[
'nofetch']);
970 if ($user->hasRight(
"fournisseur",
"commande",
"read")) {
971 $datas[
'picto'] =
'<u class="paddingrightonly">'.$langs->trans(
"SupplierOrder").
'</u>';
972 if (isset($this->statut)) {
973 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
975 if (!empty($this->
ref)) {
976 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
978 if (!empty($this->ref_supplier)) {
979 $datas[
'refsupplier'] =
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.$this->ref_supplier;
982 $langs->load(
'companies');
983 if (empty($this->thirdparty)) {
986 $datas[
'supplier'] =
'<br><b>'.$langs->trans(
'Supplier').
':</b> '.$this->thirdparty->getNomUrl(1,
'', 0, 1);
988 if (!empty($this->total_ht)) {
989 $datas[
'totalht'] =
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
991 if (!empty($this->total_tva)) {
992 $datas[
'totaltva'] =
'<br><b>'.$langs->trans(
'VAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
994 if (!empty($this->total_ttc)) {
995 $datas[
'totalttc'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
997 if (!empty($this->date)) {
998 $datas[
'date'] =
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->date,
'day');
1000 if (!empty($this->delivery_date)) {
1001 $datas[
'deliverydate'] =
'<br><b>'.$langs->trans(
'DeliveryDate').
':</b> '.
dol_print_date($this->delivery_date,
'dayhour');
1017 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = 0)
1019 global $langs, $user, $hookmanager;
1024 'objecttype' => $this->element,
1025 'option' => $option,
1028 $classfortooltip =
'classfortooltip';
1031 $classfortooltip =
'classforajaxtooltip';
1032 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1038 $url = DOL_URL_ROOT.
'/fourn/commande/card.php?id='.$this->id;
1040 if ($option !==
'nolink') {
1042 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1043 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1044 $add_save_lastsearch_values = 1;
1046 if ($add_save_lastsearch_values) {
1047 $url .=
'&save_lastsearch_values=1';
1052 if (empty($notooltip)) {
1054 $label = $langs->trans(
"ShowOrder");
1055 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1057 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1058 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
1061 $linkstart =
'<a href="'.$url.
'"';
1062 $linkstart .= $linkclose.
'>';
1065 $result .= $linkstart;
1067 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
1069 if ($withpicto != 2) {
1070 $result .= $this->ref;
1072 $result .= $linkend;
1074 if ($addlinktonotes) {
1075 $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
1078 $result .=
' <span class="note inline-block">';
1079 $result .=
'<a href="'.DOL_URL_ROOT.
'/fourn/commande/note.php?id='.$this->
id.
'" class="classfortooltip" title="'.
dol_escape_htmltag($notetoshow).
'">';
1084 $result .=
'</span>';
1089 $hookmanager->initHooks(array($this->element .
'dao'));
1090 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1091 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1093 $result = $hookmanager->resPrint;
1095 $result .= $hookmanager->resPrint;
1110 global $langs, $conf;
1111 $langs->load(
"orders");
1120 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
1122 foreach ($dirmodels as $reldir) {
1123 $dir =
dol_buildpath($reldir.
"core/modules/supplier_order/");
1126 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1134 $obj =
new $classname();
1135 '@phan-var-force ModeleNumRefSuppliersOrders $obj';
1136 $numref = $obj->getNextValue($soc, $this);
1138 if ($numref !=
"") {
1141 $this->error = $obj->error;
1145 $this->error =
"Error_COMMANDE_SUPPLIER_ADDON_NotDefined";
1159 if ($this->billed) {
1165 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur SET billed = 1';
1168 if ($this->db->query($sql)) {
1171 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CLASSIFY_BILLED', $user);
1181 $this->db->commit();
1184 $this->db->rollback();
1190 $this->db->rollback();
1204 if (empty($this->billed)) {
1210 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur SET billed = 0';
1214 if (!$this->db->query($sql)) {
1216 $this->db->rollback();
1221 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CLASSIFY_UNBILLED', $user);
1223 $this->db->rollback();
1229 $this->db->commit();
1242 public function approve($user, $idwarehouse = 0, $secondlevel = 0)
1244 global $langs, $conf;
1245 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1251 if ($user->hasRight(
"fournisseur",
"commande",
"approuver")) {
1257 $soc =
new Societe($this->db);
1258 $soc->fetch($this->fourn_id);
1261 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
1269 $movetoapprovestatus =
true;
1272 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1273 $sql .=
" SET ref='".$this->db->escape($num).
"',";
1274 if (empty($secondlevel)) {
1275 $sql .=
" date_approve='".$this->db->idate($now).
"',";
1276 $sql .=
" fk_user_approve = ".((int) $user->id);
1278 if (empty($this->user_approve_id2)) {
1279 $movetoapprovestatus =
false;
1280 $comment =
' (first level)';
1284 $sql .=
" date_approve2='".$this->db->idate($now).
"',";
1285 $sql .=
" fk_user_approve2 = ".((int) $user->id);
1286 if (empty($this->user_approve_id)) {
1287 $movetoapprovestatus =
false;
1289 $comment =
' (second level)';
1292 if ($movetoapprovestatus) {
1293 $sql .=
", fk_statut = ".self::STATUS_ACCEPTED;
1295 $sql .=
", fk_statut = ".self::STATUS_VALIDATED;
1297 $sql .=
" WHERE rowid = ".((int) $this->
id);
1298 $sql .=
" AND fk_statut = ".self::STATUS_VALIDATED;
1300 if ($this->db->query($sql)) {
1302 $result = $this->
add_contact($user->id,
'SALESREPFOLL',
'internal', 1);
1303 if ($result < 0 && $result != -2) {
1309 if (!$error && $movetoapprovestatus && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER')) {
1310 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1311 $langs->load(
"agenda");
1313 $cpt = count($this->lines);
1314 for ($i = 0; $i < $cpt; $i++) {
1316 if ($this->lines[$i]->fk_product > 0) {
1317 $this->line = $this->lines[$i];
1319 $mouvP->origin = &$this;
1320 $mouvP->setOrigin($this->element, $this->
id);
1322 $up_ht_disc = $this->lines[$i]->subprice;
1323 if (!empty($this->lines[$i]->remise_percent) && !
getDolGlobalString(
'STOCK_EXCLUDE_DISCOUNT_FOR_PMP')) {
1324 $up_ht_disc =
price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100,
'MU');
1326 $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans(
"OrderApprovedInDolibarr", $this->ref));
1337 $result = $this->
call_trigger(
'ORDER_SUPPLIER_APPROVE', $user);
1345 $this->
ref = $this->newref;
1347 if ($movetoapprovestatus) {
1352 if (empty($secondlevel)) {
1353 $this->date_approve = $now;
1354 $this->user_approve_id = $user->id;
1356 $this->date_approve2 = $now;
1357 $this->user_approve_id2 = $user->id;
1360 $this->db->commit();
1363 $this->db->rollback();
1367 $this->db->rollback();
1368 $this->error = $this->db->lasterror();
1372 dol_syslog(get_class($this).
"::approve Not Authorized", LOG_ERR);
1385 global $conf, $langs;
1391 if ($user->hasRight(
"fournisseur",
"commande",
"approuver")) {
1394 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur SET fk_statut = ".
self::STATUS_REFUSED;
1395 $sql .=
" WHERE rowid = ".((int) $this->
id);
1397 if ($this->db->query($sql)) {
1402 $result = $this->
call_trigger(
'ORDER_SUPPLIER_REFUSE', $user);
1405 $this->db->rollback();
1407 $this->db->commit();
1412 $this->db->rollback();
1413 $this->error = $this->db->lasterror();
1414 dol_syslog(get_class($this).
"::refuse Error -1");
1418 dol_syslog(get_class($this).
"::refuse Not Authorized");
1432 public function Cancel($user, $idwarehouse = -1)
1435 global $langs, $conf;
1441 if ($user->hasRight(
"fournisseur",
"commande",
"commander")) {
1446 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur SET fk_statut = ".((int) $statut);
1447 $sql .=
" WHERE rowid = ".((int) $this->
id);
1448 dol_syslog(get_class($this).
"::cancel", LOG_DEBUG);
1449 if ($this->db->query($sql)) {
1453 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CANCEL', $user);
1460 $this->db->commit();
1463 $this->db->rollback();
1467 $this->db->rollback();
1468 $this->error = $this->db->lasterror();
1469 dol_syslog(get_class($this).
"::cancel ".$this->error);
1473 dol_syslog(get_class($this).
"::cancel Not Authorized");
1487 public function commande($user, $date, $methode, $comment =
'')
1492 if ($user->hasRight(
"fournisseur",
"commande",
"commander")) {
1495 $newnoteprivate = $this->note_private;
1497 $newnoteprivate =
dol_concatdesc($newnoteprivate, $langs->trans(
"Comment").
': '.$comment);
1500 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1501 $sql .=
" SET fk_statut=".self::STATUS_ORDERSENT.
", fk_input_method=".$methode.
", date_commande='".$this->db->idate($date).
"', ";
1502 $sql .=
" note_private='".$this->db->escape($newnoteprivate).
"'";
1503 $sql .=
" WHERE rowid=".((int) $this->
id);
1505 dol_syslog(get_class($this).
"::commande", LOG_DEBUG);
1506 if ($this->db->query($sql)) {
1508 $this->methode_commande_id = $methode;
1509 $this->date_commande = $date;
1510 $this->context = array(
'comments' => $comment);
1513 $result = $this->
call_trigger(
'ORDER_SUPPLIER_SUBMIT', $user);
1520 $this->error = $this->db->lasterror();
1521 $this->errors[] = $this->db->lasterror();
1525 $this->db->commit();
1527 $this->db->rollback();
1531 $this->error = $langs->trans(
'NotAuthorized');
1532 $this->errors[] = $langs->trans(
'NotAuthorized');
1533 dol_syslog(get_class($this).
"::commande User not Authorized", LOG_WARNING);
1536 return ($error ? -1 : 1);
1546 public function create($user, $notrigger = 0)
1548 global $langs, $conf, $hookmanager;
1556 $date = ($this->date_commande ? $this->date_commande : $this->date);
1560 $delivery_date = $this->delivery_date;
1563 if (empty($this->source)) {
1568 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
1573 if (empty($this->fk_multicurrency)) {
1574 $this->multicurrency_code = $conf->currency;
1575 $this->fk_multicurrency = 0;
1576 $this->multicurrency_tx = 1;
1582 $sql =
"INSERT INTO ".$this->db->prefix().
"commande_fournisseur (";
1584 $sql .=
", ref_supplier";
1585 $sql .=
", note_private";
1586 $sql .=
", note_public";
1589 $sql .=
", fk_projet";
1590 $sql .=
", date_creation";
1591 $sql .=
", date_livraison";
1592 $sql .=
", fk_user_author";
1593 $sql .=
", fk_statut";
1595 $sql .=
", model_pdf";
1596 $sql .=
", fk_mode_reglement";
1597 $sql .=
", fk_cond_reglement";
1598 $sql .=
", fk_account";
1599 $sql .=
", fk_incoterms, location_incoterms";
1600 $sql .=
", fk_multicurrency";
1601 $sql .=
", multicurrency_code";
1602 $sql .=
", multicurrency_tx";
1604 $sql .=
" VALUES (";
1606 $sql .=
", ".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"NULL");
1607 $sql .=
", '".$this->db->escape($this->note_private).
"'";
1608 $sql .=
", '".$this->db->escape($this->note_public).
"'";
1609 $sql .=
", ".setEntity($this);
1610 $sql .=
", ".((int) $this->socid);
1611 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
1612 $sql .=
", '".$this->db->idate($date).
"'";
1613 $sql .=
", ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
"null");
1614 $sql .=
", ".((int) $user->id);
1615 $sql .=
", ".self::STATUS_DRAFT;
1616 $sql .=
", ".((int) $this->source);
1617 $sql .=
", '".$this->db->escape(
getDolGlobalString(
'COMMANDE_SUPPLIER_ADDON_PDF')).
"'";
1618 $sql .=
", ".($this->mode_reglement_id > 0 ? $this->mode_reglement_id :
'null');
1619 $sql .=
", ".($this->cond_reglement_id > 0 ? $this->cond_reglement_id :
'null');
1620 $sql .=
", ".($this->fk_account > 0 ? $this->fk_account :
'NULL');
1621 $sql .=
", ".(int) $this->fk_incoterms;
1622 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
1623 $sql .=
", ".(int) $this->fk_multicurrency;
1624 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1625 $sql .=
", ".(float) $this->multicurrency_tx;
1628 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1629 if ($this->db->query($sql)) {
1630 $this->
id = $this->db->last_insert_id($this->db->prefix().
"commande_fournisseur");
1633 $num = count($this->lines);
1636 for ($i = 0; $i < $num; $i++) {
1637 $line = $this->lines[$i];
1638 if (!is_object($line)) {
1639 $line = (object) $line;
1650 $line->localtax1_tx,
1651 $line->localtax2_tx,
1655 $line->remise_percent,
1658 $line->product_type,
1663 $line->array_options,
1665 $line->multicurrency_subprice,
1672 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
1673 $this->db->rollback();
1678 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1679 $sql .=
" SET ref='(PROV".$this->id.
")'";
1680 $sql .=
" WHERE rowid=".((int) $this->
id);
1682 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1683 if ($this->db->query($sql)) {
1686 $this->
ref =
"(PROV".$this->id.
")";
1688 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
1689 $this->linked_objects = $this->linkedObjectsIds;
1693 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
1694 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
1695 if (is_array($tmp_origin_id)) {
1696 foreach ($tmp_origin_id as $origin_id) {
1704 $origin_id = $tmp_origin_id;
1722 if (!$error && !$notrigger) {
1724 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CREATE', $user);
1726 $this->db->rollback();
1733 $this->db->commit();
1736 $this->error = $this->db->lasterror();
1737 $this->db->rollback();
1742 $this->error =
'Failed to get ID of inserted line';
1747 $this->error = $this->db->lasterror();
1748 $this->db->rollback();
1768 if (isset($this->
ref)) {
1769 $this->
ref = trim($this->
ref);
1771 if (isset($this->ref_supplier)) {
1772 $this->ref_supplier = trim($this->ref_supplier);
1774 if (isset($this->note_private)) {
1775 $this->note_private = trim($this->note_private);
1777 if (isset($this->note_public)) {
1778 $this->note_public = trim($this->note_public);
1780 if (isset($this->model_pdf)) {
1781 $this->model_pdf = trim($this->model_pdf);
1783 if (isset($this->import_key)) {
1784 $this->import_key = trim($this->import_key);
1788 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
1790 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1791 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
1792 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1793 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
1794 $sql .=
" date_commande=".(strval($this->date_commande) !=
'' ?
"'".$this->db->idate($this->date_commande).
"'" :
'null').
",";
1795 $sql .=
" date_valid=".(strval($this->date_validation) !=
'' ?
"'".$this->db->idate($this->date_validation).
"'" :
'null').
",";
1796 $sql .=
" total_tva=".(isset($this->total_tva) ? $this->total_tva :
"null").
",";
1797 $sql .=
" localtax1=".(isset($this->total_localtax1) ? $this->total_localtax1 :
"null").
",";
1798 $sql .=
" localtax2=".(isset($this->total_localtax2) ? $this->total_localtax2 :
"null").
",";
1799 $sql .=
" total_ht=".(isset($this->total_ht) ? $this->total_ht :
"null").
",";
1800 $sql .=
" total_ttc=".(isset($this->total_ttc) ? $this->total_ttc :
"null").
",";
1801 $sql .=
" fk_statut=".(isset($this->statut) ? $this->statut :
"null").
",";
1802 $sql .=
" fk_user_author=".(isset($this->user_author_id) ? $this->user_author_id :
"null").
",";
1803 $sql .=
" fk_user_valid=".(isset($this->user_validation_id) && $this->user_validation_id > 0 ? $this->user_validation_id :
"null").
",";
1804 $sql .=
" fk_projet=".(isset($this->fk_project) ? $this->fk_project :
"null").
",";
1805 $sql .=
" fk_cond_reglement=".(isset($this->cond_reglement_id) ? $this->cond_reglement_id :
"null").
",";
1806 $sql .=
" fk_mode_reglement=".(isset($this->mode_reglement_id) ? $this->mode_reglement_id :
"null").
",";
1807 $sql .=
" date_livraison=".(strval($this->delivery_date) !=
'' ?
"'".$this->db->idate($this->delivery_date).
"'" :
'null').
",";
1809 $sql .=
" fk_account=".($this->fk_account > 0 ? $this->fk_account :
"null").
",";
1811 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1812 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1813 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1814 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
1816 $sql .=
" WHERE rowid=".((int) $this->
id);
1820 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1821 $resql = $this->db->query($sql);
1824 $this->errors[] =
"Error ".$this->db->lasterror();
1834 if (!$error && !$notrigger) {
1836 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
1845 foreach ($this->errors as $errmsg) {
1846 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1847 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1849 $this->db->rollback();
1852 $this->db->commit();
1867 global $conf, $user, $hookmanager;
1874 foreach ($this->lines as $line) {
1875 $line->fetch_optionals();
1879 $objFrom = clone $this;
1882 if (!empty($socid) && $socid != $this->socid) {
1883 $objsoc =
new Societe($this->db);
1885 if ($objsoc->fetch($socid) > 0) {
1886 $this->socid = $objsoc->id;
1887 $this->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1888 $this->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1889 $this->fk_project = 0;
1890 $this->fk_delivery_address = 0;
1900 $this->user_author_id = $user->id;
1901 $this->user_validation_id = 0;
1904 $this->date_creation = 0;
1905 $this->date_validation = 0;
1906 $this->date_commande = 0;
1907 $this->ref_supplier =
'';
1908 $this->user_approve_id = 0;
1909 $this->user_approve_id2 = 0;
1910 $this->date_approve = 0;
1911 $this->date_approve2 = 0;
1914 $this->context[
'createfromclone'] =
'createfromclone';
1915 $result = $this->
create($user, $notrigger);
1922 if (is_object($hookmanager)) {
1923 $parameters = array(
'objFrom' => $objFrom);
1925 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1933 unset($this->context[
'createfromclone']);
1937 $this->db->commit();
1940 $this->db->rollback();
1974 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)
1976 global $langs, $mysoc, $conf;
1978 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");
1979 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1981 if ($this->statut == self::STATUS_DRAFT) {
1982 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1991 if (empty($txtva)) {
1997 if (empty($txlocaltax1)) {
2000 if (empty($txlocaltax2)) {
2003 if (empty($remise_percent)) {
2004 $remise_percent = 0;
2007 $remise_percent =
price2num($remise_percent);
2010 $pu_ht_devise =
price2num($pu_ht_devise);
2012 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
2017 if ($price_base_type ==
'HT') {
2022 $desc = trim($desc);
2025 if ($qty < 0 && !$fk_product) {
2026 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Product"));
2032 if ($date_start && $date_end && $date_start > $date_end) {
2033 $langs->load(
"errors");
2034 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
2041 $product_type = $type;
2044 if ($fk_product > 0) {
2047 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);
2049 if ($prod->fetch($fk_product) > 0) {
2050 $product_type = $prod->type;
2051 $label = $prod->label;
2055 $result = $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', (isset($this->fk_soc) ? $this->fk_soc : $this->socid));
2059 if ($result > 0 && ($origin ==
'commande' || $pu ===
'')) {
2060 $pu = $prod->fourn_pu;
2061 $ref_supplier = $prod->ref_supplier;
2063 if ($remise_percent == 0 && $prod->remise_percent != 0) {
2064 $remise_percent = $prod->remise_percent;
2068 $langs->load(
"errors");
2069 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
2070 $this->db->rollback();
2071 dol_syslog(get_class($this).
"::addline we did not found supplier price, so we can't guess unit price");
2076 if ($result == -1) {
2077 $langs->load(
"errors");
2078 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
2079 $this->db->rollback();
2080 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_DEBUG);
2084 $this->error = $prod->error;
2085 $this->db->rollback();
2086 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_ERR);
2090 $this->error = $prod->error;
2091 $this->db->rollback();
2098 $prod =
new Product($this->db);
2099 $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', (empty($this->fk_soc) ? $this->socid : $this->fk_soc));
2101 if ($qty < $prod->packaging) {
2102 $qty = $prod->packaging;
2104 if (!empty($prod->packaging) && (fmod((
float) $qty, $prod->packaging) > 0.000001)) {
2105 $coeff = intval((
float) $qty / $prod->packaging) + 1;
2106 $qty = (float) $prod->packaging * $coeff;
2107 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'mesgs');
2113 if (isModEnabled(
"multicurrency") && $pu_ht_devise > 0) {
2122 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
2123 $vat_src_code = $reg[1];
2124 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
2132 $tabprice =
calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise);
2134 $total_ht = $tabprice[0];
2135 $total_tva = $tabprice[1];
2136 $total_ttc = $tabprice[2];
2137 $total_localtax1 = $tabprice[9];
2138 $total_localtax2 = $tabprice[10];
2139 $pu = $pu_ht = $tabprice[3];
2142 $multicurrency_total_ht = $tabprice[16];
2143 $multicurrency_total_tva = $tabprice[17];
2144 $multicurrency_total_ttc = $tabprice[18];
2145 $pu_ht_devise = $tabprice[19];
2147 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2148 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2152 $rang = $rangmax + 1;
2158 $this->line->context = $this->context;
2160 $this->line->fk_commande = $this->id;
2161 $this->line->label = $label;
2162 $this->line->ref_fourn = $ref_supplier;
2163 $this->line->ref_supplier = $ref_supplier;
2164 $this->line->desc = $desc;
2165 $this->line->qty = $qty;
2166 $this->line->tva_tx = $txtva;
2167 $this->line->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0);
2168 $this->line->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0);
2169 $this->line->localtax1_type = $localtax1_type;
2170 $this->line->localtax2_type = $localtax2_type;
2171 $this->line->fk_product = $fk_product;
2172 $this->line->product_type = $product_type;
2173 $this->line->remise_percent = $remise_percent;
2174 $this->line->subprice = $pu_ht;
2175 $this->line->rang = $rang;
2176 $this->line->info_bits = $info_bits;
2178 $this->line->vat_src_code = $vat_src_code;
2179 $this->line->total_ht = $total_ht;
2180 $this->line->total_tva = $total_tva;
2181 $this->line->total_localtax1 = $total_localtax1;
2182 $this->line->total_localtax2 = $total_localtax2;
2183 $this->line->total_ttc = $total_ttc;
2184 $this->line->product_type = $type;
2185 $this->line->special_code = (!empty($special_code) ? $special_code : 0);
2186 $this->line->origin = $origin;
2187 $this->line->origin_id = $origin_id;
2188 $this->line->fk_unit = $fk_unit;
2190 $this->line->date_start = $date_start;
2191 $this->line->date_end = $date_end;
2194 $this->line->fk_multicurrency = $this->fk_multicurrency;
2195 $this->line->multicurrency_code = $this->multicurrency_code;
2196 $this->line->multicurrency_subprice = $pu_ht_devise;
2197 $this->line->multicurrency_total_ht = $multicurrency_total_ht;
2198 $this->line->multicurrency_total_tva = $multicurrency_total_tva;
2199 $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
2201 $this->line->subprice = $pu_ht;
2202 $this->line->price = $this->line->subprice;
2204 $this->line->remise_percent = $remise_percent;
2206 if (is_array($array_options) && count($array_options) > 0) {
2207 $this->line->array_options = $array_options;
2210 $result = $this->line->insert($notrigger);
2213 if (!empty($this->line->fk_parent_line)) {
2215 } elseif ($rang > 0 && $rang <= count($this->lines)) {
2216 $linecount = count($this->lines);
2217 for ($ii = $rang; $ii <= $linecount; $ii++) {
2223 $result = $this->
update_price(1,
'auto', 0, $this->thirdparty);
2225 $this->db->commit();
2226 return $this->line->id;
2228 $this->db->rollback();
2232 $this->error = $this->line->error;
2233 $this->errors = $this->line->errors;
2234 dol_syslog(get_class($this).
"::addline error=".$this->error, LOG_ERR);
2235 $this->db->rollback();
2260 public function dispatchProduct($user, $product, $qty, $entrepot, $price = 0, $comment =
'', $eatby =
'', $sellby =
'', $batch =
'', $fk_commandefourndet = 0, $notrigger = 0, $fk_reception = 0)
2262 global $conf, $langs;
2265 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2268 if ($entrepot <= 0) {
2269 $this->error =
'ErrorBadValueForParameterWarehouse';
2273 $this->error =
'ErrorBadValueForParameterQty';
2277 $dispatchstatus = 1;
2279 $dispatchstatus = 0;
2286 if (($this->statut == self::STATUS_ORDERSENT || $this->statut == self::STATUS_RECEIVED_PARTIALLY || $this->statut == self::STATUS_RECEIVED_COMPLETELY)) {
2289 $sql =
"INSERT INTO ".$this->db->prefix().
"receptiondet_batch";
2290 $sql .=
" (fk_element, fk_product, qty, fk_entrepot, fk_user, datec, fk_elementdet, status, comment, eatby, sellby, batch, fk_reception) VALUES";
2291 $sql .=
" ('".$this->id.
"','".$product.
"','".$qty.
"',".($entrepot > 0 ?
"'".$entrepot.
"'" :
"null").
",'".$user->id.
"','".$this->db->idate($now).
"','".$fk_commandefourndet.
"', ".$dispatchstatus.
", '".$this->db->escape($comment).
"', ";
2292 $sql .= ($eatby ?
"'".$this->db->idate($eatby).
"'" :
"null").
", ".($sellby ?
"'".$this->db->idate($sellby).
"'" :
"null").
", ".($batch ?
"'".$this->db->escape($batch).
"'" :
"null").
", ".($fk_reception > 0 ?
"'".$this->db->escape($fk_reception).
"'" :
"null");
2295 dol_syslog(get_class($this).
"::dispatchProduct", LOG_DEBUG);
2296 $resql = $this->db->query($sql);
2299 global $conf, $langs, $user;
2301 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_DISPATCH', $user);
2308 $this->error = $this->db->lasterror();
2313 if (!$error && $entrepot > 0 && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER')) {
2317 $mouv->origin = &$this;
2318 $mouv->setOrigin($this->element, $this->
id);
2321 if (
getDolGlobalString(
'SUPPLIER_ORDER_ALLOW_NEGATIVE_QTY_FOR_SUPPLIER_ORDER_RETURN') && $qty < 0) {
2322 $result = $mouv->livraison($user, $product, $entrepot, $qty * (-1), $price, $comment, $now, $eatby, $sellby, $batch, 0, $inventorycode);
2324 $result = $mouv->reception($user, $product, $entrepot, $qty, $price, $comment, $eatby, $sellby, $batch,
'', 0, $inventorycode);
2328 $this->error = $mouv->error;
2329 $this->errors = $mouv->errors;
2330 dol_syslog(get_class($this).
"::dispatchProduct ".$this->error.
" ".implode(
',', $this->errors), LOG_ERR);
2337 $this->db->commit();
2340 $this->db->rollback();
2344 $this->error =
'BadStatusForObject';
2360 if ($this->statut == 0) {
2363 if ($line->fetch($idline) <= 0) {
2369 foreach ($dispatchedLines as $dispatchLine) {
2370 if ($dispatchLine[
'orderlineid'] == $idline) {
2371 $this->error =
"LineAlreadyDispatched";
2372 $this->errors[] = $this->error;
2377 if ($line->delete($user, $notrigger) > 0) {
2396 public function delete(
User $user, $notrigger = 0)
2398 global $langs, $conf;
2399 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2405 if (empty($notrigger)) {
2407 $result = $this->
call_trigger(
'ORDER_SUPPLIER_DELETE', $user);
2409 $this->errors[] =
'ErrorWhenRunningTrigger';
2410 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2411 $this->db->rollback();
2419 if (!empty($this->linkedObjects) && array_key_exists(
'reception', $this->linkedObjects)) {
2420 foreach ($this->linkedObjects[
'reception'] as $element) {
2421 if ($element->statut >= 0) {
2422 $this->errors[] = $langs->trans(
'ReceptionExist');
2429 $main = $this->db->prefix().
'commande_fournisseurdet';
2430 $ef = $main.
"_extrafields";
2431 $sql =
"DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_commande = ".((int) $this->
id).
")";
2432 dol_syslog(get_class($this).
"::delete extrafields lines", LOG_DEBUG);
2433 if (!$this->db->query($sql)) {
2434 $this->error = $this->db->lasterror();
2435 $this->errors[] = $this->db->lasterror();
2439 $sql =
"DELETE FROM ".$this->db->prefix().
"commande_fournisseurdet WHERE fk_commande =".((int) $this->
id);
2440 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2441 if (!$this->db->query($sql)) {
2442 $this->error = $this->db->lasterror();
2443 $this->errors[] = $this->db->lasterror();
2447 $sql =
"DELETE FROM ".$this->db->prefix().
"commande_fournisseur WHERE rowid =".((int) $this->
id);
2448 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2449 if ($resql = $this->db->query($sql)) {
2450 if ($this->db->affected_rows($resql) < 1) {
2451 $this->error = $this->db->lasterror();
2452 $this->errors[] = $this->db->lasterror();
2456 $this->error = $this->db->lasterror();
2457 $this->errors[] = $this->db->lasterror();
2465 $this->error =
'FailToDeleteExtraFields';
2466 $this->errors[] =
'FailToDeleteExtraFields';
2468 dol_syslog(get_class($this).
"::delete error -4 ".$this->error, LOG_ERR);
2475 $this->error =
'FailToDeleteObjectLinked';
2476 $this->errors[] =
'FailToDeleteObjectLinked';
2487 if ($conf->fournisseur->commande->dir_output) {
2488 $dir = $conf->fournisseur->commande->dir_output.
"/".$ref;
2489 $file = $dir.
"/".$ref.
".pdf";
2490 if (file_exists($file)) {
2492 $this->error =
'ErrorFailToDeleteFile';
2493 $this->errors[] =
'ErrorFailToDeleteFile';
2497 if (file_exists($dir)) {
2500 $this->error =
'ErrorFailToDeleteDir';
2501 $this->errors[] =
'ErrorFailToDeleteDir';
2509 dol_syslog(get_class($this).
"::delete $this->id by $user->id", LOG_DEBUG);
2510 $this->db->commit();
2513 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2514 $this->db->rollback();
2533 $sql =
"SELECT p.ref, p.label,";
2534 $sql .=
" e.rowid as warehouse_id, e.ref as entrepot,";
2535 $sql .=
" cfd.rowid as dispatchedlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status, cfd.fk_elementdet";
2536 $sql .=
" FROM ".$this->db->prefix().
"product as p,";
2537 $sql .=
" ".$this->db->prefix().
"receptiondet_batch as cfd";
2538 $sql .=
" LEFT JOIN ".$this->db->prefix().
"entrepot as e ON cfd.fk_entrepot = e.rowid";
2539 $sql .=
" WHERE cfd.fk_element = ".((int) $this->
id);
2540 $sql .=
" AND cfd.fk_product = p.rowid";
2542 $sql .=
" AND cfd.status = ".((int) $status);
2544 $sql .=
" ORDER BY cfd.rowid ASC";
2546 $resql = $this->db->query($sql);
2548 $num = $this->db->num_rows($resql);
2552 $objp = $this->db->fetch_object($resql);
2555 'id' => $objp->dispatchedlineid,
2556 'productid' => $objp->fk_product,
2557 'warehouseid' => $objp->warehouse_id,
2558 'qty' => $objp->qty,
2559 'orderlineid' => $objp->fk_elementdet
2566 dol_print_error($this->db,
'Failed to execute request to get dispatched lines');
2585 global $conf, $langs;
2592 $usercanreceive = 0;
2593 if (!isModEnabled(
'reception')) {
2594 $usercanreceive = $user->hasRight(
"fournisseur",
"commande",
"receptionner");
2596 $usercanreceive = $user->hasRight(
"reception",
"creer");
2599 if ($usercanreceive) {
2601 if ($type ==
'par') {
2603 } elseif ($type ==
'tot') {
2605 } elseif ($type ==
'nev') {
2607 } elseif ($type ==
'can') {
2611 dol_syslog(get_class($this).
"::Livraison Error -2", LOG_ERR);
2618 if (!$error && ($type ==
'tot')) {
2620 if (count($dispatchedlinearray) > 0) {
2623 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove';
2624 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove', LOG_DEBUG);
2627 if (!$error &&
getDolGlobalString(
'SUPPLIER_ORDER_USE_DISPATCH_STATUS_NEED_APPROVE') && ($type ==
'tot')) {
2629 if (count($dispatchedlinearray) > 0) {
2632 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied';
2633 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied', LOG_DEBUG);
2640 if (empty($error)) {
2643 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2644 $sql .=
" SET fk_statut = ".((int) $statut);
2645 $sql .=
" WHERE rowid = ".((int) $this->
id);
2646 $sql .=
" AND fk_statut IN (".self::STATUS_ORDERSENT.
",".self::STATUS_RECEIVED_PARTIALLY.
")";
2648 dol_syslog(get_class($this).
"::Livraison", LOG_DEBUG);
2649 $resql = $this->db->query($sql);
2652 $old_statut = $this->statut;
2653 $this->statut = $statut;
2654 $this->context[
'actionmsg2'] = $comment;
2657 $result_trigger = $this->
call_trigger(
'ORDER_SUPPLIER_RECEIVE', $user);
2658 if ($result_trigger < 0) {
2663 if (empty($error)) {
2664 $this->db->commit();
2666 $this->statut = $old_statut;
2667 $this->db->rollback();
2668 $this->error = $this->db->lasterror();
2672 $this->db->rollback();
2673 $this->error = $this->db->lasterror();
2678 $this->error = $langs->trans(
'NotAuthorized');
2679 $this->errors[] = $langs->trans(
'NotAuthorized');
2680 dol_syslog(get_class($this).
"::Livraison Not Authorized");
2712 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
2717 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2718 $sql .=
" SET date_livraison = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2719 $sql .=
" WHERE rowid = ".((int) $this->
id);
2722 $resql = $this->db->query($sql);
2724 $this->errors[] = $this->db->error();
2729 $this->oldcopy = clone $this;
2730 $this->delivery_date = $delivery_date;
2733 if (!$notrigger && empty($error)) {
2735 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2743 $this->db->commit();
2746 foreach ($this->errors as $errmsg) {
2747 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2748 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2750 $this->db->rollback();
2770 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
2775 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2776 $sql .=
" SET fk_projet = ".($id_projet > 0 ? (int) $id_projet :
'null');
2777 $sql .=
" WHERE rowid = ".((int) $this->
id);
2780 $resql = $this->db->query($sql);
2782 $this->errors[] = $this->db->error();
2787 $this->oldcopy = clone $this;
2788 $this->fk_projet = $id_projet;
2789 $this->fk_project = $id_projet;
2792 if (!$notrigger && empty($error)) {
2794 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2802 $this->db->commit();
2805 foreach ($this->errors as $errmsg) {
2806 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2807 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2809 $this->db->rollback();
2827 $comclient =
new Commande($this->db);
2828 $comclient->fetch($comclientid);
2832 $this->lines = array();
2834 $num = count($comclient->lines);
2835 for ($i = 0; $i < $num; $i++) {
2836 $prod =
new Product($this->db);
2839 if ($prod->fetch($comclient->lines[$i]->fk_product) > 0) {
2840 $label = $prod->label;
2844 $sql =
"INSERT INTO ".$this->db->prefix().
"commande_fournisseurdet";
2845 $sql .=
" (fk_commande, label, description, fk_product, price, qty, tva_tx, localtax1_tx, localtax2_tx, remise_percent, subprice, remise, ref)";
2846 $sql .=
" VALUES (".((int) $idc).
", '".$this->db->escape($label).
"', '".$this->db->escape($comclient->lines[$i]->desc).
"'";
2847 $sql .=
",".$comclient->lines[$i]->fk_product.
", ".
price2num($comclient->lines[$i]->price,
'MU');
2848 $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);
2849 $sql .=
", '".price2num($comclient->lines[$i]->subprice,
'MT').
"','0', '".$this->db->escape($ref).
"');";
2850 if ($this->db->query($sql)) {
2867 global $conf, $langs;
2872 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur';
2873 $sql .=
" SET fk_statut = ".$status;
2874 $sql .=
" WHERE rowid = ".((int) $this->
id);
2876 dol_syslog(get_class($this).
"::setStatus", LOG_DEBUG);
2877 $resql = $this->db->query($sql);
2880 $triggerName = array();
2881 $triggerName[0] =
'DRAFT';
2882 $triggerName[1] =
'VALIDATED';
2883 $triggerName[2] =
'APPROVED';
2884 $triggerName[3] =
'ORDERED';
2885 $triggerName[4] =
'RECEIVED_PARTIALLY';
2886 $triggerName[5] =
'RECEIVED_COMPLETELY';
2887 $triggerName[6] =
'CANCELED';
2888 $triggerName[7] =
'CANCELED';
2889 $triggerName[9] =
'REFUSED';
2892 $result = $this->
call_trigger(
"ORDER_SUPPLIER_STATUS_".$triggerName[$status], $user);
2899 $this->error = $this->db->lasterror();
2900 dol_syslog(get_class($this).
"::setStatus ".$this->error);
2904 $this->statut = $status;
2905 $this->db->commit();
2908 $this->db->rollback();
2936 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 =
'')
2938 global $mysoc, $conf, $langs;
2939 dol_syslog(get_class($this).
"::updateline $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $type, $fk_unit");
2940 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2944 if ($this->statut == self::STATUS_DRAFT) {
2949 if (empty($info_bits)) {
2952 if (empty($txtva)) {
2955 if (empty($txlocaltax1)) {
2958 if (empty($txlocaltax2)) {
2961 if (empty($remise_percent)) {
2962 $remise_percent = 0;
2965 $remise_percent = (float)
price2num($remise_percent);
2971 $pu_ht_devise =
price2num($pu_ht_devise);
2972 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
2975 $txlocaltax1 = (float)
price2num($txlocaltax1);
2976 $txlocaltax2 = (float)
price2num($txlocaltax2);
2982 if ($date_start && $date_end && $date_start > $date_end) {
2983 $langs->load(
"errors");
2984 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
3000 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
3001 $vat_src_code = $reg[1];
3002 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
3005 $tabprice =
calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise);
3006 $total_ht = $tabprice[0];
3007 $total_tva = $tabprice[1];
3008 $total_ttc = $tabprice[2];
3009 $total_localtax1 = $tabprice[9];
3010 $total_localtax2 = $tabprice[10];
3011 $pu_ht = $tabprice[3];
3012 $pu_tva = $tabprice[4];
3013 $pu_ttc = $tabprice[5];
3016 $multicurrency_total_ht = $tabprice[16];
3017 $multicurrency_total_tva = $tabprice[17];
3018 $multicurrency_total_ttc = $tabprice[18];
3019 $pu_ht_devise = $tabprice[19];
3021 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
3022 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
3026 $this->line->fetch($rowid);
3028 $oldline = clone $this->line;
3029 $this->line->oldline = $oldline;
3031 $this->line->context = $this->context;
3033 $this->line->fk_commande = $this->id;
3035 $this->line->desc = $desc;
3039 if ($qty < $this->line->packaging) {
3040 $qty = $this->line->packaging;
3042 if (!empty($this->line->packaging) && ($qty % $this->line->packaging) > 0) {
3043 $coeff = intval($qty / $this->line->packaging) + 1;
3044 $qty = $this->line->packaging * $coeff;
3045 setEventMessage($langs->trans(
'QtyRecalculatedWithPackaging'),
'mesgs');
3050 $this->line->qty = $qty;
3051 $this->line->ref_supplier = $ref_supplier;
3053 $this->line->vat_src_code = $vat_src_code;
3054 $this->line->tva_tx = $txtva;
3055 $this->line->localtax1_tx = $txlocaltax1;
3056 $this->line->localtax2_tx = $txlocaltax2;
3057 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
3058 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
3059 $this->line->remise_percent = $remise_percent;
3060 $this->line->subprice = $pu_ht;
3061 $this->line->info_bits = $info_bits;
3062 $this->line->total_ht = $total_ht;
3063 $this->line->total_tva = $total_tva;
3064 $this->line->total_localtax1 = $total_localtax1;
3065 $this->line->total_localtax2 = $total_localtax2;
3066 $this->line->total_ttc = $total_ttc;
3067 $this->line->product_type = $type;
3068 $this->line->special_code = $oldline->special_code;
3069 $this->line->rang = $oldline->rang;
3070 $this->line->origin = $this->origin;
3071 $this->line->fk_unit = $fk_unit;
3073 $this->line->date_start = $date_start;
3074 $this->line->date_end = $date_end;
3077 $this->line->fk_multicurrency = $this->fk_multicurrency;
3078 $this->line->multicurrency_code = $this->multicurrency_code;
3079 $this->line->multicurrency_subprice = $pu_ht_devise;
3080 $this->line->multicurrency_total_ht = $multicurrency_total_ht;
3081 $this->line->multicurrency_total_tva = $multicurrency_total_tva;
3082 $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
3084 $this->line->subprice = $pu_ht;
3085 $this->line->price = $this->line->subprice;
3087 $this->line->remise_percent = $remise_percent;
3089 if (is_array($array_options) && count($array_options) > 0) {
3091 foreach ($array_options as $key => $value) {
3092 $this->line->array_options[$key] = $array_options[$key];
3096 $result = $this->line->update($notrigger);
3102 $this->db->commit();
3105 $this->error = $this->db->lasterror();
3106 $this->db->rollback();
3110 $this->error =
"Order status makes operation forbidden";
3111 dol_syslog(get_class($this).
"::updateline ".$this->error, LOG_ERR);
3126 global $user, $langs, $conf;
3128 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
3130 dol_syslog(get_class($this).
"::initAsSpecimen");
3137 $sql =
"SELECT rowid";
3138 $sql .=
" FROM ".$this->db->prefix().
"product";
3139 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
3140 $sql .= $this->db->order(
"rowid",
"ASC");
3141 $sql .= $this->db->plimit(1);
3142 $resql = $this->db->query($sql);
3144 $obj = $this->db->fetch_object($resql);
3145 $prodid = $obj->rowid;
3150 $this->
ref =
'SPECIMEN';
3151 $this->specimen = 1;
3154 $this->date_commande = $now;
3155 $this->date_lim_reglement = $this->date + 3600 * 24 * 30;
3156 $this->cond_reglement_code =
'RECEP';
3157 $this->mode_reglement_code =
'CHQ';
3159 $this->note_public =
'This is a comment (public)';
3160 $this->note_private =
'This is a comment (private)';
3162 $this->multicurrency_tx = 1;
3163 $this->multicurrency_code = $conf->currency;
3170 while ($xnbp < $nbp) {
3172 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
3174 $line->subprice = 100;
3175 $line->tva_tx = 19.6;
3176 $line->localtax1_tx = 0;
3177 $line->localtax2_tx = 0;
3179 $line->total_ht = 50;
3180 $line->total_ttc = 59.8;
3181 $line->total_tva = 9.8;
3182 $line->remise_percent = 50;
3184 $line->total_ht = 100;
3185 $line->total_ttc = 119.6;
3186 $line->total_tva = 19.6;
3187 $line->remise_percent = 00;
3189 $line->fk_product = $prodid;
3191 $this->lines[$xnbp] = $line;
3193 $this->total_ht += $line->total_ht;
3194 $this->total_tva += $line->total_tva;
3195 $this->total_ttc += $line->total_ttc;
3211 $sql =
'SELECT c.rowid, date_creation as datec, tms as datem, date_valid as date_validation, date_approve as datea, date_approve2 as datea2,';
3212 $sql .=
' fk_user_author, fk_user_modif, fk_user_valid, fk_user_approve, fk_user_approve2';
3213 $sql .=
' FROM '.$this->db->prefix().
'commande_fournisseur as c';
3214 $sql .=
' WHERE c.rowid = '.((int) $id);
3216 $result = $this->db->query($sql);
3218 if ($this->db->num_rows($result)) {
3219 $obj = $this->db->fetch_object($result);
3221 $this->
id = $obj->rowid;
3223 $this->user_creation_id = $obj->fk_user_author;
3224 $this->user_validation_id = $obj->fk_user_valid;
3225 $this->user_modification_id = $obj->fk_user_modif;
3226 $this->user_approve_id = $obj->fk_user_approve;
3227 $this->user_approve_id2 = $obj->fk_user_approve2;
3229 $this->date_creation = $this->db->jdate($obj->datec);
3230 $this->date_modification = $this->db->jdate($obj->datem);
3231 $this->date_approve = $this->db->jdate($obj->datea);
3232 $this->date_approve2 = $this->db->jdate($obj->datea2);
3233 $this->date_validation = $this->db->jdate($obj->date_validation);
3235 $this->db->free($result);
3248 global $conf, $user;
3250 $this->nb = array();
3253 $sql =
"SELECT count(co.rowid) as nb";
3254 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as co";
3255 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe as s ON co.fk_soc = s.rowid";
3256 if (!$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3257 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
3258 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
3261 $sql .=
" ".$clause.
" co.entity IN (".
getEntity(
'supplier_order').
")";
3263 $resql = $this->db->query($sql);
3265 while ($obj = $this->db->fetch_object($resql)) {
3266 $this->nb[
"supplier_orders"] = $obj->nb;
3268 $this->db->free($resql);
3272 $this->error = $this->db->error();
3288 global $conf, $langs;
3290 $sql =
"SELECT c.rowid, c.date_creation as datec, c.date_commande, c.fk_statut, c.date_livraison as delivery_date, c.total_ht";
3291 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as c";
3292 if (!$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3293 $sql .=
" JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
3295 $sql .=
" WHERE c.entity = ".$conf->entity;
3296 if ($mode ===
'awaiting') {
3297 $sql .=
" AND c.fk_statut IN (".self::STATUS_ORDERSENT.
", ".self::STATUS_RECEIVED_PARTIALLY.
")";
3299 $sql .=
" AND c.fk_statut IN (".self::STATUS_VALIDATED.
", ".self::STATUS_ACCEPTED.
")";
3302 $sql .=
" AND c.fk_soc = ".((int) $user->socid);
3305 $resql = $this->db->query($sql);
3310 $response->warning_delay = $conf->commande->fournisseur->warning_delay / 60 / 60 / 24;
3311 $response->label = $langs->trans(
"SuppliersOrdersToProcess");
3312 $response->labelShort = $langs->trans(
"Opened");
3313 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=1,2&mainmenu=commercial&leftmenu=orders_suppliers';
3314 $response->url_late = DOL_URL_ROOT.
'/fourn/commande/list.php?mainmenu=commercial&leftmenu=orders_suppliers&search_option=late';
3317 if ($mode ===
'awaiting') {
3318 $response->label = $langs->trans(
"SuppliersOrdersAwaitingReception");
3319 $response->labelShort = $langs->trans(
"AwaitingReception");
3320 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=3,4&mainmenu=commercial&leftmenu=orders_suppliers';
3323 while ($obj = $this->db->fetch_object($resql)) {
3324 $commandestatic->delivery_date = $this->db->jdate($obj->delivery_date);
3325 $commandestatic->date_commande = $this->db->jdate($obj->date_commande);
3326 $commandestatic->statut = $obj->fk_statut;
3328 $response->nbtodo++;
3329 $response->total += $obj->total_ht;
3331 if ($commandestatic->hasDelay()) {
3332 $response->nbtodolate++;
3338 $this->error = $this->db->error();
3353 if ($this->methode_commande_id > 0) {
3354 $sql =
"SELECT rowid, code, libelle as label";
3355 $sql .=
" FROM ".$this->db->prefix().
'c_input_method';
3356 $sql .=
" WHERE active=1 AND rowid = ".((int) $this->methode_commande_id);
3358 $resql = $this->db->query($sql);
3360 if ($this->db->num_rows($resql)) {
3361 $obj = $this->db->fetch_object($resql);
3363 $string = $langs->trans($obj->code);
3364 if ($string == $obj->code) {
3365 $string = $obj->label !=
'-' ? $obj->label :
'';
3388 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3390 global $conf, $langs;
3395 if (!empty($this->model_pdf)) {
3396 $modele = $this->model_pdf;
3402 if (empty($modele)) {
3405 $langs->load(
"suppliers");
3406 $outputlangs->load(
"products");
3408 $modelpath =
"core/modules/supplier_order/doc/";
3409 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3422 if (empty($this->lines)) {
3429 foreach ($this->lines as $line) {
3430 if ($line->fk_product > 0) {
3432 $idp = $tmpproductfourn->find_min_price_product_fournisseur($line->fk_product, $line->qty, $this->thirdparty->id);
3435 if ($tmpproductfourn->delivery_time_days > $nb) {
3436 $nb = $tmpproductfourn->delivery_time_days;
3445 return $nb.
' '.$langs->trans(
'days');
3457 return $user->hasRight(
"fournisseur",
"commande");
3472 'commande_fournisseur'
3489 'commande_fournisseurdet'
3506 if ($this->statut == self::STATUS_ORDERSENT || $this->statut == self::STATUS_RECEIVED_PARTIALLY) {
3508 if (!empty($this->delivery_date)) {
3509 $date_to_test = $this->delivery_date;
3510 return $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay);
3518 $date_to_test = $this->date_commande;
3520 return ($this->statut > 0 && $this->statut < 5) && $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay);
3533 global $conf, $langs;
3535 $langs->load(
'orders');
3539 if ($this->statut == self::STATUS_ORDERSENT || $this->statut == self::STATUS_RECEIVED_PARTIALLY) {
3540 if (!empty($this->delivery_date)) {
3541 $text = $langs->trans(
"DeliveryDate").
' '.
dol_print_date($this->delivery_date,
'day');
3543 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3546 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3549 $text .=
' '.($conf->commande->fournisseur->warning_delay > 0 ?
'+' :
'-').
' '.round(abs($conf->commande->fournisseur->warning_delay) / 3600 / 24, 1).
' '.$langs->trans(
"days").
' < '.$langs->trans(
"Today");
3566 if (isModEnabled(
"supplier_order")) {
3567 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
3569 $qtydelivered = array();
3570 $qtywished = array();
3574 $filter = array(
't.fk_element' => $this->
id);
3576 $filter[
't.status'] = 1;
3579 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
3581 $this->error = $supplierorderdispatch->error;
3582 $this->errors = $supplierorderdispatch->errors;
3585 if (is_array($supplierorderdispatch->lines) && count($supplierorderdispatch->lines) > 0) {
3586 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
3590 foreach ($supplierorderdispatch->lines as $line) {
3591 $qtydelivered[$line->fk_product] += $line->qty;
3593 foreach ($this->lines as $line) {
3598 $qtywished[$line->fk_product] += $line->qty;
3602 $diff_array = array_diff_assoc($qtydelivered, $qtywished);
3603 $keysinwishednotindelivered = array_diff(array_keys($qtywished), array_keys($qtydelivered));
3604 $keysindeliverednotinwished = array_diff(array_keys($qtydelivered), array_keys($qtywished));
3612 if (count($diff_array) == 0 && count($keysinwishednotindelivered) == 0 && count($keysindeliverednotinwished) == 0) {
3613 if ($closeopenorder) {
3615 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3623 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3634 if (count($diff_array) > 0) {
3638 foreach ($diff_array as $key => $value) {
3640 if ($qtydelivered[$key] >= $qtywished[$key]) {
3647 if ($close == count($diff_array)) {
3649 if ($closeopenorder) {
3650 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3657 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3665 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3673 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3695 $this->receptions = array();
3697 dol_syslog(get_class($this).
"::loadReceptions", LOG_DEBUG);
3699 $sql =
'SELECT cd.rowid, cd.fk_product,';
3700 $sql .=
' sum(cfd.qty) as qty';
3701 $sql .=
' FROM '.$this->db->prefix().
'receptiondet_batch as cfd,';
3702 if ($filtre_statut >= 0) {
3703 $sql .=
' '.$this->db->prefix().
'reception as e,';
3705 $sql .=
' '.$this->db->prefix().
'commande_fournisseurdet as cd';
3707 if ($filtre_statut >= 0) {
3708 $sql .=
' cfd.fk_reception = e.rowid AND';
3710 $sql .=
' cfd.fk_elementdet = cd.rowid';
3711 $sql .=
' AND cd.fk_commande ='.((int) $this->
id);
3712 if (isset($this->fk_product) && !empty($this->fk_product) > 0) {
3713 $sql .=
' AND cd.fk_product = '.((int) $this->fk_product);
3715 if ($filtre_statut >= 0) {
3716 $sql .=
' AND e.fk_statut >= '.((int) $filtre_statut);
3718 $sql .=
' GROUP BY cd.rowid, cd.fk_product';
3720 $resql = $this->db->query($sql);
3722 $num = $this->db->num_rows($resql);
3725 $obj = $this->db->fetch_object($resql);
3726 empty($this->receptions[$obj->rowid]) ? $this->receptions[$obj->rowid] = $obj->qty : $this->receptions[$obj->rowid] += $obj->qty;
3729 $this->db->free($resql);
3733 $this->error = $this->db->lasterror();
3749 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3751 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3752 $return .=
'<div class="info-box info-box-sm">';
3753 $return .=
'<span class="info-box-icon bg-infobox-action">';
3755 $return .=
'</span>';
3756 $return .=
'<div class="info-box-content">';
3757 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
3758 if ($selected >= 0) {
3759 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3761 if (property_exists($this,
'socid') || property_exists($this,
'total_tva')) {
3762 $return .=
'<br><span class="info-box-label amount">'.$this->socid.
'</span>';
3764 if (property_exists($this,
'billed')) {
3765 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Billed").
' : </span><span class="info-box-label">'.
yn($this->billed).
'</span>';
3767 if (method_exists($this,
'getLibStatut')) {
3768 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
3770 $return .=
'</div>';
3771 $return .=
'</div>';
3772 $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.
getNextNumRef($soc)
Returns the next order reference not used, based on the numbering model defined within COMMANDE_SUPPL...
fetch_lines($only_product=0)
Load array lines.
getInputMethod()
Returns the translated input method of object (defined if $this->methode_commande_id > 0).
const STATUS_VALIDATED
Validated status.
const STATUS_RECEIVED_COMPLETELY
Received completely.
addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0.0, $txlocaltax2=0.0, $fk_product=0, $fk_prod_fourn_price=0, $ref_supplier='', $remise_percent=0.0, $price_base_type='HT', $pu_ttc=0.0, $type=0, $info_bits=0, $notrigger=0, $date_start=null, $date_end=null, $array_options=[], $fk_unit=null, $pu_ht_devise=0, $origin='', $origin_id=0, $rang=-1, $special_code=0)
Add order line.
loadStateBoard()
Load the indicators this->nb for the state board.
calcAndSetStatusDispatch(User $user, $closeopenorder=1, $comment='')
Calc status regarding to dispatched stock.
set_id_projet($user, $id_projet, $notrigger=0)
Set the id projet.
const STATUS_DRAFT
Draft status.
showDelay()
Show the customer delayed info.
getTooltipContentArray($params)
getTooltipContentArray
classifyUnBilled(User $user)
Classify not billed.
approve($user, $idwarehouse=0, $secondlevel=0)
Approve a supplier order.
__construct($db)
Constructor.
Cancel($user, $idwarehouse=-1)
Cancel an approved order.
dispatchProduct($user, $product, $qty, $entrepot, $price=0, $comment='', $eatby='', $sellby='', $batch='', $fk_commandefourndet=0, $notrigger=0, $fk_reception=0)
Save a receiving into the tracking table of receiving (receptiondet_batch) and add product into stock...
valid($user, $idwarehouse=0, $notrigger=0)
Validate an order.
create($user, $notrigger=0)
Create order with draft status.
update(User $user, $notrigger=0)
Update Supplier Order.
createFromClone(User $user, $socid=0, $notrigger=0)
Load an object from its id and create a new one in database.
updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $type=0, $notrigger=0, $date_start=0, $date_end=0, $array_options=[], $fk_unit=null, $pu_ht_devise=0, $ref_supplier='')
Update line.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template model.
const STATUS_ACCEPTED
Accepted.
const STATUS_ORDERSENT
Order sent, shipment on process.
commande($user, $date, $methode, $comment='')
Submit a supplier order to supplier.
getRights()
Returns the rights used for this class.
load_board($user, $mode='opened')
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
deleteLine($idline, $notrigger=0)
Delete line.
getMaxDeliveryTimeDay($langs)
Return the max number delivery delay in day.
fetch($id, $ref='')
Get object and lines from database.
Livraison($user, $date, $type, $comment)
Set a delivery in database for this supplier order.
getDispachedLines($status=-1)
Return array of dispatched lines waiting to be approved for this order.
classifyBilled(User $user)
Class invoiced the supplier order.
initAsSpecimen()
Initialise an instance with random values.
const SOURCE_ID_REPLENISHMENT
The constant used into source field to track the order was generated by the replenishement feature.
setStatus($user, $status)
Tag order with a particular status.
const STATUS_REFUSED
Refused.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
getLibStatut($mode=0)
Return label of the status of object.
hasDelay()
Is the supplier order delayed? We suppose a purchase ordered as late if a the purchase order has been...
LibStatut($status, $mode=0, $billed=0)
Return label of a status.
Class to manage line orders.
Class to manage customers orders.
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
line_order($renum=false, $rowidorder='ASC', $fk_parent_line=true)
Save a new position (field rang) for details lines.
deleteEcmFiles($mode=0)
Delete related files of object in database.
update_price($exclspec=0, $roundingadjust='auto', $nodatabaseupdate=0, $seller=null)
Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines).
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
setErrorsFromObject($object)
setErrorsFromObject
updateRangOfLine($rowid, $rang)
Update position of line (rang)
deleteExtraFields()
Delete all extra fields values for the current object.
fetchObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $clause='OR', $alsosametype=1, $orderby='sourcetype', $loadalsoobjects=1)
Fetch array of objects linked to current object (object of enabled modules only).
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
static commonReplaceProduct(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
line_max($fk_parent_line=0)
Get max value used for position of line (rang)
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
call_trigger($triggerName, $user)
Call trigger based on this instance.
add_contact($fk_socpeople, $type_contact, $source='external', $notrigger=0)
Add a link between element $this->element and a contact.
Superclass for orders classes.
Class to manage Dolibarr database access.
Class to manage stock movements.
static getIdFromCode($dbs, $code)
Get id of currency from code.
static getIdAndTxFromCode($dbs, $code, $date_document='')
Get id and rate of currency from code.
Class to manage predefined suppliers products.
Class to manage products or services.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
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_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
getDolGlobalFloat($key, $default=0)
Return a Dolibarr global constant float value.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
setEventMessage($mesgs, $style='mesgs', $noduplicate=0, $attop=0)
Set event message in dol_events session object.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
yn($yesno, $format=1, $color=0)
Return yes or no in current language.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
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.
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='', $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.