private void GetBeginningInventorySummary()
        {
            DataTable p_count_result = new DataTable();
            try
            {
                List<SOI_BeginningInventory> SOI_BI;
                Image image_outlet = new Image();
                image_outlet = (Image)gvOutlets.SelectedRow.FindControl("imgOutlet");
                long customerNumber = long.Parse(image_outlet.AlternateText);
                StoreOutStandingInventory SOI = SOIManager.IsHasSOIRecord(long.Parse(image_outlet.AlternateText));
                if (SOI != null)
                {
                    txtBeginningInventoryValue.Text = SOI.ActualCountValue.ToString("###,###.00");
                    txtBeginningInventoryVolume.Text = SOI.ActualCountVolume.ToString();
                    txtBeginningInventoryTotalCost.Text = SOI.ActualCostTotalCost.ToString("###,###.00");
                    txtBeginningInventoryAvgCost.Text = SOI.ActualCountAverageCost.ToString("###,###.00");
                    SOI_BI = new List<SOI_BeginningInventory>();

                    SOI_BeginningInventory SOIBI = new SOI_BeginningInventory
                    {
                        Volume = decimal.Parse(txtBeginningInventoryVolume.Text),
                        Value = decimal.Parse(txtBeginningInventoryValue.Text),
                        AverageCost = decimal.Parse(txtBeginningInventoryAvgCost.Text),
                        TotalCost = decimal.Parse(txtActualAccountTotalCost.Text)
                    };
                    SOI_BI.Add(SOIBI);
                    gvSOIBI.DataSource = SOI_BI;
                    gvSOIBI.DataBind();
                    lblBIFrom.Text = "Beginning Inventory from Previous SOI";
                }
                else
                {
                    List<SOI_BeginningInventory> SOI_PCOUNT= new List<SOI_BeginningInventory>();
                    DateTime dtPeriodFrom = new DateTime(DateTime.Parse(txtPeriodTo.Text).Year,
                        DateTime.Parse(txtPeriodFrom.Text).Month, 1);
                    DateTime dtPeriodToTemp = DateTime.Parse(txtPeriodFrom.Text);
                    DateTime dtPeriodTo = new DateTime(dtPeriodToTemp.Year, dtPeriodToTemp.Month,
                        DateTime.DaysInMonth(dtPeriodToTemp.Year, dtPeriodToTemp.Month));

                    if (dtPeriodToTemp.Month == 12 && dtPeriodToTemp.Day == 31) // ENDING YEAR
                    {
                        dtPeriodFrom = new DateTime(dtPeriodToTemp.Year + 1, 1, 1);
                        dtPeriodTo = new DateTime(dtPeriodToTemp.Year + 1, 1, DateTime.DaysInMonth(dtPeriodToTemp.Year, 1));
                    }

                    //DataTable physical_count = SOIManager.GetDataTableStoreOutStandingInventoryPhysiclCountSummary1(
                    //                     long.Parse(image_outlet.AlternateText), dtPeriodFrom, dtPeriodTo); year to year pick up change
                    DataTable physical_count = new DataTable();
                    if ((DateTime.Parse(txtPeriodTo.Text).Month - DateTime.Parse(txtPeriodFrom.Text).Month)==11)
                    {
                        dtPeriodFrom = new DateTime(DateTime.Parse(txtPeriodFrom.Text).Year -1,12,31);
                         physical_count = SOIManager.GetDataTableStoreOutStandingInventoryPhysiclCountSummary1(
                                        customerNumber, dtPeriodFrom, dtPeriodTo);
                    }
                    else
                    {

                         physical_count = SOIManager.GetDataTableStoreOutStandingInventoryPhysiclCountSummary1(
                                             customerNumber, dtPeriodFrom, dtPeriodTo);
                    }

                    if (physical_count.Rows.Count >0)
                    {
                        p_count_result = physical_count;
                    }
                    else
                    {
                        dtPeriodFrom = new DateTime(dtPeriodFrom.Year - 1, 12, 1);
                        p_count_result = SOIManager.GetDataTableStoreOutStandingInventoryPhysiclCountSummary1(
                                          customerNumber, dtPeriodFrom, dtPeriodTo);
                    }
                    foreach (DataRow row in p_count_result.Rows)
                    {
                        SOI_BeginningInventory PCOUNT = new SOI_BeginningInventory();
                        PCOUNT.Volume = decimal.Parse(row[1].ToString());
                        PCOUNT.Value = decimal.Parse(row[0].ToString());
                        PCOUNT.TotalCost = decimal.Parse(row[2].ToString());
                        PCOUNT.AverageCost = (decimal.Parse(row[2].ToString()) / decimal.Parse(row[1].ToString()));
                        SOI_PCOUNT.Add(PCOUNT);
                    }
                    SOI_BeginningInventory BI = SOI_PCOUNT[0];
                    if (SOI_PCOUNT.Count>1)
                    {
                        SOI_BeginningInventory EI = SOI_PCOUNT[1];
                        hfPCountAveCost.Value = EI.AverageCost.ToString("###,###.00");
                        hfPcountTotalCost.Value = EI.TotalCost.ToString("###,###.00");
                        hfPCountValue.Value = EI.Value.ToString("###,###.00");
                        hfPCountVolume.Value = EI.Volume.ToString();
                    }

                    txtBeginningInventoryValue.Text = BI.Value.ToString("###,###.00");
                    txtBeginningInventoryVolume.Text = BI.Volume.ToString();

                    txtBeginningInventoryTotalCost.Text = BI.TotalCost.ToString("###,###.00");
                    txtBeginningInventoryAvgCost.Text = BI.AverageCost.ToString("###,###.00");

                    DataTable pcount_breakdown = SOIManager.GetDataTableStoreOutStandingInventoryPhysicalCountBreakdown(
                        long.Parse(image_outlet.AlternateText), DateTime.Parse(txtPeriodFrom.Text));
                    gvSOIBI.DataSource = pcount_breakdown;
                    gvSOIBI.DataBind();
                    lblBIFrom.Text = "Beginning Inventory from Bridge Table";
                }

            }
            catch (Exception)
            {
                txtBeginningInventoryValue.Text = "0.00";
                txtBeginningInventoryVolume.Text = "0";
                this.txtBeginningInventoryTotalCost.Text = "0.00";
                txtBeginningInventoryAvgCost.Text = "0.00";
            }
        }
        private void GetPhysicalCountSummary()
        {
            try
            {
                {
                    List<SOI_BeginningInventory> SOI_PCOUNT = new List<SOI_BeginningInventory>();
                    DateTime dtPeriodFrom = new DateTime(DateTime.Parse(txtCutOffDate.Text).Year,
                     DateTime.Parse(this.txtInventoryDate.Text).Month, 1);
                    DateTime dtPeriodToTemp = DateTime.Parse(txtInventoryDate.Text);
                    DateTime dtPeriodTo = new DateTime(dtPeriodToTemp.Year, dtPeriodToTemp.Month,
                        DateTime.DaysInMonth(dtPeriodToTemp.Year, dtPeriodToTemp.Month));

                    if (dtPeriodToTemp.Month == 12 && dtPeriodToTemp.Day == 31) // ENDING YEAR
                    {
                        dtPeriodFrom = new DateTime(dtPeriodToTemp.Year + 1, 1, 1);
                        dtPeriodTo = new DateTime(dtPeriodToTemp.Year + 1, 1, DateTime.DaysInMonth(dtPeriodToTemp.Year, 1));
                    }
                    DataTable physical_count = SOIManager.GetDataTableStoreOutStandingInventoryPhysiclCountSummary1(
                                          long.Parse(hfOutletNumber.Value), dtPeriodFrom, dtPeriodTo);
                    foreach (DataRow row in physical_count.Rows)
                    {
                        SOI_BeginningInventory PCOUNT = new SOI_BeginningInventory();
                        PCOUNT.Volume = decimal.Parse(row[1].ToString());
                        PCOUNT.Value = decimal.Parse(row[0].ToString());
                        PCOUNT.TotalCost = decimal.Parse(row[2].ToString());
                        PCOUNT.AverageCost = (decimal.Parse(row[2].ToString()) / decimal.Parse(row[1].ToString()));
                        SOI_PCOUNT.Add(PCOUNT);
                    }
                    SOI_BeginningInventory BI = SOI_PCOUNT[0];
                    SOI_BeginningInventory EI = SOI_PCOUNT[1];

                    txtActualPhysicalPriceCostPrice.Text = EI.TotalCost.ToString("###,###.00");
                    txtActualPhysicalCountCurrentPrice.Text = EI.Value.ToString("###,###.00");
                    txtActualPhysicalCountQuantity.Text = EI.Volume.ToString();
                }

            }
            catch (Exception)
            {
                txtActualPhysicalCountCurrentPrice.Text = "0.00";
                txtActualPhysicalCountQuantity.Text = "0";
                txtActualPhysicalPriceCostPrice.Text = "0.00";
            }
            //try
            //{
            //    // 20120316 CTS
            //    DateTime dtPeriodFrom = new DateTime(DateTime.Parse(txtCutOffDate.Text).Year, DateTime.Parse(txtCutOffDate.Text).Month, 1);
            //    DateTime dtPeriodToTemp = DateTime.Parse(txtCutOffDate.Text);
            //    DateTime dtPeriodTo = new DateTime(dtPeriodToTemp.Year, dtPeriodToTemp.Month, DateTime.DaysInMonth(dtPeriodToTemp.Year, dtPeriodToTemp.Month));

            //    if (dtPeriodToTemp.Month == 12 && dtPeriodToTemp.Day == 31) // ENDING YEAR
            //    {
            //        dtPeriodFrom = new DateTime(dtPeriodToTemp.Year + 1, 1, 1);
            //        dtPeriodTo = new DateTime(dtPeriodToTemp.Year + 1, 1, DateTime.DaysInMonth(dtPeriodToTemp.Year, 1));
            //    }

            //    //DataTable physical_count = SOIManager.GetDataTableStoreOutStandingInventoryPhysiclCountSummary(long.Parse(hfOutletNumber.Value),DateTime.Parse( txtInventoryDate.Text),DateTime.Parse(txtCutOffDate .Text ));
            //    DataTable physical_count = SOIManager.GetDataTableStoreOutStandingInventoryPhysiclCountSummary(long.Parse(hfOutletNumber.Value), dtPeriodFrom, dtPeriodTo);
            //    // 20120316 CTS

            //    foreach (DataRow row in physical_count.Rows)
            //    {
            //        txtActualPhysicalCountCurrentPrice.Text = row[0].ToString();
            //        txtActualPhysicalCountQuantity.Text = row[1].ToString();
            //        txtActualPhysicalPriceCostPrice.Text = row[2].ToString();
            //    }
            //    if (txtActualPhysicalCountCurrentPrice.Text == string.Empty)
            //    {
            //        txtActualPhysicalCountCurrentPrice.Text = "0.00";
            //        txtActualPhysicalCountQuantity.Text = "0";
            //        txtActualPhysicalPriceCostPrice.Text = "0.00";
            //    }
            //}
            //catch (Exception)
            //{
            //    txtActualPhysicalCountCurrentPrice.Text = "0.00";
            //    txtActualPhysicalCountQuantity.Text = "0";
            //    txtActualPhysicalPriceCostPrice.Text = "0.00";
            //}
        }