Skip to content
Snippets Groups Projects

Hotline#14092 Pergame Hold Doctype Issue

Merged Patrick Barroca requested to merge hotline#14092-pergame-hold-doctype-issue into hotline_6.46
Compare and
+ 476
218
Preferences
Compare changes
Files
@@ -18,19 +18,14 @@
* along with AFI-OPAC 2.0; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// OPAC3: Specifique Pergame
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class Class_Systeme_PergameService
{
class Class_Systeme_PergameService {
use Trait_TimeSource;
private $user;
//------------------------------------------------------------------------------------------------------
// Constructeur
//------------------------------------------------------------------------------------------------------
function __construct($user) {
$this->user=$user;
public function __construct($user) {
$this->user = $user;
}
@@ -38,14 +33,11 @@ class Class_Systeme_PergameService
return $this->user;
}
//------------------------------------------------------------------------------------------------------
// Nombre de prets en retard
//------------------------------------------------------------------------------------------------------
public function getNbPretsEnRetard()
{
$date=date("Y-m-d");
$req="select count(*) from prets where IDABON='".$this->user->IDABON."' and ORDREABON=".$this->user->ORDREABON." and EN_COURS=1 and DATE_RETOUR < '$date'";
$nb_retard=fetchOne($req);
public function getNbPretsEnRetard() {
$date = date('Y-m-d');
$req = 'select count(*) from prets where IDABON=\'' . $this->user->IDABON . '\' and ORDREABON=' . $this->user->ORDREABON . ' and EN_COURS=1 and DATE_RETOUR < \'' . $date .'\'';
$nb_retard = fetchOne($req);
return $nb_retard;
}
@@ -55,30 +47,22 @@ class Class_Systeme_PergameService
return null;
}
//------------------------------------------------------------------------------------------------------
// Nombre de prets en cours
//------------------------------------------------------------------------------------------------------
public function getNbEmprunts()
{
$nb_prets=fetchOne("select count(*) from prets where IDABON='".$this->user->IDABON."' and ORDREABON=".$this->user->ORDREABON." and EN_COURS=1");
public function getNbEmprunts() {
$nb_prets = fetchOne("select count(*) from prets where IDABON='".$this->user->IDABON."' and ORDREABON=".$this->user->ORDREABON." and EN_COURS=1");
return $nb_prets;
}
//------------------------------------------------------------------------------------------------------
// Nombre de reservations
//------------------------------------------------------------------------------------------------------
public function getNbReservations()
{
public function getNbReservations() {
$nb_resas=fetchOne("select count(*) from reservations where IDABON='".$this->user->IDABON."' and ORDREABON=".$this->user->ORDREABON);
return $nb_resas;
}
//------------------------------------------------------------------------------------------------------
// Liste des prets en cours
//------------------------------------------------------------------------------------------------------
public function getPrets()
{
public function getPrets() {
$data=fetchAll("select * from prets where IDABON='".$this->user->IDABON."' and ORDREABON=".$this->user->ORDREABON." and EN_COURS=1");
if(!$data) return array();
$date_ref=date("Y-m-d");
foreach($data as $ligne)
@@ -95,11 +79,7 @@ class Class_Systeme_PergameService
}
//------------------------------------------------------------------------------------------------------
// Disponibilite d'un exemplaire
//------------------------------------------------------------------------------------------------------
public function getDisponibilite($ex)
{
public function getDisponibilite($ex) {
// terme en pret
$tmp=Class_Profil::getCurrentProfil()->getCfgNoticeAsArray();
$libelle_en_pret="emprunté";
@@ -136,11 +116,8 @@ class Class_Systeme_PergameService
return $ex;
}
//------------------------------------------------------------------------------------------------------
// Liste des réservations en cours pour 1 abonné
//------------------------------------------------------------------------------------------------------
public function getReservations()
{
public function getReservations() {
$data=fetchAll("select * from reservations where IDABON='".$this->user->IDABON."' and ORDREABON=".$this->user->ORDREABON);
if(!$data) return array();
foreach($data as $enreg)
@@ -166,199 +143,193 @@ class Class_Systeme_PergameService
return $reservations;
}
//------------------------------------------------------------------------------------------------------
// Rend une notice pour un code_barres
//------------------------------------------------------------------------------------------------------
private function getNoticeFromCodeBarres($id_bib,$code_barres)
{
$cls_notice=new Class_Notice();
$id_notice=fetchOne("select id_notice from exemplaires where code_barres='$code_barres' and id_bib=$id_bib");
if(!$id_notice)
{
private function getNoticeFromCodeBarres($id_bib, $code_barres) {
$cls_notice = new Class_Notice();
$id_notice = fetchOne("select id_notice from exemplaires where code_barres='$code_barres' and id_bib=$id_bib");
if (!$id_notice) {
$notice["J"]="Anomalie de lecture du titre";
return $notice;
}
return ($model = Class_Notice::find($id_notice))
? $model->getNotice('JA') : [];
}
//------------------------------------------------------------------------------------------------------
// Rend une notice pour un id_notice_pergame et un support
//------------------------------------------------------------------------------------------------------
private function getNoticeFromTransaction($support,$id_notice_pergame)
{
$cls_notice=new Class_Notice();
$ids=fetchAll("select id_notice from exemplaires where id_origine='".$id_notice_pergame."'");
if(!$ids)
{
private function getNoticeFromTransaction($support,$id_notice_pergame) {
$cls_notice = new Class_Notice();
$ids = fetchAll("select id_notice from exemplaires where id_origine='".$id_notice_pergame."'");
if (!$ids) {
$notice["J"]="Anomalie de lecture du titre";
return $notice;
}
foreach($ids as $id)
{
if($inSql > '') $inSql.=",";
foreach($ids as $id) {
if ($inSql > '')
$inSql.=",";
$inSql.=$id["id_notice"];
}
$id_notice=fetchOne("select id_notice from notices where id_notice in($inSql) and type_doc=$support");
$id_notice = fetchOne("select id_notice from notices where id_notice in($inSql) and type_doc=$support");
return ($model = Class_Notice::find($id_notice))
? $model->getNotice('JA') : [];
}
//------------------------------------------------------------------------------------------------------
// Ecrire une réservation
//------------------------------------------------------------------------------------------------------
public function ReserverExemplairePergame($id_bib,$exemplaire, $code_annexe)
{
// Controle connexion
if(!$this->user->ID_USER) $ret["erreur"]="Vous devez être connecté pour réserver un document";
else if(!$this->user->IDABON) $ret["erreur"]="Vous devez être connecté en tant qu'abonné pour réserver un document";
public function reserverExemplairePergame($id_bib, $exemplaire, $code_annexe) {
if (!$this->user || !$this->user->ID_USER)
return ['erreur' => 'Vous devez être connecté pour réserver un document'];
if(!$this->user->IDABON)
return ['erreur' => 'Vous devez être connecté en tant qu\'abonné pour réserver un document'];
// Lire exemplaire et notice
if(!$exemplaire) return array("erreur"=>"Une erreur s'est produite lors de la lecture de la notice.");
if (!$exemplaire)
return ['erreur' => 'Une erreur s\'est produite lors de la lecture de la notice.'];
$notice = $exemplaire->getNotice();
$support = $notice->getFamilleId();
$notice= $exemplaire->getNotice();
$support=$notice->getTypeDoc();
// Controle si deja réservé par l'abonné
$ret=null;
$id_abon=$this->user->IDABON;
$ordre_abon=$this->user->ORDREABON;
$id_origine=$exemplaire->getIdOrigine();
$resa = Class_Reservation::findAllBy(['id_notice_origine' => $id_origine,
'id_site' => $id_bib,
'idabon' => $id_abon,
'ordreabon'=> $ordre_abon]);
$ret = null;
$id_abon = $this->user->IDABON;
$ordre_abon = $this->user->ORDREABON;
$id_origine = $exemplaire->getIdOrigine();
$resa = Class_Reservation::findFirstBy([
'id_notice_origine' => $id_origine,
'id_site' => $id_bib,
'idabon' => $id_abon,
'ordreabon'=> $ordre_abon]);
if($resa) $ret["erreur"]="Vous avez déjà réservé ce document le ".formatDate($resa["DATE_RESA"], 1);
if($ret["erreur"]) return $ret;
if ($resa)
return ['erreur' => 'Vous avez déjà réservé ce document le ' . formatDate($resa->getDateResa(), 1)];
// lecture des regles de reservations
$regles=$this->getReglesReservation($exemplaire->getIdBib());
$regles = $this->getReglesReservation($exemplaire->getIdBib());
// controle quota par carte
$nb=fetchOne("select count(*) from reservations where IDABON=$id_abon");
if($nb>=$regles["Max_par_carte"])
{
$ret["popup"]="La réservation est impossible car vous avez atteint le nombre maximum de réservations sur votre carte.";
return $ret;
}
$nb = Class_Reservation::countBy(['idabon' => $id_abon]);
if ($nb >= $regles['Max_par_carte'])
return ['popup' => 'La réservation est impossible car vous avez atteint le nombre maximum de réservations sur votre carte.'];
// controle quota par document
$nb=fetchOne("select count(*) from reservations where ID_NOTICE_ORIGINE=$id_origine");
if($nb>=$regles["Max_par_document"])
{
$ret["popup"]="La réservation est impossible car le nombre maximum de réservations pour ce document a été atteint (".$regles["Max_par_document"].").";
return $ret;
}
$nb = Class_Reservation::countBy(['id_notice_origine' => $id_origine]);
if ($nb >= $regles['Max_par_document'])
return ['popup' => 'La réservation est impossible car le nombre maximum de réservations pour ce document a été atteint (' . $regles["Max_par_document"] . ').'];
// Ecrire enreg reservation
if(!$id_bib) $id_bib=1;
$req="insert into reservations(ID_SITE,ID_PERGAME,IDABON,ORDREABON,DATE_RESA,SUPPORT,ID_NOTICE_ORIGINE)";
$req.="Values($id_bib,0,$id_abon,$ordre_abon,'".date("Y-m-d")."',$support,'$id_origine')";
sqlExecute($req);
// Ecrire enreg transaction
if(!$code_annexe) $code_annexe=1;
$date=date("Y-m-d H:i:s");
$heure=date("H");
$this->ecrireTransaction(6,array($id_abon,$ordre_abon,$support,$id_origine,$date,$id_bib,$heure));
}
if (!$id_bib)
$id_bib = 1;
//------------------------------------------------------------------------------------------------------
// Supprimer une réservation
//------------------------------------------------------------------------------------------------------
public function supprimerReservation($id_reservation)
{
// lire et detruire la réservation
$resa=fetchEnreg("select * from reservations where ID_RESA=$id_reservation");
if(!$resa) return false;
sqlExecute("delete from reservations where ID_RESA=$id_reservation");
// On cree la transaction
$id_abon=$this->user->IDABON;
$ordre_abon=$this->user->ORDREABON;
$id_origine=$resa["ID_NOTICE_ORIGINE"];
$date=$resa["DATE_RESA"];
$id_site=$resa["ID_SITE"];
$this->ecrireTransaction(7,array($id_abon,$ordre_abon,$date,$id_origine,$id_site));
}
$time_source = self::getTimeSource();
// Prolonger un prêt
function ProlongerPret($id_pret)
{
// lire enreg pret
$pret=fetchEnreg("select * from prets where id_pret=$id_pret");
$dateJour = date("Y-m-d");
$support=$pret["SUPPORT"];
// règles paramétrées
$regles=Class_IntBib::getLoader()->find($pret['ID_SITE'])->getCommParamsAsArray();
$complement_msg ='<br>Veuillez vous adresser à un responsable de la bibliothèque.';
// Lire le nombre de prolongations
$nbProlong=(int)$pret["NB_PROLONGATIONS"];
$nbProlong+=1;
$dateRetour=$pret["DATE_RETOUR"];
if($nbProlong > $regles["Nombre_max_par_document"]) return array('statut'=>0,"erreur"=>"Le prêt n'a pas pu être prolongé car il a atteint le nombre de prolongations autorisé.".$complement_msg);
// Controle anterioritemax
$anteriorite_max=(int)$regles['Anteriorite_max_en_jours'];
if($anteriorite_max)
{
$ecart=ecartDates($dateJour, $dateRetour);
if($ecart>$anteriorite_max) return array('statut'=>0,"erreur"=>"Le prêt n'a pas pu être prolongé car il a un retard trop important.".$complement_msg);
}
Class_Reservation::newInstance([
'id_site' => $id_bib,
'id_pergame' => 0,
'idabon' => $id_abon,
'ordreabon' => $ordre_abon,
'date_resa' => $time_source->dateYmd(),
'support' => $support,
'id_notice_origine' => $id_origine
])->save();
// Controle si le doc est réservé
if($regles["Interdire_si_reservation"]==1)
{
$controle=fetchOne("Select Count(*) From reservations Where ID_NOTICE_ORIGINE=".$pret["ID_NOTICE_ORIGINE"]);
if($controle>0) return array('statut'=>0,"erreur"=>"Le prêt n'a pas pu être prolongé car il est réservé.".$complement_msg);
}
// On prolonge
$newDate=ajouterJours($pret["DATE_RETOUR"],$regles['Duree_en_jours']);
while($newDate<=$dateJour) $newDate=ajouterJours($newDate,$regles['Duree_en_jours']);
$tempsProlong=(int)$regles['Duree_en_jours'];
$date = $time_source->dateFormat('Y-m-d H:i:s');
$heure = $time_source->dateFormat('H');
// Ecrire le prêt
sqlExecute("Update prets Set DATE_RETOUR='$newDate', NB_PROLONGATIONS=$nbProlong Where ID_PRET=".$pret["ID_PRET"]);
// Ecrire le mouvement
$enreg["ID_PRET"]=$pret["ID_PERGAME"];
$enreg["DATE_RETOUR"]=$newDate;
$enreg["NB_PROLONG"]=$nbProlong;
$enreg["TEMPS_PROLONG"]=$tempsProlong;
$this->ecrireTransaction(5,$enreg);
return array('statut'=>1);
$this->ecrireTransaction(6, [$id_abon, $ordre_abon, $support, $id_origine, $date, $id_bib, $heure]);
}
//------------------------------------------------------------------------------------------------------
// Ecrire une transaction
//------------------------------------------------------------------------------------------------------
private function ecrireTransaction($type_mvt,$enreg)
{
// Compacter les données
foreach($enreg as $item) $data.=$item."|";
// Ecrire
$req="insert into transactions(TYPE_MVT,DATA) Values($type_mvt,'$data')";
sqlExecute($req);
public function supprimerReservation($id_reservation) {
$resa = fetchEnreg("select * from reservations where ID_RESA=$id_reservation");
if(!$resa)
return false;
sqlExecute("delete from reservations where ID_RESA=$id_reservation");
// On cree la transaction
$id_abon=$this->user->IDABON;
$ordre_abon=$this->user->ORDREABON;
$id_origine=$resa["ID_NOTICE_ORIGINE"];
$date=$resa["DATE_RESA"];
$id_site=$resa["ID_SITE"];
$this->ecrireTransaction(7, array($id_abon,$ordre_abon,$date,$id_origine,$id_site));
}
public function prolongerPret($id_pret) {
$pret = fetchEnreg("select * from prets where id_pret=$id_pret");
$dateJour = date("Y-m-d");
$support=$pret["SUPPORT"];
// règles paramétrées
$regles = Class_IntBib::find($pret['ID_SITE'])->getCommParamsAsArray();
$complement_msg = '<br>Veuillez vous adresser à un responsable de la bibliothèque.';
// Lire le nombre de prolongations
$nbProlong = (int)$pret["NB_PROLONGATIONS"];
$nbProlong += 1;
$dateRetour = $pret["DATE_RETOUR"];
if($nbProlong > $regles["Nombre_max_par_document"])
return ['statut' => 0,
'erreur' => 'Le prêt n\'a pas pu être prolongé car il a atteint le nombre de prolongations autorisé.' . $complement_msg];
// Controle anterioritemax
$anteriorite_max = (int)$regles['Anteriorite_max_en_jours'];
if ($anteriorite_max) {
$ecart = ecartDates($dateJour, $dateRetour);
if ($ecart>$anteriorite_max)
return ['statut' => 0,
'erreur' => 'Le prêt n\'a pas pu être prolongé car il a un retard trop important.' . $complement_msg];
}
// Controle si le doc est réservé
if ($regles['Interdire_si_reservation'] == 1) {
$controle = fetchOne("Select Count(*) From reservations Where ID_NOTICE_ORIGINE=".$pret["ID_NOTICE_ORIGINE"]);
if($controle > 0)
return ['statut' => 0,
'erreur' => 'Le prêt n\'a pas pu être prolongé car il est réservé.' . $complement_msg];
}
// On prolonge
$newDate = ajouterJours($pret["DATE_RETOUR"], $regles['Duree_en_jours']);
while($newDate<=$dateJour)
$newDate = ajouterJours($newDate,$regles['Duree_en_jours']);
$tempsProlong=(int)$regles['Duree_en_jours'];
// Ecrire le prêt
sqlExecute("Update prets Set DATE_RETOUR='$newDate', NB_PROLONGATIONS=$nbProlong Where ID_PRET=".$pret["ID_PRET"]);
// Ecrire le mouvement
$enreg["ID_PRET"]=$pret["ID_PERGAME"];
$enreg["DATE_RETOUR"]=$newDate;
$enreg["NB_PROLONG"]=$nbProlong;
$enreg["TEMPS_PROLONG"]=$tempsProlong;
$this->ecrireTransaction(5,$enreg);
return ['statut' => 1];
}
private function ecrireTransaction($type_mvt, $enreg) {
$data = '';
foreach($enreg as $item)
$data .= $item . '|';
Class_Transaction::newInstance(['type_mvt' => $type_mvt, 'data' => $data])
->save();
}
//------------------------------------------------------------------------------------------------------
// Lire les regles de réservation
//------------------------------------------------------------------------------------------------------
public function getReglesReservation($id_bib)
{
if(!$id_bib) return false;
$bib= Class_IntBib::find($id_bib);
$data=$bib->getCommParamsAsArray();
if(!isset($data["Max_par_carte"])) $data["Max_par_carte"]=3;
if(!isset($data["Max_par_document"])) $data["Max_par_document"]=3;
public function getReglesReservation($id_bib) {
if (!$id_bib)
return false;
$bib = Class_IntBib::find($id_bib);
$data = $bib->getCommParamsAsArray();
if (!isset($data["Max_par_carte"]))
$data["Max_par_carte"] = 3;
if (!isset($data["Max_par_document"]))
$data["Max_par_document"] = 3;
return $data;
}
}
?>
?>
\ No newline at end of file