Manage paybacks should be working.

This commit is contained in:
Phyks 2013-09-23 23:43:53 +02:00
parent fd8647e678
commit 8d9a2bc1f1
8 changed files with 31 additions and 16 deletions

2
.gitignore vendored
View File

@ -3,3 +3,5 @@
old old
data/ data/
tmp/ tmp/
db_backups/*
!db_backups/README

1
TODO
View File

@ -1,5 +1,6 @@
Issues : Issues :
======== ========
* Check CSRF everywhere ?
Improvements : Improvements :
============== ==============

View File

@ -39,7 +39,7 @@
// Setters // Setters
// ======= // =======
public function setId($id) { public function setId($id) {
$this->users_in->setInvoiceId($id); $this->users_in->setPaybackId($id);
$this->id = (int) $id; $this->id = (int) $id;
} }

View File

@ -6,12 +6,12 @@
protected $payback_id = 0, $users_list; protected $payback_id = 0, $users_list;
//users_list is a 2D array of users_id and amount between them //users_list is a 2D array of users_id and amount between them
//user1 owes amount to user2 //user1 owes amount to user2
protected $TABLE_NAME = "Users_in_GlobalPayback"; protected $TABLE_NAME = "Users_in_GlobalPaybacks";
protected $fields = array( protected $fields = array(
'global_payback_id'=>'int', 'global_payback_id'=>'int',
'user1_id'=>'int', 'user1_id'=>'int',
'user2_id'=>'int', 'user2_id'=>'int',
'amount'=>'float' 'amount'=>'int'
); );
public function __construct() { public function __construct() {
@ -114,9 +114,9 @@
foreach($this->users_list as $user1=>$temp) { foreach($this->users_list as $user1=>$temp) {
foreach($temp as $user2=>$amount) { foreach($temp as $user2=>$amount) {
$query->bindParam(':user1_id', intval($user1)); $query->bindValue(':user1_id', intval($user1));
$query->bindParam(':user2_id', intval($user2)); $query->bindValue(':user2_id', intval($user2));
$query->bindParam(':amount', floatval($amount)); $query->bindValue(':amount', floatval($amount));
$query->execute(); $query->execute();
} }
} }

View File

@ -678,8 +678,11 @@
case "manage_paybacks": case "manage_paybacks":
if(empty($_GET['new'])) { if(empty($_GET['new'])) {
$global_paybacks = new GlobalPayback();
$global_paybacks = $global_paybacks->load();
$tpl->assign('list', true); $tpl->assign('list', true);
$tpl->assign('global_paybacks', array(array("id"=>1, "date"=>"now"))); $tpl->assign('global_paybacks', $global_paybacks);
} }
else { else {
if(!empty($_POST['users_in'])) { if(!empty($_POST['users_in'])) {
@ -689,7 +692,7 @@
if(!is_dir('db_backups')) { if(!is_dir('db_backups')) {
mkdir('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(); $users_in = array();
foreach($_POST['users_in'] as $user1_id) { foreach($_POST['users_in'] as $user1_id) {
@ -704,7 +707,7 @@
$users_in[$user1_id][$user2_id] = 0; $users_in[$user1_id][$user2_id] = 0;
} }
else { 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; $users_in[$user2_id][$user1_id] = 0;
} }
} }
@ -763,6 +766,8 @@
} }
} }
var_dump($users_in);
$global_payback->setUsersIn($users_in); $global_payback->setUsersIn($users_in);
$global_payback->setDate(date('i'), date('G'), date('j'), date('n'), date('Y')); $global_payback->setDate(date('i'), date('G'), date('j'), date('n'), date('Y'));
$global_payback->save(); $global_payback->save();
@ -771,7 +776,7 @@
($cached_files = glob(raintpl::$cache_dir."*.rtpl.php")) or ($cached_files = array()); ($cached_files = glob(raintpl::$cache_dir."*.rtpl.php")) or ($cached_files = array());
array_map("unlink", $cached_files); array_map("unlink", $cached_files);
header('location: index.php?do=edit_users&'.$get_redir); header('location: index.php?do=manage_paybacks&'.$get_redir);
exit(); exit();
} }

View File

@ -39,6 +39,13 @@
//Create table "Paybacks" //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'); $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) { } catch (PDOException $e) {
$error = 'Unable to connect to database and create database, check your credentials and config.<br/>Error message : '.$e->getMessage().'.'; $error = 'Unable to connect to database and create database, check your credentials and config.<br/>Error message : '.$e->getMessage().'.';
} }

View File

@ -4,12 +4,12 @@
<h2>Manage global paybacks</h2> <h2>Manage global paybacks</h2>
<p class="center"><a href="?do=manage_paybacks&new=1">Add a new global payback</a></p> <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> <p>List of previous global paybacks :</p>
<dl> <dl>
{loop="$global_paybacks"} {loop="$global_paybacks"}
<dt>{$value['date']}</dt> <dt>{$value->getDate()}</dt>
<dd><a href="?do=see_paybacks&id={$value['id']}">Payback n°{$value['id']}</a></dd> <dd><a href="?do=see_paybacks&id={$value->getId()}">Payback n°{$value->getId()}</a></dd>
{/loop} {/loop}
</dl> </dl>
{/if} {/if}

View File

@ -4,12 +4,12 @@
<h2>Gérer les remboursements globaux</h2> <h2>Gérer les remboursements globaux</h2>
<p class="center"><a href="?do=manage_paybacks&new=1">Ajouter un remboursement global</a></p> <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> <p>Liste des remboursements globaux précédents :</p>
<dl> <dl>
{loop="$global_paybacks"} {loop="$global_paybacks"}
<dt>{$value['date']}</dt> <dt>{$value->getDate()}</dt>
<dd><a href="?do=see_paybacks&id={$value['id']}">Remboursement n°{$value['id']}</a></dd> <dd><a href="?do=see_paybacks&id={$value->getId()}">Remboursement n°{$value->getId()}</a></dd>
{/loop} {/loop}
</dl> </dl>
{/if} {/if}