smart-rules : clonerules enhancement
[koha.git] / serials / claims.pl
blob6d9f172ac906afeab997b91844ffaa0910d4d88b
1 #!/usr/bin/perl
3 use strict;
4 use warnings;
5 use CGI;
6 use C4::Auth;
7 use C4::Serials;
8 use C4::Acquisition;
9 use C4::Output;
10 use C4::Bookseller;
11 use C4::Context;
12 use C4::Letters;
13 my $input = new CGI;
15 my $serialid = $input->param('serialid');
16 my $op = $input->param('op');
17 my $claimletter = $input->param('claimletter');
18 my $supplierid = $input->param('supplierid');
19 my $suppliername = $input->param('suppliername');
20 my $order = $input->param('order');
21 my %supplierlist = GetSuppliersWithLateIssues;
22 my @select_supplier;
24 # open template first (security & userenv set here)
25 my ($template, $loggedinuser, $cookie)
26 = get_template_and_user({template_name => "serials/claims.tmpl",
27 query => $input,
28 type => "intranet",
29 authnotrequired => 0,
30 flagsrequired => {serials => 1},
31 debug => 1,
32 });
33 foreach my $supplierid (sort {$supplierlist{$a} cmp $supplierlist{$b} } keys %supplierlist){
34 my ($count, @dummy) = GetLateOrMissingIssues($supplierid,"",$order);
35 my $counting = $count;
36 $supplierlist{$supplierid} = $supplierlist{$supplierid}." ($counting)";
37 push @select_supplier, $supplierid
39 my $letters = GetLetters("claimissues");
40 my @letters;
41 foreach (keys %$letters){
42 push @letters ,{code=>$_,name=> $letters->{$_}};
45 my $letter=((scalar(@letters)>1) || ($letters[0]->{name}||$letters[0]->{code}));
46 my ($count2, @missingissues);
47 if ($supplierid) {
48 ($count2, @missingissues) = GetLateOrMissingIssues($supplierid,$serialid,$order);
51 my $CGIsupplier=CGI::scrolling_list( -name => 'supplierid',
52 -id => 'supplierid',
53 -values => \@select_supplier,
54 -default => $supplierid,
55 -labels => \%supplierlist,
56 -size => 1,
57 -multiple => 0 );
59 my ($singlesupplier,@supplierinfo);
60 if($supplierid){
61 (@supplierinfo)=GetBookSeller($supplierid);
62 } else { # set up supplierid for the claim links out of main table if all suppliers is chosen
63 for my $mi (@missingissues){
64 $mi->{supplierid} = getsupplierbyserialid($mi->{serialid});
68 my $preview=0;
69 if($op && $op eq 'preview'){
70 $preview = 1;
72 if ($op eq "send_alert"){
73 my @serialnums=$input->param("serialid");
74 SendAlerts('claimissues',\@serialnums,$input->param("letter_code"));
75 my $cntupdate=UpdateClaimdateIssues(\@serialnums);
76 ### $cntupdate SHOULD be equal to scalar(@$serialnums)
77 $template->param('SHOWCONFIRMATION' => 1);
78 $template->param('suppliername' => $suppliername);
81 $template->param('letters'=>\@letters,'letter'=>$letter);
82 $template->param(
83 order =>$order,
84 CGIsupplier => $CGIsupplier,
85 phone => $supplierinfo[0]->{phone},
86 booksellerfax => $supplierinfo[0]->{booksellerfax},
87 bookselleremail => $supplierinfo[0]->{bookselleremail},
88 preview => $preview,
89 missingissues => \@missingissues,
90 supplierid => $supplierid,
91 claimletter => $claimletter,
92 singlesupplier => $singlesupplier,
93 supplierloop => \@supplierinfo,
94 dateformat => C4::Context->preference("dateformat"),
95 DHTMLcalendar_dateformat => C4::Dates->DHTMLcalendar(),
97 output_html_with_http_headers $input, $cookie, $template->output;