Exemplo n.º 1
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.º 2
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.º 3
0
        private void ValidateLineQuantity(DB.SYS_DOC_Line line)
        {
            if (line.Quantity < 0)
            {
                line.Quantity = 0;
            }

            line.Quantity = Math.Min(line.Quantity, line.LineItem.OnHand);
        }
Exemplo n.º 4
0
 private void AddLine(Int64 entityId)
 {
     DB.SYS_DOC_Line line = BL.SYS.SYS_DOC_Line.New;
     line.ItemId   = entityId;
     line.LineItem = DataContext.ReadonlyContext.VW_LineItem.FirstOrDefault(n => n.Id == entityId);
     PopulateLine(line);
     CalculateTotals(line);
     lines.Add(line);
     line.LineOrder = lines.Count();
 }
Exemplo n.º 5
0
        private void btnOk_Click(object sender, EventArgs e)
        {
            ValidateLayout();

            DialogResult result = Essential.DocumentAlert.ShowAlert("Save Document", "You are about to save this document do you wish to continue ?", Essential.DocumentAlert.Buttons.SaveAndPrint);

            if (result == System.Windows.Forms.DialogResult.Cancel)
            {
                return;
            }

            using (new CDS.Client.Desktop.Essential.UTL.WaitCursor())
            {
                string message;
                Int64  printerId = 0;

                lines.ForEach(n =>
                {
                    //1st remove current cost
                    var removalCost             = n.UnitAverage;
                    DB.SYS_DOC_Line removalLine = BL.ApplicationDataContext.DeepClone <DB.SYS_DOC_Line>(n, BL.SYS.SYS_DOC_Line.New);
                    removalLine.Quantity        = -n.Quantity;
                    removalLine.Amount          = removalCost;
                    removalLine.LineItem        = n.LineItem;
                    CalculateTotals(removalLine);
                    ((DB.SYS_DOC_Header)BindingSource.DataSource).SYS_DOC_Line.Add(removalLine);
                    removalLine.LineOrder = Doc_Header.SYS_DOC_Line.Count();
                    //then re add with new cost
                    CalculateTotals(n);
                    ((DB.SYS_DOC_Header)BindingSource.DataSource).SYS_DOC_Line.Add(n);
                    n.LineOrder = Doc_Header.SYS_DOC_Line.Count();
                });

                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;
                }
                message = BL.ApplicationDataContext.Instance.Service.SaveDocument((DB.SYS_DOC_Header)BindingSource.DataSource, printerId);
                if (message.StartsWith("Success"))
                {
                    ShowNotification("Saved Changes", String.Format("Average Cost Document number {0} was saved successfully", message.Split(',')[1]), 5000, false, null);
                    this.DialogResult = System.Windows.Forms.DialogResult.OK;
                }
                else
                {
                }
            }
            this.Close();
        }
Exemplo n.º 6
0
        private void CalculateTotals(DB.SYS_DOC_Line line)
        {
            //line.ProfitPercentage = (line.Amount > 0) ? (line.Amount - line.UnitAverage) / line.Amount : 0M;
            line.Total = line.Amount * line.Quantity;
            decimal totalExcl = 0.00M, totalTax = 0.00M, totalIncl = 0.00M;

            line.TotalTax = 0.00M;
            lines.ForEach(n => totalExcl += n.Total);
            lines.ForEach(n => totalTax  += n.TotalTax);
            lines.ForEach(n => totalIncl += (n.Total + n.TotalTax));
        }
Exemplo n.º 7
0
        private void grvItems_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            DB.SYS_DOC_Line line = (grvItems.GetFocusedRow() as DB.SYS_DOC_Line);

            switch (e.Column.FieldName)
            {
            //Handeled by Repository Item
            case "ItemId":
                //Populate all fields for this items line
                AddLine(line.ItemId);
                break;
            }
        }
