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;
428 $this->socid = $obj->fk_soc;
429 $this->thirdparty =
null;
431 $this->fourn_id = $obj->fk_soc;
432 $this->
statut = $obj->status;
433 $this->
status = $obj->status;
434 $this->billed = $obj->billed;
435 $this->last_main_doc = $obj->last_main_doc;
436 $this->user_author_id = $obj->user_author_id;
437 $this->user_validation_id = $obj->user_validation_id;
438 $this->user_approve_id = $obj->user_approve_id;
439 $this->user_approve_id2 = $obj->user_approve_id2;
440 $this->total_ht = $obj->total_ht;
441 $this->total_tva = $obj->total_tva;
442 $this->total_localtax1 = $obj->localtax1;
443 $this->total_localtax2 = $obj->localtax2;
444 $this->total_ttc = $obj->total_ttc;
445 $this->date_creation = $this->db->jdate($obj->date_creation);
446 $this->date_valid = $this->db->jdate($obj->date_valid);
447 $this->date_approve = $this->db->jdate($obj->date_approve);
448 $this->date_approve2 = $this->db->jdate($obj->date_approve2);
449 $this->date_commande = $this->db->jdate($obj->date_commande);
450 if (isset($obj->date_commande)) {
451 $this->date = $this->date_commande;
453 $this->date = $this->date_creation;
455 $this->delivery_date = $this->db->jdate($obj->delivery_date);
456 $this->remise_percent = $obj->remise_percent;
457 $this->methode_commande_id = $obj->fk_input_method;
458 $this->methode_commande = $obj->methode_commande;
460 $this->source = $obj->source;
461 $this->fk_project = $obj->fk_project;
462 $this->cond_reglement_id = $obj->fk_cond_reglement;
463 $this->cond_reglement_code = $obj->cond_reglement_code;
464 $this->cond_reglement = $obj->cond_reglement_label;
465 $this->cond_reglement_label = $obj->cond_reglement_label;
466 $this->cond_reglement_doc = $obj->cond_reglement_doc;
467 $this->fk_account = $obj->fk_account;
468 $this->mode_reglement_id = $obj->fk_mode_reglement;
469 $this->mode_reglement_code = $obj->mode_reglement_code;
470 $this->mode_reglement = $obj->mode_reglement_libelle;
471 $this->note = $obj->note_private;
472 $this->note_private = $obj->note_private;
473 $this->note_public = $obj->note_public;
474 $this->model_pdf = $obj->model_pdf;
477 $this->fk_incoterms = $obj->fk_incoterms;
478 $this->location_incoterms = $obj->location_incoterms;
479 $this->label_incoterms = $obj->label_incoterms;
482 $this->fk_multicurrency = $obj->fk_multicurrency;
483 $this->multicurrency_code = $obj->multicurrency_code;
484 $this->multicurrency_tx = $obj->multicurrency_tx;
485 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
486 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
487 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
489 $this->extraparams = isset($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
491 $this->db->free($resql);
506 $this->error = $this->db->error().
" sql=".$sql;
523 $this->lines = array();
525 $sql =
"SELECT l.rowid, l.fk_commande, l.ref as ref_supplier, l.fk_product, l.product_type, l.label, l.description, l.qty,";
526 $sql .=
" l.vat_src_code, l.tva_tx, l.remise_percent, l.subprice,";
527 $sql .=
" l.localtax1_tx, l. localtax2_tx, l.localtax1_type, l. localtax2_type, l.total_localtax1, l.total_localtax2,";
528 $sql .=
" l.total_ht, l.total_tva, l.total_ttc, l.info_bits, l.special_code, l.fk_parent_line, l.rang,";
529 $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,";
530 $sql .=
" l.fk_unit,";
531 $sql .=
" l.date_start, l.date_end,";
532 $sql .=
' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc';
533 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseurdet as l";
534 $sql .=
' LEFT JOIN '.$this->db->prefix().
'product as p ON l.fk_product = p.rowid';
535 $sql .=
" WHERE l.fk_commande = ".((int) $this->
id);
537 $sql .=
' AND p.fk_product_type = 0';
539 $sql .=
" ORDER BY l.rang, l.rowid";
542 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
544 $result = $this->db->query($sql);
546 $num = $this->db->num_rows($result);
550 $objp = $this->db->fetch_object($result);
554 $line->id = $objp->rowid;
555 $line->fk_commande = $objp->fk_commande;
556 $line->desc = $objp->description;
557 $line->description = $objp->description;
558 $line->qty = $objp->qty;
559 $line->tva_tx = $objp->tva_tx;
560 $line->localtax1_tx = $objp->localtax1_tx;
561 $line->localtax2_tx = $objp->localtax2_tx;
562 $line->localtax1_type = $objp->localtax1_type;
563 $line->localtax2_type = $objp->localtax2_type;
564 $line->subprice = $objp->subprice;
565 $line->pu_ht = $objp->subprice;
566 $line->remise_percent = $objp->remise_percent;
568 $line->vat_src_code = $objp->vat_src_code;
569 $line->total_ht = $objp->total_ht;
570 $line->total_tva = $objp->total_tva;
571 $line->total_localtax1 = $objp->total_localtax1;
572 $line->total_localtax2 = $objp->total_localtax2;
573 $line->total_ttc = $objp->total_ttc;
574 $line->product_type = $objp->product_type;
576 $line->fk_product = $objp->fk_product;
578 $line->libelle = $objp->product_label;
579 $line->product_label = $objp->product_label;
580 $line->product_desc = $objp->product_desc;
581 $line->product_tobatch = $objp->product_tobatch;
582 $line->product_barcode = $objp->product_barcode;
584 $line->ref = $objp->product_ref;
585 $line->product_ref = $objp->product_ref;
586 $line->ref_fourn = $objp->ref_supplier;
587 $line->ref_supplier = $objp->ref_supplier;
594 $sqlsearchpackage =
'SELECT rowid, packaging FROM '.$this->db->prefix().
"product_fournisseur_price";
595 $sqlsearchpackage .=
' WHERE entity IN ('.getEntity(
'product_fournisseur_price').
")";
596 $sqlsearchpackage .=
" AND fk_product = ".((int) $objp->fk_product);
597 $sqlsearchpackage .=
" AND ref_fourn = '".$this->db->escape($objp->ref_supplier).
"'";
598 $sqlsearchpackage .=
" AND quantity <= ".((float) $objp->qty);
599 $sqlsearchpackage .=
" AND (packaging IS NULL OR packaging = 0 OR packaging <= ".((float) $objp->qty).
")";
600 $sqlsearchpackage .=
" AND fk_soc = ".((int) $this->socid);
601 $sqlsearchpackage .=
" ORDER BY packaging ASC";
602 $sqlsearchpackage .=
" LIMIT 1";
604 $resqlsearchpackage = $this->db->query($sqlsearchpackage);
605 if ($resqlsearchpackage) {
606 $objsearchpackage = $this->db->fetch_object($resqlsearchpackage);
607 if ($objsearchpackage) {
608 $line->fk_fournprice = $objsearchpackage->rowid;
609 $line->packaging = $objsearchpackage->packaging;
612 $this->error = $this->db->lasterror();
617 $line->date_start = $this->db->jdate($objp->date_start);
618 $line->date_end = $this->db->jdate($objp->date_end);
619 $line->fk_unit = $objp->fk_unit;
622 $line->fk_multicurrency = $objp->fk_multicurrency;
623 $line->multicurrency_code = $objp->multicurrency_code;
624 $line->multicurrency_subprice = $objp->multicurrency_subprice;
625 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
626 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
627 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
629 $line->info_bits = $objp->info_bits;
630 $line->special_code = $objp->special_code;
631 $line->fk_parent_line = $objp->fk_parent_line;
633 $line->rang = $objp->rang;
637 $line->fetch_optionals();
639 $this->lines[$i] = $line;
643 $this->db->free($result);
647 $this->error = $this->db->error().
" sql=".$sql;
660 public function valid($user, $idwarehouse = 0, $notrigger = 0)
662 global $langs, $conf;
663 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
669 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")))
670 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"fournisseur",
"supplier_order_advance",
"validate"))) {
675 $soc->fetch($this->fourn_id);
678 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
685 $sql =
'UPDATE '.$this->db->prefix().
"commande_fournisseur";
686 $sql .=
" SET ref='".$this->db->escape($num).
"',";
687 $sql .=
" fk_statut = ".((int) self::STATUS_VALIDATED).
",";
688 $sql .=
" date_valid='".$this->db->idate(
dol_now()).
"',";
689 $sql .=
" fk_user_valid = ".((int) $user->id);
690 $sql .=
" WHERE rowid = ".((int) $this->
id);
691 $sql .=
" AND fk_statut = ".((int) self::STATUS_DRAFT);
693 $resql = $this->db->query($sql);
699 if (!$error && !$notrigger) {
701 $result = $this->
call_trigger(
'ORDER_SUPPLIER_VALIDATE', $user);
709 $this->oldref = $this->ref;
712 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
714 $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).
"'";
715 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'fournisseur/commande/".$this->db->escape($this->
ref).
"' and entity = ".((int) $conf->entity);
716 $resql = $this->db->query($sql);
719 $this->error = $this->db->lasterror();
721 $sql =
'UPDATE '.$this->db->prefix().
"ecm_files set filepath = 'fournisseur/commande/".$this->db->escape($this->newref).
"'";
722 $sql .=
" WHERE filepath = 'fournisseur/commande/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
723 $resql = $this->db->query($sql);
726 $this->error = $this->db->lasterror();
732 $dirsource = $conf->fournisseur->commande->dir_output.
'/'.$oldref;
733 $dirdest = $conf->fournisseur->commande->dir_output.
'/'.$newref;
734 if (!$error && file_exists($dirsource)) {
735 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
737 if (@rename($dirsource, $dirdest)) {
740 $listoffiles =
dol_dir_list($conf->fournisseur->commande->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
741 foreach ($listoffiles as $fileentry) {
742 $dirsource = $fileentry[
'name'];
743 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
744 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
745 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
746 @rename($dirsource, $dirdest);
764 $this->db->rollback();
768 $this->error =
'NotAuthorized';
769 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
794 public function LibStatut($status, $mode = 0, $billed = 0)
797 global $conf, $langs, $hookmanager;
799 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
800 $langs->load(
'orders');
802 $this->labelStatus[0] =
'StatusSupplierOrderDraft';
803 $this->labelStatus[1] =
'StatusSupplierOrderValidated';
804 $this->labelStatus[2] =
'StatusSupplierOrderApproved';
806 $this->labelStatus[3] =
'StatusSupplierOrderOnProcess';
808 $this->labelStatus[3] =
'StatusSupplierOrderOnProcessWithValidation';
810 $this->labelStatus[4] =
'StatusSupplierOrderReceivedPartially';
811 $this->labelStatus[5] =
'StatusSupplierOrderReceivedAll';
812 $this->labelStatus[6] =
'StatusSupplierOrderCanceled';
813 $this->labelStatus[7] =
'StatusSupplierOrderCanceled';
814 $this->labelStatus[9] =
'StatusSupplierOrderRefused';
817 $this->labelStatusShort[0] =
'StatusSupplierOrderDraftShort';
818 $this->labelStatusShort[1] =
'StatusSupplierOrderValidatedShort';
819 $this->labelStatusShort[2] =
'StatusSupplierOrderApprovedShort';
820 $this->labelStatusShort[3] =
'StatusSupplierOrderOnProcessShort';
821 $this->labelStatusShort[4] =
'StatusSupplierOrderReceivedPartiallyShort';
822 $this->labelStatusShort[5] =
'StatusSupplierOrderReceivedAllShort';
823 $this->labelStatusShort[6] =
'StatusSupplierOrderCanceledShort';
824 $this->labelStatusShort[7] =
'StatusSupplierOrderCanceledShort';
825 $this->labelStatusShort[9] =
'StatusSupplierOrderRefusedShort';
828 $statustrans = array(
840 $statusClass =
'status0';
841 if (!empty($statustrans[$status])) {
842 $statusClass = $statustrans[$status];
847 $billedtext =
' - '.$langs->trans(
"Billed");
849 if ($status == 5 && $billed) {
850 $statusClass =
'status6';
853 $statusLong = $langs->transnoentitiesnoconv($this->labelStatus[$status]).$billedtext;
854 $statusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
856 $parameters = array(
'status' => $status,
'mode' => $mode,
'billed' => $billed);
857 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
859 return $hookmanager->resPrint;
862 return dolGetStatus($statusLong, $statusShort,
'', $statusClass, $mode);
874 global $conf, $langs, $user;
876 $langs->loadLangs([
'bills',
'orders']);
879 $nofetch = !empty($params[
'nofetch']);
881 if ($user->hasRight(
"fournisseur",
"commande",
"read")) {
882 $datas[
'picto'] =
'<u class="paddingrightonly">'.$langs->trans(
"SupplierOrder").
'</u>';
883 if (isset($this->
statut)) {
884 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
886 if (!empty($this->
ref)) {
887 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
889 if (!empty($this->ref_supplier)) {
890 $datas[
'refsupplier'] =
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.$this->ref_supplier;
893 $langs->load(
'companies');
894 if (empty($this->thirdparty)) {
897 $datas[
'supplier'] =
'<br><b>'.$langs->trans(
'Supplier').
':</b> '.$this->thirdparty->getNomUrl(1,
'', 0, 1);
899 if (!empty($this->total_ht)) {
900 $datas[
'totalht'] =
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
902 if (!empty($this->total_tva)) {
903 $datas[
'totaltva'] =
'<br><b>'.$langs->trans(
'VAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
905 if (!empty($this->total_ttc)) {
906 $datas[
'totalttc'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
908 if (!empty($this->date)) {
909 $datas[
'date'] =
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->date,
'day');
911 if (!empty($this->delivery_date)) {
912 $datas[
'deliverydate'] =
'<br><b>'.$langs->trans(
'DeliveryDate').
':</b> '.
dol_print_date($this->delivery_date,
'dayhour');
928 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = 0)
930 global $langs, $conf, $user, $hookmanager;
935 'objecttype' => $this->element,
939 $classfortooltip =
'classfortooltip';
942 $classfortooltip =
'classforajaxtooltip';
943 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
949 $url = DOL_URL_ROOT.
'/fourn/commande/card.php?id='.$this->id;
951 if ($option !==
'nolink') {
953 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
954 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
955 $add_save_lastsearch_values = 1;
957 if ($add_save_lastsearch_values) {
958 $url .=
'&save_lastsearch_values=1';
963 if (empty($notooltip)) {
965 $label = $langs->trans(
"ShowOrder");
966 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
968 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
969 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
972 $linkstart =
'<a href="'.$url.
'"';
973 $linkstart .= $linkclose.
'>';
976 $result .= $linkstart;
978 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
980 if ($withpicto != 2) {
981 $result .= $this->ref;
985 if ($addlinktonotes) {
986 $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
989 $result .=
' <span class="note inline-block">';
990 $result .=
'<a href="'.DOL_URL_ROOT.
'/fourn/commande/note.php?id='.$this->
id.
'" class="classfortooltip" title="'.
dol_escape_htmltag($notetoshow).
'">';
995 $result .=
'</span>';
1000 $hookmanager->initHooks(array($this->element .
'dao'));
1001 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1002 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1004 $result = $hookmanager->resPrint;
1006 $result .= $hookmanager->resPrint;
1021 global $db, $langs, $conf;
1022 $langs->load(
"orders");
1031 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
1033 foreach ($dirmodels as $reldir) {
1034 $dir =
dol_buildpath($reldir.
"core/modules/supplier_order/");
1037 $mybool |= @include_once $dir.$file;
1040 if ($mybool ===
false) {
1045 $obj =
new $classname();
1046 $numref = $obj->getNextValue($soc, $this);
1048 if ($numref !=
"") {
1051 $this->error = $obj->error;
1055 $this->error =
"Error_COMMANDE_SUPPLIER_ADDON_NotDefined";
1069 if ($this->billed) {
1075 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur SET billed = 1';
1078 if ($this->db->query($sql)) {
1081 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CLASSIFY_BILLED', $user);
1091 $this->db->commit();
1094 $this->db->rollback();
1100 $this->db->rollback();
1113 public function approve($user, $idwarehouse = 0, $secondlevel = 0)
1115 global $langs, $conf;
1116 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1122 if ($user->hasRight(
"fournisseur",
"commande",
"approuver")) {
1128 $soc =
new Societe($this->db);
1129 $soc->fetch($this->fourn_id);
1132 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
1140 $movetoapprovestatus =
true;
1143 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1144 $sql .=
" SET ref='".$this->db->escape($num).
"',";
1145 if (empty($secondlevel)) {
1146 $sql .=
" date_approve='".$this->db->idate($now).
"',";
1147 $sql .=
" fk_user_approve = ".$user->id;
1148 if (
getDolGlobalString(
'SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED') && $this->total_ht >= $conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) {
1149 if (empty($this->user_approve_id2)) {
1150 $movetoapprovestatus =
false;
1151 $comment =
' (first level)';
1155 $sql .=
" date_approve2='".$this->db->idate($now).
"',";
1156 $sql .=
" fk_user_approve2 = ".((int) $user->id);
1157 if (empty($this->user_approve_id)) {
1158 $movetoapprovestatus =
false;
1160 $comment =
' (second level)';
1163 if ($movetoapprovestatus) {
1164 $sql .=
", fk_statut = ".self::STATUS_ACCEPTED;
1166 $sql .=
", fk_statut = ".self::STATUS_VALIDATED;
1168 $sql .=
" WHERE rowid = ".((int) $this->
id);
1169 $sql .=
" AND fk_statut = ".self::STATUS_VALIDATED;
1171 if ($this->db->query($sql)) {
1173 $result = $this->
add_contact($user->id,
'SALESREPFOLL',
'internal', 1);
1174 if ($result < 0 && $result != -2) {
1180 if (!$error && $movetoapprovestatus && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER')) {
1181 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1182 $langs->load(
"agenda");
1184 $cpt = count($this->lines);
1185 for ($i = 0; $i < $cpt; $i++) {
1187 if ($this->lines[$i]->fk_product > 0) {
1188 $this->line = $this->lines[$i];
1190 $mouvP->origin = &$this;
1191 $mouvP->setOrigin($this->element, $this->
id);
1193 $up_ht_disc = $this->lines[$i]->subprice;
1194 if (!empty($this->lines[$i]->remise_percent) && !
getDolGlobalString(
'STOCK_EXCLUDE_DISCOUNT_FOR_PMP')) {
1195 $up_ht_disc =
price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100,
'MU');
1197 $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans(
"OrderApprovedInDolibarr", $this->ref));
1208 $result = $this->
call_trigger(
'ORDER_SUPPLIER_APPROVE', $user);
1216 $this->
ref = $this->newref;
1218 if ($movetoapprovestatus) {
1223 if (empty($secondlevel)) {
1224 $this->date_approve = $now;
1225 $this->user_approve_id = $user->id;
1227 $this->date_approve2 = $now;
1228 $this->user_approve_id2 = $user->id;
1231 $this->db->commit();
1234 $this->db->rollback();
1238 $this->db->rollback();
1239 $this->error = $this->db->lasterror();
1243 dol_syslog(get_class($this).
"::approve Not Authorized", LOG_ERR);
1256 global $conf, $langs;
1262 if ($user->hasRight(
"fournisseur",
"commande",
"approuver")) {
1265 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur SET fk_statut = ".
self::STATUS_REFUSED;
1266 $sql .=
" WHERE rowid = ".((int) $this->
id);
1268 if ($this->db->query($sql)) {
1273 $result = $this->
call_trigger(
'ORDER_SUPPLIER_REFUSE', $user);
1276 $this->db->rollback();
1278 $this->db->commit();
1283 $this->db->rollback();
1284 $this->error = $this->db->lasterror();
1285 dol_syslog(get_class($this).
"::refuse Error -1");
1289 dol_syslog(get_class($this).
"::refuse Not Authorized");
1303 public function Cancel($user, $idwarehouse = -1)
1306 global $langs, $conf;
1312 if ($user->hasRight(
"fournisseur",
"commande",
"commander")) {
1317 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur SET fk_statut = ".((int) $statut);
1318 $sql .=
" WHERE rowid = ".((int) $this->
id);
1319 dol_syslog(get_class($this).
"::cancel", LOG_DEBUG);
1320 if ($this->db->query($sql)) {
1324 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CANCEL', $user);
1331 $this->db->commit();
1334 $this->db->rollback();
1338 $this->db->rollback();
1339 $this->error = $this->db->lasterror();
1340 dol_syslog(get_class($this).
"::cancel ".$this->error);
1344 dol_syslog(get_class($this).
"::cancel Not Authorized");
1358 public function commande($user, $date, $methode, $comment =
'')
1363 if ($user->hasRight(
"fournisseur",
"commande",
"commander")) {
1366 $newnoteprivate = $this->note_private;
1368 $newnoteprivate =
dol_concatdesc($newnoteprivate, $langs->trans(
"Comment").
': '.$comment);
1371 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1372 $sql .=
" SET fk_statut=".self::STATUS_ORDERSENT.
", fk_input_method=".$methode.
", date_commande='".$this->db->idate($date).
"', ";
1373 $sql .=
" note_private='".$this->db->escape($newnoteprivate).
"'";
1374 $sql .=
" WHERE rowid=".((int) $this->
id);
1376 dol_syslog(get_class($this).
"::commande", LOG_DEBUG);
1377 if ($this->db->query($sql)) {
1379 $this->methode_commande_id = $methode;
1380 $this->date_commande = $date;
1381 $this->context = array(
'comments' => $comment);
1384 $result = $this->
call_trigger(
'ORDER_SUPPLIER_SUBMIT', $user);
1391 $this->error = $this->db->lasterror();
1392 $this->errors[] = $this->db->lasterror();
1396 $this->db->commit();
1398 $this->db->rollback();
1402 $this->error = $langs->trans(
'NotAuthorized');
1403 $this->errors[] = $langs->trans(
'NotAuthorized');
1404 dol_syslog(get_class($this).
"::commande User not Authorized", LOG_WARNING);
1407 return ($error ? -1 : 1);
1417 public function create($user, $notrigger = 0)
1419 global $langs, $conf, $hookmanager;
1427 $date = ($this->date_commande ? $this->date_commande : $this->date);
1431 $delivery_date = $this->delivery_date;
1434 if (empty($this->source)) {
1439 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
1444 if (empty($this->fk_multicurrency)) {
1445 $this->multicurrency_code = $conf->currency;
1446 $this->fk_multicurrency = 0;
1447 $this->multicurrency_tx = 1;
1454 $sql =
"INSERT INTO ".$this->db->prefix().
"commande_fournisseur (";
1456 $sql .=
", ref_supplier";
1457 $sql .=
", note_private";
1458 $sql .=
", note_public";
1461 $sql .=
", fk_projet";
1462 $sql .=
", date_creation";
1463 $sql .=
", date_livraison";
1464 $sql .=
", fk_user_author";
1465 $sql .=
", fk_statut";
1467 $sql .=
", model_pdf";
1468 $sql .=
", fk_mode_reglement";
1469 $sql .=
", fk_cond_reglement";
1470 $sql .=
", fk_account";
1471 $sql .=
", fk_incoterms, location_incoterms";
1472 $sql .=
", fk_multicurrency";
1473 $sql .=
", multicurrency_code";
1474 $sql .=
", multicurrency_tx";
1476 $sql .=
" VALUES (";
1478 $sql .=
", ".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"NULL");
1479 $sql .=
", '".$this->db->escape($this->note_private).
"'";
1480 $sql .=
", '".$this->db->escape($this->note_public).
"'";
1481 $sql .=
", ".setEntity($this);
1482 $sql .=
", ".((int) $this->socid);
1483 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
1484 $sql .=
", '".$this->db->idate($date).
"'";
1485 $sql .=
", ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
"null");
1486 $sql .=
", ".((int) $user->id);
1487 $sql .=
", ".self::STATUS_DRAFT;
1488 $sql .=
", ".((int) $this->source);
1489 $sql .=
", '".$this->db->escape(
getDolGlobalString(
'COMMANDE_SUPPLIER_ADDON_PDF')).
"'";
1490 $sql .=
", ".($this->mode_reglement_id > 0 ? $this->mode_reglement_id :
'null');
1491 $sql .=
", ".($this->cond_reglement_id > 0 ? $this->cond_reglement_id :
'null');
1492 $sql .=
", ".($this->fk_account > 0 ? $this->fk_account :
'NULL');
1493 $sql .=
", ".(int) $this->fk_incoterms;
1494 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
1495 $sql .=
", ".(int) $this->fk_multicurrency;
1496 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1497 $sql .=
", ".(float) $this->multicurrency_tx;
1500 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1501 if ($this->db->query($sql)) {
1502 $this->
id = $this->db->last_insert_id($this->db->prefix().
"commande_fournisseur");
1505 $num = count($this->lines);
1508 for ($i = 0; $i < $num; $i++) {
1509 $line = $this->lines[$i];
1510 if (!is_object($line)) {
1511 $line = (object) $line;
1522 $line->localtax1_tx,
1523 $line->localtax2_tx,
1527 $line->remise_percent,
1530 $line->product_type,
1535 $line->array_options,
1537 $line->multicurrency_subprice,
1544 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
1545 $this->db->rollback();
1550 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1551 $sql .=
" SET ref='(PROV".$this->id.
")'";
1552 $sql .=
" WHERE rowid=".((int) $this->
id);
1554 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1555 if ($this->db->query($sql)) {
1558 $this->
ref =
"(PROV".$this->id.
")";
1560 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
1561 $this->linked_objects = $this->linkedObjectsIds;
1565 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
1566 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
1567 if (is_array($tmp_origin_id)) {
1568 foreach ($tmp_origin_id as $origin_id) {
1576 $origin_id = $tmp_origin_id;
1594 if (!$error && !$notrigger) {
1596 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CREATE', $user);
1598 $this->db->rollback();
1606 $this->db->commit();
1609 $this->db->rollback();
1613 $this->error = $this->db->lasterror();
1614 $this->db->rollback();
1619 $this->error =
'Failed to get ID of inserted line';
1624 $this->error = $this->db->lasterror();
1625 $this->db->rollback();
1645 if (isset($this->
ref)) {
1646 $this->
ref = trim($this->
ref);
1648 if (isset($this->ref_supplier)) {
1649 $this->ref_supplier = trim($this->ref_supplier);
1651 if (isset($this->note_private)) {
1652 $this->note_private = trim($this->note_private);
1654 if (isset($this->note_public)) {
1655 $this->note_public = trim($this->note_public);
1657 if (isset($this->model_pdf)) {
1658 $this->model_pdf = trim($this->model_pdf);
1660 if (isset($this->import_key)) {
1661 $this->import_key = trim($this->import_key);
1665 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
1667 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1668 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
1669 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1670 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
1671 $sql .=
" date_commande=".(strval($this->date_commande) !=
'' ?
"'".$this->db->idate($this->date_commande).
"'" :
'null').
",";
1672 $sql .=
" date_valid=".(strval($this->date_validation) !=
'' ?
"'".$this->db->idate($this->date_validation).
"'" :
'null').
",";
1673 $sql .=
" total_tva=".(isset($this->total_tva) ? $this->total_tva :
"null").
",";
1674 $sql .=
" localtax1=".(isset($this->total_localtax1) ? $this->total_localtax1 :
"null").
",";
1675 $sql .=
" localtax2=".(isset($this->total_localtax2) ? $this->total_localtax2 :
"null").
",";
1676 $sql .=
" total_ht=".(isset($this->total_ht) ? $this->total_ht :
"null").
",";
1677 $sql .=
" total_ttc=".(isset($this->total_ttc) ? $this->total_ttc :
"null").
",";
1678 $sql .=
" fk_statut=".(isset($this->
statut) ? $this->
statut :
"null").
",";
1679 $sql .=
" fk_user_author=".(isset($this->user_author_id) ? $this->user_author_id :
"null").
",";
1680 $sql .=
" fk_user_valid=".(isset($this->user_validation_id) && $this->user_validation_id > 0 ? $this->user_validation_id :
"null").
",";
1681 $sql .=
" fk_projet=".(isset($this->fk_project) ? $this->fk_project :
"null").
",";
1682 $sql .=
" fk_cond_reglement=".(isset($this->cond_reglement_id) ? $this->cond_reglement_id :
"null").
",";
1683 $sql .=
" fk_mode_reglement=".(isset($this->mode_reglement_id) ? $this->mode_reglement_id :
"null").
",";
1684 $sql .=
" date_livraison=".(strval($this->delivery_date) !=
'' ?
"'".$this->db->idate($this->delivery_date).
"'" :
'null').
",";
1686 $sql .=
" fk_account=".($this->fk_account > 0 ? $this->fk_account :
"null").
",";
1688 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1689 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1690 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1691 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
1693 $sql .=
" WHERE rowid=".((int) $this->
id);
1697 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1698 $resql = $this->db->query($sql);
1701 $this->errors[] =
"Error ".$this->db->lasterror();
1711 if (!$error && !$notrigger) {
1713 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
1722 foreach ($this->errors as $errmsg) {
1723 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1724 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1726 $this->db->rollback();
1729 $this->db->commit();
1744 global $conf, $user, $hookmanager;
1751 foreach ($this->lines as $line) {
1752 $line->fetch_optionals();
1756 $objFrom = clone $this;
1759 if (!empty($socid) && $socid != $this->socid) {
1760 $objsoc =
new Societe($this->db);
1762 if ($objsoc->fetch($socid) > 0) {
1763 $this->socid = $objsoc->id;
1764 $this->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1765 $this->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1766 $this->fk_project = 0;
1767 $this->fk_delivery_address = 0;
1777 $this->user_author_id = $user->id;
1778 $this->user_validation_id = 0;
1780 $this->date_creation =
'';
1781 $this->date_commande =
'';
1782 $this->date_validation =
'';
1783 $this->ref_supplier =
null;
1784 $this->user_approve_id =
'';
1785 $this->user_approve_id2 =
'';
1786 $this->date_approve =
'';
1787 $this->date_approve2 =
'';
1790 $this->context[
'createfromclone'] =
'createfromclone';
1791 $result = $this->
create($user, $notrigger);
1798 if (is_object($hookmanager)) {
1799 $parameters = array(
'objFrom'=>$objFrom);
1801 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1809 unset($this->context[
'createfromclone']);
1813 $this->db->commit();
1816 $this->db->rollback();
1850 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)
1852 global $langs, $mysoc, $conf;
1854 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");
1855 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1857 if ($this->
statut == self::STATUS_DRAFT) {
1858 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1867 if (empty($txtva)) {
1873 if (empty($txlocaltax1)) {
1876 if (empty($txlocaltax2)) {
1879 if (empty($remise_percent)) {
1880 $remise_percent = 0;
1883 $remise_percent =
price2num($remise_percent);
1886 $pu_ht_devise =
price2num($pu_ht_devise);
1888 if (!preg_match(
'/\((.*)\)/', $txtva)) {
1893 if ($price_base_type ==
'HT') {
1898 $desc = trim($desc);
1901 if ($qty < 0 && !$fk_product) {
1902 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Product"));
1908 if ($date_start && $date_end && $date_start > $date_end) {
1909 $langs->load(
"errors");
1910 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
1917 $product_type = $type;
1920 if ($fk_product > 0) {
1923 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);
1925 if ($prod->fetch($fk_product) > 0) {
1926 $product_type = $prod->type;
1927 $label = $prod->label;
1931 $result = $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', (isset($this->fk_soc) ? $this->fk_soc : $this->socid));
1935 if ($result > 0 && ($origin ==
'commande' || $pu ===
'')) {
1936 $pu = $prod->fourn_pu;
1937 $ref_supplier = $prod->ref_supplier;
1939 if ($remise_percent == 0 && $prod->remise_percent != 0) {
1940 $remise_percent = $prod->remise_percent;
1944 $langs->load(
"errors");
1945 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
1946 $this->db->rollback();
1947 dol_syslog(get_class($this).
"::addline we did not found supplier price, so we can't guess unit price");
1952 if ($result == -1) {
1953 $langs->load(
"errors");
1954 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
1955 $this->db->rollback();
1956 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_DEBUG);
1960 $this->error = $prod->error;
1961 $this->db->rollback();
1962 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_ERR);
1966 $this->error = $prod->error;
1967 $this->db->rollback();
1974 $prod =
new Product($this->db);
1975 $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', (empty($this->fk_soc) ? $this->socid : $this->fk_soc));
1977 if ($qty < $prod->packaging) {
1978 $qty = $prod->packaging;
1980 if (!empty($prod->packaging) && ($qty % $prod->packaging) > 0) {
1981 $coeff = intval($qty / $prod->packaging) + 1;
1982 $qty = $prod->packaging * $coeff;
1983 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'mesgs');
1989 if (isModEnabled(
"multicurrency") && $pu_ht_devise > 0) {
1998 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
1999 $vat_src_code = $reg[1];
2000 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
2008 $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);
2010 $total_ht = $tabprice[0];
2011 $total_tva = $tabprice[1];
2012 $total_ttc = $tabprice[2];
2013 $total_localtax1 = $tabprice[9];
2014 $total_localtax2 = $tabprice[10];
2015 $pu = $pu_ht = $tabprice[3];
2018 $multicurrency_total_ht = $tabprice[16];
2019 $multicurrency_total_tva = $tabprice[17];
2020 $multicurrency_total_ttc = $tabprice[18];
2021 $pu_ht_devise = $tabprice[19];
2023 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2024 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2028 $rang = $rangmax + 1;
2034 $this->line->context = $this->context;
2036 $this->line->fk_commande = $this->id;
2037 $this->line->label = $label;
2038 $this->line->ref_fourn = $ref_supplier;
2039 $this->line->ref_supplier = $ref_supplier;
2040 $this->line->desc = $desc;
2041 $this->line->qty = $qty;
2042 $this->line->tva_tx = $txtva;
2043 $this->line->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0);
2044 $this->line->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0);
2045 $this->line->localtax1_type = $localtax1_type;
2046 $this->line->localtax2_type = $localtax2_type;
2047 $this->line->fk_product = $fk_product;
2048 $this->line->product_type = $product_type;
2049 $this->line->remise_percent = $remise_percent;
2050 $this->line->subprice = $pu_ht;
2051 $this->line->rang = $rang;
2052 $this->line->info_bits = $info_bits;
2054 $this->line->vat_src_code = $vat_src_code;
2055 $this->line->total_ht = $total_ht;
2056 $this->line->total_tva = $total_tva;
2057 $this->line->total_localtax1 = $total_localtax1;
2058 $this->line->total_localtax2 = $total_localtax2;
2059 $this->line->total_ttc = $total_ttc;
2060 $this->line->product_type = $type;
2061 $this->line->special_code = (!empty($special_code) ? $special_code : 0);
2062 $this->line->origin = $origin;
2063 $this->line->origin_id = $origin_id;
2064 $this->line->fk_unit = $fk_unit;
2066 $this->line->date_start = $date_start;
2067 $this->line->date_end = $date_end;
2070 $this->line->fk_multicurrency = $this->fk_multicurrency;
2071 $this->line->multicurrency_code = $this->multicurrency_code;
2072 $this->line->multicurrency_subprice = $pu_ht_devise;
2073 $this->line->multicurrency_total_ht = $multicurrency_total_ht;
2074 $this->line->multicurrency_total_tva = $multicurrency_total_tva;
2075 $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
2077 $this->line->subprice = $pu_ht;
2078 $this->line->price = $this->line->subprice;
2080 $this->line->remise_percent = $remise_percent;
2082 if (is_array($array_options) && count($array_options) > 0) {
2083 $this->line->array_options = $array_options;
2086 $result = $this->line->insert($notrigger);
2089 if (!empty($this->line->fk_parent_line)) {
2091 } elseif ($rang > 0 && $rang <= count($this->lines)) {
2092 $linecount = count($this->lines);
2093 for ($ii = $rang; $ii <= $linecount; $ii++) {
2099 $result = $this->
update_price(1,
'auto', 0, $this->thirdparty);
2101 $this->db->commit();
2102 return $this->line->id;
2104 $this->db->rollback();
2108 $this->error = $this->line->error;
2109 $this->errors = $this->line->errors;
2110 dol_syslog(get_class($this).
"::addline error=".$this->error, LOG_ERR);
2111 $this->db->rollback();
2136 public function dispatchProduct($user, $product, $qty, $entrepot, $price = 0, $comment =
'', $eatby =
'', $sellby =
'', $batch =
'', $fk_commandefourndet = 0, $notrigger = 0, $fk_reception = 0)
2138 global $conf, $langs;
2141 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2144 if ($entrepot <= 0) {
2145 $this->error =
'ErrorBadValueForParameterWarehouse';
2149 $this->error =
'ErrorBadValueForParameterQty';
2153 $dispatchstatus = 1;
2155 $dispatchstatus = 0;
2162 if (($this->
statut == self::STATUS_ORDERSENT || $this->
statut == self::STATUS_RECEIVED_PARTIALLY || $this->
statut == self::STATUS_RECEIVED_COMPLETELY)) {
2165 $sql =
"INSERT INTO ".$this->db->prefix().
"commande_fournisseur_dispatch";
2166 $sql .=
" (fk_commande, fk_product, qty, fk_entrepot, fk_user, datec, fk_commandefourndet, status, comment, eatby, sellby, batch, fk_reception) VALUES";
2167 $sql .=
" ('".$this->id.
"','".$product.
"','".$qty.
"',".($entrepot > 0 ?
"'".$entrepot.
"'" :
"null").
",'".$user->id.
"','".$this->db->idate($now).
"','".$fk_commandefourndet.
"', ".$dispatchstatus.
", '".$this->db->escape($comment).
"', ";
2168 $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");
2171 dol_syslog(get_class($this).
"::dispatchProduct", LOG_DEBUG);
2172 $resql = $this->db->query($sql);
2175 global $conf, $langs, $user;
2177 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_DISPATCH', $user);
2184 $this->error = $this->db->lasterror();
2189 if (!$error && $entrepot > 0 && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER')) {
2193 $mouv->origin = &$this;
2194 $mouv->setOrigin($this->element, $this->
id);
2197 if (
getDolGlobalString(
'SUPPLIER_ORDER_ALLOW_NEGATIVE_QTY_FOR_SUPPLIER_ORDER_RETURN') && $qty < 0) {
2198 $result = $mouv->livraison($user, $product, $entrepot, $qty*(-1), $price, $comment, $now, $eatby, $sellby, $batch, 0, $inventorycode);
2200 $result = $mouv->reception($user, $product, $entrepot, $qty, $price, $comment, $eatby, $sellby, $batch,
'', 0, $inventorycode);
2204 $this->error = $mouv->error;
2205 $this->errors = $mouv->errors;
2206 dol_syslog(get_class($this).
"::dispatchProduct ".$this->error.
" ".join(
',', $this->errors), LOG_ERR);
2213 $this->db->commit();
2216 $this->db->rollback();
2220 $this->error =
'BadStatusForObject';
2234 if ($this->
statut == 0) {
2237 if ($line->fetch($idline) <= 0) {
2243 foreach ($dispatchedLines as $dispatchLine) {
2244 if ($dispatchLine[
'orderlineid'] == $idline) {
2245 $this->error =
"LineAlreadyDispatched";
2246 $this->errors[] = $this->error;
2251 if ($line->delete($notrigger) > 0) {
2255 $this->error = $line->error;
2256 $this->errors = $line->errors;
2271 public function delete(
User $user, $notrigger = 0)
2273 global $langs, $conf;
2274 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2280 if (empty($notrigger)) {
2282 $result = $this->
call_trigger(
'ORDER_SUPPLIER_DELETE', $user);
2284 $this->errors[] =
'ErrorWhenRunningTrigger';
2285 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2286 $this->db->rollback();
2294 if (!empty($this->linkedObjects) && array_key_exists(
'reception', $this->linkedObjects)) {
2295 foreach ($this->linkedObjects[
'reception'] as $element) {
2296 if ($element->statut >= 0) {
2297 $this->errors[] = $langs->trans(
'ReceptionExist');
2304 $main = $this->db->prefix().
'commande_fournisseurdet';
2307 $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).
")";
2308 dol_syslog(__METHOD__.
" linked order lines", LOG_DEBUG);
2309 if (!$this->db->query($sql1)) {
2311 $this->error = $this->db->lasterror();
2312 $this->errors[] = $this->db->lasterror();
2317 $ef = $main.
"_extrafields";
2318 $sql =
"DELETE FROM ".$this->db->sanitize($ef).
" WHERE fk_object IN (SELECT rowid FROM ".$this->db->sanitize($main).
" WHERE fk_commande = ".((int) $this->
id).
")";
2319 dol_syslog(get_class($this).
"::delete extrafields lines", LOG_DEBUG);
2320 if (!$this->db->query($sql)) {
2321 $this->error = $this->db->lasterror();
2322 $this->errors[] = $this->db->lasterror();
2328 $sql =
"DELETE FROM ".$this->db->prefix().
"commande_fournisseurdet WHERE fk_commande = ".((int) $this->
id);
2329 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2330 if (!$this->db->query($sql)) {
2331 $this->error = $this->db->lasterror();
2332 $this->errors[] = $this->db->lasterror();
2338 $sql =
"DELETE FROM ".$this->db->prefix().
"commande_fournisseur WHERE rowid = ".((int) $this->
id);
2339 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2340 if ($resql = $this->db->query($sql)) {
2341 if ($this->db->affected_rows($resql) < 1) {
2342 $this->error = $this->db->lasterror();
2343 $this->errors[] = $this->db->lasterror();
2347 $this->error = $this->db->lasterror();
2348 $this->errors[] = $this->db->lasterror();
2357 $this->error =
'FailToDeleteExtraFields';
2358 $this->errors[] =
'FailToDeleteExtraFields';
2360 dol_syslog(get_class($this).
"::delete error -4 ".$this->error, LOG_ERR);
2367 $this->error =
'FailToDeleteObjectLinked';
2368 $this->errors[] =
'FailToDeleteObjectLinked';
2379 if ($conf->fournisseur->commande->dir_output) {
2380 $dir = $conf->fournisseur->commande->dir_output.
"/".$ref;
2381 $file = $dir.
"/".$ref.
".pdf";
2382 if (file_exists($file)) {
2384 $this->error =
'ErrorFailToDeleteFile';
2385 $this->errors[] =
'ErrorFailToDeleteFile';
2389 if (file_exists($dir)) {
2392 $this->error =
'ErrorFailToDeleteDir';
2393 $this->errors[] =
'ErrorFailToDeleteDir';
2401 dol_syslog(get_class($this).
"::delete $this->id by $user->id", LOG_DEBUG);
2402 $this->db->commit();
2405 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2406 $this->db->rollback();
2425 $sql =
"SELECT p.ref, p.label,";
2426 $sql .=
" e.rowid as warehouse_id, e.ref as entrepot,";
2427 $sql .=
" cfd.rowid as dispatchedlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status, cfd.fk_commandefourndet";
2428 $sql .=
" FROM ".$this->db->prefix().
"product as p,";
2429 $sql .=
" ".$this->db->prefix().
"commande_fournisseur_dispatch as cfd";
2430 $sql .=
" LEFT JOIN ".$this->db->prefix().
"entrepot as e ON cfd.fk_entrepot = e.rowid";
2431 $sql .=
" WHERE cfd.fk_commande = ".((int) $this->
id);
2432 $sql .=
" AND cfd.fk_product = p.rowid";
2434 $sql .=
" AND cfd.status = ".((int) $status);
2436 $sql .=
" ORDER BY cfd.rowid ASC";
2438 $resql = $this->db->query($sql);
2440 $num = $this->db->num_rows($resql);
2444 $objp = $this->db->fetch_object($resql);
2447 'id' => $objp->dispatchedlineid,
2448 'productid' => $objp->fk_product,
2449 'warehouseid' => $objp->warehouse_id,
2450 'qty' => $objp->qty,
2451 'orderlineid' => $objp->fk_commandefourndet
2458 dol_print_error($this->db,
'Failed to execute request to get dispatched lines');
2477 global $conf, $langs;
2484 $usercanreceive = 0;
2485 if (!isModEnabled(
'reception')) {
2486 $usercanreceive = $user->hasRight(
"fournisseur",
"commande",
"receptionner");
2488 $usercanreceive = $user->hasRight(
"reception",
"creer");
2491 if ($usercanreceive) {
2493 if ($type ==
'par') {
2495 } elseif ($type ==
'tot') {
2497 } elseif ($type ==
'nev') {
2499 } elseif ($type ==
'can') {
2503 dol_syslog(get_class($this).
"::Livraison Error -2", LOG_ERR);
2510 if (!$error && ($type ==
'tot')) {
2512 if (count($dispatchedlinearray) > 0) {
2515 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove';
2516 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove', LOG_DEBUG);
2519 if (!$error &&
getDolGlobalString(
'SUPPLIER_ORDER_USE_DISPATCH_STATUS_NEED_APPROVE') && ($type ==
'tot')) {
2521 if (count($dispatchedlinearray) > 0) {
2524 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied';
2525 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied', LOG_DEBUG);
2532 if (empty($error)) {
2535 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2536 $sql .=
" SET fk_statut = ".((int) $statut);
2537 $sql .=
" WHERE rowid = ".((int) $this->
id);
2538 $sql .=
" AND fk_statut IN (".self::STATUS_ORDERSENT.
",".self::STATUS_RECEIVED_PARTIALLY.
")";
2540 dol_syslog(get_class($this).
"::Livraison", LOG_DEBUG);
2541 $resql = $this->db->query($sql);
2544 $old_statut = $this->statut;
2546 $this->context[
'actionmsg2'] = $comment;
2549 $result_trigger = $this->
call_trigger(
'ORDER_SUPPLIER_RECEIVE', $user);
2550 if ($result_trigger < 0) {
2555 if (empty($error)) {
2556 $this->db->commit();
2558 $this->
statut = $old_statut;
2559 $this->db->rollback();
2560 $this->error = $this->db->lasterror();
2564 $this->db->rollback();
2565 $this->error = $this->db->lasterror();
2570 $this->error = $langs->trans(
'NotAuthorized');
2571 $this->errors[] = $langs->trans(
'NotAuthorized');
2572 dol_syslog(get_class($this).
"::Livraison Not Authorized");
2604 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
2609 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2610 $sql .=
" SET date_livraison = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2611 $sql .=
" WHERE rowid = ".((int) $this->
id);
2614 $resql = $this->db->query($sql);
2616 $this->errors[] = $this->db->error();
2621 $this->oldcopy = clone $this;
2622 $this->delivery_date = $delivery_date;
2625 if (!$notrigger && empty($error)) {
2627 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2635 $this->db->commit();
2638 foreach ($this->errors as $errmsg) {
2639 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2640 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2642 $this->db->rollback();
2662 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
2667 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2668 $sql .=
" SET fk_projet = ".($id_projet > 0 ? (int) $id_projet :
'null');
2669 $sql .=
" WHERE rowid = ".((int) $this->
id);
2672 $resql = $this->db->query($sql);
2674 $this->errors[] = $this->db->error();
2679 $this->oldcopy = clone $this;
2680 $this->fk_projet = $id_projet;
2681 $this->fk_project = $id_projet;
2684 if (!$notrigger && empty($error)) {
2686 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2694 $this->db->commit();
2697 foreach ($this->errors as $errmsg) {
2698 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2699 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2701 $this->db->rollback();
2719 $comclient =
new Commande($this->db);
2720 $comclient->fetch($comclientid);
2724 $this->lines = array();
2726 $num = count($comclient->lines);
2727 for ($i = 0; $i < $num; $i++) {
2728 $prod =
new Product($this->db);
2731 if ($prod->fetch($comclient->lines[$i]->fk_product) > 0) {
2732 $label = $prod->label;
2736 $sql =
"INSERT INTO ".$this->db->prefix().
"commande_fournisseurdet";
2737 $sql .=
" (fk_commande, label, description, fk_product, price, qty, tva_tx, localtax1_tx, localtax2_tx, remise_percent, subprice, remise, ref)";
2738 $sql .=
" VALUES (".((int) $idc).
", '".$this->db->escape($label).
"', '".$this->db->escape($comclient->lines[$i]->desc).
"'";
2739 $sql .=
",".$comclient->lines[$i]->fk_product.
", ".
price2num($comclient->lines[$i]->price,
'MU');
2740 $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);
2741 $sql .=
", '".price2num($comclient->lines[$i]->subprice,
'MT').
"','0', '".$this->db->escape($ref).
"');";
2742 if ($this->db->query($sql)) {
2759 global $conf, $langs;
2764 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur';
2765 $sql .=
" SET fk_statut = ".$status;
2766 $sql .=
" WHERE rowid = ".((int) $this->
id);
2768 dol_syslog(get_class($this).
"::setStatus", LOG_DEBUG);
2769 $resql = $this->db->query($sql);
2772 $triggerName = array();
2773 $triggerName[0] =
'DRAFT';
2774 $triggerName[1] =
'VALIDATED';
2775 $triggerName[2] =
'APPROVED';
2776 $triggerName[3] =
'ORDERED';
2777 $triggerName[4] =
'RECEIVED_PARTIALLY';
2778 $triggerName[5] =
'RECEIVED_COMPLETELY';
2779 $triggerName[6] =
'CANCELED';
2780 $triggerName[7] =
'CANCELED';
2781 $triggerName[9] =
'REFUSED';
2784 $result = $this->
call_trigger(
"ORDER_SUPPLIER_STATUS_".$triggerName[$status], $user);
2791 $this->error = $this->db->lasterror();
2792 dol_syslog(get_class($this).
"::setStatus ".$this->error);
2797 $this->db->commit();
2800 $this->db->rollback();
2828 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 =
'')
2830 global $mysoc, $conf, $langs;
2831 dol_syslog(get_class($this).
"::updateline $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $type, $fk_unit");
2832 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2836 if ($this->
statut == self::STATUS_DRAFT) {
2841 if (empty($info_bits)) {
2844 if (empty($txtva)) {
2847 if (empty($txlocaltax1)) {
2850 if (empty($txlocaltax2)) {
2853 if (empty($remise_percent)) {
2854 $remise_percent = 0;
2857 $remise_percent =
price2num($remise_percent);
2863 $pu_ht_devise =
price2num($pu_ht_devise);
2864 if (!preg_match(
'/\((.*)\)/', $txtva)) {
2874 if ($date_start && $date_end && $date_start > $date_end) {
2875 $langs->load(
"errors");
2876 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
2892 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
2893 $vat_src_code = $reg[1];
2894 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
2897 $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);
2898 $total_ht = $tabprice[0];
2899 $total_tva = $tabprice[1];
2900 $total_ttc = $tabprice[2];
2901 $total_localtax1 = $tabprice[9];
2902 $total_localtax2 = $tabprice[10];
2903 $pu_ht = $tabprice[3];
2904 $pu_tva = $tabprice[4];
2905 $pu_ttc = $tabprice[5];
2908 $multicurrency_total_ht = $tabprice[16];
2909 $multicurrency_total_tva = $tabprice[17];
2910 $multicurrency_total_ttc = $tabprice[18];
2911 $pu_ht_devise = $tabprice[19];
2913 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2914 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2918 $this->line->fetch($rowid);
2920 $oldline = clone $this->line;
2921 $this->line->oldline = $oldline;
2923 $this->line->context = $this->context;
2925 $this->line->fk_commande = $this->id;
2927 $this->line->desc = $desc;
2931 if ($qty < $this->line->packaging) {
2932 $qty = $this->line->packaging;
2934 if (!empty($this->line->packaging) && ($qty % $this->line->packaging) > 0) {
2935 $coeff = intval($qty / $this->line->packaging) + 1;
2936 $qty = $this->line->packaging * $coeff;
2937 setEventMessage($langs->trans(
'QtyRecalculatedWithPackaging'),
'mesgs');
2942 $this->line->qty = $qty;
2943 $this->line->ref_supplier = $ref_supplier;
2945 $this->line->vat_src_code = $vat_src_code;
2946 $this->line->tva_tx = $txtva;
2947 $this->line->localtax1_tx = $txlocaltax1;
2948 $this->line->localtax2_tx = $txlocaltax2;
2949 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2950 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2951 $this->line->remise_percent = $remise_percent;
2952 $this->line->subprice = $pu_ht;
2953 $this->line->info_bits = $info_bits;
2954 $this->line->total_ht = $total_ht;
2955 $this->line->total_tva = $total_tva;
2956 $this->line->total_localtax1 = $total_localtax1;
2957 $this->line->total_localtax2 = $total_localtax2;
2958 $this->line->total_ttc = $total_ttc;
2959 $this->line->product_type = $type;
2960 $this->line->special_code = $oldline->special_code;
2961 $this->line->rang = $oldline->rang;
2962 $this->line->origin = $this->origin;
2963 $this->line->fk_unit = $fk_unit;
2965 $this->line->date_start = $date_start;
2966 $this->line->date_end = $date_end;
2969 $this->line->fk_multicurrency = $this->fk_multicurrency;
2970 $this->line->multicurrency_code = $this->multicurrency_code;
2971 $this->line->multicurrency_subprice = $pu_ht_devise;
2972 $this->line->multicurrency_total_ht = $multicurrency_total_ht;
2973 $this->line->multicurrency_total_tva = $multicurrency_total_tva;
2974 $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
2976 $this->line->subprice = $pu_ht;
2977 $this->line->price = $this->line->subprice;
2979 $this->line->remise_percent = $remise_percent;
2981 if (is_array($array_options) && count($array_options) > 0) {
2983 foreach ($array_options as $key => $value) {
2984 $this->line->array_options[$key] = $array_options[$key];
2988 $result = $this->line->update($notrigger);
2994 $this->db->commit();
2997 $this->errors[] = $this->line->error;
2998 $this->errors = array_merge($this->errors, $this->line->errors);
2999 $this->error = $this->db->lasterror();
3000 $this->db->rollback();
3004 $this->error =
"Order status makes operation forbidden";
3005 dol_syslog(get_class($this).
"::updateline ".$this->error, LOG_ERR);
3020 global $user, $langs, $conf;
3022 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
3024 dol_syslog(get_class($this).
"::initAsSpecimen");
3031 $sql =
"SELECT rowid";
3032 $sql .=
" FROM ".$this->db->prefix().
"product";
3033 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
3034 $sql .= $this->db->order(
"rowid",
"ASC");
3035 $sql .= $this->db->plimit(1);
3036 $resql = $this->db->query($sql);
3037 if ($resql && $this->db->num_rows($resql)) {
3038 $obj = $this->db->fetch_object($resql);
3039 $prodid = $obj->rowid;
3044 $this->
ref =
'SPECIMEN';
3045 $this->specimen = 1;
3048 $this->date_commande = $now;
3049 $this->date_lim_reglement = $this->date + 3600 * 24 * 30;
3050 $this->cond_reglement_code =
'RECEP';
3051 $this->mode_reglement_code =
'CHQ';
3053 $this->note_public =
'This is a comment (public)';
3054 $this->note_private =
'This is a comment (private)';
3056 $this->multicurrency_tx = 1;
3057 $this->multicurrency_code = $conf->currency;
3064 while ($xnbp < $nbp) {
3066 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
3068 $line->subprice = 100;
3069 $line->tva_tx = 19.6;
3070 $line->localtax1_tx = 0;
3071 $line->localtax2_tx = 0;
3073 $line->total_ht = 50;
3074 $line->total_ttc = 59.8;
3075 $line->total_tva = 9.8;
3076 $line->remise_percent = 50;
3078 $line->total_ht = 100;
3079 $line->total_ttc = 119.6;
3080 $line->total_tva = 19.6;
3081 $line->remise_percent = 00;
3083 $line->fk_product = $prodid;
3085 $this->lines[$xnbp] = $line;
3087 $this->total_ht += $line->total_ht;
3088 $this->total_tva += $line->total_tva;
3089 $this->total_ttc += $line->total_ttc;
3103 $sql =
'SELECT c.rowid, date_creation as datec, tms as datem, date_valid as date_validation, date_approve as datea, date_approve2 as datea2,';
3104 $sql .=
' fk_user_author, fk_user_modif, fk_user_valid, fk_user_approve, fk_user_approve2';
3105 $sql .=
' FROM '.$this->db->prefix().
'commande_fournisseur as c';
3106 $sql .=
' WHERE c.rowid = '.((int) $id);
3108 $result = $this->db->query($sql);
3110 if ($this->db->num_rows($result)) {
3111 $obj = $this->db->fetch_object($result);
3113 $this->
id = $obj->rowid;
3115 $this->user_creation_id = $obj->fk_user_author;
3116 $this->user_validation_id = $obj->fk_user_valid;
3117 $this->user_modification_id = $obj->fk_user_modif;
3118 $this->user_approve_id = $obj->fk_user_approve;
3119 $this->user_approve_id2 = $obj->fk_user_approve2;
3121 $this->date_creation = $this->db->jdate($obj->datec);
3122 $this->date_modification = $this->db->jdate($obj->datem);
3123 $this->date_approve = $this->db->jdate($obj->datea);
3124 $this->date_approve2 = $this->db->jdate($obj->datea2);
3125 $this->date_validation = $this->db->jdate($obj->date_validation);
3127 $this->db->free($result);
3142 global $conf, $user;
3144 $this->nb = array();
3147 $sql =
"SELECT count(co.rowid) as nb";
3148 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as co";
3149 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe as s ON co.fk_soc = s.rowid";
3150 if (!$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3151 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
3152 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
3155 $sql .=
" ".$clause.
" co.entity IN (".
getEntity(
'supplier_order').
")";
3157 $resql = $this->db->query($sql);
3159 while ($obj = $this->db->fetch_object($resql)) {
3160 $this->nb[
"supplier_orders"] = $obj->nb;
3162 $this->db->free($resql);
3166 $this->error = $this->db->error();
3182 global $conf, $langs;
3184 $sql =
"SELECT c.rowid, c.date_creation as datec, c.date_commande, c.fk_statut, c.date_livraison as delivery_date, c.total_ht";
3185 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as c";
3186 if (!$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3187 $sql .=
" JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
3189 $sql .=
" WHERE c.entity = ".$conf->entity;
3190 if ($mode ===
'awaiting') {
3191 $sql .=
" AND c.fk_statut IN (".self::STATUS_ORDERSENT.
", ".self::STATUS_RECEIVED_PARTIALLY.
")";
3193 $sql .=
" AND c.fk_statut IN (".self::STATUS_VALIDATED.
", ".self::STATUS_ACCEPTED.
")";
3196 $sql .=
" AND c.fk_soc = ".((int) $user->socid);
3199 $resql = $this->db->query($sql);
3204 $response->warning_delay = $conf->commande->fournisseur->warning_delay / 60 / 60 / 24;
3205 $response->label = $langs->trans(
"SuppliersOrdersToProcess");
3206 $response->labelShort = $langs->trans(
"Opened");
3207 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=1,2&mainmenu=commercial&leftmenu=orders_suppliers';
3210 if ($mode ===
'awaiting') {
3211 $response->label = $langs->trans(
"SuppliersOrdersAwaitingReception");
3212 $response->labelShort = $langs->trans(
"AwaitingReception");
3213 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=3,4&mainmenu=commercial&leftmenu=orders_suppliers';
3216 while ($obj = $this->db->fetch_object($resql)) {
3217 $commandestatic->delivery_date = $this->db->jdate($obj->delivery_date);
3218 $commandestatic->date_commande = $this->db->jdate($obj->date_commande);
3219 $commandestatic->statut = $obj->fk_statut;
3221 $response->nbtodo++;
3222 $response->total += $obj->total_ht;
3224 if ($commandestatic->hasDelay()) {
3225 $response->nbtodolate++;
3231 $this->error = $this->db->error();
3246 if ($this->methode_commande_id > 0) {
3247 $sql =
"SELECT rowid, code, libelle as label";
3248 $sql .=
" FROM ".$this->db->prefix().
'c_input_method';
3249 $sql .=
" WHERE active=1 AND rowid = ".((int) $this->methode_commande_id);
3251 $resql = $this->db->query($sql);
3253 if ($this->db->num_rows($resql)) {
3254 $obj = $this->db->fetch_object($resql);
3256 $string = $langs->trans($obj->code);
3257 if ($string == $obj->code) {
3258 $string = $obj->label !=
'-' ? $obj->label :
'';
3281 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3283 global $conf, $langs;
3288 if (!empty($this->model_pdf)) {
3289 $modele = $this->model_pdf;
3295 if (empty($modele)) {
3298 $langs->load(
"suppliers");
3299 $outputlangs->load(
"products");
3301 $modelpath =
"core/modules/supplier_order/doc/";
3302 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3315 if (empty($this->lines)) {
3322 foreach ($this->lines as $line) {
3323 if ($line->fk_product > 0) {
3324 $idp = $obj->find_min_price_product_fournisseur($line->fk_product, $line->qty);
3327 if ($obj->delivery_time_days > $nb) {
3328 $nb = $obj->delivery_time_days;
3337 return $nb.
' '.$langs->trans(
'Days');
3350 return $user->hasRight(
"fournisseur",
"commande");
3365 'commande_fournisseur'
3382 'commande_fournisseurdet'
3399 if ($this->
statut == self::STATUS_ORDERSENT || $this->
statut == self::STATUS_RECEIVED_PARTIALLY) {
3401 if (!empty($this->delivery_date)) {
3402 $date_to_test = $this->delivery_date;
3403 return $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay);
3411 $date_to_test = $this->date_commande;
3413 return ($this->
statut > 0 && $this->
statut < 5) && $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay);
3426 global $conf, $langs;
3430 if ($this->
statut == self::STATUS_ORDERSENT || $this->
statut == self::STATUS_RECEIVED_PARTIALLY) {
3431 if (!empty($this->delivery_date)) {
3432 $text = $langs->trans(
"DeliveryDate").
' '.
dol_print_date($this->delivery_date,
'day');
3434 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3437 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3440 $text .=
' '.($conf->commande->fournisseur->warning_delay > 0 ?
'+' :
'-').
' '.round(abs($conf->commande->fournisseur->warning_delay) / 3600 / 24, 1).
' '.$langs->trans(
"days").
' < '.$langs->trans(
"Today");
3457 global $conf, $langs;
3459 if (isModEnabled(
"supplier_order")) {
3460 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
3462 $qtydelivered = array();
3463 $qtywished = array();
3466 $filter = array(
't.fk_commande'=>$this->
id);
3468 $filter[
't.status'] = 1;
3471 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
3473 $this->error = $supplierorderdispatch->error;
3474 $this->errors = $supplierorderdispatch->errors;
3477 if (is_array($supplierorderdispatch->lines) && count($supplierorderdispatch->lines) > 0) {
3478 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
3482 foreach ($supplierorderdispatch->lines as $line) {
3483 $qtydelivered[$line->fk_product] += $line->qty;
3485 foreach ($this->lines as $line) {
3490 $qtywished[$line->fk_product] += $line->qty;
3494 $diff_array = array_diff_assoc($qtydelivered, $qtywished);
3495 $keysinwishednotindelivered = array_diff(array_keys($qtywished), array_keys($qtydelivered));
3496 $keysindeliverednotinwished = array_diff(array_keys($qtydelivered), array_keys($qtywished));
3504 if (count($diff_array) == 0 && count($keysinwishednotindelivered) == 0 && count($keysindeliverednotinwished) == 0) {
3505 if ($closeopenorder) {
3507 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3515 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3526 if (count($diff_array) > 0) {
3530 foreach ($diff_array as $key => $value) {
3532 if ($qtydelivered[$key] >= $qtywished[$key]) {
3539 if ($close == count($diff_array)) {
3541 if ($closeopenorder) {
3542 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3549 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3557 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3565 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3587 $this->receptions = array();
3589 dol_syslog(get_class($this).
"::loadReceptions", LOG_DEBUG);
3591 $sql =
'SELECT cd.rowid, cd.fk_product,';
3592 $sql .=
' sum(cfd.qty) as qty';
3593 $sql .=
' FROM '.$this->db->prefix().
'commande_fournisseur_dispatch as cfd,';
3594 if ($filtre_statut >= 0) {
3595 $sql .=
' '.$this->db->prefix().
'reception as e,';
3597 $sql .=
' '.$this->db->prefix().
'commande_fournisseurdet as cd';
3599 if ($filtre_statut >= 0) {
3600 $sql .=
' cfd.fk_reception = e.rowid AND';
3602 $sql .=
' cfd.fk_commandefourndet = cd.rowid';
3603 $sql .=
' AND cd.fk_commande ='.((int) $this->
id);
3604 if (isset($this->fk_product) && !empty($this->fk_product) > 0) {
3605 $sql .=
' AND cd.fk_product = '.((int) $this->fk_product);
3607 if ($filtre_statut >= 0) {
3608 $sql .=
' AND e.fk_statut >= '.((int) $filtre_statut);
3610 $sql .=
' GROUP BY cd.rowid, cd.fk_product';
3612 $resql = $this->db->query($sql);
3614 $num = $this->db->num_rows($resql);
3617 $obj = $this->db->fetch_object($resql);
3618 empty($this->receptions[$obj->rowid]) ? $this->receptions[$obj->rowid] = $obj->qty : $this->receptions[$obj->rowid] += $obj->qty;
3621 $this->db->free($resql);
3625 $this->error = $this->db->lasterror();
3641 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3643 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3644 $return .=
'<div class="info-box info-box-sm">';
3645 $return .=
'<span class="info-box-icon bg-infobox-action">';
3647 $return .=
'</span>';
3648 $return .=
'<div class="info-box-content">';
3649 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
3650 if ($selected >= 0) {
3651 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3653 if (property_exists($this,
'socid') || property_exists($this,
'total_tva')) {
3654 $return .=
'<br><span class="info-box-label amount">'.$this->socid.
'</span>';
3656 if (property_exists($this,
'billed')) {
3657 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Billed").
' : </span><span class="info-box-label">'.
yn($this->billed).
'</span>';
3659 if (method_exists($this,
'getLibStatut')) {
3660 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
3662 $return .=
'</div>';
3663 $return .=
'</div>';
3664 $return .=
'</div>';
3679 public $element =
'commande_fournisseurdet';
3684 public $table_element =
'commande_fournisseurdet';
3692 public $fk_commande;
3698 public $fk_parent_line;
3706 public $special_code = 0;
3716 public $fk_fournprice;
3726 public $ref_supplier;
3758 $sql =
'SELECT cd.rowid, cd.fk_commande, cd.fk_product, cd.product_type, cd.description, cd.qty, cd.tva_tx, cd.special_code,';
3759 $sql .=
' cd.localtax1_tx, cd.localtax2_tx, cd.localtax1_type, cd.localtax2_type, cd.ref as ref_supplier,';
3760 $sql .=
' cd.remise, cd.remise_percent, cd.subprice,';
3761 $sql .=
' cd.info_bits, cd.total_ht, cd.total_tva, cd.total_ttc,';
3762 $sql .=
' cd.total_localtax1, cd.total_localtax2,';
3763 $sql .=
' p.ref as product_ref, p.label as product_label, p.description as product_desc,';
3764 $sql .=
' cd.date_start, cd.date_end, cd.fk_unit,';
3765 $sql .=
' cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc,';
3766 $sql .=
' c.fk_soc as socid';
3767 $sql .=
' FROM '.$this->db->prefix().
'commande_fournisseur as c, '.$this->db->prefix().
'commande_fournisseurdet as cd';
3768 $sql .=
' LEFT JOIN '.$this->db->prefix().
'product as p ON cd.fk_product = p.rowid';
3769 $sql .=
' WHERE cd.fk_commande = c.rowid AND cd.rowid = '.((int) $rowid);
3771 $result = $this->db->query($sql);
3773 $objp = $this->db->fetch_object($result);
3775 if (!empty($objp)) {
3776 $this->
rowid = $objp->rowid;
3777 $this->
id = $objp->rowid;
3778 $this->fk_commande = $objp->fk_commande;
3779 $this->desc = $objp->description;
3780 $this->qty = $objp->qty;
3781 $this->ref_fourn = $objp->ref_supplier;
3782 $this->ref_supplier = $objp->ref_supplier;
3783 $this->subprice = $objp->subprice;
3784 $this->tva_tx = $objp->tva_tx;
3785 $this->localtax1_tx = $objp->localtax1_tx;
3786 $this->localtax2_tx = $objp->localtax2_tx;
3787 $this->localtax1_type = $objp->localtax1_type;
3788 $this->localtax2_type = $objp->localtax2_type;
3789 $this->remise = $objp->remise;
3790 $this->remise_percent = $objp->remise_percent;
3791 $this->fk_product = $objp->fk_product;
3792 $this->info_bits = $objp->info_bits;
3793 $this->total_ht = $objp->total_ht;
3794 $this->total_tva = $objp->total_tva;
3795 $this->total_localtax1 = $objp->total_localtax1;
3796 $this->total_localtax2 = $objp->total_localtax2;
3797 $this->total_ttc = $objp->total_ttc;
3798 $this->product_type = $objp->product_type;
3799 $this->special_code = $objp->special_code;
3801 $this->
ref = $objp->product_ref;
3803 $this->product_ref = $objp->product_ref;
3804 $this->product_label = $objp->product_label;
3805 $this->product_desc = $objp->product_desc;
3812 $sqlsearchpackage =
'SELECT rowid, packaging FROM '.$this->db->prefix().
"product_fournisseur_price";
3813 $sqlsearchpackage .=
' WHERE entity IN ('.getEntity(
'product_fournisseur_price').
")";
3814 $sqlsearchpackage .=
" AND fk_product = ".((int) $objp->fk_product);
3815 $sqlsearchpackage .=
" AND ref_fourn = '".$this->db->escape($objp->ref_supplier).
"'";
3816 $sqlsearchpackage .=
" AND quantity <= ".((float) $objp->qty);
3817 $sqlsearchpackage .=
" AND (packaging IS NULL OR packaging = 0 OR packaging <= ".((float) $objp->qty).
")";
3818 $sqlsearchpackage .=
" AND fk_soc = ".((int) $objp->socid);
3819 $sqlsearchpackage .=
" ORDER BY packaging ASC";
3820 $sqlsearchpackage .=
" LIMIT 1";
3822 $resqlsearchpackage = $this->db->query($sqlsearchpackage);
3823 if ($resqlsearchpackage) {
3824 $objsearchpackage = $this->db->fetch_object($resqlsearchpackage);
3825 if ($objsearchpackage) {
3826 $this->fk_fournprice = $objsearchpackage->rowid;
3827 $this->packaging = $objsearchpackage->packaging;
3830 $this->error = $this->db->lasterror();
3835 $this->date_start = $this->db->jdate($objp->date_start);
3836 $this->date_end = $this->db->jdate($objp->date_end);
3837 $this->fk_unit = $objp->fk_unit;
3839 $this->multicurrency_subprice = $objp->multicurrency_subprice;
3840 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
3841 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
3842 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
3846 $this->db->free($result);
3849 $this->error =
'Supplier order line with id='.$rowid.
' not found';
3850 dol_syslog(get_class($this).
"::fetch Error ".$this->error, LOG_ERR);
3867 global $conf, $user;
3871 dol_syslog(get_class($this).
"::insert rang=".$this->rang);
3874 if (empty($this->tva_tx)) {
3877 if (empty($this->localtax1_tx)) {
3878 $this->localtax1_tx = 0;
3880 if (empty($this->localtax2_tx)) {
3881 $this->localtax2_tx = 0;
3883 if (empty($this->localtax1_type)) {
3884 $this->localtax1_type =
'0';
3886 if (empty($this->localtax2_type)) {
3887 $this->localtax2_type =
'0';
3889 if (empty($this->total_localtax1)) {
3890 $this->total_localtax1 = 0;
3892 if (empty($this->total_localtax2)) {
3893 $this->total_localtax2 = 0;
3895 if (empty($this->rang)) {
3898 if (empty($this->remise_percent)) {
3899 $this->remise_percent = 0;
3901 if (empty($this->info_bits)) {
3902 $this->info_bits = 0;
3904 if (empty($this->special_code)) {
3905 $this->special_code = 0;
3907 if (empty($this->fk_parent_line)) {
3908 $this->fk_parent_line = 0;
3910 if (empty($this->pa_ht)) {
3915 if (!empty($this->multicurrency_code)) {
3918 if (empty($this->fk_multicurrency)) {
3919 $this->multicurrency_code = $conf->currency;
3920 $this->fk_multicurrency = 0;
3921 $this->multicurrency_tx = 1;
3925 if ($this->product_type < 0) {
3932 $sql =
'INSERT INTO '.$this->db->prefix().$this->table_element;
3933 $sql .=
" (fk_commande, label, description, date_start, date_end,";
3934 $sql .=
" fk_product, product_type, special_code, rang,";
3935 $sql .=
" qty, vat_src_code, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, remise_percent, subprice, ref,";
3936 $sql .=
" total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_unit,";
3937 $sql .=
" fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc,";
3938 $sql .=
" fk_parent_line)";
3939 $sql .=
" VALUES (".$this->fk_commande.
", '".$this->db->escape($this->label).
"','".$this->db->escape($this->desc).
"',";
3940 $sql .=
" ".($this->date_start ?
"'".$this->db->idate($this->date_start).
"'" :
"null").
",";
3941 $sql .=
" ".($this->date_end ?
"'".$this->db->idate($this->date_end).
"'" :
"null").
",";
3942 if ($this->fk_product) {
3943 $sql .= $this->fk_product.
",";
3947 $sql .=
"'".$this->db->escape($this->product_type).
"',";
3948 $sql .=
"'".$this->db->escape($this->special_code).
"',";
3949 $sql .=
"'".$this->db->escape($this->rang).
"',";
3950 $sql .=
"'".$this->db->escape($this->qty).
"', ";
3951 $sql .=
" ".(empty($this->vat_src_code) ?
"''" :
"'".$this->db->escape($this->vat_src_code).
"'").
",";
3952 $sql .=
" ".price2num($this->tva_tx).
", ";
3953 $sql .=
" ".price2num($this->localtax1_tx).
",";
3954 $sql .=
" ".price2num($this->localtax2_tx).
",";
3955 $sql .=
" '".$this->db->escape($this->localtax1_type).
"',";
3956 $sql .=
" '".$this->db->escape($this->localtax2_type).
"',";
3957 $sql .=
" ".((float) $this->remise_percent).
", ".
price2num($this->subprice,
'MU').
", '".$this->db->escape($this->ref_supplier).
"',";
3958 $sql .=
" ".price2num($this->total_ht).
",";
3959 $sql .=
" ".price2num($this->total_tva).
",";
3960 $sql .=
" ".price2num($this->total_localtax1).
",";
3961 $sql .=
" ".price2num($this->total_localtax2).
",";
3962 $sql .=
" ".price2num($this->total_ttc).
",";
3963 $sql .= ($this->fk_unit ?
"'".$this->db->escape($this->fk_unit).
"'" :
"null");
3964 $sql .=
", ".($this->fk_multicurrency ? ((int) $this->fk_multicurrency) :
"null");
3965 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
3966 $sql .=
", ".($this->multicurrency_subprice ?
price2num($this->multicurrency_subprice) :
'0');
3967 $sql .=
", ".($this->multicurrency_total_ht ?
price2num($this->multicurrency_total_ht) :
'0');
3968 $sql .=
", ".($this->multicurrency_total_tva ?
price2num($this->multicurrency_total_tva) :
'0');
3969 $sql .=
", ".($this->multicurrency_total_ttc ?
price2num($this->multicurrency_total_ttc) :
'0');
3970 $sql .=
", ".((!empty($this->fk_parent_line) && $this->fk_parent_line > 0) ? $this->fk_parent_line :
'null');
3973 dol_syslog(get_class($this).
"::insert", LOG_DEBUG);
3974 $resql = $this->db->query($sql);
3976 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
3977 $this->
rowid = $this->id;
3986 if (!$error && !$notrigger) {
3988 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_CREATE', $user);
3996 $this->db->commit();
4000 foreach ($this->errors as $errmsg) {
4001 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
4002 $this->errors[] = ($this->errors ?
', '.$errmsg : $errmsg);
4004 $this->db->rollback();
4007 $this->errors[] = $this->db->error();
4008 $this->db->rollback();
4027 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
4028 $sql .=
" description='".$this->db->escape($this->desc).
"'";
4029 $sql .=
", ref='".$this->db->escape($this->ref_supplier).
"'";
4030 $sql .=
", subprice='".price2num($this->subprice).
"'";
4032 $sql .=
", remise_percent='".price2num($this->remise_percent).
"'";
4034 $sql .=
", vat_src_code = '".(empty($this->vat_src_code) ?
'' : $this->vat_src_code).
"'";
4035 $sql .=
", tva_tx='".price2num($this->tva_tx).
"'";
4036 $sql .=
", localtax1_tx='".price2num($this->localtax1_tx).
"'";
4037 $sql .=
", localtax2_tx='".price2num($this->localtax2_tx).
"'";
4038 $sql .=
", localtax1_type='".$this->db->escape($this->localtax1_type).
"'";
4039 $sql .=
", localtax2_type='".$this->db->escape($this->localtax2_type).
"'";
4040 $sql .=
", qty='".price2num($this->qty).
"'";
4041 $sql .=
", date_start=".(!empty($this->date_start) ?
"'".$this->db->idate($this->date_start).
"'" :
"null");
4042 $sql .=
", date_end=".(!empty($this->date_end) ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
4043 $sql .=
", info_bits='".$this->db->escape($this->info_bits).
"'";
4044 $sql .=
", total_ht='".price2num($this->total_ht).
"'";
4045 $sql .=
", total_tva='".price2num($this->total_tva).
"'";
4046 $sql .=
", total_localtax1='".price2num($this->total_localtax1).
"'";
4047 $sql .=
", total_localtax2='".price2num($this->total_localtax2).
"'";
4048 $sql .=
", total_ttc='".price2num($this->total_ttc).
"'";
4049 $sql .=
", product_type=".$this->product_type;
4050 $sql .=
", special_code=".(!empty($this->special_code) ? $this->special_code : 0);
4051 $sql .= ($this->fk_unit ?
", fk_unit='".$this->db->escape($this->fk_unit).
"'" :
", fk_unit=null");
4054 $sql .=
", multicurrency_subprice=".price2num($this->multicurrency_subprice);
4055 $sql .=
", multicurrency_total_ht=".price2num($this->multicurrency_total_ht);
4056 $sql .=
", multicurrency_total_tva=".price2num($this->multicurrency_total_tva);
4057 $sql .=
", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc);
4059 $sql .=
" WHERE rowid = ".((int) $this->
id);
4061 dol_syslog(get_class($this).
"::updateline", LOG_DEBUG);
4062 $resql = $this->db->query($sql);
4071 if (!$error && !$notrigger) {
4073 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_MODIFY', $user);
4075 $this->db->rollback();
4082 $this->db->commit();
4085 $this->db->rollback();
4089 $this->error = $this->db->lasterror();
4090 $this->db->rollback();
4101 public function delete($notrigger = 0)
4112 $this->db->rollback();
4116 $sql1 =
'UPDATE '.$this->db->prefix().
"commandedet SET fk_commandefourndet = NULL WHERE fk_commandefourndet=".((int) $this->
id);
4117 $resql = $this->db->query($sql1);
4119 $this->db->rollback();
4123 $sql2 =
'DELETE FROM '.$this->db->prefix().
"commande_fournisseurdet WHERE rowid=".((int) $this->
id);
4126 $resql = $this->db->query($sql2);
4130 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_DELETE', $user);
4138 $this->db->commit();
4142 foreach ($this->errors as $errmsg) {
4143 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
4144 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
4146 $this->db->rollback();
4149 $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.