Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 5c859d64

Von Bernd Bleßmann vor fast 7 Jahren hinzugefügt

  • ID 5c859d6455cd282a69bc354bd270efb87e1b8760
  • Vorgänger 4d20057d
  • Nachfolger c84371a6

Auftrags-Controller: Konfiguration wiederkehrender Rechnungen.

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);
7
use SL::Presenter::Tag qw(select_tag hidden_tag);
8 8
use SL::Locale::String qw(t8);
9 9
use SL::SessionFile::Random;
10 10
use SL::PriceSource;
......
25 25

  
26 26
use List::Util qw(first);
27 27
use List::UtilsBy qw(sort_by uniq_by);
28
use List::MoreUtils qw(none pairwise first_index);
28
use List::MoreUtils qw(any none pairwise first_index);
29 29
use English qw(-no_match_vars);
30 30
use File::Spec;
31 31
use Cwd;
......
348 348
      ->render($self);
349 349
}
350 350

  
351
# open the periodic invoices config dialog
352
#
353
# If there are values in the form (i.e. dialog was opened before),
354
# then use this values. Create new ones, else.
355
sub action_show_periodic_invoices_config_dialog {
356
  my ($self) = @_;
357

  
358
  my $config = _make_periodic_invoices_config_from_yaml(delete $::form->{config});
359
  $config  ||= SL::DB::Manager::PeriodicInvoicesConfig->find_by(oe_id => $::form->{id}) if $::form->{id};
360
  $config  ||= SL::DB::PeriodicInvoicesConfig->new(periodicity             => 'm',
361
                                                   order_value_periodicity => 'p', # = same as periodicity
362
                                                   start_date_as_date      => $::form->{transdate} || $::form->current_date,
363
                                                   extend_automatically_by => 12,
364
                                                   active                  => 1,
365
                                                   email_subject           => GenericTranslations->get(
366
                                                                                language_id      => $::form->{language_id},
367
                                                                                translation_type =>"preset_text_periodic_invoices_email_subject"),
368
                                                   email_body              => GenericTranslations->get(
369
                                                                                language_id      => $::form->{language_id},
370
                                                                                translation_type =>"preset_text_periodic_invoices_email_body"),
371
  );
372
  $config->periodicity('m')             if none { $_ eq $config->periodicity             }       @SL::DB::PeriodicInvoicesConfig::PERIODICITIES;
373
  $config->order_value_periodicity('p') if none { $_ eq $config->order_value_periodicity } ('p', @SL::DB::PeriodicInvoicesConfig::ORDER_VALUE_PERIODICITIES);
374

  
375
  $::form->get_lists(printers => "ALL_PRINTERS",
376
                     charts   => { key       => 'ALL_CHARTS',
377
                                   transdate => 'current_date' });
378

  
379
  $::form->{AR} = [ grep { $_->{link} =~ m/(?:^|:)AR(?::|$)/ } @{ $::form->{ALL_CHARTS} } ];
380

  
381
  if ($::form->{customer_id}) {
382
    $::form->{ALL_CONTACTS} = SL::DB::Manager::Contact->get_all_sorted(where => [ cp_cv_id => $::form->{customer_id} ]);
383
  }
384

  
385
  $self->render('oe/edit_periodic_invoices_config', { layout => 0 },
386
                popup_dialog             => 1,
387
                popup_js_close_function  => 'kivi.Order.close_periodic_invoices_config_dialog()',
388
                popup_js_assign_function => 'kivi.Order.assign_periodic_invoices_config()',
389
                config                   => $config,
390
                %$::form);
391
}
392

  
393
# assign the values of the periodic invoices config dialog
394
# as yaml in the hidden tag and set the status.
395
sub action_assign_periodic_invoices_config {
396
  my ($self) = @_;
397

  
398
  $::form->isblank('start_date_as_date', $::locale->text('The start date is missing.'));
399

  
400
  my $config = { active                  => $::form->{active}     ? 1 : 0,
401
                 terminated              => $::form->{terminated} ? 1 : 0,
402
                 direct_debit            => $::form->{direct_debit} ? 1 : 0,
403
                 periodicity             => (any { $_ eq $::form->{periodicity}             }       @SL::DB::PeriodicInvoicesConfig::PERIODICITIES)              ? $::form->{periodicity}             : 'm',
404
                 order_value_periodicity => (any { $_ eq $::form->{order_value_periodicity} } ('p', @SL::DB::PeriodicInvoicesConfig::ORDER_VALUE_PERIODICITIES)) ? $::form->{order_value_periodicity} : 'p',
405
                 start_date_as_date      => $::form->{start_date_as_date},
406
                 end_date_as_date        => $::form->{end_date_as_date},
407
                 first_billing_date_as_date => $::form->{first_billing_date_as_date},
408
                 print                   => $::form->{print} ? 1 : 0,
409
                 printer_id              => $::form->{print} ? $::form->{printer_id} * 1 : undef,
410
                 copies                  => $::form->{copies} * 1 ? $::form->{copies} : 1,
411
                 extend_automatically_by => $::form->{extend_automatically_by} * 1 || undef,
412
                 ar_chart_id             => $::form->{ar_chart_id} * 1,
413
                 send_email                 => $::form->{send_email} ? 1 : 0,
414
                 email_recipient_contact_id => $::form->{email_recipient_contact_id} * 1 || undef,
415
                 email_recipient_address    => $::form->{email_recipient_address},
416
                 email_sender               => $::form->{email_sender},
417
                 email_subject              => $::form->{email_subject},
418
                 email_body                 => $::form->{email_body},
419
               };
420

  
421
  my $periodic_invoices_config = YAML::Dump($config);
422

  
423
  my $status = $self->_get_periodic_invoices_status($config);
424

  
425
  $self->js
426
    ->remove('#order_periodic_invoices_config')
427
    ->insertAfter(hidden_tag('order.periodic_invoices_config', $periodic_invoices_config), '#periodic_invoices_status')
428
    ->run('kivi.Order.close_periodic_invoices_config_dialog')
429
    ->html('#periodic_invoices_status', $status)
430
    ->flash('info', t8('The periodic invoices config has been assigned.'))
431
    ->render($self);
432
}
433

  
434
sub action_get_has_active_periodic_invoices {
435
  my ($self) = @_;
436

  
437
  my $config = _make_periodic_invoices_config_from_yaml(delete $::form->{config});
438
  $config  ||= SL::DB::Manager::PeriodicInvoicesConfig->find_by(oe_id => $::form->{id}) if $::form->{id};
439

  
440
  my $has_active_periodic_invoices =
441
       $self->type eq _sales_order_type()
442
    && $config
443
    && $config->active
444
    && (!$config->end_date || ($config->end_date > DateTime->today_local))
445
    && $config->get_previous_billed_period_start_date;
446

  
447
  $_[0]->render(\ !!$has_active_periodic_invoices, { type => 'text' });
448
}
449

  
351 450
# save the order and redirect to the frontend subroutine for a new
352 451
# delivery order
353 452
sub action_save_and_delivery_order {
......
896 995

  
897 996
# load or create a new order object
898 997
#
899
# And assign changes from the for to this object.
998
# And assign changes from the form to this object.
900 999
# If the order is loaded from db, check if items are deleted in the form,
901 1000
# remove them form the object and collect them for removing from db on saving.
902 1001
# Then create/update items from form (via _make_item) and add them.
......
910 1009
  $order   = SL::DB::Manager::Order->find_by(id => $::form->{id}) if $::form->{id};
911 1010
  $order ||= SL::DB::Order->new(orderitems => []);
912 1011

  
913
  my $form_orderitems = delete $::form->{order}->{orderitems};
1012
  my $form_orderitems               = delete $::form->{order}->{orderitems};
1013
  my $form_periodic_invoices_config = delete $::form->{order}->{periodic_invoices_config};
1014

  
914 1015
  $order->assign_attributes(%{$::form->{order}});
915 1016

  
1017
  my $periodic_invoices_config = _make_periodic_invoices_config_from_yaml($form_periodic_invoices_config);
1018
  $order->periodic_invoices_config($periodic_invoices_config) if $periodic_invoices_config;
1019

  
916 1020
  # remove deleted items
917 1021
  $self->item_ids_to_delete([]);
918 1022
  foreach my $idx (reverse 0..$#{$order->orderitems}) {
......
1106 1210
sub _pre_render {
1107 1211
  my ($self) = @_;
1108 1212

  
1109
  $self->{all_taxzones}        = SL::DB::Manager::TaxZone->get_all_sorted();
1110
  $self->{all_departments}     = SL::DB::Manager::Department->get_all_sorted();
1111
  $self->{all_employees}       = SL::DB::Manager::Employee->get_all(where => [ or => [ id => $self->order->employee_id,
1112
                                                                                       deleted => 0 ] ],
1113
                                                                    sort_by => 'name');
1114
  $self->{all_salesmen}        = SL::DB::Manager::Employee->get_all(where => [ or => [ id => $self->order->salesman_id,
1115
                                                                                       deleted => 0 ] ],
1116
                                                                    sort_by => 'name');
1117
  $self->{all_projects}        = SL::DB::Manager::Project->get_all(where => [ or => [ id => $self->order->globalproject_id,
1118
                                                                                      active => 1 ] ],
1119
                                                                   sort_by => 'projectnumber');
1120
  $self->{all_payment_terms}   = SL::DB::Manager::PaymentTerm->get_all_sorted(where => [ or => [ id => $self->order->payment_id,
1121
                                                                                                 obsolete => 0 ] ]);
1122

  
1123
  $self->{all_delivery_terms}  = SL::DB::Manager::DeliveryTerm->get_all_sorted();
1124

  
1125
  $self->{current_employee_id} = SL::DB::Manager::Employee->current->id;
1213
  $self->{all_taxzones}             = SL::DB::Manager::TaxZone->get_all_sorted();
1214
  $self->{all_departments}          = SL::DB::Manager::Department->get_all_sorted();
1215
  $self->{all_employees}            = SL::DB::Manager::Employee->get_all(where => [ or => [ id => $self->order->employee_id,
1216
                                                                                            deleted => 0 ] ],
1217
                                                                         sort_by => 'name');
1218
  $self->{all_salesmen}             = SL::DB::Manager::Employee->get_all(where => [ or => [ id => $self->order->salesman_id,
1219
                                                                                            deleted => 0 ] ],
1220
                                                                         sort_by => 'name');
1221
  $self->{all_projects}             = SL::DB::Manager::Project->get_all(where => [ or => [ id => $self->order->globalproject_id,
1222
                                                                                           active => 1 ] ],
1223
                                                                        sort_by => 'projectnumber');
1224
  $self->{all_payment_terms}        = SL::DB::Manager::PaymentTerm->get_all_sorted(where => [ or => [ id => $self->order->payment_id,
1225
                                                                                                      obsolete => 0 ] ]);
1226
  $self->{all_delivery_terms}       = SL::DB::Manager::DeliveryTerm->get_all_sorted();
1227
  $self->{current_employee_id}      = SL::DB::Manager::Employee->current->id;
1228
  $self->{periodic_invoices_status} = $self->_get_periodic_invoices_status($self->order->periodic_invoices_config);
1126 1229

  
1127 1230
  my $print_form = Form->new('');
1128 1231
  $print_form->{type}      = $self->type;
......
1156 1259
                                                } } @all_objects;
1157 1260
  }
