private static void AddPurchaseReturnTransactionLineToDatabaseContext(ERPContext context, PurchaseReturnTransactionLine purchaseReturnTransactionLine)
 {
     purchaseReturnTransactionLine.Item = context.Inventory.Single(item => item.ID.Equals(purchaseReturnTransactionLine.Item.ID));
     purchaseReturnTransactionLine.Warehouse = context.Warehouses.Single(warehouse => warehouse.ID.Equals(purchaseReturnTransactionLine.Warehouse.ID));
     purchaseReturnTransactionLine.ReturnWarehouse = context.Warehouses.Single(warehouse => warehouse.ID.Equals(purchaseReturnTransactionLine.ReturnWarehouse.ID));
     context.PurchaseReturnTransactionLines.Add(purchaseReturnTransactionLine);
 }
 private static bool IsThereEnoughLineItemStockInDatabaseContext(ERPContext context, PurchaseReturnTransactionLine purchaseReturnTransactionLine)
 {
     var stockFromDatabase = context.Stocks.SingleOrDefault(
         stock => stock.Item.ID.Equals(purchaseReturnTransactionLine.Item.ID) &&
         stock.Warehouse.ID.Equals(purchaseReturnTransactionLine.ReturnWarehouse.ID));
     if (stockFromDatabase != null && stockFromDatabase.Pieces >= purchaseReturnTransactionLine.Quantity)
         return true;
     var availableQuantity = stockFromDatabase?.Pieces ?? 0;
     MessageBox.Show(
         $"{purchaseReturnTransactionLine.Item.Name} has only {availableQuantity} left.",
         "Invalid Quantity", MessageBoxButton.OK);
     return false;
 }
        private static decimal CalculateLineCOGSFromDatabaseContext(ERPContext context, PurchaseReturnTransactionLine purchaseReturnTransactionLine)
        {
            var purchaseTransactionLine = context.PurchaseTransactionLines
            .Single(
                line => line.PurchaseTransactionID.Equals(purchaseReturnTransactionLine.PurchaseReturnTransaction.PurchaseTransaction.PurchaseID) &&
                line.ItemID.Equals(purchaseReturnTransactionLine.Item.ID) && line.WarehouseID.Equals(purchaseReturnTransactionLine.Warehouse.ID) &&
                line.PurchasePrice.Equals(purchaseReturnTransactionLine.PurchasePrice) && line.Discount.Equals(purchaseReturnTransactionLine.Discount));

            var purchaseLineNetTotal = purchaseTransactionLine.PurchasePrice - purchaseTransactionLine.Discount;
            if (purchaseLineNetTotal == 0) return 0;
            var fractionOfTransactionDiscount = purchaseReturnTransactionLine.Quantity * purchaseLineNetTotal / 
                purchaseTransactionLine.PurchaseTransaction.GrossTotal * purchaseTransactionLine.PurchaseTransaction.Discount;
            var fractionOfTransactionTax = purchaseReturnTransactionLine.Quantity * purchaseLineNetTotal / 
                purchaseTransactionLine.PurchaseTransaction.GrossTotal * purchaseTransactionLine.PurchaseTransaction.Tax;
            return purchaseReturnTransactionLine.Quantity * purchaseLineNetTotal - fractionOfTransactionDiscount + fractionOfTransactionTax;
        }
