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 .=
', i.libelle as label_incoterms';
395 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as c";
396 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_payment_term as cr ON c.fk_cond_reglement = cr.rowid";
397 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_paiement as p ON c.fk_mode_reglement = p.id";
398 $sql .=
" LEFT JOIN ".$this->db->prefix().
"c_input_method as cm ON cm.rowid = c.fk_input_method";
399 $sql .=
' LEFT JOIN '.$this->db->prefix().
'c_incoterms as i ON c.fk_incoterms = i.rowid';
402 $sql .=
" WHERE c.entity IN (".getEntity(
'supplier_order').
")";
404 $sql .=
" WHERE c.rowid=".((int) $id);
408 $sql .=
" AND c.ref='".$this->db->escape($ref).
"'";
411 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
412 $resql = $this->db->query($sql);
414 $obj = $this->db->fetch_object($resql);
416 $this->error =
'Bill with id '.$id.
' not found';
417 dol_syslog(get_class($this).
'::fetch '.$this->error);
421 $this->
id = $obj->rowid;
422 $this->entity = $obj->entity;
424 $this->
ref = $obj->ref;
425 $this->ref_supplier = $obj->ref_supplier;
426 $this->socid = $obj->fk_soc;
427 $this->fourn_id = $obj->fk_soc;
428 $this->
statut = $obj->status;
429 $this->
status = $obj->status;
430 $this->billed = $obj->billed;
431 $this->user_author_id = $obj->user_author_id;
432 $this->user_validation_id = $obj->user_validation_id;
433 $this->user_approve_id = $obj->user_approve_id;
434 $this->user_approve_id2 = $obj->user_approve_id2;
435 $this->total_ht = $obj->total_ht;
436 $this->total_tva = $obj->total_tva;
437 $this->total_localtax1 = $obj->localtax1;
438 $this->total_localtax2 = $obj->localtax2;
439 $this->total_ttc = $obj->total_ttc;
440 $this->date_creation = $this->db->jdate($obj->date_creation);
441 $this->date_valid = $this->db->jdate($obj->date_valid);
442 $this->date_approve = $this->db->jdate($obj->date_approve);
443 $this->date_approve2 = $this->db->jdate($obj->date_approve2);
444 $this->date_commande = $this->db->jdate($obj->date_commande);
445 if (isset($obj->date_commande)) {
446 $this->date = $this->date_commande;
448 $this->date = $this->date_creation;
450 $this->delivery_date = $this->db->jdate($obj->delivery_date);
451 $this->remise_percent = $obj->remise_percent;
452 $this->methode_commande_id = $obj->fk_input_method;
453 $this->methode_commande = $obj->methode_commande;
455 $this->source = $obj->source;
456 $this->fk_project = $obj->fk_project;
457 $this->cond_reglement_id = $obj->fk_cond_reglement;
458 $this->cond_reglement_code = $obj->cond_reglement_code;
459 $this->cond_reglement = $obj->cond_reglement_label;
460 $this->cond_reglement_label = $obj->cond_reglement_label;
461 $this->cond_reglement_doc = $obj->cond_reglement_doc;
462 $this->fk_account = $obj->fk_account;
463 $this->mode_reglement_id = $obj->fk_mode_reglement;
464 $this->mode_reglement_code = $obj->mode_reglement_code;
465 $this->mode_reglement = $obj->mode_reglement_libelle;
466 $this->note = $obj->note_private;
467 $this->note_private = $obj->note_private;
468 $this->note_public = $obj->note_public;
469 $this->model_pdf = $obj->model_pdf;
472 $this->fk_incoterms = $obj->fk_incoterms;
473 $this->location_incoterms = $obj->location_incoterms;
474 $this->label_incoterms = $obj->label_incoterms;
477 $this->fk_multicurrency = $obj->fk_multicurrency;
478 $this->multicurrency_code = $obj->multicurrency_code;
479 $this->multicurrency_tx = $obj->multicurrency_tx;
480 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
481 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
482 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
484 $this->extraparams = isset($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
486 $this->db->free($resql);
501 $this->error = $this->db->error().
" sql=".$sql;
518 $this->lines = array();
520 $sql =
"SELECT l.rowid, l.fk_commande, l.ref as ref_supplier, l.fk_product, l.product_type, l.label, l.description, l.qty,";
521 $sql .=
" l.vat_src_code, l.tva_tx, l.remise_percent, l.subprice,";
522 $sql .=
" l.localtax1_tx, l. localtax2_tx, l.localtax1_type, l. localtax2_type, l.total_localtax1, l.total_localtax2,";
523 $sql .=
" l.total_ht, l.total_tva, l.total_ttc, l.info_bits, l.special_code, l.fk_parent_line, l.rang,";
524 $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,";
525 $sql .=
" l.fk_unit,";
526 $sql .=
" l.date_start, l.date_end,";
527 $sql .=
' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc';
528 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseurdet as l";
529 $sql .=
' LEFT JOIN '.$this->db->prefix().
'product as p ON l.fk_product = p.rowid';
530 $sql .=
" WHERE l.fk_commande = ".((int) $this->
id);
532 $sql .=
' AND p.fk_product_type = 0';
534 $sql .=
" ORDER BY l.rang, l.rowid";
537 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
539 $result = $this->db->query($sql);
541 $num = $this->db->num_rows($result);
545 $objp = $this->db->fetch_object($result);
549 $line->id = $objp->rowid;
550 $line->fk_commande = $objp->fk_commande;
551 $line->desc = $objp->description;
552 $line->description = $objp->description;
553 $line->qty = $objp->qty;
554 $line->tva_tx = $objp->tva_tx;
555 $line->localtax1_tx = $objp->localtax1_tx;
556 $line->localtax2_tx = $objp->localtax2_tx;
557 $line->localtax1_type = $objp->localtax1_type;
558 $line->localtax2_type = $objp->localtax2_type;
559 $line->subprice = $objp->subprice;
560 $line->pu_ht = $objp->subprice;
561 $line->remise_percent = $objp->remise_percent;
563 $line->vat_src_code = $objp->vat_src_code;
564 $line->total_ht = $objp->total_ht;
565 $line->total_tva = $objp->total_tva;
566 $line->total_localtax1 = $objp->total_localtax1;
567 $line->total_localtax2 = $objp->total_localtax2;
568 $line->total_ttc = $objp->total_ttc;
569 $line->product_type = $objp->product_type;
571 $line->fk_product = $objp->fk_product;
573 $line->libelle = $objp->product_label;
574 $line->product_label = $objp->product_label;
575 $line->product_desc = $objp->product_desc;
576 $line->product_tobatch = $objp->product_tobatch;
577 $line->product_barcode = $objp->product_barcode;
579 $line->ref = $objp->product_ref;
580 $line->product_ref = $objp->product_ref;
581 $line->ref_fourn = $objp->ref_supplier;
582 $line->ref_supplier = $objp->ref_supplier;
589 $sqlsearchpackage =
'SELECT rowid, packaging FROM '.$this->db->prefix().
"product_fournisseur_price";
590 $sqlsearchpackage .=
' WHERE entity IN ('.getEntity(
'product_fournisseur_price').
")";
591 $sqlsearchpackage .=
" AND fk_product = ".((int) $objp->fk_product);
592 $sqlsearchpackage .=
" AND ref_fourn = '".$this->db->escape($objp->ref_supplier).
"'";
593 $sqlsearchpackage .=
" AND quantity <= ".((float) $objp->qty);
594 $sqlsearchpackage .=
" AND (packaging IS NULL OR packaging = 0 OR packaging <= ".((float) $objp->qty).
")";
595 $sqlsearchpackage .=
" AND fk_soc = ".((int) $this->socid);
596 $sqlsearchpackage .=
" ORDER BY packaging ASC";
597 $sqlsearchpackage .=
" LIMIT 1";
599 $resqlsearchpackage = $this->db->query($sqlsearchpackage);
600 if ($resqlsearchpackage) {
601 $objsearchpackage = $this->db->fetch_object($resqlsearchpackage);
602 if ($objsearchpackage) {
603 $line->fk_fournprice = $objsearchpackage->rowid;
604 $line->packaging = $objsearchpackage->packaging;
607 $this->error = $this->db->lasterror();
612 $line->date_start = $this->db->jdate($objp->date_start);
613 $line->date_end = $this->db->jdate($objp->date_end);
614 $line->fk_unit = $objp->fk_unit;
617 $line->fk_multicurrency = $objp->fk_multicurrency;
618 $line->multicurrency_code = $objp->multicurrency_code;
619 $line->multicurrency_subprice = $objp->multicurrency_subprice;
620 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
621 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
622 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
624 $line->info_bits = $objp->info_bits;
625 $line->special_code = $objp->special_code;
626 $line->fk_parent_line = $objp->fk_parent_line;
628 $line->rang = $objp->rang;
632 $line->fetch_optionals();
634 $this->lines[$i] = $line;
638 $this->db->free($result);
642 $this->error = $this->db->error().
" sql=".$sql;
655 public function valid($user, $idwarehouse = 0, $notrigger = 0)
657 global $langs, $conf;
658 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
664 if ((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")))
665 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
"fournisseur",
"supplier_order_advance",
"validate"))) {
670 $soc->fetch($this->fourn_id);
673 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
680 $sql =
'UPDATE '.$this->db->prefix().
"commande_fournisseur";
681 $sql .=
" SET ref='".$this->db->escape($num).
"',";
682 $sql .=
" fk_statut = ".((int) self::STATUS_VALIDATED).
",";
683 $sql .=
" date_valid='".$this->db->idate(
dol_now()).
"',";
684 $sql .=
" fk_user_valid = ".((int) $user->id);
685 $sql .=
" WHERE rowid = ".((int) $this->
id);
686 $sql .=
" AND fk_statut = ".((int) self::STATUS_DRAFT);
688 $resql = $this->db->query($sql);
694 if (!$error && !$notrigger) {
696 $result = $this->
call_trigger(
'ORDER_SUPPLIER_VALIDATE', $user);
704 $this->oldref = $this->ref;
707 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
709 $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).
"'";
710 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'fournisseur/commande/".$this->db->escape($this->
ref).
"' and entity = ".((int) $conf->entity);
711 $resql = $this->db->query($sql);
714 $this->error = $this->db->lasterror();
716 $sql =
'UPDATE '.$this->db->prefix().
"ecm_files set filepath = 'fournisseur/commande/".$this->db->escape($this->newref).
"'";
717 $sql .=
" WHERE filepath = 'fournisseur/commande/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
718 $resql = $this->db->query($sql);
721 $this->error = $this->db->lasterror();
727 $dirsource = $conf->fournisseur->commande->dir_output.
'/'.$oldref;
728 $dirdest = $conf->fournisseur->commande->dir_output.
'/'.$newref;
729 if (!$error && file_exists($dirsource)) {
730 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
732 if (@rename($dirsource, $dirdest)) {
735 $listoffiles =
dol_dir_list($conf->fournisseur->commande->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
736 foreach ($listoffiles as $fileentry) {
737 $dirsource = $fileentry[
'name'];
738 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
739 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
740 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
741 @rename($dirsource, $dirdest);
759 $this->db->rollback();
763 $this->error =
'NotAuthorized';
764 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
789 public function LibStatut($status, $mode = 0, $billed = 0)
792 global $conf, $langs, $hookmanager;
794 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
795 $langs->load(
'orders');
797 $this->labelStatus[0] =
'StatusSupplierOrderDraft';
798 $this->labelStatus[1] =
'StatusSupplierOrderValidated';
799 $this->labelStatus[2] =
'StatusSupplierOrderApproved';
801 $this->labelStatus[3] =
'StatusSupplierOrderOnProcess';
803 $this->labelStatus[3] =
'StatusSupplierOrderOnProcessWithValidation';
805 $this->labelStatus[4] =
'StatusSupplierOrderReceivedPartially';
806 $this->labelStatus[5] =
'StatusSupplierOrderReceivedAll';
807 $this->labelStatus[6] =
'StatusSupplierOrderCanceled';
808 $this->labelStatus[7] =
'StatusSupplierOrderCanceled';
809 $this->labelStatus[9] =
'StatusSupplierOrderRefused';
812 $this->labelStatusShort[0] =
'StatusSupplierOrderDraftShort';
813 $this->labelStatusShort[1] =
'StatusSupplierOrderValidatedShort';
814 $this->labelStatusShort[2] =
'StatusSupplierOrderApprovedShort';
815 $this->labelStatusShort[3] =
'StatusSupplierOrderOnProcessShort';
816 $this->labelStatusShort[4] =
'StatusSupplierOrderReceivedPartiallyShort';
817 $this->labelStatusShort[5] =
'StatusSupplierOrderReceivedAllShort';
818 $this->labelStatusShort[6] =
'StatusSupplierOrderCanceledShort';
819 $this->labelStatusShort[7] =
'StatusSupplierOrderCanceledShort';
820 $this->labelStatusShort[9] =
'StatusSupplierOrderRefusedShort';
823 $statustrans = array(
835 $statusClass =
'status0';
836 if (!empty($statustrans[$status])) {
837 $statusClass = $statustrans[$status];
842 $billedtext =
' - '.$langs->trans(
"Billed");
844 if ($status == 5 && $billed) {
845 $statusClass =
'status6';
848 $statusLong = $langs->transnoentitiesnoconv($this->labelStatus[$status]).$billedtext;
849 $statusShort = $langs->transnoentitiesnoconv($this->labelStatusShort[$status]);
851 $parameters = array(
'status' => $status,
'mode' => $mode,
'billed' => $billed);
852 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
854 return $hookmanager->resPrint;
857 return dolGetStatus($statusLong, $statusShort,
'', $statusClass, $mode);
869 global $conf, $langs, $user;
871 $langs->loadLangs([
'bills',
'orders']);
874 $nofetch = !empty($params[
'nofetch']);
876 if ($user->hasRight(
"fournisseur",
"commande",
"read")) {
877 $datas[
'picto'] =
'<u class="paddingrightonly">'.$langs->trans(
"SupplierOrder").
'</u>';
878 if (isset($this->
statut)) {
879 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
881 if (!empty($this->
ref)) {
882 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
884 if (!empty($this->ref_supplier)) {
885 $datas[
'refsupplier'] =
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.$this->ref_supplier;
888 $langs->load(
'companies');
889 if (empty($this->thirdparty)) {
892 $datas[
'supplier'] =
'<br><b>'.$langs->trans(
'Supplier').
':</b> '.$this->thirdparty->getNomUrl(1,
'', 0, 1);
894 if (!empty($this->total_ht)) {
895 $datas[
'totalht'] =
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
897 if (!empty($this->total_tva)) {
898 $datas[
'totaltva'] =
'<br><b>'.$langs->trans(
'VAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
900 if (!empty($this->total_ttc)) {
901 $datas[
'totalttc'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
903 if (!empty($this->date)) {
904 $datas[
'date'] =
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->date,
'day');
906 if (!empty($this->delivery_date)) {
907 $datas[
'deliverydate'] =
'<br><b>'.$langs->trans(
'DeliveryDate').
':</b> '.
dol_print_date($this->delivery_date,
'dayhour');
923 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = 0)
925 global $langs, $conf, $user, $hookmanager;
930 'objecttype' => $this->element,
934 $classfortooltip =
'classfortooltip';
937 $classfortooltip =
'classforajaxtooltip';
938 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
944 $url = DOL_URL_ROOT.
'/fourn/commande/card.php?id='.$this->id;
946 if ($option !==
'nolink') {
948 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
949 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
950 $add_save_lastsearch_values = 1;
952 if ($add_save_lastsearch_values) {
953 $url .=
'&save_lastsearch_values=1';
958 if (empty($notooltip)) {
960 $label = $langs->trans(
"ShowOrder");
961 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
963 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
964 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
967 $linkstart =
'<a href="'.$url.
'"';
968 $linkstart .= $linkclose.
'>';
971 $result .= $linkstart;
973 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
975 if ($withpicto != 2) {
976 $result .= $this->ref;
980 if ($addlinktonotes) {
981 $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
984 $result .=
' <span class="note inline-block">';
985 $result .=
'<a href="'.DOL_URL_ROOT.
'/fourn/commande/note.php?id='.$this->
id.
'" class="classfortooltip" title="'.
dol_escape_htmltag($notetoshow).
'">';
990 $result .=
'</span>';
995 $hookmanager->initHooks(array($this->element .
'dao'));
996 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
997 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
999 $result = $hookmanager->resPrint;
1001 $result .= $hookmanager->resPrint;
1016 global $db, $langs, $conf;
1017 $langs->load(
"orders");
1026 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
1028 foreach ($dirmodels as $reldir) {
1029 $dir =
dol_buildpath($reldir.
"core/modules/supplier_order/");
1032 $mybool |= @include_once $dir.$file;
1035 if ($mybool ===
false) {
1040 $obj =
new $classname();
1041 $numref = $obj->getNextValue($soc, $this);
1043 if ($numref !=
"") {
1046 $this->error = $obj->error;
1050 $this->error =
"Error_COMMANDE_SUPPLIER_ADDON_NotDefined";
1064 if ($this->billed) {
1070 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur SET billed = 1';
1073 if ($this->db->query($sql)) {
1076 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CLASSIFY_BILLED', $user);
1086 $this->db->commit();
1089 $this->db->rollback();
1095 $this->db->rollback();
1108 public function approve($user, $idwarehouse = 0, $secondlevel = 0)
1110 global $langs, $conf;
1111 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1117 if ($user->hasRight(
"fournisseur",
"commande",
"approuver")) {
1123 $soc =
new Societe($this->db);
1124 $soc->fetch($this->fourn_id);
1127 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
1135 $movetoapprovestatus =
true;
1138 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1139 $sql .=
" SET ref='".$this->db->escape($num).
"',";
1140 if (empty($secondlevel)) {
1141 $sql .=
" date_approve='".$this->db->idate($now).
"',";
1142 $sql .=
" fk_user_approve = ".$user->id;
1143 if (
getDolGlobalString(
'SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED') && $this->total_ht >= $conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) {
1144 if (empty($this->user_approve_id2)) {
1145 $movetoapprovestatus =
false;
1146 $comment =
' (first level)';
1150 $sql .=
" date_approve2='".$this->db->idate($now).
"',";
1151 $sql .=
" fk_user_approve2 = ".((int) $user->id);
1152 if (empty($this->user_approve_id)) {
1153 $movetoapprovestatus =
false;
1155 $comment =
' (second level)';
1158 if ($movetoapprovestatus) {
1159 $sql .=
", fk_statut = ".self::STATUS_ACCEPTED;
1161 $sql .=
", fk_statut = ".self::STATUS_VALIDATED;
1163 $sql .=
" WHERE rowid = ".((int) $this->
id);
1164 $sql .=
" AND fk_statut = ".self::STATUS_VALIDATED;
1166 if ($this->db->query($sql)) {
1168 $result = $this->
add_contact($user->id,
'SALESREPFOLL',
'internal', 1);
1169 if ($result < 0 && $result != -2) {
1175 if (!$error && $movetoapprovestatus && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER')) {
1176 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1177 $langs->load(
"agenda");
1179 $cpt = count($this->lines);
1180 for ($i = 0; $i < $cpt; $i++) {
1182 if ($this->lines[$i]->fk_product > 0) {
1183 $this->line = $this->lines[$i];
1185 $mouvP->origin = &$this;
1186 $mouvP->setOrigin($this->element, $this->
id);
1188 $up_ht_disc = $this->lines[$i]->subprice;
1189 if (!empty($this->lines[$i]->remise_percent) && !
getDolGlobalString(
'STOCK_EXCLUDE_DISCOUNT_FOR_PMP')) {
1190 $up_ht_disc =
price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100,
'MU');
1192 $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans(
"OrderApprovedInDolibarr", $this->ref));
1203 $result = $this->
call_trigger(
'ORDER_SUPPLIER_APPROVE', $user);
1211 $this->
ref = $this->newref;
1213 if ($movetoapprovestatus) {
1218 if (empty($secondlevel)) {
1219 $this->date_approve = $now;
1220 $this->user_approve_id = $user->id;
1222 $this->date_approve2 = $now;
1223 $this->user_approve_id2 = $user->id;
1226 $this->db->commit();
1229 $this->db->rollback();
1233 $this->db->rollback();
1234 $this->error = $this->db->lasterror();
1238 dol_syslog(get_class($this).
"::approve Not Authorized", LOG_ERR);
1251 global $conf, $langs;
1257 if ($user->hasRight(
"fournisseur",
"commande",
"approuver")) {
1260 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur SET fk_statut = ".
self::STATUS_REFUSED;
1261 $sql .=
" WHERE rowid = ".((int) $this->
id);
1263 if ($this->db->query($sql)) {
1268 $result = $this->
call_trigger(
'ORDER_SUPPLIER_REFUSE', $user);
1271 $this->db->rollback();
1273 $this->db->commit();
1278 $this->db->rollback();
1279 $this->error = $this->db->lasterror();
1280 dol_syslog(get_class($this).
"::refuse Error -1");
1284 dol_syslog(get_class($this).
"::refuse Not Authorized");
1298 public function Cancel($user, $idwarehouse = -1)
1301 global $langs, $conf;
1307 if ($user->hasRight(
"fournisseur",
"commande",
"commander")) {
1312 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur SET fk_statut = ".((int) $statut);
1313 $sql .=
" WHERE rowid = ".((int) $this->
id);
1314 dol_syslog(get_class($this).
"::cancel", LOG_DEBUG);
1315 if ($this->db->query($sql)) {
1319 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CANCEL', $user);
1326 $this->db->commit();
1329 $this->db->rollback();
1333 $this->db->rollback();
1334 $this->error = $this->db->lasterror();
1335 dol_syslog(get_class($this).
"::cancel ".$this->error);
1339 dol_syslog(get_class($this).
"::cancel Not Authorized");
1353 public function commande($user, $date, $methode, $comment =
'')
1358 if ($user->hasRight(
"fournisseur",
"commande",
"commander")) {
1361 $newnoteprivate = $this->note_private;
1363 $newnoteprivate =
dol_concatdesc($newnoteprivate, $langs->trans(
"Comment").
': '.$comment);
1366 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1367 $sql .=
" SET fk_statut=".self::STATUS_ORDERSENT.
", fk_input_method=".$methode.
", date_commande='".$this->db->idate($date).
"', ";
1368 $sql .=
" note_private='".$this->db->escape($newnoteprivate).
"'";
1369 $sql .=
" WHERE rowid=".((int) $this->
id);
1371 dol_syslog(get_class($this).
"::commande", LOG_DEBUG);
1372 if ($this->db->query($sql)) {
1374 $this->methode_commande_id = $methode;
1375 $this->date_commande = $date;
1376 $this->context = array(
'comments' => $comment);
1379 $result = $this->
call_trigger(
'ORDER_SUPPLIER_SUBMIT', $user);
1386 $this->error = $this->db->lasterror();
1387 $this->errors[] = $this->db->lasterror();
1391 $this->db->commit();
1393 $this->db->rollback();
1397 $this->error = $langs->trans(
'NotAuthorized');
1398 $this->errors[] = $langs->trans(
'NotAuthorized');
1399 dol_syslog(get_class($this).
"::commande User not Authorized", LOG_WARNING);
1402 return ($error ? -1 : 1);
1412 public function create($user, $notrigger = 0)
1414 global $langs, $conf, $hookmanager;
1422 $date = ($this->date_commande ? $this->date_commande : $this->date);
1426 $delivery_date = $this->delivery_date;
1429 if (empty($this->source)) {
1434 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
1439 if (empty($this->fk_multicurrency)) {
1440 $this->multicurrency_code = $conf->currency;
1441 $this->fk_multicurrency = 0;
1442 $this->multicurrency_tx = 1;
1449 $sql =
"INSERT INTO ".$this->db->prefix().
"commande_fournisseur (";
1451 $sql .=
", ref_supplier";
1452 $sql .=
", note_private";
1453 $sql .=
", note_public";
1456 $sql .=
", fk_projet";
1457 $sql .=
", date_creation";
1458 $sql .=
", date_livraison";
1459 $sql .=
", fk_user_author";
1460 $sql .=
", fk_statut";
1462 $sql .=
", model_pdf";
1463 $sql .=
", fk_mode_reglement";
1464 $sql .=
", fk_cond_reglement";
1465 $sql .=
", fk_account";
1466 $sql .=
", fk_incoterms, location_incoterms";
1467 $sql .=
", fk_multicurrency";
1468 $sql .=
", multicurrency_code";
1469 $sql .=
", multicurrency_tx";
1471 $sql .=
" VALUES (";
1473 $sql .=
", ".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"NULL");
1474 $sql .=
", '".$this->db->escape($this->note_private).
"'";
1475 $sql .=
", '".$this->db->escape($this->note_public).
"'";
1476 $sql .=
", ".setEntity($this);
1477 $sql .=
", ".((int) $this->socid);
1478 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
1479 $sql .=
", '".$this->db->idate($date).
"'";
1480 $sql .=
", ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
"null");
1481 $sql .=
", ".((int) $user->id);
1482 $sql .=
", ".self::STATUS_DRAFT;
1483 $sql .=
", ".((int) $this->source);
1484 $sql .=
", '".$this->db->escape(
getDolGlobalString(
'COMMANDE_SUPPLIER_ADDON_PDF')).
"'";
1485 $sql .=
", ".($this->mode_reglement_id > 0 ? $this->mode_reglement_id :
'null');
1486 $sql .=
", ".($this->cond_reglement_id > 0 ? $this->cond_reglement_id :
'null');
1487 $sql .=
", ".($this->fk_account > 0 ? $this->fk_account :
'NULL');
1488 $sql .=
", ".(int) $this->fk_incoterms;
1489 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
1490 $sql .=
", ".(int) $this->fk_multicurrency;
1491 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1492 $sql .=
", ".(float) $this->multicurrency_tx;
1495 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1496 if ($this->db->query($sql)) {
1497 $this->
id = $this->db->last_insert_id($this->db->prefix().
"commande_fournisseur");
1500 $num = count($this->lines);
1503 for ($i = 0; $i < $num; $i++) {
1504 $line = $this->lines[$i];
1505 if (!is_object($line)) {
1506 $line = (object) $line;
1517 $line->localtax1_tx,
1518 $line->localtax2_tx,
1522 $line->remise_percent,
1525 $line->product_type,
1530 $line->array_options,
1532 $line->multicurrency_subprice,
1539 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
1540 $this->db->rollback();
1545 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
1546 $sql .=
" SET ref='(PROV".$this->id.
")'";
1547 $sql .=
" WHERE rowid=".((int) $this->
id);
1549 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1550 if ($this->db->query($sql)) {
1553 $this->
ref =
"(PROV".$this->id.
")";
1555 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
1556 $this->linked_objects = $this->linkedObjectsIds;
1560 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
1561 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
1562 if (is_array($tmp_origin_id)) {
1563 foreach ($tmp_origin_id as $origin_id) {
1571 $origin_id = $tmp_origin_id;
1589 if (!$error && !$notrigger) {
1591 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CREATE', $user);
1593 $this->db->rollback();
1600 $this->db->commit();
1603 $this->error = $this->db->lasterror();
1604 $this->db->rollback();
1609 $this->error =
'Failed to get ID of inserted line';
1614 $this->error = $this->db->lasterror();
1615 $this->db->rollback();
1635 if (isset($this->
ref)) {
1636 $this->
ref = trim($this->
ref);
1638 if (isset($this->ref_supplier)) {
1639 $this->ref_supplier = trim($this->ref_supplier);
1641 if (isset($this->note_private)) {
1642 $this->note_private = trim($this->note_private);
1644 if (isset($this->note_public)) {
1645 $this->note_public = trim($this->note_public);
1647 if (isset($this->model_pdf)) {
1648 $this->model_pdf = trim($this->model_pdf);
1650 if (isset($this->import_key)) {
1651 $this->import_key = trim($this->import_key);
1655 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
1657 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1658 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
1659 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1660 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
1661 $sql .=
" date_commande=".(strval($this->date_commande) !=
'' ?
"'".$this->db->idate($this->date_commande).
"'" :
'null').
",";
1662 $sql .=
" date_valid=".(strval($this->date_validation) !=
'' ?
"'".$this->db->idate($this->date_validation).
"'" :
'null').
",";
1663 $sql .=
" total_tva=".(isset($this->total_tva) ? $this->total_tva :
"null").
",";
1664 $sql .=
" localtax1=".(isset($this->total_localtax1) ? $this->total_localtax1 :
"null").
",";
1665 $sql .=
" localtax2=".(isset($this->total_localtax2) ? $this->total_localtax2 :
"null").
",";
1666 $sql .=
" total_ht=".(isset($this->total_ht) ? $this->total_ht :
"null").
",";
1667 $sql .=
" total_ttc=".(isset($this->total_ttc) ? $this->total_ttc :
"null").
",";
1668 $sql .=
" fk_statut=".(isset($this->
statut) ? $this->
statut :
"null").
",";
1669 $sql .=
" fk_user_author=".(isset($this->user_author_id) ? $this->user_author_id :
"null").
",";
1670 $sql .=
" fk_user_valid=".(isset($this->user_validation_id) && $this->user_validation_id > 0 ? $this->user_validation_id :
"null").
",";
1671 $sql .=
" fk_projet=".(isset($this->fk_project) ? $this->fk_project :
"null").
",";
1672 $sql .=
" fk_cond_reglement=".(isset($this->cond_reglement_id) ? $this->cond_reglement_id :
"null").
",";
1673 $sql .=
" fk_mode_reglement=".(isset($this->mode_reglement_id) ? $this->mode_reglement_id :
"null").
",";
1674 $sql .=
" date_livraison=".(strval($this->delivery_date) !=
'' ?
"'".$this->db->idate($this->delivery_date).
"'" :
'null').
",";
1676 $sql .=
" fk_account=".($this->fk_account > 0 ? $this->fk_account :
"null").
",";
1678 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1679 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1680 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1681 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
1683 $sql .=
" WHERE rowid=".((int) $this->
id);
1687 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1688 $resql = $this->db->query($sql);
1691 $this->errors[] =
"Error ".$this->db->lasterror();
1701 if (!$error && !$notrigger) {
1703 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
1712 foreach ($this->errors as $errmsg) {
1713 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1714 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1716 $this->db->rollback();
1719 $this->db->commit();
1734 global $conf, $user, $hookmanager;
1741 foreach ($this->lines as $line) {
1742 $line->fetch_optionals();
1746 $objFrom = clone $this;
1749 if (!empty($socid) && $socid != $this->socid) {
1750 $objsoc =
new Societe($this->db);
1752 if ($objsoc->fetch($socid) > 0) {
1753 $this->socid = $objsoc->id;
1754 $this->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1755 $this->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1756 $this->fk_project = 0;
1757 $this->fk_delivery_address = 0;
1767 $this->user_author_id = $user->id;
1768 $this->user_validation_id = 0;
1770 $this->date_creation =
'';
1771 $this->date_commande =
'';
1772 $this->date_validation =
'';
1773 $this->ref_supplier =
null;
1774 $this->user_approve_id =
'';
1775 $this->user_approve_id2 =
'';
1776 $this->date_approve =
'';
1777 $this->date_approve2 =
'';
1780 $this->context[
'createfromclone'] =
'createfromclone';
1781 $result = $this->
create($user, $notrigger);
1788 if (is_object($hookmanager)) {
1789 $parameters = array(
'objFrom'=>$objFrom);
1791 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1799 unset($this->context[
'createfromclone']);
1803 $this->db->commit();
1806 $this->db->rollback();
1840 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)
1842 global $langs, $mysoc, $conf;
1844 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");
1845 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1847 if ($this->
statut == self::STATUS_DRAFT) {
1848 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1857 if (empty($txtva)) {
1863 if (empty($txlocaltax1)) {
1866 if (empty($txlocaltax2)) {
1869 if (empty($remise_percent)) {
1870 $remise_percent = 0;
1873 $remise_percent =
price2num($remise_percent);
1876 $pu_ht_devise =
price2num($pu_ht_devise);
1878 if (!preg_match(
'/\((.*)\)/', $txtva)) {
1883 if ($price_base_type ==
'HT') {
1888 $desc = trim($desc);
1891 if ($qty < 0 && !$fk_product) {
1892 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Product"));
1898 if ($date_start && $date_end && $date_start > $date_end) {
1899 $langs->load(
"errors");
1900 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
1907 $product_type = $type;
1910 if ($fk_product > 0) {
1913 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);
1915 if ($prod->fetch($fk_product) > 0) {
1916 $product_type = $prod->type;
1917 $label = $prod->label;
1921 $result = $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', (isset($this->fk_soc) ? $this->fk_soc : $this->socid));
1925 if ($result > 0 && ($origin ==
'commande' || $pu ===
'')) {
1926 $pu = $prod->fourn_pu;
1927 $ref_supplier = $prod->ref_supplier;
1929 if ($remise_percent == 0 && $prod->remise_percent != 0) {
1930 $remise_percent = $prod->remise_percent;
1934 $langs->load(
"errors");
1935 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
1936 $this->db->rollback();
1937 dol_syslog(get_class($this).
"::addline we did not found supplier price, so we can't guess unit price");
1942 if ($result == -1) {
1943 $langs->load(
"errors");
1944 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
1945 $this->db->rollback();
1946 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_DEBUG);
1950 $this->error = $prod->error;
1951 $this->db->rollback();
1952 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_ERR);
1956 $this->error = $prod->error;
1957 $this->db->rollback();
1964 $prod =
new Product($this->db);
1965 $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', (empty($this->fk_soc) ? $this->socid : $this->fk_soc));
1967 if ($qty < $prod->packaging) {
1968 $qty = $prod->packaging;
1970 if (!empty($prod->packaging) && ($qty % $prod->packaging) > 0) {
1971 $coeff = intval($qty / $prod->packaging) + 1;
1972 $qty = $prod->packaging * $coeff;
1973 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'mesgs');
1979 if (isModEnabled(
"multicurrency") && $pu_ht_devise > 0) {
1988 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
1989 $vat_src_code = $reg[1];
1990 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
1998 $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);
2000 $total_ht = $tabprice[0];
2001 $total_tva = $tabprice[1];
2002 $total_ttc = $tabprice[2];
2003 $total_localtax1 = $tabprice[9];
2004 $total_localtax2 = $tabprice[10];
2005 $pu = $pu_ht = $tabprice[3];
2008 $multicurrency_total_ht = $tabprice[16];
2009 $multicurrency_total_tva = $tabprice[17];
2010 $multicurrency_total_ttc = $tabprice[18];
2011 $pu_ht_devise = $tabprice[19];
2013 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2014 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2018 $rang = $rangmax + 1;
2024 $this->line->context = $this->context;
2026 $this->line->fk_commande = $this->id;
2027 $this->line->label = $label;
2028 $this->line->ref_fourn = $ref_supplier;
2029 $this->line->ref_supplier = $ref_supplier;
2030 $this->line->desc = $desc;
2031 $this->line->qty = $qty;
2032 $this->line->tva_tx = $txtva;
2033 $this->line->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0);
2034 $this->line->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0);
2035 $this->line->localtax1_type = $localtax1_type;
2036 $this->line->localtax2_type = $localtax2_type;
2037 $this->line->fk_product = $fk_product;
2038 $this->line->product_type = $product_type;
2039 $this->line->remise_percent = $remise_percent;
2040 $this->line->subprice = $pu_ht;
2041 $this->line->rang = $rang;
2042 $this->line->info_bits = $info_bits;
2044 $this->line->vat_src_code = $vat_src_code;
2045 $this->line->total_ht = $total_ht;
2046 $this->line->total_tva = $total_tva;
2047 $this->line->total_localtax1 = $total_localtax1;
2048 $this->line->total_localtax2 = $total_localtax2;
2049 $this->line->total_ttc = $total_ttc;
2050 $this->line->product_type = $type;
2051 $this->line->special_code = (!empty($special_code) ? $special_code : 0);
2052 $this->line->origin = $origin;
2053 $this->line->origin_id = $origin_id;
2054 $this->line->fk_unit = $fk_unit;
2056 $this->line->date_start = $date_start;
2057 $this->line->date_end = $date_end;
2060 $this->line->fk_multicurrency = $this->fk_multicurrency;
2061 $this->line->multicurrency_code = $this->multicurrency_code;
2062 $this->line->multicurrency_subprice = $pu_ht_devise;
2063 $this->line->multicurrency_total_ht = $multicurrency_total_ht;
2064 $this->line->multicurrency_total_tva = $multicurrency_total_tva;
2065 $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
2067 $this->line->subprice = $pu_ht;
2068 $this->line->price = $this->line->subprice;
2070 $this->line->remise_percent = $remise_percent;
2072 if (is_array($array_options) && count($array_options) > 0) {
2073 $this->line->array_options = $array_options;
2076 $result = $this->line->insert($notrigger);
2079 if (!empty($this->line->fk_parent_line)) {
2081 } elseif ($rang > 0 && $rang <= count($this->lines)) {
2082 $linecount = count($this->lines);
2083 for ($ii = $rang; $ii <= $linecount; $ii++) {
2089 $result = $this->
update_price(1,
'auto', 0, $this->thirdparty);
2091 $this->db->commit();
2092 return $this->line->id;
2094 $this->db->rollback();
2098 $this->error = $this->line->error;
2099 $this->errors = $this->line->errors;
2100 dol_syslog(get_class($this).
"::addline error=".$this->error, LOG_ERR);
2101 $this->db->rollback();
2126 public function dispatchProduct($user, $product, $qty, $entrepot, $price = 0, $comment =
'', $eatby =
'', $sellby =
'', $batch =
'', $fk_commandefourndet = 0, $notrigger = 0, $fk_reception = 0)
2128 global $conf, $langs;
2131 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2134 if ($entrepot <= 0) {
2135 $this->error =
'ErrorBadValueForParameterWarehouse';
2139 $this->error =
'ErrorBadValueForParameterQty';
2143 $dispatchstatus = 1;
2145 $dispatchstatus = 0;
2152 if (($this->
statut == self::STATUS_ORDERSENT || $this->
statut == self::STATUS_RECEIVED_PARTIALLY || $this->
statut == self::STATUS_RECEIVED_COMPLETELY)) {
2155 $sql =
"INSERT INTO ".$this->db->prefix().
"commande_fournisseur_dispatch";
2156 $sql .=
" (fk_commande, fk_product, qty, fk_entrepot, fk_user, datec, fk_commandefourndet, status, comment, eatby, sellby, batch, fk_reception) VALUES";
2157 $sql .=
" ('".$this->id.
"','".$product.
"','".$qty.
"',".($entrepot > 0 ?
"'".$entrepot.
"'" :
"null").
",'".$user->id.
"','".$this->db->idate($now).
"','".$fk_commandefourndet.
"', ".$dispatchstatus.
", '".$this->db->escape($comment).
"', ";
2158 $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");
2161 dol_syslog(get_class($this).
"::dispatchProduct", LOG_DEBUG);
2162 $resql = $this->db->query($sql);
2165 global $conf, $langs, $user;
2167 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_DISPATCH', $user);
2174 $this->error = $this->db->lasterror();
2179 if (!$error && $entrepot > 0 && isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER')) {
2183 $mouv->origin = &$this;
2184 $mouv->setOrigin($this->element, $this->
id);
2187 if (
getDolGlobalString(
'SUPPLIER_ORDER_ALLOW_NEGATIVE_QTY_FOR_SUPPLIER_ORDER_RETURN') && $qty < 0) {
2188 $result = $mouv->livraison($user, $product, $entrepot, $qty*(-1), $price, $comment, $now, $eatby, $sellby, $batch, 0, $inventorycode);
2190 $result = $mouv->reception($user, $product, $entrepot, $qty, $price, $comment, $eatby, $sellby, $batch,
'', 0, $inventorycode);
2194 $this->error = $mouv->error;
2195 $this->errors = $mouv->errors;
2196 dol_syslog(get_class($this).
"::dispatchProduct ".$this->error.
" ".join(
',', $this->errors), LOG_ERR);
2203 $this->db->commit();
2206 $this->db->rollback();
2210 $this->error =
'BadStatusForObject';
2224 if ($this->
statut == 0) {
2227 if ($line->fetch($idline) <= 0) {
2233 foreach ($dispatchedLines as $dispatchLine) {
2234 if ($dispatchLine[
'orderlineid'] == $idline) {
2235 $this->error =
"LineAlreadyDispatched";
2236 $this->errors[] = $this->error;
2241 if ($line->delete($notrigger) > 0) {
2245 $this->error = $line->error;
2246 $this->errors = $line->errors;
2261 public function delete(
User $user, $notrigger = 0)
2263 global $langs, $conf;
2264 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2270 if (empty($notrigger)) {
2272 $result = $this->
call_trigger(
'ORDER_SUPPLIER_DELETE', $user);
2274 $this->errors[] =
'ErrorWhenRunningTrigger';
2275 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2276 $this->db->rollback();
2284 if (!empty($this->linkedObjects) && array_key_exists(
'reception', $this->linkedObjects)) {
2285 foreach ($this->linkedObjects[
'reception'] as $element) {
2286 if ($element->statut >= 0) {
2287 $this->errors[] = $langs->trans(
'ReceptionExist');
2294 $main = $this->db->prefix().
'commande_fournisseurdet';
2297 $sql1 =
"UPDATE ".$this->db->prefix().
"commandedet SET fk_commandefourndet = NULL WHERE fk_commandefourndet IN (SELECT rowid FROM ".$main.
" WHERE fk_commande = ".((int) $this->
id).
")";
2298 dol_syslog(__METHOD__.
" linked order lines", LOG_DEBUG);
2299 if (!$this->db->query($sql1)) {
2301 $this->error = $this->db->lasterror();
2302 $this->errors[] = $this->db->lasterror();
2307 $ef = $main.
"_extrafields";
2308 $sql =
"DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_commande = ".((int) $this->
id).
")";
2309 dol_syslog(get_class($this).
"::delete extrafields lines", LOG_DEBUG);
2310 if (!$this->db->query($sql)) {
2311 $this->error = $this->db->lasterror();
2312 $this->errors[] = $this->db->lasterror();
2318 $sql =
"DELETE FROM ".$this->db->prefix().
"commande_fournisseurdet WHERE fk_commande =".((int) $this->
id);
2319 dol_syslog(get_class($this).
"::delete", 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_fournisseur WHERE rowid =".((int) $this->
id);
2329 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2330 if ($resql = $this->db->query($sql)) {
2331 if ($this->db->affected_rows($resql) < 1) {
2332 $this->error = $this->db->lasterror();
2333 $this->errors[] = $this->db->lasterror();
2337 $this->error = $this->db->lasterror();
2338 $this->errors[] = $this->db->lasterror();
2347 $this->error =
'FailToDeleteExtraFields';
2348 $this->errors[] =
'FailToDeleteExtraFields';
2350 dol_syslog(get_class($this).
"::delete error -4 ".$this->error, LOG_ERR);
2357 $this->error =
'FailToDeleteObjectLinked';
2358 $this->errors[] =
'FailToDeleteObjectLinked';
2369 if ($conf->fournisseur->commande->dir_output) {
2370 $dir = $conf->fournisseur->commande->dir_output.
"/".$ref;
2371 $file = $dir.
"/".$ref.
".pdf";
2372 if (file_exists($file)) {
2374 $this->error =
'ErrorFailToDeleteFile';
2375 $this->errors[] =
'ErrorFailToDeleteFile';
2379 if (file_exists($dir)) {
2382 $this->error =
'ErrorFailToDeleteDir';
2383 $this->errors[] =
'ErrorFailToDeleteDir';
2391 dol_syslog(get_class($this).
"::delete $this->id by $user->id", LOG_DEBUG);
2392 $this->db->commit();
2395 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2396 $this->db->rollback();
2415 $sql =
"SELECT p.ref, p.label,";
2416 $sql .=
" e.rowid as warehouse_id, e.ref as entrepot,";
2417 $sql .=
" cfd.rowid as dispatchedlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status, cfd.fk_commandefourndet";
2418 $sql .=
" FROM ".$this->db->prefix().
"product as p,";
2419 $sql .=
" ".$this->db->prefix().
"commande_fournisseur_dispatch as cfd";
2420 $sql .=
" LEFT JOIN ".$this->db->prefix().
"entrepot as e ON cfd.fk_entrepot = e.rowid";
2421 $sql .=
" WHERE cfd.fk_commande = ".((int) $this->
id);
2422 $sql .=
" AND cfd.fk_product = p.rowid";
2424 $sql .=
" AND cfd.status = ".((int) $status);
2426 $sql .=
" ORDER BY cfd.rowid ASC";
2428 $resql = $this->db->query($sql);
2430 $num = $this->db->num_rows($resql);
2434 $objp = $this->db->fetch_object($resql);
2437 'id' => $objp->dispatchedlineid,
2438 'productid' => $objp->fk_product,
2439 'warehouseid' => $objp->warehouse_id,
2440 'qty' => $objp->qty,
2441 'orderlineid' => $objp->fk_commandefourndet
2448 dol_print_error($this->db,
'Failed to execute request to get dispatched lines');
2467 global $conf, $langs;
2474 $usercanreceive = 0;
2475 if (!isModEnabled(
'reception')) {
2476 $usercanreceive = $user->hasRight(
"fournisseur",
"commande",
"receptionner");
2478 $usercanreceive = $user->hasRight(
"reception",
"creer");
2481 if ($usercanreceive) {
2483 if ($type ==
'par') {
2485 } elseif ($type ==
'tot') {
2487 } elseif ($type ==
'nev') {
2489 } elseif ($type ==
'can') {
2493 dol_syslog(get_class($this).
"::Livraison Error -2", LOG_ERR);
2500 if (!$error && ($type ==
'tot')) {
2502 if (count($dispatchedlinearray) > 0) {
2505 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove';
2506 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove', LOG_DEBUG);
2509 if (!$error &&
getDolGlobalString(
'SUPPLIER_ORDER_USE_DISPATCH_STATUS_NEED_APPROVE') && ($type ==
'tot')) {
2511 if (count($dispatchedlinearray) > 0) {
2514 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied';
2515 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied', LOG_DEBUG);
2522 if (empty($error)) {
2525 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2526 $sql .=
" SET fk_statut = ".((int) $statut);
2527 $sql .=
" WHERE rowid = ".((int) $this->
id);
2528 $sql .=
" AND fk_statut IN (".self::STATUS_ORDERSENT.
",".self::STATUS_RECEIVED_PARTIALLY.
")";
2530 dol_syslog(get_class($this).
"::Livraison", LOG_DEBUG);
2531 $resql = $this->db->query($sql);
2534 $old_statut = $this->statut;
2536 $this->context[
'actionmsg2'] = $comment;
2539 $result_trigger = $this->
call_trigger(
'ORDER_SUPPLIER_RECEIVE', $user);
2540 if ($result_trigger < 0) {
2545 if (empty($error)) {
2546 $this->db->commit();
2548 $this->
statut = $old_statut;
2549 $this->db->rollback();
2550 $this->error = $this->db->lasterror();
2554 $this->db->rollback();
2555 $this->error = $this->db->lasterror();
2560 $this->error = $langs->trans(
'NotAuthorized');
2561 $this->errors[] = $langs->trans(
'NotAuthorized');
2562 dol_syslog(get_class($this).
"::Livraison Not Authorized");
2594 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
2599 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2600 $sql .=
" SET date_livraison = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2601 $sql .=
" WHERE rowid = ".((int) $this->
id);
2604 $resql = $this->db->query($sql);
2606 $this->errors[] = $this->db->error();
2611 $this->oldcopy = clone $this;
2612 $this->delivery_date = $delivery_date;
2615 if (!$notrigger && empty($error)) {
2617 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2625 $this->db->commit();
2628 foreach ($this->errors as $errmsg) {
2629 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2630 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2632 $this->db->rollback();
2652 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
2657 $sql =
"UPDATE ".$this->db->prefix().
"commande_fournisseur";
2658 $sql .=
" SET fk_projet = ".($id_projet > 0 ? (int) $id_projet :
'null');
2659 $sql .=
" WHERE rowid = ".((int) $this->
id);
2662 $resql = $this->db->query($sql);
2664 $this->errors[] = $this->db->error();
2669 $this->oldcopy = clone $this;
2670 $this->fk_projet = $id_projet;
2671 $this->fk_project = $id_projet;
2674 if (!$notrigger && empty($error)) {
2676 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2684 $this->db->commit();
2687 foreach ($this->errors as $errmsg) {
2688 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2689 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2691 $this->db->rollback();
2709 $comclient =
new Commande($this->db);
2710 $comclient->fetch($comclientid);
2714 $this->lines = array();
2716 $num = count($comclient->lines);
2717 for ($i = 0; $i < $num; $i++) {
2718 $prod =
new Product($this->db);
2721 if ($prod->fetch($comclient->lines[$i]->fk_product) > 0) {
2722 $label = $prod->label;
2726 $sql =
"INSERT INTO ".$this->db->prefix().
"commande_fournisseurdet";
2727 $sql .=
" (fk_commande, label, description, fk_product, price, qty, tva_tx, localtax1_tx, localtax2_tx, remise_percent, subprice, remise, ref)";
2728 $sql .=
" VALUES (".((int) $idc).
", '".$this->db->escape($label).
"', '".$this->db->escape($comclient->lines[$i]->desc).
"'";
2729 $sql .=
",".$comclient->lines[$i]->fk_product.
", ".
price2num($comclient->lines[$i]->price,
'MU');
2730 $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);
2731 $sql .=
", '".price2num($comclient->lines[$i]->subprice,
'MT').
"','0', '".$this->db->escape($ref).
"');";
2732 if ($this->db->query($sql)) {
2749 global $conf, $langs;
2754 $sql =
'UPDATE '.$this->db->prefix().
'commande_fournisseur';
2755 $sql .=
" SET fk_statut = ".$status;
2756 $sql .=
" WHERE rowid = ".((int) $this->
id);
2758 dol_syslog(get_class($this).
"::setStatus", LOG_DEBUG);
2759 $resql = $this->db->query($sql);
2762 $triggerName = array();
2763 $triggerName[0] =
'DRAFT';
2764 $triggerName[1] =
'VALIDATED';
2765 $triggerName[2] =
'APPROVED';
2766 $triggerName[3] =
'ORDERED';
2767 $triggerName[4] =
'RECEIVED_PARTIALLY';
2768 $triggerName[5] =
'RECEIVED_COMPLETELY';
2769 $triggerName[6] =
'CANCELED';
2770 $triggerName[7] =
'CANCELED';
2771 $triggerName[9] =
'REFUSED';
2774 $result = $this->
call_trigger(
"ORDER_SUPPLIER_STATUS_".$triggerName[$status], $user);
2781 $this->error = $this->db->lasterror();
2782 dol_syslog(get_class($this).
"::setStatus ".$this->error);
2787 $this->db->commit();
2790 $this->db->rollback();
2818 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 =
'')
2820 global $mysoc, $conf, $langs;
2821 dol_syslog(get_class($this).
"::updateline $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $type, $fk_unit");
2822 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2826 if ($this->
statut == self::STATUS_DRAFT) {
2831 if (empty($info_bits)) {
2834 if (empty($txtva)) {
2837 if (empty($txlocaltax1)) {
2840 if (empty($txlocaltax2)) {
2843 if (empty($remise_percent)) {
2844 $remise_percent = 0;
2847 $remise_percent =
price2num($remise_percent);
2853 $pu_ht_devise =
price2num($pu_ht_devise);
2854 if (!preg_match(
'/\((.*)\)/', $txtva)) {
2864 if ($date_start && $date_end && $date_start > $date_end) {
2865 $langs->load(
"errors");
2866 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
2882 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
2883 $vat_src_code = $reg[1];
2884 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
2887 $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);
2888 $total_ht = $tabprice[0];
2889 $total_tva = $tabprice[1];
2890 $total_ttc = $tabprice[2];
2891 $total_localtax1 = $tabprice[9];
2892 $total_localtax2 = $tabprice[10];
2893 $pu_ht = $tabprice[3];
2894 $pu_tva = $tabprice[4];
2895 $pu_ttc = $tabprice[5];
2898 $multicurrency_total_ht = $tabprice[16];
2899 $multicurrency_total_tva = $tabprice[17];
2900 $multicurrency_total_ttc = $tabprice[18];
2901 $pu_ht_devise = $tabprice[19];
2903 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2904 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2908 $this->line->fetch($rowid);
2910 $oldline = clone $this->line;
2911 $this->line->oldline = $oldline;
2913 $this->line->context = $this->context;
2915 $this->line->fk_commande = $this->id;
2917 $this->line->desc = $desc;
2921 if ($qty < $this->line->packaging) {
2922 $qty = $this->line->packaging;
2924 if (!empty($this->line->packaging) && ($qty % $this->line->packaging) > 0) {
2925 $coeff = intval($qty / $this->line->packaging) + 1;
2926 $qty = $this->line->packaging * $coeff;
2927 setEventMessage($langs->trans(
'QtyRecalculatedWithPackaging'),
'mesgs');
2932 $this->line->qty = $qty;
2933 $this->line->ref_supplier = $ref_supplier;
2935 $this->line->vat_src_code = $vat_src_code;
2936 $this->line->tva_tx = $txtva;
2937 $this->line->localtax1_tx = $txlocaltax1;
2938 $this->line->localtax2_tx = $txlocaltax2;
2939 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2940 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2941 $this->line->remise_percent = $remise_percent;
2942 $this->line->subprice = $pu_ht;
2943 $this->line->info_bits = $info_bits;
2944 $this->line->total_ht = $total_ht;
2945 $this->line->total_tva = $total_tva;
2946 $this->line->total_localtax1 = $total_localtax1;
2947 $this->line->total_localtax2 = $total_localtax2;
2948 $this->line->total_ttc = $total_ttc;
2949 $this->line->product_type = $type;
2950 $this->line->special_code = $oldline->special_code;
2951 $this->line->rang = $oldline->rang;
2952 $this->line->origin = $this->origin;
2953 $this->line->fk_unit = $fk_unit;
2955 $this->line->date_start = $date_start;
2956 $this->line->date_end = $date_end;
2959 $this->line->fk_multicurrency = $this->fk_multicurrency;
2960 $this->line->multicurrency_code = $this->multicurrency_code;
2961 $this->line->multicurrency_subprice = $pu_ht_devise;
2962 $this->line->multicurrency_total_ht = $multicurrency_total_ht;
2963 $this->line->multicurrency_total_tva = $multicurrency_total_tva;
2964 $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
2966 $this->line->subprice = $pu_ht;
2967 $this->line->price = $this->line->subprice;
2969 $this->line->remise_percent = $remise_percent;
2971 if (is_array($array_options) && count($array_options) > 0) {
2973 foreach ($array_options as $key => $value) {
2974 $this->line->array_options[$key] = $array_options[$key];
2978 $result = $this->line->update($notrigger);
2984 $this->db->commit();
2987 $this->error = $this->db->lasterror();
2988 $this->db->rollback();
2992 $this->error =
"Order status makes operation forbidden";
2993 dol_syslog(get_class($this).
"::updateline ".$this->error, LOG_ERR);
3008 global $user, $langs, $conf;
3010 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
3012 dol_syslog(get_class($this).
"::initAsSpecimen");
3019 $sql =
"SELECT rowid";
3020 $sql .=
" FROM ".$this->db->prefix().
"product";
3021 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
3022 $sql .= $this->db->order(
"rowid",
"ASC");
3023 $sql .= $this->db->plimit(1);
3024 $resql = $this->db->query($sql);
3025 if ($resql && $this->db->num_rows($resql)) {
3026 $obj = $this->db->fetch_object($resql);
3027 $prodid = $obj->rowid;
3032 $this->
ref =
'SPECIMEN';
3033 $this->specimen = 1;
3036 $this->date_commande = $now;
3037 $this->date_lim_reglement = $this->date + 3600 * 24 * 30;
3038 $this->cond_reglement_code =
'RECEP';
3039 $this->mode_reglement_code =
'CHQ';
3041 $this->note_public =
'This is a comment (public)';
3042 $this->note_private =
'This is a comment (private)';
3044 $this->multicurrency_tx = 1;
3045 $this->multicurrency_code = $conf->currency;
3052 while ($xnbp < $nbp) {
3054 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
3056 $line->subprice = 100;
3057 $line->tva_tx = 19.6;
3058 $line->localtax1_tx = 0;
3059 $line->localtax2_tx = 0;
3061 $line->total_ht = 50;
3062 $line->total_ttc = 59.8;
3063 $line->total_tva = 9.8;
3064 $line->remise_percent = 50;
3066 $line->total_ht = 100;
3067 $line->total_ttc = 119.6;
3068 $line->total_tva = 19.6;
3069 $line->remise_percent = 00;
3071 $line->fk_product = $prodid;
3073 $this->lines[$xnbp] = $line;
3075 $this->total_ht += $line->total_ht;
3076 $this->total_tva += $line->total_tva;
3077 $this->total_ttc += $line->total_ttc;
3091 $sql =
'SELECT c.rowid, date_creation as datec, tms as datem, date_valid as date_validation, date_approve as datea, date_approve2 as datea2,';
3092 $sql .=
' fk_user_author, fk_user_modif, fk_user_valid, fk_user_approve, fk_user_approve2';
3093 $sql .=
' FROM '.$this->db->prefix().
'commande_fournisseur as c';
3094 $sql .=
' WHERE c.rowid = '.((int) $id);
3096 $result = $this->db->query($sql);
3098 if ($this->db->num_rows($result)) {
3099 $obj = $this->db->fetch_object($result);
3101 $this->
id = $obj->rowid;
3103 $this->user_creation_id = $obj->fk_user_author;
3104 $this->user_validation_id = $obj->fk_user_valid;
3105 $this->user_modification_id = $obj->fk_user_modif;
3106 $this->user_approve_id = $obj->fk_user_approve;
3107 $this->user_approve_id2 = $obj->fk_user_approve2;
3109 $this->date_creation = $this->db->jdate($obj->datec);
3110 $this->date_modification = $this->db->jdate($obj->datem);
3111 $this->date_approve = $this->db->jdate($obj->datea);
3112 $this->date_approve2 = $this->db->jdate($obj->datea2);
3113 $this->date_validation = $this->db->jdate($obj->date_validation);
3115 $this->db->free($result);
3130 global $conf, $user;
3132 $this->nb = array();
3135 $sql =
"SELECT count(co.rowid) as nb";
3136 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as co";
3137 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe as s ON co.fk_soc = s.rowid";
3138 if (!$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3139 $sql .=
" LEFT JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
3140 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
3143 $sql .=
" ".$clause.
" co.entity IN (".
getEntity(
'supplier_order').
")";
3145 $resql = $this->db->query($sql);
3147 while ($obj = $this->db->fetch_object($resql)) {
3148 $this->nb[
"supplier_orders"] = $obj->nb;
3150 $this->db->free($resql);
3154 $this->error = $this->db->error();
3170 global $conf, $langs;
3172 $sql =
"SELECT c.rowid, c.date_creation as datec, c.date_commande, c.fk_statut, c.date_livraison as delivery_date, c.total_ht";
3173 $sql .=
" FROM ".$this->db->prefix().
"commande_fournisseur as c";
3174 if (!$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3175 $sql .=
" JOIN ".$this->db->prefix().
"societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
3177 $sql .=
" WHERE c.entity = ".$conf->entity;
3178 if ($mode ===
'awaiting') {
3179 $sql .=
" AND c.fk_statut IN (".self::STATUS_ORDERSENT.
", ".self::STATUS_RECEIVED_PARTIALLY.
")";
3181 $sql .=
" AND c.fk_statut IN (".self::STATUS_VALIDATED.
", ".self::STATUS_ACCEPTED.
")";
3184 $sql .=
" AND c.fk_soc = ".((int) $user->socid);
3187 $resql = $this->db->query($sql);
3192 $response->warning_delay = $conf->commande->fournisseur->warning_delay / 60 / 60 / 24;
3193 $response->label = $langs->trans(
"SuppliersOrdersToProcess");
3194 $response->labelShort = $langs->trans(
"Opened");
3195 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=1,2&mainmenu=commercial&leftmenu=orders_suppliers';
3198 if ($mode ===
'awaiting') {
3199 $response->label = $langs->trans(
"SuppliersOrdersAwaitingReception");
3200 $response->labelShort = $langs->trans(
"AwaitingReception");
3201 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=3,4&mainmenu=commercial&leftmenu=orders_suppliers';
3204 while ($obj = $this->db->fetch_object($resql)) {
3205 $commandestatic->delivery_date = $this->db->jdate($obj->delivery_date);
3206 $commandestatic->date_commande = $this->db->jdate($obj->date_commande);
3207 $commandestatic->statut = $obj->fk_statut;
3209 $response->nbtodo++;
3210 $response->total += $obj->total_ht;
3212 if ($commandestatic->hasDelay()) {
3213 $response->nbtodolate++;
3219 $this->error = $this->db->error();
3234 if ($this->methode_commande_id > 0) {
3235 $sql =
"SELECT rowid, code, libelle as label";
3236 $sql .=
" FROM ".$this->db->prefix().
'c_input_method';
3237 $sql .=
" WHERE active=1 AND rowid = ".((int) $this->methode_commande_id);
3239 $resql = $this->db->query($sql);
3241 if ($this->db->num_rows($resql)) {
3242 $obj = $this->db->fetch_object($resql);
3244 $string = $langs->trans($obj->code);
3245 if ($string == $obj->code) {
3246 $string = $obj->label !=
'-' ? $obj->label :
'';
3269 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3271 global $conf, $langs;
3276 if (!empty($this->model_pdf)) {
3277 $modele = $this->model_pdf;
3283 if (empty($modele)) {
3286 $langs->load(
"suppliers");
3287 $outputlangs->load(
"products");
3289 $modelpath =
"core/modules/supplier_order/doc/";
3290 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3303 if (empty($this->lines)) {
3310 foreach ($this->lines as $line) {
3311 if ($line->fk_product > 0) {
3312 $idp = $obj->find_min_price_product_fournisseur($line->fk_product, $line->qty);
3315 if ($obj->delivery_time_days > $nb) {
3316 $nb = $obj->delivery_time_days;
3325 return $nb.
' '.$langs->trans(
'Days');
3338 return $user->hasRight(
"fournisseur",
"commande");
3353 'commande_fournisseur'
3370 'commande_fournisseurdet'
3387 if ($this->
statut == self::STATUS_ORDERSENT || $this->
statut == self::STATUS_RECEIVED_PARTIALLY) {
3389 if (!empty($this->delivery_date)) {
3390 $date_to_test = $this->delivery_date;
3391 return $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay);
3399 $date_to_test = $this->date_commande;
3401 return ($this->
statut > 0 && $this->
statut < 5) && $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay);
3414 global $conf, $langs;
3418 if ($this->
statut == self::STATUS_ORDERSENT || $this->
statut == self::STATUS_RECEIVED_PARTIALLY) {
3419 if (!empty($this->delivery_date)) {
3420 $text = $langs->trans(
"DeliveryDate").
' '.
dol_print_date($this->delivery_date,
'day');
3422 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3425 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3428 $text .=
' '.($conf->commande->fournisseur->warning_delay > 0 ?
'+' :
'-').
' '.round(abs($conf->commande->fournisseur->warning_delay) / 3600 / 24, 1).
' '.$langs->trans(
"days").
' < '.$langs->trans(
"Today");
3445 global $conf, $langs;
3447 if (isModEnabled(
"supplier_order")) {
3448 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
3450 $qtydelivered = array();
3451 $qtywished = array();
3454 $filter = array(
't.fk_commande'=>$this->
id);
3456 $filter[
't.status'] = 1;
3459 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
3461 $this->error = $supplierorderdispatch->error;
3462 $this->errors = $supplierorderdispatch->errors;
3465 if (is_array($supplierorderdispatch->lines) && count($supplierorderdispatch->lines) > 0) {
3466 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
3470 foreach ($supplierorderdispatch->lines as $line) {
3471 $qtydelivered[$line->fk_product] += $line->qty;
3473 foreach ($this->lines as $line) {
3478 $qtywished[$line->fk_product] += $line->qty;
3482 $diff_array = array_diff_assoc($qtydelivered, $qtywished);
3483 $keysinwishednotindelivered = array_diff(array_keys($qtywished), array_keys($qtydelivered));
3484 $keysindeliverednotinwished = array_diff(array_keys($qtydelivered), array_keys($qtywished));
3492 if (count($diff_array) == 0 && count($keysinwishednotindelivered) == 0 && count($keysindeliverednotinwished) == 0) {
3493 if ($closeopenorder) {
3495 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3503 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3514 if (count($diff_array) > 0) {
3518 foreach ($diff_array as $key => $value) {
3520 if ($qtydelivered[$key] >= $qtywished[$key]) {
3527 if ($close == count($diff_array)) {
3529 if ($closeopenorder) {
3530 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3537 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3545 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3553 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3575 $this->receptions = array();
3577 dol_syslog(get_class($this).
"::loadReceptions", LOG_DEBUG);
3579 $sql =
'SELECT cd.rowid, cd.fk_product,';
3580 $sql .=
' sum(cfd.qty) as qty';
3581 $sql .=
' FROM '.$this->db->prefix().
'commande_fournisseur_dispatch as cfd,';
3582 if ($filtre_statut >= 0) {
3583 $sql .=
' '.$this->db->prefix().
'reception as e,';
3585 $sql .=
' '.$this->db->prefix().
'commande_fournisseurdet as cd';
3587 if ($filtre_statut >= 0) {
3588 $sql .=
' cfd.fk_reception = e.rowid AND';
3590 $sql .=
' cfd.fk_commandefourndet = cd.rowid';
3591 $sql .=
' AND cd.fk_commande ='.((int) $this->
id);
3592 if (isset($this->fk_product) && !empty($this->fk_product) > 0) {
3593 $sql .=
' AND cd.fk_product = '.((int) $this->fk_product);
3595 if ($filtre_statut >= 0) {
3596 $sql .=
' AND e.fk_statut >= '.((int) $filtre_statut);
3598 $sql .=
' GROUP BY cd.rowid, cd.fk_product';
3600 $resql = $this->db->query($sql);
3602 $num = $this->db->num_rows($resql);
3605 $obj = $this->db->fetch_object($resql);
3606 empty($this->receptions[$obj->rowid]) ? $this->receptions[$obj->rowid] = $obj->qty : $this->receptions[$obj->rowid] += $obj->qty;
3609 $this->db->free($resql);
3613 $this->error = $this->db->lasterror();
3629 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3631 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3632 $return .=
'<div class="info-box info-box-sm">';
3633 $return .=
'<span class="info-box-icon bg-infobox-action">';
3635 $return .=
'</span>';
3636 $return .=
'<div class="info-box-content">';
3637 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
3638 if ($selected >= 0) {
3639 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3641 if (property_exists($this,
'socid') || property_exists($this,
'total_tva')) {
3642 $return .=
'<br><span class="info-box-label amount">'.$this->socid.
'</span>';
3644 if (property_exists($this,
'billed')) {
3645 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Billed").
' : </span><span class="info-box-label">'.
yn($this->billed).
'</span>';
3647 if (method_exists($this,
'getLibStatut')) {
3648 $return .=
'<br><div class="info-box-status">'.$this->getLibStatut(3).
'</div>';
3650 $return .=
'</div>';
3651 $return .=
'</div>';
3652 $return .=
'</div>';
3667 public $element =
'commande_fournisseurdet';
3672 public $table_element =
'commande_fournisseurdet';
3680 public $fk_commande;
3686 public $fk_parent_line;
3694 public $special_code = 0;
3704 public $fk_fournprice;
3714 public $ref_supplier;
3746 $sql =
'SELECT cd.rowid, cd.fk_commande, cd.fk_product, cd.product_type, cd.description, cd.qty, cd.tva_tx, cd.special_code,';
3747 $sql .=
' cd.localtax1_tx, cd.localtax2_tx, cd.localtax1_type, cd.localtax2_type, cd.ref as ref_supplier,';
3748 $sql .=
' cd.remise, cd.remise_percent, cd.subprice,';
3749 $sql .=
' cd.info_bits, cd.total_ht, cd.total_tva, cd.total_ttc,';
3750 $sql .=
' cd.total_localtax1, cd.total_localtax2,';
3751 $sql .=
' p.ref as product_ref, p.label as product_label, p.description as product_desc,';
3752 $sql .=
' cd.date_start, cd.date_end, cd.fk_unit,';
3753 $sql .=
' cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc,';
3754 $sql .=
' c.fk_soc as socid';
3755 $sql .=
' FROM '.$this->db->prefix().
'commande_fournisseur as c, '.$this->db->prefix().
'commande_fournisseurdet as cd';
3756 $sql .=
' LEFT JOIN '.$this->db->prefix().
'product as p ON cd.fk_product = p.rowid';
3757 $sql .=
' WHERE cd.fk_commande = c.rowid AND cd.rowid = '.((int) $rowid);
3759 $result = $this->db->query($sql);
3761 $objp = $this->db->fetch_object($result);
3763 if (!empty($objp)) {
3764 $this->
rowid = $objp->rowid;
3765 $this->
id = $objp->rowid;
3766 $this->fk_commande = $objp->fk_commande;
3767 $this->desc = $objp->description;
3768 $this->qty = $objp->qty;
3769 $this->ref_fourn = $objp->ref_supplier;
3770 $this->ref_supplier = $objp->ref_supplier;
3771 $this->subprice = $objp->subprice;
3772 $this->tva_tx = $objp->tva_tx;
3773 $this->localtax1_tx = $objp->localtax1_tx;
3774 $this->localtax2_tx = $objp->localtax2_tx;
3775 $this->localtax1_type = $objp->localtax1_type;
3776 $this->localtax2_type = $objp->localtax2_type;
3777 $this->remise = $objp->remise;
3778 $this->remise_percent = $objp->remise_percent;
3779 $this->fk_product = $objp->fk_product;
3780 $this->info_bits = $objp->info_bits;
3781 $this->total_ht = $objp->total_ht;
3782 $this->total_tva = $objp->total_tva;
3783 $this->total_localtax1 = $objp->total_localtax1;
3784 $this->total_localtax2 = $objp->total_localtax2;
3785 $this->total_ttc = $objp->total_ttc;
3786 $this->product_type = $objp->product_type;
3787 $this->special_code = $objp->special_code;
3789 $this->
ref = $objp->product_ref;
3791 $this->product_ref = $objp->product_ref;
3792 $this->product_label = $objp->product_label;
3793 $this->product_desc = $objp->product_desc;
3800 $sqlsearchpackage =
'SELECT rowid, packaging FROM '.$this->db->prefix().
"product_fournisseur_price";
3801 $sqlsearchpackage .=
' WHERE entity IN ('.getEntity(
'product_fournisseur_price').
")";
3802 $sqlsearchpackage .=
" AND fk_product = ".((int) $objp->fk_product);
3803 $sqlsearchpackage .=
" AND ref_fourn = '".$this->db->escape($objp->ref_supplier).
"'";
3804 $sqlsearchpackage .=
" AND quantity <= ".((float) $objp->qty);
3805 $sqlsearchpackage .=
" AND (packaging IS NULL OR packaging = 0 OR packaging <= ".((float) $objp->qty).
")";
3806 $sqlsearchpackage .=
" AND fk_soc = ".((int) $objp->socid);
3807 $sqlsearchpackage .=
" ORDER BY packaging ASC";
3808 $sqlsearchpackage .=
" LIMIT 1";
3810 $resqlsearchpackage = $this->db->query($sqlsearchpackage);
3811 if ($resqlsearchpackage) {
3812 $objsearchpackage = $this->db->fetch_object($resqlsearchpackage);
3813 if ($objsearchpackage) {
3814 $this->fk_fournprice = $objsearchpackage->rowid;
3815 $this->packaging = $objsearchpackage->packaging;
3818 $this->error = $this->db->lasterror();
3823 $this->date_start = $this->db->jdate($objp->date_start);
3824 $this->date_end = $this->db->jdate($objp->date_end);
3825 $this->fk_unit = $objp->fk_unit;
3827 $this->multicurrency_subprice = $objp->multicurrency_subprice;
3828 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
3829 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
3830 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
3834 $this->db->free($result);
3837 $this->error =
'Supplier order line with id='.$rowid.
' not found';
3838 dol_syslog(get_class($this).
"::fetch Error ".$this->error, LOG_ERR);
3855 global $conf, $user;
3859 dol_syslog(get_class($this).
"::insert rang=".$this->rang);
3862 if (empty($this->tva_tx)) {
3865 if (empty($this->localtax1_tx)) {
3866 $this->localtax1_tx = 0;
3868 if (empty($this->localtax2_tx)) {
3869 $this->localtax2_tx = 0;
3871 if (empty($this->localtax1_type)) {
3872 $this->localtax1_type =
'0';
3874 if (empty($this->localtax2_type)) {
3875 $this->localtax2_type =
'0';
3877 if (empty($this->total_localtax1)) {
3878 $this->total_localtax1 = 0;
3880 if (empty($this->total_localtax2)) {
3881 $this->total_localtax2 = 0;
3883 if (empty($this->rang)) {
3886 if (empty($this->remise_percent)) {
3887 $this->remise_percent = 0;
3889 if (empty($this->info_bits)) {
3890 $this->info_bits = 0;
3892 if (empty($this->special_code)) {
3893 $this->special_code = 0;
3895 if (empty($this->fk_parent_line)) {
3896 $this->fk_parent_line = 0;
3898 if (empty($this->pa_ht)) {
3903 if (!empty($this->multicurrency_code)) {
3906 if (empty($this->fk_multicurrency)) {
3907 $this->multicurrency_code = $conf->currency;
3908 $this->fk_multicurrency = 0;
3909 $this->multicurrency_tx = 1;
3913 if ($this->product_type < 0) {
3920 $sql =
'INSERT INTO '.$this->db->prefix().$this->table_element;
3921 $sql .=
" (fk_commande, label, description, date_start, date_end,";
3922 $sql .=
" fk_product, product_type, special_code, rang,";
3923 $sql .=
" qty, vat_src_code, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, remise_percent, subprice, ref,";
3924 $sql .=
" total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_unit,";
3925 $sql .=
" fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc,";
3926 $sql .=
" fk_parent_line)";
3927 $sql .=
" VALUES (".$this->fk_commande.
", '".$this->db->escape($this->label).
"','".$this->db->escape($this->desc).
"',";
3928 $sql .=
" ".($this->date_start ?
"'".$this->db->idate($this->date_start).
"'" :
"null").
",";
3929 $sql .=
" ".($this->date_end ?
"'".$this->db->idate($this->date_end).
"'" :
"null").
",";
3930 if ($this->fk_product) {
3931 $sql .= $this->fk_product.
",";
3935 $sql .=
"'".$this->db->escape($this->product_type).
"',";
3936 $sql .=
"'".$this->db->escape($this->special_code).
"',";
3937 $sql .=
"'".$this->db->escape($this->rang).
"',";
3938 $sql .=
"'".$this->db->escape($this->qty).
"', ";
3939 $sql .=
" ".(empty($this->vat_src_code) ?
"''" :
"'".$this->db->escape($this->vat_src_code).
"'").
",";
3940 $sql .=
" ".price2num($this->tva_tx).
", ";
3941 $sql .=
" ".price2num($this->localtax1_tx).
",";
3942 $sql .=
" ".price2num($this->localtax2_tx).
",";
3943 $sql .=
" '".$this->db->escape($this->localtax1_type).
"',";
3944 $sql .=
" '".$this->db->escape($this->localtax2_type).
"',";
3945 $sql .=
" ".((float) $this->remise_percent).
", ".
price2num($this->subprice,
'MU').
", '".$this->db->escape($this->ref_supplier).
"',";
3946 $sql .=
" ".price2num($this->total_ht).
",";
3947 $sql .=
" ".price2num($this->total_tva).
",";
3948 $sql .=
" ".price2num($this->total_localtax1).
",";
3949 $sql .=
" ".price2num($this->total_localtax2).
",";
3950 $sql .=
" ".price2num($this->total_ttc).
",";
3951 $sql .= ($this->fk_unit ?
"'".$this->db->escape($this->fk_unit).
"'" :
"null");
3952 $sql .=
", ".($this->fk_multicurrency ? ((int) $this->fk_multicurrency) :
"null");
3953 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
3954 $sql .=
", ".($this->multicurrency_subprice ?
price2num($this->multicurrency_subprice) :
'0');
3955 $sql .=
", ".($this->multicurrency_total_ht ?
price2num($this->multicurrency_total_ht) :
'0');
3956 $sql .=
", ".($this->multicurrency_total_tva ?
price2num($this->multicurrency_total_tva) :
'0');
3957 $sql .=
", ".($this->multicurrency_total_ttc ?
price2num($this->multicurrency_total_ttc) :
'0');
3958 $sql .=
", ".((!empty($this->fk_parent_line) && $this->fk_parent_line > 0) ? $this->fk_parent_line :
'null');
3961 dol_syslog(get_class($this).
"::insert", LOG_DEBUG);
3962 $resql = $this->db->query($sql);
3964 $this->
id = $this->db->last_insert_id($this->db->prefix().$this->table_element);
3965 $this->
rowid = $this->id;
3974 if (!$error && !$notrigger) {
3976 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_CREATE', $user);
3984 $this->db->commit();
3988 foreach ($this->errors as $errmsg) {
3989 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
3990 $this->errors[] = ($this->errors ?
', '.$errmsg : $errmsg);
3992 $this->db->rollback();
3995 $this->errors[] = $this->db->error();
3996 $this->db->rollback();
4015 $sql =
"UPDATE ".$this->db->prefix().$this->table_element.
" SET";
4016 $sql .=
" description='".$this->db->escape($this->desc).
"'";
4017 $sql .=
", ref='".$this->db->escape($this->ref_supplier).
"'";
4018 $sql .=
", subprice='".price2num($this->subprice).
"'";
4020 $sql .=
", remise_percent='".price2num($this->remise_percent).
"'";
4022 $sql .=
", vat_src_code = '".(empty($this->vat_src_code) ?
'' : $this->vat_src_code).
"'";
4023 $sql .=
", tva_tx='".price2num($this->tva_tx).
"'";
4024 $sql .=
", localtax1_tx='".price2num($this->localtax1_tx).
"'";
4025 $sql .=
", localtax2_tx='".price2num($this->localtax2_tx).
"'";
4026 $sql .=
", localtax1_type='".$this->db->escape($this->localtax1_type).
"'";
4027 $sql .=
", localtax2_type='".$this->db->escape($this->localtax2_type).
"'";
4028 $sql .=
", qty='".price2num($this->qty).
"'";
4029 $sql .=
", date_start=".(!empty($this->date_start) ?
"'".$this->db->idate($this->date_start).
"'" :
"null");
4030 $sql .=
", date_end=".(!empty($this->date_end) ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
4031 $sql .=
", info_bits='".$this->db->escape($this->info_bits).
"'";
4032 $sql .=
", total_ht='".price2num($this->total_ht).
"'";
4033 $sql .=
", total_tva='".price2num($this->total_tva).
"'";
4034 $sql .=
", total_localtax1='".price2num($this->total_localtax1).
"'";
4035 $sql .=
", total_localtax2='".price2num($this->total_localtax2).
"'";
4036 $sql .=
", total_ttc='".price2num($this->total_ttc).
"'";
4037 $sql .=
", product_type=".$this->product_type;
4038 $sql .=
", special_code=".(!empty($this->special_code) ? $this->special_code : 0);
4039 $sql .= ($this->fk_unit ?
", fk_unit='".$this->db->escape($this->fk_unit).
"'" :
", fk_unit=null");
4042 $sql .=
", multicurrency_subprice=".price2num($this->multicurrency_subprice);
4043 $sql .=
", multicurrency_total_ht=".price2num($this->multicurrency_total_ht);
4044 $sql .=
", multicurrency_total_tva=".price2num($this->multicurrency_total_tva);
4045 $sql .=
", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc);
4047 $sql .=
" WHERE rowid = ".((int) $this->
id);
4049 dol_syslog(get_class($this).
"::updateline", LOG_DEBUG);
4050 $resql = $this->db->query($sql);
4059 if (!$error && !$notrigger) {
4061 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_MODIFY', $user);
4063 $this->db->rollback();
4070 $this->db->commit();
4073 $this->db->rollback();
4077 $this->error = $this->db->lasterror();
4078 $this->db->rollback();
4089 public function delete($notrigger = 0)
4100 $this->db->rollback();
4104 $sql1 =
'UPDATE '.$this->db->prefix().
"commandedet SET fk_commandefourndet = NULL WHERE fk_commandefourndet=".((int) $this->
id);
4105 $resql = $this->db->query($sql1);
4107 $this->db->rollback();
4111 $sql2 =
'DELETE FROM '.$this->db->prefix().
"commande_fournisseurdet WHERE rowid=".((int) $this->
id);
4114 $resql = $this->db->query($sql2);
4118 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_DELETE', $user);
4126 $this->db->commit();
4130 foreach ($this->errors as $errmsg) {
4131 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
4132 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
4134 $this->db->rollback();
4137 $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.