39require_once DOL_DOCUMENT_ROOT.
'/core/class/commonorder.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
42if (isModEnabled(
'productbatch')) {
43 require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
55 public $element =
'order_supplier';
60 public $table_element =
'commande_fournisseur';
65 public $table_element_line =
'commande_fournisseurdet';
70 public $fk_element =
'fk_commande';
75 public $picto =
'supplier_order';
81 public $restrictiononfksoc = 1;
101 public $ref_supplier;
139 public $date_creation;
149 public $date_approve;
155 public $date_approve2;
160 public $date_commande;
163 public $remise_percent;
164 public $methode_commande_id;
165 public $methode_commande;
170 public $delivery_date;
185 public $total_localtax1;
190 public $total_localtax2;
207 public $cond_reglement_id;
212 public $cond_reglement_code;
217 public $cond_reglement_label;
222 public $cond_reglement_doc;
232 public $mode_reglement_id;
237 public $mode_reglement_code;
242 public $mode_reglement;
247 public $user_author_id;
252 public $user_approve_id;
258 public $user_approve_id2;
262 public $extraparams = array();
267 public $lines = array();
277 public $linked_objects = array();
282 public $date_lim_reglement;
283 public $receptions = array();
289 public $fk_multicurrency;
294 public $multicurrency_code;
299 public $multicurrency_tx;
304 public $multicurrency_total_ht;
309 public $multicurrency_total_tva;
314 public $multicurrency_total_ttc;
344 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => 0,
'notnull' => 1,
'position' => 10),
345 'ref' => array(
'type' =>
'varchar(255)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => 1,
'showoncombobox' => 1,
'position' => 25,
'searchall' => 1),
346 'ref_ext' => array(
'type' =>
'varchar(255)',
'label' =>
'Ref ext',
'enabled' => 1,
'visible' => 0,
'position' => 35),
347 'ref_supplier' => array(
'type' =>
'varchar(255)',
'label' =>
'RefOrderSupplierShort',
'enabled' => 1,
'visible' => 1,
'position' => 40,
'searchall' => 1),
348 'fk_projet' => array(
'type' =>
'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)',
'label' =>
'Project',
'enabled' =>
"isModEnabled('project')",
'visible' => -1,
'position' => 45),
349 'date_valid' => array(
'type' =>
'datetime',
'label' =>
'DateValidation',
'enabled' => 1,
'visible' => -1,
'position' => 710),
350 'date_approve' => array(
'type' =>
'datetime',
'label' =>
'DateApprove',
'enabled' => 1,
'visible' => -1,
'position' => 720),
351 'date_approve2' => array(
'type' =>
'datetime',
'label' =>
'DateApprove2',
'enabled' => 1,
'visible' => 3,
'position' => 725),
352 'date_commande' => array(
'type' =>
'date',
'label' =>
'OrderDateShort',
'enabled' => 1,
'visible' => 1,
'position' => 70),
353 'date_livraison' => array(
'type' =>
'datetime',
'label' =>
'DeliveryDate',
'enabled' =>
'empty($conf->global->ORDER_DISABLE_DELIVERY_DATE)',
'visible' => 1,
'position' => 74),
354 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'visible' => 3,
'position' => 41),
355 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => 3,
'notnull' => -1,
'position' => 80),
356 'fk_user_valid' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserValidation',
'enabled' => 1,
'visible' => 3,
'position' => 711),
357 'fk_user_approve' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserApproval',
'enabled' => 1,
'visible' => 3,
'position' => 721),
358 'fk_user_approve2' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserApproval2',
'enabled' => 1,
'visible' => 3,
'position' => 726),
359 'source' => array(
'type' =>
'smallint(6)',
'label' =>
'Source',
'enabled' => 1,
'visible' => 3,
'notnull' => 1,
'position' => 100),
360 'billed' => array(
'type' =>
'smallint(6)',
'label' =>
'Billed',
'enabled' => 1,
'visible' => 1,
'position' => 710),
361 'total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'AmountHT',
'enabled' => 1,
'visible' => 1,
'position' => 130,
'isameasure' => 1),
362 'total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'AmountVAT',
'enabled' => 1,
'visible' => 1,
'position' => 135,
'isameasure' => 1),
363 'localtax1' => array(
'type' =>
'double(24,8)',
'label' =>
'LT1',
'enabled' => 1,
'visible' => 3,
'position' => 140,
'isameasure' => 1),
364 'localtax2' => array(
'type' =>
'double(24,8)',
'label' =>
'LT2',
'enabled' => 1,
'visible' => 3,
'position' => 145,
'isameasure' => 1),
365 'total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'AmountTTC',
'enabled' => 1,
'visible' => -1,
'position' => 150,
'isameasure' => 1),
366 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 750,
'searchall' => 1),
367 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 760,
'searchall' => 1),
368 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'ModelPDF',
'enabled' => 1,
'visible' => 0,
'position' => 165),
369 'fk_input_method' => array(
'type' =>
'integer',
'label' =>
'OrderMode',
'enabled' => 1,
'visible' => 3,
'position' => 170),
370 'fk_cond_reglement' => array(
'type' =>
'integer',
'label' =>
'PaymentTerm',
'enabled' => 1,
'visible' => 3,
'position' => 175),
371 'fk_mode_reglement' => array(
'type' =>
'integer',
'label' =>
'PaymentMode',
'enabled' => 1,
'visible' => 3,
'position' => 180),
372 'extraparams' => array(
'type' =>
'varchar(255)',
'label' =>
'Extraparams',
'enabled' => 1,
'visible' => 0,
'position' => 190),
373 'fk_account' => array(
'type' =>
'integer',
'label' =>
'BankAccount',
'enabled' =>
'isModEnabled("bank")',
'visible' => 3,
'position' => 200),
374 'fk_incoterms' => array(
'type' =>
'integer',
'label' =>
'IncotermCode',
'enabled' => 1,
'visible' => 3,
'position' => 205),
375 'location_incoterms' => array(
'type' =>
'varchar(255)',
'label' =>
'IncotermLocation',
'enabled' => 1,
'visible' => 3,
'position' => 210),
376 'fk_multicurrency' => array(
'type' =>
'integer',
'label' =>
'Fk multicurrency',
'enabled' => 1,
'visible' => 0,
'position' => 215),
377 'multicurrency_code' => array(
'type' =>
'varchar(255)',
'label' =>
'Currency',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 220),
378 'multicurrency_tx' => array(
'type' =>
'double(24,8)',
'label' =>
'CurrencyRate',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 225),
379 'multicurrency_total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountHT',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 230),
380 'multicurrency_total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountVAT',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 235),
381 'multicurrency_total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountTTC',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 240),
382 'date_creation' => array(
'type' =>
'datetime',
'label' =>
'Date creation',
'enabled' => 1,
'visible' => -1,
'position' => 500),
383 'fk_soc' => array(
'type' =>
'integer:Societe:societe/class/societe.class.php',
'label' =>
'ThirdParty',
'enabled' =>
'isModEnabled("societe")',
'visible' => 1,
'notnull' => 1,
'position' => 50),
384 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => 0,
'notnull' => 1,
'position' => 1000,
'index' => 1),
385 'tms' => array(
'type' =>
'datetime',
'label' =>
"DateModificationShort",
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 501),
386 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'LastMainDoc',
'enabled' => 1,
'visible' => 0,
'position' => 700),
387 'fk_statut' => array(
'type' =>
'smallint(6)',
'label' =>
'Status',
'enabled' => 1,
'visible' => 1,
'position' => 701),
388 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => 0,
'position' => 900),
452 $this->ismultientitymanaged = 1;
463 public function fetch($id, $ref =
'')
466 if (empty($id) && empty($ref)) {
470 $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,";
471 $sql .=
" c.localtax1, c.localtax2, ";
472 $sql .=
" c.date_creation, c.date_valid, c.date_approve, c.date_approve2,";
473 $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,";
474 $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,";
475 $sql .=
" c.fk_account,";
476 $sql .=
" c.note_private, c.note_public, c.model_pdf, c.extraparams, c.billed,";
477 $sql .=
" c.fk_multicurrency, c.multicurrency_code, c.multicurrency_tx, c.multicurrency_total_ht, c.multicurrency_total_tva, c.multicurrency_total_ttc,";
478 $sql .=
" cm.libelle as methode_commande,";
479 $sql .=
" cr.code as cond_reglement_code, cr.libelle as cond_reglement_label, cr.libelle_facture as cond_reglement_doc,";
480 $sql .=
" p.code as mode_reglement_code, p.libelle as mode_reglement_libelle";
481 $sql .=
', c.fk_incoterms, c.location_incoterms';
482 $sql .=
', i.libelle as label_incoterms';
483 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as c";
484 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_payment_term as cr ON c.fk_cond_reglement = cr.rowid";
485 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_paiement as p ON c.fk_mode_reglement = p.id";
486 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_input_method as cm ON cm.rowid = c.fk_input_method";
487 $sql .=
' LEFT JOIN '.$this->db->prefix().
'c_incoterms as i ON c.fk_incoterms = i.rowid';
490 $sql .=
" WHERE c.entity IN (".getEntity(
'supplier_order').
")";
492 $sql .=
" WHERE c.rowid=".((int) $id);
496 $sql .=
" AND c.ref='".$this->db->escape($ref).
"'";
499 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
500 $resql = $this->db->query($sql);
502 $obj = $this->db->fetch_object($resql);
504 $this->error =
'Bill with id '.$id.
' not found';
505 dol_syslog(get_class($this).
'::fetch '.$this->error);
509 $this->
id = $obj->rowid;
510 $this->entity = $obj->entity;
512 $this->
ref = $obj->ref;
513 $this->ref_supplier = $obj->ref_supplier;
514 $this->socid = $obj->fk_soc;
515 $this->fourn_id = $obj->fk_soc;
516 $this->
statut = $obj->status;
517 $this->
status = $obj->status;
518 $this->billed = $obj->billed;
519 $this->user_author_id = $obj->user_author_id;
520 $this->user_validation_id = $obj->user_validation_id;
521 $this->user_approve_id = $obj->user_approve_id;
522 $this->user_approve_id2 = $obj->user_approve_id2;
523 $this->total_ht = $obj->total_ht;
524 $this->total_tva = $obj->total_tva;
525 $this->total_localtax1 = $obj->localtax1;
526 $this->total_localtax2 = $obj->localtax2;
527 $this->total_ttc = $obj->total_ttc;
528 $this->date_creation = $this->db->jdate($obj->date_creation);
529 $this->date_valid = $this->db->jdate($obj->date_valid);
530 $this->date_approve = $this->db->jdate($obj->date_approve);
531 $this->date_approve2 = $this->db->jdate($obj->date_approve2);
532 $this->date_commande = $this->db->jdate($obj->date_commande);
533 if (isset($obj->date_commande)) {
534 $this->date = $this->date_commande;
536 $this->date = $this->date_creation;
538 $this->delivery_date = $this->db->jdate($obj->delivery_date);
539 $this->remise_percent = $obj->remise_percent;
540 $this->methode_commande_id = $obj->fk_input_method;
541 $this->methode_commande = $obj->methode_commande;
543 $this->source = $obj->source;
544 $this->fk_project = $obj->fk_project;
545 $this->cond_reglement_id = $obj->fk_cond_reglement;
546 $this->cond_reglement_code = $obj->cond_reglement_code;
547 $this->cond_reglement = $obj->cond_reglement_label;
548 $this->cond_reglement_label = $obj->cond_reglement_label;
549 $this->cond_reglement_doc = $obj->cond_reglement_doc;
550 $this->fk_account = $obj->fk_account;
551 $this->mode_reglement_id = $obj->fk_mode_reglement;
552 $this->mode_reglement_code = $obj->mode_reglement_code;
553 $this->mode_reglement = $obj->mode_reglement_libelle;
554 $this->note = $obj->note_private;
555 $this->note_private = $obj->note_private;
556 $this->note_public = $obj->note_public;
557 $this->model_pdf = $obj->model_pdf;
560 $this->fk_incoterms = $obj->fk_incoterms;
561 $this->location_incoterms = $obj->location_incoterms;
562 $this->label_incoterms = $obj->label_incoterms;
565 $this->fk_multicurrency = $obj->fk_multicurrency;
566 $this->multicurrency_code = $obj->multicurrency_code;
567 $this->multicurrency_tx = $obj->multicurrency_tx;
568 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
569 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
570 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
572 $this->extraparams = isset($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
574 $this->db->free($resql);
589 $this->error = $this->db->error().
" sql=".$sql;
605 $this->lines = array();
607 $sql =
"SELECT l.rowid, l.fk_commande, l.ref as ref_supplier, l.fk_product, l.product_type, l.label, l.description, l.qty,";
608 $sql .=
" l.vat_src_code, l.tva_tx, l.remise_percent, l.subprice,";
609 $sql .=
" l.localtax1_tx, l. localtax2_tx, l.localtax1_type, l. localtax2_type, l.total_localtax1, l.total_localtax2,";
610 $sql .=
" l.total_ht, l.total_tva, l.total_ttc, l.info_bits, l.special_code, l.fk_parent_line, l.rang,";
611 $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,";
612 $sql .=
" l.fk_unit,";
613 $sql .=
" l.date_start, l.date_end,";
614 $sql .=
' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc';
615 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseurdet as l";
616 $sql .=
' LEFT JOIN '.$this->db->prefix().
'product as p ON l.fk_product = p.rowid';
617 $sql .=
" WHERE l.fk_commande = ".((int) $this->
id);
619 $sql .=
' AND p.fk_product_type = 0';
621 $sql .=
" ORDER BY l.rang, l.rowid";
624 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
626 $result = $this->db->query($sql);
628 $num = $this->db->num_rows($result);
632 $objp = $this->db->fetch_object($result);
636 $line->id = $objp->rowid;
637 $line->fk_commande = $objp->fk_commande;
638 $line->desc = $objp->description;
639 $line->description = $objp->description;
640 $line->qty = $objp->qty;
641 $line->tva_tx = $objp->tva_tx;
642 $line->localtax1_tx = $objp->localtax1_tx;
643 $line->localtax2_tx = $objp->localtax2_tx;
644 $line->localtax1_type = $objp->localtax1_type;
645 $line->localtax2_type = $objp->localtax2_type;
646 $line->subprice = $objp->subprice;
647 $line->pu_ht = $objp->subprice;
648 $line->remise_percent = $objp->remise_percent;
650 $line->vat_src_code = $objp->vat_src_code;
651 $line->total_ht = $objp->total_ht;
652 $line->total_tva = $objp->total_tva;
653 $line->total_localtax1 = $objp->total_localtax1;
654 $line->total_localtax2 = $objp->total_localtax2;
655 $line->total_ttc = $objp->total_ttc;
656 $line->product_type = $objp->product_type;
658 $line->fk_product = $objp->fk_product;
660 $line->libelle = $objp->product_label;
661 $line->product_label = $objp->product_label;
662 $line->product_desc = $objp->product_desc;
663 $line->product_tobatch = $objp->product_tobatch;
664 $line->product_barcode = $objp->product_barcode;
666 $line->ref = $objp->product_ref;
667 $line->product_ref = $objp->product_ref;
668 $line->ref_fourn = $objp->ref_supplier;
669 $line->ref_supplier = $objp->ref_supplier;
676 $sqlsearchpackage =
'SELECT rowid, packaging FROM '.$this->db->prefix().
"product_fournisseur_price";
677 $sqlsearchpackage .=
' WHERE entity IN ('.getEntity(
'product_fournisseur_price').
")";
678 $sqlsearchpackage .=
" AND fk_product = ".((int) $objp->fk_product);
679 $sqlsearchpackage .=
" AND ref_fourn = '".$this->db->escape($objp->ref_supplier).
"'";
680 $sqlsearchpackage .=
" AND quantity <= ".((float) $objp->qty);
681 $sqlsearchpackage .=
" AND (packaging IS NULL OR packaging = 0 OR packaging <= ".((float) $objp->qty).
")";
682 $sqlsearchpackage .=
" AND fk_soc = ".((int) $this->socid);
683 $sqlsearchpackage .=
" ORDER BY packaging ASC";
684 $sqlsearchpackage .=
" LIMIT 1";
686 $resqlsearchpackage = $this->db->query($sqlsearchpackage);
687 if ($resqlsearchpackage) {
688 $objsearchpackage = $this->db->fetch_object($resqlsearchpackage);
689 if ($objsearchpackage) {
690 $line->fk_fournprice = $objsearchpackage->rowid;
691 $line->packaging = $objsearchpackage->packaging;
694 $this->error = $this->db->lasterror();
699 $line->date_start = $this->db->jdate($objp->date_start);
700 $line->date_end = $this->db->jdate($objp->date_end);
701 $line->fk_unit = $objp->fk_unit;
704 $line->fk_multicurrency = $objp->fk_multicurrency;
705 $line->multicurrency_code = $objp->multicurrency_code;
706 $line->multicurrency_subprice = $objp->multicurrency_subprice;
707 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
708 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
709 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
711 $line->info_bits = $objp->info_bits;
712 $line->special_code = $objp->special_code;
713 $line->fk_parent_line = $objp->fk_parent_line;
715 $line->rang = $objp->rang;
719 $line->fetch_optionals();
721 $this->lines[$i] = $line;
725 $this->db->free($result);
729 $this->error = $this->db->error().
" sql=".$sql;
742 public function valid($user, $idwarehouse = 0, $notrigger = 0)
745 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
751 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")))
752 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"fournisseur",
"supplier_order_advance",
"validate"))) {
757 $soc->fetch($this->fourn_id);
760 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
767 $sql =
'UPDATE '.$this->db->prefix().
"commande_fournisseur";
768 $sql .=
" SET ref='".$this->db->escape($num).
"',";
769 $sql .=
" fk_statut = ".((int) self::STATUS_VALIDATED).
",";
770 $sql .=
" date_valid='".$this->db->idate(
dol_now()).
"',";
771 $sql .=
" fk_user_valid = ".((int) $user->id);
772 $sql .=
" WHERE rowid = ".((int) $this->
id);
773 $sql .=
" AND fk_statut = ".((int) self::STATUS_DRAFT);
775 $resql = $this->db->query($sql);
781 if (!$error && !$notrigger) {
783 $result = $this->
call_trigger(
'ORDER_SUPPLIER_VALIDATE', $user);
791 $this->oldref = $this->ref;
794 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
796 $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).
"'";
797 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'fournisseur/commande/".$this->db->escape($this->
ref).
"' and entity = ".((int) $conf->entity);
798 $resql = $this->db->query($sql);
801 $this->error = $this->db->lasterror();
803 $sql =
'UPDATE '.$this->db->prefix().
"ecm_files set filepath = 'fournisseur/commande/".$this->db->escape($this->newref).
"'";
804 $sql .=
" WHERE filepath = 'fournisseur/commande/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
805 $resql = $this->db->query($sql);
808 $this->error = $this->db->lasterror();
814 $dirsource = $conf->fournisseur->commande->dir_output.
'/'.$oldref;
815 $dirdest = $conf->fournisseur->commande->dir_output.
'/'.$newref;
816 if (!$error && file_exists($dirsource)) {
817 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
819 if (@rename($dirsource, $dirdest)) {
822 $listoffiles =
dol_dir_list($conf->fournisseur->commande->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
823 foreach ($listoffiles as $fileentry) {
824 $dirsource = $fileentry[
'name'];
825 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
826 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
827 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
828 @rename($dirsource, $dirdest);
846 $this->db->rollback();
850 $this->error =
'NotAuthorized';
851 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
876 public function LibStatut($status, $mode = 0, $billed = 0)
879 global $langs, $hookmanager;
881 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
882 $langs->load(
'orders');
884 $this->labelStatus[0] =
'StatusSupplierOrderDraft';
885 $this->labelStatus[1] =
'StatusSupplierOrderValidated';
886 $this->labelStatus[2] =
'StatusSupplierOrderApproved';
888 $this->labelStatus[3] =
'StatusSupplierOrderOnProcess';
890 $this->labelStatus[3] =
'StatusSupplierOrderOnProcessWithValidation';
892 $this->labelStatus[4] =
'StatusSupplierOrderReceivedPartially';
893 $this->labelStatus[5] =
'StatusSupplierOrderReceivedAll';
894 $this->labelStatus[6] =
'StatusSupplierOrderCanceled';
895 $this->labelStatus[7] =
'StatusSupplierOrderCanceled';
896 $this->labelStatus[9] =
'StatusSupplierOrderRefused';
899 $this->labelStatusShort[0] =
'StatusSupplierOrderDraftShort';
900 $this->labelStatusShort[1] =
'StatusSupplierOrderValidatedShort';
901 $this->labelStatusShort[2] =
'StatusSupplierOrderApprovedShort';
902 $this->labelStatusShort[3] =
'StatusSupplierOrderOnProcessShort';
903 $this->labelStatusShort[4] =
'StatusSupplierOrderReceivedPartiallyShort';
904 $this->labelStatusShort[5] =
'StatusSupplierOrderReceivedAllShort';
905 $this->labelStatusShort[6] =
'StatusSupplierOrderCanceledShort';
906 $this->labelStatusShort[7] =
'StatusSupplierOrderCanceledShort';
907 $this->labelStatusShort[9] =
'StatusSupplierOrderRefusedShort';
910 $statustrans = array(
922 $statusClass =
'status0';
923 if (!empty($statustrans[$status])) {
924 $statusClass = $statustrans[$status];
929 $billedtext =
' - '.$langs->trans(
"Billed");
931 if ($status == 5 && $billed) {
932 $statusClass =
'status6';
935 $statusLong = $langs->transnoentitiesnoconv($this->labelStatus[$status]).$billedtext;
936 $statusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
938 $parameters = array(
'status' => $status,
'mode' => $mode,
'billed' => $billed);
939 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
941 return $hookmanager->resPrint;
944 return dolGetStatus($statusLong, $statusShort,
'', $statusClass, $mode);
956 global $conf, $langs, $user;
958 $langs->loadLangs([
'bills',
'orders']);
961 $nofetch = !empty($params[
'nofetch']);
963 if ($user->hasRight(
"fournisseur",
"commande",
"read")) {
964 $datas[
'picto'] =
'<u class="paddingrightonly">'.$langs->trans(
"SupplierOrder").
'</u>';
965 if (isset($this->
statut)) {
966 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
968 if (!empty($this->
ref)) {
969 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
971 if (!empty($this->ref_supplier)) {
972 $datas[
'refsupplier'] =
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.$this->ref_supplier;
975 $langs->load(
'companies');
976 if (empty($this->thirdparty)) {
979 $datas[
'supplier'] =
'<br><b>'.$langs->trans(
'Supplier').
':</b> '.$this->thirdparty->getNomUrl(1,
'', 0, 1);
981 if (!empty($this->total_ht)) {
982 $datas[
'totalht'] =
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
984 if (!empty($this->total_tva)) {
985 $datas[
'totaltva'] =
'<br><b>'.$langs->trans(
'VAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
987 if (!empty($this->total_ttc)) {
988 $datas[
'totalttc'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
990 if (!empty($this->date)) {
991 $datas[
'date'] =
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->date,
'day');
993 if (!empty($this->delivery_date)) {
994 $datas[
'deliverydate'] =
'<br><b>'.$langs->trans(
'DeliveryDate').
':</b> '.
dol_print_date($this->delivery_date,
'dayhour');
1010 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = 0)
1012 global $langs, $user, $hookmanager;
1017 'objecttype' => $this->element,
1018 'option' => $option,
1021 $classfortooltip =
'classfortooltip';
1024 $classfortooltip =
'classforajaxtooltip';
1025 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1031 $url = DOL_URL_ROOT.
'/fourn/commande/card.php?id='.$this->id;
1033 if ($option !==
'nolink') {
1035 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1036 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1037 $add_save_lastsearch_values = 1;
1039 if ($add_save_lastsearch_values) {
1040 $url .=
'&save_lastsearch_values=1';
1045 if (empty($notooltip)) {
1047 $label = $langs->trans(
"ShowOrder");
1048 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1050 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1051 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
1054 $linkstart =
'<a href="'.$url.
'"';
1055 $linkstart .= $linkclose.
'>';
1058 $result .= $linkstart;
1060 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
1062 if ($withpicto != 2) {
1063 $result .= $this->ref;
1065 $result .= $linkend;
1067 if ($addlinktonotes) {
1068 $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
1071 $result .=
' <span class="note inline-block">';
1072 $result .=
'<a href="'.DOL_URL_ROOT.
'/fourn/commande/note.php?id='.$this->
id.
'" class="classfortooltip" title="'.
dol_escape_htmltag($notetoshow).
'">';
1077 $result .=
'</span>';
1082 $hookmanager->initHooks(array($this->element .
'dao'));
1083 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1084 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1086 $result = $hookmanager->resPrint;
1088 $result .= $hookmanager->resPrint;
1103 global $langs, $conf;
1104 $langs->load(
"orders");
1113 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
1115 foreach ($dirmodels as $reldir) {
1116 $dir =
dol_buildpath($reldir.
"core/modules/supplier_order/");
1119 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1122 if ($mybool ===
false) {
1127 $obj =
new $classname();
1128 $numref = $obj->getNextValue($soc, $this);
1130 if ($numref !=
"") {
1133 $this->error = $obj->error;
1137 $this->error =
"Error_COMMANDE_SUPPLIER_ADDON_NotDefined";
1151 if ($this->billed) {
1157 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur SET billed = 1';
1160 if ($this->db->query($sql)) {
1163 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CLASSIFY_BILLED', $user);
1173 $this->db->commit();
1176 $this->db->rollback();
1182 $this->db->rollback();
1195 public function approve($user, $idwarehouse = 0, $secondlevel = 0)
1197 global $langs, $conf;
1198 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1204 if ($user->hasRight(
"fournisseur",
"commande",
"approuver")) {
1210 $soc =
new Societe($this->db);
1211 $soc->fetch($this->fourn_id);
1214 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
1222 $movetoapprovestatus =
true;
1225 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1226 $sql .=
" SET ref='".$this->db->escape($num).
"',";
1227 if (empty($secondlevel)) {
1228 $sql .=
" date_approve='".$this->db->idate($now).
"',";
1229 $sql .=
" fk_user_approve = ".$user->id;
1230 if (
getDolGlobalString(
'SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED') && $this->total_ht >= $conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) {
1231 if (empty($this->user_approve_id2)) {
1232 $movetoapprovestatus =
false;
1233 $comment =
' (first level)';
1237 $sql .=
" date_approve2='".$this->db->idate($now).
"',";
1238 $sql .=
" fk_user_approve2 = ".((int) $user->id);
1239 if (empty($this->user_approve_id)) {
1240 $movetoapprovestatus =
false;
1242 $comment =
' (second level)';
1245 if ($movetoapprovestatus) {
1246 $sql .=
", fk_statut = ".self::STATUS_ACCEPTED;
1248 $sql .=
", fk_statut = ".self::STATUS_VALIDATED;
1250 $sql .=
" WHERE rowid = ".((int) $this->
id);
1251 $sql .=
" AND fk_statut = ".self::STATUS_VALIDATED;
1253 if ($this->db->query($sql)) {
1255 $result = $this->
add_contact($user->id,
'SALESREPFOLL',
'internal', 1);
1256 if ($result < 0 && $result != -2) {
1262 if (!$error && $movetoapprovestatus && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER')) {
1263 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1264 $langs->load(
"agenda");
1266 $cpt = count($this->lines);
1267 for ($i = 0; $i < $cpt; $i++) {
1269 if ($this->lines[$i]->fk_product > 0) {
1270 $this->line = $this->lines[$i];
1272 $mouvP->origin = &$this;
1273 $mouvP->setOrigin($this->element, $this->
id);
1275 $up_ht_disc = $this->lines[$i]->subprice;
1276 if (!empty($this->lines[$i]->remise_percent) && !
getDolGlobalString(
'STOCK_EXCLUDE_DISCOUNT_FOR_PMP')) {
1277 $up_ht_disc =
price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100,
'MU');
1279 $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans(
"OrderApprovedInDolibarr", $this->ref));
1290 $result = $this->
call_trigger(
'ORDER_SUPPLIER_APPROVE', $user);
1298 $this->
ref = $this->newref;
1300 if ($movetoapprovestatus) {
1305 if (empty($secondlevel)) {
1306 $this->date_approve = $now;
1307 $this->user_approve_id = $user->id;
1309 $this->date_approve2 = $now;
1310 $this->user_approve_id2 = $user->id;
1313 $this->db->commit();
1316 $this->db->rollback();
1320 $this->db->rollback();
1321 $this->error = $this->db->lasterror();
1325 dol_syslog(get_class($this).
"::approve Not Authorized", LOG_ERR);
1338 global $conf, $langs;
1344 if ($user->hasRight(
"fournisseur",
"commande",
"approuver")) {
1347 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur SET fk_statut = ".
self::STATUS_REFUSED;
1348 $sql .=
" WHERE rowid = ".((int) $this->
id);
1350 if ($this->db->query($sql)) {
1355 $result = $this->
call_trigger(
'ORDER_SUPPLIER_REFUSE', $user);
1358 $this->db->rollback();
1360 $this->db->commit();
1365 $this->db->rollback();
1366 $this->error = $this->db->lasterror();
1367 dol_syslog(get_class($this).
"::refuse Error -1");
1371 dol_syslog(get_class($this).
"::refuse Not Authorized");
1385 public function Cancel($user, $idwarehouse = -1)
1388 global $langs, $conf;
1394 if ($user->hasRight(
"fournisseur",
"commande",
"commander")) {
1399 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur SET fk_statut = ".((int) $statut);
1400 $sql .=
" WHERE rowid = ".((int) $this->
id);
1401 dol_syslog(get_class($this).
"::cancel", LOG_DEBUG);
1402 if ($this->db->query($sql)) {
1406 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CANCEL', $user);
1413 $this->db->commit();
1416 $this->db->rollback();
1420 $this->db->rollback();
1421 $this->error = $this->db->lasterror();
1422 dol_syslog(get_class($this).
"::cancel ".$this->error);
1426 dol_syslog(get_class($this).
"::cancel Not Authorized");
1440 public function commande($user, $date, $methode, $comment =
'')
1445 if ($user->hasRight(
"fournisseur",
"commande",
"commander")) {
1448 $newnoteprivate = $this->note_private;
1450 $newnoteprivate =
dol_concatdesc($newnoteprivate, $langs->trans(
"Comment").
': '.$comment);
1453 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1454 $sql .=
" SET fk_statut=".self::STATUS_ORDERSENT.
", fk_input_method=".$methode.
", date_commande='".$this->db->idate($date).
"', ";
1455 $sql .=
" note_private='".$this->db->escape($newnoteprivate).
"'";
1456 $sql .=
" WHERE rowid=".((int) $this->
id);
1458 dol_syslog(get_class($this).
"::commande", LOG_DEBUG);
1459 if ($this->db->query($sql)) {
1461 $this->methode_commande_id = $methode;
1462 $this->date_commande = $date;
1463 $this->context = array(
'comments' => $comment);
1466 $result = $this->
call_trigger(
'ORDER_SUPPLIER_SUBMIT', $user);
1473 $this->error = $this->db->lasterror();
1474 $this->errors[] = $this->db->lasterror();
1478 $this->db->commit();
1480 $this->db->rollback();
1484 $this->error = $langs->trans(
'NotAuthorized');
1485 $this->errors[] = $langs->trans(
'NotAuthorized');
1486 dol_syslog(get_class($this).
"::commande User not Authorized", LOG_WARNING);
1489 return ($error ? -1 : 1);
1499 public function create($user, $notrigger = 0)
1501 global $langs, $conf, $hookmanager;
1509 $date = ($this->date_commande ? $this->date_commande : $this->date);
1513 $delivery_date = $this->delivery_date;
1516 if (empty($this->source)) {
1521 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
1526 if (empty($this->fk_multicurrency)) {
1527 $this->multicurrency_code = $conf->currency;
1528 $this->fk_multicurrency = 0;
1529 $this->multicurrency_tx = 1;
1536 $sql =
"INSERT INTO ".$this->db->prefix().
"commande_fournisseur (";
1538 $sql .=
", ref_supplier";
1539 $sql .=
", note_private";
1540 $sql .=
", note_public";
1543 $sql .=
", fk_projet";
1544 $sql .=
", date_creation";
1545 $sql .=
", date_livraison";
1546 $sql .=
", fk_user_author";
1547 $sql .=
", fk_statut";
1549 $sql .=
", model_pdf";
1550 $sql .=
", fk_mode_reglement";
1551 $sql .=
", fk_cond_reglement";
1552 $sql .=
", fk_account";
1553 $sql .=
", fk_incoterms, location_incoterms";
1554 $sql .=
", fk_multicurrency";
1555 $sql .=
", multicurrency_code";
1556 $sql .=
", multicurrency_tx";
1558 $sql .=
" VALUES (";
1560 $sql .=
", ".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"NULL");
1561 $sql .=
", '".$this->db->escape($this->note_private).
"'";
1562 $sql .=
", '".$this->db->escape($this->note_public).
"'";
1563 $sql .=
", ".setEntity($this);
1564 $sql .=
", ".((int) $this->socid);
1565 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
1566 $sql .=
", '".$this->db->idate($date).
"'";
1567 $sql .=
", ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
"null");
1568 $sql .=
", ".((int) $user->id);
1569 $sql .=
", ".self::STATUS_DRAFT;
1570 $sql .=
", ".((int) $this->source);
1571 $sql .=
", '".$this->db->escape(
getDolGlobalString(
'COMMANDE_SUPPLIER_ADDON_PDF')).
"'";
1572 $sql .=
", ".($this->mode_reglement_id > 0 ? $this->mode_reglement_id :
'null');
1573 $sql .=
", ".($this->cond_reglement_id > 0 ? $this->cond_reglement_id :
'null');
1574 $sql .=
", ".($this->fk_account > 0 ? $this->fk_account :
'NULL');
1575 $sql .=
", ".(int) $this->fk_incoterms;
1576 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
1577 $sql .=
", ".(int) $this->fk_multicurrency;
1578 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1579 $sql .=
", ".(float) $this->multicurrency_tx;
1582 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1583 if ($this->db->query($sql)) {
1584 $this->
id = $this->db->last_insert_id($this->db->prefix().
"commande_fournisseur");
1587 $num = count($this->lines);
1590 for ($i = 0; $i < $num; $i++) {
1591 $line = $this->lines[$i];
1592 if (!is_object($line)) {
1593 $line = (object) $line;
1604 $line->localtax1_tx,
1605 $line->localtax2_tx,
1609 $line->remise_percent,
1612 $line->product_type,
1617 $line->array_options,
1619 $line->multicurrency_subprice,
1626 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
1627 $this->db->rollback();
1632 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1633 $sql .=
" SET ref='(PROV".$this->id.
")'";
1634 $sql .=
" WHERE rowid=".((int) $this->
id);
1636 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1637 if ($this->db->query($sql)) {
1640 $this->
ref =
"(PROV".$this->id.
")";
1642 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
1643 $this->linked_objects = $this->linkedObjectsIds;
1647 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
1648 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
1649 if (is_array($tmp_origin_id)) {
1650 foreach ($tmp_origin_id as $origin_id) {
1658 $origin_id = $tmp_origin_id;
1676 if (!$error && !$notrigger) {
1678 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CREATE', $user);
1680 $this->db->rollback();
1687 $this->db->commit();
1690 $this->error = $this->db->lasterror();
1691 $this->db->rollback();
1696 $this->error =
'Failed to get ID of inserted line';
1701 $this->error = $this->db->lasterror();
1702 $this->db->rollback();
1722 if (isset($this->
ref)) {
1723 $this->
ref = trim($this->
ref);
1725 if (isset($this->ref_supplier)) {
1726 $this->ref_supplier = trim($this->ref_supplier);
1728 if (isset($this->note_private)) {
1729 $this->note_private = trim($this->note_private);
1731 if (isset($this->note_public)) {
1732 $this->note_public = trim($this->note_public);
1734 if (isset($this->model_pdf)) {
1735 $this->model_pdf = trim($this->model_pdf);
1737 if (isset($this->import_key)) {
1738 $this->import_key = trim($this->import_key);
1742 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
1744 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1745 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
1746 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1747 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
1748 $sql .=
" date_commande=".(strval($this->date_commande) !=
'' ?
"'".$this->db->idate($this->date_commande).
"'" :
'null').
",";
1749 $sql .=
" date_valid=".(strval($this->date_validation) !=
'' ?
"'".$this->db->idate($this->date_validation).
"'" :
'null').
",";
1750 $sql .=
" total_tva=".(isset($this->total_tva) ? $this->total_tva :
"null").
",";
1751 $sql .=
" localtax1=".(isset($this->total_localtax1) ? $this->total_localtax1 :
"null").
",";
1752 $sql .=
" localtax2=".(isset($this->total_localtax2) ? $this->total_localtax2 :
"null").
",";
1753 $sql .=
" total_ht=".(isset($this->total_ht) ? $this->total_ht :
"null").
",";
1754 $sql .=
" total_ttc=".(isset($this->total_ttc) ? $this->total_ttc :
"null").
",";
1755 $sql .=
" fk_statut=".(isset($this->
statut) ? $this->
statut :
"null").
",";
1756 $sql .=
" fk_user_author=".(isset($this->user_author_id) ? $this->user_author_id :
"null").
",";
1757 $sql .=
" fk_user_valid=".(isset($this->user_validation_id) && $this->user_validation_id > 0 ? $this->user_validation_id :
"null").
",";
1758 $sql .=
" fk_projet=".(isset($this->fk_project) ? $this->fk_project :
"null").
",";
1759 $sql .=
" fk_cond_reglement=".(isset($this->cond_reglement_id) ? $this->cond_reglement_id :
"null").
",";
1760 $sql .=
" fk_mode_reglement=".(isset($this->mode_reglement_id) ? $this->mode_reglement_id :
"null").
",";
1761 $sql .=
" date_livraison=".(strval($this->delivery_date) !=
'' ?
"'".$this->db->idate($this->delivery_date).
"'" :
'null').
",";
1763 $sql .=
" fk_account=".($this->fk_account > 0 ? $this->fk_account :
"null").
",";
1765 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1766 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1767 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1768 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
1770 $sql .=
" WHERE rowid=".((int) $this->
id);
1774 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1775 $resql = $this->db->query($sql);
1778 $this->errors[] =
"Error ".$this->db->lasterror();
1788 if (!$error && !$notrigger) {
1790 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
1799 foreach ($this->errors as $errmsg) {
1800 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1801 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1803 $this->db->rollback();
1806 $this->db->commit();
1821 global $conf, $user, $hookmanager;
1828 foreach ($this->lines as $line) {
1829 $line->fetch_optionals();
1833 $objFrom = clone $this;
1836 if (!empty($socid) && $socid != $this->socid) {
1837 $objsoc =
new Societe($this->db);
1839 if ($objsoc->fetch($socid) > 0) {
1840 $this->socid = $objsoc->id;
1841 $this->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1842 $this->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1843 $this->fk_project = 0;
1844 $this->fk_delivery_address = 0;
1854 $this->user_author_id = $user->id;
1855 $this->user_validation_id = 0;
1858 $this->date_creation = 0;
1859 $this->date_validation = 0;
1860 $this->date_commande = 0;
1861 $this->ref_supplier =
'';
1862 $this->user_approve_id = 0;
1863 $this->user_approve_id2 = 0;
1864 $this->date_approve = 0;
1865 $this->date_approve2 = 0;
1868 $this->context[
'createfromclone'] =
'createfromclone';
1869 $result = $this->
create($user, $notrigger);
1876 if (is_object($hookmanager)) {
1877 $parameters = array(
'objFrom' => $objFrom);
1879 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1887 unset($this->context[
'createfromclone']);
1891 $this->db->commit();
1894 $this->db->rollback();
1928 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)
1930 global $langs, $mysoc, $conf;
1932 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");
1933 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1935 if ($this->
statut == self::STATUS_DRAFT) {
1936 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1945 if (empty($txtva)) {
1951 if (empty($txlocaltax1)) {
1954 if (empty($txlocaltax2)) {
1957 if (empty($remise_percent)) {
1958 $remise_percent = 0;
1961 $remise_percent =
price2num($remise_percent);
1964 $pu_ht_devise =
price2num($pu_ht_devise);
1966 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
1971 if ($price_base_type ==
'HT') {
1976 $desc = trim($desc);
1979 if ($qty < 0 && !$fk_product) {
1980 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Product"));
1986 if ($date_start && $date_end && $date_start > $date_end) {
1987 $langs->load(
"errors");
1988 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
1995 $product_type = $type;
1998 if ($fk_product > 0) {
2001 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);
2003 if ($prod->fetch($fk_product) > 0) {
2004 $product_type = $prod->type;
2005 $label = $prod->label;
2009 $result = $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', (isset($this->fk_soc) ? $this->fk_soc : $this->socid));
2013 if ($result > 0 && ($origin ==
'commande' || $pu ===
'')) {
2014 $pu = $prod->fourn_pu;
2015 $ref_supplier = $prod->ref_supplier;
2017 if ($remise_percent == 0 && $prod->remise_percent != 0) {
2018 $remise_percent = $prod->remise_percent;
2022 $langs->load(
"errors");
2023 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
2024 $this->db->rollback();
2025 dol_syslog(get_class($this).
"::addline we did not found supplier price, so we can't guess unit price");
2030 if ($result == -1) {
2031 $langs->load(
"errors");
2032 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
2033 $this->db->rollback();
2034 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_DEBUG);
2038 $this->error = $prod->error;
2039 $this->db->rollback();
2040 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_ERR);
2044 $this->error = $prod->error;
2045 $this->db->rollback();
2052 $prod =
new Product($this->db);
2053 $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', (empty($this->fk_soc) ? $this->socid : $this->fk_soc));
2055 if ($qty < $prod->packaging) {
2056 $qty = $prod->packaging;
2058 if (!empty($prod->packaging) && ($qty % $prod->packaging) > 0) {
2059 $coeff = intval($qty / $prod->packaging) + 1;
2060 $qty = $prod->packaging * $coeff;
2061 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'mesgs');
2067 if (isModEnabled(
"multicurrency") && $pu_ht_devise > 0) {
2076 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
2077 $vat_src_code = $reg[1];
2078 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
2086 $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);
2088 $total_ht = $tabprice[0];
2089 $total_tva = $tabprice[1];
2090 $total_ttc = $tabprice[2];
2091 $total_localtax1 = $tabprice[9];
2092 $total_localtax2 = $tabprice[10];
2093 $pu = $pu_ht = $tabprice[3];
2096 $multicurrency_total_ht = $tabprice[16];
2097 $multicurrency_total_tva = $tabprice[17];
2098 $multicurrency_total_ttc = $tabprice[18];
2099 $pu_ht_devise = $tabprice[19];
2101 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2102 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2106 $rang = $rangmax + 1;
2112 $this->line->context = $this->context;
2114 $this->line->fk_commande = $this->id;
2115 $this->line->label = $label;
2116 $this->line->ref_fourn = $ref_supplier;
2117 $this->line->ref_supplier = $ref_supplier;
2118 $this->line->desc = $desc;
2119 $this->line->qty = $qty;
2120 $this->line->tva_tx = $txtva;
2121 $this->line->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0);
2122 $this->line->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0);
2123 $this->line->localtax1_type = $localtax1_type;
2124 $this->line->localtax2_type = $localtax2_type;
2125 $this->line->fk_product = $fk_product;
2126 $this->line->product_type = $product_type;
2127 $this->line->remise_percent = $remise_percent;
2128 $this->line->subprice = $pu_ht;
2129 $this->line->rang = $rang;
2130 $this->line->info_bits = $info_bits;
2132 $this->line->vat_src_code = $vat_src_code;
2133 $this->line->total_ht = $total_ht;
2134 $this->line->total_tva = $total_tva;
2135 $this->line->total_localtax1 = $total_localtax1;
2136 $this->line->total_localtax2 = $total_localtax2;
2137 $this->line->total_ttc = $total_ttc;
2138 $this->line->product_type = $type;
2139 $this->line->special_code = (!empty($special_code) ? $special_code : 0);
2140 $this->line->origin = $origin;
2141 $this->line->origin_id = $origin_id;
2142 $this->line->fk_unit = $fk_unit;
2144 $this->line->date_start = $date_start;
2145 $this->line->date_end = $date_end;
2148 $this->line->fk_multicurrency = $this->fk_multicurrency;
2149 $this->line->multicurrency_code = $this->multicurrency_code;
2150 $this->line->multicurrency_subprice = $pu_ht_devise;
2151 $this->line->multicurrency_total_ht = $multicurrency_total_ht;
2152 $this->line->multicurrency_total_tva = $multicurrency_total_tva;
2153 $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
2155 $this->line->subprice = $pu_ht;
2156 $this->line->price = $this->line->subprice;
2158 $this->line->remise_percent = $remise_percent;
2160 if (is_array($array_options) && count($array_options) > 0) {
2161 $this->line->array_options = $array_options;
2164 $result = $this->line->insert($notrigger);
2167 if (!empty($this->line->fk_parent_line)) {
2169 } elseif ($rang > 0 && $rang <= count($this->lines)) {
2170 $linecount = count($this->lines);
2171 for ($ii = $rang; $ii <= $linecount; $ii++) {
2177 $result = $this->
update_price(1,
'auto', 0, $this->thirdparty);
2179 $this->db->commit();
2180 return $this->line->id;
2182 $this->db->rollback();
2186 $this->error = $this->line->error;
2187 $this->errors = $this->line->errors;
2188 dol_syslog(get_class($this).
"::addline error=".$this->error, LOG_ERR);
2189 $this->db->rollback();
2214 public function dispatchProduct($user, $product, $qty, $entrepot, $price = 0, $comment =
'', $eatby =
'', $sellby =
'', $batch =
'', $fk_commandefourndet = 0, $notrigger = 0, $fk_reception = 0)
2216 global $conf, $langs;
2219 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2222 if ($entrepot <= 0) {
2223 $this->error =
'ErrorBadValueForParameterWarehouse';
2227 $this->error =
'ErrorBadValueForParameterQty';
2231 $dispatchstatus = 1;
2233 $dispatchstatus = 0;
2240 if (($this->
statut == self::STATUS_ORDERSENT || $this->
statut == self::STATUS_RECEIVED_PARTIALLY || $this->
statut == self::STATUS_RECEIVED_COMPLETELY)) {
2243 $sql =
"INSERT INTO ".$this->db->prefix().
"receptiondet_batch";
2244 $sql .=
" (fk_element, fk_product, qty, fk_entrepot, fk_user, datec, fk_elementdet, status, comment, eatby, sellby, batch, fk_reception) VALUES";
2245 $sql .=
" ('".$this->id.
"','".$product.
"','".$qty.
"',".($entrepot > 0 ?
"'".$entrepot.
"'" :
"null").
",'".$user->id.
"','".$this->db->idate($now).
"','".$fk_commandefourndet.
"', ".$dispatchstatus.
", '".$this->db->escape($comment).
"', ";
2246 $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");
2249 dol_syslog(get_class($this).
"::dispatchProduct", LOG_DEBUG);
2250 $resql = $this->db->query($sql);
2253 global $conf, $langs, $user;
2255 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_DISPATCH', $user);
2262 $this->error = $this->db->lasterror();
2267 if (!$error && $entrepot > 0 && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER')) {
2271 $mouv->origin = &$this;
2272 $mouv->setOrigin($this->element, $this->
id);
2275 if (
getDolGlobalString(
'SUPPLIER_ORDER_ALLOW_NEGATIVE_QTY_FOR_SUPPLIER_ORDER_RETURN') && $qty < 0) {
2276 $result = $mouv->livraison($user, $product, $entrepot, $qty * (-1), $price, $comment, $now, $eatby, $sellby, $batch, 0, $inventorycode);
2278 $result = $mouv->reception($user, $product, $entrepot, $qty, $price, $comment, $eatby, $sellby, $batch,
'', 0, $inventorycode);
2282 $this->error = $mouv->error;
2283 $this->errors = $mouv->errors;
2284 dol_syslog(get_class($this).
"::dispatchProduct ".$this->error.
" ".implode(
',', $this->errors), LOG_ERR);
2291 $this->db->commit();
2294 $this->db->rollback();
2298 $this->error =
'BadStatusForObject';
2314 if ($this->
statut == 0) {
2317 if ($line->fetch($idline) <= 0) {
2323 foreach ($dispatchedLines as $dispatchLine) {
2324 if ($dispatchLine[
'orderlineid'] == $idline) {
2325 $this->error =
"LineAlreadyDispatched";
2326 $this->errors[] = $this->error;
2331 if ($line->delete($user, $notrigger) > 0) {
2350 public function delete(
User $user, $notrigger = 0)
2352 global $langs, $conf;
2353 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2359 if (empty($notrigger)) {
2361 $result = $this->
call_trigger(
'ORDER_SUPPLIER_DELETE', $user);
2363 $this->errors[] =
'ErrorWhenRunningTrigger';
2364 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2365 $this->db->rollback();
2373 if (!empty($this->linkedObjects) && array_key_exists(
'reception', $this->linkedObjects)) {
2374 foreach ($this->linkedObjects[
'reception'] as $element) {
2375 if ($element->statut >= 0) {
2376 $this->errors[] = $langs->trans(
'ReceptionExist');
2383 $main = $this->db->prefix().
'commande_fournisseurdet';
2386 $sql1 =
"UPDATE ".$this->db->prefix().
"commandedet SET fk_commandefourndet = NULL WHERE fk_commandefourndet IN (SELECT rowid FROM ".$main.
" WHERE fk_commande = ".((int) $this->
id).
")";
2387 dol_syslog(__METHOD__.
" linked order lines", LOG_DEBUG);
2388 if (!$this->db->query($sql1)) {
2390 $this->error = $this->db->lasterror();
2391 $this->errors[] = $this->db->lasterror();
2396 $ef = $main.
"_extrafields";
2397 $sql =
"DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_commande = ".((int) $this->
id).
")";
2398 dol_syslog(get_class($this).
"::delete extrafields lines", LOG_DEBUG);
2399 if (!$this->db->query($sql)) {
2400 $this->error = $this->db->lasterror();
2401 $this->errors[] = $this->db->lasterror();
2407 $sql =
"DELETE FROM ".$this->db->prefix().
"commande_fournisseurdet WHERE fk_commande =".((int) $this->
id);
2408 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2409 if (!$this->db->query($sql)) {
2410 $this->error = $this->db->lasterror();
2411 $this->errors[] = $this->db->lasterror();
2417 $sql =
"DELETE FROM ".$this->db->prefix().
"commande_fournisseur WHERE rowid =".((int) $this->
id);
2418 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2419 if ($resql = $this->db->query($sql)) {
2420 if ($this->db->affected_rows($resql) < 1) {
2421 $this->error = $this->db->lasterror();
2422 $this->errors[] = $this->db->lasterror();
2426 $this->error = $this->db->lasterror();
2427 $this->errors[] = $this->db->lasterror();
2436 $this->error =
'FailToDeleteExtraFields';
2437 $this->errors[] =
'FailToDeleteExtraFields';
2439 dol_syslog(get_class($this).
"::delete error -4 ".$this->error, LOG_ERR);
2446 $this->error =
'FailToDeleteObjectLinked';
2447 $this->errors[] =
'FailToDeleteObjectLinked';
2458 if ($conf->fournisseur->commande->dir_output) {
2459 $dir = $conf->fournisseur->commande->dir_output.
"/".$ref;
2460 $file = $dir.
"/".$ref.
".pdf";
2461 if (file_exists($file)) {
2463 $this->error =
'ErrorFailToDeleteFile';
2464 $this->errors[] =
'ErrorFailToDeleteFile';
2468 if (file_exists($dir)) {
2471 $this->error =
'ErrorFailToDeleteDir';
2472 $this->errors[] =
'ErrorFailToDeleteDir';
2480 dol_syslog(get_class($this).
"::delete $this->id by $user->id", LOG_DEBUG);
2481 $this->db->commit();
2484 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2485 $this->db->rollback();
2504 $sql =
"SELECT p.ref, p.label,";
2505 $sql .=
" e.rowid as warehouse_id, e.ref as entrepot,";
2506 $sql .=
" cfd.rowid as dispatchedlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status, cfd.fk_elementdet";
2507 $sql .=
" FROM ".$this->db->prefix().
"product as p,";
2508 $sql .=
" ".$this->db->prefix().
"receptiondet_batch as cfd";
2509 $sql .=
" LEFT JOIN ".$this->db->prefix().
"entrepot as e ON cfd.fk_entrepot = e.rowid";
2510 $sql .=
" WHERE cfd.fk_element = ".((int) $this->
id);
2511 $sql .=
" AND cfd.fk_product = p.rowid";
2513 $sql .=
" AND cfd.status = ".((int) $status);
2515 $sql .=
" ORDER BY cfd.rowid ASC";
2517 $resql = $this->db->query($sql);
2519 $num = $this->db->num_rows($resql);
2523 $objp = $this->db->fetch_object($resql);
2526 'id' => $objp->dispatchedlineid,
2527 'productid' => $objp->fk_product,
2528 'warehouseid' => $objp->warehouse_id,
2529 'qty' => $objp->qty,
2530 'orderlineid' => $objp->fk_elementdet
2537 dol_print_error($this->db,
'Failed to execute request to get dispatched lines');
2556 global $conf, $langs;
2563 $usercanreceive = 0;
2564 if (!isModEnabled(
'reception')) {
2565 $usercanreceive = $user->hasRight(
"fournisseur",
"commande",
"receptionner");
2567 $usercanreceive = $user->hasRight(
"reception",
"creer");
2570 if ($usercanreceive) {
2572 if ($type ==
'par') {
2574 } elseif ($type ==
'tot') {
2576 } elseif ($type ==
'nev') {
2578 } elseif ($type ==
'can') {
2582 dol_syslog(get_class($this).
"::Livraison Error -2", LOG_ERR);
2589 if (!$error && ($type ==
'tot')) {
2591 if (count($dispatchedlinearray) > 0) {
2594 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove';
2595 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove', LOG_DEBUG);
2598 if (!$error &&
getDolGlobalString(
'SUPPLIER_ORDER_USE_DISPATCH_STATUS_NEED_APPROVE') && ($type ==
'tot')) {
2600 if (count($dispatchedlinearray) > 0) {
2603 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied';
2604 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied', LOG_DEBUG);
2611 if (empty($error)) {
2614 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2615 $sql .=
" SET fk_statut = ".((int) $statut);
2616 $sql .=
" WHERE rowid = ".((int) $this->
id);
2617 $sql .=
" AND fk_statut IN (".self::STATUS_ORDERSENT.
",".self::STATUS_RECEIVED_PARTIALLY.
")";
2619 dol_syslog(get_class($this).
"::Livraison", LOG_DEBUG);
2620 $resql = $this->db->query($sql);
2623 $old_statut = $this->statut;
2625 $this->context[
'actionmsg2'] = $comment;
2628 $result_trigger = $this->
call_trigger(
'ORDER_SUPPLIER_RECEIVE', $user);
2629 if ($result_trigger < 0) {
2634 if (empty($error)) {
2635 $this->db->commit();
2637 $this->
statut = $old_statut;
2638 $this->db->rollback();
2639 $this->error = $this->db->lasterror();
2643 $this->db->rollback();
2644 $this->error = $this->db->lasterror();
2649 $this->error = $langs->trans(
'NotAuthorized');
2650 $this->errors[] = $langs->trans(
'NotAuthorized');
2651 dol_syslog(get_class($this).
"::Livraison Not Authorized");
2683 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
2688 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2689 $sql .=
" SET date_livraison = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2690 $sql .=
" WHERE rowid = ".((int) $this->
id);
2693 $resql = $this->db->query($sql);
2695 $this->errors[] = $this->db->error();
2700 $this->oldcopy = clone $this;
2701 $this->delivery_date = $delivery_date;
2704 if (!$notrigger && empty($error)) {
2706 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2714 $this->db->commit();
2717 foreach ($this->errors as $errmsg) {
2718 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2719 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2721 $this->db->rollback();
2741 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
2746 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2747 $sql .=
" SET fk_projet = ".($id_projet > 0 ? (int) $id_projet :
'null');
2748 $sql .=
" WHERE rowid = ".((int) $this->
id);
2751 $resql = $this->db->query($sql);
2753 $this->errors[] = $this->db->error();
2758 $this->oldcopy = clone $this;
2759 $this->fk_projet = $id_projet;
2760 $this->fk_project = $id_projet;
2763 if (!$notrigger && empty($error)) {
2765 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2773 $this->db->commit();
2776 foreach ($this->errors as $errmsg) {
2777 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2778 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2780 $this->db->rollback();
2798 $comclient =
new Commande($this->db);
2799 $comclient->fetch($comclientid);
2803 $this->lines = array();
2805 $num = count($comclient->lines);
2806 for ($i = 0; $i < $num; $i++) {
2807 $prod =
new Product($this->db);
2810 if ($prod->fetch($comclient->lines[$i]->fk_product) > 0) {
2811 $label = $prod->label;
2815 $sql =
"INSERT INTO ".$this->db->prefix().
"commande_fournisseurdet";
2816 $sql .=
" (fk_commande, label, description, fk_product, price, qty, tva_tx, localtax1_tx, localtax2_tx, remise_percent, subprice, remise, ref)";
2817 $sql .=
" VALUES (".((int) $idc).
", '".$this->db->escape($label).
"', '".$this->db->escape($comclient->lines[$i]->desc).
"'";
2818 $sql .=
",".$comclient->lines[$i]->fk_product.
", ".
price2num($comclient->lines[$i]->price,
'MU');
2819 $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);
2820 $sql .=
", '".price2num($comclient->lines[$i]->subprice,
'MT').
"','0', '".$this->db->escape($ref).
"');";
2821 if ($this->db->query($sql)) {
2838 global $conf, $langs;
2843 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur';
2844 $sql .=
" SET fk_statut = ".$status;
2845 $sql .=
" WHERE rowid = ".((int) $this->
id);
2847 dol_syslog(get_class($this).
"::setStatus", LOG_DEBUG);
2848 $resql = $this->db->query($sql);
2851 $triggerName = array();
2852 $triggerName[0] =
'DRAFT';
2853 $triggerName[1] =
'VALIDATED';
2854 $triggerName[2] =
'APPROVED';
2855 $triggerName[3] =
'ORDERED';
2856 $triggerName[4] =
'RECEIVED_PARTIALLY';
2857 $triggerName[5] =
'RECEIVED_COMPLETELY';
2858 $triggerName[6] =
'CANCELED';
2859 $triggerName[7] =
'CANCELED';
2860 $triggerName[9] =
'REFUSED';
2863 $result = $this->
call_trigger(
"ORDER_SUPPLIER_STATUS_".$triggerName[$status], $user);
2870 $this->error = $this->db->lasterror();
2871 dol_syslog(get_class($this).
"::setStatus ".$this->error);
2876 $this->db->commit();
2879 $this->db->rollback();
2907 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 =
'')
2909 global $mysoc, $conf, $langs;
2910 dol_syslog(get_class($this).
"::updateline $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $type, $fk_unit");
2911 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2915 if ($this->
statut == self::STATUS_DRAFT) {
2920 if (empty($info_bits)) {
2923 if (empty($txtva)) {
2926 if (empty($txlocaltax1)) {
2929 if (empty($txlocaltax2)) {
2932 if (empty($remise_percent)) {
2933 $remise_percent = 0;
2936 $remise_percent = (float)
price2num($remise_percent);
2942 $pu_ht_devise =
price2num($pu_ht_devise);
2943 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
2946 $txlocaltax1 = (float)
price2num($txlocaltax1);
2947 $txlocaltax2 = (float)
price2num($txlocaltax2);
2953 if ($date_start && $date_end && $date_start > $date_end) {
2954 $langs->load(
"errors");
2955 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
2971 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
2972 $vat_src_code = $reg[1];
2973 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
2976 $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);
2977 $total_ht = $tabprice[0];
2978 $total_tva = $tabprice[1];
2979 $total_ttc = $tabprice[2];
2980 $total_localtax1 = $tabprice[9];
2981 $total_localtax2 = $tabprice[10];
2982 $pu_ht = $tabprice[3];
2983 $pu_tva = $tabprice[4];
2984 $pu_ttc = $tabprice[5];
2987 $multicurrency_total_ht = $tabprice[16];
2988 $multicurrency_total_tva = $tabprice[17];
2989 $multicurrency_total_ttc = $tabprice[18];
2990 $pu_ht_devise = $tabprice[19];
2992 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2993 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2997 $this->line->fetch($rowid);
2999 $oldline = clone $this->line;
3000 $this->line->oldline = $oldline;
3002 $this->line->context = $this->context;
3004 $this->line->fk_commande = $this->id;
3006 $this->line->desc = $desc;
3010 if ($qty < $this->line->packaging) {
3011 $qty = $this->line->packaging;
3013 if (!empty($this->line->packaging) && ($qty % $this->line->packaging) > 0) {
3014 $coeff = intval($qty / $this->line->packaging) + 1;
3015 $qty = $this->line->packaging * $coeff;
3016 setEventMessage($langs->trans(
'QtyRecalculatedWithPackaging'),
'mesgs');
3021 $this->line->qty = $qty;
3022 $this->line->ref_supplier = $ref_supplier;
3024 $this->line->vat_src_code = $vat_src_code;
3025 $this->line->tva_tx = $txtva;
3026 $this->line->localtax1_tx = $txlocaltax1;
3027 $this->line->localtax2_tx = $txlocaltax2;
3028 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
3029 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
3030 $this->line->remise_percent = $remise_percent;
3031 $this->line->subprice = $pu_ht;
3032 $this->line->info_bits = $info_bits;
3033 $this->line->total_ht = $total_ht;
3034 $this->line->total_tva = $total_tva;
3035 $this->line->total_localtax1 = $total_localtax1;
3036 $this->line->total_localtax2 = $total_localtax2;
3037 $this->line->total_ttc = $total_ttc;
3038 $this->line->product_type = $type;
3039 $this->line->special_code = $oldline->special_code;
3040 $this->line->rang = $oldline->rang;
3041 $this->line->origin = $this->origin;
3042 $this->line->fk_unit = $fk_unit;
3044 $this->line->date_start = $date_start;
3045 $this->line->date_end = $date_end;
3048 $this->line->fk_multicurrency = $this->fk_multicurrency;
3049 $this->line->multicurrency_code = $this->multicurrency_code;
3050 $this->line->multicurrency_subprice = $pu_ht_devise;
3051 $this->line->multicurrency_total_ht = $multicurrency_total_ht;
3052 $this->line->multicurrency_total_tva = $multicurrency_total_tva;
3053 $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
3055 $this->line->subprice = $pu_ht;
3056 $this->line->price = $this->line->subprice;
3058 $this->line->remise_percent = $remise_percent;
3060 if (is_array($array_options) && count($array_options) > 0) {
3062 foreach ($array_options as $key => $value) {
3063 $this->line->array_options[$key] = $array_options[$key];
3067 $result = $this->line->update($notrigger);
3073 $this->db->commit();
3076 $this->error = $this->db->lasterror();
3077 $this->db->rollback();
3081 $this->error =
"Order status makes operation forbidden";
3082 dol_syslog(get_class($this).
"::updateline ".$this->error, LOG_ERR);
3097 global $user, $langs, $conf;
3099 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
3101 dol_syslog(get_class($this).
"::initAsSpecimen");
3108 $sql =
"SELECT rowid";
3109 $sql .=
" FROM ".$this->db->prefix().
"product";
3110 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
3111 $sql .= $this->db->order(
"rowid",
"ASC");
3112 $sql .= $this->db->plimit(1);
3113 $resql = $this->db->query($sql);
3114 if ($resql && $this->db->num_rows($resql)) {
3115 $obj = $this->db->fetch_object($resql);
3116 $prodid = $obj->rowid;
3121 $this->
ref =
'SPECIMEN';
3122 $this->specimen = 1;
3125 $this->date_commande = $now;
3126 $this->date_lim_reglement = $this->date + 3600 * 24 * 30;
3127 $this->cond_reglement_code =
'RECEP';
3128 $this->mode_reglement_code =
'CHQ';
3130 $this->note_public =
'This is a comment (public)';
3131 $this->note_private =
'This is a comment (private)';
3133 $this->multicurrency_tx = 1;
3134 $this->multicurrency_code = $conf->currency;
3141 while ($xnbp < $nbp) {
3143 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
3145 $line->subprice = 100;
3146 $line->tva_tx = 19.6;
3147 $line->localtax1_tx = 0;
3148 $line->localtax2_tx = 0;
3150 $line->total_ht = 50;
3151 $line->total_ttc = 59.8;
3152 $line->total_tva = 9.8;
3153 $line->remise_percent = 50;
3155 $line->total_ht = 100;
3156 $line->total_ttc = 119.6;
3157 $line->total_tva = 19.6;
3158 $line->remise_percent = 00;
3160 $line->fk_product = $prodid;
3162 $this->lines[$xnbp] = $line;
3164 $this->total_ht += $line->total_ht;
3165 $this->total_tva += $line->total_tva;
3166 $this->total_ttc += $line->total_ttc;
3182 $sql =
'SELECT c.rowid, date_creation as datec, tms as datem, date_valid as date_validation, date_approve as datea, date_approve2 as datea2,';
3183 $sql .=
' fk_user_author, fk_user_modif, fk_user_valid, fk_user_approve, fk_user_approve2';
3184 $sql .=
' FROM '.$this->db->prefix().
'commande_fournisseur as c';
3185 $sql .=
' WHERE c.rowid = '.((int) $id);
3187 $result = $this->db->query($sql);
3189 if ($this->db->num_rows($result)) {
3190 $obj = $this->db->fetch_object($result);
3192 $this->
id = $obj->rowid;
3194 $this->user_creation_id = $obj->fk_user_author;
3195 $this->user_validation_id = $obj->fk_user_valid;
3196 $this->user_modification_id = $obj->fk_user_modif;
3197 $this->user_approve_id = $obj->fk_user_approve;
3198 $this->user_approve_id2 = $obj->fk_user_approve2;
3200 $this->date_creation = $this->db->jdate($obj->datec);
3201 $this->date_modification = $this->db->jdate($obj->datem);
3202 $this->date_approve = $this->db->jdate($obj->datea);
3203 $this->date_approve2 = $this->db->jdate($obj->datea2);
3204 $this->date_validation = $this->db->jdate($obj->date_validation);
3206 $this->db->free($result);
3219 global $conf, $user;
3221 $this->nb = array();
3224 $sql =
"SELECT count(co.rowid) as nb";
3225 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as co";
3226 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe as s ON co.fk_soc = s.rowid";
3227 if (empty($user->socid) && !$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3228 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
3229 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
3232 $sql .=
" ".$clause.
" co.entity IN (".
getEntity(
'supplier_order').
")";
3234 $resql = $this->db->query($sql);
3236 while ($obj = $this->db->fetch_object($resql)) {
3237 $this->nb[
"supplier_orders"] = $obj->nb;
3239 $this->db->free($resql);
3243 $this->error = $this->db->error();
3259 global $conf, $langs;
3261 $sql =
"SELECT c.rowid, c.date_creation as datec, c.date_commande, c.fk_statut, c.date_livraison as delivery_date, c.total_ht";
3262 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as c";
3263 if (empty($user->socid) && !$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3264 $sql .=
" JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
3266 $sql .=
" WHERE c.entity = ".$conf->entity;
3267 if ($mode ===
'awaiting') {
3268 $sql .=
" AND c.fk_statut IN (".self::STATUS_ORDERSENT.
", ".self::STATUS_RECEIVED_PARTIALLY.
")";
3270 $sql .=
" AND c.fk_statut IN (".self::STATUS_VALIDATED.
", ".self::STATUS_ACCEPTED.
")";
3273 $sql .=
" AND c.fk_soc = ".((int) $user->socid);
3276 $resql = $this->db->query($sql);
3281 $response->warning_delay = $conf->commande->fournisseur->warning_delay / 60 / 60 / 24;
3282 $response->label = $langs->trans(
"SuppliersOrdersToProcess");
3283 $response->labelShort = $langs->trans(
"Opened");
3284 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=1,2&mainmenu=commercial&leftmenu=orders_suppliers';
3287 if ($mode ===
'awaiting') {
3288 $response->label = $langs->trans(
"SuppliersOrdersAwaitingReception");
3289 $response->labelShort = $langs->trans(
"AwaitingReception");
3290 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=3,4&mainmenu=commercial&leftmenu=orders_suppliers';
3293 while ($obj = $this->db->fetch_object($resql)) {
3294 $commandestatic->delivery_date = $this->db->jdate($obj->delivery_date);
3295 $commandestatic->date_commande = $this->db->jdate($obj->date_commande);
3296 $commandestatic->statut = $obj->fk_statut;
3298 $response->nbtodo++;
3299 $response->total += $obj->total_ht;
3301 if ($commandestatic->hasDelay()) {
3302 $response->nbtodolate++;
3308 $this->error = $this->db->error();
3323 if ($this->methode_commande_id > 0) {
3324 $sql =
"SELECT rowid, code, libelle as label";
3325 $sql .=
" FROM ".$this->db->prefix().
'c_input_method';
3326 $sql .=
" WHERE active=1 AND rowid = ".((int) $this->methode_commande_id);
3328 $resql = $this->db->query($sql);
3330 if ($this->db->num_rows($resql)) {
3331 $obj = $this->db->fetch_object($resql);
3333 $string = $langs->trans($obj->code);
3334 if ($string == $obj->code) {
3335 $string = $obj->label !=
'-' ? $obj->label :
'';
3358 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3360 global $conf, $langs;
3365 if (!empty($this->model_pdf)) {
3366 $modele = $this->model_pdf;
3372 if (empty($modele)) {
3375 $langs->load(
"suppliers");
3376 $outputlangs->load(
"products");
3378 $modelpath =
"core/modules/supplier_order/doc/";
3379 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3392 if (empty($this->lines)) {
3399 foreach ($this->lines as $line) {
3400 if ($line->fk_product > 0) {
3402 $idp = $tmpproductfourn->find_min_price_product_fournisseur($line->fk_product, $line->qty, $this->thirdparty->id);
3405 if ($tmpproductfourn->delivery_time_days > $nb) {
3406 $nb = $tmpproductfourn->delivery_time_days;
3415 return $nb.
' '.$langs->trans(
'days');
3428 return $user->hasRight(
"fournisseur",
"commande");
3443 'commande_fournisseur'
3460 'commande_fournisseurdet'
3477 if ($this->
statut == self::STATUS_ORDERSENT || $this->
statut == self::STATUS_RECEIVED_PARTIALLY) {
3479 if (!empty($this->delivery_date)) {
3480 $date_to_test = $this->delivery_date;
3481 return $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay);
3489 $date_to_test = $this->date_commande;
3491 return ($this->
statut > 0 && $this->
statut < 5) && $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay);
3504 global $conf, $langs;
3506 $langs->load(
'orders');
3510 if ($this->
statut == self::STATUS_ORDERSENT || $this->
statut == self::STATUS_RECEIVED_PARTIALLY) {
3511 if (!empty($this->delivery_date)) {
3512 $text = $langs->trans(
"DeliveryDate").
' '.
dol_print_date($this->delivery_date,
'day');
3514 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3517 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3520 $text .=
' '.($conf->commande->fournisseur->warning_delay > 0 ?
'+' :
'-').
' '.round(abs($conf->commande->fournisseur->warning_delay) / 3600 / 24, 1).
' '.$langs->trans(
"days").
' < '.$langs->trans(
"Today");
3537 if (isModEnabled(
"supplier_order")) {
3538 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
3540 $qtydelivered = array();
3541 $qtywished = array();
3545 $filter = array(
't.fk_element' => $this->
id);
3547 $filter[
't.status'] = 1;
3550 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
3552 $this->error = $supplierorderdispatch->error;
3553 $this->errors = $supplierorderdispatch->errors;
3556 if (is_array($supplierorderdispatch->lines) && count($supplierorderdispatch->lines) > 0) {
3557 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
3561 foreach ($supplierorderdispatch->lines as $line) {
3562 if (array_key_exists($line->fk_product, $qtydelivered)) {
3563 $qtydelivered[$line->fk_product] += $line->qty;
3565 $qtydelivered[$line->fk_product] = $line->qty;
3568 foreach ($this->lines as $line) {
3573 if (array_key_exists($line->fk_product, $qtywished)) {
3574 $qtywished[$line->fk_product] += $line->qty;
3576 $qtywished[$line->fk_product] = $line->qty;
3581 $diff_array = array_diff_assoc($qtydelivered, $qtywished);
3582 $keysinwishednotindelivered = array_diff(array_keys($qtywished), array_keys($qtydelivered));
3583 $keysindeliverednotinwished = array_diff(array_keys($qtydelivered), array_keys($qtywished));
3591 if (count($diff_array) == 0 && count($keysinwishednotindelivered) == 0 && count($keysindeliverednotinwished) == 0) {
3592 if ($closeopenorder) {
3594 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3602 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3613 if (count($diff_array) > 0) {
3617 foreach ($diff_array as $key => $value) {
3619 if ($qtydelivered[$key] >= $qtywished[$key]) {
3626 if ($close == count($diff_array)) {
3628 if ($closeopenorder) {
3629 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3636 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3644 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3652 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3674 $this->receptions = array();
3676 dol_syslog(get_class($this).
"::loadReceptions", LOG_DEBUG);
3678 $sql =
'SELECT cd.rowid, cd.fk_product,';
3679 $sql .=
' sum(cfd.qty) as qty';
3680 $sql .=
' FROM '.$this->db->prefix().
'receptiondet_batch as cfd,';
3681 if ($filtre_statut >= 0) {
3682 $sql .=
' '.$this->db->prefix().
'reception as e,';
3684 $sql .=
' '.$this->db->prefix().
'commande_fournisseurdet as cd';
3686 if ($filtre_statut >= 0) {
3687 $sql .=
' cfd.fk_reception = e.rowid AND';
3689 $sql .=
' cfd.fk_elementdet = cd.rowid';
3690 $sql .=
' AND cd.fk_commande ='.((int) $this->
id);
3691 if (isset($this->fk_product) && !empty($this->fk_product) > 0) {
3692 $sql .=
' AND cd.fk_product = '.((int) $this->fk_product);
3694 if ($filtre_statut >= 0) {
3695 $sql .=
' AND e.fk_statut >= '.((int) $filtre_statut);
3697 $sql .=
' GROUP BY cd.rowid, cd.fk_product';
3699 $resql = $this->db->query($sql);
3701 $num = $this->db->num_rows($resql);
3704 $obj = $this->db->fetch_object($resql);
3705 empty($this->receptions[$obj->rowid]) ? $this->receptions[$obj->rowid] = $obj->qty : $this->receptions[$obj->rowid] += $obj->qty;
3708 $this->db->free($resql);
3712 $this->error = $this->db->lasterror();
3728 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3730 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3731 $return .=
'<div class="info-box info-box-sm">';
3732 $return .=
'<span class="info-box-icon bg-infobox-action">';
3734 $return .=
'</span>';
3735 $return .=
'<div class="info-box-content">';
3736 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
3737 if ($selected >= 0) {
3738 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3740 if (property_exists($this,
'socid') || property_exists($this,
'total_tva')) {
3741 $return .=
'<br><span class="info-box-label amount">'.$this->socid.
'</span>';
3743 if (property_exists($this,
'billed')) {
3744 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Billed").
' : </span><span class="info-box-label">'.
yn($this->billed).
'</span>';
3746 if (method_exists($this,
'getLibStatut')) {
3747 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
3749 $return .=
'</div>';
3750 $return .=
'</div>';
3751 $return .=
'</div>';
3766 public $element =
'commande_fournisseurdet';
3771 public $table_element =
'commande_fournisseurdet';
3789 public $fk_commande;
3795 public $fk_parent_line;
3807 public $special_code = 0;
3817 public $fk_fournprice;
3827 public $ref_supplier;
3857 $sql =
'SELECT cd.rowid, cd.fk_commande, cd.fk_product, cd.product_type, cd.description, cd.qty, cd.tva_tx, cd.special_code,';
3858 $sql .=
' cd.localtax1_tx, cd.localtax2_tx, cd.localtax1_type, cd.localtax2_type, cd.ref as ref_supplier,';
3859 $sql .=
' cd.remise, cd.remise_percent, cd.subprice,';
3860 $sql .=
' cd.info_bits, cd.total_ht, cd.total_tva, cd.total_ttc,';
3861 $sql .=
' cd.total_localtax1, cd.total_localtax2,';
3862 $sql .=
' p.ref as product_ref, p.label as product_label, p.description as product_desc,';
3863 $sql .=
' cd.date_start, cd.date_end, cd.fk_unit,';
3864 $sql .=
' cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc,';
3865 $sql .=
' c.fk_soc as socid';
3866 $sql .=
' FROM '.$this->db->prefix().
'commande_fournisseur as c, '.$this->db->prefix().
'commande_fournisseurdet as cd';
3867 $sql .=
' LEFT JOIN '.$this->db->prefix().
'product as p ON cd.fk_product = p.rowid';
3868 $sql .=
' WHERE cd.fk_commande = c.rowid AND cd.rowid = '.((int) $rowid);
3870 $result = $this->db->query($sql);
3872 $objp = $this->db->fetch_object($result);
3874 if (!empty($objp)) {
3875 $this->
rowid = $objp->rowid;
3876 $this->
id = $objp->rowid;
3877 $this->fk_commande = $objp->fk_commande;
3878 $this->desc = $objp->description;
3879 $this->qty = $objp->qty;
3880 $this->ref_fourn = $objp->ref_supplier;
3881 $this->ref_supplier = $objp->ref_supplier;
3882 $this->subprice = $objp->subprice;
3883 $this->tva_tx = $objp->tva_tx;
3884 $this->localtax1_tx = $objp->localtax1_tx;
3885 $this->localtax2_tx = $objp->localtax2_tx;
3886 $this->localtax1_type = $objp->localtax1_type;
3887 $this->localtax2_type = $objp->localtax2_type;
3888 $this->remise = $objp->remise;
3889 $this->remise_percent = $objp->remise_percent;
3890 $this->fk_product = $objp->fk_product;
3891 $this->info_bits = $objp->info_bits;
3892 $this->total_ht = $objp->total_ht;
3893 $this->total_tva = $objp->total_tva;
3894 $this->total_localtax1 = $objp->total_localtax1;
3895 $this->total_localtax2 = $objp->total_localtax2;
3896 $this->total_ttc = $objp->total_ttc;
3897 $this->product_type = $objp->product_type;
3898 $this->special_code = $objp->special_code;
3900 $this->
ref = $objp->product_ref;
3902 $this->product_ref = $objp->product_ref;
3903 $this->product_label = $objp->product_label;
3904 $this->product_desc = $objp->product_desc;
3911 $sqlsearchpackage =
'SELECT rowid, packaging FROM '.$this->db->prefix().
"product_fournisseur_price";
3912 $sqlsearchpackage .=
' WHERE entity IN ('.getEntity(
'product_fournisseur_price').
")";
3913 $sqlsearchpackage .=
" AND fk_product = ".((int) $objp->fk_product);
3914 $sqlsearchpackage .=
" AND ref_fourn = '".$this->db->escape($objp->ref_supplier).
"'";
3915 $sqlsearchpackage .=
" AND quantity <= ".((float) $objp->qty);
3916 $sqlsearchpackage .=
" AND (packaging IS NULL OR packaging = 0 OR packaging <= ".((float) $objp->qty).
")";
3917 $sqlsearchpackage .=
" AND fk_soc = ".((int) $objp->socid);
3918 $sqlsearchpackage .=
" ORDER BY packaging ASC";
3919 $sqlsearchpackage .=
" LIMIT 1";
3921 $resqlsearchpackage = $this->db->query($sqlsearchpackage);
3922 if ($resqlsearchpackage) {
3923 $objsearchpackage = $this->db->fetch_object($resqlsearchpackage);
3924 if ($objsearchpackage) {
3925 $this->fk_fournprice = $objsearchpackage->rowid;
3926 $this->packaging = $objsearchpackage->packaging;
3929 $this->error = $this->db->lasterror();
3934 $this->date_start = $this->db->jdate($objp->date_start);
3935 $this->date_end = $this->db->jdate($objp->date_end);
3936 $this->fk_unit = $objp->fk_unit;
3938 $this->multicurrency_subprice = $objp->multicurrency_subprice;
3939 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
3940 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
3941 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
3945 $this->db->free($result);
3948 $this->error =
'Supplier order line with id='.$rowid.
' not found';
3949 dol_syslog(get_class($this).
"::fetch Error ".$this->error, LOG_ERR);
3966 global $conf, $user;
3970 dol_syslog(get_class($this).
"::insert rang=".$this->rang);
3973 if (empty($this->tva_tx)) {
3976 if (empty($this->localtax1_tx)) {
3977 $this->localtax1_tx = 0;
3979 if (empty($this->localtax2_tx)) {
3980 $this->localtax2_tx = 0;
3982 if (empty($this->localtax1_type)) {
3983 $this->localtax1_type =
'0';
3985 if (empty($this->localtax2_type)) {
3986 $this->localtax2_type =
'0';
3988 if (empty($this->total_localtax1)) {
3989 $this->total_localtax1 = 0;
3991 if (empty($this->total_localtax2)) {
3992 $this->total_localtax2 = 0;
3994 if (empty($this->rang)) {
3997 if (empty($this->remise_percent)) {
3998 $this->remise_percent = 0;
4000 if (empty($this->info_bits)) {
4001 $this->info_bits = 0;
4003 if (empty($this->special_code)) {
4004 $this->special_code = 0;
4006 if (empty($this->fk_parent_line)) {
4007 $this->fk_parent_line = 0;
4009 if (empty($this->pa_ht)) {
4014 if (!empty($this->multicurrency_code)) {
4017 if (empty($this->fk_multicurrency)) {
4018 $this->multicurrency_code = $conf->currency;
4019 $this->fk_multicurrency = 0;
4020 $this->multicurrency_tx = 1;
4024 if ($this->product_type < 0) {
4031 $sql =
'INSERT INTO '.$this->db->prefix().$this->table_element;
4032 $sql .=
" (fk_commande, label, description, date_start, date_end,";
4033 $sql .=
" fk_product, product_type, special_code, rang,";
4034 $sql .=
" qty, vat_src_code, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, remise_percent, subprice, ref,";
4035 $sql .=
" total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_unit,";
4036 $sql .=
" fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc,";
4037 $sql .=
" fk_parent_line)";
4038 $sql .=
" VALUES (".$this->fk_commande.
", '".$this->db->escape($this->label).
"','".$this->db->escape($this->desc).
"',";
4039 $sql .=
" ".($this->date_start ?
"'".$this->db->idate($this->date_start).
"'" :
"null").
",";
4040 $sql .=
" ".($this->date_end ?
"'".$this->db->idate($this->date_end).
"'" :
"null").
",";
4041 if ($this->fk_product) {
4042 $sql .= $this->fk_product.
",";
4046 $sql .=
"'".$this->db->escape($this->product_type).
"',";
4047 $sql .= (int) $this->special_code .
",";
4048 $sql .=
"'".$this->db->escape($this->rang).
"',";
4049 $sql .=
"'".$this->db->escape($this->qty).
"', ";
4050 $sql .=
" ".(empty($this->vat_src_code) ?
"''" :
"'".$this->db->escape($this->vat_src_code).
"'").
",";
4051 $sql .=
" ".price2num($this->tva_tx).
", ";
4052 $sql .=
" ".price2num($this->localtax1_tx).
",";
4053 $sql .=
" ".price2num($this->localtax2_tx).
",";
4054 $sql .=
" '".$this->db->escape($this->localtax1_type).
"',";
4055 $sql .=
" '".$this->db->escape($this->localtax2_type).
"',";
4056 $sql .=
" ".((float) $this->remise_percent).
", ".
price2num($this->subprice,
'MU').
", '".$this->db->escape($this->ref_supplier).
"',";
4057 $sql .=
" ".price2num($this->total_ht).
",";
4058 $sql .=
" ".price2num($this->total_tva).
",";
4059 $sql .=
" ".price2num($this->total_localtax1).
",";
4060 $sql .=
" ".price2num($this->total_localtax2).
",";
4061 $sql .=
" ".price2num($this->total_ttc).
",";
4062 $sql .= ($this->fk_unit ?
"'".$this->db->escape($this->fk_unit).
"'" :
"null");
4063 $sql .=
", ".($this->fk_multicurrency ? ((int) $this->fk_multicurrency) :
"null");
4064 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
4065 $sql .=
", ".($this->multicurrency_subprice ?
price2num($this->multicurrency_subprice) :
'0');
4066 $sql .=
", ".($this->multicurrency_total_ht ?
price2num($this->multicurrency_total_ht) :
'0');
4067 $sql .=
", ".($this->multicurrency_total_tva ?
price2num($this->multicurrency_total_tva) :
'0');
4068 $sql .=
", ".($this->multicurrency_total_ttc ?
price2num($this->multicurrency_total_ttc) :
'0');
4069 $sql .=
", ".((!empty($this->fk_parent_line) && $this->fk_parent_line > 0) ? $this->fk_parent_line :
'null');
4072 dol_syslog(get_class($this).
"::insert", LOG_DEBUG);
4073 $resql = $this->db->query($sql);
4075 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
4076 $this->
rowid = $this->id;
4085 if (!$error && !$notrigger) {
4087 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_CREATE', $user);
4095 $this->db->commit();
4099 foreach ($this->errors as $errmsg) {
4100 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
4101 $this->errors[] = ($this->errors ?
', '.$errmsg : $errmsg);
4103 $this->db->rollback();
4106 $this->errors[] = $this->db->error();
4107 $this->db->rollback();
4126 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
4127 $sql .=
" description='".$this->db->escape($this->desc).
"'";
4128 $sql .=
", ref='".$this->db->escape($this->ref_supplier).
"'";
4129 $sql .=
", subprice='".price2num($this->subprice).
"'";
4131 $sql .=
", remise_percent='".price2num($this->remise_percent).
"'";
4133 $sql .=
", vat_src_code = '".(empty($this->vat_src_code) ?
'' : $this->vat_src_code).
"'";
4134 $sql .=
", tva_tx='".price2num($this->tva_tx).
"'";
4135 $sql .=
", localtax1_tx='".price2num($this->localtax1_tx).
"'";
4136 $sql .=
", localtax2_tx='".price2num($this->localtax2_tx).
"'";
4137 $sql .=
", localtax1_type='".$this->db->escape($this->localtax1_type).
"'";
4138 $sql .=
", localtax2_type='".$this->db->escape($this->localtax2_type).
"'";
4139 $sql .=
", qty='".price2num($this->qty).
"'";
4140 $sql .=
", date_start=".(!empty($this->date_start) ?
"'".$this->db->idate($this->date_start).
"'" :
"null");
4141 $sql .=
", date_end=".(!empty($this->date_end) ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
4142 $sql .=
", info_bits='".$this->db->escape($this->info_bits).
"'";
4143 $sql .=
", total_ht='".price2num($this->total_ht).
"'";
4144 $sql .=
", total_tva='".price2num($this->total_tva).
"'";
4145 $sql .=
", total_localtax1='".price2num($this->total_localtax1).
"'";
4146 $sql .=
", total_localtax2='".price2num($this->total_localtax2).
"'";
4147 $sql .=
", total_ttc='".price2num($this->total_ttc).
"'";
4148 $sql .=
", product_type=".$this->product_type;
4149 $sql .=
", special_code=".(!empty($this->special_code) ? $this->special_code : 0);
4150 $sql .= ($this->fk_unit ?
", fk_unit='".$this->db->escape($this->fk_unit).
"'" :
", fk_unit=null");
4153 $sql .=
", multicurrency_subprice=".price2num($this->multicurrency_subprice);
4154 $sql .=
", multicurrency_total_ht=".price2num($this->multicurrency_total_ht);
4155 $sql .=
", multicurrency_total_tva=".price2num($this->multicurrency_total_tva);
4156 $sql .=
", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc);
4158 $sql .=
" WHERE rowid = ".((int) $this->
id);
4160 dol_syslog(get_class($this).
"::updateline", LOG_DEBUG);
4161 $resql = $this->db->query($sql);
4170 if (!$error && !$notrigger) {
4172 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_MODIFY', $user);
4174 $this->db->rollback();
4181 $this->db->commit();
4184 $this->db->rollback();
4188 $this->error = $this->db->lasterror();
4189 $this->db->rollback();
4201 public function delete($user, $notrigger = 0)
4214 $this->db->rollback();
4218 $sql1 =
'UPDATE '.$this->db->prefix().
"commandedet SET fk_commandefourndet = NULL WHERE fk_commandefourndet=".((int) $this->
id);
4219 $resql = $this->db->query($sql1);
4221 $this->db->rollback();
4225 $sql2 =
'DELETE FROM '.$this->db->prefix().
"commande_fournisseurdet WHERE rowid=".((int) $this->
id);
4228 $resql = $this->db->query($sql2);
4232 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_DELETE', $user);
4240 $this->db->commit();
4244 foreach ($this->errors as $errmsg) {
4245 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
4246 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
4248 $this->db->rollback();
4251 $this->error = $this->db->lasterror();
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Or an array listing all the potential status of the object: array: int of the status => translated la...
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 clicable 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 clicable 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
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.
update($notrigger=0)
Update the line object into db.
insert($notrigger=0)
Insert line into database.
fetch($rowid)
Load line order.
__construct($db)
Constructor.
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.
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.
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.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
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)
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...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
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 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.
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e e e e e statut
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall TAKEPOS_SHOW_SUBPRICE right right right takeposterminal SELECT e rowid