View | Details | Raw Unified | Return to bug 7294
Collapse All | Expand All

(-)a/C4/Acquisition.pm (-2 / +85 lines)
Lines 1264-1269 sub ModReceiveOrder { Link Here
1264
    my $order = $sth->fetchrow_hashref();
1264
    my $order = $sth->fetchrow_hashref();
1265
    $sth->finish();
1265
    $sth->finish();
1266
1266
1267
1268
    # If there are still items to be received
1267
    if ( $order->{quantity} > $quantrec ) {
1269
    if ( $order->{quantity} > $quantrec ) {
1268
        $sth=$dbh->prepare("
1270
        $sth=$dbh->prepare("
1269
            UPDATE aqorders
1271
            UPDATE aqorders
Lines 1285-1291 sub ModReceiveOrder { Link Here
1285
        }
1287
        }
1286
        $order->{'quantity'} -= $quantrec;
1288
        $order->{'quantity'} -= $quantrec;
1287
        $order->{'quantityreceived'} = 0;
1289
        $order->{'quantityreceived'} = 0;
1288
        my $newOrder = NewOrder($order);
1290
1291
        my ($newOrder, $newordernumber) = NewOrder($order);
1289
        # Change ordernumber in aqorders_items for items not received
1292
        # Change ordernumber in aqorders_items for items not received
1290
        my @orderitems = GetItemnumbersFromOrder( $order->{'ordernumber'} );
1293
        my @orderitems = GetItemnumbersFromOrder( $order->{'ordernumber'} );
1291
        my $count = scalar @orderitems;
1294
        my $count = scalar @orderitems;
Lines 1298-1311 sub ModReceiveOrder { Link Here
1298
        foreach (@orderitems) {
1301
        foreach (@orderitems) {
1299
            ModItemOrder($_, $newOrder);
1302
            ModItemOrder($_, $newOrder);
1300
        }
1303
        }
1304
1305
	# Do we have to update order informations from the marc record?
1306
	my ($ordertag, $ordersubtag) = GetMarcFromKohaField('aqorders.ordernumber', 'ACQ');
1307
1308
	# Updating MARC order field if exists
1309
	if ($ordertag and $ordersubtag) {
1310
	    $debug and warn "updating MARC";
1311
	    # Getting record
1312
	    my $record = GetMarcBiblio($biblionumber);
1313
	    if ($record) {
1314
		$debug and warn "updating Record";
1315
		foreach ($record->field($ordertag)) {
1316
		    if ($_->subfield($ordersubtag) eq $ordernumber) {
1317
		       # Updating ordernumber
1318
		       $debug and warn "updating ordernumber $ordernumber => $newordernumber";
1319
		       $_->update($ordersubtag => $newordernumber); 
1320
1321
		       # Updating quantity
1322
		       my ($quantitytag, $quantitysubtag) = GetMarcFromKohaField('aqorders.quantity', 'ACQ');
1323
		       if ($quantitysubtag) {
1324
			    $debug and warn "updating quantity " . $order->{quantity};
1325
			    $_->update($quantitysubtag => $order->{quantity});
1326
		       }
1327
		    }
1328
		}
1329
1330
		# Applying changes
1331
		ModBiblio($record, $biblionumber, 'ACQ'); 
1332
	    }	
1333
	}
1334
1335
1301
    } else {
1336
    } else {
1302
        $sth=$dbh->prepare("update aqorders
1337
        $sth = $dbh->prepare(
1338
            "update aqorders
1303
                            set quantityreceived=?,datereceived=?,booksellerinvoicenumber=?,
1339
                            set quantityreceived=?,datereceived=?,booksellerinvoicenumber=?,
1304
                                unitprice=?,freight=?,rrp=?
1340
                                unitprice=?,freight=?,rrp=?
1305
                            where biblionumber=? and ordernumber=?");
1341
                            where biblionumber=? and ordernumber=?");
1306
        $sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$biblionumber,$ordernumber);
1342
        $sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$biblionumber,$ordernumber);
1307
        $sth->finish;
1343
        $sth->finish;
1344
1345
	# Removing MARC order field if exists
1346
	DelMarcOrder($biblionumber, $ordernumber);
1308
    }
1347
    }
1348
1349
    
1309
    return $datereceived;
1350
    return $datereceived;
1310
}
1351
}
1311
#------------------------------------------------------------#
1352
#------------------------------------------------------------#
Lines 1409-1414 sub DelOrder { Link Here
1409
    my $sth = $dbh->prepare($query);
1450
    my $sth = $dbh->prepare($query);
1410
    $sth->execute( $bibnum, $ordernumber );
1451
    $sth->execute( $bibnum, $ordernumber );
1411
    $sth->finish;
1452
    $sth->finish;
1453
1454
    # Removing MARC order field if exists
1455
    DelMarcOrder($bibnum, $ordernumber);
1456
1412
    my @itemnumbers = GetItemnumbersFromOrder( $ordernumber );
1457
    my @itemnumbers = GetItemnumbersFromOrder( $ordernumber );
1413
    foreach my $itemnumber (@itemnumbers){
1458
    foreach my $itemnumber (@itemnumbers){
1414
    	C4::Items::DelItem( $dbh, $bibnum, $itemnumber );
1459
    	C4::Items::DelItem( $dbh, $bibnum, $itemnumber );
Lines 1416-1421 sub DelOrder { Link Here
1416
    
1461
    
1417
}
1462
}
1418
1463
1464
=head3 DelMarcOrder
1465
1466
=over 4
1467
1468
&DelMarcOrder($biblionumber, $ordernumber);
1469
1470
Delete the order field from the MARC record. aqorders.ordernumber needs
1471
to be linked to a MARC field/subfield. The field is deleted if the value of
1472
the subfield containing the ordernumber matches the ordernumber given
1473
in parameter
1474
1475
=back
1476
1477
=cut
1478
1479
sub DelMarcOrder {
1480
    my ($biblionumber, $ordernumber) = @_;
1481
1482
    # Do we have to remove order informations from the marc record?
1483
    my ($ordertag, $ordersubtag) = GetMarcFromKohaField('aqorders.ordernumber', 'ACQ');
1484
1485
    # Removing MARC order field if exists
1486
    if ($ordertag and $ordersubtag) {
1487
	# Getting record
1488
	my $record = GetMarcBiblio($biblionumber);
1489
	if ($record) {
1490
	    # Looking for the right field
1491
	    foreach ($record->field($ordertag)) {
1492
		if ($_->subfield($ordersubtag) eq $ordernumber) {
1493
		   $record->delete_field($_); 
1494
		}
1495
	    }
1496
	    # Applying changes
1497
	    ModBiblio($record, $biblionumber, 'ACQ'); 
1498
	}
1499
    }
1500
}
1501
1419
=head2 FUNCTIONS ABOUT PARCELS
1502
=head2 FUNCTIONS ABOUT PARCELS
1420
1503
1421
=cut
1504
=cut
(-)a/acqui/addorder.pl (-27 / +108 lines)
Lines 122-131 if it is an order from an existing suggestion : the id of this suggestion. Link Here
122
use strict;
122
use strict;
123
use warnings;
123
use warnings;
124
use CGI;
124
use CGI;
125
use C4::Auth;			# get_template_and_user
125
use C4::Auth;           # get_template_and_user
126
use C4::Acquisition;	# NewOrder DelOrder ModOrder
126
use C4::Acquisition;    # NewOrder DelOrder ModOrder
127
use C4::Suggestions;	# ModStatus
127
use C4::Suggestions;    # ModStatus
128
use C4::Biblio;			# AddBiblio TransformKohaToMarc
128
use C4::Biblio;         # AddBiblio TransformKohaToMarc
129
use C4::Bookseller qw/GetBookSellerFromId/;
129
use C4::Items;
130
use C4::Items;
130
use C4::Output;
131
use C4::Output;
131
132
Lines 193-235 my $user = $input->remote_user; Link Here
193
# delete biblio if delbiblio has been set to 1 by the librarian
194
# delete biblio if delbiblio has been set to 1 by the librarian
194
my $bibitemnum;
195
my $bibitemnum;
195
if ( $orderinfo->{quantity} ne '0' ) {
196
if ( $orderinfo->{quantity} ne '0' ) {
197
198
    # Getting bookseller's name
199
    if ($$orderinfo{booksellerid}) {
200
        my $bookseller = GetBookSellerFromId($$orderinfo{booksellerid});
201
        $$orderinfo{supplierreference} = $bookseller->{name};
202
    }
203
204
    # Do we have to add order informations to the marc record?
205
    my ($ordertag, $ordersubtag) = GetMarcFromKohaField('aqorders.ordernumber', 'ACQ'); 
206
    my $record;
207
    my $existingbiblio; # Was the order made on an existing biblio?
208
    my $ordermodif;     # Is this an order modification?
209
196
    #TODO:check to see if biblio exists
210
    #TODO:check to see if biblio exists
197
    unless ( $$orderinfo{biblionumber} ) {
211
    unless ( $$orderinfo{biblionumber} ) {
198
        #if it doesnt create it
212
        #if it doesnt create it
199
        my $record = TransformKohaToMarc(
213
        my $tmprecord = TransformKohaToMarc(
200
            {
214
            {   "biblio.title"                => "$$orderinfo{title}",
201
                "biblio.title"                => "$$orderinfo{title}",
215
                "biblio.author"               => $$orderinfo{author}          ? $$orderinfo{author}          : "",
202
                "biblio.author"               => $$orderinfo{author}          ? $$orderinfo{author}        : "",
216
                "biblio.seriestitle"          => $$orderinfo{series}          ? $$orderinfo{series}          : "",
203
                "biblio.seriestitle"          => $$orderinfo{series}          ? $$orderinfo{series}        : "",
217
                "biblio.copyrightdate"        => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear} : "",
204
                "biblioitems.isbn"            => $$orderinfo{isbn}            ? $$orderinfo{isbn}          : "",
218
                "biblioitems.isbn"            => $$orderinfo{isbn}            ? $$orderinfo{isbn}            : "",
205
                "biblioitems.ean"             => $$orderinfo{ean}             ? $$orderinfo{ean}           : "",
219
                "biblioitems.ean"             => $$orderinfo{ean}             ? $$orderinfo{ean}             : "",
206
                "biblioitems.publishercode"   => $$orderinfo{publishercode}   ? $$orderinfo{publishercode} : "",
220
                "biblioitems.publishercode"   => $$orderinfo{publishercode}   ? $$orderinfo{publishercode}   : "",
207
                "biblioitems.publicationyear" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear}: "",
221
                "biblioitems.publicationyear" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear} : "",
208
                "biblio.copyrightdate"        => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear}: "",
222
                "biblioitems.itemtype"        => $$orderinfo{itemtype}        ? $$orderinfo{itemtype}        : "",
209
                "biblioitems.itemtype"        => $$orderinfo{itemtype} ? $$orderinfo{itemtype} : "",
223
                "biblioitems.editionstatement"=> $$orderinfo{editionstatement}? $$orderinfo{editionstatement}: "",
210
                "biblioitems.editionstatement"=> $$orderinfo{editionstatement} ? $$orderinfo{editionstatement} : "",
224
                "aqorders.branchcode"         => $$orderinfo{branchcode}      ? $$orderinfo{branchcode}      : "",
211
            });
225
                "aqorders.quantity"           => $$orderinfo{quantity}        ? $$orderinfo{quantity}        : "",
226
                "aqorders.listprice"          => $$orderinfo{listprice}       ? $$orderinfo{listprice}       : "",
227
                "aqorders.uncertainprice"     => $$orderinfo{uncertainprice}  ? $$orderinfo{uncertainprice}  : "",
228
                "aqorders.rrp"                => $$orderinfo{rrp}             ? $$orderinfo{rrp}             : "",
229
                "aqorders.ecost"              => $$orderinfo{ecost}           ? $$orderinfo{ecost}           : "",
230
                "aqorders.notes"              => $$orderinfo{notes}           ? $$orderinfo{notes}           : "",
231
                "aqorders.supplierreference"  => $$orderinfo{supplierreference}?$$orderinfo{supplierreference}:"",
232
                "aqorders.sort1"              => $$orderinfo{sort1}           ? $$orderinfo{sort1}           : "",
233
                "aqorders.sort2"              => $$orderinfo{sort2}           ? $$orderinfo{sort2}           : ""
234
            }
235
        );
212
236
213
        # create the record in catalogue, with framework ''
237
        # create the record in catalogue, with framework ''
214
        my ($biblionumber,$bibitemnum) = AddBiblio($record,'');
238
        my ( $biblionumber, $bibitemnum ) = AddBiblio( $tmprecord, '' );
239
215
        # change suggestion status if applicable
240
        # change suggestion status if applicable
216
        if ($$orderinfo{suggestionid}) {
241
        if ($$orderinfo{suggestionid}) {
217
            ModSuggestion( {suggestionid=>$$orderinfo{suggestionid}, STATUS=>'ORDERED', biblionumber=>$biblionumber} );
242
            ModSuggestion( {suggestionid=>$$orderinfo{suggestionid}, STATUS=>'ORDERED', biblionumber=>$biblionumber} );
218
        }
243
        }
219
		$orderinfo->{biblioitemnumber}=$bibitemnum;
244
        $orderinfo->{biblioitemnumber} = $bibitemnum;
220
		$orderinfo->{biblionumber}=$biblionumber;
245
        $orderinfo->{biblionumber}     = $biblionumber;
246
    } else {
247
	$existingbiblio = 1;
221
    }
248
    }
222
249
223
    # if we already have $ordernumber, then it's an ordermodif
250
    # Getting record
224
    if ($$orderinfo{ordernumber}) {
251
    $record = GetMarcBiblio($$orderinfo{biblionumber});
225
        ModOrder( $orderinfo);
252
226
    }
253
    
227
    else { # else, it's a new line
254
255
     # if we already have $ordernumber, then it's an ordermodif
256
    if ( $$orderinfo{ordernumber} ) {
257
        ModOrder($orderinfo);
258
	$ordermodif = 1;
259
	
260
    } else {    # else, it's a new line
228
        @$orderinfo{qw(basketno ordernumber )} = NewOrder($orderinfo);
261
        @$orderinfo{qw(basketno ordernumber )} = NewOrder($orderinfo);
262
263
        # We have to add the ordernumber in the designated subfield
264
	if ($ordertag && $record && !$ordermodif) {
265
266
            # If it's a new line, but we don't have any $ordertag field yet, 
267
            if (!$record->field($ordertag)) {
268
                # We add a new $ordertag field, with the ordernumber as subfield (other fields will be populated later)
269
                $record->insert_fields_ordered(new MARC::Field($ordertag, '', '', $ordersubtag => $$orderinfo{ordernumber})) if (!$record->field($ordertag));
270
            } else {
271
                # Else, it's a new line, and we already have a $ordertag field
272
                foreach ($record->field($ordertag)) {
273
                    # If there's a $ordertag field without ordernumber, we create it
274
                    if (!$_->subfield($ordersubtag)) {
275
                        $_->update($ordersubtag, $$orderinfo{ordernumber});
276
                    }
277
                }
278
            }
279
            ModBiblio($record, $$orderinfo{biblionumber}, 'ACQ');
280
	}
281
282
229
    }
283
    }
230
284
231
    # now, add items if applicable
285
    if ($record) {
232
    if (C4::Context->preference('AcqCreateItem') eq 'ordering') {
286
287
	# If we have to add order infos to the marc record
288
	if ($ordertag) {
289
290
	    # If the order was made on an existing biblio and it is not a modification, we add the field 
291
	    $record->insert_fields_ordered(new MARC::Field($ordertag, '', '', $ordersubtag => $$orderinfo{ordernumber})) if (!$ordermodif && $existingbiblio);
292
293
	    foreach ($record->field($ordertag)) {
294
		# Looking for the matching one
295
		if ($_->subfield($ordersubtag) eq $$orderinfo{ordernumber}) {
296
297
		    # Replacing or creating subfields
298
		    my ($t, $st);
299
		    for my $tablefield (qw/branchcode quantity listprice uncertainprice rrp ecost notes supplierreference sort1 sort2/) {
300
			($t, $st) = GetMarcFromKohaField("aqorders.$tablefield", 'ACQ');
301
			$_->update($st, $$orderinfo{$tablefield}) if ($$orderinfo{$tablefield} and $st);
302
		    }
303
		    ModBiblio($record, $$orderinfo{biblionumber}, 'ACQ');
304
		}
305
	    }
306
307
	}
308
309
    }
310
311
312
      # now, add items if applicable
313
    if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) {
233
314
234
        my @tags         = $input->param('tag');
315
        my @tags         = $input->param('tag');
235
        my @subfields    = $input->param('subfield');
316
        my @subfields    = $input->param('subfield');
(-)a/admin/koha2marclinks.pl (-6 / +2 lines)
Lines 157-168 q|select tagfield,tagsubfield,liblibrarian,kohafield from marc_subfield_structur Link Here
157
    $template->param(
157
    $template->param(
158
        loop      => \@loop_data,
158
        loop      => \@loop_data,
159
        tablename => CGI::scrolling_list(
159
        tablename => CGI::scrolling_list(
160
            -name   => 'tablename',
160
            -name     => 'tablename',
161
            -values => [
161
            -values   => [ 'biblio', 'biblioitems', 'items', 'aqorders'],
162
                'biblio',
163
                'biblioitems',
164
                'items',
165
            ],
166
            -default  => $tablename,
162
            -default  => $tablename,
167
            -size     => 1,
163
            -size     => 1,
168
            -multiple => 0
164
            -multiple => 0
(-)a/admin/marc_subfields_structure.pl (+6 lines)
Lines 123-128 if ( $op eq 'add_form' ) { Link Here
123
    while ( ( my $field ) = $sth2->fetchrow_array ) {
123
    while ( ( my $field ) = $sth2->fetchrow_array ) {
124
        push @kohafields, "items." . $field;
124
        push @kohafields, "items." . $field;
125
    }
125
    }
126
    $sth2 = $dbh->prepare("SHOW COLUMNS from aqorders");
127
    $sth2->execute;
128
    while ( ( my $field ) = $sth2->fetchrow_array ) {
129
        push @kohafields, "aqorders." . $field;
130
    }
131
126
132
127
    # build authorised value list
133
    # build authorised value list
128
    $sth2->finish;
134
    $sth2->finish;
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 2771-2776 CREATE TABLE `aqorders` ( -- information related to the basket line items Link Here
2771
  `uncertainprice` tinyint(1), -- was this price uncertain (1 for yes, 0 for no)
2771
  `uncertainprice` tinyint(1), -- was this price uncertain (1 for yes, 0 for no)
2772
  `claims_count` int(11) default 0, -- count of claim letters generated
2772
  `claims_count` int(11) default 0, -- count of claim letters generated
2773
  `claimed_date` date default NULL, -- last date a claim was generated
2773
  `claimed_date` date default NULL, -- last date a claim was generated
2774
  `branchcode` varchar(10) default NULL,
2774
  PRIMARY KEY  (`ordernumber`),
2775
  PRIMARY KEY  (`ordernumber`),
2775
  KEY `basketno` (`basketno`),
2776
  KEY `basketno` (`basketno`),
2776
  KEY `biblionumber` (`biblionumber`),
2777
  KEY `biblionumber` (`biblionumber`),
(-)a/installer/data/mysql/updatedatabase.pl (+10 lines)
Lines 5635-5641 if(C4::Context->preference("Version") < TransformToNum($DBversion) ) { Link Here
5635
    SetVersion($DBversion);
5635
    SetVersion($DBversion);
5636
}
5636
}
5637
5637
5638
$DBversion = "3.09.00.XXX";
5639
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
5640
    $dbh->do("ALTER TABLE `aqorders` ADD `branchcode` VARCHAR( 10 ) NULL");
5641
    print "Upgrade to $DBversion done (Adding branchcode in aqorders)\n";
5642
    SetVersion($DBversion);
5643
}
5644
5638
=head1 FUNCTIONS
5645
=head1 FUNCTIONS
5646
=======
5647
5648
=item DropAllForeignKeys($table)
5639
5649
5640
=head2 TableExists($table)
5650
=head2 TableExists($table)
5641
5651
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt (-1 / +18 lines)
Lines 329-334 $(document).ready(function() Link Here
329
        </ol>
329
        </ol>
330
    </fieldset>
330
    </fieldset>
331
331
332
    <!-- Acquisition details -->
333
    <fieldset class="rows">
334
        <legend>Acquisition details</legend>
335
	<ol>
336
	<li>
337
	    <label for="branchcode">Branch: </label>
338
	    <select name="branchcode" id="branchcode">
339
                    <option value=""></option>
340
                [% FOREACH branch_loo IN branchloop %]
341
		    <option value="[% branch_loo.value %]" [% IF (branch_loo.selected) %]selected="selected" [% END %]>[% branch_loo.branchname %]</option>
342
                [% END %]
343
	    </select>
344
	</li>
345
	</ol>
346
    </fieldset>	
347
348
349
332
    [% IF ( suggestionid ) %]
350
    [% IF ( suggestionid ) %]
333
        <fieldset class="rows">
351
        <fieldset class="rows">
334
        <legend>Suggestion</legend>
352
        <legend>Suggestion</legend>
335
- 

Return to bug 7294