Ejemplo 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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Save changes back to models
        /// </summary>
        public void CommitHeaderChanges()
        {
            if (this.Validated)
            {
                // First check if a pickup code was configured on the back end and exists in the DB
                string pickupCode = LSRetailPosis.Settings.ApplicationSettings.Terminal.PickupDeliveryModeCode;

                if (string.IsNullOrWhiteSpace(pickupCode))
                {
                    // "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);
                }

                this.transaction.RequestedDeliveryDate = this.PickupDate.Value;
                this.transaction.StoreId         = this.SelectedStore.Number;
                this.transaction.WarehouseId     = this.SelectedStore.Warehouse;
                this.transaction.DeliveryMode    = storeDataManager.GetDeliveryMode(ApplicationSettings.Terminal.PickupDeliveryModeCode);
                this.transaction.ShippingAddress = GetStoreAddress(this.selectedStore);

                // Remove any header level charge
                var headerCharge = transaction.MiscellaneousCharges.FirstOrDefault(m => string.Equals(m.ChargeCode, LSRetailPosis.Settings.ApplicationSettings.Terminal.ShippingChargeCode, StringComparison.Ordinal));
                if (headerCharge != null)
                {
                    transaction.MiscellaneousCharges.Remove(headerCharge);
                }

                // Clear any line item delivery options and duplicate the pickup store on each line
                foreach (var item in this.transaction.SaleItems)
                {
                    ClearLineDeliveryOptions(item);

                    item.DeliveryStoreNumber = this.transaction.StoreId;
                    item.DeliveryWarehouse   = this.transaction.WarehouseId;
                    item.ShippingAddress     = this.transaction.ShippingAddress;

                    if (this.transaction.RequestedDeliveryDate != default(DateTime))
                    {
                        item.DeliveryDate = this.transaction.RequestedDeliveryDate;
                    }
                }
            }
        }
        private PickupInformationViewModel ShowPickupForm(int rowIndex)
        {
            // Before we show the pickup form, check that a pickup code exists
            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);
                SalesOrder.InternalApplication.Services.Dialog.ShowMessage(errorMessage, MessageBoxButtons.OK, MessageBoxIcon.Error);

                return(null);
            }

            PickupInformationViewModel vm = new PickupInformationViewModel(this.ViewModel.Transaction);

            vm.IsDeliveryChangeAllowed = this.ViewModel.IsDeliveryChangeAllowed;

            // Load any existing values
            if (rowIndex >= 0 && rowIndex < this.gridSource.Count)
            {
                LineLevelInformationViewModel viewModel = this.gridSource[rowIndex];

                vm.PickupDate    = viewModel.DeliveryDate;
                vm.SelectedStore = viewModel.DeliveryStore;
            }

            using (formPickupInformation pickup = new formPickupInformation(vm))
            {
                LSRetailPosis.POSProcesses.POSFormsManager.ShowPOSForm(pickup);

                if (pickup.DialogResult == DialogResult.OK)
                {
                    return(pickup.ViewModel);
                }
            }

            return(null);
        }
