41require_once DOL_DOCUMENT_ROOT.
'/core/class/commonorder.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/commande/class/orderline.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/margin/lib/margins.lib.php';
45require_once DOL_DOCUMENT_ROOT.
'/multicurrency/class/multicurrency.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/subtotals/class/commonsubtotal.class.php';
60 public $element =
'commande';
66 public $TRIGGER_PREFIX =
'ORDER';
71 public $table_element =
'commande';
76 public $table_element_line =
'commandedet';
81 public $class_element_line =
'OrderLine';
86 public $fk_element =
'fk_commande';
91 public $picto =
'order';
97 public $restrictiononfksoc = 1;
122 public $ref_customer;
150 public $date_lim_reglement;
154 public $cond_reglement_code;
159 public $cond_reglement_doc;
165 public $deposit_percent;
175 public $mode_reglement;
180 public $mode_reglement_id;
185 public $mode_reglement_code;
191 public $availability_id;
197 public $availability_code;
203 public $availability;
208 public $demand_reason_id;
213 public $demand_reason_code;
225 public $date_commande;
230 public $delivery_date;
235 public $fk_remise_except;
241 public $remise_percent;
252 public $signed_status = 0;
257 public $warehouse_id;
262 public $extraparams = array();
267 public $user_author_id;
277 public $lines = array();
283 public $module_source;
297 public $online_payment_url;
330 public $fields = array(
331 'rowid' => array(
'type' =>
'integer',
'label' =>
'TechnicalID',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 10),
332 'entity' => array(
'type' =>
'integer',
'label' =>
'Entity',
'default' =>
'1',
'enabled' => 1,
'visible' => -2,
'notnull' => 1,
'position' => 20,
'index' => 1),
333 'ref' => array(
'type' =>
'varchar(30)',
'label' =>
'Ref',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'showoncombobox' => 1,
'position' => 25),
334 'ref_ext' => array(
'type' =>
'varchar(255)',
'label' =>
'RefExt',
'enabled' => 1,
'visible' => 0,
'position' => 26),
335 'ref_client' => array(
'type' =>
'varchar(255)',
'label' =>
'RefCustomer',
'enabled' => 1,
'visible' => -1,
'position' => 28),
336 'fk_soc' => array(
'type' =>
'integer:Societe:societe/class/societe.class.php',
'label' =>
'ThirdParty',
'enabled' =>
'isModEnabled("societe")',
'visible' => -1,
'notnull' => 1,
'position' => 20),
337 'fk_projet' => array(
'type' =>
'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)',
'label' =>
'Project',
'enabled' =>
"isModEnabled('project')",
'visible' => -1,
'position' => 25),
338 'date_commande' => array(
'type' =>
'date',
'label' =>
'Date',
'enabled' => 1,
'visible' => 1,
'position' => 60,
'csslist' =>
'nowraponall'),
339 'date_valid' => array(
'type' =>
'datetime',
'label' =>
'DateValidation',
'enabled' => 1,
'visible' => -1,
'position' => 62,
'csslist' =>
'nowraponall'),
340 'date_cloture' => array(
'type' =>
'datetime',
'label' =>
'DateClosing',
'enabled' => 1,
'visible' => -1,
'position' => 65,
'csslist' =>
'nowraponall'),
341 'fk_user_valid' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserValidation',
'enabled' => 1,
'visible' => -1,
'position' => 85),
342 'fk_user_cloture' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserClosing',
'enabled' => 1,
'visible' => -1,
'position' => 90),
343 'source' => array(
'type' =>
'smallint(6)',
'label' =>
'Source',
'enabled' => 1,
'visible' => -1,
'position' => 95),
344 'total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'VAT',
'enabled' => 1,
'visible' => -1,
'position' => 125,
'isameasure' => 1),
345 'localtax1' => array(
'type' =>
'double(24,8)',
'label' =>
'LocalTax1',
'enabled' => 1,
'visible' => -1,
'position' => 130,
'isameasure' => 1),
346 'localtax2' => array(
'type' =>
'double(24,8)',
'label' =>
'LocalTax2',
'enabled' => 1,
'visible' => -1,
'position' => 135,
'isameasure' => 1),
347 'total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'TotalHT',
'enabled' => 1,
'visible' => -1,
'position' => 140,
'isameasure' => 1),
348 'total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'TotalTTC',
'enabled' => 1,
'visible' => -1,
'position' => 145,
'isameasure' => 1),
349 'signed_status' => array(
'type' =>
'smallint(6)',
'label' =>
'SignedStatus',
'enabled' => 1,
'visible' => -1,
'position' => 146,
'arrayofkeyval' => array(0 =>
'NoSignature', 1 =>
'SignedSender', 2 =>
'SignedReceiver', 9 =>
'SignedAll')),
350 'note_private' => array(
'type' =>
'html',
'label' =>
'NotePrivate',
'enabled' => 1,
'visible' => 0,
'position' => 150),
351 'note_public' => array(
'type' =>
'html',
'label' =>
'NotePublic',
'enabled' => 1,
'visible' => 0,
'position' => 155),
352 'model_pdf' => array(
'type' =>
'varchar(255)',
'label' =>
'PDFTemplate',
'enabled' => 1,
'visible' => 0,
'position' => 160),
353 'fk_account' => array(
'type' =>
'integer',
'label' =>
'BankAccount',
'enabled' =>
'isModEnabled("bank")',
'visible' => -1,
'position' => 170),
354 'fk_currency' => array(
'type' =>
'varchar(3)',
'label' =>
'MulticurrencyID',
'enabled' => 1,
'visible' => -1,
'position' => 175),
355 'fk_cond_reglement' => array(
'type' =>
'integer',
'label' =>
'PaymentTerm',
'enabled' => 1,
'visible' => -1,
'position' => 180),
356 'deposit_percent' => array(
'type' =>
'varchar(63)',
'label' =>
'DepositPercent',
'enabled' => 1,
'visible' => -1,
'position' => 181),
357 'fk_mode_reglement' => array(
'type' =>
'integer',
'label' =>
'PaymentMode',
'enabled' => 1,
'visible' => -1,
'position' => 185),
358 'date_livraison' => array(
'type' =>
'date',
'label' =>
'DateDeliveryPlanned',
'enabled' => 1,
'visible' => -1,
'position' => 190,
'csslist' =>
'nowraponall'),
359 'fk_shipping_method' => array(
'type' =>
'integer',
'label' =>
'ShippingMethod',
'enabled' => 1,
'visible' => -1,
'position' => 195),
360 'fk_warehouse' => array(
'type' =>
'integer:Entrepot:product/stock/class/entrepot.class.php',
'label' =>
'DefaultWarehouse',
'enabled' =>
'isModEnabled("stock")',
'visible' => -1,
'position' => 200,
'nodepth' => 1),
361 'fk_availability' => array(
'type' =>
'integer',
'label' =>
'Availability',
'enabled' => 1,
'visible' => -1,
'position' => 205),
362 'fk_input_reason' => array(
'type' =>
'integer',
'label' =>
'InputReason',
'enabled' => 1,
'visible' => -1,
'position' => 210),
364 'extraparams' => array(
'type' =>
'varchar(255)',
'label' =>
'Extraparams',
'enabled' => 1,
'visible' => -1,
'position' => 225),
365 'fk_incoterms' => array(
'type' =>
'integer',
'label' =>
'IncotermCode',
'enabled' =>
'isModEnabled("incoterm")',
'visible' => -1,
'position' => 230),
366 'location_incoterms' => array(
'type' =>
'varchar(255)',
'label' =>
'IncotermLabel',
'enabled' =>
'isModEnabled("incoterm")',
'visible' => -1,
'position' => 235),
367 'fk_multicurrency' => array(
'type' =>
'integer',
'label' =>
'Fk multicurrency',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 240),
368 'multicurrency_code' => array(
'type' =>
'varchar(255)',
'label' =>
'MulticurrencyCurrency',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 245),
369 'multicurrency_tx' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyRate',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 250,
'isameasure' => 1),
370 'multicurrency_total_ht' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountHT',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 255,
'isameasure' => 1),
371 'multicurrency_total_tva' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountVAT',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 260,
'isameasure' => 1),
372 'multicurrency_total_ttc' => array(
'type' =>
'double(24,8)',
'label' =>
'MulticurrencyAmountTTC',
'enabled' =>
'isModEnabled("multicurrency")',
'visible' => -1,
'position' => 265,
'isameasure' => 1),
373 'last_main_doc' => array(
'type' =>
'varchar(255)',
'label' =>
'LastMainDoc',
'enabled' => 1,
'visible' => -1,
'position' => 270),
374 'module_source' => array(
'type' =>
'varchar(32)',
'label' =>
'POSModule',
'enabled' => 1,
'visible' => -1,
'position' => 275),
375 'pos_source' => array(
'type' =>
'varchar(32)',
'label' =>
'POSTerminal',
'enabled' => 1,
'visible' => -1,
'position' => 280),
376 'fk_user_author' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserAuthor',
'enabled' => 1,
'visible' => -1,
'position' => 300),
377 'fk_user_modif' => array(
'type' =>
'integer:User:user/class/user.class.php',
'label' =>
'UserModif',
'enabled' => 1,
'visible' => -2,
'notnull' => -1,
'position' => 302),
378 'date_creation' => array(
'type' =>
'datetime',
'label' =>
'DateCreation',
'enabled' => 1,
'visible' => -2,
'position' => 304,
'csslist' =>
'nowraponall'),
379 'tms' => array(
'type' =>
'timestamp',
'label' =>
'DateModification',
'enabled' => 1,
'visible' => -1,
'notnull' => 1,
'position' => 306),
380 'import_key' => array(
'type' =>
'varchar(14)',
'label' =>
'ImportId',
'enabled' => 1,
'visible' => -2,
'position' => 400),
381 'fk_statut' => array(
'type' =>
'smallint(6)',
'label' =>
'Status',
'enabled' => 1,
'visible' => -1,
'position' => 500),
421 const STATUS_NO_SIGNATURE = 0;
426 const STATUS_SIGNED_SENDER = 1;
431 const STATUS_SIGNED_RECEIVER = 2;
436 const STATUS_SIGNED_ALL = 9;
448 $this->ismultientitymanaged = 1;
449 $this->isextrafieldmanaged = 1;
451 $this->fields[
'ref_ext'][
'visible'] =
getDolGlobalInt(
'MAIN_LIST_SHOW_REF_EXT');
461 public function getNextNumRef($soc)
463 global $langs,
$conf;
464 $langs->load(
"order");
473 $dirmodels = array_merge(array(
'/'), (array)
$conf->modules_parts[
'models']);
474 foreach ($dirmodels as $reldir) {
478 $mybool = ((bool) @include_once $dir.$file) || $mybool;
486 $obj =
new $classname();
488 '@phan-var-force ModeleNumRefCommandes $obj';
490 $numref = $obj->getNextValue($soc, $this);
495 $this->error = $obj->error;
500 print $langs->trans(
"Error").
" ".$langs->trans(
"Error_COMMANDE_ADDON_NotDefined");
514 public function valid($user, $idwarehouse = 0, $notrigger = 0)
516 global
$conf, $langs;
518 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
523 if ($this->
status == self::STATUS_VALIDATED) {
524 dol_syslog(get_class($this).
"::valid action abandoned: already validated", LOG_WARNING);
528 if (!((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'commande',
'creer'))
529 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'commande',
'order_advance',
'validate')))) {
530 $this->error =
'NotEnoughPermissions';
531 dol_syslog(get_class($this).
"::valid ".$this->error, LOG_ERR);
534 if (empty($this->socid)) {
535 $this->error =
'ErrorWrongParameters';
539 dol_syslog(get_class($this).
"::valid checkActiveProductInLines ".$this->error, LOG_INFO);
548 $soc->fetch($this->socid);
551 $result = $soc->setAsCustomer();
554 if (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref)) {
555 $num = $this->getNextNumRef($soc);
562 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
563 $sql .=
" SET ref = '".$this->db->escape($num).
"',";
564 $sql .=
" fk_statut = ".self::STATUS_VALIDATED.
",";
565 $sql .=
" date_valid = '".$this->db->idate($now).
"',";
566 $sql .=
" fk_user_valid = ".($user->id > 0 ? (int) $user->id :
"null").
",";
567 $sql .=
" fk_user_modif = ".((int) $user->id);
568 $sql .=
" WHERE rowid = ".((int) $this->
id);
570 dol_syslog(get_class($this).
"::valid", LOG_DEBUG);
571 $resql = $this->db->query($sql);
574 $this->error = $this->db->lasterror();
581 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
582 $langs->load(
"agenda");
585 $cpt = count($this->lines);
586 for ($i = 0; $i < $cpt; $i++) {
587 if ($this->lines[$i]->fk_product > 0) {
589 $mouvP->origin = &$this;
590 $mouvP->setOrigin($this->element, $this->
id);
592 $result = $mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans(
"OrderValidatedInDolibarr", $num));
605 if (!$error && !$notrigger) {
607 $result = $this->call_trigger(
'ORDER_VALIDATE', $user);
615 $this->oldref = $this->ref;
618 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
620 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filename = CONCAT('".$this->db->escape($this->newref).
"', SUBSTR(filename, ".(strlen($this->
ref) + 1).
")), filepath = 'commande/".$this->db->escape($this->newref).
"'";
621 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'commande/".$this->db->escape($this->
ref).
"' and entity = ".((int)
$conf->entity);
622 $resql = $this->db->query($sql);
625 $this->error = $this->db->lasterror();
627 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filepath = 'commande/".$this->db->escape($this->newref).
"'";
628 $sql .=
" WHERE filepath = 'commande/".$this->db->escape($this->
ref).
"' and entity = ".((int)
$conf->entity);
629 $resql = $this->db->query($sql);
632 $this->error = $this->db->lasterror();
640 if (!$error && file_exists($dirsource)) {
641 dol_syslog(get_class($this).
"::valid rename dir ".$dirsource.
" into ".$dirdest);
643 if (@rename($dirsource, $dirdest)) {
646 $listoffiles =
dol_dir_list($dirdest,
'files', 1,
'^'.preg_quote($oldref,
'/'));
647 foreach ($listoffiles as $fileentry) {
648 $dirsource = $fileentry[
'name'];
649 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
650 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
651 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
652 @rename($dirsource, $dirdest);
670 $this->db->rollback();
695 if (!((!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'commande',
'creer'))
696 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'commande',
'order_advance',
'validate')))) {
697 $this->error =
'Permission denied';
705 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
706 $sql .=
" SET fk_statut = ".((int) self::STATUS_DRAFT).
",";
707 $sql .=
" fk_user_modif = ".((int) $user->id);
708 $sql .=
" WHERE rowid = ".((int) $this->
id);
710 if ($this->db->query($sql)) {
711 $this->oldcopy = clone $this;
717 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
718 $langs->load(
"agenda");
720 $num = count($this->lines);
721 for ($i = 0; $i < $num; $i++) {
722 if ($this->lines[$i]->fk_product > 0) {
724 $mouvP->origin = &$this;
725 $mouvP->setOrigin($this->element, $this->
id);
727 $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, 0, $langs->transnoentitiesnoconv(
"OrderBackToDraftInDolibarr", $this->ref));
739 $result = $this->call_trigger(
'ORDER_UNVALIDATE', $user);
751 $this->db->rollback();
755 $this->error = $this->db->error();
756 $this->db->rollback();
775 if ($this->
status != self::STATUS_CANCELED && $this->
status != self::STATUS_CLOSED) {
776 dol_syslog(get_class($this).
"::set_reopen order has not status closed", LOG_WARNING);
782 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
783 $sql .=
' SET fk_statut='.self::STATUS_VALIDATED.
', facture=0,';
784 $sql .=
" fk_user_modif = ".((int) $user->id);
785 $sql .=
" WHERE rowid = ".((int) $this->
id);
787 dol_syslog(get_class($this).
"::set_reopen", LOG_DEBUG);
788 $resql = $this->db->query($sql);
791 $result = $this->call_trigger(
'ORDER_REOPEN', $user);
798 $this->error = $this->db->lasterror();
810 foreach ($this->errors as $errmsg) {
811 dol_syslog(get_class($this).
"::set_reopen ".$errmsg, LOG_ERR);
812 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
814 $this->db->rollback();
827 public function cloture($user, $notrigger = 0, $checkpermission = 1)
831 $usercanclose = (!$checkpermission
832 || (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'commande',
'creer'))
833 || (
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'commande',
'order_advance',
'close')));
836 if ($this->
status == self::STATUS_CLOSED) {
843 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
844 $sql .=
' SET fk_statut = '.self::STATUS_CLOSED.
',';
845 $sql .=
' fk_user_cloture = '.((int) $user->id).
',';
846 $sql .=
" date_cloture = '".$this->db->idate($now).
"',";
847 $sql .=
" fk_user_modif = ".((int) $user->id);
850 if ($this->db->query($sql)) {
853 $result = $this->call_trigger(
'ORDER_CLOSE', $user);
867 $this->db->rollback();
871 $this->error = $this->db->lasterror();
873 $this->db->rollback();
893 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
894 return parent::setCategoriesCommon($categories, Categorie::TYPE_ORDER);
905 public function cancel($user, $idwarehouse = -1)
907 global $user, $langs;
913 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
914 $sql .=
" SET fk_statut = ".self::STATUS_CANCELED.
",";
915 $sql .=
" fk_user_modif = ".((int) $user->id);
916 $sql .=
" WHERE rowid = ".((int) $this->
id);
917 $sql .=
" AND fk_statut = ".self::STATUS_VALIDATED;
919 dol_syslog(get_class($this).
"::cancel", LOG_DEBUG);
920 if ($this->db->query($sql)) {
923 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
924 $langs->load(
"agenda");
926 $num = count($this->lines);
927 for ($i = 0; $i < $num; $i++) {
928 if ($this->lines[$i]->fk_product > 0) {
930 $mouvP->setOrigin($this->element, $this->
id);
932 $result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, 0, $langs->trans(
"OrderCanceledInDolibarr", $this->ref));
944 $result = $this->call_trigger(
'ORDER_CANCEL', $user);
957 foreach ($this->errors as $errmsg) {
958 dol_syslog(get_class($this).
"::cancel ".$errmsg, LOG_ERR);
959 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
961 $this->db->rollback();
965 $this->error = $this->db->error();
966 $this->db->rollback();
979 public function create($user, $notrigger = 0)
986 if (empty($this->socid)) {
987 $this->error =
'ErrorWrongParameters';
992 $date = ($this->date_commande ? $this->date_commande : $this->date);
993 $this->import_key = trim((
string) $this->import_key);
994 $delivery_date = $this->delivery_date;
997 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
1002 if (empty($this->fk_multicurrency)) {
1003 $this->multicurrency_code =
$conf->currency;
1004 $this->fk_multicurrency = 0;
1005 $this->multicurrency_tx = 1;
1010 dol_syslog(get_class($this).
"::create user=".$user->id);
1013 if (!empty($this->
ref)) {
1016 $this->error =
'ErrorRefAlreadyExists';
1017 dol_syslog(get_class($this).
"::create ".$this->error, LOG_WARNING);
1018 $this->db->rollback();
1023 $soc =
new Societe($this->db);
1024 $result = $soc->fetch($this->socid);
1026 $this->error =
"Failed to fetch company";
1027 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
1031 $this->error = $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Source"));
1032 dol_syslog(get_class($this).
"::create ".$this->error, LOG_ERR);
1036 $this->date_creation =
dol_now();
1040 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.$this->table_element.
" (";
1041 $sql .=
" ref, fk_soc, date_creation, fk_user_author, fk_projet, date_commande, source, note_private, note_public, ref_ext, ref_client";
1042 $sql .=
", model_pdf, fk_cond_reglement, deposit_percent, fk_mode_reglement, fk_account, fk_availability, fk_input_reason, date_livraison, fk_delivery_address";
1043 $sql .=
", fk_shipping_method";
1044 $sql .=
", fk_warehouse";
1045 $sql .=
", fk_incoterms, location_incoterms";
1046 $sql .=
", entity, module_source, pos_source";
1047 $sql .=
", fk_multicurrency";
1048 $sql .=
", multicurrency_code";
1049 $sql .=
", multicurrency_tx";
1050 $sql .=
", import_key";
1052 $sql .=
" VALUES ('(PROV)', ".((int) $this->socid).
", '".$this->db->idate($this->date_creation).
"', ".($user->id > 0 ? ((int) $user->id) :
"null");
1053 $sql .=
", ".($this->fk_project > 0 ? ((int) $this->fk_project) :
"null");
1054 $sql .=
", '".$this->db->idate($date).
"'";
1055 $sql .=
", ".($this->source >= 0 && $this->source !=
'' ? $this->db->escape((
string) $this->source) :
'null');
1056 $sql .=
", '".$this->db->escape($this->note_private).
"'";
1057 $sql .=
", '".$this->db->escape($this->note_public).
"'";
1058 $sql .=
", ".($this->ref_ext ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null");
1059 $sql .=
", ".($this->ref_client ?
"'".$this->db->escape($this->ref_client).
"'" :
"null");
1060 $sql .=
", '".$this->db->escape($this->model_pdf).
"'";
1061 $sql .=
", ".($this->cond_reglement_id > 0 ? ((int) $this->cond_reglement_id) :
"null");
1062 $sql .=
", ".(!empty($this->deposit_percent) ?
"'".$this->db->escape($this->deposit_percent).
"'" :
"null");
1063 $sql .=
", ".($this->mode_reglement_id > 0 ? ((int) $this->mode_reglement_id) :
"null");
1064 $sql .=
", ".($this->fk_account > 0 ? ((int) $this->fk_account) :
'NULL');
1065 $sql .=
", ".($this->availability_id > 0 ? ((int) $this->availability_id) :
"null");
1066 $sql .=
", ".($this->demand_reason_id > 0 ? ((int) $this->demand_reason_id) :
"null");
1067 $sql .=
", ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
"null");
1068 $sql .=
", ".($this->fk_delivery_address > 0 ? ((int) $this->fk_delivery_address) :
'NULL');
1069 $sql .=
", ".(!empty($this->shipping_method_id) && $this->shipping_method_id > 0 ? ((int) $this->shipping_method_id) :
'NULL');
1070 $sql .=
", ".(!empty($this->warehouse_id) && $this->warehouse_id > 0 ? ((int) $this->warehouse_id) :
'NULL');
1071 $sql .=
", ".(int) $this->fk_incoterms;
1072 $sql .=
", '".$this->db->escape($this->location_incoterms).
"'";
1073 $sql .=
", ".(int) $this->entity;
1074 $sql .=
", ".($this->module_source ?
"'".$this->db->escape($this->module_source).
"'" :
"null");
1075 $sql .=
", ".((!is_null($this->pos_source) && $this->pos_source !=
'') ?
"'".$this->db->escape($this->pos_source).
"'" :
"null");
1076 $sql .=
", ".(int) $this->fk_multicurrency;
1077 $sql .=
", '".$this->db->escape($this->multicurrency_code).
"'";
1078 $sql .=
", ".(float) $this->multicurrency_tx;
1079 $sql .=
", '".$this->db->escape($this->import_key).
"'";
1082 dol_syslog(get_class($this).
"::create", LOG_DEBUG);
1083 $resql = $this->db->query($sql);
1085 $this->
id = $this->db->last_insert_id(MAIN_DB_PREFIX.
'commande');
1088 $fk_parent_line = 0;
1089 $num = count($this->lines);
1094 for ($i = 0; $i < $num; $i++) {
1095 $line = $this->lines[$i];
1099 if (!is_object($line)) {
1101 foreach ($line as $key => $val) {
1102 $lineobj->$key = $val;
1105 $this->lines[$i] = $line;
1109 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
1110 $fk_parent_line = 0;
1114 $vatrate = $line->tva_tx;
1115 if ($line->vat_src_code && !preg_match(
'/\(.*\)/', (
string) $vatrate)) {
1116 $vatrate .=
' ('.$line->vat_src_code.
')';
1120 $originid = $line->origin_id;
1121 $origintype = empty($line->origin_type) ? $line->origin : $line->origin_type;
1123 $originid = $line->id;
1124 $origintype = $this->element;
1128 if (empty($line->ref_ext)) {
1129 $line->ref_ext =
'';
1137 $line->localtax1_tx,
1138 $line->localtax2_tx,
1140 $line->remise_percent,
1142 $line->fk_remise_except,
1147 $line->product_type,
1149 $line->special_code,
1151 $line->fk_fournprice,
1154 $line->array_options,
1156 (
string) $origintype,
1164 if ($result != self::STOCK_NOT_ENOUGH_FOR_ORDER) {
1165 $this->error = $this->db->lasterror();
1166 $this->errors[] = $this->error;
1169 $this->db->rollback();
1175 if ($result > 0 && !empty($line->extraparams)) {
1177 $newline->id = $result;
1178 $newline->extraparams = $line->extraparams;
1179 $newline->setExtraParameters();
1183 if ($result > 0 && $line->product_type == 9) {
1184 $fk_parent_line = $result;
1191 $initialref =
'(PROV'.$this->id.
')';
1192 if (!empty($this->
ref)) {
1193 $initialref = $this->ref;
1196 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
" SET ref='".$this->db->escape($initialref).
"' WHERE rowid=".((int) $this->
id);
1197 if ($this->db->query($sql)) {
1198 $this->
ref = $initialref;
1200 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
1201 $this->linked_objects = $this->linkedObjectsIds;
1205 if (!empty($this->linked_objects) && is_array($this->linked_objects)) {
1206 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
1207 if (is_array($tmp_origin_id)) {
1208 foreach ($tmp_origin_id as $origin_id) {
1211 $this->error = $this->db->lasterror();
1216 $origin_id = $tmp_origin_id;
1219 $this->error = $this->db->lasterror();
1226 if (!$error &&
getDolGlobalString(
'MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN') && !empty($this->origin) && !empty($this->origin_id)) {
1227 $originforcontact = empty($this->origin_type) ? $this->origin : $this->origin_type;
1228 $originidforcontact = $this->origin_id;
1229 if ($originforcontact ==
'shipping') {
1230 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1232 $exp->fetch($this->origin_id);
1233 $exp->fetchObjectLinked();
1234 if (count($exp->linkedObjectsIds[
'commande']) > 0) {
1235 foreach ($exp->linkedObjectsIds[
'commande'] as $key => $value) {
1236 $originforcontact =
'commande';
1237 if (is_object($value)) {
1238 $originidforcontact = $value->id;
1240 $originidforcontact = $value;
1247 $sqlcontact =
"SELECT ctc.code, ctc.source, ec.fk_socpeople FROM ".MAIN_DB_PREFIX.
"element_contact as ec, ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
1248 $sqlcontact .=
" WHERE element_id = ".((int) $originidforcontact).
" AND ec.fk_c_type_contact = ctc.rowid AND ctc.element = '".$this->db->escape($originforcontact).
"'";
1250 $resqlcontact = $this->db->query($sqlcontact);
1251 if ($resqlcontact) {
1252 while ($objcontact = $this->db->fetch_object($resqlcontact)) {
1254 $this->
add_contact($objcontact->fk_socpeople, $objcontact->code, $objcontact->source);
1268 if (!$error && !$notrigger) {
1270 $result = $this->call_trigger(
'ORDER_CREATE', $user);
1278 $this->db->commit();
1281 $this->db->rollback();
1285 $this->error = $this->db->lasterror();
1286 $this->db->rollback();
1293 $this->error = $this->db->lasterror();
1294 $this->db->rollback();
1310 global $hookmanager;
1314 $object =
new self($this->db);
1324 if (!empty($socid) && $socid !=
$object->socid) {
1325 $objsoc =
new Societe($this->db);
1327 if ($objsoc->fetch($socid) > 0) {
1329 $object->cond_reglement_id = (!empty($objsoc->cond_reglement_id) ? $objsoc->cond_reglement_id : 0);
1330 $object->deposit_percent = (!empty($objsoc->deposit_percent) ? $objsoc->deposit_percent :
'0');
1331 $object->mode_reglement_id = (!empty($objsoc->mode_reglement_id) ? $objsoc->mode_reglement_id : 0);
1333 $object->fk_delivery_address = 0;
1339 $object->entity = (!empty($forceentity) ? $forceentity :
$object->entity);
1347 $object->user_author_id = $user->id;
1348 $object->user_validation_id = 0;
1352 $object->date_validation =
'';
1360 for ($i = 0; $i < $num; $i++) {
1361 $object->lines[$i]->ref_ext =
'';
1365 $object->context[
'createfromclone'] =
'createfromclone';
1366 $result =
$object->create($user);
1374 if (
$object->copy_linked_contact($objFrom,
'internal') < 0) {
1381 if (
$object->socid == $objFrom->socid) {
1382 if (
$object->copy_linked_contact($objFrom,
'external') < 0) {
1390 if (is_object($hookmanager)) {
1391 $parameters = array(
'objFrom' => $objFrom,
'clonedObj' =>
$object);
1393 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters,
$object, $action);
1401 unset(
$object->context[
'createfromclone']);
1405 $this->db->commit();
1408 $this->db->rollback();
1423 global
$conf, $hookmanager, $langs;
1425 require_once DOL_DOCUMENT_ROOT .
'/multicurrency/class/multicurrency.class.php';
1426 require_once DOL_DOCUMENT_ROOT .
'/core/class/extrafields.class.php';
1430 $this->date_commande =
dol_now();
1435 for ($i = 0; $i < $num; $i++) {
1438 $line->libelle =
$object->lines[$i]->libelle;
1439 $line->label =
$object->lines[$i]->label;
1440 $line->desc =
$object->lines[$i]->desc;
1441 $line->price =
$object->lines[$i]->price;
1442 $line->subprice =
$object->lines[$i]->subprice;
1443 $line->vat_src_code =
$object->lines[$i]->vat_src_code;
1444 $line->tva_tx =
$object->lines[$i]->tva_tx;
1445 $line->localtax1_tx =
$object->lines[$i]->localtax1_tx;
1446 $line->localtax2_tx =
$object->lines[$i]->localtax2_tx;
1447 $line->qty =
$object->lines[$i]->qty;
1448 $line->fk_remise_except =
$object->lines[$i]->fk_remise_except;
1449 $line->remise_percent =
$object->lines[$i]->remise_percent;
1450 $line->fk_product =
$object->lines[$i]->fk_product;
1451 $line->info_bits =
$object->lines[$i]->info_bits;
1452 $line->product_type =
$object->lines[$i]->product_type;
1453 $line->rang =
$object->lines[$i]->rang;
1454 $line->special_code =
$object->lines[$i]->special_code;
1455 $line->fk_parent_line =
$object->lines[$i]->fk_parent_line;
1456 $line->fk_unit =
$object->lines[$i]->fk_unit;
1458 $line->date_start =
$object->lines[$i]->date_start;
1459 $line->date_end =
$object->lines[$i]->date_end;
1461 $line->fk_fournprice =
$object->lines[$i]->fk_fournprice;
1463 $line->pa_ht = $marginInfos[0];
1464 $line->marge_tx = $marginInfos[1];
1465 $line->marque_tx = $marginInfos[2];
1467 $line->origin =
$object->element;
1468 $line->origin_id =
$object->lines[$i]->id;
1471 $object->lines[$i]->fetch_optionals();
1472 foreach (
$object->lines[$i]->array_options as $options_key => $value) {
1473 $line->array_options[$options_key] = $value;
1476 $this->lines[$i] = $line;
1479 $this->entity =
$object->entity;
1480 $this->socid =
$object->socid;
1481 $this->fk_project =
$object->fk_project;
1482 $this->cond_reglement_id =
$object->cond_reglement_id;
1483 $this->deposit_percent =
$object->deposit_percent;
1484 $this->mode_reglement_id =
$object->mode_reglement_id;
1485 $this->fk_account =
$object->fk_account;
1486 $this->fk_incoterms =
$object->fk_incoterms;
1487 $this->location_incoterms =
$object->location_incoterms;
1488 $this->availability_id =
$object->availability_id;
1489 $this->demand_reason_id =
$object->demand_reason_id;
1490 $this->delivery_date =
$object->delivery_date;
1491 $this->shipping_method_id =
$object->shipping_method_id;
1492 $this->warehouse_id =
$object->warehouse_id;
1493 $this->fk_delivery_address =
$object->fk_delivery_address;
1494 $this->contact_id =
$object->contact_id;
1495 $this->ref_client =
$object->ref_client;
1496 $this->ref_customer =
$object->ref_client;
1499 $this->note_private =
$object->note_private;
1500 $this->note_public =
$object->note_public;
1503 $this->origin =
$object->element;
1504 $this->origin_id =
$object->id;
1508 if (!empty(
$object->multicurrency_code)) {
1509 $this->multicurrency_code =
$object->multicurrency_code;
1512 $this->multicurrency_tx =
$object->multicurrency_tx;
1515 if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) {
1517 $this->fk_multicurrency = $tmparray[0];
1518 $this->multicurrency_tx = $tmparray[1];
1522 if (empty($this->fk_multicurrency)) {
1523 $this->multicurrency_code =
$conf->currency;
1524 $this->fk_multicurrency = 0;
1525 $this->multicurrency_tx = 1;
1533 $element_extrafields = $e->fetch_name_optionals_label($this->table_element);
1535 foreach (
$object->array_options as $options_key => $value) {
1536 if (array_key_exists(str_replace(
'options_',
'', $options_key), $element_extrafields)) {
1537 $this->array_options[$options_key] = $value;
1541 $this->linked_objects[$this->origin] = $this->origin_id;
1542 if (isset(
$object->other_linked_objects) && is_array(
$object->other_linked_objects) && !empty(
$object->other_linked_objects)) {
1543 $this->linked_objects = array_merge($this->linked_objects,
$object->other_linked_objects);
1546 $ret = $this->
create($user);
1550 $hookmanager->initHooks(array(
'orderdao'));
1552 $parameters = array(
'objFrom' =>
$object);
1554 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $this, $action);
1564 $result = $this->
valid($user);
1566 $this->
fetch($this->
id);
1569 $outputlangs = $langs;
1570 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($this->thirdparty->default_lang)) {
1572 $outputlangs->setDefaultLang($this->thirdparty->default_lang);
1573 $outputlangs->loadLangs(array(
'main',
'orders'));
1628 public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $fk_product = 0, $remise_percent = 0, $info_bits = 0, $fk_remise_except = 0, $price_base_type =
'HT', $pu_ttc = 0,
$date_start =
'', $date_end =
'', $type = 0, $rang = -1, $special_code = 0, $fk_parent_line = 0, $fk_fournprice =
null, $pa_ht = 0, $label =
'', $array_options = array(), $fk_unit =
null, $origin =
'', $origin_id = 0, $pu_ht_devise = 0, $ref_ext =
'', $noupdateafterinsertline = 0)
1630 global
$mysoc, $langs, $user;
1632 $logtext =
"::addline commandeid=$this->id, desc=$desc, pu_ht=$pu_ht, qty=$qty, txtva=$txtva, fk_product=$fk_product, remise_percent=$remise_percent";
1633 $logtext .=
", info_bits=$info_bits, fk_remise_except=$fk_remise_except, price_base_type=$price_base_type, pu_ttc=$pu_ttc, date_start=$date_start";
1634 $logtext .=
", date_end=$date_end, type=$type special_code=$special_code, fk_unit=$fk_unit, origin=$origin, origin_id=$origin_id, pu_ht_devise=$pu_ht_devise, ref_ext=$ref_ext rang=$rang";
1635 dol_syslog(get_class($this).$logtext, LOG_DEBUG);
1637 if ($this->
status == self::STATUS_DRAFT) {
1638 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
1642 if (empty($remise_percent)) {
1643 $remise_percent = 0;
1648 if (empty($info_bits)) {
1654 if (empty($txtva)) {
1657 if (empty($txlocaltax1)) {
1660 if (empty($txlocaltax2)) {
1663 if (empty($fk_parent_line) || $fk_parent_line < 0) {
1664 $fk_parent_line = 0;
1666 if (empty($this->fk_multicurrency)) {
1667 $this->fk_multicurrency = 0;
1669 if (empty($ref_ext)) {
1673 $remise_percent = (float)
price2num($remise_percent);
1676 $pu_ht_devise =
price2num($pu_ht_devise);
1679 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
1684 if ($price_base_type ==
'HT') {
1689 $label = trim($label);
1690 $desc = trim($desc);
1698 $langs->load(
"errors");
1699 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
1705 $product_type = $type;
1706 if (!empty($fk_product) && $fk_product > 0) {
1707 $product =
new Product($this->db);
1708 $result = $product->fetch($fk_product);
1709 $product_type = $product->type;
1711 if (
getDolGlobalString(
'STOCK_MUST_BE_ENOUGH_FOR_ORDER') && $product->isStockManaged()) {
1713 $productChildrenNb = 0;
1715 $productChildrenNb = $product->hasFatherOrChild(1);
1717 if ($productChildrenNb > 0) {
1719 $product_stock =
null;
1720 $product->loadStockForVirtualProduct(
'warehouseopen', $qty);
1721 foreach ($product->stock_warehouse as $componentStockWarehouse) {
1722 if ($product_stock ===
null) {
1723 $product_stock = $componentStockWarehouse->real;
1725 $product_stock = min($product_stock, $componentStockWarehouse->real);
1728 if ($product_stock ===
null) {
1732 $product_stock = $product->stock_reel;
1735 if ($product_stock < $qty) {
1736 $langs->load(
"errors");
1737 $this->error = $langs->trans(
'ErrorStockIsNotEnoughToAddProductOnOrder', $product->ref);
1738 $this->errors[] = $this->error;
1739 dol_syslog(get_class($this).
"::addline error=Product ".$product->ref.
": ".$this->error, LOG_ERR);
1740 $this->db->rollback();
1752 $tmpproduct =
new Product($this->db);
1753 $result = $tmpproduct->fetch($fk_product);
1755 if ($newqty != $qty) {
1757 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'warnings');
1764 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
1765 $vat_src_code = $reg[1];
1766 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
1769 $tabprice =
calcul_price_total($qty, (
float) $pu, $remise_percent, $txtva, (
float) $txlocaltax1, (
float) $txlocaltax2, 0, $price_base_type, $info_bits, $product_type,
$mysoc, $localtaxes_type, 100, $this->multicurrency_tx, (
float) $pu_ht_devise);
1779 $total_ht = $tabprice[0];
1780 $total_tva = $tabprice[1];
1781 $total_ttc = $tabprice[2];
1782 $total_localtax1 = $tabprice[9];
1783 $total_localtax2 = $tabprice[10];
1784 $pu_ht = $tabprice[3];
1787 $multicurrency_total_ht = $tabprice[16];
1788 $multicurrency_total_tva = $tabprice[17];
1789 $multicurrency_total_ttc = $tabprice[18];
1790 $pu_ht_devise = $tabprice[19];
1795 if (empty($ranktouse) || $ranktouse == -1) {
1796 $rangmax = $this->
line_max($fk_parent_line);
1797 $ranktouse = $rangmax + 1;
1803 $this->line->context = $this->context;
1805 $this->line->fk_commande = $this->id;
1806 $this->line->label = $label;
1807 $this->line->desc = $desc;
1808 $this->line->qty = (float) $qty;
1809 $this->line->ref_ext = $ref_ext;
1811 $this->line->vat_src_code = $vat_src_code;
1812 $this->line->tva_tx = $txtva;
1813 $this->line->localtax1_tx = ($total_localtax1 ? $localtaxes_type[1] : 0);
1814 $this->line->localtax2_tx = ($total_localtax2 ? $localtaxes_type[3] : 0);
1815 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
1816 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
1817 $this->line->fk_product = $fk_product;
1818 $this->line->product_type = $product_type;
1819 $this->line->fk_remise_except = $fk_remise_except;
1820 $this->line->remise_percent = $remise_percent;
1821 $this->line->subprice = (float) $pu_ht;
1822 $this->line->rang = $ranktouse;
1823 $this->line->info_bits = $info_bits;
1824 $this->line->total_ht = (float) $total_ht;
1825 $this->line->total_tva = (float) $total_tva;
1826 $this->line->total_localtax1 = (float) $total_localtax1;
1827 $this->line->total_localtax2 = (float) $total_localtax2;
1828 $this->line->total_ttc = (float) $total_ttc;
1829 $this->line->special_code = $special_code;
1830 if (empty($qty) && empty($special_code)) {
1831 $this->line->special_code = 3;
1833 $this->line->origin = $origin;
1834 $this->line->origin_type = $origin;
1835 $this->line->origin_id = $origin_id;
1837 $this->line->fk_parent_line = $fk_parent_line;
1838 $this->line->fk_unit = $fk_unit;
1841 $this->line->date_end = $date_end;
1843 $this->line->fk_fournprice = $fk_fournprice;
1844 $this->line->pa_ht = $pa_ht;
1847 $this->line->fk_multicurrency = $this->fk_multicurrency;
1848 $this->line->multicurrency_code = $this->multicurrency_code;
1849 $this->line->multicurrency_subprice = (float) $pu_ht_devise;
1850 $this->line->multicurrency_total_ht = (float) $multicurrency_total_ht;
1851 $this->line->multicurrency_total_tva = (float) $multicurrency_total_tva;
1852 $this->line->multicurrency_total_ttc = (float) $multicurrency_total_ttc;
1854 if (is_array($array_options) && count($array_options) > 0) {
1855 $this->line->array_options = $array_options;
1858 $result = $this->line->insert($user);
1861 if (empty($noupdateafterinsertline)) {
1866 if (!isset($this->context[
'createfromclone'])) {
1867 if (!empty($fk_parent_line)) {
1870 } elseif ($ranktouse > 0 && $ranktouse <= count($this->lines)) {
1872 foreach ($this->lines as $tmpline) {
1873 if ($tmpline->rang >= $ranktouse) {
1874 if (!empty($tmpline->id)) {
1881 $this->lines[] = $this->line;
1884 foreach ($this->lines as $tmpline) {
1885 if ($tmpline->id == $origin_id && $tmpline->element == $origin) {
1886 $this->line->extraparams = $tmpline->extraparams;
1887 $this->line->setExtraParameters();
1892 $this->db->commit();
1893 return $this->line->id;
1895 $this->db->rollback();
1900 dol_syslog(get_class($this).
"::addline error=".$this->error, LOG_ERR);
1901 $this->db->rollback();
1905 dol_syslog(get_class($this).
"::addline status of order must be Draft to allow use of ->addline()", LOG_ERR);
1934 if ($idproduct > 0) {
1936 $prod->fetch($idproduct);
1940 if (empty($tva_tx)) {
1950 $price =
$prod->multiprices[$this->thirdparty->price_level];
1951 $price_ttc =
$prod->multiprices_ttc[$this->thirdparty->price_level];
1953 $price =
$prod->price;
1954 $price_ttc =
$prod->price_ttc;
1959 $line->context = $this->context;
1961 $line->fk_product = $idproduct;
1962 $line->desc =
$prod->description;
1964 $line->subprice = $price;
1965 $line->subprice_ttc = $price_ttc;
1966 $line->remise_percent = $remise_percent;
1967 $line->vat_src_code = $vat_src_code;
1968 $line->tva_tx = $tva_tx;
1969 $line->localtax1_tx = $localtax1_tx;
1970 $line->localtax2_tx = $localtax2_tx;
1972 $line->product_ref =
$prod->ref;
1973 $line->product_label =
$prod->label;
1974 $line->product_desc =
$prod->description;
1975 $line->fk_unit =
$prod->fk_unit;
1982 $line->date_end = $date_end;
1985 $this->lines[] = $line;
2017 public function fetch($id, $ref =
'', $ref_ext =
'', $notused =
'')
2020 if (empty($id) && empty($ref) && empty($ref_ext)) {
2024 $sql =
'SELECT c.rowid, c.entity, c.date_creation, c.ref, c.fk_soc, c.fk_user_author, c.fk_user_valid, c.fk_user_modif, c.fk_statut as status';
2025 $sql .=
', c.amount_ht, c.total_ht, c.total_ttc, c.total_tva, c.localtax1 as total_localtax1, c.localtax2 as total_localtax2, c.fk_cond_reglement, c.deposit_percent, c.fk_mode_reglement, c.fk_availability, c.fk_input_reason';
2026 $sql .=
', c.fk_account';
2027 $sql .=
', c.date_commande, c.date_valid, c.tms';
2028 $sql .=
', c.date_livraison as delivery_date';
2029 $sql .=
', c.fk_shipping_method';
2030 $sql .=
', c.fk_warehouse';
2031 $sql .=
', c.fk_projet as fk_project, c.source, c.facture as billed';
2032 $sql .=
', c.note_private, c.note_public, c.ref_client, c.ref_ext, c.model_pdf, c.last_main_doc, c.fk_delivery_address, c.extraparams';
2033 $sql .=
', c.fk_incoterms, c.location_incoterms';
2034 $sql .=
", c.fk_multicurrency, c.multicurrency_code, c.multicurrency_tx, c.multicurrency_total_ht, c.multicurrency_total_tva, c.multicurrency_total_ttc";
2035 $sql .=
", c.module_source, c.pos_source";
2036 $sql .=
", i.libelle as label_incoterms";
2037 $sql .=
', p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
2038 $sql .=
', cr.code as cond_reglement_code, cr.libelle as cond_reglement_libelle, cr.libelle_facture as cond_reglement_libelle_doc';
2039 $sql .=
', ca.code as availability_code, ca.label as availability_label';
2040 $sql .=
', dr.code as demand_reason_code';
2041 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as c';
2042 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_payment_term as cr ON c.fk_cond_reglement = cr.rowid';
2043 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_paiement as p ON c.fk_mode_reglement = p.id';
2044 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_availability as ca ON c.fk_availability = ca.rowid';
2045 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_input_reason as dr ON c.fk_input_reason = dr.rowid';
2046 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_incoterms as i ON c.fk_incoterms = i.rowid';
2049 $sql .=
" WHERE c.rowid = ".((int) $id);
2051 $sql .=
" WHERE c.entity IN (".getEntity(
'commande').
")";
2055 $sql .=
" AND c.ref = '".$this->db->escape($ref).
"'";
2058 $sql .=
" AND c.ref_ext = '".$this->db->escape($ref_ext).
"'";
2061 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
2062 $result = $this->db->query($sql);
2064 $obj = $this->db->fetch_object($result);
2066 $this->
id = $obj->rowid;
2067 $this->entity = $obj->entity;
2069 $this->
ref = $obj->ref;
2070 $this->ref_client = $obj->ref_client;
2071 $this->ref_customer = $obj->ref_client;
2072 $this->ref_ext = $obj->ref_ext;
2074 $this->socid = $obj->fk_soc;
2075 $this->thirdparty =
null;
2077 $this->fk_project = $obj->fk_project;
2078 $this->project =
null;
2080 $this->statut = $obj->status;
2081 $this->
status = $obj->status;
2083 $this->user_author_id = $obj->fk_user_author;
2084 $this->user_creation_id = $obj->fk_user_author;
2085 $this->user_validation_id = $obj->fk_user_valid;
2086 $this->user_modification_id = $obj->fk_user_modif;
2087 $this->total_ht = $obj->total_ht;
2088 $this->total_tva = $obj->total_tva;
2089 $this->total_localtax1 = $obj->total_localtax1;
2090 $this->total_localtax2 = $obj->total_localtax2;
2091 $this->total_ttc = $obj->total_ttc;
2092 $this->
date = $this->db->jdate($obj->date_commande);
2093 $this->date_commande = $this->db->jdate($obj->date_commande);
2094 $this->date_creation = $this->db->jdate($obj->date_creation);
2095 $this->date_validation = $this->db->jdate($obj->date_valid);
2096 $this->date_modification = $this->db->jdate($obj->tms);
2097 $this->source = $obj->source;
2098 $this->billed = $obj->billed;
2099 $this->note = $obj->note_private;
2100 $this->note_private = $obj->note_private;
2101 $this->note_public = $obj->note_public;
2102 $this->model_pdf = $obj->model_pdf;
2103 $this->last_main_doc = $obj->last_main_doc;
2104 $this->mode_reglement_id = $obj->fk_mode_reglement;
2105 $this->mode_reglement_code = $obj->mode_reglement_code;
2106 $this->mode_reglement = $obj->mode_reglement_libelle;
2107 $this->cond_reglement_id = $obj->fk_cond_reglement;
2108 $this->cond_reglement_code = $obj->cond_reglement_code;
2109 $this->cond_reglement = $obj->cond_reglement_libelle;
2110 $this->cond_reglement_doc = $obj->cond_reglement_libelle_doc;
2111 $this->deposit_percent = $obj->deposit_percent;
2112 $this->fk_account = $obj->fk_account;
2113 $this->availability_id = $obj->fk_availability;
2114 $this->availability_code = $obj->availability_code;
2116 $this->demand_reason_id = $obj->fk_input_reason;
2117 $this->demand_reason_code = $obj->demand_reason_code;
2118 $this->delivery_date = $this->db->jdate($obj->delivery_date);
2119 $this->shipping_method_id = ($obj->fk_shipping_method > 0) ? $obj->fk_shipping_method :
null;
2120 $this->warehouse_id = ($obj->fk_warehouse > 0) ? $obj->fk_warehouse :
null;
2121 $this->fk_delivery_address = $obj->fk_delivery_address;
2122 $this->module_source = $obj->module_source;
2123 $this->pos_source = $obj->pos_source;
2126 $this->fk_incoterms = $obj->fk_incoterms;
2127 $this->location_incoterms = $obj->location_incoterms;
2128 $this->label_incoterms = $obj->label_incoterms;
2131 $this->fk_multicurrency = $obj->fk_multicurrency;
2132 $this->multicurrency_code = $obj->multicurrency_code;
2133 $this->multicurrency_tx = $obj->multicurrency_tx;
2134 $this->multicurrency_total_ht = $obj->multicurrency_total_ht;
2135 $this->multicurrency_total_tva = $obj->multicurrency_total_tva;
2136 $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc;
2138 $this->extraparams = !empty($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) : array();
2140 $this->lines = array();
2146 $this->db->free($result);
2155 $this->error =
'Order with id '.$id.
' not found sql='.$sql;
2159 $this->error = $this->db->error();
2177 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
2178 include_once DOL_DOCUMENT_ROOT.
'/core/class/discount.class.php';
2183 $result = $remise->fetch($idremise);
2186 if ($remise->fk_facture) {
2187 $this->error = $langs->trans(
"ErrorDiscountAlreadyUsed");
2188 $this->db->rollback();
2194 $line->fk_commande = $this->id;
2195 $line->fk_remise_except = $remise->id;
2196 $line->desc = $remise->description;
2197 $line->vat_src_code = $remise->vat_src_code;
2198 $line->tva_tx = $remise->tva_tx;
2199 $line->localtax1_tx = $remise->localtax1_tx;
2200 $line->localtax1_type = $remise->localtax1_type;
2201 $line->localtax2_tx = $remise->localtax1_tx;
2202 $line->localtax2_type = $remise->localtax1_type;
2203 $line->subprice = -(float) $remise->amount_ht;
2204 $line->price = -(float) $remise->amount_ht;
2205 $line->fk_product = 0;
2207 $line->remise_percent = 0;
2209 $line->info_bits = 2;
2211 $line->total_ht = -(float) $remise->amount_ht;
2212 $line->total_tva = -(float) $remise->amount_tva;
2213 $line->total_ttc = -(float) $remise->amount_ttc;
2214 $line->total_localtax1 = -(float) $remise->total_localtax1;
2215 $line->total_localtax2 = -(float) $remise->total_localtax2;
2217 $result = $line->insert();
2221 $this->db->commit();
2224 $this->db->rollback();
2229 $this->db->rollback();
2233 $this->db->rollback();
2247 public function fetch_lines($only_product = 0, $loadalsotranslation = 0)
2250 $this->lines = array();
2252 $sql =
'SELECT l.rowid, l.fk_product, l.fk_parent_line, l.product_type, l.fk_commande, l.label as custom_label, l.description, l.price, l.qty, l.vat_src_code, l.tva_tx, l.ref_ext,';
2253 $sql .=
' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.fk_remise_except, l.remise_percent, l.subprice, l.subprice_ttc, l.fk_product_fournisseur_price as fk_fournprice, l.buy_price_ht as pa_ht, l.rang, l.info_bits, l.special_code,';
2254 $sql .=
' l.total_ht, l.total_ttc, l.total_tva, l.total_localtax1, l.total_localtax2, l.date_start, l.date_end,';
2255 $sql .=
' l.fk_unit, l.extraparams,';
2256 $sql .=
' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_subprice_ttc, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,';
2257 $sql .=
' p.ref as product_ref, p.description as product_desc, p.fk_product_type, p.label as product_label, p.tosell as product_tosell, p.tobuy as product_tobuy, p.tobatch as product_tobatch, p.barcode as product_barcode,';
2258 $sql .=
' p.customcode, p.fk_country as country_id, c.code as country_code,';
2259 $sql .=
' p.weight, p.weight_units, p.volume, p.volume_units, p.packaging';
2260 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element_line.
' as l';
2261 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON (p.rowid = l.fk_product)';
2262 $sql .=
' LEFT JOIN '.MAIN_DB_PREFIX.
'c_country as c ON c.rowid = p.fk_country';
2263 $sql .=
' WHERE l.fk_commande = '.((int) $this->
id);
2264 if ($only_product) {
2265 $sql .=
' AND p.fk_product_type = 0';
2267 $sql .=
' ORDER BY l.rang, l.rowid';
2269 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
2270 $result = $this->db->query($sql);
2272 $num = $this->db->num_rows($result);
2276 $objp = $this->db->fetch_object($result);
2280 $line->rowid = $objp->rowid;
2281 $line->id = $objp->rowid;
2282 $line->fk_commande = $objp->fk_commande;
2283 $line->commande_id = $objp->fk_commande;
2284 $line->label = $objp->custom_label;
2285 $line->desc = $objp->description;
2286 $line->description = $objp->description;
2287 $line->product_type = $objp->product_type;
2288 $line->qty = $objp->qty;
2289 $line->ref_ext = $objp->ref_ext;
2291 $line->vat_src_code = $objp->vat_src_code;
2292 $line->tva_tx = $objp->tva_tx;
2293 $line->localtax1_tx = $objp->localtax1_tx;
2294 $line->localtax2_tx = $objp->localtax2_tx;
2295 $line->localtax1_type = $objp->localtax1_type;
2296 $line->localtax2_type = $objp->localtax2_type;
2297 $line->total_ht = $objp->total_ht;
2298 $line->total_ttc = $objp->total_ttc;
2299 $line->total_tva = $objp->total_tva;
2300 $line->total_localtax1 = $objp->total_localtax1;
2301 $line->total_localtax2 = $objp->total_localtax2;
2302 $line->subprice = (float) $objp->subprice;
2303 $line->subprice_ttc = (float) $objp->subprice_ttc;
2304 $line->fk_remise_except = $objp->fk_remise_except;
2305 $line->remise_percent = $objp->remise_percent;
2306 $line->price = $objp->price;
2307 $line->fk_product = $objp->fk_product;
2308 $line->fk_fournprice = $objp->fk_fournprice;
2309 $marginInfos =
getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $line->fk_fournprice, $objp->pa_ht);
2310 $line->pa_ht = $marginInfos[0];
2311 $line->marge_tx = $marginInfos[1];
2312 $line->marque_tx = $marginInfos[2];
2313 $line->rang = $objp->rang;
2314 $line->info_bits = $objp->info_bits;
2315 $line->special_code = $objp->special_code;
2316 $line->fk_parent_line = $objp->fk_parent_line;
2318 $line->ref = $objp->product_ref;
2319 $line->libelle = $objp->product_label;
2321 $line->product_ref = $objp->product_ref;
2322 $line->product_label = $objp->product_label;
2323 $line->product_tosell = $objp->product_tosell;
2324 $line->product_tobuy = $objp->product_tobuy;
2325 $line->product_desc = $objp->product_desc;
2326 $line->product_tobatch = $objp->product_tobatch;
2327 $line->product_barcode = $objp->product_barcode;
2328 $line->product_custom_code = $objp->customcode;
2329 $line->product_custom_country_id = $objp->country_id;
2330 $line->product_custom_country_code = $objp->country_code;
2332 $line->fk_product_type = $objp->fk_product_type;
2333 $line->fk_unit = $objp->fk_unit;
2335 $line->extraparams = !empty($objp->extraparams) ? (array) json_decode($objp->extraparams,
true) : array();
2337 $line->weight = $objp->weight;
2338 $line->weight_units = $objp->weight_units;
2339 $line->volume = $objp->volume;
2340 $line->volume_units = $objp->volume_units;
2341 $line->packaging = $objp->packaging;
2343 $line->date_start = $this->db->jdate($objp->date_start);
2344 $line->date_end = $this->db->jdate($objp->date_end);
2347 $line->fk_multicurrency = $objp->fk_multicurrency;
2348 $line->multicurrency_code = $objp->multicurrency_code;
2349 $line->multicurrency_subprice = $objp->multicurrency_subprice;
2350 $line->multicurrency_subprice_ttc = $objp->multicurrency_subprice_ttc;
2351 $line->multicurrency_total_ht = $objp->multicurrency_total_ht;
2352 $line->multicurrency_total_tva = $objp->multicurrency_total_tva;
2353 $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc;
2355 $line->fetch_optionals();
2358 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($objp->fk_product) && !empty($loadalsotranslation)) {
2359 $tmpproduct =
new Product($this->db);
2360 $tmpproduct->fetch($objp->fk_product);
2361 $tmpproduct->getMultiLangs();
2363 $line->multilangs = $tmpproduct->multilangs;
2366 $this->lines[$i] = $line;
2371 $this->db->free($result);
2375 $this->error = $this->db->error();
2389 foreach ($this->lines as $line) {
2390 if ($line->product_type == 0) {
2405 foreach ($this->lines as $line) {
2406 if ($line->product_type == 1) {
2422 $sql =
'SELECT COUNT(DISTINCT ed.fk_expedition) as nb';
2423 $sql .=
' FROM '.MAIN_DB_PREFIX.
'expeditiondet as ed,';
2424 $sql .=
' '.MAIN_DB_PREFIX.$this->table_element_line.
' as cd';
2426 $sql .=
' ed.fk_elementdet = cd.rowid';
2427 $sql .=
' AND cd.fk_commande = '.((int) $this->
id);
2430 dol_syslog(get_class($this).
"::getNbOfShipments", LOG_DEBUG);
2431 $resql = $this->db->query($sql);
2433 $obj = $this->db->fetch_object($resql);
2435 $nb = (int) $obj->nb;
2438 $this->db->free($resql);
2441 $this->error = $this->db->lasterror();
2456 $this->expeditions = array();
2458 $sql =
'SELECT cd.rowid, cd.fk_product,';
2459 $sql .=
' sum(ed.qty) as qty';
2460 $sql .=
' FROM '.MAIN_DB_PREFIX.
'expeditiondet as ed,';
2461 if ($filtre_statut >= 0) {
2462 $sql .=
' '.MAIN_DB_PREFIX.
'expedition as e,';
2464 $sql .=
' '.MAIN_DB_PREFIX.$this->table_element_line.
' as cd';
2466 if ($filtre_statut >= 0) {
2467 $sql .=
' ed.fk_expedition = e.rowid AND';
2469 $sql .=
' ed.fk_elementdet = cd.rowid';
2470 $sql .=
' AND cd.fk_commande = '.((int) $this->
id);
2471 if ($fk_product > 0) {
2472 $sql .=
' AND cd.fk_product = '.((int) $fk_product);
2474 if ($filtre_statut >= 0) {
2475 $sql .=
' AND e.fk_statut >= '.((int) $filtre_statut);
2477 $sql .=
' GROUP BY cd.rowid, cd.fk_product';
2480 dol_syslog(get_class($this).
"::loadExpeditions", LOG_DEBUG);
2481 $resql = $this->db->query($sql);
2483 $num = $this->db->num_rows($resql);
2486 $obj = $this->db->fetch_object($resql);
2487 $this->expeditions[$obj->rowid] = $obj->qty;
2490 $this->db->free($resql);
2493 $this->error = $this->db->lasterror();
2505 $sql =
'SELECT count(*)';
2506 $sql .=
' FROM '.MAIN_DB_PREFIX.
'expedition as e';
2507 $sql .=
', '.MAIN_DB_PREFIX.
'element_element as el';
2508 $sql .=
' WHERE el.fk_source = '.((int) $this->
id);
2509 $sql .=
" AND el.sourcetype = 'commande'";
2510 $sql .=
" AND el.fk_target = e.rowid";
2511 $sql .=
" AND el.targettype = 'shipping'";
2513 $resql = $this->db->query($sql);
2515 $row = $this->db->fetch_row($resql);
2534 if ($this->
status == self::STATUS_DRAFT) {
2540 $line->context = $this->context;
2543 $line->fetch($lineid);
2548 if ($id > 0 && (
int) $line->fk_commande !== (
int) $id) {
2549 $this->db->rollback();
2550 $this->error =
'ErrorLineIDDoesNotMatchWithObjectID';
2555 $staticline = clone $line;
2556 $line->oldline = $staticline;
2558 if ($line->delete($user) > 0) {
2562 $this->db->commit();
2565 $this->db->rollback();
2566 $this->error = $this->db->lasterror();
2570 $this->db->rollback();
2575 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
2594 dol_syslog(get_class($this).
"::set_remise is deprecated, use setDiscount instead", LOG_NOTICE);
2596 return $this->
setDiscount($user, $remise, $notrigger);
2609 $remise = trim((
string) $remise) ? trim((
string) $remise) : 0;
2611 if ($user->hasRight(
'commande',
'creer')) {
2618 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2619 $sql .=
' SET remise_percent = '.((float) $remise);
2620 $sql .=
' WHERE rowid = '.((int) $this->
id).
' AND fk_statut = '.((int) self::STATUS_DRAFT);
2623 $resql = $this->db->query($sql);
2625 $this->errors[] = $this->db->error();
2630 $this->oldcopy = clone $this;
2631 $this->remise_percent = $remise;
2635 if (!$notrigger && empty($error)) {
2637 $result = $this->call_trigger(
'ORDER_MODIFY', $user);
2645 $this->db->commit();
2648 foreach ($this->errors as $errmsg) {
2649 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2650 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2652 $this->db->rollback();
2673 if ($user->hasRight(
'commande',
'creer')) {
2678 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2679 $sql .=
" SET date_commande = ".($date ?
"'".$this->db->idate($date).
"'" :
'null');
2680 $sql .=
" WHERE rowid = ".((int) $this->
id).
" AND fk_statut = ".((int) self::STATUS_DRAFT);
2683 $resql = $this->db->query($sql);
2685 $this->errors[] = $this->db->error();
2690 $this->oldcopy = clone $this;
2691 $this->
date = $date;
2694 if (!$notrigger && empty($error)) {
2696 $result = $this->call_trigger(
'ORDER_MODIFY', $user);
2704 $this->db->commit();
2707 foreach ($this->errors as $errmsg) {
2708 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2709 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2711 $this->db->rollback();
2745 if ($user->hasRight(
'commande',
'creer')) {
2750 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element;
2751 $sql .=
" SET date_livraison = ".($delivery_date ?
"'".$this->db->idate($delivery_date).
"'" :
'null');
2752 $sql .=
" WHERE rowid = ".((int) $this->
id);
2755 $resql = $this->db->query($sql);
2757 $this->errors[] = $this->db->error();
2762 $this->oldcopy = clone $this;
2763 $this->delivery_date = $delivery_date;
2766 if (!$notrigger && empty($error)) {
2768 $result = $this->call_trigger(
'ORDER_MODIFY', $user);
2776 $this->db->commit();
2779 foreach ($this->errors as $errmsg) {
2780 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2781 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2783 $this->db->rollback();
2805 public function liste_array($shortlist = 0, $draft = 0, $excluser =
null, $socid = 0, $limit = 0, $offset = 0, $sortfield =
'c.date_commande', $sortorder =
'DESC')
2812 $sql =
"SELECT s.rowid, s.nom as name, s.client,";
2813 $sql .=
" c.rowid as cid, c.ref";
2814 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
2815 $sql .=
", sc.fk_soc, sc.fk_user";
2817 $sql .=
" FROM ".MAIN_DB_PREFIX.
"societe as s, ".MAIN_DB_PREFIX.$this->table_element.
" as c";
2818 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
2819 $sql .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
2821 $sql .=
" WHERE c.entity IN (".getEntity(
'commande').
")";
2822 $sql .=
" AND c.fk_soc = s.rowid";
2823 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
2824 $sql .=
" AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
2827 $sql .=
" AND s.rowid = ".((int) $socid);
2830 $sql .=
" AND c.fk_statut = ".self::STATUS_DRAFT;
2832 if (is_object($excluser)) {
2833 $sql .=
" AND c.fk_user_author <> ".((int) $excluser->id);
2835 $sql .= $this->db->order($sortfield, $sortorder);
2836 $sql .= $this->db->plimit($limit, $offset);
2838 $result = $this->db->query($sql);
2840 $numc = $this->db->num_rows($result);
2843 while ($i < $numc) {
2844 $obj = $this->db->fetch_object($result);
2846 if ($shortlist == 1) {
2847 $ga[$obj->cid] = $obj->ref;
2848 } elseif ($shortlist == 2) {
2849 $ga[$obj->cid] = $obj->ref.
' ('.$obj->name.
')';
2851 $ga[$i][
'id'] = $obj->cid;
2852 $ga[$i][
'ref'] = $obj->ref;
2853 $ga[$i][
'name'] = $obj->name;
2876 dol_syslog(
'Commande::availability('.$availability_id.
')');
2877 if ($this->
status >= self::STATUS_DRAFT) {
2882 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2883 $sql .=
' SET fk_availability = '.((int) $availability_id);
2884 $sql .=
' WHERE rowid='.((int) $this->
id);
2887 $resql = $this->db->query($sql);
2889 $this->errors[] = $this->db->error();
2894 $this->oldcopy = clone $this;
2895 $this->availability_id = $availability_id;
2898 if (!$notrigger && empty($error)) {
2900 $result = $this->call_trigger(
'ORDER_MODIFY', $user);
2908 $this->db->commit();
2911 foreach ($this->errors as $errmsg) {
2912 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2913 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2915 $this->db->rollback();
2919 $error_str =
'Command status do not meet requirement '.$this->status;
2921 $this->error = $error_str;
2922 $this->errors[] = $this->error;
2940 dol_syslog(
'Commande::demand_reason('.$demand_reason_id.
')');
2941 if ($this->
status >= self::STATUS_DRAFT) {
2946 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element;
2947 $sql .=
' SET fk_input_reason = '.((int) $demand_reason_id);
2948 $sql .=
' WHERE rowid='.((int) $this->
id);
2951 $resql = $this->db->query($sql);
2953 $this->errors[] = $this->db->error();
2958 $this->oldcopy = clone $this;
2959 $this->demand_reason_id = $demand_reason_id;
2962 if (!$notrigger && empty($error)) {
2964 $result = $this->call_trigger(
'ORDER_MODIFY', $user);
2972 $this->db->commit();
2975 foreach ($this->errors as $errmsg) {
2976 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
2977 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
2979 $this->db->rollback();
2983 $error_str =
'order status do not meet requirement '.$this->status;
2985 $this->error = $error_str;
2986 $this->errors[] = $this->error;
3003 if ($user->hasRight(
'commande',
'creer')) {
3008 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET';
3009 $sql .=
' ref_client = '.(empty($ref_client) ?
'NULL' :
"'".$this->db->escape($ref_client).
"'");
3010 $sql .=
' WHERE rowid = '.((int) $this->
id);
3012 dol_syslog(__METHOD__.
' this->id='.$this->id.
', ref_client='.$ref_client, LOG_DEBUG);
3013 $resql = $this->db->query($sql);
3015 $this->errors[] = $this->db->error();
3020 $this->oldcopy = clone $this;
3021 $this->ref_client = $ref_client;
3022 $this->ref_customer = $ref_client;
3025 if (!$notrigger && empty($error)) {
3027 $result = $this->call_trigger(
'ORDER_MODIFY', $user);
3034 $this->db->commit();
3037 foreach ($this->errors as $errmsg) {
3038 dol_syslog(__METHOD__.
' Error: '.$errmsg, LOG_ERR);
3039 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3041 $this->db->rollback();
3060 if ($this->billed) {
3066 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET facture = 1';
3069 dol_syslog(get_class($this).
"::classifyBilled", LOG_DEBUG);
3070 if ($this->db->query($sql)) {
3071 $this->oldcopy = clone $this;
3074 if (!$notrigger && empty($error)) {
3076 $result = $this->call_trigger(
'ORDER_CLASSIFY_BILLED', $user);
3084 $this->db->commit();
3087 foreach ($this->errors as $errmsg) {
3088 dol_syslog(get_class($this).
"::classifyBilled ".$errmsg, LOG_ERR);
3089 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3091 $this->db->rollback();
3095 $this->error = $this->db->error();
3096 $this->db->rollback();
3114 $sql =
'UPDATE '.MAIN_DB_PREFIX.$this->table_element.
' SET facture = 0';
3117 dol_syslog(get_class($this).
"::classifyUnBilled", LOG_DEBUG);
3118 if ($this->db->query($sql)) {
3119 $this->oldcopy = clone $this;
3122 if (!$notrigger && empty($error)) {
3124 $result = $this->call_trigger(
'ORDER_CLASSIFY_UNBILLED', $user);
3134 $this->db->commit();
3137 foreach ($this->errors as $errmsg) {
3138 dol_syslog(get_class($this).
"::classifyUnBilled ".$errmsg, LOG_ERR);
3139 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3141 $this->db->rollback();
3145 $this->error = $this->db->error();
3146 $this->db->rollback();
3182 public function updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1 = 0.0, $txlocaltax2 = 0.0, $price_base_type =
'HT', $info_bits = 0,
$date_start =
'', $date_end =
'', $type = 0, $fk_parent_line = 0, $skip_update_total = 0, $fk_fournprice =
null, $pa_ht = 0, $label =
'', $special_code = 0, $array_options = array(), $fk_unit =
null, $pu_ht_devise = 0, $notrigger = 0, $ref_ext =
'', $rang = 0)
3184 global
$mysoc, $langs, $user;
3187 $this->error =
'ErrorLineIDDoesNotMatchWithObjectID';
3191 dol_syslog(get_class($this).
"::updateline id=$rowid, desc=$desc, pu=$pu, qty=$qty, remise_percent=$remise_percent, txtva=$txtva, txlocaltax1=$txlocaltax1, txlocaltax2=$txlocaltax2, price_base_type=$price_base_type, info_bits=$info_bits, date_start=$date_start, date_end=$date_end, type=$type, fk_parent_line=$fk_parent_line, pa_ht=$pa_ht, special_code=$special_code, ref_ext=$ref_ext");
3192 include_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
3199 if (empty($info_bits)) {
3202 if (empty($txtva)) {
3205 if (empty($txlocaltax1)) {
3208 if (empty($txlocaltax2)) {
3211 if (empty($remise_percent)) {
3212 $remise_percent = 0;
3214 if (empty($qty) && empty($special_code)) {
3217 if (!empty($qty) && $special_code == 3) {
3220 if (empty($ref_ext)) {
3225 $langs->load(
"errors");
3226 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
3230 $remise_percent = (float)
price2num($remise_percent);
3234 $pu_ht_devise =
price2num($pu_ht_devise);
3235 if (!preg_match(
'/\((.*)\)/', (
string) $txtva)) {
3238 $txlocaltax1 = (float)
price2num($txlocaltax1);
3239 $txlocaltax2 = (float)
price2num($txlocaltax2);
3252 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
3253 $vat_src_code = $reg[1];
3254 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
3261 if ($tmpline->fetch($rowid) > 0) {
3263 if ($newqty != $qty) {
3265 setEventMessages($langs->trans(
'QtyRecalculatedWithPackaging'),
null,
'warnings');
3270 $tabprice =
calcul_price_total($qty, (
float) $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type,
$mysoc, $localtaxes_type, 100, $this->multicurrency_tx, (
float) $pu_ht_devise);
3272 $total_ht = $tabprice[0];
3273 $total_tva = $tabprice[1];
3274 $total_ttc = $tabprice[2];
3275 $total_localtax1 = $tabprice[9];
3276 $total_localtax2 = $tabprice[10];
3277 $pu_ht = $tabprice[3];
3278 $pu_tva = $tabprice[4];
3279 $pu_ttc = $tabprice[5];
3282 $multicurrency_total_ht = $tabprice[16];
3283 $multicurrency_total_tva = $tabprice[17];
3284 $multicurrency_total_ttc = $tabprice[18];
3285 $pu_ht_devise = $tabprice[19];
3289 $line->fetch($rowid);
3290 $line->fetch_optionals();
3292 if (!empty($line->fk_product)) {
3293 $product =
new Product($this->db);
3294 $result = $product->fetch($line->fk_product);
3295 $product_type = $product->type;
3297 if (
getDolGlobalString(
'STOCK_MUST_BE_ENOUGH_FOR_ORDER') && $product->isStockManaged()) {
3299 $productChildrenNb = 0;
3301 $productChildrenNb = $product->hasFatherOrChild(1);
3303 if ($productChildrenNb > 0) {
3305 $product_stock =
null;
3306 $product->loadStockForVirtualProduct(
'warehouseopen', $qty);
3307 foreach ($product->stock_warehouse as $componentStockWarehouse) {
3308 if ($product_stock ===
null) {
3309 $product_stock = $componentStockWarehouse->real;
3311 $product_stock = min($product_stock, $componentStockWarehouse->real);
3314 if ($product_stock ===
null) {
3318 $product_stock = $product->stock_reel;
3321 if ($product_stock < $qty) {
3322 $langs->load(
"errors");
3323 $this->error = $langs->trans(
'ErrorStockIsNotEnoughToAddProductOnOrder', (
string) $product->ref);
3324 $this->errors[] = $this->error;
3326 dol_syslog(get_class($this).
"::addline error=Product ".$product->ref.
": ".$this->error, LOG_ERR);
3328 $this->db->rollback();
3334 $staticline = clone $line;
3336 $line->oldline = $staticline;
3337 $this->line = $line;
3338 $this->line->context = $this->context;
3339 $this->line->rang = $rang;
3342 if (!empty($fk_parent_line) && !empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line) {
3343 $rangmax = $this->
line_max($fk_parent_line);
3344 $this->line->rang = $rangmax + 1;
3348 $this->line->id = $rowid;
3349 $this->line->label = $label;
3350 $this->line->desc = $desc;
3351 $this->line->qty = $qty;
3352 $this->line->ref_ext = $ref_ext;
3354 $this->line->vat_src_code = $vat_src_code;
3355 $this->line->tva_tx = $txtva;
3356 $this->line->localtax1_tx = $txlocaltax1;
3357 $this->line->localtax2_tx = $txlocaltax2;
3358 $this->line->localtax1_type = empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0];
3359 $this->line->localtax2_type = empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2];
3360 $this->line->remise_percent = $remise_percent;
3361 $this->line->subprice = (float) $pu_ht;
3362 $this->line->info_bits = $info_bits;
3363 $this->line->special_code = $special_code;
3364 $this->line->total_ht = (float) $total_ht;
3365 $this->line->total_tva = (float) $total_tva;
3366 $this->line->total_localtax1 = (float) $total_localtax1;
3367 $this->line->total_localtax2 = (float) $total_localtax2;
3368 $this->line->total_ttc = (float) $total_ttc;
3370 $this->line->date_end = $date_end;
3371 $this->line->product_type = $type;
3372 $this->line->fk_parent_line = $fk_parent_line;
3373 $this->line->skip_update_total = $skip_update_total;
3374 $this->line->fk_unit = $fk_unit;
3376 $this->line->fk_fournprice = $fk_fournprice;
3377 $this->line->pa_ht = $pa_ht;
3380 $this->line->multicurrency_subprice = (float) $pu_ht_devise;
3381 $this->line->multicurrency_total_ht = (float) $multicurrency_total_ht;
3382 $this->line->multicurrency_total_tva = (float) $multicurrency_total_tva;
3383 $this->line->multicurrency_total_ttc = (float) $multicurrency_total_ttc;
3385 if (is_array($array_options) && count($array_options) > 0) {
3387 foreach ($array_options as $key => $value) {
3388 $this->line->array_options[$key] = $array_options[$key];
3392 $result = $this->line->update($user, $notrigger);
3395 if (!empty($fk_parent_line)) {
3402 $this->db->commit();
3407 $this->db->rollback();
3411 $this->error = get_class($this).
"::updateline Order status makes operation forbidden";
3412 $this->errors = array(
'OrderStatusMakeOperationForbidden');
3429 if (isset($this->
ref)) {
3430 $this->
ref = trim($this->
ref);
3432 if (isset($this->ref_client)) {
3433 $this->ref_client = trim($this->ref_client);
3435 if (isset($this->ref_customer)) {
3436 $this->ref_customer = trim($this->ref_customer);
3438 if (isset($this->note) || isset($this->note_private)) {
3439 $this->note_private = (isset($this->note_private) ? trim($this->note_private) : trim($this->note));
3441 if (isset($this->note_public)) {
3442 $this->note_public = trim($this->note_public);
3444 if (isset($this->model_pdf)) {
3445 $this->model_pdf = trim($this->model_pdf);
3447 if (isset($this->import_key)) {
3448 $this->import_key = trim($this->import_key);
3450 $delivery_date = $this->delivery_date;
3456 $sql =
"UPDATE ".MAIN_DB_PREFIX.$this->table_element.
" SET";
3458 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
3459 $sql .=
" ref_client=".(isset($this->ref_client) ?
"'".$this->db->escape($this->ref_client).
"'" :
"null").
",";
3460 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
3461 $sql .=
" fk_soc=".(isset($this->socid) ? ((int) $this->socid) :
"null").
",";
3462 $sql .=
" date_commande=".(strval($this->date_commande) !=
'' ?
"'".$this->db->idate($this->date_commande).
"'" :
'null').
",";
3463 $sql .=
" date_valid=".(strval($this->date_validation) !=
'' ?
"'".$this->db->idate($this->date_validation).
"'" :
'null').
",";
3465 $sql .=
" total_tva=".(isset($this->total_tva) ? ((float) $this->total_tva) :
"null").
",";
3466 $sql .=
" localtax1=".(isset($this->total_localtax1) ? ((float) $this->total_localtax1) :
"null").
",";
3467 $sql .=
" localtax2=".(isset($this->total_localtax2) ? ((float) $this->total_localtax2) :
"null").
",";
3468 $sql .=
" total_ht=".(isset($this->total_ht) ? ((float) $this->total_ht) :
"null").
",";
3469 $sql .=
" total_ttc=".(isset($this->total_ttc) ? ((float) $this->total_ttc) :
"null").
",";
3470 $sql .=
" fk_statut=".(isset($this->
status) ? ((int) $this->
status) :
"null").
",";
3471 $sql .=
" fk_user_modif=".(isset($user->id) ? ((int) $user->id) :
"null").
",";
3472 $sql .=
" fk_user_valid=".((isset($this->user_validation_id) && $this->user_validation_id > 0) ? ((
int) $this->user_validation_id) :
"null").
",";
3473 $sql .=
" fk_projet=".(isset($this->fk_project) ? ((int) $this->fk_project) :
"null").
",";
3474 $sql .=
" fk_cond_reglement=".(isset($this->cond_reglement_id) ? ((int) $this->cond_reglement_id) :
"null").
",";
3475 $sql .=
" deposit_percent=".(!empty($this->deposit_percent) ?
"'".$this->db->escape($this->deposit_percent).
"'" :
"null").
",";
3476 $sql .=
" fk_mode_reglement=".(isset($this->mode_reglement_id) ? ((int) $this->mode_reglement_id) :
"null").
",";
3477 $sql .=
" date_livraison=".(strval($this->delivery_date) !=
'' ?
"'".$this->db->idate($this->delivery_date).
"'" :
'null').
",";
3478 $sql .=
" fk_shipping_method=".(isset($this->shipping_method_id) ? ((int) $this->shipping_method_id) :
"null").
",";
3479 $sql .=
" fk_account=".($this->fk_account > 0 ? ((int) $this->fk_account) :
"null").
",";
3480 $sql .=
" fk_input_reason=".($this->demand_reason_id > 0 ? ((int) $this->demand_reason_id) :
"null").
",";
3481 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
3482 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
3483 $sql .=
" model_pdf=".(isset($this->model_pdf) ?
"'".$this->db->escape($this->model_pdf).
"'" :
"null").
",";
3484 $sql .=
" fk_warehouse=".($this->warehouse_id > 0 ? ((int) $this->warehouse_id) :
"null").
",";
3485 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null").
",";
3486 $sql .=
" module_source = ".(isset($this->module_source) ?
"'".$this->db->escape($this->module_source).
"'" :
"null").
",";
3487 $sql .=
" pos_source = ".(isset($this->pos_source) ?
"'".$this->db->escape($this->pos_source).
"'" :
"null");
3488 $sql .=
" WHERE rowid=".((int) $this->
id);
3492 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
3493 $resql = $this->db->query($sql);
3496 $this->errors[] =
"Error ".$this->db->lasterror();
3506 if (!$error && !$notrigger) {
3508 $result = $this->call_trigger(
'ORDER_MODIFY', $user);
3517 foreach ($this->errors as $errmsg) {
3518 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
3519 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
3521 $this->db->rollback();
3524 $this->db->commit();
3536 public function delete($user, $notrigger = 0)
3538 global
$conf, $langs;
3539 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
3543 dol_syslog(get_class($this).
"::delete ".$this->
id, LOG_DEBUG);
3549 $result = $this->call_trigger(
'ORDER_DELETE', $user);
3558 $this->errors[] = $langs->trans(
'SomeShipmentExists');
3564 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"categorie_order";
3565 $sql .=
" WHERE fk_order = ".((int) $this->
id);
3567 $result = $this->db->query($sql);
3570 $this->errors[] = $this->db->lasterror();
3575 if (!$error && !empty($this->table_element_line)) {
3576 $tabletodelete = $this->table_element_line;
3577 $sqlef =
"DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete.
"_extrafields WHERE fk_object IN (SELECT rowid FROM ".MAIN_DB_PREFIX.$tabletodelete.
" WHERE ".$this->fk_element.
" = ".((int) $this->
id).
")";
3578 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete.
" WHERE ".$this->fk_element.
" = ".((int) $this->
id);
3579 if (!$this->db->query($sqlef) || !$this->db->query($sql)) {
3581 $this->error = $this->db->lasterror();
3582 $this->errors[] = $this->error;
3583 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
3608 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
3614 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element.
" WHERE rowid = ".((int) $this->
id);
3615 $res = $this->db->query($sql);
3618 $this->error = $this->db->lasterror();
3619 $this->errors[] = $this->error;
3620 dol_syslog(get_class($this).
"::delete error ".$this->error, LOG_ERR);
3636 if ($conf->commande->multidir_output[$this->entity] && !empty($this->
ref)) {
3637 $dir =
$conf->commande->multidir_output[$this->entity].
"/".$ref;
3638 $file = $dir.
"/".$ref.
".pdf";
3639 if (file_exists($file)) {
3643 $this->error =
'ErrorFailToDeleteFile';
3644 $this->errors[] = $this->error;
3645 $this->db->rollback();
3649 if (file_exists($dir)) {
3652 $this->error =
'ErrorFailToDeleteDir';
3653 $this->errors[] = $this->error;
3654 $this->db->rollback();
3662 dol_syslog(get_class($this).
"::delete ".$this->
id.
" by ".$user->id, LOG_DEBUG);
3663 $this->db->commit();
3666 $this->db->rollback();
3683 global
$conf, $langs, $hookmanager;
3687 $sql =
"SELECT c.rowid, c.date_creation as datec, c.date_commande, c.date_livraison as delivery_date, c.fk_statut, c.total_ht";
3688 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as c";
3689 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
3690 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON c.fk_soc = sc.fk_soc";
3691 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
3694 $sql .= $clause.
" c.entity IN (".
getEntity(
'commande').
")";
3696 if ($mode ==
'toship') {
3698 $sql .=
" AND c.fk_statut IN (" . self::STATUS_VALIDATED .
"," . self::STATUS_SHIPMENTONPROCESS .
")";
3700 if ($mode ==
'tobill') {
3702 $sql .=
" AND c.fk_statut IN (" . self::STATUS_VALIDATED .
"," . self::STATUS_SHIPMENTONPROCESS .
", " . self::STATUS_CLOSED .
") AND c.facture = 0";
3704 if ($mode ==
'shippedtobill') {
3706 $sql .=
" AND c.fk_statut IN (" . self::STATUS_CLOSED .
") AND c.facture = 0";
3709 $sql .=
" AND c.fk_soc = ".((int) $user->socid);
3712 $parameters = array(
'socid' => $user->socid);
3713 $reshook = $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $this);
3714 $sql .= $hookmanager->resPrint;
3715 $resql = $this->db->query($sql);
3718 $label = $labelShort = $url =
'';
3719 if ($mode ==
'toship') {
3720 $delay_warning =
$conf->commande->client->warning_delay / 60 / 60 / 24;
3721 $url = DOL_URL_ROOT.
'/commande/list.php?search_status=-2&mainmenu=commercial&leftmenu=orders';
3722 $label = $langs->transnoentitiesnoconv(
"OrdersToProcess");
3723 $labelShort = $langs->transnoentitiesnoconv(
"Opened");
3725 if ($mode ==
'tobill') {
3726 $url = DOL_URL_ROOT.
'/commande/list.php?search_status=-3&search_billed=0&mainmenu=commercial&leftmenu=orders';
3727 $label = $langs->trans(
"OrdersToBill");
3728 $labelShort = $langs->trans(
"ToBill");
3730 if ($mode ==
'shippedtobill') {
3731 $url = DOL_URL_ROOT.
'/commande/list.php?search_status=3&search_billed=0&mainmenu=commercial&leftmenu=orders';
3732 $label = $langs->trans(
"OrdersToBill");
3733 $labelShort = $langs->trans(
"StatusOrderDelivered").
' '.$langs->trans(
"and").
' '.$langs->trans(
"ToBill");
3738 $response->warning_delay = $delay_warning;
3739 $response->label = $label;
3740 $response->labelShort = $labelShort;
3741 $response->url = $url;
3742 $response->url_late = DOL_URL_ROOT.
'/commande/list.php?search_option=late&mainmenu=commercial&leftmenu=orders';
3745 $generic_commande =
new Commande($this->db);
3747 while ($obj = $this->db->fetch_object($resql)) {
3748 $response->nbtodo++;
3749 $response->total += $obj->total_ht;
3751 $generic_commande->status = $obj->fk_statut;
3752 $generic_commande->date = $this->db->jdate($obj->date_commande);
3753 $generic_commande->delivery_date = $this->db->jdate($obj->delivery_date);
3755 if ($mode ==
'toship' && $generic_commande->hasDelay()) {
3756 $response->nbtodolate++;
3762 $this->error = $this->db->error();
3776 $label = $langs->trans(
'OrderSource'.$this->source);
3778 if ($label ==
'OrderSource') {
3805 public function LibStatut($status, $billed, $mode, $donotshowbilled = 0)
3808 global $langs, $hookmanager;
3811 if (empty($donotshowbilled)) {
3812 $billedtext .= ($billed ?
' - '.$langs->transnoentitiesnoconv(
"Billed") :
'');
3814 $billedtextlong = ($billed ?
' - '.$langs->transnoentitiesnoconv(
"Billed") :
'');
3818 $paramsBadge = array(
'badgeParams' => array(
'attr' => array(
3819 'data-status-element' => $this->element,
3820 'data-billed' => (
int) $billed,
3821 'data-status' => (
int) $status
3824 if ($status == self::STATUS_CANCELED) {
3825 $labelStatus = $langs->transnoentitiesnoconv(
'StatusOrderCanceled');
3826 $labelStatusShort = $langs->transnoentitiesnoconv(
'StatusOrderCanceledShort');
3827 $statusType =
'status9';
3828 } elseif ($status == self::STATUS_DRAFT) {
3829 $labelStatus = $langs->transnoentitiesnoconv(
'StatusOrderDraft');
3830 $labelStatusShort = $langs->transnoentitiesnoconv(
'StatusOrderDraftShort');
3831 $statusType =
'status0';
3832 } elseif ($status == self::STATUS_VALIDATED) {
3833 $labelStatus = $langs->transnoentitiesnoconv(
'StatusOrderValidated').$billedtextlong;
3834 $labelStatusShort = $langs->transnoentitiesnoconv(
'StatusOrderValidatedShort').$billedtext;
3835 $statusType =
'status1';
3836 } elseif ($status == self::STATUS_SHIPMENTONPROCESS) {
3837 $labelStatus = $langs->transnoentitiesnoconv(
'StatusOrderSent').$billedtextlong;
3838 $labelStatusShort = $langs->transnoentitiesnoconv(
'StatusOrderSentShort').$billedtext;
3839 $labelTooltip = $langs->transnoentitiesnoconv(
"StatusOrderSent");
3840 if (!empty($this->delivery_date)) {
3841 $labelTooltip .=
' - '.$langs->transnoentitiesnoconv(
"DateDeliveryPlanned").dol_print_date($this->delivery_date,
'day').$billedtext;
3843 $statusType =
'status4';
3844 } elseif ($status == self::STATUS_CLOSED) {
3845 $labelStatus = $langs->transnoentitiesnoconv(
'StatusOrderDelivered').$billedtextlong;
3846 $labelStatusShort = $langs->transnoentitiesnoconv(
'StatusOrderDeliveredShort').$billedtext;
3847 $statusType =
'status6';
3849 $labelStatus = $langs->transnoentitiesnoconv(
'Unknown');
3850 $labelStatusShort =
'';
3855 $paramsBadge[
'tooltip'] = $labelTooltip;
3857 $parameters = array(
3858 'status' => $status,
3860 'billed' => $billed,
3861 'donotshowbilled' => $donotshowbilled,
3862 'paramsBadge' => & $paramsBadge
3865 $reshook = $hookmanager->executeHooks(
'LibStatut', $parameters, $this);
3868 return $hookmanager->resPrint;
3871 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode,
'', $paramsBadge);
3883 global
$conf, $langs, $user;
3885 $langs->load(
'orders');
3887 $nofetch = !empty($params[
'nofetch']);
3890 return [
'optimize' => $langs->trans(
"Order")];
3893 if ($user->hasRight(
'commande',
'lire')) {
3894 $datas[
'picto'] =
img_picto(
'', $this->picto,
'', 0, 0, 0,
'',
'paddingrightonly').
'<u>'.$langs->trans(
"Order").
'</u>';
3895 if (isset($this->
status)) {
3896 $datas[
'status'] =
' '.$this->getLibStatut(5);
3898 $datas[
'Ref'] =
'<br><b>'.$langs->trans(
'Ref').
':</b> '.$this->ref;
3900 $langs->load(
'companies');
3901 if (empty($this->thirdparty)) {
3904 $datas[
'customer'] =
'<br><b>'.$langs->trans(
'Customer').
':</b> '.$this->thirdparty->getNomUrl(1,
'', 0, 1);
3906 $datas[
'RefCustomer'] =
'<br><b>'.$langs->trans(
'RefCustomer').
':</b> '.(empty($this->ref_customer) ? (empty($this->ref_client) ?
'' : $this->ref_client) : $this->ref_customer);
3908 $langs->load(
'project');
3909 if (is_null($this->project) || (is_object($this->project) && empty($this->project->id))) {
3911 if ($res > 0 && $this->project instanceof
Project) {
3912 $datas[
'project'] =
'<br><b>'.$langs->trans(
'Project').
':</b> '.$this->project->getNomUrl(1,
'', 0,
'1');
3916 if (!empty($this->total_ht)) {
3917 $datas[
'AmountHT'] =
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1,
$conf->currency);
3919 if (!empty($this->total_tva)) {
3920 $datas[
'VAT'] =
'<br><b>'.$langs->trans(
'VAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1,
$conf->currency);
3922 if (!empty($this->total_ttc)) {
3923 $datas[
'AmountTTC'] =
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1,
$conf->currency);
3925 if (!empty($this->
date)) {
3926 $datas[
'Date'] =
'<br><b>'.$langs->trans(
'Date').
':</b> '.
dol_print_date($this->
date,
'day');
3928 if (!empty($this->delivery_date)) {
3929 $datas[
'DeliveryDate'] =
'<br><b>'.$langs->trans(
'DeliveryDate').
':</b> '.
dol_print_date($this->delivery_date,
'dayhour');
3949 public function getNomUrl($withpicto = 0, $option =
'', $max = 0, $short = 0, $notooltip = 0, $save_lastsearch_value = -1, $addlinktonotes = 0, $target =
'')
3951 global
$conf, $langs, $user, $hookmanager;
3953 if (!empty(
$conf->dol_no_mouse_hover)) {
3959 if (
isModEnabled(
"shipping") && ($option ==
'1' || $option ==
'2')) {
3960 $baseurl = DOL_URL_ROOT .
'/expedition/shipment.php';
3962 $baseurl = DOL_URL_ROOT .
'/commande/card.php';
3964 $query = [
'id' => $this->id];
3965 if (!$user->hasRight(
'commande',
'lire')) {
3969 if ($option !==
'nolink') {
3971 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
3972 if ($save_lastsearch_value == -1 && isset($_SERVER[
"PHP_SELF"]) && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
3973 $add_save_lastsearch_values = 1;
3975 if ($add_save_lastsearch_values) {
3976 $query = array_merge($query, [
'save_lastsearch_values' => 1]);
3986 'objecttype' => $this->element,
3987 'option' => $option,
3990 $classfortooltip =
'classfortooltip';
3993 $classfortooltip =
'classforajaxtooltip';
3994 $dataparams =
' data-params="'.dol_escape_htmltag(json_encode($params)).
'"';
4001 if (empty($notooltip) && $user->hasRight(
'commande',
'lire')) {
4003 $label = $langs->trans(
"Order");
4004 $linkclose .=
' alt="'.dolPrintHTMLForAttribute($label).
'"';
4006 $linkclose .= ($label ?
' title="'.dolPrintHTMLForAttribute($label).
'"' :
' title="tocomplete"');
4007 $linkclose .= $dataparams.
' class="'.$classfortooltip.
'"';
4009 $target_value = array(
'_self',
'_blank',
'_parent',
'_top');
4010 if (in_array($target, $target_value)) {
4011 $linkclose .=
' target="'.dol_escape_htmltag($target).
'"';
4015 $linkstart =
'<a href="'.$url.
'"';
4016 $linkstart .= $linkclose.
'>';
4019 if ($option ===
'nolink') {
4024 $result .= $linkstart;
4026 $result .=
img_object(($notooltip ?
'' : $label), $this->picto, (($withpicto != 2) ?
'class="paddingright"' :
''), 0, 0, $notooltip ? 0 : 1);
4028 if ($withpicto != 2) {
4029 $result .= $this->ref;
4031 $result .= $linkend;
4033 if ($addlinktonotes) {
4034 $txttoshow = ($user->socid > 0 ? $this->note_public : $this->note_private);
4037 $result .=
' <span class="note inline-block">';
4038 $result .=
'<a href="'.DOL_URL_ROOT.
'/commande/note.php?id='.$this->
id.
'" class="classfortooltip" title="'.
dol_escape_htmltag($notetoshow).
'">';
4043 $result .=
'</span>';
4048 $hookmanager->initHooks(array($this->element .
'dao'));
4049 $parameters = array(
'id' => $this->
id,
'getnomurl' => &$result);
4050 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
4052 $result = $hookmanager->resPrint;
4054 $result .= $hookmanager->resPrint;
4068 $sql =
'SELECT c.rowid, date_creation as datec, tms as datem,';
4069 $sql .=
' date_valid as datev,';
4070 $sql .=
' date_cloture as datecloture,';
4071 $sql .=
' fk_user_author, fk_user_valid, fk_user_cloture';
4072 $sql .=
' FROM '.MAIN_DB_PREFIX.$this->table_element.
' as c';
4073 $sql .=
' WHERE c.rowid = '.((int) $id);
4074 $result = $this->db->query($sql);
4076 if ($this->db->num_rows($result)) {
4077 $obj = $this->db->fetch_object($result);
4078 $this->
id = $obj->rowid;
4079 if ($obj->fk_user_author) {
4080 $this->user_creation_id = $obj->fk_user_author;
4082 if ($obj->fk_user_valid) {
4083 $this->user_validation_id = $obj->fk_user_valid;
4085 if ($obj->fk_user_cloture) {
4086 $this->user_closing_id = $obj->fk_user_cloture;
4089 $this->date_creation = $this->db->jdate($obj->datec);
4090 $this->date_modification = $this->db->jdate($obj->datem);
4091 $this->date_validation = $this->db->jdate($obj->datev);
4092 $this->date_cloture = $this->db->jdate($obj->datecloture);
4095 $this->db->free($result);
4112 global
$conf, $langs;
4114 dol_syslog(get_class($this).
"::initAsSpecimen");
4119 $sql =
"SELECT rowid";
4120 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
4121 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
4122 if (array_key_exists(
'tosell', $param)) {
4123 $sql .=
" AND tosell = ".((int) $param[
'tosell']);
4125 $sql .= $this->db->plimit(100);
4127 $resql = $this->db->query($sql);
4129 $num_prods = $this->db->num_rows($resql);
4131 while ($i < $num_prods) {
4133 $row = $this->db->fetch_row($resql);
4134 $prodids[$i] = $row[0];
4140 $this->
ref =
'SPECIMEN';
4141 $this->specimen = 1;
4142 $this->entity =
$conf->entity;
4144 $this->
date = time();
4145 $this->date_lim_reglement = $this->
date + 3600 * 24 * 30;
4146 $this->cond_reglement_code =
'RECEP';
4147 $this->mode_reglement_code =
'CHQ';
4148 $this->availability_code =
'DSP';
4149 $this->demand_reason_code =
'SRC_00';
4151 $this->note_public =
'This is a comment (public)';
4152 $this->note_private =
'This is a comment (private)';
4154 $this->multicurrency_tx = 1;
4155 $this->multicurrency_code =
$conf->currency;
4157 $this->
status = $this::STATUS_DRAFT;
4163 while ($xnbp < $nbp) {
4166 $line->desc = $langs->trans(
"Description").
" ".$xnbp;
4168 $line->subprice = 100;
4172 $line->total_ht = 50;
4173 $line->total_ttc = 60;
4174 $line->total_tva = 10;
4175 $line->remise_percent = 50;
4177 $line->total_ht = 100;
4178 $line->total_ttc = 120;
4179 $line->total_tva = 20;
4180 $line->remise_percent = 0;
4182 if ($num_prods > 0) {
4183 $prodid = mt_rand(1, $num_prods);
4184 $line->fk_product = $prodids[$prodid];
4185 $line->product_ref =
'SPECIMEN';
4188 $this->lines[$xnbp] = $line;
4190 $this->total_ht += $line->total_ht;
4191 $this->total_tva += $line->total_tva;
4192 $this->total_ttc += $line->total_ttc;
4208 global $user, $hookmanager;
4210 $this->nb = array();
4213 $sql =
"SELECT count(c.rowid) as nb";
4214 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as c";
4215 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON c.fk_soc = s.rowid";
4216 if (empty($user->socid) && !$user->hasRight(
'societe',
'client',
'voir')) {
4217 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
4218 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
4221 $sql .=
" ".$clause.
" c.entity IN (".
getEntity(
'commande').
")";
4223 $parameters = array();
4224 $hookmanager->executeHooks(
'printFieldListWhere', $parameters, $this);
4225 $sql .= $hookmanager->resPrint;
4226 $resql = $this->db->query($sql);
4228 while ($obj = $this->db->fetch_object($resql)) {
4229 $this->nb[
"orders"] = $obj->nb;
4231 $this->db->free($resql);
4235 $this->error = $this->db->error();
4261 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
4265 $langs->load(
"orders");
4266 $outputlangs->load(
"products");
4269 $modele =
'einstein';
4271 if (!empty($this->model_pdf)) {
4272 $modele = $this->model_pdf;
4278 $modelpath =
"core/modules/commande/doc/";
4280 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
4333 return max($this->
date, $this->delivery_date) < ($now -
$conf->commande->client->warning_delay);
4343 global
$conf, $langs;
4345 if (empty($this->delivery_date)) {
4348 $text = $text = $langs->trans(
"DeliveryDate").
' '.
dol_print_date($this->delivery_date,
'day');
4350 $text .=
' '.($conf->commande->client->warning_delay > 0 ?
'+' :
'-').
' '.round(abs(
$conf->commande->client->warning_delay) / 3600 / 24, 1).
' '.$langs->trans(
"days").
' < '.$langs->trans(
"Today");
4378 global
$conf, $langs;
4380 $langs->loadLangs(array(
'orders',
'sendings',
'stocks',
'products'));
4383 'has_product' =>
false,
4384 'shippable' =>
false,
4391 if ($this->
status == self::STATUS_DRAFT || $this->
status == self::STATUS_CLOSED) {
4396 $genericCommande = $this;
4397 $genericProduct =
new Product($this->db);
4400 $productstatcache = array();
4401 $productstatcachevirtual = array();
4404 $genericCommande->getLinesArray();
4405 $genericCommande->loadExpeditions();
4414 $genericProduct =
new Product($this->db);
4416 $numlines = count($genericCommande->lines);
4417 for ($lig = 0; $lig < $numlines; $lig++) {
4418 $orderLine = $genericCommande->lines[$lig];
4420 if (isset($genericCommande->expeditions[$orderLine->id])) {
4421 $reliquat = $orderLine->qty - $genericCommande->expeditions[$orderLine->id];
4423 $reliquat = $orderLine->qty;
4426 if ($orderLine->product_type == 0 && $orderLine->fk_product > 0) {
4429 if (empty($productstatcache[$orderLine->fk_product])) {
4430 $genericProduct->fetch($orderLine->fk_product);
4431 $genericProduct->load_stock(
'nobatch,warehouseopen');
4433 $productstatcache[$orderLine->fk_product][
'stockreel'] = $genericProduct->stock_reel;
4434 $productstatcachevirtual[$orderLine->fk_product][
'stockreel'] = $genericProduct->stock_theorique;
4437 $genericProduct->stock_reel = $productstatcache[$orderLine->fk_product][
'stockreel'];
4438 $genericProduct->stock_theorique = $productstatcachevirtual[$orderLine->fk_product][
'stockreel'];
4440 if ($reliquat > 0) {
4443 $textinfo .= $reliquat .
' x ' . $orderLine->product_ref .
' ' .
dol_trunc($orderLine->product_label, 20);
4444 $textinfo .=
' - ' . $langs->trans(
"Stock") .
': <span class="' . ($genericProduct->stock_reel >= $reliquat ?
'ok' :
'error') .
'">' . $genericProduct->stock_reel .
'</span>';
4445 $textinfo .=
' - ' . $langs->trans(
"VirtualStock") .
': <span class="' . ($genericProduct->stock_theorique >= $reliquat ?
'ok' :
'error') .
'">' . $genericProduct->stock_theorique .
'</span>';
4446 if ($reliquat != $orderLine->qty) {
4447 $textinfo .=
' <span class="opacitymedium">' . $langs->trans(
"QtyInOtherShipments") .
' ' . ($orderLine->qty - $reliquat) .
'</span>';
4449 $textinfo .=
'<br>';
4453 $stockordersupplier = 0;
4457 if (empty($productstatcache[$orderLine->fk_product][
'statsordercustomer'])) {
4458 $genericProduct->fetch($orderLine->fk_product);
4459 $genericProduct->load_stats_commande(0,
'1,2');
4460 $productstatcache[$orderLine->fk_product][
'statsordercustomer'] = $genericProduct->stats_commande[
'qty'];
4462 $genericProduct->stats_commande[
'qty'] = $productstatcache[$orderLine->fk_product][
'statsordercustomer'];
4463 $stockorder = $genericProduct->stats_commande[
'qty'];
4466 if (empty($productstatcache[$orderLine->fk_product][
'statsordersupplier'])) {
4467 $genericProduct->load_stats_commande_fournisseur(0,
'3');
4468 $productstatcache[$orderLine->fk_product][
'statsordersupplier'] = $genericProduct->stats_commande_fournisseur[
'qty'];
4470 $genericProduct->stats_commande_fournisseur[
'qty'] = $productstatcache[$orderLine->fk_product][
'statsordersupplier'];
4471 $stockordersupplier = $genericProduct->stats_commande_fournisseur[
'qty'];
4476 $textinfo .= $reliquat .
' x ' . $orderLine->ref .
' ' .
dol_trunc($orderLine->product_label, 20);
4477 $textinfo .=
' ' . $langs->trans(
"Available") .
' ' . $genericProduct->stock_reel .
'..' . $stockorder;
4479 if ($stockorder && $genericProduct->stock_reel < ($genericProduct->stock_reel - $stockorder + $reliquat)) {
4481 $textwarning .=
'<span class="warning">' . $langs->trans(
"Available") .
' ' . $genericProduct->stock_reel .
'..' . $stockorder .
'</span>';
4483 if ($reliquat > $genericProduct->stock_reel) {
4484 $textinfo .=
' <span class="warning">' . $langs->trans(
"Available") .
' ' . $genericProduct->stock_reel .
'</span>';
4486 $textinfo .=
' <span class="ok">' . $langs->trans(
"Available") .
' ' . $genericProduct->stock_reel .
'</span>';
4491 $textinfo .=
' ' . $langs->trans(
"SupplierOrder") .
' ' . $stockordersupplier;
4493 if ($reliquat != $orderLine->qty) {
4494 $textinfo .=
' <span class="opacitymedium">' . $langs->trans(
"QtyInOtherShipments") .
' ' . ($orderLine->qty - $reliquat) .
'</span>';
4496 $textinfo .=
'<br>';
4499 if ($reliquat > $genericProduct->stock_reel) {
4507 if (!$has_reliquat) {
4508 $texticon =
img_picto(
'',
'statut5',
'', 0, 0, 0,
'',
'paddingleft');
4509 $textinfo = $texticon .
' ' . $langs->trans(
"Shipped");
4510 $result[
'shippable'] =
true;
4511 } elseif ($notshippable) {
4512 $texticon =
img_picto(
'',
'dolly',
'', 0, 0, 0,
'',
'error paddingleft');
4513 $textinfo = $texticon .
' ' . $langs->trans(
"NonShippable") .
'<br>' . $textinfo;
4514 $result[
'shippable'] =
false;
4516 $texticon =
img_picto(
'',
'dolly',
'', 0, 0, 0,
'',
'green paddingleft');
4517 $textinfo = $texticon .
' ' . $langs->trans(
"Shippable") .
'<br>' . $textinfo;
4518 $result[
'shippable'] =
true;
4520 $result[
'has_product'] =
true;
4521 $result[
'texticon'] = $texticon;
4522 $result[
'textinfo'] = $textinfo;
4523 $result[
'warning'] = !empty($warning);
if(! $sortfield) if(! $sortorder) $object
Class to manage customers orders.
getNbOfServicesLines()
Return number of line with type service.
getNbOfShipments()
Count number of shipments for this order.
createFromProposal($object, User $user)
Load an object from a proposal and create a new order into database.
setDraft($user, $idwarehouse=-1)
Set draft status.
setDeliveryDate($user, $delivery_date, $notrigger=0)
Set the planned delivery date.
static replaceProduct(DoliDB $db, $origin_id, $dest_id)
Function used to replace a product id with another one.
getLinesArray()
Create an array of order lines.
showDelay()
Show the customer delayed info.
set_date($user, $date, $notrigger=0)
Set the order date.
static replaceThirdparty(DoliDB $dbs, $origin_id, $dest_id)
Function used to replace a thirdparty id with another one.
loadStateBoard()
Load the indicators this->nb for the state board.
fetch_lines($only_product=0, $loadalsotranslation=0)
Load array lines.
const STATUS_SHIPMENTONPROCESS
Shipment on process.
LibStatut($status, $billed, $mode, $donotshowbilled=0)
Return label of status.
getLibStatut($mode)
Return status label of Order.
hasDelay()
Is the sales order delayed?
const STATUS_CLOSED
Closed (Sent, billed or not)
valid($user, $idwarehouse=0, $notrigger=0)
Validate order.
getLabelSource()
Return source label of order.
set_remise($user, $remise, $notrigger=0)
Applique une remise relative.
initAsSpecimen($param=array())
Initialise an instance with random values.
const STATUS_CANCELED
Canceled status.
getNomUrl($withpicto=0, $option='', $max=0, $short=0, $notooltip=0, $save_lastsearch_value=-1, $addlinktonotes=0, $target='')
Return clickable link of object (with eventually picto)
loadExpeditions($filtre_statut=-1, $fk_product=0)
Load array this->expeditions of lines of shipments with nb of products sent for each order line Note:...
__construct($db)
Constructor.
availability($availability_id, $notrigger=0)
Update delivery delay.
set_reopen($user)
Tag the order as validated (opened) Function used when order is reopend after being closed.
set_ref_client($user, $ref_client, $notrigger=0)
Set customer ref.
addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0, $txlocaltax2=0, $fk_product=0, $remise_percent=0, $info_bits=0, $fk_remise_except=0, $price_base_type='HT', $pu_ttc=0, $date_start='', $date_end='', $type=0, $rang=-1, $special_code=0, $fk_parent_line=0, $fk_fournprice=null, $pa_ht=0, $label='', $array_options=array(), $fk_unit=null, $origin='', $origin_id=0, $pu_ht_devise=0, $ref_ext='', $noupdateafterinsertline=0)
Add an order line into database (linked to product/service or not)
getTooltipContentArray($params)
getTooltipContentArray
create($user, $notrigger=0)
Create sale order Note that this->ref can be set or empty.
demand_reason($demand_reason_id, $notrigger=0)
Update order demand_reason.
const STATUS_DRAFT
Draft status.
const STOCK_NOT_ENOUGH_FOR_ORDER
ERR Not enough stock.
insert_discount($idremise)
Add a discount line into a sale order (as a sale order line) using an existing absolute discount (Con...
getNbOfProductsLines()
Return number of line with type product.
update(User $user, $notrigger=0)
Update database.
classifyUnBilled(User $user, $notrigger=0)
Classify the order as not invoiced.
setDiscount($user, $remise, $notrigger=0)
Set a percentage discount.
setCategories($categories)
Sets object to given categories.
const STATUS_ACCEPTED
For backward compatibility.
updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0.0, $txlocaltax2=0.0, $price_base_type='HT', $info_bits=0, $date_start='', $date_end='', $type=0, $fk_parent_line=0, $skip_update_total=0, $fk_fournprice=null, $pa_ht=0, $label='', $special_code=0, $array_options=array(), $fk_unit=null, $pu_ht_devise=0, $notrigger=0, $ref_ext='', $rang=0)
Update a line in database.
classifyBilled(User $user, $notrigger=0)
Classify the order as invoiced.
info($id)
Charge les information d'ordre info dans l'objet commande.
load_board($user, $mode)
Load indicators for dashboard (this->nbtodo and this->nbtodolate)
const STATUS_VALIDATED
Validated status.
deleteLine($user=null, $lineid=0, $id=0)
Delete an order line.
countNbOfShipments()
Returns an array with expeditions lines number.
liste_array($shortlist=0, $draft=0, $excluser=null, $socid=0, $limit=0, $offset=0, $sortfield='c.date_commande', $sortorder='DESC')
Return list of orders (eventuelly filtered on a user) into an array.
fetch($id, $ref='', $ref_ext='', $notused='')
Get object from database.
getShippableInfos(array $options=array())
Compute shippable status and tooltip/icon for the order.
cloture($user, $notrigger=0, $checkpermission=1)
Close order.
set_date_livraison($user, $delivery_date, $notrigger=0)
Set delivery date.
add_product($idproduct, $qty, $remise_percent=0.0, $date_start='', $date_end='')
Add line into array $this->client must be loaded.
generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
Create a document onto disk according to template module.
setSignedStatus(User $user, int $status=0, int $notrigger=0, $triggercode='')
Set signed status.
cancel($user, $idwarehouse=-1)
Cancel an order If stock is decremented on order validation, we must reincrement it.
createFromClone(User $user, $socid=0, $forceentity=null)
Load an object from its id and create a new one in database.
fetch_optionals($rowid=null, $optionsArray=null)
Function to get extra fields of an object into $this->array_options This method is in most cases call...
line_order($renum=false, $rowidorder='ASC', $fk_parent_line=true)
Save a new position (field rang) for details lines.
deleteEcmFiles($mode=0)
Delete related files of object in database.
update_price($exclspec=0, $roundingadjust='auto', $nodatabaseupdate=0, $seller=null)
Update total_ht, total_ttc, total_vat, total_localtax1, total_localtax2 for an object (sum of lines).
add_object_linked($origin=null, $origin_id=null, $f_user=null, $notrigger=0)
Add an object link into llx_element_element.
roundQtyToPackaging($qty, $packaging)
Round a quantity up to the next multiple of a packaging quantity (options PRODUCT_USE_CUSTOMER_PACKAG...
commonGenerateDocument($modelspath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams=null)
Common function for all objects extending CommonObject for generating documents.
fetchProject()
Load the project with id $this->fk_project into this->project.
fetch_thirdparty($force_thirdparty_id=0)
Load the third party of object, from id $this->socid or $this->fk_soc, into this->thirdparty.
deleteObjectLinked($sourceid=null, $sourcetype='', $targetid=null, $targettype='', $rowid=0, $f_user=null, $notrigger=0)
Delete all links between an object $this.
setErrorsFromObject($object)
setErrorsFromObject
isLineOfObject($lineid)
Check that a line belongs to this object, using $this->table_element_line and $this->fk_element.
static isExistingObject($element, $id, $ref='', $ref_ext='')
Check if an object id or ref exists If you don't need or want to instantiate the object and just need...
updateRangOfLine($rowid, $rang)
Update position of line (rang)
checkActiveProductInLines($status='onsale')
Check if all products have the right status (on sale, on buy) called during validation of propal,...
deleteExtraFields()
Delete all extra fields values for the current object.
static commonReplaceThirdparty(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a thirdparty id with another one.
static commonReplaceProduct(DoliDB $dbs, $origin_id, $dest_id, array $tables, $ignoreerrors=0)
Function used to replace a product id with another one.
line_max($fk_parent_line=0)
Get max value used for position of line (rang)
insertExtraFields($trigger='', $userused=null)
Add/Update all extra fields values for the current object.
delete_linked_contact($source='', $code='')
Delete all links between an object $this and all its contacts in llx_element_contact.
add_contact($fk_socpeople, $type_contact, $source='external', $notrigger=0)
Add a link between element $this->element and a contact.
Superclass for orders classes.
Class to manage absolute discounts.
Class to manage Dolibarr database access.
Class to manage stock movements.
static getIdAndTxFromCode($dbs, $code, $date_document=0)
Get id and rate of currency from code.
static getIdFromCode($dbs, $code)
Get id of currency from code.
Class to manage order lines.
Class to manage products or services.
Class to manage projects.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
print $langs trans("Ref").' m titre as m m statut as status
Or an array listing all the potential status of the object: array: int of the status => translated la...
setSignedStatusCommon(User $user, int $status, int $notrigger=0, string $triggercode='')
Set signed status & call trigger with context message.
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0, $level=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
dol_dir_list($utf8_path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0, $nbsecondsold=0)
Scan a directory and return a list of files/directories.
dol_delete_preview($object)
Delete all preview files linked to object instance.
$date_start
Variables from include:
dol_now($mode='gmt')
Return date for now.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
setEntity($currentobject)
Set entity id to use when to create an object.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
Show picto whatever it's its name (generic function)
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $allowothertags=array())
Show a picto called object_picto (generic function)
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dol_strlen($string, $stringencoding='UTF-8')
Make a strlen call.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
getLocalTaxesFromRate($vatrate, $local, $buyer, $seller, $firstparamisid=0)
Get type and rate of localtaxes for a particular vat rate/country of a thirdparty.
getMultidirOutput($object, $module='', $forobject=0, $mode='output')
Return the full path of the directory where a module (or an object of a module) stores its files.
get_default_npr(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that returns whether VAT must be recoverable collected VAT (e.g.: VAT NPR in France)
dolGetStatus($statusLabel='', $statusLabelShort='', $html='', $statusType='status0', $displayMode=0, $url='', $params=array())
Output the badge of a status.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
getDolGlobalBool($key, $default=false)
Return a Dolibarr global constant boolean value.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
get_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular VAT rate, when selling a product with vat $vatrate,...
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
print $langs trans("Show") . '< td style="' . $timeColor . '" align="center"> s</td > badge status0 badge status4 badge status3 Error badge status8< td align="center">< span class="badge ' . $badge . '"></span ></td >< td align="center">< a href="#" class="button button-small" onclick="openLogModal(this)" data-req="' . dol_escape_htmltag($reqSafe) . '" data-res="' . dol_escape_htmltag($resSafe) . '" data-err="' . dol_escape_htmltag($errSafe) . '">< span class="fa fa-search-plus"></span ></a ></td ></tr >< tr >< td colspan="' . $colspan . '" class="opacitymedium"></td ></tr ></table ></div ></form > logModal none logModal none s a JSON string
buildzip.php
getMarginInfos($pv_ht, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, $fk_pa, $pa_ht)
Return an array with margins information of a line.
calcul_price_total($qty, $pu, $remise_percent_ligne, $txtva, $uselocaltax1_rate, $uselocaltax2_rate, $notused, $price_base_type, $info_bits, $type, $seller=null, $localtaxes_array=[], $progress=100, $multicurrency_tx=1, $pu_devise=0, $multicurrency_code='')
Calculate totals (net, vat, ...) of a line.
print $langs trans('Date')." left Ref Label right Qty right Price right TotalHT right TotalTTC right right right right right right right right right centpercent right TotalHT right n right VAT right n right TotalVAT right n No sujeto a RE IRPF right TotalLT1 right n right TotalLT2 right n right TotalTTC right n takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency takeposcustomercurrency right TotalTTC takeposcustomercurrency right takeposcustomercurrency n right Paid right PaymentTypeShortLIQ right SELECT p pos_change as p datep as date