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

Return to bug 9573