NEW : Enter amount for withdraws requests

This commit is contained in:
maxime peyrot 2015-06-19 13:45:14 +02:00
parent 2785bf7520
commit f99a127a57
7 changed files with 64 additions and 32 deletions

View File

@ -3066,6 +3066,8 @@ class Facture extends CommonInvoice
*/ */
function demande_prelevement($user) function demande_prelevement($user)
{ {
global $langs;
$error=0; $error=0;
dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG); dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG);
@ -3080,7 +3082,7 @@ class Facture extends CommonInvoice
$sql.= ' FROM '.MAIN_DB_PREFIX.'prelevement_facture_demande'; $sql.= ' FROM '.MAIN_DB_PREFIX.'prelevement_facture_demande';
$sql.= ' WHERE fk_facture = '.$this->id; $sql.= ' WHERE fk_facture = '.$this->id;
$sql.= ' AND traite = 0'; $sql.= ' AND traite = 0';
dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG); dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if ($resql) if ($resql)
@ -3099,27 +3101,36 @@ class Facture extends CommonInvoice
// For example print 239.2 - 229.3 - 9.9; does not return 0. // For example print 239.2 - 229.3 - 9.9; does not return 0.
//$resteapayer=bcadd($this->total_ttc,$totalpaye,$conf->global->MAIN_MAX_DECIMALS_TOT); //$resteapayer=bcadd($this->total_ttc,$totalpaye,$conf->global->MAIN_MAX_DECIMALS_TOT);
//$resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT); //$resteapayer=bcadd($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT);
$resteapayer = price2num($this->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits,'MT');
//$resteapayer = price2num($this->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits,'MT');
$sql = 'INSERT INTO '.MAIN_DB_PREFIX.'prelevement_facture_demande'; $amount = GETPOST('withdraw_request_amount');
$sql .= ' (fk_facture, amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib)';
$sql .= ' VALUES ('.$this->id; if (is_numeric($amount) && $amount != 0) {
$sql .= ",'".price2num($resteapayer)."'"; $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'prelevement_facture_demande';
$sql .= ",'".$this->db->idate($now)."'"; $sql .= ' (fk_facture, amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib)';
$sql .= ",".$user->id; $sql .= ' VALUES ('.$this->id;
$sql .= ",'".$bac->code_banque."'"; $sql .= ",'".price2num($amount)."'";
$sql .= ",'".$bac->code_guichet."'"; $sql .= ",'".$this->db->idate($now)."'";
$sql .= ",'".$bac->number."'"; $sql .= ",".$user->id;
$sql .= ",'".$bac->cle_rib."')"; $sql .= ",'".$bac->code_banque."'";
$sql .= ",'".$bac->code_guichet."'";
dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG); $sql .= ",'".$bac->number."'";
$resql=$this->db->query($sql); $sql .= ",'".$bac->cle_rib."')";
if (! $resql)
{ dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG);
$this->error=$this->db->lasterror(); $resql=$this->db->query($sql);
dol_syslog(get_class($this).'::demandeprelevement Erreur'); if (! $resql)
$error++; {
} $this->error=$this->db->lasterror();
dol_syslog(get_class($this).'::demandeprelevement Erreur');
$error++;
}
} else {
$this->error=$langs->trans('WithdrawRequestErrorNilAmount');
dol_syslog(get_class($this).'::demandeprelevement ' . $langs->trans('WithdrawRequestErrorNilAmount'));
$error++;
}
if (! $error) if (! $error)
{ {

View File

@ -478,7 +478,13 @@ if ($object->id > 0)
{ {
if ($user->rights->prelevement->bons->creer) if ($user->rights->prelevement->bons->creer)
{ {
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=new">'.$langs->trans("MakeWithdrawRequest").'</a>'; print '<form method="POST" action="">';
print '<input type="hidden" name="id" value="' . $object->id . '" />';
print '<input type="hidden" name="action" value="new" />';
print '<label for="withdraw_request_amount">' . $langs->trans('WithdrawRequestAmount') . ' </label>';
print '<input type="text" id="withdraw_request_amount" name="withdraw_request_amount" value="' . $resteapayer . '" size="10" />';
print '<input type="submit" class="butAction" value="'.$langs->trans("MakeWithdrawRequest").'" />';
print '</form>';
} }
else else
{ {

View File

@ -446,8 +446,17 @@ class BonPrelevement extends CommonObject
$fac = new Facture($this->db); $fac = new Facture($this->db);
$fac->fetch($facs[$i][0]); $fac->fetch($facs[$i][0]);
$amounts[$fac->id] = $facs[$i][1]; $amounts[$fac->id] = $facs[$i][1];
$result = $fac->set_paid($user);
$totalpaye = $fac->getSommePaiement();
$totalcreditnotes = $fac->getSumCreditNotesUsed();
$totaldeposits = $fac->getSumDepositsUsed();
$alreadypayed = $totalpaye + $totalcreditnotes + $totaldeposits;
if ($alreadypayed + $facs[$i][1] >= $fac->total_ttc) {
$result = $fac->set_paid($user);
}
} }
$paiement = new Paiement($this->db); $paiement = new Paiement($this->db);
$paiement->datepaye = $date ; $paiement->datepaye = $date ;
$paiement->amounts = $amounts; $paiement->amounts = $amounts;
@ -651,7 +660,7 @@ class BonPrelevement extends CommonObject
{ {
global $conf; global $conf;
$sql = "SELECT sum(f.total_ttc) as nb"; $sql = "SELECT sum(pfd.amount) as nb";
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f,"; $sql.= " FROM ".MAIN_DB_PREFIX."facture as f,";
$sql.= " ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd"; $sql.= " ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
//$sql.= " ,".MAIN_DB_PREFIX."c_paiement as cp"; //$sql.= " ,".MAIN_DB_PREFIX."c_paiement as cp";
@ -759,7 +768,7 @@ class BonPrelevement extends CommonObject
$factures_result = array(); $factures_result = array();
$factures_prev_id=array(); $factures_prev_id=array();
$factures_errors=array(); $factures_errors=array();
if (! $error) if (! $error)
{ {
$sql = "SELECT f.rowid, pfd.rowid as pfdrowid, f.fk_soc"; $sql = "SELECT f.rowid, pfd.rowid as pfdrowid, f.fk_soc";
@ -813,7 +822,7 @@ class BonPrelevement extends CommonObject
// Check RIB // Check RIB
$i = 0; $i = 0;
dol_syslog(__METHOD__."::Check RIB", LOG_DEBUG); dol_syslog(__METHOD__."::Check RIB", LOG_DEBUG);
if (count($factures) > 0) if (count($factures) > 0)
{ {
foreach ($factures as $key => $fac) foreach ($factures as $key => $fac)
@ -825,7 +834,7 @@ class BonPrelevement extends CommonObject
{ {
$bac = new CompanyBankAccount($this->db); $bac = new CompanyBankAccount($this->db);
$bac->fetch(0,$soc->id); $bac->fetch(0,$soc->id);
if ($bac->verif() >= 1) if ($bac->verif() >= 1)
//if (true) //if (true)
{ {
@ -924,7 +933,8 @@ class BonPrelevement extends CommonObject
if ($resql) if ($resql)
{ {
$prev_id = $this->db->last_insert_id(MAIN_DB_PREFIX."prelevement_bons"); $prev_id = $this->db->last_insert_id(MAIN_DB_PREFIX."prelevement_bons");
$this->id = $prev_id;
$dir=$conf->prelevement->dir_output.'/receipts'; $dir=$conf->prelevement->dir_output.'/receipts';
$file=$filebonprev; $file=$filebonprev;
if (! is_dir($dir)) dol_mkdir($dir); if (! is_dir($dir)) dol_mkdir($dir);
@ -981,6 +991,7 @@ class BonPrelevement extends CommonObject
dol_syslog(__METHOD__."::Update Orders::Sql=".$sql, LOG_DEBUG); dol_syslog(__METHOD__."::Update Orders::Sql=".$sql, LOG_DEBUG);
$resql=$this->db->query($sql); $resql=$this->db->query($sql);
if (! $resql) if (! $resql)
{ {
$error++; $error++;

View File

@ -161,7 +161,7 @@ print '<br>';
*/ */
$sql = "SELECT f.facnumber, f.rowid, f.total_ttc, s.nom as name, s.rowid as socid,"; $sql = "SELECT f.facnumber, f.rowid, f.total_ttc, s.nom as name, s.rowid as socid,";
$sql.= " pfd.date_demande"; $sql.= " pfd.date_demande, pfd.amount";
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f,"; $sql.= " FROM ".MAIN_DB_PREFIX."facture as f,";
$sql.= " ".MAIN_DB_PREFIX."societe as s,"; $sql.= " ".MAIN_DB_PREFIX."societe as s,";
$sql.= " ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd"; $sql.= " ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
@ -212,7 +212,7 @@ if ($resql)
print '</td>'; print '</td>';
// Amount // Amount
print '<td align="right">'; print '<td align="right">';
print price($obj->total_ttc,0,$langs,0,0,-1,$conf->currency); print price($obj->amount,0,$langs,0,0,-1,$conf->currency);
print '</td>'; print '</td>';
// Date // Date
print '<td align="right">'; print '<td align="right">';

View File

@ -96,7 +96,7 @@ print '</td></tr></table><br>';
* Invoices waiting for withdraw * Invoices waiting for withdraw
*/ */
$sql = "SELECT f.facnumber, f.rowid, f.total_ttc, f.fk_statut, f.paye, f.type,"; $sql = "SELECT f.facnumber, f.rowid, f.total_ttc, f.fk_statut, f.paye, f.type,";
$sql.= " pfd.date_demande,"; $sql.= " pfd.date_demande, pfd.amount,";
$sql.= " s.nom as name, s.rowid as socid"; $sql.= " s.nom as name, s.rowid as socid";
$sql.= " FROM ".MAIN_DB_PREFIX."facture as f,"; $sql.= " FROM ".MAIN_DB_PREFIX."facture as f,";
$sql.= " ".MAIN_DB_PREFIX."societe as s"; $sql.= " ".MAIN_DB_PREFIX."societe as s";
@ -143,7 +143,7 @@ if ($resql)
print '</td>'; print '</td>';
print '<td align="right">'; print '<td align="right">';
print price($obj->total_ttc); print price($obj->amount);
print '</td>'; print '</td>';
print '<td align="right">'; print '<td align="right">';

View File

@ -87,6 +87,8 @@ StatisticsByLineStatus=Statistics by status of lines
RUM=RUM RUM=RUM
RUMWillBeGenerated=RUM number will be generated once bank account information are saved RUMWillBeGenerated=RUM number will be generated once bank account information are saved
WithdrawMode=Withdraw mode (FRST or RECUR) WithdrawMode=Withdraw mode (FRST or RECUR)
WithdrawRequestAmount=Withdraw request amount:
WithdrawRequestErrorNilAmount=Unable to create withdraw request for nil amount.
### Notifications ### Notifications
InfoCreditSubject=Payment of standing order %s by the bank InfoCreditSubject=Payment of standing order %s by the bank

View File

@ -84,6 +84,8 @@ WithdrawalFile=Fichier de prélèvement
SetToStatusSent=Mettre au statut "Fichier envoyé" SetToStatusSent=Mettre au statut "Fichier envoyé"
ThisWillAlsoAddPaymentOnInvoice=Ceci créera également les paiements sur les factures et les classera payées ThisWillAlsoAddPaymentOnInvoice=Ceci créera également les paiements sur les factures et les classera payées
StatisticsByLineStatus=Statistiques par statut des lignes StatisticsByLineStatus=Statistiques par statut des lignes
WithdrawRequestAmount=Montant de la demande de prélèvement :
WithdrawRequestErrorNilAmount=Impossible de créer une demande de prélèvement avec un montant nul.
### Notifications ### Notifications
InfoCreditSubject=Crédit prélèvement %s à la banque InfoCreditSubject=Crédit prélèvement %s à la banque