520 |
520 |
$self->redirect_to(@redirect_params);
|
521 |
521 |
}
|
522 |
522 |
|
523 |
|
# open the periodic invoices config dialog
|
524 |
|
#
|
525 |
|
# If there are values in the form (i.e. dialog was opened before),
|
526 |
|
# then use this values. Create new ones, else.
|
527 |
|
sub action_show_periodic_invoices_config_dialog {
|
528 |
|
my ($self) = @_;
|
529 |
|
|
530 |
|
my $config = make_periodic_invoices_config_from_yaml(delete $::form->{config});
|
531 |
|
$config ||= SL::DB::Manager::PeriodicInvoicesConfig->find_by(oe_id => $::form->{id}) if $::form->{id};
|
532 |
|
$config ||= SL::DB::PeriodicInvoicesConfig->new(periodicity => 'm',
|
533 |
|
order_value_periodicity => 'p', # = same as periodicity
|
534 |
|
start_date_as_date => $::form->{transdate_as_date} || $::form->current_date,
|
535 |
|
extend_automatically_by => 12,
|
536 |
|
active => 1,
|
537 |
|
email_subject => GenericTranslations->get(
|
538 |
|
language_id => $::form->{language_id},
|
539 |
|
translation_type =>"preset_text_periodic_invoices_email_subject"),
|
540 |
|
email_body => GenericTranslations->get(
|
541 |
|
language_id => $::form->{language_id},
|
542 |
|
translation_type =>"preset_text_periodic_invoices_email_body"),
|
543 |
|
);
|
544 |
|
$config->periodicity('m') if none { $_ eq $config->periodicity } @SL::DB::PeriodicInvoicesConfig::PERIODICITIES;
|
545 |
|
$config->order_value_periodicity('p') if none { $_ eq $config->order_value_periodicity } ('p', @SL::DB::PeriodicInvoicesConfig::ORDER_VALUE_PERIODICITIES);
|
546 |
|
|
547 |
|
$::form->get_lists(printers => "ALL_PRINTERS",
|
548 |
|
charts => { key => 'ALL_CHARTS',
|
549 |
|
transdate => 'current_date' });
|
550 |
|
|
551 |
|
$::form->{AR} = [ grep { $_->{link} =~ m/(?:^|:)AR(?::|$)/ } @{ $::form->{ALL_CHARTS} } ];
|
552 |
|
|
553 |
|
if ($::form->{customer_id}) {
|
554 |
|
$::form->{ALL_CONTACTS} = SL::DB::Manager::Contact->get_all_sorted(where => [ cp_cv_id => $::form->{customer_id} ]);
|
555 |
|
my $customer_object = SL::DB::Manager::Customer->find_by(id => $::form->{customer_id});
|
556 |
|
$::form->{postal_invoice} = $customer_object->postal_invoice;
|
557 |
|
$::form->{email_recipient_invoice_address} = $::form->{postal_invoice} ? '' : $customer_object->invoice_mail;
|
558 |
|
$config->send_email(0) if $::form->{postal_invoice};
|
559 |
|
}
|
560 |
|
|
561 |
|
$self->render('oe/edit_periodic_invoices_config', { layout => 0 },
|
562 |
|
popup_dialog => 1,
|
563 |
|
popup_js_close_function => 'kivi.Order.close_periodic_invoices_config_dialog()',
|
564 |
|
popup_js_assign_function => 'kivi.Order.assign_periodic_invoices_config()',
|
565 |
|
config => $config,
|
566 |
|
%$::form);
|
567 |
|
}
|
568 |
|
|
569 |
|
# assign the values of the periodic invoices config dialog
|
570 |
|
# as yaml in the hidden tag and set the status.
|
571 |
|
sub action_assign_periodic_invoices_config {
|
572 |
|
my ($self) = @_;
|
573 |
|
|
574 |
|
$::form->isblank('start_date_as_date', $::locale->text('The start date is missing.'));
|
575 |
|
|
576 |
|
my $config = { active => $::form->{active} ? 1 : 0,
|
577 |
|
terminated => $::form->{terminated} ? 1 : 0,
|
578 |
|
direct_debit => $::form->{direct_debit} ? 1 : 0,
|
579 |
|
periodicity => (any { $_ eq $::form->{periodicity} } @SL::DB::PeriodicInvoicesConfig::PERIODICITIES) ? $::form->{periodicity} : 'm',
|
580 |
|
order_value_periodicity => (any { $_ eq $::form->{order_value_periodicity} } ('p', @SL::DB::PeriodicInvoicesConfig::ORDER_VALUE_PERIODICITIES)) ? $::form->{order_value_periodicity} : 'p',
|
581 |
|
start_date_as_date => $::form->{start_date_as_date},
|
582 |
|
end_date_as_date => $::form->{end_date_as_date},
|
583 |
|
first_billing_date_as_date => $::form->{first_billing_date_as_date},
|
584 |
|
print => $::form->{print} ? 1 : 0,
|
585 |
|
printer_id => $::form->{print} ? $::form->{printer_id} * 1 : undef,
|
586 |
|
copies => $::form->{copies} * 1 ? $::form->{copies} : 1,
|
587 |
|
extend_automatically_by => $::form->{extend_automatically_by} * 1 || undef,
|
588 |
|
ar_chart_id => $::form->{ar_chart_id} * 1,
|
589 |
|
send_email => $::form->{send_email} ? 1 : 0,
|
590 |
|
email_recipient_contact_id => $::form->{email_recipient_contact_id} * 1 || undef,
|
591 |
|
email_recipient_address => $::form->{email_recipient_address},
|
592 |
|
email_sender => $::form->{email_sender},
|
593 |
|
email_subject => $::form->{email_subject},
|
594 |
|
email_body => $::form->{email_body},
|
595 |
|
};
|
596 |
|
|
597 |
|
my $periodic_invoices_config = SL::YAML::Dump($config);
|
598 |
|
|
599 |
|
my $status = $self->get_periodic_invoices_status($config);
|
600 |
|
|
601 |
|
$self->js
|
602 |
|
->remove('#order_periodic_invoices_config')
|
603 |
|
->insertAfter(hidden_tag('order.periodic_invoices_config', $periodic_invoices_config), '#periodic_invoices_status')
|
604 |
|
->run('kivi.Order.close_periodic_invoices_config_dialog')
|
605 |
|
->html('#periodic_invoices_status', $status)
|
606 |
|
->flash('info', t8('The periodic invoices config has been assigned.'))
|
607 |
|
->render($self);
|
608 |
|
}
|
609 |
|
|
610 |
|
sub action_get_has_active_periodic_invoices {
|
611 |
|
my ($self) = @_;
|
612 |
|
|
613 |
|
my $config = make_periodic_invoices_config_from_yaml(delete $::form->{config});
|
614 |
|
$config ||= SL::DB::Manager::PeriodicInvoicesConfig->find_by(oe_id => $::form->{id}) if $::form->{id};
|
615 |
|
|
616 |
|
my $has_active_periodic_invoices =
|
617 |
|
$self->type eq sales_order_type()
|
618 |
|
&& $config
|
619 |
|
&& $config->active
|
620 |
|
&& (!$config->end_date || ($config->end_date > DateTime->today_local))
|
621 |
|
&& $config->get_previous_billed_period_start_date;
|
622 |
|
|
623 |
|
$_[0]->render(\ !!$has_active_periodic_invoices, { type => 'text' });
|
624 |
|
}
|
625 |
|
|
626 |
523 |
# save the order and redirect to the frontend subroutine for a new
|
627 |
524 |
# delivery order
|
628 |
525 |
sub action_save_and_delivery_order {
|
... | ... | |
1420 |
1317 |
}
|
1421 |
1318 |
|
1422 |
1319 |
my $form_orderitems = delete $::form->{order}->{orderitems};
|
1423 |
|
my $form_periodic_invoices_config = delete $::form->{order}->{periodic_invoices_config};
|
1424 |
1320 |
|
1425 |
1321 |
$order->assign_attributes(%{$::form->{order}});
|
1426 |
1322 |
|
1427 |
1323 |
$self->setup_custom_shipto_from_form($order, $::form);
|
1428 |
1324 |
|
1429 |
|
if (my $periodic_invoices_config_attrs = $form_periodic_invoices_config ? SL::YAML::Load($form_periodic_invoices_config) : undef) {
|
1430 |
|
my $periodic_invoices_config = $order->periodic_invoices_config || $order->periodic_invoices_config(SL::DB::PeriodicInvoicesConfig->new);
|
1431 |
|
$periodic_invoices_config->assign_attributes(%$periodic_invoices_config_attrs);
|
1432 |
|
}
|
1433 |
|
|
1434 |
1325 |
# remove deleted items
|
1435 |
1326 |
$self->item_ids_to_delete([]);
|
1436 |
1327 |
foreach my $idx (reverse 0..$#{$order->orderitems}) {
|
... | ... | |
1831 |
1722 |
obsolete => 0 ] ]);
|
1832 |
1723 |
$self->{all_delivery_terms} = SL::DB::Manager::DeliveryTerm->get_all_sorted();
|
1833 |
1724 |
$self->{current_employee_id} = SL::DB::Manager::Employee->current->id;
|
1834 |
|
$self->{periodic_invoices_status} = $self->get_periodic_invoices_status($self->order->periodic_invoices_config);
|
1835 |
1725 |
$self->{order_probabilities} = [ map { { title => ($_ * 10) . '%', id => $_ * 10 } } (0..10) ];
|
1836 |
1726 |
$self->{positions_scrollbar_height} = SL::Helper::UserPreferences::PositionsScrollbar->new()->get_height();
|
1837 |
1727 |
|
... | ... | |
1876 |
1766 |
$self->get_item_cvpartnumber($_) for @{$self->order->items_sorted};
|
1877 |
1767 |
|
1878 |
1768 |
$::request->{layout}->use_javascript("${_}.js") for qw(kivi.SalesPurchase kivi.Order kivi.File ckeditor/ckeditor ckeditor/adapters/jquery
|
1879 |
|
edit_periodic_invoices_config calculate_qty kivi.Validator follow_up show_history);
|
|
1769 |
calculate_qty kivi.Validator follow_up show_history);
|
1880 |
1770 |
$self->setup_edit_action_bar;
|
1881 |
1771 |
}
|
1882 |
1772 |
|
... | ... | |
1895 |
1785 |
call => [ 'kivi.Order.save', 'save', $::instance_conf->get_order_warn_duplicate_parts,
|
1896 |
1786 |
$::instance_conf->get_order_warn_no_deliverydate,
|
1897 |
1787 |
],
|
1898 |
|
checks => [ 'kivi.Order.check_save_active_periodic_invoices', ['kivi.validate_form','#order_form'] ],
|
1899 |
1788 |
],
|
1900 |
1789 |
action => [
|
1901 |
1790 |
t8('Save as new'),
|
1902 |
1791 |
call => [ 'kivi.Order.save', 'save_as_new', $::instance_conf->get_order_warn_duplicate_parts ],
|
1903 |
|
checks => [ 'kivi.Order.check_save_active_periodic_invoices' ],
|
1904 |
1792 |
disabled => !$self->order->id ? t8('This object has not been saved yet.') : undef,
|
1905 |
1793 |
],
|
1906 |
1794 |
], # end of combobox "Save"
|
... | ... | |
1934 |
1822 |
call => [ 'kivi.Order.save', 'save_and_delivery_order', $::instance_conf->get_order_warn_duplicate_parts,
|
1935 |
1823 |
$::instance_conf->get_order_warn_no_deliverydate,
|
1936 |
1824 |
],
|
1937 |
|
checks => [ 'kivi.Order.check_save_active_periodic_invoices' ],
|
1938 |
1825 |
only_if => (any { $self->type eq $_ } (sales_order_type(), purchase_order_type()))
|
1939 |
1826 |
],
|
1940 |
1827 |
action => [
|
1941 |
1828 |
t8('Save and Invoice'),
|
1942 |
1829 |
call => [ 'kivi.Order.save', 'save_and_invoice', $::instance_conf->get_order_warn_duplicate_parts ],
|
1943 |
|
checks => [ 'kivi.Order.check_save_active_periodic_invoices' ],
|
1944 |
1830 |
],
|
1945 |
1831 |
action => [
|
1946 |
1832 |
t8('Save and AP Transaction'),
|
... | ... | |
2104 |
1990 |
return %files;
|
2105 |
1991 |
}
|
2106 |
1992 |
|
2107 |
|
sub make_periodic_invoices_config_from_yaml {
|
2108 |
|
my ($yaml_config) = @_;
|
2109 |
|
|
2110 |
|
return if !$yaml_config;
|
2111 |
|
my $attr = SL::YAML::Load($yaml_config);
|
2112 |
|
return if 'HASH' ne ref $attr;
|
2113 |
|
return SL::DB::PeriodicInvoicesConfig->new(%$attr);
|
2114 |
|
}
|
2115 |
|
|
2116 |
|
|
2117 |
|
sub get_periodic_invoices_status {
|
2118 |
|
my ($self, $config) = @_;
|
2119 |
|
|
2120 |
|
return if $self->type ne sales_order_type();
|
2121 |
|
return t8('not configured') if !$config;
|
2122 |
|
|
2123 |
|
my $active = ('HASH' eq ref $config) ? $config->{active}
|
2124 |
|
: ('SL::DB::PeriodicInvoicesConfig' eq ref $config) ? $config->active
|
2125 |
|
: die "Cannot get status of periodic invoices config";
|
2126 |
|
|
2127 |
|
return $active ? t8('active') : t8('inactive');
|
2128 |
|
}
|
2129 |
|
|
2130 |
1993 |
sub get_title_for {
|
2131 |
1994 |
my ($self, $action) = @_;
|
2132 |
1995 |
|
DeliveryOrder: remove periodic invoices support