Fix: Ajout d'une remise absolue non issue d'un avoir doit se soustraire à la facture.

Fix: Les modeles crabe et azur gère les avoirs.
This commit is contained in:
Laurent Destailleur 2007-04-03 01:20:19 +00:00
parent f265a205be
commit c63eeb2cbd
9 changed files with 65 additions and 144 deletions

View File

@ -1144,8 +1144,10 @@ if ($_GET['propalid'] > 0)
{ {
if ($objp->description == '(CREDIT_NOTE)') if ($objp->description == '(CREDIT_NOTE)')
{ {
print ' - '.$langs->trans("CreditNote"); $discount=new DiscountAbsolute($db);
// \TODO Mettre ici lien sur ref avoir $discount->fetch($objp->fk_remise_except);
print ' - '.$langs->trans("DiscountFromCreditNote",$discount->ref_facture_source);
// \TODO Mettre ici lien sur ref avoir en ajoutant fonction getNomUrl sur classe DiscountAbsolute
} }
else else
{ {
@ -1319,122 +1321,6 @@ if ($_GET['propalid'] > 0)
dolibarr_print_error($db); dolibarr_print_error($db);
} }
/*
* Lignes de remise
*/
// Réductions relatives (Remises-Ristournes-Rabbais)
/* Une réduction doit s'appliquer obligatoirement sur des lignes de factures
$var=!$var;
print '<form name="updateligne" action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="action" value="setremisepercent">';
print '<input type="hidden" name="propalid" value="'.$propal->id.'">';
print '<tr class="liste_total"><td>';
print $langs->trans('CustomerRelativeDiscount');
if ($propal->brouillon) print ' <font style="font-weight: normal">('.($soc->remise_client?$langs->trans("CompanyHasRelativeDiscount",$soc->remise_client):$langs->trans("CompanyHasNoRelativeDiscount")).')</font>';
print '</td>';
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
print '<td align="right"><font style="font-weight: normal">';
if ($_GET['action'] == 'editrelativediscount')
{
print '<input type="text" name="remise_percent" size="1" value="'.$propal->remise_percent.'">%';
}
else
{
print $propal->remise_percent?$propal->remise_percent.'%':'&nbsp;';
}
print '</font></td>';
print '<td align="right"><font style="font-weight: normal">';
if ($_GET['action'] != 'editrelativediscount') print $propal->remise_percent?'-'.price($propal->remise_percent*$total/100):$langs->trans("DiscountNone");
else print '&nbsp;';
print '</font></td>';
if ($_GET['action'] != 'editrelativediscount')
{
if ($propal->brouillon && $user->rights->propale->creer)
{
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editrelativediscount&amp;propalid='.$propal->id.'">'.img_edit($langs->trans('SetRelativeDiscount'),1).'</a></td>';
}
else
{
print '<td>&nbsp;</td>';
}
if ($propal->brouillon && $user->rights->propale->creer && $propal->remise_percent)
{
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?propalid='.$propal->id.'&amp;action=setremisepercent&amp;rowid='.$objp->rowid.'">';
print img_delete();
print '</a></td>';
}
else
{
print '<td>&nbsp;</td>';
}
print '<td>&nbsp;</td>';
}
else
{
print '<td colspan="3"><input type="submit" class="button" value="'.$langs->trans("Save").'"></td>';
}
print '</tr>';
print '</form>';
*/
// Réductions absolues (Remises-Ristournes-Rabbais)
/* Les remises absolues doivent s'appliquer par ajout de lignes spécialisées
$var=!$var;
print '<form name="updateligne" action="'.$_SERVER["PHP_SELF"].'" method="post">';
print '<input type="hidden" name="action" value="setremiseabsolue">';
print '<input type="hidden" name="propalid" value="'.$propal->id.'">';
print '<tr class="liste_total"><td>';
print $langs->trans('CustomerAbsoluteDiscount');
if ($propal->brouillon) print ' <font style="font-weight: normal">('.($avoir_en_cours?$langs->trans("CompanyHasAbsoluteDiscount",$avoir_en_cours,$langs->trans("Currency".$conf->monnaie)):$langs->trans("CompanyHasNoAbsoluteDiscount")).')</font>';
print '</td>';
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
print '<td>&nbsp;</td>';
print '<td align="right"><font style="font-weight: normal">';
if ($_GET['action'] == 'editabsolutediscount')
{
print '-<input type="text" name="remise_absolue" size="2" value="'.$propal->remise_absolue.'">';
}
else
{
print $propal->remise_absolue?'-'.price($propal->remise_absolue):$langs->trans("DiscountNone");
}
print '</font></td>';
if ($_GET['action'] != 'editabsolutediscount')
{
if ($propal->brouillon && $user->rights->propale->creer)
{
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?action=editabsolutediscount&amp;propalid='.$propal->id.'">'.img_edit($langs->trans('SetAbsoluteDiscount'),1).'</a></td>';
}
else
{
print '<td>&nbsp;</td>';
}
if ($propal->brouillon && $user->rights->propale->creer && $propal->remise_absolue)
{
print '<td align="right"><a href="'.$_SERVER["PHP_SELF"].'?propalid='.$propal->id.'&amp;action=setremiseabsolue&amp;rowid='.$objp->rowid.'">';
print img_delete();
print '</a></td>';
}
else
{
print '<td>&nbsp;</td>';
}
print '<td>&nbsp;</td>';
}
else
{
print '<td colspan="3"><input type="submit" class="button" value="'.$langs->trans("Save").'"></td>';
}
print '</tr>';
print '</form>';
*/
/* /*
* Ajouter une ligne * Ajouter une ligne
*/ */

View File

@ -2197,6 +2197,7 @@ else
* Lignes de factures * Lignes de factures
*/ */
$sql = 'SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_taux,'; $sql = 'SELECT l.fk_product, l.description, l.price, l.qty, l.rowid, l.tva_taux,';
$sql.= ' l.fk_remise_except,';
$sql.= ' l.remise_percent, l.subprice, l.info_bits,'; $sql.= ' l.remise_percent, l.subprice, l.info_bits,';
$sql.= ' '.$db->pdate('l.date_start').' as date_start,'; $sql.= ' '.$db->pdate('l.date_start').' as date_start,';
$sql.= ' '.$db->pdate('l.date_end').' as date_end,'; $sql.= ' '.$db->pdate('l.date_end').' as date_end,';
@ -2274,8 +2275,10 @@ else
{ {
if ($objp->description == '(CREDIT_NOTE)') if ($objp->description == '(CREDIT_NOTE)')
{ {
print ' - '.$langs->trans("CreditNote"); $discount=new DiscountAbsolute($db);
// \TODO Mettre ici lien sur ref avoir $discount->fetch($objp->fk_remise_except);
print ' - '.$langs->trans("DiscountFromCreditNote",$discount->ref_facture_source);
// \TODO Mettre ici lien sur ref avoir en ajoutant fonction getNomUrl sur classe DiscountAbsolute
} }
else else
{ {

View File

@ -47,8 +47,8 @@ class DiscountAbsolute
var $description; // Description libre var $description; // Description libre
var $datec; // Date creation var $datec; // Date creation
var $fk_facture; // Id facture qd une remise a été utilisé var $fk_facture; // Id facture qd une remise a été utilisé
var $fk_facture_source; // Id facture avoir a l'origine de la remise var $fk_facture_source; // Id facture avoir à l'origine de la remise
var $ref_facture_source; // Ref facture avoir à l'origine de la remise
/** /**
* \brief Constructeur de la classe * \brief Constructeur de la classe
@ -67,13 +67,15 @@ class DiscountAbsolute
*/ */
function fetch($rowid) function fetch($rowid)
{ {
$sql = "SELECT fk_soc,"; $sql = "SELECT sr.fk_soc,";
$sql.= " fk_user,"; $sql.= " sr.fk_user,";
$sql.= " amount_ht, amount_tva, amount_ttc, tva_tx,"; $sql.= " sr.amount_ht, sr.amount_tva, sr.amount_ttc, sr.tva_tx,";
$sql.= " fk_facture, fk_facture_source, description,"; $sql.= " sr.fk_facture, sr.fk_facture_source, sr.description,";
$sql.= " ".$this->db->pdate("datec")." as datec"; $sql.= " ".$this->db->pdate("sr.datec")." as datec,";
$sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except"; $sql.= " f.facnumber as ref_facture_source";
$sql.= " WHERE rowid=".$rowid; $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as sr";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON sr.fk_facture_source = f.rowid";
$sql.= " WHERE sr.rowid=".$rowid;
dolibarr_syslog("DiscountAbsolute::fetch sql=".$sql); dolibarr_syslog("DiscountAbsolute::fetch sql=".$sql);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);
@ -91,7 +93,8 @@ class DiscountAbsolute
$this->tva_tx = $obj->tva_tx; $this->tva_tx = $obj->tva_tx;
$this->fk_user = $obj->fk_user; $this->fk_user = $obj->fk_user;
$this->fk_facture = $obj->fk_facture; $this->fk_facture = $obj->fk_facture;
$this->fk_facture_source = $obj->fk_facture_source; $this->fk_facture_source = $obj->fk_facture_source; // Id avoir source
$this->ref_facture_source = $obj->ref_facture_source; // Ref avoir source
$this->description = $obj->description; $this->description = $obj->description;
$this->datec = $obj->datec; $this->datec = $obj->datec;

View File

@ -612,9 +612,9 @@ class Facture extends CommonObject
$facligne->price=-$remise->amount_ht; $facligne->price=-$remise->amount_ht;
$facligne->remise=0; $facligne->remise=0;
$facligne->total_ht = $remise->amount_ht; $facligne->total_ht = -$remise->amount_ht;
$facligne->total_tva = $remise->amount_tva; $facligne->total_tva = -$remise->amount_tva;
$facligne->total_ttc = $remise->amount_ttc; $facligne->total_ttc = -$remise->amount_ttc;
$lineid=$facligne->insert(); $lineid=$facligne->insert();
if ($lineid > 0) if ($lineid > 0)

View File

@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -74,6 +74,7 @@ class pdf_crabe extends ModelePDFFactures
$this->option_codeproduitservice = 1; // Affiche code produit-service $this->option_codeproduitservice = 1; // Affiche code produit-service
$this->option_multilang = 1; // Dispo en plusieurs langues $this->option_multilang = 1; // Dispo en plusieurs langues
$this->option_escompte = 1; // Affiche si il y a eu escompte $this->option_escompte = 1; // Affiche si il y a eu escompte
$this->option_credit_note = 1; // Gère les avoirs
if (defined("FACTURE_TVAOPTION") && FACTURE_TVAOPTION == 'franchise') if (defined("FACTURE_TVAOPTION") && FACTURE_TVAOPTION == 'franchise')
$this->franchise=1; $this->franchise=1;
@ -216,12 +217,22 @@ class pdf_crabe extends ModelePDFFactures
$curY = $nexY; $curY = $nexY;
// Description de la ligne produit // Description de la ligne produit
$libelleproduitservice=_dol_htmlentities($fac->lignes[$i]->libelle,0); $libelleproduitservice=_dol_htmlentities($fac->lignes[$i]->libelle,0);
if ($fac->lignes[$i]->desc&&$fac->lignes[$i]->desc!=$fac->lignes[$i]->libelle) if ($fac->lignes[$i]->desc&&$fac->lignes[$i]->desc!=$fac->lignes[$i]->libelle)
{ {
if ($libelleproduitservice) $libelleproduitservice.="\n"; if ($libelleproduitservice) $libelleproduitservice.="\n";
$libelleproduitservice.=_dol_htmlentities($fac->lignes[$i]->desc,$conf->global->FCKEDITOR_ENABLE_DETAILS);
} if ($fac->lignes[$i]->desc == '(CREDIT_NOTE)' && $fac->lignes[$i]->fk_remise_except)
{
$discount=new DiscountAbsolute($this->db);
$discount->fetch($fac->lignes[$i]->fk_remise_except);
$libelleproduitservice=$langs->trans("DiscountFromCreditNote",$discount->ref_facture_source);
}
else
{
$libelleproduitservice.=_dol_htmlentities($fac->lignes[$i]->desc,$conf->global->FCKEDITOR_ENABLE_DETAILS);
}
}
// Si ligne associée à un code produit // Si ligne associée à un code produit
if ($fac->lignes[$i]->produit_id) if ($fac->lignes[$i]->produit_id)
{ {

View File

@ -1,5 +1,5 @@
<?php <?php
/* Copyright (C) 2004-2006 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2004-2007 Laurent Destailleur <eldy@users.sourceforge.net>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -73,6 +73,7 @@ class pdf_propale_azur extends ModelePDFPropales
$this->option_condreg = 1; // Affiche conditions règlement $this->option_condreg = 1; // Affiche conditions règlement
$this->option_codeproduitservice = 1; // Affiche code produit-service $this->option_codeproduitservice = 1; // Affiche code produit-service
$this->option_multilang = 1; // Dispo en plusieurs langues $this->option_multilang = 1; // Dispo en plusieurs langues
$this->option_credit_note = 1; // Gère les avoirs
if (defined("FACTURE_TVAOPTION") && FACTURE_TVAOPTION == 'franchise') if (defined("FACTURE_TVAOPTION") && FACTURE_TVAOPTION == 'franchise')
$this->franchise=1; $this->franchise=1;
@ -218,7 +219,17 @@ class pdf_propale_azur extends ModelePDFPropales
if ($propale->lignes[$i]->desc && $propale->lignes[$i]->desc!=$propale->lignes[$i]->libelle) if ($propale->lignes[$i]->desc && $propale->lignes[$i]->desc!=$propale->lignes[$i]->libelle)
{ {
if ($libelleproduitservice) $libelleproduitservice.="\n"; if ($libelleproduitservice) $libelleproduitservice.="\n";
$libelleproduitservice.=_dol_htmlentities($propale->lignes[$i]->desc,$conf->global->FCKEDITOR_ENABLE_DETAILS);
if ($propale->lignes[$i]->desc == '(CREDIT_NOTE)' && $propale->lignes[$i]->fk_remise_except)
{
$discount=new DiscountAbsolute($this->db);
$discount->fetch($propale->lignes[$i]->fk_remise_except);
$libelleproduitservice=$langs->trans("DiscountFromCreditNote",$discount->ref_facture_source);
}
else
{
$libelleproduitservice.=_dol_htmlentities($propale->lignes[$i]->desc,$conf->global->FCKEDITOR_ENABLE_DETAILS);
}
} }
// Si ligne associée à un code produit // Si ligne associée à un code produit
if ($propale->lignes[$i]->fk_product) if ($propale->lignes[$i]->fk_product)

View File

@ -137,6 +137,8 @@ ConfirmClassifyPayedPartiallyReasonAvoirDesc=Use this choice if all other does n
ConfirmClassifyPayedPartiallyReasonBadCustomerDesc=A <b>bad customers</b> is a customer that refuse to pay his debt. ConfirmClassifyPayedPartiallyReasonBadCustomerDesc=A <b>bad customers</b> is a customer that refuse to pay his debt.
ConfirmClassifyPayedPartiallyReasonProductReturnedDesc=This choice is used when payment is not complete because some of products were returned ConfirmClassifyPayedPartiallyReasonProductReturnedDesc=This choice is used when payment is not complete because some of products were returned
ConfirmClassifyPayedPartiallyReasonOtherDesc=Use this choice if all other does not suit, for example in following situation:<br>- payment not complete because some products were shipped back<br>- amount claimed too important because a discount was forgotten<br>In all cases, amount over-claimed must be corrected in accountancy system by creating a credit note. ConfirmClassifyPayedPartiallyReasonOtherDesc=Use this choice if all other does not suit, for example in following situation:<br>- payment not complete because some products were shipped back<br>- amount claimed too important because a discount was forgotten<br>In all cases, amount over-claimed must be corrected in accountancy system by creating a credit note.
ConfirmClassifyAbandonReasonOther=Other
ConfirmClassifyAbandonReasonOtherDesc=This choice will be used in all other cases. For example because you plan to create a replacing invoice.
ConfirmCustomerPayment=Do you confirm this paiement input for <b>%s</b> %s ? ConfirmCustomerPayment=Do you confirm this paiement input for <b>%s</b> %s ?
ValidateBill=Validate invoice ValidateBill=Validate invoice
NumberOfBills=Nb of invoices NumberOfBills=Nb of invoices
@ -198,6 +200,7 @@ RelativeDiscount=Relative discount
GlobalDiscount=Global discount GlobalDiscount=Global discount
CreditNote=Credit note CreditNote=Credit note
CreditNotes=Credit notes CreditNotes=Credit notes
DiscountFromCreditNote=Discount from credit note %s
NewGlobalDiscount=New discount NewGlobalDiscount=New discount
NoteReason=Note/Reason NoteReason=Note/Reason
ReasonDiscount=Reason ReasonDiscount=Reason

View File

@ -200,6 +200,7 @@ RelativeDiscount=Remise relative
GlobalDiscount=Remise fixe GlobalDiscount=Remise fixe
CreditNote=Avoir CreditNote=Avoir
CreditNotes=Avoirs CreditNotes=Avoirs
DiscountFromCreditNote=Remise issue de l'avoir %s
NewGlobalDiscount=Nouvelle remise fixe NewGlobalDiscount=Nouvelle remise fixe
NoteReason=Note/Motif NoteReason=Note/Motif
ReasonDiscount=Motif ReasonDiscount=Motif

View File

@ -219,9 +219,9 @@ class Propal extends CommonObject
$propalligne->rang=-1; $propalligne->rang=-1;
$propalligne->info_bits=2; $propalligne->info_bits=2;
$propalligne->total_ht = $remise->amount_ht; $propalligne->total_ht = -$remise->amount_ht;
$propalligne->total_tva = $remise->amount_tva; $propalligne->total_tva = -$remise->amount_tva;
$propalligne->total_ttc = $remise->amount_ttc; $propalligne->total_ttc = -$remise->amount_ttc;
$result=$propalligne->insert(); $result=$propalligne->insert();
if ($result > 0) if ($result > 0)
@ -860,7 +860,7 @@ class Propal extends CommonObject
/* /*
* Lignes propales liées à un produit ou non * Lignes propales liées à un produit ou non
*/ */
$sql = "SELECT d.description, d.price, d.tva_tx, d.qty, d.remise_percent, d.subprice, d.fk_product,"; $sql = "SELECT d.description, d.price, d.tva_tx, d.qty, d.fk_remise_except, d.remise_percent, d.subprice, d.fk_product,";
$sql.= " d.info_bits, d.total_ht, d.total_tva, d.total_ttc, d.coef, d.rang,"; $sql.= " d.info_bits, d.total_ht, d.total_tva, d.total_ttc, d.coef, d.rang,";
$sql.= " p.ref, p.label, p.description as product_desc"; $sql.= " p.ref, p.label, p.description as product_desc";
$sql.= " FROM ".MAIN_DB_PREFIX."propaldet as d"; $sql.= " FROM ".MAIN_DB_PREFIX."propaldet as d";
@ -884,7 +884,8 @@ class Propal extends CommonObject
$ligne->qty = $objp->qty; $ligne->qty = $objp->qty;
$ligne->tva_tx = $objp->tva_tx; $ligne->tva_tx = $objp->tva_tx;
$ligne->subprice = $objp->subprice; $ligne->subprice = $objp->subprice;
$ligne->remise_percent = $objp->remise_percent; $ligne->fk_remise_except = $objp->fk_remise_except;
$ligne->remise_percent = $objp->remise_percent;
$ligne->price = $objp->price; $ligne->price = $objp->price;
$ligne->info_bits = $objp->info_bits; $ligne->info_bits = $objp->info_bits;
@ -2051,6 +2052,8 @@ class PropaleLigne
var $tva_tx; var $tva_tx;
var $subprice; var $subprice;
var $remise_percent; var $remise_percent;
var $fk_remise_except;
var $rang = 0; var $rang = 0;
var $coef; var $coef;
var $info_bits = 0; // Bit 0: 0 si TVA normal - 1 si TVA NPR var $info_bits = 0; // Bit 0: 0 si TVA normal - 1 si TVA NPR