public bool SaveStockAdjustmentInvoice(int userid, int type, bool isOutput, string description, DateTime invoicedate) { try { var detailtemps = GetAllDetailsTemp(userid); if (detailtemps == null || detailtemps.Count() == 0) { throw new Exception("StockAdjustment Details Temp is Empty for this User"); } var sano = GetNewStockAdjustmentNo(); var header = new StockAdjustment() { InvoiceNumber = sano, UserID = userid, Description = description, Type = type, IsOutput = isOutput, InvoiceDate = invoicedate, SumPrice = detailtemps.Sum(l => l.Price * l.Qty) }; stockAdjustmentRepo.Add(header); var details = new List <StockAdjustmentDetails>(); foreach (var item in detailtemps) { details.Add(new StockAdjustmentDetails() { InvoiceID = header.Id, ProductID = item.ProductID, Qty = ((isOutput) ? -1 : 1) * item.Qty, Price = item.Price, Description = item.Description }); stockLogRepo.Add(new StockLog() { ProductID = item.ProductID, Qty = ((isOutput) ? -1 : 1) * item.Qty, InvoiceNumber = sano, TypeID = 3 }); stockRepo.SetProductStock(item.ProductID); } stockAdjustmentDetailRepo.AddRange(details); stockAdjustmentDetailsTempRepo.DeleteRange(detailtemps); return(true); } catch (Exception ex) { return(false); } }
public bool SaveSaleInvoice(int userid, int customerid, string description, IEnumerable <SaleInvoicePayments> saleInvoicePayments) { try { var detailtemps = GetAllDetailsTemp(userid); if (detailtemps == null || detailtemps.Count() == 0) { throw new Exception("SaleInvoice Detail Temp is Empty for this User"); } var sino = GetNewSaleInvoiceNo(); var sumprice = detailtemps.Sum(l => l.SalePrice * l.Qty); var sumdiscount = detailtemps.Sum(l => ((l.Discount * l.SalePrice) / 100) * l.Qty); var sumvat = detailtemps.Sum(l => ((l.Vat * l.SalePrice) / 100) * l.Qty); var sumcustomerpayment = (sumprice + sumvat) - sumdiscount; if (sumcustomerpayment != saleInvoicePayments.Sum(l => l.Value)) { throw new Exception("Payments value is not match to invoice items sum prices"); } var header = new SaleInvoice() { InvoiceNumber = sino, UserID = userid, Description = description, CustomerID = customerid, SumPrice = sumprice, SumDiscount = sumdiscount, SumVat = sumvat }; saleInvoiceRepo.Add(header); var details = new List <SaleInvoiceDetails>(); foreach (var item in detailtemps) { details.Add(new SaleInvoiceDetails() { InvoiceID = header.Id, ProductID = item.ProductID, Qty = item.Qty, Vat = item.Vat, SalePrice = item.SalePrice, PurchasePrice = item.PurchasePrice, Discount = item.Discount, Description = item.Description }); stockLogRepo.Add(new StockLog() { ProductID = item.ProductID, Qty = -1 * item.Qty, InvoiceNumber = sino, TypeID = 2 }); stockRepo.SetProductStock(item.ProductID); } saleInvoiceDetailRepo.AddRange(details); saleInvoiceDetailsTempRepo.DeleteRange(detailtemps); saleInvoicePaymentRepo.AddRange(saleInvoicePayments); return(true); } catch (Exception ex) { return(false); } }
public bool SavePurchaseInvoice(int userid, int invoiceType, string description, int providerid, DateTime invoicedate) { try { var detailtemps = GetAllDetailsTemp(userid); if (detailtemps == null || detailtemps.Count() == 0) { throw new Exception("Purchase Detail Temp is Empty for this User"); } var pino = GetNewPurchaseInvoiceNo(); var header = new PurchaseInvoice() { InvoiceNumber = pino, UserID = userid, Description = description, ProviderID = providerid, InvoiceType = invoiceType, InvoiceDate = invoicedate, SumPrice = ((invoiceType == 1) ? 1 : -1) * detailtemps.Sum(l => l.Price * l.Qty), SumDiscount = ((invoiceType == 1) ? 1 : -1) * detailtemps.Sum(l => ((l.Discount * l.Price) / 100) * l.Qty), SumVat = ((invoiceType == 1) ? 1 : -1) * detailtemps.Sum(l => ((l.Vat * l.Price) / 100) * l.Qty) }; purchaseInvoiceRepo.Add(header); var details = new List <PurchaseInvoiceDetails>(); foreach (var item in detailtemps) { details.Add(new PurchaseInvoiceDetails() { InvoiceID = header.Id, ProductID = item.ProductID, Qty = ((invoiceType == 1) ? 1 : -1) * item.Qty, Vat = item.Vat, Price = item.Price, Discount = item.Discount, Description = item.Description }); stockLogRepo.Add(new StockLog() { ProductID = item.ProductID, Qty = ((invoiceType == 1) ? 1 : -1) * item.Qty, InvoiceNumber = pino, TypeID = 1 }); stockRepo.SetProductStock(item.ProductID); } purchaseInvoiceDetailRepo.AddRange(details); purchaseInvoiceDetailsTempRepo.DeleteRange(detailtemps); return(true); } catch (Exception ex) { return(false); } }