Ejemplo n.º 1
0
        public ProductCostResult LoadProductCostsInTableRowsByOfferId(int idOffer, CallContext resultContext)
        {
            ProductCostResult productCostResult = new ProductCostResult();

            TableRow[] arrProductCosts = new TableRow[0];

            try
            {
                productCostResult.ResultContext = resultContext;
                productCostResult.ResultContext.ResultCode = ETEMEnums.ResultEnum.Success;

                List<ProductCostDataView> listProductCosts = new List<ProductCostDataView>();

                List<ProductCostDataView> listProductCostsExtrusion = new List<ProductCostDataView>();
                List<ProductCostDataView> listProductCostsPackaging = new List<ProductCostDataView>();
                List<ProductCostDataView> listProductCostsTransportationCostAndCommission = new List<ProductCostDataView>();
                List<ProductCostDataView> listProductCostsSGAsAndFinancials = new List<ProductCostDataView>();
                List<ProductCostDataView> listProductCostsTotalProductCost = new List<ProductCostDataView>();

                ProductCostResult productCost = this.LoadProductCostsByOfferId(idOffer, resultContext);

                listProductCosts = productCost.ListProductCosts;

                listProductCostsExtrusion = listProductCosts.Where(w => w.ProductCostType == "Extrusion").ToList();
                listProductCostsPackaging = listProductCosts.Where(w => w.ProductCostType == "Packaging").ToList();
                listProductCostsTransportationCostAndCommission = listProductCosts.Where(w => w.ProductCostType == "TransportationCostAndCommission").ToList();
                listProductCostsSGAsAndFinancials = listProductCosts.Where(w => w.ProductCostType == "SGAsAndFinancials").ToList();
                listProductCostsTotalProductCost = listProductCosts.Where(w => w.ProductCostType == "TotalProductCost").ToList();

                List<string> listColumns = new List<string>()
                {
                    "EUR/ton",
                    "EUR/kg",
                    "EUR/PC"
                };

                int countRows = 2 + listProductCostsExtrusion.Count +
                                3 + listProductCostsPackaging.Count +
                                3 + listProductCostsTransportationCostAndCommission.Count +
                                3 + listProductCostsSGAsAndFinancials.Count +
                                3 + listProductCostsTotalProductCost.Count;

                arrProductCosts = new TableRow[countRows];

                TableRow tableRow = new TableRow();
                TableCell tableCell = new TableCell();
                TableHeaderRow tableHeaderRow = new TableHeaderRow();
                TableHeaderCell tableHeaderCell = new TableHeaderCell();

                int rowIndex = 0;

                #region Extrusion

                tableHeaderRow = new TableHeaderRow();
                tableHeaderCell = new TableHeaderCell();

                tableHeaderCell.Text = "Extrusion";
                tableHeaderCell.ColumnSpan = 4;
                tableHeaderCell.CssClass = "GridExpenses_tr_th_Main";
                tableHeaderRow.Cells.Add(tableHeaderCell);

                arrProductCosts[rowIndex++] = tableHeaderRow;

                tableHeaderRow = new TableHeaderRow();
                tableHeaderCell = new TableHeaderCell();

                tableHeaderCell.Text = "";
                tableHeaderCell.Width = Unit.Pixel(600);
                tableHeaderCell.CssClass = "GridExpenses_td_item_center";
                tableHeaderRow.Cells.Add(tableHeaderCell);

                arrProductCosts[rowIndex] = tableHeaderRow;

                // Add header columns
                foreach (string columnName in listColumns)
                {
                    tableHeaderCell = new TableHeaderCell();

                    tableHeaderCell.Text = columnName;
                    tableHeaderCell.CssClass = "GridExpenses_td_item_center";
                    arrProductCosts[rowIndex].Cells.Add(tableHeaderCell);
                }
                rowIndex++;
                // Add header rows
                foreach (ProductCostDataView prodCostExtrusion in listProductCostsExtrusion)
                {
                    tableRow = new TableRow();
                    tableCell = new TableCell();

                    tableCell.Text = prodCostExtrusion.Name.Replace(" group", "");
                    if (prodCostExtrusion.RowType == "Total")
                    {
                        tableCell.CssClass = "GridExpenses_td_item_total";
                    }
                    tableRow.Cells.Add(tableCell);

                    tableCell = new TableCell();
                    tableCell.Text = prodCostExtrusion.Value_EUR_ton_Formatted;
                    tableCell.HorizontalAlign = HorizontalAlign.Right;
                    tableCell.CssClass = "GridExpenses_td_item_right";
                    if (prodCostExtrusion.RowType == "Total")
                    {
                        tableCell.CssClass += " GridExpenses_td_item_total";
                    }                    
                    tableRow.Cells.Add(tableCell);

                    tableCell = new TableCell();
                    tableCell.Text = prodCostExtrusion.Value_EUR_kg_Formatted;
                    tableCell.HorizontalAlign = HorizontalAlign.Right;
                    tableCell.CssClass = "GridExpenses_td_item_right";
                    if (prodCostExtrusion.RowType == "Total")
                    {
                        tableCell.CssClass += " GridExpenses_td_item_total";
                    }
                    tableRow.Cells.Add(tableCell);

                    tableCell = new TableCell();
                    tableCell.Text = prodCostExtrusion.Value_EUR_PC_Formatted;
                    tableCell.HorizontalAlign = HorizontalAlign.Right;
                    tableCell.CssClass = "GridExpenses_td_item_right";
                    if (prodCostExtrusion.RowType == "Total")
                    {
                        tableCell.CssClass += " GridExpenses_td_item_total";
                    }
                    tableRow.Cells.Add(tableCell);

                    arrProductCosts[rowIndex++] = tableRow;
                }

                #endregion

                #region Packaging

                tableHeaderRow = new TableHeaderRow();
                tableHeaderCell = new TableHeaderCell();
                tableHeaderCell.ColumnSpan = 4;
                tableHeaderCell.CssClass = "GridExpenses_tr_th_Empty";
                tableHeaderRow.Cells.Add(tableHeaderCell);

                arrProductCosts[rowIndex++] = tableHeaderRow;

                tableHeaderRow = new TableHeaderRow();
                tableHeaderCell = new TableHeaderCell();

                tableHeaderCell.Text = "Packaging";
                tableHeaderCell.ColumnSpan = 4;
                tableHeaderCell.CssClass = "GridExpenses_tr_th_Main";
                tableHeaderRow.Cells.Add(tableHeaderCell);

                arrProductCosts[rowIndex++] = tableHeaderRow;

                tableHeaderRow = new TableHeaderRow();
                tableHeaderCell = new TableHeaderCell();

                tableHeaderCell.Text = "";
                tableHeaderCell.Width = Unit.Pixel(600);
                tableHeaderCell.CssClass = "GridExpenses_td_item_center";
                tableHeaderRow.Cells.Add(tableHeaderCell);

                arrProductCosts[rowIndex] = tableHeaderRow;

                // Add header columns
                foreach (string columnName in listColumns)
                {
                    tableHeaderCell = new TableHeaderCell();

                    tableHeaderCell.Text = columnName;
                    tableHeaderCell.CssClass = "GridExpenses_td_item_center";
                    arrProductCosts[rowIndex].Cells.Add(tableHeaderCell);
                }
                rowIndex++;
                // Add header rows
                foreach (ProductCostDataView prodCostPackaging in listProductCostsPackaging)
                {
                    tableRow = new TableRow();
                    tableCell = new TableCell();

                    tableCell.Text = prodCostPackaging.Name.Replace(" group", "");
                    if (prodCostPackaging.RowType == "Total")
                    {
                        tableCell.CssClass = "GridExpenses_td_item_total";
                    }
                    tableRow.Cells.Add(tableCell);

                    tableCell = new TableCell();
                    tableCell.Text = prodCostPackaging.Value_EUR_ton_Formatted;
                    tableCell.HorizontalAlign = HorizontalAlign.Right;
                    tableCell.CssClass = "GridExpenses_td_item_right";
                    if (prodCostPackaging.RowType == "Total")
                    {
                        tableCell.CssClass += " GridExpenses_td_item_total";
                    }
                    tableRow.Cells.Add(tableCell);

                    tableCell = new TableCell();
                    tableCell.Text = prodCostPackaging.Value_EUR_kg_Formatted;
                    tableCell.HorizontalAlign = HorizontalAlign.Right;
                    tableCell.CssClass = "GridExpenses_td_item_right";
                    if (prodCostPackaging.RowType == "Total")
                    {
                        tableCell.CssClass += " GridExpenses_td_item_total";
                    }
                    tableRow.Cells.Add(tableCell);

                    tableCell = new TableCell();
                    tableCell.Text = prodCostPackaging.Value_EUR_PC_Formatted;
                    tableCell.HorizontalAlign = HorizontalAlign.Right;
                    tableCell.CssClass = "GridExpenses_td_item_right";
                    if (prodCostPackaging.RowType == "Total")
                    {
                        tableCell.CssClass += " GridExpenses_td_item_total";
                    }
                    tableRow.Cells.Add(tableCell);

                    arrProductCosts[rowIndex++] = tableRow;
                }

                #endregion

                #region Transportation Cost & Commission

                tableHeaderRow = new TableHeaderRow();
                tableHeaderCell = new TableHeaderCell();
                tableHeaderCell.ColumnSpan = 4;
                tableHeaderCell.CssClass = "GridExpenses_tr_th_Empty";
                tableHeaderRow.Cells.Add(tableHeaderCell);

                arrProductCosts[rowIndex++] = tableHeaderRow;

                tableHeaderRow = new TableHeaderRow();
                tableHeaderCell = new TableHeaderCell();

                tableHeaderCell.Text = "Transportation Cost & Commission";
                tableHeaderCell.ColumnSpan = 4;
                tableHeaderCell.CssClass = "GridExpenses_tr_th_Main";
                tableHeaderRow.Cells.Add(tableHeaderCell);

                arrProductCosts[rowIndex++] = tableHeaderRow;

                tableHeaderRow = new TableHeaderRow();
                tableHeaderCell = new TableHeaderCell();

                tableHeaderCell.Text = "";
                tableHeaderCell.Width = Unit.Pixel(600);
                tableHeaderCell.CssClass = "GridExpenses_td_item_center";
                tableHeaderRow.Cells.Add(tableHeaderCell);

                arrProductCosts[rowIndex] = tableHeaderRow;

                // Add header columns
                foreach (string columnName in listColumns)
                {
                    tableHeaderCell = new TableHeaderCell();

                    tableHeaderCell.Text = columnName;
                    tableHeaderCell.CssClass = "GridExpenses_td_item_center";
                    arrProductCosts[rowIndex].Cells.Add(tableHeaderCell);
                }
                rowIndex++;
                // Add header rows
                foreach (ProductCostDataView prodCostTransportationCostAndCommission in listProductCostsTransportationCostAndCommission)
                {
                    tableRow = new TableRow();
                    tableCell = new TableCell();

                    tableCell.Text = prodCostTransportationCostAndCommission.Name.Replace(" group", "");
                    if (prodCostTransportationCostAndCommission.RowType == "Total")
                    {
                        tableCell.CssClass = "GridExpenses_td_item_total";
                    }
                    tableRow.Cells.Add(tableCell);

                    tableCell = new TableCell();
                    tableCell.Text = prodCostTransportationCostAndCommission.Value_EUR_ton_Formatted;
                    tableCell.HorizontalAlign = HorizontalAlign.Right;
                    tableCell.CssClass = "GridExpenses_td_item_right";
                    if (prodCostTransportationCostAndCommission.RowType == "Total")
                    {
                        tableCell.CssClass += " GridExpenses_td_item_total";
                    }
                    tableRow.Cells.Add(tableCell);

                    tableCell = new TableCell();
                    tableCell.Text = prodCostTransportationCostAndCommission.Value_EUR_kg_Formatted;
                    tableCell.HorizontalAlign = HorizontalAlign.Right;
                    tableCell.CssClass = "GridExpenses_td_item_right";
                    if (prodCostTransportationCostAndCommission.RowType == "Total")
                    {
                        tableCell.CssClass += " GridExpenses_td_item_total";
                    }
                    tableRow.Cells.Add(tableCell);

                    tableCell = new TableCell();
                    tableCell.Text = prodCostTransportationCostAndCommission.Value_EUR_PC_Formatted;
                    tableCell.HorizontalAlign = HorizontalAlign.Right;
                    tableCell.CssClass = "GridExpenses_td_item_right";
                    if (prodCostTransportationCostAndCommission.RowType == "Total")
                    {
                        tableCell.CssClass += " GridExpenses_td_item_total";
                    }
                    tableRow.Cells.Add(tableCell);

                    arrProductCosts[rowIndex++] = tableRow;
                }

                #endregion

                #region SGA's and Financials

                tableHeaderRow = new TableHeaderRow();
                tableHeaderCell = new TableHeaderCell();
                tableHeaderCell.ColumnSpan = 4;
                tableHeaderCell.CssClass = "GridExpenses_tr_th_Empty";
                tableHeaderRow.Cells.Add(tableHeaderCell);

                arrProductCosts[rowIndex++] = tableHeaderRow;

                tableHeaderRow = new TableHeaderRow();
                tableHeaderCell = new TableHeaderCell();

                tableHeaderCell.Text = "SGA's and Financials";
                tableHeaderCell.ColumnSpan = 4;
                tableHeaderCell.CssClass = "GridExpenses_tr_th_Main";
                tableHeaderRow.Cells.Add(tableHeaderCell);

                arrProductCosts[rowIndex++] = tableHeaderRow;

                tableHeaderRow = new TableHeaderRow();
                tableHeaderCell = new TableHeaderCell();

                tableHeaderCell.Text = "";
                tableHeaderCell.Width = Unit.Pixel(600);
                tableHeaderCell.CssClass = "GridExpenses_td_item_center";
                tableHeaderRow.Cells.Add(tableHeaderCell);

                arrProductCosts[rowIndex] = tableHeaderRow;

                // Add header columns
                foreach (string columnName in listColumns)
                {
                    tableHeaderCell = new TableHeaderCell();

                    tableHeaderCell.Text = columnName;
                    tableHeaderCell.CssClass = "GridExpenses_td_item_center";
                    arrProductCosts[rowIndex].Cells.Add(tableHeaderCell);
                }
                rowIndex++;
                // Add header rows
                foreach (ProductCostDataView prodCostSGAsAndFinancials in listProductCostsSGAsAndFinancials)
                {
                    tableRow = new TableRow();
                    tableCell = new TableCell();

                    tableCell.Text = prodCostSGAsAndFinancials.Name.Replace(" group", "");
                    if (prodCostSGAsAndFinancials.RowType == "Total")
                    {
                        tableCell.CssClass = "GridExpenses_td_item_total";
                    }
                    tableRow.Cells.Add(tableCell);

                    tableCell = new TableCell();
                    tableCell.Text = prodCostSGAsAndFinancials.Value_EUR_ton_Formatted;
                    tableCell.HorizontalAlign = HorizontalAlign.Right;
                    tableCell.CssClass = "GridExpenses_td_item_right";
                    if (prodCostSGAsAndFinancials.RowType == "Total")
                    {
                        tableCell.CssClass += " GridExpenses_td_item_total";
                    }
                    tableRow.Cells.Add(tableCell);

                    tableCell = new TableCell();
                    tableCell.Text = prodCostSGAsAndFinancials.Value_EUR_kg_Formatted;
                    tableCell.HorizontalAlign = HorizontalAlign.Right;
                    tableCell.CssClass = "GridExpenses_td_item_right";
                    if (prodCostSGAsAndFinancials.RowType == "Total")
                    {
                        tableCell.CssClass += " GridExpenses_td_item_total";
                    }
                    tableRow.Cells.Add(tableCell);

                    tableCell = new TableCell();
                    tableCell.Text = prodCostSGAsAndFinancials.Value_EUR_PC_Formatted;
                    tableCell.HorizontalAlign = HorizontalAlign.Right;
                    tableCell.CssClass = "GridExpenses_td_item_right";                    
                    if (prodCostSGAsAndFinancials.RowType == "Total")
                    {
                        tableCell.CssClass += " GridExpenses_td_item_total";
                    }
                    tableRow.Cells.Add(tableCell);

                    arrProductCosts[rowIndex++] = tableRow;
                }

                #endregion

                #region TOTAL PRODUCT COST

                tableHeaderRow = new TableHeaderRow();
                tableHeaderCell = new TableHeaderCell();
                tableHeaderCell.ColumnSpan = 4;
                tableHeaderCell.CssClass = "GridExpenses_tr_th_Empty";
                tableHeaderRow.Cells.Add(tableHeaderCell);

                arrProductCosts[rowIndex++] = tableHeaderRow;

                tableHeaderRow = new TableHeaderRow();
                tableHeaderCell = new TableHeaderCell();

                tableHeaderCell.Text = "TOTAL PRODUCT COST";
                tableHeaderCell.ColumnSpan = 4;
                tableHeaderCell.CssClass = "GridExpenses_tr_th_Main";
                tableHeaderRow.Cells.Add(tableHeaderCell);

                arrProductCosts[rowIndex++] = tableHeaderRow;

                tableHeaderRow = new TableHeaderRow();
                tableHeaderCell = new TableHeaderCell();

                tableHeaderCell.Text = "";
                tableHeaderCell.Width = Unit.Pixel(600);
                tableHeaderCell.CssClass = "GridExpenses_td_item_center";
                tableHeaderRow.Cells.Add(tableHeaderCell);

                arrProductCosts[rowIndex] = tableHeaderRow;

                // Add header columns
                foreach (string columnName in listColumns)
                {
                    tableHeaderCell = new TableHeaderCell();

                    tableHeaderCell.Text = columnName;
                    tableHeaderCell.CssClass = "GridExpenses_td_item_center";
                    arrProductCosts[rowIndex].Cells.Add(tableHeaderCell);
                }
                rowIndex++;
                // Add header rows
                foreach (ProductCostDataView prodCostTotalProductCost in listProductCostsTotalProductCost)
                {
                    tableRow = new TableRow();
                    tableCell = new TableCell();

                    tableCell.Text = prodCostTotalProductCost.Name.Replace(" group", "");
                    if (prodCostTotalProductCost.RowType == "Total")
                    {
                        tableCell.CssClass = "GridExpenses_td_item_total GridExpenses_td_background_yellow";
                    }
                    tableRow.Cells.Add(tableCell);

                    tableCell = new TableCell();
                    tableCell.ToolTip = prodCostTotalProductCost.Value_EUR_ton.ToString();
                    tableCell.Text = prodCostTotalProductCost.Value_EUR_ton_Formatted;
                    tableCell.HorizontalAlign = HorizontalAlign.Right;
                    tableCell.CssClass = "GridExpenses_td_item_right";
                    if (prodCostTotalProductCost.RowType == "Total")
                    {
                        tableCell.CssClass += " GridExpenses_td_item_total GridExpenses_td_background_yellow";
                    }
                    tableRow.Cells.Add(tableCell);

                    tableCell = new TableCell();
                    tableCell.ToolTip = prodCostTotalProductCost.Value_EUR_kg.ToString();
                    tableCell.Text = prodCostTotalProductCost.Value_EUR_kg_Formatted;
                    tableCell.HorizontalAlign = HorizontalAlign.Right;
                    tableCell.CssClass = "GridExpenses_td_item_right";
                    if (prodCostTotalProductCost.RowType == "Total")
                    {
                        tableCell.CssClass += " GridExpenses_td_item_total GridExpenses_td_background_yellow";
                    }
                    tableRow.Cells.Add(tableCell);

                    tableCell = new TableCell();
                    tableCell.Text = prodCostTotalProductCost.Value_EUR_PC_Formatted;
                    tableCell.ToolTip = prodCostTotalProductCost.Value_EUR_PC.ToString();
                    tableCell.HorizontalAlign = HorizontalAlign.Right;
                    tableCell.CssClass = "GridExpenses_td_item_right";
                    if (prodCostTotalProductCost.RowType == "Total")
                    {
                        tableCell.CssClass += " GridExpenses_td_item_total GridExpenses_td_background_yellow";
                    }
                    tableRow.Cells.Add(tableCell);

                    arrProductCosts[rowIndex++] = tableRow;
                }

                #endregion

                productCostResult.TableRowsProductCosts = arrProductCosts;
            }
            catch (Exception ex)
            {
                productCostResult.ResultContext.ResultCode = ETEMEnums.ResultEnum.Error;
                productCostResult.ResultContext.Message = "Error load product costs by offer!";

                BaseHelper.Log("Error load product costs in table rows by offer!");
                BaseHelper.Log(ex.Message);
                BaseHelper.Log(ex.StackTrace);
            }

            return productCostResult;
        }