Ejemplo n.º 4
0
        private static void CommitShippingCharge(SaleLineItem lineItem, CustomerOrderTransaction trans, decimal?charge)
        {
            // First check if a shipping charge code was configured on the back end and exists in the DB
            string shippingChargeCode = LSRetailPosis.Settings.ApplicationSettings.Terminal.ShippingChargeCode;

            if (charge.HasValue && string.IsNullOrWhiteSpace(shippingChargeCode))
            {
                // "A shipping charge cannot be added for item: {0} because a shipping charge code was not found."
                string errorMessage = string.Format(LSRetailPosis.ApplicationLocalizer.Language.Translate(56301), lineItem.ItemId);
                SalesOrder.LogMessage(errorMessage, LSRetailPosis.LogTraceLevel.Error);

                throw new InvalidOperationException(errorMessage);
            }

            // Shipping charge
            Tax.MiscellaneousCharge mc = lineItem.MiscellaneousCharges.FirstOrDefault(m => m.ChargeCode == shippingChargeCode);

            // See if there's an existing charge
            if (mc == null)
            {
                if (charge.HasValue)
                {
                    // No charge exists, so we add it

                    // Get Cancellation charge properties from DB
                    StoreDataManager store = new StoreDataManager(
                        SalesOrder.InternalApplication.Settings.Database.Connection,
                        SalesOrder.InternalApplication.Settings.Database.DataAreaID);

                    DataEntity.MiscellaneousCharge chargeProperties = store.GetMiscellaneousCharge(shippingChargeCode);

                    if (chargeProperties != null)
                    {
                        mc = new Tax.MiscellaneousCharge(
                            charge.Value,
                            trans.Customer.SalesTaxGroup,
                            chargeProperties.TaxItemGroup,
                            chargeProperties.MarkupCode,
                            string.Empty,
                            trans);

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

                        lineItem.MiscellaneousCharges.Add(mc);
                    }
                    else
                    {
                        // "A shipping charge cannot be added for item: {0} because no information was found for shipping charge code: {1}."
                        string errorMessage = string.Format(LSRetailPosis.ApplicationLocalizer.Language.Translate(56303), lineItem.ItemId, shippingChargeCode);
                        SalesOrder.LogMessage(errorMessage, LSRetailPosis.LogTraceLevel.Error);

                        throw new InvalidOperationException(errorMessage);
                    }
                }
            }
            else // Charge exists
            {
                if (charge.HasValue)
                {
                    if (mc.Amount != charge.Value)
                    {
                        // Update amount
                        mc.Amount = charge.Value;
                    }
                }
                else
                {
                    // No charge, so remove
                    lineItem.MiscellaneousCharges.Remove(mc);
                }
            }

            // Remove any header level charge
            var headerCharge = trans.MiscellaneousCharges.FirstOrDefault(m => m.ChargeCode == shippingChargeCode);

            if (headerCharge != null)
            {
                trans.MiscellaneousCharges.Remove(headerCharge);
            }

            // Trigger new price,tax and discount for the customer (do NOT reset item prices because we should preserve any existing Price Overrides)
            SalesOrder.InternalApplication.BusinessLogic.ItemSystem.RecalcPriceTaxDiscount(trans, false);
            trans.CalcTotals();
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Save changes back to models
        /// </summary>
        public void CommitHeaderChanges()
        {
            SalesOrder.InternalApplication.BusinessLogic.CustomerSystem.SetShippingAddress(transaction, this.ShippingAddress);

            // Delivery date
            this.transaction.RequestedDeliveryDate = this.DeliveryDate.Value;

            // Shipping method
            this.transaction.DeliveryMode = storeDataManager.GetDeliveryMode(this.ShippingMethod.Code);

            // Shipping warehouse
            this.transaction.WarehouseId = LSRetailPosis.Settings.ApplicationSettings.Terminal.InventLocationIdForCustomerOrder;

            // Clear any line item delivery options
            foreach (var item in this.transaction.SaleItems)
            {
                ClearLineDeliveryOptions(item);

                item.ShippingAddress = this.transaction.ShippingAddress;
                item.DeliveryMode    = this.transaction.DeliveryMode;

                if (this.transaction.RequestedDeliveryDate != default(DateTime))
                {
                    item.DeliveryDate = this.transaction.RequestedDeliveryDate;
                }

                SalesOrder.InternalApplication.BusinessLogic.CustomerSystem.ResetCustomerTaxGroup(item);
            }

            //
            // Shipping charge
            //

            // First check if a shipping charge code was configured on the back end and exists in the DB
            string shippingChargeCode = LSRetailPosis.Settings.ApplicationSettings.Terminal.ShippingChargeCode;

            if (this.ShippingCharge.HasValue && string.IsNullOrWhiteSpace(shippingChargeCode))
            {
                // "A shipping charge cannot be added because a shipping charge code was not found."
                string errorMessage = LSRetailPosis.ApplicationLocalizer.Language.Translate(56302);
                SalesOrder.LogMessage(errorMessage, LSRetailPosis.LogTraceLevel.Error);

                throw new InvalidOperationException(errorMessage);
            }

            Tax.MiscellaneousCharge mc = this.Transaction.MiscellaneousCharges.SingleOrDefault(m => m.ChargeCode == LSRetailPosis.Settings.ApplicationSettings.Terminal.ShippingChargeCode);

            // See if there's an existing charge
            if (mc == null)
            {
                if (this.ShippingCharge.HasValue)
                {
                    // No charge exists, so we add it

                    // Get Cancellation charge properties from DB
                    DM.StoreDataManager store = new DM.StoreDataManager(
                        SalesOrder.InternalApplication.Settings.Database.Connection,
                        SalesOrder.InternalApplication.Settings.Database.DataAreaID);

                    DataEntity.MiscellaneousCharge chargeProperties = store.GetMiscellaneousCharge(LSRetailPosis.Settings.ApplicationSettings.Terminal.ShippingChargeCode);

                    if (chargeProperties != null)
                    {
                        mc = new Tax.MiscellaneousCharge(
                            this.ShippingCharge.Value,
                            this.transaction.Customer.SalesTaxGroup,
                            chargeProperties.TaxItemGroup,
                            chargeProperties.MarkupCode,
                            string.Empty,
                            this.Transaction);

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

                        this.Transaction.MiscellaneousCharges.Add(mc);
                    }
                    else
                    {
                        // "A shipping charge cannot be added because no information was found for shipping charge code: {0}."
                        string errorMessage = string.Format(LSRetailPosis.ApplicationLocalizer.Language.Translate(56304), shippingChargeCode);
                        SalesOrder.LogMessage(errorMessage, LSRetailPosis.LogTraceLevel.Error);

                        throw new InvalidOperationException(errorMessage);
                    }
                }
            }
            else // Charge exists
            {
                if (this.ShippingCharge.HasValue)
                {
                    if (mc.Amount != this.ShippingCharge.Value)
                    {
                        // Update amount
                        mc.Amount = this.ShippingCharge.Value;
                    }
                }
                else
                {
                    // No charge, so remove
                    this.Transaction.MiscellaneousCharges.Remove(mc);
                }
            }

            // Trigger new price,tax and discount for the customer
            // We should preserve any existing Price Overrides
            SalesOrder.InternalApplication.BusinessLogic.ItemSystem.RecalcPriceTaxDiscount(this.Transaction, false);
            this.Transaction.CalcTotals();
        }