id = intval($id); // si id; récupération des données du groupe if($this->id) { $this->members = array(); $this->get_data(); } } // récupération des données du groupe public function get_data() { $requete = "SELECT * FROM groupe"; $requete .= " WHERE id_groupe='".$this->id."' "; $res = pmb_mysql_query($requete); if(pmb_mysql_num_rows($res)) { $row = pmb_mysql_fetch_object($res); $this->libelle = $row->libelle_groupe; $this->lettre_rappel=$row->lettre_rappel; $this->mail_rappel=$row->mail_rappel; $this->lettre_rappel_show_nomgroup=$row->lettre_rappel_show_nomgroup; $this->comment_gestion = $row->comment_gestion; $this->comment_opac = $row->comment_opac; $this->lettre_resa=$row->lettre_resa; $this->mail_resa=$row->mail_resa; $this->lettre_resa_show_nomgroup=$row->lettre_resa_show_nomgroup; // récupération id et libelle du responsable if($row->resp_groupe) { $this->id_resp = $row->resp_groupe; $requete = "SELECT empr_nom, empr_prenom, empr_cb, empr_mail FROM empr"; $requete .= " WHERE id_empr=".$this->id_resp." LIMIT 1"; $res = pmb_mysql_query($requete); if(pmb_mysql_num_rows($res)) { $row = pmb_mysql_fetch_object($res); $this->libelle_resp = $row->empr_nom; if($row->empr_prenom) $this->libelle_resp .= ', '.$row->empr_prenom; $this->libelle_resp .= ' ('.$row->empr_cb.')'; $this->cb_resp = $row->empr_cb; $this->mail_resp = $row->empr_mail; } } $this->get_members(); } return; } // génération du form de group public function get_form() { global $group_form; global $msg; global $charset; if($this->id) $titre = $msg[912]; // modification else $titre = $msg[910]; // création $group_form = str_replace('!!titre!!', $titre, $group_form); if ($this->lettre_rappel) $group_form = str_replace('!!lettre_rappel!!', "checked", $group_form); else $group_form = str_replace('!!lettre_rappel!!', "", $group_form); if ($this->mail_rappel) $group_form = str_replace('!!mail_rappel!!', "checked", $group_form); else $group_form = str_replace('!!mail_rappel!!', "", $group_form); if ($this->lettre_rappel_show_nomgroup) $group_form = str_replace('!!lettre_rappel_show_nomgroup!!', "checked", $group_form); else $group_form = str_replace('!!lettre_rappel_show_nomgroup!!', "", $group_form); if ($this->lettre_resa) $group_form = str_replace('!!lettre_resa!!', "checked", $group_form); else $group_form = str_replace('!!lettre_resa!!', "", $group_form); if ($this->mail_resa) $group_form = str_replace('!!mail_resa!!', "checked", $group_form); else $group_form = str_replace('!!mail_resa!!', "", $group_form); if ($this->lettre_resa_show_nomgroup) $group_form = str_replace('!!lettre_resa_show_nomgroup!!', "checked", $group_form); else $group_form = str_replace('!!lettre_resa_show_nomgroup!!', "", $group_form); $group_form = str_replace('!!group_name!!', htmlentities($this->libelle,ENT_QUOTES, $charset), $group_form); $group_form = str_replace('!!nom_resp!!', $this->libelle_resp, $group_form); $group_form = str_replace('!!comment_gestion!!', $this->comment_gestion, $group_form); $group_form = str_replace('!!comment_opac!!', $this->comment_opac, $group_form); $group_form = str_replace('!!groupID!!', $this->id, $group_form); $group_form = str_replace('!!respID!!', $this->id_resp, $group_form); if($this->id) { $link_annul = './circ.php?categ=groups&action=showgroup&groupID='.$this->id; $link_suppr = ""; } else { $link_annul = './circ.php?categ=groups'; $link_suppr = ""; } $group_form = str_replace('!!link_annul!!', $link_annul, $group_form); $group_form = str_replace('', $link_suppr, $group_form); return $group_form; } // affectation de nouvelles valeurs public function set_properties_form_form() { global $group_name, $respID, $lettre_rappel, $mail_rappel; global $lettre_rappel_show_nomgroup, $comment_gestion, $comment_opac, $lettre_resa, $mail_resa, $lettre_resa_show_nomgroup; if ($group_name) { $this->libelle = stripslashes($group_name); } $this->id_resp = intval($respID); $this->lettre_rappel = intval($lettre_rappel); $this->mail_rappel = intval($mail_rappel); $this->lettre_rappel_show_nomgroup = intval($lettre_rappel_show_nomgroup); $this->comment_gestion = stripslashes($comment_gestion); $this->comment_opac = stripslashes($comment_opac); $this->lettre_resa = intval($lettre_resa); $this->mail_resa = intval($mail_resa); $this->lettre_resa_show_nomgroup = intval($lettre_resa_show_nomgroup); } // récupération des membres du groupe (feed : array members) public function get_members() { if(!$this->id) return; $requete = "select EMPR.id_empr AS id, EMPR.empr_nom AS nom , EMPR.empr_prenom AS prenom, EMPR.empr_cb AS cb, EMPR.empr_categ AS id_categ, EMPR.type_abt AS id_abt"; $requete .= " FROM empr EMPR, empr_groupe MEMBERS"; $requete .= " WHERE MEMBERS.empr_id=EMPR.id_empr"; $requete .= " AND MEMBERS.groupe_id=".$this->id; $requete .= " ORDER BY EMPR.empr_nom, EMPR.empr_prenom"; $result = pmb_mysql_query($requete); $this->nb_members = pmb_mysql_num_rows($result); if($this->nb_members) { while($mb = pmb_mysql_fetch_object($result)) { $this->members[] = array( 'nom' => $mb->nom, 'prenom' => $mb->prenom, 'cb' => $mb->cb, 'id' => $mb->id, 'id_categ' => $mb->id_categ, 'id_abt' => $mb->id_abt); } } $this->nb_members = count($this->members); return; } // ajout d'un membre public function add_member($member) { if(!$member) return 0; // checke si ce membre n'est pas déjà dans le groupe $requete = "SELECT count(1) FROM empr_groupe"; $requete .= " WHERE empr_id=$member AND groupe_id=".$this->id; $res = pmb_mysql_query($requete); if(pmb_mysql_result($res, 0, 0)) return $member; // OK. insertion 'pour de vrai' $requete = "INSERT INTO empr_groupe"; $requete .= " SET empr_id='$member', groupe_id='".$this->id."'"; $res = pmb_mysql_query($requete); if($res) return $member; else return 0; } // suppression du groupe public static function delete($id) { $id = intval($id); if ($id) { $requete = "DELETE FROM groupe WHERE id_groupe=".$id; pmb_mysql_query($requete); pmb_mysql_affected_rows(); $requete = "DELETE FROM empr_groupe WHERE groupe_id=".$id; pmb_mysql_query($requete); } return true; } // suppression d'un membre public function del_member($member) { if(!$member) return 0; $requete = "DELETE FROM empr_groupe"; $requete .= " WHERE empr_id=$member AND groupe_id=".$this->id; $res = pmb_mysql_query($requete); return $res; } // mise à jour dans la table public function update() { if($this->id) { // mise à jour $requete = "UPDATE groupe"; $requete .= " SET libelle_groupe='".addslashes($this->libelle)."'"; $requete .= ", resp_groupe='".$this->id_resp."'"; $requete .= ", lettre_rappel='".$this->lettre_rappel."'"; $requete .= ", mail_rappel='".$this->mail_rappel."'"; $requete .= ", lettre_rappel_show_nomgroup='".$this->lettre_rappel_show_nomgroup."'"; $requete .= ", comment_gestion='".addslashes($this->comment_gestion)."'"; $requete .= ", comment_opac='".addslashes($this->comment_opac)."'"; $requete .= ", lettre_resa='".$this->lettre_resa."'"; $requete .= ", mail_resa='".$this->mail_resa."'"; $requete .= ", lettre_resa_show_nomgroup='".$this->lettre_resa_show_nomgroup."'"; $requete .= " WHERE id_groupe=".$this->id." LIMIT 1"; pmb_mysql_query($requete); } else { // on voit si ça n'existe pas if($this->exists($this->libelle)) return $this->id; // création $requete = "INSERT INTO groupe SET id_groupe=''"; $requete .= ", libelle_groupe='".addslashes($this->libelle)."'"; $requete .= ", resp_groupe='".$this->id_resp."'"; $requete .= ", lettre_rappel='".$this->lettre_rappel."'"; $requete .= ", mail_rappel='".$this->mail_rappel."'"; $requete .= ", lettre_rappel_show_nomgroup='".$this->lettre_rappel_show_nomgroup."'"; $requete .= ", comment_gestion='".addslashes($this->comment_gestion)."'"; $requete .= ", comment_opac='".addslashes($this->comment_opac)."'"; $requete .= ", lettre_resa='".$this->lettre_resa."'"; $requete .= ", mail_resa='".$this->mail_resa."'"; $requete .= ", lettre_resa_show_nomgroup='".$this->lettre_resa_show_nomgroup."'"; pmb_mysql_query($requete); $this->id = pmb_mysql_insert_id(); } return $this->id; } public function exists($name) { if(!$name) return; $requete = "SELECT count(1) FROM groupe"; $requete .= " WHERE libelle_groupe='$name'"; $result = pmb_mysql_query($requete); return pmb_mysql_result($result, 0, 0); } // prolongation d'adhésion des membres en fin d'abonnement ou en abonnement dépassé public function update_members() { global $msg; if($this->id) { if($this->nb_members) { foreach ($this->members as $cle => $membre) { $date_prolong = "form_expiration_".$membre['id']; global ${$date_prolong}; if (${$date_prolong} != "") { //Ne pas débiter l'abonnement deux fois.. $requete = "SELECT empr_date_expiration FROM empr WHERE id_empr=".$membre['id']; $resultat = pmb_mysql_query($requete); if ($resultat) { if (str_replace("-","",pmb_mysql_result($resultat,0,0)) != str_replace("-","",${$date_prolong})) { // mise à jour $requete = "UPDATE empr"; $requete .= " SET empr_date_expiration='".${$date_prolong}."'"; $requete .= " WHERE id_empr=".$membre['id']." LIMIT 1"; @pmb_mysql_query($requete); if(!pmb_mysql_errno()) { global $debit; if ($debit) { if ($debit==2) $rec_caution=true; else $rec_caution=false; emprunteur::rec_abonnement($membre['id'],$membre['id_abt'],$membre['id_categ'],$rec_caution); } } else { error_message($msg[540], "erreur modification emprunteur", 1, './circ.php?categ=groups&action=showgroup&groupID=".$this->id."'); } } } } } } } } // prolongation des prêts des membres, dont la date de retour est < à la date sélectionnée public function pret_prolonge_members() { global $group_prolonge_pret_date; if(!$this->id) return; $expls = array(); foreach ($this->members as $empr) { $req = "select pret_idexpl from pret where pret_idempr=".$empr['id']; $res = pmb_mysql_query($req); while ($r = pmb_mysql_fetch_object($res)) { $expls[] = array( 'id' => $r->pret_idexpl, ); } $req = "update pret set pret_retour='".$group_prolonge_pret_date."', cpt_prolongation=cpt_prolongation+1 where pret_retour<'".$group_prolonge_pret_date."' and pret_idempr=".$empr['id']; $res = pmb_mysql_query($req); } return $expls; } public static function gen_combo_box_grp ( $selected=false, $multiple=0, $afficher_aucun=1, $afficher_premier=1, $on_change="" ) { global $msg,$param_allloc,$deflt2docs_location; if (!$selected) { if ($param_allloc) $selected=array(0=>-1); else $selected=array(0=>$deflt2docs_location); } $requete="select idlocation, location_libelle from docs_location order by location_libelle "; $champ_code="idlocation"; $champ_info="location_libelle"; $nom="group_location_id"; $liste_vide_code="0"; $liste_vide_info=$msg['class_location']; $option_premier_code="-1"; if ($afficher_premier) $option_premier_info=$msg['all_location']; $option_aucun_code="-2"; if ($afficher_aucun) $option_aucun_info=$msg['no_location']; $gen_liste_str=""; $resultat_liste=pmb_mysql_query($requete); $gen_liste_str = "\n" ; return $gen_liste_str ; } public function get_transactions($typ_compte) { global $charset, $msg; global $show_transactions, $date_debut; $display = ''; $nb_transactions = 0; $transactions_display = ''; $solde_total = 0; $non_valide_total = 0; foreach ($this->members as $empr) { $id_compte = comptes::get_compte_id_from_empr($empr['id'], $typ_compte); $cpte = new comptes($id_compte); $solde_total+= $cpte->get_solde(); $non_valide_total+= $cpte->summarize_transactions("", "", 0, 0); switch ($show_transactions) { case "2": $t = $cpte->get_transactions("", "", 0, 0); break; case "3": $date_debut_ = extraitdate($date_debut); $t = $cpte->get_transactions($date_debut_, "", 0, -1, 0, "asc"); break; case "1": default: $t = $cpte->get_transactions("", "", 0, -1, 10); break; } if (count($t)) { for ($i = 0; $i < count($t); $i++) { $nb_transactions++; $transactions_display.= " ".formatdate($t[$i]->date_enrgt)." ".($t[$i]->encaissement ? "*" : " ")."id."\">".$empr['nom']." ".$empr['prenom']." ".$t[$i]->commentaire." ".($t[$i]->sens==-1 ? "" : "").comptes::format($t[$i]->montant).($t[$i]->sens==-1? "":"")." ".($t[$i]->sens==1 ? $msg["finance_form_empr_libelle_credit"] : $msg["finance_form_empr_libelle_debit"])." ".($t[$i]->realisee ? "X" : "")." ".formatdate($t[$i]->date_effective)." "; } } } if ($nb_transactions) { $display = " ". $transactions_display."
".$msg["finance_list_tr_date_enrgt"]."   ".$msg["finance_list_tr_comment"]." ".$msg["finance_montant"]." ".$msg["finance_list_tr_deb_cred"]." ".$msg["finance_list_tr_validee"]." ".$msg["finance_date_valid"]."
"; } return array( 'typ_compte' => $typ_compte, 'typ_compte_lib' => comptes::get_typ_compte_lib($typ_compte), 'solde_total' => $solde_total, 'non_valide_total' => $non_valide_total, 'solde_total_display' => comptes::format($solde_total), 'non_valide_total_display' => comptes::format($non_valide_total), 'transactions_display' => $display, ); } public function get_transactions_form() { global $charset, $msg; global $show_transactions, $date_debut, $typ_compte; if (!$show_transactions) { $show_transactions = 2; // Non validée par défaut } $transactions = $this->get_transactions($typ_compte); $form = "

