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);
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 = new_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 = 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, new_part(
66 description => "description 1",
67 lastcost => '49.95000',
68 listprice => '0.00000',
69 partnumber => 'v-519160549',
70 sellprice => '242.20000',
75 push @parts, new_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 = 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 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 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');
162 is($invoice->cusordnumber , 'b84da' , 'cusordnumber check');
163 is($invoice->department->description , "Test Department" , 'department description ok');
164 is($invoice->amount , '1354.20000' , 'amount check');
165 is($invoice->marge_percent , '50.88666' , 'marge percent check');
166 is($invoice->marge_total , '579.08000' , 'marge total check');
167 is($invoice->netamount , '1137.98000' , 'netamount check');
170 is($invoice->items_sorted->[0]->parts_id , $parts[0]->id , 'invoiceitem 1 linked with part');
171 is(scalar @{ $invoice->invoiceitems } , 2 , 'two invoice items linked with invoice');
172 is($invoice->items_sorted->[0]->position , 1 , "position 1 order correct");
173 is($invoice->items_sorted->[1]->position , 2 , "position 2 order correct");
174 is($invoice->items_sorted->[0]->part->partnumber , 'v-519160549' , "partnumber 1 correct");
175 is($invoice->items_sorted->[1]->part->partnumber , 'v-120160086' , "partnumber 2 correct");
176 is($invoice->items_sorted->[0]->qty , '2.00000' , "pos 1 qty");
177 is($invoice->items_sorted->[1]->qty , '3.00000' , "pos 2 qty");
178 is($invoice->items_sorted->[0]->discount , 0.25 , "pos 1 discount");
179 is($invoice->items_sorted->[1]->discount , 0.25 , "pos 2 discount");
180 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>",
181 "invoice item1 rich text longdescripition");
182 # more ideas: check onhand, lastcost (parsed lastcost)
186 # check linked records AND linked items
188 # we expect something like this in record links:
189 # delivery_order_items | 144736 | invoice | 9 | 2015-09-02 16:29:32.362562 | 5
190 # delivery_order_items | 144737 | invoice | 10 | 2015-09-02 16:29:32.362562 | 6
191 # delivery_orders | 464003 | ar | 5 | 2015-09-02 16:29:32.362562 | 7
193 # verkn�pfter beleg$VAR1 = {
194 # 'from_id' => 464003,
195 # 'from_table' => 'delivery_orders',
199 # verkn�pfte positionen$VAR1 = {
200 # 'from_id' => 144737,
201 # 'from_table' => 'delivery_order_items',
203 # 'to_table' => 'invoice'
206 # 'from_id' => 144736,
207 # 'from_table' => 'delivery_order_items',
209 # 'to_table' => 'invoice'
213 my @links_record = RecordLinks->get_links('from_table' => 'delivery_orders',
215 'from_id' => $do1->id,
218 is($links_record[0]->{from_id} , $do1->id , "record from id check");
219 is($links_record[0]->{from_table} , 'delivery_orders' , "record from table check");
220 is($links_record[0]->{to_table} , 'ar' , "record to table check");
222 foreach ( $do1_item1->id, $do1_item2->id ) {
223 my @links_record_item1 = RecordLinks->get_links('from_table' => 'delivery_order_items',
224 'to_table' => 'invoice',
228 is($links_record_item1[0]->{from_id} , $_ , "record from id check $_");
229 is($links_record_item1[0]->{from_table} , 'delivery_order_items' , "record from table check $_");
230 is($links_record_item1[0]->{to_table} , 'invoice' , "record to table check $_");
239 # set emacs to perl mode