diff --git a/htdocs/admin/stock.php b/htdocs/admin/stock.php index e258011de76..6faaff1e006 100644 --- a/htdocs/admin/stock.php +++ b/htdocs/admin/stock.php @@ -73,12 +73,22 @@ if($action) || $action == 'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER' || $action == 'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') { + //Use variable cause empty(GETPOST()) do not work with php version < 5.4 + $valdispatch=GETPOST('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER','alpha'); + $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_BILL", '','chaine',0,'',$conf->entity); $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER", '','chaine',0,'',$conf->entity); $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER", '','chaine',0,'',$conf->entity); if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_BILL') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_BILL", GETPOST('STOCK_CALCULATE_ON_SUPPLIER_BILL','alpha'),'chaine',0,'',$conf->entity); if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER", GETPOST('STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER','alpha'),'chaine',0,'',$conf->entity); - if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER", GETPOST('STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER','alpha'),'chaine',0,'',$conf->entity); + if ($action == 'STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER') $res=dolibarr_set_const($db, "STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER", $valdispatch,'chaine',0,'',$conf->entity); + if (empty($valdispatch)) { + $res=dolibarr_set_const($db, "SUPPLIER_ORDER_USE_DISPATCH_STATUS", '','chaine',0,'',$conf->entity); + } + } + + if($action == 'SUPPLIER_ORDER_USE_DISPATCH_STATUS') { + $res = dolibarr_set_const($db, "SUPPLIER_ORDER_USE_DISPATCH_STATUS", GETPOST('SUPPLIER_ORDER_USE_DISPATCH_STATUS','alpha'),'chaine',0,'',$conf->entity); } if($action == 'STOCK_USE_VIRTUAL_STOCK') { @@ -163,7 +173,7 @@ if (! empty($conf->facture->enabled)) } else { - print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module30Name")); + print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module30Name")); } print "\n\n"; $found++; @@ -183,7 +193,7 @@ if (! empty($conf->commande->enabled)) } else { - print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module25Name")); + print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module25Name")); } print "\n\n"; $found++; @@ -205,7 +215,7 @@ if (! empty($conf->expedition->enabled)) } else { - print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module80Name")); + print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module80Name")); } print "\n\n"; $found++; @@ -225,7 +235,7 @@ if (! empty($conf->expedition->enabled)) } else { - print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module80Name")); + print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module80Name")); } print "\n\n"; $found++; @@ -267,7 +277,7 @@ if (! empty($conf->fournisseur->enabled)) } else { - print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name")); + print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name")); } print "\n\n"; $found++; @@ -288,7 +298,7 @@ if (! empty($conf->fournisseur->enabled)) } else { - print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name")); + print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name")); } print "\n\n"; $found++; @@ -308,9 +318,30 @@ if (! empty($conf->fournisseur->enabled)) } else { - print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name")); + print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name")); } print "\n\n"; + +if (!empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) { + $var=!$var; + print ""; + print ''.$langs->trans("UseDispatchStatus").''; + print ''; + if (! empty($conf->fournisseur->enabled)) + { + print "
"; + print ''; + print ""; + print $form->selectyesno("SUPPLIER_ORDER_USE_DISPATCH_STATUS",$conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS,1,$disabled); + print ''; + print "
\n"; + } + else + { + print $langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("Module40Name")); + } + print "\n\n"; +} $found++; /*if (! $found) @@ -446,13 +477,13 @@ print '
'; /* I keep the option/feature, but hidden to end users for the moment. If feature is used by module, no need to have users see it. If not used by a module, I still need to understand in which case user may need this now we can set rule on product page. -if ($conf->global->PRODUIT_SOUSPRODUITS) +if ($conf->global->PRODUIT_SOUSPRODUITS) { $var=!$var; - + print ""; print ''.$langs->trans("IndependantSubProductStock").''; - + print ''; print "
"; print ''; diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 6b73e5a7477..8a812c34f8b 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -126,7 +126,7 @@ class CommandeFournisseur extends CommonOrder public $multicurrency_total_ht; public $multicurrency_total_tva; public $multicurrency_total_ttc; - + /** * Constructor * @@ -255,7 +255,7 @@ class CommandeFournisseur extends CommonOrder $this->multicurrency_total_ht = $obj->multicurrency_total_ht; $this->multicurrency_total_tva = $obj->multicurrency_total_tva; $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc; - + $this->extraparams = (array) json_decode($obj->extraparams, true); $this->db->free($resql); @@ -330,7 +330,7 @@ class CommandeFournisseur extends CommonOrder $line->date_start = $this->db->jdate($objp->date_start); $line->date_end = $this->db->jdate($objp->date_end); $line->fk_unit = $objp->fk_unit; - + // Multicurrency $line->fk_multicurrency = $objp->fk_multicurrency; $line->multicurrency_code = $objp->multicurrency_code; @@ -338,7 +338,7 @@ class CommandeFournisseur extends CommonOrder $line->multicurrency_total_ht = $objp->multicurrency_total_ht; $line->multicurrency_total_tva = $objp->multicurrency_total_tva; $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc; - + $this->special_code = $objp->special_code; $this->fk_parent_line = $objp->fk_parent_line; @@ -513,7 +513,7 @@ class CommandeFournisseur extends CommonOrder $billedtext=''; //if ($statut==5 && $this->billed == 1) $statut = 8; if ($billed == 1) $billedtext=$langs->trans("Billed"); - + // List of language codes for status $statutshort[0] = 'StatusOrderDraftShort'; $statutshort[1] = 'StatusOrderValidatedShort'; @@ -678,7 +678,7 @@ class CommandeFournisseur extends CommonOrder { $error=0; $this->db->begin(); - + $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande_fournisseur SET billed = 1'; $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0 '; if ($this->db->query($sql)) @@ -690,11 +690,11 @@ class CommandeFournisseur extends CommonOrder if ($result < 0) $error++; // End call triggers } - + if (! $error) { $this->billed=1; - + $this->db->commit(); return 1; } @@ -707,7 +707,7 @@ class CommandeFournisseur extends CommonOrder else { dol_print_error($this->db); - + $this->db->rollback(); return -1; } @@ -754,7 +754,7 @@ class CommandeFournisseur extends CommonOrder // Do we have to change status now ? (If double approval is required and first approval, we keep status to 1 = validated) $movetoapprovestatus=true; $comment=''; - + $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseur"; $sql.= " SET ref='".$this->db->escape($num)."',"; if (empty($secondlevel)) // standard or first level approval @@ -763,7 +763,7 @@ class CommandeFournisseur extends CommonOrder $sql.= " fk_user_approve = ".$user->id; if (! empty($conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) && $conf->global->MAIN_FEATURES_LEVEL > 0 && $this->total_ht >= $conf->global->SUPPLIER_ORDER_3_STEPS_TO_BE_APPROVED) { - if (empty($this->user_approve_id2)) + if (empty($this->user_approve_id2)) { $movetoapprovestatus=false; // second level approval not done $comment=' (first level)'; @@ -830,7 +830,7 @@ class CommandeFournisseur extends CommonOrder if (! $error) { $this->ref = $this->newref; - + if ($movetoapprovestatus) $this->statut = 2; else $this->statut = 1; if (empty($secondlevel)) // standard or first level approval @@ -1009,7 +1009,7 @@ class CommandeFournisseur extends CommonOrder $this->statut = 3; $this->methode_commande_id = $methode; $this->date_commande = $this->db->idate($date); - + // Call trigger $result=$this->call_trigger('ORDER_SUPPLIER_SUBMIT',$user); if ($result < 0) $error++; @@ -1021,7 +1021,7 @@ class CommandeFournisseur extends CommonOrder $this->error = $this->db->lasterror(); $this->errors[] = $this->db->lasterror(); } - + if (! $error) { $this->db->commit(); @@ -1070,7 +1070,7 @@ class CommandeFournisseur extends CommonOrder $this->fk_multicurrency = 0; $this->multicurrency_tx = 1; } - + // We set order into draft status $this->brouillon = 1; @@ -1103,7 +1103,7 @@ class CommandeFournisseur extends CommonOrder $sql.= ", '".$this->db->escape($this->note_public)."'"; $sql.= ", ".$conf->entity; $sql.= ", ".$this->socid; - $sql.= ", ".($this->fk_project > 0 ? $this->fk_project : "null"); + $sql.= ", ".($this->fk_project > 0 ? $this->fk_project : "null"); $sql.= ", '".$this->db->idate($now)."'"; $sql.= ", ".($this->date_livraison?"'".$this->db->idate($this->date_livraison)."'":"null"); $sql.= ", ".$user->id; @@ -1407,7 +1407,7 @@ class CommandeFournisseur extends CommonOrder $localtaxes_type=getLocalTaxesFromRate($txtva,0,$mysoc,$this->thirdparty); $txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate. - + $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $product_type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx); $total_ht = $tabprice[0]; $total_tva = $tabprice[1]; @@ -1419,7 +1419,7 @@ class CommandeFournisseur extends CommonOrder $multicurrency_total_ht = $tabprice[16]; $multicurrency_total_tva = $tabprice[17]; $multicurrency_total_ttc = $tabprice[18]; - + $localtax1_type=$localtaxes_type[0]; $localtax2_type=$localtaxes_type[2]; @@ -1952,7 +1952,7 @@ class CommandeFournisseur extends CommonOrder $result=$this->call_trigger('ORDER_SUPPLIER_RECEIVE',$user); if ($result < 0) $error++; // End call triggers - + if (! $error) { $this->db->commit(); @@ -2211,7 +2211,7 @@ class CommandeFournisseur extends CommonOrder $localtaxes_type=getLocalTaxesFromRate($txtva,0,$mysoc, $this->thirdparty); $txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate. - + $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx); $total_ht = $tabprice[0]; $total_tva = $tabprice[1]; @@ -2223,7 +2223,7 @@ class CommandeFournisseur extends CommonOrder $multicurrency_total_ht = $tabprice[16]; $multicurrency_total_tva = $tabprice[17]; $multicurrency_total_ttc = $tabprice[18]; - + $localtax1_type=$localtaxes_type[0]; $localtax2_type=$localtaxes_type[2]; @@ -2405,7 +2405,7 @@ class CommandeFournisseur extends CommonOrder { $obj = $this->db->fetch_object($result); $this->id = $obj->rowid; - if ($obj->fk_user_author) $this->user_creation_id = $obj->fk_user_author; + if ($obj->fk_user_author) $this->user_creation_id = $obj->fk_user_author; if ($obj->fk_user_valid) $this->user_validation_id = $obj->fk_user_valid; if ($obj->fk_user_modif) $this->user_modification_id =$obj->fk_user_modif; if ($obj->fk_user_approve) $this->user_approve_id = $obj->fk_user_approve; @@ -2424,7 +2424,7 @@ class CommandeFournisseur extends CommonOrder dol_print_error($this->db); } } - + /** * Charge indicateurs this->nb de tableau de bord * @@ -2660,15 +2660,15 @@ class CommandeFournisseur extends CommonOrder public function hasDelay() { global $conf; - + if (empty($this->date_delivery) && ! empty($this->date_livraison)) $this->date_delivery = $this->date_livraison; // For backward compatibility - + $now = dol_now(); $date_to_test = empty($this->date_delivery) ? $this->date_commande : $this->date_delivery; - + return ($this->statut > 0 && $this->statut < 4) && $date_to_test && $date_to_test < ($now - $conf->commande->fournisseur->warning_delay); } - + /** * Show the customer delayed info * @@ -2677,15 +2677,72 @@ class CommandeFournisseur extends CommonOrder public function showDelay() { global $conf, $langs; - + if (empty($this->date_delivery) && ! empty($this->date_livraison)) $this->date_delivery = $this->date_livraison; // For backward compatibility - + if (empty($this->date_delivery)) $text=$langs->trans("OrderDate").' '.dol_print_date($this->date_commande, 'day'); else $text=$text=$langs->trans("DeliveryDate").' '.dol_print_date($this->date_delivery, 'day'); $text.=' '.($conf->commande->fournisseur->warning_delay>0?'+':'-').' '.round(abs($conf->commande->fournisseur->warning_delay)/3600/24,1).' '.$langs->trans("days").' < '.$langs->trans("Today"); - + return $text; - } + } + + /** + * Calc status regarding dispatch stock + * + * @param User $user User action + * @return int <0 si ko, >0 si ok + */ + public function calcAndSetStatusDispatch(User $user) { + global $conf; + + if (! empty($conf->commande->enabled) && ! empty($conf->fournisseur->enabled)) + { + require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php'; + + $qtydelivered=array(); + $qtywished=array(); + + $supplierorderdispatch = new CommandeFournisseurDispatch($this->db); + $filter=array('t.fk_commande'=>$this->id); + if (!empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) { + $filter['t.status']=1; + } + $ret=$supplierorderdispatch->fetchAll('','',0,0,$filter); + if ($ret<0) { + $this->error=$supplierorderdispatch->error; $this->errors=$supplierorderdispatch->errors; + return $ret; + } else { + if (is_array($supplierorderdispatch->lines) && count($supplierorderdispatch->lines)>0) { + //Build array with quantity deliverd by product + foreach($supplierorderdispatch->lines as $line) { + $qtydelivered[$line->fk_product]+=$line->qty; + } + foreach($this->lines as $line) { + $qtywished[$line->fk_product]+=$line->qty; + } + //Compare array + $diff_array=array_diff_assoc($qtydelivered,$qtywished); + if (count($diff_array)==0) { + //No diff => mean everythings is received + $ret=$this->setStatus($user,5); + if ($ret<0) { + $this->error=$object->error; $this->errors=$object->errors; + } + } else { + //Diff => received partially + $ret=$this->setStatus($user,4); + if ($ret<0) { + $this->error=$object->error; $this->errors=$object->errors; + } + } + } + } + + + return 1; + } + } } @@ -2883,7 +2940,7 @@ class CommandeFournisseurLigne extends CommonOrderLine $this->fk_multicurrency = 0; $this->multicurrency_tx = 1; } - + // Check parameters if ($this->product_type < 0) return -1; diff --git a/htdocs/fourn/class/fournisseur.commande.dispatch.class.php b/htdocs/fourn/class/fournisseur.commande.dispatch.class.php index 4d6f75444b8..0464a9fb51f 100644 --- a/htdocs/fourn/class/fournisseur.commande.dispatch.class.php +++ b/htdocs/fourn/class/fournisseur.commande.dispatch.class.php @@ -34,27 +34,28 @@ require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php"); */ class CommandeFournisseurDispatch extends CommonObject { - var $db; //!< To store db handler - var $error; //!< To return error code (or message) - var $errors=array(); //!< To return several error codes (or messages) - var $element='commandefournisseurdispatch'; //!< Id that identify managed objects - var $table_element='commande_fournisseur_dispatch'; //!< Name of table without prefix where object is stored + public $db; //!< To store db handler + public $error; //!< To return error code (or message) + public $errors=array(); //!< To return several error codes (or messages) + public $element='commandefournisseurdispatch'; //!< Id that identify managed objects + public $table_element='commande_fournisseur_dispatch'; //!< Name of table without prefix where object is stored + public $lines=array(); - var $id; + public $id; - var $fk_commande; - var $fk_product; - var $fk_commandefourndet; - var $qty; - var $fk_entrepot; - var $fk_user; - var $datec=''; - var $comment; - var $status; - var $tms=''; - var $batch; - var $eatby=''; - var $sellby=''; + public $fk_commande; + public $fk_product; + public $fk_commandefourndet; + public $qty; + public $fk_entrepot; + public $fk_user; + public $datec=''; + public $comment; + public $status; + public $tms=''; + public $batch; + public $eatby=''; + public $sellby=''; @@ -539,4 +540,100 @@ class CommandeFournisseurDispatch extends CommonObject } + /** + * Load object in memory from the database + * + * @param string $sortorder Sort Order + * @param string $sortfield Sort field + * @param int $limit offset limit + * @param int $offset offset limit + * @param array $filter filter array + * @param string $filtermode filter mode (AND or OR) + * + * @return int <0 if KO, >0 if OK + */ + public function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND') + { + dol_syslog(__METHOD__, LOG_DEBUG); + + $sql = "SELECT"; + $sql.= " t.rowid,"; + + $sql.= " t.fk_commande,"; + $sql.= " t.fk_product,"; + $sql.= " t.fk_commandefourndet,"; + $sql.= " t.qty,"; + $sql.= " t.fk_entrepot,"; + $sql.= " t.fk_user,"; + $sql.= " t.datec,"; + $sql.= " t.comment,"; + $sql.= " t.status,"; + $sql.= " t.tms,"; + $sql.= " t.batch,"; + $sql.= " t.eatby,"; + $sql.= " t.sellby"; + + $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element." as t"; + + // Manage filter + $sqlwhere = array(); + if (count($filter) > 0) { + foreach ($filter as $key => $value) { + if ($key=='t.comment') { + $sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; + } elseif ($key=='t.datec' || $key=='t.tms' || $key=='t.eatby' || $key=='t.sellby' || $key=='t.batch') { + $sqlwhere [] = $key . ' = \'' . $this->db->escape($value) . '\''; + } else { + $sqlwhere [] = $key . ' = ' . $this->db->escape($value); + } + } + } + if (count($sqlwhere) > 0) { + $sql .= ' WHERE ' . implode(' '.$filtermode.' ', $sqlwhere); + } + + if (!empty($sortfield)) { + $sql .= $this->db->order($sortfield,$sortorder); + } + if (!empty($limit)) { + $sql .= ' ' . $this->db->plimit($limit + 1, $offset); + } + $this->lines = array(); + + $resql = $this->db->query($sql); + if ($resql) { + $num = $this->db->num_rows($resql); + + while ($obj = $this->db->fetch_object($resql)) { + $line = new self($this->db); + + $line->id = $obj->rowid; + + $line->fk_commande = $obj->fk_commande; + $line->fk_product = $obj->fk_product; + $line->fk_commandefourndet = $obj->fk_commandefourndet; + $line->qty = $obj->qty; + $line->fk_entrepot = $obj->fk_entrepot; + $line->fk_user = $obj->fk_user; + $line->datec = $this->db->jdate($obj->datec); + $line->comment = $obj->comment; + $line->status = $obj->status; + $line->tms = $this->db->jdate($obj->tms); + $line->batch = $obj->batch; + $line->eatby = $this->db->jdate($obj->eatby); + $line->sellby = $this->db->jdate($obj->sellby); + + $this->lines[$line->id] = $line; + } + $this->db->free($resql); + + return $num; + } else { + $this->errors[] = 'Error ' . $this->db->lasterror(); + dol_syslog(__METHOD__ . ' ' . implode(',', $this->errors), LOG_ERR); + + return - 1; + } + } + } diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php index f4685469711..8494e160223 100644 --- a/htdocs/fourn/commande/dispatch.php +++ b/htdocs/fourn/commande/dispatch.php @@ -5,6 +5,7 @@ * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2010 Juanjo Menent * Copyright (C) 2014 Cedric Gross + * Copyright (C) 2016 Florian Henry * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -22,19 +23,19 @@ */ /** - * \file htdocs/fourn/commande/dispatch.php - * \ingroup commande - * \brief Page to dispatch receiving + * \file htdocs/fourn/commande/dispatch.php + * \ingroup commande + * \brief Page to dispatch receiving */ - require '../../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/core/modules/supplier_order/modules_commandefournisseur.php'; -require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; -require_once DOL_DOCUMENT_ROOT.'/core/lib/fourn.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; -require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.dispatch.class.php'; -require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; -if (! empty($conf->projet->enabled)) require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/modules/supplier_order/modules_commandefournisseur.php'; +require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/lib/fourn.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.class.php'; +require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.dispatch.class.php'; +require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php'; +if (! empty($conf->projet->enabled)) + require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php'; $langs->load('orders'); $langs->load('sendings'); @@ -43,704 +44,651 @@ $langs->load('bills'); $langs->load('deliveries'); $langs->load('products'); $langs->load('stocks'); -if (! empty($conf->productbatch->enabled)) $langs->load('productbatch'); +if (! empty($conf->productbatch->enabled)) + $langs->load('productbatch'); -// Security check -$id = GETPOST("id",'int'); + // Security check +$id = GETPOST("id", 'int'); +$ref = GETPOST('ref'); $lineid = GETPOST('lineid', 'int'); $action = GETPOST('action'); -if ($user->societe_id) $socid=$user->societe_id; +if ($user->societe_id) + $socid = $user->societe_id; $result = restrictedArea($user, 'fournisseur', $id, '', 'commande'); -if (empty($conf->stock->enabled)) -{ +if (empty($conf->stock->enabled)) { accessforbidden(); } -// Recuperation de l'id de projet -$projectid = 0; -if ($_GET["projectid"]) $projectid = GETPOST("projectid",'int'); - -$mesg=''; +// Recuperation de l'id de projet +$projectid = 0; +if ($_GET["projectid"]) + $projectid = GETPOST("projectid", 'int'); +$commande = new CommandeFournisseur($db); +if ($id > 0 || ! empty($ref)) { + $result = $commande->fetch($id, $ref); + if ($result < 0) { + setEventMessages($commande->error, $commande->errors, 'errors'); + } + $result = $commande->fetch_thirdparty(); + if ($result < 0) { + setEventMessages($commande->error, $commande->errors, 'errors'); + } +} /* * Actions */ -if ($action == 'checkdispatchline' && - ! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner)) - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check))) -) -{ +if ($action == 'checkdispatchline' && ! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner)) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check)))) { $supplierorderdispatch = new CommandeFournisseurDispatch($db); - $result=$supplierorderdispatch->fetch($lineid); - if (! $result) dol_print_error($db); - $result=$supplierorderdispatch->setStatut(1); - if ($result < 0) - { + $result = $supplierorderdispatch->fetch($lineid); + if (! $result) + dol_print_error($db); + $result = $supplierorderdispatch->setStatut(1); + if ($result < 0) { setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors'); - $error++; - $action=''; + $error ++; + $action = ''; + } else { + $result = $commande->calcAndSetStatusDispatch($user); + if ($result < 0) { + setEventMessages($commande->error, $commande->errors, 'errors'); + $error ++; + $action = ''; + } } } -if ($action == 'uncheckdispatchline' && - ! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner)) - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check))) -) -{ +if ($action == 'uncheckdispatchline' && ! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner)) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check)))) { $supplierorderdispatch = new CommandeFournisseurDispatch($db); - $result=$supplierorderdispatch->fetch($lineid); - if (! $result) dol_print_error($db); - $result=$supplierorderdispatch->setStatut(0); - if ($result < 0) - { + $result = $supplierorderdispatch->fetch($lineid); + if (! $result) + dol_print_error($db); + $result = $supplierorderdispatch->setStatut(0); + if ($result < 0) { setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors'); - $error++; - $action=''; + $error ++; + $action = ''; + } else { + $result = $commande->calcAndSetStatusDispatch($user); + if ($result < 0) { + setEventMessages($commande->error, $commande->errors, 'errors'); + $error ++; + $action = ''; + } } } -if ($action == 'denydispatchline' && - ! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner)) - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check))) -) -{ +if ($action == 'denydispatchline' && ! ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner)) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check)))) { $supplierorderdispatch = new CommandeFournisseurDispatch($db); - $result=$supplierorderdispatch->fetch($lineid); - if (! $result) dol_print_error($db); - $result=$supplierorderdispatch->setStatut(2); - if ($result < 0) - { + $result = $supplierorderdispatch->fetch($lineid); + if (! $result) + dol_print_error($db); + $result = $supplierorderdispatch->setStatut(2); + if ($result < 0) { setEventMessages($supplierorderdispatch->error, $supplierorderdispatch->errors, 'errors'); - $error++; - $action=''; + $error ++; + $action = ''; + } else { + $result = $commande->calcAndSetStatusDispatch($user); + if ($result < 0) { + setEventMessages($commande->error, $commande->errors, 'errors'); + $error ++; + $action = ''; + } } } -if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner) -{ - $commande = new CommandeFournisseur($db); - $commande->fetch($id); - - $error=0; +if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner) { + $error = 0; $db->begin(); - $pos=0; - foreach($_POST as $key => $value) - { - if (preg_match('/^product_([0-9]+)_([0-9]+)$/i', $key, $reg)) // without batch module enabled - { - $pos++; + $pos = 0; + foreach ( $_POST as $key => $value ) { + // without batch module enabled + if (preg_match('/^product_([0-9]+)_([0-9]+)$/i', $key, $reg)) { + $pos ++; - //$numline=$reg[2] + 1; // line of product - $numline=$pos; - $prod = "product_".$reg[1].'_'.$reg[2]; - $qty = "qty_".$reg[1].'_'.$reg[2]; - $ent = "entrepot_".$reg[1].'_'.$reg[2]; - $pu = "pu_".$reg[1].'_'.$reg[2]; // This is unit price including discount - $fk_commandefourndet = "fk_commandefourndet_".$reg[1].'_'.$reg[2]; + // $numline=$reg[2] + 1; // line of product + $numline = $pos; + $prod = "product_" . $reg[1] . '_' . $reg[2]; + $qty = "qty_" . $reg[1] . '_' . $reg[2]; + $ent = "entrepot_" . $reg[1] . '_' . $reg[2]; + $pu = "pu_" . $reg[1] . '_' . $reg[2]; // This is unit price including discount + $fk_commandefourndet = "fk_commandefourndet_" . $reg[1] . '_' . $reg[2]; - if (GETPOST($qty) > 0) // We ask to move a qty - { - if (! (GETPOST($ent,'int') > 0)) - { - dol_syslog('No dispatch for line '.$key.' as no warehouse choosed'); - $text = $langs->transnoentities('Warehouse').', '.$langs->transnoentities('Line').' ' .($numline); - setEventMessages($langs->trans('ErrorFieldRequired',$text), null, 'errors'); - $error++; + // We ask to move a qty + if (GETPOST($qty) > 0) { + if (! (GETPOST($ent, 'int') > 0)) { + dol_syslog('No dispatch for line ' . $key . ' as no warehouse choosed'); + $text = $langs->transnoentities('Warehouse') . ', ' . $langs->transnoentities('Line') . ' ' . ($numline); + setEventMessages($langs->trans('ErrorFieldRequired', $text), null, 'errors'); + $error ++; } - if (! $error) - { - $result = $commande->DispatchProduct($user, GETPOST($prod,'int'), GETPOST($qty), GETPOST($ent,'int'), GETPOST($pu), GETPOST('comment'), '', '', '', GETPOST($fk_commandefourndet, 'int'), $notrigger); - if ($result < 0) - { + if (! $error) { + $result = $commande->dispatchProduct($user, GETPOST($prod, 'int'), GETPOST($qty), GETPOST($ent, 'int'), GETPOST($pu), GETPOST('comment'), '', '', '', GETPOST($fk_commandefourndet, 'int'), $notrigger); + if ($result < 0) { setEventMessages($commande->error, $commande->errors, 'errors'); - $error++; + $error ++; } } } } - if (preg_match('/^product_batch_([0-9]+)_([0-9]+)$/i', $key, $reg)) // with batch module enabled - { - $pos++; + // with batch module enabled + if (preg_match('/^product_batch_([0-9]+)_([0-9]+)$/i', $key, $reg)) { + $pos ++; - //eat-by date dispatch - //$numline=$reg[2] + 1; // line of product - $numline=$pos; - $prod = 'product_batch_'.$reg[1].'_'.$reg[2]; - $qty = 'qty_'.$reg[1].'_'.$reg[2]; - $ent = 'entrepot_'.$reg[1].'_'.$reg[2]; - $pu = 'pu_'.$reg[1].'_'.$reg[2]; - $fk_commandefourndet = 'fk_commandefourndet_'.$reg[1].'_'.$reg[2]; - $lot = 'lot_number_'.$reg[1].'_'.$reg[2]; - $dDLUO = dol_mktime(12, 0, 0, $_POST['dluo_'.$reg[1].'_'.$reg[2].'month'], $_POST['dluo_'.$reg[1].'_'.$reg[2].'day'], $_POST['dluo_'.$reg[1].'_'.$reg[2].'year']); - $dDLC = dol_mktime(12, 0, 0, $_POST['dlc_'.$reg[1].'_'.$reg[2].'month'], $_POST['dlc_'.$reg[1].'_'.$reg[2].'day'], $_POST['dlc_'.$reg[1].'_'.$reg[2].'year']); + // eat-by date dispatch + // $numline=$reg[2] + 1; // line of product + $numline = $pos; + $prod = 'product_batch_' . $reg[1] . '_' . $reg[2]; + $qty = 'qty_' . $reg[1] . '_' . $reg[2]; + $ent = 'entrepot_' . $reg[1] . '_' . $reg[2]; + $pu = 'pu_' . $reg[1] . '_' . $reg[2]; + $fk_commandefourndet = 'fk_commandefourndet_' . $reg[1] . '_' . $reg[2]; + $lot = 'lot_number_' . $reg[1] . '_' . $reg[2]; + $dDLUO = dol_mktime(12, 0, 0, $_POST['dluo_' . $reg[1] . '_' . $reg[2] . 'month'], $_POST['dluo_' . $reg[1] . '_' . $reg[2] . 'day'], $_POST['dluo_' . $reg[1] . '_' . $reg[2] . 'year']); + $dDLC = dol_mktime(12, 0, 0, $_POST['dlc_' . $reg[1] . '_' . $reg[2] . 'month'], $_POST['dlc_' . $reg[1] . '_' . $reg[2] . 'day'], $_POST['dlc_' . $reg[1] . '_' . $reg[2] . 'year']); - $fk_commandefourndet = 'fk_commandefourndet_'.$reg[1].'_'.$reg[2]; - - if (GETPOST($qty) > 0) // We ask to move a qty - { - if (! (GETPOST($ent,'int') > 0)) - { - dol_syslog('No dispatch for line '.$key.' as no warehouse choosed'); - $text = $langs->transnoentities('Warehouse').', '.$langs->transnoentities('Line').' ' .($numline).'-'.($reg[1]+1); - setEventMessages($langs->trans('ErrorFieldRequired',$text), null, 'errors'); - $error++; + $fk_commandefourndet = 'fk_commandefourndet_' . $reg[1] . '_' . $reg[2]; + + // We ask to move a qty + if (GETPOST($qty) > 0) { + if (! (GETPOST($ent, 'int') > 0)) { + dol_syslog('No dispatch for line ' . $key . ' as no warehouse choosed'); + $text = $langs->transnoentities('Warehouse') . ', ' . $langs->transnoentities('Line') . ' ' . ($numline) . '-' . ($reg[1] + 1); + setEventMessages($langs->trans('ErrorFieldRequired', $text), null, 'errors'); + $error ++; } - if (! (GETPOST($lot, 'alpha') || $dDLUO || $dDLC)) - { - dol_syslog('No dispatch for line '.$key.' as serial/eat-by/sellby date are not set'); - $text = $langs->transnoentities('atleast1batchfield').', '.$langs->transnoentities('Line').' ' .($numline).'-'.($reg[1]+1); - setEventMessages($langs->trans('ErrorFieldRequired',$text), null, 'errors'); - $error++; + if (! (GETPOST($lot, 'alpha') || $dDLUO || $dDLC)) { + dol_syslog('No dispatch for line ' . $key . ' as serial/eat-by/sellby date are not set'); + $text = $langs->transnoentities('atleast1batchfield') . ', ' . $langs->transnoentities('Line') . ' ' . ($numline) . '-' . ($reg[1] + 1); + setEventMessages($langs->trans('ErrorFieldRequired', $text), null, 'errors'); + $error ++; } - if (! $error) - { - $result = $commande->dispatchProduct($user, GETPOST($prod,'int'), GETPOST($qty), GETPOST($ent,'int'), GETPOST($pu), GETPOST('comment'), $dDLC, $dDLUO, GETPOST($lot, 'alpha'), GETPOST($fk_commandefourndet, 'int'), $notrigger); - if ($result < 0) - { + if (! $error) { + $result = $commande->dispatchProduct($user, GETPOST($prod, 'int'), GETPOST($qty), GETPOST($ent, 'int'), GETPOST($pu), GETPOST('comment'), $dDLC, $dDLUO, GETPOST($lot, 'alpha'), GETPOST($fk_commandefourndet, 'int'), $notrigger); + if ($result < 0) { setEventMessages($commande->error, $commande->errors, 'errors'); - $error++; + $error ++; } } } } } - if (! $notrigger && ! $error) - { - global $conf, $langs, $user; - // Call trigger - $result = $commande->call_trigger('ORDER_SUPPLIER_DISPATCH', $user); - // End call triggers - - if ($result < 0) - { + if (! $error) { + $result = $commande->calcAndSetStatusDispatch($user); + if ($result < 0) { setEventMessages($commande->error, $commande->errors, 'errors'); - $error++; + $error ++; } } - if ($result >= 0 && ! $error) - { + if (! $notrigger && ! $error) { + global $conf, $langs, $user; + // Call trigger + + $result = $commande->call_trigger('ORDER_SUPPLIER_DISPATCH', $user); + // End call triggers + + if ($result < 0) { + setEventMessages($commande->error, $commande->errors, 'errors'); + $error ++; + } + } + + if ($result >= 0 && ! $error) { $db->commit(); - header("Location: dispatch.php?id=".$id); - exit; - } - else - { + header("Location: dispatch.php?id=" . $id); + exit(); + } else { $db->rollback(); } } - /* * View */ -$form = new Form($db); +$form = new Form($db); $formproduct = new FormProduct($db); $warehouse_static = new Entrepot($db); $supplierorderdispatch = new CommandeFournisseurDispatch($db); +$help_url = 'EN:CommandeFournisseur'; +llxHeader('', $langs->trans("OrderCard"), $help_url, '', 0, 0, array( + '/fourn/js/lib_dispatch.js' +)); -$help_url='EN:CommandeFournisseur'; -llxHeader('',$langs->trans("OrderCard"),$help_url,'',0,0,array('/fourn/js/lib_dispatch.js')); +$now = dol_now(); -$now=dol_now(); +if ($id > 0 || ! empty($ref)) { + $soc = new Societe($db); + $soc->fetch($commande->socid); -$id = GETPOST('id','int'); -$ref= GETPOST('ref'); -if ($id > 0 || ! empty($ref)) -{ - //if ($mesg) print $mesg.'
'; + $author = new User($db); + $author->fetch($commande->user_author_id); - $commande = new CommandeFournisseur($db); + $head = ordersupplier_prepare_head($commande); - $result=$commande->fetch($id,$ref); - if ($result >= 0) - { - $soc = new Societe($db); - $soc->fetch($commande->socid); + $title = $langs->trans("SupplierOrder"); + dol_fiche_head($head, 'dispatch', $title, 0, 'order'); - $author = new User($db); - $author->fetch($commande->user_author_id); + /* + * Commande + */ + print ''; - $head = ordersupplier_prepare_head($commande); + // Ref + print ''; + print ''; + print ''; - $title=$langs->trans("SupplierOrder"); - dol_fiche_head($head, 'dispatch', $title, 0, 'order'); + // Fournisseur + print '"; + print ''; + print ''; - /* - * Commande - */ - print '
' . $langs->trans("Ref") . ''; + print $form->showrefnav($commande, 'ref', '', 1, 'ref', 'ref'); + print '
' . $langs->trans("Supplier") . "' . $soc->getNomUrl(1, 'supplier') . '
'; + // Statut + print ''; + print ''; + print '"; - // Ref - print ''; - print ''; - print ''; - - // Fournisseur - print '"; - print ''; - print ''; - - // Statut - print ''; - print ''; - print '"; - // Date - if ($commande->methode_commande_id > 0) - { - print '"; - - if ($commande->methode_commande) - { - print ''; - } + if ($commande->methode_commande) { + print ''; } + } - // Auteur - print ''; - print ''; - print ''; + // Auteur + print ''; + print ''; + print ''; - print "
' . $langs->trans("Status") . ''; + print $commande->getLibStatut(4); + print "
'.$langs->trans("Ref").''; - print $form->showrefnav($commande,'ref','',1,'ref','ref'); - print '
'.$langs->trans("Supplier")."'.$soc->getNomUrl(1,'supplier').'
'.$langs->trans("Status").''; - print $commande->getLibStatut(4); + // Date + if ($commande->methode_commande_id > 0) { + print '
' . $langs->trans("Date") . ''; + if ($commande->date_commande) { + print dol_print_date($commande->date_commande, "dayhourtext") . "\n"; + } print "
'.$langs->trans("Date").''; - if ($commande->date_commande) - { - print dol_print_date($commande->date_commande,"dayhourtext")."\n"; - } - print "
'.$langs->trans("Method").''.$commande->methode_commande.'
' . $langs->trans("Method") . '' . $commande->methode_commande . '
'.$langs->trans("AuthorRequest").''.$author->getNomUrl(1).'
' . $langs->trans("AuthorRequest") . '' . $author->getNomUrl(1) . '
"; + print ""; - //if ($mesg) print $mesg; - print '
'; + // if ($mesg) print $mesg; + print '
'; - - $disabled=1; - if (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) $disabled=0; + $disabled = 1; + if (! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) + $disabled = 0; /* - * Lignes de commandes - */ - if ($commande->statut <= 2 || $commande->statut >= 6) - { - print $langs->trans("OrderStatusNotReadyToDispatch"); - } + * Lignes de commandes + */ + if ($commande->statut <= 2 || $commande->statut >= 6) { + print $langs->trans("OrderStatusNotReadyToDispatch"); + } - if ($commande->statut == 3 || $commande->statut == 4 || $commande->statut == 5) - { - $entrepot = new Entrepot($db); - $listwarehouses=$entrepot->list_array(1); + if ($commande->statut == 3 || $commande->statut == 4 || $commande->statut == 5) { + $entrepot = new Entrepot($db); + $listwarehouses = $entrepot->list_array(1); - print ''; - print ''; - print ''; - print ''; + print ''; + print ''; + print ''; + print '
'; - // Set $products_dispatched with qty dispatched for each product id - $products_dispatched = array(); - $sql = "SELECT l.rowid, cfd.fk_product, sum(cfd.qty) as qty"; - $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as cfd"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseurdet as l on l.rowid = cfd.fk_commandefourndet"; - $sql.= " WHERE cfd.fk_commande = ".$commande->id; - $sql.= " GROUP BY l.rowid, cfd.fk_product"; - - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - $i = 0; - - if ($num) - { - while ($i < $num) - { - $objd = $db->fetch_object($resql); - $products_dispatched[$objd->rowid] = price2num($objd->qty, 5); - $i++; - } - } - $db->free($resql); - } - - $sql = "SELECT l.rowid, l.fk_product, l.subprice, l.remise_percent, SUM(l.qty) as qty,"; - $sql.= " p.ref, p.label, p.tobatch"; - $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON l.fk_product=p.rowid"; - $sql.= " WHERE l.fk_commande = ".$commande->id; - if(empty($conf->global->STOCK_SUPPORTS_SERVICES)) $sql.= " AND l.product_type = 0"; - $sql.= " GROUP BY p.ref, p.label, p.tobatch, l.rowid, l.fk_product, l.subprice, l.remise_percent"; // Calculation of amount dispatched is done per fk_product so we must group by fk_product - $sql.= " ORDER BY p.ref, p.label"; - - $resql = $db->query($sql); - if ($resql) - { - $num = $db->num_rows($resql); - $i = 0; - - if ($num) - { - print ''; - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - - if (! empty($conf->productbatch->enabled)) - { - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print "\n"; - } - - } - - $nbfreeproduct=0; - $nbproduct=0; - - $var=false; - while ($i < $num) - { - $objp = $db->fetch_object($resql); - - // On n'affiche pas les produits personnalises - if (! $objp->fk_product > 0) - { - $nbfreeproduct++; - } - else - { - $remaintodispatch=price2num($objp->qty - ((float) $products_dispatched[$objp->rowid]), 5); // Calculation of dispatched - if ($remaintodispatch < 0) $remaintodispatch=0; - - if ($remaintodispatch || empty($conf->global->SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED)) - { - $nbproduct++; - - $var=!$var; - - // To show detail cref and description value, we must make calculation by cref - //print ($objp->cref?' ('.$objp->cref.')':''); - //if ($objp->description) print '
'.nl2br($objp->description); - $suffix='_0_'.$i; - - print "\n"; - print ''."\n"; - print ""; - - $linktoprod=''.img_object($langs->trans("ShowProduct"),'product').' '.$objp->ref.''; - $linktoprod.=' - '.$objp->label."\n"; - - if (! empty($conf->productbatch->enabled)) - { - if ($objp->tobatch) - { - print '"; - } - else - { - print '"; - print ''; - } - } - else - { - print '"; - } - - $var=!$var; - $up_ht_disc=$objp->subprice; - if (! empty($objp->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) $up_ht_disc=price2num($up_ht_disc * (100 - $objp->remise_percent) / 100, 'MU'); - - // Qty ordered - print ''; - - // Already dispatched - print ''; - - if (! empty($conf->productbatch->enabled) && $objp->tobatch==1) - { - $type = 'batch'; - print ''; // Dispatch column - print ''; // Warehouse column - print ''; - - print ''; - print ''; - - print ''; - print ''; - print ''; - print ''; // Qty ordered + qty already dispatached - } - else - { - $type = 'dispatch'; - print ''; // Dispatch column - print ''; - print ''; - print ''; - print ''; - } - // Dispatch - print ''; - - // Warehouse - print '\n"; - - print "\n"; - } - } - $i++; - } - $db->free($resql); - } - else - { - dol_print_error($db); - } - - print "
'.$langs->trans("Description").''.$langs->trans("QtyOrdered").''.$langs->trans("QtyDispatchedShort").''.$langs->trans("QtyToDispatchShort").''.$langs->trans("Warehouse").'
'.$langs->trans("batch_number").''.$langs->trans("l_eatby").''.$langs->trans("l_sellby").' 
'; - print $linktoprod; - print "'; - print $linktoprod; - print "'; - print $langs->trans("ProductDoesNotUseBatchSerial"); - print ''; - print $linktoprod; - print "'.$objp->qty.''.$products_dispatched[$objp->rowid].''.img_picto($langs->trans('AddDispatchBatchLine'),'split.png','onClick="addDispatchLine('.$i.',\''.$type.'\')"').'
'; - print ''; - print ''; - print ''; - // hidden fields for js function - print ''; - print ''; - print ''; - print ''; - print ''; - $dlcdatesuffix=dol_mktime(0, 0, 0, GETPOST('dlc'.$suffix.'month'), GETPOST('dlc'.$suffix.'day'), GETPOST('dlc'.$suffix.'year')); - $form->select_date($dlcdatesuffix,'dlc'.$suffix,'','',1,""); - print ''; - $dluodatesuffix=dol_mktime(0, 0, 0, GETPOST('dluo'.$suffix.'month'), GETPOST('dluo'.$suffix.'day'), GETPOST('dluo'.$suffix.'year')); - $form->select_date($dluodatesuffix,'dluo'.$suffix,'','',1,""); - print ' '.img_picto($langs->trans('AddStockLocationLine'),'split.png','onClick="addDispatchLine('.$i.',\''.$type.'\')"').'
'; - print ''; - print ''; - print ''; - // hidden fields for js function - print ''; - print ''; - print ''; - print ''; - print ''; - if (count($listwarehouses)>1) - { - print $formproduct->selectWarehouses(GETPOST("entrepot".$suffix), "entrepot".$suffix,'',1,0,$objp->fk_product); - } - elseif (count($listwarehouses)==1) - { - print $formproduct->selectWarehouses(GETPOST("entrepot".$suffix), "entrepot".$suffix,'',0,0,$objp->fk_product); - } - else - { - print $langs->trans("NoWarehouseDefined"); - } - print "
\n"; - print "
\n"; - - if ($nbproduct) - { - print $langs->trans("Comment").' : '; - print 'trans("DispatchSupplierOrder",$commande->ref); - // print ' / '.$commande->ref_supplier; // Not yet available - print '" class="flat">   '; - - //print '
'; - print ''; - //print '
'; - } - if (! $nbproduct && $nbfreeproduct) - { - print $langs->trans("NoPredefinedProductToDispatch"); - } - - print ''; - } - - dol_fiche_end(); - - - // List of lines already dispatched - $sql = "SELECT p.ref, p.label,"; - $sql.= " e.rowid as warehouse_id, e.label as entrepot,"; - $sql.= " cfd.rowid as dispatchlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status"; - $sql.= " FROM ".MAIN_DB_PREFIX."product as p,"; - $sql.= " ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as cfd"; - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."entrepot as e ON cfd.fk_entrepot = e.rowid"; - $sql.= " WHERE cfd.fk_commande = ".$commande->id; - $sql.= " AND cfd.fk_product = p.rowid"; - $sql.= " ORDER BY cfd.rowid ASC"; + // Set $products_dispatched with qty dispatched for each product id + $products_dispatched = array(); + $sql = "SELECT l.rowid, cfd.fk_product, sum(cfd.qty) as qty"; + $sql .= " FROM " . MAIN_DB_PREFIX . "commande_fournisseur_dispatch as cfd"; + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "commande_fournisseurdet as l on l.rowid = cfd.fk_commandefourndet"; + $sql .= " WHERE cfd.fk_commande = " . $commande->id; + $sql .= " GROUP BY l.rowid, cfd.fk_product"; $resql = $db->query($sql); - if ($resql) - { + if ($resql) { $num = $db->num_rows($resql); $i = 0; - if ($num > 0) - { - print "
\n"; - - print load_fiche_titre($langs->trans("ReceivingForSameOrder")); - - print ''; - - print ''; - print ''; - if (! empty($conf->productbatch->enabled)) - { - print ''; - print ''; - print ''; + if ($num) { + while ( $i < $num ) { + $objd = $db->fetch_object($resql); + $products_dispatched[$objd->rowid] = price2num($objd->qty, 5); + $i ++; } - print ''; + } + $db->free($resql); + } + + $sql = "SELECT l.rowid, l.fk_product, l.subprice, l.remise_percent, SUM(l.qty) as qty,"; + $sql .= " p.ref, p.label, p.tobatch"; + $sql .= " FROM " . MAIN_DB_PREFIX . "commande_fournisseurdet as l"; + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON l.fk_product=p.rowid"; + $sql .= " WHERE l.fk_commande = " . $commande->id; + if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) + $sql .= " AND l.product_type = 0"; + $sql .= " GROUP BY p.ref, p.label, p.tobatch, l.rowid, l.fk_product, l.subprice, l.remise_percent"; // Calculation of amount dispatched is done per fk_product so we must group by fk_product + $sql .= " ORDER BY p.ref, p.label"; + + $resql = $db->query($sql); + if ($resql) { + $num = $db->num_rows($resql); + $i = 0; + + if ($num) { + print ''; + + print ''; print ''; - print ''; - print ''; - if (! empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; print "\n"; - $var=false; - - while ($i < $num) - { - $objp = $db->fetch_object($resql); - - print ""; - print '\n"; - - if (! empty($conf->productbatch->enabled)) - { - print ''; - print ''; - print ''; - } - - // Qty - print ''; - print ''; - - // Warehouse - print ''; - - // Comment - print ''; - - // Status - if (! empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) - { - print ''; - - // Add button to check/uncheck disaptching - print ''; - } - + if (! empty($conf->productbatch->enabled)) { + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; print "\n"; - - $i++; - $var=!$var; } - $db->free($resql); - - print "
'.$langs->trans("Description").''.$langs->trans("batch_number").''.$langs->trans("l_eatby").''.$langs->trans("l_sellby").''.$langs->trans("QtyDispatched").'
' . $langs->trans("Description") . ''.$langs->trans("Warehouse").''.$langs->trans("Comment").''.$langs->trans("Status").'' . $langs->trans("QtyOrdered") . '' . $langs->trans("QtyDispatchedShort") . '' . $langs->trans("QtyToDispatchShort") . '' . $langs->trans("Warehouse") . '
'; - print ''.img_object($langs->trans("ShowProduct"),'product').' '.$objp->ref.''; - print ' - '.$objp->label; - print "'.$objp->batch.''.dol_print_date($db->jdate($objp->eatby),'day').''.dol_print_date($db->jdate($objp->sellby),'day').''.$objp->qty.' '; - $warehouse_static->id=$objp->warehouse_id; - $warehouse_static->libelle=$objp->entrepot; - print $warehouse_static->getNomUrl(1); - print ''.dol_trunc($objp->comment).''; - $supplierorderdispatch->status = (empty($objp->status)?0:$objp->status); - //print $supplierorderdispatch->status; - print $supplierorderdispatch->getLibStatut(5); - print ''; - if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner)) - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check)) - ) - { - if (empty($objp->status)) - { - print ''.$langs->trans("Approve").''; - print ''.$langs->trans("Deny").''; - } - else - { - print ''.$langs->trans("Disapprove").''; - print ''.$langs->trans("Deny").''; - } - } - else - { - $disabled=''; - if ($commande->statut == 5) $disabled=1; - if (empty($objp->status)) - { - print 'dispatchlineid.'">'.$langs->trans("Approve").''; - print 'dispatchlineid.'">'.$langs->trans("Deny").''; - } - if ($objp->status == 1) - { - print 'dispatchlineid.'">'.$langs->trans("Reinit").''; - print 'dispatchlineid.'">'.$langs->trans("Deny").''; - } - if ($objp->status == 2) - { - print 'dispatchlineid.'">'.$langs->trans("Reinit").''; - print 'dispatchlineid.'">'.$langs->trans("Approve").''; - } - } - print '
' . $langs->trans("batch_number") . '' . $langs->trans("l_eatby") . '' . $langs->trans("l_sellby") . ' 
\n"; } - } - else - { + + $nbfreeproduct = 0; + $nbproduct = 0; + + $var = false; + while ( $i < $num ) { + $objp = $db->fetch_object($resql); + + // On n'affiche pas les produits personnalises + if (! $objp->fk_product > 0) { + $nbfreeproduct ++; + } else { + $remaintodispatch = price2num($objp->qty - (( float ) $products_dispatched[$objp->rowid]), 5); // Calculation of dispatched + if ($remaintodispatch < 0) + $remaintodispatch = 0; + + if ($remaintodispatch || empty($conf->global->SUPPLIER_ORDER_DISABLE_STOCK_DISPATCH_WHEN_TOTAL_REACHED)) { + $nbproduct ++; + + $var = ! $var; + + // To show detail cref and description value, we must make calculation by cref + // print ($objp->cref?' ('.$objp->cref.')':''); + // if ($objp->description) print '
'.nl2br($objp->description); + $suffix = '_0_' . $i; + + print "\n"; + print '' . "\n"; + print ""; + + $linktoprod = '' . img_object($langs->trans("ShowProduct"), 'product') . ' ' . $objp->ref . ''; + $linktoprod .= ' - ' . $objp->label . "\n"; + + if (! empty($conf->productbatch->enabled)) { + if ($objp->tobatch) { + print ''; + print $linktoprod; + print ""; + } else { + print ''; + print $linktoprod; + print ""; + print ''; + print $langs->trans("ProductDoesNotUseBatchSerial"); + print ''; + } + } else { + print ''; + print $linktoprod; + print ""; + } + + $var = ! $var; + $up_ht_disc = $objp->subprice; + if (! empty($objp->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) + $up_ht_disc = price2num($up_ht_disc * (100 - $objp->remise_percent) / 100, 'MU'); + + // Qty ordered + print '' . $objp->qty . ''; + + // Already dispatched + print '' . $products_dispatched[$objp->rowid] . ''; + + if (! empty($conf->productbatch->enabled) && $objp->tobatch == 1) { + $type = 'batch'; + print '' . img_picto($langs->trans('AddDispatchBatchLine'), 'split.png', 'onClick="addDispatchLine(' . $i . ',\'' . $type . '\')"') . ''; // Dispatch column + print ''; // Warehouse column + print ''; + + print ''; + print ''; + print ''; + print ''; + print ''; + // hidden fields for js function + print ''; + print ''; + print ''; + + print ''; + print ''; + print ''; + print ''; + $dlcdatesuffix = dol_mktime(0, 0, 0, GETPOST('dlc' . $suffix . 'month'), GETPOST('dlc' . $suffix . 'day'), GETPOST('dlc' . $suffix . 'year')); + $form->select_date($dlcdatesuffix, 'dlc' . $suffix, '', '', 1, ""); + print ''; + print ''; + $dluodatesuffix = dol_mktime(0, 0, 0, GETPOST('dluo' . $suffix . 'month'), GETPOST('dluo' . $suffix . 'day'), GETPOST('dluo' . $suffix . 'year')); + $form->select_date($dluodatesuffix, 'dluo' . $suffix, '', '', 1, ""); + print ''; + print ' '; // Qty ordered + qty already dispatached + } else { + $type = 'dispatch'; + print '' . img_picto($langs->trans('AddStockLocationLine'), 'split.png', 'onClick="addDispatchLine(' . $i . ',\'' . $type . '\')"') . ''; // Dispatch column + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + // hidden fields for js function + print ''; + print ''; + print ''; + } + // Dispatch + print ''; + print ''; + print ''; + + // Warehouse + print ''; + if (count($listwarehouses) > 1) { + print $formproduct->selectWarehouses(GETPOST("entrepot" . $suffix), "entrepot" . $suffix, '', 1, 0, $objp->fk_product); + } elseif (count($listwarehouses) == 1) { + print $formproduct->selectWarehouses(GETPOST("entrepot" . $suffix), "entrepot" . $suffix, '', 0, 0, $objp->fk_product); + } else { + print $langs->trans("NoWarehouseDefined"); + } + print "\n"; + + print "\n"; + } + } + $i ++; + } + $db->free($resql); + } else { dol_print_error($db); } + + print "\n"; + print "
\n"; + + if ($nbproduct) { + print $langs->trans("Comment") . ' : '; + print 'trans("DispatchSupplierOrder", $commande->ref); + // print ' / '.$commande->ref_supplier; // Not yet available + print '" class="flat">   '; + + // print '
'; + print ''; + // print '
'; + } + if (! $nbproduct && $nbfreeproduct) { + print $langs->trans("NoPredefinedProductToDispatch"); + } + + print ''; } - else - { - // Commande non trouvee + + dol_fiche_end(); + + // List of lines already dispatched + $sql = "SELECT p.ref, p.label,"; + $sql .= " e.rowid as warehouse_id, e.label as entrepot,"; + $sql .= " cfd.rowid as dispatchlineid, cfd.fk_product, cfd.qty, cfd.eatby, cfd.sellby, cfd.batch, cfd.comment, cfd.status"; + $sql .= " FROM " . MAIN_DB_PREFIX . "product as p,"; + $sql .= " " . MAIN_DB_PREFIX . "commande_fournisseur_dispatch as cfd"; + $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "entrepot as e ON cfd.fk_entrepot = e.rowid"; + $sql .= " WHERE cfd.fk_commande = " . $commande->id; + $sql .= " AND cfd.fk_product = p.rowid"; + $sql .= " ORDER BY cfd.rowid ASC"; + + $resql = $db->query($sql); + if ($resql) { + $num = $db->num_rows($resql); + $i = 0; + + if ($num > 0) { + print "
\n"; + + print load_fiche_titre($langs->trans("ReceivingForSameOrder")); + + print ''; + + print ''; + print ''; + if (! empty($conf->productbatch->enabled)) { + print ''; + print ''; + print ''; + } + print ''; + print ''; + print ''; + print ''; + if (! empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) + print ''; + print "\n"; + + $var = false; + + while ( $i < $num ) { + $objp = $db->fetch_object($resql); + + print ""; + print '\n"; + + if (! empty($conf->productbatch->enabled)) { + print ''; + print ''; + print ''; + } + + // Qty + print ''; + print ''; + + // Warehouse + print ''; + + // Comment + print ''; + + // Status + if (! empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) { + print ''; + + // Add button to check/uncheck disaptching + print ''; + } + + print "\n"; + + $i ++; + $var = ! $var; + } + $db->free($resql); + + print "
' . $langs->trans("Description") . '' . $langs->trans("batch_number") . '' . $langs->trans("l_eatby") . '' . $langs->trans("l_sellby") . '' . $langs->trans("QtyDispatched") . '' . $langs->trans("Warehouse") . '' . $langs->trans("Comment") . '' . $langs->trans("Status") . '
'; + print '' . img_object($langs->trans("ShowProduct"), 'product') . ' ' . $objp->ref . ''; + print ' - ' . $objp->label; + print "' . $objp->batch . '' . dol_print_date($db->jdate($objp->eatby), 'day') . '' . dol_print_date($db->jdate($objp->sellby), 'day') . '' . $objp->qty . ' '; + $warehouse_static->id = $objp->warehouse_id; + $warehouse_static->libelle = $objp->entrepot; + print $warehouse_static->getNomUrl(1); + print '' . dol_trunc($objp->comment) . ''; + $supplierorderdispatch->status = (empty($objp->status) ? 0 : $objp->status); + // print $supplierorderdispatch->status; + print $supplierorderdispatch->getLibStatut(5); + print ''; + if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande->receptionner)) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->fournisseur->commande_advance->check))) { + if (empty($objp->status)) { + print '' . $langs->trans("Approve") . ''; + print '' . $langs->trans("Deny") . ''; + } else { + print '' . $langs->trans("Disapprove") . ''; + print '' . $langs->trans("Deny") . ''; + } + } else { + $disabled = ''; + if ($commande->statut == 5) + $disabled = 1; + if (empty($objp->status)) { + print 'dispatchlineid . '">' . $langs->trans("Approve") . ''; + print 'dispatchlineid . '">' . $langs->trans("Deny") . ''; + } + if ($objp->status == 1) { + print 'dispatchlineid . '">' . $langs->trans("Reinit") . ''; + print 'dispatchlineid . '">' . $langs->trans("Deny") . ''; + } + if ($objp->status == 2) { + print 'dispatchlineid . '">' . $langs->trans("Reinit") . ''; + print 'dispatchlineid . '">' . $langs->trans("Approve") . ''; + } + } + print '
\n"; + } + } else { dol_print_error($db); } } - llxFooter(); $db->close(); diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index 8ea8ad609d1..10c463f71c4 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -132,3 +132,4 @@ OpenAll=Open for all actions OpenInternal=Open for internal actions OpenShipping=Open for shippings OpenDispatch=Open for dispatch +UseDispatchStatus=Use dispatch status (aprouve/refuse) diff --git a/htdocs/langs/en_US/workflow.lang b/htdocs/langs/en_US/workflow.lang index 688938f28ea..e18f93f65ab 100644 --- a/htdocs/langs/en_US/workflow.lang +++ b/htdocs/langs/en_US/workflow.lang @@ -9,4 +9,4 @@ descWORKFLOW_ORDER_AUTOCREATE_INVOICE=Automatically create a customer invoice af descWORKFLOW_ORDER_CLASSIFY_BILLED_PROPAL=Classify linked source proposal to billed when customer order is set to paid descWORKFLOW_INVOICE_CLASSIFY_BILLED_ORDER=Classify linked source customer order(s) to billed when customer invoice is set to paid descWORKFLOW_INVOICE_AMOUNT_CLASSIFY_BILLED_ORDER=Classify linked source customer order(s) to billed when customer invoice is validated -descWORKFLOW_INVOICE_CLASSIFY_BILLED_PROPAL=Classify linked source proposal to billed when customer invoice is validated +descWORKFLOW_INVOICE_CLASSIFY_BILLED_PROPAL=Classify linked source proposal to billed when customer invoice is validated \ No newline at end of file