'filter.fromdate' => $::form->{filter}->{fromdate},
));
- $self->render(
- 'bank_transactions/create_invoice',
- { layout => 0 },
- title => t8('Create invoice'),
- TEMPLATES_GL => $use_vendor_filter && @{ $templates_ap } ? undef : $templates_gl,
- TEMPLATES_AP => $templates_ap,
- vendor_name => $use_vendor_filter && @{ $templates_ap } ? $vendor_of_transaction->name : undef,
- );
+ # if we have exactly one ap match, use this directly
+ if (1 == scalar @{ $templates_ap }) {
+ $self->redirect_to($self->load_ap_record_template_url($templates_ap->[0]));
+
+ } else {
+ my $dialog_html = $self->render(
+ 'bank_transactions/create_invoice',
+ { layout => 0, output => 0 },
+ title => t8('Create invoice'),
+ TEMPLATES_GL => $use_vendor_filter && @{ $templates_ap } ? undef : $templates_gl,
+ TEMPLATES_AP => $templates_ap,
+ vendor_name => $use_vendor_filter && @{ $templates_ap } ? $vendor_of_transaction->name : undef,
+ );
+ $self->js->run('kivi.BankTransaction.show_create_invoice_dialog', $dialog_html)->render;
+ }
}
sub action_ajax_payment_suggestion {
};
ns.create_invoice = function(bank_transaction_id) {
+ $.post('controller.pl?action=BankTransaction/create_invoice',
+ '&bt_id=' + bank_transaction_id + "&filter.bank_account=" + $('#filter_bank_account').val() + '&filter.fromdate=' + $('#filter_fromdate').val() + '&filter.todate=' + $('#filter_todate').val(),
+ kivi.eval_json_result);
+ };
+
+ ns.show_create_invoice_dialog = function(dialog_html) {
kivi.popup_dialog({
- url: 'controller.pl?action=BankTransaction/create_invoice',
- data: '&bt_id=' + bank_transaction_id + "&filter.bank_account=" + $('#filter_bank_account').val() + '&filter.fromdate=' + $('#filter_fromdate').val() + '&filter.todate=' + $('#filter_todate').val(),
- type: 'POST',
+ html: dialog_html,
id: 'create_invoice_window',
dialog: { title: kivi.t8('Create invoice') }
});
- return true;
};