public IList GetSupplierInvoiceItem(int partID)
        {
            MySql.Data.MySqlClient.MySqlDataReader rdr;
            Part      p      = PartRepository.GetByID(m_command, partID);
            ArrayList result = new ArrayList();

            m_command.CommandText = SupplierInvoiceItem.GetByPartIDOrderByDateSQL(partID);
            rdr = m_command.ExecuteReader();
            IList piis = SupplierInvoiceItem.TransformReaderList(rdr);

            rdr.Close();
            foreach (SupplierInvoiceItem itm in piis)
            {
                itm.EVENT = SupplierInvoiceRepository.GetHeaderOnly(m_command, itm.EVENT.ID);
                itm.PART  = p;
                result.Add(itm);
            }

            m_command.CommandText = StockTakingItems.GetByPartIDOrderByDateSQL(partID);
            rdr = m_command.ExecuteReader();
            IList sti = StockTakingItems.TransformReaderList(rdr);

            rdr.Close();
            foreach (StockTakingItems itm in sti)
            {
                itm.EVENT = StockTakingRepository.GetHeaderOnly(m_command, itm.EVENT.ID);
                itm.PART  = p;
                result.Add(itm);
            }

            m_command.CommandText = OpeningStockItem.GetByPartIDOrderByDateSQL(partID);
            rdr = m_command.ExecuteReader();
            IList opi = OpeningStockItem.TransformReaderList(rdr);

            rdr.Close();
            foreach (OpeningStockItem itm in opi)
            {
                itm.EVENT = OpeningStockRepository.GetHeaderOnly(m_command, itm.EVENT.ID);
                itm.PART  = p;
                result.Add(itm);
            }

            result.Sort(new Profit.Server.PartRepository.EventDateComparer());
            return(result);
        }
示例#2
0
        public static double GetLatestPriceMovementItemPeriod(MySql.Data.MySqlClient.MySqlCommand m_command,
                                                              int partID, DateTime start, DateTime end)
        {
            MySql.Data.MySqlClient.MySqlDataReader rdr;
            Part      p      = PartRepository.GetByID(m_command, partID);
            ArrayList result = new ArrayList();

            m_command.CommandText = SupplierInvoiceItem.GetByPartIDOrderByDateRangeSQL(partID, start, end);
            rdr = m_command.ExecuteReader();
            IList piis = SupplierInvoiceItem.TransformReaderList(rdr);

            rdr.Close();
            foreach (SupplierInvoiceItem itm in piis)
            {
                itm.EVENT = SupplierInvoiceRepository.GetHeaderOnly(m_command, itm.EVENT.ID);
                itm.PART  = p;
                result.Add(itm);
            }

            m_command.CommandText = StockTakingItems.GetByPartIDOrderByDateSQL(partID);
            rdr = m_command.ExecuteReader();
            IList sti = StockTakingItems.TransformReaderList(rdr);

            rdr.Close();
            foreach (StockTakingItems itm in sti)
            {
                itm.EVENT = StockTakingRepository.GetHeaderOnly(m_command, itm.EVENT.ID);
                itm.PART  = p;
                result.Add(itm);
            }

            m_command.CommandText = OpeningStockItem.GetByPartIDOrderByDateSQL(partID);
            rdr = m_command.ExecuteReader();
            IList opi = OpeningStockItem.TransformReaderList(rdr);

            rdr.Close();
            foreach (OpeningStockItem itm in opi)
            {
                itm.EVENT = OpeningStockRepository.GetHeaderOnly(m_command, itm.EVENT.ID);
                itm.PART  = p;
                result.Add(itm);
            }
            result.Sort(new Profit.Server.PartRepository.EventDateComparer());

            double   average      = 0;
            double   price        = 0;
            double   priceBaseCcy = 0;
            Currency baseccy      = CurrencyRepository.GetBaseCurrency(m_command);

            for (int i = 0; i < result.Count; i++)
            {
                if (result[i] is OpeningStockItem)
                {
                    price = ((OpeningStockItem)result[i]).TOTAL_AMOUNT / ((OpeningStockItem)result[i]).GetAmountInSmallestUnit();
                    if (baseccy.ID == ((OpeningStock)((OpeningStockItem)result[i]).EVENT).CURRENCY.ID)
                    {
                        priceBaseCcy = price;
                    }
                    else
                    {
                        priceBaseCcy = CurrencyRepository.ConvertToBaseCurrency(m_command, ((OpeningStock)((OpeningStockItem)result[i]).EVENT).CURRENCY, price, DateTime.Today);
                    }
                }
                if (result[i] is StockTakingItems)
                {
                    price = ((StockTakingItems)result[i]).TOTAL_AMOUNT / ((StockTakingItems)result[i]).GetAmountInSmallestUnit();
                    if (baseccy.ID == ((StockTaking)((StockTakingItems)result[i]).EVENT).CURRENCY.ID)
                    {
                        priceBaseCcy = price;
                    }
                    else
                    {
                        priceBaseCcy = CurrencyRepository.ConvertToBaseCurrency(m_command, ((StockTaking)((StockTakingItems)result[i]).EVENT).CURRENCY, price, DateTime.Today);
                    }
                }
                if (result[i] is SupplierInvoiceItem)
                {
                    price = ((SupplierInvoiceItem)result[i]).SUBTOTAL / ((SupplierInvoiceItem)result[i]).GetAmountInSmallestUnit();
                    if (baseccy.ID == ((SupplierInvoice)((SupplierInvoiceItem)result[i]).EVENT).CURRENCY.ID)
                    {
                        priceBaseCcy = price;
                    }
                    else
                    {
                        priceBaseCcy = CurrencyRepository.ConvertToBaseCurrency(m_command, ((SupplierInvoice)((SupplierInvoiceItem)result[i]).EVENT).CURRENCY, price, DateTime.Today);
                    }
                }
                if (i == 0)
                {
                    average = priceBaseCcy;
                }
                else
                {
                    average = (average + priceBaseCcy) / 2;
                }
            }

            return(average < 0 ? -average : average);
        }