Fix: Deposits was not included into lines but into into remain to pay

This commit is contained in:
Laurent Destailleur 2011-11-16 18:58:11 +01:00
parent 3d01d77427
commit bf9c482f8a
15 changed files with 100 additions and 58 deletions

View File

@ -359,7 +359,7 @@ if ($action == 'confirm_valid' && $confirm == 'yes' && $user->rights->facture->v
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();
@ -380,13 +380,13 @@ if ($action == 'confirm_modif' && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS
$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);
@ -398,17 +398,17 @@ if ($action == 'confirm_modif' && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS
{
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='';
@ -1937,8 +1937,13 @@ else
if ($object->paye) $resteapayer=0;
$resteapayeraffiche=$resteapayer;
$absolute_discount=$soc->getAvailableDiscounts('','fk_facture_source IS NULL');
$absolute_creditnote=$soc->getAvailableDiscounts('','fk_facture_source IS NOT NULL');
//$filterabsolutediscount="fk_facture_source IS NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
//$filtercreditnote="fk_facture_source IS NOT NULL"; // If we want deposit to be substracted to payments only and not to total of final invoice
$filterabsolutediscount="fk_facture_source IS NULL OR (fk_facture_source IS NOT NULL AND description='(DEPOSIT)')";
$filtercreditnote="fk_facture_source IS NOT NULL AND description <> '(DEPOSIT)'";
$absolute_discount=$soc->getAvailableDiscounts('',$filterabsolutediscount);
$absolute_creditnote=$soc->getAvailableDiscounts('',$filtercreditnote);
$absolute_discount=price2num($absolute_discount,'MT');
$absolute_creditnote=price2num($absolute_creditnote,'MT');
@ -2259,9 +2264,8 @@ else
else
{
// Remise dispo de type remise fixe (not credit note)
$filter='fk_facture_source IS NULL';
print '<br>';
$form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, GETPOST('discountid'), 'remise_id', $soc->id, $absolute_discount, $filter, $resteapayer, ' ('.$addabsolutediscount.')');
$form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, GETPOST('discountid'), 'remise_id', $soc->id, $absolute_discount, $filterabsolutediscount, $resteapayer, ' ('.$addabsolutediscount.')');
}
}
else
@ -2291,9 +2295,8 @@ else
else
{
// Remise dispo de type avoir
$filter='fk_facture_source IS NOT NULL';
if (! $absolute_discount) print '<br>';
$form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, 0, 'remise_id_for_payment', $soc->id, $absolute_creditnote, $filter, $resteapayer);
$form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, 0, 'remise_id_for_payment', $soc->id, $absolute_creditnote, $filtercreditnote, $resteapayer);
}
}
if (! $absolute_discount && ! $absolute_creditnote)

View File

@ -89,13 +89,12 @@ else
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."bank_account as ba ON b.fk_account = ba.rowid";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON p.rowid = pf.fk_paiement";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON pf.fk_facture = f.rowid";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON f.fk_soc = s.rowid AND s.entity = ".$conf->entity;
if (!$user->rights->societe->client->voir && !$socid)
{
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
}
$sql.= " WHERE p.fk_paiement = c.id";
$sql.= " AND s.entity = ".$conf->entity;
if (!$user->rights->societe->client->voir && !$socid)
{
$sql.= " AND sc.fk_user = " .$user->id;

View File

@ -35,7 +35,7 @@ accessforbidden();
// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES')
$modecompta = $conf->global->COMPTA_MODE;
if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"];
if (GETPOST("modecompta")) $modecompta=GETPOST("modecompta");
$sortorder=isset($_GET["sortorder"])?$_GET["sortorder"]:$_POST["sortorder"];
$sortfield=isset($_GET["sortfield"])?$_GET["sortfield"]:$_POST["sortfield"];
@ -121,7 +121,10 @@ else {
$builddate=time();
//$exportlink=$langs->trans("NotYetAvailable");
}
report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink);
$moreparam=array();
if (! empty($modecompta)) $moreparam['modecompta']=$modecompta;
report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink,$moreparam);
// Charge tableau
@ -136,7 +139,7 @@ if ($modecompta == 'CREANCES-DETTES')
$sql.= " f.type = 0"; // Standard
$sql.= " OR f.type = 1"; // Replacement
$sql.= " OR f.type = 2"; // Credit note
//$sql.= " OR f.type = 3"; // We do not include deposit
$sql.= " OR f.type = 3"; // Deposit
$sql.= ")";
if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
}

View File

