public ActionResult Save(PrqChemLocalPurcBill model) { _userId = Convert.ToInt32(Session["UserID"]); const string url = "ChemLocalPurcBillEnt/ChemLocalPurcBillEnt"; //model.OtherCost = 0; _validationMsg = _chemLocalPurcBillEnt.Save(model, _userId, url); return(Json(_validationMsg, JsonRequestBehavior.AllowGet)); }
private PrqChemLocalPurcBill SetToBillModel(PRQ_ChemLocalPurcBill entity) { var model = new PrqChemLocalPurcBill(); model.BillId = entity.BillID; model.BillNo = entity.BillNo; model.BillDate = string.Format("{0:dd/MM/yyyy}", entity.BillDate); model.SupplierName = entity.SupplierID == null ? "" : _unit.SysSupplierRepository.GetByID(entity.SupplierID).SupplierName; model.SupplierBillNo = entity.SupplierBillNo; model.RecordStatus = DalCommon.ReturnRecordStatus(entity.RecordStatus); return(model); }
private PRQ_ChemLocalPurcBill BillConversion(PrqChemLocalPurcBill model, int userId, string url) { var entity = model.BillId == 0 ? new PRQ_ChemLocalPurcBill() : (from b in _context.PRQ_ChemLocalPurcBill.AsEnumerable() where b.BillID == model.BillId select b).FirstOrDefault(); entity.BillID = model.BillId; entity.BillNo = model.BillId == 0 ? DalCommon.GetPreDefineNextCodeByUrl(url) : model.BillNo; entity.BillDate = DalCommon.SetDate(model.BillDate); entity.PurchaseYear = model.PurchaseYear; entity.SupplierID = model.SupplierId; entity.SupplierAddressID = model.SupplierAddressId; entity.SupplierBillNo = model.SupplierBillNo; entity.SupBillDate = DalCommon.SetDate(model.SupBillDate); entity.BillCategory = "Real"; entity.BillType = "Supplier"; entity.Currency = model.Currency; entity.ExchangRate = model.ExchangRate; entity.ExchangCurrency = model.ExchangCurrency; entity.ExchangValue = model.ExchangValue; entity.BillAmt = model.BillAmt; entity.VatAmt = model.VatAmt; entity.DiscountPercent = model.DiscountPercent; entity.DiscountAmt = model.DiscountAmt; entity.PayableAmt = model.PayableAmt; entity.RecordStatus = model.BillId == 0 ? "NCF" : model.RecordStatus; entity.SetBy = model.BillId == 0 ? userId : _unit.ChemicalLocalPurchaseBillRepository.GetByID(model.BillId).SetBy; entity.SetOn = model.BillId == 0 ? DateTime.Now : _unit.ChemicalLocalPurchaseBillRepository.GetByID(model.BillId).SetOn; entity.ModifiedBy = model.BillId == 0 ? (int?)null : userId; entity.ModifiedOn = model.BillId == 0 ? (DateTime?)null : DateTime.Now; return(entity); }
public ActionResult GetBillById(long billId) { var bill = _unit.ChemicalLocalPurchaseBillRepository.GetByID(billId); var result = new PrqChemLocalPurcBill { BillId = bill.BillID, BillNo = bill.BillNo, BillDate = string.Format("{0:dd/MM/yyyy}", bill.BillDate), PurchaseYear = bill.PurchaseYear, SupplierId = bill.SupplierID, SupplierName = _unit.SysSupplierRepository.GetByID(bill.SupplierID).SupplierName, SupplierAddressId = bill.SupplierAddressID, SupplierAddress = _unit.SupplierAddressRepository.GetByID(bill.SupplierAddressID).Address, SupplierBillNo = bill.SupplierBillNo, SupBillDate = string.Format("{0:dd/MM/yyyy}", bill.SupBillDate), BillAmt = bill.BillAmt, VatAmt = bill.VatAmt, DiscountAmt = bill.DiscountAmt, DiscountPercent = bill.DiscountPercent, PayableAmt = bill.PayableAmt, ExchangCurrency = bill.ExchangCurrency, ExchangRate = bill.ExchangRate, Currency = bill.Currency, ExchangValue = bill.ExchangValue, CheckComments = bill.CheckComments, ApprovalComments = bill.ApprovalComments, RecordStatus = bill.RecordStatus, References = _unit.ChemicalLocalPurchaseBillReferenceRepository.Get().Where(ob => ob.BillID == bill.BillID) .Select(reff => new PrqChemLocalPurcBillRef { BillRefId = reff.BillRefID, BillId = reff.BillID, OrderID = reff.OrderID, ReceiveID = reff.ReceiveID, OrderNo = _unit.ChemicalPurchaseOrderRepository.GetByID(reff.OrderID).OrderNo, OrderDate = string.Format("{0:dd/MM/yyyy}", _unit.ChemicalPurchaseOrderRepository.GetByID(reff.OrderID).OrderDate), ReceiveNo = _unit.ChemicalLocalPurchaseReceiveRepository.GetByID(reff.ReceiveID).ReceiveNo, ReceiveDate = string.Format("{0:dd/MM/yyyy}", _unit.ChemicalLocalPurchaseReceiveRepository.GetByID(reff.ReceiveID).ReceiveDate), Items = _unit.ChemicalLocalPurchaseBillItemRepository.Get().Where(ob => ob.BillRefID == reff.BillRefID) .Select(item => new PrqChemLocalPurcBillItem { BillItemId = item.BillItemID, BillRefId = item.BillRefID, ItemId = item.ItemID, SupplierId = item.SupplierID, PackSize = item.PackSize, SizeUnit = item.SizeUnit, PackQty = item.PackQty, ReceiveQty = item.ReceiveQty, UnitId = item.UnitID, UnitPrice = item.UnitPrice, TotalPrice = item.TotalPrice, ManufacturerId = item.ManufacturerID, ItemName = item.ItemID == null ? "" : _unit.SysChemicalItemRepository.GetByID(item.ItemID).ItemName, PackSizeName = item.PackSize == null ? "" : _unit.SysSizeRepository.GetByID(item.PackSize).SizeName, SizeUnitName = item.SizeUnit == null ? "" : _unit.SysUnitRepository.GetByID(item.SizeUnit).UnitName, UnitName = item.UnitID == null ? "" : _unit.SysUnitRepository.GetByID(item.UnitID).UnitName, ManufacturerName = item.ManufacturerID == null ? "" : _unit.SysSupplierRepository.GetByID(item.ManufacturerID).SupplierName }).ToList() }).ToList(), }; return(Json(result, JsonRequestBehavior.AllowGet)); }
public ValidationMsg Save(PrqChemLocalPurcBill model, int userId, string url) { try { using (var tx = new TransactionScope()) { using (_context) { var bill = BillConversion(model, userId, url); if (model.BillId == 0) { _context.PRQ_ChemLocalPurcBill.Add(bill); _context.SaveChanges(); _mode = 1; } else { _context.SaveChanges(); _mode = 2; } if (model.References != null) { foreach (var reference in model.References) { var entityRef = BillReferenceConversion(reference, userId, bill.BillID); if (reference.BillRefId == 0) { _context.PRQ_ChemLocalPurcBillRef.Add(entityRef); _context.SaveChanges(); } else { _context.SaveChanges(); } if (reference.Items != null) { foreach (var item in reference.Items) { var entityItem = BillItemConversion(item, userId, bill.BillID, entityRef.BillRefID); if (item.BillItemId == 0) { _context.PRQ_ChemLocalPurcBillItem.Add(entityItem); _context.SaveChanges(); } else { _context.SaveChanges(); } } } } } tx.Complete(); if (_mode == 1) { _validationMsg.ReturnId = bill.BillID; _validationMsg.ReturnCode = bill.BillNo; _validationMsg.Type = Enums.MessageType.Success; _validationMsg.Msg = "Saved successfully."; } if (_mode == 2) { _validationMsg.Type = Enums.MessageType.Update; _validationMsg.Msg = "Updated successfully."; } } } } catch { _validationMsg.Type = Enums.MessageType.Error; _validationMsg.Msg = "Failed to save."; } return(_validationMsg); }