Commit cbd9e9aa4862465dcd5baef049bc824196a0638a

Authored by Lucas Schmoeller da Silva
1 parent c593826d
Exists in master

Alterado processo de reservas

Colocado validações no processo, criando verificações de outras reservas no exemplar;
Adicionado filtro de tipo de reserva na listagem;
Removido links que apontavam para cadastro antigo de reservas;

portabilis/ieducar#87
ieducar/intranet/educar_reservas_lst.php
@@ -29,6 +29,7 @@ require_once ("include/clsListagem.inc.php"); @@ -29,6 +29,7 @@ require_once ("include/clsListagem.inc.php");
29 require_once ("include/clsBanco.inc.php"); 29 require_once ("include/clsBanco.inc.php");
30 require_once( "include/pmieducar/geral.inc.php" ); 30 require_once( "include/pmieducar/geral.inc.php" );
31 require_once ("include/localizacaoSistema.php"); 31 require_once ("include/localizacaoSistema.php");
  32 +require_once 'Portabilis/Date/Utils.php';
32 33
33 class clsIndexBase extends clsBase 34 class clsIndexBase extends clsBase
34 { 35 {
@@ -87,6 +88,8 @@ class indice extends clsListagem @@ -87,6 +88,8 @@ class indice extends clsListagem
87 var $ref_cod_escola; 88 var $ref_cod_escola;
88 var $cod_biblioteca; 89 var $cod_biblioteca;
89 90
  91 + var $tipo_reserva;
  92 +
90 function Gerar() 93 function Gerar()
91 { 94 {
92 @session_start(); 95 @session_start();
@@ -105,7 +108,8 @@ class indice extends clsListagem @@ -105,7 +108,8 @@ class indice extends clsListagem
105 $lista_busca = array( 108 $lista_busca = array(
106 "Cliente", 109 "Cliente",
107 "Obra", 110 "Obra",
108 - "Data Reserva" 111 + "Data Reserva",
  112 + 'Data retirada'
109 ); 113 );
110 114
111 // Filtros de Foreign Keys 115 // Filtros de Foreign Keys
@@ -126,7 +130,15 @@ class indice extends clsListagem @@ -126,7 +130,15 @@ class indice extends clsListagem
126 $this->campoOculto("ref_cod_exemplar", $this->ref_cod_exemplar); 130 $this->campoOculto("ref_cod_exemplar", $this->ref_cod_exemplar);
127 $this->campoOculto("ref_cod_acervo", $this->ref_cod_acervo); 131 $this->campoOculto("ref_cod_acervo", $this->ref_cod_acervo);
128 132
129 - $this->campoData( "data_reserva", "Data Reserva", $this->data_reserva, false ); 133 + // Filtro verificando se ouve retirada
  134 + $resources = array( 1 => 'Todas',
  135 + 2 => 'Sem retirada',
  136 + 3 => 'Com retirada');
  137 +
  138 + $options = array('label' => 'Tipo de reserva', 'resources' => $resources, 'value' => $this->tipo_reserva);
  139 + $this->inputsHelper()->select('tipo_reserva', $options);
  140 +
  141 + $this->campoData( "data_reserva", "Data reserva", $this->data_reserva, false );
130 142
131 if ($this->ref_cod_biblioteca) 143 if ($this->ref_cod_biblioteca)
132 { 144 {
@@ -162,7 +174,8 @@ class indice extends clsListagem @@ -162,7 +174,8 @@ class indice extends clsListagem
162 1, 174 1,
163 $this->ref_cod_biblioteca, 175 $this->ref_cod_biblioteca,
164 $this->ref_cod_instituicao, 176 $this->ref_cod_instituicao,
165 - $this->ref_cod_escola 177 + $this->ref_cod_escola,
  178 + ($this->tipo_reserva == 1 || is_null($this->tipo_reserva) ? null : ($this->tipo_reserva == 2 ? true : false))
166 ); 179 );
167 180
168 $total = $obj_reservas->_total; 181 $total = $obj_reservas->_total;
@@ -175,6 +188,7 @@ class indice extends clsListagem @@ -175,6 +188,7 @@ class indice extends clsListagem
175 // muda os campos data 188 // muda os campos data
176 $registro["data_reserva_time"] = strtotime( substr( $registro["data_reserva"], 0, 16 ) ); 189 $registro["data_reserva_time"] = strtotime( substr( $registro["data_reserva"], 0, 16 ) );
177 $registro["data_reserva_br"] = date( "d/m/Y", $registro["data_reserva_time"] ); 190 $registro["data_reserva_br"] = date( "d/m/Y", $registro["data_reserva_time"] );
  191 + $registro["data_retirada_br"] = ($registro["data_retirada"] == null ? '-' : Portabilis_Date_Utils::PgSqltoBr(substr($registro["data_retirada"],0,10) ));
178 192
179 // pega detalhes de foreign_keys 193 // pega detalhes de foreign_keys
180 if( class_exists( "clsPmieducarExemplar" ) ) 194 if( class_exists( "clsPmieducarExemplar" ) )
@@ -227,20 +241,21 @@ class indice extends clsListagem @@ -227,20 +241,21 @@ class indice extends clsListagem
227 } 241 }
228 242
229 $lista_busca = array( 243 $lista_busca = array(
230 - "<a href=\"educar_reservas_det.php?cod_reserva={$registro["cod_reserva"]}\">{$registro["ref_cod_cliente"]}</a>",  
231 - "<a href=\"educar_reservas_det.php?cod_reserva={$registro["cod_reserva"]}\">{$registro["ref_cod_exemplar"]}</a>",  
232 - "<a href=\"educar_reservas_det.php?cod_reserva={$registro["cod_reserva"]}\">{$registro["data_reserva_br"]}</a>" 244 + "{$registro["ref_cod_cliente"]}",
  245 + "{$registro["ref_cod_exemplar"]}",
  246 + "{$registro["data_reserva_br"]}",
  247 + "{$registro["data_retirada_br"] }"
233 ); 248 );
234 249
235 250
236 if ($qtd_bibliotecas > 1 && ($nivel_usuario == 4 || $nivel_usuario == 8)) 251 if ($qtd_bibliotecas > 1 && ($nivel_usuario == 4 || $nivel_usuario == 8))
237 - $lista_busca[] = "<a href=\"educar_reservas_det.php?cod_reserva={$registro["cod_reserva"]}\">{$registro["ref_cod_biblioteca"]}</a>"; 252 + $lista_busca[] = "{$registro["ref_cod_biblioteca"]}";
238 else if ($nivel_usuario == 1 || $nivel_usuario == 2 || $nivel_usuario == 4) 253 else if ($nivel_usuario == 1 || $nivel_usuario == 2 || $nivel_usuario == 4)
239 - $lista_busca[] = "<a href=\"educar_reservas_det.php?cod_reserva={$registro["cod_reserva"]}\">{$registro["ref_cod_biblioteca"]}</a>"; 254 + $lista_busca[] = "{$registro["ref_cod_biblioteca"]}";
240 if ($nivel_usuario == 1 || $nivel_usuario == 2) 255 if ($nivel_usuario == 1 || $nivel_usuario == 2)
241 - $lista_busca[] = "<a href=\"educar_reservas_det.php?cod_reserva={$registro["cod_reserva"]}\">{$registro["ref_cod_escola"]}</a>"; 256 + $lista_busca[] = "{$registro["ref_cod_escola"]}";
242 if ($nivel_usuario == 1) 257 if ($nivel_usuario == 1)
243 - $lista_busca[] = "<a href=\"educar_reservas_det.php?cod_reserva={$registro["cod_reserva"]}\">{$registro["ref_cod_instituicao"]}</a>"; 258 + $lista_busca[] = "{$registro["ref_cod_instituicao"]}";
244 259
245 $this->addLinhas($lista_busca); 260 $this->addLinhas($lista_busca);
246 } 261 }
@@ -249,7 +264,7 @@ class indice extends clsListagem @@ -249,7 +264,7 @@ class indice extends clsListagem
249 $obj_permissoes = new clsPermissoes(); 264 $obj_permissoes = new clsPermissoes();
250 if( $obj_permissoes->permissao_cadastra( 609, $this->pessoa_logada, 11 ) ) 265 if( $obj_permissoes->permissao_cadastra( 609, $this->pessoa_logada, 11 ) )
251 { 266 {
252 - $this->acao = "go(\"educar_reservas_login_cad.php\")"; 267 + $this->acao = "go(\"/module/Biblioteca/Reserva\")";
253 $this->nome_acao = "Novo"; 268 $this->nome_acao = "Novo";
254 } 269 }
255 270
ieducar/intranet/include/pmieducar/clsPmieducarReservas.inc.php
@@ -390,7 +390,7 @@ class clsPmieducarReservas @@ -390,7 +390,7 @@ class clsPmieducarReservas
390 * 390 *
391 * @return array 391 * @return array
392 */ 392 */
393 - function lista( $int_cod_reserva = null, $int_ref_usuario_libera = null, $int_ref_usuario_cad = null, $int_ref_cod_cliente = null, $date_data_reserva_ini = null, $date_data_reserva_fim = null, $date_data_prevista_disponivel_ini = null, $date_data_prevista_disponivel_fim = null, $date_data_retirada_ini = null, $date_data_retirada_fim = null, $int_ref_cod_exemplar = null, $int_ativo = null, $int_ref_cod_biblioteca = null, $int_ref_cod_instituicao = null, $int_ref_cod_escola = null, $data_retirada_null = false ) 393 + function lista( $int_cod_reserva = null, $int_ref_usuario_libera = null, $int_ref_usuario_cad = null, $int_ref_cod_cliente = null, $date_data_reserva_ini = null, $date_data_reserva_fim = null, $date_data_prevista_disponivel_ini = null, $date_data_prevista_disponivel_fim = null, $date_data_retirada_ini = null, $date_data_retirada_fim = null, $int_ref_cod_exemplar = null, $int_ativo = null, $int_ref_cod_biblioteca = null, $int_ref_cod_instituicao = null, $int_ref_cod_escola = null, $data_retirada_null = null )
394 { 394 {
395 $sql = "SELECT {$this->_campos_lista}, a.ref_cod_biblioteca, b.ref_cod_instituicao, b.ref_cod_escola FROM {$this->_tabela} r, {$this->_schema}exemplar e, {$this->_schema}acervo a, {$this->_schema}biblioteca b"; 395 $sql = "SELECT {$this->_campos_lista}, a.ref_cod_biblioteca, b.ref_cod_instituicao, b.ref_cod_escola FROM {$this->_tabela} r, {$this->_schema}exemplar e, {$this->_schema}acervo a, {$this->_schema}biblioteca b";
396 396
@@ -478,11 +478,16 @@ class clsPmieducarReservas @@ -478,11 +478,16 @@ class clsPmieducarReservas
478 $whereAnd = " AND "; 478 $whereAnd = " AND ";
479 } 479 }
480 480
481 - if($data_retirada_null)  
482 - {  
483 - $filtros .= "{$whereAnd} r.data_retirada is null";  
484 - $whereAnd = " AND ";  
485 - } 481 + if(!is_null($data_retirada_null)){
  482 + if($data_retirada_null)
  483 + {
  484 + $filtros .= "{$whereAnd} r.data_retirada is null";
  485 + $whereAnd = " AND ";
  486 + }else{
  487 + $filtros .= "{$whereAnd} r.data_retirada is not null";
  488 + $whereAnd = " AND ";
  489 + }
  490 + }
