<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class FormaMetodoPagoRepository extends EntityRepository {

    private $table = 'formas_metodos_pago';

    public function save(array $data, $table = null) {
        return parent::save($data, $this->table);
    }
    
    public function delete($id, $table = null) {
        return parent::delete($id, $this->table);
    }

    public function update($id, $data, $table = null) {
        return parent::update($id, $data, $this->table);
    }

    public function getById($id, $table = null,$selectAux = null) {
        return parent::getById($id, $this->table);
    }

    public function isUsedInRecord($id, array $buscarEn = null,$andWhere = null) {
        return parent::isUsedInRecord($id, array('pagos' => 'formaPago','cobros' => 'formaPago','ventas' => 'metodo_pago','compras' => 'metodoPago'));
    }
    
    public function getListFormasPago(){
        $query = "SELECT * FROM $this->table WHERE tipo = 'Forma pago' AND status = '1'";
        $result = $this->query($query);
        
        if($result->num_rows > 0){
            $result =  $this->resultToArray($result);           
            
            $array = array();
            foreach($result as $row){
                $array[$row['id']] = $row;
            }
            
            return $array;
        }
        
        return null;
    }
    
    public function getListSelectFormasPago(){
        $query = "SELECT * FROM $this->table WHERE tipo = 'Forma pago' AND status = '1'";
        $result = $this->query($query);
        
        if($result->num_rows > 0){
            $result =  $this->resultToArray($result);           
            
            $array = array();
            foreach($result as $row){
                $array[$row['id']] = $row['descripcion'];
            }
            
            return $array;
        }
        
        return null;
    }
    
    public function getListFormasPagoParaCierre(){
        $query = "SELECT * FROM $this->table WHERE tipo = 'Forma pago' AND status = '1' AND mostrar_en_cierre = 1";
        $result = $this->query($query);
        
        if($result->num_rows > 0){
            $result =  $this->resultToArray($result);           
            
            $array = array();
            foreach($result as $row){
                $array[$row['id']] = $row['descripcion'];
            }
            
            return $array;
        }
        
        return null;
    }
    
    public function getListMetodosPago(){
        $query = "SELECT id,descripcion FROM $this->table WHERE tipo = 'Metodo pago'";
        $result = $this->query($query);
        
        if($result){
            $array = array();
            while($row = $result->fetch_object()){
                $array[$row->id] = $row->descripcion;
            }
            
            return $array;
        }
    }
}