Commit 6e1d5b52 authored by Denis S. Valdenaire's avatar Denis S. Valdenaire

fixes #48

parent e17f1e03
......@@ -27,7 +27,7 @@ class Game extends Record {
g.price, g.players_min, g.players_max,
g.age_min, g.age_max, g.game_type,
l.id as loan_id, l.end_date AS loan_end_date,
r.id AS reservation_id, r.member_id, r.reservation_date,
r.id AS reservation_id, r.member_id AS reservation_member_id, r.reservation_date,
CONCAT(m.firstname, ' ', m.lastname) AS reservation_member_name
FROM games g
LEFT OUTER JOIN loans l ON (g.id = l.game_id AND l.is_back = 0)
......
......@@ -28,7 +28,7 @@ class Loan extends Record {
g.id = l.game_id
".($member_id == 0 ? "" : "AND l.member_id = ".$member_id)."
AND l.member_id = m.id
ORDER BY l.is_back ASC, start_date ASC
ORDER BY l.is_back ASC, start_date DESC
".($limit != 0 ? "LIMIT 0,$limit" : "");
$GLOBALS["data"]->select($sql, $loans, "Loan", true);
return sizeof($loans);
......@@ -65,7 +65,6 @@ class Loan extends Record {
}
public static function fetch($id) {
// SQL SELECT loans
$sql = " SELECT l.id, start_date, end_date, is_back, l.created_at, l.updated_at, member_id,
......@@ -93,11 +92,17 @@ class Loan extends Record {
return false;
}
function change_state($new_state) {
public function change_state($new_state) {
// update loans but also any reservation on the same game
// that's a multi-table update ! returns 1 or 2 depending
// on how many table have been updated
// SQL UPDATE loans
$sql = " UPDATE loans SET is_back = ".$new_state.",
updated_at = now()
WHERE id = ".$this->id;
$sql = " UPDATE loans l, reservations r
SET l.is_back = ".$new_state.", l.updated_at = now(),
r.available = ".$new_state.", r.updated_at = now()
WHERE l.id = ".$this->id."
AND l.game_id = r.game_id";
$this->is_back = $new_state;
return $GLOBALS["data"]->update($sql);
}
}
......@@ -9,7 +9,7 @@ class Member extends Record {
public $family_links;
public $subscriptions, $loans;
public $subscriptions, $loans, $reservations;
public $table = "members";
......@@ -22,7 +22,8 @@ class Member extends Record {
2 => "Conjoint",
3 => "Autre");
$this->subscriptions = array();
$this->loans = array();
$this->loans = array();
$this->reservations = array();
}
public static function get_family_link_name($id = 0) {
......@@ -85,6 +86,11 @@ class Member extends Record {
return $rset;
}
public function fetch_reservations() {
Reservation::fetch_all($this->reservations, $this->id);
return sizeof($this->reservations);
}
public function fetch_subscriptions() {
Subscription::fetch_all($this->subscriptions, $this->id);
$this->subscription_text = sizeof($this->subscriptions) ?
......
<?php
class Reservation extends Record {
public $id, $game_id, $member_id, $reservation_date;
public $id, $game_id, $member_id, $reservation_date, $available;
public $created_at, $updated_at;
public $member_name;
......@@ -15,15 +15,15 @@ class Reservation extends Record {
}
}
public static function fetch_all(&$reservations, $member_id, $limit = 0) {
public static function fetch_all(&$reservations, $member_id = 0, $limit = 0) {
$reservations = array();
// SQL SELECT reservations games members
$sql = " SELECT r.id, r.created_at, r.updated_at,
g.id AS game_id, g.name as game_name,
$sql = " SELECT r.id, r.created_at, r.updated_at, r.available,
g.id AS game_id, g.name as game_name,
CONCAT(m.firstname, ' ', m.lastname) AS member_name, m.id AS member_id
FROM reservations r, games g, members m
WHERE
g.id = r.game_id
g.id = r.game_id
".($member_id == 0 ? "" : "AND r.member_id = ".$member_id)."
AND r.member_id = m.id
ORDER BY r.created_at ASC
......@@ -34,7 +34,7 @@ class Reservation extends Record {
public static function fetch($id) {
// SQL SELECT reservations
$sql = " SELECT r.id, r.created_at, r.updated_at, r.member_id,
$sql = " SELECT r.id, r.created_at, r.updated_at, r.member_id, r.available,
g.name as game_name
FROM reservations r, games g
WHERE r.id = $id
......
......@@ -25,7 +25,9 @@ class LoansController extends AppController {
try {
$loan = Loan::fetch($GLOBALS["data"]->db_escape_string($_REQUEST["i"]));
if($loan->id != 0) {
$loan->change_state($GLOBALS["data"]->db_escape_string($_REQUEST["state"]));
$loan->reservation_avail =
($loan->change_state($GLOBALS["data"]->db_escape_string($_REQUEST["state"])) == 2)
? $loan->is_back : -1;
echo json_encode($loan);
exit();
} else {
......
......@@ -21,6 +21,7 @@ class MembersController extends AppController {
if($member->id != 0) {
$member->fetch_subscriptions();
$member->fetch_loans();
$member->fetch_reservations();
$this->set("member", $member);
return "members/edit";
} else {
......
-- for the games
update games set name = replace(name, 'É', 'É');
update games set name = replace(name, 'È', 'È');
update games set name = replace(name, 'À', 'À');
update games set name = replace(name, 'é', 'é');
update games set name = replace(name, 'ÃŽ', 'Î');
update games set name = replace(name, 'Ê', 'Ê');
update games set name = replace(name, 'Ô', 'Ô');
update games set name = replace(name, 'Ä', 'ä');
update games set name = replace(name, 'OÙ', 'Ù');
update games set name = replace(name, 'Ï', 'Ï');
update games set name = replace(name, 'Ö', 'ö');
update members set lastname = replace( lastname, 'É', 'É');
update members set firstname = replace( firstname, 'É', 'É');
update members set firstname = replace( firstname, 'é', 'é');
update members set po_town = replace( po_town, 'è', 'è');
update members set po_town = replace( po_town, 'É', 'É');
update members set other_members = replace( other_members, 'É', 'É');
update members set other_members = replace( other_members, 'È', 'È');
update members set other_members = replace( other_members, 'é', 'é');
update members set other_members = replace( other_members, 'ô', 'ô');
update members set other_members = replace( other_members, 'ç', 'ç');
update members set firstname = replace( firstname, 'ç', 'ç');
update members set address = replace( address, 'ë', 'ë');
update members set address = replace( address, 'é', 'é');
update members set firstname = replace( firstname, 'è', 'ê';
update members set firstname = replace( firstname, 'ë', 'æ');
update members set firstname = replace( firstname, 'ë', 'ë');
update members set address = replace( address, 'ô', 'ô');
update members set address = replace( address, 'ê', 'ê');
update members set address = replace( address, 'É', 'É');
update members set address = replace( address, 'è', 'è');
update members set po_town = replace( po_town, 'â', 'â');
update members set other_members = replace( other_members, 'ë', 'ë');
update members set other_members = replace( other_members, 'Ç', 'Ç');
update members set other_members = replace( other_members, 'è', 'è');
update members set other_members = replace( other_members, 'î', 'î');
update members set other_members = replace( other_members, 'ï', 'ï');
insert into schema_migrations values ('201512271652');
......@@ -15,18 +15,18 @@
INDISPONIBLE :
jusqu'au {{ game.loan_end_date | date("d/m/Y") }}
</span>
<button type="button" class="btn btn-primary btn-md"
style="float: right; margin-right: 20px"
data-toggle="modal" data-target="#editModal" data-id="reservations">
<i class="glyphicon glyphicon-plus"></i>
<span>Réserver...</span>
</button>
{% else %}
<span class="label label-success">
DISPONIBLE
</span>
{% endif %}
</small>
<button type="button" class="btn btn-primary btn-md"
style="float: right; margin-right: 20px"
data-toggle="modal" data-target="#editModal" data-id="reservations">
<i class="glyphicon glyphicon-plus"></i>
<span>Réserver...</span>
</button>
<button type="button" class="btn btn-primary btn-md"
style="float: right; margin-right: 20px"
data-toggle="modal" data-target="#editModal" data-id="loans">
......
......@@ -8,7 +8,8 @@
</div>
<div class="modal-body">
{% if game.reservation_id %}
Ce jeu est déjà réservé par {{ game.reservation_member_name }}
Ce jeu est déjà réservé par
<a href="index.php?o=members&a=edit&i={{ game.reservation_member_id }}">{{ game.reservation_member_name }}</a>
pour le {{ game.reservation_date | date ("d/m/Y") }}
{% else %}
<div class="form-group">
......
......@@ -6,7 +6,12 @@
<div class="panel panel-default">
<div class="panel-heading">
<h4><span class="glyphicon glyphicon-user" style="margin-right: 10px" ></span>
{% if member.id %} {{ member.lastname }} {{ member.firstname }} {% else %} Nouvel adhérent {% endif %}
{% if member.id %}
{{ member.lastname }} {{ member.firstname }}
{% if member.reservations %}
<span class="label label-info">Réservations en cours</span>
{% endif %}
{% else %} Nouvel adhérent {% endif %}
</h4>
</div>
<div class="panel-body">
......
{% extends "base.html" %}
{% block title %}Catalogue des jeux{% endblock %}
{% block title %}Liste des adhérents{% endblock %}
{% block content %}
<div class="panel panel-default">
<div class="panel-heading">
......
{% extends "base.html" %}
{% block title %}{{ member.lastname }} {{ member.firstname }} - Adhésions{% endblock %}
{% block title %}{{ member.lastname }} {{ member.firstname }} - Emprunt{% endblock %}
{% block content %}
<div class="panel panel-default">
<div class="panel-heading">
......@@ -109,11 +109,18 @@ $(document).ready(function () {
var myXhr = $.ajaxSettings.xhr();
return myXhr;
},
success: function(){
if(state == 1) {
alert('Le jeu est noté comme restitué aujourd\'hui.');
success: function(response){
var msg = (state == 1) ? 'Le jeu est noté comme restitué aujourd\'hui.'
: 'Le jeu est noté comme non restitué aujourd\'hui.';
// console.log(response);
if(response.reservation_avail >= 0) {
if(response.is_back == 1) {
alert(msg + ' Une réservation est maintenant disponible.');
} else {
alert(msg);
}
} else {
alert('Le jeu est noté comme non restitué aujourd\'hui.');
alert(msg);
}
},
error: function(){
......
......@@ -28,6 +28,9 @@
<tr>
<td>
<a href="index.php?o=games&a=edit&i={{ val.game_id }}">{{ val.game_name }}</a>
{% if val.available %}
<span class="label label-info">Disponible</span>
{% endif %}
</td>
<td>
<a href="index.php?o=members&a=edit&i={{ val.member_id }}">{{ val.member_name }}</a>
......@@ -44,7 +47,7 @@
</tr>
{% else %}
<tr>
<td colspan="3" align="center">Aucune réservation en cours</td>
<td colspan="4" align="center">Aucune réservation en cours</td>
</tr>
{% endfor %}
</tbody>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment