$main::auth->assert('vendor_invoice_edit');
+ if (!$::instance_conf->get_allow_new_purchase_invoice) {
+ $::form->show_generic_error($::locale->text("You do not have the permissions to access this function."));
+ }
+
return $main::lxdebug->leave_sub() if (load_draft_maybe());
$form->{title} = $locale->text('Record Vendor Invoice');
$form->{vc} = 'vendor';
# create links
- $form->{webdav} = $::lx_office_conf{features}->{webdav};
- $form->{jsscript} = 1;
+ $form->{webdav} = $::instance_conf->get_webdav;
$form->create_links("AP", \%myconfig, "vendor");
}
}
- my ($payment_id, $language_id, $taxzone_id, $currency);
- if ($form->{payment_id}) {
- $payment_id = $form->{payment_id};
- }
- if ($form->{language_id}) {
- $language_id = $form->{language_id};
- }
- if ($form->{taxzone_id}) {
- $taxzone_id = $form->{taxzone_id};
- }
- if ($form->{currency}) {
- $currency = $form->{currency};
- }
+ $form->backup_vars(qw(payment_id language_id taxzone_id
+ currency delivery_term_id intnotes cp_id));
- my $cp_id = $form->{cp_id};
IR->get_vendor(\%myconfig, \%$form);
IR->retrieve_invoice(\%myconfig, \%$form);
- $form->{cp_id} = $cp_id;
- if ($payment_id) {
- $form->{payment_id} = $payment_id;
- }
- if ($language_id) {
- $form->{language_id} = $language_id;
- }
- if ($taxzone_id) {
- $form->{taxzone_id} = $taxzone_id;
- }
- if ($currency) {
- $form->{currency} = $currency;
- }
+ $form->restore_vars(qw(payment_id language_id taxzone_id
+ currency delivery_term_id intnotes cp_id));
- my @curr = split(/:/, $form->{currencies}); #seems to be missing
+ my @curr = $form->get_all_currencies();
map { $form->{selectcurrency} .= "<option>$_\n" } @curr;
$form->{oldvendor} = "$form->{vendor}--$form->{vendor_id}";
$main::auth->assert('vendor_invoice_edit');
+ $form->{type} = "purchase_invoice";
+
if ($form->{id}) {
map { $form->{$_} =~ s/\"/"/g } qw(invnumber ordnumber quonumber);
"departments" => "all_departments",
"price_factors" => "ALL_PRICE_FACTORS");
- $TMPL_VAR{ALL_EMPLOYEES} = SL::DB::Manager::Employee->get_all(query => [ or => [ id => $::form->{employee_id}, deleted => 0 ] ]);
- $TMPL_VAR{ALL_CONTACTS} = SL::DB::Manager::Contact->get_all(query => [
+ $TMPL_VAR{ALL_EMPLOYEES} = SL::DB::Manager::Employee->get_all_sorted(query => [ or => [ id => $::form->{employee_id}, deleted => 0 ] ]);
+ $TMPL_VAR{ALL_CONTACTS} = SL::DB::Manager::Contact->get_all_sorted(query => [
or => [
cp_cv_id => $::form->{"$::form->{vc}_id"} * 1,
and => [
$TMPL_VAR{creditwarning} = ($form->{creditlimit} != 0) && ($form->{creditremaining} < 0) && !$form->{update};
$TMPL_VAR{is_credit_remaining_negativ} = $form->{creditremaining} =~ /-/;
- $::request->{layout}->focus('#vendor');
-
my $follow_up_vc = $form->{vendor};
$follow_up_vc =~ s/--\d*\s*$//;
$TMPL_VAR{vendor_name} = $follow_up_vc;
max_dunning_level dunning_amount
shiptoname shiptostreet shiptozipcode shiptocity shiptocountry shiptocontact shiptophone shiptofax
shiptoemail shiptodepartment_1 shiptodepartment_2 message email subject cc bcc taxaccounts cursor_fokus
- convert_from_do_ids convert_from_oe_ids
+ convert_from_do_ids convert_from_oe_ids show_details gldate
), @custom_hiddens,
map { $_.'_rate', $_.'_description', $_.'_taxnumber' } split / /, $form->{taxaccounts}];
- $form->{jsscript} = 1;
+ $::request->{layout}->use_javascript(map { "${_}.js" } qw(kivi.SalesPurchase ckeditor/ckeditor ckeditor/adapters/jquery kivi.io autocomplete_customer autocomplete_part));
+
$form->header();
print $form->parse_html_template("ir/form_header", \%TMPL_VAR);
$totalpaid += $form->{"paid_$i"};
}
+ $form->{ALL_DELIVERY_TERMS} = SL::DB::Manager::DeliveryTerm->get_all_sorted();
+
print $form->parse_html_template('ir/form_footer', {
is_type_credit_note => ($form->{type} eq "credit_note"),
totalpaid => $totalpaid,
if ($sellprice) {
$form->{"sellprice_$i"} = $sellprice;
} else {
+ my $record = _make_record();
+ my $price_source = SL::PriceSource->new(record_item => $record->items->[$i-1], record => $record);
+ my $best_price = $price_source->best_price;
+ my $best_discount = $price_source->best_discount;
+
+ if ($best_price) {
+ $::form->{"sellprice_$i"} = $best_price->price;
+ $::form->{"active_price_source_$i"} = $best_price->source;
+ }
+ if ($best_discount) {
+ $::form->{"discount_$i"} = $best_discount->discount;
+ $::form->{"active_discount_source_$i"} = $best_discount->source;
+ }
+
# if there is an exchange rate adjust sellprice
$form->{"sellprice_$i"} /= $exchangerate;
}
# Payments must not be recorded for the new storno invoice.
$form->{paidaccounts} = 0;
map { my $key = $_; delete $form->{$key} if grep { $key =~ /^$_/ } qw(datepaid_ gldate_ acc_trans_id_ source_ memo_ paid_ exchangerate_ AR_paid_) } keys %{ $form };
+ # set new ids for storno invoice
+ delete $form->{"invoice_id_$_"} for 1 .. $form->{"rowcount"};
# saving the history
if(!exists $form->{addition} && $form->{id} ne "") {
}
-sub use_as_template {
+sub use_as_new {
$main::lxdebug->enter_sub();
my $form = $main::form;
$form->{paidaccounts} = 1;
$form->{rowcount}--;
$form->{invdate} = $form->current_date(\%myconfig);
+ delete $form->{"invoice_id_$_"} for 1 .. $form->{"rowcount"};
&display_form;
$main::lxdebug->leave_sub();
my $invdate = $form->datetonum($form->{invdate}, \%myconfig);
my $max_datepaid = _max_datepaid();
- $form->error($locale->text('Cannot post invoice for a closed period!')) if $max_datepaid && $form->date_closed($max_datepaid, \%myconfig);
+ $form->error($locale->text('Cannot post transaction above the maximum future booking date!'))
+ if ($form->date_max_future($invdate, \%myconfig));
+ $form->error($locale->text('Cannot post invoice for a closed period!'))
+ if ($invdate <= $closedto);
$form->isblank("exchangerate", $locale->text('Exchangerate missing!'))
if ($form->{currency} ne $form->{defaultcurrency});