// combine UDF Fields and UDF Values

UDF_1:
LOAD [RecID] as UDFFieldRecID,[Name] as UDFName;
SQL select `RecID`,
`Name`
from `UDF Fields`;
Inner Join
UDF_Value:
Load ParentRecID as UDFFieldRecID,
OwnerRecID as LoanRecID,
Value as UDFValue;
SQL select `ParentRecID`,
`OwnerRecID` ,
`Value`
from `UDF Values`;

// ————————————————————–
// separte non-commitment records
Commitment_1:
NoConcatenate load
trim(subfield(UDFName,’ ‘,2)) as ConnectLender,
num(UDFValue) as CommitAmt,
LoanRecID
Resident UDF_1 where wildmatch(UDFName,’COMM*’);
IRR_1:
NoConcatenate load
trim(subfield(UDFName,’ ‘,2)) as ConnectLender,
num(UDFValue) as IRRAmt,
LoanRecID
Resident UDF_1 where wildmatch(UDFName,’IRR*’);

RR_1:
NoConcatenate load
trim(subfield(UDFName,’ ‘,3)) as ConnectLender,
num(UDFValue) as Risk,
LoanRecID
Resident UDF_1 where wildmatch(UDFName,’Risk*’);
UDF:
NoConcatenate Load LoanRecID,
// UDFName,
subfield(UDFValue,’ ‘,1) as MaturityDateOrig
Resident UDF_1 where wildmatch(UDFName,’Mat*’);

Maturity:
NoConcatenate Load LoanRecID,
Date(MaturityDateOrig,’MM,DD,YYYY’) as MaturityDateOrig
resident UDF;
drop table UDF;
AcctOrig:
NoConcatenate Load LoanRecID,
// UDFName,
UDFValue as AccountOrig
Resident UDF_1 where wildmatch(UDFName,’Account*’);

drop table UDF_1;

// now logic to add funding/commitment information to funding record
// Map_Lender:
// mapping Load
// trim([Account.Lender]) as ConnectLender,
// LenderRecID
// resident Lenders;
// this now is created in Loans module since it is used of LTV in Property module

Commitment:
NoConcatenate LOAD LoanRecID
, ConnectLender
, CommitAmt
,ApplyMap(‘Map_Lender’,ConnectLender, ‘Committ Map’) as LenderRecID
resident Commitment_1;
drop table Commitment_1;

IRR:
NoConcatenate LOAD LoanRecID
, ConnectLender
, IRRAmt
,ApplyMap(‘Map_Lender’,ConnectLender, ‘Mapping not found’) as LenderRecID
resident IRR_1;
drop table IRR_1;

RR:
NoConcatenate LOAD LoanRecID
, ConnectLender
, Risk
,ApplyMap(‘Map_Lender’,ConnectLender, ‘Mapping not found’) as LenderRecID
resident RR_1;
drop table RR_1;
Map_key_c:
mapping Load
autonumber(LoanRecID&LenderRecID) as mapkey,
CommitAmt
resident Commitment;

Map_key_i:
mapping Load
autonumber(LoanRecID&LenderRecID) as mapkey,
IRRAmt
resident IRR;

Map_key_r:
mapping Load
autonumber(LoanRecID&LenderRecID) as mapkey,
Risk
resident RR;

Map_key_l:
mapping Load
autonumber(LoanRecID&LenderRecID) as mapkey,
LTV
resident LTV;

Funding_1:
LOAD BrokerFeePct,
DrawControl,
EffRateValue,
FundControl,
LenderRecID,
LoanRecID,
if(FundControl=0,’Fund-0′,’Funding’) as FactType,
autonumber(LoanRecID&LenderRecID) as mapkey;
SQL SELECT `BrokerFeePct`,
`DrawControl`,
`EffRateValue`,
`FundControl`,
`LenderRecID`,
`LoanRecID`
FROM `TDS Funding`;
// where FundControl > 0;

// split 0 and non 0 to get rid of funding = 0, doesn’t seem to work though
// Funding_old:
// NoConcatenate load *
// resident Funding_1 where FactType = ‘Fund-0’;

// this should only have non zero funding records from funding table
Funding_cur:
NoConcatenate load *
resident Funding_1 where FactType = ‘Funding’;

// drop table Funding_old;
drop table Funding_1;

// using the mapping function instead of join

