From bbb1c5c94254baeb634fe110423960b139a54a35 Mon Sep 17 00:00:00 2001 From: Junior-Shyko Date: Thu, 19 Dec 2024 17:33:00 -0300 Subject: [PATCH 1/4] =?UTF-8?q?=F0=9F=9A=A7=20#337=20-=20Enviando=20notifi?= =?UTF-8?q?ca=C3=A7=C3=A3o=20para=20fiscal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../modules/Diligence/Controllers/Tado.php | 2 +- .../Diligence/Entities/AnswerDiligence.php | 10 +++-- .../Entities/NotificationDiligence.php | 37 +++++++++++-------- 3 files changed, 29 insertions(+), 20 deletions(-) diff --git a/src/protected/application/lib/modules/Diligence/Controllers/Tado.php b/src/protected/application/lib/modules/Diligence/Controllers/Tado.php index 0a07cbff0..7a5f5b88f 100644 --- a/src/protected/application/lib/modules/Diligence/Controllers/Tado.php +++ b/src/protected/application/lib/modules/Diligence/Controllers/Tado.php @@ -164,6 +164,6 @@ public function sendNotificationTagoGeneration() }; $class->data = $notifi; - $notification->create($class, $msgTado); + $notification->create($class, 'diligence'); } } \ No newline at end of file diff --git a/src/protected/application/lib/modules/Diligence/Entities/AnswerDiligence.php b/src/protected/application/lib/modules/Diligence/Entities/AnswerDiligence.php index e07387998..3da46b902 100644 --- a/src/protected/application/lib/modules/Diligence/Entities/AnswerDiligence.php +++ b/src/protected/application/lib/modules/Diligence/Entities/AnswerDiligence.php @@ -2,7 +2,8 @@ namespace Diligence\Entities; use DateTime; -use \MapasCulturais\App; +use Diligence\Entities\NotificationDiligence; +use MapasCulturais\App; use MapasCulturais\Entity; use Doctrine\ORM\Mapping as ORM; use Respect\Validation\Rules\Json; @@ -89,17 +90,18 @@ public function createOrUpdate($class): string App::i()->applyHook('entity(diligence).createAnswer:before'); $repo = new DiligenceRepo(); - //Buscando a ultima diligencia da inscrição passado por parametro $lastDiligence = $repo->getIdLastDiligence($class->data['registration']); + // Notificando a pessoa fiscal + $notification = new NotificationDiligence(); + $notification->create($class, 'answer'); $answer = new AnswerDiligence(); $reg = $app->repo('Registration')->find($class->data['registration']); if($class->data['idAnswer'] > 0){ //Se tiver registro de diligência $answerDiligences = App::i()->repo('Diligence\Entities\AnswerDiligence')->find($class->data['idAnswer']); - $answerDiligences->answer = $class->data['answer']; $answerDiligences->createTimestamp = new DateTime(); $answerDiligences->registration = $reg; @@ -118,7 +120,7 @@ public function createOrUpdate($class): string $save = self::saveEntity($answer); App::i()->applyHook('entity(diligence).createAnswer', [&$answer]); - + return json_encode(['message' => 'success', 'entityId' => $save['entityId'], 'status' => 200]); } diff --git a/src/protected/application/lib/modules/Diligence/Entities/NotificationDiligence.php b/src/protected/application/lib/modules/Diligence/Entities/NotificationDiligence.php index 42c524f56..894757795 100644 --- a/src/protected/application/lib/modules/Diligence/Entities/NotificationDiligence.php +++ b/src/protected/application/lib/modules/Diligence/Entities/NotificationDiligence.php @@ -7,26 +7,27 @@ class NotificationDiligence { - public function create($class, $msgSend) + public function create($class, $type) { $app = App::i(); $notification = new Notification(); - - $agent = $app->repo('Agent')->find($class->data['agent']); - $url = $app->createUrl('inscricao', $class->data['registration']); - //Mensagem para notificação na plataforma - $numberRegis = ''.$class->data['registration'].''; - - if($msgSend == '' || $msgSend == null) - { - $msgSend = 'Um parecerista abriu uma diligência para você responder na inscrição de número: '; + $userNotifi = null; + if($type == 'diligence') { + $agent = $app->repo('Agent')->find($class->data['agent']); + $url = $app->createUrl('inscricao', $class->data['registration']); + //Mensagem para notificação na plataforma + $numberRegis = ''.$class->data['registration'].''; + $msgSend = 'Um parecerista abriu uma diligência para você responder na inscrição de número: '.$numberRegis; + $userNotifi = $agent->user; + }else{ + $dili = $app->repo('Diligence\Entities\Diligence')->findOneBy(['registration' => $class->data['registration']]); + $numberRegis = ''.$class->data['registration'].''; + $msgSend = "Houve uma resposta para prestação de conta de número: ".$numberRegis; + $userNotifi = $dili->openAgent->user; } - - $message = $msgSend . $numberRegis ; - - $notification->message = $message; - $notification->user = $agent->user; + $notification->message = $msgSend; + $notification->user = $userNotifi; $app->disableAccessControl(); $notification->save(true); @@ -49,5 +50,11 @@ public function userDestination($class) : array ]; } +// public function getNotificationAudictor($app, $class) +// { +// $dili = $app->repo('Diligence\Entities\Diligence')->findOneBy(['registration' => $class->data['registration']]); +// $numberRegis = ''.$class->data['registration'].''; +// $notification->create($class, sprintf(\MapasCulturais\i::__("Houve uma resposta da prestação de conta: ". $numberRegis))); +// } } \ No newline at end of file From 066334007eb0f2f8b8dc3c1f73344d8392f2b2e6 Mon Sep 17 00:00:00 2001 From: Junior-Shyko Date: Fri, 20 Dec 2024 10:49:41 -0300 Subject: [PATCH 2/4] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20#337=20-=20Refatorando?= =?UTF-8?q?=20classe=20de=20notificacao?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Entities/NotificationDiligence.php | 46 ++++++++++--------- 1 file changed, 25 insertions(+), 21 deletions(-) diff --git a/src/protected/application/lib/modules/Diligence/Entities/NotificationDiligence.php b/src/protected/application/lib/modules/Diligence/Entities/NotificationDiligence.php index 894757795..17ae015ab 100644 --- a/src/protected/application/lib/modules/Diligence/Entities/NotificationDiligence.php +++ b/src/protected/application/lib/modules/Diligence/Entities/NotificationDiligence.php @@ -9,26 +9,18 @@ class NotificationDiligence { public function create($class, $type) { - $app = App::i(); $notification = new Notification(); - $userNotifi = null; + // Mensagem para notificação na plataforma if($type == 'diligence') { $agent = $app->repo('Agent')->find($class->data['agent']); - $url = $app->createUrl('inscricao', $class->data['registration']); - //Mensagem para notificação na plataforma - $numberRegis = ''.$class->data['registration'].''; - $msgSend = 'Um parecerista abriu uma diligência para você responder na inscrição de número: '.$numberRegis; - $userNotifi = $agent->user; + $notification->message = $this->generateMessage($class, $type); + $notification->user = $agent->user; }else{ $dili = $app->repo('Diligence\Entities\Diligence')->findOneBy(['registration' => $class->data['registration']]); - $numberRegis = ''.$class->data['registration'].''; - $msgSend = "Houve uma resposta para prestação de conta de número: ".$numberRegis; - $userNotifi = $dili->openAgent->user; + $notification->message = $this->generateMessage($class, $type); + $notification->user = $dili->openAgent->user; } - $notification->message = $msgSend; - $notification->user = $userNotifi; - $app->disableAccessControl(); $notification->save(true); $app->enableAccessControl(); @@ -41,7 +33,7 @@ public function userDestination($class) : array $class->data['openAgent'], $class->data['agent'] ); - //Array para fila + // Array para fila return [ 'name' => $regs['agent']->name, 'email' => $regs['agent']->user->email, @@ -49,12 +41,24 @@ public function userDestination($class) : array 'days' => $regs['reg']->opportunity->getMetadata('diligence_days') ]; } - -// public function getNotificationAudictor($app, $class) -// { -// $dili = $app->repo('Diligence\Entities\Diligence')->findOneBy(['registration' => $class->data['registration']]); -// $numberRegis = ''.$class->data['registration'].''; -// $notification->create($class, sprintf(\MapasCulturais\i::__("Houve uma resposta da prestação de conta: ". $numberRegis))); -// } + /** + * Gera o contexto da mensagem para a notificação + * @param $class + * @param $type + * @return string + */ + public function generateMessage($class, $type) : string + { + $app = App::i(); + if($type == 'diligence') { + // Mensagem para o proponente + $numberRegis = ''.$class->data['registration'].''; + return 'Um parecerista abriu uma diligência para você responder na inscrição de número: '.$numberRegis; + } else { + // Mensagem para o fiscal + $numberRegis = ''.$class->data['registration'].''; + return "Houve uma resposta para prestação de conta de número: ".$numberRegis; + } + } } \ No newline at end of file From 505eb1c71c08ac74d64b871b7549a0e610ab3e87 Mon Sep 17 00:00:00 2001 From: Junior-Shyko Date: Fri, 20 Dec 2024 11:08:36 -0300 Subject: [PATCH 3/4] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20#337=20-=20adicionado?= =?UTF-8?q?=20constantes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/modules/Diligence/Controllers/Controller.php | 3 ++- .../lib/modules/Diligence/Entities/AnswerDiligence.php | 3 ++- .../application/lib/modules/Diligence/Entities/Diligence.php | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/protected/application/lib/modules/Diligence/Controllers/Controller.php b/src/protected/application/lib/modules/Diligence/Controllers/Controller.php index 6290627ef..5180e9d5b 100644 --- a/src/protected/application/lib/modules/Diligence/Controllers/Controller.php +++ b/src/protected/application/lib/modules/Diligence/Controllers/Controller.php @@ -22,6 +22,7 @@ class Controller extends \MapasCulturais\Controller implements NotificationInter const ANSWER_DRAFT = 'resposta_rascunho'; const ANSWER_SEND = 'resposta_enviada'; + /** * Salva uma diligência * @@ -120,7 +121,7 @@ public function notification(): void App::i()->applyHook('controller(diligence).notification:before'); //Notificação no Mapa Cultural $notification = new NotificationDiligence(); - $notification->create($this, ''); + $notification->create($this, EntityDiligence::TYPE_NOTIFICATION_AUDITOR); $userDestination = $notification->userDestination($this); App::i()->applyHook('controller(diligence).notification:after'); diff --git a/src/protected/application/lib/modules/Diligence/Entities/AnswerDiligence.php b/src/protected/application/lib/modules/Diligence/Entities/AnswerDiligence.php index 3da46b902..77519112d 100644 --- a/src/protected/application/lib/modules/Diligence/Entities/AnswerDiligence.php +++ b/src/protected/application/lib/modules/Diligence/Entities/AnswerDiligence.php @@ -9,6 +9,7 @@ use Respect\Validation\Rules\Json; use Diligence\Controllers\Controller; use Diligence\Service\DiligenceInterface; +use Diligence\Entities\Diligence as DiligenceEntity; use Diligence\Repositories\Diligence as DiligenceRepo; use Carbon\Carbon; @@ -95,7 +96,7 @@ public function createOrUpdate($class): string // Notificando a pessoa fiscal $notification = new NotificationDiligence(); - $notification->create($class, 'answer'); + $notification->create($class, DiligenceEntity::TYPE_NOTIFICATION_PROPONENT); $answer = new AnswerDiligence(); $reg = $app->repo('Registration')->find($class->data['registration']); diff --git a/src/protected/application/lib/modules/Diligence/Entities/Diligence.php b/src/protected/application/lib/modules/Diligence/Entities/Diligence.php index d2986cf42..88e80a0e2 100644 --- a/src/protected/application/lib/modules/Diligence/Entities/Diligence.php +++ b/src/protected/application/lib/modules/Diligence/Entities/Diligence.php @@ -35,7 +35,8 @@ class Diligence extends \MapasCulturais\Entity implements DiligenceInterface const STATUS_OPEN = 2; // Para diligencias que está em aberto const STATUS_SEND = 3; // Para diligência enviada para o proponente const STATUS_ANSWERED = 4; // Para diligências respondida pelo proponente - + const TYPE_NOTIFICATION_AUDITOR = 'diligence'; + const TYPE_NOTIFICATION_PROPONENT = 'answer'; /** * @var integer * From 6ef853b268a7ec18f1d1294454d85de32f0e5c9b Mon Sep 17 00:00:00 2001 From: Junior-Shyko Date: Fri, 20 Dec 2024 11:27:57 -0300 Subject: [PATCH 4/4] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20#337=20-=20Refatorado?= =?UTF-8?q?=20para=20notificar=20notado?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lib/modules/Diligence/Controllers/Tado.php | 4 +--- .../lib/modules/Diligence/Entities/Diligence.php | 2 ++ .../Diligence/Entities/NotificationDiligence.php | 14 ++++++++++---- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/protected/application/lib/modules/Diligence/Controllers/Tado.php b/src/protected/application/lib/modules/Diligence/Controllers/Tado.php index 7a5f5b88f..cabea1ea8 100644 --- a/src/protected/application/lib/modules/Diligence/Controllers/Tado.php +++ b/src/protected/application/lib/modules/Diligence/Controllers/Tado.php @@ -147,8 +147,6 @@ private function returnRequestJson($title, $message, $status) //Notificação via plataforma do mapa cultural ao proponente public function sendNotificationTagoGeneration() { - $msgTado = 'O TERMO DE ACEITAÇÃO DEFINITIVA DO OBJETO, foi gerado e você já pode verificar acessando o sua inscrição: Nº '; - $app = App::i(); $ag = $app->repo('Registration')->find($this->data['id']); //Inscrição, agente fiscal e agente proponente @@ -164,6 +162,6 @@ public function sendNotificationTagoGeneration() }; $class->data = $notifi; - $notification->create($class, 'diligence'); + $notification->create($class, EntityDiligence::TYPE_NOTIFICATION_TADO); } } \ No newline at end of file diff --git a/src/protected/application/lib/modules/Diligence/Entities/Diligence.php b/src/protected/application/lib/modules/Diligence/Entities/Diligence.php index 88e80a0e2..8af4e2a17 100644 --- a/src/protected/application/lib/modules/Diligence/Entities/Diligence.php +++ b/src/protected/application/lib/modules/Diligence/Entities/Diligence.php @@ -37,6 +37,8 @@ class Diligence extends \MapasCulturais\Entity implements DiligenceInterface const STATUS_ANSWERED = 4; // Para diligências respondida pelo proponente const TYPE_NOTIFICATION_AUDITOR = 'diligence'; const TYPE_NOTIFICATION_PROPONENT = 'answer'; + + const TYPE_NOTIFICATION_TADO = 'tado'; /** * @var integer * diff --git a/src/protected/application/lib/modules/Diligence/Entities/NotificationDiligence.php b/src/protected/application/lib/modules/Diligence/Entities/NotificationDiligence.php index 17ae015ab..fc0d0b946 100644 --- a/src/protected/application/lib/modules/Diligence/Entities/NotificationDiligence.php +++ b/src/protected/application/lib/modules/Diligence/Entities/NotificationDiligence.php @@ -1,6 +1,8 @@ createUrl('inscricao', $class->data['registration']).'">'.$class->data['registration'].''; + if($type == EntityDiligence::TYPE_NOTIFICATION_AUDITOR) { // Mensagem para o proponente - $numberRegis = ''.$class->data['registration'].''; return 'Um parecerista abriu uma diligência para você responder na inscrição de número: '.$numberRegis; - } else { + } + if($type == EntityDiligence::TYPE_NOTIFICATION_PROPONENT) { // Mensagem para o fiscal - $numberRegis = ''.$class->data['registration'].''; return "Houve uma resposta para prestação de conta de número: ".$numberRegis; } + if($type == EntityDiligence::TYPE_NOTIFICATION_TADO) { + // Mensagem para o proponente + return "O TERMO DE ACEITAÇÃO DEFINITIVA DO OBJETO, foi gerado e você já pode verificar acessando o sua inscrição: Nº ".$numberRegis; + } } } \ No newline at end of file