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

(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/reports/itemslost.tt (-2 / +16 lines)
Lines 39-45 Link Here
39
                <a href="#" class="ClearAll"><i class="fa fa-remove"></i> Clear all</a>
39
                <a href="#" class="ClearAll"><i class="fa fa-remove"></i> Clear all</a>
40
                <span class="itemselection_actions">
40
                <span class="itemselection_actions">
41
                  | Actions:
41
                  | Actions:
42
                  <a class="itemselection_action_export"><i class="fa fa-trash"></i> Export selected items</a>
42
                  [% IF csv_profiles.count %]
43
                      <a class="itemselection_action_export"><i class="fa fa-download"></i> Export selected items</a>
44
                      Using the following CSV profile:
45
                      <select name="csv_profile_id" id="csv_profile_id">
46
                          [% FOREACH csv_profile IN csv_profiles %]
47
                              <option value="[% csv_profile.export_format_id %]">[% csv_profile.profile %]</<option>
48
                          [% END %]
49
                      </select>
50
                  [% ELSE %]
51
                      <span class="itemselection_action_export" title="You should create a CSV profile for export_lost_items"><i class="fa fa-download"></i> Export selected items</a>
52
                  [% END %]
43
                </span>
53
                </span>
44
        </div>
54
        </div>
45
55
Lines 180-186 Link Here
180
                    itemnumbers.push($(this).val());
190
                    itemnumbers.push($(this).val());
181
                });
191
                });
