public RSmartTicketService() { _scaleLib = new ScaleLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); _scaleDetailLib = new ScaleDetailsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); _scaleAttachmentLib = new ScaleAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); _leadLogLib = new LeadLogLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); }
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; }
protected override void DeleteChildEntities(string[] childEntityList, string parentID) { foreach (string ChildEntity in childEntityList) { switch (ChildEntity) { #region /* Case Statements - All child grids */ case "ScaleDetails": if (Convert.ToInt32(parentID) > 0) { ScaleDetailsLibrary ScaleDetailsLibrary = new ScaleDetailsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); IEnumerable <ScaleDetails> resultList = ScaleDetailsLibrary.GetAllByParentID(Convert.ToInt32(parentID)); foreach (ScaleDetails scaleDetails in resultList) { ScaleDetailsLibrary.Delete(scaleDetails.ID.ToString()); } } break; case "ScaleNotes": if (Convert.ToInt32(parentID) > 0) { ScaleNotesLibrary ScaleNotesLibrary = new ScaleNotesLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); IEnumerable <ScaleNotes> resultList = ScaleNotesLibrary.GetAllByParentID(Convert.ToInt32(parentID)); foreach (ScaleNotes ScaleNote in resultList) { ScaleNotesLibrary.Delete(ScaleNote.ID.ToString()); } } break; case "ScaleAttachments": if (Convert.ToInt32(parentID) > 0) { ScaleAttachmentsLibrary ScaleLibrary = new ScaleAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); IEnumerable <ScaleAttachments> resultList = ScaleLibrary.GetAllByParentID(Convert.ToInt32(parentID)); foreach (ScaleAttachments scaleAttachment in resultList) { ScaleLibrary.Delete(scaleAttachment.ID.ToString()); } } break; //case "ScaleIDCardAttachments": // if (Convert.ToInt32(parentID) > 0) { // ScaleIDCardAttachmentsLibrary ScaleLibrary = new ScaleIDCardAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); // IEnumerable<ScaleIDCardAttachments> resultList = ScaleLibrary.GetAllByParentID(Convert.ToInt32(parentID)); // foreach (ScaleIDCardAttachments scaleAttachment in resultList) { // ScaleLibrary.Delete(scaleAttachment.ID.ToString()); // } // } //break; #endregion } } }
public void ValidItem(Scale entity) { IEnumerable <ScaleDetails> scaleDetails; if (entity.ID <= 0) { scaleDetails = (IList <ScaleDetails>)Session["ScaleDetails"]; } else { scaleDetails = new ScaleDetailsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()).GetAllByParentID(entity.ID, new string[] { "Scale", "Item_Received" }); } if (scaleDetails != null && scaleDetails.Count() > 0) { // Ticket Types are Receiving/Trading if (entity.Ticket_Type != null && new string[] { "receiving ticket", "trading" }.Any(s => s == entity.Ticket_Type.ToLower())) { ValidatePOItem(entity, scaleDetails); } // Ticket Types are Shipping/Trading else if (entity.Ticket_Type != null && new string[] { "shipping ticket", "trading" }.Any(s => s == entity.Ticket_Type.ToLower()) && entity.Container_No != null) { Container container = new ContainerLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()).GetByID(entity.Container_No.ID.ToString(), new string[] { "Booking.Sales_Order_No" }); if (container != null && container.Booking != null && container.Booking.Sales_Order_No != null) { ValidateSOItem(container.Booking.Sales_Order_No.ID, scaleDetails); } } // Ticket Types is Local Sale else if (entity.Ticket_Type != null && entity.Ticket_Type.ToLower() == "local sale" && entity.Sales_Order != null) { ValidateSOItem(entity.Sales_Order.ID, scaleDetails); } // Ticket Types is Brokerage. else if (entity.Ticket_Type != null && entity.Ticket_Type.ToLower() == "brokerage") { // Validate SO Item if (entity.Booking != null && entity.Booking.ID > 0) { BookingLibrary bookingLib = new BookingLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); Booking booking = bookingLib.GetByID(entity.Booking.ID.ToString(), new string[] { "Sales_Order_No" }); if (booking.Sales_Order_No != null) { ValidateSOItem(booking.Sales_Order_No.ID, scaleDetails); } } // Validate PO Item ValidatePOItem(entity, scaleDetails); } } }
private IEnumerable <ScaleDetails> GetDetailItemsByScaleId(int scaleID) { IEnumerable <ScaleDetails> scaleDetails; if (scaleID <= 0) { scaleDetails = (IList <ScaleDetails>)Session["ScaleDetails"]; } else { scaleDetails = new ScaleDetailsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()).GetAllByParentID(scaleID, new string[] { "Scale", "Item_Received" }); } return(scaleDetails); }
public ActionResult _MakePayment(Scale data, bool isNew = false) { try { // Start transaction. using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted })) { // Save scale record ActionResult result = base.Save(data); data = ModelFromActionResult <Scale>(result); if (data.Ticket_Settled == false) { // Settlement IEnumerable <ScaleDetails> scaleDetails = new ScaleDetailsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()).GetAllByParentID(data.ID); Settlement addSettlement = AddSettlement(data, scaleDetails); // Payment Settlement settlement = new SettlementLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()).GetByID(addSettlement.ID.ToString(), new string[] { "Scale.Party_ID" }); IEnumerable <SettlementDetails> settlementDetails = new SettlementDetailsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()).GetAllByParentID(settlement.ID); AddPayment(settlement, settlementDetails); // Cash AddCash(settlement); } // Complete transaction. scope.Complete(); ModelState.Clear(); } return(Display(data.ID.ToString())); } catch (Exception ex) { Response.StatusCode = 500; if (ex.GetBaseException() is smART.Common.DuplicateException) { ModelState.AddModelError("Error", ex.GetBaseException().Message); } else { ModelState.AddModelError("Error", ex.Message); } return(Display(data)); } }
public ActionResult _TicketHistory(string partyId, GridCommand command) { int totalRows = 0; int id = string.IsNullOrEmpty(partyId) ? 0 : Convert.ToInt32(partyId); IEnumerable <ScaleDetails> resultList = new ScaleDetailsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()) .GetAllByPartyIdWithPagging( id, 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", new string[] { "Scale", "Item_Received" }, (command.FilterDescriptors.Count == 0 ? null : command.FilterDescriptors) ); return(View(new GridModel { Data = resultList, Total = totalRows })); }
public ActionResult _TicketHistory(string partyId) { int totalRows = 0; int id = string.IsNullOrEmpty(partyId) ? 0 : Convert.ToInt32(partyId); ViewBag.PageSize = ConfigurationHelper.GetsmARTLookupGridPageSize(); IEnumerable <ScaleDetails> resultList = new ScaleDetailsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()) .GetAllByPartyIdWithPagging( id, out totalRows, 1, ViewBag.PageSize, "Created_Date", "Desc", new string[] { "Scale", "Item_Received" }, null ); ViewBag.PartyId = id; return(View("~/Views/Transaction/QScale/_TicketHistory.cshtml", resultList)); }
public bool IsLineItemExits(int scaleId) { bool exits = true; IEnumerable <ScaleDetails> resultList; if (scaleId <= 0) { resultList = (IList <ScaleDetails>)Session["ScaleDetails"]; } else { ScaleDetailsLibrary ScaleDetailsLibrary = new ScaleDetailsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); resultList = ScaleDetailsLibrary.GetAllByParentID(scaleId); } if (resultList == null || resultList.Count() <= 0) { exits = false; } return(exits); }
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)); }
protected override void SaveChildEntities(string[] childEntityList, Scale entity) { foreach (string ChildEntity in childEntityList) { switch (ChildEntity) { #region /* Case Statements - All child grids */ case "ScaleDetails": if (Session[ChildEntity] != null) { ScaleDetailsLibrary ScaleDetailsLibrary = new ScaleDetailsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); IEnumerable <ScaleDetails> resultList = (IList <ScaleDetails>)Session[ChildEntity]; foreach (ScaleDetails scaleDetails in resultList) { scaleDetails.Scale = new Scale { ID = entity.ID }; ScaleDetailsLibrary.Add(scaleDetails); } } break; case "ScaleNotes": if (Session[ChildEntity] != null) { ScaleNotesLibrary ScaleNotesLibrary = new ScaleNotesLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); IEnumerable <ScaleNotes> resultList = (IList <ScaleNotes>)Session[ChildEntity]; foreach (ScaleNotes ScaleNote in resultList) { ScaleNote.Parent = new Scale { ID = entity.ID }; //itemNote.Notes = System.Web.HttpUtility.HtmlDecode(itemNote.Notes); ScaleNotesLibrary.Add(ScaleNote); } } break; case "ScaleAttachments": if (Session[ChildEntity] != null) { ScaleAttachmentsLibrary ScaleLibrary = new ScaleAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); IEnumerable <ScaleAttachments> resultList = (IList <ScaleAttachments>)Session[ChildEntity]; string destinationPath; string sourcePath; FilelHelper fileHelper = new FilelHelper(); foreach (ScaleAttachments Scale in resultList) { destinationPath = fileHelper.GetSourceDirByFileRefId(Scale.Document_RefId.ToString()); // Path.Combine(Configuration.GetsmARTDocPath(), Scale.Document_RefId.ToString()); sourcePath = fileHelper.GetTempSourceDirByFileRefId(Scale.Document_RefId.ToString()); // Path.Combine(Configuration.GetsmARTTempDocPath(), Scale.Document_RefId.ToString()); Scale.Document_Path = fileHelper.GetFilePath(sourcePath); fileHelper.MoveFile(Scale.Document_Name, sourcePath, destinationPath); Scale.Parent = new Scale { ID = entity.ID }; ScaleLibrary.Add(Scale); } } break; //case "ScaleIDCardAttachments": // if (Session[ChildEntity] != null) { // ScaleIDCardAttachmentsLibrary ScaleLibrary = new ScaleIDCardAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); // IEnumerable<ScaleIDCardAttachments> resultList = (IList<ScaleIDCardAttachments>) Session[ChildEntity]; // string destinationPath; // string sourcePath; // FilelHelper fileHelper = new FilelHelper(); // foreach (ScaleIDCardAttachments Scale in resultList) { // destinationPath = fileHelper.GetSourceDirByFileRefId(Scale.Document_RefId.ToString());// Path.Combine(Configuration.GetsmARTDocPath(), Scale.Document_RefId.ToString()); // sourcePath = fileHelper.GetTempSourceDirByFileRefId(Scale.Document_RefId.ToString()); // Path.Combine(Configuration.GetsmARTTempDocPath(), Scale.Document_RefId.ToString()); // Scale.Document_Path = fileHelper.GetFilePath(sourcePath); // fileHelper.MoveFile(Scale.Document_Name, sourcePath, destinationPath); // Scale.Parent = new Scale { // ID = entity.ID // }; // ScaleLibrary.Add(Scale); // } // } // break; case "ScaleExpense": if (Session[ChildEntity] != null) { ScaleExpenseLibrary lib = new ScaleExpenseLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); IEnumerable <ExpensesRequest> resultList = (IList <ExpensesRequest>)Session[ChildEntity]; foreach (ExpensesRequest exp in resultList) { exp.Reference = new Invoice { ID = entity.ID }; exp.Reference_Table = entity.GetType().Name; exp.Reference_ID = entity.ID; lib.Add(exp); } } break; #endregion } } }
public HttpResponseMessage SaveTicket([FromBody] Ticket value) { try { if (value.Scale == null) { return(Request.CreateResponse(HttpStatusCode.BadRequest)); } // Start transaction. using (TransactionScope scope = new TransactionScope(TransactionScopeOption.Required, new TransactionOptions { IsolationLevel = IsolationLevel.ReadCommitted })) { smART.ViewModel.Scale newScale = new Scale(); // Add new party if already exists if (!string.IsNullOrEmpty(value.Scale.License_No)) { PartyLibrary partyLib = new PartyLibrary(ConString); Party party = partyLib.GetByLicenseNo(value.Scale.License_No); if (party != null) { newScale.Party_ID = party; } else { // Add new party party = new Party(); party.Party_Name = value.Scale.Customer_Name; party.Party_Short_Name = value.Scale.Customer_Name; party.License_No = value.Scale.License_No; party.Party_Type = "Individual"; party.Created_By = value.Scale.Created_By; party.Updated_By = value.Scale.Created_By; party.Created_Date = value.Scale.Created_Date; party.Last_Updated_Date = value.Scale.Created_Date; party.Active_Ind = true; party.IsActive = true; party.State = !string.IsNullOrEmpty(value.Scale.Customer_State) ? value.Scale.Customer_State.ToString().Trim() : ""; party.ACLicense_ID = value.Scale.Customer_ACLicense_ID; party.Party_DOB = value.Scale.Customer_DOB; //string dobString = value.Scale.Customer_DOB; //DateTime dobDt; //if (smART.Common.DateTimeHelper.IsValidDate(dobString, out dobDt)) // party.Party_DOB = dobDt; party = partyLib.Add(party); newScale.Party_ID = party; // Add new Address AddressBook address = new AddressBook(); address.Address1 = value.Scale.Customer_Address; address.City = value.Scale.Customer_City; address.State = value.Scale.Customer_State; address.Country = value.Scale.Customer_Country; address.Party = party; address.Created_By = value.Scale.Created_By; address.Updated_By = value.Scale.Created_By; address.Created_Date = value.Scale.Created_Date; address.Last_Updated_Date = value.Scale.Created_Date; address.Primary_Flag = true; address.Active_Ind = true; address.Zip_Code = value.Scale.Customer_Zip; AddressBookLibrary addressLib = new AddressBookLibrary(ConString); addressLib.Add(address); } } // Save Scale ScaleLibrary lib = new ScaleLibrary(ConString); newScale.Ticket_Status = "Open"; newScale.QScale = true; newScale.Gross_Weight = value.ScaleDetails.Sum(s => s.GrossWeight); newScale.Tare_Weight = value.ScaleDetails.Sum(s => s.TareWeight);; newScale.Net_Weight = value.ScaleDetails.Sum(s => s.NetWeight); value.Scale.MapServiceEntityToServerEntity(newScale); smART.ViewModel.Scale scale = lib.Add(newScale); // Save scale detail if (value.ScaleDetails != null) { ScaleDetailsLibrary libScaleDetail = new ScaleDetailsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); ItemLibrary libItem = new ItemLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); foreach (var item in value.ScaleDetails) { smART.ViewModel.ScaleDetails newScaleDetails = new smART.ViewModel.ScaleDetails(); newScaleDetails.Apply_To_Item = libItem.GetByID(item.Item_ID.ToString()); newScaleDetails.Item_Received = libItem.GetByID(item.Item_ID.ToString()); newScaleDetails.Scale = scale; item.MapServiceEntityToServerEntity(newScaleDetails); ScaleDetails scaleDetails = libScaleDetail.Add(newScaleDetails); // Set docuent related id if document is related to item if (value.ScaleAttachments != null && value.ScaleAttachments.Count > 0) { Model.ScaleAttachments modelAttach = value.ScaleAttachments.Where(w => w.Document_RelatedID == item.ID).FirstOrDefault(); if (modelAttach != null && modelAttach.Document_RelatedTo == 1) { modelAttach.Document_RelatedID = scaleDetails.ID; } } } } // Save Max Ticket ID in Device Settings DeviceSettingLibrary deviceLib = new DeviceSettingLibrary(ConString); DeviceSettings deviceSettings = deviceLib.GetByUniueID(scale.Unique_ID.Value); deviceSettings.MaxTicket_ID = value.Scale.ID; deviceLib.Modify(deviceSettings); // Save Attachments if (value.ScaleAttachments != null) { ScaleAttachmentsLibrary libAttach = new ScaleAttachmentsLibrary(ConfigurationHelper.GetsmARTDBContextConnectionString()); FilelHelper fileHelper = new FilelHelper(); foreach (var item in value.ScaleAttachments) { smART.ViewModel.ScaleAttachments newScaleAttachment = new smART.ViewModel.ScaleAttachments(); // Save file Guid docRefId = Guid.NewGuid(); string destinationPath = fileHelper.GetSourceDirByFileRefId(docRefId.ToString()); fileHelper.MoveFile(item.Document_Title, fileHelper.GetTempSourceDirByFileRefId(item.Document_Path), destinationPath); // Save attachment newScaleAttachment.Parent = scale; newScaleAttachment.Document_RefId = docRefId; newScaleAttachment.Document_Path = Path.Combine(destinationPath, item.Document_Title); item.MapServiceEntityToServerEntity(newScaleAttachment); libAttach.Add(newScaleAttachment); } } // Complete transaction. scope.Complete(); } return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception ex) { ExceptionHandler.HandleException(ex, "An error occured in SaveTicket."); //string details = string.Format("Method: {1} {0} Message: {2} {0} Stack Trace: {3}", System.Environment.NewLine, "SaveTicket", ex.Message, ex.StackTrace.ToString()); //smART.Common.MessageLogger.Instance.LogMessage(ex, details, Common.Priority.High, 0, System.Diagnostics.TraceEventType.Error, "Service Error", "Service"); return(Request.CreateResponse(HttpStatusCode.InternalServerError)); } }