3 # This file is part of Koha.
5 # Koha is free software; you can redistribute it and/or modify it under the
6 # terms of the GNU General Public License as published by the Free Software
7 # Foundation; either version 2 of the License, or (at your option) any later
10 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License along with
15 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
16 # Suite 330, Boston, MA 02111-1307 USA
25 use C4::Interface::CGI::Output;
27 use C4::Branch; # GetBranches
33 my $op = $query->param('op');
34 my $dbh = C4::Context->dbh;
35 my ($subscriptionid,$auser,$branchcode,$librarian,$cost,$aqbooksellerid, $aqbooksellername,$aqbudgetid, $bookfundid, $startdate, $periodicity,
36 $firstacquidate, $dow, $irregularity, $numberpattern, $numberlength, $weeklength, $monthlength, $sublength,
37 $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1,
38 $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
39 $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
40 $numberingmethod, $status, $biblionumber,
41 $bibliotitle, $callnumber, $notes, $hemisphere, $letter, $manualhistory);
44 my ($template, $loggedinuser, $cookie)
45 = get_template_and_user({template_name => "serials/subscription-add.tmpl",
49 flagsrequired => {serials => 1},
56 my ($year, $month, $day) = UnixDate("today", "%Y", "%m", "%d");
57 my $firstday = Date_DayOfYear($month,$day,$year);
58 my $wkno = Date_WeekOfYear($month,$day,$year,1); # week starting monday
60 for(my $i=$firstday;$i<($firstday+365);$i=$i+7){
62 if($wkno > 52){$year++; $wkno=1;}
63 if($count>365){$count=$i-365;}
64 my ($y,$m,$d) = Date_NthDayOfYear($year,$count);
65 my $output = "$y-$m-$d";
66 $weekarrayjs .= "'Wk $wkno: ".format_date($output)."',";
73 my @subscription_types = (
74 'issues', 'weeks', 'months'
78 my $letters = GetLetters('serial');
80 foreach my $thisletter (keys %$letters) {
81 my $selected = 1 if $thisletter eq $letter;
82 my %row =(value => $thisletter,
83 selected => $selected,
84 lettername => $letters->{$thisletter},
86 push @letterloop, \%row;
88 $template->param(letterloop => \@letterloop);
90 my $onlymine=C4::Context->preference('IndependantBranches') &&
91 C4::Context->userenv &&
92 C4::Context->userenv->{flags}!=1 &&
93 C4::Context->userenv->{branch};
94 my $branches = GetBranches($onlymine);
96 foreach my $thisbranch (keys %$branches) {
97 my $selected = 1 if $thisbranch eq C4::Context->userenv->{'branch'};
98 my %row =(value => $thisbranch,
99 selected => $selected,
100 branchname => $branches->{$thisbranch}->{'branchname'},
102 push @branchloop, \%row;
104 $template->param(branchloop => \@branchloop);
106 if ($op eq 'mod'||$op eq 'dup') {
107 my $subscriptionid = $query->param('subscriptionid');
108 # warn "irregularity :$irregularity numberpattern : $numberpattern, callnumber :$callnumber, firstacquidate :$firstacquidate";
109 my $subs = &GetSubscription($subscriptionid);
110 $subs->{'startdate'}=format_date($subs->{'startdate'});
111 $subs->{'firstacquidate'}=format_date($subs->{'firstacquidate'});
112 $subs->{'histstartdate'}=format_date($subs->{'histstartdate'});
113 $subs->{'enddate'}=format_date($subs->{enddate});
114 $subs->{'letter'}='' unless($subs->{'letter'});
116 if($subs->{numberlength} > 0){
117 $sublength = $subs->{numberlength};
118 $sub_on = $subscription_types[0];
119 } elsif ($subs->{weeklength}>0){
120 $sublength = $weeklength;
121 $sub_on = $subscription_types[1];
123 $sublength = $subs->{monthlength};
124 $sub_on = $subscription_types[2];
126 while (@subscription_types) {
127 my $sub_type = shift @subscription_types;
128 my %row = ( 'name' => $sub_type );
129 if ( $sub_on eq $sub_type ) {
130 $row{'selected'} = ' selected';
132 $row{'selected'} = '';
134 push( @sub_type_data, \%row );
137 $template->param($subs);
140 subtype => \@sub_type_data,
141 sublength =>$sublength,
142 history => ($op eq 'mod' && ($subs->{recievedlist}||$subs->{missinglist}||$subs->{opacnote}||$subs->{librariannote}))
145 "periodicity".$subs->{'periodicity'} => 1,
146 "dow".$subs->{'periodicity'} => 1,
147 "numberpattern".$subs->{'periodicity'} => 1,
151 if ($op eq 'addsubscription') {
152 my @irregular = $query->param('irregular');
153 my $irregular_count = scalar(@irregular);
154 for(my $i =0;$i<$irregular_count;$i++){
155 $irregularity .=$irregular[$i].",";
157 $irregularity =~ s/\,$//;
159 my $auser = $query->param('user');
160 my $branchcode = $query->param('branchcode');
161 my $aqbooksellerid = $query->param('aqbooksellerid');
162 my $cost = $query->param('cost');
163 my $aqbudgetid = $query->param('aqbudgetid');
164 my $startdate = $query->param('startdate');
165 my $firstacquidate = $query->param('firstacquidate');
166 my $periodicity = $query->param('periodicity');
167 my $dow = $query->param('dow');
168 my $irregularity = $query->param('irregularity');
169 my $numberlength = 0;
172 my $numberpattern = $query->param('numbering_pattern');
173 my $sublength = $query->param('sublength');
174 my $subtype = $query->param('subtype');
175 if ($subtype eq 'months'){
176 $monthlength = $sublength;
177 } elsif ($subtype eq 'weeks'){
178 $weeklength = $sublength;
180 $numberlength = $sublength;
183 my $add1 = $query->param('add1');
184 my $every1 = $query->param('every1');
185 my $whenmorethan1 = $query->param('whenmorethan1');
186 my $setto1 = $query->param('setto1');
187 my $lastvalue1 = $query->param('lastvalue1');
188 my $add2 = $query->param('add2');
189 my $every2 = $query->param('every2');
190 my $whenmorethan2 = $query->param('whenmorethan2');
191 my $setto2 = $query->param('setto2');
192 my $lastvalue2 = $query->param('lastvalue2');
193 my $add3 = $query->param('add3');
194 my $every3 = $query->param('every3');
195 my $whenmorethan3 = $query->param('whenmorethan3');
196 my $setto3 = $query->param('setto3');
197 my $lastvalue3 = $query->param('lastvalue3');
198 my $numberingmethod = $query->param('numberingmethod');
200 my $biblionumber = $query->param('biblionumber');
201 my $callnumber = $query->param('callnumber');
202 my $notes = $query->param('notes');
203 my $internalnotes = $query->param('internalnotes');
204 my $hemisphere = $query->param('hemisphere') || 1;
205 my $letter = $query->param('letter');
206 ### BugFIX : hdl doesnot know what innerloops or letter stand for but it seems necessary. So he adds them.
207 my $manualhistory = $query->param('manualhist');
208 my ($innerloop1,$innerloop2,$innerloop3);
209 my $subscriptionid = NewSubscription($auser,$branchcode,$aqbooksellerid,$cost,$aqbudgetid,$biblionumber,
210 $startdate,$periodicity,$dow,$numberlength,$weeklength,$monthlength,
211 $add1,$every1,$whenmorethan1,$setto1,$lastvalue1,$innerloop1,
212 $add2,$every2,$whenmorethan2,$setto2,$lastvalue2,$innerloop2,
213 $add3,$every3,$whenmorethan3,$setto3,$lastvalue3,$innerloop3,
214 $numberingmethod, $status, $notes,$letter,$firstacquidate,$irregularity,
215 $numberpattern, $callnumber, $hemisphere,($manualhistory?$manualhistory:0),$internalnotes
218 print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
219 } elsif ($op eq 'modsubscription') {
220 my $subscriptionid = $query->param('subscriptionid');
221 my @irregular = $query->param('irregular');
222 my $irregular_count = @irregular;
223 for(my $i =0;$i<$irregular_count;$i++){
224 $irregularity .=$irregular[$i].",";
225 warn "irregular : $irregular[$i] string :$irregularity";
227 $irregularity =~ s/\,$//;
229 my $auser = $query->param('user');
230 my $librarian => $query->param('librarian'),
231 my $branchcode = $query->param('branchcode');
232 my $cost = $query->param('cost');
233 my $aqbooksellerid = $query->param('aqbooksellerid');
234 my $biblionumber = $query->param('biblionumber');
235 my $aqbudgetid = $query->param('aqbudgetid');
236 my $startdate = format_date_in_iso($query->param('startdate'));
237 my $firstacquidate = format_date_in_iso($query->param('firstacquidate'));
238 my $periodicity = $query->param('periodicity');
239 my $dow = $query->param('dow');
240 my $sublength = $query->param('sublength');
241 my $subtype = $query->param('subtype');
243 if($subtype eq 'months'){
244 $monthlength = $sublength;
245 } elsif ($subtype eq 'weeks'){
246 $weeklength = $sublength;
248 $numberlength = $sublength;
250 my $numberpattern = $query->param('numbering_pattern');
251 my $add1 = $query->param('add1');
252 my $every1 = $query->param('every1');
253 my $whenmorethan1 = $query->param('whenmorethan1');
254 my $setto1 = $query->param('setto1');
255 my $lastvalue1 = $query->param('lastvalue1');
256 my $innerloop1 = $query->param('innerloop1');
257 my $add2 = $query->param('add2');
258 my $every2 = $query->param('every2');
259 my $whenmorethan2 = $query->param('whenmorethan2');
260 my $setto2 = $query->param('setto2');
261 my $lastvalue2 = $query->param('lastvalue2');
262 my $innerloop2 = $query->param('innerloop2');
263 my $add3 = $query->param('add3');
264 my $every3 = $query->param('every3');
265 my $whenmorethan3 = $query->param('whenmorethan3');
266 my $setto3 = $query->param('setto3');
267 my $lastvalue3 = $query->param('lastvalue3');
268 my $innerloop3 = $query->param('innerloop3');
269 my $numberingmethod = $query->param('numberingmethod');
271 my $callnumber = $query->param('callnumber');
272 my $notes = $query->param('notes');
273 my $internalnotes = $query->param('internalnotes');
274 my $hemisphere = $query->param('hemisphere');
275 my $letter = $query->param('letter');
276 my $manualhistory = $query->param('manualhist');
277 my $enddate = $query->param('enddate');
278 my $histstartdate = format_date_in_iso($query->param('histstartdate'));
279 my $recievedlist = $query->param('recievedlist');
280 my $missinglist = $query->param('missinglist');
281 my $opacnote = $query->param('opacnote');
282 my $librariannote = $query->param('librariannote');
284 $auser, $branchcode, $aqbooksellerid, $cost,
285 $aqbudgetid, $startdate, $periodicity, $firstacquidate,
286 $dow, $irregularity, $numberpattern, $numberlength,
287 $weeklength, $monthlength, $add1, $every1,
288 $whenmorethan1, $setto1, $lastvalue1, $innerloop1,
289 $add2, $every2, $whenmorethan2, $setto2,
290 $lastvalue2, $innerloop2, $add3, $every3,
291 $whenmorethan3, $setto3, $lastvalue3, $innerloop3,
292 $numberingmethod, $status, $biblionumber, $callnumber,
293 $notes, $letter, $hemisphere, $manualhistory,$internalnotes,
296 ModSubscriptionHistory ($subscriptionid,$histstartdate,$enddate,$recievedlist,$missinglist,$opacnote,$librariannote);
297 print $query->redirect("/cgi-bin/koha/serials/subscription-detail.pl?subscriptionid=$subscriptionid");
300 while (@subscription_types) {
301 my $sub_type = shift @subscription_types;
302 my %row = ( 'name' => $sub_type );
303 if ( $sub_on eq $sub_type ) {
304 $row{'selected'} = ' selected';
306 $row{'selected'} = '';
308 push( @sub_type_data, \%row );
310 $template->param(subtype => \@sub_type_data,
311 weekarrayjs => $weekarrayjs,
314 output_html_with_http_headers $query, $cookie, $template->output;