Global paybacks should be ok. To be tested
This commit is contained in:
parent
32cd8a4fe7
commit
e5014cb7f9
5
TODO
5
TODO
@ -1,7 +1,6 @@
|
||||
Issues :
|
||||
========
|
||||
* Check CSRF everywhere
|
||||
* Close a global payback
|
||||
|
||||
Improvements :
|
||||
==============
|
||||
@ -11,7 +10,3 @@ Improvements :
|
||||
* API
|
||||
* cf TODO in files
|
||||
* README file
|
||||
|
||||
Manage paybacks :
|
||||
=================
|
||||
* TODO : Global payback
|
||||
|
@ -4,7 +4,7 @@
|
||||
require_once('UsersInGlobalPayback.class.php');
|
||||
|
||||
class GlobalPayback extends Storage {
|
||||
protected $id = 0, $date, $users_in;
|
||||
protected $id = 0, $date, $users_in, $closed;
|
||||
// date is a DateTime object
|
||||
// buyer is a User object
|
||||
// users_in is a UsersIn objects
|
||||
@ -12,11 +12,13 @@
|
||||
protected $fields = array(
|
||||
'id'=>'key',
|
||||
'date'=>'date',
|
||||
'closed'=>'bool'
|
||||
);
|
||||
|
||||
public function __construct() {
|
||||
parent::__construct();
|
||||
$this->users_in = new UsersInGlobalPayback();
|
||||
$this->date = new Datetime();
|
||||
}
|
||||
|
||||
// Getters
|
||||
@ -36,6 +38,10 @@
|
||||
return $this->users_in;
|
||||
}
|
||||
|
||||
public function getClosed() {
|
||||
return (bool) $this->closed;
|
||||
}
|
||||
|
||||
// Setters
|
||||
// =======
|
||||
public function setId($id) {
|
||||
@ -44,7 +50,7 @@
|
||||
}
|
||||
|
||||
public function setDate($minute, $hour, $day, $month, $year) {
|
||||
if((int) $minute < 10) $minute = '0'.$minute;
|
||||
if((int) $minute < 10) $minute = '0'.(int) $minute;
|
||||
|
||||
$this->date = DateTime::createFromFormat('Y-n-j G:i', $year.'-'.(int) $month.'-'.(int) $day.' '.(int) $hour.':'.$minute);
|
||||
}
|
||||
@ -54,6 +60,10 @@
|
||||
$this->users_in->set($users_in);
|
||||
}
|
||||
|
||||
public function setClosed($closed) {
|
||||
$this->closed = (bool) $closed;
|
||||
}
|
||||
|
||||
// Maps htmlspecialchars on the class before display
|
||||
// =================================================
|
||||
public function secureDisplay() {
|
||||
@ -71,6 +81,7 @@
|
||||
|
||||
$this->setId($data['id']);
|
||||
$this->date = DateTime::createFromFormat('Y-m-d H:i:s', $data['date']);
|
||||
$this->setClosed($data['closed']);
|
||||
}
|
||||
|
||||
// Override parent load() method
|
||||
|
@ -59,7 +59,7 @@
|
||||
}
|
||||
|
||||
public function setDate($minute, $hour, $day, $month, $year) {
|
||||
if((int) $minute < 10) $minute = '0'.$minute;
|
||||
if((int) $minute < 10) $minute = '0'.(int) $minute;
|
||||
|
||||
$this->date = DateTime::createFromFormat('Y-n-j G:i', $year.'-'.(int) $month.'-'.(int) $day.' '.(int) $hour.':'.$minute);
|
||||
}
|
||||
|
@ -55,6 +55,19 @@
|
||||
return $this;
|
||||
}
|
||||
|
||||
// Test if the payback should be closed
|
||||
// ====================================
|
||||
public function isEmpty() {
|
||||
foreach($this->users_list as $user1=>$temp) {
|
||||
foreach($temp as $user2=>$amount) {
|
||||
if($amount != 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Override load() method
|
||||
// ======================
|
||||
public function load() {
|
||||
@ -85,7 +98,7 @@
|
||||
public function save() {
|
||||
// TODO : Optimize ?
|
||||
|
||||
$query = 'SELECT COUNT(payback_id) FROM '.MYSQL_PREFIX.$this->TABLE_NAME.' WHERE payback_id=:payback_id';
|
||||
$query = 'SELECT COUNT(global_payback_id) FROM '.MYSQL_PREFIX.$this->TABLE_NAME.' WHERE global_payback_id=:payback_id';
|
||||
$query = $this->getConnection()->prepare($query);
|
||||
$query->bindParam(':payback_id', $this->payback_id);
|
||||
$query->execute();
|
||||
@ -94,7 +107,7 @@
|
||||
|
||||
if($count != 0) {
|
||||
// If there are already some records, delete them first
|
||||
$query = $this->getConnection()->prepare('DELETE FROM '.MYSQL_PREFIX.$this->TABLE_NAME.' WHERE payback_id=:payback_id');
|
||||
$query = $this->getConnection()->prepare('DELETE FROM '.MYSQL_PREFIX.$this->TABLE_NAME.' WHERE global_payback_id=:payback_id');
|
||||
$query->bindParam(':payback_id', $this->payback_id);
|
||||
$query->execute();
|
||||
}
|
||||
|
17
index.php
17
index.php
@ -719,13 +719,20 @@
|
||||
|
||||
$global_payback->setUsersIn($users_in);
|
||||
|
||||
if($global_payback->getUsersIn()->isEmpty()) {
|
||||
$global_payback->setClosed(true);
|
||||
}
|
||||
else {
|
||||
$global_payback->setClosed(false);
|
||||
}
|
||||
|
||||
$global_payback->save();
|
||||
|
||||
// Clear the cache
|
||||
($cached_files = glob(raintpl::$cache_dir."*.rtpl.php")) or ($cached_files = array());
|
||||
array_map("unlink", $cached_files);
|
||||
|
||||
header('location: see_paybacks.php?id='.(int)$_GET['payback_id']);
|
||||
header('location: ?do=see_paybacks&id='.(int)$_GET['payback_id']);
|
||||
exit();
|
||||
|
||||
}
|
||||
@ -839,6 +846,14 @@
|
||||
}
|
||||
|
||||
$global_payback->setUsersIn($users_in);
|
||||
|
||||
if($global_payback->getUsersIn()->isEmpty()) {
|
||||
$global_payback->setClosed(true);
|
||||
}
|
||||
else {
|
||||
$global_payback->setClosed(false);
|
||||
}
|
||||
|
||||
$global_payback->setDate(date('i'), date('G'), date('j'), date('n'), date('Y'));
|
||||
$global_payback->save();
|
||||
|
||||
|
@ -9,7 +9,7 @@
|
||||
<dl>
|
||||
{loop="$global_paybacks"}
|
||||
<dt>{$value->getDate()}</dt>
|
||||
<dd><a href="?do=see_paybacks&id={$value->getId()}">Payback n°{$value->getId()}</a></dd>
|
||||
<dd>{if condition="$value->getClosed() === true"}[Closed] {/if}<a href="?do=see_paybacks&id={$value->getId()}">Payback n°{$value->getId()}</a></dd>
|
||||
{/loop}
|
||||
</dl>
|
||||
{/if}
|
||||
@ -36,7 +36,7 @@
|
||||
{/loop}
|
||||
</fieldset>
|
||||
<p>
|
||||
<input type="submit" onclick="confirm('You are going to add a global payback which includes the selected user. Confirm ?');" value="Confirm"/>
|
||||
<input type="submit" onclick="return confirm('You are going to add a global payback which includes the selected user. Confirm ?');" value="Confirm"/>
|
||||
</p>
|
||||
</form>
|
||||
{/if}
|
||||
|
@ -6,42 +6,52 @@
|
||||
<dl>
|
||||
{loop="$global_paybacks"}
|
||||
<dt>{$value->getDate()}</dt>
|
||||
<dd><a href="?do=see_paybacks&id={$value->getId()}">Payback n°{$value->getId()}</a></dd>
|
||||
<dd>
|
||||
{if condition="$value->getClosed() !== false"}
|
||||
<a href="?do=see_paybacks&id={$value->getId()}" onclick="return confirm("Are you sure you want to confirm this payback ? This action can't be undone easily");">Payback n°{$value->getId()}</a>
|
||||
{else}
|
||||
[Closed] Payback n°{$value->getId()}
|
||||
{/if}
|
||||
</dd>
|
||||
{/loop}
|
||||
</dl>
|
||||
{else}
|
||||
<p>No global paybacks available.</p>
|
||||
{/if}
|
||||
{else}
|
||||
<h2>Payback n°{$global_paybacks->getId()}</h2>
|
||||
{if condition="$global_paybacks === false"}
|
||||
Payback doesn't exist.
|
||||
{else}
|
||||
<h2>Payback n°{$global_paybacks->getId()}</h2>
|
||||
|
||||
{$table=$global_paybacks->getUsersIn()->get()}
|
||||
<table id="global_paybacks_table">
|
||||
<tr>
|
||||
<th>Owes / To</th>
|
||||
{loop="$global_paybacks->getUsersIn()->get()"}
|
||||
<th>{$users[$key1]->getDisplayName()}</th>
|
||||
{/loop}
|
||||
</tr>
|
||||
{loop="$global_paybacks->getUsersIn()->get()"}
|
||||
{$table=$global_paybacks->getUsersIn()->get()}
|
||||
<table id="global_paybacks_table">
|
||||
<tr>
|
||||
<th>{$users[$key1]->getDisplayName()}</th>
|
||||
<th>Owes / To</th>
|
||||
{loop="$global_paybacks->getUsersIn()->get()"}
|
||||
{if condition="$key1 == $key2"}
|
||||
<td class="cell-disabled"></td>
|
||||
{else}
|
||||
<td>
|
||||
{if condition="$table[$key1][$key2] != 0"}
|
||||
<a href="?do=confirm_global_paybacks&from={$key1}&to={$key2}&payback_id={$global_paybacks->getId()}" title="Confirm payback">{$table[$key1][$key2]}</a>
|
||||
{else}
|
||||
-
|
||||
{/if}
|
||||
</td>
|
||||
{/if}
|
||||
<th>{$users[$key1]->getDisplayName()}</th>
|
||||
{/loop}
|
||||
</tr>
|
||||
{/loop}
|
||||
</table>
|
||||
{loop="$global_paybacks->getUsersIn()->get()"}
|
||||
<tr>
|
||||
<th>{$users[$key1]->getDisplayName()}</th>
|
||||
{loop="$global_paybacks->getUsersIn()->get()"}
|
||||
{if condition="$key1 == $key2"}
|
||||
<td class="cell-disabled"></td>
|
||||
{else}
|
||||
<td>
|
||||
{if condition="$table[$key1][$key2] != 0"}
|
||||
<a href="?do=confirm_global_paybacks&from={$key1}&to={$key2}&payback_id={$global_paybacks->getId()}" title="Confirm payback">{$table[$key1][$key2]}</a>
|
||||
{else}
|
||||
-
|
||||
{/if}
|
||||
</td>
|
||||
{/if}
|
||||
{/loop}
|
||||
</tr>
|
||||
{/loop}
|
||||
</table>
|
||||
{/if}
|
||||
|
||||
<p class="center"><a href="?do=see_paybacks">Go back to global paybacks list</a></p>
|
||||
{/if}
|
||||
|
@ -9,7 +9,7 @@
|
||||
<dl>
|
||||
{loop="$global_paybacks"}
|
||||
<dt>{$value->getDate()}</dt>
|
||||
<dd><a href="?do=see_paybacks&id={$value->getId()}">Remboursement n°{$value->getId()}</a></dd>
|
||||
<dd>{if condition="$value->getClosed() === true"}[Terminé] {/if}<a href="?do=see_paybacks&id={$value->getId()}">Remboursement n°{$value->getId()}</a></dd>
|
||||
{/loop}
|
||||
</dl>
|
||||
{/if}
|
||||
@ -36,7 +36,7 @@
|
||||
{/loop}
|
||||
</fieldset>
|
||||
<p>
|
||||
<input type="submit" onclick="confirm('Vous êtes sur le point d\'ajouter un remboursement global incluant les utilisateurs sélectionnés.');" value="Valider"/>
|
||||
<input type="submit" onclick="return confirm('Vous êtes sur le point d\'ajouter un remboursement global incluant les utilisateurs sélectionnés.');" value="Valider"/>
|
||||
</p>
|
||||
</form>
|
||||
{/if}
|
||||
|
@ -6,42 +6,51 @@
|
||||
<dl>
|
||||
{loop="$global_paybacks"}
|
||||
<dt>{$value->getDate()}</dt>
|
||||
<dd><a href="?do=see_paybacks&id={$value->getId()}">Remboursement n°{$value->getId()}</a></dd>
|
||||
<dd>
|
||||
{if condition="$value->getClosed() !== false"}
|
||||
<a href="?do=see_paybacks&id={$value->getId()}" onclick="return confirm('Etes-vous sur de vouloir confirmer ce remboursement ? Cette action ne peut etre annulée facilement.');">Remboursement n°{$value->getId()}</a>
|
||||
{else}
|
||||
[Terminé] Remboursement n°{$value->getId()}
|
||||
{/if}
|
||||
</dd>
|
||||
{/loop}
|
||||
</dl>
|
||||
{else}
|
||||
<p>Aucun remboursement global disponible pour l'instant.</p>
|
||||
{/if}
|
||||
{else}
|
||||
<h2>Remboursement n°{$global_paybacks->getId()}</h2>
|
||||
|
||||
{$table=$global_paybacks->getUsersIn()->get()}
|
||||
<table id="global_paybacks_table">
|
||||
<tr>
|
||||
<th>Doit / À</th>
|
||||
{loop="$global_paybacks->getUsersIn()->get()"}
|
||||
<th>{$users[$key1]->getDisplayName()}</th>
|
||||
{/loop}
|
||||
</tr>
|
||||
{loop="$global_paybacks->getUsersIn()->get()"}
|
||||
{if condition="$global_paybacks === false"}
|
||||
Remboursement inexistant.
|
||||
{else}
|
||||
<h2>Remboursement n°{$global_paybacks->getId()}</h2>
|
||||
{$table=$global_paybacks->getUsersIn()->get()}
|
||||
<table id="global_paybacks_table">
|
||||
<tr>
|
||||
<th>{$users[$key1]->getDisplayName()}</th>
|
||||
<th>Doit / À</th>
|
||||
{loop="$global_paybacks->getUsersIn()->get()"}
|
||||
{if condition="$key1 == $key2"}
|
||||
<td class="cell-disabled"></td>
|
||||
{else}
|
||||
<td>
|
||||
{if condition="$table[$key1][$key2] != 0"}
|
||||
<a href="?do=confirm_global_paybacks&from={$key1}&to={$key2}&payback_id={$global_paybacks->getId()}" title="Confirmer le remboursement">{$table[$key1][$key2]}</a>
|
||||
{else}
|
||||
-
|
||||
{/if}
|
||||
</td>
|
||||
{/if}
|
||||
<th>{$users[$key1]->getDisplayName()}</th>
|
||||
{/loop}
|
||||
</tr>
|
||||
{/loop}
|
||||
</table>
|
||||
{loop="$global_paybacks->getUsersIn()->get()"}
|
||||
<tr>
|
||||
<th>{$users[$key1]->getDisplayName()}</th>
|
||||
{loop="$global_paybacks->getUsersIn()->get()"}
|
||||
{if condition="$key1 == $key2"}
|
||||
<td class="cell-disabled"></td>
|
||||
{else}
|
||||
<td>
|
||||
{if condition="$table[$key1][$key2] != 0"}
|
||||
<a href="?do=confirm_global_paybacks&from={$key1}&to={$key2}&payback_id={$global_paybacks->getId()}" title="Confirmer le remboursement">{$table[$key1][$key2]}</a>
|
||||
{else}
|
||||
-
|
||||
{/if}
|
||||
</td>
|
||||
{/if}
|
||||
{/loop}
|
||||
</tr>
|
||||
{/loop}
|
||||
</table>
|
||||
{/if}
|
||||
|
||||
<p class="center"><a href="?do=see_paybacks">Retour à la liste des remboursements</a></p>
|
||||
{/if}
|
||||
|
Loading…
Reference in New Issue
Block a user