Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 7d9823cd

Von Tamino Steinert vor 10 Monaten hinzugefügt

  • ID 7d9823cd990142fbe16ce84ab4648556989024d8
  • Vorgänger 3380b8ed
  • Nachfolger c13b0ae6

BJ:ImportRecordEmails: Status vom auto. ZUGFeRD-Import in erw. Status

Unterschiede anzeigen:

SL/DB/Helper/ZUGFeRD.pm
764 764

  
765 765
  # Try to fill in AP account to book against
766 766
  my $ap_chart_id = $::instance_conf->get_ap_chart_id;
767
  my $ap_chart = SL::DB::Manager::Chart->find_by(id => $ap_chart_id);
768

  
769
  unless ( defined $ap_chart ) {
767
  my $ap_chart;
768
  unless ( defined $ap_chart_id ) {
770 769
    # If no default account is configured, just use the first AP account found.
771
    my $ap_charts = SL::DB::Manager::Chart->get_all(
770
    ($ap_chart) = @{SL::DB::Manager::Chart->get_all(
772 771
      where   => [ link => 'AP' ],
773 772
      sort_by => [ 'accno' ],
774
    );
775
    $ap_chart = ${$ap_charts}[0];
773
    )};
774
  } else {
775
    $ap_chart = SL::DB::Manager::Chart->find_by(id => $ap_chart_id);
776 776
  }
777 777

  
778 778
  my $currency = SL::DB::Manager::Currency->find_by(
......
799 799
  my %template_params;
800 800
  my $template_ap = SL::DB::Manager::RecordTemplate->get_first(where => [vendor_id => $vendor->id]);
801 801
  if ($template_ap) {
802
    $template_params{globalproject_id}        = $template_ap->globalproject_id;
802
    $template_params{globalproject_id}        = $template_ap->project_id;
803 803
    $template_params{payment_id}              = $template_ap->payment_id;
804 804
    $template_params{department_id}           = $template_ap->department_id;
805 805
    $template_params{ordnumber}               = $template_ap->ordnumber;
......
813 813
    taxzone_id   => $vendor->taxzone_id,
814 814
    currency_id  => $currency->id,
815 815
    direct_debit => $metadata{'direct_debit'},
816
    invnumber   => $invnumber,
817
    transdate   => $metadata{transdate} || $today->to_kivitendo,
818
    duedate     => $metadata{duedate}   || $today->to_kivitendo,
819
    taxincluded => 0,
820
    intnotes    => $intnotes,
816
    invnumber    => $invnumber,
817
    transdate    => $metadata{transdate} || $today->to_kivitendo,
818
    duedate      => $metadata{duedate}   || $today->to_kivitendo,
819
    taxincluded  => 0,
820
    intnotes     => $intnotes,
821 821
    transactions => [],
822 822
    %template_params,
823 823
  );
......
825 825
  $self->assign_attributes(%params);
826 826

  
827 827
  # parse items
828
  my $template_item;
829
  if ($template_ap && scalar @{$template_ap->items}) {
830
    my $template_item = $template_ap->items->[0];
831
  }
828 832
  foreach my $i (@items) {
829 833
    my %item = %{$i};
830 834

  
831 835
    my $net_total = $item{'subtotal'};
832 836

  
833 837
    # set default values for items
834
    my ($tax, $chart, $project_id);
835
    if ($template_ap) {
836
      my $template_item = $template_ap->items->[0];
837
      $tax = SL::DB::Tax->new(id => $template_item->tax_id)->load();
838
      $chart = SL::DB::Chart->new(id => $template_item->chart_id)->load();
839
      $project_id = $template_item->project_id;
838
    my %line_params;
839
    $line_params{amount} = $net_total;
840
    if ($template_item) {
841
      $line_params{tax_id}     = $template_item->tax->id;
842
      $line_params{chart}      = $template_item->chart;
843
      $line_params{project_id} = $template_item->project_id;
840 844
    } else {
841

  
842
      my $tax_rate = $item{'tax_rate'};
843
      $tax_rate /= 100 if $tax_rate > 1; # XML data is usually in percent
844

  
845
      $tax   = first { $tax_rate              == $_->rate } @{ $taxes };
846
      $tax    //= first { $active_taxkey->tax_id == $_->id }   @{ $taxes };
847
      $tax    //= $taxes->[0];
848

  
849
      $chart = $default_ap_amount_chart;
845
      my $tax_rate  = $item{'tax_rate'};
846
         $tax_rate /= 100 if $tax_rate > 1; # XML data is usually in percent
847
      my $tax   = first { $tax_rate              == $_->rate } @{ $taxes };
848
         $tax //= first { $active_taxkey->tax_id == $_->id }   @{ $taxes };
849
         $tax //= $taxes->[0];
850
      $line_params{tax_id}  = $tax->id;
851
      $line_params{chart}   = $default_ap_amount_chart;
850 852
    }
851 853

  
852
    my %line_params = (
853
      amount => $net_total,
854
      tax_id => $tax->id,
855
      chart  => $chart,
856
    );
857

  
858 854
    $self->add_ap_amount_row(%line_params);
859 855
  }
860 856
  $self->recalculate_amounts();

Auch abrufbar als: Unified diff