Ejemplo n.º 2
0
        public ProductCostResult LoadProductCostResult()
        {
            productCostResult = new ProductCostBL().LoadProductCostsByOfferId(idOffer, new CallContext());

            return productCostResult;
        }
Ejemplo n.º 3
0
        public ProductCostResult LoadProductCostsByOfferId(int idOffer, CallContext resultContext)
        {
            ProductCostResult productCostResult = new ProductCostResult();

            List<ProductCostDataView> listProductCosts = new List<ProductCostDataView>();

            try
            {
                productCostResult.ResultContext = resultContext;
                productCostResult.ResultContext.ResultCode = ETEMEnums.ResultEnum.Success;

                List<string> listKeyTypeIntCodes = new List<string>()
                {
                    ETEMEnums.KeyTypeEnum.CostCenter.ToString(),
                    ETEMEnums.KeyTypeEnum.ExpensesTypeGroup.ToString()
                };

                List<KeyValueDataView> listKeyValuesToSAPDataCostCenterAndExpensesTypeGroup = new List<KeyValueDataView>();
                List<KeyValueDataView> listKeyValueCostCenter = new List<KeyValueDataView>();
                List<KeyValueDataView> listKeyValueCostCenterWithoutPackaging = new List<KeyValueDataView>();
                List<KeyValueDataView> listKeyValueCostCenterWithPackaging = new List<KeyValueDataView>();
                List<KeyValueDataView> listKeyValueExpensesTypeGroup = new List<KeyValueDataView>();

                listKeyValuesToSAPDataCostCenterAndExpensesTypeGroup = (from kv in this.dbContext.KeyValues
                                                                        join kt in this.dbContext.KeyTypes on kv.idKeyType equals kt.idKeyType
                                                                        where listKeyTypeIntCodes.Contains(kt.KeyTypeIntCode)
                                                                        orderby kv.V_Order ascending
                                                                        select new KeyValueDataView
                                                                            {
                                                                                idKeyValue = kv.idKeyValue,
                                                                                Name = kv.Name,
                                                                                NameEN = kv.NameEN,
                                                                                DefaultValue1 = kv.DefaultValue1,
                                                                                KeyValueIntCode = kv.KeyValueIntCode,
                                                                                KeyTypeIntCode = kt.KeyTypeIntCode
                                                                            }
                                                                        ).ToList<KeyValueDataView>();

                Offer offer = new OfferBL().GetEntityById(idOffer);
                List<OfferDataExpenseGroupView> listGroupExpense = new OfferDataExpenseGroupBL().GetAllOfferDataExpenseGroupByOffer(idOffer);
                OfferProducitivity offerProducitivity = new OfferProducitivityBL().GetOfferProducitivityByOfferID(idOffer);

                List<int> listCostCenterIDs = listGroupExpense.DistinctBy(k => k.idCostCenter).Select(k => k.idCostCenter).ToList();

                listKeyValueCostCenter = listKeyValuesToSAPDataCostCenterAndExpensesTypeGroup.Where(w => listCostCenterIDs.Contains(w.idKeyValue)).ToList();

                listKeyValueCostCenterWithoutPackaging = listKeyValueCostCenter.Where(w => w.KeyValueIntCode != ETEMEnums.CostCenterEnum.Packaging.ToString()).ToList();
                listKeyValueCostCenterWithPackaging = listKeyValueCostCenter.Where(w => w.KeyValueIntCode == ETEMEnums.CostCenterEnum.Packaging.ToString()).ToList();

                listKeyValueExpensesTypeGroup = listKeyValuesToSAPDataCostCenterAndExpensesTypeGroup.Where(w => w.KeyTypeIntCode == ETEMEnums.KeyTypeEnum.ExpensesTypeGroup.ToString()).ToList();

                decimal weightPerPC = offer.WeightPerPC.HasValue ? offer.WeightPerPC.Value : decimal.Zero;

                decimal currValue = decimal.Zero;

                ProductCostDataView productCostDataView = new ProductCostDataView();

                #region Extrusion

                decimal totalExtrusion = decimal.Zero;

                decimal totalExtrusionCost_ton = decimal.Zero;
                decimal totalExtrusionConversionCost_ton = decimal.Zero;
                decimal totalExtrusionConversionCostWithoutDepreciation_ton = decimal.Zero;
                decimal totalVariableExpenses_ton = decimal.Zero;
                decimal totalFixedExpenses_ton = decimal.Zero;
                decimal totalDepreciations_ton = decimal.Zero;

                decimal totalExtrusionCost_kg = decimal.Zero;
                decimal totalExtrusionConversionCost_kg = decimal.Zero;
                decimal totalExtrusionConversionCostWithoutDepreciation_kg = decimal.Zero;
                decimal totalVariableExpenses_kg = decimal.Zero;
                decimal totalFixedExpenses_kg = decimal.Zero;
                decimal totalDepreciations_kg = decimal.Zero;

                decimal totalExtrusionCost_PC = decimal.Zero;
                decimal totalExtrusionConversionCost_PC = decimal.Zero;
                decimal totalExtrusionConversionCostWithoutDepreciation_PC = decimal.Zero;
                decimal totalVariableExpenses_PC = decimal.Zero;
                decimal totalFixedExpenses_PC = decimal.Zero;
                decimal totalDepreciations_PC = decimal.Zero;

                ProductCostDataView productCostDieHandlingCostDataView = new ProductCostDataView();

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "Extrusion";
                productCostDataView.RowType = "Data";
                productCostDataView.Name = "LME";
                productCostDataView.RowKeyIntCode = "LME";
                productCostDataView.Value_EUR_ton = offer.LME;
                productCostDataView.Value_EUR_kg = (productCostDataView.Value_EUR_ton.HasValue ? productCostDataView.Value_EUR_ton.Value / 1000 : decimal.Zero);
                productCostDataView.Value_EUR_PC = (productCostDataView.Value_EUR_kg.HasValue ? productCostDataView.Value_EUR_kg.Value * weightPerPC : decimal.Zero);

                listProductCosts.Add(productCostDataView);

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "Extrusion";
                productCostDataView.RowType = "Data";
                productCostDataView.Name = "PREMIUM";
                productCostDataView.RowKeyIntCode = "PREMIUM";
                productCostDataView.Value_EUR_ton = offer.PREMIUM;
                productCostDataView.Value_EUR_kg = (productCostDataView.Value_EUR_ton.HasValue ? productCostDataView.Value_EUR_ton.Value / 1000 : decimal.Zero);
                productCostDataView.Value_EUR_PC = (productCostDataView.Value_EUR_kg.HasValue ? productCostDataView.Value_EUR_kg.Value * weightPerPC : decimal.Zero);

                listProductCosts.Add(productCostDataView);

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "Extrusion";
                productCostDataView.RowType = "Data";
                productCostDataView.Name = "Cost of Billet Scrap";
                productCostDataView.RowKeyIntCode = "Cost_Of_Billet_Scrap";
                productCostDataView.Value_EUR_ton = offer.CostOfScrap;
                productCostDataView.Value_EUR_kg = (productCostDataView.Value_EUR_ton.HasValue ? productCostDataView.Value_EUR_ton.Value / 1000 : decimal.Zero);
                productCostDataView.Value_EUR_PC = (productCostDataView.Value_EUR_kg.HasValue ? productCostDataView.Value_EUR_kg.Value * weightPerPC : decimal.Zero);

                listProductCosts.Add(productCostDataView);

                foreach (KeyValueDataView kvExpensesTypeGroup in listKeyValueExpensesTypeGroup)
                {
                    totalExtrusion = decimal.Zero;

                    foreach (KeyValueDataView kvCostCenter in listKeyValueCostCenterWithoutPackaging)
                    {
                        var currGroupExpense = listGroupExpense.Where(w => w.idExpensesType == kvExpensesTypeGroup.idKeyValue &&
                                                                      w.idCostCenter == kvCostCenter.idKeyValue).FirstOrDefault();

                        if (currGroupExpense != null)
                        {
                            currValue = Convert.ToDecimal(currGroupExpense.ValueData);

                            #region Calculate EUR per TON
                            if (kvCostCenter.DefaultValue1 == "Press")
                            {
                                if (offerProducitivity != null && offerProducitivity.PressProducitivity_TON_MH != decimal.Zero)
                                {
                                    totalExtrusion += currValue / offerProducitivity.PressProducitivity_TON_MH;
                                }
                                else
                                {
                                    totalExtrusion += currValue;
                                }
                            }
                            else if (kvCostCenter.DefaultValue1 == "COMETAL")
                            {
                                if (offerProducitivity != null && offerProducitivity.COMetalProducitivity_TON_MH != decimal.Zero)
                                {
                                    totalExtrusion += currValue / offerProducitivity.COMetalProducitivity_TON_MH;
                                }
                                else
                                {
                                    totalExtrusion += currValue;
                                }
                            }
                            else if (kvCostCenter.DefaultValue1 == "QualityControl")
                            {
                                if (offerProducitivity != null && offerProducitivity.QCProducitivity_TON_MH != decimal.Zero)
                                {
                                    totalExtrusion += currValue / offerProducitivity.QCProducitivity_TON_MH;
                                }
                                else
                                {
                                    totalExtrusion += currValue;
                                }
                            }
                            else if (kvCostCenter.DefaultValue1 == "DIES")
                            {
                                if (kvExpensesTypeGroup.KeyValueIntCode == ETEMEnums.ExpensesTypeGroupEnum.IndirectDepartmentExpensesGroup.ToString())
                                {
                                    productCostDieHandlingCostDataView = new ProductCostDataView();

                                    productCostDieHandlingCostDataView.ProductCostType = "Extrusion";
                                    productCostDieHandlingCostDataView.RowType = "Data";
                                    productCostDieHandlingCostDataView.Name = "Die handling cost";
                                    productCostDieHandlingCostDataView.RowKeyIntCode = "DieHandlingCost";
                                    productCostDieHandlingCostDataView.Value_EUR_ton = currValue * 1000;
                                    productCostDieHandlingCostDataView.Value_EUR_kg = currValue;
                                    productCostDieHandlingCostDataView.Value_EUR_PC = currValue * weightPerPC;
                                }
                                else
                                {
                                    if (kvExpensesTypeGroup.KeyValueIntCode != ETEMEnums.ExpensesTypeGroupEnum.DirectDepreciationGroup.ToString())
                                    {
                                        totalExtrusion += currValue * 1000; //For DIES Department formula is different: '=Value (EUR/kg)*1000
                                    }
                                    else
                                    {

                                    }
                                }
                            }
                            else
                            {
                                totalExtrusion += decimal.Zero;
                            }
                            #endregion
                        }
                    }

                    productCostDataView = new ProductCostDataView();

                    productCostDataView.ProductCostType = "Extrusion";
                    productCostDataView.RowType = "Data";
                    productCostDataView.Name = kvExpensesTypeGroup.Name;
                    productCostDataView.RowKeyIntCode = kvExpensesTypeGroup.KeyValueIntCode;
                    productCostDataView.Value_EUR_ton = totalExtrusion;
                    productCostDataView.Value_EUR_kg = totalExtrusion / 1000;
                    productCostDataView.Value_EUR_PC = (totalExtrusion / 1000) * weightPerPC;

                    listProductCosts.Add(productCostDataView);

                    if (kvExpensesTypeGroup.KeyValueIntCode == ETEMEnums.ExpensesTypeGroupEnum.IndirectDepartmentExpensesGroup.ToString())
                    {
                        listProductCosts.Add(productCostDieHandlingCostDataView);
                    }
                }

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "Extrusion";
                productCostDataView.RowType = "Data";
                productCostDataView.Name = "Die depreciation";
                productCostDataView.RowKeyIntCode = "DieDepreciation";
                productCostDataView.Value_EUR_ton = (offer.CostOfDieEUR_Per_TON_Computable.HasValue ? offer.CostOfDieEUR_Per_TON_Computable.Value : 0);
                productCostDataView.Value_EUR_kg = productCostDataView.Value_EUR_ton / 1000;
                productCostDataView.Value_EUR_PC = productCostDataView.Value_EUR_kg * weightPerPC;

                listProductCosts.Add(productCostDataView);

                List<string> listVariableExpenses = new List<string>();
                listVariableExpenses.Add(ETEMEnums.ExpensesTypeGroupEnum.ElectricityGroup.ToString());
                listVariableExpenses.Add(ETEMEnums.ExpensesTypeGroupEnum.NaturalGasGroup.ToString());
                listVariableExpenses.Add(ETEMEnums.ExpensesTypeGroupEnum.ProdMaterialGroup.ToString());

                List<string> listFixedExpenses = new List<string>();
                listFixedExpenses.Add(ETEMEnums.ExpensesTypeGroupEnum.MaintenSparePartGroup.ToString());
                listFixedExpenses.Add(ETEMEnums.ExpensesTypeGroupEnum.OtherFixedCostsGroup.ToString());
                listFixedExpenses.Add(ETEMEnums.ExpensesTypeGroupEnum.IndirectDepartmentExpensesGroup.ToString());
                listFixedExpenses.Add("DieHandlingCost");
                listFixedExpenses.Add(ETEMEnums.ExpensesTypeGroupEnum.FeesAndOtherMaintenanceExpensesGroup.ToString());
                listFixedExpenses.Add(ETEMEnums.ExpensesTypeGroupEnum.OtherIndirectExpensesGroup.ToString());

                List<string> listDepreciations = new List<string>();
                listDepreciations.Add(ETEMEnums.ExpensesTypeGroupEnum.DirectDepreciationGroup.ToString());
                listDepreciations.Add(ETEMEnums.ExpensesTypeGroupEnum.IndirectDepreciationGroup.ToString());
                listDepreciations.Add("DieDepreciation");

                foreach (ProductCostDataView productCost in listProductCosts.Where(w => w.ProductCostType == "Extrusion").ToList())
                {
                    totalExtrusionCost_ton += (productCost.Value_EUR_ton.HasValue ? productCost.Value_EUR_ton.Value : decimal.Zero);
                    totalExtrusionCost_kg += (productCost.Value_EUR_kg.HasValue ? productCost.Value_EUR_kg.Value : decimal.Zero);
                    totalExtrusionCost_PC += (productCost.Value_EUR_PC.HasValue ? productCost.Value_EUR_PC.Value : decimal.Zero);

                    if (productCost.RowKeyIntCode != "LME" && productCost.RowKeyIntCode != "PREMIUM")
                    {
                        totalExtrusionConversionCost_ton += (productCost.Value_EUR_ton.HasValue ? productCost.Value_EUR_ton.Value : decimal.Zero);
                        totalExtrusionConversionCost_kg += (productCost.Value_EUR_kg.HasValue ? productCost.Value_EUR_kg.Value : decimal.Zero);
                        totalExtrusionConversionCost_PC += (productCost.Value_EUR_PC.HasValue ? productCost.Value_EUR_PC.Value : decimal.Zero);
                    }

                    if (productCost.RowKeyIntCode != "LME" && productCost.RowKeyIntCode != "PREMIUM" &&
                        !listDepreciations.Contains(productCost.RowKeyIntCode))
                    {
                        totalExtrusionConversionCostWithoutDepreciation_ton += (productCost.Value_EUR_ton.HasValue ? productCost.Value_EUR_ton.Value : decimal.Zero);
                        totalExtrusionConversionCostWithoutDepreciation_kg += (productCost.Value_EUR_kg.HasValue ? productCost.Value_EUR_kg.Value : decimal.Zero);
                        totalExtrusionConversionCostWithoutDepreciation_PC += (productCost.Value_EUR_PC.HasValue ? productCost.Value_EUR_PC.Value : decimal.Zero);
                    }

                    if (listVariableExpenses.Contains(productCost.RowKeyIntCode))
                    {
                        totalVariableExpenses_ton += (productCost.Value_EUR_ton.HasValue ? productCost.Value_EUR_ton.Value : decimal.Zero);
                        totalVariableExpenses_kg += (productCost.Value_EUR_kg.HasValue ? productCost.Value_EUR_kg.Value : decimal.Zero);
                        totalVariableExpenses_PC += (productCost.Value_EUR_PC.HasValue ? productCost.Value_EUR_PC.Value : decimal.Zero);
                    }

                    if (listFixedExpenses.Contains(productCost.RowKeyIntCode))
                    {
                        totalFixedExpenses_ton += (productCost.Value_EUR_ton.HasValue ? productCost.Value_EUR_ton.Value : decimal.Zero);
                        totalFixedExpenses_kg += (productCost.Value_EUR_kg.HasValue ? productCost.Value_EUR_kg.Value : decimal.Zero);
                        totalFixedExpenses_PC += (productCost.Value_EUR_PC.HasValue ? productCost.Value_EUR_PC.Value : decimal.Zero);
                    }

                    if (listDepreciations.Contains(productCost.RowKeyIntCode))
                    {
                        totalDepreciations_ton += (productCost.Value_EUR_ton.HasValue ? productCost.Value_EUR_ton.Value : decimal.Zero);
                        totalDepreciations_kg += (productCost.Value_EUR_kg.HasValue ? productCost.Value_EUR_kg.Value : decimal.Zero);
                        totalDepreciations_PC += (productCost.Value_EUR_PC.HasValue ? productCost.Value_EUR_PC.Value : decimal.Zero);
                    }
                }

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "Extrusion";
                productCostDataView.RowType = "Total";
                productCostDataView.Name = "Total Extrusion Cost (incl. Aluminium)";
                productCostDataView.RowKeyIntCode = "TotalExtrusionCost";
                productCostDataView.Value_EUR_ton = totalExtrusionCost_ton;
                productCostDataView.Value_EUR_kg = totalExtrusionCost_kg;
                productCostDataView.Value_EUR_PC = totalExtrusionCost_PC;

                listProductCosts.Add(productCostDataView);

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "Extrusion";
                productCostDataView.RowType = "Total";
                productCostDataView.Name = "Extrusion Conversion cost (excl. Aluminium)";
                productCostDataView.RowKeyIntCode = "TotalExtrusionConversionCost";
                productCostDataView.Value_EUR_ton = totalExtrusionConversionCost_ton;
                productCostDataView.Value_EUR_kg = totalExtrusionConversionCost_kg;
                productCostDataView.Value_EUR_PC = totalExtrusionConversionCost_PC;

                listProductCosts.Add(productCostDataView);

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "Extrusion";
                productCostDataView.RowType = "Total";
                productCostDataView.Name = "Extrusion Conversion cost (excl. Aluminium and Depreciation)";
                productCostDataView.RowKeyIntCode = "TotalExtrusionConversionCostWithoutDepreciation";
                productCostDataView.Value_EUR_ton = totalExtrusionConversionCostWithoutDepreciation_ton;
                productCostDataView.Value_EUR_kg = totalExtrusionConversionCostWithoutDepreciation_kg;
                productCostDataView.Value_EUR_PC = totalExtrusionConversionCostWithoutDepreciation_PC;

                listProductCosts.Add(productCostDataView);

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "Extrusion";
                productCostDataView.RowType = "Total";
                productCostDataView.Name = "Variable Expenses";
                productCostDataView.RowKeyIntCode = "VariableExpenses";
                productCostDataView.Value_EUR_ton = totalVariableExpenses_ton;
                productCostDataView.Value_EUR_kg = totalVariableExpenses_kg;
                productCostDataView.Value_EUR_PC = totalVariableExpenses_PC;

                listProductCosts.Add(productCostDataView);

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "Extrusion";
                productCostDataView.RowType = "Total";
                productCostDataView.Name = "Fixed Expenses";
                productCostDataView.RowKeyIntCode = "FixedExpenses";
                productCostDataView.Value_EUR_ton = totalFixedExpenses_ton;
                productCostDataView.Value_EUR_kg = totalFixedExpenses_kg;
                productCostDataView.Value_EUR_PC = totalFixedExpenses_PC;

                listProductCosts.Add(productCostDataView);

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "Extrusion";
                productCostDataView.RowType = "Total";
                productCostDataView.Name = "Depreciation";
                productCostDataView.RowKeyIntCode = "Depreciation";
                productCostDataView.Value_EUR_ton = totalDepreciations_ton;
                productCostDataView.Value_EUR_kg = totalDepreciations_kg;
                productCostDataView.Value_EUR_PC = totalDepreciations_PC;

                listProductCosts.Add(productCostDataView);

                #endregion

                #region Packaging

                decimal totalPackaging = decimal.Zero;

                decimal totalPackagingCost_ton = decimal.Zero;
                decimal totalPackagingCostWithoutDepreciation_ton = decimal.Zero;
                decimal totalPackVariableExpenses_ton = decimal.Zero;
                decimal totalPackFixedExpenses_ton = decimal.Zero;
                decimal totalPackDepreciations_ton = decimal.Zero;

                decimal totalPackagingCost_kg = decimal.Zero;
                decimal totalPackagingCostWithoutDepreciation_kg = decimal.Zero;
                decimal totalPackVariableExpenses_kg = decimal.Zero;
                decimal totalPackFixedExpenses_kg = decimal.Zero;
                decimal totalPackDepreciations_kg = decimal.Zero;
                
                decimal totalPackagingCost_PC = decimal.Zero;
                decimal totalPackagingCostWithoutDepreciation_PC = decimal.Zero;
                decimal totalPackVariableExpenses_PC = decimal.Zero;
                decimal totalPackFixedExpenses_PC = decimal.Zero;
                decimal totalPackDepreciations_PC = decimal.Zero;

                decimal materialCostForPackaging = decimal.Zero;
                decimal ratioConsumptionPackaging = decimal.Zero;

                if (offer.MaterialCostForPackaging.HasValue)
                {
                    materialCostForPackaging = (offer.MaterialCostForPackaging.HasValue ? offer.MaterialCostForPackaging.Value : decimal.Zero);
                }
                else
                {
                    Setting setting = new SettingBL().GetSettingByCode(ETEMEnums.AppSettings.Material_cost_for_packaging.ToString());
                    if (setting != null)
                    {
                        materialCostForPackaging = BaseHelper.ConvertToDecimalOrZero(setting.SettingValue);
                    }
                }
                if (offer.RatioConsumptionPackaging.HasValue)
                {
                    ratioConsumptionPackaging = (offer.RatioConsumptionPackaging.HasValue ? offer.RatioConsumptionPackaging.Value : decimal.Zero);
                }
                else
                {
                    Setting setting = new SettingBL().GetSettingByCode(ETEMEnums.AppSettings.Ratio_consumption_packaging.ToString());
                    if (setting != null)
                    {
                        ratioConsumptionPackaging = BaseHelper.ConvertToDecimalOrZero(setting.SettingValue);
                    }
                }                

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "Packaging";
                productCostDataView.RowType = "Data";
                productCostDataView.Name = "Material cost";
                productCostDataView.RowKeyIntCode = "MaterialCost";
                productCostDataView.Value_EUR_ton = materialCostForPackaging;
                productCostDataView.Value_EUR_kg = materialCostForPackaging / 1000;
                productCostDataView.Value_EUR_PC = (materialCostForPackaging / 1000) * weightPerPC;

                listProductCosts.Add(productCostDataView);

                decimal costOfConsumedMaterialScrap = decimal.Zero;
                decimal totalExtrusionCost  = decimal.Zero;
                
                ProductCostDataView prodCostDataView = listProductCosts.Where(w => w.ProductCostType == "Extrusion" &&
                                                                              w.RowType == "Total" &&
                                                                              w.RowKeyIntCode == "TotalExtrusionCost").FirstOrDefault();

                totalExtrusionCost = (prodCostDataView != null && prodCostDataView.Value_EUR_ton.HasValue ? prodCostDataView.Value_EUR_ton.Value : decimal.Zero);

                costOfConsumedMaterialScrap = (ratioConsumptionPackaging - 1) *
                                               (totalExtrusionCost - ((offer.ScrapValuePercent.HasValue ? offer.ScrapValuePercent.Value : decimal.Zero) *
                                                                      (offer.LME.HasValue ? offer.LME.Value : decimal.Zero)));

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "Packaging";
                productCostDataView.RowType = "Data";
                productCostDataView.Name = "Cost of Consumed material Scrap";
                productCostDataView.RowKeyIntCode = "CostOfConsumedMaterialScrap";
                productCostDataView.Value_EUR_ton = costOfConsumedMaterialScrap;
                productCostDataView.Value_EUR_kg = costOfConsumedMaterialScrap / 1000;
                productCostDataView.Value_EUR_PC = (costOfConsumedMaterialScrap / 1000) * weightPerPC;

                listProductCosts.Add(productCostDataView);

                foreach (KeyValueDataView kvExpensesTypeGroup in listKeyValueExpensesTypeGroup)
                {
                    totalPackaging = decimal.Zero;

                    foreach (KeyValueDataView kvCostCenter in listKeyValueCostCenterWithPackaging)
                    {
                        var currGroupExpense = listGroupExpense.Where(w => w.idExpensesType == kvExpensesTypeGroup.idKeyValue &&
                                                                      w.idCostCenter == kvCostCenter.idKeyValue).FirstOrDefault();

                        if (currGroupExpense != null)
                        {
                            currValue = Convert.ToDecimal(currGroupExpense.ValueData);

                            #region Calculate EUR per TON
                            if (kvCostCenter.DefaultValue1 == "Packaging")
                            {
                                if (offerProducitivity != null && offerProducitivity.PackagingProducitivity_TON_MH != decimal.Zero)
                                {
                                    totalPackaging += currValue / offerProducitivity.PackagingProducitivity_TON_MH;
                                }
                                else
                                {
                                    totalPackaging += currValue;
                                }
                            }                            
                            else
                            {
                                totalPackaging += decimal.Zero;
                            }
                            #endregion
                        }
                    }

                    productCostDataView = new ProductCostDataView();

                    productCostDataView.ProductCostType = "Packaging";
                    productCostDataView.RowType = "Data";
                    productCostDataView.Name = kvExpensesTypeGroup.Name;
                    productCostDataView.RowKeyIntCode = kvExpensesTypeGroup.KeyValueIntCode;
                    productCostDataView.Value_EUR_ton = totalPackaging;
                    productCostDataView.Value_EUR_kg = totalPackaging / 1000;
                    productCostDataView.Value_EUR_PC = (totalPackaging / 1000) * weightPerPC;

                    listProductCosts.Add(productCostDataView);
                }

                foreach (ProductCostDataView productCost in listProductCosts.Where(w => w.ProductCostType == "Packaging").ToList())
                {
                    totalPackagingCost_ton += (productCost.Value_EUR_ton.HasValue ? productCost.Value_EUR_ton.Value : decimal.Zero);
                    totalPackagingCost_kg += (productCost.Value_EUR_kg.HasValue ? productCost.Value_EUR_kg.Value : decimal.Zero);
                    totalPackagingCost_PC += (productCost.Value_EUR_PC.HasValue ? productCost.Value_EUR_PC.Value : decimal.Zero);

                    if (productCost.RowKeyIntCode != ETEMEnums.ExpensesTypeGroupEnum.DirectDepreciationGroup.ToString() &&
                        productCost.RowKeyIntCode != ETEMEnums.ExpensesTypeGroupEnum.IndirectDepreciationGroup.ToString() &&
                        productCost.RowKeyIntCode != "DieDepreciation")
                    {
                        totalPackagingCostWithoutDepreciation_ton += (productCost.Value_EUR_ton.HasValue ? productCost.Value_EUR_ton.Value : decimal.Zero);
                        totalPackagingCostWithoutDepreciation_kg += (productCost.Value_EUR_kg.HasValue ? productCost.Value_EUR_kg.Value : decimal.Zero);
                        totalPackagingCostWithoutDepreciation_PC += (productCost.Value_EUR_PC.HasValue ? productCost.Value_EUR_PC.Value : decimal.Zero);
                    }

                    if (listVariableExpenses.Contains(productCost.RowKeyIntCode))
                    {
                        totalPackVariableExpenses_ton += (productCost.Value_EUR_ton.HasValue ? productCost.Value_EUR_ton.Value : decimal.Zero);
                        totalPackVariableExpenses_kg += (productCost.Value_EUR_kg.HasValue ? productCost.Value_EUR_kg.Value : decimal.Zero);
                        totalPackVariableExpenses_PC += (productCost.Value_EUR_PC.HasValue ? productCost.Value_EUR_PC.Value : decimal.Zero);
                    }

                    if (listFixedExpenses.Contains(productCost.RowKeyIntCode))
                    {
                        totalPackFixedExpenses_ton += (productCost.Value_EUR_ton.HasValue ? productCost.Value_EUR_ton.Value : decimal.Zero);
                        totalPackFixedExpenses_kg += (productCost.Value_EUR_kg.HasValue ? productCost.Value_EUR_kg.Value : decimal.Zero);
                        totalPackFixedExpenses_PC += (productCost.Value_EUR_PC.HasValue ? productCost.Value_EUR_PC.Value : decimal.Zero);
                    }

                    if (listDepreciations.Contains(productCost.RowKeyIntCode))
                    {
                        totalPackDepreciations_ton += (productCost.Value_EUR_ton.HasValue ? productCost.Value_EUR_ton.Value : decimal.Zero);
                        totalPackDepreciations_kg += (productCost.Value_EUR_kg.HasValue ? productCost.Value_EUR_kg.Value : decimal.Zero);
                        totalPackDepreciations_PC += (productCost.Value_EUR_PC.HasValue ? productCost.Value_EUR_PC.Value : decimal.Zero);
                    }
                }

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "Packaging";
                productCostDataView.RowType = "Total";
                productCostDataView.Name = "Total Packaging Cost";
                productCostDataView.RowKeyIntCode = "TotalPackagingCost";
                productCostDataView.Value_EUR_ton = totalPackagingCost_ton;
                productCostDataView.Value_EUR_kg = totalPackagingCost_kg;
                productCostDataView.Value_EUR_PC = totalPackagingCost_PC;

                listProductCosts.Add(productCostDataView);

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "Packaging";
                productCostDataView.RowType = "Total";
                productCostDataView.Name = "Total Packaging Cost (excl. Depreciation)";
                productCostDataView.RowKeyIntCode = "TotalPackagingCostWithoutDepreciation";
                productCostDataView.Value_EUR_ton = totalPackagingCostWithoutDepreciation_ton;
                productCostDataView.Value_EUR_kg = totalPackagingCostWithoutDepreciation_kg;
                productCostDataView.Value_EUR_PC = totalPackagingCostWithoutDepreciation_PC;

                listProductCosts.Add(productCostDataView);

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "Packaging";
                productCostDataView.RowType = "Total";
                productCostDataView.Name = "Variable Expenses";
                productCostDataView.RowKeyIntCode = "PackagingVariableExpenses";
                productCostDataView.Value_EUR_ton = totalPackVariableExpenses_ton;
                productCostDataView.Value_EUR_kg = totalPackVariableExpenses_kg;
                productCostDataView.Value_EUR_PC = totalPackVariableExpenses_PC;

                listProductCosts.Add(productCostDataView);

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "Packaging";
                productCostDataView.RowType = "Total";
                productCostDataView.Name = "Fixed Expenses";
                productCostDataView.RowKeyIntCode = "PackagingFixedExpenses";
                productCostDataView.Value_EUR_ton = totalPackFixedExpenses_ton;
                productCostDataView.Value_EUR_kg = totalPackFixedExpenses_kg;
                productCostDataView.Value_EUR_PC = totalPackFixedExpenses_PC;

                listProductCosts.Add(productCostDataView);

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "Packaging";
                productCostDataView.RowType = "Total";
                productCostDataView.Name = "Depreciation";
                productCostDataView.RowKeyIntCode = "PackagingDepreciation";
                productCostDataView.Value_EUR_ton = totalPackDepreciations_ton;
                productCostDataView.Value_EUR_kg = totalPackDepreciations_kg;
                productCostDataView.Value_EUR_PC = totalPackDepreciations_PC;

                listProductCosts.Add(productCostDataView);

                #endregion

                #region Transportation Cost & Commission

                decimal commission = decimal.Zero;

                decimal totalTransportationCostAndCommission_ton = decimal.Zero;
                decimal totalTransportationCostAndCommission_kg = decimal.Zero;
                decimal totalTransportationCostAndCommission_PC = decimal.Zero;

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "TransportationCostAndCommission";
                productCostDataView.RowType = "Data";
                productCostDataView.Name = "Transportation";
                productCostDataView.RowKeyIntCode = "Transportation";
                productCostDataView.Value_EUR_ton = (offer.TransportationCost.HasValue ? offer.TransportationCost.Value : decimal.Zero);
                productCostDataView.Value_EUR_kg = (productCostDataView.Value_EUR_ton.HasValue ? productCostDataView.Value_EUR_ton / 1000 : decimal.Zero);
                productCostDataView.Value_EUR_PC = (productCostDataView.Value_EUR_kg.HasValue ? productCostDataView.Value_EUR_kg * weightPerPC : decimal.Zero);

                listProductCosts.Add(productCostDataView);

                commission = (offer.Commission_EUR_Computable.HasValue ? offer.Commission_EUR_Computable.Value : decimal.Zero) / (offer.Tonnage.HasValue && offer.Tonnage.Value != 0 ? offer.Tonnage.Value : 1);

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "TransportationCostAndCommission";
                productCostDataView.RowType = "Data";
                productCostDataView.Name = "Commission";
                productCostDataView.RowKeyIntCode = "Commission";
                productCostDataView.Value_EUR_ton = commission;
                productCostDataView.Value_EUR_kg = (productCostDataView.Value_EUR_ton.HasValue ? productCostDataView.Value_EUR_ton / 1000 : decimal.Zero);
                productCostDataView.Value_EUR_PC = (productCostDataView.Value_EUR_kg.HasValue ? productCostDataView.Value_EUR_kg * weightPerPC : decimal.Zero);

                listProductCosts.Add(productCostDataView);

                foreach (ProductCostDataView productCost in listProductCosts.Where(w => w.ProductCostType == "TransportationCostAndCommission").ToList())
                {
                    totalTransportationCostAndCommission_ton += (productCost.Value_EUR_ton.HasValue ? productCost.Value_EUR_ton.Value : decimal.Zero);
                    totalTransportationCostAndCommission_kg += (productCost.Value_EUR_kg.HasValue ? productCost.Value_EUR_kg.Value : decimal.Zero);
                    totalTransportationCostAndCommission_PC += (productCost.Value_EUR_PC.HasValue ? productCost.Value_EUR_PC.Value : decimal.Zero);
                }

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "TransportationCostAndCommission";
                productCostDataView.RowType = "Total";
                productCostDataView.Name = "Total Transportation Cost & Commission";
                productCostDataView.RowKeyIntCode = "TotalTransportationCostAndCommission";
                productCostDataView.Value_EUR_ton = totalTransportationCostAndCommission_ton;
                productCostDataView.Value_EUR_kg = totalTransportationCostAndCommission_kg;
                productCostDataView.Value_EUR_PC = totalTransportationCostAndCommission_PC;

                listProductCosts.Add(productCostDataView);

                #endregion

                #region SGA's and Financials

                decimal totalSGAsAndFinancials_ton = decimal.Zero;
                decimal totalSGAsAndFinancials_kg = decimal.Zero;
                decimal totalSGAsAndFinancials_PC = decimal.Zero;

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "SGAsAndFinancials";
                productCostDataView.RowType = "Data";
                productCostDataView.Name = "Administration expenses";
                productCostDataView.RowKeyIntCode = "AdministrationExpenses";
                productCostDataView.Value_EUR_ton = (offer.AdministrationExpenses.HasValue ? offer.AdministrationExpenses.Value : decimal.Zero);
                productCostDataView.Value_EUR_kg = (productCostDataView.Value_EUR_ton.HasValue ? productCostDataView.Value_EUR_ton / 1000 : decimal.Zero);
                productCostDataView.Value_EUR_PC = (productCostDataView.Value_EUR_kg.HasValue ? productCostDataView.Value_EUR_kg * weightPerPC : decimal.Zero);

                listProductCosts.Add(productCostDataView);

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "SGAsAndFinancials";
                productCostDataView.RowType = "Data";
                productCostDataView.Name = "Sales expenses";
                productCostDataView.RowKeyIntCode = "SalesExpenses";
                productCostDataView.Value_EUR_ton = (offer.SalesExpenses.HasValue ? offer.SalesExpenses.Value : decimal.Zero);
                productCostDataView.Value_EUR_kg = (productCostDataView.Value_EUR_ton.HasValue ? productCostDataView.Value_EUR_ton / 1000 : decimal.Zero);
                productCostDataView.Value_EUR_PC = (productCostDataView.Value_EUR_kg.HasValue ? productCostDataView.Value_EUR_kg * weightPerPC : decimal.Zero);

                listProductCosts.Add(productCostDataView);

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "SGAsAndFinancials";
                productCostDataView.RowType = "Data";
                productCostDataView.Name = "Financial fixed expenses";
                productCostDataView.RowKeyIntCode = "FinancialFixedExpenses";
                productCostDataView.Value_EUR_ton = (offer.FinancialFixedExpenses.HasValue ? offer.FinancialFixedExpenses.Value : decimal.Zero);
                productCostDataView.Value_EUR_kg = (productCostDataView.Value_EUR_ton.HasValue ? productCostDataView.Value_EUR_ton / 1000 : decimal.Zero);
                productCostDataView.Value_EUR_PC = (productCostDataView.Value_EUR_kg.HasValue ? productCostDataView.Value_EUR_kg * weightPerPC : decimal.Zero);

                listProductCosts.Add(productCostDataView);

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "SGAsAndFinancials";
                productCostDataView.RowType = "Data";
                productCostDataView.Name = "Financial variable expenses";
                productCostDataView.RowKeyIntCode = "FinancialVariableExpenses";
                productCostDataView.Value_EUR_ton = (offer.FinancialVariableExpenses.HasValue ? offer.FinancialVariableExpenses.Value : decimal.Zero);
                productCostDataView.Value_EUR_kg = (productCostDataView.Value_EUR_ton.HasValue ? productCostDataView.Value_EUR_ton / 1000 : decimal.Zero);
                productCostDataView.Value_EUR_PC = (productCostDataView.Value_EUR_kg.HasValue ? productCostDataView.Value_EUR_kg * weightPerPC : decimal.Zero);

                listProductCosts.Add(productCostDataView);

                foreach (ProductCostDataView productCost in listProductCosts.Where(w => w.ProductCostType == "SGAsAndFinancials").ToList())
                {
                    totalSGAsAndFinancials_ton += (productCost.Value_EUR_ton.HasValue ? productCost.Value_EUR_ton.Value : decimal.Zero);
                    totalSGAsAndFinancials_kg += (productCost.Value_EUR_kg.HasValue ? productCost.Value_EUR_kg.Value : decimal.Zero);
                    totalSGAsAndFinancials_PC += (productCost.Value_EUR_PC.HasValue ? productCost.Value_EUR_PC.Value : decimal.Zero);
                }

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "SGAsAndFinancials";
                productCostDataView.RowType = "Total";
                productCostDataView.Name = "Total SGA's and Financial Cost";
                productCostDataView.RowKeyIntCode = "TotalSGAsAndFinancialCost";
                productCostDataView.Value_EUR_ton = totalSGAsAndFinancials_ton;
                productCostDataView.Value_EUR_kg = totalSGAsAndFinancials_kg;
                productCostDataView.Value_EUR_PC = totalSGAsAndFinancials_PC;

                listProductCosts.Add(productCostDataView);

                #endregion

                #region TOTAL PRODUCT COST

                decimal totalConversionCost_ton = decimal.Zero;
                decimal totalConversionCost_kg = decimal.Zero;
                decimal totalConversionCost_PC = decimal.Zero;

                decimal totalConversionCostWithoutAluminium_ton = decimal.Zero;
                decimal totalConversionCostWithoutAluminium_kg = decimal.Zero;
                decimal totalConversionCostWithoutAluminium_PC = decimal.Zero;

                decimal totalConversionCostWithoutAluminiumAndDepreciation_ton = decimal.Zero;
                decimal totalConversionCostWithoutAluminiumAndDepreciation_kg = decimal.Zero;
                decimal totalConversionCostWithoutAluminiumAndDepreciation_PC = decimal.Zero;

                decimal totalCostExtrPackTranspAndComm_ton = decimal.Zero;
                decimal totalCostExtrPackTranspAndComm_kg = decimal.Zero;
                decimal totalCostExtrPackTranspAndComm_PC = decimal.Zero;

                decimal totalCostExtrPackTranspAndCommWithoutDepr_ton = decimal.Zero;
                decimal totalCostExtrPackTranspAndCommWithoutDepr_kg = decimal.Zero;
                decimal totalCostExtrPackTranspAndCommWithoutDepr_PC = decimal.Zero;

                decimal totalCost_ton = decimal.Zero;
                decimal totalCost_kg = decimal.Zero;
                decimal totalCost_PC = decimal.Zero;

                var productCostExtrusionTotal = listProductCosts.Where(w => w.ProductCostType == "Extrusion" && w.RowType == "Total" && w.RowKeyIntCode == "TotalExtrusionCost").FirstOrDefault();
                var productCostPackagingTotal = listProductCosts.Where(w => w.ProductCostType == "Packaging" && w.RowType == "Total" && w.RowKeyIntCode == "TotalPackagingCost").FirstOrDefault();

                var productCostExtrusionLME = listProductCosts.Where(w => w.ProductCostType == "Extrusion" && w.RowType == "Data" && w.RowKeyIntCode == "LME").FirstOrDefault();
                var productCostExtrusionPREMIUM = listProductCosts.Where(w => w.ProductCostType == "Extrusion" && w.RowType == "Data" && w.RowKeyIntCode == "PREMIUM").FirstOrDefault();

                var productCostExtrusionDepreciation = listProductCosts.Where(w => w.ProductCostType == "Extrusion" && w.RowType == "Total" && w.RowKeyIntCode == "Depreciation").FirstOrDefault();
                var productCostPackagingDepreciation = listProductCosts.Where(w => w.ProductCostType == "Packaging" && w.RowType == "Total" && w.RowKeyIntCode == "PackagingDepreciation").FirstOrDefault();

                var productCostSGAsAndFinancialsTotal = listProductCosts.Where(w => w.ProductCostType == "SGAsAndFinancials" && w.RowType == "Total" && w.RowKeyIntCode == "TotalSGAsAndFinancialCost").FirstOrDefault();

                var productCostTransportationCostAndCommissionTotal = listProductCosts.Where(w => w.ProductCostType == "TransportationCostAndCommission" && w.RowType == "Total" && w.RowKeyIntCode == "TotalTransportationCostAndCommission").FirstOrDefault();

                if (productCostExtrusionTotal != null)
                {
                    totalConversionCost_ton = (productCostExtrusionTotal.Value_EUR_ton.HasValue ? productCostExtrusionTotal.Value_EUR_ton.Value : decimal.Zero);
                    totalConversionCost_kg = (productCostExtrusionTotal.Value_EUR_kg.HasValue ? productCostExtrusionTotal.Value_EUR_kg.Value : decimal.Zero);
                    totalConversionCost_PC = (productCostExtrusionTotal.Value_EUR_PC.HasValue ? productCostExtrusionTotal.Value_EUR_PC.Value : decimal.Zero);

                    totalCostExtrPackTranspAndComm_ton = (productCostExtrusionTotal.Value_EUR_ton.HasValue ? productCostExtrusionTotal.Value_EUR_ton.Value : decimal.Zero);
                    totalCostExtrPackTranspAndComm_kg = (productCostExtrusionTotal.Value_EUR_kg.HasValue ? productCostExtrusionTotal.Value_EUR_kg.Value : decimal.Zero);
                    totalCostExtrPackTranspAndComm_PC = (productCostExtrusionTotal.Value_EUR_PC.HasValue ? productCostExtrusionTotal.Value_EUR_PC.Value : decimal.Zero);
                }
                if (productCostPackagingTotal != null)
                {
                    totalConversionCost_ton += (productCostPackagingTotal.Value_EUR_ton.HasValue ? productCostPackagingTotal.Value_EUR_ton.Value : decimal.Zero);
                    totalConversionCost_kg += (productCostPackagingTotal.Value_EUR_kg.HasValue ? productCostPackagingTotal.Value_EUR_kg.Value : decimal.Zero);
                    totalConversionCost_PC += (productCostPackagingTotal.Value_EUR_PC.HasValue ? productCostPackagingTotal.Value_EUR_PC.Value : decimal.Zero);

                    totalCostExtrPackTranspAndComm_ton += (productCostPackagingTotal.Value_EUR_ton.HasValue ? productCostPackagingTotal.Value_EUR_ton.Value : decimal.Zero);
                    totalCostExtrPackTranspAndComm_kg += (productCostPackagingTotal.Value_EUR_kg.HasValue ? productCostPackagingTotal.Value_EUR_kg.Value : decimal.Zero);
                    totalCostExtrPackTranspAndComm_PC += (productCostPackagingTotal.Value_EUR_PC.HasValue ? productCostPackagingTotal.Value_EUR_PC.Value : decimal.Zero);
                }
                if (productCostSGAsAndFinancialsTotal != null)
                {
                    totalCost_ton = totalConversionCost_ton + (productCostSGAsAndFinancialsTotal.Value_EUR_ton.HasValue ? productCostSGAsAndFinancialsTotal.Value_EUR_ton.Value : decimal.Zero);
                    totalCost_kg = totalConversionCost_kg + (productCostSGAsAndFinancialsTotal.Value_EUR_kg.HasValue ? productCostSGAsAndFinancialsTotal.Value_EUR_kg.Value : decimal.Zero);
                    totalCost_PC = totalConversionCost_PC + (productCostSGAsAndFinancialsTotal.Value_EUR_PC.HasValue ? productCostSGAsAndFinancialsTotal.Value_EUR_PC.Value : decimal.Zero);
                }
                if (productCostTransportationCostAndCommissionTotal != null)
                {
                    totalCost_ton += (productCostTransportationCostAndCommissionTotal.Value_EUR_ton.HasValue ? productCostTransportationCostAndCommissionTotal.Value_EUR_ton.Value : decimal.Zero);
                    totalCost_kg += (productCostTransportationCostAndCommissionTotal.Value_EUR_kg.HasValue ? productCostTransportationCostAndCommissionTotal.Value_EUR_kg.Value : decimal.Zero);
                    totalCost_PC += (productCostTransportationCostAndCommissionTotal.Value_EUR_PC.HasValue ? productCostTransportationCostAndCommissionTotal.Value_EUR_PC.Value : decimal.Zero);

                    totalCostExtrPackTranspAndComm_ton += (productCostTransportationCostAndCommissionTotal.Value_EUR_ton.HasValue ? productCostTransportationCostAndCommissionTotal.Value_EUR_ton.Value : decimal.Zero);
                    totalCostExtrPackTranspAndComm_kg += (productCostTransportationCostAndCommissionTotal.Value_EUR_kg.HasValue ? productCostTransportationCostAndCommissionTotal.Value_EUR_kg.Value : decimal.Zero);
                    totalCostExtrPackTranspAndComm_PC += (productCostTransportationCostAndCommissionTotal.Value_EUR_PC.HasValue ? productCostTransportationCostAndCommissionTotal.Value_EUR_PC.Value : decimal.Zero);
                }
                if (productCostExtrusionLME != null)
                {
                    totalConversionCostWithoutAluminium_ton = totalConversionCost_ton - (productCostExtrusionLME.Value_EUR_ton.HasValue ? productCostExtrusionLME.Value_EUR_ton.Value : decimal.Zero);
                    totalConversionCostWithoutAluminium_kg = totalConversionCost_kg - (productCostExtrusionLME.Value_EUR_kg.HasValue ? productCostExtrusionLME.Value_EUR_kg.Value : decimal.Zero);
                    totalConversionCostWithoutAluminium_PC = totalConversionCost_PC - (productCostExtrusionLME.Value_EUR_PC.HasValue ? productCostExtrusionLME.Value_EUR_PC.Value : decimal.Zero);
                }
                if (productCostExtrusionPREMIUM != null)
                {
                    totalConversionCostWithoutAluminium_ton = totalConversionCostWithoutAluminium_ton - (productCostExtrusionPREMIUM.Value_EUR_ton.HasValue ? productCostExtrusionPREMIUM.Value_EUR_ton.Value : decimal.Zero);
                    totalConversionCostWithoutAluminium_kg = totalConversionCostWithoutAluminium_kg - (productCostExtrusionPREMIUM.Value_EUR_kg.HasValue ? productCostExtrusionPREMIUM.Value_EUR_kg.Value : decimal.Zero);
                    totalConversionCostWithoutAluminium_PC = totalConversionCostWithoutAluminium_PC - (productCostExtrusionPREMIUM.Value_EUR_PC.HasValue ? productCostExtrusionPREMIUM.Value_EUR_PC.Value : decimal.Zero);
                }
                if (productCostExtrusionDepreciation != null)
                {
                    totalConversionCostWithoutAluminiumAndDepreciation_ton = totalConversionCostWithoutAluminium_ton - (productCostExtrusionDepreciation.Value_EUR_ton.HasValue ? productCostExtrusionDepreciation.Value_EUR_ton.Value : decimal.Zero);
                    totalConversionCostWithoutAluminiumAndDepreciation_kg = totalConversionCostWithoutAluminium_kg - (productCostExtrusionDepreciation.Value_EUR_kg.HasValue ? productCostExtrusionDepreciation.Value_EUR_kg.Value : decimal.Zero);
                    totalConversionCostWithoutAluminiumAndDepreciation_PC = totalConversionCostWithoutAluminium_PC - (productCostExtrusionDepreciation.Value_EUR_PC.HasValue ? productCostExtrusionDepreciation.Value_EUR_PC.Value : decimal.Zero);

                    totalCostExtrPackTranspAndCommWithoutDepr_ton = totalCostExtrPackTranspAndComm_ton - (productCostExtrusionDepreciation.Value_EUR_ton.HasValue ? productCostExtrusionDepreciation.Value_EUR_ton.Value : decimal.Zero);
                    totalCostExtrPackTranspAndCommWithoutDepr_kg = totalCostExtrPackTranspAndComm_kg - (productCostExtrusionDepreciation.Value_EUR_kg.HasValue ? productCostExtrusionDepreciation.Value_EUR_kg.Value : decimal.Zero);
                    totalCostExtrPackTranspAndCommWithoutDepr_PC = totalCostExtrPackTranspAndComm_PC - (productCostExtrusionDepreciation.Value_EUR_PC.HasValue ? productCostExtrusionDepreciation.Value_EUR_PC.Value : decimal.Zero);
                }
                if (productCostPackagingDepreciation != null)
                {
                    totalConversionCostWithoutAluminiumAndDepreciation_ton = totalConversionCostWithoutAluminiumAndDepreciation_ton - (productCostPackagingDepreciation.Value_EUR_ton.HasValue ? productCostPackagingDepreciation.Value_EUR_ton.Value : decimal.Zero);
                    totalConversionCostWithoutAluminiumAndDepreciation_kg = totalConversionCostWithoutAluminiumAndDepreciation_kg - (productCostPackagingDepreciation.Value_EUR_kg.HasValue ? productCostPackagingDepreciation.Value_EUR_kg.Value : decimal.Zero);
                    totalConversionCostWithoutAluminiumAndDepreciation_PC = totalConversionCostWithoutAluminiumAndDepreciation_PC - (productCostPackagingDepreciation.Value_EUR_PC.HasValue ? productCostPackagingDepreciation.Value_EUR_PC.Value : decimal.Zero);

                    totalCostExtrPackTranspAndCommWithoutDepr_ton = totalCostExtrPackTranspAndCommWithoutDepr_ton - (productCostPackagingDepreciation.Value_EUR_ton.HasValue ? productCostPackagingDepreciation.Value_EUR_ton.Value : decimal.Zero);
                    totalCostExtrPackTranspAndCommWithoutDepr_kg = totalCostExtrPackTranspAndCommWithoutDepr_kg - (productCostPackagingDepreciation.Value_EUR_kg.HasValue ? productCostPackagingDepreciation.Value_EUR_kg.Value : decimal.Zero);
                    totalCostExtrPackTranspAndCommWithoutDepr_PC = totalCostExtrPackTranspAndCommWithoutDepr_PC - (productCostPackagingDepreciation.Value_EUR_PC.HasValue ? productCostPackagingDepreciation.Value_EUR_PC.Value : decimal.Zero);
                }

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "TotalProductCost";
                productCostDataView.RowType = "Total";
                productCostDataView.Name = "Total Cost (incl. Extrusion and Packaging)";
                productCostDataView.RowKeyIntCode = "TotalConversionCost";
                productCostDataView.Value_EUR_ton = totalConversionCost_ton;
                productCostDataView.Value_EUR_kg = totalConversionCost_kg;
                productCostDataView.Value_EUR_PC = totalConversionCost_PC;

                listProductCosts.Add(productCostDataView);

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "TotalProductCost";
                productCostDataView.RowType = "Total";
                productCostDataView.Name = "Total Conversion Cost (excl.  Aluminium)";
                productCostDataView.RowKeyIntCode = "TotalConversionCostWithoutLMEsPREMIUM";
                productCostDataView.Value_EUR_ton = totalConversionCostWithoutAluminium_ton;
                productCostDataView.Value_EUR_kg = totalConversionCostWithoutAluminium_kg;
                productCostDataView.Value_EUR_PC = totalConversionCostWithoutAluminium_PC;

                listProductCosts.Add(productCostDataView);

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "TotalProductCost";
                productCostDataView.RowType = "Total";
                productCostDataView.Name = "Total Conversion Cost (excl. Aluminium and Depreciation)";
                productCostDataView.RowKeyIntCode = "TotalConversionCostWithoutAluminiumAndDepreciation";
                productCostDataView.Value_EUR_ton = totalConversionCostWithoutAluminiumAndDepreciation_ton;
                productCostDataView.Value_EUR_kg = totalConversionCostWithoutAluminiumAndDepreciation_kg;
                productCostDataView.Value_EUR_PC = totalConversionCostWithoutAluminiumAndDepreciation_PC;

                listProductCosts.Add(productCostDataView);

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "TotalProductCost";
                productCostDataView.RowType = "Total";
                productCostDataView.Name = "Total Cost (incl. Extrusion, Packaging, Transportation and Commission)";
                productCostDataView.RowKeyIntCode = "TotalCostExtrusionPackagingTransportationAndCommission";
                productCostDataView.Value_EUR_ton = totalCostExtrPackTranspAndComm_ton;
                productCostDataView.Value_EUR_kg = totalCostExtrPackTranspAndComm_kg;
                productCostDataView.Value_EUR_PC = totalCostExtrPackTranspAndComm_PC;

                listProductCosts.Add(productCostDataView);

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "TotalProductCost";
                productCostDataView.RowType = "Total";
                productCostDataView.Name = "Total Cost (incl. Extrusion, Packaging, Transportation and Commission, excl. Depreciation)";
                productCostDataView.RowKeyIntCode = "TotalCostExtrusionPackagingTransportationAndCommissionWithoutDepreciation";
                productCostDataView.Value_EUR_ton = totalCostExtrPackTranspAndCommWithoutDepr_ton;
                productCostDataView.Value_EUR_kg = totalCostExtrPackTranspAndCommWithoutDepr_kg;
                productCostDataView.Value_EUR_PC = totalCostExtrPackTranspAndCommWithoutDepr_PC;

                listProductCosts.Add(productCostDataView);

                productCostDataView = new ProductCostDataView();

                productCostDataView.ProductCostType = "TotalProductCost";
                productCostDataView.RowType = "Total";
                productCostDataView.Name = "TOTAL COST (incl. Extrusion, Packaging, Transportation and Commission, SGA's and Financials)";
                productCostDataView.RowKeyIntCode = "TotalCost";
                productCostDataView.Value_EUR_ton = totalCost_ton;
                productCostDataView.Value_EUR_kg = totalCost_kg;
                productCostDataView.Value_EUR_PC = totalCost_PC;

                listProductCosts.Add(productCostDataView);

                #endregion

                productCostResult.ListProductCosts = listProductCosts;
            }
            catch (Exception ex)
            {
                productCostResult.ResultContext.ResultCode = ETEMEnums.ResultEnum.Error;
                productCostResult.ResultContext.Message = "Error load product costs by offer!";

                BaseHelper.Log("Error load product costs by offer!");
                BaseHelper.Log(ex.Message);
                BaseHelper.Log(ex.StackTrace);
            }

            return productCostResult;
        }