@ -32,7 +32,7 @@ $langs->load("companies");
// Define modecompta ('CREANCES-DETTES' or 'RECETTES-DEPENSES')
$modecompta = $conf->global->COMPTA_MODE;
if ($_GET["modecompta"]) $modecompta=$_GET["modecompta"];
if (GETPOST("modecompta")) $modecompta=GETPOST("modecompta");
$sortorder=isset($_GET["sortorder"])?$_GET["sortorder"]:$_POST["sortorder"];
$sortfield=isset($_GET["sortfield"])?$_GET["sortfield"]:$_POST["sortfield"];
@ -124,7 +124,9 @@ else {
$builddate=time();
//$exportlink=$langs->trans("NotYetAvailable");
}
report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink);
$moreparam=array();
if (! empty($modecompta)) $moreparam['modecompta']=$modecompta;
report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportlink,$moreparam);
// Charge tableau
@ -139,7 +141,7 @@ if ($modecompta == 'CREANCES-DETTES')
$sql.= " f.type = 0"; // Standard
$sql.= " OR f.type = 1"; // Replacement
$sql.= " OR f.type = 2"; // Credit note
//$sql.= " OR f.type = 3"; // We do not include deposit
$sql.= " OR f.type = 3"; // Deposit
$sql.= ")";
$sql.= " AND f.fk_soc = s.rowid";
if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";

View File

@ -87,7 +87,7 @@ if ($modecompta == 'CREANCES-DETTES') {
$sql.= " f.type = 0"; // Standard
$sql.= " OR f.type = 1"; // Replacement
$sql.= " OR f.type = 2"; // Credit note
//$sql.= " OR f.type = 3"; // We do not include deposit
$sql.= " OR f.type = 3"; // Deposit
$sql.= ")";
} else {
/*
@ -221,7 +221,7 @@ for ($mois = 1+$nb_mois_decalage ; $mois <= 12+$nb_mois_decalage ; $mois++)
if ($cum[$case])
{
$now_show_delta=1; // On a trouve le premier mois de la premiere annee generant du chiffre.
print '<a href="casoc.php?year='.$annee_decalage.'&month='.$mois_modulo.'">'.price($cum[$case],1).'</a>';
print '<a href="casoc.php?year='.$annee_decalage.'&month='.$mois_modulo.($modecompta?'&modecompta='.$modecompta:'').'">'.price($cum[$case],1).'</a>';
}
else
{

View File

@ -2023,6 +2023,7 @@ abstract class CommonObject
* TODO Move this into an output class file (htmlline.class.php)
* If lines are into a template, title must also be into a template
* But for the moment we don't know if it's possible as we keep a method available on overloaded objects.
*
* @param $action GET/POST action
* @param $line Selected object line to output
* @param $var Is it a an odd line

View File

@ -352,7 +352,7 @@ class DiscountAbsolute
$sql.= " WHERE (rc.fk_facture IS NULL AND rc.fk_facture_line IS NULL)"; // Available
if (is_object($company)) $sql.= " AND rc.fk_soc = ".$company->id;
if (is_object($user)) $sql.= " AND rc.fk_user = ".$user->id;
if ($filter) $sql.=' AND '.$filter;
if ($filter) $sql.=' AND ('.$filter.')';
if ($maxvalue) $sql.=' AND rc.amount_ttc <= '.price2num($maxvalue);
dol_syslog(get_class($this)."::getAvailableDiscounts sql=".$sql,LOG_DEBUG);

View File

@ -2710,7 +2710,7 @@ class Form
* @param float $amount Total amount available
* @param string $filter SQL filter on discounts
* @param int $maxvalue Max value for lines that can be selected
* @param string $more More string to add
* @param string $more More string to add
* @return void
*/
function form_remise_dispo($page, $selected='', $htmlname='remise_id',$socid, $amount, $filter='', $maxvalue=0, $more='')
@ -2723,19 +2723,19 @@ class Form
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<table class="nobordernopadding" cellpadding="0" cellspacing="0">';
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)).': '; // If we want deposit to be substracted to payments only and not to total of final invoice
if (! $filter || $filter=="fk_facture_source IS NULL OR (fk_facture_source IS NOT NULL AND description='(DEPOSIT)')") print $langs->trans("CompanyHasAbsoluteDiscount",price($amount),$langs->transnoentities("Currency".$conf->monnaie)).': ';
else print $langs->trans("CompanyHasCreditNote",price($amount),$langs->transnoentities("Currency".$conf->monnaie)).': ';
$newfilter='fk_facture IS NULL AND fk_facture_line IS NULL'; // Remises disponibles
if ($filter) $newfilter.=' AND '.$filter;
if ($filter) $newfilter.=' AND ('.$filter.')';
$nbqualifiedlines=$this->select_remises($selected,$htmlname,$newfilter,$socid,$maxvalue);
print '</td>';
print '<td>';
if ($nbqualifiedlines > 0)
{
print ' &nbsp; <input type="submit" class="button" value="';
if (! $filter || $filter=='fk_facture_source IS NULL') print $langs->trans("UseDiscount");
else print $langs->trans("UseCredit");
print '" title="'.$langs->trans("UseCreditNoteInInvoicePayment").'">';
print ' &nbsp; <input type="submit" class="button" value="'.$langs->trans("UseLine").'"';
if ($filter && $filter != "fk_facture_source IS NULL OR (fk_facture_source IS NOT NULL AND description='(DEPOSIT)')") print '" title="'.$langs->trans("UseCreditNoteInInvoicePayment");
print '">';
}
if ($more) print $more;
print '</td>';

