diff --git a/htdocs/admin/facture.php b/htdocs/admin/facture.php
index 488be9ec78a..2bc054eb3bb 100644
--- a/htdocs/admin/facture.php
+++ b/htdocs/admin/facture.php
@@ -19,7 +19,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
- * $Source$
*/
/**
diff --git a/htdocs/comm/remx.php b/htdocs/comm/remx.php
index 1b0a67a2b2a..68282d15a7c 100644
--- a/htdocs/comm/remx.php
+++ b/htdocs/comm/remx.php
@@ -17,7 +17,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
- * $Source$
*/
/**
@@ -60,7 +59,7 @@ if ($_POST["action"] == 'setremise')
$mesg='
'.$langs->trans("ErrorFieldRequired",$langs->trans("ReasonDiscount")).'
';
}
- $soc = New Societe($db);
+ $soc = new Societe($db);
$soc->fetch($_GET["id"]);
$soc->set_remise_except($_POST["amount_ht"],$user,$_POST["desc"],$_POST["tva_tx"]);
@@ -82,17 +81,19 @@ if ($_POST["action"] == 'setremise')
if ($_GET["action"] == 'remove')
{
- $soc = New Societe($db);
+ $db->begin();
+
+ $soc = new Societe($db);
$soc->fetch($_GET["id"]);
$result=$soc->del_remise_except($_GET["remid"]);
if ($result > 0)
{
- Header("Location: remx.php?id=".$_GET["id"]);
- exit;
+ $db->commit();
}
else
{
+ $db->rollback();
$mesg=''.$soc->error.'
';
}
}
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index bd88847cd73..872c21debe4 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -188,7 +188,8 @@ if ($_REQUEST['action'] == 'setremisepercent' && $user->rights->facture->creer)
if ($_POST['action'] == "setabsolutediscount" && $user->rights->facture->creer)
{
- if ($_POST["remise_id"])
+ // POST[remise_id] ou POST[remise_id_for_payment]
+ if (! empty($_POST["remise_id"]))
{
$fac = new Facture($db);
$fac->id=$_GET['facid'];
@@ -206,6 +207,20 @@ if ($_POST['action'] == "setabsolutediscount" && $user->rights->facture->creer)
dolibarr_print_error($db,$fac->error);
}
}
+ if (! empty($_POST["remise_id_for_payment"]))
+ {
+ require_once(DOL_DOCUMENT_ROOT.'/discount.class.php');
+ $discount = new DiscountAbsolute($db);
+ $discount->fetch($_POST["remise_id_for_payment"]);
+
+ $result=$discount->link_to_invoice(0,$fac->rowid);
+ if ($result < 0)
+ {
+ $mesg=''.$discount->error.'
';
+ }
+
+ exit;
+ }
}
if ($_POST['action'] == 'classin')
diff --git a/htdocs/compta/facture/apercu.php b/htdocs/compta/facture/apercu.php
index 3b902aada6a..163ebfd3c03 100644
--- a/htdocs/compta/facture/apercu.php
+++ b/htdocs/compta/facture/apercu.php
@@ -1,7 +1,7 @@
* Copyright (C) 2004 Éric Seigne
- * Copyright (C) 2004-2005 Laurent Destailleur
+ * 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
@@ -18,7 +18,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
- * $Source$
*/
/**
diff --git a/htdocs/compta/facture/contact.php b/htdocs/compta/facture/contact.php
index d11475fa55d..76f1528ddba 100644
--- a/htdocs/compta/facture/contact.php
+++ b/htdocs/compta/facture/contact.php
@@ -171,7 +171,7 @@ if ($id > 0)
print '';
// Reference du facture
- print '| '.$langs->trans("Ref").' | ';
+ print ' |
| '.$langs->trans("Ref").' | ';
print $facture->ref;
print " |
";
diff --git a/htdocs/compta/facture/note.php b/htdocs/compta/facture/note.php
index d907583af42..1abc9bd1d14 100644
--- a/htdocs/compta/facture/note.php
+++ b/htdocs/compta/facture/note.php
@@ -1,6 +1,6 @@
- * Copyright (C) 2004-2006 Laurent Destailleur
+ * 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
@@ -17,7 +17,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
- * $Source$
*/
/**
@@ -113,7 +112,7 @@ if ($_GET["facid"])
print '';
// Reference
- print '| '.$langs->trans('Ref').' | '.$fac->ref.' |
';
+ print '| '.$langs->trans('Ref').' | '.$fac->ref.' |
';
// Société
print '| '.$langs->trans("Company").' | ';
diff --git a/htdocs/discount.class.php b/htdocs/discount.class.php
index 9ffe5404234..08b5cdab613 100644
--- a/htdocs/discount.class.php
+++ b/htdocs/discount.class.php
@@ -17,7 +17,6 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
* $Id$
- * $Source$
*/
/**
@@ -46,7 +45,8 @@ class DiscountAbsolute
var $fk_user; // Id utilisateur qui accorde la remise
var $description; // Description libre
var $datec; // Date creation
- var $fk_facture; // Id facture qd une remise a été utilisé
+ var $fk_facture_line; // Id invoice line when a discount linked to invoice line
+ var $fk_facture; // Id invoice when a discoutn linked to invoice
var $fk_facture_source; // Id facture avoir à l'origine de la remise
var $ref_facture_source; // Ref facture avoir à l'origine de la remise
@@ -78,7 +78,7 @@ class DiscountAbsolute
$sql = "SELECT sr.rowid, 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.= " sr.fk_facture_line, 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";
@@ -102,6 +102,7 @@ class DiscountAbsolute
$this->amount_ttc = $obj->amount_ttc;
$this->tva_tx = $obj->tva_tx;
$this->fk_user = $obj->fk_user;
+ $this->fk_facture_line = $obj->fk_facture_line;
$this->fk_facture = $obj->fk_facture;
$this->fk_facture_source = $obj->fk_facture_source; // Id avoir source
$this->ref_facture_source = $obj->ref_facture_source; // Ref avoir source
@@ -167,7 +168,7 @@ class DiscountAbsolute
}
- /*
+ /*
* \brief Delete object in database
* \return int <0 if KO, >0 if OK
*/
@@ -175,18 +176,47 @@ class DiscountAbsolute
{
global $conf, $langs;
+ $this->db->begin();
+
$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_remise_except ";
- $sql.= " WHERE rowid = ".$this->id." AND fk_facture IS NULL";
+ $sql.= " WHERE rowid = ".$this->id." AND (fk_facture_line IS NULL or fk_facture IS NULL)";
- dolibarr_syslog("DiscountAbsolute::delete sql=".$sql);
- if (! $this->db->query($sql))
+ dolibarr_syslog("DiscountAbsolute::delete Delete discount sql=".$sql);
+ $result=$this->db->query($sql);
+ if ($result)
{
- $this->error=$this->db->lasterror().' sql='.$sql;
- return -1;
+ // If source of discount was a credit not, we change credit note statut.
+ if ($this->fk_facture_source)
+ {
+ $sql = "UPDATE ".MAIN_DB_PREFIX."facture";
+ $sql.=" set paye=0, fk_statut=1";
+ $sql.=" WHERE type = 2 AND rowid=".$this->fk_facture_source;
+
+ dolibarr_syslog("DiscountAbsolute::delete Update credit note statut sql=".$sql);
+ $result=$this->db->query($sql);
+ if ($result)
+ {
+ $this->db->commit();
+ return 1;
+ }
+ else
+ {
+ $this->error=$this->db->lasterror();
+ $this->db->rollback();
+ return -1;
+ }
+ }
+ else
+ {
+ $this->db->commit();
+ return 1;
+ }
}
else
{
- return 1;
+ $this->error=$this->db->lasterror();
+ $this->db->rollback();
+ return -1;
}
}
@@ -194,16 +224,32 @@ class DiscountAbsolute
/**
* \brief Link the discount to a particular invoice line
- * \param rowid Invoice line id
- * \return int <0 ko, >0 ok
+ * \param rowidline Invoice line id
+ * \param rowidinvoice Invoice id
+ * \return int <0 ko, >0 ok
*/
- function link_to_invoice($rowid)
+ function link_to_invoice($rowidline,$rowidinvoice)
{
- dolibarr_syslog("DiscountAbsolute::link_to_invoice link discount ".$this->id." to invoice line rowid=".$rowid);
+ dolibarr_syslog("DiscountAbsolute::link_to_invoice Link discount ".$this->id." to invoice line rowid=".$rowidline." or invoice rowid=".$rowidinvoice);
+ // Check parameters
+ if (! $rowidline && ! $rowidinvoice)
+ {
+ $this->error='ErrorBadParameters';
+ return -1;
+ }
+ if ($rowidline && $rowidinvoice)
+ {
+ $this->error='ErrorBadParameters';
+ return -2;
+ }
+
$sql ="UPDATE ".MAIN_DB_PREFIX."societe_remise_except";
- $sql.=" SET fk_facture = ".$rowid;
+ if ($rowidline) $sql.=" SET fk_facture_line = ".$rowidline;
+ if ($rowidinvoice) $sql.=" SET fk_facture = ".$rowidinvoice;
$sql.=" WHERE rowid = ".$this->id;
+
+ dolibarr_syslog("DiscountAbsolute::link_to_invoice sql=".$sql);
$resql = $this->db->query($sql);
if ($resql)
{
@@ -212,8 +258,8 @@ class DiscountAbsolute
else
{
$this->error=$this->db->error();
- dolibarr_syslog("DiscountAbsolute::link_to_invoice ".$this->error." sql=".$sql);
- return -1;
+ dolibarr_syslog("DiscountAbsolute::link_to_invoice ".$this->error);
+ return -3;
}
}
diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php
index 3403ff0970b..e391f2bda33 100644
--- a/htdocs/facture.class.php
+++ b/htdocs/facture.class.php
@@ -646,7 +646,7 @@ class Facture extends CommonObject
if ($result > 0)
{
// Crée lien entre remise et ligne de facture
- $result=$remise->link_to_invoice($lineid);
+ $result=$remise->link_to_invoice($lineid,0);
if ($result < 0)
{
$this->error=$remise->error;
@@ -2991,8 +2991,14 @@ class FactureLigne
}
else
{
- $discount->link_to_invoice($this->rowid);
-
+ $result=$discount->link_to_invoice($this->rowid,0);
+ if ($result < 0)
+ {
+ $this->error=$discount->error;
+ dolibarr_syslog("FactureLigne::insert Error ".$this->error);
+ $this->db->rollback();
+ return -3;
+ }
}
}
else
diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang
index 4f443a2dc96..557713e909e 100644
--- a/htdocs/langs/en_US/bills.lang
+++ b/htdocs/langs/en_US/bills.lang
@@ -47,7 +47,7 @@ PaymentsBack=Payments back
DatePayment=Payment date
DeletePayment=Delete payment
ConfirmDeletePayment=Are you sure you want to delete this payment ?
-ConfirmConvertToReduc=Do you want to convert this credit note into absolute discount ?
The amount of this credit note will so be saved among all discounts and could be used as a discount for a future invoice for this customer.
+ConfirmConvertToReduc=Do you want to convert this credit note into absolute discount ?
The amount of this credit note will so be saved among all discounts and could be used as a discount for a current or a future invoice for this customer.
ReceivedPayments=Received payments
ReceivedCustomersPayments=Payments received from customers
ReceivedCustomersPaymentsToValid=Received customers payments to validate
@@ -231,6 +231,7 @@ InvoiceStatus=Invoice status
InvoiceNote=Invoice note
InvoicePayed=Invoice payed
PaymentNumber=Payment number
+RemoveDiscount=Remove discount
# PaymentConditions
PaymentConditionShortRECEP=Immediate
@@ -291,7 +292,7 @@ LawApplicationPart4=their price.
VATDischarged=VAT paid on debits.
LimitedLiabilityCompanyCapital=SARL with Capital of
UseDiscount=Use discount
-UseCreditNoteInInvoicePayment=Include credit note as payment
+UseCreditNoteInInvoicePayment=Reduce payment with this credit note
MenuChequeDeposits=Cheques deposits
MenuCheques=Cheques
MenuChequesReceipts=Cheques receipts
diff --git a/htdocs/langs/fr_FR/bills.lang b/htdocs/langs/fr_FR/bills.lang
index 21ca1e40352..fd43c586f93 100644
--- a/htdocs/langs/fr_FR/bills.lang
+++ b/htdocs/langs/fr_FR/bills.lang
@@ -46,7 +46,7 @@ PaymentsBack=Remboursements
DatePayment=Date paiement
DeletePayment=Supprimer le paiement
ConfirmDeletePayment=Etes vous sur de vouloir supprimer ce paiement ?
-ConfirmConvertToReduc=Voulez-vous convertir cet avoir en réduction future ?
Le montant de cet avoir sera alors stocké en réduction fixe en attente pour le client. Cette dernière pourra être utilisée pour réduire le montant d'une prochaine facture de ce client.
+ConfirmConvertToReduc=Voulez-vous convertir cet avoir en réduction future ?
Le montant de cet avoir sera alors stocké en réduction fixe en attente pour le client. Cette dernière pourra être utilisée pour réduire le montant d'une facture en cours ou prochaine de ce client.
ReceivedPayments=Réglements reçus
ReceivedCustomersPayments=Réglements reçus du client
ReceivedCustomersPaymentsToValid=Réglements clients reçus à valider
@@ -230,6 +230,7 @@ InvoiceStatus=Statut facture
InvoiceNote=Note facture
InvoicePayed=Facture payée
PaymentNumber=Numéro paiement
+RemoveDiscount=Supprimer remise
# PaymentConditions
PaymentConditionShortRECEP=A réception
@@ -290,7 +291,7 @@ LawApplicationPart4=leurs prix.
VATDischarged=TVA acquittée sur les débits.
LimitedLiabilityCompanyCapital=SARL au Capital de
UseDiscount=Appliquer remise
-UseCreditNoteInInvoicePayment=Appliquer avoir en tant que paiement
+UseCreditNoteInInvoicePayment=Réduire paiement avec cet avoir
MenuChequeDeposits=Remises de chèques
MenuCheques=Gestion chèques
MenuChequesReceipts=Bordereaux
diff --git a/mysql/migration/2.1.0-2.2.0.sql b/mysql/migration/2.1.0-2.2.0.sql
index 4bfafc4f829..16fc951e830 100644
--- a/mysql/migration/2.1.0-2.2.0.sql
+++ b/mysql/migration/2.1.0-2.2.0.sql
@@ -1124,3 +1124,22 @@ insert into llx_c_pays (rowid,code,libelle) values (246, 'MF', 'Saint-Martin' )
ALTER TABLE llx_boxes ADD UNIQUE INDEX uk_boxes (box_id, position, fk_user);
+-- Drop constraints to allow rename
+ALTER TABLE llx_societe_remise_except drop foreign key fk_societe_remise_fk_facture;
+ALTER TABLE llx_societe_remise_except drop index idx_societe_remise_except_fk_facture;
+
+-- Rename field
+ALTER TABLE llx_societe_remise_except change fk_facture fk_facture_line integer;
+ALTER TABLE llx_societe_remise_except add fk_facture integer after fk_facture_line;
+
+-- Create constraints
+ALTER TABLE llx_societe_remise_except ADD INDEX idx_societe_remise_except_fk_facture_line (fk_facture_line);
+ALTER TABLE llx_societe_remise_except ADD INDEX idx_societe_remise_except_fk_facture (fk_facture);
+ALTER TABLE llx_societe_remise_except ADD CONSTRAINT fk_societe_remise_fk_facture_line FOREIGN KEY (fk_facture_line) REFERENCES llx_facturedet (rowid);
+ALTER TABLE llx_societe_remise_except ADD CONSTRAINT fk_societe_remise_fk_facture FOREIGN KEY (fk_facture) REFERENCES llx_facture (rowid);
+
+-- Corrige statut avoir transforme en reduc ou reduc supprime apres coup
+-- V4.1 update llx_facture set paye=0, fk_statut=1 where paye=1 and type=2 and rowid not in (select fk_facture_source from llx_societe_remise_except);
+
+-- Corrige avoirs affectes en ligne a affectation sur facture
+-- V4.1 update llx_societe_remise_except as r set fk_facture_line = NULL, fk_facture = (select fk_facture from llx_facturedet where rowid = r.fk_facture_line)
diff --git a/mysql/tables/llx_societe_remise_except.key.sql b/mysql/tables/llx_societe_remise_except.key.sql
index c6b6107bebd..d78357289d5 100644
--- a/mysql/tables/llx_societe_remise_except.key.sql
+++ b/mysql/tables/llx_societe_remise_except.key.sql
@@ -26,13 +26,15 @@
ALTER TABLE llx_societe_remise_except ADD INDEX idx_societe_remise_except_fk_user (fk_user);
ALTER TABLE llx_societe_remise_except ADD INDEX idx_societe_remise_except_fk_soc (fk_soc);
+ALTER TABLE llx_societe_remise_except ADD INDEX idx_societe_remise_except_fk_facture_line (fk_facture_line);
ALTER TABLE llx_societe_remise_except ADD INDEX idx_societe_remise_except_fk_facture (fk_facture);
ALTER TABLE llx_societe_remise_except ADD INDEX idx_societe_remise_except_fk_facture_source (fk_facture_source);
ALTER TABLE llx_societe_remise_except ADD CONSTRAINT fk_societe_remise_fk_user FOREIGN KEY (fk_user) REFERENCES llx_user (rowid);
ALTER TABLE llx_societe_remise_except ADD CONSTRAINT fk_societe_remise_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe (rowid);
-ALTER TABLE llx_societe_remise_except ADD CONSTRAINT fk_societe_remise_fk_facture FOREIGN KEY (fk_facture) REFERENCES llx_facturedet (rowid);
+ALTER TABLE llx_societe_remise_except ADD CONSTRAINT fk_societe_remise_fk_facture_line FOREIGN KEY (fk_facture_line) REFERENCES llx_facturedet (rowid);
+ALTER TABLE llx_societe_remise_except ADD CONSTRAINT fk_societe_remise_fk_facture FOREIGN KEY (fk_facture) REFERENCES llx_facture (rowid);
ALTER TABLE llx_societe_remise_except ADD CONSTRAINT fk_societe_remise_fk_facture_source FOREIGN KEY (fk_facture_source) REFERENCES llx_facture (rowid);
diff --git a/mysql/tables/llx_societe_remise_except.sql b/mysql/tables/llx_societe_remise_except.sql
index 41604bcfe3e..0aa9f7b7050 100644
--- a/mysql/tables/llx_societe_remise_except.sql
+++ b/mysql/tables/llx_societe_remise_except.sql
@@ -17,7 +17,6 @@
-- Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
--
-- $Id$
--- $Source$
--
-- Remises exceptionnelles
-- ============================================================================
@@ -32,6 +31,7 @@ create table llx_societe_remise_except
amount_ttc double(24,8) DEFAULT 0 NOT NULL,
tva_tx double(6,3) DEFAULT 0 NOT NULL,
fk_user integer NOT NULL,
+ fk_facture_line integer,
fk_facture integer,
fk_facture_source integer,
description varchar(255) NOT NULL