public ActionResult UpdateOrdersBulkSingle(Order Order, OrderRecipientInfo shipmentAndRecipientInfo) { // get properties of tenant try { if (ModelState.IsValid) { var orderDetailsList = GaneOrderDetailsSessionHelper.GetOrderDetailSession(shipmentAndRecipientInfo.PageSessionToken); var orderNotesList = GaneOrderNotesSessionHelper.GetOrderNotesSession(shipmentAndRecipientInfo.PageSessionToken); OrderService.UpdateWorksOrderBulkSingle(Order, shipmentAndRecipientInfo, CurrentTenantId, CurrentWarehouseId, CurrentUserId, Mapper.Map(orderDetailsList, new List <OrderDetail>()), orderNotesList); GaneOrderDetailsSessionHelper.ClearSessionTokenData(shipmentAndRecipientInfo.PageSessionToken); GaneOrderNotesSessionHelper.ClearSessionTokenData(shipmentAndRecipientInfo.PageSessionToken); return(Json(new { success = true, message = "Saved" }, JsonRequestBehavior.AllowGet)); } SetViewBagItems(); ViewBag.OrderDetails = Order.OrderDetails; ViewBag.OrderProcesses = Order.OrderProcess; ViewBag.SupplierID = new SelectList(AccountServices.GetAllValidAccounts(CurrentTenantId, EnumAccountType.Supplier), "AccountID", "CompanyName", Order.AccountID); return(Json(new { success = false, message = "Model state not valid, failed to save!" }, JsonRequestBehavior.AllowGet)); } catch (Exception Exp) { SetViewBagItems(); ViewBag.OrderDetails = Order.OrderDetails; ViewBag.OrderProcesses = Order.OrderProcess; ViewBag.SupplierID = new SelectList(AccountServices.GetAllValidAccounts(CurrentTenantId, EnumAccountType.Supplier), "AccountID", "CompanyName", Order.AccountID); ModelState.AddModelError("", Exp.Message); return(Json(new { success = false, message = Exp.Message }, JsonRequestBehavior.AllowGet)); } }
public async Task <ActionResult> Create(Order Order, OrderRecipientInfo shipmentAndRecipientInfo) { // get properties of tenant try { if (ModelState.IsValid) { var tempList = GaneOrderDetailsSessionHelper.GetOrderDetailSession(shipmentAndRecipientInfo.PageSessionToken); var orderNotesList = GaneOrderNotesSessionHelper.GetOrderNotesSession(shipmentAndRecipientInfo.PageSessionToken); OrderService.CreateWorksOrder(Order, shipmentAndRecipientInfo, CurrentTenantId, CurrentWarehouseId, CurrentUserId, Mapper.Map(tempList, new List <OrderDetail>()), orderNotesList); var result = await _ganeConfigurationsHelper.CreateTenantEmailNotificationQueue($"#{Order.OrderNumber} - Works order logged", Mapper.Map(Order, new OrderViewModel()), sendImmediately : true, shipmentAndRecipientInfo : shipmentAndRecipientInfo, worksOrderNotificationType : WorksOrderNotificationTypeEnum.WorksOrderLogTemplate); if (result != "Success") { TempData["Error"] = result; } return(AnchoredOrderIndex("WorksOrders", "Index", ViewBag.Fragment as string)); } SetViewBagItems(); ViewBag.OrderDetails = Order.OrderDetails; ViewBag.OrderProcesses = Order.OrderProcess; ViewBag.ForceRegeneratePageToken = "True"; ViewBag.ForceRegeneratedPageToken = shipmentAndRecipientInfo.PageSessionToken ?? Guid.NewGuid().ToString(); ViewBag.SupplierID = new SelectList(AccountServices.GetAllValidAccounts(CurrentTenantId, EnumAccountType.Supplier), "AccountID", "CompanyName", Order.AccountID); return(View(Order)); } catch (Exception Exp) { if (Exp.InnerException != null && Exp.InnerException.Message == "Duplicate Order Number") { ModelState.AddModelError("OrderNumber", Exp.Message); } else if (Exp.InnerException != null && Exp.InnerException.Message.Contains("Template")) { ModelState.AddModelError("PropertyTenantIds", Exp.Message); } else { ModelState.AddModelError(string.Empty, Exp.Message); } SetViewBagItems(); ViewBag.ForceRegeneratePageToken = "True"; ViewBag.ForceRegeneratedPageToken = shipmentAndRecipientInfo.PageSessionToken ?? Guid.NewGuid().ToString(); ViewBag.OrderDetails = Order.OrderDetails; ViewBag.OrderProcesses = Order.OrderProcess; ViewBag.SupplierID = new SelectList(AccountServices.GetAllValidAccounts(CurrentTenantId, EnumAccountType.Supplier), "AccountID", "CompanyName", Order.AccountID); return(View(Order)); } }
public async Task <ActionResult> Edit(Order Order, OrderRecipientInfo shipmentAndRecipientInfo, string orderSaveAndComplete, string orderSaveAndProcess) { var orderCompleted = false; if (orderSaveAndComplete == "1") { Order.OrderStatusID = (int)OrderStatusEnum.Complete; orderCompleted = true; } if (ModelState.IsValid) { var tempList = GaneOrderDetailsSessionHelper.GetOrderDetailSession(shipmentAndRecipientInfo.PageSessionToken); var orderNotesList = GaneOrderNotesSessionHelper.GetOrderNotesSession(shipmentAndRecipientInfo.PageSessionToken); OrderService.SaveWorksOrder(Order, shipmentAndRecipientInfo, CurrentTenantId, CurrentWarehouseId, CurrentUserId, orderCompleted, Mapper.Map(tempList, new List <OrderDetail>()), orderNotesList); if (orderCompleted) { try { if (shipmentAndRecipientInfo.SendEmailWithAttachment) { var result = await _ganeConfigurationsHelper.CreateTenantEmailNotificationQueue($"#{Order.OrderNumber} - Works order completed", Mapper.Map(Order, new OrderViewModel()), sendImmediately : true, shipmentAndRecipientInfo : shipmentAndRecipientInfo, worksOrderNotificationType : WorksOrderNotificationTypeEnum.WorksOrderCompletedTemplate); if (result != "Success") { TempData["Error"] = result; } } } catch (Exception ex) { throw new Exception("Exception while creating tenant email notification queue - " + ex.Message.ToString(), ex.InnerException); } } ViewBag.Fragment = Request.Form["fragment"]; if (orderSaveAndProcess == "1") { return(Redirect(Url.RouteUrl(new { controller = "WorksOrders", action = "ProcessOrder", id = Order.OrderID }) + "?fragment=" + ViewBag.Fragment as string)); } return(AnchoredOrderIndex("WorksOrders", "Index", ViewBag.Fragment as string)); } ViewBag.ForceRegeneratePageToken = "True"; ViewBag.ForceRegeneratedPageToken = shipmentAndRecipientInfo.PageSessionToken ?? Guid.NewGuid().ToString(); SetViewBagItems(Order); ViewBag.POStatusID = new SelectList(LookupServices.GetAllOrderStatuses(), "OrderStatusID", "Status", Order.OrderStatusID); ViewBag.SupplierID = new SelectList(AccountServices.GetAllValidAccounts(CurrentTenantId, EnumAccountType.Supplier), "SupplierID", "CompanyName", Order.AccountID); return(View(Order)); }
public async Task <ActionResult> Edit([Bind(Include = "OrderID,OrderNumber,DirectShip,ExpectedDate,Note,AccountID,OrderTypeID,LoanID,OrderStatusID,AccountContactId,Posted,PPropertyId,DepartmentId,InvoiceNo,InvoiceDetails,OrderCost,IsCollectionFromCustomerSide")] Order Order, OrderRecipientInfo shipmentAndRecipientInfo, string orderSaveAndProcess, int EmailTemplate) { if (ModelState.IsValid) { var items = GaneOrderDetailsSessionHelper.GetOrderDetailSession(shipmentAndRecipientInfo.PageSessionToken); var orderNotes = GaneOrderNotesSessionHelper.GetOrderNotesSession(shipmentAndRecipientInfo.PageSessionToken); OrderService.SavePurchaseOrder(Order, shipmentAndRecipientInfo, CurrentTenantId, CurrentWarehouseId, CurrentUserId, Mapper.Map(items, new List <OrderDetail>()), orderNotes); if (shipmentAndRecipientInfo.SendEmailWithAttachment) { var report = CreatePurchaseOrderPrint(Order.OrderID); PrepareDirectory("~/UploadedFiles/reports/po/"); var reportPath = "~/UploadedFiles/reports/po/" + Order.OrderNumber + ".pdf"; report.ExportToPdf(Server.MapPath(reportPath)); var result = await GaneConfigurationsHelper.CreateTenantEmailNotificationQueue($"#{Order.OrderNumber} - Purchase order has been updated", Mapper.Map(Order, new OrderViewModel()), reportPath, shipmentAndRecipientInfo : shipmentAndRecipientInfo, worksOrderNotificationType : (WorksOrderNotificationTypeEnum)EmailTemplate); if (result != "Success") { TempData["Error"] = result; } } GaneOrderDetailsSessionHelper.ClearSessionTokenData(shipmentAndRecipientInfo.PageSessionToken); GaneOrderNotesSessionHelper.ClearSessionTokenData(shipmentAndRecipientInfo.PageSessionToken); ViewBag.Fragment = Request.Form["fragment"]; if (orderSaveAndProcess == "1") { return(Redirect(Url.RouteUrl(new { controller = "PurchaseOrders", action = "ReceivePO", id = Order.OrderID }) + "?fragment=" + ViewBag.Fragment as string)); } return(AnchoredOrderIndex("PurchaseOrders", "Index", ViewBag.Fragment as string)); } ViewBag.AllowAccountAddress = caCurrent.CurrentWarehouse()?.AllowShipToAccountAddress; ViewBag.ForceRegeneratePageToken = "True"; ViewBag.ForceRegeneratedPageToken = shipmentAndRecipientInfo.PageSessionToken ?? Guid.NewGuid().ToString(); SetViewBagItems(null, EnumAccountType.Supplier); ViewBag.SupplierID = new SelectList(AccountServices.GetAllValidAccounts(CurrentTenantId, EnumAccountType.Supplier), "SupplierID", "CompanyName", Order.AccountID); return(View(Order)); }
public async Task <ActionResult> Edit(Order Order, FormCollection formCollection, OrderRecipientInfo shipmentAndRecipientInfo, string orderSaveAndProcess, int EmailTemplate) { if (ModelState.IsValid) { Order.OrderNumber = Order.OrderNumber.Trim(); // get properties of user caUser user = caCurrent.CurrentUser(); Order.DateUpdated = DateTime.UtcNow; Order.UpdatedBy = user.UserId; Order.WarehouseId = CurrentWarehouseId; var items = GaneOrderDetailsSessionHelper.GetOrderDetailSession(shipmentAndRecipientInfo.PageSessionToken); var nItems = GaneOrderNotesSessionHelper.GetOrderNotesSession(shipmentAndRecipientInfo.PageSessionToken); Order = OrderService.SaveSalesOrder(Order, shipmentAndRecipientInfo, CurrentTenantId, CurrentWarehouseId, CurrentUserId, Mapper.Map(items, new List <OrderDetail>()), nItems); if (shipmentAndRecipientInfo.SendEmailWithAttachment) { var report = CreateSalesOrderPrint(Order.OrderID); PrepareDirectory("~/UploadedFiles/reports/so/"); var reportPath = "~/UploadedFiles/reports/so/" + Order.OrderNumber + ".pdf"; report.ExportToPdf(Server.MapPath(reportPath)); var result = await GaneConfigurationsHelper.CreateTenantEmailNotificationQueue($"#{Order.OrderNumber} - Sales order has been updated", Mapper.Map(Order, new OrderViewModel()), reportPath, shipmentAndRecipientInfo : shipmentAndRecipientInfo, worksOrderNotificationType : (WorksOrderNotificationTypeEnum)EmailTemplate); if (result != "Success") { TempData["Error"] = result; } } if (Order.OrderStatusID == (int)OrderStatusEnum.AwaitingAuthorisation) { var result = await GaneConfigurationsHelper.CreateTenantEmailNotificationQueue($"#{Order.OrderNumber} - Order Requires Authorisation", Mapper.Map(Order, new OrderViewModel()), null, shipmentAndRecipientInfo : shipmentAndRecipientInfo, worksOrderNotificationType : WorksOrderNotificationTypeEnum.AwaitingOrderTemplate); if (result != "Success") { TempData["Error"] = result; } } GaneOrderDetailsSessionHelper.ClearSessionTokenData(shipmentAndRecipientInfo.PageSessionToken); GaneOrderNotesSessionHelper.ClearSessionTokenData(shipmentAndRecipientInfo.PageSessionToken); ViewBag.Fragment = Request.Form["fragment"]; if (orderSaveAndProcess == "1") { return(Redirect(Url.RouteUrl(new { controller = "SalesOrders", action = "ProcessOrder", id = Order.OrderID }) + "?fragment=" + ViewBag.Fragment as string)); } return(AnchoredOrderIndex("SalesOrders", "Index", ViewBag.Fragment as string)); } ViewBag.ForceRegeneratePageToken = "True"; ViewBag.ForceRegeneratedPageToken = shipmentAndRecipientInfo.PageSessionToken ?? Guid.NewGuid().ToString(); SetViewBagItems(CurrentTenant, EnumAccountType.Customer); ViewBag.SupplierID = new SelectList(AccountServices.GetAllValidAccounts(CurrentTenantId, EnumAccountType.Supplier), "SupplierID", "CompanyName", Order.AccountID); ViewBag.AccountAddresses = new List <SelectListItem>(); if (Order.AccountID > 0) { var account = AccountServices.GetAccountsById(Order.AccountID.Value); ViewBag.AccountAddresses = new SelectList(account.AccountAddresses, "AddressID", "FullAddressValue", Order.ShipmentAccountAddressId); if (Order.ConsignmentTypeId.HasValue && Order.ConsignmentTypeId.Value != (int)ConsignmentTypeEnum.Collection && Order.ShipmentAccountAddressId > 0) { ViewBag.ShipmentAccountAddressId = Order.ShipmentAccountAddressId; ViewBag.IsShipmentToAccountAddress = true; ViewBag.IsShipmentToCustomAddress = false; } else { ViewBag.ShipmentAccountAddressId = 0; ViewBag.IsShipmentToAccountAddress = false; ViewBag.IsShipmentToCustomAddress = true; } } ViewBag.ConsignmentTypes = new SelectList(OrderService.GetAllValidConsignmentTypes(CurrentTenantId), "ConsignmentTypeId", "ConsignmentType", Order.ConsignmentTypeId); return(View(Order)); }
public async Task <ActionResult> Create(Order Order, OrderRecipientInfo shipmentAndRecipientInfo, int EmailTemplate) { try { if (ModelState.IsValid) { var tempNotesList = GaneOrderNotesSessionHelper.GetOrderNotesSession(shipmentAndRecipientInfo.PageSessionToken); var tempList = GaneOrderDetailsSessionHelper.GetOrderDetailSession(shipmentAndRecipientInfo.PageSessionToken); Order = OrderService.CreateSalesOrder(Order, shipmentAndRecipientInfo, CurrentTenantId, CurrentWarehouseId, CurrentUserId, Mapper.Map(tempList, new List <OrderDetail>()), tempNotesList); if (shipmentAndRecipientInfo.SendEmailWithAttachment) { var report = CreateSalesOrderPrint(Order.OrderID); PrepareDirectory("~/UploadedFiles/reports/so/"); var reportPath = "~/UploadedFiles/reports/so/" + Order.OrderNumber + ".pdf"; report.ExportToPdf(Server.MapPath(reportPath)); var result = await GaneConfigurationsHelper.CreateTenantEmailNotificationQueue($"#{Order.OrderNumber} - Sales order", Mapper.Map(Order, new OrderViewModel()), reportPath, shipmentAndRecipientInfo : shipmentAndRecipientInfo, worksOrderNotificationType : (WorksOrderNotificationTypeEnum)EmailTemplate); if (result != "Success") { TempData["Error"] = result; } } if (Order.OrderStatusID == (int)OrderStatusEnum.AwaitingAuthorisation) { var result = await GaneConfigurationsHelper.CreateTenantEmailNotificationQueue($"#{Order.OrderNumber} - Order Requires Authorisation", Mapper.Map(Order, new OrderViewModel()), null, shipmentAndRecipientInfo : shipmentAndRecipientInfo, worksOrderNotificationType : WorksOrderNotificationTypeEnum.AwaitingOrderTemplate); if (result != "Success") { TempData["Error"] = result; } } //send ingredients email for certain categories var productCategoryTc = _tenantServices.GetTenantConfigById(Order.TenentId)?.ProductCatagories; if (Order.InventoryTransactionTypeId == (int)InventoryTransactionTypeEnum.SalesOrder && !string.IsNullOrEmpty(productCategoryTc)) { var productcategoryList = productCategoryTc.Split(',').Select(int.Parse).ToList(); if (Order.OrderDetails.Any(x => productcategoryList.Contains((int?)x.ProductMaster?.ProductGroupId ?? 0))) { var result = await GaneConfigurationsHelper.SendStandardMailProductGroup(Order.TenentId, Order.OrderNumber, Order.AccountID ?? 0); if (result != "Success") { TempData["Error"] = result; } } } GaneOrderDetailsSessionHelper.ClearSessionTokenData(shipmentAndRecipientInfo.PageSessionToken); GaneOrderNotesSessionHelper.ClearSessionTokenData(shipmentAndRecipientInfo.PageSessionToken); return(AnchoredOrderIndex("SalesOrders", "Index", "SOA")); } int id = 0; var accountaddress = _accountServices.GetAllValidAccountContactsByAccountId(id, CurrentTenantId); ViewBag.AccountContactes = new SelectList(accountaddress, "AccountContactId", "ContactEmail", accountaddress.Select(x => x.AccountID).FirstOrDefault()); ViewBag.ForceRegeneratePageToken = "True"; ViewBag.ForceRegeneratedPageToken = shipmentAndRecipientInfo.PageSessionToken ?? Guid.NewGuid().ToString(); SetViewBagItems(CurrentTenant, EnumAccountType.Customer); ViewBag.OrderDetails = Order.OrderDetails; ViewBag.OrderProcesses = Order.OrderProcess; ViewBag.IsShipmentToAccountAddress = true; ViewBag.AccountAddresses = new List <SelectListItem>() { new SelectListItem() { Text = "Select", Value = "0" } }; ViewBag.ShipmentAccountAddressId = 0; ViewBag.IsShipmentToCustomAddress = false; ViewBag.ConsignmentTypes = new SelectList(OrderService.GetAllValidConsignmentTypes(CurrentTenantId), "ConsignmentTypeId", "ConsignmentType"); ViewBag.SupplierID = new SelectList(AccountServices.GetAllValidAccounts(CurrentTenantId, EnumAccountType.Supplier), "AccountID", "CompanyName", Order.AccountID); return(View(Order)); } catch (Exception Exp) { int ids = 0; var accountaddress = _accountServices.GetAllValidAccountContactsByAccountId(ids, CurrentTenantId); ViewBag.AccountContactes = new SelectList(accountaddress, "AccountContactId", "ContactEmail", accountaddress.Select(x => x.AccountID).FirstOrDefault()); ViewBag.IsShipmentToAccountAddress = true; ViewBag.AccountAddresses = new List <SelectListItem>() { new SelectListItem() { Text = "Select", Value = "0" } }; ViewBag.ShipmentAccountAddressId = 0; ViewBag.IsShipmentToCustomAddress = false; if (Exp.InnerException != null && Exp.InnerException.Message == "Duplicate Order Number") { ModelState.AddModelError("OrderNumber", Exp.Message); } else { ModelState.AddModelError("", Exp.Message); } var tenent = caCurrent.CurrentTenant(); SetViewBagItems(tenent, EnumAccountType.Customer); ViewBag.OrderDetails = Order.OrderDetails; ViewBag.OrderProcesses = Order.OrderProcess; ViewBag.ForceRegeneratePageToken = "True"; ViewBag.ForceRegeneratedPageToken = shipmentAndRecipientInfo.PageSessionToken ?? Guid.NewGuid().ToString(); ViewBag.ConsignmentTypes = new SelectList(OrderService.GetAllValidConsignmentTypes(CurrentTenantId), "ConsignmentTypeId", "ConsignmentType"); ViewBag.SupplierID = new SelectList(AccountServices.GetAllValidAccounts(CurrentTenantId, EnumAccountType.Supplier), "AccountID", "CompanyName", Order.AccountID); return(View(Order)); } }
public async Task <ActionResult> Create(Order Order, OrderRecipientInfo shipmentAndRecipientInfo, int EmailTemplate) { try { if (ModelState.IsValid) { if (shipmentAndRecipientInfo.ShipmentDestination == null || shipmentAndRecipientInfo.TenantAddressID == null) { ViewBag.Error = "Please choose a delivery address"; } else { var orderDetails = GaneOrderDetailsSessionHelper.GetOrderDetailSession(shipmentAndRecipientInfo.PageSessionToken); var orderNotes = GaneOrderNotesSessionHelper.GetOrderNotesSession(shipmentAndRecipientInfo.PageSessionToken); OrderService.CreatePurchaseOrder(Order, shipmentAndRecipientInfo, CurrentTenantId, CurrentWarehouseId, CurrentUserId, Mapper.Map(orderDetails, new List <OrderDetail>()), orderNotes); if (shipmentAndRecipientInfo.SendEmailWithAttachment) { var report = CreatePurchaseOrderPrint(Order.OrderID); PrepareDirectory("~/UploadedFiles/reports/po/"); var reportPath = "~/UploadedFiles/reports/po/" + Order.OrderNumber + ".pdf"; report.ExportToPdf(Server.MapPath(reportPath)); var result = await GaneConfigurationsHelper.CreateTenantEmailNotificationQueue($"#{Order.OrderNumber} - Purchase order", Mapper.Map(Order, new OrderViewModel()), reportPath, shipmentAndRecipientInfo : shipmentAndRecipientInfo, worksOrderNotificationType : (WorksOrderNotificationTypeEnum)EmailTemplate); if (result != "Success") { TempData["Error"] = result; } } GaneOrderDetailsSessionHelper.ClearSessionTokenData(shipmentAndRecipientInfo.PageSessionToken); GaneOrderNotesSessionHelper.ClearSessionTokenData(shipmentAndRecipientInfo.PageSessionToken); return(AnchoredOrderIndex("PurchaseOrders", "Index", "PO")); } } SetViewBagItems(Order, EnumAccountType.Supplier); int id = 0; ViewBag.AllowAccountAddress = caCurrent.CurrentWarehouse().AllowShipToAccountAddress; var accountaddress = _accountServices.GetAllValidAccountContactsByAccountId(id, CurrentTenantId); ViewBag.AccountContactes = new SelectList(accountaddress, "AccountContactId", "ContactEmail", accountaddress.Select(x => x.AccountID).FirstOrDefault()); var directsales = _salesServices.GetDirectSaleOrders(null); ViewBag.DirectOrderList = new SelectList(directsales, "OrderID", "OrderNumber"); if (string.IsNullOrEmpty(shipmentAndRecipientInfo.PageSessionToken)) { ViewBag.ForceRegeneratePageToken = "True"; ViewBag.ForceRegeneratedPageToken = Guid.NewGuid().ToString(); } return(View(Order)); } catch (Exception Exp) { if (Exp.InnerException != null && Exp.InnerException.Message == "Duplicate Order Number") { ModelState.AddModelError("OrderNumber", Exp.Message); } else { ModelState.AddModelError("", Exp.Message); } SetViewBagItems(Order); int id = 0; var accountaddress = _accountServices.GetAllValidAccountContactsByAccountId(id, CurrentTenantId); ViewBag.AccountContactes = new SelectList(accountaddress, "AccountContactId", "ContactEmail", accountaddress.Select(x => x.AccountID).FirstOrDefault()); ViewBag.ForceRegeneratePageToken = "True"; ViewBag.ForceRegeneratedPageToken = shipmentAndRecipientInfo.PageSessionToken ?? Guid.NewGuid().ToString(); var directsales = _salesServices.GetDirectSaleOrders(null); ViewBag.DirectOrderList = new SelectList(directsales, "OrderID", "OrderNumber"); return(View(Order)); } }