|
Lines 97-102
if ($op eq "additem") {
Link Here
|
| 97 |
my @indicator = $input->param('indicator'); |
97 |
my @indicator = $input->param('indicator'); |
| 98 |
my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag, 'ITEM'); |
98 |
my $xml = TransformHtmlToXml(\@tags,\@subfields,\@values,\@indicator,\@ind_tag, 'ITEM'); |
| 99 |
my $record = MARC::Record::new_from_xml($xml, 'UTF-8'); |
99 |
my $record = MARC::Record::new_from_xml($xml, 'UTF-8'); |
|
|
100 |
|
| 101 |
# type of add |
| 102 |
my $add_submit = $input->param('add_submit'); |
| 103 |
my $add_duplicate_submit = $input->param('add_duplicate_submit'); |
| 104 |
my $add_multiple_copies_submit = $input->param('add_multiple_copies_submit'); |
| 105 |
my $number_of_copies = $input->param('number_of_copies'); |
| 106 |
|
| 100 |
# if autoBarcode is set to 'incremental', calculate barcode... |
107 |
# if autoBarcode is set to 'incremental', calculate barcode... |
| 101 |
# NOTE: This code is subject to change in 3.2 with the implemenation of ajax based autobarcode code |
108 |
# NOTE: This code is subject to change in 3.2 with the implemenation of ajax based autobarcode code |
| 102 |
# NOTE: 'incremental' is the ONLY autoBarcode option available to those not using javascript |
109 |
# NOTE: 'incremental' is the ONLY autoBarcode option available to those not using javascript |
|
Lines 114-129
if ($op eq "additem") {
Link Here
|
| 114 |
$record->insert_fields_ordered($fieldItem); |
121 |
$record->insert_fields_ordered($fieldItem); |
| 115 |
} |
122 |
} |
| 116 |
} |
123 |
} |
| 117 |
# check for item barcode # being unique |
124 |
|
| 118 |
my $addedolditem = TransformMarcToKoha($dbh,$record); |
125 |
my $addedolditem = TransformMarcToKoha($dbh,$record); |
| 119 |
my $exist_itemnumber = get_item_from_barcode($addedolditem->{'barcode'}); |
126 |
|
| 120 |
push @errors,"barcode_not_unique" if($exist_itemnumber); |
127 |
# If we have to add or add & duplicate, we add the item |
| 121 |
# if barcode exists, don't create, but report The problem. |
128 |
if ($add_submit || $add_duplicate_submit) { |
| 122 |
my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItemFromMarc($record,$biblionumber) unless ($exist_itemnumber); |
129 |
# check for item barcode # being unique |
| 123 |
$nextop = "additem"; |
130 |
my $exist_itemnumber = get_item_from_barcode($addedolditem->{'barcode'}); |
| 124 |
if ($exist_itemnumber) { |
131 |
push @errors,"barcode_not_unique" if($exist_itemnumber); |
|
|
132 |
# if barcode exists, don't create, but report The problem. |
| 133 |
my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItemFromMarc($record,$biblionumber) unless ($exist_itemnumber); |
| 134 |
$nextop = "additem"; |
| 135 |
if ($exist_itemnumber) { |
| 136 |
$itemrecord = $record; |
| 137 |
} |
| 138 |
} |
| 139 |
|
| 140 |
# If we have to add & duplicate |
| 141 |
if ($add_duplicate_submit) { |
| 142 |
|
| 143 |
# We try to get the next barcode |
| 144 |
use C4::Barcodes; |
| 145 |
my $barcodeobj = C4::Barcodes->new; |
| 146 |
my $barcodevalue = $barcodeobj->next_value($addedolditem->{'barcode'}) if $barcodeobj; |
| 147 |
my ($tagfield,$tagsubfield) = &GetMarcFromKohaField("items.barcode",$frameworkcode); |
| 148 |
if ($record->field($tagfield)->subfield($tagsubfield)) { |
| 149 |
# If we got the next codebar value, we put it in the record |
| 150 |
if ($barcodevalue) { |
| 151 |
$record->field($tagfield)->update($tagsubfield => $barcodevalue); |
| 152 |
# If not, we delete the recently inserted barcode from the record (so the user can input a barcode himself) |
| 153 |
} else { |
| 154 |
$record->field($tagfield)->update($tagsubfield => ''); |
| 155 |
} |
| 156 |
} |
| 125 |
$itemrecord = $record; |
157 |
$itemrecord = $record; |
| 126 |
} |
158 |
} |
|
|
159 |
|
| 160 |
# If we have to add multiple copies |
| 161 |
if ($add_multiple_copies_submit) { |
| 162 |
|
| 163 |
use C4::Barcodes; |
| 164 |
my $barcodeobj = C4::Barcodes->new; |
| 165 |
my $oldbarcode = $addedolditem->{'barcode'}; |
| 166 |
my ($tagfield,$tagsubfield) = &GetMarcFromKohaField("items.barcode",$frameworkcode); |
| 167 |
|
| 168 |
# If there is a barcode and we can't find him new values, we can't add multiple copies |
| 169 |
my $testbarcode = $barcodeobj->next_value($oldbarcode) if $barcodeobj; |
| 170 |
if ($oldbarcode && !$testbarcode) { |
| 171 |
|
| 172 |
push @errors, "no_next_barcode"; |
| 173 |
$itemrecord = $record; |
| 174 |
|
| 175 |
} else { |
| 176 |
# We add each item |
| 177 |
|
| 178 |
# For the first iteration |
| 179 |
my $barcodevalue = $oldbarcode; |
| 180 |
my $exist_itemnumber; |
| 181 |
|
| 182 |
|
| 183 |
for (my $i = 0; $i < $number_of_copies;) { |
| 184 |
|
| 185 |
# If there is a barcode |
| 186 |
if ($barcodevalue) { |
| 187 |
|
| 188 |
# Getting a new barcode (if it is not the first iteration or the barcode we tried already exists) |
| 189 |
$barcodevalue = $barcodeobj->next_value($oldbarcode) if ($i > 0 || $exist_itemnumber); |
| 190 |
|
| 191 |
# Putting it into the record |
| 192 |
if ($barcodevalue) { |
| 193 |
$record->field($tagfield)->update($tagsubfield => $barcodevalue); |
| 194 |
} |
| 195 |
|
| 196 |
# Checking if the barcode already exists |
| 197 |
$exist_itemnumber = get_item_from_barcode($barcodevalue); |
| 198 |
} |
| 199 |
|
| 200 |
# Adding the item |
| 201 |
my ($oldbiblionumber,$oldbibnum,$oldbibitemnum) = AddItemFromMarc($record,$biblionumber) unless ($exist_itemnumber); |
| 202 |
|
| 203 |
# We count the item only if it was really added |
| 204 |
# That way, all items are added, even if there was some already existing barcodes |
| 205 |
# FIXME : Please note that there is a risk of infinite loop here if we never find a suitable barcode |
| 206 |
$i++ unless ($exist_itemnumber); |
| 207 |
|
| 208 |
# Preparing the next iteration |
| 209 |
$oldbarcode = $barcodevalue; |
| 210 |
} |
| 211 |
undef($itemrecord); |
| 212 |
} |
| 213 |
} |
| 214 |
|
| 215 |
|
| 127 |
#------------------------------------------------------------------------------- |
216 |
#------------------------------------------------------------------------------- |
| 128 |
} elsif ($op eq "edititem") { |
217 |
} elsif ($op eq "edititem") { |
| 129 |
#------------------------------------------------------------------------------- |
218 |
#------------------------------------------------------------------------------- |