diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php
index abe04634432..c83edcea45e 100644
--- a/htdocs/commande/class/commande.class.php
+++ b/htdocs/commande/class/commande.class.php
@@ -317,10 +317,11 @@ class Commande extends CommonObject
/**
* Set draft status
*
- * @param User $user Object user that modify
- * @return int <0 if KO, >0 if OK
+ * @param User $user Object user that modify
+ * @param int $idwarehouse Id warehouse to use for stock change.
+ * @return int <0 if KO, >0 if OK
*/
- function set_draft($user, $idwarehouse=1)
+ function set_draft($user, $idwarehouse=-1)
{
global $conf,$langs;
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 85f8afd0bf5..74293809271 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -321,7 +321,7 @@ if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->facture->v
$object->fetch_thirdparty();
// Check parameters
- if (! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $object->hasProductsOrServices(1))
+ if ($object->type != 3 && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $object->hasProductsOrServices(1))
{
if (! $idwarehouse || $idwarehouse == -1)
{
@@ -356,7 +356,7 @@ if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->facture->v
}
// Repasse la facture en mode brouillon (unvalidate)
-if ($action == 'modif' && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->facture->valider) || $user->rights->facture->invoice_advance->unvalidate))
+if ($action == 'confirm_modif' && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->facture->valider) || $user->rights->facture->invoice_advance->unvalidate))
{
$object->fetch($id);
$object->fetch_thirdparty();
@@ -1985,7 +1985,7 @@ else
$text.=$notify->confirmMessage('NOTIFY_VAL_FAC',$object->socid);
}
$formquestion=array();
- if (! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $object->hasProductsOrServices(1))
+ if ($object->type != 3 && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $object->hasProductsOrServices(1))
{
$langs->load("stocks");
require_once(DOL_DOCUMENT_ROOT."/product/class/html.formproduct.class.php");
@@ -2000,6 +2000,26 @@ else
$formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?facid='.$object->id,$langs->trans('ValidateBill'),$text,'confirm_valid',$formquestion,"yes",($conf->notification->enabled?0:2));
}
+ // Confirm back to draft status
+ if ($action == 'modif')
+ {
+ $text=$langs->trans('ConfirmUnvalidateBill',$object->ref);
+ $formquestion=array();
+ if ($object->type != 3 && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $object->hasProductsOrServices(1))
+ {
+ $langs->load("stocks");
+ require_once(DOL_DOCUMENT_ROOT."/product/class/html.formproduct.class.php");
+ $formproduct=new FormProduct($db);
+ $formquestion=array(
+ //'text' => $langs->trans("ConfirmClone"),
+ //array('type' => 'checkbox', 'name' => 'clone_content', 'label' => $langs->trans("CloneMainAttributes"), 'value' => 1),
+ //array('type' => 'checkbox', 'name' => 'update_prices', 'label' => $langs->trans("PuttingPricesUpToDate"), 'value' => 1),
+ array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'),'idwarehouse','',1)));
+ }
+
+ $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?facid='.$object->id,$langs->trans('UnvalidateBill'),$text,'confirm_modif',$formquestion,"yes",1);
+ }
+
// Confirmation du classement paye
if ($action == 'paid' && $resteapayer <= 0)
{
diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php
index 66171a68ec6..e876bd69731 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -1481,6 +1481,7 @@ class Facture extends CommonObject
/**
* Tag invoice as validated + call trigger BILL_VALIDATE
+ * Object must have lines loaded with fetch_lines
*
* @param User $user Object user that validate
* @param string $force_number Reference to force on invoice
@@ -1494,7 +1495,7 @@ class Facture extends CommonObject
$error=0;
- // Protection
+ // Check parameters
if (! $this->brouillon)
{
dol_syslog(get_class($this)."::validate no draft status", LOG_WARNING);
@@ -1698,10 +1699,10 @@ class Facture extends CommonObject
* Set draft status
*
* @param User $user Object user that modify
- * @param int $idwarehouse Id warehouse to use for stock change
+ * @param int $idwarehouse Id warehouse to use for stock change.
* @return int <0 if KO, >0 if OK
*/
- function set_draft($user,$idwarehouse=1)
+ function set_draft($user,$idwarehouse=-1)
{
global $conf,$langs;
@@ -1720,7 +1721,8 @@ class Facture extends CommonObject
$sql.= " WHERE rowid = ".$this->id;
dol_syslog(get_class($this)."::set_draft sql=".$sql, LOG_DEBUG);
- if ($this->db->query($sql))
+ $result=$this->db->query($sql);
+ if ($result)
{
// Si on decremente le produit principal et ses composants a la validation de facture, on réincrement
if ($this->type != 3 && $result >= 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_BILL)
diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php
index 83f1bfa651d..d4825c62fd1 100644
--- a/htdocs/fourn/class/fournisseur.commande.class.php
+++ b/htdocs/fourn/class/fournisseur.commande.class.php
@@ -382,10 +382,11 @@ class CommandeFournisseur extends Commande
* Set draft status
* TODO This method seems to be never called.
*
- * @param User $user Object user that modify
- * @return int <0 if KO, >0 if OK
+ * @param User $user Object user that modify
+ * @param int $idwarehouse Id warehouse to use for stock change.
+ * @return int <0 if KO, >0 if OK
*/
- function set_draft($user)
+ function set_draft($user, $idwarehouse=-1)
{
global $conf,$langs;
@@ -425,8 +426,7 @@ class CommandeFournisseur extends Commande
{
$mouvP = new MouvementStock($this->db);
// We increment stock of product (and sub-products)
- $entrepot_id = "1"; // TODO ajouter possibilite de choisir l'entrepot
- $result=$mouvP->reception($user, $this->lines[$i]->fk_product, $entrepot_id, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("OrderBackToDraftInDolibarr",$this->ref));
+ $result=$mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("OrderBackToDraftInDolibarr",$this->ref));
if ($result < 0) { $error++; }
}
}
diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php
index ed2100a03bd..244efc1a636 100644
--- a/htdocs/fourn/class/fournisseur.facture.class.php
+++ b/htdocs/fourn/class/fournisseur.facture.class.php
@@ -835,11 +835,13 @@ class FactureFournisseur extends Facture
/**
- * Set draft status
- * @param user Object user that modify
- * @param int <0 if KO, >0 if OK
+ * Set draft status
+ *
+ * @param User $user Object user that modify
+ * @param int $idwarehouse Id warehouse to use for stock change.
+ * @return int <0 if KO, >0 if OK
*/
- function set_draft($user)
+ function set_draft($user, $idwarehouse=-1)
{
global $conf,$langs;
@@ -847,7 +849,7 @@ class FactureFournisseur extends Facture
if ($this->statut == 0)
{
- dol_syslog("FactureFournisseur::set_draft already draft status", LOG_WARNING);
+ dol_syslog(get_class($this)."::set_draft already draft status", LOG_WARNING);
return 0;
}
@@ -857,8 +859,9 @@ class FactureFournisseur extends Facture
$sql.= " SET fk_statut = 0";
$sql.= " WHERE rowid = ".$this->id;
- dol_syslog("FactureFournisseur::set_draft sql=".$sql, LOG_DEBUG);
- if ($this->db->query($sql))
+ dol_syslog(get_class($this)."::set_draft sql=".$sql, LOG_DEBUG);
+ $result=$this->db->query($sql);
+ if ($result)
{
// Si on incremente le produit principal et ses composants a la validation de facture fournisseur, on decremente
if ($result >= 0 && $conf->stock->enabled && $conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL)
@@ -873,8 +876,7 @@ class FactureFournisseur extends Facture
{
$mouvP = new MouvementStock($this->db);
// We increase stock for product
- $entrepot_id = "1"; // TODO ajouter possibilite de choisir l'entrepot
- $result=$mouvP->livraison($user, $this->lines[$i]->fk_product, $entrepot_id, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceBackToDraftInDolibarr",$this->ref));
+ $result=$mouvP->livraison($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $this->lines[$i]->subprice, $langs->trans("InvoiceBackToDraftInDolibarr",$this->ref));
}
}
}
@@ -901,10 +903,10 @@ class FactureFournisseur extends Facture
/**
* Ajoute une ligne de facture (associe a aucun produit/service predefini)
- * Les parametres sont deja cense etre juste et avec valeurs finales a l'appel
- * de cette methode. Aussi, pour le taux tva, il doit deja avoir ete defini
- * par l'appelant par la methode get_default_tva(societe_vendeuse,societe_acheteuse,idprod)
- * et le desc doit deja avoir la bonne valeur (a l'appelant de gerer le multilangue)
+ * Les parametres sont deja cense etre juste et avec valeurs finales a l'appel
+ * de cette methode. Aussi, pour le taux tva, il doit deja avoir ete defini
+ * par l'appelant par la methode get_default_tva(societe_vendeuse,societe_acheteuse,idprod)
+ * et le desc doit deja avoir la bonne valeur (a l'appelant de gerer le multilangue)
*
* @param desc Description de la ligne
* @param pu Prix unitaire (HT ou TTC selon price_base_type)
diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang
index a66bd16a546..b6ff02dfbf4 100644
--- a/htdocs/langs/en_US/bills.lang
+++ b/htdocs/langs/en_US/bills.lang
@@ -144,6 +144,7 @@ SuppliersDraftInvoices=Suppliers draft invoices
Unpaid=Unpaid
ConfirmDeleteBill=Are you sure you want to delete this invoice ?
ConfirmValidateBill=Are you sure you want to validate this invoice with reference %s ?
+ConfirmUnvalidateBill=Are you sure you want to change invoice %s to draft status ?
ConfirmClassifyPaidBill=Are you sure you want to change invoice %s to status paid ?
ConfirmCancelBill=Are you sure you want to cancel invoice %s ?
ConfirmCancelBillQuestion=Why do you want to classify this invoice 'abandoned' ?
@@ -166,6 +167,7 @@ ConfirmClassifyAbandonReasonOtherDesc=This choice will be used in all other case
ConfirmCustomerPayment=Do you confirm this payment input for %s %s ?
ConfirmValidatePayment=Are you sure you want to validate this payment ? No change can be made once payment is validated.
ValidateBill=Validate invoice
+UnvalidateBill=Unvalidate invoice
NumberOfBills=Nb of invoices
NumberOfBillsByMonth=Nb of invoices by month
AmountOfBills=Amount of invoices
diff --git a/htdocs/langs/fr_FR/bills.lang b/htdocs/langs/fr_FR/bills.lang
index 99865ba5387..6be746e3f55 100644
--- a/htdocs/langs/fr_FR/bills.lang
+++ b/htdocs/langs/fr_FR/bills.lang
@@ -140,6 +140,7 @@ SuppliersDraftInvoices=Factures fournisseurs brouillons
Unpaid=Impayées
ConfirmDeleteBill=Êtes-vous sûr de vouloir supprimer cette facture ?
ConfirmValidateBill=Êtes-vous sûr de vouloir valider cette facture sous la référence %s ?
+ConfirmUnvalidateBill=Êtes-vous sûr de vouloir repasser la facture %s au statut brouillon ?
ConfirmClassifyPaidBill=Êtes-vous sûr de vouloir classer la facture %s comme payée ?
ConfirmCancelBill=Êtes-vous sûr de vouloir annuler la facture %s ?
ConfirmCancelBillQuestion=Pour quelle raison voulez-vous classer la facture abandonnée ?
@@ -162,6 +163,7 @@ ConfirmClassifyAbandonReasonOtherDesc=Ce choix sera celui choisi dans tout autre
ConfirmCustomerPayment=Confirmez-vous la saisie de ce règlement de %s %s ?
ConfirmValidatePayment=Êtes-vous sûr de vouloir valider ce paiement, aucune modification n'est possible une fois le paiement validé ?
ValidateBill=Valider facture
+UnvalidateBill=Repasser facture en brouillon
NumberOfBills=Nb de factures
NumberOfBillsByMonth=Nb de factures par mois
AmountOfBills=Montant de factures
diff --git a/htdocs/product/stock/class/mouvementstock.class.php b/htdocs/product/stock/class/mouvementstock.class.php
index 3c6d2e051e6..d96539e311e 100644
--- a/htdocs/product/stock/class/mouvementstock.class.php
+++ b/htdocs/product/stock/class/mouvementstock.class.php
@@ -78,7 +78,7 @@ class MouvementStock
$movestock=0;
if ($product->type != 1 || ! empty($conf->global->STOCK_SUPPORTS_SERVICES)) $movestock=1;
- if ($movestock) // Change stock for current product, change for subproduct is done after
+ if ($movestock && $entrepot_id > 0) // Change stock for current product, change for subproduct is done after
{
$sql = "INSERT INTO ".MAIN_DB_PREFIX."stock_mouvement";
$sql.= " (datem, fk_product, fk_entrepot, value, type_mouvement, fk_user_author, label, price)";