public List <Models.MViewModels.MViewTransactions> GetAll()
            {
                List <Models.MViewModels.MViewTransactions> Transactions    = new List <Models.MViewModels.MViewTransactions>();
                List <Models.MSaleTransactions>             AllTransactions = new List <Models.MSaleTransactions>();

                Models.MViewModels.MViewTransactions mvv = new Models.MViewModels.MViewTransactions();
                Classes.CProducts        cp  = new CProducts();
                Classes.CSaleTransations cst = new CSaleTransations();
                Classes.CWareHouse       cw  = new CWareHouse();
                AllTransactions = cst.GetAll();
                AllTransactions = (from o in AllTransactions select o).OrderBy(o => o.date).ToList();
                for (int i = 0; i < AllTransactions.Count; i++)
                {
                    mvv = new Models.MViewModels.MViewTransactions();
                    string ProductId     = AllTransactions[i].ProductID;
                    string ProductName   = cp.GetProductNameWithTagsById(Convert.ToInt32(ProductId));
                    string WareHouseId   = AllTransactions[i].WareHouseId;
                    string WareHouseName = cw.GetWareHouseNameById(Convert.ToInt32(WareHouseId));
                    mvv.TransactionId = AllTransactions[i].id.ToString();
                    mvv.Date          = AllTransactions[i].date.ToShortDateString();
                    mvv.Product       = ProductName;
                    mvv.Type          = AllTransactions[i].transactionType;
                    mvv.Units         = AllTransactions[i].units;
                    mvv.WareHouse     = WareHouseName;
                    mvv.OrderId       = AllTransactions[i].OrderId;
                    mvv.WareHouseId   = WareHouseId;
                    Transactions.Add(mvv);
                }
                return(Transactions);
            }
        public List <Models.MInventoryBalance> GetInventoryBalance(DateTime fromDate, DateTime toDate)
        {
            List <Models.MInventoryBalance> Data = new List <Models.MInventoryBalance>();
            var query = from o in obj.InventoryBalances
                        where o.Date >= fromDate && o.Date <= toDate
                        select o;

            Classes.CProducts  cp = new CProducts();
            Classes.CWareHouse cw = new CWareHouse();
            foreach (var item in query)
            {
                Models.MInventoryBalance mib = new Models.MInventoryBalance();
                string ProductName           = string.Empty;
                string WarehouseName         = string.Empty;
                ProductName           = cp.GetProductNameWithTagsById(Convert.ToInt32(item.ProductsId));
                mib.WareHouseId       = Convert.ToInt32(item.WarehouseId.ToString());
                WarehouseName         = cw.GetWareHouseNameById(Convert.ToInt32(item.WarehouseId));
                mib.BalanceTotal      = item.BalanceTotal;
                mib.BalanceUnits      = item.BalanceUnits;
                mib.BalanceUnitsCost  = item.BalanceUnitsCost;
                mib.date              = Convert.ToDateTime(item.Date);
                mib.ProductName       = ProductName;
                mib.PurchaseTotal     = item.PurchaseTotal;
                mib.PurchaseUnits     = item.PurchaseUnits;
                mib.PurchaseUnitsCost = item.PurchaseUnitsCost;
                mib.SaleTotal         = item.SaleTotal;
                mib.SaleUnits         = item.SaleUnits;
                mib.SaleUnitsCost     = item.SaleUnitsCost;
                mib.WareHouseName     = WarehouseName;
                Data.Add(mib);
            }

            return(Data);
        }
        public List <Models.MInventory> GetInventoryData()
        {
            List <Models.MInventory> Data = new List <Models.MInventory>();
            var query = from o in obj.Inventories orderby o.WareHouseId ascending select o;

            if (query != null)
            {
                foreach (var item in query)
                {
                    Models.MInventory  mi            = new Models.MInventory();
                    string             Get           = string.Empty;
                    string             WareHouseName = string.Empty;
                    Classes.CProducts  cp            = new CProducts();
                    Classes.CWareHouse cw            = new CWareHouse();
                    Get           = cp.GetProductNameWithTagsById(Convert.ToInt32(item.ProductId));
                    WareHouseName = cw.GetWareHouseNameById(Convert.ToInt32(item.WareHouseId));
                    string[] ProductDetails = Get.Split('-');
                    mi.ProductCode   = ProductDetails[0];
                    mi.ProductName   = ProductDetails[1];
                    mi.ProducyTag1   = ProductDetails[2];
                    mi.ProductTag2   = ProductDetails[3];
                    mi.ProductId     = item.ProductId.ToString();
                    mi.WareHouseld   = item.WareHouseId.ToString();
                    mi.WareHouseName = WareHouseName;
                    mi.Cost          = item.Cost;
                    mi.Quantity      = item.Quantity;
                    mi.TotalCost     = Convert.ToSingle(Convert.ToSingle(item.Cost) * Convert.ToSingle(item.Quantity));
                    Data.Add(mi);
                }
            }


            return(Data);
        }
            public List <Models.MViewModels.MViewCashInHand> GetAll(int fiscalYeadId)
            {
                List <Models.MViewModels.MViewCashInHand> Get = new List <Models.MViewModels.MViewCashInHand>();

                Models.MViewModels.MViewCashInHand mvm = new Models.MViewModels.MViewCashInHand();
                Classes.CInventory       ci            = new CInventory();
                Classes.CWareHouse       cw            = new CWareHouse();
                List <Models.MInventory> Inventory     = new List <Models.MInventory>();

                Inventory = ci.GetAll();
                Inventory = (from o in Inventory
                             where Convert.ToInt32(o.FiscalYearld) == fiscalYeadId
                             select o).ToList();
                for (int i = 0; i < Inventory.Count; i++)
                {
                    string            ProductName;
                    string            ProductCode;
                    string            ProductTag1;
                    string            ProductTag2;
                    string            Units;
                    string            PerUnitCost;
                    string            Total;
                    string            WareHouseName;
                    Classes.CProducts cp = new CProducts();
                    int ProductId        = 0;
                    ProductId = Convert.ToInt32(Inventory[i].ProductId);
                    List <Models.MProducts> Products = new List <Models.MProducts>();
                    Products = cp.GetAllbyid(ProductId);
                    if (Products.Count() != 0)
                    {
                        mvm = new Models.MViewModels.MViewCashInHand();
                        int WareHouseId = 0;

                        WareHouseId   = Convert.ToInt32(Inventory[i].WareHouseld);
                        WareHouseName = cw.GetWareHouseNameById(WareHouseId);
                        ProductName   = Products[0].Name;
                        ProductCode   = Products[0].ProductCode;
                        ProductTag1   = Products[0].tag1;
                        ProductTag2   = Products[0].tag2;
                        Units         = Inventory[i].Quantity.ToString();
                        PerUnitCost   = Inventory[i].Cost;
                        Total         = (Convert.ToSingle(Units) * Convert.ToSingle(PerUnitCost)).ToString();
                        //object
                        mvm.PerUnitCost   = PerUnitCost;
                        mvm.ProductCode   = ProductCode;
                        mvm.ProductName   = ProductName;
                        mvm.ProductTag1   = ProductTag1;
                        mvm.ProductTag2   = ProductTag2;
                        mvm.Total         = Total;
                        mvm.Units         = Units;
                        mvm.WareHouseName = WareHouseName;
                        Get.Add(mvm);
                    }
                }
                return(Get);
            }
            public List <Models.MViewModels.MViewOrderDetails> GetAllDetails(int OrderId)
            {
                List <Models.MViewModels.MViewOrderDetails> OrderDetails = new List <Models.MViewModels.MViewOrderDetails>();
                List <Models.MOrdersLine> OrderLine = new List <Models.MOrdersLine>();

                Models.MViewModels.MViewOrderDetails mvo = new Models.MViewModels.MViewOrderDetails();
                Classes.COrderOnline coo = new COrderOnline();
                Classes.COrders      co  = new COrders();
                Classes.CProducts    cp  = new CProducts();
                OrderLine = coo.GetAll();
                OrderLine = OrderLine.Where(o => o.OrderId == OrderId.ToString()).ToList();
                for (int i = 0; i < OrderLine.Count; i++)
                {
                    mvo = new Models.MViewModels.MViewOrderDetails();
                    string CurrentProductPrice = string.Empty, ProductName = string.Empty;
                    ProductName = cp.GetProductNameWithTagsById(Convert.ToInt32(OrderLine[i].ProductId));
                    string OrderType = co.ReturnOrderTypeById(OrderId);
                    switch (OrderType)
                    {
                    case "Client":
                    {
                        CurrentProductPrice = cp.ReturnSalePrice(Convert.ToInt32(OrderLine[i].ProductId));
                        break;
                    }

                    case "Vendor":
                    {
                        CurrentProductPrice = cp.ReturnCostPrice(Convert.ToInt32(OrderLine[i].ProductId));
                        break;
                    }

                    default:
                        break;
                    }
                    mvo.CurrentProductPrice = CurrentProductPrice;
                    mvo.OrderProductPrice   = OrderLine[i].SalePrice;
                    mvo.ProductCost         = OrderLine[i].totalProductCost;
                    mvo.ProductName         = ProductName;
                    mvo.Units = OrderLine[i].unit;
                    OrderDetails.Add(mvo);
                }
                return(OrderDetails);
            }
