コード例 #1
0
        /// <summary>
        /// Get a sales order or quote by id
        /// </summary>
        /// <param name="orderId"></param>
        /// <param name="orderType"></param>
        /// <returns></returns>
        internal static CustomerOrderTransaction GetCustomerOrder(string orderId, CustomerOrderType orderType, CustomerOrderMode forMode)
        {
            CustomerOrderTransaction result = null;
            IRetailTransaction       order;
            bool   retValue = false;
            string comment;

            //Verify that the user has rights to EDIT an order, and prompt for access.
            if (!SalesOrder.InternalApplication.Services.LogOn.VerifyOperationAccess(SalesOrder.InternalApplication.Shift.StaffId, PosisOperations.CustomerOrderDetails))
            {
                return(null);
            }

            switch (orderType)
            {
            case CustomerOrderType.SalesOrder:
                SalesOrder.InternalApplication.Services.SalesOrder.GetCustomerOrder(
                    ref retValue, orderId, out comment, out order);
                break;

            case CustomerOrderType.Quote:
                SalesOrder.InternalApplication.Services.SalesOrder.GetCustomerQuote(
                    ref retValue, orderId, out comment, out order);
                break;

            default:
                throw new InvalidOperationException("Unsupported CustomerOrderType");
            }

            if (retValue)
            {
                // Cache the order
                CustomerOrderTransaction customerOrder = (CustomerOrderTransaction)order;
                customerOrder.Mode = forMode;

                if (forMode == CustomerOrderMode.Cancel)
                {
                    AddDefaultCancellationCharge(customerOrder);
                }

                customerOrder.CalcTotals();

                result = customerOrder;
            }
            else
            {
                // The sales order was not found in AX
                ApplicationLog.Log(SalesOrderActions.LogSource,
                                   string.Format("{0}\n{1}", ApplicationLocalizer.Language.Translate(56124), comment),
                                   LogTraceLevel.Error);
                SalesOrder.InternalApplication.Services.Dialog.ShowMessage(56124, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            return(result);
        }
コード例 #2
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();
        }