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
* cf TODO in files
inc/Invoices.class.php :
========================
* Edit a bill
* Error in guest input on token error
Manage paybacks :
=================
* TODO : Payback system (class should be ok)

View File

@ -20,7 +20,6 @@
public function __construct() {
parent::__construct();
$this->users_in = new UsersIn();
$this->date = new DateTime();
}
// Getters
@ -30,7 +29,10 @@
}
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() {
@ -90,7 +92,6 @@
$this->what = htmlspecialchars($this->what);
$this->amount = (float) $this->amount;
$this->buyer = (int) $this->buyer;
// TODO : $this->date = htmlspecialchars($this->date);
return $this;
}
@ -106,7 +107,8 @@
$this->setWhat($data['what']);
$this->setAmount($data['amount']);
$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
@ -114,20 +116,31 @@
public function load($fields = NULL, $first_only = false) {
$return = parent::load($fields, $first_only); // Execute parent load
if($return !== false) {
if(is_array($return)) {
foreach(array_keys($return) as $key) {
$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
}
// Overrid parent save() method
// Override parent save() method
// ============================
public function save() {
parent::save(); // Save invoice element
$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) {
if(!empty($this->$field)) {
if($fields[$field] == 'date')
$value = $value->format('Y-m-d H:i:s');
if($this->fields[$field] == 'date')
$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();
}
}
// 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) {
global $localized;
// TODO : Move this function to somewhere else ?
$return = '';
$users_in = $users_in->get();
@ -91,10 +92,10 @@
$return .= $all_users[$user_in]->getDisplayName();
if($guests != 0) {
if($guest > 1)
$return .= ' ('.$guests.' '.$localized['guest'].'s)';
if($guests > 1)
$return .= ' ('.$guests.' '.$localized['guest'][LANG].'s)';
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.'),
'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.'),
'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(
@ -448,15 +449,25 @@
break;
case 'delete_invoice':
// TODO : Check user has right to do it
if(!empty($_GET['id'])) {
$invoice = new Invoice();
$invoice->setId($_GET['id']);
$invoice->delete();
$invoice = $invoice->load(array('id'=>(int) $_GET['id']), true);
// Clear the cache
array_map("unlink", glob(raintpl::$cache_dir."*.rtpl.php"));
if($current_user->getAdmin() || $invoice->getBuyer() == $current_user->getId()) {
$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);
exit();
}
@ -464,10 +475,10 @@
default:
// 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;
}
else { */
else {
$users_list = new User();
$users_list = $users_list->load();
@ -482,5 +493,5 @@
$tpl->draw('index');
break;
//}
}
}

View File

@ -1,9 +1,5 @@
{include="header"}
{if condition="$error != ''"}
<p class="error">{$error}</p>
{/if}
{if condition="$view == 'list_users'"}
<h2>List of users</h2>
<p class="center">You can also <a href="?do=add_user">add a user</a>.</p>

View File

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

View File

@ -27,7 +27,7 @@
<div id="detailed_summary">
<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">
<tr>
<th>Date</th>
@ -40,7 +40,7 @@
</tr>
{loop="invoices"}
<tr>
<td>{$value->getDate()}</td>
<td>{$value->getDate('d-m-Y A')}</td>
<td>{$users[$value->getBuyer()]->getDisplayName()}</td>
<td>{function="formatUsersIn($value->getUsersIn(), $users)"}</td>
<td>{$value->getAmount()}</td>

View File

@ -1,9 +1,5 @@
{include="header"}
{if condition="$error != ''"}
<p class="error">{$error}</p>
{/if}
<h2>Add a bill</h2>
<form method="post" action="index.php?do=new_invoice" id="invoice_form">

View File

@ -2,7 +2,6 @@
{if condition="!$show_settings"}
<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">
<p>
<label for="textarea_notice">Homepage notice :</label><br/>
@ -17,7 +16,6 @@
{else}
<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">
<fieldset>
<legend>Database</legend>