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

(-)a/Koha/Cash/Register/Action.pm (+116 lines)
Lines 48-53 sub manager { Link Here
48
    return Koha::Patron->_new_from_dbic($rs);
48
    return Koha::Patron->_new_from_dbic($rs);
49
}
49
}
50
50
51
=head3 register
52
53
Return the register linked to this cash register::action
54
55
=cut
56
57
sub register {
58
    my ($self) = @_;
59
    my $rs = $self->_result->register;
60
    return unless $rs;
61
    return Koha::Cash::Register->_new_from_dbic($rs);
62
}
63
64
=head3 cashup_summary
65
66
  my $cashup_summary = $action->cashup_summary;
67
68
Return a hashref containing a summary of transactions that make up this cashup action.
69
70
=cut
71
72
sub cashup_summary {
73
    my ($self) = @_;
74
    my $summary;
75
    my $prior_cashup = Koha::Cash::Register::Actions->search(
76
        {
77
            'code'      => 'CASHUP',
78
            'timestamp' => { '<' => $self->timestamp },
79
            register_id => $self->register_id
80
        },
81
        {
82
            order_by => { '-desc' => [ 'timestamp', 'id' ] },
83
            rows     => 1
84
        }
85
    );
86
87
    my $previous = $prior_cashup->single;
88
89
    my $conditions =
90
      $previous
91
      ? {
92
        'date' => {
93
            '-between' =>
94
              [ $previous->_result->get_column('timestamp'), $self->timestamp ]
95
        }
96
      }
97
      : { 'date' => { '<' => $self->timestamp } };
98
99
    my $outgoing_transactions = $self->register->accountlines->search(
100
        { %{$conditions}, credit_type_code => undef },
101
        { select => 'accountlines_id' } );
102
    my $income_transactions = $self->register->accountlines->search(
103
        { %{$conditions}, debit_type_code => undef },
104
        { select => 'accountlines_id' } );
105
106
    my $income_summary = Koha::Account::Offsets->search(
107
        {
108
            'me.credit_id' =>
109
              { '-in' => $income_transactions->_resultset->as_query },
110
            'me.debit_id' => { '!=' => undef }
111
        },
112
        {
113
            join     => { 'debit' => 'debit_type_code' },
114
            group_by => [ 'debit.debit_type_code', 'debit_type_code.description' ],
115
            'select' => [ { sum => 'me.amount' }, 'debit.debit_type_code', 'debit_type_code.description' ],
116
            'as'     => [ 'total', 'debit_type_code', 'debit_description' ],
117
        }
118
    );
119
120
    my $outgoing_summary = Koha::Account::Offsets->search(
121
        {
122
            'me.debit_id' =>
123
              { '-in' => $outgoing_transactions->_resultset->as_query },
124
            'me.credit_id' => { '!=' => undef }
125
        },
126
        {
127
            join     => { 'credit' => 'credit_type_code' },
128
            group_by => [ 'credit.credit_type_code', 'credit_type_code.description' ],
129
            'select' => [ { sum => 'me.amount' }, 'credit.credit_type_code', 'credit_type_code.description' ],
130
            'as'     => [ 'total', 'credit_type_code', 'credit_description' ],
131
        }
132
    );
133
134
    my @income = map {
135
        {
136
            total           => $_->get_column('total'),
137
            debit_type_code => $_->get_column('debit_type_code'),
138
            debit_type      => { description => $_->get_column('debit_description') }
139
        }
140
    } $income_summary->as_list;
141
    my @outgoing = map {
142
        {
143
            total            => $_->get_column('total'),
144
            credit_type_code => $_->get_column('credit_type_code'),
145
            credit_type      => { description => $_->get_column('credit_description') }
146
        }
147
    } $outgoing_summary->as_list;
148
    $summary = {
149
        from_date => $previous ? $previous->timestamp : undef,
150
        to_date   => $self->timestamp,
151
        income    => \@income,
152
        outgoing  => \@outgoing,
153
        total     => ( $outgoing_transactions->total * -1 ) +
154
          ( $income_transactions->total * -1 ),
155
        bankable => (
156
            $outgoing_transactions->search( { payment_type => 'CASH' } )
157
              ->total * -1
158
        ) + (
159
            $income_transactions->search( { payment_type => 'CASH' } )->total *
160
              -1
161
        )
162
    };
163
164
    return $summary;
165
}
166
51
=head2 Internal methods
167
=head2 Internal methods
52
168
53
=cut
169
=cut
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/pos/register.tt (-2 / +58 lines)
Lines 59-65 Link Here
59
            <h2>Summary</h2>