!!group_name!! : !!type_compte!!

".$msg["finance_solde"]." !!solde!!
".$msg["finance_not_validated"]." : !!non_valide!!

 
".$transactions['transactions_display']."
 

"; for ($i = 1; $i <= 3; $i++) { if ($i == $show_transactions) $form = str_replace("!!checked$i!!", "checked", $form); else $form = str_replace("!!checked$i!!", "", $form); } $form = str_replace("!!group_name!!", htmlentities($this->libelle, ENT_QUOTES, $charset), $form); $form = str_replace("!!typ_compte!!", $typ_compte, $form); $form = str_replace("!!type_compte!!", htmlentities($transactions['typ_compte_lib'], ENT_QUOTES, $charset), $form); $form = str_replace("!!solde!!", $transactions['solde_total_display'], $form); $form = str_replace("!!non_valide!!", $transactions['non_valide_total_display'], $form); $form = str_replace("!!date_debut!!", htmlentities(stripslashes($date_debut), ENT_QUOTES, $charset), $form); return $form; } public function get_solde_form() { global $msg; global $pmb_gestion_financiere, $pmb_gestion_abonnement, $pmb_gestion_tarif_prets, $pmb_gestion_amende; if (!$pmb_gestion_financiere) return ''; $solde_abonnement = 0; $novalid_abonnement = 0; $solde_prets = 0; $novalid_prets = 0; $solde_amende = 0; $novalid_amende = 0; $total_amende = 0; $nb_amendes = 0; $solde_transac = 0; $novalid_transac = 0; $form = ''; foreach ($this->members as $empr) { if ($pmb_gestion_abonnement) { $cpt_id = comptes::get_compte_id_from_empr($empr['id'], 1); if ($cpt_id) { $cpt = new comptes($cpt_id); $solde_abonnement+= $cpt->update_solde(); $novalid_abonnement+= $cpt->summarize_transactions("", "", 0, 0); } } if ($pmb_gestion_tarif_prets) { $cpt_id = comptes::get_compte_id_from_empr($empr['id'], 3); if ($cpt_id) { $cpt = new comptes($cpt_id); $solde_prets+= $cpt->update_solde(); $novalid_prets+= $cpt->summarize_transactions("", "", 0, 0); } } if ($pmb_gestion_amende) { $cpt_id = comptes::get_compte_id_from_empr($empr['id'], 2); if ($cpt_id) { $cpt = new comptes($cpt_id); $solde_amende+= $cpt->update_solde(); $novalid_amende+= $cpt->summarize_transactions("", "", 0, 0); //Calcul des amendes $amende = new amende($empr['id'],true); $total_amende+= $amende->get_total_amendes(); $nb_amendes+= $amende->nb_amendes; } } // Autre compte, que s'il y a des types de transaction $transactype = new transactype_list(); if ($transactype->get_count()) { $cpt_id = comptes::get_compte_id_from_empr($empr['id'], 4); if ($cpt_id) { $cpt = new comptes($cpt_id); $solde_transac+= $cpt->update_solde(); $novalid_transac+= $cpt->summarize_transactions("", "", 0, 0); } } } // construnction du formulaire if ($solde_abonnement || $novalid_abonnement) { $form.= "
".$msg["finance_solde_abt"]." ".comptes::format($solde_abonnement)."
"; if ($novalid_abonnement) $form.= "
".$msg["finance_not_validated"]." : ".comptes::format($novalid_abonnement)."
"; $form.= "
"; } if ($solde_prets || $novalid_prets) { $form.= "
".$msg["finance_solde_pret"]." ".comptes::format($solde_prets)."
"; if ($novalid_prets) $form.= "
".$msg["finance_not_validated"]." : ".comptes::format($novalid_prets)."
"; $form.= "
"; } if ($solde_amende || $novalid_amende) { $form.= "
".$msg["finance_solde_amende"]." ".comptes::format($solde_amende)."
"; if ($novalid_amende) $form.= "
".$msg["finance_not_validated"]." : ".comptes::format($novalid_amende)."
"; if ($total_amende) $form.= "
".$msg["finance_pret_amende_en_cours"]." : ".comptes::format($total_amende)."
"; $form.= "
"; } if ($solde_transac || $novalid_transac) { $form.= "
".$msg["transactype_empr_compte"]." ".comptes::format($solde_transac)."
"; if ($novalid_transac) $form.= "
".$msg["finance_not_validated"]." : ".comptes::format($novalid_transac)."
"; $form.= "
"; } return $form; } public function get_encaissement_rapide_form() { global $charset, $msg; global $show_transactions, $typ_compte, $date_debut, $pmb_gestion_devise; $somme = 0; $solde = 0; $val_transactions = ""; foreach ($this->members as $empr) { $id_compte = comptes::get_compte_id_from_empr($empr['id'], $typ_compte); $cpte = new comptes($id_compte); //Validation de ce qui n'est pas valide $t = $cpte->get_transactions("", "", 0, 0); if(is_array($t) && count($t)) { for ($i = 0; $i < count($t); $i++) { if ($cpte->validate_transaction($t[$i]->id_transaction)) { $somme+= $t[$i]->montant*$t[$i]->sens; $val_transactions.= " #".$t[$i]->id_transaction."#"; } } $transacash_num = $cpte->cashdesk_memo_transactions($t); } $solde_avant = $cpte->get_solde(); if ($solde_avant != 0) $val_transactions.= $msg["finance_enc_tr_lib_etat_compte"]." : ".$solde_avant; $cpte->update_solde(); $solde+= $cpte->get_solde(); } if ($val_transactions != "") $val_transactions = $msg["finance_enc_tr_lib_valider"]." : ".$val_transactions."\n"; $form = ''; if ($solde < 0) { $form = "

