Invoice management complete

This commit is contained in:
Phyks 2013-09-08 18:36:59 +02:00
parent 9c13305080
commit d4a5da6297
11 changed files with 59 additions and 38 deletions

5
TODO
View File

@ -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)

View File

@ -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") {
if(!empty($this->date))
return $this->date->format($format); 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
}
} }

View File

@ -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);
} }
} }

View File

@ -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();
}
} }

View File

@ -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].')';
} }
} }

View File

@ -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,10 +449,11 @@
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);
if($current_user->getAdmin() || $invoice->getBuyer() == $current_user->getId()) {
$invoice->delete(); $invoice->delete();
// Clear the cache // Clear the cache
@ -460,14 +462,23 @@
header('location: index.php?'.$get_redir); header('location: index.php?'.$get_redir);
exit(); exit();
} }
else {
$tpl->assign('error', $errors['unauthorized']);
$tpl->draw('index');
}
}
else {
header('location: index.php?'.$get_redir);
exit();
}
break; break;
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;
//} }
} }

View File

@ -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>

View File

@ -27,3 +27,4 @@
{/if} {/if}
</div> </div>
{/if} {/if}
{if condition="!empty($error)"}<p class="error">{$error}</p>{/if}

View File

@ -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>

View File

@ -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">

View File

@ -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>