diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 10a8776aa38..d91352a4a1a 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -3061,13 +3061,14 @@ class Facture extends CommonInvoice /** * Create a withdrawal request for a standing order * - * @param User $user User asking standing order + * @param User $fuser User asking standing order + * @param float $amount Amount we request withdraw for * @return int <0 if KO, >0 if OK */ - function demande_prelevement($user) + function demande_prelevement($fuser, $amount=0) { global $langs; - + $error=0; dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG); @@ -3082,7 +3083,7 @@ class Facture extends CommonInvoice $sql.= ' FROM '.MAIN_DB_PREFIX.'prelevement_facture_demande'; $sql.= ' WHERE fk_facture = '.$this->id; $sql.= ' AND traite = 0'; - + dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) @@ -3101,23 +3102,21 @@ class Facture extends CommonInvoice // 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($resteapayer,$totalavoir,$conf->global->MAIN_MAX_DECIMALS_TOT); - - //$resteapayer = price2num($this->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits,'MT'); + if (empty($amount)) $amount = price2num($this->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits,'MT'); - $amount = GETPOST('withdraw_request_amount'); - - if (is_numeric($amount) && $amount != 0) { + if (is_numeric($amount) && $amount != 0) + { $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'prelevement_facture_demande'; $sql .= ' (fk_facture, amount, date_demande, fk_user_demande, code_banque, code_guichet, number, cle_rib)'; $sql .= ' VALUES ('.$this->id; $sql .= ",'".price2num($amount)."'"; $sql .= ",'".$this->db->idate($now)."'"; - $sql .= ",".$user->id; + $sql .= ",".$fuser->id; $sql .= ",'".$bac->code_banque."'"; $sql .= ",'".$bac->code_guichet."'"; $sql .= ",'".$bac->number."'"; $sql .= ",'".$bac->cle_rib."')"; - + dol_syslog(get_class($this)."::demande_prelevement", LOG_DEBUG); $resql=$this->db->query($sql); if (! $resql) @@ -3126,9 +3125,11 @@ class Facture extends CommonInvoice dol_syslog(get_class($this).'::demandeprelevement Erreur'); $error++; } - } else { - $this->error=$langs->trans('WithdrawRequestErrorNilAmount'); - dol_syslog(get_class($this).'::demandeprelevement ' . $langs->trans('WithdrawRequestErrorNilAmount')); + } + else + { + $this->error='WithdrawRequestErrorNilAmount'; + dol_syslog(get_class($this).'::demandeprelevement WithdrawRequestErrorNilAmount'); $error++; } @@ -3170,11 +3171,11 @@ class Facture extends CommonInvoice /** * Supprime une demande de prelevement * - * @param User $user utilisateur creant la demande + * @param User $fuser User making delete * @param int $did id de la demande a supprimer * @return int <0 if OK, >0 if KO */ - function demande_prelevement_delete($user, $did) + function demande_prelevement_delete($fuser, $did) { $sql = 'DELETE FROM '.MAIN_DB_PREFIX.'prelevement_facture_demande'; $sql .= ' WHERE rowid = '.$did; @@ -3195,8 +3196,8 @@ class Facture extends CommonInvoice /** * Load indicators for dashboard (this->nbtodo and this->nbtodolate) * - * @param User $user Object user - * @return WorkboardResponse|int <0 if KO, WorkboardResponse if OK + * @param User $user Object user + * @return WorkboardResponse|int <0 if KO, WorkboardResponse if OK */ function load_board($user) { diff --git a/htdocs/compta/facture/prelevement.php b/htdocs/compta/facture/prelevement.php index e5115dcfd5b..be78b422fe6 100644 --- a/htdocs/compta/facture/prelevement.php +++ b/htdocs/compta/facture/prelevement.php @@ -1,7 +1,7 @@ * Copyright (C) 2004 Eric Seigne - * Copyright (C) 2004-2014 Laurent Destailleur + * Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2010-2014 Juanjo Menent * @@ -68,14 +68,19 @@ if ($action == "new") { if ($object->id > 0) { - $result = $object->demande_prelevement($user); + $db->begin(); + + $result = $object->demande_prelevement($user, GETPOST('withdraw_request_amount')); if ($result > 0) { + $db->commit(); + setEventMessage($langs->trans("RecordSaved")); } else - { - setEventMessage($object->error, 'errors'); + { + $db->rollback(); + setEventMessage($object->error, $object->errors, 'errors'); } } $action=''; @@ -309,7 +314,7 @@ if ($object->id > 0) print ''; print ''; - // Conditions de reglement + // Payment condition print ''; print ''; @@ -514,10 +519,12 @@ if ($object->id > 0) print ''; print ''; - print ''; + print ''; print ''; print ''; - print ''; + print ''; + print ''; + print ''; print ''; $var=true; @@ -532,15 +539,18 @@ if ($object->id > 0) print ""; print '\n"; - print ''; + print ''; print ''; print ''; - print ''; print ''; - print ''; + + print ''; + print "\n"; $i++; } @@ -580,7 +590,7 @@ if ($object->id > 0) print '\n"; - print '\n"; + print ''; print ''; @@ -591,9 +601,10 @@ if ($object->id > 0) print $withdrawreceipt->getNomUrl(1); print "\n"; - print ''; - print ''; + + print '\n"; + print ''; print "\n"; diff --git a/htdocs/compta/prelevement/bons.php b/htdocs/compta/prelevement/bons.php index c2d67b4551b..177aaf72a4a 100644 --- a/htdocs/compta/prelevement/bons.php +++ b/htdocs/compta/prelevement/bons.php @@ -55,7 +55,7 @@ $pagenext = $page + 1; /* - * Mode Liste + * Mode List * */ $sql = "SELECT p.rowid, p.ref, p.amount, p.statut"; @@ -81,7 +81,7 @@ if ($result) print ''; print_liste_field_titre($langs->trans("WithdrawalsReceipts"),$_SERVER["PHP_SELF"],"p.ref",'','','class="liste_titre"'); print_liste_field_titre($langs->trans("Date"),$_SERVER["PHP_SELF"],"p.datec","","",'class="liste_titre" align="center"'); - print ''; + print_liste_field_titre($langs->trans("Amount"),$_SERVER["PHP_SELF"],"","","",'align="center"'); print ''; print ''; @@ -121,7 +121,7 @@ else dol_print_error($db); } -$db->close(); llxFooter(); +$db->close(); diff --git a/htdocs/compta/prelevement/card.php b/htdocs/compta/prelevement/card.php index 16e95402ec5..00dab9943b6 100644 --- a/htdocs/compta/prelevement/card.php +++ b/htdocs/compta/prelevement/card.php @@ -25,6 +25,7 @@ require('../../main.inc.php'); require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; @@ -45,6 +46,11 @@ if ($user->societe_id > 0) accessforbidden(); $action = GETPOST('action','alpha'); $id = GETPOST('id','int'); +$socid = GETPOST('socid','int'); +$page = GETPOST('page','int'); +$sortorder = ((GETPOST('sortorder','alpha')=="")) ? "DESC" : GETPOST('sortorder','alpha'); +$sortfield = ((GETPOST('sortfield','alpha')=="")) ? "pl.fk_soc" : GETPOST('sortfield','alpha'); + /* * Actions @@ -207,10 +213,10 @@ if ($id > 0) print '
'; print $langs->trans('PaymentConditionsShort'); @@ -370,11 +375,11 @@ if ($object->id > 0) print ''; if ($action == 'editmode') { - $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'mode_reglement_id'); + $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'mode_reglement_id'); } else { - $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'none'); + $form->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id, $object->mode_reglement_id, 'none'); } print '
'.$langs->trans("DateRequest").''.$langs->trans("DateProcess").''.$langs->trans("User").''.$langs->trans("Amount").''.$langs->trans("WithdrawalReceipt").''.$langs->trans("User").'   '.$langs->trans("DateProcess").' 
'.dol_print_date($db->jdate($obj->date_demande),'day')."'.$langs->trans("OrderWaiting").''.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.''.price($obj->amount).'-'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.' '; + + print ''.$langs->trans("OrderWaiting").''; print ''; print img_delete(); print '
'.dol_print_date($db->jdate($obj->date_demande),'day')."'.dol_print_date($db->jdate($obj->date_traite),'day')."'.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.''.price($obj->amount).''.img_object($langs->trans("ShowUser"),'user').' '.$obj->login.' '.dol_print_date($db->jdate($obj->date_traite),'day')." 
'.$langs->trans("Amount").'
'; print ''; print ''; - print ''; - print ''; /* print ''; print ''; print ''; + print ''; print ''; print ''; print ''; @@ -210,6 +217,10 @@ if ($resql) print ''; + // RUM + print ''; // Amount print '"; + + print "\n"; + print '\n"; print '\n"; diff --git a/htdocs/compta/prelevement/lignes.php b/htdocs/compta/prelevement/lignes.php deleted file mode 100644 index c4724824f36..00000000000 --- a/htdocs/compta/prelevement/lignes.php +++ /dev/null @@ -1,225 +0,0 @@ - - * Copyright (C) 2005 Laurent Destailleur - * Copyright (C) 2005-2009 Regis Houssin - * Copyright (C) 2010-2012 Juanjo Menent - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -/** - * \file htdocs/compta/prelevement/lignes.php - * \ingroup prelevement - * \brief Prelevement lines - */ - -require('../../main.inc.php'); -require_once DOL_DOCUMENT_ROOT.'/core/lib/prelevement.lib.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/ligneprelevement.class.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/rejetprelevement.class.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; -require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; - -$langs->load("banks"); -$langs->load("categories"); - -// Security check -if ($user->societe_id > 0) accessforbidden(); - -$langs->load('withdrawals'); -$langs->load('bills'); - -// Get supervariables -$prev_id = GETPOST('id','int'); -$socid = GETPOST('socid','int'); -$page = GETPOST('page','int'); -$sortorder = ((GETPOST('sortorder','alpha')=="")) ? "DESC" : GETPOST('sortorder','alpha'); -$sortfield = ((GETPOST('sortfield','alpha')=="")) ? "pl.fk_soc" : GETPOST('sortfield','alpha'); - - - -/* - * View - */ - -llxHeader('',$langs->trans("WithdrawalsReceipts")); - -if ($prev_id) -{ - $bon = new BonPrelevement($db,""); - - if ($bon->fetch($prev_id) == 0) - { - $head = prelevement_prepare_head($bon); - dol_fiche_head($head, 'lines', $langs->trans("WithdrawalsReceipts"), '', 'payment'); - - print '
'.$langs->trans("NotifyTransmision").'
'.$langs->trans("TransData").''; + print '
'.$langs->trans("TransData").''; print $form->select_date('','','','','',"userfile",1,1); print '
'.$langs->trans("TransMetod").''; + print '
'.$langs->trans("TransMetod").''; print $form->selectarray("methode",$bon->methodes_trans); print '
'.$langs->trans("File").''; @@ -230,7 +236,7 @@ if ($id > 0) print ''; print ''; print ''; - print ''; print '
'.$langs->trans("NotifyCredit").'
'.$langs->trans('CreditDate').''; + print '
'.$langs->trans('CreditDate').''; print $form->select_date('','','','','',"infocredit",1,1); print '
'; @@ -259,6 +265,122 @@ if ($id > 0) print ""; } + + + $ligne=new LignePrelevement($db,$user); + + if ($page == -1) { $page = 0 ; } + + $offset = $conf->liste_limit * $page ; + $pageprev = $page - 1; + $pagenext = $page + 1; + + /* + * Lines into withdraw request + */ + $sql = "SELECT pl.rowid, pl.statut, pl.amount"; + $sql.= ", s.rowid as socid, s.nom as name"; + $sql.= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl"; + $sql.= ", ".MAIN_DB_PREFIX."prelevement_bons as pb"; + $sql.= ", ".MAIN_DB_PREFIX."societe as s"; + $sql.= " WHERE pl.fk_prelevement_bons = ".$id; + $sql.= " AND pl.fk_prelevement_bons = pb.rowid"; + $sql.= " AND pb.entity = ".$conf->entity; + $sql.= " AND pl.fk_soc = s.rowid"; + if ($socid) $sql.= " AND s.rowid = ".$socid; + $sql.= $db->order($sortfield, $sortorder); + $sql.= $db->plimit($conf->liste_limit+1, $offset); + + $result = $db->query($sql); + + if ($result) + { + $num = $db->num_rows($result); + $i = 0; + + $urladd = "&id=".$prev_id; + + print_barre_liste("", $page, $_SERVER["PHP_SELF"], $urladd, $sortfield, $sortorder, '', $num); + print"\n\n"; + print ''; + print ''; + print_liste_field_titre($langs->trans("Lines"),$_SERVER["PHP_SELF"],"pl.rowid",'',$urladd); + print_liste_field_titre($langs->trans("ThirdParty"),$_SERVER["PHP_SELF"],"s.nom",'',$urladd); + print_liste_field_titre($langs->trans("Amount"),$_SERVER["PHP_SELF"],"pl.amount","",$urladd,'align="center"'); + print_liste_field_titre(''); + print ''; + + $var=false; + + $total = 0; + + while ($i < min($num,$conf->liste_limit)) + { + $obj = $db->fetch_object($result); + + print ""; + + print "'; + + $thirdparty=new Societe($db); + $thirdparty->fetch($obj->socid); + print '\n"; + + print '\n"; + + print ''; + + $total += $obj->total_ttc; + $var=!$var; + $i++; + } + + if($socid) + { + print ""; + + print ''; + + print '\n"; + + print ''; + + print ''; + + print "\n"; + } + + print "
"; + + print $ligne->LibStatut($obj->statut,2); + print " "; + + print ''; + print substr('000000'.$obj->rowid, -6); + print ''; + print $thirdparty->getNomUrl(1); + print "'.price($obj->amount)."'; + + if ($obj->statut == 3) + { + print ''.$langs->trans("StatusRefused").''; + } + else + { + print " "; + } + + print '
'.$langs->trans("Total").''.price($total)."  
"; + $db->free($result); + } + else + { + dol_print_error($db); + } + + + + } diff --git a/htdocs/compta/prelevement/class/bonprelevement.class.php b/htdocs/compta/prelevement/class/bonprelevement.class.php index 750b1b94db7..3f813e00938 100644 --- a/htdocs/compta/prelevement/class/bonprelevement.class.php +++ b/htdocs/compta/prelevement/class/bonprelevement.class.php @@ -446,17 +446,17 @@ class BonPrelevement extends CommonObject $fac = new Facture($this->db); $fac->fetch($facs[$i][0]); $amounts[$fac->id] = $facs[$i][1]; - + $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->datepaye = $date ; $paiement->amounts = $amounts; @@ -768,7 +768,7 @@ class BonPrelevement extends CommonObject $factures_result = array(); $factures_prev_id=array(); $factures_errors=array(); - + if (! $error) { $sql = "SELECT f.rowid, pfd.rowid as pfdrowid, f.fk_soc"; @@ -822,7 +822,7 @@ class BonPrelevement extends CommonObject // Check RIB $i = 0; dol_syslog(__METHOD__."::Check RIB", LOG_DEBUG); - + if (count($factures) > 0) { foreach ($factures as $key => $fac) @@ -834,7 +834,7 @@ class BonPrelevement extends CommonObject { $bac = new CompanyBankAccount($this->db); $bac->fetch(0,$soc->id); - + if ($bac->verif() >= 1) //if (true) { @@ -846,7 +846,7 @@ class BonPrelevement extends CommonObject else { dol_syslog(__METHOD__."::Check RIB Error on default bank number RIB/IBAN for thirdparty reported by verif() ".$fact->socid." ".$soc->name, LOG_ERR); - $this->invoice_in_error[$fac[0]]="Error on default bank number RIB/IBAN for invoice ".$fact->getNomUrl(0)." for thirdparty (reported by function verif) ".$soc->name; + $this->invoice_in_error[$fac[0]]="Error on default bank number RIB/IBAN for invoice ".$fact->getNomUrl(0)." for thirdparty (reported by function verif) ".$soc->getNomUrl(0); } } else @@ -934,7 +934,7 @@ class BonPrelevement extends CommonObject { $prev_id = $this->db->last_insert_id(MAIN_DB_PREFIX."prelevement_bons"); $this->id = $prev_id; - + $dir=$conf->prelevement->dir_output.'/receipts'; $file=$filebonprev; if (! is_dir($dir)) dol_mkdir($dir); @@ -1221,7 +1221,7 @@ class BonPrelevement extends CommonObject /** * Generate a withdrawal file. * Generation Formats: - * - Europe: SEPA (France: CFONB no more supported, Spain: AEB19 if external module EsAEB is enabled) + * - Europe: SEPA (France: CFONB no more supported, Spain: AEB19 if external module EsAEB is enabled) * - Others countries: Warning message * File is generated with name this->filename * @@ -1237,6 +1237,11 @@ class BonPrelevement extends CommonObject dol_syslog(get_class($this)."::generate build file ".$this->filename); $this->file = fopen($this->filename,"w"); + if (empty($this->file)) + { + $this->error=$langs->trans('ErrorFailedToOpenFile', $this->filename); + return -1; + } $found=0; @@ -1298,7 +1303,8 @@ class BonPrelevement extends CommonObject //echo $sql; $resql=$this->db->query($sql); if ($resql) - { $num = $this->db->num_rows($resql); + { + $num = $this->db->num_rows($resql); while ($i < $num) { $obj = $this->db->fetch_object($resql); @@ -1308,7 +1314,8 @@ class BonPrelevement extends CommonObject } } else - { fputs($this->file, 'ERREUR DEBITEUR '.$sql.$CrLf); + { + fputs($this->file, 'ERREUR DEBITEUR '.$sql.$CrLf); $result = -2; } @@ -1316,10 +1323,12 @@ class BonPrelevement extends CommonObject * section Emetteur(sepa Emetteur bloc lines) */ if ($result != -2) - { $fileEmetteurSection .= $this->EnregEmetteurSEPA($conf, $date_actu, $i, $this->total, $CrLf); + { + $fileEmetteurSection .= $this->EnregEmetteurSEPA($conf, $date_actu, $i, $this->total, $CrLf); } else - { fputs($this->file, 'ERREUR EMETTEUR'.$CrLf); + { + fputs($this->file, 'ERREUR EMETTEUR'.$CrLf); } /** @@ -1514,7 +1523,7 @@ class BonPrelevement extends CommonObject */ static function buildRumNumber($row_code_client, $row_datec, $row_drum) { - $pre = ($row_datec > 1359673200) ? 'Rum' : '++R'; + $pre = ($row_datec > 1359673200) ? 'RUM-' : '++R'; return $pre.$row_code_client.'-'.$row_drum.'-'.date('U', $row_datec); } diff --git a/htdocs/compta/prelevement/create.php b/htdocs/compta/prelevement/create.php index 5df7ed13e05..8dc81bcffd5 100644 --- a/htdocs/compta/prelevement/create.php +++ b/htdocs/compta/prelevement/create.php @@ -1,6 +1,6 @@ - * Copyright (C) 2010 Laurent Destailleur + * Copyright (C) 2010-2015 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2010-2012 Juanjo Menent * @@ -96,13 +96,19 @@ if (prelevement_check_config() < 0) print ''; } -$h=0; +/*$h=0; $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/create.php'; $head[$h][1] = $langs->trans("NewStandingOrder"); +$head[$h][2] = 'payment'; +$hselected = 'payment'; $h++; dol_fiche_head($head, $hselected, $langs->trans("StandingOrders"), 0, 'payment'); +*/ +print_barre_liste($langs->trans("NewStandingOrder"), 0, $_SERVER["PHP_SELF"]); + +dol_fiche_head(); $nb=$bprev->NbFactureAPrelever(); $nb1=$bprev->NbFactureAPrelever(1); @@ -184,6 +190,7 @@ if ($resql) print '
'.$langs->trans("Invoice").''.$langs->trans("ThirdParty").''.$langs->trans("RIB").''.$langs->trans("RUM").''.$langs->trans("AmountTTC").''.$langs->trans("DateRequest").'
'; print $thirdpartystatic->display_rib(); print ''; + print $thirdpartystatic->display_rib('rum'); + print ''; print price($obj->amount,0,$langs,0,0,-1,$conf->currency); @@ -265,11 +276,14 @@ if ($result) $obj = $db->fetch_object($result); $var=!$var; - print "
"; + print "
"; $bprev->id=$obj->rowid; $bprev->ref=$obj->ref; print $bprev->getNomUrl(1); print "'.dol_print_date($db->jdate($obj->datec),'day')."'.price($obj->amount,0,$langs,0,0,-1,$conf->currency)."
'; - - print ''; - print ''; - print ''; - - // Status - print ''; - print ''; - print ''; - - if($bon->date_trans <> 0) - { - $muser = new User($db); - $muser->fetch($bon->user_trans); - - print ''; - print ''; - } - if($bon->date_credit <> 0) - { - print ''; - } - - print '
'.$langs->trans("Ref").''.$bon->getNomUrl(1).'
'.$langs->trans("Date").''.dol_print_date($bon->datec,'day').'
'.$langs->trans("Amount").''.price($bon->amount).'
'.$langs->trans('Status').''.$bon->getLibStatut(1).'
'.$langs->trans("TransData").''; - print dol_print_date($bon->date_trans,'day'); - print ' '.$langs->trans("By").' '.$muser->getFullName($langs).'
'.$langs->trans("TransMetod").''; - print $bon->methodes_trans[$bon->method_trans]; - print '
'.$langs->trans('CreditDate').''; - print dol_print_date($bon->date_credit,'day'); - print '
'; - - print '
'; - - print '
'; - print $langs->trans("WithdrawalFile").''; - $relativepath = 'receipts/'.$bon->ref; - print ''.$relativepath.''; - print '
'; - - dol_fiche_end(); - - } - else - { - dol_print_error($db); - } -} - -$ligne=new LignePrelevement($db,$user); - -if ($page == -1) { $page = 0 ; } - -$offset = $conf->liste_limit * $page ; -$pageprev = $page - 1; -$pagenext = $page + 1; - -/* - * Liste des lignes de prelevement - */ -$sql = "SELECT pl.rowid, pl.statut, pl.amount"; -$sql.= ", s.rowid as socid, s.nom as name"; -$sql.= " FROM ".MAIN_DB_PREFIX."prelevement_lignes as pl"; -$sql.= ", ".MAIN_DB_PREFIX."prelevement_bons as pb"; -$sql.= ", ".MAIN_DB_PREFIX."societe as s"; -$sql.= " WHERE pl.fk_prelevement_bons = ".$prev_id; -$sql.= " AND pl.fk_prelevement_bons = pb.rowid"; -$sql.= " AND pb.entity = ".$conf->entity; -$sql.= " AND pl.fk_soc = s.rowid"; -if ($socid) $sql.= " AND s.rowid = ".$socid; -$sql.= " ORDER BY $sortfield $sortorder "; -$sql.= $db->plimit($conf->liste_limit+1, $offset); - -$result = $db->query($sql); - -if ($result) -{ - $num = $db->num_rows($result); - $i = 0; - - $urladd = "&id=".$prev_id; - - print_barre_liste("", $page, $_SERVER["PHP_SELF"], $urladd, $sortfield, $sortorder, '', $num); - print"\n\n"; - print ''; - print ''; - print_liste_field_titre($langs->trans("Lines"),$_SERVER["PHP_SELF"],"pl.rowid",'',$urladd); - print_liste_field_titre($langs->trans("ThirdParty"),$_SERVER["PHP_SELF"],"s.nom",'',$urladd); - print_liste_field_titre($langs->trans("Amount"),$_SERVER["PHP_SELF"],"pl.amount","",$urladd,'align="center"'); - print ''; - - $var=false; - - $total = 0; - - while ($i < min($num,$conf->liste_limit)) - { - $obj = $db->fetch_object($result); - - print "'; - - $thirdparty=new Societe($db); - $thirdparty->fetch($obj->socid); - print '\n"; - - print '\n"; - - print ''; - - $total += $obj->total_ttc; - $var=!$var; - $i++; - } - - if($socid) - { - print "'; - - print '\n"; - - print ''; - - print "\n"; - } - - print "
 
