+# clear_up();
+
+sub new_purchase_invoice {
+ # manually create a Kreditorenbuchung from scratch, ap + acc_trans bookings, as no helper exists yet, like $invoice->post.
+ # arap-Booking must come last in the acc_trans order
+ # this function was essentially copied from t/db_helper/payment.t, refactor once $purchase_invoice->post exists
+ my $currency_id = $::instance_conf->get_currency_id;
+ my $employee = SL::DB::Manager::Employee->current || die "No employee";
+ my $taxzone = SL::DB::Manager::TaxZone->find_by( description => 'Inland') || die "No taxzone";
+
+ my $purchase_invoice = SL::DB::PurchaseInvoice->new(
+ amount => '226',
+ currency_id => $currency_id,
+ employee_id => $employee->id,
+ gldate => $date,
+ invnumber => "ap1",
+ invoice => 0,
+ itime => $date,
+ mtime => $date,
+ netamount => '200',
+ paid => '0',
+ taxincluded => 0,
+ taxzone_id => $taxzone->id,
+ transdate => $date,
+ type => 'invoice',
+ vendor_id => $vendor->id,
+ )->save;
+
+ my $expense_chart = SL::DB::Manager::Chart->find_by(accno => '3400');
+ my $expense_chart_booking= SL::DB::AccTransaction->new(
+ amount => '-100',
+ chart_id => $expense_chart->id,
+ chart_link => $expense_chart->link,
+ itime => $date,
+ mtime => $date,
+ source => '',
+ tax_id => SL::DB::Manager::Tax->find_by(taxkey => 9)->id,
+ taxkey => 9,
+ transdate => $date,
+ trans_id => $purchase_invoice->id,
+ );
+ $expense_chart_booking->save;
+
+ my $tax_chart = SL::DB::Manager::Chart->find_by(accno => '1576');
+ my $tax_chart_booking= SL::DB::AccTransaction->new(
+ amount => '-19',
+ chart_id => $tax_chart->id,
+ chart_link => $tax_chart->link,
+ itime => $date,
+ mtime => $date,
+ source => '',
+ tax_id => SL::DB::Manager::Tax->find_by(taxkey => 9)->id,
+ taxkey => 0,
+ transdate => $date,
+ trans_id => $purchase_invoice->id,
+ );
+ $tax_chart_booking->save;
+ $expense_chart = SL::DB::Manager::Chart->find_by(accno => '3300');
+ $expense_chart_booking= SL::DB::AccTransaction->new(
+ amount => '-100',
+ chart_id => $expense_chart->id,
+ chart_link => $expense_chart->link,
+ itime => $date,
+ mtime => $date,
+ source => '',
+ tax_id => SL::DB::Manager::Tax->find_by(taxkey => 8)->id,
+ taxkey => 8,
+ transdate => $date,
+ trans_id => $purchase_invoice->id,
+ );
+ $expense_chart_booking->save;
+
+ $tax_chart = SL::DB::Manager::Chart->find_by(accno => '1571');
+ $tax_chart_booking= SL::DB::AccTransaction->new(
+ trans_id => $purchase_invoice->id,
+ chart_id => $tax_chart->id,
+ chart_link => $tax_chart->link,
+ amount => '-7',
+ transdate => $date,
+ itime => $date,
+ mtime => $date,
+ source => '',
+ taxkey => 0,
+ tax_id => SL::DB::Manager::Tax->find_by(taxkey => 8)->id,
+ );
+ $tax_chart_booking->save;
+ my $arap_chart = SL::DB::Manager::Chart->find_by(accno => '1600');
+ my $arap_booking= SL::DB::AccTransaction->new(
+ trans_id => $purchase_invoice->id,
+ chart_id => $arap_chart->id,
+ chart_link => $arap_chart->link,
+ amount => '226',
+ transdate => $date,
+ itime => $date,
+ mtime => $date,
+ source => '',
+ taxkey => 0,
+ tax_id => SL::DB::Manager::Tax->find_by(taxkey => 0)->id,
+ );
+ $arap_booking->save;
+
+ return $purchase_invoice;
+}