/// <summary> /// save new inventory transaction /// </summary> /// <param name="transaction"></param> /// <param name="transactionLines"></param> /// <returns></returns> public OperationResult SaveInventoryTransaction(IV10000_IventoryTransaction_Work transaction, List <IV10000_IventoryTransaction_Work> transactionLines) { var operationResult = new OperationResult(); logger.Debug("Receipt is being created..."); using (eConnectMethods e = new eConnectMethods()) { try { if (transactionLines != null && transactionLines.Count > 0) { taIVTransactionLotInsert_ItemsTaIVTransactionLotInsert[] lotItems = new taIVTransactionLotInsert_ItemsTaIVTransactionLotInsert[transactionLines.Count]; taIVTransactionLineInsert_ItemsTaIVTransactionLineInsert[] lineItems = new taIVTransactionLineInsert_ItemsTaIVTransactionLineInsert[transactionLines.Count]; var transactionLineNumber = 16384; var lineNumber = 0; foreach (var transactionLine in transactionLines) { //// Instantiate a taUpdateCreateItemRcd XML node object taIVTransactionLotInsert_ItemsTaIVTransactionLotInsert transactionLotItem = new taIVTransactionLotInsert_ItemsTaIVTransactionLotInsert(); //Populate elements of the taUpdateCreateItemRcd XML node object transactionLotItem.IVDOCNBR = transactionLine.IVDOCNBR; transactionLotItem.IVDOCTYP = transactionLine.IVDOCTYP; transactionLotItem.LOTNUMBR = transactionLine.LOTNUMBR; transactionLotItem.ITEMNMBR = transactionLine.ITEMNMBR; transactionLotItem.SERLTQTY = transactionLine.TRXQTY; transactionLotItem.LOCNCODE = transactionLine.TRXLOCTN; //transactionLotItem.EXPNDATE = transactionLine.EXPNDATE; //transactionLotItem.DATERECD = transactionLine.DATERECD; lotItems[lineNumber] = transactionLotItem; // Instantiate a taUpdateCreateItemRcd XML node object taIVTransactionLineInsert_ItemsTaIVTransactionLineInsert transactionLineItem = new taIVTransactionLineInsert_ItemsTaIVTransactionLineInsert(); //Populate elements of the taUpdateCreateItemRcd XML node object transactionLineItem.IVDOCNBR = transactionLine.IVDOCNBR; transactionLineItem.IVDOCTYP = transactionLine.IVDOCTYP; //transactionLineItem.LNSEQNBR = transactionLine.LNSEQNBR; transactionLineItem.ITEMNMBR = transactionLine.ITEMNMBR; transactionLineItem.TRXLOCTN = transactionLine.TRXLOCTN; transactionLineItem.TRXQTY = transactionLine.TRXQTY; //transactionLineItem.Reason_Code = transactionLine.Reason_Code; lineItems[lineNumber] = transactionLineItem; transactionLineNumber = transactionLineNumber * 2; lineNumber++; } // Instantiate a taUpdateCreateItemRcd XML node object taIVTransactionHeaderInsert transactionHeader = new taIVTransactionHeaderInsert(); //Populate elements of the taUpdateCreateItemRcd XML node object transactionHeader.BACHNUMB = transaction.BACHNUMB; transactionHeader.IVDOCNBR = transaction.IVDOCNBR; transactionHeader.IVDOCTYP = transaction.IVDOCTYP; transactionHeader.DOCDATE = transaction.DOCDATE; // Instantiate a IVItemMasterType schema object IVInventoryTransactionType transactiontype = new IVInventoryTransactionType(); // Populate the IVItemMasterType schema with the taUpdateCreateItemRcd XML node transactiontype.taIVTransactionLotInsert_Items = lotItems; transactiontype.taIVTransactionLineInsert_Items = lineItems; transactiontype.taIVTransactionHeaderInsert = transactionHeader; IVInventoryTransactionType[] transactionEntry = { transactiontype }; // Instantiate an eConnectType schema object eConnectType eConnect = new eConnectType(); // Instantiate a Memory Stream object MemoryStream memoryStream = new MemoryStream(); // Create an XML serializer object XmlSerializer serializer = new XmlSerializer(eConnect.GetType()); // Populate the eConnectType object with the IVItemMasterType schema object eConnect.IVInventoryTransactionType = transactionEntry; /////////////////////////////////////////////////////////////////////////////// // Serialize the eConnectType. serializer.Serialize(memoryStream, eConnect); // Reset the position of the memory stream to the start. memoryStream.Position = 0; // Create an XmlDocument from the serialized eConnectType in memory. XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(memoryStream); memoryStream.Close(); // Call eConnect to process the XmlDocument. e.CreateEntity(_dynamicsConnection, xmlDocument.OuterXml); ///////////////////////////////////////////////////////////////////////////////// //string xmldocument; //SerializeTransactionObject("C:\\inventoryTransaction.xml", transaction, transactionLines); ////Use an XML document to create a string representation of the customer //XmlDocument xmldoc = new XmlDocument(); //xmldoc.Load("C:\\inventoryTransaction.xml"); //xmldocument = xmldoc.OuterXml; ////Call eConnect to process the xmldocument. //e.CreateEntity(_dynamicsConnection, xmldocument); ////////////////////////////////////////////////////////////////////////////////// operationResult.Success = true; operationResult.Message = "Success"; } else { operationResult.Success = false; operationResult.Message = "No items are attached to receive."; } } // The eConnectException class will catch eConnect business logic errors. // display the error message on the console catch (eConnectException exc) { operationResult.Success = false; operationResult.Message = "Error"; logger.ErrorFormat("Error saving new receipt: {0} ", exc.ToString()); } // Catch any system error that might occurr. // display the error message on the console catch (System.Exception ex) { operationResult.Success = false; operationResult.Message = "Error"; logger.ErrorFormat("Error saving new receipt: {0} ", ex.ToString()); } finally { // Call the Dispose method to release the resources // of the eConnectMethds object e.Dispose(); } } // end of using statement return(operationResult); }
public Boolean CreateInventoryAdjustment(Document inventoryAdj, short adjType) //adjType: Ajustment or Variance { eConnectType eConnect; try { taIVTransactionLineInsert_ItemsTaIVTransactionLineInsert[] docLines = new taIVTransactionLineInsert_ItemsTaIVTransactionLineInsert[inventoryAdj.DocumentLines.Count]; //Create an object that holds XML node object taIVTransactionLineInsert_ItemsTaIVTransactionLineInsert curLine; int i = 1; int sign; // Next consecutive for a Purchase Receipt foreach (DocumentLine dr in inventoryAdj.DocumentLines) { curLine = new taIVTransactionLineInsert_ItemsTaIVTransactionLineInsert(); // Populate Lines curLine.ITEMNMBR = dr.Product.ProductCode; curLine.IVDOCNBR = inventoryAdj.DocNumber; curLine.IVDOCTYP = (short)((adjType == GP_DocType.IV_Variance) ? GP_DocType.IV_Variance : GP_DocType.IV_Adjustment); curLine.LNSEQNBR = i; curLine.TRXLOCTN = inventoryAdj.Location.ErpCode; curLine.UOFM = dr.Unit.ErpCode; /* Override quantity flag; to use this element, inventory control must allow for adjustment overrides: 0=Reset TRXQTY with quantity available; 1=Override quantity available and use TRXQTY Se debe configurar en el GP la Opcion en el Inventory Control */ curLine.OverrideQty = 1; sign = (dr.IsDebit == true) ? -1 : 1; curLine.TRXQTY = sign * Decimal.Parse(dr.Quantity.ToString()); docLines[i-1] = curLine; i++; } //Create a SOPTransactionType schema object and populate its taSopLineIvcInsert_Items poperty IVInventoryTransactionType docType = new IVInventoryTransactionType(); docType.taIVTransactionLineInsert_Items = docLines; //Create a taSopHdrIvcInsert XML node object taIVTransactionHeaderInsert docHdr = new taIVTransactionHeaderInsert(); //Populate Header //BATCH si hay notes, ahi se pone el BATCH if (string.IsNullOrEmpty(inventoryAdj.Notes)) docHdr.BACHNUMB = inventoryAdj.Location.ErpCode + "_" + GPBatchNumber.Inventory; else docHdr.BACHNUMB = inventoryAdj.Notes; docHdr.DOCDATE = ((DateTime)inventoryAdj.Date1).ToString("yyyy-MM-dd"); //DateTime.Today.ToString(); docHdr.IVDOCNBR = inventoryAdj.DocNumber; //IA00119 //Determina si crea un adjustment o variance. docHdr.IVDOCTYP = (short)((adjType == GP_DocType.IV_Variance) ? GP_DocType.IV_Variance : GP_DocType.IV_Adjustment); docHdr.NOTETEXT = inventoryAdj.Comment; docType.taIVTransactionHeaderInsert = docHdr; IVInventoryTransactionType[] docTypeArray = new IVInventoryTransactionType[1]; docTypeArray[0] = docType; //Create an eConnect XML document object and populate its docType property with //the docType schema object eConnect = new eConnectType(); eConnect.IVInventoryTransactionType = docTypeArray; //Serialize the XML document to the file XmlSerializer serializer = new XmlSerializer(typeof(eConnectType)); StringWriter writer = new StringWriter(); serializer.Serialize(writer, eConnect); DynamicsGP_ec.SendData(writer.ToString()); return true; } catch (Exception ex) { throw new Exception(WriteLog.GetTechMessage(ex)); //ExceptionMngr.WriteEvent("CreateInventoryAdjustment:" + inventoryAdj.DocNumber, ListValues.EventType.Error, // ex, null, ListValues.ErrorCategory.ErpConnection); //return false; } }