Revision b3b80856
Von Moritz Bunkus vor fast 10 Jahren hinzugefügt
SL/LiquidityProjection.pm | ||
---|---|---|
5 | 5 |
use List::MoreUtils qw(uniq); |
6 | 6 |
|
7 | 7 |
use SL::DBUtils; |
8 |
use SL::DB::PeriodicInvoicesConfig; |
|
8 | 9 |
|
9 | 10 |
sub new { |
10 | 11 |
my $package = shift; |
... | ... | |
128 | 129 |
SELECT (oi.qty * (1 - oi.discount) * oi.sellprice) AS linetotal, |
129 | 130 |
bg.description AS buchungsgruppe, |
130 | 131 |
CASE WHEN COALESCE(e.name, '') = '' THEN e.login ELSE e.name END AS salesman, |
131 |
pcfg.periodicity, pcfg.id AS config_id, |
|
132 |
pcfg.periodicity, pcfg.order_value_periodicity, pcfg.id AS config_id,
|
|
132 | 133 |
EXTRACT(year FROM pcfg.start_date) AS start_year, EXTRACT(month FROM pcfg.start_date) AS start_month |
133 | 134 |
FROM orderitems oi |
134 | 135 |
LEFT JOIN oe ON (oi.trans_id = oe.id) |
... | ... | |
140 | 141 |
SQL |
141 | 142 |
|
142 | 143 |
# 3. Iterieren über Saldierungsintervalle, vormerken |
143 |
my %periodicities = ( 'm' => 1, 'q' => 3, 'y' => 12 ); |
|
144 | 144 |
my @scentries; |
145 | 145 |
$sth = prepare_execute_query($::form, $dbh, $query); |
146 | 146 |
while ($ref = $sth->fetchrow_hashref) { |
... | ... | |
148 | 148 |
my $date; |
149 | 149 |
|
150 | 150 |
while (($date = _the_date($year, $month)) le $self->{max_date}) { |
151 |
my $billing_len = $SL::DB::PeriodicInvoicesConfig::PERIOD_LENGTHS{ $ref->{periodicity} } || 1; |
|
152 |
|
|
151 | 153 |
if (($date ge $self->{min_date}) && (!$periodic_invoices{ $ref->{config_id} } || !$periodic_invoices{ $ref->{config_id} }->{$date})) { |
154 |
my $order_value_periodicity = $ref->{order_value_periodicity} eq 'p' ? $ref->{periodicity} : $ref->{order_value_periodicity}; |
|
155 |
my $order_value_len = $SL::DB::PeriodicInvoicesConfig::ORDER_VALUE_PERIOD_LENGTHS{$order_value_periodicity} || 1; |
|
156 |
|
|
152 | 157 |
push @scentries, { buchungsgruppe => $ref->{buchungsgruppe}, |
153 | 158 |
salesman => $ref->{salesman}, |
154 |
linetotal => $ref->{linetotal}, |
|
159 |
linetotal => $ref->{linetotal} * $billing_len / $order_value_len,
|
|
155 | 160 |
date => $date, |
156 | 161 |
}; |
157 | 162 |
} |
158 | 163 |
|
159 |
($year, $month) = _fix_date($year, $month + ($periodicities{ $ref->{periodicity} } || 1));
|
|
164 |
($year, $month) = _fix_date($year, $month + $billing_len);
|
|
160 | 165 |
} |
161 | 166 |
} |
162 | 167 |
$sth->finish; |
Auch abrufbar als: Unified diff
Liquiditätsübersicht: Auftragswertperiodizität von wied. Rechnungen berücksichtigen