486 491
487 $db = new clsBanco(); 492 $db = new clsBanco();
488 $countCampos = count( explode( ",", $this->_campos_lista ) ); 493 $countCampos = count( explode( ",", $this->_campos_lista ) );
ieducar/modules/Biblioteca/Views/EmprestimoApiController.php
@@ -229,7 +229,7 @@ class EmprestimoApiController extends ApiCoreController @@ -229,7 +229,7 @@ class EmprestimoApiController extends ApiCoreController
229 null, 229 null,
230 null, 230 null,
231 null, 231 null,
232 - $exemplar['cod_exemplar'], 232 + $exemplar['id'],
233 1, 233 1,
234 $this->getRequest()->biblioteca_id, 234 $this->getRequest()->biblioteca_id,
235 $this->getRequest()->instituicao_id, 235 $this->getRequest()->instituicao_id,
@@ -364,9 +364,48 @@ class EmprestimoApiController extends ApiCoreController @@ -364,9 +364,48 @@ class EmprestimoApiController extends ApiCoreController
364 if (is_null($exemplar)) 364 if (is_null($exemplar))
365 $exemplar = $this->loadExemplar(); 365 $exemplar = $this->loadExemplar();
366 366
  367 + if ($exemplar['situacao']['flag'] == 'reservado')
  368 + $exemplar['situacao']['flag'] = $this->validateReservaOfExemplar($exemplar);
  369 +
