diff --git a/ci4/app/Config/OrdenTrabajo.php b/ci4/app/Config/OrdenTrabajo.php index 763bad87..1d91e1d2 100644 --- a/ci4/app/Config/OrdenTrabajo.php +++ b/ci4/app/Config/OrdenTrabajo.php @@ -33,6 +33,13 @@ class OrdenTrabajo extends BaseConfig "pre_imposicion_at" => "pre_imposicion_user_id", ]; + public array $DATE_USER_MAPPING_PEDIDO = [ + "inaplazable" => "inaplazable_change_user_id", + "fecha_entrega_real" => "fecha_entrega_real_change_user_id", + "fecha_impresion" => "fecha_impresion_change_user_id", + "fecha_encuadernado" => "fecha_encuadernado_change_user_id", + "fecha_entrega_externo" => "fecha_entrega_externo_change_user_id", + ]; public function __construct() { diff --git a/ci4/app/Config/Routes.php b/ci4/app/Config/Routes.php index 36133af7..3f308c76 100644 --- a/ci4/app/Config/Routes.php +++ b/ci4/app/Config/Routes.php @@ -735,6 +735,8 @@ $routes->group('produccion', ['namespace' => 'App\Controllers\Produccion'], func *========================**/ $routes->post("update/tarea", 'Ordentrabajo::update_orden_trabajo_tarea'); $routes->post("update/date", 'Ordentrabajo::update_orden_trabajo_date'); + $routes->post("update/pedido/date", 'Ordentrabajo::update_orden_trabajo_pedido_date'); + $routes->post("update/pedido", 'Ordentrabajo::update_orden_trabajo_pedido'); $routes->post("update/user", 'Ordentrabajo::update_orden_trabajo_user'); $routes->post("update", 'Ordentrabajo::update_orden_trabajo'); $routes->post("upload/portada", 'Ordentrabajo::upload_orden_trabajo_portada'); diff --git a/ci4/app/Controllers/Produccion/Ordentrabajo.php b/ci4/app/Controllers/Produccion/Ordentrabajo.php index 54b9335d..5bbff500 100755 --- a/ci4/app/Controllers/Produccion/Ordentrabajo.php +++ b/ci4/app/Controllers/Produccion/Ordentrabajo.php @@ -118,7 +118,26 @@ class Ordentrabajo extends BaseController return $this->response->setJSON(["errors" => $this->validation->getErrors()])->setStatusCode(400); } } - + public function update_orden_trabajo_pedido_date() + { + try { + $bodyData = $this->request->getPost(); + $r = $this->produccionService->init($bodyData["orden_trabajo_id"])->updateOrdenTrabajoPedidoDate($bodyData); + return $this->response->setJSON(["message" => lang("App.global_alert_save_success"), "status" => $r["status"], "user" => $r["user"], "data" => $bodyData]); + } catch (\Throwable $th) { + return $this->response->setJSON(["errors" => $th->getMessage(), "status" => false])->setStatusCode(500); + } + } + public function update_orden_trabajo_pedido() + { + try { + $bodyData = $this->request->getPost(); + $r = $this->produccionService->init($bodyData["orden_trabajo_id"])->updateOrdenTrabajoPedido($bodyData); + return $this->response->setJSON(["message" => lang("App.global_alert_save_success"), "status" => $r,"data" => $bodyData]); + } catch (\Throwable $th) { + return $this->response->setJSON(["errors" => $th->getMessage(), "status" => false])->setStatusCode(500); + } + } public function edit($orden_trabajo_id) { // Breadcrumbs @@ -132,6 +151,8 @@ class Ordentrabajo extends BaseController $this->viewData["cliente"] = $this->produccionService->getCliente(); $this->viewData["ot"] = $this->produccionService->getOrdenTrabajo(); $this->viewData["user_dates"] = $this->produccionService->userDates(); + $this->viewData["pedido_user_dates"] = $this->produccionService->pedidoUserDates(); + return view(static::$viewPath . $this->editRoute, $this->viewData); } @@ -233,8 +254,7 @@ class Ordentrabajo extends BaseController ->edit("tiempo_estimado", fn($q) => float_seconds_to_hhmm_string($q->tiempo_estimado)) ->edit("tiempo_real", fn($q) => float_seconds_to_hhmm_string($q->tiempo_real)) ->edit("maquina_tarea", fn($q) => ["id" => $q->id, "maquina_id" => $q->maquina_tarea, "maquina_name" => $q->maquina_nombre]) - ->add("imposicion", fn($q) => ["id" => $q->id, "imposicion_id" => $q->imposicion_id, "name" => $q->imposicion_name,"is_presupuesto_linea" => $q->presupuesto_linea_id ? true : false ]) - + ->add("imposicion", fn($q) => ["id" => $q->id, "imposicion_id" => $q->imposicion_id, "name" => $q->imposicion_name, "is_presupuesto_linea" => $q->presupuesto_linea_id ? true : false]) ->toJson(true); } public function get_pdf($orden_trabajo_id) @@ -244,7 +264,6 @@ class Ordentrabajo extends BaseController public function upload_orden_trabajo_portada() { try { - //code... $file = $this->request->getFile("portada_file"); $bodyData = $this->request->getPost(); $id = $bodyData["orden_trabajo_id"]; @@ -252,6 +271,12 @@ class Ordentrabajo extends BaseController $fullpath = null; if ($file->isValid() && !$file->hasMoved()) { $fullpath = $file->store('ordenes_trabajo_portadas'); + $otEntity = $this->otModel->find($id); + if ($otEntity->portada_path) { + if (file_exists($otEntity->full_path)) { + unlink($otEntity->full_path); + } + } $r = $this->otModel->update($id, ["portada_path" => $fullpath]); } return $this->response->setJSON(["message" => "Portada subida", "data" => $r]); @@ -259,7 +284,7 @@ class Ordentrabajo extends BaseController if ($fullpath) { delete_files($fullpath); } - return $this->response->setJSON(["message" => "Portada error", "error" => $th->getMessage()])->setStatusCode($th->getCode()); + return $this->response->setJSON(["message" => "Portada error", "error" => $th->getMessage()])->setStatusCode(500); } } public function delete_orden_trabajo_portada($orden_trabajo_id) @@ -283,7 +308,7 @@ class Ordentrabajo extends BaseController try { $ot = $this->otModel->find($orden_trabajo_id); if ($ot->portada_path) { - $filePath = WRITEPATH . 'uploads/' . $ot->portada_path; + $filePath = $ot->full_path; if (file_exists($filePath)) { $mimeType = mime_content_type($filePath); diff --git a/ci4/app/Entities/Pedidos/PedidoEntity.php b/ci4/app/Entities/Pedidos/PedidoEntity.php index 61c40e25..18c55903 100644 --- a/ci4/app/Entities/Pedidos/PedidoEntity.php +++ b/ci4/app/Entities/Pedidos/PedidoEntity.php @@ -6,9 +6,11 @@ use App\Entities\Produccion\OrdenTrabajoEntity; use App\Models\OrdenTrabajo\OrdenTrabajoModel; use App\Entities\Clientes\ClienteEntity; use App\Entities\Configuracion\UbicacionesEntity; +use App\Entities\Usuarios\UserEntity; use App\Models\Clientes\ClienteModel; use App\Models\Pedidos\PedidoLineaModel; use App\Models\Presupuestos\PresupuestoModel; +use App\Models\Usuarios\UserModel; use CodeIgniter\Entity; class PedidoEntity extends \CodeIgniter\Entity\Entity @@ -40,6 +42,12 @@ class PedidoEntity extends \CodeIgniter\Entity\Entity protected $casts = [ "total_precio" => "float", "total_tirada" => "float", + "inaplazable" => "bool", + "fecha_entrega_real_change_user_id" => "?integer", + "fecha_impresion_change_user_id" => "?integer", + "fecha_encuadernado_change_user_id" => "?integer", + "fecha_entrega_change_externo_user_id" => "?integer", + "inaplazable_change_user_id" => "?integer", ]; /** * Devuelve la entidad `PedidoEntity` con sus relaciones @@ -91,4 +99,16 @@ class PedidoEntity extends \CodeIgniter\Entity\Entity $pre = $pm->find($pedido_linea->presupuesto_id); return $m->find($pre->cliente_id); } + public function userBy(string $key): ?UserEntity + { + $user = null; + if (isset($this->attributes[$key])) { + + if ($this->attributes[$key]) { + $m = model(UserModel::class); + $user = $m->find($this->attributes[$key]); + } + } + return $user; + } } diff --git a/ci4/app/Entities/Presupuestos/PresupuestoLineaEntity.php b/ci4/app/Entities/Presupuestos/PresupuestoLineaEntity.php index 247a12ec..3fa722b7 100755 --- a/ci4/app/Entities/Presupuestos/PresupuestoLineaEntity.php +++ b/ci4/app/Entities/Presupuestos/PresupuestoLineaEntity.php @@ -225,4 +225,8 @@ class PresupuestoLineaEntity extends \CodeIgniter\Entity\Entity { return in_array($this->attributes['tipo'],['lp_rot_color','lp_rot_bn']); } + public function isColor():bool { + return in_array($this->attributes['tipo'],['lp_color','lp_colorhq','lp_rot_color']); + + } } diff --git a/ci4/app/Entities/Produccion/OrdenTrabajoEntity.php b/ci4/app/Entities/Produccion/OrdenTrabajoEntity.php index e60a9671..0728d4b9 100644 --- a/ci4/app/Entities/Produccion/OrdenTrabajoEntity.php +++ b/ci4/app/Entities/Produccion/OrdenTrabajoEntity.php @@ -134,10 +134,10 @@ class OrdenTrabajoEntity extends Entity { return $this->pedidoEsperaBy(); } - public function getPortadaPath(): ?string + public function getFullPath(): ?string { helper('filesystem'); - $path = $this->attributes["portada_path"]; + $path = WRITEPATH . 'uploads/' . $this->attributes["portada_path"]; $portada_path = null; if($path){ if(file_exists($path)){ diff --git a/ci4/app/Entities/Produccion/OrdenTrabajoTareaEntity.php b/ci4/app/Entities/Produccion/OrdenTrabajoTareaEntity.php index 946b3819..883f76ad 100644 --- a/ci4/app/Entities/Produccion/OrdenTrabajoTareaEntity.php +++ b/ci4/app/Entities/Produccion/OrdenTrabajoTareaEntity.php @@ -110,7 +110,11 @@ class OrdenTrabajoTareaEntity extends Entity public function imposicion() : ?Imposicion { $m = model(ImposicionModel::class); - return $m->find($this->attributes["imposicion_id"]); + $imposicion = null; + if($this->attributes["imposicion_id"]){ + $imposicion = $m->find($this->attributes["imposicion_id"]); + } + return $imposicion; } } diff --git a/ci4/app/Language/es/Produccion.php b/ci4/app/Language/es/Produccion.php index d9719aeb..c8cb238b 100644 --- a/ci4/app/Language/es/Produccion.php +++ b/ci4/app/Language/es/Produccion.php @@ -99,7 +99,9 @@ return [ "errors" => [ - "date_not_exist" => "Esta fecha no existe en el modelo." + "date_not_exist" => "Esta fecha no existe en el modelo", + "attr_not_exist" => "El atributo {0,string} no pertenece al modelo Pedido" + ] diff --git a/ci4/app/Models/OrdenTrabajo/OrdenTrabajoDate.php b/ci4/app/Models/OrdenTrabajo/OrdenTrabajoDate.php index 9feb110a..83f62c54 100644 --- a/ci4/app/Models/OrdenTrabajo/OrdenTrabajoDate.php +++ b/ci4/app/Models/OrdenTrabajo/OrdenTrabajoDate.php @@ -5,6 +5,7 @@ namespace App\Models\OrdenTrabajo; use App\Entities\Produccion\OrdenTrabajoDateEntity; use CodeIgniter\Database\MySQLi\Builder; use CodeIgniter\Model; +use Config\OrdenTrabajo; class OrdenTrabajoDate extends Model { @@ -107,22 +108,8 @@ class OrdenTrabajoDate extends Model return $data; } public function updateUserDateMap($orden_trabajo_id,$data){ - $mapping = [ - "fecha_encuadernado_at" => "encuadernacion_user_id", - // "fecha_externo_at" => "null", - "fecha_impresion_at" => null, - "pendiente_ferro_at" => "pendiente_ferro_user_id", - "ferro_en_cliente_at" => "ferro_en_cliente_user_id", - "ferro_ok_at" => "ferro_ok_user_id", - "interior_bn_at" => "interior_bn_user_id", - "interior_color_at" => "interior_color_user_id", - "preparacion_interiores_at" => "preparacion_interior_user_id", - "cubierta_at" => "cubierta_user_id", - "plastificado_at" => "plastificado_user_id", - "corte_at" => "corte_user_id", - "embalaje_at" => "embalaje_user_id", - "entrada_manipulado_at" => "entrada_manipulado_user_id" - ]; + $ordenTrabajoConfig = new OrdenTrabajo(); + $mapping = $ordenTrabajoConfig->DATE_USER_MAPPING; $otUser = model(OrdenTrabajoUser::class); $auth_user_id = auth()->user()->id; foreach ($data as $key => $value) { diff --git a/ci4/app/Services/ProductionService.php b/ci4/app/Services/ProductionService.php index eab9ef70..ade89a42 100644 --- a/ci4/app/Services/ProductionService.php +++ b/ci4/app/Services/ProductionService.php @@ -19,6 +19,7 @@ use App\Entities\Produccion\OrdenTrabajoTareaEntity; use App\Models\Configuracion\ConfigVariableModel; use App\Models\Configuracion\MaquinaModel; use App\Models\OrdenTrabajo\OrdenTrabajoFileModel; +use App\Models\Pedidos\PedidoModel; use App\Models\Usuarios\UserModel; use CodeIgniter\Database\BaseBuilder; use CodeIgniter\Database\BaseResult; @@ -43,6 +44,7 @@ class ProductionService extends BaseService protected OrdenTrabajoUser $otUser; protected OrdenTrabajoEntity $ot; protected OrdenTrabajoFileModel $otFileModel; + protected PedidoModel $pedidoModel; protected UserModel $userModel; protected string $defaultMaquinaCorteName = 'HT-1000'; protected MaquinaEntity $defaultMaquinaCorte; @@ -70,6 +72,7 @@ class ProductionService extends BaseService $this->otUser = model(OrdenTrabajoUser::class); $this->userModel = model(UserModel::class); $this->otFileModel = model(OrdenTrabajoFileModel::class); + $this->pedidoModel = model(PedidoModel::class); $this->ordenTrabajoConfig = config('OrdenTrabajo'); } public function init(int $orden_trabajo_id): self @@ -627,6 +630,7 @@ class ProductionService extends BaseService "tareas_encuadernacion" => $this->tareas_encuadernacion(), "tareas_preimpresion" => $this->tareas_preimpresion(), "tareas_impresion" => $this->tareas_impresion(), + "tiempo_procesamiento" => $this->getTiempoProcesamientoHHMM(), ]; return $summary; } @@ -650,7 +654,9 @@ class ProductionService extends BaseService "linea_cubierta" => $this->presupuesto->presupuestoLineaCubierta(), "peso_unidad" => $logistica_data["peso_unidad"], "peso_pedido" => $logistica_data["peso_pedido"], - "imposicion" => $this->getImposicionTareaImpresion() + "imposicion" => $this->getImposicionTareaImpresion(), + "tiempo_procesamiento" => $this->getTiempoProcesamientoHHMM(), + ]; } public function getImposicionTareaImpresion(): ?Imposicion @@ -658,10 +664,10 @@ class ProductionService extends BaseService $imposicion = null; $impresionInteriorBnImposicion = $this->getTareaImpresionInteriorBn()?->imposicion(); $impresionInteriorColorImposicion = $this->getTareaImpresionInteriorColor()?->imposicion(); - if($impresionInteriorBnImposicion){ + if ($impresionInteriorBnImposicion) { $imposicion = $impresionInteriorBnImposicion; } - if($impresionInteriorColorImposicion){ + if ($impresionInteriorColorImposicion) { $imposicion = $impresionInteriorColorImposicion; } return $imposicion; @@ -755,16 +761,45 @@ class ProductionService extends BaseService } else { $result = ["user" => null, "status" => false]; } + $this->updateProgress(); return $result; } + public function updateOrdenTrabajoPedidoDate($data): array + { + $status = false; + $user = auth()->user(); + $row = []; + $pedidoDatesUser = $this->ordenTrabajoConfig->DATE_USER_MAPPING_PEDIDO; + $attrPedido = $data["name"]; + if (isset($pedidoDatesUser[$attrPedido])) { + $row[$attrPedido] = Time::createFromFormat("Y-m-d", $data[$attrPedido])->format('Y-m-d 00:00:00'); + $attrUserPedido = $pedidoDatesUser[$attrPedido]; + $row[$attrUserPedido] = $user->id; + $status = $this->pedidoModel->update($this->pedido->id, $row); + $this->updateProgress(); + } else { + throw new Exception(lang('Produccion.errors.attr_not_exist', [$attrPedido])); + } + return [ + "user" => $user, + "status" => $status + ]; + } public function updateOrdenTrabajo($data): bool { - if(isset($data["is_pedido_espera"])){ + if (isset($data["is_pedido_espera"])) { $data["pedido_espera_by"] = auth()->user()->id; } return $this->otModel->update($this->ot->id, $data); } + public function updateOrdenTrabajoPedido($data) + { + if (isset($data["inaplazable"])) { + $data[$this->ordenTrabajoConfig->DATE_USER_MAPPING_PEDIDO["inaplazable"]] = auth()->user()->id; + } + return $this->pedidoModel->update($this->pedido->id, $data); + } /**======================================================================== * RELATION METHODS *========================================================================**/ @@ -1022,18 +1057,60 @@ class ProductionService extends BaseService } return $status; } - public function userDates() : array + public function userDates(): array { $userDates = []; foreach ($this->ordenTrabajoConfig->DATE_USER_MAPPING as $key => $value) { - $otUserEntity = $this->otUser->where("orden_trabajo_id",$this->ot->id)->first(); + $otUserEntity = $this->otUser->where("orden_trabajo_id", $this->ot->id)->first(); $userEntity = $otUserEntity->userBy($value); - if($userEntity){ + if ($userEntity) { $userDates[$key] = $userEntity->full_name; - }else{ + } else { $userDates[$key] = null; } } return $userDates; } + public function pedidoUserDates(): array + { + $pedidoUserDates = []; + foreach ($this->ordenTrabajoConfig->DATE_USER_MAPPING_PEDIDO as $key => $value) { + $userEntity = $this->pedido->userBy($value); + if ($userEntity) { + $pedidoUserDates[$key] = $userEntity->full_name; + } else { + $pedidoUserDates[$key] = null; + } + } + return $pedidoUserDates; + } + public function getTiempoProcesamientoHHMM(): string + { + $time_tareas_seconds = array_map(fn($q) => $q->tiempo_estimado ?? 0, $this->ot->tareas()); + $seconds = array_sum($time_tareas_seconds); + return float_seconds_to_hhmm_string($seconds); + } + public function updateProgress(): bool + { + $userDates = $this->ordenTrabajoConfig->DATE_USER_MAPPING; + $pedidoUserDates = $this->ordenTrabajoConfig->DATE_USER_MAPPING_PEDIDO; + + $fill_dates = 0; + $status = false; + $total = count($userDates) + count($pedidoUserDates); + if ($this->ot->estado != "F") { + foreach ($userDates as $key => $value) { + if ($this->ot->dates()->{$key} != null) $fill_dates++; + } + foreach ($pedidoUserDates as $key => $value) { + if ($this->pedido->{$key} != null) $fill_dates++; + } + + $progreso = (float) $fill_dates / $total * 100; + $status = $this->otModel->update($this->ot->id, ["progreso" => round($progreso,2)]); + }else{ + $status = $this->otModel->update($this->ot->id, ["progreso" => 100]); + } + return $status; + } } diff --git a/ci4/app/Views/themes/vuexy/form/produccion/ot/otDates.php b/ci4/app/Views/themes/vuexy/form/produccion/ot/otDates.php index d569c1ec..c45bb0c8 100644 --- a/ci4/app/Views/themes/vuexy/form/produccion/ot/otDates.php +++ b/ci4/app/Views/themes/vuexy/form/produccion/ot/otDates.php @@ -15,27 +15,33 @@