Commit 32d3e9cc authored by thejoelinux's avatar thejoelinux

work in progress

parent f1d1d307
<?php
class Payment extends Record {
public $id;
public $subscription_id, $payment_method_id;
public $amount, $comment;
public $check_bank_name, $check_owner_name;
public $created_at;
public static $table = "lud_payments";
public function __construct($id = 0) {
if (!$this->id) {
$this->id = $id;
}
}
/*
* function fetch_all
* fetches all payments for a given subscription, in an array by ref
* @return the number of payments
*/
public static function fetch_all(&$payments, $subscription_id) {
$payments = array();
// SQL SELECT lud_payments
$sql = "SELECT id, payment_method_id, amount, comment,
check_bank_name, check_owner_name, created_at
FROM ".Payment::$table."
WHERE subscription_id = $subscription_id
ORDER BY id";
$GLOBALS["data"]->select($sql, $payments, "Payment", 1);
return sizeof($payments);
}
public static function fetch($id) {
// SQL SELECT lud_payments
$sql = "SELECT id, payment_method_id, amount, comment,
check_bank_name, check_owner_name, created_at
FROM ".Payment::$table."
WHERE id = ".$id;
$GLOBALS["data"]->select($sql, $payment, "Payment");
return $payment;
}
}
......@@ -21,35 +21,40 @@ class Subscription extends Record {
}
public static function fetch($id) {
// SQL SELECT lud_subscriptions lud_membership_types lud_payment_methods lud_members
// SQL SELECT lud_subscriptions lud_membership_types lud_members
$sql = " SELECT ms.id, start_date, end_date, ms.member_id, CONCAT(m.lastname, ' ', m.firstname) as member_name,
ms.membership_type_id, mt.name as membership_type_name,
ms.payment_method_id, pm.name as payment_method_name,
COUNT(p.id) AS num_payment, sum(p.amount) AS total_payment,
ms.price, credit, ms.comments, ms.created_at, ms.updated_at,
DATEDIFF(end_date, curdate()) as remaining_days
FROM ".Subscription::$table." ms, ".Member::$table." m, ".Membership_Type::$table." mt, ".Payment_Method::$table." pm
FROM ".Subscription::$table." ms, ".Member::$table." m, ".Membership_Type::$table." mt, ".Payment::$table." p
WHERE ms.id = ".$id."
AND ms.member_id = m.id
AND ms.membership_type_id = mt.id
AND ms.payment_method_id = pm.id
AND ms.id = p.subscription_id
";
$GLOBALS["data"]->select($sql, $subscription, "Subscription");
return $subscription;
}
/*
* function fetch_all
* fetches all subscriptions for a member in an array by ref
* @return the number of subscriptions
*/
public static function fetch_all(&$subscriptions, $member_id) {
$subscriptions = array();
// SQL SELECT lud_subscriptions lud_members lud_membership_types lud_payment_methods
// SQL SELECT lud_subscriptions lud_members lud_membership_types
$sql = " SELECT ms.id, start_date, end_date, ms.member_id, CONCAT(m.lastname, ' ', m.firstname) as member_name,
ms.membership_type_id, mt.name as membership_type_name,
ms.payment_method_id, pm.name as payment_method_name,
ms.membership_type_id, mt.name as membership_type_name,
COUNT(p.id) AS num_payment, sum(p.amount) AS total_payment,
ms.price, credit, ms.comments, ms.created_at, ms.updated_at,
DATEDIFF(end_date, curdate()) as remaining_days
FROM ".Subscription::$table." ms, ".Member::$table." m, ".Membership_Type::$table." mt, ".Payment_Method::$table." pm
FROM ".Subscription::$table." ms, ".Member::$table." m, ".Membership_Type::$table." mt, ".Payment::$table." p
WHERE member_id = ".$member_id."
AND ms.member_id = m.id
AND ms.membership_type_id = mt.id
AND ms.payment_method_id = pm.id
AND ms.id = p.subscription_id
ORDER BY end_date DESC
";
$GLOBALS["data"]->select($sql, $subscriptions, "Subscription", true);
......
......@@ -196,14 +196,18 @@ class AppController {
}
function _edit($success = "edit") {
$classname = $this->model;
$object = $classname::fetch($GLOBALS["data"]->db_escape_string($_REQUEST["i"]));
if($this->format == "json") {
echo json_encode($object);
exit();
}
$this->set("object", $object);
return $_REQUEST["o"]."/".$success;
try {
$classname = $this->model;
$object = $classname::fetch($GLOBALS["data"]->db_escape_string($_REQUEST["i"]));
if($this->format == "json") {
echo json_encode($object);
exit();
}
$this->set("object", $object);
return $_REQUEST["o"]."/".$success;
} catch(data_exception $e) {
return "data_exception";
}
}
function _update() {
......
......@@ -21,6 +21,22 @@ class SubscriptionsController extends AppController {
return $_REQUEST["o"]."/edit";
}
function _payments() {
try {
$subscription = Subscription::fetch($GLOBALS["data"]->db_escape_string($_REQUEST["i"]));
$payments = array();
Payment::fetch_all($payments, $subscription->id);
if($this->format == "json") {
echo json_encode($payments);
exit();
} else {
return "payments/list";
}
} catch(data_exception $e) {
return "data_exception";
}
}
function _print() {
try {
$subscription = Subscription::fetch($GLOBALS["data"]->db_escape_string($_REQUEST["i"]));
......
......@@ -24,9 +24,9 @@
<th>Début</th>
<th>Fin</th>
<th>Type</th>
<th>Prix</th>
<th>Paiement</th>
<th>Crédit</th>
<th>Prix</th>
<th>Notes</th>
<th>Actions</th>
</tr>
......@@ -37,15 +37,19 @@
<td>{{ val.start_date | date("d/m/Y") }}</td>
<td>{{ val.end_date | date("d/m/Y") }}</td>
<td>{{ val.membership_type_name }}</td>
<td>{{ val.payment_method_name }}</td>
<td>{{ val.credit ? "Oui" : "Non" }}</td>
<td>{{ val.price }}</td>
<td>{{ val.total_payment }}</td>
<td>{{ val.credit ? "Oui" : "Non" }}</td>
<td>{{ val.comments }}</td>
<td>
<button type="button" class="btn btn-success btn-sm"
data-toggle="modal" data-target="#editModal" data-id="{{ val.id }}">
<i class="glyphicon glyphicon-edit"></i>
</button>
<button type="button" class="btn btn-success btn-sm"
data-toggle="modal" data-target="#paymentModal" data-id="{{ val.id }}">
<i class="glyphicon glyphicon-euro"></i>
</button>
<button type="button" class="btn btn-default btn-sm button_print" data-id="{{ val.id }}">
<i class="glyphicon glyphicon-print"></i>
</button>
......@@ -74,6 +78,14 @@
</div>
</div>
<!-- end edit modal -->
<!-- payment modal skel -->
<div class="modal fade" id="paymentModal" tabindex="-1" role="dialog" aria-labelledby="paymentModalLabel">
<div class="modal-dialog">
<div class="modal-content">
</div>
</div>
</div>
<!-- end edit modal -->
<script>
$(document).ready(function () {
......@@ -89,7 +101,12 @@ $(document).ready(function () {
}
}).on("hidden.bs.modal", function(e) {
$(this).find(".modal-content").empty();
});
$("#paymentModal").on("show.bs.modal", function(e) {
var button = $(e.relatedTarget);
$(this).find(".modal-content").load("index.php?o=" + $('#a').val() + "&a=payments&i=" + button.data('id'));
}).on("hidden.bs.modal", function(e) {
$(this).find(".modal-content").empty();
});
$('#object_list').on('click', '.button_delete', function(e){
if(confirm('Êtes vous sur ?')) {
......
......@@ -77,28 +77,9 @@
}});
</script>
</div>
<label class="control-label col-sm-2" for="payment_method_id">Méthode de paiement</label>
<label class="control-label col-sm-2" for="payment_method_id">Paiements</label>
<div class="col-sm-4">
<select id="payment_method_id" name="payment_method_id" class="form-control">
</select>
<script>
$('#payment_method_id').html('<option value="">Loading...</option>');
$.ajax({url: 'api.php?o=payment_methods&a=list',
success: function(output) {
var html = '';
$.each(output, function(key, val){
html = html + '<option value="' + val.id + '"'
+ (val.id == {{ object.payment_method_id ?: 0 }} ? ' selected ' : '' ) + '>'
+ val.name + '</option>';
});
$('#payment_method_id').html(html);
},
error: function (xhr, ajaxOptions, thrownError) {
// well, that's weird, ok :)
$('#payment_method_id').html('<option value="">' + xhr.status + ' ' + thrownError + '</option>');
// alert(xhr.status + " " + thrownError);
}});
</script>
FIXME : link
</div>
</div>
<div class="form-group">
......
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