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

(-)a/C4/Acquisition.pm (+100 lines)
Lines 1305-1310 sub ModReceiveOrder { Link Here
1305
    $sth->finish();
1305
    $sth->finish();
1306
1306
1307
    my $new_ordernumber = $ordernumber;
1307
    my $new_ordernumber = $ordernumber;
1308
1309
    # If there are still items to be received
1308
    if ( $order->{quantity} > $quantrec ) {
1310
    if ( $order->{quantity} > $quantrec ) {
1309
        # Split order line in two parts: the first is the original order line
1311
        # Split order line in two parts: the first is the original order line
1310
        # without received items (the quantity is decreased),
1312
        # without received items (the quantity is decreased),
Lines 1336-1341 sub ModReceiveOrder { Link Here
1336
                ModItemOrder($itemnumber, $new_ordernumber);
1338
                ModItemOrder($itemnumber, $new_ordernumber);
1337
            }
1339
            }
1338
        }
1340
        }
1341
1342
        # create a new order for the remaining items, and set its bookfund.
1343
        foreach my $orderkey ( "linenumber", "allocation" ) {
1344
            delete($order->{'$orderkey'});
1345
        }
1346
        $order->{'quantity'} -= $quantrec;
1347
        $order->{'quantityreceived'} = 0;
1348
1349
        my ($newOrder, $newordernumber) = NewOrder($order);
1350
        # Change ordernumber in aqorders_items for items not received
1351
        my @orderitems = GetItemnumbersFromOrder( $order->{'ordernumber'} );
1352
        my $count = scalar @orderitems;
1353
1354
        for (my $i=0; $i<$count; $i++){
1355
            foreach (@$received_items){
1356
                splice (@orderitems, $i, 1) if ($orderitems[$i] == $_);
1357
            }
1358
        }
1359
        foreach (@orderitems) {
1360
            ModItemOrder($_, $newOrder);
1361
        }
1362
1363
	# Do we have to update order informations from the marc record?
1364
	my ($ordertag, $ordersubtag) = GetMarcFromKohaField('aqorders.ordernumber', 'ACQ');
1365
1366
	# Updating MARC order field if exists
1367
	if ($ordertag and $ordersubtag) {
1368
	    $debug and warn "updating MARC";
1369
	    # Getting record
1370
	    my $record = GetMarcBiblio($biblionumber);
1371
	    if ($record) {
1372
		$debug and warn "updating Record";
1373
		foreach ($record->field($ordertag)) {
1374
		    if ($_->subfield($ordersubtag) eq $ordernumber) {
1375
		       # Updating ordernumber
1376
		       $debug and warn "updating ordernumber $ordernumber => $newordernumber";
1377
		       $_->update($ordersubtag => $newordernumber); 
1378
1379
		       # Updating quantity
1380
		       my ($quantitytag, $quantitysubtag) = GetMarcFromKohaField('aqorders.quantity', 'ACQ');
1381
		       if ($quantitysubtag) {
1382
			    $debug and warn "updating quantity " . $order->{quantity};
1383
			    $_->update($quantitysubtag => $order->{quantity});
1384
		       }
1385
		    }
1386
		}
1387
1388
		# Applying changes
1389
		ModBiblio($record, $biblionumber, 'ACQ'); 
1390
	    }	
1391
	}
