Revision 840aea13
Von Moritz Bunkus vor fast 18 Jahren hinzugefügt
SL/DN.pm | ||
---|---|---|
121 | 121 |
sub save_dunning { |
122 | 122 |
$main::lxdebug->enter_sub(); |
123 | 123 |
|
124 |
my ($self, $myconfig, $form, $rows, $userspath,$spool, $sendmail) = @_; |
|
124 |
my ($self, $myconfig, $form, $rows, $userspath, $spool, $sendmail) = @_;
|
|
125 | 125 |
# connect to database |
126 | 126 |
my $dbh = $form->dbconnect_noauto($myconfig); |
127 | 127 |
|
128 | 128 |
my ($query, @values); |
129 | 129 |
|
130 |
my ($dunning_id) = selectrow_query($form, $dbh, qq|SELECT nextval('id')|); |
|
131 |
|
|
130 | 132 |
foreach my $row (@{ $rows }) { |
131 | 133 |
|
132 | 134 |
$form->{"interest_$row"} = $form->parse_amount($myconfig,$form->{"interest_$row"}); |
133 | 135 |
$form->{"fee_$row"} = $form->parse_amount($myconfig,$form->{"fee_$row"}); |
134 | 136 |
$form->{send_email} = $form->{"email_$row"}; |
135 | 137 |
|
136 |
$query = qq|UPDATE ar SET dunning_id = ? WHERE id = ?|; |
|
137 |
@values = ($form->{"next_dunning_id_$row"}, $form->{"inv_id_$row"}); |
|
138 |
$query = qq|UPDATE ar SET dunning_config_id = ? WHERE id = ?|; |
|
139 |
@values = ($form->{"next_dunning_config_id_$row"}, |
|
140 |
$form->{"inv_id_$row"}); |
|
138 | 141 |
do_query($form, $dbh, $query, @values); |
142 |
|
|
139 | 143 |
$query = |
140 |
qq|INSERT INTO dunning (dunning_id, dunning_level, trans_id, fee,
|
|
141 |
interest, transdate, duedate) |
|
142 |
VALUES (?, (SELECT dunning_level FROM dunning_config WHERE id = ?), |
|
144 |
qq|INSERT INTO dunning (dunning_id, dunning_config_id, dunning_level,
|
|
145 |
trans_id, fee, interest, transdate, duedate)
|
|
146 |
VALUES (?, ?, (SELECT dunning_level FROM dunning_config WHERE id = ?),
|
|
143 | 147 |
?, ?, ?, current_date, ?)|; |
144 |
@values = (conv_i($form->{"next_dunning_id_$row"}), |
|
145 |
conv_i($form->{"next_dunning_id_$row"}), |
|
148 |
@values = ($dunning_id, |
|
149 |
conv_i($form->{"next_dunning_config_id_$row"}), |
|
150 |
conv_i($form->{"next_dunning_config_id_$row"}), |
|
146 | 151 |
conv_i($form->{"inv_id_$row"}), $form->{"fee_$row"}, |
147 | 152 |
$form->{"interest_$row"}, |
148 | 153 |
conv_date($form->{"next_duedate_$row"})); |
... | ... | |
155 | 160 |
template AS formname, email_subject, email_body, email_attachment, |
156 | 161 |
da.fee, da.interest, da.transdate AS dunning_date, |
157 | 162 |
da.duedate AS dunning_duedate |
158 |
FROM ar LEFT JOIN dunning_config ON (dunning_config.id = ar.dunning_id) |
|
163 |
FROM ar LEFT JOIN dunning_config ON (dunning_config.id = ar.dunning_config_id)
|
|
159 | 164 |
LEFT JOIN dunning da ON (ar.id = da.trans_id AND dunning_config.dunning_level = da.dunning_level) |
160 | 165 |
WHERE ar.id IN (| |
161 | 166 |
. join(", ", map("?", @{ $form->{"inv_ids"} })) . qq|)|; |
... | ... | |
233 | 238 |
$form->{keep_tmpfile} = 1; |
234 | 239 |
} |
235 | 240 |
|
241 |
delete($form->{tmpfile}); |
|
236 | 242 |
$form->parse_template($myconfig, $userspath); |
237 | 243 |
|
238 | 244 |
$dbh->commit; |
... | ... | |
258 | 264 |
WHERE dunning_level > |
259 | 265 |
(SELECT |
260 | 266 |
CASE |
261 |
WHEN a.dunning_id IS NULL |
|
267 |
WHEN a.dunning_config_id IS NULL
|
|
262 | 268 |
THEN 0 |
263 |
ELSE (SELECT dunning_level FROM dunning_config WHERE id = a.dunning_id ORDER BY dunning_level LIMIT 1) |
|
269 |
ELSE (SELECT dunning_level |
|
270 |
FROM dunning_config |
|
271 |
WHERE id = a.dunning_config_id |
|
272 |
ORDER BY dunning_level |
|
273 |
LIMIT 1) |
|
264 | 274 |
END |
265 | 275 |
FROM dunning_config LIMIT 1) |
266 | 276 |
LIMIT 1)) |; |
... | ... | |
289 | 299 |
} |
290 | 300 |
|
291 | 301 |
if ($form->{dunning_level}) { |
292 |
$where .= qq| AND a.dunning_id = ?|; |
|
302 |
$where .= qq| AND a.dunning_config_id = ?|;
|
|
293 | 303 |
push(@values, conv_i($form->{dunning_level})); |
294 | 304 |
} |
295 | 305 |
|
... | ... | |
310 | 320 |
a.duedate + dnn.terms - current_date AS nextlevel, |
311 | 321 |
$paymentdate - a.duedate AS pastdue, dn.dunning_level, |
312 | 322 |
current_date + dnn.payment_terms AS next_duedate, |
313 |
dnn.dunning_description AS next_dunning_description, dnn.id AS next_dunning_id, |
|
323 |
dnn.dunning_description AS next_dunning_description, dnn.id AS next_dunning_config_id,
|
|
314 | 324 |
dnn.interest AS interest_rate, dnn.terms |
315 | 325 |
FROM dunning_config dnn, ar a |
316 | 326 |
JOIN customer ct ON (a.customer_id = ct.id) |
317 |
LEFT JOIN dunning_config dn ON (dn.id = a.dunning_id) |
|
327 |
LEFT JOIN dunning_config dn ON (dn.id = a.dunning_config_id)
|
|
318 | 328 |
LEFT JOIN dunning da ON ((da.trans_id = a.id) AND (dn.dunning_level = da.dunning_level)) |
319 | 329 |
$where |
320 | 330 |
ORDER BY a.id, transdate, duedate, name|; |
... | ... | |
378 | 388 |
} |
379 | 389 |
|
380 | 390 |
if ($form->{dunning_level}) { |
381 |
$where .= qq| AND a.dunning_id = ?|; |
|
391 |
$where .= qq| AND a.dunning_config_id = ?|;
|
|
382 | 392 |
push(@values, conv_i($form->{dunning_level})); |
383 | 393 |
} |
384 | 394 |
|
... | ... | |
389 | 399 |
} |
390 | 400 |
|
391 | 401 |
if (!$form->{showold}) { |
392 |
$where .= qq| AND (a.amount > a.paid) AND (da.dunning_id = a.dunning_id) |;
|
|
402 |
$where .= qq| AND (a.amount > a.paid) AND (da.dunning_config_id = a.dunning_config_id) |;
|
|
393 | 403 |
} |
394 | 404 |
|
395 | 405 |
if ($form->{transdatefrom}) { |
... | ... | |
411 | 421 |
|
412 | 422 |
$query = |
413 | 423 |
qq|SELECT a.id, a.ordnumber, a.invoice, a.transdate, a.invnumber, a.amount, |
414 |
ct.name AS customername, ct.id AS customer_id, a.duedate, da.fee, |
|
415 |
da.interest, dn.dunning_description, da.transdate AS dunning_date, da.duedate AS dunning_duedate, da.dunning_id |
|
416 |
FROM ar a |
|
417 |
JOIN customer ct ON (a.customer_id = ct.id), dunning da |
|
418 |
LEFT JOIN dunning_config dn ON (da.dunning_id = dn.id) |
|
419 |
$where |
|
420 |
ORDER BY name, a.id|; |
|
424 |
ct.name AS customername, ct.id AS customer_id, a.duedate, da.fee, |
|
425 |
da.interest, dn.dunning_description, da.transdate AS dunning_date, |
|
426 |
da.duedate AS dunning_duedate, da.dunning_id, da.dunning_config_id |
|
427 |
FROM ar a |
|
428 |
JOIN customer ct ON (a.customer_id = ct.id), dunning da |
|
429 |
LEFT JOIN dunning_config dn ON (da.dunning_config_id = dn.id) |
|
430 |
$where |
|
431 |
ORDER BY name, a.id|; |
|
421 | 432 |
|
422 | 433 |
$form->{DUNNINGS} = selectall_hashref_query($form, $dbh, $query, @values); |
423 | 434 |
|
... | ... | |
485 | 496 |
|
486 | 497 |
my ($self, $myconfig, $form, $userspath) = @_; |
487 | 498 |
|
488 |
map({ $_ =~ s|.*/||g; } @{ $form->{DUNNING_PDFS} }); |
|
489 |
|
|
490 | 499 |
foreach my $file (@{ $form->{DUNNING_PDFS} }) { |
491 | 500 |
$inputfiles .= " $userspath/$file "; |
492 | 501 |
} |
... | ... | |
543 | 552 |
sub print_dunning { |
544 | 553 |
$main::lxdebug->enter_sub(); |
545 | 554 |
|
546 |
my ($self, $myconfig, $form, $dunning_id, $customer_id, $userspath,$spool, $sendmail) = @_;
|
|
555 |
my ($self, $myconfig, $form, $dunning_id, $userspath,$spool, $sendmail) = @_; |
|
547 | 556 |
# connect to database |
548 | 557 |
my $dbh = $form->dbconnect_noauto($myconfig); |
549 | 558 |
|
... | ... | |
552 | 561 |
ar.transdate, ar.duedate, paid, amount - paid AS open_amount, |
553 | 562 |
template AS formname, email_subject, email_body, email_attachment, |
554 | 563 |
da.fee, da.interest, da.transdate AS dunning_date, da.duedate AS dunning_duedate |
555 |
FROM ar
|
|
556 |
LEFT JOIN dunning_config ON (dunning_config.id = ar.dunning_id)
|
|
557 |
LEFT JOIN dunning da ON ((ar.id = da.trans_id) AND (dunning_config.dunning_level = da.dunning_level))
|
|
558 |
WHERE (ar.dunning_id = ?) AND (customer_id = ?)|;
|
|
564 |
FROM dunning da
|
|
565 |
LEFT JOIN dunning_config ON (dunning_config.id = da.dunning_config_id)
|
|
566 |
LEFT JOIN ar ON (ar.id = da.trans_id)
|
|
567 |
WHERE (da.dunning_id = ?)|;
|
|
559 | 568 |
|
560 |
my $sth = prepare_execute_query($form, $dbh, $query, $dunning_id, $customer_id);
|
|
569 |
my $sth = prepare_execute_query($form, $dbh, $query, $dunning_id); |
|
561 | 570 |
my $first = 1; |
562 | 571 |
while (my $ref = $sth->fetchrow_hashref(NAME_lc)) { |
563 | 572 |
if ($first) { |
SL/IS.pm | ||
---|---|---|
1700 | 1700 |
map { $form->{$_} = $ref->{$_} } keys %$ref; |
1701 | 1701 |
|
1702 | 1702 |
my $query = qq|SELECT sum(a.amount - a.paid) AS dunning_amount FROM ar a |
1703 |
WHERE a.paid < a.amount AND a.customer_id = ? AND a.dunning_id IS NOT NULL|; |
|
1703 |
WHERE a.paid < a.amount AND a.customer_id = ? AND a.dunning_config_id IS NOT NULL|;
|
|
1704 | 1704 |
$ref = selectfirst_hashref_query($form, $dbh, $query, $form->{customer_id}); |
1705 | 1705 |
map { $form->{$_} = $ref->{$_} } keys %$ref; |
1706 | 1706 |
|
1707 | 1707 |
my $query = qq|SELECT dnn.dunning_description AS max_dunning_level FROM dunning_config dnn |
1708 |
WHERE id in (SELECT dunning_id from ar WHERE paid < amount AND customer_id = ? AND dunning_id IS NOT NULL) |
|
1708 |
WHERE id in (SELECT dunning_config_id from ar WHERE paid < amount AND customer_id = ? AND dunning_id IS NOT NULL)
|
|
1709 | 1709 |
ORDER BY dunning_level DESC LIMIT 1|; |
1710 | 1710 |
$ref = selectfirst_hashref_query($form, $dbh, $query, $form->{customer_id}); |
1711 | 1711 |
map { $form->{$_} = $ref->{$_} } keys %$ref; |
bin/mozilla/dn.pl | ||
---|---|---|
163 | 163 |
$column_data{dunning_level} = |
164 | 164 |
qq|<td><input type=hidden size=2 name=dunning_level_$i value=$i>$i</td>|; |
165 | 165 |
$column_data{dunning_description} = qq|<td><input name=dunning_description_$i ></td>|; |
166 |
my $active = ""; |
|
167 | 166 |
$column_data{active} = |
168 |
qq|<td><input type=checkbox name=active_$i value=1 $active></td>|;
|
|
167 |
qq|<td><input type=checkbox name=active_$i value=1></td>|; |
|
169 | 168 |
my $email = ""; |
170 | 169 |
$column_data{email} = |
171 | 170 |
qq|<td><input type=checkbox name=email_$i value=1 $email><button type="button" onclick="set_email_window('email_subject_$i', 'email_body_$i', 'email_attachment_$i')">| . $locale->text('L') . qq|</button><input type=hidden name=email_body_$i><input type=hidden name=email_subject_$i><input type=hidden name=email_attachment_$i></td>|; |
... | ... | |
465 | 464 |
|; |
466 | 465 |
|
467 | 466 |
$form->{selectdunning} =~ s/ selected//g; |
468 |
if ($ref->{next_dunning_id} ne "") { |
|
469 |
$form->{selectdunning} =~ s/value=$ref->{next_dunning_id}/value=$ref->{next_dunning_id} selected/;
|
|
467 |
if ($ref->{next_dunning_config_id} ne "") {
|
|
468 |
$form->{selectdunning} =~ s/value=$ref->{next_dunning_config_id}/value=$ref->{next_dunning_config_id} selected/;
|
|
470 | 469 |
} |
471 | 470 |
|
472 | 471 |
|
473 |
$dunning = qq|<select name=next_dunning_id_$i>$form->{selectdunning}</select>|; |
|
472 |
$dunning = qq|<select name=next_dunning_config_id_$i>$form->{selectdunning}</select>|;
|
|
474 | 473 |
|
475 | 474 |
|
476 | 475 |
$column_data{dunning_description} = qq|<td><input type=hidden name=inv_id_$i size=2 value="$ref->{id}"><input type=hidden name=customer_id_$i size=2 value="$ref->{customer_id}">$ref->{dunning_level}: $dunning</td>|; |
... | ... | |
589 | 588 |
} |
590 | 589 |
} |
591 | 590 |
if (scalar(@{ $form->{inv_ids} }) != 0) { |
592 |
DN->save_dunning(\%myconfig, \%$form, \@rows, $userspath,$spool, $sendmail); |
|
591 |
DN->save_dunning(\%myconfig, \%$form, \@rows, $userspath, $spool, $sendmail);
|
|
593 | 592 |
} |
594 | 593 |
} |
595 | 594 |
} else { |
... | ... | |
598 | 597 |
@rows = (); |
599 | 598 |
$form->{inv_ids} = [ $form->{"inv_id_$i"} ]; |
600 | 599 |
push(@rows, $i); |
601 |
DN->save_dunning(\%myconfig, \%$form, \@rows, $userspath,$spool, $sendmail); |
|
600 |
DN->save_dunning(\%myconfig, \%$form, \@rows, $userspath, $spool, $sendmail);
|
|
602 | 601 |
} |
603 | 602 |
} |
604 | 603 |
} |
... | ... | |
887 | 886 |
print qq| |
888 | 887 |
</tr> |
889 | 888 |
|; |
889 |
|
|
890 |
my %columns = ( |
|
891 |
"dunning_duedate" => "next_duedate", |
|
892 |
"duedate" => "inv_duedate", |
|
893 |
"transdate" => "invdate", |
|
894 |
"amount" => "invamount", |
|
895 |
); |
|
896 |
|
|
890 | 897 |
my $i = 0; |
891 | 898 |
my $j = 0; |
892 |
my $previous_customer_id;
|
|
899 |
my ($previous_dunning_id, $first_row_for_dunning);
|
|
893 | 900 |
foreach $ref (@{ $form->{DUNNINGS} }) { |
894 | 901 |
$i++; |
895 |
$j++ if ($previous_customer_id != $ref->{customer_id}); |
|
896 |
$j = $j % 2; |
|
897 |
$previous_customer_id = $ref->{customer_id}; |
|
902 |
|
|
903 |
if ($previous_dunning_id != $ref->{dunning_id}) { |
|
904 |
$j++; |
|
905 |
$j = $j % 2; |
|
906 |
$first_row_for_dunning = 1; |
|
907 |
} else { |
|
908 |
$first_row_for_dunning = 0; |
|
909 |
} |
|
910 |
$previous_dunning_id = $ref->{dunning_id}; |
|
898 | 911 |
|
899 | 912 |
print qq| |
900 | 913 |
<tr valign=top class=listrow$j> |
... | ... | |
902 | 915 |
|
903 | 916 |
|
904 | 917 |
|
905 |
$dunning = qq|<select name=next_dunning_id_$i>$form->{selectdunning}</select>|; |
|
906 |
my $script = ""; |
|
907 |
if ($ref->{invoice}) { |
|
908 |
$script = "is.pl"; |
|
909 |
} else { |
|
910 |
$script = "ar.pl"; |
|
918 |
foreach (qw(dunning_date dunning_duedate duedate transdate customername |
|
919 |
amount fee interest)) { |
|
920 |
my $col = $columns{$_} ? $columns{$_} : $_; |
|
921 |
$column_data{$col} = "<td>" . H($ref->{$_}) . "</td>"; |
|
911 | 922 |
} |
912 |
$column_data{dunning_description} = qq|<td><a href=dn.pl?action=print_dunning&dunning_id=$ref->{dunning_id}&customer_id=$ref->{customer_id}&format=pdf&media=screen&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$form->{callback}>$ref->{dunning_description}</a></td>|; |
|
913 |
my $active = "checked"; |
|
914 |
$column_data{dunning_date} = qq|<td>$ref->{dunning_date}</td>|; |
|
915 |
$column_data{next_duedate} = qq|<td>$ref->{dunning_duedate}</td>|; |
|
916 |
|
|
917 |
$column_data{inv_duedate} = qq|<td>$ref->{duedate}</td>|; |
|
918 |
$column_data{invdate} = qq|<td>$ref->{transdate}</td>|; |
|
919 |
$column_data{invnumber} = qq|<td><a href=$script?action=edit&id=$ref->{id}&path=$form->{path}&login=$form->{login}&password=$form->{password}&callback=$form->{callback}>$ref->{invnumber}</a></td>|; |
|
920 |
$column_data{customername} = qq|<td>$ref->{customername}</td>|; |
|
921 |
$column_data{invamount} = qq|<td>$ref->{amount}</td>|; |
|
922 |
$column_data{fee} = qq|<td>$ref->{fee}</td>|; |
|
923 |
$column_data{interest} = qq|<td>$ref->{interest}</td>|; |
|
924 | 923 |
|
924 |
if ($first_row_for_dunning) { |
|
925 |
$column_data{dunning_description} = |
|
926 |
qq|<td><a href="dn.pl?action=print_dunning&format=pdf&media=screen&| . |
|
927 |
qq|dunning_id=| . E($ref->{dunning_id}) . |
|
928 |
join(map({ "&${_}=" . E($form->{$_}) } qw(login path password callback))) . |
|
929 |
qq|">| . H($ref->{dunning_description}) . qq|</a></td>|; |
|
930 |
} else { |
|
931 |
$column_data{dunning_description} = qq|<td> </td>|; |
|
932 |
$column_data{customername} = qq|<td> </td>|; |
|
933 |
} |
|
925 | 934 |
|
935 |
$column_data{invnumber} = |
|
936 |
qq|<td><a href="| . ($ref->{invoice} ? "is.pl" : "ar.pl" ) . |
|
937 |
qq|?action=edit&id=| . H($ref->{id}) . |
|
938 |
join(map({ "&${_}=" . E($form->{$_}) } qw(login path password callback))) . |
|
939 |
qq|">| . H($ref->{invnumber}) . qq|</a></td>|; |
|
926 | 940 |
|
927 | 941 |
map { print "$column_data{$_}\n" } @column_index; |
928 | 942 |
|
... | ... | |
968 | 982 |
sub print_dunning { |
969 | 983 |
$lxdebug->enter_sub(); |
970 | 984 |
|
971 |
DN->print_dunning(\%myconfig, \%$form, $form->{dunning_id}, $form->{customer_id}, $userspath, $spool, $sendmail);
|
|
985 |
DN->print_dunning(\%myconfig, \%$form, $form->{dunning_id}, $userspath, $spool, $sendmail); |
|
972 | 986 |
|
973 | 987 |
if($form->{DUNNING_PDFS}) { |
974 | 988 |
DN->melt_pdfs(\%myconfig, \%$form,$spool); |
lx-erp.conf | ||
---|---|---|
81 | 81 |
# |
82 | 82 |
# Beipiel: |
83 | 83 |
# $LXDebug::global_level = LXDebug::TRACE | LXDebug::QUERY; |
84 |
$LXDebug::global_level = LXDebug::NONE;
|
|
84 |
$LXDebug::global_level = LXDebug::ALL;
|
|
85 | 85 |
|
86 | 86 |
1; |
87 | 87 |
|
sql/Pg-upgrade2/dunning_dunning_id.sql | ||
---|---|---|
1 |
-- @tag: dunning_dunning_id |
|
2 |
-- @description: In der Tabelle dunning ist dunning_id falsch benannt und es fehlt eine Spalte, die mehrere Einträge zusammenfasst. |
|
3 |
-- @depends: release_2_4_2 |
|
4 |
ALTER TABLE dunning ADD COLUMN dunning_config_id integer; |
|
5 |
UPDATE dunning SET dunning_config_id = dunning_id; |
|
6 |
ALTER TABLE dunning ADD FOREIGN KEY (dunning_config_id) REFERENCES dunning_config (id); |
|
7 |
|
|
8 |
ALTER TABLE dunning ADD COLUMN itime timestamp; |
|
9 |
ALTER TABLE dunning ALTER COLUMN itime SET DEFAULT now(); |
|
10 |
UPDATE dunning SET itime = now(); |
|
11 |
|
|
12 |
ALTER TABLE dunning ADD COLUMN mtime timestamp; |
|
13 |
CREATE TRIGGER mtime_dunning |
|
14 |
BEFORE UPDATE ON dunning |
|
15 |
FOR EACH ROW |
|
16 |
EXECUTE PROCEDURE set_mtime(); |
|
17 |
|
|
18 |
UPDATE dunning SET dunning_id = nextval('id'); |
|
19 |
|
|
20 |
ALTER TABLE ar RENAME COLUMN dunning_id TO dunning_config_id; |
|
21 |
ALTER TABLE ar ADD FOREIGN KEY (dunning_config_id) REFERENCES dunning_config (id); |
Auch abrufbar als: Unified diff
Mahnwesen: Die Tabelle dunning so umgebaut, dass gemeinsam gestartete Mahnungen auch später gemeinsam erneut ausgedruckt werden können. Dafür auch die Listenansicht bereits gestarteter Mahnungen verbessert.