59
            <h2>Summary</h2>
60
            <ul>
60
            <ul>
61
                [% IF register.last_cashup %]
61
                [% IF register.last_cashup %]
62
                <li>Last cashup: [% register.last_cashup.timestamp | $KohaDates with_hours => 1 %]</li>
62
                <li>Last cashup: [% register.last_cashup.timestamp | $KohaDates with_hours => 1 %] (<a data-toggle="modal" href="#cashupSummaryModal" class="button">Summary</a>)</li>
63
63
                [% END %]
64
                [% END %]
64
                <li>Float: [% register.starting_float | $Price %]</li>
65
                <li>Float: [% register.starting_float | $Price %]</li>
65
                <li>Total income (cash): [% accountlines.credits_total * -1 | $Price %] ([% accountlines.credits_total(payment_type => 'CASH') * -1 | $Price %])</li>
66
                <li>Total income (cash): [% accountlines.credits_total * -1 | $Price %] ([% accountlines.credits_total(payment_type => 'CASH') * -1 | $Price %])</li>
Lines 303-308 Link Here
303
        </form> <!-- /#refund_form -->
304
        </form> <!-- /#refund_form -->
304
    </div> <!-- /#issueRefundModal -->
305
    </div> <!-- /#issueRefundModal -->
305
306
307
    <!-- Cashup summary modal -->
308
    [% IF register.last_cashup %]
309
    <div class="modal" id="cashupSummaryModal" tabindex="-1" role="dialog" aria-labelledby="cashupSummaryLabel">
310
        <div class="modal-dialog" role="document">
311
            <div class="modal-content">
312
                <div class="modal-header">
313
                    <button type="button" class="closebtn" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
314
                    <h4 class="modal-title" id="cashupSummaryLabel">Cashup summary</h4>
315
                </div>
316
                <div class="modal-body">
317
                    <ul>
318
                        <li>Cash register: [% register.description | html %]</li>
319
                        <li>Period: [% register.last_cashup.cashup_summary.from_date | $KohaDates with_hours => 1 %] to [% register.last_cashup.cashup_summary.to_date | $KohaDates with_hours => 1 %]</li>
320
                    </ul>
321
                    <table>
322
                        <thead>
323
                            <tr>
324
                                <th>Type</th>
325
                                <th>Total</th>
326
                            </tr>
327
                        </thead>
328
                        <tbody>
329
                            [%- FOREACH out IN register.last_cashup.cashup_summary.outgoing -%]
330
                            <tr>
331
                                <td>[%- PROCESS account_type_description account=out -%]</td>
332
                                <td>[% out.total * -1 | $Price %]</td>
333
                            </tr>
334
                            [%- END -%]
335
                            [%- FOREACH in IN register.last_cashup.cashup_summary.income -%]
336
                            <tr>
337
                                <td>[%- PROCESS account_type_description account=in -%]</td>
338
                                <td>[% in.total * -1 | $Price %]</td>
339
                            </tr>
340
                            [%- END -%]
341
                        </tbody>
342
                        <tfoot>
343
                            <tr>
344
                                <td>Total</td>
345
                                <td>[% register.last_cashup.cashup_summary.total | $Price %]</td>
346
                            </tr>
347
                            <tr>
348
                                <td>Bankable</td>
349
                                <td>[% register.last_cashup.cashup_summary.bankable | $Price %]</td>
350
                            </tr>
351
352
                        </tfoot>
353
                    </table>
354
                </div> <!-- /.modal-body -->
355
                <div class="modal-footer">
356
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
357
                </div> <!-- /.modal-footer -->
358
            </div> <!-- /.modal-content -->
359
        </div> <!-- /.modal-dialog -->
360
    </div> <!-- /#cashupSummaryModal -->
361
    [% END %]
362
306
[% MACRO jsinclude BLOCK %]
363
[% MACRO jsinclude BLOCK %]
307
    [% INCLUDE 'datatables.inc' %]
364
    [% INCLUDE 'datatables.inc' %]
308
    [% Asset.js("lib/jquery/plugins/rowGroup/dataTables.rowGroup.min.js") | $raw %]
365
    [% Asset.js("lib/jquery/plugins/rowGroup/dataTables.rowGroup.min.js") | $raw %]
309
- 

Return to bug 26172