1 select xt.install_js('XM','Billing','xtuple', $$
2 /* Copyright (c) 1999-2011 by OpenMFG LLC, d/b/a xTuple.
3 See www.xtuple.com/CPAL for the full text of the software license. */
8 "InvcNumberGeneration",
12 "EnableCustomerDeposits",
23 "AutoCreditWarnLateCustomers",
24 "DefaultAutoCreditWarnGraceDays",
25 "RecurringInvoiceBuffer",
26 "DefaultARIncidentStatus",
32 for(i = 0; i < billingOptions.length; i++) {
33 option = billingOptions[i];
34 if(!XM.Billing.options.contains(option)) {
35 XM.Billing.options.push(option);
41 XM.Billing.options = billingOptions;
44 XM.Billing.isDispatchable = true;
47 Return Billing configuration settings.
51 XM.Billing.settings = function() {
53 var keys = XM.Billing.options.slice(0),
54 data = Object.create(XT.Data),
59 ret.NextARMemoNumber = plv8.execute('select currentARMemoNumber() as value', [])[0].value;
60 ret.NextCashRcptNumber = plv8.execute('select currentCashRcptNumber() as value',[])[0].value;
62 ret = XT.extend(data.retrieveMetrics(keys), ret);
67 Update Billing configuration settings. Only valid options as defined in the array
68 XM.Billing.options will be processed.
70 @param {Object} settings
73 XM.Billing.commitSettings = function(patches) {
74 var sql, settings, options = XM.Billing.options.slice(0),
75 data = Object.create(XT.Data), metrics = {};
77 /* check privileges */
78 if(!data.checkPrivilege('ConfigureAR')) throw new Error('Access Denied');
80 /* Compose our commit settings by applying the patch to what we already have */
81 settings = XM.Billing.settings();
82 if (!XT.jsonpatch.apply(settings, patches)) {
83 plv8.elog(NOTICE, 'Malformed patch document');
86 if (settings['NextARMemoNumber']) {
87 plv8.execute('select setNextARMemoNumber($1)', [settings['NextARMemoNumber'] - 0]);
89 options.remove('NextARMemoNumber');
91 if (settings['NextCashRcptNumber']) {
92 plv8.execute('select setNextCashRcptNumber($1)', [settings['NextCashRcptNumber'] - 0]);
94 options.remove('NextCashRcptNumber');
96 /* update remaining options as metrics
97 first make sure we pass an object that only has valid metric options for this type */
98 for(var i = 0; i < options.length; i++) {
99 var prop = options[i];
100 if(settings[prop] !== undefined) metrics[prop] = settings[prop];
103 return data.commitMetrics(metrics);