35 include_once DOL_DOCUMENT_ROOT.
'/core/class/commonorder.class.php';
36 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
37 if (!empty($conf->productbatch->enabled)) require_once DOL_DOCUMENT_ROOT.
'/product/class/productbatch.class.php';
38 require_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
48 public $element =
'order_supplier';
53 public $table_element =
'commande_fournisseur';
58 public $table_element_line =
'commande_fournisseurdet';
63 public $fk_element =
'fk_commande';
68 public $picto =
'supplier_order';
74 public $ismultientitymanaged = 1;
80 public $restrictiononfksoc = 1;
113 public $date_approve;
114 public $date_approve2;
115 public $date_commande;
121 public $date_livraison;
126 public $delivery_date;
130 public $total_localtax1;
131 public $total_localtax2;
140 public $cond_reglement_id;
141 public $cond_reglement_code;
142 public $cond_reglement_label;
143 public $cond_reglement_doc;
150 public $mode_reglement_id;
151 public $mode_reglement_code;
152 public $user_author_id;
153 public $user_valid_id;
154 public $user_approve_id;
155 public $user_approve_id2;
157 public $extraparams = array();
162 public $lines = array();
167 public $linked_objects = array();
173 public $fk_multicurrency;
175 public $multicurrency_code;
176 public $multicurrency_tx;
177 public $multicurrency_total_ht;
178 public $multicurrency_total_tva;
179 public $multicurrency_total_ttc;
183 public $fields = array(
184 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
185 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>15),
186 'fk_soc' =>array(
'type'=>
'integer:Societe:societe/class/societe.class.php',
'label'=>
'ThirdParty',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>20),
187 'ref' =>array(
'type'=>
'varchar(255)',
'label'=>
'Ref',
'enabled'=>1,
'visible'=>-1,
'showoncombobox'=>1,
'position'=>25),
188 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>30,
'index'=>1),
189 'ref_ext' =>array(
'type'=>
'varchar(255)',
'label'=>
'Ref ext',
'enabled'=>1,
'visible'=>0,
'position'=>35),
190 'ref_supplier' =>array(
'type'=>
'varchar(255)',
'label'=>
'RefSupplier',
'enabled'=>1,
'visible'=>-1,
'position'=>40),
191 'fk_projet' =>array(
'type'=>
'integer:Project:projet/class/project.class.php:1:fk_statut=1',
'label'=>
'Fk projet',
'enabled'=>1,
'visible'=>-1,
'position'=>45),
192 'date_creation' =>array(
'type'=>
'datetime',
'label'=>
'Date creation',
'enabled'=>1,
'visible'=>-1,
'position'=>50),
193 'date_valid' =>array(
'type'=>
'datetime',
'label'=>
'DateValidation',
'enabled'=>1,
'visible'=>-1,
'position'=>55),
194 'date_approve' =>array(
'type'=>
'datetime',
'label'=>
'Date approve',
'enabled'=>1,
'visible'=>-1,
'position'=>60),
195 'date_approve2' =>array(
'type'=>
'datetime',
'label'=>
'Date approve2',
'enabled'=>1,
'visible'=>-1,
'position'=>65),
196 'date_commande' =>array(
'type'=>
'date',
'label'=>
'Date commande',
'enabled'=>1,
'visible'=>-1,
'position'=>70),
197 'fk_user_author' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'Fk user author',
'enabled'=>1,
'visible'=>-1,
'position'=>75),
198 'fk_user_modif' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>80),
199 'fk_user_valid' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserValidation',
'enabled'=>1,
'visible'=>-1,
'position'=>85),
200 'fk_user_approve' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserApproval',
'enabled'=>1,
'visible'=>-1,
'position'=>90),
201 'fk_user_approve2' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserSecondApproval',
'enabled'=>1,
'visible'=>-1,
'position'=>95),
202 'source' =>array(
'type'=>
'smallint(6)',
'label'=>
'Source',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>100),
203 'billed' =>array(
'type'=>
'smallint(6)',
'label'=>
'Billed',
'enabled'=>1,
'visible'=>-1,
'position'=>110),
204 'amount_ht' =>array(
'type'=>
'double(24,8)',
'label'=>
'Amount ht',
'enabled'=>1,
'visible'=>-1,
'position'=>115),
205 'remise_percent' =>array(
'type'=>
'double',
'label'=>
'Remise percent',
'enabled'=>1,
'visible'=>-1,
'position'=>120),
206 'remise' =>array(
'type'=>
'double',
'label'=>
'Remise',
'enabled'=>1,
'visible'=>-1,
'position'=>125),
207 'tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'Tva',
'enabled'=>1,
'visible'=>-1,
'position'=>130,
'isameasure'=>1),
208 'localtax1' =>array(
'type'=>
'double(24,8)',
'label'=>
'Localtax1',
'enabled'=>1,
'visible'=>-1,
'position'=>135,
'isameasure'=>1),
209 'localtax2' =>array(
'type'=>
'double(24,8)',
'label'=>
'Localtax2',
'enabled'=>1,
'visible'=>-1,
'position'=>140,
'isameasure'=>1),
210 'total_ht' =>array(
'type'=>
'double(24,8)',
'label'=>
'TotalHT',
'enabled'=>1,
'visible'=>-1,
'position'=>145,
'isameasure'=>1),
211 'total_ttc' =>array(
'type'=>
'double(24,8)',
'label'=>
'TotalTTC',
'enabled'=>1,
'visible'=>-1,
'position'=>150,
'isameasure'=>1),
212 'note_private' =>array(
'type'=>
'text',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>155),
213 'note_public' =>array(
'type'=>
'text',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>0,
'position'=>160),
214 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'ModelPDF',
'enabled'=>1,
'visible'=>0,
'position'=>165),
215 'fk_input_method' =>array(
'type'=>
'integer',
'label'=>
'InputMethod',
'enabled'=>1,
'visible'=>-1,
'position'=>170),
216 'fk_cond_reglement' =>array(
'type'=>
'integer',
'label'=>
'PaymentTerm',
'enabled'=>1,
'visible'=>-1,
'position'=>175),
217 'fk_mode_reglement' =>array(
'type'=>
'integer',
'label'=>
'PaymentMode',
'enabled'=>1,
'visible'=>-1,
'position'=>180),
218 'extraparams' =>array(
'type'=>
'varchar(255)',
'label'=>
'Extraparams',
'enabled'=>1,
'visible'=>-1,
'position'=>190),
219 'date_livraison' =>array(
'type'=>
'datetime',
'label'=>
'DeliveryDate',
'enabled'=>1,
'visible'=>-1,
'position'=>195),
220 'fk_account' =>array(
'type'=>
'integer',
'label'=>
'Fk account',
'enabled'=>1,
'visible'=>-1,
'position'=>200),
221 'fk_incoterms' =>array(
'type'=>
'integer',
'label'=>
'IncotermCode',
'enabled'=>1,
'visible'=>-1,
'position'=>205),
222 'location_incoterms' =>array(
'type'=>
'varchar(255)',
'label'=>
'IncotermLocation',
'enabled'=>1,
'visible'=>-1,
'position'=>210),
223 'fk_multicurrency' =>array(
'type'=>
'integer',
'label'=>
'Fk multicurrency',
'enabled'=>1,
'visible'=>-1,
'position'=>215),
224 'multicurrency_code' =>array(
'type'=>
'varchar(255)',
'label'=>
'MulticurrencyCode',
'enabled'=>1,
'visible'=>-1,
'position'=>220),
225 'multicurrency_tx' =>array(
'type'=>
'double(24,8)',
'label'=>
'MulticurrencyRate',
'enabled'=>1,
'visible'=>-1,
'position'=>225),
226 'multicurrency_total_ht' =>array(
'type'=>
'double(24,8)',
'label'=>
'MulticurrencyTotalHT',
'enabled'=>1,
'visible'=>-1,
'position'=>230),
227 'multicurrency_total_tva' =>array(
'type'=>
'double(24,8)',
'label'=>
'MulticurrencyTotalVAT',
'enabled'=>1,
'visible'=>-1,
'position'=>235),
228 'multicurrency_total_ttc' =>array(
'type'=>
'double(24,8)',
'label'=>
'MulticurrencyTotalTTC',
'enabled'=>1,
'visible'=>-1,
'position'=>240),
229 'last_main_doc' =>array(
'type'=>
'varchar(255)',
'label'=>
'LastMainDoc',
'enabled'=>1,
'visible'=>-1,
'position'=>245),
230 'fk_statut' =>array(
'type'=>
'smallint(6)',
'label'=>
'Status',
'enabled'=>1,
'visible'=>-1,
'position'=>500),
231 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>900),
301 public function fetch($id, $ref =
'')
306 if (empty($id) && empty($ref))
return -1;
308 $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.tva as total_vat,";
309 $sql .=
" c.localtax1, c.localtax2, ";
310 $sql .=
" c.date_creation, c.date_valid, c.date_approve, c.date_approve2,";
311 $sql .=
" c.fk_user_author, c.fk_user_valid, c.fk_user_approve, c.fk_user_approve2,";
312 $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,";
313 $sql .=
" c.fk_account,";
314 $sql .=
" c.note_private, c.note_public, c.model_pdf, c.extraparams, c.billed,";
315 $sql .=
" c.fk_multicurrency, c.multicurrency_code, c.multicurrency_tx, c.multicurrency_total_ht, c.multicurrency_total_tva, c.multicurrency_total_ttc,";
316 $sql .=
" cm.libelle as methode_commande,";
317 $sql .=
" cr.code as cond_reglement_code, cr.libelle as cond_reglement_label, cr.libelle_facture as cond_reglement_doc,";
318 $sql .=
" p.code as mode_reglement_code, p.libelle as mode_reglement_libelle";
319 $sql .=
', c.fk_incoterms, c.location_incoterms';
320 $sql .=
', i.libelle as label_incoterms';
321 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseur as c";
322 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_payment_term as cr ON c.fk_cond_reglement = cr.rowid";
323 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_paiement as p ON c.fk_mode_reglement = p.id";
324 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"c_input_method as cm ON cm.rowid = c.fk_input_method";
325 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON c.fk_incoterms = i.rowid';
327 if (empty($id)) $sql .=
" WHERE c.entity IN (".getEntity(
'supplier_order').
")";
328 else $sql .=
" WHERE c.rowid=".$id;
330 if ($ref) $sql .=
" AND c.ref='".$this->db->escape($ref).
"'";
332 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
336 $obj = $this->
db->fetch_object(
$resql);
339 $this->error =
'Bill with id '.$id.
' not found';
340 dol_syslog(get_class($this).
'::fetch '.$this->error);
344 $this->
id = $obj->rowid;
345 $this->entity = $obj->entity;
347 $this->ref = $obj->ref;
348 $this->ref_supplier = $obj->ref_supplier;
349 $this->socid = $obj->fk_soc;
350 $this->fourn_id = $obj->fk_soc;
351 $this->
statut = $obj->fk_statut;
352 $this->status = $obj->fk_statut;
353 $this->billed = $obj->billed;
354 $this->user_author_id = $obj->fk_user_author;
355 $this->user_valid_id = $obj->fk_user_valid;
356 $this->user_approve_id = $obj->fk_user_approve;
357 $this->user_approve_id2 = $obj->fk_user_approve2;
358 $this->total_ht = $obj->total_ht;
359 $this->total_tva = $obj->total_vat;
360 $this->total_localtax1 = $obj->localtax1;
361 $this->total_localtax2 = $obj->localtax2;
362 $this->total_ttc = $obj->total_ttc;
363 $this->date = $this->
db->jdate($obj->date_creation);
364 $this->date_valid = $this->
db->jdate($obj->date_valid);
365 $this->date_approve = $this->
db->jdate($obj->date_approve);
366 $this->date_approve2 = $this->
db->jdate($obj->date_approve2);
367 $this->date_commande = $this->
db->jdate($obj->date_commande);
368 $this->date_livraison = $this->
db->jdate($obj->delivery_date);
369 $this->delivery_date = $this->
db->jdate($obj->delivery_date);
370 $this->remise_percent = $obj->remise_percent;
371 $this->methode_commande_id = $obj->fk_input_method;
372 $this->methode_commande = $obj->methode_commande;
374 $this->source = $obj->source;
375 $this->fk_project = $obj->fk_project;
376 $this->cond_reglement_id = $obj->fk_cond_reglement;
377 $this->cond_reglement_code = $obj->cond_reglement_code;
378 $this->cond_reglement = $obj->cond_reglement_label;
379 $this->cond_reglement_label = $obj->cond_reglement_label;
380 $this->cond_reglement_doc = $obj->cond_reglement_doc;
381 $this->fk_account = $obj->fk_account;
382 $this->mode_reglement_id = $obj->fk_mode_reglement;
383 $this->mode_reglement_code = $obj->mode_reglement_code;
384 $this->mode_reglement = $obj->mode_reglement_libelle;
385 $this->
note = $obj->note_private;
386 $this->note_private = $obj->note_private;
387 $this->note_public = $obj->note_public;
388 $this->model_pdf = $obj->model_pdf;
389 $this->modelpdf = $obj->model_pdf;
392 $this->fk_incoterms = $obj->fk_incoterms;
393 $this->location_incoterms = $obj->location_incoterms;
394 $this->label_incoterms = $obj->label_incoterms;
397 $this->fk_multicurrency = $obj->fk_multicurrency;
398 $this->multicurrency_code = $obj->multicurrency_code;
399 $this->multicurrency_tx = $obj->multicurrency_tx;
400 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
401 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
402 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
404 $this->extraparams = (array) json_decode($obj->extraparams,
true);
412 if ($this->
statut == 0) $this->brouillon = 1;
425 $this->error = $this->
db->error().
" sql=".$sql;
442 $this->lines = array();
444 $sql =
"SELECT l.rowid, l.ref as ref_supplier, l.fk_product, l.product_type, l.label, l.description, l.qty,";
445 $sql .=
" l.vat_src_code, l.tva_tx, l.remise_percent, l.subprice,";
446 $sql .=
" l.localtax1_tx, l. localtax2_tx, l.localtax1_type, l. localtax2_type, l.total_localtax1, l.total_localtax2,";
447 $sql .=
" l.total_ht, l.total_tva, l.total_ttc, l.special_code, l.fk_parent_line, l.rang,";
448 $sql .=
" p.rowid as product_id, p.ref as product_ref, p.label as product_label, p.description as product_desc,";
449 $sql .=
" l.fk_unit,";
450 $sql .=
" l.date_start, l.date_end,";
451 $sql .=
' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc';
452 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING))
453 $sql .=
", pfp.rowid as fk_pfp, pfp.packaging";
454 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet as l";
455 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON l.fk_product = p.rowid';
456 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING))
457 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product_fournisseur_price as pfp ON l.fk_product = pfp.fk_product and l.ref = pfp.ref_fourn";
458 $sql .=
" WHERE l.fk_commande = ".$this->id;
459 if ($only_product) $sql .=
' AND p.fk_product_type = 0';
460 $sql .=
" ORDER BY l.rang, l.rowid";
463 dol_syslog(get_class($this).
"::fetch get lines", LOG_DEBUG);
464 $result = $this->
db->query($sql);
467 $num = $this->
db->num_rows($result);
472 $objp = $this->
db->fetch_object($result);
476 $line->id = $objp->rowid;
477 $line->desc = $objp->description;
478 $line->description = $objp->description;
479 $line->qty = $objp->qty;
480 $line->tva_tx = $objp->tva_tx;
481 $line->localtax1_tx = $objp->localtax1_tx;
482 $line->localtax2_tx = $objp->localtax2_tx;
483 $line->localtax1_type = $objp->localtax1_type;
484 $line->localtax2_type = $objp->localtax2_type;
485 $line->subprice = $objp->subprice;
486 $line->pu_ht = $objp->subprice;
487 $line->remise_percent = $objp->remise_percent;
489 $line->vat_src_code = $objp->vat_src_code;
490 $line->total_ht = $objp->total_ht;
491 $line->total_tva = $objp->total_tva;
492 $line->total_localtax1 = $objp->total_localtax1;
493 $line->total_localtax2 = $objp->total_localtax2;
494 $line->total_ttc = $objp->total_ttc;
495 $line->product_type = $objp->product_type;
497 $line->fk_product = $objp->fk_product;
499 $line->libelle = $objp->product_label;
500 $line->product_label = $objp->product_label;
501 $line->product_desc = $objp->product_desc;
503 $line->ref = $objp->product_ref;
504 $line->product_ref = $objp->product_ref;
505 $line->ref_fourn = $objp->ref_supplier;
506 $line->ref_supplier = $objp->ref_supplier;
508 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING))
510 $line->fk_fournprice = $objp->fk_pfp;
511 $line->packaging = $objp->packaging;
514 $line->date_start = $this->
db->jdate($objp->date_start);
515 $line->date_end = $this->
db->jdate($objp->date_end);
516 $line->fk_unit = $objp->fk_unit;
519 $line->fk_multicurrency = $objp->fk_multicurrency;
520 $line->multicurrency_code = $objp->multicurrency_code;
521 $line->multicurrency_subprice = $objp->multicurrency_subprice;
522 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
523 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
524 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
526 $line->special_code = $objp->special_code;
527 $line->fk_parent_line = $objp->fk_parent_line;
529 $line->rang = $objp->rang;
533 $line->fetch_optionals();
535 $this->lines[$i] = $line;
539 $this->
db->free($result);
543 $this->error = $this->
db->error().
" sql=".$sql;
556 public function valid($user, $idwarehouse = 0, $notrigger = 0)
558 global $langs, $conf;
559 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
565 if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->commande->creer))
566 || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && !empty($user->rights->fournisseur->supplier_order_advance->validate)))
572 $soc->fetch($this->fourn_id);
575 if (preg_match(
'/^[\(]?PROV/i', $this->ref) || empty($this->ref))
583 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"commande_fournisseur";
584 $sql .=
" SET ref='".$this->db->escape($num).
"',";
585 $sql .=
" fk_statut = ".self::STATUS_VALIDATED.
",";
586 $sql .=
" date_valid='".$this->db->idate(
dol_now()).
"',";
587 $sql .=
" fk_user_valid = ".$user->id;
588 $sql .=
" WHERE rowid = ".$this->id;
589 $sql .=
" AND fk_statut = ".self::STATUS_DRAFT;
598 if (!$error && !$notrigger)
601 $result = $this->
call_trigger(
'ORDER_SUPPLIER_VALIDATE', $user);
602 if ($result < 0) $error++;
608 $this->oldref = $this->ref;
611 if (preg_match(
'/^[\(]?PROV/i', $this->ref))
614 $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).
"'";
615 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->ref).
"%' AND filepath = 'fournisseur/commande/".$this->
db->escape($this->ref).
"' and entity = ".$conf->entity;
617 if (!
$resql) { $error++; $this->error = $this->
db->lasterror(); }
622 $dirsource = $conf->fournisseur->commande->dir_output.
'/'.$oldref;
623 $dirdest = $conf->fournisseur->commande->dir_output.
'/'.$newref;
624 if (!$error && file_exists($dirsource))
626 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
628 if (@rename($dirsource, $dirdest))
632 $listoffiles =
dol_dir_list($conf->fournisseur->commande->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
633 foreach ($listoffiles as $fileentry)
635 $dirsource = $fileentry[
'name'];
636 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
637 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
638 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
639 @rename($dirsource, $dirdest);
649 $this->
statut = self::STATUS_VALIDATED;
658 $this->
db->rollback();
662 $this->error =
'NotAuthorized';
663 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
688 public function LibStatut($status, $mode = 0, $billed = 0)
691 global $conf, $langs;
693 if (empty($this->statuts) || empty($this->statutshort)) {
694 $langs->load(
'orders');
696 $this->statuts[0] =
'StatusSupplierOrderDraft';
697 $this->statuts[1] =
'StatusSupplierOrderValidated';
698 $this->statuts[2] =
'StatusSupplierOrderApproved';
699 if (empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) $this->statuts[3] =
'StatusSupplierOrderOnProcess';
700 else $this->statuts[3] =
'StatusSupplierOrderOnProcessWithValidation';
701 $this->statuts[4] =
'StatusSupplierOrderReceivedPartially';
702 $this->statuts[5] =
'StatusSupplierOrderReceivedAll';
703 $this->statuts[6] =
'StatusSupplierOrderCanceled';
704 $this->statuts[7] =
'StatusSupplierOrderCanceled';
705 $this->statuts[9] =
'StatusSupplierOrderRefused';
708 $this->statutshort[0] =
'StatusSupplierOrderDraftShort';
709 $this->statutshort[1] =
'StatusSupplierOrderValidatedShort';
710 $this->statutshort[2] =
'StatusSupplierOrderApprovedShort';
711 $this->statutshort[3] =
'StatusSupplierOrderOnProcessShort';
712 $this->statutshort[4] =
'StatusSupplierOrderReceivedPartiallyShort';
713 $this->statutshort[5] =
'StatusSupplierOrderReceivedAllShort';
714 $this->statutshort[6] =
'StatusSupplierOrderCanceledShort';
715 $this->statutshort[7] =
'StatusSupplierOrderCanceledShort';
716 $this->statutshort[9] =
'StatusSupplierOrderRefusedShort';
719 $statustrans = array(
731 $statusClass =
'status0';
732 if (!empty($statustrans[$status])) {
733 $statusClass = $statustrans[$status];
738 $billedtext =
' - '.$langs->trans(
"Billed");
740 if ($status == 5 && $billed) $statusClass =
'status6';
742 $statusLong = $langs->trans($this->statuts[$status]).$billedtext;
743 $statusShort = $langs->trans($this->statutshort[$status]);
745 return dolGetStatus($statusLong, $statusShort,
'', $statusClass, $mode);
759 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = 0)
761 global $langs, $conf, $user;
767 if ($user->rights->fournisseur->commande->lire) {
768 $label =
'<u class="paddingrightonly">'.$langs->trans(
"SupplierOrder").
'</u>';
769 if (isset($this->
statut)) {
770 $label .=
' '.$this->getLibStatut(5);
772 if (!empty($this->ref)) {
773 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
775 if (!empty($this->ref_supplier)) {
776 $label .=
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.$this->ref_supplier;
778 if (!empty($this->total_ht)) {
779 $label .=
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
781 if (!empty($this->total_tva)) {
782 $label .=
'<br><b>'.$langs->trans(
'VAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
784 if (!empty($this->total_ttc)) {
785 $label .=
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
787 if (!empty($this->delivery_date)) {
788 $label .=
'<br><b>'.$langs->trans(
'DeliveryDate').
':</b> '.
dol_print_date($this->delivery_date,
'dayhour');
793 $url = DOL_URL_ROOT.
'/fourn/commande/card.php?id='.$this->id;
795 if ($option !==
'nolink')
798 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
799 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/',
$_SERVER[
"PHP_SELF"])) $add_save_lastsearch_values = 1;
800 if ($add_save_lastsearch_values) $url .=
'&save_lastsearch_values=1';
804 if (empty($notooltip))
806 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
808 $label = $langs->trans(
"ShowOrder");
809 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
811 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
812 $linkclose .=
' class="classfortooltip"';
815 $linkstart =
'<a href="'.$url.
'"';
816 $linkstart .= $linkclose.
'>';
819 $result .= $linkstart;
820 if ($withpicto) $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
821 if ($withpicto != 2) $result .= $this->ref;
826 $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
830 $result .=
' <span class="note inline-block">';
831 $result .=
'<a href="'.DOL_URL_ROOT.
'/fourn/commande/note.php?id='.$this->
id.
'" class="classfortooltip" title="'.
dol_escape_htmltag($notetoshow).
'">';
836 $result .=
'</span>';
853 global $db, $langs, $conf;
854 $langs->load(
"orders");
856 if (!empty($conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER))
860 $file = $conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER.
'.php';
861 $classname = $conf->global->COMMANDE_SUPPLIER_ADDON_NUMBER;
864 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
866 foreach ($dirmodels as $reldir) {
867 $dir =
dol_buildpath($reldir.
"core/modules/supplier_order/");
870 $mybool |= @include_once $dir.$file;
873 if ($mybool ===
false) {
878 $obj =
new $classname();
879 $numref = $obj->getNextValue($soc, $this);
885 $this->error = $obj->error;
889 $this->error =
"Error_COMMANDE_SUPPLIER_ADDON_NotDefined";
910 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur SET billed = 1';
911 $sql .=
' WHERE rowid = '.$this->id.
' AND fk_statut > '.self::STATUS_DRAFT;
913 if ($this->
db->query($sql))
918 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CLASSIFY_BILLED', $user);
919 if ($result < 0) $error++;
930 $this->
db->rollback();
936 $this->
db->rollback();
949 public function approve($user, $idwarehouse = 0, $secondlevel = 0)
951 global $langs, $conf;
952 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
958 if ($user->rights->fournisseur->commande->approuver)
966 $soc->fetch($this->fourn_id);
969 if (preg_match(
'/^[\(]?PROV/i', $this->ref) || empty($this->ref))
978 $movetoapprovestatus =
true;
981 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur";
982 $sql .=
" SET ref='".$this->db->escape($num).
"',";
983 if (empty($secondlevel))
985 $sql .=
" date_approve='".$this->db->idate($now).
"',";
986 $sql .=
" fk_user_approve = ".$user->id;
987 if (!empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) && $conf->global->MAIN_FEATURES_LEVEL > 0 && $this->total_ht >= $conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED)
989 if (empty($this->user_approve_id2))
991 $movetoapprovestatus =
false;
992 $comment =
' (first level)';
997 $sql .=
" date_approve2='".$this->db->idate($now).
"',";
998 $sql .=
" fk_user_approve2 = ".$user->id;
999 if (empty($this->user_approve_id)) $movetoapprovestatus =
false;
1000 $comment =
' (second level)';
1003 if ($movetoapprovestatus) $sql .=
", fk_statut = ".self::STATUS_ACCEPTED;
1004 else $sql .=
", fk_statut = ".self::STATUS_VALIDATED;
1005 $sql .=
" WHERE rowid = ".$this->id;
1006 $sql .=
" AND fk_statut = ".self::STATUS_VALIDATED;
1008 if ($this->
db->query($sql))
1010 if (!empty($conf->global->SUPPLIER_ORDER_AUTOADD_USER_CONTACT))
1012 $result = $this->
add_contact($user->id,
'SALESREPFOLL',
'internal', 1);
1013 if ($result < 0 && $result != -2)
1020 if (!$error && $movetoapprovestatus && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER))
1022 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1023 $langs->load(
"agenda");
1025 $cpt = count($this->lines);
1026 for ($i = 0; $i < $cpt; $i++)
1029 if ($this->lines[$i]->fk_product > 0)
1031 $this->line = $this->lines[$i];
1033 $mouvP->origin = &$this;
1035 $up_ht_disc = $this->lines[$i]->subprice;
1036 if (!empty($this->lines[$i]->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) $up_ht_disc =
price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100,
'MU');
1037 $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans(
"OrderApprovedInDolibarr", $this->ref));
1038 if ($result < 0) { $error++; }
1047 $result = $this->
call_trigger(
'ORDER_SUPPLIER_APPROVE', $user);
1048 if ($result < 0) $error++;
1054 $this->ref = $this->newref;
1056 if ($movetoapprovestatus) $this->
statut = self::STATUS_ACCEPTED;
1057 else $this->
statut = self::STATUS_VALIDATED;
1058 if (empty($secondlevel))
1060 $this->date_approve = $now;
1061 $this->user_approve_id = $user->id;
1064 $this->date_approve2 = $now;
1065 $this->user_approve_id2 = $user->id;
1068 $this->
db->commit();
1071 $this->
db->rollback();
1075 $this->
db->rollback();
1076 $this->error = $this->
db->lasterror();
1080 dol_syslog(get_class($this).
"::approve Not Authorized", LOG_ERR);
1093 global $conf, $langs;
1099 if ($user->rights->fournisseur->commande->approuver)
1103 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur SET fk_statut = ".self::STATUS_REFUSED;
1104 $sql .=
" WHERE rowid = ".$this->id;
1106 if ($this->
db->query($sql))
1113 $result = $this->
call_trigger(
'ORDER_SUPPLIER_REFUSE', $user);
1117 $this->
db->rollback();
1118 }
else $this->
db->commit();
1122 $this->
db->rollback();
1123 $this->error = $this->
db->lasterror();
1124 dol_syslog(get_class($this).
"::refuse Error -1");
1128 dol_syslog(get_class($this).
"::refuse Not Authorized");
1142 public function Cancel($user, $idwarehouse = -1)
1145 global $langs, $conf;
1151 if ($user->rights->fournisseur->commande->commander)
1153 $statut = self::STATUS_CANCELED;
1157 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur SET fk_statut = ".$statut;
1158 $sql .=
" WHERE rowid = ".$this->id;
1159 dol_syslog(get_class($this).
"::cancel", LOG_DEBUG);
1160 if ($this->
db->query($sql))
1165 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CANCEL', $user);
1166 if ($result < 0) $error++;
1171 $this->
db->commit();
1174 $this->
db->rollback();
1178 $this->
db->rollback();
1179 $this->error = $this->
db->lasterror();
1180 dol_syslog(get_class($this).
"::cancel ".$this->error);
1184 dol_syslog(get_class($this).
"::cancel Not Authorized");
1198 public function commande($user, $date, $methode, $comment =
'')
1203 if ($user->rights->fournisseur->commande->commander)
1207 $newnoteprivate = $this->note_private;
1208 if ($comment) $newnoteprivate =
dol_concatdesc($newnoteprivate, $langs->trans(
"Comment").
': '.$comment);
1210 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur";
1211 $sql .=
" SET fk_statut=".self::STATUS_ORDERSENT.
", fk_input_method=".$methode.
", date_commande='".$this->
db->idate($date).
"', ";
1212 $sql .=
" note_private='".$this->db->escape($newnoteprivate).
"'";
1213 $sql .=
" WHERE rowid=".$this->id;
1215 dol_syslog(get_class($this).
"::commande", LOG_DEBUG);
1216 if ($this->
db->query($sql))
1218 $this->
statut = self::STATUS_ORDERSENT;
1219 $this->methode_commande_id = $methode;
1220 $this->date_commande = $date;
1221 $this->context = array(
'comments' => $comment);
1224 $result = $this->
call_trigger(
'ORDER_SUPPLIER_SUBMIT', $user);
1225 if ($result < 0) $error++;
1229 $this->error = $this->
db->lasterror();
1230 $this->errors[] = $this->
db->lasterror();
1235 $this->
db->commit();
1237 $this->
db->rollback();
1241 $this->error = $langs->trans(
'NotAuthorized');
1242 $this->errors[] = $langs->trans(
'NotAuthorized');
1243 dol_syslog(get_class($this).
"::commande User not Authorized", LOG_WARNING);
1246 return ($error ? -1 : 1);
1256 public function create($user, $notrigger = 0)
1258 global $langs, $conf, $hookmanager;
1266 $date = ($this->date_commande ? $this->date_commande : $this->date);
1267 if (empty($date)) $date = $now;
1268 $delivery_date = empty($this->delivery_date) ? $this->date_livraison : $this->delivery_date;
1271 if (empty($this->source)) $this->source = 0;
1274 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) list($this->fk_multicurrency, $this->multicurrency_tx) =
MultiCurrency::getIdAndTxFromCode($this->
db, $this->multicurrency_code, $date);
1276 if (empty($this->fk_multicurrency))
1278 $this->multicurrency_code = $conf->currency;
1279 $this->fk_multicurrency = 0;
1280 $this->multicurrency_tx = 1;
1284 $this->brouillon = 1;
1286 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"commande_fournisseur (";
1288 $sql .=
", ref_supplier";
1289 $sql .=
", note_private";
1290 $sql .=
", note_public";
1293 $sql .=
", fk_projet";
1294 $sql .=
", date_creation";
1295 $sql .=
", date_livraison";
1296 $sql .=
", fk_user_author";
1297 $sql .=
", fk_statut";
1299 $sql .=
", model_pdf";
1300 $sql .=
", fk_mode_reglement";
1301 $sql .=
", fk_cond_reglement";
1302 $sql .=
", fk_account";
1303 $sql .=
", fk_incoterms, location_incoterms";
1304 $sql .=
", fk_multicurrency";
1305 $sql .=
", multicurrency_code";
1306 $sql .=
", multicurrency_tx";
1308 $sql .=
" VALUES (";
1310 $sql .=
", '".$this->db->escape($this->ref_supplier).
"'";
1311 $sql .=
", '".$this->db->escape($this->note_private).
"'";
1312 $sql .=
", '".$this->db->escape($this->note_public).
"'";
1313 $sql .=
", ".$conf->entity;
1314 $sql .=
", ".$this->socid;
1315 $sql .=
", ".($this->fk_project > 0 ? $this->fk_project :
"null");
1316 $sql .=
", '".$this->db->idate($date).
"'";
1317 $sql .=
", ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
"null");
1318 $sql .=
", ".$user->id;
1319 $sql .=
", ".self::STATUS_DRAFT;
1320 $sql .=
", ".$this->db->escape($this->source);
1321 $sql .=
", '".$this->db->escape($conf->global->COMMANDE_SUPPLIER_ADDON_PDF).
"'";
1322 $sql .=
", ".($this->mode_reglement_id > 0 ? $this->mode_reglement_id :
'null');
1323 $sql .=
", ".($this->cond_reglement_id > 0 ? $this->cond_reglement_id :
'null');
1324 $sql .=
", ".($this->fk_account > 0 ? $this->fk_account :
'NULL');
1325 $sql .=
", ".(int) $this->fk_incoterms;
1326 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
1327 $sql .=
", ".(int) $this->fk_multicurrency;
1328 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1329 $sql .=
", ".(double) $this->multicurrency_tx;
1332 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1333 if ($this->
db->query($sql))
1335 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"commande_fournisseur");
1338 $num = count($this->lines);
1341 for ($i = 0; $i < $num; $i++)
1343 $this->special_code = $this->lines[$i]->special_code;
1347 $this->lines[$i]->desc,
1348 $this->lines[$i]->subprice,
1349 $this->lines[$i]->qty,
1350 $this->lines[$i]->tva_tx,
1351 $this->lines[$i]->localtax1_tx,
1352 $this->lines[$i]->localtax2_tx,
1353 $this->lines[$i]->fk_product,
1355 $this->lines[$i]->ref_fourn,
1356 $this->lines[$i]->remise_percent,
1359 $this->lines[$i]->product_type,
1360 $this->lines[$i]->info_bits,
1362 $this->lines[$i]->date_start,
1363 $this->lines[$i]->date_end,
1364 $this->lines[$i]->array_options,
1365 $this->lines[$i]->fk_unit
1369 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
1370 $this->
db->rollback();
1375 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur";
1376 $sql .=
" SET ref='(PROV".$this->id.
")'";
1377 $sql .=
" WHERE rowid=".$this->id;
1378 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1379 if ($this->
db->query($sql))
1384 $this->ref =
"(PROV".$this->id.
")";
1386 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects))
1388 $this->linked_objects = $this->linkedObjectsIds;
1392 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects))
1394 foreach ($this->linked_objects as $origin => $tmp_origin_id)
1396 if (is_array($tmp_origin_id))
1398 foreach ($tmp_origin_id as $origin_id)
1409 $origin_id = $tmp_origin_id;
1424 if ($result < 0) $error++;
1427 if (!$error && !$notrigger)
1430 $result = $this->
call_trigger(
'ORDER_SUPPLIER_CREATE', $user);
1433 $this->
db->rollback();
1439 $this->
db->commit();
1442 $this->error = $this->
db->lasterror();
1443 $this->
db->rollback();
1448 $this->error = $this->
db->lasterror();
1449 $this->
db->rollback();
1463 global $conf, $user, $hookmanager;
1470 foreach ($this->lines as $line)
1471 $line->fetch_optionals();
1474 $objFrom = clone $this;
1477 if (!empty($socid) && $socid != $this->socid)
1481 if ($objsoc->fetch($socid) > 0)
1483 $this->socid = $objsoc->id;
1484 $this->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1485 $this->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1486 $this->fk_project = 0;
1487 $this->fk_delivery_address = 0;
1494 $this->
statut = self::STATUS_DRAFT;
1497 $this->user_author_id = $user->id;
1498 $this->user_valid =
'';
1499 $this->date_creation =
'';
1500 $this->date_validation =
'';
1501 $this->ref_supplier =
'';
1502 $this->user_approve_id =
'';
1503 $this->user_approve_id2 =
'';
1504 $this->date_approve =
'';
1505 $this->date_approve2 =
'';
1508 $this->context[
'createfromclone'] =
'createfromclone';
1509 $result = $this->
create($user);
1510 if ($result < 0) $error++;
1515 if (is_object($hookmanager))
1517 $parameters = array(
'objFrom'=>$objFrom);
1519 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1520 if ($reshook < 0) $error++;
1524 unset($this->context[
'createfromclone']);
1529 $this->
db->commit();
1532 $this->
db->rollback();
1564 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)
1566 global $langs, $mysoc, $conf;
1568 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");
1569 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1571 if ($this->
statut == self::STATUS_DRAFT)
1573 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1576 if (empty($qty)) $qty = 0;
1577 if (!$info_bits) $info_bits = 0;
1578 if (empty($txtva)) $txtva = 0;
1579 if (empty($txlocaltax1)) $txlocaltax1 = 0;
1580 if (empty($txlocaltax2)) $txlocaltax2 = 0;
1581 if (empty($remise_percent)) $remise_percent = 0;
1583 $remise_percent =
price2num($remise_percent);
1586 $pu_ht_devise =
price2num($pu_ht_devise);
1588 if (!preg_match(
'/\((.*)\)/', $txtva)) {
1593 if ($price_base_type ==
'HT')
1599 $desc = trim($desc);
1602 if ($qty < 0 && !$fk_product)
1604 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Product"));
1607 if ($type < 0)
return -1;
1608 if ($date_start && $date_end && $date_start > $date_end) {
1609 $langs->load(
"errors");
1610 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
1617 $product_type = $type;
1620 if ($fk_product > 0) {
1621 if (!empty($conf->global->SUPPLIER_ORDER_WITH_PREDEFINED_PRICES_ONLY)) {
1623 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);
1625 if ($prod->fetch($fk_product) > 0) {
1626 $product_type = $prod->type;
1627 $label = $prod->label;
1631 $result = $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', (isset($this->fk_soc) ? $this->fk_soc : $this->socid));
1635 if ($result > 0 && ($origin ==
'commande' || $pu ===
''))
1637 $pu = $prod->fourn_pu;
1638 $ref_supplier = $prod->ref_supplier;
1640 if ($remise_percent == 0 && $prod->remise_percent != 0) $remise_percent = $prod->remise_percent;
1644 $langs->load(
"errors");
1645 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
1646 $this->
db->rollback();
1647 dol_syslog(get_class($this).
"::addline we did not found supplier price, so we can't guess unit price");
1654 $langs->load(
"errors");
1655 $this->error =
"Ref ".$prod->ref.
" ".$langs->trans(
"ErrorQtyTooLowForThisSupplier");
1656 $this->
db->rollback();
1657 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_DEBUG);
1662 $this->error = $prod->error;
1663 $this->
db->rollback();
1664 dol_syslog(get_class($this).
"::addline result=".$result.
" - ".$this->error, LOG_ERR);
1668 $this->error = $prod->error;
1669 $this->
db->rollback();
1675 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING)) {
1676 $prod =
new Product($this->
db, $fk_product);
1677 $prod->get_buyprice($fk_prod_fourn_price, $qty, $fk_product,
'none', ($this->fk_soc ? $this->fk_soc : $this->socid));
1678 if ($qty < $prod->packaging) {
1679 $qty = $prod->packaging;
1681 if (!empty($prod->packaging) && ($qty % $prod->packaging) > 0) {
1682 $coeff = intval($qty / $prod->packaging) + 1;
1683 $qty = $prod->packaging * $coeff;
1686 setEventMessage($langs->trans(
'QtyRecalculatedWithPackaging'),
'mesgs');
1690 if (!empty($conf->multicurrency->enabled) && $pu_ht_devise > 0) {
1698 if (preg_match(
'/\((.*)\)/', $txtva, $reg))
1700 $vat_src_code = $reg[1];
1701 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
1709 $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);
1711 $total_ht = $tabprice[0];
1712 $total_tva = $tabprice[1];
1713 $total_ttc = $tabprice[2];
1714 $total_localtax1 = $tabprice[9];
1715 $total_localtax2 = $tabprice[10];
1716 $pu = $pu_ht = $tabprice[3];
1719 $multicurrency_total_ht = $tabprice[16];
1720 $multicurrency_total_tva = $tabprice[17];
1721 $multicurrency_total_ttc = $tabprice[18];
1722 $pu_ht_devise = $tabprice[19];
1724 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
1725 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
1728 $rang = $rangmax + 1;
1733 $this->line->context = $this->context;
1735 $this->line->fk_commande = $this->id;
1736 $this->line->label = $label;
1737 $this->line->ref_fourn = $ref_supplier;
1738 $this->line->ref_supplier = $ref_supplier;
1739 $this->line->desc = $desc;
1740 $this->line->qty = $qty;
1741 $this->line->tva_tx = $txtva;
1742 $this->line->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0);
1743 $this->line->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0);
1744 $this->line->localtax1_type = $localtax1_type;
1745 $this->line->localtax2_type = $localtax2_type;
1746 $this->line->fk_product = $fk_product;
1747 $this->line->product_type = $product_type;
1748 $this->line->remise_percent = $remise_percent;
1749 $this->line->subprice = $pu_ht;
1750 $this->line->rang = $rang;
1751 $this->line->info_bits = $info_bits;
1753 $this->line->vat_src_code = $vat_src_code;
1754 $this->line->total_ht = $total_ht;
1755 $this->line->total_tva = $total_tva;
1756 $this->line->total_localtax1 = $total_localtax1;
1757 $this->line->total_localtax2 = $total_localtax2;
1758 $this->line->total_ttc = $total_ttc;
1759 $this->line->product_type = $type;
1760 $this->line->special_code = $this->special_code;
1761 $this->line->origin = $origin;
1762 $this->line->origin_id = $origin_id;
1763 $this->line->fk_unit = $fk_unit;
1765 $this->line->date_start = $date_start;
1766 $this->line->date_end = $date_end;
1769 $this->line->fk_multicurrency = $this->fk_multicurrency;
1770 $this->line->multicurrency_code = $this->multicurrency_code;
1771 $this->line->multicurrency_subprice = $pu_ht_devise;
1772 $this->line->multicurrency_total_ht = $multicurrency_total_ht;
1773 $this->line->multicurrency_total_tva = $multicurrency_total_tva;
1774 $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
1776 $this->line->subprice = $pu_ht;
1777 $this->line->price = $this->line->subprice;
1779 $this->line->remise_percent = $remise_percent;
1781 if (is_array($array_options) && count($array_options) > 0) {
1782 $this->line->array_options = $array_options;
1785 $result = $this->line->insert($notrigger);
1789 if (!empty($fk_parent_line)) $this->
line_order(
true,
'DESC');
1792 $result = $this->
update_price(1,
'auto', 0, $this->thirdparty);
1795 $this->
db->commit();
1796 return $this->line->id;
1798 $this->
db->rollback();
1802 $this->error = $this->line->error;
1803 $this->errors = $this->line->errors;
1804 dol_syslog(get_class($this).
"::addline error=".$this->error, LOG_ERR);
1805 $this->
db->rollback();
1828 public function dispatchProduct($user, $product, $qty, $entrepot, $price = 0, $comment =
'', $eatby =
'', $sellby =
'', $batch =
'', $fk_commandefourndet = 0, $notrigger = 0)
1830 global $conf, $langs;
1833 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
1838 $this->error =
'ErrorBadValueForParameterWarehouse';
1843 $this->error =
'ErrorBadValueForParameterQty';
1847 $dispatchstatus = 1;
1848 if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) $dispatchstatus = 0;
1852 if (($this->
statut == self::STATUS_ORDERSENT || $this->
statut == self::STATUS_RECEIVED_PARTIALLY || $this->
statut == self::STATUS_RECEIVED_COMPLETELY))
1856 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch";
1857 $sql .=
" (fk_commande, fk_product, qty, fk_entrepot, fk_user, datec, fk_commandefourndet, status, comment, eatby, sellby, batch) VALUES";
1858 $sql .=
" ('".$this->id.
"','".$product.
"','".$qty.
"',".($entrepot > 0 ?
"'".$entrepot.
"'" :
"null").
",'".$user->id.
"','".$this->db->idate($now).
"','".$fk_commandefourndet.
"', ".$dispatchstatus.
", '".$this->
db->escape($comment).
"', ";
1859 $sql .= ($eatby ?
"'".$this->db->idate($eatby).
"'" :
"null").
", ".($sellby ?
"'".$this->
db->idate($sellby).
"'" :
"null").
", ".($batch ?
"'".$this->
db->escape($batch).
"'" :
"null");
1862 dol_syslog(get_class($this).
"::dispatchProduct", LOG_DEBUG);
1868 global $conf, $langs, $user;
1870 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_DISPATCH', $user);
1878 $this->error = $this->
db->lasterror();
1883 if (!$error && $entrepot > 0 && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER))
1889 $mouv->origin = &$this;
1890 $result = $mouv->reception($user, $product, $entrepot, $qty, $price, $comment, $eatby, $sellby, $batch);
1893 $this->error = $mouv->error;
1894 $this->errors = $mouv->errors;
1895 dol_syslog(get_class($this).
"::dispatchProduct ".$this->error.
" ".join(
',', $this->errors), LOG_ERR);
1903 $this->
db->commit();
1906 $this->
db->rollback();
1910 $this->error =
'BadStatusForObject';
1928 if ($line->fetch($idline) <= 0)
1933 if ($line->delete($notrigger) > 0)
1938 $this->error = $line->error;
1939 $this->errors = $line->errors;
1954 public function delete(
User $user, $notrigger = 0)
1956 global $langs, $conf;
1957 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1963 if (empty($notrigger))
1966 $result = $this->
call_trigger(
'ORDER_SUPPLIER_DELETE', $user);
1969 $this->errors[] =
'ErrorWhenRunningTrigger';
1970 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
1971 $this->
db->rollback();
1977 $main = MAIN_DB_PREFIX.
'commande_fournisseurdet';
1978 $ef = $main.
"_extrafields";
1979 $sql =
"DELETE FROM $ef WHERE fk_object IN (SELECT rowid FROM $main WHERE fk_commande = ".$this->id.
")";
1980 dol_syslog(get_class($this).
"::delete extrafields lines", LOG_DEBUG);
1981 if (!$this->
db->query($sql))
1983 $this->error = $this->
db->lasterror();
1984 $this->errors[] = $this->
db->lasterror();
1988 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"commande_fournisseurdet WHERE fk_commande =".$this->id;
1989 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1990 if (!$this->
db->query($sql))
1992 $this->error = $this->
db->lasterror();
1993 $this->errors[] = $this->
db->lasterror();
1997 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"commande_fournisseur WHERE rowid =".$this->id;
1998 dol_syslog(get_class($this).
"::delete", LOG_DEBUG);
1999 if (
$resql = $this->
db->query($sql))
2001 if ($this->
db->affected_rows(
$resql) < 1)
2003 $this->error = $this->
db->lasterror();
2004 $this->errors[] = $this->
db->lasterror();
2008 $this->error = $this->
db->lasterror();
2009 $this->errors[] = $this->
db->lasterror();
2019 $this->error =
'FailToDeleteExtraFields';
2020 $this->errors[] =
'FailToDeleteExtraFields';
2022 dol_syslog(get_class($this).
"::delete error -4 ".$this->error, LOG_ERR);
2029 $this->error =
'FailToDeleteObjectLinked';
2030 $this->errors[] =
'FailToDeleteObjectLinked';
2041 if ($conf->fournisseur->commande->dir_output)
2043 $dir = $conf->fournisseur->commande->dir_output.
"/".$ref;
2044 $file = $dir.
"/".$ref.
".pdf";
2045 if (file_exists($file))
2049 $this->error =
'ErrorFailToDeleteFile';
2050 $this->errors[] =
'ErrorFailToDeleteFile';
2054 if (file_exists($dir))
2059 $this->error =
'ErrorFailToDeleteDir';
2060 $this->errors[] =
'ErrorFailToDeleteDir';
2069 dol_syslog(get_class($this).
"::delete $this->id by $user->id", LOG_DEBUG);
2070 $this->
db->commit();
2073 dol_syslog(get_class($this).
"::delete ".$this->error, LOG_ERR);
2074 $this->
db->rollback();
2088 $sql =
"SELECT rowid, libelle";
2089 $sql .=
" FROM ".MAIN_DB_PREFIX.
"c_input_method";
2090 $sql .=
" WHERE active = 1";
2096 $num = $this->
db->num_rows(
$resql);
2097 $this->methodes_commande = array();
2100 $row = $this->
db->fetch_row(
$resql);
2102 $this->methodes_commande[$row[0]] = $row[1];
2125 $sql =
"SELECT p.ref, p.label,";
2126 $sql .=
" e.rowid as warehouse_id, e.ref as entrepot,";
2127 $sql .=
" cfd.rowid as dispatchedlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status";
2128 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product as p,";
2129 $sql .=
" ".MAIN_DB_PREFIX.
"commande_fournisseur_dispatch as cfd";
2130 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"entrepot as e ON cfd.fk_entrepot = e.rowid";
2131 $sql .=
" WHERE cfd.fk_commande = ".$this->id;
2132 $sql .=
" AND cfd.fk_product = p.rowid";
2133 if ($status >= 0) $sql .=
" AND cfd.status = ".$status;
2134 $sql .=
" ORDER BY cfd.rowid ASC";
2139 $num = $this->
db->num_rows(
$resql);
2144 $objp = $this->
db->fetch_object(
$resql);
2148 'id' => $objp->dispatchedlineid,
2149 'productid' => $objp->fk_product,
2150 'warehouseid' => $objp->warehouse_id,
2151 'qty' => $objp->qty,
2157 }
else dol_print_error($this->
db,
'Failed to execute request to get dispatched lines');
2176 global $conf, $langs;
2183 if ($user->rights->fournisseur->commande->receptionner)
2186 if ($type ==
'par') $statut = self::STATUS_RECEIVED_PARTIALLY;
2187 elseif ($type ==
'tot') $statut = self::STATUS_RECEIVED_COMPLETELY;
2188 elseif ($type ==
'nev') $statut = self::STATUS_CANCELED_AFTER_ORDER;
2189 elseif ($type ==
'can') $statut = self::STATUS_CANCELED_AFTER_ORDER;
2192 dol_syslog(get_class($this).
"::Livraison Error -2", LOG_ERR);
2197 if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS))
2200 if (!$error && ($type ==
'tot'))
2203 if (count($dispatchedlinearray) > 0)
2207 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove';
2208 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionToApprove', LOG_DEBUG);
2211 if (!$error && !empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS_NEED_APPROVE) && ($type ==
'tot'))
2214 if (count($dispatchedlinearray) > 0)
2218 $this->errors[] =
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied';
2219 dol_syslog(
'ErrorCantSetReceptionToTotalDoneWithReceptionDenied', LOG_DEBUG);
2230 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur";
2231 $sql .=
" SET fk_statut = ".$statut;
2232 $sql .=
" WHERE rowid = ".$this->id;
2233 $sql .=
" AND fk_statut IN (".self::STATUS_ORDERSENT.
",".self::STATUS_RECEIVED_PARTIALLY.
")";
2235 dol_syslog(get_class($this).
"::Livraison", LOG_DEBUG);
2240 $old_statut = $this->statut;
2242 $this->actionmsg2 = $comment;
2245 $result_trigger = $this->
call_trigger(
'ORDER_SUPPLIER_RECEIVE', $user);
2246 if ($result_trigger < 0) $error++;
2251 $this->
db->commit();
2253 $this->
statut = $old_statut;
2254 $this->
db->rollback();
2255 $this->error = $this->
db->lasterror();
2259 $this->
db->rollback();
2260 $this->error = $this->
db->lasterror();
2265 $this->error = $langs->trans(
'NotAuthorized');
2266 $this->errors[] = $langs->trans(
'NotAuthorized');
2267 dol_syslog(get_class($this).
"::Livraison Not Authorized");
2299 if ($user->rights->fournisseur->commande->creer)
2305 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur";
2306 $sql .=
" SET date_livraison = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2307 $sql .=
" WHERE rowid = ".$this->id;
2313 $this->errors[] = $this->
db->error();
2319 $this->oldcopy = clone $this;
2320 $this->date_livraison = $delivery_date;
2321 $this->delivery_date = $delivery_date;
2324 if (!$notrigger && empty($error))
2327 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2328 if ($result < 0) $error++;
2334 $this->
db->commit();
2337 foreach ($this->errors as $errmsg)
2339 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2340 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2342 $this->
db->rollback();
2362 if ($user->rights->fournisseur->commande->creer)
2368 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"commande_fournisseur";
2369 $sql .=
" SET fk_projet = ".($id_projet > 0 ? (int) $id_projet :
'null');
2370 $sql .=
" WHERE rowid = ".$this->id;
2376 $this->errors[] = $this->
db->error();
2382 $this->oldcopy = clone $this;
2383 $this->fk_projet = $id_projet;
2384 $this->fk_project = $id_projet;
2387 if (!$notrigger && empty($error))
2390 $result = $this->
call_trigger(
'ORDER_SUPPLIER_MODIFY', $user);
2391 if ($result < 0) $error++;
2397 $this->
db->commit();
2400 foreach ($this->errors as $errmsg)
2402 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2403 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2405 $this->
db->rollback();
2424 $comclient->fetch($comclientid);
2428 $this->lines = array();
2430 $num = count($comclient->lines);
2431 for ($i = 0; $i < $num; $i++)
2436 if ($prod->fetch($comclient->lines[$i]->fk_product) > 0)
2438 $label = $prod->label;
2442 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"commande_fournisseurdet";
2443 $sql .=
" (fk_commande, label, description, fk_product, price, qty, tva_tx, localtax1_tx, localtax2_tx, remise_percent, subprice, remise, ref)";
2444 $sql .=
" VALUES (".$idc.
", '".$this->
db->escape($label).
"', ".$this->
db->escape($comclient->lines[$i]->desc);
2445 $sql .=
",".$comclient->lines[$i]->fk_product.
", ".
price2num($comclient->lines[$i]->price);
2446 $sql .=
", ".$comclient->lines[$i]->qty.
", ".$comclient->lines[$i]->tva_tx.
", ".$comclient->lines[$i]->localtax1_tx.
", ".$comclient->lines[$i]->localtax2_tx.
", ".$comclient->lines[$i]->remise_percent;
2447 $sql .=
", '".price2num($comclient->lines[$i]->subprice).
"','0', '".$this->
db->escape($ref).
"');";
2448 if ($this->
db->query($sql))
2466 global $conf, $langs;
2471 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'commande_fournisseur';
2472 $sql .=
' SET fk_statut='.$status;
2473 $sql .=
' WHERE rowid = '.$this->id;
2475 dol_syslog(get_class($this).
"::setStatus", LOG_DEBUG);
2480 $triggerName = array();
2481 $triggerName[0] =
'DRAFT';
2482 $triggerName[1] =
'VALIDATED';
2483 $triggerName[2] =
'APPROVED';
2484 $triggerName[3] =
'ORDERED';
2485 $triggerName[4] =
'RECEIVED_PARTIALLY';
2486 $triggerName[5] =
'RECEIVED_COMPLETELY';
2487 $triggerName[6] =
'CANCELED';
2488 $triggerName[7] =
'CANCELED';
2489 $triggerName[9] =
'REFUSED';
2492 $result = $this->
call_trigger(
"ORDER_SUPPLIER_STATUS_".$triggerName[$status], $user);
2493 if ($result < 0) { $error++; }
2497 $this->error = $this->
db->lasterror();
2498 dol_syslog(get_class($this).
"::setStatus ".$this->error);
2504 $this->
db->commit();
2507 $this->
db->rollback();
2535 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 =
'')
2537 global $mysoc, $conf, $langs;
2538 dol_syslog(get_class($this).
"::updateline $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $type, $fk_unit");
2539 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2543 if ($this->brouillon)
2546 if (empty($qty)) $qty = 0;
2547 if (empty($info_bits)) $info_bits = 0;
2548 if (empty($txtva)) $txtva = 0;
2549 if (empty($txlocaltax1)) $txlocaltax1 = 0;
2550 if (empty($txlocaltax2)) $txlocaltax2 = 0;
2551 if (empty($remise)) $remise = 0;
2552 if (empty($remise_percent)) $remise_percent = 0;
2554 $remise_percent =
price2num($remise_percent);
2556 if (!$qty) $qty = 1;
2558 $pu_ht_devise =
price2num($pu_ht_devise);
2559 if (!preg_match(
'/\((.*)\)/', $txtva)) {
2566 if ($type < 0)
return -1;
2567 if ($date_start && $date_end && $date_start > $date_end) {
2568 $langs->load(
"errors");
2569 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
2585 if (preg_match(
'/\((.*)\)/', $txtva, $reg))
2587 $vat_src_code = $reg[1];
2588 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
2591 $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);
2592 $total_ht = $tabprice[0];
2593 $total_tva = $tabprice[1];
2594 $total_ttc = $tabprice[2];
2595 $total_localtax1 = $tabprice[9];
2596 $total_localtax2 = $tabprice[10];
2597 $pu_ht = $tabprice[3];
2598 $pu_tva = $tabprice[4];
2599 $pu_ttc = $tabprice[5];
2602 $multicurrency_total_ht = $tabprice[16];
2603 $multicurrency_total_tva = $tabprice[17];
2604 $multicurrency_total_ttc = $tabprice[18];
2605 $pu_ht_devise = $tabprice[19];
2607 $localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2608 $localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2612 $this->line->fetch($rowid);
2614 $oldline = clone $this->line;
2615 $this->line->oldline = $oldline;
2617 $this->line->context = $this->context;
2619 $this->line->fk_commande = $this->id;
2621 $this->line->desc = $desc;
2624 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING))
2626 if ($qty < $this->line->packaging)
2628 $qty = $this->line->packaging;
2630 if (($qty % $this->line->packaging) > 0)
2632 $coeff = intval($qty / $this->line->packaging) + 1;
2633 $qty = $this->line->packaging * $coeff;
2634 setEventMessage($langs->trans(
'QtyRecalculatedWithPackaging'),
'mesgs');
2639 $this->line->qty = $qty;
2640 $this->line->ref_supplier = $ref_supplier;
2642 $this->line->vat_src_code = $vat_src_code;
2643 $this->line->tva_tx = $txtva;
2644 $this->line->localtax1_tx = $txlocaltax1;
2645 $this->line->localtax2_tx = $txlocaltax2;
2646 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
2647 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
2648 $this->line->remise_percent = $remise_percent;
2649 $this->line->subprice = $pu_ht;
2650 $this->line->rang = $this->rang;
2651 $this->line->info_bits = $info_bits;
2652 $this->line->total_ht = $total_ht;
2653 $this->line->total_tva = $total_tva;
2654 $this->line->total_localtax1 = $total_localtax1;
2655 $this->line->total_localtax2 = $total_localtax2;
2656 $this->line->total_ttc = $total_ttc;
2657 $this->line->product_type = $type;
2658 $this->line->special_code = $this->special_code;
2659 $this->line->origin = $this->origin;
2660 $this->line->fk_unit = $fk_unit;
2662 $this->line->date_start = $date_start;
2663 $this->line->date_end = $date_end;
2666 $this->line->fk_multicurrency = $this->fk_multicurrency;
2667 $this->line->multicurrency_code = $this->multicurrency_code;
2668 $this->line->multicurrency_subprice = $pu_ht_devise;
2669 $this->line->multicurrency_total_ht = $multicurrency_total_ht;
2670 $this->line->multicurrency_total_tva = $multicurrency_total_tva;
2671 $this->line->multicurrency_total_ttc = $multicurrency_total_ttc;
2673 $this->line->subprice = $pu_ht;
2674 $this->line->price = $this->line->subprice;
2676 $this->line->remise_percent = $remise_percent;
2678 if (is_array($array_options) && count($array_options) > 0) {
2680 foreach ($array_options as $key => $value) {
2681 $this->line->array_options[$key] = $array_options[$key];
2685 $result = $this->line->update($notrigger);
2692 $this->
db->commit();
2695 $this->error = $this->
db->lasterror();
2696 $this->
db->rollback();
2700 $this->error =
"Order status makes operation forbidden";
2701 dol_syslog(get_class($this).
"::updateline ".$this->error, LOG_ERR);
2716 global $user, $langs, $conf;
2718 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
2720 dol_syslog(get_class($this).
"::initAsSpecimen");
2727 $sql =
"SELECT rowid";
2728 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
2729 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
2730 $sql .= $this->
db->order(
"rowid",
"ASC");
2731 $sql .= $this->
db->plimit(1);
2735 $obj = $this->
db->fetch_object(
$resql);
2736 $prodid = $obj->rowid;
2741 $this->ref =
'SPECIMEN';
2742 $this->specimen = 1;
2745 $this->date_commande = $now;
2746 $this->date_lim_reglement = $this->date + 3600 * 24 * 30;
2747 $this->cond_reglement_code =
'RECEP';
2748 $this->mode_reglement_code =
'CHQ';
2750 $this->note_public =
'This is a comment (public)';
2751 $this->note_private =
'This is a comment (private)';
2753 $this->multicurrency_tx = 1;
2754 $this->multicurrency_code = $conf->currency;
2761 while ($xnbp < $nbp)
2764 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
2766 $line->subprice = 100;
2768 $line->tva_tx = 19.6;
2769 $line->localtax1_tx = 0;
2770 $line->localtax2_tx = 0;
2773 $line->total_ht = 50;
2774 $line->total_ttc = 59.8;
2775 $line->total_tva = 9.8;
2776 $line->remise_percent = 50;
2778 $line->total_ht = 100;
2779 $line->total_ttc = 119.6;
2780 $line->total_tva = 19.6;
2781 $line->remise_percent = 00;
2783 $line->fk_product = $prodid;
2785 $this->lines[$xnbp] = $line;
2787 $this->total_ht += $line->total_ht;
2788 $this->total_tva += $line->total_tva;
2789 $this->total_ttc += $line->total_ttc;
2803 $sql =
'SELECT c.rowid, date_creation as datec, tms as datem, date_valid as date_validation, date_approve as datea, date_approve2 as datea2,';
2804 $sql .=
' fk_user_author, fk_user_modif, fk_user_valid, fk_user_approve, fk_user_approve2';
2805 $sql .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseur as c';
2806 $sql .=
' WHERE c.rowid = '.$id;
2808 $result = $this->
db->query($sql);
2811 if ($this->
db->num_rows($result))
2813 $obj = $this->
db->fetch_object($result);
2814 $this->
id = $obj->rowid;
2815 if ($obj->fk_user_author) $this->user_creation_id = $obj->fk_user_author;
2816 if ($obj->fk_user_valid) $this->user_validation_id = $obj->fk_user_valid;
2817 if ($obj->fk_user_modif) $this->user_modification_id = $obj->fk_user_modif;
2818 if ($obj->fk_user_approve) $this->user_approve_id = $obj->fk_user_approve;
2819 if ($obj->fk_user_approve2) $this->user_approve_id2 = $obj->fk_user_approve2;
2821 $this->date_creation = $this->
db->idate($obj->datec);
2822 $this->date_modification = $this->
db->idate($obj->datem);
2823 $this->date_approve = $this->
db->idate($obj->datea);
2824 $this->date_approve2 = $this->
db->idate($obj->datea2);
2825 $this->date_validation = $this->
db->idate($obj->date_validation);
2827 $this->
db->free($result);
2842 global $conf, $user;
2844 $this->nb = array();
2847 $sql =
"SELECT count(co.rowid) as nb";
2848 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseur as co";
2849 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON co.fk_soc = s.rowid";
2850 if (!$user->rights->societe->client->voir && !$user->socid)
2852 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
2853 $sql .=
" WHERE sc.fk_user = ".$user->id;
2856 $sql .=
" ".$clause.
" co.entity = ".$conf->entity;
2861 while ($obj = $this->
db->fetch_object(
$resql))
2863 $this->nb[
"supplier_orders"] = $obj->nb;
2869 $this->error = $this->
db->error();
2885 global $conf, $langs;
2889 $sql =
"SELECT c.rowid, c.date_creation as datec, c.date_commande, c.fk_statut, c.date_livraison as delivery_date";
2890 $sql .=
" FROM ".MAIN_DB_PREFIX.
"commande_fournisseur as c";
2891 if (!$user->rights->societe->client->voir && !$user->socid)
2893 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON c.fk_soc = sc.fk_soc";
2894 $sql .=
" WHERE sc.fk_user = ".$user->id;
2897 $sql .= $clause.
" c.entity = ".$conf->entity;
2898 if ($mode ===
'awaiting') {
2899 $sql .=
" AND c.fk_statut IN (".self::STATUS_ORDERSENT.
", ".self::STATUS_RECEIVED_PARTIALLY.
")";
2901 $sql .=
" AND c.fk_statut IN (".self::STATUS_VALIDATED.
", ".self::STATUS_ACCEPTED.
")";
2903 if ($user->socid) $sql .=
" AND c.fk_soc = ".$user->socid;
2911 $response->warning_delay = $conf->commande->fournisseur->warning_delay / 60 / 60 / 24;
2912 $response->label = $langs->trans(
"SuppliersOrdersToProcess");
2913 $response->labelShort = $langs->trans(
"Opened");
2914 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?statut=1,2&mainmenu=commercial&leftmenu=orders_suppliers';
2917 if ($mode ===
'awaiting') {
2918 $response->label = $langs->trans(
"SuppliersOrdersAwaitingReception");
2919 $response->labelShort = $langs->trans(
"AwaitingReception");
2920 $response->url = DOL_URL_ROOT.
'/fourn/commande/list.php?statut=3,4&mainmenu=commercial&leftmenu=orders_suppliers';
2923 while ($obj = $this->
db->fetch_object(
$resql))
2925 $response->nbtodo++;
2927 $commandestatic->delivery_date = $this->
db->jdate($obj->delivery_date);
2928 $commandestatic->date_commande = $this->
db->jdate($obj->date_commande);
2929 $commandestatic->statut = $obj->fk_statut;
2931 if ($commandestatic->hasDelay()) {
2932 $response->nbtodolate++;
2938 $this->error = $this->
db->error();
2953 if ($this->methode_commande_id > 0)
2955 $sql =
"SELECT rowid, code, libelle as label";
2956 $sql .=
" FROM ".MAIN_DB_PREFIX.
'c_input_method';
2957 $sql .=
" WHERE active=1 AND rowid = ".$this->db->escape($this->methode_commande_id);
2964 $obj = $this->
db->fetch_object(
$resql);
2966 $string = $langs->trans($obj->code);
2967 if ($string == $obj->code)
2969 $string = $obj->label !=
'-' ? $obj->label :
'';
2990 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
2992 global $conf, $langs;
2994 $langs->load(
"suppliers");
2995 $outputlangs->load(
"products");
2998 $modele =
'muscadet';
3000 if ($this->model_pdf) {
3001 $modele = $this->model_pdf;
3002 } elseif (!empty($conf->global->COMMANDE_SUPPLIER_ADDON_PDF)) {
3003 $modele = $conf->global->COMMANDE_SUPPLIER_ADDON_PDF;
3007 $modelpath =
"core/modules/supplier_order/doc/";
3009 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3020 if (empty($this->lines))
return '';
3025 foreach ($this->lines as $line)
3027 if ($line->fk_product > 0)
3029 $idp = $obj->find_min_price_product_fournisseur($line->fk_product, $line->qty);
3033 if ($obj->delivery_time_days > $nb) $nb = $obj->delivery_time_days;
3038 if ($nb === 0)
return '';
3039 else return $nb.
' '.$langs->trans(
'Days');
3050 return $user->rights->fournisseur->commande;
3065 'commande_fournisseur'
3082 if (empty($this->delivery_date) && !empty($this->date_livraison)) $this->delivery_date = $this->date_livraison;
3084 if ($this->
statut == self::STATUS_ORDERSENT || $this->
statut == self::STATUS_RECEIVED_PARTIALLY) {
3086 if (!empty($this->delivery_date)) {
3087 $date_to_test = $this->delivery_date;
3088 return $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay);
3096 $date_to_test = $this->date_commande;
3098 return ($this->
statut > 0 && $this->
statut < 5) && $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay);
3111 global $conf, $langs;
3113 if (empty($this->delivery_date) && !empty($this->date_livraison)) $this->delivery_date = $this->date_livraison;
3117 if ($this->
statut == self::STATUS_ORDERSENT || $this->
statut == self::STATUS_RECEIVED_PARTIALLY) {
3118 if (!empty($this->delivery_date)) {
3119 $text = $langs->trans(
"DeliveryDate").
' '.
dol_print_date($this->delivery_date,
'day');
3121 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3124 $text = $langs->trans(
"OrderDate").
' '.
dol_print_date($this->date_commande,
'day');
3127 $text .=
' '.($conf->commande->fournisseur->warning_delay > 0 ?
'+' :
'-').
' '.round(abs($conf->commande->fournisseur->warning_delay) / 3600 / 24, 1).
' '.$langs->trans(
"days").
' < '.$langs->trans(
"Today");
3144 global $conf, $langs;
3146 if (!empty($conf->fournisseur->enabled) && empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) || !empty($conf->supplier_order->enabled))
3148 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.commande.dispatch.class.php';
3150 $qtydelivered = array();
3151 $qtywished = array();
3154 $filter = array(
't.fk_commande'=>$this->
id);
3155 if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) {
3156 $filter[
't.status'] = 1;
3159 $ret = $supplierorderdispatch->fetchAll(
'',
'', 0, 0, $filter);
3161 $this->error = $supplierorderdispatch->error; $this->errors = $supplierorderdispatch->errors;
3164 if (is_array($supplierorderdispatch->lines) && count($supplierorderdispatch->lines) > 0) {
3165 require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
3169 foreach ($supplierorderdispatch->lines as $line) {
3170 $qtydelivered[$line->fk_product] += $line->qty;
3172 foreach ($this->lines as $line) {
3174 if (empty($conf->global->STOCK_SUPPORTS_SERVICES) && $line->product_type > 0)
continue;
3175 $qtywished[$line->fk_product] += $line->qty;
3179 $diff_array = array_diff_assoc($qtydelivered, $qtywished);
3180 $keysinwishednotindelivered = array_diff(array_keys($qtywished), array_keys($qtydelivered));
3181 $keysindeliverednotinwished = array_diff(array_keys($qtydelivered), array_keys($qtywished));
3190 if (count($diff_array) == 0 && count($keysinwishednotindelivered) == 0 && count($keysindeliverednotinwished) == 0)
3192 if ($closeopenorder)
3195 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3203 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3209 } elseif (!empty($conf->global->SUPPLIER_ORDER_MORE_THAN_WISHED)) {
3214 if (count($diff_array) > 0)
3219 foreach ($diff_array as $key => $value)
3222 if ($qtydelivered[$key] >= $qtywished[$key])
3230 if ($close == count($diff_array)) {
3232 if ($closeopenorder) {
3233 $ret = $this->
Livraison($user, $date_liv,
'tot', $comment);
3240 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3248 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3256 $ret = $this->
Livraison($user, $date_liv,
'par', $comment);
3278 $this->receptions = array();
3280 $sql =
'SELECT cd.rowid, cd.fk_product,';
3281 $sql .=
' sum(cfd.qty) as qty';
3282 $sql .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseur_dispatch as cfd,';
3283 if ($filtre_statut >= 0) $sql .=
' '.MAIN_DB_PREFIX.
'reception as e,';
3284 $sql .=
' '.MAIN_DB_PREFIX.
'commande_fournisseurdet as cd';
3286 if ($filtre_statut >= 0) $sql .=
' cfd.fk_reception = e.rowid AND';
3287 $sql .=
' cfd.fk_commandefourndet = cd.rowid';
3288 $sql .=
' AND cd.fk_commande ='.$this->id;
3289 if ($this->fk_product > 0) $sql .=
' AND cd.fk_product = '.$this->fk_product;
3290 if ($filtre_statut >= 0) $sql .=
' AND e.fk_statut >= '.$filtre_statut;
3291 $sql .=
' GROUP BY cd.rowid, cd.fk_product';
3294 dol_syslog(get_class($this).
"::loadReceptions", LOG_DEBUG);
3295 $result = $this->
db->query($sql);
3298 $num = $this->
db->num_rows($result);
3302 $obj = $this->
db->fetch_object($result);
3303 empty($this->receptions[$obj->rowid]) ? $this->receptions[$obj->rowid] = $obj->qty : $this->receptions[$obj->rowid] += $obj->qty;
3310 $this->error = $this->
db->lasterror();
3326 public $element =
'commande_fournisseurdet';
3331 public $table_element =
'commande_fournisseurdet';
3339 public $fk_commande;
3345 public $fk_parent_line;
3353 public $special_code = 0;
3370 public $ref_supplier;
3394 $sql =
'SELECT cd.rowid, cd.fk_commande, cd.fk_product, cd.product_type, cd.description, cd.qty, cd.tva_tx, cd.special_code,';
3395 $sql .=
' cd.localtax1_tx, cd.localtax2_tx, cd.localtax1_type, cd.localtax2_type, cd.ref,';
3396 $sql .=
' cd.remise, cd.remise_percent, cd.subprice,';
3397 $sql .=
' cd.info_bits, cd.total_ht, cd.total_tva, cd.total_ttc,';
3398 $sql .=
' cd.total_localtax1, cd.total_localtax2,';
3399 $sql .=
' p.ref as product_ref, p.label as product_label, p.description as product_desc,';
3400 $sql .=
' cd.date_start, cd.date_end, cd.fk_unit,';
3401 $sql .=
' cd.multicurrency_subprice, cd.multicurrency_total_ht, cd.multicurrency_total_tva, cd.multicurrency_total_ttc';
3402 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING))
3403 $sql .=
", pfp.rowid as fk_pfp, pfp.packaging";
3404 $sql .=
' FROM '.MAIN_DB_PREFIX.
'commande_fournisseurdet as cd';
3405 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON cd.fk_product = p.rowid';
3406 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING))
3407 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"product_fournisseur_price as pfp ON cd.fk_product = pfp.fk_product and cd.ref = pfp.ref_fourn";
3408 $sql .=
' WHERE cd.rowid = '.$rowid;
3409 $result = $this->
db->query($sql);
3412 $objp = $this->
db->fetch_object($result);
3416 $this->
rowid = $objp->rowid;
3417 $this->
id = $objp->rowid;
3418 $this->fk_commande = $objp->fk_commande;
3419 $this->desc = $objp->description;
3420 $this->qty = $objp->qty;
3421 $this->ref_fourn = $objp->ref;
3422 $this->ref_supplier = $objp->ref;
3423 $this->subprice = $objp->subprice;
3424 $this->tva_tx = $objp->tva_tx;
3425 $this->localtax1_tx = $objp->localtax1_tx;
3426 $this->localtax2_tx = $objp->localtax2_tx;
3427 $this->localtax1_type = $objp->localtax1_type;
3428 $this->localtax2_type = $objp->localtax2_type;
3429 $this->remise = $objp->remise;
3430 $this->remise_percent = $objp->remise_percent;
3431 $this->fk_product = $objp->fk_product;
3432 $this->info_bits = $objp->info_bits;
3433 $this->total_ht = $objp->total_ht;
3434 $this->total_tva = $objp->total_tva;
3435 $this->total_localtax1 = $objp->total_localtax1;
3436 $this->total_localtax2 = $objp->total_localtax2;
3437 $this->total_ttc = $objp->total_ttc;
3438 $this->product_type = $objp->product_type;
3439 $this->special_code = $objp->special_code;
3441 $this->ref = $objp->product_ref;
3443 $this->product_ref = $objp->product_ref;
3444 $this->product_label = $objp->product_label;
3445 $this->product_desc = $objp->product_desc;
3446 if (!empty($conf->global->PRODUCT_USE_SUPPLIER_PACKAGING))
3448 $this->packaging = $objp->packaging;
3449 $this->fk_fournprice = $objp->fk_pfp;
3452 $this->date_start = $this->
db->jdate($objp->date_start);
3453 $this->date_end = $this->
db->jdate($objp->date_end);
3454 $this->fk_unit = $objp->fk_unit;
3456 $this->multicurrency_subprice = $objp->multicurrency_subprice;
3457 $this->multicurrency_total_ht = $objp->multicurrency_total_ht;
3458 $this->multicurrency_total_tva = $objp->multicurrency_total_tva;
3459 $this->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
3463 $this->
db->free($result);
3466 $this->error =
'Supplier order line with id='.$rowid.
' not found';
3467 dol_syslog(get_class($this).
"::fetch Error ".$this->error, LOG_ERR);
3484 global $conf, $user;
3488 dol_syslog(get_class($this).
"::insert rang=".$this->rang);
3491 if (empty($this->tva_tx)) $this->tva_tx = 0;
3492 if (empty($this->localtax1_tx)) $this->localtax1_tx = 0;
3493 if (empty($this->localtax2_tx)) $this->localtax2_tx = 0;
3494 if (empty($this->localtax1_type)) $this->localtax1_type =
'0';
3495 if (empty($this->localtax2_type)) $this->localtax2_type =
'0';
3496 if (empty($this->total_localtax1)) $this->total_localtax1 = 0;
3497 if (empty($this->total_localtax2)) $this->total_localtax2 = 0;
3498 if (empty($this->rang)) $this->rang = 0;
3499 if (empty($this->remise)) $this->remise = 0;
3500 if (empty($this->remise_percent)) $this->remise_percent = 0;
3501 if (empty($this->info_bits)) $this->info_bits = 0;
3502 if (empty($this->special_code)) $this->special_code = 0;
3503 if (empty($this->fk_parent_line)) $this->fk_parent_line = 0;
3504 if (empty($this->pa_ht)) $this->pa_ht = 0;
3508 if (empty($this->fk_multicurrency))
3510 $this->multicurrency_code = $conf->currency;
3511 $this->fk_multicurrency = 0;
3512 $this->multicurrency_tx = 1;
3516 if ($this->product_type < 0)
return -1;
3521 $sql =
'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element;
3522 $sql .=
" (fk_commande, label, description, date_start, date_end,";
3523 $sql .=
" fk_product, product_type, special_code, rang,";
3524 $sql .=
" qty, vat_src_code, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, remise_percent, subprice, ref,";
3525 $sql .=
" total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_unit,";
3526 $sql .=
" fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc";
3528 $sql .=
" VALUES (".$this->fk_commande.
", '".$this->
db->escape($this->label).
"','".$this->
db->escape($this->desc).
"',";
3529 $sql .=
" ".($this->date_start ?
"'".$this->db->idate($this->date_start).
"'" :
"null").
",";
3530 $sql .=
" ".($this->date_end ?
"'".$this->db->idate($this->date_end).
"'" :
"null").
",";
3531 if ($this->fk_product) { $sql .= $this->fk_product.
","; }
else { $sql .=
"null,"; }
3532 $sql .=
"'".$this->db->escape($this->product_type).
"',";
3533 $sql .=
"'".$this->db->escape($this->special_code).
"',";
3534 $sql .=
"'".$this->db->escape($this->rang).
"',";
3535 $sql .=
"'".$this->db->escape($this->qty).
"', ";
3536 $sql .=
" ".(empty($this->vat_src_code) ?
"''" :
"'".$this->db->escape($this->vat_src_code).
"'").
",";
3537 $sql .=
" ".$this->tva_tx.
", ";
3538 $sql .=
" ".$this->localtax1_tx.
",";
3539 $sql .=
" ".$this->localtax2_tx.
",";
3540 $sql .=
" '".$this->db->escape($this->localtax1_type).
"',";
3541 $sql .=
" '".$this->db->escape($this->localtax2_type).
"',";
3542 $sql .=
" ".$this->remise_percent.
", ".
price2num($this->subprice,
'MU').
", '".$this->
db->escape($this->ref_supplier).
"',";
3543 $sql .=
" ".price2num($this->total_ht).
",";
3544 $sql .=
" ".price2num($this->total_tva).
",";
3545 $sql .=
" ".price2num($this->total_localtax1).
",";
3546 $sql .=
" ".price2num($this->total_localtax2).
",";
3547 $sql .=
" ".price2num($this->total_ttc).
",";
3548 $sql .= ($this->fk_unit ?
"'".$this->db->escape($this->fk_unit).
"'" :
"null");
3549 $sql .=
", ".($this->fk_multicurrency ? $this->fk_multicurrency :
"null");
3550 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
3551 $sql .=
", ".($this->multicurrency_subprice ?
price2num($this->multicurrency_subprice) :
'0');
3552 $sql .=
", ".($this->multicurrency_total_ht ?
price2num($this->multicurrency_total_ht) :
'0');
3553 $sql .=
", ".($this->multicurrency_total_tva ?
price2num($this->multicurrency_total_tva) :
'0');
3554 $sql .=
", ".($this->multicurrency_total_ttc ?
price2num($this->multicurrency_total_ttc) :
'0');
3557 dol_syslog(get_class($this).
"::insert", LOG_DEBUG);
3561 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.$this->table_element);
3562 $this->
rowid = $this->id;
3573 if (!$error && !$notrigger)
3576 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_CREATE', $user);
3577 if ($result < 0) $error++;
3582 $this->
db->commit();
3586 foreach ($this->errors as $errmsg)
3588 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
3589 $this->errors[] = ($this->errors ?
', '.$errmsg : $errmsg);
3591 $this->
db->rollback();
3594 $this->errors[] = $this->
db->error();
3595 $this->
db->rollback();
3607 global $conf, $user;
3614 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
3615 $sql .=
" description='".$this->db->escape($this->desc).
"'";
3616 $sql .=
", ref='".$this->db->escape($this->ref_supplier).
"'";
3617 $sql .=
", subprice='".price2num($this->subprice).
"'";
3619 $sql .=
", remise_percent='".price2num($this->remise_percent).
"'";
3621 $sql .=
", vat_src_code = '".(empty($this->vat_src_code) ?
'' : $this->vat_src_code).
"'";
3622 $sql .=
", tva_tx='".price2num($this->tva_tx).
"'";
3623 $sql .=
", localtax1_tx='".price2num($this->total_localtax1).
"'";
3624 $sql .=
", localtax2_tx='".price2num($this->total_localtax2).
"'";
3625 $sql .=
", localtax1_type='".$this->db->escape($this->localtax1_type).
"'";
3626 $sql .=
", localtax2_type='".$this->db->escape($this->localtax2_type).
"'";
3627 $sql .=
", qty='".price2num($this->qty).
"'";
3628 $sql .=
", date_start=".(!empty($this->date_start) ?
"'".$this->db->idate($this->date_start).
"'" :
"null");
3629 $sql .=
", date_end=".(!empty($this->date_end) ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
3630 $sql .=
", info_bits='".$this->db->escape($this->info_bits).
"'";
3631 $sql .=
", total_ht='".price2num($this->total_ht).
"'";
3632 $sql .=
", total_tva='".price2num($this->total_tva).
"'";
3633 $sql .=
", total_localtax1='".price2num($this->total_localtax1).
"'";
3634 $sql .=
", total_localtax2='".price2num($this->total_localtax2).
"'";
3635 $sql .=
", total_ttc='".price2num($this->total_ttc).
"'";
3636 $sql .=
", product_type=".$this->product_type;
3637 $sql .=
", special_code=".(!empty($this->special_code) ? $this->special_code : 0);
3638 $sql .= ($this->fk_unit ?
", fk_unit='".$this->db->escape($this->fk_unit).
"'" :
", fk_unit=null");
3641 $sql .=
", multicurrency_subprice=".price2num($this->multicurrency_subprice).
"";
3642 $sql .=
", multicurrency_total_ht=".price2num($this->multicurrency_total_ht).
"";
3643 $sql .=
", multicurrency_total_tva=".price2num($this->multicurrency_total_tva).
"";
3644 $sql .=
", multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc).
"";
3646 $sql .=
" WHERE rowid = ".$this->id;
3648 dol_syslog(get_class($this).
"::updateline", LOG_DEBUG);
3649 $result = $this->
db->query($sql);
3661 if (!$error && !$notrigger)
3665 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_UPDATE', $user);
3668 $this->
db->rollback();
3676 $this->
db->commit();
3679 $this->
db->rollback();
3683 $this->error = $this->
db->lasterror();
3684 $this->
db->rollback();
3695 public function delete($notrigger = 0)
3707 $this->
db->rollback();
3711 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
"commande_fournisseurdet WHERE rowid=".$this->id;
3720 $result = $this->
call_trigger(
'LINEORDER_SUPPLIER_DELETE', $user);
3721 if ($result < 0) $error++;
3727 $this->
db->commit();
3731 foreach ($this->errors as $errmsg)
3733 dol_syslog(get_class($this).
"::delete ".$errmsg, LOG_ERR);
3734 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3736 $this->
db->rollback();
3739 $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.
if(!empty($arrayfields['u.datec']['checked'])) print_liste_field_titre("DateCreationShort"u if(!empty($arrayfields['u.tms']['checked'])) print_liste_field_titre("DateModificationShort"u if(!empty($arrayfields['u.statut']['checked'])) print_liste_field_titre("Status"u statut
static getIdAndTxFromCode($db, $code, $date_document= '')
Get id and rate of currency from code.
deleteline($idline, $notrigger=0)
Delete line.
__construct($db)
Constructor.
const STATUS_RECEIVED_COMPLETELY
Received completely.
fetch($id, $ref= '')
Get object and lines from database.
Class to manage table commandefournisseurdispatch.
fetch($rowid)
Load line order.
</td >< tdcolspan="3">< spanclass="opacitymedium"></span ></td ></tr >< trclass="liste_total"> CREANCES DETTES< tdcolspan="3"class="right"></td >< tdcolspan="3"class="right"></td ></tr > CREANCES DETTES RECETTES DEPENSES trips CREANCES DETTES Y m expensereport p date_valid Y m expensereport pe datep $db idate($date_start)."' AND $column < p rowid
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.
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.
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.
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.
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...
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)
Add order line.
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.
$conf db
API class for accounts.
create($user, $notrigger=0)
Create order with draft status.
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)...
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.
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)
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.
static getIdFromCode($db, $code)
Get id of currency from code.
const STATUS_RECEIVED_PARTIALLY
Received partially.
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.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories) ...
const STATUS_VALIDATED
Validated status.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1)
Remove a file or several files with a mask.
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.
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.
deleteObjectLinked($sourceid=null, $sourcetype= '', $targetid=null, $targettype= '', $rowid= '')
Delete all links between an object $this.
Livraison($user, $date, $type, $comment)
Set a delivery in database for this supplier order.
print $_SERVER["PHP_SELF"]
Edit parameters.
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.
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.
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
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.
add_object_linked($origin=null, $origin_id=null)
Add objects linked in llx_element_element.
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.
__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.
if(!empty($search_group)) natural_search(array("g.nom"g note
createFromClone(User $user, $socid=0)
Load an object from its id and create a new one in database.
Class to manage line orders.
setDeliveryDate($user, $delivery_date, $notrigger=0)
Set the planned delivery date.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...