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); }