From c63eeb2cbd53b8cf5a1e8f3b5d17323b84d346db Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 3 Apr 2007 01:20:19 +0000 Subject: [PATCH] =?UTF-8?q?Fix:=20Ajout=20d'une=20remise=20absolue=20non?= =?UTF-8?q?=20issue=20d'un=20avoir=20doit=20se=20soustraire=20=E0=20la=20f?= =?UTF-8?q?acture.=20Fix:=20Les=20modeles=20crabe=20et=20azur=20g=E8re=20l?= =?UTF-8?q?es=20avoirs.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- htdocs/comm/propal.php | 122 +----------------- htdocs/compta/facture.php | 7 +- htdocs/discount.class.php | 23 ++-- htdocs/facture.class.php | 6 +- .../modules/facture/pdf_crabe.modules.php | 19 ++- .../propale/pdf_propale_azur.modules.php | 15 ++- htdocs/langs/en_US/bills.lang | 3 + htdocs/langs/fr_FR/bills.lang | 1 + htdocs/propal.class.php | 13 +- 9 files changed, 65 insertions(+), 144 deletions(-) diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index 45988e1a2d4..41e1eb5ffdb 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -1144,8 +1144,10 @@ if ($_GET['propalid'] > 0) { if ($objp->description == '(CREDIT_NOTE)') { - print ' - '.$langs->trans("CreditNote"); - // \TODO Mettre ici lien sur ref avoir + $discount=new DiscountAbsolute($db); + $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 { @@ -1319,122 +1321,6 @@ if ($_GET['propalid'] > 0) 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 '
'; - print ''; - print ''; - print ''; - print $langs->trans('CustomerRelativeDiscount'); - if ($propal->brouillon) print ' ('.($soc->remise_client?$langs->trans("CompanyHasRelativeDiscount",$soc->remise_client):$langs->trans("CompanyHasNoRelativeDiscount")).')'; - print ''; - print ' '; - print ' '; - print ' '; - print ''; - if ($_GET['action'] == 'editrelativediscount') - { - print '%'; - } - else - { - print $propal->remise_percent?$propal->remise_percent.'%':' '; - } - print ''; - print ''; - if ($_GET['action'] != 'editrelativediscount') print $propal->remise_percent?'-'.price($propal->remise_percent*$total/100):$langs->trans("DiscountNone"); - else print ' '; - print ''; - if ($_GET['action'] != 'editrelativediscount') - { - if ($propal->brouillon && $user->rights->propale->creer) - { - print 'id.'">'.img_edit($langs->trans('SetRelativeDiscount'),1).''; - } - else - { - print ' '; - } - if ($propal->brouillon && $user->rights->propale->creer && $propal->remise_percent) - { - print 'rowid.'">'; - print img_delete(); - print ''; - } - else - { - print ' '; - } - print ' '; - } - else - { - print ''; - } - print ''; - print '
'; - */ - - // Réductions absolues (Remises-Ristournes-Rabbais) - /* Les remises absolues doivent s'appliquer par ajout de lignes spécialisées - $var=!$var; - print '
'; - print ''; - print ''; - print ''; - print $langs->trans('CustomerAbsoluteDiscount'); - if ($propal->brouillon) print ' ('.($avoir_en_cours?$langs->trans("CompanyHasAbsoluteDiscount",$avoir_en_cours,$langs->trans("Currency".$conf->monnaie)):$langs->trans("CompanyHasNoAbsoluteDiscount")).')'; - print ''; - print ' '; - print ' '; - print ' '; - print ' '; - print ''; - if ($_GET['action'] == 'editabsolutediscount') - { - print '-'; - } - else - { - print $propal->remise_absolue?'-'.price($propal->remise_absolue):$langs->trans("DiscountNone"); - } - print ''; - if ($_GET['action'] != 'editabsolutediscount') - { - if ($propal->brouillon && $user->rights->propale->creer) - { - print 'id.'">'.img_edit($langs->trans('SetAbsoluteDiscount'),1).''; - } - else - { - print ' '; - } - if ($propal->brouillon && $user->rights->propale->creer && $propal->remise_absolue) - { - print 'rowid.'">'; - print img_delete(); - print ''; - } - else - { - print ' '; - } - print ' '; - } - else - { - print ''; - } - print ''; - print '
'; - */ - /* * Ajouter une ligne */ diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 2393884c04d..62c8ddb2043 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -2197,6 +2197,7 @@ else * Lignes de factures */ $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.= ' '.$db->pdate('l.date_start').' as date_start,'; $sql.= ' '.$db->pdate('l.date_end').' as date_end,'; @@ -2274,8 +2275,10 @@ else { if ($objp->description == '(CREDIT_NOTE)') { - print ' - '.$langs->trans("CreditNote"); - // \TODO Mettre ici lien sur ref avoir + $discount=new DiscountAbsolute($db); + $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 { diff --git a/htdocs/discount.class.php b/htdocs/discount.class.php index 4b8a429bdd9..544e3de0600 100644 --- a/htdocs/discount.class.php +++ b/htdocs/discount.class.php @@ -47,8 +47,8 @@ class DiscountAbsolute var $description; // Description libre var $datec; // Date creation 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 @@ -67,13 +67,15 @@ class DiscountAbsolute */ function fetch($rowid) { - $sql = "SELECT fk_soc,"; - $sql.= " fk_user,"; - $sql.= " amount_ht, amount_tva, amount_ttc, tva_tx,"; - $sql.= " fk_facture, fk_facture_source, description,"; - $sql.= " ".$this->db->pdate("datec")." as datec"; - $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except"; - $sql.= " WHERE rowid=".$rowid; + $sql = "SELECT sr.fk_soc,"; + $sql.= " sr.fk_user,"; + $sql.= " sr.amount_ht, sr.amount_tva, sr.amount_ttc, sr.tva_tx,"; + $sql.= " sr.fk_facture, sr.fk_facture_source, sr.description,"; + $sql.= " ".$this->db->pdate("sr.datec")." as datec,"; + $sql.= " f.facnumber as ref_facture_source"; + $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); $resql = $this->db->query($sql); @@ -91,7 +93,8 @@ class DiscountAbsolute $this->tva_tx = $obj->tva_tx; $this->fk_user = $obj->fk_user; $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->datec = $obj->datec; diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php index 1bdd77cfc69..4226c058d81 100644 --- a/htdocs/facture.class.php +++ b/htdocs/facture.class.php @@ -612,9 +612,9 @@ class Facture extends CommonObject $facligne->price=-$remise->amount_ht; $facligne->remise=0; - $facligne->total_ht = $remise->amount_ht; - $facligne->total_tva = $remise->amount_tva; - $facligne->total_ttc = $remise->amount_ttc; + $facligne->total_ht = -$remise->amount_ht; + $facligne->total_tva = -$remise->amount_tva; + $facligne->total_ttc = -$remise->amount_ttc; $lineid=$facligne->insert(); if ($lineid > 0) diff --git a/htdocs/includes/modules/facture/pdf_crabe.modules.php b/htdocs/includes/modules/facture/pdf_crabe.modules.php index 3bc815c1742..1d0e3a8730e 100644 --- a/htdocs/includes/modules/facture/pdf_crabe.modules.php +++ b/htdocs/includes/modules/facture/pdf_crabe.modules.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2004-2007 Laurent Destailleur * * 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 @@ -74,6 +74,7 @@ class pdf_crabe extends ModelePDFFactures $this->option_codeproduitservice = 1; // Affiche code produit-service $this->option_multilang = 1; // Dispo en plusieurs langues $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') $this->franchise=1; @@ -216,12 +217,22 @@ class pdf_crabe extends ModelePDFFactures $curY = $nexY; // 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 ($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 if ($fac->lignes[$i]->produit_id) { diff --git a/htdocs/includes/modules/propale/pdf_propale_azur.modules.php b/htdocs/includes/modules/propale/pdf_propale_azur.modules.php index 52bd90b46e0..4fbe8c4d0b7 100644 --- a/htdocs/includes/modules/propale/pdf_propale_azur.modules.php +++ b/htdocs/includes/modules/propale/pdf_propale_azur.modules.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2004-2007 Laurent Destailleur * * 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 @@ -73,6 +73,7 @@ class pdf_propale_azur extends ModelePDFPropales $this->option_condreg = 1; // Affiche conditions règlement $this->option_codeproduitservice = 1; // Affiche code produit-service $this->option_multilang = 1; // Dispo en plusieurs langues + $this->option_credit_note = 1; // Gère les avoirs if (defined("FACTURE_TVAOPTION") && FACTURE_TVAOPTION == 'franchise') $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 ($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 if ($propale->lignes[$i]->fk_product) diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index 4ca2e1538cb..0e0cce687a2 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -137,6 +137,8 @@ ConfirmClassifyPayedPartiallyReasonAvoirDesc=Use this choice if all other does n ConfirmClassifyPayedPartiallyReasonBadCustomerDesc=A bad customers 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 ConfirmClassifyPayedPartiallyReasonOtherDesc=Use this choice if all other does not suit, for example in following situation:
- payment not complete because some products were shipped back
- amount claimed too important because a discount was forgotten
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 %s %s ? ValidateBill=Validate invoice NumberOfBills=Nb of invoices @@ -198,6 +200,7 @@ RelativeDiscount=Relative discount GlobalDiscount=Global discount CreditNote=Credit note CreditNotes=Credit notes +DiscountFromCreditNote=Discount from credit note %s NewGlobalDiscount=New discount NoteReason=Note/Reason ReasonDiscount=Reason diff --git a/htdocs/langs/fr_FR/bills.lang b/htdocs/langs/fr_FR/bills.lang index 9ed4608d9db..7cd4364c94a 100644 --- a/htdocs/langs/fr_FR/bills.lang +++ b/htdocs/langs/fr_FR/bills.lang @@ -200,6 +200,7 @@ RelativeDiscount=Remise relative GlobalDiscount=Remise fixe CreditNote=Avoir CreditNotes=Avoirs +DiscountFromCreditNote=Remise issue de l'avoir %s NewGlobalDiscount=Nouvelle remise fixe NoteReason=Note/Motif ReasonDiscount=Motif diff --git a/htdocs/propal.class.php b/htdocs/propal.class.php index ca2e9e9c817..c0819b587a3 100644 --- a/htdocs/propal.class.php +++ b/htdocs/propal.class.php @@ -219,9 +219,9 @@ class Propal extends CommonObject $propalligne->rang=-1; $propalligne->info_bits=2; - $propalligne->total_ht = $remise->amount_ht; - $propalligne->total_tva = $remise->amount_tva; - $propalligne->total_ttc = $remise->amount_ttc; + $propalligne->total_ht = -$remise->amount_ht; + $propalligne->total_tva = -$remise->amount_tva; + $propalligne->total_ttc = -$remise->amount_ttc; $result=$propalligne->insert(); if ($result > 0) @@ -860,7 +860,7 @@ class Propal extends CommonObject /* * 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.= " p.ref, p.label, p.description as product_desc"; $sql.= " FROM ".MAIN_DB_PREFIX."propaldet as d"; @@ -884,7 +884,8 @@ class Propal extends CommonObject $ligne->qty = $objp->qty; $ligne->tva_tx = $objp->tva_tx; $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->info_bits = $objp->info_bits; @@ -2051,6 +2052,8 @@ class PropaleLigne var $tva_tx; var $subprice; var $remise_percent; + var $fk_remise_except; + var $rang = 0; var $coef; var $info_bits = 0; // Bit 0: 0 si TVA normal - 1 si TVA NPR