WebshopApi: ShopOrder Controller
authorWerner Hahn <wh@futureworldsearch.net>
Fri, 22 Sep 2017 00:32:53 +0000 (02:32 +0200)
committerWerner Hahn <wh@futureworldsearch.net>
Tue, 26 Sep 2017 10:25:02 +0000 (12:25 +0200)
SL/Controller/ShopOrder.pm [new file with mode: 0644]
SL/DB/Helper/LinkedRecords.pm
js/kivi.ShopOrder.js [new file with mode: 0644]
templates/webpages/shop_order/_filter.html [new file with mode: 0644]
templates/webpages/shop_order/_transfer_status.html [new file with mode: 0644]
templates/webpages/shop_order/list.html [new file with mode: 0644]
templates/webpages/shop_order/show.html [new file with mode: 0644]

diff --git a/SL/Controller/ShopOrder.pm b/SL/Controller/ShopOrder.pm
new file mode 100644 (file)
index 0000000..e8d804f
--- /dev/null
@@ -0,0 +1,407 @@
+package SL::Controller::ShopOrder;
+
+use strict;
+
+use parent qw(SL::Controller::Base);
+
+use SL::BackgroundJob::ShopOrderMassTransfer;
+use SL::System::TaskServer;
+use SL::DB::ShopOrder;
+use SL::DB::ShopOrderItem;
+use SL::DB::Shop;
+use SL::DB::History;
+use SL::DBUtils;
+use SL::Shop;
+use SL::Presenter;
+use SL::Helper::Flash;
+use SL::Locale::String;
+use SL::Controller::Helper::ParseFilter;
+use Rose::Object::MakeMethods::Generic
+(
+  'scalar --get_set_init' => [ qw(shop_order shops transferred js) ],
+);
+
+__PACKAGE__->run_before('check_auth');
+__PACKAGE__->run_before('setup');
+
+use Data::Dumper;
+
+sub action_get_orders {
+  my ( $self ) = @_;
+  my $orders_fetched;
+  my $new_orders;
+  my %new_order;
+  my $active_shops = SL::DB::Manager::Shop->get_all(query => [ obsolete => 0 ]);
+  foreach my $shop_config ( @{ $active_shops } ) {
+    my $shop = SL::Shop->new( config => $shop_config );
+    my $connect = $shop->check_connectivity;
+
+    if( !$connect->{success} ){
+      %new_order  = (
+        number_of_orders => $connect->{data}->{version},
+        shop_id          => $shop->config->description,
+        error            => 1,
+     );
+     $new_orders = \%new_order;
+    }else{
+      $new_orders = $shop->connector->get_new_orders;
+    }
+    push @{ $orders_fetched }, $new_orders ;
+  }
+
+  foreach my $shop_fetched(@{ $orders_fetched }) {
+    if($shop_fetched->{error}){
+      flash_later('error', t8('From shop "#1" :  #2 ', $shop_fetched->{shop_id}, $shop_fetched->{number_of_orders},));
+    }else{
+      flash_later('info', t8('From shop #1 :  #2 shoporders have been fetched.', $shop_fetched->{shop_id}, $shop_fetched->{number_of_orders},));
+    }
+  }
+  $self->redirect_to(controller => "ShopOrder", action => 'list');
+}
+
+sub action_list {
+  my ( $self ) = @_;
+
+  my %filter = ($::form->{filter} ? parse_filter($::form->{filter}) : query => [ transferred => 0, obsolete => 0 ]);
+  my $transferred = $::form->{filter}->{transferred_eq_ignore_empty} ne '' ? $::form->{filter}->{transferred_eq_ignore_empty} : '';
+  my $sort_by = $::form->{sort_by} ? $::form->{sort_by} : 'order_date';
+  $sort_by .=$::form->{sort_dir} ? ' DESC' : ' ASC';
+  my $shop_orders = SL::DB::Manager::ShopOrder->get_all( %filter, sort_by => $sort_by,
+                                                      with_objects => ['shop_order_items', 'kivi_customer', 'shop'],
+                                                    );
+
+  foreach my $shop_order(@{ $shop_orders }){
+
+    my $open_invoices = SL::DB::Manager::Invoice->get_all_count(
+      query => [customer_id => $shop_order->{kivi_customer_id},
+              paid => {lt_sql => 'amount'},
+      ],
+    );
+    $shop_order->{open_invoices} = $open_invoices;
+  }
+  $self->_setup_list_action_bar;
+  $self->render('shop_order/list',
+                title       => t8('ShopOrders'),
+                SHOPORDERS  => $shop_orders,
+                TOOK        => $transferred,
+              );
+}
+
+sub action_show {
+  my ( $self ) = @_;
+  my $id = $::form->{id} || {};
+  my $shop_order = SL::DB::ShopOrder->new( id => $id )->load( with => ['kivi_customer'] );
+  die "can't find shoporder with id $id" unless $shop_order;
+
+  my $proposals = $shop_order->check_for_existing_customers;
+
+  $self->render('shop_order/show',
+                title       => t8('Shoporder'),
+                IMPORT      => $shop_order,
+                PROPOSALS   => $proposals,
+              );
+
+}
+
+sub action_delete_order {
+  my ( $self ) = @_;
+
+  $self->shop_order->obsolete(1);
+  $self->shop_order->save;
+  $self->redirect_to(controller => "ShopOrder", action => 'list', filter => { 'transferred:eq_ignore_empty' => 0 });
+}
+
+sub action_undelete_order {
+  my ( $self ) = @_;
+
+  $self->shop_order->obsolete(0);
+  $self->shop_order->save;
+  $self->redirect_to(controller => "ShopOrder", action => 'show', id => $self->shop_order->id);
+}
+
+sub action_transfer {
+  my ( $self ) = @_;
+
+  my $customer = SL::DB::Manager::Customer->find_by(id => $::form->{customer});
+  die "Can't find customer" unless $customer;
+  my $employee = SL::DB::Manager::Employee->current;
+  die "Can't find employee" unless $employee;
+
+  die "Can't load shop_order form form->import_id" unless $self->shop_order;
+  my $order = $self->shop_order->convert_to_sales_order(customer => $customer, employee => $employee);
+
+  if ($order->{error}){
+    flash_later('error',@{$order->{errors}});
+    $self->redirect_to(controller => "ShopOrder", action => 'show', id => $self->shop_order->id);
+  }else{
+    $order->db->with_transaction( sub {
+      $order->calculate_prices_and_taxes;
+      $order->save;
+
+      my $snumbers = "ordernumber_" . $order->ordnumber;
+      SL::DB::History->new(
+                        trans_id    => $order->id,
+                        snumbers    => $snumbers,
+                        employee_id => SL::DB::Manager::Employee->current->id,
+                        addition    => 'SAVED',
+                        what_done   => 'Shopimport -> Order',
+                      )->save();
+      foreach my $item(@{ $order->orderitems }){
+        $item->parse_custom_variable_values->save;
+        $item->{custom_variables} = \@{ $item->cvars_by_config };
+        $item->save;
+      }
+
+      $self->shop_order->transferred(1);
+      $self->shop_order->transfer_date(DateTime->now_local);
+      $self->shop_order->save;
+      $self->shop_order->link_to_record($order);
+    }) || die $order->db->error;
+    $self->redirect_to(controller => "oe.pl", action => 'edit', type => 'sales_order', vc => 'customer', id => $order->id);
+  }
+}
+
+sub action_mass_transfer {
+  my ($self) = @_;
+  my @shop_orders =  @{ $::form->{id} || [] };
+
+  my $job                   = SL::DB::BackgroundJob->new(
+    type                    => 'once',
+    active                  => 1,
+    package_name            => 'ShopOrderMassTransfer',
+  )->set_data(
+     shop_order_record_ids       => [ @shop_orders ],
+     num_order_created           => 0,
+     num_delivery_order_created  => 0,
+     status                      => SL::BackgroundJob::ShopOrderMassTransfer->WAITING_FOR_EXECUTION(),
+     conversion_errors         => [ ],
+   )->update_next_run_at;
+
+   SL::System::TaskServer->new->wake_up;
+
+   my $html = $self->render('shop_order/_transfer_status', { output => 0 }, job => $job);
+
+   $self->js
+      ->html('#status_mass_transfer', $html)
+      ->run('kivi.ShopOrder.massTransferStarted')
+      ->render;
+}
+
+sub action_transfer_status {
+  my ($self)  = @_;
+  my $job     = SL::DB::BackgroundJob->new(id => $::form->{job_id})->load;
+  my $html    = $self->render('shop_order/_transfer_status', { output => 0 }, job => $job);
+
+  $self->js->html('#status_mass_transfer', $html);
+  $self->js->run('kivi.ShopOrder.massTransferFinished') if $job->data_as_hash->{status} == SL::BackgroundJob::ShopOrderMassTransfer->DONE();
+  $self->js->render;
+
+}
+
+sub action_apply_customer {
+  my ( $self, %params ) = @_;
+  my $shop = SL::DB::Manager::Shop->find_by( id => $self->shop_order->shop_id );
+  my $what = $::form->{create_customer}; # new from billing, customer or delivery address
+  my %address = ( 'name'                  => $::form->{$what.'_name'},
+                  'department_1'          => $::form->{$what.'_company'},
+                  'department_2'          => $::form->{$what.'_department'},
+                  'street'                => $::form->{$what.'_street'},
+                  'zipcode'               => $::form->{$what.'_zipcode'},
+                  'city'                  => $::form->{$what.'_city'},
+                  'email'                 => $::form->{$what.'_email'},
+                  'country'               => $::form->{$what.'_country'},
+                  'phone'                 => $::form->{$what.'_phone'},
+                  'email'                 => $::form->{$what.'_email'},
+                  'greeting'              => $::form->{$what.'_greeting'},
+                  'taxincluded_checked'   => $shop->pricetype eq "brutto" ? 1 : 0,
+                  'taxincluded'           => $shop->pricetype eq "brutto" ? 1 : 0,
+                  'pricegroup_id'         => (split '\/',$shop->price_source)[0] eq "pricegroup" ?  (split '\/',$shop->price_source)[1] : undef,
+                  'taxzone_id'            => $shop->taxzone_id,
+                  'currency'              => $::instance_conf->get_currency_id,
+                  #'payment_id'            => 7345,# TODO hardcoded
+                );
+  my $customer;
+  if($::form->{cv_id}){
+    $customer = SL::DB::Customer->new(id => $::form->{cv_id})->load;
+    $customer->assign_attributes(%address);
+    $customer->save;
+  }else{
+    $customer = SL::DB::Customer->new(%address);
+    $customer->save;
+  }
+  my $snumbers = "customernumber_" . $customer->customernumber;
+  SL::DB::History->new(
+                    trans_id    => $customer->id,
+                    snumbers    => $snumbers,
+                    employee_id => SL::DB::Manager::Employee->current->id,
+                    addition    => 'SAVED',
+                    what_done   => 'Shopimport',
+                  )->save();
+
+  $self->redirect_to(action => 'show', id => $::form->{import_id});
+}
+
+sub setup {
+  my ($self) = @_;
+  $::auth->assert('shop_part_edit');
+  $::request->layout->use_javascript("${_}.js")  for qw(kivi.ShopOrder);
+}
+
+sub check_auth {
+  $::auth->assert('shop_part_edit');
+}
+#
+# Helper
+#
+
+sub init_shop_order {
+  my ( $self ) = @_;
+  return SL::DB::ShopOrder->new(id => $::form->{import_id})->load if $::form->{import_id};
+}
+
+sub init_transferred {
+  [ { title => t8("all"),             value => '' },
+    { title => t8("transferred"),     value => 1  },
+    { title => t8("not transferred"), value => 0  }, ]
+}
+
+sub init_shops {
+  SL::DB::Shop->shops_dd;
+}
+
+sub _setup_list_action_bar {
+  my ($self) = @_;
+
+  for my $bar ($::request->layout->get('actionbar')) {
+    $bar->add(
+        action => [
+          t8('Search'),
+          submit    => [ '#shoporders', { action => "ShopOrder/list" } ],
+        ],
+         link => [
+          t8('Shoporders'),
+          link => [ $self->url_for(action => 'get_orders') ],
+          tooltip => t8('New shop orders'),
+        ],
+        'separator',
+        action => [
+          t8('Execute'),
+          call => [ 'kivi.ShopOrder.setup', id => "mass_transfer" ],
+          tooltip => t8('Transfer all marked'),
+        ],
+    );
+  }
+}
+
+1;
+
+__END__
+
+=encoding utf-8
+
+=head1 NAME
+
+SL::Controller::ShopOrder - Shoporder CRUD Controller
+
+=head1 DESCRIPTION
+
+Fetches the shoporders and transfers them to orders.
+
+Relations for shoporders
+
+=over 2
+
+=item shop_order_items
+
+=item shops
+
+=item shop_parts
+
+=back
+
+=head1 URL ACTIONS
+
+=over 4
+
+=item C<action_get_orders>
+
+Fetches the shoporders with the shopconnector class
+
+=item C<action_list>
+
+List the shoporders by different filters.
+From the List you can transfer shoporders into orders in batch where it is possible or one by one.
+
+=item C<action_show>
+
+Shows one order. From here you can apply/change/select customer data and transfer the shoporder to an order.
+
+=item C<action_delete>
+
+Marks the shoporder as obsolete. It's for shoporders you don't want to transfer.
+
+=item C<action_undelete>
+
+Marks the shoporder obsolete = false
+
+=item C<action_transfer>
+
+Transfers one shoporder to an order.
+
+=item C<action_apply_customer>
+
+Applys a new customer from the shoporder.
+
+=back
+
+=head1 TASKSERVER ACTIONS
+
+=over 4
+
+=item C<action_mass_transfer>
+
+Transfers more shoporders by backgroundjob called from the taskserver to orders.
+
+=item C<action_transfer_status>
+
+Shows the backgroundjobdata for the popup status window
+
+=back
+
+=head1 SETUP
+
+=over 4
+
+=item C<setup>
+
+=back
+
+=head1 INITS
+
+=over 4
+
+=item C<init_shoporder>
+
+=item C<init_transfered>
+
+Transferstatuses for the filter dropdown
+
+=item C<init_shops>
+
+Filter dropdown Shops
+
+=back
+
+=head1 TODO
+
+Implements different payments, pricesources and pricegroups. Till now not needed.
+
+=head1 BUGS
+
+None yet. :)
+
+=head1 AUTHOR
+
+W. Hahn E<lt>wh@futureworldsearch.netE<gt>
+
+=cut
index 5ad4925..bf91e6a 100644 (file)
@@ -312,6 +312,7 @@ sub sort_linked_records {
                   'SL::DB::PurchaseInvoice' => sub { $_[0]->invnumber },
                   'SL::DB::RequirementSpec' => sub { $_[0]->id },
                   'SL::DB::Letter'          => sub { $_[0]->letternumber },
+                  'SL::DB::ShopOrder'       => sub { $_[0]->shop_ordernumber },
                   UNKNOWN                   => '9999999999999999',
                 );
   my $number_xtor = sub {
@@ -341,6 +342,7 @@ sub sort_linked_records {
               'SL::DB::PurchaseInvoice' => 150,
               'SL::DB::PurchaseInvoice' => 150,
               'SL::DB::Letter'          => 200,
+              'SL::DB::ShopOrder'       => 250,
               UNKNOWN                   => 999,
             );
   my $score_xtor = sub {
diff --git a/js/kivi.ShopOrder.js b/js/kivi.ShopOrder.js
new file mode 100644 (file)
index 0000000..21ac487
--- /dev/null
@@ -0,0 +1,35 @@
+namespace('kivi.ShopOrder', function(ns) {
+  ns.massTransferInitialize = function() {
+    kivi.popup_dialog({
+      id: 'status_mass_transfer',
+      dialog: {
+        title: kivi.t8('Status Shoptransfer'),
+      }
+    });
+  };
+
+  ns.massTransferStarted = function() {
+    $('#status_mass_transfer').data('timerId', setInterval(function() {
+      $.get("controller.pl", {
+        action: 'ShopOrder/transfer_status',
+        job_id: $('#smt_job_id').val()
+      }, kivi.eval_json_result);
+    }, 5000));
+  };
+
+  ns.massTransferFinished = function() {
+    clearInterval($('#status_mass_transfer').data('timerId'));
+    $('.ui-dialog-titlebar button.ui-dialog-titlebar-close').prop('disabled', '')
+  };
+
+  ns.processClose = function() {
+    $('#status_mass_transfer').dialog('close');
+    window.location.href = 'controller.pl?filter.obsolete=0&filter.transferred=0&action=ShopOrder%2flist&db=shop_orders&sort_by=shop_ordernumber';
+  };
+
+  ns.setup = function() {
+    kivi.ShopOrder.massTransferInitialize();
+    kivi.submit_ajax_form('controller.pl?action=ShopOrder/mass_transfer','[name=shop_orders_list]');
+  };
+
+});
diff --git a/templates/webpages/shop_order/_filter.html b/templates/webpages/shop_order/_filter.html
new file mode 100644 (file)
index 0000000..b07d7f7
--- /dev/null
@@ -0,0 +1,38 @@
+[%- USE T8 %]
+[%- USE L %]
+[%- USE LxERP %]
+[%- USE HTML %]
+ <form method="post" action="controller.pl" name="shop_orders" id="shoporders">
+ <table id='filter_table'>
+
+    <tr>
+     <th align="right">[% 'Shop' | $T8 %]</th>
+     <td>[% L.select_tag('filter.shop_id:eq_ignore_empty', SELF.shops, value_key = 'value', title_key = 'title', default=0) %]</td>
+    </tr>
+
+    <tr>
+     <th align="right">[% 'Status' | $T8 %]</th>
+     <td>[% L.select_tag('filter.transferred:eq_ignore_empty', SELF.transferred, value_key = 'value', title_key = 'title', default=0) %]</td>
+    </tr>
+
+
+    <tr>
+     <th align="right">[% 'from' | $T8 %]</th>
+     <td>[% L.date_tag('filter.order_date:date::ge', FORM.filter.order_date_date__ge) %]</td>
+    </tr>
+
+    <tr>
+     <th align="right">[% 'to' | $T8 %]</th>
+     <td>[% L.date_tag('filter.order_date:date::le', FORM.filter.order_date_date__le) %]</td>
+    </tr>
+
+    <tr>
+      <th align="right">[% 'Obsolete' | $T8 %]</th>
+      <td>[% L.yes_no_tag('filter.obsolete', FORM.filter.obsolete, default='0', with_empty=1, empty_title='---') %]</td>
+    </tr>
+
+ </table>
+
+
+<a href='#' onClick='javascript:$("#filter_table input").val("");$("#filter_table input[type=checkbox]").prop("checked", 0);'>[% 'Reset' | $T8 %]</a>
+<br>
diff --git a/templates/webpages/shop_order/_transfer_status.html b/templates/webpages/shop_order/_transfer_status.html
new file mode 100644 (file)
index 0000000..26b8c82
--- /dev/null
@@ -0,0 +1,61 @@
+[%- USE LxERP -%][%- USE L -%][%- USE HTML -%]
+[%- USE Dumper -%]
+[% SET data = job.data_as_hash %]
+
+
+<h2>[% LxERP.t8("Watch status") %]</h2>
+
+[% L.hidden_tag('', job.id, id="smt_job_id") %]
+
+JOBID: [% job.id %] <p>
+ [% LxERP.t8("This status output will be refreshed every five seconds.") %]
+</p>
+<p>
+</p>
+<p>
+ [% L.link("#", LxERP.t8("Close window"), onclick="kivi.ShopOrder.processClose();") %]
+ <table>
+  <tr>
+   <th valign="top" align="left">[% LxERP.t8("Current status:") %]</th>
+   <td valign="top">
+    [% IF !data.status %]
+     [% LxERP.t8("waiting for job to be started") %]
+    [% ELSIF data.status == 1 %]
+     [% LxERP.t8("Converting to deliveryorder") %]
+     [% ELSE %]
+     [% LxERP.t8("Done.") %]
+    [% END %]
+   </td>
+  </tr>
+  <tr>
+   <th valign="top" align="left">[% LxERP.t8("Number of orders created:") %]</th>
+   <td valign="top">[% IF data.status > 0 %][% HTML.escape(data.num_order_created) %] / [% HTML.escape(data.shop_order_record_ids.size) %][% ELSE %]–[% END %]</td>
+  </tr>
+
+
+  <tr>
+   <th valign="top" align="left">[% LxERP.t8("Errors during conversion:") %]</th>
+   <td valign="top">
+[% IF !data.status %]
+  â€“
+[% ELSIF !data.conversion_errors.size %]
+ [% LxERP.t8("No errors have occurred.") %]
+[% ELSE %]
+    <table>
+     <tr class="listheader">
+      <th>[% LxERP.t8("Shoporder") %]</th>
+      <th>[% LxERP.t8("Error") %]</th>
+     </tr>
+
+ [% FOREACH error = data.conversion_errors %]
+     <tr>
+      <td valign="top">[% HTML.escape(error.number) %]</td>
+      <td valign="top">[% FOREACH message = error.message %][% HTML.escape(message) %]<br>[% END %]</td>
+     </tr>
+ [% END %]
+    </table>
+[% END %]
+   </td>
+  </tr>
+ </table>
+</p>
diff --git a/templates/webpages/shop_order/list.html b/templates/webpages/shop_order/list.html
new file mode 100644 (file)
index 0000000..1da0b17
--- /dev/null
@@ -0,0 +1,204 @@
+[%- USE HTML -%][%- USE LxERP -%][%- USE L -%][%- USE T8 -%]
+[% USE Dumper %]
+
+[% L.stylesheet_tag('webshop') %]
+[%- INCLUDE 'common/flash.html' %]
+<h1>[% title %]<span style="float:right;">[% 'Number data sets' | $T8 %]: [% SHOPORDERS.size %]</span></h1>
+[%- PROCESS 'shop_order/_filter.html' filter=SELF.models.filtered.laundered %]
+
+<hr>
+
+ <table id="shoplist" width="100%">
+  <thead>
+   <tr class="listheading">
+    <th>[% 'Shop' | $T8 %]</th>
+    <th>[% IF FORM.sort_by == 'order_date' %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=order_date&sort_dir=[% 1 - FORM.sort_dir %]&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Shop orderdate' | $T8 %][% IF FORM.sort_dir == 0 %]<img border="0" src="image/down.png">[% ELSE %]<img border="0" src="image/up.png">[% END %]</a>
+    [% ELSE %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=order_date&sort_dir=0&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Shop orderdate' | $T8 %]</a>
+    [% END %]
+    <br>
+    [% IF FORM.sort_by == 'itime' %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=itime&sort_dir=[% 1 - FORM.sort_dir %]&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Importdate' | $T8 %][% IF FORM.sort_dir == 0 %]<img border="0" src="image/down.png">[% ELSE %]<img border="0" src="image/up.png">[% END %]</a>
+    [% ELSE %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=itime&sort_dir=0&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Importdate' | $T8 %]</a>
+    [% END %]
+    </th>
+    <th>[% IF FORM.sort_by == 'shop_ordernumber' %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=shop_ordernumber&sort_dir=[% 1 - FORM.sort_dir %]&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Shop ordernumber' | $T8 %][% IF FORM.sort_dir == 0 %]<img border="0" src="image/down.png">[% ELSE %]<img border="0" src="image/up.png">[% END %]</a>
+    [% ELSE %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=shop_ordernumber&sort_dir=0&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Shop ordernumber' | $T8 %]</a>
+    [% END %]
+    </th>
+    <th>[% IF FORM.sort_by == 'shop_customer_number' %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=shop_customer_number&sort_dir=[% 1 - FORM.sort_dir %]&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Shop customernumber' | $T8 %][% IF FORM.sort_dir == 0 %]<img border="0" src="image/down.png">[% ELSE %]<img border="0" src="image/up.png">[% END %]</a>
+    [% ELSE %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=shop_customer_number&sort_dir=0&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Shop customernumber' | $T8 %]</a>
+    [% END %]
+    </th>
+    <th>[% 'Shop Customer Address' | $T8 %]<br>
+    [% IF FORM.sort_by == 'customer_lastname' %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=customer_lastname&sort_dir=[% 1 - FORM.sort_dir %]&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Name' | $T8 %][% IF FORM.sort_dir == 0 %]<img border="0" src="image/down.png">[% ELSE %]<img border="0" src="image/up.png">[% END %]</a>|
+    [% ELSE %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=customer_lastname&sort_dir=0&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Name' | $T8 %]</a>|
+    [% END %]
+    [% IF FORM.sort_by == 'customer_zipcode' %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=customer_zipcode&sort_dir=[% 1 - FORM.sort_dir %]&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Zip' | $T8 %][% IF FORM.sort_dir == 0 %]<img border="0" src="image/down.png">[% ELSE %]<img border="0" src="image/up.png">[% END %]</a>|
+    [% ELSE %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=customer_zipcode&sort_dir=0&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Zip' | $T8 %]</a>|
+    [% END %]
+    [% IF FORM.sort_by == 'customer_country' %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=customer_country&sort_dir=[% 1 - FORM.sort_dir %]&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Country' | $T8 %][% IF FORM.sort_dir == 0 %]<img border="0" src="image/down.png">[% ELSE %]<img border="0" src="image/up.png">[% END %]</a>
+    [% ELSE %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=customer_country&sort_dir=0&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Country' | $T8 %]</a>
+    [% END %]
+      </th>
+    <th>[% 'Shop Billing Address' | $T8 %]</br>
+    [% IF FORM.sort_by == 'billing_lastname' %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=billing_lastname&sort_dir=[% 1 - FORM.sort_dir %]&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Name' | $T8 %][% IF FORM.sort_dir == 0 %]<img border="0" src="image/down.png">[% ELSE %]<img border="0" src="image/up.png">[% END %]</a>|
+    [% ELSE %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=billing_lastname&sort_dir=0&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Name' | $T8 %]</a>|
+    [% END %]
+    [% IF FORM.sort_by == 'billing_zipcode' %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=billing_zipcode&sort_dir=[% 1 - FORM.sort_dir %]&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Zip' | $T8 %][% IF FORM.sort_dir == 0 %]<img border="0" src="image/down.png">[% ELSE %]<img border="0" src="image/up.png">[% END %]</a>|
+    [% ELSE %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=billing_zipcode&sort_dir=0&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Zip' | $T8 %]</a>|
+    [% END %]
+    [% IF FORM.sort_by == 'billing_country' %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=billing_country&sort_dir=[% 1 - FORM.sort_dir %]&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Country' | $T8 %][% IF FORM.sort_dir == 0 %]<img border="0" src="image/down.png">[% ELSE %]<img border="0" src="image/up.png">[% END %]</a>
+    [% ELSE %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=billing_country&sort_dir=0&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Country' | $T8 %]</a>
+    [% END %]
+      </th>
+    <th>[% 'Shop Delivery Address' | $T8 %]</br>
+    [% IF FORM.sort_by == 'delivery_lastname' %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=delivery_lastname&sort_dir=[% 1 - FORM.sort_dir %]&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Name' | $T8 %][% IF FORM.sort_dir == 0 %]<img border="0" src="image/down.png">[% ELSE %]<img border="0" src="image/up.png">[% END %]</a>|
+    [% ELSE %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=delivery_lastname&sort_dir=0&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Name' | $T8 %]</a>|
+    [% END %]
+    [% IF FORM.sort_by == 'delivery_zipcode' %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=delivery_zipcode&sort_dir=[% 1 - FORM.sort_dir %]&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Zip' | $T8 %][% IF FORM.sort_dir == 0 %]<img border="0" src="image/down.png">[% ELSE %]<img border="0" src="image/up.png">[% END %]</a>|
+    [% ELSE %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=delivery_zipcode&sort_dir=0&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Zip' | $T8 %]</a>|
+    [% END %]
+    [% IF FORM.sort_by == 'delivery_country' %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=delivery_country&sort_dir=[% 1 - FORM.sort_dir %]&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Country' | $T8 %][% IF FORM.sort_dir == 0 %]<img border="0" src="image/down.png">[% ELSE %]<img border="0" src="image/up.png">[% END %]</a>
+    [% ELSE %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=delivery_country&sort_dir=0&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Country' | $T8 %]</a>
+    [% END %]
+      </th>
+    <th>[% IF FORM.sort_by == 'shop_customer_comment' %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=shop_customer_comment&sort_dir=[% 1 - FORM.sort_dir %]&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Notes' | $T8 %][% IF FORM.sort_dir == 0 %]<img border="0" src="image/down.png">[% ELSE %]<img border="0" src="image/up.png">[% END %]</a>
+    [% ELSE %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=shop_customer_comment&sort_dir=0&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Notes' | $T8 %]</a>
+    [% END %]
+    </th>
+    <th>
+      [% IF FORM.sort_by == 'positions' %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=positions&sort_dir=[% 1 - FORM.sort_dir %]&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Positions' | $T8 %][% IF FORM.sort_dir == 0 %]<img border="0" src="image/down.png">[% ELSE %]<img border="0" src="image/up.png">[% END %]</a><br>
+      [% ELSE %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=positions&sort_dir=0&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link"> [% 'Positions' | $T8 %]</a><br>
+      [% END %]
+      [% IF FORM.sort_by == 'amount' %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=amount&sort_dir=[% 1 - FORM.sort_dir %]&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Amount' | $T8 %][% IF FORM.sort_dir == 0 %]<img border="0" src="image/down.png">[% ELSE %]<img border="0" src="image/up.png">[% END %]</a><br>
+      [% ELSE %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=amount&sort_dir=0&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link"> [% 'Amount' | $T8 %]</a><br>
+      [% END %]
+      [% IF FORM.sort_by == 'shipping_costs' %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=shipping_costs&sort_dir=[% 1 - FORM.sort_dir %]&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link">
+        [% 'Shippingcosts' | $T8 %][% IF FORM.sort_dir == 0 %]<img border="0" src="image/down.png">[% ELSE %]<img border="0" src="image/up.png">[% END %]</a>
+      [% ELSE %]
+      <a href ="controller.pl?action=ShopOrder/list&filter.transferred:eq_ignore_empty=[% FORM.filter.transferred_eq_ignore_empty %]&sort_by=shipping_costs&sort_dir=0&filter.order_date:date::ge=[% FORM.filter.order_date_date__ge %]&filter.order_date:date::le=[% FORM.filter.order_date_date__le %]&filter.obsolete=[% FORM.filter.obsolete %]" class="sort_link"> [% 'Shippingcosts' | $T8 %]</a>
+      [% END %]
+    </th>
+    <th>[% 'Action' | $T8 %]<br>[% L.checkbox_tag('check_all') %]</th>
+   </tr>
+  </thead>
+ </form>
+ <form method="post" action="controller.pl" name="shop_orders_list" id="shoporderslist">
+  [% FOREACH shop_order = SHOPORDERS %]
+  [% # Dumper.dump_html(shop_order) %]
+    [% IF shop_order.kivi_customer.id && shop_order.kivi_customer.order_lock == 0 && shop_order.open_invoices == 0 %] [% SET transferable = 1 %] [% SET transferable_class = 'class="shop_transferable"' %] [% ELSE %] [% SET transferable = 0 %] [% SET transferable_class = '' %][% END %]
+  <tr class="listrow">
+    <td>[% HTML.escape(shop_order.shop.description) %]</td>
+    <td>[% shop_order.order_date.to_kivitendo('precision' => 'minute') %]<br>[% shop_order.itime.to_kivitendo('precision' => 'minute') %]</td>
+    <td>[% HTML.escape(shop_order.shop_ordernumber) %]</td>
+    <td>[% HTML.escape(shop_order.shop_customer_number) %]</td>
+    <td>[% IF shop_order.customer_company %]<b>[% HTML.escape(shop_order.customer_company) %]</b><br>[% END %]
+      <b>[% HTML.escape(shop_order.customer_lastname) %],&nbsp;[% HTML.escape(shop_order.customer_firstname) %]</b>
+      <br>[% HTML.escape(shop_order.customer_street) %]
+      <br>[% HTML.escape(shop_order.customer_zipcode) %]&nbsp;[% HTML.escape(shop_order.customer_city) %]
+      <br>[% HTML.escape(shop_order.customer_country) %] </td>
+    <td [% transferable_class %]>[% IF shop_order.customer_company %]<b>[% HTML.escape(shop_order.customer_company) %]</b><br>[% END %]
+      <b>[% HTML.escape(shop_order.billing_lastname) %],&nbsp;[% HTML.escape(shop_order.billing_firstname) %]</b>
+      <br>[% HTML.escape(shop_order.billing_street) %]
+      <br>[% HTML.escape(shop_order.billing_zipcode) %]&nbsp;[% HTML.escape(shop_order.billing_city) %]
+      <br>[% HTML.escape(shop_order.billing_country) %]
+      <br>[% IF shop_order.open_invoices > 0 || shop_order.customer.order_lock == 1 %][% SET alertclass = 'class="shop_alert"' %][% ELSE %][% SET alertclass = '' %][% END %]<span [% alertclass %]>&nbsp;&nbsp;[% 'Customernumber' | $T8 %] [% HTML.escape(shop_order.kivi_customer.customernumber) %] -- [% 'Invoices' | $T8 %] [% shop_order.open_invoices %]&nbsp;&nbsp;</span></td>
+    [% IF (shop_order.delivery_lastname != shop_order.billing_lastname || shop_order.delivery_firstname != shop_order.billing_firstname || shop_order.delivery_street != shop_order.billing_street || shop_order.delivery_city != shop_order.billing_city) %] [% SET deliveryclass = 'class="shop_delivery"' %] [% ELSE %] [% SET deliveryclass = '' %] [% END %]
+    <td [% deliveryclass %]>[% IF shop_order.customer_company %]<b>[% HTML.escape(shop_order.customer_company) %]</b><br>[% END %]
+      <b>[% HTML.escape(shop_order.delivery_lastname) %],&nbsp;[% HTML.escape(shop_order.delivery_firstname) %]</b>
+      <br>[% HTML.escape(shop_order.delivery_street) %]
+      <br>[% HTML.escape(shop_order.delivery_zipcode) %]&nbsp;[% HTML.escape(shop_order.delivery_city) %]
+      <br>[% HTML.escape(shop_order.delivery_country) %] </td>
+    <td>[% HTML.escape(shop_order.shop_customer_comment) %]</td>
+    <td><span class="tooltipster-html" title="[% FOREACH item = shop_order.shop_order_items %] [% LxERP.format_amount(item.quantity,0) %] x [% item.partnumber %] [% item.description %] <br> [% END %]">[% shop_order.positions %]<br>[% shop_order.amount_as_number %]<br>[% shop_order.shipping_costs_as_number %]</td><span>
+    <td valign="middle">[% IF shop_order.transferred == 1 %]<a href="controller.pl?id=[% shop_order.id %]&action=ShopOrder/show">[% 'Show order' | $T8 %]<br>[% shop_order.transferred_date_as_date %]</a>
+        [% ELSE %]
+          [% IF transferable == 1 && shop_order.obsolete == 0 %]
+            [% L.checkbox_tag('id[]', checked = '1',  value=shop_order.id) %]<br>
+          [% END %]
+          [% IF shop_order.obsolete == 0 %]<a href="controller.pl?id=[% shop_order.id %]&action=ShopOrder/show">[% 'Create order' | $T8 %]</a></br></br>
+          <a href="controller.pl?import_id=[% shop_order.id %]&action=ShopOrder/delete_order">[% 'Delete shoporder' | $T8 %]</a>
+          [% ELSE %]
+          [% 'Obsolete' | $T8 %]<br><br>
+            <a href="controller.pl?id=[% shop_order.id %]&action=ShopOrder/show">[% 'Show order' | $T8 %]
+          [% END %]
+    </td>
+        [% END %]
+  </tr>
+  [% END %]
+ </table>
+ <hr>
+  <div id="status_mass_transfer" style="display: none;">
+    [%- INCLUDE 'shop_order/_transfer_status.html' %]
+  </div>
+ </form>
+<script type="text/javascript">
+<!--
+
+$(function() {
+  $('#check_all').checkall('INPUT[name^="id"]');
+});
+-->
+</script>
diff --git a/templates/webpages/shop_order/show.html b/templates/webpages/shop_order/show.html
new file mode 100644 (file)
index 0000000..e9c22e5
--- /dev/null
@@ -0,0 +1,208 @@
+[%- USE HTML -%][%- USE LxERP -%][%- USE L -%][%- USE T8 -%]
+[% L.stylesheet_tag('webshop') %]
+[%- INCLUDE 'common/flash.html' %]
+<h1>[% title %]</h1>
+
+  <div class="shop_table shop_main">
+    <div class="shop_table-row">
+      <div class="shop_table-cell">
+      <form method="post" action="controller.pl" id="customer">[% L.hidden_tag('create_customer','customer') %][% L.hidden_tag('import_id', IMPORT.id) %]
+        <div class="shop_table shop_table_address">
+          <div class="shop_table-row listheading">
+            <div class="shop_table-cell">[% 'Shop Customer Address' | $T8 %]</div>
+            <div class="shop_table-cell"></div>
+          </div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Greeting' | $T8 %]</div><div class="shop_table-cell">[% HTML.escape(IMPORT.customer_greeting) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Firstname' | $T8 %]</div><div class="shop_table-cell">[% HTML.escape(IMPORT.customer_firstname) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Lastname' | $T8 %]</div><div class="shop_table-cell">[% HTML.escape(IMPORT.customer_lastname) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Company' | $T8 %]</div><div class="shop_table-cell">[% HTML.escape(IMPORT.customer_company) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Department' | $T8 %]</div><div class="shop_table-cell">[% HTML.escape(IMPORT.customer_department) %]</div></div>
+            [% SET customer = IMPORT.customer_firstname _ ' ' _ IMPORT.customer_lastname %]
+          <hr>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Greeting' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('customer_greeting', IMPORT.customer_greeting) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Customer' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('customer_name', customer) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Name 2' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('customer_company', IMPORT.customer_company) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Name 3' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('customer_department', IMPORT.customer_department) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Street' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('customer_street', IMPORT.customer_street) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Zipcode' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('customer_zipcode', IMPORT.customer_zipcode) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'City' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('customer_city', IMPORT.customer_city) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Country' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('customer_country', IMPORT.customer_country) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Phone' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('customer_phone', IMPORT.customer_phone) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Email' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('customer_email', IMPORT.customer_email) %]</div></div>
+          [% IF C_ADDRESS %]
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Customernumber' | $T8 %]</div><div class="shop_table-cell">[% C_ADDRESS.customernumber %]</div></div>
+          [% ELSE %]
+          <div>[% L.ajax_submit_tag("controller.pl?action=ShopOrder/apply_customer",  "#customer", LxERP.t8("Apply customer")) %]</div>
+          [% END %]
+        </div>
+      </form>
+      </div>
+      <div class="shop_table-cell">
+      <form method="post" action="controller.pl" id="billing">[% L.hidden_tag('create_customer','billing') %][% L.hidden_tag('import_id', IMPORT.id) %]
+        <div class="shop_table shop_table_address">
+          <div class="shop_table-row listheading">
+            <div class="shop_table-cell">[% 'Shop Billing Address' | $T8 %]</div>
+            <div class="shop_table-cell"></div>
+          </div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Greeting' | $T8 %]</div><div class="shop_table-cell">[% HTML.escape(IMPORT.billing_greeting) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Firstname' | $T8 %]</div><div class="shop_table-cell">[% HTML.escape(IMPORT.billing_firstname) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Lastname' | $T8 %]</div><div class="shop_table-cell">[% HTML.escape(IMPORT.billing_lastname) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Company' | $T8 %]</div><div class="shop_table-cell">[% HTML.escape(IMPORT.billing_company) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Department' | $T8 %]</div><div class="shop_table-cell">[% HTML.escape(IMPORT.billing_department) %]</div></div>
+            [% SET billing = IMPORT.billing_firstname _ ' ' _ IMPORT.billing_lastname %]
+          <hr>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Greeting' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('billing_greeting', IMPORT.billing_greeting) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Customer' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('billing_name', billing) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Name 2' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('billing_company', IMPORT.billing_company) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Name 3' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('billing_department', IMPORT.billing_department) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Street' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('billing_street', IMPORT.billing_street) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Zipcode' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('billing_zipcode', IMPORT.billing_zipcode) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'City' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('billing_city', IMPORT.billing_city) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Country' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('billing_country', IMPORT.billing_country) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Phone' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('billing_phone', IMPORT.billing_phone) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Email' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('billing_email', IMPORT.billing_email) %]</div></div>
+          [% IF B_ADDRESS %]
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Customernumber' | $T8 %]</div><div class="shop_table-cell">[% B_ADDRESS.customernumber %]</div></div>
+          [% ELSE %]
+          <div>[% L.ajax_submit_tag("controller.pl?action=ShopOrder/apply_customer",  "#billing", LxERP.t8("Apply customer")) %]</div>
+          [% END %]
+        </div>
+      </form>
+      </div>
+      <div class="shop_table-cell">
+      <form method="post" action="controller.pl" id="delivery">[% L.hidden_tag('create_customer','delivery') %][% L.hidden_tag('import_id', IMPORT.id) %]
+        <div class="shop_table shop_table_address">
+          <div class="shop_table-row listheading">
+            <div class="shop_table-cell">[% 'Shop Delivery Address' | $T8 %]</div>
+            <div class="shop_table-cell"></div>
+          </div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Greeting' | $T8 %]</div><div class="shop_table-cell">[% HTML.escape(IMPORT.delivery_greeting) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Firstname' | $T8 %]</div><div class="shop_table-cell">[% HTML.escape(IMPORT.delivery_firstname) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Lastname' | $T8 %]</div><div class="shop_table-cell">[% HTML.escape(IMPORT.delivery_lastname) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Company' | $T8 %]</div><div class="shop_table-cell">[% HTML.escape(IMPORT.delivery_company) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Department' | $T8 %]</div><div class="shop_table-cell">[% HTML.escape(IMPORT.delivery_department) %]</div></div>
+            [% SET delivery = IMPORT.delivery_firstname _ ' ' _ IMPORT.delivery_lastname %]
+          <hr>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Greeting' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('delivery_greeting', IMPORT.delivery_greeting) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Customer' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('delivery_name', delivery) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Name 2' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('delivery_company', IMPORT.delivery_company) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Name 3' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('delivery_department', IMPORT.delivery_department) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Street' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('delivery_street', IMPORT.delivery_street) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Zipcode' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('delivery_zipcode', IMPORT.delivery_zipcode) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'City' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('delivery_city', IMPORT.delivery_city) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Country' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('delivery_country', IMPORT.delivery_country) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Phone' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('delivery_phone', IMPORT.delivery_phone) %]</div></div>
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Email' | $T8 %]</div><div class="shop_table-cell">[% L.input_tag('delivery_email', IMPORT.delivery_email) %]</div></div>
+          [% IF D_ADDRESS %]
+          <div class="shop_table-row"><div class="shop_table-cell listheading">[% 'Customernumber' | $T8 %]</div><div class="shop_table-cell">[% D_ADDRESS.customernumber %]</div></div>
+          [% ELSE %]
+          <div>[% L.ajax_submit_tag("controller.pl?action=ShopOrder/apply_customer",  "#delivery", LxERP.t8("Apply customer")) %]</div>
+          [% END %]
+        </div>
+      </form>
+      </div>
+    </div>
+  </div>
+  <hr>
+  <table width="100%">
+    <tr>
+      <td width="35%">
+        <table>
+          <tr class="listheading">
+            <th colspan="2">[% 'Shop Headdata' | $T8 %]</th>
+          </tr>
+          <tr><td><b>[% 'Shop Ordernumber' | $T8 %]</b></td><td>[% HTML.escape(IMPORT.shop_ordernumber) %]</td></tr>
+          <tr><td><b>[% 'Shop Orderdate' | $T8 %]</b></td><td>[% HTML.escape(IMPORT.order_date.dmy('.')) _ ' ' _ HTML.escape(IMPORT.order_date.hms(':')) %]</td></tr>
+          <tr><td><b>[% 'Shop Host' | $T8 %]</b></td><td>[% HTML.escape(IMPORT.host) %]</td></tr>
+          <tr><td><b>[% 'Shop OrderIP' | $T8 %]</b></td><td>[% HTML.escape(IMPORT.remote_ip) %]</td></tr>
+          <tr><td><b>[% 'Shop Ordernotes' | $T8 %]</b></td><td>[% HTML.escape(IMPORT.shop_customer_comment) %]</td></tr>
+          <tr><td><b>[% 'Shop Orderamount' | $T8 %]</b></td><td>[% HTML.escape(IMPORT.amount_as_number) %]</td></tr>
+          <tr><td><b>[% 'Shipping costs' | $T8 %]</b></td><td>[% HTML.escape(IMPORT.shipping_costs_as_number) %]</td></tr>
+        </table>
+      </td>
+      <td style="padding-left: 20px; vertical-align: top;">
+        [% IF IMPORT.obsolete %]
+        <b>[% 'Shoporder deleted -- ' | $T8 %]</b><a href="controller.pl?action=ShopOrder/undelete_order&import_id=[% IMPORT.id %]">[% 'revert deleted' | $T8 %]</a>
+        [% ELSE %]
+        [% UNLESS IMPORT.transferred %]
+        [% IF PROPOSALS %]
+          <form method="post" action="controller.pl" id="create_order">
+            [% L.hidden_tag('import_id', IMPORT.id) %]
+            <div style="height: 125px; overflow:auto;">
+              <table>
+                <tr class="listheading">
+                  <th colspan="7">Customer Proposals</td>
+                </tr>
+                [% FOREACH prop = PROPOSALS %][% IF prop.order_lock %][% SET orderlock_class = 'style="background:rgba(232, 32, 23, 0.2);"' %][% ELSE %][% SET orderlock_class = '' %][% END %]
+                <tr class="listrow" [% orderlock_class %]>
+                  <td>[% IF !prop.order_lock %][% L.radio_button_tag('customer', value=prop.id) %][% END %]</td>
+                  <td><a href="controller.pl?action=CustomerVendor/edit&id=[% prop.id %]&db=customer&callback=[% HTML.url('controller.pl?action=ShopOrder/show&id=' _ IMPORT.id) %]">[% HTML.escape(prop.customernumber) %]</a></td>
+                  <td>[% IF !prop.notes == '' %]<span class="tooltipster-html" title="[% HTML.escape(prop.notes) %]"><span style="color:red;font-weight: bold;">[% HTML.escape(prop.name) %]</span>[% ELSE %][% HTML.escape(prop.name) %][% END %]</td>
+                  <td>[% HTML.escape(prop.street) %]</td>
+                  <td>[% HTML.escape(prop.zipcode) %]</td>
+                  <td>[% HTML.escape(prop.city) %]</td>
+                  <td>[% HTML.escape(prop.email) %]</td>
+                </tr>
+                [% END %]
+              </table>
+            </div>
+            <div id="transfer" style="float:left; display:none;">
+              [% # 'Customernumber: ' _ %]
+              [% L.ajax_submit_tag('controller.pl?action=ShopOrder/transfer', "#create_order", LxERP.t8('Create order')) %]
+            </div>
+            [% FOREACH prop = PROPOSALS %]
+            <div id="shop_update_customer_[% prop.id %]" class="div_hidden" style="display:none;">
+              [% L.ajax_submit_tag("controller.pl?action=ShopOrder/apply_customer&cv_id=" _ prop.id,  "#billing", LxERP.t8("Update customer using billing address")) %]
+            </div>
+            [% END %]
+          </form>
+        <a href="controller.pl?action=ShopOrder/delete_order&import_id=[% IMPORT.id %]">[% 'delete order' | $T8 %]</a>
+        [% END # PROPOSALS %]
+        [% ELSE %]
+        <div>
+          [% 'Transferred' | $T8 %]
+          <div id="recordlinks"></div>
+          <script type="text/javascript">
+            var url = 'controller.pl?action=RecordLinks/ajax_list&object_model=ShopOrder&object_id=[% IMPORT.id %]';
+            $('#recordlinks').load(url);
+          </script>
+        </div>
+        [% END %]
+        [% END %]
+      </td>
+    </tr>
+  </table>
+  <hr>
+  <div style="height: 250px; overflow:auto; margin:15px;">
+    <table width="99%">
+      <tr class="listheading">
+        <th>[% 'Position' | $T8 %]</th>
+        <th>[% 'Partnumber' | $T8 %]</th>
+        <th>[% 'Part Description' | $T8 %]</th>
+        <th>[% 'Qty' | $T8 %]</th>
+        <th>[% 'Price' | $T8 %]</th>
+        <th>[% 'Extended' | $T8 %]</th>
+      </tr>
+      [% FOREACH pos = IMPORT.shop_order_items %]
+      <tr class="listrow">
+        <td>[% count() %]</td>
+        <td>[% HTML.escape(pos.partnumber) %]</td>
+        <td>[% HTML.escape(pos.description) %]</td>
+        <td>[% pos.quantity_as_number%]</td>
+        <td>[% pos.price_as_number%]</td>
+        [% SET extended = pos.price * pos.quantity %]
+        <td>[% LxERP.format_amount(extended,2) %]</td>
+      </tr>
+      [% END %]
+    </table>
+  </div>
+  <hr>
+<script type="text/javascript">
+$("input[type=radio]").change(function(){
+      $('.div_hidden').css("display", 'none');
+      var cv_id = $("input[type=radio][id="+ this.id + "]").val();
+      $('#shop_update_customer_'+ cv_id).css("display", 'block');
+      $('#transfer').css("display", 'block');
+});
+</script>
+[% # L.dump(IMPORT) %]