1 select xt.install_js('XM','Account','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. */
7 XM.Account.isDispatchable = true,
9 XM.Account.findExisting = function(key, value, id) {
10 /* look in crmacct for any records that have num */
11 /* if you don't find one, return 0 meaning you didn't find anything
12 if you do find a result, look to see if prospect or cust columns are populated.
13 return an object where 1 property is the crmacct_id and the other is A for account, P for prospect or C for customer*/
14 /* use result.crmacct_id to get the crmacct_id column. the result of the query will be an array so get the 1st result */
19 sql = "select crmacct_number, cust_number, prospect_number " +
21 "left join custinfo on cust_id = crmacct_cust_id " +
22 "left join prospect on prospect_id = crmacct_prospect_id " +
23 " where crmacct_number = $1";
25 res = XM.Model.findExisting("XM.Account", key, value, id);
27 /*if the result is falsey, no CRM account exists by this name, and return 0. */
31 row = plv8.execute(sql, [res])[0];
33 if (row.cust_number) {
34 retVal.id = row.cust_number;
36 } else if (row.prospect_number) {
37 retVal.id = row.prospect_number;
40 retVal.id = row.crmacct_number;
48 XM.Account.used = function(id) {
49 var sql = "select (crmacct_cust_id is null" +
50 " and crmacct_prospect_id is null" +
51 " and crmacct_emp_id is null" +
52 " and crmacct_salesrep_id is null" +
53 " and crmacct_taxauth_id is null" +
54 " and crmacct_vend_id is null" +
55 " and crmacct_usr_username is null) as result " +
56 "from crmacct where crmacct_number = $1",
57 res = plv8.execute(sql, [id])[0].result;
58 return res ? XM.Model.used('XM.Account', id) : true;