1 use Test::More tests => 41;
8 use Support::TestSetup;
12 use Support::TestSetup;
15 use SL::DB::Buchungsgruppe;
21 use SL::DB::DeliveryOrder;
27 my ($customer, $employee, $payment_do, $unit, @parts, $department);
29 my $VISUAL_TEST = 0; # just a sleep to click around
32 foreach (qw(DeliveryOrderItem DeliveryOrder InvoiceItem Invoice Part Customer Department PaymentTerm)) {
33 "SL::DB::Manager::${_}"->delete_all(all => 1);
35 SL::DB::Manager::Employee->delete_all(where => [ login => 'testuser' ]);
43 $unit = SL::DB::Manager::Unit->find_by(name => 'kg') || die "Can't find unit 'kg'";
44 $customer = SL::Dev::CustomerVendor::create_customer->save;
46 $employee = SL::DB::Employee->new(
47 'login' => 'testuser',
48 'name' => 'Test User',
51 $department = SL::DB::Department->new(
52 'description' => 'Test Department',
55 $payment_do = SL::Dev::Payment::create_payment_terms(
56 'description' => '14Tage 2%Skonto, 30Tage netto',
57 'description_long' => "Innerhalb von 14 Tagen abzüglich 2 % Skonto, innerhalb von 30 Tagen rein netto.|Bei einer Zahlung bis zum <%skonto_date%> gewähren wir 2 % Skonto (EUR <%skonto_amount%>) entspricht EUR <%total_wo_skonto%>.Bei einer Zahlung bis zum <%netto_date%> ist der fällige Betrag in Höhe von <%total%> <%currency%> zu überweisen.",
58 'percent_skonto' => '0.02',
65 push @parts, SL::Dev::Part::create_part(
66 description => "description 1",
67 lastcost => '49.95000',
68 listprice => '0.00000',
69 partnumber => 'v-519160549',
70 sellprice => '242.20000',
75 push @parts, SL::Dev::Part::create_part(
76 description => "description 2",
77 lastcost => '153.00000',
78 listprice => '0.00000',
79 partnumber => 'v-120160086',
80 sellprice => '344.30000',
87 Support::TestSetup::login();
91 # we create L20199 with two items
92 my $do1 = SL::Dev::Record::create_sales_delivery_order(
93 'department_id' => $department->id,
94 'donumber' => 'L20199',
95 'employee_id' => $employee->id,
96 'intnotes' => 'some intnotes',
97 'ordnumber' => 'A16399',
98 'payment_id' => $payment_do->id,
99 'salesman_id' => $employee->id,
100 'shippingpoint' => 'sendtome',
101 'shipvia' => 'DHL, Versand am 06.03.2015, 1 Paket 17,00 kg',
102 'cusordnumber' => 'b84da',
103 'customer_id' => $customer->id,
104 'notes' => '<ul><li><strong>fett</strong></li><li><strong>und</strong></li><li><strong>mit</strong></li><li><strong>bullets</strong></li><li> </li></ul>',
106 SL::Dev::Record::create_delivery_order_item(
109 lastcost => '49.95000',
110 longdescription => "<ol><li>27</li><li>28</li><li>29</li><li><sub>asdf</sub></li><li><sub>asdf</sub></li><li><sup>oben</sup></li></ol><p><s>kommt nicht mehr vor</s></p>",
111 marge_price_factor => 1,
113 sellprice => '242.20000',
116 SL::Dev::Record::create_delivery_order_item(
119 lastcost => '153.00000',
121 sellprice => '344.30000',
122 transdate => '06.03.2015',
131 my $do1_item1 = $do1->orderitems->[0];
132 my $do1_item2 = $do1->orderitems->[1];
134 # test delivery order before any conversion
135 ok($do1->donumber eq "L20199", 'Delivery Order Number created');
136 ok($do1->notes eq '<ul><li><strong>fett</strong></li><li><strong>und</strong></li><li><strong>mit</strong></li><li><strong>bullets</strong></li><li> </li></ul>', "do RichText notes saved");
137 ok((not $do1->closed) , 'Delivery Order is not closed');
138 is($do1_item1->parts_id, $parts[0]->id, 'doi linked with part');
139 ok($do1_item1->qty == 2, 'qty check doi');
140 ok($do1_item1->longdescription eq "<ol><li>27</li><li>28</li><li>29</li><li><sub>asdf</sub></li><li><sub>asdf</sub></li><li><sup>oben</sup></li></ol><p><s>kommt nicht mehr vor</s></p>",
141 "do item1 rich text longdescripition");
142 ok ($do1_item2->position == 2, 'doi2 position check');
143 is (SL::DB::Manager::DeliveryOrderItem->get_all_count(where => [ delivery_order_id => $do1->id ]), 2 , 'two doi linked');
146 # convert this do to invoice
147 my $invoice = $do1->convert_to_invoice();
149 sleep (300) if $VISUAL_TEST; # we can do a real visual test via gui login
150 # test invoice afterwards
152 ok ($invoice->shipvia eq "DHL, Versand am 06.03.2015, 1 Paket 17,00 kg", "ship via check");
153 ok ($invoice->shippingpoint eq "sendtome", "shipping point check");
154 ok ($invoice->ordnumber eq "A16399", "ordnumber check");
155 ok ($invoice->donumber eq "L20199", "donumber check");
156 ok ($invoice->notes eq '<ul><li><strong>fett</strong></li><li><strong>und</strong></li><li><strong>mit</strong></li><li><strong>bullets</strong></li><li> </li></ul>', "do RichText notes saved");
157 ok(($do1->closed) , 'Delivery Order is closed after conversion');
158 is($invoice->payment_terms->description, "14Tage 2%Skonto, 30Tage netto", 'payment term description check');
160 # some test data from original client invoice console (!)
161 # my $invoice3 = SL::DB::Manager::Invoice->find_by( ordnumber => 'A16399' );
162 # which will fail due to PTC Calculation differs from GUI-Calculation, see issue: http://redmine.kivitendo-premium.de/issues/82
164 # values from gui should be:
165 #ok($invoice->amount == 1354.20000, 'amount check');
166 #ok($invoice->marge_percent == 50.88666, 'marge percent check');
167 #ok($invoice->marge_total == 579.08000, 'marge total check');
168 #ok($invoice->netamount == 1137.98000, 'netamount check');
171 # the values change if one reloads the object
172 # without reloading we get this failures
173 #not ok 17 - amount check
174 # Failed test 'amount check'
175 # at t/db_helper/convert_invoice.t line 272.
177 # expected: '1354.17000'
178 #not ok 18 - marge percent check
179 # Failed test 'marge percent check'
180 # at t/db_helper/convert_invoice.t line 273.
181 # got: '50.8857956342929'
182 # expected: '50.88580'
183 #not ok 19 - marge total check
184 # Failed test 'marge total check'
185 # at t/db_helper/convert_invoice.t line 274.
187 # expected: '579.06000'
188 #not ok 20 - netamount check
189 # Failed test 'netamount check'
190 # at t/db_helper/convert_invoice.t line 275.
192 # expected: '1137.96000'
196 is($invoice->cusordnumber , 'b84da' , 'cusordnumber check');
197 is($invoice->department->description , "Test Department" , 'department description ok');
198 is($invoice->amount , '1354.17000' , 'amount check');
199 is($invoice->marge_percent , '50.88580' , 'marge percent check');
200 is($invoice->marge_total , '579.06000' , 'marge total check');
201 is($invoice->netamount , '1137.96000' , 'netamount check');
204 is($invoice->items_sorted->[0]->parts_id , $parts[0]->id , 'invoiceitem 1 linked with part');
205 is(scalar @{ $invoice->invoiceitems } , 2 , 'two invoice items linked with invoice');
206 is($invoice->items_sorted->[0]->position , 1 , "position 1 order correct");
207 is($invoice->items_sorted->[1]->position , 2 , "position 2 order correct");
208 is($invoice->items_sorted->[0]->part->partnumber , 'v-519160549' , "partnumber 1 correct");
209 is($invoice->items_sorted->[1]->part->partnumber , 'v-120160086' , "partnumber 2 correct");
210 is($invoice->items_sorted->[0]->qty , '2.00000' , "pos 1 qty");
211 is($invoice->items_sorted->[1]->qty , '3.00000' , "pos 2 qty");
212 is($invoice->items_sorted->[0]->discount , 0.25 , "pos 1 discount");
213 is($invoice->items_sorted->[1]->discount , 0.25 , "pos 2 discount");
214 is($invoice->items_sorted->[0]->longdescription , "<ol><li>27</li><li>28</li><li>29</li><li><sub>asdf</sub></li><li><sub>asdf</sub></li><li><sup>oben</sup></li></ol><p><s>kommt nicht mehr vor</s></p>",
215 "invoice item1 rich text longdescripition");
216 # more ideas: check onhand, lastcost (parsed lastcost)
220 # check linked records AND linked items
222 # we expect something like this in record links:
223 # delivery_order_items | 144736 | invoice | 9 | 2015-09-02 16:29:32.362562 | 5
224 # delivery_order_items | 144737 | invoice | 10 | 2015-09-02 16:29:32.362562 | 6
225 # delivery_orders | 464003 | ar | 5 | 2015-09-02 16:29:32.362562 | 7
227 # verkn�pfter beleg$VAR1 = {
228 # 'from_id' => 464003,
229 # 'from_table' => 'delivery_orders',
233 # verkn�pfte positionen$VAR1 = {
234 # 'from_id' => 144737,
235 # 'from_table' => 'delivery_order_items',
237 # 'to_table' => 'invoice'
240 # 'from_id' => 144736,
241 # 'from_table' => 'delivery_order_items',
243 # 'to_table' => 'invoice'
247 my @links_record = RecordLinks->get_links('from_table' => 'delivery_orders',
249 'from_id' => $do1->id,
252 is($links_record[0]->{from_id} , $do1->id , "record from id check");
253 is($links_record[0]->{from_table} , 'delivery_orders' , "record from table check");
254 is($links_record[0]->{to_table} , 'ar' , "record to table check");
256 foreach ( $do1_item1->id, $do1_item2->id ) {
257 my @links_record_item1 = RecordLinks->get_links('from_table' => 'delivery_order_items',
258 'to_table' => 'invoice',
262 is($links_record_item1[0]->{from_id} , $_ , "record from id check $_");
263 is($links_record_item1[0]->{from_table} , 'delivery_order_items' , "record from table check $_");
264 is($links_record_item1[0]->{to_table} , 'invoice' , "record to table check $_");