From 7f77391acbfebf210e1af6190a72b7fc32fa62c2 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 14 Nov 2011 16:57:26 +0100 Subject: [PATCH] Ask warehouse even when going back to draft --- htdocs/comm/propal.php | 4 +- htdocs/commande/fiche.php | 88 +++++++++++++++++++++--------- htdocs/compta/facture.php | 98 ++++++++++++++++++++-------------- htdocs/langs/en_US/agenda.lang | 1 + htdocs/langs/en_US/orders.lang | 2 + htdocs/langs/fr_FR/agenda.lang | 1 + htdocs/langs/fr_FR/orders.lang | 2 + 7 files changed, 126 insertions(+), 70 deletions(-) diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 833d7e80443..8bd5bd98f8d 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -1045,9 +1045,7 @@ if ($id > 0 || ! empty($ref)) $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id.'&lineid='.$lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline','',0,1); } - /* - * Confirmation de la validation de la propale - */ + // Confirm validate proposal if ($action == 'validate') { $error=0; diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php index 84c301428e6..f8df322e99a 100644 --- a/htdocs/commande/fiche.php +++ b/htdocs/commande/fiche.php @@ -382,7 +382,7 @@ if ($action == 'setremise' && $user->rights->commande->creer) $object->set_remise($user, $_POST['remise']); } -if ($action == "setabsolutediscount" && $user->rights->commande->creer) +if ($action == 'setabsolutediscount' && $user->rights->commande->creer) { if ($_POST["remise_id"]) { @@ -775,6 +775,45 @@ if ($action == 'confirm_validate' && $confirm == 'yes' && $user->rights->command } } +// Go back to draft status +if ($action == 'confirm_modif' && $user->rights->commande->creer) +{ + $idwarehouse=GETPOST('idwarehouse'); + + $object->fetch($id); // Load order and lines + $object->fetch_thirdparty(); + + // 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->set_draft($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 ($action == 'confirm_close' && $confirm == 'yes' && $user->rights->commande->cloturer) { $object->fetch($id); // Load order and lines @@ -790,30 +829,6 @@ if ($action == 'confirm_cancel' && $confirm == 'yes' && $user->rights->commande- $result = $object->cancel($user); } -if ($action == 'modif' && $user->rights->commande->creer) -{ - /* - * Repasse la commande en mode brouillon - */ - $object->fetch($id); // Load order and lines - $object->fetch_thirdparty(); - - $result = $object->set_draft($user); - 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); - } -} /* * Ordonnancement des lignes @@ -1492,9 +1507,30 @@ else array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockDecrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'),'idwarehouse','',1))); } - $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateOrder'), $text, 'confirm_validate', $formquestion, 0, 1, 240); + $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('ValidateOrder'), $text, 'confirm_validate', $formquestion, 0, 1, 220); } + // Confirm back to draft status + if ($action == 'modif') + { + $text=$langs->trans('ConfirmUnvalidateOrder',$object->ref); + $formquestion=array(); + 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"); + $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("SelectWarehouseForStockIncrease"), 'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse'),'idwarehouse','',1))); + } + + $formconfirm=$form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('UnvalidateOrder'), $text, 'confirm_modif', $formquestion, "yes", 1, 220); + } + + /* * Confirmation de la cloture */ diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 74293809271..9086d0992a9 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -355,56 +355,72 @@ if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->facture->v } } -// Repasse la facture en mode brouillon (unvalidate) +// Go back to draft status (unvalidate) if ($action == 'confirm_modif' && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->facture->valider) || $user->rights->facture->invoice_advance->unvalidate)) { + $idwarehouse=GETPOST('idwarehouse'); + $object->fetch($id); $object->fetch_thirdparty(); - // On verifie si la facture a des paiements - $sql = 'SELECT pf.amount'; - $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf'; - $sql.= ' WHERE pf.fk_facture = '.$object->id; - - $result = $db->query($sql); - if ($result) + // Check parameters + if ($object->type != 3 && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $object->hasProductsOrServices(1)) { - $i = 0; - $num = $db->num_rows($result); - - while ($i < $num) + if (! $idwarehouse || $idwarehouse == -1) { - $objp = $db->fetch_object($result); - $totalpaye += $objp->amount; - $i++; + $error++; + $errors[]=$langs->trans('ErrorFieldRequired',$langs->transnoentitiesnoconv("Warehouse")); + $action=''; } } - else + + if (! $error) { - dol_print_error($db,''); - } - - $resteapayer = $object->total_ttc - $totalpaye; - - // On verifie si les lignes de factures ont ete exportees en compta et/ou ventilees - $ventilExportCompta = $object->getVentilExportCompta(); - - // On verifie si aucun paiement n'a ete effectue - if ($resteapayer == $object->total_ttc && $object->paye == 0 && $ventilExportCompta == 0) - { - $object->set_draft($user); - - // 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)) facture_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager); + // On verifie si la facture a des paiements + $sql = 'SELECT pf.amount'; + $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture as pf'; + $sql.= ' WHERE pf.fk_facture = '.$object->id; + + $result = $db->query($sql); + if ($result) + { + $i = 0; + $num = $db->num_rows($result); + + while ($i < $num) + { + $objp = $db->fetch_object($result); + $totalpaye += $objp->amount; + $i++; + } + } + else + { + dol_print_error($db,''); + } + + $resteapayer = $object->total_ttc - $totalpaye; + + // On verifie si les lignes de factures ont ete exportees en compta et/ou ventilees + $ventilExportCompta = $object->getVentilExportCompta(); + + // On verifie si aucun paiement n'a ete effectue + if ($resteapayer == $object->total_ttc && $object->paye == 0 && $ventilExportCompta == 0) + { + $object->set_draft($user, $idwarehouse); + + // 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)) facture_pdf_create($db, $object, '', $object->modelpdf, $outputlangs, GETPOST('hidedetails'), GETPOST('hidedesc'), GETPOST('hideref'), $hookmanager); + } } } @@ -2014,7 +2030,7 @@ else //'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))); + array('type' => 'other', 'name' => 'idwarehouse', 'label' => $langs->trans("SelectWarehouseForStockIncrease"), '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); diff --git a/htdocs/langs/en_US/agenda.lang b/htdocs/langs/en_US/agenda.lang index 2acf601712d..8a28ba667bc 100644 --- a/htdocs/langs/en_US/agenda.lang +++ b/htdocs/langs/en_US/agenda.lang @@ -38,6 +38,7 @@ InvoiceValidatedInDolibarr= Invoice %s validated InvoiceBackToDraftInDolibarr=Invoice %s go back to draft status OrderValidatedInDolibarr= Order %s validated OrderApprovedInDolibarr=Order %s approved +OrderBackToDraftInDolibarr=Order %s go back to draft status InterventionValidatedInDolibarr=Intervention %s validated ProposalSentByEMail=Commercial proposal %s sent by EMail OrderSentByEMail=Customer order %s sent by EMail diff --git a/htdocs/langs/en_US/orders.lang b/htdocs/langs/en_US/orders.lang index 9b9bdc626e2..ff8a50fad6e 100644 --- a/htdocs/langs/en_US/orders.lang +++ b/htdocs/langs/en_US/orders.lang @@ -59,6 +59,7 @@ CreateOrder=Create Order RefuseOrder=Refuse order ApproveOrder=Accept order ValidateOrder=Validate order +UnvalidateOrder=Unvalidate order DeleteOrder=Delete order CancelOrder=Cancel order AddOrder=Add order @@ -83,6 +84,7 @@ ConfirmCloseOrder=Are you sure you want to close this order ? Once an order is c ConfirmCloseOrderIfSending=Are you sure you want to close this order ? You must close an order only when all shipping are done. ConfirmDeleteOrder=Are you sure you want to delete this order ? ConfirmValidateOrder=Are you sure you want to validate this order under name %s ? +ConfirmUnvalidateOrder=Are you sure you want to restore order %s to draft status ? ConfirmCancelOrder=Are you sure you want to cancel this order ? ConfirmMakeOrder=Are you sure you want to confirm you made this order on %s ? GenerateBill=Generate invoice diff --git a/htdocs/langs/fr_FR/agenda.lang b/htdocs/langs/fr_FR/agenda.lang index f9dd2226d77..b4ef15f0ae9 100644 --- a/htdocs/langs/fr_FR/agenda.lang +++ b/htdocs/langs/fr_FR/agenda.lang @@ -38,6 +38,7 @@ InvoiceValidatedInDolibarr=Facture %s validée InvoiceBackToDraftInDolibarr=Facture %s repassée en brouillon OrderValidatedInDolibarr=Commande %s validée OrderApprovedInDolibarr=Commande %s approuvée +OrderBackToDraftInDolibarr=Commande %s repassée en brouillon InterventionValidatedInDolibarr=Intervention %s validée ProposalSentByEMail=Proposition commerciale %s envoyée par EMail OrderSentByEMail=Commande client %s envoyée par EMail diff --git a/htdocs/langs/fr_FR/orders.lang b/htdocs/langs/fr_FR/orders.lang index 67261fc26cd..df484e33b3a 100644 --- a/htdocs/langs/fr_FR/orders.lang +++ b/htdocs/langs/fr_FR/orders.lang @@ -59,6 +59,7 @@ CreateOrder=Créer Commande RefuseOrder=Refuser la commande ApproveOrder=Accepter la commande ValidateOrder=Valider la commande +UnvalidateOrder=Dévalider la commande DeleteOrder=Supprimer la commande CancelOrder=Annuler la commande AddOrder=Créer commande @@ -83,6 +84,7 @@ ConfirmCloseOrder=Êtes-vous sûr de vouloir clôturer cette commande ? Une fois ConfirmCloseOrderIfSending=Êtes-vous sûr de vouloir clôturer cette commande ? Vous ne devez clôturer une commande qu'une fois les produits expédiés. ConfirmDeleteOrder=Êtes-vous sûr de vouloir effacer cette commande ? ConfirmValidateOrder=Êtes-vous sûr de vouloir valider cette commande sous la référence %s ? +ConfirmUnvalidateOrder=Êtes-vous sûr de vouloir restaurer la commande %s au statut brouillon ? ConfirmCancelOrder=Êtes-vous sûr de vouloir annuler cette commande ? ConfirmMakeOrder=Êtes-vous sûr de vouloir confirmer cette commande en date du %s ? GenerateBill=Facturer