Bug 21829: Correctly format dateexpiry in notices (date only)
[koha.git] / C4 / Accounts.pm
index 1baecda..d2c597a 100644 (file)
@@ -97,7 +97,7 @@ FIXME : if no replacement price, borrower just doesn't get charged?
 
 sub chargelostitem{
     my $dbh = C4::Context->dbh();
-    my ($borrowernumber, $itemnumber, $issue_id, $amount, $description) = @_;
+    my ($borrowernumber, $itemnumber, $amount, $description) = @_;
     my $itype = Koha::ItemTypes->find({ itemtype => Koha::Items->find($itemnumber)->effective_itemtype() });
     my $replacementprice = $amount;
     my $defaultreplacecost = $itype->defaultreplacecost;
@@ -107,6 +107,9 @@ sub chargelostitem{
     if ($usedefaultreplacementcost && $amount == 0 && $defaultreplacecost){
         $replacementprice = $defaultreplacecost;
     }
+
+    my $branchcode = C4::Context->userenv ? C4::Context->userenv->{'branch'} : undef;
+
     # first make sure the borrower hasn't already been charged for this item
     # FIXME this should be more exact
     #       there is no reason a user can't lose an item, find and return it, and lost it again
@@ -120,6 +123,8 @@ sub chargelostitem{
 
     # OK, they haven't
     unless ($existing_charges) {
+        my $checkout = Koha::Checkouts->find({ itemnumber => $itemnumber });
+        my $issue_id = $checkout ? $checkout->issue_id : undef;
         #add processing fee
         if ($processfee && $processfee > 0){
             my $accountline = Koha::Account::Line->new(
@@ -135,6 +140,7 @@ sub chargelostitem{
                     itemnumber        => $itemnumber,
                     note              => $processingfeenote,
                     manager_id        => C4::Context->userenv ? C4::Context->userenv->{'number'} : 0,
+                    branchcode        => $branchcode,
                 }
             )->store();
 
@@ -175,6 +181,7 @@ sub chargelostitem{
                     amountoutstanding => $replacementprice,
                     itemnumber        => $itemnumber,
                     manager_id        => C4::Context->userenv ? C4::Context->userenv->{'number'} : 0,
+                    branchcode        => $branchcode,
                 }
             )->store();
 
@@ -239,6 +246,8 @@ sub manualinvoice {
     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,
@@ -251,6 +260,7 @@ sub manualinvoice {
             itemnumber        => $itemnum || undef,
             note              => $note,
             manager_id        => $manager_id,
+            branchcode        => $branchcode,
         }
     )->store();