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 383-393 if ( $op eq "add" ) { Link Here
383
    
548
    
384
    printbasketgrouppdf($basketgroupid);
549
    printbasketgrouppdf($basketgroupid);
385
    exit;
550
    exit;
551
} elsif ( $op eq 'closeandmail') {
552
    my $basketgroupid = $input->param('basketgroupid');
553
    
554
    CloseBasketgroup($basketgroupid);
555
    
556
    mailbasketgroup($basketgroupid);
557
558
    print $input->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid);
386
}elsif ($op eq 'print'){
559
}elsif ($op eq 'print'){
387
    my $basketgroupid = $input->param('basketgroupid');
560
    my $basketgroupid = $input->param('basketgroupid');
388
    
561
    
389
    printbasketgrouppdf($basketgroupid);
562
    printbasketgrouppdf($basketgroupid);
390
    exit;
563
    exit;
564
}elsif ($op eq 'mail'){
565
    my $basketgroupid = $input->param('basketgroupid');
566
    
567
    mailbasketgroup($basketgroupid);
568
569
    print $input->redirect('/cgi-bin/koha/acqui/basketgroup.pl?booksellerid=' . $booksellerid);
391
}elsif( $op eq "delete"){
570
}elsif( $op eq "delete"){
392
    my $basketgroupid = $input->param('basketgroupid');
571
    my $basketgroupid = $input->param('basketgroupid');
393
    DelBasketgroup($basketgroupid);
572
    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/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/basketgroup.tt (+14 lines)
Lines 297-302 function submitForm(form) { Link Here
297
		        				<li>
297
		        				<li>
298
		        					<span class="yui-button yui-link-button">
298
		        					<span class="yui-button yui-link-button">
299
		        						<span class="first-child">
299
		        						<span class="first-child">
300
		        							<a href="/cgi-bin/koha/acqui/basketgroup.pl?op=closeandmail&amp;booksellerid=[% basketgroup.booksellerid %]&amp;basketgroupid=[% basketgroup.id %]" class="yui-button yui-link-button">Close & Send Email</a>
301
	        							</span>
302
        							</span>
303
       							</li>
304
		        				<li>
305
		        					<span class="yui-button yui-link-button">
306
		        						<span class="first-child">
300
		        							<a href="?op=add&amp;booksellerid=[% basketgroup.booksellerid %]&amp;basketgroupid=[% basketgroup.id %]" class="yui-button yui-link-button" >Edit</a>
307
		        							<a href="?op=add&amp;booksellerid=[% basketgroup.booksellerid %]&amp;basketgroupid=[% basketgroup.id %]" class="yui-button yui-link-button" >Edit</a>
301
	        							</span>
308
	        							</span>
302
        							</span>
309
        							</span>
Lines 333-338 function submitForm(form) { Link Here
333
	        								</span>
340
	        								</span>
334
        								</span>
341
        								</span>
335
			        				</li>
342
			        				</li>
343
								<li>
344
									<span class="yui-button yui-link-button">
345
										<span class="first-child">
346
											<a href="/cgi-bin/koha/acqui/basketgroup.pl?op=mail&amp;booksellerid=[% basketgroup.booksellerid %]&amp;basketgroupid=[% basketgroup.id %]" class="yui-button yui-link-button">Send Email</a>
347
										</span>
348
									</span>
349
								</li>
336
			        				<li>
350
			        				<li>
337
										<span class="yui-button yui-link-button">
351
										<span class="yui-button yui-link-button">
338
			        						<span class="first-child">
352
			        						<span class="first-child">
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/letter.tt (+5 lines)
Lines 210-215 $(document).ready(function() { Link Here
210
                                    [% ELSE %]
210
                                    [% ELSE %]
211
                                    <option value="reserves">Holds</option>
211
                                    <option value="reserves">Holds</option>
212
                                    [% END %]
212
                                    [% END %]
213
                                    [% IF ( orders ) %]
214
                                    <option value="orders" selected="selected">Orders</option>
215
                                    [% ELSE %]
216
                                    <option value="orders">Orders</option>
217
                                    [% END %]
213
                                    [% IF ( members ) %]
218
                                    [% IF ( members ) %]
214
                                    <option value="members" selected="selected">Members</option>
219
                                    <option value="members" selected="selected">Members</option>
215
                                    [% ELSE %]
220
                                    [% ELSE %]
(-)a/tools/letter.pl (+10 lines)
Lines 154-159 sub add_form { Link Here
154
    elsif ($module eq 'claimacquisition') {
154
    elsif ($module eq 'claimacquisition') {
155
        push @{$field_selection}, add_fields('aqbooksellers', 'aqorders');
155
        push @{$field_selection}, add_fields('aqbooksellers', 'aqorders');
156
    }
156
    }
157
    elsif ($module eq 'orders') {
158
        push @{$field_selection}, add_fields('aqbooksellers', 'aqorders', 'biblio', 'items');
159
        push @{$field_selection}, { value => q{}, text => '---ORDER ITEMS---' };
160
        push @{$field_selection}, { value => "orders.$_", text => "orders.$_" }
161
		foreach (qw/listprice quantity ecost quantityreceived author title volume seriestitle isbn publishercode/);
162
        push @{$field_selection}, { value => "orders.$_", text => "orders.$_" }
163
		foreach (qw/full_title itemtype quantity_ecost basketno/);
164
        push @{$field_selection}, { value => "orders.total.$_", text => "orders.total.$_" }
165
		foreach (qw/quantity gstrate currency discount ecost_gste ecost_gsti gstrate/);
166
    }
157
    elsif ($module eq 'claimissues') {
167
    elsif ($module eq 'claimissues') {
158
        push @{$field_selection}, add_fields('aqbooksellers', 'serial', 'subscription');
168
        push @{$field_selection}, add_fields('aqbooksellers', 'serial', 'subscription');
159
        push @{$field_selection},
169
        push @{$field_selection},

Return to bug 5260