[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

SF.net SVN: ledger-smb: [1759] trunk



Revision: 1759
          http://ledger-smb.svn.sourceforge.net/ledger-smb/?rev=1759&view=rev
Author:   tetragon
Date:     2007-10-15 11:00:54 -0700 (Mon, 15 Oct 2007)

Log Message:
-----------
Convert till_closing to templates

Modified Paths:
--------------
    trunk/bin/rc.pl

Added Paths:
-----------
    trunk/UI/rc-till-closing.html

Added: trunk/UI/rc-till-closing.html
===================================================================
--- trunk/UI/rc-till-closing.html	                        (rev 0)
+++ trunk/UI/rc-till-closing.html	2007-10-15 18:00:54 UTC (rev 1759)
@@ -0,0 +1,84 @@
+<?lsmb INCLUDE 'ui-header.html' ?> 
+<?lsmb PROCESS elements.html ?> 
+<body>
+<script type='text/javascript'>
+function money_round(m){
+  var r;
+  r = Math.round(m * 100)/100;
+  return r;
+}
+
+function custom_calc_total(){
+<?lsmb sub_sum = []; round_line = [];
+FOREACH unit IN units;
+  sub_sum.push("document.forms[0].sub_${unit.unit_name}.value * 1");
+  round_line.push("document.forms[0].sub_${unit.unit_name}.value = money_round(document.forms[0].sub_${unit.unit_name}.value);");
+ ?>
+    document.forms[0].sub_<?lsmb unit.unit_name ?>.value = document.forms[0].calc_<?lsmb unit.unit_name ?>.value * <?lsmb unit.unit ?>;
+<?lsmb END ?>
+    document.forms[0].sub_sub.value = <?lsmb sub_sum.join(' + ') ?>
+    <?lsmb round_line.join(' ') ?>
+    document.forms[0].sub_sub.value = 
+        money_round(document.forms[0].sub_sub.value);
+    document.forms[0].amount_cash.value = money_round(
+        document.forms[0].sub_sub.value - <?lsmb pos.till_cash ?>);
+    check_errors();
+}
+function check_errors(){
+    var cumulative_error = 0;
+    var source_error = 0;
+    var err_cell;
+
+<?lsmb FOREACH source IN sources; s = source.source ?>
+    source_error = money_round(
+        document.forms[0].amount_<?lsmb s ?>.value -
+        document.forms[0].expected_<?lsmb s ?>.value
+        );
+    cumulative_error = cumulative_error + source_error;
+    err_cell = document.getElementById('error_<?lsmb s ?>');
+    err_cell.innerHTML = '<?lsmb pos.curren ?>' + source_error;
+<?lsmb END ?>
+
+    alert('<?lsmb text('Cumulative Error:') ?> ' + money_round(cumulative_error));
+}
+</script>
+<form method="post" action="<?lsmb form.script ?>">
+<table width="100%">
+  <tr>
+    <th class="listtop"><?lsmb form.title ?></th>
+  </tr>
+</table> 
+<table width="100%">
+<tr><?lsmb FOREACH column IN columns ?>
+<td class="listheading"><?lsmb text(column) ?></td>
+<?lsmb END ?></tr>
+<?lsmb FOREACH source IN sources ?><tr class="listrow<?lsmb source.i ?>">
+    <td><?lsmb source.label ?></td>
+    <td><?lsmb PROCESS input element_data={name => "amount_${source.source}"} ?></td>
+    <td><?lsmb source.currenamount ?></td>
+    <td id="error_<?lsmb source.source ?>"></td>
+</tr><?lsmb END ?><tr><td colspan="4">
+<table>
+    <?lsmb FOREACH unit IN units ?><tr>
+      <td><?lsmb PROCESS input element_data=unit.quantity ?></td>
+      <th>X <?lsmb unit.currenunit ?> = </th>
+      <td><?lsmb PROCESS input element_data=unit.value ?></td>
+    </tr><?lsmb END ?>
+    <tr>
+    <td>&nbsp;</td>
+    <th><?lsmb text('Subtotal:') ?></th>
+    <td><?lsmb PROCESS input element_data={name => 'sub_sub' value => form.sub_sub} ?></td>
+  </tr>
+  </table></td></tr>
+</table>
+<?lsmb FOREACH hidden IN hiddens.keys;
+	PROCESS input element_data={
+		type => 'hidden',
+		name => hidden,
+		value => hiddens.item(hidden)
+		}; END ?>
+<?lsmb FOREACH button IN buttons; PROCESS button element_data=button; END ?>
+</form>
+
+</body>
+</html>

Modified: trunk/bin/rc.pl
===================================================================
--- trunk/bin/rc.pl	2007-10-15 04:46:35 UTC (rev 1758)
+++ trunk/bin/rc.pl	2007-10-15 18:00:54 UTC (rev 1759)
@@ -209,6 +209,7 @@
 sub continue { &{ $form->{nextsub} } }
 
 sub till_closing {
+    my %hiddens;
     $form->{callback} =
 "$form->{script}?path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}";
 
@@ -222,31 +223,16 @@
     $form->{title} = $locale->text( "Closing Till For [_1]", $form->{login} );
     require "pos.conf.pl";
     RC->getposlines( \%myconfig, \%$form );
-    $form->header;
-    print qq|
-<body>
 
-<form method=post action=$form->{script}>
-<input type=hidden name=path value=$form->{path}>
-<input type=hidden name=login value=$form->{login}>
-<input type=hidden name=sessionid value=$form->{sessionid}>
+    $hiddens{path} = $form->{path};
+    $hiddens{login} = $form->{login};
+    $hiddens{sessionid} = $form->{sessionid};
+    $hiddens{callback} = $form->{callback};
+    $hiddens{sum} = "$form->{sum}" * -1;
 
-<input type=hidden name=callback value="$form->{callback}">
-<input type=hidden name=sum value="| . $form->{sum} * -1 . qq|">
-<table width=100%>
-  <tr>
-    <th class=listtop>$form->{title}</th>
-  </tr>
-</table> 
-<table width=100%>
-|;
-
-    print "<tr>";
-    map { print "<td class=listheading>" . $locale->text($_) . "</td>"; }
-      @colheadings;
-    print "</tr>";
     my $j;
     my $source;
+    my @sources;
     foreach $source ( sort keys %pos_sources ) {
         $amount = 0;
         foreach $ref ( @{ $form->{TB} } ) {
@@ -257,103 +243,56 @@
         }
         ++$j;
         $j = $j % 2;
-        print qq|<tr class=listrow$j><td>| . $pos_sources{$source} . qq|</td>
-             <td><input name="amount_$source">
-             <input type=hidden name="expected_$source" 
-		value="$amount"></td>
-             <td>${curren}$amount</td>
-             <td id="error_$source">&nbsp;</td></tr>|;
+        push @sources, {i => $j,
+            label => $pos_sources{$source},
+            source => $source,
+            currenamount => "${curren}${amount}",
+            };
+        $hiddens{"expected_$source"} = "$amount";
     }
-    print qq|
-<script type='text/javascript'>
- 
-function money_round(m){
-  var r;
-  r = Math.round(m * 100)/100;
-  return r;
-}
-
-function custom_calc_total(){
-  |;
-    my $subgen  = 'document.forms[0].sub_sub.value = ';
-    my $toround = '';
+    my @units;
     foreach my $unit ( @{ $pos_config{'breakdown'} } ) {
 
         # XXX Needs to take into account currencies that don't use 2 dp
-        my $parsed = $form->parse_amount( \%pos_config, $unit );
-        my $calcval = $parsed;
-        $calcval = sprintf( '%03d', $calcval * 100 ) if $calcval < 1;
-        my $subval = 'sub_' . $calcval;
-        $calcval = 'calc_' . $calcval;
-        print qq|
-  document.forms[0].${subval}.value = document.forms[0].${calcval}.value * $parsed;
-    |;
-        $subgen  .= "document.forms[0].${subval}.value * 1 + ";
-        $toround .= qq|
-    	document.forms[0].${subval}.value = 
-    	money_round(document.forms[0].${subval}.value); |;
-    }
-    print $subgen . "0;";
-    print $toround;
-    print qq|document.forms[0].sub_sub.value = 
-           money_round(document.forms[0].sub_sub.value);
-  document.forms[0].amount_cash.value = money_round(
-	document.forms[0].sub_sub.value - $pos_config{till_cash});
-  check_errors();
-}
-function check_errors(){
-  var cumulative_error = 0;
-  var source_error = 0;
-  var err_cell;
-  |;
-    map {
-        print "  source_error = money_round(
-	document.forms[0].amount_$_.value - 
- 	document.forms[0].expected_$_.value);
-  cumulative_error = cumulative_error + source_error;
-  err_cell = document.getElementById('error_$_');
-  err_cell.innerHTML = '$curren' + source_error;\n";
-    } ( keys %pos_sources );
-    print qq|
-  alert('|
-      . $locale->text('Cumulative Error:')
-      . qq| $curren' + money_round(cumulative_error));
-}
-</script>
-
-<table>
-<col><col><col>|;
-    foreach my $unit ( @{ $pos_config{'breakdown'} } ) {
-
-        # XXX Needs to take into account currencies that don't use 2 dp
         my $calcval = $form->parse_amount( \%pos_config, $unit );
         $calcval = sprintf( '%03d', $calcval * 100 ) if $calcval < 1;
         my $subval = 'sub_' . $calcval;
+        my $unit_name = $calcval;
         $calcval = 'calc_' . $calcval;
-        print qq|<tr>
-      <td><input type=text name=$calcval value="$form->{$calcval}"></td>
-      <th>X ${curren}${unit} = </th>
-      <td><input type="text" name="$subval" value="$form->{$subval}"></td>
-    </tr>|;
+        push @units, {
+            unit => $unit,
+            unit_name => "$unit_name",
+            currenunit => "${curren}${unit}",
+            quantity => {name => $calcval, value => $form->{$calcval}},
+            value => {name => $subval, value => $form->{$subval}},
+            };
     }
-    print qq|<tr>
-    <td>&nbsp;</td>
-    <th>| . $locale->text("Subtotal") . qq|:</th>
-    <td><input type=text name=sub_sub value="$form->{sub_sub}"></td>
-  </tr>
-  </table>
-<input type=button name=calculate class=submit onClick="custom_calc_total()" 
-   value='| . $locale->text('Calculate') . qq|'>
-|;
-    print qq|</table><button type="submit" name="action" value="close_till">|
-      . $locale->text("Close Till")
-      . qq|</button>|;
-    print qq|
-</form>
-
-</body>
-</html>
-|;
+    my @buttons = ({
+        name => 'calculate',
+        value => 'Calculate',
+        type => 'button',
+        text => $locale->text('Calculate'),
+        attributes => {onclick => 'custom_calc_total()'},
+    }, {
+        name => 'action',
+        value => 'close_till',
+        text => $locale->text('Close Till'),
+    });
+    my $template = LedgerSMB::Template->new_UI(
+        user => \%myconfig, 
+        locale => $locale, 
+        template => 'rc-till-closing',
+        );
+    $template->render({
+        form => $form,
+        user => \%myconfig, 
+        'pos' => \%pos_config, 
+        hiddens => \%hiddens,
+        columns => ..hidden..,
+        sources => ..hidden..,
+        units => ..hidden..,
+        buttons => ..hidden..,
+    });
 }
 
 sub close_till {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.