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

(-)a/acqui/basketgroup.pl (+179 lines)
Lines 248-253 sub printbasketgrouppdf{ Link Here
248
    print $pdf;
248
    print $pdf;
249
}
249
}
250
250
251
sub order_mail {
252
#use Data::Dumper;
253
	my ($booksellerid, $mail_orders) = @_;
254
#print "order_mail\n";
255
#print "booksellerid: $booksellerid\n", "mail_orders: ", Dumper($mail_orders);
256
	my $mail_order_total = shift @$mail_orders;
257
258
	my $bookseller = GetBookSellerFromId($booksellerid);
259
260
	my $letter = C4::Letters::getletter('orders', 'ORDERMAIL') || return;
261
#print "letter: ",  Dumper(\$letter);
262
263
	eval "use Mail::Sendmail";
264
	eval "use C4::Log";
265
	eval "use Carp";
266
	eval "use Encode";
267
268
	# branch info
269
	my $userenv = C4::Context->userenv;
270
	C4::Letters::parseletter($letter, 'branches', $userenv->{branch});
271
272
	# librarian name
273
	$letter->{content} =~ s/<<LibrarianFirstname>>/$userenv->{firstname}/g;
274
	$letter->{content} =~ s/<<LibrarianSurname>>/$userenv->{surname}/g;
275
	$letter->{content} =~ s/<<LibrarianEmailaddress>>/$userenv->{emailaddress}/g;
276
277
	# booksellers
278
	C4::Letters::parseletter($letter, 'aqbooksellers', $booksellerid);
279
280
	# items and total
281
	return unless $letter->{'content'} =~ m/(<item>(.*)<\/item>)/sm;
282
	my $item_place = $1; my $item_format = $2;
283
	my ($total_place, $total_format);
284
	if ($letter->{'content'} =~ m/(<total>(.*)<\/total>)/sm) {
285
		$total_place = $1; $total_format = $2;
286
	}
287
288
	my @items;
289
	foreach my $mail_order (@$mail_orders) {
290
		my $item = $item_format;
291
		while (my ($key, $value) = each %$mail_order) {
292
#print "$key: $value\n";
293
			$item =~ s/<<orders.$key>>/$value/g;
294
		}
295
		push @items, $item;
296
	}
297
#print "items: ", Dumper(@items);
298
	$letter->{'content'} =~ s/\Q$item_place\E/join "\n",@items/e;
299
	if ($total_format) {
300
#print "total_place: $total_place\n";
301
#print "total_format: $total_format\n";
302
		my $total = $total_format;
303
		while (my ($key, $value) = each %$mail_order_total) {
304
			$total =~ s/<<orders.total.$key>>/$value/g;
305
		}
306
#print "total: $total\n";
307
		$letter->{'content'} =~ s/\Q$total_place\E/$total/;
308
	}
309
	my %mail = (
310
		To => $bookseller->{bookselleremail} ||
311
			$bookseller->{contemail} ||
312
			$userenv->{emailaddress},
313
		From => $userenv->{emailaddress},
314
		Subject => $letter->{title},
315
		Message => Encode::encode("UTF-8", $letter->{content}),
316
		'Content-Type' => 'text/plain; charset="utf8"',
317
	);
318
#print "mail: ", Dumper(\%mail);
319
	sendmail(%mail) or carp $Mail::Sendmail::error;
320
	logaction(
321
		"ORDER",
322
		"Send email order",
323
		undef,
324
		"To=%mail{To}\nSubject=%mail{Subject}\nMessage=%mail{Message}"
325
	) if C4::Context->preference("LetterLog");
326
}
327
328
sub mailbasketgroup {
329
	my ($basketgroupid) = @_;
330
    
331
	eval "use C4::Branch";
332
	eval "use C4::Biblio";
333
	eval "use C4::Koha";
334
	eval "use Number::Format qw(format_number format_price)";
335
336
	my $num = FormatNumber; # C4::Output
337
338
	my $itemtypes = GetItemTypes();
339
    
340
	my $basketgroup = GetBasketgroup($basketgroupid);
341
	my $booksellerid = $basketgroup->{booksellerid};
342
	my $bookseller = GetBookSellerFromId($booksellerid);
343
	my $baskets = GetBasketsByBasketgroup($basketgroupid);
344
345
	my $gstrate = $bookseller->{gstrate} || C4::Context->preference("gist") || 0;
346
	my $discount = $bookseller->{'discount'} / 100;
347
348
	my $total_ecost;	# Total, its value will be assigned to $total_ecost_gsti or $total_ecost_gste depending of $bookseller->{'listincgst'}
349
	my $total_ecost_gsti;	# Total, GST included
350
	my $total_ecost_gste;	# Total, GST excluded
351
	my $total_quantity;	# Total quantity
352
353
	my @mail_orders;
354
	for my $basket (@$baskets) {
355
		my $basketno = $basket->{basketno};
356
		my @orders = &GetOrders($basketno);
357
		for my $order (@orders) {
358
			my %mail_order;
359
360
			my $quantity = $order->{quantity} || 0;
361
			next if $quantity <= 0;
362
			my $ecost = $order->{ecost} || 0;
363
364
			for (qw(quantity quantityreceived author title volume seriestitle isbn publishercode)) {
365
				$mail_order{$_} = $order->{$_} if defined $order->{$_};
366
			}
367
			for (qw(listprice ecost)) {
368
				$mail_order{$_} = $num->format_price($order->{$_}) if defined $order->{$_};
369
			}
370
			my $full_title = $order->{title};
371
			$full_title .= (" " . $order->{seriestitle}) if $order->{seriestitle};
372
			$full_title .= (" " . $order->{volume}) if $order->{volume};
373
			$mail_order{full_title} = $full_title;
374
			if ($order->{biblionumber}) {
375
				my $bibliodata = GetBiblioData($order->{biblionumber});
376
				if ($bibliodata->{itemtype}) {
377
					$mail_order{itemtype} = $itemtypes->{$bibliodata->{itemtype}}->{description};
378
				}
379
			}
380
381
			my $quantity_ecost = $quantity * $ecost;
382
			$mail_order{quantity_ecost} = $num->format_price($quantity_ecost);
383
			$mail_order{basketno} = $basketno;
384
			$total_ecost += $quantity_ecost;
385
			$total_quantity += $quantity;
386
			push @mail_orders, \%mail_order;
387
		}
388
	}
389
390
	my %total;
391
	$total{quantity} = $total_quantity;
392
	$total{gstrate} = $num->format_number($gstrate);
393
	$total{currency} = $bookseller->{listprice};
394
	$total{discount} = $num->format_number($bookseller->{discount});
395
396
	my $total_gist;
397
398
	if ($bookseller->{listincgst}) { # prices already includes GST
399
		$total_ecost_gsti = $total_ecost;
400
		$total_ecost_gste = $total_ecost_gsti / ($gstrate + 1);
401
		$total_gist       = $total_ecost_gsti - $total_ecost_gste;
402
	} else { # prices does not include GST
403
		$total_ecost_gste = $total_ecost;
404
		$total_gist = $total_ecost_gste * $gstrate;
405
		$total_ecost_gsti = $total_ecost_gste + $total_gist;
406
	}
407
	$total{ecost_gste} = $num->format_price($total_ecost_gste);
408
	$total{ecost_gsti} = $num->format_price($total_ecost_gsti);
409
	$total{gist} = $num->format_number($total_gist);
410
411
	unshift @mail_orders, \%total;
412
	
413
	order_mail($booksellerid, \@mail_orders);
414
}
415
251
my $op = $input->param('op');
416
my $op = $input->param('op');
252
my $booksellerid = $input->param('booksellerid');
417
my $booksellerid = $input->param('booksellerid');
253
$template->param(booksellerid => $booksellerid);
418
$template->param(booksellerid => $booksellerid);
Lines 387-397 if ( $op eq "add" ) { Link Here
387
    
552
    
388
    printbasketgrouppdf($basketgroupid);
553
    printbasketgrouppdf($basketgroupid);
389
    exit;
554
    exit;
555
} elsif ( $op eq 'closeandmail') {
556
    my $basketgroupid = $input->param('basketgroupid');
557
    
558
    CloseBasketgroup($basketgroupid);
559
    
560
    mailbasketgroup($basketgroupid);
561
562
    print $input->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid);
