Merge pull request #4736 from marcosgdf/bankcateg-oop

NEW Moved code that deals with bank categories to BankCateg. Created BankCateg::fetchAll function
This commit is contained in:
Laurent Destailleur 2016-03-12 12:01:32 +01:00
commit dca5e5278b
5 changed files with 287 additions and 416 deletions

View File

@ -5,7 +5,7 @@
* Copyright (C) 2004 Christophe Combelles <ccomb@free.fr> * Copyright (C) 2004 Christophe Combelles <ccomb@free.fr>
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2010-2011 Juanjo Menent <jmenent@@2byte.es> * Copyright (C) 2010-2011 Juanjo Menent <jmenent@@2byte.es>
* Copyright (C) 2012-2014 Marcos García <marcosgdf@gmail.com> * Copyright (C) 2012-2016 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2011-2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com> * Copyright (C) 2011-2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
* Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro> * Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
* *
@ -209,29 +209,13 @@ if ($id > 0 || ! empty($ref))
$result=$object->fetch($id, $ref); $result=$object->fetch($id, $ref);
// Chargement des categories bancaires dans $options // Load bank groups
$nbcategories=0; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/bankcateg.class.php';
$bankcateg = new BankCateg($db);
$options = array();
$sql = "SELECT rowid, label"; foreach ($bankcateg->fetchAll() as $bankcategory) {
$sql.= " FROM ".MAIN_DB_PREFIX."bank_categ"; $options[$bankcategory->id] = $bankcategory->label;
$sql.= " WHERE entity = ".$conf->entity;
$sql.= " ORDER BY label";
$result = $db->query($sql);
if ($result)
{
$var=True;
$num = $db->num_rows($result);
$i = 0;
$options = '<option value="0" selected>&nbsp;</option>';
while ($i < $num)
{
$obj = $db->fetch_object($result);
$options.= '<option value="'.$obj->rowid.'">'.$obj->label.'</option>'."\n";
$nbcategories++;
$i++;
}
$db->free($result);
} }
// Definition de sql_rech et param // Definition de sql_rech et param
@ -490,9 +474,9 @@ if ($id > 0 || ! empty($ref))
print '<input name="num_chq" class="flat" type="text" size="4" value="'.GETPOST("num_chq").'"></td>'; print '<input name="num_chq" class="flat" type="text" size="4" value="'.GETPOST("num_chq").'"></td>';
print '<td colspan="2">'; print '<td colspan="2">';
print '<input name="label" class="flat" type="text" size="24" value="'.GETPOST("label").'">'; print '<input name="label" class="flat" type="text" size="24" value="'.GETPOST("label").'">';
if ($nbcategories) if ($options) {
{ print '<br>'.$langs->trans("Rubrique").': ';
print '<br>'.$langs->trans("Rubrique").': <select class="flat" name="cat1">'.$options.'</select>'; print Form::selectarray('cat1', $options, GETPOST('cat1'), 1);
} }
print '</td>'; print '</td>';
print '<td align=right><input name="debit" class="flat" type="text" size="4" value="'.GETPOST("debit").'"></td>'; print '<td align=right><input name="debit" class="flat" type="text" size="4" value="'.GETPOST("debit").'"></td>';

View File

