X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FLiquidityProjection.pm;h=5954e005607769b57e6d5ac08dc59bb69c245edc;hb=30b4a78c4100ebdcd6e6917fbcbf1d12f4f7b4d6;hp=03a1894c2c88402c0840289382a3ce51ab40e31e;hpb=fa7fc7eeb3ca718914affee06c0629a08d571288;p=kivitendo-erp.git diff --git a/SL/LiquidityProjection.pm b/SL/LiquidityProjection.pm index 03a1894c2..5954e0056 100644 --- a/SL/LiquidityProjection.pm +++ b/SL/LiquidityProjection.pm @@ -5,6 +5,7 @@ use strict; use List::MoreUtils qw(uniq); use SL::DBUtils; +use SL::DB::PeriodicInvoicesConfig; sub new { my $package = shift; @@ -112,6 +113,7 @@ sub create { FROM periodic_invoices pi LEFT JOIN periodic_invoices_configs pcfg ON (pi.config_id = pcfg.id) WHERE pcfg.active + AND NOT pcfg.periodicity = 'o' AND (pi.period_start_date >= to_date($q_min_date, 'YYYY-MM-DD')) SQL @@ -128,7 +130,7 @@ SQL SELECT (oi.qty * (1 - oi.discount) * oi.sellprice) AS linetotal, bg.description AS buchungsgruppe, CASE WHEN COALESCE(e.name, '') = '' THEN e.login ELSE e.name END AS salesman, - pcfg.periodicity, pcfg.id AS config_id, + pcfg.periodicity, pcfg.order_value_periodicity, pcfg.id AS config_id, EXTRACT(year FROM pcfg.start_date) AS start_year, EXTRACT(month FROM pcfg.start_date) AS start_month FROM orderitems oi LEFT JOIN oe ON (oi.trans_id = oe.id) @@ -137,10 +139,10 @@ SQL LEFT JOIN buchungsgruppen bg ON (p.buchungsgruppen_id = bg.id) LEFT JOIN employee e ON (COALESCE(oe.salesman_id, oe.employee_id) = e.id) WHERE pcfg.active + AND NOT pcfg.periodicity = 'o' SQL # 3. Iterieren über Saldierungsintervalle, vormerken - my %periodicities = ( 'm' => 1, 'q' => 3, 'y' => 12 ); my @scentries; $sth = prepare_execute_query($::form, $dbh, $query); while ($ref = $sth->fetchrow_hashref) { @@ -148,15 +150,20 @@ SQL my $date; while (($date = _the_date($year, $month)) le $self->{max_date}) { + my $billing_len = $SL::DB::PeriodicInvoicesConfig::PERIOD_LENGTHS{ $ref->{periodicity} } || 1; + if (($date ge $self->{min_date}) && (!$periodic_invoices{ $ref->{config_id} } || !$periodic_invoices{ $ref->{config_id} }->{$date})) { + my $order_value_periodicity = $ref->{order_value_periodicity} eq 'p' ? $ref->{periodicity} : $ref->{order_value_periodicity}; + my $order_value_len = $SL::DB::PeriodicInvoicesConfig::ORDER_VALUE_PERIOD_LENGTHS{$order_value_periodicity} || 1; + push @scentries, { buchungsgruppe => $ref->{buchungsgruppe}, salesman => $ref->{salesman}, - linetotal => $ref->{linetotal}, + linetotal => $ref->{linetotal} * $billing_len / $order_value_len, date => $date, }; } - ($year, $month) = _fix_date($year, $month + ($periodicities{ $ref->{periodicity} } || 1)); + ($year, $month) = _fix_date($year, $month + $billing_len); } } $sth->finish; @@ -175,7 +182,7 @@ SQL WHERE (oe.customer_id IS NOT NULL) AND NOT COALESCE(oe.quotation, FALSE) AND NOT COALESCE(oe.closed, FALSE) - AND (oe.id NOT IN (SELECT oe_id FROM periodic_invoices_configs)) + AND (oe.id NOT IN (SELECT oe_id FROM periodic_invoices_configs WHERE periodicity <> 'o')) SQL # 5. Initialisierung der Datenstrukturen zum Speichern der