public function __construct($c = FALSE) { parent::__construct('cajas', 'plugins/facturacion_base/'); if (!isset(self::$agentes)) { self::$agentes = array(); } if ($c) { $this->id = $this->intval($c['id']); $this->fs_id = $this->intval($c['fs_id']); $this->fecha_inicial = Date('d-m-Y H:i:s', strtotime($c['f_inicio'])); $this->dinero_inicial = floatval($c['d_inicio']); if (is_null($c['f_fin'])) { $this->fecha_fin = NULL; } else { $this->fecha_fin = Date('d-m-Y H:i:s', strtotime($c['f_fin'])); } $this->dinero_fin = floatval($c['d_fin']); $this->codagente = $c['codagente']; $this->tickets = intval($c['tickets']); $this->ip = NULL; if (isset($c['ip'])) { $this->ip = $c['ip']; } foreach (self::$agentes as $ag) { if ($ag->codagente == $this->codagente) { $this->agente = $ag; break; } } if (!isset($this->agente)) { $ag = new agente(); $this->agente = $ag->get($this->codagente); self::$agentes[] = $this->agente; } } else { $this->id = NULL; $this->fs_id = NULL; $this->codagente = NULL; $this->fecha_inicial = Date('d-m-Y H:i:s'); $this->dinero_inicial = 0; $this->fecha_fin = NULL; $this->dinero_fin = 0; $this->tickets = 0; $this->ip = NULL; if (isset($_SERVER['REMOTE_ADDR'])) { $this->ip = $_SERVER['REMOTE_ADDR']; } $this->agente = NULL; } }
/** * @param array $data * @return caja */ public function setValues($data = array()) { if (!isset(self::$agentes)) { self::$agentes = array(); } $this->id = isset($data['id']) ? $this->intval($data['id']) : null; $this->fs_id = isset($data['fs_id']) ? $this->intval($data['fs_id']) : null; $this->fecha_inicial = isset($data['f_inicio']) ? date(self::DATE_FORMAT_FULL, strtotime($data['f_inicio'])) : date(self::DATE_FORMAT_FULL); $this->dinero_inicial = isset($data['d_inicio']) ? floatval($data['d_inicio']) : 0; $this->fecha_fin = isset($data['f_fin']) && !is_null($data['f_fin']) ? date(self::DATE_FORMAT_FULL, strtotime($data['f_fin'])) : null; $this->dinero_fin = isset($data['d_fin']) && floatval($data['d_fin']) > 0.0 ? $data['d_fin'] : $this->dinero_inicial; $this->codagente = isset($data['codagente']) ? $data['codagente'] : null; $this->tickets = isset($data['tickets']) ? intval($data['tickets']) : 0; $this->ip = isset($data['ip']) ? $data['ip'] : null; $this->idasiento = isset($data['idasiento']) ? intval($data['idasiento']) : null; if (isset($_SERVER['REMOTE_ADDR'])) { $this->ip = $_SERVER['REMOTE_ADDR']; } foreach (self::$agentes as $ag) { if ($ag && $ag->codagente == $this->codagente) { $this->agente = $ag; break; } } if (!isset($this->agente)) { $ag = new agente(); $this->agente = $ag->get($this->codagente); self::$agentes[] = $this->agente; } return $this; }