Exemple #1
0
    circuit.series(function* (resume) {
      var moveinData,
        addrKey;

      try {
        if (!args.premise) { // lookup next available premise in company table and increment
          args.premise = yield sql.execSingleValue(args.conn, snippets.getNextPremiseIDQueText, resume);
        }

        if (!args.templateTenant) { // If templateTenant not specified lookup current tenant on templatePremise
          args.templateTenant = yield sql.execSingleValue(args.conn, shareCmn.buildStr(snippets.curTenantCtrQueText, args.templatePremise), resume);
        }

        args.tenant = 1;

        addrKey = yield newRecord(args.conn, args.serviceAddr, 'addresses', resume); // service address. Required

        // Build new premise record with service address
        yield sql.execStmt(args.conn, shareCmn.buildStr(snippets.newPremiseQueText, args.templatePremise, args.premise, args.inDate, addrKey), resume);

        moveinData = yield newOccupant(args, resume);

        yield sql.execStmt(args.conn, moveinData.fullSql, resume); // Run all sql built above

        moveinData.keys.servAddrKey = addrKey;
        moveinData.keys.premiseKey = args.premise;
        callback(null, moveinData.keys); // return keys for new premise
      } catch(e) {
        callback(e);
      }
    })();
Exemple #2
0
    circuit.series(function* (resume) {
      var moveinData,
        tPlateTenantCtr;

      try {
        tPlateTenantCtr = yield sql.execSingleValue(args.conn, shareCmn.buildStr(snippets.curTenantCtrQueText, args.premise), resume);

        args.templateTenant = tPlateTenantCtr;
        args.tenant = tPlateTenantCtr + 1;
        args.templatePremise = args.premise;

        moveinData = yield newOccupant(args, resume);

        /* If moving in AddrType of Tenant then continue association of any landlord or manager.
           If acct has been through mid-cycle final than the old PNALs have PNALActive=False so reset them to True */
        if (args.addrType === 'Tenant') { //~~~ use const
          moveinData.fullSql = addToSqlText(moveinData.fullSql, shareCmn.buildStr(snippets.moveInReactivatePNALQueText, args.templatePremise, args.templateTenant, args.tenant));
        }

        yield sql.execStmt(args.conn, moveinData.fullSql, resume); // Run all sql built above

        callback(null, moveinData.keys);
      } catch(e) {
        callback(e);
      }

    })();
Exemple #3
0
    circuit.series(function* (resume) {
      var fullSql = '',
        keys = {},
        rs;

      args.inDate = shareCmn.stripTimeFromDate(args.inDate);
      try {
        rs = yield sql.execSingleRow(args.conn, shareCmn.buildStr(snippets.residentKeysQueText, args.templatePremise, args.templateTenant), resume);

        if (rs.reccnt === 1) {
          args.addrType = args.addrType || rs.addrtype;
        } else {
          args.addrType = args.addrType || shareCmn.consts.ADDRESS_TYPE_OWNER;
        }

        keys.nameKey = yield newRecord(args.conn, args.residentName, 'names', resume); // resident name. Required
        keys.mailAddrKey = yield newRecord(args.conn, args.mailAddr, 'addresses', resume); // mail address. Optional
        if (!keys.mailAddrKey) { // Mail address was not specified use service addr
          keys.mailAddrKey = yield sql.execSingleValue(args.conn, shareCmn.buildStr(snippets.moveInCurServAddrQueText, args.premise), resume);
        }

        if (args.chargeItems) { // caller specified list of charge items ..
          args.chargeItems = args.chargeItems.join() || -1;
        } else { // .. or get list of charge items from template account
          rs = yield sql.execQuery(args.conn, shareCmn.buildStr(snippets.moveInTemplateChargeItemsQueText, args.templatePremise, args.templateTenant), resume);
          args.chargeItems = rs.records.join() || -1;
        }

        if (args.charges) { // caller specified list of charges ..
          args.charges = args.charges.join() || -1;
        } else { // .. or get list of charges from template account
          rs = yield sql.execQuery(args.conn, shareCmn.buildStr(snippets.moveInTemplateChargesQueText, args.templatePremise, args.templateTenant), resume);
          args.charges =  rs.records.join() || -1;
        }

        fullSql = addToSqlText(fullSql, shareCmn.buildStr(snippets.moveInCreatePTnTQueText, args.templatePremise, args.templateTenant, args.premise, args.tenant));
        fullSql = addToSqlText(fullSql, shareCmn.buildStr(snippets.moveInUpdateCurrTenantCtrQueText, args.premise, args.tenant));
        fullSql = addToSqlText(fullSql, shareCmn.buildStr(snippets.moveInNewPNALQueText, args.premise, args.tenant, keys.nameKey, keys.mailAddrKey, args.inDate, args.addrType));

        // Create PTCh records
        fullSql = addToSqlText(fullSql, shareCmn.buildStr(snippets.moveInBuildPTChQueText, args.templatePremise, args.templateTenant, args.premise, args.tenant, args.chargeItems));

        /* Create PTCD records
           Not copying over PTCDDescBalance. Any $s there belong to the template acct NOT the new acct
           Exclude RoundUp and PayPlan unless marked as Universal
           Add in any universal charges that dont already exist */
        fullSql = addToSqlText(fullSql, shareCmn.buildStr(snippets.moveInBuildPTCDQueText, args.templatePremise, args.templateTenant, args.premise, args.tenant, args.inDate, args.charges));

        // Add in any PTCh records that don't already exist if an existing PTCD record requires them
        fullSql = addToSqlText(fullSql, shareCmn.buildStr(snippets.moveInAddMissingPTChQueText, args.premise, args.tenant));

        callback(null, {keys:keys, fullSql:fullSql});
      } catch(e) {
        callback(e);
      }

    })();
