public int InsertPurchaseInvoice(EntityDebitNote entPurchaseInvoice, List <EntityDebitNoteDetails> lstInvoice) { try { int?id = 0; objData.STP_Insert_DebitNote(Convert.ToDateTime(entPurchaseInvoice.DNDate), Convert.ToInt32(entPurchaseInvoice.SupplierId), false, Convert.ToDecimal(entPurchaseInvoice.Amount), Convert.ToDecimal(entPurchaseInvoice.NetAmount), Convert.ToInt32(entPurchaseInvoice.Tax1), Convert.ToInt32(entPurchaseInvoice.Tax2), Convert.ToInt32(entPurchaseInvoice.Discount), ref id); foreach (EntityDebitNoteDetails item in lstInvoice) { tblDebitNoteDetail obj = new tblDebitNoteDetail() { DNNo = id, ProductCode = item.ProductCode, Quantity = item.Quantity, Price = item.Price, Amount = item.Amount, BatchNo = item.BatchNo, ExpiryDate = item.ExpiryDate, IsDelete = false }; tblStockDetail objStock = new tblStockDetail() { OpeningQty = 0, InwardQty = 0, InwardPrice = 0, InwardAmount = 0, BatchNo = item.BatchNo, ExpiryDate = item.ExpiryDate, OutwardQty = item.Quantity, OutwardPrice = item.Price, DocumentNo = id, IsDelete = false, ProductId = Convert.ToInt32(item.ProductCode), TransactionType = "DebitNote", OutwardAmount = item.Amount }; objData.tblStockDetails.InsertOnSubmit(objStock); objData.tblDebitNoteDetails.InsertOnSubmit(obj); } int TId = new PatientInvoiceBLL().GetTransactionId(); tblCustomerTransaction objCust = new tblCustomerTransaction() { PayAmount = entPurchaseInvoice.NetAmount, IsCash = false, IsDelete = false, SupplierId = entPurchaseInvoice.SupplierId, ReceiptDate = entPurchaseInvoice.DNDate, TransactionDocNo = id, TransactionId = TId, TransactionType = "DebitNote" }; objData.tblCustomerTransactions.InsertOnSubmit(objCust); objData.SubmitChanges(); } catch (Exception ex) { throw ex; } return(1); }
public static DebitNoteDetailModel ToModel(this tblDebitNoteDetail entity) { return(Mapper.Map <tblDebitNoteDetail, DebitNoteDetailModel>(entity)); }
public int Update(EntityDebitNote lstEdited, List <EntityDebitNoteDetails> lst) { int i = 0; try { tblDebitNote objTest = (from tbl in objData.tblDebitNotes where tbl.IsDelete == false && tbl.DNNo == lstEdited.DNNo select tbl).FirstOrDefault(); if (objTest != null) { objTest.Amount = lstEdited.Amount; objTest.NetAmount = lstEdited.NetAmount; objTest.SupplierId = lstEdited.SupplierId; objTest.DNDate = lstEdited.DNDate; objTest.Discount = lstEdited.Discount; objTest.Tax1 = lstEdited.Tax1; objTest.Tax2 = lstEdited.Tax2; } foreach (EntityDebitNoteDetails item in lst) { if (item.DNSrNo == 0) { tblDebitNoteDetail objNewAdded = new tblDebitNoteDetail() { DNNo = lstEdited.DNNo, ProductCode = item.ProductCode, Quantity = item.Quantity, Price = item.Price, Amount = item.Amount, BatchNo = item.BatchNo, ExpiryDate = item.ExpiryDate, IsDelete = false }; objData.tblDebitNoteDetails.InsertOnSubmit(objNewAdded); tblStockDetail stock = new tblStockDetail() { ProductId = Convert.ToInt32(item.ProductCode), OpeningQty = 0, InwardQty = 0, InwardPrice = 0, InwardAmount = 0, BatchNo = item.BatchNo, ExpiryDate = item.ExpiryDate, OutwardQty = item.Quantity, OutwardPrice = item.Price, OutwardAmount = item.Amount, TransactionType = "DebitNote", IsDelete = false, }; objData.tblStockDetails.InsertOnSubmit(stock); } else { tblDebitNoteDetail cnt = (from tbl in objData.tblDebitNoteDetails where tbl.IsDelete == false && tbl.DNSrNo == item.DNSrNo select tbl).FirstOrDefault(); if (cnt != null) { cnt.BatchNo = item.BatchNo; cnt.ExpiryDate = item.ExpiryDate; cnt.ProductCode = Convert.ToInt32(item.ProductCode); cnt.Quantity = item.Quantity; cnt.Price = item.Price; cnt.Amount = Convert.ToDecimal(item.Amount); cnt.IsDelete = item.IsDelete; } tblStockDetail stock = (from tbl in objData.tblStockDetails where tbl.IsDelete == false && tbl.DocumentNo == lstEdited.DNNo && tbl.ProductId == item.ProductCode && tbl.TransactionType.Equals("DebitNote") select tbl).FirstOrDefault(); if (stock != null) { stock.ProductId = Convert.ToInt32(item.ProductCode); stock.OpeningQty = 0; stock.InwardQty = 0; stock.InwardPrice = 0; stock.InwardAmount = 0; stock.BatchNo = item.BatchNo; stock.ExpiryDate = item.ExpiryDate; stock.OutwardQty = item.Quantity; stock.OutwardPrice = item.Price; stock.OutwardAmount = item.Amount; stock.IsDelete = Convert.ToBoolean(item.IsDelete); } } } #region Update Status of Order and Transaction tblCustomerTransaction transact = (from tbl in objData.tblCustomerTransactions where tbl.SupplierId == lstEdited.SupplierId && tbl.IsDelete == false && tbl.TransactionDocNo == lstEdited.DNNo && tbl.TransactionType.Equals("DebitNote") select tbl).FirstOrDefault(); if (transact != null) { transact.PayAmount = lstEdited.NetAmount; transact.ReceiptDate = lstEdited.DNDate; } objData.SubmitChanges(); #endregion i++; } catch (Exception ex) { i = 0; throw ex; } return(i); }