37require_once DOL_DOCUMENT_ROOT.
'/core/class/commonorder.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
39require_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
40if (isModEnabled(
'productbatch')) {
41 require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
53 public $element =
'order_supplier';
58 public $table_element =
'commande_fournisseur';
63 public $table_element_line =
'commande_fournisseurdet';
68 public $fk_element =
'fk_commande';
73 public $picto =
'supplier_order';
79 public $ismultientitymanaged = 1;
85 public $restrictiononfksoc = 1;
106 public $ref_supplier;
132 public $labelStatusShort;
139 public $date_creation;
141 public $date_approve;
142 public $date_approve2;
143 public $date_commande;
146 public $remise_percent;
147 public $methode_commande_id;
148 public $methode_commande;
153 public $delivery_date;
157 public $total_localtax1;
158 public $total_localtax2;
167 public $cond_reglement_id;
168 public $cond_reglement_code;
169 public $cond_reglement_label;
170 public $cond_reglement_doc;
180 public $mode_reglement_id;
185 public $mode_reglement_code;
190 public $mode_reglement;
192 public $user_author_id;
193 public $user_approve_id;
194 public $user_approve_id2;
198 public $extraparams = array();
203 public $lines = array();
213 public $linked_objects = array();
215 public $date_lim_reglement;
216 public $receptions = array();
222 public $fk_multicurrency;
224 public $multicurrency_code;
225 public $multicurrency_tx;
226 public $multicurrency_total_ht;
227 public $multicurrency_total_tva;
228 public $multicurrency_total_ttc;
258 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>0,
'notnull'=>1,
'position'=>10),
259 'ref' =>array(
'type'=>
'varchar(255)',
'label'=>
'Ref',
'enabled'=>1,
'visible'=>1,
'showoncombobox'=>1,
'position'=>25,
'searchall'=>1),
260 'ref_ext' =>array(
'type'=>
'varchar(255)',
'label'=>
'Ref ext',
'enabled'=>1,
'visible'=>0,
'position'=>35),
261 'ref_supplier' =>array(
'type'=>
'varchar(255)',
'label'=>
'RefOrderSupplierShort',
'enabled'=>1,
'visible'=>1,
'position'=>40,
'searchall'=>1),
262 'fk_projet' =>array(
'type'=>
'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)',
'label'=>
'Project',
'enabled'=>
"isModEnabled('project')",
'visible'=>-1,
'position'=>45),
263 'date_valid' =>array(
'type'=>
'datetime',
'label'=>
'DateValidation',
'enabled'=>1,
'visible'=>-1,
'position'=>710),
264 'date_approve' =>array(
'type'=>
'datetime',
'label'=>
'DateApprove',
'enabled'=>1,
'visible'=>-1,
'position'=>720),
265 'date_approve2' =>array(
'type'=>
'datetime',
'label'=>
'DateApprove2',
'enabled'=>1,
'visible'=>3,
'position'=>725),
266 'date_commande' =>array(
'type'=>
'date',
'label'=>
'OrderDateShort',
'enabled'=>1,
'visible'=>1,
'position'=>70),
267 'date_livraison' =>array(
'type'=>
'datetime',
'label'=>
'DeliveryDate',
'enabled'=>
'empty($conf->global->ORDER_DISABLE_DELIVERY_DATE)',
'visible'=>1,
'position'=>74),
268 'fk_user_author' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserAuthor',
'enabled'=>1,
'visible'=>3,
'position'=>41),
269 'fk_user_modif' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>3,
'notnull'=>-1,
'position'=>80),
270 'fk_user_valid' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserValidation',
'enabled'=>1,
'visible'=>3,
'position'=>711),
271 'fk_user_approve' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserApproval',
'enabled'=>1,
'visible'=>3,
'position'=>721),
272 'fk_user_approve2' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserApproval2',
'enabled'=>1,
'visible'=>3,
'position'=>726),
273 'source' =>array(
'type'=>
'smallint(6)',
'label'=>
'Source',
'enabled'=>1,
'visible'=>3,
'notnull'=>1,
'position'=>100),
274 'billed' =>array(
'type'=>
'smallint(6)',
'label'=>
'Billed',
'enabled'=>1,
'visible'=>1,
'position'=>710),
275 'total_ht' =>array(
'type'=>
'double(24,8)',
'label'=>
'AmountHT',
'enabled'=>1,
'visible'=>1,
'position'=>130,
'isameasure'=>1),
276 'total_tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'AmountVAT',
'enabled'=>1,
'visible'=>1,
'position'=>135,
'isameasure'=>1),
277 'localtax1' =>array(
'type'=>
'double(24,8)',
'label'=>
'LT1',
'enabled'=>1,
'visible'=>3,
'position'=>140,
'isameasure'=>1),
278 'localtax2' =>array(
'type'=>
'double(24,8)',
'label'=>
'LT2',
'enabled'=>1,
'visible'=>3,
'position'=>145,
'isameasure'=>1),
279 'total_ttc' =>array(
'type'=>
'double(24,8)',
'label'=>
'AmountTTC',
'enabled'=>1,
'visible'=>-1,
'position'=>150,
'isameasure'=>1),
280 'note_public' =>array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>750,
'searchall'=>1),
281 'note_private' =>array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>0,
'position'=>760,
'searchall'=>1),
282 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'ModelPDF',
'enabled'=>1,
'visible'=>0,
'position'=>165),
283 'fk_input_method' =>array(
'type'=>
'integer',
'label'=>
'OrderMode',
'enabled'=>1,
'visible'=>3,
'position'=>170),
284 'fk_cond_reglement' =>array(
'type'=>
'integer',
'label'=>
'PaymentTerm',
'enabled'=>1,
'visible'=>3,
'position'=>175),
285 'fk_mode_reglement' =>array(
'type'=>
'integer',
'label'=>
'PaymentMode',
'enabled'=>1,
'visible'=>3,
'position'=>180),
286 'extraparams' =>array(
'type'=>
'varchar(255)',
'label'=>
'Extraparams',
'enabled'=>1,
'visible'=>0,
'position'=>190),
287 'fk_account' =>array(
'type'=>
'integer',
'label'=>
'BankAccount',
'enabled'=>
'isModEnabled("banque")',
'visible'=>3,
'position'=>200),
288 'fk_incoterms' =>array(
'type'=>
'integer',
'label'=>
'IncotermCode',
'enabled'=>1,
'visible'=>3,
'position'=>205),
289 'location_incoterms' =>array(
'type'=>
'varchar(255)',
'label'=>
'IncotermLocation',
'enabled'=>1,
'visible'=>3,
'position'=>210),
290 'fk_multicurrency' =>array(
'type'=>
'integer',
'label'=>
'Fk multicurrency',
'enabled'=>1,
'visible'=>0,
'position'=>215),
291 'multicurrency_code' =>array(
'type'=>
'varchar(255)',
'label'=>
'Currency',
'enabled'=>
'isModEnabled("multicurrency")',
'visible'=>-1,
'position'=>220),
292 'multicurrency_tx' =>array(
'type'=>
'double(24,8)',
'label'=>
'CurrencyRate',
'enabled'=>
'isModEnabled("multicurrency")',
'visible'=>-1,
'position'=>225),
293 'multicurrency_total_ht' =>array(
'type'=>
'double(24,8)',
'label'=>
'MulticurrencyAmountHT',
'enabled'=>
'isModEnabled("multicurrency")',
'visible'=>-1,
'position'=>230),
294 'multicurrency_total_tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'MulticurrencyAmountVAT',
'enabled'=>
'isModEnabled("multicurrency")',
'visible'=>-1,
'position'=>235),
295 'multicurrency_total_ttc' =>array(
'type'=>
'double(24,8)',
'label'=>
'MulticurrencyAmountTTC',
'enabled'=>
'isModEnabled("multicurrency")',
'visible'=>-1,
'position'=>240),
296 'date_creation' =>array(
'type'=>
'datetime',
'label'=>
'Date creation',
'enabled'=>1,
'visible'=>-1,
'position'=>500),
297 'fk_soc' =>array(
'type'=>
'integer:Societe:societe/class/societe.class.php',
'label'=>
'ThirdParty',
'enabled'=>
'isModEnabled("societe")',
'visible'=>1,
'notnull'=>1,
'position'=>50),
298 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>0,
'notnull'=>1,
'position'=>1000,
'index'=>1),
299 'tms'=>array(
'type'=>
'datetime',
'label'=>
"DateModificationShort",
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>501),
300 'last_main_doc' =>array(
'type'=>
'varchar(255)',
'label'=>
'LastMainDoc',
'enabled'=>1,
'visible'=>0,
'position'=>700),
301 'fk_statut' =>array(
'type'=>
'smallint(6)',
'label'=>
'Status',
'enabled'=>1,
'visible'=>1,
'position'=>701),
302 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>0,
'position'=>900),
375 public function fetch($id, $ref =
'')
378 if (empty($id) && empty($ref)) {
382 $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,";
383 $sql .=
" c.localtax1, c.localtax2, ";
384 $sql .=
" c.date_creation, c.date_valid, c.date_approve, c.date_approve2,";
385 $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,";
386 $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,";
387 $sql .=
" c.fk_account,";
388 $sql .=
" c.note_private, c.note_public, c.model_pdf, c.extraparams, c.billed,";
389 $sql .=
" c.fk_multicurrency, c.multicurrency_code, c.multicurrency_tx, c.multicurrency_total_ht, c.multicurrency_total_tva, c.multicurrency_total_ttc,";
390 $sql .=
" cm.libelle as methode_commande,";
391 $sql .=
" cr.code as cond_reglement_code, cr.libelle as cond_reglement_label, cr.libelle_facture as cond_reglement_doc,";
392 $sql .=
" p.code as mode_reglement_code, p.libelle as mode_reglement_libelle";
393 $sql .=
', c.fk_incoterms, c.location_incoterms';
394 $sql .=
', c.last_main_doc';
395 $sql .=
', i.libelle as label_incoterms';
396 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as c";
397 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_payment_term as cr ON c.fk_cond_reglement = cr.rowid";
398 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_paiement as p ON c.fk_mode_reglement = p.id";
399 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_input_method as cm ON cm.rowid = c.fk_input_method";
400 $sql .=
' LEFT JOIN '.$this->db->prefix().
'c_incoterms as i ON c.fk_incoterms = i.rowid';
403 $sql .=
" WHERE c.entity IN (".getEntity(
'supplier_order').
")";
405 $sql .=
" WHERE c.rowid=".((int) $id);
409 $sql .=
" AND c.ref='".$this->db->escape($ref).
"'";
412 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
413 $resql = $this->db->query($sql);
415 $obj = $this->db->fetch_object($resql);
417 $this->error =
'Bill with id '.$id.
' not found';
418 dol_syslog(get_class($this).
'::fetch '.$this->error);
422 $this->
id = $obj->rowid;
423 $this->entity = $obj->entity;
425 $this->
ref = $obj->ref;
426 $this->ref_supplier = $obj->ref_supplier;
427 $this->socid = $obj->fk_soc;
428 $this->fourn_id = $obj->fk_soc;
429 $this->
statut = $obj->status;
430 $this->
status = $obj->status;
431 $this->billed = $obj->billed;
432 $this->last_main_doc = $obj->last_main_doc;
433 $this->user_author_id = $obj->user_author_id;
434 $this->user_validation_id = $obj->user_validation_id;
435 $this->user_approve_id = $obj->user_approve_id;
436 $this->user_approve_id2 = $obj->user_approve_id2;
437 $this->total_ht = $obj->total_ht;
438 $this->total_tva = $obj->total_tva;
439 $this->total_localtax1 = $obj->localtax1;
440 $this->total_localtax2 = $obj->localtax2;
441 $this->total_ttc = $obj->total_ttc;
442 $this->date_creation = $this->db->jdate($obj->date_creation);
443 $this->date_valid = $this->db->jdate($obj->date_valid);
444 $this->date_approve = $this->db->jdate($obj->date_approve);
445 $this->date_approve2 = $this->db->jdate($obj->date_approve2);
446 $this->date_commande = $this->db->jdate($obj->date_commande);
447 if (isset($obj->date_commande)) {
448 $this->date = $this->date_commande;
450 $this->date = $this->date_creation;
452 $this->delivery_date = $this->db->jdate($obj->delivery_date);
453 $this->remise_percent = $obj->remise_percent;
454 $this->methode_commande_id = $obj->fk_input_method;
455 $this->methode_commande = $obj->methode_commande;
457 $this->source = $obj->source;
458 $this->fk_project = $obj->fk_project;
459 $this->cond_reglement_id = $obj->fk_cond_reglement;
460 $this->cond_reglement_code = $obj->cond_reglement_code;
461 $this->cond_reglement = $obj->cond_reglement_label;
462 $this->cond_reglement_label = $obj->cond_reglement_label;
463 $this->cond_reglement_doc = $obj->cond_reglement_doc;
464 $this->fk_account = $obj->fk_account;
465 $this->mode_reglement_id = $obj->fk_mode_reglement;
466 $this->mode_reglement_code = $obj->mode_reglement_code;
467 $this->mode_reglement = $obj->mode_reglement_libelle;
468 $this->note = $obj->note_private;
469 $this->note_private = $obj->note_private;
470 $this->note_public = $obj->note_public;
471 $this->model_pdf = $obj->model_pdf;
474 $this->fk_incoterms = $obj->fk_incoterms;
475 $this->location_incoterms = $obj->location_incoterms;
476 $this->label_incoterms = $obj->label_incoterms;
479 $this->fk_multicurrency = $obj->fk_multicurrency;
480 $this->multicurrency_code = $obj->multicurrency_code;
481 $this->multicurrency_tx = $obj->multicurrency_tx;
482 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
483 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
484 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
486 $this->extraparams = isset($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
488 $this->db->free($resql);
503 $this->error = $this->db->error().
" sql=".$sql;
520 $this->lines = array();
522 $sql =
"SELECT l.rowid, l.fk_commande, l.ref as ref_supplier, l.fk_product, l.product_type, l.label, l.description, l.qty,";
523 $sql .=
" l.vat_src_code, l.tva_tx, l.remise_percent, l.subprice,";
524 $sql .=
" l.localtax1_tx, l. localtax2_tx, l.localtax1_type, l. localtax2_type, l.total_localtax1, l.total_localtax2,";
525 $sql .=
" l.total_ht, l.total_tva, l.total_ttc, l.info_bits, l.special_code, l.fk_parent_line, l.rang,";
526 $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,";
527 $sql .=
" l.fk_unit,";
528 $sql .=
" l.date_start, l.date_end,";
529 $sql .=
' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc';
530 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseurdet as l";
531 $sql .=
' LEFT JOIN '.$this->db->prefix().
'product as p ON l.fk_product = p.rowid';
532 $sql .=
" WHERE l.fk_commande = ".((int) $this->
id);
534 $sql .=
' AND p.fk_product_type = 0';
536 $sql .=
" ORDER BY l.rang, l.rowid";
539 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
541 $result = $this->db->query($sql);
543 $num = $this->db->num_rows($result);
547 $objp = $this->db->fetch_object($result);
551 $line->id = $objp->rowid;
552 $line->fk_commande = $objp->fk_commande;
553 $line->desc = $objp->description;
554 $line->description = $objp->description;
555 $line->qty = $objp->qty;
556 $line->tva_tx = $objp->tva_tx;
557 $line->localtax1_tx = $objp->localtax1_tx;
558 $line->localtax2_tx = $objp->localtax2_tx;
559 $line->localtax1_type = $objp->localtax1_type;
560 $line->localtax2_type = $objp->localtax2_type;
561 $line->subprice = $objp->subprice;
562 $line->pu_ht = $objp->subprice;
563 $line->remise_percent = $objp->remise_percent;
565 $line->vat_src_code = $objp->vat_src_code;
566 $line->total_ht = $objp->total_ht;
567 $line->total_tva = $objp->total_tva;
568 $line->total_localtax1 = $objp->total_localtax1;
569 $line->total_localtax2 = $objp->total_localtax2;
570 $line->total_ttc = $objp->total_ttc;
571 $line->product_type = $objp->product_type;
573 $line->fk_product = $objp->fk_product;
575 $line->libelle = $objp->product_label;
576 $line->product_label = $objp->product_label;
577 $line->product_desc = $objp->product_desc;
578 $line->product_tobatch = $objp->product_tobatch;
579 $line->product_barcode = $objp->product_barcode;
581 $line->ref = $objp->product_ref;
582 $line->product_ref = $objp->product_ref;
583 $line->ref_fourn = $objp->ref_supplier;
584 $line->ref_supplier = $objp->ref_supplier;
591 $sqlsearchpackage =
'SELECT rowid, packaging FROM '.$this->db->prefix().
"product_fournisseur_price";
592 $sqlsearchpackage .=
' WHERE entity IN ('.getEntity(
'product_fournisseur_price').
")";
593 $sqlsearchpackage .=
" AND fk_product = ".((int) $objp->fk_product);
594 $sqlsearchpackage .=
" AND ref_fourn = '".$this->db->escape($objp->ref_supplier).
"'";
595 $sqlsearchpackage .=
" AND quantity <= ".((float) $objp->qty);
596 $sqlsearchpackage .=
" AND (packaging IS NULL OR packaging = 0 OR packaging <= ".((float) $objp->qty).
")";
597 $sqlsearchpackage .=
" AND fk_soc = ".((int) $this->socid);
598 $sqlsearchpackage .=
" ORDER BY packaging ASC";
599 $sqlsearchpackage .=
" LIMIT 1";
601 $resqlsearchpackage = $this->db->query($sqlsearchpackage);
602 if ($resqlsearchpackage) {
603 $objsearchpackage = $this->db->fetch_object($resqlsearchpackage);
604 if ($objsearchpackage) {
605 $line->fk_fournprice = $objsearchpackage->rowid;
606 $line->packaging = $objsearchpackage->packaging;
609 $this->error = $this->db->lasterror();
614 $line->date_start = $this->db->jdate($objp->date_start);
615 $line->date_end = $this->db->jdate($objp->date_end);
616 $line->fk_unit = $objp->fk_unit;
619 $line->fk_multicurrency = $objp->fk_multicurrency;
620 $line->multicurrency_code = $objp->multicurrency_code;
621 $line->multicurrency_subprice = $objp->multicurrency_subprice;
622 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
623 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
624 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
626 $line->info_bits = $objp->info_bits;
627 $line->special_code = $objp->special_code;
628 $line->fk_parent_line = $objp->fk_parent_line;
630 $line->rang = $objp->rang;
634 $line->fetch_optionals();
636 $this->lines[$i] = $line;
640 $this->db->free($result);
644 $this->error = $this->db->error().
" sql=".$sql;
657 public function valid($user, $idwarehouse = 0, $notrigger = 0)
659 global $langs, $conf;
660 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
666 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")))
667 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"fournisseur",
"supplier_order_advance",
"validate"))) {
672 $soc->fetch($this->fourn_id);
675 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
682 $sql =
'UPDATE '.$this->db->prefix().
"commande_fournisseur";
683 $sql .=
" SET ref='".$this->db->escape($num).
"',";
684 $sql .=
" fk_statut = ".((int) self::STATUS_VALIDATED).
",";
685 $sql .=
" date_valid='".$this->db->idate(
dol_now()).
"',";
686 $sql .=
" fk_user_valid = ".((int) $user->id);
687 $sql .=
" WHERE rowid = ".((int) $this->
id);
688 $sql .=
" AND fk_statut = ".((int) self::STATUS_DRAFT);
690 $resql = $this->db->query($sql);
696 if (!$error && !$notrigger) {
698 $result = $this->
call_trigger(
'ORDER_SUPPLIER_VALIDATE', $user);
706 $this->oldref = $this->ref;
709 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
711 $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).
"'";
712 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'fournisseur/commande/".$this->db->escape($this->
ref).
"' and entity = ".((int) $conf->entity);
713 $resql = $this->db->query($sql);
716 $this->error = $this->db->lasterror();
718 $sql =
'UPDATE '.$this->db->prefix().
"ecm_files set filepath = 'fournisseur/commande/".$this->db->escape($this->newref).
"'";
719 $sql .=
" WHERE filepath = 'fournisseur/commande/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
720 $resql = $this->db->query($sql);
723 $this->error = $this->db->lasterror();
729 $dirsource = $conf->fournisseur->commande->dir_output.
'/'.$oldref;
730 $dirdest = $conf->fournisseur->commande->dir_output.
'/'.$newref;
731 if (!$error && file_exists($dirsource)) {
732 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
734 if (@rename($dirsource, $dirdest)) {
737 $listoffiles =
dol_dir_list($conf->fournisseur->commande->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
738 foreach ($listoffiles as $fileentry) {
739 $dirsource = $fileentry[
'name'];
740 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
741 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
742 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
743 @rename($dirsource, $dirdest);
761 $this->db->rollback();
765 $this->error =
'NotAuthorized';
766 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
791 public function LibStatut($status, $mode = 0, $billed = 0)
794 global $conf, $langs, $hookmanager;
796 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
797 $langs->load(
'orders');
799 $this->labelStatus[0] =
'StatusSupplierOrderDraft';
800 $this->labelStatus[1] =
'StatusSupplierOrderValidated';
801 $this->labelStatus[2] =
'StatusSupplierOrderApproved';
803 $this->labelStatus[3] =
'StatusSupplierOrderOnProcess';
805 $this->labelStatus[3] =
'StatusSupplierOrderOnProcessWithValidation';
807 $this->labelStatus[4] =
'StatusSupplierOrderReceivedPartially';
808 $this->labelStatus[5] =
'StatusSupplierOrderReceivedAll';
809 $this->labelStatus[6] =
'StatusSupplierOrderCanceled';
810 $this->labelStatus[7] =
'StatusSupplierOrderCanceled';
811 $this->labelStatus[9] =
'StatusSupplierOrderRefused';
814 $this->labelStatusShort[0] =
'StatusSupplierOrderDraftShort';
815 $this->labelStatusShort[1] =
'StatusSupplierOrderValidatedShort';
816 $this->labelStatusShort[2] =
'StatusSupplierOrderApprovedShort';
817 $this->labelStatusShort[3] =
'StatusSupplierOrderOnProcessShort';
818 $this->labelStatusShort[4] =
'StatusSupplierOrderReceivedPartiallyShort';
819 $this->labelStatusShort[5] =
'StatusSupplierOrderReceivedAllShort';
820 $this->labelStatusShort[6] =
'StatusSupplierOrderCanceledShort';
821 $this->labelStatusShort[7] =
'StatusSupplierOrderCanceledShort';
822 $this->labelStatusShort[9] =
'StatusSupplierOrderRefusedShort';
825 $statustrans = array(
837 $statusClass =
'status0';
838 if (!empty($statustrans[$status])) {
839 $statusClass = $statustrans[$status];
844 $billedtext =
' - '.$langs->trans(
"Billed");
846 if ($status == 5 && $billed) {
847 $statusClass =
'status6';
850 $statusLong = $langs->transnoentitiesnoconv($this->labelStatus[$status]).$billedtext;
851 $statusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
853 $parameters = array(
'status' => $status,
'mode' => $mode,
'billed' => $billed);
854 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
856 return $hookmanager->resPrint;
859 return dolGetStatus($statusLong, $statusShort,
'', $statusClass, $mode);
871 global $conf, $langs, $user;
873 $langs->loadLangs([
'bills',
'orders']);
876 $nofetch = !empty($params[
'nofetch']);
878 if ($user->hasRight(
"fournisseur",
"commande",
"read")) {
879 $datas[
'picto'] =
'<u class="paddingrightonly">'.$langs->trans(
"SupplierOrder").
'</u>';
880 if (isset($this->
statut)) {
881 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
883 if (!empty($this->
ref)) {
884 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
886 if (!empty($this->ref_supplier)) {
887 $datas[
'refsupplier'] =
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.$this->ref_supplier;
890 $langs->load(
'companies');
891 if (empty($this->thirdparty)) {
894 $datas[
'supplier'] =
'<br><b>'.$langs->trans(
'Supplier').
':</b> '.$this->thirdparty->getNomUrl(1,
'', 0, 1);
896 if (!empty($this->total_ht)) {
897 $datas[
'totalht'] =
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
899 if (!empty($this->total_tva)) {
900 $datas[
'totaltva'] =
'<br><b>'.$langs->trans(
'VAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
902 if (!empty($this->total_ttc)) {
903 $datas[
'totalttc'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
905 if (!empty($this->date)) {
906 $datas[
'date'] =
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->date,
'day');
908 if (!empty($this->delivery_date)) {
909 $datas[
'deliverydate'] =
'<br><b>'.$langs->trans(
'DeliveryDate').
':</b> '.
dol_print_date($this->delivery_date,
'dayhour');
925 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = 0)
927 global $langs, $conf, $user, $hookmanager;
932 'objecttype' => $this->element,
936 $classfortooltip =
'classfortooltip';
939 $classfortooltip =
'classforajaxtooltip';
940 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
946 $url = DOL_URL_ROOT.
'/fourn/commande/card.php?id='.$this->id;
948 if ($option !==
'nolink') {
950 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
951 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
952 $add_save_lastsearch_values = 1;
954 if ($add_save_lastsearch_values) {
955 $url .=
'&save_lastsearch_values=1';
960 if (empty($notooltip)) {
962 $label = $langs->trans(
"ShowOrder");
963 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
965 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
966 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
969 $linkstart =
'<a href="'.$url.
'"';
970 $linkstart .= $linkclose.
'>';
973 $result .= $linkstart;
975 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
977 if ($withpicto != 2) {
978 $result .= $this->ref;
982 if ($addlinktonotes) {
983 $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
986 $result .=
' <span class="note inline-block">';
987 $result .=
'<a href="'.DOL_URL_ROOT.
'/fourn/commande/note.php?id='.$this->
id.
'" class="classfortooltip" title="'.
dol_escape_htmltag($notetoshow).
'">';
992 $result .=
'</span>';
997 $hookmanager->initHooks(array($this->element .
'dao'));
998 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
999 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1001 $result = $hookmanager->resPrint;
1003 $result .= $hookmanager->resPrint;
1018 global $db, $langs, $conf;
1019 $langs->load(
"orders");
1028 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
1030 foreach ($dirmodels as $reldir) {
1031 $dir =
dol_buildpath($reldir.
"core/modules/supplier_order/");
1034 $mybool |= @include_once $dir.$file;
1037 if ($mybool ===
false) {
1042 $obj =
new $classname();
1043 $numref = $obj->getNextValue($soc, $this);
1045 if ($numref !=
"") {
1048 $this->error = $obj->error;
1052 $this->error =
"Error_COMMANDE_SUPPLIER_ADDON_NotDefined";
1066 if ($this->billed) {
1072 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur SET billed = 1';
1075 if ($this->db->query($sql)) {
1078 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CLASSIFY_BILLED', $user);
1088 $this->db->commit();
1091 $this->db->rollback();
1097 $this->db->rollback();
1110 public function approve($user, $idwarehouse = 0, $secondlevel = 0)
1112 global $langs, $conf;
1113 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1119 if ($user->hasRight(
"fournisseur",
"commande",
"approuver")) {
1125 $soc =
new Societe($this->db);
1126 $soc->fetch($this->fourn_id);
1129 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
1137 $movetoapprovestatus =
true;
1140 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1141 $sql .=
" SET ref='".$this->db->escape($num).
"',";
1142 if (empty($secondlevel)) {
1143 $sql .=
" date_approve='".$this->db->idate($now).
"',";
1144 $sql .=
" fk_user_approve = ".$user->id;
1145 if (
getDolGlobalString(
'SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED') && $this->total_ht >= $conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) {
1146 if (empty($this->user_approve_id2)) {
1147 $movetoapprovestatus =
false;
1148 $comment =
' (first level)';
1152 $sql .=
" date_approve2='".$this->db->idate($now).
"',";
1153 $sql .=
" fk_user_approve2 = ".((int) $user->id);
1154 if (empty($this->user_approve_id)) {
1155 $movetoapprovestatus =
false;
1157 $comment =
' (second level)';
1160 if ($movetoapprovestatus) {
1161 $sql .=
", fk_statut = ".self::STATUS_ACCEPTED;
1163 $sql .=
", fk_statut = ".self::STATUS_VALIDATED;
1165 $sql .=
" WHERE rowid = ".((int) $this->
id);
1166 $sql .=
" AND fk_statut = ".self::STATUS_VALIDATED;
1168 if ($this->db->query($sql)) {
1170 $result = $this->
add_contact($user->id,
'SALESREPFOLL',
'internal', 1);
1171 if ($result < 0 && $result != -2) {
1177 if (!$error && $movetoapprovestatus && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER')) {
1178 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1179 $langs->load(
"agenda");
1181 $cpt = count($this->lines);
1182 for ($i = 0; $i < $cpt; $i++) {
1184 if ($this->lines[$i]->fk_product > 0) {
1185 $this->line = $this->lines[$i];
1187 $mouvP->origin = &$this;
1188 $mouvP->setOrigin($this->element, $this->
id);
1190 $up_ht_disc = $this->lines[$i]->subprice;
1191 if (!empty($this->lines[$i]->remise_percent) && !
getDolGlobalString(
'STOCK_EXCLUDE_DISCOUNT_FOR_PMP')) {
1192 $up_ht_disc =
price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100,
'MU');
1194 $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans(
"OrderApprovedInDolibarr", $this->ref));
1205 $result = $this->
call_trigger(
'ORDER_SUPPLIER_APPROVE', $user);
1213 $this->
ref = $this->newref;
1215 if ($movetoapprovestatus) {
1220 if (empty($secondlevel)) {
1221 $this->date_approve = $now;
1222 $this->user_approve_id = $user->id;
1224 $this->date_approve2 = $now;
1225 $this->user_approve_id2 = $user->id;
1228 $this->db->commit();
1231 $this->db->rollback();
1235 $this->db->rollback();
1236 $this->error = $this->db->lasterror();
1240 dol_syslog(get_class($this).
"::approve Not Authorized", LOG_ERR);
1253 global $conf, $langs;
1259 if ($user->hasRight(
"fournisseur",
"commande",
"approuver")) {
1262 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur SET fk_statut = ".
self::STATUS_REFUSED;
1263 $sql .=
" WHERE rowid = ".((int) $this->
id);
1265 if ($this->db->query($sql)) {
1270 $result = $this->
call_trigger(
'ORDER_SUPPLIER_REFUSE', $user);
1273 $this->db->rollback();
1275 $this->db->commit();
1280 $this->db->rollback();
1281 $this->error = $this->db->lasterror();
1282 dol_syslog(get_class($this).
"::refuse Error -1");
1286 dol_syslog(get_class($this).
"::refuse Not Authorized");
1300 public function Cancel($user, $idwarehouse = -1)
1303 global $langs, $conf;
1309 if ($user->hasRight(
"fournisseur",
"commande",
"commander")) {
1314 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur SET fk_statut = ".((int) $statut);
1315 $sql .=
" WHERE rowid = ".((int) $this->
id);
1316 dol_syslog(get_class($this).
"::cancel", LOG_DEBUG);
1317 if ($this->db->query($sql)) {
1321 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CANCEL', $user);
1328 $this->db->commit();
1331 $this->db->rollback();
1335 $this->db->rollback();
1336 $this->error = $this->db->lasterror();
1337 dol_syslog(get_class($this).
"::cancel ".$this->error);
1341 dol_syslog(get_class($this).
"::cancel Not Authorized");
1355 public function commande($user, $date, $methode, $comment =
'')
1360 if ($user->hasRight(
"fournisseur",
"commande",
"commander")) {
1363 $newnoteprivate = $this->note_private;
1365 $newnoteprivate =
dol_concatdesc($newnoteprivate, $langs->trans(
"Comment").
': '.$comment);
1368 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1369 $sql .=
" SET fk_statut=".self::STATUS_ORDERSENT.
", fk_input_method=".$methode.
", date_commande='".$this->db->idate($date).
"', ";
1370 $sql .=
" note_private='".$this->db->escape($newnoteprivate).
"'";
1371 $sql .=
" WHERE rowid=".((int) $this->
id);
1373 dol_syslog(get_class($this).
"::commande", LOG_DEBUG);
1374 if ($this->db->query($sql)) {
1376 $this->methode_commande_id = $methode;
1377 $this->date_commande = $date;
1378 $this->context = array(
'comments' => $comment);
1381 $result = $this->
call_trigger(
'ORDER_SUPPLIER_SUBMIT', $user);
1388 $this->error = $this->db->lasterror();
1389 $this->errors[] = $this->db->lasterror();
1393 $this->db->commit();
1395 $this->db->rollback();
1399 $this->error = $langs->trans(
'NotAuthorized');
1400 $this->errors[] = $langs->trans(
'NotAuthorized');
1401 dol_syslog(get_class($this).
"::commande User not Authorized", LOG_WARNING);
1404 return ($error ? -1 : 1);
1414 public function create($user, $notrigger = 0)
1416 global $langs, $conf, $hookmanager;
1424 $date = ($this->date_commande ? $this->date_commande : $this->date);
1428 $delivery_date = $this->delivery_date;
1431 if (empty($this->source)) {
1436 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
1441 if (empty($this->fk_multicurrency)) {
1442 $this->multicurrency_code = $conf->currency;
1443 $this->fk_multicurrency = 0;
1444 $this->multicurrency_tx = 1;
1451 $sql =
"INSERT INTO ".$this->db->prefix().
"commande_fournisseur (";
1453 $sql .=
", ref_supplier";
1454 $sql .=
", note_private";
1455 $sql .=
", note_public";
1458 $sql .=
", fk_projet";
1459 $sql .=
", date_creation";
1460 $sql .=
", date_livraison";
1461 $sql .=
", fk_user_author";
1462 $sql .=
", fk_statut";
1464 $sql .=
", model_pdf";
1465 $sql .=
", fk_mode_reglement";
1466 $sql .=
", fk_cond_reglement";
1467 $sql .=
", fk_account";
1468 $sql .=
", fk_incoterms, location_incoterms";
1469 $sql .=
", fk_multicurrency";
1470 $sql .=
", multicurrency_code";
1471 $sql .=
", multicurrency_tx";
1473 $sql .=
" VALUES (";
1475 $sql .=
", ".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"NULL");
1476 $sql .=
", '".$this->db->escape($this->note_private).
"'";
1477 $sql .=
", '".$this->db->escape($this->note_public).
"'";
1478 $sql .=
", ".setEntity($this);
1479 $sql .=
", ".((int) $this->socid);
1480 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
1481 $sql .=
", '".$this->db->idate($date).
"'";
1482 $sql .=
", ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
"null");
1483 $sql .=
", ".((int) $user->id);
1484 $sql .=
", ".self::STATUS_DRAFT;
1485 $sql .=
", ".((int) $this->source);
1486 $sql .=
", '".$this->db->escape(
getDolGlobalString(
'COMMANDE_SUPPLIER_ADDON_PDF')).
"'";
1487 $sql .=
", ".($this->mode_reglement_id > 0 ? $this->mode_reglement_id :
'null');
1488 $sql .=
", ".($this->cond_reglement_id > 0 ? $this->cond_reglement_id :
'null');
1489 $sql .=
", ".($this->fk_account > 0 ? $this->fk_account :
'NULL');
1490 $sql .=
", ".(int) $this->fk_incoterms;
1491 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
1492 $sql .=
", ".(int) $this->fk_multicurrency;
1493 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1494 $sql .=
", ".(float) $this->multicurrency_tx;
1497 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1498 if ($this->db->query($sql)) {
1499 $this->
id = $this->db->last_insert_id($this->db->prefix().
"commande_fournisseur");
1502 $num = count($this->lines);
1505 for ($i = 0; $i < $num; $i++) {
1506 $line = $this->lines[$i];
1507 if (!is_object($line)) {
1508 $line = (object) $line;
1519 $line->localtax1_tx,
1520 $line->localtax2_tx,
1524 $line->remise_percent,
1527 $line->product_type,
1532 $line->array_options,
1534 $line->multicurrency_subprice,
1541 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
1542 $this->db->rollback();
1547 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1548 $sql .=
" SET ref='(PROV".$this->id.
")'";
1549 $sql .=
" WHERE rowid=".((int) $this->
id);
1551 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1552 if ($this->db->query($sql)) {
1555 $this->
ref =
"(PROV".$this->id.
")";
1557 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
1558 $this->linked_objects = $this->linkedObjectsIds;
1562 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
1563 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
1564 if (is_array($tmp_origin_id)) {
1565 foreach ($tmp_origin_id as $origin_id) {
1573 $origin_id = $tmp_origin_id;
1591 if (!$error && !$notrigger) {
1593 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CREATE', $user);
1595 $this->db->rollback();
1603 $this->db->commit();
1606 $this->db->rollback();
1610 $this->error = $this->db->lasterror();
1611 $this->db->rollback();
1616 $this->error =
'Failed to get ID of inserted line';
1621 $this->error = $this->db->lasterror();
1622 $this->db->rollback();
1642 if (isset($this->
ref)) {
1643 $this->
ref = trim($this->
ref);
1645 if (isset($this->ref_supplier)) {
1646 $this->ref_supplier = trim($this->ref_supplier);
1648 if (isset($this->note_private)) {
1649 $this->note_private = trim($this->note_private);
1651 if (isset($this->note_public)) {
1652 $this->note_public = trim($this->note_public);
1654 if (isset($this->model_pdf)) {
1655 $this->model_pdf = trim($this->model_pdf);
1657 if (isset($this->import_key)) {
1658 $this->import_key = trim($this->import_key);
1662 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
1664 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1665 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
1666 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1667 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
1668 $sql .=
" date_commande=".(strval($this->date_commande) !=
'' ?
"'".$this->db->idate($this->date_commande).
"'" :
'null').
",";
1669 $sql .=
" date_valid=".(strval($this->date_validation) !=
'' ?
"'".$this->db->idate($this->date_validation).
"'" :
'null').
",";
1670 $sql .=
" total_tva=".(isset($this->total_tva) ? $this->total_tva :
"null").
",";
1671 $sql .=
" localtax1=".(isset($this->total_localtax1) ? $this->total_localtax1 :
"null").
",";
1672 $sql .=
" localtax2=".(isset($this->total_localtax2) ? $this->total_localtax2 :
"null").
",";
1673 $sql .=
" total_ht=".(isset($this->total_ht) ? $this->total_ht :
"null").
",";
1674 $sql .=
" total_ttc=".(isset($this->total_ttc) ? $this->total_ttc :
"null").
",";
1675 $sql .=
" fk_statut=".(isset($this->
statut) ? $this->
statut :
"null").
",";
1676 $sql .=
" fk_user_author=".(isset($this->user_author_id) ? $this->user_author_id :
"null").
",";
1677 $sql .=
" fk_user_valid=".(isset($this->user_validation_id) && $this->user_validation_id > 0 ? $this->user_validation_id :
"null").
",";
1678 $sql .=
" fk_projet=".(isset($this->fk_project) ? $this->fk_project :
"null").
",";
1679 $sql .=
" fk_cond_reglement=".(isset($this->cond_reglement_id) ? $this->cond_reglement_id :
"null").
",";
1680 $sql .=
" fk_mode_reglement=".(isset($this->mode_reglement_id) ? $this->mode_reglement_id :
"null").
",";
1681 $sql .=
" date_livraison=".(strval($this->delivery_date) !=
'' ?
"'".$this->db->idate($this->delivery_date).
"'" :
'null').
",";
1683 $sql .=
" fk_account=".($this->fk_account > 0 ? $this->fk_account :
"null").
",";
1685 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1686 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1687 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1688 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
1690 $sql .=
" WHERE rowid=".((int) $this->
id);
1694 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1695 $resql = $this->db->query($sql);
1698 $this->errors[] =
"Error ".$this->db->lasterror();
1708 if (!$error && !$notrigger) {
1710 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
1719 foreach ($this->errors as $errmsg) {
1720 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1721 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1723 $this->db->rollback();
1726 $this->db->commit();
1741 global $conf, $user, $hookmanager;
1748 foreach ($this->lines as $line) {
1749 $line->fetch_optionals();
1753 $objFrom = clone $this;
1756 if (!empty($socid) && $socid != $this->socid) {
1757 $objsoc =
new Societe($this->db);
1759 if ($objsoc->fetch($socid) > 0) {
1760 $this->socid = $objsoc->id;
1761 $this->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1762 $this->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1763 $this->fk_project = 0;
1764 $this->fk_delivery_address = 0;
1774 $this->user_author_id = $user->id;
1775 $this->user_validation_id = 0;
1777 $this->date_creation =
'';
1778 $this->date_commande =
'';
1779 $this->date_validation =
'';
1780 $this->ref_supplier =
null;
1781 $this->user_approve_id =
'';
1782 $this->user_approve_id2 =
'';
1783 $this->date_approve =
'';
1784 $this->date_approve2 =
'';
1787 $this->context[
'createfromclone'] =
'createfromclone';
1788 $result = $this->
create($user, $notrigger);
1795 if (is_object($hookmanager)) {
1796 $parameters = array(
'objFrom'=>$objFrom);
1798 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1806 unset($this->context[
'createfromclone']);
1810 $this->db->commit();
1813 $this->db->rollback();
1847 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 =
false, $date_start =
null, $date_end =
null, $array_options = 0, $fk_unit =
null, $pu_ht_devise = 0, $origin =
'', $origin_id = 0, $rang = -1, $special_code = 0)
1849 global $langs, $mysoc, $conf;
1851 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");
1852 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1854 if ($this->
statut == self::STATUS_DRAFT) {
1855 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1864 if (empty($txtva)) {
1870 if (empty($txlocaltax1)) {
1873 if (empty($txlocaltax2)) {
1876 if (empty($remise_percent)) {
1877 $remise_percent = 0;
1880 $remise_percent =
price2num($remise_percent);
1883 $pu_ht_devise =
price2num($pu_ht_devise);
1885 if (!preg_match(
'/\((.*)\)/', $txtva)) {
1890 if ($price_base_type ==
'HT') {
1895 $desc = trim($desc);
1898 if ($qty < 0 && !$fk_product) {
1899 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Product"));
1905 if ($date_start && $date_end && $date_start > $date_end) {
1906 $langs->load(
"errors");
1907 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
1914 $product_type = $type;
1917 if ($fk_product > 0) {
1920 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);
1922 if ($prod->fetch($fk_product) > 0) {
1923 $product_type = $prod->type;
1924 $label = $prod->label;
1928 $result = $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', (isset($this->fk_soc) ? $this->fk_soc : $this->socid));
1932 if ($result > 0 && ($origin ==
'commande' || $pu ===
'')) {
1933 $pu = $prod->fourn_pu;
1934 $ref_supplier = $prod->ref_supplier;
1936 if ($remise_percent == 0 && $prod->remise_percent != 0) {
1937 $remise_percent = $prod->remise_percent;
1941 $langs->load(
"errors");
1942 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
1943 $this->db->rollback();
1944 dol_syslog(get_class($this).
"::addline we did not found supplier price, so we can't guess unit price");
1949 if ($result == -1) {
1950 $langs->load(
"errors");
1951 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
1952 $this->db->rollback();
1953 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_DEBUG);
1957 $this->error = $prod->error;
1958 $this->db->rollback();
1959 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_ERR);
1963 $this->error = $prod->error;
1964 $this->db->rollback();
1971 $prod =
new Product($this->db);
1972 $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', (empty($this->fk_soc) ? $this->socid : $this->fk_soc));
1974 if ($qty < $prod->packaging) {
1975 $qty = $prod->packaging;
1977 if (!empty($prod->packaging) && ($qty % $prod->packaging) > 0) {
1978 $coeff = intval($qty / $prod->packaging) + 1;
1979 $qty = $prod->packaging * $coeff;
1980 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'mesgs');
1986 if (isModEnabled(
"multicurrency") && $pu_ht_devise > 0) {
1995 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
1996 $vat_src_code = $reg[1];
1997 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
2005 $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);
2007 $total_ht = $tabprice[0];
2008 $total_tva = $tabprice[1];
2009 $total_ttc = $tabprice[2];
2010 $total_localtax1 = $tabprice[9];
2011 $total_localtax2 = $tabprice[10];
2012 $pu = $pu_ht = $tabprice[3];
2015 $multicurrency_total_ht = $tabprice[16];
2016 $multicurrency_total_tva = $tabprice[17];
2017 $multicurrency_total_ttc = $tabprice[18];
2018 $pu_ht_devise = $tabprice[19];
2020 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2021 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2025 $rang = $rangmax + 1;
2031 $this->line->context = $this->context;
2033 $this->line->fk_commande = $this->id;
2034 $this->line->label = $label;
2035 $this->line->ref_fourn = $ref_supplier;
2036 $this->line->ref_supplier = $ref_supplier;
2037 $this->line->desc = $desc;
2038 $this->line->qty = $qty;
2039 $this->line->tva_tx = $txtva;
2040 $this->line->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0);
2041 $this->line->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0);
2042 $this->line->localtax1_type = $localtax1_type;
2043 $this->line->localtax2_type = $localtax2_type;
2044 $this->line->fk_product = $fk_product;
2045 $this->line->product_type = $product_type;
2046 $this->line->remise_percent = $remise_percent;
2047 $this->line->subprice = $pu_ht;
2048 $this->line->rang = $rang;
2049 $this->line->info_bits = $info_bits;
2051 $this->line->vat_src_code = $vat_src_code;
2052 $this->line->total_ht = $total_ht;
2053 $this->line->total_tva = $total_tva;
2054 $this->line->total_localtax1 = $total_localtax1;
2055 $this->line->total_localtax2 = $total_localtax2;
2056 $this->line->total_ttc = $total_ttc;
2057 $this->line->product_type = $type;
2058 $this->line->special_code = (!empty($special_code) ? $special_code : 0);
2059 $this->line->origin = $origin;
2060 $this->line->origin_id = $origin_id;
2061 $this->line->fk_unit = $fk_unit;
2063 $this->line->date_start = $date_start;
2064 $this->line->date_end = $date_end;
2067 $this->line->fk_multicurrency = $this->fk_multicurrency;
2068 $this->line->multicurrency_code = $this->multicurrency_code;
2069 $this->line->multicurrency_subprice = $pu_ht_devise;
2070 $this->line->multicurrency_total_ht = $multicurrency_total_ht;
2071 $this->line->multicurrency_total_tva = $multicurrency_total_tva;
2072 $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
2074 $this->line->subprice = $pu_ht;
2075 $this->line->price = $this->line->subprice;
2077 $this->line->remise_percent = $remise_percent;
2079 if (is_array($array_options) && count($array_options) > 0) {
2080 $this->line->array_options = $array_options;
2083 $result = $this->line->insert($notrigger);
2086 if (!empty($this->line->fk_parent_line)) {
2088 } elseif ($rang > 0 && $rang <= count($this->lines)) {
2089 $linecount = count($this->lines);
2090 for ($ii = $rang; $ii <= $linecount; $ii++) {
2096 $result = $this->
update_price(1,
'auto', 0, $this->thirdparty);
2098 $this->db->commit();
2099 return $this->line->id;
2101 $this->db->rollback();
2105 $this->error = $this->line->error;
2106 $this->errors = $this->line->errors;
2107 dol_syslog(get_class($this).
"::addline error=".$this->error, LOG_ERR);
2108 $this->db->rollback();
2133 public function dispatchProduct($user, $product, $qty, $entrepot, $price = 0, $comment =
'', $eatby =
'', $sellby =
'', $batch =
'', $fk_commandefourndet = 0, $notrigger = 0, $fk_reception = 0)
2135 global $conf, $langs;
2138 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2141 if ($entrepot <= 0) {
2142 $this->error =
'ErrorBadValueForParameterWarehouse';
2146 $this->error =
'ErrorBadValueForParameterQty';
2150 $dispatchstatus = 1;
2152 $dispatchstatus = 0;
2159 if (($this->
statut == self::STATUS_ORDERSENT || $this->
statut == self::STATUS_RECEIVED_PARTIALLY || $this->
statut == self::STATUS_RECEIVED_COMPLETELY)) {
2162 $sql =
"INSERT INTO ".$this->db->prefix().
"commande_fournisseur_dispatch";
2163 $sql .=
" (fk_commande, fk_product, qty, fk_entrepot, fk_user, datec, fk_commandefourndet, status, comment, eatby, sellby, batch, fk_reception) VALUES";
2164 $sql .=
" ('".$this->id.
"','".$product.
"','".$qty.
"',".($entrepot > 0 ?
"'".$entrepot.
"'" :
"null").
",'".$user->id.
"','".$this->db->idate($now).
"','".$fk_commandefourndet.
"', ".$dispatchstatus.
", '".$this->db->escape($comment).
"', ";
2165 $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");
2168 dol_syslog(get_class($this).
"::dispatchProduct", LOG_DEBUG);
2169 $resql = $this->db->query($sql);
2172 global $conf, $langs, $user;
2174 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_DISPATCH', $user);
2181 $this->error = $this->db->lasterror();
2186 if (!$error && $entrepot > 0 && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER')) {
2190 $mouv->origin = &$this;
2191 $mouv->setOrigin($this->element, $this->
id);
2194 if (
getDolGlobalString(
'SUPPLIER_ORDER_ALLOW_NEGATIVE_QTY_FOR_SUPPLIER_ORDER_RETURN') && $qty < 0) {
2195 $result = $mouv->livraison($user, $product, $entrepot, $qty*(-1), $price, $comment, $now, $eatby, $sellby, $batch, 0, $inventorycode);
2197 $result = $mouv->reception($user, $product, $entrepot, $qty, $price, $comment, $eatby, $sellby, $batch,
'', 0, $inventorycode);
2201 $this->error = $mouv->error;
2202 $this->errors = $mouv->errors;
2203 dol_syslog(get_class($this).
"::dispatchProduct ".$this->error.
" ".join(
',', $this->errors), LOG_ERR);
2210 $this->db->commit();
2213 $this->db->rollback();
2217 $this->error =
'BadStatusForObject';
2231 if ($this->
statut == 0) {
2234 if ($line->fetch($idline) <= 0) {
2240 foreach ($dispatchedLines as $dispatchLine) {
2241 if ($dispatchLine[
'orderlineid'] == $idline) {
2242 $this->error =
"LineAlreadyDispatched";
2243 $this->errors[] = $this->error;
2248 if ($line->delete($notrigger) > 0) {
2252 $this->error = $line->error;
2253 $this->errors = $line->errors;
2268 public function delete(
User $user, $notrigger = 0)
2270 global $langs, $conf;
2271 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2277 if (empty($notrigger)) {
2279 $result = $this->
call_trigger(
'ORDER_SUPPLIER_DELETE', $user);
2281 $this->errors[] =
'ErrorWhenRunningTrigger';
2282 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2283 $this->db->rollback();
2291 if (!empty($this->linkedObjects) && array_key_exists(
'reception', $this->linkedObjects)) {
2292 foreach ($this->linkedObjects[
'reception'] as $element) {
2293 if ($element->statut >= 0) {
2294 $this->errors[] = $langs->trans(
'ReceptionExist');
2301 $main = $this->db->prefix().
'commande_fournisseurdet';
2304 $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).
")";
2305 dol_syslog(__METHOD__.
" linked order lines", LOG_DEBUG);
2306 if (!$this->db->query($sql1)) {
2308 $this->error = $this->db->lasterror();
2309 $this->errors[] = $this->db->lasterror();
2314 $ef = $main.
"_extrafields";
2315 $sql =
"DELETE FROM ".$this->db->sanitize($ef).
" WHERE fk_object IN (SELECT rowid FROM ".$this->db->sanitize($main).
" WHERE fk_commande = ".((int) $this->
id).
")";
2316 dol_syslog(get_class($this).
"::delete extrafields lines", LOG_DEBUG);
2317 if (!$this->db->query($sql)) {
2318 $this->error = $this->db->lasterror();
2319 $this->errors[] = $this->db->lasterror();
2325 $sql =
"DELETE FROM ".$this->db->prefix().
"commande_fournisseurdet WHERE fk_commande = ".((int) $this->
id);
2326 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2327 if (!$this->db->query($sql)) {
2328 $this->error = $this->db->lasterror();
2329 $this->errors[] = $this->db->lasterror();
2335 $sql =
"DELETE FROM ".$this->db->prefix().
"commande_fournisseur WHERE rowid = ".((int) $this->
id);
2336 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2337 if ($resql = $this->db->query($sql)) {
2338 if ($this->db->affected_rows($resql) < 1) {
2339 $this->error = $this->db->lasterror();
2340 $this->errors[] = $this->db->lasterror();
2344 $this->error = $this->db->lasterror();
2345 $this->errors[] = $this->db->lasterror();
2354 $this->error =
'FailToDeleteExtraFields';
2355 $this->errors[] =
'FailToDeleteExtraFields';
2357 dol_syslog(get_class($this).
"::delete error -4 ".$this->error, LOG_ERR);
2364 $this->error =
'FailToDeleteObjectLinked';
2365 $this->errors[] =
'FailToDeleteObjectLinked';
2376 if ($conf->fournisseur->commande->dir_output) {
2377 $dir = $conf->fournisseur->commande->dir_output.
"/".$ref;
2378 $file = $dir.
"/".$ref.
".pdf";
2379 if (file_exists($file)) {
2381 $this->error =
'ErrorFailToDeleteFile';
2382 $this->errors[] =
'ErrorFailToDeleteFile';
2386 if (file_exists($dir)) {
2389 $this->error =
'ErrorFailToDeleteDir';
2390 $this->errors[] =
'ErrorFailToDeleteDir';
2398 dol_syslog(get_class($this).
"::delete $this->id by $user->id", LOG_DEBUG);
2399 $this->db->commit();
2402 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2403 $this->db->rollback();
2422 $sql =
"SELECT p.ref, p.label,";
2423 $sql .=
" e.rowid as warehouse_id, e.ref as entrepot,";
2424 $sql .=
" cfd.rowid as dispatchedlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status, cfd.fk_commandefourndet";
2425 $sql .=
" FROM ".$this->db->prefix().
"product as p,";
2426 $sql .=
" ".$this->db->prefix().
"commande_fournisseur_dispatch as cfd";
2427 $sql .=
" LEFT JOIN ".$this->db->prefix().
"entrepot as e ON cfd.fk_entrepot = e.rowid";
2428 $sql .=
" WHERE cfd.fk_commande = ".((int) $this->
id);
2429 $sql .=
" AND cfd.fk_product = p.rowid";
2431 $sql .=
" AND cfd.status = ".((int) $status);
2433 $sql .=
" ORDER BY cfd.rowid ASC";
2435 $resql = $this->db->query($sql);
2437 $num = $this->db->num_rows($resql);
2441 $objp = $this->db->fetch_object($resql);
2444 'id' => $objp->dispatchedlineid,
2445 'productid' => $objp->fk_product,
2446 'warehouseid' => $objp->warehouse_id,
2447 'qty' => $objp->qty,
2448 'orderlineid' => $objp->fk_commandefourndet
2455 dol_print_error($this->db,
'Failed to execute request to get dispatched lines');
2474 global $conf, $langs;
2481 $usercanreceive = 0;
2482 if (!isModEnabled(
'reception')) {
2483 $usercanreceive = $user->hasRight(
"fournisseur",
"commande",
"receptionner");
2485 $usercanreceive = $user->hasRight(
"reception",
"creer");
2488 if ($usercanreceive) {
2490 if ($type ==
'par') {
2492 } elseif ($type ==
'tot') {
2494 } elseif ($type ==
'nev') {
2496 } elseif ($type ==
'can') {
2500 dol_syslog(get_class($this).
"::Livraison Error -2", LOG_ERR);
2507 if (!$error && ($type ==
'tot')) {
2509 if (count($dispatchedlinearray) > 0) {
2512 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove';
2513 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove', LOG_DEBUG);
2516 if (!$error &&
getDolGlobalString(
'SUPPLIER_ORDER_USE_DISPATCH_STATUS_NEED_APPROVE') && ($type ==
'tot')) {
2518 if (count($dispatchedlinearray) > 0) {
2521 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied';
2522 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied', LOG_DEBUG);
2529 if (empty($error)) {
2532 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2533 $sql .=
" SET fk_statut = ".((int) $statut);
2534 $sql .=
" WHERE rowid = ".((int) $this->
id);
2535 $sql .=
" AND fk_statut IN (".self::STATUS_ORDERSENT.
",".self::STATUS_RECEIVED_PARTIALLY.
")";
2537 dol_syslog(get_class($this).
"::Livraison", LOG_DEBUG);
2538 $resql = $this->db->query($sql);
2541 $old_statut = $this->statut;
2543 $this->context[
'actionmsg2'] = $comment;
2546 $result_trigger = $this->
call_trigger(
'ORDER_SUPPLIER_RECEIVE', $user);
2547 if ($result_trigger < 0) {
2552 if (empty($error)) {
2553 $this->db->commit();
2555 $this->
statut = $old_statut;
2556 $this->db->rollback();
2557 $this->error = $this->db->lasterror();
2561 $this->db->rollback();
2562 $this->error = $this->db->lasterror();
2567 $this->error = $langs->trans(
'NotAuthorized');
2568 $this->errors[] = $langs->trans(
'NotAuthorized');
2569 dol_syslog(get_class($this).
"::Livraison Not Authorized");
2601 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
2606 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2607 $sql .=
" SET date_livraison = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2608 $sql .=
" WHERE rowid = ".((int) $this->
id);
2611 $resql = $this->db->query($sql);
2613 $this->errors[] = $this->db->error();
2618 $this->oldcopy = clone $this;
2619 $this->delivery_date = $delivery_date;
2622 if (!$notrigger && empty($error)) {
2624 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2632 $this->db->commit();
2635 foreach ($this->errors as $errmsg) {
2636 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2637 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2639 $this->db->rollback();
2659 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
2664 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2665 $sql .=
" SET fk_projet = ".($id_projet > 0 ? (int) $id_projet :
'null');
2666 $sql .=
" WHERE rowid = ".((int) $this->
id);
2669 $resql = $this->db->query($sql);
2671 $this->errors[] = $this->db->error();
2676 $this->oldcopy = clone $this;
2677 $this->fk_projet = $id_projet;
2678 $this->fk_project = $id_projet;
2681 if (!$notrigger && empty($error)) {
2683 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2691 $this->db->commit();
2694 foreach ($this->errors as $errmsg) {
2695 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2696 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2698 $this->db->rollback();
2716 $comclient =
new Commande($this->db);
2717 $comclient->fetch($comclientid);
2721 $this->lines = array();
2723 $num = count($comclient->lines);
2724 for ($i = 0; $i < $num; $i++) {
2725 $prod =
new Product($this->db);
2728 if ($prod->fetch($comclient->lines[$i]->fk_product) > 0) {
2729 $label = $prod->label;
2733 $sql =
"INSERT INTO ".$this->db->prefix().
"commande_fournisseurdet";
2734 $sql .=
" (fk_commande, label, description, fk_product, price, qty, tva_tx, localtax1_tx, localtax2_tx, remise_percent, subprice, remise, ref)";
2735 $sql .=
" VALUES (".((int) $idc).
", '".$this->db->escape($label).
"', '".$this->db->escape($comclient->lines[$i]->desc).
"'";
2736 $sql .=
",".$comclient->lines[$i]->fk_product.
", ".
price2num($comclient->lines[$i]->price,
'MU');
2737 $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);
2738 $sql .=
", '".price2num($comclient->lines[$i]->subprice,
'MT').
"','0', '".$this->db->escape($ref).
"');";
2739 if ($this->db->query($sql)) {
2756 global $conf, $langs;
2761 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur';
2762 $sql .=
" SET fk_statut = ".$status;
2763 $sql .=
" WHERE rowid = ".((int) $this->
id);
2765 dol_syslog(get_class($this).
"::setStatus", LOG_DEBUG);
2766 $resql = $this->db->query($sql);
2769 $triggerName = array();
2770 $triggerName[0] =
'DRAFT';
2771 $triggerName[1] =
'VALIDATED';
2772 $triggerName[2] =
'APPROVED';
2773 $triggerName[3] =
'ORDERED';
2774 $triggerName[4] =
'RECEIVED_PARTIALLY';
2775 $triggerName[5] =
'RECEIVED_COMPLETELY';
2776 $triggerName[6] =
'CANCELED';
2777 $triggerName[7] =
'CANCELED';
2778 $triggerName[9] =
'REFUSED';
2781 $result = $this->
call_trigger(
"ORDER_SUPPLIER_STATUS_".$triggerName[$status], $user);
2788 $this->error = $this->db->lasterror();
2789 dol_syslog(get_class($this).
"::setStatus ".$this->error);
2794 $this->db->commit();
2797 $this->db->rollback();
2825 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 =
'', $date_end =
'', $array_options = 0, $fk_unit =
null, $pu_ht_devise = 0, $ref_supplier =
'')
2827 global $mysoc, $conf, $langs;
2828 dol_syslog(get_class($this).
"::updateline $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $type, $fk_unit");
2829 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2833 if ($this->
statut == self::STATUS_DRAFT) {
2838 if (empty($info_bits)) {
2841 if (empty($txtva)) {
2844 if (empty($txlocaltax1)) {
2847 if (empty($txlocaltax2)) {
2850 if (empty($remise_percent)) {
2851 $remise_percent = 0;
2854 $remise_percent =
price2num($remise_percent);
2860 $pu_ht_devise =
price2num($pu_ht_devise);
2861 if (!preg_match(
'/\((.*)\)/', $txtva)) {
2871 if ($date_start && $date_end && $date_start > $date_end) {
2872 $langs->load(
"errors");
2873 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
2889 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
2890 $vat_src_code = $reg[1];
2891 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
2894 $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);
2895 $total_ht = $tabprice[0];
2896 $total_tva = $tabprice[1];
2897 $total_ttc = $tabprice[2];
2898 $total_localtax1 = $tabprice[9];
2899 $total_localtax2 = $tabprice[10];
2900 $pu_ht = $tabprice[3];
2901 $pu_tva = $tabprice[4];
2902 $pu_ttc = $tabprice[5];
2905 $multicurrency_total_ht = $tabprice[16];
2906 $multicurrency_total_tva = $tabprice[17];
2907 $multicurrency_total_ttc = $tabprice[18];
2908 $pu_ht_devise = $tabprice[19];
2910 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2911 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2915 $this->line->fetch($rowid);
2917 $oldline = clone $this->line;
2918 $this->line->oldline = $oldline;
2920 $this->line->context = $this->context;
2922 $this->line->fk_commande = $this->id;
2924 $this->line->desc = $desc;
2928 if ($qty < $this->line->packaging) {
2929 $qty = $this->line->packaging;
2931 if (!empty($this->line->packaging) && ($qty % $this->line->packaging) > 0) {
2932 $coeff = intval($qty / $this->line->packaging) + 1;
2933 $qty = $this->line->packaging * $coeff;
2934 setEventMessage($langs->trans(
'QtyRecalculatedWithPackaging'),
'mesgs');
2939 $this->line->qty = $qty;
2940 $this->line->ref_supplier = $ref_supplier;
2942 $this->line->vat_src_code = $vat_src_code;
2943 $this->line->tva_tx = $txtva;
2944 $this->line->localtax1_tx = $txlocaltax1;
2945 $this->line->localtax2_tx = $txlocaltax2;
2946 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2947 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2948 $this->line->remise_percent = $remise_percent;
2949 $this->line->subprice = $pu_ht;
2950 $this->line->info_bits = $info_bits;
2951 $this->line->total_ht = $total_ht;
2952 $this->line->total_tva = $total_tva;
2953 $this->line->total_localtax1 = $total_localtax1;
2954 $this->line->total_localtax2 = $total_localtax2;
2955 $this->line->total_ttc = $total_ttc;
2956 $this->line->product_type = $type;
2957 $this->line->special_code = $oldline->special_code;
2958 $this->line->rang = $oldline->rang;
2959 $this->line->origin = $this->origin;
2960 $this->line->fk_unit = $fk_unit;
2962 $this->line->date_start = $date_start;
2963 $this->line->date_end = $date_end;
2966 $this->line->fk_multicurrency = $this->fk_multicurrency;
2967 $this->line->multicurrency_code = $this->multicurrency_code;
2968 $this->line->multicurrency_subprice = $pu_ht_devise;
2969 $this->line->multicurrency_total_ht = $multicurrency_total_ht;
2970 $this->line->multicurrency_total_tva = $multicurrency_total_tva;
2971 $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
2973 $this->line->subprice = $pu_ht;
2974 $this->line->price = $this->line->subprice;
2976 $this->line->remise_percent = $remise_percent;
2978 if (is_array($array_options) && count($array_options) > 0) {
2980 foreach ($array_options as $key => $value) {
2981 $this->line->array_options[$key] = $array_options[$key];
2985 $result = $this->line->update($notrigger);
2991 $this->db->commit();
2994 $this->errors[] = $this->line->error;
2995 $this->errors = array_merge($this->errors, $this->line->errors);
2996 $this->error = $this->db->lasterror();
2997 $this->db->rollback();
3001 $this->error =
"Order status makes operation forbidden";
3002 dol_syslog(get_class($this).
"::updateline ".$this->error, LOG_ERR);
3017 global $user, $langs, $conf;
3019 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
3021 dol_syslog(get_class($this).
"::initAsSpecimen");
3028 $sql =
"SELECT rowid";
3029 $sql .=
" FROM ".$this->db->prefix().
"product";
3030 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
3031 $sql .= $this->db->order(
"rowid",
"ASC");
3032 $sql .= $this->db->plimit(1);
3033 $resql = $this->db->query($sql);
3034 if ($resql && $this->db->num_rows($resql)) {
3035 $obj = $this->db->fetch_object($resql);
3036 $prodid = $obj->rowid;
3041 $this->
ref =
'SPECIMEN';
3042 $this->specimen = 1;
3045 $this->date_commande = $now;
3046 $this->date_lim_reglement = $this->date + 3600 * 24 * 30;
3047 $this->cond_reglement_code =
'RECEP';
3048 $this->mode_reglement_code =
'CHQ';
3050 $this->note_public =
'This is a comment (public)';
3051 $this->note_private =
'This is a comment (private)';
3053 $this->multicurrency_tx = 1;
3054 $this->multicurrency_code = $conf->currency;
3061 while ($xnbp < $nbp) {
3063 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
3065 $line->subprice = 100;
3066 $line->tva_tx = 19.6;
3067 $line->localtax1_tx = 0;
3068 $line->localtax2_tx = 0;
3070 $line->total_ht = 50;
3071 $line->total_ttc = 59.8;
3072 $line->total_tva = 9.8;
3073 $line->remise_percent = 50;
3075 $line->total_ht = 100;
3076 $line->total_ttc = 119.6;
3077 $line->total_tva = 19.6;
3078 $line->remise_percent = 00;
3080 $line->fk_product = $prodid;
3082 $this->lines[$xnbp] = $line;
3084 $this->total_ht += $line->total_ht;
3085 $this->total_tva += $line->total_tva;
3086 $this->total_ttc += $line->total_ttc;
3100 $sql =
'SELECT c.rowid, date_creation as datec, tms as datem, date_valid as date_validation, date_approve as datea, date_approve2 as datea2,';
3101 $sql .=
' fk_user_author, fk_user_modif, fk_user_valid, fk_user_approve, fk_user_approve2';
3102 $sql .=
' FROM '.$this->db->prefix().
'commande_fournisseur as c';
3103 $sql .=
' WHERE c.rowid = '.((int) $id);
3105 $result = $this->db->query($sql);
3107 if ($this->db->num_rows($result)) {
3108 $obj = $this->db->fetch_object($result);
3110 $this->
id = $obj->rowid;
3112 $this->user_creation_id = $obj->fk_user_author;
3113 $this->user_validation_id = $obj->fk_user_valid;
3114 $this->user_modification_id = $obj->fk_user_modif;
3115 $this->user_approve_id = $obj->fk_user_approve;
3116 $this->user_approve_id2 = $obj->fk_user_approve2;
3118 $this->date_creation = $this->db->jdate($obj->datec);
3119 $this->date_modification = $this->db->jdate($obj->datem);
3120 $this->date_approve = $this->db->jdate($obj->datea);
3121 $this->date_approve2 = $this->db->jdate($obj->datea2);
3122 $this->date_validation = $this->db->jdate($obj->date_validation);
3124 $this->db->free($result);
3139 global $conf, $user;
3141 $this->nb = array();
3144 $sql =
"SELECT count(co.rowid) as nb";
3145 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as co";
3146 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe as s ON co.fk_soc = s.rowid";
3147 if (!$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3148 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
3149 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
3152 $sql .=
" ".$clause.
" co.entity IN (".
getEntity(
'supplier_order').
")";
3154 $resql = $this->db->query($sql);
3156 while ($obj = $this->db->fetch_object($resql)) {
3157 $this->nb[
"supplier_orders"] = $obj->nb;
3159 $this->db->free($resql);
3163 $this->error = $this->db->error();
3179 global $conf, $langs;
3181 $sql =
"SELECT c.rowid, c.date_creation as datec, c.date_commande, c.fk_statut, c.date_livraison as delivery_date, c.total_ht";
3182 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as c";
3183 if (!$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3184 $sql .=
" JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
3186 $sql .=
" WHERE c.entity = ".$conf->entity;
3187 if ($mode ===
'awaiting') {
3188 $sql .=
" AND c.fk_statut IN (".self::STATUS_ORDERSENT.
", ".self::STATUS_RECEIVED_PARTIALLY.
")";
3190 $sql .=
" AND c.fk_statut IN (".self::STATUS_VALIDATED.
", ".self::STATUS_ACCEPTED.
")";
3193 $sql .=
" AND c.fk_soc = ".((int) $user->socid);
3196 $resql = $this->db->query($sql);
3201 $response->warning_delay = $conf->commande->fournisseur->warning_delay / 60 / 60 / 24;
3202 $response->label = $langs->trans(
"SuppliersOrdersToProcess");
3203 $response->labelShort = $langs->trans(
"Opened");
3204 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=1,2&mainmenu=commercial&leftmenu=orders_suppliers';
3207 if ($mode ===
'awaiting') {
3208 $response->label = $langs->trans(
"SuppliersOrdersAwaitingReception");
3209 $response->labelShort = $langs->trans(
"AwaitingReception");
3210 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=3,4&mainmenu=commercial&leftmenu=orders_suppliers';
3213 while ($obj = $this->db->fetch_object($resql)) {
3214 $commandestatic->delivery_date = $this->db->jdate($obj->delivery_date);
3215 $commandestatic->date_commande = $this->db->jdate($obj->date_commande);
3216 $commandestatic->statut = $obj->fk_statut;
3218 $response->nbtodo++;
3219 $response->total += $obj->total_ht;
3221 if ($commandestatic->hasDelay()) {
3222 $response->nbtodolate++;
3228 $this->error = $this->db->error();
3243 if ($this->methode_commande_id > 0) {
3244 $sql =
"SELECT rowid, code, libelle as label";
3245 $sql .=
" FROM ".$this->db->prefix().
'c_input_method';
3246 $sql .=
" WHERE active=1 AND rowid = ".((int) $this->methode_commande_id);
3248 $resql = $this->db->query($sql);
3250 if ($this->db->num_rows($resql)) {
3251 $obj = $this->db->fetch_object($resql);
3253 $string = $langs->trans($obj->code);
3254 if ($string == $obj->code) {
3255 $string = $obj->label !=
'-' ? $obj->label :
'';
3278 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3280 global $conf, $langs;
3285 if (!empty($this->model_pdf)) {
3286 $modele = $this->model_pdf;
3292 if (empty($modele)) {
3295 $langs->load(
"suppliers");
3296 $outputlangs->load(
"products");
3298 $modelpath =
"core/modules/supplier_order/doc/";
3299 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3312 if (empty($this->lines)) {
3319 foreach ($this->lines as $line) {
3320 if ($line->fk_product > 0) {
3321 $idp = $obj->find_min_price_product_fournisseur($line->fk_product, $line->qty);
3324 if ($obj->delivery_time_days > $nb) {
3325 $nb = $obj->delivery_time_days;
3334 return $nb.
' '.$langs->trans(
'Days');
3347 return $user->hasRight(
"fournisseur",
"commande");
3362 'commande_fournisseur'
3379 'commande_fournisseurdet'
3396 if ($this->
statut == self::STATUS_ORDERSENT || $this->
statut == self::STATUS_RECEIVED_PARTIALLY) {
3398 if (!empty($this->delivery_date)) {
3399 $date_to_test = $this->delivery_date;
3400 return $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay);
3408 $date_to_test = $this->date_commande;
3410 return ($this->
statut > 0 && $this->
statut < 5) && $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay);
3423 global $conf, $langs;
3427 if ($this->
statut == self::STATUS_ORDERSENT || $this->
statut == self::STATUS_RECEIVED_PARTIALLY) {
3428 if (!empty($this->delivery_date)) {
3429 $text = $langs->trans(
"DeliveryDate").
' '.
dol_print_date($this->delivery_date,
'day');
3431 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3434 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3437 $text .=
' '.($conf->commande->fournisseur->warning_delay > 0 ?
'+' :
'-').
' '.round(abs($conf->commande->fournisseur->warning_delay) / 3600 / 24, 1).
' '.$langs->trans(
"days").
' < '.$langs->trans(
"Today");
3454 global $conf, $langs;
3456 if (isModEnabled(
"supplier_order")) {
3457 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
3459 $qtydelivered = array();
3460 $qtywished = array();
3463 $filter = array(
't.fk_commande'=>$this->
id);
3465 $filter[
't.status'] = 1;
3468 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
3470 $this->error = $supplierorderdispatch->error;
3471 $this->errors = $supplierorderdispatch->errors;
3474 if (is_array($supplierorderdispatch->lines) && count($supplierorderdispatch->lines) > 0) {
3475 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
3479 foreach ($supplierorderdispatch->lines as $line) {
3480 $qtydelivered[$line->fk_product] += $line->qty;
3482 foreach ($this->lines as $line) {
3487 $qtywished[$line->fk_product] += $line->qty;
3491 $diff_array = array_diff_assoc($qtydelivered, $qtywished);
3492 $keysinwishednotindelivered = array_diff(array_keys($qtywished), array_keys($qtydelivered));
3493 $keysindeliverednotinwished = array_diff(array_keys($qtydelivered), array_keys($qtywished));
3501 if (count($diff_array) == 0 && count($keysinwishednotindelivered) == 0 && count($keysindeliverednotinwished) == 0) {
3502 if ($closeopenorder) {
3504 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3512 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3523 if (count($diff_array) > 0) {
3527 foreach ($diff_array as $key => $value) {
3529 if ($qtydelivered[$key] >= $qtywished[$key]) {
3536 if ($close == count($diff_array)) {
3538 if ($closeopenorder) {
3539 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3546 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3554 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3562 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3584 $this->receptions = array();
3586 dol_syslog(get_class($this).
"::loadReceptions", LOG_DEBUG);
3588 $sql =
'SELECT cd.rowid, cd.fk_product,';
3589 $sql .=
' sum(cfd.qty) as qty';
3590 $sql .=
' FROM '.$this->db->prefix().
'commande_fournisseur_dispatch as cfd,';
3591 if ($filtre_statut >= 0) {
3592 $sql .=
' '.$this->db->prefix().
'reception as e,';
3594 $sql .=
' '.$this->db->prefix().
'commande_fournisseurdet as cd';
3596 if ($filtre_statut >= 0) {
3597 $sql .=
' cfd.fk_reception = e.rowid AND';
3599 $sql .=
' cfd.fk_commandefourndet = cd.rowid';
3600 $sql .=
' AND cd.fk_commande ='.((int) $this->
id);
3601 if (isset($this->fk_product) && !empty($this->fk_product) > 0) {
3602 $sql .=
' AND cd.fk_product = '.((int) $this->fk_product);
3604 if ($filtre_statut >= 0) {
3605 $sql .=
' AND e.fk_statut >= '.((int) $filtre_statut);
3607 $sql .=
' GROUP BY cd.rowid, cd.fk_product';
3609 $resql = $this->db->query($sql);
3611 $num = $this->db->num_rows($resql);
3614 $obj = $this->db->fetch_object($resql);
3615 empty($this->receptions[$obj->rowid]) ? $this->receptions[$obj->rowid] = $obj->qty : $this->receptions[$obj->rowid] += $obj->qty;
3618 $this->db->free($resql);
3622 $this->error = $this->db->lasterror();
3638 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3640 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3641 $return .=
'<div class="info-box info-box-sm">';
3642 $return .=
'<span class="info-box-icon bg-infobox-action">';
3644 $return .=
'</span>';
3645 $return .=
'<div class="info-box-content">';
3646 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
3647 if ($selected >= 0) {
3648 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3650 if (property_exists($this,
'socid') || property_exists($this,
'total_tva')) {
3651 $return .=
'<br><span class="info-box-label amount">'.$this->socid.
'</span>';
3653 if (property_exists($this,
'billed')) {
3654 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Billed").
' : </span><span class="info-box-label">'.
yn($this->billed).
'</span>';
3656 if (method_exists($this,
'getLibStatut')) {
3657 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
3659 $return .=
'</div>';
3660 $return .=
'</div>';
3661 $return .=
'</div>';
3676 public $element =
'commande_fournisseurdet';
3681 public $table_element =
'commande_fournisseurdet';
3689 public $fk_commande;
3695 public $fk_parent_line;
3703 public $special_code = 0;
3713 public $fk_fournprice;
3723 public $ref_supplier;
3755 $sql =
'SELECT cd.rowid, cd.fk_commande, cd.fk_product, cd.product_type, cd.description, cd.qty, cd.tva_tx, cd.special_code,';
3756 $sql .=
' cd.localtax1_tx, cd.localtax2_tx, cd.localtax1_type, cd.localtax2_type, cd.ref as ref_supplier,';
3757 $sql .=
' cd.remise, cd.remise_percent, cd.subprice,';
3758 $sql .=
' cd.info_bits, cd.total_ht, cd.total_tva, cd.total_ttc,';
3759 $sql .=
' cd.total_localtax1, cd.total_localtax2,';
3760 $sql .=
' p.ref as product_ref, p.label as product_label, p.description as product_desc,';
3761 $sql .=
' cd.date_start, cd.date_end, cd.fk_unit,';
3762 $sql .=
' cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc,';
3763 $sql .=
' c.fk_soc as socid';
3764 $sql .=
' FROM '.$this->db->prefix().
'commande_fournisseur as c, '.$this->db->prefix().
'commande_fournisseurdet as cd';
3765 $sql .=
' LEFT JOIN '.$this->db->prefix().
'product as p ON cd.fk_product = p.rowid';
3766 $sql .=
' WHERE cd.fk_commande = c.rowid AND cd.rowid = '.((int) $rowid);
3768 $result = $this->db->query($sql);
3770 $objp = $this->db->fetch_object($result);
3772 if (!empty($objp)) {
3773 $this->
rowid = $objp->rowid;
3774 $this->
id = $objp->rowid;
3775 $this->fk_commande = $objp->fk_commande;
3776 $this->desc = $objp->description;
3777 $this->qty = $objp->qty;
3778 $this->ref_fourn = $objp->ref_supplier;
3779 $this->ref_supplier = $objp->ref_supplier;
3780 $this->subprice = $objp->subprice;
3781 $this->tva_tx = $objp->tva_tx;
3782 $this->localtax1_tx = $objp->localtax1_tx;
3783 $this->localtax2_tx = $objp->localtax2_tx;
3784 $this->localtax1_type = $objp->localtax1_type;
3785 $this->localtax2_type = $objp->localtax2_type;
3786 $this->remise = $objp->remise;
3787 $this->remise_percent = $objp->remise_percent;
3788 $this->fk_product = $objp->fk_product;
3789 $this->info_bits = $objp->info_bits;
3790 $this->total_ht = $objp->total_ht;
3791 $this->total_tva = $objp->total_tva;
3792 $this->total_localtax1 = $objp->total_localtax1;
3793 $this->total_localtax2 = $objp->total_localtax2;
3794 $this->total_ttc = $objp->total_ttc;
3795 $this->product_type = $objp->product_type;
3796 $this->special_code = $objp->special_code;
3798 $this->
ref = $objp->product_ref;
3800 $this->product_ref = $objp->product_ref;
3801 $this->product_label = $objp->product_label;
3802 $this->product_desc = $objp->product_desc;
3809 $sqlsearchpackage =
'SELECT rowid, packaging FROM '.$this->db->prefix().
"product_fournisseur_price";
3810 $sqlsearchpackage .=
' WHERE entity IN ('.getEntity(
'product_fournisseur_price').
")";
3811 $sqlsearchpackage .=
" AND fk_product = ".((int) $objp->fk_product);
3812 $sqlsearchpackage .=
" AND ref_fourn = '".$this->db->escape($objp->ref_supplier).
"'";
3813 $sqlsearchpackage .=
" AND quantity <= ".((float) $objp->qty);
3814 $sqlsearchpackage .=
" AND (packaging IS NULL OR packaging = 0 OR packaging <= ".((float) $objp->qty).
")";
3815 $sqlsearchpackage .=
" AND fk_soc = ".((int) $objp->socid);
3816 $sqlsearchpackage .=
" ORDER BY packaging ASC";
3817 $sqlsearchpackage .=
" LIMIT 1";
3819 $resqlsearchpackage = $this->db->query($sqlsearchpackage);
3820 if ($resqlsearchpackage) {
3821 $objsearchpackage = $this->db->fetch_object($resqlsearchpackage);
3822 if ($objsearchpackage) {
3823 $this->fk_fournprice = $objsearchpackage->rowid;
3824 $this->packaging = $objsearchpackage->packaging;
3827 $this->error = $this->db->lasterror();
3832 $this->date_start = $this->db->jdate($objp->date_start);
3833 $this->date_end = $this->db->jdate($objp->date_end);
3834 $this->fk_unit = $objp->fk_unit;
3836 $this->multicurrency_subprice = $objp->multicurrency_subprice;
3837 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
3838 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
3839 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
3843 $this->db->free($result);
3846 $this->error =
'Supplier order line with id='.$rowid.
' not found';
3847 dol_syslog(get_class($this).
"::fetch Error ".$this->error, LOG_ERR);
3864 global $conf, $user;
3868 dol_syslog(get_class($this).
"::insert rang=".$this->rang);
3871 if (empty($this->tva_tx)) {
3874 if (empty($this->localtax1_tx)) {
3875 $this->localtax1_tx = 0;
3877 if (empty($this->localtax2_tx)) {
3878 $this->localtax2_tx = 0;
3880 if (empty($this->localtax1_type)) {
3881 $this->localtax1_type =
'0';
3883 if (empty($this->localtax2_type)) {
3884 $this->localtax2_type =
'0';
3886 if (empty($this->total_localtax1)) {
3887 $this->total_localtax1 = 0;
3889 if (empty($this->total_localtax2)) {
3890 $this->total_localtax2 = 0;
3892 if (empty($this->rang)) {
3895 if (empty($this->remise_percent)) {
3896 $this->remise_percent = 0;
3898 if (empty($this->info_bits)) {
3899 $this->info_bits = 0;
3901 if (empty($this->special_code)) {
3902 $this->special_code = 0;
3904 if (empty($this->fk_parent_line)) {
3905 $this->fk_parent_line = 0;
3907 if (empty($this->pa_ht)) {
3912 if (!empty($this->multicurrency_code)) {
3915 if (empty($this->fk_multicurrency)) {
3916 $this->multicurrency_code = $conf->currency;
3917 $this->fk_multicurrency = 0;
3918 $this->multicurrency_tx = 1;
3922 if ($this->product_type < 0) {
3929 $sql =
'INSERT INTO '.$this->db->prefix().$this->table_element;
3930 $sql .=
" (fk_commande, label, description, date_start, date_end,";
3931 $sql .=
" fk_product, product_type, special_code, rang,";
3932 $sql .=
" qty, vat_src_code, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, remise_percent, subprice, ref,";
3933 $sql .=
" total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_unit,";
3934 $sql .=
" fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc,";
3935 $sql .=
" fk_parent_line)";
3936 $sql .=
" VALUES (".$this->fk_commande.
", '".$this->db->escape($this->label).
"','".$this->db->escape($this->desc).
"',";
3937 $sql .=
" ".($this->date_start ?
"'".$this->db->idate($this->date_start).
"'" :
"null").
",";
3938 $sql .=
" ".($this->date_end ?
"'".$this->db->idate($this->date_end).
"'" :
"null").
",";
3939 if ($this->fk_product) {
3940 $sql .= $this->fk_product.
",";
3944 $sql .=
"'".$this->db->escape($this->product_type).
"',";
3945 $sql .=
"'".$this->db->escape($this->special_code).
"',";
3946 $sql .=
"'".$this->db->escape($this->rang).
"',";
3947 $sql .=
"'".$this->db->escape($this->qty).
"', ";
3948 $sql .=
" ".(empty($this->vat_src_code) ?
"''" :
"'".$this->db->escape($this->vat_src_code).
"'").
",";
3949 $sql .=
" ".price2num($this->tva_tx).
", ";
3950 $sql .=
" ".price2num($this->localtax1_tx).
",";
3951 $sql .=
" ".price2num($this->localtax2_tx).
",";
3952 $sql .=
" '".$this->db->escape($this->localtax1_type).
"',";
3953 $sql .=
" '".$this->db->escape($this->localtax2_type).
"',";
3954 $sql .=
" ".((float) $this->remise_percent).
", ".
price2num($this->subprice,
'MU').
", '".$this->db->escape($this->ref_supplier).
"',";
3955 $sql .=
" ".price2num($this->total_ht).
",";
3956 $sql .=
" ".price2num($this->total_tva).
",";
3957 $sql .=
" ".price2num($this->total_localtax1).
",";
3958 $sql .=
" ".price2num($this->total_localtax2).
",";
3959 $sql .=
" ".price2num($this->total_ttc).
",";
3960 $sql .= ($this->fk_unit ?
"'".$this->db->escape($this->fk_unit).
"'" :
"null");
3961 $sql .=
", ".($this->fk_multicurrency ? ((int) $this->fk_multicurrency) :
"null");
3962 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
3963 $sql .=
", ".($this->multicurrency_subprice ?
price2num($this->multicurrency_subprice) :
'0');
3964 $sql .=
", ".($this->multicurrency_total_ht ?
price2num($this->multicurrency_total_ht) :
'0');
3965 $sql .=
", ".($this->multicurrency_total_tva ?
price2num($this->multicurrency_total_tva) :
'0');
3966 $sql .=
", ".($this->multicurrency_total_ttc ?
price2num($this->multicurrency_total_ttc) :
'0');
3967 $sql .=
", ".((!empty($this->fk_parent_line) && $this->fk_parent_line > 0) ? $this->fk_parent_line :
'null');
3970 dol_syslog(get_class($this).
"::insert", LOG_DEBUG);
3971 $resql = $this->db->query($sql);
3973 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
3974 $this->
rowid = $this->id;
3983 if (!$error && !$notrigger) {
3985 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_CREATE', $user);
3993 $this->db->commit();
3997 foreach ($this->errors as $errmsg) {
3998 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
3999 $this->errors[] = ($this->errors ?
', '.$errmsg : $errmsg);
4001 $this->db->rollback();
4004 $this->errors[] = $this->db->error();
4005 $this->db->rollback();
4024 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
4025 $sql .=
" description='".$this->db->escape($this->desc).
"'";
4026 $sql .=
", ref='".$this->db->escape($this->ref_supplier).
"'";
4027 $sql .=
", subprice='".price2num($this->subprice).
"'";
4029 $sql .=
", remise_percent='".price2num($this->remise_percent).
"'";
4031 $sql .=
", vat_src_code = '".(empty($this->vat_src_code) ?
'' : $this->vat_src_code).
"'";
4032 $sql .=
", tva_tx='".price2num($this->tva_tx).
"'";
4033 $sql .=
", localtax1_tx='".price2num($this->localtax1_tx).
"'";
4034 $sql .=
", localtax2_tx='".price2num($this->localtax2_tx).
"'";
4035 $sql .=
", localtax1_type='".$this->db->escape($this->localtax1_type).
"'";
4036 $sql .=
", localtax2_type='".$this->db->escape($this->localtax2_type).
"'";
4037 $sql .=
", qty='".price2num($this->qty).
"'";
4038 $sql .=
", date_start=".(!empty($this->date_start) ?
"'".$this->db->idate($this->date_start).
"'" :
"null");
4039 $sql .=
", date_end=".(!empty($this->date_end) ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
4040 $sql .=
", info_bits='".$this->db->escape($this->info_bits).
"'";
4041 $sql .=
", total_ht='".price2num($this->total_ht).
"'";
4042 $sql .=
", total_tva='".price2num($this->total_tva).
"'";
4043 $sql .=
", total_localtax1='".price2num($this->total_localtax1).
"'";
4044 $sql .=
", total_localtax2='".price2num($this->total_localtax2).
"'";
4045 $sql .=
", total_ttc='".price2num($this->total_ttc).
"'";
4046 $sql .=
", product_type=".$this->product_type;
4047 $sql .=
", special_code=".(!empty($this->special_code) ? $this->special_code : 0);
4048 $sql .= ($this->fk_unit ?
", fk_unit='".$this->db->escape($this->fk_unit).
"'" :
", fk_unit=null");
4051 $sql .=
", multicurrency_subprice=".price2num($this->multicurrency_subprice);
4052 $sql .=
", multicurrency_total_ht=".price2num($this->multicurrency_total_ht);
4053 $sql .=
", multicurrency_total_tva=".price2num($this->multicurrency_total_tva);
4054 $sql .=
", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc);
4056 $sql .=
" WHERE rowid = ".((int) $this->
id);
4058 dol_syslog(get_class($this).
"::updateline", LOG_DEBUG);
4059 $resql = $this->db->query($sql);
4068 if (!$error && !$notrigger) {
4070 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_MODIFY', $user);
4072 $this->db->rollback();
4079 $this->db->commit();
4082 $this->db->rollback();
4086 $this->error = $this->db->lasterror();
4087 $this->db->rollback();
4098 public function delete($notrigger = 0)
4109 $this->db->rollback();
4113 $sql1 =
'UPDATE '.$this->db->prefix().
"commandedet SET fk_commandefourndet = NULL WHERE fk_commandefourndet=".((int) $this->
id);
4114 $resql = $this->db->query($sql1);
4116 $this->db->rollback();
4120 $sql2 =
'DELETE FROM '.$this->db->prefix().
"commande_fournisseurdet WHERE rowid=".((int) $this->
id);
4123 $resql = $this->db->query($sql2);
4127 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_DELETE', $user);
4135 $this->db->commit();
4139 foreach ($this->errors as $errmsg) {
4140 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
4141 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
4143 $this->db->rollback();
4146 $this->error = $this->db->lasterror();
print $langs trans("AuditedSecurityEvents").'</strong >< span class="opacitymedium"></span >< br > status
Class to manage table commandefournisseurdispatch.
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.
deleteline($idline, $notrigger=0)
Delete line.
load_state_board()
Charge indicateurs this->nb de tableau de bord.
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: ...
$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 informations d'ordre info dans l'objet facture.
const STATUS_CANCELED
Order canceled.
getNextNumRef($soc)
Returns the following order reference not used depending on the numbering model activated defined wit...
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=false, $date_start=null, $date_end=null, $array_options=0, $fk_unit=null, $pu_ht_devise=0, $origin='', $origin_id=0, $rang=-1, $special_code=0)
Add order line.
calcAndSetStatusDispatch(User $user, $closeopenorder=1, $comment='')
Calc status regarding to dispatched stock.
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='', $date_end='', $array_options=0, $fk_unit=null, $pu_ht_devise=0, $ref_supplier='')
Update line.
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 (commande_fournisseur_dispatch) and add product...
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.
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)
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.
static replaceProduct(DoliDB $db, $origin_id, $dest_id)
Function used to replace a product id with another one.
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.
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)
update_price($exclspec=0, $roundingadjust='none', $nodatabaseupdate=0, $seller=null)
Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines).
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($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.
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 '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
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_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
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.
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...
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e rowid
publicphonebutton2 phonegreen basiclayout basiclayout TotalHT VATCode TotalVAT TotalLT1 TotalLT2 TotalTTC TotalHT clearboth nowraponall right right takeposterminal SELECT e e e e e statut
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.