"; - - print $ligne->LibStatut($obj->statut,2); - print " "; - - print ''; - print substr('000000'.$obj->rowid, -6); - print ''; - print $thirdparty->getNomUrl(1); - print "'.price($obj->amount)."'; - - if ($obj->statut == 3) - { - print ''.$langs->trans("StatusRefused").''; - } - else - { - print " "; - } - - print '
"; - - print 'Total'.price($total)." 
"; - $db->free($result); -} -else -{ - dol_print_error($db); -} - -$db->close(); - -llxFooter(); diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 0adf708b392..75f10d812f9 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -2324,7 +2324,7 @@ class Form /** - * Charge dans cache la liste des conditions de paiements possibles + * Load into cache list of payment terms * * @return int Nb of lines loaded, <0 if KO */ @@ -2358,7 +2358,7 @@ class Form $i++; } - //$this->cache_conditions_paiements=dol_sort_array($this->cache_conditions_paiements, 'label'); // We use the sortorder + //$this->cache_conditions_paiements=dol_sort_array($this->cache_conditions_paiements, 'label', 'asc', 0, 0, 1); // We use the field sortorder of table return $num; } @@ -2403,7 +2403,7 @@ class Form $i++; } - $this->cache_availability = dol_sort_array($this->cache_availability, 'label'); + $this->cache_availability = dol_sort_array($this->cache_availability, 'label', 'asc', 0, 0, 1); return $num; } @@ -2484,7 +2484,7 @@ class Form $i++; } - $this->cache_demand_reason=dol_sort_array($tmparray, 'label', 'asc'); + $this->cache_demand_reason=dol_sort_array($tmparray, 'label', 'asc', 0, 0, 1); unset($tmparray); return $num; @@ -2547,7 +2547,9 @@ class Form dol_syslog(__METHOD__, LOG_DEBUG); - $sql = "SELECT id, code, libelle, type"; + $this->cache_types_paiements = array(); + + $sql = "SELECT id, code, libelle as label, type"; $sql.= " FROM ".MAIN_DB_PREFIX."c_paiement"; $sql.= " WHERE active > 0"; @@ -2561,14 +2563,15 @@ class Form $obj = $this->db->fetch_object($resql); // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut - $label=($langs->trans("PaymentTypeShort".$obj->code)!=("PaymentTypeShort".$obj->code)?$langs->trans("PaymentTypeShort".$obj->code):($obj->libelle!='-'?$obj->libelle:'')); + $label=($langs->transnoentitiesnoconv("PaymentTypeShort".$obj->code)!=("PaymentTypeShort".$obj->code)?$langs->transnoentitiesnoconv("PaymentTypeShort".$obj->code):($obj->label!='-'?$obj->label:'')); + $this->cache_types_paiements[$obj->id]['id'] =$obj->id; $this->cache_types_paiements[$obj->id]['code'] =$obj->code; $this->cache_types_paiements[$obj->id]['label']=$label; $this->cache_types_paiements[$obj->id]['type'] =$obj->type; $i++; } - $this->cache_types_paiements = dol_sort_array($this->cache_types_paiements, 'label'); + $this->cache_types_paiements = dol_sort_array($this->cache_types_paiements, 'label', 'asc', 0, 0, 1); return $num; } @@ -3579,7 +3582,7 @@ class Form /** - * Affiche formulaire de selection des modes de reglement + * Show form with payment mode * * @param string $page Page * @param int $selected Id mode pre-selectionne @@ -3607,6 +3610,7 @@ class Form if ($selected) { $this->load_cache_types_paiements(); + print $this->cache_types_paiements[$selected]['label']; } else { print " "; diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index cbd7d308f07..3aadf529843 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -4557,12 +4557,13 @@ function dol_htmloutput_errors($mesgstring='', $mesgarray='', $keepembedded=0) * * @param array $array Array to sort (array of array('key','otherkey1','otherkey2'...)) * @param string $index Key in array to use for sorting criteria - * @param int $order Sort order + * @param int $order Sort order ('asc' or 'desc') * @param int $natsort 1=use "natural" sort (natsort), 0=use "standard" sort (asort) * @param int $case_sensitive 1=sort is case sensitive, 0=not case sensitive + * @param int $keepindex If 0 and index key of array to sort is a numeric, than index will be rewrote. If 1 or index key is not numeric, key for index is kept after sorting. * @return array Sorted array */ -function dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0) +function dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0) { // Clean parameters $order=strtolower($order); @@ -4571,13 +4572,21 @@ function dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensiti if (is_array($array) && $sizearray>0) { foreach(array_keys($array) as $key) $temp[$key]=$array[$key][$index]; + if (!$natsort) ($order=='asc') ? asort($temp) : arsort($temp); else { ($case_sensitive) ? natsort($temp) : natcasesort($temp); if($order!='asc') $temp=array_reverse($temp,TRUE); } - foreach(array_keys($temp) as $key) (is_numeric($key))? $sorted[]=$array[$key] : $sorted[$key]=$array[$key]; + + $sorted = array(); + + foreach(array_keys($temp) as $key) + { + (is_numeric($key) && empty($keepindex)) ? $sorted[]=$array[$key] : $sorted[$key]=$array[$key]; + } + return $sorted; } return $array; diff --git a/htdocs/core/lib/prelevement.lib.php b/htdocs/core/lib/prelevement.lib.php index 18608a55a04..a575ae51bcc 100644 --- a/htdocs/core/lib/prelevement.lib.php +++ b/htdocs/core/lib/prelevement.lib.php @@ -44,11 +44,6 @@ function prelevement_prepare_head(BonPrelevement $object) $head[$h][2] = 'prelevement'; $h++; - $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/lignes.php?id='.$object->id; - $head[$h][1] = $langs->trans("Lines"); - $head[$h][2] = 'lines'; - $h++; - $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/factures.php?id='.$object->id; $head[$h][1] = $langs->trans("Bills"); $head[$h][2] = 'invoices'; diff --git a/htdocs/societe/class/companybankaccount.class.php b/htdocs/societe/class/companybankaccount.class.php index 8904d2573ed..336aab0ebbd 100644 --- a/htdocs/societe/class/companybankaccount.class.php +++ b/htdocs/societe/class/companybankaccount.class.php @@ -120,7 +120,7 @@ class CompanyBankAccount extends Account { global $conf; - if (! $this->id) + if (! $this->id) { $this->create(); } @@ -163,15 +163,15 @@ class CompanyBankAccount extends Account * Load record from database * * @param int $id Id of record - * @param int $socid Id of company + * @param int $socid Id of company. If this is filled, function will return the default RIB of company * @return int <0 if KO, >0 if OK */ - function fetch($id,$socid=0) + function fetch($id, $socid=0) { if (empty($id) && empty($socid)) return -1; $sql = "SELECT rowid, fk_soc, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,"; - $sql.= " owner_address, default_rib, label, datec, tms as datem, frstrecur"; + $sql.= " owner_address, default_rib, label, datec, tms as datem, rum, frstrecur"; $sql.= " FROM ".MAIN_DB_PREFIX."societe_rib"; if ($id) $sql.= " WHERE rowid = ".$id; if ($socid) $sql.= " WHERE fk_soc = ".$socid." AND default_rib = 1"; @@ -199,6 +199,7 @@ class CompanyBankAccount extends Account $this->default_rib = $obj->default_rib; $this->datec = $this->db->jdate($obj->datec); $this->datem = $this->db->jdate($obj->datem); + $this->rum = $obj->rum; $this->frstrecur = $obj->frstrecur; } $this->db->free($resql); diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 965727ef6e9..06b369e0141 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -2132,16 +2132,33 @@ class Societe extends CommonObject /** - * Return bank number property of thirdparty + * Return bank number property of thirdparty (label or rum) * - * @return string Bank number + * @param string $mode 'label' or 'rum' + * @return string Bank number */ - function display_rib() + function display_rib($mode='label') { require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php'; $bac = new CompanyBankAccount($this->db); $bac->fetch(0,$this->id); - return $bac->getRibLabel(true); + + if ($mode == 'label') + { + return $bac->getRibLabel(true); + } + elseif ($mode == 'rum') + { + if (empty($bac->rum)) + { + $prelevement = new BonPrelevement($this->db); + $bac->fetch_thirdparty(); + $bac->rum = $prelevement->buildRumNumber($bac->thirdparty->code_client, $bac->datec, $bac->id); + } + return $bac->rum; + } + + return 'BadParameterToFunctionDisplayRib'; } /** diff --git a/htdocs/societe/rib.php b/htdocs/societe/rib.php index d9b7df8153f..7d62059c03e 100644 --- a/htdocs/societe/rib.php +++ b/htdocs/societe/rib.php @@ -1,7 +1,7 @@ * Copyright (C) 2003 Jean-Louis Bergamo - * Copyright (C) 2004-2014 Laurent Destailleur + * Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin * Copyright (C) 2013 Peter Fontaine * Copyright (C) 2015 Marcos GarcĂ­a @@ -137,7 +137,7 @@ if ($action == 'add' && ! $_POST["cancel"]) $account->proprio = $_POST["proprio"]; $account->owner_address = $_POST["owner_address"]; $account->frstrecur = GETPOST('frstrecur'); - + $result = $account->update($user); // TODO Use create and include update into create method if (! $result) { @@ -157,7 +157,7 @@ if ($action == 'setasdefault') { $account = new CompanyBankAccount($db); $res = $account->setAsDefault(GETPOST('ribid','int')); - if ($res) + if ($res) { $url=DOL_URL_ROOT.'/societe/rib.php?socid='.$soc->id; header('Location: '.$url); @@ -230,7 +230,7 @@ if ($socid && $action == 'create' && $user->rights->societe->creer) if ($socid && $action != 'edit' && $action != "create") { dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"),0,'company'); - + // Confirm delete third party if ($action == 'delete') { @@ -396,8 +396,10 @@ if ($socid && $action != 'edit' && $action != "create") if (! empty($conf->prelevement->enabled)) { + // RUM print ''.$prelevement->buildRumNumber($soc->code_client, $rib->datec, $rib->id).''; - + + // FRSTRECUR print ''.$rib->frstrecur.''; } @@ -429,8 +431,8 @@ if ($socid && $action != 'edit' && $action != "create") print ''; print ''; } - - if (count($rib_list) == 0) + + if (count($rib_list) == 0) { $colspan=7; if (! empty($conf->prelevement->enabled)) $colspan+=2; @@ -441,7 +443,7 @@ if ($socid && $action != 'edit' && $action != "create") } else { dol_print_error($db); } - + dol_fiche_end(); } @@ -449,7 +451,7 @@ if ($socid && $action != 'edit' && $action != "create") if ($socid && $action == 'edit' && $user->rights->societe->creer) { dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"),0,'company'); - + print ''; print ''; @@ -546,20 +548,24 @@ if ($socid && $action == 'edit' && $user->rights->societe->creer) if ($conf->prelevement->enabled) { print '
'; - + print '
'.$langs->trans("LabelRIB").'
'; + if (empty($account->rum)) $account->rum = $prelevement->buildRumNumber($soc->code_client, $account->datec, $account->id); + + // RUM print ''; print ''; - + + // FRSTRECUR print ''; print ''; - + print '
'.$langs->trans("RUM").''.$account->rum.'
'.$langs->trans("WithdrawMode").'
'; } - + dol_fiche_end(); - + print '
'; print ''; print '     '; @@ -572,7 +578,7 @@ if ($socid && $action == 'edit' && $user->rights->societe->creer) if ($socid && $action == 'create' && $user->rights->societe->creer) { dol_fiche_head($head, 'rib', $langs->trans("ThirdParty"),0,'company'); - + print ''; @@ -633,27 +639,29 @@ if ($socid && $action == 'create' && $user->rights->societe->creer) print ""; print '
'; - + if ($conf->prelevement->enabled) { print '
'; - + print ''; + // RUM print ''; print ''; - + + // FRSTRECUR print ''; print ''; - + print '
'.$langs->trans("RUM").''.$langs->trans("RUMWillBeGenerated").'
'.$langs->trans("WithdrawMode").'
'; } - + dol_fiche_end(); - + print '
'; print ''; - print '     '; + print '     '; print ''; print '
'; }