From dde3b204b288b72ce848bdc72762acab5399fef0 Mon Sep 17 00:00:00 2001 From: einhverfr Date: Mon, 16 Jul 2007 00:03:37 +0000 Subject: Credit/Debit notes now work, credit/debit invoices still need some testing git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@1399 4979c152-3d1c-0410-bac9-87ea11338e46 --- LedgerSMB.pm | 2 +- LedgerSMB/AA.pm | 24 ++++++++++++++++-------- LedgerSMB/CT.pm | 2 +- LedgerSMB/Form.pm | 20 ++++++++++++++------ LedgerSMB/IR.pm | 9 ++++++--- LedgerSMB/IS.pm | 10 ++++++++-- LedgerSMB/Menu.pm | 1 - LedgerSMB/Template.pm | 1 + bin/aa.pl | 51 ++++++++++++++++++++++++++++++++++++++++++++++----- bin/ir.pl | 24 ++++++++++++++++++------ bin/is.pl | 25 ++++++++++++++++++------- lsmb-request.pl | 1 + scripts/menu.pl | 2 +- 13 files changed, 131 insertions(+), 41 deletions(-) diff --git a/LedgerSMB.pm b/LedgerSMB.pm index 89aa2f92..083ecb8a 100755 --- a/LedgerSMB.pm +++ b/LedgerSMB.pm @@ -226,7 +226,7 @@ sub new { sub _get_password { my ($self) = shift @_; $self->{sessionexpired} = shift @_; - @{$self->{hidden}} = []; + $self->{hidden} = []; for (keys %$self){ next if $_ =~ /(^script$|^endsession$|^password$)/; my $attr = {}; diff --git a/LedgerSMB/AA.pm b/LedgerSMB/AA.pm index c29652b0..29bf8ce3 100644 --- a/LedgerSMB/AA.pm +++ b/LedgerSMB/AA.pm @@ -39,6 +39,12 @@ use LedgerSMB::Sysconfig; sub post_transaction { my ( $self, $myconfig, $form ) = @_; + for (1 .. $form->{rowcount}){ + $form->{"amount_$_"} = $form->parse_amount( + $myconfig, $form->{"amount_$_"} + ); + $form->{"amount_$_"} *= -1 if $form->{reverse}; + } # connect to database my $dbh = $form->{dbh}; @@ -89,11 +95,10 @@ sub post_transaction { my %tax = (); my $accno; - # add taxes foreach $accno (@taxaccounts) { - $fxtax += $tax{fxamount}{$accno} = - $form->parse_amount( $myconfig, $form->{"tax_$accno"} ); + $form->{"tax_$accno"} *= -1 if $form->{reverse}; + $fxtax += $tax{fxamount}{$accno} = $form->{"tax_$accno"}; $tax += $tax{fxamount}{$accno}; push @{ $form->{acc_trans}{taxes} }, @@ -125,8 +130,7 @@ sub post_transaction { my %amount = (); my $fxinvamount = 0; for ( 1 .. $form->{rowcount} ) { - $fxinvamount += $amount{fxamount}{$_} = - $form->parse_amount( $myconfig, $form->{"amount_$_"} ); + $fxinvamount += $amount{fxamount}{$_} = $form->{"amount_$_"}; } $form->{taxincluded} *= 1; @@ -207,7 +211,11 @@ sub post_transaction { # add payments for $i ( 1 .. $form->{paidaccounts} ) { - $fxamount = $form->parse_amount( $myconfig, $form->{"paid_$i"} ); + $form->{"paid_$i"} = $form->parse_amount( + $myconfig, $form->{"paid_$i"} + ); + $form->{"paid_$i"} *= -1 if $form->{reverse}; + $fxamount = $form->{"paid_$i"}; if ($fxamount) { $paid += $fxamount; @@ -294,7 +302,7 @@ sub post_transaction { SET invnumber = ?, ordnumber = ?, transdate = ?, - $form->{vc}_id = ?, + entity_id = ?, taxincluded = ?, amount = ?, duedate = ?, @@ -304,7 +312,7 @@ sub post_transaction { curr = ?, notes = ?, department_id = ?, - employee_id = ?, + person_id = ?, ponumber = ? WHERE id = ? |; diff --git a/LedgerSMB/CT.pm b/LedgerSMB/CT.pm index 768f2196..fd84016c 100644 --- a/LedgerSMB/CT.pm +++ b/LedgerSMB/CT.pm @@ -325,7 +325,7 @@ sub _save_vc { $sth->execute( $form->{entity_id}, $form->{entity_class}, $form->{discount}, $form->{taxincluded}, $form->{creditlimit}, - $form->{terms}, $form->{"$form->{vc}number"}, $form->{cc}, + $form->{terms}, $form->{"$form->{db}number"}, $form->{cc}, $form->{bcc}, $form->{business_id}, $form->{language_code}, $form->{pricegroup_id}, $form->{curr}, $form->{startdate} || undef, $form->{enddate} || undef, diff --git a/LedgerSMB/Form.pm b/LedgerSMB/Form.pm index e0eaf529..f914ce46 100644 --- a/LedgerSMB/Form.pm +++ b/LedgerSMB/Form.pm @@ -1241,15 +1241,20 @@ sub all_vc { my $sth; - my $query = qq|SELECT count(*) FROM $vc|; + if ($vc eq 'customer'){ + $self->{vc_class} = 2; + } else { + $self->{vc_class} = 1; + } + my $query = qq|SELECT count(*) FROM entity_credit_account where entity_class = ?|; my $where; - my @queryargs = (); + my @queryargs = ($self->{vc_class}); if ($transdate) { - $query .= qq| WHERE (startdate IS NULL OR startdate <= ?) + $query .= qq| AND (startdate IS NULL OR startdate <= ?) AND (enddate IS NULL OR enddate >= ?)|; - @queryargs = ( $transdate, $transdate ); + push (@queryargs, $transdate, $transdate ); } $sth = $dbh->prepare($query); @@ -1596,7 +1601,7 @@ sub create_links { d.description AS department, a.amount AS oldinvtotal, a.paid AS oldtotalpaid, a.employee_id, e.name AS employee, - c.language_code, a.ponumber + c.language_code, a.ponumber, a.reverse FROM $arap a JOIN $vc c ON (a.${vc}_id = c.id) LEFT JOIN employee e ON (e.id = a.employee_id) @@ -1664,6 +1669,9 @@ sub create_links { $ref->{exchangerate} = $self->get_exchangerate( $dbh, $self->{currency}, $ref->{transdate}, $fld ); + if ($form->{reverse}){ + $ref->{amount} *= -1; + } push @{ $self->{acc_trans}{ $xkeyref{ $ref->{accno} } } }, $ref; } @@ -1741,7 +1749,7 @@ sub lastname_used { where entity_id IS NOT NULL $where order by id DESC limit 1)|; - $sth = $dbh->prepare($query); + $sth = $self->{dbh}->prepare($query); $sth->execute() || $self->dberror($query); my $ref = $sth->fetchrow_hashref(NAME_lc); diff --git a/LedgerSMB/IR.pm b/LedgerSMB/IR.pm index 7a26de61..3c44df45 100644 --- a/LedgerSMB/IR.pm +++ b/LedgerSMB/IR.pm @@ -45,6 +45,7 @@ sub post_invoice { unless $form->{invnumber}; for ( 1 .. $form->{rowcount} ) { + $form->{"qty_$_"} *= -1 if $form->{reverse}; unless ( $form->{"deliverydate_$_"} ) { $form->{"deliverydate_$_"} = $form->{transdate}; } @@ -285,6 +286,7 @@ sub post_invoice { deliverydate = ?, project_id = ?, serialnumber = ?, + reverse = ? notes = ? WHERE id = ?|; $sth = $dbh->prepare($query); @@ -295,7 +297,8 @@ sub post_invoice { $form->{"discount_$i"}, $allocated, $form->{"unit_$i"}, $form->{"deliverydate_$i"}, $project_id, $form->{"serialnumber_$i"}, - $form->{"notes_$i"}, $invoice_id + $form->{reverse}, $form->{"notes_$i"}, + $invoice_id ) || $form->dberror($query); if (defined $form->{approved}) { @@ -1070,7 +1073,7 @@ sub retrieve_invoice { a.ordnumber, a.quonumber, a.paid, a.taxincluded, a.notes, a.intnotes, a.curr AS currency, a.vendor_id, a.language_code, a.ponumber, - a.on_hold + a.on_hold, a.reverse FROM ap a WHERE id = ?|; $sth = $dbh->prepare($query); @@ -1138,7 +1141,7 @@ sub retrieve_invoice { while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) { $form->db_parse_numeric(sth=>$sth, hashref=>$ref); - + $ref->{qty} *= -1 if $form->{reverse}; my ($dec) = ( $ref->{fxsellprice} =~ /\.(\d+)/ ); $dec = length $dec; my $decimalplaces = ( $dec > 2 ) ? $dec : 2; diff --git a/LedgerSMB/IS.pm b/LedgerSMB/IS.pm index f76e13f2..4967f999 100644 --- a/LedgerSMB/IS.pm +++ b/LedgerSMB/IS.pm @@ -912,6 +912,9 @@ sub post_invoice { foreach $i ( 1 .. $form->{rowcount} ) { $form->{"qty_$i"} = $form->parse_amount( $myconfig, $form->{"qty_$i"} ); + if ($form->{reverse}){ + $form->{"qty_$i"} *= -1; + } if ( $form->{"qty_$i"} ) { @@ -1120,6 +1123,7 @@ sub post_invoice { deliverydate = ?, project_id = ?, serialnumber = ?, + reverse = ?, notes = ? WHERE id = ?|; @@ -1131,7 +1135,8 @@ sub post_invoice { $form->{"discount_$i"}, $allocated, $form->{"unit_$i"}, $form->{"deliverydate_$i"}, $project_id, $form->{"serialnumber_$i"}, - $form->{"notes_$i"}, $invoice_id + $form->{reverse}, $form->{"notes_$i"}, + $invoice_id ) || $form->dberror($query); if (defined $form->{approved}) { @@ -1793,7 +1798,7 @@ sub retrieve_invoice { a.intnotes, a.duedate, a.taxincluded, a.curr AS currency, a.employee_id, e.name AS employee, a.till, - a.entity_id, + a.entity_id, a.reverse a.language_code, a.ponumber, a.on_hold FROM ar a @@ -1863,6 +1868,7 @@ sub retrieve_invoice { while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) { $form->db_parse_numeric(sth=>$sth, hashref => $ref); + $ref->{qty} *= -1 if $form->{reverse}; my ($dec) = ( $ref->{fxsellprice} =~ /\.(\d+)/ ); $dec = length $dec; my $decimalplaces = ( $dec > 2 ) ? $dec : 2; diff --git a/LedgerSMB/Menu.pm b/LedgerSMB/Menu.pm index b95b7a6a..9e29fdf2 100644 --- a/LedgerSMB/Menu.pm +++ b/LedgerSMB/Menu.pm @@ -19,7 +19,6 @@ package LedgerSMB::Menu; use Config::Std; use base(qw(LedgerSMB::DBObject)); - 1; =head1 METHODS diff --git a/LedgerSMB/Template.pm b/LedgerSMB/Template.pm index 2366a9ca..ba2cd221 100755 --- a/LedgerSMB/Template.pm +++ b/LedgerSMB/Template.pm @@ -144,6 +144,7 @@ sub _http_output { my $self = shift; my $FH; + print STDERR "Content-Type: $self->{mimetype}; charset=utf-8\n\n"; if ($self->{mimetype} =~ /^text/) { print "Content-Type: $self->{mimetype}; charset=utf-8\n\n"; } else { diff --git a/bin/aa.pl b/bin/aa.pl index 73550101..e097a7b2 100644 --- a/bin/aa.pl +++ b/bin/aa.pl @@ -92,6 +92,18 @@ sub add { $form->{callback} = "$form->{script}?action=add&path=$form->{path}&login=$form->{login}&sessionid=$form->{sessionid}" unless $form->{callback}; + if ($form->{type} eq "credit_note"){ + $form->{reverse} = 1; + $form->{subtype} = 'credit_note'; + $form->{type} = 'transaction'; + } elsif ($form->{type} eq 'debit_note'){ + $form->{reverse} = 1; + $form->{subtype} = 'debit_note'; + $form->{type} = 'transaction'; + } + else { + $form->{reverse} = 0; + } &create_links; @@ -103,6 +115,18 @@ sub add { sub edit { $form->{title} = "Edit"; + if ($form->{reverse}){ + if ($form->{ARAP} eq 'AR'){ + $form->{subtype} = 'credit_note'; + $form->{type} = 'transaction'; + } elsif ($form->{ARAP} eq 'AP'){ + $form->{subtype} = 'debit_note'; + $form->{type} = 'transaction'; + } else { + $form->error("Unknown AR/AP selection value: $form->{ARAP}"); + } + + } &create_links; &display_form; @@ -375,12 +399,29 @@ qq|