diff --git a/Model/ServicioAT.php b/Model/ServicioAT.php index 085b84e..6ff9f48 100644 --- a/Model/ServicioAT.php +++ b/Model/ServicioAT.php @@ -1,7 +1,7 @@ + * Copyright (C) 2020-2026 Carlos Garcia Gomez * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Lesser General Public License as @@ -43,8 +43,8 @@ */ class ServicioAT extends ModelClass { - use ModelTrait; use CompanyRelationTrait; + use ModelTrait; /** @var string */ public $asignado; @@ -88,24 +88,24 @@ class ServicioAT extends ModelClass /** @var int */ public $idmaquina4; - /** @var int */ - public $idtipo; - /** @var int */ public $idprioridad; /** @var int */ public $idservicio; - /** @var string */ - public $material; + /** @var int */ + public $idtipo; /** @var string */ - public $nick; + public $material; /** @var double */ public $neto; + /** @var string */ + public $nick; + /** @var string */ public $observaciones; @@ -180,7 +180,9 @@ public function delete(): bool // añadimos el cambio al log $messageLog = Tools::trans('deleted-service'); - $this->log($messageLog); + if (false === $this->log($messageLog)) { + Tools::log()->error('record-save-error', ['%modelo%' => 'ServicioATLog']); + } return true; } @@ -208,19 +210,19 @@ public function getAvailablePriority(): array } /** - * @return TipoAT[] + * @return EstadoAT[] */ - public function getAvailableTypes(): array + public function getAvailableStatus(): array { - return TipoAT::all(); + return EstadoAT::all(); } /** - * @return EstadoAT[] + * @return TipoAT[] */ - public function getAvailableStatus(): array + public function getAvailableTypes(): array { - return EstadoAT::all(); + return TipoAT::all(); } public function getCustomer(?string $codcliente = null): Cliente @@ -251,14 +253,6 @@ public function getMachines(): array return $result; } - public function getStatus(?int $idestado = null): EstadoAT - { - $idestado = $idestado ?? $this->idestado; - $status = new EstadoAT(); - $status->load($idestado); - return $status; - } - public function getPriority(): PrioridadAT { $priority = new PrioridadAT(); @@ -266,11 +260,12 @@ public function getPriority(): PrioridadAT return $priority; } - public function getType(): TipoAT + public function getStatus(?int $idestado = null): EstadoAT { - $type = new TipoAT(); - $type->load($this->idtipo); - return $type; + $idestado = $idestado ?? $this->idestado; + $status = new EstadoAT(); + $status->load($idestado); + return $status; } public function getSubject(): Cliente @@ -290,6 +285,13 @@ public function getTrabajos(): array return DinTrabajoAT::all($where, $order); } + public function getType(): TipoAT + { + $type = new TipoAT(); + $type->load($this->idtipo); + return $type; + } + public function getUser(?string $nick = null): User { $nick = is_null($nick) ? $this->nick : $nick; @@ -393,6 +395,78 @@ public function url(string $type = 'auto', string $list = 'List'): string return $type === 'new' ? 'NewServicioAT' : parent::url($type, $list); } + protected function notifyAgent(string $notification): void + { + $agent = new Agente(); + if (false === $agent->load($this->codagente) || empty($agent->email)) { + return; + } + + MailNotifier::send($notification, $agent->email, $agent->nombre, [ + 'number' => $this->idservicio, + 'code' => $this->codigo, + 'date' => $this->fecha, + 'customer' => $this->getSubject()->nombre, + 'author' => $this->nick, + 'status' => $this->getStatus()->nombre, + 'url' => Tools::siteUrl() . '/EditServicioAT?code=' . $this->idservicio + ]); + } + + protected function notifyAssignedUser(string $notification): void + { + $assigned = new User(); + if (false === $assigned->load($this->asignado)) { + return; + } + + MailNotifier::send($notification, $assigned->email, $assigned->nick, [ + 'number' => $this->idservicio, + 'code' => $this->codigo, + 'date' => $this->fecha, + 'customer' => $this->getSubject()->nombre, + 'author' => $this->nick, + 'status' => $this->getStatus()->nombre, + 'url' => Tools::siteUrl() . '/EditServicioAT?code=' . $this->idservicio + ]); + } + + protected function notifyCustomer(string $notification): void + { + $customer = $this->getSubject(); + if (empty($customer) || empty($customer->email)) { + return; + } + + MailNotifier::send($notification, $customer->email, $customer->nombre, [ + 'number' => $this->idservicio, + 'code' => $this->codigo, + 'date' => $this->fecha, + 'customer' => $customer->nombre, + 'author' => $this->nick, + 'status' => $this->getStatus()->nombre, + 'url' => Tools::siteUrl() . '/EditServicioAT?code=' . $this->idservicio + ]); + } + + protected function notifyUser(string $notification): void + { + $user = new User(); + if (false === $user->load($this->nick)) { + return; + } + + MailNotifier::send($notification, $user->email, $user->nick, [ + 'number' => $this->idservicio, + 'code' => $this->codigo, + 'date' => $this->fecha, + 'customer' => $this->getSubject()->nombre, + 'author' => $this->nick, + 'status' => $this->getStatus()->nombre, + 'url' => Tools::siteUrl() . '/EditServicioAT?code=' . $this->idservicio + ]); + } + protected function onChange(string $field): bool { if ($field == 'idestado') { @@ -411,7 +485,9 @@ protected function onChange(string $field): bool '%oldStatus%' => $this->getStatus($this->getOriginal('idestado'))->nombre, '%newStatus%' => $newStatus->nombre ]); - $this->log($messageLog); + if (false === $this->log($messageLog)) { + return false; + } } return parent::onChange($field); @@ -430,8 +506,13 @@ protected function onInsert(): void $this->notifyCustomer('new-service-customer'); } - $message = Tools::trans('new-service-created', ['%number%' => $this->id()]); - $this->log($message); + $message = Tools::trans('new-service-created', [ + '%number%' => $this->id(), + '%status%' => $this->getStatus()->nombre + ]); + if (false === $this->log($message)) { + Tools::log()->error('record-save-error', ['%modelo%' => 'ServicioATLog']); + } parent::onInsert(); } @@ -560,76 +641,4 @@ protected function onUpdateUser(): void $this->notifyUser('new-service-user'); } } - - protected function notifyAgent(string $notification): void - { - $agent = new Agente(); - if (false === $agent->load($this->codagente) || empty($agent->email)) { - return; - } - - MailNotifier::send($notification, $agent->email, $agent->nombre, [ - 'number' => $this->idservicio, - 'code' => $this->codigo, - 'date' => $this->fecha, - 'customer' => $this->getSubject()->nombre, - 'author' => $this->nick, - 'status' => $this->getStatus()->nombre, - 'url' => Tools::siteUrl() . '/EditServicioAT?code=' . $this->idservicio - ]); - } - - protected function notifyAssignedUser(string $notification): void - { - $assigned = new User(); - if (false === $assigned->load($this->asignado)) { - return; - } - - MailNotifier::send($notification, $assigned->email, $assigned->nick, [ - 'number' => $this->idservicio, - 'code' => $this->codigo, - 'date' => $this->fecha, - 'customer' => $this->getSubject()->nombre, - 'author' => $this->nick, - 'status' => $this->getStatus()->nombre, - 'url' => Tools::siteUrl() . '/EditServicioAT?code=' . $this->idservicio - ]); - } - - protected function notifyCustomer(string $notification): void - { - $customer = $this->getSubject(); - if (empty($customer) || empty($customer->email)) { - return; - } - - MailNotifier::send($notification, $customer->email, $customer->nombre, [ - 'number' => $this->idservicio, - 'code' => $this->codigo, - 'date' => $this->fecha, - 'customer' => $customer->nombre, - 'author' => $this->nick, - 'status' => $this->getStatus()->nombre, - 'url' => Tools::siteUrl() . '/EditServicioAT?code=' . $this->idservicio - ]); - } - - protected function notifyUser(string $notification): void - { - $user = new User(); - if (false === $user->load($this->nick)) { - return; - } - - MailNotifier::send($notification, $user->email, $user->nick, [ - 'number' => $this->idservicio, - 'code' => $this->codigo, - 'date' => $this->fecha, - 'customer' => $this->getSubject()->nombre, - 'author' => $this->nick, - 'status' => $this->getStatus()->nombre, - 'url' => Tools::siteUrl() . '/EditServicioAT?code=' . $this->idservicio - ]); - } } diff --git a/Translation/es_ES.json b/Translation/es_ES.json index 4084436..099dd5f 100644 --- a/Translation/es_ES.json +++ b/Translation/es_ES.json @@ -27,7 +27,7 @@ "new-service-agent-body": "Hola {name}, {author} te ha asignado el servicio {number} para el cliente {customer}. Puedes ver más detalles desde aquí: {url}", "new-service-assignee": "Servicio {number} asignado", "new-service-assignee-body": "Hola {name}, {author} te ha asignado el servicio {number} para el cliente {customer}. Puedes ver más detalles desde aquí: {url}", - "new-service-created": "Servicio creado", + "new-service-created": "Servicio creado con el estado %status%", "new-service-customer": "Servicio {number} registrado", "new-service-customer-body": "Hola {name}, hemos registrado el servicio {number} para atenderte.", "new-service-p": "Para crear un servicio primero debes seleccionar o crear un cliente y después una máquina (opcional)",