37 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonorder.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
39 if (!empty($conf->productbatch->enabled)) {
40 require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
42 require_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
52 public $element =
'order_supplier';
57 public $table_element =
'commande_fournisseur';
62 public $table_element_line =
'commande_fournisseurdet';
67 public $fk_element =
'fk_commande';
72 public $picto =
'supplier_order';
78 public $ismultientitymanaged = 1;
84 public $restrictiononfksoc = 1;
102 public $ref_supplier;
116 public $date_creation;
118 public $date_approve;
119 public $date_approve2;
120 public $date_commande;
126 public $date_livraison;
131 public $delivery_date;
135 public $total_localtax1;
136 public $total_localtax2;
145 public $cond_reglement_id;
146 public $cond_reglement_code;
147 public $cond_reglement_label;
148 public $cond_reglement_doc;
155 public $mode_reglement_id;
156 public $mode_reglement_code;
157 public $user_author_id;
158 public $user_valid_id;
159 public $user_approve_id;
160 public $user_approve_id2;
164 public $extraparams = array();
169 public $lines = array();
174 public $linked_objects = array();
180 public $fk_multicurrency;
182 public $multicurrency_code;
183 public $multicurrency_tx;
184 public $multicurrency_total_ht;
185 public $multicurrency_total_tva;
186 public $multicurrency_total_ttc;
217 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>0,
'notnull'=>1,
'position'=>10),
218 'ref' =>array(
'type'=>
'varchar(255)',
'label'=>
'Ref',
'enabled'=>1,
'visible'=>1,
'showoncombobox'=>1,
'position'=>25,
'searchall'=>1),
219 'ref_ext' =>array(
'type'=>
'varchar(255)',
'label'=>
'Ref ext',
'enabled'=>1,
'visible'=>0,
'position'=>35),
220 'ref_supplier' =>array(
'type'=>
'varchar(255)',
'label'=>
'RefOrderSupplierShort',
'enabled'=>1,
'visible'=>1,
'position'=>40,
'searchall'=>1),
221 'fk_projet' =>array(
'type'=>
'integer:Project:projet/class/project.class.php:1:fk_statut=1',
'label'=>
'Project',
'enabled'=>
'$conf->project->enabled',
'visible'=>-1,
'position'=>45),
222 'date_valid' =>array(
'type'=>
'datetime',
'label'=>
'DateValidation',
'enabled'=>1,
'visible'=>-1,
'position'=>60),
223 'date_approve' =>array(
'type'=>
'datetime',
'label'=>
'DateApprove',
'enabled'=>1,
'visible'=>-1,
'position'=>62),
224 'date_approve2' =>array(
'type'=>
'datetime',
'label'=>
'DateApprove2',
'enabled'=>1,
'visible'=>3,
'position'=>64),
225 'date_commande' =>array(
'type'=>
'date',
'label'=>
'OrderDateShort',
'enabled'=>1,
'visible'=>1,
'position'=>70),
226 'date_livraison' =>array(
'type'=>
'datetime',
'label'=>
'DeliveryDate',
'enabled'=>
'empty($conf->global->ORDER_DISABLE_DELIVERY_DATE)',
'visible'=>1,
'position'=>74),
227 'fk_user_author' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserAuthor',
'enabled'=>1,
'visible'=>3,
'position'=>75),
228 'fk_user_modif' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>3,
'notnull'=>-1,
'position'=>80),
229 'fk_user_valid' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserValidation',
'enabled'=>1,
'visible'=>3,
'position'=>85),
230 'fk_user_approve' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserApproval',
'enabled'=>1,
'visible'=>3,
'position'=>90),
231 'fk_user_approve2' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserApproval2',
'enabled'=>1,
'visible'=>3,
'position'=>95),
232 'source' =>array(
'type'=>
'smallint(6)',
'label'=>
'Source',
'enabled'=>1,
'visible'=>3,
'notnull'=>1,
'position'=>100),
233 'billed' =>array(
'type'=>
'smallint(6)',
'label'=>
'Billed',
'enabled'=>1,
'visible'=>1,
'position'=>110),
234 'total_tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'Tva',
'enabled'=>1,
'visible'=>1,
'position'=>130,
'isameasure'=>1),
235 'localtax1' =>array(
'type'=>
'double(24,8)',
'label'=>
'Localtax1',
'enabled'=>1,
'visible'=>3,
'position'=>135,
'isameasure'=>1),
236 'localtax2' =>array(
'type'=>
'double(24,8)',
'label'=>
'Localtax2',
'enabled'=>1,
'visible'=>3,
'position'=>140,
'isameasure'=>1),
237 'total_ht' =>array(
'type'=>
'double(24,8)',
'label'=>
'TotalHT',
'enabled'=>1,
'visible'=>1,
'position'=>145,
'isameasure'=>1),
238 'total_ttc' =>array(
'type'=>
'double(24,8)',
'label'=>
'TotalTTC',
'enabled'=>1,
'visible'=>-1,
'position'=>150,
'isameasure'=>1),
239 'note_public' =>array(
'type'=>
'text',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>155,
'searchall'=>1),
240 'note_private' =>array(
'type'=>
'text',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>0,
'position'=>160,
'searchall'=>1),
241 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'ModelPDF',
'enabled'=>1,
'visible'=>0,
'position'=>165),
242 'fk_input_method' =>array(
'type'=>
'integer',
'label'=>
'OrderMode',
'enabled'=>1,
'visible'=>3,
'position'=>170),
243 'fk_cond_reglement' =>array(
'type'=>
'integer',
'label'=>
'PaymentTerm',
'enabled'=>1,
'visible'=>3,
'position'=>175),
244 'fk_mode_reglement' =>array(
'type'=>
'integer',
'label'=>
'PaymentMode',
'enabled'=>1,
'visible'=>3,
'position'=>180),
245 'extraparams' =>array(
'type'=>
'varchar(255)',
'label'=>
'Extraparams',
'enabled'=>1,
'visible'=>0,
'position'=>190),
246 'fk_account' =>array(
'type'=>
'integer',
'label'=>
'BankAccount',
'enabled'=>
'$conf->banque->enabled',
'visible'=>3,
'position'=>200),
247 'fk_incoterms' =>array(
'type'=>
'integer',
'label'=>
'IncotermCode',
'enabled'=>1,
'visible'=>3,
'position'=>205),
248 'location_incoterms' =>array(
'type'=>
'varchar(255)',
'label'=>
'IncotermLocation',
'enabled'=>1,
'visible'=>3,
'position'=>210),
249 'fk_multicurrency' =>array(
'type'=>
'integer',
'label'=>
'Fk multicurrency',
'enabled'=>1,
'visible'=>0,
'position'=>215),
250 'multicurrency_code' =>array(
'type'=>
'varchar(255)',
'label'=>
'Currency',
'enabled'=>
'!empty($conf->multicurrency->enabled)',
'visible'=>-1,
'position'=>220),
251 'multicurrency_tx' =>array(
'type'=>
'double(24,8)',
'label'=>
'CurrencyRate',
'enabled'=>
'!empty($conf->multicurrency->enabled)',
'visible'=>-1,
'position'=>225),
252 'multicurrency_total_ht' =>array(
'type'=>
'double(24,8)',
'label'=>
'MulticurrencyAmountHT',
'enabled'=>
'!empty($conf->multicurrency->enabled)',
'visible'=>-1,
'position'=>230),
253 'multicurrency_total_tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'MulticurrencyAmountVAT',
'enabled'=>
'!empty($conf->multicurrency->enabled)',
'visible'=>-1,
'position'=>235),
254 'multicurrency_total_ttc' =>array(
'type'=>
'double(24,8)',
'label'=>
'MulticurrencyAmountTTC',
'enabled'=>
'!empty($conf->multicurrency->enabled)',
'visible'=>-1,
'position'=>240),
255 'date_creation' =>array(
'type'=>
'datetime',
'label'=>
'Date creation',
'enabled'=>1,
'visible'=>-1,
'position'=>500),
256 'fk_soc' =>array(
'type'=>
'integer:Societe:societe/class/societe.class.php',
'label'=>
'ThirdParty',
'enabled'=>
'$conf->societe->enabled',
'visible'=>1,
'notnull'=>1,
'position'=>46),
257 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>0,
'notnull'=>1,
'position'=>1000,
'index'=>1),
258 'tms'=>array(
'type'=>
'datetime',
'label'=>
"DateModificationShort",
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>501),
259 'last_main_doc' =>array(
'type'=>
'varchar(255)',
'label'=>
'LastMainDoc',
'enabled'=>1,
'visible'=>0,
'position'=>700),
260 'fk_statut' =>array(
'type'=>
'smallint(6)',
'label'=>
'Status',
'enabled'=>1,
'visible'=>1,
'position'=>701),
261 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>0,
'position'=>900),
336 public function fetch($id, $ref =
'')
341 if (empty($id) && empty($ref)) {
345 $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,";
346 $sql .=
" c.localtax1, c.localtax2, ";
347 $sql .=
" c.date_creation, c.date_valid, c.date_approve, c.date_approve2,";
348 $sql .=
" c.fk_user_author, c.fk_user_valid, c.fk_user_approve, c.fk_user_approve2,";
349 $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,";
350 $sql .=
" c.fk_account,";
351 $sql .=
" c.note_private, c.note_public, c.model_pdf, c.extraparams, c.billed,";
352 $sql .=
" c.fk_multicurrency, c.multicurrency_code, c.multicurrency_tx, c.multicurrency_total_ht, c.multicurrency_total_tva, c.multicurrency_total_ttc,";
353 $sql .=
" cm.libelle as methode_commande,";
354 $sql .=
" cr.code as cond_reglement_code, cr.libelle as cond_reglement_label, cr.libelle_facture as cond_reglement_doc,";
355 $sql .=
" p.code as mode_reglement_code, p.libelle as mode_reglement_libelle";
356 $sql .=
', c.fk_incoterms, c.location_incoterms';
357 $sql .=
', i.libelle as label_incoterms';
358 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseur as c";
359 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_payment_term as cr ON c.fk_cond_reglement = cr.rowid";
360 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as p ON c.fk_mode_reglement = p.id";
361 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_input_method as cm ON cm.rowid = c.fk_input_method";
362 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON c.fk_incoterms = i.rowid';
365 $sql .=
" WHERE c.entity IN (".getEntity(
'supplier_order').
")";
367 $sql .=
" WHERE c.rowid=".((int) $id);
371 $sql .=
" AND c.ref='".$this->db->escape($ref).
"'";
374 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
377 $obj = $this->
db->fetch_object(
$resql);
379 $this->error =
'Bill with id '.$id.
' not found';
380 dol_syslog(get_class($this).
'::fetch '.$this->error);
384 $this->
id = $obj->rowid;
385 $this->entity = $obj->entity;
387 $this->
ref = $obj->ref;
388 $this->ref_supplier = $obj->ref_supplier;
389 $this->socid = $obj->fk_soc;
390 $this->fourn_id = $obj->fk_soc;
391 $this->statut = $obj->fk_statut;
392 $this->status = $obj->fk_statut;
393 $this->billed = $obj->billed;
394 $this->user_author_id = $obj->fk_user_author;
395 $this->user_valid_id = $obj->fk_user_valid;
396 $this->user_approve_id = $obj->fk_user_approve;
397 $this->user_approve_id2 = $obj->fk_user_approve2;
398 $this->total_ht = $obj->total_ht;
399 $this->total_tva = $obj->total_tva;
400 $this->total_localtax1 = $obj->localtax1;
401 $this->total_localtax2 = $obj->localtax2;
402 $this->total_ttc = $obj->total_ttc;
403 $this->date_creation = $this->
db->jdate($obj->date_creation);
404 $this->date_valid = $this->
db->jdate($obj->date_valid);
405 $this->date_approve = $this->
db->jdate($obj->date_approve);
406 $this->date_approve2 = $this->
db->jdate($obj->date_approve2);
407 $this->date_commande = $this->
db->jdate($obj->date_commande);
408 if (isset($obj->date_commande)) {
409 $this->date = $this->date_commande;
411 $this->date = $this->date_creation;
413 $this->date_livraison = $this->
db->jdate($obj->delivery_date);
414 $this->delivery_date = $this->
db->jdate($obj->delivery_date);
415 $this->remise_percent = $obj->remise_percent;
416 $this->methode_commande_id = $obj->fk_input_method;
417 $this->methode_commande = $obj->methode_commande;
419 $this->source = $obj->source;
420 $this->fk_project = $obj->fk_project;
421 $this->cond_reglement_id = $obj->fk_cond_reglement;
422 $this->cond_reglement_code = $obj->cond_reglement_code;
423 $this->cond_reglement = $obj->cond_reglement_label;
424 $this->cond_reglement_label = $obj->cond_reglement_label;
425 $this->cond_reglement_doc = $obj->cond_reglement_doc;
426 $this->fk_account = $obj->fk_account;
427 $this->mode_reglement_id = $obj->fk_mode_reglement;
428 $this->mode_reglement_code = $obj->mode_reglement_code;
429 $this->mode_reglement = $obj->mode_reglement_libelle;
430 $this->note = $obj->note_private;
431 $this->note_private = $obj->note_private;
432 $this->note_public = $obj->note_public;
433 $this->model_pdf = $obj->model_pdf;
434 $this->modelpdf = $obj->model_pdf;
437 $this->fk_incoterms = $obj->fk_incoterms;
438 $this->location_incoterms = $obj->location_incoterms;
439 $this->label_incoterms = $obj->label_incoterms;
442 $this->fk_multicurrency = $obj->fk_multicurrency;
443 $this->multicurrency_code = $obj->multicurrency_code;
444 $this->multicurrency_tx = $obj->multicurrency_tx;
445 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
446 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
447 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
449 $this->extraparams = (array) json_decode($obj->extraparams,
true);
457 if ($this->statut == 0) {
458 $this->brouillon = 1;
472 $this->error = $this->
db->error().
" sql=".$sql;
489 $this->lines = array();
491 $sql =
"SELECT l.rowid, l.ref as ref_supplier, l.fk_product, l.product_type, l.label, l.description, l.qty,";
492 $sql .=
" l.vat_src_code, l.tva_tx, l.remise_percent, l.subprice,";
493 $sql .=
" l.localtax1_tx, l. localtax2_tx, l.localtax1_type, l. localtax2_type, l.total_localtax1, l.total_localtax2,";
494 $sql .=
" l.total_ht, l.total_tva, l.total_ttc, l.special_code, l.fk_parent_line, l.rang,";
495 $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,";
496 $sql .=
" l.fk_unit,";
497 $sql .=
" l.date_start, l.date_end,";
498 $sql .=
' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc';
499 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as l";
500 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON l.fk_product = p.rowid';
501 $sql .=
" WHERE l.fk_commande = ".((int) $this->
id);
503 $sql .=
' AND p.fk_product_type = 0';
505 $sql .=
" ORDER BY l.rang, l.rowid";
508 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
510 $result = $this->
db->query($sql);
512 $num = $this->
db->num_rows($result);
516 $objp = $this->
db->fetch_object($result);
520 $line->id = $objp->rowid;
521 $line->desc = $objp->description;
522 $line->description = $objp->description;
523 $line->qty = $objp->qty;
524 $line->tva_tx = $objp->tva_tx;
525 $line->localtax1_tx = $objp->localtax1_tx;
526 $line->localtax2_tx = $objp->localtax2_tx;
527 $line->localtax1_type = $objp->localtax1_type;
528 $line->localtax2_type = $objp->localtax2_type;
529 $line->subprice = $objp->subprice;
530 $line->pu_ht = $objp->subprice;
531 $line->remise_percent = $objp->remise_percent;
533 $line->vat_src_code = $objp->vat_src_code;
534 $line->total_ht = $objp->total_ht;
535 $line->total_tva = $objp->total_tva;
536 $line->total_localtax1 = $objp->total_localtax1;
537 $line->total_localtax2 = $objp->total_localtax2;
538 $line->total_ttc = $objp->total_ttc;
539 $line->product_type = $objp->product_type;
541 $line->fk_product = $objp->fk_product;
543 $line->libelle = $objp->product_label;
544 $line->product_label = $objp->product_label;
545 $line->product_desc = $objp->product_desc;
546 $line->product_tobatch = $objp->product_tobatch;
547 $line->product_barcode = $objp->product_barcode;
549 $line->ref = $objp->product_ref;
550 $line->product_ref = $objp->product_ref;
551 $line->ref_fourn = $objp->ref_supplier;
552 $line->ref_supplier = $objp->ref_supplier;
554 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
559 $sqlsearchpackage =
'SELECT rowid, packaging FROM '.MAIN_DB_PREFIX.
"product_fournisseur_price";
560 $sqlsearchpackage .=
' WHERE entity IN ('.getEntity(
'product_fournisseur_price').
")";
561 $sqlsearchpackage .=
" AND fk_product = ".((int) $objp->fk_product);
562 $sqlsearchpackage .=
" AND ref_fourn = '".$this->db->escape($objp->ref_supplier).
"'";
563 $sqlsearchpackage .=
" AND quantity <= ".((float) $objp->qty);
564 $sqlsearchpackage .=
" AND (packaging IS NULL OR packaging = 0 OR packaging <= ".((float) $objp->qty).
")";
565 $sqlsearchpackage .=
" AND fk_soc = ".((int) $this->socid);
566 $sqlsearchpackage .=
" ORDER BY packaging ASC";
567 $sqlsearchpackage .=
" LIMIT 1";
569 $resqlsearchpackage = $this->
db->query($sqlsearchpackage);
570 if ($resqlsearchpackage) {
571 $objsearchpackage = $this->
db->fetch_object($resqlsearchpackage);
572 if ($objsearchpackage) {
573 $line->fk_fournprice = $objsearchpackage->rowid;
574 $line->packaging = $objsearchpackage->packaging;
577 $this->error = $this->
db->lasterror();
582 $line->date_start = $this->
db->jdate($objp->date_start);
583 $line->date_end = $this->
db->jdate($objp->date_end);
584 $line->fk_unit = $objp->fk_unit;
587 $line->fk_multicurrency = $objp->fk_multicurrency;
588 $line->multicurrency_code = $objp->multicurrency_code;
589 $line->multicurrency_subprice = $objp->multicurrency_subprice;
590 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
591 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
592 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
594 $line->special_code = $objp->special_code;
595 $line->fk_parent_line = $objp->fk_parent_line;
597 $line->rang = $objp->rang;
601 $line->fetch_optionals();
603 $this->lines[$i] = $line;
607 $this->
db->free($result);
611 $this->error = $this->
db->error().
" sql=".$sql;
624 public function valid($user, $idwarehouse = 0, $notrigger = 0)
626 global $langs, $conf;
627 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
633 if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && (!empty($user->rights->fournisseur->commande->creer) || !empty($user->rights->supplier_order->creer)))
634 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->supplier_order_advance->validate))) {
639 $soc->fetch($this->fourn_id);
642 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
649 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"commande_fournisseur";
650 $sql .=
" SET ref='".$this->db->escape($num).
"',";
651 $sql .=
" fk_statut = ".self::STATUS_VALIDATED.
",";
652 $sql .=
" date_valid='".$this->db->idate(
dol_now()).
"',";
653 $sql .=
" fk_user_valid = ".((int) $user->id);
654 $sql .=
" WHERE rowid = ".((int) $this->
id);
655 $sql .=
" AND fk_statut = ".self::STATUS_DRAFT;
663 if (!$error && !$notrigger) {
665 $result = $this->
call_trigger(
'ORDER_SUPPLIER_VALIDATE', $user);
673 $this->oldref = $this->ref;
676 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
678 $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).
"'";
679 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'fournisseur/commande/".$this->
db->escape($this->
ref).
"' and entity = ".((int) $conf->entity);
682 $error++; $this->error = $this->
db->lasterror();
688 $dirsource = $conf->fournisseur->commande->dir_output.
'/'.$oldref;
689 $dirdest = $conf->fournisseur->commande->dir_output.
'/'.$newref;
690 if (!$error && file_exists($dirsource)) {
691 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
693 if (@rename($dirsource, $dirdest)) {
696 $listoffiles =
dol_dir_list($conf->fournisseur->commande->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
697 foreach ($listoffiles as $fileentry) {
698 $dirsource = $fileentry[
'name'];
699 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
700 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
701 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
702 @rename($dirsource, $dirdest);
711 $this->statut = self::STATUS_VALIDATED;
719 $this->
db->rollback();
723 $this->error =
'NotAuthorized';
724 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
737 return $this->
LibStatut($this->statut, $mode, $this->billed);
749 public function LibStatut($status, $mode = 0, $billed = 0)
752 global $conf, $langs, $hookmanager;
754 if (empty($this->statuts) || empty($this->statutshort)) {
755 $langs->load(
'orders');
757 $this->statuts[0] =
'StatusSupplierOrderDraft';
758 $this->statuts[1] =
'StatusSupplierOrderValidated';
759 $this->statuts[2] =
'StatusSupplierOrderApproved';
760 if (empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) {
761 $this->statuts[3] =
'StatusSupplierOrderOnProcess';
763 $this->statuts[3] =
'StatusSupplierOrderOnProcessWithValidation';
765 $this->statuts[4] =
'StatusSupplierOrderReceivedPartially';
766 $this->statuts[5] =
'StatusSupplierOrderReceivedAll';
767 $this->statuts[6] =
'StatusSupplierOrderCanceled';
768 $this->statuts[7] =
'StatusSupplierOrderCanceled';
769 $this->statuts[9] =
'StatusSupplierOrderRefused';
772 $this->statutshort[0] =
'StatusSupplierOrderDraftShort';
773 $this->statutshort[1] =
'StatusSupplierOrderValidatedShort';
774 $this->statutshort[2] =
'StatusSupplierOrderApprovedShort';
775 $this->statutshort[3] =
'StatusSupplierOrderOnProcessShort';
776 $this->statutshort[4] =
'StatusSupplierOrderReceivedPartiallyShort';
777 $this->statutshort[5] =
'StatusSupplierOrderReceivedAllShort';
778 $this->statutshort[6] =
'StatusSupplierOrderCanceledShort';
779 $this->statutshort[7] =
'StatusSupplierOrderCanceledShort';
780 $this->statutshort[9] =
'StatusSupplierOrderRefusedShort';
783 $statustrans = array(
795 $statusClass =
'status0';
796 if (!empty($statustrans[$status])) {
797 $statusClass = $statustrans[$status];
802 $billedtext =
' - '.$langs->trans(
"Billed");
804 if ($status == 5 && $billed) {
805 $statusClass =
'status6';
808 $statusLong = $langs->transnoentitiesnoconv($this->statuts[$status]).$billedtext;
809 $statusShort = $langs->transnoentitiesnoconv($this->statutshort[$status]);
811 $parameters = array(
'status' => $status,
'mode' => $mode,
'billed' => $billed);
812 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
814 return $hookmanager->resPrint;
817 return dolGetStatus($statusLong, $statusShort,
'', $statusClass, $mode);
831 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = 0)
833 global $langs, $conf, $user, $hookmanager;
839 if ($user->rights->fournisseur->commande->lire) {
840 $label =
'<u class="paddingrightonly">'.$langs->trans(
"SupplierOrder").
'</u>';
841 if (isset($this->statut)) {
842 $label .=
' '.$this->getLibStatut(5);
844 if (!empty($this->
ref)) {
845 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
847 if (!empty($this->ref_supplier)) {
848 $label .=
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.$this->ref_supplier;
850 if (!empty($this->total_ht)) {
851 $label .=
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
853 if (!empty($this->total_tva)) {
854 $label .=
'<br><b>'.$langs->trans(
'VAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
856 if (!empty($this->total_ttc)) {
857 $label .=
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
859 if (!empty($this->date)) {
860 $label .=
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->date,
'day');
862 if (!empty($this->delivery_date)) {
863 $label .=
'<br><b>'.$langs->trans(
'DeliveryDate').
':</b> '.
dol_print_date($this->delivery_date,
'dayhour');
868 $url = DOL_URL_ROOT.
'/fourn/commande/card.php?id='.$this->id;
870 if ($option !==
'nolink') {
872 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
873 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
874 $add_save_lastsearch_values = 1;
876 if ($add_save_lastsearch_values) {
877 $url .=
'&save_lastsearch_values=1';
882 if (empty($notooltip)) {
883 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
884 $label = $langs->trans(
"ShowOrder");
885 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
887 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
888 $linkclose .=
' class="classfortooltip"';
891 $linkstart =
'<a href="'.$url.
'"';
892 $linkstart .= $linkclose.
'>';
895 $result .= $linkstart;
897 $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
899 if ($withpicto != 2) {
900 $result .= $this->ref;
904 if ($addlinktonotes) {
905 $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
908 $result .=
' <span class="note inline-block">';
909 $result .=
'<a href="'.DOL_URL_ROOT.
'/fourn/commande/note.php?id='.$this->
id.
'" class="classfortooltip" title="'.
dol_escape_htmltag($notetoshow).
'">';
914 $result .=
'</span>';
919 $hookmanager->initHooks(array($this->element .
'dao'));
920 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
921 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
923 $result = $hookmanager->resPrint;
925 $result .= $hookmanager->resPrint;
940 global $db, $langs, $conf;
941 $langs->load(
"orders");
943 if (!empty($conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER)) {
946 $file = $conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER.
'.php';
947 $classname = $conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER;
950 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
952 foreach ($dirmodels as $reldir) {
953 $dir =
dol_buildpath($reldir.
"core/modules/supplier_order/");
956 $mybool |= @include_once $dir.$file;
959 if ($mybool ===
false) {
964 $obj =
new $classname();
965 $numref = $obj->getNextValue($soc, $this);
970 $this->error = $obj->error;
974 $this->error =
"Error_COMMANDE_SUPPLIER_ADDON_NotDefined";
994 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur SET billed = 1';
995 $sql .=
" WHERE rowid = ".((int) $this->
id).
' AND fk_statut > '.self::STATUS_DRAFT;
997 if ($this->
db->query($sql)) {
1000 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CLASSIFY_BILLED', $user);
1010 $this->
db->commit();
1013 $this->
db->rollback();
1019 $this->
db->rollback();
1032 public function approve($user, $idwarehouse = 0, $secondlevel = 0)
1034 global $langs, $conf;
1035 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1041 if ($user->rights->fournisseur->commande->approuver) {
1048 $soc->fetch($this->fourn_id);
1051 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
1059 $movetoapprovestatus =
true;
1062 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur";
1063 $sql .=
" SET ref='".$this->db->escape($num).
"',";
1064 if (empty($secondlevel)) {
1065 $sql .=
" date_approve='".$this->db->idate($now).
"',";
1066 $sql .=
" fk_user_approve = ".$user->id;
1067 if (!empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) && $this->total_ht >= $conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) {
1068 if (empty($this->user_approve_id2)) {
1069 $movetoapprovestatus =
false;
1070 $comment =
' (first level)';
1075 $sql .=
" date_approve2='".$this->db->idate($now).
"',";
1076 $sql .=
" fk_user_approve2 = ".((int) $user->id);
1077 if (empty($this->user_approve_id)) {
1078 $movetoapprovestatus =
false;
1080 $comment =
' (second level)';
1083 if ($movetoapprovestatus) {
1084 $sql .=
", fk_statut = ".self::STATUS_ACCEPTED;
1086 $sql .=
", fk_statut = ".self::STATUS_VALIDATED;
1088 $sql .=
" WHERE rowid = ".((int) $this->
id);
1089 $sql .=
" AND fk_statut = ".self::STATUS_VALIDATED;
1091 if ($this->
db->query($sql)) {
1092 if (!empty($conf->global->SUPPLIER_ORDER_AUTOADD_USER_CONTACT)) {
1093 $result = $this->
add_contact($user->id,
'SALESREPFOLL',
'internal', 1);
1094 if ($result < 0 && $result != -2) {
1100 if (!$error && $movetoapprovestatus && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER)) {
1101 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1102 $langs->load(
"agenda");
1104 $cpt = count($this->lines);
1105 for ($i = 0; $i < $cpt; $i++) {
1107 if ($this->lines[$i]->fk_product > 0) {
1108 $this->line = $this->lines[$i];
1110 $mouvP->origin = &$this;
1111 $mouvP->setOrigin($this->element, $this->
id);
1113 $up_ht_disc = $this->lines[$i]->subprice;
1114 if (!empty($this->lines[$i]->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) {
1115 $up_ht_disc =
price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100,
'MU');
1117 $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans(
"OrderApprovedInDolibarr", $this->ref));
1128 $result = $this->
call_trigger(
'ORDER_SUPPLIER_APPROVE', $user);
1136 $this->
ref = $this->newref;
1138 if ($movetoapprovestatus) {
1139 $this->statut = self::STATUS_ACCEPTED;
1141 $this->statut = self::STATUS_VALIDATED;
1143 if (empty($secondlevel)) {
1144 $this->date_approve = $now;
1145 $this->user_approve_id = $user->id;
1148 $this->date_approve2 = $now;
1149 $this->user_approve_id2 = $user->id;
1152 $this->
db->commit();
1155 $this->
db->rollback();
1159 $this->
db->rollback();
1160 $this->error = $this->
db->lasterror();
1164 dol_syslog(get_class($this).
"::approve Not Authorized", LOG_ERR);
1177 global $conf, $langs;
1183 if ($user->rights->fournisseur->commande->approuver) {
1186 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur SET fk_statut = ".self::STATUS_REFUSED;
1187 $sql .=
" WHERE rowid = ".((int) $this->
id);
1189 if ($this->
db->query($sql)) {
1194 $result = $this->
call_trigger(
'ORDER_SUPPLIER_REFUSE', $user);
1197 $this->
db->rollback();
1199 $this->
db->commit();
1204 $this->
db->rollback();
1205 $this->error = $this->
db->lasterror();
1206 dol_syslog(get_class($this).
"::refuse Error -1");
1210 dol_syslog(get_class($this).
"::refuse Not Authorized");
1224 public function Cancel($user, $idwarehouse = -1)
1227 global $langs, $conf;
1233 if ($user->rights->fournisseur->commande->commander) {
1234 $statut = self::STATUS_CANCELED;
1238 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur SET fk_statut = ".((int) $statut);
1239 $sql .=
" WHERE rowid = ".((int) $this->
id);
1240 dol_syslog(get_class($this).
"::cancel", LOG_DEBUG);
1241 if ($this->
db->query($sql)) {
1245 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CANCEL', $user);
1252 $this->
db->commit();
1255 $this->
db->rollback();
1259 $this->
db->rollback();
1260 $this->error = $this->
db->lasterror();
1261 dol_syslog(get_class($this).
"::cancel ".$this->error);
1265 dol_syslog(get_class($this).
"::cancel Not Authorized");
1279 public function commande($user, $date, $methode, $comment =
'')
1284 if ($user->rights->fournisseur->commande->commander) {
1287 $newnoteprivate = $this->note_private;
1289 $newnoteprivate =
dol_concatdesc($newnoteprivate, $langs->trans(
"Comment").
': '.$comment);
1292 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur";
1293 $sql .=
" SET fk_statut=".self::STATUS_ORDERSENT.
", fk_input_method=".$methode.
", date_commande='".$this->
db->idate($date).
"', ";
1294 $sql .=
" note_private='".$this->db->escape($newnoteprivate).
"'";
1295 $sql .=
" WHERE rowid=".((int) $this->
id);
1297 dol_syslog(get_class($this).
"::commande", LOG_DEBUG);
1298 if ($this->
db->query($sql)) {
1299 $this->statut = self::STATUS_ORDERSENT;
1300 $this->methode_commande_id = $methode;
1301 $this->date_commande = $date;
1302 $this->context = array(
'comments' => $comment);
1305 $result = $this->
call_trigger(
'ORDER_SUPPLIER_SUBMIT', $user);
1312 $this->error = $this->
db->lasterror();
1313 $this->errors[] = $this->
db->lasterror();
1317 $this->
db->commit();
1319 $this->
db->rollback();
1323 $this->error = $langs->trans(
'NotAuthorized');
1324 $this->errors[] = $langs->trans(
'NotAuthorized');
1325 dol_syslog(get_class($this).
"::commande User not Authorized", LOG_WARNING);
1328 return ($error ? -1 : 1);
1338 public function create($user, $notrigger = 0)
1340 global $langs, $conf, $hookmanager;
1348 $date = ($this->date_commande ? $this->date_commande : $this->date);
1352 $delivery_date = empty($this->delivery_date) ? $this->date_livraison : $this->delivery_date;
1355 if (empty($this->source)) {
1360 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
1365 if (empty($this->fk_multicurrency)) {
1366 $this->multicurrency_code = $conf->currency;
1367 $this->fk_multicurrency = 0;
1368 $this->multicurrency_tx = 1;
1372 $this->brouillon = 1;
1374 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"commande_fournisseur (";
1376 $sql .=
", ref_supplier";
1377 $sql .=
", note_private";
1378 $sql .=
", note_public";
1381 $sql .=
", fk_projet";
1382 $sql .=
", date_creation";
1383 $sql .=
", date_livraison";
1384 $sql .=
", fk_user_author";
1385 $sql .=
", fk_statut";
1387 $sql .=
", model_pdf";
1388 $sql .=
", fk_mode_reglement";
1389 $sql .=
", fk_cond_reglement";
1390 $sql .=
", fk_account";
1391 $sql .=
", fk_incoterms, location_incoterms";
1392 $sql .=
", fk_multicurrency";
1393 $sql .=
", multicurrency_code";
1394 $sql .=
", multicurrency_tx";
1396 $sql .=
" VALUES (";
1398 $sql .=
", '".$this->db->escape($this->ref_supplier).
"'";
1399 $sql .=
", '".$this->db->escape($this->note_private).
"'";
1400 $sql .=
", '".$this->db->escape($this->note_public).
"'";
1401 $sql .=
", ".((int) $conf->entity);
1402 $sql .=
", ".((int) $this->socid);
1403 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
1404 $sql .=
", '".$this->db->idate($date).
"'";
1405 $sql .=
", ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
"null");
1406 $sql .=
", ".((int) $user->id);
1407 $sql .=
", ".self::STATUS_DRAFT;
1408 $sql .=
", ".((int) $this->source);
1409 $sql .=
", '".$this->db->escape($conf->global->COMMANDE_SUPPLIER_ADDON_PDF).
"'";
1410 $sql .=
", ".($this->mode_reglement_id > 0 ? $this->mode_reglement_id :
'null');
1411 $sql .=
", ".($this->cond_reglement_id > 0 ? $this->cond_reglement_id :
'null');
1412 $sql .=
", ".($this->fk_account > 0 ? $this->fk_account :
'NULL');
1413 $sql .=
", ".(int) $this->fk_incoterms;
1414 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
1415 $sql .=
", ".(int) $this->fk_multicurrency;
1416 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1417 $sql .=
", ".(double) $this->multicurrency_tx;
1420 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1421 if ($this->
db->query($sql)) {
1422 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"commande_fournisseur");
1425 $num = count($this->lines);
1428 for ($i = 0; $i < $num; $i++) {
1429 $line = $this->lines[$i];
1430 if (!is_object($line)) {
1431 $line = (object) $line;
1435 $this->special_code = $line->special_code;
1443 $line->localtax1_tx,
1444 $line->localtax2_tx,
1448 $line->remise_percent,
1451 $line->product_type,
1456 $line->array_options,
1460 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
1461 $this->
db->rollback();
1466 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur";
1467 $sql .=
" SET ref='(PROV".$this->id.
")'";
1468 $sql .=
" WHERE rowid=".((int) $this->
id);
1469 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1470 if ($this->
db->query($sql)) {
1473 $this->
ref =
"(PROV".$this->id.
")";
1475 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
1476 $this->linked_objects = $this->linkedObjectsIds;
1480 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
1481 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
1482 if (is_array($tmp_origin_id)) {
1483 foreach ($tmp_origin_id as $origin_id) {
1492 $origin_id = $tmp_origin_id;
1510 if (!$error && !$notrigger) {
1512 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CREATE', $user);
1514 $this->
db->rollback();
1520 $this->
db->commit();
1523 $this->error = $this->
db->lasterror();
1524 $this->
db->rollback();
1529 $this->error = $this->
db->lasterror();
1530 $this->
db->rollback();
1549 if (isset($this->
ref)) {
1550 $this->
ref = trim($this->
ref);
1552 if (isset($this->ref_supplier)) {
1553 $this->ref_supplier = trim($this->ref_supplier);
1555 if (isset($this->note_private)) {
1556 $this->note_private = trim($this->note_private);
1558 if (isset($this->note_public)) {
1559 $this->note_public = trim($this->note_public);
1561 if (isset($this->model_pdf)) {
1562 $this->model_pdf = trim($this->model_pdf);
1564 if (isset($this->import_key)) {
1565 $this->import_key = trim($this->import_key);
1569 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
1571 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1572 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
1573 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1574 $sql .=
" fk_soc=".(isset($this->socid) ? $this->socid :
"null").
",";
1575 $sql .=
" date_commande=".(strval($this->date_commande) !=
'' ?
"'".$this->db->idate($this->date_commande).
"'" :
'null').
",";
1576 $sql .=
" date_valid=".(strval($this->date_validation) !=
'' ?
"'".$this->db->idate($this->date_validation).
"'" :
'null').
",";
1577 $sql .=
" total_tva=".(isset($this->total_tva) ? $this->total_tva :
"null").
",";
1578 $sql .=
" localtax1=".(isset($this->total_localtax1) ? $this->total_localtax1 :
"null").
",";
1579 $sql .=
" localtax2=".(isset($this->total_localtax2) ? $this->total_localtax2 :
"null").
",";
1580 $sql .=
" total_ht=".(isset($this->total_ht) ? $this->total_ht :
"null").
",";
1581 $sql .=
" total_ttc=".(isset($this->total_ttc) ? $this->total_ttc :
"null").
",";
1582 $sql .=
" fk_statut=".(isset($this->statut) ? $this->statut :
"null").
",";
1583 $sql .=
" fk_user_author=".(isset($this->user_author_id) ? $this->user_author_id :
"null").
",";
1584 $sql .=
" fk_user_valid=".(isset($this->user_valid) && $this->user_valid > 0 ? $this->user_valid :
"null").
",";
1585 $sql .=
" fk_projet=".(isset($this->fk_project) ? $this->fk_project :
"null").
",";
1586 $sql .=
" fk_cond_reglement=".(isset($this->cond_reglement_id) ? $this->cond_reglement_id :
"null").
",";
1587 $sql .=
" fk_mode_reglement=".(isset($this->mode_reglement_id) ? $this->mode_reglement_id :
"null").
",";
1588 $sql .=
" date_livraison=".(strval($this->delivery_date) !=
'' ?
"'".$this->db->idate($this->delivery_date).
"'" :
'null').
",";
1590 $sql .=
" fk_account=".($this->fk_account > 0 ? $this->fk_account :
"null").
",";
1592 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1593 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1594 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
1595 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null").
"";
1597 $sql .=
" WHERE rowid=".((int) $this->
id);
1601 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
1605 $this->errors[] =
"Error ".$this->db->lasterror();
1615 if (!$error && !$notrigger) {
1617 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
1626 foreach ($this->errors as $errmsg) {
1627 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1628 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1630 $this->
db->rollback();
1633 $this->
db->commit();
1648 global $conf, $user, $hookmanager;
1655 foreach ($this->lines as $line) {
1656 $line->fetch_optionals();
1660 $objFrom = clone $this;
1663 if (!empty($socid) && $socid != $this->socid) {
1666 if ($objsoc->fetch($socid) > 0) {
1667 $this->socid = $objsoc->id;
1668 $this->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1669 $this->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1670 $this->fk_project = 0;
1671 $this->fk_delivery_address = 0;
1678 $this->statut = self::STATUS_DRAFT;
1681 $this->user_author_id = $user->id;
1682 $this->user_valid = 0;
1683 $this->date_creation =
'';
1684 $this->date_validation =
'';
1685 $this->ref_supplier =
'';
1686 $this->user_approve_id =
'';
1687 $this->user_approve_id2 =
'';
1688 $this->date_approve =
'';
1689 $this->date_approve2 =
'';
1692 $this->context[
'createfromclone'] =
'createfromclone';
1693 $result = $this->
create($user, $notrigger);
1700 if (is_object($hookmanager)) {
1701 $parameters = array(
'objFrom'=>$objFrom);
1703 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1710 unset($this->context[
'createfromclone']);
1714 $this->
db->commit();
1717 $this->
db->rollback();
1750 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)
1752 global $langs, $mysoc, $conf;
1754 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");
1755 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1757 if ($this->statut == self::STATUS_DRAFT) {
1758 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1767 if (empty($txtva)) {
1773 if (empty($txlocaltax1)) {
1776 if (empty($txlocaltax2)) {
1779 if (empty($remise_percent)) {
1780 $remise_percent = 0;
1783 $remise_percent =
price2num($remise_percent);
1786 $pu_ht_devise =
price2num($pu_ht_devise);
1788 if (!preg_match(
'/\((.*)\)/', $txtva)) {
1793 if ($price_base_type ==
'HT') {
1798 $desc = trim($desc);
1801 if ($qty < 0 && !$fk_product) {
1802 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Product"));
1808 if ($date_start && $date_end && $date_start > $date_end) {
1809 $langs->load(
"errors");
1810 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
1817 $product_type = $type;
1820 if ($fk_product > 0) {
1821 if (!empty($conf->global->SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY)) {
1823 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);
1825 if ($prod->fetch($fk_product) > 0) {
1826 $product_type = $prod->type;
1827 $label = $prod->label;
1831 $result = $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', (isset($this->fk_soc) ? $this->fk_soc : $this->socid));
1835 if ($result > 0 && ($origin ==
'commande' || $pu ===
'')) {
1836 $pu = $prod->fourn_pu;
1837 $ref_supplier = $prod->ref_supplier;
1839 if ($remise_percent == 0 && $prod->remise_percent != 0) {
1840 $remise_percent = $prod->remise_percent;
1844 $langs->load(
"errors");
1845 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
1846 $this->
db->rollback();
1847 dol_syslog(get_class($this).
"::addline we did not found supplier price, so we can't guess unit price");
1852 if ($result == -1) {
1853 $langs->load(
"errors");
1854 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
1855 $this->
db->rollback();
1856 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_DEBUG);
1860 $this->error = $prod->error;
1861 $this->
db->rollback();
1862 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_ERR);
1866 $this->error = $prod->error;
1867 $this->
db->rollback();
1873 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
1875 $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', ($this->fk_soc ? $this->fk_soc : $this->socid));
1877 if ($qty < $prod->packaging) {
1878 $qty = $prod->packaging;
1880 if (!empty($prod->packaging) && ($qty % $prod->packaging) > 0) {
1881 $coeff = intval($qty / $prod->packaging) + 1;
1882 $qty = $prod->packaging * $coeff;
1883 setEventMessage($langs->trans(
'QtyRecalculatedWithPackaging'),
'mesgs');
1889 if (!empty($conf->multicurrency->enabled) && $pu_ht_devise > 0) {
1897 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
1898 $vat_src_code = $reg[1];
1899 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
1907 $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);
1909 $total_ht = $tabprice[0];
1910 $total_tva = $tabprice[1];
1911 $total_ttc = $tabprice[2];
1912 $total_localtax1 = $tabprice[9];
1913 $total_localtax2 = $tabprice[10];
1914 $pu = $pu_ht = $tabprice[3];
1917 $multicurrency_total_ht = $tabprice[16];
1918 $multicurrency_total_tva = $tabprice[17];
1919 $multicurrency_total_ttc = $tabprice[18];
1920 $pu_ht_devise = $tabprice[19];
1922 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
1923 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
1927 $rang = $rangmax + 1;
1933 $this->line->context = $this->context;
1935 $this->line->fk_commande = $this->id;
1936 $this->line->label = $label;
1937 $this->line->ref_fourn = $ref_supplier;
1938 $this->line->ref_supplier = $ref_supplier;
1939 $this->line->desc = $desc;
1940 $this->line->qty = $qty;
1941 $this->line->tva_tx = $txtva;
1942 $this->line->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0);
1943 $this->line->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0);
1944 $this->line->localtax1_type = $localtax1_type;
1945 $this->line->localtax2_type = $localtax2_type;
1946 $this->line->fk_product = $fk_product;
1947 $this->line->product_type = $product_type;
1948 $this->line->remise_percent = $remise_percent;
1949 $this->line->subprice = $pu_ht;
1950 $this->line->rang = $rang;
1951 $this->line->info_bits = $info_bits;
1953 $this->line->vat_src_code = $vat_src_code;
1954 $this->line->total_ht = $total_ht;
1955 $this->line->total_tva = $total_tva;
1956 $this->line->total_localtax1 = $total_localtax1;
1957 $this->line->total_localtax2 = $total_localtax2;
1958 $this->line->total_ttc = $total_ttc;
1959 $this->line->product_type = $type;
1960 $this->line->special_code = $this->special_code;
1961 $this->line->origin = $origin;
1962 $this->line->origin_id = $origin_id;
1963 $this->line->fk_unit = $fk_unit;
1965 $this->line->date_start = $date_start;
1966 $this->line->date_end = $date_end;
1969 $this->line->fk_multicurrency = $this->fk_multicurrency;
1970 $this->line->multicurrency_code = $this->multicurrency_code;
1971 $this->line->multicurrency_subprice = $pu_ht_devise;
1972 $this->line->multicurrency_total_ht = $multicurrency_total_ht;
1973 $this->line->multicurrency_total_tva = $multicurrency_total_tva;
1974 $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
1976 $this->line->subprice = $pu_ht;
1977 $this->line->price = $this->line->subprice;
1979 $this->line->remise_percent = $remise_percent;
1981 if (is_array($array_options) && count($array_options) > 0) {
1982 $this->line->array_options = $array_options;
1985 $result = $this->line->insert($notrigger);
1988 if (!empty($fk_parent_line)) {
1990 } elseif ($rang > 0 && $rang <= count($this->lines)) {
1991 $linecount = count($this->lines);
1992 for ($ii = $rang; $ii <= $linecount; $ii++) {
1998 $result = $this->
update_price(1,
'auto', 0, $this->thirdparty);
2000 $this->
db->commit();
2001 return $this->line->id;
2003 $this->
db->rollback();
2007 $this->error = $this->line->error;
2008 $this->errors = $this->line->errors;
2009 dol_syslog(get_class($this).
"::addline error=".$this->error, LOG_ERR);
2010 $this->
db->rollback();
2033 public function dispatchProduct($user, $product, $qty, $entrepot, $price = 0, $comment =
'', $eatby =
'', $sellby =
'', $batch =
'', $fk_commandefourndet = 0, $notrigger = 0)
2035 global $conf, $langs;
2038 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
2041 if ($entrepot <= 0) {
2042 $this->error =
'ErrorBadValueForParameterWarehouse';
2046 $this->error =
'ErrorBadValueForParameterQty';
2050 $dispatchstatus = 1;
2051 if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) {
2052 $dispatchstatus = 0;
2059 if (($this->statut == self::STATUS_ORDERSENT || $this->statut == self::STATUS_RECEIVED_PARTIALLY || $this->statut == self::STATUS_RECEIVED_COMPLETELY)) {
2062 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch";
2063 $sql .=
" (fk_commande, fk_product, qty, fk_entrepot, fk_user, datec, fk_commandefourndet, status, comment, eatby, sellby, batch) VALUES";
2064 $sql .=
" ('".$this->id.
"','".$product.
"','".$qty.
"',".($entrepot > 0 ?
"'".$entrepot.
"'" :
"null").
",'".$user->id.
"','".$this->db->idate($now).
"','".$fk_commandefourndet.
"', ".$dispatchstatus.
", '".$this->
db->escape($comment).
"', ";
2065 $sql .= ($eatby ?
"'".$this->db->idate($eatby).
"'" :
"null").
", ".($sellby ?
"'".$this->
db->idate($sellby).
"'" :
"null").
", ".($batch ?
"'".$this->
db->escape($batch).
"'" :
"null");
2068 dol_syslog(get_class($this).
"::dispatchProduct", LOG_DEBUG);
2072 global $conf, $langs, $user;
2074 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_DISPATCH', $user);
2081 $this->error = $this->
db->lasterror();
2086 if (!$error && $entrepot > 0 && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) {
2090 $mouv->origin = &$this;
2091 $mouv->setOrigin($this->element, $this->
id);
2094 if (!empty($conf->global->SUPPLIER_ORDER_ALLOW_NEGATIVE_QTY_FOR_SUPPLIER_ORDER_RETURN) && $qty < 0) {
2095 $result = $mouv->livraison($user, $product, $entrepot, $qty*(-1), $price, $comment, $now, $eatby, $sellby, $batch, 0, $inventorycode);
2097 $result = $mouv->reception($user, $product, $entrepot, $qty, $price, $comment, $eatby, $sellby, $batch,
'', 0, $inventorycode);
2101 $this->error = $mouv->error;
2102 $this->errors = $mouv->errors;
2103 dol_syslog(get_class($this).
"::dispatchProduct ".$this->error.
" ".join(
',', $this->errors), LOG_ERR);
2110 $this->
db->commit();
2113 $this->
db->rollback();
2117 $this->error =
'BadStatusForObject';
2131 if ($this->statut == 0) {
2134 if ($line->fetch($idline) <= 0) {
2138 if ($line->delete($notrigger) > 0) {
2142 $this->error = $line->error;
2143 $this->errors = $line->errors;
2158 public function delete(
User $user, $notrigger = 0)
2160 global $langs, $conf;
2161 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
2167 if (empty($notrigger)) {
2169 $result = $this->
call_trigger(
'ORDER_SUPPLIER_DELETE', $user);
2171 $this->errors[] =
'ErrorWhenRunningTrigger';
2172 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2173 $this->
db->rollback();
2181 if (!empty($this->linkedObjects) && array_key_exists(
'reception', $this->linkedObjects)) {
2182 foreach ($this->linkedObjects[
'reception'] as $element) {
2183 if ($element->statut >= 0) {
2184 $this->errors[] = $langs->trans(
'ReceptionExist');
2191 $main = MAIN_DB_PREFIX.
'commande_fournisseurdet';
2192 $ef = $main.
"_extrafields";
2193 $sql =
"DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_commande = ".((int) $this->
id).
")";
2194 dol_syslog(get_class($this).
"::delete extrafields lines", LOG_DEBUG);
2195 if (!$this->
db->query($sql)) {
2196 $this->error = $this->
db->lasterror();
2197 $this->errors[] = $this->
db->lasterror();
2201 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet WHERE fk_commande =".((int) $this->
id);
2202 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2203 if (!$this->
db->query($sql)) {
2204 $this->error = $this->
db->lasterror();
2205 $this->errors[] = $this->
db->lasterror();
2209 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"commande_fournisseur WHERE rowid =".((int) $this->
id);
2210 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
2211 if (
$resql = $this->
db->query($sql)) {
2212 if ($this->
db->affected_rows(
$resql) < 1) {
2213 $this->error = $this->
db->lasterror();
2214 $this->errors[] = $this->
db->lasterror();
2218 $this->error = $this->
db->lasterror();
2219 $this->errors[] = $this->
db->lasterror();
2227 $this->error =
'FailToDeleteExtraFields';
2228 $this->errors[] =
'FailToDeleteExtraFields';
2230 dol_syslog(get_class($this).
"::delete error -4 ".$this->error, LOG_ERR);
2237 $this->error =
'FailToDeleteObjectLinked';
2238 $this->errors[] =
'FailToDeleteObjectLinked';
2248 if ($conf->fournisseur->commande->dir_output) {
2249 $dir = $conf->fournisseur->commande->dir_output.
"/".$ref;
2250 $file = $dir.
"/".$ref.
".pdf";
2251 if (file_exists($file)) {
2253 $this->error =
'ErrorFailToDeleteFile';
2254 $this->errors[] =
'ErrorFailToDeleteFile';
2258 if (file_exists($dir)) {
2261 $this->error =
'ErrorFailToDeleteDir';
2262 $this->errors[] =
'ErrorFailToDeleteDir';
2270 dol_syslog(get_class($this).
"::delete $this->id by $user->id", LOG_DEBUG);
2271 $this->
db->commit();
2274 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2275 $this->
db->rollback();
2289 $sql =
"SELECT rowid, libelle";
2290 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_input_method";
2291 $sql .=
" WHERE active = 1";
2296 $num = $this->
db->num_rows(
$resql);
2297 $this->methodes_commande = array();
2299 $row = $this->
db->fetch_row(
$resql);
2301 $this->methodes_commande[$row[0]] = $row[1];
2324 $sql =
"SELECT p.ref, p.label,";
2325 $sql .=
" e.rowid as warehouse_id, e.ref as entrepot,";
2326 $sql .=
" cfd.rowid as dispatchedlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status";
2327 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product as p,";
2328 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as cfd";
2329 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"entrepot as e ON cfd.fk_entrepot = e.rowid";
2330 $sql .=
" WHERE cfd.fk_commande = ".((int) $this->
id);
2331 $sql .=
" AND cfd.fk_product = p.rowid";
2333 $sql .=
" AND cfd.status = ".((int) $status);
2335 $sql .=
" ORDER BY cfd.rowid ASC";
2339 $num = $this->
db->num_rows(
$resql);
2343 $objp = $this->
db->fetch_object(
$resql);
2346 'id' => $objp->dispatchedlineid,
2347 'productid' => $objp->fk_product,
2348 'warehouseid' => $objp->warehouse_id,
2349 'qty' => $objp->qty,
2356 dol_print_error($this->
db,
'Failed to execute request to get dispatched lines');
2375 global $conf, $langs;
2382 $usercanreceive = 0;
2383 if (empty($conf->reception->enabled)) {
2384 $usercanreceive = $user->rights->fournisseur->commande->receptionner;
2386 $usercanreceive = $user->rights->reception->creer;
2389 if ($usercanreceive) {
2391 if ($type ==
'par') {
2392 $statut = self::STATUS_RECEIVED_PARTIALLY;
2393 } elseif ($type ==
'tot') {
2394 $statut = self::STATUS_RECEIVED_COMPLETELY;
2395 } elseif ($type ==
'nev') {
2396 $statut = self::STATUS_CANCELED_AFTER_ORDER;
2397 } elseif ($type ==
'can') {
2398 $statut = self::STATUS_CANCELED_AFTER_ORDER;
2401 dol_syslog(get_class($this).
"::Livraison Error -2", LOG_ERR);
2406 if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) {
2408 if (!$error && ($type ==
'tot')) {
2410 if (count($dispatchedlinearray) > 0) {
2413 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove';
2414 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove', LOG_DEBUG);
2417 if (!$error && !empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS_NEED_APPROVE) && ($type ==
'tot')) {
2419 if (count($dispatchedlinearray) > 0) {
2422 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied';
2423 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied', LOG_DEBUG);
2430 if (empty($error)) {
2433 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur";
2434 $sql .=
" SET fk_statut = ".((int) $statut);
2435 $sql .=
" WHERE rowid = ".((int) $this->
id);
2436 $sql .=
" AND fk_statut IN (".self::STATUS_ORDERSENT.
",".self::STATUS_RECEIVED_PARTIALLY.
")";
2438 dol_syslog(get_class($this).
"::Livraison", LOG_DEBUG);
2442 $old_statut = $this->statut;
2443 $this->statut = $statut;
2444 $this->actionmsg2 = $comment;
2447 $result_trigger = $this->
call_trigger(
'ORDER_SUPPLIER_RECEIVE', $user);
2448 if ($result_trigger < 0) {
2453 if (empty($error)) {
2454 $this->
db->commit();
2456 $this->statut = $old_statut;
2457 $this->
db->rollback();
2458 $this->error = $this->
db->lasterror();
2462 $this->
db->rollback();
2463 $this->error = $this->
db->lasterror();
2468 $this->error = $langs->trans(
'NotAuthorized');
2469 $this->errors[] = $langs->trans(
'NotAuthorized');
2470 dol_syslog(get_class($this).
"::Livraison Not Authorized");
2502 if ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer) {
2507 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur";
2508 $sql .=
" SET date_livraison = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2509 $sql .=
" WHERE rowid = ".((int) $this->
id);
2514 $this->errors[] = $this->
db->error();
2519 $this->oldcopy = clone $this;
2520 $this->date_livraison = $delivery_date;
2521 $this->delivery_date = $delivery_date;
2524 if (!$notrigger && empty($error)) {
2526 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2534 $this->
db->commit();
2537 foreach ($this->errors as $errmsg) {
2538 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2539 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2541 $this->
db->rollback();
2561 if ($user->rights->fournisseur->commande->creer || $user->rights->supplier_order->creer) {
2566 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur";
2567 $sql .=
" SET fk_projet = ".($id_projet > 0 ? (int) $id_projet :
'null');
2568 $sql .=
" WHERE rowid = ".((int) $this->
id);
2573 $this->errors[] = $this->
db->error();
2578 $this->oldcopy = clone $this;
2579 $this->fk_projet = $id_projet;
2580 $this->fk_project = $id_projet;
2583 if (!$notrigger && empty($error)) {
2585 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2593 $this->
db->commit();
2596 foreach ($this->errors as $errmsg) {
2597 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2598 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2600 $this->
db->rollback();
2619 $comclient->fetch($comclientid);
2623 $this->lines = array();
2625 $num = count($comclient->lines);
2626 for ($i = 0; $i < $num; $i++) {
2630 if ($prod->fetch($comclient->lines[$i]->fk_product) > 0) {
2631 $label = $prod->label;
2635 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"commande_fournisseurdet";
2636 $sql .=
" (fk_commande, label, description, fk_product, price, qty, tva_tx, localtax1_tx, localtax2_tx, remise_percent, subprice, remise, ref)";
2637 $sql .=
" VALUES (".((int) $idc).
", '".$this->
db->escape($label).
"', '".$this->
db->escape($comclient->lines[$i]->desc).
"'";
2638 $sql .=
",".$comclient->lines[$i]->fk_product.
", ".
price2num($comclient->lines[$i]->price,
'MU');
2639 $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);
2640 $sql .=
", '".price2num($comclient->lines[$i]->subprice,
'MT').
"','0', '".$this->
db->escape($ref).
"');";
2641 if ($this->
db->query($sql)) {
2658 global $conf, $langs;
2663 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur';
2664 $sql .=
" SET fk_statut = ".$status;
2665 $sql .=
" WHERE rowid = ".((int) $this->
id);
2667 dol_syslog(get_class($this).
"::setStatus", LOG_DEBUG);
2671 $triggerName = array();
2672 $triggerName[0] =
'DRAFT';
2673 $triggerName[1] =
'VALIDATED';
2674 $triggerName[2] =
'APPROVED';
2675 $triggerName[3] =
'ORDERED';
2676 $triggerName[4] =
'RECEIVED_PARTIALLY';
2677 $triggerName[5] =
'RECEIVED_COMPLETELY';
2678 $triggerName[6] =
'CANCELED';
2679 $triggerName[7] =
'CANCELED';
2680 $triggerName[9] =
'REFUSED';
2683 $result = $this->
call_trigger(
"ORDER_SUPPLIER_STATUS_".$triggerName[$status], $user);
2690 $this->error = $this->
db->lasterror();
2691 dol_syslog(get_class($this).
"::setStatus ".$this->error);
2695 $this->statut = $status;
2696 $this->
db->commit();
2699 $this->
db->rollback();
2727 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 =
'')
2729 global $mysoc, $conf, $langs;
2730 dol_syslog(get_class($this).
"::updateline $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $type, $fk_unit");
2731 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2735 if ($this->brouillon) {
2740 if (empty($info_bits)) {
2743 if (empty($txtva)) {
2746 if (empty($txlocaltax1)) {
2749 if (empty($txlocaltax2)) {
2752 if (empty($remise)) {
2755 if (empty($remise_percent)) {
2756 $remise_percent = 0;
2759 $remise_percent =
price2num($remise_percent);
2765 $pu_ht_devise =
price2num($pu_ht_devise);
2766 if (!preg_match(
'/\((.*)\)/', $txtva)) {
2776 if ($date_start && $date_end && $date_start > $date_end) {
2777 $langs->load(
"errors");
2778 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
2794 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
2795 $vat_src_code = $reg[1];
2796 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
2799 $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);
2800 $total_ht = $tabprice[0];
2801 $total_tva = $tabprice[1];
2802 $total_ttc = $tabprice[2];
2803 $total_localtax1 = $tabprice[9];
2804 $total_localtax2 = $tabprice[10];
2805 $pu_ht = $tabprice[3];
2806 $pu_tva = $tabprice[4];
2807 $pu_ttc = $tabprice[5];
2810 $multicurrency_total_ht = $tabprice[16];
2811 $multicurrency_total_tva = $tabprice[17];
2812 $multicurrency_total_ttc = $tabprice[18];
2813 $pu_ht_devise = $tabprice[19];
2815 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2816 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2820 $this->line->fetch($rowid);
2822 $oldline = clone $this->line;
2823 $this->line->oldline = $oldline;
2825 $this->line->context = $this->context;
2827 $this->line->fk_commande = $this->id;
2829 $this->line->desc = $desc;
2832 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
2833 if ($qty < $this->line->packaging) {
2834 $qty = $this->line->packaging;
2836 if (! empty($this->line->packaging) && ($qty % $this->line->packaging) > 0) {
2837 $coeff = intval($qty / $this->line->packaging) + 1;
2838 $qty = $this->line->packaging * $coeff;
2839 setEventMessage($langs->trans(
'QtyRecalculatedWithPackaging'),
'mesgs');
2844 $this->line->qty = $qty;
2845 $this->line->ref_supplier = $ref_supplier;
2847 $this->line->vat_src_code = $vat_src_code;
2848 $this->line->tva_tx = $txtva;
2849 $this->line->localtax1_tx = $txlocaltax1;
2850 $this->line->localtax2_tx = $txlocaltax2;
2851 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2852 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2853 $this->line->remise_percent = $remise_percent;
2854 $this->line->subprice = $pu_ht;
2855 $this->line->rang = $this->rang;
2856 $this->line->info_bits = $info_bits;
2857 $this->line->total_ht = $total_ht;
2858 $this->line->total_tva = $total_tva;
2859 $this->line->total_localtax1 = $total_localtax1;
2860 $this->line->total_localtax2 = $total_localtax2;
2861 $this->line->total_ttc = $total_ttc;
2862 $this->line->product_type = $type;
2863 $this->line->special_code = $this->special_code;
2864 $this->line->origin = $this->origin;
2865 $this->line->fk_unit = $fk_unit;
2867 $this->line->date_start = $date_start;
2868 $this->line->date_end = $date_end;
2871 $this->line->fk_multicurrency = $this->fk_multicurrency;
2872 $this->line->multicurrency_code = $this->multicurrency_code;
2873 $this->line->multicurrency_subprice = $pu_ht_devise;
2874 $this->line->multicurrency_total_ht = $multicurrency_total_ht;
2875 $this->line->multicurrency_total_tva = $multicurrency_total_tva;
2876 $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
2878 $this->line->subprice = $pu_ht;
2879 $this->line->price = $this->line->subprice;
2881 $this->line->remise_percent = $remise_percent;
2883 if (is_array($array_options) && count($array_options) > 0) {
2885 foreach ($array_options as $key => $value) {
2886 $this->line->array_options[$key] = $array_options[$key];
2890 $result = $this->line->update($notrigger);
2896 $this->
db->commit();
2899 $this->error = $this->
db->lasterror();
2900 $this->
db->rollback();
2904 $this->error =
"Order status makes operation forbidden";
2905 dol_syslog(get_class($this).
"::updateline ".$this->error, LOG_ERR);
2920 global $user, $langs, $conf;
2922 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
2924 dol_syslog(get_class($this).
"::initAsSpecimen");
2931 $sql =
"SELECT rowid";
2932 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
2933 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
2934 $sql .= $this->
db->order(
"rowid",
"ASC");
2935 $sql .= $this->
db->plimit(1);
2938 $obj = $this->
db->fetch_object(
$resql);
2939 $prodid = $obj->rowid;
2944 $this->
ref =
'SPECIMEN';
2945 $this->specimen = 1;
2948 $this->date_commande = $now;
2949 $this->date_lim_reglement = $this->date + 3600 * 24 * 30;
2950 $this->cond_reglement_code =
'RECEP';
2951 $this->mode_reglement_code =
'CHQ';
2953 $this->note_public =
'This is a comment (public)';
2954 $this->note_private =
'This is a comment (private)';
2956 $this->multicurrency_tx = 1;
2957 $this->multicurrency_code = $conf->currency;
2964 while ($xnbp < $nbp) {
2966 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
2968 $line->subprice = 100;
2970 $line->tva_tx = 19.6;
2971 $line->localtax1_tx = 0;
2972 $line->localtax2_tx = 0;
2974 $line->total_ht = 50;
2975 $line->total_ttc = 59.8;
2976 $line->total_tva = 9.8;
2977 $line->remise_percent = 50;
2979 $line->total_ht = 100;
2980 $line->total_ttc = 119.6;
2981 $line->total_tva = 19.6;
2982 $line->remise_percent = 00;
2984 $line->fk_product = $prodid;
2986 $this->lines[$xnbp] = $line;
2988 $this->total_ht += $line->total_ht;
2989 $this->total_tva += $line->total_tva;
2990 $this->total_ttc += $line->total_ttc;
3004 $sql =
'SELECT c.rowid, date_creation as datec, tms as datem, date_valid as date_validation, date_approve as datea, date_approve2 as datea2,';
3005 $sql .=
' fk_user_author, fk_user_modif, fk_user_valid, fk_user_approve, fk_user_approve2';
3006 $sql .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseur as c';
3007 $sql .=
' WHERE c.rowid = '.((int) $id);
3009 $result = $this->
db->query($sql);
3011 if ($this->
db->num_rows($result)) {
3012 $obj = $this->
db->fetch_object($result);
3013 $this->
id = $obj->rowid;
3014 if ($obj->fk_user_author) {
3015 $this->user_creation_id = $obj->fk_user_author;
3017 if ($obj->fk_user_valid) {
3018 $this->user_validation_id = $obj->fk_user_valid;
3020 if ($obj->fk_user_modif) {
3021 $this->user_modification_id = $obj->fk_user_modif;
3023 if ($obj->fk_user_approve) {
3024 $this->user_approve_id = $obj->fk_user_approve;
3026 if ($obj->fk_user_approve2) {
3027 $this->user_approve_id2 = $obj->fk_user_approve2;
3030 $this->date_creation = $this->
db->jdate($obj->datec);
3031 $this->date_modification = $this->
db->jdate($obj->datem);
3032 $this->date_approve = $this->
db->jdate($obj->datea);
3033 $this->date_approve2 = $this->
db->jdate($obj->datea2);
3034 $this->date_validation = $this->
db->jdate($obj->date_validation);
3036 $this->
db->free($result);
3051 global $conf, $user;
3053 $this->nb = array();
3056 $sql =
"SELECT count(co.rowid) as nb";
3057 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseur as co";
3058 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON co.fk_soc = s.rowid";
3059 if (empty($user->rights->societe->client->voir) && !$user->socid) {
3060 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
3061 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
3064 $sql .=
" ".$clause.
" co.entity IN (".
getEntity(
'supplier_order').
")";
3068 while ($obj = $this->
db->fetch_object(
$resql)) {
3069 $this->nb[
"supplier_orders"] = $obj->nb;
3075 $this->error = $this->
db->error();
3091 global $conf, $langs;
3093 $sql =
"SELECT c.rowid, c.date_creation as datec, c.date_commande, c.fk_statut, c.date_livraison as delivery_date, c.total_ht";
3094 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseur as c";
3095 if (empty($user->rights->societe->client->voir) && !$user->socid) {
3096 $sql .=
" JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
3098 $sql .=
" WHERE c.entity = ".$conf->entity;
3099 if ($mode ===
'awaiting') {
3100 $sql .=
" AND c.fk_statut IN (".self::STATUS_ORDERSENT.
", ".self::STATUS_RECEIVED_PARTIALLY.
")";
3102 $sql .=
" AND c.fk_statut IN (".self::STATUS_VALIDATED.
", ".self::STATUS_ACCEPTED.
")";
3105 $sql .=
" AND c.fk_soc = ".((int) $user->socid);
3113 $response->warning_delay = $conf->commande->fournisseur->warning_delay / 60 / 60 / 24;
3114 $response->label = $langs->trans(
"SuppliersOrdersToProcess");
3115 $response->labelShort = $langs->trans(
"Opened");
3116 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=1,2&mainmenu=commercial&leftmenu=orders_suppliers';
3119 if ($mode ===
'awaiting') {
3120 $response->label = $langs->trans(
"SuppliersOrdersAwaitingReception");
3121 $response->labelShort = $langs->trans(
"AwaitingReception");
3122 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?search_status=3,4&mainmenu=commercial&leftmenu=orders_suppliers';
3125 while ($obj = $this->
db->fetch_object(
$resql)) {
3126 $commandestatic->delivery_date = $this->
db->jdate($obj->delivery_date);
3127 $commandestatic->date_commande = $this->
db->jdate($obj->date_commande);
3128 $commandestatic->statut = $obj->fk_statut;
3130 $response->nbtodo++;
3131 $response->total += $obj->total_ht;
3133 if ($commandestatic->hasDelay()) {
3134 $response->nbtodolate++;
3140 $this->error = $this->
db->error();
3155 if ($this->methode_commande_id > 0) {
3156 $sql =
"SELECT rowid, code, libelle as label";
3157 $sql .=
" FROM ".MAIN_DB_PREFIX.
'c_input_method';
3158 $sql .=
" WHERE active=1 AND rowid = ".((int) $this->methode_commande_id);
3163 $obj = $this->
db->fetch_object(
$resql);
3165 $string = $langs->trans($obj->code);
3166 if ($string == $obj->code) {
3167 $string = $obj->label !=
'-' ? $obj->label :
'';
3190 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
3192 global $conf, $langs;
3194 $langs->load(
"suppliers");
3195 $outputlangs->load(
"products");
3199 if ($this->model_pdf) {
3200 $modele = $this->model_pdf;
3201 } elseif (!empty($conf->global->COMMANDE_SUPPLIER_ADDON_PDF)) {
3202 $modele = $conf->global->COMMANDE_SUPPLIER_ADDON_PDF;
3205 if (empty($modele)) {
3208 $modelpath =
"core/modules/supplier_order/doc/";
3209 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3221 if (empty($this->lines)) {
3228 foreach ($this->lines as $line) {
3229 if ($line->fk_product > 0) {
3230 $idp = $obj->find_min_price_product_fournisseur($line->fk_product, $line->qty);
3233 if ($obj->delivery_time_days > $nb) {
3234 $nb = $obj->delivery_time_days;
3243 return $nb.
' '.$langs->trans(
'Days');
3255 return $user->rights->fournisseur->commande;
3270 'commande_fournisseur'
3287 'commande_fournisseurdet'
3304 if (empty($this->delivery_date) && !empty($this->date_livraison)) {
3305 $this->delivery_date = $this->date_livraison;
3308 if ($this->statut == self::STATUS_ORDERSENT || $this->statut == self::STATUS_RECEIVED_PARTIALLY) {
3310 if (!empty($this->delivery_date)) {
3311 $date_to_test = $this->delivery_date;
3312 return $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay);
3320 $date_to_test = $this->date_commande;
3322 return ($this->statut > 0 && $this->statut < 5) && $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay);
3335 global $conf, $langs;
3337 if (empty($this->delivery_date) && !empty($this->date_livraison)) {
3338 $this->delivery_date = $this->date_livraison;
3343 if ($this->statut == self::STATUS_ORDERSENT || $this->statut == self::STATUS_RECEIVED_PARTIALLY) {
3344 if (!empty($this->delivery_date)) {
3345 $text = $langs->trans(
"DeliveryDate").
' '.
dol_print_date($this->delivery_date,
'day');
3347 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3350 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3353 $text .=
' '.($conf->commande->fournisseur->warning_delay > 0 ?
'+' :
'-').
' '.round(abs($conf->commande->fournisseur->warning_delay) / 3600 / 24, 1).
' '.$langs->trans(
"days").
' < '.$langs->trans(
"Today");
3370 global $conf, $langs;
3372 if ((!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)) || !empty($conf->supplier_order->enabled)) {
3373 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
3375 $qtydelivered = array();
3376 $qtywished = array();
3379 $filter = array(
't.fk_commande'=>$this->
id);
3380 if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) {
3381 $filter[
't.status'] = 1;
3384 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
3386 $this->error = $supplierorderdispatch->error; $this->errors = $supplierorderdispatch->errors;
3389 if (is_array($supplierorderdispatch->lines) && count($supplierorderdispatch->lines) > 0) {
3390 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
3394 foreach ($supplierorderdispatch->lines as $line) {
3395 $qtydelivered[$line->fk_product] += $line->qty;
3397 foreach ($this->lines as $line) {
3399 if (empty($conf->global->STOCK_SUPPORTS_SERVICES) && $line->product_type > 0) {
3402 $qtywished[$line->fk_product] += $line->qty;
3406 $diff_array = array_diff_assoc($qtydelivered, $qtywished);
3407 $keysinwishednotindelivered = array_diff(array_keys($qtywished), array_keys($qtydelivered));
3408 $keysindeliverednotinwished = array_diff(array_keys($qtydelivered), array_keys($qtywished));
3416 if (count($diff_array) == 0 && count($keysinwishednotindelivered) == 0 && count($keysindeliverednotinwished) == 0) {
3417 if ($closeopenorder) {
3419 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3427 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3433 } elseif (!empty($conf->global->SUPPLIER_ORDER_MORE_THAN_WISHED)) {
3438 if (count($diff_array) > 0) {
3442 foreach ($diff_array as $key => $value) {
3444 if ($qtydelivered[$key] >= $qtywished[$key]) {
3451 if ($close == count($diff_array)) {
3453 if ($closeopenorder) {
3454 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3461 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3469 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3477 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3499 $this->receptions = array();
3501 dol_syslog(get_class($this).
"::loadReceptions", LOG_DEBUG);
3503 $sql =
'SELECT cd.rowid, cd.fk_product,';
3504 $sql .=
' sum(cfd.qty) as qty';
3505 $sql .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseur_dispatch as cfd,';
3506 if ($filtre_statut >= 0) {
3507 $sql .=
' '.MAIN_DB_PREFIX.
'reception as e,';
3509 $sql .=
' '.MAIN_DB_PREFIX.
'commande_fournisseurdet as cd';
3511 if ($filtre_statut >= 0) {
3512 $sql .=
' cfd.fk_reception = e.rowid AND';
3514 $sql .=
' cfd.fk_commandefourndet = cd.rowid';
3515 $sql .=
' AND cd.fk_commande ='.((int) $this->
id);
3516 if ($this->fk_product > 0) {
3517 $sql .=
' AND cd.fk_product = '.((int) $this->fk_product);
3519 if ($filtre_statut >= 0) {
3520 $sql .=
' AND e.fk_statut >= '.((int) $filtre_statut);
3522 $sql .=
' GROUP BY cd.rowid, cd.fk_product';
3526 $num = $this->
db->num_rows(
$resql);
3529 $obj = $this->
db->fetch_object(
$resql);
3530 empty($this->receptions[$obj->rowid]) ? $this->receptions[$obj->rowid] = $obj->qty : $this->receptions[$obj->rowid] += $obj->qty;
3537 $this->error = $this->
db->lasterror();
3553 public $element =
'commande_fournisseurdet';
3558 public $table_element =
'commande_fournisseurdet';
3566 public $fk_commande;
3572 public $fk_parent_line;
3580 public $special_code = 0;
3597 public $ref_supplier;
3621 $sql =
'SELECT cd.rowid, cd.fk_commande, cd.fk_product, cd.product_type, cd.description, cd.qty, cd.tva_tx, cd.special_code,';
3622 $sql .=
' cd.localtax1_tx, cd.localtax2_tx, cd.localtax1_type, cd.localtax2_type, cd.ref as ref_supplier,';
3623 $sql .=
' cd.remise, cd.remise_percent, cd.subprice,';
3624 $sql .=
' cd.info_bits, cd.total_ht, cd.total_tva, cd.total_ttc,';
3625 $sql .=
' cd.total_localtax1, cd.total_localtax2,';
3626 $sql .=
' p.ref as product_ref, p.label as product_label, p.description as product_desc,';
3627 $sql .=
' cd.date_start, cd.date_end, cd.fk_unit,';
3628 $sql .=
' cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc,';
3629 $sql .=
' c.fk_soc as socid';
3630 $sql .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseur as c, '.MAIN_DB_PREFIX.
'commande_fournisseurdet as cd';
3631 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON cd.fk_product = p.rowid';
3632 $sql .=
' WHERE cd.fk_commande = c.rowid AND cd.rowid = '.((int) $rowid);
3634 $result = $this->
db->query($sql);
3636 $objp = $this->
db->fetch_object($result);
3638 if (!empty($objp)) {
3639 $this->
rowid = $objp->rowid;
3640 $this->
id = $objp->rowid;
3641 $this->fk_commande = $objp->fk_commande;
3642 $this->desc = $objp->description;
3643 $this->qty = $objp->qty;
3644 $this->ref_fourn = $objp->ref_supplier;
3645 $this->ref_supplier = $objp->ref_supplier;
3646 $this->subprice = $objp->subprice;
3647 $this->tva_tx = $objp->tva_tx;
3648 $this->localtax1_tx = $objp->localtax1_tx;
3649 $this->localtax2_tx = $objp->localtax2_tx;
3650 $this->localtax1_type = $objp->localtax1_type;
3651 $this->localtax2_type = $objp->localtax2_type;
3652 $this->remise = $objp->remise;
3653 $this->remise_percent = $objp->remise_percent;
3654 $this->fk_product = $objp->fk_product;
3655 $this->info_bits = $objp->info_bits;
3656 $this->total_ht = $objp->total_ht;
3657 $this->total_tva = $objp->total_tva;
3658 $this->total_localtax1 = $objp->total_localtax1;
3659 $this->total_localtax2 = $objp->total_localtax2;
3660 $this->total_ttc = $objp->total_ttc;
3661 $this->product_type = $objp->product_type;
3662 $this->special_code = $objp->special_code;
3664 $this->
ref = $objp->product_ref;
3666 $this->product_ref = $objp->product_ref;
3667 $this->product_label = $objp->product_label;
3668 $this->product_desc = $objp->product_desc;
3670 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
3675 $sqlsearchpackage =
'SELECT rowid, packaging FROM '.MAIN_DB_PREFIX.
"product_fournisseur_price";
3676 $sqlsearchpackage .=
' WHERE entity IN ('.getEntity(
'product_fournisseur_price').
")";
3677 $sqlsearchpackage .=
" AND fk_product = ".((int) $objp->fk_product);
3678 $sqlsearchpackage .=
" AND ref_fourn = '".$this->db->escape($objp->ref_supplier).
"'";
3679 $sqlsearchpackage .=
" AND quantity <= ".((float) $objp->qty);
3680 $sqlsearchpackage .=
" AND (packaging IS NULL OR packaging = 0 OR packaging <= ".((float) $objp->qty).
")";
3681 $sqlsearchpackage .=
" AND fk_soc = ".((int) $objp->socid);
3682 $sqlsearchpackage .=
" ORDER BY packaging ASC";
3683 $sqlsearchpackage .=
" LIMIT 1";
3685 $resqlsearchpackage = $this->
db->query($sqlsearchpackage);
3686 if ($resqlsearchpackage) {
3687 $objsearchpackage = $this->
db->fetch_object($resqlsearchpackage);
3688 if ($objsearchpackage) {
3689 $this->fk_fournprice = $objsearchpackage->rowid;
3690 $this->packaging = $objsearchpackage->packaging;
3693 $this->error = $this->
db->lasterror();
3698 $this->date_start = $this->
db->jdate($objp->date_start);
3699 $this->date_end = $this->
db->jdate($objp->date_end);
3700 $this->fk_unit = $objp->fk_unit;
3702 $this->multicurrency_subprice = $objp->multicurrency_subprice;
3703 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
3704 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
3705 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
3709 $this->
db->free($result);
3712 $this->error =
'Supplier order line with id='.$rowid.
' not found';
3713 dol_syslog(get_class($this).
"::fetch Error ".$this->error, LOG_ERR);
3730 global $conf, $user;
3734 dol_syslog(get_class($this).
"::insert rang=".$this->rang);
3737 if (empty($this->tva_tx)) {
3740 if (empty($this->localtax1_tx)) {
3741 $this->localtax1_tx = 0;
3743 if (empty($this->localtax2_tx)) {
3744 $this->localtax2_tx = 0;
3746 if (empty($this->localtax1_type)) {
3747 $this->localtax1_type =
'0';
3749 if (empty($this->localtax2_type)) {
3750 $this->localtax2_type =
'0';
3752 if (empty($this->total_localtax1)) {
3753 $this->total_localtax1 = 0;
3755 if (empty($this->total_localtax2)) {
3756 $this->total_localtax2 = 0;
3758 if (empty($this->rang)) {
3761 if (empty($this->remise_percent)) {
3762 $this->remise_percent = 0;
3764 if (empty($this->info_bits)) {
3765 $this->info_bits = 0;
3767 if (empty($this->special_code)) {
3768 $this->special_code = 0;
3770 if (empty($this->fk_parent_line)) {
3771 $this->fk_parent_line = 0;
3773 if (empty($this->pa_ht)) {
3778 if (!empty($this->multicurrency_code)) {
3781 if (empty($this->fk_multicurrency)) {
3782 $this->multicurrency_code = $conf->currency;
3783 $this->fk_multicurrency = 0;
3784 $this->multicurrency_tx = 1;
3788 if ($this->product_type < 0) {
3795 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element;
3796 $sql .=
" (fk_commande, label, description, date_start, date_end,";
3797 $sql .=
" fk_product, product_type, special_code, rang,";
3798 $sql .=
" qty, vat_src_code, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, remise_percent, subprice, ref,";
3799 $sql .=
" total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_unit,";
3800 $sql .=
" fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc";
3802 $sql .=
" VALUES (".$this->fk_commande.
", '".$this->
db->escape($this->label).
"','".$this->
db->escape($this->desc).
"',";
3803 $sql .=
" ".($this->date_start ?
"'".$this->db->idate($this->date_start).
"'" :
"null").
",";
3804 $sql .=
" ".($this->date_end ?
"'".$this->db->idate($this->date_end).
"'" :
"null").
",";
3805 if ($this->fk_product) {
3806 $sql .= $this->fk_product.
",";
3810 $sql .=
"'".$this->db->escape($this->product_type).
"',";
3811 $sql .=
"'".$this->db->escape($this->special_code).
"',";
3812 $sql .=
"'".$this->db->escape($this->rang).
"',";
3813 $sql .=
"'".$this->db->escape($this->qty).
"', ";
3814 $sql .=
" ".(empty($this->vat_src_code) ?
"''" :
"'".$this->db->escape($this->vat_src_code).
"'").
",";
3815 $sql .=
" ".price2num($this->tva_tx).
", ";
3816 $sql .=
" ".price2num($this->localtax1_tx).
",";
3817 $sql .=
" ".price2num($this->localtax2_tx).
",";
3818 $sql .=
" '".$this->db->escape($this->localtax1_type).
"',";
3819 $sql .=
" '".$this->db->escape($this->localtax2_type).
"',";
3820 $sql .=
" ".((float) $this->remise_percent).
", ".
price2num($this->subprice,
'MU').
", '".$this->
db->escape($this->ref_supplier).
"',";
3821 $sql .=
" ".price2num($this->total_ht).
",";
3822 $sql .=
" ".price2num($this->total_tva).
",";
3823 $sql .=
" ".price2num($this->total_localtax1).
",";
3824 $sql .=
" ".price2num($this->total_localtax2).
",";
3825 $sql .=
" ".price2num($this->total_ttc).
",";
3826 $sql .= ($this->fk_unit ?
"'".$this->db->escape($this->fk_unit).
"'" :
"null");
3827 $sql .=
", ".($this->fk_multicurrency ? ((int) $this->fk_multicurrency) :
"null");
3828 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
3829 $sql .=
", ".($this->multicurrency_subprice ?
price2num($this->multicurrency_subprice) :
'0');
3830 $sql .=
", ".($this->multicurrency_total_ht ?
price2num($this->multicurrency_total_ht) :
'0');
3831 $sql .=
", ".($this->multicurrency_total_tva ?
price2num($this->multicurrency_total_tva) :
'0');
3832 $sql .=
", ".($this->multicurrency_total_ttc ?
price2num($this->multicurrency_total_ttc) :
'0');
3835 dol_syslog(get_class($this).
"::insert", LOG_DEBUG);
3838 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
3839 $this->
rowid = $this->id;
3848 if (!$error && !$notrigger) {
3850 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_CREATE', $user);
3858 $this->
db->commit();
3862 foreach ($this->errors as $errmsg) {
3863 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
3864 $this->errors[] = ($this->errors ?
', '.$errmsg : $errmsg);
3866 $this->
db->rollback();
3869 $this->errors[] = $this->
db->error();
3870 $this->
db->rollback();
3882 global $conf, $user;
3889 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
3890 $sql .=
" description='".$this->db->escape($this->desc).
"'";
3891 $sql .=
", ref='".$this->db->escape($this->ref_supplier).
"'";
3892 $sql .=
", subprice='".price2num($this->subprice).
"'";
3894 $sql .=
", remise_percent='".price2num($this->remise_percent).
"'";
3896 $sql .=
", vat_src_code = '".(empty($this->vat_src_code) ?
'' : $this->vat_src_code).
"'";
3897 $sql .=
", tva_tx='".price2num($this->tva_tx).
"'";
3898 $sql .=
", localtax1_tx='".price2num($this->total_localtax1).
"'";
3899 $sql .=
", localtax2_tx='".price2num($this->total_localtax2).
"'";
3900 $sql .=
", localtax1_type='".$this->db->escape($this->localtax1_type).
"'";
3901 $sql .=
", localtax2_type='".$this->db->escape($this->localtax2_type).
"'";
3902 $sql .=
", qty='".price2num($this->qty).
"'";
3903 $sql .=
", date_start=".(!empty($this->date_start) ?
"'".$this->db->idate($this->date_start).
"'" :
"null");
3904 $sql .=
", date_end=".(!empty($this->date_end) ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
3905 $sql .=
", info_bits='".$this->db->escape($this->info_bits).
"'";
3906 $sql .=
", total_ht='".price2num($this->total_ht).
"'";
3907 $sql .=
", total_tva='".price2num($this->total_tva).
"'";
3908 $sql .=
", total_localtax1='".price2num($this->total_localtax1).
"'";
3909 $sql .=
", total_localtax2='".price2num($this->total_localtax2).
"'";
3910 $sql .=
", total_ttc='".price2num($this->total_ttc).
"'";
3911 $sql .=
", product_type=".$this->product_type;
3912 $sql .=
", special_code=".(!empty($this->special_code) ? $this->special_code : 0);
3913 $sql .= ($this->fk_unit ?
", fk_unit='".$this->db->escape($this->fk_unit).
"'" :
", fk_unit=null");
3916 $sql .=
", multicurrency_subprice=".price2num($this->multicurrency_subprice).
"";
3917 $sql .=
", multicurrency_total_ht=".price2num($this->multicurrency_total_ht).
"";
3918 $sql .=
", multicurrency_total_tva=".price2num($this->multicurrency_total_tva).
"";
3919 $sql .=
", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc).
"";
3921 $sql .=
" WHERE rowid = ".((int) $this->
id);
3923 dol_syslog(get_class($this).
"::updateline", LOG_DEBUG);
3924 $result = $this->
db->query($sql);
3933 if (!$error && !$notrigger) {
3936 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_MODIFY', $user);
3938 $this->
db->rollback();
3945 $this->
db->commit();
3948 $this->
db->rollback();
3952 $this->error = $this->
db->lasterror();
3953 $this->
db->rollback();
3964 public function delete($notrigger = 0)
3975 $this->
db->rollback();
3979 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
"commande_fournisseurdet WHERE rowid=".((int) $this->
id);
3986 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_DELETE', $user);
3994 $this->
db->commit();
3998 foreach ($this->errors as $errmsg) {
3999 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
4000 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
4002 $this->
db->rollback();
4005 $this->error = $this->
db->lasterror();
Class to manage stock movements.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto= 'UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
Cancel($user, $idwarehouse=-1)
Cancel an approved order.
const STATUS_ACCEPTED
Accepted.
const STATUS_DRAFT
Draft status.
deleteline($idline, $notrigger=0)
Delete line.
__construct($db)
Constructor.
const STATUS_RECEIVED_COMPLETELY
Received completely.
$conf db
API class for accounts.
fetch($id, $ref= '')
Get object and lines from database.
Class to manage table commandefournisseurdispatch.
fetch($rowid)
Load line order.
updateRangOfLine($rowid, $rang)
Update position of line (rang)
Class to manage products or services.
const STATUS_CANCELED_AFTER_ORDER
Order canceled/never received.
dol_now($mode= 'auto')
Return date for now.
line_order($renum=false, $rowidorder= 'ASC', $fk_parent_line=true)
Save a new position (field rang) for details lines.
deleteObjectLinked($sourceid=null, $sourcetype= '', $targetid=null, $targettype= '', $rowid= '', $f_user=null, $notrigger=0)
Delete all links between an object $this.
static commonReplaceProduct(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
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.
Class to manage Dolibarr users.
update(User $user, $notrigger=0)
Update Supplier Order.
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.
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)
Add order line.
showDelay()
Show the customer delayed info.
Class to manage Dolibarr database access.
add_contact($fk_socpeople, $type_contact, $source= 'external', $notrigger=0)
Add a link between element $this->element and a contact.
setEventMessage($mesgs, $style= 'mesgs')
Set event message in dol_events session object.
static replaceProduct(DoliDB $db, $origin_id, $dest_id)
Function used to replace a product id with another one.
getMaxDeliveryTimeDay($langs)
Return the max number delivery delay in day.
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
hasDelay()
Is the supplier order delayed? We suppose a purchase ordered as late if a the purchase order has been...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
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...
getNextNumRef($soc)
Returns the following order reference not used depending on the numbering model activated defined wit...
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
refuse($user)
Refuse an order.
updateFromCommandeClient($user, $idc, $comclientid)
Update a supplier order from a customer order.
create($user, $notrigger=0)
Create order with draft status.
$fields
'type' field format ('integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortf...
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...
insertExtraFields($trigger= '', $userused=null)
Add/Update all extra fields values for the current object.
getInputMethod()
Returns the translated input method of object (defined if $this->methode_commande_id > 0)...
static getIdAndTxFromCode($dbs, $code, $date_document= '')
Get id and rate of currency from code.
set_date_livraison($user, $delivery_date, $notrigger=0)
Set delivery date.
Class to manage third parties objects (customers, suppliers, prospects...)
static replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
line_max($fk_parent_line=0)
Get max value used for position of line (rang)
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
price2num($amount, $rounding= '', $option=0)
Function that return a number with universal decimal format (decimal separator is '...
getNomUrl($withpicto=0, $option= '', $notooltip=0, $save_lastsearch_value=-1, $addlinktonotes=0)
Return clicable name (with picto eventually)
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) ...
LibStatut($status, $mode=0, $billed=0)
Return label of a status.
deleteEcmFiles($mode=0)
Delete related files of object in database.
info($id)
Charge les informations d'ordre info dans l'objet facture.
static commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
const SOURCE_ID_REPLENISHMENT
The constant used into source field to track the order was generated by the replenishement feature...
const STATUS_RECEIVED_PARTIALLY
Received partially.
createFromClone(User $user, $socid=0, $notrigger=0)
Load an object from its id and create a new one in database.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
Class to manage customers orders.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
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). ...
const STATUS_VALIDATED
Validated status.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
calcAndSetStatusDispatch(User $user, $closeopenorder=1, $comment= '')
Calc status regarding to dispatched stock.
deleteExtraFields()
Delete all extra fields values for the current object.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
load_board($user, $mode= 'opened')
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
classifyBilled(User $user)
Class invoiced the supplier order.
setStatus($user, $status)
Tag order with a particular status.
static getIdFromCode($dbs, $code)
Get id of currency from code.
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...
Superclass for orders classes.
commande($user, $date, $methode, $comment= '')
Submit a supplier order to supplier.
Class to manage predefined suppliers products.
Livraison($user, $date, $type, $comment)
Set a delivery in database for this supplier order.
if(isModEnabled('facture')&&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur')&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)&&$user->rights->fournisseur->facture->lire)||(isModEnabled('supplier_invoice')&&$user->rights->supplier_invoice->lire)) if(isModEnabled('don')&&!empty($user->rights->don->lire)) if(isModEnabled('tax')&&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture')&&isModEnabled('commande')&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
getDispachedLines($status=-1)
Return array of dispatched lines waiting to be approved for this order.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
call_trigger($triggerName, $user)
Call trigger based on this instance.
const STATUS_ORDERSENT
Order sent, shipment on process.
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add objects linked in llx_element_element.
dispatchProduct($user, $product, $qty, $entrepot, $price=0, $comment= '', $eatby= '', $sellby= '', $batch= '', $fk_commandefourndet=0, $notrigger=0)
Save a receiving into the tracking table of receiving (commande_fournisseur_dispatch) and add product...
Superclass for orders classes.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template model.
valid($user, $idwarehouse=0, $notrigger=0)
Validate an order.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetStatus($statusLabel= '', $statusLabelShort= '', $html= '', $statusType= 'status0', $displayMode=0, $url= '', $params=array())
Output the badge of a status.
const STATUS_REFUSED
Refused.
update($notrigger=0)
Update the line object into db.
initAsSpecimen()
Initialise an instance with random values.
load_state_board()
Charge indicateurs this->nb de tableau de bord.
getLibStatut($mode=0)
Return label of the status of object.
getRights()
Returns the rights used for this class.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
approve($user, $idwarehouse=0, $secondlevel=0)
Approve a supplier order.
const STATUS_CANCELED
Order canceled.
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)...
fetch_lines($only_product=0)
Load array lines.
get_methodes_commande()
Get list of order methods.
insert($notrigger=0)
Insert line into database.
set_id_projet($user, $id_projet, $notrigger=0)
Set the id projet.
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.
__construct($db)
Constructor.
loadReceptions($filtre_statut=-1)
Load array this->receptions of lines of shipments with nb of products sent for each order line Note: ...
Class to manage predefined suppliers products.
Class to manage line orders.
setDeliveryDate($user, $delivery_date, $notrigger=0)
Set the planned delivery date.
print *****$script_file(".$version.") pid c cd cd cd description as p label as s rowid