367 return $exemplar['situacao']; 370 return $exemplar['situacao'];
368 } 371 }
369 372
  373 + // Verifica se há reservas para o exemplar
  374 + // Efetua retirada da reserva caso seja para o cliente em questão
  375 + protected function validateReservaOfExemplar($exemplar = null){
  376 + if (is_null($exemplar))
  377 + $exemplar = $this->loadExemplar();
  378 +
  379 + $reservas = $this->loadReservasForExemplar($exemplar);
  380 + $cont = 0;
  381 + $clientePossuiReserva = false;
  382 + $codReserva = 0;
  383 + if (is_array($reservas) && count($reservas)){
  384 + foreach ($reservas as $registro) {
  385 + $cont;
  386 + if ($registro['cliente_id'] == $this->getRequest()->cliente_id){
  387 + $clientePossuiReserva = true;
  388 + $codReserva = $registro['id'];
  389 + break;
  390 + }
  391 + }
  392 + }
  393 + if ($clientePossuiReserva){
  394 + if ($cont==1){
  395 + $reservas = new clsPmieducarReservas($codReserva);
  396 + $reservas->data_retirada = date('Y-m-d H:i:s');
  397 + $reservas->edita();
  398 + }else{
  399 +
  400 + $this->messenger->append("Outros clientes já haviam reservado o exemplar anteriormente.".$cont, 'success');
  401 + }
  402 + }else if($cont>0){
  403 + $this->messenger->append("Outros clientes já haviam reservado o exemplar.", 'success');
  404 + }
  405 +
  406 + return 'disponivel';
  407 + }
  408 +
370 409
371 protected function getPendenciasForExemplar($exemplar) { 410 protected function getPendenciasForExemplar($exemplar) {
372 if (! isset($exemplar['situacao'])) 411 if (! isset($exemplar['situacao']))