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

(-)a/Koha/Cash/Register.pm (-2 / +67 lines)
Lines 42-51 Return the library linked to this cash register Link Here
42
=cut
42
=cut
43
43
44
sub library {
44
sub library {
45
    my ( $self ) = @_;
45
    my ($self) = @_;
46
    my $rs = $self->_result->branch;
46
    my $rs = $self->_result->branch;
47
    return unless $rs;
47
    return unless $rs;
48
    return Koha::Library->_new_from_dbic( $rs );
48
    return Koha::Library->_new_from_dbic($rs);
49
}
50
51
=head3 store
52
53
Local store method to prevent direct manipulation of the 'branch_default' field
54
55
=cut
56
57
sub store {
58
    my ($self) = @_;
59
    $self->_result->result_source->schema->txn_do(
60
        sub {
61
            if ( $self->_result->is_column_changed('branch_default') ) {
62
                Koha::Exceptions::Object::ReadOnlyProperty->throw(
63
                    property => 'branch_default' );
64
            }
65
            else {
66
                if ($self->_result->is_column_changed('branch') && $self->branch_default) {
67
                }
68
                $self = $self->SUPER::store;
69
            }
70
        }
71
    );
72
    return $self;
73
}
74
75
=head3 make_default
76
77
Set the current cash register as the branch default
78
79
=cut
80
81
sub make_default {
82
    my ($self) = @_;
83
84
    $self->_result->result_source->schema->txn_do(
85
        sub {
86
            my $registers =
87
              Koha::Cash::Registers->search( { branch => $self->branch } );
88
            $registers->update( { branch_default => 0 } );
89
            $self->set( { branch_default => 1 } );
90
            $self->SUPER::store;
91
        }
92
    );
93
94
    return $self;
95
}
96
97
=head3 drop_default
98
99
Drop the current cash register as the branch default
100
101
=cut
102
103
sub drop_default {
104
    my ($self) = @_;
105
106
    $self->_result->result_source->schema->txn_do(
107
        sub {
108
            $self->set( { branch_default => 0 } );
109
            $self->SUPER::store;
110
        }
111
    );
112
113
    return $self;
49
}
114
}
50
115
51
=head2 Internal methods
116
=head2 Internal methods
(-)a/Koha/Exceptions/Object.pm (+8 lines)
Lines 41-46 use Exception::Class ( Link Here
41
        isa => 'Koha::Exceptions::Object',
41
        isa => 'Koha::Exceptions::Object',
42
        description => "Invalid property",
42
        description => "Invalid property",
43
    },
43
    },
44
    'Koha::Exceptions::Object::ReadOnlyProperty' => {
45
        isa => 'Koha::Exceptions::Object',
46
        description => "Change of readonly property attempted",
47
        fields => [ 'property' ],
48
    },
