|
Lines 43-55
empty it returns 0.
Link Here
|
| 43 |
=cut |
43 |
=cut |
| 44 |
|
44 |
|
| 45 |
sub total_outstanding { |
45 |
sub total_outstanding { |
| 46 |
my ( $self ) = @_; |
46 |
my ($self) = @_; |
| 47 |
|
47 |
|
| 48 |
my $lines = $self->search( |
48 |
my $lines = $self->search( |
| 49 |
{}, |
49 |
{}, |
| 50 |
{ |
50 |
{ |
| 51 |
select => [ { sum => 'amountoutstanding' } ], |
51 |
select => [ { sum => 'amountoutstanding' } ], |
| 52 |
as => ['total_amountoutstanding'], |
52 |
as => ['total_amountoutstanding'], |
| 53 |
} |
53 |
} |
| 54 |
); |
54 |
); |
| 55 |
|
55 |
|
|
Lines 58-63
sub total_outstanding {
Link Here
|
| 58 |
: 0; |
58 |
: 0; |
| 59 |
} |
59 |
} |
| 60 |
|
60 |
|
|
|
61 |
=head3 total |
| 62 |
|
| 63 |
my $lines = Koha::Account::Lines->search({ ... }); |
| 64 |
my $total = $lines->total; |
| 65 |
|
| 66 |
Returns the sum of the amounts of the resultset. If the resultset is |
| 67 |
empty it returns 0. |
| 68 |
|
| 69 |
=cut |
| 70 |
|
| 71 |
sub total { |
| 72 |
my ( $self, $conditions ) = @_; |
| 73 |
|
| 74 |
$conditions //= {}; |
| 75 |
my $lines = $self->search( |
| 76 |
$conditions, |
| 77 |
{ |
| 78 |
select => [ { sum => 'me.amount' } ], |
| 79 |
as => ['total'] |
| 80 |
} |
| 81 |
); |
| 82 |
return $lines->count ? $lines->next->get_column('total') + 0 : 0; |
| 83 |
} |
| 84 |
|
| 85 |
=head3 credits_total |
| 86 |
|
| 87 |
my $lines = Koha::Account::Lines->search({ ... }); |
| 88 |
my $credits_total = $lines->credits_total; |
| 89 |
|
| 90 |
Returns the sum of the amounts of the resultset. If the resultset is |
| 91 |
empty it returns 0. |
| 92 |
|
| 93 |
=cut |
| 94 |
|
| 95 |
sub credits_total { |
| 96 |
my ( $self, $conditions ) = @_; |
| 97 |
|
| 98 |
my $local_conditions = { 'me.amount' => { '<' => 0 } }; |
| 99 |
$conditions //= {}; |
| 100 |
my $merged_conditions = { %{$conditions}, %{$local_conditions} }; |
| 101 |
|
| 102 |
my $lines = $self->search( |
| 103 |
$merged_conditions, |
| 104 |
{ |
| 105 |
select => [ { sum => 'me.amount' } ], |
| 106 |
as => ['total'] |
| 107 |
} |
| 108 |
); |
| 109 |
return $lines->count ? $lines->next->get_column('total') + 0 : 0; |
| 110 |
} |
| 111 |
|
| 112 |
=head3 debits_total |
| 113 |
|
| 114 |
my $lines = Koha::Account::Lines->search({ ... }); |
| 115 |
my $debits_total = $lines->debits_total; |
| 116 |
|
| 117 |
Returns the sum of the amounts of the resultset. If the resultset is |
| 118 |
empty it returns 0. |
| 119 |
|
| 120 |
=cut |
| 121 |
|
| 122 |
sub debits_total { |
| 123 |
my ( $self, $conditions ) = @_; |
| 124 |
|
| 125 |
my $local_conditions = { 'me.amount' => { '>' => 0 } }; |
| 126 |
$conditions //= {}; |
| 127 |
my $merged_conditions = { %{$conditions}, %{$local_conditions} }; |
| 128 |
|
| 129 |
my $lines = $self->search( |
| 130 |
$merged_conditions, |
| 131 |
{ |
| 132 |
select => [ { sum => 'me.amount' } ], |
| 133 |
as => ['total'] |
| 134 |
} |
| 135 |
); |
| 136 |
return $lines->count ? $lines->next->get_column('total') + 0 : 0; |
| 137 |
} |
| 138 |
|
| 61 |
=head2 Internal methods |
139 |
=head2 Internal methods |
| 62 |
|
140 |
|
| 63 |
=head3 _type |
141 |
=head3 _type |
| 64 |
- |
|
|