public RentalOrderDetails GetRentalOrderDetails(Customer customer, string invenTransId) { if (customer.DatabaseName == DataBases.NetsuiteInsphire) { return(Helpers.InspHire.DAL.GetRentalOrderDetails(customer, invenTransId)); } RentalOrderDetails returnData = new RentalOrderDetails(); SPLog splog = new SPLog("GetRentalOrderDetails", customer.DatabaseName, customer.CustomerId); try { returnData = _database.Query <RentalOrderDetails>( "web.GetRentalOrderDetails" + customer.DatabaseName, new { company = customer.CompanyId, customer = customer.CustomerId, inventtransid = invenTransId }, commandType: CommandType.StoredProcedure).FirstOrDefault(); if (returnData != null) { returnData.DatabaseName = customer.DatabaseName; } splog.Log(); return(returnData); } catch (Exception e) { splog.LogError(e.GetType().Name + " - " + e.Message); throw new Exception("See inner exception", e); } }
public async Task <ActionResult> CancelTransfer(string transferId) { try { //Find the Transfer in the database Transfer transfer = projectsDB.GetCustomerTransferById(ActiveCustomer, transferId); //Validate the transfer exists if (transfer == null) { return(Json(new { success = false, message = Resources.AnErrorOccured })); } //Update the transfer model with a status of canceled (4) transfer.Status = 4; //Call the AX business connector to update the transfer string apiUrlSuffix = ConfigurationManager.AppSettings["TransfersBaseURL"]; var completeUrl = baseApiUrl + apiUrlSuffix + "/ChangeTransferStatus"; string postData = JsonConvert.SerializeObject(transfer); WebClient client = new WebClient(); client.Headers.Add(HttpRequestHeader.ContentType, "application/json"); string response = client.UploadString(completeUrl, "POST", postData); //Validate the response from the AX business connector if (response != "true") { return(Json(new { success = false, message = Resources.AnErrorOccured })); } //Get the order to be transfer to build the success message and email Customer customer = new Customer() { CompanyId = transfer.DataAreaId, CustomerId = transfer.TransferFromCustAccount, DatabaseName = transfer.DatabaseName }; RentalOrderDetails machine = db.GetRentalOrderDetails(customer, transfer.TransferfromInventTransId); //Send the canceled transfer email await CancelTransferEmail(transfer, machine); return(Json(new { success = true, message = string.Format(Resources.OffRentTransfer, machine.ItemName, transfer.TransferFromFullName, transfer.TransferFromSalesName) })); } catch { return(Json(new { success = false, message = Resources.AnErrorOccured })); } }
//Region containing all functions related to trasfer workflow/data flow #region Transfer Operations public async Task <ActionResult> CreateTransfer(Transfer transfer) { //Validate the off hire date of the transfer if (transfer.DateOnHire.Date < DateTime.Now.Date.AddDays(await BusinessLogicHelper.DaysUntilDelivery(ActiveCustomer))) { return(Json(new { success = false, message = Resources.AnErrorOccured })); } //Validate that this is a new transfer the transfer already exists IEnumerable <Transfer> transfers = projectsDB.GetCustomerTransfers(ActiveCustomer); if (transfers.Where(i => i.TransferfromInventTransId == transfer.TransferfromInventTransId && i.Status != 4).Count() > 0) { return(Json(new { success = false, message = Resources.AnErrorOccured })); } //Get the order to be transfered and populate the transfer model RentalOrderDetails machine = db.GetRentalOrderDetails(ActiveCustomer, transfer.TransferfromInventTransId); IdentityUser transferFromUser = UserTable.GetUserById(User.Identity.GetUserId()); ContactPerson user = db.GetContactPersonById(transfer.ContactPersonId); transfer.TransferFromCustAccount = ActiveCustomer.CustomerId; transfer.TransferFromUserId = transferFromUser.Id; transfer.TransferFromSalesName = ActiveCustomer.Name; transfer.TransferFromContactPersonId = transferFromUser.ContactPersonId; transfer.DatabaseName = ActiveCustomer.DatabaseName; transfer.DataAreaId = ActiveCustomer.CompanyId; transfer.UserId = "N/A"; //Call AX Business connector string apiUrlSuffix = ConfigurationManager.AppSettings["TransfersBaseURL"]; var completeUrl = baseApiUrl + apiUrlSuffix + "/CreateTransfer"; string postData = JsonConvert.SerializeObject(transfer); WebClient client = new WebClient(); client.Headers.Add(HttpRequestHeader.ContentType, "application/json"); string response = client.UploadString(completeUrl, "POST", postData); //Check the response from the AX business connector if (response == "false") { return(Json(new { success = false, message = Resources.AnErrorOccured })); } await PushCreationEmail(transfer, machine); return(Json(new { success = true, message = string.Format(Resources.SenderS0, machine.ItemName, transfer.SalesName, user.ContactPersonName) })); }
public async Task <bool> CancelTransferEmail(Transfer transfer, RentalOrderDetails machine) { Customer senderCustomer = ActiveCustomer; //Build email template model TransferEmail emailModel = new TransferEmail(); IdentityUser Sender = UserTable.GetUserById(transfer.TransferFromUserId); ContactPerson Recipient = db.GetContactPersonById(transfer.ContactPersonId); emailModel.SenderFullName = Sender.FirstName + " " + Sender.LastName; emailModel.RecipientFullName = Recipient.ContactPersonName; emailModel.Machine = machine; emailModel.Transfer = transfer; emailModel.AcceptLink = ConfigurationManager.AppSettings["DomainURL"] + "/Rentals/OffHire/" + transfer.TransferfromInventTransId; //Generate HTML for the cancelation email ViewData.Model = emailModel; var pushRequestConfirmation = new StringWriter(); var viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, "~/Views/Emails/ProjectPushCanceled.cshtml"); var viewContext = new ViewContext(ControllerContext, viewResult.View, ViewData, TempData, pushRequestConfirmation); viewResult.View.Render(viewContext, pushRequestConfirmation); viewResult.ViewEngine.ReleaseView(ControllerContext, viewResult.View); string senderEmail = ((System.Security.Claims.ClaimsIdentity)User.Identity).FindFirst("Email").Value; string senderOnRentEmail = await db.GetOnRentEmailAddress(senderCustomer); string senderAmEmail = (await new OverviewDAL().GetAccountManagerDetails(senderCustomer)).Email; string[] senderNotificationEmails = null; if (!String.IsNullOrEmpty(this.ActiveCustomer.NotificationEmailAddress)) { senderNotificationEmails = this.ActiveCustomer.NotificationEmailAddress.Split(';'); } bool success = false; if (MailClient.SendEmail(senderCustomer, Resources.TransferCancelled, pushRequestConfirmation.GetStringBuilder().ToString(), senderAmEmail, senderEmail, senderOnRentEmail, senderNotificationEmails)) { success = true; } return(success); }
public async Task <bool> RentalDeskPushTransferEmail(string transferId, List <string> filePaths, string purchaseOrder) { try { Transfer transfer = projectsDB.GetCustomerTransferById(ActiveCustomer, transferId); IdentityUser Sender = UserTable.GetUserById(transfer.TransferFromUserId); ContactPerson Recipient = db.GetContactPersonById(transfer.ContactPersonId); Customer customer = new Customer() { CompanyId = transfer.DataAreaId, CustomerId = transfer.TransferFromCustAccount, DatabaseName = transfer.DatabaseName }; RentalOrderDetails orderDetails = db.GetRentalOrderDetails(customer, transfer.TransferfromInventTransId); customer = ActiveCustomer; List <Attachment> attachments = new List <Attachment>(); for (int i = 0; i < filePaths.Count; i++) { using (Stream stream = FileHelper.GetFileStream("Transfers\\" + transfer.RequestId + "\\" + filePaths[i])) { MemoryStream mem = new MemoryStream(); stream.CopyTo(mem); mem.Seek(0, 0); attachments.Add(new Attachment(mem, "RentalImage_" + i + Path.GetExtension(filePaths[i]))); } } StringBuilder sb = new StringBuilder(); sb.AppendFormat("<h2>MyRiwal {0}</h2>", Resources.TransferRequested); sb.AppendLine("<table>"); sb.AppendFormat("<tr><td>{0}:</td><td>{1:dd-MM-yyyy HH:mm}</td></tr>\n", Resources.DateTime, DateTime.Now); sb.AppendFormat("<tr><td>MyRiwal {0}:</td><td>{1}</td></tr>\n", Resources.UserName, ((System.Security.Claims.ClaimsIdentity)User.Identity).FindFirst("FullName").Value); sb.AppendFormat("<tr><td></td><td></td></tr>\n"); sb.AppendFormat("<tr><td>{0}:</td><td></td></tr>\n", Resources.FormDetails); sb.AppendLine("<tr><td> </td></tr>\n"); sb.AppendFormat("<tr><td>{0}:</td><td></td></tr>\n", Resources.From); sb.AppendLine("<tr><td> </td></tr>\n"); sb.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>\n", Resources.RentalOrderNumber, orderDetails.InventTransId); sb.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>\n", Resources.CompanyNumber, transfer.DataAreaId); sb.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>\n", Resources.CustomerNumber, transfer.TransferFromCustAccount); sb.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>\n", Resources.CustomerName, transfer.TransferFromSalesName); sb.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>\n", Resources.ContactName, Sender.FirstName + " " + Sender.LastName); sb.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>\n", Resources.ContactPhone, Sender.Telephone); sb.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>\n", Resources.ContactEmail, Sender.Email); sb.AppendLine("<tr><td> </td></tr>\n"); sb.AppendFormat("<tr><td>{0}:</td><td></td></tr>\n", Resources.To); sb.AppendLine("<tr><td> </td></tr>\n"); sb.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>\n", Resources.CompanyNumber, transfer.DataAreaId); sb.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>\n", Resources.CustomerNumber, transfer.CustAccount); sb.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>\n", Resources.CustomerName, transfer.SalesName); sb.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>\n", Resources.ContactName, Recipient.ContactPersonName); sb.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>\n", Resources.ContactEmail, Recipient.ContactPersonEmail); sb.AppendFormat("<tr><td>{0}:</td><td>{1}</td></tr>\n", Resources.YourPurchaseOrder, purchaseOrder); sb.AppendLine("</table>"); sb.AppendLine("<br /><br />"); sb.AppendFormat("<h3>{0}:</h3>", Resources.TransferMachine); sb.AppendLine("<table style='margin-top:20px' border='1'>"); sb.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td></tr>\n", Resources.MachineType, Resources.Brand, Resources.FleetNumber, Resources.SerialNumber, Resources.OnHireDate, Resources.OffHireDate); sb.AppendFormat("<tr><td>{0}</td><td>{1}</td><td>{2}</td><td>{3}</td><td>{4}</td><td>{5}</td>\n", orderDetails.ProductId, orderDetails.ItemName, orderDetails.AssetId, orderDetails.ObjectId, transfer.DateOnHire.ToShortDateString(), transfer.DateOffHire.ToShortDateString()); sb.AppendLine("</table>"); string userEmail = ((System.Security.Claims.ClaimsIdentity)User.Identity).FindFirst("Email").Value; string onRentEmail = await db.GetOnRentEmailAddress(customer); string amEmail = (await new OverviewDAL().GetAccountManagerDetails(customer)).Email; string subjectLine = Resources.TransferMachine; if (!string.IsNullOrWhiteSpace(orderDetails.DeliveryName)) { subjectLine += " " + orderDetails.DeliveryName; } if (!string.IsNullOrWhiteSpace(orderDetails.DeliveryCity)) { subjectLine += " (" + orderDetails.DeliveryCity + ")"; } string[] notificationEmails = null; if (!String.IsNullOrEmpty(this.ActiveCustomer.NotificationEmailAddress)) { notificationEmails = this.ActiveCustomer.NotificationEmailAddress.Split(';'); } if (MailClient.SendEmail(customer, subjectLine, sb.ToString(), amEmail, userEmail, onRentEmail, notificationEmails, attachments)) { return(true); } return(false); } catch (Exception e) { return(false); } }
//Region containing all functions related to sending notifications out for the transfer process #region Transfer Notifications public ActionResult GetNotifications() { IEnumerable <Transfer> transfers = projectsDB.GetCustomerTransfers(ActiveCustomer); List <object> notifications = new List <object>(); foreach (var transfer in transfers) { Customer customer = new Customer() { CompanyId = transfer.DataAreaId, CustomerId = transfer.TransferFromCustAccount, DatabaseName = transfer.DatabaseName }; RentalOrderDetails machine = db.GetRentalOrderDetails(customer, transfer.TransferfromInventTransId); IdentityUser transferFromUser = UserTable.GetUserById(User.Identity.GetUserId()); ContactPerson user = db.GetContactPersonById(transfer.ContactPersonId); transfer.TransferFromFullName = transferFromUser.FirstName + " " + transferFromUser.LastName; if (user == null) { transfer.TransferFromFullName = "DELETE TRANSFER"; } else { transfer.FullName = user.ContactPersonName; } if (transfer.Status == 0) { if (transfer.TransferFromCustAccount == ActiveCustomer.CustomerId) { var newNotification = new { Message = string.Format(Resources.SenderS0, machine.ItemName, transfer.SalesName, transfer.FullName), SenderS1 = true, TransferId = transfer.RequestId }; notifications.Add(newNotification); } else if (transfer.CustAccount == ActiveCustomer.CustomerId) { var newNotification = new { Message = string.Format(Resources.RecipientS0, transfer.TransferFromFullName, transfer.TransferFromSalesName, machine.ItemName, transfer.FullName), RecipientS1 = true, TransferId = transfer.RequestId, CompanyId = transfer.DataAreaId, ItemName = machine.ItemName, DaysUntilTransfer = Math.Floor((transfer.DateOnHire - DateTime.Now).TotalDays + 2).ToString() }; notifications.Add(newNotification); } } if (transfer.Status == 1) { if (transfer.TransferFromCustAccount == ActiveCustomer.CustomerId) { var newNotification = new { Message = string.Format(Resources.SenderS1, machine.ItemName, transfer.FullName, transfer.SalesName), SenderS2 = true, TransferId = transfer.RequestId }; notifications.Add(newNotification); } else if (transfer.CustAccount == ActiveCustomer.CustomerId) { var newNotification = new { Message = string.Format(Resources.RecipientS1, machine.ItemName, transferFromUser.FirstName + " " + transferFromUser.LastName, transfer.TransferFromSalesName), RecipientS2 = true, TransferId = transfer.RequestId }; notifications.Add(newNotification); } } if (transfer.Status == 2) { if (transfer.TransferFromCustAccount == ActiveCustomer.CustomerId) { var newNotification = new { Message = string.Format(Resources.SenderS2, machine.ItemName, transfer.SalesName, transfer.DateOnHire.ToShortDateString(), transfer.InspectionDate.ToShortDateString()), SenderS3 = true, TransferId = transfer.RequestId }; notifications.Add(newNotification); } else if (transfer.CustAccount == ActiveCustomer.CustomerId) { var newNotification = new { Message = string.Format(Resources.RecipientS2, transfer.FullName, machine.ItemName, transfer.TransferFromSalesName, transfer.DateOnHire.ToShortDateString(), transfer.InspectionDate.ToShortDateString()), RecipientS3 = true, TransferId = transfer.RequestId }; notifications.Add(newNotification); } } } return(Json(new { notifications = notifications })); }
public async Task <ActionResult> SubmitPhotos(Transfer tempTransfer, string purchaseOrder) { try { //Find the transfer in the database Transfer transfer = projectsDB.GetCustomerTransferById(ActiveCustomer, tempTransfer.RequestId); //Validate the transfer exists if (transfer == null) { return(Json(new { success = false, message = Resources.AnErrorOccured })); } //Populate the missing values from the model transfer.ExactDateInput = tempTransfer.ExactDateInput; transfer.DateOffHire = tempTransfer.DateOffHire; //Validate the on and off hire dates if (transfer.DateOffHire <= transfer.DateOnHire) { return(Json(new { success = false, message = Resources.AnErrorOccured })); } //Check the transfer has images List <string> filePaths = FileHelper.GetFileNames("Transfers\\" + transfer.RequestId); if (filePaths != null && filePaths.Count > 0) { //Validate that there are 4 photos if (filePaths.Count < 4) { return(Json(new { success = false, message = Resources.AnErrorOccured })); } //Call the AX business connector to update the transfer transfer.Status = 1; string apiUrlSuffix = ConfigurationManager.AppSettings["TransfersBaseURL"]; var completeUrl = baseApiUrl + apiUrlSuffix + "/UpdateTransfer"; string postData = JsonConvert.SerializeObject(transfer); WebClient client = new WebClient(); client.Headers.Add(HttpRequestHeader.ContentType, "application/json"); string response = client.UploadString(completeUrl, "POST", postData); //Check the response from the AX business connector if (response != "true") { return(Json(new { success = false, message = Resources.AnErrorOccured })); } //Send the rental desk email await RentalDeskPushTransferEmail(transfer.RequestId, filePaths, purchaseOrder); } Customer customer = new Customer() { CompanyId = transfer.DataAreaId, CustomerId = transfer.TransferFromCustAccount, DatabaseName = transfer.DatabaseName }; //Get user and order details to build the success message IdentityUser transferFromUser = UserTable.GetUserById(transfer.TransferFromUserId); RentalOrderDetails machine = db.GetRentalOrderDetails(customer, transfer.TransferfromInventTransId); return(Json(new { success = true, message = string.Format(Resources.RecipientS1, machine.ItemName, transferFromUser.FirstName + " " + transferFromUser.LastName, transfer.TransferFromSalesName) })); } catch { return(Json(new { success = false, message = Resources.AnErrorOccured })); } }
public IEnumerable <MaintenanceTask> GetMachineMaintenance(Customer customer, DateTime StartDate, DateTime EndDate, RentalOrderDetails orderDetails) { if (customer.DatabaseName == DataBases.NetsuiteInsphire) { return(Helpers.InspHire.DAL.GetMachineMaintenance(customer, StartDate, EndDate, orderDetails)); } IEnumerable <MaintenanceTask> returnData; SPLog splog = new SPLog("GetMachineMaintenance", customer.DatabaseName, customer.CustomerId); try { returnData = _database.QueryAsync <MaintenanceTask>( "web.GetMachineMaintenance", new { customer = customer.CustomerId, startdate = StartDate, enddate = EndDate, objectid = orderDetails.ObjectId }, commandType: CommandType.StoredProcedure).Result; splog.Log(); return(returnData); } catch (Exception e) { splog.LogError(e.GetType().Name + " - " + e.Message); throw new Exception("See inner exception", e); } }
internal static RentalOrderDetails GetRentalOrderDetails(Customer customer, string recordID) { // If customer has no InspHireAcct then can view all records, so exit //if (string.IsNullOrEmpty(customer.InspHireAcct)) // return new RentalOrderDetails(); // Create the OData to get the specified rental string oData = "$filter="; // Check if the customer has business relationships enabled, and if so, get all the customers they're related to if (customer.showChildBROrders) { oData += "(" + CreateCustomerListODataCondition(GetRelationshipsCustomerList(customer)) + ")"; } else { oData += "ACCT eq '" + customer.InspHireAcct + "'"; } // Finish the OData oData += " and PARITEM eq '' and (TYPE eq 0 or TYPE eq 1) and RECID eq '" + recordID + "'"; // Get the rental from InspHire var contractItems_Raw = Helpers.InspHire.API.Get("contractitems", oData); if (contractItems_Raw.Count() < 1) { return(null); } var contractItem = new RentalOrderDetails(); contractItem.Populate_InspHireSalesItem(contractItems_Raw.First()); // Add data from Stock on ContractItems.ITEMNO oData = "$filter=ITEMNO eq '" + contractItem.ITEMNO + "'"; var stock = Helpers.InspHire.API.Get("stock", oData).First(); contractItem.Populate_INSPHIREStock(stock); // Add data from SubGroup on Stock.GRPCODE oData = "$filter=CODE eq '" + contractItem.PGROUP + "'"; var productGroup = Helpers.InspHire.API.Get("productgroups", oData).First(); contractItem.Populate_INSPHIREProductGroup(productGroup); // Add data from Depot on rentalOrder.HIREDEPOT oData = "$filter=CODE eq '" + contractItem.DEPOT + "'"; var depot = Helpers.InspHire.API.Get("depots", oData).First(); contractItem.Populate_INSPHIREDepot(depot); // Add data from Contract on Contract.contno = ContractItem.contno oData = "$filter=CONTNO eq '" + contractItem.CONTNO + "'"; var contract = Helpers.InspHire.API.Get("contracts", oData).FirstOrDefault(); contractItem.Populate_INSPHIREContract(contract); // Link SalesIDs on Contract.SPCODE oData = "$filter=CODE eq '" + contractItem.SPCODE + "'"; var salesID = Helpers.InspHire.API.Get("SalesIDs", oData).FirstOrDefault(); contractItem.Populate_InspHireSalesID(salesID); return(contractItem); }
internal static IEnumerable <MaintenanceTask> GetMachineMaintenance(Customer customer, DateTime startDate, DateTime endDate, RentalOrderDetails orderDetails) { // ToDo - this isn't tested as no appropriate test data. List <MaintenanceTask> maintenanceTasks = new List <MaintenanceTask>() { new MaintenanceTask(), new MaintenanceTask(), new MaintenanceTask(), new MaintenanceTask() }; string oData = ""; var maintenanceTasks_Raw = Helpers.InspHire.API.Get <Dictionary <string, string> >("stock/" + orderDetails.AssetId + "/contractservicedetail", oData); maintenanceTasks[0].Populate_InspHireContractServiceDetail(maintenanceTasks_Raw, MaintenanceTask.SERVICETYPE.LastInspection); maintenanceTasks[1].Populate_InspHireContractServiceDetail(maintenanceTasks_Raw, MaintenanceTask.SERVICETYPE.LastService); maintenanceTasks[2].Populate_InspHireContractServiceDetail(maintenanceTasks_Raw, MaintenanceTask.SERVICETYPE.NextInspection); maintenanceTasks[3].Populate_InspHireContractServiceDetail(maintenanceTasks_Raw, MaintenanceTask.SERVICETYPE.NextService); return(maintenanceTasks.Where(i => i.PlannedFromDate != DateTime.MinValue)); }