Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 199bd497

Von Bernd Bleßmann vor mehr als 3 Jahren hinzugefügt

  • ID 199bd497fa158b819070767fa737b2e23d164b96
  • Vorgänger 7cad87f8
  • Nachfolger 330df4c5

Auftrags-Controller: individuelle Lieferadresse

Behebt #365 (redmine)

Unterschiede anzeigen:

SL/Controller/Order.pm
4 4
use parent qw(SL::Controller::Base);
5 5

  
6 6
use SL::Helper::Flash qw(flash_later);
7
use SL::Presenter::Tag qw(select_tag hidden_tag);
7
use SL::Presenter::Tag qw(select_tag hidden_tag div_tag);
8 8
use SL::Locale::String qw(t8);
9 9
use SL::SessionFile::Random;
10 10
use SL::PriceSource;
......
21 21
use SL::DB::Printer;
22 22
use SL::DB::Language;
23 23
use SL::DB::RecordLink;
24
use SL::DB::Shipto;
24 25

  
25 26
use SL::Helper::CreatePDF qw(:all);
26 27
use SL::Helper::PrintOptions;
......
40 41

  
41 42
use Rose::Object::MakeMethods::Generic
42 43
(
43
 scalar => [ qw(item_ids_to_delete) ],
44
 scalar => [ qw(item_ids_to_delete is_custom_shipto_to_delete) ],
44 45
 'scalar --get_set_init' => [ qw(order valid_types type cv p multi_items_models all_price_factors search_cvpartnumber show_update_button) ],
45 46
);
46 47

  
......
676 677
  }
677 678

  
678 679
  if ($self->order->$cv_method->shipto && scalar @{ $self->order->$cv_method->shipto } > 0) {
679
    $self->js->show('#shipto_row');
680
    $self->js->show('#shipto_selection');
680 681
  } else {
681
    $self->js->hide('#shipto_row');
682
    $self->js->hide('#shipto_selection');
682 683
  }
683 684

  
684 685
  $self->js->val( '#order_salesman_id',      $self->order->salesman_id)        if $self->order->is_sales;
......
686 687
  $self->js
687 688
    ->replaceWith('#order_cp_id',            $self->build_contact_select)
688 689
    ->replaceWith('#order_shipto_id',        $self->build_shipto_select)
690
    ->replaceWith('#shipto_inputs  ',        $self->build_shipto_inputs)
689 691
    ->replaceWith('#business_info_row',      $self->build_business_info_row)
690 692
    ->val(        '#order_taxzone_id',       $self->order->taxzone_id)
691 693
    ->val(        '#order_taxincluded',      $self->order->taxincluded)
......
1291 1293
sub build_shipto_select {
1292 1294
  my ($self) = @_;
1293 1295

  
1294
  select_tag('order.shipto_id', [ $self->order->{$self->cv}->shipto ],
1295
    value_key  => 'shipto_id',
1296
    title_key  => 'displayable_id',
1297
    default    => $self->order->shipto_id,
1298
    with_empty => 1,
1299
    style      => 'width: 300px',
1296
  select_tag('order.shipto_id',
1297
             [ {displayable_id => t8("No/individual shipping address"), shipto_id => ''}, $self->order->{$self->cv}->shipto ],
1298
             value_key  => 'shipto_id',
1299
             title_key  => 'displayable_id',
1300
             default    => $self->order->shipto_id,
1301
             with_empty => 0,
1302
             style      => 'width: 300px',
1300 1303
  );
1301 1304
}
1302 1305

  
1306
# build the inputs for the cusom shipto dialog
1307
#
1308
# Needed, if customer/vendor changed.
1309
sub build_shipto_inputs {
1310
  my ($self) = @_;
1311

  
1312
  my $content = $self->p->render('common/_ship_to_dialog',
1313
                                 vc_obj      => $self->order->customervendor,
1314
                                 cs_obj      => $self->order->custom_shipto,
1315
                                 cvars       => $self->order->custom_shipto->cvars_by_config,
1316
                                 id_selector => '#order_shipto_id');
1317

  
1318
  div_tag($content, id => 'shipto_inputs');
1319
}
1320

  
1303 1321
# render the info line for business
1304 1322
#
1305 1323
# Needed, if customer/vendor changed.
......
1349 1367
  return if !$::form->{id};
1350 1368

  
1351 1369
  $self->order(SL::DB::Order->new(id => $::form->{id})->load);
1370

  
1371
  # Add an empty custom shipto to the order, so that the dialog can render the cvar inputs.
1372
  # You need a custom shipto object to call cvars_by_config to get the cvars.
1373
  $self->order->custom_shipto(SL::DB::Shipto->new(module => 'OE', custom_variables => [])) if !$self->order->custom_shipto;
1374

  
1375
  return $self->order;
1352 1376
}
1353 1377

  
1354 1378
# load or create a new order object
......
1367 1391
  $order   = SL::DB::Order->new(id => $::form->{id})->load(with => [ 'orderitems', 'orderitems.part' ]) if $::form->{id};