44
    'Koha::Exceptions::Object::MethodNotCoveredByTests' => {
49
    'Koha::Exceptions::Object::MethodNotCoveredByTests' => {
45
        isa => 'Koha::Exceptions::Object',
50
        isa => 'Koha::Exceptions::Object',
46
        description => "Method not covered by tests",
51
        description => "Method not covered by tests",
Lines 64-69 sub full_message { Link Here
64
        elsif ( $self->isa('Koha::Exceptions::Object::BadValue') ) {
69
        elsif ( $self->isa('Koha::Exceptions::Object::BadValue') ) {
65
            $msg = sprintf("Invalid value passed, %s=%s expected type is %s", $self->property, $self->value, $self->type );
70
            $msg = sprintf("Invalid value passed, %s=%s expected type is %s", $self->property, $self->value, $self->type );
66
        }
71
        }
72
        elsif ( $self->isa('Koha::Exceptions::Object::ReadOnlyProperty') ) {
73
            $msg = sprintf("Invalid attempt to change readonly property: %s", $self->property );
74
        }
67
    }
75
    }
68
76
69
    return $msg;
77
    return $msg;
(-)a/admin/cash_registers.pl (-1 / +30 lines)
Lines 128-136 elsif ( $op eq 'unarchive' ) { Link Here
128
    $op = 'list';
128
    $op = 'list';
129
}
129
}
130
130
131
elsif ( $op eq 'make_default' ) {
132
    if ($registerid) {
133
        try {
134
            my $cash_register = Koha::Cash::Registers->find($registerid);
135
            $cash_register->make_default;
136
            push @messages, { code => 'success_on_default', type => 'message' };
137
        }
138
        catch {
139
            push @messages, { code => 'error_on_default', type => 'alert' };
140
        }
141
    }
142
    $op = 'list';
143
}
144
elsif ( $op eq 'drop_default' ) {
145
    if ($registerid) {
146
        try {
147
            my $cash_register = Koha::Cash::Registers->find($registerid);
148
            $cash_register->drop_default;
149
            push @messages, { code => 'success_on_default', type => 'message' };
150
        }
151
        catch {
152
            push @messages, { code => 'error_on_default', type => 'alert' };
153
        }
154
    }
155
    $op = 'list';
156
}
157
158
131
if ( $op eq 'list' ) {
159
if ( $op eq 'list' ) {
132
    my $cash_registers =
160
    my $cash_registers =
133
      Koha::Cash::Registers->search( {}, { prefetch => 'branch' } );
161
      Koha::Cash::Registers->search( {},
162
        { prefetch => 'branch', order_by => { -asc => [qw/branch name/] } } );
134
    $template->param( cash_registers => $cash_registers, );
163
    $template->param( cash_registers => $cash_registers, );
135
}
164
}
136
165
(-)a/koha-tmpl/intranet-tmpl/prog/css/src/_tables.scss (+6 lines)
Lines 267-272 tr { Link Here
267
            }
267
            }
268
        }
268
        }
269
    }
269
    }
270
271
    &.default {
272
        td {
273
            font-weight: bold;
274
        }
275
    }
