Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision aa014f11

Von Bernd Bleßmann vor etwa 11 Jahren hinzugefügt

  • ID aa014f1111f1244dcb9b8cb232240a00ff129e99
  • Vorgänger 7dd4a299
  • Nachfolger df141b69

Preisfaktoren und Preisgruppen behandeln.

Unterschiede anzeigen:

SL/Controller/CsvImport/Order.pm
12 12
use SL::DB::PaymentTerm;
13 13
use SL::DB::Contact;
14 14
use SL::DB::Department;
15
use SL::DB::PriceFactor;
16
use SL::DB::Pricegroup;
15 17
use SL::DB::Project;
16 18
use SL::DB::Shipto;
17 19
use SL::DB::TaxZone;
......
22 24

  
23 25
use Rose::Object::MakeMethods::Generic
24 26
(
25
 'scalar --get_set_init' => [ qw(settings languages_by parts_by contacts_by departments_by projects_by ct_shiptos_by taxzones_by) ],
27
 'scalar --get_set_init' => [ qw(settings languages_by parts_by contacts_by departments_by projects_by ct_shiptos_by taxzones_by price_factors_by pricegroups_by) ],
26 28
);
27 29

  
28 30

  
......
93 95
                                );
94 96

  
95 97
  $self->add_displayable_columns('OrderItem',
96
                                 { name => 'parts_id',      description => $::locale->text('Part (database ID)')    },
97
                                 { name => 'partnumber',    description => $::locale->text('Part Number')           },
98
                                 { name => 'project_id',    description => $::locale->text('Project (database ID)') },
99
                                 { name => 'projectnumber', description => $::locale->text('Project (number)')      },
100
                                 { name => 'project',       description => $::locale->text('Project (description)') },
98
                                 { name => 'parts_id',        description => $::locale->text('Part (database ID)')         },
99
                                 { name => 'partnumber',      description => $::locale->text('Part Number')                },
100
                                 { name => 'project_id',      description => $::locale->text('Project (database ID)')      },
101
                                 { name => 'projectnumber',   description => $::locale->text('Project (number)')           },
102
                                 { name => 'project',         description => $::locale->text('Project (description)')      },
103
                                 { name => 'price_factor_id', description => $::locale->text('Price factor (database ID)') },
104
                                 { name => 'price_factor',    description => $::locale->text('Price factor (name)')        },
105
                                 { name => 'pricegroup_id',   description => $::locale->text('Price group (database ID)')  },
106
                                 { name => 'pricegroup',      description => $::locale->text('Price group (name)')         },
101 107
                                );
102 108
}
103 109

  
......
162 168
  return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_taxzones } } ) } qw(id description) };
163 169
}
164 170

  
171
sub init_price_factors_by {
172
  my ($self) = @_;
173

  
174
  my $all_price_factors = SL::DB::Manager::PriceFactor->get_all;
175
  return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_price_factors } } ) } qw(id description) };
176
}
177

  
178
sub init_pricegroups_by {
179
  my ($self) = @_;
180

  
181
  my $all_pricegroups = SL::DB::Manager::Pricegroup->get_all;
182
  return { map { my $col = $_; ( $col => { map { ( $_->$col => $_ ) } @{ $all_pricegroups } } ) } qw(id pricegroup) };
183
}
184

  
165 185
sub check_objects {
166 186
  my ($self) = @_;
167 187

  
......
243 263
      $entry->{object}->ship(0)          unless $entry->{object}->ship;
244 264

  
245 265
      $self->check_project($entry, global => 0);
266
      $self->check_price_factor($entry);
267
      $self->check_pricegroup($entry);
268
      
246 269
    }
247 270
  }
248 271

  
......
250 273
                          { header => $::locale->text('Part Number'), method => 'partnumber' });
251 274
  # Todo: access via ->[1] ok? Better: search first item column and use this
252 275
  $self->add_columns($self->settings->{'item_column'},
253
                     map { "${_}_id" } grep { exists $self->controller->data->[1]->{raw_data}->{$_} } qw(project));
276
                     map { "${_}_id" } grep { exists $self->controller->data->[1]->{raw_data}->{$_} } qw(project price_factor pricegroup));
254 277
  $self->add_columns($self->settings->{'item_column'}, 'project_id') if exists $self->controller->data->[1]->{raw_data}->{projectnumber};
255 278

  
256 279
  # add orderitems to order
......
552 575
}
553 576

  
554 577

  
578
sub check_price_factor {
579
  my ($self, $entry) = @_;
580

  
581
  my $object = $entry->{object};
582

  
583
  # Check wether or not price_factor ID is valid.
584
  if ($object->price_factor_id && !$self->price_factors_by->{id}->{ $object->price_factor_id }) {
585
    push @{ $entry->{errors} }, $::locale->text('Error: Invalid price factor');
586
    return 0;
587
  }
588

  
589
  # Map description to ID if given.
590
  if (!$object->price_factor_id && $entry->{raw_data}->{price_factor}) {
591
    my $price_factor = $self->price_factors_by->{description}->{ $entry->{raw_data}->{price_factor} };
592
    if (!$price_factor) {
593
      push @{ $entry->{errors} }, $::locale->text('Error: Invalid price factor');
594
      return 0;
595
    }
596

  
597
    $object->price_factor_id($price_factor->id);
598
  }
599

  
600
  return 1;
601
}
602

  
603
sub check_pricegroup {
604
  my ($self, $entry) = @_;
605

  
606
  my $object = $entry->{object};
607

  
608
  # Check wether or not pricegroup ID is valid.
609
  if ($object->pricegroup_id && !$self->pricegroups_by->{id}->{ $object->pricegroup_id }) {
610
    push @{ $entry->{errors} }, $::locale->text('Error: Invalid price group');
611
    return 0;
612
  }
613

  
614
  # Map pricegroup to ID if given.
615
  if (!$object->pricegroup_id && $entry->{raw_data}->{pricegroup}) {
616
    my $pricegroup = $self->pricegroups_by->{pricegroup}->{ $entry->{raw_data}->{pricegroup} };
617
    if (!$pricegroup) {
618
      push @{ $entry->{errors} }, $::locale->text('Error: Invalid price group');
619
      return 0;
620
    }
621

  
622
    $object->pricegroup_id($pricegroup->id);
623
  }
624

  
625
  return 1;
626
}
627

  
628

  
555 629
sub save_objects {
556 630
  my ($self, %params) = @_;
557 631

  

Auch abrufbar als: Unified diff