1158 1261

  
1159
  $::request->{layout}->use_javascript("${_}.js")  for qw(kivi.SalesPurchase kivi.Order kivi.File ckeditor/ckeditor ckeditor/adapters/jquery);
1262
  $::request->{layout}->use_javascript("${_}.js") for qw(kivi.SalesPurchase kivi.Order kivi.File ckeditor/ckeditor ckeditor/adapters/jquery edit_periodic_invoices_config);
1160 1263
  $self->_setup_edit_action_bar;
1161 1264
}
1162 1265

  
......
1172 1275
        action => [
1173 1276
          t8('Save'),
1174 1277
          call      => [ 'kivi.Order.save', $::instance_conf->get_order_warn_duplicate_parts ],
1278
          checks    => [ 'kivi.Order.check_save_active_periodic_invoices' ],
1175 1279
          accesskey => 'enter',
1176 1280
        ],
1177 1281
        action => [
1178 1282
          t8('Save and Delivery Order'),
1179 1283
          call      => [ 'kivi.Order.save_and_delivery_order', $::instance_conf->get_order_warn_duplicate_parts ],
1284
          checks    => [ 'kivi.Order.check_save_active_periodic_invoices' ],
1180 1285
        ],
1181 1286
        action => [
1182 1287
          t8('Save and Invoice'),
1183 1288
          call      => [ 'kivi.Order.save_and_invoice', $::instance_conf->get_order_warn_duplicate_parts ],
1289
          checks    => [ 'kivi.Order.check_save_active_periodic_invoices' ],
1184 1290
        ],
