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

(-)a/C4/Acquisition.pm (-1 / +102 lines)
Lines 1287-1292 sub ModReceiveOrder { Link Here
1287
    $sth->finish();
1287
    $sth->finish();
1288
1288
1289
    my $new_ordernumber = $ordernumber;
1289
    my $new_ordernumber = $ordernumber;
1290
1291
    # If there are still items to be received
1290
    if ( $order->{quantity} > $quantrec ) {
1292
    if ( $order->{quantity} > $quantrec ) {
1291
        # Split order line in two parts: the first is the original order line
1293
        # Split order line in two parts: the first is the original order line
1292
        # without received items (the quantity is decreased),
1294
        # without received items (the quantity is decreased),
Lines 1317-1329 sub ModReceiveOrder { Link Here
1317
                ModItemOrder($itemnumber, $new_ordernumber);
1319
                ModItemOrder($itemnumber, $new_ordernumber);
1318
            }
1320
            }
1319
        }
1321
        }
1322
1323
        # create a new order for the remaining items, and set its bookfund.
1324
        foreach my $orderkey ( "linenumber", "allocation" ) {
1325
            delete($order->{'$orderkey'});
1326
        }
1327
        $order->{'quantity'} -= $quantrec;
1328
        $order->{'quantityreceived'} = 0;
1329
1330
        my ($newOrder, $newordernumber) = NewOrder($order);
1331
        # Change ordernumber in aqorders_items for items not received
1332
        my @orderitems = GetItemnumbersFromOrder( $order->{'ordernumber'} );
1333
        my $count = scalar @orderitems;
1334
1335
        for (my $i=0; $i<$count; $i++){
1336
            foreach (@$received_items){
1337
                splice (@orderitems, $i, 1) if ($orderitems[$i] == $_);
1338
            }
1339
        }
1340
        foreach (@orderitems) {
1341
            ModItemOrder($_, $newOrder);
1342
        }
1343
1344
	# Do we have to update order informations from the marc record?
1345
	my ($ordertag, $ordersubtag) = GetMarcFromKohaField('aqorders.ordernumber', 'ACQ');
1346
1347
	# Updating MARC order field if exists
1348
	if ($ordertag and $ordersubtag) {
1349
	    $debug and warn "updating MARC";
1350
	    # Getting record
1351
	    my $record = GetMarcBiblio($biblionumber);
1352
	    if ($record) {
1353
		$debug and warn "updating Record";
1354
		foreach ($record->field($ordertag)) {
1355
		    if ($_->subfield($ordersubtag) eq $ordernumber) {
1356
		       # Updating ordernumber
1357
		       $debug and warn "updating ordernumber $ordernumber => $newordernumber";
1358
		       $_->update($ordersubtag => $newordernumber); 
1359
1360
		       # Updating quantity
1361
		       my ($quantitytag, $quantitysubtag) = GetMarcFromKohaField('aqorders.quantity', 'ACQ');
1362
		       if ($quantitysubtag) {
1363
			    $debug and warn "updating quantity " . $order->{quantity};
1364
			    $_->update($quantitysubtag => $order->{quantity});
1365
		       }
1366
		    }
1367
		}
1368
1369
		# Applying changes
1370
		ModBiblio($record, $biblionumber, 'ACQ'); 
1371
	    }	
1372
	}
1373
1374
1320
    } else {
1375
    } else {
1321
        $sth=$dbh->prepare("update aqorders
1376
        $sth = $dbh->prepare(
1377
            "update aqorders
1322
                            set quantityreceived=?,datereceived=?,booksellerinvoicenumber=?,
1378
                            set quantityreceived=?,datereceived=?,booksellerinvoicenumber=?,
1323
                                unitprice=?,freight=?,rrp=?
1379
                                unitprice=?,freight=?,rrp=?
1324
                            where biblionumber=? and ordernumber=?");
1380
                            where biblionumber=? and ordernumber=?");
1325
        $sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$biblionumber,$ordernumber);
1381
        $sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$biblionumber,$ordernumber);
1326
        $sth->finish;
1382
        $sth->finish;
1383
1384
	# Removing MARC order field if exists
1385
	DelMarcOrder($biblionumber, $ordernumber);
1327
    }
1386
    }
1328
    return ($datereceived, $new_ordernumber);
1387
    return ($datereceived, $new_ordernumber);
