function add_pret($id_empr, $id_expl, $cb_doc, $resarc_id = 0, $short_loan = 0) { // le lien MySQL global $dbh, $msg; global $pmb_quotas_avances, $pmb_utiliser_calendrier; global $pmb_gestion_financiere, $pmb_gestion_tarif_prets; global $include_path, $lang; global $deflt2docs_location; global $pmb_pret_date_retour_adhesion_depassee; global $pmb_short_loan_management; global $pmb_transferts_actif; global $pmb_resa_planning; $resarc_id += 0; /* on prépare la date de début*/ $pret_date = today(); $duree_pret = 0; // calcul de la duree du pret si la date de fin est definie par les previsions if ($resarc_id && $pmb_resa_planning == 1) { $q = 'select datediff(resarc_fin,"' . $pret_date . '") from resa_archive where resarc_id =' . $resarc_id . ' and resarc_resa_planning_id_resa!=0 limit 1'; $r = pmb_mysql_query($q, $dbh); if (pmb_mysql_num_rows($r)) { $duree_pret = pmb_mysql_result($r, 0, 0); } } if (!$duree_pret) { /* on cherche la durée du prêt */ if ($pmb_short_loan_management && $short_loan) { if ($pmb_quotas_avances) { //Initialisation de la classe $qt = new quota("SHORT_LOAN_TIME_QUOTA"); $struct["READER"] = $id_empr; $struct["EXPL"] = $id_expl; $duree_pret = $qt->get_quota_value($struct); if ($duree_pret == -1) { $duree_pret = 0; } } else { $query = "SELECT short_loan_duration as duree_pret"; $query .= " FROM exemplaires, docs_type"; $query .= " WHERE expl_id='" . $id_expl; $query .= "' and idtyp_doc=expl_typdoc LIMIT 1"; $result = @pmb_mysql_query($query, $dbh) or die("can't SELECT exemplaires " . $query); $expl_properties = pmb_mysql_fetch_object($result); $duree_pret = $expl_properties->duree_pret; } } else { if ($pmb_quotas_avances) { //Initialisation de la classe $qt = new quota("LEND_TIME_QUOTA"); $struct["READER"] = $id_empr; $struct["EXPL"] = $id_expl; $duree_pret = $qt->get_quota_value($struct); if ($duree_pret == -1) { $duree_pret = 0; } } else { $query = "SELECT duree_pret"; $query .= " FROM exemplaires, docs_type"; $query .= " WHERE expl_id='" . $id_expl; $query .= "' and idtyp_doc=expl_typdoc LIMIT 1"; $result = @pmb_mysql_query($query, $dbh) or die("can't SELECT exemplaires " . $query); $expl_properties = pmb_mysql_fetch_object($result); $duree_pret = $expl_properties->duree_pret; } } } // calculer la date de retour prévue, tenir compte de la date de fin d'adhésion if (!$duree_pret) { $duree_pret = '0'; } if ($pmb_pret_date_retour_adhesion_depassee) { $rqt_date = "select empr_date_expiration,if(empr_date_expiration>date_add('" . $pret_date . "', INTERVAL '{$duree_pret}' DAY),0,1) as pret_depasse_adhes, date_add('" . $pret_date . "', INTERVAL '{$duree_pret}' DAY) as date_retour from empr where id_empr='" . $id_empr . "'"; } else { $rqt_date = "select empr_date_expiration,if(empr_date_expiration>date_add('" . $pret_date . "', INTERVAL '{$duree_pret}' DAY),0,1) as pret_depasse_adhes, if(empr_date_expiration>date_add('" . $pret_date . "', INTERVAL '{$duree_pret}' DAY),date_add('" . $pret_date . "', INTERVAL '{$duree_pret}' DAY),empr_date_expiration) as date_retour from empr where id_empr='" . $id_empr . "'"; } $resultatdate = pmb_mysql_query($rqt_date) or die(pmb_mysql_error() . "<br /><br />{$rqt_date}<br /><br />"); $res = pmb_mysql_fetch_object($resultatdate); $date_retour = $res->date_retour; $pret_depasse_adhes = $res->pret_depasse_adhes; $empr_date_expiration = $res->empr_date_expiration; if ($pmb_utiliser_calendrier) { if ($pret_depasse_adhes == 0 || $pmb_pret_date_retour_adhesion_depassee) { $rqt_date = "select date_ouverture from ouvertures where ouvert=1 and to_days(date_ouverture)>=to_days('{$date_retour}') and num_location={$deflt2docs_location} order by date_ouverture "; $resultatdate = pmb_mysql_query($rqt_date); $res = @pmb_mysql_fetch_object($resultatdate); if ($res->date_ouverture) { $date_retour = $res->date_ouverture; } } else { $rqt_date = "select date_ouverture from ouvertures where date_ouverture>=sysdate() and ouvert=1 and to_days(date_ouverture)<=to_days('{$date_retour}') and num_location={$deflt2docs_location} order by date_ouverture DESC"; $resultatdate = pmb_mysql_query($rqt_date); $res = @pmb_mysql_fetch_object($resultatdate); if ($res->date_ouverture) { $date_retour = $res->date_ouverture; } } // Si la date_retour, calculée ci-dessus d'après le calendrier, dépasse l'adhésion, alors que c'est interdit, // la date de retour doit etre le dernier jour ouvert if (!$pmb_pret_date_retour_adhesion_depassee) { $rqt_date = "SELECT DATEDIFF('{$empr_date_expiration}','{$date_retour}')as diff"; $resultatdate = pmb_mysql_query($rqt_date); $res = @pmb_mysql_fetch_object($resultatdate); if ($res->diff < 0) { $rqt_date = "select date_ouverture from ouvertures where date_ouverture>=sysdate() and ouvert=1 and to_days(date_ouverture)<=to_days('{$empr_date_expiration}') and num_location={$deflt2docs_location} order by date_ouverture DESC"; $resultatdate = pmb_mysql_query($rqt_date); $res = @pmb_mysql_fetch_object($resultatdate); if ($res->date_ouverture) { $date_retour = $res->date_ouverture; } } } } // insérer le prêt $query = "INSERT INTO pret SET "; $query .= "pret_idempr = '" . $id_empr . "', "; $query .= "pret_idexpl = '" . $id_expl . "', "; $query .= "pret_date = sysdate(), "; $query .= "pret_retour = '{$date_retour}', "; $query .= "retour_initial = '{$date_retour}', "; $query .= "short_loan_flag = " . ($pmb_short_loan_management && $short_loan ? "'1'" : "'0'"); $result = @pmb_mysql_query($query, $dbh) or die(pmb_mysql_error() . "<br />can't INSERT into pret" . $query); // insérer la trace en stat, récupérer l'id et le mettre dans la table des prêts pour la maj ultérieure $stat_avant_pret = pret_construit_infos_stat($id_expl); $stat_id = stat_stuff($stat_avant_pret); $query = "update pret SET pret_arc_id='{$stat_id}' where "; $query .= "pret_idempr = '" . $id_empr . "' and "; $query .= "pret_idexpl = '" . $id_expl . "' "; $result = @pmb_mysql_query($query, $dbh) or die("can't update pret for stats " . $query); audit::insert_creation(AUDIT_PRET, $stat_id); //enregistrer les champs perso pret $p_perso = new pret_parametres_perso("pret"); $p_perso->rec_fields_perso($stat_id); if ($resarc_id) { $rqt_arch = "UPDATE resa_archive SET resarc_arcpretid = {$stat_id} WHERE resarc_id = '" . $resarc_id . "' "; @pmb_mysql_query($rqt_arch, $dbh); } $query = "update exemplaires SET "; $query .= "last_loan_date = sysdate() "; $query .= "where expl_id= '" . $id_expl . "' "; $result = @pmb_mysql_query($query, $dbh) or die("can't update last_loan_date in exemplaires : " . $query); $query = "update exemplaires SET "; $query .= "expl_retloc=0 "; $query .= "where expl_id= '" . $id_expl . "' "; $result = @pmb_mysql_query($query, $dbh) or die("can't update expl_retloc in exemplaires : " . $query); $query = "update empr SET "; $query .= "last_loan_date = sysdate() "; $query .= "where id_empr= '" . $id_empr . "' "; $result = @pmb_mysql_query($query, $dbh) or die("can't update last_loan_date in empr : " . $query); $query = "delete from resa_ranger "; $query .= "where resa_cb='" . $cb_doc . "'"; $result = @pmb_mysql_query($query, $dbh) or die("can't delete cb_doc in resa_ranger : " . $query); //Débit du compte lecteur si nécessaire if ($pmb_gestion_financiere && $pmb_gestion_tarif_prets) { $tarif_pret = 0; switch ($pmb_gestion_tarif_prets) { case 1: //Gestion simple $query = "SELECT tarif_pret"; $query .= " FROM exemplaires, docs_type"; $query .= " WHERE expl_id='" . $id_expl; $query .= "' and idtyp_doc=expl_typdoc LIMIT 1"; $result = @pmb_mysql_query($query, $dbh) or die("can't SELECT exemplaires " . $query); $expl_tarif = pmb_mysql_fetch_object($result); $tarif_pret = $expl_tarif->tarif_pret; break; case 2: //Gestion avancée //Initialisation Quotas global $_parsed_quotas_; $_parsed_quotas_ = false; $qt_tarif = new quota("COST_LEND_QUOTA", "{$include_path}/quotas/own/{$lang}/finances.xml"); $struct["READER"] = $id_empr; $struct["EXPL"] = $id_expl; $tarif_pret = $qt_tarif->get_quota_value($struct); break; } $tarif_pret = $tarif_pret * 1; if ($tarif_pret) { $compte_id = comptes::get_compte_id_from_empr($id_empr, 3); if ($compte_id) { $cpte = new comptes($compte_id); $explaire = new exemplaire('', $id_expl); if ($explaire->id_notice == 0 && $explaire->id_bulletin) { //C'est un exemplaire de bulletin $bulletin = new bulletinage_display($explaire->id_bulletin); $titre = strip_tags($bulletin->display); } elseif ($explaire->id_notice) { $notice = new mono_display($explaire->id_notice); $titre = strip_tags($notice->header); } $libelle_expl = strlen($titre) > 15 ? $explaire->cb . " " . $titre : $explaire->cb . " " . $titre; $cpte->record_transaction("", abs($tarif_pret), -1, sprintf($msg["finance_pret_expl"], $libelle_expl), 0); } } } if ($pmb_transferts_actif) { // si transferts validé (en attente d'envoi), il faut restaurer le statut global $PMBuserid; $rqt = "SELECT id_transfert FROM transferts,transferts_demande\r\n\t\twhere\r\n\t\tnum_transfert=id_transfert and\r\n\t\tetat_demande=1 and num_expl ={$id_expl} and etat_transfert=0 and sens_transfert=0"; $res = pmb_mysql_query($rqt); if (pmb_mysql_num_rows($res)) { $obj = pmb_mysql_fetch_object($res); $idTrans = $obj->id_transfert; //Récupération des informations d'origine $rqt = "SELECT statut_origine, num_expl FROM transferts INNER JOIN transferts_demande ON id_transfert=num_transfert\r\n\t\t\tWHERE id_transfert=" . $idTrans . " AND sens_transfert=0"; $res = pmb_mysql_query($rqt); $obj_data = pmb_mysql_fetch_object($res); //on met à jour $rqt = "UPDATE exemplaires SET expl_statut=" . $obj_data->statut_origine . " WHERE expl_id=" . $obj_data->num_expl; pmb_mysql_query($rqt); } // cloture les demandes de transfert pour résa, refusée ou pas // afin de générer les transfert en automatique dans le circuit classique des résa $req = " update transferts,transferts_demande\n\t\tset etat_transfert=1 ,\n\t\tmotif=CONCAT(motif,'. Cloture, car parti en pret (gestion {$PMBuserid}, {$id_empr})')\n\t\twhere\n\t\tnum_transfert=id_transfert and\n\t\t(etat_demande=4 or etat_demande=0 or etat_demande=1)and\n\t\tetat_demande != 3 and etat_demande!=2 and etat_demande!=5 and\n\t\tnum_expl ={$id_expl} and etat_transfert=0 and sens_transfert=0\n\t\t"; pmb_mysql_query($req, $dbh); } // invalidation des résas avec ce code-barre, au cas où // $query = "update resa SET resa_cb='' where resa_cb='".$cb_doc."' "; // $result = @ pmb_mysql_query($query, $dbh) or die("can't update resa ".$query); }
function add_pret($id_empr, $id_expl, $cb_doc) { // le lien MySQL global $dbh; global $msg; global $pmb_quotas_avances; /* on prépare la date de début*/ $pret_date = time(); /* on cherche la durée du prêt */ if ($pmb_quotas_avances) { //Initialisation de la classe $qt = new quota("LEND_TIME_QUOTA"); $struct["READER"] = $id_empr; $struct["EXPL"] = $id_expl; $duree_pret = $qt->get_quota_value($struct); if ($duree_pret == -1) { $duree_pret = 0; } } else { $query = "SELECT duree_pret"; $query .= " FROM exemplaires, docs_type"; $query .= " WHERE expl_id='" . $id_expl; $query .= "' and idtyp_doc=expl_typdoc LIMIT 1"; $result = @pmb_mysql_query($query, $dbh) or die("can't SELECT exemplaires " . $query); $expl_properties = pmb_mysql_fetch_object($result); $duree_pret = $expl_properties->duree_pret; } // calculer la date de retour prévue $pret_retour = $pret_date + 3600 * 24 * $duree_pret; // insérer le prêt $query = "INSERT INTO pret SET "; $query .= "pret_idempr = '" . $id_empr . "', "; $query .= "pret_idexpl = '" . $id_expl . "', "; $query .= "pret_date = sysdate(), "; $query .= "pret_retour = '" . date("Y-m-d", $pret_retour) . "', "; $query .= "retour_initial = '" . date("Y-m-d", $pret_retour) . "' "; $result = @pmb_mysql_query($query, $dbh) or die(pmb_mysql_error() . "<br />can't INSERT into pret" . $query); // insérer la trace en stat, récupérer l'id et le mettre dans la table des prêts pour la maj ultérieure $stat_avant_pret = pret_construit_infos_stat($id_expl); $stat_id = stat_stuff($stat_avant_pret); $query = "update pret SET pret_arc_id='{$stat_id}' where "; $query .= "pret_idempr = '" . $id_empr . "' and "; $query .= "pret_idexpl = '" . $id_expl . "' "; $result = @pmb_mysql_query($query, $dbh) or die("can't update pret for stats " . $query); audit::insert_creation(AUDIT_PRET, $stat_id); //enregistrer les champs perso pret $p_perso = new pret_parametres_perso("pret"); $p_perso->rec_fields_perso($stat_id); $query = "update exemplaires SET "; $query .= "last_loan_date = sysdate() "; $query .= "where expl_id= '" . $id_expl . "' "; $result = @pmb_mysql_query($query, $dbh) or die("can't update last_loan_date in exemplaires : " . $query); $query = "update empr SET "; $query .= "last_loan_date = sysdate() "; $query .= "where id_empr= '" . $id_empr . "' "; $result = @pmb_mysql_query($query, $dbh) or die("can't update last_loan_date in empr : " . $query); }
function confirm_pret($id_empr, $id_expl, $short_loan = 0) { // le lien MySQL global $dbh, $msg; global $pmb_quotas_avances, $pmb_utiliser_calendrier; global $pmb_gestion_financiere, $pmb_gestion_tarif_prets; global $include_path, $lang; global $deflt2docs_location; global $pmb_pret_date_retour_adhesion_depassee; global $pmb_short_loan_management; //supprimer le pret temporaire $query = "delete from pret where pret_idexpl = '" . $id_expl . "' "; $result = mysql_query($query, $dbh); /* on prépare la date de début*/ $pret_date = today(); /* on cherche la durée du prêt */ if ($pmb_short_loan_management && $short_loan) { if ($pmb_quotas_avances) { //Initialisation de la classe $qt = new quota("SHORT_LOAN_TIME_QUOTA"); $struct["READER"] = $id_empr; $struct["EXPL"] = $id_expl; $duree_pret = $qt->get_quota_value($struct); if ($duree_pret == -1) { $duree_pret = 0; } } else { $query = "SELECT short_loan_duration as duree_pret"; $query .= " FROM exemplaires, docs_type"; $query .= " WHERE expl_id='" . $id_expl; $query .= "' and idtyp_doc=expl_typdoc LIMIT 1"; $result = @mysql_query($query, $dbh) or die("can't SELECT exemplaires " . $query); $expl_properties = mysql_fetch_object($result); $duree_pret = $expl_properties->duree_pret; } } else { if ($pmb_quotas_avances) { //Initialisation de la classe $qt = new quota("LEND_TIME_QUOTA"); $struct["READER"] = $id_empr; $struct["EXPL"] = $id_expl; $duree_pret = $qt->get_quota_value($struct); if ($duree_pret == -1) { $duree_pret = 0; } } else { $query = "SELECT duree_pret"; $query .= " FROM exemplaires, docs_type"; $query .= " WHERE expl_id='" . $id_expl; $query .= "' and idtyp_doc=expl_typdoc LIMIT 1"; $result = @mysql_query($query, $dbh) or die("can't SELECT exemplaires " . $query); $expl_properties = mysql_fetch_object($result); $duree_pret = $expl_properties->duree_pret; } } // calculer la date de retour prévue, tenir compte de la date de fin d'adhésion if (!$duree_pret) { $duree_pret = "0"; } if ($pmb_pret_date_retour_adhesion_depassee) { $rqt_date = "select empr_date_expiration,if(empr_date_expiration>date_add('" . $pret_date . "', INTERVAL '{$duree_pret}' DAY),0,1) as pret_depasse_adhes, date_add('" . $pret_date . "', INTERVAL '{$duree_pret}' DAY) as date_retour from empr where id_empr='" . $id_empr . "'"; } else { $rqt_date = "select empr_date_expiration,if(empr_date_expiration>date_add('" . $pret_date . "', INTERVAL '{$duree_pret}' DAY),0,1) as pret_depasse_adhes, if(empr_date_expiration>date_add('" . $pret_date . "', INTERVAL '{$duree_pret}' DAY),date_add('" . $pret_date . "', INTERVAL '{$duree_pret}' DAY),empr_date_expiration) as date_retour from empr where id_empr='" . $id_empr . "'"; } $resultatdate = mysql_query($rqt_date) or die(mysql_error() . "<br /><br />{$rqt_date}<br /><br />"); $res = mysql_fetch_object($resultatdate); $date_retour = $res->date_retour; $pret_depasse_adhes = $res->pret_depasse_adhes; $empr_date_expiration = $res->empr_date_expiration; if ($pmb_utiliser_calendrier) { if ($pret_depasse_adhes == 0 || $pmb_pret_date_retour_adhesion_depassee) { $rqt_date = "select date_ouverture from ouvertures where ouvert=1 and to_days(date_ouverture)>=to_days('{$date_retour}') and num_location={$deflt2docs_location} order by date_ouverture "; $resultatdate = mysql_query($rqt_date); $res = @mysql_fetch_object($resultatdate); if ($res->date_ouverture) { $date_retour = $res->date_ouverture; } } else { $rqt_date = "select date_ouverture from ouvertures where date_ouverture>=sysdate() and ouvert=1 and to_days(date_ouverture)<=to_days('{$date_retour}') and num_location={$deflt2docs_location} order by date_ouverture DESC"; $resultatdate = mysql_query($rqt_date); $res = @mysql_fetch_object($resultatdate); if ($res->date_ouverture) { $date_retour = $res->date_ouverture; } } // Si la date_retour, calculée ci-dessus d'après le calendrier, dépasse l'adhésion, alors que c'est interdit, // la date de retour doit etre le dernier jour ouvert if (!$pmb_pret_date_retour_adhesion_depassee) { $rqt_date = "SELECT DATEDIFF('{$empr_date_expiration}','{$date_retour}')as diff"; $resultatdate = mysql_query($rqt_date); $res = @mysql_fetch_object($resultatdate); if ($res->diff < 0) { $rqt_date = "select date_ouverture from ouvertures where date_ouverture>=sysdate() and ouvert=1 and to_days(date_ouverture)<=to_days('{$empr_date_expiration}') and num_location={$deflt2docs_location} order by date_ouverture DESC"; $resultatdate = mysql_query($rqt_date); $res = @mysql_fetch_object($resultatdate); if ($res->date_ouverture) { $date_retour = $res->date_ouverture; } } } } // insérer le prêt $query = "INSERT INTO pret SET "; $query .= "pret_idempr = '" . $id_empr . "', "; $query .= "pret_idexpl = '" . $id_expl . "', "; $query .= "pret_date = sysdate(), "; $query .= "pret_retour = '{$date_retour}', "; $query .= "retour_initial = '{$date_retour}', "; $query .= "short_loan_flag = " . ($pmb_short_loan_management && $short_loan ? "'1'" : "'0'"); $result = @mysql_query($query, $dbh) or die("can't INSERT into pret" . $query); // insérer la trace en stat, récupérer l'id et le mettre dans la table des prêts pour la maj ultérieure $stat_avant_pret = pret_construit_infos_stat($id_expl); $stat_id = stat_stuff($stat_avant_pret); $query = "update pret SET pret_arc_id='{$stat_id}' where "; $query .= "pret_idempr = '" . $id_empr . "' and "; $query .= "pret_idexpl = '" . $id_expl . "' "; $result = @mysql_query($query, $dbh) or die("can't update pret for stats " . $query); $query = "update exemplaires SET "; $query .= "last_loan_date = sysdate() "; $query .= "where expl_id= '" . $id_expl . "' "; $result = @mysql_query($query, $dbh) or die("can't update last_loan_date in exemplaires : " . $query); $query = "update exemplaires SET "; $query .= "expl_retloc=0 "; $query .= "where expl_id= '" . $id_expl . "' "; $result = @mysql_query($query, $dbh) or die("can't update expl_retloc in exemplaires : " . $query); $query = "update empr SET "; $query .= "last_loan_date = sysdate() "; $query .= "where id_empr= '" . $id_empr . "' "; $result = @mysql_query($query, $dbh) or die("can't update last_loan_date in empr : " . $query); //Débit du compte lecteur si nécessaire if ($pmb_gestion_financiere && $pmb_gestion_tarif_prets) { $tarif_pret = 0; switch ($pmb_gestion_tarif_prets) { case 1: //Gestion simple $query = "SELECT tarif_pret"; $query .= " FROM exemplaires, docs_type"; $query .= " WHERE expl_id='" . $id_expl; $query .= "' and idtyp_doc=expl_typdoc LIMIT 1"; $result = @mysql_query($query, $dbh) or die("can't SELECT exemplaires " . $query); $expl_tarif = mysql_fetch_object($result); $tarif_pret = $expl_tarif->tarif_pret; break; case 2: //Gestion avancée //Initialisation Quotas global $_parsed_quotas_; $_parsed_quotas_ = false; $qt_tarif = new quota("COST_LEND_QUOTA", "{$include_path}/quotas/own/{$lang}/finances.xml"); $struct["READER"] = $id_empr; $struct["EXPL"] = $id_expl; $tarif_pret = $qt_tarif->get_quota_value($struct); break; } $tarif_pret = $tarif_pret * 1; if ($tarif_pret) { $compte_id = comptes::get_compte_id_from_empr($id_empr, 3); if ($compte_id) { $cpte = new comptes($compte_id); $cpte->record_transaction("", abs($tarif_pret), -1, sprintf($msg["finance_pret_expl"], $id_expl), 0); } } } $this->resa_pret_gestion($id_empr, $id_expl, $stat_id); $array[0]['statut'] = 1; $buf_xml = array2xml($array); return $buf_xml; }