diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 0263395ec50..b2cd3d3dd31 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -49,9 +49,10 @@ class Categorie extends CommonObject const TYPE_MEMBER = 3; // TODO Replace this value with 'member' const TYPE_CONTACT = 4; // TODO Replace this value with 'contact' const TYPE_USER = 4; // categorie contact and user are same ! TODO Replace this value with 'user' - const TYPE_ACCOUNT = 5; // for bank account TODO Replace this value with 'account' - const TYPE_PROJECT = 6; - public $picto = 'category'; + const TYPE_ACCOUNT = 5; // TODO Replace this value with 'bank_account' + const TYPE_PROJECT = 6; + const TYPE_BANK_LINE = 'bank_line'; + public $picto = 'category'; /** @@ -1337,34 +1338,68 @@ class Categorie extends CommonObject $type = $map_type[$type]; } - $sql = "SELECT ct.fk_categorie, c.label, c.rowid"; - $sql .= " FROM " . MAIN_DB_PREFIX . "categorie_" . $this->MAP_CAT_TABLE[$type] . " as ct, " . MAIN_DB_PREFIX . "categorie as c"; - $sql .= " WHERE ct.fk_categorie = c.rowid AND ct.fk_" . $this->MAP_CAT_FK[$type] . " = " . (int) $id . " AND c.type = " . $this->MAP_ID[$type]; - $sql .= " AND c.entity IN (" . getEntity( 'category', 1 ) . ")"; - - $res = $this->db->query($sql); - if ($res) + if ($type == Categorie::TYPE_BANK_LINE) // TODO Remove this with standard category code { - while ($obj = $this->db->fetch_object($res)) - { - if ($mode == 'id') { - $cats[] = $obj->rowid; - } else if ($mode == 'label') { - $cats[] = $obj->label; - } else { - $cat = new Categorie($this->db); - $cat->fetch($obj->fk_categorie); - $cats[] = $cat; - } - } - - return $cats; - } - else - { - dol_print_error($this->db); - return -1; + // Load bank groups + $sql = "SELECT c.label, c.rowid"; + $sql.= " FROM ".MAIN_DB_PREFIX."bank_class as a, ".MAIN_DB_PREFIX."bank_categ as c"; + $sql.= " WHERE a.lineid=".$id." AND a.fk_categ = c.rowid"; + $sql.= " ORDER BY c.label"; + + $res = $this->db->query($sql); + if ($res) + { + while ($obj = $this->db->fetch_object($res)) + { + if ($mode == 'id') { + $cats[] = $obj->rowid; + } else if ($mode == 'label') { + $cats[] = $obj->label; + } else { + $cat = new Categorie($this->db); + $cat->id = $obj->rowid; + $cat->label = $obj->label; + $cats[] = $cat; + } + } + } + else + { + dol_print_error($this->db); + return -1; + } } + else + { + $sql = "SELECT ct.fk_categorie, c.label, c.rowid"; + $sql .= " FROM " . MAIN_DB_PREFIX . "categorie_" . $this->MAP_CAT_TABLE[$type] . " as ct, " . MAIN_DB_PREFIX . "categorie as c"; + $sql .= " WHERE ct.fk_categorie = c.rowid AND ct.fk_" . $this->MAP_CAT_FK[$type] . " = " . (int) $id . " AND c.type = " . $this->MAP_ID[$type]; + $sql .= " AND c.entity IN (" . getEntity( 'category', 1 ) . ")"; + + $res = $this->db->query($sql); + if ($res) + { + while ($obj = $this->db->fetch_object($res)) + { + if ($mode == 'id') { + $cats[] = $obj->rowid; + } else if ($mode == 'label') { + $cats[] = $obj->label; + } else { + $cat = new Categorie($this->db); + $cat->fetch($obj->fk_categorie); + $cats[] = $cat; + } + } + } + else + { + dol_print_error($this->db); + return -1; + } + } + + return $cats; } diff --git a/htdocs/compta/bank/ligne.php b/htdocs/compta/bank/ligne.php index 360a0d15a00..b50bf07d31a 100644 --- a/htdocs/compta/bank/ligne.php +++ b/htdocs/compta/bank/ligne.php @@ -1,7 +1,7 @@ * Copyright (C) 2003 Xavier DUTOIT - * Copyright (C) 2004-2015 Laurent Destailleur + * Copyright (C) 2004-2017 Laurent Destailleur * Copyright (C) 2004 Christophe Combelles * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2015-2017 Alexandre Spangaro @@ -30,6 +30,7 @@ require('../../main.inc.php'); require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; +require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; $langs->load("banks"); $langs->load("categories"); @@ -47,6 +48,8 @@ $action=GETPOST('action','alpha'); $confirm=GETPOST('confirm','alpha'); $rowid=GETPOST("rowid",'int'); $orig_account=GETPOST("orig_account"); +$backtopage=GETPOST('backtopage'); +$cancel=GETPOSt('cancel'); // Security check $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref :'')); @@ -59,6 +62,14 @@ if (! $user->rights->banque->lire && ! $user->rights->banque->consolidate) acces /* * Actions */ +if ($cancel) +{ + if ($backtopage) + { + header("Location: ".$backtopage); + exit; + } +} if ($user->rights->banque->consolidate && $action == 'dvnext') { @@ -81,21 +92,6 @@ if ($action == 'confirm_delete_categ' && $confirm == "yes" && $user->rights->ban } } -if ($user->rights->banque->modifier && $action == 'class') -{ - $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class WHERE lineid = ".$rowid." AND fk_categ = ".GETPOST('cat1', 'int'); - if (! $db->query($sql)) - { - dol_print_error($db); - } - - $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_class (lineid, fk_categ) VALUES (".$rowid.", ".GETPOST('cat1', 'int').")"; - if (! $db->query($sql)) - { - dol_print_error($db); - } -} - if ($user->rights->banque->modifier && $action == "update") { $error=0; @@ -145,7 +141,36 @@ if ($user->rights->banque->modifier && $action == "update") $sql.= " WHERE rowid = ".$rowid; $result = $db->query($sql); - if ($result) + if (! $result) + { + $error++; + } + + if (! $error) + { + $arrayofcategs=GETPOST('custcats', 'array'); + $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_class WHERE lineid = ".$rowid; + if (! $db->query($sql)) + { + $error++; + dol_print_error($db); + } + if (count($arrayofcategs)) + { + foreach($arrayofcategs as $val) + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_class (lineid, fk_categ) VALUES (".$rowid.", ".$val.")"; + if (! $db->query($sql)) + { + $error++; + dol_print_error($db); + } + } + // $arrayselected will be loaded after in page output + } + } + + if (! $error) { setEventMessages($langs->trans("RecordSaved"), null, 'mesgs'); $db->commit(); @@ -204,19 +229,14 @@ if ($user->rights->banque->consolidate && ($action == 'num_releve' || $action == $form = new Form($db); -llxHeader(); +llxHeader('', $langs->trans("BankTransaction")); -// Load bank groups -require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/bankcateg.class.php'; -$bankcateg = new BankCateg($db); -$options = array(); - -foreach ($bankcateg->fetchAll() as $bankcategory) { - $options[$bankcategory->id] = $bankcategory->label; +$c = new Categorie($db); +$cats = $c->containing($rowid, Categorie::TYPE_BANK_LINE); +foreach ($cats as $cat) { + $arrayselected[] = $cat->id; } -$var=false; - $tabs = array( array( DOL_URL_ROOT.'/compta/bank/ligne.php?rowid='.$rowid, @@ -300,7 +320,7 @@ if ($result) // Show links of bank transactions if (count($links)) { - print "".$langs->trans("Links").""; + print ''.$langs->trans("Links").''; print ''; foreach($links as $key=>$val) { @@ -430,7 +450,7 @@ if ($result) if ($user->rights->banque->modifier || $user->rights->banque->consolidate) { print ''; - print ''; + print ''; print ''; } else @@ -444,7 +464,7 @@ if ($result) if ($user->rights->banque->modifier || $user->rights->banque->consolidate) { print ''; - print ''; + print ''; print ''; } else @@ -498,7 +518,7 @@ if ($result) if ($user->rights->banque->modifier || $user->rights->banque->consolidate) { print ''; - print 'rappro?' disabled':'').' value="'; + print 'rappro?' disabled':'').' value="'; if (preg_match('/^\((.*)\)$/i',$objp->label,$reg)) { // Label generique car entre parentheses. On l'affiche en le traduisant @@ -508,7 +528,7 @@ if ($result) { print $objp->label; } - print '" size="50">'; + print '">'; print ''; } else @@ -532,7 +552,7 @@ if ($result) if ($user->rights->banque->modifier) { print ''; - print 'rappro?' disabled':'').' value="'.price($objp->amount).'"> '.$langs->trans("Currency".$acct->currency_code); + print 'rappro?' disabled':'').' value="'.price($objp->amount).'"> '.$langs->trans("Currency".$acct->currency_code); print ''; } else @@ -543,25 +563,41 @@ if ($result) } print ""; + // Categories + if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) + { + $langs->load('categories'); + + // Bank line + print '' . fieldLabel('RubriquesTransactions', 'custcats') . ''; + $cate_arbo = $form->select_all_categories(Categorie::TYPE_BANK_LINE, null, 'parent', null, null, 1); + print $form->multiselectarray('custcats', $cate_arbo, $arrayselected, null, null, null, null, "90%"); + print ""; + } + print ""; dol_fiche_end(); + print '

