New invoice form improved
This commit is contained in:
parent
863751b377
commit
53e7d93670
3
TODO
3
TODO
@ -3,7 +3,6 @@
|
|||||||
* tokens + ban system
|
* tokens + ban system
|
||||||
* remember me
|
* remember me
|
||||||
* htmlspecialchars => on users objects
|
* htmlspecialchars => on users objects
|
||||||
* Associate a guest with someone
|
|
||||||
|
|
||||||
install.php :
|
install.php :
|
||||||
=============
|
=============
|
||||||
@ -15,10 +14,12 @@ inc/Invoices.class.php :
|
|||||||
* Better way to store date ? (use specific date types)
|
* Better way to store date ? (use specific date types)
|
||||||
* Better way to store users in ?
|
* Better way to store users in ?
|
||||||
* Modify load() method to handle complex queries (such as WHERE date < DATE_1 AND date > DATE_2)
|
* 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 :
|
index.php?do=new_invoice :
|
||||||
==========================
|
==========================
|
||||||
* Improve date handling for form display
|
* Improve date handling for form display
|
||||||
|
* Onchange not working as wanted
|
||||||
|
|
||||||
index.php?do=settings :
|
index.php?do=settings :
|
||||||
=======================
|
=======================
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
require_once('data/config.php');
|
require_once('data/config.php');
|
||||||
require_once('Storage.class.php');
|
require_once('Storage.class.php');
|
||||||
|
|
||||||
class Invoices extends Storage {
|
class Invoice extends Storage {
|
||||||
protected $id, $date, $users_in, $buyer, $amount, $what;
|
protected $id, $date, $users_in, $buyer, $amount, $what;
|
||||||
protected $TABLE_NAME = "Invoices";
|
protected $TABLE_NAME = "Invoices";
|
||||||
protected $fields = array(
|
protected $fields = array(
|
||||||
@ -54,7 +54,7 @@
|
|||||||
$this->buyer = (int) $buyer;
|
$this->buyer = (int) $buyer;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setAmount ($admount) {
|
public function setAmount ($amount) {
|
||||||
$this->amount = (float) $amount;
|
$this->amount = (float) $amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
22
index.php
22
index.php
@ -203,18 +203,25 @@
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'new_invoice':
|
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 = new Invoice();
|
||||||
$invoice->setWhat($_POST['what']);
|
$invoice->setWhat($_POST['what']);
|
||||||
$invoice->setAmount($_POST['amount']);
|
$invoice->setAmount($_POST['amount']);
|
||||||
$invoice->setBuyer($current_user->getId());
|
$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();
|
//$invoice->save();
|
||||||
header('location: index.php');
|
// header('location: index.php');
|
||||||
exit();
|
// exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
$users_list = new User();
|
$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('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('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('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('amount_post', (!empty($_POST['amount']) ? (float) $_POST['amount'] : 0));
|
||||||
$tpl->assign('what_post', (!empty($_POST['what']) ? htmlspecialchars($_POST['what']) : ''));
|
$tpl->assign('what_post', (!empty($_POST['what']) ? htmlspecialchars($_POST['what']) : ''));
|
||||||
$tpl->assign('users', $users_list);
|
$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');
|
$tpl->draw('new_invoice');
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -23,6 +23,11 @@
|
|||||||
|
|
||||||
<tr>
|
<tr>
|
||||||
<th><?php echo $value1->getDisplayName();?></th>
|
<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>
|
</tr>
|
||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
<textarea name="what" id="what" rows="10"><?php echo $what_post;?></textarea>
|
<textarea name="what" id="what" rows="10"><?php echo $what_post;?></textarea>
|
||||||
<p>
|
<p>
|
||||||
<label for="amount">Amount : </label>
|
<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>
|
||||||
<p>
|
<p>
|
||||||
@ -41,7 +41,7 @@
|
|||||||
Users in ?
|
Users in ?
|
||||||
<?php $counter1=-1; if( isset($users) && is_array($users) && sizeof($users) ) foreach( $users as $key1 => $value1 ){ $counter1++; ?>
|
<?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 } ?>
|
<?php } ?>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
|
@ -17,6 +17,9 @@
|
|||||||
{loop="users"}
|
{loop="users"}
|
||||||
<tr>
|
<tr>
|
||||||
<th>{$value->getDisplayName()}</th>
|
<th>{$value->getDisplayName()}</th>
|
||||||
|
{loop="users"}
|
||||||
|
<td><a href="">{$value->getDisplayName()}</a></td>
|
||||||
|
{/loop}
|
||||||
</tr>
|
</tr>
|
||||||
{/loop}
|
{/loop}
|
||||||
</table>
|
</table>
|
||||||
|
@ -1,3 +1,10 @@
|
|||||||
function set_days_month_year() {
|
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';
|
||||||
|
}
|
||||||
|
@ -9,7 +9,7 @@
|
|||||||
<textarea name="what" id="what" rows="10">{$what_post}</textarea>
|
<textarea name="what" id="what" rows="10">{$what_post}</textarea>
|
||||||
<p>
|
<p>
|
||||||
<label for="amount">Amount : </label>
|
<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>
|
||||||
<p>
|
<p>
|
||||||
<label for="date_day">Date : </label>
|
<label for="date_day">Date : </label>
|
||||||
@ -32,7 +32,7 @@
|
|||||||
<p>
|
<p>
|
||||||
Users in ?
|
Users in ?
|
||||||
{loop="users"}
|
{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}
|
{/loop}
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
|
Loading…
Reference in New Issue
Block a user