Exemplo n.º 1
0
        /// <summary>
        /// Sets view state of the Add Custom Product view based on a set of rules.
        /// </summary>
        /// <param name="form">The Edit Sales Order Item form.</param>
        /// <param name="args">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        public static void OnLoad1Step(IICEditSalesOrderItem form, EventArgs args)
        {
            ISalesOrderItem   salesOrderItem = form.CurrentEntity as ISalesOrderItem;
            ISalesOrder       salesOrder     = salesOrderItem.SalesOrder;
            IWebDialogService dialogService  = form.Services.Get <IWebDialogService>();

            if (dialogService != null && dialogService.DialogParameters.ContainsKey("CustomProductSalesOrder"))
            {
                salesOrder = dialogService.DialogParameters["CustomProductSalesOrder"] as ISalesOrder;
                salesOrderItem.SalesOrder      = salesOrder;
                salesOrderItem.Quantity        = 1;
                salesOrderItem.CalculatedPrice = 0;
                salesOrderItem.Discount        = 0;
                salesOrderItem.ExtendedPrice   = 0;
                salesOrderItem.Price           = 0;
                dialogService.DialogParameters.Remove("CustomProductSalesOrder");
            }

            if (salesOrder != null && salesOrder.IsMultiCurrencyEnabled())
            {
                form.curMCCalcPrice.ExchangeRate     = salesOrder.ExchangeRate.GetValueOrDefault(1);
                form.curMCCalcPrice.CurrentCode      = salesOrder.CurrencyCode;
                form.curMCCalcPrice.ExchangeRateType = Sage.Platform.Controls.ExchangeRateTypeEnum.EntityRate;
                form.curMCCalcPrice.Text             = salesOrderItem.CalculatedPrice.ToString();
            }
            else
            {
                form.ctrlstMCPrice.Visible = false;
            }

            form.ctrlstLineNumber.Visible = (salesOrderItem.Id != null);

            if (salesOrderItem.Product == null) // AdHocProduct
            {
                if (String.IsNullOrEmpty(salesOrderItem.LineType))
                {
                    salesOrderItem.LineType = "FreeText"; // Use as literal; represents adhoc product.
                }
                form.curPrice.IsReadOnly       = false;
                form.txtSKU.IsReadOnly         = false;
                form.txtFamily.IsReadOnly      = false;
                form.txtDescription.IsReadOnly = false;
                form.txtProduct.IsReadOnly     = false;
                form.ctrlstWarehouse.Visible   = false;
                form.ctrlstWarehouses.Visible  = false;
            }
            IAppIdMappingService mappingService = Sage.Platform.Application.ApplicationContext.Current.Services.Get <IAppIdMappingService>(true);
            //if this is a Sales Order that synced from the accounting system or the Sales Order has been submitted then we disable it
            bool isOpen = false;

            if (!String.IsNullOrEmpty(salesOrder.ERPSalesOrder.ERPStatus))
            {
                isOpen = (salesOrder.ERPSalesOrder.ERPStatus.Equals(
                              form.GetResource("erpStatus_Open").ToString()) ||
                          salesOrder.ERPSalesOrder.ERPStatus.Equals(form.GetResource("erpStatus_Rejected").ToString()));
            }
            bool erpSalesOrder = (mappingService.IsIntegrationEnabled() && (salesOrder.GlobalSyncId.HasValue && !isOpen));

            form.txtDescription.Enabled      = !erpSalesOrder;
            form.txtFamily.Enabled           = !erpSalesOrder;
            form.lueLocation.Enabled         = !erpSalesOrder;
            form.numDiscount.Enabled         = !erpSalesOrder;
            form.currCalculatedPrice.Enabled = !erpSalesOrder;
            form.numQuantity.Enabled         = !erpSalesOrder;
            form.lueUnitOfMeasure.Enabled    = !erpSalesOrder;
            form.chkPriceLocked.Enabled      = !erpSalesOrder;
            form.btnOk.Visible       = !erpSalesOrder;
            form.txtComments.Enabled = !erpSalesOrder;
            form.btnCancel.Caption   = form.GetResource("Closed_Caption").ToString();

            IRoleSecurityService roleSecurityService = form.Services.Get <IRoleSecurityService>(true);

            form.chkPriceLocked.Enabled = roleSecurityService.HasAccess("IntegrationContract/LockPricing");
        }