internal static CustomerOrderInfo GetInfoFromTransaction(CustomerOrderTransaction customerOrder) { CustomerOrderInfo parameters = new CustomerOrderInfo(); //GRW DAC odac = new DAC(SalesOrder.InternalApplication.Settings.Database.Connection); DataTable dt = odac.GetContactData(customerOrder.TransactionId, customerOrder.TerminalId, customerOrder.StoreId); if (dt.Rows.Count > 0) { parameters.CustName = dt.Rows[0]["NAME"].ToString(); parameters.CustPhone = dt.Rows[0]["PHONE"].ToString(); parameters.Email = dt.Rows[0]["EMAIL"].ToString(); } //GRW parameters.OrderType = customerOrder.OrderType; parameters.Id = customerOrder.OrderId; parameters.TransactionId = customerOrder.TransactionId; parameters.QuotationId = customerOrder.OrderId; parameters.AutoPickOrder = false; parameters.WarehouseId = customerOrder.WarehouseId; parameters.CurrencyCode = customerOrder.StoreCurrencyCode; parameters.StoreId = customerOrder.StoreId; parameters.TerminalId = customerOrder.TerminalId; parameters.LocalHourOfDay = customerOrder.LocalHourOfDay; parameters.AddressRecordId = (customerOrder.ShippingAddress != null) ? customerOrder.ShippingAddress.AddressRecId : string.Empty; parameters.CustomerAccount = (customerOrder.Customer != null) ? customerOrder.Customer.CustomerId : string.Empty; parameters.SalespersonStaffId = (customerOrder.SalesPersonId) ?? string.Empty; // The format must match the expected format in AX RetailTransactionService.CreateCustomerOrder: "dd/MM/yyyy" parameters.ExpiryDateString = customerOrder.ExpirationDate.ToString(FixedDateFormat); parameters.RequestedDeliveryDateString = customerOrder.RequestedDeliveryDate.ToString(FixedDateFormat); parameters.DeliveryMode = customerOrder.DeliveryMode != null ? customerOrder.DeliveryMode.Code : string.Empty; parameters.PrepaymentAmountOverridden = customerOrder.PrepaymentAmountOverridden; parameters.PrepaymentAmountApplied = customerOrder.NetAmountWithTaxAndCharges - customerOrder.AmountDue; parameters.TotalManualDiscountAmount = customerOrder.TotalManualDiscountAmount; parameters.TotalManualDiscountPercentage = customerOrder.TotalManualPctDiscount; //parameters.Email = customerOrder.ReceiptEmailAddress; parameters.Comment = ((IPosTransactionV1)customerOrder).Comment; parameters.ReturnReasonCodeId = customerOrder.ReturnReasonCodeId; parameters.LoyaltyCardId = (customerOrder.LoyaltyItem != null) ? customerOrder.LoyaltyItem.LoyaltyCardNumber : string.Empty; // If we do not have the channel reference identifier, we create a new receipt identifier instead. parameters.ChannelReferenceId = customerOrder.ChannelReferenceId; parameters.CreditCardToken = customerOrder.CreditCardToken; // Discount codes parameters.DiscountCodes = new Collection <string>(); foreach (string code in customerOrder.DiscountCodes) { parameters.DiscountCodes.Add(code); } // Line Items parameters.Items = new Collection <ItemInfo>(); foreach (SaleLineItem item in customerOrder.SaleItems) { if (!item.Voided) { string deliveryMode = parameters.DeliveryMode; if (item.DeliveryMode != null) { deliveryMode = item.DeliveryMode.Code; } string deliveryDateString = parameters.RequestedDeliveryDateString; if (item.DeliveryDate.HasValue) { deliveryDateString = item.DeliveryDate.Value.ToString(FixedDateFormat); } Collection <ChargeInfo> lineChargeInfo = new Collection <ChargeInfo>(); foreach (Tax.MiscellaneousCharge charge in item.MiscellaneousCharges) { lineChargeInfo.Add(new ChargeInfo() { Amount = charge.Amount, Code = charge.ChargeCode, SalesTaxGroup = charge.SalesTaxGroupId, TaxGroup = charge.TaxGroupId }); } // If no line-level warehouse is specified, fall back to the header warehouse string inventLocationId = string.IsNullOrWhiteSpace(item.DeliveryWarehouse) ? customerOrder.WarehouseId : item.DeliveryWarehouse; // AX SO line stores discount amount per item, POS stores for whole line, calculate per item discount amount decimal lineDiscount = (item.Quantity == 0M ? 0M : (item.TotalDiscount + item.LineDiscount + item.PeriodicDiscount) / (item.Quantity)); // Save all discount lines per sales line Collection <DiscountInfo> lineDiscountInfo = new Collection <DiscountInfo>(); foreach (DiscountItem discountLine in item.DiscountLines) { DiscountInfo discountInfo = new DiscountInfo(); discountInfo.DiscountCode = string.Empty; discountInfo.PeriodicDiscountOfferId = string.Empty; discountInfo.EffectiveAmount = discountLine.EffectiveAmount; discountInfo.DealPrice = discountLine.DealPrice; discountInfo.Percentage = discountLine.Percentage; discountInfo.DiscountAmount = discountLine.Amount; LineDiscountItem lineDiscountItem; PeriodicDiscountItem periodicDiscountItem; CustomerDiscountItem customerDiscountItem; if ((lineDiscountItem = discountLine as LineDiscountItem) != null) { discountInfo.DiscountOriginType = (int)lineDiscountItem.LineDiscountType; if ((periodicDiscountItem = discountLine as PeriodicDiscountItem) != null) { discountInfo.PeriodicDiscountOfferId = periodicDiscountItem.OfferId; discountInfo.DiscountCode = periodicDiscountItem.DiscountCode; } else if ((customerDiscountItem = discountLine as CustomerDiscountItem) != null) { discountInfo.CustomerDiscountType = (int)customerDiscountItem.CustomerDiscountType; } else { discountInfo.DiscountOriginType = (int)LineDiscountItem.DiscountTypes.Manual; discountInfo.ManualDiscountType = (int)discountLine.GetManualDiscountType(); } } if (discountLine is TotalDiscountItem) { discountInfo.DiscountOriginType = (int)LineDiscountItem.DiscountTypes.Manual; discountInfo.ManualDiscountType = (int)discountLine.GetManualDiscountType(); } lineDiscountInfo.Add(discountInfo); } parameters.Items.Add(new ItemInfo() { RecId = item.OrderLineRecordId, //quantity ItemId = item.ItemId, Quantity = item.Quantity, Unit = item.SalesOrderUnitOfMeasure, //pricing Price = item.Price, Discount = lineDiscount, NetAmount = item.NetAmount, ItemTaxGroup = item.TaxGroupId, SalesTaxGroup = item.SalesTaxGroupId, SalesMarkup = item.SalesMarkup, PeriodicDiscount = item.PeriodicDiscount, LineDscAmount = item.LineDiscount, LineManualDiscountAmount = item.LineManualDiscountAmount, LineManualDiscountPercentage = item.LineManualDiscountPercentage, TotalDiscount = item.TotalDiscount, TotalPctDiscount = item.TotalPctDiscount, PeriodicPercentageDiscount = item.PeriodicPctDiscount, //Comment Comment = item.Comment, //delivery WarehouseId = inventLocationId, AddressRecordId = item.ShippingAddress != null ? item.ShippingAddress.AddressRecId : null, DeliveryMode = deliveryMode, RequestedDeliveryDateString = deliveryDateString, //inventDim BatchId = item.BatchId, SerialId = item.SerialId, VariantId = item.Dimension.VariantId, ColorId = item.Dimension.ColorId, SizeId = item.Dimension.SizeId, StyleId = item.Dimension.StyleId, ConfigId = item.Dimension.ConfigId, //Return InvoiceId = item.ReturnInvoiceId, InventTransId = item.ReturnInvoiceInventTransId, //line-level misc. charges Charges = lineChargeInfo, //line-level discounts Discounts = lineDiscountInfo, }); } } // Header level Misc Charges parameters.Charges = new Collection <ChargeInfo>(); foreach (Tax.MiscellaneousCharge charge in customerOrder.MiscellaneousCharges) { parameters.Charges.Add(new ChargeInfo() { Code = charge.ChargeCode, Amount = charge.Amount, SalesTaxGroup = charge.SalesTaxGroupId, TaxGroup = charge.TaxGroupId }); } string CardType = ""; // Payments parameters.Payments = new Collection <PaymentInfo>(); foreach (ITenderLineItem tender in customerOrder.TenderLines) { CardType = ""; if (!tender.Voided) { ICardTenderLineItem cardTender = tender as ICardTenderLineItem; if (cardTender != null && cardTender.EFTInfo.IsAuthOnly) { // This is a Pre-Authorization record. IEFTInfo eft = cardTender.EFTInfo; parameters.Preauthorization = new Preauthorization() { PaymentPropertiesBlob = eft.PaymentProviderPropertiesXML }; } else if (tender.Amount != decimal.Zero) { // This is an actual payment record. DAC odac2 = new DAC(ApplicationSettings.Database.LocalConnection); CardType = odac2.getCardType(customerOrder.TransactionId, customerOrder.TerminalId, customerOrder.StoreId, tender.LineId, tender.TenderTypeId); parameters.Payments.Add(new PaymentInfo() { PaymentType = tender.TenderTypeId, Amount = string.IsNullOrEmpty(tender.CurrencyCode) ? tender.Amount : tender.ForeignCurrencyAmount, Currency = (tender.CurrencyCode) ?? string.Empty, CardType = string.IsNullOrEmpty(CardType) ? "":CardType }); } } } // Affiliations parameters.Affiliations = new Collection <AffiliationInfo>(); foreach (IAffiliation affiliation in customerOrder.AffiliationLines) { parameters.Affiliations.Add(new AffiliationInfo() { AffiliationId = affiliation.RecId, LoyaltyTierId = affiliation.LoyaltyTier }); } return(parameters); }
/// <summary> /// Creates a <see cref="LineLevelInformationViewModel" object/> /// </summary> /// <param name="saleLineItem">Reference to the line item. It will be modified on Commit.</param> public LineLevelInformationViewModel(SaleLineItem saleLineItem, CustomerOrderTransaction custTransaction) { this.transaction = custTransaction; bool IsPickupaux = false; string DelMode = ""; StoreDataManager storeDataManager = new StoreDataManager( SalesOrder.InternalApplication.Settings.Database.Connection, SalesOrder.InternalApplication.Settings.Database.DataAreaID); DAC odac = new DAC(SalesOrder.InternalApplication.Settings.Database.Connection); DataTable dt = odac.GetLineDataOV(custTransaction.TransactionId, custTransaction.TerminalId, custTransaction.StoreId, saleLineItem.LineId.ToString()); if (dt.Rows.Count > 0) { saleLineItem.DeliveryStoreNumber = dt.Rows[0]["STORENUMBER"].ToString(); IsPickupaux = dt.Rows[0]["ISPICKUP"].ToString() == "1"?true:false; DelMode = dt.Rows[0]["SHIPMODE"].ToString(); if (IsPickupaux) { IList <Microsoft.Dynamics.Retail.Pos.DataEntity.DeliveryMode> delmod = storeDataManager.GetDeliveryModes(); foreach (DeliveryMode mod in delmod) { if (mod.Code == DelMode) { saleLineItem.DeliveryMode = mod; } } } } this.deliveryStore = storeDataManager.GetStore(saleLineItem.DeliveryStoreNumber); this.saleLineItem = saleLineItem; this.LineItemId = saleLineItem.ItemId; this.Description = saleLineItem.Description; this.Quantity = saleLineItem.Quantity; this.DeliveryDate = saleLineItem.DeliveryDate; this.ShippingAddress = saleLineItem.ShippingAddress; this.ShippingMethodCode = saleLineItem.DeliveryMode != null ? saleLineItem.DeliveryMode.Code : string.Empty; // Since there is a difference between no shipping charge and a shipping charge of zero, we need to see if we have any shipping charges before summing them IEnumerable <Tax.MiscellaneousCharge> shippingCharges = saleLineItem.MiscellaneousCharges.Where(c => c.ChargeCode == ApplicationSettings.Terminal.ShippingChargeCode); if (shippingCharges.Any()) { this.ShippingCharge = shippingCharges.Sum(c => c.Price); } // Check for delivery mode on line first, then header IDeliveryMode deliveryMode = saleLineItem.DeliveryMode ?? custTransaction.DeliveryMode; bool hasPickupCode = deliveryMode != null && string.Equals(deliveryMode.Code, ApplicationSettings.Terminal.PickupDeliveryModeCode, StringComparison.OrdinalIgnoreCase); bool hasDeliveryDate = saleLineItem.DeliveryDate.HasValue; // we have to do this because if hasPickupCode == false, that does not mean that IsShipping will be set to true if (IsPickupaux) { this.IsPickup = IsPickupaux; this.IsShipping = !IsPickupaux; } else { this.IsPickup = hasPickupCode && hasDeliveryDate; this.IsShipping = !hasPickupCode && hasDeliveryDate; } }