Revision 529c6ea4
Von Sven Schöling vor fast 18 Jahren hinzugefügt
SL/IS.pm | ||
---|---|---|
1090 | 1090 |
} |
1091 | 1091 |
|
1092 | 1092 |
sub post_payment { |
1093 |
$main::lxdebug->enter_sub(); |
|
1094 |
|
|
1095 |
my ($self, $myconfig, $form, $locale) = @_; |
|
1093 |
$main::lxdebug->enter_sub() and my ($self, $myconfig, $form, $locale) = @_; |
|
1096 | 1094 |
|
1097 | 1095 |
# connect to database, turn off autocommit |
1098 | 1096 |
my $dbh = $form->dbconnect_noauto($myconfig); |
... | ... | |
1101 | 1099 |
|
1102 | 1100 |
# total payments, don't move we need it here |
1103 | 1101 |
for my $i (1 .. $form->{paidaccounts}) { |
1104 |
if ($form->{type} eq "credit_note") { |
|
1105 |
$form->{"paid_$i"} = $form->parse_amount($myconfig, $form->{"paid_$i"}) * -1; |
|
1106 |
} else { |
|
1107 |
$form->{"paid_$i"} = $form->parse_amount($myconfig, $form->{"paid_$i"}); |
|
1108 |
} |
|
1109 |
$form->{paid} += $form->{"paid_$i"}; |
|
1110 |
$form->{datepaid} = $form->{"datepaid_$i"} if ($form->{"datepaid_$i"}); |
|
1102 |
$form->{"paid_$i"} = $form->parse_amount($myconfig, $form->{"paid_$i"}); |
|
1103 |
$form->{"paid_$i"} *= -1 if ($form->{type} eq "credit_note"); |
|
1104 |
$form->{"paid"} += $form->{"paid_$i"}; |
|
1105 |
$form->{"datepaid"} = $form->{"datepaid_$i"} if ($form->{"datepaid_$i"}); |
|
1111 | 1106 |
} |
1112 | 1107 |
|
1113 |
$form->{exchangerate} = |
|
1114 |
$form->get_exchangerate($dbh, $form->{currency}, $form->{invdate}, |
|
1115 |
"buy"); |
|
1116 |
|
|
1117 |
my $project_id = conv_i($form->{"globalproject_id"}); |
|
1108 |
$form->{exchangerate} = $form->get_exchangerate($dbh, $form->{currency}, $form->{invdate}, "buy"); |
|
1118 | 1109 |
|
1119 | 1110 |
# record payments and offsetting AR |
1120 | 1111 |
for my $i (1 .. $form->{paidaccounts}) { |
1112 |
if ($form->{"paid_$i"}) { |
|
1121 | 1113 |
|
1122 |
if ($form->{"paid_$i"} != 0) { |
|
1123 | 1114 |
my ($accno) = split /--/, $form->{"AR_paid_$i"}; |
1124 |
$form->{"datepaid_$i"} = $form->{invdate} |
|
1125 |
unless ($form->{"datepaid_$i"}); |
|
1115 |
$form->{"datepaid_$i"} = $form->{invdate} unless ($form->{"datepaid_$i"}); |
|
1126 | 1116 |
$form->{datepaid} = $form->{"datepaid_$i"}; |
1127 | 1117 |
|
1128 | 1118 |
$exchangerate = 0; |
1129 | 1119 |
if (($form->{currency} eq $form->{defaultcurrency}) || ($form->{defaultcurrency} eq "")) { |
1130 | 1120 |
$form->{"exchangerate_$i"} = 1; |
1131 | 1121 |
} else { |
1132 |
$exchangerate = |
|
1133 |
$form->check_exchangerate($myconfig, $form->{currency}, |
|
1134 |
$form->{"datepaid_$i"}, 'buy'); |
|
1135 |
|
|
1136 |
$form->{"exchangerate_$i"} = |
|
1137 |
($exchangerate) |
|
1138 |
? $exchangerate |
|
1139 |
: $form->parse_amount($myconfig, $form->{"exchangerate_$i"}); |
|
1122 |
$exchangerate = $form->check_exchangerate($myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'); |
|
1123 |
$form->{"exchangerate_$i"} = ($exchangerate) ? $exchangerate : $form->parse_amount($myconfig, $form->{"exchangerate_$i"}); |
|
1140 | 1124 |
} |
1141 | 1125 |
|
1142 | 1126 |
# record AR |
1143 |
$amount = |
|
1144 |
$form->round_amount($form->{"paid_$i"} * $form->{"exchangerate"}, |
|
1145 |
2); |
|
1146 |
|
|
1147 |
|
|
1148 |
$query = qq|DELETE FROM acc_trans WHERE trans_id=$form->{id} AND chart_id=(SELECT c.id FROM chart c |
|
1149 |
WHERE c.accno = '$form->{AR}') AND amount=$amount AND transdate='$form->{"datepaid_$i"}'|; |
|
1150 |
$dbh->do($query) || $form->dberror($query); |
|
1151 |
|
|
1152 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, |
|
1153 |
transdate, project_id) |
|
1154 |
VALUES ($form->{id}, (SELECT c.id FROM chart c |
|
1155 |
WHERE c.accno = '$form->{AR}'), |
|
1156 |
$amount, '$form->{"datepaid_$i"}', ?)|; |
|
1157 |
do_query($form, $dbh, $query, $project_id); |
|
1127 |
$amount = $form->round_amount($form->{"paid_$i"} * $form->{"exchangerate"}, 2); |
|
1158 | 1128 |
|
1129 |
$query = qq|DELETE FROM acc_trans WHERE trans_id = ? AND chart_id = (SELECT c.id FROM chart c WHERE c.accno = ?) AND amount = ? AND transdate = ?|; |
|
1130 |
do_query($form, $dbh, $query, $form->{id}, $form->{AR}, $amount, $form->{"datepaid_$i"}); |
|
1131 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, project_id) VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?)|; |
|
1132 |
do_query($form, $dbh, $query, $form->{id}, $form->{AR}, $amount, $form->{"datepaid_$i"}, conv_i($form->{"globalproject_id"})); |
|
1159 | 1133 |
|
1160 | 1134 |
# record payment |
1161 | 1135 |
$form->{"paid_$i"} *= -1; |
1162 | 1136 |
|
1163 |
$query = qq|DELETE FROM acc_trans WHERE trans_id=$form->{id} AND chart_id=(SELECT c.id FROM chart c |
|
1164 |
WHERE c.accno = '$accno') AND amount=$form->{"paid_$i"} AND transdate='$form->{"datepaid_$i"}' AND source='$form->{"source_$i"}' AND memo='$form->{"memo_$i"}'|; |
|
1165 |
$dbh->do($query) || $form->dberror($query); |
|
1166 |
|
|
1167 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, |
|
1168 |
source, memo, project_id) |
|
1169 |
VALUES ($form->{id}, (SELECT c.id FROM chart c |
|
1170 |
WHERE c.accno = '$accno'), |
|
1171 |
$form->{"paid_$i"}, '$form->{"datepaid_$i"}', |
|
1172 |
'$form->{"source_$i"}', '$form->{"memo_$i"}', ?)|; |
|
1173 |
do_query($form, $dbh, $query, $project_id); |
|
1174 |
|
|
1137 |
$query = qq|DELETE FROM acc_trans WHERE trans_id = ? AND chart_id = (SELECT c.id FROM chart c WHERE c.accno = ?) AND amount = ? AND transdate = ? AND source = ? AND memo = ?|; |
|
1138 |
do_query($form, $dbh, $query, $form->{id}, $accno, $form->{"paid_$i"}, $form->{"datepaid_$i"}, $form->{"source_$i"}, $form->{"memo_$i"}); |
|
1139 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, source, memo, project_id) VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?, ?)|; |
|
1140 |
do_query($form, $dbh, $query, $form->{id}, $accno, $form->{"paid_$i"}, $form->{"datepaid_$i"}, $form->{"source_$i"}, $form->{"memo_$i"}, conv_i($form->{"globalproject_id"})); |
|
1175 | 1141 |
|
1176 | 1142 |
# gain/loss |
1177 |
$amount = |
|
1178 |
$form->{"paid_$i"} * $form->{exchangerate} - $form->{"paid_$i"} * |
|
1179 |
$form->{"exchangerate_$i"}; |
|
1180 |
if ($amount > 0) { |
|
1181 |
$form->{fx}{ $form->{fxgain_accno} }{ $form->{"datepaid_$i"} } += |
|
1182 |
$amount; |
|
1183 |
} else { |
|
1184 |
$form->{fx}{ $form->{fxloss_accno} }{ $form->{"datepaid_$i"} } += |
|
1185 |
$amount; |
|
1186 |
} |
|
1143 |
$amount = $form->{"paid_$i"} * $form->{exchangerate} - $form->{"paid_$i"} * $form->{"exchangerate_$i"}; |
|
1144 |
$form->{fx}{ $form->{($amount > 0 ? 'fxgain_accno' : 'fxloss_accno')} }{ $form->{"datepaid_$i"} } += $amount; |
|
1187 | 1145 |
|
1188 | 1146 |
$diff = 0; |
1189 | 1147 |
|
1190 | 1148 |
# update exchange rate |
1191 | 1149 |
if (($form->{currency} ne $form->{defaultcurrency}) && !$exchangerate) { |
1192 |
$form->update_exchangerate($dbh, $form->{currency}, |
|
1193 |
$form->{"datepaid_$i"}, |
|
1194 |
$form->{"exchangerate_$i"}, 0); |
|
1150 |
$form->update_exchangerate($dbh, $form->{currency}, $form->{"datepaid_$i"}, $form->{"exchangerate_$i"}, 0); |
|
1195 | 1151 |
} |
1152 |
|
|
1196 | 1153 |
} |
1197 | 1154 |
} |
1198 | 1155 |
|
1199 | 1156 |
# record exchange rate differences and gains/losses |
1200 | 1157 |
foreach my $accno (keys %{ $form->{fx} }) { |
1201 | 1158 |
foreach my $transdate (keys %{ $form->{fx}{$accno} }) { |
1202 |
if ( |
|
1203 |
($form->{fx}{$accno}{$transdate} = |
|
1204 |
$form->round_amount($form->{fx}{$accno}{$transdate}, 2) |
|
1205 |
) != 0 |
|
1206 |
) { |
|
1207 |
$query = qq|DELETE FROM acc_trans WHERE trans_id=$form->{id} AND chart_id=(SELECT c.id FROM chart c |
|
1208 |
WHERE c.accno = '$accno') AND amount=$form->{fx}{$accno}{$transdate} AND transdate='$transdate' AND cleared='0' AND fx_transaction='1'|; |
|
1209 |
$dbh->do($query) || $form->dberror($query); |
|
1210 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, |
|
1211 |
transdate, cleared, fx_transaction, project_id) |
|
1212 |
VALUES ($form->{id}, |
|
1213 |
(SELECT c.id FROM chart c |
|
1214 |
WHERE c.accno = '$accno'), |
|
1215 |
$form->{fx}{$accno}{$transdate}, '$transdate', '0', '1', ?)|; |
|
1216 |
do_query($form, $dbh, $query, $project_id); |
|
1159 |
|
|
1160 |
if ($form->{fx}{$accno}{$transdate} = $form->round_amount($form->{fx}{$accno}{$transdate}, 2)) { # '=' is no typo, it's an assignment |
|
1161 |
$query = qq|DELETE FROM acc_trans WHERE trans_id = ? AND chart_id = (SELECT c.id FROM chart c WHERE c.accno = ?) |
|
1162 |
AND amount = ? AND transdate = ? AND cleared = ? AND fx_transaction = ?|; |
|
1163 |
do_query($form, $dbh, $query, $form->{id}, $accno, $form->{fx}{$accno}{$transdate}, $transdate, 0, 1); |
|
1164 |
$query = qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, cleared, fx_transaction, project_id) |
|
1165 |
VALUES (?, (SELECT c.id FROM chart c WHERE c.accno = ?), ?, ?, ?, ?, ?)|; |
|
1166 |
do_query($form, $dbh, $query, $form->{id}, $accno, $form->{fx}{$accno}{$transdate}, $transdate, 0, 1, conv_i($form->{"globalproject_id"})); |
|
1217 | 1167 |
} |
1168 |
|
|
1218 | 1169 |
} |
1219 | 1170 |
} |
1220 |
my $datepaid = ($form->{paid}) ? qq|'$form->{datepaid}'| : "NULL"; |
|
1221 | 1171 |
|
1222 | 1172 |
# save AR record |
1223 |
my $query = qq|UPDATE ar set |
|
1224 |
paid = $form->{paid}, |
|
1225 |
datepaid = $datepaid |
|
1226 |
WHERE id=$form->{id}|; |
|
1173 |
delete $form->{datepaid} unless $form->{paid}; |
|
1227 | 1174 |
|
1228 |
$dbh->do($query) || $form->dberror($query); |
|
1175 |
my $query = qq|UPDATE ar set paid = ?, datepaid = ? WHERE id = ?|; |
|
1176 |
do_query($form, $dbh, $query, $form->{paid}, $form->{datepaid}, $form->{id}); |
|
1229 | 1177 |
|
1230 | 1178 |
my $rc = $dbh->commit; |
1231 | 1179 |
$dbh->disconnect; |
1232 | 1180 |
|
1233 |
$main::lxdebug->leave_sub(); |
|
1234 |
|
|
1235 |
return $rc; |
|
1181 |
$main::lxdebug->leave_sub() and return $rc; |
|
1236 | 1182 |
} |
1237 | 1183 |
|
1238 | 1184 |
sub process_assembly { |
Auch abrufbar als: Unified diff
IS::post_payment auf derzeitigen Stand gebracht um hinterher bug 583 anzugehen.
Aenderungen sind zum Grossteil sicherheitsrelevant oder kosmetisch.
- Aenderungen von perltidy wurden rueckgaengig gemacht (voellig unleserlich)
- Queries werden jetzt sicher ueber do_query und DBI gehandhabt
- einige seltsame if abfragen wurden gefaltet
- reihenfolge der statements leichter lesbar gemacht