Exemple #4
0
  /*
    buildInsertStmt(obj)

    obj is single object with enough info to create a record
      {table:tableName, flds:{fld1:value, fld1:value, ...}}
    eg
      {table:'addresses', flds:{AddrStreetName:'123 N Main Ave', AddrCity:'Hometown', AddrState:'CA', AddrPostalCode:'98765'}}
    returns a string with the insert statement followed by "; SELECT @@IDENTITY"
  */
  function buildInsertStmt(obj) {
    var stmt = 'insert into {0} ({1}) values ({2}); SELECT @@IDENTITY',
      flds = [],
      values = [];

    Object.keys(obj.flds).forEach(function(key) {
      flds.push('[' + key + ']');
      values.push(shareCmn.doubleQuotes(obj.flds[key]));
    });
    return shareCmn.buildStr(stmt, obj.table, flds.join(), values.join());
  }
Exemple #5
0
    circuit.series(function* (resume) {
      var keys = {},
        insertStmt;

      try {
        args.addrType = args.addrType || shareCmn.consts.ADDRESS_TYPE_OTHER;
        keys.nameKey = yield newRecord(args.conn, args.newName, 'names', resume); // name. Required
        keys.mailAddrKey = yield newRecord(args.conn, args.mailAddr, 'addresses', resume); // mail address. Optional
        if (!keys.mailAddrKey) { // Mail address was not specified use service addr
          keys.mailAddrKey = yield sql.execSingleValue(args.conn, shareCmn.buildStr(snippets.moveInCurServAddrQueText, args.premise), resume);
        }

        insertStmt = shareCmn.buildStr(snippets.newNameQueText, args.premise, args.tenant, args.addrType, keys.nameKey, keys.mailAddrKey);
        keys.PNALKey = yield sql.execSingleValue(args.conn, insertStmt, resume);

        callback(null, keys); // return the new new PNAL keys
      } catch(e) {
        callback(e);
      }
    })();
Exemple #6
0
    circuit.series(function* (resume) {
      var fullSql = '',
        curMODate = null,
        keys = {},
        residentKeys, landlordKeys;

      args.outDate = shareCmn.stripTimeFromDate(args.outDate);
      args.effectiveDate = shareCmn.stripTimeFromDate(args.effectiveDate);
      try {
        residentKeys = yield sql.execSingleRow(args.conn, shareCmn.buildStr(snippets.residentKeysQueText, args.premise, args.tenant), resume); // lookup resident's keys
        if (residentKeys.reccnt === 1) { // if we don't have a valid resident record then skip forwarding address and current move out date code
          keys.forwardAddrKey = yield newRecord(args.conn, args.forwardAddr, 'addresses', resume); // forwarding address. Optional
          if (keys.forwardAddrKey) {
            if (args.effectiveDate) { // build new pnal of type 'forwarding' ..
              fullSql = addToSqlText(fullSql, shareCmn.buildStr(snippets.newPNALAddrQueText, args.effectiveDate, keys.forwardAddrKey, residentKeys.pnalkey));
            } else { // .. or update residents existing PNAL to point to forwarding address
              fullSql = addToSqlText(fullSql, shareCmn.buildStr(snippets.updatePNALAddrQueText, keys.forwardAddrKey, residentKeys.pnalkey));
            }
          }
          curMODate = yield sql.execSingleValue(args.conn, shareCmn.buildStr(snippets.curMODateQueText, residentKeys.pnalkey), resume); // If acct is already moved out get existing move out date
        }

        // Set the PTCDEndDate/PNALEndDate for all records where the date is null or is set to the current move out date (allow changing move out date).
        fullSql = addToSqlText(fullSql, shareCmn.buildStr(snippets.setDatesQueText, args.premise, args.tenant, args.outDate, curMODate ? "'" + curMODate + "'": curMODate)); // ugly hack here that relies on null.toString() returning the string 'null'

        // Set deposits and interest to refund at final and credit account
        fullSql = addToSqlText(fullSql, shareCmn.buildStr(snippets.setDepositsQueText, args.premise, args.tenant));

        yield sql.execStmt(args.conn, fullSql, resume); // Run all sql built above

        /* If user requested to move in landlord and there is exactly 1 landlord PNAL for the current tenant,
           exactly one Resident PNAL and they are different names then move in landlord */
        if (args.moveInLandlord) {
          landlordKeys = yield sql.execSingleRow(args.conn, shareCmn.buildStr(snippets.landlordQueText, args.premise, args.tenant), resume); // lookup landlords's keys
          if (landlordKeys.reccnt === 1) {
            if (residentKeys.namekey !== landlordKeys.namekey) {
              // reuse existing move in webService
              yield doMoveIn({conn:args.conn, premise:args.premise, residentName:landlordKeys.namekey, mailAddr:landlordKeys.addrkey, addrType:'Tenant', inDate:args.outDate}, resume); // ~~~ use const for Tenant
            }
          }
        }

        callback(null, keys);
      } catch(e) {
        callback(e);
      }
    })();