changing DB structure to calculate next issue number.
[koha.git] / bull / subscription-add.pl
1 #!/usr/bin/perl
2
3 use strict;
4 use CGI;
5 use C4::Koha;
6 use C4::Auth;
7 use C4::Date;
8 use C4::Output;
9 use C4::Bull;
10 use C4::Acquisition;
11 use C4::Interface::CGI::Output;
12 use C4::Context;
13 use HTML::Template;
14 use C4::Bull;
15
16 my $query = new CGI;
17 my $op = $query->param('op');
18 my $dbh = C4::Context->dbh;
19 my ($subscriptionid,$auser,$librarian,$cost,$aqbooksellerid, $aqbooksellername,$aqbudgetid, $bookfundid, $startdate, $periodicity,
20         $dow, $numberlength, $weeklength, $monthlength,
21         $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,
22         $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,
23         $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,
24         $numberingmethod, $arrivalplanified, $status, $biblionumber, 
25         $bibliotitle, $notes);
26
27         my @budgets;
28 my ($template, $loggedinuser, $cookie)
29 = get_template_and_user({template_name => "bull/subscription-add.tmpl",
30                                 query => $query,
31                                 type => "intranet",
32                                 authnotrequired => 0,
33                                 flagsrequired => {catalogue => 1},
34                                 debug => 1,
35                                 });
36
37
38 if ($op eq 'mod') {
39         my $subscriptionid = $query->param('subscriptionid');
40         my $subs = &getsubscription($subscriptionid);
41         $auser = $subs->{'user'};
42         $librarian => $subs->{'librarian'},
43         $cost = $subs->{'cost'};
44         $aqbooksellerid = $subs->{'aqbooksellerid'};
45         $aqbooksellername = $subs->{'aqbooksellername'};
46         $bookfundid = $subs->{'bookfundid'};
47         $aqbudgetid = $subs->{'aqbudgetid'};
48         $startdate = $subs->{'startdate'};
49         $periodicity = $subs->{'periodicity'};
50         $dow = $subs->{'dow'};
51         $numberlength = $subs->{'numberlength'};
52         $weeklength = $subs->{'weeklength'};
53         $monthlength = $subs->{'monthlength'};
54         $add1 = $subs->{'add1'};
55         $every1 = $subs->{'every1'};
56         $whenmorethan1 = $subs->{'whenmorethan1'};
57         $setto1 = $subs->{'setto1'};
58         $lastvalue1 = $subs->{'lastvalue1'};
59         $add2 = $subs->{'add2'};
60         $every2 = $subs->{'every2'};
61         $whenmorethan2 = $subs->{'whenmorethan2'};
62         $setto2 = $subs->{'setto2'};
63         $lastvalue2 = $subs->{'lastvalue2'};
64         $add3 = $subs->{'add3'};
65         $every3 = $subs->{'every3'};
66         $whenmorethan3 = $subs->{'whenmorethan3'};
67         $setto3 = $subs->{'setto3'};
68         $lastvalue3 = $subs->{'lastvalue3'};
69         $numberingmethod = $subs->{'numberingmethod'};
70         $arrivalplanified = $subs->{'arrivalplanified'};
71         $status = $subs->{status};
72         $biblionumber = $subs->{'biblionumber'};
73         $bibliotitle = $subs->{'bibliotitle'},
74         $notes = $subs->{'notes'};
75         $template->param(
76                 $op => 1,
77                 user => $auser,
78                 librarian => $librarian,
79                 aqbooksellerid => $aqbooksellerid,
80                 aqbooksellername => $aqbooksellername,
81                 cost => $cost,
82                 aqbudgetid => $aqbudgetid,
83                 bookfundid => $bookfundid,
84                 startdate => format_date($startdate),
85                 periodicity => $periodicity,
86                 dow => $dow,
87                 numberlength => $numberlength,
88                 weeklength => $weeklength,
89                 monthlength => $monthlength,
90                 add1 => $add1,
91                 every1 => $every1,
92                 whenmorethan1 => $whenmorethan1,
93                 setto1 => $setto1,
94                 lastvalue1 => $lastvalue1,
95                 add2 => $add2,
96                 every2 => $every2,
97                 whenmorethan2 => $whenmorethan2,
98                 setto2 => $setto2,
99                 lastvalue2 => $lastvalue2,
100                 add3 => $add3,
101                 every3 => $every3,
102                 whenmorethan3 => $whenmorethan3,
103                 setto3 => $setto3,
104                 lastvalue3 => $lastvalue3,
105                 numberingmethod => $numberingmethod,
106                 arrivalplanified => format_date($arrivalplanified),
107                 status => $status,
108                 biblionumber => $biblionumber,
109                 bibliotitle => $bibliotitle,
110                 notes => $notes,
111                 subscriptionid => $subscriptionid,
112                 );
113         $template->param(
114                                 "periodicity$periodicity" => 1,
115                                 "dow$dow" => 1,
116                                 );
117 }
118 (my $temp,@budgets) = bookfunds();
119 # find default value & set it for the template
120 for (my $i=0;$i<=$#budgets;$i++) {
121         if ($budgets[$i]->{'aqbudgetid'} eq $aqbudgetid) {
122                 $budgets[$i]->{'selected'}=1;
123         }
124 }
125 $template->param(budgets => \@budgets);
126
127 if ($op eq 'addsubscription') {
128         my $auser = $query->param('user');
129         my $aqbooksellerid = $query->param('aqbooksellerid');
130         my $cost = $query->param('cost');
131         my $aqbudgetid = $query->param('aqbudgetid'); 
132         my $startdate = $query->param('startdate');
133         my $periodicity = $query->param('periodicity');
134         my $dow = $query->param('dow');
135         my $numberlength = $query->param('numberlength');
136         my $weeklength = $query->param('weeklength');
137         my $monthlength = $query->param('monthlength');
138         my $add1 = $query->param('add1');
139         my $every1 = $query->param('every1');
140         my $whenmorethan1 = $query->param('whenmorethan1');
141         my $setto1 = $query->param('setto1');
142         my $lastvalue1 = $query->param('lastvalue1');
143         my $add2 = $query->param('add2');
144         my $every2 = $query->param('every2');
145         my $whenmorethan2 = $query->param('whenmorethan2');
146         my $setto2 = $query->param('setto2');
147         my $lastvalue2 = $query->param('lastvalue2');
148         my $add3 = $query->param('add3');
149         my $every3 = $query->param('every3');
150         my $whenmorethan3 = $query->param('whenmorethan3');
151         my $setto3 = $query->param('setto3');
152         my $lastvalue3 = $query->param('lastvalue3');
153         my $numberingmethod = $query->param('numberingmethod');
154         my $arrivalplanified = $query->param('arrivalplanified');
155         my $status = 1;
156         my $biblionumber = $query->param('biblionumber');
157         my $notes = $query->param('notes');
158         newsubscription($auser,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber,
159                                         $startdate,$periodicity,$dow,$numberlength,$weeklength,$monthlength,
160                                         $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,
161                                         $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,
162                                         $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,
163                                         $numberingmethod, $arrivalplanified, $status, $notes
164                                 );
165         
166 }
167
168 output_html_with_http_headers $query, $cookie, $template->output;