epic-s6ts
[kivitendo-erp.git] / js / kivi.AP.js
1 namespace('kivi.AP', function(ns){
2   'use strict';
3
4   ns.check_fields_before_posting = function() {
5     var errors = [];
6
7     // if the element transdate exists, we have a AP form otherwise we have to check the invoice form
8     var invoice_date = ($('#transdate').length === 0) ? $('#transdate').val() : $('#invdate').val();
9     if (invoice_date === '')
10       errors.push(kivi.t8('Invoice Date missing!'));
11
12     if ($('#duedate').val() === '')
13       errors.push(kivi.t8('Due Date missing!'));
14
15     if ($('#invnumber').val() === '')
16       errors.push(kivi.t8('Invoice Number missing!'));
17
18     if ($('#vendor_id').val() ===  '')
19       errors.push(kivi.t8('Vendor missing!'));
20
21     if (errors.length === 0)
22       return true;
23
24     alert(errors.join(' '));
25
26     return false;
27   };
28
29   ns.check_duplicate_invnumber = function() {
30     var exists_invnumber = false;
31
32     $.ajax({
33       url: 'controller.pl',
34       data: { action: 'SalesPurchase/check_duplicate_invnumber',
35               vendor_id    : $('#vendor_id').val(),
36               invnumber    : $('#invnumber').val()
37       },
38       method: "GET",
39       async: false,
40       dataType: 'text',
41       success: function(val) {
42         exists_invnumber = val;
43       }
44     });
45
46     if (exists_invnumber == 1) {
47       return confirm(kivi.t8('This vendor has already a booking with this invoice number, do you really want to add the same invoice number again?'));
48     }
49
50     return true;
51   };
52
53 });
54
55 $(function() {
56   kivi.File.doc_tab_init('ap_tabs', 'ui-tabs-docs', $('#id').val(), 'purchase_invoice');
57 });