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;
516 $this->socid = $obj->fk_soc;
517 $this->thirdparty =
null;
519 $this->fourn_id = $obj->fk_soc;
520 $this->
statut = $obj->status;
521 $this->
status = $obj->status;
522 $this->billed = $obj->billed;
523 $this->last_main_doc = $obj->last_main_doc;
524 $this->user_author_id = $obj->user_author_id;
525 $this->user_validation_id = $obj->user_validation_id;
526 $this->user_approve_id = $obj->user_approve_id;
527 $this->user_approve_id2 = $obj->user_approve_id2;
528 $this->total_ht = $obj->total_ht;
529 $this->total_tva = $obj->total_tva;
530 $this->total_localtax1 = $obj->localtax1;
531 $this->total_localtax2 = $obj->localtax2;
532 $this->total_ttc = $obj->total_ttc;
533 $this->date_creation = $this->db->jdate($obj->date_creation);
534 $this->date_valid = $this->db->jdate($obj->date_valid);
535 $this->date_approve = $this->db->jdate($obj->date_approve);
536 $this->date_approve2 = $this->db->jdate($obj->date_approve2);
537 $this->date_commande = $this->db->jdate($obj->date_commande);
538 if (isset($obj->date_commande)) {
539 $this->date = $this->date_commande;
541 $this->date = $this->date_creation;
543 $this->delivery_date = $this->db->jdate($obj->delivery_date);
544 $this->remise_percent = $obj->remise_percent;
545 $this->methode_commande_id = $obj->fk_input_method;
546 $this->methode_commande = $obj->methode_commande;
548 $this->source = $obj->source;
549 $this->fk_project = $obj->fk_project;
550 $this->cond_reglement_id = $obj->fk_cond_reglement;
551 $this->cond_reglement_code = $obj->cond_reglement_code;
552 $this->cond_reglement = $obj->cond_reglement_label;
553 $this->cond_reglement_label = $obj->cond_reglement_label;
554 $this->cond_reglement_doc = $obj->cond_reglement_doc;
555 $this->fk_account = $obj->fk_account;
556 $this->mode_reglement_id = $obj->fk_mode_reglement;
557 $this->mode_reglement_code = $obj->mode_reglement_code;
558 $this->mode_reglement = $obj->mode_reglement_libelle;
559 $this->note = $obj->note_private;
560 $this->note_private = $obj->note_private;
561 $this->note_public = $obj->note_public;
562 $this->model_pdf = $obj->model_pdf;
565 $this->fk_incoterms = $obj->fk_incoterms;
566 $this->location_incoterms = $obj->location_incoterms;
567 $this->label_incoterms = $obj->label_incoterms;
570 $this->fk_multicurrency = $obj->fk_multicurrency;
571 $this->multicurrency_code = $obj->multicurrency_code;
572 $this->multicurrency_tx = $obj->multicurrency_tx;
573 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
574 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
575 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
577 $this->extraparams = isset($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
579 $this->db->free($resql);
594 $this->error = $this->db->error().
" sql=".$sql;
610 $this->lines = array();
612 $sql =
"SELECT l.rowid, l.fk_commande, l.ref as ref_supplier, l.fk_product, l.product_type, l.label, l.description, l.qty,";
613 $sql .=
" l.vat_src_code, l.tva_tx, l.remise_percent, l.subprice,";
614 $sql .=
" l.localtax1_tx, l. localtax2_tx, l.localtax1_type, l. localtax2_type, l.total_localtax1, l.total_localtax2,";
615 $sql .=
" l.total_ht, l.total_tva, l.total_ttc, l.info_bits, l.special_code, l.fk_parent_line, l.rang,";
616 $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,";
617 $sql .=
" l.fk_unit,";
618 $sql .=
" l.date_start, l.date_end,";
619 $sql .=
' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc';
620 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseurdet as l";
621 $sql .=
' LEFT JOIN '.$this->db->prefix().
'product as p ON l.fk_product = p.rowid';
622 $sql .=
" WHERE l.fk_commande = ".((int) $this->
id);
624 $sql .=
' AND p.fk_product_type = 0';
626 $sql .=
" ORDER BY l.rang, l.rowid";
629 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
631 $result = $this->db->query($sql);
633 $num = $this->db->num_rows($result);
637 $objp = $this->db->fetch_object($result);
641 $line->id = $objp->rowid;
642 $line->fk_commande = $objp->fk_commande;
643 $line->desc = $objp->description;
644 $line->description = $objp->description;
645 $line->qty = $objp->qty;
646 $line->tva_tx = $objp->tva_tx;
647 $line->localtax1_tx = $objp->localtax1_tx;
648 $line->localtax2_tx = $objp->localtax2_tx;
649 $line->localtax1_type = $objp->localtax1_type;
650 $line->localtax2_type = $objp->localtax2_type;
651 $line->subprice = $objp->subprice;
652 $line->pu_ht = $objp->subprice;
653 $line->remise_percent = $objp->remise_percent;
655 $line->vat_src_code = $objp->vat_src_code;
656 $line->total_ht = $objp->total_ht;
657 $line->total_tva = $objp->total_tva;
658 $line->total_localtax1 = $objp->total_localtax1;
659 $line->total_localtax2 = $objp->total_localtax2;
660 $line->total_ttc = $objp->total_ttc;
661 $line->product_type = $objp->product_type;
663 $line->fk_product = $objp->fk_product;
665 $line->libelle = $objp->product_label;
666 $line->product_label = $objp->product_label;
667 $line->product_desc = $objp->product_desc;
668 $line->product_tobatch = $objp->product_tobatch;
669 $line->product_barcode = $objp->product_barcode;
671 $line->ref = $objp->product_ref;
672 $line->product_ref = $objp->product_ref;
673 $line->ref_fourn = $objp->ref_supplier;
674 $line->ref_supplier = $objp->ref_supplier;
681 $sqlsearchpackage =
'SELECT rowid, packaging FROM '.$this->db->prefix().
"product_fournisseur_price";
682 $sqlsearchpackage .=
' WHERE entity IN ('.getEntity(
'product_fournisseur_price').
")";
683 $sqlsearchpackage .=
" AND fk_product = ".((int) $objp->fk_product);
684 $sqlsearchpackage .=
" AND ref_fourn = '".$this->db->escape($objp->ref_supplier).
"'";
685 $sqlsearchpackage .=
" AND quantity <= ".((float) $objp->qty);
686 $sqlsearchpackage .=
" AND (packaging IS NULL OR packaging = 0 OR packaging <= ".((float) $objp->qty).
")";
687 $sqlsearchpackage .=
" AND fk_soc = ".((int) $this->socid);
688 $sqlsearchpackage .=
" ORDER BY packaging ASC";
689 $sqlsearchpackage .=
" LIMIT 1";
691 $resqlsearchpackage = $this->db->query($sqlsearchpackage);
692 if ($resqlsearchpackage) {
693 $objsearchpackage = $this->db->fetch_object($resqlsearchpackage);
694 if ($objsearchpackage) {
695 $line->fk_fournprice = $objsearchpackage->rowid;
696 $line->packaging = $objsearchpackage->packaging;
699 $this->error = $this->db->lasterror();
704 $line->date_start = $this->db->jdate($objp->date_start);
705 $line->date_end = $this->db->jdate($objp->date_end);
706 $line->fk_unit = $objp->fk_unit;
709 $line->fk_multicurrency = $objp->fk_multicurrency;
710 $line->multicurrency_code = $objp->multicurrency_code;
711 $line->multicurrency_subprice = $objp->multicurrency_subprice;
712 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
713 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
714 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
716 $line->info_bits = $objp->info_bits;
717 $line->special_code = $objp->special_code;
718 $line->fk_parent_line = $objp->fk_parent_line;
720 $line->rang = $objp->rang;
724 $line->fetch_optionals();
726 $this->lines[$i] = $line;
730 $this->db->free($result);
734 $this->error = $this->db->error().
" sql=".$sql;
747 public function valid($user, $idwarehouse = 0, $notrigger = 0)
750 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
756 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")))
757 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"fournisseur",
"supplier_order_advance",
"validate"))) {
762 $soc->fetch($this->fourn_id);
765 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
772 $sql =
'UPDATE '.$this->db->prefix().
"commande_fournisseur";
773 $sql .=
" SET ref='".$this->db->escape($num).
"',";
774 $sql .=
" fk_statut = ".((int) self::STATUS_VALIDATED).
",";
775 $sql .=
" date_valid='".$this->db->idate(
dol_now()).
"',";
776 $sql .=
" fk_user_valid = ".((int) $user->id);
777 $sql .=
" WHERE rowid = ".((int) $this->
id);
778 $sql .=
" AND fk_statut = ".((int) self::STATUS_DRAFT);
780 $resql = $this->db->query($sql);
786 if (!$error && !$notrigger) {
788 $result = $this->
call_trigger(
'ORDER_SUPPLIER_VALIDATE', $user);
796 $this->oldref = $this->ref;
799 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
801 $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).
"'";
802 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'fournisseur/commande/".$this->db->escape($this->
ref).
"' and entity = ".((int) $conf->entity);
803 $resql = $this->db->query($sql);
806 $this->error = $this->db->lasterror();
808 $sql =
'UPDATE '.$this->db->prefix().
"ecm_files set filepath = 'fournisseur/commande/".$this->db->escape($this->newref).
"'";
809 $sql .=
" WHERE filepath = 'fournisseur/commande/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
810 $resql = $this->db->query($sql);
813 $this->error = $this->db->lasterror();
819 $dirsource = $conf->fournisseur->commande->dir_output.
'/'.$oldref;
820 $dirdest = $conf->fournisseur->commande->dir_output.
'/'.$newref;
821 if (!$error && file_exists($dirsource)) {
822 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
824 if (@rename($dirsource, $dirdest)) {
827 $listoffiles =
dol_dir_list($conf->fournisseur->commande->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
828 foreach ($listoffiles as $fileentry) {
829 $dirsource = $fileentry[
'name'];
830 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
831 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
832 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
833 @rename($dirsource, $dirdest);
851 $this->db->rollback();
855 $this->error =
'NotAuthorized';
856 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
881 public function LibStatut($status, $mode = 0, $billed = 0)
884 global $langs, $hookmanager;
886 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
887 $langs->load(
'orders');
889 $this->labelStatus[0] =
'StatusSupplierOrderDraft';
890 $this->labelStatus[1] =
'StatusSupplierOrderValidated';
891 $this->labelStatus[2] =
'StatusSupplierOrderApproved';
893 $this->labelStatus[3] =
'StatusSupplierOrderOnProcess';
895 $this->labelStatus[3] =
'StatusSupplierOrderOnProcessWithValidation';
897 $this->labelStatus[4] =
'StatusSupplierOrderReceivedPartially';
898 $this->labelStatus[5] =
'StatusSupplierOrderReceivedAll';
899 $this->labelStatus[6] =
'StatusSupplierOrderCanceled';
900 $this->labelStatus[7] =
'StatusSupplierOrderCanceled';
901 $this->labelStatus[9] =
'StatusSupplierOrderRefused';
904 $this->labelStatusShort[0] =
'StatusSupplierOrderDraftShort';
905 $this->labelStatusShort[1] =
'StatusSupplierOrderValidatedShort';
906 $this->labelStatusShort[2] =
'StatusSupplierOrderApprovedShort';
907 $this->labelStatusShort[3] =
'StatusSupplierOrderOnProcessShort';
908 $this->labelStatusShort[4] =
'StatusSupplierOrderReceivedPartiallyShort';
909 $this->labelStatusShort[5] =
'StatusSupplierOrderReceivedAllShort';
910 $this->labelStatusShort[6] =
'StatusSupplierOrderCanceledShort';
911 $this->labelStatusShort[7] =
'StatusSupplierOrderCanceledShort';
912 $this->labelStatusShort[9] =
'StatusSupplierOrderRefusedShort';
915 $statustrans = array(
927 $statusClass =
'status0';
928 if (!empty($statustrans[$status])) {
929 $statusClass = $statustrans[$status];
934 $billedtext =
' - '.$langs->trans(
"Billed");
936 if ($status == 5 && $billed) {
937 $statusClass =
'status6';
940 $statusLong = $langs->transnoentitiesnoconv($this->labelStatus[$status]).$billedtext;
941 $statusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
943 $parameters = array(
'status' => $status,
'mode' => $mode,
'billed' => $billed);
944 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
946 return $hookmanager->resPrint;
949 return dolGetStatus($statusLong, $statusShort,
'', $statusClass, $mode);
961 global $conf, $langs, $user;
963 $langs->loadLangs([
'bills',
'orders']);
966 $nofetch = !empty($params[
'nofetch']);
968 if ($user->hasRight(
"fournisseur",
"commande",
"read")) {
969 $datas[
'picto'] =
'<u class="paddingrightonly">'.$langs->trans(
"SupplierOrder").
'</u>';
970 if (isset($this->
statut)) {
971 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
973 if (!empty($this->
ref)) {
974 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
976 if (!empty($this->ref_supplier)) {
977 $datas[
'refsupplier'] =
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.$this->ref_supplier;
980 $langs->load(
'companies');
981 if (empty($this->thirdparty)) {
984 $datas[
'supplier'] =
'<br><b>'.$langs->trans(
'Supplier').
':</b> '.$this->thirdparty->getNomUrl(1,
'', 0, 1);
986 if (!empty($this->total_ht)) {
987 $datas[
'totalht'] =
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
989 if (!empty($this->total_tva)) {
990 $datas[
'totaltva'] =
'<br><b>'.$langs->trans(
'VAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
992 if (!empty($this->total_ttc)) {
993 $datas[
'totalttc'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
995 if (!empty($this->date)) {
996 $datas[
'date'] =
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->date,
'day');
998 if (!empty($this->delivery_date)) {
999 $datas[
'deliverydate'] =
'<br><b>'.$langs->trans(
'DeliveryDate').
':</b> '.
dol_print_date($this->delivery_date,
'dayhour');
1015 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = 0)
1017 global $langs, $user, $hookmanager;
1022 'objecttype' => $this->element,
1023 'option' => $option,
1026 $classfortooltip =
'classfortooltip';
1029 $classfortooltip =
'classforajaxtooltip';
1030 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
1036 $url = DOL_URL_ROOT.
'/fourn/commande/card.php?id='.$this->id;
1038 if ($option !==
'nolink') {
1040 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
1041 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
1042 $add_save_lastsearch_values = 1;
1044 if ($add_save_lastsearch_values) {
1045 $url .=
'&save_lastsearch_values=1';
1050 if (empty($notooltip)) {
1052 $label = $langs->trans(
"ShowOrder");
1053 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
1055 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
1056 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
1059 $linkstart =
'<a href="'.$url.
'"';
1060 $linkstart .= $linkclose.
'>';
1063 $result .= $linkstart;
1065 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
1067 if ($withpicto != 2) {
1068 $result .= $this->ref;
1070 $result .= $linkend;
1072 if ($addlinktonotes) {
1073 $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
1076 $result .=
' <span class="note inline-block">';
1077 $result .=
'<a href="'.DOL_URL_ROOT.
'/fourn/commande/note.php?id='.$this->
id.
'" class="classfortooltip" title="'.
dol_escape_htmltag($notetoshow).
'">';
1082 $result .=
'</span>';
1087 $hookmanager->initHooks(array($this->element .
'dao'));
1088 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
1089 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1091 $result = $hookmanager->resPrint;
1093 $result .= $hookmanager->resPrint;
1108 global $langs, $conf;
1109 $langs->load(
"orders");
1118 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
1120 foreach ($dirmodels as $reldir) {
1121 $dir =
dol_buildpath($reldir.
"core/modules/supplier_order/");
1124 $mybool = ((bool) @include_once $dir.$file) || $mybool;
1127 if ($mybool ===
false) {
1132 $obj =
new $classname();
1133 $numref = $obj->getNextValue($soc, $this);
1135 if ($numref !=
"") {
1138 $this->error = $obj->error;
1142 $this->error =
"Error_COMMANDE_SUPPLIER_ADDON_NotDefined";
1156 if ($this->billed) {
1162 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur SET billed = 1';
1165 if ($this->db->query($sql)) {
1168 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CLASSIFY_BILLED', $user);
1178 $this->db->commit();
1181 $this->db->rollback();
1187 $this->db->rollback();
1200 public function approve($user, $idwarehouse = 0, $secondlevel = 0)
1202 global $langs, $conf;
1203 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1209 if ($user->hasRight(
"fournisseur",
"commande",
"approuver")) {
1215 $soc =
new Societe($this->db);
1216 $soc->fetch($this->fourn_id);
1219 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
1227 $movetoapprovestatus =
true;
1230 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1231 $sql .=
" SET ref='".$this->db->escape($num).
"',";
1232 if (empty($secondlevel)) {
1233 $sql .=
" date_approve='".$this->db->idate($now).
"',";
1234 $sql .=
" fk_user_approve = ".$user->id;
1235 if (
getDolGlobalString(
'SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED') && $this->total_ht >= $conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) {
1236 if (empty($this->user_approve_id2)) {
1237 $movetoapprovestatus =
false;
1238 $comment =
' (first level)';
1242 $sql .=
" date_approve2='".$this->db->idate($now).
"',";
1243 $sql .=
" fk_user_approve2 = ".((int) $user->id);
1244 if (empty($this->user_approve_id)) {
1245 $movetoapprovestatus =
false;
1247 $comment =
' (second level)';
1250 if ($movetoapprovestatus) {
1251 $sql .=
", fk_statut = ".self::STATUS_ACCEPTED;
1253 $sql .=
", fk_statut = ".self::STATUS_VALIDATED;
1255 $sql .=
" WHERE rowid = ".((int) $this->
id);
1256 $sql .=
" AND fk_statut = ".self::STATUS_VALIDATED;
1258 if ($this->db->query($sql)) {
1260 $result = $this->
add_contact($user->id,
'SALESREPFOLL',
'internal', 1);
1261 if ($result < 0 && $result != -2) {
1267 if (!$error && $movetoapprovestatus && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER')) {
1268 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1269 $langs->load(
"agenda");
1271 $cpt = count($this->lines);
1272 for ($i = 0; $i < $cpt; $i++) {
1274 if ($this->lines[$i]->fk_product > 0) {
1275 $this->line = $this->lines[$i];
1277 $mouvP->origin = &$this;
1278 $mouvP->setOrigin($this->element, $this->
id);
1280 $up_ht_disc = $this->lines[$i]->subprice;
1281 if (!empty($this->lines[$i]->remise_percent) && !
getDolGlobalString(
'STOCK_EXCLUDE_DISCOUNT_FOR_PMP')) {
1282 $up_ht_disc =
price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100,
'MU');
1284 $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans(
"OrderApprovedInDolibarr", $this->ref));
1295 $result = $this->
call_trigger(
'ORDER_SUPPLIER_APPROVE', $user);
1303 $this->
ref = $this->newref;
1305 if ($movetoapprovestatus) {
1310 if (empty($secondlevel)) {
1311 $this->date_approve = $now;
1312 $this->user_approve_id = $user->id;
1314 $this->date_approve2 = $now;
1315 $this->user_approve_id2 = $user->id;
1318 $this->db->commit();
1321 $this->db->rollback();
1325 $this->db->rollback();
1326 $this->error = $this->db->lasterror();
1330 dol_syslog(get_class($this).
"::approve Not Authorized", LOG_ERR);
1343 global $conf, $langs;
1349 if ($user->hasRight(
"fournisseur",
"commande",
"approuver")) {
1352 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur SET fk_statut = ".
self::STATUS_REFUSED;
1353 $sql .=
" WHERE rowid = ".((int) $this->
id);
1355 if ($this->db->query($sql)) {
1360 $result = $this->
call_trigger(
'ORDER_SUPPLIER_REFUSE', $user);
1363 $this->db->rollback();
1365 $this->db->commit();
1370 $this->db->rollback();
1371 $this->error = $this->db->lasterror();
1372 dol_syslog(get_class($this).
"::refuse Error -1");
1376 dol_syslog(get_class($this).
"::refuse Not Authorized");
1390 public function Cancel($user, $idwarehouse = -1)
1393 global $langs, $conf;
1399 if ($user->hasRight(
"fournisseur",
"commande",
"commander")) {
1404 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur SET fk_statut = ".((int) $statut);
1405 $sql .=
" WHERE rowid = ".((int) $this->
id);
1406 dol_syslog(get_class($this).
"::cancel", LOG_DEBUG);
1407 if ($this->db->query($sql)) {
1411 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CANCEL', $user);
1418 $this->db->commit();
1421 $this->db->rollback();
1425 $this->db->rollback();
1426 $this->error = $this->db->lasterror();
1427 dol_syslog(get_class($this).
"::cancel ".$this->error);
1431 dol_syslog(get_class($this).
"::cancel Not Authorized");
1445 public function commande($user, $date, $methode, $comment =
'')
1450 if ($user->hasRight(
"fournisseur",
"commande",
"commander")) {
1453 $newnoteprivate = $this->note_private;
1455 $newnoteprivate =
dol_concatdesc($newnoteprivate, $langs->trans(
"Comment").
': '.$comment);
1458 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1459 $sql .=
" SET fk_statut=".self::STATUS_ORDERSENT.
", fk_input_method=".$methode.
", date_commande='".$this->db->idate($date).
"', ";
1460 $sql .=
" note_private='".$this->db->escape($newnoteprivate).
"'";
1461 $sql .=
" WHERE rowid=".((int) $this->
id);
1463 dol_syslog(get_class($this).
"::commande", LOG_DEBUG);
1464 if ($this->db->query($sql)) {
1466 $this->methode_commande_id = $methode;
1467 $this->date_commande = $date;
1468 $this->context = array(
'comments' => $comment);
1471 $result = $this->
call_trigger(
'ORDER_SUPPLIER_SUBMIT', $user);
1478 $this->error = $this->db->lasterror();
1479 $this->errors[] = $this->db->lasterror();
1483 $this->db->commit();
1485 $this->db->rollback();
1489 $this->error = $langs->trans(
'NotAuthorized');
1490 $this->errors[] = $langs->trans(
'NotAuthorized');
1491 dol_syslog(get_class($this).
"::commande User not Authorized", LOG_WARNING);
1494 return ($error ? -1 : 1);
1504 public function create($user, $notrigger = 0)
1506 global $langs, $conf, $hookmanager;
1514 $date = ($this->date_commande ? $this->date_commande : $this->date);
1518 $delivery_date = $this->delivery_date;
1521 if (empty($this->source)) {
1526 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
1531 if (empty($this->fk_multicurrency)) {
1532 $this->multicurrency_code = $conf->currency;
1533 $this->fk_multicurrency = 0;
1534 $this->multicurrency_tx = 1;
1541 $sql =
"INSERT INTO ".$this->db->prefix().
"commande_fournisseur (";
1543 $sql .=
", ref_supplier";
1544 $sql .=
", note_private";
1545 $sql .=
", note_public";
1548 $sql .=
", fk_projet";
1549 $sql .=
", date_creation";
1550 $sql .=
", date_livraison";
1551 $sql .=
", fk_user_author";
1552 $sql .=
", fk_statut";
1554 $sql .=
", model_pdf";
1555 $sql .=
", fk_mode_reglement";
1556 $sql .=
", fk_cond_reglement";
1557 $sql .=
", fk_account";
1558 $sql .=
", fk_incoterms, location_incoterms";
1559 $sql .=
", fk_multicurrency";
1560 $sql .=
", multicurrency_code";
1561 $sql .=
", multicurrency_tx";
1563 $sql .=
" VALUES (";
1565 $sql .=
", ".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"NULL");
1566 $sql .=
", '".$this->db->escape($this->note_private).
"'";
1567 $sql .=
", '".$this->db->escape($this->note_public).
"'";
1568 $sql .=
", ".setEntity($this);
1569 $sql .=
", ".((int) $this->socid);
1570 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
1571 $sql .=
", '".$this->db->idate($date).
"'";
1572 $sql .=
", ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
"null");
1573 $sql .=
", ".((int) $user->id);
1574 $sql .=
", ".self::STATUS_DRAFT;
1575 $sql .=
", ".((int) $this->source);
1576 $sql .=
", '".$this->db->escape(
getDolGlobalString(
'COMMANDE_SUPPLIER_ADDON_PDF')).
"'";
1577 $sql .=
", ".($this->mode_reglement_id > 0 ? $this->mode_reglement_id :
'null');
1578 $sql .=
", ".($this->cond_reglement_id > 0 ? $this->cond_reglement_id :
'null');
1579 $sql .=
", ".($this->fk_account > 0 ? $this->fk_account :
'NULL');
1580 $sql .=
", ".(int) $this->fk_incoterms;
1581 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
1582 $sql .=
", ".(int) $this->fk_multicurrency;
1583 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1584 $sql .=
", ".(float) $this->multicurrency_tx;
1587 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1588 if ($this->db->query($sql)) {
1589 $this->
id = $this->db->last_insert_id($this->db->prefix().
"commande_fournisseur");
1592 $num = count($this->lines);
1595 for ($i = 0; $i < $num; $i++) {
1596 $line = $this->lines[$i];
1597 if (!is_object($line)) {
1598 $line = (object) $line;
1609 $line->localtax1_tx,
1610 $line->localtax2_tx,
1614 $line->remise_percent,
1617 $line->product_type,
1622 $line->array_options,
1624 $line->multicurrency_subprice,
1631 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
1632 $this->db->rollback();
1637 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1638 $sql .=
" SET ref='(PROV".$this->id.
")'";
1639 $sql .=
" WHERE rowid=".((int) $this->
id);
1641 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1642 if ($this->db->query($sql)) {
1645 $this->
ref =
"(PROV".$this->id.
")";
1647 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
1648 $this->linked_objects = $this->linkedObjectsIds;
1652 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
1653 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
1654 if (is_array($tmp_origin_id)) {
1655 foreach ($tmp_origin_id as $origin_id) {
1663 $origin_id = $tmp_origin_id;
1681 if (!$error && !$notrigger) {
1683 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CREATE', $user);
1685 $this->db->rollback();
1693 $this->db->commit();
1696 $this->db->rollback();
1700 $this->error = $this->db->lasterror();
1701 $this->db->rollback();
1706 $this->error =
'Failed to get ID of inserted line';
1711 $this->error = $this->db->lasterror();
1712 $this->db->rollback();
1732 if (isset($this->
ref)) {
1733 $this->
ref = trim($this->
ref);
1735 if (isset($this->ref_supplier)) {
1736 $this->ref_supplier = trim($this->ref_supplier);
1738 if (isset($this->note_private)) {
1739 $this->note_private = trim($this->note_private);
1741 if (isset($this->note_public)) {
1742 $this->note_public = trim($this->note_public);
1744 if (isset($this->model_pdf)) {
1745 $this->model_pdf = trim($this->model_pdf);
1747 if (isset($this->import_key)) {
1748 $this->import_key = trim($this->import_key);
1752 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
1754 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1755 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
1756 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1757 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
1758 $sql .=
" date_commande=".(strval($this->date_commande) !=
'' ?
"'".$this->db->idate($this->date_commande).
"'" :
'null').
",";
1759 $sql .=
" date_valid=".(strval($this->date_validation) !=
'' ?
"'".$this->db->idate($this->date_validation).
"'" :
'null').
",";
1760 $sql .=
" total_tva=".(isset($this->total_tva) ? $this->total_tva :
"null").
",";
1761 $sql .=
" localtax1=".(isset($this->total_localtax1) ? $this->total_localtax1 :
"null").
",";
1762 $sql .=
" localtax2=".(isset($this->total_localtax2) ? $this->total_localtax2 :
"null").
",";
1763 $sql .=
" total_ht=".(isset($this->total_ht) ? $this->total_ht :
"null").
",";
1764 $sql .=
" total_ttc=".(isset($this->total_ttc) ? $this->total_ttc :
"null").
",";
1765 $sql .=
" fk_statut=".(isset($this->
statut) ? $this->
statut :
"null").
",";
1766 $sql .=
" fk_user_author=".(isset($this->user_author_id) ? $this->user_author_id :
"null").
",";
1767 $sql .=
" fk_user_valid=".(isset($this->user_validation_id) && $this->user_validation_id > 0 ? $this->user_validation_id :
"null").
",";
1768 $sql .=
" fk_projet=".(isset($this->fk_project) ? $this->fk_project :
"null").
",";
1769 $sql .=
" fk_cond_reglement=".(isset($this->cond_reglement_id) ? $this->cond_reglement_id :
"null").
",";
1770 $sql .=
" fk_mode_reglement=".(isset($this->mode_reglement_id) ? $this->mode_reglement_id :
"null").
",";
1771 $sql .=
" date_livraison=".(strval($this->delivery_date) !=
'' ?
"'".$this->db->idate($this->delivery_date).
"'" :
'null').
",";
1773 $sql .=
" fk_account=".($this->fk_account > 0 ? $this->fk_account :
"null").
",";
1775 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1776 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1777 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1778 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
1780 $sql .=
" WHERE rowid=".((int) $this->
id);
1784 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1785 $resql = $this->db->query($sql);
1788 $this->errors[] =
"Error ".$this->db->lasterror();
1798 if (!$error && !$notrigger) {
1800 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
1809 foreach ($this->errors as $errmsg) {
1810 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1811 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1813 $this->db->rollback();
1816 $this->db->commit();
1831 global $conf, $user, $hookmanager;
1838 foreach ($this->lines as $line) {
1839 $line->fetch_optionals();
1843 $objFrom = clone $this;
1846 if (!empty($socid) && $socid != $this->socid) {
1847 $objsoc =
new Societe($this->db);
1849 if ($objsoc->fetch($socid) > 0) {
1850 $this->socid = $objsoc->id;
1851 $this->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1852 $this->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1853 $this->fk_project = 0;
1854 $this->fk_delivery_address = 0;
1864 $this->user_author_id = $user->id;
1865 $this->user_validation_id = 0;
1868 $this->date_creation = 0;
1869 $this->date_validation = 0;
1870 $this->date_commande = 0;
1871 $this->ref_supplier =
'';
1872 $this->user_approve_id = 0;
1873 $this->user_approve_id2 = 0;
1874 $this->date_approve = 0;
1875 $this->date_approve2 = 0;
1878 $this->context[
'createfromclone'] =
'createfromclone';
1879 $result = $this->
create($user, $notrigger);
1886 if (is_object($hookmanager)) {
1887 $parameters = array(
'objFrom' => $objFrom);
1889 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1897 unset($this->context[
'createfromclone']);
1901 $this->db->commit();
1904 $this->db->rollback();
1938 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)
1940 global $langs, $mysoc, $conf;
1942 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");
1943 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1945 if ($this->
statut == self::STATUS_DRAFT) {
1946 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1955 if (empty($txtva)) {
1961 if (empty($txlocaltax1)) {
1964 if (empty($txlocaltax2)) {
1967 if (empty($remise_percent)) {
1968 $remise_percent = 0;
1971 $remise_percent =
price2num($remise_percent);
1974 $pu_ht_devise =
price2num($pu_ht_devise);
1976 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
1981 if ($price_base_type ==
'HT') {
1986 $desc = trim($desc);
1989 if ($qty < 0 && !$fk_product) {
1990 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Product"));
1996 if ($date_start && $date_end && $date_start > $date_end) {
1997 $langs->load(
"errors");
1998 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
2005 $product_type = $type;
2008 if ($fk_product > 0) {
2011 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);
2013 if ($prod->fetch($fk_product) > 0) {
2014 $product_type = $prod->type;
2015 $label = $prod->label;
2019 $result = $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', (isset($this->fk_soc) ? $this->fk_soc : $this->socid));
2023 if ($result > 0 && ($origin ==
'commande' || $pu ===
'')) {
2024 $pu = $prod->fourn_pu;
2025 $ref_supplier = $prod->ref_supplier;
2027 if ($remise_percent == 0 && $prod->remise_percent != 0) {
2028 $remise_percent = $prod->remise_percent;
2032 $langs->load(
"errors");
2033 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
2034 $this->db->rollback();
2035 dol_syslog(get_class($this).
"::addline we did not found supplier price, so we can't guess unit price");
2040 if ($result == -1) {
2041 $langs->load(
"errors");
2042 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
2043 $this->db->rollback();
2044 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_DEBUG);
2048 $this->error = $prod->error;
2049 $this->db->rollback();
2050 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_ERR);
2054 $this->error = $prod->error;
2055 $this->db->rollback();
2062 $prod =
new Product($this->db);
2063 $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', (empty($this->fk_soc) ? $this->socid : $this->fk_soc));
2065 if ($qty < $prod->packaging) {
2066 $qty = $prod->packaging;
2068 if (!empty($prod->packaging) && ($qty % $prod->packaging) > 0) {
2069 $coeff = intval($qty / $prod->packaging) + 1;
2070 $qty = $prod->packaging * $coeff;
2071 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'mesgs');
2077 if (isModEnabled(
"multicurrency") && $pu_ht_devise > 0) {
2086 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
2087 $vat_src_code = $reg[1];
2088 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
2096 $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);
2098 $total_ht = $tabprice[0];
2099 $total_tva = $tabprice[1];
2100 $total_ttc = $tabprice[2];
2101 $total_localtax1 = $tabprice[9];
2102 $total_localtax2 = $tabprice[10];
2103 $pu = $pu_ht = $tabprice[3];
2106 $multicurrency_total_ht = $tabprice[16];
2107 $multicurrency_total_tva = $tabprice[17];
2108 $multicurrency_total_ttc = $tabprice[18];
2109 $pu_ht_devise = $tabprice[19];
2111 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2112 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2116 $rang = $rangmax + 1;
2122 $this->line->context = $this->context;
2124 $this->line->fk_commande = $this->id;
2125 $this->line->label = $label;
2126 $this->line->ref_fourn = $ref_supplier;
2127 $this->line->ref_supplier = $ref_supplier;
2128 $this->line->desc = $desc;
2129 $this->line->qty = $qty;
2130 $this->line->tva_tx = $txtva;
2131 $this->line->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0);
2132 $this->line->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0);
2133 $this->line->localtax1_type = $localtax1_type;
2134 $this->line->localtax2_type = $localtax2_type;
2135 $this->line->fk_product = $fk_product;
2136 $this->line->product_type = $product_type;
2137 $this->line->remise_percent = $remise_percent;
2138 $this->line->subprice = $pu_ht;
2139 $this->line->rang = $rang;
2140 $this->line->info_bits = $info_bits;
2142 $this->line->vat_src_code = $vat_src_code;
2143 $this->line->total_ht = $total_ht;
2144 $this->line->total_tva = $total_tva;
2145 $this->line->total_localtax1 = $total_localtax1;
2146 $this->line->total_localtax2 = $total_localtax2;
2147 $this->line->total_ttc = $total_ttc;
2148 $this->line->product_type = $type;
2149 $this->line->special_code = (!empty($special_code) ? $special_code : 0);
2150 $this->line->origin = $origin;
2151 $this->line->origin_id = $origin_id;
2152 $this->line->fk_unit = $fk_unit;
2154 $this->line->date_start = $date_start;
2155 $this->line->date_end = $date_end;
2158 $this->line->fk_multicurrency = $this->fk_multicurrency;
2159 $this->line->multicurrency_code = $this->multicurrency_code;
2160 $this->line->multicurrency_subprice = $pu_ht_devise;
2161 $this->line->multicurrency_total_ht = $multicurrency_total_ht;
2162 $this->line->multicurrency_total_tva = $multicurrency_total_tva;
2163 $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
2165 $this->line->subprice = $pu_ht;
2166 $this->line->price = $this->line->subprice;
2168 $this->line->remise_percent = $remise_percent;
2170 if (is_array($array_options) && count($array_options) > 0) {
2171 $this->line->array_options = $array_options;
2174 $result = $this->line->insert($notrigger);
2177 if (!empty($this->line->fk_parent_line)) {
2179 } elseif ($rang > 0 && $rang <= count($this->lines)) {
2180 $linecount = count($this->lines);
2181 for ($ii = $rang; $ii <= $linecount; $ii++) {
2187 $result = $this->
update_price(1,
'auto', 0, $this->thirdparty);
2189 $this->db->commit();
2190 return $this->line->id;
2192 $this->db->rollback();
2196 $this->error = $this->line->error;
2197 $this->errors = $this->line->errors;
2198 dol_syslog(get_class($this).
"::addline error=".$this->error, LOG_ERR);
2199 $this->db->rollback();
2224 public function dispatchProduct($user, $product, $qty, $entrepot, $price = 0, $comment =
'', $eatby =
'', $sellby =
'', $batch =
'', $fk_commandefourndet = 0, $notrigger = 0, $fk_reception = 0)
2226 global $conf, $langs;
2229 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2232 if ($entrepot <= 0) {
2233 $this->error =
'ErrorBadValueForParameterWarehouse';
2237 $this->error =
'ErrorBadValueForParameterQty';
2241 $dispatchstatus = 1;
2243 $dispatchstatus = 0;
2250 if (($this->
statut == self::STATUS_ORDERSENT || $this->
statut == self::STATUS_RECEIVED_PARTIALLY || $this->
statut == self::STATUS_RECEIVED_COMPLETELY)) {
2253 $sql =
"INSERT INTO ".$this->db->prefix().
"receptiondet_batch";
2254 $sql .=
" (fk_element, fk_product, qty, fk_entrepot, fk_user, datec, fk_elementdet, status, comment, eatby, sellby, batch, fk_reception) VALUES";
2255 $sql .=
" ('".$this->id.
"','".$product.
"','".$qty.
"',".($entrepot > 0 ?
"'".$entrepot.
"'" :
"null").
",'".$user->id.
"','".$this->db->idate($now).
"','".$fk_commandefourndet.
"', ".$dispatchstatus.
", '".$this->db->escape($comment).
"', ";
2256 $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");
2259 dol_syslog(get_class($this).
"::dispatchProduct", LOG_DEBUG);
2260 $resql = $this->db->query($sql);
2263 global $conf, $langs, $user;
2265 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_DISPATCH', $user);
2272 $this->error = $this->db->lasterror();
2277 if (!$error && $entrepot > 0 && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER')) {
2281 $mouv->origin = &$this;
2282 $mouv->setOrigin($this->element, $this->
id);
2285 if (
getDolGlobalString(
'SUPPLIER_ORDER_ALLOW_NEGATIVE_QTY_FOR_SUPPLIER_ORDER_RETURN') && $qty < 0) {
2286 $result = $mouv->livraison($user, $product, $entrepot, $qty * (-1), $price, $comment, $now, $eatby, $sellby, $batch, 0, $inventorycode);
2288 $result = $mouv->reception($user, $product, $entrepot, $qty, $price, $comment, $eatby, $sellby, $batch,
'', 0, $inventorycode);
2292 $this->error = $mouv->error;
2293 $this->errors = $mouv->errors;
2294 dol_syslog(get_class($this).
"::dispatchProduct ".$this->error.
" ".implode(
',', $this->errors), LOG_ERR);
2301 $this->db->commit();
2304 $this->db->rollback();
2308 $this->error =
'BadStatusForObject';
2324 if ($this->
statut == 0) {
2327 if ($line->fetch($idline) <= 0) {
2333 foreach ($dispatchedLines as $dispatchLine) {
2334 if ($dispatchLine[
'orderlineid'] == $idline) {
2335 $this->error =
"LineAlreadyDispatched";
2336 $this->errors[] = $this->error;
2341 if ($line->delete($user, $notrigger) > 0) {
2360 public function delete(
User $user, $notrigger = 0)
2362 global $langs, $conf;
2363 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2369 if (empty($notrigger)) {
2371 $result = $this->
call_trigger(
'ORDER_SUPPLIER_DELETE', $user);
2373 $this->errors[] =
'ErrorWhenRunningTrigger';
2374 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2375 $this->db->rollback();
2383 if (!empty($this->linkedObjects) && array_key_exists(
'reception', $this->linkedObjects)) {
2384 foreach ($this->linkedObjects[
'reception'] as $element) {
2385 if ($element->statut >= 0) {
2386 $this->errors[] = $langs->trans(
'ReceptionExist');
2393 $main = $this->db->prefix().
'commande_fournisseurdet';
2396 $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).
")";
2397 dol_syslog(__METHOD__.
" linked order lines", LOG_DEBUG);
2398 if (!$this->db->query($sql1)) {
2400 $this->error = $this->db->lasterror();
2401 $this->errors[] = $this->db->lasterror();
2406 $ef = $main.
"_extrafields";
2407 $sql =
"DELETE FROM ".$this->db->sanitize($ef).
" WHERE fk_object IN (SELECT rowid FROM ".$this->db->sanitize($main).
" WHERE fk_commande = ".((int) $this->
id).
")";
2408 dol_syslog(get_class($this).
"::delete extrafields lines", LOG_DEBUG);
2409 if (!$this->db->query($sql)) {
2410 $this->error = $this->db->lasterror();
2411 $this->errors[] = $this->db->lasterror();
2417 $sql =
"DELETE FROM ".$this->db->prefix().
"commande_fournisseurdet WHERE fk_commande = ".((int) $this->
id);
2418 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2419 if (!$this->db->query($sql)) {
2420 $this->error = $this->db->lasterror();
2421 $this->errors[] = $this->db->lasterror();
2427 $sql =
"DELETE FROM ".$this->db->prefix().
"commande_fournisseur WHERE rowid = ".((int) $this->
id);
2428 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2429 if ($resql = $this->db->query($sql)) {
2430 if ($this->db->affected_rows($resql) < 1) {
2431 $this->error = $this->db->lasterror();
2432 $this->errors[] = $this->db->lasterror();
2436 $this->error = $this->db->lasterror();
2437 $this->errors[] = $this->db->lasterror();
2446 $this->error =
'FailToDeleteExtraFields';
2447 $this->errors[] =
'FailToDeleteExtraFields';
2449 dol_syslog(get_class($this).
"::delete error -4 ".$this->error, LOG_ERR);
2456 $this->error =
'FailToDeleteObjectLinked';
2457 $this->errors[] =
'FailToDeleteObjectLinked';
2468 if ($conf->fournisseur->commande->dir_output) {
2469 $dir = $conf->fournisseur->commande->dir_output.
"/".$ref;
2470 $file = $dir.
"/".$ref.
".pdf";
2471 if (file_exists($file)) {
2473 $this->error =
'ErrorFailToDeleteFile';
2474 $this->errors[] =
'ErrorFailToDeleteFile';
2478 if (file_exists($dir)) {
2481 $this->error =
'ErrorFailToDeleteDir';
2482 $this->errors[] =
'ErrorFailToDeleteDir';
2490 dol_syslog(get_class($this).
"::delete $this->id by $user->id", LOG_DEBUG);
2491 $this->db->commit();
2494 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2495 $this->db->rollback();
2514 $sql =
"SELECT p.ref, p.label,";
2515 $sql .=
" e.rowid as warehouse_id, e.ref as entrepot,";
2516 $sql .=
" cfd.rowid as dispatchedlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status, cfd.fk_elementdet";
2517 $sql .=
" FROM ".$this->db->prefix().
"product as p,";
2518 $sql .=
" ".$this->db->prefix().
"receptiondet_batch as cfd";
2519 $sql .=
" LEFT JOIN ".$this->db->prefix().
"entrepot as e ON cfd.fk_entrepot = e.rowid";
2520 $sql .=
" WHERE cfd.fk_element = ".((int) $this->
id);
2521 $sql .=
" AND cfd.fk_product = p.rowid";
2523 $sql .=
" AND cfd.status = ".((int) $status);
2525 $sql .=
" ORDER BY cfd.rowid ASC";
2527 $resql = $this->db->query($sql);
2529 $num = $this->db->num_rows($resql);
2533 $objp = $this->db->fetch_object($resql);
2536 'id' => $objp->dispatchedlineid,
2537 'productid' => $objp->fk_product,
2538 'warehouseid' => $objp->warehouse_id,
2539 'qty' => $objp->qty,
2540 'orderlineid' => $objp->fk_elementdet
2547 dol_print_error($this->db,
'Failed to execute request to get dispatched lines');
2566 global $conf, $langs;
2573 $usercanreceive = 0;
2574 if (!isModEnabled(
'reception')) {
2575 $usercanreceive = $user->hasRight(
"fournisseur",
"commande",
"receptionner");
2577 $usercanreceive = $user->hasRight(
"reception",
"creer");
2580 if ($usercanreceive) {
2582 if ($type ==
'par') {
2584 } elseif ($type ==
'tot') {
2586 } elseif ($type ==
'nev') {
2588 } elseif ($type ==
'can') {
2592 dol_syslog(get_class($this).
"::Livraison Error -2", LOG_ERR);
2599 if (!$error && ($type ==
'tot')) {
2601 if (count($dispatchedlinearray) > 0) {
2604 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove';
2605 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove', LOG_DEBUG);
2608 if (!$error &&
getDolGlobalString(
'SUPPLIER_ORDER_USE_DISPATCH_STATUS_NEED_APPROVE') && ($type ==
'tot')) {
2610 if (count($dispatchedlinearray) > 0) {
2613 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied';
2614 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied', LOG_DEBUG);
2621 if (empty($error)) {
2624 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2625 $sql .=
" SET fk_statut = ".((int) $statut);
2626 $sql .=
" WHERE rowid = ".((int) $this->
id);
2627 $sql .=
" AND fk_statut IN (".self::STATUS_ORDERSENT.
",".self::STATUS_RECEIVED_PARTIALLY.
")";
2629 dol_syslog(get_class($this).
"::Livraison", LOG_DEBUG);
2630 $resql = $this->db->query($sql);
2633 $old_statut = $this->statut;
2635 $this->context[
'actionmsg2'] = $comment;
2638 $result_trigger = $this->
call_trigger(
'ORDER_SUPPLIER_RECEIVE', $user);
2639 if ($result_trigger < 0) {
2644 if (empty($error)) {
2645 $this->db->commit();
2647 $this->
statut = $old_statut;
2648 $this->db->rollback();
2649 $this->error = $this->db->lasterror();
2653 $this->db->rollback();
2654 $this->error = $this->db->lasterror();
2659 $this->error = $langs->trans(
'NotAuthorized');
2660 $this->errors[] = $langs->trans(
'NotAuthorized');
2661 dol_syslog(get_class($this).
"::Livraison Not Authorized");
2693 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
2698 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2699 $sql .=
" SET date_livraison = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2700 $sql .=
" WHERE rowid = ".((int) $this->
id);
2703 $resql = $this->db->query($sql);
2705 $this->errors[] = $this->db->error();
2710 $this->oldcopy = clone $this;
2711 $this->delivery_date = $delivery_date;
2714 if (!$notrigger && empty($error)) {
2716 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2724 $this->db->commit();
2727 foreach ($this->errors as $errmsg) {
2728 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2729 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2731 $this->db->rollback();
2751 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
2756 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2757 $sql .=
" SET fk_projet = ".($id_projet > 0 ? (int) $id_projet :
'null');
2758 $sql .=
" WHERE rowid = ".((int) $this->
id);
2761 $resql = $this->db->query($sql);
2763 $this->errors[] = $this->db->error();
2768 $this->oldcopy = clone $this;
2769 $this->fk_projet = $id_projet;
2770 $this->fk_project = $id_projet;
2773 if (!$notrigger && empty($error)) {
2775 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2783 $this->db->commit();
2786 foreach ($this->errors as $errmsg) {
2787 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2788 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2790 $this->db->rollback();
2808 $comclient =
new Commande($this->db);
2809 $comclient->fetch($comclientid);
2813 $this->lines = array();
2815 $num = count($comclient->lines);
2816 for ($i = 0; $i < $num; $i++) {
2817 $prod =
new Product($this->db);
2820 if ($prod->fetch($comclient->lines[$i]->fk_product) > 0) {
2821 $label = $prod->label;
2825 $sql =
"INSERT INTO ".$this->db->prefix().
"commande_fournisseurdet";
2826 $sql .=
" (fk_commande, label, description, fk_product, price, qty, tva_tx, localtax1_tx, localtax2_tx, remise_percent, subprice, remise, ref)";
2827 $sql .=
" VALUES (".((int) $idc).
", '".$this->db->escape($label).
"', '".$this->db->escape($comclient->lines[$i]->desc).
"'";
2828 $sql .=
",".$comclient->lines[$i]->fk_product.
", ".
price2num($comclient->lines[$i]->price,
'MU');
2829 $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);
2830 $sql .=
", '".price2num($comclient->lines[$i]->subprice,
'MT').
"','0', '".$this->db->escape($ref).
"');";
2831 if ($this->db->query($sql)) {
2848 global $conf, $langs;
2853 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur';
2854 $sql .=
" SET fk_statut = ".$status;
2855 $sql .=
" WHERE rowid = ".((int) $this->
id);
2857 dol_syslog(get_class($this).
"::setStatus", LOG_DEBUG);
2858 $resql = $this->db->query($sql);
2861 $triggerName = array();
2862 $triggerName[0] =
'DRAFT';
2863 $triggerName[1] =
'VALIDATED';
2864 $triggerName[2] =
'APPROVED';
2865 $triggerName[3] =
'ORDERED';
2866 $triggerName[4] =
'RECEIVED_PARTIALLY';
2867 $triggerName[5] =
'RECEIVED_COMPLETELY';
2868 $triggerName[6] =
'CANCELED';
2869 $triggerName[7] =
'CANCELED';
2870 $triggerName[9] =
'REFUSED';
2873 $result = $this->
call_trigger(
"ORDER_SUPPLIER_STATUS_".$triggerName[$status], $user);
2880 $this->error = $this->db->lasterror();
2881 dol_syslog(get_class($this).
"::setStatus ".$this->error);
2886 $this->db->commit();
2889 $this->db->rollback();
2917 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 =
'')
2919 global $mysoc, $conf, $langs;
2920 dol_syslog(get_class($this).
"::updateline $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $type, $fk_unit");
2921 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2925 if ($this->
statut == self::STATUS_DRAFT) {
2930 if (empty($info_bits)) {
2933 if (empty($txtva)) {
2936 if (empty($txlocaltax1)) {
2939 if (empty($txlocaltax2)) {
2942 if (empty($remise_percent)) {
2943 $remise_percent = 0;
2946 $remise_percent = (float)
price2num($remise_percent);
2952 $pu_ht_devise =
price2num($pu_ht_devise);
2953 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
2956 $txlocaltax1 = (float)
price2num($txlocaltax1);
2957 $txlocaltax2 = (float)
price2num($txlocaltax2);
2963 if ($date_start && $date_end && $date_start > $date_end) {
2964 $langs->load(
"errors");
2965 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
2981 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
2982 $vat_src_code = $reg[1];
2983 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
2986 $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);
2987 $total_ht = $tabprice[0];
2988 $total_tva = $tabprice[1];
2989 $total_ttc = $tabprice[2];
2990 $total_localtax1 = $tabprice[9];
2991 $total_localtax2 = $tabprice[10];
2992 $pu_ht = $tabprice[3];
2993 $pu_tva = $tabprice[4];
2994 $pu_ttc = $tabprice[5];
2997 $multicurrency_total_ht = $tabprice[16];
2998 $multicurrency_total_tva = $tabprice[17];
2999 $multicurrency_total_ttc = $tabprice[18];
3000 $pu_ht_devise = $tabprice[19];
3002 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
3003 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
3007 $this->line->fetch($rowid);
3009 $oldline = clone $this->line;
3010 $this->line->oldline = $oldline;
3012 $this->line->context = $this->context;
3014 $this->line->fk_commande = $this->id;
3016 $this->line->desc = $desc;
3020 if ($qty < $this->line->packaging) {
3021 $qty = $this->line->packaging;
3023 if (!empty($this->line->packaging) && ($qty % $this->line->packaging) > 0) {
3024 $coeff = intval($qty / $this->line->packaging) + 1;
3025 $qty = $this->line->packaging * $coeff;
3026 setEventMessage($langs->trans(
'QtyRecalculatedWithPackaging'),
'mesgs');
3031 $this->line->qty = $qty;
3032 $this->line->ref_supplier = $ref_supplier;
3034 $this->line->vat_src_code = $vat_src_code;
3035 $this->line->tva_tx = $txtva;
3036 $this->line->localtax1_tx = $txlocaltax1;
3037 $this->line->localtax2_tx = $txlocaltax2;
3038 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
3039 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
3040 $this->line->remise_percent = $remise_percent;
3041 $this->line->subprice = $pu_ht;
3042 $this->line->info_bits = $info_bits;
3043 $this->line->total_ht = $total_ht;
3044 $this->line->total_tva = $total_tva;
3045 $this->line->total_localtax1 = $total_localtax1;
3046 $this->line->total_localtax2 = $total_localtax2;
3047 $this->line->total_ttc = $total_ttc;
3048 $this->line->product_type = $type;
3049 $this->line->special_code = $oldline->special_code;
3050 $this->line->rang = $oldline->rang;
3051 $this->line->origin = $this->origin;
3052 $this->line->fk_unit = $fk_unit;
3054 $this->line->date_start = $date_start;
3055 $this->line->date_end = $date_end;
3058 $this->line->fk_multicurrency = $this->fk_multicurrency;
3059 $this->line->multicurrency_code = $this->multicurrency_code;
3060 $this->line->multicurrency_subprice = $pu_ht_devise;
3061 $this->line->multicurrency_total_ht = $multicurrency_total_ht;
3062 $this->line->multicurrency_total_tva = $multicurrency_total_tva;
3063 $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
3065 $this->line->subprice = $pu_ht;
3066 $this->line->price = $this->line->subprice;
3068 $this->line->remise_percent = $remise_percent;
3070 if (is_array($array_options) && count($array_options) > 0) {
3072 foreach ($array_options as $key => $value) {
3073 $this->line->array_options[$key] = $array_options[$key];
3077 $result = $this->line->update($notrigger);
3083 $this->db->commit();
3086 $this->errors[] = $this->line->error;
3087 $this->errors = array_merge($this->errors, $this->line->errors);
3088 $this->error = $this->db->lasterror();
3089 $this->db->rollback();
3093 $this->error =
"Order status makes operation forbidden";
3094 dol_syslog(get_class($this).
"::updateline ".$this->error, LOG_ERR);
3109 global $user, $langs, $conf;
3111 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
3113 dol_syslog(get_class($this).
"::initAsSpecimen");
3120 $sql =
"SELECT rowid";
3121 $sql .=
" FROM ".$this->db->prefix().
"product";
3122 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
3123 $sql .= $this->db->order(
"rowid",
"ASC");
3124 $sql .= $this->db->plimit(1);
3125 $resql = $this->db->query($sql);
3126 if ($resql && $this->db->num_rows($resql)) {
3127 $obj = $this->db->fetch_object($resql);
3128 $prodid = $obj->rowid;
3133 $this->
ref =
'SPECIMEN';
3134 $this->specimen = 1;
3137 $this->date_commande = $now;
3138 $this->date_lim_reglement = $this->date + 3600 * 24 * 30;
3139 $this->cond_reglement_code =
'RECEP';
3140 $this->mode_reglement_code =
'CHQ';
3142 $this->note_public =
'This is a comment (public)';
3143 $this->note_private =
'This is a comment (private)';
3145 $this->multicurrency_tx = 1;
3146 $this->multicurrency_code = $conf->currency;
3153 while ($xnbp < $nbp) {
3155 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
3157 $line->subprice = 100;
3158 $line->tva_tx = 19.6;
3159 $line->localtax1_tx = 0;
3160 $line->localtax2_tx = 0;
3162 $line->total_ht = 50;
3163 $line->total_ttc = 59.8;
3164 $line->total_tva = 9.8;
3165 $line->remise_percent = 50;
3167 $line->total_ht = 100;
3168 $line->total_ttc = 119.6;
3169 $line->total_tva = 19.6;
3170 $line->remise_percent = 00;
3172 $line->fk_product = $prodid;
3174 $this->lines[$xnbp] = $line;
3176 $this->total_ht += $line->total_ht;
3177 $this->total_tva += $line->total_tva;
3178 $this->total_ttc += $line->total_ttc;
3194 $sql =
'SELECT c.rowid, date_creation as datec, tms as datem, date_valid as date_validation, date_approve as datea, date_approve2 as datea2,';
3195 $sql .=
' fk_user_author, fk_user_modif, fk_user_valid, fk_user_approve, fk_user_approve2';
3196 $sql .=
' FROM '.$this->db->prefix().
'commande_fournisseur as c';
3197 $sql .=
' WHERE c.rowid = '.((int) $id);
3199 $result = $this->db->query($sql);
3201 if ($this->db->num_rows($result)) {
3202 $obj = $this->db->fetch_object($result);
3204 $this->
id = $obj->rowid;
3206 $this->user_creation_id = $obj->fk_user_author;
3207 $this->user_validation_id = $obj->fk_user_valid;
3208 $this->user_modification_id = $obj->fk_user_modif;
3209 $this->user_approve_id = $obj->fk_user_approve;
3210 $this->user_approve_id2 = $obj->fk_user_approve2;
3212 $this->date_creation = $this->db->jdate($obj->datec);
3213 $this->date_modification = $this->db->jdate($obj->datem);
3214 $this->date_approve = $this->db->jdate($obj->datea);
3215 $this->date_approve2 = $this->db->jdate($obj->datea2);
3216 $this->date_validation = $this->db->jdate($obj->date_validation);
3218 $this->db->free($result);
3231 global $conf, $user;
3233 $this->nb = array();
3236 $sql =
"SELECT count(co.rowid) as nb";
3237 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as co";
3238 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe as s ON co.fk_soc = s.rowid";
3239 if (empty($user->socid) && !$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3240 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
3241 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
3244 $sql .=
" ".$clause.
" co.entity IN (".
getEntity(
'supplier_order').
")";
3246 $resql = $this->db->query($sql);
3248 while ($obj = $this->db->fetch_object($resql)) {
3249 $this->nb[
"supplier_orders"] = $obj->nb;
3251 $this->db->free($resql);
3255 $this->error = $this->db->error();
3271 global $conf, $langs;
3273 $sql =
"SELECT c.rowid, c.date_creation as datec, c.date_commande, c.fk_statut, c.date_livraison as delivery_date, c.total_ht";
3274 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as c";
3275 if (empty($user->socid) && !$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3276 $sql .=
" JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
3278 $sql .=
" WHERE c.entity = ".$conf->entity;
3279 if ($mode ===
'awaiting') {
3280 $sql .=
" AND c.fk_statut IN (".self::STATUS_ORDERSENT.
", ".self::STATUS_RECEIVED_PARTIALLY.
")";
3282 $sql .=
" AND c.fk_statut IN (".self::STATUS_VALIDATED.
", ".self::STATUS_ACCEPTED.
")";
3285 $sql .=
" AND c.fk_soc = ".((int) $user->socid);
3288 $resql = $this->db->query($sql);
3293 $response->warning_delay = $conf->commande->fournisseur->warning_delay / 60 / 60 / 24;
3294 $response->label = $langs->trans(
"SuppliersOrdersToProcess");
3295 $response->labelShort = $langs->trans(
"Opened");
3296 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=1,2&mainmenu=commercial&leftmenu=orders_suppliers';
3299 if ($mode ===
'awaiting') {
3300 $response->label = $langs->trans(
"SuppliersOrdersAwaitingReception");
3301 $response->labelShort = $langs->trans(
"AwaitingReception");
3302 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=3,4&mainmenu=commercial&leftmenu=orders_suppliers';
3305 while ($obj = $this->db->fetch_object($resql)) {
3306 $commandestatic->delivery_date = $this->db->jdate($obj->delivery_date);
3307 $commandestatic->date_commande = $this->db->jdate($obj->date_commande);
3308 $commandestatic->statut = $obj->fk_statut;
3310 $response->nbtodo++;
3311 $response->total += $obj->total_ht;
3313 if ($commandestatic->hasDelay()) {
3314 $response->nbtodolate++;
3320 $this->error = $this->db->error();
3335 if ($this->methode_commande_id > 0) {
3336 $sql =
"SELECT rowid, code, libelle as label";
3337 $sql .=
" FROM ".$this->db->prefix().
'c_input_method';
3338 $sql .=
" WHERE active=1 AND rowid = ".((int) $this->methode_commande_id);
3340 $resql = $this->db->query($sql);
3342 if ($this->db->num_rows($resql)) {
3343 $obj = $this->db->fetch_object($resql);
3345 $string = $langs->trans($obj->code);
3346 if ($string == $obj->code) {
3347 $string = $obj->label !=
'-' ? $obj->label :
'';
3370 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3372 global $conf, $langs;
3377 if (!empty($this->model_pdf)) {
3378 $modele = $this->model_pdf;
3384 if (empty($modele)) {
3387 $langs->load(
"suppliers");
3388 $outputlangs->load(
"products");
3390 $modelpath =
"core/modules/supplier_order/doc/";
3391 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3404 if (empty($this->lines)) {
3411 foreach ($this->lines as $line) {
3412 if ($line->fk_product > 0) {
3414 $idp = $tmpproductfourn->find_min_price_product_fournisseur($line->fk_product, $line->qty, $this->thirdparty->id);
3417 if ($tmpproductfourn->delivery_time_days > $nb) {
3418 $nb = $tmpproductfourn->delivery_time_days;
3427 return $nb.
' '.$langs->trans(
'days');
3440 return $user->hasRight(
"fournisseur",
"commande");
3455 'commande_fournisseur'
3472 'commande_fournisseurdet'
3489 if ($this->
statut == self::STATUS_ORDERSENT || $this->
statut == self::STATUS_RECEIVED_PARTIALLY) {
3491 if (!empty($this->delivery_date)) {
3492 $date_to_test = $this->delivery_date;
3493 return $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay);
3501 $date_to_test = $this->date_commande;
3503 return ($this->
statut > 0 && $this->
statut < 5) && $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay);
3516 global $conf, $langs;
3518 $langs->load(
'orders');
3522 if ($this->
statut == self::STATUS_ORDERSENT || $this->
statut == self::STATUS_RECEIVED_PARTIALLY) {
3523 if (!empty($this->delivery_date)) {
3524 $text = $langs->trans(
"DeliveryDate").
' '.
dol_print_date($this->delivery_date,
'day');
3526 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3529 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3532 $text .=
' '.($conf->commande->fournisseur->warning_delay > 0 ?
'+' :
'-').
' '.round(abs($conf->commande->fournisseur->warning_delay) / 3600 / 24, 1).
' '.$langs->trans(
"days").
' < '.$langs->trans(
"Today");
3549 if (isModEnabled(
"supplier_order")) {
3550 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
3552 $qtydelivered = array();
3553 $qtywished = array();
3557 $filter = array(
't.fk_element' => $this->
id);
3559 $filter[
't.status'] = 1;
3562 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
3564 $this->error = $supplierorderdispatch->error;
3565 $this->errors = $supplierorderdispatch->errors;
3568 if (is_array($supplierorderdispatch->lines) && count($supplierorderdispatch->lines) > 0) {
3569 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
3573 foreach ($supplierorderdispatch->lines as $line) {
3574 if (array_key_exists($line->fk_product, $qtydelivered)) {
3575 $qtydelivered[$line->fk_product] += $line->qty;
3577 $qtydelivered[$line->fk_product] = $line->qty;
3580 foreach ($this->lines as $line) {
3585 if (array_key_exists($line->fk_product, $qtywished)) {
3586 $qtywished[$line->fk_product] += $line->qty;
3588 $qtywished[$line->fk_product] = $line->qty;
3593 $diff_array = array_diff_assoc($qtydelivered, $qtywished);
3594 $keysinwishednotindelivered = array_diff(array_keys($qtywished), array_keys($qtydelivered));
3595 $keysindeliverednotinwished = array_diff(array_keys($qtydelivered), array_keys($qtywished));
3603 if (count($diff_array) == 0 && count($keysinwishednotindelivered) == 0 && count($keysindeliverednotinwished) == 0) {
3604 if ($closeopenorder) {
3606 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3614 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3625 if (count($diff_array) > 0) {
3629 foreach ($diff_array as $key => $value) {
3631 if ($qtydelivered[$key] >= $qtywished[$key]) {
3638 if ($close == count($diff_array)) {
3640 if ($closeopenorder) {
3641 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3648 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3656 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3664 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3686 $this->receptions = array();
3688 dol_syslog(get_class($this).
"::loadReceptions", LOG_DEBUG);
3690 $sql =
'SELECT cd.rowid, cd.fk_product,';
3691 $sql .=
' sum(cfd.qty) as qty';
3692 $sql .=
' FROM '.$this->db->prefix().
'receptiondet_batch as cfd,';
3693 if ($filtre_statut >= 0) {
3694 $sql .=
' '.$this->db->prefix().
'reception as e,';
3696 $sql .=
' '.$this->db->prefix().
'commande_fournisseurdet as cd';
3698 if ($filtre_statut >= 0) {
3699 $sql .=
' cfd.fk_reception = e.rowid AND';
3701 $sql .=
' cfd.fk_elementdet = cd.rowid';
3702 $sql .=
' AND cd.fk_commande ='.((int) $this->
id);
3703 if (isset($this->fk_product) && !empty($this->fk_product) > 0) {
3704 $sql .=
' AND cd.fk_product = '.((int) $this->fk_product);
3706 if ($filtre_statut >= 0) {
3707 $sql .=
' AND e.fk_statut >= '.((int) $filtre_statut);
3709 $sql .=
' GROUP BY cd.rowid, cd.fk_product';
3711 $resql = $this->db->query($sql);
3713 $num = $this->db->num_rows($resql);
3716 $obj = $this->db->fetch_object($resql);
3717 empty($this->receptions[$obj->rowid]) ? $this->receptions[$obj->rowid] = $obj->qty : $this->receptions[$obj->rowid] += $obj->qty;
3720 $this->db->free($resql);
3724 $this->error = $this->db->lasterror();
3740 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3742 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3743 $return .=
'<div class="info-box info-box-sm">';
3744 $return .=
'<span class="info-box-icon bg-infobox-action">';
3746 $return .=
'</span>';
3747 $return .=
'<div class="info-box-content">';
3748 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
3749 if ($selected >= 0) {
3750 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3752 if (property_exists($this,
'socid') || property_exists($this,
'total_tva')) {
3753 $return .=
'<br><span class="info-box-label amount">'.$this->socid.
'</span>';
3755 if (property_exists($this,
'billed')) {
3756 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Billed").
' : </span><span class="info-box-label">'.
yn($this->billed).
'</span>';
3758 if (method_exists($this,
'getLibStatut')) {
3759 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
3761 $return .=
'</div>';
3762 $return .=
'</div>';
3763 $return .=
'</div>';
3778 public $element =
'commande_fournisseurdet';
3783 public $table_element =
'commande_fournisseurdet';
3801 public $fk_commande;
3807 public $fk_parent_line;
3819 public $special_code = 0;
3829 public $fk_fournprice;
3839 public $ref_supplier;
3869 $sql =
'SELECT cd.rowid, cd.fk_commande, cd.fk_product, cd.product_type, cd.description, cd.qty, cd.tva_tx, cd.special_code,';
3870 $sql .=
' cd.localtax1_tx, cd.localtax2_tx, cd.localtax1_type, cd.localtax2_type, cd.ref as ref_supplier,';
3871 $sql .=
' cd.remise, cd.remise_percent, cd.subprice,';
3872 $sql .=
' cd.info_bits, cd.total_ht, cd.total_tva, cd.total_ttc,';
3873 $sql .=
' cd.total_localtax1, cd.total_localtax2,';
3874 $sql .=
' p.ref as product_ref, p.label as product_label, p.description as product_desc,';
3875 $sql .=
' cd.date_start, cd.date_end, cd.fk_unit,';
3876 $sql .=
' cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc,';
3877 $sql .=
' c.fk_soc as socid';
3878 $sql .=
' FROM '.$this->db->prefix().
'commande_fournisseur as c, '.$this->db->prefix().
'commande_fournisseurdet as cd';
3879 $sql .=
' LEFT JOIN '.$this->db->prefix().
'product as p ON cd.fk_product = p.rowid';
3880 $sql .=
' WHERE cd.fk_commande = c.rowid AND cd.rowid = '.((int) $rowid);
3882 $result = $this->db->query($sql);
3884 $objp = $this->db->fetch_object($result);
3886 if (!empty($objp)) {
3887 $this->
rowid = $objp->rowid;
3888 $this->
id = $objp->rowid;
3889 $this->fk_commande = $objp->fk_commande;
3890 $this->desc = $objp->description;
3891 $this->qty = $objp->qty;
3892 $this->ref_fourn = $objp->ref_supplier;
3893 $this->ref_supplier = $objp->ref_supplier;
3894 $this->subprice = $objp->subprice;
3895 $this->tva_tx = $objp->tva_tx;
3896 $this->localtax1_tx = $objp->localtax1_tx;
3897 $this->localtax2_tx = $objp->localtax2_tx;
3898 $this->localtax1_type = $objp->localtax1_type;
3899 $this->localtax2_type = $objp->localtax2_type;
3900 $this->remise = $objp->remise;
3901 $this->remise_percent = $objp->remise_percent;
3902 $this->fk_product = $objp->fk_product;
3903 $this->info_bits = $objp->info_bits;
3904 $this->total_ht = $objp->total_ht;
3905 $this->total_tva = $objp->total_tva;
3906 $this->total_localtax1 = $objp->total_localtax1;
3907 $this->total_localtax2 = $objp->total_localtax2;
3908 $this->total_ttc = $objp->total_ttc;
3909 $this->product_type = $objp->product_type;
3910 $this->special_code = $objp->special_code;
3912 $this->
ref = $objp->product_ref;
3914 $this->product_ref = $objp->product_ref;
3915 $this->product_label = $objp->product_label;
3916 $this->product_desc = $objp->product_desc;
3923 $sqlsearchpackage =
'SELECT rowid, packaging FROM '.$this->db->prefix().
"product_fournisseur_price";
3924 $sqlsearchpackage .=
' WHERE entity IN ('.getEntity(
'product_fournisseur_price').
")";
3925 $sqlsearchpackage .=
" AND fk_product = ".((int) $objp->fk_product);
3926 $sqlsearchpackage .=
" AND ref_fourn = '".$this->db->escape($objp->ref_supplier).
"'";
3927 $sqlsearchpackage .=
" AND quantity <= ".((float) $objp->qty);
3928 $sqlsearchpackage .=
" AND (packaging IS NULL OR packaging = 0 OR packaging <= ".((float) $objp->qty).
")";
3929 $sqlsearchpackage .=
" AND fk_soc = ".((int) $objp->socid);
3930 $sqlsearchpackage .=
" ORDER BY packaging ASC";
3931 $sqlsearchpackage .=
" LIMIT 1";
3933 $resqlsearchpackage = $this->db->query($sqlsearchpackage);
3934 if ($resqlsearchpackage) {
3935 $objsearchpackage = $this->db->fetch_object($resqlsearchpackage);
3936 if ($objsearchpackage) {
3937 $this->fk_fournprice = $objsearchpackage->rowid;
3938 $this->packaging = $objsearchpackage->packaging;
3941 $this->error = $this->db->lasterror();
3946 $this->date_start = $this->db->jdate($objp->date_start);
3947 $this->date_end = $this->db->jdate($objp->date_end);
3948 $this->fk_unit = $objp->fk_unit;
3950 $this->multicurrency_subprice = $objp->multicurrency_subprice;
3951 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
3952 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
3953 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
3957 $this->db->free($result);
3960 $this->error =
'Supplier order line with id='.$rowid.
' not found';
3961 dol_syslog(get_class($this).
"::fetch Error ".$this->error, LOG_ERR);
3978 global $conf, $user;
3982 dol_syslog(get_class($this).
"::insert rang=".$this->rang);
3985 if (empty($this->tva_tx)) {
3988 if (empty($this->localtax1_tx)) {
3989 $this->localtax1_tx = 0;
3991 if (empty($this->localtax2_tx)) {
3992 $this->localtax2_tx = 0;
3994 if (empty($this->localtax1_type)) {
3995 $this->localtax1_type =
'0';
3997 if (empty($this->localtax2_type)) {
3998 $this->localtax2_type =
'0';
4000 if (empty($this->total_localtax1)) {
4001 $this->total_localtax1 = 0;
4003 if (empty($this->total_localtax2)) {
4004 $this->total_localtax2 = 0;
4006 if (empty($this->rang)) {
4009 if (empty($this->remise_percent)) {
4010 $this->remise_percent = 0;
4012 if (empty($this->info_bits)) {
4013 $this->info_bits = 0;
4015 if (empty($this->special_code)) {
4016 $this->special_code = 0;
4018 if (empty($this->fk_parent_line)) {
4019 $this->fk_parent_line = 0;
4021 if (empty($this->pa_ht)) {
4026 if (!empty($this->multicurrency_code)) {
4029 if (empty($this->fk_multicurrency)) {
4030 $this->multicurrency_code = $conf->currency;
4031 $this->fk_multicurrency = 0;
4032 $this->multicurrency_tx = 1;
4036 if ($this->product_type < 0) {
4043 $sql =
'INSERT INTO '.$this->db->prefix().$this->table_element;
4044 $sql .=
" (fk_commande, label, description, date_start, date_end,";
4045 $sql .=
" fk_product, product_type, special_code, rang,";
4046 $sql .=
" qty, vat_src_code, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, remise_percent, subprice, ref,";
4047 $sql .=
" total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_unit,";
4048 $sql .=
" fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc,";
4049 $sql .=
" fk_parent_line)";
4050 $sql .=
" VALUES (".$this->fk_commande.
", '".$this->db->escape($this->label).
"','".$this->db->escape($this->desc).
"',";
4051 $sql .=
" ".($this->date_start ?
"'".$this->db->idate($this->date_start).
"'" :
"null").
",";
4052 $sql .=
" ".($this->date_end ?
"'".$this->db->idate($this->date_end).
"'" :
"null").
",";
4053 if ($this->fk_product) {
4054 $sql .= $this->fk_product.
",";
4058 $sql .=
"'".$this->db->escape($this->product_type).
"',";
4059 $sql .= (int) $this->special_code .
",";
4060 $sql .=
"'".$this->db->escape($this->rang).
"',";
4061 $sql .=
"'".$this->db->escape($this->qty).
"', ";
4062 $sql .=
" ".(empty($this->vat_src_code) ?
"''" :
"'".$this->db->escape($this->vat_src_code).
"'").
",";
4063 $sql .=
" ".price2num($this->tva_tx).
", ";
4064 $sql .=
" ".price2num($this->localtax1_tx).
",";
4065 $sql .=
" ".price2num($this->localtax2_tx).
",";
4066 $sql .=
" '".$this->db->escape($this->localtax1_type).
"',";
4067 $sql .=
" '".$this->db->escape($this->localtax2_type).
"',";
4068 $sql .=
" ".((float) $this->remise_percent).
", ".
price2num($this->subprice,
'MU').
", '".$this->db->escape($this->ref_supplier).
"',";
4069 $sql .=
" ".price2num($this->total_ht).
",";
4070 $sql .=
" ".price2num($this->total_tva).
",";
4071 $sql .=
" ".price2num($this->total_localtax1).
",";
4072 $sql .=
" ".price2num($this->total_localtax2).
",";
4073 $sql .=
" ".price2num($this->total_ttc).
",";
4074 $sql .= ($this->fk_unit ?
"'".$this->db->escape($this->fk_unit).
"'" :
"null");
4075 $sql .=
", ".($this->fk_multicurrency ? ((int) $this->fk_multicurrency) :
"null");
4076 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
4077 $sql .=
", ".($this->multicurrency_subprice ?
price2num($this->multicurrency_subprice) :
'0');
4078 $sql .=
", ".($this->multicurrency_total_ht ?
price2num($this->multicurrency_total_ht) :
'0');
4079 $sql .=
", ".($this->multicurrency_total_tva ?
price2num($this->multicurrency_total_tva) :
'0');
4080 $sql .=
", ".($this->multicurrency_total_ttc ?
price2num($this->multicurrency_total_ttc) :
'0');
4081 $sql .=
", ".((!empty($this->fk_parent_line) && $this->fk_parent_line > 0) ? $this->fk_parent_line :
'null');
4084 dol_syslog(get_class($this).
"::insert", LOG_DEBUG);
4085 $resql = $this->db->query($sql);
4087 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
4088 $this->
rowid = $this->id;
4097 if (!$error && !$notrigger) {
4099 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_CREATE', $user);
4107 $this->db->commit();
4111 foreach ($this->errors as $errmsg) {
4112 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
4113 $this->errors[] = ($this->errors ?
', '.$errmsg : $errmsg);
4115 $this->db->rollback();
4118 $this->errors[] = $this->db->error();
4119 $this->db->rollback();
4138 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
4139 $sql .=
" description='".$this->db->escape($this->desc).
"'";
4140 $sql .=
", ref='".$this->db->escape($this->ref_supplier).
"'";
4141 $sql .=
", subprice='".price2num($this->subprice).
"'";
4143 $sql .=
", remise_percent='".price2num($this->remise_percent).
"'";
4145 $sql .=
", vat_src_code = '".(empty($this->vat_src_code) ?
'' : $this->vat_src_code).
"'";
4146 $sql .=
", tva_tx='".price2num($this->tva_tx).
"'";
4147 $sql .=
", localtax1_tx='".price2num($this->localtax1_tx).
"'";
4148 $sql .=
", localtax2_tx='".price2num($this->localtax2_tx).
"'";
4149 $sql .=
", localtax1_type='".$this->db->escape($this->localtax1_type).
"'";
4150 $sql .=
", localtax2_type='".$this->db->escape($this->localtax2_type).
"'";
4151 $sql .=
", qty='".price2num($this->qty).
"'";
4152 $sql .=
", date_start=".(!empty($this->date_start) ?
"'".$this->db->idate($this->date_start).
"'" :
"null");
4153 $sql .=
", date_end=".(!empty($this->date_end) ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
4154 $sql .=
", info_bits='".$this->db->escape($this->info_bits).
"'";
4155 $sql .=
", total_ht='".price2num($this->total_ht).
"'";
4156 $sql .=
", total_tva='".price2num($this->total_tva).
"'";
4157 $sql .=
", total_localtax1='".price2num($this->total_localtax1).
"'";
4158 $sql .=
", total_localtax2='".price2num($this->total_localtax2).
"'";
4159 $sql .=
", total_ttc='".price2num($this->total_ttc).
"'";
4160 $sql .=
", product_type=".$this->product_type;
4161 $sql .=
", special_code=".(!empty($this->special_code) ? $this->special_code : 0);
4162 $sql .= ($this->fk_unit ?
", fk_unit='".$this->db->escape($this->fk_unit).
"'" :
", fk_unit=null");
4165 $sql .=
", multicurrency_subprice=".price2num($this->multicurrency_subprice);
4166 $sql .=
", multicurrency_total_ht=".price2num($this->multicurrency_total_ht);
4167 $sql .=
", multicurrency_total_tva=".price2num($this->multicurrency_total_tva);
4168 $sql .=
", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc);
4170 $sql .=
" WHERE rowid = ".((int) $this->
id);
4172 dol_syslog(get_class($this).
"::updateline", LOG_DEBUG);
4173 $resql = $this->db->query($sql);
4182 if (!$error && !$notrigger) {
4184 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_MODIFY', $user);
4186 $this->db->rollback();
4193 $this->db->commit();
4196 $this->db->rollback();
4200 $this->error = $this->db->lasterror();
4201 $this->db->rollback();
4213 public function delete($user, $notrigger = 0)
4226 $this->db->rollback();
4230 $sql1 =
'UPDATE '.$this->db->prefix().
"commandedet SET fk_commandefourndet = NULL WHERE fk_commandefourndet=".((int) $this->
id);
4231 $resql = $this->db->query($sql1);
4233 $this->db->rollback();
4237 $sql2 =
'DELETE FROM '.$this->db->prefix().
"commande_fournisseurdet WHERE rowid=".((int) $this->
id);
4240 $resql = $this->db->query($sql2);
4244 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_DELETE', $user);
4252 $this->db->commit();
4256 foreach ($this->errors as $errmsg) {
4257 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
4258 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
4260 $this->db->rollback();
4263 $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