New: Can add a discount directly when building invoice

This commit is contained in:
Laurent Destailleur
2011-02-19 12:15:17 +00:00
parent deb223afbf
commit 87f2b821de
7 changed files with 83 additions and 86 deletions

View File

@@ -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

View File

@@ -1,6 +1,6 @@
<?PHP
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
*
* 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 '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$objsoc->id.'">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="setremise">';
print '<input type="hidden" name="backtopage" value="'.GETPOST('backtopage').'">';
print '<table class="border" width="100%">';
@@ -260,7 +276,14 @@ if ($_socid > 0)
print '<tr><td>'.$langs->trans("NoteReason").'</td>';
print '<td><input type="text" size="60" name="desc" value="'.$_POST["desc"].'"></td></tr>';
print '<tr><td align="center" colspan="2"><input type="submit" class="button" value="'.$langs->trans("AddGlobalDiscount").'"></td></tr>';
print '<tr><td align="center" colspan="2">';
print '<input type="submit" class="button" name="submit" value="'.$langs->trans("AddGlobalDiscount").'">';
if (GETPOST("backtopage"))
{
print '&nbsp; &nbsp; ';
print '<input type="submit" class="button" name="cancel" value="'.$langs->trans("Cancel").'">';
}
print '</td></tr>';
print "</table></form>";

View File

@@ -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 '<tr><td>'.$langs->trans('Ref').'</td><td colspan="2">'.$langs->trans('Draft').'</td></tr>';
/*
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 '<tr><td>'.$langs->trans('RefCustomerOrder').'</td><td>';
print '<input type="text" name="ref_client" value="'.$ref_client.'">';
print '</td></tr>';
}
// 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 '<tr height="18"><td width="16px" valign="middle">';
print '<input type="radio" name="type" value="0"'.($_POST['type']==0?' checked="true"':'').'>';
print '<input type="radio" name="type" value="0"'.(GETPOST('type')==0?' checked="true"':'').'>';
print '</td><td valign="middle">';
$desc=$html->textwithpicto($langs->trans("InvoiceStandardAsk"),$langs->transnoentities("InvoiceStandardDesc"),1);
print $desc;
@@ -1544,7 +1531,7 @@ if ($_GET['action'] == 'create')
// Deposit
print '<tr height="18"><td width="16px" valign="middle">';
print '<input type="radio" name="type" value="3"'.($_POST['type']==3?' checked="true"':'').'>';
print '<input type="radio" name="type" value="3"'.(GETPOST('type')==3?' checked="true"':'').'>';
print '</td><td valign="middle">';
$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 '<tr height="18"><td width="16px" valign="middle">';
print '<input type="radio" name="type" value="4"'.($_POST['type']==4?' checked="true"':'').'>';
print '<input type="radio" name="type" value="4"'.(GETPOST('type')==4?' checked="true"':'').'>';
print '</td><td valign="middle">';
$desc=$html->textwithpicto($langs->trans("InvoiceProForma"),$langs->transnoentities("InvoiceProFormaDesc"),1);
print $desc;
@@ -1563,7 +1550,7 @@ if ($_GET['action'] == 'create')
// Replacement
print '<tr height="18"><td valign="middle">';
print '<input type="radio" name="type" value="1"'.($_POST['type']==1?' checked=true':'');
print '<input type="radio" name="type" value="1"'.(GETPOST('type')==1?' checked=true':'');
if (! $options) print ' disabled="true"';
print '>';
print '</td><td valign="middle">';
@@ -1587,7 +1574,7 @@ if ($_GET['action'] == 'create')
// Credit note
print '<tr height="18"><td valign="middle">';
print '<input type="radio" name="type" value="2"'.($_POST['type']==2?' checked=true':'');
print '<input type="radio" name="type" value="2"'.(GETPOST('type')==2?' checked=true':'');
if (! $optionsav) print ' disabled="true"';
print '>';
print '</td><td valign="middle">';
@@ -1787,9 +1774,9 @@ if ($_GET['action'] == 'create')
{
$title=$langs->trans('ProductsAndServices');
print_titre($title);
print '<table class="noborder" width="100%">';
$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 '</td></tr>';
// 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 '<tr><td>';
print '<table class="nobordernopadding" width="100%"><tr><td nowrap="nowrap">';
print $langs->trans('RefCustomerOrder').'</td><td align="left">';
print '</td>';
if ($_GET['action'] != 'RefCustomerOrder' && $object->brouillon) print '<td align="right"><a href="'.$_SERVER['PHP_SELF'].'?action=RefCustomerOrder&amp;facid='.$object->id.'">'.img_edit($langs->trans('Modify')).'</a></td>';
print '</tr></table>';
print '</td><td colspan="5">';
if ($user->rights->facture->creer && $_GET['action'] == 'RefCustomerOrder')
{
print '<form action="facture.php?facid='.$object->id.'" method="post">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="set_ref_client">';
print '<input type="text" class="flat" size="20" name="ref_client" value="'.$object->ref_client.'">';
print ' <input type="submit" class="button" value="'.$langs->trans('Modify').'">';
print '</form>';
}
else
{
print $object->ref_client;
}
print '</td>';
print '</tr>';
}
// Third party
print '<tr><td>'.$langs->trans('Company').'</td>';
print '<td colspan="5">'.$soc->getNomUrl(1,'compta');
@@ -2111,18 +2064,21 @@ else
}
print '</td></tr>';
// Discounts
print '<tr><td>'.$langs->trans('Discounts').'</td><td colspan="5">';
// Relative and absolute discounts
print '<tr><td>'.$langs->trans('Discounts');
print '</td><td colspan="5">';
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 '<br>';
$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 '<br>';
$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 '<br>';
$addabsolutediscount=' <a href="'.DOL_URL_ROOT.'/comm/remx.php?id='.$soc->id.'&backtopage='.urlencode($_SERVER["PHP_SELF"]).'?facid='.$object->id.'">'.$langs->trans("AddDiscount").'</a>';
$addcreditnote=' <a href="'.DOL_URL_ROOT.'/compta/facture.php?action=create&socid='.$soc->id.'&type=2&backtopage='.urlencode($_SERVER["PHP_SELF"]).'?facid='.$object->id.'">'.$langs->trans("AddCreditNote").'</a>';
print $addabsolutediscount.' &nbsp; - &nbsp; '.$addcreditnote;
}
print '</td></tr>';
// 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

View File

@@ -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 '<td rowspan="'.$nbrows.'" colspan="2" valign="top">';

View File

@@ -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 '<input type="hidden" name="action" value="setabsolutediscount">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
print '<tr><td>';
print '<tr><td nowrap="nowrap">';
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 '</td>';
print '<td align="left">';
print '<td>';
if ($nbqualifiedlines > 0)
{
print ' &nbsp; <input type="submit" class="button" value="';
@@ -2185,6 +2186,7 @@ class Form
else print $langs->trans("UseCredit");
print '" title="'.$langs->trans("UseCreditNoteInInvoicePayment").'">';
}
if ($more) print $more;
print '</td>';
print '</tr></table></form>';
}

View File

@@ -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

View File

@@ -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