@ -4,6 +4,7 @@
* Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2005-2009 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2013 Charles-Fr BENKE <charles.fr@benke.fr> * Copyright (C) 2013 Charles-Fr BENKE <charles.fr@benke.fr>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr> * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -27,6 +28,7 @@
require('../../main.inc.php'); require('../../main.inc.php');
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php';
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/bankcateg.class.php';
$langs->load("banks"); $langs->load("banks");
$langs->load("categories"); $langs->load("categories");
@ -36,70 +38,39 @@ $action=GETPOST('action');
if (!$user->rights->banque->configurer) if (!$user->rights->banque->configurer)
accessforbidden(); accessforbidden();
$bankcateg = new BankCateg($db);
$categid = GETPOST('categid');
$label = GETPOST("label");
/* /*
* Add category * Add category
*/ */
if (GETPOST('add')) if (GETPOST('add'))
{ {
if (GETPOST("label")) if ($label) {
{ $bankcateg = new BankCateg($db);
$sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_categ ("; $bankcateg->label = GETPOST('label');
$sql.= "label"; $bankcateg->create($user);
$sql.= ", entity";
$sql.= ") VALUES (";
$sql.= "'".$db->escape(GETPOST("label"))."'";
$sql.= ", ".$conf->entity;
$sql.= ")";
$result = $db->query($sql);
if (!$result)
{
dol_print_error($db);
}
} }
} }
/* if ($categid) {
* Update category $bankcateg = new BankCateg($db);
*/
if (GETPOST('update'))
{
if (GETPOST("label"))
{
$sql = "UPDATE ".MAIN_DB_PREFIX."bank_categ ";
$sql.= "set label='".$db->escape(GETPOST("label"))."'";
$sql.= " WHERE rowid = '".GETPOST('categid')."'";
$sql.= " AND entity = ".$conf->entity;
$result = $db->query($sql); if ($bankcateg->fetch($categid) > 0) {
if (!$result)
{ //Update category
dol_print_error($db); if (GETPOST('update') && $label) {
$bankcateg->label = $label;
$bankcateg->update($user);
}
//Delete category
if ($action == 'delete') {
$bankcateg->delete($user);
} }
} }
} }
/*
* Action suppression catégorie
*/
if ($action == 'delete')
{
if (GETPOST('categid'))
{
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_categ";
$sql.= " WHERE rowid = '".GETPOST('categid')."'";
$sql.= " AND entity = ".$conf->entity;
$result = $db->query($sql);
if (!$result)
{
dol_print_error($db);
}
}
}
/* /*
* View * View
@ -174,5 +145,3 @@ if ($action != 'edit')
print '</table></form>'; print '</table></form>';
llxFooter(); llxFooter();
$db->close();

View File

@ -1,6 +1,7 @@
<?php <?php
/* Copyright (C) 2008 Laurent Destailleur <eldy@users.sourceforge.net> /* Copyright (C) 2008 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2009 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2009 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -17,346 +18,294 @@
*/ */
/** /**
* \file compta/bank/class/bankcateg.class.php * \file compta/bank/class/bankcateg.class.php
* \ingroup banque * \ingroup bank
* \brief This file is CRUD class file (Create/Read/Update/Delete) for bank categories * \brief This file is CRUD class file (Create/Read/Update/Delete) for bank categories
* \author Laurent Destailleur
*/ */
// Put here all includes required by your class file
//require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
//require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php';
//require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
/** /**
* Class to manage bank categories * Class to manage bank categories
*/ */
class BankCateg // extends CommonObject class BankCateg // extends CommonObject
{ {
//public $element='bank_categ'; //!< Id that identify managed objects //public $element='bank_categ'; //!< Id that identify managed objects
//public $table_element='bank_categ'; //!< Name of table without prefix where object is stored //public $table_element='bank_categ'; //!< Name of table without prefix where object is stored
var $id; public $id;
var $label; public $label;
/** /**
* Constructor * Constructor
* *
* @param DoliDB $db Database handler * @param DoliDB $db Database handler
*/ */
function __construct($db) public function __construct(DoliDB $db)
{ {
$this->db = $db; $this->db = $db;
return 1; }
}
/** /**
* Create in database * Create in database
* *
* @param User $user User that create * @param User $user User that create
* @param int $notrigger 0=launch triggers after, 1=disable triggers * @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int <0 if KO, Id of created object if OK * @return int <0 if KO, Id of created object if OK
*/ */
function create($user, $notrigger=0) public function create(User $user, $notrigger = 0)
{ {
global $conf, $langs; global $conf;
$error=0;
// Clean parameters $error = 0;
if (isset($this->label)) $this->label=trim($this->label);
// Check parameters // Clean parameters
// Put here code to add control on parameters values if (isset($this->label)) {
$this->label = trim($this->label);
}
// Insert request // Insert request
$sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_categ ("; $sql = "INSERT INTO ".MAIN_DB_PREFIX."bank_categ (";
$sql.= "label"; $sql .= "label";
$sql.= ", entity"; $sql .= ", entity";
$sql.= ") VALUES ("; $sql .= ") VALUES (";
$sql.= " ".(! isset($this->label)?'NULL':"'".$this->db->escape($this->label)."'").""; $sql .= " ".(!isset($this->label) ? 'NULL' : "'".$this->db->escape($this->label)."'")."";
$sql.= ", ".$conf->entity; $sql .= ", ".$conf->entity;
$sql.= ")"; $sql .= ")";
$this->db->begin(); $this->db->begin();
dol_syslog(get_class($this)."::create", LOG_DEBUG); dol_syslog(get_class($this)."::create", LOG_DEBUG);
$resql=$this->db->query($sql); $resql = $this->db->query($sql);
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } if (!$resql) {
$error++;
$this->errors[] = "Error ".$this->db->lasterror();
}
if (! $error) if (!$error) {
{ $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."bank_categ");
$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."bank_categ"); }
if (! $notrigger) // Commit or rollback
{ if ($error) {
// Uncomment this and change MYOBJECT to your own tag if you foreach ($this->errors as $errmsg) {
// want this action call a trigger. dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
//// Call triggers }
//include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $this->db->rollback();
//$interface=new Interfaces($this->db); return -1 * $error;
//$result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf); } else {
//if ($result < 0) { $error++; $this->errors=$interface->errors; } $this->db->commit();
//// End call triggers return $this->id;
} }
} }
// Commit or rollback
if ($error)
{
foreach($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR);
$this->error.=($this->error?', '.$errmsg:$errmsg);
}
$this->db->rollback();
return -1*$error;
}
else
{
$this->db->commit();
return $this->id;
}
}
/** /**
* Load object in memory from database * Load object in memory from database
* *
* @param int $id Id object * @param int $id Id object
* @return int <0 if KO, >0 if OK * @return int <0 if KO, >0 if OK
*/ */
function fetch($id) public function fetch($id)
{ {
global $langs,$conf; global $conf;
$sql = "SELECT"; $sql = "SELECT";
$sql.= " t.rowid,"; $sql .= " t.rowid,";
$sql.= " t.label"; $sql .= " t.label";
$sql.= " FROM ".MAIN_DB_PREFIX."bank_categ as t"; $sql .= " FROM ".MAIN_DB_PREFIX."bank_categ as t";
$sql.= " WHERE t.rowid = ".$id; $sql .= " WHERE t.rowid = ".$id;
$sql.= " AND t.entity = ".$conf->entity; $sql .= " AND t.entity = ".$conf->entity;
dol_syslog(get_class($this)."::fetch", LOG_DEBUG); dol_syslog(get_class($this)."::fetch", LOG_DEBUG);
$resql=$this->db->query($sql); $resql = $this->db->query($sql);
if ($resql) if ($resql) {
{ if ($this->db->num_rows($resql)) {
if ($this->db->num_rows($resql)) $obj = $this->db->fetch_object($resql);
{
$obj = $this->db->fetch_object($resql);
$this->id = $obj->rowid; $this->id = $obj->rowid;
$this->label = $obj->label; $this->label = $obj->label;
} }
$this->db->free($resql); $this->db->free($resql);
return 1; return 1;
} } else {
else $this->error = "Error ".$this->db->lasterror();
{ return -1;
$this->error="Error ".$this->db->lasterror(); }
return -1; }
}
}
/**
* Update database
*
* @param User $user User that modify
* @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int <0 if KO, >0 if OK
*/
public function update(User $user = null, $notrigger = 0)
{
global $conf;
$error = 0;
/** // Clean parameters
* Update database if (isset($this->label)) {
* $this->label = trim($this->label);
* @param User $user User that modify }
* @param int $notrigger 0=launch triggers after, 1=disable triggers
* @return int <0 if KO, >0 if OK
*/
function update($user=null, $notrigger=0)
{
global $conf, $langs;
$error=0;
// Clean parameters // Check parameters
if (isset($this->label)) $this->label=trim($this->label); // Put here code to add control on parameters values
// Check parameters // Update request
// Put here code to add control on parameters values $sql = "UPDATE ".MAIN_DB_PREFIX."bank_categ SET";
$sql .= " label=".(isset($this->label) ? "'".$this->db->escape($this->label)."'" : "null")."";
$sql .= " WHERE rowid=".$this->id;
$sql .= " AND entity = ".$conf->entity;
// Update request $this->db->begin();
$sql = "UPDATE ".MAIN_DB_PREFIX."bank_categ SET";
$sql.= " label=".(isset($this->label)?"'".$this->db->escape($this->label)."'":"null")."";
$sql.= " WHERE rowid=".$this->id;
$sql.= " AND entity = ".$conf->entity;
$this->db->begin(); dol_syslog(get_class($this)."::update", LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql) {
$error++;
$this->errors[] = "Error ".$this->db->lasterror();
}
dol_syslog(get_class($this)."::update", LOG_DEBUG); // Commit or rollback
$resql = $this->db->query($sql); if ($error) {
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } foreach ($this->errors as $errmsg) {
dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
$this->error .= ($this->error ? ', '.$errmsg : $errmsg);
}
$this->db->rollback();
return -1 * $error;
} else {
$this->db->commit();
return 1;
}
}
if (! $error) /**
{ * Delete object in database
if (! $notrigger) *
{ * @param User $user User that delete
// Uncomment this and change MYOBJECT to your own tag if you * @param int $notrigger 0=launch triggers after, 1=disable triggers
// want this action call a trigger. * @return int <0 if KO, >0 if OK
*/
public function delete(User $user, $notrigger = 0)
{
global $conf;
$error = 0;
//// Call triggers $sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_categ";
//include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $sql .= " WHERE rowid=".$this->id;
//$interface=new Interfaces($this->db); $sql .= " AND entity = ".$conf->entity;
//$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf);
//if ($result < 0) { $error++; $this->errors=$interface->errors; }
//// End call triggers
}
}
// Commit or rollback $this->db->begin();
if ($error)
{
foreach($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR);
$this->error.=($this->error?', '.$errmsg:$errmsg);
}
$this->db->rollback();
return -1*$error;
}
else
{
$this->db->commit();
return 1;
}
}
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql) {
$error++;
$this->errors[] = "Error ".$this->db->lasterror();
}
/** // Commit or rollback
* Delete object in database if ($error) {
* foreach ($this->errors as $errmsg) {
* @param User $user User that delete dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
* @param int $notrigger 0=launch triggers after, 1=disable triggers $this->error .= ($this->error ? ', '.$errmsg : $errmsg);
* @return int <0 if KO, >0 if OK }
*/ $this->db->rollback();
function delete($user, $notrigger=0) return -1 * $error;
{ } else {
global $conf, $langs; $this->db->commit();
$error=0; return 1;
}
}
$sql = "DELETE FROM ".MAIN_DB_PREFIX."bank_categ"; /**
$sql.= " WHERE rowid=".$this->id; * Load an object from its id and create a new one in database
$sql.= " AND entity = ".$conf->entity; *
* @param int $fromid Id of object to clone
* @return int New id of clone
*/
public function createFromClone($fromid)
{
global $user;
$this->db->begin(); $error = 0;
dol_syslog(get_class($this)."::delete", LOG_DEBUG); $object = new BankCateg($this->db);
$resql = $this->db->query($sql);
if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); }
if (! $error)
{
if (! $notrigger)
{
// Uncomment this and change MYOBJECT to your own tag if you
// want this action call a trigger.
//// Call triggers
//include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
//$interface=new Interfaces($this->db);
//$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf);
//if ($result < 0) { $error++; $this->errors=$interface->errors; }
//// End call triggers
}
}
// Commit or rollback
if ($error)
{
foreach($this->errors as $errmsg)
{
dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR);
$this->error.=($this->error?', '.$errmsg:$errmsg);
}
$this->db->rollback();
return -1*$error;
}
else
{
$this->db->commit();
return 1;
}
}
/**
* Load an object from its id and create a new one in database
*
* @param int $fromid Id of object to clone
* @return int New id of clone
*/
function createFromClone($fromid)
{
global $user,$langs;
$error=0;
$object=new BankCateg($this->db);
$object->context['createfromclone'] = 'createfromclone'; $object->context['createfromclone'] = 'createfromclone';
$this->db->begin(); $this->db->begin();
// Load source object // Load source object
$object->fetch($fromid); $object->fetch($fromid);
$object->id=0; $object->id = 0;
$object->statut=0; $object->statut = 0;
// Clear fields // Create clone
// ... $result = $object->create($user);
// Create clone // Other options
$result=$object->create($user); if ($result < 0) {
$this->error = $object->error;
$error++;
}
// Other options unset($object->context['createfromclone']);
if ($result < 0)
{
$this->error=$object->error;
$error++;
}
if (! $error) // End
{ if (!$error) {
$this->db->commit();
return $object->id;
} else {
$this->db->rollback();
return -1;
}
}
/**
* Returns all bank categories
*
* @return BankCateg[]
*/
public function fetchAll()
{
global $conf;
$return = array();
} $sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."bank_categ WHERE entity = ".$conf->entity." ORDER BY label";
$resql = $this->db->query($sql);
unset($object->context['createfromclone']); if ($resql) {
while ($obj = $this->db->fetch_object($resql)) {
$tmp = new BankCateg($this->db);
$tmp->id = $obj->rowid;
$tmp->label = $obj->label;
// End $return[] = $tmp;
if (! $error) }
{ }
$this->db->commit();
return $object->id;
}
else
{
$this->db->rollback();
return -1;
}
}
return $return;
}
/** /**
* Initialise an instance with random values. * Initialise an instance with random values.
* Used to build previews or test instances. * Used to build previews or test instances.
* id must be 0 if object instance is a specimen. * id must be 0 if object instance is a specimen.
* *
* @return void * @return void
*/ */
function initAsSpecimen() public function initAsSpecimen()
{ {
$this->id=0; $this->id = 0;
$this->label = '';
$this->label=''; }
}
} }

