Invoice management complete
This commit is contained in:
parent
9c13305080
commit
d4a5da6297
5
TODO
5
TODO
@ -5,11 +5,6 @@
|
|||||||
* User groups
|
* User groups
|
||||||
* cf TODO in files
|
* cf TODO in files
|
||||||
|
|
||||||
inc/Invoices.class.php :
|
|
||||||
========================
|
|
||||||
* Edit a bill
|
|
||||||
* Error in guest input on token error
|
|
||||||
|
|
||||||
Manage paybacks :
|
Manage paybacks :
|
||||||
=================
|
=================
|
||||||
* TODO : Payback system (class should be ok)
|
* TODO : Payback system (class should be ok)
|
||||||
|
@ -20,7 +20,6 @@
|
|||||||
public function __construct() {
|
public function __construct() {
|
||||||
parent::__construct();
|
parent::__construct();
|
||||||
$this->users_in = new UsersIn();
|
$this->users_in = new UsersIn();
|
||||||
$this->date = new DateTime();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Getters
|
// Getters
|
||||||
@ -30,7 +29,10 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function getDate($format = "d-m-Y H:i") {
|
public function getDate($format = "d-m-Y H:i") {
|
||||||
return $this->date->format($format);
|
if(!empty($this->date))
|
||||||
|
return $this->date->format($format);
|
||||||
|
else
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getBuyer() {
|
public function getBuyer() {
|
||||||
@ -90,7 +92,6 @@
|
|||||||
$this->what = htmlspecialchars($this->what);
|
$this->what = htmlspecialchars($this->what);
|
||||||
$this->amount = (float) $this->amount;
|
$this->amount = (float) $this->amount;
|
||||||
$this->buyer = (int) $this->buyer;
|
$this->buyer = (int) $this->buyer;
|
||||||
// TODO : $this->date = htmlspecialchars($this->date);
|
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
@ -106,7 +107,8 @@
|
|||||||
$this->setWhat($data['what']);
|
$this->setWhat($data['what']);
|
||||||
$this->setAmount($data['amount']);
|
$this->setAmount($data['amount']);
|
||||||
$this->setBuyer($data['buyer']);
|
$this->setBuyer($data['buyer']);
|
||||||
//TODO : $this->setDate($data['date']);
|
|
||||||
|
$this->date = DateTime::createFromFormat('Y-m-d H:i:s', $data['date']);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Override parent load() method
|
// Override parent load() method
|
||||||
@ -114,20 +116,31 @@
|
|||||||
public function load($fields = NULL, $first_only = false) {
|
public function load($fields = NULL, $first_only = false) {
|
||||||
$return = parent::load($fields, $first_only); // Execute parent load
|
$return = parent::load($fields, $first_only); // Execute parent load
|
||||||
|
|
||||||
if($return !== false) {
|
if(is_array($return)) {
|
||||||
foreach(array_keys($return) as $key) {
|
foreach(array_keys($return) as $key) {
|
||||||
$return[$key]->users_in->load(); // Load users in for each invoice
|
$return[$key]->users_in->load(); // Load users in for each invoice
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
elseif(is_a($return, 'Invoice')) {
|
||||||
|
$return->users_in->load();
|
||||||
|
}
|
||||||
|
|
||||||
return $return; // Return the loaded elements
|
return $return; // Return the loaded elements
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overrid parent save() method
|
// Override parent save() method
|
||||||
// ============================
|
// ============================
|
||||||
public function save() {
|
public function save() {
|
||||||
parent::save(); // Save invoice element
|
parent::save(); // Save invoice element
|
||||||
|
|
||||||
$this->users_in->save(); // Save users in
|
$this->users_in->save(); // Save users in
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Override parent delete() method
|
||||||
|
// ===============================
|
||||||
|
public function delete() {
|
||||||
|
parent::delete(); // Delete invoice element
|
||||||
|
|
||||||
|
$this->users_in->delete(); // Also delete users in
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -264,10 +264,12 @@ class Storage {
|
|||||||
|
|
||||||
foreach($this->fields as $field=>$type) {
|
foreach($this->fields as $field=>$type) {
|
||||||
if(!empty($this->$field)) {
|
if(!empty($this->$field)) {
|
||||||
if($fields[$field] == 'date')
|
if($this->fields[$field] == 'date')
|
||||||
$value = $value->format('Y-m-d H:i:s');
|
$value = $this->$field->format('Y-m-d H:i:s');
|
||||||
|
else
|
||||||
|
$value = $this->$field;
|
||||||
|
|
||||||
$query->bindParam(':'.$field, $this->$field);
|
$query->bindValue(':'.$field, $value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,4 +114,12 @@
|
|||||||
$query->execute();
|
$query->execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Override delete() method
|
||||||
|
// ========================
|
||||||
|
public function delete() {
|
||||||
|
$query = $this->getConnection()->prepare('DELETE FROM '.MYSQL_PREFIX.$this->TABLE_NAME.' WHERE invoice_id=:invoice_id');
|
||||||
|
$query->bindParam(':invoice_id', $this->invoice_id);
|
||||||
|
$query->execute();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -81,6 +81,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
function formatUsersIn($users_in, $all_users) {
|
function formatUsersIn($users_in, $all_users) {
|
||||||
|
global $localized;
|
||||||
// TODO : Move this function to somewhere else ?
|
// TODO : Move this function to somewhere else ?
|
||||||
$return = '';
|
$return = '';
|
||||||
$users_in = $users_in->get();
|
$users_in = $users_in->get();
|
||||||
@ -91,10 +92,10 @@
|
|||||||
|
|
||||||
$return .= $all_users[$user_in]->getDisplayName();
|
$return .= $all_users[$user_in]->getDisplayName();
|
||||||
if($guests != 0) {
|
if($guests != 0) {
|
||||||
if($guest > 1)
|
if($guests > 1)
|
||||||
$return .= ' ('.$guests.' '.$localized['guest'].'s)';
|
$return .= ' ('.$guests.' '.$localized['guest'][LANG].'s)';
|
||||||
else
|
else
|
||||||
$return .= ' ('.$guests.' '.$localized['guest'].')';
|
$return .= ' ('.$guests.' '.$localized['guest'][LANG].')';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
29
index.php
29
index.php
@ -8,7 +8,8 @@
|
|||||||
'write_error_data'=>array('fr'=>'Le script ne peut pas écrire dans le dossier data/, vérifiez les permissions sur ce dossier.', 'en'=>'The script can\'t write in data/ dir, check permissions set on this folder.'),
|
'write_error_data'=>array('fr'=>'Le script ne peut pas écrire dans le dossier data/, vérifiez les permissions sur ce dossier.', 'en'=>'The script can\'t write in data/ dir, check permissions set on this folder.'),
|
||||||
'unable_write_config'=>array('fr'=>'Impossible d\'écrire le fichier data/config.php. Vérifiez les permissions.', 'en'=>'Unable to write data/config.php file. Check permissions.'),
|
'unable_write_config'=>array('fr'=>'Impossible d\'écrire le fichier data/config.php. Vérifiez les permissions.', 'en'=>'Unable to write data/config.php file. Check permissions.'),
|
||||||
'negative_amount'=>array('fr'=>'Montant négatif non autorisé.', 'en'=>'Negative amount not allowed.'),
|
'negative_amount'=>array('fr'=>'Montant négatif non autorisé.', 'en'=>'Negative amount not allowed.'),
|
||||||
'template_error'=>array('fr'=>'Template non disponible.', 'en'=>'Template not available.')
|
'template_error'=>array('fr'=>'Template non disponible.', 'en'=>'Template not available.'),
|
||||||
|
'unauthorized'=>array('fr'=>'Vous n\'avez pas le droit de faire cette action.', 'en'=>'You are not authorized to do that.')
|
||||||
);
|
);
|
||||||
|
|
||||||
$localized = array(
|
$localized = array(
|
||||||
@ -448,15 +449,25 @@
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'delete_invoice':
|
case 'delete_invoice':
|
||||||
// TODO : Check user has right to do it
|
|
||||||
if(!empty($_GET['id'])) {
|
if(!empty($_GET['id'])) {
|
||||||
$invoice = new Invoice();
|
$invoice = new Invoice();
|
||||||
$invoice->setId($_GET['id']);
|
$invoice = $invoice->load(array('id'=>(int) $_GET['id']), true);
|
||||||
$invoice->delete();
|
|
||||||
|
|
||||||
// Clear the cache
|
if($current_user->getAdmin() || $invoice->getBuyer() == $current_user->getId()) {
|
||||||
array_map("unlink", glob(raintpl::$cache_dir."*.rtpl.php"));
|
$invoice->delete();
|
||||||
|
|
||||||
|
// Clear the cache
|
||||||
|
array_map("unlink", glob(raintpl::$cache_dir."*.rtpl.php"));
|
||||||
|
|
||||||
|
header('location: index.php?'.$get_redir);
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$tpl->assign('error', $errors['unauthorized']);
|
||||||
|
$tpl->draw('index');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
header('location: index.php?'.$get_redir);
|
header('location: index.php?'.$get_redir);
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
@ -464,10 +475,10 @@
|
|||||||
|
|
||||||
default:
|
default:
|
||||||
// Display cached page in priority
|
// Display cached page in priority
|
||||||
/* TODO if($cache = $tpl->cache('index', $expire_time = 600, $cache_id = $current_user->getLogin())) {
|
if($cache = $tpl->cache('index', $expire_time = 600, $cache_id = $current_user->getLogin())) {
|
||||||
echo $cache;
|
echo $cache;
|
||||||
}
|
}
|
||||||
else { */
|
else {
|
||||||
$users_list = new User();
|
$users_list = new User();
|
||||||
$users_list = $users_list->load();
|
$users_list = $users_list->load();
|
||||||
|
|
||||||
@ -482,5 +493,5 @@
|
|||||||
|
|
||||||
$tpl->draw('index');
|
$tpl->draw('index');
|
||||||
break;
|
break;
|
||||||
//}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
{include="header"}
|
{include="header"}
|
||||||
|
|
||||||
{if condition="$error != ''"}
|
|
||||||
<p class="error">{$error}</p>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
{if condition="$view == 'list_users'"}
|
{if condition="$view == 'list_users'"}
|
||||||
<h2>List of users</h2>
|
<h2>List of users</h2>
|
||||||
<p class="center">You can also <a href="?do=add_user">add a user</a>.</p>
|
<p class="center">You can also <a href="?do=add_user">add a user</a>.</p>
|
||||||
|
@ -27,3 +27,4 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
{if condition="!empty($error)"}<p class="error">{$error}</p>{/if}
|
||||||
|
@ -27,7 +27,7 @@
|
|||||||
<div id="detailed_summary">
|
<div id="detailed_summary">
|
||||||
<h2>Detailed list of bills for last month</h2>
|
<h2>Detailed list of bills for last month</h2>
|
||||||
|
|
||||||
{if condition="count($invoices)>=1"}
|
{if condition="$invoices !== false && count($invoices)>=1"}
|
||||||
<table id="list_expenses">
|
<table id="list_expenses">
|
||||||
<tr>
|
<tr>
|
||||||
<th>Date</th>
|
<th>Date</th>
|
||||||
@ -40,7 +40,7 @@
|
|||||||
</tr>
|
</tr>
|
||||||
{loop="invoices"}
|
{loop="invoices"}
|
||||||
<tr>
|
<tr>
|
||||||
<td>{$value->getDate()}</td>
|
<td>{$value->getDate('d-m-Y A')}</td>
|
||||||
<td>{$users[$value->getBuyer()]->getDisplayName()}</td>
|
<td>{$users[$value->getBuyer()]->getDisplayName()}</td>
|
||||||
<td>{function="formatUsersIn($value->getUsersIn(), $users)"}</td>
|
<td>{function="formatUsersIn($value->getUsersIn(), $users)"}</td>
|
||||||
<td>{$value->getAmount()}</td>
|
<td>{$value->getAmount()}</td>
|
||||||
|
@ -1,9 +1,5 @@
|
|||||||
{include="header"}
|
{include="header"}
|
||||||
|
|
||||||
{if condition="$error != ''"}
|
|
||||||
<p class="error">{$error}</p>
|
|
||||||
{/if}
|
|
||||||
|
|
||||||
<h2>Add a bill</h2>
|
<h2>Add a bill</h2>
|
||||||
|
|
||||||
<form method="post" action="index.php?do=new_invoice" id="invoice_form">
|
<form method="post" action="index.php?do=new_invoice" id="invoice_form">
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
{if condition="!$show_settings"}
|
{if condition="!$show_settings"}
|
||||||
<h2>Edit homepage notice</h2>
|
<h2>Edit homepage notice</h2>
|
||||||
{if condition="$error"}<p class="error">{$error}</p>{/if}
|
|
||||||
<form method="post" id="notice_form" action="index.php?do=edit_notice">
|
<form method="post" id="notice_form" action="index.php?do=edit_notice">
|
||||||
<p>
|
<p>
|
||||||
<label for="textarea_notice">Homepage notice :</label><br/>
|
<label for="textarea_notice">Homepage notice :</label><br/>
|
||||||
@ -17,7 +16,6 @@
|
|||||||
|
|
||||||
{else}
|
{else}
|
||||||
<h2>Change settings of your Bouffe@Ulm installation</h2>
|
<h2>Change settings of your Bouffe@Ulm installation</h2>
|
||||||
{if condition="$error"}<p class="error">{$error}</p>{/if}
|
|
||||||
<form method="post" action="index.php?do=settings" id="settings_form">
|
<form method="post" action="index.php?do=settings" id="settings_form">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<legend>Database</legend>
|
<legend>Database</legend>
|
||||||
|
Loading…
Reference in New Issue
Block a user