View | Details | Raw Unified | Return to bug 16631
Collapse All | Expand All

(-)a/Koha/Manual.pm (+1 lines)
Lines 117-122 our $mapping = { Link Here
117
    'admin/preferences#logs'                   => '/logspreferences.html',
117
    'admin/preferences#logs'                   => '/logspreferences.html',
118
    'admin/preferences#opac'                   => '/opacpreferences.html',
118
    'admin/preferences#opac'                   => '/opacpreferences.html',
119
    'admin/preferences#patrons'                => '/patronspreferences.html',
119
    'admin/preferences#patrons'                => '/patronspreferences.html',
120
    'admin/preferences#reports'                => '/reportspreferences.html',
120
    'admin/preferences#searching'              => '/searchingpreferences.html',
121
    'admin/preferences#searching'              => '/searchingpreferences.html',
121
    'admin/preferences#serials'                => '/serialspreferences.html',
122
    'admin/preferences#serials'                => '/serialspreferences.html',
122
    'admin/preferences#staff_interface'        => '/staffclientpreferences.html',
123
    'admin/preferences#staff_interface'        => '/staffclientpreferences.html',
(-)a/Koha/Report.pm (-1 / +19 lines)
Lines 20-28 use Modern::Perl; Link Here
20
use Koha::Database;
20
use Koha::Database;
21
use Koha::Reports;
21
use Koha::Reports;
22
22
23
use Koha::Object;
24
use Koha::Object::Limit::Library;
25
26
use base qw(Koha::Object Koha::Object::Limit::Library);
27
23
#use Koha::DateUtils qw( dt_from_string output_pref );
28
#use Koha::DateUtils qw( dt_from_string output_pref );
24
29
25
use base qw(Koha::Object);
26
#
30
#
27
# FIXME We could only return an error code instead of the arrayref
31
# FIXME We could only return an error code instead of the arrayref
28
# Only 1 error is returned
32
# Only 1 error is returned
Lines 268-271 sub _type { Link Here
268
    return 'SavedSql';
272
    return 'SavedSql';
269
}
273
}
270
274
275
=head3 _library_limits
276
277
Configurable library limits
278
279
=cut
280
281
sub _library_limits {
282
    return {
283
        class   => "ReportsBranch",
284
        id      => "report_id",
285
        library => "branchcode",
286
    };
287
}
288
271
1;
289
1;
(-)a/Koha/Reports.pm (-1 / +28 lines)
Lines 21-27 use Koha::Database; Link Here
21
21
22
use Koha::Report;
22
use Koha::Report;
23
23
24
use base qw(Koha::Objects);
24
use base qw(Koha::Objects Koha::Objects::Limit::Library);
25
25
26
=head1 NAME
26
=head1 NAME
27
27
Lines 33-38 Koha::Reports - Koha Report Object set class Link Here
33
33
34
=cut
34
=cut
35
35
36
=head3 search_with_localization
37
38
my $itemtypes = Koha::ItemTypes->search_with_localization
39
40
=cut
41
42
sub search_with_localization {
43
    my ( $self, $params, $attributes ) = @_;
44
45
    my $language = C4::Languages::getlanguage();
46
    $Koha::Schema::Result::Itemtype::LANGUAGE = $language;
47
    $attributes->{order_by}                   = 'translated_description' unless exists $attributes->{order_by};
48
    $attributes->{join}                       = 'localization';
49
    $attributes->{'+select'}                  = [
50
        {
51
            coalesce => [qw( localization.translation me.description )],
52
            -as      => 'translated_description'
53
        }
54
    ];
55
    if ( defined $params->{branchcode} ) {
56
        my $branchcode = delete $params->{branchcode};
57
        $self->search_with_library_limits( $params, $attributes, $branchcode );
58
    } else {
59
        $self->SUPER::search( $params, $attributes );
60
    }
61
}
62
36
=head3 _type
63
=head3 _type
37
64
38
Returns name of corresponding DBIC resultset
65
Returns name of corresponding DBIC resultset
(-)a/Koha/Schema/Result/ReportsBranch.pm (+85 lines)
Line 0 Link Here
1
use utf8;
2
3
package Koha::Schema::Result::ReportsBranch;
4
5
# Created by DBIx::Class::Schema::Loader
6
# DO NOT MODIFY THE FIRST PART OF THIS FILE
7
8
=head1 NAME
9
10
Koha::Schema::Result::ReportsBranch
11
12
=cut
13
14
use strict;
15
use warnings;
16
17
use base 'DBIx::Class::Core';
18
19
=head1 TABLE: C<reports_branches>
20
21
=cut
22
23
__PACKAGE__->table("reports_branches");
24
25
=head1 ACCESSORS
26
27
=head2 report_id
28
29
  data_type: 'integer'
30
  is_foreign_key: 1
31
  is_nullable: 0
32
33
=head2 branchcode
34
35
  data_type: 'varchar'
