diff --git a/htdocs/commande/commande.class.php b/htdocs/commande/commande.class.php
index d4897ff72d9..3ea883f802b 100644
--- a/htdocs/commande/commande.class.php
+++ b/htdocs/commande/commande.class.php
@@ -838,23 +838,6 @@ class Commande extends CommonObject
}
}
- if ($this->user_author_id)
- {
- $sql = "SELECT name, firstname";
- $sql.= " FROM ".MAIN_DB_PREFIX."user";
- $sql.= " WHERE rowid = ".$this->user_author_id;
-
- $resqluser = $this->db->query($sql);
-
- if ($resqluser)
- {
- $obju = $this->db->fetch_object($resqluser);
- $this->user_author_name = $obju->name;
- $this->user_author_firstname = $obju->firstname;
- }
- }
-
-
$this->lignes = $this->fetch_lignes();
/*
diff --git a/htdocs/commande/fiche.php b/htdocs/commande/fiche.php
index 308a69de2de..2a4c96ae76f 100644
--- a/htdocs/commande/fiche.php
+++ b/htdocs/commande/fiche.php
@@ -949,7 +949,7 @@ else
$author->fetch();
$head = commande_prepare_head($commande);
- dolibarr_fiche_head($head, 'order', $langs->trans("CustomerOrder"));
+ dolibarr_fiche_head($head, 'order', $langs->trans("CustomerOrder"));
/*
* Confirmation de la suppression de la commande
diff --git a/htdocs/compta/commande/fiche.php b/htdocs/compta/commande/fiche.php
index 927569739d9..8c43ba831f8 100644
--- a/htdocs/compta/commande/fiche.php
+++ b/htdocs/compta/commande/fiche.php
@@ -81,6 +81,7 @@ if ($_GET["id"] > 0)
{
$soc = new Societe($db);
$soc->fetch($commande->socidp);
+
$author = new User($db);
$author->id = $commande->user_author_id;
$author->fetch();
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index ce1fa1e4996..ac3a46d6e8c 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -224,6 +224,28 @@ if ($_POST['action'] == 'confirm_payed' && $_POST['confirm'] == 'yes' && $user->
$fac->fetch($_GET['facid']);
$result = $fac->set_payed($user);
}
+if ($_POST['action'] == 'confirm_payed_partially' && $_POST['confirm'] == 'yes' && $user->rights->facture->paiement)
+{
+ $fac = new Facture($db);
+ $fac->fetch($_GET['facid']);
+ $close_code=$_POST["close_code"];
+ $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);
+ }
+ }
+ else
+ {
+ $msg=''.$langs->trans("ErrorFieldRequired",$langs->trans("Reason")).'
';
+ }
+}
/*
* Insertion facture
@@ -284,7 +306,7 @@ if ($_POST['action'] == 'add')
else
{
$_GET["action"]='create';
- $mesg=''.$facture->error.'
';
+ $msg=''.$facture->error.'
';
}
}
else
@@ -582,7 +604,7 @@ if ($_POST['action'] == 'confirm_canceled' && $_POST['confirm'] == 'yes')
if ($user->rights->facture->supprimer)
{
$fac = new Facture($db);
- $fac->fetch($_GET['facid']);
+ $fac->fetch($_GET['facid']);
$result = $fac->set_canceled($user);
}
}
@@ -838,7 +860,7 @@ if ($_GET['action'] == 'create')
{
print_titre($langs->trans('NewBill'));
- if ($mesg) print $mesg;
+ if ($msg) print $msg;
$soc = new Societe($db);
@@ -1416,6 +1438,10 @@ else
$soc = new Societe($db, $fac->socidp);
$soc->fetch($fac->socidp);
$absolute_discount=$soc->getCurrentDiscount();
+
+ $totalpaye = $fac->getSommePaiement();
+ $resteapayer = $fac->total_ttc - $totalpaye;
+ if ($fac->paye) $resteapayer=0;
$author = new User($db);
if ($fac->user_author)
@@ -1470,14 +1496,26 @@ else
/*
* Confirmation du classement payé
*/
- if ($_GET['action'] == 'payed')
+ if ($_GET['action'] == 'payed' && $resteapayer <= 0)
{
$html->form_confirm($_SERVER["PHP_SELF"].'?facid='.$fac->id,$langs->trans('ClassifyPayed'),$langs->trans('ConfirmClassifyPayedBill',$fac->ref),'confirm_payed');
print '
';
}
+ if ($_GET['action'] == 'payed' && $resteapayer > 0)
+ {
+ // Crée un tableau formulaire
+ $formquestion=array(
+ 'text' => $langs->trans("ConfirmClassifyPayedPartiallyQuestion"),
+ array('type' => 'radio', 'name' => 'close_code', 'label' => $langs->trans("Reason"), 'values' => array('escompte' => $langs->trans("ConfirmClassifyPayedPartiallyReasonEscompte",$resteapayer,$langs->trans("Currency".$conf->monnaie)), 'other' => $langs->trans("ConfirmClassifyPayedPartiallyReasonOther"))),
+ array('type' => 'text', 'name' => 'close_note', 'label' => $langs->trans("Comment"), 'value' => '', 'size' => '70')
+ );
+ // 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);
+ print '
';
+ }
/*
- * Confirmation du classement abandonn
+ * Confirmation du classement abandonne
*/
if ($_GET['action'] == 'canceled')
{
@@ -1563,8 +1601,6 @@ else
/*
* Liste des paiements
*/
- $totalpaye = 0;
-
$sql = 'SELECT '.$db->pdate('datep').' as dp, pf.amount,';
$sql.= ' c.libelle as paiement_type, p.num_paiement, p.rowid';
$sql.= ' FROM '.MAIN_DB_PREFIX.'paiement as p, '.MAIN_DB_PREFIX.'c_paiement as c, '.MAIN_DB_PREFIX.'paiement_facture as pf';
@@ -1588,19 +1624,19 @@ else
$var=!$var;
print '| ';
print ''.img_object($langs->trans('ShowPayment'),'payment').' ';
- print dolibarr_print_date($objp->dp).' | ';
+ print dolibarr_print_date($objp->dp).'';
print ''.$objp->paiement_type.' '.$objp->num_paiement.' | ';
print ''.price($objp->amount).' | '.$langs->trans('Currency'.$conf->monnaie).' | ';
print '
';
- $totalpaye += $objp->amount;
$i++;
}
print '| '.$langs->trans('AlreadyPayed').' : | '.price($totalpaye).' | '.$langs->trans('Currency'.$conf->monnaie).' |
';
print '| '.$langs->trans("Billed").' : | '.price($fac->total_ttc).' | '.$langs->trans('Currency'.$conf->monnaie).' |
';
-
- $resteapayer = $fac->total_ttc - $totalpaye;
-
+ if ($fac->close_code == 'escompte')
+ {
+ print '| '.$langs->trans("EscompteOffered").' : | '.price($fac->total_ttc - $totalpaye).' | '.$langs->trans('Currency'.$conf->monnaie).' |
';
+ }
print '| '.$langs->trans('RemainderToPay').' : | ';
print ''.price($resteapayer).' | '.$langs->trans('Currency'.$conf->monnaie).' |
';
@@ -2248,7 +2284,7 @@ else
}
// Envoyer une relance
- if ($fac->statut == 1 && price($resteapayer) > 0 && $user->rights->facture->envoyer)
+ if ($fac->statut == 1 && $resteapayer > 0 && $user->rights->facture->envoyer)
{
print ' '.$langs->trans('SendRemindByMail').'';
}
@@ -2261,18 +2297,18 @@ else
// Classer 'payé'
if ($fac->statut == 1 && $fac->paye == 0 && $user->rights->facture->paiement
- && price($resteapayer) <= 0)
+ && $resteapayer <= 0)
{
print ' '.$langs->trans('ClassifyPayed').'';
}
- // Classer 'fermée' (possible si validée et pas encore classer payée)
- if ($fac->statut == 1 && $fac->paye == 0 && $user->rights->facture->paiement
- && price($resteapayer) > 0)
+ // Classer 'fermée' (possible si validée et pas encore classée payée)
+ if ($fac->statut == 1 && $fac->paye == 0 && $resteapayer > 0
+ && $user->rights->facture->paiement)
{
if ($totalpaye > 0)
{
- print ' '.$langs->trans('ClassifyPayedPartially').'';
+ print ' '.$langs->trans('ClassifyPayedPartially').'';
}
else
{
diff --git a/htdocs/conf/conf.class.php b/htdocs/conf/conf.class.php
index 70ab5763426..e0f0a9a596b 100644
--- a/htdocs/conf/conf.class.php
+++ b/htdocs/conf/conf.class.php
@@ -147,6 +147,7 @@ class Conf
// Module externalrss
$this->externalrss->enabled=defined("MAIN_MODULE_EXTERNALRSS")?MAIN_MODULE_EXTERNALRSS:0;
+ $this->externalrss->dir_temp=DOL_DATA_ROOT."/rss/temp";
// Module commande client
$this->commande->enabled=defined("MAIN_MODULE_COMMANDE")?MAIN_MODULE_COMMANDE:0;
diff --git a/htdocs/expedition/commande.php b/htdocs/expedition/commande.php
index 17dcb340eb2..59129802572 100644
--- a/htdocs/expedition/commande.php
+++ b/htdocs/expedition/commande.php
@@ -89,6 +89,7 @@ if ($_GET["id"] > 0)
$soc = new Societe($db);
$soc->fetch($commande->socidp);
+
$author = new User($db);
$author->id = $commande->user_author_id;
$author->fetch();
diff --git a/htdocs/expedition/fiche.php b/htdocs/expedition/fiche.php
index 82c54d4d001..cc988453fae 100644
--- a/htdocs/expedition/fiche.php
+++ b/htdocs/expedition/fiche.php
@@ -191,6 +191,7 @@ if ($_GET["action"] == 'create')
{
$soc = new Societe($db);
$soc->fetch($commande->socidp);
+
$author = new User($db);
$author->id = $commande->user_author_id;
$author->fetch();
diff --git a/htdocs/facture.class.php b/htdocs/facture.class.php
index 161dc850e72..e5f39cc24a5 100644
--- a/htdocs/facture.class.php
+++ b/htdocs/facture.class.php
@@ -63,6 +63,8 @@ class Facture extends CommonObject
var $note_public;
var $statut;
var $paye; // 1 si facture payée COMPLETEMENT, 0 sinon
+ var $close_code; // Si mis a paye sans paiement complet, code qui justifie
+ var $close_note; // Commentaire si mis a paye sans paiement complet
var $propalid;
var $projetid;
var $date_lim_reglement;
@@ -312,7 +314,7 @@ class Facture extends CommonObject
$sql = 'SELECT f.fk_soc,f.facnumber,f.amount,f.tva,f.total,f.total_ttc,f.remise_percent,f.remise_absolue,f.remise';
$sql .= ','.$this->db->pdate('f.datef').' as df, f.fk_projet';
$sql .= ','.$this->db->pdate('f.date_lim_reglement').' as dlr';
- $sql .= ', f.note, f.note_public, f.paye, f.fk_statut, f.fk_user_author, f.model_pdf';
+ $sql .= ', f.note, f.note_public, f.fk_statut, f.paye, f.close_code, f.close_note, f.fk_user_author, f.model_pdf';
$sql .= ', f.fk_mode_reglement, f.ref_client, p.code as mode_reglement_code, p.libelle as mode_reglement_libelle';
$sql .= ', f.fk_cond_reglement, c.code as cond_reglement_code, c.libelle as cond_reglement_libelle, c.libelle_facture as cond_reglement_libelle_facture';
$sql .= ', cf.fk_commande';
@@ -346,6 +348,8 @@ class Facture extends CommonObject
$this->total_tva = $obj->tva;
$this->total_ttc = $obj->total_ttc;
$this->paye = $obj->paye;
+ $this->close_code = $obj->close_code;
+ $this->close_note = $obj->close_note;
$this->socidp = $obj->fk_soc;
$this->statut = $obj->fk_statut;
$this->date_lim_reglement = $obj->dlr;
@@ -365,36 +369,20 @@ class Facture extends CommonObject
$this->lignes = array();
- if ($this->user_author)
- {
- $sql = "SELECT name, firstname";
- $sql.= " FROM ".MAIN_DB_PREFIX."user";
- $sql.= " WHERE rowid = ".$this->user_author;
-
- $resqluser = $this->db->query($sql);
-
- if ($resqluser)
- {
- $obju = $this->db->fetch_object($resqluser);
- $this->user_author_name = $obju->name;
- $this->user_author_firstname = $obju->firstname;
- }
- }
-
- if ($this->commande_id)
- {
- $sql = "SELECT ref";
- $sql.= " FROM ".MAIN_DB_PREFIX."commande";
- $sql.= " WHERE rowid = ".$this->commande_id;
-
- $resqlcomm = $this->db->query($sql);
-
- if ($resqlcomm)
- {
- $objc = $this->db->fetch_object($resqlcomm);
- $this->commande_ref = $objc->ref;
- }
- }
+ if ($this->commande_id)
+ {
+ $sql = "SELECT ref";
+ $sql.= " FROM ".MAIN_DB_PREFIX."commande";
+ $sql.= " WHERE rowid = ".$this->commande_id;
+
+ $resqlcomm = $this->db->query($sql);
+
+ if ($resqlcomm)
+ {
+ $objc = $this->db->fetch_object($resqlcomm);
+ $this->commande_ref = $objc->ref;
+ }
+ }
if ($this->statut == 0)
{
@@ -725,17 +713,23 @@ 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
*/
- function set_payed($user)
+ function set_payed($user,$close_code='',$close_note='')
{
global $conf,$langs;
dolibarr_syslog("Facture.class.php::set_payed rowid=".$this->id);
- $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture';
- $sql.= ' SET paye=1 WHERE rowid = '.$this->id ;
- $resql = $this->db->query($sql);
+ $sql = 'UPDATE '.MAIN_DB_PREFIX.'facture SET';
+ $sql.= ' paye=1';
+ 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)
{
$this->use_webcal=($conf->global->PHPWEBCALENDAR_BILLSTATUS=='always'?1:0);
@@ -1488,16 +1482,19 @@ class Facture extends CommonObject
}
/**
- * \brief Renvoie la sommes des paiements deja effectués
- * \remarks Utilisé entre autre par certains modèles de factures
+ * \brief Renvoie la sommes des paiements deja effectués
+ * \return Montant deja versé, <0 si ko
*/
function getSommePaiement()
{
- $sql = 'SELECT sum(amount) FROM '.MAIN_DB_PREFIX.'paiement_facture WHERE fk_facture = '.$this->id;
- if ($this->db->query($sql))
+ $sql = 'SELECT sum(amount) as amount';
+ $sql.= ' FROM '.MAIN_DB_PREFIX.'paiement_facture';
+ $sql.= ' WHERE fk_facture = '.$this->id;
+ $resql=$this->db->query($sql);
+ if ($resql)
{
- $row = $this->db->fetch_row(0);
- return $row[0];
+ $obj = $this->db->fetch_object($resql);
+ return $obj->amount;
}
else
{
diff --git a/htdocs/fourn/commande/history.php b/htdocs/fourn/commande/history.php
index 4af044ba37f..cbaf50f8ee0 100644
--- a/htdocs/fourn/commande/history.php
+++ b/htdocs/fourn/commande/history.php
@@ -53,15 +53,15 @@ if ($_GET["id"] > 0)
{
$soc->fetch($commande->socidp);
+ $author = new User($db);
+ $author->id = $commande->user_author_id;
+ $author->fetch();
+
$addons[0][0] = DOL_URL_ROOT.'/fourn/fiche.php?socid='.$soc->id;
$addons[0][1] = $soc->nom;
llxHeader('',$langs->trans("History"),"CommandeFournisseur",$addons);
- $author = new User($db);
- $author->id = $commande->user_author_id;
- $author->fetch();
-
$h = 0;
$head[$h][0] = DOL_URL_ROOT.'/fourn/commande/fiche.php?id='.$commande->id;
$head[$h][1] = $langs->trans("OrderCard");
diff --git a/htdocs/fourn/commande/note.php b/htdocs/fourn/commande/note.php
index 117901ad348..0c31471006d 100644
--- a/htdocs/fourn/commande/note.php
+++ b/htdocs/fourn/commande/note.php
@@ -74,6 +74,7 @@ if ($_GET["id"] > 0)
{
$soc = new Societe($db);
$soc->fetch($commande->socidp);
+
$author = new User($db);
$author->id = $commande->user_author_id;
$author->fetch();
diff --git a/htdocs/fourn/fournisseur.commande.class.php b/htdocs/fourn/fournisseur.commande.class.php
index 33274339b59..e386eebd52c 100644
--- a/htdocs/fourn/fournisseur.commande.class.php
+++ b/htdocs/fourn/fournisseur.commande.class.php
@@ -483,7 +483,7 @@ class CommandeFournisseur extends Commande
{
require_once (DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php");
- $cc = new user($this->db, $this->user_author_id);
+ $cc = new User($this->db, $this->user_author_id);
$cc->fetch();
$sendto = $cc->email;
diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php
index 6cd70cc2e69..c38ce1b829f 100644
--- a/htdocs/html.form.class.php
+++ b/htdocs/html.form.class.php
@@ -1487,28 +1487,60 @@ class Form
/**
* \brief Affiche formulaire de demande de confirmation
- * \param page page
- * \param title title
- * \param question question
- * \param action action
+ * \param page page
+ * \param title title
+ * \param question question
+ * \param action action
+ * \param formquestion an array with forms compementary inputs
*/
- function form_confirm($page, $title, $question, $action)
+ function form_confirm($page, $title, $question, $action, $formquestion='')
{
global $langs;
- print '