View | Details | Raw Unified | Return to bug 5533
Collapse All | Expand All

(-)a/C4/Accounts.pm (-54 / +23 lines)
Lines 23-30 use strict; Link Here
23
use C4::Context;
23
use C4::Context;
24
use C4::Stats;
24
use C4::Stats;
25
use C4::Members;
25
use C4::Members;
26
use C4::Items;
26
use C4::Circulation qw(ReturnLostItem);
27
use C4::Circulation qw(MarkIssueReturned);
28
27
29
use vars qw($VERSION @ISA @EXPORT);
28
use vars qw($VERSION @ISA @EXPORT);
30
29
Lines 218-224 sub makepayment { Link Here
218
217
219
    #check to see what accounttype
218
    #check to see what accounttype
220
    if ( $data->{'accounttype'} eq 'Rep' || $data->{'accounttype'} eq 'L' ) {
219
    if ( $data->{'accounttype'} eq 'Rep' || $data->{'accounttype'} eq 'L' ) {
221
        returnlost( $borrowernumber, $data->{'itemnumber'} );
220
        ReturnLostItem( $borrowernumber, $data->{'itemnumber'} );
222
    }
221
    }
223
}
222
}
224
223
Lines 278-341 EOT Link Here
278
277
279
=cut
278
=cut
280
279
281
sub returnlost{
282
    my ( $borrowernumber, $itemnum ) = @_;
283
    C4::Circulation::MarkIssueReturned( $borrowernumber, $itemnum );
284
    my $borrower = C4::Members::GetMember( 'borrowernumber'=>$borrowernumber );
285
    my @datearr = localtime(time);
286
    my $date = ( 1900 + $datearr[5] ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3];
287
    my $bor = "$borrower->{'firstname'} $borrower->{'surname'} $borrower->{'cardnumber'}";
288
    ModItem({ paidfor =>  "Paid for by $bor $date" }, undef, $itemnum);
289
}
290
291
292
sub chargelostitem{
280
sub chargelostitem{
293
# lost ==1 Lost, lost==2 longoverdue, lost==3 lost and paid for
281
# lost ==1 Lost, lost==2 longoverdue, lost==3 lost and paid for
294
# FIXME: itemlost should be set to 3 after payment is made, should be a warning to the interface that
282
# FIXME: itemlost should be set to 3 after payment is made, should be a warning to the interface that
295
# a charge has been added
283
# a charge has been added
296
# FIXME : if no replacement price, borrower just doesn't get charged?
284
# FIXME : if no replacement price, borrower just doesn't get charged?
297
   
298
    my $dbh = C4::Context->dbh();
285
    my $dbh = C4::Context->dbh();
299
    my ($itemnumber) = @_;
286
    my ($borrowernumber, $itemnumber, $amount, $description) = @_;
300
    my $sth=$dbh->prepare("SELECT issues.*,items.*,biblio.title 
287
301
                           FROM issues 
288
    # first make sure the borrower hasn't already been charged for this item
302
                           JOIN items USING (itemnumber) 
289
    my $sth1=$dbh->prepare("SELECT * from accountlines
303
                           JOIN biblio USING (biblionumber)
290
    WHERE borrowernumber=? AND itemnumber=? and accounttype='L'");
304
                           WHERE issues.itemnumber=?");
291
    $sth1->execute($borrowernumber,$itemnumber);
305
    $sth->execute($itemnumber);
292
    my $existing_charge_hashref=$sth1->fetchrow_hashref();
306
    my $issues=$sth->fetchrow_hashref();
293
307
294
    # OK, they haven't
308
    # if a borrower lost the item, add a replacement cost to the their record
295
    unless ($existing_charge_hashref) {
309
    if ( $issues->{borrowernumber} ){
296
        # This item is on issue ... add replacement cost to the borrower's record and mark it returned
310
297
        #  Note that we add this to the account even if there's no replacement price, allowing some other
311
        # first make sure the borrower hasn't already been charged for this item
298
        #  process (or person) to update it, since we don't handle any defaults for replacement prices.
312
        my $sth1=$dbh->prepare("SELECT * from accountlines
299
        my $accountno = getnextacctno($borrowernumber);
313
        WHERE borrowernumber=? AND itemnumber=? and accounttype='L'");
300
        my $sth2=$dbh->prepare("INSERT INTO accountlines
314
        $sth1->execute($issues->{'borrowernumber'},$itemnumber);
301
        (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber)
315
        my $existing_charge_hashref=$sth1->fetchrow_hashref();
302
        VALUES (?,?,now(),?,?,'L',?,?)");
316
303
        $sth2->execute($borrowernumber,$accountno,$amount,
317
        # OK, they haven't
304
        $description,$amount,$itemnumber);
318
        unless ($existing_charge_hashref) {
305
        $sth2->finish;
319
            # This item is on issue ... add replacement cost to the borrower's record and mark it returned
306
    # FIXME: Log this ?
320
            #  Note that we add this to the account even if there's no replacement price, allowing some other
321
            #  process (or person) to update it, since we don't handle any defaults for replacement prices.
322
            my $accountno = getnextacctno($issues->{'borrowernumber'});
323
            my $sth2=$dbh->prepare("INSERT INTO accountlines
324
            (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber)
325
            VALUES (?,?,now(),?,?,'L',?,?)");
326
            $sth2->execute($issues->{'borrowernumber'},$accountno,$issues->{'replacementprice'},
327
            "Lost Item $issues->{'title'} $issues->{'barcode'}",
328
            $issues->{'replacementprice'},$itemnumber);
329
            $sth2->finish;
330
        # FIXME: Log this ?
331
        }
332
        #FIXME : Should probably have a way to distinguish this from an item that really was returned.
333
        #warn " $issues->{'borrowernumber'}  /  $itemnumber ";
334
        C4::Circulation::MarkIssueReturned($issues->{borrowernumber},$itemnumber);
335
	#  Shouldn't MarkIssueReturned do this?
336
        C4::Items::ModItem({ onloan => undef }, undef, $itemnumber);
337
    }
307
    }
338
    $sth->finish;
339
}
308
}
340
309
341
=head2 manualinvoice
310
=head2 manualinvoice
(-)a/C4/Circulation.pm (-2 / +38 lines)
Lines 59-66 BEGIN { Link Here
59
59
60
	# FIXME subs that should probably be elsewhere
60
	# FIXME subs that should probably be elsewhere
61
	push @EXPORT, qw(
61
	push @EXPORT, qw(
62
		&FixOverduesOnReturn
63
		&barcodedecode
62
		&barcodedecode
63
        &LostItem
64
        &ReturnLostItem
64
	);
65
	);
65
66
66
	# subs to deal with issuing a book
67
	# subs to deal with issuing a book
Lines 2949-2956 sub DeleteBranchTransferLimits { Link Here
2949
   $sth->execute();
2950
   $sth->execute();
2950
}
2951
}
2951
2952
2953
sub ReturnLostItem{
2954
    my ( $borrowernumber, $itemnum ) = @_;
2952
2955
2953
  1;
2956
    MarkIssueReturned( $borrowernumber, $itemnum );
2957
    my $borrower = C4::Members::GetMember( 'borrowernumber'=>$borrowernumber );
2958
    my @datearr = localtime(time);
2959
    my $date = ( 1900 + $datearr[5] ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3];
2960
    my $bor = "$borrower->{'firstname'} $borrower->{'surname'} $borrower->{'cardnumber'}";
2961
    ModItem({ paidfor =>  "Paid for by $bor $date" }, undef, $itemnum);
2962
}
2963
2964
2965
sub LostItem{
2966
    my ($itemnumber, $mark_returned) = @_;
2967
2968
    my $dbh = C4::Context->dbh();
2969
    my $sth=$dbh->prepare("SELECT issues.*,items.*,biblio.title 
2970
                           FROM issues 
2971
                           JOIN items USING (itemnumber) 
2972
                           JOIN biblio USING (biblionumber)
2973
                           WHERE issues.itemnumber=?");
2974
    $sth->execute($itemnumber);
2975
    my $issues=$sth->fetchrow_hashref();
2976
    $sth->finish;
2977
2978
    # if a borrower lost the item, add a replacement cost to the their record
2979
    if ( my $borrowernumber = $issues->{borrowernumber} ){
2980
2981
        C4::Accounts::chargelostitem($borrowernumber, $itemnumber, $issues->{'replacementprice'}, "Lost Item $issues->{'title'} $issues->{'barcode'}");
2982
        #FIXME : Should probably have a way to distinguish this from an item that really was returned.
2983
        #warn " $issues->{'borrowernumber'}  /  $itemnumber ";
2984
        MarkIssueReturned($borrowernumber,$itemnumber) if $mark_returned;
2985
    }
2986
}
2987
2988
2989
1;
2954
2990
2955
__END__
2991
__END__
2956
2992
(-)a/C4/Items.pm (-1 / +7 lines)
Lines 401-406 Note that only columns that can be directly Link Here
401
changed from the cataloging and serials
401
changed from the cataloging and serials
402
item editors are included in this hash.
402
item editors are included in this hash.
403
403
404
Returns item record
405
404
=cut
406
=cut
405
407
406
my %default_values_for_mod_from_marc = (
408
my %default_values_for_mod_from_marc = (
Lines 450-456 sub ModItemFromMarc { Link Here
450
    }
452
    }
451
    my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode );
453
    my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode );
452
454
453
    return ModItem($item, $biblionumber, $itemnumber, $dbh, $frameworkcode, $unlinked_item_subfields); 
455
    ModItem($item, $biblionumber, $itemnumber, $dbh, $frameworkcode, $unlinked_item_subfields); 
456
    return $item;
454
}
457
}
455
458
456
=head2 ModItem
459
=head2 ModItem
Lines 499-504 sub ModItem { Link Here
499
    };
502
    };
500
503
501
    $item->{'itemnumber'} = $itemnumber or return undef;
504
    $item->{'itemnumber'} = $itemnumber or return undef;
505
506
    $item->{onloan} = undef if $item->{itemlost};
507
502
    _set_derived_columns_for_mod($item);
508
    _set_derived_columns_for_mod($item);
503
    _do_column_fixes_for_mod($item);
509
    _do_column_fixes_for_mod($item);
504
    # FIXME add checks
510
    # FIXME add checks
(-)a/catalogue/updateitem.pl (-2 / +1 lines)
Lines 26-32 use C4::Biblio; Link Here
26
use C4::Items;
26
use C4::Items;
27
use C4::Output;
27
use C4::Output;
28
use C4::Circulation;
28
use C4::Circulation;
29
use C4::Accounts;
30
use C4::Reserves;
29
use C4::Reserves;
31
30
32
my $cgi= new CGI;
31
my $cgi= new CGI;
Lines 75-80 if (defined $itemnotes) { # i.e., itemnotes parameter passed from form Link Here
75
74
76
ModItem($item_changes, $biblionumber, $itemnumber);
75
ModItem($item_changes, $biblionumber, $itemnumber);
77
76
78
C4::Accounts::chargelostitem($itemnumber) if ($itemlost==1) ;
77
LostItem($itemnumber, 'MARK RETURNED') if $itemlost;
79
78
80
print $cgi->redirect("moredetail.pl?biblionumber=$biblionumber&itemnumber=$itemnumber#item$itemnumber");
79
print $cgi->redirect("moredetail.pl?biblionumber=$biblionumber&itemnumber=$itemnumber#item$itemnumber");
(-)a/cataloguing/additem.pl (-15 / +22 lines)
Lines 206-233 sub generate_subfield_form { Link Here
206
                  }
206
                  }
207
            }
207
            }
