private Document GetDocumentLineItem(DataSets.Order.CalculatedOrderDetailsRow row, Token lastToken, NorthwindConfig config) { #region Declarations LineItemDocument doc; string id; decimal discountPercentage; #endregion id = row.OrderID.ToString() + "-" + row.ProductID.ToString(); doc = new LineItemDocument(); doc.Id = id; if (lastToken.InitRequest) doc.LogState = LogState.Created; else if ((row.CreateID >= lastToken.SequenceNumber) && (row.CreateUser != config.CrmUser)) doc.LogState = LogState.Created; else if ((row.ModifyID >= lastToken.SequenceNumber) && (row.ModifyUser != config.CrmUser)) doc.LogState = LogState.Updated; doc.productid.Value = row.ProductID; //doc.orderquouteid.Value = row.OrderID; doc.uomid.Value = row.ProductID; doc.quantity.Value = row.IsQuantityNull() ? Convert.ToInt16(0) : row.Quantity; doc.listprice.Value = row.IsUnitPriceNull() ? new decimal(0) : row.UnitPrice; discountPercentage = row.IsDiscountNull() ? (decimal)0 : Convert.ToDecimal(row.Discount); //doc.discountsum.Value = (decimal)(short)doc.Quantity.Value * (decimal)doc.ListPrice.Value * discountPercentage; doc.discountsum.Value = (decimal)doc.listprice.Value * discountPercentage; doc.quotedprice.Value = (decimal)doc.listprice.Value * (1 - discountPercentage); //doc.quotedprice.Value = row.IsQuotePriceNull() ? new decimal(0) : Convert.ToDecimal(row.QuotePrice); doc.taxrate.Value = "0"; doc.tax.Value = new decimal(0); doc.quotedpricetotal.Value = Convert.ToDecimal(doc.quantity.Value) * Convert.ToDecimal(doc.quotedprice.Value); return doc; }
private SalesOrderLinePayload GetLineItem(DataSets.Order.CalculatedOrderDetailsRow row, NorthwindConfig config) { #region Declarations SalesOrderLinePayload payload; string id; decimal discountPercentage; #endregion id = row.OrderID.ToString() + "-" + row.ProductID.ToString(); payload = new SalesOrderLinePayload(); payload.LocalID = id; //payload.SyncUuid = GetUuid(id, "", SupportedResourceKinds.salesOrderLines); payload.SalesOrderLinetype.applicationID = id; payload.ForeignIds.Add("commodity", row.ProductID.ToString()); payload.ForeignIds.Add("salesOrder", row.OrderID.ToString()); payload.ForeignIds.Add("unitOfMeasure", row.ProductID.ToString()); payload.SalesOrderLinetype.quantitySpecified = true; payload.SalesOrderLinetype.quantity = row.IsQuantityNull() ? Convert.ToInt16(0) : row.Quantity; payload.SalesOrderLinetype.initialPriceSpecified = true; payload.SalesOrderLinetype.initialPrice = row.IsUnitPriceNull() ? new decimal(0) : row.UnitPrice; payload.SalesOrderLinetype.orderLineDiscountPercentSpecified = true; payload.SalesOrderLinetype.orderLineDiscountPercent = row.IsDiscountNull() ? (decimal)0 : Convert.ToDecimal(row.Discount); payload.SalesOrderLinetype.discountTotalSpecified = true; payload.SalesOrderLinetype.discountTotal = payload.SalesOrderLinetype.initialPrice * (decimal)payload.SalesOrderLinetype.orderLineDiscountPercent; payload.SalesOrderLinetype.costTotalSpecified = true; payload.SalesOrderLinetype.costTotal = (decimal)payload.SalesOrderLinetype.initialPrice * (1 - payload.SalesOrderLinetype.orderLineDiscountPercent); payload.SalesOrderLinetype.netTotalSpecified = true; payload.SalesOrderLinetype.netTotal = Convert.ToDecimal(payload.SalesOrderLinetype.quantity) * Convert.ToDecimal(payload.SalesOrderLinetype.costTotal); return payload; }