Exemplo n.º 8
0
        public void NewDocument(Int64 recipeId, BL.SYS.SYS_DOC_Type itm_bom_type)
        {
            try
            {
                //Werner: Need to run this to get the NewRecord behaviour of the form
                OnNewRecord();
                btnComplete.Visibility          = DevExpress.XtraBars.BarItemVisibility.Never;
                btnCancel.Visibility            = DevExpress.XtraBars.BarItemVisibility.Never;
                txtQuantityActualResult.Enabled = false;
                //Recipe
                BindingSourceRecipe.DataSource = BL.ITM.ITM_BOM_Recipe.Load(recipeId, DataContext, new List <string>()
                {
                    "ITM_BOM_RecipeLine"
                });                                                                                                                              //DataContext.EntityInventoryContext.ITM_BOM_Recipe.FirstOrDefault(n => n.Id == recipeId);
                //SYS DOC Header
                BindingSourceDocument.DataSource = BL.SYS.SYS_DOC_Document.New(itm_bom_type);
                //BOM Document
                BindingSource.DataSource = BL.ITM.ITM_BOM_Document.New;//((DB.SYS_DOC_Header)BindingSourceDocument.DataSource).ITM_BOM_Document.FirstOrDefault();
                //Link item to BOM Document
                ((DB.ITM_BOM_Document)BindingSource.DataSource).RecipeId               = ((DB.ITM_BOM_Recipe)BindingSourceRecipe.DataSource).Id;
                ((DB.ITM_BOM_Document)BindingSource.DataSource).ItemResultId           = ((DB.ITM_BOM_Recipe)BindingSourceRecipe.DataSource).ItemResultId;
                ((DB.ITM_BOM_Document)BindingSource.DataSource).QuantityExpectedResult = ((DB.ITM_BOM_Recipe)BindingSourceRecipe.DataSource).QuantityResult * (itm_bom_type == BL.SYS.SYS_DOC_Type.BOMAssemblyStarted ? 1 : -1);

                //Link Lines
                ((DB.SYS_DOC_Header)BindingSourceDocument.DataSource).SYS_DOC_Line = sys_doc_line;
                BindingSourceDocumentLine.DataSource = sys_doc_line;

                //Populate the SYS_DOC_Header's lines
                foreach (var recipeLine in ((DB.ITM_BOM_Recipe)BindingSourceRecipe.DataSource).ITM_BOM_RecipeLine)
                {
                    DB.SYS_DOC_Line line = BL.SYS.SYS_DOC_Line.New;
                    line.ItemId      = recipeLine.ItemId;
                    line.Description = BL.SYS.SYS_Entity.Load(recipeLine.ItemId, DataContext).Description;
                    line.Quantity    = recipeLine.Quantity * (itm_bom_type == BL.SYS.SYS_DOC_Type.BOMAssemblyStarted ? 1 : -1);
                    line.Amount      = recipeLine.Amount;
                    line.Total       = line.Quantity * line.Amount;
                    line.TotalTax    = 0;

                    //SYS DOC Lines
                    sys_doc_line.Add(line);
                }
            }
            catch (Exception ex)
            {
                if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
                {
                    throw ex;
                }
            }
        }
Exemplo n.º 9
0
        private void PopulateLine(DB.SYS_DOC_Line line)
        {
            if (line == null || line.LineItem == null)
            {
                return;
            }

            line.Quantity     = line.LineItem.OnHand;
            line.Description  = line.LineItem.Description;
            line.UnitAverage  = line.LineItem.UnitAverage;
            line.UnitCost     = line.LineItem.UnitCost;
            line.Amount       = line.LineItem.UnitAverage;
            line.PriceChanged = false;
        }
Exemplo n.º 10
0
        internal static String Save(DB.SYS_DOC_Line entry, DataContext dataContext)
        {
            try
            {
                if (dataContext.EntitySystemContext.GetEntityState(entry) == System.Data.Entity.EntityState.Detached)
                {
                    dataContext.EntitySystemContext.SYS_DOC_Line.Add(entry);
                }
            }
            catch (System.Data.Entity.Validation.DbEntityValidationException ex)
            {
                return(dataContext.PackageValidationException());
            }

            return("Success");
        }
Exemplo n.º 11
0
 private void repLineEntity_EditValueChanged(object sender, EventArgs e)
 {
     try
     {
         DB.SYS_DOC_Line line     = SelectedLine;
         Int64           entityId = Convert.ToInt64((sender as DevExpress.XtraEditors.SearchLookUpEdit).EditValue);
         line.LineItem = DataContext.ReadonlyContext.VW_LineItem.FirstOrDefault(n => n.Id == entityId);
     }
     catch (Exception ex)
     {
         if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex))
         {
             throw ex;
         }
     }
 }
Exemplo n.º 12
0
        private static DB.SYS_DOC_Header CopyDocument(DB.SYS_DOC_Header entity, DataContext dataContext)
        {
            DB.SYS_DOC_Header docHeader = ApplicationDataContext.DeepClone <DB.SYS_DOC_Header>(entity, SYS.SYS_DOC_Document.New(SYS.SYS_DOC_Type.Quote));
            docHeader.DocumentNumber = null;
            DB.ORG_TRX_Header trxHeader = null;
            if (entity.ORG_TRX_Header != null)
            {
                trxHeader = ApplicationDataContext.DeepClone <DB.ORG_TRX_Header>(entity.ORG_TRX_Header, ORG.ORG_TRX_Header.New);
            }
            DB.JOB_Header jobHeader = null;
            if (entity.JOB_Header != null)
            {
                jobHeader = ApplicationDataContext.DeepClone <DB.JOB_Header>(entity.JOB_Header, JOB.JOB_Header.New);
            }

            foreach (DB.SYS_DOC_Line line in entity.SYS_DOC_Line)
            {
                DB.SYS_DOC_Line newLine = ApplicationDataContext.DeepClone <DB.SYS_DOC_Line>(line, SYS.SYS_DOC_Line.New);

                //Werner: Wanted to do this here but some of the document needs these values to generate another document
                ////Need to clear these when copying a documents lines
                //newLine.QtyReceived = 0;
                //newLine.QtyOutstanding = 0;
                //TODO : Just check but this should always be null as the DeepCopy
                //ignores all DB.* types
                if (line.LineItem != null)
                {
                    newLine.LineItem = line.LineItem;
                }
                else
                {
                    if (!dataContext.ReadonlyContext.VW_LineItem.Any(n => n.Id == newLine.ItemId && n.TypeId == (byte)SYS.SYS_Type.Account))
                    {
                        newLine.LineItem    = dataContext.ReadonlyContext.VW_LineItem.FirstOrDefault(n => n.Id == newLine.ItemId);
                        newLine.UnitAverage = newLine.LineItem.UnitAverage;
                        newLine.UnitCost    = newLine.LineItem.UnitCost;
                    }
                }

                docHeader.SYS_DOC_Line.Add(newLine);
            }

            docHeader.ORG_TRX_Header = trxHeader;
            docHeader.JOB_Header     = jobHeader;

            return(docHeader);
        }
