Manage paybacks should be working.
This commit is contained in:
parent
fd8647e678
commit
8d9a2bc1f1
2
.gitignore
vendored
2
.gitignore
vendored
@ -3,3 +3,5 @@
|
||||
old
|
||||
data/
|
||||
tmp/
|
||||
db_backups/*
|
||||
!db_backups/README
|
||||
|
1
TODO
1
TODO
@ -1,5 +1,6 @@
|
||||
Issues :
|
||||
========
|
||||
* Check CSRF everywhere ?
|
||||
|
||||
Improvements :
|
||||
==============
|
||||
|
@ -39,7 +39,7 @@
|
||||
// Setters
|
||||
// =======
|
||||
public function setId($id) {
|
||||
$this->users_in->setInvoiceId($id);
|
||||
$this->users_in->setPaybackId($id);
|
||||
$this->id = (int) $id;
|
||||
}
|
||||
|
||||
|
@ -6,12 +6,12 @@
|
||||
protected $payback_id = 0, $users_list;
|
||||
//users_list is a 2D array of users_id and amount between them
|
||||
//user1 owes amount to user2
|
||||
protected $TABLE_NAME = "Users_in_GlobalPayback";
|
||||
protected $TABLE_NAME = "Users_in_GlobalPaybacks";
|
||||
protected $fields = array(
|
||||
'global_payback_id'=>'int',
|
||||
'user1_id'=>'int',
|
||||
'user2_id'=>'int',
|
||||
'amount'=>'float'
|
||||
'amount'=>'int'
|
||||
);
|
||||
|
||||
public function __construct() {
|
||||
@ -114,9 +114,9 @@
|
||||
|
||||
foreach($this->users_list as $user1=>$temp) {
|
||||
foreach($temp as $user2=>$amount) {
|
||||
$query->bindParam(':user1_id', intval($user1));
|
||||
$query->bindParam(':user2_id', intval($user2));
|
||||
$query->bindParam(':amount', floatval($amount));
|
||||
$query->bindValue(':user1_id', intval($user1));
|
||||
$query->bindValue(':user2_id', intval($user2));
|
||||
$query->bindValue(':amount', floatval($amount));
|
||||
$query->execute();
|
||||
}
|
||||
}
|
||||
|
13
index.php
13
index.php
@ -678,8 +678,11 @@
|
||||
|
||||
case "manage_paybacks":
|
||||
if(empty($_GET['new'])) {
|
||||
$global_paybacks = new GlobalPayback();
|
||||
$global_paybacks = $global_paybacks->load();
|
||||
|
||||
$tpl->assign('list', true);
|
||||
$tpl->assign('global_paybacks', array(array("id"=>1, "date"=>"now")));
|
||||
$tpl->assign('global_paybacks', $global_paybacks);
|
||||
}
|
||||
else {
|
||||
if(!empty($_POST['users_in'])) {
|
||||
@ -689,7 +692,7 @@
|
||||
if(!is_dir('db_backups')) {
|
||||
mkdir('db_backups');
|
||||
}
|
||||
system("mysqldump -h ".MYSQL_HOST." -u ".MYSQL_LOGIN." -p ".MYSQL_PASSWORD." ".MYSQL_DB." > db_backup/".date('d-m-Y_H:i'));
|
||||
system("mysqldump -h ".MYSQL_HOST." -u ".MYSQL_LOGIN." -p ".MYSQL_PASSWORD." ".MYSQL_DB." > db_backups/".date('d-m-Y_H:i'));
|
||||
|
||||
$users_in = array();
|
||||
foreach($_POST['users_in'] as $user1_id) {
|
||||
@ -704,7 +707,7 @@
|
||||
$users_in[$user1_id][$user2_id] = 0;
|
||||
}
|
||||
else {
|
||||
$users_in[$user1_id][$user2_id] = -$users_in[$user1_id][$user2_id];
|
||||
$users_in[$user1_id][$user2_id] = -$users_in[$user2_id][$user1_id];
|
||||
$users_in[$user2_id][$user1_id] = 0;
|
||||
}
|
||||
}
|
||||
@ -763,6 +766,8 @@
|
||||
}
|
||||
}
|
||||
|
||||
var_dump($users_in);
|
||||
|
||||
$global_payback->setUsersIn($users_in);
|
||||
$global_payback->setDate(date('i'), date('G'), date('j'), date('n'), date('Y'));
|
||||
$global_payback->save();
|
||||
@ -771,7 +776,7 @@
|
||||
($cached_files = glob(raintpl::$cache_dir."*.rtpl.php")) or ($cached_files = array());
|
||||
array_map("unlink", $cached_files);
|
||||
|
||||
header('location: index.php?do=edit_users&'.$get_redir);
|
||||
header('location: index.php?do=manage_paybacks&'.$get_redir);
|
||||
exit();
|
||||
}
|
||||
|
||||
|
@ -39,6 +39,13 @@
|
||||
|
||||
//Create table "Paybacks"
|
||||
$db->query('CREATE TABLE IF NOT EXISTS '.$mysql_prefix.'Paybacks (id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, date DATETIME, invoice_id INT(11), KEY invoice_id (invoice_id), amount INT(11), from_user INT(11), to_user INT(11)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci');
|
||||
|
||||
// Create table "GlobalPaybacks"
|
||||
$db->query('CREATE TABLE IF NOT EXISTS '.$mysql_prefix.'GlobalPaybacks (id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, date DATETIME) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci');
|
||||
|
||||
// Create table "Users_in_GlobalPaybacks"
|
||||
$db->query('CREATE TABLE IF NOT EXISTS '.$mysql_prefix.'Users_in_GlobalPaybacks (global_payback_id INT(11) NOT NULL, KEY global_payback_id (global_payback_id), user1_id INT(11), user2_id INT(11), amount INT(11)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci');
|
||||
|
||||
} catch (PDOException $e) {
|
||||
$error = 'Unable to connect to database and create database, check your credentials and config.<br/>Error message : '.$e->getMessage().'.';
|
||||
}
|
||||
|
@ -4,12 +4,12 @@
|
||||
<h2>Manage global paybacks</h2>
|
||||
<p class="center"><a href="?do=manage_paybacks&new=1">Add a new global payback</a></p>
|
||||
|
||||
{if condition="count($global_paybacks) > 0"}
|
||||
{if condition="$global_paybacks !== FALSE"}
|
||||
<p>List of previous global paybacks :</p>
|
||||
<dl>
|
||||
{loop="$global_paybacks"}
|
||||
<dt>{$value['date']}</dt>
|
||||
<dd><a href="?do=see_paybacks&id={$value['id']}">Payback n°{$value['id']}</a></dd>
|
||||
<dt>{$value->getDate()}</dt>
|
||||
<dd><a href="?do=see_paybacks&id={$value->getId()}">Payback n°{$value->getId()}</a></dd>
|
||||
{/loop}
|
||||
</dl>
|
||||
{/if}
|
||||
|
@ -4,12 +4,12 @@
|
||||
<h2>Gérer les remboursements globaux</h2>
|
||||
<p class="center"><a href="?do=manage_paybacks&new=1">Ajouter un remboursement global</a></p>
|
||||
|
||||
{if condition="count($global_paybacks) > 0"}
|
||||
{if condition="$global_paybacks !== FALSE"}
|
||||
<p>Liste des remboursements globaux précédents :</p>
|
||||
<dl>
|
||||
{loop="$global_paybacks"}
|
||||
<dt>{$value['date']}</dt>
|
||||
<dd><a href="?do=see_paybacks&id={$value['id']}">Remboursement n°{$value['id']}</a></dd>
|
||||
<dt>{$value->getDate()}</dt>
|
||||
<dd><a href="?do=see_paybacks&id={$value->getId()}">Remboursement n°{$value->getId()}</a></dd>
|
||||
{/loop}
|
||||
</dl>
|
||||
{/if}
|
||||
|
Loading…
Reference in New Issue
Block a user