'; - + print ""; + + // Releve rappro if ($acct->canBeConciliated() > 0) // Si compte rapprochable { - print '

'."\n"; - print load_fiche_titre($langs->trans("Reconciliation"), '', 'title_bank.png'); + print '
'."\n"; + print '
'; print ''; print ''; print ''; - + print ''; + print ''; print '"; @@ -600,7 +636,15 @@ if ($result) print ''; print '
'.$langs->trans("Conciliation")."
'; - print '

'; + print '
'; + + print ''; + if ($backtopage) + { + print '   '; + print ''; + } + print '
'; print '
'; } @@ -611,55 +655,6 @@ if ($result) } else dol_print_error($db); - - -// List of bank categories -print '
'; - -print '
'; -print ''; -print ''; -print ''; - -print ''; -print ''; -} -print ''; - -$sql = "SELECT c.label, c.rowid"; -$sql.= " FROM ".MAIN_DB_PREFIX."bank_class as a, ".MAIN_DB_PREFIX."bank_categ as c"; -$sql.= " WHERE a.lineid=".$rowid." AND a.fk_categ = c.rowid"; -$sql.= " ORDER BY c.label"; -$result = $db->query($sql); -if ($result) -{ - $var=True; - $num = $db->num_rows($result); - $i = 0; $total = 0; - while ($i < $num) - { - $objp = $db->fetch_object($result); - - print ''; - - print ""; - print ""; - if ($user->rights->banque->modifier) - { - print ''; - } - print ''; - - $i++; - } - $db->free($result); -} -print '
'.$langs->trans("Rubriques").''; -if ($user->rights->banque->modifier) -{ - print Form::selectarray('cat1', $options, '', 1).' '; - print '
".$objp->label."rowid."\">".$langs->trans("ListBankTransactions")."'.img_delete($langs->trans("Remove")).'
'; - llxFooter(); $db->close(); diff --git a/htdocs/compta/bank/releve.php b/htdocs/compta/bank/releve.php index 9d9826d0729..5abbcb2512e 100644 --- a/htdocs/compta/bank/releve.php +++ b/htdocs/compta/bank/releve.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2015 Laurent Destailleur + * Copyright (C) 2004-2017 Laurent Destailleur * Copyright (C) 2005-2013 Regis Houssin * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2017 Patrick Delcroix @@ -403,8 +403,7 @@ else $objp = $db->fetch_object($result); $total = $total + $objp->amount; - $var=!$var; - print ""; + print ''; // Date operation print ''.dol_print_date($db->jdate($objp->do),"day").''; @@ -595,7 +594,7 @@ else if ($user->rights->banque->modifier || $user->rights->banque->consolidate) { - print "rowid&account=".$object->id."\">"; + print ''; print img_edit(); print ""; } diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index eba2fda5049..6bd2d3036b9 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -3395,7 +3395,7 @@ class Form */ function select_all_categories($type, $selected='', $htmlname="parent", $maxlength=64, $excludeafterid=0, $outputmode=0) { - global $langs; + global $conf, $langs; $langs->load("categories"); include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; @@ -3406,9 +3406,35 @@ class Form dol_syslog(__METHOD__ . ': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING); } - $cat = new Categorie($this->db); - $cate_arbo = $cat->get_full_arbo($type,$excludeafterid); - + if ($type == Categorie::TYPE_BANK_LINE) + { + // TODO Move this into common category feature + $categids=array(); + $sql = "SELECT c.label, c.rowid"; + $sql.= " FROM ".MAIN_DB_PREFIX."bank_categ as c"; + $sql.= " WHERE entity = ".$conf->entity; + $sql.= " ORDER BY c.label"; + $result = $this->db->query($sql); + if ($result) + { + $num = $this->db->num_rows($result); + $i = 0; + while ($i < $num) + { + $objp = $this->db->fetch_object($result); + if ($objp) $cate_arbo[$objp->rowid]=array('id'=>$objp->rowid, 'fulllabel'=>$objp->label); + $i++; + } + $this->db->free($result); + } + else dol_print_error($this->db); + } + else + { + $cat = new Categorie($this->db); + $cate_arbo = $cat->get_full_arbo($type,$excludeafterid); + } + $output = '