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 216-222 sub makepayment { Link Here
216
215
217
    #check to see what accounttype
216
    #check to see what accounttype
218
    if ( $data->{'accounttype'} eq 'Rep' || $data->{'accounttype'} eq 'L' ) {
217
    if ( $data->{'accounttype'} eq 'Rep' || $data->{'accounttype'} eq 'L' ) {
219
        returnlost( $borrowernumber, $data->{'itemnumber'} );
218
        ReturnLostItem( $borrowernumber, $data->{'itemnumber'} );
220
    }
219
    }
221
}
220
}
222
221
Lines 276-339 EOT Link Here
276
275
277
=cut
276
=cut
278
277
279
sub returnlost{
280
    my ( $borrowernumber, $itemnum ) = @_;
281
    C4::Circulation::MarkIssueReturned( $borrowernumber, $itemnum );
282
    my $borrower = C4::Members::GetMember( 'borrowernumber'=>$borrowernumber );
283
    my @datearr = localtime(time);
284
    my $date = ( 1900 + $datearr[5] ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3];
285
    my $bor = "$borrower->{'firstname'} $borrower->{'surname'} $borrower->{'cardnumber'}";
286
    ModItem({ paidfor =>  "Paid for by $bor $date" }, undef, $itemnum);
287
}
288
289
290
sub chargelostitem{
278
sub chargelostitem{
291
# lost ==1 Lost, lost==2 longoverdue, lost==3 lost and paid for
279
# lost ==1 Lost, lost==2 longoverdue, lost==3 lost and paid for
292
# FIXME: itemlost should be set to 3 after payment is made, should be a warning to the interface that
280
# FIXME: itemlost should be set to 3 after payment is made, should be a warning to the interface that
293
# a charge has been added
281
# a charge has been added
294
# FIXME : if no replacement price, borrower just doesn't get charged?
282
# FIXME : if no replacement price, borrower just doesn't get charged?
295
   
296
    my $dbh = C4::Context->dbh();
283
    my $dbh = C4::Context->dbh();
297
    my ($itemnumber) = @_;
284
    my ($borrowernumber, $itemnumber, $amount, $description) = @_;
298
    my $sth=$dbh->prepare("SELECT issues.*,items.*,biblio.title 
285
299
                           FROM issues 
286
    # first make sure the borrower hasn't already been charged for this item
300
                           JOIN items USING (itemnumber) 
287
    my $sth1=$dbh->prepare("SELECT * from accountlines
301
                           JOIN biblio USING (biblionumber)
288
    WHERE borrowernumber=? AND itemnumber=? and accounttype='L'");
302
                           WHERE issues.itemnumber=?");
289
    $sth1->execute($borrowernumber,$itemnumber);
303
    $sth->execute($itemnumber);
290
    my $existing_charge_hashref=$sth1->fetchrow_hashref();
304
    my $issues=$sth->fetchrow_hashref();
291
305
292
    # OK, they haven't
306
    # if a borrower lost the item, add a replacement cost to the their record
293
    unless ($existing_charge_hashref) {
307
    if ( $issues->{borrowernumber} ){
294
        # This item is on issue ... add replacement cost to the borrower's record and mark it returned
308
295
        #  Note that we add this to the account even if there's no replacement price, allowing some other
309
        # first make sure the borrower hasn't already been charged for this item
296
        #  process (or person) to update it, since we don't handle any defaults for replacement prices.
310
        my $sth1=$dbh->prepare("SELECT * from accountlines
297
        my $accountno = getnextacctno($borrowernumber);
311
        WHERE borrowernumber=? AND itemnumber=? and accounttype='L'");
298
        my $sth2=$dbh->prepare("INSERT INTO accountlines
312
        $sth1->execute($issues->{'borrowernumber'},$itemnumber);
299
        (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber)
313
        my $existing_charge_hashref=$sth1->fetchrow_hashref();
300
        VALUES (?,?,now(),?,?,'L',?,?)");
314
301
        $sth2->execute($borrowernumber,$accountno,$amount,
315
        # OK, they haven't
302
        $description,$amount,$itemnumber);
316
        unless ($existing_charge_hashref) {
303
        $sth2->finish;
317
            # This item is on issue ... add replacement cost to the borrower's record and mark it returned
304
    # FIXME: Log this ?
318
            #  Note that we add this to the account even if there's no replacement price, allowing some other
319
            #  process (or person) to update it, since we don't handle any defaults for replacement prices.
320
            my $accountno = getnextacctno($issues->{'borrowernumber'});
321
            my $sth2=$dbh->prepare("INSERT INTO accountlines
322
            (borrowernumber,accountno,date,amount,description,accounttype,amountoutstanding,itemnumber)
323
            VALUES (?,?,now(),?,?,'L',?,?)");
324
            $sth2->execute($issues->{'borrowernumber'},$accountno,$issues->{'replacementprice'},
325
            "Lost Item $issues->{'title'} $issues->{'barcode'}",
326
            $issues->{'replacementprice'},$itemnumber);
327
            $sth2->finish;
328
        # FIXME: Log this ?
329
        }
330
        #FIXME : Should probably have a way to distinguish this from an item that really was returned.
331
        #warn " $issues->{'borrowernumber'}  /  $itemnumber ";
332
        C4::Circulation::MarkIssueReturned($issues->{borrowernumber},$itemnumber);
333
	#  Shouldn't MarkIssueReturned do this?
334
        C4::Items::ModItem({ onloan => undef }, undef, $itemnumber);
335
    }
305
    }
336
    $sth->finish;
337
}
306
}
338
307
339
=head2 manualinvoice
308
=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 2943-2950 sub DeleteBranchTransferLimits { Link Here
2943
   $sth->execute();
2944
   $sth->execute();
2944
}
2945
}
2945
2946
2947
sub ReturnLostItem{
2948
    my ( $borrowernumber, $itemnum ) = @_;
2946
2949
2947
  1;
2950
    MarkIssueReturned( $borrowernumber, $itemnum );
2951
    my $borrower = C4::Members::GetMember( 'borrowernumber'=>$borrowernumber );
2952
    my @datearr = localtime(time);
2953
    my $date = ( 1900 + $datearr[5] ) . "-" . ( $datearr[4] + 1 ) . "-" . $datearr[3];
2954
    my $bor = "$borrower->{'firstname'} $borrower->{'surname'} $borrower->{'cardnumber'}";
2955
    ModItem({ paidfor =>  "Paid for by $bor $date" }, undef, $itemnum);
2956
}
2957
2958
2959
sub LostItem{
2960
    my ($itemnumber, $mark_returned) = @_;
2961
2962
    my $dbh = C4::Context->dbh();
2963
    my $sth=$dbh->prepare("SELECT issues.*,items.*,biblio.title 
2964
                           FROM issues 
2965
                           JOIN items USING (itemnumber) 
2966
                           JOIN biblio USING (biblionumber)
2967
                           WHERE issues.itemnumber=?");
2968
    $sth->execute($itemnumber);
2969
    my $issues=$sth->fetchrow_hashref();
2970
    $sth->finish;
2971
2972
    # if a borrower lost the item, add a replacement cost to the their record
2973
    if ( my $borrowernumber = $issues->{borrowernumber} ){
2974
2975
        C4::Accounts::chargelostitem($borrowernumber, $itemnumber, $issues->{'replacementprice'}, "Lost Item $issues->{'title'} $issues->{'barcode'}");
2976
        #FIXME : Should probably have a way to distinguish this from an item that really was returned.
2977
        #warn " $issues->{'borrowernumber'}  /  $itemnumber ";
2978
        MarkIssueReturned($borrowernumber,$itemnumber) if $mark_returned;
2979
    }
2980
}
2981
2982
2983
1;
2948
2984
2949
__END__
2985
__END__
2950
2986
(-)a/C4/Items.pm (-1 / +7 lines)
Lines 397-402 Note that only columns that can be directly Link Here
397
changed from the cataloging and serials
397
changed from the cataloging and serials
398
item editors are included in this hash.
398
item editors are included in this hash.
399
399
400
Returns item record
401
400
=cut
402
=cut
401
403
402
my %default_values_for_mod_from_marc = (
404
my %default_values_for_mod_from_marc = (
Lines 446-452 sub ModItemFromMarc { Link Here
446
    }
448
    }
447
    my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode );
449
    my $unlinked_item_subfields = _get_unlinked_item_subfields( $localitemmarc, $frameworkcode );
448
450
449
    return ModItem($item, $biblionumber, $itemnumber, $dbh, $frameworkcode, $unlinked_item_subfields); 
451
    ModItem($item, $biblionumber, $itemnumber, $dbh, $frameworkcode, $unlinked_item_subfields); 
452
    return $item;
450
}
453
}
451
454
452
=head2 ModItem
455
=head2 ModItem
Lines 495-500 sub ModItem { Link Here
495
    };
498
    };
496
499
497
    $item->{'itemnumber'} = $itemnumber or return undef;
500
    $item->{'itemnumber'} = $itemnumber or return undef;
501
502
    $item->{onloan} = undef if $item->{itemlost};
503
498
    _set_derived_columns_for_mod($item);
504
    _set_derived_columns_for_mod($item);
499
    _do_column_fixes_for_mod($item);
505
    _do_column_fixes_for_mod($item);
500
    # FIXME add checks
506
    # 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 200-227 sub generate_subfield_form { Link Here
200
                  }
200
                  }
