37 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonorder.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
39 require_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
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;
257 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>0,
'notnull'=>1,
'position'=>10),
258 'ref' =>array(
'type'=>
'varchar(255)',
'label'=>
'Ref',
'enabled'=>1,
'visible'=>1,
'showoncombobox'=>1,
'position'=>25,
'searchall'=>1),
259 'ref_ext' =>array(
'type'=>
'varchar(255)',
'label'=>
'Ref ext',
'enabled'=>1,
'visible'=>0,
'position'=>35),
260 'ref_supplier' =>array(
'type'=>
'varchar(255)',
'label'=>
'RefOrderSupplierShort',
'enabled'=>1,
'visible'=>1,
'position'=>40,
'searchall'=>1),
261 'fk_projet' =>array(
'type'=>
'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)',
'label'=>
'Project',
'enabled'=>
"isModEnabled('project')",
'visible'=>-1,
'position'=>45),
262 'date_valid' =>array(
'type'=>
'datetime',
'label'=>
'DateValidation',
'enabled'=>1,
'visible'=>-1,
'position'=>710),
263 'date_approve' =>array(
'type'=>
'datetime',
'label'=>
'DateApprove',
'enabled'=>1,
'visible'=>-1,
'position'=>720),
264 'date_approve2' =>array(
'type'=>
'datetime',
'label'=>
'DateApprove2',
'enabled'=>1,
'visible'=>3,
'position'=>725),
265 'date_commande' =>array(
'type'=>
'date',
'label'=>
'OrderDateShort',
'enabled'=>1,
'visible'=>1,
'position'=>70),
266 'date_livraison' =>array(
'type'=>
'datetime',
'label'=>
'DeliveryDate',
'enabled'=>
'empty($conf->global->ORDER_DISABLE_DELIVERY_DATE)',
'visible'=>1,
'position'=>74),
267 'fk_user_author' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserAuthor',
'enabled'=>1,
'visible'=>3,
'position'=>41),
268 'fk_user_modif' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>3,
'notnull'=>-1,
'position'=>80),
269 'fk_user_valid' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserValidation',
'enabled'=>1,
'visible'=>3,
'position'=>711),
270 'fk_user_approve' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserApproval',
'enabled'=>1,
'visible'=>3,
'position'=>721),
271 'fk_user_approve2' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserApproval2',
'enabled'=>1,
'visible'=>3,
'position'=>726),
272 'source' =>array(
'type'=>
'smallint(6)',
'label'=>
'Source',
'enabled'=>1,
'visible'=>3,
'notnull'=>1,
'position'=>100),
273 'billed' =>array(
'type'=>
'smallint(6)',
'label'=>
'Billed',
'enabled'=>1,
'visible'=>1,
'position'=>710),
274 'total_ht' =>array(
'type'=>
'double(24,8)',
'label'=>
'AmountHT',
'enabled'=>1,
'visible'=>1,
'position'=>130,
'isameasure'=>1),
275 'total_tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'AmountVAT',
'enabled'=>1,
'visible'=>1,
'position'=>135,
'isameasure'=>1),
276 'localtax1' =>array(
'type'=>
'double(24,8)',
'label'=>
'LT1',
'enabled'=>1,
'visible'=>3,
'position'=>140,
'isameasure'=>1),
277 'localtax2' =>array(
'type'=>
'double(24,8)',
'label'=>
'LT2',
'enabled'=>1,
'visible'=>3,
'position'=>145,
'isameasure'=>1),
278 'total_ttc' =>array(
'type'=>
'double(24,8)',
'label'=>
'AmountTTC',
'enabled'=>1,
'visible'=>-1,
'position'=>150,
'isameasure'=>1),
279 'note_public' =>array(
'type'=>
'html',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>750,
'searchall'=>1),
280 'note_private' =>array(
'type'=>
'html',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>0,
'position'=>760,
'searchall'=>1),
281 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'ModelPDF',
'enabled'=>1,
'visible'=>0,
'position'=>165),
282 'fk_input_method' =>array(
'type'=>
'integer',
'label'=>
'OrderMode',
'enabled'=>1,
'visible'=>3,
'position'=>170),
283 'fk_cond_reglement' =>array(
'type'=>
'integer',
'label'=>
'PaymentTerm',
'enabled'=>1,
'visible'=>3,
'position'=>175),
284 'fk_mode_reglement' =>array(
'type'=>
'integer',
'label'=>
'PaymentMode',
'enabled'=>1,
'visible'=>3,
'position'=>180),
285 'extraparams' =>array(
'type'=>
'varchar(255)',
'label'=>
'Extraparams',
'enabled'=>1,
'visible'=>0,
'position'=>190),
286 'fk_account' =>array(
'type'=>
'integer',
'label'=>
'BankAccount',
'enabled'=>
'isModEnabled("banque")',
'visible'=>3,
'position'=>200),
287 'fk_incoterms' =>array(
'type'=>
'integer',
'label'=>
'IncotermCode',
'enabled'=>1,
'visible'=>3,
'position'=>205),
288 'location_incoterms' =>array(
'type'=>
'varchar(255)',
'label'=>
'IncotermLocation',
'enabled'=>1,
'visible'=>3,
'position'=>210),
289 'fk_multicurrency' =>array(
'type'=>
'integer',
'label'=>
'Fk multicurrency',
'enabled'=>1,
'visible'=>0,
'position'=>215),
290 'multicurrency_code' =>array(
'type'=>
'varchar(255)',
'label'=>
'Currency',
'enabled'=>
'isModEnabled("multicurrency")',
'visible'=>-1,
'position'=>220),
291 'multicurrency_tx' =>array(
'type'=>
'double(24,8)',
'label'=>
'CurrencyRate',
'enabled'=>
'isModEnabled("multicurrency")',
'visible'=>-1,
'position'=>225),
292 'multicurrency_total_ht' =>array(
'type'=>
'double(24,8)',
'label'=>
'MulticurrencyAmountHT',
'enabled'=>
'isModEnabled("multicurrency")',
'visible'=>-1,
'position'=>230),
293 'multicurrency_total_tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'MulticurrencyAmountVAT',
'enabled'=>
'isModEnabled("multicurrency")',
'visible'=>-1,
'position'=>235),
294 'multicurrency_total_ttc' =>array(
'type'=>
'double(24,8)',
'label'=>
'MulticurrencyAmountTTC',
'enabled'=>
'isModEnabled("multicurrency")',
'visible'=>-1,
'position'=>240),
295 'date_creation' =>array(
'type'=>
'datetime',
'label'=>
'Date creation',
'enabled'=>1,
'visible'=>-1,
'position'=>500),
296 'fk_soc' =>array(
'type'=>
'integer:Societe:societe/class/societe.class.php',
'label'=>
'ThirdParty',
'enabled'=>
'isModEnabled("societe")',
'visible'=>1,
'notnull'=>1,
'position'=>50),
297 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>0,
'notnull'=>1,
'position'=>1000,
'index'=>1),
298 'tms'=>array(
'type'=>
'datetime',
'label'=>
"DateModificationShort",
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>501),
299 'last_main_doc' =>array(
'type'=>
'varchar(255)',
'label'=>
'LastMainDoc',
'enabled'=>1,
'visible'=>0,
'position'=>700),
300 'fk_statut' =>array(
'type'=>
'smallint(6)',
'label'=>
'Status',
'enabled'=>1,
'visible'=>1,
'position'=>701),
301 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>0,
'position'=>900),
376 public function fetch($id, $ref =
'')
381 if (empty($id) && empty($ref)) {
385 $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,";
386 $sql .=
" c.localtax1, c.localtax2, ";
387 $sql .=
" c.date_creation, c.date_valid, c.date_approve, c.date_approve2,";
388 $sql .=
" c.fk_user_author, c.fk_user_valid, c.fk_user_approve, c.fk_user_approve2,";
389 $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,";
390 $sql .=
" c.fk_account,";
391 $sql .=
" c.note_private, c.note_public, c.model_pdf, c.extraparams, c.billed,";
392 $sql .=
" c.fk_multicurrency, c.multicurrency_code, c.multicurrency_tx, c.multicurrency_total_ht, c.multicurrency_total_tva, c.multicurrency_total_ttc,";
393 $sql .=
" cm.libelle as methode_commande,";
394 $sql .=
" cr.code as cond_reglement_code, cr.libelle as cond_reglement_label, cr.libelle_facture as cond_reglement_doc,";
395 $sql .=
" p.code as mode_reglement_code, p.libelle as mode_reglement_libelle";
396 $sql .=
', c.fk_incoterms, c.location_incoterms';
397 $sql .=
', i.libelle as label_incoterms';
398 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseur as c";
399 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_payment_term as cr ON c.fk_cond_reglement = cr.rowid";
400 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as p ON c.fk_mode_reglement = p.id";
401 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_input_method as cm ON cm.rowid = c.fk_input_method";
402 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON c.fk_incoterms = i.rowid';
405 $sql .=
" WHERE c.entity IN (".getEntity(
'supplier_order').
")";
407 $sql .=
" WHERE c.rowid=".((int) $id);
411 $sql .=
" AND c.ref='".$this->db->escape($ref).
"'";
414 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
415 $resql = $this->db->query(
$sql);
417 $obj = $this->db->fetch_object($resql);
419 $this->error =
'Bill with id '.$id.
' not found';
420 dol_syslog(get_class($this).
'::fetch '.$this->error);
424 $this->
id = $obj->rowid;
425 $this->entity = $obj->entity;
427 $this->
ref = $obj->ref;
428 $this->ref_supplier = $obj->ref_supplier;
429 $this->socid = $obj->fk_soc;
430 $this->fourn_id = $obj->fk_soc;
431 $this->statut = $obj->fk_statut;
432 $this->status = $obj->fk_statut;
433 $this->billed = $obj->billed;
434 $this->user_author_id = $obj->fk_user_author;
435 $this->user_valid_id = $obj->fk_user_valid;
436 $this->user_approve_id = $obj->fk_user_approve;
437 $this->user_approve_id2 = $obj->fk_user_approve2;
438 $this->total_ht = $obj->total_ht;
439 $this->total_tva = $obj->total_tva;
440 $this->total_localtax1 = $obj->localtax1;
441 $this->total_localtax2 = $obj->localtax2;
442 $this->total_ttc = $obj->total_ttc;
443 $this->date_creation = $this->db->jdate($obj->date_creation);
444 $this->date_valid = $this->db->jdate($obj->date_valid);
445 $this->date_approve = $this->db->jdate($obj->date_approve);
446 $this->date_approve2 = $this->db->jdate($obj->date_approve2);
447 $this->date_commande = $this->db->jdate($obj->date_commande);
448 if (isset($obj->date_commande)) {
449 $this->date = $this->date_commande;
451 $this->date = $this->date_creation;
453 $this->date_livraison = $this->db->jdate($obj->delivery_date);
454 $this->delivery_date = $this->db->jdate($obj->delivery_date);
455 $this->remise_percent = $obj->remise_percent;
456 $this->methode_commande_id = $obj->fk_input_method;
457 $this->methode_commande = $obj->methode_commande;
459 $this->source = $obj->source;
460 $this->fk_project = $obj->fk_project;
461 $this->cond_reglement_id = $obj->fk_cond_reglement;
462 $this->cond_reglement_code = $obj->cond_reglement_code;
463 $this->cond_reglement = $obj->cond_reglement_label;
464 $this->cond_reglement_label = $obj->cond_reglement_label;
465 $this->cond_reglement_doc = $obj->cond_reglement_doc;
466 $this->fk_account = $obj->fk_account;
467 $this->mode_reglement_id = $obj->fk_mode_reglement;
468 $this->mode_reglement_code = $obj->mode_reglement_code;
469 $this->mode_reglement = $obj->mode_reglement_libelle;
470 $this->note = $obj->note_private;
471 $this->note_private = $obj->note_private;
472 $this->note_public = $obj->note_public;
473 $this->model_pdf = $obj->model_pdf;
474 $this->modelpdf = $obj->model_pdf;
477 $this->fk_incoterms = $obj->fk_incoterms;
478 $this->location_incoterms = $obj->location_incoterms;
479 $this->label_incoterms = $obj->label_incoterms;
482 $this->fk_multicurrency = $obj->fk_multicurrency;
483 $this->multicurrency_code = $obj->multicurrency_code;
484 $this->multicurrency_tx = $obj->multicurrency_tx;
485 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
486 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
487 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
489 $this->extraparams = isset($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
491 $this->db->free($resql);
497 if ($this->statut == 0) {
498 $this->brouillon = 1;
512 $this->error = $this->db->error().
" sql=".
$sql;
529 $this->lines = array();
531 $sql =
"SELECT l.rowid, l.fk_commande, l.ref as ref_supplier, l.fk_product, l.product_type, l.label, l.description, l.qty,";
532 $sql .=
" l.vat_src_code, l.tva_tx, l.remise_percent, l.subprice,";
533 $sql .=
" l.localtax1_tx, l. localtax2_tx, l.localtax1_type, l. localtax2_type, l.total_localtax1, l.total_localtax2,";
534 $sql .=
" l.total_ht, l.total_tva, l.total_ttc, l.special_code, l.fk_parent_line, l.rang,";
535 $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,";
536 $sql .=
" l.fk_unit,";
537 $sql .=
" l.date_start, l.date_end,";
538 $sql .=
' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc';
539 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as l";
540 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON l.fk_product = p.rowid';
541 $sql .=
" WHERE l.fk_commande = ".((int) $this->
id);
543 $sql .=
' AND p.fk_product_type = 0';
545 $sql .=
" ORDER BY l.rang, l.rowid";
548 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
550 $result = $this->db->query(
$sql);
552 $num = $this->db->num_rows($result);
556 $objp = $this->db->fetch_object($result);
560 $line->id = $objp->rowid;
561 $line->fk_commande = $objp->fk_commande;
562 $line->desc = $objp->description;
563 $line->description = $objp->description;
564 $line->qty = $objp->qty;
565 $line->tva_tx = $objp->tva_tx;
566 $line->localtax1_tx = $objp->localtax1_tx;
567 $line->localtax2_tx = $objp->localtax2_tx;
568 $line->localtax1_type = $objp->localtax1_type;
569 $line->localtax2_type = $objp->localtax2_type;
570 $line->subprice = $objp->subprice;
571 $line->pu_ht = $objp->subprice;
572 $line->remise_percent = $objp->remise_percent;
574 $line->vat_src_code = $objp->vat_src_code;
575 $line->total_ht = $objp->total_ht;
576 $line->total_tva = $objp->total_tva;
577 $line->total_localtax1 = $objp->total_localtax1;
578 $line->total_localtax2 = $objp->total_localtax2;
579 $line->total_ttc = $objp->total_ttc;
580 $line->product_type = $objp->product_type;
582 $line->fk_product = $objp->fk_product;
584 $line->libelle = $objp->product_label;
585 $line->product_label = $objp->product_label;
586 $line->product_desc = $objp->product_desc;
587 $line->product_tobatch = $objp->product_tobatch;
588 $line->product_barcode = $objp->product_barcode;
590 $line->ref = $objp->product_ref;
591 $line->product_ref = $objp->product_ref;
592 $line->ref_fourn = $objp->ref_supplier;
593 $line->ref_supplier = $objp->ref_supplier;
595 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
600 $sqlsearchpackage =
'SELECT rowid, packaging FROM '.MAIN_DB_PREFIX.
"product_fournisseur_price";
601 $sqlsearchpackage .=
' WHERE entity IN ('.getEntity(
'product_fournisseur_price').
")";
602 $sqlsearchpackage .=
" AND fk_product = ".((int) $objp->fk_product);
603 $sqlsearchpackage .=
" AND ref_fourn = '".$this->db->escape($objp->ref_supplier).
"'";
604 $sqlsearchpackage .=
" AND quantity <= ".((float) $objp->qty);
605 $sqlsearchpackage .=
" AND (packaging IS NULL OR packaging = 0 OR packaging <= ".((float) $objp->qty).
")";
606 $sqlsearchpackage .=
" AND fk_soc = ".((int) $this->socid);
607 $sqlsearchpackage .=
" ORDER BY packaging ASC";
608 $sqlsearchpackage .=
" LIMIT 1";
610 $resqlsearchpackage = $this->db->query($sqlsearchpackage);
611 if ($resqlsearchpackage) {
612 $objsearchpackage = $this->db->fetch_object($resqlsearchpackage);
613 if ($objsearchpackage) {
614 $line->fk_fournprice = $objsearchpackage->rowid;
615 $line->packaging = $objsearchpackage->packaging;
618 $this->error = $this->db->lasterror();
623 $line->date_start = $this->db->jdate($objp->date_start);
624 $line->date_end = $this->db->jdate($objp->date_end);
625 $line->fk_unit = $objp->fk_unit;
628 $line->fk_multicurrency = $objp->fk_multicurrency;
629 $line->multicurrency_code = $objp->multicurrency_code;
630 $line->multicurrency_subprice = $objp->multicurrency_subprice;
631 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
632 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
633 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
635 $line->special_code = $objp->special_code;
636 $line->fk_parent_line = $objp->fk_parent_line;
638 $line->rang = $objp->rang;
642 $line->fetch_optionals();
644 $this->lines[$i] = $line;
648 $this->db->free($result);
652 $this->error = $this->db->error().
" sql=".
$sql;
665 public function valid($user, $idwarehouse = 0, $notrigger = 0)
667 global $langs, $conf;
668 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
674 if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")))
675 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->hasRight(
"fournisseur",
"supplier_order_advance",
"validate"))) {
680 $soc->fetch($this->fourn_id);
683 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
690 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"commande_fournisseur";
691 $sql .=
" SET ref='".$this->db->escape($num).
"',";
692 $sql .=
" fk_statut = ".self::STATUS_VALIDATED.
",";
693 $sql .=
" date_valid='".$this->db->idate(
dol_now()).
"',";
694 $sql .=
" fk_user_valid = ".((int) $user->id);
695 $sql .=
" WHERE rowid = ".((int) $this->
id);
696 $sql .=
" AND fk_statut = ".self::STATUS_DRAFT;
698 $resql = $this->db->query(
$sql);
704 if (!$error && !$notrigger) {
706 $result = $this->
call_trigger(
'ORDER_SUPPLIER_VALIDATE', $user);
714 $this->oldref = $this->ref;
717 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
719 $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).
"'";
720 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'fournisseur/commande/".$this->db->escape($this->
ref).
"' and entity = ".((int) $conf->entity);
721 $resql = $this->db->query(
$sql);
723 $error++; $this->error = $this->db->lasterror();
729 $dirsource = $conf->fournisseur->commande->dir_output.
'/'.$oldref;
730 $dirdest = $conf->fournisseur->commande->dir_output.
'/'.$newref;
731 if (!$error && file_exists($dirsource)) {
732 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
734 if (@rename($dirsource, $dirdest)) {
737 $listoffiles =
dol_dir_list($conf->fournisseur->commande->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
738 foreach ($listoffiles as $fileentry) {
739 $dirsource = $fileentry[
'name'];
740 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
741 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
742 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
743 @rename($dirsource, $dirdest);
760 $this->db->rollback();
764 $this->error =
'NotAuthorized';
765 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
778 return $this->
LibStatut($this->statut, $mode, $this->billed);
790 public function LibStatut($status, $mode = 0, $billed = 0)
793 global $conf, $langs, $hookmanager;
795 if (empty($this->statuts) || empty($this->statuts_short)) {
796 $langs->load(
'orders');
798 $this->statuts[0] =
'StatusSupplierOrderDraft';
799 $this->statuts[1] =
'StatusSupplierOrderValidated';
800 $this->statuts[2] =
'StatusSupplierOrderApproved';
801 if (empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) {
802 $this->statuts[3] =
'StatusSupplierOrderOnProcess';
804 $this->statuts[3] =
'StatusSupplierOrderOnProcessWithValidation';
806 $this->statuts[4] =
'StatusSupplierOrderReceivedPartially';
807 $this->statuts[5] =
'StatusSupplierOrderReceivedAll';
808 $this->statuts[6] =
'StatusSupplierOrderCanceled';
809 $this->statuts[7] =
'StatusSupplierOrderCanceled';
810 $this->statuts[9] =
'StatusSupplierOrderRefused';
813 $this->statuts_short[0] =
'StatusSupplierOrderDraftShort';
814 $this->statuts_short[1] =
'StatusSupplierOrderValidatedShort';
815 $this->statuts_short[2] =
'StatusSupplierOrderApprovedShort';
816 $this->statuts_short[3] =
'StatusSupplierOrderOnProcessShort';
817 $this->statuts_short[4] =
'StatusSupplierOrderReceivedPartiallyShort';
818 $this->statuts_short[5] =
'StatusSupplierOrderReceivedAllShort';
819 $this->statuts_short[6] =
'StatusSupplierOrderCanceledShort';
820 $this->statuts_short[7] =
'StatusSupplierOrderCanceledShort';
821 $this->statuts_short[9] =
'StatusSupplierOrderRefusedShort';
824 $statustrans = array(
836 $statusClass =
'status0';
837 if (!empty($statustrans[$status])) {
838 $statusClass = $statustrans[$status];
843 $billedtext =
' - '.$langs->trans(
"Billed");
845 if ($status == 5 && $billed) {
846 $statusClass =
'status6';
849 $statusLong = $langs->transnoentitiesnoconv($this->statuts[$status]).$billedtext;
850 $statusShort = $langs->transnoentitiesnoconv($this->statuts_short[$status]);
852 $parameters = array(
'status' => $status,
'mode' => $mode,
'billed' => $billed);
853 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
855 return $hookmanager->resPrint;
858 return dolGetStatus($statusLong, $statusShort,
'', $statusClass, $mode);
870 global $conf, $langs, $user;
872 $langs->loadLangs([
'bills',
'orders']);
875 $nofetch = !empty($params[
'nofetch']);
877 if ($user->hasRight(
"fournisseur",
"commande",
"read")) {
878 $datas[
'picto'] =
'<u class="paddingrightonly">'.$langs->trans(
"SupplierOrder").
'</u>';
879 if (isset($this->statut)) {
880 $datas[
'picto'] .=
' '.$this->getLibStatut(5);
882 if (!empty($this->
ref)) {
883 $datas[
'ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
885 if (!empty($this->ref_supplier)) {
886 $datas[
'refsupplier'] =
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.$this->ref_supplier;
889 $langs->load(
'companies');
890 if (empty($this->thirdparty)) {
893 $datas[
'supplier'] =
'<br><b>'.$langs->trans(
'Supplier').
':</b> '.$this->thirdparty->getNomUrl(1,
'', 0, 1);
895 if (!empty($this->total_ht)) {
896 $datas[
'totalht'] =
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
898 if (!empty($this->total_tva)) {
899 $datas[
'totaltva'] =
'<br><b>'.$langs->trans(
'VAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
901 if (!empty($this->total_ttc)) {
902 $datas[
'totalttc'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
904 if (!empty($this->date)) {
905 $datas[
'date'] =
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->date,
'day');
907 if (!empty($this->delivery_date)) {
908 $datas[
'deliverydate'] =
'<br><b>'.$langs->trans(
'DeliveryDate').
':</b> '.
dol_print_date($this->delivery_date,
'dayhour');
924 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = 0)
926 global $langs, $conf, $user, $hookmanager;
931 'objecttype' => $this->element,
935 $classfortooltip =
'classfortooltip';
938 $classfortooltip =
'classforajaxtooltip';
939 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
945 $url = DOL_URL_ROOT.
'/fourn/commande/card.php?id='.$this->id;
947 if ($option !==
'nolink') {
949 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
950 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
951 $add_save_lastsearch_values = 1;
953 if ($add_save_lastsearch_values) {
954 $url .=
'&save_lastsearch_values=1';
959 if (empty($notooltip)) {
960 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
961 $label = $langs->trans(
"ShowOrder");
962 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
964 $linkclose .= ($label ?
' title="'.dol_escape_htmltag($label, 1).
'"' :
' title="tocomplete"');
965 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
968 $linkstart =
'<a href="'.$url.
'"';
969 $linkstart .= $linkclose.
'>';
972 $result .= $linkstart;
974 $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') : $dataparams.
' class="'.(($withpicto != 2) ?
'paddingright ' :
'').$classfortooltip.
'"'), 0, 0, $notooltip ? 0 : 1);
976 if ($withpicto != 2) {
977 $result .= $this->ref;
981 if ($addlinktonotes) {
982 $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
985 $result .=
' <span class="note inline-block">';
986 $result .=
'<a href="'.DOL_URL_ROOT.
'/fourn/commande/note.php?id='.$this->
id.
'" class="classfortooltip" title="'.
dol_escape_htmltag($notetoshow).
'">';
991 $result .=
'</span>';
996 $hookmanager->initHooks(array($this->element .
'dao'));
997 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
998 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
1000 $result = $hookmanager->resPrint;
1002 $result .= $hookmanager->resPrint;
1017 global $db, $langs, $conf;
1018 $langs->load(
"orders");
1020 if (!empty($conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER)) {
1027 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
1029 foreach ($dirmodels as $reldir) {
1030 $dir =
dol_buildpath($reldir.
"core/modules/supplier_order/");
1033 $mybool |= @include_once $dir.$file;
1036 if ($mybool ===
false) {
1041 $obj =
new $classname();
1042 $numref = $obj->getNextValue($soc, $this);
1044 if ($numref !=
"") {
1047 $this->error = $obj->error;
1051 $this->error =
"Error_COMMANDE_SUPPLIER_ADDON_NotDefined";
1065 if ($this->billed) {
1071 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur SET billed = 1';
1074 if ($this->db->query(
$sql)) {
1077 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CLASSIFY_BILLED', $user);
1087 $this->db->commit();
1090 $this->db->rollback();
1096 $this->db->rollback();
1109 public function approve($user, $idwarehouse = 0, $secondlevel = 0)
1111 global $langs, $conf;
1112 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1118 if ($user->hasRight(
"fournisseur",
"commande",
"approuver")) {
1124 $soc =
new Societe($this->db);
1125 $soc->fetch($this->fourn_id);
1128 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
1136 $movetoapprovestatus =
true;
1139 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur";
1140 $sql .=
" SET ref='".$this->db->escape($num).
"',";
1141 if (empty($secondlevel)) {
1142 $sql .=
" date_approve='".$this->db->idate($now).
"',";
1143 $sql .=
" fk_user_approve = ".$user->id;
1144 if (!empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) && $this->total_ht >= $conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) {
1145 if (empty($this->user_approve_id2)) {
1146 $movetoapprovestatus =
false;
1147 $comment =
' (first level)';
1152 $sql .=
" date_approve2='".$this->db->idate($now).
"',";
1153 $sql .=
" fk_user_approve2 = ".((int) $user->id);
1154 if (empty($this->user_approve_id)) {
1155 $movetoapprovestatus =
false;
1157 $comment =
' (second level)';
1160 if ($movetoapprovestatus) {
1161 $sql .=
", fk_statut = ".self::STATUS_ACCEPTED;
1163 $sql .=
", fk_statut = ".self::STATUS_VALIDATED;
1165 $sql .=
" WHERE rowid = ".((int) $this->
id);
1166 $sql .=
" AND fk_statut = ".self::STATUS_VALIDATED;
1168 if ($this->db->query(
$sql)) {
1169 if (!empty($conf->global->SUPPLIER_ORDER_AUTOADD_USER_CONTACT)) {
1170 $result = $this->
add_contact($user->id,
'SALESREPFOLL',
'internal', 1);
1171 if ($result < 0 && $result != -2) {
1177 if (!$error && $movetoapprovestatus &&
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER)) {
1178 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1179 $langs->load(
"agenda");
1181 $cpt = count($this->lines);
1182 for ($i = 0; $i < $cpt; $i++) {
1184 if ($this->lines[$i]->fk_product > 0) {
1185 $this->line = $this->lines[$i];
1187 $mouvP->origin = &$this;
1188 $mouvP->setOrigin($this->element, $this->
id);
1190 $up_ht_disc = $this->lines[$i]->subprice;
1191 if (!empty($this->lines[$i]->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) {
1192 $up_ht_disc =
price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100,
'MU');
1194 $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans(
"OrderApprovedInDolibarr", $this->ref));
1205 $result = $this->
call_trigger(
'ORDER_SUPPLIER_APPROVE', $user);
1213 $this->
ref = $this->newref;
1215 if ($movetoapprovestatus) {
1220 if (empty($secondlevel)) {
1221 $this->date_approve = $now;
1222 $this->user_approve_id = $user->id;
1225 $this->date_approve2 = $now;
1226 $this->user_approve_id2 = $user->id;
1229 $this->db->commit();
1232 $this->db->rollback();
1236 $this->db->rollback();
1237 $this->error = $this->db->lasterror();
1241 dol_syslog(get_class($this).
"::approve Not Authorized", LOG_ERR);
1254 global $conf, $langs;
1260 if ($user->hasRight(
"fournisseur",
"commande",
"approuver")) {
1264 $sql .=
" WHERE rowid = ".((int) $this->
id);
1266 if ($this->db->query(
$sql)) {
1271 $result = $this->
call_trigger(
'ORDER_SUPPLIER_REFUSE', $user);
1274 $this->db->rollback();
1276 $this->db->commit();
1281 $this->db->rollback();
1282 $this->error = $this->db->lasterror();
1283 dol_syslog(get_class($this).
"::refuse Error -1");
1287 dol_syslog(get_class($this).
"::refuse Not Authorized");
1301 public function Cancel($user, $idwarehouse = -1)
1304 global $langs, $conf;
1310 if ($user->hasRight(
"fournisseur",
"commande",
"commander")) {
1315 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur SET fk_statut = ".((int) $statut);
1316 $sql .=
" WHERE rowid = ".((int) $this->
id);
1317 dol_syslog(get_class($this).
"::cancel", LOG_DEBUG);
1318 if ($this->db->query(
$sql)) {
1322 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CANCEL', $user);
1329 $this->db->commit();
1332 $this->db->rollback();
1336 $this->db->rollback();
1337 $this->error = $this->db->lasterror();
1338 dol_syslog(get_class($this).
"::cancel ".$this->error);
1342 dol_syslog(get_class($this).
"::cancel Not Authorized");
1356 public function commande($user, $date, $methode, $comment =
'')
1361 if ($user->hasRight(
"fournisseur",
"commande",
"commander")) {
1364 $newnoteprivate = $this->note_private;
1366 $newnoteprivate =
dol_concatdesc($newnoteprivate, $langs->trans(
"Comment").
': '.$comment);
1369 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur";
1370 $sql .=
" SET fk_statut=".self::STATUS_ORDERSENT.
", fk_input_method=".$methode.
", date_commande='".$this->db->idate($date).
"', ";
1371 $sql .=
" note_private='".$this->db->escape($newnoteprivate).
"'";
1372 $sql .=
" WHERE rowid=".((int) $this->
id);
1374 dol_syslog(get_class($this).
"::commande", LOG_DEBUG);
1375 if ($this->db->query(
$sql)) {
1377 $this->methode_commande_id = $methode;
1378 $this->date_commande = $date;
1379 $this->context = array(
'comments' => $comment);
1382 $result = $this->
call_trigger(
'ORDER_SUPPLIER_SUBMIT', $user);
1389 $this->error = $this->db->lasterror();
1390 $this->errors[] = $this->db->lasterror();
1394 $this->db->commit();
1396 $this->db->rollback();
1400 $this->error = $langs->trans(
'NotAuthorized');
1401 $this->errors[] = $langs->trans(
'NotAuthorized');
1402 dol_syslog(get_class($this).
"::commande User not Authorized", LOG_WARNING);
1405 return ($error ? -1 : 1);
1415 public function create($user, $notrigger = 0)
1417 global $langs, $conf, $hookmanager;
1425 $date = ($this->date_commande ? $this->date_commande : $this->date);
1429 $delivery_date = empty($this->delivery_date) ? $this->date_livraison : $this->delivery_date;
1432 if (empty($this->source)) {
1437 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
1442 if (empty($this->fk_multicurrency)) {
1443 $this->multicurrency_code = $conf->currency;
1444 $this->fk_multicurrency = 0;
1445 $this->multicurrency_tx = 1;
1449 $this->brouillon = 1;
1451 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"commande_fournisseur (";
1453 $sql .=
", ref_supplier";
1454 $sql .=
", note_private";
1455 $sql .=
", note_public";
1458 $sql .=
", fk_projet";
1459 $sql .=
", date_creation";
1460 $sql .=
", date_livraison";
1461 $sql .=
", fk_user_author";
1462 $sql .=
", fk_statut";
1464 $sql .=
", model_pdf";
1465 $sql .=
", fk_mode_reglement";
1466 $sql .=
", fk_cond_reglement";
1467 $sql .=
", fk_account";
1468 $sql .=
", fk_incoterms, location_incoterms";
1469 $sql .=
", fk_multicurrency";
1470 $sql .=
", multicurrency_code";
1471 $sql .=
", multicurrency_tx";
1473 $sql .=
" VALUES (";
1475 $sql .=
", '".$this->db->escape($this->ref_supplier).
"'";
1476 $sql .=
", '".$this->db->escape($this->note_private).
"'";
1477 $sql .=
", '".$this->db->escape($this->note_public).
"'";
1478 $sql .=
", ".setEntity($this);
1479 $sql .=
", ".((int) $this->socid);
1480 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
1481 $sql .=
", '".$this->db->idate($date).
"'";
1482 $sql .=
", ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
"null");
1483 $sql .=
", ".((int) $user->id);
1484 $sql .=
", ".self::STATUS_DRAFT;
1485 $sql .=
", ".((int) $this->source);
1487 $sql .=
", ".($this->mode_reglement_id > 0 ? $this->mode_reglement_id :
'null');
1488 $sql .=
", ".($this->cond_reglement_id > 0 ? $this->cond_reglement_id :
'null');
1489 $sql .=
", ".($this->fk_account > 0 ? $this->fk_account :
'NULL');
1490 $sql .=
", ".(int) $this->fk_incoterms;
1491 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
1492 $sql .=
", ".(int) $this->fk_multicurrency;
1493 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1494 $sql .=
", ".(double) $this->multicurrency_tx;
1497 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1498 if ($this->db->query(
$sql)) {
1499 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"commande_fournisseur");
1502 $num = count($this->lines);
1505 for ($i = 0; $i < $num; $i++) {
1506 $line = $this->lines[$i];
1507 if (!is_object($line)) {
1508 $line = (object) $line;
1520 $line->localtax1_tx,
1521 $line->localtax2_tx,
1525 $line->remise_percent,
1528 $line->product_type,
1533 $line->array_options,
1538 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
1539 $this->db->rollback();
1544 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur";
1545 $sql .=
" SET ref='(PROV".$this->id.
")'";
1546 $sql .=
" WHERE rowid=".((int) $this->
id);
1547 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1548 if ($this->db->query(
$sql)) {
1551 $this->
ref =
"(PROV".$this->id.
")";
1553 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
1554 $this->linked_objects = $this->linkedObjectsIds;
1558 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
1559 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
1560 if (is_array($tmp_origin_id)) {
1561 foreach ($tmp_origin_id as $origin_id) {
1570 $origin_id = $tmp_origin_id;
1588 if (!$error && !$notrigger) {
1590 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CREATE', $user);
1592 $this->db->rollback();
1599 $this->db->commit();
1602 $this->error = $this->db->lasterror();
1603 $this->db->rollback();
1608 $this->error =
'Failed to get ID of inserted line';
1613 $this->error = $this->db->lasterror();
1614 $this->db->rollback();
1634 if (isset($this->
ref)) {
1635 $this->
ref = trim($this->
ref);
1637 if (isset($this->ref_supplier)) {
1638 $this->ref_supplier = trim($this->ref_supplier);
1640 if (isset($this->note_private)) {
1641 $this->note_private = trim($this->note_private);
1643 if (isset($this->note_public)) {
1644 $this->note_public = trim($this->note_public);
1646 if (isset($this->model_pdf)) {
1647 $this->model_pdf = trim($this->model_pdf);
1649 if (isset($this->import_key)) {
1650 $this->import_key = trim($this->import_key);
1654 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
1656 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1657 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
1658 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1659 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
1660 $sql .=
" date_commande=".(strval($this->date_commande) !=
'' ?
"'".$this->db->idate($this->date_commande).
"'" :
'null').
",";
1661 $sql .=
" date_valid=".(strval($this->date_validation) !=
'' ?
"'".$this->db->idate($this->date_validation).
"'" :
'null').
",";
1662 $sql .=
" total_tva=".(isset($this->total_tva) ? $this->total_tva :
"null").
",";
1663 $sql .=
" localtax1=".(isset($this->total_localtax1) ? $this->total_localtax1 :
"null").
",";
1664 $sql .=
" localtax2=".(isset($this->total_localtax2) ? $this->total_localtax2 :
"null").
",";
1665 $sql .=
" total_ht=".(isset($this->total_ht) ? $this->total_ht :
"null").
",";
1666 $sql .=
" total_ttc=".(isset($this->total_ttc) ? $this->total_ttc :
"null").
",";
1667 $sql .=
" fk_statut=".(isset($this->statut) ? $this->statut :
"null").
",";
1668 $sql .=
" fk_user_author=".(isset($this->user_author_id) ? $this->user_author_id :
"null").
",";
1669 $sql .=
" fk_user_valid=".(isset($this->user_valid) && $this->user_valid > 0 ? $this->user_valid :
"null").
",";
1670 $sql .=
" fk_projet=".(isset($this->fk_project) ? $this->fk_project :
"null").
",";
1671 $sql .=
" fk_cond_reglement=".(isset($this->cond_reglement_id) ? $this->cond_reglement_id :
"null").
",";
1672 $sql .=
" fk_mode_reglement=".(isset($this->mode_reglement_id) ? $this->mode_reglement_id :
"null").
",";
1673 $sql .=
" date_livraison=".(strval($this->delivery_date) !=
'' ?
"'".$this->db->idate($this->delivery_date).
"'" :
'null').
",";
1675 $sql .=
" fk_account=".($this->fk_account > 0 ? $this->fk_account :
"null").
",";
1677 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1678 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1679 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1680 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null");
1682 $sql .=
" WHERE rowid=".((int) $this->
id);
1686 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1687 $resql = $this->db->query(
$sql);
1690 $this->errors[] =
"Error ".$this->db->lasterror();
1700 if (!$error && !$notrigger) {
1702 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
1711 foreach ($this->errors as $errmsg) {
1712 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1713 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1715 $this->db->rollback();
1718 $this->db->commit();
1733 global $conf, $user, $hookmanager;
1740 foreach ($this->lines as $line) {
1741 $line->fetch_optionals();
1745 $objFrom = clone $this;
1748 if (!empty($socid) && $socid != $this->socid) {
1749 $objsoc =
new Societe($this->db);
1751 if ($objsoc->fetch($socid) > 0) {
1752 $this->socid = $objsoc->id;
1753 $this->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1754 $this->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1755 $this->fk_project = 0;
1756 $this->fk_delivery_address = 0;
1766 $this->user_author_id = $user->id;
1767 $this->user_valid = 0;
1768 $this->date_creation =
'';
1769 $this->date_validation =
'';
1770 $this->ref_supplier =
'';
1771 $this->user_approve_id =
'';
1772 $this->user_approve_id2 =
'';
1773 $this->date_approve =
'';
1774 $this->date_approve2 =
'';
1777 $this->context[
'createfromclone'] =
'createfromclone';
1778 $result = $this->
create($user, $notrigger);
1785 if (is_object($hookmanager)) {
1786 $parameters = array(
'objFrom'=>$objFrom);
1788 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1796 unset($this->context[
'createfromclone']);
1800 $this->db->commit();
1803 $this->db->rollback();
1837 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)
1839 global $langs, $mysoc, $conf;
1841 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");
1842 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1844 if ($this->statut == self::STATUS_DRAFT) {
1845 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1854 if (empty($txtva)) {
1860 if (empty($txlocaltax1)) {
1863 if (empty($txlocaltax2)) {
1866 if (empty($remise_percent)) {
1867 $remise_percent = 0;
1870 $remise_percent =
price2num($remise_percent);
1873 $pu_ht_devise =
price2num($pu_ht_devise);
1875 if (!preg_match(
'/\((.*)\)/', $txtva)) {
1880 if ($price_base_type ==
'HT') {
1885 $desc = trim($desc);
1888 if ($qty < 0 && !$fk_product) {
1889 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Product"));
1895 if ($date_start && $date_end && $date_start > $date_end) {
1896 $langs->load(
"errors");
1897 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
1904 $product_type = $type;
1907 if ($fk_product > 0) {
1908 if (!empty($conf->global->SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY)) {
1910 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);
1912 if ($prod->fetch($fk_product) > 0) {
1913 $product_type = $prod->type;
1914 $label = $prod->label;
1918 $result = $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', (isset($this->fk_soc) ? $this->fk_soc : $this->socid));
1922 if ($result > 0 && ($origin ==
'commande' || $pu ===
'')) {
1923 $pu = $prod->fourn_pu;
1924 $ref_supplier = $prod->ref_supplier;
1926 if ($remise_percent == 0 && $prod->remise_percent != 0) {
1927 $remise_percent = $prod->remise_percent;
1931 $langs->load(
"errors");
1932 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
1933 $this->db->rollback();
1934 dol_syslog(get_class($this).
"::addline we did not found supplier price, so we can't guess unit price");
1939 if ($result == -1) {
1940 $langs->load(
"errors");
1941 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
1942 $this->db->rollback();
1943 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_DEBUG);
1947 $this->error = $prod->error;
1948 $this->db->rollback();
1949 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_ERR);
1953 $this->error = $prod->error;
1954 $this->db->rollback();
1960 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
1961 $prod =
new Product($this->db);
1962 $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', ($this->fk_soc ? $this->fk_soc : $this->socid));
1964 if ($qty < $prod->packaging) {
1965 $qty = $prod->packaging;
1967 if (!empty($prod->packaging) && ($qty % $prod->packaging) > 0) {
1968 $coeff = intval($qty / $prod->packaging) + 1;
1969 $qty = $prod->packaging * $coeff;
1970 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'mesgs');
1976 if (
isModEnabled(
"multicurrency") && $pu_ht_devise > 0) {
1985 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
1986 $vat_src_code = $reg[1];
1987 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
1995 $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);
1997 $total_ht = $tabprice[0];
1998 $total_tva = $tabprice[1];
1999 $total_ttc = $tabprice[2];
2000 $total_localtax1 = $tabprice[9];
2001 $total_localtax2 = $tabprice[10];
2002 $pu = $pu_ht = $tabprice[3];
2005 $multicurrency_total_ht = $tabprice[16];
2006 $multicurrency_total_tva = $tabprice[17];
2007 $multicurrency_total_ttc = $tabprice[18];
2008 $pu_ht_devise = $tabprice[19];
2010 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2011 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2015 $rang = $rangmax + 1;
2021 $this->line->context = $this->context;
2023 $this->line->fk_commande = $this->id;
2024 $this->line->label = $label;
2025 $this->line->ref_fourn = $ref_supplier;
2026 $this->line->ref_supplier = $ref_supplier;
2027 $this->line->desc = $desc;
2028 $this->line->qty = $qty;
2029 $this->line->tva_tx = $txtva;
2030 $this->line->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0);
2031 $this->line->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0);
2032 $this->line->localtax1_type = $localtax1_type;
2033 $this->line->localtax2_type = $localtax2_type;
2034 $this->line->fk_product = $fk_product;
2035 $this->line->product_type = $product_type;
2036 $this->line->remise_percent = $remise_percent;
2037 $this->line->subprice = $pu_ht;
2038 $this->line->rang = $rang;
2039 $this->line->info_bits = $info_bits;
2041 $this->line->vat_src_code = $vat_src_code;
2042 $this->line->total_ht = $total_ht;
2043 $this->line->total_tva = $total_tva;
2044 $this->line->total_localtax1 = $total_localtax1;
2045 $this->line->total_localtax2 = $total_localtax2;
2046 $this->line->total_ttc = $total_ttc;
2047 $this->line->product_type = $type;
2048 $this->line->special_code = (!empty($this->special_code) ? $this->special_code : 0);
2049 $this->line->origin = $origin;
2050 $this->line->origin_id = $origin_id;
2051 $this->line->fk_unit = $fk_unit;
2053 $this->line->date_start = $date_start;
2054 $this->line->date_end = $date_end;
2057 $this->line->fk_multicurrency = $this->fk_multicurrency;
2058 $this->line->multicurrency_code = $this->multicurrency_code;
2059 $this->line->multicurrency_subprice = $pu_ht_devise;
2060 $this->line->multicurrency_total_ht = $multicurrency_total_ht;
2061 $this->line->multicurrency_total_tva = $multicurrency_total_tva;
2062 $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
2064 $this->line->subprice = $pu_ht;
2065 $this->line->price = $this->line->subprice;
2067 $this->line->remise_percent = $remise_percent;
2069 if (is_array($array_options) && count($array_options) > 0) {
2070 $this->line->array_options = $array_options;
2073 $result = $this->line->insert($notrigger);
2076 if (!empty($fk_parent_line)) {
2078 } elseif ($rang > 0 && $rang <= count($this->lines)) {
2079 $linecount = count($this->lines);
2080 for ($ii = $rang; $ii <= $linecount; $ii++) {
2086 $result = $this->
update_price(1,
'auto', 0, $this->thirdparty);
2088 $this->db->commit();
2089 return $this->line->id;
2091 $this->db->rollback();
2095 $this->error = $this->line->error;
2096 $this->errors = $this->line->errors;
2097 dol_syslog(get_class($this).
"::addline error=".$this->error, LOG_ERR);
2098 $this->db->rollback();
2123 public function dispatchProduct($user, $product, $qty, $entrepot, $price = 0, $comment =
'', $eatby =
'', $sellby =
'', $batch =
'', $fk_commandefourndet = 0, $notrigger = 0, $fk_reception = 0)
2125 global $conf, $langs;
2128 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2131 if ($entrepot <= 0) {
2132 $this->error =
'ErrorBadValueForParameterWarehouse';
2136 $this->error =
'ErrorBadValueForParameterQty';
2140 $dispatchstatus = 1;
2141 if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) {
2142 $dispatchstatus = 0;
2149 if (($this->statut == self::STATUS_ORDERSENT || $this->statut == self::STATUS_RECEIVED_PARTIALLY || $this->statut == self::STATUS_RECEIVED_COMPLETELY)) {
2152 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch";
2153 $sql .=
" (fk_commande, fk_product, qty, fk_entrepot, fk_user, datec, fk_commandefourndet, status, comment, eatby, sellby, batch, fk_reception) VALUES";
2154 $sql .=
" ('".$this->id.
"','".$product.
"','".$qty.
"',".($entrepot > 0 ?
"'".$entrepot.
"'" :
"null").
",'".$user->id.
"','".$this->db->idate($now).
"','".$fk_commandefourndet.
"', ".$dispatchstatus.
", '".$this->db->escape($comment).
"', ";
2155 $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");
2158 dol_syslog(get_class($this).
"::dispatchProduct", LOG_DEBUG);
2159 $resql = $this->db->query(
$sql);
2162 global $conf, $langs, $user;
2164 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_DISPATCH', $user);
2171 $this->error = $this->db->lasterror();
2176 if (!$error && $entrepot > 0 &&
isModEnabled(
'stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) {
2180 $mouv->origin = &$this;
2181 $mouv->setOrigin($this->element, $this->
id);
2184 if (!empty($conf->global->SUPPLIER_ORDER_ALLOW_NEGATIVE_QTY_FOR_SUPPLIER_ORDER_RETURN) && $qty < 0) {
2185 $result = $mouv->livraison($user, $product, $entrepot, $qty*(-1), $price, $comment, $now, $eatby, $sellby, $batch, 0, $inventorycode);
2187 $result = $mouv->reception($user, $product, $entrepot, $qty, $price, $comment, $eatby, $sellby, $batch,
'', 0, $inventorycode);
2191 $this->error = $mouv->error;
2192 $this->errors = $mouv->errors;
2193 dol_syslog(get_class($this).
"::dispatchProduct ".$this->error.
" ".join(
',', $this->errors), LOG_ERR);
2200 $this->db->commit();
2203 $this->db->rollback();
2207 $this->error =
'BadStatusForObject';
2221 if ($this->statut == 0) {
2224 if ($line->fetch($idline) <= 0) {
2230 foreach ($dispatchedLines as $dispatchLine) {
2231 if ($dispatchLine[
'orderlineid'] == $idline) {
2232 $this->error =
"LineAlreadyDispatched";
2233 $this->errors[] = $this->error;
2238 if ($line->delete($notrigger) > 0) {
2242 $this->error = $line->error;
2243 $this->errors = $line->errors;
2258 public function delete(
User $user, $notrigger = 0)
2260 global $langs, $conf;
2261 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2267 if (empty($notrigger)) {
2269 $result = $this->
call_trigger(
'ORDER_SUPPLIER_DELETE', $user);
2271 $this->errors[] =
'ErrorWhenRunningTrigger';
2272 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2273 $this->db->rollback();
2281 if (!empty($this->linkedObjects) && array_key_exists(
'reception', $this->linkedObjects)) {
2282 foreach ($this->linkedObjects[
'reception'] as $element) {
2283 if ($element->statut >= 0) {
2284 $this->errors[] = $langs->trans(
'ReceptionExist');
2291 $main = MAIN_DB_PREFIX.
'commande_fournisseurdet';
2292 $ef = $main.
"_extrafields";
2293 $sql =
"DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_commande = ".((int) $this->
id).
")";
2294 dol_syslog(get_class($this).
"::delete extrafields lines", LOG_DEBUG);
2295 if (!$this->db->query(
$sql)) {
2296 $this->error = $this->db->lasterror();
2297 $this->errors[] = $this->db->lasterror();
2301 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet WHERE fk_commande =".((int) $this->
id);
2302 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2303 if (!$this->db->query(
$sql)) {
2304 $this->error = $this->db->lasterror();
2305 $this->errors[] = $this->db->lasterror();
2309 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"commande_fournisseur WHERE rowid =".((int) $this->
id);
2310 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2311 if ($resql = $this->db->query(
$sql)) {
2312 if ($this->db->affected_rows($resql) < 1) {
2313 $this->error = $this->db->lasterror();
2314 $this->errors[] = $this->db->lasterror();
2318 $this->error = $this->db->lasterror();
2319 $this->errors[] = $this->db->lasterror();
2327 $this->error =
'FailToDeleteExtraFields';
2328 $this->errors[] =
'FailToDeleteExtraFields';
2330 dol_syslog(get_class($this).
"::delete error -4 ".$this->error, LOG_ERR);
2337 $this->error =
'FailToDeleteObjectLinked';
2338 $this->errors[] =
'FailToDeleteObjectLinked';
2348 if ($conf->fournisseur->commande->dir_output) {
2349 $dir = $conf->fournisseur->commande->dir_output.
"/".$ref;
2350 $file = $dir.
"/".$ref.
".pdf";
2351 if (file_exists($file)) {
2353 $this->error =
'ErrorFailToDeleteFile';
2354 $this->errors[] =
'ErrorFailToDeleteFile';
2358 if (file_exists($dir)) {
2361 $this->error =
'ErrorFailToDeleteDir';
2362 $this->errors[] =
'ErrorFailToDeleteDir';
2370 dol_syslog(get_class($this).
"::delete $this->id by $user->id", LOG_DEBUG);
2371 $this->db->commit();
2374 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2375 $this->db->rollback();
2389 $sql =
"SELECT rowid, libelle";
2390 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_input_method";
2391 $sql .=
" WHERE active = 1";
2393 $resql = $this->db->query(
$sql);
2396 $num = $this->db->num_rows($resql);
2397 $this->methodes_commande = array();
2399 $row = $this->db->fetch_row($resql);
2401 $this->methodes_commande[$row[0]] = $row[1];
2424 $sql =
"SELECT p.ref, p.label,";
2425 $sql .=
" e.rowid as warehouse_id, e.ref as entrepot,";
2426 $sql .=
" cfd.rowid as dispatchedlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status, cfd.fk_commandefourndet";
2427 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product as p,";
2428 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as cfd";
2429 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"entrepot as e ON cfd.fk_entrepot = e.rowid";
2430 $sql .=
" WHERE cfd.fk_commande = ".((int) $this->
id);
2431 $sql .=
" AND cfd.fk_product = p.rowid";
2433 $sql .=
" AND cfd.status = ".((int) $status);
2435 $sql .=
" ORDER BY cfd.rowid ASC";
2437 $resql = $this->db->query(
$sql);
2439 $num = $this->db->num_rows($resql);
2443 $objp = $this->db->fetch_object($resql);
2446 'id' => $objp->dispatchedlineid,
2447 'productid' => $objp->fk_product,
2448 'warehouseid' => $objp->warehouse_id,
2449 'qty' => $objp->qty,
2450 'orderlineid' => $objp->fk_commandefourndet
2457 dol_print_error($this->db,
'Failed to execute request to get dispatched lines');
2476 global $conf, $langs;
2483 $usercanreceive = 0;
2485 $usercanreceive = $user->hasRight(
"fournisseur",
"commande",
"receptionner");
2487 $usercanreceive = $user->hasRight(
"reception",
"creer");
2490 if ($usercanreceive) {
2492 if ($type ==
'par') {
2494 } elseif ($type ==
'tot') {
2496 } elseif ($type ==
'nev') {
2498 } elseif ($type ==
'can') {
2502 dol_syslog(get_class($this).
"::Livraison Error -2", LOG_ERR);
2507 if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) {
2509 if (!$error && ($type ==
'tot')) {
2511 if (count($dispatchedlinearray) > 0) {
2514 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove';
2515 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove', LOG_DEBUG);
2518 if (!$error && !empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS_NEED_APPROVE) && ($type ==
'tot')) {
2520 if (count($dispatchedlinearray) > 0) {
2523 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied';
2524 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied', LOG_DEBUG);
2531 if (empty($error)) {
2534 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur";
2535 $sql .=
" SET fk_statut = ".((int) $statut);
2536 $sql .=
" WHERE rowid = ".((int) $this->
id);
2537 $sql .=
" AND fk_statut IN (".self::STATUS_ORDERSENT.
",".self::STATUS_RECEIVED_PARTIALLY.
")";
2539 dol_syslog(get_class($this).
"::Livraison", LOG_DEBUG);
2540 $resql = $this->db->query(
$sql);
2543 $old_statut = $this->statut;
2544 $this->statut = $statut;
2545 $this->context[
'actionmsg2'] = $comment;
2548 $result_trigger = $this->
call_trigger(
'ORDER_SUPPLIER_RECEIVE', $user);
2549 if ($result_trigger < 0) {
2554 if (empty($error)) {
2555 $this->db->commit();
2557 $this->statut = $old_statut;
2558 $this->db->rollback();
2559 $this->error = $this->db->lasterror();
2563 $this->db->rollback();
2564 $this->error = $this->db->lasterror();
2569 $this->error = $langs->trans(
'NotAuthorized');
2570 $this->errors[] = $langs->trans(
'NotAuthorized');
2571 dol_syslog(get_class($this).
"::Livraison Not Authorized");
2603 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
2608 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur";
2609 $sql .=
" SET date_livraison = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2610 $sql .=
" WHERE rowid = ".((int) $this->
id);
2613 $resql = $this->db->query(
$sql);
2615 $this->errors[] = $this->db->error();
2620 $this->oldcopy = clone $this;
2621 $this->date_livraison = $delivery_date;
2622 $this->delivery_date = $delivery_date;
2625 if (!$notrigger && empty($error)) {
2627 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2635 $this->db->commit();
2638 foreach ($this->errors as $errmsg) {
2639 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2640 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2642 $this->db->rollback();
2662 if ($user->hasRight(
"fournisseur",
"commande",
"creer") || $user->hasRight(
"supplier_order",
"creer")) {
2667 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur";
2668 $sql .=
" SET fk_projet = ".($id_projet > 0 ? (int) $id_projet :
'null');
2669 $sql .=
" WHERE rowid = ".((int) $this->
id);
2672 $resql = $this->db->query(
$sql);
2674 $this->errors[] = $this->db->error();
2679 $this->oldcopy = clone $this;
2680 $this->fk_projet = $id_projet;
2681 $this->fk_project = $id_projet;
2684 if (!$notrigger && empty($error)) {
2686 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2694 $this->db->commit();
2697 foreach ($this->errors as $errmsg) {
2698 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2699 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2701 $this->db->rollback();
2719 $comclient =
new Commande($this->db);
2720 $comclient->fetch($comclientid);
2724 $this->lines = array();
2726 $num = count($comclient->lines);
2727 for ($i = 0; $i < $num; $i++) {
2728 $prod =
new Product($this->db);
2731 if ($prod->fetch($comclient->lines[$i]->fk_product) > 0) {
2732 $label = $prod->label;
2736 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"commande_fournisseurdet";
2737 $sql .=
" (fk_commande, label, description, fk_product, price, qty, tva_tx, localtax1_tx, localtax2_tx, remise_percent, subprice, remise, ref)";
2738 $sql .=
" VALUES (".((int) $idc).
", '".$this->db->escape($label).
"', '".$this->db->escape($comclient->lines[$i]->desc).
"'";
2739 $sql .=
",".$comclient->lines[$i]->fk_product.
", ".
price2num($comclient->lines[$i]->price,
'MU');
2740 $sql .=
", ".price2num($comclient->lines[$i]->qty,
'MS').
", ".
price2num($comclient->lines[$i]->tva_tx, 5).
", ".
price2num($comclient->lines[$i]->localtax1_tx, 5).
", ".
price2num($comclient->lines[$i]->localtax2_tx, 5).
", ".
price2num($comclient->lines[$i]->remise_percent, 3);
2741 $sql .=
", '".price2num($comclient->lines[$i]->subprice,
'MT').
"','0', '".$this->db->escape($ref).
"');";
2742 if ($this->db->query(
$sql)) {
2759 global $conf, $langs;
2764 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur';
2765 $sql .=
" SET fk_statut = ".$status;
2766 $sql .=
" WHERE rowid = ".((int) $this->
id);
2768 dol_syslog(get_class($this).
"::setStatus", LOG_DEBUG);
2769 $resql = $this->db->query(
$sql);
2772 $triggerName = array();
2773 $triggerName[0] =
'DRAFT';
2774 $triggerName[1] =
'VALIDATED';
2775 $triggerName[2] =
'APPROVED';
2776 $triggerName[3] =
'ORDERED';
2777 $triggerName[4] =
'RECEIVED_PARTIALLY';
2778 $triggerName[5] =
'RECEIVED_COMPLETELY';
2779 $triggerName[6] =
'CANCELED';
2780 $triggerName[7] =
'CANCELED';
2781 $triggerName[9] =
'REFUSED';
2784 $result = $this->
call_trigger(
"ORDER_SUPPLIER_STATUS_".$triggerName[$status], $user);
2791 $this->error = $this->db->lasterror();
2792 dol_syslog(get_class($this).
"::setStatus ".$this->error);
2796 $this->statut = $status;
2797 $this->db->commit();
2800 $this->db->rollback();
2828 public function updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $price_base_type =
'HT', $info_bits = 0, $type = 0, $notrigger = 0, $date_start =
'', $date_end =
'', $array_options = 0, $fk_unit =
null, $pu_ht_devise = 0, $ref_supplier =
'')
2830 global $mysoc, $conf, $langs;
2831 dol_syslog(get_class($this).
"::updateline $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $type, $fk_unit");
2832 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2836 if ($this->brouillon) {
2841 if (empty($info_bits)) {
2844 if (empty($txtva)) {
2847 if (empty($txlocaltax1)) {
2850 if (empty($txlocaltax2)) {
2853 if (empty($remise)) {
2856 if (empty($remise_percent)) {
2857 $remise_percent = 0;
2860 $remise_percent =
price2num($remise_percent);
2866 $pu_ht_devise =
price2num($pu_ht_devise);
2867 if (!preg_match(
'/\((.*)\)/', $txtva)) {
2877 if ($date_start && $date_end && $date_start > $date_end) {
2878 $langs->load(
"errors");
2879 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
2895 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
2896 $vat_src_code = $reg[1];
2897 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
2900 $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);
2901 $total_ht = $tabprice[0];
2902 $total_tva = $tabprice[1];
2903 $total_ttc = $tabprice[2];
2904 $total_localtax1 = $tabprice[9];
2905 $total_localtax2 = $tabprice[10];
2906 $pu_ht = $tabprice[3];
2907 $pu_tva = $tabprice[4];
2908 $pu_ttc = $tabprice[5];
2911 $multicurrency_total_ht = $tabprice[16];
2912 $multicurrency_total_tva = $tabprice[17];
2913 $multicurrency_total_ttc = $tabprice[18];
2914 $pu_ht_devise = $tabprice[19];
2916 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2917 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2921 $this->line->fetch($rowid);
2923 $oldline = clone $this->line;
2924 $this->line->oldline = $oldline;
2926 $this->line->context = $this->context;
2928 $this->line->fk_commande = $this->id;
2930 $this->line->desc = $desc;
2933 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
2934 if ($qty < $this->line->packaging) {
2935 $qty = $this->line->packaging;
2937 if (!empty($this->line->packaging) && ($qty % $this->line->packaging) > 0) {
2938 $coeff = intval($qty / $this->line->packaging) + 1;
2939 $qty = $this->line->packaging * $coeff;
2940 setEventMessage($langs->trans(
'QtyRecalculatedWithPackaging'),
'mesgs');
2945 $this->line->qty = $qty;
2946 $this->line->ref_supplier = $ref_supplier;
2948 $this->line->vat_src_code = $vat_src_code;
2949 $this->line->tva_tx = $txtva;
2950 $this->line->localtax1_tx = $txlocaltax1;
2951 $this->line->localtax2_tx = $txlocaltax2;
2952 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2953 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2954 $this->line->remise_percent = $remise_percent;
2955 $this->line->subprice = $pu_ht;
2956 $this->line->rang = $this->rang;
2957 $this->line->info_bits = $info_bits;
2958 $this->line->total_ht = $total_ht;
2959 $this->line->total_tva = $total_tva;
2960 $this->line->total_localtax1 = $total_localtax1;
2961 $this->line->total_localtax2 = $total_localtax2;
2962 $this->line->total_ttc = $total_ttc;
2963 $this->line->product_type = $type;
2964 $this->line->special_code = (!empty($this->special_code) ? $this->special_code : 0);
2965 $this->line->origin = $this->origin;
2966 $this->line->fk_unit = $fk_unit;
2968 $this->line->date_start = $date_start;
2969 $this->line->date_end = $date_end;
2972 $this->line->fk_multicurrency = $this->fk_multicurrency;
2973 $this->line->multicurrency_code = $this->multicurrency_code;
2974 $this->line->multicurrency_subprice = $pu_ht_devise;
2975 $this->line->multicurrency_total_ht = $multicurrency_total_ht;
2976 $this->line->multicurrency_total_tva = $multicurrency_total_tva;
2977 $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
2979 $this->line->subprice = $pu_ht;
2980 $this->line->price = $this->line->subprice;
2982 $this->line->remise_percent = $remise_percent;
2984 if (is_array($array_options) && count($array_options) > 0) {
2986 foreach ($array_options as $key => $value) {
2987 $this->line->array_options[$key] = $array_options[$key];
2991 $result = $this->line->update($notrigger);
2997 $this->db->commit();
3000 $this->error = $this->db->lasterror();
3001 $this->db->rollback();
3005 $this->error =
"Order status makes operation forbidden";
3006 dol_syslog(get_class($this).
"::updateline ".$this->error, LOG_ERR);
3021 global $user, $langs, $conf;
3023 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
3025 dol_syslog(get_class($this).
"::initAsSpecimen");
3032 $sql =
"SELECT rowid";
3033 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
3034 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
3035 $sql .= $this->db->order(
"rowid",
"ASC");
3036 $sql .= $this->db->plimit(1);
3037 $resql = $this->db->query(
$sql);
3039 $obj = $this->db->fetch_object($resql);
3040 $prodid = $obj->rowid;
3045 $this->
ref =
'SPECIMEN';
3046 $this->specimen = 1;
3049 $this->date_commande = $now;
3050 $this->date_lim_reglement = $this->date + 3600 * 24 * 30;
3051 $this->cond_reglement_code =
'RECEP';
3052 $this->mode_reglement_code =
'CHQ';
3054 $this->note_public =
'This is a comment (public)';
3055 $this->note_private =
'This is a comment (private)';
3057 $this->multicurrency_tx = 1;
3058 $this->multicurrency_code = $conf->currency;
3065 while ($xnbp < $nbp) {
3067 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
3069 $line->subprice = 100;
3071 $line->tva_tx = 19.6;
3072 $line->localtax1_tx = 0;
3073 $line->localtax2_tx = 0;
3075 $line->total_ht = 50;
3076 $line->total_ttc = 59.8;
3077 $line->total_tva = 9.8;
3078 $line->remise_percent = 50;
3080 $line->total_ht = 100;
3081 $line->total_ttc = 119.6;
3082 $line->total_tva = 19.6;
3083 $line->remise_percent = 00;
3085 $line->fk_product = $prodid;
3087 $this->lines[$xnbp] = $line;
3089 $this->total_ht += $line->total_ht;
3090 $this->total_tva += $line->total_tva;
3091 $this->total_ttc += $line->total_ttc;
3105 $sql =
'SELECT c.rowid, date_creation as datec, tms as datem, date_valid as date_validation, date_approve as datea, date_approve2 as datea2,';
3106 $sql .=
' fk_user_author, fk_user_modif, fk_user_valid, fk_user_approve, fk_user_approve2';
3107 $sql .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseur as c';
3108 $sql .=
' WHERE c.rowid = '.((int) $id);
3110 $result = $this->db->query(
$sql);
3112 if ($this->db->num_rows($result)) {
3113 $obj = $this->db->fetch_object($result);
3114 $this->
id = $obj->rowid;
3115 if ($obj->fk_user_author) {
3116 $this->user_creation_id = $obj->fk_user_author;
3118 if ($obj->fk_user_valid) {
3119 $this->user_validation_id = $obj->fk_user_valid;
3121 if ($obj->fk_user_modif) {
3122 $this->user_modification_id = $obj->fk_user_modif;
3124 if ($obj->fk_user_approve) {
3125 $this->user_approve_id = $obj->fk_user_approve;
3127 if ($obj->fk_user_approve2) {
3128 $this->user_approve_id2 = $obj->fk_user_approve2;
3131 $this->date_creation = $this->db->jdate($obj->datec);
3132 $this->date_modification = $this->db->jdate($obj->datem);
3133 $this->date_approve = $this->db->jdate($obj->datea);
3134 $this->date_approve2 = $this->db->jdate($obj->datea2);
3135 $this->date_validation = $this->db->jdate($obj->date_validation);
3137 $this->db->free($result);
3152 global $conf, $user;
3154 $this->nb = array();
3157 $sql =
"SELECT count(co.rowid) as nb";
3158 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseur as co";
3159 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON co.fk_soc = s.rowid";
3160 if (!$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3161 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
3162 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
3165 $sql .=
" ".$clause.
" co.entity IN (".
getEntity(
'supplier_order').
")";
3167 $resql = $this->db->query(
$sql);
3169 while ($obj = $this->db->fetch_object($resql)) {
3170 $this->nb[
"supplier_orders"] = $obj->nb;
3172 $this->db->free($resql);
3176 $this->error = $this->db->error();
3192 global $conf, $langs;
3194 $sql =
"SELECT c.rowid, c.date_creation as datec, c.date_commande, c.fk_statut, c.date_livraison as delivery_date, c.total_ht";
3195 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseur as c";
3196 if (!$user->hasRight(
"societe",
"client",
"voir") && !$user->socid) {
3197 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
3199 $sql .=
" WHERE c.entity = ".$conf->entity;
3200 if ($mode ===
'awaiting') {
3201 $sql .=
" AND c.fk_statut IN (".self::STATUS_ORDERSENT.
", ".self::STATUS_RECEIVED_PARTIALLY.
")";
3203 $sql .=
" AND c.fk_statut IN (".self::STATUS_VALIDATED.
", ".self::STATUS_ACCEPTED.
")";
3206 $sql .=
" AND c.fk_soc = ".((int) $user->socid);
3209 $resql = $this->db->query(
$sql);
3214 $response->warning_delay = $conf->commande->fournisseur->warning_delay / 60 / 60 / 24;
3215 $response->label = $langs->trans(
"SuppliersOrdersToProcess");
3216 $response->labelShort = $langs->trans(
"Opened");
3217 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=1,2&mainmenu=commercial&leftmenu=orders_suppliers';
3220 if ($mode ===
'awaiting') {
3221 $response->label = $langs->trans(
"SuppliersOrdersAwaitingReception");
3222 $response->labelShort = $langs->trans(
"AwaitingReception");
3223 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=3,4&mainmenu=commercial&leftmenu=orders_suppliers';
3226 while ($obj = $this->db->fetch_object($resql)) {
3227 $commandestatic->delivery_date = $this->db->jdate($obj->delivery_date);
3228 $commandestatic->date_commande = $this->db->jdate($obj->date_commande);
3229 $commandestatic->statut = $obj->fk_statut;
3231 $response->nbtodo++;
3232 $response->total += $obj->total_ht;
3234 if ($commandestatic->hasDelay()) {
3235 $response->nbtodolate++;
3241 $this->error = $this->db->error();
3256 if ($this->methode_commande_id > 0) {
3257 $sql =
"SELECT rowid, code, libelle as label";
3258 $sql .=
" FROM ".MAIN_DB_PREFIX.
'c_input_method';
3259 $sql .=
" WHERE active=1 AND rowid = ".((int) $this->methode_commande_id);
3261 $resql = $this->db->query(
$sql);
3263 if ($this->db->num_rows($resql)) {
3264 $obj = $this->db->fetch_object($resql);
3266 $string = $langs->trans($obj->code);
3267 if ($string == $obj->code) {
3268 $string = $obj->label !=
'-' ? $obj->label :
'';
3291 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
3293 global $conf, $langs;
3298 if (!empty($this->model_pdf)) {
3299 $modele = $this->model_pdf;
3300 } elseif (!empty($conf->global->COMMANDE_SUPPLIER_ADDON_PDF)) {
3305 if (empty($modele)) {
3308 $langs->load(
"suppliers");
3309 $outputlangs->load(
"products");
3311 $modelpath =
"core/modules/supplier_order/doc/";
3312 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3324 if (empty($this->lines)) {
3331 foreach ($this->lines as $line) {
3332 if ($line->fk_product > 0) {
3333 $idp = $obj->find_min_price_product_fournisseur($line->fk_product, $line->qty);
3336 if ($obj->delivery_time_days > $nb) {
3337 $nb = $obj->delivery_time_days;
3346 return $nb.
' '.$langs->trans(
'Days');
3358 return $user->hasRight(
"fournisseur",
"commande");
3373 'commande_fournisseur'
3390 'commande_fournisseurdet'
3407 if (empty($this->delivery_date) && !empty($this->date_livraison)) {
3408 $this->delivery_date = $this->date_livraison;
3411 if ($this->statut == self::STATUS_ORDERSENT || $this->statut == self::STATUS_RECEIVED_PARTIALLY) {
3413 if (!empty($this->delivery_date)) {
3414 $date_to_test = $this->delivery_date;
3415 return $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay);
3423 $date_to_test = $this->date_commande;
3425 return ($this->statut > 0 && $this->statut < 5) && $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay);
3438 global $conf, $langs;
3440 if (empty($this->delivery_date) && !empty($this->date_livraison)) {
3441 $this->delivery_date = $this->date_livraison;
3446 if ($this->statut == self::STATUS_ORDERSENT || $this->statut == self::STATUS_RECEIVED_PARTIALLY) {
3447 if (!empty($this->delivery_date)) {
3448 $text = $langs->trans(
"DeliveryDate").
' '.
dol_print_date($this->delivery_date,
'day');
3450 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3453 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3456 $text .=
' '.($conf->commande->fournisseur->warning_delay > 0 ?
'+' :
'-').
' '.round(abs($conf->commande->fournisseur->warning_delay) / 3600 / 24, 1).
' '.$langs->trans(
"days").
' < '.$langs->trans(
"Today");
3473 global $conf, $langs;
3476 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
3478 $qtydelivered = array();
3479 $qtywished = array();
3482 $filter = array(
't.fk_commande'=>$this->
id);
3483 if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) {
3484 $filter[
't.status'] = 1;
3487 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
3489 $this->error = $supplierorderdispatch->error; $this->errors = $supplierorderdispatch->errors;
3492 if (is_array($supplierorderdispatch->lines) && count($supplierorderdispatch->lines) > 0) {
3493 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
3497 foreach ($supplierorderdispatch->lines as $line) {
3498 $qtydelivered[$line->fk_product] += $line->qty;
3500 foreach ($this->lines as $line) {
3502 if (empty($conf->global->STOCK_SUPPORTS_SERVICES) && $line->product_type > 0) {
3505 $qtywished[$line->fk_product] += $line->qty;
3509 $diff_array = array_diff_assoc($qtydelivered, $qtywished);
3510 $keysinwishednotindelivered = array_diff(array_keys($qtywished), array_keys($qtydelivered));
3511 $keysindeliverednotinwished = array_diff(array_keys($qtydelivered), array_keys($qtywished));
3519 if (count($diff_array) == 0 && count($keysinwishednotindelivered) == 0 && count($keysindeliverednotinwished) == 0) {
3520 if ($closeopenorder) {
3522 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3530 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3536 } elseif (!empty($conf->global->SUPPLIER_ORDER_MORE_THAN_WISHED)) {
3541 if (count($diff_array) > 0) {
3545 foreach ($diff_array as $key => $value) {
3547 if ($qtydelivered[$key] >= $qtywished[$key]) {
3554 if ($close == count($diff_array)) {
3556 if ($closeopenorder) {
3557 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3564 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3572 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3580 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3602 $this->receptions = array();
3604 dol_syslog(get_class($this).
"::loadReceptions", LOG_DEBUG);
3606 $sql =
'SELECT cd.rowid, cd.fk_product,';
3607 $sql .=
' sum(cfd.qty) as qty';
3608 $sql .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseur_dispatch as cfd,';
3609 if ($filtre_statut >= 0) {
3610 $sql .=
' '.MAIN_DB_PREFIX.
'reception as e,';
3612 $sql .=
' '.MAIN_DB_PREFIX.
'commande_fournisseurdet as cd';
3614 if ($filtre_statut >= 0) {
3615 $sql .=
' cfd.fk_reception = e.rowid AND';
3617 $sql .=
' cfd.fk_commandefourndet = cd.rowid';
3618 $sql .=
' AND cd.fk_commande ='.((int) $this->
id);
3619 if (isset($this->fk_product) && !empty($this->fk_product) > 0) {
3620 $sql .=
' AND cd.fk_product = '.((int) $this->fk_product);
3622 if ($filtre_statut >= 0) {
3623 $sql .=
' AND e.fk_statut >= '.((int) $filtre_statut);
3625 $sql .=
' GROUP BY cd.rowid, cd.fk_product';
3627 $resql = $this->db->query(
$sql);
3629 $num = $this->db->num_rows($resql);
3632 $obj = $this->db->fetch_object($resql);
3633 empty($this->receptions[$obj->rowid]) ? $this->receptions[$obj->rowid] = $obj->qty : $this->receptions[$obj->rowid] += $obj->qty;
3636 $this->db->free($resql);
3640 $this->error = $this->db->lasterror();
3656 $selected = (empty($arraydata[
'selected']) ? 0 : $arraydata[
'selected']);
3658 $return =
'<div class="box-flex-item box-flex-grow-zero">';
3659 $return .=
'<div class="info-box info-box-sm">';
3660 $return .=
'<span class="info-box-icon bg-infobox-action">';
3662 $return .=
'</span>';
3663 $return .=
'<div class="info-box-content">';
3664 $return .=
'<span class="info-box-ref inline-block tdoverflowmax150 valignmiddle">'.(method_exists($this,
'getNomUrl') ? $this->
getNomUrl() : $this->ref).
'</span>';
3665 $return .=
'<input id="cb'.$this->id.
'" class="flat checkforselect fright" type="checkbox" name="toselect[]" value="'.$this->
id.
'"'.($selected ?
' checked="checked"' :
'').
'>';
3666 if (property_exists($this,
'socid') || property_exists($this,
'total_tva')) {
3667 $return .=
'<br><span class="info-box-label amount">'.$this->socid.
'</span>';
3669 if (property_exists($this,
'billed')) {
3670 $return .=
'<br><span class="opacitymedium">'.$langs->trans(
"Billed").
' : </span><span class="info-box-label">'.
yn($this->billed).
'</span>';
3672 if (method_exists($this,
'getLibStatut')) {
3673 $return .=
'<br><div class="info-box-status margintoponly">'.$this->getLibStatut(3).
'</div>';
3675 $return .=
'</div>';
3676 $return .=
'</div>';
3677 $return .=
'</div>';
3692 public $element =
'commande_fournisseurdet';
3697 public $table_element =
'commande_fournisseurdet';
3705 public $fk_commande;
3711 public $fk_parent_line;
3719 public $special_code = 0;
3736 public $ref_supplier;
3768 $sql =
'SELECT cd.rowid, cd.fk_commande, cd.fk_product, cd.product_type, cd.description, cd.qty, cd.tva_tx, cd.special_code,';
3769 $sql .=
' cd.localtax1_tx, cd.localtax2_tx, cd.localtax1_type, cd.localtax2_type, cd.ref as ref_supplier,';
3770 $sql .=
' cd.remise, cd.remise_percent, cd.subprice,';
3771 $sql .=
' cd.info_bits, cd.total_ht, cd.total_tva, cd.total_ttc,';
3772 $sql .=
' cd.total_localtax1, cd.total_localtax2,';
3773 $sql .=
' p.ref as product_ref, p.label as product_label, p.description as product_desc,';
3774 $sql .=
' cd.date_start, cd.date_end, cd.fk_unit,';
3775 $sql .=
' cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc,';
3776 $sql .=
' c.fk_soc as socid';
3777 $sql .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseur as c, '.MAIN_DB_PREFIX.
'commande_fournisseurdet as cd';
3778 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON cd.fk_product = p.rowid';
3779 $sql .=
' WHERE cd.fk_commande = c.rowid AND cd.rowid = '.((int) $rowid);
3781 $result = $this->db->query(
$sql);
3783 $objp = $this->db->fetch_object($result);
3785 if (!empty($objp)) {
3786 $this->
rowid = $objp->rowid;
3787 $this->
id = $objp->rowid;
3788 $this->fk_commande = $objp->fk_commande;
3789 $this->desc = $objp->description;
3790 $this->qty = $objp->qty;
3791 $this->ref_fourn = $objp->ref_supplier;
3792 $this->ref_supplier = $objp->ref_supplier;
3793 $this->subprice = $objp->subprice;
3794 $this->tva_tx = $objp->tva_tx;
3795 $this->localtax1_tx = $objp->localtax1_tx;
3796 $this->localtax2_tx = $objp->localtax2_tx;
3797 $this->localtax1_type = $objp->localtax1_type;
3798 $this->localtax2_type = $objp->localtax2_type;
3799 $this->remise = $objp->remise;
3800 $this->remise_percent = $objp->remise_percent;
3801 $this->fk_product = $objp->fk_product;
3802 $this->info_bits = $objp->info_bits;
3803 $this->total_ht = $objp->total_ht;
3804 $this->total_tva = $objp->total_tva;
3805 $this->total_localtax1 = $objp->total_localtax1;
3806 $this->total_localtax2 = $objp->total_localtax2;
3807 $this->total_ttc = $objp->total_ttc;
3808 $this->product_type = $objp->product_type;
3809 $this->special_code = $objp->special_code;
3811 $this->
ref = $objp->product_ref;
3813 $this->product_ref = $objp->product_ref;
3814 $this->product_label = $objp->product_label;
3815 $this->product_desc = $objp->product_desc;
3817 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
3822 $sqlsearchpackage =
'SELECT rowid, packaging FROM '.MAIN_DB_PREFIX.
"product_fournisseur_price";
3823 $sqlsearchpackage .=
' WHERE entity IN ('.getEntity(
'product_fournisseur_price').
")";
3824 $sqlsearchpackage .=
" AND fk_product = ".((int) $objp->fk_product);
3825 $sqlsearchpackage .=
" AND ref_fourn = '".$this->db->escape($objp->ref_supplier).
"'";
3826 $sqlsearchpackage .=
" AND quantity <= ".((float) $objp->qty);
3827 $sqlsearchpackage .=
" AND (packaging IS NULL OR packaging = 0 OR packaging <= ".((float) $objp->qty).
")";
3828 $sqlsearchpackage .=
" AND fk_soc = ".((int) $objp->socid);
3829 $sqlsearchpackage .=
" ORDER BY packaging ASC";
3830 $sqlsearchpackage .=
" LIMIT 1";
3832 $resqlsearchpackage = $this->db->query($sqlsearchpackage);
3833 if ($resqlsearchpackage) {
3834 $objsearchpackage = $this->db->fetch_object($resqlsearchpackage);
3835 if ($objsearchpackage) {
3836 $this->fk_fournprice = $objsearchpackage->rowid;
3837 $this->packaging = $objsearchpackage->packaging;
3840 $this->error = $this->db->lasterror();
3845 $this->date_start = $this->db->jdate($objp->date_start);
3846 $this->date_end = $this->db->jdate($objp->date_end);
3847 $this->fk_unit = $objp->fk_unit;
3849 $this->multicurrency_subprice = $objp->multicurrency_subprice;
3850 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
3851 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
3852 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
3856 $this->db->free($result);
3859 $this->error =
'Supplier order line with id='.$rowid.
' not found';
3860 dol_syslog(get_class($this).
"::fetch Error ".$this->error, LOG_ERR);
3877 global $conf, $user;
3881 dol_syslog(get_class($this).
"::insert rang=".$this->rang);
3884 if (empty($this->tva_tx)) {
3887 if (empty($this->localtax1_tx)) {
3888 $this->localtax1_tx = 0;
3890 if (empty($this->localtax2_tx)) {
3891 $this->localtax2_tx = 0;
3893 if (empty($this->localtax1_type)) {
3894 $this->localtax1_type =
'0';
3896 if (empty($this->localtax2_type)) {
3897 $this->localtax2_type =
'0';
3899 if (empty($this->total_localtax1)) {
3900 $this->total_localtax1 = 0;
3902 if (empty($this->total_localtax2)) {
3903 $this->total_localtax2 = 0;
3905 if (empty($this->rang)) {
3908 if (empty($this->remise_percent)) {
3909 $this->remise_percent = 0;
3911 if (empty($this->info_bits)) {
3912 $this->info_bits = 0;
3914 if (empty($this->special_code)) {
3915 $this->special_code = 0;
3917 if (empty($this->fk_parent_line)) {
3918 $this->fk_parent_line = 0;
3920 if (empty($this->pa_ht)) {
3925 if (!empty($this->multicurrency_code)) {
3928 if (empty($this->fk_multicurrency)) {
3929 $this->multicurrency_code = $conf->currency;
3930 $this->fk_multicurrency = 0;
3931 $this->multicurrency_tx = 1;
3935 if ($this->product_type < 0) {
3942 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element;
3943 $sql .=
" (fk_commande, label, description, date_start, date_end,";
3944 $sql .=
" fk_product, product_type, special_code, rang,";
3945 $sql .=
" qty, vat_src_code, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, remise_percent, subprice, ref,";
3946 $sql .=
" total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_unit,";
3947 $sql .=
" fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc";
3949 $sql .=
" VALUES (".$this->fk_commande.
", '".$this->db->escape($this->label).
"','".$this->db->escape($this->desc).
"',";
3950 $sql .=
" ".($this->date_start ?
"'".$this->db->idate($this->date_start).
"'" :
"null").
",";
3951 $sql .=
" ".($this->date_end ?
"'".$this->db->idate($this->date_end).
"'" :
"null").
",";
3952 if ($this->fk_product) {
3953 $sql .= $this->fk_product.
",";
3957 $sql .=
"'".$this->db->escape($this->product_type).
"',";
3958 $sql .=
"'".$this->db->escape($this->special_code).
"',";
3959 $sql .=
"'".$this->db->escape($this->rang).
"',";
3960 $sql .=
"'".$this->db->escape($this->qty).
"', ";
3961 $sql .=
" ".(empty($this->vat_src_code) ?
"''" :
"'".$this->db->escape($this->vat_src_code).
"'").
",";
3962 $sql .=
" ".price2num($this->tva_tx).
", ";
3963 $sql .=
" ".price2num($this->localtax1_tx).
",";
3964 $sql .=
" ".price2num($this->localtax2_tx).
",";
3965 $sql .=
" '".$this->db->escape($this->localtax1_type).
"',";
3966 $sql .=
" '".$this->db->escape($this->localtax2_type).
"',";
3967 $sql .=
" ".((float) $this->remise_percent).
", ".
price2num($this->subprice,
'MU').
", '".$this->db->escape($this->ref_supplier).
"',";
3968 $sql .=
" ".price2num($this->total_ht).
",";
3969 $sql .=
" ".price2num($this->total_tva).
",";
3970 $sql .=
" ".price2num($this->total_localtax1).
",";
3971 $sql .=
" ".price2num($this->total_localtax2).
",";
3972 $sql .=
" ".price2num($this->total_ttc).
",";
3973 $sql .= ($this->fk_unit ?
"'".$this->db->escape($this->fk_unit).
"'" :
"null");
3974 $sql .=
", ".($this->fk_multicurrency ? ((int) $this->fk_multicurrency) :
"null");
3975 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
3976 $sql .=
", ".($this->multicurrency_subprice ?
price2num($this->multicurrency_subprice) :
'0');
3977 $sql .=
", ".($this->multicurrency_total_ht ?
price2num($this->multicurrency_total_ht) :
'0');
3978 $sql .=
", ".($this->multicurrency_total_tva ?
price2num($this->multicurrency_total_tva) :
'0');
3979 $sql .=
", ".($this->multicurrency_total_ttc ?
price2num($this->multicurrency_total_ttc) :
'0');
3982 dol_syslog(get_class($this).
"::insert", LOG_DEBUG);
3983 $resql = $this->db->query(
$sql);
3985 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
3986 $this->
rowid = $this->id;
3995 if (!$error && !$notrigger) {
3997 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_CREATE', $user);
4005 $this->db->commit();
4009 foreach ($this->errors as $errmsg) {
4010 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
4011 $this->errors[] = ($this->errors ?
', '.$errmsg : $errmsg);
4013 $this->db->rollback();
4016 $this->errors[] = $this->db->error();
4017 $this->db->rollback();
4029 global $conf, $user;
4036 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
4037 $sql .=
" description='".$this->db->escape($this->desc).
"'";
4038 $sql .=
", ref='".$this->db->escape($this->ref_supplier).
"'";
4039 $sql .=
", subprice='".price2num($this->subprice).
"'";
4041 $sql .=
", remise_percent='".price2num($this->remise_percent).
"'";
4043 $sql .=
", vat_src_code = '".(empty($this->vat_src_code) ?
'' : $this->vat_src_code).
"'";
4044 $sql .=
", tva_tx='".price2num($this->tva_tx).
"'";
4045 $sql .=
", localtax1_tx='".price2num($this->localtax1_tx).
"'";
4046 $sql .=
", localtax2_tx='".price2num($this->localtax2_tx).
"'";
4047 $sql .=
", localtax1_type='".$this->db->escape($this->localtax1_type).
"'";
4048 $sql .=
", localtax2_type='".$this->db->escape($this->localtax2_type).
"'";
4049 $sql .=
", qty='".price2num($this->qty).
"'";
4050 $sql .=
", date_start=".(!empty($this->date_start) ?
"'".$this->db->idate($this->date_start).
"'" :
"null");
4051 $sql .=
", date_end=".(!empty($this->date_end) ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
4052 $sql .=
", info_bits='".$this->db->escape($this->info_bits).
"'";
4053 $sql .=
", total_ht='".price2num($this->total_ht).
"'";
4054 $sql .=
", total_tva='".price2num($this->total_tva).
"'";
4055 $sql .=
", total_localtax1='".price2num($this->total_localtax1).
"'";
4056 $sql .=
", total_localtax2='".price2num($this->total_localtax2).
"'";
4057 $sql .=
", total_ttc='".price2num($this->total_ttc).
"'";
4058 $sql .=
", product_type=".$this->product_type;
4059 $sql .=
", special_code=".(!empty($this->special_code) ? $this->special_code : 0);
4060 $sql .= ($this->fk_unit ?
", fk_unit='".$this->db->escape($this->fk_unit).
"'" :
", fk_unit=null");
4063 $sql .=
", multicurrency_subprice=".price2num($this->multicurrency_subprice);
4064 $sql .=
", multicurrency_total_ht=".price2num($this->multicurrency_total_ht);
4065 $sql .=
", multicurrency_total_tva=".price2num($this->multicurrency_total_tva);
4066 $sql .=
", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc);
4068 $sql .=
" WHERE rowid = ".((int) $this->
id);
4070 dol_syslog(get_class($this).
"::updateline", LOG_DEBUG);
4071 $resql = $this->db->query(
$sql);
4080 if (!$error && !$notrigger) {
4082 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_MODIFY', $user);
4084 $this->db->rollback();
4091 $this->db->commit();
4094 $this->db->rollback();
4098 $this->error = $this->db->lasterror();
4099 $this->db->rollback();
4110 public function delete($notrigger = 0)
4121 $this->db->rollback();
4125 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
"commande_fournisseurdet WHERE rowid=".((int) $this->
id);
4128 $resql = $this->db->query(
$sql);
4132 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_DELETE', $user);
4140 $this->db->commit();
4144 foreach ($this->errors as $errmsg) {
4145 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
4146 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
4148 $this->db->rollback();
4151 $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.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
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 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.
if(isModEnabled('facture') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $sql
Social contributions to pay.
print *****$script_file(".$version.") pid c cd cd cd description as p label as s rowid
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...
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
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.
isModEnabled($module)
Is Dolibarr module enabled.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $remise_percent_global, $price_base_type, $info_bits, $type, $seller='', $localtaxes_array='', $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.