Beispiel #1
0
        public static DateTime LocalTimeToUTC(DateTime localTime, int?timeZoneCode, ContextWrapper contextWrapper)
        {
            if (!timeZoneCode.HasValue)
            {
                return(localTime);
            }

            var request = new UtcTimeFromLocalTimeRequest
            {
                TimeZoneCode = timeZoneCode.Value,
                LocalTime    = DateTime.SpecifyKind(localTime, DateTimeKind.Local)
            };

            var response = (UtcTimeFromLocalTimeResponse)contextWrapper.service.Execute(request);

            return(response.UtcTime);
        }
Beispiel #2
0
        public static void setPluginMessage(Entity target, String message, ContextWrapper contextWrapper)
        {
            // ensure the message is 200 chars or less
            if (message.Length > 200)
            {
                message = message.Substring(0, 200);
            }

            // add the message to the plugin message entity
            Entity pluginMessage = new Entity("fsip_pluginmessage");

            pluginMessage["fsip_name"] = message;
            Guid guid = contextWrapper.service.Create(pluginMessage);

            // add the reference to the target entity
            target["fsip_pluginmessage"] = new EntityReference("fsip_pluginmessage", guid);
        }
Beispiel #3
0
        // call on CRM to convert a UTC time to the local time
        public static DateTime UTCToLocalTime(DateTime utcTime, int?timeZoneCode, ContextWrapper contextWrapper)
        {
            if (!timeZoneCode.HasValue)
            {
                return(utcTime);
            }

            var request = new LocalTimeFromUtcTimeRequest
            {
                TimeZoneCode = timeZoneCode.Value,
                UtcTime      = DateTime.SpecifyKind(utcTime, DateTimeKind.Utc)
            };

            var response = (LocalTimeFromUtcTimeResponse)contextWrapper.service.Execute(request);

            return(response.LocalTime);
        }
