Beispiel #1
0
        public void AddNewStockItem(skStock StockOb, int UserID)
        {
            dtStock newstock = new dtStock
            {
                CategoryID  = StockOb.CategoryObject.StockTypeID,
                ItemDesc    = StockOb.Description,
                ItemTitle   = StockOb.Name,
                ValueBandID = StockOb.ValueBandObject.ID,
                Batch       = 0,
                Sold        = false,
                CreatedBy   = UserID,
                Created     = DateTime.Now
            };

            dtStockDetail newdetails = new dtStockDetail
            {
                PurchaseValue = StockOb.purchasedvalue
            };

            dtStockHistory newstatus = new dtStockHistory
            {
                Status   = "Stock Created",
                Value    = 0,
                UserID   = UserID,
                Created  = DateTime.Now,
                StatusID = 0
            };

            newstock.dtStockHistories.Add(newstatus);
            newstock.dtStockDetails.Add(newdetails);

            DB.dtStocks.InsertOnSubmit(newstock);
            DB.SubmitChanges();
        }
Beispiel #2
0
        public void AddToExistingPurchase(skStock StockOb, int PurchaseID, int UserID)
        {
            dtStockDetail newdetails = new dtStockDetail
            {
                PurchaseValue = StockOb.purchasedvalue
            };

            dtStock newstock = new dtStock
            {
                CategoryID  = StockOb.CategoryObject.StockTypeID,
                ItemDesc    = StockOb.Description,
                ItemTitle   = StockOb.Name,
                ValueBandID = StockOb.ValueBandObject.ID,
                Batch       = 0,
                Sold        = false,
                CreatedBy   = UserID,
                Created     = DateTime.Now,
                PurchaseID  = PurchaseID,
            };

            newstock.dtStockDetails.Add(newdetails);

            DB.dtStocks.InsertOnSubmit(newstock);
            DB.SubmitChanges();

            dtPurchese purchase = DB.dtPurcheses.Single(x => x.pID == PurchaseID);

            purchase.PurchesedValue += StockOb.purchasedvalue;

            DB.SubmitChanges();
        }
        public void RemoveStockFromPurchase(int StockID, int UserID)
        {
            dtStock       StockObj       = DB.dtStocks.Single(x => x.sID == StockID);
            dtStockDetail StockDetailObj = DB.dtStockDetails.Single(x => x.StockID == StockObj.sID);
            dtPurchese    PurchaseOBJ;

            if (StockObj.PurchaseID != null)
            {
                PurchaseOBJ = DB.dtPurcheses.Single(x => x.pID == StockObj.PurchaseID);

                if (StockDetailObj.PurchaseValue > PurchaseOBJ.PurchesedValue)
                {
                    PurchaseOBJ.PurchesedValue = 0;
                }
                else
                {
                    PurchaseOBJ.PurchesedValue -= StockDetailObj.PurchaseValue;
                }

                StockDetailObj.PurchaseValue = null;
                StockObj.PurchaseID          = null;

                DB.SubmitChanges();

                CreateNewStockStatus(StockID, "Removed from Purchase", UserID);
            }
        }
        public void LinkTranToStock(ITransaction TransactionObject, skStock StockOBJ, int UserID)
        {
            dtStock       StockObj    = DB.dtStocks.Single(x => x.sID == StockOBJ.Stockid);
            dtStockDetail StockDetais = DB.dtStockDetails.Single(x => x.StockID == StockOBJ.Stockid);

            switch (TransactionObject.TransactionType)
            {
            case TransactionType.Sale:
                StockDetais.SaleValue = StockOBJ.SaleValue;
                dtSale SaleObj = DB.dtSales.Single(x => x.tID == TransactionObject.ID);
                SaleObj.SoldValue += StockDetais.SaleValue;
                StockObj.SaleID    = TransactionObject.ID;
                CreateNewStockStatus(StockOBJ.Stockid, "Linked To sale " + SaleObj.tID, UserID, Convert.ToDecimal(StockOBJ.SaleValue));
                break;

            case TransactionType.Purchase:
                StockDetais.PurchaseValue = StockOBJ.purchasedvalue;
                dtPurchese PurchaseObj = DB.dtPurcheses.Single(x => x.pID == TransactionObject.ID);
                PurchaseObj.PurchesedValue += StockDetais.PurchaseValue;
                StockObj.PurchaseID         = TransactionObject.ID;
                CreateNewStockStatus(StockOBJ.Stockid, "Linked To Purchase " + PurchaseObj.pID, UserID, Convert.ToDecimal(StockOBJ.purchasedvalue));
                break;
            }

            DB.SubmitChanges();
        }
        public void RemoveStockFromSale(int StockID, int UserID)
        {
            dtStock       StockObj       = DB.dtStocks.Single(x => x.sID == StockID);
            dtStockDetail StockDetailObj = DB.dtStockDetails.Single(x => x.StockID == StockObj.sID);
            dtSale        SaleOBJ;

            if (StockObj.SaleID != null)
            {
                SaleOBJ = DB.dtSales.Single(x => x.tID == StockObj.SaleID);

                if (StockDetailObj.SaleValue > SaleOBJ.SoldValue)
                {
                    SaleOBJ.SoldValue = 0;
                }
                else
                {
                    SaleOBJ.SoldValue -= StockDetailObj.SaleValue;
                }

                StockDetailObj.SaleValue = null;
                StockObj.SaleID          = null;

                DB.SubmitChanges();

                CreateNewStockStatus(StockID, "Removed from sale", UserID);
            }
        }
        public void AddNewRefund(skRefund RefundObject, bool ReturnStock, int UserID)
        {
            dtRefund NewRefund = new dtRefund
            {
                Reason     = RefundObject.Description,
                Amount     = Convert.ToDecimal(RefundObject.Amount),
                Postage    = RefundObject.SHippingCosts,
                Refunded   = DateTime.Now,
                RefundedBy = UserID,
                StockID    = Convert.ToInt32(RefundObject.StockItem.Stockid),
                Created    = DateTime.Now,
                Updated    = DateTime.Now,
            };

            dtStockHistory NewStatus = new dtStockHistory
            {
                StoockID = Convert.ToInt32(RefundObject.StockItem.Stockid),
                Status   = "Return",
                Value    = RefundObject.Amount,
                UserID   = UserID,
                Created  = DateTime.Now,
                StatusID = 0
            };


            if (ReturnStock == true)
            {
                dtStockDetail details = DB.dtStockDetails.Single(s => s.StockID == RefundObject.StockItem.Stockid);
                dtStock       stock   = DB.dtStocks.Single(s => s.sID == RefundObject.StockItem.Stockid);

                stock.Sold        = false;
                stock.SaleID      = null;
                details.SaleValue = null;
            }

            DB.dtRefunds.InsertOnSubmit(NewRefund);
            DB.dtStockHistories.InsertOnSubmit(NewStatus);

            DB.SubmitChanges();
        }
