Exemplo n.º 1
0
        /// <summary>
        /// Checks if stock is availble for work to start
        /// </summary>
        /// <param name="sys_doc_type"></param>
        /// <returns></returns>
        private bool HasItems(BL.SYS.SYS_DOC_Type sys_doc_type)
        {
            bool hasItems = true;

            //Recipe Items
            foreach (DB.ITM_BOM_RecipeLine line in ((DB.ITM_BOM_Recipe)BindingSource.DataSource).ITM_BOM_RecipeLine)
            {
                if (line.Quantity * (sys_doc_type == BL.SYS.SYS_DOC_Type.BOMAssemblyStarted ? 1 : -1) < 0)
                {
                    DB.ITM_History itm_history = BL.ITM.ITM_History.GetItemCurrentHistory(DataContext.EntityInventoryContext.ITM_Inventory.FirstOrDefault(n => n.EntityId == line.ItemId), DataContext);

                    if (itm_history.OnHand < -line.Quantity)
                    {
                        hasItems = false;
                        break;
                    }
                }
            }
            //Source Item
            DB.ITM_BOM_Recipe recipe = (DB.ITM_BOM_Recipe)BindingSource.DataSource;
            DB.ITM_History    itm_historyItemResult = BL.ITM.ITM_History.GetItemCurrentHistory(DataContext.EntityInventoryContext.ITM_Inventory.FirstOrDefault(n => n.EntityId == recipe.ItemResultId), DataContext);
            if (recipe.QuantityResult * (sys_doc_type == BL.SYS.SYS_DOC_Type.BOMAssemblyStarted ? 1 : -1) < 0)
            {
                if (itm_historyItemResult.OnHand < -recipe.QuantityResult * (sys_doc_type == BL.SYS.SYS_DOC_Type.BOMAssemblyStarted ? 1 : -1))
                {
                    hasItems = false;
                }
            }
            if (!hasItems)
            {
                Essential.BaseAlert.ShowAlert("Insufficient On Hand", "Insufficient On Hand to start work", Essential.BaseAlert.Buttons.Ok, Essential.BaseAlert.Icons.Error);
            }

            return(hasItems);
        }
Exemplo n.º 2
0
        internal static void UpdateHistoryUnitAverageAndProfitMargin(DB.SYS_DOC_Line line, byte typeId, DataContext dataContext)
        {
            //Get current History
            DB.ITM_History itm_history = BL.ITM.ITM_History.GetItemCurrentHistory(dataContext.EntityInventoryContext.ITM_Inventory.FirstOrDefault(n => n.EntityId == line.ItemId), dataContext);
            //Force Reload history from DB
            dataContext.EntityInventoryContext.Entry(itm_history).Reload();
            //Calculate new Average Cost
            decimal?newAverageCost = GetNewAverageCost(ref itm_history, line, typeId, dataContext);

            //Update Unit Selling form profit margin
            if (newAverageCost > itm_history.UnitAverage && line.LineItem.ProfitMargin != null)
            {
                //Added for the Log entry for UnitPrice
                itm_history.UnitPrice = Convert.ToDecimal(Math.Round(newAverageCost.Value / ((100.00M - (decimal)line.LineItem.ProfitMargin.Value) / 100.00M), 2));
                BL.ITM.ITM_History.UpdateHistoryUnitPrice(line.ItemId, itm_history.UnitPrice, dataContext);
            }
            //Change Price to new Average Cost (so that we cannot set stock at a loss
            if (newAverageCost > itm_history.UnitPrice)
            {
                itm_history.UnitPrice = newAverageCost.Value;
                BL.ITM.ITM_History.UpdateHistoryUnitPrice(line.ItemId, itm_history.UnitPrice, dataContext);
            }
            //If OnHand + OnReserve != 0
            if (newAverageCost != null && newAverageCost != itm_history.UnitAverage)
            {
                //Added for the Log entry for UnitAverage
                itm_history.UnitAverage = newAverageCost.Value;
                BL.ITM.ITM_History.UpdateHistoryUnitAverage(line.ItemId, newAverageCost.Value, dataContext);
            }
        }