1329
}
1388
}
Lines 1543-1548 sub DelOrder { Link Here
1543
    my $sth = $dbh->prepare($query);
1602
    my $sth = $dbh->prepare($query);
1544
    $sth->execute( $bibnum, $ordernumber );
1603
    $sth->execute( $bibnum, $ordernumber );
1545
    $sth->finish;
1604
    $sth->finish;
1605
1606
    # Removing MARC order field if exists
1607
    DelMarcOrder($bibnum, $ordernumber);
1608
1546
    my @itemnumbers = GetItemnumbersFromOrder( $ordernumber );
1609
    my @itemnumbers = GetItemnumbersFromOrder( $ordernumber );
1547
    foreach my $itemnumber (@itemnumbers){
1610
    foreach my $itemnumber (@itemnumbers){
1548
    	C4::Items::DelItem( $dbh, $bibnum, $itemnumber );
1611
    	C4::Items::DelItem( $dbh, $bibnum, $itemnumber );
Lines 1550-1555 sub DelOrder { Link Here
1550
    
1613
    
1551
}
1614
}
1552
1615
1616
=head3 DelMarcOrder
1617
1618
=over 4
1619
1620
&DelMarcOrder($biblionumber, $ordernumber);
1621
1622
Delete the order field from the MARC record. aqorders.ordernumber needs
1623
to be linked to a MARC field/subfield. The field is deleted if the value of
1624
the subfield containing the ordernumber matches the ordernumber given
1625
in parameter
1626
1627
=back
1628
1629
=cut
1630
1631
sub DelMarcOrder {
1632
    my ($biblionumber, $ordernumber) = @_;
1633
1634
    # Do we have to remove order informations from the marc record?
1635
    my ($ordertag, $ordersubtag) = GetMarcFromKohaField('aqorders.ordernumber', 'ACQ');
1636
1637
    # Removing MARC order field if exists
1638
    if ($ordertag and $ordersubtag) {
1639
	# Getting record
1640
	my $record = GetMarcBiblio($biblionumber);
1641
	if ($record) {
1642
	    # Looking for the right field
1643
	    foreach ($record->field($ordertag)) {
1644
		if ($_->subfield($ordersubtag) eq $ordernumber) {
1645
		   $record->delete_field($_); 
1646
		}
1647
	    }
1648
	    # Applying changes
1649
	    ModBiblio($record, $biblionumber, 'ACQ'); 
1650
	}
1651
    }
1652
}
1653
1553
=head2 FUNCTIONS ABOUT PARCELS
1654
=head2 FUNCTIONS ABOUT PARCELS
1554
1655
1555
=cut
1656
=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 2776-2781 CREATE TABLE `aqorders` ( -- information related to the basket line items Link Here
2776
  `claims_count` int(11) default 0, -- count of claim letters generated
2776
  `claims_count` int(11) default 0, -- count of claim letters generated
2777
  `claimed_date` date default NULL, -- last date a claim was generated
2777
  `claimed_date` date default NULL, -- last date a claim was generated
2778
  parent_ordernumber int(11) default NULL, -- ordernumber of parent order line, or same as ordernumber if no parent
2778
  parent_ordernumber int(11) default NULL, -- ordernumber of parent order line, or same as ordernumber if no parent
2779
  `branchcode` varchar(10) default NULL,
2779
  PRIMARY KEY  (`ordernumber`),
2780
  PRIMARY KEY  (`ordernumber`),
2780
  KEY `basketno` (`basketno`),
2781
  KEY `basketno` (`basketno`),
2781
  KEY `biblionumber` (`biblionumber`),
2782
  KEY `biblionumber` (`biblionumber`),
(-)a/installer/data/mysql/updatedatabase.pl (+9 lines)
Lines 5804-5813 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { Link Here
5804
    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowReturnToBranch', '$prefvalue', 'Where an item may be returned', 'anywhere|homebranch|holdingbranch|homeorholdingbranch', 'Choice');");
5804
    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowReturnToBranch', '$prefvalue', 'Where an item may be returned', 'anywhere|homebranch|holdingbranch|homeorholdingbranch', 'Choice');");
5805
5805
5806
    print "Upgrade to $DBversion done: adding AllowReturnToBranch syspref (bug 6151)";
5806
    print "Upgrade to $DBversion done: adding AllowReturnToBranch syspref (bug 6151)";
5807
}
5808
5809
$DBversion = "3.09.00.XXX";
5810
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
5811
    $dbh->do("ALTER TABLE `aqorders` ADD `branchcode` VARCHAR( 10 ) NULL");
5812
    print "Upgrade to $DBversion done (Adding branchcode in aqorders)\n";
5807
    SetVersion($DBversion);
5813
    SetVersion($DBversion);
5808
}
5814
}
5809
5815
5810
=head1 FUNCTIONS
5816
=head1 FUNCTIONS
5817
=======
5818
5819
=item DropAllForeignKeys($table)
5811
5820
5812
=head2 TableExists($table)
5821
=head2 TableExists($table)
5813
5822
(-)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