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

Auch abrufbar als: Unified diff