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

(-)a/Koha/Cash/Register.pm (+69 lines)
Line 0 Link Here
1
package Koha::Cash::Register;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Carp;
21
22
use Koha::Database;
23
24
use base qw(Koha::Object);
25
26
=encoding utf8
27
28
=head1 NAME
29
30
Koha::Cash::Register - Koha cashregister Object class
31
32
=head1 API
33
34
=head2 Class methods
35
36
=cut
37
38
=head3 library
39
40
Return the library linked to this cash register
41
42
=cut
43
44
sub library {
45
    my ( $self ) = @_;
46
    my $rs = $self->_result->branch;
47
    return unless $rs;
48
    return Koha::Library->_new_from_dbic( $rs );
49
}
50
51
=head2 Internal methods
52
53
=cut
54
55
=head3 _type
56
57
=cut
58
59
sub _type {
60
    return 'CashRegister';
61
}
62
63
1;
64
65
=head1 AUTHORS
66
67
Martin Renvoize <martin.renvoize@ptfs-europe.com>
68
69
=cut
(-)a/Koha/Cash/Registers.pm (+58 lines)
Line 0 Link Here
1
package Koha::Cash::Registers;
2
3
# This file is part of Koha.
4
#
5
# Koha is free software; you can redistribute it and/or modify it under the
6
# terms of the GNU General Public License as published by the Free Software
7
# Foundation; either version 3 of the License, or (at your option) any later
8
# version.
9
#
10
# Koha is distributed in the hope that it will be useful, but WITHOUT ANY
11
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
12
# A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License along
15
# with Koha; if not, write to the Free Software Foundation, Inc.,
16
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17
18
use Modern::Perl;
19
20
use Carp;
21
22
use Koha::Database;
23
24
use Koha::Cash::Register;
25
26
use base qw(Koha::Objects);
27
28
=head1 NAME
29
30
Koha::Cash::Registers - Koha Cash Register Object set class
31
32
=head1 API
33
34
=head2 Class methods
35
36
    my $cash_registers = Koha::Cash::Registers->search({ ...  });
