12 |
12 |
|
13 |
13 |
use SL::DB::Buchungsgruppe;
|
14 |
14 |
use SL::DB::Currency;
|
|
15 |
use SL::DB::Exchangerate;
|
15 |
16 |
use SL::DB::Customer;
|
16 |
17 |
use SL::DB::Vendor;
|
17 |
18 |
use SL::DB::Employee;
|
... | ... | |
21 |
22 |
use SL::DB::TaxZone;
|
22 |
23 |
use SL::DB::BankAccount;
|
23 |
24 |
use SL::DB::PaymentTerm;
|
|
25 |
use Data::Dumper;
|
24 |
26 |
|
25 |
|
my ($customer, $vendor, $currency_id, @parts, $buchungsgruppe, $buchungsgruppe7, $unit, $employee, $tax, $tax7, $taxzone, $payment_terms, $bank_account);
|
|
27 |
my ($customer, $vendor, $currency_id, @parts, $buchungsgruppe, $buchungsgruppe7, $unit, $employee, $tax, $tax7, $tax_9, $taxzone, $payment_terms, $bank_account);
|
|
28 |
my ($transdate, $transdate2, $currency, $exchangerate, $exchangerate2);
|
|
29 |
my ($ar_chart,$bank,$ar_amount_chart, $ap_chart, $ap_amount_chart);
|
26 |
30 |
|
27 |
31 |
my $ALWAYS_RESET = 1;
|
28 |
32 |
|
... | ... | |
39 |
43 |
SL::DB::Manager::Vendor->delete_all(all => 1);
|
40 |
44 |
SL::DB::Manager::BankAccount->delete_all(all => 1);
|
41 |
45 |
SL::DB::Manager::PaymentTerm->delete_all(all => 1);
|
|
46 |
SL::DB::Manager::Exchangerate->delete_all(all => 1);
|
|
47 |
SL::DB::Manager::Currency->delete_all(where => [ name => 'CUR' ]);
|
42 |
48 |
};
|
43 |
49 |
|
44 |
50 |
sub reset_state {
|
... | ... | |
50 |
56 |
|
51 |
57 |
clear_up();
|
52 |
58 |
|
|
59 |
$transdate = DateTime->today;
|
|
60 |
$transdate2 = DateTime->today->add(days => 1);
|
53 |
61 |
|
54 |
62 |
$buchungsgruppe = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 19%', %{ $params{buchungsgruppe} }) || croak "No accounting group";
|
55 |
63 |
$buchungsgruppe7 = SL::DB::Manager::Buchungsgruppe->find_by(description => 'Standard 7%') || croak "No accounting group for 7\%";
|
... | ... | |
58 |
66 |
$tax = SL::DB::Manager::Tax->find_by(taxkey => 3, rate => 0.19, %{ $params{tax} }) || croak "No tax";
|
59 |
67 |
$tax7 = SL::DB::Manager::Tax->find_by(taxkey => 2, rate => 0.07) || croak "No tax for 7\%";
|
60 |
68 |
$taxzone = SL::DB::Manager::TaxZone->find_by( description => 'Inland') || croak "No taxzone";
|
|
69 |
$tax_9 = SL::DB::Manager::Tax->find_by(taxkey => 9, rate => 0.19, %{ $params{tax} }) || croak "No tax";
|
|
70 |
# $tax7 = SL::DB::Manager::Tax->find_by(taxkey => 2, rate => 0.07) || croak "No tax for 7\%";
|
61 |
71 |
|
62 |
72 |
$currency_id = $::instance_conf->get_currency_id;
|
63 |
73 |
|
|
74 |
$currency = SL::DB::Currency->new(name => 'CUR')->save;
|
|
75 |
$exchangerate = SL::DB::Exchangerate->new(transdate => $transdate,
|
|
76 |
buy => '1.33333',
|
|
77 |
sell => '1.33333',
|
|
78 |
currency_id => $currency->id,
|
|
79 |
)->save;
|
|
80 |
$exchangerate2 = SL::DB::Exchangerate->new(transdate => $transdate2,
|
|
81 |
buy => '1.55555',
|
|
82 |
sell => '1.55555',
|
|
83 |
currency_id => $currency->id,
|
|
84 |
)->save;
|
|
85 |
|
64 |
86 |
$customer = SL::DB::Customer->new(
|
65 |
87 |
name => 'Test Customer',
|
66 |
88 |
currency_id => $currency_id,
|
... | ... | |
135 |
157 |
%{ $params{part4} }
|
136 |
158 |
)->save;
|
137 |
159 |
|
|
160 |
$ar_chart = SL::DB::Manager::Chart->find_by( accno => '1400' ); # Forderungen
|
|
161 |
$ap_chart = SL::DB::Manager::Chart->find_by( accno => '1600' ); # Verbindlichkeiten
|
|
162 |
$bank = SL::DB::Manager::Chart->find_by( accno => '1200' ); # Bank
|
|
163 |
$ar_amount_chart = SL::DB::Manager::Chart->find_by( accno => '8400' ); # Erlöse
|
|
164 |
$ap_amount_chart = SL::DB::Manager::Chart->find_by( accno => '3400' ); # Wareneingang 19%
|
|
165 |
|
138 |
166 |
$reset_state_counter++;
|
139 |
167 |
}
|
140 |
168 |
|
... | ... | |
179 |
207 |
# %params,
|
180 |
208 |
)->save;
|
181 |
209 |
|
182 |
|
my $today = DateTime->today_local->to_kivitendo;
|
183 |
210 |
my $expense_chart = SL::DB::Manager::Chart->find_by(accno => '3400');
|
184 |
211 |
my $expense_chart_booking= SL::DB::AccTransaction->new(
|
185 |
212 |
trans_id => $purchase_invoice->id,
|
186 |
213 |
chart_id => $expense_chart->id,
|
187 |
214 |
chart_link => $expense_chart->link,
|
188 |
215 |
amount => '-100',
|
189 |
|
transdate => $today,
|
|
216 |
transdate => $transdate,
|
190 |
217 |
source => '',
|
191 |
218 |
taxkey => 9,
|
192 |
219 |
tax_id => SL::DB::Manager::Tax->find_by(taxkey => 9)->id);
|
... | ... | |
198 |
225 |
chart_id => $tax_chart->id,
|
199 |
226 |
chart_link => $tax_chart->link,
|
200 |
227 |
amount => '-19',
|
201 |
|
transdate => $today,
|
|
228 |
transdate => $transdate,
|
202 |
229 |
source => '',
|
203 |
230 |
taxkey => 0,
|
204 |
231 |
tax_id => SL::DB::Manager::Tax->find_by(taxkey => 9)->id);
|
... | ... | |
209 |
236 |
chart_id => $expense_chart->id,
|
210 |
237 |
chart_link => $expense_chart->link,
|
211 |
238 |
amount => '-100',
|
212 |
|
transdate => $today,
|
|
239 |
transdate => $transdate,
|
213 |
240 |
source => '',
|
214 |
241 |
taxkey => 8,
|
215 |
242 |
tax_id => SL::DB::Manager::Tax->find_by(taxkey => 8)->id);
|
... | ... | |
222 |
249 |
chart_id => $tax_chart->id,
|
223 |
250 |
chart_link => $tax_chart->link,
|
224 |
251 |
amount => '-7',
|
225 |
|
transdate => $today,
|
|
252 |
transdate => $transdate,
|
226 |
253 |
source => '',
|
227 |
254 |
taxkey => 0,
|
228 |
255 |
tax_id => SL::DB::Manager::Tax->find_by(taxkey => 8)->id);
|
... | ... | |
232 |
259 |
chart_id => $arap_chart->id,
|
233 |
260 |
chart_link => $arap_chart->link,
|
234 |
261 |
amount => '226',
|
235 |
|
transdate => $today,
|
|
262 |
transdate => $transdate,
|
236 |
263 |
source => '',
|
237 |
264 |
taxkey => 0,
|
238 |
265 |
tax_id => SL::DB::Manager::Tax->find_by(taxkey => 0)->id);
|
... | ... | |
623 |
650 |
|
624 |
651 |
}
|
625 |
652 |
|
626 |
|
sub test_default_invoice_two_items_19_7_tax_without_skonto_multiple_payments_final_difference_as_skonto_2cent() {
|
|
653 |
sub test_default_invoice_two_items_19_7_tax_without_skonto_multiple_payments_final_difference_as_skonto_2cent() {
|
627 |
654 |
reset_state() if $ALWAYS_RESET;
|
628 |
655 |
|
629 |
656 |
# if there are two cents left there will be two skonto bookings, 1 cent each
|
... | ... | |
998 |
1025 |
is($total, 0, "${title}: even balance: this will fail due to rounding error in invoice post, not the skonto");
|
999 |
1026 |
}
|
1000 |
1027 |
|
|
1028 |
sub test_ar_currency_tax_not_included_and_payment {
|
|
1029 |
my $netamount = $::form->round_amount(75 * $exchangerate->sell,2); # 75 in CUR, 100.00 in EUR
|
|
1030 |
my $amount = $::form->round_amount($netamount * 1.19,2); # 100 in CUR, 119.00 in EUR
|
|
1031 |
my $invoice = SL::DB::Invoice->new(
|
|
1032 |
invoice => 0,
|
|
1033 |
amount => $amount,
|
|
1034 |
netamount => $netamount,
|
|
1035 |
transdate => $transdate,
|
|
1036 |
taxincluded => 0,
|
|
1037 |
customer_id => $customer->id,
|
|
1038 |
taxzone_id => $customer->taxzone_id,
|
|
1039 |
currency_id => $currency->id,
|
|
1040 |
transactions => [],
|
|
1041 |
notes => 'test_ar_currency_tax_not_included_and_payment',
|
|
1042 |
);
|
|
1043 |
$invoice->add_ar_amount_row(
|
|
1044 |
amount => $invoice->netamount,
|
|
1045 |
chart => $ar_amount_chart,
|
|
1046 |
tax_id => $tax->id,
|
|
1047 |
);
|
|
1048 |
|
|
1049 |
$invoice->create_ar_row(chart => $ar_chart);
|
|
1050 |
$invoice->save;
|
|
1051 |
|
|
1052 |
is(SL::DB::Manager::Invoice->get_all_count(where => [ invoice => 0 ]), 1, 'there is one ar transaction');
|
|
1053 |
is($invoice->currency_id , $currency->id , 'currency_id has been saved');
|
|
1054 |
is($invoice->netamount , 100 , 'ar amount has been converted');
|
|
1055 |
is($invoice->amount , 119 , 'ar amount has been converted');
|
|
1056 |
is($invoice->taxincluded , 0 , 'ar transaction doesn\'t have taxincluded');
|
|
1057 |
is(SL::DB::Manager::AccTransaction->find_by(chart_id => $ar_amount_chart->id, trans_id => $invoice->id)->amount, '100.00000', $ar_amount_chart->accno . ': has been converted for currency');
|
|
1058 |
is(SL::DB::Manager::AccTransaction->find_by(chart_id => $ar_chart->id, trans_id => $invoice->id)->amount, '-119.00000', $ar_chart->accno . ': has been converted for currency');
|
|
1059 |
|
|
1060 |
$invoice->pay_invoice(chart_id => $bank->id,
|
|
1061 |
amount => 50,
|
|
1062 |
currency => 'CUR',
|
|
1063 |
transdate => $transdate->to_kivitendo,
|
|
1064 |
);
|
|
1065 |
$invoice->pay_invoice(chart_id => $bank->id,
|
|
1066 |
amount => 39.25,
|
|
1067 |
currency => 'CUR',
|
|
1068 |
transdate => $transdate->to_kivitendo,
|
|
1069 |
);
|
|
1070 |
# $invoice->pay_invoice(chart_id => $bank->id,
|
|
1071 |
# amount => 30,
|
|
1072 |
# transdate => $transdate2->to_kivitendo,
|
|
1073 |
# );
|
|
1074 |
is(scalar @{$invoice->transactions}, 9, 'ar transaction has 9 transactions (incl. fxtransactions)');
|
|
1075 |
is($invoice->paid, $invoice->amount, 'ar transaction paid = amount in default currency');
|
|
1076 |
};
|
|
1077 |
|
|
1078 |
sub test_ar_currency_tax_included {
|
|
1079 |
# we want the acc_trans amount to be 100
|
|
1080 |
my $amount = $::form->round_amount(75 * $exchangerate->sell * 1.19);
|
|
1081 |
my $netamount = $::form->round_amount($amount / 1.19,2);
|
|
1082 |
my $invoice = SL::DB::Invoice->new(
|
|
1083 |
invoice => 0,
|
|
1084 |
amount => 119, #$amount,
|
|
1085 |
netamount => 100, #$netamount,
|
|
1086 |
transdate => $transdate,
|
|
1087 |
taxincluded => 1,
|
|
1088 |
customer_id => $customer->id,
|
|
1089 |
taxzone_id => $customer->taxzone_id,
|
|
1090 |
currency_id => $currency->id,
|
|
1091 |
notes => 'test_ar_currency_tax_included',
|
|
1092 |
transactions => [],
|
|
1093 |
);
|
|
1094 |
$invoice->add_ar_amount_row( # should take care of taxincluded
|
|
1095 |
amount => $invoice->amount, # tax included in local currency
|
|
1096 |
chart => $ar_amount_chart,
|
|
1097 |
tax_id => $tax->id,
|
|
1098 |
);
|
|
1099 |
|
|
1100 |
$invoice->create_ar_row( chart => $ar_chart );
|
|
1101 |
$invoice->save;
|
|
1102 |
is(SL::DB::Manager::Invoice->get_all_count(where => [ invoice => 0 ]), 2, 'there are now two ar transactions');
|
|
1103 |
is($invoice->currency_id , $currency->id , 'currency_id has been saved');
|
|
1104 |
is($invoice->amount , $amount , 'amount ok');
|
|
1105 |
is($invoice->netamount , $netamount , 'netamount ok');
|
|
1106 |
is($invoice->taxincluded , 1 , 'ar transaction has taxincluded');
|
|
1107 |
is(SL::DB::Manager::AccTransaction->find_by(chart_id => $ar_amount_chart->id, trans_id => $invoice->id)->amount, '100.00000', $ar_amount_chart->accno . ': has been converted for currency');
|
|
1108 |
is(SL::DB::Manager::AccTransaction->find_by(chart_id => $ar_chart->id, trans_id => $invoice->id)->amount, '-119.00000', $ar_chart->accno . ': has been converted for currency');
|
|
1109 |
$invoice->pay_invoice(chart_id => $bank->id,
|
|
1110 |
amount => 89.25,
|
|
1111 |
currency => 'CUR',
|
|
1112 |
transdate => $transdate->to_kivitendo,
|
|
1113 |
);
|
|
1114 |
|
|
1115 |
};
|
|
1116 |
|
|
1117 |
sub test_ap_currency_tax_not_included_and_payment {
|
|
1118 |
my $netamount = $::form->round_amount(75 * $exchangerate->sell,2); # 75 in CUR, 100.00 in EUR
|
|
1119 |
my $amount = $::form->round_amount($netamount * 1.19,2); # 100 in CUR, 119.00 in EUR
|
|
1120 |
my $invoice = SL::DB::PurchaseInvoice->new(
|
|
1121 |
invoice => 0,
|
|
1122 |
invnumber => 'test_ap_currency_tax_not_included_and_payment',
|
|
1123 |
amount => $amount,
|
|
1124 |
netamount => $netamount,
|
|
1125 |
transdate => $transdate,
|
|
1126 |
taxincluded => 0,
|
|
1127 |
vendor_id => $vendor->id,
|
|
1128 |
taxzone_id => $vendor->taxzone_id,
|
|
1129 |
currency_id => $currency->id,
|
|
1130 |
transactions => [],
|
|
1131 |
notes => 'test_ap_currency_tax_not_included_and_payment',
|
|
1132 |
);
|
|
1133 |
$invoice->add_ap_amount_row(
|
|
1134 |
amount => $invoice->netamount,
|
|
1135 |
chart => $ap_amount_chart,
|
|
1136 |
tax_id => $tax_9->id,
|
|
1137 |
);
|
|
1138 |
|
|
1139 |
$invoice->create_ap_row(chart => $ap_chart);
|
|
1140 |
$invoice->save;
|
|
1141 |
|
|
1142 |
is($invoice->currency_id, $currency->id, 'currency_id has been saved');
|
|
1143 |
is($invoice->netamount, 100, 'ap amount has been converted');
|
|
1144 |
is($invoice->amount, 119, 'ap amount has been converted');
|
|
1145 |
is($invoice->taxincluded, 0, 'ap transaction doesn\'t have taxincluded');
|
|
1146 |
is(SL::DB::Manager::AccTransaction->find_by(chart_id => $ap_amount_chart->id, trans_id => $invoice->id)->amount, '-100.00000', $ap_amount_chart->accno . ': has been converted for currency');
|
|
1147 |
is(SL::DB::Manager::AccTransaction->find_by(chart_id => $ap_chart->id, trans_id => $invoice->id)->amount, '119.00000', $ap_chart->accno . ': has been converted for currency');
|
|
1148 |
|
|
1149 |
$invoice->pay_invoice(chart_id => $bank->id,
|
|
1150 |
amount => 50,
|
|
1151 |
currency => 'CUR',
|
|
1152 |
transdate => $transdate->to_kivitendo,
|
|
1153 |
);
|
|
1154 |
$invoice->pay_invoice(chart_id => $bank->id,
|
|
1155 |
amount => 39.25,
|
|
1156 |
currency => 'CUR',
|
|
1157 |
transdate => $transdate->to_kivitendo,
|
|
1158 |
);
|
|
1159 |
# $invoice->pay_invoice(chart_id => $bank->id,
|
|
1160 |
# amount => 30,
|
|
1161 |
# transdate => $transdate2->to_kivitendo,
|
|
1162 |
# );
|
|
1163 |
is(scalar @{$invoice->transactions}, 9, 'ap transaction has 9 transactions (incl. fxtransactions)');
|
|
1164 |
is($invoice->paid, $invoice->amount, 'ap transaction paid = amount in default currency');
|
|
1165 |
};
|
|
1166 |
|
|
1167 |
sub test_ap_currency_tax_included {
|
|
1168 |
# we want the acc_trans amount to be 100
|
|
1169 |
my $amount = $::form->round_amount(75 * $exchangerate->sell * 1.19);
|
|
1170 |
my $netamount = $::form->round_amount($amount / 1.19,2);
|
|
1171 |
my $invoice = SL::DB::PurchaseInvoice->new(
|
|
1172 |
invoice => 0,
|
|
1173 |
amount => 119, #$amount,
|
|
1174 |
netamount => 100, #$netamount,
|
|
1175 |
transdate => $transdate,
|
|
1176 |
taxincluded => 1,
|
|
1177 |
vendor_id => $vendor->id,
|
|
1178 |
taxzone_id => $vendor->taxzone_id,
|
|
1179 |
currency_id => $currency->id,
|
|
1180 |
notes => 'test_ap_currency_tax_included',
|
|
1181 |
invnumber => 'test_ap_currency_tax_included',
|
|
1182 |
transactions => [],
|
|
1183 |
);
|
|
1184 |
$invoice->add_ap_amount_row( # should take care of taxincluded
|
|
1185 |
amount => $invoice->amount, # tax included in local currency
|
|
1186 |
chart => $ap_amount_chart,
|
|
1187 |
tax_id => $tax_9->id,
|
|
1188 |
);
|
|
1189 |
|
|
1190 |
$invoice->create_ap_row( chart => $ap_chart );
|
|
1191 |
$invoice->save;
|
|
1192 |
is($invoice->currency_id , $currency->id , 'currency_id has been saved');
|
|
1193 |
is($invoice->amount , $amount , 'amount ok');
|
|
1194 |
is($invoice->netamount , $netamount , 'netamount ok');
|
|
1195 |
is($invoice->taxincluded , 1 , 'ap transaction has taxincluded');
|
|
1196 |
is(SL::DB::Manager::AccTransaction->find_by(chart_id => $ap_amount_chart->id, trans_id => $invoice->id)->amount, '-100.00000', $ap_amount_chart->accno . ': has been converted for currency');
|
|
1197 |
is(SL::DB::Manager::AccTransaction->find_by(chart_id => $ap_chart->id, trans_id => $invoice->id)->amount, '119.00000', $ap_chart->accno . ': has been converted for currency');
|
|
1198 |
|
|
1199 |
$invoice->pay_invoice(chart_id => $bank->id,
|
|
1200 |
amount => 89.25,
|
|
1201 |
currency => 'CUR',
|
|
1202 |
transdate => $transdate->to_kivitendo,
|
|
1203 |
);
|
|
1204 |
|
|
1205 |
};
|
|
1206 |
|
1001 |
1207 |
Support::TestSetup::login();
|
1002 |
1208 |
# die;
|
1003 |
1209 |
|
... | ... | |
1027 |
1233 |
test_default_invoice_four_items_19_7_tax_with_skonto_4x_25_tax_included();
|
1028 |
1234 |
test_default_invoice_two_items_19_7_tax_with_skonto_tax_included();
|
1029 |
1235 |
|
|
1236 |
# test payment of ar and ap transactions with currency and tax included/not included
|
|
1237 |
test_ar_currency_tax_not_included_and_payment();
|
|
1238 |
test_ar_currency_tax_included();
|
|
1239 |
test_ap_currency_tax_not_included_and_payment();
|
|
1240 |
test_ap_currency_tax_included();
|
|
1241 |
|
1030 |
1242 |
# remove all created data at end of test
|
1031 |
1243 |
clear_up();
|
1032 |
1244 |
|
Paymenthelper kann Fremdwährung mit Steuer inkl. und exkl.