Lines 26-35
use CGI;
Link Here
|
26 |
use C4::Auth; |
26 |
use C4::Auth; |
27 |
use C4::Output; |
27 |
use C4::Output; |
28 |
use C4::Context; |
28 |
use C4::Context; |
|
|
29 |
use C4::Dates; |
29 |
use C4::Acquisition; |
30 |
use C4::Acquisition; |
30 |
use C4::Biblio; |
31 |
use C4::Biblio; |
31 |
use C4::Items; |
32 |
use C4::Items; |
32 |
use C4::Search; |
|
|
33 |
use List::MoreUtils qw/any/; |
33 |
use List::MoreUtils qw/any/; |
34 |
|
34 |
|
35 |
my $input=new CGI; |
35 |
my $input=new CGI; |
Lines 42-117
my $ordernumber=$input->param('ordernumber');
Link Here
|
42 |
my $origquantityrec=$input->param('origquantityrec'); |
42 |
my $origquantityrec=$input->param('origquantityrec'); |
43 |
my $quantityrec=$input->param('quantityrec'); |
43 |
my $quantityrec=$input->param('quantityrec'); |
44 |
my $quantity=$input->param('quantity'); |
44 |
my $quantity=$input->param('quantity'); |
45 |
my $unitprice=$input->param('cost'); |
|
|
46 |
my $invoiceno=$input->param('invoice'); |
45 |
my $invoiceno=$input->param('invoice'); |
47 |
my $datereceived=$input->param('datereceived'); |
46 |
my $datereceived=$input->param('datereceived') || C4::Dates->output('iso'); |
48 |
my $replacement=$input->param('rrp'); |
|
|
49 |
my $gst=$input->param('gst'); |
47 |
my $gst=$input->param('gst'); |
50 |
my $freight=$input->param('freight'); |
48 |
my $freight=$input->param('freight'); |
51 |
my $supplierid = $input->param('supplierid'); |
49 |
my $supplierid = $input->param('supplierid'); |
52 |
my $cnt=0; |
50 |
my $cnt=0; |
53 |
my $error_url_str; |
51 |
my $error_url_str = ''; |
54 |
my $ecost = $input->param('ecost'); |
|
|
55 |
my $note = $input->param("note"); |
56 |
|
52 |
|
57 |
my %tplorder = ( 'quantity' => $input->param('quantity') || '', |
|
|
58 |
'quantityreceived' => $input->param('quantityrec') || '', |
59 |
'notes' => $input->param("note") || '', |
60 |
'rrp' => $input->param('rrp') || '', |
61 |
'ecost' => $input->param('ecost') || '', |
62 |
'unitprice' => $input->param('cost') || '', |
63 |
); |
64 |
my $order = GetOrder($ordernumber); |
53 |
my $order = GetOrder($ordernumber); |
65 |
if ( any { $order->{$_} ne $tplorder{$_} } qw(quantity quantityreceived notes rrp ecost unitprice) ) { |
54 |
$order->{booksellerinvoicenumber} = $invoiceno; |
66 |
$order->{quantity} = $tplorder{quantity} if $tplorder{quantity}; |
55 |
$order->{datereceived} = $datereceived; |
67 |
$order->{quantityreceived} = $tplorder{quantityreceived} if $tplorder{quantityreceived}; |
56 |
$order->{freight} = $freight; |
68 |
$order->{notes} = $tplorder{notes} if $tplorder{notes}; |
57 |
$order->{quantity} = $quantity; |
69 |
$order->{rrp} = $tplorder{rrp} if $tplorder{rrp}; |
58 |
$order->{quantityreceived} = $quantityrec; |
70 |
$order->{ecost} = $tplorder{ecost} if $tplorder{ecost}; |
59 |
$order->{notes} = $input->param("note"); |
71 |
$order->{unitprice} = $tplorder{unitprice} if $tplorder{unitprice}; |
60 |
$order->{rrp} = $input->param('rrp'); |
72 |
ModOrder($order); |
61 |
$order->{ecost} = $input->param('ecost'); |
73 |
} |
62 |
$order->{unitprice} = $input->param('cost'); |
|
|
63 |
ModOrder($order); |
74 |
|
64 |
|
75 |
#need old recievedate if we update the order, parcel.pl only shows the right parcel this way FIXME |
65 |
#need old recievedate if we update the order, parcel.pl only shows the right parcel this way FIXME |
76 |
if ($quantityrec > $origquantityrec ) { |
66 |
|
77 |
# now, add items if applicable |
67 |
# now, add or update items if applicable |
78 |
if (C4::Context->preference('AcqCreateItem') eq 'receiving') { |
68 |
my @tags = $input->param('tag'); |
79 |
my @tags = $input->param('tag'); |
69 |
my @subfields = $input->param('subfield'); |
80 |
my @subfields = $input->param('subfield'); |
70 |
my @field_values = $input->param('field_value'); |
81 |
my @field_values = $input->param('field_value'); |
71 |
my @serials = $input->param('serial'); |
82 |
my @serials = $input->param('serial'); |
72 |
my @itemid = $input->param('itemid'); |
83 |
my @itemid = $input->param('itemid'); |
73 |
my @ind_tag = $input->param('ind_tag'); |
84 |
my @ind_tag = $input->param('ind_tag'); |
74 |
my @indicator = $input->param('indicator'); |
85 |
my @indicator = $input->param('indicator'); |
75 |
#Rebuilding ALL the data for items into a hash |
86 |
#Rebuilding ALL the data for items into a hash |
76 |
# parting them on $itemid. |
87 |
# parting them on $itemid. |
77 |
my %itemhash; |
88 |
my %itemhash; |
78 |
my $countdistinct; |
89 |
my $countdistinct; |
79 |
my $range=scalar(@itemid); |
90 |
my $range=scalar(@itemid); |
80 |
for (my $i=0; $i<$range; $i++){ |
91 |
for (my $i=0; $i<$range; $i++){ |
81 |
unless ($itemhash{$itemid[$i]}){ |
92 |
unless ($itemhash{$itemid[$i]}){ |
82 |
$countdistinct++; |
93 |
$countdistinct++; |
83 |
} |
94 |
} |
84 |
push @{$itemhash{$itemid[$i]}->{'tags'}},$tags[$i]; |
95 |
push @{$itemhash{$itemid[$i]}->{'tags'}},$tags[$i]; |
85 |
push @{$itemhash{$itemid[$i]}->{'subfields'}},$subfields[$i]; |
96 |
push @{$itemhash{$itemid[$i]}->{'subfields'}},$subfields[$i]; |
86 |
push @{$itemhash{$itemid[$i]}->{'field_values'}},$field_values[$i]; |
97 |
push @{$itemhash{$itemid[$i]}->{'field_values'}},$field_values[$i]; |
87 |
push @{$itemhash{$itemid[$i]}->{'ind_tag'}},$ind_tag[$i]; |
98 |
push @{$itemhash{$itemid[$i]}->{'ind_tag'}},$ind_tag[$i]; |
88 |
push @{$itemhash{$itemid[$i]}->{'indicator'}},$indicator[$i]; |
99 |
push @{$itemhash{$itemid[$i]}->{'indicator'}},$indicator[$i]; |
89 |
} |
100 |
} |
90 |
my $error; |
101 |
foreach my $item (keys %itemhash){ |
91 |
my %itemnumbers = map { $_ => 1 } GetItemnumbersFromOrder($ordernumber); |
102 |
my $xml = TransformHtmlToXml( $itemhash{$item}->{'tags'}, |
92 |
my @received; |
103 |
$itemhash{$item}->{'subfields'}, |
93 |
foreach my $id (keys %itemhash){ |
104 |
$itemhash{$item}->{'field_values'}, |
94 |
my $xml = TransformHtmlToXml( $itemhash{$id}->{'tags'}, |
105 |
$itemhash{$item}->{'ind_tag'}, |
95 |
$itemhash{$id}->{'subfields'}, |
106 |
$itemhash{$item}->{'indicator'},'ITEM'); |
96 |
$itemhash{$id}->{'field_values'}, |
107 |
my $record=MARC::Record::new_from_xml($xml, 'UTF-8'); |
97 |
$itemhash{$id}->{'ind_tag'}, |
108 |
my ($biblionumber,$bibitemnum,$itemnumber) = AddItemFromMarc($record,$biblionumber); |
98 |
$itemhash{$id}->{'indicator'},'ITEM'); |
109 |
} |
99 |
my $record=MARC::Record::new_from_xml($xml, 'UTF-8'); |
|
|
100 |
my $item = AddItemFromMarc($record,$biblionumber); |
101 |
my $itemnumber = $item ? $item->{itemnumber} : undef; |
102 |
if ($itemnumber) { |
103 |
push @received, $itemnumber; |
104 |
NewOrderItem($itemnumber, $ordernumber) unless $itemnumbers{$itemnumber}; |
105 |
} else { |
106 |
$error++; |
110 |
} |
107 |
} |
111 |
|
108 |
} |
|
|
109 |
|
110 |
if ($error) { |
111 |
$error_url_str = "&error=Datbase+write+error"; |
112 |
} |
113 |
elsif ($quantityrec != $origquantityrec ) { |
112 |
# save the quantity received. |
114 |
# save the quantity received. |
113 |
if( $quantityrec > 0 ) { |
115 |
ModReceiveOrder($biblionumber,$ordernumber, $quantityrec, \@received); |
114 |
$datereceived = ModReceiveOrder($biblionumber,$ordernumber, $quantityrec ,$user,$unitprice,$invoiceno,$freight,$replacement,undef,$datereceived); |
|
|
115 |
} |
116 |
} |
116 |
} |
117 |
print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoice=$invoiceno&supplierid=$supplierid&freight=$freight&gst=$gst&datereceived=$datereceived$error_url_str"); |
117 |
|
|
|
118 |
print $input->redirect("/cgi-bin/koha/acqui/parcel.pl?invoice=$invoiceno&supplierid=$supplierid&freight=$freight&gst=$gst&datereceived=$datereceived$error_url_str"); |