37
38
Returns a list of cash registers.
39
40
=head2 Internal methods
41
42
=head3 _type
43
44
=cut
45
46
sub _type {
47
    return 'CashRegister';
48
}
49
50
=head3 object_class
51
52
=cut
53
54
sub object_class {
55
    return 'Koha::Cash::Register';
56
}
57
58
1;
(-)a/admin/cash_registers.pl (+139 lines)
Line 0 Link Here
1
#!/usr/bin/perl
2
#
3
# Copyright 2019 PTFS Europe
4
#
5
# This file is part of Koha.
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use strict;
21
use warnings;
22
23
use CGI;
24
use Try::Tiny;
25
26
use C4::Auth;
27
use Koha::Libraries;
28
use C4::Koha;
29
use C4::Context;
30
use C4::Output;
31
use Koha::Cash::Registers;
32
33
my $cgi = CGI->new();
34
my ( $template, $borrowernumber, $cookie ) = get_template_and_user(
35
    {
36
        template_name   => 'admin/cash_registers.tt',
37
        query           => $cgi,
38
        type            => 'intranet',
39
        authnotrequired => 0,
40
        flagsrequired   => { admin => 'edit_cash_registers' },
41
    }
42
);
43
44
my $op         = $cgi->param('op') || 'list';
45
my $registerid = $cgi->param('id');             # update/archive
46
my $dbh        = C4::Context->dbh;
47
my @messages;
48
if ( $op eq 'add_form' ) {
49
    if ($registerid) {
50
        my $cash_register = Koha::Cash::Registers->find($registerid);
51
        $template->param( cash_register => $cash_register );
52
    }
53
    my $libraries =
54
      Koha::Libraries->search( {}, { order_by => ['branchcode'] }, );
55
    $template->param(
56
        branch_list => $libraries,
57
        add_form    => 1
58
    );
59
}
60
elsif ( $op eq 'add_validate' ) {
61
    my $name = $cgi->param('name');
62
    $name ||= q{};
63
    my $description = $cgi->param('description');
64
    $description ||= q{};
65
    my $branch = $cgi->param('branch');
66
    my $float  = $cgi->param('starting_float') // 0;
67
    if ($registerid) {
68
        try {
69
            my $cash_register = Koha::Cash::Registers->find($registerid);
70
            $cash_register->set(
71
                {
72
                    name           => $name,
73
                    description    => $description,
74
                    branch         => $branch,
75
                    starting_float => $float
76
                }
77
            )->store;
78
            push @messages, { code => 'success_on_update', type => 'message' };
79
        }
80
        catch {
81
            push @messages, { code => 'error_on_update', type => 'alert' };
82
        }
83
    }
84
    else {
85
        try {
86
            my $cash_register = Koha::Cash::Register->new(
87
                {
88
                    name           => $name,
89
                    description    => $description,
90
                    branch         => $branch,
91
                    starting_float => $float,
92
                }
93
            )->store;
94
            push @messages, { code => 'success_on_insert', type => 'message' };
95
        }
96
        catch {
97
            push @messages, { code => 'error_on_insert', type => 'alert' };
98
        }
99
    }
100
    $op = 'list';
101
}
102
103
elsif ( $op eq 'archive' ) {
104
    if ($registerid) {
105
        try {
106
            my $cash_register = Koha::Cash::Registers->find($registerid);
107
            $cash_register->archived(1)->store();
108
            push @messages, { code => 'success_on_archive', type => 'message' };
109
        }
110
        catch {
111
            push @messages, { code => 'error_on_archive', type => 'alert' };
112
113
        }
114
    }
115
    $op = 'list';
116
}
117
elsif ( $op eq 'unarchive' ) {
118
    if ($registerid) {
119
        try {
120
            my $cash_register = Koha::Cash::Registers->find($registerid);
121
            $cash_register->archived(0)->store();
122
            push @messages, { code => 'success_on_restore', type => 'message' };
123
        }
124
        catch {
125
            push @messages, { code => 'error_on_restore', type => 'alert' };
126
        }
127
    }
128
    $op = 'list';
129
}
130
131
if ( $op eq 'list' ) {
132
    my $cash_registers =
133
      Koha::Cash::Registers->search( {}, { prefetch => 'branch' } );
134
    $template->param( cash_registers => $cash_registers, );
135
}
136
137
$template->param( op => $op, messages => \@messages );
138
139
output_html_with_http_headers $cgi, $cookie, $template->output;
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/admin-home.tt (+10 lines)
Lines 98-103 Link Here
98
                </dl>
98
                </dl>
99
            [% END %]
99
            [% END %]
100
100
101
            [% IF ( Koha.Preference('UseCashRegisters') && CAN_user_cash_management_manage_cash_registers ) %]
102
                <h3>Accounting</h3>
103
                <dl>
104
                    [% IF ( CAN_user_cash_management_manage_cash_registers ) %]
105
                        <dt><a href="/cgi-bin/koha/admin/cash_registers.pl">Cash registers</a></dt>
106
                        <dd>Define cash registers</dd>
107
                    [% END %]
108
                </dl>
109
            [% END %]
110
101
            [% IF CAN_user_plugins && plugins_enabled %]
111
            [% IF CAN_user_plugins && plugins_enabled %]
102
                <h3>Plugins</h3>
112
                <h3>Plugins</h3>
103
                <dl>
113
                <dl>
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/cash_registers.tt (+178 lines)
Line 0 Link Here
1
[% USE raw %]
2
[% USE Asset %]
3
[% SET footerjs = 1 %]
4
[% USE ColumnsSettings %]
5
[% INCLUDE 'doc-head-open.inc' %]
6
<title>Koha &rsaquo; Administration &rsaquo; Cash Registers
7
[% IF op == 'add_form' %]
8
    &rsaquo;[% IF cash_register %]Modify cash register[% ELSE %]New cash register [% cash_register.id | html %][% END %]
9
[% ELSIF op == 'delete_confirm' %]
10
    &rsaquo; Confirm deletion of cash register '[% cash_register.id | html %]'
