Exemplo n.º 1
0
        /// <summary>
        /// Commits all changes to the line item.
        /// </summary>
        public void Commit()
        {
            string storeTaxGroup = string.Empty;

            StoreDataManager storeDataManager = new StoreDataManager(
                SalesOrder.InternalApplication.Settings.Database.Connection,
                SalesOrder.InternalApplication.Settings.Database.DataAreaID);

            //In case of mixed delivery mode, set transaction RequestedDeliveryDate to the earliest date of all line items in customer order instead of an arbitrary value
            if (this.DeliveryDate.HasValue && DateTime.Compare(this.transaction.RequestedDeliveryDate, this.DeliveryDate.Value) > 0)
            {
                this.transaction.RequestedDeliveryDate = this.DeliveryDate.Value;
            }
            else
            {
                if (this.transaction.RequestedDeliveryDate == DateTime.MinValue)
                {
                    this.transaction.RequestedDeliveryDate = DateTime.Now.Date;
                }
            }

            this.saleLineItem.DeliveryDate = this.DeliveryDate;
            this.saleLineItem.Quantity     = this.Quantity;

            this.saleLineItem.DeliveryStoreNumber = this.StoreNumber;

            if (this.IsShipping)
            {
                // if this line is shipping, then use the stores shipping warehouse setting
                this.saleLineItem.DeliveryWarehouse   = ApplicationSettings.Terminal.InventLocationIdForCustomerOrder;
                this.saleLineItem.DeliveryStoreNumber = ApplicationSettings.Terminal.StoreId;

                this.saleLineItem.ShippingAddress = this.ShippingAddress;

                this.saleLineItem.DeliveryMode = storeDataManager.GetDeliveryMode(this.ShippingMethodCode);
            }
            else if (this.IsPickup)
            {
                if (string.IsNullOrWhiteSpace(ApplicationSettings.Terminal.PickupDeliveryModeCode))
                {
                    // "Pickup cannot be used for delivery because a pickup delivery code was not found."
                    string errorMessage = LSRetailPosis.ApplicationLocalizer.Language.Translate(56382);
                    SalesOrder.LogMessage(errorMessage, LSRetailPosis.LogTraceLevel.Error);

                    throw new InvalidOperationException(errorMessage);
                }

                // if the delivery warehouse is not set, default to the store's warehouse
                this.saleLineItem.DeliveryWarehouse = (this.deliveryStore != null) ? this.deliveryStore.Warehouse : ApplicationSettings.Terminal.InventLocationId;
                this.saleLineItem.DeliveryMode      = storeDataManager.GetDeliveryMode(ApplicationSettings.Terminal.PickupDeliveryModeCode);
                this.saleLineItem.ShippingAddress   = this.shippingAddress;
            }

            // Set the proper SalesTaxGroup based on the store/customer settings
            SalesOrder.InternalApplication.BusinessLogic.CustomerSystem.ResetCustomerTaxGroup(this.saleLineItem);

            // Adds or removes shipping charge
            CommitShippingCharge(this.saleLineItem, this.transaction, this.ShippingCharge);
        }
Exemplo n.º 2
0
        private static void AddSalesItemToTransaction(string invoiceId, CustomerOrderTransaction transaction, StoreDataManager storeDataManager, InvoiceItem item)
        {
            // add item
            SaleLineItem lineItem = (SaleLineItem)
                                    SalesOrder.InternalApplication.BusinessLogic.Utility.CreateSaleLineItem(
                ApplicationSettings.Terminal.StoreCurrency,
                SalesOrder.InternalApplication.Services.Rounding,
                transaction);

            lineItem.Found                      = true;
            lineItem.ItemId                     = item.ItemId;
            lineItem.Description                = item.ProductName;
            lineItem.Quantity                   = item.Quantity;
            lineItem.ReturnQtyAllowed           = item.Quantity;
            lineItem.SalesOrderUnitOfMeasure    = item.Unit;
            lineItem.Price                      = item.Price;
            lineItem.NetAmount                  = item.NetAmount;
            lineItem.SalesTaxGroupId            = item.SalesTaxGroup;
            lineItem.TaxGroupId                 = item.ItemTaxGroup;
            lineItem.SalesMarkup                = item.SalesMarkup;
            lineItem.QuantityOrdered            = item.Quantity;
            lineItem.DeliveryMode               = storeDataManager.GetDeliveryMode(item.DeliveryMode);
            lineItem.DeliveryDate               = DateTime.Today;
            lineItem.DeliveryStoreNumber        = transaction.StoreId;
            lineItem.DeliveryWarehouse          = item.Warehouse;
            lineItem.SerialId                   = item.SerialId;
            lineItem.BatchId                    = item.BatchId;
            lineItem.ReturnInvoiceInventTransId = item.InventTransId;
            lineItem.ReturnInvoiceId            = invoiceId;
            // When we get price from a sales invoice in AX; this is THE price that we will use
            lineItem.ReceiptReturnItem = true;

            lineItem.Dimension.ColorId    = item.ColorId;
            lineItem.Dimension.SizeId     = item.SizeId;
            lineItem.Dimension.StyleId    = item.StyleId;
            lineItem.Dimension.ConfigId   = item.ConfigId;
            lineItem.Dimension.ColorName  = item.ColorName;
            lineItem.Dimension.SizeName   = item.SizeName;
            lineItem.Dimension.StyleName  = item.StyleName;
            lineItem.Dimension.ConfigName = item.ConfigName;

            // set discount, everything is converted into a LineDiscount
            if ((item.DiscountAmount != decimal.Zero) && (item.Quantity != decimal.Zero))
            {
                ILineDiscountItem lineDiscountItem = SalesOrder.InternalApplication
                                                     .BusinessLogic.Utility.CreateLineDiscountItem();
                lineDiscountItem.Amount = item.DiscountAmount;

                // this method takes the per item discount amount
                SalesOrder.InternalApplication.Services.Discount.AddLineDiscountAmount(lineItem, lineDiscountItem);
            }

            SalesOrder.InternalApplication.Services.Item.ProcessItem(lineItem);
            transaction.Add(lineItem);
        }