201
            }
201
            }
202
202
203
            $subfield_data{marc_value} =CGI::scrolling_list(      # FIXME: factor out scrolling_list
203
            if ($subfieldlib->{'hidden'}) {
204
                  -name     => "field_value",
204
                $subfield_data{marc_value} = qq(<input type="hidden" $attributes /> $authorised_lib{$value});
205
                  -values   => \@authorised_values,
205
            }
206
                  -default  => $value,
206
            else {
207
                  -labels   => \%authorised_lib,
207
                $subfield_data{marc_value} =CGI::scrolling_list(      # FIXME: factor out scrolling_list
208
                  -override => 1,
208
                    -name     => "field_value",
209
                  -size     => 1,
209
                    -values   => \@authorised_values,
210
                  -multiple => 0,
210
                    -default  => $value,
211
                  -tabindex => 1,
211
                    -labels   => \%authorised_lib,
212
                  -id       => "tag_".$tag."_subfield_".$subfieldtag."_".$index_subfield,
212
                    -override => 1,
213
                  -class    => "input_marceditor",
213
                    -size     => 1,
214
            );
214
                    -multiple => 0,
215
                    -tabindex => 1,
216
                    -id       => "tag_".$tag."_subfield_".$subfieldtag."_".$index_subfield,
217
                    -class    => "input_marceditor",
218
                );
219
            }
