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 :
|
Issues :
|
||||||
========
|
========
|
||||||
* Check CSRF everywhere
|
* Check CSRF everywhere
|
||||||
* Close a global payback
|
|
||||||
|
|
||||||
Improvements :
|
Improvements :
|
||||||
==============
|
==============
|
||||||
@ -11,7 +10,3 @@ Improvements :
|
|||||||
* API
|
* API
|
||||||
* cf TODO in files
|
* cf TODO in files
|
||||||
* README file
|
* README file
|
||||||
|
|
||||||
Manage paybacks :
|
|
||||||
=================
|
|
||||||
* TODO : Global payback
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
require_once('UsersInGlobalPayback.class.php');
|
require_once('UsersInGlobalPayback.class.php');
|
||||||
|
|
||||||
class GlobalPayback extends Storage {
|
class GlobalPayback extends Storage {
|
||||||
protected $id = 0, $date, $users_in;
|
protected $id = 0, $date, $users_in, $closed;
|
||||||
// date is a DateTime object
|
// date is a DateTime object
|
||||||
// buyer is a User object
|
// buyer is a User object
|
||||||
// users_in is a UsersIn objects
|
// users_in is a UsersIn objects
|
||||||
@ -12,11 +12,13 @@
|
|||||||
protected $fields = array(
|
protected $fields = array(
|
||||||
'id'=>'key',
|
'id'=>'key',
|
||||||
'date'=>'date',
|
'date'=>'date',
|
||||||
|
'closed'=>'bool'
|
||||||
);
|
);
|
||||||
|
|
||||||
public function __construct() {
|
public function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->users_in = new UsersInGlobalPayback();
|
$this->users_in = new UsersInGlobalPayback();
|
||||||
|
$this->date = new Datetime();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
@ -36,6 +38,10 @@
|
|||||||
return $this->users_in;
|
return $this->users_in;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getClosed() {
|
||||||
|
return (bool) $this->closed;
|
||||||
|
}
|
||||||
|
|
||||||
// Setters
|
// Setters
|
||||||
// =======
|
// =======
|
||||||
public function setId($id) {
|
public function setId($id) {
|
||||||
@ -44,7 +50,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function setDate($minute, $hour, $day, $month, $year) {
|
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);
|
$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);
|
$this->users_in->set($users_in);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setClosed($closed) {
|
||||||
|
$this->closed = (bool) $closed;
|
||||||
|
}
|
||||||
|
|
||||||
// Maps htmlspecialchars on the class before display
|
// Maps htmlspecialchars on the class before display
|
||||||
// =================================================
|
// =================================================
|
||||||
public function secureDisplay() {
|
public function secureDisplay() {
|
||||||
@ -71,6 +81,7 @@
|
|||||||
|
|
||||||
$this->setId($data['id']);
|
$this->setId($data['id']);
|
||||||
$this->date = DateTime::createFromFormat('Y-m-d H:i:s', $data['date']);
|
$this->date = DateTime::createFromFormat('Y-m-d H:i:s', $data['date']);
|
||||||
|
$this->setClosed($data['closed']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override parent load() method
|
// Override parent load() method
|
||||||
|
@ -59,7 +59,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function setDate($minute, $hour, $day, $month, $year) {
|
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);
|
$this->date = DateTime::createFromFormat('Y-n-j G:i', $year.'-'.(int) $month.'-'.(int) $day.' '.(int) $hour.':'.$minute);
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,19 @@
|
|||||||
return $this;
|
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
|
// Override load() method
|
||||||
// ======================
|
// ======================
|
||||||
public function load() {
|
public function load() {
|
||||||
@ -85,7 +98,7 @@
|
|||||||
public function save() {
|
public function save() {
|
||||||
// TODO : Optimize ?
|
// 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 = $this->getConnection()->prepare($query);
|
||||||
$query->bindParam(':payback_id', $this->payback_id);
|
$query->bindParam(':payback_id', $this->payback_id);
|
||||||
$query->execute();
|
$query->execute();
|
||||||
@ -94,7 +107,7 @@
|
|||||||
|
|
||||||
if($count != 0) {
|
if($count != 0) {
|
||||||
// If there are already some records, delete them first
|
// 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->bindParam(':payback_id', $this->payback_id);
|
||||||
$query->execute();
|
$query->execute();
|
||||||
}
|
}
|
||||||
|
17
index.php
17
index.php
@ -719,13 +719,20 @@
|
|||||||
|
|
||||||
$global_payback->setUsersIn($users_in);
|
$global_payback->setUsersIn($users_in);
|
||||||
|
|
||||||
|
if($global_payback->getUsersIn()->isEmpty()) {
|
||||||
|
$global_payback->setClosed(true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$global_payback->setClosed(false);
|
||||||
|
}
|
||||||
|
|
||||||
$global_payback->save();
|
$global_payback->save();
|
||||||
|
|
||||||
// Clear the cache
|
// Clear the cache
|
||||||
($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: see_paybacks.php?id='.(int)$_GET['payback_id']);
|
header('location: ?do=see_paybacks&id='.(int)$_GET['payback_id']);
|
||||||
exit();
|
exit();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -839,6 +846,14 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
$global_payback->setUsersIn($users_in);
|
$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->setDate(date('i'), date('G'), date('j'), date('n'), date('Y'));
|
||||||
$global_payback->save();
|
$global_payback->save();
|
||||||
|
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
<dl>
|
<dl>
|
||||||
{loop="$global_paybacks"}
|
{loop="$global_paybacks"}
|
||||||
<dt>{$value->getDate()}</dt>
|
<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}
|
{/loop}
|
||||||
</dl>
|
</dl>
|
||||||
{/if}
|
{/if}
|
||||||
@ -36,7 +36,7 @@
|
|||||||
{/loop}
|
{/loop}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<p>
|
<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>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
{/if}
|
{/if}
|
||||||
|
@ -6,42 +6,52 @@
|
|||||||
<dl>
|
<dl>
|
||||||
{loop="$global_paybacks"}
|
{loop="$global_paybacks"}
|
||||||
<dt>{$value->getDate()}</dt>
|
<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}
|
{/loop}
|
||||||
</dl>
|
</dl>
|
||||||
{else}
|
{else}
|
||||||
<p>No global paybacks available.</p>
|
<p>No global paybacks available.</p>
|
||||||
{/if}
|
{/if}
|
||||||
{else}
|
{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=$global_paybacks->getUsersIn()->get()}
|
||||||
<table id="global_paybacks_table">
|
<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()"}
|
|
||||||
<tr>
|
<tr>
|
||||||
<th>{$users[$key1]->getDisplayName()}</th>
|
<th>Owes / To</th>
|
||||||
{loop="$global_paybacks->getUsersIn()->get()"}
|
{loop="$global_paybacks->getUsersIn()->get()"}
|
||||||
{if condition="$key1 == $key2"}
|
<th>{$users[$key1]->getDisplayName()}</th>
|
||||||
<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}
|
{/loop}
|
||||||
</tr>
|
</tr>
|
||||||
{/loop}
|
{loop="$global_paybacks->getUsersIn()->get()"}
|
||||||
</table>
|
<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>
|
<p class="center"><a href="?do=see_paybacks">Go back to global paybacks list</a></p>
|
||||||
{/if}
|
{/if}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
<dl>
|
<dl>
|
||||||
{loop="$global_paybacks"}
|
{loop="$global_paybacks"}
|
||||||
<dt>{$value->getDate()}</dt>
|
<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}
|
{/loop}
|
||||||
</dl>
|
</dl>
|
||||||
{/if}
|
{/if}
|
||||||
@ -36,7 +36,7 @@
|
|||||||
{/loop}
|
{/loop}
|
||||||
</fieldset>
|
</fieldset>
|
||||||
<p>
|
<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>
|
</p>
|
||||||
</form>
|
</form>
|
||||||
{/if}
|
{/if}
|
||||||
|
@ -6,42 +6,51 @@
|
|||||||
<dl>
|
<dl>
|
||||||
{loop="$global_paybacks"}
|
{loop="$global_paybacks"}
|
||||||
<dt>{$value->getDate()}</dt>
|
<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}
|
{/loop}
|
||||||
</dl>
|
</dl>
|
||||||
{else}
|
{else}
|
||||||
<p>Aucun remboursement global disponible pour l'instant.</p>
|
<p>Aucun remboursement global disponible pour l'instant.</p>
|
||||||
{/if}
|
{/if}
|
||||||
{else}
|
{else}
|
||||||
<h2>Remboursement n°{$global_paybacks->getId()}</h2>
|
{if condition="$global_paybacks === false"}
|
||||||
|
Remboursement inexistant.
|
||||||
{$table=$global_paybacks->getUsersIn()->get()}
|
{else}
|
||||||
<table id="global_paybacks_table">
|
<h2>Remboursement n°{$global_paybacks->getId()}</h2>
|
||||||
<tr>
|
{$table=$global_paybacks->getUsersIn()->get()}
|
||||||
<th>Doit / À</th>
|
<table id="global_paybacks_table">
|
||||||
{loop="$global_paybacks->getUsersIn()->get()"}
|
|
||||||
<th>{$users[$key1]->getDisplayName()}</th>
|
|
||||||
{/loop}
|
|
||||||
</tr>
|
|
||||||
{loop="$global_paybacks->getUsersIn()->get()"}
|
|
||||||
<tr>
|
<tr>
|
||||||
<th>{$users[$key1]->getDisplayName()}</th>
|
<th>Doit / À</th>
|
||||||
{loop="$global_paybacks->getUsersIn()->get()"}
|
{loop="$global_paybacks->getUsersIn()->get()"}
|
||||||
{if condition="$key1 == $key2"}
|
<th>{$users[$key1]->getDisplayName()}</th>
|
||||||
<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}
|
{/loop}
|
||||||
</tr>
|
</tr>
|
||||||
{/loop}
|
{loop="$global_paybacks->getUsersIn()->get()"}
|
||||||
</table>
|
<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>
|
<p class="center"><a href="?do=see_paybacks">Retour à la liste des remboursements</a></p>
|
||||||
{/if}
|
{/if}
|
||||||
|
Loading…
Reference in New Issue
Block a user