Beispiel #7
0
        public void AddNewStockItem(skStock StockOb, skPurchase PurchaseOb, int UserID)
        {
            dtPurchese newpurchase = new dtPurchese
            {
                ItemTitle       = StockOb.Name,
                ItemDescription = StockOb.Description,
                PurchesedValue  = PurchaseOb.Amount,
                ShippingCosts   = PurchaseOb.Postage,
                InvoiceID       = PurchaseOb.Invoice,
                Purchesed_Date  = PurchaseOb.PurchaseDate,
                AddedBy         = UserID,
                VendorID        = PurchaseOb.VendorObject.VendorID,
                IsExpense       = false,
                Created         = DateTime.Now,
                Updated         = DateTime.Now
            };

            dtStock newstock = new dtStock
            {
                CategoryID  = StockOb.CategoryObject.StockTypeID,
                ItemDesc    = StockOb.Description,
                ItemTitle   = StockOb.Name,
                ValueBandID = StockOb.ValueBandObject.ID,
                Batch       = 0,
                Sold        = false,
                CreatedBy   = UserID,
                Created     = DateTime.Now,
                dtPurchese  = newpurchase
            };

            dtStockDetail newdetails = new dtStockDetail
            {
                PurchaseValue = StockOb.purchasedvalue
            };

            newstock.dtStockDetails.Add(newdetails);
            DB.dtStocks.InsertOnSubmit(newstock);
            DB.SubmitChanges();

            decimal pVALUE   = System.Math.Abs(Convert.ToDecimal(PurchaseOb.Amount)) * (-1);
            decimal pPOSTAGE = System.Math.Abs(PurchaseOb.Postage) * (-1);
            int     pID      = TopPurchase();
            int?    stockID  = GetTop1MostrecentSid();

            dtStockHistory newstatus = new dtStockHistory
            {
                StoockID = stockID,
                Status   = "Stock Created",
                Value    = StockOb.purchasedvalue,
                UserID   = UserID,
                Created  = DateTime.Now,
                StatusID = 0
            };

            dtTransactionLedger newpurchaseledger = new dtTransactionLedger
            {
                PurchaseID          = pID,
                TransactionType     = "Purchase",
                TotelAmount         = pVALUE,
                SaleID              = null,
                TransactionDateTime = Convert.ToDateTime(PurchaseOb.PurchaseDate)
            };

            dtTransactionLedger newshippingledger = new dtTransactionLedger
            {
                PurchaseID          = pID,
                TransactionType     = "Shipping",
                TotelAmount         = pPOSTAGE,
                SaleID              = null,
                TransactionDateTime = Convert.ToDateTime(PurchaseOb.PurchaseDate)
            };

            DB.dtStockHistories.InsertOnSubmit(newstatus);
            DB.dtTransactionLedgers.InsertOnSubmit(newpurchaseledger);
            DB.dtTransactionLedgers.InsertOnSubmit(newshippingledger);
            DB.SubmitChanges();
        }