Funding:
load *,
ApplyMap(‘Map_key_c’,mapkey,’no Comm match’) as CommitAmt,
ApplyMap(‘Map_key_l’,mapkey,’no LTV match’) as LTV,
ApplyMap(‘Map_key_i’,mapkey,’no IRR match’ ) as IRRAmt
// ApplyMap(‘Map_key_r’,mapkey,’no RR match’) as Risk
resident Funding_cur;

// this is for testing only, later just do the drop
// drop field LenderRecID from Commitment;
// Commitment_t:
// load LoanRecID,
// ConnectLender,
// CommitAmt as UDFCommited
// resident Commitment;

drop table Commitment;
drop table Funding_cur;
drop table IRR;
drop table RR;
drop table LTV;

Prop_1:
LOAD City  as City.Property,
Description as Descr.Property,
LoanRecID,
num(LTV) as LTV,[Priority] as Priority.Property,
num([Primary]) as IsPrimary,
PropertyType,[State] as State.Property,
ZipCode as Zip.Property;
SQL SELECT `City`,
`Description`,
`LoanRecID`,
`LTV`,
`Priority`,
`Primary`,
PropertyType,
`State`,
`ZipCode`
FROM `TDS Properties`;
Properties:
NoConcatenate Load[City.Property], [Descr.Property], LoanRecID,
PropertyType, [State.Property], [Zip.Property],
IsPrimary
resident Prop_1 Where IsPrimary < 0;
// resident Prop_1 where  not wildmatch(Descr.Property,’*LTV*’);
// this will only work once I can associate it with a lender and merge concatenate it with
// a FactType table
LTV_1:
NoConcatenate load
LoanRecID,
LTV,
trim(subfield([Descr.Property],’ ‘,2)) as ConnectLender
resident Prop_1 where wildmatch([Descr.Property],’LTV*’);drop table Prop_1;
// here goes mapping to Lender before concatenate
LTV:
NoConcatenate Load LoanRecID
, ConnectLender
, LTV
, ApplyMap(‘Map_Lender’,ConnectLender,’LTV Map’) as LenderRecID
Resident LTV_1;
drop table LTV_1;
// end mappeing
// LoanFacts:
// Load * Resident LoanFacts;
// Concatenate
// load * resident LTV;
// drop table LTV;

Loans_1:
LOAD Account as Account.Loan,
num([ARM_Ceiling]) as [ARM_Ceiling],
num([ARM_Floor]) as [Arm_Floor],[ARM_IndexRate],[ARM_Margin],[ARM_RateChangeNext],
Categories as Categories.Loan,
ClosingDate,[CON_ConstructionLoan],[CON_Revolving] as Revolving,
EmailAddress,
FundControl as FundControl.Loan,[RecID] as LoanRecID,
if(WildMatch(Categories,’*Conventional*’),NextRevision,MaturityDate) as MaturityDate,
year(MaturityDate) as Year.Maturity,
month(MaturityDate) as Month.Maturity,
NextDueDate,
NextRevision,
NoteRate,
OrigBal,
PmtFreq,
PmtPI,
PrinBal,
SortName as SortName.Client,
LoanOfficer,[Priority] as Priority.Loan,
UnpaidInterest,
if (WildMatch([Account],’*-IR*’),’IR’, if(right([Account],3)=’-92′,’LC’,’RG’))
as LoanType,
if (WildMatch(Categories,’*Capped*’),’Yes’,’No’) as Capped,
if (WildMatch(Categories,’*Paid*’),’No’,’Yes’) as IsActive,
if (WildMatch(Categories,’*Conventional*’),’Yes’,’No’) as Conventional;
SQL SELECT `Account`,
`ARM_Ceiling`,
`ARM_Floor`,
`ARM_IndexRate`,
`ARM_Margin`,
`ARM_RateChangeNext`,
`Categories`,
`ClosingDate`,
`CON_ConstructionLoan`,
`CON_Revolving`,
`EmailAddress`,
`FundControl`,
`RecID`,
`MaturityDate`,
`NextDueDate`,
`NextRevision`,
`NoteRate`,
`OrigBal`,
`PmtFreq`,
`PmtPI`,
`PrinBal`,
`SortName`,
`LoanOfficer`,
`Priority`,
`UnpaidInterest`
FROM `TDS Loans` ;

Loans:
NoConcatenate Load *
resident Loans_1;
// Where not wildmatch(Categories.Loan,’*Paid*’)
//and (LoanType = ‘RG’ or LoanType = ‘LC’);

drop table Loans_1;