5 use Support::TestSetup;
14 use SL::Controller::Project;
19 Support::TestSetup::login();
23 my $vendor = SL::Dev::CustomerVendor::create_vendor->save;
24 my $customer = SL::Dev::CustomerVendor::create_customer->save;
25 my $project = SL::Dev::Record::create_project(projectnumber => 'p1', description => 'Project 1')->save;
27 my $part1 = SL::Dev::Part::create_part( partnumber => 'T4254')->save;
28 my $part2 = SL::Dev::Part::create_service(partnumber => 'Serv1')->save;
30 # sales order with globalproject_id and item project_ids
31 my $sales_order = SL::Dev::Record::create_sales_order(
33 customer => $customer,
34 globalproject_id => $project->id,
36 orderitems => [ SL::Dev::Record::create_order_item(part => $part1, qty => 3, sellprice => 70, project_id => $project->id),
37 SL::Dev::Record::create_order_item(part => $part2, qty => 10, sellprice => 50, project_id => $project->id),
41 # sales order with no globalproject_id but item project_ids
42 my $sales_order2 = SL::Dev::Record::create_sales_order(
44 customer => $customer,
46 orderitems => [ SL::Dev::Record::create_order_item(part => $part1, qty => 3, sellprice => 70, project_id => $project->id),
47 SL::Dev::Record::create_order_item(part => $part2, qty => 10, sellprice => 50),
51 # purchase order with globalproject_id and item project_ids
52 my $purchase_order = SL::Dev::Record::create_purchase_order(
55 globalproject_id => $project->id,
57 orderitems => [ SL::Dev::Record::create_order_item(part => $part1, qty => 3, sellprice => 70, project_id => $project->id),
58 SL::Dev::Record::create_order_item(part => $part2, qty => 10, sellprice => 50, project_id => $project->id),
62 # sales_invoice with globalproject_id, and all items with project_id
63 my $sales_invoice = SL::Dev::Record::create_sales_invoice(
64 customer => $customer,
65 globalproject_id => $project->id,
67 invoiceitems => [ SL::Dev::Record::create_invoice_item(part => $part1, qty => 3, sellprice => 70, project_id => $project->id),
68 SL::Dev::Record::create_invoice_item(part => $part2, qty => 10, sellprice => 50, project_id => $project->id),
72 # sales_invoice with globalproject_id, but none of the items has a project_id
73 my $sales_invoice2 = SL::Dev::Record::create_sales_invoice(
74 customer => $customer,
75 globalproject_id => $project->id,
77 invoiceitems => [ SL::Dev::Record::create_invoice_item(part => $part1, qty => 3, sellprice => 70),
78 SL::Dev::Record::create_invoice_item(part => $part2, qty => 10, sellprice => 50),
82 # one of the invoice items has the project id, but there is no globalproject_id
83 my $sales_invoice4 = SL::Dev::Record::create_sales_invoice(
84 customer => $customer,
86 invoiceitems => [ SL::Dev::Record::create_invoice_item(part => $part1, qty => 3, sellprice => 70),
87 SL::Dev::Record::create_invoice_item(part => $part2, qty => 10, sellprice => 50, project_id => $project->id),
91 my $today = DateTime->today;
92 my $expense_chart_porto = SL::DB::Manager::Chart->find_by(description => 'Porto');
93 my $income_chart = SL::DB::Manager::Chart->find_by(accno => 8400);
94 my $tax_9 = SL::DB::Manager::Tax->find_by(taxkey => 9, rate => 0.19) || die "No tax";
95 my $tax_3 = SL::DB::Manager::Tax->find_by(taxkey => 3, rate => 0.19) || die "No tax";
97 # create an ar_transaction manually, with globalproject_id and acc_trans project_ids
98 my $ar_transaction = SL::DB::Invoice->new(
100 invnumber => 'test ar_transaction globalproject_id',
105 customer_id => $customer->id,
106 taxzone_id => $customer->taxzone_id,
107 currency_id => $::instance_conf->get_currency_id,
109 notes => 'test ar_transaction globalproject_id',
110 globalproject_id => $project->id,
112 $ar_transaction->add_ar_amount_row(
113 amount => $ar_transaction->netamount,
114 chart => $income_chart,
115 tax_id => $tax_3->id,
116 project_id => $project->id,
118 my $ar_chart = SL::DB::Manager::Chart->find_by( accno => '1400' ); # Forderungen
119 $ar_transaction->create_ar_row(chart => $ar_chart);
120 $ar_transaction->save;
122 # create an ap_transaction manually, with globalproject_id and acc_trans project_ids
123 my $ap_transaction = SL::DB::PurchaseInvoice->new(
125 invnumber => 'test ap_transaction globalproject_id',
130 vendor_id => $vendor->id,
131 taxzone_id => $vendor->taxzone_id,
132 currency_id => $::instance_conf->get_currency_id,
134 notes => 'test ap_transaction globalproject_id',
135 globalproject_id => $project->id,
137 $ap_transaction->add_ap_amount_row(
138 amount => $ap_transaction->netamount,
139 chart => $expense_chart_porto,
140 tax_id => $tax_9->id,
141 project_id => $project->id,
143 my $ap_chart = SL::DB::Manager::Chart->find_by( accno => '1600' ); # Verbindlichkeiten
144 $ap_transaction->create_ap_row(chart => $ap_chart);
145 $ap_transaction->save;
147 # create an ap_transaction manually, with no globalproject_id but acc_trans project_ids
148 my $ap_transaction2 = SL::DB::PurchaseInvoice->new(
150 invnumber => 'test ap_transaction no globalproject_id',
155 vendor_id => $vendor->id,
156 taxzone_id => $vendor->taxzone_id,
157 currency_id => $::instance_conf->get_currency_id,
159 notes => 'test ap_transaction no globalproject_id',
161 $ap_transaction2->add_ap_amount_row(
162 amount => $ap_transaction2->netamount,
163 chart => $expense_chart_porto,
164 tax_id => $tax_9->id,
165 project_id => $project->id,
167 $ap_chart = SL::DB::Manager::Chart->find_by( accno => '1600' ); # Verbindlichkeiten
168 $ap_transaction2->create_ap_row(chart => $ap_chart);
169 $ap_transaction2->save;
171 my $expense_chart = SL::DB::Manager::Chart->find_by(accno => '4660'); # Reisekosten
172 my $cash_chart = SL::DB::Manager::Chart->find_by(accno => '1000'); # Kasse
173 my $tax_chart = SL::DB::Manager::Chart->find_by(accno => '1576'); # Vorsteuer
176 push(@acc_trans, SL::DB::AccTransaction->new(
177 chart_id => $expense_chart->id,
178 chart_link => $expense_chart->link,
183 tax_id => $tax_9->id,
184 project_id => $project->id,
186 push(@acc_trans, SL::DB::AccTransaction->new(
187 chart_id => $tax_chart->id,
188 chart_link => $tax_chart->link,
193 tax_id => $tax_9->id,
194 project_id => $project->id,
196 push(@acc_trans, SL::DB::AccTransaction->new(
197 chart_id => $cash_chart->id,
198 chart_link => $cash_chart->link,
206 my $gl_transaction = SL::DB::GLTransaction->new(
207 reference => "reise",
208 description => "reise",
211 employee_id => SL::DB::Manager::Employee->current->id,
218 transactions => \@acc_trans,
221 my $controller = SL::Controller::Project->new;
222 $::form->{id} = $project->id;
223 $controller->load_project;
224 is( scalar @{$controller->linked_records}, 10, "found all records that have a link to the project");
231 foreach (qw(OrderItem Order InvoiceItem Invoice PurchaseInvoice Part GLTransaction AccTransaction PurchaseInvoice Project Vendor Customer)) {
232 "SL::DB::Manager::${_}"->delete_all(all => 1);