public Returner DeleteInvoice() { var ITD = db.CustomerInvoices.Where(p => p.Id == this.Id).SingleOrDefault(); var InvLines = db.CustomerInvoiceLines.Where(p => p.InvoiceId == ITD.Id).ToList(); List <CustomerInvoiceLine> LOCIL = new List <CustomerInvoiceLine>(); LOCIL = InvLines; var FtToDelete = db.FinancialTransactions.Where(p => p.ReferanceDocumentNumber == ITD.Id).ToList(); foreach (FinancialTransaction item in FtToDelete) { db.FinancialTransactions.Remove(item); db.SaveChanges(); } foreach (CustomerInvoiceLine CIL in LOCIL) { Stock S = db.Stocks.Single(p => p.ProjectID == ITD.ProjectID && p.ProductID == CIL.ProductId); S.Quantity += CIL.Qty; StockTransaction ST = new StockTransaction(); ST.Date = DateTime.UtcNow.AddHours(3); ST.ProductID = CIL.ProductId; ST.Quantity = CIL.Qty; ST.StockID = S.Id; ST.Type = (int)StockTransactionsTypes.حذف_فاتورة_بيع; db.StockTransactions.Add(ST); db.SaveChanges(); db.CustomerInvoiceLines.Remove(CIL); } db.CustomerInvoices.Remove(ITD); db.SaveChanges(); return(new Returner { Message = Message.Invoice_Deleted_Successfully }); }
public Returner Sells(int InvoiceID) { int ProjID = (int)(db.CustomerInvoices.Where(p => p.Id == InvoiceID).SingleOrDefault().ProjectID); List <CustomerInvoiceLine> LOSIL = new List <CustomerInvoiceLine>(); LOSIL = new CustomerInvoiceLine { InvoiceId = InvoiceID }.GetByInvoiceID().Data as List <CustomerInvoiceLine>; foreach (CustomerInvoiceLine item in LOSIL) { var StockToUpdate = db.Stocks.Where(p => p.ProjectID == ProjID && p.ProductID == item.ProductId).SingleOrDefault(); StockToUpdate.Quantity -= item.Qty; db.SaveChanges(); StockTransaction ST = new StockTransaction { Date = DateTime.UtcNow.AddHours(3), ProductID = StockToUpdate.ProductID, Quantity = -item.Qty, StockID = StockToUpdate.Id, Type = (int)StockTransactionsTypes.بيع }; db.StockTransactions.Add(ST); db.SaveChanges(); } return(new Returner { Message = Message.Sell_Operation_Finished_Successfully }); }
public Returner SaveWorkOrder(List <CustomerInvoiceLine> CIL, DateTime Date, int ProjID, int Acc, string Notes, double Total, int EditBy) { var CurrentProject = db.Projects.Where(p => p.Id == ProjID).SingleOrDefault(); foreach (CustomerInvoiceLine item in CIL) { var CurrentStock = db.Stocks.Single(p => p.ProjectID == ProjID && p.ProductID == item.ProductId); CurrentStock.Quantity -= item.Qty; db.SaveChanges(); StockTransaction ST = new StockTransaction(); ST.Date = Date; ST.StockID = CurrentStock.Id; ST.ProductID = item.ProductId; ST.Quantity = -item.Qty; ST.Type = (int)StockTransactionsTypes.امر_عمل; db.StockTransactions.Add(ST); db.SaveChanges(); var CurrentProduct = db.Products.Single(p => p.Id == item.ProductId); FinancialTransaction Ft = new FinancialTransaction(); Ft.Debit = item.Total; Ft.Credit = 0; Ft.LastEditBy = EditBy; Ft.Confirmed = false; Ft.Notes = Notes; Ft.Statement = "امر شغل " + " بتاريخ " + Date.ToString("MM/dd/yyyy"); Ft.TransactionDate = Date; Ft.FromAccount = CurrentProject.AccountID; Ft.ReferanceDocumentNumber = ST.Id; db.FinancialTransactions.Add(Ft); FinancialTransaction Ft1 = new FinancialTransaction(); Ft1.Credit = item.Total; Ft1.LastEditBy = EditBy; Ft1.Confirmed = false; Ft1.Notes = Notes; Ft1.Statement = "امر شغل " + " بتاريخ " + Date.ToString("MM/dd/yyyy"); Ft1.TransactionDate = Date; Ft1.FromAccount = CurrentProduct.AccountID; db.FinancialTransactions.Add(Ft1); } db.SaveChanges(); return(new Returner { Message = Message.Work_Order_Saved_Successfully }); }
public Returner Remove() { var ILToRemove = db.SupplierInvoiceLines.Where(p => p.Id == this.Id).SingleOrDefault(); var ILParent = db.SupplierInvoices.Single(p => p.Id == ILToRemove.InvoiceId); StockTransaction ST = new StockTransaction(); ST.Date = DateTime.UtcNow.AddHours(3); ST.ProductID = ILToRemove.ProductId; ST.Quantity = -ILToRemove.Qty; ST.StockID = db.Stocks.Single(p => p.ProductID == ILToRemove.ProductId && p.ProjectID == ILParent.ProjectID).Id; ST.Type = (int)StockTransactionsTypes.تعديل_فاتورة_شراء; db.StockTransactions.Add(ST); var StockToEdit = db.Stocks.Single(p => p.ProductID == ILToRemove.ProductId && p.ProjectID == ILParent.ProjectID); StockToEdit.Quantity += ST.Quantity; ILParent.InvoiceTotal -= ILToRemove.Total; ILParent.InvoiceNet = ILParent.InvoiceTotal - ILParent.InvoiceDiscount; db.SupplierInvoiceLines.Remove(ILToRemove); db.SaveChanges(); return(new Returner { Message = Message.Invoice_Line_Removed_Successfully }); }