Exemple #6
0
        public List <Models.MRevertInventory.RevertConfirm> GetAllConfirm(int OrderId)
        {
            List <Models.MRevertInventory.RevertConfirm> RevertConfirm = new List <Models.MRevertInventory.RevertConfirm>();
            List <Models.MOrdersLine> OrdersLine = new List <Models.MOrdersLine>();

            Classes.COrderOnline coo = new COrderOnline();
            Classes.CProducts    cp  = new CProducts();
            OrdersLine = coo.GetAll();
            OrdersLine = OrdersLine.Where(o => o.OrderId == OrderId.ToString()).ToList();
            for (int i = 0; i < OrdersLine.Count; i++)
            {
                Models.MRevertInventory.RevertConfirm mrc = new Models.MRevertInventory.RevertConfirm();
                mrc.Price       = OrdersLine[i].SalePrice;
                mrc.ProductId   = OrdersLine[i].ProductId;
                mrc.ProductName = cp.GetProductNameWithTagsById(Convert.ToInt32(mrc.ProductId));
                mrc.Units       = OrdersLine[i].unit;
                RevertConfirm.Add(mrc);
            }
            return(RevertConfirm);
        }
Exemple #7
0
        public int RevertSingleTransaction(int TransactionId, int Units, int ProductId)
        {
            try
            {
                var TransactionType = (from o in obj.Transaction1s
                                       where o.id == TransactionId
                                       select o.TransactionType).FirstOrDefault();
                var PaymentId = (from o in obj.Payments
                                 where o.TransactionId == TransactionId
                                 select o.id).FirstOrDefault();
                var DataPaymentLine = from o in obj.PaymentLines
                                      where o.PaymentId == Convert.ToInt32(PaymentId)
                                      select o;
                var AccountType = (from o in obj.Payments
                                   join paymentLine in obj.PaymentLines
                                   on o.id equals paymentLine.PaymentId
                                   select paymentLine.ModeOfPayment);
                string AccountId = string.Empty;


                Classes.CPayment         cp        = new CPayment();
                Models.MPayments         mp        = new Models.MPayments();
                Classes.CInventory       ci        = new CInventory();
                List <Models.MInventory> Inventory = new List <Models.MInventory>();
                Classes.CProducts        cpr       = new CProducts();

                Inventory = ci.GetAll();
                string CostPrice = (from o in obj.Transaction1s
                                    where o.ProductID == ProductId &&
                                    o.id == TransactionId
                                    select o.CostPrice).FirstOrDefault();
                string SalePrice = (from o in obj.Transaction1s
                                    where o.ProductID == ProductId &&
                                    o.id == TransactionId
                                    select o.SalePrice).FirstOrDefault();
                switch (TransactionType)
                {
                case "Addition":
                {
                    //Reverting Inventory
                    float oldUnits = (from o in Inventory
                                      where o.ProductId == (ProductId).ToString()
                                      select Convert.ToSingle(o.Quantity)).FirstOrDefault();
                    float newUnits = oldUnits - Convert.ToSingle(Units);

                    var query = from o in obj.Inventories
                                where o.ProductId == Convert.ToInt32(ProductId)
                                select o;
                    foreach (var item in query)
                    {
                        item.Quantity = newUnits.ToString();
                    }
                    obj.SubmitChanges();


                    obj.SubmitChanges();
                    //checking for cash of bank account
                    if (Convert.ToString(AccountType) == Common.Constants.ModeOfPayment.Cash.ToString())
                    {
                        string Amount = (Convert.ToSingle(CostPrice) * Convert.ToSingle(Units)).ToString();
                        Classes.CBankOfAccount      cba = new CBankOfAccount();
                        Classes.CAccountTransaction cat = new CAccountTransaction();
                        //Reverting Account
                        float OldTotal = cba.ReturnTotalOfAccountById(Convert.ToInt32(AccountId));
                        float NewTotal = OldTotal + Convert.ToSingle(Amount);
                        cba.SetNewAccountTotal(Convert.ToInt32(AccountId), NewTotal);

                        //Add Revert Account Transaction
                        Models.MAccountTransaction mat = new Models.MAccountTransaction();
                        mat.AccountId    = AccountId.ToString();
                        mat.Credit       = "0";
                        mat.Debit        = Amount.ToString();
                        mat.Description  = "Reverted Sale Transaction Product Id[" + ProductId + "] Units [" + Units + "]";
                        mat.eDate        = DateTime.Now;
                        mat.FiscalYearId = (from o in obj.AccountTransactions
                                            where o.CurrentTransaction == TransactionId.ToString()
                                            select o.FiscalYearId.ToString()).FirstOrDefault();
                        mat.Total           = cba.ReturnTotalOfAccountById(Convert.ToInt32(AccountId)).ToString();
                        mat.Transactiontype = "Credit";

                        cat.Save(mat);
                    }
                    else if (Convert.ToString(AccountType) == Common.Constants.ModeOfPayment.Cheque.ToString())
                    {
                        Classes.CCashAccount     cca = new CCashAccount();
                        Classes.CCashTransaction cct = new CCashTransaction();
                        Models.MCashTransactions mct = new Models.MCashTransactions();
                        Models.MCashAccount      mca = new Models.MCashAccount();
                        string Amount = (Convert.ToSingle(CostPrice) * Convert.ToSingle(Units)).ToString();
                        //Reverting Account
                        float OldTotal = cca.ReturnTotalOfCashAccount(Convert.ToInt32(AccountId));
                        float NewTotal = OldTotal + Convert.ToSingle(Amount);
                        //setting new total
                        cca.SetNewAccountTotal(Convert.ToInt32(AccountId), NewTotal);

                        mct.CashAccountId = Convert.ToInt32(AccountId);
                        mct.Credit        = Amount;
                        mct.Debit         = "0";
                        mct.Description   = "Reverted Sale Transaction Product Id[" + ProductId + "] Units [" + Units + "]";
                        mct.eDate         = DateTime.Now.ToShortDateString();
                        mct.FiscalYearId  = Convert.ToInt32((from o in obj.CashTransactions
                                                             where o.TransactionId == TransactionId
                                                             select o.FiscalYearId).FirstOrDefault());
                        mct.OrderId         = -1;
                        mct.TransactionId   = -1;
                        mct.TransactionType = Common.Constants.TransactionStatus.Reverse.ToString();
                        mct.UserId          = Convert.ToString((from o in obj.CashTransactions
                                                                where o.TransactionId == TransactionId
                                                                select o.UserId).FirstOrDefault());
                        mct.WareHouseId = Convert.ToInt32((from o in obj.CashTransactions
                                                           where o.TransactionId == TransactionId
                                                           select o.WareHouseId).FirstOrDefault());
                        cct.Save(mct);
                    }

                    break;
                }

                case "Deduction":
                {
                    //Reverting Inventory
                    float oldUnits = (from o in Inventory
                                      where o.ProductId == (ProductId).ToString()
                                      select Convert.ToSingle(o.Quantity)).FirstOrDefault();
                    float newUnits = oldUnits + Convert.ToSingle(Units);

                    var query = from o in obj.Inventories
                                where o.ProductId == Convert.ToInt32(ProductId)
                                select o;
                    foreach (var item in query)
                    {
                        item.Quantity = newUnits.ToString();
                    }
                    obj.SubmitChanges();


                    //checking for cash of bank account
                    if (Convert.ToString(AccountType) == Common.Constants.ModeOfPayment.Cash.ToString())
                    {
                        string Amount = (Convert.ToSingle(CostPrice) * Convert.ToSingle(Units)).ToString();
                        Classes.CBankOfAccount      cba = new CBankOfAccount();
                        Classes.CAccountTransaction cat = new CAccountTransaction();
                        //Reverting Account
                        float OldTotal = cba.ReturnTotalOfAccountById(Convert.ToInt32(AccountId));
                        float NewTotal = OldTotal - Convert.ToSingle(Amount);
                        cba.SetNewAccountTotal(Convert.ToInt32(AccountId), NewTotal);

                        //Add Revert Account Transaction
                        Models.MAccountTransaction mat = new Models.MAccountTransaction();
                        mat.AccountId    = AccountId.ToString();
                        mat.Credit       = "0";
                        mat.Debit        = Amount.ToString();
                        mat.Description  = "Reverted Sale Transaction Product Id[" + ProductId + "] Units [" + Units + "]";
                        mat.eDate        = DateTime.Now;
                        mat.FiscalYearId = (from o in obj.AccountTransactions
                                            where o.CurrentTransaction == TransactionId.ToString()
                                            select o.FiscalYearId.ToString()).FirstOrDefault();
                        mat.Total           = cba.ReturnTotalOfAccountById(Convert.ToInt32(AccountId)).ToString();
                        mat.Transactiontype = "Credit";

                        cat.Save(mat);
                    }
                    else if (Convert.ToString(AccountType) == Common.Constants.ModeOfPayment.Cheque.ToString())
                    {
                        Classes.CCashAccount     cca = new CCashAccount();
                        Classes.CCashTransaction cct = new CCashTransaction();
                        Models.MCashTransactions mct = new Models.MCashTransactions();
                        Models.MCashAccount      mca = new Models.MCashAccount();
                        string Amount = (Convert.ToSingle(CostPrice) * Convert.ToSingle(Units)).ToString();
                        //Reverting Account
                        float OldTotal = cca.ReturnTotalOfCashAccount(Convert.ToInt32(AccountId));
                        float NewTotal = OldTotal - Convert.ToSingle(Amount);
                        //setting new total
                        cca.SetNewAccountTotal(Convert.ToInt32(AccountId), NewTotal);


                        //cash account transation
                        mct.CashAccountId = Convert.ToInt32(AccountId);
                        mct.Credit        = "0";
                        mct.Debit         = Amount;
                        mct.Description   = "Reverted Sale Transaction Product Id[" + ProductId + "] Units [" + Units + "]";
                        mct.eDate         = DateTime.Now.ToShortDateString();
                        mct.FiscalYearId  = Convert.ToInt32((from o in obj.CashTransactions
                                                             where o.TransactionId == TransactionId
                                                             select o.FiscalYearId).FirstOrDefault());
                        mct.OrderId         = -1;
                        mct.TransactionId   = -1;
                        mct.TransactionType = Common.Constants.TransactionStatus.Reverse.ToString();
                        mct.UserId          = Convert.ToString((from o in obj.CashTransactions
                                                                where o.TransactionId == TransactionId
                                                                select o.UserId).FirstOrDefault());
                        mct.WareHouseId = Convert.ToInt32((from o in obj.CashTransactions
                                                           where o.TransactionId == TransactionId
                                                           select o.WareHouseId).FirstOrDefault());
                        cct.Save(mct);
                    }
                    break;
                }

                default:
                    break;
                }

                //deletin Transaction
                var transactions = from o in obj.Transaction1s
                                   where o.id == TransactionId
                                   select o;
                foreach (var item in transactions)
                {
                    obj.Transaction1s.DeleteOnSubmit(item);
                }
                //deleting Payment lines
                foreach (var item in DataPaymentLine)
                {
                    obj.PaymentLines.DeleteOnSubmit(item);
                }
                obj.SubmitChanges();
                //deleting payments
                mp.id = Convert.ToInt32(PaymentId);
                cp.Delete(mp);
                return(1);
            }
            catch
            {
                return(-1);
            }
        }
            public List <Models.MViewModels.MItemProfatibilityReport> GetAll(DateTime fromDate, DateTime toDate)
            {
                #region Class Objects
                Classes.CSaleTransations ct = new CSaleTransations();
                Classes.CWareHouse       cw = new CWareHouse();
                Classes.CProducts        cp = new CProducts();

                #endregion

                #region Models
                Models.MSaleTransactions mt = new Models.MSaleTransactions();
                Models.MViewModels.MItemProfatibilityReport mii = new Models.MViewModels.MItemProfatibilityReport();
                #endregion

                #region Lists
                List <Models.MViewModels.MItemProfatibilityReport> ItemProfatiblity = new List <Models.MViewModels.MItemProfatibilityReport>();
                List <Models.MSaleTransactions> Transactions = new List <Models.MSaleTransactions>();
                List <string> Products = new List <string>();
                #endregion

                #region Logic
                float totalUnits = 0;
                Transactions = ct.GetAll();

                //filtering for only deductions
                Transactions = (from o in Transactions
                                where o.transactionType == Common.Constants.SaleTransactions.Deduction.ToString() &&
                                Convert.ToDateTime(o.date) >= fromDate && Convert.ToDateTime(o.date) <= toDate
                                select o).ToList();
                totalUnits = (from o in Transactions select Convert.ToSingle(o.units)).Sum();
                Products   = (from o in Transactions select o.ProductID).Distinct().ToList();
                for (int i = 0; i < Products.Count; i++)
                {
                    mii = new Models.MViewModels.MItemProfatibilityReport();
                    List <Models.MSaleTransactions> ProductWise = new List <Models.MSaleTransactions>();
                    ProductWise = (from o in Transactions where o.ProductID == Products[i] select o).ToList();
                    string ProductName = cp.GetProductNameWithTagsById(Convert.ToInt32(Products[i]));

                    float CostPrice = (from a in ProductWise
                                       where a.ProductID == Products[i]
                                       select Convert.ToSingle(a.CostPrice)).Sum();
                    float Revenue = (from a in ProductWise
                                     where a.ProductID == Products[i]
                                     select Convert.ToSingle(a.SalePrice)).Sum();
                    float units = (from a in ProductWise
                                   where a.ProductID == Products[i]
                                   select Convert.ToSingle(a.units)).Sum();
                    CostPrice = CostPrice * units;
                    Revenue   = Revenue * units;
                    float Difference = Revenue - CostPrice;
                    float totalCost  = Transactions.Select(o => Convert.ToSingle(o.units)).Sum();
                    float Percentage = (units / totalUnits) * 100;
                    mii.Inventory     = ProductName;
                    mii.WareHouse     = "Remaining";
                    mii.ActualCost    = CostPrice.ToString();
                    mii.ActualRevenue = Revenue.ToString();
                    mii.Diff          = Difference.ToString();
                    mii.UnitsSold     = units.ToString();
                    mii.Percent       = Percentage.ToString() + "%";
                    ItemProfatiblity.Add(mii);
                }
                #endregion
                return(ItemProfatiblity);
            }