use SL::DB::Default;
use SL::DB::Department;
use SL::DB::PurchaseInvoice;
+use SL::DB::Vendor;
use List::Util qw(max sum);
use List::UtilsBy qw(sort_by);
require "bin/mozilla/io.pl";
-require "bin/mozilla/arap.pl";
require "bin/mozilla/common.pl";
use strict;
# create links
$form->create_links("AP", \%myconfig, "vendor");
- #quote all_vendor Bug 133
- foreach my $ref (@{ $form->{all_vendor} }) {
- $ref->{name} = $form->quote($ref->{name});
- }
-
- if ($form->{all_vendor}) {
- unless ($form->{vendor_id}) {
- $form->{vendor_id} = $form->{all_vendor}->[0]->{id};
- }
- }
-
$form->backup_vars(qw(payment_id language_id taxzone_id
currency delivery_term_id intnotes cp_id));
my @curr = $form->get_all_currencies();
map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
- $form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
-
- # build vendor/customer drop down comatibility... don't ask
- if (@{ $form->{"all_vendor"} || [] }) {
- $form->{"selectvendor"} = 1;
- $form->{vendor} = qq|$form->{vendor}--$form->{vendor_id}|;
- }
-
# forex
$form->{forex} = $form->{exchangerate};
my $exchangerate = ($form->{exchangerate}) ? $form->{exchangerate} : 1;
$main::lxdebug->leave_sub();
}
+sub setup_ir_action_bar {
+ my $form = $::form;
+ my $change_never = $::instance_conf->get_ir_changeable == 0;
+ my $change_on_same_day_only = $::instance_conf->get_ir_changeable == 2 && ($form->current_date(\%::myconfig) ne $form->{gldate});
+
+ for my $bar ($::request->layout->get('actionbar')) {
+ $bar->add(
+ action => [
+ t8('Update'),
+ submit => [ '#form', { action => "update" } ],
+ id => 'update_button',
+ accesskey => 'enter',
+ ],
+
+ combobox => [
+ action => [
+ t8('Post'),
+ submit => [ '#form', { action => "post" } ],
+ disabled => $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.')
+ : undef,
+ ],
+ action => [
+ t8('Post Payment'),
+ submit => [ '#form', { action => "post_payment" } ],
+ disabled => !$form->{id} ? t8('This invoice has not been posted yet.') : undef,
+ ],
+ 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 => !$form->{id} ? t8('This invoice has not been posted yet.') : undef,
+ only_if => $::instance_conf->get_ir_show_mark_as_paid,
+ ],
+ ], # end of combobox "Post"
+
+ combobox => [
+ action => [ t8('Storno'),
+ submit => [ '#form', { action => "storno" } ],
+ confirm => t8('Do you really want to cancel this invoice?'),
+ disabled => !$form->{id} ? t8('This invoice has not been posted yet.') : undef,
+ ],
+ action => [ t8('Delete'),
+ submit => [ '#form', { action => "delete" } ],
+ confirm => t8('Do you really want to delete this object?'),
+ disabled => !$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.')
+ : undef,
+ ],
+ ], # end of combobox "Storno"
+
+ 'separator',
+
+ combobox => [
+ action => [ t8('Workflow') ],
+ action => [
+ t8('Use As New'),
+ submit => [ '#form', { action => "use_as_new" } ],
+ disabled => !$form->{id} ? t8('This invoice has not been posted yet.') : undef,
+ ],
+ ], # end of combobox "Workflow"
+
+ combobox => [
+ action => [ t8('more') ],
+ action => [
+ t8('History'),
+ call => [ 'set_history_window', $::form->{id} * 1, 'id', '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', 'ir', 'invoice', $::form->{draft_id}, $::form->{draft_description} ],
+ disabled => $form->{id} ? t8('This invoice has already been posted.')
+ : $form->{locked} ? t8('The billing period has already been locked.')
+ : undef,
+ ],
+ ], # end of combobox "more"
+ );
+ }
+}
+
sub form_header {
$main::lxdebug->enter_sub();
my %TMPL_VAR = ();
my @custom_hiddens;
- $TMPL_VAR{invoice_obj} = SL::DB::PurchaseInvoice->new(id => $form->{id})->load if $form->{id};
- $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
- $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
+ $TMPL_VAR{invoice_obj} = SL::DB::PurchaseInvoice->load_cached($form->{id}) if $form->{id};
+ $TMPL_VAR{vendor_obj} = SL::DB::Vendor->load_cached($form->{vendor_id}) if $form->{vendor_id};
+ my $current_employee = SL::DB::Manager::Employee->current;
+ $form->{employee_id} = $form->{old_employee_id} if $form->{old_employee_id};
+ $form->{salesman_id} = $form->{old_salesman_id} if $form->{old_salesman_id};
+ $form->{employee_id} ||= $current_employee->id;
+ $form->{salesman_id} ||= $current_employee->id;
$form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
$form->get_lists("taxzones" => ($form->{id} ? "ALL_TAXZONES" : "ALL_ACTIVE_TAXZONES"),
"currencies" => "ALL_CURRENCIES",
- "vendors" => "ALL_VENDORS",
"price_factors" => "ALL_PRICE_FACTORS");
$TMPL_VAR{ALL_DEPARTMENTS} = SL::DB::Manager::Department->get_all_sorted;
]
]);
- # customer
- $TMPL_VAR{vc_keys} = sub { "$_[0]->{name}--$_[0]->{id}" };
- $TMPL_VAR{vclimit} = $myconfig{vclimit};
- $TMPL_VAR{vc_select} = "customer_or_vendor_selection_window('vendor', '', 1, 0)";
- push @custom_hiddens, "vendor_id";
- push @custom_hiddens, "oldvendor";
- push @custom_hiddens, "selectvendor";
-
# currencies and exchangerate
my @values = map { $_ } @{ $form->{ALL_CURRENCIES} };
my %labels = map { $_ => $_ } @{ $form->{ALL_CURRENCIES} };
$TMPL_VAR{creditwarning} = ($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update};
$TMPL_VAR{is_credit_remaining_negativ} = $form->{creditremaining} =~ /-/;
- my $follow_up_vc = $form->{vendor};
- $follow_up_vc =~ s/--\d*\s*$//;
- $TMPL_VAR{vendor_name} = $follow_up_vc;
-
# set option selected
foreach my $item (qw(AP)) {
$form->{"select$item"} =~ s/ selected//;
# hiddens
$TMPL_VAR{HIDDENS} = [qw(
- id action type media format queued printed emailed title vc discount
+ id type queued printed emailed title vc discount
title creditlimit creditremaining tradediscount business closedto locked shipped storno storno_id
max_dunning_level dunning_amount
shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptogln shiptocontact shiptophone shiptofax
map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts}];
$TMPL_VAR{payment_terms_obj} = get_payment_terms_for_invoice();
- $form->{duedate} = $TMPL_VAR{payment_terms_obj}->calc_date(reference_date => $form->{invdate}, due_date => $form->{due_due})->to_kivitendo if $TMPL_VAR{payment_terms_obj};
+ $form->{duedate} = $TMPL_VAR{payment_terms_obj}->calc_date(reference_date => $form->{invdate}, due_date => $form->{duedate})->to_kivitendo if $TMPL_VAR{payment_terms_obj};
+
+ $::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.Draft kivi.File kivi.SalesPurchase kivi.Part ckeditor/ckeditor ckeditor/adapters/jquery kivi.io autocomplete_customer autocomplete_project client_js));
- $::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.Draft kivi.SalesPurchase ckeditor/ckeditor ckeditor/adapters/jquery kivi.io autocomplete_customer autocomplete_part autocomplete_project client_js));
+ setup_ir_action_bar();
$form->header();
$main::auth->assert('vendor_invoice_edit');
- &check_name('vendor');
+ if (($form->{previous_vendor_id} || $form->{vendor_id}) != $form->{vendor_id}) {
+ IR->get_vendor(\%myconfig, $form);
+ }
if (!$form->{forex}) { # read exchangerate from input field (not hidden)
$form->{exchangerate} = $form->parse_amount(\%myconfig, $form->{exchangerate});
$form->{defaultcurrency} = $form->get_default_currency(\%myconfig);
$form->isblank("invdate", $locale->text('Invoice Date missing!'));
- $form->isblank("vendor", $locale->text('Vendor missing!'));
+ $form->isblank("vendor_id", $locale->text('Vendor missing!'));
$form->isblank("invnumber", $locale->text('Invnumber missing!'));
$form->{invnumber} =~ s/^\s*//g;
$form->{invnumber} =~ s/\s*$//g;
# if the vendor changed get new values
- if (&check_name('vendor')) {
+ if (($form->{previous_vendor_id} || $form->{vendor_id}) != $form->{vendor_id}) {
&update;
$::dispatcher->end_request;
}
$form->save_history;
}
# /saving the history
+ $form->{callback} = 'ir.pl?action=add';
$form->redirect( $locale->text('Invoice')
. " $form->{invnumber} "
. $locale->text('posted!'));