Exemplo n.º 1
0
        //============================================================================*
        // SetTransactionData()
        //============================================================================*

        public void SetTransactionData(ListViewItem Item, cTransaction Transaction)
        {
            Item.SubItems.Clear();

            if (Transaction.TransactionType == cTransaction.eTransactionType.SetStockLevel)
            {
                Item.Text = "";
            }
            else
            {
                Item.Text = Transaction.Date.ToShortDateString();
            }

            if (Transaction.Archived)
            {
                Item.Text += " - Archived";
            }

            Item.Checked = Transaction.Checked;

            Item.Tag = Transaction;

            if (Transaction.TransactionType == cTransaction.eTransactionType.SetStockLevel)
            {
                Transaction.Source = "";
            }

            if (Transaction.BatchID != 0)
            {
                Transaction.Source = String.Format("Batch {0:G0}", Transaction.BatchID);
            }

            Item.SubItems.Add(cTransaction.TransactionDescriptionString(Transaction.TransactionType));
            Item.SubItems.Add(Transaction.Source);

            double dQuantity = Transaction.Quantity;

            switch (Transaction.Supply.SupplyType)
            {
            case cSupply.eSupplyTypes.Ammo:
            case cSupply.eSupplyTypes.Bullets:
            case cSupply.eSupplyTypes.Cases:
            case cSupply.eSupplyTypes.Primers:
                Item.SubItems.Add(String.Format("{0:N0}", dQuantity));
                break;

            case cSupply.eSupplyTypes.Powder:
                dQuantity = cDataFiles.StandardToMetric(dQuantity / 7000.0, cDataFiles.eDataType.CanWeight);

                Item.SubItems.Add(String.Format("{0:F3}", dQuantity));

                break;
            }

            double dCostEach = m_DataFiles.SupplyCostEach(Transaction.Supply);

            double dCost = 0.0;

            if (Transaction.BatchID != 0)
            {
                if (Transaction.Supply.SupplyType == cSupply.eSupplyTypes.Ammo)
                {
                    dCost = m_DataFiles.BatchCost(Transaction.BatchID);
                }
                else
                {
                    dCost = Transaction.Quantity * dCostEach;
                }
            }
            else
            {
                dCost = Transaction.Cost;
            }

            Item.SubItems.Add(String.Format("{0:F2}", dCost));

            if (Transaction.BatchID == 0 &&
                (Transaction.TransactionType == cTransaction.eTransactionType.Purchase ||
                 Transaction.TransactionType == cTransaction.eTransactionType.SetStockLevel))
            {
                Item.SubItems.Add(Transaction.Tax != 0.0 ? String.Format("{0:F2}", Transaction.Tax) : "-");
                Item.SubItems.Add(Transaction.Shipping != 0.0 ? String.Format("{0:F2}", Transaction.Shipping) : "-");
            }
            else
            {
                Item.SubItems.Add("-");
                Item.SubItems.Add("-");
            }

            Item.SubItems.Add(String.Format("{0:F2}", dCost + Transaction.Tax + Transaction.Shipping));

            if (Transaction.TransactionType == cTransaction.eTransactionType.Purchase ||
                Transaction.TransactionType == cTransaction.eTransactionType.SetStockLevel)
            {
                if (m_DataFiles.Preferences.IncludeTaxShipping)
                {
                    dCost += (Transaction.Tax + Transaction.Shipping);
                }

                dCostEach = 0.0;

                if (dQuantity > 0.0)
                {
                    dCostEach = dCost / dQuantity;
                }

                Item.SubItems.Add(String.Format("{0:F2}", dCostEach));
            }
            else
            {
                Item.SubItems.Add("-");
            }
        }
        //============================================================================*
        // SupplyTotals()
        //============================================================================*

        public cCostAnalysisSupplyTotals SupplyTotals(cSupply Supply)
        {
            cCostAnalysisSupplyTotals SupplyTotals = new cCostAnalysisSupplyTotals();

            SupplyTotals.InStockQty   += m_DataFiles.SupplyQuantity(Supply);
            SupplyTotals.InStockTotal += m_DataFiles.SupplyCost(Supply);

            //----------------------------------------------------------------------------*
            // Loop through the supply transactions
            //----------------------------------------------------------------------------*

            foreach (cTransaction Transaction in Supply.TransactionList)
            {
                //----------------------------------------------------------------------------*
                // See if this transaction meets the filter criteria
                //----------------------------------------------------------------------------*

                if (IncludeTransaction(Transaction))
                {
                    //----------------------------------------------------------------------------*
                    // Add to the overall totals
                    //----------------------------------------------------------------------------*

                    SupplyTotals.NumTransactions++;

                    //----------------------------------------------------------------------------*
                    // Determine the Transaction type
                    //----------------------------------------------------------------------------*

                    switch (Transaction.TransactionType)
                    {
                    //----------------------------------------------------------------------------*
                    // Purchase
                    //----------------------------------------------------------------------------*

                    case cTransaction.eTransactionType.Purchase:
                        SupplyTotals.NumPurchases++;
                        SupplyTotals.PurchaseQty   += Transaction.Quantity;
                        SupplyTotals.PurchaseTotal += Transaction.Cost;

                        if (m_DataFiles.Preferences.IncludeTaxShipping)
                        {
                            SupplyTotals.PurchaseTotal += (Transaction.Tax + Transaction.Shipping);
                        }

                        break;

                    //----------------------------------------------------------------------------*
                    // SetStockLevel
                    //----------------------------------------------------------------------------*

                    case cTransaction.eTransactionType.SetStockLevel:
                        if (Supply.SupplyType != cSupply.eSupplyTypes.Ammo || Transaction.BatchID == 0)
                        {
                            SupplyTotals.NumInitialStock++;
                            SupplyTotals.InitialStockQty   += Transaction.Quantity;
                            SupplyTotals.InitialStockTotal += Transaction.Cost;

                            if (m_DataFiles.Preferences.IncludeTaxShipping)
                            {
                                SupplyTotals.InitialStockTotal += (Transaction.Tax + Transaction.Shipping);
                            }
                        }
                        else
                        {
                            SupplyTotals.NumInitialStock++;
                            SupplyTotals.InitialStockQty   += Transaction.Quantity;
                            SupplyTotals.InitialStockTotal += m_DataFiles.BatchCost(Transaction.BatchID);
                        }

                        break;

                    //----------------------------------------------------------------------------*
                    // AddStock
                    //----------------------------------------------------------------------------*

                    case cTransaction.eTransactionType.AddStock:
                        SupplyTotals.NumAdjustments++;
                        SupplyTotals.AdjustmentsQty   += Transaction.Quantity;
                        SupplyTotals.AdjustmentsTotal += Transaction.Cost;

                        if (m_DataFiles.Preferences.IncludeTaxShipping)
                        {
                            SupplyTotals.AdjustmentsTotal += (Transaction.Tax + Transaction.Shipping);
                        }

                        break;

                    //----------------------------------------------------------------------------*
                    // ReduceStock
                    //----------------------------------------------------------------------------*

                    case cTransaction.eTransactionType.ReduceStock:
                        if (Supply.SupplyType == cSupply.eSupplyTypes.Ammo)
                        {
                            SupplyTotals.NumAdjustments++;
                            SupplyTotals.AdjustmentsQty   -= Transaction.Quantity;
                            SupplyTotals.AdjustmentsTotal -= Transaction.Cost;
                        }
                        else
                        {
                            if (Transaction.BatchID == 0)
                            {
                                SupplyTotals.NumAdjustments++;
                                SupplyTotals.AdjustmentsQty   -= Transaction.Quantity;
                                SupplyTotals.AdjustmentsTotal -= Transaction.Cost;
                            }
                            else
                            {
                                SupplyTotals.NumUsed++;

                                switch (Supply.SupplyType)
                                {
                                case cSupply.eSupplyTypes.Bullets:
                                    SupplyTotals.UsedQty   -= Transaction.Quantity;
                                    SupplyTotals.UsedTotal -= m_DataFiles.BatchBulletCost(Transaction.BatchID);
                                    break;

                                case cSupply.eSupplyTypes.Cases:
                                    SupplyTotals.UsedQty   -= Transaction.Quantity;
                                    SupplyTotals.UsedTotal -= m_DataFiles.BatchCaseCost(Transaction.BatchID);
                                    break;

                                case cSupply.eSupplyTypes.Powder:
                                    SupplyTotals.UsedQty   -= Transaction.Quantity;
                                    SupplyTotals.UsedTotal -= m_DataFiles.BatchPowderCost(Transaction.BatchID);
                                    break;

                                case cSupply.eSupplyTypes.Primers:
                                    SupplyTotals.UsedQty   -= Transaction.Quantity;
                                    SupplyTotals.UsedTotal -= m_DataFiles.BatchPrimerCost(Transaction.BatchID);
                                    break;
                                }
                            }
                        }

                        break;

                    //----------------------------------------------------------------------------*
                    // Fired
                    //----------------------------------------------------------------------------*

                    case cTransaction.eTransactionType.Fired:
                        SupplyTotals.NumFired++;

                        SupplyTotals.FiredQty   += Transaction.Quantity;
                        SupplyTotals.FiredTotal += Transaction.Cost;

                        break;
                    }
                }
            }

            if (Supply.SupplyType == cSupply.eSupplyTypes.Powder)
            {
                SupplyTotals.AdjustmentsQty  /= 7000.0;
                SupplyTotals.FiredQty        /= 7000.0;
                SupplyTotals.InitialStockQty /= 7000.0;
                SupplyTotals.InStockQty      /= 7000.0;
                SupplyTotals.PurchaseQty     /= 7000.0;
                SupplyTotals.UsedQty         /= 7000.0;

                SupplyTotals.AdjustmentsQty  = cDataFiles.StandardToMetric(SupplyTotals.AdjustmentsQty, cDataFiles.eDataType.CanWeight);
                SupplyTotals.FiredQty        = cDataFiles.StandardToMetric(SupplyTotals.FiredQty, cDataFiles.eDataType.CanWeight);
                SupplyTotals.InitialStockQty = cDataFiles.StandardToMetric(SupplyTotals.InitialStockQty, cDataFiles.eDataType.CanWeight);
                SupplyTotals.InStockQty      = cDataFiles.StandardToMetric(SupplyTotals.InStockQty, cDataFiles.eDataType.CanWeight);
                SupplyTotals.PurchaseQty     = cDataFiles.StandardToMetric(SupplyTotals.PurchaseQty, cDataFiles.eDataType.CanWeight);
                SupplyTotals.UsedQty         = cDataFiles.StandardToMetric(SupplyTotals.UsedQty, cDataFiles.eDataType.CanWeight);
            }

            return(SupplyTotals);
        }