1 package SL::Controller::Pricegroup;
5 use parent qw(SL::Controller::Base);
8 use SL::Locale::String;
10 use SL::DB::Manager::Pricegroup;
12 use Rose::Object::MakeMethods::Generic (
13 scalar => [ qw(pricegroup) ],
14 'scalar --get_set_init' => [ qw(all_pricegroups) ],
17 __PACKAGE__->run_before('check_auth');
18 __PACKAGE__->run_before('load_pricegroup', only => [ qw(edit update delete) ]);
27 $self->render('pricegroup/list',
28 title => t8('Pricegroups'),
35 $self->pricegroup( SL::DB::Pricegroup->new );
36 $self->render('pricegroup/form',
37 title => t8('Add pricegroup'),
44 $self->render('pricegroup/form',
45 title => t8('Edit pricegroup'),
52 $self->pricegroup( SL::DB::Pricegroup->new );
53 $self->create_or_update;
58 $self->create_or_update;
64 if ( !$self->pricegroup->orphaned ) {
65 flash_later('error', $::locale->text('The pricegroup has been used and cannot be deleted.'));
66 } elsif ( eval { $self->pricegroup->delete; 1; } ) {
67 flash_later('info', $::locale->text('The pricegroup has been deleted.'));
69 flash_later('error', $::locale->text('The pricegroup has been used and cannot be deleted.'));
71 $self->redirect_to(action => 'list');
77 SL::DB::Pricegroup->reorder_list(@{ $::form->{pricegroup_id} || [] });
78 $self->render(\'', { type => 'json' });
86 $::auth->assert('config');
92 $self->pricegroup( SL::DB::Pricegroup->new(id => $::form->{id})->load );
95 sub init_all_pricegroups { SL::DB::Manager::Pricegroup->get_all_sorted }
101 sub create_or_update {
103 my $is_new = !$self->pricegroup->id;
105 my $params = delete($::form->{pricegroup}) || { };
107 $self->pricegroup->assign_attributes(%{ $params });
109 my @errors = $self->pricegroup->validate;
112 flash('error', @errors);
113 $self->render('pricegroup/form',
114 title => $is_new ? t8('Add pricegroup') : t8('Edit pricegroup'),
119 $self->pricegroup->save;
121 flash_later('info', $is_new ? t8('The pricegroup has been created.') : t8('The pricegroup has been saved.'));
122 $self->redirect_to(action => 'list');
133 SL::Controller::Pricegroup - CRUD controller for pricegroups
137 A new controller to create / edit / delete pricegroups.
139 Pricegroups can only be deleted if they haven't been used anywhere.
141 =head1 OBSOLETE PRICEGROUPS
143 Pricegroups can't be obsoleted while any of the customers still use that
144 pricegroup as their default pricegroup. Obsoleting a pricegroup means it can't
145 be selected when editing customers and it can't be selected as a price source
150 G. Richardson E<lt>grichardson@kivitendo-premium.deE<gt>