36
  is_foreign_key: 1
37
  is_nullable: 0
38
  size: 10
39
40
=cut
41
42
__PACKAGE__->add_columns(
43
    "report_id",
44
    { data_type => "integer", is_foreign_key => 1, is_nullable => 0 },
45
    "branchcode",
46
    { data_type => "varchar", is_foreign_key => 1, is_nullable => 0, size => 10 },
47
);
48
49
=head1 RELATIONS
50
51
=head2 branchcode
52
53
Type: belongs_to
54
55
Related object: L<Koha::Schema::Result::Branch>
56
57
=cut
58
59
__PACKAGE__->belongs_to(
60
    "branchcode",
61
    "Koha::Schema::Result::Branch",
62
    { branchcode    => "branchcode" },
63
    { is_deferrable => 1, on_delete => "CASCADE", on_update => "RESTRICT" },
64
);
65
66
=head2 report
67
68
Type: belongs_to
69
70
Related object: L<Koha::Schema::Result::SavedSql>
71
72
=cut
73
74
__PACKAGE__->belongs_to(
75
    "report",
76
    "Koha::Schema::Result::SavedSql",
77
    { id            => "report_id" },
78
    { is_deferrable => 1, on_delete => "CASCADE", on_update => "RESTRICT" },
79
);
80
81
# Created by DBIx::Class::Schema::Loader v0.07051 @ 2025-07-06 17:02:11
82
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:SJqUxMgLJHAjbX3GJlpB+A
83
84
# You can replace this text with custom code or comments, and it will be preserved on regeneration
85
1;
(-)a/Koha/Schema/Result/SavedSql.pm (+220 lines)
Lines 185-190 __PACKAGE__->add_columns( Link Here
185
185
186
__PACKAGE__->set_primary_key("id");
186
__PACKAGE__->set_primary_key("id");
187
187
188
=head1 RELATIONS
189
190
=head2 reports_branches
191
192
Type: has_many
193
194
Related object: L<Koha::Schema::Result::ReportsBranch>
195
196
=cut
197
198
__PACKAGE__->has_many(
199
  "reports_branches",
200
  "Koha::Schema::Result::ReportsBranch",
201
  { "foreign.report_id" => "self.id" },
202
  { cascade_copy => 0, cascade_delete => 0 },
203
);
204
205
206
# Created by DBIx::Class::Schema::Loader v0.07051 @ 2025-07-06 17:02:11
207
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:qFqDaOxgdm2I12cJEiCieg
208
# These lines were loaded from '/kohadevbox/koha/Koha/Schema/Result/SavedSql.pm' found in @INC.
209
# They are now part of the custom portion of this file
210
# for you to hand-edit.  If you do not either delete
211
# this section or remove that file from @INC, this section
212
# will be repeated redundantly when you re-create this
213
# file again via Loader!  See skip_load_external to disable
214
# this feature.
215
216
use utf8;
217
package Koha::Schema::Result::SavedSql;
218
219
# Created by DBIx::Class::Schema::Loader
220
# DO NOT MODIFY THE FIRST PART OF THIS FILE
221
222
=head1 NAME
223
224
Koha::Schema::Result::SavedSql
225
226
=cut
227
228
use strict;
229
use warnings;
230
231
use base 'DBIx::Class::Core';
232
233
=head1 TABLE: C<saved_sql>
234
235
=cut
236
237
__PACKAGE__->table("saved_sql");
238
239
=head1 ACCESSORS
240
241
=head2 id
242
243
  data_type: 'integer'
244
  is_auto_increment: 1
245
  is_nullable: 0
246
247
unique id and primary key assigned by Koha
248
249
=head2 borrowernumber
250
251
  data_type: 'integer'
252
  is_nullable: 1
253
254
the staff member who created this report (borrowers.borrowernumber)
255
256
=head2 date_created
257
258
  data_type: 'datetime'
259
  datetime_undef_if_invalid: 1
260
  is_nullable: 1
261
262
the date this report was created
263
264
=head2 last_modified
265
266
  data_type: 'datetime'
267
  datetime_undef_if_invalid: 1
268
  is_nullable: 1
269
270
the date this report was last edited
271
272
=head2 savedsql
273
274
  data_type: 'mediumtext'
275
  is_nullable: 1
276
277
the SQL for this report
278
279
=head2 last_run
280
281
  data_type: 'datetime'
282
  datetime_undef_if_invalid: 1
283
  is_nullable: 1
284
285
=head2 report_name
286
287
  data_type: 'varchar'
288
  default_value: (empty string)
289
  is_nullable: 0
290
  size: 255
291
292
the name of this report
293
294
=head2 type
295
296
  data_type: 'varchar'
297
  is_nullable: 1
298
  size: 255
299
300
always 1 for tabular
301
302
=head2 notes
303
304
  data_type: 'mediumtext'
305
  is_nullable: 1
306
307
the notes or description given to this report
308
309
=head2 cache_expiry
310
311
  data_type: 'integer'
312
  default_value: 300
313
  is_nullable: 0
314
315
=head2 public
316
317
  data_type: 'tinyint'
318
  default_value: 0
319
  is_nullable: 0
320
321
=head2 report_area
322
323
  data_type: 'varchar'
324
  is_nullable: 1
325
  size: 6
326
327
=head2 report_group
328
329
  data_type: 'varchar'
330
  is_nullable: 1
331
  size: 80
332
333
=head2 report_subgroup
334
335
  data_type: 'varchar'
336
  is_nullable: 1
337
  size: 80
338
339
=head2 mana_id
340
341
  data_type: 'integer'
342
  is_nullable: 1
343
344
=cut
345
346
__PACKAGE__->add_columns(
347
  "id",
348
  { data_type => "integer", is_auto_increment => 1, is_nullable => 0 },
349
  "borrowernumber",
350
  { data_type => "integer", is_nullable => 1 },
351
  "date_created",
352
  {
353
    data_type => "datetime",
354
    datetime_undef_if_invalid => 1,
355
    is_nullable => 1,
356
  },
357
  "last_modified",
358
  {
359
    data_type => "datetime",
360
    datetime_undef_if_invalid => 1,
361
    is_nullable => 1,
362
  },
363
  "savedsql",
364
  { data_type => "mediumtext", is_nullable => 1 },
365
  "last_run",
366
  {
367
    data_type => "datetime",
368
    datetime_undef_if_invalid => 1,
369
    is_nullable => 1,
370
  },
371
  "report_name",
372
  { data_type => "varchar", default_value => "", is_nullable => 0, size => 255 },
373
  "type",
374
  { data_type => "varchar", is_nullable => 1, size => 255 },
375
  "notes",
376
  { data_type => "mediumtext", is_nullable => 1 },
377
  "cache_expiry",
378
  { data_type => "integer", default_value => 300, is_nullable => 0 },
379
  "public",
380
  { data_type => "tinyint", default_value => 0, is_nullable => 0 },
381
  "report_area",
382
  { data_type => "varchar", is_nullable => 1, size => 6 },
383
  "report_group",
384
  { data_type => "varchar", is_nullable => 1, size => 80 },
385
  "report_subgroup",
386
  { data_type => "varchar", is_nullable => 1, size => 80 },
387
  "mana_id",
388
  { data_type => "integer", is_nullable => 1 },
389
);
390
391
=head1 PRIMARY KEY
392
393
=over 4
394
395
=item * L</id>
396
397
=back
398
399
=cut
400
401
__PACKAGE__->set_primary_key("id");
402
188
403
189
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29
404
# Created by DBIx::Class::Schema::Loader v0.07049 @ 2021-01-21 13:39:29
190
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:198dNG9DGQzop+s5IHy7sw
405
# DO NOT MODIFY THIS OR ANYTHING ABOVE! md5sum:198dNG9DGQzop+s5IHy7sw
Lines 214-216 sub koha_objects_class { Link Here
214
}
429
}
215
430
216
1;
431
1;
432
# End of lines loaded from '/kohadevbox/koha/Koha/Schema/Result/SavedSql.pm'
433
434
435
# You can replace this text with custom code or comments, and it will be preserved on regeneration
436
1;
(-)a/installer/data/mysql/kohastructure.sql (+13 lines)
Lines 5772-5777 CREATE TABLE `saved_reports` ( Link Here
5772
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
5772
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
5773
/*!40101 SET character_set_client = @saved_cs_client */;
5773
/*!40101 SET character_set_client = @saved_cs_client */;
5774
5774
5775
DROP TABLE IF EXISTS `reports_branches`;
5776
/*!40101 SET @saved_cs_client     = @@character_set_client */;
5777
/*!40101 SET character_set_client = utf8mb4 */;
5778
CREATE TABLE `reports_branches` (
5779
  `report_id` int(11) NOT NULL,
5780
  `branchcode` varchar(10) NOT NULL,
5781
  KEY `report_id` (`report_id`),
5782
  KEY `branchcode` (`branchcode`),
5783
  CONSTRAINT `reports_branches_ibfk_1` FOREIGN KEY (`report_id`) REFERENCES `saved_sql` (`id`) ON DELETE CASCADE,
5784
  CONSTRAINT `reports_branches_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE
5785
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
5786
/*!40101 SET character_set_client = @saved_cs_client */;
5787
5775
--
5788
--
5776
-- Table structure for table `saved_sql`
5789
-- Table structure for table `saved_sql`
5777
--
5790
--
(-)a/installer/data/mysql/updatedatabase.pl (+16 lines)
Lines 29455-29460 if ( CheckVersion($DBversion) ) { Link Here
29455
    NewVersion( $DBversion, 28108, "Add new systempreference OpacHiddenItemsHidesRecord" );
29455
    NewVersion( $DBversion, 28108, "Add new systempreference OpacHiddenItemsHidesRecord" );
29456
}
29456
}
29457
29457
29458
$DBversion = '25.06.00.003';
29459
if ( C4::Context->preference("Version") < TransformToNum($DBversion) ) {
29460
    $dbh->do(
29461
        "CREATE TABLE `reports_branches` (
29462
            `report_id` int(11) NOT NULL,
29463
            `branchcode` varchar(10) NOT NULL,
29464
            KEY `report_id` (`report_id`),
29465
            KEY `branchcode` (`branchcode`),
29466
            CONSTRAINT `reports_branches_ibfk_1` FOREIGN KEY (`report_id`) REFERENCES `saved_sql` (`id`) ON DELETE CASCADE,
29467
            CONSTRAINT `reports_branches_ibfk_2` FOREIGN KEY (`branchcode`) REFERENCES `branches` (`branchcode`) ON DELETE CASCADE
29468
        ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;"
29469
    );
29470
    print "Upgrade to $DBversion done (reports_branches added)\n";
29471
    SetVersion($DBversion);
29472
}
29473
29458
$DBversion = '21.05.00.000';
29474
$DBversion = '21.05.00.000';
29459
if ( CheckVersion($DBversion) ) {
29475
if ( CheckVersion($DBversion) ) {
29460
    NewVersion( $DBversion, "", "Koha 21.05.00 release" );
29476
    NewVersion( $DBversion, "", "Koha 21.05.00 release" );
(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/prefs-menu.inc (+11 lines)
Lines 165-170 Link Here
165
            </li>
165
            </li>
166
        [% END %]
166
        [% END %]
167
167
168
        [% IF ( reports ) %]
169
            <li class="active">
170
                <a title="Reports" href="/cgi-bin/koha/admin/preferences.pl?tab=reports">Reports</a>
171
                [% PROCESS subtabs %]
172
            </li>
173
        [% ELSE %]
174
            <li>
175
                <a title="Reports" href="/cgi-bin/koha/admin/preferences.pl?tab=reports">Reports</a>
176
            </li>
177
        [% END %]
178
168
        [% IF ( searching ) %]
179
        [% IF ( searching ) %]
169
            <li class="active">
180
            <li class="active">
170
                <a title="Searching" href="/cgi-bin/koha/admin/preferences.pl?tab=searching">Searching</a>
181
                <a title="Searching" href="/cgi-bin/koha/admin/preferences.pl?tab=searching">Searching</a>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/reports.pref (+9 lines)
Line 0 Link Here
1
Reports:
2
    Reports Access:
3
     -
4
         - pref: EnableFilteringReports
5
           choices:
6
               1: Enable
7
               0: Disable
8
         - "filtering report access based on staff home library."
9
         - "<br><strong>NOTE:</strong> A NOTE ABOUT THE EFFECTS OF THIS PREFERENCE / SETTING"
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/guided_reports_start.tt (-2 / +26 lines)
Lines 3-8 Link Here
3
[% USE AuthorisedValues %]
3
[% USE AuthorisedValues %]
4
[% USE KohaDates %]
4
[% USE KohaDates %]
5
[% USE Koha %]
5
[% USE Koha %]
6
[% USE Branches %]
6
[% USE TablesSettings %]
7
[% USE TablesSettings %]
7
[% USE HtmlScrubber %]
8
[% USE HtmlScrubber %]
8
[% USE JSON.Escape %]
9
[% USE JSON.Escape %]
Lines 850-855 Link Here
850
                            <input type="hidden" name="reportname" value="[% reportname | html %]" />
851
                            <input type="hidden" name="reportname" value="[% reportname | html %]" />
851
                            <input type="hidden" name="group" value="[% group | html %]" />
852
                            <input type="hidden" name="group" value="[% group | html %]" />
852
                            <input type="hidden" name="subgroup" value="[% subgroup | html %]" />
853
                            <input type="hidden" name="subgroup" value="[% subgroup | html %]" />
854
                            <input type="hidden" name="branches" value="[% branches | html %] />
853
                            <input type="hidden" name="notes" value="[% notes | scrub_html type => 'note' | $raw %]" />
855
                            <input type="hidden" name="notes" value="[% notes | scrub_html type => 'note' | $raw %]" />
854
                            <input type="hidden" name="cache_expiry" value="[% cache_expiry | html %]" />
856
                            <input type="hidden" name="cache_expiry" value="[% cache_expiry | html %]" />
855
                            <input type="hidden" name="cache_expiry_units" value="[% cache_expiry_units | html %]" />
857
                            <input type="hidden" name="cache_expiry_units" value="[% cache_expiry_units | html %]" />
Lines 1434-1440 Link Here
1434
                                <span class="required">Required</span>
1436
                                <span class="required">Required</span>
1435
                            </div>
1437
                            </div>
1436
                        </fieldset>
1438
                        </fieldset>
1437
1439
                        [% IF ( Koha.Preference('EnableFilteringReports') ) %]
1440
                            <fieldset class="rows">
1441
                                <legend>Library limitation:</legend>
1442
                                <div
1443
                                ><label for="library_limitation">Library limitation: </label>
1444
                                   <select id="library_limitation" name="branches" multiple size="10">
1445
                                        [% PROCESS options_for_libraries libraries => Branches.all( selected => report.get_library_limits, unfiltered => 1, do_not_select_my_library => 1 ) %]
1446
                                    </select>
1447
                                    <div class="hint">Limits the use of this report to the selected libraries.</div>
1448
                                </div>
1449
                            </fieldset>
1450
                        [% END %]       
1438
                        <fieldset class="action">
1451
                        <fieldset class="action">
1439
                            <input type="hidden" name="op" value="cud-save" />
1452
                            <input type="hidden" name="op" value="cud-save" />
1440
                            <input type="submit" name="submit" class="btn btn-primary" value="Save report" />
1453
                            <input type="submit" name="submit" class="btn btn-primary" value="Save report" />
Lines 1548-1554 Link Here
1548
                            <br />
1561
                            <br />
1549
                            <span class="required" style="margin-left:30px;">Required</span>
1562
                            <span class="required" style="margin-left:30px;">Required</span>
1550
                        </fieldset>
1563
                        </fieldset>
1551
1564
                        [% IF ( Koha.Preference('EnableFilteringReports') ) %]
1565
                            <fieldset class="rows">
1566
                                <legend>Library limitation:</legend>
1567
                                <div
1568
                                ><label for="library_limitation">Library limitation: </label>
1569
                                   <select id="library_limitation" name="branches" multiple size="10">
1570
                                        [% PROCESS options_for_libraries libraries => Branches.all( selected => report.get_library_limits, unfiltered => 1, do_not_select_my_library => 1 ) %]
1571
                                    </select>
1572
                                    <div class="hint">Limits the use of this report to the selected libraries.</div>
1573
                                </div>
1574
                            </fieldset>
1575
                        [% END %]                        
1552
                        <fieldset class="action">
1576
                        <fieldset class="action">
1553
                            <button class="btn btn-primary" type="submit" name="op" value="cud-update_sql">Update SQL</button>
1577
                            <button class="btn btn-primary" type="submit" name="op" value="cud-update_sql">Update SQL</button>
1554
                            <button class="btn btn-default" type="submit" name="op" value="cud-update_and_run_sql">Update and run SQL</button>
1578
                            <button class="btn btn-default" type="submit" name="op" value="cud-update_and_run_sql">Update and run SQL</button>
(-)a/reports/guided_reports.pl (-24 / +81 lines)
Lines 42-47 use Koha::Notice::Templates; Link Here
42
use Koha::TemplateUtils qw( process_tt );
42
use Koha::TemplateUtils qw( process_tt );
43
use C4::ClassSource     qw( GetClassSources );
43
use C4::ClassSource     qw( GetClassSources );
44
use C4::Scrubber;
44
use C4::Scrubber;
45
use Data::Dumper;
45
46
46
=head1 NAME
47
=head1 NAME
47
48
Lines 57-62 my $input = CGI->new; Link Here
57
my $usecache = Koha::Caches->get_instance->memcached_cache;
58
my $usecache = Koha::Caches->get_instance->memcached_cache;
58
59
59
my $op = $input->param('op') // '';
60
my $op = $input->param('op') // '';
61
print STDERR "DEBUG op: $op\n";
62
63
# my @branches = grep { $_ ne q{} } $input->multi_param('branches');
60
my $flagsrequired;
64
my $flagsrequired;
61
if (   ( $op eq 'add_form' )
65
if (   ( $op eq 'add_form' )
62
    || ( $op eq 'add_form_sql' )
66
    || ( $op eq 'add_form_sql' )
Lines 127-133 if ( !$op ) { Link Here
127
        'showsql'       => 1,
131
        'showsql'       => 1,
128
        'mana_success'  => scalar $input->param('mana_success'),
132
        'mana_success'  => scalar $input->param('mana_success'),
129
        'mana_id'       => $report->{mana_id},
133
        'mana_id'       => $report->{mana_id},
130
        'mana_comments' => $report->{comments}
134
        'mana_comments' => $report->{comments},
131
    );
135
    );
132
136
133
} elsif ( $op eq 'edit_form' ) {
137
} elsif ( $op eq 'edit_form' ) {
Lines 136-141 if ( !$op ) { Link Here
136
    my $group    = $report->report_group;
140
    my $group    = $report->report_group;
137
    my $subgroup = $report->report_subgroup;
141
    my $subgroup = $report->report_subgroup;
138
    my $tables   = get_tables();
142
    my $tables   = get_tables();
143
139
    $template->param(
144
    $template->param(
140
        'sql'                   => $report->savedsql,
145
        'sql'                   => $report->savedsql,
141
        'reportname'            => $report->report_name,
146
        'reportname'            => $report->report_name,
Lines 148-158 if ( !$op ) { Link Here
148
        'editsql'               => 1,
153
        'editsql'               => 1,
149
        'mana_id'               => $report->{mana_id},
154
        'mana_id'               => $report->{mana_id},
150
        'mana_comments'         => $report->{comments},
155
        'mana_comments'         => $report->{comments},
151
        'tables'                => $tables
156
        'tables'                => $tables,
157
        'report'                => $report,
152
    );
158
    );
153
159
154
} elsif ( $op eq 'cud-update_sql' || $op eq 'cud-update_and_run_sql' ) {
160
} elsif ( $op eq 'cud-update_sql' || $op eq 'cud-update_and_run_sql' ) {
155
    my $id                 = $input->param('id');
161
    my $id                 = $input->param('id');
162
    my $report             = Koha::Reports->find($id);
156
    my $sql                = $input->param('sql');
163
    my $sql                = $input->param('sql');
157
    my $reportname         = $input->param('reportname');
164
    my $reportname         = $input->param('reportname');
158
    my $group              = $input->param('group');
165
    my $group              = $input->param('group');
Lines 163-171 if ( !$op ) { Link Here
163
    my $public             = $input->param('public');
170
    my $public             = $input->param('public');
164
    my $save_anyway        = $input->param('save_anyway');
171
    my $save_anyway        = $input->param('save_anyway');
165
    my @errors;
172
    my @errors;
166
    my $tables = get_tables();
173
    my $tables   = get_tables();
174
    my @branches = grep { $_ ne q{} } $input->multi_param('branches');
167
175
168
    # if we have the units, then we came from creating a report from SQL and thus need to handle converting units
169
    if ($cache_expiry_units) {
176
    if ($cache_expiry_units) {
170
        if ( $cache_expiry_units eq "minutes" ) {
177
        if ( $cache_expiry_units eq "minutes" ) {
171
            $cache_expiry *= 60;
178
            $cache_expiry *= 60;
Lines 211-216 if ( !$op ) { Link Here
211
                'problematic_authvals' => $problematic_authvals,
218
                'problematic_authvals' => $problematic_authvals,
212
                'warn_authval_problem' => 1,
219
                'warn_authval_problem' => 1,
213
                'phase_update'         => 1,
220
                'phase_update'         => 1,
221
                'branches'             => @branches,
222
                'report'               => $report,
214
            );
223
            );
215
224
216
        } else {
225
        } else {
Lines 226-234 if ( !$op ) { Link Here
226
                    notes        => $notes,
235
                    notes        => $notes,
227
                    public       => $public,
236
                    public       => $public,
228
                    cache_expiry => $cache_expiry,
237
                    cache_expiry => $cache_expiry,
238
239
                    # report       => $report,
229
                }
240
                }
230
            );
241
            );
231
242
243
            $report->store;
244
            $report->replace_library_limits( \@branches );
245
232
            my $editsql = 1;
246
            my $editsql = 1;
233
            if ( $op eq 'cud-update_and_run_sql' ) {
247
            if ( $op eq 'cud-update_and_run_sql' ) {
234
                $editsql = 0;
248
                $editsql = 0;
Lines 245-251 if ( !$op ) { Link Here
245
                'cache_expiry'          => $cache_expiry,
259
                'cache_expiry'          => $cache_expiry,
246
                'public'                => $public,
260
                'public'                => $public,
247
                'usecache'              => $usecache,
261
                'usecache'              => $usecache,
248
                'tables'                => $tables
262
                'tables'                => $tables,
263
264
                # 'branches'              => @branches,
265
                'report' => $report,
249
            );
266
            );
250
            logaction( "REPORTS", "MODIFY", $id, "$reportname | $sql" ) if C4::Context->preference("ReportsLog");
267
            logaction( "REPORTS", "MODIFY", $id, "$reportname | $sql" ) if C4::Context->preference("ReportsLog");
251
        }
268
        }
Lines 489-494 if ( !$op ) { Link Here
489
    my $area = $input->param('area');
506
    my $area = $input->param('area');
490
    my $sql  = $input->param('sql');
507
    my $sql  = $input->param('sql');
491
    my $type = $input->param('type');
508
    my $type = $input->param('type');
509
492
    $template->param(
510
    $template->param(
493
        'save'                  => 1,
511
        'save'                  => 1,
494
        'area'                  => $area,
512
        'area'                  => $area,
Lines 514-519 if ( !$op ) { Link Here
514
    my $public             = $input->param('public');
532
    my $public             = $input->param('public');
515
    my $save_anyway        = $input->param('save_anyway');
533
    my $save_anyway        = $input->param('save_anyway');
516
    my $tables             = get_tables();
534
    my $tables             = get_tables();
535
    my @branches           = grep { $_ ne q{} } $input->multi_param('branches');
517
536
518
    # if we have the units, then we came from creating a report from SQL and thus need to handle converting units
537
    # if we have the units, then we came from creating a report from SQL and thus need to handle converting units
519
    if ($cache_expiry_units) {
538
    if ($cache_expiry_units) {
Lines 591-596 if ( !$op ) { Link Here
591
                    public         => $public,
610
                    public         => $public,
592
                }
611
                }
593
            );
612
            );
613
            my $report = Koha::Reports->find($id);
614
            $report->replace_library_limits( \@branches );
615
594
            logaction( "REPORTS", "ADD", $id, "$name | $sql" ) if C4::Context->preference("ReportsLog");
616
            logaction( "REPORTS", "ADD", $id, "$name | $sql" ) if C4::Context->preference("ReportsLog");
595
            $template->param(
617
            $template->param(
596
                'save_successful'       => 1,
618
                'save_successful'       => 1,
Lines 603-609 if ( !$op ) { Link Here
603
                'cache_expiry'          => $cache_expiry,
625
                'cache_expiry'          => $cache_expiry,
604
                'public'                => $public,
626
                'public'                => $public,
605
                'usecache'              => $usecache,
627
                'usecache'              => $usecache,
606
                'tables'                => $tables
628
                'tables'                => $tables,
629
                'report'                => $report,
607
            );
630
            );
608
        }
631
        }
609
    }
632
    }
Lines 746-765 if ( !$op ) { Link Here
746
769
747
} elsif ( $op eq 'add_form_sql' || $op eq 'duplicate' ) {
770
} elsif ( $op eq 'add_form_sql' || $op eq 'duplicate' ) {
748
771
749
    my ( $group, $subgroup, $sql, $reportname, $notes );
772
    my ( $group, $subgroup, $sql, $reportname, $notes, @branches, $report );
750
    if ( $input->param('sql') ) {
773
    if ( $input->param('sql') ) {
751
        $group      = $input->param('report_group');
774
        $group      = $input->param('report_group');
752
        $subgroup   = $input->param('report_subgroup');
775
        $subgroup   = $input->param('report_subgroup');
753
        $sql        = $input->param('sql')        // '';
776
        $sql        = $input->param('sql')        // '';
754
        $reportname = $input->param('reportname') // '';
777
        $reportname = $input->param('reportname') // '';
755
        $notes      = $input->param('notes')      // '';
778
        $notes      = $input->param('notes')      // '';
779
        @branches   = grep { $_ ne q{} } $input->multi_param('branches');
780
756
    } elsif ( my $report_id = $input->param('id') ) {
781
    } elsif ( my $report_id = $input->param('id') ) {
757
        my $report = Koha::Reports->find($report_id);
782
        $report     = Koha::Reports->find($report_id);
758
        $group      = $report->report_group;
783
        $group      = $report->report_group;
759
        $subgroup   = $report->report_subgroup;
784
        $subgroup   = $report->report_subgroup;
760
        $sql        = $report->savedsql    // '';
785
        $sql        = $report->savedsql    // '';
761
        $reportname = $report->report_name // '';
786
        $reportname = $report->report_name // '';
762
        $notes      = $report->notes       // '';
787
        $notes      = $report->notes       // '';
788
        @branches   = grep { $_ ne q{} } $input->multi_param('branches');
789
763
    }
790
    }
764
791
765
    my $tables = get_tables();
792
    my $tables = get_tables();
Lines 775-780 if ( !$op ) { Link Here
775
        'usecache'              => $usecache,
802
        'usecache'              => $usecache,
776
        'tables'                => $tables,
803
        'tables'                => $tables,
777
804
805
        # 'branches'              => \@branches,
806
        'report' => $report,
807
778
    );
808
    );
779
}
809
}
780
810
Lines 1081-1104 if ( $op eq 'list' || $op eq 'convert' ) { Link Here
1081
    my $subgroup = $input->param('subgroup');
1111
    my $subgroup = $input->param('subgroup');
1082
    $filter->{group}    = $group;
1112
    $filter->{group}    = $group;
1083
    $filter->{subgroup} = $subgroup;
1113
    $filter->{subgroup} = $subgroup;
1084
    my $reports = get_saved_reports($filter);
1114
1085
    my $has_obsolete_reports;
1115
    my $pref_enable_filtering_reports = C4::Context->preference("EnableFilteringReports");
1086
    for my $report (@$reports) {
1116
    if ( $pref_enable_filtering_reports == "1" ) {
1087
        $report->{results} = C4::Reports::Guided::get_results( $report->{id} );
1117
        my $reports_with_library_limits_results =
1088
        if ( $report->{savedsql} =~ m|biblioitems| and $report->{savedsql} =~ m|marcxml| ) {
1118
            Koha::Reports->search_with_library_limits( {}, {}, C4::Context::mybranch() );
1089
            $report->{seems_obsolete} = 1;
1119
        my $reports_list = $reports_with_library_limits_results->unblessed;
1090
            $has_obsolete_reports++;
1120
        my $has_obsolete_reports;
1121
        while ( my $report = $reports_with_library_limits_results->next ) {
1122
            $report->{results} = C4::Reports::Guided::get_results( $report->{id} );
1123
            if ( $report->{savedsql} =~ m|biblioitems| and $report->{savedsql} =~ m|marcxml| ) {
1124
                $report->{seems_obsolete} = 1;
1125
                $has_obsolete_reports++;
1126
            }
1127
            $template->param(
1128
                'manamsg'               => $input->param('manamsg') || '',
1129
                'saved1'                => 1,
1130
                'savedreports'          => $reports_list,
1131
                'usecache'              => $usecache,
1132
                'groups_with_subgroups' => groups_with_subgroups( $group, $subgroup ),
1133
                filters                 => $filter,
1134
                has_obsolete_reports    => $has_obsolete_reports,
1135
            );
1091
        }
1136
        }
1137
    } else {
1138
1139
        my $reports = get_saved_reports($filter);
1140
        my $has_obsolete_reports;
1141
1142
        for my $report (@$reports) {
1143
            $report->{results} = C4::Reports::Guided::get_results( $report->{id} );
1144
            if ( $report->{savedsql} =~ m|biblioitems| and $report->{savedsql} =~ m|marcxml| ) {
1145
                $report->{seems_obsolete} = 1;
1146
                $has_obsolete_reports++;
1147
            }
1148
        }
1149
        $template->param(
1150
            'manamsg'               => $input->param('manamsg') || '',
1151
            'saved1'                => 1,
1152
            'savedreports'          => $reports,
1153
            'usecache'              => $usecache,
1154
            'groups_with_subgroups' => groups_with_subgroups( $group, $subgroup ),
1155
            filters                 => $filter,
1156
            has_obsolete_reports    => $has_obsolete_reports,
1157
        );
1092
    }
1158
    }
1093
    $template->param(
1094
        'manamsg'               => $input->param('manamsg') || '',
1095
        'saved1'                => 1,
1096
        'savedreports'          => $reports,
1097
        'usecache'              => $usecache,
1098
        'groups_with_subgroups' => groups_with_subgroups( $group, $subgroup ),
1099
        filters                 => $filter,
1100
        has_obsolete_reports    => $has_obsolete_reports,
1101
    );
1102
}
1159
}
1103
1160
1104
# pass $sth, get back an array of names for the column headers
1161
# pass $sth, get back an array of names for the column headers
(-)a/t/db_dependent/Koha/Reports.t (-2 / +37 lines)
Lines 18-24 Link Here
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::NoWarnings;
20
use Test::NoWarnings;
21
use Test::More tests => 9;
21
use Test::More tests => 10;
22
22
23
use Koha::Report;
23
use Koha::Report;
24
use Koha::Reports;
24
use Koha::Reports;
Lines 185-188 subtest '_might_add_limit' => sub { Link Here
185
    );
185
    );
186
};
186
};
187
187
188
subtest 'reports_branches are added and removed from report_branches table' => sub {
189
    plan tests => 4;
190
191
    my $updated_nb_of_reports = Koha::Reports->search->count;
192
    my $report                = Koha::Report->new(
193
        {
194
            report_name => 'report_name_for_test_1',
195
            savedsql    => 'SELECT * FROM items WHERE itemnumber IN <<Test|list>>',
196
        }
197
    )->store;
198
199
    my $id       = $report->id;
200
    my $library1 = $builder->build_object( { class => 'Koha::Libraries' } );
201
    my $library2 = $builder->build_object( { class => 'Koha::Libraries' } );
202
    my $library3 = $builder->build_object( { class => 'Koha::Libraries' } );
203
    my @branches = ( $library1->branchcode, $library2->branchcode, $library3->branchcode );
204
205
    $report->replace_library_limits( \@branches );
206
207
    my @branches_loop = $report->get_library_limits->as_list;
208
    is( scalar @branches_loop, 3, '3 branches added to report_branches table' );
209
210
    $report->replace_library_limits( [ $library1->branchcode, $library2->branchcode ] );
211
212
    @branches_loop = $report->get_library_limits->as_list;
213
    is( scalar @branches_loop, 2, '1 branch removed from report_branches table' );
214
215
    $report->delete;
216
    is( Koha::Reports->search->count, $updated_nb_of_reports, 'Report deleted, count is back to original' );
217
    is(
218
        $schema->resultset('ReportsBranch')->search( { report_id => $id } )->count,
219
        0,
220
        'No branches left in reports_branches table after report deletion'
221
    );
222
};
223
188
$schema->storage->txn_rollback;
224
$schema->storage->txn_rollback;
189
- 

Return to bug 16631