390
}elsif ($op eq 'print'){
563
}elsif ($op eq 'print'){
391
    my $basketgroupid = $input->param('basketgroupid');
564
    my $basketgroupid = $input->param('basketgroupid');
392
    
565
    
393
    printbasketgrouppdf($basketgroupid);
566
    printbasketgrouppdf($basketgroupid);
394
    exit;
567
    exit;
568
}elsif ($op eq 'mail'){
569
    my $basketgroupid = $input->param('basketgroupid');
570
    
571
    mailbasketgroup($basketgroupid);
572
573
    print $input->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid);
395
}elsif( $op eq "delete"){
574
}elsif( $op eq "delete"){
396
    my $basketgroupid = $input->param('basketgroupid');
575
    my $basketgroupid = $input->param('basketgroupid');
397
    DelBasketgroup($basketgroupid);
576
    DelBasketgroup($basketgroupid);
(-)a/koha-tmpl/intranet-tmpl/prog/en/js/acq.js (+8 lines)
Lines 388-393 function closeandprint(bg){ Link Here
388
	}
388
	}
389
}
389
}
390
390
391
function closeandmail(bs, bg){
392
	if(document.location = '/cgi-bin/koha/acqui/basketgroup.pl?op=closeandmail&amp;booksellerid=' + bs + '&amp;basketgroupid=' + bg ){
393
		setTimeout("window.location.reload();",3000);
394
	}else{
395
		alert('Error downloading the file');
396
	}
397
}
398
391
//function that lets the user unclose a basketgroup as long as he hasn't submitted the changes to the page.
399
//function that lets the user unclose a basketgroup as long as he hasn't submitted the changes to the page.
392
function unclosegroup(bgid){
400
function unclosegroup(bgid){
393
    var div = document.getElementById('basketgroup-'+bgid+'-closed').parentNode;
401
    var div = document.getElementById('basketgroup-'+bgid+'-closed').parentNode;
(-)a/tools/letter.pl (-1 / +33 lines)
Lines 147-152 sub add_form { Link Here
147
    }
147
    }
148
148
149
    my $field_selection;
149
    my $field_selection;
150
    if ( $module eq "suggestions" ) {
151
        push @SQLfieldname, column_picks('borrowers'),
152
                            column_picks('suggestions'),
153
                            column_picks('aqbooksellers'),
154
                            column_picks('biblio'),
155
                            column_picks('items');
156
	}
157
    elsif ( $module eq "reserves" ) {
158
        push @SQLfieldname, column_picks('borrowers'),
159
                            column_picks('reserves'),
160
                            column_picks('biblio'),
161
                            column_picks('items');
162
    }
163
    elsif ( $module eq "orders" ) {
164
        push @SQLfieldname, column_picks('aqbooksellers'),
165
                            column_picks('aqorders'),
166
                            column_picks('biblio'),
167
                            column_picks('items');
168
    }
169
    elsif ( index( $module, "acquisition" ) > 0 ) {	# FIXME: imprecise comparison
170
        push @SQLfieldname, column_picks('aqbooksellers'), column_picks('aqorders');
171
        # add issues specific tables
172
    }
150
    push @{$field_selection}, add_fields('branches');
173
    push @{$field_selection}, add_fields('branches');
151
    if ($module eq 'reserves') {
174
    if ($module eq 'reserves') {
152
        push @{$field_selection}, add_fields('borrowers', 'reserves', 'biblio', 'items');
175
        push @{$field_selection}, add_fields('borrowers', 'reserves', 'biblio', 'items');
Lines 154-159 sub add_form { Link Here
154
    elsif ($module eq 'claimacquisition') {
177
    elsif ($module eq 'claimacquisition') {
155
        push @{$field_selection}, add_fields('aqbooksellers', 'aqorders');
178
        push @{$field_selection}, add_fields('aqbooksellers', 'aqorders');
156
    }
179
    }
180
    elsif ($module eq 'orders') {
181
        push @{$field_selection}, add_fields('aqbooksellers', 'aqorders', 'biblio', 'items');
182
        push @{$field_selection}, { value => q{}, text => '---ORDER ITEMS---' };
183
        push @{$field_selection}, { value => "orders.$_", text => "orders.$_" }
184
		foreach (qw/listprice quantity ecost quantityreceived author title volume seriestitle isbn publishercode/);
185
        push @{$field_selection}, { value => "orders.$_", text => "orders.$_" }
186
		foreach (qw/full_title itemtype quantity_ecost basketno/);
187
        push @{$field_selection}, { value => "orders.total.$_", text => "orders.total.$_" }
188
		foreach (qw/quantity gstrate currency discount ecost_gste ecost_gsti gstrate/);
189
    }
157
    elsif ($module eq 'claimissues') {
190
    elsif ($module eq 'claimissues') {
158
        push @{$field_selection}, add_fields('aqbooksellers', 'serial', 'subscription');
191
        push @{$field_selection}, add_fields('aqbooksellers', 'serial', 'subscription');
159
        push @{$field_selection},
192
        push @{$field_selection},
160
- 

Return to bug 5260