From 87f2b821de1d9925f3eeef3db3164ad7ca1675fa Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 19 Feb 2011 12:15:17 +0000 Subject: [PATCH] New: Can add a discount directly when building invoice --- ChangeLog | 1 + htdocs/comm/remx.php | 43 +++++++++--- htdocs/compta/facture.php | 96 +++++++++------------------ htdocs/compta/facture/apercu.php | 1 - htdocs/core/class/html.form.class.php | 24 ++++--- htdocs/langs/en_US/bills.lang | 2 + htdocs/langs/fr_FR/bills.lang | 2 + 7 files changed, 83 insertions(+), 86 deletions(-) diff --git a/ChangeLog b/ChangeLog index f40003bdb32..9ba6e397910 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,7 @@ $Id$ ***** ChangeLog for 3.1 compared to 3.0 ***** For users: +- New: Can add a discount for third party, during invoice edition. - New: A specialized menu is now used when using smartphones. - New: Can add information on current user on odt generation - New: Prefix on third party is not used by default. Hidden option diff --git a/htdocs/comm/remx.php b/htdocs/comm/remx.php index c5cbd23a51b..545dc91d9cd 100644 --- a/htdocs/comm/remx.php +++ b/htdocs/comm/remx.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2009 Laurent Destailleur + * Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2008 Raphael Bertrand (Resultic) * * This program is free software; you can redistribute it and/or modify @@ -45,13 +45,20 @@ if ($user->societe_id > 0) /* * Actions */ -if ($_REQUEST["action"] == 'confirm_split' && $_REQUEST["confirm"] == 'yes') + +if (GETPOST('cancel') && GETPOST('backtopage')) +{ + Header("Location: ".GETPOST("backtopage")); + exit; +} + +if (GETPOST("action") == 'confirm_split' && GETPOST("confirm") == 'yes') { //if ($user->rights->societe->creer) //if ($user->rights->facture->creer) $error=0; - $remid=isset($_REQUEST["remid"])?$_REQUEST["remid"]:0; + $remid=GETPOST("remid")?GETPOST("remid"):0; $discount=new DiscountAbsolute($db); $res=$discount->fetch($remid); if (! $res > 0) @@ -122,7 +129,7 @@ if ($_REQUEST["action"] == 'confirm_split' && $_REQUEST["confirm"] == 'yes') } } -if ($_POST["action"] == 'setremise') +if (GETPOST("action") == 'setremise') { //if ($user->rights->societe->creer) //if ($user->rights->facture->creer) @@ -144,8 +151,16 @@ if ($_POST["action"] == 'setremise') if ($result > 0) { - Header("Location: remx.php?id=".$_GET["id"]); - exit; + if (GETPOST("backtopage")) + { + Header("Location: ".GETPOST("backtopage")); + exit; + } + else + { + Header("Location: remx.php?id=".$_GET["id"]); + exit; + } } else { @@ -160,7 +175,7 @@ if ($_POST["action"] == 'setremise') } } -if ($_REQUEST["action"] == 'confirm_remove' && $_REQUEST["confirm"]=='yes') +if (GETPOST("action") == 'confirm_remove' && GETPOST("confirm")=='yes') { //if ($user->rights->societe->creer) //if ($user->rights->facture->creer) @@ -168,12 +183,12 @@ if ($_REQUEST["action"] == 'confirm_remove' && $_REQUEST["confirm"]=='yes') $db->begin(); $discount = new DiscountAbsolute($db); - $result=$discount->fetch($_REQUEST["remid"]); + $result=$discount->fetch(GETPOST("remid")); $result=$discount->delete($user); if ($result > 0) { $db->commit(); - header("Location: ".$_SERVER["PHP_SELF"].'?id='.$_REQUEST['id']); // To avoid pb whith back + header("Location: ".$_SERVER["PHP_SELF"].'?id='.GETPOST('id')); // To avoid pb whith back exit; } else @@ -213,6 +228,7 @@ if ($_socid > 0) print '
'; print ''; print ''; + print ''; print ''; @@ -260,7 +276,14 @@ if ($_socid > 0) print ''; print ''; - print ''; + print ''; print "
'.$langs->trans("NoteReason").'
'; + print ''; + if (GETPOST("backtopage")) + { + print '    '; + print ''; + } + print '
"; diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index f9e985d24c9..d99752c89b6 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -1357,7 +1357,7 @@ llxHeader('',$langs->trans('Bill'),'EN:Customers_Invoices|FR:Factures_Clients|ES $html = new Form($db); $formfile = new FormFile($db); - +$now=dol_now(); /********************************************************************* @@ -1439,19 +1439,6 @@ if ($_GET['action'] == 'create') // Ref print ''.$langs->trans('Ref').''.$langs->trans('Draft').''; - /* - L'info "Reference commande client" est une carac de la commande et non de la facture. - Elle devrait donc etre stockee sur l'objet commande liee a la facture et non sur la facture. - Pour ceux qui veulent l'utiliser au niveau de la facture, positionner la - constante FAC_USE_CUSTOMER_ORDER_REF a 1. - */ - if ($conf->global->FAC_USE_CUSTOMER_ORDER_REF) // deprecated - { - print ''.$langs->trans('RefCustomerOrder').''; - print ''; - print ''; - } - // Factures predefinies if (empty($_GET['propalid']) && empty($_GET['commandeid']) && empty($_GET['contratid']) && empty($_GET['originid'])) { @@ -1536,7 +1523,7 @@ if ($_GET['action'] == 'create') // Standard invoice print ''; - print ''; + print ''; print ''; $desc=$html->textwithpicto($langs->trans("InvoiceStandardAsk"),$langs->transnoentities("InvoiceStandardDesc"),1); print $desc; @@ -1544,7 +1531,7 @@ if ($_GET['action'] == 'create') // Deposit print ''; - print ''; + print ''; print ''; $desc=$html->textwithpicto($langs->trans("InvoiceDeposit"),$langs->transnoentities("InvoiceDepositDesc"),1); print $desc; @@ -1554,7 +1541,7 @@ if ($_GET['action'] == 'create') if ($conf->global->FACTURE_USE_PROFORMAT) { print ''; - print ''; + print ''; print ''; $desc=$html->textwithpicto($langs->trans("InvoiceProForma"),$langs->transnoentities("InvoiceProFormaDesc"),1); print $desc; @@ -1563,7 +1550,7 @@ if ($_GET['action'] == 'create') // Replacement print ''; - print ''; print ''; @@ -1587,7 +1574,7 @@ if ($_GET['action'] == 'create') // Credit note print ''; - print ''; print ''; @@ -1787,9 +1774,9 @@ if ($_GET['action'] == 'create') { $title=$langs->trans('ProductsAndServices'); print_titre($title); - + print ''; - + $objectsrc->printOriginTitleList(); $objectsrc->printOriginLinesList($object); @@ -1803,8 +1790,6 @@ else * Show object in view mode */ - $now=dol_now(); - $id = $facid; $ref= GETPOST('ref'); @@ -2034,38 +2019,6 @@ else print $html->showrefnav($object,'ref','',1,'facnumber','ref',$morehtmlref); print ''; - // Ref client - /* - L'info "Reference commande client" est une carac de la commande et non de la facture. - Elle devrait donc etre stockee sur l'objet commande lie a la facture et non sur la facture. - Pour ceux qui utilisent ainsi, positionner la constante FAC_USE_CUSTOMER_ORDER_REF a 1. - */ - if ($conf->global->FAC_USE_CUSTOMER_ORDER_REF) // deprecated - { - print ''; - print ''; - } - // Third party print ''; print ''; - // Discounts - print ''; // Date invoice @@ -2202,7 +2171,6 @@ else */ $nbrows=8; - if ($conf->global->FAC_USE_CUSTOMER_ORDER_REF) $nbrows++; if ($conf->projet->enabled) $nbrows++; //Local taxes diff --git a/htdocs/compta/facture/apercu.php b/htdocs/compta/facture/apercu.php index 85fb4b7d740..2fefe7998c4 100644 --- a/htdocs/compta/facture/apercu.php +++ b/htdocs/compta/facture/apercu.php @@ -129,7 +129,6 @@ if ($_GET["facid"] > 0) // } $nbrows=5; - if ($conf->global->FAC_USE_CUSTOMER_ORDER_REF) $nbrows++; if ($conf->projet->enabled) $nbrows++; print '
'; - print ''; - if ($_GET['action'] != 'RefCustomerOrder' && $object->brouillon) print ''; - print '
'; - print $langs->trans('RefCustomerOrder').''; - print ''.img_edit($langs->trans('Modify')).'
'; - print '
'; - if ($user->rights->facture->creer && $_GET['action'] == 'RefCustomerOrder') - { - print '
'; - print ''; - print ''; - print ''; - print ' '; - print '
'; - } - else - { - print $object->ref_client; - } - print '
'.$langs->trans('Company').''.$soc->getNomUrl(1,'compta'); @@ -2111,18 +2064,21 @@ else } print '
'.$langs->trans('Discounts').''; + // Relative and absolute discounts + print '
'.$langs->trans('Discounts'); + print ''; if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client); else print $langs->trans("CompanyHasNoRelativeDiscount"); print '. '; + if ($absolute_discount > 0) { if ($object->statut > 0 || $object->type == 2 || $object->type == 3) { if ($object->statut == 0) { - print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->monnaie)).'. '; + print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->monnaie)); + print '. '; } else { @@ -2141,10 +2097,10 @@ else } else { - // Remise dispo de type non avoir + // Remise dispo de type remise fixe (not credit note) $filter='fk_facture_source IS NULL'; print '
'; - $html->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id,0,'remise_id',$soc->id,$absolute_discount,$filter,$resteapayer); + $html->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, 0, 'remise_id',$soc->id, $absolute_discount, $filter, $resteapayer); } } if ($absolute_creditnote > 0) @@ -2157,17 +2113,30 @@ else $text=$langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->monnaie)); print $html->textwithpicto($text,$langs->trans("CreditNoteDepositUse")); } - else print $langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->monnaie)).'.'; + else + { + print $langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->monnaie)).'.'; + } } else { // Remise dispo de type avoir $filter='fk_facture_source IS NOT NULL'; if (! $absolute_discount) print '
'; - $html->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id,0,'remise_id_for_payment',$soc->id,$absolute_creditnote,$filter,$resteapayer); + $html->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, 0, 'remise_id_for_payment', $soc->id, $absolute_creditnote, $filter, $resteapayer); } } - if (! $absolute_discount && ! $absolute_creditnote) print $langs->trans("CompanyHasNoAbsoluteDiscount").'.'; + if (! $absolute_discount && ! $absolute_creditnote) + { + print $langs->trans("CompanyHasNoAbsoluteDiscount").'.'; + } + if ($object->statut == 0 && $object->type != 2 && $object->type != 3) + { + if (! $absolute_discount && ! $absolute_creditnote) print '
'; + $addabsolutediscount=' '.$langs->trans("AddDiscount").''; + $addcreditnote=' '.$langs->trans("AddCreditNote").''; + print $addabsolutediscount.'   -   '.$addcreditnote; + } print '
'; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 38b0b08b849..18638cdb7d4 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2151,16 +2151,17 @@ class Form /** - * \brief Affiche formulaire de selection de la remise fixe - * \param page Page URL where form is shown - * \param selected Value pre-selected - * \param htmlname Nom du formulaire select. Si none, non modifiable - * \param socid Third party id - * \param amount Total amount available - * \param filter SQL filter on discounts - * \param maxvalue Max value for lines that can be selected + * Show a select box with available absolute discounts + * @param page Page URL where form is shown + * @param selected Value pre-selected + * @param htmlname Nom du formulaire select. Si none, non modifiable + * @param socid Third party id + * @param amount Total amount available + * @param filter SQL filter on discounts + * @param maxvalue Max value for lines that can be selected + * @param more More string to add */ - function form_remise_dispo($page, $selected='', $htmlname='remise_id',$socid, $amount, $filter='', $maxvalue=0) + function form_remise_dispo($page, $selected='', $htmlname='remise_id',$socid, $amount, $filter='', $maxvalue=0, $more='') { global $conf,$langs; if ($htmlname != "none") @@ -2169,7 +2170,7 @@ class Form print ''; print ''; print ''; - print ''; - print ''; print '
'; + print '
'; if (! $filter || $filter=='fk_facture_source IS NULL') print $langs->trans("CompanyHasAbsoluteDiscount",price($amount),$langs->transnoentities("Currency".$conf->monnaie)).': '; else print $langs->trans("CompanyHasCreditNote",price($amount),$langs->transnoentities("Currency".$conf->monnaie)).': '; // print $langs->trans("AvailableGlobalDiscounts").': '; @@ -2177,7 +2178,7 @@ class Form if ($filter) $newfilter.=' AND '.$filter; $nbqualifiedlines=$this->select_remises('',$htmlname,$newfilter,$socid,$maxvalue); print ''; + print ''; if ($nbqualifiedlines > 0) { print '   '; } + if ($more) print $more; print '
'; } diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index 96eaf17ac2e..eae9aebdea7 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -233,6 +233,8 @@ Reductions=Reductions ReductionsShort=Reduc. Discount=Discount Discounts=Discounts +AddDiscount=Create discount +AddCreditNote=Create credit note ShowDiscount=Show discount RelativeDiscount=Relative discount GlobalDiscount=Global discount diff --git a/htdocs/langs/fr_FR/bills.lang b/htdocs/langs/fr_FR/bills.lang index db0faff162c..7800939913e 100644 --- a/htdocs/langs/fr_FR/bills.lang +++ b/htdocs/langs/fr_FR/bills.lang @@ -234,6 +234,8 @@ RelativeDiscount=Remise relative GlobalDiscount=Remise fixe CreditNote=Avoir CreditNotes=Avoirs +AddDiscount=Créer remise +AddCreditNote=Créer facture avoir Deposit=Acompte Deposits=Acomptes DiscountFromCreditNote=Remise issue de l'avoir %s