null, "user_created_id" => null, "user_updated_id" => null, "fecha_entrega_warning" => null, "fecha_entrega_warning_revised" => null, "total_tirada" => null, "total_precio" => null, "tipo_entrada" => "out", "progreso" => 0.00, "estado" => "I", "comentarios" => null, "revisar_formato" => null, "revisar_lomo" => null, "revisar_solapa" => null, "revisar_isbn" => null, "revisar_codigo_barras" => null, "realizar_imposicion" => null, "enviar_impresion" => null, "portada_path" => null, "is_pedido_espera" => null, "pedido_espera_by" => null, ]; protected $casts = [ "pedido_id" => "integer", "user_created_id" => "integer", "user_updated_id" => "?integer", "fecha_entrega_warning" => "bool", "fecha_entrega_warning_revised" => "bool", "total_tirada" => "float", "total_precio" => "float", "tipo_entrada" => "string", "progreso" => "float", "estado" => "string", "comentarios" => "string", "revisar_formato" => "bool", "revisar_lomo" => "bool", "revisar_solapa" => "bool", "revisar_isbn" => "bool", "revisar_codigo_barras" => "bool", "realizar_imposicion" => "bool", "enviar_impresion" => "bool", "portada_path" => "string", "is_pedido_espera" => "bool", ]; /** * Devuelve las tareas de la orden de trabajo. * * @return array */ public function tareas(): array { $m = model(OrdenTrabajoTarea::class); return $m->where("orden_trabajo_id", $this->attributes["id"])->findAll(); } public function tareas_impresion(): array { $m = model(OrdenTrabajoTarea::class); return $m->where("orden_trabajo_id", $this->attributes["id"])->where("presupuesto_linea_id IS NOT NULL", NULL, FALSE)->findAll() ?? []; } /** * Devuelve el presupuesto de la orden de trabajo * * @return PresupuestoEntity */ public function presupuesto(): ?PresupuestoEntity { return $this->pedido()->presupuesto(); } /** * Devuelve el pedido de la orden de trabajo * * @return PedidoEntity */ public function pedido(): ?PedidoEntity { $m = model(PedidoModel::class); return $m->find($this->attributes["pedido_id"]); } public function dates(): ?OrdenTrabajoDateEntity { $m = model(OrdenTrabajoDate::class); return $m->where('orden_trabajo_id', $this->attributes["id"])->first(); } public function users(): ?OrdenTrabajoUserEntity { $m = model(OrdenTrabajoUser::class); return $m->where('orden_trabajo_id', $this->attributes["id"])->first(); } /** * Almacena en la tabla `orden_trabajo_dates` las fechas correspondientes del pedido. * Se almacenan en una tabla externa porque puede haber modificaciones de estas fechas * en la orden del trabajo, pero en el pedido quedarĂ¡n fijas. * * @todo Falta implementacion * @return boolean */ public function storeDates($data): self { $ot_dates = new OrdenTrabajoDateEntity(); $this->attributes["dates"] = $ot_dates->fill($data); return $this; } public function getBarCode(): string { $barcode = new TypeCode128(); $renderer = new PngRenderer(); $barcodeData = $barcode->getBarcode($this->pedido()->presupuesto()->id); return base64_encode($renderer->render($barcodeData, 200, 50)); } public function getBarCodeFile() { $barcode = new TypeCode128(); $renderer = new PngRenderer(); $renderer->setBackgroundColor([255, 255, 255]); // Give a color blue for the background, default is transparent. Give it as 3 times 0-255 values for red, green and blue. $barcodeData = $barcode->getBarcode($this->pedido()->presupuesto()->id); return ($renderer->render($barcodeData, 200, 50)); } public function files(): array { $m = model(OrdenTrabajoFileModel::class); return $m->where('orden_trabajo_id', $this->attributes['id'])->findAll() ?? []; } public function pedidoEsperaBy(): ?UserEntity { $m = model(UserModel::class); if ($this->attributes['pedido_espera_by']) { return $m->findById($this->attributes['pedido_espera_by']); } else { return null; } } public function getPedidoEsperaBy(): ?UserEntity { return $this->pedidoEsperaBy(); } public function getFullPath(): ?string { helper('filesystem'); $path = WRITEPATH . 'uploads/' . $this->attributes["portada_path"]; $portada_path = null; if ($this->attributes["portada_path"]) { if ($path) { if (file_exists($path)) { $portada_path = $path; } else { $portada_path = null; } } } return $portada_path; } public function getEstadoText(): string { $estados = [ "E" => lang('Produccion.error'), "I" => lang('Produccion.iniciada'), "F" => lang('Produccion.finalizada'), "PM" => lang("Produccion.pendiente_material") ]; return $estados[$this->attributes["estado"]]; } }