Beispiel #8
0
        public void AddNewStockItem(List <skStock> StockList, skPurchase PurchaseObject, int UserID)
        {
            dtPurchese newpurchase = new dtPurchese
            {
                ItemTitle       = PurchaseObject.Title,
                ItemDescription = PurchaseObject.Description,
                PurchesedValue  = PurchaseObject.Amount,
                ShippingCosts   = PurchaseObject.Postage,
                InvoiceID       = PurchaseObject.Invoice,
                Purchesed_Date  = PurchaseObject.PurchaseDate,
                AddedBy         = UserID,
                VendorID        = PurchaseObject.VendorObject.VendorID,
                IsExpense       = false,
                Created         = DateTime.Now,
                Updated         = DateTime.Now
            };

            DB.dtPurcheses.InsertOnSubmit(newpurchase);
            DB.SubmitChanges();

            int ID = (from s in DB.dtPurcheses
                      orderby s.pID descending
                      select new { ID = s.pID }).Take(1).FirstOrDefault().ID;

            foreach (skStock s in StockList)
            {
                dtStock newstock = new dtStock
                {
                    CategoryID  = s.CategoryObject.StockTypeID,
                    ItemDesc    = s.Description,
                    ItemTitle   = s.Name,
                    ValueBandID = s.ValueBandObject.ID,
                    Batch       = 0,
                    Sold        = false,
                    CreatedBy   = UserID,
                    Created     = DateTime.Now,
                    PurchaseID  = ID
                };

                dtStockDetail newdetails = new dtStockDetail
                {
                    PurchaseValue = s.purchasedvalue
                };

                dtStockHistory newstatus = new dtStockHistory
                {
                    Status   = "Stock Created",
                    Value    = s.purchasedvalue,
                    UserID   = UserID,
                    Created  = DateTime.Now,
                    StatusID = 0
                };

                newstock.dtStockHistories.Add(newstatus);
                newstock.dtStockDetails.Add(newdetails);


                DB.dtStocks.InsertOnSubmit(newstock);
            }

            DB.SubmitChanges();
        }
        public void AddNewSale(skSales TransactionObject, int UserID)
        {
            dtSale newtransaction = new dtSale
            {
                SoldValue           = TransactionObject.Amount,
                PaypayFees          = TransactionObject.PayPalFees,
                PandP               = TransactionObject.Postage,
                SaleMethod          = TransactionObject.SaleMethod,
                SoldDate            = TransactionObject.SaleDate,
                SoldBy              = UserID,
                PayPalTransactionID = TransactionObject.PayPalTransactionID,
                Updated             = DateTime.Now,
                Created             = DateTime.Now,
                Title               = TransactionObject.Title,
                Description         = TransactionObject.Description,
                PersonID            = TransactionObject.PersonObj.pID
            };

            DB.dtSales.InsertOnSubmit(newtransaction);
            DB.SubmitChanges();

            int     tid     = MostRecentsalesID();
            decimal pvalue  = Math.Abs(Convert.ToDecimal(TransactionObject.PayPalFees)) * (-1);
            decimal ppvalue = Math.Abs(Convert.ToDecimal(TransactionObject.Postage)) * (-1);

            dtTransactionLedger newsaleledger = new dtTransactionLedger
            {
                SaleID              = tid,
                PurchaseID          = null,
                TotelAmount         = Convert.ToDecimal(TransactionObject.Amount),
                TransactionType     = "Item Sale",
                TransactionDateTime = Convert.ToDateTime(TransactionObject.SaleDate)
            };

            dtTransactionLedger newspaypal = new dtTransactionLedger

            {
                SaleID              = tid,
                PurchaseID          = null,
                TotelAmount         = pvalue,
                TransactionType     = "PayPal Fees",
                TransactionDateTime = Convert.ToDateTime(TransactionObject.SaleDate)
            };

            dtTransactionLedger newepostage = new dtTransactionLedger
            {
                SaleID              = tid,
                PurchaseID          = null,
                TotelAmount         = ppvalue,
                TransactionType     = "Sale Postage",
                TransactionDateTime = Convert.ToDateTime(TransactionObject.SaleDate)
            };

            foreach (skStock s in TransactionObject.StockList)
            {
                dtStockHistory newstatus = new dtStockHistory
                {
                    StoockID = Convert.ToInt32(s.Stockid),
                    Status   = "Stock Sold",
                    Value    = 0,
                    UserID   = UserID,
                    Created  = DateTime.Now,
                    StatusID = 1
                };
                DB.dtStockHistories.InsertOnSubmit(newstatus);

                dtStockDetail SD = DB.dtStockDetails.Single(x => x.StockID == s.Stockid);
                SD.SaleValue = s.SaleValue;
            }

            List <long> StockIds = new List <long>();

            foreach (skStock s in TransactionObject.StockList)
            {
                StockIds.Add(s.Stockid);
            }

            var setsold = from ST in DB.dtStocks
                          where StockIds.Contains(ST.sID)
                          select ST;

            foreach (dtStock s in setsold)
            {
                s.Sold   = true;
                s.SaleID = tid;
            }

            DB.dtTransactionLedgers.InsertOnSubmit(newepostage);
            DB.dtTransactionLedgers.InsertOnSubmit(newspaypal);
            DB.dtTransactionLedgers.InsertOnSubmit(newsaleledger);

            DB.SubmitChanges();
        }