Merge remote-tracking branch 'origin/new/bug_7178'
authorPaul Poulain <paul.poulain@biblibre.com>
Mon, 14 May 2012 14:18:46 +0000 (16:18 +0200)
committerPaul Poulain <paul.poulain@biblibre.com>
Mon, 14 May 2012 14:18:46 +0000 (16:18 +0200)
C4/Items.pm
acqui/check_uniqueness.pl
acqui/neworderempty.pl
koha-tmpl/intranet-tmpl/prog/en/js/additem.js
koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt

index 52423a2..65a2bcc 100644 (file)
@@ -81,6 +81,7 @@ BEGIN {
        GetAnalyticsCount
         GetItemHolds
 
+        SearchItems
 
         PrepareItemrecordDisplay
 
@@ -2517,6 +2518,43 @@ sub GetItemHolds {
     $holds = $sth->fetchrow;
     return $holds;
 }
+
+# Return the list of the column names of items table
+sub _get_items_columns {
+    my $dbh = C4::Context->dbh;
+    my $sth = $dbh->column_info(undef, undef, 'items', '%');
+    $sth->execute;
+    my $results = $sth->fetchall_hashref('COLUMN_NAME');
+    return keys %$results;
+}
+
+=head2 SearchItems
+
+    my $items = SearchItems($field, $value);
+
+SearchItems will search for items on a specific given field.
+For instance you can search all items with a specific stocknumber like this:
+
+    my $items = SearchItems('stocknumber', $stocknumber);
+
+=cut
+
+sub SearchItems {
+    my ($field, $value) = @_;
+
+    my $dbh = C4::Context->dbh;
+    my @columns = _get_items_columns;
+    my $results = [];
+    if(0 < grep /^$field$/, @columns) {
+        my $query = "SELECT $field FROM items WHERE $field = ?";
+        my $sth = $dbh->prepare( $query );
+        $sth->execute( $value );
+        $results = $sth->fetchall_arrayref({});
+    }
+    return $results;
+}
+
+
 =head1  OTHER FUNCTIONS
 
 =head2 _find_value
index 95b1992..6260048 100755 (executable)
@@ -33,36 +33,21 @@ use Modern::Perl;
 
 use CGI;
 use JSON;
-use C4::Context;
 use C4::Output;
-use C4::Auth;
+use C4::Items;
 
 my $input = new CGI;
 my @field = $input->param('field');
 my @value = $input->param('value');
 
-my $dbh = C4::Context->dbh;
-
-my $query = "SHOW COLUMNS FROM items";
-my $sth = $dbh->prepare($query);
-$sth->execute;
-my $results = $sth->fetchall_hashref('Field');
-my @columns = keys %$results;
-
 my $r = {};
-my $index = 0;
-for my $f ( @field ) {
-    if(0 < grep /^$f$/, @columns) {
-        $query = "SELECT $f FROM items WHERE $f = ?";
-        $sth = $dbh->prepare( $query );
-        $sth->execute( $value[$index] );
-        my @values = $sth->fetchrow_array;
+my $i = 0;
+for ( my $i=0; $i<@field; $i++ ) {
+    my $items = C4::Items::SearchItems($field[$i], $value[$i]);
 
-        if ( @values ) {
-            push @{ $r->{$f} }, $values[0];
-        }
+    if ( @$items ) {
+        push @{ $r->{$field[$i]} }, $value[$i];
     }
-    $index++;
 }
 
 output_with_http_headers $input, undef, to_json($r), 'json';
index 7dc7cb5..c99863a 100755 (executable)
@@ -380,7 +380,7 @@ $template->param(
     listprice        => sprintf("%.2f", $data->{'listprice'}||$data->{'price'}||$listprice),
     total            => sprintf("%.2f", ($data->{'ecost'}||0)*($data->{'quantity'}||0) ),
     ecost            => $data->{'ecost'},
-    unitprice        => sprintf("%.2f", $data->{'unitprice'}),
+    unitprice        => sprintf("%.2f", $data->{'unitprice'}||0),
     notes            => $data->{'notes'},
     publishercode    => $data->{'publishercode'},
     barcode_subfield => $barcode_subfield,
index 859fe02..2d72de7 100644 (file)
@@ -13,7 +13,7 @@ function addItem( node, unique_item_fields ) {
                 cloneItemBlock(index, unique_item_fields);
             addItemInList(index, unique_item_fields);
             $("#" + index).find("a[name='buttonPlus']").text("Update");
-            $("#quantity").val(current_qty + 1);
+            $("#quantity").val(current_qty + 1).change();
         } else if ( current_qty >= max_qty ) {
             alert(window.MSG_ADDITEM_JS_CANT_RECEIVE_MORE_ITEMS
                 || "You can't receive any more items.");
@@ -87,7 +87,7 @@ function deleteItemBlock(node_a, index, unique_item_fields) {
     } else {
         max_qty = 99999;
     }
-    $("#quantity").val(current_qty - 1);
+    $("#quantity").val(current_qty - 1).change();
     $(node_a).parents('tr').remove();
     if(current_qty - 1 == 0)
         $("#items_list").hide();
index 8aec465..4cd6b49 100644 (file)
@@ -104,6 +104,11 @@ $(document).ready(function()
         [% IF (AcqCreateItemOrdering) %]
             cloneItemBlock(0, '[% UniqueItemFields %]');
         [% END %]
+
+        $("#quantity").change(function() {
+            calcNeworderTotal();
+        });
+
         //We apply the fonction only for modify option
         [% IF ( quantityrec ) %]
         $('#quantity').blur(function() 
@@ -376,9 +381,9 @@ $(document).ready(function()
                 [% ELSE %]
                     <label class="required" for="quantity">Quantity: </label>
                     [% IF (AcqCreateItemOrdering) %]
-                        <input type="text" readonly="readonly" size="20" id="quantity" name="quantity" value="0" onchange="updateCosts();" />
+                        <input type="text" readonly="readonly" size="20" id="quantity" name="quantity" value="0" />
                     [% ELSE %]
-                        <input type="text" size="20" id="quantity" name="quantity" value="[% quantityrec %]" onchange="calcNeworderTotal();" />
+                        <input type="text" size="20" id="quantity" name="quantity" value="[% quantityrec %]" />
                     [% END %]
                 [% END %]
                 <!-- origquantityrec only here for javascript compatibility (additem.js needs it, useless here, usefull when receiveing an order -->