".htmlentities($this->libelle)." : ".comptes::get_typ_compte_lib($typ_compte)."

"; if ($solde <= 0) { $form.= " "; }elseif ($solde > 0) { $form.= " "; } $form.= "
".$msg["finance_enc_montant_valide"]." : ".comptes::format($somme*(-1))."
".$msg["finance_enc_montant_a_enc"]." :
".$msg["finance_enc_compte_cred"]." : ".comptes::format($solde*(-1))."
". htmlentities($msg['finance_mnt_percu'], ENT_QUOTES, $charset)."  ".$pmb_gestion_devise." " . transaction_payment_method_list::get_selector() . "  
"; } else { $form.= ""; } return $form; } public function do_encaissement_rapide() { global $msg; global $show_transactions, $typ_compte, $date_debut; global $somme, $f_payment_method, $transacash_num, $val_transactions; $somme_restante = $somme*1; $f_payment_method = intval($f_payment_method); if(empty($f_payment_method)) $f_payment_method = 1; if ($somme_restante > 0) { foreach ($this->members as $empr) { if ($somme_restante <= 0) { // toute la somme donnée est encaisée break; } $id_compte = comptes::get_compte_id_from_empr($empr['id'], $typ_compte); $cpte = new comptes($id_compte); $solde_empr = $cpte->get_solde(); if ($solde_empr < 0) { if (round($somme_restante - abs($solde_empr), 2) >= 0) { // la totalité de ce que doit l'emprunteur est encaissée $encaisser = abs($solde_empr); $somme_restante = round($somme_restante - abs($solde_empr), 2); } else { // Une partie (la somme restante) de ce que doit l'emprunteur est encaissée $encaisser = $somme_restante; $somme_restante = 0; } // Generation de la transaction if (($id_transaction = $cpte->record_transaction("", $encaisser, 1, $val_transactions, $f_payment_method))) { $cpte->validate_transaction($id_transaction); $cpte->update_solde(); if (!$transacash_num) { $req = "select MAX(transacash_num) from transactions where compte_id=".$cpte->id_compte; $resultat = pmb_mysql_query($req); if ($transacash_num = pmb_mysql_result($resultat, 0, 0)) { $req = "update transactions set transacash_num = $transacash_num where compte_id=".$cpte->id_compte." and transacash_num=0"; pmb_mysql_query($req); } } $cpte->cashdesk_memo_encaissement($id_transaction, $transacash_num, $encaisser); } } } if ($somme_restante > 0) { // Trop percu, il faut rendre la monnaie return ""; } } return ""; } public function transactions_proceed() { global $act; switch ($act) { case 'valenc': print $this->get_encaissement_rapide_form(); break; case "enc": print $this->do_encaissement_rapide(); break; default: print $this->get_transactions_form(); break; } } public function get_nb_loans() { if(!isset($this->nb_loans)) { $this->nb_loans = 0; $query = "SELECT count( pret_idempr ) as nb_pret FROM empr_groupe,pret where groupe_id=".$this->id." and empr_id = pret_idempr"; $result = pmb_mysql_query($query); if (pmb_mysql_num_rows($result)) { $row=pmb_mysql_fetch_object($result); $this->nb_loans = $row->nb_pret; } } return $this->nb_loans; } public function get_nb_resas() { if(!isset($this->nb_resas)) { $this->nb_resas = 0; $query = "SELECT count( resa_idempr ) as nb_resa FROM empr_groupe,resa where groupe_id=".$this->id." and empr_id = resa_idempr"; $result = pmb_mysql_query($query); if (pmb_mysql_num_rows($result)) { $row=pmb_mysql_fetch_object($result); $this->nb_resas = $row->nb_resa; } } return $this->nb_resas; } }