<?php
namespace App\Model;


class Comprobante extends GenericObject
{
    static $table_name = 'comproba';

    static $primary_key = 'cpb_codigo';

    public function cargar($data){
        $this->cpb_codigo = $data->id;
        $this->cpb_descri = $data->descripcion;
        $this->cpb_tipcpb = $data->tipoComprobante;
        $this->cpb_tipmov = $data->tipoMovimiento;
    }

    public static function toJSON($result)
    {
        if ($result === null) return $result;
        $temp = array();
        if(!isset($result->cpb_codigo)){
            foreach($result as $item){
                $object = array(
                    "id" => $item->cpb_codigo,
                    "descripcion" => $item->cpb_descri,
                    "tipoComprobante" => $item->cpb_tipcpb,
                    "tipoMovimiento" => $item->cpb_tipmov
                );
                $temp[] = $object;
            }
        }else{
            $temp = array(
                "id" => $result->cpb_codigo,
                "descripcion" => $result->cpb_descri,
                "tipoComprobante" => $result->cpb_tipcpb,
                "tipoMovimiento" => $result->cpb_tipmov
            );
        }
        return json_encode($temp);
    }

}