13 use Test::More tests => 7;
16 use_ok('C4::Accounts');
19 my $dbh = C4::Context->dbh;
20 $dbh->{AutoCommit} = 0;
21 $dbh->{RaiseError} = 1;
22 $dbh->do(q|DELETE FROM accountlines|);
26 my @branches = keys %{ GetBranches() };
28 $branchcode = $branches[0];
31 ModBranch({ add => 1, branchcode => $branchcode, branchname => 'Branch' });
35 my %item_branch_infos = (
36 homebranch => $branchcode,
37 holdingbranch => $branchcode,
40 my ($biblionumber1) = AddBiblio(MARC::Record->new, '');
41 my $itemnumber1 = AddItem({ barcode => '0101', %item_branch_infos }, $biblionumber1);
42 my $itemnumber2 = AddItem({ barcode => '0102', %item_branch_infos }, $biblionumber1);
44 my ($biblionumber2) = AddBiblio(MARC::Record->new, '');
45 my $itemnumber3 = AddItem({ barcode => '0203', %item_branch_infos }, $biblionumber2);
49 my @categories = C4::Category->all;
51 $categorycode = $categories[0]->{categorycode}
55 "INSERT INTO categories(categorycode) VALUES(?)", undef, $categorycode);
56 $category_created = 1;
59 my $borrowernumber = AddMember(categorycode => $categorycode, branchcode => $branchcode);
60 my $borrower = GetMember(borrowernumber => $borrowernumber);
62 # Need to mock userenv for AddIssue
63 my $module = new Test::MockModule('C4::Context');
64 $module->mock('userenv', sub { { branch => $branchcode } });
65 AddIssue($borrower, '0101');
66 AddIssue($borrower, '0203');
71 $issues = C4::Circulation::GetIssues({biblionumber => $biblionumber1});
72 my $issue=$issues->[0];
73 $issue->{'processfee'} = $processfee;
74 C4::Accounts::chargelostitem($issue, 'test');
76 my @accountline = C4::Accounts::getcharges($borrowernumber);
78 is( scalar(@accountline), 1, 'accountline should have 1 row' );
79 is( int($accountline[0]->{amount}), $processfee, "The accountline amount should be precessfee value " );
80 is( $accountline[0]->{accounttype}, 'PF', "The accountline accounttype should be PF " );
81 is( $accountline[0]->{borrowernumber}, $borrowernumber, "The accountline borrowernumber should be the example borrowernumber" );
82 my $itemnumber = C4::Items::GetItemnumberFromBarcode('0101');
83 is( $accountline[0]->{itemnumber}, $itemnumber, "The accountline itemnumber should the linked with barcode '0101'" );
84 is( $accountline[0]->{description}, 'test ' . $issue->{itemnumber}, "The accountline description should be 'test'" );