public void AddNewPurchase(skPurchase PurchaseOb, int UserID) { dtPurchese newpurchase = new dtPurchese { ItemTitle = PurchaseOb.Title, ItemDescription = PurchaseOb.Description, PurchesedValue = PurchaseOb.Amount, ShippingCosts = PurchaseOb.Postage, InvoiceID = PurchaseOb.Invoice, Purchesed_Date = PurchaseOb.PurchaseDate, AddedBy = UserID, VendorID = PurchaseOb.VendorObject.VendorID, IsExpense = PurchaseOb.IsExpense, Created = DateTime.Now, Updated = DateTime.Now }; DB.dtPurcheses.InsertOnSubmit(newpurchase); DB.SubmitChanges(); decimal pVALUE = System.Math.Abs(Convert.ToDecimal(PurchaseOb.Amount)) * (-1); decimal pPOSTAGE = System.Math.Abs(PurchaseOb.Postage) * (-1); int pID = TopPurchase(); 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.dtTransactionLedgers.InsertOnSubmit(newpurchaseledger); DB.dtTransactionLedgers.InsertOnSubmit(newshippingledger); DB.SubmitChanges(); }
public void AddNewRefund(skRefund RefundObject, 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 }; DB.dtRefunds.InsertOnSubmit(NewRefund); DB.SubmitChanges(); dtTransactionLedger NewRefundLedger = new dtTransactionLedger { RefundID = getlastrefund(), TransactionType = "Refund", TotelAmount = Maths.GetNegativeValue(Convert.ToDecimal(RefundObject.Amount)), TransactionDateTime = DateTime.Now }; dtStockHistory NewStatus = new dtStockHistory { StoockID = Convert.ToInt32(RefundObject.StockItem.Stockid), Status = "Return", Value = RefundObject.Amount, UserID = UserID, Created = DateTime.Now, StatusID = 0 }; DB.dtTransactionLedgers.InsertOnSubmit(NewRefundLedger); DB.dtStockHistories.InsertOnSubmit(NewStatus); DB.SubmitChanges(); dtStock stock = DB.dtStocks.Single(s => s.sID == RefundObject.StockItem.Stockid); stock.Sold = false; DB.SubmitChanges(); }
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(); }
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(); }