1185 1291

  
1186 1292
      ], # end of combobox "Save"
......
1298 1404
  return %files;
1299 1405
}
1300 1406

  
1407
sub _make_periodic_invoices_config_from_yaml {
1408
  my ($yaml_config) = @_;
1409

  
1410
  return if !$yaml_config;
1411
  my $attr = YAML::Load($yaml_config);
1412
  return if 'HASH' ne ref $attr;
1413
  return SL::DB::PeriodicInvoicesConfig->new(%$attr);
1414
}
1415

  
1416

  
1417
sub _get_periodic_invoices_status {
1418
  my ($self, $config) = @_;
1419

  
1420
  return                      if $self->type ne _sales_order_type();
1421
  return t8('not configured') if !$config;
1422

  
1423
  my $active = ('HASH' eq ref $config)                           ? $config->{active}
1424
             : ('SL::DB::PeriodicInvoicesConfig' eq ref $config) ? $config->active
1425
             :                                                     die "Cannot get status of periodic invoices config";
1426

  
1427
  return $active ? t8('active') : t8('inactive');
1428
}
1429

  
1301 1430
sub _sales_order_type {
1302 1431
  'sales_order';
1303 1432
}
......
1443 1572

  
1444 1573
=item * custom shipto address
1445 1574

  
1446
=item * periodic invoices
1447

  
1448 1575
=item * language / part translations
1449 1576

  
1450 1577
=item * access rights
js/kivi.Order.js
546 546
    kivi.io.close_dialog();
