Commit e17f1e03 authored by Denis S. Valdenaire's avatar Denis S. Valdenaire

fixes #66

parent 1c399af7
......@@ -89,7 +89,7 @@ class Member extends Record {
Subscription::fetch_all($this->subscriptions, $this->id);
$this->subscription_text = sizeof($this->subscriptions) ?
$this->subscriptions[0]->text() : "Aucune adhésion trouvée";
$this->valid_subscription = $this->has_valid_subscription();
$this->valid_subscription = $this->has_valid_subscription($null);
// DEBUG echo "<pre>"; print_r($this); echo "</pre>";
}
......@@ -113,8 +113,9 @@ class Member extends Record {
$this->loans_text() : "Aucun emprunt trouvé";
}
public function has_valid_subscription() {
$cr = false;
public function has_valid_subscription(&$reasons = null) {
$cr = false;
$reasons = array();
if(sizeof($this->subscriptions)) {
while(list($key, $val) = each($this->subscriptions)) {
if($val->remaining_days > 0) {
......@@ -122,14 +123,22 @@ class Member extends Record {
}
}
reset($this->subscriptions);
if(!$cr) {
$reasons[] = "Aucune adhésion valide en cours.";
}
}
if($this->deposit) {
if($this->remaining_deposit_days < 0) {
if($this->remaining_deposit_days < 0) {
$reasons[] = "Dépôt de caution expiré.";
$cr = false;
}
} else {
} else {
$reasons[] = "Pas de dépôt de caution.";
$cr = false;
}
if($cr) {
$reasons[] = "L'emprunt est possible.";
}
return $cr;
}
......
......@@ -85,6 +85,22 @@ class MembersController extends AppController {
}
}
function _impossible_loan() {
try {
$member = Member::fetch($GLOBALS["data"]->db_escape_string($_REQUEST["i"]));
if($member->id != 0) {
$member->fetch_subscriptions();
$member->has_valid_subscription($reasons);
$this->set("member", $member);
$this->set("reasons", $reasons);
return "members/impossible_loan";
}
return "members/not_found";
} catch(data_exception $e) {
return "data_exception";
}
}
function _create_loan() {
$_REQUEST["a"] = "loans";
$this->context["request"] = $_REQUEST;
......
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title" id="myModalLabel">
<span class="glyphicon glyphicon-list-alt" style="margin-right: 10px;" ></span>
Impossible de faire un nouvel emprunt
</h4>
</div>
<div class="modal-body">
<ul>
{% for key, val in reasons %}
<li>{{ val }}</li>
{% endfor %}
</ul>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
......@@ -15,7 +15,8 @@
<span>Nouvel emprunt...</span>
</button>
{% else %}
<span class="btn btn-danger btn-md" style="float: right">
<span class="btn btn-danger btn-md" style="float: right"
data-toggle="modal" data-target="#editModal" data-id="impossible_loan">
<i class="glyphicon glyphicon-warning-sign"></i>
<span>Impossible de faire un nouvel emprunt.</span>
</span>
......@@ -85,7 +86,11 @@ $(document).ready(function () {
if(button.data('id') == 0) {
$(this).find(".modal-content").load("index.php?o=" + $('#a').val() + "&a=new&i={{ member.id }}");
} else {
$(this).find(".modal-content").load("index.php?o=" + $('#a').val() + "&a=edit&i=" + button.data('id'));
if(button.data('id') == 'impossible_loan') {
$(this).find(".modal-content").load("index.php?o=members&a=impossible_loan&i={{ member.id }}");
} else {
$(this).find(".modal-content").load("index.php?o=" + $('#a').val() + "&a=edit&i=" + button.data('id'));
}
}
}).on("hidden.bs.modal", function(e) {
$(this).find(".modal-content").empty();
......
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