summaryrefslogtreecommitdiff
path: root/LedgerSMB/RC.pm
diff options
context:
space:
mode:
authoreinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2006-10-03 03:26:37 +0000
committereinhverfr <einhverfr@4979c152-3d1c-0410-bac9-87ea11338e46>2006-10-03 03:26:37 +0000
commitfcd5ee36c7b5f42d557ca7b0ec8be997c0faaadb (patch)
treec8608b6f4d98caee857932190939f5e115f4adce /LedgerSMB/RC.pm
parentf98990bd9964b6bfe2fa8526f36a9b7bc2f961f7 (diff)
Merged SL-POS.
git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@185 4979c152-3d1c-0410-bac9-87ea11338e46
Diffstat (limited to 'LedgerSMB/RC.pm')
-rwxr-xr-xLedgerSMB/RC.pm80
1 files changed, 79 insertions, 1 deletions
diff --git a/LedgerSMB/RC.pm b/LedgerSMB/RC.pm
index e1c3a144..47a8a4c4 100755
--- a/LedgerSMB/RC.pm
+++ b/LedgerSMB/RC.pm
@@ -33,12 +33,90 @@
package RC;
+
+sub getposlines{
+ my ($self, $myconfig, $form) = @_;
+ %pos_config = %{$form->{pos_config}};
+ %pos_sources = %{$form->{pos_sources}};
+ my $sources = '';
+ foreach $key (keys %pos_sources){
+ $sources .= ", '$key'";
+ }
+ $sources =~ s/^,\s*//;
+ my $dbh = $form->{dbh};
+
+ # Considering the query below to be safe since all variables are from config
+ # files rather than user input.
+ my $query = qq|
+ SELECT sum(amount) AS amount, source FROM acc_trans
+ WHERE chart_id =
+ (SELECT id FROM chart WHERE accno = '$pos_config{till_accno}')
+ AND transdate = date 'NOW'
+ AND cleared IS NOT TRUE
+ GROUP BY source
+ |;
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+ while (my $ref = $sth->fetchrow_hashref(NAME_lc)) {
+ push @{$form->{TB}}, $ref;
+ }
+ $sth->finish;
+ my $query = qq|
+ SELECT sum(amount) AS sum FROM acc_trans
+ WHERE chart_id =
+ (SELECT id FROM chart WHERE accno = '$pos_config{till_accno}')
+ AND transdate = date 'NOW'
+ AND cleared IS NOT TRUE
+ |;
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+ my $ref = $sth->fetchrow_hashref(NAME_lc);
+ $form->{sum} = $ref->{sum};
+ $sth->finish;
+}
+
+sub clear_till {
+ my ($self, $myconfig, $form) = @_;
+ %pos_config = %{$form->{pos_config}};
+ %pos_sources = %{$form->{pos_sources}};
+ my $sources = '';
+ foreach $key (keys %pos_sources){
+ $sources .= ", '$key'";
+ }
+ $sources =~ s/^,\s//;
+ my $dbh = $form->{dbh};
+ my $query = qq|
+ UPDATE acc_trans
+ SET cleared = TRUE
+ WHERE chart_id =
+ (SELECT id FROM chart WHERE accno = '$pos_config{till_accno}')
+ AND transdate = date 'NOW'
+ |;
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+}
+
+sub getbalance{
+ my ($self, $myconfig, $form) = @_;
+ my $dbh = $form->{dbh};
+
+ my $query = qq|SELECT sum(amount) AS balance
+ FROM acc_trans
+ WHERE chart_id =
+ (SELECT id FROM chart WHERE accno = '$form->{accno}')|;
+
+ my $sth = $dbh->prepare($query);
+ $sth->execute || $form->dberror($query);
+ my $ref = $sth->fetchrow_hashref(NAME_lc);
+ $form->{balance} = $ref->{balance};
+}
+
sub paymentaccounts {
my ($self, $myconfig, $form) = @_;
# connect to database
- my $dbh = $form->dbconnect($myconfig);
+ my $dbh = $form->{dbh};
my $query = qq|SELECT accno, description
FROM chart