Beispiel #4
0
        public static String getNextSequenceNumber(String which, ContextWrapper contextWrapper)
        {
            String nextSeqNum = String.Empty;

            String fetchXml = String.Format(@"
                <fetch distinct='false' mapping='logical' > 
                  <entity name='fsip_sequentialnumber'> 
                    <attribute name='fsip_prefix' /> 
                    <attribute name='fsip_nextnumber' /> 
                    <filter type='and'>
                        <condition attribute='fsip_name' operator='eq' value='{0}' />
                    </filter>
                  </entity> 
                </fetch>", which);

            // NOTE: This lock is useless on distributed servers
            lock (seqNumberLock)
            {
                EntityCollection seqnums = contextWrapper.service.RetrieveMultiple(new FetchExpression(fetchXml));
                if (seqnums.Entities.Count == 0)
                {
                    throw new InvalidPluginExecutionException("Please set up an entry in the Sequential Number entity for " + which);
                }

                if (seqnums.Entities.Count == 1)
                {
                    Entity seqnum = seqnums.Entities[0];

                    Decimal nextNumber = getDecimalValue(seqnum, "fsip_nextnumber");
                    String  prefix     = getStringValue(seqnum, "fsip_prefix");
                    nextSeqNum = String.Format("{0}-{1:0000000}", prefix, nextNumber);

                    seqnum["fsip_nextnumber"] = ++nextNumber;
                    contextWrapper.service.Update(seqnum);
                }
            }

            return(nextSeqNum);
        }
Beispiel #5
0
        public static void ExecuteAssociateDisassociate(ContextWrapper contextWrapper)
        {
            // see which relationship changed
            if (contextWrapper.context.InputParameters.Contains("Relationship") &&
                contextWrapper.context.InputParameters.Contains("Target") &&
                contextWrapper.context.InputParameters.Contains("RelatedEntities"))
            {
                Relationship              relationship      = (Relationship)contextWrapper.context.InputParameters["Relationship"];
                EntityReference           targetEntityRef   = (EntityReference)contextWrapper.context.InputParameters["Target"];
                EntityReferenceCollection relatedEntityRefs = contextWrapper.context.InputParameters["RelatedEntities"] as EntityReferenceCollection;
                EntityReference           relatedEntityRef  = relatedEntityRefs[0];

                String schemaName = relationship.SchemaName;

                //// Maintenance Contract and Device
                //if (relationship.SchemaName == "fsip_contract_new_servloc")
                //{
                //    // pushmepullyou - the Device can be the target or related depending on if this is "associate" or "disassociate"
                //    EntityReference deviceRef = targetEntityRef.LogicalName == "new_servloc" ? targetEntityRef : relatedEntityRef;
                //    MaintenanceContract.updateActiveContractFields(deviceRef, contextWrapper);
                //}
            }
        }
Beispiel #6
0
 public static void setEntityStatus(EntityReference entityRef, int state, int status, ContextWrapper contextWrapper)
 {
     contextWrapper.service.Execute(new SetStateRequest
     {
         EntityMoniker = entityRef,
         State         = new OptionSetValue(state),
         Status        = new OptionSetValue(status)
     });
 }
Beispiel #7
0
        //public static ServiceActivity.WageInfo getLaborRateWageInfo(EntityReference rateTableRef, ContextWrapper contextWrapper)
        //{
        //    ColumnSet cols = new ColumnSet
        //    (
        //        "fsip_overtime1laborcostrate",
        //        "fsip_overtime2laborcostrate",
        //        "fsip_paycode",
        //        "fsip_positionname",
        //        "fsip_regularlaborcostrate"
        //    );

        //    Entity laborRate = contextWrapper.service.Retrieve(rateTableRef.LogicalName, rateTableRef.Id, cols);
        //    return ServiceActivity.WageInfo.fromLaborRate(laborRate);
        //}

        //public static ServiceActivity.WageInfo getWageCategoryWageInfo(EntityReference rateTableRef, EntityReference wageCategoryRef, ContextWrapper contextWrapper)
        //{
        //    ServiceActivity.WageInfo wageInfo = null;

        //    if (wageCategoryRef != null)
        //    {

        //        String fetchXml = String.Format(@"
        //        <fetch mapping='logical'>
        //          <entity name='fsip_laborratedetail'>
        //            <filter>
        //              <condition attribute='statecode' operator='eq' value='0' />
        //              <condition attribute='fsip_laborrate' operator='eq' value='{0}' />
        //              <condition attribute='fsip_wagecategory' operator='eq' value='{1}' />
        //            </filter>
        //          </entity>
        //        </fetch>", rateTableRef.Id.ToString(), wageCategoryRef.Id.ToString());

        //        EntityCollection laborRateDetails = contextWrapper.service.RetrieveMultiple(new FetchExpression(fetchXml));
        //        if (laborRateDetails.Entities.Count == 1)
        //            wageInfo = ServiceActivity.WageInfo.fromLaborRateDetail(laborRateDetails.Entities[0]);
        //    }

        //    return wageInfo;
        //}

        //public static ServiceActivity.WageInfo getWageInfoToUse(ServiceActivity.WageInfo baseWageInfo, ServiceActivity.WageInfo wageCategoryWageInfo, String which)
        //{
        //    ServiceActivity.WageInfo wageInfo = baseWageInfo;

        //    if(wageCategoryWageInfo != null)
        //    {
        //        // compare the base wage info to the wage category wage info
        //        // in case of a tie, pick the wage category one
        //        switch(which)
        //        {
        //            case "reg":
        //                wageInfo = baseWageInfo.rateRegular > wageCategoryWageInfo.rateRegular ? baseWageInfo : wageCategoryWageInfo;
        //                break;
        //            case "OT":
        //                wageInfo = baseWageInfo.rateOT > wageCategoryWageInfo.rateOT ? baseWageInfo : wageCategoryWageInfo;
        //                break;
        //            case "DT":
        //                wageInfo = baseWageInfo.rateDT > wageCategoryWageInfo.rateDT ? baseWageInfo : wageCategoryWageInfo;
        //                break;
        //        }
        //    }

        //    return wageInfo;
        //}

        public static Entity getPriceListItem(Guid productId, Guid priceListId, Guid uomId, ContextWrapper contextWrapper)
        {
            Entity priceListItem = null;

            QueryExpression qe = new QueryExpression
            {
                EntityName = "productpricelevel",
                ColumnSet  = new ColumnSet("amount", "percentage", "pricingmethodcode"),
                Criteria   = new FilterExpression
                {
                    Conditions =
                    {
                        new ConditionExpression
                        {
                            AttributeName = "productid", Operator = ConditionOperator.Equal, Values ={ productId                                                                               }
                        },
                        new ConditionExpression
                        {
                            AttributeName = "pricelevelid", Operator = ConditionOperator.Equal, Values ={ priceListId                                                                             }
                        },
                        new ConditionExpression
                        {
                            AttributeName = "uomid", Operator = ConditionOperator.Equal, Values ={ uomId                                                                                   }
                        }
                    }
                }
            };

            EntityCollection priceListItems = contextWrapper.service.RetrieveMultiple(qe);

            if (priceListItems.Entities.Count == 1)
            {
                priceListItem = priceListItems.Entities[0];
            }

            return(priceListItem);
        }
Beispiel #8
0
 public static void traceAttributes(ContextWrapper contextWrapper, Entity entity)
 {
     contextWrapper.trace.Trace(getAttributesAsString(entity, String.Empty));
 }
Beispiel #9
0
        public Config(ContextWrapper contextWrapper)
        {
            string fetchXml = @"
            <fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false' no-lock='true'>
              <entity name='new_mapconfiguration'>
                <attribute name='fsip_approvesawhentimecardsapproved' />
                <attribute name='fsip_autogeneratebuildingid' />
                <attribute name='fsip_createprojectnumbers' />
                <attribute name='fsip_createtimecardswhensaismarkeddone' />
                <attribute name='fsip_defaultpaymentterm' />
                <attribute name='fsip_defaulttaxscheduleforaccounts' />
                <attribute name='fsip_defaulttaxscheduleforfreight' />
                <attribute name='fsip_enableinvoicetax' />
                <attribute name='fsip_enablequotetax' />
                <attribute name='fsip_enableworkordertax' />
                <attribute name='fsip_erpintegration' />
                <attribute name='fsip_externalbuildinglink' />
                <attribute name='fsip_mapsaactualtimestoscheduled' />
                <attribute name='fsip_overheadpercent' />
                <attribute name='fsip_retainageproduct' />
                <attribute name='fsip_syncsascheduledtimestoactual' />
                <attribute name='fsip_useoverridecostsinwototals' />
                <attribute name='new_googlekey' />
              </entity>
            </fetch>";

            EntityCollection collection = contextWrapper.service.RetrieveMultiple(new FetchExpression(fetchXml));

            // there must be one and only one config record
            switch (collection.Entities.Count)
            {
            case 0:
                throw new InvalidPluginExecutionException("There is no configuration record. Please set one up in the 'Settings' area.");

            case 1:
                Entity config = collection.Entities[0];

                _approvesawhentimecardsapproved    = RRUtils.getBoolValue(config, "fsip_approvesawhentimecardsapproved");
                _autogeneratebuildingid            = RRUtils.getBoolValue(config, "fsip_autogeneratebuildingid");
                _createProjectNumbers              = RRUtils.getBoolValue(config, "fsip_createprojectnumbers");
                _createtimecardswhensaismarkeddone = RRUtils.getBoolValue(config, "fsip_createtimecardswhensaismarkeddone");
                _defaultPaymentTerm            = RRUtils.getEntityReference(config, "fsip_defaultpaymentterm");
                _defaulttaxscheduleforaccounts = RRUtils.getEntityReference(config, "fsip_defaulttaxscheduleforaccounts");
                _defaulttaxscheduleforfreight  = RRUtils.getEntityReference(config, "fsip_defaulttaxscheduleforfreight");
                _enableinvoicetax            = RRUtils.getBoolValue(config, "fsip_enableinvoicetax");
                _enablequotetax              = RRUtils.getBoolValue(config, "fsip_enablequotetax");
                _enableworkordertax          = RRUtils.getBoolValue(config, "fsip_enableworkordertax");
                _erpIntegration              = RRUtils.getIntValue(config, "fsip_erpintegration");
                _externalBuildingLink        = RRUtils.getIntValue(config, "fsip_externalbuildinglink");
                _googleApiKey                = RRUtils.getStringValue(config, "new_googlekey");
                _mapsaactualtimestoscheduled = RRUtils.getBoolValue(config, "fsip_mapsaactualtimestoscheduled");
                _overheadPct                  = RRUtils.getDecimalValue(config, "fsip_overheadpercent");
                _retainageProduct             = RRUtils.getEntityReference(config, "fsip_retainageproduct");
                _syncsascheduledtimestoactual = RRUtils.getBoolValue(config, "fsip_syncsascheduledtimestoactual");
                _useoverridecostsinwototals   = RRUtils.getBoolValue(config, "fsip_useoverridecostsinwototals");;

                break;

            default:
                throw new InvalidPluginExecutionException("More than one configuration record found. Please ensure only one Config record exisits.");
            }
        }