public FacturaDeCompraPM(ConexionDB DatosConexionDB) { _DatosConexionDB = DatosConexionDB; facturaPm = new taPMTransactionInsert(); facturaPmType = new PMTransactionType(); _distribucionPm = new taPMDistribution_ItemsTaPMDistribution[2]; }
public APInvoiceResponseDto ImportGPInvoice(taPMTransactionInsert pmTransaction) { var response = new APInvoiceResponseDto(); try { var PMTransaction = new PMTransactionType(); PMTransaction.taPMTransactionInsert = pmTransaction; PMTransactionType[] PMTransType = { PMTransaction }; eConnectType eConnect = new eConnectType(); eConnect.PMTransactionType = PMTransType; MemoryStream memStream = new MemoryStream(); XmlSerializer serializer = new XmlSerializer(eConnect.GetType()); serializer.Serialize(memStream, eConnect); memStream.Position = 0; XmlDocument xmlDocument = new XmlDocument(); xmlDocument.Load(memStream); memStream.Close(); string finalXML = xmlDocument.OuterXml; string responseMessage = string.Empty; string errorMessage = string.Empty; string voucher = pmTransaction.VCHNUMWK; string docNumber = pmTransaction.DOCNUMBR; string vendorID = pmTransaction.VENDORID; bool success = eConn.CreateTransactionEntity(ref responseMessage, finalXML, _config.Value.GPCompanyDB); response.Success = success; response.ErrorCode = 0; if (success) { response.Message = "Vendor " + vendorID + " invoice " + docNumber + " imported as voucher " + voucher; } else { errorMessage = "Failed to import vendor " + vendorID + " invoice " + docNumber + ": " + responseMessage; response.Message = errorMessage; response.ErrorCode = LoggingEvents.INSERT_INVOICE_FAILED; } return(response); } catch (Exception ex) { response.Success = false; response.ErrorCode = LoggingEvents.INSERT_INVOICE_EXCEPTION; response.Message = "An unexpected error occured in ImportGPInvoice: " + ex.Message; return(response); } }
/// <summary> /// serialize payables object /// </summary> /// <param name="filename"></param> public static void SerializePayablesObject(string filename) { try { // Instantiate an eConnectType schema object eConnectType eConnect = new eConnectType(); // Instantiate a PMTransactionType schema object PMTransactionType transactionType = new PMTransactionType(); // Instantiate a taPMTransactionInsert XML node object taPMTransactionInsert transaction = new taPMTransactionInsert(); // Create an XML serializer object XmlSerializer serializer = new XmlSerializer(eConnect.GetType()); // Populate elements of the taPMTransactionInsert XML node object //transaction.CUSTNMBR = "Customer001"; //transaction.CUSTNAME = "Customer 1"; //transaction.ADDRESS1 = "2002 60th St SW"; //transaction.ADRSCODE = "Primary"; //transaction.CITY = "NewCity"; //transaction.ZIPCODE = "52302"; // Populate the PMTransactionType schema with the taPMTransactionInsert XML node transactionType.taPMTransactionInsert = transaction; PMTransactionType[] payablesTransaction = { transactionType }; // Populate the eConnectType object with the PMTransactionType schema object eConnect.PMTransactionType = payablesTransaction; // Create objects to create file and write the customer XML to the file FileStream fs = new FileStream(filename, FileMode.Create); XmlTextWriter writer = new XmlTextWriter(fs, new UTF8Encoding()); // Serialize the eConnectType object to a file using the XmlTextWriter. serializer.Serialize(writer, eConnect); writer.Close(); } // catch any errors that occur and display them to the console catch (System.Exception ex) { Console.Write(ex.ToString()); } }
/// <summary> /// save new payable transaction /// </summary> /// <param name="payable"></param> /// <returns></returns> public OperationResult SavePayableTransaction(PM10000_Payables_Work payable) { var operationResult = new OperationResult(); logger.Debug("Payable is being created..."); using (eConnectMethods e = new eConnectMethods()) { try { // Instantiate a taPMTransactionInsert XML node object taPMTransactionInsert transaction = new taPMTransactionInsert(); //Populate elements of the taUpdateCreateItemRcd XML node object transaction.BACHNUMB = payable.BACHNUMB; transaction.VCHNUMWK = payable.VCHNUMWK; transaction.VENDORID = payable.VENDORID; transaction.DOCNUMBR = payable.DOCNUMBR; transaction.DOCTYPE = payable.DOCTYPE; transaction.DOCAMNT = payable.DOCAMNT; transaction.DOCDATE = payable.DOCDATE.ToShortDateString(); transaction.MSCCHAMT = payable.MSCCHAMT; transaction.PRCHAMNT = payable.PRCHAMNT; transaction.CHRGAMNT = payable.CHRGAMNT; transaction.TAXAMNT = payable.TAXAMNT; transaction.FRTAMNT = payable.FRTAMNT; transaction.TRDISAMT = payable.TRDISAMT; transaction.CASHAMNT = payable.CASHAMNT; transaction.CHEKAMNT = payable.CHEKAMNT; transaction.CRCRDAMT = payable.CRCRDAMT; transaction.DISTKNAM = payable.DISTKNAM; // Instantiate a PMTransactionType schema object PMTransactionType transactiontype = new PMTransactionType(); // Populate the PMTransactionType schema with the taPMTransactionInsert XML node transactiontype.taPMTransactionInsert = transaction; PMTransactionType[] payableTransaction = { 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 PMTransactionType schema object eConnect.PMTransactionType = payableTransaction; // 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); operationResult.Success = true; operationResult.Message = "Success"; } // The eConnectException class will catch eConnect business logic errors. // display the error message on the console catch (eConnectException exc) { Console.Write(exc.ToString()); operationResult.Success = false; operationResult.Message = "Error"; logger.ErrorFormat("Error saving new payables transaction: {0} ", exc.ToString()); } // Catch any system error that might occurr. // display the error message on the console catch (System.Exception ex) { Console.Write(ex.ToString()); operationResult.Success = false; operationResult.Message = "Error"; logger.ErrorFormat("Error saving new payables transaction: {0} ", ex.ToString()); } finally { // Call the Dispose method to release the resources // of the eConnectMethds object e.Dispose(); } } // end of using statement return(operationResult); }
private static void SerializeObject(string filename) { // Create a datetime format object DateTimeFormatInfo dateFormat = new CultureInfo("en-US").DateTimeFormat; try { taPMTransactionInsert PurchInvoice = new taPMTransactionInsert(); PurchInvoice.BACHNUMB = "SAVE"; PurchInvoice.VENDORID = "ACETRAVE0001"; PurchInvoice.DOCAMNT = 500m; PurchInvoice.DOCNUMBR = "15444445"; PurchInvoice.DOCTYPE = 1; PurchInvoice.VCHNUMWK = "8914985"; PurchInvoice.DOCDATE = "01/06/2017"; //System.DateTime.Today.ToString("MM/dd/yyyy", dateFormat); PurchInvoice.PRCHAMNT = 500m; PurchInvoice.MSCCHAMT = 0; PurchInvoice.TAXAMNT = 0; PurchInvoice.FRTAMNT = 0; PurchInvoice.TRDISAMT = 0; PurchInvoice.CHRGAMNT = 500m; PurchInvoice.CREATEDIST = 1; // PurchInvoice.DISAMTAV = 0; taPMDistribution_ItemsTaPMDistribution[] LineItems = new taPMDistribution_ItemsTaPMDistribution[2]; taPMDistribution_ItemsTaPMDistribution invLines = new taPMDistribution_ItemsTaPMDistribution(); invLines.DOCTYPE = 1; // invLines.ACTNUMST = "000-1410-00"; invLines.DEBITAMT = 500m; invLines.DISTTYPE = 6; invLines.VCHRNMBR = PurchInvoice.VCHNUMWK; invLines.VENDORID = PurchInvoice.VENDORID; invLines.ACTINDX = 10; LineItems[0] = invLines; invLines = new taPMDistribution_ItemsTaPMDistribution(); invLines.DOCTYPE = 1; invLines.DISTTYPE = 2; invLines.VCHRNMBR = PurchInvoice.VCHNUMWK; invLines.VENDORID = PurchInvoice.VENDORID; invLines.CRDTAMNT = PurchInvoice.DOCAMNT; invLines.ACTINDX = 35; //Reset the lines LineItems[1] = invLines; PMTransactionType crInvoice = new PMTransactionType(); crInvoice.taPMTransactionInsert = PurchInvoice; crInvoice.taPMDistribution_Items = LineItems; PMTransactionType[] myPMTrancationType = { crInvoice }; eConnectType eConnect = new eConnectType(); eConnect.PMTransactionType = myPMTrancationType; FileStream fs = new FileStream(filename, FileMode.Create); XmlTextWriter writer = new XmlTextWriter(fs, new UTF8Encoding()); // Serialize the eConnect document object to the file using the XmlTextWriter. XmlSerializer serializer = new XmlSerializer(eConnect.GetType()); serializer.Serialize(writer, eConnect); writer.Close(); } //If an eConnect exception occurs, notify the user catch (eConnectException ex) { Console.Write(ex.ToString()); } }
/// <summary> /// Set Header Values /// </summary> /// <param name="transaction"></param> /// <param name="VCHRNUMBER"></param> /// <returns></returns> private taPMTransactionInsert SetTransactionValues(PMTransactionHeader transaction, string VCHRNUMBER) { try { var pmTransactionInsert = new taPMTransactionInsert { BACHNUMB = transaction.BACHNUMB, VCHNUMWK = VCHRNUMBER, VENDORID = transaction.VENDORID, DOCNUMBR = transaction.DOCNUMBR, DOCTYPE = transaction.DOCTYPE, DOCDATE = transaction.DOCDATE.ToString("yyyy-MM-dd"), VADCDTRO = transaction.VADCDTRO, VADDCDPR = transaction.VADDCDPR, PYMTRMID = transaction.PYMTRMID, TAXSCHID = transaction.TAXSCHID, DUEDATE = transaction.DUEDATE.ToString("yyyy-MM-dd"), DSCDLRAM = transaction.DSCDLRAM.GetValueOrDefault(), PRCHAMNT = transaction.PRCHAMNT, CASHAMNT = transaction.CASHAMNT.GetValueOrDefault(), CAMCBKID = transaction.CAMCBKID, CDOCNMBR = transaction.CDOCNMBR, CAMPMTNM = transaction.CAMPMTNM, CHEKAMNT = transaction.CHEKAMNT.GetValueOrDefault(), CHAMCBID = transaction.CHAMCBID, CAMPYNBR = transaction.CAMPYNBR, CRCRDAMT = transaction.CRCRDAMT.GetValueOrDefault(), CCAMPYNM = transaction.CCAMPYNM, CHEKNMBR = transaction.CHEKNMBR, CARDNAME = transaction.CARDNAME, CCRCTNUM = transaction.CCRCTNUM, CHEKBKID = transaction.CHEKBKID, TRXDSCRN = transaction.TRXDSCRN, TRDISAMT = transaction.TRDISAMT.GetValueOrDefault(), TAXAMNT = transaction.TAXAMNT.GetValueOrDefault(), FRTAMNT = transaction.FRTAMNT.GetValueOrDefault(), TEN99AMNT = transaction.TEN99AMNT.GetValueOrDefault(), MSCCHAMT = transaction.MSCCHAMT.GetValueOrDefault(), PORDNMBR = transaction.PORDNMBR, SHIPMTHD = transaction.SHIPMTHD, DISAMTAV = transaction.DISAMTAV.GetValueOrDefault(), DISTKNAM = transaction.DISTKNAM.GetValueOrDefault(), APDSTKAM = transaction.APDSTKAM.GetValueOrDefault(), MDFUSRID = transaction.MDFUSRID, PTDUSRID = transaction.PTDURID, PCHSCHID = transaction.PCHSCHID, FRTSCHID = transaction.FRTSCHID, MSCSCHID = transaction.MSCSCHID, PRCTDISC = transaction.PRCTDISC.GetValueOrDefault(), CURNCYID = transaction.CURNCYID, XCHGRATE = transaction.XCHGRATE.GetValueOrDefault(), RATETPID = transaction.RATEPID, EXGTBDSC = transaction.EXGTBDSC, EXTBLSRC = transaction.EXTBLSRC, RATEEXPR = transaction.RATEEXPR.GetValueOrDefault(), DYSTINCR = transaction.DYSTINCR.GetValueOrDefault(), RATEVARC = transaction.RATEVARC.GetValueOrDefault(), TRXDTDEF = transaction.TRXDTDEF.GetValueOrDefault(), RTCLCMTD = transaction.RTCLCMTD.GetValueOrDefault(), PRVDSLMT = transaction.PRVDSLMT.GetValueOrDefault(), DATELMTS = transaction.DATELMTS.GetValueOrDefault(), BatchCHEKBKID = transaction.BatchCHEKBKID, CREATEDIST = transaction.CREATEDIST.GetValueOrDefault(), RequesterTrx = transaction.RequesterTrx.GetValueOrDefault() }; pmTransactionInsert.DOCAMNT = pmTransactionInsert.MSCCHAMT + pmTransactionInsert.PRCHAMNT + pmTransactionInsert.TAXAMNT + pmTransactionInsert.FRTAMNT + pmTransactionInsert.TRDISAMT; pmTransactionInsert.CHRGAMNT = pmTransactionInsert.DOCAMNT - pmTransactionInsert.CASHAMNT - pmTransactionInsert.CHEKAMNT - pmTransactionInsert.CRCRDAMT - pmTransactionInsert.DISTKNAM; if (transaction.PSTGDATE != null) { pmTransactionInsert.PSTGDATE = transaction.PSTGDATE.GetValueOrDefault().ToString("yyyy-MM-dd"); } if (transaction.DISCDATE != null) { pmTransactionInsert.DISCDATE = transaction.DISCDATE.GetValueOrDefault().ToString("yyyy-MM-dd"); } if (transaction.CAMTDATE != null) { pmTransactionInsert.CAMTDATE = transaction.CAMTDATE.GetValueOrDefault().ToString("yyyy-MM-dd"); } if (transaction.CRCARDDT != null) { pmTransactionInsert.CRCARDDT = transaction.CRCARDDT.GetValueOrDefault().ToString("yyyy-MM-dd"); } if (transaction.CHEKDATE != null) { pmTransactionInsert.CHEKDATE = transaction.CHEKDATE.GetValueOrDefault().ToString("yyyy-MM-dd"); } if (transaction.POSTEDDT != null) { pmTransactionInsert.POSTEDDT = transaction.POSTEDDT.GetValueOrDefault().ToString("yyyy-MM-dd"); } if (transaction.Tax_Date != null) { pmTransactionInsert.Tax_Date = transaction.Tax_Date.GetValueOrDefault().ToString("yyyy-MM-dd"); } if (transaction.EXPNDATE != null) { pmTransactionInsert.EXPNDATE = transaction.EXPNDATE.GetValueOrDefault().ToString("yyyy-MM-dd"); } if (transaction.EXCHDATE != null) { pmTransactionInsert.EXCHDATE = transaction.EXCHDATE.GetValueOrDefault().ToString("yyyy-MM-dd"); } return(pmTransactionInsert); } catch (Exception) { throw; } }