using System.Collections.Generic; using System.Linq; using AyaNova.Biz; using AyaNova.Models; namespace AyaNova.DataList { internal class CustomerDataList : DataListProcessingBase, IDataListInternalCriteria { public CustomerDataList(long translationId) { DefaultListAType = AyaType.Customer; SQLFrom = @"FROM ACUSTOMER LEFT JOIN AHEADOFFICE ON (ACUSTOMER.HEADOFFICEID = AHEADOFFICE.ID) LEFT JOIN ACONTRACT ON (ACUSTOMER.CONTRACTID = ACONTRACT.ID) LEFT JOIN LATERAL (SELECT serial AS LASTWORKORDERSERIAL, SERVICEDATE AS LASTWORKORDERSERVICEDATE, AWORKORDER.ID AS LASTWORKORDERID FROM AWORKORDER LEFT JOIN AWORKORDERSTATUS ON AWORKORDER.LASTSTATUSID = AWORKORDERSTATUS.ID WHERE AWORKORDER.CUSTOMERID = ACUSTOMER.ID ORDER BY AWORKORDER.SERVICEDATE DESC LIMIT 1) AS LWO ON TRUE"; var RoleSet = BizRoles.GetRoleSet(DefaultListAType); AllowedRoles = RoleSet.ReadFullRecord | RoleSet.Change; DefaultColumns = new List() { "customername", "customerphone1", "customeremail", "customerheadoffice" }; DefaultSortBy = new Dictionary() { { "customername", "+" } }; FieldDefinitions = new List(); FieldDefinitions.Add(new DataListFieldDefinition { FieldKey = "LastServiceWorkOrder", TKey = "LastServiceWorkOrder", AType = (int)AyaType.WorkOrder, UiFieldDataType = (int)UiFieldDataType.Integer, SqlIdColumnName = "lwo.LASTWORKORDERID", SqlValueColumnName = "lwo.lastworkorderserial" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "LastServiceWorkOrderServiceDate", FieldKey = "LastServiceWorkOrderServiceDate", UiFieldDataType = (int)UiFieldDataType.DateTime, SqlValueColumnName = "lwo.lastworkorderservicedate" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "CustomerName", FieldKey = "customername", AType = (int)AyaType.Customer, UiFieldDataType = (int)UiFieldDataType.Text, SqlIdColumnName = "acustomer.id", SqlValueColumnName = "acustomer.name", IsRowId = true }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "CustomerNotes", FieldKey = "customernotes", UiFieldDataType = (int)UiFieldDataType.Text, SqlValueColumnName = "acustomer.notes" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "Active", FieldKey = "customeractive", UiFieldDataType = (int)UiFieldDataType.Bool, SqlValueColumnName = "acustomer.active" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "Tags", FieldKey = "customertags", UiFieldDataType = (int)UiFieldDataType.Tags, SqlValueColumnName = "acustomer.tags" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "WebAddress", FieldKey = "customerwebaddress", UiFieldDataType = (int)UiFieldDataType.HTTP, SqlValueColumnName = "acustomer.webaddress" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "CustomerAlertNotes", FieldKey = "CustomerAlertNotes", UiFieldDataType = (int)UiFieldDataType.Text, SqlValueColumnName = "acustomer.alertnotes" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "HeadOffice", FieldKey = "customerheadoffice", UiFieldDataType = (int)UiFieldDataType.Text, AType = (int)AyaType.HeadOffice, SqlIdColumnName = "aheadoffice.id", SqlValueColumnName = "aheadoffice.name" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "CustomerBillHeadOffice", FieldKey = "customerbillheadoffice", UiFieldDataType = (int)UiFieldDataType.Bool, SqlValueColumnName = "acustomer.billheadoffice" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "CustomerTechNotes", FieldKey = "customertechnotes", UiFieldDataType = (int)UiFieldDataType.Text, SqlValueColumnName = "acustomer.technotes" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "CustomerAccountNumber", FieldKey = "customeraccountnumber", UiFieldDataType = (int)UiFieldDataType.Text, SqlValueColumnName = "acustomer.accountnumber" }); // FieldDefinitions.Add(new DataListFieldDefinition // { // TKey = "UsesBanking", // FieldKey = "customerusesbanking", // UiFieldDataType = (int)UiFieldDataType.Bool, // SqlValueColumnName = "acustomer.usesbanking" // }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "Contract", FieldKey = "customercontract", UiFieldDataType = (int)UiFieldDataType.Text, AType = (int)AyaType.Contract, SqlIdColumnName = "acontract.id", SqlValueColumnName = "acontract.name" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "ContractExpires", FieldKey = "customercontractexpires", UiFieldDataType = (int)UiFieldDataType.DateTime, SqlValueColumnName = "acustomer.contractexpires" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "CustomerPhone1", FieldKey = "customerphone1", UiFieldDataType = (int)UiFieldDataType.PhoneNumber, SqlValueColumnName = "acustomer.phone1" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "CustomerPhone2", FieldKey = "customerphone2", UiFieldDataType = (int)UiFieldDataType.PhoneNumber, SqlValueColumnName = "acustomer.phone2" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "CustomerPhone3", FieldKey = "customerphone3", UiFieldDataType = (int)UiFieldDataType.PhoneNumber, SqlValueColumnName = "acustomer.phone3" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "CustomerPhone4", FieldKey = "customerphone4", UiFieldDataType = (int)UiFieldDataType.PhoneNumber, SqlValueColumnName = "acustomer.phone4" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "CustomerPhone5", FieldKey = "customerphone5", UiFieldDataType = (int)UiFieldDataType.PhoneNumber, SqlValueColumnName = "acustomer.phone5" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "CustomerEmail", FieldKey = "customeremail", UiFieldDataType = (int)UiFieldDataType.EmailAddress, SqlValueColumnName = "acustomer.emailaddress" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "AddressPostalDeliveryAddress", FieldKey = "customerpostaddress", UiFieldDataType = (int)UiFieldDataType.Text, SqlValueColumnName = "acustomer.postaddress" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "AddressPostalCity", FieldKey = "customerpostcity", UiFieldDataType = (int)UiFieldDataType.Text, SqlValueColumnName = "acustomer.postcity" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "AddressPostalStateProv", FieldKey = "customerpostregion", UiFieldDataType = (int)UiFieldDataType.Text, SqlValueColumnName = "acustomer.postregion" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "AddressPostalCountry", FieldKey = "customerpostcountry", UiFieldDataType = (int)UiFieldDataType.Text, SqlValueColumnName = "acustomer.postcountry" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "AddressPostalPostal", FieldKey = "customerpostcode", UiFieldDataType = (int)UiFieldDataType.Text, SqlValueColumnName = "acustomer.postcode" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "AddressDeliveryAddress", FieldKey = "customeraddress", UiFieldDataType = (int)UiFieldDataType.Text, SqlValueColumnName = "acustomer.address" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "AddressCity", FieldKey = "customercity", UiFieldDataType = (int)UiFieldDataType.Text, SqlValueColumnName = "acustomer.city" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "AddressStateProv", FieldKey = "customerregion", UiFieldDataType = (int)UiFieldDataType.Text, SqlValueColumnName = "acustomer.region" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "AddressCountry", FieldKey = "customercountry", UiFieldDataType = (int)UiFieldDataType.Text, SqlValueColumnName = "acustomer.country" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "AddressPostal", FieldKey = "customeraddresspostal", UiFieldDataType = (int)UiFieldDataType.Text, SqlValueColumnName = "acustomer.addresspostal" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "AddressLatitude", FieldKey = "customerlatitude", UiFieldDataType = (int)UiFieldDataType.Decimal, SqlValueColumnName = "acustomer.latitude" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "AddressLongitude", FieldKey = "customerlongitude", UiFieldDataType = (int)UiFieldDataType.Decimal, SqlValueColumnName = "acustomer.longitude" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "CustomerCustom1", FieldKey = "customercustom1", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "acustomer.customfields" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "CustomerCustom2", FieldKey = "customercustom2", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "acustomer.customfields" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "CustomerCustom3", FieldKey = "customercustom3", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "acustomer.customfields" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "CustomerCustom4", FieldKey = "customercustom4", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "acustomer.customfields" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "CustomerCustom5", FieldKey = "customercustom5", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "acustomer.customfields" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "CustomerCustom6", FieldKey = "customercustom6", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "acustomer.customfields" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "CustomerCustom7", FieldKey = "customercustom7", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "acustomer.customfields" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "CustomerCustom8", FieldKey = "customercustom8", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "acustomer.customfields" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "CustomerCustom9", FieldKey = "customercustom9", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "acustomer.customfields" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "CustomerCustom10", FieldKey = "customercustom10", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "acustomer.customfields" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "CustomerCustom11", FieldKey = "customercustom11", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "acustomer.customfields" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "CustomerCustom12", FieldKey = "customercustom12", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "acustomer.customfields" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "CustomerCustom13", FieldKey = "customercustom13", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "acustomer.customfields" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "CustomerCustom14", FieldKey = "customercustom14", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "acustomer.customfields" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "CustomerCustom15", FieldKey = "customercustom15", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "acustomer.customfields" }); FieldDefinitions.Add(new DataListFieldDefinition { TKey = "CustomerCustom16", FieldKey = "customercustom16", IsCustomField = true, IsFilterable = false, IsSortable = false, SqlValueColumnName = "acustomer.customfields" }); //META COLUMNS FieldDefinitions.Add(new DataListFieldDefinition { FieldKey = "metaheadoffice", UiFieldDataType = (int)UiFieldDataType.InternalId, SqlIdColumnName = "aheadoffice.id", SqlValueColumnName = "aheadoffice.id", IsMeta = true //"I'm So Meta Even This Acronym" }); } public List DataListInternalCriteria(long currentUserId, AuthorizationRoles userRoles, string clientCriteria) { List ret = new List(); //ClientCriteria format for this list is "OBJECTID,AYATYPE" var crit = (clientCriteria ?? "").Split(',').Select(z => z.Trim()).ToArray(); if (crit.Length > 1) { //for now just show all customers of headoffice int nType = 0; if (!int.TryParse(crit[1], out nType)) return ret; AyaType forType = (AyaType)nType; if (forType != AyaType.HeadOffice) return ret; long lId = 0; if (!long.TryParse(crit[0], out lId)) return ret; if (lId == 0) return ret; //Have valid type, have an id, so filter away switch (forType) { case AyaType.HeadOffice: { DataListFilterOption FilterOption = new DataListFilterOption() { Column = "metaheadoffice" }; FilterOption.Items.Add(new DataListColumnFilter() { value = crit[0], op = DataListFilterComparisonOperator.Equality }); ret.Add(FilterOption); } break; } } return ret; } }//eoc }//eons