diff options
author | einhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46> | 2007-04-12 20:46:20 +0000 |
---|---|---|
committer | einhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46> | 2007-04-12 20:46:20 +0000 |
commit | df073d6e09c0f87fb2e88cc215ace843a5851d4a (patch) | |
tree | 1c15ce909d3e0353b21bbd909e6720fd485a3a53 /LedgerSMB/GL.pm | |
parent | 65458125b8f3814fd6ef4d07b55ab69f62f5a528 (diff) |
Formatting with Perltidy
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/branches/1.2@1068 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'LedgerSMB/GL.pm')
-rwxr-xr-x | LedgerSMB/GL.pm | 728 |
1 files changed, 362 insertions, 366 deletions
diff --git a/LedgerSMB/GL.pm b/LedgerSMB/GL.pm index dab7b0a1..a5c39dbb 100755 --- a/LedgerSMB/GL.pm +++ b/LedgerSMB/GL.pm @@ -1,5 +1,5 @@ #===================================================================== -# LedgerSMB +# LedgerSMB # Small Medium Business Accounting software # http://www.ledgersmb.org/ # @@ -33,141 +33,138 @@ package GL; - sub delete_transaction { - my ($self, $myconfig, $form) = @_; + my ( $self, $myconfig, $form ) = @_; - # connect to database - my $dbh = $form->{dbh}; + # connect to database + my $dbh = $form->{dbh}; - my %audittrail = ( - tablename => 'gl', - reference => $form->{reference}, - formname => 'transaction', - action => 'deleted', - id => $form->{id} ); + my %audittrail = ( + tablename => 'gl', + reference => $form->{reference}, + formname => 'transaction', + action => 'deleted', + id => $form->{id} + ); - $form->audittrail($dbh, "", \%audittrail); - my $id = $dbh->quote($form->{id}); - my $query = qq|DELETE FROM gl WHERE id = $id|; - $dbh->do($query) || $form->dberror($query); + $form->audittrail( $dbh, "", \%audittrail ); + my $id = $dbh->quote( $form->{id} ); + my $query = qq|DELETE FROM gl WHERE id = $id|; + $dbh->do($query) || $form->dberror($query); - $query = qq|DELETE FROM acc_trans WHERE trans_id = $id|; - $dbh->do($query) || $form->dberror($query); + $query = qq|DELETE FROM acc_trans WHERE trans_id = $id|; + $dbh->do($query) || $form->dberror($query); - # commit and redirect - my $rc = $dbh->commit; + # commit and redirect + my $rc = $dbh->commit; - $rc; + $rc; } - sub post_transaction { - my ($self, $myconfig, $form) = @_; + my ( $self, $myconfig, $form ) = @_; + + my $null; + my $project_id; + my $department_id; + my $i; - my $null; - my $project_id; - my $department_id; - my $i; + # connect to database, turn off AutoCommit + my $dbh = $form->{dbh}; - # connect to database, turn off AutoCommit - my $dbh = $form->{dbh}; + my $query; + my $sth; - my $query; - my $sth; + my $id = $dbh->quote( $form->{id} ); + if ( $form->{id} ) { - my $id = $dbh->quote($form->{id}); - if ($form->{id}) { + $query = qq|SELECT id FROM gl WHERE id = $id|; + ( $form->{id} ) = $dbh->selectrow_array($query); - $query = qq|SELECT id FROM gl WHERE id = $id|; - ($form->{id}) = $dbh->selectrow_array($query); + if ( $form->{id} ) { - if ($form->{id}) { - # delete individual transactions - $query = qq| + # delete individual transactions + $query = qq| DELETE FROM acc_trans WHERE trans_id = $id|; - $dbh->do($query) || $form->dberror($query); - } - } + $dbh->do($query) || $form->dberror($query); + } + } - if (! $form->{id}) { + if ( !$form->{id} ) { - my $uid = localtime; - $uid .= "$$"; + my $uid = localtime; + $uid .= "$$"; - $query = qq| + $query = qq| INSERT INTO gl (reference, employee_id) VALUES ('$uid', (SELECT id FROM employee WHERE login = ?))|; - $sth = $dbh->prepare($query); - $sth->execute($form->{login}) || $form->dberror($query); + $sth = $dbh->prepare($query); + $sth->execute( $form->{login} ) || $form->dberror($query); - $query = qq| + $query = qq| SELECT id FROM gl WHERE reference = '$uid'|; - - ($form->{id}) = $dbh->selectrow_array($query); - } - ($null, $department_id) = split /--/, $form->{department}; - $department_id *= 1; + ( $form->{id} ) = $dbh->selectrow_array($query); + } - $form->{reference} = $form->update_defaults( - $myconfig, 'glnumber', $dbh) - unless $form->{reference}; - $form->{reference} ||= $form->{id}; + ( $null, $department_id ) = split /--/, $form->{department}; + $department_id *= 1; - $query = qq| + $form->{reference} = $form->update_defaults( $myconfig, 'glnumber', $dbh ) + unless $form->{reference}; + $form->{reference} ||= $form->{id}; + + $query = qq| UPDATE gl - SET reference = |.$dbh->quote($form->{reference}).qq|, - description = |.$dbh->quote($form->{description}).qq|, - notes = |.$dbh->quote($form->{notes}).qq|, + SET reference = | . $dbh->quote( $form->{reference} ) . qq|, + description = | . $dbh->quote( $form->{description} ) . qq|, + notes = | . $dbh->quote( $form->{notes} ) . qq|, transdate = ?, department_id = ? WHERE id = ?|; - $sth = $dbh->prepare($query); - $sth->execute($form->{transdate}, $department_id, $form->{id}) - || $form->dberror($query); - - my $amount = 0; - my $posted = 0; - my $debit; - my $credit; + $sth = $dbh->prepare($query); + $sth->execute( $form->{transdate}, $department_id, $form->{id} ) + || $form->dberror($query); - # insert acc_trans transactions - for $i (1 .. $form->{rowcount}) { + my $amount = 0; + my $posted = 0; + my $debit; + my $credit; - $debit = $form->parse_amount($myconfig, $form->{"debit_$i"}); - $credit = $form->parse_amount($myconfig, $form->{"credit_$i"}); + # insert acc_trans transactions + for $i ( 1 .. $form->{rowcount} ) { - # extract accno - ($accno) = split(/--/, $form->{"accno_$i"}); + $debit = $form->parse_amount( $myconfig, $form->{"debit_$i"} ); + $credit = $form->parse_amount( $myconfig, $form->{"credit_$i"} ); - if ($credit) { - $amount = $credit; - $posted = 0; - } + # extract accno + ($accno) = split( /--/, $form->{"accno_$i"} ); - if ($debit) { - $amount = $debit * -1; - $posted = 0; - } + if ($credit) { + $amount = $credit; + $posted = 0; + } - # add the record - if (! $posted) { + if ($debit) { + $amount = $debit * -1; + $posted = 0; + } - ($null, $project_id) = split /--/, - $form->{"projectnumber_$i"}; - $project_id ||= undef; + # add the record + if ( !$posted ) { + ( $null, $project_id ) = split /--/, $form->{"projectnumber_$i"}; + $project_id ||= undef; - $query = qq| + $query = qq| INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, source, project_id, @@ -177,232 +174,228 @@ sub post_transaction { WHERE accno = ?), ?, ?, ?, ?, ?, ?, ?)|; - $sth = $dbh->prepare($query); - $sth->execute( - $form->{id}, $accno, $amount, - $form->{transdate}, $form->{"source_$i"}, - $project_id, $form->{"fx_transaction_$i"}, - $form->{"memo_$i"}, $form->{"cleared_$i"} - ) || $form->dberror($query); + $sth = $dbh->prepare($query); + $sth->execute( + $form->{id}, $accno, + $amount, $form->{transdate}, + $form->{"source_$i"}, $project_id, + $form->{"fx_transaction_$i"}, $form->{"memo_$i"}, + $form->{"cleared_$i"} + ) || $form->dberror($query); - $posted = 1; - } - } + $posted = 1; + } + } - my %audittrail = ( - tablename => 'gl', - reference => $form->{reference}, - formname => 'transaction', - action => 'posted', - id => $form->{id} ); + my %audittrail = ( + tablename => 'gl', + reference => $form->{reference}, + formname => 'transaction', + action => 'posted', + id => $form->{id} + ); - $form->audittrail($dbh, "", \%audittrail); + $form->audittrail( $dbh, "", \%audittrail ); - $form->save_recurring($dbh, $myconfig); + $form->save_recurring( $dbh, $myconfig ); - # commit and redirect - my $rc = $dbh->commit; + # commit and redirect + my $rc = $dbh->commit; - $rc; + $rc; } - - sub all_transactions { - my ($self, $myconfig, $form) = @_; - - # connect to database - my $dbh = $form->{dbh}; - my $query; - my $sth; - my $var; - my $null; - - my ($glwhere, $arwhere, $apwhere) = ("1 = 1", "1 = 1", "1 = 1"); - - if ($form->{reference} ne "") { - $var = $dbh->quote($form->like(lc $form->{reference})); - $glwhere .= " AND lower(g.reference) LIKE $var"; - $arwhere .= " AND lower(a.invnumber) LIKE $var"; - $apwhere .= " AND lower(a.invnumber) LIKE $var"; - } - - if ($form->{department} ne "") { - ($null, $var) = split /--/, $form->{department}; - $var = $dbh->quote($var); - $glwhere .= " AND g.department_id = $var"; - $arwhere .= " AND a.department_id = $var"; - $apwhere .= " AND a.department_id = $var"; - } - - if ($form->{source} ne "") { - $var = $dbh->quote($form->like(lc $form->{source})); - $glwhere .= " AND lower(ac.source) LIKE $var"; - $arwhere .= " AND lower(ac.source) LIKE $var"; - $apwhere .= " AND lower(ac.source) LIKE $var"; - } - - if ($form->{memo} ne "") { - $var = $form->like(lc $form->{memo}); - $glwhere .= " AND lower(ac.memo) LIKE $var"; - $arwhere .= " AND lower(ac.memo) LIKE $var"; - $apwhere .= " AND lower(ac.memo) LIKE $var"; - } - - ($form->{datefrom}, $form->{dateto}) = $form->from_to( - $form->{year}, $form->{month}, $form->{interval}) - if $form->{year} && $form->{month}; - - if ($form->{datefrom}) { - $glwhere .= " AND ac.transdate >= ". - $dbh->quote($form->{datefrom}); - $arwhere .= " AND ac.transdate >= ". - $dbh->quote($form->{datefrom}); - $apwhere .= " AND ac.transdate >= ". - $dbh->quote($form->{datefrom}); - } - - if ($form->{dateto}) { - $glwhere .= " AND ac.transdate <= ". - $dbh->quote($form->{dateto}); - $arwhere .= " AND ac.transdate <= ". - $dbh->quote($form->{dateto}); - $apwhere .= " AND ac.transdate <= ". - $dbh->quote($form->{dateto}); - } - - if ($form->{amountfrom}) { - $glwhere .= " AND abs(ac.amount) >= ". - $dbh->quote($form->{amountfrom}); - $arwhere .= " AND abs(ac.amount) >= ". - $dbh->quote($form->{amountfrom}); - $apwhere .= " AND abs(ac.amount) >= ". - $dbh->quote($form->{amountfrom}); - } - - if ($form->{amountto}) { - $glwhere .= " AND abs(ac.amount) <= ". - $dbh->quote($form->{amountto}); - $arwhere .= " AND abs(ac.amount) <= ". - $dbh->quote($form->{amountto}); - $apwhere .= " AND abs(ac.amount) <= ". - $dbh->quote($form->{amountto}); - } - - if ($form->{description}) { - - $var = $dbh->quote($form->like(lc $form->{description})); - $glwhere .= " AND lower(g.description) LIKE $var"; - $arwhere .= " AND (lower(ct.name) LIKE $var + my ( $self, $myconfig, $form ) = @_; + + # connect to database + my $dbh = $form->{dbh}; + my $query; + my $sth; + my $var; + my $null; + + my ( $glwhere, $arwhere, $apwhere ) = ( "1 = 1", "1 = 1", "1 = 1" ); + + if ( $form->{reference} ne "" ) { + $var = $dbh->quote( $form->like( lc $form->{reference} ) ); + $glwhere .= " AND lower(g.reference) LIKE $var"; + $arwhere .= " AND lower(a.invnumber) LIKE $var"; + $apwhere .= " AND lower(a.invnumber) LIKE $var"; + } + + if ( $form->{department} ne "" ) { + ( $null, $var ) = split /--/, $form->{department}; + $var = $dbh->quote($var); + $glwhere .= " AND g.department_id = $var"; + $arwhere .= " AND a.department_id = $var"; + $apwhere .= " AND a.department_id = $var"; + } + + if ( $form->{source} ne "" ) { + $var = $dbh->quote( $form->like( lc $form->{source} ) ); + $glwhere .= " AND lower(ac.source) LIKE $var"; + $arwhere .= " AND lower(ac.source) LIKE $var"; + $apwhere .= " AND lower(ac.source) LIKE $var"; + } + + if ( $form->{memo} ne "" ) { + $var = $form->like( lc $form->{memo} ); + $glwhere .= " AND lower(ac.memo) LIKE $var"; + $arwhere .= " AND lower(ac.memo) LIKE $var"; + $apwhere .= " AND lower(ac.memo) LIKE $var"; + } + + ( $form->{datefrom}, $form->{dateto} ) = + $form->from_to( $form->{year}, $form->{month}, $form->{interval} ) + if $form->{year} && $form->{month}; + + if ( $form->{datefrom} ) { + $glwhere .= " AND ac.transdate >= " . $dbh->quote( $form->{datefrom} ); + $arwhere .= " AND ac.transdate >= " . $dbh->quote( $form->{datefrom} ); + $apwhere .= " AND ac.transdate >= " . $dbh->quote( $form->{datefrom} ); + } + + if ( $form->{dateto} ) { + $glwhere .= " AND ac.transdate <= " . $dbh->quote( $form->{dateto} ); + $arwhere .= " AND ac.transdate <= " . $dbh->quote( $form->{dateto} ); + $apwhere .= " AND ac.transdate <= " . $dbh->quote( $form->{dateto} ); + } + + if ( $form->{amountfrom} ) { + $glwhere .= + " AND abs(ac.amount) >= " . $dbh->quote( $form->{amountfrom} ); + $arwhere .= + " AND abs(ac.amount) >= " . $dbh->quote( $form->{amountfrom} ); + $apwhere .= + " AND abs(ac.amount) >= " . $dbh->quote( $form->{amountfrom} ); + } + + if ( $form->{amountto} ) { + $glwhere .= + " AND abs(ac.amount) <= " . $dbh->quote( $form->{amountto} ); + $arwhere .= + " AND abs(ac.amount) <= " . $dbh->quote( $form->{amountto} ); + $apwhere .= + " AND abs(ac.amount) <= " . $dbh->quote( $form->{amountto} ); + } + + if ( $form->{description} ) { + + $var = $dbh->quote( $form->like( lc $form->{description} ) ); + $glwhere .= " AND lower(g.description) LIKE $var"; + $arwhere .= " AND (lower(ct.name) LIKE $var OR lower(ac.memo) LIKE $var OR a.id IN (SELECT DISTINCT trans_id FROM invoice WHERE lower(description) LIKE $var))"; - $apwhere .= " AND (lower(ct.name) LIKE $var + $apwhere .= " AND (lower(ct.name) LIKE $var OR lower(ac.memo) LIKE $var OR a.id IN (SELECT DISTINCT trans_id FROM invoice WHERE lower(description) LIKE $var))"; - } - - if ($form->{notes}) { - $var = $dbh->quote($form->like(lc $form->{notes})); - $glwhere .= " AND lower(g.notes) LIKE $var"; - $arwhere .= " AND lower(a.notes) LIKE $var"; - $apwhere .= " AND lower(a.notes) LIKE $var"; - } - - if ($form->{accno}) { - $var = $dbh->quote($form->{accno}); - $glwhere .= " AND c.accno = $var"; - $arwhere .= " AND c.accno = $var"; - $apwhere .= " AND c.accno = $var"; - } - - if ($form->{gifi_accno}) { - $var = $dbh->quote($form->{gifiaccno}); - $glwhere .= " AND c.gifi_accno = $var"; - $arwhere .= " AND c.gifi_accno = $var"; - $apwhere .= " AND c.gifi_accno = $var"; - } - - if ($form->{category} ne 'X') { - $var = $dbh->quote($form->{gifiaccno}); - $glwhere .= " AND c.category = $var"; - $arwhere .= " AND c.category = $var"; - $apwhere .= " AND c.category = $var"; - } - - if ($form->{accno}) { - my $accno = $dbh->quote($form->{accno}); - - # get category for account - $query = qq|SELECT category, link, contra, description + } + + if ( $form->{notes} ) { + $var = $dbh->quote( $form->like( lc $form->{notes} ) ); + $glwhere .= " AND lower(g.notes) LIKE $var"; + $arwhere .= " AND lower(a.notes) LIKE $var"; + $apwhere .= " AND lower(a.notes) LIKE $var"; + } + + if ( $form->{accno} ) { + $var = $dbh->quote( $form->{accno} ); + $glwhere .= " AND c.accno = $var"; + $arwhere .= " AND c.accno = $var"; + $apwhere .= " AND c.accno = $var"; + } + + if ( $form->{gifi_accno} ) { + $var = $dbh->quote( $form->{gifiaccno} ); + $glwhere .= " AND c.gifi_accno = $var"; + $arwhere .= " AND c.gifi_accno = $var"; + $apwhere .= " AND c.gifi_accno = $var"; + } + + if ( $form->{category} ne 'X' ) { + $var = $dbh->quote( $form->{gifiaccno} ); + $glwhere .= " AND c.category = $var"; + $arwhere .= " AND c.category = $var"; + $apwhere .= " AND c.category = $var"; + } + + if ( $form->{accno} ) { + my $accno = $dbh->quote( $form->{accno} ); + + # get category for account + $query = qq|SELECT category, link, contra, description FROM chart WHERE accno = $accno|; - ($form->{category}, $form->{link}, $form->{contra}, - $form->{account_description}) = $dbh->selectrow_array($query); + ( + $form->{category}, $form->{link}, $form->{contra}, + $form->{account_description} + ) = $dbh->selectrow_array($query); - if ($form->{datefrom}) { + if ( $form->{datefrom} ) { - $query = qq| + $query = qq| SELECT SUM(ac.amount) FROM acc_trans ac JOIN chart c ON (ac.chart_id = c.id) WHERE c.accno = $accno - AND ac.transdate < date |. - $dbh->quote($form->{datefrom}); + AND ac.transdate < date | . $dbh->quote( $form->{datefrom} ); - ($form->{balance}) = $dbh->selectrow_array($query); - } - } + ( $form->{balance} ) = $dbh->selectrow_array($query); + } + } - if ($form->{gifi_accno}) { - my $gifi = $dbh->quote($form->{gifi_accno}); + if ( $form->{gifi_accno} ) { + my $gifi = $dbh->quote( $form->{gifi_accno} ); - # get category for account - $query = qq|SELECT c.category, c.link, c.contra, g.description + # get category for account + $query = qq|SELECT c.category, c.link, c.contra, g.description FROM chart c LEFT JOIN gifi g ON (g.accno = c.gifi_accno) WHERE c.gifi_accno = $gifi|; - ($form->{category}, $form->{link}, $form->{contra}, - $form->{gifi_account_description}) = $dbh->selectrow_array( - $query); + ( + $form->{category}, $form->{link}, $form->{contra}, + $form->{gifi_account_description} + ) = $dbh->selectrow_array($query); - if ($form->{datefrom}) { + if ( $form->{datefrom} ) { - $query = qq| + $query = qq| SELECT SUM(ac.amount) FROM acc_trans ac JOIN chart c ON (ac.chart_id = c.id) WHERE c.gifi_accno = $gifi - AND ac.transdate < date |. - $dbh->quote($form->{datefrom}); + AND ac.transdate < date | . $dbh->quote( $form->{datefrom} ); - ($form->{balance}) = $dbh->selectrow_array($query); - } - } + ( $form->{balance} ) = $dbh->selectrow_array($query); + } + } - my $false = 'FALSE'; + my $false = 'FALSE'; - my %ordinal = ( - id => 1, - reference => 4, - description => 5, - transdate => 6, - source => 7, - accno => 9, - department => 15, - memo => 16 ); + my %ordinal = ( + id => 1, + reference => 4, + description => 5, + transdate => 6, + source => 7, + accno => 9, + department => 15, + memo => 16 + ); - my @a = (id, transdate, reference, source, description, accno); - my $sortorder = $form->sort_order(\@a, \%ordinal); + my @a = ( id, transdate, reference, source, description, accno ); + my $sortorder = $form->sort_order( \@a, \%ordinal ); - my $query = qq|SELECT g.id, 'gl' AS type, $false AS invoice, g.reference, + my $query = qq|SELECT g.id, 'gl' AS type, $false AS invoice, g.reference, g.description, ac.transdate, ac.source, ac.amount, c.accno, c.gifi_accno, g.notes, c.link, '' AS till, ac.cleared, d.description AS department, @@ -442,150 +435,153 @@ sub all_transactions { WHERE $apwhere ORDER BY $sortorder|; - my $sth = $dbh->prepare($query); - $sth->execute || $form->dberror($query); - - while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { - - # gl - if ($ref->{type} eq "gl") { - $ref->{module} = "gl"; - } - - # ap - if ($ref->{type} eq "ap") { - - if ($ref->{invoice}) { - $ref->{module} = "ir"; - } else { - $ref->{module} = "ap"; - } - } - - # ar - if ($ref->{type} eq "ar") { - - if ($ref->{invoice}) { - $ref->{module} = ($ref->{till}) ? "ps" : "is"; - } else { - $ref->{module} = "ar"; - } - } - - if ($ref->{amount} < 0) { - $ref->{debit} = $ref->{amount} * -1; - $ref->{credit} = 0; - } else { - $ref->{credit} = $ref->{amount}; - $ref->{debit} = 0; - } - - push @{ $form->{GL} }, $ref; - } - - $sth->finish; - $dbh->commit; + my $sth = $dbh->prepare($query); + $sth->execute || $form->dberror($query); + + while ( my $ref = $sth->fetchrow_hashref(NAME_lc) ) { + + # gl + if ( $ref->{type} eq "gl" ) { + $ref->{module} = "gl"; + } + + # ap + if ( $ref->{type} eq "ap" ) { + + if ( $ref->{invoice} ) { + $ref->{module} = "ir"; + } + else { + $ref->{module} = "ap"; + } + } + + # ar + if ( $ref->{type} eq "ar" ) { + + if ( $ref->{invoice} ) { + $ref->{module} = ( $ref->{till} ) ? "ps" : "is"; + } + else { + $ref->{module} = "ar"; + } + } + + if ( $ref->{amount} < 0 ) { + $ref->{debit} = $ref->{amount} * -1; + $ref->{credit} = 0; + } + else { + $ref->{credit} = $ref->{amount}; + $ref->{debit} = 0; + } + + push @{ $form->{GL} }, $ref; + } + + $sth->finish; + $dbh->commit; } - sub transaction { - my ($self, $myconfig, $form) = @_; + my ( $self, $myconfig, $form ) = @_; - my ($query, $sth, $ref); + my ( $query, $sth, $ref ); - # connect to database - my $dbh = $form->{dbh}; + # connect to database + my $dbh = $form->{dbh}; - if ($form->{id}) { + if ( $form->{id} ) { - $query = "SELECT setting_key, value + $query = "SELECT setting_key, value FROM defaults WHERE setting_key IN ('closedto', 'revtrans')"; - $sth = $dbh->prepare($query); - $sth->execute || $form->dberror($query); + $sth = $dbh->prepare($query); + $sth->execute || $form->dberror($query); - my $results = $sth->fetchall_hashref('setting_key'); - $form->{closedto} = $results->{'closedto'}->{'value'}; - $form->{revtrans} = $results->{'revtrans'}->{'value'}; - $sth->finish; + my $results = $sth->fetchall_hashref('setting_key'); + $form->{closedto} = $results->{'closedto'}->{'value'}; + $form->{revtrans} = $results->{'revtrans'}->{'value'}; + $sth->finish; - $query = qq|SELECT g.*, d.description AS department + $query = qq|SELECT g.*, d.description AS department FROM gl g LEFT JOIN department d ON (d.id = g.department_id) WHERE g.id = ?|; - $sth = $dbh->prepare($query); - $sth->execute($form->{id}) || $form->dberror($query); + $sth = $dbh->prepare($query); + $sth->execute( $form->{id} ) || $form->dberror($query); - $ref = $sth->fetchrow_hashref(NAME_lc); - for (keys %$ref) { $form->{$_} = $ref->{$_} } - $sth->finish; + $ref = $sth->fetchrow_hashref(NAME_lc); + for ( keys %$ref ) { $form->{$_} = $ref->{$_} } + $sth->finish; - # retrieve individual rows - $query = qq|SELECT ac.*, c.accno, c.description, p.projectnumber + # retrieve individual rows + $query = qq|SELECT ac.*, c.accno, c.description, p.projectnumber FROM acc_trans ac JOIN chart c ON (ac.chart_id = c.id) LEFT JOIN project p ON (p.id = ac.project_id) WHERE ac.trans_id = ? ORDER BY accno|; - $sth = $dbh->prepare($query); - $sth->execute($form->{id}) || $form->dberror($query); + $sth = $dbh->prepare($query); + $sth->execute( $form->{id} ) || $form->dberror($query); - while ($ref = $sth->fetchrow_hashref(NAME_lc)) { + while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) { - if ($ref->{fx_transaction}) { - $form->{transfer} = 1; - } - push @{ $form->{GL} }, $ref; - } + if ( $ref->{fx_transaction} ) { + $form->{transfer} = 1; + } + push @{ $form->{GL} }, $ref; + } - # get recurring transaction - $form->get_recurring($dbh); + # get recurring transaction + $form->get_recurring($dbh); - } else { + } + else { - $query = "SELECT current_date AS transdate, setting_key, value + $query = "SELECT current_date AS transdate, setting_key, value FROM defaults WHERE setting_key IN ('closedto', 'revtrans')"; - - $sth = $dbh->prepare($query); - $sth->execute || $form->dberror($query); - my $results = $sth->fetchall_hashref('setting_key'); - $form->{closedto} = $results->{'closedto'}->{'value'}; - $form->{revtrans} = $results->{'revtrans'}->{'value'}; - $form->{transdate} = $results->{'revtrans'}->{'transdate'}; - } + $sth = $dbh->prepare($query); + $sth->execute || $form->dberror($query); + + my $results = $sth->fetchall_hashref('setting_key'); + $form->{closedto} = $results->{'closedto'}->{'value'}; + $form->{revtrans} = $results->{'revtrans'}->{'value'}; + $form->{transdate} = $results->{'revtrans'}->{'transdate'}; + } - $sth->finish; + $sth->finish; - # get chart of accounts - $query = qq|SELECT accno,description + # get chart of accounts + $query = qq|SELECT accno,description FROM chart WHERE charttype = 'A' ORDER BY accno|; - $sth = $dbh->prepare($query); - $sth->execute || $form->dberror($query); + $sth = $dbh->prepare($query); + $sth->execute || $form->dberror($query); - while ($ref = $sth->fetchrow_hashref(NAME_lc)) { - push @{ $form->{all_accno} }, $ref; - } + while ( $ref = $sth->fetchrow_hashref(NAME_lc) ) { + push @{ $form->{all_accno} }, $ref; + } - $sth->finish; + $sth->finish; - # get departments - $form->all_departments($myconfig, $dbh); + # get departments + $form->all_departments( $myconfig, $dbh ); - # get projects - $form->all_projects($myconfig, $dbh, $form->{transdate}); + # get projects + $form->all_projects( $myconfig, $dbh, $form->{transdate} ); - $dbh->commit; + $dbh->commit; } |