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;
133 public $statuts_short;
140 public $date_creation;
142 public $date_approve;
143 public $date_approve2;
144 public $date_commande;
150 public $date_livraison;
155 public $delivery_date;
159 public $total_localtax1;
160 public $total_localtax2;
169 public $cond_reglement_id;
170 public $cond_reglement_code;
171 public $cond_reglement_label;
172 public $cond_reglement_doc;
182 public $mode_reglement_id;
187 public $mode_reglement_code;
192 public $mode_reglement;
193 public $user_author_id;
194 public $user_valid_id;
195 public $user_approve_id;
196 public $user_approve_id2;
200 public $extraparams = array();
205 public $lines = array();
215 public $linked_objects = array();
221 public $fk_multicurrency;
223 public $multicurrency_code;
224 public $multicurrency_tx;
225 public $multicurrency_total_ht;
226 public $multicurrency_total_tva;
227 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),
377 public function fetch($id, $ref =
'')
382 if (empty($id) && empty($ref)) {
386 $sql =
"SELECT c.rowid, c.entity, c.ref, ref_supplier, c.fk_soc, c.fk_statut, c.amount_ht, c.total_ht, c.total_ttc, c.total_tva,";
387 $sql .=
" c.localtax1, c.localtax2, ";
388 $sql .=
" c.date_creation, c.date_valid, c.date_approve, c.date_approve2,";
389 $sql .=
" c.fk_user_author, c.fk_user_valid, c.fk_user_approve, c.fk_user_approve2,";
390 $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,";
391 $sql .=
" c.fk_account,";
392 $sql .=
" c.note_private, c.note_public, c.model_pdf, c.extraparams, c.billed,";
393 $sql .=
" c.fk_multicurrency, c.multicurrency_code, c.multicurrency_tx, c.multicurrency_total_ht, c.multicurrency_total_tva, c.multicurrency_total_ttc,";
394 $sql .=
" cm.libelle as methode_commande,";
395 $sql .=
" cr.code as cond_reglement_code, cr.libelle as cond_reglement_label, cr.libelle_facture as cond_reglement_doc,";
396 $sql .=
" p.code as mode_reglement_code, p.libelle as mode_reglement_libelle";
397 $sql .=
', c.fk_incoterms, c.location_incoterms';
398 $sql .=
', i.libelle as label_incoterms';
399 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseur as c";
400 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_payment_term as cr ON c.fk_cond_reglement = cr.rowid";
401 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as p ON c.fk_mode_reglement = p.id";
402 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_input_method as cm ON cm.rowid = c.fk_input_method";
403 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON c.fk_incoterms = i.rowid';
406 $sql .=
" WHERE c.entity IN (".getEntity(
'supplier_order').
")";
408 $sql .=
" WHERE c.rowid=".((int) $id);
412 $sql .=
" AND c.ref='".$this->db->escape($ref).
"'";
415 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
416 $resql = $this->db->query($sql);
418 $obj = $this->db->fetch_object($resql);
420 $this->error =
'Bill with id '.$id.
' not found';
421 dol_syslog(get_class($this).
'::fetch '.$this->error);
425 $this->
id = $obj->rowid;
426 $this->entity = $obj->entity;
428 $this->
ref = $obj->ref;
429 $this->ref_supplier = $obj->ref_supplier;
430 $this->socid = $obj->fk_soc;
431 $this->fourn_id = $obj->fk_soc;
432 $this->
statut = $obj->fk_statut;
433 $this->status = $obj->fk_statut;
434 $this->billed = $obj->billed;
435 $this->user_author_id = $obj->fk_user_author;
436 $this->user_valid_id = $obj->fk_user_valid;
437 $this->user_approve_id = $obj->fk_user_approve;
438 $this->user_approve_id2 = $obj->fk_user_approve2;
439 $this->total_ht = $obj->total_ht;
440 $this->total_tva = $obj->total_tva;
441 $this->total_localtax1 = $obj->localtax1;
442 $this->total_localtax2 = $obj->localtax2;
443 $this->total_ttc = $obj->total_ttc;
444 $this->date_creation = $this->db->jdate($obj->date_creation);
445 $this->date_valid = $this->db->jdate($obj->date_valid);
446 $this->date_approve = $this->db->jdate($obj->date_approve);
447 $this->date_approve2 = $this->db->jdate($obj->date_approve2);
448 $this->date_commande = $this->db->jdate($obj->date_commande);
449 if (isset($obj->date_commande)) {
450 $this->date = $this->date_commande;
452 $this->date = $this->date_creation;
454 $this->date_livraison = $this->db->jdate($obj->delivery_date);
455 $this->delivery_date = $this->db->jdate($obj->delivery_date);
456 $this->remise_percent = $obj->remise_percent;
457 $this->methode_commande_id = $obj->fk_input_method;
458 $this->methode_commande = $obj->methode_commande;
460 $this->source = $obj->source;
461 $this->fk_project = $obj->fk_project;
462 $this->cond_reglement_id = $obj->fk_cond_reglement;
463 $this->cond_reglement_code = $obj->cond_reglement_code;
464 $this->cond_reglement = $obj->cond_reglement_label;
465 $this->cond_reglement_label = $obj->cond_reglement_label;
466 $this->cond_reglement_doc = $obj->cond_reglement_doc;
467 $this->fk_account = $obj->fk_account;
468 $this->mode_reglement_id = $obj->fk_mode_reglement;
469 $this->mode_reglement_code = $obj->mode_reglement_code;
470 $this->mode_reglement = $obj->mode_reglement_libelle;
471 $this->note = $obj->note_private;
472 $this->note_private = $obj->note_private;
473 $this->note_public = $obj->note_public;
474 $this->model_pdf = $obj->model_pdf;
475 $this->modelpdf = $obj->model_pdf;
478 $this->fk_incoterms = $obj->fk_incoterms;
479 $this->location_incoterms = $obj->location_incoterms;
480 $this->label_incoterms = $obj->label_incoterms;
483 $this->fk_multicurrency = $obj->fk_multicurrency;
484 $this->multicurrency_code = $obj->multicurrency_code;
485 $this->multicurrency_tx = $obj->multicurrency_tx;
486 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
487 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
488 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
490 $this->extraparams = isset($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
492 $this->db->free($resql);
499 $this->brouillon = 1;
513 $this->error = $this->db->error().
" sql=".$sql;
530 $this->lines = array();
532 $sql =
"SELECT l.rowid, l.fk_commande, l.ref as ref_supplier, l.fk_product, l.product_type, l.label, l.description, l.qty,";
533 $sql .=
" l.vat_src_code, l.tva_tx, l.remise_percent, l.subprice,";
534 $sql .=
" l.localtax1_tx, l. localtax2_tx, l.localtax1_type, l. localtax2_type, l.total_localtax1, l.total_localtax2,";
535 $sql .=
" l.total_ht, l.total_tva, l.total_ttc, l.info_bits, l.special_code, l.fk_parent_line, l.rang,";
536 $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,";
537 $sql .=
" l.fk_unit,";
538 $sql .=
" l.date_start, l.date_end,";
539 $sql .=
' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc';
540 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as l";
541 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON l.fk_product = p.rowid';
542 $sql .=
" WHERE l.fk_commande = ".((int) $this->
id);
544 $sql .=
' AND p.fk_product_type = 0';
546 $sql .=
" ORDER BY l.rang, l.rowid";
549 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
551 $result = $this->db->query($sql);
553 $num = $this->db->num_rows($result);
557 $objp = $this->db->fetch_object($result);
561 $line->id = $objp->rowid;
562 $line->fk_commande = $objp->fk_commande;
563 $line->desc = $objp->description;
564 $line->description = $objp->description;
565 $line->qty = $objp->qty;
566 $line->tva_tx = $objp->tva_tx;
567 $line->localtax1_tx = $objp->localtax1_tx;
568 $line->localtax2_tx = $objp->localtax2_tx;
569 $line->localtax1_type = $objp->localtax1_type;
570 $line->localtax2_type = $objp->localtax2_type;
571 $line->subprice = $objp->subprice;
572 $line->pu_ht = $objp->subprice;
573 $line->remise_percent = $objp->remise_percent;
575 $line->vat_src_code = $objp->vat_src_code;
576 $line->total_ht = $objp->total_ht;
577 $line->total_tva = $objp->total_tva;
578 $line->total_localtax1 = $objp->total_localtax1;
579 $line->total_localtax2 = $objp->total_localtax2;
580 $line->total_ttc = $objp->total_ttc;
581 $line->product_type = $objp->product_type;
583 $line->fk_product = $objp->fk_product;
585 $line->libelle = $objp->product_label;
586 $line->product_label = $objp->product_label;
587 $line->product_desc = $objp->product_desc;
588 $line->product_tobatch = $objp->product_tobatch;
589 $line->product_barcode = $objp->product_barcode;
591 $line->ref = $objp->product_ref;
592 $line->product_ref = $objp->product_ref;
593 $line->ref_fourn = $objp->ref_supplier;
594 $line->ref_supplier = $objp->ref_supplier;
596 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
601 $sqlsearchpackage =
'SELECT rowid, packaging FROM '.MAIN_DB_PREFIX.
"product_fournisseur_price";
602 $sqlsearchpackage .=
' WHERE entity IN ('.getEntity(
'product_fournisseur_price').
")";
603 $sqlsearchpackage .=
" AND fk_product = ".((int) $objp->fk_product);
604 $sqlsearchpackage .=
" AND ref_fourn = '".$this->db->escape($objp->ref_supplier).
"'";
605 $sqlsearchpackage .=
" AND quantity <= ".((float) $objp->qty);
606 $sqlsearchpackage .=
" AND (packaging IS NULL OR packaging = 0 OR packaging <= ".((float) $objp->qty).
")";
607 $sqlsearchpackage .=
" AND fk_soc = ".((int) $this->socid);
608 $sqlsearchpackage .=
" ORDER BY packaging ASC";
609 $sqlsearchpackage .=
" LIMIT 1";
611 $resqlsearchpackage = $this->db->query($sqlsearchpackage);
612 if ($resqlsearchpackage) {
613 $objsearchpackage = $this->db->fetch_object($resqlsearchpackage);
614 if ($objsearchpackage) {
615 $line->fk_fournprice = $objsearchpackage->rowid;
616 $line->packaging = $objsearchpackage->packaging;
619 $this->error = $this->db->lasterror();
624 $line->date_start = $this->db->jdate($objp->date_start);
625 $line->date_end = $this->db->jdate($objp->date_end);
626 $line->fk_unit = $objp->fk_unit;
629 $line->fk_multicurrency = $objp->fk_multicurrency;
630 $line->multicurrency_code = $objp->multicurrency_code;
631 $line->multicurrency_subprice = $objp->multicurrency_subprice;
632 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
633 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
634 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
636 $line->info_bits = $objp->info_bits;
637 $line->special_code = $objp->special_code;
638 $line->fk_parent_line = $objp->fk_parent_line;
640 $line->rang = $objp->rang;
644 $line->fetch_optionals();
646 $this->lines[$i] = $line;
650 $this->db->free($result);
654 $this->error = $this->db->error().
" sql=".$sql;
667 public function valid($user, $idwarehouse = 0, $notrigger = 0)
669 global $langs, $conf;
670 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
676 if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")))
677 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->hasRight(
"fournisseur",
"supplier_order_advance",
"validate"))) {
682 $soc->fetch($this->fourn_id);
685 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
692 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"commande_fournisseur";
693 $sql .=
" SET ref='".$this->db->escape($num).
"',";
694 $sql .=
" fk_statut = ".self::STATUS_VALIDATED.
",";
695 $sql .=
" date_valid='".$this->db->idate(
dol_now()).
"',";
696 $sql .=
" fk_user_valid = ".((int) $user->id);
697 $sql .=
" WHERE rowid = ".((int) $this->
id);
698 $sql .=
" AND fk_statut = ".self::STATUS_DRAFT;
700 $resql = $this->db->query($sql);
706 if (!$error && !$notrigger) {
708 $result = $this->
call_trigger(
'ORDER_SUPPLIER_VALIDATE', $user);
716 $this->oldref = $this->ref;
719 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
721 $sql =
'UPDATE '.MAIN_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).
"'";
722 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'fournisseur/commande/".$this->db->escape($this->
ref).
"' and entity = ".((int) $conf->entity);
723 $resql = $this->db->query($sql);
725 $error++; $this->error = $this->db->lasterror();
727 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'fournisseur/commande/".$this->db->escape($this->newref).
"'";
728 $sql .=
" WHERE filepath = 'fournisseur/commande/".$this->db->escape($this->
ref).
"' and entity = ".$conf->entity;
729 $resql = $this->db->query($sql);
731 $error++; $this->error = $this->db->lasterror();
737 $dirsource = $conf->fournisseur->commande->dir_output.
'/'.$oldref;
738 $dirdest = $conf->fournisseur->commande->dir_output.
'/'.$newref;
739 if (!$error && file_exists($dirsource)) {
740 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
742 if (@rename($dirsource, $dirdest)) {
745 $listoffiles =
dol_dir_list($conf->fournisseur->commande->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
746 foreach ($listoffiles as $fileentry) {
747 $dirsource = $fileentry[
'name'];
748 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
749 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
750 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
751 @rename($dirsource, $dirdest);
768 $this->db->rollback();
772 $this->error =
'NotAuthorized';
773 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
798 public function LibStatut($status, $mode = 0, $billed = 0)
801 global $conf, $langs, $hookmanager;
803 if (empty($this->statuts) || empty($this->statuts_short)) {
804 $langs->load(
'orders');
806 $this->statuts[0] =
'StatusSupplierOrderDraft';
807 $this->statuts[1] =
'StatusSupplierOrderValidated';
808 $this->statuts[2] =
'StatusSupplierOrderApproved';
809 if (empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) {
810 $this->statuts[3] =
'StatusSupplierOrderOnProcess';
812 $this->statuts[3] =
'StatusSupplierOrderOnProcessWithValidation';
814 $this->statuts[4] =
'StatusSupplierOrderReceivedPartially';
815 $this->statuts[5] =
'StatusSupplierOrderReceivedAll';
816 $this->statuts[6] =
'StatusSupplierOrderCanceled';
817 $this->statuts[7] =
'StatusSupplierOrderCanceled';
818 $this->statuts[9] =
'StatusSupplierOrderRefused';
821 $this->statuts_short[0] =
'StatusSupplierOrderDraftShort';
822 $this->statuts_short[1] =
'StatusSupplierOrderValidatedShort';
823 $this->statuts_short[2] =
'StatusSupplierOrderApprovedShort';
824 $this->statuts_short[3] =
'StatusSupplierOrderOnProcessShort';
825 $this->statuts_short[4] =
'StatusSupplierOrderReceivedPartiallyShort';
826 $this->statuts_short[5] =
'StatusSupplierOrderReceivedAllShort';
827 $this->statuts_short[6] =
'StatusSupplierOrderCanceledShort';
828 $this->statuts_short[7] =
'StatusSupplierOrderCanceledShort';
829 $this->statuts_short[9] =
'StatusSupplierOrderRefusedShort';
832 $statustrans = array(
844 $statusClass =
'status0';
845 if (!empty($statustrans[$status])) {
846 $statusClass = $statustrans[$status];
851 $billedtext =
' - '.$langs->trans(
"Billed");
853 if ($status == 5 && $billed) {
854 $statusClass =
'status6';
857 $statusLong = $langs->transnoentitiesnoconv($this->statuts[$status]).$billedtext;
858 $statusShort = $langs->transnoentitiesnoconv($this->statuts_short[$status]);
860 $parameters = array(
'status' => $status,
'mode' => $mode,
'billed' => $billed);
861 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
863 return $hookmanager->resPrint;
866 return dolGetStatus($statusLong, $statusShort,
'', $statusClass, $mode);
878 global $conf, $langs, $user;
880 $langs->loadLangs([
'bills',
'orders']);
883 $nofetch = !empty($params[
'nofetch']);
885 if ($user->hasRight(
"fournisseur",
"commande",
"read")) {
886 $datas[
'picto'] =
'<u class="paddingrightonly">'.$langs->trans(
"SupplierOrder").
'</u>';
887 if (isset($this->
statut)) {
888 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
890 if (!empty($this->
ref)) {
891 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
893 if (!empty($this->ref_supplier)) {
894 $datas[
'refsupplier'] =
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.$this->ref_supplier;
897 $langs->load(
'companies');
898 if (empty($this->thirdparty)) {
901 $datas[
'supplier'] =
'<br><b>'.$langs->trans(
'Supplier').
':</b> '.$this->thirdparty->getNomUrl(1,
'', 0, 1);
903 if (!empty($this->total_ht)) {
904 $datas[
'totalht'] =
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
906 if (!empty($this->total_tva)) {
907 $datas[
'totaltva'] =
'<br><b>'.$langs->trans(
'VAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
909 if (!empty($this->total_ttc)) {
910 $datas[
'totalttc'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
912 if (!empty($this->date)) {
913 $datas[
'date'] =
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->date,
'day');
915 if (!empty($this->delivery_date)) {
916 $datas[
'deliverydate'] =
'<br><b>'.$langs->trans(
'DeliveryDate').
':</b> '.
dol_print_date($this->delivery_date,
'dayhour');
932 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = 0)
934 global $langs, $conf, $user, $hookmanager;
939 'objecttype' => $this->element,
943 $classfortooltip =
'classfortooltip';
946 $classfortooltip =
'classforajaxtooltip';
947 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
953 $url = DOL_URL_ROOT.
'/fourn/commande/card.php?id='.$this->id;
955 if ($option !==
'nolink') {
957 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
958 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
959 $add_save_lastsearch_values = 1;
961 if ($add_save_lastsearch_values) {
962 $url .=
'&save_lastsearch_values=1';
967 if (empty($notooltip)) {
968 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
969 $label = $langs->trans(
"ShowOrder");
970 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
972 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
973 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
976 $linkstart =
'<a href="'.$url.
'"';
977 $linkstart .= $linkclose.
'>';
980 $result .= $linkstart;
982 $result .=
img_object(($notooltip ?
'' : $label), ($this->picto ? $this->picto :
'generic'), (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
984 if ($withpicto != 2) {
985 $result .= $this->ref;
989 if ($addlinktonotes) {
990 $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
993 $result .=
' <span class="note inline-block">';
994 $result .=
'<a href="'.DOL_URL_ROOT.
'/fourn/commande/note.php?id='.$this->
id.
'" class="classfortooltip" title="'.
dol_escape_htmltag($notetoshow).
'">';
999 $result .=
'</span>';
1004 $hookmanager->initHooks(array($this->element .
'dao'));
1005 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
1006 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1008 $result = $hookmanager->resPrint;
1010 $result .= $hookmanager->resPrint;
1025 global $db, $langs, $conf;
1026 $langs->load(
"orders");
1028 if (!empty($conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER)) {
1035 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
1037 foreach ($dirmodels as $reldir) {
1038 $dir =
dol_buildpath($reldir.
"core/modules/supplier_order/");
1041 $mybool |= @include_once $dir.$file;
1044 if ($mybool ===
false) {
1049 $obj =
new $classname();
1050 $numref = $obj->getNextValue($soc, $this);
1052 if ($numref !=
"") {
1055 $this->error = $obj->error;
1059 $this->error =
"Error_COMMANDE_SUPPLIER_ADDON_NotDefined";
1073 if ($this->billed) {
1079 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur SET billed = 1';
1082 if ($this->db->query($sql)) {
1085 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CLASSIFY_BILLED', $user);
1095 $this->db->commit();
1098 $this->db->rollback();
1104 $this->db->rollback();
1117 public function approve($user, $idwarehouse = 0, $secondlevel = 0)
1119 global $langs, $conf;
1120 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1126 if ($user->hasRight(
"fournisseur",
"commande",
"approuver")) {
1132 $soc =
new Societe($this->db);
1133 $soc->fetch($this->fourn_id);
1136 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
1144 $movetoapprovestatus =
true;
1147 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur";
1148 $sql .=
" SET ref='".$this->db->escape($num).
"',";
1149 if (empty($secondlevel)) {
1150 $sql .=
" date_approve='".$this->db->idate($now).
"',";
1151 $sql .=
" fk_user_approve = ".$user->id;
1152 if (!empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) && $this->total_ht >= $conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) {
1153 if (empty($this->user_approve_id2)) {
1154 $movetoapprovestatus =
false;
1155 $comment =
' (first level)';
1160 $sql .=
" date_approve2='".$this->db->idate($now).
"',";
1161 $sql .=
" fk_user_approve2 = ".((int) $user->id);
1162 if (empty($this->user_approve_id)) {
1163 $movetoapprovestatus =
false;
1165 $comment =
' (second level)';
1168 if ($movetoapprovestatus) {
1169 $sql .=
", fk_statut = ".self::STATUS_ACCEPTED;
1171 $sql .=
", fk_statut = ".self::STATUS_VALIDATED;
1173 $sql .=
" WHERE rowid = ".((int) $this->
id);
1174 $sql .=
" AND fk_statut = ".self::STATUS_VALIDATED;
1176 if ($this->db->query($sql)) {
1177 if (!empty($conf->global->SUPPLIER_ORDER_AUTOADD_USER_CONTACT)) {
1178 $result = $this->
add_contact($user->id,
'SALESREPFOLL',
'internal', 1);
1179 if ($result < 0 && $result != -2) {
1185 if (!$error && $movetoapprovestatus && isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER)) {
1186 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1187 $langs->load(
"agenda");
1189 $cpt = count($this->lines);
1190 for ($i = 0; $i < $cpt; $i++) {
1192 if ($this->lines[$i]->fk_product > 0) {
1193 $this->line = $this->lines[$i];
1195 $mouvP->origin = &$this;
1196 $mouvP->setOrigin($this->element, $this->
id);
1198 $up_ht_disc = $this->lines[$i]->subprice;
1199 if (!empty($this->lines[$i]->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) {
1200 $up_ht_disc =
price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100,
'MU');
1202 $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans(
"OrderApprovedInDolibarr", $this->ref));
1213 $result = $this->
call_trigger(
'ORDER_SUPPLIER_APPROVE', $user);
1221 $this->
ref = $this->newref;
1223 if ($movetoapprovestatus) {
1228 if (empty($secondlevel)) {
1229 $this->date_approve = $now;
1230 $this->user_approve_id = $user->id;
1233 $this->date_approve2 = $now;
1234 $this->user_approve_id2 = $user->id;
1237 $this->db->commit();
1240 $this->db->rollback();
1244 $this->db->rollback();
1245 $this->error = $this->db->lasterror();
1249 dol_syslog(get_class($this).
"::approve Not Authorized", LOG_ERR);
1262 global $conf, $langs;
1268 if ($user->hasRight(
"fournisseur",
"commande",
"approuver")) {
1272 $sql .=
" WHERE rowid = ".((int) $this->
id);
1274 if ($this->db->query($sql)) {
1279 $result = $this->
call_trigger(
'ORDER_SUPPLIER_REFUSE', $user);
1282 $this->db->rollback();
1284 $this->db->commit();
1289 $this->db->rollback();
1290 $this->error = $this->db->lasterror();
1291 dol_syslog(get_class($this).
"::refuse Error -1");
1295 dol_syslog(get_class($this).
"::refuse Not Authorized");
1309 public function Cancel($user, $idwarehouse = -1)
1312 global $langs, $conf;
1318 if ($user->hasRight(
"fournisseur",
"commande",
"commander")) {
1323 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur SET fk_statut = ".((int) $statut);
1324 $sql .=
" WHERE rowid = ".((int) $this->
id);
1325 dol_syslog(get_class($this).
"::cancel", LOG_DEBUG);
1326 if ($this->db->query($sql)) {
1330 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CANCEL', $user);
1337 $this->db->commit();
1340 $this->db->rollback();
1344 $this->db->rollback();
1345 $this->error = $this->db->lasterror();
1346 dol_syslog(get_class($this).
"::cancel ".$this->error);
1350 dol_syslog(get_class($this).
"::cancel Not Authorized");
1364 public function commande($user, $date, $methode, $comment =
'')
1369 if ($user->hasRight(
"fournisseur",
"commande",
"commander")) {
1372 $newnoteprivate = $this->note_private;
1374 $newnoteprivate =
dol_concatdesc($newnoteprivate, $langs->trans(
"Comment").
': '.$comment);
1377 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur";
1378 $sql .=
" SET fk_statut=".self::STATUS_ORDERSENT.
", fk_input_method=".$methode.
", date_commande='".$this->db->idate($date).
"', ";
1379 $sql .=
" note_private='".$this->db->escape($newnoteprivate).
"'";
1380 $sql .=
" WHERE rowid=".((int) $this->
id);
1382 dol_syslog(get_class($this).
"::commande", LOG_DEBUG);
1383 if ($this->db->query($sql)) {
1385 $this->methode_commande_id = $methode;
1386 $this->date_commande = $date;
1387 $this->context = array(
'comments' => $comment);
1390 $result = $this->
call_trigger(
'ORDER_SUPPLIER_SUBMIT', $user);
1397 $this->error = $this->db->lasterror();
1398 $this->errors[] = $this->db->lasterror();
1402 $this->db->commit();
1404 $this->db->rollback();
1408 $this->error = $langs->trans(
'NotAuthorized');
1409 $this->errors[] = $langs->trans(
'NotAuthorized');
1410 dol_syslog(get_class($this).
"::commande User not Authorized", LOG_WARNING);
1413 return ($error ? -1 : 1);
1423 public function create($user, $notrigger = 0)
1425 global $langs, $conf, $hookmanager;
1433 $date = ($this->date_commande ? $this->date_commande : $this->date);
1437 $delivery_date = empty($this->delivery_date) ? $this->date_livraison : $this->delivery_date;
1440 if (empty($this->source)) {
1445 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
1450 if (empty($this->fk_multicurrency)) {
1451 $this->multicurrency_code = $conf->currency;
1452 $this->fk_multicurrency = 0;
1453 $this->multicurrency_tx = 1;
1457 $this->brouillon = 1;
1461 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"commande_fournisseur (";
1463 $sql .=
", ref_supplier";
1464 $sql .=
", note_private";
1465 $sql .=
", note_public";
1468 $sql .=
", fk_projet";
1469 $sql .=
", date_creation";
1470 $sql .=
", date_livraison";
1471 $sql .=
", fk_user_author";
1472 $sql .=
", fk_statut";
1474 $sql .=
", model_pdf";
1475 $sql .=
", fk_mode_reglement";
1476 $sql .=
", fk_cond_reglement";
1477 $sql .=
", fk_account";
1478 $sql .=
", fk_incoterms, location_incoterms";
1479 $sql .=
", fk_multicurrency";
1480 $sql .=
", multicurrency_code";
1481 $sql .=
", multicurrency_tx";
1483 $sql .=
" VALUES (";
1485 $sql .=
", '".$this->db->escape($this->ref_supplier).
"'";
1486 $sql .=
", '".$this->db->escape($this->note_private).
"'";
1487 $sql .=
", '".$this->db->escape($this->note_public).
"'";
1488 $sql .=
", ".setEntity($this);
1489 $sql .=
", ".((int) $this->socid);
1490 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
1491 $sql .=
", '".$this->db->idate($date).
"'";
1492 $sql .=
", ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
"null");
1493 $sql .=
", ".((int) $user->id);
1494 $sql .=
", ".self::STATUS_DRAFT;
1495 $sql .=
", ".((int) $this->source);
1496 $sql .=
", '".$this->db->escape(
getDolGlobalString(
'COMMANDE_SUPPLIER_ADDON_PDF')).
"'";
1497 $sql .=
", ".($this->mode_reglement_id > 0 ? $this->mode_reglement_id :
'null');
1498 $sql .=
", ".($this->cond_reglement_id > 0 ? $this->cond_reglement_id :
'null');
1499 $sql .=
", ".($this->fk_account > 0 ? $this->fk_account :
'NULL');
1500 $sql .=
", ".(int) $this->fk_incoterms;
1501 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
1502 $sql .=
", ".(int) $this->fk_multicurrency;
1503 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1504 $sql .=
", ".(double) $this->multicurrency_tx;
1507 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1508 if ($this->db->query($sql)) {
1509 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"commande_fournisseur");
1512 $num = count($this->lines);
1515 for ($i = 0; $i < $num; $i++) {
1516 $line = $this->lines[$i];
1517 if (!is_object($line)) {
1518 $line = (object) $line;
1530 $line->localtax1_tx,
1531 $line->localtax2_tx,
1535 $line->remise_percent,
1538 $line->product_type,
1543 $line->array_options,
1545 $line->multicurrency_subprice,
1552 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
1553 $this->db->rollback();
1558 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur";
1559 $sql .=
" SET ref='(PROV".$this->id.
")'";
1560 $sql .=
" WHERE rowid=".((int) $this->
id);
1561 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1562 if ($this->db->query($sql)) {
1565 $this->
ref =
"(PROV".$this->id.
")";
1567 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
1568 $this->linked_objects = $this->linkedObjectsIds;
1572 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
1573 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
1574 if (is_array($tmp_origin_id)) {
1575 foreach ($tmp_origin_id as $origin_id) {
1584 $origin_id = $tmp_origin_id;
1602 if (!$error && !$notrigger) {
1604 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CREATE', $user);
1606 $this->db->rollback();
1614 $this->db->commit();
1617 $this->db->rollback();
1621 $this->error = $this->db->lasterror();
1622 $this->db->rollback();
1627 $this->error =
'Failed to get ID of inserted line';
1632 $this->error = $this->db->lasterror();
1633 $this->db->rollback();
1653 if (isset($this->
ref)) {
1654 $this->
ref = trim($this->
ref);
1656 if (isset($this->ref_supplier)) {
1657 $this->ref_supplier = trim($this->ref_supplier);
1659 if (isset($this->note_private)) {
1660 $this->note_private = trim($this->note_private);
1662 if (isset($this->note_public)) {
1663 $this->note_public = trim($this->note_public);
1665 if (isset($this->model_pdf)) {
1666 $this->model_pdf = trim($this->model_pdf);
1668 if (isset($this->import_key)) {
1669 $this->import_key = trim($this->import_key);
1673 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
1675 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1676 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
1677 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1678 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
1679 $sql .=
" date_commande=".(strval($this->date_commande) !=
'' ?
"'".$this->db->idate($this->date_commande).
"'" :
'null').
",";
1680 $sql .=
" date_valid=".(strval($this->date_validation) !=
'' ?
"'".$this->db->idate($this->date_validation).
"'" :
'null').
",";
1681 $sql .=
" total_tva=".(isset($this->total_tva) ? $this->total_tva :
"null").
",";
1682 $sql .=
" localtax1=".(isset($this->total_localtax1) ? $this->total_localtax1 :
"null").
",";
1683 $sql .=
" localtax2=".(isset($this->total_localtax2) ? $this->total_localtax2 :
"null").
",";
1684 $sql .=
" total_ht=".(isset($this->total_ht) ? $this->total_ht :
"null").
",";
1685 $sql .=
" total_ttc=".(isset($this->total_ttc) ? $this->total_ttc :
"null").
",";
1686 $sql .=
" fk_statut=".(isset($this->
statut) ? $this->
statut :
"null").
",";
1687 $sql .=
" fk_user_author=".(isset($this->user_author_id) ? $this->user_author_id :
"null").
",";
1688 $sql .=
" fk_user_valid=".(isset($this->user_valid) && $this->user_valid > 0 ? $this->user_valid :
"null").
",";
1689 $sql .=
" fk_projet=".(isset($this->fk_project) ? $this->fk_project :
"null").
",";
1690 $sql .=
" fk_cond_reglement=".(isset($this->cond_reglement_id) ? $this->cond_reglement_id :
"null").
",";
1691 $sql .=
" fk_mode_reglement=".(isset($this->mode_reglement_id) ? $this->mode_reglement_id :
"null").
",";
1692 $sql .=
" date_livraison=".(strval($this->delivery_date) !=
'' ?
"'".$this->db->idate($this->delivery_date).
"'" :
'null').
",";
1694 $sql .=
" fk_account=".($this->fk_account > 0 ? $this->fk_account :
"null").
",";
1696 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1697 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1698 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1699 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
1701 $sql .=
" WHERE rowid=".((int) $this->
id);
1705 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1706 $resql = $this->db->query($sql);
1709 $this->errors[] =
"Error ".$this->db->lasterror();
1719 if (!$error && !$notrigger) {
1721 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
1730 foreach ($this->errors as $errmsg) {
1731 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1732 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1734 $this->db->rollback();
1737 $this->db->commit();
1752 global $conf, $user, $hookmanager;
1759 foreach ($this->lines as $line) {
1760 $line->fetch_optionals();
1764 $objFrom = clone $this;
1767 if (!empty($socid) && $socid != $this->socid) {
1768 $objsoc =
new Societe($this->db);
1770 if ($objsoc->fetch($socid) > 0) {
1771 $this->socid = $objsoc->id;
1772 $this->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1773 $this->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1774 $this->fk_project = 0;
1775 $this->fk_delivery_address = 0;
1785 $this->user_author_id = $user->id;
1786 $this->user_valid = 0;
1787 $this->date_creation =
'';
1788 $this->date_validation =
'';
1789 $this->ref_supplier =
'';
1790 $this->user_approve_id =
'';
1791 $this->user_approve_id2 =
'';
1792 $this->date_approve =
'';
1793 $this->date_approve2 =
'';
1796 $this->context[
'createfromclone'] =
'createfromclone';
1797 $result = $this->
create($user, $notrigger);
1804 if (is_object($hookmanager)) {
1805 $parameters = array(
'objFrom'=>$objFrom);
1807 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1815 unset($this->context[
'createfromclone']);
1819 $this->db->commit();
1822 $this->db->rollback();
1856 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)
1858 global $langs, $mysoc, $conf;
1860 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");
1861 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1863 if ($this->
statut == self::STATUS_DRAFT) {
1864 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1873 if (empty($txtva)) {
1879 if (empty($txlocaltax1)) {
1882 if (empty($txlocaltax2)) {
1885 if (empty($remise_percent)) {
1886 $remise_percent = 0;
1889 $remise_percent =
price2num($remise_percent);
1892 $pu_ht_devise =
price2num($pu_ht_devise);
1894 if (!preg_match(
'/\((.*)\)/', $txtva)) {
1899 if ($price_base_type ==
'HT') {
1904 $desc = trim($desc);
1907 if ($qty < 0 && !$fk_product) {
1908 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Product"));
1914 if ($date_start && $date_end && $date_start > $date_end) {
1915 $langs->load(
"errors");
1916 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
1923 $product_type = $type;
1926 if ($fk_product > 0) {
1927 if (!empty($conf->global->SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY)) {
1929 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);
1931 if ($prod->fetch($fk_product) > 0) {
1932 $product_type = $prod->type;
1933 $label = $prod->label;
1937 $result = $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', (isset($this->fk_soc) ? $this->fk_soc : $this->socid));
1941 if ($result > 0 && ($origin ==
'commande' || $pu ===
'')) {
1942 $pu = $prod->fourn_pu;
1943 $ref_supplier = $prod->ref_supplier;
1945 if ($remise_percent == 0 && $prod->remise_percent != 0) {
1946 $remise_percent = $prod->remise_percent;
1950 $langs->load(
"errors");
1951 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
1952 $this->db->rollback();
1953 dol_syslog(get_class($this).
"::addline we did not found supplier price, so we can't guess unit price");
1958 if ($result == -1) {
1959 $langs->load(
"errors");
1960 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
1961 $this->db->rollback();
1962 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_DEBUG);
1966 $this->error = $prod->error;
1967 $this->db->rollback();
1968 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_ERR);
1972 $this->error = $prod->error;
1973 $this->db->rollback();
1979 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
1980 $prod =
new Product($this->db);
1981 $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', (empty($this->fk_soc) ? $this->socid : $this->fk_soc));
1983 if ($qty < $prod->packaging) {
1984 $qty = $prod->packaging;
1986 if (!empty($prod->packaging) && ($qty % $prod->packaging) > 0) {
1987 $coeff = intval($qty / $prod->packaging) + 1;
1988 $qty = $prod->packaging * $coeff;
1989 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'mesgs');
1995 if (isModEnabled(
"multicurrency") && $pu_ht_devise > 0) {
2004 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
2005 $vat_src_code = $reg[1];
2006 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
2014 $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);
2016 $total_ht = $tabprice[0];
2017 $total_tva = $tabprice[1];
2018 $total_ttc = $tabprice[2];
2019 $total_localtax1 = $tabprice[9];
2020 $total_localtax2 = $tabprice[10];
2021 $pu = $pu_ht = $tabprice[3];
2024 $multicurrency_total_ht = $tabprice[16];
2025 $multicurrency_total_tva = $tabprice[17];
2026 $multicurrency_total_ttc = $tabprice[18];
2027 $pu_ht_devise = $tabprice[19];
2029 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2030 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2034 $rang = $rangmax + 1;
2040 $this->line->context = $this->context;
2042 $this->line->fk_commande = $this->id;
2043 $this->line->label = $label;
2044 $this->line->ref_fourn = $ref_supplier;
2045 $this->line->ref_supplier = $ref_supplier;
2046 $this->line->desc = $desc;
2047 $this->line->qty = $qty;
2048 $this->line->tva_tx = $txtva;
2049 $this->line->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0);
2050 $this->line->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0);
2051 $this->line->localtax1_type = $localtax1_type;
2052 $this->line->localtax2_type = $localtax2_type;
2053 $this->line->fk_product = $fk_product;
2054 $this->line->product_type = $product_type;
2055 $this->line->remise_percent = $remise_percent;
2056 $this->line->subprice = $pu_ht;
2057 $this->line->rang = $rang;
2058 $this->line->info_bits = $info_bits;
2060 $this->line->vat_src_code = $vat_src_code;
2061 $this->line->total_ht = $total_ht;
2062 $this->line->total_tva = $total_tva;
2063 $this->line->total_localtax1 = $total_localtax1;
2064 $this->line->total_localtax2 = $total_localtax2;
2065 $this->line->total_ttc = $total_ttc;
2066 $this->line->product_type = $type;
2067 $this->line->special_code = (!empty($special_code) ? $special_code : 0);
2068 $this->line->origin = $origin;
2069 $this->line->origin_id = $origin_id;
2070 $this->line->fk_unit = $fk_unit;
2072 $this->line->date_start = $date_start;
2073 $this->line->date_end = $date_end;
2076 $this->line->fk_multicurrency = $this->fk_multicurrency;
2077 $this->line->multicurrency_code = $this->multicurrency_code;
2078 $this->line->multicurrency_subprice = $pu_ht_devise;
2079 $this->line->multicurrency_total_ht = $multicurrency_total_ht;
2080 $this->line->multicurrency_total_tva = $multicurrency_total_tva;
2081 $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
2083 $this->line->subprice = $pu_ht;
2084 $this->line->price = $this->line->subprice;
2086 $this->line->remise_percent = $remise_percent;
2088 if (is_array($array_options) && count($array_options) > 0) {
2089 $this->line->array_options = $array_options;
2092 $result = $this->line->insert($notrigger);
2095 if (!empty($fk_parent_line)) {
2097 } elseif ($rang > 0 && $rang <= count($this->lines)) {
2098 $linecount = count($this->lines);
2099 for ($ii = $rang; $ii <= $linecount; $ii++) {
2105 $result = $this->
update_price(1,
'auto', 0, $this->thirdparty);
2107 $this->db->commit();
2108 return $this->line->id;
2110 $this->db->rollback();
2114 $this->error = $this->line->error;
2115 $this->errors = $this->line->errors;
2116 dol_syslog(get_class($this).
"::addline error=".$this->error, LOG_ERR);
2117 $this->db->rollback();
2142 public function dispatchProduct($user, $product, $qty, $entrepot, $price = 0, $comment =
'', $eatby =
'', $sellby =
'', $batch =
'', $fk_commandefourndet = 0, $notrigger = 0, $fk_reception = 0)
2144 global $conf, $langs;
2147 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2150 if ($entrepot <= 0) {
2151 $this->error =
'ErrorBadValueForParameterWarehouse';
2155 $this->error =
'ErrorBadValueForParameterQty';
2159 $dispatchstatus = 1;
2160 if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) {
2161 $dispatchstatus = 0;
2168 if (($this->
statut == self::STATUS_ORDERSENT || $this->
statut == self::STATUS_RECEIVED_PARTIALLY || $this->
statut == self::STATUS_RECEIVED_COMPLETELY)) {
2171 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch";
2172 $sql .=
" (fk_commande, fk_product, qty, fk_entrepot, fk_user, datec, fk_commandefourndet, status, comment, eatby, sellby, batch, fk_reception) VALUES";
2173 $sql .=
" ('".$this->id.
"','".$product.
"','".$qty.
"',".($entrepot > 0 ?
"'".$entrepot.
"'" :
"null").
",'".$user->id.
"','".$this->db->idate($now).
"','".$fk_commandefourndet.
"', ".$dispatchstatus.
", '".$this->db->escape($comment).
"', ";
2174 $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");
2177 dol_syslog(get_class($this).
"::dispatchProduct", LOG_DEBUG);
2178 $resql = $this->db->query($sql);
2181 global $conf, $langs, $user;
2183 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_DISPATCH', $user);
2190 $this->error = $this->db->lasterror();
2195 if (!$error && $entrepot > 0 && isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) {
2199 $mouv->origin = &$this;
2200 $mouv->setOrigin($this->element, $this->
id);
2203 if (!empty($conf->global->SUPPLIER_ORDER_ALLOW_NEGATIVE_QTY_FOR_SUPPLIER_ORDER_RETURN) && $qty < 0) {
2204 $result = $mouv->livraison($user, $product, $entrepot, $qty*(-1), $price, $comment, $now, $eatby, $sellby, $batch, 0, $inventorycode);
2206 $result = $mouv->reception($user, $product, $entrepot, $qty, $price, $comment, $eatby, $sellby, $batch,
'', 0, $inventorycode);
2210 $this->error = $mouv->error;
2211 $this->errors = $mouv->errors;
2212 dol_syslog(get_class($this).
"::dispatchProduct ".$this->error.
" ".join(
',', $this->errors), LOG_ERR);
2219 $this->db->commit();
2222 $this->db->rollback();
2226 $this->error =
'BadStatusForObject';
2240 if ($this->
statut == 0) {
2243 if ($line->fetch($idline) <= 0) {
2249 foreach ($dispatchedLines as $dispatchLine) {
2250 if ($dispatchLine[
'orderlineid'] == $idline) {
2251 $this->error =
"LineAlreadyDispatched";
2252 $this->errors[] = $this->error;
2257 if ($line->delete($notrigger) > 0) {
2261 $this->error = $line->error;
2262 $this->errors = $line->errors;
2277 public function delete(
User $user, $notrigger = 0)
2279 global $langs, $conf;
2280 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2286 if (empty($notrigger)) {
2288 $result = $this->
call_trigger(
'ORDER_SUPPLIER_DELETE', $user);
2290 $this->errors[] =
'ErrorWhenRunningTrigger';
2291 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2292 $this->db->rollback();
2300 if (!empty($this->linkedObjects) && array_key_exists(
'reception', $this->linkedObjects)) {
2301 foreach ($this->linkedObjects[
'reception'] as $element) {
2302 if ($element->statut >= 0) {
2303 $this->errors[] = $langs->trans(
'ReceptionExist');
2310 $main = $this->db->prefix().
'commande_fournisseurdet';
2311 $ef = $main.
"_extrafields";
2312 $sql =
"DELETE FROM ".$this->db->sanitize($ef).
" WHERE fk_object IN (SELECT rowid FROM ".$this->db->sanitize($main).
" WHERE fk_commande = ".((int) $this->
id).
")";
2313 dol_syslog(get_class($this).
"::delete extrafields lines", LOG_DEBUG);
2314 if (!$this->db->query($sql)) {
2315 $this->error = $this->db->lasterror();
2316 $this->errors[] = $this->db->lasterror();
2321 $sql1 =
"UPDATE ".$this->db->prefix().
"commandedet SET fk_commandefourndet = NULL WHERE fk_commandefourndet IN (SELECT rowid FROM ".$this->db->sanitize($main).
" WHERE fk_commande = ".((int) $this->
id).
")";
2322 dol_syslog(__METHOD__.
" linked order lines", LOG_DEBUG);
2323 if (!$this->db->query($sql1)) {
2325 $this->error = $this->db->lasterror();
2326 $this->errors[] = $this->db->lasterror();
2330 $sql =
"DELETE FROM ".$this->db->prefix().
"commande_fournisseurdet WHERE fk_commande =".((int) $this->
id);
2331 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2332 if (!$this->db->query($sql)) {
2333 $this->error = $this->db->lasterror();
2334 $this->errors[] = $this->db->lasterror();
2338 $sql =
"DELETE FROM ".$this->db->prefix().
"commande_fournisseur WHERE rowid =".((int) $this->
id);
2339 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2340 if ($resql = $this->db->query($sql)) {
2341 if ($this->db->affected_rows($resql) < 1) {
2342 $this->error = $this->db->lasterror();
2343 $this->errors[] = $this->db->lasterror();
2347 $this->error = $this->db->lasterror();
2348 $this->errors[] = $this->db->lasterror();
2356 $this->error =
'FailToDeleteExtraFields';
2357 $this->errors[] =
'FailToDeleteExtraFields';
2359 dol_syslog(get_class($this).
"::delete error -4 ".$this->error, LOG_ERR);
2366 $this->error =
'FailToDeleteObjectLinked';
2367 $this->errors[] =
'FailToDeleteObjectLinked';
2377 if ($conf->fournisseur->commande->dir_output) {
2378 $dir = $conf->fournisseur->commande->dir_output.
"/".$ref;
2379 $file = $dir.
"/".$ref.
".pdf";
2380 if (file_exists($file)) {
2382 $this->error =
'ErrorFailToDeleteFile';
2383 $this->errors[] =
'ErrorFailToDeleteFile';
2387 if (file_exists($dir)) {
2390 $this->error =
'ErrorFailToDeleteDir';
2391 $this->errors[] =
'ErrorFailToDeleteDir';
2399 dol_syslog(get_class($this).
"::delete $this->id by $user->id", LOG_DEBUG);
2400 $this->db->commit();
2403 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2404 $this->db->rollback();
2418 $sql =
"SELECT rowid, libelle";
2419 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_input_method";
2420 $sql .=
" WHERE active = 1";
2422 $resql = $this->db->query($sql);
2425 $num = $this->db->num_rows($resql);
2426 $this->methodes_commande = array();
2428 $row = $this->db->fetch_row($resql);
2430 $this->methodes_commande[$row[0]] = $row[1];
2453 $sql =
"SELECT p.ref, p.label,";
2454 $sql .=
" e.rowid as warehouse_id, e.ref as entrepot,";
2455 $sql .=
" cfd.rowid as dispatchedlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status, cfd.fk_commandefourndet";
2456 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product as p,";
2457 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as cfd";
2458 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"entrepot as e ON cfd.fk_entrepot = e.rowid";
2459 $sql .=
" WHERE cfd.fk_commande = ".((int) $this->
id);
2460 $sql .=
" AND cfd.fk_product = p.rowid";
2462 $sql .=
" AND cfd.status = ".((int) $status);
2464 $sql .=
" ORDER BY cfd.rowid ASC";
2466 $resql = $this->db->query($sql);
2468 $num = $this->db->num_rows($resql);
2472 $objp = $this->db->fetch_object($resql);
2475 'id' => $objp->dispatchedlineid,
2476 'productid' => $objp->fk_product,
2477 'warehouseid' => $objp->warehouse_id,
2478 'qty' => $objp->qty,
2479 'orderlineid' => $objp->fk_commandefourndet
2486 dol_print_error($this->db,
'Failed to execute request to get dispatched lines');
2505 global $conf, $langs;
2512 $usercanreceive = 0;
2513 if (!isModEnabled(
'reception')) {
2514 $usercanreceive = $user->hasRight(
"fournisseur",
"commande",
"receptionner");
2516 $usercanreceive = $user->hasRight(
"reception",
"creer");
2519 if ($usercanreceive) {
2521 if ($type ==
'par') {
2523 } elseif ($type ==
'tot') {
2525 } elseif ($type ==
'nev') {
2527 } elseif ($type ==
'can') {
2531 dol_syslog(get_class($this).
"::Livraison Error -2", LOG_ERR);
2536 if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) {
2538 if (!$error && ($type ==
'tot')) {
2540 if (count($dispatchedlinearray) > 0) {
2543 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove';
2544 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove', LOG_DEBUG);
2547 if (!$error && !empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS_NEED_APPROVE) && ($type ==
'tot')) {
2549 if (count($dispatchedlinearray) > 0) {
2552 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied';
2553 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied', LOG_DEBUG);
2560 if (empty($error)) {
2563 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur";
2564 $sql .=
" SET fk_statut = ".((int) $statut);
2565 $sql .=
" WHERE rowid = ".((int) $this->
id);
2566 $sql .=
" AND fk_statut IN (".self::STATUS_ORDERSENT.
",".self::STATUS_RECEIVED_PARTIALLY.
")";
2568 dol_syslog(get_class($this).
"::Livraison", LOG_DEBUG);
2569 $resql = $this->db->query($sql);
2572 $old_statut = $this->statut;
2574 $this->actionmsg2 = $comment;
2577 $result_trigger = $this->
call_trigger(
'ORDER_SUPPLIER_RECEIVE', $user);
2578 if ($result_trigger < 0) {
2583 if (empty($error)) {
2584 $this->db->commit();
2586 $this->
statut = $old_statut;
2587 $this->db->rollback();
2588 $this->error = $this->db->lasterror();
2592 $this->db->rollback();
2593 $this->error = $this->db->lasterror();
2598 $this->error = $langs->trans(
'NotAuthorized');
2599 $this->errors[] = $langs->trans(
'NotAuthorized');
2600 dol_syslog(get_class($this).
"::Livraison Not Authorized");
2632 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
2637 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur";
2638 $sql .=
" SET date_livraison = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2639 $sql .=
" WHERE rowid = ".((int) $this->
id);
2642 $resql = $this->db->query($sql);
2644 $this->errors[] = $this->db->error();
2649 $this->oldcopy = clone $this;
2650 $this->date_livraison = $delivery_date;
2651 $this->delivery_date = $delivery_date;
2654 if (!$notrigger && empty($error)) {
2656 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2664 $this->db->commit();
2667 foreach ($this->errors as $errmsg) {
2668 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2669 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2671 $this->db->rollback();
2691 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
2696 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur";
2697 $sql .=
" SET fk_projet = ".($id_projet > 0 ? (int) $id_projet :
'null');
2698 $sql .=
" WHERE rowid = ".((int) $this->
id);
2701 $resql = $this->db->query($sql);
2703 $this->errors[] = $this->db->error();
2708 $this->oldcopy = clone $this;
2709 $this->fk_projet = $id_projet;
2710 $this->fk_project = $id_projet;
2713 if (!$notrigger && empty($error)) {
2715 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2723 $this->db->commit();
2726 foreach ($this->errors as $errmsg) {
2727 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2728 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2730 $this->db->rollback();
2748 $comclient =
new Commande($this->db);
2749 $comclient->fetch($comclientid);
2753 $this->lines = array();
2755 $num = count($comclient->lines);
2756 for ($i = 0; $i < $num; $i++) {
2757 $prod =
new Product($this->db);
2760 if ($prod->fetch($comclient->lines[$i]->fk_product) > 0) {
2761 $label = $prod->label;
2765 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"commande_fournisseurdet";
2766 $sql .=
" (fk_commande, label, description, fk_product, price, qty, tva_tx, localtax1_tx, localtax2_tx, remise_percent, subprice, remise, ref)";
2767 $sql .=
" VALUES (".((int) $idc).
", '".$this->db->escape($label).
"', '".$this->db->escape($comclient->lines[$i]->desc).
"'";
2768 $sql .=
",".$comclient->lines[$i]->fk_product.
", ".
price2num($comclient->lines[$i]->price,
'MU');
2769 $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);
2770 $sql .=
", '".price2num($comclient->lines[$i]->subprice,
'MT').
"','0', '".$this->db->escape($ref).
"');";
2771 if ($this->db->query($sql)) {
2788 global $conf, $langs;
2793 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur';
2794 $sql .=
" SET fk_statut = ".$status;
2795 $sql .=
" WHERE rowid = ".((int) $this->
id);
2797 dol_syslog(get_class($this).
"::setStatus", LOG_DEBUG);
2798 $resql = $this->db->query($sql);
2801 $triggerName = array();
2802 $triggerName[0] =
'DRAFT';
2803 $triggerName[1] =
'VALIDATED';
2804 $triggerName[2] =
'APPROVED';
2805 $triggerName[3] =
'ORDERED';
2806 $triggerName[4] =
'RECEIVED_PARTIALLY';
2807 $triggerName[5] =
'RECEIVED_COMPLETELY';
2808 $triggerName[6] =
'CANCELED';
2809 $triggerName[7] =
'CANCELED';
2810 $triggerName[9] =
'REFUSED';
2813 $result = $this->
call_trigger(
"ORDER_SUPPLIER_STATUS_".$triggerName[$status], $user);
2820 $this->error = $this->db->lasterror();
2821 dol_syslog(get_class($this).
"::setStatus ".$this->error);
2826 $this->db->commit();
2829 $this->db->rollback();
2857 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 =
'')
2859 global $mysoc, $conf, $langs;
2860 dol_syslog(get_class($this).
"::updateline $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $type, $fk_unit");
2861 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2865 if ($this->brouillon) {
2870 if (empty($info_bits)) {
2873 if (empty($txtva)) {
2876 if (empty($txlocaltax1)) {
2879 if (empty($txlocaltax2)) {
2882 if (empty($remise)) {
2885 if (empty($remise_percent)) {
2886 $remise_percent = 0;
2889 $remise_percent =
price2num($remise_percent);
2895 $pu_ht_devise =
price2num($pu_ht_devise);
2896 if (!preg_match(
'/\((.*)\)/', $txtva)) {
2906 if ($date_start && $date_end && $date_start > $date_end) {
2907 $langs->load(
"errors");
2908 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
2924 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
2925 $vat_src_code = $reg[1];
2926 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
2929 $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);
2930 $total_ht = $tabprice[0];
2931 $total_tva = $tabprice[1];
2932 $total_ttc = $tabprice[2];
2933 $total_localtax1 = $tabprice[9];
2934 $total_localtax2 = $tabprice[10];
2935 $pu_ht = $tabprice[3];
2936 $pu_tva = $tabprice[4];
2937 $pu_ttc = $tabprice[5];
2940 $multicurrency_total_ht = $tabprice[16];
2941 $multicurrency_total_tva = $tabprice[17];
2942 $multicurrency_total_ttc = $tabprice[18];
2943 $pu_ht_devise = $tabprice[19];
2945 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2946 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2950 $this->line->fetch($rowid);
2952 $oldline = clone $this->line;
2953 $this->line->oldline = $oldline;
2955 $this->line->context = $this->context;
2957 $this->line->fk_commande = $this->id;
2959 $this->line->desc = $desc;
2962 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
2963 if ($qty < $this->line->packaging) {
2964 $qty = $this->line->packaging;
2966 if (!empty($this->line->packaging) && ($qty % $this->line->packaging) > 0) {
2967 $coeff = intval($qty / $this->line->packaging) + 1;
2968 $qty = $this->line->packaging * $coeff;
2969 setEventMessage($langs->trans(
'QtyRecalculatedWithPackaging'),
'mesgs');
2974 $this->line->qty = $qty;
2975 $this->line->ref_supplier = $ref_supplier;
2977 $this->line->vat_src_code = $vat_src_code;
2978 $this->line->tva_tx = $txtva;
2979 $this->line->localtax1_tx = $txlocaltax1;
2980 $this->line->localtax2_tx = $txlocaltax2;
2981 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2982 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2983 $this->line->remise_percent = $remise_percent;
2984 $this->line->subprice = $pu_ht;
2985 $this->line->info_bits = $info_bits;
2986 $this->line->total_ht = $total_ht;
2987 $this->line->total_tva = $total_tva;
2988 $this->line->total_localtax1 = $total_localtax1;
2989 $this->line->total_localtax2 = $total_localtax2;
2990 $this->line->total_ttc = $total_ttc;
2991 $this->line->product_type = $type;
2992 $this->line->special_code = $oldline->special_code;
2993 $this->line->rang = $oldline->rang;
2994 $this->line->origin = $this->origin;
2995 $this->line->fk_unit = $fk_unit;
2997 $this->line->date_start = $date_start;
2998 $this->line->date_end = $date_end;
3001 $this->line->fk_multicurrency = $this->fk_multicurrency;
3002 $this->line->multicurrency_code = $this->multicurrency_code;
3003 $this->line->multicurrency_subprice = $pu_ht_devise;
3004 $this->line->multicurrency_total_ht = $multicurrency_total_ht;
3005 $this->line->multicurrency_total_tva = $multicurrency_total_tva;
3006 $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
3008 $this->line->subprice = $pu_ht;
3009 $this->line->price = $this->line->subprice;
3011 $this->line->remise_percent = $remise_percent;
3013 if (is_array($array_options) && count($array_options) > 0) {
3015 foreach ($array_options as $key => $value) {
3016 $this->line->array_options[$key] = $array_options[$key];
3020 $result = $this->line->update($notrigger);
3026 $this->db->commit();
3029 $this->errors[] = $this->line->error;
3030 $this->errors = array_merge($this->errors, $this->line->errors);
3031 $this->error = $this->db->lasterror();
3032 $this->db->rollback();
3036 $this->error =
"Order status makes operation forbidden";
3037 dol_syslog(get_class($this).
"::updateline ".$this->error, LOG_ERR);
3052 global $user, $langs, $conf;
3054 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
3056 dol_syslog(get_class($this).
"::initAsSpecimen");
3063 $sql =
"SELECT rowid";
3064 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
3065 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
3066 $sql .= $this->db->order(
"rowid",
"ASC");
3067 $sql .= $this->db->plimit(1);
3068 $resql = $this->db->query($sql);
3069 if ($resql && $this->db->num_rows($resql)) {
3070 $obj = $this->db->fetch_object($resql);
3071 $prodid = $obj->rowid;
3076 $this->
ref =
'SPECIMEN';
3077 $this->specimen = 1;
3080 $this->date_commande = $now;
3081 $this->date_lim_reglement = $this->date + 3600 * 24 * 30;
3082 $this->cond_reglement_code =
'RECEP';
3083 $this->mode_reglement_code =
'CHQ';
3085 $this->note_public =
'This is a comment (public)';
3086 $this->note_private =
'This is a comment (private)';
3088 $this->multicurrency_tx = 1;
3089 $this->multicurrency_code = $conf->currency;
3096 while ($xnbp < $nbp) {
3098 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
3100 $line->subprice = 100;
3102 $line->tva_tx = 19.6;
3103 $line->localtax1_tx = 0;
3104 $line->localtax2_tx = 0;
3106 $line->total_ht = 50;
3107 $line->total_ttc = 59.8;
3108 $line->total_tva = 9.8;
3109 $line->remise_percent = 50;
3111 $line->total_ht = 100;
3112 $line->total_ttc = 119.6;
3113 $line->total_tva = 19.6;
3114 $line->remise_percent = 00;
3116 $line->fk_product = $prodid;
3118 $this->lines[$xnbp] = $line;
3120 $this->total_ht += $line->total_ht;
3121 $this->total_tva += $line->total_tva;
3122 $this->total_ttc += $line->total_ttc;
3136 $sql =
'SELECT c.rowid, date_creation as datec, tms as datem, date_valid as date_validation, date_approve as datea, date_approve2 as datea2,';
3137 $sql .=
' fk_user_author, fk_user_modif, fk_user_valid, fk_user_approve, fk_user_approve2';
3138 $sql .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseur as c';
3139 $sql .=
' WHERE c.rowid = '.((int) $id);
3141 $result = $this->db->query($sql);
3143 if ($this->db->num_rows($result)) {
3144 $obj = $this->db->fetch_object($result);
3145 $this->
id = $obj->rowid;
3146 if ($obj->fk_user_author) {
3147 $this->user_creation_id = $obj->fk_user_author;
3149 if ($obj->fk_user_valid) {
3150 $this->user_validation_id = $obj->fk_user_valid;
3152 if ($obj->fk_user_modif) {
3153 $this->user_modification_id = $obj->fk_user_modif;
3155 if ($obj->fk_user_approve) {
3156 $this->user_approve_id = $obj->fk_user_approve;
3158 if ($obj->fk_user_approve2) {
3159 $this->user_approve_id2 = $obj->fk_user_approve2;
3162 $this->date_creation = $this->db->jdate($obj->datec);
3163 $this->date_modification = $this->db->jdate($obj->datem);
3164 $this->date_approve = $this->db->jdate($obj->datea);
3165 $this->date_approve2 = $this->db->jdate($obj->datea2);
3166 $this->date_validation = $this->db->jdate($obj->date_validation);
3168 $this->db->free($result);
3183 global $conf, $user;
3185 $this->nb = array();
3188 $sql =
"SELECT count(co.rowid) as nb";
3189 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseur as co";
3190 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON co.fk_soc = s.rowid";
3191 if (!$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3192 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
3193 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
3196 $sql .=
" ".$clause.
" co.entity IN (".
getEntity(
'supplier_order').
")";
3198 $resql = $this->db->query($sql);
3200 while ($obj = $this->db->fetch_object($resql)) {
3201 $this->nb[
"supplier_orders"] = $obj->nb;
3203 $this->db->free($resql);
3207 $this->error = $this->db->error();
3223 global $conf, $langs;
3225 $sql =
"SELECT c.rowid, c.date_creation as datec, c.date_commande, c.fk_statut, c.date_livraison as delivery_date, c.total_ht";
3226 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseur as c";
3227 if (!$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3228 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
3230 $sql .=
" WHERE c.entity = ".$conf->entity;
3231 if ($mode ===
'awaiting') {
3232 $sql .=
" AND c.fk_statut IN (".self::STATUS_ORDERSENT.
", ".self::STATUS_RECEIVED_PARTIALLY.
")";
3234 $sql .=
" AND c.fk_statut IN (".self::STATUS_VALIDATED.
", ".self::STATUS_ACCEPTED.
")";
3237 $sql .=
" AND c.fk_soc = ".((int) $user->socid);
3240 $resql = $this->db->query($sql);
3245 $response->warning_delay = $conf->commande->fournisseur->warning_delay / 60 / 60 / 24;
3246 $response->label = $langs->trans(
"SuppliersOrdersToProcess");
3247 $response->labelShort = $langs->trans(
"Opened");
3248 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=1,2&mainmenu=commercial&leftmenu=orders_suppliers';
3251 if ($mode ===
'awaiting') {
3252 $response->label = $langs->trans(
"SuppliersOrdersAwaitingReception");
3253 $response->labelShort = $langs->trans(
"AwaitingReception");
3254 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=3,4&mainmenu=commercial&leftmenu=orders_suppliers';
3257 while ($obj = $this->db->fetch_object($resql)) {
3258 $commandestatic->delivery_date = $this->db->jdate($obj->delivery_date);
3259 $commandestatic->date_commande = $this->db->jdate($obj->date_commande);
3260 $commandestatic->statut = $obj->fk_statut;
3262 $response->nbtodo++;
3263 $response->total += $obj->total_ht;
3265 if ($commandestatic->hasDelay()) {
3266 $response->nbtodolate++;
3272 $this->error = $this->db->error();
3287 if ($this->methode_commande_id > 0) {
3288 $sql =
"SELECT rowid, code, libelle as label";
3289 $sql .=
" FROM ".MAIN_DB_PREFIX.
'c_input_method';
3290 $sql .=
" WHERE active=1 AND rowid = ".((int) $this->methode_commande_id);
3292 $resql = $this->db->query($sql);
3294 if ($this->db->num_rows($resql)) {
3295 $obj = $this->db->fetch_object($resql);
3297 $string = $langs->trans($obj->code);
3298 if ($string == $obj->code) {
3299 $string = $obj->label !=
'-' ? $obj->label :
'';
3322 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3324 global $conf, $langs;
3329 if (!empty($this->model_pdf)) {
3330 $modele = $this->model_pdf;
3331 } elseif (!empty($conf->global->COMMANDE_SUPPLIER_ADDON_PDF)) {
3336 if (empty($modele)) {
3339 $langs->load(
"suppliers");
3340 $outputlangs->load(
"products");
3342 $modelpath =
"core/modules/supplier_order/doc/";
3343 $result = $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3356 if (empty($this->lines)) {
3363 foreach ($this->lines as $line) {
3364 if ($line->fk_product > 0) {
3365 $idp = $obj->find_min_price_product_fournisseur($line->fk_product, $line->qty);
3368 if ($obj->delivery_time_days > $nb) {
3369 $nb = $obj->delivery_time_days;
3378 return $nb.
' '.$langs->trans(
'Days');
3390 return $user->hasRight(
"fournisseur",
"commande");
3405 'commande_fournisseur'
3422 'commande_fournisseurdet'
3439 if (empty($this->delivery_date) && !empty($this->date_livraison)) {
3440 $this->delivery_date = $this->date_livraison;
3443 if ($this->
statut == self::STATUS_ORDERSENT || $this->
statut == self::STATUS_RECEIVED_PARTIALLY) {
3445 if (!empty($this->delivery_date)) {
3446 $date_to_test = $this->delivery_date;
3447 return $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay);
3455 $date_to_test = $this->date_commande;
3457 return ($this->
statut > 0 && $this->
statut < 5) && $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay);
3470 global $conf, $langs;
3472 if (empty($this->delivery_date) && !empty($this->date_livraison)) {
3473 $this->delivery_date = $this->date_livraison;
3478 if ($this->
statut == self::STATUS_ORDERSENT || $this->
statut == self::STATUS_RECEIVED_PARTIALLY) {
3479 if (!empty($this->delivery_date)) {
3480 $text = $langs->trans(
"DeliveryDate").
' '.
dol_print_date($this->delivery_date,
'day');
3482 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3485 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3488 $text .=
' '.($conf->commande->fournisseur->warning_delay > 0 ?
'+' :
'-').
' '.round(abs($conf->commande->fournisseur->warning_delay) / 3600 / 24, 1).
' '.$langs->trans(
"days").
' < '.$langs->trans(
"Today");
3505 global $conf, $langs;
3507 if (isModEnabled(
"supplier_order")) {
3508 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
3510 $qtydelivered = array();
3511 $qtywished = array();
3514 $filter = array(
't.fk_commande'=>$this->
id);
3515 if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) {
3516 $filter[
't.status'] = 1;
3519 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
3521 $this->error = $supplierorderdispatch->error; $this->errors = $supplierorderdispatch->errors;
3524 if (is_array($supplierorderdispatch->lines) && count($supplierorderdispatch->lines) > 0) {
3525 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
3529 foreach ($supplierorderdispatch->lines as $line) {
3530 $qtydelivered[$line->fk_product] += $line->qty;
3532 foreach ($this->lines as $line) {
3534 if (empty($conf->global->STOCK_SUPPORTS_SERVICES) && $line->product_type > 0) {
3537 $qtywished[$line->fk_product] += $line->qty;
3541 $diff_array = array_diff_assoc($qtydelivered, $qtywished);
3542 $keysinwishednotindelivered = array_diff(array_keys($qtywished), array_keys($qtydelivered));
3543 $keysindeliverednotinwished = array_diff(array_keys($qtydelivered), array_keys($qtywished));
3551 if (count($diff_array) == 0 && count($keysinwishednotindelivered) == 0 && count($keysindeliverednotinwished) == 0) {
3552 if ($closeopenorder) {
3554 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3562 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3568 } elseif (!empty($conf->global->SUPPLIER_ORDER_MORE_THAN_WISHED)) {
3573 if (count($diff_array) > 0) {
3577 foreach ($diff_array as $key => $value) {
3579 if ($qtydelivered[$key] >= $qtywished[$key]) {
3586 if ($close == count($diff_array)) {
3588 if ($closeopenorder) {
3589 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3596 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3604 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3612 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3634 $this->receptions = array();
3636 dol_syslog(get_class($this).
"::loadReceptions", LOG_DEBUG);
3638 $sql =
'SELECT cd.rowid, cd.fk_product,';
3639 $sql .=
' sum(cfd.qty) as qty';
3640 $sql .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseur_dispatch as cfd,';
3641 if ($filtre_statut >= 0) {
3642 $sql .=
' '.MAIN_DB_PREFIX.
'reception as e,';
3644 $sql .=
' '.MAIN_DB_PREFIX.
'commande_fournisseurdet as cd';
3646 if ($filtre_statut >= 0) {
3647 $sql .=
' cfd.fk_reception = e.rowid AND';
3649 $sql .=
' cfd.fk_commandefourndet = cd.rowid';
3650 $sql .=
' AND cd.fk_commande ='.((int) $this->
id);
3651 if (isset($this->fk_product) && !empty($this->fk_product) > 0) {
3652 $sql .=
' AND cd.fk_product = '.((int) $this->fk_product);
3654 if ($filtre_statut >= 0) {
3655 $sql .=
' AND e.fk_statut >= '.((int) $filtre_statut);
3657 $sql .=
' GROUP BY cd.rowid, cd.fk_product';
3659 $resql = $this->db->query($sql);
3661 $num = $this->db->num_rows($resql);
3664 $obj = $this->db->fetch_object($resql);
3665 empty($this->receptions[$obj->rowid]) ? $this->receptions[$obj->rowid] = $obj->qty : $this->receptions[$obj->rowid] += $obj->qty;
3668 $this->db->free($resql);
3672 $this->error = $this->db->lasterror();
3688 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3690 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3691 $return .=
'<div class="info-box info-box-sm">';
3692 $return .=
'<span class="info-box-icon bg-infobox-action">';
3694 $return .=
'</span>';
3695 $return .=
'<div class="info-box-content">';
3696 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
3697 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3698 if (property_exists($this,
'socid') || property_exists($this,
'total_tva')) {
3699 $return .=
'<br><span class="info-box-label amount">'.$this->socid.
'</span>';
3701 if (property_exists($this,
'billed')) {
3702 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Billed").
' : </span><span class="info-box-label">'.
yn($this->billed).
'</span>';
3704 if (method_exists($this,
'getLibStatut')) {
3705 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).
'</div>';
3707 $return .=
'</div>';
3708 $return .=
'</div>';
3709 $return .=
'</div>';
3724 public $element =
'commande_fournisseurdet';
3729 public $table_element =
'commande_fournisseurdet';
3737 public $fk_commande;
3743 public $fk_parent_line;
3751 public $special_code = 0;
3768 public $ref_supplier;
3800 $sql =
'SELECT cd.rowid, cd.fk_commande, cd.fk_product, cd.product_type, cd.description, cd.qty, cd.tva_tx, cd.special_code,';
3801 $sql .=
' cd.localtax1_tx, cd.localtax2_tx, cd.localtax1_type, cd.localtax2_type, cd.ref as ref_supplier,';
3802 $sql .=
' cd.remise, cd.remise_percent, cd.subprice,';
3803 $sql .=
' cd.info_bits, cd.total_ht, cd.total_tva, cd.total_ttc,';
3804 $sql .=
' cd.total_localtax1, cd.total_localtax2,';
3805 $sql .=
' p.ref as product_ref, p.label as product_label, p.description as product_desc,';
3806 $sql .=
' cd.date_start, cd.date_end, cd.fk_unit,';
3807 $sql .=
' cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc,';
3808 $sql .=
' c.fk_soc as socid';
3809 $sql .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseur as c, '.MAIN_DB_PREFIX.
'commande_fournisseurdet as cd';
3810 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON cd.fk_product = p.rowid';
3811 $sql .=
' WHERE cd.fk_commande = c.rowid AND cd.rowid = '.((int) $rowid);
3813 $result = $this->db->query($sql);
3815 $objp = $this->db->fetch_object($result);
3817 if (!empty($objp)) {
3818 $this->
rowid = $objp->rowid;
3819 $this->
id = $objp->rowid;
3820 $this->fk_commande = $objp->fk_commande;
3821 $this->desc = $objp->description;
3822 $this->qty = $objp->qty;
3823 $this->ref_fourn = $objp->ref_supplier;
3824 $this->ref_supplier = $objp->ref_supplier;
3825 $this->subprice = $objp->subprice;
3826 $this->tva_tx = $objp->tva_tx;
3827 $this->localtax1_tx = $objp->localtax1_tx;
3828 $this->localtax2_tx = $objp->localtax2_tx;
3829 $this->localtax1_type = $objp->localtax1_type;
3830 $this->localtax2_type = $objp->localtax2_type;
3831 $this->remise = $objp->remise;
3832 $this->remise_percent = $objp->remise_percent;
3833 $this->fk_product = $objp->fk_product;
3834 $this->info_bits = $objp->info_bits;
3835 $this->total_ht = $objp->total_ht;
3836 $this->total_tva = $objp->total_tva;
3837 $this->total_localtax1 = $objp->total_localtax1;
3838 $this->total_localtax2 = $objp->total_localtax2;
3839 $this->total_ttc = $objp->total_ttc;
3840 $this->product_type = $objp->product_type;
3841 $this->special_code = $objp->special_code;
3843 $this->
ref = $objp->product_ref;
3845 $this->product_ref = $objp->product_ref;
3846 $this->product_label = $objp->product_label;
3847 $this->product_desc = $objp->product_desc;
3849 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
3854 $sqlsearchpackage =
'SELECT rowid, packaging FROM '.MAIN_DB_PREFIX.
"product_fournisseur_price";
3855 $sqlsearchpackage .=
' WHERE entity IN ('.getEntity(
'product_fournisseur_price').
")";
3856 $sqlsearchpackage .=
" AND fk_product = ".((int) $objp->fk_product);
3857 $sqlsearchpackage .=
" AND ref_fourn = '".$this->db->escape($objp->ref_supplier).
"'";
3858 $sqlsearchpackage .=
" AND quantity <= ".((float) $objp->qty);
3859 $sqlsearchpackage .=
" AND (packaging IS NULL OR packaging = 0 OR packaging <= ".((float) $objp->qty).
")";
3860 $sqlsearchpackage .=
" AND fk_soc = ".((int) $objp->socid);
3861 $sqlsearchpackage .=
" ORDER BY packaging ASC";
3862 $sqlsearchpackage .=
" LIMIT 1";
3864 $resqlsearchpackage = $this->db->query($sqlsearchpackage);
3865 if ($resqlsearchpackage) {
3866 $objsearchpackage = $this->db->fetch_object($resqlsearchpackage);
3867 if ($objsearchpackage) {
3868 $this->fk_fournprice = $objsearchpackage->rowid;
3869 $this->packaging = $objsearchpackage->packaging;
3872 $this->error = $this->db->lasterror();
3877 $this->date_start = $this->db->jdate($objp->date_start);
3878 $this->date_end = $this->db->jdate($objp->date_end);
3879 $this->fk_unit = $objp->fk_unit;
3881 $this->multicurrency_subprice = $objp->multicurrency_subprice;
3882 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
3883 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
3884 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
3888 $this->db->free($result);
3891 $this->error =
'Supplier order line with id='.$rowid.
' not found';
3892 dol_syslog(get_class($this).
"::fetch Error ".$this->error, LOG_ERR);
3909 global $conf, $user;
3913 dol_syslog(get_class($this).
"::insert rang=".$this->rang);
3916 if (empty($this->tva_tx)) {
3919 if (empty($this->localtax1_tx)) {
3920 $this->localtax1_tx = 0;
3922 if (empty($this->localtax2_tx)) {
3923 $this->localtax2_tx = 0;
3925 if (empty($this->localtax1_type)) {
3926 $this->localtax1_type =
'0';
3928 if (empty($this->localtax2_type)) {
3929 $this->localtax2_type =
'0';
3931 if (empty($this->total_localtax1)) {
3932 $this->total_localtax1 = 0;
3934 if (empty($this->total_localtax2)) {
3935 $this->total_localtax2 = 0;
3937 if (empty($this->rang)) {
3940 if (empty($this->remise_percent)) {
3941 $this->remise_percent = 0;
3943 if (empty($this->info_bits)) {
3944 $this->info_bits = 0;
3946 if (empty($this->special_code)) {
3947 $this->special_code = 0;
3949 if (empty($this->fk_parent_line)) {
3950 $this->fk_parent_line = 0;
3952 if (empty($this->pa_ht)) {
3957 if (!empty($this->multicurrency_code)) {
3960 if (empty($this->fk_multicurrency)) {
3961 $this->multicurrency_code = $conf->currency;
3962 $this->fk_multicurrency = 0;
3963 $this->multicurrency_tx = 1;
3967 if ($this->product_type < 0) {
3974 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element;
3975 $sql .=
" (fk_commande, label, description, date_start, date_end,";
3976 $sql .=
" fk_product, product_type, special_code, rang,";
3977 $sql .=
" qty, vat_src_code, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, remise_percent, subprice, ref,";
3978 $sql .=
" total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_unit,";
3979 $sql .=
" fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc";
3981 $sql .=
" VALUES (".$this->fk_commande.
", '".$this->db->escape($this->label).
"','".$this->db->escape($this->desc).
"',";
3982 $sql .=
" ".($this->date_start ?
"'".$this->db->idate($this->date_start).
"'" :
"null").
",";
3983 $sql .=
" ".($this->date_end ?
"'".$this->db->idate($this->date_end).
"'" :
"null").
",";
3984 if ($this->fk_product) {
3985 $sql .= $this->fk_product.
",";
3989 $sql .=
"'".$this->db->escape($this->product_type).
"',";
3990 $sql .=
"'".$this->db->escape($this->special_code).
"',";
3991 $sql .=
"'".$this->db->escape($this->rang).
"',";
3992 $sql .=
"'".$this->db->escape($this->qty).
"', ";
3993 $sql .=
" ".(empty($this->vat_src_code) ?
"''" :
"'".$this->db->escape($this->vat_src_code).
"'").
",";
3994 $sql .=
" ".price2num($this->tva_tx).
", ";
3995 $sql .=
" ".price2num($this->localtax1_tx).
",";
3996 $sql .=
" ".price2num($this->localtax2_tx).
",";
3997 $sql .=
" '".$this->db->escape($this->localtax1_type).
"',";
3998 $sql .=
" '".$this->db->escape($this->localtax2_type).
"',";
3999 $sql .=
" ".((float) $this->remise_percent).
", ".
price2num($this->subprice,
'MU').
", '".$this->db->escape($this->ref_supplier).
"',";
4000 $sql .=
" ".price2num($this->total_ht).
",";
4001 $sql .=
" ".price2num($this->total_tva).
",";
4002 $sql .=
" ".price2num($this->total_localtax1).
",";
4003 $sql .=
" ".price2num($this->total_localtax2).
",";
4004 $sql .=
" ".price2num($this->total_ttc).
",";
4005 $sql .= ($this->fk_unit ?
"'".$this->db->escape($this->fk_unit).
"'" :
"null");
4006 $sql .=
", ".($this->fk_multicurrency ? ((int) $this->fk_multicurrency) :
"null");
4007 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
4008 $sql .=
", ".($this->multicurrency_subprice ?
price2num($this->multicurrency_subprice) :
'0');
4009 $sql .=
", ".($this->multicurrency_total_ht ?
price2num($this->multicurrency_total_ht) :
'0');
4010 $sql .=
", ".($this->multicurrency_total_tva ?
price2num($this->multicurrency_total_tva) :
'0');
4011 $sql .=
", ".($this->multicurrency_total_ttc ?
price2num($this->multicurrency_total_ttc) :
'0');
4014 dol_syslog(get_class($this).
"::insert", LOG_DEBUG);
4015 $resql = $this->db->query($sql);
4017 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
4018 $this->
rowid = $this->id;
4027 if (!$error && !$notrigger) {
4029 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_CREATE', $user);
4037 $this->db->commit();
4041 foreach ($this->errors as $errmsg) {
4042 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
4043 $this->errors[] = ($this->errors ?
', '.$errmsg : $errmsg);
4045 $this->db->rollback();
4048 $this->errors[] = $this->db->error();
4049 $this->db->rollback();
4061 global $conf, $user;
4068 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
4069 $sql .=
" description='".$this->db->escape($this->desc).
"'";
4070 $sql .=
", ref='".$this->db->escape($this->ref_supplier).
"'";
4071 $sql .=
", subprice='".price2num($this->subprice).
"'";
4073 $sql .=
", remise_percent='".price2num($this->remise_percent).
"'";
4075 $sql .=
", vat_src_code = '".(empty($this->vat_src_code) ?
'' : $this->vat_src_code).
"'";
4076 $sql .=
", tva_tx='".price2num($this->tva_tx).
"'";
4077 $sql .=
", localtax1_tx='".price2num($this->localtax1_tx).
"'";
4078 $sql .=
", localtax2_tx='".price2num($this->localtax2_tx).
"'";
4079 $sql .=
", localtax1_type='".$this->db->escape($this->localtax1_type).
"'";
4080 $sql .=
", localtax2_type='".$this->db->escape($this->localtax2_type).
"'";
4081 $sql .=
", qty='".price2num($this->qty).
"'";
4082 $sql .=
", date_start=".(!empty($this->date_start) ?
"'".$this->db->idate($this->date_start).
"'" :
"null");
4083 $sql .=
", date_end=".(!empty($this->date_end) ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
4084 $sql .=
", info_bits='".$this->db->escape($this->info_bits).
"'";
4085 $sql .=
", total_ht='".price2num($this->total_ht).
"'";
4086 $sql .=
", total_tva='".price2num($this->total_tva).
"'";
4087 $sql .=
", total_localtax1='".price2num($this->total_localtax1).
"'";
4088 $sql .=
", total_localtax2='".price2num($this->total_localtax2).
"'";
4089 $sql .=
", total_ttc='".price2num($this->total_ttc).
"'";
4090 $sql .=
", product_type=".$this->product_type;
4091 $sql .=
", special_code=".(!empty($this->special_code) ? $this->special_code : 0);
4092 $sql .= ($this->fk_unit ?
", fk_unit='".$this->db->escape($this->fk_unit).
"'" :
", fk_unit=null");
4095 $sql .=
", multicurrency_subprice=".price2num($this->multicurrency_subprice);
4096 $sql .=
", multicurrency_total_ht=".price2num($this->multicurrency_total_ht);
4097 $sql .=
", multicurrency_total_tva=".price2num($this->multicurrency_total_tva);
4098 $sql .=
", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc);
4100 $sql .=
" WHERE rowid = ".((int) $this->
id);
4102 dol_syslog(get_class($this).
"::updateline", LOG_DEBUG);
4103 $resql = $this->db->query($sql);
4112 if (!$error && !$notrigger) {
4114 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_MODIFY', $user);
4116 $this->db->rollback();
4123 $this->db->commit();
4126 $this->db->rollback();
4130 $this->error = $this->db->lasterror();
4131 $this->db->rollback();
4142 public function delete($notrigger = 0)
4153 $this->db->rollback();
4157 $sql1 =
"UPDATE ".MAIN_DB_PREFIX.
"commandedet SET fk_commandefourndet = NULL WHERE fk_commandefourndet=".((int) $this->
id);
4158 $resql = $this->db->query($sql1);
4160 $this->db->rollback();
4164 $sql2 =
'DELETE FROM '.MAIN_DB_PREFIX.
"commande_fournisseurdet WHERE rowid=".((int) $this->
id);
4167 $resql = $this->db->query($sql2);
4171 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_DELETE', $user);
4179 $this->db->commit();
4183 foreach ($this->errors as $errmsg) {
4184 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
4185 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
4187 $this->db->rollback();
4190 $this->error = $this->db->lasterror();
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.
get_methodes_commande()
Get list of order methods.
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.
setErrorsFromObject($object)
setErrorsFromObject
updateRangOfLine($rowid, $rang)
Update position of line (rang)
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid='', $f_user=null, $notrigger=0)
Delete all links between an object $this.
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.
print $langs trans("Ref").' m m m statut
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 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
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.