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

(-)a/C4/Acquisition.pm (-3 / +85 lines)
Lines 1159-1164 sub ModReceiveOrder { Link Here
1159
    my $order = $sth->fetchrow_hashref();
1159
    my $order = $sth->fetchrow_hashref();
1160
    $sth->finish();
1160
    $sth->finish();
1161
1161
1162
1163
    # If there are still items to be received
1162
    if ( $order->{quantity} > $quantrec ) {
1164
    if ( $order->{quantity} > $quantrec ) {
1163
        $sth=$dbh->prepare("
1165
        $sth=$dbh->prepare("
1164
            UPDATE aqorders
1166
            UPDATE aqorders
Lines 1180-1194 sub ModReceiveOrder { Link Here
1180
        }
1182
        }
1181
        $order->{'quantity'} -= $quantrec;
1183
        $order->{'quantity'} -= $quantrec;
1182
        $order->{'quantityreceived'} = 0;
1184
        $order->{'quantityreceived'} = 0;
1183
        my $newOrder = NewOrder($order);
1185
        my ($newOrder, $newordernumber) = NewOrder($order);
1184
} else {
1186
1185
        $sth=$dbh->prepare("update aqorders
1187
	# Do we have to update order informations from the marc record?
1188
	my ($ordertag, $ordersubtag) = GetMarcFromKohaField('aqorders.ordernumber', 'ACQ');
1189
1190
	# Updating MARC order field if exists
1191
	if ($ordertag and $ordersubtag) {
1192
	    $debug and warn "updating MARC";
1193
	    # Getting record
1194
	    my $record = GetMarcBiblio($biblionumber);
1195
	    if ($record) {
1196
		$debug and warn "updating Record";
1197
		foreach ($record->field($ordertag)) {
1198
		    if ($_->subfield($ordersubtag) eq $ordernumber) {
1199
		       # Updating ordernumber
1200
		       $debug and warn "updating ordernumber $ordernumber => $newordernumber";
1201
		       $_->update($ordersubtag => $newordernumber); 
1202
1203
		       # Updating quantity
1204
		       my ($quantitytag, $quantitysubtag) = GetMarcFromKohaField('aqorders.quantity', 'ACQ');
1205
		       if ($quantitysubtag) {
1206
			    $debug and warn "updating quantity " . $order->{quantity};
1207
			    $_->update($quantitysubtag => $order->{quantity});
1208
		       }
1209
		    }
1210
		}
1211
1212
		# Applying changes
1213
		ModBiblio($record, $biblionumber, 'ACQ'); 
1214
	    }	
1215
	}
1216
1217
1218
    } else {
1219
        $sth = $dbh->prepare(
1220
            "update aqorders
1186
                            set quantityreceived=?,datereceived=?,booksellerinvoicenumber=?,
1221
                            set quantityreceived=?,datereceived=?,booksellerinvoicenumber=?,
1187
                                unitprice=?,freight=?,rrp=?
1222
                                unitprice=?,freight=?,rrp=?
1188
                            where biblionumber=? and ordernumber=?");
1223
                            where biblionumber=? and ordernumber=?");
1189
        $sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$biblionumber,$ordernumber);
1224
        $sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$biblionumber,$ordernumber);
1190
        $sth->finish;
1225
        $sth->finish;
1226
1227
	# Removing MARC order field if exists
1228
	DelMarcOrder($biblionumber, $ordernumber);
1191
    }
1229
    }
1230
1231
    
1192
    return $datereceived;
1232
    return $datereceived;
1193
}
1233
}
1194
#------------------------------------------------------------#
1234
#------------------------------------------------------------#
Lines 1288-1293 sub DelOrder { Link Here
1288
    my $sth = $dbh->prepare($query);
1328
    my $sth = $dbh->prepare($query);
1289
    $sth->execute( $bibnum, $ordernumber );
1329
    $sth->execute( $bibnum, $ordernumber );
1290
    $sth->finish;
1330
    $sth->finish;
1331
1332
    # Removing MARC order field if exists
1333
    DelMarcOrder($bibnum, $ordernumber);
1334
1291
    my @itemnumbers = GetItemnumbersFromOrder( $ordernumber );
1335
    my @itemnumbers = GetItemnumbersFromOrder( $ordernumber );
1292
    foreach my $itemnumber (@itemnumbers){
1336
    foreach my $itemnumber (@itemnumbers){
1293
    	C4::Items::DelItem( $dbh, $bibnum, $itemnumber );
1337
    	C4::Items::DelItem( $dbh, $bibnum, $itemnumber );
Lines 1295-1300 sub DelOrder { Link Here
1295
    
1339
    
1296
}
1340
}
1297
1341
1342
=head3 DelMarcOrder
1343
1344
=over 4
1345
1346
&DelMarcOrder($biblionumber, $ordernumber);
1347
1348
Delete the order field from the MARC record. aqorders.ordernumber needs
1349
to be linked to a MARC field/subfield. The field is deleted if the value of
1350
the subfield containing the ordernumber matches the ordernumber given
1351
in parameter
1352
1353
=back
1354
1355
=cut
1356
1357
sub DelMarcOrder {
1358
    my ($biblionumber, $ordernumber) = @_;
1359
1360
    # Do we have to remove order informations from the marc record?
1361
    my ($ordertag, $ordersubtag) = GetMarcFromKohaField('aqorders.ordernumber', 'ACQ');
1362
1363
    # Removing MARC order field if exists
1364
    if ($ordertag and $ordersubtag) {
1365
	# Getting record
1366
	my $record = GetMarcBiblio($biblionumber);
1367
	if ($record) {
1368
	    # Looking for the right field
1369
	    foreach ($record->field($ordertag)) {
1370
		if ($_->subfield($ordersubtag) eq $ordernumber) {
1371
		   $record->delete_field($_); 
1372
		}
1373
	    }
1374
	    # Applying changes
1375
	    ModBiblio($record, $biblionumber, 'ACQ'); 
1376
	}
1377
    }
1378
}
1379
1298
=head2 FUNCTIONS ABOUT PARCELS
1380
=head2 FUNCTIONS ABOUT PARCELS
1299
1381
1300
=cut
1382
=cut
(-)a/acqui/addorder.pl (-26 / +100 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-234 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.publishercode"   => $$orderinfo{publishercode}   ? $$orderinfo{publishercode} : "",
219
                "biblioitems.ean"             => $$orderinfo{ean}             ? $$orderinfo{ean}             : "",
206
                "biblioitems.publicationyear" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear}: "",
220
                "biblioitems.publishercode"   => $$orderinfo{publishercode}   ? $$orderinfo{publishercode}   : "",
207
                "biblio.copyrightdate"        => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear}: "",
221
                "biblioitems.publicationyear" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear} : "",