547 547
  };
548 548

  
549
  ns.show_periodic_invoices_config_dialog = function() {
550
    if ($('#type').val() !== 'sales_order') return;
551

  
552
    kivi.popup_dialog({
553
      url: 'controller.pl?action=Order/show_periodic_invoices_config_dialog',
554
      data: { type       : $('#type').val(),
555
              id         : $('#id').val(),
556
              config     : $('#order_periodic_invoices_config').val(),
557
              customer_id: $('#order_customer_id').val(),
558
              transdate  : $('#order_transdate').val(),
559
              language_id: $('#language_id').val()
560
            },
561
      id: 'jq_periodic_invoices_config_dialog',
562
      load: kivi.reinit_widgets,
563
      dialog: {
564
        title: kivi.t8('Edit the configuration for periodic invoices'),
565
        width:  800,
566
        height: 650
567
      }
568
    });
569
    return true;
570
  };
571

  
572
  ns.close_periodic_invoices_config_dialog = function() {
573
    $('#jq_periodic_invoices_config_dialog').dialog('close');
574
  };
575

  
576
  ns.assign_periodic_invoices_config = function() {
577
    var data = $('[name="Form"]').serializeArray();
578
    data.push({ name: 'type',   value: $('#type').val() });
579
    data.push({ name: 'action', value: 'Order/assign_periodic_invoices_config' });
580
    $.post("controller.pl", data, kivi.eval_json_result);
581
  };
