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,10 +739,25 @@ 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 (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER) && $object->hasProductsOrServices(1))
{
if (! $idwarehouse || $idwarehouse == -1)
{
$error++;
$errors[]=$langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("Warehouse"));
$action='';
}
}
if (! $error)
{
$result=$object->valid($user,$idwarehouse);
if ($result >= 0) if ($result >= 0)
{ {
// Define output language // Define output language
@ -758,6 +773,7 @@ if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->command
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);
} }
} }
}
if ($action == 'confirm_close' && $confirm == 'yes' && $user->rights->commande->cloturer) if ($action == 'confirm_close' && $confirm == 'yes' && $user->rights->commande->cloturer)
{ {
@ -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);
} }
/* /*

View File

@ -138,7 +138,9 @@ abstract class CommonObject
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface=new Interfaces($this->db); $interface=new Interfaces($this->db);
$result=$interface->run_triggers(strtoupper($this->element).'_ADD_CONTACT',$this,$user,$langs,$conf); $result=$interface->run_triggers(strtoupper($this->element).'_ADD_CONTACT',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; } if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// End call triggers // End call triggers
} }
@ -210,7 +212,9 @@ abstract class CommonObject
include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php");
$interface=new Interfaces($this->db); $interface=new Interfaces($this->db);
$result=$interface->run_triggers(strtoupper($this->element).'_DELETE_CONTACT',$this,$user,$langs,$conf); $result=$interface->run_triggers(strtoupper($this->element).'_DELETE_CONTACT',$this,$user,$langs,$conf);
if ($result < 0) { $error++; $this->errors=$interface->errors; } if ($result < 0) {
$error++; $this->errors=$interface->errors;
}
// End call triggers // End call triggers
} }
@ -1423,20 +1427,40 @@ abstract class CommonObject
$classpath = $element.'/class'; $classpath = $element.'/class';
// To work with non standard path // To work with non standard path
if ($objecttype == 'facture') { $classpath = 'compta/facture/class'; } if ($objecttype == 'facture') {
if ($objecttype == 'propal') { $classpath = 'comm/propal/class'; } $classpath = 'compta/facture/class';
if ($objecttype == 'shipping') { $classpath = 'expedition/class'; $subelement = 'expedition'; $module = 'expedition_bon'; } }
if ($objecttype == 'delivery') { $classpath = 'livraison/class'; $subelement = 'livraison'; $module = 'livraison_bon'; } if ($objecttype == 'propal') {
if ($objecttype == 'invoice_supplier') { $classpath = 'fourn/class'; } $classpath = 'comm/propal/class';
if ($objecttype == 'order_supplier') { $classpath = 'fourn/class'; } }
if ($objecttype == 'fichinter') { $classpath = 'fichinter/class'; $subelement = 'fichinter'; $module = 'ficheinter'; } if ($objecttype == 'shipping') {
$classpath = 'expedition/class'; $subelement = 'expedition'; $module = 'expedition_bon';
}
if ($objecttype == 'delivery') {
$classpath = 'livraison/class'; $subelement = 'livraison'; $module = 'livraison_bon';
}
if ($objecttype == 'invoice_supplier') {
$classpath = 'fourn/class';
}
if ($objecttype == 'order_supplier') {
$classpath = 'fourn/class';
}
if ($objecttype == 'fichinter') {
$classpath = 'fichinter/class'; $subelement = 'fichinter'; $module = 'ficheinter';
}
// TODO ajout temporaire - MAXIME MANGIN // TODO ajout temporaire - MAXIME MANGIN
if ($objecttype == 'contratabonnement') { $classpath = 'contrat/class'; $subelement = 'contrat'; $module = 'contratabonnement'; } if ($objecttype == 'contratabonnement') {
$classpath = 'contrat/class'; $subelement = 'contrat'; $module = 'contratabonnement';
}
$classfile = strtolower($subelement); $classname = ucfirst($subelement); $classfile = strtolower($subelement); $classname = ucfirst($subelement);
if ($objecttype == 'invoice_supplier') { $classfile = 'fournisseur.facture'; $classname = 'FactureFournisseur'; } if ($objecttype == 'invoice_supplier') {
if ($objecttype == 'order_supplier') { $classfile = 'fournisseur.commande'; $classname = 'CommandeFournisseur'; } $classfile = 'fournisseur.facture'; $classname = 'FactureFournisseur';
}
if ($objecttype == 'order_supplier') {
$classfile = 'fournisseur.commande'; $classname = 'CommandeFournisseur';
}
if ($conf->$module->enabled && $element != $this->element) if ($conf->$module->enabled && $element != $this->element)
{ {
@ -1707,6 +1731,32 @@ abstract class CommonObject
else return 0; else return 0;
} }
/**
* Function to say how many lines object contains
*
* @param int $predefined -1=All, 0=Count free product/service only, 1=Count predefined product/service only
* @return int <0 if KO, 0 if no predefined products, nb of lines with predefined products if found
*/
function hasProductsOrServices($predefined=-1)
{
$nb=0;
//if (empty($this->table_element_line)) dol_print_error('Call hasPredefinedProducts on a class with no table_element_line property');
//$sql ='SELECT COUNT(rowid) FROM '.MAIN_DB_PREFIX.$this->table_element_line;
//$sql.='WHERE ...';
//var_dump($this->lines);
foreach($this->lines as $key => $val)
{
$qualified=0;
if ($predefined == -1) $qualified=1;
if ($predefined == 1 && $val->fk_product > 0) $qualified=1;
if ($predefined == 0 && $val->fk_product <= 0) $qualified=1;
if ($qualified) $nb++;
}
dol_syslog(get_class($this).'::hasProductsOrServices we found '.$nb.' qualified lines of products/servcies');
return $nb;
}
// -------------------- // --------------------
// TODO: All functions here must be redesigned and moved as they are not business functions but output functions // TODO: All functions here must be redesigned and moved as they are not business functions but output functions
@ -1737,21 +1787,43 @@ abstract class CommonObject
$classpath = $element.'/class'; $classpath = $element.'/class';
// To work with non standard path // To work with non standard path
if ($objecttype == 'facture' || $objecttype == 'invoice') { $classpath = 'compta/facture/class'; $module='facture'; $subelement='facture'; } if ($objecttype == 'facture' || $objecttype == 'invoice') {
if ($objecttype == 'commande' || $objecttype == 'order') { $classpath = 'commande/class'; $module='commande'; $subelement='commande'; } $classpath = 'compta/facture/class'; $module='facture'; $subelement='facture';
if ($objecttype == 'propal') { $classpath = 'comm/propal/class'; } }
if ($objecttype == 'shipping') { $classpath = 'expedition/class'; $subelement = 'expedition'; $module = 'expedition_bon'; } if ($objecttype == 'commande' || $objecttype == 'order') {
if ($objecttype == 'delivery') { $classpath = 'livraison/class'; $subelement = 'livraison'; $module = 'livraison_bon'; } $classpath = 'commande/class'; $module='commande'; $subelement='commande';
if ($objecttype == 'invoice_supplier') { $classpath = 'fourn/class'; } }
if ($objecttype == 'order_supplier') { $classpath = 'fourn/class'; } if ($objecttype == 'propal') {
if ($objecttype == 'contract') { $classpath = 'contrat/class'; $module='contrat'; $subelement='contrat'; } $classpath = 'comm/propal/class';
if ($objecttype == 'member') { $classpath = 'adherents/class'; $module='adherent'; $subelement='adherent'; } }
if ($objecttype == 'shipping') {
$classpath = 'expedition/class'; $subelement = 'expedition'; $module = 'expedition_bon';
}
if ($objecttype == 'delivery') {
$classpath = 'livraison/class'; $subelement = 'livraison'; $module = 'livraison_bon';
}
if ($objecttype == 'invoice_supplier') {
$classpath = 'fourn/class';
}
if ($objecttype == 'order_supplier') {
$classpath = 'fourn/class';
}
if ($objecttype == 'contract') {
$classpath = 'contrat/class'; $module='contrat'; $subelement='contrat';
}
if ($objecttype == 'member') {
$classpath = 'adherents/class'; $module='adherent'; $subelement='adherent';
}
//print "objecttype=".$objecttype." module=".$module." subelement=".$subelement; //print "objecttype=".$objecttype." module=".$module." subelement=".$subelement;
$classfile = strtolower($subelement); $classname = ucfirst($subelement); $classfile = strtolower($subelement); $classname = ucfirst($subelement);
if ($objecttype == 'invoice_supplier') { $classfile = 'fournisseur.facture'; $classname='FactureFournisseur'; } if ($objecttype == 'invoice_supplier') {
if ($objecttype == 'order_supplier') { $classfile = 'fournisseur.commande'; $classname='CommandeFournisseur'; } $classfile = 'fournisseur.facture'; $classname='FactureFournisseur';
}
if ($objecttype == 'order_supplier') {
$classfile = 'fournisseur.commande'; $classname='CommandeFournisseur';
}
if ($conf->$module->enabled) if ($conf->$module->enabled)
{ {
@ -1790,12 +1862,24 @@ abstract class CommonObject
} }
// To work with non standard path // To work with non standard path
if ($objecttype == 'facture') { $tplpath = 'compta/'.$element; } if ($objecttype == 'facture') {
if ($objecttype == 'propal') { $tplpath = 'comm/'.$element; } $tplpath = 'compta/'.$element;
if ($objecttype == 'shipping') { $tplpath = 'expedition'; } }
if ($objecttype == 'delivery') { $tplpath = 'livraison'; } if ($objecttype == 'propal') {
if ($objecttype == 'invoice_supplier') { $tplpath = 'fourn/facture'; } $tplpath = 'comm/'.$element;
if ($objecttype == 'order_supplier') { $tplpath = 'fourn/commande'; } }
if ($objecttype == 'shipping') {
$tplpath = 'expedition';
}
if ($objecttype == 'delivery') {
$tplpath = 'livraison';
}
if ($objecttype == 'invoice_supplier') {
$tplpath = 'fourn/facture';
}
if ($objecttype == 'order_supplier') {
$tplpath = 'fourn/commande';
}
global $linkedObjectBlock; global $linkedObjectBlock;
$linkedObjectBlock = $objects; $linkedObjectBlock = $objects;

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)
{ {