1368 1392
  $order ||= SL::DB::Order->new(orderitems  => [],
1369 1393
                                quotation   => (any { $self->type eq $_ } (sales_quotation_type(), request_quotation_type())),
1370
                                currency_id => $::instance_conf->get_currency_id());
1394
                                currency_id => $::instance_conf->get_currency_id(),);
1371 1395

  
1372 1396
  my $cv_id_method = $self->cv . '_id';
1373 1397
  if (!$::form->{id} && $::form->{$cv_id_method}) {
......
1380 1404

  
1381 1405
  $order->assign_attributes(%{$::form->{order}});
1382 1406

  
1407
  $self->setup_custom_shipto_from_form($order, $::form);
1408

  
1383 1409
  if (my $periodic_invoices_config_attrs = $form_periodic_invoices_config ? SL::YAML::Load($form_periodic_invoices_config) : undef) {
1384 1410
    my $periodic_invoices_config = $order->periodic_invoices_config || $order->periodic_invoices_config(SL::DB::PeriodicInvoicesConfig->new);
1385 1411
    $periodic_invoices_config->assign_attributes(%$periodic_invoices_config_attrs);
......
1521 1547

  
1522 1548
}
1523 1549

  
1550
# setup custom shipto from form
1551
#
1552
# The dialog returns form variables starting with 'shipto' and cvars starting
1553
# with 'shiptocvar_'.
1554
# Mark it to be deleted if a shipto from master data is selected
1555
# (i.e. order has a shipto).
1556
# Else, update or create a new custom shipto. If the fields are empty, it
1557
# will not be saved on save.
1558
sub setup_custom_shipto_from_form {
1559
  my ($self, $order, $form) = @_;
1560

  
1561
  if ($order->shipto) {
1562
    $self->is_custom_shipto_to_delete(1);
1563
  } else {
1564
    my $custom_shipto = $order->custom_shipto || $order->custom_shipto(SL::DB::Shipto->new(module => 'OE', custom_variables => []));
1565

  
1566
    my $shipto_cvars  = {map { my ($key) = m{^shiptocvar_(.+)}; $key => delete $form->{$_}} grep { m{^shiptocvar_} } keys %$form};
1567
    my $shipto_attrs  = {map {                                  $_   => delete $form->{$_}} grep { m{^shipto}      } keys %$form};
1568

  
1569
    $custom_shipto->assign_attributes(%$shipto_attrs);
1570
    $custom_shipto->cvar_by_name($_)->value($shipto_cvars->{$_}) for keys %$shipto_cvars;
1571
  }
1572
}
1573

  
1524 1574
# recalculate prices and taxes
1525 1575
#
1526 1576
# Using the PriceTaxCalculator. Store linetotals in the item objects.
......
1588 1638
  my $db     = $self->order->db;
1589 1639

  
1590 1640
  $db->with_transaction(sub {
1641
    # delete custom shipto if it is to be deleted or if it is empty
1642
    if ($self->order->custom_shipto && ($self->is_custom_shipto_to_delete || $self->order->custom_shipto->is_empty)) {
1643
      $self->order->custom_shipto->delete if $self->order->custom_shipto->shipto_id;
1644
      $self->order->custom_shipto(undef);
1645
    }
1646

  
1591 1647
    SL::DB::OrderItem->new(id => $_)->delete for @{$self->item_ids_to_delete || []};
1592 1648
    $self->order->save(cascade => 1);
1593 1649

  
......
2132 2188

  
2133 2189
=item * select units in input row?
2134 2190

  
2135
=item * custom shipto address
2136

  
2137 2191
=item * check for direct delivery (workflow sales order -> purchase order)
2138 2192

  
2139 2193
=item * language / part translations
bin/mozilla/io.pl
944 944

  
945 945
    require SL::Controller::Order;
946 946
    my $c = SL::Controller::Order->new(order => $order);
947
    $c->setup_custom_shipto_from_form($order, $::form);
947 948
    $c->action_edit();
948 949

  
949 950
    $main::lxdebug->leave_sub();
js/kivi.Order.js
164 164
  };
165 165

  
166 166
  ns.reload_cv_dependent_selections = function() {
167
    $('#order_shipto_id').val('');
167 168
    var data = $('#order_form').serializeArray();
168 169
    data.push({ name: 'action', value: 'Order/customer_vendor_changed' });
169 170

  
......
845 846
    return true;
846 847
  };
847 848

  
849
  ns.edit_custom_shipto = function() {
850
    if (!ns.check_cv()) return;
851

  
852
    kivi.SalesPurchase.edit_custom_shipto();
853
  };
854

  
848 855
});
849 856

  
850 857
$(function() {
js/kivi.SalesPurchase.js
170 170
    $('#shiptoname').focus();
171 171
  };
172 172

  
173
  this.submit_custom_shipto = function() {
174
    $('#shipto_id').val('');
173
  this.submit_custom_shipto = function(id_selector) {
174
    id_selector = id_selector || '#shipto_id';
175
    $(id_selector).val('');
175 176
    $('#shipto_dialog').data('confirmed', true);
176 177
    $('#shipto_dialog').dialog('close');
177 178
  };
templates/webpages/common/_ship_to_dialog.html
57 57
 [% L.button_tag("kivi.SalesPurchase.copy_shipto_address()", LxERP.t8("Copy")) %]
58 58
</p>
59 59

  
60
[% IF cs_obj ;
61
  fields = ['shiptoname', 'shiptodepartment_1', 'shiptodepartment_2',
62
            'shiptostreet', 'shiptozipcode', 'shiptocity', 'shiptocountry',
63
            'shiptogln', 'shiptocontact', 'shiptocp_gender', 'shiptophone',
64
            'shiptofax', 'shiptoemail'] ;
65
  FOREACH field = fields ;
66
      $field = cs_obj.$field ;
67
  END ;
68
END ;
69
'' %]
70

  
71

  
60 72
<table>
61 73
 <tr class="listheading">
62 74
  <th></th>
......
145 157
</table>
146 158

  
147 159
<p>
148
 [% L.button_tag("kivi.SalesPurchase.submit_custom_shipto()", LxERP.t8("Apply")) %]
160
 [% L.button_tag("kivi.SalesPurchase.submit_custom_shipto('" _ id_selector _ "')", LxERP.t8("Apply")) %]
149 161
 [% L.button_tag("kivi.SalesPurchase.reset_shipto_fields()", LxERP.t8("Reset")) %]
150 162
 [% L.button_tag("kivi.SalesPurchase.clear_shipto_fields()", LxERP.t8("Clear fields")) %]
151 163
 [% L.button_tag("\$('#shipto_dialog').dialog('close');", LxERP.t8("Abort")) %]
templates/webpages/order/form.html
13 13
  </form>
14 14
</div>
15 15

  
16
<div id="shipto_dialog" class="hidden"></div>
17

  
16 18
<form method="post" action="controller.pl" id="order_form">
17 19
  [% L.hidden_tag('callback',             FORM.callback) %]
18 20
  [% L.hidden_tag('type',                 FORM.type) %]
......
41 43
    <div id="ui-tabs-1">
42 44
      [%- LxERP.t8("Loading...") %]
43 45
    </div>
46

  
47
    <div id="shipto_inputs" class="hidden">
48
      [%- PROCESS 'common/_ship_to_dialog.html'
49
        vc_obj=SELF.order.customervendor
50
        cs_obj=SELF.order.custom_shipto
51
        cvars=SELF.order.custom_shipto.cvars_by_config
52
        id_selector='#order_shipto_id' %]
53
    </div>
54

  
44 55
  </div>
56

  
45 57
</form>
templates/webpages/order/tabs/basic_data.html
31 31
                                style='width: 300px') %]</td>
