Invoice management complete
This commit is contained in:
parent
9c13305080
commit
d4a5da6297
5
TODO
5
TODO
@ -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)
|
||||
|
@ -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") {
|
||||
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
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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].')';
|
||||
}
|
||||
}
|
||||
|
||||
|
23
index.php
23
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.'),
|
||||
'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,10 +449,11 @@
|
||||
break;
|
||||
|
||||
case 'delete_invoice':
|
||||
// TODO : Check user has right to do it
|
||||
if(!empty($_GET['id'])) {
|
||||
$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();
|
||||
|
||||
// Clear the cache
|
||||
@ -460,14 +462,23 @@
|
||||
header('location: index.php?'.$get_redir);
|
||||
exit();
|
||||
}
|
||||
else {
|
||||
$tpl->assign('error', $errors['unauthorized']);
|
||||
$tpl->draw('index');
|
||||
}
|
||||
}
|
||||
else {
|
||||
header('location: index.php?'.$get_redir);
|
||||
exit();
|
||||
}
|
||||
break;
|
||||
|
||||
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;
|
||||
//}
|
||||
}
|
||||
}
|
||||
|
@ -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>
|
||||
|
@ -27,3 +27,4 @@
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
{if condition="!empty($error)"}<p class="error">{$error}</p>{/if}
|
||||
|
@ -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>
|
||||
|
@ -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">
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user