public void AddUnPaidPurchaseScaleExpenses(int scaleId) { // Search for all expenses that matches scaleId. ExpensesRequestLibrary lib = new ExpensesRequestLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); string refTableName = new Model.Scale().GetType().Name; IEnumerable <ExpensesRequest> expenses = lib.GetAllPurchasingExepneseByRefTableAndRefId(scaleId, refTableName, new[] { "Payment", "Paid_Party_To" }); ScaleLibrary scaleLib = new ScaleLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); foreach (var item in expenses) { // If scale expense already exists. if (TempEntityList.FirstOrDefault(m => m.ID == item.ID) == null) { // Get scale entity Scale scale = scaleLib.GetByID(item.Reference_ID.ToString(), new string[] { "Dispatch_Request_No" }); if (item.Paid_Party_To == null) { item.Paid_Party_To = new Party(); } // Add eexpense to TempList. TempEntityList.Add(item); // Add dispatcher expense. if (scale.Dispatch_Request_No != null && scale.Dispatch_Request_No.ID > 0) { AddUnPaidPurchaseDispatcherExpenses(scale.Dispatch_Request_No.ID); } } } }
public ActionResult GetUnPaidTickets(GridCommand command, string partyId, string locationId = "0") { TempEntityList.Clear(); if (Convert.ToInt32(partyId) > 0) { string dbContextConnectionString = ConfigurationHelper.GetsmARTDBContextConnectionString(); SettlementLibrary settlementLib = new SettlementLibrary(); settlementLib.Initialize(dbContextConnectionString); IEnumerable <Settlement> results = settlementLib.GetUnPaidTickets(new string[] { "Scale", "Scale.Party_ID", "Scale.Purchase_Order", "Scale.Party_Address" }, int.Parse(partyId), int.Parse(locationId)); if (results != null && results.Count() > 0) { PaymentReceiptDetails paymentDetails; int id = 0; foreach (var item in results) { //if (item.Scale != null && item.Scale.Purchase_Order == null) { // item.Scale.Purchase_Order = new PurchaseOrder(); //} id += 1; paymentDetails = new PaymentReceiptDetails() { ID = id, Settlement = item, Balance_Amount = item.Amount - item.Amount_Paid_Till_Date, PaymentReceipt = new PaymentReceipt() }; TempEntityList.Add(paymentDetails); } } } return(Display(command, "0", true)); }
public JsonResult _GetTotal(string id) { int scaleID = int.Parse(id); decimal gw = 0; decimal nw = 0; decimal amt = 0; if (scaleID > 0) { IEnumerable <ScaleDetails> sDetails = new ScaleDetailsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()).GetAllByParentID(scaleID); gw = sDetails.Sum(i => i.GrossWeight); nw = sDetails.Sum(i => i.NetWeight); amt = sDetails.Sum(i => i.Amount); } else { gw = TempEntityList.Sum(i => i.GrossWeight); nw = TempEntityList.Sum(i => i.NetWeight); amt = TempEntityList.Sum(i => i.Amount); } var data = new { GW = gw, NW = nw, Amt = amt }; return(Json(data, JsonRequestBehavior.AllowGet)); //string str = string.Format("{0}#{1}#{2}", gw, nw, amt); //return str; }
private void AddNonInvoiceSellingDispatcherExpenses(int bookingId, string containerNo) { // Search for expenses that matches dispatcher id. DispatcherRequestLibrary dispathcerRequestLib = new DispatcherRequestLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); IEnumerable <DispatcherRequest> dispatcherReqs = dispathcerRequestLib.GetDispatcherByBookingAndContainerNo(bookingId, containerNo, new string[] { "Booking_Ref_No", "Container" }); foreach (DispatcherRequest dispatcherReq in dispatcherReqs) { ExpensesRequestLibrary lib = new ExpensesRequestLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); string refTableName = new Model.DispatcherRequest().GetType().Name; IEnumerable <ExpensesRequest> expenses = lib.GetAllPurchasingExepneseByRefTableAndRefId(dispatcherReq.ID, refTableName, new[] { "Payment", "Paid_Party_To", "Invoice" }); foreach (var item in expenses) { // If expense already exists. if (TempEntityList.FirstOrDefault(m => m.ID == item.ID) == null) { // If party is null. if (item.Paid_Party_To == null) { item.Paid_Party_To = new Party(); } // Add to TempList. TempEntityList.Add(item); } } } }
//[HttpPost] //public void RemoveUnPaidSellingExpenses(string bookingId) { // // If TEmpEntityList has no Items. // if (TempEntityList != null) { // int intBookingId = Convert.ToInt32(bookingId); // if (intBookingId > 0) { // // Get all scale exepenses. // IEnumerable<ExpensesRequest> scaleExps = from exp in TempEntityList // where exp.Reference_Table == "Scale" && exp.Reference_ID == intBookingId // select exp; // if (scaleExps != null) { // IList<ExpensesRequest> removeExpenses = new List<ExpensesRequest>(); // ScaleLibrary scaleLib = new ScaleLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); // foreach (var item in scaleExps) { // // Get scale entity. // Scale scale = scaleLib.GetByID(item.Reference_ID.ToString(), new string[] { "Dispatch_Request_No" }); // if (scale != null && scale.Dispatch_Request_No != null && scale.Dispatch_Request_No.ID > 0) { // // Get dispatcher id. // int dispatcherId = scale.Dispatch_Request_No.ID; // // Get all dispatcher expenses. // IEnumerable<ExpensesRequest> dispatcherExps = from exp in TempEntityList // where exp.Reference_Table == "DispatcherRequest" && exp.Reference_ID == dispatcherId // select exp; // if (dispatcherExps != null) { // foreach (var dispExp in dispatcherExps) { // // Add dispatcher expense in removeExpense list. // removeExpenses.Add(dispExp); // } // } // } // // Add scale expense in removeExpense list. // removeExpenses.Add(item); // } // // Delete scale and dispatcher expense. // foreach (var removeExp in removeExpenses) { // TempEntityList.Remove(removeExp); // } // } // } // } //} public void AddNonInvoiceSellingScaleExpenses(int bookingId) { TempEntityList.Clear(); ScaleLibrary scaleLib = new ScaleLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); IEnumerable <Scale> scales = scaleLib.GetScalesByBookingId(bookingId); // Search for all expenses that matches scaleId. ExpensesRequestLibrary lib = new ExpensesRequestLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); string refTableName = new Model.Scale().GetType().Name; foreach (var scale in scales) { IEnumerable <ExpensesRequest> expenses = lib.GetAllSellingExepneseByRefTableAndRefId(scale.ID, refTableName, new[] { "Payment", "Paid_Party_To", "Invoice" }); foreach (var expense in expenses) { // If scale expense already exists. if (TempEntityList.FirstOrDefault(m => m.ID == expense.ID) == null) { if (expense.Paid_Party_To == null) { expense.Paid_Party_To = new Party(); } // Add eexpense to TempList. TempEntityList.Add(expense); // Add dispatcher expense. } } AddNonInvoiceSellingDispatcherExpenses(bookingId, scale.ContainerNo); } }
public void RemoveUnPaidPurchaseExpenses(string scaleId) { // If TEmpEntityList has no Items. if (TempEntityList != null) { int intScaleId = Convert.ToInt32(scaleId); if (intScaleId > 0) { // Get all scale exepenses. IEnumerable <ExpensesRequest> scaleExps = from exp in TempEntityList where exp.Reference_Table == "Scale" && exp.Reference_ID == intScaleId select exp; if (scaleExps != null) { IList <ExpensesRequest> removeExpenses = new List <ExpensesRequest>(); ScaleLibrary scaleLib = new ScaleLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); foreach (var item in scaleExps) { // Get scale entity. Scale scale = scaleLib.GetByID(item.Reference_ID.ToString(), new string[] { "Dispatch_Request_No" }); if (scale != null && scale.Dispatch_Request_No != null && scale.Dispatch_Request_No.ID > 0) { // Get dispatcher id. int dispatcherId = scale.Dispatch_Request_No.ID; // Get all dispatcher expenses. IEnumerable <ExpensesRequest> dispatcherExps = from exp in TempEntityList where exp.Reference_Table == "DispatcherRequest" && exp.Reference_ID == dispatcherId select exp; if (dispatcherExps != null) { foreach (var dispExp in dispatcherExps) { // Add dispatcher expense in removeExpense list. removeExpenses.Add(dispExp); } } } // Add scale expense in removeExpense list. removeExpenses.Add(item); } // Delete scale and dispatcher expense. foreach (var removeExp in removeExpenses) { TempEntityList.Remove(removeExp); } } } } }
public ActionResult GetUnPaidInvoices(GridCommand command, string partyId) { int totalRows = 0; TempEntityList.Clear(); if (Convert.ToInt32(partyId) > 0) { string dbContextConnectionString = ConfigurationHelper.GetsmARTDBContextConnectionString(); InvoiceLibrary lib = new InvoiceLibrary(); lib.Initialize(dbContextConnectionString); IEnumerable <Invoice> results = lib.GetUnPaidInvoicesWithPaging(out totalRows, command.Page, command.PageSize == 0 ? 20 : command.PageSize, "", "Asc", new string[] { "Booking.Sales_Order_No.Party", "Sales_Order_No.Party" }, null, int.Parse(partyId) ); if (results != null && results.Count() > 0) { PaymentReceiptDetails paymentDetails; int id = 0; foreach (var item in results) { id += 1; if (item.Booking == null) { item.Booking = new Booking(); } paymentDetails = new PaymentReceiptDetails() { ID = id, Invoice = item, Balance_Amount = item.Net_Amt - item.Amount_Paid_Till_Date, PaymentReceipt = new PaymentReceipt() }; TempEntityList.Add(paymentDetails); } } } IEnumerable <PaymentReceiptDetails> resultList = TempEntityList; return(View(new GridModel { Data = resultList, Total = totalRows })); }
protected override ActionResult Display(GridCommand command, string id, bool isNew) { int totalRows = 0; IEnumerable <CycleDetails> resultList; if (isNew == true || id == "0") { if (TempEntityList.Count <= 0) { ItemLibrary ItemLibrary = new smART.Library.ItemLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); IEnumerable <Item> itemList = ItemLibrary.GetAll().Where(o => o.IsActive == true && o.Active_Ind == true); int iValue = 1; foreach (var item in itemList) { CycleDetails cycleDetails = new CycleDetails(); cycleDetails.Item = item; cycleDetails.ID = iValue; TempEntityList.Add(cycleDetails); iValue++; } resultList = TempEntityList; Session["CycleDetails"] = TempEntityList; } else { resultList = _cycleDetailsOps.GetAllByPaging(TempEntityList, out totalRows, command.Page, command.PageSize, command.SortDescriptors.Count == 0 ? "" : command.SortDescriptors[0].Member, command.SortDescriptors.Count == 0 ? "" : command.SortDescriptors[0].SortDirection == System.ComponentModel.ListSortDirection.Descending ? "Desc" : "Asc", IncludePredicates, (command.FilterDescriptors.Count == 0 ? null : command.FilterDescriptors) ); } Session["CycleDetails"] = TempEntityList; totalRows = TempEntityList.Count; } else { resultList = ((IParentChildLibrary <CycleDetails>)Library).GetAllByPagingByParentID(out totalRows, int.Parse(id.ToString()), command.Page, command.PageSize == 0 ? 20 : command.PageSize, "", "Asc", IncludePredicates); } return(View(new GridModel { Data = resultList, Total = totalRows })); }
public string _GetTotalAppliedAmount(string id) { decimal totalApplyAmt = 0; int parentId = Convert.ToInt32(id); if (parentId > 0) { PaymentReceiptDetailsLibrary lib = new PaymentReceiptDetailsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); IEnumerable <PaymentReceiptDetails> resultList = lib.GetAllByParentID(parentId); totalApplyAmt = resultList.Sum(s => s.Apply_Amount); return(totalApplyAmt.ToString()); } if (Session["PaymentDetails"] != null && ((IList <PaymentReceiptDetails>)Session["PaymentDetails"]).Count > 0) { totalApplyAmt = TempEntityList.Sum(s => s.Apply_Amount); } return(totalApplyAmt.ToString()); }
//protected override ActionResult Display(GridCommand command, string id, bool isNew) //{ // int totalRows = 0; // IEnumerable<LOV> resultList; // = ((IParentChildLibrary<TEntity>)Library).GetAllByPagingByParentID(out totalRows, int.Parse(id.ToString()), command.Page, command.PageSize==0?20:command.PageSize, "", "Asc", IncludePredicates); // if (Convert.ToInt32(id)>0) // ViewBag.Parent_Type_ID = id; // if (isNew || id == "0") // { // resultList = TempEntityList; // totalRows = TempEntityList.Count; // } // else // { // resultList = (Library.GetAllByPagingByParentID(out totalRows, int.Parse(id.ToString()), command.Page, command.PageSize == 0 ? 20 : command.PageSize, "", "Asc", IncludePredicates)); // //resultList = ((IParentChildLibrary<TEntity>)Library).GetAllByPagingByParentID(out totalRows, int.Parse(id.ToString()), command.Page, command.PageSize, "", "Asc", IncludePredicates); // } // return View(new GridModel { Data = resultList, Total = totalRows }); //} //protected override ActionResult Display(GridCommand command, LOV entity, bool isNew = false) //{ // if (entity.LOVType != null && entity.LOVType.ID != 0) // return Display(command, entity.LOVType.ID.ToString(), isNew); // else // return base.Display(command, entity, isNew); //} //[HttpPost] //public virtual ActionResult GetByParentID(string id) //{ // IEnumerable<LOV> resultList = Library.GetAllByParentID(int.Parse(id)); // SelectList list = new SelectList(resultList, "ListValue", "ListText"); // return Json(list); //} //[HttpPost] //[GridAction(EnableCustomBinding = true)] //public ActionResult _GetAllLOV(GridCommand command) { // int totalRows = 0; // IEnumerable<LOV> resultList = new LOVLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()).GetAllByPaging( // out totalRows, command.Page, // (command.PageSize == 0 ? 20 : command.PageSize), // "", "Asc", new string[] { "LOVType" }, // (command.FilterDescriptors.Count == 0 ? null : command.FilterDescriptors) // ); // return View(new GridModel { // Data = resultList, // Total = totalRows // }); //} protected override void ValidateEntity(smART.ViewModel.CycleDetails entity) { ModelState.Clear(); if (entity.Item == null || entity.Item.ID == 0) { ModelState.AddModelError("EmptyItem", "Item is required."); } // Check duplicate item if (entity.Cycle.ID == 0) { CycleDetails cycleDetails = TempEntityList.FirstOrDefault <CycleDetails>(s => s.Item.ID == entity.Item.ID && s.ID != entity.ID); if (cycleDetails != null) { ModelState.AddModelError("EmptyItem", "Similar transaction already exists. Please click on search button and fetch existing record."); } } }
public override ActionResult _Update(PaymentReceiptDetails data, GridCommand command, bool isNew = false) { try { if (data.Apply_Amount == data.Balance_Amount) { data.Paid_In_Full = true; } ValidateEntity(data); if (ModelState.IsValid) { if (isNew) { //TODO: Add logic to update in memory data TempEntityList.SingleOrDefault(m => m.ID == data.ID).InjectFrom(data); //UpdateUnPaidExpenses(data); } else { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted })) { Library.Modify(data, new string[] { "Settlement", "PaymentReceipt", "ExpenseRequest" }); scope.Complete(); } } } } catch (Exception ex) { if (ex.GetBaseException() is smART.Common.DuplicateException) { ModelState.AddModelError("Error", ex.GetBaseException().Message); } else { ModelState.AddModelError("Error", ex.Message); } } return(Display(command, data.PaymentReceipt.ID.ToString(), isNew)); }
protected override ActionResult Display(GridCommand command, string id, bool isNew) { int totalRows = 0; IEnumerable <PriceListItem> resultList; // = ((IParentChildLibrary<TEntity>)Library).GetAllByPagingByParentID(out totalRows, int.Parse(id.ToString()), command.Page, command.PageSize==0?20:command.PageSize, "", "Asc", IncludePredicates); //if (isNew==true || id=="0" || id==null) if (isNew == true || id == "0") { //PriceListItem priceListItem = new PriceListItem(); //priceListItem.Item = new Item() { ID=1,Item_Category="A",Item_Group="B",Long_Name="Item1",Short_Name="I1",Site_Org_ID=1,Priced=true,Active_Ind=true}; //TempEntityList.Add(priceListItem); if (id == "-1") { string dbContextConnectionString = ConfigurationHelper.GetsmARTDBContextConnectionString(); ItemLibrary ItemLibrary = new smART.Library.ItemLibrary(); ItemLibrary.Initialize(dbContextConnectionString); IEnumerable <Item> itemList = ItemLibrary.GetAll().Where(o => o.Priced == true); int iValue = 1; foreach (var item in itemList) { PriceListItem priceListItem = new PriceListItem(); priceListItem.Item = item; priceListItem.ID = iValue; TempEntityList.Add(priceListItem); iValue++; //((PriceListItemLibrary)Library).Add(priceListItem); } } resultList = TempEntityList; totalRows = TempEntityList.Count; } else { resultList = ((IParentChildLibrary <PriceListItem>)Library).GetAllByPagingByParentID(out totalRows, int.Parse(id.ToString()), command.Page, command.PageSize == 0 ? 20 : command.PageSize, "", "Asc", IncludePredicates); //resultList = ((IParentChildLibrary<PriceListItem>)Library).GetAllByPagingByParentID(out totalRows, int.Parse(id.ToString()), command.Page, command.PageSize, "", "Asc", IncludePredicates); } return(View(new GridModel { Data = resultList, Total = totalRows })); }
public override ActionResult _Insert(TEntity data, GridCommand command, bool isNew = false) { try { string docRefId = Convert.ToString(TempData["DocRefId"]); if (string.IsNullOrEmpty(docRefId)) { ModelState.AddModelError("docRefId", "Error occured on save document."); } if (ModelState.IsValid) { data.Document_RefId = Guid.Parse(docRefId); data = UpdateFileInfo(data, _fileHelper.GetTempSourceDirByFileRefId(docRefId)); data.Last_Updated_Date = DateTime.Now; data.Updated_By = User.Identity.Name; // HttpContext.Current.User.Identity.Name; if (isNew) { data.Document_Path = _fileHelper.GetFilePath(_fileHelper.GetTempSourceDirByFileRefId(docRefId)); // Path.Combine(Configuration.GetsmARTTempDocPath(), docRefId, data.Document_Name); TempEntityList.Add(data); } else { data.Document_Path = _fileHelper.GetFilePath(_fileHelper.GetSourceDirByFileRefId(docRefId));// Path.Combine(Configuration.GetsmARTDocPath(), docRefId, data.Document_Name); data = Library.Add(data); string destinationPath = _fileHelper.GetSourceDirByFileRefId(docRefId); // Path.Combine(Configuration.GetsmARTDocPath(), docRefId); string sourcePath = _fileHelper.GetTempSourceDirByFileRefId(docRefId); // Path.Combine(Configuration.GetsmARTTempDocPath(), docRefId); _fileHelper.MoveFile(data.Document_Name, sourcePath, destinationPath); } UpdateAttachmentImagePath(data); TempData["DocRefId"] = null; } } catch (Exception ex) { ModelState.AddModelError("Error", ex.Message); } return(Display(command, data, isNew)); }
public ActionResult _InsertUpdate(ScaleDetails data, GridCommand command, bool isNew = false) { data.Split_Value = 100; if (data.ID > 0) { return(_Update(data, command, isNew)); } else { ScaleDetails tempItem = TempEntityList.FirstOrDefault(i => i.Item_Received.ID == data.Item_Received.ID); if (tempItem == null) { return(_Insert(data, command, isNew)); } else { data.ID = tempItem.ID; return(_Update(data, command, isNew)); } } }
public override ActionResult _Delete(string id, GridCommand command, string MasterID = null, bool isNew = false) { AddressBook entity; if (isNew) { //TODO: Delete entity with id entity = TempEntityList.FirstOrDefault(m => m.ID == int.Parse(id)); } else { entity = Library.GetByID(id); } if (entity.Primary_Flag == true) { ModelState.AddModelError("delete", "Can't delete primary address"); } return(base._Delete(id, command, MasterID, isNew)); }
public ActionResult GetUnPaidExpenses(GridCommand command, string partyId, string bookingId = "0") { TempEntityList.Clear(); if (Convert.ToInt32(partyId) > 0) { string dbContextConnectionString = ConfigurationHelper.GetsmARTDBContextConnectionString(); ExpensesRequestLibrary lib = new ExpensesRequestLibrary(); lib.Initialize(dbContextConnectionString); IEnumerable <ExpensesRequest> results = lib.GetUnPaidExpenses(new string[] { "Paid_Party_To", "Scale_Ref", "Dispatcher_Request_Ref.Booking_Ref_No", "Dispatcher_Request_Ref.Container" }, int.Parse(partyId), int.Parse(bookingId) ); if (results != null && results.Count() > 0) { PaymentReceiptDetails paymentDetails; int id = 0; foreach (var item in results) { id += 1; paymentDetails = new PaymentReceiptDetails() { ID = id, ExpenseRequest = item, Balance_Amount = Convert.ToDecimal(item.Amount_Paid - item.Amount_Paid_Till_Date), PaymentReceipt = new PaymentReceipt() }; if (paymentDetails.Settlement != null) { paymentDetails.Settlement.Scale = null; } if (paymentDetails.ExpenseRequest.Dispatcher_Request_Ref != null) { paymentDetails.ExpenseRequest.Dispatcher_Request_Ref.TruckingCompany = null; } TempEntityList.Add(paymentDetails); } } } return(Display(command, "0", true)); }
public override ActionResult _Update(PaymentReceiptDetails data, GridCommand command, bool isNew = false) { try { if (!isNew && !IsApplied_AmountZero(data)) { ModelState.AddModelError("Applied_Amount", "Receipt details amount mismetch to total amount."); } if (ModelState.IsValid) { if (isNew) { //TODO: Add logic to update in memory data TempEntityList.SingleOrDefault(m => m.ID == data.ID).InjectFrom(data); } else { using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted })) { Library.Modify(data, new string[] { "Invoice", "PaymentReceipt" }); scope.Complete(); } } } } catch (Exception ex) { if (ex.GetBaseException() is smART.Common.DuplicateException) { ModelState.AddModelError("Error", ex.GetBaseException().Message); } else { ModelState.AddModelError("Error", ex.Message); } } return(Display(command, data.PaymentReceipt.ID.ToString(), isNew)); }
private void SetPrimaryAddress(AddressBook entity) { IEnumerable <AddressBook> resultList = null; if (entity.Party.ID > 0) { resultList = new AddressBookLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()).GetAllByParentID(entity.Party.ID); } else { resultList = (IList <AddressBook>)Session["AddressBook"]; } if (entity.Primary_Flag == true) { var oldPrimaryAdd = resultList == null ? null : resultList.Where(o => o.Primary_Flag == true && o.ID != entity.ID).FirstOrDefault(); if (oldPrimaryAdd != null) { oldPrimaryAdd.Primary_Flag = false; if (entity.Party.ID > 0) { Library.Modify(oldPrimaryAdd); } else { TempEntityList.SingleOrDefault(m => m.ID == oldPrimaryAdd.ID).InjectFrom(oldPrimaryAdd); } } } else { var oldPrimaryAdd = resultList == null ? null : resultList.Where(o => o.Primary_Flag == true).FirstOrDefault(); if (oldPrimaryAdd == null) { entity.Primary_Flag = true; } } }
public override ActionResult _Delete(string id, GridCommand command, string MasterID = null, bool isNew = false) { string filePath; string fileName; try { if (isNew) { //TODO: Delete entity with id TEntity entity = TempEntityList.SingleOrDefault(m => m.ID == int.Parse(id)); filePath = _fileHelper.GetTempSourceDirByFileRefId(entity.Document_RefId.ToString());// Path.Combine(Configuration.GetsmARTTempDocPath(), entity.Document_RefId.ToString()); fileName = entity.Document_Name; TempEntityList.Remove(entity); } else { TEntity entity = Library.GetByID(id); filePath = _fileHelper.GetSourceDirByFileRefId(entity.Document_RefId.ToString()); fileName = entity.Document_Name; Library.Delete(id); } _fileHelper.RemoveFile(fileName, filePath); } catch (Exception ex) { ModelState.AddModelError("Error", ex.Message); } if (string.IsNullOrEmpty(MasterID)) { return(Display(command, isNew)); } else { return(Display(command, MasterID, isNew)); } }
private void AddUnPaidPurchaseDispatcherExpenses(int dispathcerId) { // Search for expenses that matches dispatcher id. ExpensesRequestLibrary lib = new ExpensesRequestLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); string refTableName = new Model.DispatcherRequest().GetType().Name; IEnumerable <ExpensesRequest> expenses = lib.GetAllPurchasingExepneseByRefTableAndRefId(dispathcerId, refTableName, new[] { "Payment", "Paid_Party_To" }); foreach (var item in expenses) { // If expense already exists. if (TempEntityList.FirstOrDefault(m => m.ID == item.ID) == null) { // If party is null. if (item.Paid_Party_To == null) { item.Paid_Party_To = new Party(); } // Add to TempList. TempEntityList.Add(item); } } }
public override ActionResult _Insert(SettlementDetails data, GridCommand command, bool isNew = false) { ModelState.Clear(); Validate(data); if (ModelState.IsValid) { ScaleDetailsLibrary ScaleDetailsLibrary = new ScaleDetailsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); ScaleDetails scaleDetails = ScaleDetailsLibrary.GetByID(data.Scale_Details_ID.ID.ToString(), new string[] { "Scale", "Scale.Purchase_Order", "Item_Received", "Apply_To_Item" }); data.Scale_Details_ID.Scale.ID = scaleDetails.Scale.ID; data.Scale_Details_ID.Apply_To_Item = scaleDetails.Apply_To_Item; data.Scale_Details_ID.Scale = scaleDetails.Scale; data.Scale_Details_ID.Contamination_Weight = scaleDetails.Contamination_Weight; data.Scale_Details_ID.Split_Value = scaleDetails.Split_Value; if (string.IsNullOrWhiteSpace(data.Item_UOM) || data.Item_UOM == "LBS") { data.Item_UOM = "LBS"; data.Item_UOM_Conv_Fact = 1; data.Item_UOM_NetWeight = data.Actual_Net_Weight; } TempEntityList.SingleOrDefault(m => m.Scale_Details_ID.ID == data.Scale_Details_ID.ID).InjectFrom(data); ModelState.Clear(); } return(Display(command, data.Scale_Details_ID.Scale.ID.ToString(), isNew)); }
public ActionResult _Index(GridCommand command, int id) { int totalRows = 0; //Delete entity from TempEntityList if exits. if (TempEntityList != null && TempEntityList.Count > 0) { IList <SettlementDetails> settlementDetails = (from data in TempEntityList where data.Scale_Details_ID.Scale.ID == id select data as SettlementDetails).ToList <SettlementDetails>(); foreach (var item in settlementDetails) { TempEntityList.Remove(item); } } //Get all unsettled scale details tickets string dbContextConnectionString = ConfigurationHelper.GetsmARTDBContextConnectionString(); ScaleDetailsLibrary scaleDetailsLibrary = new smART.Library.ScaleDetailsLibrary(); scaleDetailsLibrary.Initialize(dbContextConnectionString); IEnumerable <ScaleDetails> scaleDetailsList = scaleDetailsLibrary.GetAllByPagingByParentID (out totalRows, int.Parse(id.ToString()), 1, 20, "", "Asc", new string[] { "Scale", "Scale.Purchase_Order", "Item_Received", "Apply_To_Item" } ); // Create temp settlement details collection by scale details tickets int iValue = 1; PurchaseOrderItemLibrary poItemLibrary = new smART.Library.PurchaseOrderItemLibrary(); poItemLibrary.Initialize(dbContextConnectionString); foreach (var item in scaleDetailsList) { SettlementDetails settlementDetails = new SettlementDetails(); settlementDetails.ID = iValue; settlementDetails.Scale_Details_ID = item; settlementDetails.Actual_Net_Weight = settlementDetails.Scale_Details_ID.NetWeight; //Get rate from PO Item if (item.Scale.Purchase_Order != null) { PurchaseOrderItem poItem = poItemLibrary.GetPOItemByItemCode(item.Scale.Purchase_Order.ID, item.Item_Received.ID, null); // If po item exits then update rate and amount. if (poItem != null) { settlementDetails.Rate = poItem.Price; settlementDetails.Item_UOM = poItem.Ordered_Qty_UOM; // If po item unit is not lbs. if (!string.IsNullOrWhiteSpace(settlementDetails.Item_UOM) && settlementDetails.Item_UOM.ToLower() != "lbs") { UOMConversionLibrary uomConvLib = new UOMConversionLibrary(); uomConvLib.Initialize(dbContextConnectionString); UOMConversion uomConv = uomConvLib.GetByUOM(poItem.Ordered_Qty_UOM, "LBS"); // When convertion factor not exits. if (uomConv != null) { settlementDetails.Item_UOM_Conv_Fact = (decimal)uomConv.Factor; settlementDetails.Item_UOM_NetWeight = settlementDetails.Actual_Net_Weight / (decimal)uomConv.Factor; settlementDetails.Item_UOM_NetWeight = decimal.Round(settlementDetails.Item_UOM_NetWeight, 3, MidpointRounding.AwayFromZero); } else { settlementDetails.Item_UOM_Conv_Fact = 1; settlementDetails.Item_UOM_NetWeight = settlementDetails.Actual_Net_Weight; } } // When Unit is default. Set default unit. else { SetDefaultUnit(settlementDetails); } settlementDetails.Amount = settlementDetails.Item_UOM_NetWeight * poItem.Price; settlementDetails.Amount = decimal.Round(settlementDetails.Amount, 2, MidpointRounding.AwayFromZero); } else { // When PO Item not exists.Set default unit. SetDefaultUnit(settlementDetails); } } // When PO not exists.Set default unit. else { SetDefaultUnit(settlementDetails); } settlementDetails.Settlement_ID = new Settlement(); settlementDetails.Price_List_ID = new PriceList(); TempEntityList.Add(settlementDetails); iValue++; } return(Display(command, id.ToString(), true)); }