Exemplo n.º 3
0
        protected override bool SaveSuccessful()
        {
            try
            {
                DialogResult result = Essential.BaseAlert.ShowAlert("Save Document", "You are about the save this document do you wish to continue ?", Essential.BaseAlert.Buttons.OkCancel, Essential.BaseAlert.Icons.Information);
                using (new CDS.Client.Desktop.Essential.UTL.WaitCursor())
                {
                    this.OnSaveRecord();

                    Int64 printerId = 0;
                    switch (result)
                    {
                    case System.Windows.Forms.DialogResult.Yes:
                        printerId = BL.ApplicationDataContext.Instance.LoggedInUser.DefaultPrinterId.Value;
                        break;

                    case System.Windows.Forms.DialogResult.No:
                        printerId = 0;
                        break;

                    case System.Windows.Forms.DialogResult.Cancel:
                        printerId = -1;
                        return(false);
                    }

                    DB.SYS_DOC_Header entry = ((DB.SYS_DOC_Header)BindingSourceDocument.DataSource);
                    entry.ITM_BOM_Document = ((DB.ITM_BOM_Document)BindingSource.DataSource);
                    //Add result item
                    DB.SYS_DOC_Line resultLine = BL.SYS.SYS_DOC_Line.New;
                    resultLine.ItemId = ((DB.ITM_BOM_Recipe)BindingSourceRecipe.DataSource).ItemResultId;
                    DB.ITM_History itm_history = BL.ITM.ITM_History.GetItemCurrentHistory(DataContext.EntityInventoryContext.ITM_Inventory.FirstOrDefault(n => n.EntityId == resultLine.ItemId), DataContext);
                    resultLine.Quantity    = ((DB.ITM_BOM_Recipe)BindingSourceRecipe.DataSource).QuantityResult * (entry.TypeId == (byte)BL.SYS.SYS_DOC_Type.BOMAssemblyStarted ? 1 : -1);
                    resultLine.Description = DataContext.ReadonlyContext.VW_LineItem.FirstOrDefault(n => n.Id == resultLine.ItemId).Description;
                    resultLine.Amount      = itm_history.UnitAverage;
                    resultLine.Total       = resultLine.Quantity * resultLine.Amount;
                    resultLine.TotalTax    = 0;
                    //SYS DOC Lines
                    sys_doc_line.Add(resultLine);
                    sys_doc_line.ForEach(n => n.LineItem = DataContext.ReadonlyContext.VW_LineItem.FirstOrDefault(k => k.Id == n.ItemId));
                    BL.ApplicationDataContext.Instance.Service.SaveDocument(entry, printerId);
                    btnComplete.Visibility = DevExpress.XtraBars.BarItemVisibility.Always;
                    btnCancel.Visibility   = DevExpress.XtraBars.BarItemVisibility.Always;

                    return(true);

                    //If you ever remove this make sure that you refresh all the datasources as the BindingSource.DataSource is save disjoint from the DataContext
                    ForceClose = true;
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                {
                    throw ex;
                }
                return(false);
            }
        }
Exemplo n.º 4
0
        public static DB.ITM_History GetItemCurrentHistory(DB.ITM_Inventory entry, DataContext dataContext)
        {
            DB.SYS_Period  currentPeriod = SYS.SYS_Period.GetCurrentPeriod(dataContext);
            DB.ITM_History history       = dataContext.EntityInventoryContext.ITM_History.FirstOrDefault(n => n.InventoryId ==
                                                                                                         entry.EntityId && n.PeriodId == currentPeriod.Id && n.SiteId == ApplicationDataContext.Instance.LoggedInUser.DefaultSiteId);

            return(history);
        }
Exemplo n.º 5
0
        internal static String Save(DB.ITM_History entry, DataContext dataContext)
        {
            try
            {
                if (dataContext.EntityInventoryContext.GetEntityState(entry) == System.Data.Entity.EntityState.Detached)
                {
                    dataContext.EntityInventoryContext.ITM_History.Add(entry);
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                return(dataContext.PackageValidationException());
            }

            return("Success");
        }
Exemplo n.º 6
0
 protected override void OnNewRecord()
 {
     base.OnNewRecord();
     AllowArchive        = false;
     AllowRefresh        = false;
     itmInventory        = BL.ITM.ITM_Inventory.New;
     sysInventoryEntity  = BL.SYS.SYS_Entity.NewInventory;
     itmHistory          = BL.ITM.ITM_History.New;
     itmHistory.PeriodId = BL.SYS.SYS_Period.GetCurrentPeriod(DataContext).Id;
     if (BL.ApplicationDataContext.Instance.Modules.Any(n => n.Id == (byte)BL.SYS.SYS_Modules.GLX && n.Code == "YES"))
     {
         itmInventory.InventoryId   = BL.ApplicationDataContext.Instance.SiteAccounts.Inventory.EntityId;
         itmInventory.CostofSalesId = BL.ApplicationDataContext.Instance.SiteAccounts.CostOfSales.EntityId;
     }
     txtName.Properties.ReadOnly = false;
     txtName.BackColor           = Color.White;
 }
Exemplo n.º 7
0
        public override void OpenRecord(long Id)
        {
            base.OpenRecord(Id);
            AllowRefresh       = true;
            itmInventory       = BL.ITM.ITM_Inventory.Load(Id, DataContext);
            sysInventoryEntity = BL.SYS.SYS_Entity.Load(itmInventory.EntityId, DataContext);
            itmHistory         = BL.ITM.ITM_History.GetItemCurrentHistory(itmInventory, DataContext);

            foreach (var item in BL.ITM.ITM_Surcharge.LoadByEntityId(sysInventoryEntity.Id, DataContext))
            {
                itmSurcharge.Add(item);
            }

            foreach (var item in BL.ITM.ITM_InventorySupplier.LoadByEntityId(sysInventoryEntity.Id, DataContext))
            {
                itmInventorySupplier.Add(item);
            }
        }
Exemplo n.º 8
0
        public override void RefreshRecord()
        {
            base.RefreshRecord();
            if (chkAllSites.CheckState == CheckState.Unchecked)
            {
                colTransactionSiteName.Visible = false;
            }
            else
            {
                colTransactionSiteName.Visible = true;
            }

            DataContext.EntityInventoryContext.ReloadEntry(itmInventory);
            DataContext.EntitySystemContext.ReloadEntry(sysInventoryEntity);
            itmHistory = BL.ITM.ITM_History.GetItemCurrentHistory(itmInventory, DataContext);
            DataContext.EntityInventoryContext.ReloadEntry(itmHistory);
            InstantFeedbackSourceTransaction = new DevExpress.Data.Linq.LinqInstantFeedbackSource(InstantFeedbackSourceTransaction_GetQueryable);
            grdTransactions.DataSource       = InstantFeedbackSourceTransaction;
            grvTransactions.RefreshData();
            InstantFeedbackSourceTransaction.Refresh();
            InstantFeedbackSourceOutstandingOrders.Refresh();
            InstantFeedbackSourceOutstandingTransfers.Refresh();
            InstantFeedbackSourceSalesHistory.Refresh();
        }
Exemplo n.º 9
0
        private static decimal?GetNewAverageCost(ref DB.ITM_History itm_history, DB.SYS_DOC_Line line, byte documentType, DataContext dataContext)
        {
            long    stockModifier  = dataContext.EntitySystemContext.SYS_DOC_Type.Where(n => n.Id == documentType).Select(n => n.StockModifier).FirstOrDefault();
            decimal?newAverageCost = null;

            if (((itm_history.OnHand + itm_history.OnReserve) + (stockModifier * line.Quantity)) != 0)
            {
                switch (documentType)
                {
                case (byte)BL.SYS.SYS_DOC_Type.Quote:
                    break;

                case (byte)BL.SYS.SYS_DOC_Type.SalesOrder:
                    break;

                case (byte)BL.SYS.SYS_DOC_Type.TAXInvoice:
                    newAverageCost = (((itm_history.OnHand + itm_history.OnReserve) * itm_history.UnitAverage) + ((stockModifier * line.Quantity) * line.UnitAverage)) / ((itm_history.OnHand + itm_history.OnReserve) + stockModifier * line.Quantity);
                    break;

                case (byte)BL.SYS.SYS_DOC_Type.CreditNote:
                    newAverageCost = (((itm_history.OnHand + itm_history.OnReserve) * itm_history.UnitAverage) + ((stockModifier * line.Quantity) * line.UnitAverage)) / ((itm_history.OnHand + itm_history.OnReserve) + stockModifier * line.Quantity);
                    break;

                case (byte)BL.SYS.SYS_DOC_Type.PickingSlip:
                    break;

                case (byte)BL.SYS.SYS_DOC_Type.PurchaseOrder:
                    break;

                case (byte)BL.SYS.SYS_DOC_Type.GoodsReceived:
                    newAverageCost = (((itm_history.OnHand + itm_history.OnReserve) * itm_history.UnitAverage) + ((stockModifier * line.Quantity) * line.Amount)) / ((itm_history.OnHand + itm_history.OnReserve) + stockModifier * line.Quantity);
                    break;

                case (byte)BL.SYS.SYS_DOC_Type.GoodsReturned:
                    newAverageCost = (((itm_history.OnHand + itm_history.OnReserve) * itm_history.UnitAverage) + ((stockModifier * line.Quantity) * line.Amount)) / ((itm_history.OnHand + itm_history.OnReserve) + stockModifier * line.Quantity);
                    break;

                case (byte)BL.SYS.SYS_DOC_Type.Job:
                    newAverageCost = (((itm_history.OnHand + itm_history.OnReserve) * itm_history.UnitAverage) + ((stockModifier * line.Quantity) * line.UnitAverage)) / ((itm_history.OnHand + itm_history.OnReserve) + stockModifier * line.Quantity);
                    break;

                case (byte)BL.SYS.SYS_DOC_Type.TransferRequest:
                    break;

                case (byte)BL.SYS.SYS_DOC_Type.TransferShipment:
                    newAverageCost = (((itm_history.OnHand + itm_history.OnReserve) * itm_history.UnitAverage) + ((stockModifier * line.Quantity) * line.UnitAverage)) / ((itm_history.OnHand + itm_history.OnReserve) + stockModifier * line.Quantity);
                    break;

                case (byte)BL.SYS.SYS_DOC_Type.TransferReceived:
                    newAverageCost = (((itm_history.OnHand + itm_history.OnReserve) * itm_history.UnitAverage) + ((stockModifier * line.Quantity) * line.Amount)) / ((itm_history.OnHand + itm_history.OnReserve) + stockModifier * line.Quantity);
                    break;

                case (byte)BL.SYS.SYS_DOC_Type.InventoryAdjustment:
                    newAverageCost = (((itm_history.OnHand + itm_history.OnReserve) * itm_history.UnitAverage) + ((stockModifier * line.Quantity) * line.Amount)) / ((itm_history.OnHand + itm_history.OnReserve) + stockModifier * line.Quantity);
                    break;

                case (byte)BL.SYS.SYS_DOC_Type.BackOrder:
                    break;

                case (byte)BL.SYS.SYS_DOC_Type.BOMCanceled:
                    newAverageCost = (((itm_history.OnHand + itm_history.OnReserve) * itm_history.UnitAverage) + ((stockModifier * line.Quantity) * line.UnitAverage)) / ((itm_history.OnHand + itm_history.OnReserve) + line.Quantity);
                    break;

                case (byte)BL.SYS.SYS_DOC_Type.BOMComplete:
                    newAverageCost = (((itm_history.OnHand + itm_history.OnReserve) * itm_history.UnitAverage) + ((stockModifier * line.Quantity) * line.UnitAverage)) / ((itm_history.OnHand + itm_history.OnReserve) + line.Quantity);
                    break;
                }
            }
            return(newAverageCost);
        }