<!--todo: If you edit this file be sure to also update field_access.xml in the doc folder!-->

<tables>

    <table name="Contact" access="EDAR">
        <description>Contact data</description>
        <table-name>Contact</table-name>
        <sql-join>LEFT JOIN LeadSource ON Contact.LeadSourceId=LeadSource.Id</sql-join>
        <restriction>
            <restriction-field>Contact.IsUser</restriction-field>
            <value>0</value>
        </restriction>
        <fields>
            <field name="Address1Type"/>
            <field name="Address2Street1"/>
            <field name="Address2Street2"/>
            <field name="Address2Type"/>
            <field name="Address3Street1"/>
            <field name="Address3Street2"/>
            <field name="Address3Type"/>
            <field name="Anniversary" type="Date"/>
            <field name="AssistantName"/>
            <field name="AssistantPhone"/>
            <field name="BillingInformation"/>
            <field name="Birthday" type="Date"/>
            <field name="City"/>
            <field name="City2"/>
            <field name="City3"/>
            <field name="Company"/>
            <field name="AccountId" sql-field="CompanyID" type="Integer" />
            <field name="CompanyID" type="Integer">
                <relationship table="Contact" field="Id" type="MANY_ONE"/>
            </field>
            <field name="ContactNotes"/>
            <field name="ContactType"/>
            <field name="Country"/>
            <field name="Country2"/>
            <field name="Country3"/>
            <field name="CreatedBy" access="R" type="Integer">
                <relationship table="User" field="Id" type="MANY_ONE"/>
            </field>
            <field name="DateCreated" access="R" type="DateTime"/>
            <field name="Email"/>
            <field name="EmailAddress2"/>
            <field name="EmailAddress3"/>
            <field name="Fax1"/>
            <field name="Fax1Type"/>
            <field name="Fax2"/>
            <field name="Fax2Type"/>
            <field name="FirstName"/>
            <field name="Groups" access="R"/>
            <field name="Id" access="R" type="Integer"/>
            <field name="JobTitle"/>
            <field name="LastName"/>
            <field name="LastUpdated" access="R" type="DateTime" />
            <field name="LastUpdatedBy" access="R" type="Integer"/>
            <field name="Leadsource" sql-field-join="LeadSource.Name" access="ERA"/>
            <field name="LeadSourceId" access="ERA" type="Integer"/>
            <field name="MiddleName"/>
            <field name="Nickname"/>
            <field name="OwnerID" type="Integer">
                <relationship table="User" field="Id" type="MANY_ONE"/>
            </field>
            <field name="Password"/>
            <field name="Phone1"/>
            <field name="Phone1Ext"/>
            <field name="Phone1Type"/>
            <field name="Phone2"/>
            <field name="Phone2Ext"/>
            <field name="Phone2Type"/>
            <field name="Phone3"/>
            <field name="Phone3Ext"/>
            <field name="Phone3Type"/>
            <field name="Phone4"/>
            <field name="Phone4Ext"/>
            <field name="Phone4Type"/>
            <field name="Phone5"/>
            <field name="Phone5Ext"/>
            <field name="Phone5Type"/>
            <field name="PostalCode"/>
            <field name="PostalCode2"/>
            <field name="PostalCode3"/>
            <field name="ReferralCode"/>
            <field name="SpouseName"/>
            <field name="State"/>
            <field name="State2"/>
            <field name="State3"/>
            <field name="StreetAddress1"/>
            <field name="StreetAddress2"/>
            <field name="Suffix"/>
            <field name="Title"/>
            <field name="Username"/>
            <field name="Validated" access="R"/>
            <field name="Website"/>
            <field name="ZipFour1"/>
            <field name="ZipFour2"/>
            <field name="ZipFour3"/>
            <!--Custom Fields:-->
            <!--"_" + Name (as shown in step #2 of your CRM's Custom Field Wizard)-->
            <!--EXAMPLE:-->
            <!--<field name="_CustomField1"/>-->
        </fields>
    </table>

    <table name="User" access="R">
        <description>User data</description>
        <table-name>Contact</table-name>
        <sql-join>LEFT JOIN User ON Contact.Id=User.Id</sql-join>
        <restriction>
            <restriction-field>IsUser</restriction-field>
            <value>1</value>
        </restriction>
        <fields>
            <field name="City"/>
            <field name="Email"/>
            <field name="EmailAddress2"/>
            <field name="EmailAddress3"/>
            <field name="FirstName"/>
            <field name="HTMLSignature" sql-field-join="User.HTMLSignature"/>
            <field name="Id" access="R" type="Integer"/>
            <field name="LastName"/>
            <field name="MiddleName"/>
            <field name="Nickname"/>
            <field name="Phone1"/>
            <field name="Phone1Ext"/>
            <field name="Phone1Type"/>
            <field name="Phone2"/>
            <field name="Phone2Ext"/>
            <field name="Phone2Type"/>
            <field name="PostalCode"/>
            <field name="Signature" sql-field-join="User.Signature"/>
            <field name="SpouseName"/>
            <field name="State"/>
            <field name="StreetAddress1"/>
            <field name="StreetAddress2"/>
            <field name="Suffix"/>
            <field name="Title"/>
            <field name="ZipFour1"/>
        </fields>
    </table>

    <table name="UserGroup" access="R">
        <fields>
            <field name="Id" access="R" type="Integer"/>
            <field name="Name"/>
            <field name="OwnerId" type="Integer"/>
        </fields>
    </table>

    <table name="GroupAssign" access="R">
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="UserId" type="Integer"/>
            <field name="GroupId" type="Integer"/>
            <field name="Admin" type="Integer"/>
        </fields>
    </table>

    <table name="Campaignee" access="R">
        <description>Which campaigns</description>
        <table-name>Campaignee</table-name>
        <sql-join>INNER JOIN Campaign ON Campaign.Id=Campaignee.CampaignId</sql-join>
        <fields>
            <field name="CampaignId" type="Integer">
                <relationship table="Campaign" field="Id" type="MANY_ONE"/>
            </field>
            <field name="Status" sql-field="Campaignee.Status">
                <options>
                    <option>Active</option>
                    <option>Inactive</option>
                </options>
            </field>
            <field name="Campaign" sql-field-join="Campaign.Name"/>
            <field name="ContactId" type="Integer">
                <relationship table="Contact" field="Id" type="MANY_ONE"/>
            </field>
        </fields>
    </table>

    <table name="Template" access="R">
        <table-name>MarketingPiece</table-name>
        <fields>
            <field name="Id" access="R" type="Integer"/>
            <!--
                Email
                Fax
                Voice Broadcast
                Letter
                Fulfillment List
                Queued Fulfillment List
                Task
                Activity History
                Actions
             -->
            <field name="PieceType"/>
            <field name="PieceTitle"/>
            <field name="Categories"/>
        </fields>
    </table>

    <table name="CampaignStep" access="R">
        <fields>
            <field name="Id" access="R" type="Integer"/>
            <field name="CampaignId" type="Integer"/>
            <field name="TemplateId" sql-field="CampaignPieceId" type="Integer"/>
            <field name="StepStatus"/>
            <field name="StepTitle"/>
        </fields>
    </table>

    <table name="MtgLead" access="EDAR">
        <fields>
            <field name="Id" access="R" type="Integer"/>
            <field name="OpportunityId" type="Integer"/>
            <field name="DateAppraisalOrdered" type="DateTime"/>
            <field name="DateAppraisalDone" type="DateTime"/>
            <field name="DateAppraisalReceived" type="DateTime"/>
            <field name="DateTitleOrdered" type="DateTime"/>
            <field name="DateTitleReceived" type="DateTime"/>
            <field name="DateRateLocked" type="DateTime"/>
            <field name="DateRateLockExpires" type="DateTime"/>
            <field name="CreditReportDate" type="DateTime"/>
            <field name="ApplicationDate" type="DateTime"/>
            <field name="EstimatedCloseDate" type="DateTime"/>
            <field name="ActualCloseDate" type="DateTime"/>
            <field name="FundingDate" type="DateTime"/>
            <field name="MtgNotes"/>
        </fields>
    </table>

    <table name="Lead" access="EDAR">
        <description>Lead data</description>
        <table-name>Opportunity</table-name>
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="OpportunityTitle"/>
            <field name="ContactID" type="Integer"/>
            <field name="AffiliateId" type="Integer"/>
            <field name="UserID" type="Integer"/>
            <field name="StageID" type="Integer"/>
            <field name="StatusID" type="Integer"/>
            <field name="Leadsource" access="RA"/>
            <field name="Objection"/>
            <field name="ProjectedRevenueLow" type="Double"/>
            <field name="ProjectedRevenueHigh" type="Double"/>
            <field name="OpportunityNotes"/>
            <field name="DateCreated" access="ERD" type="DateTime"/>
            <field name="LastUpdated" access="ERD" type="DateTime"/>
            <field name="LastUpdatedBy" type="Integer"/>
            <field name="CreatedBy" type="Integer"/>
        </fields>
    </table>

    <table name="Stage" access="R">
        <description>Lead Stages</description>
        <fields>
            <field name="Id" access="R" type="Integer"/>
            <field name="StageName"/>
            <field name="StageOrder" type="Integer"/>
            <field name="TargetNumDays" type="Integer"/>
        </fields>
    </table>

    <table name="Status" access="R">
        <description>Lead Statuses</description>
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="StatusName"/>
            <field name="StatusOrder"/>
            <field name="TargetNumDays"/>
        </fields>
    </table>

    <table name="ProductInterest" access="EDAR">
        <description>Product/Subscription Interests</description>
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <!--ObjectId is either a ProductInterestBundle Id, an Opportunity Id, or an ActionCreateOrder Id-->
            <field name="ObjectId" type="Integer"/>
            <!--
                Bundle
                Opportunity
                Action
             -->
            <field name="ObjType"/>
            <!--ProductId is either a Product Id or a CProgram Id-->
            <field name="ProductId" type="Integer"/>
            <!--
                Product
                Program
             -->
            <field name="ProductType"/>
            <field name="Qty"/>
            <field name="DiscountPercent"/>
        </fields>
    </table>

    <table name="ProductInterestBundle" access="EAR">
        <description>Product/Subscription Interest Bundles</description>
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="BundleName"/>
            <field name="Description"/>
        </fields>
    </table>

    <table name="CProgram" access="AER">
        <description>Continuity Programs</description>
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="ProgramName" type="String"/>
            <field name="DefaultPrice" type="Double"/>

            <!--
                Billing Cycle. This is used in conjunction with Default Frequency below. (ie Every one week where the
                default cycle is the one and week is the default frequency). Appropriate values include:
                Option  Value
                Week    3
                Month   2
                Year    1
                Day     6
            -->
            <field name="DefaultCycle" type="String"/>

            <!--
                Period (Week/3, Month/2, Year/1, Day/6)
            -->
            <field name="DefaultFrequency" type="Integer"/>
            <field name="Sku" type="String"/>
            <field name="ShortDescription" sql-field="ProgramShortDesc" type="String"/>

            <!--
                One of two values(Service,Product)
            -->
            <field name="BillingType" type="String"/>
            <field name="SubCategory" type="Integer"/>
            <field name="Description" sql-field="ProgramDesc" type="String"/>

            <!--
                Option      Value
                True        1
                False       0
            -->
            <field name="HideInStore" sql-field="IsHidden" type="Integer"/>

            <!--
                Option      Value
                Active        1
                Inactive       0
            -->
            <field name="Status" type="Integer"/>
            <field name="LargeImage" sql-field="ProgramImageLarge" type="Blob"/>

            <!--
                Option      Value
                True        1
                False       0
            -->
            <field name="Taxable" type="Integer"/>
            <field name="Family" type="String"/>
        </fields>
    </table>

    <table name="Product" access="AER">
        <description>Products</description>
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="ProductName" type="String"/>

            <!--
                Listing price of the product.
            -->
            <field name="ProductPrice" type="Double"/>
            <field name="Sku" type="String"/>
            <field name="ShortDescription" sql-field="ProductShortDesc" type="String"/>

            <!--
                Option      Value
                True        1
                False       0
            -->
            <field name="Taxable" type="Integer"/>
            <field name="Weight" type="Double"/>

            <!--
                Option      Value
                True        1
                False       0
            -->
            <field name="IsPackage" type="Integer"/>

            <!--
                Option      Value
                True        1
                False       0
            -->
            <field name="NeedsDigitalDelivery" sql-field="IsDigital" type="Integer"/>
            <field name="SubCategory" type="Integer"/>
            <field name="Description" sql-field="ProductDesc" type="String"/>

            <!--
                Option      Value
                True        1
                False       0
            -->
            <field name="HideInStore" sql-field="IsHidden" type="Integer"/>

            <!--
                Option      Value
                Active        1
                Inactive       0
            -->
            <field name="Status" type="Integer"/>
            <field name="TopHTML" type="String"/>
            <field name="BottomHTML" type="String"/>
            <field name="ShippingTime" type="String"/>
            <field name="LargeImage" sql-field="ProductImageLarge" type="Blob"/>
            <field name="InventoryNotifiee" type="String"/>
            <field name="InventoryLimit" type="Integer"/>
        </fields>
    </table>

    <table name="CreditCard" access="EAR">
        <description>Credit Card</description>
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="ContactId" type="Integer" access="AR">
                <relationship table="Contact" field="Id" type="MANY_ONE"/>
            </field>

            <field name="BillName"/>
            <field name="FirstName"/>
            <field name="LastName"/>
            <field name="PhoneNumber"/>
            <field name="Email"/>
            <field name="BillAddress1"/>
            <field name="BillAddress2"/>
            <field name="BillCity"/>
            <field name="BillState"/>
            <field name="BillZip"/>
            <field name="BillCountry"/>

            <field name="ShipFirstName"/>
            <field name="ShipMiddleName"/>
            <field name="ShipLastName"/>
            <field name="ShipCompanyName"/>
            <field name="ShipPhoneNumber"/>
            <field name="ShipAddress1"/>
            <field name="ShipAddress2"/>
            <field name="ShipCity"/>
            <field name="ShipState"/>
            <field name="ShipZip"/>
            <field name="ShipCountry"/>
            <field name="ShipName"/>

            <field name="NameOnCard"/>
            <field name="CardNumber" encrypted="true" access="A"/>
            <field name="Last4" access="R"/>

            <!--Expiration Month must be MM -->
            <field name="ExpirationMonth"/>

            <!--Expiration Year must be YYYY -->
            <field name="ExpirationYear"/>

            <!--CVV2 is not stored to the database, but is held in memory for a short time-->
            <field name="CVV2" sql-field="VerificationCode" access="AE"/>

            <!--0 = unknown-->
            <!--1 = error -->
            <!--2 = deleted -->
            <!--3 = OK -->
            <!--4 = inactive -->
            <field name="Status" access="R"/>

            <!--Example: 'American Express', 'Discover', 'MasterCard', 'Visa', etc. -->
            <field name="CardType"/>

            <!--  Fields for UK Cards -->
            <field name="StartDateMonth"/>
            <field name="StartDateYear"/>
            <field name="MaestroIssueNumber"/>
        </fields>
    </table>

    <!--
       This stores a recurring order.  You can add or update these
       records using the data service
    -->
    <table name="RecurringOrder" access="EAR">
        <description>Recurring Order</description>
        <table-name>JobRecurring</table-name>
        <fields>

            <field name="Id" type="Integer" access="R"/>
            <field name="ContactId" type="Integer">
                <relationship table="Contact" field="Id" type="MANY_ONE"/>
            </field>

            <field name="ProgramId" type="Integer">
                <relationship table="CProgram" field="Id" type="MANY_ONE"/>
            </field>

            <field name="StartDate" type="Date"/>
            <field name="EndDate" type="Date"/>

            <field name="LastBillDate" type="Date"/>
            <field name="NextBillDate" access="R"/>

            <!--This field is really the last billed date -->
            <field name="PaidThruDate" sql-field="LastBillDate" type="Date"/>

            <!--
               Monthly = 2
               Yearly = 1
               Weekly = 3
               Daily = 6
            -->
            <field name="BillingCycle"/>

            <!--
               How many cycles between billing.
               eg.  every X weeks
            -->
            <field name="Frequency" type="Integer"/>

            <field name="BillingAmt" type="Double"/>

            <!--
            "Active" or "Inactive"
            -->
            <field name="Status"/>

            <field name="ReasonStopped"/>

            <!--
               No = 0
               Yes = 1
            -->
            <field name="AutoCharge" type="Integer"/>

            <!--Credit Card id to use in autocharge -->
            <field name="CC1" type="Integer"/>
            <field name="CC2" type="Integer"/>

            <field name="NumDaysBetweenRetry" type="Integer"/>
            <field name="MaxRetry" type="Integer"/>
            <field name="MerchantAccountId" type="Integer"/>
            <field name="AffiliateId" type="Integer"/>
            <field name="PromoCode"/>
            <field name="LeadAffiliateId" type="Integer"/>
            <field name="Qty" type="Integer"/>
        </fields>
    </table>

    <!--
       This stores a recurring order.  You can add or update these
       records using the data service
    -->
    <table name="RecurringOrderWithContact" access="R">
        <description>Recurring Order With Basic Contact Info (no custom fields)</description>
        <table-name>JobRecurring</table-name>
        <sql-join>INNER JOIN Contact ON Contact.Id=JobRecurring.ContactId</sql-join>
        <fields>

            <field name="RecurringOrderId" type="Integer" sql-field="JobRecurring.Id" />
            <field name="ContactId" type="Integer">
                <relationship table="Contact" field="Id" type="MANY_ONE"/>
            </field>

            <field name="ProgramId" type="Integer">
                <relationship table="CProgram" field="Id" type="MANY_ONE"/>
            </field>

            <field name="StartDate" type="Date"/>
            <field name="EndDate" type="Date"/>

            <field name="LastBillDate" type="Date"/>
            <field name="NextBillDate" access="R"/>

            <!--This field is really the last billed date -->
            <field name="PaidThruDate" sql-field="LastBillDate" type="Date"/>

            <!--
               Monthly = 2
               Yearly = 1
               Weekly = 3
               Daily = 6
            -->
            <field name="BillingCycle"/>

            <!--
               How many cycles between billing.
               eg.  every X weeks
            -->
            <field name="Frequency"/>

            <field name="BillingAmt" type="Double"/>

            <!--
            "Active" or "Inactive"
            -->
            <field name="Status"/>

            <field name="ReasonStopped"/>

            <!--
               No = 0
               Yes = 1
            -->
            <field name="AutoCharge"/>

            <!--Credit Card id to use in autocharge -->
            <field name="CC1"/>
            <field name="CC2"/>

            <field name="NumDaysBetweenRetry"/>
            <field name="MaxRetry"/>
            <field name="MerchantAccountId" type="Integer"/>
            <field name="AffiliateId" type="Integer"/>
            <field name="PromoCode"/>
            <field name="LeadAffiliateId" type="Integer"/>


            <!-- Contact Fields -->
            <field name="City" sql-field-join="Contact.City"/>
            <field name="Email" sql-field-join="Contact.Email"/>
            <field name="EmailAddress2" sql-field-join="Contact.EmailAddress2"/>
            <field name="EmailAddress3" sql-field-join="Contact.EmailAddress3"/>
            <field name="FirstName" sql-field-join="Contact.FirstName"/>
            <field name="HTMLSignature" sql-field-join="Contact.HTMLSignature"/>
            <field name="Id" sql-field-join="Contact.Id" access="R"/>
            <field name="LastName" sql-field-join="Contact.LastName"/>
            <field name="MiddleName" sql-field-join="Contact.MiddleName"/>
            <field name="Nickname" sql-field-join="Contact.Nickname"/>
            <field name="Phone1" sql-field-join="Contact.Phone1"/>
            <field name="Phone1Ext" sql-field-join="Contact.Phone1Ext"/>
            <field name="Phone1Type" sql-field-join="Contact.Phone1Type"/>
            <field name="Phone2" sql-field-join="Contact.Phone2"/>
            <field name="Phone2Ext" sql-field-join="Contact.Phone2Ext"/>
            <field name="Phone2Type" sql-field-join="Contact.Phone2Type"/>
            <field name="PostalCode" sql-field-join="Contact.PostalCode"/>
            <field name="Signature" sql-field-join="Contact.Signature"/>
            <field name="SpouseName" sql-field-join="Contact.SpouseName"/>
            <field name="State" sql-field-join="Contact.State"/>
            <field name="StreetAddress1" sql-field-join="Contact.StreetAddress1"/>
            <field name="StreetAddress2" sql-field-join="Contact.StreetAddress2"/>
            <field name="Suffix" sql-field-join="Contact.Suffix"/>
            <field name="Title" sql-field-join="Contact.Title"/>
            <field name="ZipFour1" sql-field-join="Contact.ZipFour1"/>

        </fields>
    </table>

    <table name="ContactGroupAssign" access="R">
        <restriction>
            <restriction-field>Contact.IsUser</restriction-field>
            <value>0</value>
        </restriction>
        <sql-join>
            INNER JOIN ContactGroup ON ContactGroupAssign.GroupId=ContactGroup.Id
            INNER JOIN Contact ON Contact.Id=ContactGroupAssign.ContactId
            LEFT JOIN LeadSource ON Contact.LeadSourceId=LeadSource.Id
        </sql-join>
        <fields>
            <field name="GroupId" type="Integer">
                <relationship table="ContactGroup" field="Id" type="MANY_ONE"/>
            </field>
            <field name="ContactGroup" sql-field-join="ContactGroup.GroupName"/>
            <field name="DateCreated" access="R" type="DateTime"/>

            <field name="ContactId" type="Integer">
                <relationship table="Contact" field="Id" type="MANY_ONE"/>
            </field>

            <field name="Contact.Address1Type"/>
            <field name="Contact.Address2Street1"/>
            <field name="Contact.Address2Street2"/>
            <field name="Contact.Address2Type"/>
            <field name="Contact.Address3Street1"/>
            <field name="Contact.Address3Street2"/>
            <field name="Contact.Address3Type"/>
            <field name="Contact.Anniversary" type="Date"/>
            <field name="Contact.AssistantName"/>
            <field name="Contact.AssistantPhone"/>
            <field name="Contact.BillingInformation"/>
            <field name="Contact.Birthday"/>
            <field name="Contact.City"/>
            <field name="Contact.City2"/>
            <field name="Contact.City3"/>
            <field name="Contact.Company"/>
            <field name="Contact.CompanyID">
                <relationship table="Contact" field="Id" type="MANY_ONE"/>
            </field>
            <field name="Contact.ContactNotes"/>
            <field name="Contact.ContactType"/>
            <field name="Contact.Country"/>
            <field name="Contact.Country2"/>
            <field name="Contact.Country3"/>
            <field name="Contact.CreatedBy" access="R">
                <relationship table="User" field="Id" type="MANY_ONE"/>
            </field>
            <field name="Contact.CustomDate1"/>
            <field name="Contact.CustomDate2"/>
            <field name="Contact.CustomDate3"/>
            <field name="Contact.CustomDate4"/>
            <field name="Contact.CustomDate5"/>
            <field name="Contact.CustomDbl1"/>
            <field name="Contact.CustomDbl2"/>
            <field name="Contact.CustomDbl3"/>
            <field name="Contact.CustomDbl4"/>
            <field name="Contact.CustomDbl5"/>
            <field name="Contact.CustomField1"/>
            <field name="Contact.CustomField10"/>
            <field name="Contact.CustomField2"/>
            <field name="Contact.CustomField3"/>
            <field name="Contact.CustomField4"/>
            <field name="Contact.CustomField5"/>
            <field name="Contact.CustomField6"/>
            <field name="Contact.CustomField7"/>
            <field name="Contact.CustomField8"/>
            <field name="Contact.CustomField9"/>
            <field name="Contact.DateCreated" type="DateTime" access="R"/>
            <field name="Contact.Email"/>
            <field name="Contact.EmailAddress2"/>
            <field name="Contact.EmailAddress3"/>
            <field name="Contact.Fax1"/>
            <field name="Contact.Fax1Type"/>
            <field name="Contact.Fax2"/>
            <field name="Contact.Fax2Type"/>
            <field name="Contact.FirstName"/>
            <field name="Contact.Groups" access="R"/>
            <field name="Contact.HTMLSignature"/>
            <field name="Contact.Id" type="Integer" access="R"/>
            <field name="Contact.JobTitle"/>
            <field name="Contact.LastName"/>
            <field name="Contact.LastUpdated" access="R"/>
            <field name="Contact.LastUpdatedBy" access="R"/>
            <field name="Contact.Leadsource" sql-field-join="LeadSource.Name" access="R"/>
            <field name="Contact.MiddleName"/>
            <field name="Contact.Nickname"/>
            <field name="Contact.OwnerID">
                <relationship table="User" field="Id" type="MANY_ONE"/>
            </field>
            <field name="Contact.Phone1"/>
            <field name="Contact.Phone1Ext"/>
            <field name="Contact.Phone1Type"/>
            <field name="Contact.Phone2"/>
            <field name="Contact.Phone2Ext"/>
            <field name="Contact.Phone2Type"/>
            <field name="Contact.Phone3"/>
            <field name="Contact.Phone3Ext"/>
            <field name="Contact.Phone3Type"/>
            <field name="Contact.Phone4"/>
            <field name="Contact.Phone4Ext"/>
            <field name="Contact.Phone4Type"/>
            <field name="Contact.Phone5"/>
            <field name="Contact.Phone5Ext"/>
            <field name="Contact.Phone5Type"/>
            <field name="Contact.PostalCode"/>
            <field name="Contact.PostalCode2"/>
            <field name="Contact.PostalCode3"/>
            <field name="Contact.ReferralCode"/>
            <field name="Contact.Signature"/>
            <field name="Contact.SpouseName"/>
            <field name="Contact.State"/>
            <field name="Contact.State2"/>
            <field name="Contact.State3"/>
            <field name="Contact.StreetAddress1"/>
            <field name="Contact.StreetAddress2"/>
            <field name="Contact.Suffix"/>
            <field name="Contact.Title"/>
            <field name="Contact.Website"/>
            <field name="Contact.ZipFour1"/>
            <field name="Contact.ZipFour2"/>
            <field name="Contact.ZipFour3"/>
        </fields>
    </table>

    <table name="ContactGroup" access="EAR">
        <description>Contact Groups</description>
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="GroupName"/>
            <field name="GroupCategoryId" type="Integer"/>
            <field name="GroupDescription"/>
        </fields>
    </table>

    <table name="ContactGroupCategory" access="EAR">
        <description>Contact Group Categories</description>
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="CategoryName"/>
            <field name="CategoryDescription"/>
        </fields>
    </table>

    <table name="LeadSource" access="EAR">
        <description>Lead Sources in the system</description>
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="Name"/>
            <field name="Description"/>
            <field name="StartDate" type="Date"/>
            <field name="EndDate" type="Date"/>
            <field name="CostPerLead"/>

            <!--
            "Active" or "Inactive"
            -->
            <field name="Status"/>
        </fields>
    </table>

    <table name="Campaign" access="R">
        <description>Campaigns in the system</description>
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="Name"/>

            <!--
            "Active" or "Inactive"
            -->
            <field name="Status"/>
        </fields>
    </table>

    <table name="Invoice" access="R">
        <description>An invoice for a client</description>
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="ContactId" type="Integer">
                <relationship table="Contact" field="Id" type="MANY_ONE"/>
            </field>
            <field name="DateCreated" access="R" type="DateTime"/>
            <field name="InvoiceTotal"/>
            <field name="TotalPaid"/>
            <field name="TotalDue"/>
            <field name="PayStatus"/>
            <field name="CreditStatus"/>
            <field name="RefundStatus"/>
            <field name="PayPlanStatus"/>
            <field name="AffiliateId" type="Integer">
                <relationship table="Affiliate" field="Id" type="MANY_ONE"/>
            </field>
            <field name="LeadAffiliateId" type="Integer">
                <relationship table="Affiliate" field="Id" type="MANY_ONE"/>
            </field>
            <field name="PromoCode"/>
            <field name="InvoiceType"/>
            <field name="Description"/>
            <field name="ProductSold"/>
            <field name="Synced"/>
        </fields>
    </table>

    <table name="Affiliate" access="EDAR">
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="ContactId" type="Integer">
                <relationship table="Contact" field="Id" type="MANY_ONE"/>
            </field>

            <field name="ParentId" type="Integer">
                <relationship table="Affiliate" field="Id" type="MANY_ONE"/>
            </field>
            <!--Eg. 23.33 ($23.33)-->
            <field name="LeadAmt" type="Double"/>

            <!--Eg. 30.5 (30.5%)-->
            <field name="LeadPercent"/>
            <field name="SaleAmt" type="Double"/>
            <field name="SalePercent"/>

            <!--
            On Reciept of Payment = 5
            Up front = 4
            -->
            <field name="PayoutType"/>

            <!--
            Use Affiliate's Commissions = 2
            Use Product Commissions = 3
            -->
            <field name="DefCommissionType"/>

            <!--
            0 = Inactive
            1 = Active
            -->
            <field name="Status"/>

            <!--
            Name of Affiliate eg. "John Doe"
            -->
            <field name="AffName"/>
            <field name="Password"/>

            <!--
            Must be unique
            -->
            <field name="AffCode"/>

            <!--
            0 = No
            1 = Yes
            -->
            <field name="NotifyLead"/>

            <!--
            0 = No
            1 = Yes
            -->
            <field name="NotifySale"/>

            <!--
            Number of days to keep lead cookie
            -->
            <field name="LeadCookieFor"/>


        </fields>
    </table>

    <table name="Referral" access="RA">
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="ContactId" type="Integer"/>
            <field name="AffiliateId" type="Integer"/>
            <field name="DateSet"/>
            <field name="DateExpires"/>
            <field name="IPAddress"/>
            <field name="Source"/>
            <field name="Info"/>
            <field name="Type"/>
            <!--types:-->
            <!--0 = cookie-->
            <!--1 = permanent-->
            <!--2 = manual-->
        </fields>
    </table>

    <table name="InvoiceItem" access="R">
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="InvoiceId" type="Integer">
                <relationship table="Invoice" field="Id" type="MANY_ONE"/>
            </field>
            <field name="InvoiceAmt" type="Double"/>
            <field name="Discount"/>
            <field name="DateCreated" access="R" type="DateTime"/>
            <field name="Description"/>
            <field name="CommissionStatus"/>
        </fields>
    </table>

    <table name="InvoicePayment" access="R">
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="InvoiceId" type="Integer">
                <relationship table="Invoice" field="Id" type="MANY_ONE"/>
            </field>
            <field name="Amt" type="Double"/>
            <field name="PayDate" type="Date"/>
            <field name="PayStatus"/>
            <field name="PaymentId" type="Integer" access="R">
                <relationship table="Payment" field="id" type="MANY_ONE"/>
            </field>
            <field name="SkipCommission"/>
        </fields>
    </table>

    <table name="PayPlan" access="R">
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="InvoiceId" type="Integer">
                <relationship table="Invoice" field="id" type="MANY_ONE"/>
            </field>
            <field name="DateDue"/>
            <field name="AmtDue"/>
            <field name="Type"/>
            <field name="InitDate" type="Date"/>
            <field name="StartDate" type="Date"/>
            <field name="FirstPayAmt" type="Double"/>
        </fields>
    </table>

    <table name="PayPlanItem" access="R">
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="PayPlanId" type="Integer">
                <relationship table="PayPlan" field="Id" type="MANY_ONE"/>
            </field>
            <field name="DateDue"/>
            <field name="AmtDue"/>
            <field name="Status"/>
            <field name="AmtPaid"/>
        </fields>
    </table>

    <table name="Payment" access="R">
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="PayDate" type="Date"/>
            <field name="UserId" type="Integer"/>
            <field name="PayAmt" type="Double"/>
            <field name="PayType"/>
            <field name="ContactId" type="Integer">
                <relationship table="Contact" field="Id" type="MANY_ONE"/>
            </field>
            <field name="PayNote"/>
            <field name="InvoiceId" type="Integer">
                <relationship table="Invoice" field="Id" type="MANY_ONE"/>
            </field>
            <field name="RefundId" type="Integer"/>
            <field name="ChargeId" type="Integer" access="R">
                <relationship table="CCharge" field="Id" type="ONE_ONE"/>                
            </field>
            <field name="Commission"/>
            <field name="Synced"/>
        </fields>
    </table>

    <table name="CCharge" access="R">
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="RefNum" access="R"/>
            <field name="ApprCode" access="R"/>
            <field name="Amt" type="Double" access="R"/>
        </fields>
    </table>

    <table name="Job" access="EAR">
        <sql-join>LEFT JOIN Address ON Job.ShippingAddressId=Address.Id</sql-join>
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="JobTitle"/>
            <field name="ContactId" type="Integer">
                <relationship table="Contact" field="Id" type="MANY_ONE"/>
            </field>
            <field name="StartDate" type="Date"/>
            <field name="DueDate" type="Date"/>
            <field name="JobNotes"/>
            <field name="ProductId" type="Integer">
                <relationship table="Product" field="Id" type="MANY_ONE"/>
            </field>
            <field name="JobStatus"/>
            <field name="DateCreated" access="R" type="DateTime"/>
            <field name="InvoiceId" type="Integer">
                <relationship table="Invoice" field="Id" type="MANY_ONE"/>
            </field>
            <field name="OrderType"/>
            <field name="OrderStatus" type="TinyInt"/>
            <field name="ShipFirstName" sql-field-join="Address.FirstName"/>
            <field name="ShipMiddleName" sql-field-join="Address.MiddleName"/>
            <field name="ShipLastName" sql-field-join="Address.LastName"/>
            <field name="ShipCompany" sql-field-join="Address.Company"/>
            <field name="ShipPhone" sql-field-join="Address.Phone"/>
            <field name="ShipStreet1" sql-field-join="Address.Street1"/>
            <field name="ShipStreet2" sql-field-join="Address.Street2"/>
            <field name="ShipCity" sql-field-join="Address.City"/>
            <field name="ShipState" sql-field-join="Address.State"/>
            <field name="ShipZip" sql-field-join="Address.Zip"/>
            <field name="ShipCountry" sql-field-join="Address.Country"/>
        </fields>
    </table>

    <table name="JobRecurringInstance" access="R">
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="RecurringId" type="Integer">
                <relationship table="RecurringOrder" field="Id" type="MANY_ONE"/>
            </field>
            <field name="InvoiceItemId" type="Integer">
                <relationship table="InvoiceItem" field="Id" type="MANY_ONE"/>
            </field>
            <field name="Status"/>
            <field name="AutoCharge"/>
            <field name="StartDate" type="Date"/>
            <field name="EndDate" type="Date"/>
            <field name="DateCreated" access="R" type="DateTime"/>
            <field name="Description"/>
        </fields>
    </table>

    <table name="OrderItem" access="R">
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="OrderId" type="Integer">
                <relationship table="Order" field="Id" type="MANY_ONE"/>
            </field>
            <field name="ProductId" type="Integer">
                <relationship table="Product" field="Id" type="MANY_ONE"/>
            </field>
            <field name="ItemName"/>
            <field name="Qty"/>
            <field name="CPU"/>
            <field name="PPU"/>
            <field name="ItemDescription"/>
            <field name="InvoiceItemId" type="Integer">
                <relationship table="InvoiceItem" field="Id" type="MANY_ONE"/>
            </field>
            <field name="ItemType"/>
        </fields>
    </table>

    <table name="ActionSequence" access="R">
        <table-name>ContactTemplate</table-name>
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="TemplateName"/>
        </fields>
    </table>

    <table name="ContactAction" access="EDAR">
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="ContactId" type="Integer">
                <relationship table="Contact" field="Id" type="MANY_ONE"/>
            </field>
            <field name="OpportunityId" type="Integer">
                <relationship table="Opportunity" field="Id" type="MANY_ONE"/>
            </field>
            <field name="ActionType" type="String"/>
            <field name="ActionDescription" type="String"/>
            <field name="CreationDate" type="DateTime"/>
            <field name="CreationNotes" type="String"/>
            <field name="CompletionDate" type="DateTime"/>
            <field name="ActionDate" type="DateTime"/>
            <field name="EndDate" type="DateTime"/>
            <field name="PopupDate" type="DateTime"/>
            <field name="UserID" type="Integer">
                <relationship field="Id" table="User" type="MANY_ONE"/>
            </field>
            <field name="Accepted" type="TinyInt"/>
            <field name="CreatedBy" type="Integer">
                <relationship field="Id" table="User" type="MANY_ONE"/>
            </field>
            <field name="LastUpdated" access="R" type="DateTime"/>
            <field name="LastUpdatedBy" access="R" type="Integer">
                <relationship field="Id" table="User" type="MANY_ONE"/>
            </field>
            <field name="Priority" type="Integer"/>
            <field name="IsAppointment" type="TinyInt"/>

        </fields>
    </table>

    <table name="Ticket" access="EDAR">
        <table-name>ServiceCall</table-name>
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="IssueId" type="Integer"/>
            <field name="ContactId" type="Integer" sql-field="AccountId"/>
            <field name="UserId" type="Integer"/>
            <field name="DevId" type="Integer"/>

            <field name="TicketTitle"/>
            <field name="TicketApplication"/>
            <field name="TicketCategory"/>
            <field name="TicketTypeId" type="Integer"/>
            <field name="Summary"/>

            <field name="Stage" type="Integer"/>
            <field name="Priority" type="TinyInt"/>
            <field name="Ordering" type="Integer"/>

            <field name="DateCreated" type="DateTime" access="R"/>
            <field name="CreatedBy" type="Integer"/>
            <field name="LastUpdated" type="DateTime" access="R"/>
            <field name="LastUpdatedBy" type="Integer"/>

            <field name="CloseDate" type="Date"/>
            <field name="FolowUpDate" type="Date"/>
            <field name="TargetCompletionDate" type="Date"/>
            <field name="DateInStage" type="Date"/>

            <field name="TimeSpent"/>
            <field name="HasCustomerCalled" type="TinyInt"/>
        </fields>
    </table>

    <table name="TicketStage" access="R">
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="StageName"/>
        </fields>
    </table>

    <table name="TicketType" access="R">
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="CategoryId" type="Integer"/>
            <field name="Label"/>
        </fields>
    </table>

    <table name="DataFormTab" access="R">
        <fields>
            <field name="Id" access="R" type="Integer"/>
            <field name="FormId" type="Integer"/>
            <field name="TabName" sql-field="GroupName" type="String"/>
        </fields>
    </table>

    <table name="DataFormGroup" access="R">
        <fields>
            <field name="Id" access="R" type="Integer"/>
            <field name="TabId" type="Integer"/>
            <field name="Name" sql-field="GroupName" type="String"/>
        </fields>
    </table>

    <table name="DataFormField" access="RE">
        <fields>
            <!--
                Name                (Enum string/integer identifier/has options)
                Currency -                  (Currency/3/no)
                Date -                      (Date/13/no)
                Date/Time -                 (DateTime/14/no)
                Day of Week -               (DayOfWeek/9/no)
                Drilldown -                 (Drilldown/23/yes)
                Email -                     (Email/19/no)
                Month -                     (Month/8/no)
                List Box -                  (MultiSelect/17/yes)
                Name -                      (Name/10/no)
                Whole Number -              (Number/12/no)
                Decimal Number -            (NumberDecimal/11/no)
                Percent -                   (Percent/4/no)
                Phone Number -              (Phone/1/no)
                Radio -                     (Radio/20/yes)
                Dropdown -                  (Select/21/yes)
                Social Security Number -    (SSN/2/no)
                State -                     (State/5/no)
                Text -                      (Text/15/no)
                Text Area -                 (TextArea/16/no)
                User -                      (User/22/yes)
                Website -                   (Website/18/no)
                Year -                      (Year/7/no)
                Yes/No -                    (YesNo/6/no)
            -->
            <field name="DataType" type="Integer" access="R"/>
            <field name="Id" type="Integer" access="R"/>

            <!--
                This depends on the context of the form. These options include:
                (Enum string/id)
                ContactAction/-5
                Opportunity/-4
                Affiliate/-3
                ServiceCall/-2
                Contact/-1
            -->
            <field name="FormId" type="Integer" access="R"/>
            <field name="GroupId" type="Integer">
                <relationship field="Id" table="DataFormGroup" type="MANY_ONE"/>
            </field>
            <field name="Name" sql-field="FieldName" type="String"/>
            <field name="Label" sql-field="DisplayName" type="String"/>
            <field name="DefaultValue" type="String"/>
            <field name="Values" type="String"/>
            <field name="ListRows" type="Integer"/>
            <field name="UserGroup" type="Integer"/>
        </fields>
    </table>

    <table name="Expense" access="R">
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="ContactId" type="Integer"/>
            <field name="ExpenseType" type="Enum"/>
            <field name="TypeId" type="Integer"/>
            <field name="ExpenseAmt" type="Double"/>
            <field name="DateIncurred" type="DateTime"/>
        </fields>
    </table>

    <table name="FileBox" access="R">
        <fields>
            <field name="Id" type="Integer" access="R"/>
            <field name="FileName" type="String"/>
            <field name="Extension" type="String"/>
            <field name="FileSize" type="Long"/>
            <field name="ContactId" sql-field="UserId" type="Integer"/>
            <field name="Public" sql-field="CanDownload" type="Integer"/>
        </fields>
    </table>

</tables>