Exemplo n.º 13
0
        private void grvItems_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            //Werner: Go read the comment in the OnSaveRecord for why I do this
            ForceClose = false;

            DB.SYS_DOC_Line line = (grvItems.GetFocusedRow() as DB.SYS_DOC_Line);
            if (line == null)
            {
                return;
            }

            if (line.ItemId != 0 && line.LineItem == null)
            {
                line.LineItem = DataContext.ReadonlyContext.VW_LineItem.FirstOrDefault(n => n.Id == line.ItemId);
            }

            switch (e.Column.FieldName)
            {
            //Handeled by Repository Item
            case "ItemId":
                if (DataContext.ReadonlyContext.VW_Alternative.Any(n => n.SearchItemName == line.LineItem.Name))
                {
                    using (AlternativeDialogue dlg = new AlternativeDialogue(line.LineItem.Name))
                    {
                        if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                        {
                            line.LineItem      = DataContext.ReadonlyContext.VW_LineItem.FirstOrDefault(n => n.Id == dlg.SelectedItem.EntityId);
                            line.IgnoreChanges = true;
                            line.ItemId        = dlg.SelectedItem.EntityId.Value;
                            line.IgnoreChanges = false;
                        }
                    }
                }

                PopulateNewLine(line);
                break;

            case "Quantity":
                ValidateLineQuantity(line);
                break;
            }
            CalculateLineTotals(line);
            CalculateDocumentTotals();
            ValidateLayout();
        }
Exemplo n.º 14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="line"></param>
        /// <remarks>Created: Henko Rabie 23/01/2015</remarks>
        private void ValidateLineQuantity(DB.SYS_DOC_Line line)
        {
            switch (DocumentType)
            {
            case BL.SYS.SYS_DOC_Type.TransferRequest:
                break;

            case BL.SYS.SYS_DOC_Type.TransferShipment:
                break;

            case BL.SYS.SYS_DOC_Type.TransferReceived:
                break;

            case BL.SYS.SYS_DOC_Type.InventoryAdjustment:
                break;
            }
            CalculateLineTotals(line);
        }
Exemplo n.º 15
0
        private void RemoveItem()
        {
            if (SelectedLine == null)
            {
                return;
            }

            if (AllowRemoveItem && !SelectedLine.NewJobLine && !colItemId.OptionsColumn.ReadOnly)
            {
                JobRemoveDialogue dialogue = new JobRemoveDialogue(SelectedLine.Quantity);
                dialogue.ShowDialog();

                if (dialogue.Quantity > 0)
                {
                    if (SelectedLine.NewJobLine)
                    {
                        if (SelectedLine.Quantity == dialogue.Quantity)
                        {
                            grvItems.DeleteSelectedRows();
                        }
                        else
                        {
                            SelectedLine.Quantity = dialogue.Quantity;
                        }
                        IsSaved = false;
                    }
                    else
                    {
                        DB.SYS_DOC_Line deletedItem = BL.ApplicationDataContext.DeepClone <DB.SYS_DOC_Line>(SelectedLine, BL.SYS.SYS_DOC_Line.New);
                        deletedItem.LineItem   = DataContext.ReadonlyContext.VW_LineItem.FirstOrDefault(n => n.Id == deletedItem.ItemId);
                        deletedItem.Quantity   = -dialogue.Quantity;
                        deletedItem.NewJobLine = true;
                        deletedItem.Total      = deletedItem.Quantity * deletedItem.Amount;
                        //Using Line Order to Group in VW_JobLines
                        deletedItem.LineOrder = ((DB.SYS_DOC_Header)BindingSource.DataSource).SYS_DOC_Line.Max(m => m.LineOrder) + 1;
                        IsSaved = false;
                        lines.Add(deletedItem);
                        CalculateLineTotals(deletedItem);
                        //((DB.SYS_DOC_Header)BindingSource.DataSource).SYS_DOC_Line.Add(deletedItem);
                        grvItems.RefreshData();
                    }
                }
            }
        }
Exemplo n.º 16
0
        private void PopulateLineAmount(DB.SYS_DOC_Line line)
        {
            switch (SelectedCompany.CostCategoryId)
            {
            case (byte)BL.ORG.ORG_CostCategory.SellingPriceIncludingSalesTax:
            case (byte)BL.ORG.ORG_CostCategory.SellingPriceExcludingSalesTax:
                line.Amount = line.LineItem.UnitPrice;
                break;

            case (byte)BL.ORG.ORG_CostCategory.CostIncludingSalesTax:
            case (byte)BL.ORG.ORG_CostCategory.CostExcludingSalesTax:
                line.Amount = line.LineItem.UnitCost;
                break;

            case (byte)BL.ORG.ORG_CostCategory.AverageCostExcludingSalesTax:
                line.Amount = line.LineItem.UnitAverage;
                break;
            }
        }