View File

@ -6,6 +6,7 @@
* Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com> * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com> * Copyright (C) 2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr> * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -205,24 +206,13 @@ $form = new Form($db);
llxHeader(); llxHeader();
// The list of categories is initialized // Load bank groups
$sql = "SELECT rowid, label"; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/bankcateg.class.php';
$sql.= " FROM ".MAIN_DB_PREFIX."bank_categ"; $bankcateg = new BankCateg($db);
$sql.= " ORDER BY label"; $options = array();
$result = $db->query($sql);
if ($result) foreach ($bankcateg->fetchAll() as $bankcategory) {
{ $options[$bankcategory->id] = $bankcategory->label;
$var=True;
$num = $db->num_rows($result);
$i = 0;
$options = "<option value=\"0\" selected>&nbsp;</option>";
while ($i < $num)
{
$obj = $db->fetch_object($result);
$options .= "<option value=\"$obj->rowid\">$obj->label</option>\n";
$i++;
}
$db->free($result);
} }
$var=false; $var=false;
@ -620,7 +610,7 @@ print '<table class="noborder" width="100%">';
print '<tr class="liste_titre"><td>'.$langs->trans("Rubriques").'</td><td colspan="2">'; print '<tr class="liste_titre"><td>'.$langs->trans("Rubriques").'</td><td colspan="2">';
if ($user->rights->banque->modifier) if ($user->rights->banque->modifier)
{ {
print '<select class="flat" name="cat1">'.$options.'</select>&nbsp;'; print Form::selectarray('cat1', $options, '', 1).' ';
print '<input type="submit" class="button" value="'.$langs->trans("Add").'"></td>'; print '<input type="submit" class="button" value="'.$langs->trans("Add").'"></td>';
} }
print '</tr>'; print '</tr>';