Ejemplo n.º 4
0
        internal OfferOverviewResult LoadOfferOverviewByOfferId(int idOffer, CallContext resultContext)
        {
            OfferOverviewResult result = new OfferOverviewResult();

            listOfferOverview = new List<OfferOverviewDataView>();

            Offer offer = new OfferBL().GetEntityById(idOffer);
            
            productCost = new ProductCostBL().LoadProductCostsByOfferId(idOffer, resultContext);
            
            #region CostTable
            //Aluminum
            ProductCostDataView ProductCostLME = productCost.ListProductCosts.Where(p => p.RowKeyIntCode == "LME").FirstOrDefault();
            ProductCostDataView ProductCostPREMIUM = productCost.ListProductCosts.Where(p => p.RowKeyIntCode == "PREMIUM").FirstOrDefault();
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Aluminum",
                RowKeyIntCode = "Aluminum",
                OfferOverviewType = "CostTable",
                Indicator_Value = (ProductCostLME.Value_EUR_ton.HasValue ? ProductCostLME.Value_EUR_ton.Value : Decimal.Zero) + (ProductCostPREMIUM.Value_EUR_ton.HasValue ? ProductCostPREMIUM.Value_EUR_ton.Value : Decimal.Zero),
                RowType = ETEMEnums.DataRowType.Data
            });

            //Commission
            ProductCostDataView ProductCostCommission = productCost.ListProductCosts.Where(p => p.RowKeyIntCode == "Commission").FirstOrDefault();
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Commission",
                RowKeyIntCode = "CostTableCommission",
                OfferOverviewType = "CostTable",
                Indicator_Value = (ProductCostCommission.Value_EUR_ton.HasValue ? ProductCostCommission.Value_EUR_ton.Value : Decimal.Zero),
                RowType = ETEMEnums.DataRowType.Data
            });

            //Transportation
            ProductCostDataView ProductCostTransportation = productCost.ListProductCosts.Where(p => p.RowKeyIntCode == "Transportation").FirstOrDefault();
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Transportation",
                RowKeyIntCode = "Transportation",
                OfferOverviewType = "CostTable",
                Indicator_Value = (ProductCostTransportation.Value_EUR_ton.HasValue ? ProductCostTransportation.Value_EUR_ton.Value : Decimal.Zero),
                RowType = ETEMEnums.DataRowType.Data
            });

            //Extrusion Conversion cost (without Aluminium) per ton
            ProductCostDataView ProductCostTotalExtrusionConversionCost = productCost.ListProductCosts.Where(p => p.RowKeyIntCode == "TotalExtrusionConversionCost").FirstOrDefault();
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Extrusion conversion cost per ton",
                RowKeyIntCode = "TotalExtrusionConversionCost",
                OfferOverviewType = "CostTable",
                Indicator_Value = (ProductCostTotalExtrusionConversionCost.Value_EUR_ton.HasValue ? ProductCostTotalExtrusionConversionCost.Value_EUR_ton.Value : Decimal.Zero),
                RowType = ETEMEnums.DataRowType.Data
            });


            //Packaging  conversion cost per ton
            ProductCostDataView ProductCostTotalPackagingCost = productCost.ListProductCosts.Where(p => p.RowKeyIntCode == "TotalPackagingCost").FirstOrDefault();
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Packaging  conversion cost per ton",
                RowKeyIntCode = "TotalPackagingCost",
                OfferOverviewType = "CostTable",
                Indicator_Value = (ProductCostTotalPackagingCost.Value_EUR_ton.HasValue ? ProductCostTotalPackagingCost.Value_EUR_ton.Value : Decimal.Zero),
                RowType = ETEMEnums.DataRowType.Data
            });

            //TOTAL COST
            //'=Aluminum+Commision+Transportation+Extrusion conversion cost per ton+Packaging  conversion cost per ton
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "TOTAL COST",
                RowKeyIntCode = "CostTableTotalCost",
                OfferOverviewType = "CostTable",
                Indicator_Value = listOfferOverview.Where(o => o.OfferOverviewType == "CostTable").Sum(s => s.Indicator_Value),
                RowType = ETEMEnums.DataRowType.Total
            });
            
            #endregion

            #region SalesPrice
            //'=Gross margin (%), tab Inquiry data
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Gross margin (%)",
                RowKeyIntCode = "SalesPriceGrossMargin",
                OfferOverviewType = "SalesPrice",
                Indicator_Value = offer.GrossMargin.HasValue ? offer.GrossMargin.Value : Decimal.Zero,
                RowType = ETEMEnums.DataRowType.Data
            });

            //'=TOTAL COST/(1-Gross margin (%))

            try
            {

                listOfferOverview.Add(new OfferOverviewDataView()
                {
                    Name = "Total sales price (EUR/ton)",
                    RowKeyIntCode = "TotalSalesPrice_EUR_TON",
                    OfferOverviewType = "SalesPrice",
                    Indicator_Value = listOfferOverview.FirstOrDefault(p => p.RowKeyIntCode == "CostTableTotalCost").Indicator_Value /
                                        (1 - listOfferOverview.FirstOrDefault(p => p.RowKeyIntCode == "SalesPriceGrossMargin").Indicator_Value / 100),
                    RowType = ETEMEnums.DataRowType.Data
                });
            }
            catch
            {
                
                listOfferOverview.Add(new OfferOverviewDataView()
                {
                    Name = "Total sales price (EUR/ton)",
                    RowKeyIntCode = "TotalSalesPrice_EUR_TON",
                    OfferOverviewType = "SalesPrice",
                    Indicator_Value = Decimal.Zero,
                    RowType = ETEMEnums.DataRowType.Data
                });
            }
           

            //Sales conversion (EUR/ton)
            //'=Total sales price (EUR/ton)-TOTAL COST
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Sales conversion (EUR/ton)",
                RowKeyIntCode = "SalesConversion_EUR_TON",
                OfferOverviewType = "SalesPrice",
                Indicator_Value = listOfferOverview.FirstOrDefault(p => p.RowKeyIntCode == "TotalSalesPrice_EUR_TON").Indicator_Value -
                                  listOfferOverview.FirstOrDefault(p => p.RowKeyIntCode == "CostTableTotalCost").Indicator_Value,
                RowType = ETEMEnums.DataRowType.Data
            });

            //CONVERSION TO CUSTOMER (EUR/ton)
            //'=Total sales price (EUR/ton)-Aluminum
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "CONVERSION TO CUSTOMER (EUR/ton)",
                RowKeyIntCode = "CONVERSION_TO_CUSTOMER_EUR_TON",
                OfferOverviewType = "SalesPrice",
                Indicator_Value = listOfferOverview.FirstOrDefault(p => p.RowKeyIntCode == "TotalSalesPrice_EUR_TON").Indicator_Value -
                                  listOfferOverview.FirstOrDefault(p => p.RowKeyIntCode == "Aluminum").Indicator_Value,
                RowType = ETEMEnums.DataRowType.Data
            });

            ////'=Savings rate %, tab Inquiry data
            //listOfferOverview.Add(new OfferOverviewDataView()
            //{
            //    Name = "Savings rate %",
            //    RowKeyIntCode = "SavingsRate",
            //    OfferOverviewType = "SalesPrice",
            //    Indicator_Value = offer.SavingsRate.HasValue ? offer.SavingsRate.Value : Decimal.Zero,
            //    RowType = ETEMEnums.DataRowType.Data
            //});

            ////Total sales price with savings and discounts (EUR/ton)
            //listOfferOverview.Add(new OfferOverviewDataView()
            //{
            //    Name = "Total sales price with savings and discounts (EUR/ton)",
            //    RowKeyIntCode = "TotalSalesPriceWithSavingsAndDiscounts_EUR_TON",
            //    OfferOverviewType = "SalesPrice",
            //    Indicator_Value = listOfferOverview.FirstOrDefault(p => p.RowKeyIntCode == "TotalSalesPrice_EUR_TON").Indicator_Value *
            //                    (1 + listOfferOverview.FirstOrDefault(p => p.RowKeyIntCode == "SavingsRate").Indicator_Value / 100),
            //    RowType = ETEMEnums.DataRowType.Data
            //});

            //Target price (EUR/ton)
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Target price (EUR/ton)",
                RowKeyIntCode = "TargetPrice_EUR_TON",
                OfferOverviewType = "SalesPrice",
                Indicator_Value = offer.TargetPrice_EUR_TON.HasValue ? offer.TargetPrice_EUR_TON.Value : Decimal.Zero,
                RowType = ETEMEnums.DataRowType.Data
            });


            //Target price (EUR/ton)
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Balance (EUR/ton)",
                RowKeyIntCode = "Balance_EUR_TON",
                OfferOverviewType = "SalesPrice",
                Indicator_Value = listOfferOverview.FirstOrDefault(p => p.RowKeyIntCode == "TargetPrice_EUR_TON").Indicator_Value -
                                    listOfferOverview.FirstOrDefault(p => p.RowKeyIntCode == "TotalSalesPrice_EUR_TON").Indicator_Value,
                RowType = ETEMEnums.DataRowType.Data
            });



            try
            {
                
                //Target price (EUR/ton)
                listOfferOverview.Add(new OfferOverviewDataView()
                {
                    Name = "Balance (%)",
                    RowKeyIntCode = "Balance_Persent",
                    OfferOverviewType = "SalesPrice",
                    Indicator_Value = listOfferOverview.FirstOrDefault(p => p.RowKeyIntCode == "Balance_EUR_TON").Indicator_Value /
                                        listOfferOverview.FirstOrDefault(p => p.RowKeyIntCode == "TotalSalesPrice_EUR_TON").Indicator_Value * 100,
                    RowType = ETEMEnums.DataRowType.Data
                });
            }
            catch
            { 

                //Target price (EUR/ton)
                listOfferOverview.Add(new OfferOverviewDataView()
                {
                    Name = "Balance (%)",
                    RowKeyIntCode = "Balance_Persent",
                    OfferOverviewType = "SalesPrice",
                    Indicator_Value = Decimal.Zero,
                    RowType = ETEMEnums.DataRowType.Data
                }); 
            }
            #endregion

            #region Summary Expenses

            //Commission
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Commission",
                RowKeyIntCode = "SummaryExpensesCommission",
                OfferOverviewType = "SummaryExpenses",
                Indicator_Value = offer.Commission_EUR_Computable,
                RowType = ETEMEnums.DataRowType.Data
            }); 



            //Other material cost
            //''=(Cost of Billet Scrap, table Extrusion, tab Product cost+Material cost, table Packaging, tab Product cost+Cost of Consumed material Scrap, table Packaging, tab Product cost)*Tonnage 
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Other material cost",
                RowKeyIntCode = "Other_Material_Cost",
                OfferOverviewType = "SummaryExpenses",
                Indicator_Value = (
                                        GetPC_EUR_TON("Extrusion", "Cost_Of_Billet_Scrap") + 
                                        GetPC_EUR_TON("Packaging", "MaterialCost") +
                                        GetPC_EUR_TON("Packaging", "CostOfConsumedMaterialScrap")
                                  ) * offer.Tonnage,
                RowType = ETEMEnums.DataRowType.Data
            });

            //Variable expenses
            //'=(Direct Labour, table Extrusion, tab Product cost+Variable Expenses,  table Extrusion, tab Product cost+Direct Labour, table Packaging, tab Product cost+Variable Expenses,table 
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Variable expenses",
                RowKeyIntCode = "Variable_Expenses",
                OfferOverviewType = "SummaryExpenses",
                Indicator_Value = (
                                        GetPC_EUR_TON("Extrusion", "DirectLaborGroup") + 
                                        GetPC_EUR_TON("Extrusion", "VariableExpenses") +
                                        GetPC_EUR_TON("Packaging", "DirectLaborGroup") + 
                                        GetPC_EUR_TON("Packaging", "PackagingVariableExpenses")
                                  ) * offer.Tonnage,
                RowType = ETEMEnums.DataRowType.Data
            });

            //Fixed expenses
            //'=(Fixed Expenses,  table Extrusion, tab Product cost+Fixed Expenses,table Packaging, tab Product cost)*Tonnage (kg)/1000
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Fixed expenses",
                RowKeyIntCode = "Fixed_Expenses",
                OfferOverviewType = "SummaryExpenses",
                Indicator_Value = (
                                      GetPC_EUR_TON("Extrusion", "FixedExpenses") + 
                                      GetPC_EUR_TON("Packaging", "PackagingFixedExpenses") 
                                  ) * offer.Tonnage,
                RowType = ETEMEnums.DataRowType.Data
            });


            //Depreciation
            //'=(Depreciation, table Extrusion, tab Product cost+Depreciation,table Packaging, tab Product cost)*Tonnage (kg)/1000
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Depreciation",
                RowKeyIntCode = "Depreciation",
                OfferOverviewType = "SummaryExpenses",
               Indicator_Value = (
                                      GetPC_EUR_TON("Extrusion", "Depreciation")  + 
                                      GetPC_EUR_TON("Packaging", "PackagingDepreciation") 
                                  ) * offer.Tonnage,
                RowType = ETEMEnums.DataRowType.Data
            });

            
            //LME
            //'=LME (EUR/ton), tab Inquiry data*Tonnage (kg)/1000
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "LME",
                RowKeyIntCode = "LME",
                OfferOverviewType = "SummaryExpenses",
                Indicator_Value = offer.LME * offer.Tonnage,
                RowType = ETEMEnums.DataRowType.Data
            });

            //PREMIUM
            //'=PREMIUM (EUR/ton), tab Inquiry data*Tonnage (kg)/1000
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "PREMIUM",
                RowKeyIntCode = "PREMIUM",
                OfferOverviewType = "SummaryExpenses",
                Indicator_Value = offer.PREMIUM * offer.Tonnage,
                RowType = ETEMEnums.DataRowType.Data
            });


            
            //Production expenses
            //'=Commission+Other material cost+Variable expenses+Fixed expenses+Depreciation+LME+PREMIUM
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Production expenses",
                RowKeyIntCode = "Production_Expenses",
                OfferOverviewType = "SummaryExpenses",
                Indicator_Value = SumIndicatorValue(null, "SummaryExpensesCommission", "Other_Material_Cost", "Variable_Expenses","Fixed_Expenses","Depreciation", "LME","PREMIUM"   ) ,
                RowType = ETEMEnums.DataRowType.Total
            });

            //Administration
            //'=Commission+Other material cost+Variable expenses+Fixed expenses+Depreciation+LME+PREMIUM
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Administration",
                RowKeyIntCode = "SummaryExpensesAdministration",
                OfferOverviewType = "SummaryExpenses",
                Indicator_Value = GetPC_EUR_TON("SGAsAndFinancials", "AdministrationExpenses") *  offer.Tonnage,
                RowType = ETEMEnums.DataRowType.Data
            });

            //Selling
            //'=Sales expenses, table SGA's and Financials, tab Product cost*Tonnage (kg)/1000
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Selling",
                RowKeyIntCode = "SummaryExpensesSelling",
                OfferOverviewType = "SummaryExpenses",
                Indicator_Value = GetPC_EUR_TON("SGAsAndFinancials", "SalesExpenses") *  offer.Tonnage,
                RowType = ETEMEnums.DataRowType.Data
            });

            //Financial fixed expenses
            //'=Financial fixed expenses, table SGA's and Financials, tab Product cost*Tonnage (kg)/1000
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Financial fixed expenses",
                RowKeyIntCode = "Financial_Fixed_Expenses",
                OfferOverviewType = "SummaryExpenses",
                Indicator_Value = GetPC_EUR_TON("SGAsAndFinancials", "FinancialFixedExpenses") *  offer.Tonnage,
                RowType = ETEMEnums.DataRowType.Data
            });

            //Financial variable expenses
            //'=Financial variable expenses, table SGA's and Financials, tab Product cost*Tonnage (kg)/1000
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Financial variable expenses",
                RowKeyIntCode = "Financial_Variable_Expenses",
                OfferOverviewType = "SummaryExpenses",
               Indicator_Value = GetPC_EUR_TON("SGAsAndFinancials", "FinancialVariableExpenses") *  offer.Tonnage,
                RowType = ETEMEnums.DataRowType.Data
            });

            //Non Production expenses
            //'=Administration+Selling+Financial fixed expenses+Financial variable expenses
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Non Production expenses",
                RowKeyIntCode = "Non_Production_expenses",
                OfferOverviewType = "SummaryExpenses",
                Indicator_Value = SumIndicatorValue("SummaryExpenses", "SummaryExpensesAdministration", "SummaryExpensesSelling", "Financial_Fixed_Expenses","Financial_Variable_Expenses"   ),
                RowType = ETEMEnums.DataRowType.Total
            });


            #endregion

            #region ETEM CALCULATIONS
            //Length of final PC (mm)
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Length of final PC (mm)",
                RowKeyIntCode = "LengthOfFinalPC",
                OfferOverviewType = "EtemCalculations",
                Indicator_Value = offer.LengthOfFinalPC.HasValue ? offer.LengthOfFinalPC.Value : Decimal.Zero,
                RowType = ETEMEnums.DataRowType.Data
            });


            //Tonnage (kg)
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Tonnage (kg)",
                RowKeyIntCode = "Tonnage_KG",
                OfferOverviewType = "EtemCalculations",
                Indicator_Value = offer.Tonnage.HasValue ? offer.Tonnage.Value * 1000: Decimal.Zero,
                RowType = ETEMEnums.DataRowType.Data
            }); 

            //'=Pcs for the whole project, tab Inquiry data
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Pcs for the whole project",
                RowKeyIntCode = "PcsForTheWholeProject",
                OfferOverviewType = "EtemCalculations",
                Indicator_Value = offer.PcsForTheWholeProject.HasValue ? offer.PcsForTheWholeProject.Value : Decimal.Zero,
                RowType = ETEMEnums.DataRowType.Data
            }); 


            
            //'Price EUR/PC
            //'=Total sales price (EUR/ton)/1000*Weight per PC (kg), tab Inquiry data
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Price EUR/PC",
                RowKeyIntCode = "Price_EUR_PC",
                OfferOverviewType = "EtemCalculations",
                Indicator_Value = listOfferOverview.FirstOrDefault(p => p.RowKeyIntCode == "TotalSalesPrice_EUR_TON").Indicator_Value * 
                                  (offer.WeightPerPC.HasValue ? offer.WeightPerPC.Value : Decimal.Zero) / 1000 ,
                RowType = ETEMEnums.DataRowType.Data
            }); 


             
            //'Total cost EUR/PC (excl. SGA)
            //'=Total Cost (incl. Extrusion, Packaging, Transportation and Commission)/1000*Weight per PC (kg), tab Inquiry data
            ProductCostDataView ProductCostTotalCostExtrusionPackagingTransportationAndCommission = productCost.ListProductCosts.Where(p => p.RowKeyIntCode == "TotalCostExtrusionPackagingTransportationAndCommission").FirstOrDefault();
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Total cost EUR/PC (excl. SGA)",
                RowKeyIntCode = "Total_Cost_EUR_PC_Excl_SGA",
                OfferOverviewType = "EtemCalculations",
                Indicator_Value = ProductCostTotalCostExtrusionPackagingTransportationAndCommission.Value_EUR_PC,
                RowType = ETEMEnums.DataRowType.Data
            }); 


             //Gross (%)
            //=(Price EUR/PC-Total cost EUR/PC (excl. SGA))/Price EUR/PC*100            
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Gross (%)",
                RowKeyIntCode = "EtemCalculationsGross",
                OfferOverviewType = "EtemCalculations",
                Indicator_Value = CalcPercentByListOfferIndicator(listOfferOverview, "Price_EUR_PC", "Total_Cost_EUR_PC_Excl_SGA" ),
                RowType = ETEMEnums.DataRowType.Data
            });
 

            
            ProductCostDataView ProductCostTotalCost = productCost.ListProductCosts.Where(p => p.RowKeyIntCode == "TotalCost").FirstOrDefault();
            //Total cost EUR/PC (incl. SGA, Finance, etc.)
            //'=TOTAL COST (EUR/ton) (incl. Extrusion, Packaging, Transportation and Commission, SGA's and Financials), tab Product cost/1000*Weight per PC (kg), tab Inquiry data    
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Total cost EUR/PC (incl. SGA, Finance, etc.)",
                RowKeyIntCode = "TotalCost_EUR_PC_incl_SGA_Finance_etc",
                OfferOverviewType = "EtemCalculations",
                Indicator_Value = ProductCostTotalCost.Value_EUR_PC,
                RowType = ETEMEnums.DataRowType.Data
            });


            //Net Profit (%)
            //'=(Price EUR/PC-Total cost EUR/PC (+SGA, Finance, etc))/Price EUR/PC*100

           

            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Net Profit (%)",
                RowKeyIntCode = "Net_Profit_Percent_PC",
                OfferOverviewType = "EtemCalculations",
                Indicator_Value = CalcPercentByListOfferIndicator(listOfferOverview, "Price_EUR_PC","TotalCost_EUR_PC_incl_SGA_Finance_etc"),
                RowType = ETEMEnums.DataRowType.Data
            });
        

             Decimal price_EUR_PC   = listOfferOverview.FirstOrDefault(p => p.RowKeyIntCode == "Price_EUR_PC").Indicator_Value.HasValue?listOfferOverview.FirstOrDefault(p => p.RowKeyIntCode == "Price_EUR_PC").Indicator_Value.Value:Decimal.Zero;
            //Turnover (EUR)
            //'=Price EUR/PC*Pcs for the whole project
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Turnover (EUR)",
                RowKeyIntCode = "Turnover_EUR",
                OfferOverviewType = "EtemCalculations",
                Indicator_Value = price_EUR_PC * offer.PcsForTheWholeProject,
                RowType = ETEMEnums.DataRowType.Data
            });

             
            //Total cost (EUR) (excl. SGA)
            //Total cost EUR/PC (excl. SGA)*Pcs for the whole project
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Total cost (EUR) (excl. SGA)",
                RowKeyIntCode = "Total_Cost_EUR_excl_SGA",
                OfferOverviewType = "EtemCalculations",
                Indicator_Value =  listOfferOverview.FirstOrDefault(p => p.RowKeyIntCode == "Total_Cost_EUR_PC_Excl_SGA").Indicator_Value * offer.PcsForTheWholeProject,
                RowType = ETEMEnums.DataRowType.Data
            });


             
            //Gross (%)
            //'=(Turnover (EUR)-Total cost (EUR) (excl. SGA))/Turnover (EUR)*100
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Gross (%)",
                RowKeyIntCode = "EtemCalculationsGrossTurnover",
                OfferOverviewType = "EtemCalculations",
                Indicator_Value = CalcPercentByListOfferIndicator(listOfferOverview, "Turnover_EUR","Total_Cost_EUR_excl_SGA" ),
                RowType = ETEMEnums.DataRowType.Data
            });

            //Total cost EUR (incl. SGA, Finance, etc.)
            //Total cost EUR/PC (incl. SGA, Finance, etc.)*Pcs for the whole project
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Total cost EUR (incl. SGA, Finance, etc.)",
                RowKeyIntCode = "TotalCost_EUR_PC_incl_SGA_Finance_etc_PcsForTheWholeProject",
                OfferOverviewType = "EtemCalculations",
                Indicator_Value = listOfferOverview.FirstOrDefault(p => p.RowKeyIntCode == "TotalCost_EUR_PC_incl_SGA_Finance_etc").Indicator_Value * offer.PcsForTheWholeProject,
                RowType = ETEMEnums.DataRowType.Data
            });


            //Net profit (EUR)
            //'=Turnover (EUR)-Total cost EUR (incl. SGA, Finance, etc.)
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Net profit (EUR)",
                RowKeyIntCode = "Net_profit_EUR",
                OfferOverviewType = "EtemCalculations",
                Indicator_Value = listOfferOverview.FirstOrDefault(p => p.RowKeyIntCode == "Turnover_EUR").Indicator_Value - 
                                  listOfferOverview.FirstOrDefault(p => p.RowKeyIntCode == "TotalCost_EUR_PC_incl_SGA_Finance_etc_PcsForTheWholeProject").Indicator_Value,
                RowType = ETEMEnums.DataRowType.Data
            });


            //Net profit (%)
            //'=(Turnover (EUR)-Total cost EUR (incl. SGA, Finance, etc.))/Turnover (EUR)*100
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Net profit (%)",
                RowKeyIntCode = "Net_Profit_Percent_Turnover",
                OfferOverviewType = "EtemCalculations",
                Indicator_Value = CalcPercentByListOfferIndicator(listOfferOverview, "Turnover_EUR","TotalCost_EUR_PC_incl_SGA_Finance_etc_PcsForTheWholeProject") ,
                RowType = ETEMEnums.DataRowType.Data
            });



            //Conversion (EUR)
            //'=Sales conversion (EUR/ton)/1000*Tonnage (kg)
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Conversion (EUR)",
                RowKeyIntCode = "ConversionTonnage",
                OfferOverviewType = "EtemCalculations",
                Indicator_Value = listOfferOverview.FirstOrDefault(p => p.RowKeyIntCode == "SalesConversion_EUR_TON").Indicator_Value / 1000 * 
                                  listOfferOverview.FirstOrDefault(p => p.RowKeyIntCode == "Tonnage_KG").Indicator_Value,
                RowType = ETEMEnums.DataRowType.Data
            });


            //Net Conversion  (EUR)
            //=Conversion (EUR)-Non Production expenses
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Net Conversion  (EUR)",
                RowKeyIntCode = "Net_Conversion_EUR",
                OfferOverviewType = "EtemCalculations",
                Indicator_Value = SumIndicatorValue("EtemCalculations", "ConversionTonnage") - SumIndicatorValue("SummaryExpenses", "Non_Production_expenses"),
                RowType = ETEMEnums.DataRowType.Data
            });

            //Contribution margin (EUR)
            //'=Turnover (EUR)-Production expenses+Fixed expenses
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "Contribution margin (EUR)",
                RowKeyIntCode = "Contribution_Margin_EUR",
                OfferOverviewType = "EtemCalculations",
                Indicator_Value =   SumIndicatorValue("EtemCalculations", "Turnover_EUR") +                                    
                                    SumIndicatorValue("SummaryExpenses", "Fixed_Expenses") -
                                    SumIndicatorValue("SummaryExpenses", "Production_Expenses") ,
                RowType = ETEMEnums.DataRowType.Data
            });



            try
            {
                
                //Marginal Contribution (%)
                //'=Contribution margin (EUR)/Turnover (EUR)*100
                listOfferOverview.Add(new OfferOverviewDataView()
                {
                    Name = "Marginal Contribution (%)",
                    RowKeyIntCode = "Marginal_Contribution_Percent",
                    OfferOverviewType = "EtemCalculations",
                    Indicator_Value = SumIndicatorValue("EtemCalculations", "Contribution_Margin_EUR") /  SumIndicatorValue("EtemCalculations", "Turnover_EUR") * 100,
                    RowType = ETEMEnums.DataRowType.Data
                });
            }
            catch
            {
                
                //Marginal Contribution (%)
                //'=Contribution margin (EUR)/Turnover (EUR)*100
                listOfferOverview.Add(new OfferOverviewDataView()
                {
                    Name = "Marginal Contribution (%)",
                    RowKeyIntCode = "Marginal_Contribution_Percent",
                    OfferOverviewType = "EtemCalculations",
                    Indicator_Value = Decimal.Zero,
                    RowType = ETEMEnums.DataRowType.Data
                });
            }
             //EBITDA
            //'=Net profit (EUR)+Financial fixed expenses+Financial variable expenses+Depreciation
            listOfferOverview.Add(new OfferOverviewDataView()
            {
                Name = "EBITDA (EUR)",
                RowKeyIntCode = "EBITDA",
                OfferOverviewType = "EtemCalculations",
                Indicator_Value = SumIndicatorValue("EtemCalculations", "Net_profit_EUR") + 
                                  SumIndicatorValue("SummaryExpenses", "Financial_Fixed_Expenses", "Financial_Variable_Expenses", "Depreciation"),
                RowType = ETEMEnums.DataRowType.Data
            });


            #endregion

            result.ListOfferOverview.AddRange(listOfferOverview);

            return result;
           
        }