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 .=
', c.last_main_doc';
483 $sql .=
', i.libelle as label_incoterms';
484 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as c";
485 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_payment_term as cr ON c.fk_cond_reglement = cr.rowid";
486 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_paiement as p ON c.fk_mode_reglement = p.id";
487 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_input_method as cm ON cm.rowid = c.fk_input_method";
488 $sql .=
' LEFT JOIN '.$this->db->prefix().
'c_incoterms as i ON c.fk_incoterms = i.rowid';
491 $sql .=
" WHERE c.entity IN (".getEntity(
'supplier_order').
")";
493 $sql .=
" WHERE c.rowid=".((int) $id);
497 $sql .=
" AND c.ref='".$this->db->escape($ref).
"'";
500 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
501 $resql = $this->db->query($sql);
503 $obj = $this->db->fetch_object($resql);
505 $this->error =
'Bill with id '.$id.
' not found';
506 dol_syslog(get_class($this).
'::fetch '.$this->error);
510 $this->
id = $obj->rowid;
511 $this->entity = $obj->entity;
513 $this->
ref = $obj->ref;
514 $this->ref_supplier = $obj->ref_supplier;
515 $this->socid = $obj->fk_soc;
516 $this->fourn_id = $obj->fk_soc;
517 $this->
statut = $obj->status;
518 $this->
status = $obj->status;
519 $this->billed = $obj->billed;
520 $this->last_main_doc = $obj->last_main_doc;
521 $this->user_author_id = $obj->user_author_id;
522 $this->user_validation_id = $obj->user_validation_id;
523 $this->user_approve_id = $obj->user_approve_id;
524 $this->user_approve_id2 = $obj->user_approve_id2;
525 $this->total_ht = $obj->total_ht;
526 $this->total_tva = $obj->total_tva;
527 $this->total_localtax1 = $obj->localtax1;
528 $this->total_localtax2 = $obj->localtax2;
529 $this->total_ttc = $obj->total_ttc;
530 $this->date_creation = $this->db->jdate($obj->date_creation);
531 $this->date_valid = $this->db->jdate($obj->date_valid);
532 $this->date_approve = $this->db->jdate($obj->date_approve);
533 $this->date_approve2 = $this->db->jdate($obj->date_approve2);
534 $this->date_commande = $this->db->jdate($obj->date_commande);
535 if (isset($obj->date_commande)) {
536 $this->date = $this->date_commande;
538 $this->date = $this->date_creation;
540 $this->delivery_date = $this->db->jdate($obj->delivery_date);
541 $this->remise_percent = $obj->remise_percent;
542 $this->methode_commande_id = $obj->fk_input_method;
543 $this->methode_commande = $obj->methode_commande;
545 $this->source = $obj->source;
546 $this->fk_project = $obj->fk_project;
547 $this->cond_reglement_id = $obj->fk_cond_reglement;
548 $this->cond_reglement_code = $obj->cond_reglement_code;
549 $this->cond_reglement = $obj->cond_reglement_label;
550 $this->cond_reglement_label = $obj->cond_reglement_label;
551 $this->cond_reglement_doc = $obj->cond_reglement_doc;
552 $this->fk_account = $obj->fk_account;
553 $this->mode_reglement_id = $obj->fk_mode_reglement;
554 $this->mode_reglement_code = $obj->mode_reglement_code;
555 $this->mode_reglement = $obj->mode_reglement_libelle;
556 $this->note = $obj->note_private;
557 $this->note_private = $obj->note_private;
558 $this->note_public = $obj->note_public;
559 $this->model_pdf = $obj->model_pdf;
562 $this->fk_incoterms = $obj->fk_incoterms;
563 $this->location_incoterms = $obj->location_incoterms;
564 $this->label_incoterms = $obj->label_incoterms;
567 $this->fk_multicurrency = $obj->fk_multicurrency;
568 $this->multicurrency_code = $obj->multicurrency_code;
569 $this->multicurrency_tx = $obj->multicurrency_tx;
570 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
571 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
572 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
574 $this->extraparams = isset($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
576 $this->db->free($resql);
591 $this->error = $this->db->error().
" sql=".$sql;
607 $this->lines = array();
609 $sql =
"SELECT l.rowid, l.fk_commande, l.ref as ref_supplier, l.fk_product, l.product_type, l.label, l.description, l.qty,";
610 $sql .=
" l.vat_src_code, l.tva_tx, l.remise_percent, l.subprice,";
611 $sql .=
" l.localtax1_tx, l. localtax2_tx, l.localtax1_type, l. localtax2_type, l.total_localtax1, l.total_localtax2,";
612 $sql .=
" l.total_ht, l.total_tva, l.total_ttc, l.info_bits, l.special_code, l.fk_parent_line, l.rang,";
613 $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,";
614 $sql .=
" l.fk_unit,";
615 $sql .=
" l.date_start, l.date_end,";
616 $sql .=
' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc';
617 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseurdet as l";
618 $sql .=
' LEFT JOIN '.$this->db->prefix().
'product as p ON l.fk_product = p.rowid';
619 $sql .=
" WHERE l.fk_commande = ".((int) $this->
id);
621 $sql .=
' AND p.fk_product_type = 0';
623 $sql .=
" ORDER BY l.rang, l.rowid";
626 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
628 $result = $this->db->query($sql);
630 $num = $this->db->num_rows($result);
634 $objp = $this->db->fetch_object($result);
638 $line->id = $objp->rowid;
639 $line->fk_commande = $objp->fk_commande;
640 $line->desc = $objp->description;
641 $line->description = $objp->description;
642 $line->qty = $objp->qty;
643 $line->tva_tx = $objp->tva_tx;
644 $line->localtax1_tx = $objp->localtax1_tx;
645 $line->localtax2_tx = $objp->localtax2_tx;
646 $line->localtax1_type = $objp->localtax1_type;
647 $line->localtax2_type = $objp->localtax2_type;
648 $line->subprice = $objp->subprice;
649 $line->pu_ht = $objp->subprice;
650 $line->remise_percent = $objp->remise_percent;
652 $line->vat_src_code = $objp->vat_src_code;
653 $line->total_ht = $objp->total_ht;
654 $line->total_tva = $objp->total_tva;
655 $line->total_localtax1 = $objp->total_localtax1;
656 $line->total_localtax2 = $objp->total_localtax2;
657 $line->total_ttc = $objp->total_ttc;
658 $line->product_type = $objp->product_type;
660 $line->fk_product = $objp->fk_product;
662 $line->libelle = $objp->product_label;
663 $line->product_label = $objp->product_label;
664 $line->product_desc = $objp->product_desc;
665 $line->product_tobatch = $objp->product_tobatch;
666 $line->product_barcode = $objp->product_barcode;
668 $line->ref = $objp->product_ref;
669 $line->product_ref = $objp->product_ref;
670 $line->ref_fourn = $objp->ref_supplier;
671 $line->ref_supplier = $objp->ref_supplier;
678 $sqlsearchpackage =
'SELECT rowid, packaging FROM '.$this->db->prefix().
"product_fournisseur_price";
679 $sqlsearchpackage .=
' WHERE entity IN ('.getEntity(
'product_fournisseur_price').
")";
680 $sqlsearchpackage .=
" AND fk_product = ".((int) $objp->fk_product);
681 $sqlsearchpackage .=
" AND ref_fourn = '".$this->db->escape($objp->ref_supplier).
"'";
682 $sqlsearchpackage .=
" AND quantity <= ".((float) $objp->qty);
683 $sqlsearchpackage .=
" AND (packaging IS NULL OR packaging = 0 OR packaging <= ".((float) $objp->qty).
")";
684 $sqlsearchpackage .=
" AND fk_soc = ".((int) $this->socid);
685 $sqlsearchpackage .=
" ORDER BY packaging ASC";
686 $sqlsearchpackage .=
" LIMIT 1";
688 $resqlsearchpackage = $this->db->query($sqlsearchpackage);
689 if ($resqlsearchpackage) {
690 $objsearchpackage = $this->db->fetch_object($resqlsearchpackage);
691 if ($objsearchpackage) {
692 $line->fk_fournprice = $objsearchpackage->rowid;
693 $line->packaging = $objsearchpackage->packaging;
696 $this->error = $this->db->lasterror();
701 $line->date_start = $this->db->jdate($objp->date_start);
702 $line->date_end = $this->db->jdate($objp->date_end);
703 $line->fk_unit = $objp->fk_unit;
706 $line->fk_multicurrency = $objp->fk_multicurrency;
707 $line->multicurrency_code = $objp->multicurrency_code;
708 $line->multicurrency_subprice = $objp->multicurrency_subprice;
709 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
710 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
711 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
713 $line->info_bits = $objp->info_bits;
714 $line->special_code = $objp->special_code;
715 $line->fk_parent_line = $objp->fk_parent_line;
717 $line->rang = $objp->rang;
721 $line->fetch_optionals();
723 $this->lines[$i] = $line;
727 $this->db->free($result);
731 $this->error = $this->db->error().
" sql=".$sql;
744 public function valid($user, $idwarehouse = 0, $notrigger = 0)
747 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
753 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")))
754 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"fournisseur",
"supplier_order_advance",
"validate"))) {
759 $soc->fetch($this->fourn_id);
762 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
769 $sql =
'UPDATE '.$this->db->prefix().
"commande_fournisseur";
770 $sql .=
" SET ref='".$this->db->escape($num).
"',";
771 $sql .=
" fk_statut = ".((int) self::STATUS_VALIDATED).
",";
772 $sql .=
" date_valid='".$this->db->idate(
dol_now()).
"',";
773 $sql .=
" fk_user_valid = ".((int) $user->id);
774 $sql .=
" WHERE rowid = ".((int) $this->
id);
775 $sql .=
" AND fk_statut = ".((int) self::STATUS_DRAFT);
777 $resql = $this->db->query($sql);
783 if (!$error && !$notrigger) {
785 $result = $this->
call_trigger(
'ORDER_SUPPLIER_VALIDATE', $user);
793 $this->oldref = $this->ref;
796 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
798 $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).
"'";
799 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'fournisseur/commande/".$this->db->escape($this->
ref).
"' and entity = ".((int) $conf->entity);
800 $resql = $this->db->query($sql);
803 $this->error = $this->db->lasterror();
805 $sql =
'UPDATE '.$this->db->prefix().
"ecm_files set filepath = 'fournisseur/commande/".$this->db->escape($this->newref).
"'";
806 $sql .=
" WHERE filepath = 'fournisseur/commande/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
807 $resql = $this->db->query($sql);
810 $this->error = $this->db->lasterror();
816 $dirsource = $conf->fournisseur->commande->dir_output.
'/'.$oldref;
817 $dirdest = $conf->fournisseur->commande->dir_output.
'/'.$newref;
818 if (!$error && file_exists($dirsource)) {
819 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
821 if (@rename($dirsource, $dirdest)) {
824 $listoffiles =
dol_dir_list($conf->fournisseur->commande->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
825 foreach ($listoffiles as $fileentry) {
826 $dirsource = $fileentry[
'name'];
827 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
828 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
829 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
830 @rename($dirsource, $dirdest);
848 $this->db->rollback();
852 $this->error =
'NotAuthorized';
853 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
878 public function LibStatut($status, $mode = 0, $billed = 0)
881 global $langs, $hookmanager;
883 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
884 $langs->load(
'orders');
886 $this->labelStatus[0] =
'StatusSupplierOrderDraft';
887 $this->labelStatus[1] =
'StatusSupplierOrderValidated';
888 $this->labelStatus[2] =
'StatusSupplierOrderApproved';
890 $this->labelStatus[3] =
'StatusSupplierOrderOnProcess';
892 $this->labelStatus[3] =
'StatusSupplierOrderOnProcessWithValidation';
894 $this->labelStatus[4] =
'StatusSupplierOrderReceivedPartially';
895 $this->labelStatus[5] =
'StatusSupplierOrderReceivedAll';
896 $this->labelStatus[6] =
'StatusSupplierOrderCanceled';
897 $this->labelStatus[7] =
'StatusSupplierOrderCanceled';
898 $this->labelStatus[9] =
'StatusSupplierOrderRefused';
901 $this->labelStatusShort[0] =
'StatusSupplierOrderDraftShort';
902 $this->labelStatusShort[1] =
'StatusSupplierOrderValidatedShort';
903 $this->labelStatusShort[2] =
'StatusSupplierOrderApprovedShort';
904 $this->labelStatusShort[3] =
'StatusSupplierOrderOnProcessShort';
905 $this->labelStatusShort[4] =
'StatusSupplierOrderReceivedPartiallyShort';
906 $this->labelStatusShort[5] =
'StatusSupplierOrderReceivedAllShort';
907 $this->labelStatusShort[6] =
'StatusSupplierOrderCanceledShort';
908 $this->labelStatusShort[7] =
'StatusSupplierOrderCanceledShort';
909 $this->labelStatusShort[9] =
'StatusSupplierOrderRefusedShort';
912 $statustrans = array(
924 $statusClass =
'status0';
925 if (!empty($statustrans[$status])) {
926 $statusClass = $statustrans[$status];
931 $billedtext =
' - '.$langs->trans(
"Billed");
933 if ($status == 5 && $billed) {
934 $statusClass =
'status6';
937 $statusLong = $langs->transnoentitiesnoconv($this->labelStatus[$status]).$billedtext;
938 $statusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
940 $parameters = array(
'status' => $status,
'mode' => $mode,
'billed' => $billed);
941 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
943 return $hookmanager->resPrint;
946 return dolGetStatus($statusLong, $statusShort,
'', $statusClass, $mode);
958 global $conf, $langs, $user;
960 $langs->loadLangs([
'bills',
'orders']);
963 $nofetch = !empty($params[
'nofetch']);
965 if ($user->hasRight(
"fournisseur",
"commande",
"read")) {
966 $datas[
'picto'] =
'<u class="paddingrightonly">'.$langs->trans(
"SupplierOrder").
'</u>';
967 if (isset($this->
statut)) {
968 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
970 if (!empty($this->
ref)) {
971 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
973 if (!empty($this->ref_supplier)) {
974 $datas[
'refsupplier'] =
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.$this->ref_supplier;
977 $langs->load(
'companies');
978 if (empty($this->thirdparty)) {
981 $datas[
'supplier'] =
'<br><b>'.$langs->trans(
'Supplier').
':</b> '.$this->thirdparty->getNomUrl(1,
'', 0, 1);
983 if (!empty($this->total_ht)) {
984 $datas[
'totalht'] =
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
986 if (!empty($this->total_tva)) {
987 $datas[
'totaltva'] =
'<br><b>'.$langs->trans(
'VAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
989 if (!empty($this->total_ttc)) {
990 $datas[
'totalttc'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
992 if (!empty($this->date)) {
993 $datas[
'date'] =
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->date,
'day');
995 if (!empty($this->delivery_date)) {
996 $datas[
'deliverydate'] =
'<br><b>'.$langs->trans(
'DeliveryDate').
':</b> '.
dol_print_date($this->delivery_date,
'dayhour');
1012 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = 0)
1014 global $langs, $user, $hookmanager;
1019 'objecttype' => $this->element,
1020 'option' => $option,
1023 $classfortooltip =
'classfortooltip';
1026 $classfortooltip =
'classforajaxtooltip';
1027 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1033 $url = DOL_URL_ROOT.
'/fourn/commande/card.php?id='.$this->id;
1035 if ($option !==
'nolink') {
1037 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1038 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1039 $add_save_lastsearch_values = 1;
1041 if ($add_save_lastsearch_values) {
1042 $url .=
'&save_lastsearch_values=1';
1047 if (empty($notooltip)) {
1049 $label = $langs->trans(
"ShowOrder");
1050 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1052 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1053 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
1056 $linkstart =
'<a href="'.$url.
'"';
1057 $linkstart .= $linkclose.
'>';
1060 $result .= $linkstart;
1062 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
1064 if ($withpicto != 2) {
1065 $result .= $this->ref;
1067 $result .= $linkend;
1069 if ($addlinktonotes) {
1070 $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
1073 $result .=
' <span class="note inline-block">';
1074 $result .=
'<a href="'.DOL_URL_ROOT.
'/fourn/commande/note.php?id='.$this->
id.
'" class="classfortooltip" title="'.
dol_escape_htmltag($notetoshow).
'">';
1079 $result .=
'</span>';
1084 $hookmanager->initHooks(array($this->element .
'dao'));
1085 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1086 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1088 $result = $hookmanager->resPrint;
1090 $result .= $hookmanager->resPrint;
1105 global $langs, $conf;
1106 $langs->load(
"orders");
1115 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
1117 foreach ($dirmodels as $reldir) {
1118 $dir =
dol_buildpath($reldir.
"core/modules/supplier_order/");
1121 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1124 if ($mybool ===
false) {
1129 $obj =
new $classname();
1130 $numref = $obj->getNextValue($soc, $this);
1132 if ($numref !=
"") {
1135 $this->error = $obj->error;
1139 $this->error =
"Error_COMMANDE_SUPPLIER_ADDON_NotDefined";
1153 if ($this->billed) {
1159 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur SET billed = 1';
1162 if ($this->db->query($sql)) {
1165 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CLASSIFY_BILLED', $user);
1175 $this->db->commit();
1178 $this->db->rollback();
1184 $this->db->rollback();
1197 public function approve($user, $idwarehouse = 0, $secondlevel = 0)
1199 global $langs, $conf;
1200 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1206 if ($user->hasRight(
"fournisseur",
"commande",
"approuver")) {
1212 $soc =
new Societe($this->db);
1213 $soc->fetch($this->fourn_id);
1216 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
1224 $movetoapprovestatus =
true;
1227 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1228 $sql .=
" SET ref='".$this->db->escape($num).
"',";
1229 if (empty($secondlevel)) {
1230 $sql .=
" date_approve='".$this->db->idate($now).
"',";
1231 $sql .=
" fk_user_approve = ".$user->id;
1232 if (
getDolGlobalString(
'SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED') && $this->total_ht >= $conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) {
1233 if (empty($this->user_approve_id2)) {
1234 $movetoapprovestatus =
false;
1235 $comment =
' (first level)';
1239 $sql .=
" date_approve2='".$this->db->idate($now).
"',";
1240 $sql .=
" fk_user_approve2 = ".((int) $user->id);
1241 if (empty($this->user_approve_id)) {
1242 $movetoapprovestatus =
false;
1244 $comment =
' (second level)';
1247 if ($movetoapprovestatus) {
1248 $sql .=
", fk_statut = ".self::STATUS_ACCEPTED;
1250 $sql .=
", fk_statut = ".self::STATUS_VALIDATED;
1252 $sql .=
" WHERE rowid = ".((int) $this->
id);
1253 $sql .=
" AND fk_statut = ".self::STATUS_VALIDATED;
1255 if ($this->db->query($sql)) {
1257 $result = $this->
add_contact($user->id,
'SALESREPFOLL',
'internal', 1);
1258 if ($result < 0 && $result != -2) {
1264 if (!$error && $movetoapprovestatus && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER')) {
1265 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1266 $langs->load(
"agenda");
1268 $cpt = count($this->lines);
1269 for ($i = 0; $i < $cpt; $i++) {
1271 if ($this->lines[$i]->fk_product > 0) {
1272 $this->line = $this->lines[$i];
1274 $mouvP->origin = &$this;
1275 $mouvP->setOrigin($this->element, $this->
id);
1277 $up_ht_disc = $this->lines[$i]->subprice;
1278 if (!empty($this->lines[$i]->remise_percent) && !
getDolGlobalString(
'STOCK_EXCLUDE_DISCOUNT_FOR_PMP')) {
1279 $up_ht_disc =
price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100,
'MU');
1281 $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans(
"OrderApprovedInDolibarr", $this->ref));
1292 $result = $this->
call_trigger(
'ORDER_SUPPLIER_APPROVE', $user);
1300 $this->
ref = $this->newref;
1302 if ($movetoapprovestatus) {
1307 if (empty($secondlevel)) {
1308 $this->date_approve = $now;
1309 $this->user_approve_id = $user->id;
1311 $this->date_approve2 = $now;
1312 $this->user_approve_id2 = $user->id;
1315 $this->db->commit();
1318 $this->db->rollback();
1322 $this->db->rollback();
1323 $this->error = $this->db->lasterror();
1327 dol_syslog(get_class($this).
"::approve Not Authorized", LOG_ERR);
1340 global $conf, $langs;
1346 if ($user->hasRight(
"fournisseur",
"commande",
"approuver")) {
1349 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur SET fk_statut = ".
self::STATUS_REFUSED;
1350 $sql .=
" WHERE rowid = ".((int) $this->
id);
1352 if ($this->db->query($sql)) {
1357 $result = $this->
call_trigger(
'ORDER_SUPPLIER_REFUSE', $user);
1360 $this->db->rollback();
1362 $this->db->commit();
1367 $this->db->rollback();
1368 $this->error = $this->db->lasterror();
1369 dol_syslog(get_class($this).
"::refuse Error -1");
1373 dol_syslog(get_class($this).
"::refuse Not Authorized");
1387 public function Cancel($user, $idwarehouse = -1)
1390 global $langs, $conf;
1396 if ($user->hasRight(
"fournisseur",
"commande",
"commander")) {
1401 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur SET fk_statut = ".((int) $statut);
1402 $sql .=
" WHERE rowid = ".((int) $this->
id);
1403 dol_syslog(get_class($this).
"::cancel", LOG_DEBUG);
1404 if ($this->db->query($sql)) {
1408 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CANCEL', $user);
1415 $this->db->commit();
1418 $this->db->rollback();
1422 $this->db->rollback();
1423 $this->error = $this->db->lasterror();
1424 dol_syslog(get_class($this).
"::cancel ".$this->error);
1428 dol_syslog(get_class($this).
"::cancel Not Authorized");
1442 public function commande($user, $date, $methode, $comment =
'')
1447 if ($user->hasRight(
"fournisseur",
"commande",
"commander")) {
1450 $newnoteprivate = $this->note_private;
1452 $newnoteprivate =
dol_concatdesc($newnoteprivate, $langs->trans(
"Comment").
': '.$comment);
1455 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1456 $sql .=
" SET fk_statut=".self::STATUS_ORDERSENT.
", fk_input_method=".$methode.
", date_commande='".$this->db->idate($date).
"', ";
1457 $sql .=
" note_private='".$this->db->escape($newnoteprivate).
"'";
1458 $sql .=
" WHERE rowid=".((int) $this->
id);
1460 dol_syslog(get_class($this).
"::commande", LOG_DEBUG);
1461 if ($this->db->query($sql)) {
1463 $this->methode_commande_id = $methode;
1464 $this->date_commande = $date;
1465 $this->context = array(
'comments' => $comment);
1468 $result = $this->
call_trigger(
'ORDER_SUPPLIER_SUBMIT', $user);
1475 $this->error = $this->db->lasterror();
1476 $this->errors[] = $this->db->lasterror();
1480 $this->db->commit();
1482 $this->db->rollback();
1486 $this->error = $langs->trans(
'NotAuthorized');
1487 $this->errors[] = $langs->trans(
'NotAuthorized');
1488 dol_syslog(get_class($this).
"::commande User not Authorized", LOG_WARNING);
1491 return ($error ? -1 : 1);
1501 public function create($user, $notrigger = 0)
1503 global $langs, $conf, $hookmanager;
1511 $date = ($this->date_commande ? $this->date_commande : $this->date);
1515 $delivery_date = $this->delivery_date;
1518 if (empty($this->source)) {
1523 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
1528 if (empty($this->fk_multicurrency)) {
1529 $this->multicurrency_code = $conf->currency;
1530 $this->fk_multicurrency = 0;
1531 $this->multicurrency_tx = 1;
1538 $sql =
"INSERT INTO ".$this->db->prefix().
"commande_fournisseur (";
1540 $sql .=
", ref_supplier";
1541 $sql .=
", note_private";
1542 $sql .=
", note_public";
1545 $sql .=
", fk_projet";
1546 $sql .=
", date_creation";
1547 $sql .=
", date_livraison";
1548 $sql .=
", fk_user_author";
1549 $sql .=
", fk_statut";
1551 $sql .=
", model_pdf";
1552 $sql .=
", fk_mode_reglement";
1553 $sql .=
", fk_cond_reglement";
1554 $sql .=
", fk_account";
1555 $sql .=
", fk_incoterms, location_incoterms";
1556 $sql .=
", fk_multicurrency";
1557 $sql .=
", multicurrency_code";
1558 $sql .=
", multicurrency_tx";
1560 $sql .=
" VALUES (";
1562 $sql .=
", ".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"NULL");
1563 $sql .=
", '".$this->db->escape($this->note_private).
"'";
1564 $sql .=
", '".$this->db->escape($this->note_public).
"'";
1565 $sql .=
", ".setEntity($this);
1566 $sql .=
", ".((int) $this->socid);
1567 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
1568 $sql .=
", '".$this->db->idate($date).
"'";
1569 $sql .=
", ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
"null");
1570 $sql .=
", ".((int) $user->id);
1571 $sql .=
", ".self::STATUS_DRAFT;
1572 $sql .=
", ".((int) $this->source);
1573 $sql .=
", '".$this->db->escape(
getDolGlobalString(
'COMMANDE_SUPPLIER_ADDON_PDF')).
"'";
1574 $sql .=
", ".($this->mode_reglement_id > 0 ? $this->mode_reglement_id :
'null');
1575 $sql .=
", ".($this->cond_reglement_id > 0 ? $this->cond_reglement_id :
'null');
1576 $sql .=
", ".($this->fk_account > 0 ? $this->fk_account :
'NULL');
1577 $sql .=
", ".(int) $this->fk_incoterms;
1578 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
1579 $sql .=
", ".(int) $this->fk_multicurrency;
1580 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1581 $sql .=
", ".(float) $this->multicurrency_tx;
1584 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1585 if ($this->db->query($sql)) {
1586 $this->
id = $this->db->last_insert_id($this->db->prefix().
"commande_fournisseur");
1589 $num = count($this->lines);
1592 for ($i = 0; $i < $num; $i++) {
1593 $line = $this->lines[$i];
1594 if (!is_object($line)) {
1595 $line = (object) $line;
1606 $line->localtax1_tx,
1607 $line->localtax2_tx,
1611 $line->remise_percent,
1614 $line->product_type,
1619 $line->array_options,
1621 $line->multicurrency_subprice,
1628 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
1629 $this->db->rollback();
1634 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1635 $sql .=
" SET ref='(PROV".$this->id.
")'";
1636 $sql .=
" WHERE rowid=".((int) $this->
id);
1638 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1639 if ($this->db->query($sql)) {
1642 $this->
ref =
"(PROV".$this->id.
")";
1644 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
1645 $this->linked_objects = $this->linkedObjectsIds;
1649 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
1650 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
1651 if (is_array($tmp_origin_id)) {
1652 foreach ($tmp_origin_id as $origin_id) {
1660 $origin_id = $tmp_origin_id;
1678 if (!$error && !$notrigger) {
1680 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CREATE', $user);
1682 $this->db->rollback();
1690 $this->db->commit();
1693 $this->db->rollback();
1697 $this->error = $this->db->lasterror();
1698 $this->db->rollback();
1703 $this->error =
'Failed to get ID of inserted line';
1708 $this->error = $this->db->lasterror();
1709 $this->db->rollback();
1729 if (isset($this->
ref)) {
1730 $this->
ref = trim($this->
ref);
1732 if (isset($this->ref_supplier)) {
1733 $this->ref_supplier = trim($this->ref_supplier);
1735 if (isset($this->note_private)) {
1736 $this->note_private = trim($this->note_private);
1738 if (isset($this->note_public)) {
1739 $this->note_public = trim($this->note_public);
1741 if (isset($this->model_pdf)) {
1742 $this->model_pdf = trim($this->model_pdf);
1744 if (isset($this->import_key)) {
1745 $this->import_key = trim($this->import_key);
1749 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
1751 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1752 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
1753 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1754 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
1755 $sql .=
" date_commande=".(strval($this->date_commande) !=
'' ?
"'".$this->db->idate($this->date_commande).
"'" :
'null').
",";
1756 $sql .=
" date_valid=".(strval($this->date_validation) !=
'' ?
"'".$this->db->idate($this->date_validation).
"'" :
'null').
",";
1757 $sql .=
" total_tva=".(isset($this->total_tva) ? $this->total_tva :
"null").
",";
1758 $sql .=
" localtax1=".(isset($this->total_localtax1) ? $this->total_localtax1 :
"null").
",";
1759 $sql .=
" localtax2=".(isset($this->total_localtax2) ? $this->total_localtax2 :
"null").
",";
1760 $sql .=
" total_ht=".(isset($this->total_ht) ? $this->total_ht :
"null").
",";
1761 $sql .=
" total_ttc=".(isset($this->total_ttc) ? $this->total_ttc :
"null").
",";
1762 $sql .=
" fk_statut=".(isset($this->
statut) ? $this->
statut :
"null").
",";
1763 $sql .=
" fk_user_author=".(isset($this->user_author_id) ? $this->user_author_id :
"null").
",";
1764 $sql .=
" fk_user_valid=".(isset($this->user_validation_id) && $this->user_validation_id > 0 ? $this->user_validation_id :
"null").
",";
1765 $sql .=
" fk_projet=".(isset($this->fk_project) ? $this->fk_project :
"null").
",";
1766 $sql .=
" fk_cond_reglement=".(isset($this->cond_reglement_id) ? $this->cond_reglement_id :
"null").
",";
1767 $sql .=
" fk_mode_reglement=".(isset($this->mode_reglement_id) ? $this->mode_reglement_id :
"null").
",";
1768 $sql .=
" date_livraison=".(strval($this->delivery_date) !=
'' ?
"'".$this->db->idate($this->delivery_date).
"'" :
'null').
",";
1770 $sql .=
" fk_account=".($this->fk_account > 0 ? $this->fk_account :
"null").
",";
1772 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1773 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1774 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1775 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
1777 $sql .=
" WHERE rowid=".((int) $this->
id);
1781 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1782 $resql = $this->db->query($sql);
1785 $this->errors[] =
"Error ".$this->db->lasterror();
1795 if (!$error && !$notrigger) {
1797 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
1806 foreach ($this->errors as $errmsg) {
1807 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1808 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1810 $this->db->rollback();
1813 $this->db->commit();
1828 global $conf, $user, $hookmanager;
1835 foreach ($this->lines as $line) {
1836 $line->fetch_optionals();
1840 $objFrom = clone $this;
1843 if (!empty($socid) && $socid != $this->socid) {
1844 $objsoc =
new Societe($this->db);
1846 if ($objsoc->fetch($socid) > 0) {
1847 $this->socid = $objsoc->id;
1848 $this->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1849 $this->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1850 $this->fk_project = 0;
1851 $this->fk_delivery_address = 0;
1861 $this->user_author_id = $user->id;
1862 $this->user_validation_id = 0;
1865 $this->date_creation = 0;
1866 $this->date_validation = 0;
1867 $this->date_commande = 0;
1868 $this->ref_supplier =
'';
1869 $this->user_approve_id = 0;
1870 $this->user_approve_id2 = 0;
1871 $this->date_approve = 0;
1872 $this->date_approve2 = 0;
1875 $this->context[
'createfromclone'] =
'createfromclone';
1876 $result = $this->
create($user, $notrigger);
1883 if (is_object($hookmanager)) {
1884 $parameters = array(
'objFrom' => $objFrom);
1886 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1894 unset($this->context[
'createfromclone']);
1898 $this->db->commit();
1901 $this->db->rollback();
1935 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)
1937 global $langs, $mysoc, $conf;
1939 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");
1940 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1942 if ($this->
statut == self::STATUS_DRAFT) {
1943 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1952 if (empty($txtva)) {
1958 if (empty($txlocaltax1)) {
1961 if (empty($txlocaltax2)) {
1964 if (empty($remise_percent)) {
1965 $remise_percent = 0;
1968 $remise_percent =
price2num($remise_percent);
1971 $pu_ht_devise =
price2num($pu_ht_devise);
1973 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
1978 if ($price_base_type ==
'HT') {
1983 $desc = trim($desc);
1986 if ($qty < 0 && !$fk_product) {
1987 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Product"));
1993 if ($date_start && $date_end && $date_start > $date_end) {
1994 $langs->load(
"errors");
1995 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
2002 $product_type = $type;
2005 if ($fk_product > 0) {
2008 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);
2010 if ($prod->fetch($fk_product) > 0) {
2011 $product_type = $prod->type;
2012 $label = $prod->label;
2016 $result = $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', (isset($this->fk_soc) ? $this->fk_soc : $this->socid));
2020 if ($result > 0 && ($origin ==
'commande' || $pu ===
'')) {
2021 $pu = $prod->fourn_pu;
2022 $ref_supplier = $prod->ref_supplier;
2024 if ($remise_percent == 0 && $prod->remise_percent != 0) {
2025 $remise_percent = $prod->remise_percent;
2029 $langs->load(
"errors");
2030 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
2031 $this->db->rollback();
2032 dol_syslog(get_class($this).
"::addline we did not found supplier price, so we can't guess unit price");
2037 if ($result == -1) {
2038 $langs->load(
"errors");
2039 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
2040 $this->db->rollback();
2041 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_DEBUG);
2045 $this->error = $prod->error;
2046 $this->db->rollback();
2047 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_ERR);
2051 $this->error = $prod->error;
2052 $this->db->rollback();
2059 $prod =
new Product($this->db);
2060 $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', (empty($this->fk_soc) ? $this->socid : $this->fk_soc));
2062 if ($qty < $prod->packaging) {
2063 $qty = $prod->packaging;
2065 if (!empty($prod->packaging) && ($qty % $prod->packaging) > 0) {
2066 $coeff = intval($qty / $prod->packaging) + 1;
2067 $qty = $prod->packaging * $coeff;
2068 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'mesgs');
2074 if (isModEnabled(
"multicurrency") && $pu_ht_devise > 0) {
2083 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
2084 $vat_src_code = $reg[1];
2085 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
2093 $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);
2095 $total_ht = $tabprice[0];
2096 $total_tva = $tabprice[1];
2097 $total_ttc = $tabprice[2];
2098 $total_localtax1 = $tabprice[9];
2099 $total_localtax2 = $tabprice[10];
2100 $pu = $pu_ht = $tabprice[3];
2103 $multicurrency_total_ht = $tabprice[16];
2104 $multicurrency_total_tva = $tabprice[17];
2105 $multicurrency_total_ttc = $tabprice[18];
2106 $pu_ht_devise = $tabprice[19];
2108 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2109 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2113 $rang = $rangmax + 1;
2119 $this->line->context = $this->context;
2121 $this->line->fk_commande = $this->id;
2122 $this->line->label = $label;
2123 $this->line->ref_fourn = $ref_supplier;
2124 $this->line->ref_supplier = $ref_supplier;
2125 $this->line->desc = $desc;
2126 $this->line->qty = $qty;
2127 $this->line->tva_tx = $txtva;
2128 $this->line->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0);
2129 $this->line->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0);
2130 $this->line->localtax1_type = $localtax1_type;
2131 $this->line->localtax2_type = $localtax2_type;
2132 $this->line->fk_product = $fk_product;
2133 $this->line->product_type = $product_type;
2134 $this->line->remise_percent = $remise_percent;
2135 $this->line->subprice = $pu_ht;
2136 $this->line->rang = $rang;
2137 $this->line->info_bits = $info_bits;
2139 $this->line->vat_src_code = $vat_src_code;
2140 $this->line->total_ht = $total_ht;
2141 $this->line->total_tva = $total_tva;
2142 $this->line->total_localtax1 = $total_localtax1;
2143 $this->line->total_localtax2 = $total_localtax2;
2144 $this->line->total_ttc = $total_ttc;
2145 $this->line->product_type = $type;
2146 $this->line->special_code = (!empty($special_code) ? $special_code : 0);
2147 $this->line->origin = $origin;
2148 $this->line->origin_id = $origin_id;
2149 $this->line->fk_unit = $fk_unit;
2151 $this->line->date_start = $date_start;
2152 $this->line->date_end = $date_end;
2155 $this->line->fk_multicurrency = $this->fk_multicurrency;
2156 $this->line->multicurrency_code = $this->multicurrency_code;
2157 $this->line->multicurrency_subprice = $pu_ht_devise;
2158 $this->line->multicurrency_total_ht = $multicurrency_total_ht;
2159 $this->line->multicurrency_total_tva = $multicurrency_total_tva;
2160 $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
2162 $this->line->subprice = $pu_ht;
2163 $this->line->price = $this->line->subprice;
2165 $this->line->remise_percent = $remise_percent;
2167 if (is_array($array_options) && count($array_options) > 0) {
2168 $this->line->array_options = $array_options;
2171 $result = $this->line->insert($notrigger);
2174 if (!empty($this->line->fk_parent_line)) {
2176 } elseif ($rang > 0 && $rang <= count($this->lines)) {
2177 $linecount = count($this->lines);
2178 for ($ii = $rang; $ii <= $linecount; $ii++) {
2184 $result = $this->
update_price(1,
'auto', 0, $this->thirdparty);
2186 $this->db->commit();
2187 return $this->line->id;
2189 $this->db->rollback();
2193 $this->error = $this->line->error;
2194 $this->errors = $this->line->errors;
2195 dol_syslog(get_class($this).
"::addline error=".$this->error, LOG_ERR);
2196 $this->db->rollback();
2221 public function dispatchProduct($user, $product, $qty, $entrepot, $price = 0, $comment =
'', $eatby =
'', $sellby =
'', $batch =
'', $fk_commandefourndet = 0, $notrigger = 0, $fk_reception = 0)
2223 global $conf, $langs;
2226 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2229 if ($entrepot <= 0) {
2230 $this->error =
'ErrorBadValueForParameterWarehouse';
2234 $this->error =
'ErrorBadValueForParameterQty';
2238 $dispatchstatus = 1;
2240 $dispatchstatus = 0;
2247 if (($this->
statut == self::STATUS_ORDERSENT || $this->
statut == self::STATUS_RECEIVED_PARTIALLY || $this->
statut == self::STATUS_RECEIVED_COMPLETELY)) {
2250 $sql =
"INSERT INTO ".$this->db->prefix().
"receptiondet_batch";
2251 $sql .=
" (fk_element, fk_product, qty, fk_entrepot, fk_user, datec, fk_elementdet, status, comment, eatby, sellby, batch, fk_reception) VALUES";
2252 $sql .=
" ('".$this->id.
"','".$product.
"','".$qty.
"',".($entrepot > 0 ?
"'".$entrepot.
"'" :
"null").
",'".$user->id.
"','".$this->db->idate($now).
"','".$fk_commandefourndet.
"', ".$dispatchstatus.
", '".$this->db->escape($comment).
"', ";
2253 $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");
2256 dol_syslog(get_class($this).
"::dispatchProduct", LOG_DEBUG);
2257 $resql = $this->db->query($sql);
2260 global $conf, $langs, $user;
2262 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_DISPATCH', $user);
2269 $this->error = $this->db->lasterror();
2274 if (!$error && $entrepot > 0 && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER')) {
2278 $mouv->origin = &$this;
2279 $mouv->setOrigin($this->element, $this->
id);
2282 if (
getDolGlobalString(
'SUPPLIER_ORDER_ALLOW_NEGATIVE_QTY_FOR_SUPPLIER_ORDER_RETURN') && $qty < 0) {
2283 $result = $mouv->livraison($user, $product, $entrepot, $qty * (-1), $price, $comment, $now, $eatby, $sellby, $batch, 0, $inventorycode);
2285 $result = $mouv->reception($user, $product, $entrepot, $qty, $price, $comment, $eatby, $sellby, $batch,
'', 0, $inventorycode);
2289 $this->error = $mouv->error;
2290 $this->errors = $mouv->errors;
2291 dol_syslog(get_class($this).
"::dispatchProduct ".$this->error.
" ".implode(
',', $this->errors), LOG_ERR);
2298 $this->db->commit();
2301 $this->db->rollback();
2305 $this->error =
'BadStatusForObject';
2321 if ($this->
statut == 0) {
2324 if ($line->fetch($idline) <= 0) {
2330 foreach ($dispatchedLines as $dispatchLine) {
2331 if ($dispatchLine[
'orderlineid'] == $idline) {
2332 $this->error =
"LineAlreadyDispatched";
2333 $this->errors[] = $this->error;
2338 if ($line->delete($user, $notrigger) > 0) {
2357 public function delete(
User $user, $notrigger = 0)
2359 global $langs, $conf;
2360 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2366 if (empty($notrigger)) {
2368 $result = $this->
call_trigger(
'ORDER_SUPPLIER_DELETE', $user);
2370 $this->errors[] =
'ErrorWhenRunningTrigger';
2371 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2372 $this->db->rollback();
2380 if (!empty($this->linkedObjects) && array_key_exists(
'reception', $this->linkedObjects)) {
2381 foreach ($this->linkedObjects[
'reception'] as $element) {
2382 if ($element->statut >= 0) {
2383 $this->errors[] = $langs->trans(
'ReceptionExist');
2390 $main = $this->db->prefix().
'commande_fournisseurdet';
2393 $sql1 =
"UPDATE ".$this->db->prefix().
"commandedet SET fk_commandefourndet = NULL WHERE fk_commandefourndet IN (SELECT rowid FROM ".$this->db->sanitize($main).
" WHERE fk_commande = ".((int) $this->
id).
")";
2394 dol_syslog(__METHOD__.
" linked order lines", LOG_DEBUG);
2395 if (!$this->db->query($sql1)) {
2397 $this->error = $this->db->lasterror();
2398 $this->errors[] = $this->db->lasterror();
2403 $ef = $main.
"_extrafields";
2404 $sql =
"DELETE FROM ".$this->db->sanitize($ef).
" WHERE fk_object IN (SELECT rowid FROM ".$this->db->sanitize($main).
" WHERE fk_commande = ".((int) $this->
id).
")";
2405 dol_syslog(get_class($this).
"::delete extrafields lines", LOG_DEBUG);
2406 if (!$this->db->query($sql)) {
2407 $this->error = $this->db->lasterror();
2408 $this->errors[] = $this->db->lasterror();
2414 $sql =
"DELETE FROM ".$this->db->prefix().
"commande_fournisseurdet WHERE fk_commande = ".((int) $this->
id);
2415 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2416 if (!$this->db->query($sql)) {
2417 $this->error = $this->db->lasterror();
2418 $this->errors[] = $this->db->lasterror();
2424 $sql =
"DELETE FROM ".$this->db->prefix().
"commande_fournisseur WHERE rowid = ".((int) $this->
id);
2425 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2426 if ($resql = $this->db->query($sql)) {
2427 if ($this->db->affected_rows($resql) < 1) {
2428 $this->error = $this->db->lasterror();
2429 $this->errors[] = $this->db->lasterror();
2433 $this->error = $this->db->lasterror();
2434 $this->errors[] = $this->db->lasterror();
2443 $this->error =
'FailToDeleteExtraFields';
2444 $this->errors[] =
'FailToDeleteExtraFields';
2446 dol_syslog(get_class($this).
"::delete error -4 ".$this->error, LOG_ERR);
2453 $this->error =
'FailToDeleteObjectLinked';
2454 $this->errors[] =
'FailToDeleteObjectLinked';
2465 if ($conf->fournisseur->commande->dir_output) {
2466 $dir = $conf->fournisseur->commande->dir_output.
"/".$ref;
2467 $file = $dir.
"/".$ref.
".pdf";
2468 if (file_exists($file)) {
2470 $this->error =
'ErrorFailToDeleteFile';
2471 $this->errors[] =
'ErrorFailToDeleteFile';
2475 if (file_exists($dir)) {
2478 $this->error =
'ErrorFailToDeleteDir';
2479 $this->errors[] =
'ErrorFailToDeleteDir';
2487 dol_syslog(get_class($this).
"::delete $this->id by $user->id", LOG_DEBUG);
2488 $this->db->commit();
2491 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2492 $this->db->rollback();
2511 $sql =
"SELECT p.ref, p.label,";
2512 $sql .=
" e.rowid as warehouse_id, e.ref as entrepot,";
2513 $sql .=
" cfd.rowid as dispatchedlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status, cfd.fk_elementdet";
2514 $sql .=
" FROM ".$this->db->prefix().
"product as p,";
2515 $sql .=
" ".$this->db->prefix().
"receptiondet_batch as cfd";
2516 $sql .=
" LEFT JOIN ".$this->db->prefix().
"entrepot as e ON cfd.fk_entrepot = e.rowid";
2517 $sql .=
" WHERE cfd.fk_element = ".((int) $this->
id);
2518 $sql .=
" AND cfd.fk_product = p.rowid";
2520 $sql .=
" AND cfd.status = ".((int) $status);
2522 $sql .=
" ORDER BY cfd.rowid ASC";
2524 $resql = $this->db->query($sql);
2526 $num = $this->db->num_rows($resql);
2530 $objp = $this->db->fetch_object($resql);
2533 'id' => $objp->dispatchedlineid,
2534 'productid' => $objp->fk_product,
2535 'warehouseid' => $objp->warehouse_id,
2536 'qty' => $objp->qty,
2537 'orderlineid' => $objp->fk_elementdet
2544 dol_print_error($this->db,
'Failed to execute request to get dispatched lines');
2563 global $conf, $langs;
2570 $usercanreceive = 0;
2571 if (!isModEnabled(
'reception')) {
2572 $usercanreceive = $user->hasRight(
"fournisseur",
"commande",
"receptionner");
2574 $usercanreceive = $user->hasRight(
"reception",
"creer");
2577 if ($usercanreceive) {
2579 if ($type ==
'par') {
2581 } elseif ($type ==
'tot') {
2583 } elseif ($type ==
'nev') {
2585 } elseif ($type ==
'can') {
2589 dol_syslog(get_class($this).
"::Livraison Error -2", LOG_ERR);
2596 if (!$error && ($type ==
'tot')) {
2598 if (count($dispatchedlinearray) > 0) {
2601 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove';
2602 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove', LOG_DEBUG);
2605 if (!$error &&
getDolGlobalString(
'SUPPLIER_ORDER_USE_DISPATCH_STATUS_NEED_APPROVE') && ($type ==
'tot')) {
2607 if (count($dispatchedlinearray) > 0) {
2610 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied';
2611 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied', LOG_DEBUG);
2618 if (empty($error)) {
2621 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2622 $sql .=
" SET fk_statut = ".((int) $statut);
2623 $sql .=
" WHERE rowid = ".((int) $this->
id);
2624 $sql .=
" AND fk_statut IN (".self::STATUS_ORDERSENT.
",".self::STATUS_RECEIVED_PARTIALLY.
")";
2626 dol_syslog(get_class($this).
"::Livraison", LOG_DEBUG);
2627 $resql = $this->db->query($sql);
2630 $old_statut = $this->statut;
2632 $this->context[
'actionmsg2'] = $comment;
2635 $result_trigger = $this->
call_trigger(
'ORDER_SUPPLIER_RECEIVE', $user);
2636 if ($result_trigger < 0) {
2641 if (empty($error)) {
2642 $this->db->commit();
2644 $this->
statut = $old_statut;
2645 $this->db->rollback();
2646 $this->error = $this->db->lasterror();
2650 $this->db->rollback();
2651 $this->error = $this->db->lasterror();
2656 $this->error = $langs->trans(
'NotAuthorized');
2657 $this->errors[] = $langs->trans(
'NotAuthorized');
2658 dol_syslog(get_class($this).
"::Livraison Not Authorized");
2690 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
2695 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2696 $sql .=
" SET date_livraison = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2697 $sql .=
" WHERE rowid = ".((int) $this->
id);
2700 $resql = $this->db->query($sql);
2702 $this->errors[] = $this->db->error();
2707 $this->oldcopy = clone $this;
2708 $this->delivery_date = $delivery_date;
2711 if (!$notrigger && empty($error)) {
2713 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2721 $this->db->commit();
2724 foreach ($this->errors as $errmsg) {
2725 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2726 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2728 $this->db->rollback();
2748 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
2753 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2754 $sql .=
" SET fk_projet = ".($id_projet > 0 ? (int) $id_projet :
'null');
2755 $sql .=
" WHERE rowid = ".((int) $this->
id);
2758 $resql = $this->db->query($sql);
2760 $this->errors[] = $this->db->error();
2765 $this->oldcopy = clone $this;
2766 $this->fk_projet = $id_projet;
2767 $this->fk_project = $id_projet;
2770 if (!$notrigger && empty($error)) {
2772 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2780 $this->db->commit();
2783 foreach ($this->errors as $errmsg) {
2784 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2785 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2787 $this->db->rollback();
2805 $comclient =
new Commande($this->db);
2806 $comclient->fetch($comclientid);
2810 $this->lines = array();
2812 $num = count($comclient->lines);
2813 for ($i = 0; $i < $num; $i++) {
2814 $prod =
new Product($this->db);
2817 if ($prod->fetch($comclient->lines[$i]->fk_product) > 0) {
2818 $label = $prod->label;
2822 $sql =
"INSERT INTO ".$this->db->prefix().
"commande_fournisseurdet";
2823 $sql .=
" (fk_commande, label, description, fk_product, price, qty, tva_tx, localtax1_tx, localtax2_tx, remise_percent, subprice, remise, ref)";
2824 $sql .=
" VALUES (".((int) $idc).
", '".$this->db->escape($label).
"', '".$this->db->escape($comclient->lines[$i]->desc).
"'";
2825 $sql .=
",".$comclient->lines[$i]->fk_product.
", ".
price2num($comclient->lines[$i]->price,
'MU');
2826 $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);
2827 $sql .=
", '".price2num($comclient->lines[$i]->subprice,
'MT').
"','0', '".$this->db->escape($ref).
"');";
2828 if ($this->db->query($sql)) {
2845 global $conf, $langs;
2850 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur';
2851 $sql .=
" SET fk_statut = ".$status;
2852 $sql .=
" WHERE rowid = ".((int) $this->
id);
2854 dol_syslog(get_class($this).
"::setStatus", LOG_DEBUG);
2855 $resql = $this->db->query($sql);
2858 $triggerName = array();
2859 $triggerName[0] =
'DRAFT';
2860 $triggerName[1] =
'VALIDATED';
2861 $triggerName[2] =
'APPROVED';
2862 $triggerName[3] =
'ORDERED';
2863 $triggerName[4] =
'RECEIVED_PARTIALLY';
2864 $triggerName[5] =
'RECEIVED_COMPLETELY';
2865 $triggerName[6] =
'CANCELED';
2866 $triggerName[7] =
'CANCELED';
2867 $triggerName[9] =
'REFUSED';
2870 $result = $this->
call_trigger(
"ORDER_SUPPLIER_STATUS_".$triggerName[$status], $user);
2877 $this->error = $this->db->lasterror();
2878 dol_syslog(get_class($this).
"::setStatus ".$this->error);
2883 $this->db->commit();
2886 $this->db->rollback();
2914 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 =
'')
2916 global $mysoc, $conf, $langs;
2917 dol_syslog(get_class($this).
"::updateline $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $type, $fk_unit");
2918 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2922 if ($this->
statut == self::STATUS_DRAFT) {
2927 if (empty($info_bits)) {
2930 if (empty($txtva)) {
2933 if (empty($txlocaltax1)) {
2936 if (empty($txlocaltax2)) {
2939 if (empty($remise_percent)) {
2940 $remise_percent = 0;
2943 $remise_percent = (float)
price2num($remise_percent);
2949 $pu_ht_devise =
price2num($pu_ht_devise);
2950 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
2953 $txlocaltax1 = (float)
price2num($txlocaltax1);
2954 $txlocaltax2 = (float)
price2num($txlocaltax2);
2960 if ($date_start && $date_end && $date_start > $date_end) {
2961 $langs->load(
"errors");
2962 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
2978 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
2979 $vat_src_code = $reg[1];
2980 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
2983 $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);
2984 $total_ht = $tabprice[0];
2985 $total_tva = $tabprice[1];
2986 $total_ttc = $tabprice[2];
2987 $total_localtax1 = $tabprice[9];
2988 $total_localtax2 = $tabprice[10];
2989 $pu_ht = $tabprice[3];
2990 $pu_tva = $tabprice[4];
2991 $pu_ttc = $tabprice[5];
2994 $multicurrency_total_ht = $tabprice[16];
2995 $multicurrency_total_tva = $tabprice[17];
2996 $multicurrency_total_ttc = $tabprice[18];
2997 $pu_ht_devise = $tabprice[19];
2999 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
3000 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
3004 $this->line->fetch($rowid);
3006 $oldline = clone $this->line;
3007 $this->line->oldline = $oldline;
3009 $this->line->context = $this->context;
3011 $this->line->fk_commande = $this->id;
3013 $this->line->desc = $desc;
3017 if ($qty < $this->line->packaging) {
3018 $qty = $this->line->packaging;
3020 if (!empty($this->line->packaging) && ($qty % $this->line->packaging) > 0) {
3021 $coeff = intval($qty / $this->line->packaging) + 1;
3022 $qty = $this->line->packaging * $coeff;
3023 setEventMessage($langs->trans(
'QtyRecalculatedWithPackaging'),
'mesgs');
3028 $this->line->qty = $qty;
3029 $this->line->ref_supplier = $ref_supplier;
3031 $this->line->vat_src_code = $vat_src_code;
3032 $this->line->tva_tx = $txtva;
3033 $this->line->localtax1_tx = $txlocaltax1;
3034 $this->line->localtax2_tx = $txlocaltax2;
3035 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
3036 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
3037 $this->line->remise_percent = $remise_percent;
3038 $this->line->subprice = $pu_ht;
3039 $this->line->info_bits = $info_bits;
3040 $this->line->total_ht = $total_ht;
3041 $this->line->total_tva = $total_tva;
3042 $this->line->total_localtax1 = $total_localtax1;
3043 $this->line->total_localtax2 = $total_localtax2;
3044 $this->line->total_ttc = $total_ttc;
3045 $this->line->product_type = $type;
3046 $this->line->special_code = $oldline->special_code;
3047 $this->line->rang = $oldline->rang;
3048 $this->line->origin = $this->origin;
3049 $this->line->fk_unit = $fk_unit;
3051 $this->line->date_start = $date_start;
3052 $this->line->date_end = $date_end;
3055 $this->line->fk_multicurrency = $this->fk_multicurrency;
3056 $this->line->multicurrency_code = $this->multicurrency_code;
3057 $this->line->multicurrency_subprice = $pu_ht_devise;
3058 $this->line->multicurrency_total_ht = $multicurrency_total_ht;
3059 $this->line->multicurrency_total_tva = $multicurrency_total_tva;
3060 $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
3062 $this->line->subprice = $pu_ht;
3063 $this->line->price = $this->line->subprice;
3065 $this->line->remise_percent = $remise_percent;
3067 if (is_array($array_options) && count($array_options) > 0) {
3069 foreach ($array_options as $key => $value) {
3070 $this->line->array_options[$key] = $array_options[$key];
3074 $result = $this->line->update($notrigger);
3080 $this->db->commit();
3083 $this->errors[] = $this->line->error;
3084 $this->errors = array_merge($this->errors, $this->line->errors);
3085 $this->error = $this->db->lasterror();
3086 $this->db->rollback();
3090 $this->error =
"Order status makes operation forbidden";
3091 dol_syslog(get_class($this).
"::updateline ".$this->error, LOG_ERR);
3106 global $user, $langs, $conf;
3108 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
3110 dol_syslog(get_class($this).
"::initAsSpecimen");
3117 $sql =
"SELECT rowid";
3118 $sql .=
" FROM ".$this->db->prefix().
"product";
3119 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
3120 $sql .= $this->db->order(
"rowid",
"ASC");
3121 $sql .= $this->db->plimit(1);
3122 $resql = $this->db->query($sql);
3123 if ($resql && $this->db->num_rows($resql)) {
3124 $obj = $this->db->fetch_object($resql);
3125 $prodid = $obj->rowid;
3130 $this->
ref =
'SPECIMEN';
3131 $this->specimen = 1;
3134 $this->date_commande = $now;
3135 $this->date_lim_reglement = $this->date + 3600 * 24 * 30;
3136 $this->cond_reglement_code =
'RECEP';
3137 $this->mode_reglement_code =
'CHQ';
3139 $this->note_public =
'This is a comment (public)';
3140 $this->note_private =
'This is a comment (private)';
3142 $this->multicurrency_tx = 1;
3143 $this->multicurrency_code = $conf->currency;
3150 while ($xnbp < $nbp) {
3152 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
3154 $line->subprice = 100;
3155 $line->tva_tx = 19.6;
3156 $line->localtax1_tx = 0;
3157 $line->localtax2_tx = 0;
3159 $line->total_ht = 50;
3160 $line->total_ttc = 59.8;
3161 $line->total_tva = 9.8;
3162 $line->remise_percent = 50;
3164 $line->total_ht = 100;
3165 $line->total_ttc = 119.6;
3166 $line->total_tva = 19.6;
3167 $line->remise_percent = 00;
3169 $line->fk_product = $prodid;
3171 $this->lines[$xnbp] = $line;
3173 $this->total_ht += $line->total_ht;
3174 $this->total_tva += $line->total_tva;
3175 $this->total_ttc += $line->total_ttc;
3191 $sql =
'SELECT c.rowid, date_creation as datec, tms as datem, date_valid as date_validation, date_approve as datea, date_approve2 as datea2,';
3192 $sql .=
' fk_user_author, fk_user_modif, fk_user_valid, fk_user_approve, fk_user_approve2';
3193 $sql .=
' FROM '.$this->db->prefix().
'commande_fournisseur as c';
3194 $sql .=
' WHERE c.rowid = '.((int) $id);
3196 $result = $this->db->query($sql);
3198 if ($this->db->num_rows($result)) {
3199 $obj = $this->db->fetch_object($result);
3201 $this->
id = $obj->rowid;
3203 $this->user_creation_id = $obj->fk_user_author;
3204 $this->user_validation_id = $obj->fk_user_valid;
3205 $this->user_modification_id = $obj->fk_user_modif;
3206 $this->user_approve_id = $obj->fk_user_approve;
3207 $this->user_approve_id2 = $obj->fk_user_approve2;
3209 $this->date_creation = $this->db->jdate($obj->datec);
3210 $this->date_modification = $this->db->jdate($obj->datem);
3211 $this->date_approve = $this->db->jdate($obj->datea);
3212 $this->date_approve2 = $this->db->jdate($obj->datea2);
3213 $this->date_validation = $this->db->jdate($obj->date_validation);
3215 $this->db->free($result);
3228 global $conf, $user;
3230 $this->nb = array();
3233 $sql =
"SELECT count(co.rowid) as nb";
3234 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as co";
3235 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe as s ON co.fk_soc = s.rowid";
3236 if (empty($user->socid) && !$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3237 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
3238 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
3241 $sql .=
" ".$clause.
" co.entity IN (".
getEntity(
'supplier_order').
")";
3243 $resql = $this->db->query($sql);
3245 while ($obj = $this->db->fetch_object($resql)) {
3246 $this->nb[
"supplier_orders"] = $obj->nb;
3248 $this->db->free($resql);
3252 $this->error = $this->db->error();
3268 global $conf, $langs;
3270 $sql =
"SELECT c.rowid, c.date_creation as datec, c.date_commande, c.fk_statut, c.date_livraison as delivery_date, c.total_ht";
3271 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as c";
3272 if (empty($user->socid) && !$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3273 $sql .=
" JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
3275 $sql .=
" WHERE c.entity = ".$conf->entity;
3276 if ($mode ===
'awaiting') {
3277 $sql .=
" AND c.fk_statut IN (".self::STATUS_ORDERSENT.
", ".self::STATUS_RECEIVED_PARTIALLY.
")";
3279 $sql .=
" AND c.fk_statut IN (".self::STATUS_VALIDATED.
", ".self::STATUS_ACCEPTED.
")";
3282 $sql .=
" AND c.fk_soc = ".((int) $user->socid);
3285 $resql = $this->db->query($sql);
3290 $response->warning_delay = $conf->commande->fournisseur->warning_delay / 60 / 60 / 24;
3291 $response->label = $langs->trans(
"SuppliersOrdersToProcess");
3292 $response->labelShort = $langs->trans(
"Opened");
3293 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=1,2&mainmenu=commercial&leftmenu=orders_suppliers';
3296 if ($mode ===
'awaiting') {
3297 $response->label = $langs->trans(
"SuppliersOrdersAwaitingReception");
3298 $response->labelShort = $langs->trans(
"AwaitingReception");
3299 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=3,4&mainmenu=commercial&leftmenu=orders_suppliers';
3302 while ($obj = $this->db->fetch_object($resql)) {
3303 $commandestatic->delivery_date = $this->db->jdate($obj->delivery_date);
3304 $commandestatic->date_commande = $this->db->jdate($obj->date_commande);
3305 $commandestatic->statut = $obj->fk_statut;
3307 $response->nbtodo++;
3308 $response->total += $obj->total_ht;
3310 if ($commandestatic->hasDelay()) {
3311 $response->nbtodolate++;
3317 $this->error = $this->db->error();
3332 if ($this->methode_commande_id > 0) {
3333 $sql =
"SELECT rowid, code, libelle as label";
3334 $sql .=
" FROM ".$this->db->prefix().
'c_input_method';
3335 $sql .=
" WHERE active=1 AND rowid = ".((int) $this->methode_commande_id);
3337 $resql = $this->db->query($sql);
3339 if ($this->db->num_rows($resql)) {
3340 $obj = $this->db->fetch_object($resql);
3342 $string = $langs->trans($obj->code);
3343 if ($string == $obj->code) {
3344 $string = $obj->label !=
'-' ? $obj->label :
'';
3367 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3369 global $conf, $langs;
3374 if (!empty($this->model_pdf)) {
3375 $modele = $this->model_pdf;
3381 if (empty($modele)) {
3384 $langs->load(
"suppliers");
3385 $outputlangs->load(
"products");
3387 $modelpath =
"core/modules/supplier_order/doc/";
3388 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3401 if (empty($this->lines)) {
3408 foreach ($this->lines as $line) {
3409 if ($line->fk_product > 0) {
3411 $idp = $tmpproductfourn->find_min_price_product_fournisseur($line->fk_product, $line->qty, $this->thirdparty->id);
3414 if ($tmpproductfourn->delivery_time_days > $nb) {
3415 $nb = $tmpproductfourn->delivery_time_days;
3424 return $nb.
' '.$langs->trans(
'days');
3437 return $user->hasRight(
"fournisseur",
"commande");
3452 'commande_fournisseur'
3469 'commande_fournisseurdet'
3486 if ($this->
statut == self::STATUS_ORDERSENT || $this->
statut == self::STATUS_RECEIVED_PARTIALLY) {
3488 if (!empty($this->delivery_date)) {
3489 $date_to_test = $this->delivery_date;
3490 return $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay);
3498 $date_to_test = $this->date_commande;
3500 return ($this->
statut > 0 && $this->
statut < 5) && $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay);
3513 global $conf, $langs;
3515 $langs->load(
'orders');
3519 if ($this->
statut == self::STATUS_ORDERSENT || $this->
statut == self::STATUS_RECEIVED_PARTIALLY) {
3520 if (!empty($this->delivery_date)) {
3521 $text = $langs->trans(
"DeliveryDate").
' '.
dol_print_date($this->delivery_date,
'day');
3523 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3526 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3529 $text .=
' '.($conf->commande->fournisseur->warning_delay > 0 ?
'+' :
'-').
' '.round(abs($conf->commande->fournisseur->warning_delay) / 3600 / 24, 1).
' '.$langs->trans(
"days").
' < '.$langs->trans(
"Today");
3546 if (isModEnabled(
"supplier_order")) {
3547 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
3549 $qtydelivered = array();
3550 $qtywished = array();
3554 $filter = array(
't.fk_element' => $this->
id);
3556 $filter[
't.status'] = 1;
3559 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
3561 $this->error = $supplierorderdispatch->error;
3562 $this->errors = $supplierorderdispatch->errors;
3565 if (is_array($supplierorderdispatch->lines) && count($supplierorderdispatch->lines) > 0) {
3566 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
3570 foreach ($supplierorderdispatch->lines as $line) {
3571 if (array_key_exists($line->fk_product, $qtydelivered)) {
3572 $qtydelivered[$line->fk_product] += $line->qty;
3574 $qtydelivered[$line->fk_product] = $line->qty;
3577 foreach ($this->lines as $line) {
3582 if (array_key_exists($line->fk_product, $qtywished)) {
3583 $qtywished[$line->fk_product] += $line->qty;
3585 $qtywished[$line->fk_product] = $line->qty;
3590 $diff_array = array_diff_assoc($qtydelivered, $qtywished);
3591 $keysinwishednotindelivered = array_diff(array_keys($qtywished), array_keys($qtydelivered));
3592 $keysindeliverednotinwished = array_diff(array_keys($qtydelivered), array_keys($qtywished));
3600 if (count($diff_array) == 0 && count($keysinwishednotindelivered) == 0 && count($keysindeliverednotinwished) == 0) {
3601 if ($closeopenorder) {
3603 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3611 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3622 if (count($diff_array) > 0) {
3626 foreach ($diff_array as $key => $value) {
3628 if ($qtydelivered[$key] >= $qtywished[$key]) {
3635 if ($close == count($diff_array)) {
3637 if ($closeopenorder) {
3638 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3645 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3653 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3661 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3683 $this->receptions = array();
3685 dol_syslog(get_class($this).
"::loadReceptions", LOG_DEBUG);
3687 $sql =
'SELECT cd.rowid, cd.fk_product,';
3688 $sql .=
' sum(cfd.qty) as qty';
3689 $sql .=
' FROM '.$this->db->prefix().
'receptiondet_batch as cfd,';
3690 if ($filtre_statut >= 0) {
3691 $sql .=
' '.$this->db->prefix().
'reception as e,';
3693 $sql .=
' '.$this->db->prefix().
'commande_fournisseurdet as cd';
3695 if ($filtre_statut >= 0) {
3696 $sql .=
' cfd.fk_reception = e.rowid AND';
3698 $sql .=
' cfd.fk_elementdet = cd.rowid';
3699 $sql .=
' AND cd.fk_commande ='.((int) $this->
id);
3700 if (isset($this->fk_product) && !empty($this->fk_product) > 0) {
3701 $sql .=
' AND cd.fk_product = '.((int) $this->fk_product);
3703 if ($filtre_statut >= 0) {
3704 $sql .=
' AND e.fk_statut >= '.((int) $filtre_statut);
3706 $sql .=
' GROUP BY cd.rowid, cd.fk_product';
3708 $resql = $this->db->query($sql);
3710 $num = $this->db->num_rows($resql);
3713 $obj = $this->db->fetch_object($resql);
3714 empty($this->receptions[$obj->rowid]) ? $this->receptions[$obj->rowid] = $obj->qty : $this->receptions[$obj->rowid] += $obj->qty;
3717 $this->db->free($resql);
3721 $this->error = $this->db->lasterror();
3737 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3739 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3740 $return .=
'<div class="info-box info-box-sm">';
3741 $return .=
'<span class="info-box-icon bg-infobox-action">';
3743 $return .=
'</span>';
3744 $return .=
'<div class="info-box-content">';
3745 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
3746 if ($selected >= 0) {
3747 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3749 if (property_exists($this,
'socid') || property_exists($this,
'total_tva')) {
3750 $return .=
'<br><span class="info-box-label amount">'.$this->socid.
'</span>';
3752 if (property_exists($this,
'billed')) {
3753 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Billed").
' : </span><span class="info-box-label">'.
yn($this->billed).
'</span>';
3755 if (method_exists($this,
'getLibStatut')) {
3756 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
3758 $return .=
'</div>';
3759 $return .=
'</div>';
3760 $return .=
'</div>';
3775 public $element =
'commande_fournisseurdet';
3780 public $table_element =
'commande_fournisseurdet';
3798 public $fk_commande;
3804 public $fk_parent_line;
3816 public $special_code = 0;
3826 public $fk_fournprice;
3836 public $ref_supplier;
3866 $sql =
'SELECT cd.rowid, cd.fk_commande, cd.fk_product, cd.product_type, cd.description, cd.qty, cd.tva_tx, cd.special_code,';
3867 $sql .=
' cd.localtax1_tx, cd.localtax2_tx, cd.localtax1_type, cd.localtax2_type, cd.ref as ref_supplier,';
3868 $sql .=
' cd.remise, cd.remise_percent, cd.subprice,';
3869 $sql .=
' cd.info_bits, cd.total_ht, cd.total_tva, cd.total_ttc,';
3870 $sql .=
' cd.total_localtax1, cd.total_localtax2,';
3871 $sql .=
' p.ref as product_ref, p.label as product_label, p.description as product_desc,';
3872 $sql .=
' cd.date_start, cd.date_end, cd.fk_unit,';
3873 $sql .=
' cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc,';
3874 $sql .=
' c.fk_soc as socid';
3875 $sql .=
' FROM '.$this->db->prefix().
'commande_fournisseur as c, '.$this->db->prefix().
'commande_fournisseurdet as cd';
3876 $sql .=
' LEFT JOIN '.$this->db->prefix().
'product as p ON cd.fk_product = p.rowid';
3877 $sql .=
' WHERE cd.fk_commande = c.rowid AND cd.rowid = '.((int) $rowid);
3879 $result = $this->db->query($sql);
3881 $objp = $this->db->fetch_object($result);
3883 if (!empty($objp)) {
3884 $this->
rowid = $objp->rowid;
3885 $this->
id = $objp->rowid;
3886 $this->fk_commande = $objp->fk_commande;
3887 $this->desc = $objp->description;
3888 $this->qty = $objp->qty;
3889 $this->ref_fourn = $objp->ref_supplier;
3890 $this->ref_supplier = $objp->ref_supplier;
3891 $this->subprice = $objp->subprice;
3892 $this->tva_tx = $objp->tva_tx;
3893 $this->localtax1_tx = $objp->localtax1_tx;
3894 $this->localtax2_tx = $objp->localtax2_tx;
3895 $this->localtax1_type = $objp->localtax1_type;
3896 $this->localtax2_type = $objp->localtax2_type;
3897 $this->remise = $objp->remise;
3898 $this->remise_percent = $objp->remise_percent;
3899 $this->fk_product = $objp->fk_product;
3900 $this->info_bits = $objp->info_bits;
3901 $this->total_ht = $objp->total_ht;
3902 $this->total_tva = $objp->total_tva;
3903 $this->total_localtax1 = $objp->total_localtax1;
3904 $this->total_localtax2 = $objp->total_localtax2;
3905 $this->total_ttc = $objp->total_ttc;
3906 $this->product_type = $objp->product_type;
3907 $this->special_code = $objp->special_code;
3909 $this->
ref = $objp->product_ref;
3911 $this->product_ref = $objp->product_ref;
3912 $this->product_label = $objp->product_label;
3913 $this->product_desc = $objp->product_desc;
3920 $sqlsearchpackage =
'SELECT rowid, packaging FROM '.$this->db->prefix().
"product_fournisseur_price";
3921 $sqlsearchpackage .=
' WHERE entity IN ('.getEntity(
'product_fournisseur_price').
")";
3922 $sqlsearchpackage .=
" AND fk_product = ".((int) $objp->fk_product);
3923 $sqlsearchpackage .=
" AND ref_fourn = '".$this->db->escape($objp->ref_supplier).
"'";
3924 $sqlsearchpackage .=
" AND quantity <= ".((float) $objp->qty);
3925 $sqlsearchpackage .=
" AND (packaging IS NULL OR packaging = 0 OR packaging <= ".((float) $objp->qty).
")";
3926 $sqlsearchpackage .=
" AND fk_soc = ".((int) $objp->socid);
3927 $sqlsearchpackage .=
" ORDER BY packaging ASC";
3928 $sqlsearchpackage .=
" LIMIT 1";
3930 $resqlsearchpackage = $this->db->query($sqlsearchpackage);
3931 if ($resqlsearchpackage) {
3932 $objsearchpackage = $this->db->fetch_object($resqlsearchpackage);
3933 if ($objsearchpackage) {
3934 $this->fk_fournprice = $objsearchpackage->rowid;
3935 $this->packaging = $objsearchpackage->packaging;
3938 $this->error = $this->db->lasterror();
3943 $this->date_start = $this->db->jdate($objp->date_start);
3944 $this->date_end = $this->db->jdate($objp->date_end);
3945 $this->fk_unit = $objp->fk_unit;
3947 $this->multicurrency_subprice = $objp->multicurrency_subprice;
3948 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
3949 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
3950 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
3954 $this->db->free($result);
3957 $this->error =
'Supplier order line with id='.$rowid.
' not found';
3958 dol_syslog(get_class($this).
"::fetch Error ".$this->error, LOG_ERR);
3975 global $conf, $user;
3979 dol_syslog(get_class($this).
"::insert rang=".$this->rang);
3982 if (empty($this->tva_tx)) {
3985 if (empty($this->localtax1_tx)) {
3986 $this->localtax1_tx = 0;
3988 if (empty($this->localtax2_tx)) {
3989 $this->localtax2_tx = 0;
3991 if (empty($this->localtax1_type)) {
3992 $this->localtax1_type =
'0';
3994 if (empty($this->localtax2_type)) {
3995 $this->localtax2_type =
'0';
3997 if (empty($this->total_localtax1)) {
3998 $this->total_localtax1 = 0;
4000 if (empty($this->total_localtax2)) {
4001 $this->total_localtax2 = 0;
4003 if (empty($this->rang)) {
4006 if (empty($this->remise_percent)) {
4007 $this->remise_percent = 0;
4009 if (empty($this->info_bits)) {
4010 $this->info_bits = 0;
4012 if (empty($this->special_code)) {
4013 $this->special_code = 0;
4015 if (empty($this->fk_parent_line)) {
4016 $this->fk_parent_line = 0;
4018 if (empty($this->pa_ht)) {
4023 if (!empty($this->multicurrency_code)) {
4026 if (empty($this->fk_multicurrency)) {
4027 $this->multicurrency_code = $conf->currency;
4028 $this->fk_multicurrency = 0;
4029 $this->multicurrency_tx = 1;
4033 if ($this->product_type < 0) {
4040 $sql =
'INSERT INTO '.$this->db->prefix().$this->table_element;
4041 $sql .=
" (fk_commande, label, description, date_start, date_end,";
4042 $sql .=
" fk_product, product_type, special_code, rang,";
4043 $sql .=
" qty, vat_src_code, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, remise_percent, subprice, ref,";
4044 $sql .=
" total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_unit,";
4045 $sql .=
" fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc,";
4046 $sql .=
" fk_parent_line)";
4047 $sql .=
" VALUES (".$this->fk_commande.
", '".$this->db->escape($this->label).
"','".$this->db->escape($this->desc).
"',";
4048 $sql .=
" ".($this->date_start ?
"'".$this->db->idate($this->date_start).
"'" :
"null").
",";
4049 $sql .=
" ".($this->date_end ?
"'".$this->db->idate($this->date_end).
"'" :
"null").
",";
4050 if ($this->fk_product) {
4051 $sql .= $this->fk_product.
",";
4055 $sql .=
"'".$this->db->escape($this->product_type).
"',";
4056 $sql .= (int) $this->special_code .
",";
4057 $sql .=
"'".$this->db->escape($this->rang).
"',";
4058 $sql .=
"'".$this->db->escape($this->qty).
"', ";
4059 $sql .=
" ".(empty($this->vat_src_code) ?
"''" :
"'".$this->db->escape($this->vat_src_code).
"'").
",";
4060 $sql .=
" ".price2num($this->tva_tx).
", ";
4061 $sql .=
" ".price2num($this->localtax1_tx).
",";
4062 $sql .=
" ".price2num($this->localtax2_tx).
",";
4063 $sql .=
" '".$this->db->escape($this->localtax1_type).
"',";
4064 $sql .=
" '".$this->db->escape($this->localtax2_type).
"',";
4065 $sql .=
" ".((float) $this->remise_percent).
", ".
price2num($this->subprice,
'MU').
", '".$this->db->escape($this->ref_supplier).
"',";
4066 $sql .=
" ".price2num($this->total_ht).
",";
4067 $sql .=
" ".price2num($this->total_tva).
",";
4068 $sql .=
" ".price2num($this->total_localtax1).
",";
4069 $sql .=
" ".price2num($this->total_localtax2).
",";
4070 $sql .=
" ".price2num($this->total_ttc).
",";
4071 $sql .= ($this->fk_unit ?
"'".$this->db->escape($this->fk_unit).
"'" :
"null");
4072 $sql .=
", ".($this->fk_multicurrency ? ((int) $this->fk_multicurrency) :
"null");
4073 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
4074 $sql .=
", ".($this->multicurrency_subprice ?
price2num($this->multicurrency_subprice) :
'0');
4075 $sql .=
", ".($this->multicurrency_total_ht ?
price2num($this->multicurrency_total_ht) :
'0');
4076 $sql .=
", ".($this->multicurrency_total_tva ?
price2num($this->multicurrency_total_tva) :
'0');
4077 $sql .=
", ".($this->multicurrency_total_ttc ?
price2num($this->multicurrency_total_ttc) :
'0');
4078 $sql .=
", ".((!empty($this->fk_parent_line) && $this->fk_parent_line > 0) ? $this->fk_parent_line :
'null');
4081 dol_syslog(get_class($this).
"::insert", LOG_DEBUG);
4082 $resql = $this->db->query($sql);
4084 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
4085 $this->
rowid = $this->id;
4094 if (!$error && !$notrigger) {
4096 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_CREATE', $user);
4104 $this->db->commit();
4108 foreach ($this->errors as $errmsg) {
4109 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
4110 $this->errors[] = ($this->errors ?
', '.$errmsg : $errmsg);
4112 $this->db->rollback();
4115 $this->errors[] = $this->db->error();
4116 $this->db->rollback();
4135 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
4136 $sql .=
" description='".$this->db->escape($this->desc).
"'";
4137 $sql .=
", ref='".$this->db->escape($this->ref_supplier).
"'";
4138 $sql .=
", subprice='".price2num($this->subprice).
"'";
4140 $sql .=
", remise_percent='".price2num($this->remise_percent).
"'";
4142 $sql .=
", vat_src_code = '".(empty($this->vat_src_code) ?
'' : $this->vat_src_code).
"'";
4143 $sql .=
", tva_tx='".price2num($this->tva_tx).
"'";
4144 $sql .=
", localtax1_tx='".price2num($this->localtax1_tx).
"'";
4145 $sql .=
", localtax2_tx='".price2num($this->localtax2_tx).
"'";
4146 $sql .=
", localtax1_type='".$this->db->escape($this->localtax1_type).
"'";
4147 $sql .=
", localtax2_type='".$this->db->escape($this->localtax2_type).
"'";
4148 $sql .=
", qty='".price2num($this->qty).
"'";
4149 $sql .=
", date_start=".(!empty($this->date_start) ?
"'".$this->db->idate($this->date_start).
"'" :
"null");
4150 $sql .=
", date_end=".(!empty($this->date_end) ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
4151 $sql .=
", info_bits='".$this->db->escape($this->info_bits).
"'";
4152 $sql .=
", total_ht='".price2num($this->total_ht).
"'";
4153 $sql .=
", total_tva='".price2num($this->total_tva).
"'";
4154 $sql .=
", total_localtax1='".price2num($this->total_localtax1).
"'";
4155 $sql .=
", total_localtax2='".price2num($this->total_localtax2).
"'";
4156 $sql .=
", total_ttc='".price2num($this->total_ttc).
"'";
4157 $sql .=
", product_type=".$this->product_type;
4158 $sql .=
", special_code=".(!empty($this->special_code) ? $this->special_code : 0);
4159 $sql .= ($this->fk_unit ?
", fk_unit='".$this->db->escape($this->fk_unit).
"'" :
", fk_unit=null");
4162 $sql .=
", multicurrency_subprice=".price2num($this->multicurrency_subprice);
4163 $sql .=
", multicurrency_total_ht=".price2num($this->multicurrency_total_ht);
4164 $sql .=
", multicurrency_total_tva=".price2num($this->multicurrency_total_tva);
4165 $sql .=
", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc);
4167 $sql .=
" WHERE rowid = ".((int) $this->
id);
4169 dol_syslog(get_class($this).
"::updateline", LOG_DEBUG);
4170 $resql = $this->db->query($sql);
4179 if (!$error && !$notrigger) {
4181 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_MODIFY', $user);
4183 $this->db->rollback();
4190 $this->db->commit();
4193 $this->db->rollback();
4197 $this->error = $this->db->lasterror();
4198 $this->db->rollback();
4210 public function delete($user, $notrigger = 0)
4223 $this->db->rollback();
4227 $sql1 =
'UPDATE '.$this->db->prefix().
"commandedet SET fk_commandefourndet = NULL WHERE fk_commandefourndet=".((int) $this->
id);
4228 $resql = $this->db->query($sql1);
4230 $this->db->rollback();
4234 $sql2 =
'DELETE FROM '.$this->db->prefix().
"commande_fournisseurdet WHERE rowid=".((int) $this->
id);
4237 $resql = $this->db->query($sql2);
4241 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_DELETE', $user);
4249 $this->db->commit();
4253 foreach ($this->errors as $errmsg) {
4254 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
4255 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
4257 $this->db->rollback();
4260 $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