private void ProcessOrdersInProcessStatus(ERPClient erpClient) { Console.WriteLine("Attempting to update orders in In-Process status"); var orderToUpdateList = Db.Orders?.Where(x => x.OrderStatusTypeId == 5); Console.WriteLine($"Number of orders from DC in status 5 are {orderToUpdateList?.Count()}"); if (orderToUpdateList != null && orderToUpdateList.Count() > 0) { foreach (var item in orderToUpdateList) { var result = erpClient.CheckStatusForInProcessOrdersAsync(item.ERPOrderNumber); Console.WriteLine($"Sent request to ERP for Order Number - { item.ERPOrderNumber}"); if (result != null && result.ProjectID != 0) { var orderToUpdate = orderToUpdateList?.FirstOrDefault(x => x.QuoteId == result.QuoteID); if (orderToUpdate != null) { Console.WriteLine($"Order match for - { orderToUpdate.OrderId }"); orderToUpdate.OrderStatusTypeId = 6; orderToUpdate.WebServiceImportStatus = "InProcessOrdersUpdate"; UpdateAndLogOrdersInDC(orderToUpdate); } } } } }
private void ProcessOrderStatusImport() { using (var erpClient = new ERPClient()) { //Pull all orders from DC with Order status = 2 (Submitted) //Loop through each order in EDI850HDR and lookup in EDI850 using PO Key // If exist, update orders to 3(Awaiting CSR) and update DC Order Timestamp ProcessOrdersInSubmittedStatus(erpClient); //Pull all orders from DC with Order Status = 3 (Awaiting CSR) //Loop through each order in OECPLGP and update DC Order Timestamp, // DC order status to 6 (Picked) ProcessOrdersInAwaitingCSRStatus(erpClient); //Pull all order with Order Status = 5(In Process) //Loop through each order and lookup in Mapics(??? Mahesh / Ashok) table // Update DC Order ERPInvoiceNumber, ERPInvoiceDate, ERPShipDate, Timestamp ProcessOrdersInProcessStatus(erpClient); //Pull all order with Order Status = 6(Picked) //Loop through each order and lookup in MBDHREP table //If order number exists in MBDHREP and DHINST = 50 then Order status to 8(Invoiced) // Else If order number exists in MBDHREP and DHINST = 20 then Order status to 7(Shipped) // Update DC Order ERPInvoiceNumber, ERPInvoiceDate, ERPShipDate, Timestamp // Update DC Project as already done in code ProcessOrdersInPickedStatus(erpClient); } }
private void ProcessOrdersInAwaitingCSRStatus(ERPClient erpClient) { Console.WriteLine("Attempting to update orders in Awaiting CSR Status"); var orderList = erpClient.CheckStatusForAwaitingCSROrdersAsync(); if (orderList != null && orderList.Count() > 0) { //Group the list as it might contain duplicates with different comments var groupedByOrderList = GetGroupedByOrderList(orderList); Console.WriteLine($"Numbers of orders imported from Orders table are {groupedByOrderList?.Count()}"); //Get all orders currently in statustypeId = 3 var orderToUpdateList = Db.Orders?.Where(x => x.OrderStatusTypeId == 3); //If any record is found in DC that is in status 3 if (orderToUpdateList != null && orderToUpdateList.Count() > 0) { foreach (var order in groupedByOrderList.ToList().Where(x => orderToUpdateList.Any(y => y.QuoteId == x.QuoteID))) { var orderToUpdate = orderToUpdateList?.FirstOrDefault(x => x.QuoteId == order.QuoteID); if (orderToUpdate != null) { Console.WriteLine($"Order match found for {orderToUpdate.OrderId} in DC"); orderToUpdate.ERPOrderNumber = order.OrderNumber; orderToUpdate.ERPOrderDate = order.OrderDate; orderToUpdate.ERPStatus = order.OrderStatus; orderToUpdate.ERPComment = order.OrderComment; orderToUpdate.OrderStatusTypeId = 5; orderToUpdate.WebServiceImportStatus = "AwaitingCSROrdersUpdate"; UpdateAndLogOrdersInDC(orderToUpdate); //Also update associated Project var quote = Db.Quotes?.FirstOrDefault(x => x.QuoteId == orderToUpdate.QuoteId); if (quote != null) { Console.WriteLine($"Project match found for {quote.ProjectId} in DC"); UpdateProjectsToOpenOrderStatus(quote.ProjectId, order); } } } } } else { Console.WriteLine("No orders came through from MBC6REP."); } }
private void ProcessInvoicesImportByDateTime(string datetime) { using (var erpClient = new ERPClient()) { var invoiceList = erpClient.GetInvoicesToUpdateInDCAsync(string.IsNullOrEmpty(datetime) ? null : datetime); if (invoiceList != null && invoiceList.Count() > 0) { foreach (var invoice in invoiceList) { UpdateProjectsToShippedStatus(invoice.ProjectID, invoice); } } else { Console.WriteLine("No orders were imported from Mapics."); } } }
private void ProcessOrdersInPickedStatus(ERPClient erpClient) { Console.WriteLine("Attempting to update orders in Picked status"); var orderToUpdateList = Db.Orders?.Where(x => x.OrderStatusTypeId == 6); Console.WriteLine($"Number of orders from DC in status 6 are {orderToUpdateList?.Count()}"); if (orderToUpdateList != null && orderToUpdateList.Count() > 0) { foreach (var item in orderToUpdateList) { var result = erpClient.CheckStatusForPickedOrdersAsync(item.ERPOrderNumber); Console.WriteLine($"Sent request to ERP for Order Number - { item.ERPOrderNumber}"); if (result != null && result.QuoteID != 0) { var orderToUpdate = orderToUpdateList?.FirstOrDefault(x => x.QuoteId == result.QuoteID); if (orderToUpdate != null) { Console.WriteLine($"Order match for - { orderToUpdate.OrderId }"); orderToUpdate.ERPInvoiceNumber = result.InvoiceNumber; orderToUpdate.ERPInvoiceDate = result.InvoiceDate; orderToUpdate.ERPShipDate = result.ShipmentDate; orderToUpdate.OrderStatusTypeId = 7; orderToUpdate.WebServiceImportStatus = "PickedOrdersUpdate"; UpdateAndLogOrdersInDC(orderToUpdate); var quote = Db.Quotes?.FirstOrDefault(x => x.QuoteId == orderToUpdate.QuoteId); if (quote != null) { UpdateProjectsToShippedStatus(quote.ProjectId, result); } } } else { Console.WriteLine($"No match found in Mapics for - { item.ERPOrderNumber} to confirm if the order is picked"); } } } }
public ServiceResponse CheckPONumberExist(string erpAccountId, string poNumber) { var count = (from o in this.Context.Orders select o).Count(o => o.PONumber == poNumber && o.Quote.Project.Owner.Business.ERPAccountId == erpAccountId); if (count > 0) { Response.Messages.AddError("PONumber", "PO number already exists"); return(Response); } else { using (var erpClient = new ERPClient()) { Response = erpClient.GetOrderInfoFromMapicsAsync(erpAccountId, poNumber); //connect to mapics web api call } return(Response); } }
private void ProcessOrdersInSubmittedStatus(ERPClient erpClient) { Console.WriteLine("Attempting to update orders in Submitted Status"); var orderList = erpClient.CheckStatusForSubmittedOrdersAsync(); if (orderList != null && orderList.Count() > 0) { Console.WriteLine($"Numbers of orders imported from EDI850HDR are {orderList?.Count()}"); //Get all orders currently in statustypeId = 2 var orderToUpdateList = Db.Orders?.Where(x => x.OrderStatusTypeId == 2); //If any record is found in DC that is in status 2 if (orderToUpdateList != null && orderToUpdateList.Count() > 0) { foreach (var order in orderList.ToList()) { var orderToUpdate = orderToUpdateList?.FirstOrDefault(x => x.QuoteId == order.QuoteID); if (orderToUpdate != null) { Console.WriteLine($"Order match found for QuoteId {order.QuoteID} in DC"); orderToUpdate.OrderStatusTypeId = 3; //update order status to awaiting csr orderToUpdate.WebServiceImportStatus = "SubmittedOrdersUpdate"; UpdateAndLogOrdersInDC(orderToUpdate); } } } } else { Console.WriteLine("No orders came through from EDI850HDR."); } }
private void ProcessOrdersImportByDateTime(string datetime) { using (var erpClient = new ERPClient()) { var orderList = erpClient.GetOrdersToUpdateInDCAsync(string.IsNullOrEmpty(datetime) ? null : datetime); if (orderList != null && orderList.Count() > 0) { var groupedByOrderList = GetGroupedByOrderList(orderList); if (groupedByOrderList != null && groupedByOrderList.Count() > 0) { foreach (var order in groupedByOrderList.ToList()) { UpdateProjectsToOpenOrderStatus(order.ProjectID, order); } } } else { Console.WriteLine("No orders were imported from Mapics."); } } }
public ServiceResponse CheckWithMapicsBeforeSavingToDb(List <OrderItemsViewModel> orderItemsVm, Order order, OrderViewModelLight model) { var orderDetailList = new List <OrderDetail>(); // array of order detail to send it to mapics var address = Db.Addresses.FirstOrDefault(x => x.AddressId == model.ShipToAddressId); var state = Db.States.FirstOrDefault(x => x.StateId == address.StateId); var increment = 1; foreach (var item in orderItemsVm) { var orderDetail = new OrderDetail() { LineSeq = increment, ProductNumber = item.ProductNumber, CustomerProductNo = "", Quantity = item.Quantity, NetPrice = item.NetPrice, ExtendedNetPrice = item.ExtendedPrice, ProductDescription = "", DiscountPercent = item.DiscountPercentage, CompanyNo = 1, }; increment++; orderDetailList.Add(orderDetail); } //construct json array to post it to mapics var jsonData = new ERPOrderInfo { CustomerNumber = !string.IsNullOrWhiteSpace(model.ERPAccountId) ? Convert.ToInt32(model.ERPAccountId) : 0, PONo = model.PONumber, PODate = DateTime.Today, RequestDate = model.OrderReleaseDate, TermsCode = "", OrderType = "DK", ShipToName = model.ShipToName, ShipToAddress1 = address?.AddressLine1, ShipToAddress2 = address?.AddressLine2, ShipToCity = address?.Location, ShipToState = state?.Code, ShipToZip = address?.PostalCode, ShipToInstruction = order.Comments, ///From Delivery notes ContactName = model.DeliveryContactName, ContactPhone = model.DeliveryContactPhone, TotalAmount = model.TotalNetPrice, OrderCode = "DK", Status = model.ERPStatus, ShipToNumber = null, CompanyNo = 1, BusinessID = model.BusinessId.GetValueOrDefault(), BusinessName = model.BusinessName, ProjectID = model.ProjectId, ProjectName = model.ProjectName, ProjectRefID = null, QuoteID = model.QuoteId, QuoteRefID = null, Comments = model.Comments, DiscountPercent = 0, Details = orderDetailList?.ToArray() }; using (var erpClient = new ERPClient()) { this.Response = erpClient.PostOrderToMapicsAsync(jsonData); } return(this.Response); }