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 ***** ***** ChangeLog for 3.1 compared to 3.0 *****
For users: For users:
- New: Can add a discount for third party, during invoice edition.
- New: A specialized menu is now used when using smartphones. - New: A specialized menu is now used when using smartphones.
- New: Can add information on current user on odt generation - New: Can add information on current user on odt generation
- New: Prefix on third party is not used by default. Hidden option - New: Prefix on third party is not used by default. Hidden option

View File

@ -1,6 +1,6 @@
<?PHP <?PHP
/* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* 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> * Copyright (C) 2008 Raphael Bertrand (Resultic) <raphael.bertrand@resultic.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -45,13 +45,20 @@ if ($user->societe_id > 0)
/* /*
* Actions * 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->societe->creer)
//if ($user->rights->facture->creer) //if ($user->rights->facture->creer)
$error=0; $error=0;
$remid=isset($_REQUEST["remid"])?$_REQUEST["remid"]:0; $remid=GETPOST("remid")?GETPOST("remid"):0;
$discount=new DiscountAbsolute($db); $discount=new DiscountAbsolute($db);
$res=$discount->fetch($remid); $res=$discount->fetch($remid);
if (! $res > 0) 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->societe->creer)
//if ($user->rights->facture->creer) //if ($user->rights->facture->creer)
@ -144,8 +151,16 @@ if ($_POST["action"] == 'setremise')
if ($result > 0) if ($result > 0)
{ {
Header("Location: remx.php?id=".$_GET["id"]); if (GETPOST("backtopage"))
exit; {
Header("Location: ".GETPOST("backtopage"));
exit;
}
else
{
Header("Location: remx.php?id=".$_GET["id"]);
exit;
}
} }
else 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->societe->creer)
//if ($user->rights->facture->creer) //if ($user->rights->facture->creer)
@ -168,12 +183,12 @@ if ($_REQUEST["action"] == 'confirm_remove' && $_REQUEST["confirm"]=='yes')
$db->begin(); $db->begin();
$discount = new DiscountAbsolute($db); $discount = new DiscountAbsolute($db);
$result=$discount->fetch($_REQUEST["remid"]); $result=$discount->fetch(GETPOST("remid"));
$result=$discount->delete($user); $result=$discount->delete($user);
if ($result > 0) if ($result > 0)
{ {
$db->commit(); $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; exit;
} }
else else
@ -213,6 +228,7 @@ if ($_socid > 0)
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'?id='.$objsoc->id.'">'; 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="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="setremise">'; print '<input type="hidden" name="action" value="setremise">';
print '<input type="hidden" name="backtopage" value="'.GETPOST('backtopage').'">';
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
@ -260,7 +276,14 @@ if ($_socid > 0)
print '<tr><td>'.$langs->trans("NoteReason").'</td>'; print '<tr><td>'.$langs->trans("NoteReason").'</td>';
print '<td><input type="text" size="60" name="desc" value="'.$_POST["desc"].'"></td></tr>'; 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>"; print "</table></form>";

View File

@ -1357,7 +1357,7 @@ llxHeader('',$langs->trans('Bill'),'EN:Customers_Invoices|FR:Factures_Clients|ES
$html = new Form($db); $html = new Form($db);
$formfile = new FormFile($db); $formfile = new FormFile($db);
$now=dol_now();
/********************************************************************* /*********************************************************************
@ -1439,19 +1439,6 @@ if ($_GET['action'] == 'create')
// Ref // Ref
print '<tr><td>'.$langs->trans('Ref').'</td><td colspan="2">'.$langs->trans('Draft').'</td></tr>'; 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 // Factures predefinies
if (empty($_GET['propalid']) && empty($_GET['commandeid']) && empty($_GET['contratid']) && empty($_GET['originid'])) if (empty($_GET['propalid']) && empty($_GET['commandeid']) && empty($_GET['contratid']) && empty($_GET['originid']))
{ {
@ -1536,7 +1523,7 @@ if ($_GET['action'] == 'create')
// Standard invoice // Standard invoice
print '<tr height="18"><td width="16px" valign="middle">'; 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">'; print '</td><td valign="middle">';
$desc=$html->textwithpicto($langs->trans("InvoiceStandardAsk"),$langs->transnoentities("InvoiceStandardDesc"),1); $desc=$html->textwithpicto($langs->trans("InvoiceStandardAsk"),$langs->transnoentities("InvoiceStandardDesc"),1);
print $desc; print $desc;
@ -1544,7 +1531,7 @@ if ($_GET['action'] == 'create')
// Deposit // Deposit
print '<tr height="18"><td width="16px" valign="middle">'; 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">'; print '</td><td valign="middle">';
$desc=$html->textwithpicto($langs->trans("InvoiceDeposit"),$langs->transnoentities("InvoiceDepositDesc"),1); $desc=$html->textwithpicto($langs->trans("InvoiceDeposit"),$langs->transnoentities("InvoiceDepositDesc"),1);
print $desc; print $desc;
@ -1554,7 +1541,7 @@ if ($_GET['action'] == 'create')
if ($conf->global->FACTURE_USE_PROFORMAT) if ($conf->global->FACTURE_USE_PROFORMAT)
{ {
print '<tr height="18"><td width="16px" valign="middle">'; 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">'; print '</td><td valign="middle">';
$desc=$html->textwithpicto($langs->trans("InvoiceProForma"),$langs->transnoentities("InvoiceProFormaDesc"),1); $desc=$html->textwithpicto($langs->trans("InvoiceProForma"),$langs->transnoentities("InvoiceProFormaDesc"),1);
print $desc; print $desc;
@ -1563,7 +1550,7 @@ if ($_GET['action'] == 'create')
// Replacement // Replacement
print '<tr height="18"><td valign="middle">'; 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"'; if (! $options) print ' disabled="true"';
print '>'; print '>';
print '</td><td valign="middle">'; print '</td><td valign="middle">';
@ -1587,7 +1574,7 @@ if ($_GET['action'] == 'create')
// Credit note // Credit note
print '<tr height="18"><td valign="middle">'; 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"'; if (! $optionsav) print ' disabled="true"';
print '>'; print '>';
print '</td><td valign="middle">'; print '</td><td valign="middle">';
@ -1787,9 +1774,9 @@ if ($_GET['action'] == 'create')
{ {
$title=$langs->trans('ProductsAndServices'); $title=$langs->trans('ProductsAndServices');
print_titre($title); print_titre($title);
print '<table class="noborder" width="100%">'; print '<table class="noborder" width="100%">';
$objectsrc->printOriginTitleList(); $objectsrc->printOriginTitleList();
$objectsrc->printOriginLinesList($object); $objectsrc->printOriginLinesList($object);
@ -1803,8 +1790,6 @@ else
* Show object in view mode * Show object in view mode
*/ */
$now=dol_now();
$id = $facid; $id = $facid;
$ref= GETPOST('ref'); $ref= GETPOST('ref');
@ -2034,38 +2019,6 @@ else
print $html->showrefnav($object,'ref','',1,'facnumber','ref',$morehtmlref); print $html->showrefnav($object,'ref','',1,'facnumber','ref',$morehtmlref);
print '</td></tr>'; 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 // Third party
print '<tr><td>'.$langs->trans('Company').'</td>'; print '<tr><td>'.$langs->trans('Company').'</td>';
print '<td colspan="5">'.$soc->getNomUrl(1,'compta'); print '<td colspan="5">'.$soc->getNomUrl(1,'compta');
@ -2111,18 +2064,21 @@ else
} }
print '</td></tr>'; print '</td></tr>';
// Discounts // Relative and absolute discounts
print '<tr><td>'.$langs->trans('Discounts').'</td><td colspan="5">'; print '<tr><td>'.$langs->trans('Discounts');
print '</td><td colspan="5">';
if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client); if ($soc->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$soc->remise_client);
else print $langs->trans("CompanyHasNoRelativeDiscount"); else print $langs->trans("CompanyHasNoRelativeDiscount");
print '. '; print '. ';
if ($absolute_discount > 0) if ($absolute_discount > 0)
{ {
if ($object->statut > 0 || $object->type == 2 || $object->type == 3) if ($object->statut > 0 || $object->type == 2 || $object->type == 3)
{ {
if ($object->statut == 0) 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 else
{ {
@ -2141,10 +2097,10 @@ else
} }
else else
{ {
// Remise dispo de type non avoir // Remise dispo de type remise fixe (not credit note)
$filter='fk_facture_source IS NULL'; $filter='fk_facture_source IS NULL';
print '<br>'; 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) if ($absolute_creditnote > 0)
@ -2157,17 +2113,30 @@ else
$text=$langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->monnaie)); $text=$langs->trans("CompanyHasCreditNote",price($absolute_creditnote),$langs->transnoentities("Currency".$conf->monnaie));
print $html->textwithpicto($text,$langs->trans("CreditNoteDepositUse")); 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 else
{ {
// Remise dispo de type avoir // Remise dispo de type avoir
$filter='fk_facture_source IS NOT NULL'; $filter='fk_facture_source IS NOT NULL';
if (! $absolute_discount) print '<br>'; 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>'; print '</td></tr>';
// Date invoice // Date invoice
@ -2202,7 +2171,6 @@ else
*/ */
$nbrows=8; $nbrows=8;
if ($conf->global->FAC_USE_CUSTOMER_ORDER_REF) $nbrows++;
if ($conf->projet->enabled) $nbrows++; if ($conf->projet->enabled) $nbrows++;
//Local taxes //Local taxes

View File

@ -129,7 +129,6 @@ if ($_GET["facid"] > 0)
// } // }
$nbrows=5; $nbrows=5;
if ($conf->global->FAC_USE_CUSTOMER_ORDER_REF) $nbrows++;
if ($conf->projet->enabled) $nbrows++; if ($conf->projet->enabled) $nbrows++;
print '<td rowspan="'.$nbrows.'" colspan="2" valign="top">'; 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 * Show a select box with available absolute discounts
* \param page Page URL where form is shown * @param page Page URL where form is shown
* \param selected Value pre-selected * @param selected Value pre-selected
* \param htmlname Nom du formulaire select. Si none, non modifiable * @param htmlname Nom du formulaire select. Si none, non modifiable
* \param socid Third party id * @param socid Third party id
* \param amount Total amount available * @param amount Total amount available
* \param filter SQL filter on discounts * @param filter SQL filter on discounts
* \param maxvalue Max value for lines that can be selected * @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; global $conf,$langs;
if ($htmlname != "none") if ($htmlname != "none")
@ -2169,7 +2170,7 @@ class Form
print '<input type="hidden" name="action" value="setabsolutediscount">'; print '<input type="hidden" name="action" value="setabsolutediscount">';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">'; 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)).': '; 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)).': '; else print $langs->trans("CompanyHasCreditNote",price($amount),$langs->transnoentities("Currency".$conf->monnaie)).': ';
// print $langs->trans("AvailableGlobalDiscounts").': '; // print $langs->trans("AvailableGlobalDiscounts").': ';
@ -2177,7 +2178,7 @@ class Form
if ($filter) $newfilter.=' AND '.$filter; if ($filter) $newfilter.=' AND '.$filter;
$nbqualifiedlines=$this->select_remises('',$htmlname,$newfilter,$socid,$maxvalue); $nbqualifiedlines=$this->select_remises('',$htmlname,$newfilter,$socid,$maxvalue);
print '</td>'; print '</td>';
print '<td align="left">'; print '<td>';
if ($nbqualifiedlines > 0) if ($nbqualifiedlines > 0)
{ {
print ' &nbsp; <input type="submit" class="button" value="'; print ' &nbsp; <input type="submit" class="button" value="';
@ -2185,6 +2186,7 @@ class Form
else print $langs->trans("UseCredit"); else print $langs->trans("UseCredit");
print '" title="'.$langs->trans("UseCreditNoteInInvoicePayment").'">'; print '" title="'.$langs->trans("UseCreditNoteInInvoicePayment").'">';
} }
if ($more) print $more;
print '</td>'; print '</td>';
print '</tr></table></form>'; print '</tr></table></form>';
} }

View File

@ -233,6 +233,8 @@ Reductions=Reductions
ReductionsShort=Reduc. ReductionsShort=Reduc.
Discount=Discount Discount=Discount
Discounts=Discounts Discounts=Discounts
AddDiscount=Create discount
AddCreditNote=Create credit note
ShowDiscount=Show discount ShowDiscount=Show discount
RelativeDiscount=Relative discount RelativeDiscount=Relative discount
GlobalDiscount=Global discount GlobalDiscount=Global discount

View File

@ -234,6 +234,8 @@ RelativeDiscount=Remise relative
GlobalDiscount=Remise fixe GlobalDiscount=Remise fixe
CreditNote=Avoir CreditNote=Avoir
CreditNotes=Avoirs CreditNotes=Avoirs
AddDiscount=Créer remise
AddCreditNote=Créer facture avoir
Deposit=Acompte Deposit=Acompte
Deposits=Acomptes Deposits=Acomptes
DiscountFromCreditNote=Remise issue de l'avoir %s DiscountFromCreditNote=Remise issue de l'avoir %s