private Money RetrivePrice(Entity vehicleCabChassis) { /* Legend: * itemType = 1 : Accessory * itemType = 2 : Cab Chassis */ PriceListHandler priceListHandler = new PriceListHandler(_organizationService, _tracingService); priceListHandler.itemType = 2; priceListHandler.productFieldName = "gsc_itemid"; List <Entity> latestPriceList = priceListHandler.RetrievePriceList(vehicleCabChassis, 100000000, 100000002); if (latestPriceList.Count > 0) { Entity priceListItem = latestPriceList[0]; Entity priceList = latestPriceList[1]; return(priceListItem.GetAttributeValue <Money>("amount")); } else { throw new InvalidPluginExecutionException("There is no effective Price List for the selected item."); } }
//Create By: Raphael Herrera, Created On: 7/12/2016 /* //Modified By: Leslie Baliguat, Modified On: 01/25/17 /* Purpose: Set DNP Amount * Registration Details: * Event/Message: * Post/Update: * Primary Entity: VehiclePurchaseOrderDetail */ public decimal SetDNPAmount(Entity vpoDetail) { _tracingService.Trace("Started SetDNPAmount method..."); var productId = vpoDetail.GetAttributeValue <EntityReference>("gsc_productid") != null ? vpoDetail.GetAttributeValue <EntityReference>("gsc_productid").Id : Guid.Empty; if (productId != Guid.Empty) { Money amount = new Money(); var dateToday = DateTime.Now.ToShortDateString(); PriceListHandler priceListHandler = new PriceListHandler(_organizationService, _tracingService); priceListHandler.itemType = 0; priceListHandler.productFieldName = "gsc_productid"; List <Entity> latestPriceList = priceListHandler.RetrievePriceList(vpoDetail, 100000001, 0); if (latestPriceList.Count > 0) { Entity priceListItem = latestPriceList[0]; Entity priceList = latestPriceList[1]; amount = new Money(priceListItem.GetAttributeValue <Money>("amount").Value); vpoDetail["gsc_dnpamount"] = amount; _organizationService.Update(vpoDetail); _tracingService.Trace("Updated DNP Amount to " + amount.Value); _tracingService.Trace("Ending SetDNPAmount method..."); ComputeVAT(vpoDetail, latestPriceList); return(amount.Value); } else { throw new InvalidPluginExecutionException("There is no effecive DNP Price List for the selected Vehicle."); } } return(0); }
/// <summary> /// Executes the plug-in. /// </summary> /// <param name="localContext">The <see cref="LocalPluginContext"/> which contains the /// <see cref="IPluginExecutionContext"/>, /// <see cref="IOrganizationService"/> /// and <see cref="ITracingService"/> /// </param> /// <remarks> /// For improved performance, Microsoft Dynamics CRM caches plug-in instances. /// The plug-in's Execute method should be written to be stateless as the constructor /// is not called for every invocation of the plug-in. Also, multiple system threads /// could execute the plug-in at the same time. All per invocation state information /// is stored in the context. This means that you should not use global variables in plug-ins. /// </remarks> protected void ExecutePostPriceListCreate(LocalPluginContext localContext) { if (localContext == null) { throw new ArgumentNullException("localContext"); } IPluginExecutionContext context = localContext.PluginExecutionContext; IOrganizationService service = localContext.OrganizationService; ITracingService trace = localContext.TracingService; Entity entity = (Entity)context.InputParameters["Target"]; try { PriceListHandler priceListHandler = new PriceListHandler(service, trace); priceListHandler.ValidateGlobal(entity); } catch (Exception ex) { throw new InvalidPluginExecutionException(ex.ToString()); } }
/// <summary> /// Executes the plug-in. /// </summary> /// <param name="localContext">The <see cref="LocalPluginContext"/> which contains the /// <see cref="IPluginExecutionContext"/>, /// <see cref="IOrganizationService"/> /// and <see cref="ITracingService"/> /// </param> /// <remarks> /// For improved performance, Microsoft Dynamics CRM caches plug-in instances. /// The plug-in's Execute method should be written to be stateless as the constructor /// is not called for every invocation of the plug-in. Also, multiple system threads /// could execute the plug-in at the same time. All per invocation state information /// is stored in the context. This means that you should not use global variables in plug-ins. /// </remarks> protected void ExecutePrePriceListCreate(LocalPluginContext localContext) { if (localContext == null) { throw new ArgumentNullException("localContext"); } IPluginExecutionContext context = localContext.PluginExecutionContext; IOrganizationService service = localContext.OrganizationService; ITracingService trace = localContext.TracingService; Entity priceList = (Entity)context.InputParameters["Target"]; try { PriceListHandler priceListItemHandler = new PriceListHandler(service, trace); priceListItemHandler.CheckIfThereIsExistingDefaultPriceList(priceList); } catch (Exception ex) { throw new InvalidPluginExecutionException(ex.Message); } }
/// <summary> /// Executes the plug-in. /// </summary> /// <param name="localContext">The <see cref="LocalPluginContext"/> which contains the /// <see cref="IPluginExecutionContext"/>, /// <see cref="IOrganizationService"/> /// and <see cref="ITracingService"/> /// </param> /// <remarks> /// For improved performance, Microsoft Dynamics CRM caches plug-in instances. /// The plug-in's Execute method should be written to be stateless as the constructor /// is not called for every invocation of the plug-in. Also, multiple system threads /// could execute the plug-in at the same time. All per invocation state information /// is stored in the context. This means that you should not use global variables in plug-ins. /// </remarks> protected void ExecutePostPriceListUpdate(LocalPluginContext localContext) { if (localContext == null) { throw new ArgumentNullException("localContext"); } IPluginExecutionContext context = localContext.PluginExecutionContext; IOrganizationService service = localContext.OrganizationService; ITracingService trace = localContext.TracingService; Entity preImageEntity = (context.PreEntityImages != null && context.PreEntityImages.Contains(this.preImageAlias)) ? context.PreEntityImages[this.preImageAlias] : null; Entity postImageEntity = (context.PostEntityImages != null && context.PostEntityImages.Contains(this.postImageAlias)) ? context.PostEntityImages[this.postImageAlias] : null; if (!(context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)) { return; } if (postImageEntity.LogicalName != "pricelevel") { return; } string message = context.MessageName; if (context.Mode == 0) //synchronous plugin { try { PriceListHandler priceListHandler = new PriceListHandler(service, trace); var preImageDefault = preImageEntity.GetAttributeValue <Boolean>("gsc_default"); var preImagePublish = preImageEntity.GetAttributeValue <Boolean>("gsc_publish"); var preImageGlobal = preImageEntity.GetAttributeValue <Boolean>("gsc_isglobalrecord"); var preImageTransactionType = preImageEntity.GetAttributeValue <OptionSetValue>("gsc_transactiontype").Value; var postImageDefault = postImageEntity.GetAttributeValue <Boolean>("gsc_default"); var postImagePublish = postImageEntity.GetAttributeValue <Boolean>("gsc_publish"); var postImageGlobal = postImageEntity.GetAttributeValue <Boolean>("gsc_isglobalrecord"); var postImageTransactionType = postImageEntity.GetAttributeValue <OptionSetValue>("gsc_transactiontype").Value; if (preImageDefault != postImageDefault || preImageTransactionType != postImageTransactionType) { priceListHandler.ChangeDefaultPriceList(postImageEntity); priceListHandler.SendDefaultPriceListNotification(postImageEntity); } if (preImagePublish != postImagePublish) { priceListHandler.ValidateGlobal(postImageEntity); priceListHandler.PublishPromoNotification(postImageEntity); priceListHandler.PublishPriceListNotification(postImageEntity); priceListHandler.UpdateAccessorySellPrice(postImageEntity); } } catch (Exception ex) { //throw new InvalidPluginExecutionException(String.Concat("(Exception)\n", ex.Message, Environment.NewLine, ex.StackTrace, Environment.NewLine, error)); throw new InvalidPluginExecutionException(ex.Message); } } }
public IHttpActionResult GetVehicleUnitPrice(Guid productId, int markUp) { try { var context = HttpContext.Current; Guid branchId = Guid.Empty; if (context != null) { var request = context.Request.RequestContext; var cookies = request.HttpContext.Request.Cookies; if (cookies != null) { if (cookies["Branch"] != null) { branchId = new Guid(cookies["Branch"]["branchId"]); } } } if (branchId == Guid.Empty) { return(InternalServerError(new Exception("Couldn't determine current branch."))); } if (productId != Guid.Empty) { decimal sellPrice = 0; PriceListHandler priceListHandler = new PriceListHandler(_conn.ServiceContext); priceListHandler.itemType = 0; priceListHandler.productFieldName = "gsc_productid"; Entity quoteEntity = new Entity(); quoteEntity.Attributes.Add("gsc_branchid", new EntityReference("account", branchId)); quoteEntity.Attributes.Add("gsc_productid", new EntityReference("product", productId)); Entity productEntity = _conn.ServiceContext.Retrieve("product", productId, new ColumnSet("gsc_taxrate")); List <Entity> latestPriceList = priceListHandler.RetrievePriceList(quoteEntity, 100000000, 100000003); if (latestPriceList.Count > 0) { Entity priceListItem = latestPriceList[0]; Entity priceList = latestPriceList[1]; sellPrice = priceListItem.GetAttributeValue <Money>("amount").Value; decimal taxStatus = priceList.GetAttributeValue <OptionSetValue>("gsc_taxstatus").Value; var taxRate = productEntity.Contains("gsc_taxrate") ? (Decimal)productEntity.GetAttributeValue <Double>("gsc_taxrate") : 0; if (markUp != 0) { markUp = markUp / 100; } if (taxRate != 0) { taxRate = taxRate / 100; } if (taxStatus == 100000001) { sellPrice = (sellPrice * (1 + taxRate)); } sellPrice = sellPrice * (1 + markUp); } else { return(InternalServerError(new Exception("There is no effective Price List for the selected Vehicle."))); } return(Ok(sellPrice)); } return(InternalServerError(new Exception("No Vehicle Price Found."))); } catch (Exception ex) { return(InternalServerError(ex)); } }
//Created By: Leslie G. Baliguat //Create By: Raphael Herrera, Created On: 2/06/2017 /* /* Purpose: Set DNP Amount * Registration Details: * Event/Message: * Post/Update: productid * Primary Entity: ReceivingDetails */ public Entity SetDNPAmount(Entity receivingDetail) { _tracingService.Trace("Started SetDNPAmount method..."); var productId = receivingDetail.GetAttributeValue <EntityReference>("gsc_productid") != null ? receivingDetail.GetAttributeValue <EntityReference>("gsc_productid").Id : Guid.Empty; Money amount = new Money(); var dateToday = DateTime.Now.ToShortDateString(); PriceListHandler priceListHandler = new PriceListHandler(_organizationService, _tracingService); priceListHandler.itemType = 0; priceListHandler.productFieldName = "gsc_productid"; List <Entity> latestPriceList = priceListHandler.RetrievePriceList(receivingDetail, 100000001, 0); if (latestPriceList.Count > 0) { Entity priceListItem = latestPriceList[0]; Entity priceList = latestPriceList[1]; amount = new Money(priceListItem.GetAttributeValue <Money>("amount").Value); receivingDetail["gsc_dnpamount"] = amount; _tracingService.Trace("Updated DNP Amount to " + amount.Value); _tracingService.Trace("Ending SetDNPAmount method..."); ComputeVAT(receivingDetail, latestPriceList); } else { throw new InvalidPluginExecutionException("There is no effecive DNP Price List for the selected Vehicle."); } //Get Price List where begin date is less than or equal to current date and end date is greater than than or equak to current date /* var priceLevelConditionList = new List<ConditionExpression> * { * new ConditionExpression("gsc_transactiontype", ConditionOperator.Equal, 100000001), * new ConditionExpression("begindate", ConditionOperator.LessEqual, dateToday), * new ConditionExpression("enddate", ConditionOperator.GreaterEqual, dateToday) * }; * * EntityCollection priceListCollection = CommonHandler.RetrieveRecordsByConditions("pricelevel", priceLevelConditionList, _organizationService, "begindate", OrderType.Descending, * new[] { "gsc_transactiontype", "begindate", "enddate", "gsc_taxstatus" }); * * _tracingService.Trace(priceListCollection.Entities.Count + " price list records retrieved..."); * * if (priceListCollection != null && priceListCollection.Entities.Count > 0) * { * Entity priceListEntity = priceListCollection.Entities[0]; * var priceListItemConditionList = new List<ConditionExpression> * { * new ConditionExpression("pricelevelid", ConditionOperator.Equal, priceListEntity.Id), * new ConditionExpression("productid", ConditionOperator.Equal, productId) * }; * * EntityCollection priceListItemCollection = CommonHandler.RetrieveRecordsByConditions("productpricelevel", priceListItemConditionList, _organizationService, null, OrderType.Ascending, * new[] { "amount" }); * * _tracingService.Trace(priceListItemCollection.Entities.Count + " price list item records retrieved..."); * * if (priceListItemCollection.Entities.Count > 0) * { * amount = new Money(priceListItemCollection.Entities[0].GetAttributeValue<Money>("amount").Value); * receivingDetail["gsc_dnpamount"] = amount; * _tracingService.Trace("Updated DNP Amount to " + amount.Value); * ComputeVAT(receivingDetail, priceListEntity); * * } * else * throw new InvalidPluginExecutionException("Vehicle selected is not yet included in the most recent DNP Price List."); * } * else * throw new InvalidPluginExecutionException("There is no effecive DNP Price List.");*/ _tracingService.Trace("Ending SetDNPAmount method..."); return(receivingDetail); }