From 53e7d936703881ea1414cde98da6aa788a8b37ff Mon Sep 17 00:00:00 2001 From: Phyks Date: Sat, 17 Aug 2013 18:43:35 +0200 Subject: [PATCH] New invoice form improved --- TODO | 3 ++- inc/Invoices.class.php | 4 ++-- index.php | 22 +++++++++++++------ ....af3906cfde643ae7f290cfdc51cc9342.rtpl.php | 7 +++++- ....af3906cfde643ae7f290cfdc51cc9342.rtpl.php | 4 ++-- tpl/index.html | 5 ++++- tpl/js/main.js | 7 ++++++ tpl/new_invoice.html | 4 ++-- 8 files changed, 40 insertions(+), 16 deletions(-) diff --git a/TODO b/TODO index 8c0a114..c350cd0 100755 --- a/TODO +++ b/TODO @@ -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 : ======================= diff --git a/inc/Invoices.class.php b/inc/Invoices.class.php index 45e9eb5..808edfd 100644 --- a/inc/Invoices.class.php +++ b/inc/Invoices.class.php @@ -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; } diff --git a/index.php b/index.php index 175bf28..67e9d3c 100644 --- a/index.php +++ b/index.php @@ -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; diff --git a/tmp/index.af3906cfde643ae7f290cfdc51cc9342.rtpl.php b/tmp/index.af3906cfde643ae7f290cfdc51cc9342.rtpl.php index b8af817..09b56ae 100755 --- a/tmp/index.af3906cfde643ae7f290cfdc51cc9342.rtpl.php +++ b/tmp/index.af3906cfde643ae7f290cfdc51cc9342.rtpl.php @@ -9,7 +9,7 @@

Balance

-

Read line owes case to column. You can click on links to confirm the payback. +

Read line owes case to column. You can click on links to confirm the payback. @@ -23,6 +23,11 @@ + $value2 ){ $counter2++; ?> + + + + diff --git a/tmp/new_invoice.af3906cfde643ae7f290cfdc51cc9342.rtpl.php b/tmp/new_invoice.af3906cfde643ae7f290cfdc51cc9342.rtpl.php index b289f93..8a925f7 100644 --- a/tmp/new_invoice.af3906cfde643ae7f290cfdc51cc9342.rtpl.php +++ b/tmp/new_invoice.af3906cfde643ae7f290cfdc51cc9342.rtpl.php @@ -10,7 +10,7 @@

- + value="" size="5"/>

@@ -41,7 +41,7 @@ Users in ? $value1 ){ $counter1++; ?> -
and . +
getId() == $value1->getId() || in_array($value1->getId(), $users_in) ){ ?> checked /> and .

diff --git a/tpl/index.html b/tpl/index.html index 5baee74..5453ece 100755 --- a/tpl/index.html +++ b/tpl/index.html @@ -6,7 +6,7 @@

Balance

-

Read line owes case{$currency} to column. You can click on links to confirm the payback. +

Read line owes case {$currency} to column. You can click on links to confirm the payback.

Owes\To
getDisplayName();?>getDisplayName();?>
@@ -17,6 +17,9 @@ {loop="users"} + {loop="users"} + + {/loop} {/loop}
Owes\To
{$value->getDisplayName()}{$value->getDisplayName()}
diff --git a/tpl/js/main.js b/tpl/js/main.js index 4e44235..48608e0 100644 --- a/tpl/js/main.js +++ b/tpl/js/main.js @@ -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'; +} diff --git a/tpl/new_invoice.html b/tpl/new_invoice.html index 58123dd..0b79d59 100755 --- a/tpl/new_invoice.html +++ b/tpl/new_invoice.html @@ -9,7 +9,7 @@

- {$currency} + {$currency}

@@ -32,7 +32,7 @@

Users in ? {loop="users"} -
and . +
and getId(), $users_in)"} {$guests[$value->getId()]} {else} 0 {/if}" onchange="guest_user_label({$value->getId()});"/>. {/loop}