Qual: Mutualize a lot of code between supplier and customer payments
This commit is contained in:
parent
79546fa072
commit
fe30491a45
@ -501,7 +501,6 @@ if ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $user->rights->f
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Insert new invoice in database
|
* Insert new invoice in database
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -54,8 +54,9 @@ class Paiement extends CommonObject
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Constructeur de la classe
|
* Constructor
|
||||||
* \param DB handler acces base de donnees
|
*
|
||||||
|
* @param DoliDB $DB Database handler
|
||||||
*/
|
*/
|
||||||
function Paiement($DB)
|
function Paiement($DB)
|
||||||
{
|
{
|
||||||
@ -64,8 +65,9 @@ class Paiement extends CommonObject
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Load payment from database
|
* 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)
|
function fetch($id)
|
||||||
{
|
{
|
||||||
@ -120,9 +122,10 @@ class Paiement extends CommonObject
|
|||||||
/**
|
/**
|
||||||
* Create payment of invoices into database.
|
* Create payment of invoices into database.
|
||||||
* Use this->amounts to have list of invoices for the payment
|
* 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
|
* @param User $user Object user
|
||||||
* @return int id of created payment, < 0 if error
|
* @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)
|
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
|
* 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 un ecriture compte qui est rapprochee, on refuse
|
||||||
* Si le paiement porte sur au moins une facture a "payee", 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)
|
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.
|
* 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().
|
* 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 User $user Object of user making payment
|
||||||
* @param label Label to use in bank record
|
* @param string $mode 'payment', 'payment_supplier'
|
||||||
* @param accountid Id of bank account to do link with
|
* @param string $label Label to use in bank record
|
||||||
* @param emetteur_nom Name of transmitter
|
* @param int $accountid Id of bank account to do link with
|
||||||
* @param emetteur_banque Name of bank
|
* @param string $emetteur_nom Name of transmitter
|
||||||
* @return int <0 if KO, bank_line_id if OK
|
* @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)
|
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;
|
if ($mode == 'payment_supplier') $totalamount=-$totalamount;
|
||||||
|
|
||||||
// Insert payment into llx_bank
|
// Insert payment into llx_bank
|
||||||
$bank_line_id = $acc->addline($this->datepaye,
|
$bank_line_id = $acc->addline(
|
||||||
$this->paiementid, // Payment mode id or code ("CHQ or VIR for example")
|
$this->datepaye,
|
||||||
$label,
|
$this->paiementid, // Payment mode id or code ("CHQ or VIR for example")
|
||||||
$totalamount,
|
$label,
|
||||||
$this->num_paiement,
|
$totalamount,
|
||||||
'',
|
$this->num_paiement,
|
||||||
$user,
|
'',
|
||||||
$emetteur_nom,
|
$user,
|
||||||
$emetteur_banque);
|
$emetteur_nom,
|
||||||
|
$emetteur_banque
|
||||||
|
);
|
||||||
|
|
||||||
// Mise a jour fk_bank dans llx_paiement
|
// Mise a jour fk_bank dans llx_paiement
|
||||||
// On connait ainsi le paiement qui a genere l'ecriture bancaire
|
// On connait ainsi le paiement qui a genere l'ecriture bancaire
|
||||||
@ -433,8 +442,13 @@ class Paiement extends CommonObject
|
|||||||
$fac->fetch_thirdparty();
|
$fac->fetch_thirdparty();
|
||||||
if (! in_array($fac->thirdparty->id,$linkaddedforthirdparty)) // Not yet done for this 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,
|
$result=$acc->add_url_line(
|
||||||
DOL_URL_ROOT.'/comm/fiche.php?socid=', $fac->thirdparty->nom, 'company');
|
$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);
|
if ($result <= 0) dol_print_error($this->db);
|
||||||
$linkaddedforthirdparty[$fac->thirdparty->id]=$fac->thirdparty->id; // Mark as done for this thirdparty
|
$linkaddedforthirdparty[$fac->thirdparty->id]=$fac->thirdparty->id; // Mark as done for this thirdparty
|
||||||
}
|
}
|
||||||
@ -446,8 +460,13 @@ class Paiement extends CommonObject
|
|||||||
$fac->fetch_thirdparty();
|
$fac->fetch_thirdparty();
|
||||||
if (! in_array($fac->thirdparty->id,$linkaddedforthirdparty)) // Not yet done for this 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,
|
$result=$acc->add_url_line(
|
||||||
DOL_URL_ROOT.'/fourn/fiche.php?socid=', $fac->thirdparty->nom, 'company');
|
$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);
|
if ($result <= 0) dol_print_error($this->db);
|
||||||
$linkaddedforthirdparty[$fac->thirdparty->id]=$fac->thirdparty->id; // Mark as done for this thirdparty
|
$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
|
* 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)
|
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
|
* Validate payment
|
||||||
|
*
|
||||||
* @return int <0 if KO, >0 if OK
|
* @return int <0 if KO, >0 if OK
|
||||||
*/
|
*/
|
||||||
function valide()
|
function valide()
|
||||||
@ -572,9 +657,10 @@ class Paiement extends CommonObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Retourne la liste des factures sur lesquels porte le paiement
|
* Retourne la liste des factures sur lesquels porte le paiement
|
||||||
* \param filter Critere de filtre
|
*
|
||||||
* \return array Tableau des id de factures
|
* @param string $filter Critere de filtre
|
||||||
|
* @return array Tableau des id de factures
|
||||||
*/
|
*/
|
||||||
function getBillsArray($filter='')
|
function getBillsArray($filter='')
|
||||||
{
|
{
|
||||||
@ -608,10 +694,11 @@ class Paiement extends CommonObject
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Renvoie nom clicable (avec eventuellement le picto)
|
* 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
|
* @param int $withpicto 0=Pas de picto, 1=Inclut le picto dans le lien, 2=Picto seul
|
||||||
* \return string Chaine avec URL
|
* @param string $option Sur quoi pointe le lien
|
||||||
|
* @return string Chaine avec URL
|
||||||
*/
|
*/
|
||||||
function getNomUrl($withpicto=0,$option='')
|
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)
|
* 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
|
* @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)
|
function getLibStatut($mode=0)
|
||||||
{
|
{
|
||||||
@ -639,14 +727,16 @@ class Paiement extends CommonObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Renvoi le libelle d'un statut donne
|
* 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
|
* @param int $status Statut
|
||||||
* \return string Libelle du 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)
|
function LibStatut($status,$mode=0)
|
||||||
{
|
{
|
||||||
global $langs; // TODO Renvoyer le libelle anglais et faire traduction a affichage
|
global $langs; // TODO Renvoyer le libelle anglais et faire traduction a affichage
|
||||||
|
|
||||||
$langs->load('compta');
|
$langs->load('compta');
|
||||||
if ($mode == 0)
|
if ($mode == 0)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -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 = '<div class="ok">'.$langs->trans('PaymentNumberUpdateSucceeded').'</div>';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$mesg = '<div class="error">'.$langs->trans('PaymentNumberUpdateFailed').'</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($action == 'setdate' && !empty($_POST['dateday']))
|
||||||
|
{
|
||||||
|
$paiement = new Paiement($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 = '<div class="ok">'.$langs->trans('PaymentDateUpdateSucceeded').'</div>';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$mesg = '<div class="error">'.$langs->trans('PaymentDateUpdateFailed').'</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* View
|
* View
|
||||||
@ -185,25 +216,25 @@ dol_htmloutput_mesg($mesg);
|
|||||||
print '<table class="border" width="100%">';
|
print '<table class="border" width="100%">';
|
||||||
|
|
||||||
// Ref
|
// Ref
|
||||||
print '<tr><td valign="top" width="140">'.$langs->trans('Ref').'</td><td colspan="3">'.$paiement->id.'</td></tr>';
|
print '<tr><td valign="top" width="20%">'.$langs->trans('Ref').'</td><td colspan="3">'.$paiement->id.'</td></tr>';
|
||||||
|
|
||||||
// Date
|
// Date payment
|
||||||
print '<tr><td valign="top" width="120">'.$langs->trans('Date').'</td><td colspan="3">'.dol_print_date($paiement->date,'day').'</td></tr>';
|
print '<tr><td valign="top">'.$html->editfieldkey("Date",'date',$paiement->date,'id',$paiement->id,$user->rights->facture->paiement).'</td><td colspan="3">';
|
||||||
|
print $html->editfieldval("Date",'date',$paiement->date,'id',$paiement->id,$user->rights->facture->paiement,'day');
|
||||||
|
print '</td></tr>';
|
||||||
|
|
||||||
// Payment type (VIR, LIQ, ...)
|
// Payment type (VIR, LIQ, ...)
|
||||||
$labeltype=$langs->trans("PaymentType".$paiement->type_code)!=("PaymentType".$paiement->type_code)?$langs->trans("PaymentType".$paiement->type_code):$paiement->type_libelle;
|
$labeltype=$langs->trans("PaymentType".$paiement->type_code)!=("PaymentType".$paiement->type_code)?$langs->trans("PaymentType".$paiement->type_code):$paiement->type_libelle;
|
||||||
print '<tr><td valign="top">'.$langs->trans('Mode').'</td><td colspan="3">'.$labeltype.'</td></tr>';
|
print '<tr><td valign="top">'.$langs->trans('PaymentMode').'</td><td colspan="3">'.$labeltype.'</td></tr>';
|
||||||
|
|
||||||
// Numero
|
// Payment numero
|
||||||
//if ($paiement->montant)
|
print '<tr><td valign="top">'.$html->editfieldkey("Numero",'num',$paiement->numero,'id',$paiement->id,$paiement->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td colspan="3">';
|
||||||
//{
|
print $html->editfieldval("Numero",'num',$paiement->numero,'id',$paiement->id,$paiement->statut == 0 && $user->rights->fournisseur->facture->creer,'string');
|
||||||
print '<tr><td valign="top">'.$langs->trans('Numero').'</td><td colspan="3">'.$paiement->numero.'</td></tr>';
|
print '</td></tr>';
|
||||||
//}
|
|
||||||
|
|
||||||
// Amount
|
// Amount
|
||||||
print '<tr><td valign="top">'.$langs->trans('Amount').'</td><td colspan="3">'.price($paiement->montant).' '.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
|
print '<tr><td valign="top">'.$langs->trans('Amount').'</td><td colspan="3">'.price($paiement->montant).' '.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
|
||||||
|
|
||||||
|
|
||||||
// Note
|
// Note
|
||||||
print '<tr><td valign="top">'.$html->editfieldkey("Note",'note',$paiement->note,'id',$paiement->id,$user->rights->facture->paiement).'</td><td colspan="3">';
|
print '<tr><td valign="top">'.$html->editfieldkey("Note",'note',$paiement->note,'id',$paiement->id,$user->rights->facture->paiement).'</td><td colspan="3">';
|
||||||
print $html->editfieldval("Note",'note',$paiement->note,'id',$paiement->id,$user->rights->facture->paiement,'text');
|
print $html->editfieldval("Note",'note',$paiement->note,'id',$paiement->id,$user->rights->facture->paiement,'text');
|
||||||
|
|||||||
@ -55,10 +55,10 @@ class PaiementFourn extends Paiement
|
|||||||
// fk_paiement dans llx_paiement_facture est le rowid du paiement
|
// fk_paiement dans llx_paiement_facture est le rowid du paiement
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Constructeur de la classe
|
* Constructor
|
||||||
* \param DB handler acces base de donnees
|
*
|
||||||
|
* @param DoliDB $DB Database handler
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function PaiementFourn($DB)
|
function PaiementFourn($DB)
|
||||||
{
|
{
|
||||||
$this->db = $DB ;
|
$this->db = $DB ;
|
||||||
@ -475,65 +475,5 @@ class PaiementFourn extends Paiement
|
|||||||
if ($withpicto != 2) $result.=$lien.$text.$lienfin;
|
if ($withpicto != 2) $result.=$lien.$text.$lienfin;
|
||||||
return $result;
|
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|||||||
@ -35,18 +35,38 @@ $langs->load('companies');
|
|||||||
$langs->load("suppliers");
|
$langs->load("suppliers");
|
||||||
|
|
||||||
$mesg='';
|
$mesg='';
|
||||||
|
$action=GETPOST('action');
|
||||||
|
$id=GETPOST('id');
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Actions
|
* 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='<div class="error">'.$paiement->error.'</div>';
|
||||||
|
$db->rollback();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($action == 'confirm_delete' && $_POST['confirm'] == 'yes' && $user->rights->fournisseur->facture->supprimer)
|
||||||
{
|
{
|
||||||
$db->begin();
|
$db->begin();
|
||||||
|
|
||||||
$paiement = new PaiementFourn($db);
|
$paiement = new PaiementFourn($db);
|
||||||
$paiement->fetch($_GET['id']);
|
$paiement->fetch($id);
|
||||||
$result = $paiement->delete();
|
$result = $paiement->delete();
|
||||||
if ($result > 0)
|
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();
|
$db->begin();
|
||||||
|
|
||||||
$paiement = new PaiementFourn($db);
|
$paiement = new PaiementFourn($db);
|
||||||
$paiement->id = $_GET['id'];
|
$paiement->fetch($id);
|
||||||
if ($paiement->valide() >= 0)
|
if ($paiement->valide() >= 0)
|
||||||
{
|
{
|
||||||
$db->commit();
|
$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 = '<div class="ok">'.$langs->trans('PaymentNumberUpdateSucceeded').'</div>';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$mesg = '<div class="error">'.$langs->trans('PaymentNumberUpdateFailed').'</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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 = '<div class="ok">'.$langs->trans('PaymentDateUpdateSucceeded').'</div>';
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$mesg = '<div class="error">'.$langs->trans('PaymentDateUpdateFailed').'</div>';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* View
|
* View
|
||||||
@ -91,12 +142,12 @@ $html = new Form($db);
|
|||||||
|
|
||||||
$h=0;
|
$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');
|
$head[$h][1] = $langs->trans('Card');
|
||||||
$hselected = $h;
|
$hselected = $h;
|
||||||
$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');
|
$head[$h][1] = $langs->trans('Info');
|
||||||
$h++;
|
$h++;
|
||||||
|
|
||||||
@ -104,14 +155,13 @@ $h++;
|
|||||||
dol_fiche_head($head, $hselected, $langs->trans('SupplierPayment'), 0, 'payment');
|
dol_fiche_head($head, $hselected, $langs->trans('SupplierPayment'), 0, 'payment');
|
||||||
|
|
||||||
$paiement = new PaiementFourn($db);
|
$paiement = new PaiementFourn($db);
|
||||||
$result=$paiement->fetch($_GET['id']);
|
$result=$paiement->fetch($id);
|
||||||
if ($result > 0)
|
if ($result > 0)
|
||||||
{
|
{
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Confirmation de la suppression du paiement
|
* 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');
|
$ret=$html->form_confirm('fiche.php?id='.$paiement->id, $langs->trans("DeletePayment"), $langs->trans("ConfirmDeletePayment"), 'confirm_delete');
|
||||||
if ($ret == 'html') print '<br>';
|
if ($ret == 'html') print '<br>';
|
||||||
@ -120,102 +170,31 @@ if ($result > 0)
|
|||||||
/*
|
/*
|
||||||
* Confirmation de la validation du paiement
|
* 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');
|
$ret=$html->form_confirm('fiche.php?id='.$paiement->id, $langs->trans("ValidatePayment"), $langs->trans("ConfirmValidatePayment"), 'confirm_valide');
|
||||||
if ($ret == 'html') print '<br>';
|
if ($ret == 'html') print '<br>';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($_POST['action']) && $_POST['action'] == 'update_num' && !empty($_POST['new_num']))
|
|
||||||
{
|
|
||||||
$res = $paiement->update_num($_POST['new_num']);
|
|
||||||
if ($res === 0) {
|
|
||||||
$mesg = '<div class="ok">'.$langs->trans('PaymentNumberUpdateSucceeded').'</div>';
|
|
||||||
} else {
|
|
||||||
$mesg = '<div class="error">'.$langs->trans('PaymentNumberUpdateFailed').'</div>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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 = '<div class="ok">'.$langs->trans('PaymentDateUpdateSucceeded').'</div>';
|
|
||||||
} else {
|
|
||||||
$mesg = '<div class="error">'.$langs->trans('PaymentDateUpdateFailed').'</div>';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
print '<table class="border" width="100%">';
|
print '<table class="border" width="100%">';
|
||||||
|
|
||||||
print '<tr>';
|
print '<tr>';
|
||||||
print '<td valign="top" width="20%" colspan="2">'.$langs->trans('Ref').'</td><td colspan="3">'.$paiement->id.'</td></tr>';
|
print '<td valign="top" width="20%" colspan="2">'.$langs->trans('Ref').'</td><td colspan="3">'.$paiement->id.'</td></tr>';
|
||||||
|
|
||||||
//switch through edition options for date (only available when statut is -not 1- (=validated))
|
// Date payment
|
||||||
if (empty($_GET['action']) || $_GET['action']!='edit_date')
|
print '<tr><td valign="top" colspan="2">'.$html->editfieldkey("Date",'date',$paiement->date,'id',$paiement->id,$paiement->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td colspan="3">';
|
||||||
{
|
print $html->editfieldval("Date",'date',$paiement->date,'id',$paiement->id,$paiement->statut == 0 && $user->rights->fournisseur->facture->creer,'day');
|
||||||
print '<tr><td colspan="2">';
|
print '</td></tr>';
|
||||||
print '<table class="nobordernopadding" width="100%"><tr><td nowrap="nowrap">';
|
|
||||||
print $langs->trans('Date');
|
|
||||||
print '</td>';
|
|
||||||
if ($paiement->statut == 0 && $_GET['action'] != 'edit_date') print '<td align="right"><a href="'.DOL_URL_ROOT.'/fourn/paiement/fiche.php?id='.$paiement->id.'&action=edit_date">'.img_edit($langs->trans('Modify')).'</a></td>';
|
|
||||||
print '</tr></table>';
|
|
||||||
print '</td>';
|
|
||||||
print '<td colspan="3">'.dol_print_date($paiement->date,'day').'</td></tr>';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
print '<tr>';
|
|
||||||
print '<td valign="top" colspan="2">'.$langs->trans('Date').'</td>';
|
|
||||||
print '<td colspan="3">';
|
|
||||||
print '<form name="formsoc" method="post" action="'.DOL_URL_ROOT.'/fourn/paiement/fiche.php?id='.$paiement->id.'"><input type="hidden" name="action" value="update_date" />';
|
|
||||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
|
||||||
if (!empty($_POST['remonth']) && !empty($_POST['reday']) && !empty($_POST['reyear']))
|
|
||||||
$sel_date=dol_mktime(12, 0, 0, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
|
|
||||||
else
|
|
||||||
$sel_date=$paiement->date;
|
|
||||||
$html->select_date($sel_date,'','','','',"addpaiement");
|
|
||||||
print '<input type="submit" class="button" name="submit" value="'.$langs->trans('Validate').'" />';
|
|
||||||
print '</form>';
|
|
||||||
print '</td>';
|
|
||||||
print '</tr>';
|
|
||||||
}
|
|
||||||
|
|
||||||
print '<tr><td valign="top" colspan="2">'.$langs->trans('Type').'</td><td colspan="3">'.$paiement->type_libelle.'</td></tr>';
|
// Payment mode
|
||||||
|
print '<tr><td valign="top" colspan="2">'.$langs->trans('PaymentMode').'</td><td colspan="3">'.$paiement->type_libelle.'</td></tr>';
|
||||||
|
|
||||||
//switch through edition options for number (only available when statut is -not 1- (=validated))
|
// Payment numero
|
||||||
if (empty($_GET['action']) || $_GET['action'] != 'edit_num')
|
print '<tr><td valign="top" colspan="2">'.$html->editfieldkey("Numero",'num',$paiement->numero,'id',$paiement->id,$paiement->statut == 0 && $user->rights->fournisseur->facture->creer).'</td><td colspan="3">';
|
||||||
{
|
print $html->editfieldval("Numero",'num',$paiement->numero,'id',$paiement->id,$paiement->statut == 0 && $user->rights->fournisseur->facture->creer,'string');
|
||||||
print '<tr><td colspan="2">';
|
print '</td></tr>';
|
||||||
print '<table class="nobordernopadding" width="100%"><tr><td nowrap="nowrap">';
|
|
||||||
print $langs->trans('Numero');
|
// Amount
|
||||||
print '</td>';
|
|
||||||
if ($paiement->statut == 0 && $_GET['action'] != 'edit_num') print '<td align="right"><a href="'.DOL_URL_ROOT.'/fourn/paiement/fiche.php?id='.$paiement->id.'&action=edit_num">'.img_edit($langs->trans('Modify')).'</a></td>';
|
|
||||||
print '</tr></table>';
|
|
||||||
print '</td>';
|
|
||||||
print '<td colspan="3">'.$paiement->numero.'</td></tr>';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
print '<tr>';
|
|
||||||
print '<td valign="top" colspan="2">'.$langs->trans('Numero').'</td>';
|
|
||||||
print '<td colspan="3">';
|
|
||||||
print '<form name="formsoc" method="post" action="'.DOL_URL_ROOT.'/fourn/paiement/fiche.php?id='.$paiement->id.'"><input type="hidden" name="action" value="update_num" />';
|
|
||||||
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
|
|
||||||
if (!empty($_POST['new_num']))
|
|
||||||
$num = $this->db->escape($_POST['new_num']);
|
|
||||||
else
|
|
||||||
$num = $paiement->numero;
|
|
||||||
print '<input type="text" name="new_num" value="'.$num.'"/>';
|
|
||||||
print '<input type="submit" class="button" name="submit" value="'.$langs->trans('Validate').'" />';
|
|
||||||
print '</form></td>';
|
|
||||||
print '</tr>';
|
|
||||||
}
|
|
||||||
print '<tr><td valign="top" colspan="2">'.$langs->trans('Amount').'</td><td colspan="3">'.price($paiement->montant).' '.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
|
print '<tr><td valign="top" colspan="2">'.$langs->trans('Amount').'</td><td colspan="3">'.price($paiement->montant).' '.$langs->trans('Currency'.$conf->monnaie).'</td></tr>';
|
||||||
|
|
||||||
if ($conf->global->BILL_ADD_PAYMENT_VALIDATION)
|
if ($conf->global->BILL_ADD_PAYMENT_VALIDATION)
|
||||||
@ -223,7 +202,10 @@ if ($result > 0)
|
|||||||
print '<tr><td valign="top" colspan="2">'.$langs->trans('Status').'</td><td colspan="3">'.$paiement->getLibStatut(4).'</td></tr>';
|
print '<tr><td valign="top" colspan="2">'.$langs->trans('Status').'</td><td colspan="3">'.$paiement->getLibStatut(4).'</td></tr>';
|
||||||
}
|
}
|
||||||
|
|
||||||
print '<tr><td valign="top" colspan="2">'.$langs->trans('Note').'</td><td colspan="3">'.nl2br($paiement->note).'</td></tr>';
|
// Note
|
||||||
|
print '<tr><td valign="top"" colspan="2">'.$html->editfieldkey("Note",'note',$paiement->note,'id',$paiement->id,$user->rights->fournisseur->facture->creer).'</td><td colspan="3">';
|
||||||
|
print $html->editfieldval("Note",'note',$paiement->note,'id',$paiement->id,$user->rights->fournisseur->facture->creer,'text');
|
||||||
|
print '</td></tr>';
|
||||||
|
|
||||||
// Bank account
|
// Bank account
|
||||||
if ($conf->banque->enabled)
|
if ($conf->banque->enabled)
|
||||||
@ -244,7 +226,7 @@ if ($result > 0)
|
|||||||
|
|
||||||
print '</table>';
|
print '</table>';
|
||||||
|
|
||||||
if ($mesg) print '<br>'.$mesg;
|
dol_htmloutput_mesg($mesg);
|
||||||
|
|
||||||
print '<br>';
|
print '<br>';
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user