208
                "biblioitems.itemtype"        => $$orderinfo{itemtype} ? $$orderinfo{itemtype} : "",
222
                "biblioitems.itemtype"        => $$orderinfo{itemtype}        ? $$orderinfo{itemtype}        : "",
209
                "biblioitems.editionstatement"=> $$orderinfo{editionstatement} ? $$orderinfo{editionstatement} : "",
223
                "biblioitems.editionstatement"=> $$orderinfo{editionstatement}? $$orderinfo{editionstatement}: "",
210
            });
224
                "aqorders.branchcode"         => $$orderinfo{branchcode}      ? $$orderinfo{branchcode}      : "",
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
        );
211
236
212
        # create the record in catalogue, with framework ''
237
        # create the record in catalogue, with framework ''
213
        my ($biblionumber,$bibitemnum) = AddBiblio($record,'');
238
        my ( $biblionumber, $bibitemnum ) = AddBiblio( $tmprecord, '' );
239
214
        # change suggestion status if applicable
240
        # change suggestion status if applicable
215
        if ($$orderinfo{suggestionid}) {
241
        if ($$orderinfo{suggestionid}) {
216
            ModSuggestion( {suggestionid=>$$orderinfo{suggestionid}, STATUS=>'ORDERED', biblionumber=>$biblionumber} );
242
            ModSuggestion( {suggestionid=>$$orderinfo{suggestionid}, STATUS=>'ORDERED', biblionumber=>$biblionumber} );
217
        }
243
        }
218
		$orderinfo->{biblioitemnumber}=$bibitemnum;
244
        $orderinfo->{biblioitemnumber} = $bibitemnum;
219
		$orderinfo->{biblionumber}=$biblionumber;
245
        $orderinfo->{biblionumber}     = $biblionumber;
246
    } else {
247
	$existingbiblio = 1;
220
    }
248
    }
221
249
222
    # if we already have $ordernumber, then it's an ordermodif
250
    # Getting record
223
    if ($$orderinfo{ordernumber}) {
251
    $record = GetMarcBiblio($$orderinfo{biblionumber});
224
        ModOrder( $orderinfo);
252
225
    }
253
    
226
    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
227
        @$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
	    # To which field do we add it : to the one with currently no ordernumber