182
                if (itemnumbers.length > 0) {
192
                if (itemnumbers.length > 0) {
183
                    var url = '/cgi-bin/koha/tools/batchMod.pl?op=show';
193
                    var csv_profile_id = $("#csv_profile_id  option:selected").val();
194
                    var url = '/cgi-bin/koha/reports/itemslost.pl?op=export&csv_profile_id='+csv_profile_id;
184
                    url += '&itemnumber=' + itemnumbers.join('&itemnumber=');
195
                    url += '&itemnumber=' + itemnumbers.join('&itemnumber=');
185
                    $('a.itemselection_action_export').attr('href', url);
196
                    $('a.itemselection_action_export').attr('href', url);
186
                } else {
197
                } else {
Lines 203-208 Link Here
203
            $("input[name='itemnumber'][type='checkbox']").change(function() {
214
            $("input[name='itemnumber'][type='checkbox']").change(function() {
204
                itemSelectionBuildActionLinks();
215
                itemSelectionBuildActionLinks();
205
            });
216
            });
217
            $("#csv_profile_id").change(function() {
218
                itemSelectionBuildActionLinks();
219
            });
206
220
207
            $(".SelectAll").on("click",function(e){
221
            $(".SelectAll").on("click",function(e){
208
                e.preventDefault();
222
                e.preventDefault();
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/csv-profiles.tt (-1 / +2 lines)
Lines 91-96 Link Here
91
    [% IF used_for_code == 'export_records' %] Export records
91
    [% IF used_for_code == 'export_records' %] Export records
92
    [% ELSIF used_for_code == 'late_issues' %] Late serial issues claims
92
    [% ELSIF used_for_code == 'late_issues' %] Late serial issues claims
93
    [% ELSIF used_for_code == 'export_basket' %] Basket export in acquisition
93
    [% ELSIF used_for_code == 'export_basket' %] Basket export in acquisition
94
    [% ELSIF used_for_code == 'export_lost_items' %] Export lost items in report
94
    [% ELSE %] Unknown usage
95
    [% ELSE %] Unknown usage
95
    [% END %]
96
    [% END %]
96
[% END %]
97
[% END %]
Lines 131-137 Link Here
131
                <li class="sql_specific">
132
                <li class="sql_specific">
132
                    <label for="used_for_sql">Usage: </label>
133
                    <label for="used_for_sql">Usage: </label>
133
                    <select id="used_for_sql" name="used_for_sql">
134
                    <select id="used_for_sql" name="used_for_sql">
134
                        [% FOREACH used_for IN [ 'late_issues' 'export_basket' ] %]
135
                        [% FOREACH used_for IN [ 'late_issues' 'export_basket' 'export_lost_items' ] %]
135
                        [% IF csv_profile.used_for == used_for %]
136
                        [% IF csv_profile.used_for == used_for %]
136
                            <option value="[% used_for %]" selected="selected">[% PROCESS used_for_description used_for_code = used_for %]</option>
137
                            <option value="[% used_for %]" selected="selected">[% PROCESS used_for_description used_for_code = used_for %]</option>
137
                        [% ELSE %]
138
                        [% ELSE %]
(-)a/reports/itemslost.pl (-3 / +60 lines)
Lines 34-39 use C4::Biblio; Link Here
34
use C4::Items;
34
use C4::Items;
35
35
36
use Koha::AuthorisedValues;
36
use Koha::AuthorisedValues;
37
use Koha::CsvProfiles;
37
use Koha::DateUtils;
38
use Koha::DateUtils;
38
39
39
my $query = new CGI;
40
my $query = new CGI;
Lines 50-57 my ( $template, $loggedinuser, $cookie ) = get_template_and_user( Link Here
50
51
51
my $params = $query->Vars;
52
my $params = $query->Vars;
52
my $get_items = $params->{'get_items'};
53
my $get_items = $params->{'get_items'};
53
54
my $op = $query->param('op') || '';
54
if ($get_items) {
55
56
if ( $op eq 'export' ) {
57
    my @itemnumbers = $query->multi_param('itemnumber');
58
    my $csv_profile_id = $query->param('csv_profile_id');
59
    my @rows;
60
    if ($csv_profile_id) {
61
        # FIXME This following code has the same logic as GetBasketAsCSV
62
        # We should refactor all the CSV export code
63
        # Note: For MARC it is already done in Koha::Exporter::Record but not for SQL CSV profiles type
64
        my $csv_profile = Koha::CsvProfiles->find( $csv_profile_id );
65
        die "There is no valid csv profile given" unless $csv_profile;
66
67
        my $csv = Text::CSV_XS->new({'quote_char'=>'"','escape_char'=>'"','sep_char'=>$csv_profile->csv_separator,'binary'=>1});
68
        my $csv_profile_content = $csv_profile->content;
69
        my ( @headers, @fields );
70
        while ( $csv_profile_content =~ /
71
            ([^=\|]+) # header
72
            =?
73
            ([^\|]*) # fieldname (table.row or row)
74
            \|? /gxms
75
        ) {
76
            my $header = $1;
77
            my $field = ($2 eq '') ? $1 : $2;
78
79
            $header =~ s/^\s+|\s+$//g; # Trim whitespaces
80
            push @headers, $header;
81
82
            $field =~ s/[^\.]*\.{1}//; # Remove the table name if exists.
83
            $field =~ s/^\s+|\s+$//g; # Trim whitespaces
84
            push @fields, $field;
85
        }
86
        my $items = Koha::Items->search({ itemnumber => { -in => \@itemnumbers } });
87
        while ( my $item = $items->next ) {
88
            my @row;
89
            my $all_fields = $item->unblessed;
90
            $all_fields = { %$all_fields, %{$item->biblio->unblessed}, %{$item->biblioitem->unblessed} };
91
            for my $field (@fields) {
92
                push @row, $all_fields->{$field};
93
            }
94
            push @rows, \@row;
95
        }
96
        my $content = join( $csv_profile->csv_separator, @headers ) . "\n";
97
        for my $row ( @rows ) {
98
            $csv->combine(@$row);
99
            my $string = $csv->string;
100
            $content .= $string . "\n";
101
        }
102
        print $query->header(
103
            -type       => 'text/csv',
104
            -attachment => 'lost_items.csv',
105
        );
106
        print $content;
107
        exit;
108
    }
109
} elsif ( $get_items ) {
55
    my $branchfilter     = $params->{'branchfilter'}     || undef;
110
    my $branchfilter     = $params->{'branchfilter'}     || undef;
56
    my $barcodefilter    = $params->{'barcodefilter'}    || undef;
111
    my $barcodefilter    = $params->{'barcodefilter'}    || undef;
57
    my $itemtypesfilter  = $params->{'itemtypesfilter'}  || undef;
112
    my $itemtypesfilter  = $params->{'itemtypesfilter'}  || undef;
Lines 96-103 if ($get_items) { Link Here
96
# getting all itemtypes
151
# getting all itemtypes
97
my $itemtypes = Koha::ItemTypes->search_with_localization;
152
my $itemtypes = Koha::ItemTypes->search_with_localization;
98
153
154
my $csv_profiles = Koha::CsvProfiles->search({ type => 'sql', used_for => 'export_lost_items' });
155
99
$template->param(
156
$template->param(
100
    itemtypes => $itemtypes,
157
    itemtypes => $itemtypes,
158
    csv_profiles => $csv_profiles,
101
);
159
);
102
160
103
# writing the template
161
# writing the template
104
- 

Return to bug 9573