Exemplo n.º 17
0
        private void PopulateNewLine(DB.SYS_DOC_Line line)
        {
            if (line == null || line.LineItem == null)
            {
                return;
            }

            //If new item is a stock item and Bar codes are enabled populate line with quantity one
            if (BL.ApplicationDataContext.Instance.CompanySite.UseBarcodes && line.LineItem.InventoryId != null)
            {
                line.Quantity = 1M;
            }

            line.Description = line.LineItem.Description;
            line.UnitAverage = line.Amount = line.LineItem.UnitAverage;

            PopulateLineOrder();

            PopulateLineAmount(line);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Populates a newly added lines fields from the parent item
        /// </summary>
        /// <param name="line">The new line that needs to be populated</param>
        /// <remarks>Created: Henko Rabie 23/01/2015</remarks>
        private void PopulateNewLine(DB.SYS_DOC_Line line)
        {
            if (line == null || line.LineItem == null)
            {
                return;
            }

            if (DocumentType == BL.SYS.SYS_DOC_Type.Quote || DocumentType == BL.SYS.SYS_DOC_Type.JobQuote)
            {
                line.Quantity = 1;
            }

            line.Description = line.LineItem.Description;
            line.UnitAverage = line.LineItem.UnitAverage;
            line.UnitCost    = line.LineItem.UnitCost;
            //Only populate LineOrder if not previously set
            // WHEN will you reach this code and the lineOrder has already be set???
            line.LineOrder = line.LineOrder == 0 ? ((List <DB.SYS_DOC_Line>)BindingSourceLine.DataSource).Count() : line.LineOrder;

            SetLineAmount(line);
        }
Exemplo n.º 19
0
        private void grvItems_CellValueChanged(object sender, DevExpress.XtraGrid.Views.Base.CellValueChangedEventArgs e)
        {
            DB.SYS_DOC_Line line = (grvItems.GetFocusedRow() as DB.SYS_DOC_Line);
            switch (e.Column.FieldName)
            {
            //Handeled by Repository Item
            case "ItemId":
                if (BL.ApplicationDataContext.Instance.CompanySite.UseBarcodes)
                {
                    line.Quantity          = 1M;
                    grvItems.FocusedColumn = colAmount;
                }
                //Populate all fields for this items line
                PopulateNewLine(line);
                break;

            case "Quantity":
                ValidateLineQuantity(line);
                break;
            }
            CalculateDocumentTotals();
            grvItems.InvalidateRowCell(e.RowHandle, colTotal);
            ValidateLayout();
        }
Exemplo n.º 20
0
        private DB.SYS_DOC_Header GenerateStockTakeDocument()
        {
            DB.SYS_DOC_Header sys_header = BL.SYS.SYS_DOC_Document.New(BL.SYS.SYS_DOC_Type.InventoryAdjustment);
            sys_header.ORG_TRX_Header = BL.ORG.ORG_TRX_Header.New;
            sys_header.ORG_TRX_Header.ReferenceLong2 = ((DB.ITM_StockTake)BindingSource.DataSource).Description;

            foreach (DB.ITM_StockTakeItem item in ((DB.ITM_StockTake)BindingSource.DataSource).ITM_StockTakeItem)
            {
                if (item.QuantityCount2 == null)
                {
                    item.QuantityCount2 = item.QuantityCount1;
                }

                //DB.VW_Inventory inventory = DataContext.ReadonlyContext.VW_Inventory.FirstOrDefault(n => n.Id == item.InventoryId);
                DB.SYS_DOC_Line line = BL.SYS.SYS_DOC_Line.New;
                line.LineItem = DataContext.ReadonlyContext.VW_LineItem.FirstOrDefault(n => n.Id == item.InventoryId);
                line.ItemId   = line.LineItem.Id;
                line.Quantity = item.QuantityCount2.Value - item.OnHand.Value;
                line.Amount   = line.LineItem.UnitAverage;
                line.Total    = line.Quantity * line.Amount;
                sys_header.SYS_DOC_Line.Add(line);
            }
            return(sys_header);
        }
Exemplo n.º 21
0
        /// <summary>
        /// Received AOR_Order object and created Purchase Order Documents
        /// </summary>
        /// <param name="order"></param>
        /// <param name="printer"></param>
        /// <returns></returns>
        public String GenerateOrder(long orderId, long createdBy, long printer)
        {
            string message = "";

            try
            {
                var order = BL.AOR.AOR_Order.Load(orderId, DataContext, new List <string>()
                {
                    "AOR_OrderLine"
                });
                BL.ApplicationDataContext.Instance.LoggedInUser = (DB.SEC_User)BL.SEC.SEC_User.LoadByPerson(createdBy, DataContext);
                BL.ApplicationDataContext.Instance.PopulateModuleAccess();
                BL.ApplicationDataContext.Instance.PopulateValidationRestrictions();
                decimal vatPercentage = BL.ApplicationDataContext.Instance.CompanySite.VatPercentage;
                List <DB.SYS_DOC_Header> purchaseOrders = new List <DB.SYS_DOC_Header>();
                foreach (var supplier in order.AOR_OrderLine.GroupBy(n => n.SupplierId).Select(n => new { EntityId = n.Key, Lines = n }))
                {
                    var supplierdetail = DataContext.ReadonlyContext.VW_Company.Where(n => n.EntityId == supplier.EntityId && n.TypeId == (byte)BL.ORG.ORG_Type.Supplier).Select(n => new { n.Id, CostCategory = n.CostCategoryId }).FirstOrDefault();

                    DB.SYS_DOC_Header header = BL.SYS.SYS_DOC_Document.New(BL.SYS.SYS_DOC_Type.PurchaseOrder);
                    header.ORG_TRX_Header                 = BL.ORG.ORG_TRX_Header.New;
                    header.ORG_TRX_Header.CompanyId       = supplierdetail.Id;
                    header.ORG_TRX_Header.ReferenceShort1 = orderId.ToString("D10");
                    System.Threading.Tasks.Parallel.ForEach(supplier.Lines, line =>
                    {
                        DB.SYS_DOC_Line docLine = BL.SYS.SYS_DOC_Line.New;
                        docLine.ItemId          = line.InventoryId;
                        docLine.LineItem        = DataContext.ReadonlyContext.VW_LineItem.FirstOrDefault(n => n.Id == docLine.ItemId);
                        docLine.Description     = line.Name;
                        docLine.Amount          = line.UnitCost.Value;
                        docLine.Quantity        = line.OrderAmount.Value;
                        docLine.Total           = line.Total.Value;
                        switch (supplierdetail.CostCategory)
                        {
                        case (byte)BL.ORG.ORG_CostCategory.SellingPriceIncludingSalesTax:
                            docLine.TotalTax = docLine.Total * vatPercentage / 100;
                            break;

                        case (byte)BL.ORG.ORG_CostCategory.SellingPriceExcludingSalesTax:
                            docLine.TotalTax = 0;
                            break;

                        case (byte)BL.ORG.ORG_CostCategory.CostIncludingSalesTax:
                            docLine.TotalTax = docLine.Total * vatPercentage / 100;
                            break;

                        case (byte)BL.ORG.ORG_CostCategory.CostExcludingSalesTax:
                            docLine.TotalTax = 0;
                            break;

                        case (byte)BL.ORG.ORG_CostCategory.AverageCostExcludingSalesTax:
                            docLine.TotalTax = 0;
                            break;
                        }
                        line.TotalTax = docLine.TotalTax;
                        lock (header.SYS_DOC_Line)
                        {
                            header.SYS_DOC_Line.Add(docLine);
                            docLine.LineOrder = header.SYS_DOC_Line.Count();
                        }
                    });
                    purchaseOrders.Add(header);
                }



                try
                {
                    purchaseOrders.ForEach(n =>
                    {
                        string result = SaveDocument(n, printer);
                        if (result.StartsWith("Exception"))
                        {
                            throw new Exception(result.Split(':')[1]);
                        }
                        else
                        {
                            message += String.Format(";{0},{1}", n.DocumentNumber, n.TrackId);
                        }
                    });

                    using (TransactionScope transaction = new TransactionScope())
                    {
                        order.OrderDate = BL.ApplicationDataContext.Instance.ServerDateTime;
                        BL.EntityController.SaveAOR_Order(order, DataContext);
                        DataContext.SaveChangesEntityOrderingContext();
                        DataContext.CompleteTransaction(transaction);
                    }
                    DataContext.EntityOrderingContext.AcceptAllChanges();
                }
                catch (Exception ex)
                {
                    DataContext.EntityOrderingContext.RejectChanges();
                    throw ex;
                }
            }
            catch (Exception ex)
            {
                return("Exception : " + ex.ToString());
            }
            return("Success" + message);
        }
Exemplo n.º 22
0
        protected bool SaveSuccessful()
        {
            if (!ValidateBeforeSave())
                return false;

            if (IBO_TRX_Header.SupplierId == null && BL.ApplicationDataContext.Instance.CompanySite.BuyoutSupplierAccount.HasValue && SYS_DOC_Header.TypeId == (byte)BL.SYS.SYS_DOC_Type.SalesOrder)
            {
                using (UnitOfWork uow = new UnitOfWork())
                {           
                    var supplier = uow.Query<XDB.ORG_Company>().Where(n => n.EntityId.HasSupplier && n.EntityId.Id == BL.ApplicationDataContext.Instance.CompanySite.BuyoutSupplierAccount.Value).Select(l => new { l.EntityId.Id, CostCategory = l.CostCategoryId.Id }).FirstOrDefault();
                    ((DB.IBO_TRX_Header)BindingSource.DataSource).SupplierId = (long)lueSupplier.EditValue; //supplier.Id;
                    CostCategory = supplier.CostCategory;
                }
            }
            using (UnitOfWork uow = new UnitOfWork())
            {
                if (IBO_TRX_Header.SupplierId != null)
                {
                    ((DB.IBO_TRX_Header)BindingSource.DataSource).Supplier = uow.Query<XDB.ORG_Company>().Where(n => n.Id == IBO_TRX_Header.SupplierId).Select(l => l.EntityId.Name).FirstOrDefault();
                }
                if (IBO_TRX_Header.CustomerId != null)
                {
                    ((DB.IBO_TRX_Header)BindingSource.DataSource).Customer= uow.Query<XDB.ORG_Company>().Where(n => n.Id == IBO_TRX_Header.CustomerId).Select(l => l.EntityId.Name).FirstOrDefault();
                }
            }

            try
            { 
                using (new CDS.Client.Desktop.Essential.UTL.WaitCursor())
                {
                    try
                    {
                        using (new CDS.Client.Desktop.Essential.UTL.WaitCursor())
                        {
                            using (TransactionScope transaction = DataContext.GetTransactionScope())
                            {
                                BL.EntityController.SaveSYS_Entity(SYS_Entity, DataContext);
                                DataContext.SaveChangesEntitySystemContext();
                                DataContext.CompleteTransaction(transaction);
                            }
                            DataContext.EntityInventoryContext.AcceptAllChanges();
                            DataContext.EntitySystemContext.AcceptAllChanges();
                        }
                    }
                    catch (Exception ex)
                    {
                        DataContext.EntityInventoryContext.RejectChanges();
                        DataContext.EntitySystemContext.RejectChanges();
                        if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex)) { throw ex; }
                        return false;
                    }
                  
                    SYS_DOC_Header_GoodsReceived = BL.SYS.SYS_DOC_Document.New(BL.SYS.SYS_DOC_Type.GoodsReceived);
                    SYS_DOC_Header_GoodsReceived.ORG_TRX_Header = BL.ORG.ORG_TRX_Header.New;
                    SYS_DOC_Header_GoodsReceived.SiteId = (long)defaultSiteId;
                    BL.ApplicationDataContext.DeepClone<DB.ORG_TRX_Header>(SYS_DOC_Header.ORG_TRX_Header, SYS_DOC_Header_GoodsReceived.ORG_TRX_Header);

                    DB.SYS_DOC_Line line = BL.SYS.SYS_DOC_Line.New;

                    ((DB.IBO_TRX_Header)BindingSource.DataSource).EntityId = SYS_Entity.Id;
                    line.LineOrder = 1;
                    line.ItemId = ((DB.IBO_TRX_Header)BindingSource.DataSource).EntityId;
                    line.Amount = ((DB.IBO_TRX_Header)BindingSource.DataSource).UnitCost;
                    line.Quantity = ((DB.IBO_TRX_Header)BindingSource.DataSource).Quantity;
                    line.ItemId = SYS_Entity.Id;
                    //line.LineItem = DataContext.ReadonlyContext.VW_LineItem.FirstOrDefault(n => n.Id == ((DB.SYS_Entity)BindingSourceEntity.DataSource).Id);
                    line.IBO_TRX_Header = ((DB.IBO_TRX_Header)BindingSource.DataSource);

                    line.Total = Math.Round(line.Amount * line.Quantity, 2, MidpointRounding.AwayFromZero);

                    //TODO: Check if item is VAT Exempt
                    switch (CostCategory)
                    {
                        case (byte)BL.ORG.ORG_CostCategory.SellingPriceIncludingSalesTax:
                            line.TotalTax = line.Total * BL.ApplicationDataContext.Instance.CompanySite.VatPercentage / 100;
                            break;
                        case (byte)BL.ORG.ORG_CostCategory.SellingPriceExcludingSalesTax:
                            line.TotalTax = 0;
                            break;
                        case (byte)BL.ORG.ORG_CostCategory.CostIncludingSalesTax:
                            line.TotalTax = line.Total * BL.ApplicationDataContext.Instance.CompanySite.VatPercentage / 100;
                            break;
                        case (byte)BL.ORG.ORG_CostCategory.CostExcludingSalesTax:
                            line.TotalTax = 0;
                            break;
                        case (byte)BL.ORG.ORG_CostCategory.AverageCostExcludingSalesTax:
                            line.TotalTax = 0;
                            break;
                    }

                    if (((DB.IBO_TRX_Header)BindingSource.DataSource).SupplierId.HasValue)
                    {
                        SYS_DOC_Header_GoodsReceived.ORG_TRX_Header.CompanyId = ((DB.IBO_TRX_Header)BindingSource.DataSource).SupplierId.Value;
                    }

                    SYS_DOC_Header_GoodsReceived.SYS_DOC_Line.Add(line);

                    if (SYS_DOC_Header.TypeId == (byte)BL.SYS.SYS_DOC_Type.SalesOrder)
                    {
                        DialogResult result = Essential.DocumentAlert.ShowAlert("Save Document", "You are about to save this document do you wish to continue ?", Essential.DocumentAlert.Buttons.SaveAndPrint);
                        if (result == System.Windows.Forms.DialogResult.Cancel)
                            return false;

                        string message = "";
                        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;
                        }
                        DataContext.SaveChangesEntitySystemContext();
                        message = BL.ApplicationDataContext.Instance.Service.SaveDocument(SYS_DOC_Header_GoodsReceived, printerId);

                        if (message.StartsWith("Success"))
                        {
                            var returns = message.Split(',');
                            //Normal Document number
                            if (returns[1] != null)
                            {
                                ShowNotification("Document Saved", String.Format("{0} number {1} was saved successfully", "Goods Received", returns[1]), 5000, false, null);
                                SYS_DOC_Header_GoodsReceived.IgnoreChanges = true;
                                SYS_DOC_Header_GoodsReceived.DocumentNumber = Convert.ToInt64(returns[1]);
                                SYS_DOC_Header_GoodsReceived.IgnoreChanges = false;
                            }

                            //Tracking number
                            if (returns[2] != null)
                            {
                                ShowNotification("Document Saved", String.Format("{0} number {1} was saved successfully", "Tracking", returns[2]), 5000, false, null);
                                SYS_DOC_Header_GoodsReceived.IgnoreChanges = true;
                                SYS_DOC_Header_GoodsReceived.TrackId = Convert.ToInt64(returns[2]);
                                SYS_DOC_Header_GoodsReceived.IgnoreChanges = false;
                            }
                            DataContext.SaveChangesEntitySystemContext();
                            return true;
                        }
                        else if (message != string.Empty)
                        {
                            return false;
                        }
                        else
                            return false;
                    }
                    else if (SYS_DOC_Header.TypeId == (byte)BL.SYS.SYS_DOC_Type.GoodsReceived)
                    {
                        return true;
                    }

                    //Document Type not supported
                    return false;
                }
            }
            catch (Exception ex)
            {
                return false;
            }
        }