215
220
216
            # it's a thesaurus / authority field
217
        }
221
        }
222
            # it's a thesaurus / authority field
218
        elsif ( $subfieldlib->{authtypecode} ) {
223
        elsif ( $subfieldlib->{authtypecode} ) {
219
                $subfield_data{marc_value} = "<input type=\"text\" $attributes />
224
                $subfield_data{marc_value} = "<input type=\"text\" $attributes />
220
                    <a href=\"#\" class=\"buttonDot\"
225
                    <a href=\"#\" class=\"buttonDot\"
221
                        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>
226
                        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>
222
            ";
227
            ";
223
            # it's a plugin field
224
        }
228
        }
229
            # it's a plugin field
225
        elsif ( $subfieldlib->{value_builder} ) {
230
        elsif ( $subfieldlib->{value_builder} ) {
226
                # opening plugin
231
                # opening plugin
227
                my $plugin = C4::Context->intranetdir . "/cataloguing/value_builder/" . $subfieldlib->{'value_builder'};
232
                my $plugin = C4::Context->intranetdir . "/cataloguing/value_builder/" . $subfieldlib->{'value_builder'};
Lines 484-490 if ($op eq "additem") { Link Here
484
    if ($exist_itemnumber && $exist_itemnumber != $itemnumber) {
489
    if ($exist_itemnumber && $exist_itemnumber != $itemnumber) {
485
        push @errors,"barcode_not_unique";
490
        push @errors,"barcode_not_unique";
486
    } else {
491
    } else {
487
        my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = ModItemFromMarc($itemtosave,$biblionumber,$itemnumber);
492
        ModItemFromMarc($itemtosave,$biblionumber,$itemnumber);
488
        $itemnumber="";
493
        $itemnumber="";
489
    }
494
    }
490
    $nextop="additem";
495
    $nextop="additem";
Lines 590-595 if($itemrecord){ Link Here
590
            next if subfield_is_koha_internal_p($subfieldtag);
595
            next if subfield_is_koha_internal_p($subfieldtag);
591
            next if ($tagslib->{$tag}->{$subfieldtag}->{'tab'} ne "10");
596
            next if ($tagslib->{$tag}->{$subfieldtag}->{'tab'} ne "10");
592
597
598
            $subfieldlib->{hidden} = 1
599
              if $tagslib->{$tag}->{$subfieldtag}->{authorised_value} eq 'LOST';
593
            my $subfield_data = generate_subfield_form($tag, $subfieldtag, $value, $tagslib, $subfieldlib, $branches, $today_iso, $biblionumber, $temp, \@loop_data, $i);        
600
            my $subfield_data = generate_subfield_form($tag, $subfieldtag, $value, $tagslib, $subfieldlib, $branches, $today_iso, $biblionumber, $temp, \@loop_data, $i);        
594
601
595
            push @fields, "$tag$subfieldtag";
602
            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 (-4 / +13 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 140-155 if ($op eq "action") { Link Here
140
			    $deleted_items++;
141
			    $deleted_items++;
141
			} else {
142
			} else {
142
			    $not_deleted_items++;
143
			    $not_deleted_items++;
143
			    push @not_deleted, { biblionumber => $itemdata->{'biblionumber'}, itemnumber => $itemdata->{'itemnumber'}, barcode => $itemdata->{'barcode'}, title => $itemdata->{'title'}, $return => 1 };
144
			    push @not_deleted, {
145
                    biblionumber => $itemdata->{'biblionumber'},
146
                    itemnumber => $itemdata->{'itemnumber'},
147
                    barcode => $itemdata->{'barcode'},
148
                    title => $itemdata->{'title'},
149
                    $return => 1
150
                };
144
			}
151
			}
145
		} else {
152
		} else {
146
		    if ($something_to_modify) {
153
		    if ($something_to_modify) {
147
			my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag, 'ITEM');
154
			my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag, 'ITEM');
148
			my $marcitem = MARC::Record::new_from_xml($xml, 'UTF-8');
155
			my $marcitem = MARC::Record::new_from_xml($xml, 'UTF-8');
149
			my $localitem = TransformMarcToKoha( $dbh, $marcitem, "", 'items' );
150
			my $localmarcitem=Item2Marc($itemdata);
156
			my $localmarcitem=Item2Marc($itemdata);
151
			UpdateMarcWith($marcitem,$localmarcitem);
157
			UpdateMarcWith($marcitem,$localmarcitem);
152
			eval{my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = ModItemFromMarc($localmarcitem,$itemdata->{biblionumber},$itemnumber)};
158
			eval{
159
                if ( my $item = ModItemFromMarc( $localmarcitem, $itemdata->{biblionumber}, $itemnumber ) ) {
160
                    LostItem($itemnumber, 'MARK RETURNED') if $item->{itemlost};
161
                }
162
            };
153
		    }
163
		    }
154
		}
164
		}
155
		$i++;
165
		$i++;
156
- 

Return to bug 5533