Commit 9e23c458 authored by thejoelinux's avatar thejoelinux

deplacement des payment_methods dans la compta

parent 12f033a9
......@@ -11,9 +11,7 @@ CREATE TABLE `lud_payments` (
`created_at` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `subscription_id` (`subscription_id`),
KEY `payment_method_id` (`payment_method_id`),
CONSTRAINT `lud_payments_ibfk_1` FOREIGN KEY (`subscription_id`) REFERENCES `lud_subscriptions` (`id`),
CONSTRAINT `lud_payments_ibfk_2` FOREIGN KEY (`payment_method_id`) REFERENCES `lud_payment_methods` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO lud_payments (subscription_id, payment_method_id, amount, comments, created_at)
......@@ -32,3 +30,11 @@ CREATE TABLE lud_subscriptions_bck AS SELECT * FROM lud_subscriptions;
ALTER TABLE `lud_subscriptions` DROP FOREIGN KEY `fk_member_sub_payment_method_id`;
ALTER TABLE `lud_subscriptions` CHANGE `payment_method_id` `payment_method_id_bck` INT(11) NOT NULL;
DROP TABLE lud_payment_methods;
alter table lud_payments add payment_method_name varchar(32) not NULL after payment_method_id;
update lud_payments set payment_method_name = 'ludotheque_new_payment_check' where payment_method_id = 1;
update lud_payments set payment_method_name = 'ludotheque_new_payment_cash' where payment_method_id = 2;
alter table lud_payments drop column payment_method_id;
......@@ -44,12 +44,6 @@ class data {
return mysqli_real_escape_string($this->db_handle, $string);
}
public static function log($sql) {
error_log("-------------------");
error_log(preg_replace("/\n/", " ", $sql));
error_log("-------------------");
}
public function find($query, &$rset, $object) {
$this->select($query, $rset, $object);
if(!is_object($rset)) {
......
......@@ -3,7 +3,7 @@
class Payment extends Record {
public $id;
public $subscription_id;
public $payment_method_name, $payment_method_id;
public $payment_method_name;
public $amount, $comments;
public $check_bank_name, $check_owner_name;
public $created_at;
......@@ -24,12 +24,11 @@ class Payment extends Record {
public static function fetch_all(&$payments, $subscription_id) {
$payments = array();
// SQL SELECT lud_payments
$sql = "SELECT p.id, p.payment_method_id, pm.name AS payment_method_name,
$sql = "SELECT p.id, p.payment_method_name,
p.amount, p.comments,
p.check_bank_name, p.check_owner_name, p.created_at
FROM ".Payment::$table." p, ".Payment_Method::$table." pm
FROM ".Payment::$table." p
WHERE p.subscription_id = $subscription_id
AND p.payment_method_id = pm.id
ORDER BY p.id";
$GLOBALS["data"]->select($sql, $payments, "Payment", 1);
return sizeof($payments);
......@@ -37,7 +36,7 @@ class Payment extends Record {
public static function fetch($id) {
// SQL SELECT lud_payments
$sql = "SELECT id, payment_method_id, amount, comments,
$sql = "SELECT id, payment_method_name, amount, comments,
check_bank_name, check_owner_name, created_at
FROM ".Payment::$table."
WHERE id = ".$id;
......@@ -46,11 +45,11 @@ class Payment extends Record {
}
public static function create_from_post($subscription_id, $payment_method_id,
public static function create_from_post($subscription_id, $payment_method_name,
$comments, $amount) {
$payment = new Payment();
$payment->subscription_id = $subscription_id;
$payment->payment_method_id = $payment_method_id;
$payment->payment_method_name = $payment_method_name;
$payment->comments = $comments;
$payment->amount = $amount;
$payment->save();
......@@ -59,8 +58,8 @@ class Payment extends Record {
public function save() {
// SQL INSERT lud_payments
$sql = " INSERT INTO ".Payment::$table." (subscription_id, payment_method_id, amount, comments)
VALUES ('".$this->subscription_id."', '".$this->payment_method_id."',
$sql = " INSERT INTO ".Payment::$table." (subscription_id, payment_method_name, amount, comments)
VALUES ('".$this->subscription_id."', '".$this->payment_method_name."',
'".$this->amount."', '".$this->comments."' )";
$this->id = $GLOBALS["data"]->insert($sql);
}
......
<?php
class Payment_Method extends Record {
public $id, $name, $description;
public static $table = "lud_payment_methods";
<?php
public function __construct($id = 0) {
if (!$this->id) {
$this->id = $id;
}
}
class Payment_Method {
public static function fetch_all(&$payment_methods) {
$payment_methods = array();
// SQL SELECT lud_payment_methods
$sql = "SELECT id, name, description
FROM ".Payment_Method::$table."
ORDER BY name";
$GLOBALS["data"]->select($sql, $payment_methods, "Payment_Method", 1);
return sizeof($payment_methods);
// call to the compta API
public static function fetch_all() {
return Saas_Service::call("compta", "payment_methods", "list",
array());
}
public static function fetch($id) {
// SQL SELECT lud_payment_methods
$sql = "SELECT id, name, description
FROM ".Payment_Method::$table."
WHERE id = ".$id;
$GLOBALS["data"]->select($sql, $payment_method, "Payment_Method");
return $payment_method;
}
// FIXME : hey you can't just delete like that
// if the payment method is used somewhere, that
// can't be done
// so overload the record method
public function validate_input(&$errors) {
$v = new Valitron\Validator($_REQUEST);
$v->rule('required', ['name', 'description']);
$v->labels(array(
'name' => 'Le nom',
'description' => 'La description'
));
if($v->validate()) {
$errors = null;
return true;
} else {
// Errors
$errors = $v->errors();
return false;
}
}
}
<?php
class PaymentMethodsController extends AppController {
public $model = "Payment_Method";
function PaymentMethodsController() {
$this->AppController();
$function_name = "_".$_REQUEST["a"];
// to the view
try {
$render = $this->$function_name();
} catch (object_not_found_exception $e) {
$this->http_error(404);
if($this->format == "json") {
echo "{}";
exit();
}
$render = $_REQUEST["o"]."/not_found"; // TODO
} catch (data_exception $e) {
$this->http_error(500);
if($this->format == "json") {
exit();
}
$render = "data_exception";
}
// view part
$this->render($render);
}
function _index() {
return $this->_list();
}
}
......@@ -17,18 +17,16 @@ class PaymentsController extends AppController {
// is not greater than its price
$payment = Payment::create_from_post(
$GLOBALS["data"]->db_escape_string($_REQUEST["subscription_id"]),
$GLOBALS["data"]->db_escape_string($_REQUEST["payment_method_id"]),
$GLOBALS["data"]->db_escape_string($_REQUEST["payment_method_name"]),
$GLOBALS["data"]->db_escape_string($_REQUEST["comments"]),
$GLOBALS["data"]->db_escape_string($_REQUEST["amount"]));
$payment_method = Payment_Method::fetch($payment->payment_method_id);
$payment->payment_method_name = $payment_method->name;
$this->set("payment", $payment);
Account::ludotheque_new_payment(
"Paiement adhésion #".$payment->subscription_id." - ".$payment->comments,
date("Y-m-d"),
Member::fetch_account_from_subscription($payment->subscription_id),
$payment->amount, $payment_method->description);
$payment->amount, $payment->payment_method_name);
return "payments/single_payment";
} catch (data_exception $e) {
......
......@@ -26,13 +26,22 @@ class SubscriptionsController extends AppController {
$subscription = Subscription::fetch($GLOBALS["data"]->db_escape_string($_REQUEST["i"]));
$subscription->payments = array();
Payment::fetch_all($subscription->payments, $subscription->id);
$payment_methods = Payment_Method::fetch_all();
while(list($key, $val) = each($payment_methods)) {
$desc[$val->method] = $val->name;
}
reset($payment_methods);
// complement the name by a more human readable description
while(list($key, $val) = each($subscription->payments)) {
$subscription->payments[$key]->description = $desc[
$subscription->payments[$key]->payment_method_name];
}
if($this->format == "json") {
echo json_encode($subscription->payments, JSON_PRETTY_PRINT);
exit();
} else {
$payment_methods = array();
Payment_Method::fetch_all($payment_methods);
$this->set("methods", $payment_methods);
$this->set("object", $subscription);
return "payments/list";
}
......
......@@ -44,7 +44,6 @@
{% endif %}
{% if roles.members %}
<li><a href="index.php?o=membership_types&a=list">Types d'adhésion</a></li>
<li><a href="index.php?o=payment_methods&a=list">Méthodes de paiement</a></li>
{% endif %}
</ul>
</li>
......
{% extends 'modal_api.html' %}
{% block modal_title %}
{% if object.id %} Méthode de paiement : {{ object.name }} {% else %} Nouvelle méthode de paiement {% endif %}
{% endblock %}
{% block modal_body %}
<div class="alert alert-info alert-dismissible" role="alert" style="display: none" id="created_ok">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<span class="glyphicon glyphicon-ok"></span>
Création effectuée
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="name">Nom</label>
<div class="col-sm-10">
<input type="text" id="name" name="name" class="form-control" value="{{ object.name }}"/>
<span id="help-name" class="help-block" style="display: none"></span>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="description">Description</label>
<div class="col-sm-10">
<textarea id="description" name="description" class="form-control" rows="4">{{ object.description }}</textarea>
<span id="help-description" class="help-block" style="display: none"></span>
</div>
</div>
{% endblock %}
{% block javascript_fields %}
var fields = ['name', 'description'];
{% endblock %}
{% block javascript_msg %}
var msg = 'Voulez-vous réellement supprimer cette méthode de paiement ?\n' +
'Cette action n\'est possible que si cette méthode n\'a pas été\n' +
'utilisée pour l\'inscription d\'un adhérent.';
{% endblock %}
{% extends "base.html" %}
{% block title %}Méthode de paiement{% endblock %}
{% block content %}
<div class="panel panel-default">
<div class="panel-heading">
<span style="font-size: 150%;" class="glyphicon glyphicon-user"></span>
<span style="font-size: 150%; font-weight: bold">
Méthodes de paiement
</span>
<button type="button" class="btn btn-success btn-md" style="float: right"
data-toggle="modal" data-target="#editModal" data-id="0">
<i class="glyphicon glyphicon-plus"></i>
<span>Nouvelle méthode...</span>
</button>
</div>
</div>
<div class="panel-body">
{% include 'ihm_messages.html' %}
<div class="col-sm-12" align="center">
<table id="object_list" style="display:none">
<thead>
<tr>
<th>Nom</th>
<th>Description</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for key, val in objects %}
<tr>
<td>{{ val.name }}</td>
<td>{{ val.description }}</td>
<td align="center">
<button type="button" class="btn btn-success btn-xs"
data-toggle="modal" data-target="#editModal" data-id="{{ val.id }}">
<i class="glyphicon glyphicon-edit"></i>
</button>
<a href="#" onClick="if(confirm('Êtes vous sur ?')) { $('#a').val('delete'); $('#i').val('{{ val.id }}'); defaultform.submit()}" href="#">
<button type="button" class="btn btn-danger btn-xs">
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button>
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
<!-- end of panel -->
</div>
</div>
<!-- edit modal skel -->
<div class="modal fade" id="editModal" tabindex="-1" role="dialog" aria-labelledby="editModalLabel">
<div class="modal-dialog">
<div class="modal-content">
</div>
</div>
</div>
<!-- end edit modal -->
<script>
$(document).ready(function() {
$('#object_list').DataTable({
"autoWidth": false,
"language": {
"emptyTable": "Aucun moyen de paiement n'a été trouvé."
},
"columnDefs": [{ "orderable": false, "targets": -1 }],
"fnDrawCallback": function() {
$(this).show();
}
});
$("#editModal").on("show.bs.modal", function(e) {
var button = $(e.relatedTarget);
if(button.data('id') == 0) {
$(this).find(".modal-content").load("index.php?o=" + $('#o').val() + "&a=new");
} else {
$(this).find(".modal-content").load("index.php?o=" + $('#o').val() + "&a=edit&i=" + button.data('id'));
}
}).on("hidden.bs.modal", function(e) {
$(this).find(".modal-content").empty();
});
});
/* FIXME : translation of the table
see https://datatables.net/plug-ins/i18n/French
*/
</script>
{% endblock %}
......@@ -17,18 +17,39 @@
<div id="new_payment">
<div class="form-group">
<label class="control-label col-md-2" for="payment_method_id">Méthode</label>
<div class="col-md-3">
<select id="payment_method_id" name="payment_method_id" class="form-control">
<option value="0" selected >Methode...</option>{% for key2, val2 in methods
%}<option value="{{ val2.id }}">{{ val2.name }}</option>
{% endfor %}<select>
<label class="control-label col-md-2" for="payment_method_name">Méthode</label>
<div class="col-md-5">
<select id="payment_method_name" name="payment_method_name" class="form-control">
{% for key2, val2 in methods %}<option value="{{ val2.method }}">{{ val2.name }}</option>
{% endfor %}
<select>
<!--
<select id="payment_method_name" name="payment_method_name" class="form-control">
</select>
<script>
$('#payment_method_name').html('<option value="">Loading...</option>');
// FIXME : do not call compta directly, use the saas !!!!
$.ajax({url: '/ludotm/compta/webroot/rest/payment_methods',
success: function(output) {
var html = '';
$.each(output, function(key, val){
html = html + '<option value="' + val.method + '">'
+ val.description + '</option>';
});
$('#payment_method_name').html(html);
},
error: function (xhr, ajaxOptions, thrownError) {
// well, that's weird, ok :)
$('#payment_method_name').html('<option value="">' + xhr.status + ' ' + thrownError + '</option>');
// alert(xhr.status + " " + thrownError);
}});
</script>
-->
</div>
<label class="control-label col-md-2" for="amount">Montant</label>
<div class="col-md-3">
<div class="col-md-2">
<input style="text-align: right" type="text" class="form-control"
size="10" name="amount"
id="amount" align="right" value=""></div>
name="amount" id="amount" align="right" value=""></div>
</div>
<div class="form-group">
<label class="control-label col-md-2" for="comments">Note</label>
......@@ -61,7 +82,7 @@
$.post('index.php', {
o: 'payments', a: 'create', i: '',
subscription_id: $('#subscription_id').val(),
payment_method_id: $('#payment_method_id').val(),
payment_method_name: $('#payment_method_name').val(),
comments: $('#comments').val(),
amount: $('#amount').val()
})
......@@ -70,7 +91,7 @@
// set the new_payment fields to default values !
$('#amount').val('');
$('#comments').val('');
$("#payment_method_id").prop('selectedIndex',0);
$("#payment_method_name").prop('selectedIndex',0);
});
return true;
});
......
<div class="form-group payment_{{ payment.id }}" id="payment_{{ payment.id }}">
<div class="col-md-2">
{{ payment.payment_method_name }}
{{ payment.description }}
</div>
<div class="col-md-6">
{{ payment.comments }}
......
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