';
+ }
$i++;
}
$db->free($resql);
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 010d8aad094..f68a4c13bd4 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -428,8 +428,8 @@ if ($_REQUEST['action'] == 'confirm_converttoreduc' && $_REQUEST['confirm'] == '
// Insert one discount by VAT rate category
$discount = new DiscountAbsolute($db);
- if ($fac->type == 2) $discount->desc='(CREDIT_NOTE)';
- elseif ($fac->type == 3) $discount->desc='(DEPOSIT)';
+ if ($fac->type == 2) $discount->description='(CREDIT_NOTE)';
+ elseif ($fac->type == 3) $discount->description='(DEPOSIT)';
else {
$this->error="CantConvertToReducAnInvoiceOfThisType";
return -1;
@@ -2285,8 +2285,17 @@ else
}
else
{
- $text=$langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->monnaie));
- print $html->textwithpicto($text,$langs->trans("AbsoluteDiscountUse"));
+ if ($fac->statut < 1 || $fac->type == 2 || $fac->type == 3)
+ {
+ $text=$langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->monnaie));
+ print ' '.$text.'. ';
+ }
+ else
+ {
+ $text=$langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->transnoentities("Currency".$conf->monnaie));
+ $text2=$langs->trans("AbsoluteDiscountUse");
+ print $html->textwithpicto($text,$text2);
+ }
}
}
else
diff --git a/htdocs/discount.class.php b/htdocs/discount.class.php
index d01fdfd4dff..d606fb08024 100644
--- a/htdocs/discount.class.php
+++ b/htdocs/discount.class.php
@@ -1,6 +1,6 @@
- * Copyright (C) 2004-2007 Laurent Destailleur
+ * Copyright (C) 2004-2009 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
@@ -44,8 +44,8 @@ class DiscountAbsolute
var $datec; // Date creation
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
+ var $fk_facture_source; // Id facture avoir a l'origine de la remise
+ var $ref_facture_source; // Ref facture avoir a l'origine de la remise
/**
* \brief Constructeur de la classe
@@ -58,10 +58,10 @@ class DiscountAbsolute
/**
- * \brief Charge objet remise depuis la base
- * \param rowid id du projet � charger
+ * \brief Load object from database into memory
+ * \param rowid id discount to load
* \param fk_facture_source fk_facture_source
- * \return int <0 si ko, =0 si non trouv�, >0 si ok
+ * \return int <0 if KO, =0 if not found, >0 if OK
*/
function fetch($rowid,$fk_facture_source=0)
{
@@ -76,7 +76,7 @@ class DiscountAbsolute
$sql.= " sr.fk_user,";
$sql.= " sr.amount_ht, sr.amount_tva, sr.amount_ttc, sr.tva_tx,";
$sql.= " sr.fk_facture_line, sr.fk_facture, sr.fk_facture_source, sr.description,";
- $sql.= " ".$this->db->pdate("sr.datec")." as datec,";
+ $sql.= " sr.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";
@@ -104,7 +104,7 @@ class DiscountAbsolute
$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;
+ $this->datec = $this->db->jdate($obj->datec);
$this->db->free($resql);
return 1;
@@ -132,19 +132,27 @@ class DiscountAbsolute
{
global $conf, $langs;
- // Nettoyage parametres
+ // Clean parameters
$this->amount_ht=price2num($this->amount_ht);
$this->amount_tva=price2num($this->amount_tva);
$this->amount_ttc=price2num($this->amount_ttc);
$this->tva_tx=price2num($this->tva_tx);
+ // Check parameters
+ if (empty($this->description))
+ {
+ $this->error='BadValueForPropertyDescription';
+ dol_syslog("DiscountAbsolute::create ".$this->error, LOG_ERR);
+ return -1;
+ }
+
// Insert request
$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_except";
$sql.= " (datec, fk_soc, fk_user, description,";
$sql.= " amount_ht, amount_tva, amount_ttc, tva_tx,";
$sql.= " fk_facture_source";
$sql.= ")";
- $sql.= " VALUES (".$this->db->idate(mktime()).", ".$this->fk_soc.", ".$user->id.", '".addslashes($this->desc)."',";
+ $sql.= " VALUES (".$this->db->idate($this->datec!=''?$this->datec:dol_now('tzserver')).", ".$this->fk_soc.", ".$user->id.", '".addslashes($this->description)."',";
$sql.= " ".$this->amount_ht.", ".$this->amount_tva.", ".$this->amount_ttc.", ".$this->tva_tx.",";
$sql.= " ".($this->fk_facture_source?"'".$this->fk_facture_source."'":"null");
$sql.= ")";
@@ -166,23 +174,56 @@ class DiscountAbsolute
/*
- * \brief Delete object in database
+ * \brief Delete object in database. If fk_facture_source is defined, we delete all familiy with same fk_facture_source. If not, only with id is removed.
+ * \param user Object of user asking to delete
* \return int <0 if KO, >0 if OK
*/
- function delete()
+ function delete($user)
{
global $conf, $langs;
+ // Check if we can remove the discount
+ if ($this->fk_facture_source)
+ {
+ $sql.="SELECT COUNT(rowid) as nb";
+ $sql.=" FROM ".MAIN_DB_PREFIX."societe_remise_except";
+ $sql.=" WHERE (fk_facture_line IS NOT NULL"; // Not used as absolute simple discount
+ $sql.=" OR fk_facture IS NOT NULL)"; // Not used as credit note and not used as deposit
+ $sql.=" AND fk_facture_source = ".$this->fk_facture_source;
+ //$sql.=" AND rowid != ".$this->id;
+
+ dol_syslog("DiscountAbsolute::delete Check if we can remove discount sql=".$sql);
+ $resql=$this->db->query($sql);
+ if ($resql)
+ {
+ $obj = $this->db->fetch_object($resql);
+ if ($obj->nb > 0)
+ {
+ $this->error='ErrorThisPartOrAnotherIsAlreadyUsedSoDiscountSerieCantBeRemoved';
+ return -2;
+ }
+ }
+ else
+ {
+ dol_print_error($db);
+ return -1;
+ }
+ }
+
$this->db->begin();
+ // Delete but only if not used
$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_remise_except ";
- $sql.= " WHERE rowid = ".$this->id." AND (fk_facture_line IS NULL or fk_facture IS NULL)";
+ if ($this->fk_facture_source) $sql.= " WHERE fk_facture_source = ".$this->fk_facture_source; // Delete all lines of same serie
+ else $sql.= " WHERE rowid = ".$this->id; // Delete only line
+ $sql.= " AND (fk_facture_line IS NULL"; // Not used as absolute simple discount
+ $sql.= " AND fk_facture IS NULL)"; // Not used as credit note and not used as deposit
dol_syslog("DiscountAbsolute::delete Delete discount sql=".$sql);
$result=$this->db->query($sql);
if ($result)
{
- // If source of discount was a credit not, we change credit note statut.
+ // If source of discount was a credit note or deposit, we change source statut.
if ($this->fk_facture_source)
{
$sql = "UPDATE ".MAIN_DB_PREFIX."facture";
@@ -191,7 +232,7 @@ class DiscountAbsolute
dol_syslog("DiscountAbsolute::delete Update credit note or deposit invoice statut sql=".$sql);
$result=$this->db->query($sql);
- if ($result)
+ if ($result)
{
$this->db->commit();
return 1;
@@ -288,7 +329,7 @@ class DiscountAbsolute
/**
- * \brief Renvoie montant TTC des reductions/avoirs en cours disponibles
+ * \brief Renvoie montant TTC des reductions/avoirs en cours disponibles pour une société, un user ou autre
* \param company Object third party for filter
* \param user Filtre sur un user auteur des remises
* \param filter Filtre autre
diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php
index 3bc2e0b6385..5178e3a5fe0 100644
--- a/htdocs/html.form.class.php
+++ b/htdocs/html.form.class.php
@@ -2623,13 +2623,13 @@ class Form
$resultyesno = ''."\n";
return $resultyesno;
diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang
index b2876c8faaa..de0d47793f0 100644
--- a/htdocs/langs/en_US/bills.lang
+++ b/htdocs/langs/en_US/bills.lang
@@ -241,7 +241,8 @@ DiscountFromCreditNote=Discount from credit note %s
DiscountFromDeposit=Payments from deposit invoice %s
AbsoluteDiscountUse=This kind of credit can be used on invoice before its validation
CreditNoteDepositUse=Invoice must be validated to use this king of credits
-NewGlobalDiscount=New discount
+NewGlobalDiscount=New fix discount
+NewRelativeDiscount=New relative discount
NoteReason=Note/Reason
ReasonDiscount=Reason
AddGlobalDiscount=Add discount
@@ -268,6 +269,11 @@ ConfirmCloneInvoice=Are you sure you want to clone this invoice %s ?
DisabledBecauseReplacedInvoice=Action disabled because invoice has been replaced
DescTaxAndDividendsArea=This area presents a summary of all payments made for tax or social contributions. Only records with payment during the fixed year are included here.
NbOfPayments=Nb of payments
+SplitDiscount=Split discount in two
+ConfirmSplitDiscount=Are you sure you want to split this discount of %s %s into 2 lower discounts ?
+TypeAmountOfEachNewDiscount=Input amount for each of two parts :
+TotalOfTwoDiscountMustEqualsOriginal=Total of two new discount must be equal to original discount amount.
+ConfirmRemoveDiscount=Are you sure you want to remove this discount ?
# PaymentConditions
PaymentConditionShortRECEP=Immediate
diff --git a/htdocs/langs/fr_FR/bills.lang b/htdocs/langs/fr_FR/bills.lang
index 99792e8aa20..12bec3b336e 100644
--- a/htdocs/langs/fr_FR/bills.lang
+++ b/htdocs/langs/fr_FR/bills.lang
@@ -241,6 +241,7 @@ 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édits
NewGlobalDiscount=Nouvelle remise fixe
+NewRelativeDiscount=Nouvelle remise relative
NoteReason=Note/Motif
ReasonDiscount=Motif
AddGlobalDiscount=Ajouter remise fixe
@@ -268,6 +269,11 @@ ConfirmCloneInvoice=Etes-vous sur de vouloir cloner cette facture %s ?
DisabledBecauseReplacedInvoice=Action désactivée car facture remplacée
DescTaxAndDividendsArea=Cet écran résumé la liste de toutes les taxes et charges sociales sociales exigées pour une année donnée. La date prise en compte est la période d'exigibilité.
NbOfPayments=Nb de payements
+SplitDiscount=Scinder réduction en deux
+ConfirmSplitDiscount=Etes-vous sur de vouloir scinder la réduction de %s %s en 2 réductions plus petites ?
+TypeAmountOfEachNewDiscount=Saisissez le montant de chacune des deux parts :
+TotalOfTwoDiscountMustEqualsOriginal=La somme du montant des 2 nouvelles réductions doit être équivalent au montant de la réduction à scinder.
+ConfirmRemoveDiscount=Etes-vous sur de vouloir supprimer cette réduction ?
# PaymentConditions
PaymentConditionShortRECEP=A réception
diff --git a/htdocs/lib/functions.lib.php b/htdocs/lib/functions.lib.php
index 0d11ca143f6..84c502023d0 100644
--- a/htdocs/lib/functions.lib.php
+++ b/htdocs/lib/functions.lib.php
@@ -2367,8 +2367,8 @@ function get_default_npr($societe_vendeuse, $societe_acheteuse, $taux_produit)
/**
- * \brief Renvoie oui ou non dans la langue choisie
- * \param yesno Variable pour test si oui ou non
+ * \brief Return yes or no in current language
+ * \param yesno Value to test (1, 'yes', 'true' or 0, 'no', 'false')
* \param case 1=Yes/No, 0=yes/no
* \param color 0=texte only, 1=Text is formated with a color font style ('ok' or 'error'), 2=Text is formated with 'ok' color.
*/
@@ -2640,7 +2640,7 @@ function dol_nboflines($s,$maxchar=0)
*/
function dol_nboflines_bis($texte,$maxlinesize=0,$charset='UTF-8')
{
- //print $texte;
+ //print $texte;
$repTable = array("\t" => " ", "\n" => " ", "\r" => " ", "\0" => " ", "\x0B" => " ");
$texte = strtr($texte, $repTable);
if ($charset == 'UTF-8') { $pattern = '/(<[^>]+>)/Uu'; } // /U is to have UNGREEDY regex to limit to one html tag. /u is for UTF8 support
diff --git a/htdocs/societe.class.php b/htdocs/societe.class.php
index 3e2f622082e..295212191f4 100644
--- a/htdocs/societe.class.php
+++ b/htdocs/societe.class.php
@@ -1048,7 +1048,7 @@ class Societe extends CommonObject
}
/**
- * \brief Ajoute une remise fixe pour la societe
+ * \brief Add a discount for third party
* \param remise Montant de la remise
* \param user Utilisateur qui accorde la remise
* \param desc Motif de l'avoir
@@ -1084,7 +1084,7 @@ class Societe extends CommonObject
$discount->amount_tva=price2num($remise*$tva_tx/100,'MT');
$discount->amount_ttc=price2num($discount->amount_ht+$discount->amount_tva,'MT');
$discount->tva_tx=price2num($tva_tx,'MT');
- $discount->desc=$desc;
+ $discount->description=$desc;
$result=$discount->create($user);
if ($result > 0)
{
@@ -1099,26 +1099,6 @@ class Societe extends CommonObject
else return 0;
}
- /**
- * \brief Supprime un avoir (a condition que non affecte a une facture)
- * \param id Id de l'avoir a supprimer
- * \return int <0 si ko, id de l'avoir si ok
- */
- function del_remise_except($id)
- {
- if ($this->id)
- {
- require_once(DOL_DOCUMENT_ROOT.'/discount.class.php');
-
- $discount = new DiscountAbsolute($this->db);
- $result=$discount->fetch($id);
- $result=$discount->delete();
- return $result;
- }
- else return 0;
- }
-
-
/**
* \brief Renvoie montant TTC des reductions/avoirs en cours disponibles de la societe
* \param user Filtre sur un user auteur des remises
diff --git a/htdocs/theme/auguria/img/split.png b/htdocs/theme/auguria/img/split.png
new file mode 100644
index 00000000000..008557d7341
Binary files /dev/null and b/htdocs/theme/auguria/img/split.png differ
diff --git a/htdocs/theme/bluelagoon/img/split.png b/htdocs/theme/bluelagoon/img/split.png
new file mode 100644
index 00000000000..008557d7341
Binary files /dev/null and b/htdocs/theme/bluelagoon/img/split.png differ
diff --git a/htdocs/theme/eldy/img/split.png b/htdocs/theme/eldy/img/split.png
new file mode 100644
index 00000000000..008557d7341
Binary files /dev/null and b/htdocs/theme/eldy/img/split.png differ
diff --git a/htdocs/theme/freelug/img/split.png b/htdocs/theme/freelug/img/split.png
new file mode 100644
index 00000000000..008557d7341
Binary files /dev/null and b/htdocs/theme/freelug/img/split.png differ
diff --git a/htdocs/theme/rodolphe/img/split.png b/htdocs/theme/rodolphe/img/split.png
new file mode 100644
index 00000000000..008557d7341
Binary files /dev/null and b/htdocs/theme/rodolphe/img/split.png differ
diff --git a/htdocs/theme/yellow/img/split.png b/htdocs/theme/yellow/img/split.png
new file mode 100644
index 00000000000..008557d7341
Binary files /dev/null and b/htdocs/theme/yellow/img/split.png differ
diff --git a/htdocs/translate.class.php b/htdocs/translate.class.php
index 189d193bf67..1e4cac11a90 100644
--- a/htdocs/translate.class.php
+++ b/htdocs/translate.class.php
@@ -333,6 +333,30 @@ class Translate {
}
+ function getTradFromKey($key)
+ {
+ global $db;
+ $newstr=$key;
+ if (eregi('CurrencyShort([A-Z]+)$',$key,$reg))
+ {
+ global $db;
+ //$newstr=$this->getLabelFromKey($db,$reg[1],'c_currencies','code_iso','labelshort');
+ $newstr=$this->getLabelFromKey($db,$reg[1],'c_currencies','code_iso','code');
+ }
+ else if (eregi('Currency([A-Z]+)$',$key,$reg))
+ {
+ global $db;
+ $newstr=$this->getLabelFromKey($db,$reg[1],'c_currencies','code_iso','label');
+ }
+ else if (eregi('SendingMethod([0-9A-Z]+)$',$key,$reg))
+ {
+ global $db;
+ $newstr=$this->getLabelFromKey($db,$reg[1],'expedition_methode','code','libelle');
+ }
+ return $newstr;
+ }
+
+
/**
* \brief Retourne la version traduite du texte passe en parametre en la codant en HTML
* Si il n'y a pas de correspondance pour ce texte, on cherche dans fichier alternatif
@@ -372,23 +396,7 @@ class Translate {
}
else // Translation is not available
{
- $newstr=$key;
- if (eregi('CurrencyShort([A-Z]+)$',$key,$reg))
- {
- global $db;
- //$newstr=$this->getLabelFromKey($db,$reg[1],'c_currencies','code_iso','labelshort');
- $newstr=$this->getLabelFromKey($db,$reg[1],'c_currencies','code_iso','code');
- }
- else if (eregi('Currency([A-Z]+)$',$key,$reg))
- {
- global $db;
- $newstr=$this->getLabelFromKey($db,$reg[1],'c_currencies','code_iso','label');
- }
- else if (eregi('SendingMethod([0-9A-Z]+)$',$key,$reg))
- {
- global $db;
- $newstr=$this->getLabelFromKey($db,$reg[1],'expedition_methode','code','libelle');
- }
+ $newstr=$this->getTradFromKey($key);
return $this->convToOutputCharset($newstr);
}
}
@@ -408,11 +416,14 @@ class Translate {
*/
function transnoentities($key, $param1='', $param2='', $param3='', $param4='')
{
- $newstr=$key;
- if ($this->getTransFromTab($newstr))
+ if ($this->getTransFromTab($key))
{
// Si la traduction est disponible
- $newstr=sprintf($this->tab_translate[$newstr],$param1,$param2,$param3,$param4);
+ $newstr=sprintf($this->tab_translate[$key],$param1,$param2,$param3,$param4);
+ }
+ else
+ {
+ $newstr=$this->getTradFromKey($key);
}
return $this->convToOutputCharset($newstr);
}
@@ -433,11 +444,14 @@ class Translate {
*/
function transnoentitiesnoconv($key, $param1='', $param2='', $param3='', $param4='')
{
- $newstr=$key;
- if ($this->getTransFromTab($newstr))
+ if ($this->getTransFromTab($key))
{
// Si la traduction est disponible
- $newstr=sprintf($this->tab_translate[$newstr],$param1,$param2,$param3,$param4);
+ $newstr=sprintf($this->tab_translate[$key],$param1,$param2,$param3,$param4);
+ }
+ else
+ {
+ $newstr=$this->getTradFromKey($key);
}
return $newstr;
}