require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(
- &getnextacctno
&chargelostitem
&purge_zero_balance_fees
);
=head1 FUNCTIONS
-=head2 getnextacctno
-
- $nextacct = &getnextacctno($borrowernumber);
-
-Returns the next unused account number for the patron with the given
-borrower number.
-
-=cut
-
-#'
-# FIXME - Okay, so what does the above actually _mean_?
-sub getnextacctno {
- my ($borrowernumber) = shift or return;
- my $sth = C4::Context->dbh->prepare(
- "SELECT accountno+1 FROM accountlines
- WHERE (borrowernumber = ?)
- ORDER BY accountno DESC
- LIMIT 1"
- );
- $sth->execute($borrowernumber);
- return ($sth->fetchrow || 1);
-}
-
=head2 chargelostitem
In a default install of Koha the following lost values are set
$manager_id = C4::Context->userenv->{'number'} if C4::Context->userenv;
my $dbh = C4::Context->dbh;
my $insert;
- my $accountno = getnextacctno($borrowernumber);
my $amountleft = $amount;
my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
my $accountline = Koha::Account::Line->new(
{
borrowernumber => $borrowernumber,
- accountno => $accountno,
date => \'NOW()',
amount => $amount,
description => $desc,
logaction("FINES", 'CREATE',$borrowernumber,Dumper({
action => 'create_fee',
borrowernumber => $borrowernumber,
- accountno => $accountno,
amount => $amount,
description => $desc,
accounttype => $type,
accounttype => { -in => [ 'L', 'Rep', 'W' ] },
},
{
- order_by => { -desc => [ 'date', 'accountno' ] }
+ order_by => { -desc => [ 'date' ] }
}
);
amount : the amount of the transaction
other : sipmode
itemtype : the type of the item
- accountno : the count
ccode : the collection code of the item
type key is mandatory.
# 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 accountno ccode location);
+ 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 $other = exists $params->{other} ? $params->{other} : '';
my $itemtype = exists $params->{itemtype} ? $params->{itemtype} : '';
my $location = exists $params->{location} ? $params->{location} : undef;
- my $accountno = exists $params->{accountno} ? $params->{accountno} : '';
my $ccode = exists $params->{ccode} ? $params->{ccode} : '';
my $dbh = C4::Context->dbh;
(datetime,
branch, type, value,
other, itemnumber, itemtype, location,
- borrowernumber, proccode, ccode)
- VALUES (now(),?,?,?,?,?,?,?,?,?,?)"
+ borrowernumber, ccode)
+ VALUES (now(),?,?,?,?,?,?,?,?,?)"
);
$sth->execute(
$branch, $type, $amount, $other,
$itemnumber, $itemtype, $location, $borrowernumber,
- $accountno, $ccode
+ $ccode
);
}
my $patron = Koha::Patrons->find( $self->{patron_id} );
- # We should remove accountno, it is no longer needed
- my $last = $self->lines->search(
- {},
- { order_by => 'accountno' } )->next();
- my $accountno = $last ? $last->accountno + 1 : 1;
-
my $manager_id = $userenv ? $userenv->{number} : 0;
my @fines_paid; # List of account lines paid on with this payment
new_amountoutstanding => 0,
amount_paid => $old_amountoutstanding,
accountlines_id => $fine->id,
- accountno => $fine->accountno,
manager_id => $manager_id,
note => $note,
}
new_amountoutstanding => $fine->amountoutstanding,
amount_paid => $amount_to_pay,
accountlines_id => $fine->id,
- accountno => $fine->accountno,
manager_id => $manager_id,
note => $note,
}
my $payment = Koha::Account::Line->new(
{
borrowernumber => $self->{patron_id},
- accountno => $accountno,
date => dt_from_string(),
amount => 0 - $amount,
description => $description,
type => $type,
amount => $amount,
borrowernumber => $self->{patron_id},
- accountno => $accountno,
}
);
{
action => "create_$type",
borrowernumber => $self->{patron_id},
- accountno => $accountno,
amount => 0 - $amount,
amountoutstanding => 0 - $balance_remaining,
accounttype => $account_type,
$schema->txn_do(
sub {
- # We should remove accountno, it is no longer needed
- my $last = $self->lines->search(
- {},
- { order_by => 'accountno' } )->next();
- my $accountno = $last ? $last->accountno + 1 : 1;
# Insert the account line
$line = Koha::Account::Line->new(
{ borrowernumber => $self->{patron_id},
- accountno => $accountno,
date => \'NOW()',
amount => $amount,
description => $description,
type => $type,
amount => $amount,
borrowernumber => $self->{patron_id},
- accountno => $accountno,
}
) if grep { $type eq $_ } ('payment', 'writeoff') ;
Dumper(
{ action => "create_$type",
borrowernumber => $self->{patron_id},
- accountno => $accountno,
amount => $amount,
description => $description,
amountoutstanding => $amount,
$schema->txn_do(
sub {
- # We should remove accountno, it is no longer needed
- my $last = Koha::Account::Lines->search( { borrowernumber => $self->{patron_id} },
- { order_by => 'accountno' } )->next();
- my $accountno = $last ? $last->accountno + 1 : 1;
# Insert the account line
$line = Koha::Account::Line->new(
Dumper(
{ action => "create_$type",
borrowernumber => $self->{patron_id},
- accountno => $accountno,
amount => $amount,
description => $description,
amountoutstanding => $amount,
our $to_api_mapping = {
accountlines_id => 'account_line_id',
- accountno => undef, # removed
accounttype => 'account_type',
amountoutstanding => 'amount_outstanding',
borrowernumber => 'patron_id',
'description' => $accountline->{'description'},
'amount' => $accountline->{'amount'},
'amountoutstanding' => $accountline->{'amountoutstanding'},
- 'accountno' => $accountline->{'accountno'},
accounttype => $accountline->{accounttype},
'note' => $accountline->{'note'},
);
'amount' => sprintf( "%.2f", $accountline->{'amount'} ),
'amountoutstanding' =>
sprintf( "%.2f", $accountline->{'amountoutstanding'} ),
- 'accountno' => $accountline->{'accountno'},
accounttype => $accountline->{accounttype},
'note' => $accountline->{'note'},
);
$sth4->execute($itemnumber);
my $title = $sth4->fetchrow;
- my $nextaccntno = C4::Accounts::getnextacctno($borrowernumber);
my $desc = "staticfine";
my $query = "INSERT INTO accountlines
- (borrowernumber,itemnumber,date,amount,description,accounttype,amountoutstanding,lastincrement,accountno)
- VALUES (?,?,now(),?,?,'F',?,?,?)";
+ (borrowernumber,itemnumber,date,amount,description,accounttype,amountoutstanding,lastincrement)
+ VALUES (?,?,now(),?,?,'F',?,?)";
my $sth2 = $dbh->prepare($query);
- $bigdebug and warn "query: $query\nw/ args: $borrowernumber, $itemnumber, $amount, $desc, $amount, $amount, $nextaccntno\n";
- $sth2->execute( $borrowernumber, $itemnumber, $amount, $desc, $amount, $amount, $nextaccntno );
+ $bigdebug and warn "query: $query\nw/ args: $borrowernumber, $itemnumber, $amount, $desc, $amount, $amount\n";
+ $sth2->execute( $borrowernumber, $itemnumber, $amount, $desc, $amount, $amount );
}
}
our $dbh = C4::Context->dbh;
$dbh->{AutoCommit} = 0;
my $sth = $dbh->prepare("
-SELECT borrowernumber, itemnumber, accountno, description
+SELECT accountlines_id, description
FROM accountlines
WHERE accounttype in ('FU', 'F', 'O', 'M')
;");
my $update_sth = $dbh->prepare('
UPDATE accountlines
SET description = ?
- WHERE borrowernumber = ? AND itemnumber = ? AND accountno = ?
+ WHERE accountlines_id = ?
;');
}
print "Changing description from '" . $accountline->{'description'} . "' to '" . $description . "'\n" if $DEBUG;
- $update_sth->execute($description, $accountline->{'borrowernumber'}, $accountline->{'itemnumber'}, $accountline->{'accountno'});
+ $update_sth->execute($description, $accountline->{'accountlines_id'});
$done++;
SELECT * FROM accountlines
WHERE ( accounttype = 'FU' OR accounttype = 'F' )
AND description like '%23:59%'
- ORDER BY borrowernumber, itemnumber, accountno, description
+ ORDER BY borrowernumber, itemnumber, accountlines_id, description
";
my $sth = $dbh->prepare($query);
$sth->execute();
}
my $sql =
- "DELETE FROM accountlines WHERE borrowernumber = ? AND accountno = ? AND itemnumber = ? AND date = ? AND description = ? LIMIT 1";
- $dbh->do( $sql, undef, $f->{'borrowernumber'},
- $f->{'accountno'}, $f->{'itemnumber'}, $f->{'date'},
- $f->{'description'} );
+ "DELETE FROM accountlines WHERE accountlines_id = ? LIMIT 1";
+ $dbh->do( $sql, undef, $f->{'accountlines_id'} );
}
if ($has_changed) {
my $sql =
- "UPDATE accountlines SET amountoutstanding = ? WHERE borrowernumber = ? AND accountno = ? AND itemnumber = ? AND date = ? AND description = ? LIMIT 1";
+ "UPDATE accountlines SET amountoutstanding = ? WHERE accountlines_id = ? LIMIT 1";
$dbh->do(
$sql, undef,
- $keeper->{'amountoutstanding'}, $keeper->{'borrowernumber'},
- $keeper->{'accountno'}, $keeper->{'itemnumber'},
- $keeper->{'date'}, $keeper->{'description'}
+ $keeper->{'amountoutstanding'}, $keeper->{'accountlines_id'}
);
}
}
can_ok( 'C4::Accounts',
qw(
- getnextacctno
chargelostitem
manualinvoice
purge_zero_balance_fees )
Koha::Account::Line->new(
{
borrowernumber => $patron->borrowernumber,
- accountno => 1,
date => $today,
description => 'a Res fee',
accounttype => 'Res',
Koha::Account::Line->new(
{
borrowernumber => $patron->borrowernumber,
- accountno => 2,
date => $today,
description => 'a Rental fee',
accounttype => 'Rent',
Koha::Account::Line->new(
{
borrowernumber => $patron->borrowernumber,
- accountno => 3,
date => $today,
description => 'a Manual invoice fee',
accounttype => 'Copie',
source => 'Accountline',
value => {
borrowernumber => $brwr->{borrowernumber},
- accountno => 1,
accounttype => 'xxx',
amountoutstanding => 10
}
use C4::Stats;
use Koha::Database;
-use Test::More tests => 19;
+use Test::More tests => 18;
BEGIN {
use_ok('C4::Stats');
other => "bla",
itemtype => "BK",
location => "LOC",
- accountno => 51,
ccode => "CODE",
};
my $return_error;
other => "bla",
itemtype => "BK",
location => "LOC",
- accountno => 51,
ccode => "CODE",
type => "return"
};
is ($params->{other}, $line->{other}, "UpdateStats save other param in other field of statistics table");
is ($params->{itemtype}, $line->{itemtype}, "UpdateStats save itemtype param in itemtype field of statistics table");
is ($params->{location}, $line->{location}, "UpdateStats save location param in location field of statistics table");
-is ($params->{accountno}, $line->{proccode}, "UpdateStats save accountno param in proccode field of statistics table");
is ($params->{ccode}, $line->{ccode}, "UpdateStats save ccode param in ccode field of statistics table");
$dbh->do(q|DELETE FROM statistics|);
amount => 5.1,
other => "bla",
itemtype => "BK",
- accountno => 51,
ccode => "CODE",
type => "return"
};
other => "bla",
itemtype => "BK",
location => undef,
- accountno => 51,
ccode => "CODE",
type => "return"
};
AuthHeader => {
marcxml => '',
},
- Accountline => {
- accountno => 0,
- },
};
}