
<!--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>
        <sql-from>Contact</sql-from>
        <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"/>
            <field name="AssistantName"/>
            <field name="AssistantPhone"/>
            <field name="BillingInformation"/>
            <field name="Birthday"/>
            <field name="City"/>
            <field name="City2"/>
            <field name="City3"/>
            <field name="Company"/>
            <field name="CompanyID">
                <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">
                <relationship table="User" field="Id" type="MANY_ONE"/>
            </field>
            <field name="DateCreated" access="R"/>
            <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"/>
            <field name="JobTitle"/>
            <field name="LastName"/>
            <field name="LastUpdated" access="R"/>
            <field name="LastUpdatedBy" access="R"/>
            <field name="MiddleName"/>
            <field name="Nickname"/>
            <field name="OwnerID" access="RA">
                <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="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>
        <sql-from>Contact</sql-from>
        <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="Id" access="R"/>
            <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"/>
            <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"/>
            <field name="Name"/>
            <field name="OwnerId"/>
        </fields>
    </table>

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

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

    <table name="Template" access="R">
        <sql-from>MarketingPiece</sql-from>
        <fields>
            <field name="Id" access="R"/>
            <!--
                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"/>
            <field name="CampaignId"/>
            <field name="TemplateId" sql-select="CampaignPieceId"/>
            <field name="StepStatus"/>
            <field name="StepTitle"/>
        </fields>
    </table>

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

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

    <table name="Status" access="R">
        <description>Lead Statuses</description>
        <fields>
            <field name="Id"/>
            <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"/>
            <!--ObjectId is either a ProductInterestBundle Id, an Opportunity Id, or an ActionCreateOrder Id-->
            <field name="ObjectId"/>
            <!--
                Bundle
                Opportunity
                Action
             -->
            <field name="ObjType"/>
            <!--ProductId is either a Product Id or a CProgram Id-->
            <field name="ProductId"/>
            <!--
                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"/>
            <field name="BundleName"/>
            <field name="Description"/>
        </fields>
    </table>

    <table name="CProgram" access="AER">
        <description>Continuity Programs</description>
        <sql-from>CProgram</sql-from>
        <fields>
            <field name="Id" access="R" type="int"/>
            <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="int"/>
            <field name="Sku" type="string"/>
            <field name="ShortDescription" sql-select="ProgramShortDesc" type="string"/>

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

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

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

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

    <table name="Product" access="AER">
        <description>Products</description>
        <sql-from>Product</sql-from>
        <fields>
            <field name="Id" access="R" type="int"/>
            <field name="ProductName" type="string"/>

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

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

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

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

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

            <!--
                Option      Value
                Active        1
                Inactive       0
            -->
            <field name="Status" type="int"/>
            <field name="TopHTML" type="string"/>
            <field name="BottomHTML" type="string"/>
            <field name="ShippingTime" type="string"/>
            <field name="LargeImage" sql-select="ProductImageLarge" type="blob"/>
            <field name="InventoryNotifiee" type="string"/>
            <field name="InventoryLimit" type="int"/>
						<field name="Shippable" type="tinyint"/>
        </fields>
    </table>

    <table name="CreditCard" access="EAR">
        <description>Credit Card</description>
        <sql-from>CreditCard</sql-from>
        <fields>
            <field name="Id" access="R"/>
            <field name="ContactId" 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-select="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>
        <sql-from>JobRecurring</sql-from>
        <fields>

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

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

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

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

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

            <!--
               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"/>

            <!--
            "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"/>
            <field name="AffiliateId"/>
            <field name="PromoCode"/>
            <field name="LeadAffiliateId"/>

        </fields>
    </table>

    <table name="ContactGroupAssign" access="R">
        <restriction>
            <restriction-field>Contact.IsUser</restriction-field>
            <value>0</value>
        </restriction>

        <sql-from>ContactGroupAssign INNER JOIN ContactGroup ON ContactGroupAssign.GroupId=ContactGroup.Id
            INNER JOIN Contact ON Contact.Id=ContactGroupAssign.ContactId
        </sql-from>
        <fields>
            <field name="GroupId">
                <relationship table="ContactGroup" field="Id" type="MANY_ONE"/>
            </field>
            <field name="ContactGroup" sql-select="ContactGroup.GroupName"/>
            <field name="DateCreated"/>
            <field name="ContactId">
                <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"/>
            <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" 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" 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"/>
            <field name="Contact.MiddleName"/>
            <field name="Contact.Nickname"/>
            <field name="Contact.OwnerID" access="R">
                <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>
        <sql-from>ContactGroup</sql-from>
        <fields>
            <field name="Id"/>
            <field name="GroupName"/>
            <field name="GroupCategoryId"/>
            <field name="GroupDescription"/>
        </fields>
    </table>

    <table name="ContactGroupCategory" access="EAR">
        <description>Contact Group Categories</description>
        <sql-from>ContactGroupCategory</sql-from>
        <fields>
            <field name="Id"/>
            <field name="CategoryName"/>
            <field name="CategoryDescription"/>
        </fields>
    </table>

    <table name="LeadSource" access="EAR">
        <description>Lead Sources in the system</description>
        <fields>
            <field name="Id"/>
            <field name="Name"/>
            <field name="Description"/>
            <field name="StartDate"/>
            <field name="EndDate"/>
            <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"/>
            <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"/>
            <field name="ContactId">
                <relationship table="Contact" field="Id" type="MANY_ONE"/>
            </field>
            <field name="DateCreated"/>
            <field name="InvoiceTotal"/>
            <field name="TotalPaid"/>
            <field name="TotalDue"/>
            <field name="PayStatus"/>
            <field name="CreditStatus"/>
            <field name="RefundStatus"/>
            <field name="PayPlanStatus"/>
            <field name="AffiliateId">
                <relationship table="Affiliate" field="Id" type="MANY_ONE"/>
            </field>
            <field name="LeadAffiliateId">
                <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"/>
            <field name="ContactId">
                <relationship table="Contact" field="Id" type="MANY_ONE"/>
            </field>

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

            <!--Eg. 30.5 (30.5%)-->
            <field name="LeadPercent"/>
            <field name="SaleAmt"/>
            <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"/>
            <field name="ContactId"/>
            <field name="AffiliateId"/>
            <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"/>
            <field name="InvoiceId">
                <relationship table="Invoice" field="Id" type="MANY_ONE"/>
            </field>
            <field name="InvoiceAmt"/>
            <field name="Discount"/>
            <field name="DateCreated"/>
            <field name="Description"/>
            <field name="CommissionStatus"/>
        </fields>
    </table>

    <table name="InvoicePayment" access="R">
        <fields>
            <field name="Id"/>
            <field name="InvoiceId">
                <relationship table="Invoice" field="Id" type="MANY_ONE"/>
            </field>
            <field name="Amt"/>
            <field name="PayDate"/>
            <field name="PayStatus"/>
            <field name="SkipCommission"/>
        </fields>
    </table>

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

    <table name="PayPlanItem" access="R">
        <fields>
            <field name="Id"/>
            <field name="PayPlanId">
                <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"/>
            <field name="PayDate"/>
            <field name="UserId"/>
            <field name="PayAmt"/>
            <field name="PayType"/>
            <field name="ContactId">
                <relationship table="Contact" field="Id" type="MANY_ONE"/>
            </field>
            <field name="PayNote"/>
            <field name="InvoiceId">
                <relationship table="Invoice" field="Id" type="MANY_ONE"/>
            </field>
            <field name="RefundId"/>
            <field name="ChargeId"/>
            <field name="Commission"/>
            <field name="Synced"/>
        </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"/>
            <field name="RecurringId">
                <relationship table="RecurringOrder" field="Id" type="MANY_ONE"/>
            </field>
            <field name="InvoiceItemId">
                <relationship table="InvoiceItem" field="Id" type="MANY_ONE"/>
            </field>
            <field name="Status"/>
            <field name="AutoCharge"/>
            <field name="StartDate"/>
            <field name="EndDate"/>
            <field name="DateCreated"/>
            <field name="Description"/>
        </fields>
    </table>

    <table name="OrderItem" access="R">
        <fields>
            <field name="Id"/>
            <field name="OrderId">
                <relationship table="Order" field="Id" type="MANY_ONE"/>
            </field>
            <field name="ProductId">
                <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">
                <relationship table="InvoiceItem" field="Id" type="MANY_ONE"/>
            </field>
            <field name="ItemType"/>
        </fields>
    </table>

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

    <table name="ContactAction" access="EDAR">
        <fields>
            <field name="Id" type="int"/>
            <field name="ContactId" type="int">
                <relationship table="Contact" field="Id" type="MANY_ONE" />
            </field>
            <field name="OpportunityId" type="int">
                <relationship table="Opportunity" field="Id" type="MANY_ONE" />
            </field>
            <field name="ActionType" type="string"/>
            <field name="ActionDescription" type="string"/>
            <field name="CreationDate" type="date"/>
            <field name="CreationNotes" type="string"/>
            <field name="CompletionDate" type="date"/>
            <field name="ActionDate" type="date"/>
            <field name="EndDate" type="date"/>
            <field name="PopupDate" type="date"/>
            <field name="UserID" type="int">
                <relationship field="Id" table="User" type="MANY_ONE"/>
            </field>
            <field name="Accepted" type="int"/>
            <field name="CreatedBy" type="int">
                 <relationship field="Id" table="User" type="MANY_ONE"/>
            </field>
            <field name="Priority" type="int"/>
            <field name="IsAppointment" type="int"/>

        </fields>
    </table>

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

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

            <field name="Stage"/>
            <field name="Priority"/>
            <field name="Ordering"/>

            <field name="DateCreated"/>
            <field name="CreatedBy"/>
            <field name="LastUpdated"/>
            <field name="LastUpdatedBy"/>

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

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

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

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

    <table name="DataFormTab" access="R">
        <fields>
            <field name="Id" type="int"/>
            <field name="FormId" type="int"/>
            <field name="TabName" sql-select="GroupName" type="string"/>
        </fields>
    </table>

    <table name="DataFormGroup" access="R">
        <fields>
            <field name="Id" type="int"/>
            <field name="TabId" type="int"/>
            <field name="Name" sql-select="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="int" access="R"/>
            <field name="Id" type="int" 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="int" access="R"/>
            <field name="GroupId" type="int">
                <relationship field="Id" table="DataFormGroup" type="MANY_ONE"/>
            </field>
            <field name="Label" sql-select="DisplayName" type="string"/>
            <field name="DefaultValue" type="string"/>
            <field name="Values" type="string"/>
            <field name="ListRows" type="int"/>
            <field name="UserGroup" type="int"/>
        </fields>
    </table>

    <table name="FileBox" access="EDAR">
        <fields>
            <field name="Id" type="int" access="R"/>
            <field name="FileName" type="string"/>
						<field name="Extension" type="string"/>
						<field name="FileSize" type="long"/>
						<field name="ContactId" type="int"/>
						<field name="Public" type="int"/>
        </fields>
    </table>

    <table name="SavedFilter" access="EDAR">
        <fields>
            <field name="Id" type="int" access="R"/>
            <field name="FilterName" type="string"/>
						<field name="ReportStoredName" type="string"/>
						<field name="UserId" type="int"/>
        </fields>
    </table>
    
</tables>