|
Lines 40-46
BEGIN {
Link Here
|
| 40 |
&makepayment |
40 |
&makepayment |
| 41 |
&manualinvoice |
41 |
&manualinvoice |
| 42 |
&getnextacctno |
42 |
&getnextacctno |
| 43 |
&reconcileaccount |
|
|
| 44 |
&getcharges |
43 |
&getcharges |
| 45 |
&ModNote |
44 |
&ModNote |
| 46 |
&getcredits |
45 |
&getcredits |
|
Lines 413-428
sub manualinvoice {
Link Here
|
| 413 |
my $accountno = getnextacctno($borrowernumber); |
412 |
my $accountno = getnextacctno($borrowernumber); |
| 414 |
my $amountleft = $amount; |
413 |
my $amountleft = $amount; |
| 415 |
|
414 |
|
| 416 |
# if ( $type eq 'CS' |
|
|
| 417 |
# || $type eq 'CB' |
| 418 |
# || $type eq 'CW' |
| 419 |
# || $type eq 'CF' |
| 420 |
# || $type eq 'CL' ) |
| 421 |
# { |
| 422 |
# my $amount2 = $amount * -1; # FIXME - $amount2 = -$amount |
| 423 |
# $amountleft = |
| 424 |
# fixcredit( $borrowernumber, $amount2, $itemnum, $type, $user ); |
| 425 |
# } |
| 426 |
if ( $type eq 'N' ) { |
415 |
if ( $type eq 'N' ) { |
| 427 |
$desc .= " New Card"; |
416 |
$desc .= " New Card"; |
| 428 |
} |
417 |
} |
|
Lines 440-449
sub manualinvoice {
Link Here
|
| 440 |
|
429 |
|
| 441 |
$desc = " Lost Item"; |
430 |
$desc = " Lost Item"; |
| 442 |
} |
431 |
} |
| 443 |
# if ( $type eq 'REF' ) { |
|
|
| 444 |
# $desc .= " Cash Refund"; |
| 445 |
# $amountleft = refund( '', $borrowernumber, $amount ); |
| 446 |
# } |
| 447 |
if ( ( $type eq 'L' ) |
432 |
if ( ( $type eq 'L' ) |
| 448 |
or ( $type eq 'F' ) |
433 |
or ( $type eq 'F' ) |
| 449 |
or ( $type eq 'A' ) |
434 |
or ( $type eq 'A' ) |
|
Lines 488-656
sub manualinvoice {
Link Here
|
| 488 |
return 0; |
473 |
return 0; |
| 489 |
} |
474 |
} |
| 490 |
|
475 |
|
| 491 |
=head2 fixcredit #### DEPRECATED |
|
|
| 492 |
|
| 493 |
$amountleft = &fixcredit($borrowernumber, $data, $barcode, $type, $user); |
| 494 |
|
| 495 |
This function is only used internally, not exported. |
| 496 |
|
| 497 |
=cut |
| 498 |
|
| 499 |
# This function is deprecated in 3.0 |
| 500 |
|
| 501 |
sub fixcredit { |
| 502 |
|
| 503 |
#here we update both the accountoffsets and the account lines |
| 504 |
my ( $borrowernumber, $data, $barcode, $type, $user ) = @_; |
| 505 |
my $dbh = C4::Context->dbh; |
| 506 |
my $newamtos = 0; |
| 507 |
my $accdata = ""; |
| 508 |
my $amountleft = $data; |
| 509 |
if ( $barcode ne '' ) { |
| 510 |
my $item = GetBiblioFromItemNumber( '', $barcode ); |
| 511 |
my $nextaccntno = getnextacctno($borrowernumber); |
| 512 |
my $query = "SELECT * FROM accountlines WHERE (borrowernumber=? |
| 513 |
AND itemnumber=? AND amountoutstanding > 0)"; |
| 514 |
if ( $type eq 'CL' ) { |
| 515 |
$query .= " AND (accounttype = 'L' OR accounttype = 'Rep')"; |
| 516 |
} |
| 517 |
elsif ( $type eq 'CF' ) { |
| 518 |
$query .= " AND (accounttype = 'F' OR accounttype = 'FU' OR |
| 519 |
accounttype='Res' OR accounttype='Rent')"; |
| 520 |
} |
| 521 |
elsif ( $type eq 'CB' ) { |
| 522 |
$query .= " and accounttype='A'"; |
| 523 |
} |
| 524 |
|
| 525 |
# print $query; |
| 526 |
my $sth = $dbh->prepare($query); |
| 527 |
$sth->execute( $borrowernumber, $item->{'itemnumber'} ); |
| 528 |
$accdata = $sth->fetchrow_hashref; |
| 529 |
if ( $accdata->{'amountoutstanding'} < $amountleft ) { |
| 530 |
$newamtos = 0; |
| 531 |
$amountleft -= $accdata->{'amountoutstanding'}; |
| 532 |
} |
| 533 |
else { |
| 534 |
$newamtos = $accdata->{'amountoutstanding'} - $amountleft; |
| 535 |
$amountleft = 0; |
| 536 |
} |
| 537 |
my $thisacct = $accdata->{accountlines_id}; |
| 538 |
my $usth = $dbh->prepare( |
| 539 |
"UPDATE accountlines SET amountoutstanding= ? |
| 540 |
WHERE (accountlines_id = ?)" |
| 541 |
); |
| 542 |
$usth->execute( $newamtos, $thisacct ); |
| 543 |
$usth = $dbh->prepare( |
| 544 |
"INSERT INTO accountoffsets |
| 545 |
(borrowernumber, accountno, offsetaccount, offsetamount) |
| 546 |
VALUES (?,?,?,?)" |
| 547 |
); |
| 548 |
$usth->execute( $borrowernumber, $accdata->{'accountno'}, |
| 549 |
$nextaccntno, $newamtos ); |
| 550 |
} |
| 551 |
|
| 552 |
# begin transaction |
| 553 |
my $nextaccntno = getnextacctno($borrowernumber); |
| 554 |
|
| 555 |
# get lines with outstanding amounts to offset |
| 556 |
my $sth = $dbh->prepare( |
| 557 |
"SELECT * FROM accountlines |
| 558 |
WHERE (borrowernumber = ?) AND (amountoutstanding >0) |
| 559 |
ORDER BY date" |
| 560 |
); |
| 561 |
$sth->execute($borrowernumber); |
| 562 |
|
| 563 |
# print $query; |
| 564 |
# offset transactions |
| 565 |
while ( ( $accdata = $sth->fetchrow_hashref ) and ( $amountleft > 0 ) ) { |
| 566 |
if ( $accdata->{'amountoutstanding'} < $amountleft ) { |
| 567 |
$newamtos = 0; |
| 568 |
$amountleft -= $accdata->{'amountoutstanding'}; |
| 569 |
} |
| 570 |
else { |
| 571 |
$newamtos = $accdata->{'amountoutstanding'} - $amountleft; |
| 572 |
$amountleft = 0; |
| 573 |
} |
| 574 |
my $thisacct = $accdata->{accountlines_id}; |
| 575 |
my $usth = $dbh->prepare( |
| 576 |
"UPDATE accountlines SET amountoutstanding= ? |
| 577 |
WHERE (accountlines_id = ?)" |
| 578 |
); |
| 579 |
$usth->execute( $newamtos, $thisacct ); |
| 580 |
$usth = $dbh->prepare( |
| 581 |
"INSERT INTO accountoffsets |
| 582 |
(borrowernumber, accountno, offsetaccount, offsetamount) |
| 583 |
VALUE (?,?,?,?)" |
| 584 |
); |
| 585 |
$usth->execute( $borrowernumber, $accdata->{'accountno'}, |
| 586 |
$nextaccntno, $newamtos ); |
| 587 |
} |
| 588 |
$type = "Credit " . $type; |
| 589 |
UpdateStats( $user, $type, $data, $user, '', '', $borrowernumber ); |
| 590 |
$amountleft *= -1; |
| 591 |
return ($amountleft); |
| 592 |
|
| 593 |
} |
| 594 |
|
| 595 |
=head2 refund |
| 596 |
|
| 597 |
#FIXME : DEPRECATED SUB |
| 598 |
This subroutine tracks payments and/or credits against fines/charges |
| 599 |
using the accountoffsets table, which is not used consistently in |
| 600 |
Koha's fines management, and so is not used in 3.0 |
| 601 |
|
| 602 |
=cut |
| 603 |
|
| 604 |
sub refund { |
| 605 |
|
| 606 |
#here we update both the accountoffsets and the account lines |
| 607 |
my ( $borrowernumber, $data ) = @_; |
| 608 |
my $dbh = C4::Context->dbh; |
| 609 |
my $newamtos = 0; |
| 610 |
my $accdata = ""; |
| 611 |
my $amountleft = $data * -1; |
| 612 |
|
| 613 |
# begin transaction |
| 614 |
my $nextaccntno = getnextacctno($borrowernumber); |
| 615 |
|
| 616 |
# get lines with outstanding amounts to offset |
| 617 |
my $sth = $dbh->prepare( |
| 618 |
"SELECT * FROM accountlines |
| 619 |
WHERE (borrowernumber = ?) AND (amountoutstanding<0) |
| 620 |
ORDER BY date" |
| 621 |
); |
| 622 |
$sth->execute($borrowernumber); |
| 623 |
|
| 624 |
# print $amountleft; |
| 625 |
# offset transactions |
| 626 |
while ( ( $accdata = $sth->fetchrow_hashref ) and ( $amountleft < 0 ) ) { |
| 627 |
if ( $accdata->{'amountoutstanding'} > $amountleft ) { |
| 628 |
$newamtos = 0; |
| 629 |
$amountleft -= $accdata->{'amountoutstanding'}; |
| 630 |
} |
| 631 |
else { |
| 632 |
$newamtos = $accdata->{'amountoutstanding'} - $amountleft; |
| 633 |
$amountleft = 0; |
| 634 |
} |
| 635 |
|
| 636 |
# print $amountleft; |
| 637 |
my $thisacct = $accdata->{accountlines_id}; |
| 638 |
my $usth = $dbh->prepare( |
| 639 |
"UPDATE accountlines SET amountoutstanding= ? |
| 640 |
WHERE (accountlines_id = ?)" |
| 641 |
); |
| 642 |
$usth->execute( $newamtos, $thisacct ); |
| 643 |
$usth = $dbh->prepare( |
| 644 |
"INSERT INTO accountoffsets |
| 645 |
(borrowernumber, accountno, offsetaccount, offsetamount) |
| 646 |
VALUES (?,?,?,?)" |
| 647 |
); |
| 648 |
$usth->execute( $borrowernumber, $accdata->{'accountno'}, |
| 649 |
$nextaccntno, $newamtos ); |
| 650 |
} |
| 651 |
return ($amountleft); |
| 652 |
} |
| 653 |
|
| 654 |
sub getcharges { |
476 |
sub getcharges { |
| 655 |
my ( $borrowerno, $timestamp, $accountno ) = @_; |
477 |
my ( $borrowerno, $timestamp, $accountno ) = @_; |
| 656 |
my $dbh = C4::Context->dbh; |
478 |
my $dbh = C4::Context->dbh; |
| 657 |
- |
|
|