View File

@ -748,6 +748,14 @@ function pdf_getlinedesc($object,$i,$outputlangs,$hideref=0,$hidedesc=0,$issuppl
$discount->fetch($object->lines[$i]->fk_remise_except);
$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromCreditNote",$discount->ref_facture_source);
}
elseif ($desc == '(DEPOSIT)' && $object->lines[$i]->fk_remise_except)
{
$discount=new DiscountAbsolute($db);
$discount->fetch($object->lines[$i]->fk_remise_except);
$libelleproduitservice=$outputlangs->transnoentities("DiscountFromDeposit",$discount->ref_facture_source);
// Add date of deposit
if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) echo ' ('.dol_print_date($discount->datec,'day','',$outputlangs).')';
}
else
{
if ($idprod)

View File

@ -24,15 +24,17 @@
/**
* Show header of a VAT report
* @param nom Name of report
* @param variante Link for alternate report
* @param period Period of report
* @param periodlink Link to switch period
* @param description Description
* @param builddate Date generation
* @param exportlink Link for export or ''
*
* @param $nom Name of report
* @param $variante Link for alternate report
* @param $period Period of report
* @param $periodlink Link to switch period
* @param $description Description
* @param $builddate Date generation
* @param $exportlink Link for export or ''
* @param $moreparam Array with list of params to add into form
*/
function report_header($nom,$variante='',$period,$periodlink,$description,$builddate,$exportlink='')
function report_header($nom,$variante='',$period,$periodlink,$description,$builddate,$exportlink='',$moreparam=array())
{
global $langs;
@ -44,6 +46,10 @@ function report_header($nom,$variante='',$period,$periodlink,$description,$build
dol_fiche_head($head, $hselected, $societe->nom);
print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
foreach($moreparam as $key => $value)
{
print '<input type="hidden" name="'.$key.'" value="'.$value.'">';
}
print '<table width="100%" class="border">';
// Ligne de titre

View File

@ -23,29 +23,47 @@
<td><a name="<?php echo $line->rowid; ?>"></a>
<?php if (($line->info_bits & 2) == 2) { ?>
<a href="<?php echo DOL_URL_ROOT.'/comm/remx.php?id='.$this->socid; ?>">
<?php echo img_object($langs->trans("ShowReduc"),'reduc').' '.$langs->trans("Discount"); ?>
<?php
$txt='';
print img_object($langs->trans("ShowReduc"),'reduc').' ';
if ($line->description == '(DEPOSIT)') $txt=$langs->trans("Deposit");
//else $txt=$langs->trans("Discount");
print $txt;
?>
</a>
<?php if ($line->description) {
if ($line->description == '(CREDIT_NOTE)') {
<?php
if ($line->description)
{
if ($line->description == '(CREDIT_NOTE)')
{
$discount=new DiscountAbsolute($this->db);
$discount->fetch($line->fk_remise_except);
echo ' - '.$langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0));
} elseif ($line->description == '(DEPOSIT)') {
echo ($txt?' - ':'').$langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0));
}
elseif ($line->description == '(DEPOSIT)')
{
$discount=new DiscountAbsolute($this->db);
$discount->fetch($line->fk_remise_except);
echo ' - '.$langs->transnoentities("DiscountFromDeposit",$discount->getNomUrl(0));
} else {
echo ' - '.dol_htmlentitiesbr($line->description,1,true);
echo ($txt?' - ':'').$langs->transnoentities("DiscountFromDeposit",$discount->getNomUrl(0));
// Add date of deposit
if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) echo ' ('.dol_print_date($discount->datec).')';
}
else
{
echo ($txt?' - ':'').dol_htmlentitiesbr($line->description,1,true);
}
}
} else {
}
else
{
if (! empty($line->fk_parent_line)) echo img_picto('', 'rightarrow');
if ($type==1) $text = img_object($langs->trans('Service'),'service');
else $text = img_object($langs->trans('Product'),'product');
echo $text.' '.dol_htmlentitiesbr($line->description,1,true);
// Show range
print_date_range($line->date_start,$line->date_end);
} ?>
}
?>
</td>
<td align="right" nowrap="nowrap"><?php echo vatrate($line->tva_tx,'%',$line->info_bits); ?></td>

View File

