Improve "add invoice" form
This commit is contained in:
parent
9bdf052ae0
commit
c63e7116b3
13
TODO
13
TODO
@ -12,20 +12,9 @@ install.php :
|
|||||||
|
|
||||||
inc/Invoices.class.php :
|
inc/Invoices.class.php :
|
||||||
========================
|
========================
|
||||||
* Better way to store date ? (use specific date types)
|
* Better way to store users in ? => reprendre cette partie
|
||||||
* 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 ?
|
* 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 :
|
Manage paybacks :
|
||||||
=================
|
=================
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
protected $TABLE_NAME = "Invoices";
|
protected $TABLE_NAME = "Invoices";
|
||||||
protected $fields = array(
|
protected $fields = array(
|
||||||
'id'=>'key',
|
'id'=>'key',
|
||||||
'date'=>'int',
|
'date'=>'date',
|
||||||
'users_in'=>'string',
|
'users_in'=>'string',
|
||||||
'buyer'=>'int',
|
'buyer'=>'int',
|
||||||
'amount'=>'float',
|
'amount'=>'float',
|
||||||
@ -42,8 +42,11 @@
|
|||||||
$this->id = (int) $id;
|
$this->id = (int) $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setDate($date) {
|
public function setDate($date_day, $date_month, $date_year) {
|
||||||
$this->date = $date;
|
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) {
|
public function setUsersIn($users_in) {
|
||||||
|
@ -67,6 +67,10 @@ class Storage {
|
|||||||
$return = 'VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci';
|
$return = 'VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci';
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 'date':
|
||||||
|
$return = 'DATETIME NOT NULL';
|
||||||
|
break;
|
||||||
|
|
||||||
case 'bool':
|
case 'bool':
|
||||||
$return = 'TINYINT(1)';
|
$return = 'TINYINT(1)';
|
||||||
break;
|
break;
|
||||||
|
@ -197,7 +197,7 @@
|
|||||||
$tpl->assign('mysql_login', MYSQL_LOGIN);
|
$tpl->assign('mysql_login', MYSQL_LOGIN);
|
||||||
$tpl->assign('mysql_db', MYSQL_DB);
|
$tpl->assign('mysql_db', MYSQL_DB);
|
||||||
$tpl->assign('mysql_prefix', MYSQL_PREFIX);
|
$tpl->assign('mysql_prefix', MYSQL_PREFIX);
|
||||||
$tpl->assign('timezone', '');
|
$tpl->assign('timezone', @date_default_timezone_get());
|
||||||
$tpl->assign('show_settings', true);
|
$tpl->assign('show_settings', true);
|
||||||
$tpl->draw('settings');
|
$tpl->draw('settings');
|
||||||
break;
|
break;
|
||||||
@ -233,7 +233,7 @@
|
|||||||
$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(time());
|
$invoice->setDate($date_day, $date_month, $date_year);
|
||||||
|
|
||||||
$users_in = '';
|
$users_in = '';
|
||||||
$guests = array();
|
$guests = array();
|
||||||
|
@ -27,6 +27,10 @@
|
|||||||
|
|
||||||
//Create table "Invoices"
|
//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');
|
$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
|
//Create table "Payback" - TODO
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
$error = 'Unable to connect to database, check your credentials and config.<br/>Error message : '.$e->getMessage().'.';
|
$error = 'Unable to connect to database, check your credentials and config.<br/>Error message : '.$e->getMessage().'.';
|
||||||
|
@ -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>
|
</html>
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
<title><?php echo $instance_title;?></title>
|
<title><?php echo $instance_title;?></title>
|
||||||
<link rel="stylesheet" media="screen" type="text/css" href="tpl/./css/style.css" />
|
<link rel="stylesheet" media="screen" type="text/css" href="tpl/./css/style.css" />
|
||||||
<link rel="icon" href="tpl/./favicon.ico" />
|
<link rel="icon" href="tpl/./favicon.ico" />
|
||||||
<script type="text/javascript" src="tpl/./js/main.js"></script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<?php if( !$connection ){ ?>
|
<?php if( !$connection ){ ?>
|
||||||
|
10
tmp/new_invoice.af3906cfde643ae7f290cfdc51cc9342.rtpl.php
Normal file → Executable file
10
tmp/new_invoice.af3906cfde643ae7f290cfdc51cc9342.rtpl.php
Normal file → Executable file
@ -22,17 +22,17 @@
|
|||||||
<?php } ?>
|
<?php } ?>
|
||||||
|
|
||||||
</select> /
|
</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++; ?>
|
<?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 } ?>
|
<?php } ?>
|
||||||
|
|
||||||
</select> /
|
</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++; ?>
|
<?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 } ?>
|
<?php } ?>
|
||||||
|
|
||||||
</select>
|
</select>
|
||||||
@ -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();?>" <?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 } ?>
|
<?php } ?>
|
||||||
|
|
||||||
</p>
|
</p>
|
||||||
|
@ -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>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
<title>{$instance_title}</title>
|
<title>{$instance_title}</title>
|
||||||
<link rel="stylesheet" media="screen" type="text/css" href="css/style.css" />
|
<link rel="stylesheet" media="screen" type="text/css" href="css/style.css" />
|
||||||
<link rel="icon" href="favicon.ico" />
|
<link rel="icon" href="favicon.ico" />
|
||||||
<script type="text/javascript" src="js/main.js"></script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{if condition="!$connection"}
|
{if condition="!$connection"}
|
||||||
|
6
tpl/js/jquery-1.10.2.min.js
vendored
Normal file
6
tpl/js/jquery-1.10.2.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@ -1,5 +1,28 @@
|
|||||||
function set_days_month_year() {
|
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) {
|
function guest_user_label(id) {
|
||||||
|
@ -18,21 +18,21 @@
|
|||||||
<option value="{$value}" {if condition="$value == $day_post"}selected{/if}>{$value}</option>
|
<option value="{$value}" {if condition="$value == $day_post"}selected{/if}>{$value}</option>
|
||||||
{/loop}
|
{/loop}
|
||||||
</select> /
|
</select> /
|
||||||
<select name="date_month">
|
<select name="date_month" id="date_month" onchange="set_days_month_year();">
|
||||||
{loop="months"}
|
{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}
|
{/loop}
|
||||||
</select> /
|
</select> /
|
||||||
<select name="date_year">
|
<select name="date_year" id="date_year" onchange="set_days_month_year();">
|
||||||
{loop="years"}
|
{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}
|
{/loop}
|
||||||
</select>
|
</select>
|
||||||
</p>
|
</p>
|
||||||
<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()}" {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}
|
{/loop}
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
|
Loading…
Reference in New Issue
Block a user