266
	    foreach ($record->field($ordertag)) {
267
		if (!$_->subfield($ordersubtag)) {
268
		    $_->update($ordersubtag, $$orderinfo{ordernumber});
269
		}
270
	    }
271
	    ModBiblio($record, $$orderinfo{biblionumber}, 'ACQ');
272
	}
273
274
275
    }
276
277
    if ($record) {
278
279
	# If we have to add order infos to the marc record
280
	if ($ordertag) {
281
282
	    # If the order was made on an existing biblio and it is not a modification, we add the field 
283
	    $record->insert_fields_ordered(new MARC::Field($ordertag, '', '', $ordersubtag => $$orderinfo{ordernumber})) if (!$ordermodif && $existingbiblio);
284
285
	    foreach ($record->field($ordertag)) {
286
		# Looking for the matching one
287
		if ($_->subfield($ordersubtag) eq $$orderinfo{ordernumber}) {
288
289
		    # Replacing or creating subfields
290
		    my ($t, $st);
291
		    for my $tablefield (qw/branchcode quantity listprice uncertainprice rrp ecost notes supplierreference sort1 sort2/) {
292
			($t, $st) = GetMarcFromKohaField("aqorders.$tablefield", 'ACQ');
293
			$_->update($st, $$orderinfo{$tablefield}) if ($$orderinfo{$tablefield} and $st);
294
		    }
295
		    ModBiblio($record, $$orderinfo{biblionumber}, 'ACQ');
296
		}
297
	    }
298
299
	}
300
228
    }
301
    }
229
302
230
    # now, add items if applicable
303
231
    if (C4::Context->preference('AcqCreateItem') eq 'ordering') {
304
      # now, add items if applicable
305
    if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) {
232
306
233
        my @tags         = $input->param('tag');
307
        my @tags         = $input->param('tag');
234
        my @subfields    = $input->param('subfield');
308
        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 2742-2747 CREATE TABLE `aqorders` ( Link Here
2742
  `uncertainprice` tinyint(1),
2742
  `uncertainprice` tinyint(1),
2743
  `claims_count` int(11) default 0,
2743
  `claims_count` int(11) default 0,
2744
  `claimed_date` date default NULL,
2744
  `claimed_date` date default NULL,
2745
  `branchcode` varchar(10) default NULL,
2745
  PRIMARY KEY  (`ordernumber`),
2746
  PRIMARY KEY  (`ordernumber`),
2746
  KEY `basketno` (`basketno`),
2747
  KEY `basketno` (`basketno`),
2747
  KEY `biblionumber` (`biblionumber`),
2748
  KEY `biblionumber` (`biblionumber`),
(-)a/installer/data/mysql/updatedatabase.pl (+21 lines)
Lines 5146-5152 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { Link Here
5146
    SetVersion($DBversion);
5146
    SetVersion($DBversion);
5147
}
5147
}
5148
5148
5149
5150
5151
5152
5153
$DBversion = "3.07.00.028";
5154
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
5155
    $dbh->do("ALTER TABLE `aqorders` ADD `branchcode` VARCHAR( 10 ) NULL");
5156
    print "Upgrade to $DBversion done (Adding branchcode in aqorders)\n";
5157
    SetVersion($DBversion);
5158
}
5159
5160
5161
5162
5163
5164
5165
5166
5149
=head1 FUNCTIONS
5167
=head1 FUNCTIONS
5168
=======
5169
5170
=item DropAllForeignKeys($table)
5150
5171
5151
=head2 DropAllForeignKeys($table)
5172
=head2 DropAllForeignKeys($table)
5152
5173
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt (-1 / +17 lines)
Lines 313-318 $(document).ready(function() Link Here
313
        </ol>
313
        </ol>
314
    </fieldset>
314
    </fieldset>
315
315
316
    <!-- Acquisition details -->
317
    <fieldset class="rows">
318
        <legend>Acquisition details</legend>
319
	<ol>
320
	<li>
321
	    <label for="branchcode">Branch: </label>
322
	    <select name="branchcode" id="branchcode">
323
                [% FOREACH branch_loo IN branchloop %]
324
		    <option value="[% branch_loo.value %]" [% IF (branch_loo.selected) %]selected="selected" [% END %]>[% branch_loo.branchname %]</option>
325
                [% END %]
326
	    </select>
327
	</li>
328
	</ol>
329
    </fieldset>	
330
331
332
316
    [% IF ( suggestionid ) %]
333
    [% IF ( suggestionid ) %]
317
        <fieldset class="rows">
334
        <fieldset class="rows">
318
        <legend>Suggestion</legend>
335
        <legend>Suggestion</legend>
319
- 

Return to bug 7294