208
208
209
            $subfield_data{marc_value} =CGI::scrolling_list(      # FIXME: factor out scrolling_list
209
            if ($subfieldlib->{'hidden'}) {
210
                  -name     => "field_value",
210
                $subfield_data{marc_value} = qq(<input type="hidden" $attributes /> $authorised_lib{$value});
211
                  -values   => \@authorised_values,
211
            }
212
                  -default  => $value,
212
            else {
213
                  -labels   => \%authorised_lib,
213
                $subfield_data{marc_value} =CGI::scrolling_list(      # FIXME: factor out scrolling_list
214
                  -override => 1,
214
                    -name     => "field_value",
215
                  -size     => 1,
215
                    -values   => \@authorised_values,
216
                  -multiple => 0,
216
                    -default  => $value,
217
                  -tabindex => 1,
217
                    -labels   => \%authorised_lib,
218
                  -id       => "tag_".$tag."_subfield_".$subfieldtag."_".$index_subfield,
218
                    -override => 1,
219
                  -class    => "input_marceditor",
219
                    -size     => 1,
220
            );
220
                    -multiple => 0,
221
                    -tabindex => 1,
222
                    -id       => "tag_".$tag."_subfield_".$subfieldtag."_".$index_subfield,
223
                    -class    => "input_marceditor",
224
                );
225
            }