Exemplo n.º 23
0
 /// <summary>
 /// Calculate a lines Total and Tax?????
 /// </summary>
 /// <param name="line">The line wich totals you wish to calculate</param>
 /// <remarks>Created: Henko Rabie 23/01/2015</remarks>
 private void CalculateLineTotals(DB.SYS_DOC_Line line)
 {
     // Accounts do not have a quantity also not allowed to change qty so always use 1 if Parent Type = 5 (Account)
     line.Total    = Math.Round(line.Amount * (line.LineItem.TypeId == (byte)BL.SYS.SYS_Type.Account ? 1 : line.Quantity), 2, MidpointRounding.AwayFromZero);
     line.TotalTax = 0.00M;
 }
Exemplo n.º 24
0
        protected override void BindData()
        {
            base.BindData();
            BindingSource.DataSource            = Doc_Header;
            BindingSourceTransaction.DataSource = Job_header;
            BindingSourceLine.DataSource        = lines;

            Doc_Header.JOB_Header = Job_header;
            lines.Clear();


            switch (ItemState)
            {
            case EntityState.Generated:
                IsSaved = false;
                btnCreateQuote.Visibility       = DevExpress.XtraBars.BarItemVisibility.Never;
                btnViewSalesOrder.Visibility    = DevExpress.XtraBars.BarItemVisibility.Never;
                btnCreateSalesOrder.ButtonStyle = DevExpress.XtraBars.BarButtonStyle.Default;
                lines.Clear();
                foreach (DB.SYS_DOC_Line docline in ((DB.SYS_DOC_Header)BindingSource.DataSource).SYS_DOC_Line)
                {
                    docline.NewJobLine = true;
                    lines.Add(docline);
                    CalculateUnboundColumns(docline);
                    CalculateLineTotals(docline);
                }
                BindingSourceLine.DataSource   = lines;
                ddlCompany.Properties.ReadOnly = true;

                colItemId.OptionsColumn.AllowFocus      = false;
                colDescription.OptionsColumn.AllowFocus = false;
                break;

            case EntityState.Open:

                foreach (DB.VW_JobLine jobLine in DataContext.ReadonlyContext.VW_JobLine.Where(n => n.HeaderId == ((DB.SYS_DOC_Header)BindingSource.DataSource).Id).OrderBy(o => o.LineOrder))
                {
                    DB.SYS_DOC_Line line = BL.SYS.SYS_DOC_Line.New;
                    line.LineItem           = DataContext.ReadonlyContext.VW_LineItem.FirstOrDefault(n => n.Id == jobLine.ItemId);
                    line.ParentLineId       = jobLine.Id.Value;
                    line.HeaderId           = jobLine.HeaderId;
                    line.ItemId             = jobLine.ItemId;
                    line.DiscountPercentage = jobLine.DiscountPercentage;
                    line.Description        = jobLine.Description;
                    line.Quantity           = jobLine.Quantity.Value;
                    line.Amount             = jobLine.Amount;
                    line.Total     = jobLine.Total.Value;
                    line.TotalTax  = jobLine.TotalTax.Value;
                    line.CreatedOn = jobLine.CreatedOn;
                    line.CreatedBy = jobLine.CreatedBy;
                    if ((new byte[] { (byte)BL.SYS.SYS_Type.Inventory, (byte)BL.SYS.SYS_Type.BuyOut }).Contains(line.LineItem.TypeId))
                    {
                        line.UnitAverage = BL.ITM.ITM_Movement.LoadByLineId(jobLine.Id.Value, DataContext).UnitAverage.Value;
                    }
                    line.LineOrder = jobLine.LineOrder;
                    lines.Add(line);
                    CalculateUnboundColumns(line);
                    CalculateLineTotals(line);
                }
                readOnlyLineCount = Doc_Header.SYS_DOC_Line.Count();
                break;
            }
        }
