Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 2023adb0

Von Moritz Bunkus vor fast 8 Jahren hinzugefügt

  • ID 2023adb0a6dcb362cff74c4df75cc8beec56a002
  • Vorgänger 7e2bc8a0
  • Nachfolger cbdc5c37

Belegvorlagen: Laden bei Dialogbuchungen

Unterschiede anzeigen:

bin/mozilla/gl.pl
36 36
use strict;
37 37

  
38 38
use POSIX qw(strftime);
39
use List::Util qw(sum);
39
use List::Util qw(first sum);
40 40

  
41
use SL::DB::RecordTemplate;
42
use SL::DB::Tax;
41 43
use SL::FU;
42 44
use SL::GL;
45
use SL::Helper::Flash qw(flash);
43 46
use SL::IS;
44 47
use SL::ReportGenerator;
45 48
use SL::DBUtils qw(selectrow_query selectall_hashref_query);
......
77 80
# $locale->text('Nov')
78 81
# $locale->text('Dec')
79 82

  
83
sub load_record_template {
84
  $::auth->assert('gl_transactions');
85

  
86
  # Load existing template and verify that its one for this module.
87
  my $template = SL::DB::RecordTemplate
88
    ->new(id => $::form->{id})
89
    ->load(
90
      with_object => [ qw(customer payment currency record_items record_items.chart) ],
91
    );
92

  
93
  die "invalid template type" unless $template->template_type eq 'gl_transaction';
94

  
95
  $template->substitute_variables;
96

  
97
  # Clean the current $::form before rebuilding it from the template.
98
  delete @{ $::form }{ grep { !m{^(?:script|login)$}i } keys %{ $::form } };
99

  
100
  my $dummy_form = {};
101
  GL->transaction(\%::myconfig, $dummy_form);
102

  
103
  # Fill $::form from the template.
104
  my $today                   = DateTime->today_local;
105
  $::form->{title}            = "Add";
106
  $::form->{transdate}        = $today->to_kivitendo;
107
  $::form->{duedate}          = $today->to_kivitendo;
108
  $::form->{rowcount}         = @{ $template->items } + 1;
109
  $::form->{paidaccounts}     = 1;
110
  $::form->{$_}               = $template->$_     for qw(department_id taxincluded ob_transaction cb_transaction reference description);
111
  $::form->{$_}               = $dummy_form->{$_} for qw(closedto revtrans previous_id previous_gldate);
112

  
113
  my $row = 0;
114
  foreach my $item (@{ $template->items }) {
115
    $row++;
116

  
117
    my $active_taxkey = $item->chart->get_active_taxkey;
118
    my $taxes         = SL::DB::Manager::Tax->get_all(
119
      where   => [ chart_categories => { like => '%' . $item->chart->category . '%' }],
120
      sort_by => 'taxkey, rate',
121
    );
122

  
123
    my $tax   = first { $item->tax_id          == $_->id } @{ $taxes };
124
    $tax    //= first { $active_taxkey->tax_id == $_->id } @{ $taxes };
125
    $tax    //= $taxes->[0];
126

  
127
    if (!$tax) {
128
      $row--;
129
      next;
130
    }
131

  
132
    $::form->{"accno_id_${row}"}          = $item->chart_id;
133
    $::form->{"previous_accno_id_${row}"} = $item->chart_id;
134
    $::form->{"debit_${row}"}             = $::form->format_amount(\%::myconfig, $item->amount1, 2) if $item->amount1 * 1;
135
    $::form->{"credit_${row}"}            = $::form->format_amount(\%::myconfig, $item->amount2, 2) if $item->amount2 * 1;
136
    $::form->{"taxchart_${row}"}          = $item->tax_id . '--' . $tax->rate;
137
    $::form->{"${_}_${row}"}              = $item->$_ for qw(source memo project_id);
138
  }
139

  
140
  flash('info', $::locale->text("The record template '#1' has been loaded.", $template->template_name));
141

  
142
  update();
143
}
144

  
80 145
sub add {
81 146
  $main::lxdebug->enter_sub();
82 147

  

Auch abrufbar als: Unified diff