WebshopApi: Shop-Tab in Partcontroller eingebaut
authorWerner Hahn <wh@futureworldsearch.net>
Fri, 22 Sep 2017 00:27:58 +0000 (02:27 +0200)
committerWerner Hahn <wh@futureworldsearch.net>
Tue, 26 Sep 2017 10:25:02 +0000 (12:25 +0200)
SL/Controller/Part.pm
templates/webpages/part/_shop.html [new file with mode: 0644]
templates/webpages/part/form.html

index 66f8731..f152e08 100644 (file)
@@ -6,6 +6,7 @@ use parent qw(SL::Controller::Base);
 use Clone qw(clone);
 use SL::DB::Part;
 use SL::DB::PartsGroup;
+use SL::DB::Shop;
 use SL::Controller::Helper::GetModels;
 use SL::Locale::String qw(t8);
 use SL::JSON;
@@ -21,7 +22,7 @@ use Carp;
 
 use Rose::Object::MakeMethods::Generic (
   'scalar --get_set_init' => [ qw(parts models part p warehouses multi_items_models
-                                  makemodels
+                                  makemodels shops_not_assigned
                                   orphaned
                                   assortment assortment_items assembly assembly_items
                                   all_pricegroups all_translations all_partsgroups all_units
@@ -636,7 +637,7 @@ sub add {
 
 sub _set_javascript {
   my ($self) = @_;
-  $::request->layout->use_javascript("${_}.js")  for qw(kivi.Part kivi.File kivi.PriceRule ckeditor/ckeditor ckeditor/adapters/jquery);
+  $::request->layout->use_javascript("${_}.js")  for qw(kivi.Part kivi.File kivi.PriceRule ckeditor/ckeditor ckeditor/adapters/jquery kivi.ShopPart);
   $::request->layout->add_javascripts_inline("\$(function(){kivi.PriceRule.load_price_rules_for_part(@{[ $self->part->id ]})});") if $self->part->id;
 }
 
@@ -803,7 +804,7 @@ sub init_part {
   # used by edit, save, delete and add
 
   if ( $::form->{part}{id} ) {
-    return SL::DB::Part->new(id => $::form->{part}{id})->load(with => [ qw(makemodels prices translations partsgroup) ]);
+    return SL::DB::Part->new(id => $::form->{part}{id})->load(with => [ qw(makemodels prices translations partsgroup shop_parts shop_parts.shop) ]);
   } else {
     die "part_type missing" unless $::form->{part}{part_type};
     return SL::DB::Part->new(part_type => $::form->{part}{part_type});
@@ -924,6 +925,18 @@ sub init_all_buchungsgruppen {
   }
 }
 
+sub init_shops_not_assigned {
+  my ($self) = @_;
+
+  my @used_shop_ids = map { $_->shop->id } @{ $self->part->shop_parts };
+  if ( @used_shop_ids ) {
+    return SL::DB::Manager::Shop->get_all( query => [ obsolete => 0, '!id' => \@used_shop_ids ], sort_by => 'sortkey' );
+  }
+  else {
+    return SL::DB::Manager::Shop->get_all( query => [ obsolete => 0 ], sort_by => 'sortkey' );
+  }
+}
+
 sub init_all_units {
   my ($self) = @_;
   if ( $self->part->orphaned ) {
diff --git a/templates/webpages/part/_shop.html b/templates/webpages/part/_shop.html
new file mode 100644 (file)
index 0000000..051a230
--- /dev/null
@@ -0,0 +1,82 @@
+[%- USE HTML %][%- USE L -%][%- USE P -%][%- USE LxERP -%]
+[%- USE Dumper %]
+[%- USE JavaScript -%]
+<div id="shop_variables">
+ <h2>[% LxERP.t8("Active shops:") %]</h2>
+ <table width="100%">
+  <thead>
+  <tr class="listheading">
+   <th>[% LxERP.t8("Shop") %]</th>
+   <th>[% LxERP.t8("Active") %]</th>
+   <th>[% LxERP.t8("Shop part") %]</th>
+   <th>[% LxERP.t8("Price source") %]</th>
+   <th>[% LxERP.t8("Price") %]</th>
+   <th>[% LxERP.t8("Stock Local/Shop") %]</th>
+   <th>[% LxERP.t8("Last update") %]</th>
+   <th>[% LxERP.t8("Action") %]</th>
+   <th>[% LxERP.t8("Action") %]</th>
+   <th>[% LxERP.t8("Action") %]</th>
+  </tr>
+  </thead>
+  [% # L.dump(SELF.part) %]
+  [%- FOREACH shop_part = SELF.part.shop_parts %]
+  [% IF !shop_part.shop.obsolete %]
+  <tr class="listrow">
+   <td>[% HTML.escape( shop_part.shop.description ) %]</td>
+   <td>[% L.html_tag('span', shop_part.active, id => 'shop_part_active_' _ shop_part.id ) %]</td>
+   <td>[% L.html_tag('span', shop_part.shop_description, id => 'shop_part_description_' _ shop_part.id ) %]</td>
+   <td>[% L.html_tag('span',LxERP.t8(), id => 'active_price_source_' _ shop_part.id) %] </td>
+   <td>[% L.html_tag('span','Price', id => 'price_' _ shop_part.id) %]</td>
+   <td>[% L.html_tag('span','Stock', id => 'stock_' _ shop_part.id) %]</td>
+   <td>[% L.html_tag('span', shop_part.last_update.to_kivitendo('precision' => 'minute'), id => 'shop_part_last_update_' _ shop_part.id ) %]</td>
+   <td>[% L.button_tag("kivi.ShopPart.edit_shop_part(" _ shop_part.id _ ")", LxERP.t8("Edit"))  %]</td>
+   <td>[% L.button_tag("kivi.ShopPart.update_shop_part(" _ shop_part.id _ ")", LxERP.t8("Upload"))  %]</td>
+   <td>[% L.button_tag("kivi.ShopPart.get_all_categories(" _ shop_part.id _ ")", LxERP.t8("Shopcategories"))  %]<br>
+    [% IF shop_part.shop_category %]
+      [% IF shop_part.shop_category.1.size > 1%]
+        [% FOREACH cat = shop_part.shop_category %]
+          [% HTML.escape(cat.1) %]<br>
+        [% END %]
+      [% ELSE %]
+        [% HTML.escape(shop_part.shop_category.1) %]<br>
+      [% END %]
+    [% END %]
+   </td>
+  </tr>
+  <script type="text/javascript">
+    $(function() {
+      kivi.ShopPart.update_price_n_price_source([% shop_part.id %],'[% shop_part.active_price_source %]');
+      kivi.ShopPart.update_stock([% shop_part.id %]);
+    });
+  </script>
+  [% END %]
+  [%- END %]
+  [%- FOREACH shop = SELF.shops_not_assigned %]
+  <tr>
+   <td>[% HTML.escape( shop.description ) %]</td>
+   <td></td>
+   <td></td>
+   <td></td>
+   <td></td>
+   <td></td>
+   <td>[% L.button_tag("kivi.ShopPart.create_shop_part(" _ id _ ", " _ shop.id _ ")", LxERP.t8("Add"))  %]</td>
+  </tr>
+  </thead>
+  [%- END %]
+</table>
+
+
+[% # L.dump(shop_part) %]
+<h2>[% LxERP.t8("Shopimages - valid for all shops") %]</h2>
+  [%- IF shop_part.part_id %]
+    <script type="text/javascript">
+      $(function() {
+        kivi.ShopPart.show_images([% shop_part.part_id %]);
+      });
+    </script>
+    <div id="shop_images" border=1 ></div>
+  [%- ELSE %]
+    <div id="shop_images" border=1 >[% LxERP.t8('To upload images: Please create shoppart first') %]</div>
+  [%- END %]
+</div>
+
index b33d5b0..733fb13 100644 (file)
@@ -41,6 +41,9 @@
     [%- IF CUSTOM_VARIABLES.size %]
     <li><a href="#custom_variables">[% 'Custom Variables' | $T8 %]</a></li>
     [%- END %]
+    [% IF AUTH.assert('shop_part_edit', 1) && SELF.part.id && SELF.part.shop %]
+    <li><a href="#shop_variables">[% 'Shop variables' | $T8 %]</a></li>
+    [% END %]
    </ul>
 
    <div id="basic_data">
    <div id="sales_price_information">
      [% PROCESS part/_sales_price_information.html id=SELF.part.id %]
    </div>
+   [% IF AUTH.assert('shop_part_edit', 1) && SELF.part.id %]
+   <div id="shop_variables">
+     [% PROCESS 'part/_shop.html' %]
+   </div>
+   [%- END %]
    [%- END %]
 
    [%- IF CUSTOM_VARIABLES.size %]