View File

@ -3,6 +3,7 @@
* Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es> * Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr> * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -111,28 +112,13 @@ if ($action == 'del')
} }
} }
require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/bankcateg.class.php';
$bankcateg = new BankCateg($db);
$options = array();
// Load bank groups foreach ($bankcateg->fetchAll() as $bankcategory) {
$sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."bank_categ ORDER BY label"; $options[$bankcategory->id] = $bankcategory->label;
$resql = $db->query($sql);
$options="";
if ($resql)
{
$var=True;
$num = $db->num_rows($resql);
if ($num > 0) $options .= '<option value="0"'.(GETPOST('cat')?'':' selected').'>&nbsp;</option>';
$i = 0;
while ($i < $num)
{
$obj = $db->fetch_object($resql);
$options .= '<option value="'.$obj->rowid.'"'.(GETPOST('cat')==$obj->rowid?' selected':'').'>'.$obj->label.'</option>'."\n";
$i++;
}
$db->free($resql);
//print $options;
} }
else dol_print_error($db);
/* /*
* View * View
@ -236,10 +222,11 @@ if ($resql)
print '<strong>'.$langs->trans("InputReceiptNumber").'</strong>: '; print '<strong>'.$langs->trans("InputReceiptNumber").'</strong>: ';
print '<input class="flat" name="num_releve" type="text" value="'.(GETPOST('num_releve')?GETPOST('num_releve'):'').'" size="10">'; // The only default value is value we just entered print '<input class="flat" name="num_releve" type="text" value="'.(GETPOST('num_releve')?GETPOST('num_releve'):'').'" size="10">'; // The only default value is value we just entered
print '<br>'; print '<br>';
if ($options) if ($options) {
{ print $langs->trans("EventualyAddCategory").': ';
print $langs->trans("EventualyAddCategory").': <select class="flat" name="cat">'.$options.'</select><br>'; print Form::selectarray('cat', $options, GETPOST('cat'), 1);
} print '<br>';
}
print '<br>'.$langs->trans("ThenCheckLinesAndConciliate").' "'.$langs->trans("Conciliate").'"<br>'; print '<br>'.$langs->trans("ThenCheckLinesAndConciliate").' "'.$langs->trans("Conciliate").'"<br>';
print '<br>'; print '<br>';
@ -440,14 +427,6 @@ if ($resql)
print '<td align="center" class="nowrap">'; print '<td align="center" class="nowrap">';
print '<input class="flat" name="rowid['.$objp->rowid.']" type="checkbox" value="'.$objp->rowid.'" size="1"'.(! empty($_POST['rowid'][$objp->rowid])?' checked':'').'>'; print '<input class="flat" name="rowid['.$objp->rowid.']" type="checkbox" value="'.$objp->rowid.'" size="1"'.(! empty($_POST['rowid'][$objp->rowid])?' checked':'').'>';
// print '<input class="flat" name="num_releve" type="text" value="'.$objp->num_releve.'" size="8">';
// print ' &nbsp; ';
// print "<input class=\"button\" type=\"submit\" value=\"".$langs->trans("Conciliate")."\">";
// if ($options)
// {
// print "<br><select class=\"flat\" name=\"cat\">$options";
// print "</select>";
// }
print "</td>"; print "</td>";
} }
else else