Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision d3801bc9

Von Kivitendo Admin vor mehr als 10 Jahren hinzugefügt

  • ID d3801bc92648bd7284b543162299fa31a0a0eb77
  • Vorgänger 078c9769
  • Nachfolger a6fc1f81

Neue Methode orphaned für Buchungsgruppe

Zum Prüfen, ob eine Buchungsgruppe gelöscht oder bearbeitet werden kann.

Unterschiede anzeigen:

SL/Controller/Buchungsgruppen.pm
61 61
sub action_edit {
62 62
  my ($self) = @_;
63 63

  
64
  # Allow editing of Buchungsgruppe if it isn't assigned to any parts. The
65
  # variable is checked in the template, which toggles between L.select_tag and
66
  # text.
67

  
68
  my $number_of_parts_with_buchungsgruppe = SL::DB::Manager::Part->get_objects_count(where => [ buchungsgruppen_id => $self->config->id]);
64
  # Allow editing of the charts of the Buchungsgruppe if it isn't assigned to
65
  # any parts. This is checked inside the template via the Buchungsgruppen
66
  # orphaned method, where an IF-ELSE statement toggles between L.select_tag
67
  # and text.
69 68

  
70 69
  $self->show_form(title     => t8('Edit Buchungsgruppe'),
71
                   linked_parts  => $number_of_parts_with_buchungsgruppe,
72 70
                   CHARTLIST => SL::DB::TaxzoneChart->get_all_accounts_by_buchungsgruppen_id($self->config->id));
73 71
}
74 72

  
......
147 145

  
148 146
  $self->config->save;
149 147

  
150
  # check whether there are any assigned parts 
151
  my $number_of_parts_with_buchungsgruppe = SL::DB::Manager::Part->get_objects_count(where => [ buchungsgruppen_id => $self->config->id]);
152

  
153
  # Save or update taxzone_charts:
154
  if ($is_new or $number_of_parts_with_buchungsgruppe == 0) {
148
  # Save or update taxzone_charts for new or unused Buchungsgruppen
149
  if ($is_new or $self->config->orphaned) {
155 150
    my $taxzones = SL::DB::Manager::TaxZone->get_all_sorted();
156 151

  
157 152
    foreach my $tz (@{ $taxzones }) {
SL/DB/Buchungsgruppe.pm
72 72
  my ($self) = @_;
73 73
  return SL::DB::Manager::TaxzoneChart->get_all(where => [ buchungsgruppen_id => $self->id ]);
74 74
}
75
 
76
sub orphaned {
77
  my ($self) = @_;
78
  die 'not an accessor' if @_ > 1;
79

  
80
  require SL::DB::Part;
81
  return 0 if SL::DB::Manager::Part->get_all_count(query => [ buchungsgruppen_id => $self->id ]);
82
  return 1;
83
}
75 84

  
76 85
1;
77 86
__END__
......
111 120
account for the given taxzone (either the DB id or an instance of
112 121
L<SL::DB::TaxZone>).
113 122

  
123
=item C<orphaned>
124

  
125
Checks whether this Buchungsgruppe is assigned to any parts.
126

  
114 127
=back
115 128

  
116 129
=head1 BUGS
templates/webpages/buchungsgruppen/form.html
12 12
  </tr>
13 13
  <tr>
14 14
    <th align="right">[% 'Inventory account' | $T8 %]</th>
15
    [%- IF SELF.config.id AND linked_parts != 0 %]
15
    [%- IF SELF.config.id AND NOT SELF.config.orphaned %]
16 16
    <td>[%- CHARTLIST.inventory_accno %] -- [%- CHARTLIST.inventory_accno_description %]</td>
17
    [%- ELSIF NOT SELF.config.id AND linked_parts != 0 %]
17
    [%- ELSIF NOT SELF.config.id AND NOT SELF.config.orphaned %]
18 18
    <td>[%- L.select_tag("config.inventory_accno_id", ACCOUNTS.ic, title_sub=\account_label, default=SELF.defaults.inventory_accno_id) %]</td>
19 19
    [%- ELSE %]
20 20
    <td>[%- L.select_tag("config.inventory_accno_id", ACCOUNTS.ic, title_sub=\account_label, default=SELF.config.inventory_accno_id) %]</td>
......
23 23
[%- FOREACH tz = TAXZONES %]
24 24
  <tr>
25 25
    <th align="right">[% 'Revenue' | $T8 %] [% HTML.escape(tz.description) %]</th>
26
    [%- IF SELF.config.id AND linked_parts != 0 %]
26
    [%- IF SELF.config.id AND NOT SELF.config.orphaned %]
27 27
    <td>[% CHARTLIST.${tz.id}.income_accno %] -- [% CHARTLIST.${tz.id}.income_accno_description %]</td>
28
    [%- ELSIF NOT SELF.config.id AND linked_parts != 0 %]
28
    [%- ELSIF NOT SELF.config.id AND NOT SELF.config.orphaned %]
29 29
    <td>[%- L.select_tag('income_accno_id_' _ tz.id, ACCOUNTS.ic_income, title_sub=\account_label, default=SELF.defaults.income_accno_id) %]</td>
30 30
    [%- ELSE %]
31 31
    <td>[%- L.select_tag('income_accno_id_' _ tz.id, ACCOUNTS.ic_income, title_sub=\account_label, default=CHARTLIST.${tz.id}.income_accno_id) %]</td>
......
33 33
  </tr>
34 34
  <tr>
35 35
    <th align="right">[% 'Expense' | $T8 %] [% HTML.escape(tz.description) %]</th>
36
    [%- IF SELF.config.id AND linked_parts != 0 %]
36
    [%- IF SELF.config.id AND NOT SELF.config.orphaned %]
37 37
    <td>[% CHARTLIST.${tz.id}.expense_accno %] -- [% CHARTLIST.${tz.id}.expense_accno_description %]</td>
38
    [%- ELSIF NOT SELF.config.id AND linked_parts != 0 %]
38
    [%- ELSIF NOT SELF.config.id AND NOT SELF.config.orphaned %]
39 39
    <td>[%- L.select_tag('expense_accno_id_' _ tz.id, ACCOUNTS.ic_expense, title_sub=\account_label, default=SELF.defaults.expense_accno_id) %]</td>
40 40
    [%- ELSE %]
41 41
    <td>[%- L.select_tag('expense_accno_id_' _ tz.id, ACCOUNTS.ic_expense, title_sub=\account_label, default=CHARTLIST.${tz.id}.expense_accno_id) %]</td>
......
47 47
 <p>
48 48
  [% L.hidden_tag("action", "Buchungsgruppen/dispatch") %]
49 49
  [% L.submit_tag("action_" _  (SELF.config.id ? "update" : "create"), LxERP.t8('Save'), onclick="return check_prerequisites();") %]
50
  [%- IF SELF.config.id AND linked_parts == 0 %]
50
  [%- IF SELF.config.id AND SELF.config.orphaned %]
51 51
    [% L.submit_tag("action_delete", LxERP.t8('Delete'), confirm=LxERP.t8('Are you sure?')) %]
52 52
  [%- END %]
53 53
 </p>

Auch abrufbar als: Unified diff