270
}
276
}
271
277
272
.table_borrowers {
278
.table_borrowers {
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/cash_registers.tt (-17 / +59 lines)
Lines 1-9 Link Here
1
[% USE raw %]
1
[% USE raw %]
2
[% USE Asset %]
2
[% USE Asset %]
3
[% USE Branches %]
3
[% SET footerjs = 1 %]
4
[% SET footerjs = 1 %]
4
[% USE ColumnsSettings %]
5
[% INCLUDE 'doc-head-open.inc' %]
5
[% INCLUDE 'doc-head-open.inc' %]
6
<title>Koha &rsaquo; Administration &rsaquo; Cash Registers
6
<title>Koha &rsaquo; Administration &rsaquo; Cash registers
7
[% IF op == 'add_form' %]
7
[% IF op == 'add_form' %]
8
    &rsaquo;[% IF cash_register %]Modify cash register[% ELSE %]New cash register [% cash_register.id | html %][% END %]
8
    &rsaquo;[% IF cash_register %]Modify cash register[% ELSE %]New cash register [% cash_register.id | html %][% END %]
9
[% ELSIF op == 'delete_confirm' %]
9
[% ELSIF op == 'delete_confirm' %]
Lines 36-55 Link Here
36
                [% FOREACH m IN messages %]
36
                [% FOREACH m IN messages %]
37
                <div class="dialog [% m.type | html %]">
37
                <div class="dialog [% m.type | html %]">
38
                    [% SWITCH m.code %]
38
                    [% SWITCH m.code %]
39
                    [% CASE 'error_on_update' %]
39
                    [% CASE 'success_on_insert' %]
40
                        An error occurred when updating this cash register.
40
                        Cash register added successfully.
41
                    [% CASE 'error_on_insert' %]
41
                    [% CASE 'error_on_insert' %]
42
                        An error occurred when adding this cash register.
42
                        An error occurred when adding this cash register.
43
                    [% CASE 'success_on_update' %]
43
                    [% CASE 'success_on_update' %]
44
                        Cash register updated successfully.
44
                        Cash register updated successfully.
45
                    [% CASE 'success_on_insert' %]
45
                    [% CASE 'error_on_update' %]
46
                        Cash register added successfully.
46
                        An error occurred when updating this cash register.
47
                    [% CASE 'success_on_default' %]
48
                        Branch default updated successfully.
49
                    [% CASE 'error_on_update' %]
50
                        An error on setting branch default.
47
                    [% CASE 'success_on_archive' %]
51
                    [% CASE 'success_on_archive' %]
48
                        Cash register archived successfully.
52
                        Cash register archived successfully.
49
                    [% CASE 'success_on_restore' %]
53
                    [% CASE 'success_on_restore' %]
50
                        Cash register restored successfully.
54
                        Cash register restored successfully.
51
                    [% CASE 'success_on_delete' %]
52
                        Cash register deleted successfully.
53
                    [% CASE %]
55
                    [% CASE %]
54
                        [% m.code | html %]
56
                        [% m.code | html %]
55
                    [% END %]
57
                    [% END %]
Lines 81-87 Link Here
81
                                <input type="text" name="description" id="description" value="[% cash_register.description %]"/>
83
                                <input type="text" name="description" id="description" value="[% cash_register.description %]"/>
82
                            </li>
84
                            </li>
83
                            <li>
85
                            <li>
84
                                <label for="branch">Branch: </label>
86
                                <label for="branch">Library: </label>
85
                                <select id="branch" name="branch">
87
                                <select id="branch" name="branch">
86
                                [% FOREACH branch IN branch_list %]
88
                                [% FOREACH branch IN branch_list %]
87
                                [% IF cash_register.branch == branch.branchcode %]
89
                                [% IF cash_register.branch == branch.branchcode %]
Lines 116-142 Link Here
116
                   <a class="btn btn-default" id="newcashregister" href="/cgi-bin/koha/admin/cash_registers.pl?op=add_form"><i class="fa fa-plus"></i> New cash register</a>
118
                   <a class="btn btn-default" id="newcashregister" href="/cgi-bin/koha/admin/cash_registers.pl?op=add_form"><i class="fa fa-plus"></i> New cash register</a>
117
               </div>
119
               </div>
118
120
119
               <h3>Cash Registers</h3>
121
               <h3>Cash registers for <select id="branch_filter" name="branch_filter">
122
                       <option value=""></option>
123
                       [% PROCESS options_for_libraries libraries => Branches.all( selected => branchcode, unfiltered => 1, ) %]
124
                   </select>
125
               </h3>
126
120
               [% IF cash_registers.count %]
127
               [% IF cash_registers.count %]
121
               <table id="table_cash_registers">
128
               <table id="table_cash_registers">
122
                   <thead>
129
                   <thead>
123
                       <th>Id</th>
124
                       <th>Name</th>
130
                       <th>Name</th>
125
                       <th>Description</th>
131
                       <th>Description</th>
126
                       <th>Branch</th>
132
                       <th>Library</th>
133
                       <th>Default</th>
127
                       <th>Initial float</th>
134
                       <th>Initial float</th>
128
                       <th>Actions</th>
135
                       <th>Actions</th>
129
                   </thead>
136
                   </thead>
130
                   <tbody>
137
                   <tbody>
131
                   [% FOREACH cash_register IN cash_registers %]
138
                   [% FOREACH cash_register IN cash_registers %]
139
                   [% IF cash_register.branch_default %]
140
                   <tr class="default">
141
                   [% ELSE %]
132
                   <tr>
142
                   <tr>
133
                       <td>[% cash_register.id %]</td>
143
                   [% END %]
134
                       <td>[% cash_register.name %]</td>
144
                       <td>[% cash_register.name %]</td>
135
                       <td>[% cash_register.description %]</td>
145
                       <td>[% cash_register.description %]</td>
136
                       <td>[% cash_register.library.branchname %]</td>
146
                       <td>[% cash_register.library.branchname %]</td>
147
                       <td>[% IF cash_register.branch_default %]Yes[% ELSE %]No[% END %]</td>
137
                       <td>[% cash_register.starting_float %]</td>
148
                       <td>[% cash_register.starting_float %]</td>
138
                       [% IF cash_register.archived == '0' %]
149
                       [% IF cash_register.archived == '0' %]
139
                       <td class="actions"><a class="btn btn-default btn-xs" href="cash_registers.pl?op=add_form&amp;id=[% cash_register.id | uri %]"><i class="fa fa-pencil"></i> Edit</a><a class="btn btn-default btn-xs" href="cash_registers.pl?op=archive&amp;id=[% cash_register.id %]"><i class="fa fa-archive"></i> Archive</a></td>
150
                       <td class="actions">
151
                           <a class="btn btn-default btn-xs" href="cash_registers.pl?op=add_form&amp;id=[% cash_register.id | uri %]"><i class="fa fa-pencil"></i> Edit</a>
152
                           [% IF cash_register.branch_default %]
153
                           <a class="btn btn-default btn-xs" href="cash_registers.pl?op=drop_default&amp;id=[% cash_register.id %]"><i class="fa fa-archive"></i> Drop default</a>
154
                           [% ELSE %]
155
                           <a class="btn btn-default btn-xs" href="cash_registers.pl?op=make_default&amp;id=[% cash_register.id %]"><i class="fa fa-archive"></i> Make default</a>
156
                           [% END %]
157
                           <a class="btn btn-default btn-xs" href="cash_registers.pl?op=archive&amp;id=[% cash_register.id %]"><i class="fa fa-archive"></i> Archive</a>
158
                       </td>
140
                       [% ELSE %]
159
                       [% ELSE %]
141
                       <td class="actions"><a class="btn btn-default btn-xs" href="cash_registers.pl?op=unarchive&amp;id=[% cash_register.id %]"><i class="fa fa-trash-restore"></i> Restore</a></td>
160
                       <td class="actions"><a class="btn btn-default btn-xs" href="cash_registers.pl?op=unarchive&amp;id=[% cash_register.id %]"><i class="fa fa-trash-restore"></i> Restore</a></td>
142
                       [% END %]
161
                       [% END %]
Lines 161-175 Link Here
161
[% MACRO jsinclude BLOCK %]
180
[% MACRO jsinclude BLOCK %]
162
    [% Asset.js("js/admin-menu.js") | $raw %]
181
    [% Asset.js("js/admin-menu.js") | $raw %]
163
    [% INCLUDE 'datatables.inc' %]
182
    [% INCLUDE 'datatables.inc' %]
164
165
    <script>
183
    <script>
184
    function filterDataTable( table, column, term ){
185
        if( column ){
186
            table.column( column ).search( term ).draw();
187
        } else {
188
            table.search( term ).draw();
189
        }
190
        clearFilter( term );
191
    }
192
193
    function clearFilter( term ){
194
        if( term == "" ){
195
            $(".dt_button_clear_filter").addClass("disabled");
196
        } else {
197
            $(".dt_button_clear_filter").removeClass("disabled");
198
        }
199
    }
200
166
    $(document).ready(function() {
201
    $(document).ready(function() {
167
        $("#table_cash_registers").dataTable($.extend(true, {}, dataTablesDefaults, {
202
        var crtable = $("#table_cash_registers").DataTable($.extend(true, {}, dataTablesDefaults, {
168
              "aoColumnDefs": [
203
              "aoColumnDefs": [
169
                  { "aTargets": [ -1, -2 ], "bSortable": false, "bSearchable":false },
204
                  { "aTargets": [ -1, -2 ], "bSortable": false, "bSearchable":false },
170
               ],
205
               ],
171
               "aaSorting": [[ 1, "asc" ]],
206
               "aaSorting": [[ 1, "asc" ]],
207
               "paginationType": "four_button",
172
        }));
208
        }));
209
210
        $("#branch_filter").on("change", function(){
211
            // Table must be filtered by the <option>'s text, not its value
212
            var opt = $(this).find("option:selected").text();
213
            filterDataTable( crtable, 2, opt );
214
        });
215
173
    });
216
    });
174
    </script>
217
    </script>
175
[% END %]
218
[% END %]
176
- 

Return to bug 23321