1 package SL::Controller::Shop;
 
   5 use parent qw(SL::Controller::Base);
 
   8 use SL::Locale::String;
 
  10 use SL::DB::Manager::Shop;
 
  11 use SL::DB::Pricegroup;
 
  14 use Rose::Object::MakeMethods::Generic (
 
  15   scalar                  => [ qw(connectors price_types price_sources taxzone_id protocols) ],
 
  16   'scalar --get_set_init' => [ qw(shop) ]
 
  19 __PACKAGE__->run_before('check_auth');
 
  20 __PACKAGE__->run_before('load_types',    only => [ qw(new edit) ]);
 
  29   $self->_setup_list_action_bar;
 
  30   $self->render('shops/list',
 
  32                 SHOPS => SL::DB::Manager::Shop->get_all_sorted,
 
  39   my $is_new = !$self->shop->id;
 
  40   $self->_setup_form_action_bar;
 
  41   $self->render('shops/form', title => ($is_new ? t8('Add shop') : t8('Edit shop')));
 
  47   $self->create_or_update;
 
  53   if ( eval { $self->shop->delete; 1; } ) {
 
  54     flash_later('info',  $::locale->text('The shop has been deleted.'));
 
  56     flash_later('error', $::locale->text('The shop is in use and cannot be deleted.'));
 
  58   $self->redirect_to(action => 'list');
 
  64   SL::DB::Shop->reorder_list(@{ $::form->{shop_id} || [] });
 
  65   $self->render(\'', { type => 'json' }); # ' emacs happy again
 
  68 sub action_check_connectivity {
 
  73   my $shop = SL::Shop->new( config => $self->shop );
 
  74   my $connect = $shop->check_connectivity;
 
  75   $ok       = $connect->{success};
 
  76   my  $version = $connect->{data}->{version};
 
  77   $self->render('shops/test_shop_connection', { layout => 0 },
 
  78                 title   => t8('Shop Connection Test'),
 
  84   $::auth->assert('config');
 
  88   SL::DB::Manager::Shop->find_by_or_create(id => $::form->{id} || 0)->assign_attributes(%{ $::form->{shop} });
 
  95 sub create_or_update {
 
  98   my $is_new = !$self->shop->id;
 
 100   my @errors = $self->shop->validate;
 
 102     flash('error', @errors);
 
 104     $self->action_edit();
 
 110   flash_later('info', $is_new ? t8('The shop has been created.') : t8('The shop has been saved.'));
 
 111   $self->redirect_to(action => 'list');
 
 116   # data for the dropdowns when editing Shop configs
 
 118   require SL::ShopConnector::ALL;
 
 119   $self->connectors(SL::ShopConnector::ALL->connectors);
 
 121   $self->price_types( [ { id => "brutto", name => t8('brutto') },
 
 122                         { id => "netto",  name => t8('netto')  } ] );
 
 124   $self->protocols(   [ { id => "http",  name => t8('http') },
 
 125                         { id => "https", name => t8('https') } ] );
 
 128   push(@{ $pricesources } , { id => "master_data/sellprice", name => t8("Master Data") . " - " . t8("Sellprice") },
 
 129                             { id => "master_data/listprice", name => t8("Master Data") . " - " . t8("Listprice") },
 
 130                             { id => "master_data/lastcost",  name => t8("Master Data") . " - " . t8("Lastcost")  });
 
 131   my $pricegroups = SL::DB::Manager::Pricegroup->get_all;
 
 132   foreach my $pg ( @$pricegroups ) {
 
 133     push( @{ $pricesources } , { id => "pricegroup/" . $pg->id, name => t8("Pricegroup") . " - " . $pg->pricegroup} );
 
 136   $self->price_sources($pricesources);
 
 138   #Buchungsgruppen for calculate the tax for an article
 
 140   my $taxzones = SL::DB::Manager::TaxZone->get_all_sorted();
 
 142   foreach my $tz (@$taxzones) {
 
 143     push  @{ $taxkey_ids }, { id => $tz->id, name => $tz->description };
 
 145   $self->taxzone_id( $taxkey_ids );
 
 148 sub _setup_form_action_bar {
 
 151   for my $bar ($::request->layout->get('actionbar')) {
 
 156           submit    => [ '#form', { action => "Shop/save" } ],
 
 157           accesskey => 'enter',
 
 161           submit => [ '#form', { action => "Shop/delete" } ],
 
 166         call => [ 'kivi.Shop.check_connectivity', id => "form" ],
 
 167         tooltip => t8('Check connectivity'),
 
 171         submit => [ '#form', { action => "Shop/list" } ],
 
 177 sub _setup_list_action_bar {
 
 180   for my $bar ($::request->layout->get('actionbar')) {
 
 184         link => $self->url_for(action => 'edit'),
 
 212 G. Richardson E<lt>information@kivitendo-premium.deE<gt>
 
 213 W. Hahn E<lt>wh@futureworldsearch.netE<gt>