582

  
583
  ns.check_save_active_periodic_invoices = function() {
584
    var type = $('#type').val();
585
    if (type !== 'sales_order') return true;
586

  
587
    var active = false;
588
    $.ajax({
589
      url: 'controller.pl',
590
      data: { action: 'Order/get_has_active_periodic_invoices',
591
              type  : type,
592
              id    : $('#id').val(),
593
              config: $('#order_periodic_invoices_config').val(),
594
      },
595
      method: "GET",
596
      async: false,
597
      dataType: 'text',
598
      success: function(val){
599
        active = val;
600
      }
601
    });
602

  
603
    if (active == 1) {
604
      return confirm(kivi.t8('This sales order has an active configuration for periodic invoices. If you save then all subsequently created invoices will contain those changes as well, but not those that have already been created. Do you want to continue?'));
605
    }
606

  
607
    return true;
608
  };
609

  
549 610
});
550 611

  
551 612
$(function(){
js/locale/de.js
54 54
"Edit picture":"Bild bearbeiten",
55 55
"Edit project link":"Projektverknüpfung bearbeiten",
56 56
"Edit text block":"Textblock bearbeiten",
57
"Edit the configuration for periodic invoices":"Konfiguration für wiederkehrende Rechnungen bearbeiten",
57 58
"Enter longdescription":"Langtext eingeben",
58 59
"Error: Name missing":"Fehler: Name fehlt",
59 60
"File upload":"Datei Upload",
locale/de/all
3283 3283
  'The payment term has been saved.' => 'Die Zahlungsbedingungen wurden gespeichert.',
3284 3284
  'The payment term is in use and cannot be deleted.' => 'Die Zahlungsbedingungen werden bereits benutzt und können nicht gelöscht werden.',
3285 3285
  'The payments have been posted.' => 'Die Zahlungen wurden gebucht.',
3286
  'The periodic invoices config has been assigned.' => 'Die Konfiguration für wiederkehrende Rechnungen wurde übernommen.',
3286 3287
  'The port is missing.'        => 'Port fehlt',
3287 3288
  'The preferred one is to install packages provided by your operating system distribution (e.g. Debian or RPM packages).' => 'Die bevorzugte Art, ein Perl-Modul zu installieren, ist durch Installation eines von Ihrem Betriebssystem zur Verfügung gestellten Paketes (z.B. Debian-Pakete oder RPM).',
3288 3289
  'The price rule for this discount does not exist anymore' => 'Die Preisregel für diesen Rabatt existiert nicht mehr',
templates/webpages/order/tabs/basic_data.html
233 233
                                      title_key = 'description',
234 234
                                      style = 'width: 250px') %]</td>
235 235
                </tr>
236
                [%- IF SELF.type == "sales_order" %]
237
                <tr>
238
                  <th align="right">[%- 'Periodic Invoices' | T8 %]</th>
239
                  <td>[% L.button_tag('kivi.Order.show_periodic_invoices_config_dialog()', LxERP.t8('Configure')) %]
240
                    (<span id='periodic_invoices_status'>[%- SELF.periodic_invoices_status -%]</span>)
241
                    <a href="doc/html/ch03.html#features.periodic-invoices.variables" target="_blank">?</a>
242
                  </td>
243
                </tr>
244
                [%- END %]
236 245
              </table>
237 246
            </td>
238 247

  

Auch abrufbar als: Unified diff