Bug 30952: Staff interface redesign (header)
[koha.git] / reports / catalogue_stats.pl
1 #!/usr/bin/perl
2
3
4 # Copyright 2000-2002 Katipo Communications
5 #
6 # This file is part of Koha.
7 #
8 # Koha is free software; you can redistribute it and/or modify it
9 # under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 3 of the License, or
11 # (at your option) any later version.
12 #
13 # Koha is distributed in the hope that it will be useful, but
14 # WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with Koha; if not, see <http://www.gnu.org/licenses>.
20
21 use Modern::Perl;
22 use C4::Auth qw( get_template_and_user );
23 use CGI qw ( -utf8 );
24 use C4::Context;
25 use C4::Output qw( output_html_with_http_headers );
26 use C4::Koha qw( GetAuthorisedValues );
27 use C4::Reports qw( GetDelimiterChoices );
28 use C4::Biblio qw( GetMarcSubfieldStructureFromKohaField );
29
30 use Koha::AuthorisedValues;
31 use Koha::DateUtils qw( dt_from_string );
32 use Koha::ItemTypes;
33
34 =head1 NAME
35
36 plugin that shows a stats on borrowers
37
38 =head1 DESCRIPTION
39
40 =cut
41
42 our $debug = 0;
43 my $input = CGI->new;
44 my $fullreportname = "reports/catalogue_stats.tt";
45 my $do_it       = $input->param('do_it');
46 my $line        = $input->param("Line");
47 my $column      = $input->param("Column");
48 my $cellvalue      = $input->param("Cellvalue"); # one of 'items', 'biblios', 'deleteditems'
49 my @filters     = $input->multi_param("Filter");
50 my $cotedigits  = $input->param("cotedigits");
51 my $output      = $input->param("output");
52 my $basename    = $input->param("basename");
53 our $sep        = C4::Context->csv_delimiter(scalar $input->param("sep"));
54 my $item_itype;
55 if(C4::Context->preference('item-level_itypes')) {
56         $item_itype = "items\.itype"
57 } else {
58         $item_itype = "itemtype";
59 }
60 if(C4::Context->preference('marcflavour') ne "UNIMARC" && ($line=~ /publicationyear/ )) {
61     $line = "copyrightdate";
62 }
63 if(C4::Context->preference('marcflavour') ne "UNIMARC" && ($column =~ /publicationyear/ )) {
64     $column = "copyrightdate";
65 }
66
67 my ($template, $borrowernumber, $cookie)
68         = get_template_and_user({template_name => $fullreportname,
69                                 query => $input,
70                                 type => "intranet",
71                                 flagsrequired => {reports => '*'},
72                                 });
73 $template->param(do_it => $do_it);
74 if ($do_it) {
75     my $results = calculate( $line, $column, $cellvalue, $cotedigits, \@filters );
76     if ( $output eq "screen" ) {
77         $template->param( mainloop => $results );
78         output_html_with_http_headers $input, $cookie, $template->output;
79         exit;
80     } else {
81         print $input->header(
82             -type       => 'text/csv',
83             -encoding   => 'utf-8',
84             -attachment => "$basename.csv",
85             -name       => "$basename.csv"
86         );
87         my $cols  = @$results[0]->{loopcol};
88         my $lines = @$results[0]->{looprow};
89         print @$results[0]->{line} . "/" . @$results[0]->{column} . $sep;
90         foreach my $col (@$cols) {
91             print $col->{coltitle} . $sep;
92         }
93         print "Total\n";
94         foreach my $line (@$lines) {
95             my $x = $line->{loopcell};
96             print $line->{rowtitle} . $sep;
97             foreach my $cell (@$x) {
98                 print $cell->{value} . $sep;
99             }
100             print $line->{totalrow};
101             print "\n";
102         }
103         print "TOTAL";
104         $cols = @$results[0]->{loopfooter};
105         foreach my $col (@$cols) {
106             print $sep. $col->{totalcol};
107         }
108         print $sep. @$results[0]->{total};
109         exit;
110     }
111 } else {
112         my $dbh = C4::Context->dbh;
113         my $count=0;
114
115     my $itemtypes = Koha::ItemTypes->search_with_localization;
116
117     my @authvals = map { { code => $_->{authorised_value}, description => $_->{lib} } } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.ccode' }, { order_by => ['description'] } );
118     my @locations = map { { code => $_->{authorised_value}, description => $_->{lib} } } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => 'items.location' }, { order_by => ['description'] } );
119
120     foreach my $kohafield (qw(items.notforloan items.materials)) {
121         my $subfield_structure = GetMarcSubfieldStructureFromKohaField($kohafield);
122         if($subfield_structure) {
123             my $avlist;
124             my $avcategory = $subfield_structure->{authorised_value};
125             if($avcategory) {
126                 $avlist = GetAuthorisedValues($avcategory);
127             }
128             my $kf = $kohafield;
129             $kf =~ s/^items\.//;
130             $template->param(
131                 $kf => 1,
132                 $kf."_label" => $subfield_structure->{liblibrarian},
133                 $kf."_avlist" => $avlist
134             );
135         }
136     }
137
138     my @mime  = ( map { +{type =>$_} } (split /[;:]/, 'CSV') ); # FIXME translation
139
140     $template->param(
141         itemtypes    => $itemtypes,
142         locationloop => \@locations,
143         authvals     => \@authvals,
144         CGIextChoice => \@mime,
145         CGIsepChoice => GetDelimiterChoices,
146         item_itype   => $item_itype,
147     );
148
149 }
150 output_html_with_http_headers $input, $cookie, $template->output;
151
152 ## End of Main Body
153
154
155 sub calculate {
156     my ( $line, $column, $cellvalue, $cotedigits, $filters ) = @_;
157     my @mainloop;
158     my @loopfooter;
159     my @loopcol;
160     my @loopline;
161     my @looprow;
162     my %globalline;
163     my $grantotal     = 0;
164     my $barcodelike   = @$filters[16];
165     my $barcodefilter = @$filters[17];
166     my $not;
167     my $itemstable = ($cellvalue eq 'deleteditems') ? 'deleteditems' : 'items';
168
169     my $dbh = C4::Context->dbh;
170
171     # if barcodefilter is empty set as %
172     if ($barcodefilter) {
173
174         # Check if barcodefilter is "like" or "not like"
175         if ( !$barcodelike ) {
176             $not = "not";
177         }
178
179         # Change * to %
180         $barcodefilter =~ s/\*/%/g;
181     }
182
183     # Filters
184     # Checking filters
185     #
186     my @loopfilter;
187     for ( my $i = 0 ; $i <= @$filters ; $i++ ) {
188         my %cell;
189         if ( defined @$filters[$i] and @$filters[$i] ne '' and $i != 11 ) {
190             if ( ( ( $i == 1 ) or ( $i == 5 ) ) and ( @$filters[ $i - 1 ] ) ) {
191                 $cell{err} = 1 if ( @$filters[$i] < @$filters[ $i - 1 ] );
192             }
193             $cell{filter} .= @$filters[$i];
194             $cell{crit} .=
195                 ( $i == 0 )  ? "Item CallNumber From"
196               : ( $i == 1 )  ? "Item CallNumber To"
197               : ( $i == 2 )  ? "Item type"
198               : ( $i == 3 )  ? "Publisher"
199               : ( $i == 4 )  ? "Publication year From"
200               : ( $i == 5 )  ? "Publication year To"
201               : ( $i == 6 ) ? "Library"
202               : ( $i == 7 ) ? "Shelving Location"
203               : ( $i == 8 ) ? "Collection Code"
204               : ( $i == 9 ) ? "Status"
205               : ( $i == 10 ) ? "Materials"
206               : ( $i == 12 and $filters->[11] == 0 ) ? "Barcode (not like)"
207               : ( $i == 12 and $filters->[11] == 1 ) ? "Barcode (like)"
208               : ( $i == 13 ) ? "Date acquired (item) from"
209               : ( $i == 14 ) ? "Date acquired (item) to"
210               : ( $i == 15 ) ? "Date deleted (item) from"
211               : ( $i == 16 ) ? "Date deleted (item) to"
212               :                '';
213
214             push @loopfilter, \%cell;
215         }
216     }
217
218     @$filters[13] = dt_from_string(@$filters[13])->date() if @$filters[13];
219     @$filters[14] = dt_from_string(@$filters[14])->date() if @$filters[14];
220     @$filters[15] = dt_from_string(@$filters[15])->date() if @$filters[15];
221     @$filters[16] = dt_from_string(@$filters[16])->date() if @$filters[16];
222
223     my @linefilter;
224     $linefilter[0] = @$filters[0] if ( $line =~ /items\.itemcallnumber/ );
225     $linefilter[1] = @$filters[1] if ( $line =~ /items\.itemcallnumber/ );
226     if ( C4::Context->preference('item-level_itypes') ) {
227         $linefilter[0] = @$filters[2] if ( $line =~ /items\.itype/ );
228     } else {
229         $linefilter[0] = @$filters[2] if ( $line =~ /itemtype/ );
230     }
231     $linefilter[0] = @$filters[3] if ( $line =~ /publishercode/ );
232     $linefilter[0] = @$filters[4] if ( $line =~ /publicationyear/ );
233     $linefilter[1] = @$filters[5] if ( $line =~ /publicationyear/ );
234
235     $linefilter[0] = @$filters[6] if ( $line =~ /items\.homebranch/ );
236     $linefilter[0] = @$filters[7] if ( $line =~ /items\.location/ );
237     $linefilter[0] = @$filters[8] if ( $line =~ /items\.ccode/ );
238     $linefilter[0] = @$filters[9] if ( $line =~ /items\.notforloan/ );
239     $linefilter[0] = @$filters[10] if ( $line =~ /items\.materials/ );
240     $linefilter[0] = @$filters[13] if ( $line =~ /items\.dateaccessioned/ );
241     $linefilter[1] = @$filters[14] if ( $line =~ /items\.dateaccessioned/ );
242     $linefilter[0] = @$filters[15] if ( $line =~ /deleteditems\.timestamp/ );
243     $linefilter[1] = @$filters[16] if ( $line =~ /deleteditems\.timestamp/ );
244
245     my @colfilter;
246     $colfilter[0] = @$filters[0] if ( $column =~ /items\.itemcallnumber/ );
247     $colfilter[1] = @$filters[1] if ( $column =~ /items\.itemcallnumber/ );
248     if ( C4::Context->preference('item-level_itypes') ) {
249         $colfilter[0] = @$filters[2] if ( $column =~ /items\.itype/ );
250     } else {
251         $colfilter[0] = @$filters[2] if ( $column =~ /itemtype/ );
252     }
253     $colfilter[0] = @$filters[3]  if ( $column =~ /publishercode/ );
254     $colfilter[0] = @$filters[4]  if ( $column =~ /publicationyear/ );
255     $colfilter[1] = @$filters[5]  if ( $column =~ /publicationyear/ );
256     $colfilter[0] = @$filters[6] if ( $column =~ /items\.homebranch/ );
257     $colfilter[0] = @$filters[7] if ( $column =~ /items\.location/ );
258     $colfilter[0] = @$filters[8] if ( $column =~ /items\.ccode/ );
259     $colfilter[0] = @$filters[9] if ( $column =~ /items\.notforloan/ );
260     $colfilter[0] = @$filters[10] if ( $column =~ /items\.materials/ );
261     $colfilter[0] = @$filters[13] if ( $column =~ /items.dateaccessioned/ );
262     $colfilter[1] = @$filters[14] if ( $column =~ /items\.dateaccessioned/ );
263     $colfilter[0] = @$filters[15] if ( $column =~ /deleteditems\.timestamp/ );
264     $colfilter[1] = @$filters[16] if ( $column =~ /deleteditems\.timestamp/ );
265
266     # 1st, loop rows.
267     my $origline = $line;
268     $line =~ s/^items\./deleteditems./ if($cellvalue eq "deleteditems");
269     my $linefield;
270     if ( ( $line =~ /itemcallnumber/ ) and ($cotedigits) ) {
271         $linefield = "left($line,$cotedigits)";
272     } elsif ( $line =~ /^deleteditems\.timestamp$/ ) {
273         $linefield = "DATE($line)";
274     } else {
275         $linefield = $line;
276     }
277
278     my $strsth = "SELECT DISTINCTROW $linefield FROM $itemstable
279                     LEFT JOIN biblioitems USING (biblioitemnumber)
280                     LEFT JOIN biblio ON (biblioitems.biblionumber = biblio.biblionumber)
281                   WHERE 1 ";
282     $strsth .= " AND barcode $not LIKE ? " if ($barcodefilter);
283     if (@linefilter) {
284         if ( $linefilter[1] ) {
285             $strsth .= " AND $line >= ? ";
286             $strsth .= " AND $line <= ? ";
287         } elsif ( defined $linefilter[0] and $linefilter[0] ne '' ) {
288             $linefilter[0] =~ s/\*/%/g;
289             $strsth .= " AND $line LIKE ? ";
290         }
291     }
292     $strsth .= " ORDER BY $linefield";
293     $debug and print STDERR "catalogue_stats SQL: $strsth\n";
294
295     my $sth = $dbh->prepare($strsth);
296     if ( $barcodefilter and (@linefilter) and ( $linefilter[1] ) ) {
297         $sth->execute( $barcodefilter, $linefilter[0], $linefilter[1] );
298     } elsif ( (@linefilter) and ( $linefilter[1] ) ) {
299         $sth->execute( $linefilter[0], $linefilter[1] );
300     } elsif ( $barcodefilter and $linefilter[0] ) {
301         $sth->execute( $barcodefilter, $linefilter[0] );
302     } elsif ( $linefilter[0] ) {
303         $sth->execute($linefilter[0]);
304     } elsif ($barcodefilter) {
305         $sth->execute($barcodefilter);
306     } else {
307         $sth->execute();
308     }
309     my $rowauthvals = { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => $origline } ) };
310     while ( my ($celvalue) = $sth->fetchrow ) {
311         my %cell;
312         if (defined $celvalue and $celvalue ne '') {
313             if($rowauthvals and $rowauthvals->{$celvalue}) {
314                 $cell{rowtitle} = $rowauthvals->{$celvalue};
315             } else {
316                 $cell{rowtitle} = $celvalue;
317             }
318             $cell{value} = $celvalue;
319         }
320         else {
321             $cell{rowtitle} = "NULL";
322             $cell{value} = "zzEMPTY";
323         }
324         $cell{totalrow} = 0;
325         push @loopline, \%cell;
326     }
327
328     # 2nd, loop cols.
329     my $origcolumn = $column;
330     $column =~ s/^items\./deleteditems./ if($cellvalue eq "deleteditems");
331     my $colfield;
332     if ( ( $column =~ /itemcallnumber/ ) and ($cotedigits) ) {
333         $colfield = "left($column,$cotedigits)";
334     } elsif ( $column =~ /^deleteditems\.timestamp$/ ) {
335         $colfield = "DATE($column)";
336     } else {
337         $colfield = $column;
338     }
339
340     my $strsth2 = "
341         SELECT distinctrow $colfield
342         FROM   $itemstable
343         LEFT JOIN biblioitems
344             USING (biblioitemnumber)
345         LEFT JOIN biblio
346             ON (biblioitems.biblionumber = biblio.biblionumber)
347         WHERE 1 ";
348     $strsth2 .= " AND barcode $not LIKE ?" if $barcodefilter;
349
350     if ( (@colfilter) and ( $colfilter[1] ) ) {
351         $strsth2 .= " AND $column >= ? AND $column <= ?";
352     } elsif ( defined $colfilter[0] and $colfilter[0] ne '' ) {
353         $colfilter[0] =~ s/\*/%/g;
354         $strsth2 .= " AND $column LIKE ? ";
355     }
356     $strsth2 .= " ORDER BY $colfield";
357     $debug and print STDERR "SQL: $strsth2";
358     my $sth2 = $dbh->prepare($strsth2);
359     if ( $barcodefilter and (@colfilter) and ( $colfilter[1] ) ) {
360         $sth2->execute( $barcodefilter, $colfilter[0], $colfilter[1] );
361     } elsif ( (@colfilter) and ( $colfilter[1] ) ) {
362         $sth2->execute( $colfilter[0], $colfilter[1] );
363     } elsif ( $barcodefilter && $colfilter[0] ) {
364         $sth2->execute( $barcodefilter , $colfilter[0] );
365     } elsif ( $colfilter[0]) {
366         $sth2->execute( $colfilter[0] );
367     } elsif ($barcodefilter) {
368         $sth2->execute($barcodefilter);
369     } else {
370         $sth2->execute();
371     }
372     my $colauthvals = { map { $_->{authorised_value} => $_->{lib} } Koha::AuthorisedValues->get_descriptions_by_koha_field( { frameworkcode => '', kohafield => $origcolumn } ) };
373     while ( my ($celvalue) = $sth2->fetchrow ) {
374         my %cell;
375         if (defined $celvalue and $celvalue ne '') {
376             if($colauthvals and $colauthvals->{$celvalue}) {
377                 $cell{coltitle} = $colauthvals->{$celvalue};
378             } else {
379                 $cell{coltitle} = $celvalue;
380             }
381             $cell{value} = $celvalue;
382         }
383         else {
384             $cell{coltitle} = "NULL";
385             $cell{value} = "zzEMPTY";
386         }
387         $cell{totalcol} = 0;
388         push @loopcol, \%cell;
389     }
390
391     my $i = 0;
392     my $hilighted = -1;
393
394     #Initialization of cell values.....
395     my %table;
396
397     foreach my $row (@loopline) {
398         foreach my $col (@loopcol) {
399             $table{ $row->{value} }->{ $col->{value} } = 0;
400         }
401         $table{ $row->{value} }->{totalrow} = 0;
402     }
403
404     # preparing calculation
405     my $select_cellvalue = " COUNT(*) ";
406     $select_cellvalue = " COUNT(DISTINCT biblioitems.biblionumber) " if($cellvalue eq 'biblios');
407     my $strcalc = "
408         SELECT $linefield, $colfield, $select_cellvalue
409         FROM $itemstable
410         LEFT JOIN biblioitems ON ($itemstable.biblioitemnumber = biblioitems.biblioitemnumber)
411         LEFT JOIN biblio ON (biblioitems.biblionumber = biblio.biblionumber)
412         WHERE 1 ";
413
414     my @sqlargs;
415
416     if ($barcodefilter) {
417         $strcalc .= "AND barcode $not like ? ";
418         push @sqlargs, $barcodefilter;
419     }
420
421     if ( @$filters[0] ) {
422         $strcalc .= " AND $itemstable.itemcallnumber >= ? ";
423         @$filters[0] =~ s/\*/%/g;
424         push @sqlargs, @$filters[0];
425     }
426
427     if ( @$filters[1] ) {
428         $strcalc .= " AND $itemstable.itemcallnumber <= ? ";
429         @$filters[1] =~ s/\*/%/g;
430         push @sqlargs, @$filters[1];
431     }
432
433     if ( @$filters[2] ) {
434         $strcalc .= " AND " . ( C4::Context->preference('item-level_itypes') ? "$itemstable.itype" : 'biblioitems.itemtype' ) . " LIKE ? ";
435         @$filters[2] =~ s/\*/%/g;
436         push @sqlargs, @$filters[2];
437     }
438
439     if ( @$filters[3] ) {
440         $strcalc .= " AND biblioitems.publishercode LIKE ? ";
441         @$filters[3] =~ s/\*/%/g;
442         @$filters[3] .= "%" unless @$filters[3] =~ /%/;
443         push @sqlargs, @$filters[3];
444     }
445     if ( @$filters[4] ) {
446         $strcalc .= " AND " .
447         (C4::Context->preference('marcflavour') eq 'UNIMARC' ? 'publicationyear' : 'copyrightdate')
448         . "> ? ";
449         @$filters[4] =~ s/\*/%/g;
450         push @sqlargs, @$filters[4];
451     }
452     if ( @$filters[5] ) {
453         @$filters[5] =~ s/\*/%/g;
454         $strcalc .= " AND " .
455         (C4::Context->preference('marcflavour') eq 'UNIMARC' ? 'publicationyear' : 'copyrightdate')
456         . "< ? ";
457         push @sqlargs, @$filters[5];
458     }
459     if ( @$filters[6] ) {
460         $strcalc .= " AND $itemstable.homebranch LIKE ? ";
461         @$filters[6] =~ s/\*/%/g;
462         push @sqlargs, @$filters[6];
463     }
464     if ( @$filters[7] ) {
465         $strcalc .= " AND $itemstable.location LIKE ? ";
466         @$filters[7] =~ s/\*/%/g;
467         push @sqlargs, @$filters[7];
468     }
469     if ( @$filters[8] ) {
470         $strcalc .= " AND $itemstable.ccode  LIKE ? ";
471         @$filters[8] =~ s/\*/%/g;
472         push @sqlargs, @$filters[8];
473     }
474     if ( defined @$filters[9] and @$filters[9] ne '' ) {
475         $strcalc .= " AND $itemstable.notforloan  LIKE ? ";
476         @$filters[9] =~ s/\*/%/g;
477         push @sqlargs, @$filters[9];
478     }
479     if ( defined @$filters[10] and @$filters[10] ne '' ) {
480         $strcalc .= " AND $itemstable.materials  LIKE ? ";
481         @$filters[10] =~ s/\*/%/g;
482         push @sqlargs, @$filters[10];
483     }
484     if ( @$filters[13] ) {
485         $strcalc .= " AND $itemstable.dateaccessioned >= ? ";
486         @$filters[13] =~ s/\*/%/g;
487         push @sqlargs, @$filters[13];
488     }
489     if ( @$filters[14] ) {
490         $strcalc .= " AND $itemstable.dateaccessioned <= ? ";
491         @$filters[14] =~ s/\*/%/g;
492         push @sqlargs, @$filters[14];
493     }
494     if ( $cellvalue eq 'deleteditems' and @$filters[15] ) {
495         $strcalc .= " AND DATE(deleteditems.timestamp) >= ? ";
496         @$filters[15] =~ s/\*/%/g;
497         push @sqlargs, @$filters[15];
498     }
499     if ( $cellvalue eq 'deleteditems' and @$filters[16] ) {
500         @$filters[16] =~ s/\*/%/g;
501         $strcalc .= " AND DATE(deleteditems.timestamp) <= ?";
502         push @sqlargs, @$filters[16];
503     }
504     $strcalc .= " group by $linefield, $colfield order by $linefield,$colfield";
505     $debug and warn "SQL: $strcalc";
506     my $dbcalc = $dbh->prepare($strcalc);
507     $dbcalc->execute(@sqlargs);
508
509     while ( my ( $row, $col, $value ) = $dbcalc->fetchrow ) {
510
511         $col      = "zzEMPTY" if ( !defined($col) );
512         $row      = "zzEMPTY" if ( !defined($row) );
513
514         $table{$row}->{$col}     += $value;
515         $table{$row}->{totalrow} += $value;
516         $grantotal               += $value;
517     }
518
519     foreach my $row ( @loopline ) {
520         my @loopcell;
521
522         #@loopcol ensures the order for columns is common with column titles
523         # and the number matches the number of columns
524         foreach my $col (@loopcol) {
525             my $value = $table{$row->{value}}->{ $col->{value} };
526             push @loopcell, { value => $value };
527         }
528         push @looprow,
529           { 'rowtitle' => $row->{rowtitle},
530             'value'    => $row->{value},
531             'loopcell' => \@loopcell,
532             'hilighted' => ( $hilighted *= -1 > 0 ),
533             'totalrow' => $table{$row->{value}}->{totalrow}
534           };
535     }
536
537     foreach my $col (@loopcol) {
538         my $total = 0;
539         foreach my $row (@looprow) {
540             $total += $table{ $row->{value} }->{ $col->{value} };
541         }
542
543         push @loopfooter, { 'totalcol' => $total };
544     }
545
546     # the header of the table
547     $globalline{loopfilter} = \@loopfilter;
548
549     # the core of the table
550     $globalline{looprow} = \@looprow;
551     $globalline{loopcol} = \@loopcol;
552
553     # the foot (totals by borrower type)
554     $globalline{loopfooter} = \@loopfooter;
555     $globalline{total}      = $grantotal;
556     $globalline{line}       = $line;
557     $globalline{column}     = $column;
558     push @mainloop, \%globalline;
559     return \@mainloop;
560 }