Fix: Quand on supprime reduc de type avoir, le statut de l'avoir redevient non honor (pay = 0 et statut = 1)
This commit is contained in:
parent
3698e0dc95
commit
bc6754033c
@ -19,7 +19,6 @@
|
||||
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
||||
*
|
||||
* $Id$
|
||||
* $Source$
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
@ -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='<div class="error">'.$langs->trans("ErrorFieldRequired",$langs->trans("ReasonDiscount")).'</div>';
|
||||
}
|
||||
|
||||
$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='<div class="error">'.$soc->error.'</div>';
|
||||
}
|
||||
}
|
||||
|
||||
@ -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='<div class="error">'.$discount->error.'</div>';
|
||||
}
|
||||
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
if ($_POST['action'] == 'classin')
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
/* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* Copyright (C) 2004 Éric Seigne <eric.seigne@ryxeo.com>
|
||||
* Copyright (C) 2004-2005 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
|
||||
* 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$
|
||||
*/
|
||||
|
||||
/**
|
||||
|
||||
@ -171,7 +171,7 @@ if ($id > 0)
|
||||
print '<table class="border" width="100%">';
|
||||
|
||||
// Reference du facture
|
||||
print '<tr><td width="25%">'.$langs->trans("Ref").'</td><td colspan="3">';
|
||||
print '<tr><td width="20%">'.$langs->trans("Ref").'</td><td colspan="3">';
|
||||
print $facture->ref;
|
||||
print "</td></tr>";
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<?php
|
||||
/* Copyright (C) 2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
|
||||
* 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
|
||||
* 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 '<table class="border" width="100%">';
|
||||
|
||||
// Reference
|
||||
print '<tr><td width="25%">'.$langs->trans('Ref').'</td><td colspan="3">'.$fac->ref.'</td></tr>';
|
||||
print '<tr><td width="20%">'.$langs->trans('Ref').'</td><td colspan="3">'.$fac->ref.'</td></tr>';
|
||||
|
||||
// Société
|
||||
print '<tr><td>'.$langs->trans("Company").'</td>';
|
||||
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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 ?<br>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 ?<br>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
|
||||
|
||||
@ -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 ?<br>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 ?<br>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
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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);
|
||||
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user