From 20c324814f67054484cb5d01669db1165812bd95 Mon Sep 17 00:00:00 2001 From: tetragon Date: Fri, 2 Nov 2007 15:57:33 +0000 Subject: Template list_payments (Point of Sale->Receipts) git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1839 4979c152-3d1c-0410-bac9-87ea11338e46 --- bin/rp.pl | 273 +++++++++++++++++++++++--------------------------------------- 1 file changed, 102 insertions(+), 171 deletions(-) (limited to 'bin') diff --git a/bin/rp.pl b/bin/rp.pl index 866dde8e..900b47be 100644 --- a/bin/rp.pl +++ b/bin/rp.pl @@ -2436,18 +2436,20 @@ sub tax_subtotal { sub list_payments { + my %hiddens; + my @options; if ( $form->{account} ) { ( $form->{paymentaccounts} ) = split /--/, $form->{account}; } if ( $form->{department} ) { ( $department, $form->{department_id} ) = split /--/, $form->{department}; - $option = $locale->text('Department') . " : $department"; + push @options, $locale->text('Department: [_1]', $department); } RP->payments( \%myconfig, \%$form ); - @columns = $form->sort_columns(qw(transdate name paid source memo)); + my @columns = $form->sort_columns(qw(transdate name paid source memo)); if ( $form->{till} ) { @columns = @@ -2460,10 +2462,10 @@ sub list_payments { } # construct href - $title = $form->escape( $form->{title} ); + my $title = $form->escape( $form->{title} ); $form->{paymentaccounts} =~ s/ /%20/g; - $href = + my $href = "$form->{script}?path=$form->{path}&direction=$form->{direction}&sort=$form->{sort}&oldsort=$form->{oldsort}&action=list_payments&till=$form->{till}&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&fx_transaction=$form->{fx_transaction}&db=$form->{db}&l_subtotal=$form->{l_subtotal}&prepayment=$form->{prepayment}&paymentaccounts=$form->{paymentaccounts}&title=" . $form->escape( $form->{title} ); @@ -2473,147 +2475,110 @@ sub list_payments { "$form->{script}?path=$form->{path}&direction=$form->{direction}&sort=$form->{sort}&oldsort=$form->{oldsort}&action=list_payments&till=$form->{till}&login=$form->{login}&sessionid=$form->{sessionid}&fromdate=$form->{fromdate}&todate=$form->{todate}&fx_transaction=$form->{fx_transaction}&db=$form->{db}&l_subtotal=$form->{l_subtotal}&prepayment=$form->{prepayment}&paymentaccounts=$form->{paymentaccounts}&title=" . $form->escape( $form->{title}, 1 ); + my $callback; if ( $form->{account} ) { $callback .= "&account=" . $form->escape( $form->{account}, 1 ); $href .= "&account=" . $form->escape( $form->{account} ); - $option .= "\n
" if ($option); - $option .= $locale->text('Account') . " : $form->{account}"; + push @options, $locale->text('Account: [_1]', $form->{account}); } if ( $form->{department} ) { $callback .= "&department=" . $form->escape( $form->{department}, 1 ); $href .= "&department=" . $form->escape( $form->{department} ); - $option .= "\n
" if ($option); - $option .= $locale->text('Department') . " : $form->{department}"; + push @options, $locale->text('Department: [_1]', $form->{department}); } if ( $form->{description} ) { $callback .= "&description=" . $form->escape( $form->{description}, 1 ); $href .= "&description=" . $form->escape( $form->{description} ); - $option .= "\n
" if ($option); - $option .= $locale->text('Description') . " : $form->{description}"; + push @options, $locale->text('Description: [_1]', $form->{description}); } if ( $form->{source} ) { $callback .= "&source=" . $form->escape( $form->{source}, 1 ); $href .= "&source=" . $form->escape( $form->{source} ); - $option .= "\n
" if ($option); - $option .= $locale->text('Source') . " : $form->{source}"; + push @options, $locale->text('Source: [_1]', $form->{source}); } if ( $form->{memo} ) { $callback .= "&memo=" . $form->escape( $form->{memo}, 1 ); $href .= "&memo=" . $form->escape( $form->{memo} ); - $option .= "\n
" if ($option); - $option .= $locale->text('Memo') . " : $form->{memo}"; + push @options, $locale->text('Memo: [_1]', $form->{memo}); } if ( $form->{fromdate} ) { - $option .= "\n
" if ($option); - $option .= - $locale->text('From') . " " - . $locale->date( \%myconfig, $form->{fromdate}, 1 ); + push @options, + $locale->text('From [_1]', + $locale->date( \%myconfig, $form->{fromdate}, 1 )); } if ( $form->{todate} ) { - $option .= "\n
" if ($option); - $option .= - $locale->text('To') . " " - . $locale->date( \%myconfig, $form->{todate}, 1 ); + push @options, + $locale->text('To [_1]', + $locale->date( \%myconfig, $form->{todate}, 1 )); } $callback = $form->escape( $form->{callback} ); - $column_header{name} = - "" - . $locale->text('Description') - . ""; - $column_header{transdate} = - "" - . $locale->text('Date') - . ""; - $column_header{paid} = - "" . $locale->text('Amount') . ""; - $column_header{curr} = - "" . $locale->text('Curr') . ""; - $column_header{source} = - "" - . $locale->text('Source') - . ""; - $column_header{memo} = - "" - . $locale->text('Memo') - . ""; - - $column_header{employee} = - "" - . $locale->text('Salesperson') - . ""; - $column_header{till} = - "" - . $locale->text('Till') - . ""; - - @column_index = @columns; - $colspan = $#column_index + 1; - - $form->header; - - print qq| - - - - - - - - - - - - - - - - -
$form->{title}
$option
- - -|; - - for (@column_index) { print "\n$column_header{$_}" } + my %column_header; + $column_header{name} = { + href => "$href&sort=name", + text => $locale->text('Description'), + }; + $column_header{transdate} = { + href => "$href&sort=transdate", + text => $locale->text('Date'), + }; + $column_header{paid} = $locale->text('Amount'); + $column_header{curr} = $locale->text('Curr'); + $column_header{source} = { + href => "$href&sort=source", + text => $locale->text('Source'), + }; + $column_header{memo} = { + href => "$href&sort=memo", + text => $locale->text('Memo'), + }; + $column_header{employee} = { + href => "$href&sort=employee", + text => $locale->text('Salesperson'), + }; + $column_header{till} = { + href => "$href&sort=till", + text => $locale->text('Till'), + }; - print qq| - -|; + my @column_index = @columns; - foreach $ref ( sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} } ) { + my @accounts; + my $i; + foreach my $ref ( sort { $a->{accno} cmp $b->{accno} } @{ $form->{PR} } ) { next unless @{ $form->{ $ref->{id} } }; - print qq| - - - -|; + push @accounts, {header => "$ref->{accno}--$ref->{description}"}; if ( @{ $form->{ $ref->{id} } } ) { $sameitem = $form->{ $ref->{id} }[0]->{ $form->{sort} }; } - foreach $payment ( @{ $form->{ $ref->{id} } } ) { + my @rows; + foreach my $payment ( @{ $form->{ $ref->{id} } } ) { if ( $form->{l_subtotal} ) { if ( $payment->{ $form->{sort} } ne $sameitem ) { # print subtotal - &payment_subtotal; + push @rows, &payment_subtotal(\@column_index); } } next if ( $form->{till} && !$payment->{till} ); - $column_data{name} = ""; - $column_data{transdate} = ""; + my %column_data; + $column_data{name} = $payment->{name}; + $column_data{transdate} = $payment->{transdate}; $column_data{paid} = - ""; - $column_data{curr} = ""; - $column_data{source} = ""; - $column_data{memo} = ""; - $column_data{employee} = ""; - $column_data{till} = ""; + $form->format_amount(\%myconfig, $payment->{paid}, 2, ' '); + $column_data{curr} = $payment->{curr}; + $column_data{source} = $payment->{source}; + $column_data{memo} = $payment->{memo}; + $column_data{employee} = $payment->{employee}; + $column_data{till} = $payment->{till}; $subtotalpaid += $payment->{paid}; $accounttotalpaid += $payment->{paid}; @@ -2621,104 +2586,70 @@ sub list_payments { $i++; $i %= 2; - print qq| - -|; - - for (@column_index) { print "\n$column_data{$_}" } - - print qq| - -|; + $column_data{i} = $i; + push @rows, \%column_data; $sameitem = $payment->{ $form->{sort} }; } - - &payment_subtotal if $form->{l_subtotal}; + push @rows, &payment_subtotal(\@column_index) if $form->{l_subtotal}; + $accounts[$#accounts]{rows} = \@rows; # print account totals - for (@column_index) { $column_data{$_} = "" } + my %column_data; + for (@column_index) { $column_data{$_} = ' ' } $column_data{paid} = - ""; - - print qq| - -|; - - for (@column_index) { print "\n$column_data{$_}" } - - print qq| - -|; + $form->format_amount( \%myconfig, $accounttotalpaid, 2, ' ' ); + $accounts[$#accounts]{totals} = \%column_data; $accounttotalpaid = 0; } - # print total - for (@column_index) { $column_data{$_} = "" } - - $column_data{paid} = - ""; - - print qq| - -|; - - for (@column_index) { print "\n$column_data{$_}" } - - print qq| - - -
$ref->{accno}--$ref->{description}
$payment->{name} $payment->{transdate} " - . $form->format_amount( \%myconfig, $payment->{paid}, 2, - " " ) - . "$payment->{curr}$payment->{source} $payment->{memo} $payment->{employee} $payment->{till} 
 " - . $form->format_amount( \%myconfig, $accounttotalpaid, 2, " " ) - . "
 " - . $form->format_amount( \%myconfig, $totalpaid, 2, " " ) . "
-

-|; - - if ( $form->{lynx} ) { - require "bin/menu.pl"; - &menubar; - } + # prepare total + my %column_data; + for (@column_index) { $column_data{$_} = ' ' } + $column_data{paid} = $form->format_amount( \%myconfig, $totalpaid, 2, ' ' ); - print qq| - - - -|; +##SC: Temporary removal +## if ( $form->{lynx} ) { +## require "bin/menu.pl"; +## &menubar; +## } + my $template = LedgerSMB::Template->new_UI( + user => \%myconfig, + locale => $locale, + template => 'rp-payments', + ); + $template->render({ + form => $form, + hiddens => \%hiddens, + options => \@options, + columns => \@column_index, + heading => \%column_header, + accounts => \@accounts, + totals => \%column_data, + row_alignment => { + paid => 'right', + }, + }); } sub payment_subtotal { + my $column_index = shift; + my %column_data; if ( $subtotalpaid != 0 ) { - for (@column_index) { $column_data{$_} = " " } + for (@column_index) { $column_data{$_} = ' ' } $column_data{paid} = - "" - . $form->format_amount( \%myconfig, $subtotalpaid, 2, " " ) - . ""; - - print qq| - -|; - - for (@column_index) { print "\n$column_data{$_}" } - - print qq| - -|; + $form->format_amount( \%myconfig, $subtotalpaid, 2, ' ' ); + $column_data{class} = 'subtotal'; } $subtotalpaid = 0; - + \%column_data; } -- cgit v1.2.3