Improve "add invoice" form

This commit is contained in:
Phyks 2013-08-22 23:14:14 +02:00
parent 9bdf052ae0
commit c63e7116b3
13 changed files with 62 additions and 31 deletions

13
TODO
View File

@ -12,20 +12,9 @@ install.php :
inc/Invoices.class.php :
========================
* Better way to store date ? (use specific date types)
* Better way to store users in ?
* Better way to store users in ? => reprendre cette partie
* 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
* Handle date/months
index.php?do=settings :
=======================
* Prefill the timezone field
Manage paybacks :
=================

View File

@ -7,7 +7,7 @@
protected $TABLE_NAME = "Invoices";
protected $fields = array(
'id'=>'key',
'date'=>'int',
'date'=>'date',
'users_in'=>'string',
'buyer'=>'int',
'amount'=>'float',
@ -42,8 +42,11 @@
$this->id = (int) $id;
}
public function setDate($date) {
$this->date = $date;
public function setDate($date_day, $date_month, $date_year) {
if((int) $date_day < 10) $date_day = "0".(int) $date_day;
if((int) $date_month < 10) $date_month = "0".(int) $date_month;
$this->date = $date_year.$date_month.$date_day;
}
public function setUsersIn($users_in) {

View File

@ -67,6 +67,10 @@ class Storage {
$return = 'VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci';
break;
case 'date':
$return = 'DATETIME NOT NULL';
break;
case 'bool':
$return = 'TINYINT(1)';
break;

View File

@ -197,7 +197,7 @@
$tpl->assign('mysql_login', MYSQL_LOGIN);
$tpl->assign('mysql_db', MYSQL_DB);
$tpl->assign('mysql_prefix', MYSQL_PREFIX);
$tpl->assign('timezone', '');
$tpl->assign('timezone', @date_default_timezone_get());
$tpl->assign('show_settings', true);
$tpl->draw('settings');
break;
@ -233,7 +233,7 @@
$invoice->setWhat($_POST['what']);
$invoice->setAmount($_POST['amount']);
$invoice->setBuyer($current_user->getId());
$invoice->setDate(time());
$invoice->setDate($date_day, $date_month, $date_year);
$users_in = '';
$guests = array();

View File

@ -27,6 +27,10 @@
//Create table "Invoices"
$db->query('CREATE TABLE IF NOT EXISTS '.$mysql_prefix.'Invoices (id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, date INT(11), users_in VARCHAR(255), buyer INT(11), amount FLOAT, what TEXT) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci');
//Create table "Users_in_invoice"
$db->query('CREATE TABLE IF NOT EXISTS '.$mysql_prefix.'Users_in_invoices (invoice_id INT(11) NOT NULL, KEY invoice_id (invoice_id), user_id INT(11), KEY user_id (user_id), guests INT(11)) DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci');
//Create table "Payback" - TODO
} catch (PDOException $e) {
$error = 'Unable to connect to database, check your credentials and config.<br/>Error message : '.$e->getMessage().'.';

View File

@ -1,2 +1,4 @@
<?php if(!class_exists('raintpl')){exit;}?> </body>
<?php if(!class_exists('raintpl')){exit;}?> <script type="text/javascript" src="tpl/./js/main.js"></script>
<script type="text/javascript" src="tpl/./js/jquery-1.10.2.min.js"></script>
</body>
</html>

View File

@ -5,7 +5,6 @@
<title><?php echo $instance_title;?></title>
<link rel="stylesheet" media="screen" type="text/css" href="tpl/./css/style.css" />
<link rel="icon" href="tpl/./favicon.ico" />
<script type="text/javascript" src="tpl/./js/main.js"></script>
</head>
<body>
<?php if( !$connection ){ ?>

View File

@ -22,17 +22,17 @@
<?php } ?>
</select> /
<select name="date_month">
<select name="date_month" id="date_month" onchange="set_days_month_year();">
<?php $counter1=-1; if( isset($months) && is_array($months) && sizeof($months) ) foreach( $months as $key1 => $value1 ){ $counter1++; ?>
<option value="<?php echo $value1;?>" <?php if( $value1 == $month_post ){ ?>selected<?php } ?> onchange="set_days_month_year();"><?php echo $value1;?></option>
<option value="<?php echo $value1;?>" <?php if( $value1 == $month_post ){ ?>selected<?php } ?>><?php echo $value1;?></option>
<?php } ?>
</select> /
<select name="date_year">
<select name="date_year" id="date_year" onchange="set_days_month_year();">
<?php $counter1=-1; if( isset($years) && is_array($years) && sizeof($years) ) foreach( $years as $key1 => $value1 ){ $counter1++; ?>
<option value="<?php echo $value1;?>" <?php if( $value1 == $year_post ){ ?>selected<?php } ?> onchange="set_days_month_year();"><?php echo $value1;?></option>
<option value="<?php echo $value1;?>" <?php if( $value1 == $year_post ){ ?>selected<?php } ?>><?php echo $value1;?></option>
<?php } ?>
</select>
@ -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();?>" <?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>.
<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" <?php if( in_array($value1->getId(), $users_in) ){ ?> value="<?php echo $guests[$value1->getId()];?>" <?php }else{ ?> value="0" <?php } ?> onkeyup="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

@ -1,2 +1,4 @@
<script type="text/javascript" src="js/main.js"></script>
<script type="text/javascript" src="js/jquery-1.10.2.min.js"></script>
</body>
</html>

View File

@ -5,7 +5,6 @@
<title>{$instance_title}</title>
<link rel="stylesheet" media="screen" type="text/css" href="css/style.css" />
<link rel="icon" href="favicon.ico" />
<script type="text/javascript" src="js/main.js"></script>
</head>
<body>
{if condition="!$connection"}

6
tpl/js/jquery-1.10.2.min.js vendored Normal file

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,28 @@
function set_days_month_year() {
var date_day = $('#date_day option:selected').val();
var date_month = $('#date_month option:selected').val();
var date_year = $('#date_year option:selected').val();
// Handle day for month
if(["4", "6", "9", "11"].indexOf(date_month) > -1) {
(! $('#date_day options[value=29]').length) && $('#date_day').append('<option value="29">29</option>');
(! $('#date_day options[value=30]').length) && $('#date_day').append('<option value="30">30</option>');
$('#date_day option[value=31]').remove();
}
else if(date_month == "2") {
// Handle bissextile years
$('#date_day option[value=30]').remove();
$('#date_day option[value=31]').remove();
if(date_year % 4 != 0 || date_year % 400 == 0) {
$('#date_day option[value=29]').remove();
}
}
else {
(! $('#date_day options[value=29]').length) && $('#date_day').append('<option value="29">29</option>');
(! $('#date_day options[value=30]').length) && $('#date_day').append('<option value="30">30</option>');
(! $('#date_day options[value=31]').length) && $('#date_day').append('<option value="31">31</option>');
}
}
function guest_user_label(id) {

View File

@ -18,21 +18,21 @@
<option value="{$value}" {if condition="$value == $day_post"}selected{/if}>{$value}</option>
{/loop}
</select> /
<select name="date_month">
<select name="date_month" id="date_month" onchange="set_days_month_year();">
{loop="months"}
<option value="{$value}" {if condition="$value == $month_post"}selected{/if} onchange="set_days_month_year();">{$value}</option>
<option value="{$value}" {if condition="$value == $month_post"}selected{/if}>{$value}</option>
{/loop}
</select> /
<select name="date_year">
<select name="date_year" id="date_year" onchange="set_days_month_year();">
{loop="years"}
<option value="{$value}" {if condition="$value == $year_post"}selected{/if} onchange="set_days_month_year();">{$value}</option>
<option value="{$value}" {if condition="$value == $year_post"}selected{/if}>{$value}</option>
{/loop}
</select>
</p>
<p>
Users in ?
{loop="users"}
<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>.
<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" {if condition="in_array($value->getId(), $users_in)"} value="{$guests[$value->getId()]}" {else} value="0" {/if} onkeyup="guest_user_label({$value->getId()});"/><label for="guest_user_{$value->getId()}" id="guest_user_{$value->getId()}_label"> guest</label>.
{/loop}
</p>
<p>