1 use Test::More tests => 41;
8 use Support::TestSetup;
12 use Support::TestSetup;
15 use SL::DB::Buchungsgruppe;
21 use SL::DB::DeliveryOrder;
25 use SL::Dev::ALL qw(:ALL);
27 my ($customer, $employee, $payment_do, $unit, @parts, $department);
30 my $VISUAL_TEST = 0; # just a sleep to click around
33 foreach (qw(DeliveryOrderItem DeliveryOrder InvoiceItem Invoice Part Customer Department PaymentTerm)) {
34 "SL::DB::Manager::${_}"->delete_all(all => 1);
36 SL::DB::Manager::Employee->delete_all(where => [ login => 'testuser' ]);
44 $transdate = DateTime->today_local;
45 $transdate->set_year(2019) if $transdate->year == 2020; # use year 2019 in 2020, because of tax rate change in Germany
47 $unit = SL::DB::Manager::Unit->find_by(name => 'kg') || die "Can't find unit 'kg'";
48 $customer = new_customer()->save;
50 $employee = SL::DB::Employee->new(
51 'login' => 'testuser',
52 'name' => 'Test User',
55 $department = SL::DB::Department->new(
56 'description' => 'Test Department',
59 $payment_do = create_payment_terms(
60 'description' => '14Tage 2%Skonto, 30Tage netto',
61 '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.",
62 'percent_skonto' => '0.02',
69 push @parts, new_part(
70 description => "description 1",
71 lastcost => '49.95000',
72 listprice => '0.00000',
73 partnumber => 'v-519160549',
74 sellprice => '242.20000',
79 push @parts, new_part(
80 description => "description 2",
81 lastcost => '153.00000',
82 listprice => '0.00000',
83 partnumber => 'v-120160086',
84 sellprice => '344.30000',
91 Support::TestSetup::login();
95 # we create L20199 with two items
96 my $do1 = create_sales_delivery_order(
97 'department_id' => $department->id,
98 'transdate' => $transdate,
99 'donumber' => 'L20199',
100 'employee_id' => $employee->id,
101 'intnotes' => 'some intnotes',
102 'ordnumber' => 'A16399',
103 'payment_id' => $payment_do->id,
104 'salesman_id' => $employee->id,
105 'shippingpoint' => 'sendtome',
106 'shipvia' => 'DHL, Versand am 06.03.2015, 1 Paket 17,00 kg',
107 'cusordnumber' => 'b84da',
108 'customer_id' => $customer->id,
109 '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>',
111 create_delivery_order_item(
114 lastcost => '49.95000',
115 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>",
116 marge_price_factor => 1,
118 sellprice => '242.20000',
121 create_delivery_order_item(
124 lastcost => '153.00000',
126 sellprice => '344.30000',
127 transdate => '06.03.2015',
136 my $do1_item1 = $do1->orderitems->[0];
137 my $do1_item2 = $do1->orderitems->[1];
139 # test delivery order before any conversion
140 ok($do1->donumber eq "L20199", 'Delivery Order Number created');
141 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");
142 ok((not $do1->closed) , 'Delivery Order is not closed');
143 is($do1_item1->parts_id, $parts[0]->id, 'doi linked with part');
144 ok($do1_item1->qty == 2, 'qty check doi');
145 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>",
146 "do item1 rich text longdescripition");
147 ok ($do1_item2->position == 2, 'doi2 position check');
148 is (SL::DB::Manager::DeliveryOrderItem->get_all_count(where => [ delivery_order_id => $do1->id ]), 2 , 'two doi linked');
151 # convert this do to invoice
152 my $invoice = $do1->convert_to_invoice(transdate => $transdate);
154 sleep (300) if $VISUAL_TEST; # we can do a real visual test via gui login
155 # test invoice afterwards
157 ok ($invoice->shipvia eq "DHL, Versand am 06.03.2015, 1 Paket 17,00 kg", "ship via check");
158 ok ($invoice->shippingpoint eq "sendtome", "shipping point check");
159 ok ($invoice->ordnumber eq "A16399", "ordnumber check");
160 ok ($invoice->donumber eq "L20199", "donumber check");
161 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");
162 ok(($do1->closed) , 'Delivery Order is closed after conversion');
163 is($invoice->payment_terms->description, "14Tage 2%Skonto, 30Tage netto", 'payment term description check');
167 is($invoice->cusordnumber , 'b84da' , 'cusordnumber check');
168 is($invoice->department->description , "Test Department" , 'department description ok');
169 is($invoice->amount , '1354.20000' , 'amount check');
170 is($invoice->marge_percent , '50.88666' , 'marge percent check');
171 is($invoice->marge_total , '579.08000' , 'marge total check');
172 is($invoice->netamount , '1137.98000' , 'netamount check');
175 is($invoice->items_sorted->[0]->parts_id , $parts[0]->id , 'invoiceitem 1 linked with part');
176 is(scalar @{ $invoice->invoiceitems } , 2 , 'two invoice items linked with invoice');
177 is($invoice->items_sorted->[0]->position , 1 , "position 1 order correct");
178 is($invoice->items_sorted->[1]->position , 2 , "position 2 order correct");
179 is($invoice->items_sorted->[0]->part->partnumber , 'v-519160549' , "partnumber 1 correct");
180 is($invoice->items_sorted->[1]->part->partnumber , 'v-120160086' , "partnumber 2 correct");
181 is($invoice->items_sorted->[0]->qty , '2.00000' , "pos 1 qty");
182 is($invoice->items_sorted->[1]->qty , '3.00000' , "pos 2 qty");
183 is($invoice->items_sorted->[0]->discount , 0.25 , "pos 1 discount");
184 is($invoice->items_sorted->[1]->discount , 0.25 , "pos 2 discount");
185 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>",
186 "invoice item1 rich text longdescripition");
187 # more ideas: check onhand, lastcost (parsed lastcost)
191 # check linked records AND linked items
193 # we expect something like this in record links:
194 # delivery_order_items | 144736 | invoice | 9 | 2015-09-02 16:29:32.362562 | 5
195 # delivery_order_items | 144737 | invoice | 10 | 2015-09-02 16:29:32.362562 | 6
196 # delivery_orders | 464003 | ar | 5 | 2015-09-02 16:29:32.362562 | 7
198 # verkn�pfter beleg$VAR1 = {
199 # 'from_id' => 464003,
200 # 'from_table' => 'delivery_orders',
204 # verkn�pfte positionen$VAR1 = {
205 # 'from_id' => 144737,
206 # 'from_table' => 'delivery_order_items',
208 # 'to_table' => 'invoice'
211 # 'from_id' => 144736,
212 # 'from_table' => 'delivery_order_items',
214 # 'to_table' => 'invoice'
218 my @links_record = RecordLinks->get_links('from_table' => 'delivery_orders',
220 'from_id' => $do1->id,
223 is($links_record[0]->{from_id} , $do1->id , "record from id check");
224 is($links_record[0]->{from_table} , 'delivery_orders' , "record from table check");
225 is($links_record[0]->{to_table} , 'ar' , "record to table check");
227 foreach ( $do1_item1->id, $do1_item2->id ) {
228 my @links_record_item1 = RecordLinks->get_links('from_table' => 'delivery_order_items',
229 'to_table' => 'invoice',
233 is($links_record_item1[0]->{from_id} , $_ , "record from id check $_");
234 is($links_record_item1[0]->{from_table} , 'delivery_order_items' , "record from table check $_");
235 is($links_record_item1[0]->{to_table} , 'invoice' , "record to table check $_");
243 # set emacs to perl mode