Fix for bug 1313, silent failure when entering manual invoice with invalid
authorrangi <rangi>
Sun, 15 Jul 2007 22:19:01 +0000 (22:19 +0000)
committerrangi <rangi>
Sun, 15 Jul 2007 22:19:01 +0000 (22:19 +0000)
itemnumber

C4/Accounts.pm
koha-tmpl/intranet-tmpl/prog/en/members/maninvoice.tmpl
members/maninvoice.pl

index e385443..82262f2 100755 (executable)
@@ -314,8 +314,7 @@ sub manualinvoice{
     my $sth=$dbh->prepare("INSERT INTO  accountlines
                         (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding, itemnumber,notify_id)
         VALUES (?, ?, now(), ?,?, ?,?,?,?)");
-#     $sth->execute($borrowernumber, $accountno, $amount, $desc, $type, $amountleft, $data->{'itemnumber'});
-     $sth->execute($borrowernumber, $accountno, $amount, $desc, $type, $amountleft, $itemnum,$notifyid);
+     $sth->execute($borrowernumber, $accountno, $amount, $desc, $type, $amountleft, $itemnum,$notifyid) || return $sth->errstr;
   } else {
     my $sth=$dbh->prepare("INSERT INTO  accountlines
             (borrowernumber, accountno, date, amount, description, accounttype, amountoutstanding,notify_id)
index 649d49e..c353a45 100644 (file)
@@ -1,11 +1,15 @@
 <!-- TMPL_INCLUDE NAME="doc-head-open.inc" -->
-<title>Koha &rsaquo; Patrons &rsaquo; Create Manual Invoice</title>
+<title>Koha &rsaquo; Borrowers &rsaquo; Create Manual Invoice</title>
 <!-- TMPL_INCLUDE NAME="doc-head-close.inc" -->
 
 <!-- TMPL_INCLUDE NAME="menus.inc" -->
 <!-- TMPL_INCLUDE NAME="menu-members.inc" -->
 
-
+<!-- TMPL_IF NAME="ERROR" -->
+<!-- TMPL_IF NAME="ITEMNUMBER" -->
+  ERROR an invalid itemnumber was entered, please hit back and try again
+<!-- /TMPL_IF -->
+<!-- TMPL_ELSE -->
 <form action="/cgi-bin/koha/members/maninvoice.pl" method="post"><input type="hidden" name="borrowernumber" value="<!-- TMPL_VAR Name="borrowernumber" -->" />
        <table>
        <caption>Manual Invoice</caption>
@@ -27,7 +31,7 @@
 
 <form action="/cgi-bin/koha/members/boraccount.pl" method="get"><input type="hidden" name="borrowernumber" value="<!-- TMPL_VAR Name="borrowernumber" -->" /><input type="submit" value="Cancel" /></form>
 
-
+<!-- /TMPL_IF -->
 
 
 <!-- TMPL_INCLUDE Name="intranet-bottom.inc" -->
index a09f308..00157da 100755 (executable)
@@ -42,8 +42,28 @@ if ($add){
     my $desc=$input->param('desc');
     my $amount=$input->param('amount');
     my $type=$input->param('type');
-    manualinvoice($borrowernumber,$itemnum,$desc,$type,$amount);
-    print $input->redirect("/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
+    my $error=manualinvoice($borrowernumber,$itemnum,$desc,$type,$amount);
+       if ($error){
+               my ($template, $loggedinuser, $cookie)
+                 = get_template_and_user({template_name => "members/maninvoice.tmpl",
+                                       query => $input,
+                                       type => "intranet",
+                                       authnotrequired => 0,
+                                       flagsrequired => {borrowers => 1},
+                                       debug => 1,
+                                       });
+               if ($error =~ /FOREIGN KEY/ && $error =~ /itemnumber/){
+                       $template->param('ITEMNUMBER' => 1);
+               }
+               $template->param('ERROR' => $error);
+               print $input->header(
+                       -type => 'utf-8',
+                       -cookie => $cookie
+               ),$template->output;
+       }
+       else {
+               print $input->redirect("/cgi-bin/koha/members/boraccount.pl?borrowernumber=$borrowernumber");
+       }
 } else {
        my ($template, $loggedinuser, $cookie)
        = get_template_and_user({template_name => "members/maninvoice.tmpl",