@ -100,7 +100,7 @@ BillStatus=Invoice status
BillStatusDraft=Draft (needs to be validated)
BillStatusPaid=Paid
BillStatusPaidBackOrConverted=Paid or converted into discount
BillStatusConverted=Converted into discount
BillStatusConverted=Paid (ready for final invoice)
BillStatusCanceled=Abandoned
BillStatusValidated=Validated (needs to be paid)
BillStatusStarted=Started

View File

@ -208,8 +208,8 @@ CustomerRelativeDiscountShort=Relative discount
CustomerAbsoluteDiscountShort=Absolute discount
CompanyHasRelativeDiscount=This customer has a default discount of <b>%s%%</b>
CompanyHasNoRelativeDiscount=This customer has no relative discount by default
CompanyHasAbsoluteDiscount=This customer still has discount credits for <b>%s %s</b>
CompanyHasCreditNote=This customer still has credit notes or previous deposits for <b>%s %s</b>
CompanyHasAbsoluteDiscount=This customer still has discount credits or deposits for <b>%s %s</b>
CompanyHasCreditNote=This customer still has credit notes for <b>%s %s</b>
CompanyHasNoAbsoluteDiscount=This customer has no discount credit available
CustomerAbsoluteDiscountAllUsers=Absolute discounts (granted by all users)
CustomerAbsoluteDiscountMy=Absolute discounts (granted by yourself)

View File

@ -96,7 +96,7 @@ BillStatus=État de la facture
BillStatusDraft=Brouillon (à valider)
BillStatusPaid=Payée
BillStatusPaidBackOrConverted=Remboursé ou converti en réduction
BillStatusConverted=Converti en réduction
BillStatusConverted=Payée (prêt pour facture final)
BillStatusCanceled=Abandonnée
BillStatusValidated=Validée (à payer)
BillStatusStarted=Règlement commencé
@ -231,14 +231,15 @@ ReductionsShort=Réduc.
Discount=Remise
Discounts=Remises
ShowDiscount=Visualiser l'avoir
ShowReduc=Visualiser la déduction
RelativeDiscount=Remise relative
GlobalDiscount=Remise fixe
GlobalDiscount=Ligne de déduction
CreditNote=Avoir
CreditNotes=Avoirs
AddDiscount=Editer remises
AddRelativeDiscount=Créer remise relative
EditRelativeDiscount=Editer remise relative
AddGlobalDiscount=Créer remise fixe
AddGlobalDiscount=Créer ligne de déduction
EditGlobalDiscounts=Editer remises fixes
AddCreditNote=Créer facture avoir
Deposit=Acompte
@ -247,7 +248,7 @@ DiscountFromCreditNote=Remise issue de l'avoir %s
DiscountFromDeposit=Paiements issue de l'acompte %s
AbsoluteDiscountUse=Ce type de crédit ne peut s'utiliser que sur une facture non validée
CreditNoteDepositUse=La facture doit être validée pour pouvoir utiliser ce type de crédit
NewGlobalDiscount=Nouvelle remise fixe
NewGlobalDiscount=Nouvelle ligne de déduction
NewRelativeDiscount=Nouvelle remise relative
NoteReason=Note/Motif
ReasonDiscount=Motif
@ -344,6 +345,7 @@ LawApplicationPart2=les marchandises demeurent la propriété du
LawApplicationPart3=vendeur jusqu'à complet encaissement de
LawApplicationPart4=leurs prix.
LimitedLiabilityCompanyCapital=SARL au Capital de
UseLine=Appliquer
UseDiscount=Appliquer remise
UseCredit=Utiliser crédit
UseCreditNoteInInvoicePayment=Réduire le montant du reste à payer avec ce crédit

View File

@ -210,8 +210,8 @@ CustomerRelativeDiscountShort=Remise relative
CustomerAbsoluteDiscountShort=Remise fixe
CompanyHasRelativeDiscount=Ce client a une remise par défaut de <b>%s%%</b>
CompanyHasNoRelativeDiscount=Ce client n'a pas de remise relative par défaut
CompanyHasAbsoluteDiscount=Ce client a <b>%s %s</b> de remises fixes disponibles
CompanyHasCreditNote=Ce client a <b>%s %s</b> d'avoirs/acomptes disponibles
CompanyHasAbsoluteDiscount=Ce client a <b>%s %s</b> de lignes de déduction disponibles (remises, acomptes...)
CompanyHasCreditNote=Ce client a <b>%s %s</b> d'avoirs disponibles
CompanyHasNoAbsoluteDiscount=Ce client n'a pas ou plus de remise fixe disponible
CustomerAbsoluteDiscountAllUsers=Remises fixes en cours (accordées par tout utilisateur)
CustomerAbsoluteDiscountMy=Remises fixes en cours (accordées personnellement)