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

(-)a/C4/Acquisition.pm (-3 / +85 lines)
Lines 1124-1129 sub ModReceiveOrder { Link Here
1124
    my $order = $sth->fetchrow_hashref();
1124
    my $order = $sth->fetchrow_hashref();
1125
    $sth->finish();
1125
    $sth->finish();
1126
1126
1127
1128
    # If there are still items to be received
1127
    if ( $order->{quantity} > $quantrec ) {
1129
    if ( $order->{quantity} > $quantrec ) {
1128
        $sth=$dbh->prepare("
1130
        $sth=$dbh->prepare("
1129
            UPDATE aqorders
1131
            UPDATE aqorders
Lines 1145-1159 sub ModReceiveOrder { Link Here
1145
        }
1147
        }
1146
        $order->{'quantity'} -= $quantrec;
1148
        $order->{'quantity'} -= $quantrec;
1147
        $order->{'quantityreceived'} = 0;
1149
        $order->{'quantityreceived'} = 0;
1148
        my $newOrder = NewOrder($order);
1150
        my ($newOrder, $newordernumber) = NewOrder($order);
1149
} else {
1151
1150
        $sth=$dbh->prepare("update aqorders
1152
	# Do we have to update order informations from the marc record?
1153
	my ($ordertag, $ordersubtag) = GetMarcFromKohaField('aqorders.ordernumber', 'ACQ');
1154
1155
	# Updating MARC order field if exists
1156
	if ($ordertag and $ordersubtag) {
1157
	    $debug and warn "updating MARC";
1158
	    # Getting record
1159
	    my $record = GetMarcBiblio($biblionumber);
1160
	    if ($record) {
1161
		$debug and warn "updating Record";
1162
		foreach ($record->field($ordertag)) {
1163
		    if ($_->subfield($ordersubtag) eq $ordernumber) {
1164
		       # Updating ordernumber
1165
		       $debug and warn "updating ordernumber $ordernumber => $newordernumber";
1166
		       $_->update($ordersubtag => $newordernumber); 
1167
1168
		       # Updating quantity
1169
		       my ($quantitytag, $quantitysubtag) = GetMarcFromKohaField('aqorders.quantity', 'ACQ');
1170
		       if ($quantitysubtag) {
1171
			    $debug and warn "updating quantity " . $order->{quantity};
1172
			    $_->update($quantitysubtag => $order->{quantity});
1173
		       }
1174
		    }
1175
		}
1176
1177
		# Applying changes
1178
		ModBiblio($record, $biblionumber, 'ACQ'); 
1179
	    }	
1180
	}
1181
1182
1183
    } else {
1184
        $sth = $dbh->prepare(
1185
            "update aqorders
1151
                            set quantityreceived=?,datereceived=?,booksellerinvoicenumber=?,
1186
                            set quantityreceived=?,datereceived=?,booksellerinvoicenumber=?,
1152
                                unitprice=?,freight=?,rrp=?
1187
                                unitprice=?,freight=?,rrp=?
1153
                            where biblionumber=? and ordernumber=?");
1188
                            where biblionumber=? and ordernumber=?");
1154
        $sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$biblionumber,$ordernumber);
1189
        $sth->execute($quantrec,$datereceived,$invoiceno,$cost,$freight,$rrp,$biblionumber,$ordernumber);
1155
        $sth->finish;
1190
        $sth->finish;
1191
1192
	# Removing MARC order field if exists
1193
	DelMarcOrder($biblionumber, $ordernumber);
1156
    }
1194
    }
1195
1196
    
1157
    return $datereceived;
1197
    return $datereceived;
1158
}
1198
}
1159
#------------------------------------------------------------#
1199
#------------------------------------------------------------#
Lines 1253-1258 sub DelOrder { Link Here
1253
    my $sth = $dbh->prepare($query);
1293
    my $sth = $dbh->prepare($query);
1254
    $sth->execute( $bibnum, $ordernumber );
1294
    $sth->execute( $bibnum, $ordernumber );
1255
    $sth->finish;
1295
    $sth->finish;
1296
1297
    # Removing MARC order field if exists
1298
    DelMarcOrder($bibnum, $ordernumber);
1299
1256
    my @itemnumbers = GetItemnumbersFromOrder( $ordernumber );
1300
    my @itemnumbers = GetItemnumbersFromOrder( $ordernumber );
1257
    foreach my $itemnumber (@itemnumbers){
1301
    foreach my $itemnumber (@itemnumbers){
1258
    	C4::Items::DelItem( $dbh, $bibnum, $itemnumber );
1302
    	C4::Items::DelItem( $dbh, $bibnum, $itemnumber );
Lines 1260-1265 sub DelOrder { Link Here
1260
    
1304
    
1261
}
1305
}
1262
1306
1307
=head3 DelMarcOrder
1308
1309
=over 4
1310
1311
&DelMarcOrder($biblionumber, $ordernumber);
1312
1313
Delete the order field from the MARC record. aqorders.ordernumber needs
1314
to be linked to a MARC field/subfield. The field is deleted if the value of
1315
the subfield containing the ordernumber matches the ordernumber given
1316
in parameter
1317
1318
=back
1319
1320
=cut
1321
1322
sub DelMarcOrder {
1323
    my ($biblionumber, $ordernumber) = @_;
1324
1325
    # Do we have to remove order informations from the marc record?
1326
    my ($ordertag, $ordersubtag) = GetMarcFromKohaField('aqorders.ordernumber', 'ACQ');
1327
1328
    # Removing MARC order field if exists
1329
    if ($ordertag and $ordersubtag) {
1330
	# Getting record
1331
	my $record = GetMarcBiblio($biblionumber);
1332
	if ($record) {
1333
	    # Looking for the right field
1334
	    foreach ($record->field($ordertag)) {
1335
		if ($_->subfield($ordersubtag) eq $ordernumber) {
1336
		   $record->delete_field($_); 
1337
		}
1338
	    }
1339
	    # Applying changes
1340
	    ModBiblio($record, $biblionumber, 'ACQ'); 
1341
	}
1342
    }
1343
}
1344
1263
=head2 FUNCTIONS ABOUT PARCELS
1345
=head2 FUNCTIONS ABOUT PARCELS
1264
1346
1265
=cut
1347
=cut
(-)a/acqui/addorder.pl (-26 / +101 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
    my $supplierreference;
200
    if ($$orderinfo{booksellerid}) {
201
        my $bookseller = GetBookSellerFromId($$orderinfo{booksellerid});
202
        $supplierreference = $bookseller->{name};
203
    }
204
205
    # Do we have to add order informations to the marc record?
206
    my ($ordertag, $ordersubtag) = GetMarcFromKohaField('aqorders.ordernumber', 'ACQ'); 
207
    my $record;
208
    my $existingbiblio; # Was the order made on an existing biblio?
209
    my $ordermodif;     # Is this an order modification?
210
196
    #TODO:check to see if biblio exists
211
    #TODO:check to see if biblio exists
197
    unless ( $$orderinfo{biblionumber} ) {
212
    unless ( $$orderinfo{biblionumber} ) {
198
        #if it doesnt create it
213
        #if it doesnt create it
199
        my $record = TransformKohaToMarc(
214
        my $tmprecord = TransformKohaToMarc(
200
            {
215
            {   "biblio.title"                => "$$orderinfo{title}",
201
                "biblio.title"                => "$$orderinfo{title}",
216
                "biblio.author"               => $$orderinfo{author}          ? $$orderinfo{author}          : "",
202
                "biblio.author"               => $$orderinfo{author}          ? $$orderinfo{author}        : "",
217
                "biblio.seriestitle"          => $$orderinfo{series}          ? $$orderinfo{series}          : "",
203
                "biblio.seriestitle"          => $$orderinfo{series}          ? $$orderinfo{series}        : "",
218
                "biblio.copyrightdate"        => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear} : "",
204
                "biblioitems.isbn"            => $$orderinfo{isbn}            ? $$orderinfo{isbn}          : "",
219
                "biblioitems.isbn"            => $$orderinfo{isbn}            ? $$orderinfo{isbn}            : "",
205
                "biblioitems.publishercode"   => $$orderinfo{publishercode}   ? $$orderinfo{publishercode} : "",
220
                "biblioitems.ean"             => $$orderinfo{ean}             ? $$orderinfo{ean}             : "",
206
                "biblioitems.publicationyear" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear}: "",
221
                "biblioitems.publishercode"   => $$orderinfo{publishercode}   ? $$orderinfo{publishercode}   : "",
207
                "biblio.copyrightdate"        => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear}: "",
222
                "biblioitems.publicationyear" => $$orderinfo{publicationyear} ? $$orderinfo{publicationyear} : "",
208
                "biblioitems.itemtype"        => $$orderinfo{itemtype} ? $$orderinfo{itemtype} : "",
223
                "biblioitems.itemtype"        => $$orderinfo{itemtype}        ? $$orderinfo{itemtype}        : "",
209
                "biblioitems.editionstatement"=> $$orderinfo{editionstatement} ? $$orderinfo{editionstatement} : "",
224
                "biblioitems.editionstatement"=> $$orderinfo{editionstatement}? $$orderinfo{editionstatement}: "",
210
            });
225
                "aqorders.branchcode"         => $$orderinfo{branchcode}      ? $$orderinfo{branchcode}      : "",
226
                "aqorders.quantity"           => $$orderinfo{quantity}        ? $$orderinfo{quantity}        : "",
227
                "aqorders.listprice"          => $$orderinfo{listprice}       ? $$orderinfo{listprice}       : "",
228
                "aqorders.uncertainprice"     => $$orderinfo{uncertainprice}  ? $$orderinfo{uncertainprice}  : "",
229
                "aqorders.rrp"                => $$orderinfo{rrp}             ? $$orderinfo{rrp}             : "",
230
                "aqorders.ecost"              => $$orderinfo{ecost}           ? $$orderinfo{ecost}           : "",
231
                "aqorders.notes"              => $$orderinfo{notes}           ? $$orderinfo{notes}           : "",
232
                "aqorders.supplierreference"  => $supplierreference           ? $supplierreference           : "",
233
                "aqorders.sort1"              => $$orderinfo{sort1}           ? $$orderinfo{sort1}           : "",
234
                "aqorders.sort2"              => $$orderinfo{sort2}           ? $$orderinfo{sort2}           : ""
235
            }
236
        );
211
237
212
        # create the record in catalogue, with framework ''
238
        # create the record in catalogue, with framework ''
213
        my ($biblionumber,$bibitemnum) = AddBiblio($record,'');
239
        my ( $biblionumber, $bibitemnum ) = AddBiblio( $tmprecord, '' );
240
214
        # change suggestion status if applicable
241
        # change suggestion status if applicable
215
        if ($$orderinfo{suggestionid}) {
242
        if ($$orderinfo{suggestionid}) {
216
            ModSuggestion( {suggestionid=>$$orderinfo{suggestionid}, STATUS=>'ORDERED', biblionumber=>$biblionumber} );
243
            ModSuggestion( {suggestionid=>$$orderinfo{suggestionid}, STATUS=>'ORDERED', biblionumber=>$biblionumber} );
217
        }
244
        }
218
		$orderinfo->{biblioitemnumber}=$bibitemnum;
245
        $orderinfo->{biblioitemnumber} = $bibitemnum;
219
		$orderinfo->{biblionumber}=$biblionumber;
246
        $orderinfo->{biblionumber}     = $biblionumber;
247
    } else {
248
	$existingbiblio = 1;
220
    }
249
    }
221
250
222
    # if we already have $ordernumber, then it's an ordermodif
251
    # Getting record
223
    if ($$orderinfo{ordernumber}) {
252
    $record = GetMarcBiblio($$orderinfo{biblionumber});
224
        ModOrder( $orderinfo);
253
225
    }
254
    
226
    else { # else, it's a new line
255
256
     # if we already have $ordernumber, then it's an ordermodif
257
    if ( $$orderinfo{ordernumber} ) {
258
        ModOrder($orderinfo);
259
	$ordermodif = 1;
260
	
261
    } else {    # else, it's a new line
227
        @$orderinfo{qw(basketno ordernumber )} = NewOrder($orderinfo);
262
        @$orderinfo{qw(basketno ordernumber )} = NewOrder($orderinfo);
263
264
	# We have to add the ordernumber in the designated subfield
265
	if ($ordertag && $record && !$ordermodif) {
266
	    # To which field do we add it : to the one with currently no ordernumber
267
	    foreach ($record->field($ordertag)) {
268
		if (!$_->subfield($ordersubtag)) {
269
		    $_->update($ordersubtag, $$orderinfo{ordernumber});
270
		}
271
	    }
272
	    ModBiblio($record, $$orderinfo{biblionumber}, 'ACQ');
273
	}
274
275
276
    }
277
278
    if ($record) {
279
280
	# If we have to add order infos to the marc record
281
	if ($ordertag) {
282
283
	    # If the order was made on an existing biblio and it is not a modification, we add the field 
284
	    $record->insert_fields_ordered(new MARC::Field($ordertag, '', '', $ordersubtag => $$orderinfo{ordernumber})) if (!$ordermodif && $existingbiblio);
285
286
	    foreach ($record->field($ordertag)) {
287
		# Looking for the matching one
288
		if ($_->subfield($ordersubtag) eq $$orderinfo{ordernumber}) {
289
290
		    # Replacing or creating subfields
291
		    my ($t, $st);
292
		    for my $tablefield (qw/branchcode quantity listprice uncertainprice rrp ecost notes supplierreference sort1 sort2/) {
293
			($t, $st) = GetMarcFromKohaField("aqorders.$tablefield", 'ACQ');
294
			$_->update($st, $$orderinfo{$tablefield}) if ($$orderinfo{$tablefield} and $st);
295
		    }
296
		    ModBiblio($record, $$orderinfo{biblionumber}, 'ACQ');
297
		}
298
	    }
299
300
	}
301
228
    }
302
    }
229
303
230
    # now, add items if applicable
304
231
    if (C4::Context->preference('AcqCreateItem') eq 'ordering') {
305
      # now, add items if applicable
306
    if ( C4::Context->preference('AcqCreateItem') eq 'ordering' ) {
232
307
233
        my @tags         = $input->param('tag');
308
        my @tags         = $input->param('tag');
234
        my @subfields    = $input->param('subfield');
309
        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 2658-2663 CREATE TABLE `aqorders` ( Link Here
2658
  `uncertainprice` tinyint(1),
2658
  `uncertainprice` tinyint(1),
2659
  `claims_count` int(11) default 0,
2659
  `claims_count` int(11) default 0,
2660
  `claimed_date` date default NULL,
2660
  `claimed_date` date default NULL,
2661
  `branchcode` varchar(10) default NULL,
2661
  PRIMARY KEY  (`ordernumber`),
2662
  PRIMARY KEY  (`ordernumber`),
2662
  KEY `basketno` (`basketno`),
2663
  KEY `basketno` (`basketno`),
2663
  KEY `biblionumber` (`biblionumber`),
2664
  KEY `biblionumber` (`biblionumber`),
(-)a/installer/data/mysql/updatedatabase.pl (-1 / +21 lines)
Lines 4924-4930 if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) { Link Here
4924
}
4924
}
4925
4925
4926
4926
4927
4928
4929
4930
4931
$DBversion = "3.07.00.028";
4932
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
4933
    $dbh->do("ALTER TABLE `aqorders` ADD `branchcode` VARCHAR( 10 ) NULL");
4934
    print "Upgrade to $DBversion done (Adding branchcode in aqorders)\n";
4935
    SetVersion($DBversion);
4936
}
4937
4938
4939
4940
4941
4942
4943
4944
4927
=head1 FUNCTIONS
4945
=head1 FUNCTIONS
4946
=======
4947
4948
=item DropAllForeignKeys($table)
4928
4949
4929
=head2 DropAllForeignKeys($table)
4950
=head2 DropAllForeignKeys($table)
4930
4951
4931
- 

Return to bug 7294