mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
fechas pedido and imposiciones
This commit is contained in:
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user