1392
1393
1339
    } else {
1394
    } else {
1340
        $sth=$dbh->prepare("update aqorders
1395
        $sth=$dbh->prepare("update aqorders
1341
                            set quantityreceived=?,datereceived=?,invoiceid=?,
1396
                            set quantityreceived=?,datereceived=?,invoiceid=?,
Lines 1343-1348 sub ModReceiveOrder { Link Here
1343
                            where biblionumber=? and ordernumber=?");
1398
                            where biblionumber=? and ordernumber=?");
1344
        $sth->execute($quantrec,$datereceived,$invoiceid,$cost,$rrp,$ecost,$biblionumber,$ordernumber);
1399
        $sth->execute($quantrec,$datereceived,$invoiceid,$cost,$rrp,$ecost,$biblionumber,$ordernumber);
1345
        $sth->finish;
1400
        $sth->finish;
1401
1402
	# Removing MARC order field if exists
1403
	DelMarcOrder($biblionumber, $ordernumber);
1346
    }
1404
    }
1347
    return ($datereceived, $new_ordernumber);
1405
    return ($datereceived, $new_ordernumber);
1348
}
1406
}
Lines 1562-1567 sub DelOrder { Link Here
1562
    my $sth = $dbh->prepare($query);
1620
    my $sth = $dbh->prepare($query);
1563
    $sth->execute( $bibnum, $ordernumber );
1621
    $sth->execute( $bibnum, $ordernumber );
1564
    $sth->finish;
1622
    $sth->finish;
1623
1624
    # Removing MARC order field if exists
1625
    DelMarcOrder($bibnum, $ordernumber);
1626
1565
    my @itemnumbers = GetItemnumbersFromOrder( $ordernumber );
1627
    my @itemnumbers = GetItemnumbersFromOrder( $ordernumber );
1566
    foreach my $itemnumber (@itemnumbers){
1628
    foreach my $itemnumber (@itemnumbers){
1567
    	C4::Items::DelItem( $dbh, $bibnum, $itemnumber );
1629
    	C4::Items::DelItem( $dbh, $bibnum, $itemnumber );
Lines 1569-1574 sub DelOrder { Link Here
1569
    
1631
    
1570
}
1632
}
1571
1633
1634
=head3 DelMarcOrder
1635
1636
=over 4
1637
1638
&DelMarcOrder($biblionumber, $ordernumber);
1639
1640
Delete the order field from the MARC record. aqorders.ordernumber needs
1641
to be linked to a MARC field/subfield. The field is deleted if the value of
1642
the subfield containing the ordernumber matches the ordernumber given
1643
in parameter
1644
1645
=back
1646
1647
=cut
1648
1649
sub DelMarcOrder {
1650
    my ($biblionumber, $ordernumber) = @_;
1651
1652
    # Do we have to remove order informations from the marc record?
1653
    my ($ordertag, $ordersubtag) = GetMarcFromKohaField('aqorders.ordernumber', 'ACQ');
1654
1655
    # Removing MARC order field if exists
1656
    if ($ordertag and $ordersubtag) {
1657
	# Getting record
1658
	my $record = GetMarcBiblio($biblionumber);
1659
	if ($record) {
1660
	    # Looking for the right field
1661
	    foreach ($record->field($ordertag)) {
1662
		if ($_->subfield($ordersubtag) eq $ordernumber) {
1663
		   $record->delete_field($_); 
1664
		}
1665
	    }
1666
	    # Applying changes
1667
	    ModBiblio($record, $biblionumber, 'ACQ'); 
1668
	}
1669
    }
1670
}
1671
1572
=head2 FUNCTIONS ABOUT PARCELS
1672
=head2 FUNCTIONS ABOUT PARCELS
1573
1673
1574
=cut
1674
=cut
(-)a/acqui/addorder.pl (-34 / +109 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 163-214 my $user = $input->remote_user; Link Here
163
# delete biblio if delbiblio has been set to 1 by the librarian
164
# delete biblio if delbiblio has been set to 1 by the librarian
164
my $bibitemnum;
165
my $bibitemnum;
165
if ( $orderinfo->{quantity} ne '0' ) {
166
if ( $orderinfo->{quantity} ne '0' ) {
167
168
    # Getting bookseller's name
169
    if ($$orderinfo{booksellerid}) {
170
        my $bookseller = GetBookSellerFromId($$orderinfo{booksellerid});
171
        $$orderinfo{supplierreference} = $bookseller->{name};
172
    }
173
174
    # Do we have to add order informations to the marc record?
175
    my ($ordertag, $ordersubtag) = GetMarcFromKohaField('aqorders.ordernumber', 'ACQ'); 
176
    my $record;
177
    my $existingbiblio; # Was the order made on an existing biblio?
178
    my $ordermodif;     # Is this an order modification?
179
166
    #TODO:check to see if biblio exists
180
    #TODO:check to see if biblio exists
167
    unless ( $$orderinfo{biblionumber} ) {
181
    unless ( $$orderinfo{biblionumber} ) {
168
        #if it doesnt create it
182
        #if it doesnt create it
169
        my $record = TransformKohaToMarc(
183
        my $tmprecord = TransformKohaToMarc(
170
            {
184
            {   "biblio.title"                => "$$orderinfo{title}",
171
                "biblio.title"                => "$$orderinfo{title}",
185
                "biblio.author"               => $$orderinfo{author}          ? $$orderinfo{author}          : "",
172
                "biblio.author"               => $$orderinfo{author}          ? $$orderinfo{author}        : "",
186
                "biblio.seriestitle"          => $$orderinfo{series}          ? $$orderinfo{series}          : "",
173
                "biblio.seriestitle"          => $$orderinfo{series}          ? $$orderinfo{series}        : "",
187
                "biblio.copyrightdate"        => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear} : "",
174
                "biblioitems.isbn"            => $$orderinfo{isbn}            ? $$orderinfo{isbn}          : "",
188
                "biblioitems.isbn"            => $$orderinfo{isbn}            ? $$orderinfo{isbn}            : "",
175
                "biblioitems.ean"             => $$orderinfo{ean}             ? $$orderinfo{ean}           : "",
189
                "biblioitems.ean"             => $$orderinfo{ean}             ? $$orderinfo{ean}             : "",
176
                "biblioitems.publishercode"   => $$orderinfo{publishercode}   ? $$orderinfo{publishercode} : "",
190
                "biblioitems.publishercode"   => $$orderinfo{publishercode}   ? $$orderinfo{publishercode}   : "",
177
                "biblioitems.publicationyear" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear}: "",
191
                "biblioitems.publicationyear" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear} : "",
178
                "biblio.copyrightdate"        => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear}: "",
192
                "biblioitems.itemtype"        => $$orderinfo{itemtype}        ? $$orderinfo{itemtype}        : "",
179
                "biblioitems.itemtype"        => $$orderinfo{itemtype} ? $$orderinfo{itemtype} : "",
193
                "biblioitems.editionstatement"=> $$orderinfo{editionstatement}? $$orderinfo{editionstatement}: "",
180
                "biblioitems.editionstatement"=> $$orderinfo{editionstatement} ? $$orderinfo{editionstatement} : "",
194
                "aqorders.branchcode"         => $$orderinfo{branchcode}      ? $$orderinfo{branchcode}      : "",
181
                "aqorders.branchcode"         => $$orderinfo{branchcode} ? $$orderinfo{branchcode} : "",
195
                "aqorders.quantity"           => $$orderinfo{quantity}        ? $$orderinfo{quantity}        : "",
182
                "aqorders.quantity"           => $$orderinfo{quantity} ? $$orderinfo{quantity} : "",
196
                "aqorders.listprice"          => $$orderinfo{listprice}       ? $$orderinfo{listprice}       : "",
183
                "aqorders.listprice"          => $$orderinfo{listprice} ? $$orderinfo{listprice} : "",
197
                "aqorders.uncertainprice"     => $$orderinfo{uncertainprice}  ? $$orderinfo{uncertainprice}  : "",
184
                "aqorders.uncertainprice"     => $$orderinfo{uncertainprice} ? $$orderinfo{uncertainprice} : "",
198
                "aqorders.rrp"                => $$orderinfo{rrp}             ? $$orderinfo{rrp}             : "",
185
                "aqorders.rrp"                => $$orderinfo{rrp} ? $$orderinfo{rrp} : "",
199
                "aqorders.ecost"              => $$orderinfo{ecost}           ? $$orderinfo{ecost}           : "",
186
                "aqorders.ecost"              => $$orderinfo{ecost} ? $$orderinfo{ecost} : "",
200
                "aqorders.discount"           => $$orderinfo{discount}        ? $$orderinfo{discount}        : "",
187
                "aqorders.discount"           => $$orderinfo{discount} ? $$orderinfo{discount} : "",
201
                "aqorders.notes"              => $$orderinfo{notes}           ? $$orderinfo{notes}           : "",
188
            });
202
                "aqorders.supplierreference"  => $$orderinfo{supplierreference}?$$orderinfo{supplierreference}:"",
203
                "aqorders.sort1"              => $$orderinfo{sort1}           ? $$orderinfo{sort1}           : "",
204
                "aqorders.sort2"              => $$orderinfo{sort2}           ? $$orderinfo{sort2}           : ""
205
            }
206
        );
189
207
190
        # create the record in catalogue, with framework ''
208
        # create the record in catalogue, with framework ''
191
        my ($biblionumber,$bibitemnum) = AddBiblio($record,'');
209
        my ( $biblionumber, $bibitemnum ) = AddBiblio( $tmprecord, '' );
210
192
        # change suggestion status if applicable
211
        # change suggestion status if applicable
193
        if ($$orderinfo{suggestionid}) {
212
        if ($$orderinfo{suggestionid}) {
194
            ModSuggestion( {suggestionid=>$$orderinfo{suggestionid}, STATUS=>'ORDERED', biblionumber=>$biblionumber} );
213
            ModSuggestion( {suggestionid=>$$orderinfo{suggestionid}, STATUS=>'ORDERED', biblionumber=>$biblionumber} );
195
        }
214
        }
196
		$orderinfo->{biblioitemnumber}=$bibitemnum;
215
        $orderinfo->{biblioitemnumber} = $bibitemnum;
197
		$orderinfo->{biblionumber}=$biblionumber;
216
        $orderinfo->{biblionumber}     = $biblionumber;
217
    } else {
218
	$existingbiblio = 1;
198
    }
219
    }
199
220
200
    $orderinfo->{unitprice} = $orderinfo->{ecost} if not defined $orderinfo->{unitprice} or $orderinfo->{unitprice} eq '';
221
    $orderinfo->{unitprice} = $orderinfo->{ecost} if not defined $orderinfo->{unitprice} or $orderinfo->{unitprice} eq '';
201
222
202
    # if we already have $ordernumber, then it's an ordermodif
223
    # Getting record
203
    if ($$orderinfo{ordernumber}) {
224
    $record = GetMarcBiblio($$orderinfo{biblionumber});
204
        ModOrder( $orderinfo);
225
205
    }
226
    
206
    else { # else, it's a new line
227
228
     # if we already have $ordernumber, then it's an ordermodif
229
    if ( $$orderinfo{ordernumber} ) {
230
        ModOrder($orderinfo);
231
	$ordermodif = 1;
232
	
233
    } else {    # else, it's a new line
207
        @$orderinfo{qw(basketno ordernumber )} = NewOrder($orderinfo);
234
        @$orderinfo{qw(basketno ordernumber )} = NewOrder($orderinfo);
235
236
        # We have to add the ordernumber in the designated subfield
237
	if ($ordertag && $record && !$ordermodif) {
238
239
            # If it's a new line, but we don't have any $ordertag field yet, 
240
            if (!$record->field($ordertag)) {
241
                # We add a new $ordertag field, with the ordernumber as subfield (other fields will be populated later)
242
                $record->insert_fields_ordered(new MARC::Field($ordertag, '', '', $ordersubtag => $$orderinfo{ordernumber})) if (!$record->field($ordertag));
243
            } else {
244
                # Else, it's a new line, and we already have a $ordertag field
245
                foreach ($record->field($ordertag)) {
246
                    # If there's a $ordertag field without ordernumber, we create it
247
                    if (!$_->subfield($ordersubtag)) {
248
                        $_->update($ordersubtag, $$orderinfo{ordernumber});
249
                    }
250
                }
251
            }
252
            ModBiblio($record, $$orderinfo{biblionumber}, 'ACQ');
253
	}
254
255
208
    }
256
    }
209
257
210
    # now, add items if applicable
258
    if ($record) {
211
    if (C4::Context->preference('AcqCreateItem') eq 'ordering') {
259
260
	# If we have to add order infos to the marc record
261
	if ($ordertag) {
262
263
	    # If the order was made on an existing biblio and it is not a modification, we add the field 
264
	    $record->insert_fields_ordered(new MARC::Field($ordertag, '', '', $ordersubtag => $$orderinfo{ordernumber})) if (!$ordermodif && $existingbiblio);
265
266
	    foreach ($record->field($ordertag)) {
267
		# Looking for the matching one
268
		if ($_->subfield($ordersubtag) eq $$orderinfo{ordernumber}) {
269
270
		    # Replacing or creating subfields
271
		    my ($t, $st);
272
		    for my $tablefield (qw/branchcode quantity listprice uncertainprice rrp ecost notes supplierreference sort1 sort2/) {
273
			($t, $st) = GetMarcFromKohaField("aqorders.$tablefield", 'ACQ');
274
			$_->update($st, $$orderinfo{$tablefield}) if ($$orderinfo{$tablefield} and $st);
275
		    }
276
		    ModBiblio($record, $$orderinfo{biblionumber}, 'ACQ');
277
		}
278
	    }
279
280
	}
281
282
    }
283
284
285
      # now, add items if applicable
286
    if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) {
212
287
213
        my @tags         = $input->param('tag');
288
        my @tags         = $input->param('tag');
214
        my @subfields    = $input->param('subfield');
289
        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 122-127 if ( $op eq 'add_form' ) { Link Here
122
    while ( ( my $field ) = $sth2->fetchrow_array ) {
122
    while ( ( my $field ) = $sth2->fetchrow_array ) {
123
        push @kohafields, "items." . $field;
123
        push @kohafields, "items." . $field;
124
    }
124
    }
125
    $sth2 = $dbh->prepare("SHOW COLUMNS from aqorders");
126
    $sth2->execute;
127
    while ( ( my $field ) = $sth2->fetchrow_array ) {
128
        push @kohafields, "aqorders." . $field;
129
    }
130
125
131
126
    # build authorised value list
132
    # build authorised value list
127
    $sth2->finish;
133
    $sth2->finish;
(-)a/installer/data/mysql/kohastructure.sql (+1 lines)
Lines 2805-2810 CREATE TABLE `aqorders` ( -- information related to the basket line items Link Here
2805
  `claims_count` int(11) default 0, -- count of claim letters generated
2805
  `claims_count` int(11) default 0, -- count of claim letters generated
2806
  `claimed_date` date default NULL, -- last date a claim was generated
2806
  `claimed_date` date default NULL, -- last date a claim was generated
2807
  parent_ordernumber int(11) default NULL, -- ordernumber of parent order line, or same as ordernumber if no parent
2807
  parent_ordernumber int(11) default NULL, -- ordernumber of parent order line, or same as ordernumber if no parent
2808
  `branchcode` varchar(10) default NULL,
2808
  PRIMARY KEY  (`ordernumber`),
2809
  PRIMARY KEY  (`ordernumber`),
2809
  KEY `basketno` (`basketno`),
2810
  KEY `basketno` (`basketno`),
2810
  KEY `biblionumber` (`biblionumber`),
2811
  KEY `biblionumber` (`biblionumber`),
(-)a/installer/data/mysql/updatedatabase.pl (+9 lines)
Lines 5805-5810 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { Link Here
5805
    $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
    $dbh->do("INSERT INTO systempreferences (variable,value,explanation,options,type) VALUES('AllowReturnToBranch', '$prefvalue', 'Where an item may be returned', 'anywhere|homebranch|holdingbranch|homeorholdingbranch', 'Choice');");
5806
5806
5807
    print "Upgrade to $DBversion done: adding AllowReturnToBranch syspref (bug 6151)";
5807
    print "Upgrade to $DBversion done: adding AllowReturnToBranch syspref (bug 6151)";
5808
}
5809
5810
$DBversion = "3.09.00.XXX";
5811
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
5812
    $dbh->do("ALTER TABLE `aqorders` ADD `branchcode` VARCHAR( 10 ) NULL");
5813
    print "Upgrade to $DBversion done (Adding branchcode in aqorders)\n";
5808
    SetVersion($DBversion);
5814
    SetVersion($DBversion);
5809
}
5815
}
5810
5816
Lines 6182-6187 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
6182
}
6188
}
6183
6189
6184
=head1 FUNCTIONS
6190
=head1 FUNCTIONS
6191
=======
6192
6193
=item DropAllForeignKeys($table)
6185
6194
6186
=head2 TableExists($table)
6195
=head2 TableExists($table)
6187
6196
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt (-1 / +22 lines)
Lines 327-332 $(document).ready(function() Link Here
327
        </ol>
327
        </ol>
328
    </fieldset>
328
    </fieldset>
329
329
330
    <!-- Acquisition details -->
331
    <fieldset class="rows">
332
        <legend>Acquisition details</legend>
333
	<ol>
334
	<li>
335
	    <label for="branchcode">Branch: </label>
336
	    <select name="branchcode" id="branchcode">
337
                    <option value=""></option>
338
                [% FOREACH branch_loo IN branchloop %]
339
                    [% IF (branch_loo.selected) %]
340
                        <option value="[% branch_loo.value %]" selected="selected">[% branch_loo.branchname %]</option>
341
                    [% ELSE %]
342
                        <option value="[% branch_loo.value %]">[% branch_loo.branchname %]</option>
343
                    [% END %]
344
                [% END %]
345
	    </select>
346
	</li>
347
	</ol>
348
    </fieldset>	
349
350
351
330
    [% IF ( suggestionid ) %]
352
    [% IF ( suggestionid ) %]
331
        <fieldset class="rows">
353
        <fieldset class="rows">
332
        <legend>Suggestion</legend>
354
        <legend>Suggestion</legend>
333
- 

Return to bug 7294