diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 30140897089..ab79e96522b 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -119,7 +119,11 @@ if ($_POST['action'] == "setabsolutediscount" && $user->rights->propale->creer)
$ret=$fac->fetch($_GET['facid']);
if ($ret > 0)
{
- $fac->insert_discount($_POST["remise_id"]);
+ $result=$fac->insert_discount($_POST["remise_id"]);
+ if ($result < 0)
+ {
+ $mesg='
'.$fac->error.'
';
+ }
}
else
{
@@ -236,14 +240,23 @@ if ($_POST['action'] == 'confirm_payed_partially' && $_POST['confirm'] == 'yes'
$close_note=$_POST["close_note"];
if ($close_code)
{
+/*
if ($close_code == 'other' && ! $close_note)
{
$msg=''.$langs->trans("ErrorFieldRequired",$langs->trans("Comment")).'
';
}
else
{
- $result = $fac->set_payed($user,$close_code,$close_note);
- }
+*/
+ if ($close_code == 'abandon')
+ {
+ $result = $fac->set_canceled($user,$close_code,$close_note);
+ }
+ else
+ {
+ $result = $fac->set_payed($user,$close_code,$close_note);
+ }
+// }
}
else
{
@@ -342,7 +355,8 @@ if ($_POST['action'] == 'add')
'',
'',
0,
- $prop->lignes[$i]->info_bits);
+ $prop->lignes[$i]->info_bits,
+ $prop->lignes[$i]->fk_remise_except);
}
}
else
@@ -384,7 +398,8 @@ if ($_POST['action'] == 'add')
'',
'',
0,
- $lines[$i]->info_bits);
+ $lines[$i]->info_bits,
+ $lines[$i]->fk_remise_except);
}
}
else
@@ -431,7 +446,10 @@ if ($_POST['action'] == 'add')
$lines[$i]->fk_product,
$lines[$i]->remise_percent,
$date_start,
- $date_end);
+ $date_end,
+ 0,
+ $lines[$i]->info_bits,
+ $lines[$i]->fk_remise_except);
}
}
else
@@ -1420,22 +1438,19 @@ else
if ($_GET['action'] == 'payed' && $resteapayer > 0)
{
// Crée un tableau formulaire
- // \todo Restreindre les choix en fonction d'une option globale
- $helpescompte_avoir=$langs->trans("ConfirmClassifyPayedPartiallyAvoir").'
'.$langs->trans("Note").': '.$langs->trans("HelpEscompte");
- $helpescompte_novat=$langs->trans("ConfirmClassifyPayedPartiallyNoVat").'
'.$langs->trans("Note").': '.$langs->trans("HelpEscompte");
- $helpescompte_vat =$langs->trans("ConfirmClassifyPayedPartiallyVat"). '
'.$langs->trans("Note").': '.$langs->trans("HelpEscompte");
- $reason_avoir=$html->textwithhelp($langs->transnoentities("ConfirmClassifyPayedPartiallyReasonDiscountAvoir",$resteapayer,$langs->trans("Currency".$conf->monnaie)),$helpescompte_avoir,1);
- $reason_novat=$html->textwithhelp($langs->transnoentities("ConfirmClassifyPayedPartiallyReasonDiscountNoVat",$resteapayer,$langs->trans("Currency".$conf->monnaie)),$helpescompte_novat,1);
- $reason_vat =$html->textwithhelp($langs->transnoentities("ConfirmClassifyPayedPartiallyReasonDiscountVat",$resteapayer,$langs->trans("Currency".$conf->monnaie)),$helpescompte_vat,1);
- $reason_other=$langs->trans("ConfirmClassifyPayedPartiallyReasonOther");
- $arrayreasons['discount_avoir']=$reason_avoir;
- $arrayreasons['discount_novat']=$reason_novat;
- $arrayreasons['discount_vat'] =$reason_vat;
- $arrayreasons['discount_other']=$reason_other;
+ //$helpescompte_avoir=$langs->trans("ConfirmClassifyPayedPartiallyAvoir");
+ $helpescompte_vat =$langs->trans("HelpEscompte").'
'.$langs->trans("ConfirmClassifyPayedPartiallyVat");
+ $helpescompte_abandon=$langs->trans("ConfirmClassifyPayedPartiallyAbandon");
+ //$reason_avoir =$html->textwithhelp($langs->transnoentities("ConfirmClassifyPayedPartiallyReasonAvoir",$resteapayer,$langs->trans("Currency".$conf->monnaie)),$helpescompte_avoir,1);
+ $reason_vat =$html->textwithhelp($langs->transnoentities("ConfirmClassifyPayedPartiallyReasonDiscountVat",$resteapayer,$langs->trans("Currency".$conf->monnaie)),$helpescompte_vat,1);
+ $reason_abandon=$html->textwithhelp($langs->transnoentities("ConfirmClassifyPayedPartiallyReasonAbandon",$resteapayer,$langs->trans("Currency".$conf->monnaie)),$helpescompte_abandon,1);
+ //$arrayreasons['avoir'] =$reason_avoir;
+ $arrayreasons['discount_vat']=$reason_vat;
+ $arrayreasons['abandon'] =$reason_abandon;
$formquestion=array(
'text' => $langs->trans("ConfirmClassifyPayedPartiallyQuestion"),
array('type' => 'radio', 'name' => 'close_code', 'label' => $langs->trans("Reason"), 'values' => $arrayreasons),
- array('type' => 'text', 'name' => 'close_note', 'label' => $langs->trans("Comment"), 'value' => '', 'size' => '70')
+ array('type' => 'text', 'name' => 'close_note', 'label' => $langs->trans("Comment"), 'value' => '', 'size' => '100')
);
// Paiement incomplet. On demande si motif = escompte ou autre
$html->form_confirm($_SERVER["PHP_SELF"].'?facid='.$fac->id,$langs->trans('ClassifyPayed'),$langs->trans('ConfirmClassifyPayedPartially',$fac->ref),'confirm_payed_partially',$formquestion);
diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php
index eee094e9b3c..8dc6294e5bf 100644
--- a/htdocs/facture.class.php
+++ b/htdocs/facture.class.php
@@ -717,7 +717,6 @@ class Facture extends CommonObject
* \brief Tag la facture comme payée complètement + appel trigger BILL_PAYED
* \param user Objet utilisateur qui modifie
* \param close_code Code renseigné si on classe à payée alors que paiement incomplet
- * Les valeurs possibles sont: escompte, other
* \param close_note Commentaire renseigné si on classe à payée alors que paiement incomplet
* \return int <0 si ok, >0 si ok
*/
@@ -788,15 +787,20 @@ class Facture extends CommonObject
/**
* \brief Tag la facture comme abandonnée + appel trigger BILL_CANCEL
* \param user Objet utilisateur qui modifie
+ * \param close_code Code renseigné si on classe à payée alors que paiement incomplet
+ * \param close_note Commentaire renseigné si on classe à payée alors que paiement incomplet
* \return int <0 si ok, >0 si ok
*/
- function set_canceled($user)
+ function set_canceled($user,$close_code='',$close_note='')
{
global $conf,$langs;
dolibarr_syslog("Facture.class.php::set_canceled rowid=".$this->id);
- $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture';
- $sql.= ' SET fk_statut=3 WHERE rowid = '.$this->id;
+ $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture SET';
+ $sql.= ' fk_statut=3';
+ if ($close_code) $sql.= ", close_code='".addslashes($close_code)."'";
+ if ($close_note) $sql.= ", close_note='".addslashes($close_note)."'";
+ $sql.= ' WHERE rowid = '.$this->id;
$resql = $this->db->query($sql);
if ($resql)
@@ -898,11 +902,11 @@ class Facture extends CommonObject
/*
- * Tope les lignes de remises fixes avec id des lignes de facture au montant négatif
+ * Tope les lignes de remises fixes avec id des lignes de facture de remise
*/
foreach($this->lignes as $i => $line)
{
- if (($this->lignes[$i]->info_bits & 2) == 2)
+ if (($this->lignes[$i]->info_bits & 2) == 2 && $this->lignes[$i]->fk_remise_except)
{
// Ligne de remise
dolibarr_syslog("Facture.class::set_valid: recherche si remise ".$this->lignes[$i]->fk_remise_except." toujours dispo");
@@ -1102,7 +1106,7 @@ class Facture extends CommonObject
* par l'appelant par la methode get_default_tva(societe_vendeuse,societe_acheteuse,taux_produit)
* et le desc doit deja avoir la bonne valeur (a l'appelant de gerer le multilangue)
*/
- function addline($facid, $desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='')
+ function addline($facid, $desc, $pu, $qty, $txtva, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $fk_remise_except='')
{
global $conf;
dolibarr_syslog("facture.class.php::addline($facid,$desc,$pu,$qty,$txtva,$fk_product,$remise_percent,$date_start,$date_end,$ventil,$info_bits)");
@@ -1157,6 +1161,7 @@ class Facture extends CommonObject
$ligne->ventil=$ventil;
$ligne->rang=-1;
$ligne->info_bits=$info_bits;
+ $ligne->fk_remise_except=$fk_remise_except;
$ligne->total_ht=$total_ht;
$ligne->total_tva=$total_tva;
$ligne->total_ttc=$total_ttc;
diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang
index a50c0b784e7..2789463247a 100644
--- a/htdocs/langs/en_US/bills.lang
+++ b/htdocs/langs/en_US/bills.lang
@@ -87,8 +87,14 @@ ConfirmClassifyPayedBill=Are you sure you want to change invoice %s to st
ConfirmCancelBill=Are you sure you want to cancel invoice %s ?
ConfirmClassifyPayedPartially=Are you sure you want to change invoice %s to status payed ?
ConfirmClassifyPayedPartiallyQuestion=This invoice has not been payed completely. What are reasons for you to close this invoice ?
-ConfirmClassifyPayedPartiallyReasonEscompte=Remainder to pay (%s %s) is a discount granted because payment was made before term
-ConfirmClassifyPayedPartiallyReasonOther=Other
+ConfirmClassifyPayedPartiallyReasonAvoir=Remainder to pay (%s %s) is a discount granted because payment was made before term. Je régularise la TVA par un avoir.
+ConfirmClassifyPayedPartiallyReasonDiscountNoVat=Remainder to pay (%s %s) is a discount granted because payment was made before term. J'accepte de perdre la TVA sur cet escompte.
+ConfirmClassifyPayedPartiallyReasonDiscountVat=Remainder to pay (%s %s) is a discount granted because payment was made before term. Je récupère la TVA sur cet escompte sans avoir.
+ConfirmClassifyPayedPartiallyReasonAbandon=Debit irremediably not recoverable (bad customer...)
+ConfirmClassifyPayedPartiallyNoVat=Ce choix est possible si votre facture était munie de la mention adéquate. (Exemple: « escompte net de taxe »)
+ConfirmClassifyPayedPartiallyVat=Ce choix est possible si votre facture était munie de la mention adéquate. (Exemple: «seule la taxe correspondant au prix effectivement payé ouvre droit à déduction»)
+ConfirmClassifyPayedPartiallyAvoir=Ce choix est le choix à prendre si les autres ne sont pas applicables
+ConfirmClassifyPayedPartiallyAbandon=Ce choix sera celui dans le cas d'un mauvais payeur sans aucun espoir de recouvrement
ValidateBill=Validate invoice
NumberOfBills=Nb of invoices
NumberOfBillsByMonth=Nb of invoices by month
diff --git a/htdocs/langs/fr_FR/bills.lang b/htdocs/langs/fr_FR/bills.lang
index 93eb3674578..67eb3aa5532 100644
--- a/htdocs/langs/fr_FR/bills.lang
+++ b/htdocs/langs/fr_FR/bills.lang
@@ -87,13 +87,14 @@ ConfirmClassifyPayedBill=
ConfirmCancelBill=Êtes-vous sûr de vouloir annuler la facture %s ?
ConfirmClassifyPayedPartially=Êtes-vous sûr de vouloir classer la facture %s comme payée ?
ConfirmClassifyPayedPartiallyQuestion=Cette facture n'a pas été payée à hauteur du montant initial. Pour quelle raison voulez-vous la classer magré tout ?
-ConfirmClassifyPayedPartiallyReasonDiscountNoVat=Le reste à payer (%s %s) est un escompte accordé après facture. J'accepte de perdre la TVA sur cet escompte.
-ConfirmClassifyPayedPartiallyReasonDiscountVat=Le reste à payer (%s %s) est un escompte accordé après facture. Je récupère la TVA sur cet escompte sans avoir.
-ConfirmClassifyPayedPartiallyReasonDiscountAvoir=Le reste à payer (%s %s) est un escompte accordé après facture. Je régularise la TVA par un avoir.
-ConfirmClassifyPayedPartiallyReasonOther=Autre
-ConfirmClassifyPayedPartiallyNoVat=Ce choix est possible si votre facture était munie de la mention adéquate. (Exemple: « escompte net de taxe »)
-ConfirmClassifyPayedPartiallyVat=Ce choix est possible si votre facture était munie de la mention adéquate. (Exemple: «seule la taxe correspondant au prix effectivement payé ouvre droit à déduction»)
+ConfirmClassifyPayedPartiallyReasonAvoir=Le reste à payer (%s %s) est un trop facturé (car article retourné, oubli, escompte non défini...) régularisé par un avoir
+ConfirmClassifyPayedPartiallyReasonDiscountNoVat=Le rest à payer (%s %s) est un escompte accordé après facture. J'accepte de perdre la TVA sur cet escompte
+ConfirmClassifyPayedPartiallyReasonDiscountVat=Le reste à payer (%s %s) est un escompte
+ConfirmClassifyPayedPartiallyReasonAbandon=Créance définitivement abandonnée (client irrécouvrable...)
ConfirmClassifyPayedPartiallyAvoir=Ce choix est le choix à prendre si les autres ne sont pas applicables
+ConfirmClassifyPayedPartiallyNoVat=Ce choix est possible si votre facture était munie de la mention adéquate. (Exemple: «escompte net de taxe»)
+ConfirmClassifyPayedPartiallyVat=Ce choix est possible si votre facture était munie de la mention adéquate. (Exemple: mention définissant l'escompte ou du genre «seule la taxe correspondant au prix effectivement payé ouvre droit à déduction»)
+ConfirmClassifyPayedPartiallyAbandon=Ce choix sera celui dans le cas d'un mauvais payeur sans aucun espoir de recouvrement
ValidateBill=Valider facture
NumberOfBills=Nb de factures
NumberOfBillsByMonth=Nb de factures par mois
diff --git a/mysql/migration/2.0.0-2.1.0.sql b/mysql/migration/2.0.0-2.1.0.sql
index 39900f3199c..0aa7f3bea02 100644
--- a/mysql/migration/2.0.0-2.1.0.sql
+++ b/mysql/migration/2.0.0-2.1.0.sql
@@ -118,6 +118,8 @@ ALTER TABLE llx_facturedet ADD COLUMN total_tva real AFTER total_ht;
ALTER TABLE llx_facturedet ADD COLUMN total_ttc real AFTER total_tva;
ALTER TABLE llx_facturedet ADD COLUMN info_bits integer DEFAULT 0 AFTER date_end;
+UPDATE llx_facturedet SET info_bits=0 where (fk_remise_except IS NULL OR fk_remise_except = 0);
+
ALTER TABLE llx_propaldet ADD COLUMN total_ht real AFTER price;
ALTER TABLE llx_propaldet ADD COLUMN total_tva real AFTER total_ht;
ALTER TABLE llx_propaldet ADD COLUMN total_ttc real AFTER total_tva;