32 32
          </tr>
33 33

  
34
          <tr id='shipto_row' [%- IF !SELF.order.${SELF.cv}.shipto.size %]style='display:none'[%- END %]>
34
          <tr>
35 35
            <th align="right">[% 'Shipping Address' | $T8 %]</th>
36
            <td>[% L.select_tag('order.shipto_id',
37
                                SELF.order.${SELF.cv}.shipto,
38
                                default=SELF.order.shipto_id,
39
                                title_key='displayable_id',
40
                                value_key='shipto_id',
41
                                with_empty=1,
42
                                style='width: 300px') %]</td>
36
            <td>
37
              <span id='shipto_selection' [%- IF !SELF.order.${SELF.cv}.shipto.size %]style='display:none'[%- END %]>
38
                [% shiptos = [ { shipto_id => "", displayable_id => LxERP.t8("No/individual shipping address") } ] ;
39
                   L.select_tag('order.shipto_id',
40
                                 shiptos.import(SELF.order.${SELF.cv}.shipto),
41
                                 default=SELF.order.shipto_id,
42
                                 title_key='displayable_id',
43
                                 value_key='shipto_id',
44
                                 with_empty=0,
45
                                 style='width: 300px') %]
46
              </span>
47
              [% L.button_tag("kivi.Order.edit_custom_shipto()", LxERP.t8("Custom shipto")) %]
48
            </td>
43 49
          </tr>
44 50

  
45 51
          [%- PROCESS order/tabs/_business_info_row.html SELF=SELF %]

Auch abrufbar als: Unified diff