<?php
namespace App\Model;


class Condicion extends GenericObject
{
    static $table_name = 'condici';

    static $primary_key = 'cnd_codigo';

    public function cargar($data){
        $this->cnd_codigo = $data->id;
        $this->cnd_descri = $data->descripcion;
        $this->cnd_lapso = $data->lapso;
    }

    public static function toJSON($result, $cn=null)
    {
        return json_encode(Condicion::toArray($result, $cn));
    }

    public static function toArray($result)
    {
        if ($result === null) return $result;
        $temp = array();
        if(!isset($result->cnd_codigo)){
            foreach($result as $item){
                $object = array(
                    "id" => $item->cnd_codigo,
                    "descripcion" => $item->cnd_descri,
                    "lapso" => $item->cnd_lapso,
                    "porcentajeVenta" => $item->cnd_porven,
                    "tipo" => $item->cnd_tipcnd,
                    "activo" => $item->cnd_desact == 0,
                );
                $temp[] = $object;
            }
        }else{
            $temp = array(
                "id" => $result->cnd_codigo,
                "descripcion" => $result->cnd_descri,
                "lapso" => $result->cnd_lapso,
                "porcentajeVenta" => $result->cnd_porven,
                "tipo" => $result->cnd_tipcnd,
                "activo" => $result->cnd_desact == 0,
            );
        }
        return $temp;
    }

}