<?php
/**
 * gtcCostCenter business
 *
 * @author Moises Heberle [moises@solis.coop.br]
 *
 * @version $Id$
 *
 * \b Maintainers \n
 * Eduardo Bonfandini [eduardo@solis.coop.br]
 * Jamiel Spezia [jamiel@solis.coop.br]
 * Luiz Gregory Filho [luiz@solis.coop.br]
 * Moises Heberle [moises@solis.coop.br]
 * Sandro Roberto Weisheimer [sandrow@solis.coop.br]
 *
 * @since
 * Class created on 03/12/2008
 *
 * \b Organization: \n
 * SOLIS - Cooperativa de Solucoes Livres \n
 * The Gnuteca3 Development Team
 *
 * \b CopyLeft: \n
 * CopyLeft (L) 2008 SOLIS - Cooperativa de Solucoes Livres \n
 *
 * \b License: \n
 * Licensed under GPL (for further details read the COPYING file or http://www.gnu.org/copyleft/gpl.html )
 *
 * \b History: \n
 * See history in SVN repository: http://gnuteca.solis.coop.br
 */
class BusinessGnuteca3BusCostCenter extends GnutecaBusiness
{
    public $costCenterId;
    public $description;
    public $columns,
           $table       = 'gtcCostCenter',
           $pkeys       = 'costCenterId',
           $cols        = 'description';

    public function __construct()
    {
        $this->columns = "{$this->pkeys}, {$this->cols}";
        parent::__construct($this->table, $this->pkeys, $this->cols);
    }


    public function insertCostCenter()
    {
        return $this->autoInsert();
    }


    public function updateCostCenter()
    {
        return $this->autoUpdate();
    }


    public function deleteCostCenter($costCenterId)
    {
        return $this->autoDelete($costCenterId);
    }


    public function getCostCenter($costCenterId)
    {
        $this->clear();
        return $this->autoGet($costCenterId);
    }


    public function searchCostCenter($object = false)
    {
        $this->clear();
        $filters = array
        (
            'costCenterId'      => 'equals',
            'description'        => 'ilike',
        );

        return $this->autoSearch($filters, $object);
    }


    public function deleteAllCostCenter()
    {
        $rs  = $this->execute("DELETE FROM {$this->tables}");
        return $rs;
    }


    public function listCostCenter($forCatalogue = false)
    {
        //$this->clear();
        $this->setColumns($this->columns);
        $this->setTables($this->table);
        $sql = $this->select();
        $rs  = $this->query($sql);

        if(!$rs || !$forCatalogue)
        {
            return $rs;
        }

        foreach ($rs as $i => $v)
        {
            $r[$i]->option      = $v[0];
            $r[$i]->description = $v[1];
        }

        return $r;
    }

}
?>
