+ 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);
+ my @allowed_circulation_types = qw (renew issue localuse return onsite_checkout);
+ 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");
+ }
+ if (grep ($_ eq $params->{type}, @allowed_circulation_types )) {
+ @mandatory_keys = @circulation_mandatory_keys;
+ } elsif (grep ($_ eq $params->{type}, @allowed_accounts_types )) {
+ @mandatory_keys = @accounts_mandatory_keys;
+ } else {
+ croak ("UpdateStats received forbidden type param: ".$params->{type});
+ }
+ my @missing_params = ();
+ for my $mykey (@mandatory_keys ) {
+ push @missing_params, $mykey if !grep (/^$mykey/, keys %$params);
+ }
+ if (scalar @missing_params > 0 ) {
+ croak ("UpdateStats did not received mandatory param(s): ".join (", ",@missing_params ));
+ }
+ my @invalid_params = ();
+ for my $myparam (keys %$params ) {
+ push @invalid_params, $myparam unless grep (/^$myparam$/, @allowed_keys);
+ }
+ if (scalar @invalid_params > 0 ) {
+ croak ("UpdateStats received invalid param(s): ".join (", ",@invalid_params ));
+ }
+# get the parameters
+ my $branch = $params->{branch};
+ my $type = $params->{type};
+ my $borrowernumber = exists $params->{borrowernumber} ? $params->{borrowernumber} : '';
+ my $itemnumber = exists $params->{itemnumber} ? $params->{itemnumber} : undef;
+ my $amount = exists $params->{amount} ? $params->{amount} : 0;
+ my $other = exists $params->{other} ? $params->{other} : '';
+ my $itemtype = exists $params->{itemtype} ? $params->{itemtype} : '';
+ my $location = exists $params->{location} ? $params->{location} : undef;
+ my $ccode = exists $params->{ccode} ? $params->{ccode} : '';