// This function processes just one order static int P21SalesOrder(DataRow drOrder) { int nReturnCode = 0; try { RestClientSecurity rcs = P21.Soa.Service.Rest.Common.RestResourceClientHelper.GetClientSecurity(strToken); // This call generates a client which has all of the exposed rest methods. Token security is used based off the user and password. P21.Soa.Service.Rest.Sales.OrderResourceClient orderResourceClient = new P21.Soa.Service.Rest.Sales.OrderResourceClient(Properties.order.Default.rootUri, rcs); // Setup the variables used to store data during processing orderResourceClient.AcceptType = AcceptTypes.xml; P21.DomainObject.Sales.Order.Order orderCreate = new P21.DomainObject.Sales.Order.Order(); //Populate the main fields for the order orderCreate.CustomerId = Convert.ToInt32(drOrder["CustomerID"]); orderCreate.CompanyId = drOrder["CompanyID"].ToString(); orderCreate.LocationId = Convert.ToInt32(drOrder["SalesLocationID"]); orderCreate.PoNo = drOrder["CustomerPONumber"].ToString(); orderCreate.Taker = drOrder["Taker"].ToString(); orderCreate.JobName = drOrder["JobName"].ToString(); orderCreate.OrderDate = Convert.ToDateTime(drOrder["OrderDate"].ToString()); orderCreate.RequestedDate = Convert.ToDateTime(drOrder["RequestedDate"].ToString()); orderCreate.Quote = drOrder["Quote"].ToString(); orderCreate.Approved = ((drOrder["Approved"].ToString() == "Y") ? true : false); orderCreate.ShipToId = Convert.ToInt32(drOrder["ShipToID"].ToString()); orderCreate.ShipToName = drOrder["ShipToName"].ToString(); orderCreate.ShipToAddress1 = drOrder["ShipToAddress1"].ToString(); orderCreate.ShipToAddress2 = drOrder["ShipToAddress2"].ToString(); orderCreate.ShipToAddress3 = drOrder["ShipToAddress3"].ToString(); orderCreate.ShipToCity = drOrder["ShipToCity"].ToString(); orderCreate.OeHdrShip2State = drOrder["ShipToState"].ToString(); orderCreate.ZipCode = drOrder["ShipToZipCode"].ToString(); orderCreate.ShipToCountry = drOrder["ShipToCountry"].ToString(); orderCreate.SourceLocationId = Convert.ToInt32(drOrder["SourceLocationID"].ToString()); orderCreate.CarrierId = Convert.ToInt32(drOrder["CarrierID"].ToString()); orderCreate.PackingBasis = drOrder["PackingBasis"].ToString(); orderCreate.DeliveryInstructions = drOrder["DeliveryInstructions"].ToString(); orderCreate.Terms = drOrder["Terms"].ToString(); orderCreate.Class1id = drOrder["Class1"].ToString(); orderCreate.RMA = drOrder["RMAFlag"].ToString(); orderCreate.WebReferenceNo = drOrder["WebReferenceNumber"].ToString(); orderCreate.CreateInvoice = ((drOrder["CreateInvoice"].ToString() == "Y") ? true : false); /* RJL 11/15/2019 - Replace the following block with file read to support more flexibility * to stop orders suddenly during a business day without calling support. * * // RJL 05/31/2018 - For Ohio Misc. customers, when there is tax, don't convert to an invoice. * // This is necssary because we don't know which P21 tax jurisdiction to apply. * if ((orderCreate.CustomerId == 10164) || (orderCreate.CustomerId == 10165)) * { * if (Convert.ToDecimal(drOrder["TaxTotal"]) > 0) * { * orderCreate.CreateInvoice = false; * } * } * * Opening the file multiple times isn't super efficient fbut we only do 30 invoices per day so...whatever; Its clean. */ string[] strCustList = System.IO.File.ReadAllLines(@"C:\sism\StopCustomerList.txt"); foreach (string strCustNum in strCustList) { if (orderCreate.CustomerId == Convert.ToInt16(strCustNum)) { orderCreate.CreateInvoice = false; } } // RJL 11/15/2019 - End // Append Header Notes orderCreate.Notes = AppendOrderNotes(drOrder["ImportSet"].ToString()); // Append Salesreps orderCreate.Salesreps = AppendSalesReps(drOrder["ImportSet"].ToString()); // Go get the list of line items for this order from the SQL database //DataSet dsLines = SqlGetOrderLines(Properties.order.Default.SqlQueryLines, drOrder[1].ToString()); DataSet dsLines = SqlGetOrderLines(Properties.order.Default.SqlQueryLines, drOrder["ImportSet"].ToString()); // Declare the list of order detail lines P21.DomainObject.Sales.Order.OrderLines orderLines = new P21.DomainObject.Sales.Order.OrderLines(); // For each line item we add them to the Order with the Notes and Serials int lineNum = 1; foreach (DataRow drLine in dsLines.Tables[0].Rows) { P21.DomainObject.Sales.Order.OrderLine lineItem = new P21.DomainObject.Sales.Order.OrderLine(); // Populate the members of the lineItem object lineItem.LineNo = lineNum; lineItem.ItemId = drLine["ItemID"].ToString(); lineItem.UnitQuantity = Convert.ToDouble(drLine["UnitQuantity"].ToString()); lineItem.UnitOfMeasure = drLine["UnitOfMeasure"].ToString(); lineItem.UnitPrice = Convert.ToDouble(drLine["UnitPrice"].ToString()); lineItem.ExtendedDesc = drLine["ExtendedDescription"].ToString(); lineItem.SourceLocId = Convert.ToInt32(drLine["SourceLocationID"].ToString()); lineItem.ShipLocId = Convert.ToInt32(drLine["ShipLocationID"].ToString()); lineItem.ProductGroupId = drLine["ProductGroupID"].ToString(); lineItem.TaxItem = drLine["TaxItem"].ToString(); lineItem.PricingUnit = drLine["PricingUnit"].ToString(); if (drLine["CommissionCost"].ToString().Length > 0) { lineItem.CommissionCost = Convert.ToDouble(drLine["CommissionCost"].ToString()); } lineItem.ManualPriceOveride = drLine["ManualPriceOverride"].ToString(); // add the serial numbers to the line lineItem.Serials = AppendSerials(drOrder["ImportSet"].ToString(), drLine["LineID"].ToString(), lineNum); // add any line comments/notes lineItem.Notes = AppendOrderLineNotes(drOrder["ImportSet"].ToString(), drLine["LineID"].ToString(), lineNum); // Add this line to the list of order lines orderLines.list.Add(lineItem); lineNum++; } orderCreate.Lines = orderLines; if ((orderCreate.WebReferenceNo != "3099949") && (orderCreate.WebReferenceNo != "3099978") && (orderCreate.WebReferenceNo != "3099983") && (orderCreate.PoNo != "HOLLY ELLIS SN FIX") ) { // Now we have a populated Order XML Document and we can call the webservice // Fingers Crossed!! P21.DomainObject.Sales.Order.Order orderReturn = new P21.DomainObject.Sales.Order.Order(); orderReturn = orderResourceClient.Resource.CreateOrder(orderCreate); //orderCreate.OrderNo = nOrderCount++.ToString(); jtd_utilities.log.AppendLog("Added Order: " + orderReturn.OrderNo.ToString() + " LinesOut " + orderCreate.Lines.list.Count.ToString() + " LinesIn " + orderReturn.Lines.list.Count.ToString()); if (orderReturn.APIInformation != null) { jtd_utilities.log.AppendLog("Return Message: " + orderReturn.APIInformation.ContextMessage); } totalLines += orderCreate.Lines.list.Count; if (orderCreate.Lines.list.Count != orderReturn.Lines.list.Count) { // Identify the order for support String msgText; msgText = "Customer: " + drOrder["CustomerID"].ToString() + " "; msgText += "PO Number: " + drOrder["CustomerPONumber"].ToString() + " "; msgText += "Web Order: " + drOrder["WebReferenceNumber"].ToString(); msgText += "Number of Lines added to P21 does not match SOM lines received."; jtd_utilities.mail.SendEmailMessage(msgText); } } // RJL 01/02/2019 - Why didn't we ever close that orderResourceClient.Close(); } catch (Exception ex) { // Depending on the exception additional error information may be returned in the form or a ResourceError. This helper // will extract that from the exception. ResourceError rErr = ExceptionHandler.GetResourceError(ex); string messageText = ex.ToString(); if (rErr != null) { messageText += Environment.NewLine + Environment.NewLine + "Details: " + Environment.NewLine + rErr.ErrorMessage; } jtd_utilities.log.AppendLog(messageText); // Identify the order for support messageText = "Customer: " + drOrder["CustomerID"].ToString() + " "; messageText += "PO Number: " + drOrder["CustomerPONumber"].ToString() + " "; messageText += "Web Order: " + drOrder["WebReferenceNumber"].ToString(); jtd_utilities.log.AppendLog(messageText); jtd_utilities.mail.SendEmailMessage(messageText); nReturnCode = 0; } finally { } return(nReturnCode); }
static int P21GLEntry() { int nReturnCode = 0; try { // This call generates a client which has all of the exposed rest methods. Token security is used based off the user and password. RestClientSecurity rcs = RestResourceClientHelper.GetClientSecurity(strToken); GlResourceClient glrc = new GlResourceClient(Properties.gl.Default.rootUri, rcs); // Setup the new objects Gl gl = new Gl(); Gl gl1 = new Gl(); List <Gl> gls = new List <Gl>(); DateTime txDate = DateTime.Now; // Get the Dataset from the P21 Database DataSet dsGL = SqlGetGlEntry(); Double GlAmount = 0; String GlSource = ""; // Should only be one row. Save the data we need foreach (DataRow row in dsGL.Tables[0].Rows) { GlSource = row[0].ToString(); GlAmount = Convert.ToDouble(row[1].ToString()); } // First half of the GL entry gl.CompanyNo = "JTD"; gl.AccountNumber = "220010"; gl.Period = DateTime.Now.Month; gl.YearForPeriod = DateTime.Now.Year; gl.JournalId = "PJ"; gl.Amount = GlAmount; gl.Description = "SOM Integration"; gl.ForeignAmount = GlAmount; gl.Source = GlSource; gl.TransactionDate = txDate; gls.Add(gl); // Second half of the GL entry gl1.CompanyNo = "JTD"; gl1.AccountNumber = "221510"; gl1.Period = DateTime.Now.Month; gl1.YearForPeriod = DateTime.Now.Year; gl1.JournalId = "PJ"; gl1.Amount = GlAmount * -1; gl1.Description = "SOM Integration"; gl1.ForeignAmount = GlAmount * -1; gl1.Source = GlSource; gl1.TransactionDate = txDate; gls.Add(gl1); // Call the Middleware API Gl[] glReturn = glrc.Resource.CreateGl(gls.ToArray()); // RJL 01/02/2019 - Why did I never close this?? glrc.Close(); jtd_utilities.log.AppendLog("GL Update successful -- " + GlAmount.ToString()); } catch (Exception ex) { // Depending on the exception additional error information may be returned in the form or a ResourceError. This helper // will extract that from the exception. ResourceError rErr = ExceptionHandler.GetResourceError(ex); string messageText = ex.ToString(); if (rErr != null) { messageText += Environment.NewLine + Environment.NewLine + "Details: " + Environment.NewLine + rErr.ErrorMessage; } jtd_utilities.log.AppendLog(messageText); nReturnCode = -1; } finally { nReturnCode = 0; } return(nReturnCode); }
static int P21InventoryAdjustment() { int nReturnCode = 0; int lineCount = 0; try { RestClientSecurity rcs = RestResourceClientHelper.GetClientSecurity(strToken); // This call generates a client which has all of the exposed rest methods. // Token security is used based off the user and password. P21.Soa.Service.Rest.Inventory.InventoryAdjustmentResourceClient inventoryAdjustmentResourceClient = new P21.Soa.Service.Rest.Inventory.InventoryAdjustmentResourceClient(Properties.inventory.Default.rootUri, rcs); // Setup the variables used to store data during processing inventoryAdjustmentResourceClient.AcceptType = AcceptTypes.xml; InventoryAdjustment adjustmentReturn = new InventoryAdjustment(); // Go get the list of adjustments from the SQL database DataSet dsInventory = SqlGetInventory(); // For each line item we post directly to P21 foreach (DataRow drLine in dsInventory.Tables[0].Rows) { // Retrieve the serial numbers for this inventory item DataSet dsSerials = SqlGetSerialForLine(Convert.ToInt32(drLine[0].ToString()), drLine[1].ToString()); // If we have serial numbers, they are included in the call to middleware if (dsSerials.Tables[0].Rows.Count > 0) { // It's possible we could have more then one serial number for this item. // We post them individually foreach (DataRow drSerial in dsSerials.Tables[0].Rows) { adjustmentReturn = inventoryAdjustmentResourceClient.Resource.CreateWmsAdjustmentWithCost( drLine["SourceLocationID"].ToString(), // Location "SOM Inventory Adjustment", // Reason "Y", // Approved "", // Description drLine["ItemID"].ToString(), // Item "1", // Qty drLine["UnitOfMeasure"].ToString(), // UOM "", // Bin "", // Lot drSerial["SerialNumber"].ToString().Trim(), // Serial drLine["Cost"].ToString()); // Cost if (adjustmentReturn.Lines.list[0].Serials.list.Count > 0) { jtd_utilities.log.AppendLog("Added Item -- " + adjustmentReturn.Lines.list[0].ItemId + " -- " + adjustmentReturn.Lines.list[0].Serials.list[0].SerialNumber); } else { jtd_utilities.log.AppendLog("Added Item -- " + adjustmentReturn.Lines.list[0].ItemId + " -- Serial not returned"); } } } else { // If there is no serial number, we still post the adjustment for stockable items but the Quantity can be multiples. adjustmentReturn = inventoryAdjustmentResourceClient.Resource.CreateWmsAdjustmentWithCost( drLine["SourceLocationID"].ToString(), // Location "SOM Inventory Adjustment", // Reason "Y", // Approved "", // Description drLine["ItemID"].ToString(), // Item drLine["AdjAmount"].ToString(), // Qty drLine["UnitOfMeasure"].ToString(), // UOM "", // Bin "", // Lot "", // Serial drLine["Cost"].ToString()); jtd_utilities.log.AppendLog("Added Item -- " + adjustmentReturn.Lines.list[0].ItemId); } lineCount++; } // RJL -- 01/02/2019 - Why did you not close this - DUMMY! inventoryAdjustmentResourceClient.Close(); } catch (Exception ex) { // Depending on the exception additional error information may be returned in the form or a ResourceError. This helper // will extract that from the exception. ResourceError rErr = ExceptionHandler.GetResourceError(ex); string messageText = ex.ToString(); if (rErr != null) { messageText += Environment.NewLine + Environment.NewLine + "Details: " + Environment.NewLine + rErr.ErrorMessage; } jtd_utilities.log.AppendLog(messageText); nReturnCode = -1; } finally { } jtd_utilities.log.AppendLog("Total Items: " + lineCount.ToString()); return(nReturnCode); }