diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index f86d78c14b2..cc4d8b5c441 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -501,7 +501,6 @@ if ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $user->rights->f } - /* * Insert new invoice in database */ diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index 3c673da95d0..7754a370ecd 100644 --- a/htdocs/compta/paiement/class/paiement.class.php +++ b/htdocs/compta/paiement/class/paiement.class.php @@ -54,8 +54,9 @@ class Paiement extends CommonObject /** - * \brief Constructeur de la classe - * \param DB handler acces base de donnees + * Constructor + * + * @param DoliDB $DB Database handler */ function Paiement($DB) { @@ -64,8 +65,9 @@ class Paiement extends CommonObject /** * Load payment from database - * @param id id of payment to get - * @return int <0 if KO, 0 if not found, >0 if OK + * + * @param int $id Id of payment to get + * @return int <0 if KO, 0 if not found, >0 if OK */ function fetch($id) { @@ -120,9 +122,10 @@ class Paiement extends CommonObject /** * Create payment of invoices into database. * Use this->amounts to have list of invoices for the payment - * @param user object user - * @param closepaidinvoices 1=Also close payed invoices to paid, 0=Do nothing more - * @return int id of created payment, < 0 if error + * + * @param User $user Object user + * @param int $closepaidinvoices 1=Also close payed invoices to paid, 0=Do nothing more + * @return int id of created payment, < 0 if error */ function create($user,$closepaidinvoices=0) { @@ -252,7 +255,9 @@ class Paiement extends CommonObject * Supprime un paiement ainsi que les lignes qu'il a genere dans comptes * Si le paiement porte sur un ecriture compte qui est rapprochee, on refuse * Si le paiement porte sur au moins une facture a "payee", on refuse - * @return int <0 si ko, >0 si ok + * + * @param int $notrigger No trigger + * @return int <0 si ko, >0 si ok */ function delete($notrigger=0) { @@ -351,13 +356,15 @@ class Paiement extends CommonObject /** * A record into bank for payment with links between this bank record and invoices of payment. * All payment properties must have been set first like after a call to create(). - * @param user Object of user making payment - * @param mode 'payment', 'payment_supplier' - * @param label Label to use in bank record - * @param accountid Id of bank account to do link with - * @param emetteur_nom Name of transmitter - * @param emetteur_banque Name of bank - * @return int <0 if KO, bank_line_id if OK + * + * @param User $user Object of user making payment + * @param string $mode 'payment', 'payment_supplier' + * @param string $label Label to use in bank record + * @param int $accountid Id of bank account to do link with + * @param string $emetteur_nom Name of transmitter + * @param string $emetteur_banque Name of bank + * @param int $notrigger No trigger + * @return int <0 if KO, bank_line_id if OK */ function addPaymentToBank($user,$mode,$label,$accountid,$emetteur_nom,$emetteur_banque,$notrigger=0) { @@ -382,15 +389,17 @@ class Paiement extends CommonObject if ($mode == 'payment_supplier') $totalamount=-$totalamount; // Insert payment into llx_bank - $bank_line_id = $acc->addline($this->datepaye, - $this->paiementid, // Payment mode id or code ("CHQ or VIR for example") - $label, - $totalamount, - $this->num_paiement, - '', - $user, - $emetteur_nom, - $emetteur_banque); + $bank_line_id = $acc->addline( + $this->datepaye, + $this->paiementid, // Payment mode id or code ("CHQ or VIR for example") + $label, + $totalamount, + $this->num_paiement, + '', + $user, + $emetteur_nom, + $emetteur_banque + ); // Mise a jour fk_bank dans llx_paiement // On connait ainsi le paiement qui a genere l'ecriture bancaire @@ -433,8 +442,13 @@ class Paiement extends CommonObject $fac->fetch_thirdparty(); if (! in_array($fac->thirdparty->id,$linkaddedforthirdparty)) // Not yet done for this thirdparty { - $result=$acc->add_url_line($bank_line_id, $fac->thirdparty->id, - DOL_URL_ROOT.'/comm/fiche.php?socid=', $fac->thirdparty->nom, 'company'); + $result=$acc->add_url_line( + $bank_line_id, + $fac->thirdparty->id, + DOL_URL_ROOT.'/comm/fiche.php?socid=', + $fac->thirdparty->nom, + 'company' + ); if ($result <= 0) dol_print_error($this->db); $linkaddedforthirdparty[$fac->thirdparty->id]=$fac->thirdparty->id; // Mark as done for this thirdparty } @@ -446,8 +460,13 @@ class Paiement extends CommonObject $fac->fetch_thirdparty(); if (! in_array($fac->thirdparty->id,$linkaddedforthirdparty)) // Not yet done for this thirdparty { - $result=$acc->add_url_line($bank_line_id, $fac->thirdparty->id, - DOL_URL_ROOT.'/fourn/fiche.php?socid=', $fac->thirdparty->nom, 'company'); + $result=$acc->add_url_line( + $bank_line_id, + $fac->thirdparty->id, + DOL_URL_ROOT.'/fourn/fiche.php?socid=', + $fac->thirdparty->nom, + 'company' + ); if ($result <= 0) dol_print_error($this->db); $linkaddedforthirdparty[$fac->thirdparty->id]=$fac->thirdparty->id; // Mark as done for this thirdparty } @@ -485,7 +504,9 @@ class Paiement extends CommonObject /** * Mise a jour du lien entre le paiement et la ligne generee dans llx_bank - * @param id_bank Id compte bancaire + * + * @param int $id_bank Id compte bancaire + * @return int <0 if KO, >0 if OK */ function update_fk_bank($id_bank) { @@ -506,8 +527,72 @@ class Paiement extends CommonObject } } + /** + * Updates the payment date + * + * @param timestamp $date New date + * @return int <0 if KO, 0 if OK + */ + function update_date($date) + { + if (!empty($date) && $this->statut!=1) + { + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql.= " SET datep = ".$this->db->idate($date); + $sql.= " WHERE rowid = ".$this->id; + + dol_syslog(get_class($this)."::update_date sql=".$sql); + $result = $this->db->query($sql); + if ($result) + { + $this->datepaye = $date; + $this->date = $date; + return 0; + } + else + { + $this->error='Error -1 '.$this->db->error(); + dol_syslog(get_class($this)."::update_date ".$this->error, LOG_ERR); + return -2; + } + } + return -1; //no date given or already validated + } + + /** + * Updates the payment number + * + * @param string $num New num + * @return int <0 if KO, 0 if OK + */ + function update_num($num) + { + if(!empty($num) && $this->statut!=1) + { + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element; + $sql.= " SET num_paiement = '".$this->db->escape($num)."'"; + $sql.= " WHERE rowid = ".$this->id; + + dol_syslog(get_class($this)."::update_num sql=".$sql); + $result = $this->db->query($sql); + if ($result) + { + $this->numero = $this->db->escape($num); + return 0; + } + else + { + $this->error='Error -1 '.$this->db->error(); + dol_syslog(get_class($this)."::update_num ".$this->error, LOG_ERR); + return -2; + } + } + return -1; //no num given or already validated + } + /** * Validate payment + * * @return int <0 if KO, >0 if OK */ function valide() @@ -572,9 +657,10 @@ class Paiement extends CommonObject } /** - * \brief Retourne la liste des factures sur lesquels porte le paiement - * \param filter Critere de filtre - * \return array Tableau des id de factures + * Retourne la liste des factures sur lesquels porte le paiement + * + * @param string $filter Critere de filtre + * @return array Tableau des id de factures */ function getBillsArray($filter='') { @@ -608,10 +694,11 @@ class Paiement extends CommonObject /** - * \brief Renvoie nom clicable (avec eventuellement le picto) - * \param withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul - * \param option Sur quoi pointe le lien - * \return string Chaine avec URL + * Renvoie nom clicable (avec eventuellement le picto) + * + * @param int $withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul + * @param string $option Sur quoi pointe le lien + * @return string Chaine avec URL */ function getNomUrl($withpicto=0,$option='') { @@ -629,9 +716,10 @@ class Paiement extends CommonObject } /** - * \brief Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee) - * \param mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto - * \return string Libelle + * Retourne le libelle du statut d'une facture (brouillon, validee, abandonnee, payee) + * + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * @return string Libelle */ function getLibStatut($mode=0) { @@ -639,14 +727,16 @@ class Paiement extends CommonObject } /** - * \brief Renvoi le libelle d'un statut donne - * \param status Statut - * \param mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto - * \return string Libelle du statut + * Renvoi le libelle d'un statut donne + * + * @param int $status Statut + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * @return string Libelle du statut */ function LibStatut($status,$mode=0) { global $langs; // TODO Renvoyer le libelle anglais et faire traduction a affichage + $langs->load('compta'); if ($mode == 0) { diff --git a/htdocs/compta/paiement/fiche.php b/htdocs/compta/paiement/fiche.php index 390ef0984f0..26707aeb6fa 100644 --- a/htdocs/compta/paiement/fiche.php +++ b/htdocs/compta/paiement/fiche.php @@ -126,6 +126,37 @@ if ($action == 'confirm_valide' && GETPOST('confirm') == 'yes' && $user->rights- } } +if ($action == 'setnum' && !empty($_POST['num'])) +{ + $paiement = new Paiement($db); + $paiement->fetch($id); + $res = $paiement->update_num($_POST['num']); + if ($res === 0) + { + $mesg = '
| '.$langs->trans('Ref').' | '.$paiement->id.' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| '.$langs->trans('Ref').' | '.$paiement->id.' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| '.$langs->trans('Date').' | '.dol_print_date($paiement->date,'day').' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| '.$html->editfieldkey("Date",'date',$paiement->date,'id',$paiement->id,$user->rights->facture->paiement).' | '; +print $html->editfieldval("Date",'date',$paiement->date,'id',$paiement->id,$user->rights->facture->paiement,'day'); +print ' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| '.$langs->trans('Mode').' | '.$labeltype.' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| '.$langs->trans('PaymentMode').' | '.$labeltype.' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| '.$langs->trans('Numero').' | '.$paiement->numero.' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| '.$html->editfieldkey("Numero",'num',$paiement->numero,'id',$paiement->id,$paiement->statut == 0 && $user->rights->fournisseur->facture->creer).' | '; +print $html->editfieldval("Numero",'num',$paiement->numero,'id',$paiement->id,$paiement->statut == 0 && $user->rights->fournisseur->facture->creer,'string'); +print ' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| '.$langs->trans('Amount').' | '.price($paiement->montant).' '.$langs->trans('Currency'.$conf->monnaie).' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| '.$html->editfieldkey("Note",'note',$paiement->note,'id',$paiement->id,$user->rights->facture->paiement).' | ';
print $html->editfieldval("Note",'note',$paiement->note,'id',$paiement->id,$user->rights->facture->paiement,'text');
diff --git a/htdocs/fourn/class/paiementfourn.class.php b/htdocs/fourn/class/paiementfourn.class.php
index ec97237457f..0c08c282767 100644
--- a/htdocs/fourn/class/paiementfourn.class.php
+++ b/htdocs/fourn/class/paiementfourn.class.php
@@ -55,10 +55,10 @@ class PaiementFourn extends Paiement
// fk_paiement dans llx_paiement_facture est le rowid du paiement
/**
- * \brief Constructeur de la classe
- * \param DB handler acces base de donnees
+ * Constructor
+ *
+ * @param DoliDB $DB Database handler
*/
-
function PaiementFourn($DB)
{
$this->db = $DB ;
@@ -475,65 +475,5 @@ class PaiementFourn extends Paiement
if ($withpicto != 2) $result.=$lien.$text.$lienfin;
return $result;
}
-
- /**
- * \brief Updates the payment number
- * \param string New num
- * \return int -1 on error, 0 otherwise
- */
- function update_num($num)
- {
- if(!empty($num) && $this->statut!=1)
- {
- $sql = "UPDATE ".MAIN_DB_PREFIX."paiementfourn";
- $sql.= " SET num_paiement = '".$this->db->escape($num)."'";
- $sql.= " WHERE rowid = ".$this->id;
-
- dol_syslog("PaiementFourn::update_num sql=".$sql);
- $result = $this->db->query($sql);
- if ($result)
- {
- $this->numero = $this->db->escape($num);
- return 0;
- }
- else
- {
- $this->error='PaiementFourn::update_num Error -1 '.$this->db->error();
- dol_syslog('PaiementFourn::update_num error '.$this->error, LOG_ERR);
- return -1;
- }
- }
- return -1; //no num given or already validated
- }
- /**
- * \brief Updates the payment date
- * \param string New date
- * \return int -1 on error, 0 otherwise
- */
- function update_date($date)
- {
- if(!empty($date) && $this->statut!=1)
- {
- $sql = "UPDATE ".MAIN_DB_PREFIX."paiementfourn";
- $sql.= " SET datep = ".$this->db->idate($date);
- $sql.= " WHERE rowid = ".$this->id;
-
- dol_syslog("PaiementFourn::update_date sql=".$sql);
- $result = $this->db->query($sql);
- if ($result)
- {
- $this->datepaye = $date;
- $this-> date = $date;
- return 0;
- }
- else
- {
- $this->error='PaiementFourn::update_date Error -1 '.$this->db->error();
- dol_syslog('PaiementFourn::update_date error '.$this->error, LOG_ERR);
- return -1;
- }
- }
- return -1; //no date given or already validated
- }
}
?>
diff --git a/htdocs/fourn/paiement/fiche.php b/htdocs/fourn/paiement/fiche.php
index c03e72e44b7..56692542365 100644
--- a/htdocs/fourn/paiement/fiche.php
+++ b/htdocs/fourn/paiement/fiche.php
@@ -35,18 +35,38 @@ $langs->load('companies');
$langs->load("suppliers");
$mesg='';
+$action=GETPOST('action');
+$id=GETPOST('id');
/*
* Actions
*/
-if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes' && $user->rights->fournisseur->facture->supprimer)
+if ($action == 'setnote' && $user->rights->fournisseur->facture->creer)
+{
+ $db->begin();
+ $paiement = new PaiementFourn($db);
+ $paiement->fetch($id);
+ $result = $paiement->update_note(GETPOST('note'));
+ if ($result > 0)
+ {
+ $db->commit();
+ $action='';
+ }
+ else
+ {
+ $mesg=' '.$paiement->error.' ';
+ $db->rollback();
+ }
+}
+
+if ($action == 'confirm_delete' && $_POST['confirm'] == 'yes' && $user->rights->fournisseur->facture->supprimer)
{
$db->begin();
$paiement = new PaiementFourn($db);
- $paiement->fetch($_GET['id']);
+ $paiement->fetch($id);
$result = $paiement->delete();
if ($result > 0)
{
@@ -61,12 +81,12 @@ if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes' && $user-
}
}
-if ($_POST['action'] == 'confirm_valide' && $_POST['confirm'] == 'yes' && $user->rights->fournisseur->facture->valider)
+if ($action == 'confirm_valide' && $_POST['confirm'] == 'yes' && $user->rights->fournisseur->facture->valider)
{
$db->begin();
$paiement = new PaiementFourn($db);
- $paiement->id = $_GET['id'];
+ $paiement->fetch($id);
if ($paiement->valide() >= 0)
{
$db->commit();
@@ -80,6 +100,37 @@ if ($_POST['action'] == 'confirm_valide' && $_POST['confirm'] == 'yes' && $user-
}
}
+if ($action == 'setnum' && !empty($_POST['num']))
+{
+ $paiement = new PaiementFourn($db);
+ $paiement->fetch($id);
+ $res = $paiement->update_num($_POST['num']);
+ if ($res === 0)
+ {
+ $mesg = ''.$langs->trans('PaymentNumberUpdateSucceeded').' ';
+ }
+ else
+ {
+ $mesg = ''.$langs->trans('PaymentNumberUpdateFailed').' ';
+ }
+}
+
+if ($action == 'setdate' && !empty($_POST['dateday']))
+{
+ $paiement = new PaiementFourn($db);
+ $paiement->fetch($id);
+ $datepaye = dol_mktime(12, 0, 0, $_POST['datemonth'], $_POST['dateday'], $_POST['dateyear']);
+ $res = $paiement->update_date($datepaye);
+ if ($res === 0)
+ {
+ $mesg = ''.$langs->trans('PaymentDateUpdateSucceeded').' ';
+ }
+ else
+ {
+ $mesg = ''.$langs->trans('PaymentDateUpdateFailed').' ';
+ }
+}
+
/*
* View
@@ -91,12 +142,12 @@ $html = new Form($db);
$h=0;
-$head[$h][0] = DOL_URL_ROOT.'/fourn/paiement/fiche.php?id='.$_GET['id'];
+$head[$h][0] = DOL_URL_ROOT.'/fourn/paiement/fiche.php?id='.$id;
$head[$h][1] = $langs->trans('Card');
$hselected = $h;
$h++;
-$head[$h][0] = DOL_URL_ROOT.'/fourn/paiement/info.php?id='.$_GET['id'];
+$head[$h][0] = DOL_URL_ROOT.'/fourn/paiement/info.php?id='.$id;
$head[$h][1] = $langs->trans('Info');
$h++;
@@ -104,14 +155,13 @@ $h++;
dol_fiche_head($head, $hselected, $langs->trans('SupplierPayment'), 0, 'payment');
$paiement = new PaiementFourn($db);
-$result=$paiement->fetch($_GET['id']);
+$result=$paiement->fetch($id);
if ($result > 0)
{
-
/*
* Confirmation de la suppression du paiement
*/
- if ($_GET['action'] == 'delete')
+ if ($action == 'delete')
{
$ret=$html->form_confirm('fiche.php?id='.$paiement->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete');
if ($ret == 'html') print ''; @@ -120,102 +170,31 @@ if ($result > 0) /* * Confirmation de la validation du paiement */ - if ($_GET['action'] == 'valide') + if ($action == 'valide') { $ret=$html->form_confirm('fiche.php?id='.$paiement->id, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide'); if ($ret == 'html') print ' '; } - if (!empty($_POST['action']) && $_POST['action'] == 'update_num' && !empty($_POST['new_num'])) - { - $res = $paiement->update_num($_POST['new_num']); - if ($res === 0) { - $mesg = ' '.$langs->trans('PaymentNumberUpdateSucceeded').' ';
- } else {
- $mesg = ''.$langs->trans('PaymentNumberUpdateFailed').' ';
- }
- }
-
- if (!empty($_POST['action']) && $_POST['action'] == 'update_date' && !empty($_POST['reday']))
- {
- $datepaye = dol_mktime(12, 0 , 0,
- $_POST['remonth'],
- $_POST['reday'],
- $_POST['reyear']);
- $res = $paiement->update_date($datepaye);
- if ($res === 0) {
- $mesg = ''.$langs->trans('PaymentDateUpdateSucceeded').' ';
- } else {
- $mesg = ''.$langs->trans('PaymentDateUpdateFailed').' ';
- }
- }
-
-
print '
'.$mesg; + dol_htmloutput_mesg($mesg); print ' '; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||