+sub setup_is_action_bar {
+ my ($tmpl_var) = @_;
+ my $form = $::form;
+ my $change_never = $::instance_conf->get_is_changeable == 0;
+ my $change_on_same_day_only = $::instance_conf->get_is_changeable == 2 && ($form->current_date(\%::myconfig) ne $form->{gldate});
+ my $payments_balanced = ($::form->{oldtotalpaid} == 0);
+ my $has_storno = ($::form->{storno} && !$::form->{storno_id});
+ my $may_edit_create = $::auth->assert('invoice_edit', 1);
+ my $factur_x_enabled = $tmpl_var->{invoice_obj} && $tmpl_var->{invoice_obj}->customer->create_zugferd_invoices_for_this_customer;
+ my ($is_linked_bank_transaction, $warn_unlinked_delivery_order);
+ if ($::form->{id}
+ && SL::DB::Default->get->payments_changeable != 0
+ && SL::DB::Manager::BankTransactionAccTrans->find_by(ar_id => $::form->{id})) {
+
+ $is_linked_bank_transaction = 1;
+ }
+ if ($::instance_conf->get_warn_no_delivery_order_for_invoice && !$form->{id}) {
+ $warn_unlinked_delivery_order = 1 unless $form->{convert_from_do_ids};
+ }
+
+ my $has_further_invoice_for_advance_payment;
+ if ($form->{id} && $form->{type} eq "invoice_for_advance_payment") {
+ my $invoice_obj = SL::DB::Invoice->load_cached($form->{id});
+ my $lr = $invoice_obj->linked_records(direction => 'to', to => ['Invoice']);
+ $has_further_invoice_for_advance_payment = any {'SL::DB::Invoice' eq ref $_ && "invoice_for_advance_payment" eq $_->type} @$lr;
+ }
+
+ my $has_final_invoice;
+ if ($form->{id} && $form->{type} eq "invoice_for_advance_payment") {
+ my $invoice_obj = SL::DB::Invoice->load_cached($form->{id});
+ my $lr = $invoice_obj->linked_records(direction => 'to', to => ['Invoice']);
+ $has_final_invoice = any {'SL::DB::Invoice' eq ref $_ && "final_invoice" eq $_->invoice_type} @$lr;
+ }
+
+ my $is_invoice_for_advance_payment_from_order;
+ if ($form->{id} && $form->{type} eq "invoice_for_advance_payment") {
+ my $invoice_obj = SL::DB::Invoice->load_cached($form->{id});
+ my $lr = $invoice_obj->linked_records(direction => 'from', from => ['Order']);
+ $is_invoice_for_advance_payment_from_order = scalar @$lr >= 1;
+ }
+
+ for my $bar ($::request->layout->get('actionbar')) {
+ $bar->add(
+ action => [
+ t8('Update'),
+ submit => [ '#form', { action => "update" } ],
+ disabled => !$may_edit_create ? t8('You must not change this invoice.')
+ : $form->{locked} ? t8('The billing period has already been locked.')
+ : undef,
+ id => 'update_button',
+ accesskey => 'enter',
+ ],
+
+ combobox => [
+ action => [
+ t8('Post'),
+ submit => [ '#form', { action => "post" } ],
+ checks => [ 'kivi.validate_form' ],
+ confirm => t8('The invoice is not linked with a sales delivery order. Post anyway?') x !!$warn_unlinked_delivery_order,
+ disabled => !$may_edit_create ? t8('You must not change this invoice.')
+ : $form->{locked} ? t8('The billing period has already been locked.')
+ : $form->{storno} ? t8('A canceled invoice cannot be posted.')
+ : ($form->{id} && $change_never) ? t8('Changing invoices has been disabled in the configuration.')
+ : ($form->{id} && $change_on_same_day_only) ? t8('Invoices can only be changed on the day they are posted.')
+ : $is_linked_bank_transaction ? t8('This transaction is linked with a bank transaction. Please undo and redo the bank transaction booking if needed.')
+ : undef,
+ ],
+ action => [
+ t8('Post Payment'),
+ submit => [ '#form', { action => "post_payment" } ],
+ checks => [ 'kivi.validate_form' ],
+ disabled => !$may_edit_create ? t8('You must not change this invoice.')
+ : !$form->{id} ? t8('This invoice has not been posted yet.')
+ : $is_linked_bank_transaction ? t8('This transaction is linked with a bank transaction. Please undo and redo the bank transaction booking if needed.')
+ : undef,
+ only_if => $form->{type} ne "invoice_for_advance_payment",
+ ],
+ action => [ t8('Mark as paid'),
+ submit => [ '#form', { action => "mark_as_paid" } ],
+ confirm => t8('This will remove the invoice from showing as unpaid even if the unpaid amount does not match the amount. Proceed?'),
+ disabled => !$may_edit_create ? t8('You must not change this invoice.')
+ : !$form->{id} ? t8('This invoice has not been posted yet.')
+ : undef,
+ only_if => ($::instance_conf->get_is_show_mark_as_paid && $form->{type} ne "invoice_for_advance_payment") || $form->{type} eq 'final_invoice',
+ ],
+ ], # end of combobox "Post"
+
+ combobox => [
+ action => [ t8('Storno'),
+ submit => [ '#form', { action => "storno" } ],
+ confirm => t8('Do you really want to cancel this invoice?'),
+ checks => [ 'kivi.validate_form' ],
+ disabled => !$may_edit_create ? t8('You must not change this invoice.')
+ : !$form->{id} ? t8('This invoice has not been posted yet.')
+ : $form->{storno} ? t8('Cannot storno storno invoice!')
+ : $form->{locked} ? t8('The billing period has already been locked.')
+ : !$payments_balanced ? t8('Cancelling is disallowed. Either undo or balance the current payments until the open amount matches the invoice amount')
+ : undef,
+ ],
+ action => [ t8('Delete'),
+ submit => [ '#form', { action => "delete" } ],
+ confirm => t8('Do you really want to delete this object?'),
+ checks => [ 'kivi.validate_form' ],
+ disabled => !$may_edit_create ? t8('You must not change this invoice.')
+ : !$form->{id} ? t8('This invoice has not been posted yet.')
+ : $form->{locked} ? t8('The billing period has already been locked.')
+ : $change_never ? t8('Changing invoices has been disabled in the configuration.')
+ : $change_on_same_day_only ? t8('Invoices can only be changed on the day they are posted.')
+ : $has_storno ? t8('Can only delete the "Storno zu" part of the cancellation pair.')
+ : undef,
+ ],
+ ], # end of combobox "Storno"
+
+ 'separator',
+
+ combobox => [
+ action => [ t8('Workflow') ],
+ action => [
+ t8('Use As New'),
+ submit => [ '#form', { action => "use_as_new" } ],
+ checks => [ 'kivi.validate_form' ],
+ disabled => !$may_edit_create ? t8('You must not change this invoice.')
+ : !$form->{id} ? t8('This invoice has not been posted yet.')
+ : undef,
+ ],
+ action => [
+ t8('Further Invoice for Advance Payment'),
+ submit => [ '#form', { action => "further_invoice_for_advance_payment" } ],
+ checks => [ 'kivi.validate_form' ],
+ disabled => !$may_edit_create ? t8('You must not change this invoice.')
+ : !$form->{id} ? t8('This invoice has not been posted yet.')
+ : $has_further_invoice_for_advance_payment ? t8('This invoice has already a further invoice for advanced payment.')
+ : $has_final_invoice ? t8('This invoice has already a final invoice.')
+ : $is_invoice_for_advance_payment_from_order ? t8('This invoice was added from an order. See there.')
+ : undef,
+ only_if => $form->{type} eq "invoice_for_advance_payment",
+ ],
+ action => [
+ t8('Final Invoice'),
+ submit => [ '#form', { action => "final_invoice" } ],
+ checks => [ 'kivi.validate_form' ],
+ disabled => !$may_edit_create ? t8('You must not change this invoice.')
+ : !$form->{id} ? t8('This invoice has not been posted yet.')
+ : $has_further_invoice_for_advance_payment ? t8('This invoice has a further invoice for advanced payment.')
+ : $has_final_invoice ? t8('This invoice has already a final invoice.')
+ : $is_invoice_for_advance_payment_from_order ? t8('This invoice was added from an order. See there.')
+ : undef,
+ only_if => $form->{type} eq "invoice_for_advance_payment",
+ ],
+ action => [
+ t8('Credit Note'),
+ submit => [ '#form', { action => "credit_note" } ],
+ checks => [ 'kivi.validate_form' ],
+ disabled => !$may_edit_create ? t8('You must not change this invoice.')
+ : $form->{type} eq "credit_note" ? t8('Credit notes cannot be converted into other credit notes.')
+ : !$form->{id} ? t8('This invoice has not been posted yet.')
+ : $form->{storno} ? t8('A canceled invoice cannot be used. Please undo the cancellation first.')
+ : undef,
+ ],
+ action => [
+ t8('Sales Order'),
+ submit => [ '#form', { action => "order" } ],
+ checks => [ 'kivi.validate_form' ],
+ disabled => !$form->{id} ? t8('This invoice has not been posted yet.') : undef,
+ ],
+ ], # end of combobox "Workflow"
+
+ combobox => [
+ action => [ t8('Export') ],
+ action => [
+ ($form->{id} ? t8('Print') : t8('Preview')),
+ call => [ 'kivi.SalesPurchase.show_print_dialog', $form->{id} ? 'print' : 'preview' ],
+ checks => [ 'kivi.validate_form' ],
+ disabled => !$may_edit_create ? t8('You must not print this invoice.')
+ : !$form->{id} && $form->{locked} ? t8('The billing period has already been locked.')
+ : undef,
+ ],
+ action => [ t8('Print and Post'),
+ call => [ 'kivi.SalesPurchase.show_print_dialog', 'print_and_post' ],
+ checks => [ 'kivi.validate_form' ],
+ confirm => t8('The invoice is not linked with a sales delivery order. Post anyway?') x !!$warn_unlinked_delivery_order,
+ disabled => !$may_edit_create ? t8('You must not change this invoice.')
+ : $form->{locked} ? t8('The billing period has already been locked.')
+ : $form->{storno} ? t8('A canceled invoice cannot be posted.')
+ : ($form->{id} && $change_never) ? t8('Changing invoices has been disabled in the configuration.')
+ : ($form->{id} && $change_on_same_day_only) ? t8('Invoices can only be changed on the day they are posted.')
+ : $is_linked_bank_transaction ? t8('This transaction is linked with a bank transaction. Please undo and redo the bank transaction booking if needed.')
+ : undef,
+ ],
+ action => [ t8('E Mail'),
+ call => [ 'kivi.SalesPurchase.show_email_dialog' ],
+ checks => [ 'kivi.validate_form' ],
+ disabled => !$may_edit_create ? t8('You must not print this invoice.')
+ : !$form->{id} ? t8('This invoice has not been posted yet.')
+ : $form->{postal_invoice} ? t8('This customer wants a postal invoices.')
+ : undef,
+ ],
+ action => [ t8('Factur-X/ZUGFeRD'),
+ submit => [ '#form', { action => "download_factur_x_xml" } ],
+ checks => [ 'kivi.validate_form' ],
+ disabled => !$may_edit_create ? t8('You must not print this invoice.')
+ : !$form->{id} ? t8('This invoice has not been posted yet.')
+ : !$factur_x_enabled ? t8('Creating Factur-X/ZUGFeRD invoices is not enabled for this customer.')
+ : undef,
+ ],
+ ], # end of combobox "Export"
+
+ combobox => [
+ action => [ t8('more') ],
+ action => [
+ t8('History'),
+ call => [ 'set_history_window', $form->{id} * 1, 'glid' ],
+ disabled => !$form->{id} ? t8('This invoice has not been posted yet.') : undef,
+ ],
+ action => [
+ t8('Follow-Up'),
+ call => [ 'follow_up_window' ],
+ disabled => !$form->{id} ? t8('This invoice has not been posted yet.') : undef,
+ ],
+ action => [
+ t8('Drafts'),
+ call => [ 'kivi.Draft.popup', 'is', 'invoice', $form->{draft_id}, $form->{draft_description} ],
+ disabled => !$may_edit_create ? t8('You must not change this invoice.')
+ : $form->{id} ? t8('This invoice has already been posted.')
+ : $form->{locked} ? t8('The billing period has already been locked.')
+ : undef,
+ ],
+ ], # end of combobox "more"
+ );
+ }
+ $::request->layout->add_javascripts('kivi.Validator.js');
+}
+