public void TestQuoteServices_add_new_quote() { var sa = GetUserSessionModel("*****@*****.**"); var activequote = db.Quotes.Where(q => q.Title == "Quote 2").FirstOrDefault(); var response = service.GetQuoteModel(sa, activequote); var quotemodel = response.Model as QuoteModel; quotemodel.Title = "New title"; quotemodel.Description = "New desc"; quotemodel.IsCommissionScheme = false; quotemodel.Multiplier = 11; quotemodel.TotalFreight = 22; quotemodel.Notes = "New notes"; quotemodel.IsGrossMargin = true; quotemodel.CommissionPercentage = 123; response = service.PostModel(sa, quotemodel); var newquote = db.Quotes.Where(q => q.ProjectId == activequote.ProjectId && q.Title == "New title").FirstOrDefault(); Assert.IsNotNull(newquote); Assert.AreEqual(newquote.Title, quotemodel.Title); Assert.AreEqual(newquote.Description, quotemodel.Description); Assert.AreEqual(newquote.TotalFreight, quotemodel.TotalFreight); Assert.AreEqual(newquote.Notes, quotemodel.Notes); Assert.AreEqual(newquote.IsGrossMargin, quotemodel.IsGrossMargin); Assert.AreEqual(newquote.CommissionPercentage * 100, quotemodel.CommissionPercentage); }
public ServiceResponse GetQuoteModel(long?projectId, long?quoteId) { if (projectId == null && quoteId != null) { projectId = quoteService.GetProjectIdByQuoteId(this.CurrentUser, quoteId.Value); } return(quoteService.GetQuoteModel(this.CurrentUser, projectId, quoteId)); }
public void TestQuoteServices_GetQuoteModel_ShouldReturnQuoteModel(string testValue) { if (testValue == "GetQuoteModel") { //make sure it return existed QuoteModel based on ProjectId and Quoteid this.Response = quoteService.GetQuoteModel(user, _projectId, _quoteId); Assert.That(this.Response.HasError, Is.EqualTo(false)); QuoteModel model = this.Response.Model as QuoteModel; Assert.That(model, Is.Not.EqualTo(null)); Assert.That(model.Title, Is.Not.EqualTo(string.Empty)); Assert.That(model.ProjectId, Is.EqualTo(_projectId)); Assert.That(model.QuoteId, Is.EqualTo(_quoteId)); } else if (testValue == "CreateQuoteModel") { //make sure if return new QuoteModel when the quoteId is null or not existed this.Response = quoteService.GetQuoteModel(user, _projectId, null); Assert.That(this.Response.HasError, Is.EqualTo(false)); QuoteModel model = this.Response.Model as QuoteModel; Assert.That(model.QuoteId, Is.EqualTo(null)); Assert.That(model.ProjectId, Is.EqualTo(_projectId)); Assert.That(model.Title, Is.EqualTo(null)); } }
public void TestOrderService_RulesOnStatusChange_SetQuoteToActiveWhenSubmitOrder() { this.response.Messages.Items.Clear(); this.response.Messages.HasErrors = false; var query = this.db.Context.Projects.Where(p => p.OwnerId == user.UserId).ToList(); Quote quote = null; foreach (Project project in query) { quote = this.db.Context.Quotes.Where(q => q.ProjectId == project.ProjectId && q.Active == false && q.Orders.Count() == 0).FirstOrDefault(); break; } orderVMLight.QuoteId = quote.QuoteId; orderVMLight.ProjectId = quote.ProjectId; orderService.PostModel(user, orderVMLight); QuoteModel quoteModel = quoteService.GetQuoteModel(user, orderVMLight.ProjectId, orderVMLight.QuoteId).Model as QuoteModel; Assert.That(quoteModel.Active, Is.EqualTo(true)); }
public TestOrderAPI() { orderService = new OrderServices(this.TContext); orderServiceLight = new OrderServiceLight(); searchOrders = new SearchOrders(); accountService = new AccountServices(); user = accountService.GetUserSessionModel("*****@*****.**").Model as UserSessionModel; quoteService = new QuoteServices(); orderVMLight = new OrderViewModelLight(); orderVMLight.BusinessId = 206680765352640513; orderVMLight.ShipToAddressId = 479102086194151432; orderVMLight.PricingTypeId = 1; orderVMLight.PONumber = "AAPO0613201601"; orderVMLight.TotalDiscountPercent = 0; orderVMLight.EstimatedReleaseDate = Convert.ToDateTime("2016-06-06 00:00:00.000"); orderVMLight.DeliveryAppointmentRequired = false; orderVMLight.DeliveryContactName = ""; orderVMLight.DeliveryContactPhone = ""; orderVMLight.OrderReleaseDate = DateTime.Now.AddDays(2); orderVMLight.SubmittedByUserId = 392643416367824896; orderVMLight.SubmitDate = DateTime.Now; orderVMLight.CreatedByUserId = 392643416367824896; orderVMLight.UpdatedByUserId = 392643416367824896; orderVMLight.DiscountRequestId = 0; orderVMLight.CommissionRequestId = 0; orderVMLight.ERPOrderNumber = ""; orderVMLight.ERPPOKey = 0; orderVMLight.ERPStatus = "Submitted"; orderVMLight.Comments = "PLEASE CALL BEFORE SHIPPING"; orderVMLight.ERPComments = ""; orderVMLight.ERPOrderDate = null; orderVMLight.ERPInvoiceDate = null; orderVMLight.ERPShipDate = null; orderVMLight.ERPInvoiceNumber = null; orderVMLight.QuoteId = 479102111284477952; orderVMLight.ProjectId = 479102086194151424; orderVMLight.CurrentUser = user; var fileUpload = new FileUploadTest(); orderVMLight.POAttachment = fileUpload; orderVMLight.POAttachmentFileName = fileUpload.FileUploadName; orderVMLight.ERPAccountId = "1234"; orderController = new OrderController(); projects = this.db.Projects.Where(p => p.OwnerId == user.UserId).ToList(); foreach (var project in projects) { var result = this.db.Context.Quotes.Where(q => q.AwaitingOrder == null && q.ProjectId == project.ProjectId).OrderByDescending(q => q.QuoteId).Select(q => new { q.QuoteId, q.ProjectId }).FirstOrDefault(); if (result != null) { quoteModel = quoteService.GetQuoteModel(user, result.ProjectId, result.QuoteId).Model as QuoteModel; if (quoteModel != null) { quotesModelWithoutOrder.Add(quoteModel); } } } foreach (var project in projects) { var result = this.db.Context.Quotes.Where(q => q.AwaitingOrder == true && q.ProjectId == project.ProjectId).OrderByDescending(q => q.QuoteId).Select(q => new { q.QuoteId, q.ProjectId }).FirstOrDefault(); if (result != null) { quoteModel = quoteService.GetQuoteModel(user, result.ProjectId, result.QuoteId).Model as QuoteModel; if (quoteModel != null) { quotesModelWithOrder.Add(quoteModel); } } } }
public void RulesOnStatusChange(UserSessionModel user, Order entity) { if (base.Entry.HasChanged("OrderStatusTypeId")) { entity.UpdatedByUserId = user.UserId; if (entity.Quote.Project == null) { // Needed for quote calculations Db.QueryProjectViewableByProjectId(user, entity.Quote.ProjectId).Include("Owner").Include("Owner.Business").Load(); } if (entity.OrderStatusTypeId == (byte)OrderStatusTypeEnum.Submitted) { entity.Quote.Active = true; QuoteServices quoteService = new QuoteServices(); QuoteModel quoteVM = new QuoteModel(); quoteVM = quoteService.GetQuoteModel(user, entity.Quote.ProjectId, entity.QuoteId).Model as QuoteModel; if (quoteVM != null) { this.Response = quoteService.SetActive(user, quoteVM); } if (this.Response.IsOK) { entity.Quote.Project.ProjectOpenStatusTypeId = (byte)ProjectOpenStatusTypeEnum.DaikinHasPO; entity.Quote.Project.ProjectStatusTypeId = ProjectStatusTypeEnum.ClosedWon; } else { this.Response.Messages.AddError("Set Quote to Active failed"); } } //if (entity.DiscountRequestStatusTypeId == (byte)DiscountRequestStatusTypeEnum.Rejected || // entity.DiscountRequestStatusTypeId == (byte)DiscountRequestStatusTypeEnum.Deleted) //{ // entity.Quote.DiscountRequestId = null; // entity.Quote.AwaitingDiscountRequest = false; // entity.ApprovedDiscount = 0; // entity.ApprovedDiscountSplit = 0; // entity.ApprovedDiscountVRV = 0; // RecalulateQuote(user, entity); // if (entity.DiscountRequestStatusTypeId == (byte)DiscountRequestStatusTypeEnum.Rejected) // { // if (this.Response.IsOK) this.Response.AddSuccess("Discount request rejected."); // } // else // { // if (this.Response.IsOK) this.Response.AddSuccess("Discount request deleted."); // } //} //if (entity.DiscountRequestStatusTypeId == (byte)DiscountRequestStatusTypeEnum.Approved) //{ // entity.Quote.DiscountRequestId = entity.DiscountRequestId; // entity.Quote.ApprovedCommissionPercentage = entity.RequestedCommission; // if (entity.ApprovedDiscount != null && entity.ApprovedDiscount > 0) // { // entity.Quote.ApprovedDiscountPercentage = entity.ApprovedDiscount.Value; // } // else // { // entity.Quote.ApprovedDiscountPercentage = entity.RequestedDiscount; // } // entity.Quote.AwaitingDiscountRequest = false; // RecalulateQuote(user, entity); // if (this.Response.IsOK) this.Response.AddSuccess("Discount request approved."); //} } }
public void TestProjectQuotesView_TestSetActiveButton_ShouldSetTheSelectedQuoteToActive() { NavigateToProjectQuotesView(user, projectId); IWebElement quoteTable = driver.FindElement(By.Id("ProjectQuotes_table")); IWebElement quoteSetActiveBtnDiv = quoteTable.FindElement(By.TagName("tbody")) .FindElements(By.TagName("td")).ToList() .Where(i => i.GetAttribute("data-col-id") == "9").First(); //get the row that contain the quoteId that we select. default will be first row IWebElement quoteSelectedId = quoteTable.FindElement(By.TagName("tbody")) .FindElements(By.TagName("tr")).ToList() .First(); //now we need to check if the quote we select is active or not bool isActive = false; long quoteId = (Convert.ToInt64(quoteSelectedId.GetAttribute("id"))); QuoteServices quoteService = new QuoteServices(); QuoteModel selectedQuote = quoteService.GetQuoteModel(user, projectId, quoteId).Model as QuoteModel; if (selectedQuote != null) { if (selectedQuote.Active == true) { isActive = true; } } IWebElement quoteSetActiveBtn = null; if (isActive == false) { quoteSetActiveBtn = quoteSetActiveBtnDiv.FindElement(By.TagName("a")); Assert.That(quoteSetActiveBtn.GetAttribute("href").ToLower(), Is.EqualTo("http://user15%40test.com:123456@tstsysdcity2/projectdashboard/projectquotes/" + projectId + "#")); Assert.That(quoteSetActiveBtn.GetAttribute("sc-ajaxpost").ToLower(), Is.EqualTo("/projectdashboard/quotesetactive")); Assert.That(quoteSetActiveBtn.GetAttribute("sc-quoteid"), Is.Not.EqualTo(string.Empty)); Assert.That(quoteSetActiveBtn.FindElement(By.TagName("img")).GetAttribute("src").ToLower(), Is.EqualTo("http://user15%40test.com:123456@tstsysdcity2/images/switch-off.png")); //only need to check for the click event when quote is not Active. //when quote is Active , the SetActive button is unclickable. IJavaScriptExecutor js = driver as IJavaScriptExecutor; js.ExecuteScript("arguments[0].click()", quoteSetActiveBtn); //set the thread sleep for 5 seconds to make sure the Return message availble Thread.Sleep(5000); IWebElement quoteSetActiveMessage = driver.FindElement(By.ClassName("pagemessage-success")); Assert.That(quoteSetActiveMessage.Text.ToLower().Contains("has been updated.")); } else { quoteSetActiveBtn = quoteSetActiveBtnDiv.FindElement(By.TagName("img")); Assert.That(quoteSetActiveBtn.GetAttribute("src").ToLower(), Is.EqualTo("http://user15%40test.com:123456@tstsysdcity2/images/switch-on.png")); } }
public ServiceResponse QuotePackageCreate(SubmittalRequestModel model) { //bool chkAllSubmittalSheets = (Request.Form["chkAllSubmittalSheets"] != null); //bool chkAllInstallationManuals = (Request.Form["chkAllInstallationManuals"] != null); //bool chkAllOperationalManuals = (Request.Form["chkAllOperationalManuals"] != null); //bool chkAllGuideSpecs = (Request.Form["chkAllGuideSpecs"] != null); //bool chkAllProductBrochures = (Request.Form["chkAllProductBrochures"] != null); //bool chkAllRevitDrawing = (Request.Form["chkAllRevitDrawing"] != null); //bool chkAllCADDrawing = (Request.Form["chkAllCADDrawing"] != null); //bool chkAllProductFlyer = (Request.Form["chkAllProductFlyer"] != null); var quotePackage = submittalService.GetQuoteQuotePackage(this.CurrentUser, model).Model as SubmittalRequestModel; var currentProject = projectService.GetProjectModel(this.CurrentUser, model.ProjectId).Model as ProjectModel; //ViewData["CurrentUser"] = this.CurrentUser; var currentProjectNameAsFileName = currentProject.Name; //create valid filename out of project name foreach (char c in System.IO.Path.GetInvalidFileNameChars()) { currentProjectNameAsFileName = currentProjectNameAsFileName.Replace(c, '_'); } var coverPageModel = new QuotePackageModel { Quote = quoteService.GetQuoteModel(this.CurrentUser, model.ProjectId, model.QuoteId).Model as QuoteModel }; coverPageModel.Quote.Project = currentProject; coverPageModel.AttachedFiles = quotePackage.QuotePackageAttachedFiles; coverPageModel.SelectedDocuments = new List <QuotePackageSelectedItemModel>(); var documents = new List <string>(); var existingDocs = new List <string>(); foreach (var item in quotePackage.Items) { var itemForCoverPage = new QuotePackageSelectedItemModel { ProductNumber = item.ProductNumber }; // var itemForCoverPage = new QuotePackageSelectedItemModel(); if (item.LineItemTypeId == (byte)LineItemTypeEnum.Configured) { itemForCoverPage.ProductNumber = item.CodeString; } else { itemForCoverPage.ProductNumber = item.ProductNumber; } foreach (var document in item.Documents) { // var isSelected = (Request.Form["doc" + document.FileName] + "" != ""); // // if (isSelected == false) isSelected = (chkAllSubmittalSheets && document.DocumentTypeId == (int)DocumentTypeEnum.SubmittalData); // if (isSelected == false) isSelected = (chkAllInstallationManuals && document.DocumentTypeId == (int)DocumentTypeEnum.InstallationManual); // if (isSelected == false) isSelected = (chkAllOperationalManuals && document.DocumentTypeId == (int)DocumentTypeEnum.OperationManual); // if (isSelected == false) isSelected = (chkAllProductBrochures && document.DocumentTypeId == (int)DocumentTypeEnum.ProductBrochure); // if (isSelected == false) isSelected = (chkAllGuideSpecs && document.DocumentTypeId == (int)DocumentTypeEnum.WrittenGuideSpec); // if (isSelected == false) isSelected = (chkAllRevitDrawing && document.DocumentTypeId == (int)DocumentTypeEnum.RevitDrawing); // if (isSelected == false) isSelected = (chkAllCADDrawing && document.DocumentTypeId == (int)DocumentTypeEnum.CADDrawing); // if (isSelected == false) isSelected = (chkAllProductFlyer && document.DocumentTypeId == (int)DocumentTypeEnum.ProductFlyer); var isSelected = false; //temporary fix if (isSelected && !existingDocs.Exists(n => n == document.FileName)) { if (item.LineItemTypeId == (byte)LineItemTypeEnum.Configured) { itemForCoverPage.Items.Add((int)document.DocumentTypeId); documents.Add(item.CodeString + "@" + "Configured Submittl Datasheet" + "@" + document.AbsoultePath); } else { itemForCoverPage.Items.Add((int)document.DocumentTypeId); documents.Add(item.ProductNumber + "@" + document.Type + "@" + document.AbsoultePath); } existingDocs.Add(document.FileName); } } if (itemForCoverPage.Items.Count > 0) { coverPageModel.SelectedDocuments.Add(itemForCoverPage); } } //bool chkAllAttachedFiles = (Request.Form["chkAllAttachedFiles"] != null); var quotePackageDirectory = Utilities.GetQuotePackageDirectory(model.QuoteId.Value); var quotePackageFilename = quotePackageDirectory + Utilities.QuotePackageFileName(model.QuoteId.Value); documents = documents.Distinct().ToList(); if (documents.Count > 0 || quotePackage.QuotePackageAttachedFiles.Count() > 0) { var locked = true; var lockFile = quotePackageFilename.Replace(".zip", ".lck"); try { lock (htmlService) { locked = (System.IO.File.Exists(lockFile)); if (!locked) { System.IO.File.Create(lockFile).Close(); } } if (!locked) { if (System.IO.File.Exists(quotePackageFilename)) { System.IO.File.Delete(quotePackageFilename); } using (var zip = ZipFile.Open(quotePackageFilename, ZipArchiveMode.Create)) { var productNumbers = ""; var builder = new System.Text.StringBuilder(); builder.Append(productNumbers); foreach (var doc in documents) { var split = doc.Split('@'); var productnumber = split[0]; var type = split[1]; var file = split[2]; if (type.ToLower().Contains("submittal")) { type = "Submittals Sheets"; builder.Append((productNumbers.Length == 0) ? productnumber : ("," + productnumber)); } else { var filename = System.IO.Path.GetFileName(file).Replace("GENERATED_", ""); var fileRef = (type + "\\" + filename); if (System.IO.File.Exists(file)) { zip.CreateEntryFromFile(file, fileRef, CompressionLevel.Optimal); } } } productNumbers = builder.ToString(); if (productNumbers.Length > 0) { var sdsfile = quotePackageDirectory + "DPO_QuotePackage_SubmittalDataSheets.pdf"; var pdf = new PdfConvertor(); var productService = new ProductServices(); foreach (var productNumber in productNumbers.Split(',')) { //add product tags, project info and user info to header of each submittal sheet //if no specific template type if given, add in the external submittal sheet(if it exists) var product = quotePackage.Items.Where(x => x.ProductNumber == productNumber).FirstOrDefault(); if (product.GetSubmittalSheetTemplateName != "SubmittalTemplate") { var file = productService.GenerateSubmittalDataFileForPackage(productNumber, product.QuoteItemId, currentProject.ProjectId); if (file != null) { pdf.AppendHtml(file); } } else { var submittalDocument = product.Documents.Where(d => d.DocumentTypeId == (int)DocumentTypeEnum.SubmittalData).FirstOrDefault(); var fullFile = Utilities.GetSubmittalDirectory() + submittalDocument.FileName + @".pdf"; if (System.IO.File.Exists(fullFile)) { pdf.AppendFile(fullFile); } } } pdf.WriteToFile(sdsfile); if (System.IO.File.Exists(sdsfile)) { zip.CreateEntryFromFile(sdsfile, "Submittals Sheets\\SDS_" + currentProjectNameAsFileName + ".pdf", CompressionLevel.Optimal); } } foreach (var doc in quotePackage.QuotePackageAttachedFiles.ToList()) { var fullFile = quotePackageDirectory + doc.FileName; if (System.IO.File.Exists(fullFile)) { var filename = System.IO.Path.GetFileName(fullFile); //bool isSelected = (Request.Form["doc" + doc.FileName] + "" != ""); //if (isSelected == false) isSelected = (chkAllAttachedFiles && doc.DocumentTypeId == (int)DocumentTypeEnum.QuotePackageAttachedFile); //f (isSelected) //{ zip.CreateEntryFromFile(fullFile, "AttachedFiles\\" + filename, CompressionLevel.Optimal); //} } } } //var coverPageFile = projectService.GenerateQuotePackageCoverPageFile((long)model.QuoteId, base.RenderView(this, "QuotePackageCoverPage", coverPageModel)); // if (coverPageFile != null) // { using (var zip = ZipFile.Open(quotePackageFilename, ZipArchiveMode.Update)) { //zip.CreateEntryFromFile(coverPageFile, "CoverSheet_" + currentProjectNameAsFileName + ".pdf", CompressionLevel.Optimal); } //} } // this.Response.ContentType = MimeMapping.GetMimeMapping(quotePackageFilename); //Response.AddHeader("Content-Disposition", String.Format("attachment;filename=\"{0}\"", "QuotePackage_" + currentProjectNameAsFileName + ".zip")); //Response.TransmitFile(quotePackageFilename); return(null); } finally { lock (htmlService) { if (!locked) { System.IO.File.Delete(lockFile); } } } } // return base.RedirectToAction("QuotePackage", new { ProjectId = model.ProjectId, QuoteId = model.QuoteId }); return(null); }