-
- #module to insert stats data into stats table
- my (
- $env, $branch, $type,
- $amount, $other, $itemnum,
- $itemtype, $borrowernumber, $accountno
- )
- = @_;
- my $dbh = C4::Context->dbh;
- if ( $branch eq '' ) {
- $branch = $env->{'branchcode'};
- }
- my $user = $env->{'usercode'};
- my $organisation = $env->{'organisation'};
-
- # FIXME - Use $dbh->do() instead
- my $sth = $dbh->prepare(
- "Insert into statistics (datetime,branch,type,usercode,value,
- other,itemnumber,itemtype,borrowernumber,proccode,associatedborrower) values (now(),?,?,?,?,?,?,?,?,?,?)"
- );
- $sth->execute(
- $branch, $type, $user, $amount,
- $other, $itemnum, $itemtype, $borrowernumber,
- $accountno, $organisation
- );
- $sth->finish;
-}
-
-# Otherwise, it'd need a POD.
-sub TotalPaid {
- my ( $time, $time2, $spreadsheet ) = @_;
- $time2 = $time unless $time2;
- my $dbh = C4::Context->dbh;
- my $query = "SELECT * FROM statistics,borrowers
- WHERE statistics.borrowernumber= borrowers.borrowernumber
- AND (statistics.type='payment' OR statistics.type='writeoff') ";
- if ( $time eq 'today' ) {
- $query = $query . " AND datetime = now()";
- }
- else {
- $query .= " AND datetime > '$time'";
- }
- if ( $time2 ne '' ) {
- $query .= " AND datetime < '$time2'";
- }
- if ($spreadsheet) {
- $query .= " ORDER BY branch, type";
- }
- my $sth = $dbh->prepare($query);
- $sth->execute();
- my @results;
- while ( my $data = $sth->fetchrow_hashref ) {
- push @results, $data;
- }
- $sth->finish;
- return (@results);
-}
-
-# Otherwise, it needs a POD.
-sub getcharges {
- my ( $borrowerno, $timestamp, $accountno ) = @_;
- my $dbh = C4::Context->dbh;
- my $timestamp2 = $timestamp - 1;
- my $query = "";
- my $sth;
-
- # getcharges is now taking accountno. as an argument
- if ($accountno) {
- $sth = $dbh->prepare(
- "Select * from accountlines where borrowernumber=?
- and accountno = ?"
- );
- $sth->execute( $borrowerno, $accountno );
-
- # this bit left in for old 2 arg usage of getcharges
+ my ($params) = @_;
+# make some controls
+ return () if ! defined $params;
+# change these arrays if new types of transaction or new parameters are allowed
+ my @allowed_keys = qw (type branch amount other itemnumber itemtype borrowernumber ccode location categorycode);
+ my @allowed_circulation_types = qw (renew issue localuse return onsite_checkout recall);
+ my @allowed_accounts_types = qw (writeoff payment);
+ my @circulation_mandatory_keys = qw (type branch borrowernumber itemnumber ccode itemtype);
+ my @accounts_mandatory_keys = qw (type branch borrowernumber amount);
+
+ my @mandatory_keys = ();
+ if (! exists $params->{type} or ! defined $params->{type}) {
+ croak ("UpdateStats did not received type param");