/// <summary> /// Recall a customer order by sales id. /// </summary> /// <param name="request">The request containing the sales id.</param> /// <returns>The response containing the sales order.</returns> private static RecallCustomerOrderRealtimeResponse RecallCustomerOrder(RecallCustomerOrderRealtimeRequest request) { if (request == null) { throw new ArgumentNullException("request"); } var client = new TransactionServiceClient(request.RequestContext); ReadOnlyCollection <object> transactionResponse; if (request.IsQuote) { transactionResponse = client.GetCustomerQuote(request.Id); } else { transactionResponse = client.GetCustomerOrder(request.Id, includeOnlineOrders: true); } var orderInfo = CustomerOrderInfo.FromXml(transactionResponse[0].ToString()); var order = SalesOrderHelper.GetSalesOrderFromInfo(orderInfo, request.RequestContext.GetChannelConfiguration(), request.RequestContext); // Check that the channel currency code is the same as the recalled order if (order != null && !string.IsNullOrWhiteSpace(order.CurrencyCode) && !request.RequestContext.GetChannelConfiguration().Currency.Equals(order.CurrencyCode, StringComparison.OrdinalIgnoreCase)) { throw new DataValidationException( DataValidationErrors.Microsoft_Dynamics_Commerce_Runtime_CurrencyChannelOrderMismatch, string.Format("Channel currency = {0} doesn't match sales order currency = {1}", request.RequestContext.GetChannelConfiguration().Currency, order.CurrencyCode)); } var response = new RecallCustomerOrderRealtimeResponse(order); return(response); }
/// <summary> /// Fills the customer order info object with affiliations and loyalty tiers from the sales transaction. /// </summary> /// <param name="parameters">CustomerOrderInfo object to be filled.</param> /// <param name="salesTransaction">The sales transaction to be used as a base.</param> private static void FillAffiliationsAndLoyaltyTiers(CustomerOrderInfo parameters, SalesTransaction salesTransaction) { var affiliations = salesTransaction.AffiliationLoyaltyTierLines.Select(line => new AffiliationInfo { AffiliationRecordId = line.AffiliationId, LoyaltyTierRecordId = line.LoyaltyTierId, AffiliationType = line.AffiliationType }); parameters.Affiliations.AddRange(affiliations.ToList()); }
public void loadDataByOrderNo(int orderNo) { using (entities = new DAL.Model.SilverEntities()) { var gridData = ( from ordDetail in entities.OrderDetails where ordDetail.orderNo == orderNo select ordDetail).ToList(); var bindingListSP = new BindingList <OrderDetail>(gridData); var sourceSP = new BindingSource(bindingListSP, null); dgvOrder.DataSource = null; dgvOrder.DataSource = sourceSP; dgvOrder.Columns["TID"].Visible = false; dgvOrder.Columns["Lcode"].Visible = false; dgvOrder.Columns["KID"].Visible = false; dgvOrder.Columns["artisanReqDate"].Visible = false; dgvOrder.Columns["orderPlacedDate"].Visible = false; dgvOrder.Columns["orderRecdDate"].Visible = false; dgvOrder.Columns["JobNo"].Visible = false; dgvOrder.Columns["orderType"].Visible = false; dgvOrder.Columns["orderNo"].Visible = false; dgvOrder.Columns["orderDate"].Visible = false; dgvOrder.Columns["PCode"].HeaderText = "Item Name"; dgvOrder.Columns["Qty"].HeaderText = "Quantity"; dgvOrder.Columns["Weight"].HeaderText = "Weight"; dgvOrder.Columns["TotalWeight"].HeaderText = "Total Weight"; var orderDetail = (from ordDetail in entities.CustomerOrderInfoes where ordDetail.orderNo == orderNo select ordDetail).ToList(); if (orderDetail != null) { CustomerOrderInfo orderInfo = orderDetail[0]; String custCode = orderInfo.lcode; var customerInfo = (from custInfo in entities.CustomerMs where custInfo.Code.Equals(custCode) select custInfo).ToList(); txtMetalRate.Text = orderInfo.metalRate.ToString(); dtDate.Value = orderInfo.orderDate.Value; dtDeliveryDate.Value = orderInfo.orderDeliveryDate.Value; txtRemark.Text = orderInfo.remark; myColumnComboBox.ValueMember = customerInfo[0].Code; DataTable table = (DataTable)myColumnComboBox.Data; DataRow[] foundRows = table.Select("Code = '" + customerInfo[0].Code + "'"); if (foundRows.Length > 0) { int SelectedIndex = table.Rows.IndexOf(foundRows[0]); myColumnComboBox.SelectedIndex = SelectedIndex; } calculateTotalWeight(); } } }
public async Task <CustomerOrderInfo> GetCustomerOrderInfo(string email, int orderId) { var user = await _userManager.FindByEmailAsync(email); using (IUnitOfWork unitOfWork = _unitOfWorkFactory.Create()) { var orderRepository = unitOfWork.Repository <Order>(); var autoRepository = unitOfWork.Repository <Auto>(); var order = await orderRepository.GetAsync(orderId); if (order == null || order.CustomerId != user.Id) { return(null); } var auto = await autoRepository.GetAsync((int)order.AutoId); var orderInfo = new CustomerOrderInfo() { OrderId = order.Id, Status = order.Status.ToString(), Date = order.Date.ToString("dd-MM-yyyy"), AutoRiaId = auto.AutoRiaId, MarkName = auto.MarkName, ModelName = auto.ModelName, Year = auto.Year, PhotoLink = auto.PhotoLink }; if (order.Status != OrderStatus.Canceled) { orderInfo.ReviewPropositions = GetReviewPropositions(order.Id); } if (order.Status == OrderStatus.Pending || order.Status == OrderStatus.Done) { orderInfo.MechanicId = (int)order.MechanicId; } if (order.Status == OrderStatus.Done) { orderInfo.ReviewId = (int)order.ReviewId; } return(orderInfo); } }
/// <summary> /// Fills a customer order info object with payment information from a sales transaction. /// </summary> /// <param name="parameters">CustomerOrderInfo object to be filled.</param> /// <param name="salesTransaction">The sales transaction to be used as base.</param> /// <param name="storeCurrency">The store currency.</param> private static void FillPaymentInformation(CustomerOrderInfo parameters, SalesTransaction salesTransaction, string storeCurrency) { foreach (TenderLine tenderLine in salesTransaction.TenderLines) { if (tenderLine.Status != TenderLineStatus.Voided && tenderLine.Status != TenderLineStatus.Historical && (tenderLine.Amount != decimal.Zero || !tenderLine.IsPreProcessed)) { PaymentInfo paymentInfo = new PaymentInfo() { PaymentType = tenderLine.TenderTypeId, CardType = tenderLine.CardTypeId ?? string.Empty, Amount = tenderLine.Currency == null ? tenderLine.AmountInCompanyCurrency : tenderLine.AmountInTenderedCurrency, Currency = tenderLine.Currency ?? storeCurrency, Prepayment = tenderLine.IsDeposit, CreditCardAuthorization = tenderLine.Authorization ?? string.Empty, PaymentCaptured = tenderLine.IsPaymentCaptured, CreditCardToken = tenderLine.CardToken ?? string.Empty }; parameters.Payments.Add(paymentInfo); } } }
/// <summary> /// Converts a sales transaction into the XML that transaction service can consume. /// </summary> /// <param name="salesTransaction">The sales transaction to be converted.</param> /// <param name="cardToken">The card token object.</param> /// <param name="cardTokenResponseXml">The card token response XML.</param> /// <param name="context">The request context.</param> /// <returns>The customer order info object.</returns> public static string ConvertSalesTransactionToXml( SalesTransaction salesTransaction, CardTokenInfo cardToken, string cardTokenResponseXml, RequestContext context) { string storeCurrency = context.GetChannelConfiguration().Currency; CustomerOrderInfo parameters = new CustomerOrderInfo(); parameters.OrderType = salesTransaction.CustomerOrderMode == CustomerOrderMode.QuoteCreateOrEdit ? CustomerOrderType.Quote : CustomerOrderType.SalesOrder; parameters.AutoPickOrder = false; parameters.Id = salesTransaction.SalesId; parameters.QuotationId = salesTransaction.SalesId; parameters.CustomerAccount = salesTransaction.CustomerId; parameters.ChannelRecordId = salesTransaction.ChannelId.ToString(CultureInfo.InvariantCulture); parameters.SalespersonStaffId = salesTransaction.StaffId ?? string.Empty; parameters.IsTaxIncludedInPrice = salesTransaction.IsTaxIncludedInPrice.ToString(); parameters.WarehouseId = salesTransaction.InventoryLocationId; parameters.CurrencyCode = storeCurrency; parameters.StoreId = salesTransaction.StoreId; parameters.TerminalId = salesTransaction.TerminalId; parameters.TransactionId = salesTransaction.Id; parameters.LocalHourOfDay = DateTime.Now.Hour + 1; // headquarters will match this value with an id parameters.AddressRecordId = SalesTransactionSerializationHelper.ConvertAddressRecIdToString(salesTransaction.ShippingAddress); parameters.ExpiryDateString = Utilities.ConvertDateToAxString(salesTransaction.QuotationExpiryDate); parameters.RequestedDeliveryDateString = Utilities.ConvertDateToAxString(salesTransaction.RequestedDeliveryDate); parameters.DeliveryMode = string.IsNullOrWhiteSpace(salesTransaction.DeliveryMode) ? string.Empty : salesTransaction.DeliveryMode; parameters.PrepaymentAmountOverridden = salesTransaction.IsDepositOverridden; parameters.PrepaymentAmountApplied = salesTransaction.PrepaymentAmountAppliedOnPickup; parameters.OriginalTransactionTime = DateTime.UtcNow; parameters.TotalManualDiscountAmount = salesTransaction.TotalManualDiscountAmount; parameters.TotalManualDiscountPercentage = salesTransaction.TotalManualDiscountPercentage; parameters.Email = salesTransaction.ReceiptEmail; parameters.Comment = salesTransaction.Comment ?? string.Empty; parameters.LoyaltyCardId = string.IsNullOrWhiteSpace(salesTransaction.LoyaltyCardId) ? string.Empty : salesTransaction.LoyaltyCardId; parameters.ChannelReferenceId = salesTransaction.ChannelReferenceId; parameters.ReturnReasonCodeId = SalesTransactionSerializationHelper.GetReturnReasonCodeId(salesTransaction, context); if (cardToken != null) { parameters.CreditCardToken = cardTokenResponseXml; } // Sales lines SalesTransactionSerializationHelper.FillSaleLines(parameters, salesTransaction); // Payments SalesTransactionSerializationHelper.FillPaymentInformation(parameters, salesTransaction, storeCurrency); // Charges SalesTransactionSerializationHelper.ConvertChargeLinesToChargeInfos(salesTransaction.ChargeLines, parameters.Charges); // Affiliations and loyalty tiers SalesTransactionSerializationHelper.FillAffiliationsAndLoyaltyTiers(parameters, salesTransaction); // Discount codes parameters.DiscountCodes.AddRange(salesTransaction.DiscountCodes.ToArray()); // Extension properties parameters.ExtensionProperties.AddRange(salesTransaction.ExtensionProperties); return(parameters.ToXml()); }
/// <summary> /// Fills a customer order info object with a sales transaction sales line information. /// </summary> /// <param name="parameters">The customer order info object to be filled.</param> /// <param name="salesTransaction">The sales transaction object used as source.</param> private static void FillSaleLines(CustomerOrderInfo parameters, SalesTransaction salesTransaction) { ProductVariant emptyVariant = new ProductVariant(); // Line Items foreach (SalesLine salesLine in salesTransaction.ActiveSalesLines) { if (!salesLine.IsVoided && !(salesTransaction.CustomerOrderMode == CustomerOrderMode.Return && salesLine.Quantity == 0)) { // use property from header, override with line property if available string deliveryMode = string.IsNullOrWhiteSpace(salesLine.DeliveryMode) ? parameters.DeliveryMode : salesLine.DeliveryMode; // use property from header, override with line property if available string deliveryDateString = Utilities.IsDateNullOrDefaultValue(salesLine.RequestedDeliveryDate) ? parameters.RequestedDeliveryDateString : Utilities.ConvertDateToAxString(salesLine.RequestedDeliveryDate); // If no line-level warehouse is specified, fall back to the header warehouse string inventLocationId = string.IsNullOrWhiteSpace(salesLine.InventoryLocationId) ? parameters.WarehouseId : salesLine.InventoryLocationId; // AX SO line stores discount amount per item, CRT stores for whole line, calculate per item discount amount decimal lineDiscount = salesLine.Quantity == 0M ? 0M : (salesLine.TotalDiscount + salesLine.LineDiscount + salesLine.PeriodicDiscount) / salesLine.Quantity; string lineAddress = SalesTransactionSerializationHelper.ConvertAddressRecIdToString(salesLine.ShippingAddress); // use header address is line does not have it set if (string.IsNullOrWhiteSpace(lineAddress)) { lineAddress = parameters.AddressRecordId; } ProductVariant variant = salesLine.Variant ?? emptyVariant; ItemInfo itemInfo = new ItemInfo() { RecId = salesLine.RecordId, // quantity ItemId = salesLine.ItemId, Quantity = salesLine.Quantity, Comment = salesLine.Comment, Unit = salesLine.SalesOrderUnitOfMeasure, // pricing Price = salesLine.Price, Discount = lineDiscount, NetAmount = salesLine.NetAmount, ItemTaxGroup = salesLine.ItemTaxGroupId, SalesTaxGroup = salesLine.SalesTaxGroupId, SalesMarkup = 0M, PeriodicDiscount = salesLine.PeriodicDiscount, PeriodicPercentageDiscount = salesLine.PeriodicPercentageDiscount, LineDscAmount = salesLine.LineDiscount, LineManualDiscountAmount = salesLine.LineManualDiscountAmount, LineManualDiscountPercentage = salesLine.LineManualDiscountPercentage, TotalDiscount = salesLine.TotalDiscount, TotalPctDiscount = salesLine.TotalPercentageDiscount, // delivery WarehouseId = inventLocationId, AddressRecordId = lineAddress, DeliveryMode = deliveryMode, RequestedDeliveryDateString = deliveryDateString, FulfillmentStoreId = salesLine.FulfillmentStoreId, // inventDim BatchId = salesLine.BatchId, SerialId = salesLine.SerialNumber, VariantId = variant.VariantId ?? string.Empty, ColorId = variant.ColorId ?? string.Empty, SizeId = variant.SizeId ?? string.Empty, StyleId = variant.StyleId ?? string.Empty, ConfigId = variant.ConfigId ?? string.Empty, // Return InvoiceId = salesLine.ReturnTransactionId, ReturnInventTransId = salesLine.ReturnInventTransId, Catalog = salesLine.CatalogId, Giftcard = false, }; // line-level misc. charges SalesTransactionSerializationHelper.ConvertChargeLinesToChargeInfos(salesLine.ChargeLines, itemInfo.Charges); // line -level discount SalesTransactionSerializationHelper.ConvertDiscountLineToDiscountInfos(salesLine.DiscountLines, itemInfo.Discounts); parameters.Items.Add(itemInfo); } } }
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); }
internal static CustomerOrderTransaction GetTransactionFromInfo(CustomerOrderInfo orderInfo, SalesOrder salesOrderService) { CustomerOrderTransaction transaction = (CustomerOrderTransaction)SalesOrder.InternalApplication.BusinessLogic.Utility.CreateCustomerOrderTransaction( ApplicationSettings.Terminal.StoreId, ApplicationSettings.Terminal.StoreCurrency, ApplicationSettings.Terminal.TaxIncludedInPrice, SalesOrder.InternalApplication.Services.Rounding, salesOrderService); // Get all the defaults SalesOrder.InternalApplication.BusinessLogic.TransactionSystem.LoadTransactionStatus(transaction); // General header properties transaction.OrderId = orderInfo.Id; transaction.OrderType = orderInfo.OrderType; if (orderInfo.OrderType == CustomerOrderType.Quote) { transaction.QuotationId = orderInfo.Id; } transaction.OriginalOrderType = orderInfo.OrderType; switch (orderInfo.OrderType) { case CustomerOrderType.Quote: transaction.OrderStatus = GetSalesStatus((SalesQuotationStatus)orderInfo.Status); break; case CustomerOrderType.SalesOrder: transaction.OrderStatus = GetSalesStatus((SalesOrderStatus)orderInfo.Status, (DocumentStatus)orderInfo.DocumentStatus); break; default: transaction.OrderStatus = SalesStatus.Unknown; NetTracer.Information("SalesOrder::CustomerOrderTransaction: CustomerOrderInfo OrderType is unknown: {0}", orderInfo.OrderType); break; } transaction.LockPrices = true; transaction.ExpirationDate = ParseDateString(orderInfo.ExpiryDateString, DateTime.Today); // RequestedDeliveryDate is directly input from user. It is stored in the local timezone transaction.RequestedDeliveryDate = ParseDateString(orderInfo.RequestedDeliveryDateString, DateTime.Today); // CreationDate is stored in UTC. It needs to be converted to local time zone where order is accessed. ((IPosTransactionV2)transaction).BeginDateTime = ParseDateString(orderInfo.CreationDateString, DateTime.UtcNow, DateTimeStyles.AdjustToUniversal).ToLocalTime(); transaction.LocalHourOfDay = orderInfo.LocalHourOfDay; ((IPosTransactionV2)transaction).Comment = orderInfo.Comment; // Header delivery DM.StoreDataManager storeDataManager = new DM.StoreDataManager( SalesOrder.InternalApplication.Settings.Database.Connection, SalesOrder.InternalApplication.Settings.Database.DataAreaID); transaction.WarehouseId = orderInfo.WarehouseId; transaction.DeliveryMode = storeDataManager.GetDeliveryMode(orderInfo.DeliveryMode); transaction.CurrencyCode = orderInfo.CurrencyCode; foreach (var code in orderInfo.DiscountCodes) { transaction.DiscountCodes.AddLast(code); } // Header affiliation DM.AffiliationDataManager affiliationDataManager = new DM.AffiliationDataManager( SalesOrder.InternalApplication.Settings.Database.Connection, SalesOrder.InternalApplication.Settings.Database.DataAreaID); if (orderInfo.Affiliations != null && orderInfo.Affiliations.Any()) { foreach (AffiliationInfo affiliationInfo in orderInfo.Affiliations) { transaction.AffiliationLines.AddLast( new AffiliationItem() { RecId = affiliationInfo.AffiliationId, LoyaltyTier = affiliationInfo.LoyaltyTierId, AffiliationType = affiliationInfo.AffiliationType }); } } // Customer info ICustomerSystem customerSystem = SalesOrder.InternalApplication.BusinessLogic.CustomerSystem; DM.CustomerDataManager customerDataManager = new DM.CustomerDataManager( SalesOrder.InternalApplication.Settings.Database.Connection, SalesOrder.InternalApplication.Settings.Database.DataAreaID); DE.ICustomer customer = customerSystem.GetCustomerInfo(orderInfo.CustomerAccount); // try to get the customer from transaction service if (customer == null || customer.IsEmptyCustomer()) { DE.ICustomer tempCustomer = SalesOrder.GetCustomerFromAX(orderInfo.CustomerAccount, customerSystem, customerDataManager); if (tempCustomer != null) { customer = tempCustomer; } } DE.ICustomer invoicedCustomer = customerSystem.GetCustomerInfo(customer.InvoiceAccount); // try to get the invoicedCustomer from transaction service if (invoicedCustomer == null || invoicedCustomer.IsEmptyCustomer()) { DE.ICustomer tempinvoicedCustomer = SalesOrder.GetCustomerFromAX(customer.InvoiceAccount, customerSystem, customerDataManager); if (tempinvoicedCustomer != null) { invoicedCustomer = tempinvoicedCustomer; } } // If InvoiceCustomer is *still* blank/empty then fallback to Customer so that the UI fields are populated. if (invoicedCustomer == null || invoicedCustomer.IsEmptyCustomer()) { invoicedCustomer = customer; } customerSystem.SetCustomer(transaction, customer, invoicedCustomer); if (transaction.DeliveryMode != null && !string.IsNullOrWhiteSpace(orderInfo.AddressRecordId)) { DE.IAddress shippingAddress = customerDataManager.GetAddress(Int64.Parse(orderInfo.AddressRecordId)); customerSystem.SetShippingAddress(transaction, shippingAddress); } if (!string.IsNullOrEmpty(orderInfo.SalespersonStaffId)) { // Sets the sales person id and name according to AX values // This is done because we do not know whether the sales person information is available on this store transaction.SalesPersonId = orderInfo.SalespersonStaffId; transaction.SalesPersonName = orderInfo.SalespersonName; DM.EmployeeDataManager employees = new DM.EmployeeDataManager( SalesOrder.InternalApplication.Settings.Database.Connection, SalesOrder.InternalApplication.Settings.Database.DataAreaID); Employee employee = employees.GetEmployee(ApplicationSettings.Terminal.StoreId, orderInfo.SalespersonStaffId); if (employee != null) { transaction.SalesPersonId = employee.StaffId; transaction.SalesPersonName = employee.Name; transaction.SalesPersonNameOnReceipt = employee.NameOnReceipt; } } transaction.ChannelReferenceId = orderInfo.ChannelReferenceId; if (transaction.LoyaltyItem != null && !string.IsNullOrEmpty(orderInfo.LoyaltyCardId)) { transaction.LoyaltyItem.LoyaltyCardNumber = orderInfo.LoyaltyCardId; } transaction.ReceiptEmailAddress = orderInfo.Email; transaction.TotalManualDiscountAmount = orderInfo.TotalManualDiscountAmount; transaction.TotalManualPctDiscount = orderInfo.TotalManualDiscountPercentage; DateTime earliestDeliveryDate = DateTime.MaxValue; // Items foreach (ItemInfo item in orderInfo.Items) { Collection <Tax.MiscellaneousCharge> lineCharges = new Collection <Tax.MiscellaneousCharge>(); foreach (ChargeInfo charge in item.Charges) { Tax.MiscellaneousCharge lineCharge = (Tax.MiscellaneousCharge)SalesOrder.InternalApplication.BusinessLogic.Utility.CreateMiscellaneousCharge( charge.Amount, charge.SalesTaxGroup, charge.TaxGroup, charge.Code, string.Empty, transaction); lineCharges.Add(lineCharge); } // add item SaleLineItem lineItem = (SaleLineItem)SalesOrder.InternalApplication.BusinessLogic.Utility.CreateSaleLineItem( ApplicationSettings.Terminal.StoreCurrency, SalesOrder.InternalApplication.Services.Rounding, transaction); lineItem.Found = true; lineItem.OrderLineRecordId = item.RecId; lineItem.ItemId = item.ItemId; lineItem.Quantity = item.Quantity; lineItem.ReturnQtyAllowed = item.Quantity; lineItem.SalesOrderUnitOfMeasure = item.Unit; lineItem.Price = item.Price; lineItem.NetAmount = item.NetAmount; lineItem.QuantityOrdered = item.Quantity; lineItem.QuantityPickedUp = item.QuantityPicked; lineItem.DeliveryMode = storeDataManager.GetDeliveryMode(item.DeliveryMode); lineItem.DeliveryDate = ParseDateString(item.RequestedDeliveryDateString, DateTime.Today); lineItem.DeliveryStoreNumber = item.StoreId; lineItem.DeliveryWarehouse = item.WarehouseId; lineItem.SerialId = item.SerialId; lineItem.BatchId = item.BatchId; lineItem.HasBeenRecalled = true; lineItem.SalesMarkup = item.SalesMarkup; lineItem.Comment = string.IsNullOrEmpty(item.Comment) ? string.Empty : item.Comment; lineItem.LineStatus = GetSalesStatus((SalesOrderStatus)item.Status); lineItem.LineDiscount = item.LineDscAmount; lineItem.PeriodicDiscount = item.PeriodicDiscount; lineItem.PeriodicPctDiscount = item.PeriodicPercentageDiscount; lineItem.LineManualDiscountAmount = item.LineManualDiscountAmount; lineItem.LineManualDiscountPercentage = item.LineManualDiscountPercentage; lineItem.TotalDiscount = item.TotalDiscount; lineItem.TotalPctDiscount = item.TotalPctDiscount; foreach (Tax.MiscellaneousCharge charge in lineCharges) { lineItem.MiscellaneousCharges.Add(charge); } if (lineItem.DeliveryMode != null && !string.IsNullOrWhiteSpace(item.AddressRecordId)) { lineItem.ShippingAddress = customerDataManager.GetAddress(Int64.Parse(item.AddressRecordId)); } lineItem.Dimension.VariantId = item.VariantId; lineItem.Dimension.ColorId = item.ColorId; lineItem.Dimension.StyleId = item.StyleId; lineItem.Dimension.SizeId = item.SizeId; lineItem.Dimension.ConfigId = item.ConfigId; lineItem.Dimension.ColorName = item.ColorName; lineItem.Dimension.StyleName = item.StyleName; lineItem.Dimension.SizeName = item.SizeName; lineItem.Dimension.ConfigName = item.ConfigName; if (!string.IsNullOrEmpty(lineItem.Dimension.VariantId)) { Dimensions dimension = (Dimensions)SalesOrder.InternalApplication.BusinessLogic.Utility.CreateDimension(); dimension.VariantId = lineItem.Dimension.VariantId; SalesOrder.InternalApplication.Services.Dimension.GetDimensionForVariant(dimension); lineItem.Dimension = dimension; } if (item.Discounts.Count > 0) { lineItem.QuantityDiscounted = item.Quantity; lineItem.LinePctDiscount = lineItem.CalculateLinePercentDiscount(); } // create discount line from discount info object foreach (DiscountInfo discountInfo in item.Discounts) { DiscountItem discountItem = ConvertToDiscountItem( discountInfo.DiscountOriginType, discountInfo.ManualDiscountType, discountInfo.CustomerDiscountType, discountInfo.EffectiveAmount, discountInfo.DealPrice, discountInfo.DiscountAmount, discountInfo.Percentage, discountInfo.PeriodicDiscountOfferId, discountInfo.OfferName, discountInfo.DiscountCode); SalesOrder.InternalApplication.Services.Discount.AddDiscountLine(lineItem, discountItem); } // Set other default properties for this item SalesOrder.InternalApplication.Services.Item.ProcessItem(lineItem, bypassSerialNumberEntry: true); // Set tax info after defaults, as it may have been overridden. lineItem.SalesTaxGroupId = item.SalesTaxGroup; lineItem.SalesTaxGroupIdOriginal = item.SalesTaxGroup; lineItem.TaxGroupId = item.ItemTaxGroup; lineItem.TaxGroupIdOriginal = item.ItemTaxGroup; // Add it to the transaction transaction.Add(lineItem); if (lineItem.DeliveryDate < earliestDeliveryDate) { earliestDeliveryDate = lineItem.DeliveryDate.HasValue ? lineItem.DeliveryDate.Value : earliestDeliveryDate; } } // Once Items are populated - Reset Customer Tax Group //GRW Linea comentada para poder recoger la orden de venta en una tienda distinta a la configurada en AX //customerSystem.ResetCustomerTaxGroup(transaction); // The order can be created through some other channel other than POS which has set header delivery date as NoDate. // This must not be interpreted as a valid date. Instead the earliestDeliveryDate is used. if (transaction.RequestedDeliveryDate == NoDate) { transaction.RequestedDeliveryDate = earliestDeliveryDate; } // Charges foreach (ChargeInfo charge in orderInfo.Charges) { // add charges Tax.MiscellaneousCharge newCharge = (Tax.MiscellaneousCharge)SalesOrder.InternalApplication.BusinessLogic.Utility.CreateMiscellaneousCharge( charge.Amount, charge.SalesTaxGroup, charge.TaxGroup, charge.Code, string.Empty, transaction); transaction.Add(newCharge); } SalesOrder.InternalApplication.BusinessLogic.ItemSystem.CalculatePriceTaxDiscount(transaction); transaction.CalculateAmountDue(); // Payments // - total up amounts // - add history entries transaction.PrepaymentAmountPaid = decimal.Zero; transaction.PrepaymentAmountInvoiced = decimal.Zero; decimal nonPrepayments = decimal.Zero; PaymentInfo pinfo = new PaymentInfo(); pinfo.Amount = -111; pinfo.Currency = "MXN"; orderInfo.Payments.Add(pinfo); foreach (PaymentInfo payment in orderInfo.Payments) { // sum up payments decimal amount = (string.IsNullOrWhiteSpace(payment.Currency)) ? payment.Amount : (SalesOrder.InternalApplication.Services.Currency.CurrencyToCurrency( payment.Currency, ApplicationSettings.Terminal.StoreCurrency, payment.Amount)); if (payment.Prepayment) { // Sum prepayments to track total deposits paid transaction.PrepaymentAmountPaid += amount; } else { // Sum non-prepayments as base for calculating deposits applied to pickups nonPrepayments += amount; } CustomerOrderPaymentHistory paymentHistory = (CustomerOrderPaymentHistory)SalesOrder.InternalApplication.BusinessLogic.Utility.CreateCustomerOrderPaymentHistory(); paymentHistory.Amount = payment.Amount; paymentHistory.Currency = payment.Currency; paymentHistory.Date = ParseDateString(payment.DateString, DateTime.MinValue); paymentHistory.Balance = transaction.NetAmountWithTaxAndCharges - transaction.PrepaymentAmountPaid; transaction.PaymentHistory.Add(paymentHistory); } // Prepayment/Deposit override info transaction.PrepaymentAmountOverridden = orderInfo.PrepaymentAmountOverridden; if (transaction.PrepaymentAmountOverridden) { transaction.PrepaymentAmountRequired = transaction.PrepaymentAmountPaid; } // Amount that has been previously invoiced (picked-up) transaction.PreviouslyInvoicedAmount = orderInfo.PreviouslyInvoicedAmount; // Portion of the prepayment that has been applied to invoices. // If .PrepaymentAmountApplied is non-NULL then use the explicit amount, otherwise fall back to computing the amount based on payment history. transaction.PrepaymentAmountInvoiced = orderInfo.PrepaymentAmountApplied ?? (transaction.PreviouslyInvoicedAmount - nonPrepayments); transaction.HasLoyaltyPayment = orderInfo.HasLoyaltyPayment; return(transaction); }
internal static CustomerOrderInfo GetInfoFromTransaction(CustomerOrderTransaction customerOrder) { CustomerOrderInfo parameters = new CustomerOrderInfo(); parameters.OrderType = customerOrder.OrderType; parameters.Id = customerOrder.OrderId; 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.Email = customerOrder.ReceiptEmailAddress; parameters.Comment = ((IPosTransactionV1)customerOrder).Comment; parameters.ReturnReasonCodeId = customerOrder.ReturnReasonCodeId; parameters.LoyaltyCardId = (customerOrder.LoyaltyItem != null && customerOrder.LoyaltyItem.UsageType == LSRetailPosis.Transaction.Line.LoyaltyItem.LoyaltyItemUsageType.UsedForLoyaltyRequest) ? customerOrder.LoyaltyItem.LoyaltyCardNumber : string.Empty; // If we do not have the channel reference identifier, we create a new receipt identifier instead. parameters.ChannelReferenceId = !string.IsNullOrWhiteSpace(customerOrder.ChannelReferenceId) ? customerOrder.ChannelReferenceId : SalesOrder.InternalApplication.Services.ApplicationService.GetNextReceiptId(customerOrder); 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)); 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, //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, }); } } // 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 }); } // Payments parameters.Payments = new Collection <PaymentInfo>(); foreach (ITenderLineItem tender in customerOrder.TenderLines) { 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. parameters.Payments.Add(new PaymentInfo() { PaymentType = tender.TenderTypeId, Amount = tender.Amount, Currency = (tender.CurrencyCode) ?? string.Empty }); } } } return(parameters); }
public static SalesOrder GetSalesOrderFromInfo(CustomerOrderInfo orderInfo, ChannelConfiguration channelConfiguration, RequestContext context) { // Stores the local copy. There is high probability of having the same shipping/delivery address on all the lines. Dictionary <long, Address> shippingAddressDictionary = new Dictionary <long, Address>(); decimal shippingChargeAmount; ColumnSet columnSet = new ColumnSet(); var salesOrder = new SalesOrder { SalesId = orderInfo.Id, TransactionType = SalesTransactionType.CustomerOrder, CustomerOrderMode = CustomerOrderMode.OrderRecalled, CartType = CartType.CustomerOrder, CustomerOrderType = orderInfo.OrderType, StoreId = orderInfo.StoreId, IsTaxIncludedInPrice = Convert.ToBoolean(orderInfo.IsTaxIncludedInPrice) }; switch (orderInfo.OrderType) { case CustomerOrderType.Quote: salesOrder.Status = Utilities.GetSalesStatus((SalesQuotationStatus)orderInfo.Status); break; case CustomerOrderType.SalesOrder: salesOrder.Status = Utilities.GetSalesStatus((SalesOrderStatus)orderInfo.Status, (DocumentStatus)orderInfo.DocumentStatus); break; default: salesOrder.Status = SalesStatus.Unknown; break; } DateTimeOffset currentChannelDate = context.GetNowInChannelTimeZone(); salesOrder.RequestedDeliveryDate = Utilities.ParseDateStringAsDateTimeOffset(orderInfo.RequestedDeliveryDateString, currentChannelDate.Date, currentChannelDate.Offset); salesOrder.QuotationExpiryDate = Utilities.ParseDateStringAsDateTimeOffset(orderInfo.ExpiryDateString, currentChannelDate.Date, currentChannelDate.Offset); // CreationDate is stored in UTC. It needs to be converted to local time zone where order is accessed. salesOrder.BeginDateTime = Utilities.ParseDateString(orderInfo.CreationDateString, currentChannelDate.ToUniversalTime().DateTime, DateTimeStyles.AssumeUniversal); salesOrder.Comment = orderInfo.Comment; // Header delivery salesOrder.InventoryLocationId = orderInfo.WarehouseId; salesOrder.DeliveryMode = orderInfo.DeliveryMode; foreach (var discountCode in orderInfo.DiscountCodes) { salesOrder.DiscountCodes.Add(discountCode); } // Customer info salesOrder.CustomerId = orderInfo.CustomerAccount; long addressRecordIdLong = 0; if (long.TryParse(orderInfo.AddressRecordId, out addressRecordIdLong)) { var dataServiceRequest = new GetAddressDataRequest(addressRecordIdLong, columnSet); SingleEntityDataServiceResponse <Address> dataServiceResponse = context.Execute <SingleEntityDataServiceResponse <Address> >(dataServiceRequest); if (dataServiceResponse.Entity == null) { Utilities.DownloadCustomerData(context, salesOrder.CustomerId); dataServiceResponse = context.Execute <SingleEntityDataServiceResponse <Address> >(dataServiceRequest); } if (dataServiceResponse.Entity != null) { salesOrder.ShippingAddress = dataServiceResponse.Entity; shippingAddressDictionary.Add(salesOrder.ShippingAddress.RecordId, salesOrder.ShippingAddress); } } if (!string.IsNullOrEmpty(orderInfo.SalespersonStaffId)) { // Sets the sales person id and name according to AX values // This is done because we do not know whether the sales person information is available on this store salesOrder.StaffId = orderInfo.SalespersonStaffId; } salesOrder.ChannelReferenceId = orderInfo.ChannelReferenceId; salesOrder.LoyaltyCardId = orderInfo.LoyaltyCardId; salesOrder.ReceiptEmail = orderInfo.Email; string shippingChargeCode = channelConfiguration.ShippingChargeCode; // Items int lineId = 0; foreach (ItemInfo item in orderInfo.Items) { lineId++; var lineItem = new SalesLine { LineId = lineId.ToString(CultureInfo.InvariantCulture), Found = true, RecordId = item.RecId, ItemId = item.ItemId, Comment = item.Comment, Quantity = item.Quantity, ReturnQuantity = item.Quantity, SalesOrderUnitOfMeasure = item.Unit, UnitOfMeasureSymbol = item.Unit, Price = item.Price, NetAmount = item.NetAmount, QuantityOrdered = item.Quantity, QuantityInvoiced = item.QuantityPicked, DeliveryMode = item.DeliveryMode, RequestedDeliveryDate = Utilities.ParseDateStringAsDateTimeOffset(item.RequestedDeliveryDateString, currentChannelDate.Date, currentChannelDate.Offset), FulfillmentStoreId = item.FulfillmentStoreId, InventoryLocationId = item.WarehouseId, SerialNumber = item.SerialId, BatchId = item.BatchId, Status = TransactionStatus.Normal, SalesStatus = Utilities.GetSalesStatus((SalesOrderStatus)item.Status) }; // Copy charges to line and calculates total shipping charge amount lineItem.ChargeLines.AddRange(SalesOrderHelper.CreateChargeLines(item.Charges, shippingChargeCode, salesOrder.BeginDateTime, out shippingChargeAmount)); lineItem.DeliveryModeChargeAmount = shippingChargeAmount; // Line level discount amounts lineItem.LineDiscount = item.LineDscAmount; lineItem.PeriodicDiscount = item.PeriodicDiscount; lineItem.PeriodicPercentageDiscount = item.PeriodicPercentageDiscount; lineItem.LineManualDiscountAmount = item.LineManualDiscountAmount; lineItem.LineManualDiscountPercentage = item.LineManualDiscountPercentage; lineItem.TotalDiscount = item.TotalDiscount; lineItem.TotalPercentageDiscount = item.TotalPctDiscount; // Copy discounts to line lineItem.DiscountLines.AddRange(SalesOrderHelper.CreateDiscountLines(item.Discounts)); long itemAddressRecordIdLong; if (long.TryParse(item.AddressRecordId, out itemAddressRecordIdLong)) { Address lineLevelshippingAddress = new Address(); if (!shippingAddressDictionary.TryGetValue(itemAddressRecordIdLong, out lineLevelshippingAddress)) { var dataServiceRequest = new GetAddressDataRequest(itemAddressRecordIdLong, columnSet); SingleEntityDataServiceResponse <Address> dataServiceResponse = context.Execute <SingleEntityDataServiceResponse <Address> >(dataServiceRequest); // If address not found download and get. if (dataServiceResponse.Entity == null) { Utilities.DownloadCustomerData(context, salesOrder.CustomerId); dataServiceResponse = context.Execute <SingleEntityDataServiceResponse <Address> >(dataServiceRequest); } if (dataServiceResponse.Entity != null) { lineItem.ShippingAddress = dataServiceResponse.Entity; shippingAddressDictionary.Add(lineItem.ShippingAddress.RecordId, lineItem.ShippingAddress); } } else { lineItem.ShippingAddress = lineLevelshippingAddress; } } Utilities.SetUpVariantAndProduct(context, item.InventDimensionId, lineItem.ItemId, lineItem); lineItem.DiscountAmount = item.Discount; // Set tax info after defaults, as it may have been overridden. lineItem.SalesTaxGroupId = item.SalesTaxGroup ?? string.Empty; lineItem.ItemTaxGroupId = item.ItemTaxGroup ?? string.Empty; // Add it to the transaction salesOrder.SalesLines.Add(lineItem); } // Charges for the header salesOrder.ChargeLines.AddRange(SalesOrderHelper.CreateChargeLines(orderInfo.Charges, shippingChargeCode, salesOrder.BeginDateTime, out shippingChargeAmount)); salesOrder.DeliveryModeChargeAmount = shippingChargeAmount; // Payments // - total up amounts // - add history entries decimal nonPrepayments = decimal.Zero; decimal prepaymentAmountPaid = decimal.Zero; int tenderLineId = 0; foreach (PaymentInfo payment in orderInfo.Payments) { if (salesOrder.TenderLines == null) { salesOrder.TenderLines = new Collection <TenderLine>(); } decimal amount = 0M; if (string.IsNullOrWhiteSpace(payment.Currency) || payment.Currency.Equals(channelConfiguration.Currency, StringComparison.OrdinalIgnoreCase)) { amount = payment.Amount; } else { GetCurrencyValueServiceRequest currencyValueRequest = new GetCurrencyValueServiceRequest(payment.Currency, channelConfiguration.Currency, payment.Amount); GetCurrencyValueServiceResponse currencyValueResponse = context.Execute <GetCurrencyValueServiceResponse>(currencyValueRequest); amount = currencyValueResponse.RoundedConvertedAmount; } if (payment.Prepayment) { // Sum prepayments to track total deposits paid prepaymentAmountPaid += amount; } else { // Sum non-prepayments as base for calculating deposits applied to pickups nonPrepayments += amount; } tenderLineId++; var tenderLine = new TenderLine { TenderLineId = tenderLineId.ToString(CultureInfo.InvariantCulture), Amount = payment.Amount, Currency = payment.Currency, CardTypeId = string.Empty, Status = TenderLineStatus.Historical, IsVoidable = false, TenderDate = Utilities.ParseDateString( payment.DateString, currentChannelDate.Date, DateTimeStyles.None) // On channel timezone }; salesOrder.TenderLines.Add(tenderLine); } if (orderInfo.Affiliations != null && orderInfo.Affiliations.Any()) { salesOrder.AffiliationLoyaltyTierLines.Clear(); salesOrder.AffiliationLoyaltyTierLines.AddRange(orderInfo.Affiliations.Select(line => new SalesAffiliationLoyaltyTier { AffiliationId = line.AffiliationRecordId, LoyaltyTierId = line.LoyaltyTierRecordId, AffiliationType = line.AffiliationType })); } // Prepayment/Deposit override info if (orderInfo.PrepaymentAmountOverridden) { salesOrder.OverriddenDepositAmount = prepaymentAmountPaid; } salesOrder.PrepaymentAmountPaid = prepaymentAmountPaid; // Portion of the prepayment that has been applied to invoices // (total amount invoiced less payments, difference is the deposit applied) salesOrder.PrepaymentAmountInvoiced = orderInfo.PreviouslyInvoicedAmount - nonPrepayments; // if the prepayment invoiced is greater than the total paid as deposit, there is no credit left salesOrder.AvailableDepositAmount = Math.Max(decimal.Zero, salesOrder.PrepaymentAmountPaid - salesOrder.PrepaymentAmountInvoiced); salesOrder.HasLoyaltyPayment = orderInfo.HasLoyaltyPayment; salesOrder.CurrencyCode = orderInfo.CurrencyCode; return(salesOrder); }
/// <summary> /// 丰富信息 /// </summary> /// <returns></returns> private CustomerOrderInfoModel DecorateCustomerOrderInfo(CustomerOrderInfo model) { var ApplicationInfos = new List <ApplicationInfoModel>(); model.ApplicationInfos.ToList().ForEach(m => ApplicationInfos.Add(new ApplicationInfoModel() { ApplicationID = m.ApplicationID, ApplicationName = m.ApplicationName, HSCode = m.HSCode, PickingName = m.PickingName, Qty = m.Qty ?? 0, Remark = m.Remark, Total = m.Total ?? 0, UnitPrice = m.UnitPrice ?? 0, UnitWeight = m.UnitWeight ?? 0, WayBillNumber = m.WayBillNumber })); var customer = _customerService.GetCustomer(model.CustomerCode); var customerOrderInfoModel = new CustomerOrderInfoModel() { CustomerOrderID = model.CustomerOrderID, CustomerOrderNumber = model.CustomerOrderNumber, CustomerCode = model.CustomerCode, TrackingNumber = model.TrackingNumber, ShippingMethodId = model.ShippingMethodId ?? 0, ShippingMethodName = model.ShippingMethodName, GoodsTypeID = model.GoodsTypeID ?? 0, InsuredID = model.InsuredID ?? 0, IsReturn = model.IsReturn, IsInsured = model.IsInsured, IsBattery = model.IsBattery, IsPrinted = model.IsPrinted, IsHold = model.IsHold, Status = model.Status, CreatedOn = model.CreatedOn, SensitiveTypeID = model.SensitiveTypeID ?? 0, PackageNumber = model.PackageNumber, AppLicationType = model.AppLicationType, Weight = model.Weight, Length = model.Length, Width = model.Width, Height = model.Height, ApplicationInfoList = ApplicationInfos, WayBillInfos = model.WayBillInfos.ToList(), WayBillNumber = model.WayBillInfos.FirstOrDefault() == null ? "" : model.WayBillInfos.FirstOrDefault().WayBillNumber, ShippingAddress = (model.ShippingInfo.ShippingAddress + " " + model.ShippingInfo.ShippingAddress1 + " " + model.ShippingInfo.ShippingAddress2).Trim(), ShippingCity = model.ShippingInfo.ShippingCity, ShippingCompany = model.ShippingInfo.ShippingCompany, ShippingFirstLastName = model.ShippingInfo.ShippingFirstName + " " + model.ShippingInfo.ShippingLastName, ShippingFirstName = model.ShippingInfo.ShippingFirstName, ShippingLastName = model.ShippingInfo.ShippingLastName, ShippingPhone = model.ShippingInfo.ShippingPhone, ShippingState = model.ShippingInfo.ShippingState, ShippingZip = model.ShippingInfo.ShippingZip, ShippingTaxId = model.ShippingInfo.ShippingTaxId, CountryCode = model.ShippingInfo.CountryCode, CustomerName = customer.Name, ShippingZone = GetShippingZone(model.ShippingMethodId ?? 0, model.ShippingInfo.ShippingZip, model.ShippingInfo.CountryCode), }; if (string.IsNullOrWhiteSpace(customerOrderInfoModel.TrackingNumber)) { var firstOrDefault = customerOrderInfoModel.WayBillInfos.FirstOrDefault(); if (firstOrDefault != null) { customerOrderInfoModel.TrackingNumber = firstOrDefault.WayBillNumber; } } customerOrderInfoModel.BarCode = "<img id=\"img\" src=\"/barcode.ashx?m=0&h=35&vCode=" + customerOrderInfoModel.TrackingNumber + "\" alt=\"" + customerOrderInfoModel.TrackingNumber + "\" style=\"width:200px;height:35px;\" />"; customerOrderInfoModel.BarCode128 = "<img id=\"img\" src=\"/print/barcode128h?Code=" + customerOrderInfoModel.TrackingNumber + "\" alt=\"" + customerOrderInfoModel.TrackingNumber + "\" style=\"\" />"; customerOrderInfoModel.CustomerOrderNumberCode39 = "<img id=\"img\" src=\"/print/barcode39?Code=" + customerOrderInfoModel.CustomerOrderNumber + "\" alt=\"" + customerOrderInfoModel.CustomerOrderNumber + "\" style=\"\" />"; customerOrderInfoModel.CustomerOrderNumberCode128 = "<img id=\"img\" src=\"/print/barcode128?Code=" + customerOrderInfoModel.CustomerOrderNumber + "\" alt=\"" + customerOrderInfoModel.CustomerOrderNumber + "\" style=\"\" />"; customerOrderInfoModel.CustomerOrderNumberCode128L = "<img id=\"img\" src=\"/print/barcode128?Code=" + customerOrderInfoModel.CustomerOrderNumber + "&dpiy=40\" alt=\"" + customerOrderInfoModel.CustomerOrderNumber + "\" style=\"\" />"; customerOrderInfoModel.TrackingNumberCode39 = "<img id=\"img\" src=\"/print/barcode39?Code=" + customerOrderInfoModel.TrackingNumber + "\" alt=\"" + customerOrderInfoModel.TrackingNumber + "\" style=\"\" />"; customerOrderInfoModel.TrackingNumberCode128 = "<img id=\"img\" src=\"/print/barcode128?Code=" + customerOrderInfoModel.TrackingNumber + "\" alt=\"" + customerOrderInfoModel.TrackingNumber + "\" style=\"\" />"; customerOrderInfoModel.WayBillNumberCode39 = "<img id=\"img\" src=\"/print/barcode39?Code=" + customerOrderInfoModel.WayBillNumber + "\" alt=\"" + customerOrderInfoModel.WayBillNumber + "\" style=\"\" />"; customerOrderInfoModel.WayBillNumberCode128 = "<img id=\"img\" src=\"/print/barcode128?Code=" + customerOrderInfoModel.WayBillNumber + "\" alt=\"" + customerOrderInfoModel.WayBillNumber + "\" style=\"\" />"; customerOrderInfoModel.CustomerOrderNumberCode128Lh = "<img id=\"img\" src=\"/print/barcode128?Code=" + customerOrderInfoModel.CustomerOrderNumber + "&dpiy=40&angleF=90&showText=true\" alt=\"" + customerOrderInfoModel.CustomerOrderNumber + "\" style=\"\" />"; var country = GetCountryList().Single(c => c.CountryCode == customerOrderInfoModel.CountryCode); customerOrderInfoModel.CountryName = country.Name; customerOrderInfoModel.CountryChineseName = country.ChineseName; var mouthCountry = GetMouthCountryList().Find(c => c.CountryCode == customerOrderInfoModel.CountryCode); customerOrderInfoModel.MouthNumber = mouthCountry == null ? 0 : mouthCountry.MouthNumber; customerOrderInfoModel.SortingIdentity = GetSortingIdentityHtml(model.ShippingInfo.ShippingZip, model.ShippingInfo.CountryCode); customerOrderInfoModel.BatteryIdentity = (model.IsBattery && (model.SensitiveTypeID == 1 || model.SensitiveTypeID == 2)) ? "D" : ""; return(customerOrderInfoModel); }
public override void ExportCustomerOrders(Customer customer) { ClearDocument(); var orderRepository = DbManger.GetInstance().GetOrderRepository(); var productRepository = DbManger.GetInstance().GetProductRepository(); // var ratesRepository = DbManger.GetInstance().GetRatesRepository(); if (customer.GetCommissionInfo() == null) throw new ApplicationException("Для покупателя неверно установлена ставка комиссии!"); // информация о комиссии пользователя // ManagedRate comission; List<Order> orders; try { // comission = ratesRepository.GetById(customer.AccountTypeId); orders = orderRepository.GetOrdersForCustomerFromAlbum(customer, WorkingAlbum); } catch (Exception exception) { m_logger.ErrorException(exception); throw new ApplicationException("Ошибка: Не удалось выполнить чтение из БД"); } // прелоад информации о способе доставки customer.GetDeliveryInfo(); var orderInfo = new CustomerOrderInfo(customer); foreach (Order order in orders) { if (!IsIncludingEmpty && order.Amount == 0) continue; Product productInfo; OnProgressChanged("Получение информации о продукте"); string partialIndicator = ""; try { productInfo = productRepository.GetById(order.ProductId); var total = orderRepository.GetProductTotalOrderedAmount(productInfo); if (total < productInfo.MinAmount) { if (!IsIncludingPartial) { continue; } partialIndicator = "(!)"; } } catch (Exception exception) { m_logger.ErrorException(exception); continue; } orderInfo.Items.Add(new CustomerOrderItem { Amount = order.Amount, Price = productInfo.Price, IsPartial = partialIndicator.Length > 0, Title = productInfo.Title }); } m_document.Dispatcher.Invoke(DispatcherPriority.Normal, new Action<object>(o => { var borderThick = new Thickness(1); var borderColor = Brushes.LightGray; var corders = (CustomerOrderInfo) o; m_document.Blocks.Add( new Paragraph(new Run(corders.Customer.GetFullName().ToUpper())) { FontSize = 16, FontWeight = FontWeights.Bold }); var table = new Table { CellSpacing = 3, FontSize = 12 }; const int numberOfColumns = 5; for (int x = 0; x < numberOfColumns; x++) { table.Columns.Add(new TableColumn()); table.Columns[x].Background = x % 2 == 0 ? Brushes.White : Brushes.WhiteSmoke; } table.Columns[0].Width = new GridLength(30); table.Columns[1].Width = new GridLength(400); table.Columns[2].Width = new GridLength(100); table.Columns[3].Width = new GridLength(60); table.Columns[4].Width = new GridLength(100); var rowGroup = new TableRowGroup(); table.RowGroups.Add(rowGroup); var row = new TableRow { FontWeight = FontWeights.Bold }; rowGroup.Rows.Add(row); #region Table title row.Cells.Add(new TableCell(new Paragraph(new Run("№"))) { TextAlignment = TextAlignment.Center, Padding = new Thickness(5), BorderThickness = borderThick, BorderBrush = borderColor }); row.Cells.Add(new TableCell(new Paragraph(new Run("Наименование"))) { TextAlignment = TextAlignment.Center, Padding = new Thickness(5), BorderThickness = borderThick, BorderBrush = borderColor }); row.Cells.Add(new TableCell(new Paragraph(new Run("Цена"))) { TextAlignment = TextAlignment.Center, Padding = new Thickness(5), BorderThickness = borderThick, BorderBrush = borderColor }); row.Cells.Add(new TableCell(new Paragraph(new Run("Кол-во"))) { TextAlignment = TextAlignment.Center, Padding = new Thickness(5), BorderThickness = borderThick, BorderBrush = borderColor }); row.Cells.Add(new TableCell(new Paragraph(new Run("Сумма"))) { TextAlignment = TextAlignment.Center, Padding = new Thickness(5), BorderThickness = borderThick, BorderBrush = borderColor }); #endregion var rowNum = 1; decimal summary = 0; foreach (var order in corders.Items) { summary += order.Total; row = new TableRow { Background = rowNum % 2 == 0 ? Brushes.WhiteSmoke : Brushes.White }; rowGroup.Rows.Add(row); row.Cells.Add(new TableCell(new Paragraph(new Run(rowNum.ToString()))) { TextAlignment = TextAlignment.Center, Padding = new Thickness(5), BorderThickness = borderThick, BorderBrush = borderColor }); row.Cells.Add(new TableCell(new Paragraph(new Run(order.Title))) { TextAlignment = TextAlignment.Left, Padding = new Thickness(5), BorderThickness = borderThick, BorderBrush = borderColor }); row.Cells.Add(new TableCell(new Paragraph(new Run(order.Price.ToString("C2")))) { TextAlignment = TextAlignment.Center, Padding = new Thickness(5), BorderThickness = borderThick, BorderBrush = borderColor }); row.Cells.Add(new TableCell(new Paragraph(new Run(order.Amount.ToString()))) { TextAlignment = TextAlignment.Center, Padding = new Thickness(5), BorderThickness = borderThick, BorderBrush = borderColor }); row.Cells.Add(new TableCell(new Paragraph(new Run(order.Total.ToString("C2")))) { TextAlignment = TextAlignment.Center, Padding = new Thickness(5), BorderThickness = borderThick, BorderBrush = borderColor }); rowNum++; } var commission = corders.Customer.GetCommissionInfo(); var comissionValue = summary * (commission.Rate / 100); var total = summary * (1 + (commission.Rate / 100)); var delivery = corders.Customer.GetDeliveryInfo(); var p = new Paragraph(new Run(String.Format("Сумма: {0}", summary.ToString("C2")))) { FontSize = 13, FontWeight = FontWeights.Bold }; p.Inlines.Add(new LineBreak()); p.Inlines.Add(new Run(String.Format("Сбор ({0}): {1:C2}", commission.Comment, comissionValue)) { FontSize = 13, FontWeight = FontWeights.Bold }); p.Inlines.Add(new LineBreak()); if (delivery != null && delivery.IsActive) { if ((delivery.IsConditional && delivery.MinimumOrderSummaryCondition > summary) || delivery.IsConditional == false) { total += delivery.Price; p.Inlines.Add(new Run(String.Format("Доставка: {0:C2}", delivery.Price)) { FontSize = 13, FontWeight = FontWeights.Bold }); p.Inlines.Add(new LineBreak()); } } p.Inlines.Add(new Run(String.Format("Итог: {0:C0}", total)) { FontSize = 13, FontWeight = FontWeights.Bold }); p.Inlines.Add(new LineBreak()); m_document.Blocks.Add(table); m_document.Blocks.Add(p); m_document.Tag = corders.Customer.GetFullName(); }), orderInfo); }
public override void ExportCustomersSummary() { ClearDocument(); var orderRepository = DbManger.GetInstance().GetOrderRepository(); var customersRepository = DbManger.GetInstance().GetCustomersRepository(); var productRepository = DbManger.GetInstance().GetProductRepository(); var ratesRepository = DbManger.GetInstance().GetRatesRepository(); List<Order> albumOrders; OnProgressChanged("Получение заказов для альбома"); try { albumOrders = orderRepository.GetOrdersForAlbum(WorkingAlbum); } catch (Exception exception) { m_logger.ErrorException(exception); throw new ApplicationException("Не удалось получить заказы альбома из БД"); } var customers = new List<Customer>(); IEnumerable<IGrouping<int, Order>> byCustomerOrders = albumOrders.GroupBy(order => order.CustomerId); foreach (IGrouping<int, Order> byCustomerOrder in byCustomerOrders) { Customer custObj; try { OnProgressChanged("Получение данных о заказчике."); custObj = customersRepository.GetById(byCustomerOrder.Key); } catch (Exception exception) { m_logger.ErrorException(exception); throw new ApplicationException("Не удалось получить информацию о заказчике " + byCustomerOrder.Key); } customers.Add(custObj); } customers.Sort((c1, c2) => String.Compare(c1.LastName, c2.LastName, StringComparison.CurrentCultureIgnoreCase)); var bills = new List<CustomerOrderInfo>(); foreach (var custObj in customers) { // прелоад информации о способе доставки покупателю custObj.GetDeliveryInfo(); // информация о комиссии пользователя // ManagedRate comission; // try // { // comission = ratesRepository.GetById(custObj.AccountTypeId); // } // catch (Exception exception) // { // m_logger.ErrorException(exception); // comission = new ManagedRate { Comment = "???", Id = 0, Rate = 0 }; // } if (custObj.GetCommissionInfo() == null) throw new ApplicationException("Для покупателя не задана ставка комиссии: " + custObj.GetFullName()); var coi = new CustomerOrderInfo(custObj); var customerOrders = byCustomerOrders.FirstOrDefault(orders => orders.Key == custObj.Id); foreach (Order order in customerOrders) { if (!IsIncludingEmpty && order.Amount == 0) continue; Product productInfo = null; OnProgressChanged("Получение информации о продукте"); string partialIndicator = ""; try { productInfo = productRepository.GetById(order.ProductId); var total = orderRepository.GetProductTotalOrderedAmount(productInfo); if (total < productInfo.MinAmount) { if (!IsIncludingPartial) { continue; } partialIndicator = "(!)"; } } catch (Exception exception) { m_logger.ErrorException(exception); continue; } coi.Items.Add(new CustomerOrderItem { Amount = order.Amount, IsPartial = partialIndicator.Length > 0, Price = productInfo.Price, Title = productInfo.Title, Comment = order.Comment }); } if (coi.GetOrderCleanSum() > 0) { bills.Add(coi); } } m_document.Dispatcher.Invoke(DispatcherPriority.Normal, new Action<object>(o => { var data = (List<CustomerOrderInfo>) o; var borderThick = new Thickness(1); var borderColor = Brushes.LightGray; var table = new Table { CellSpacing = 1, FontSize = 12 }; table.Columns.Add(new TableColumn()); table.Columns.Add(new TableColumn()); table.Columns[0].Width = new GridLength(0.7, GridUnitType.Star); table.Columns[1].Width = new GridLength(0.3, GridUnitType.Star); table.RowGroups.Add(new TableRowGroup()); var r = new TableRow { FontWeight = FontWeights.Bold }; r.Cells.Add( new TableCell( new Paragraph(new Run(String.Format("Заказы в альбоме '{0}'", WorkingAlbum.GetCleanTitle()).ToUpper()))) { TextAlignment = TextAlignment.Left }); r.Cells.Add(new TableCell(new Paragraph(new Run(DateTime.Now.ToString()))) { TextAlignment = TextAlignment.Right, FontSize = 10 }); table.RowGroups[0].Rows.Add(r); m_document.Blocks.Add(table); decimal totalSum = 0; decimal totalComission = 0; decimal totalDelivery = 0; const int numberOfColumns = 5; foreach (CustomerOrderInfo orderInfo in data) { totalSum += orderInfo.GetOrderCleanSum(); totalComission += orderInfo.GetOrderComission(); var paragraph = new Paragraph( new Run(orderInfo.Customer.GetFullName().ToUpper())) { FontSize = 12, FontWeight = FontWeights.Bold }; m_document.Blocks.Add(paragraph); table = new Table { CellSpacing = 0, FontSize = 11 }; for (int x = 0; x < numberOfColumns; x++) { table.Columns.Add(new TableColumn()); } table.Columns[0].Width = new GridLength(30); table.Columns[1].Width = new GridLength(400); table.Columns[2].Width = new GridLength(100); table.Columns[3].Width = new GridLength(60); table.Columns[4].Width = new GridLength(100); var rowGroup = new TableRowGroup(); table.RowGroups.Add(rowGroup); var row = new TableRow { FontWeight = FontWeights.Bold, FontSize = 11}; rowGroup.Rows.Add(row); #region Table title row.Cells.Add(new TableCell(new Paragraph(new Run("№"))) { TextAlignment = TextAlignment.Center, Padding = new Thickness(3), BorderThickness = borderThick, BorderBrush = borderColor }); row.Cells.Add(new TableCell(new Paragraph(new Run("Наименование"))) { TextAlignment = TextAlignment.Center, Padding = new Thickness(3), BorderThickness = borderThick, BorderBrush = borderColor }); row.Cells.Add(new TableCell(new Paragraph(new Run("Цена"))) { TextAlignment = TextAlignment.Center, Padding = new Thickness(3), BorderThickness = borderThick, BorderBrush = borderColor }); row.Cells.Add(new TableCell(new Paragraph(new Run("Кол-во"))) { TextAlignment = TextAlignment.Center, Padding = new Thickness(3), BorderThickness = borderThick, BorderBrush = borderColor }); row.Cells.Add(new TableCell(new Paragraph(new Run("Сумма"))) { TextAlignment = TextAlignment.Center, Padding = new Thickness(3), BorderThickness = borderThick, BorderBrush = borderColor }); #endregion var rowNum = 1; foreach (var prod in orderInfo.Items) { row = new TableRow { Background = prod.IsPartial ? Brushes.Gainsboro : Brushes.White }; rowGroup.Rows.Add(row); row.Cells.Add(new TableCell(new Paragraph(new Run(rowNum.ToString()))) { TextAlignment = TextAlignment.Center, Padding = new Thickness(3), BorderThickness = borderThick, BorderBrush = borderColor }); var title = !String.IsNullOrEmpty(prod.Comment) ? String.Format("{0} ({1})", prod.Title, prod.Comment) : prod.Title; row.Cells.Add(new TableCell(new Paragraph(new Run(title))) { TextAlignment = TextAlignment.Left, Padding = new Thickness(3), BorderThickness = borderThick, BorderBrush = borderColor }); row.Cells.Add(new TableCell(new Paragraph(new Run(prod.Price.ToString("C2")))) { TextAlignment = TextAlignment.Center, Padding = new Thickness(3), BorderThickness = borderThick, BorderBrush = borderColor }); row.Cells.Add(new TableCell(new Paragraph(new Run(prod.Amount.ToString()))) { TextAlignment = TextAlignment.Center, Padding = new Thickness(3), BorderThickness = borderThick, BorderBrush = borderColor, }); row.Cells.Add(new TableCell(new Paragraph(new Run(prod.Total.ToString("C2")))) { TextAlignment = TextAlignment.Center, Padding = new Thickness(3), BorderThickness = borderThick, BorderBrush = borderColor }); rowNum++; } m_document.Blocks.Add(table); var delivery = orderInfo.Customer.GetDeliveryInfo(); var summary = orderInfo.GetOrderCleanSum() + orderInfo.GetOrderComission(); var p = new Paragraph(new Run(String.Format("Сумма: {0}", orderInfo.GetOrderCleanSum().ToString("C2")))) { FontSize = 11, }; p.Inlines.Add(new LineBreak()); p.Inlines.Add( new Run(String.Format("Сбор ({0}): {1}", orderInfo.Customer.GetCommissionInfo().Comment, orderInfo.GetOrderComission().ToString("C2")))); p.Inlines.Add(new LineBreak()); if (delivery != null && delivery.IsActive) { if ((delivery.IsConditional && delivery.MinimumOrderSummaryCondition > summary) || delivery.IsConditional == false) { summary += delivery.Price; totalDelivery += delivery.Price; p.Inlines.Add(new Run(String.Format("Доставка: {0:C0}", delivery.Price))); p.Inlines.Add(new LineBreak()); } } p.Inlines.Add(new Run(String.Format("Итог: {0}", summary.ToString("C0")))); p.Inlines.Add(new LineBreak()); m_document.Blocks.Add(p); } var p1 = new Paragraph(new Run(String.Format("Сумма: {0}", totalSum.ToString("C2")))) { FontSize = 11, FontWeight = FontWeights.Bold }; p1.Inlines.Add(new LineBreak()); p1.Inlines.Add(new Run(String.Format("Комиссия: {0}", totalComission.ToString("C2")))); p1.Inlines.Add(new LineBreak()); p1.Inlines.Add(new Run(String.Format("Доставка: {0}", totalDelivery.ToString("C2")))); p1.Inlines.Add(new LineBreak()); p1.Inlines.Add( new Run(String.Format("Итог: {0}", (totalSum + totalComission) .ToString("C2")))); p1.Inlines.Add(new LineBreak()); m_document.Blocks.Add(p1); m_document.Tag = "Заказы"; }), bills); }