New invoice form improved

This commit is contained in:
Phyks 2013-08-17 18:43:35 +02:00
parent 863751b377
commit 53e7d93670
8 changed files with 40 additions and 16 deletions

3
TODO
View File

@ -3,7 +3,6 @@
* tokens + ban system
* remember me
* htmlspecialchars => on users objects
* Associate a guest with someone
install.php :
=============
@ -15,10 +14,12 @@ inc/Invoices.class.php :
* Better way to store date ? (use specific date types)
* Better way to store users in ?
* Modify load() method to handle complex queries (such as WHERE date < DATE_1 AND date > DATE_2)
* Buyer as user object ?
index.php?do=new_invoice :
==========================
* Improve date handling for form display
* Onchange not working as wanted
index.php?do=settings :
=======================

View File

@ -2,7 +2,7 @@
require_once('data/config.php');
require_once('Storage.class.php');
class Invoices extends Storage {
class Invoice extends Storage {
protected $id, $date, $users_in, $buyer, $amount, $what;
protected $TABLE_NAME = "Invoices";
protected $fields = array(
@ -54,7 +54,7 @@
$this->buyer = (int) $buyer;
}
public function setAmount ($admount) {
public function setAmount ($amount) {
$this->amount = (float) $amount;
}

View File

@ -203,18 +203,25 @@
break;
case 'new_invoice':
if(!empty($_POST['what']) && (float) $_POST['amount'] != 0 && !empty($_POST['date_day']) && !empty($_POT['date_month']) && !empty($_POST['date_year']) && !empty($_POST['users_in'])) {
if(!empty($_POST['what']) && !empty($_POST['amount']) && (float) $_POST['amount'] != 0 && !empty($_POST['date_day']) && !empty($_POST['date_month']) && !empty($_POST['date_year']) && !empty($_POST['users_in'])) {
$invoice = new Invoice();
$invoice->setWhat($_POST['what']);
$invoice->setAmount($_POST['amount']);
$invoice->setBuyer($current_user->getId());
$invoice->setDate();
$invoice->setDate(time());
//TODO : Handle users_in + guests
$users_in = '';
$guests = array();
foreach($_POST['users_in'] as $user) {
$users_in .= ($users_in != '') ? ', ' : '';
$users_in .= $user.'('.(!empty($_POST['guest_user_'.$user]) ? (int) $_POST['guest_user_'.$user] : '0').')';
$guests[$user] = (int) $_POST['guest_user_'.$user];
}
$invoice->setUsersIn($users_in);
$invoice->save();
header('location: index.php');
exit();
//$invoice->save();
// header('location: index.php');
// exit();
}
$users_list = new User();
@ -227,10 +234,11 @@
$tpl->assign('day_post', (!empty($_POST['date_day']) ? (int) $_POST['date_day'] : (int) date('d')));
$tpl->assign('month_post', (!empty($_POST['date_month']) ? (int) $_POST['date_month'] : (int) date('m')));
$tpl->assign('year_post', (!empty($_POST['date_year']) ? (int) $_POST['date_year'] : (int) date('Y')));
$tpl->assign('amount_post', (!empty($_POST['amount']) ? (float) $_POST['amount'] : 0));
$tpl->assign('what_post', (!empty($_POST['what']) ? htmlspecialchars($_POST['what']) : ''));
$tpl->assign('users', $users_list);
$tpl->assign('users_in', (!empty($_POST['users_in']) ? $_POST['users_in'] : array()));
$tpl->assign('guests', (!empty($guests) ? $guests : array()));
$tpl->draw('new_invoice');
break;

View File

@ -9,7 +9,7 @@
<div id="quick_summary">
<h2>Balance</h2>
<p class="center">Read <em>line</em> owes <em>case</em><?php echo $currency;?> to <em>column</em>. You can click on links to confirm the payback.
<p class="center">Read <em>line</em> owes <em>case</em> <?php echo $currency;?> to <em>column</em>. You can click on links to confirm the payback.
<table>
<tr>
<th>Owes\To</th>
@ -23,6 +23,11 @@
<tr>
<th><?php echo $value1->getDisplayName();?></th>
<?php $counter2=-1; if( isset($users) && is_array($users) && sizeof($users) ) foreach( $users as $key2 => $value2 ){ $counter2++; ?>
<td><a href=""><?php echo $value2->getDisplayName();?></a></td>
<?php } ?>
</tr>
<?php } ?>

View File

@ -10,7 +10,7 @@
<textarea name="what" id="what" rows="10"><?php echo $what_post;?></textarea>
<p>
<label for="amount">Amount : </label>
<input type="text" name="amount" id="amount" {($amount_post != 0) ? 'value="'.$value_post.'"' : ''} size="5"/> <?php echo $currency;?>
<input type="text" name="amount" id="amount" <?php if( $amount_post != 0 ){ ?> value="<?php echo $amount_post;?>" <?php } ?> size="5"/> <?php echo $currency;?>
</p>
<p>
@ -41,7 +41,7 @@
Users in ?
<?php $counter1=-1; if( isset($users) && is_array($users) && sizeof($users) ) foreach( $users as $key1 => $value1 ){ $counter1++; ?>
<br/><input type="checkbox" name="users_in" value="<?php echo $value1->getId();?>" id="users_in_<?php echo $value1->getId();?>"/> <label for="users_in_<?php echo $value1->getId();?>"><?php echo $value1->getDisplayName();?></label> and <input type="text" name="guest_user_<?php echo $value1->getId();?>" id="guest_user_<?php echo $value1->getId();?>" size="1" value="0"/><label for="guest_user_<?php echo $value1->getId();?>"> guest</label>.
<br/><input type="checkbox" name="users_in[]" value="<?php echo $value1->getId();?>" id="users_in_<?php echo $value1->getId();?>" <?php if( $current_user->getId() == $value1->getId() || in_array($value1->getId(), $users_in) ){ ?> checked <?php } ?>/> <label for="users_in_<?php echo $value1->getId();?>"><?php echo $value1->getDisplayName();?></label> and <input type="text" name="guest_user_<?php echo $value1->getId();?>" id="guest_user_<?php echo $value1->getId();?>" size="1" value="<?php if( in_array($value1->getId(), $users_in) ){ ?> <?php echo $guests[$value1->getId()];?> <?php }else{ ?> 0 <?php } ?>" onchange="guest_user_label(<?php echo $value1->getId();?>);"/><label for="guest_user_<?php echo $value1->getId();?>" id="guest_user_<?php echo $value1->getId();?>_label"> guest</label>.
<?php } ?>
</p>

View File

@ -6,7 +6,7 @@
<div id="quick_summary">
<h2>Balance</h2>
<p class="center">Read <em>line</em> owes <em>case</em>{$currency} to <em>column</em>. You can click on links to confirm the payback.
<p class="center">Read <em>line</em> owes <em>case</em> {$currency} to <em>column</em>. You can click on links to confirm the payback.
<table>
<tr>
<th>Owes\To</th>
@ -17,6 +17,9 @@
{loop="users"}
<tr>
<th>{$value->getDisplayName()}</th>
{loop="users"}
<td><a href="">{$value->getDisplayName()}</a></td>
{/loop}
</tr>
{/loop}
</table>

View File

@ -1,3 +1,10 @@
function set_days_month_year() {
}
function guest_user_label(id) {
if(document.getElementById('guest_user_'+id).value > 1)
document.getElementById('guest_user_'+id+'_label').innerHTML = ' guests';
else
document.getElementById('guest_user_'+id+'_label').innerHTML = ' guest';
}

View File

@ -9,7 +9,7 @@
<textarea name="what" id="what" rows="10">{$what_post}</textarea>
<p>
<label for="amount">Amount : </label>
<input type="text" name="amount" id="amount" {($amount_post != 0) ? 'value="'.$value_post.'"' : ''} size="5"/> {$currency}
<input type="text" name="amount" id="amount" {if condition="$amount_post != 0"} value="{$amount_post}" {/if} size="5"/> {$currency}
</p>
<p>
<label for="date_day">Date : </label>
@ -32,7 +32,7 @@
<p>
Users in ?
{loop="users"}
<br/><input type="checkbox" name="users_in" value="{$value->getId()}" id="users_in_{$value->getId()}"/> <label for="users_in_{$value->getId()}">{$value->getDisplayName()}</label> and <input type="text" name="guest_user_{$value->getId()}" id="guest_user_{$value->getId()}" size="1" value="0"/><label for="guest_user_{$value->getId()}"> guest</label>.
<br/><input type="checkbox" name="users_in[]" value="{$value->getId()}" id="users_in_{$value->getId()}" {if condition="$current_user->getId() == $value->getId() || in_array($value->getId(), $users_in)"} checked {/if}/> <label for="users_in_{$value->getId()}">{$value->getDisplayName()}</label> and <input type="text" name="guest_user_{$value->getId()}" id="guest_user_{$value->getId()}" size="1" value="{if condition="in_array($value->getId(), $users_in)"} {$guests[$value->getId()]} {else} 0 {/if}" onchange="guest_user_label({$value->getId()});"/><label for="guest_user_{$value->getId()}" id="guest_user_{$value->getId()}_label"> guest</label>.
{/loop}
</p>
<p>