11
[% END %]
12
</title>
13
[% INCLUDE 'doc-head-close.inc' %]
14
</head>
15
16
<body id="admin_cash_registers" class="admin">
17
[% INCLUDE 'header.inc' %]
18
[% INCLUDE 'prefs-admin-search.inc' %]
19
20
<div id="breadcrumbs">
21
    <a href="/cgi-bin/koha/mainpage.pl">Home</a>
22
&rsaquo; <a href="/cgi-bin/koha/admin/admin-home.pl">Administration</a>
23
&rsaquo; <a href="/cgi-bin/koha/admin/cash_registers.pl">Cash registers</a>
24
[% IF op == 'add_form'  %]
25
&rsaquo; [% IF cash_register %]Modify cash register [% cash_register.id | html %][% ELSE %]New cash register[% END %]
26
[% ELSIF op == 'delete_confirm' %]
27
&rsaquo; Confirm deletion of cash register '[% cash_register.id | html %]'
28
[% END %]
29
</div>
30
31
<div class="main container-fluid">
32
    <div class="row">
33
        <div class="col-sm-10 col-sm-push-2">
34
            <main>
35
36
                [% FOREACH m IN messages %]
37
                <div class="dialog [% m.type | html %]">
38
                    [% SWITCH m.code %]
39
                    [% CASE 'error_on_update' %]
40
                        An error occurred when updating this cash register.
41
                    [% CASE 'error_on_insert' %]
42
                        An error occurred when adding this cash register.
43
                    [% CASE 'success_on_update' %]
44
                        Cash register updated successfully.
45
                    [% CASE 'success_on_insert' %]
46
                        Cash register added successfully.
47
                    [% CASE 'success_on_archive' %]
48
                        Cash register archived successfully.
49
                    [% CASE 'success_on_restore' %]
50
                        Cash register restored successfully.
51
                    [% CASE 'success_on_delete' %]
52
                        Cash register deleted successfully.
53
                    [% CASE %]
54
                        [% m.code | html %]
55
                    [% END %]
56
                </div>
57
                [% END %]
58
59
                [% IF op == 'add_form' %]
60
                <h3>[% IF cash_register %]Modify cash register[% ELSE %]Add new cash_register[% END %]</h3>
61
                <form action="/cgi-bin/koha/admin/cash_registers.pl" id="Aform" name="Aform" class="validated" method="post">
62
63
                    <fieldset class="rows">
64
                        <input type="hidden" name="op" value="add_validate" />
65
                        <ol>
66
                        [% IF cash_register %]
67
                            <li>
68
                                <span class="label">Cash Register ID: </span>[% cash_register.id | html %]
69
                                <input type="hidden" name="id" value="[% cash_register.id %]" />
70
                            </li>
71
                        [% END %]
72
73
                            <li>
74
                                <label for="name" class="required">Name: </label>
75
                                <input type="text" name="name" id="name" size="80" value="[% cash_register.name | html %]" class="required" />
76
                                <span class="required">Required</span>
77
                            </li>
78
79
                            <li>
80
                                <label for="description">Description: </label>
81
                                <input type="text" name="description" id="description" value="[% cash_register.description %]"/>
82
                            </li>
83
                            <li>
84
                                <label for="branch">Branch: </label>
85
                                <select id="branch" name="branch">
86
                                [% FOREACH branch IN branch_list %]
87
                                [% IF cash_register.branch == branch.branchcode %]
88
                                    <option value="[% branch.branchcode %]" selected="1">[% branch.branchname %]</option>
89
                                [% ELSE %]
90
                                    <option value="[% branch.branchcode %]">[% branch.branchname %]</option>
91
                                [% END %]
92
                                [% END %]
93
                                </select>
94
                            </li>
95
96
                            <li>
97
                                <label for="starting_float">Initial float: </label>
98
                                <input type="text" pattern='^\d+(?:\.\d{0,2})$' name="starting_float" id="starting_float" value="[% cash_register.starting_float %]" />
99
                            </li>
100
                        </ol>
101
                   </fieldset>
102
103
                   <fieldset class="action">
104
                       [% IF cash_register %]
105
                       <input type="submit" value="Save" />
106
                       [% ELSE %]
107
                       <input type="submit" value="Add" />
108
                       [% END %]
109
                       <a class=cancel" href="/cgi-bin/koha/admin/cash_registers.pl?op=list">Cancel</a>