Exemplo n.º 25
0
        public static void GetSellPrice(DB.SYS_DOC_Line line, DB.VW_Company entity, decimal amount, bool useWarehouseDiscount, out decimal sellPrice, out decimal discountPrice, out decimal discountPercentage, DataContext dataContext)
        {
            if (line == null || line.LineItem == null || (line.LineItem as DB.VW_LineItem).InventoryId == null)
            {
                sellPrice          = line.Amount;
                discountPrice      = line.Amount;
                discountPercentage = 0M;
                return;
            }

            sellPrice          = line.Amount;
            discountPrice      = 0M;
            discountPercentage = 0M;
            if ((entity == null))
            {
                // NO entity SELECTED
                //sellPrice = inventoryItem.UnitPrice;
                return;
            }

            DB.VW_LineItem inventory = line.LineItem as DB.VW_LineItem;
            var            discounts = dataContext.ReadonlyContext.VW_Discount.Where(n => (n.CompanyDiscountCode == entity.DiscountCode || n.EntityId == entity.OrgEntityId) && (n.InventoryDiscountCode == inventory.DiscountCode || n.InventoryId == inventory.InventoryId)).ToList();


            //If any of the discounts are fixed price discounts
            if (discounts.Any(n => n.DiscountAmountTypeId == (byte)BL.ITM.ITM_DIS_AmountType.FixedPriceDiscount))
            {
                if (!useWarehouseDiscount)
                {
                    sellPrice = discounts.Min(n => n.CompanyDiscount).Value;
                }
                else
                {
                    sellPrice = discounts.Min(n => n.WorkshopDiscount).Value;
                }
                discountPrice      = sellPrice;
                discountPercentage = 0;
                return;
            }
            else
            {
                //Henko: I am pretty sure if anything this should be MIN not MAX? But either way this is really badly done...
                if (!useWarehouseDiscount)
                {
                    discountPercentage = discounts.Count() > 0 ? discounts.Max(n => n.CompanyDiscount).Value : 0;
                }
                else
                {
                    discountPercentage = discounts.Count() > 0 ? discounts.Max(n => n.WorkshopDiscount).Value : 0;
                }
            }

            if ((entity.CostCategoryId == (byte)BL.ORG.ORG_CostCategory.CostExcludingSalesTax) || (entity.CostCategoryId == (byte)BL.ORG.ORG_CostCategory.CostIncludingSalesTax))
            {
                // COST INCLUDING or COST EXCLUDING
                if (discountPercentage < 0)
                {
                    discountPrice = inventory.UnitCost - (inventory.UnitCost * discountPercentage / 100);
                    sellPrice     = inventory.UnitCost;
                }
                else
                {
                    discountPrice = (inventory.UnitCost * (100 - discountPercentage)) / 100;
                    sellPrice     = inventory.UnitCost;
                }
                //sellPrice = line.UnitCost;
                return;
            }
            else if (entity.CostCategoryId == (byte)BL.ORG.ORG_CostCategory.AverageCostExcludingSalesTax)
            {
                // AVG COST EXCLUDING
                if (discountPercentage < 0)
                {
                    discountPrice = inventory.UnitAverage - (line.UnitAverage * discountPercentage / 100);
                    sellPrice     = inventory.UnitAverage;
                }
                else
                {
                    discountPrice = (inventory.UnitAverage * (100 - discountPercentage)) / 100;
                    sellPrice     = inventory.UnitAverage;
                }
                //sellPrice = line.UnitAverage;
                return;
            }
            else if ((entity.CostCategoryId == (byte)BL.ORG.ORG_CostCategory.SellingPriceExcludingSalesTax) || (entity.CostCategoryId == (byte)BL.ORG.ORG_CostCategory.SellingPriceIncludingSalesTax))
            {
                // SELLING PRICE INCLUDING or SELLING PRICE EXCLUDING
                if (discountPercentage < 0)
                {
                    discountPrice = inventory.UnitPrice - (inventory.UnitPrice * discountPercentage / 100);
                    sellPrice     = inventory.UnitPrice;
                }
                else
                {
                    discountPrice = (inventory.UnitPrice * (100 - discountPercentage)) / 100;
                    sellPrice     = inventory.UnitPrice;
                }
                //sellPrice = line.UnitAverage;
                return;
            }
        }
Exemplo n.º 26
0
 private void CalculateLineTotals(DB.SYS_DOC_Line line)
 {
     line.Amount = Math.Round(line.Amount, 2, MidpointRounding.AwayFromZero);
     line.Total  = Math.Round((line.Amount * line.Quantity), 2, MidpointRounding.AwayFromZero);
 }
Exemplo n.º 27
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);
        }
Exemplo n.º 28
0
 /// <summary>
 /// Sets the lines amount value
 /// </summary>
 /// <param name="line">The current line that needs to be populated</param>
 /// <remarks>Created: Henko Rabie 23/01/2015</remarks>
 private void SetLineAmount(DB.SYS_DOC_Line line)
 {
     line.Amount = line.LineItem.UnitAverage;
     CalculateLineTotals(line);
 }
Exemplo n.º 29
0
 private void CalculateUnboundColumns(DB.SYS_DOC_Line line)
 {
     //line.ProfitPercentage = (line.Amount > 0) ? (line.Amount - line.UnitAverage) / line.Amount : 0M;
 }