Choose warehouse for order validation

This commit is contained in:
Laurent Destailleur 2011-11-07 15:04:02 +01:00
parent 8193e8a54e
commit 8d1284ed42
6 changed files with 1752 additions and 1644 deletions

View File

@ -167,11 +167,13 @@ class Commande extends CommonObject
/** /**
* \brief Validate order * Validate order
* \param user User making status change *
* \return int <=0 if OK, >0 if KO * @param User $user User making status change
* @param int $idwarehouse Id of warehouse to use for stock decrease
* @return int <=0 if OK, >0 if KO
*/ */
function valid($user) function valid($user, $idwarehouse=0)
{ {
global $conf,$langs; global $conf,$langs;
require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php"); require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php");
@ -181,14 +183,14 @@ class Commande extends CommonObject
// Protection // Protection
if ($this->statut == 1) if ($this->statut == 1)
{ {
dol_syslog("Commande::valid no draft status", LOG_WARNING); dol_syslog(get_class($this)."::valid no draft status", LOG_WARNING);
return 0; return 0;
} }
if (! $user->rights->commande->valider) if (! $user->rights->commande->valider)
{ {
$this->error='Permission denied'; $this->error='Permission denied';
dol_syslog("Commande::valid ".$this->error, LOG_ERR); dol_syslog(get_class($this)."::valid ".$this->error, LOG_ERR);
return -1; return -1;
} }
@ -215,17 +217,17 @@ class Commande extends CommonObject
// Validate // Validate
$sql = "UPDATE ".MAIN_DB_PREFIX."commande"; $sql = "UPDATE ".MAIN_DB_PREFIX."commande";
$sql.= " SET ref = '".$num."'"; $sql.= " SET ref = '".$num."',";
$sql.= ", fk_statut = 1"; $sql.= " fk_statut = 1,";
$sql.= ", date_valid=".$this->db->idate($now); $sql.= " date_valid='".$this->db->idate($now)."',";
$sql.= ", fk_user_valid = ".$user->id; $sql.= " fk_user_valid = ".$user->id;
$sql.= " WHERE rowid = ".$this->id; $sql.= " WHERE rowid = ".$this->id;
dol_syslog("Commande::valid() sql=".$sql); dol_syslog("Commande::valid() sql=".$sql);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if (! $resql) if (! $resql)
{ {
dol_syslog("Commande::valid() Echec update - 10 - sql=".$sql, LOG_ERR); dol_syslog(get_class($this)."::valid Echec update - 10 - sql=".$sql, LOG_ERR);
dol_print_error($this->db); dol_print_error($this->db);
$error++; $error++;
} }
@ -244,10 +246,10 @@ class Commande extends CommonObject
{ {
if ($this->lines[$i]->fk_product > 0) if ($this->lines[$i]->fk_product > 0)
{ {
$langs->load("agenda");
$mouvP = new MouvementStock($this->db); $mouvP = new MouvementStock($this->db);
// We decrement stock of product (and sub-products) // We decrement stock of product (and sub-products)
$entrepot_id = "1"; // TODO ajouter possibilite de choisir l'entrepot $result=$mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("OrderValidatedInDolibarr",$this->ref));
$result=$mouvP->livraison($user, $this->lines[$i]->fk_product, $entrepot_id, $this->lines[$i]->qty, $this->lines[$i]->subprice);
if ($result < 0) { $error++; } if ($result < 0) { $error++; }
} }
} }
@ -269,7 +271,7 @@ class Commande extends CommonObject
$dirdest = $conf->commande->dir_output.'/'.$snum; $dirdest = $conf->commande->dir_output.'/'.$snum;
if (file_exists($dirsource)) if (file_exists($dirsource))
{ {
dol_syslog("Commande::valid() rename dir ".$dirsource." into ".$dirdest); dol_syslog(get_class($this)."::valid() rename dir ".$dirsource." into ".$dirdest);
if (@rename($dirsource, $dirdest)) if (@rename($dirsource, $dirdest))
{ {

View File

@ -739,23 +739,39 @@ if ($action == 'updateligne' && $user->rights->commande->creer && $_POST['cancel
if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->commande->valider) if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->commande->valider)
{ {
$idwarehouse=GETPOST('idwarehouse');
$object->fetch($id); // Load order and lines $object->fetch($id); // Load order and lines
$object->fetch_thirdparty(); $object->fetch_thirdparty();
$result=$object->valid($user); // Check parameters
if ($result >= 0) if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1))
{ {
// Define output language if (! $idwarehouse || $idwarehouse == -1)
$outputlangs = $langs;
$newlang='';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
if (! empty($newlang))
{ {
$outputlangs = new Translate("",$conf); $error++;
$outputlangs->setDefaultLang($newlang); $errors[]=$langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("Warehouse"));
$action='';
}
}
if (! $error)
{
$result=$object->valid($user,$idwarehouse);
if ($result >= 0)
{
// Define output language
$outputlangs = $langs;
$newlang='';
if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$object->client->default_lang;
if (! empty($newlang))
{
$outputlangs = new Translate("",$conf);
$outputlangs->setDefaultLang($newlang);
}
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager);
} }
if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) commande_pdf_create($db, $object, $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager);
} }
} }
@ -1413,6 +1429,7 @@ else
if ($id > 0 || ! empty($ref)) if ($id > 0 || ! empty($ref))
{ {
dol_htmloutput_mesg($mesg,$mesgs); dol_htmloutput_mesg($mesg,$mesgs);
dol_htmloutput_errors('',$errors);
$product_static=new Product($db); $product_static=new Product($db);
@ -1462,8 +1479,9 @@ else
$text.='<br>'; $text.='<br>';
$text.=$notify->confirmMessage('NOTIFY_VAL_ORDER',$object->socid); $text.=$notify->confirmMessage('NOTIFY_VAL_ORDER',$object->socid);
} }
if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && '1' == 'TODO') if (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1))
{ {
$langs->load("stocks");
require_once(DOL_DOCUMENT_ROOT."/product/class/html.formproduct.class.php"); require_once(DOL_DOCUMENT_ROOT."/product/class/html.formproduct.class.php");
$formproduct=new FormProduct($db); $formproduct=new FormProduct($db);
$formquestion=array( $formquestion=array(
@ -1473,7 +1491,7 @@ else
array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'),'idwarehouse','',1))); array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'),'idwarehouse','',1)));
} }
$formconfirm=$html->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateOrder'), $text, 'confirm_validate', $formquestion, 0, 1); $formconfirm=$html->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateOrder'), $text, 'confirm_validate', $formquestion, 0, 1, 240);
} }
/* /*

File diff suppressed because it is too large Load Diff

View File

@ -79,3 +79,5 @@ DeleteAWarehouse=Delete a warehouse
ConfirmDeleteWarehouse=Are you sure you want to delete the warehouse <b>%s</b> ? ConfirmDeleteWarehouse=Are you sure you want to delete the warehouse <b>%s</b> ?
PersonalStock=Personal stock %s PersonalStock=Personal stock %s
ThisWarehouseIsPersonalStock=This warehouse represents personal stock of %s %s ThisWarehouseIsPersonalStock=This warehouse represents personal stock of %s %s
SelectWarehouseForStockDecrease=Choose warehouse to use for stock decrease
SelectWarehouseForStockIncrease=Choose warehouse to use for stock increase

View File

@ -79,3 +79,5 @@ DeleteAWarehouse=Supprimer un entrepôt
ConfirmDeleteWarehouse=Êtes-vous sûr de vouloir supprimer l'entrepôt <b>%s</b> ? ConfirmDeleteWarehouse=Êtes-vous sûr de vouloir supprimer l'entrepôt <b>%s</b> ?
PersonalStock=Stock personnel %s PersonalStock=Stock personnel %s
ThisWarehouseIsPersonalStock=Cet entrepôt représente le stock personnel de %s %s ThisWarehouseIsPersonalStock=Cet entrepôt représente le stock personnel de %s %s
SelectWarehouseForStockDecrease=Sélectionner l'entrepôt à utiliser pour la décrémentation du stock
SelectWarehouseForStockIncrease=Sélectionner l'entrepôt à utiliser pour l'incrémentation du stock

View File

@ -118,7 +118,7 @@ class FormProduct
$this->loadWarehouses($fk_product); $this->loadWarehouses($fk_product);
$out='<select class="flat"'.($disabled?' disabled="disabled"':'').' name="'.($htmlname.($disabled?'_disabled':'')).'">'; $out='<select class="flat"'.($disabled?' disabled="disabled"':'').' id="'.$htmlname.'" name="'.($htmlname.($disabled?'_disabled':'')).'">';
if ($empty) $out.='<option value="">&nbsp;</option>'; if ($empty) $out.='<option value="">&nbsp;</option>';
foreach($this->cache_warehouses as $id => $arraytypes) foreach($this->cache_warehouses as $id => $arraytypes)
{ {