Beispiel #4
0
        private PurchaseReturnTransactionLineVM MakeNewEntryPurchaseReturnTransactionLine()
        {
            var purchaseReturnTransactionLine = new PurchaseReturnTransactionLine
            {
                PurchaseReturnTransaction = _parentVM.Model,
                Item            = _parentVM.SelectedPurchaseTransactionLine.Item,
                Warehouse       = _parentVM.SelectedPurchaseTransactionLine.Warehouse,
                PurchasePrice   = _parentVM.SelectedPurchaseTransactionLine.PurchasePrice,
                Discount        = _parentVM.SelectedPurchaseTransactionLine.Discount,
                ReturnPrice     = _purchaseReturnEntryPrice,
                Quantity        = _purchaseReturnEntryQuantity,
                Total           = _purchaseReturnEntryQuantity * _purchaseReturnEntryPrice,
                ReturnWarehouse = _purchaseReturnEntryWarehouse.Model
            };

            return(new PurchaseReturnTransactionLineVM {
                Model = purchaseReturnTransactionLine
            });
        }
 private PurchaseReturnTransactionLineVM MakeNewEntryPurchaseReturnTransactionLine()
 {
     var purchaseReturnTransactionLine = new PurchaseReturnTransactionLine
     {
         PurchaseReturnTransaction = _parentVM.Model,
         Item = _parentVM.SelectedPurchaseTransactionLine.Item,
         Warehouse = _parentVM.SelectedPurchaseTransactionLine.Warehouse,
         PurchasePrice = _parentVM.SelectedPurchaseTransactionLine.PurchasePrice,
         Discount = _parentVM.SelectedPurchaseTransactionLine.Discount,
         ReturnPrice = _purchaseReturnEntryPrice,
         Quantity = _purchaseReturnEntryQuantity,
         Total = _purchaseReturnEntryQuantity*_purchaseReturnEntryPrice,
         ReturnWarehouse = _purchaseReturnEntryWarehouse.Model
     };
     return new PurchaseReturnTransactionLineVM {Model = purchaseReturnTransactionLine};
 }
 private static void IncreasePurchaseReturnTransactionLineItemSoldOrReturnedInDatabaseContext(ERPContext context, PurchaseReturnTransactionLine purchaseReturnTransactionLine)
 {
     var purchaseTransactionLine = context.PurchaseTransactionLines
             .Single(
         line => line.PurchaseTransactionID.Equals(purchaseReturnTransactionLine.PurchaseReturnTransaction.PurchaseTransaction.PurchaseID) &&
         line.ItemID.Equals(purchaseReturnTransactionLine.Item.ID) && line.WarehouseID.Equals(purchaseReturnTransactionLine.Warehouse.ID) && 
         line.PurchasePrice.Equals(purchaseReturnTransactionLine.PurchasePrice) && line.Discount.Equals(purchaseReturnTransactionLine.Discount));
     purchaseTransactionLine.SoldOrReturned += purchaseReturnTransactionLine.Quantity;
 }
 private static void DecreasePurchaseReturnTransactionLineItemStockInDatabaseContext(ERPContext context, PurchaseReturnTransactionLine purchaseReturnTransactionLine)
 {
     var stockFromDatabase = context.Stocks.Single(
         stock => stock.Item.ID.Equals(purchaseReturnTransactionLine.Item.ID) && 
         stock.Warehouse.ID.Equals(purchaseReturnTransactionLine.Warehouse.ID));
     stockFromDatabase.Pieces -= purchaseReturnTransactionLine.Quantity;
     if (stockFromDatabase.Pieces == 0) context.Stocks.Remove(stockFromDatabase);
 }
 private static void AddPurchaseReturnTransactionLineToDatabaseContext(ERPContext context, PurchaseReturnTransactionLine purchaseReturnTransactionLine)
 {
     purchaseReturnTransactionLine.Item            = context.Inventory.Single(item => item.ID.Equals(purchaseReturnTransactionLine.Item.ID));
     purchaseReturnTransactionLine.Warehouse       = context.Warehouses.Single(warehouse => warehouse.ID.Equals(purchaseReturnTransactionLine.Warehouse.ID));
     purchaseReturnTransactionLine.ReturnWarehouse = context.Warehouses.Single(warehouse => warehouse.ID.Equals(purchaseReturnTransactionLine.ReturnWarehouse.ID));
     context.PurchaseReturnTransactionLines.Add(purchaseReturnTransactionLine);
 }
        private static bool IsThereEnoughLineItemStockInDatabaseContext(ERPContext context, PurchaseReturnTransactionLine purchaseReturnTransactionLine)
        {
            var stockFromDatabase = context.Stocks.SingleOrDefault(
                stock => stock.Item.ID.Equals(purchaseReturnTransactionLine.Item.ID) &&
                stock.Warehouse.ID.Equals(purchaseReturnTransactionLine.ReturnWarehouse.ID));

            if (stockFromDatabase != null && stockFromDatabase.Pieces >= purchaseReturnTransactionLine.Quantity)
            {
                return(true);
            }
            var availableQuantity = stockFromDatabase?.Pieces ?? 0;

            MessageBox.Show(
                $"{purchaseReturnTransactionLine.Item.Name} has only {availableQuantity} left.",
                "Invalid Quantity", MessageBoxButton.OK);
            return(false);
        }
        private static decimal CalculateLineCOGSFromDatabaseContext(ERPContext context, PurchaseReturnTransactionLine purchaseReturnTransactionLine)
        {
            var purchaseTransactionLine = context.PurchaseTransactionLines
                                          .Single(
                line => line.PurchaseTransactionID.Equals(purchaseReturnTransactionLine.PurchaseReturnTransaction.PurchaseTransaction.PurchaseID) &&
                line.ItemID.Equals(purchaseReturnTransactionLine.Item.ID) && line.WarehouseID.Equals(purchaseReturnTransactionLine.Warehouse.ID) &&
                line.PurchasePrice.Equals(purchaseReturnTransactionLine.PurchasePrice) && line.Discount.Equals(purchaseReturnTransactionLine.Discount));

            var purchaseLineNetTotal = purchaseTransactionLine.PurchasePrice - purchaseTransactionLine.Discount;

            if (purchaseLineNetTotal == 0)
            {
                return(0);
            }
            var fractionOfTransactionDiscount = purchaseReturnTransactionLine.Quantity * purchaseLineNetTotal /
                                                purchaseTransactionLine.PurchaseTransaction.GrossTotal * purchaseTransactionLine.PurchaseTransaction.Discount;
            var fractionOfTransactionTax = purchaseReturnTransactionLine.Quantity * purchaseLineNetTotal /
                                           purchaseTransactionLine.PurchaseTransaction.GrossTotal * purchaseTransactionLine.PurchaseTransaction.Tax;

            return(purchaseReturnTransactionLine.Quantity * purchaseLineNetTotal - fractionOfTransactionDiscount + fractionOfTransactionTax);
        }
        private static void DecreasePurchaseReturnTransactionLineItemStockInDatabaseContext(ERPContext context, PurchaseReturnTransactionLine purchaseReturnTransactionLine)
        {
            var stockFromDatabase = context.Stocks.Single(
                stock => stock.Item.ID.Equals(purchaseReturnTransactionLine.Item.ID) &&
                stock.Warehouse.ID.Equals(purchaseReturnTransactionLine.Warehouse.ID));

            stockFromDatabase.Pieces -= purchaseReturnTransactionLine.Quantity;
            if (stockFromDatabase.Pieces == 0)
            {
                context.Stocks.Remove(stockFromDatabase);
            }
        }
        private static void IncreasePurchaseReturnTransactionLineItemSoldOrReturnedInDatabaseContext(ERPContext context, PurchaseReturnTransactionLine purchaseReturnTransactionLine)
        {
            var purchaseTransactionLine = context.PurchaseTransactionLines
                                          .Single(
                line => line.PurchaseTransactionID.Equals(purchaseReturnTransactionLine.PurchaseReturnTransaction.PurchaseTransaction.PurchaseID) &&
                line.ItemID.Equals(purchaseReturnTransactionLine.Item.ID) && line.WarehouseID.Equals(purchaseReturnTransactionLine.Warehouse.ID) &&
                line.PurchasePrice.Equals(purchaseReturnTransactionLine.PurchasePrice) && line.Discount.Equals(purchaseReturnTransactionLine.Discount));

            purchaseTransactionLine.SoldOrReturned += purchaseReturnTransactionLine.Quantity;
        }