110
                   </fieldset>
111
               </form>
112
               [% END %]
113
114
               [% IF op == 'list' %]
115
               <div id="toolbar" class="btn-toolbar">
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>
117
               </div>
118
119
               <h3>Cash Registers</h3>
120
               [% IF cash_registers.count %]
121
               <table id="table_cash_registers">
122
                   <thead>
123
                       <th>Id</th>
124
                       <th>Name</th>
125
                       <th>Description</th>
126
                       <th>Branch</th>
127
                       <th>Initial float</th>
128
                       <th>Actions</th>
129
                   </thead>
130
                   <tbody>
131
                   [% FOREACH cash_register IN cash_registers %]
132
                   <tr>
133
                       <td>[% cash_register.id %]</td>
134
                       <td>[% cash_register.name %]</td>
135
                       <td>[% cash_register.description %]</td>
136
                       <td>[% cash_register.library.branchname %]</td>
137
                       <td>[% cash_register.starting_float %]</td>
138
                       [% 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>
140
                       [% 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>
142
                       [% END %]
143
                   </tr>
144
                   [% END %]
145
                   </tbody>
146
               </table>
147
               [% ELSE %]
148
               <div class="dialog message">There are no cash registers defined. <a href="/cgi-bin/koha/admin/cash_registers.pl?op=add_form">Start adding cash registers</a>.</div>
149
               [% END # /cash_register.count %]
150
               [% END # /op == 'list' %]
151
           </main>
152
        </div> <!-- /.col-sm-10.col-sm-push-2 -->
153
154
        <div class="col-sm-2 col-sm-pull-10">
155
            <aside>
156
                [% INCLUDE 'admin-menu.inc' %]
157
            </aside>
158
        </div> <!-- /.col-sm-2.col-sm-pull-10 -->
159
    </div> <!-- /.row -->
160
161
[% MACRO jsinclude BLOCK %]
162
    [% Asset.js("js/admin-menu.js") | $raw %]
163
    [% INCLUDE 'datatables.inc' %]
164
165
    <script>
166
    $(document).ready(function() {
167
        $("#table_cash_registers").dataTable($.extend(true, {}, dataTablesDefaults, {
168
              "aoColumnDefs": [
169
                  { "aTargets": [ -1, -2 ], "bSortable": false, "bSearchable":false },
170
               ],
171
               "aaSorting": [[ 1, "asc" ]],
172
               "paginationType": "full",
173
        }));
174
    });
175
    </script>
176
[% END %]
177
178
[% INCLUDE 'intranet-bottom.inc' %]
(-)a/t/db_dependent/Koha/Cash/Register.t (-1 / +57 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
# Copyright 2019 Koha Development team
4
#
5
# This file is part of Koha
6
#
7
# Koha is free software; you can redistribute it and/or modify it
8
# under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
12
# Koha is distributed in the hope that it will be useful, but
13
# WITHOUT ANY WARRANTY; without even the implied warranty of
14
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
# GNU General Public License for more details.
16
#
17
# You should have received a copy of the GNU General Public License
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
20
use Modern::Perl;
21
22
use Test::More tests => 1;
23
24
use C4::Context;
25
26
use Koha::Library;
27
use Koha::Libraries;
28
use Koha::Database;
29
30
use t::lib::TestBuilder;
31
32
my $builder = t::lib::TestBuilder->new;
33
my $schema  = Koha::Database->new->schema;
34
35
subtest 'library' => sub {
36
    plan tests => 2;
37
38
    $schema->storage->txn_begin;
39
40
    my $library = $builder->build_object( { class => 'Koha::Libraries' } );
41
    my $register = $builder->build_object(
42
        {
43
            class => 'Koha::Cash::Registers',
44
            value => { branch => $library->branchcode },
45
        }
46
    );
47
48
    is( ref( $register->library ),
49
        'Koha::Library',
50
        'Koha::Cash::Register->library should return a Koha::Library' );
51
52
    is( $register->library->id,
53
        $library->id,
54
        'Koha::Cash::Register->library returns the correct Koha::Library' );
55
56
    $schema->storage->txn_rollback;
57
};

Return to bug 23321