a3abd40ae1bbe4740ee120dca930d289eb4374f0
[xtuple] / enyo-client / extensions / source / billing / database / source / xm / javascript / invoice.sql
1 select xt.install_js('XM','Invoice','xtuple', $$
2   /* Copyright (c) 1999-2011 by OpenMFG LLC, d/b/a xTuple.
3      See www.xm.ple.com/CPAL for the full text of the software license. */
4
5   XM.Invoice = {};
6
7   XM.Invoice.isDispatchable = true;
8
9   XM.Invoice.authorizedCredit = function(invoiceNumber) {
10     var sql = "select xt.invc_authorized_credit($1) AS result";
11
12     return plv8.execute(sql, [invoiceNumber])[0].result;
13   };
14
15   XM.Invoice.outstandingCredit = function(customerNumber, currencyAbbreviation, invoiceDate) {
16     var sql = "select xt.invc_outstanding_credit($1, $2, $3) AS result",
17       customerId = XT.Data.getId(XT.Orm.fetch('XM', 'Customer'), customerNumber),
18       currencyId = XT.Data.getId(XT.Orm.fetch('XM', 'Currency'), currencyAbbreviation);
19
20     return plv8.execute(sql, [customerId, currencyId, invoiceDate])[0].result;
21   };
22
23   XM.Invoice.post = function(invoiceNumber) {
24     var invoiceId = XT.Data.getId(XT.Orm.fetch('XM', 'Invoice'), invoiceNumber);
25     return XT.executeFunction("postinvoice", [invoiceId]);
26   };
27
28   XM.Invoice.void = function(invoiceNumber) {
29     var invoiceId = XT.Data.getId(XT.Orm.fetch('XM', 'Invoice'), invoiceNumber);
30     return XT.executeFunction("voidinvoice", [invoiceId]);
31   };
32 $$ );