221
226
222
            # it's a thesaurus / authority field
223
        }
227
        }
228
            # it's a thesaurus / authority field
224
        elsif ( $subfieldlib->{authtypecode} ) {
229
        elsif ( $subfieldlib->{authtypecode} ) {
225
                $subfield_data{marc_value} = "<input type=\"text\" $attributes />
230
                $subfield_data{marc_value} = "<input type=\"text\" $attributes />
226
                    <a href=\"#\" class=\"buttonDot\"
231
                    <a href=\"#\" class=\"buttonDot\"
227
                        onclick=\"Dopop('/cgi-bin/koha/authorities/auth_finder.pl?authtypecode=".$subfieldlib->{authtypecode}."&index=$subfield_data{id}','$subfield_data{id}'); return false;\" title=\"Tag Editor\">...</a>
232
                        onclick=\"Dopop('/cgi-bin/koha/authorities/auth_finder.pl?authtypecode=".$subfieldlib->{authtypecode}."&index=$subfield_data{id}','$subfield_data{id}'); return false;\" title=\"Tag Editor\">...</a>
228
            ";
233
            ";
229
            # it's a plugin field
230
        }
234
        }
235
            # it's a plugin field
231
        elsif ( $subfieldlib->{value_builder} ) {
236
        elsif ( $subfieldlib->{value_builder} ) {
232
                # opening plugin
237
                # opening plugin
233
                my $plugin = C4::Context->intranetdir . "/cataloguing/value_builder/" . $subfieldlib->{'value_builder'};
238
                my $plugin = C4::Context->intranetdir . "/cataloguing/value_builder/" . $subfieldlib->{'value_builder'};
Lines 500-506 if ($op eq "additem") { Link Here
500
    if ($exist_itemnumber && $exist_itemnumber != $itemnumber) {
505
    if ($exist_itemnumber && $exist_itemnumber != $itemnumber) {
501
        push @errors,"barcode_not_unique";
506
        push @errors,"barcode_not_unique";
502
    } else {
507
    } else {
503
        my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = ModItemFromMarc($itemtosave,$biblionumber,$itemnumber);
508
        ModItemFromMarc($itemtosave,$biblionumber,$itemnumber);
504
        $itemnumber="";
509
        $itemnumber="";
505
    }
510
    }
506
    $nextop="additem";
511
    $nextop="additem";
Lines 665-670 if($itemrecord){ Link Here
665
            next if subfield_is_koha_internal_p($subfieldtag);
670
            next if subfield_is_koha_internal_p($subfieldtag);
666
            next if ($tagslib->{$tag}->{$subfieldtag}->{'tab'} ne "10");
671
            next if ($tagslib->{$tag}->{$subfieldtag}->{'tab'} ne "10");
667
672
673
            $subfieldlib->{hidden} = 1
674
              if $tagslib->{$tag}->{$subfieldtag}->{authorised_value} eq 'LOST';
668
            my $subfield_data = generate_subfield_form($tag, $subfieldtag, $value, $tagslib, $subfieldlib, $branches, $today_iso, $biblionumber, $temp, \@loop_data, $i);        
675
            my $subfield_data = generate_subfield_form($tag, $subfieldtag, $value, $tagslib, $subfieldlib, $branches, $today_iso, $biblionumber, $temp, \@loop_data, $i);        
669
676
670
            push @fields, "$tag$subfieldtag";
677
            push @fields, "$tag$subfieldtag";
(-)a/misc/cronjobs/longoverdue.pl (-2 / +1 lines)
Lines 35-41 BEGIN { Link Here
35
}
35
}
36
use C4::Context;
36
use C4::Context;
37
use C4::Items;
37
use C4::Items;
38
use C4::Accounts;
39
use Getopt::Long;
38
use Getopt::Long;
40
39
41
my  $lost;  #  key=lost value,  value=num days.
40
my  $lost;  #  key=lost value,  value=num days.
Lines 155-161 foreach my $startrange (sort keys %$lost) { Link Here
155
            printf ("Due %s: item %5s from borrower %5s to lost: %s\n", $row->{date_due}, $row->{itemnumber}, $row->{borrowernumber}, $lostvalue) if($verbose);
154
            printf ("Due %s: item %5s from borrower %5s to lost: %s\n", $row->{date_due}, $row->{itemnumber}, $row->{borrowernumber}, $lostvalue) if($verbose);
156
            if($confirm) {
155
            if($confirm) {
157
                ModItem({ itemlost => $lostvalue }, $row->{'biblionumber'}, $row->{'itemnumber'});
156
                ModItem({ itemlost => $lostvalue }, $row->{'biblionumber'}, $row->{'itemnumber'});
158
                chargelostitem($row->{'itemnumber'}) if( $charge && $charge eq $lostvalue);
157
                LostItem($row->{'itemnumber'}) if( $charge && $charge eq $lostvalue);
159
            }
158
            }
160
            $count++;
159
            $count++;
161
        }
160
        }
(-)a/t/db_dependent/lib/KohaTest/Accounts.pm (-1 lines)
Lines 15-21 sub methods : Test( 1 ) { Link Here
15
    my @methods = qw( recordpayment
15
    my @methods = qw( recordpayment
16
                      makepayment
16
                      makepayment
17
                      getnextacctno
17
                      getnextacctno
18
                      returnlost
19
                      manualinvoice
18
                      manualinvoice
20
                      fixcredit
19
                      fixcredit
21
                      refund
20
                      refund
(-)a/t/db_dependent/lib/KohaTest/Circulation.pm (+1 lines)
Lines 47-52 sub methods : Test( 1 ) { Link Here
47
                      CheckSpecialHolidays
47
                      CheckSpecialHolidays
48
                      CheckRepeatableSpecialHolidays
48
                      CheckRepeatableSpecialHolidays
49
                      CheckValidBarcode
49
                      CheckValidBarcode
50
                      ReturnLostItem
50
                );
51
                );
51
    
52
    
52
    can_ok( $self->testing_class, @methods );    
53
    can_ok( $self->testing_class, @methods );    
(-)a/tools/batchMod.pl (-2 / +6 lines)
Lines 25-30 use C4::Auth; Link Here
25
use C4::Output;
25
use C4::Output;
26
use C4::Biblio;
26
use C4::Biblio;
27
use C4::Items;
27
use C4::Items;
28
use C4::Circulation;
28
use C4::Context;
29
use C4::Context;
29
use C4::Koha; # XXX subfield_is_koha_internal_p
30
use C4::Koha; # XXX subfield_is_koha_internal_p
30
use C4::Branch; # XXX subfield_is_koha_internal_p
31
use C4::Branch; # XXX subfield_is_koha_internal_p
Lines 174-180 if ($op eq "action") { Link Here
174
		    if ($values_to_modify || $values_to_blank) {
175
		    if ($values_to_modify || $values_to_blank) {
175
			my $localmarcitem = Item2Marc($itemdata);
176
			my $localmarcitem = Item2Marc($itemdata);
176
			UpdateMarcWith( $marcitem, $localmarcitem );
177
			UpdateMarcWith( $marcitem, $localmarcitem );
177
			eval{ my ( $oldbiblionumber, $oldbibnum, $oldbibitemnum ) = ModItemFromMarc( $localmarcitem, $itemdata->{biblionumber}, $itemnumber ) };
178
			eval{
179
                if ( my $item = ModItemFromMarc( $localmarcitem, $itemdata->{biblionumber}, $itemnumber ) ) {
180
                    LostItem($itemnumber, 'MARK RETURNED') if $item->{itemlost};
181
                }
182
            };
178
		    }
183
		    }
179
		}
184
		}
180
		$i++;
185
		$i++;
181
- 

Return to bug 5533