static void Main() { try { QsRetailDataContext qsRetail = new QsRetailDataContext(); WriteToLog("Start export MOLDTELECOM payments"); string[] parts = ConfigurationManager.AppSettings["organizations"].Split(','); int[] organizationList = (from s in parts select int.Parse(s)).ToArray(); string[] orgs = ConfigurationManager.AppSettings["Moldtelecom"].Split(','); int[] moldtelecom = (from s in orgs select int.Parse(s)).ToArray(); orgs = ConfigurationManager.AppSettings["MaxDsl"].Split(','); int[] maxdsl = (from s in orgs select int.Parse(s)).ToArray(); orgs = ConfigurationManager.AppSettings["Unite"].Split(','); int[] unite = (from s in orgs select int.Parse(s)).ToArray(); orgs = ConfigurationManager.AppSettings["UnitePrePay"].Split(','); int[] unitePrePay = (from s in orgs select int.Parse(s)).ToArray(); var qsMovements = from p in qsRetail.Movements where organizationList.Contains(p.OrganizationIDTo) && p.Document.StatusID == 2 && p.IsReceivedTo == false && p.Direction && p.OperationDate >= DateTime.Parse("2012-03-01") && p.Document.TransactionAmount > 0 select p; foreach (var qsMovement in qsMovements) { try { string resp = ""; paymentsWSClient clientService = new paymentsWSClient(); XmlDocument doc = new XmlDocument(); string name = ""; string contract = ""; string tipCont = ""; string searchParam = ""; searchParam = qsMovement.Document.OwnerKey.Length == 8 ? "phone" : "cont"; if (moldtelecom.Contains(qsMovement.OrganizationIDTo)) { resp = clientService.getAccountInfo(user, password, searchParam, qsMovement.Document.OwnerKey, "1"); doc.LoadXml(resp); name = doc.FirstChild.Name; if (name == "error" || doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=1][1]/TIPCONT") == null) { throw new ArgumentException("Error code: " + doc.SelectSingleNode("/error/code").InnerText + " Message: " + doc.SelectSingleNode("/error/message").InnerText); } contract = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=1][1]/CONTRACT").InnerText; tipCont = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=1][1]/TIPCONT").InnerText; } else if (maxdsl.Contains(qsMovement.OrganizationIDTo)) { resp = clientService.getAccountInfo(user, password, searchParam, qsMovement.Document.OwnerKey, "2"); doc.LoadXml(resp); name = doc.FirstChild.Name; if (name == "error" || doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=2][1]/TIPCONT") == null) { throw new ArgumentException("Error code: " + doc.SelectSingleNode("/error/code").InnerText + " Message: " + doc.SelectSingleNode("/error/message").InnerText); } contract = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=2][1]/CONTRACT").InnerText; tipCont = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=2][1]/TIPCONT").InnerText; } else if (unite.Contains(qsMovement.OrganizationIDTo)) { resp = clientService.getAccountInfo(user, password, searchParam, qsMovement.Document.OwnerKey, "3"); doc.LoadXml(resp); name = doc.FirstChild.Name; if (name == "error" || doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=3][1]/TIPCONT") == null) { throw new ArgumentException("Error code: " + doc.SelectSingleNode("/error/code").InnerText + " Message: " + doc.SelectSingleNode("/error/message").InnerText); } contract = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=3][1]/CONTRACT").InnerText; tipCont = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=3][1]/TIPCONT").InnerText; } else if (unitePrePay.Contains(qsMovement.OrganizationIDTo)) { resp = clientService.getAccountInfo(user, password, searchParam, qsMovement.Document.OwnerKey, "4"); doc.LoadXml(resp); name = doc.FirstChild.Name; if (name == "error" || doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=4][1]/TIPCONT") == null) { throw new ArgumentException("Error code: " + doc.SelectSingleNode("/error/code").InnerText + " Message: " + doc.SelectSingleNode("/error/message").InnerText); } contract = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=4][1]/CONTRACT").InnerText; tipCont = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=4][1]/TIPCONT").InnerText; } string result = clientService.addPayment( user, password, contract, qsMovement.RealOperationDate.ToString("yyyyMMdd"), double.Parse(qsMovement.Document.TransactionAmount.ToString("0.00")), "1", int.Parse(tipCont), "VICBMD2X"); if (result.Trim().Substring(0,1) == "<") { doc.LoadXml(result); throw new ArgumentException("Error code: " + doc.SelectSingleNode("/error/code").InnerText + " Message: " + doc.SelectSingleNode("/error/message").InnerText); } qsMovement.IsReceivedTo = true; qsRetail.SubmitChanges(); WriteToLog(string.Format("MovementID : {0} order_id : {1} : Response : {2} OK ", new object[] { qsMovement.ID.ToString(), qsMovement.Document.OwnerKey, result })); } catch (Exception e) { Console.WriteLine(e.Message); WriteToLog(string.Format("{0} : {1} : {2}", new object[] { qsMovement.ID.ToString(), qsMovement.Document.OwnerKey, e.Message })); } } WriteToLog("End export MOLDTELECOM payments"); WriteToLog("Start export MOLDTELECOM unpayments"); var qsUnMovements = from p in qsRetail.Movements where organizationList.Contains(p.OrganizationIDTo) && p.Document.StatusID == 3 && p.IsReceivedTo && p.Direction && p.OperationDate >= DateTime.Parse("2012-03-01") && p.Document.TransactionAmount > 0 select p; foreach (var qsUnMovement in qsUnMovements) { try { string resp = ""; paymentsWSClient clientService = new paymentsWSClient(); XmlDocument doc = new XmlDocument(); string name = ""; string contract = ""; string tipCont = ""; string searchParam = ""; searchParam = qsUnMovement.Document.OwnerKey.Length == 8 ? "phone" : "cont"; if (moldtelecom.Contains(qsUnMovement.OrganizationIDTo)) { resp = clientService.getAccountInfo(user, password, searchParam, qsUnMovement.Document.OwnerKey, "1"); doc.LoadXml(resp); name = doc.FirstChild.Name; if (name == "error" || doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=1][1]/TIPCONT") == null) { throw new ArgumentException("Error code: " + doc.SelectSingleNode("/error/code").InnerText + " Message: " + doc.SelectSingleNode("/error/message").InnerText); } contract = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=1][1]/CONTRACT").InnerText; tipCont = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=1][1]/TIPCONT").InnerText; } else if (maxdsl.Contains(qsUnMovement.OrganizationIDTo)) { resp = clientService.getAccountInfo(user, password, searchParam, qsUnMovement.Document.OwnerKey, "2"); doc.LoadXml(resp); name = doc.FirstChild.Name; if (name == "error" || doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=2][1]/TIPCONT") == null) { throw new ArgumentException("Error code: " + doc.SelectSingleNode("/error/code").InnerText + " Message: " + doc.SelectSingleNode("/error/message").InnerText); } contract = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=2][1]/CONTRACT").InnerText; tipCont = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=2][1]/TIPCONT").InnerText; } else if (unite.Contains(qsUnMovement.OrganizationIDTo)) { resp = clientService.getAccountInfo(user, password, searchParam, qsUnMovement.Document.OwnerKey, "3"); doc.LoadXml(resp); name = doc.FirstChild.Name; if (name == "error" || doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=3][1]/TIPCONT") == null) { throw new ArgumentException("Error code: " + doc.SelectSingleNode("/error/code").InnerText + " Message: " + doc.SelectSingleNode("/error/message").InnerText); } contract = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=3][1]/CONTRACT").InnerText; tipCont = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=3][1]/TIPCONT").InnerText; } else if (unitePrePay.Contains(qsUnMovement.OrganizationIDTo)) { resp = clientService.getAccountInfo(user, password, searchParam, qsUnMovement.Document.OwnerKey, "4"); doc.LoadXml(resp); name = doc.FirstChild.Name; if (name == "error" || doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=4][1]/TIPCONT") == null) { throw new ArgumentException("Error code: " + doc.SelectSingleNode("/error/code").InnerText + " Message: " + doc.SelectSingleNode("/error/message").InnerText); } contract = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=4][1]/CONTRACT").InnerText; tipCont = doc.SelectSingleNode("/ROWSET/ROW[TIPCONT=4][1]/TIPCONT").InnerText; } string result = clientService.addPayment( user, password, contract, qsUnMovement.RealOperationDate.ToString("yyyyMMdd"), -double.Parse(qsUnMovement.Document.TransactionAmount.ToString("0.00")), "1", int.Parse(tipCont), "VICBMD2X"); if (result.Trim().Substring(0, 1) == "<") { doc.LoadXml(result); throw new ArgumentException("Error code: " + doc.SelectSingleNode("/error/code").InnerText + " Message: " + doc.SelectSingleNode("/error/message").InnerText); } qsUnMovement.IsReceivedTo = false; qsRetail.SubmitChanges(); WriteToLog(string.Format("MovementID : {0} order_id : {1} : Response : {2} OK ", new object[] { qsUnMovement.ID.ToString(), qsUnMovement.Document.OwnerKey, result })); } catch (Exception e) { Console.WriteLine(e.Message); WriteToLog(string.Format("{0} : {1} : {2}", new object[] { qsUnMovement.ID.ToString(), qsUnMovement.Document.OwnerKey, e.Message })); } } WriteToLog("End export MOLDTELECOM unpayments"); } catch (Exception e) { Console.WriteLine(e.Message); WriteToLog(e.Message); } }
static void Main(string[] args) { try { WriteToLog("Start adding registr."); string startDate = ""; string endDate = ""; int per = int.Parse(args[0].Substring(1)); if (args[0].Substring(0, 1) == "z") { startDate = DateTime.Today.AddDays(-per).ToString("yyyy-MM-dd"); endDate = DateTime.Today.AddDays(-1).ToString("yyyy-MM-dd"); } else if (args[0].Substring(0, 1) == "l") { DateTime today = DateTime.Today.AddMonths(-per); startDate = new DateTime(today.Year, today.Month, 1).ToString("yyyy-MM-dd"); endDate = new DateTime(DateTime.Today.Year, DateTime.Today.AddMonths(-per + 1).Month, 1).AddDays(-1).ToString("yyyy-MM-dd"); } else { throw new ArgumentException("Invalid parameter format."); } string[] orgs = ConfigurationManager.AppSettings["Moldtelecom"].Split(','); int[] moldtelecom = (from s in orgs select int.Parse(s)).ToArray(); orgs = ConfigurationManager.AppSettings["MaxDsl"].Split(','); int[] maxdsl = (from s in orgs select int.Parse(s)).ToArray(); orgs = ConfigurationManager.AppSettings["Unite"].Split(','); int[] unite = (from s in orgs select int.Parse(s)).ToArray(); orgs = ConfigurationManager.AppSettings["UnitePrePay"].Split(','); int[] unitePrePay = (from s in orgs select int.Parse(s)).ToArray(); long[] stornate = (from s in StornateNeexportate select long.Parse(s)).ToArray(); List<int[]> organizations = new List<int[]> {moldtelecom, maxdsl, unite, unitePrePay}; QsRetailDataContext qsRetail = new QsRetailDataContext(); paymentsWSClient clientService = new paymentsWSClient(); XmlDocument doc = new XmlDocument(); for (int i = 1; i <= organizations.Count; i++) { int count = 0; decimal sum = 0; try { var qsMovements = from p in qsRetail.Movements where organizations[i - 1].Contains(p.OrganizationIDTo) && ((p.Document.StatusID == 2 && p.IsReceivedTo) || (p.Document.StatusID == 3 && p.IsReceivedTo == false)) && p.Direction && p.OperationDate >= DateTime.Parse(startDate) && p.OperationDate < DateTime.Parse(endDate).AddDays(1) && p.Document.TransactionAmount > 0 && !stornate.Contains(p.Document.ID) select p; foreach (var qsMovement in qsMovements) { if (qsMovement.Document.StatusID == 3) { count = count + 2; } else { count++; sum += qsMovement.Document.TransactionAmount; } } string result = clientService.addPaymentsRegistr( user, password, i, DateTime.Parse(startDate).ToString("yyyyMMdd"), DateTime.Parse(endDate).ToString("yyyyMMdd"), "VICBMD2X", sum.ToString("0.00"), count.ToString()); if (result.Trim().Substring(0, 1) == "<") { doc.LoadXml(result); throw new ArgumentException("Error code: " + doc.SelectSingleNode("/error/code").InnerText + " Message: " + doc.SelectSingleNode("/error/message").InnerText + " (" + i + ") Count: " + count.ToString() + " Suma: " + sum.ToString("0.00") + " lei."); } WriteToLog(string.Format("Registru : {0} - {1} : Response : {2} OK ({3}) Count: {4} Suma: {5} lei.", new object[] { startDate, endDate, result, i, count.ToString(), sum.ToString("0.00") })); } catch (Exception e) { Console.WriteLine(e.Message); WriteToLog(e.Message); } } WriteToLog("End adding registr."); } catch (Exception e) { Console.WriteLine(e.Message); WriteToLog(e.Message); } }
public bool GetInvoices(string ticket, string organizationID, string ownerKey, out string invoicesDataAsXml, out string messageDataAsXML) { string[] parts = ConfigurationManager.AppSettings["Moldtelecom"].Split(','); int[] moldtelecom = (from s in parts select int.Parse(s)).ToArray(); parts = ConfigurationManager.AppSettings["MaxDsl"].Split(','); int[] maxdsl = (from s in parts select int.Parse(s)).ToArray(); parts = ConfigurationManager.AppSettings["Unite"].Split(','); int[] unite = (from s in parts select int.Parse(s)).ToArray(); parts = ConfigurationManager.AppSettings["UnitePrePay"].Split(','); int[] unitePrePay = (from s in parts select int.Parse(s)).ToArray(); try { string resp = ""; paymentsWSClient clientService = new paymentsWSClient(); XmlDocument xDoc = new XmlDocument(); string name = ""; string amount = ""; string payFor = ""; string npp = ""; string contract = ""; string branch = ""; string tipCont = ""; string searchParam = ""; searchParam = ownerKey.Length == 8 ? "phone" : "cont"; if (moldtelecom.Contains(int.Parse(organizationID))) { resp = clientService.getAccountInfo(user, password, searchParam, ownerKey, "1"); xDoc.LoadXml(resp); name = xDoc.FirstChild.Name; if (name == "error" || xDoc.SelectSingleNode("/ROWSET/ROW[TIPCONT=1][1]/TIPCONT") == null) { throw new ArgumentException("Error code: " + xDoc.SelectSingleNode("/error/code").InnerText + " Message: " + xDoc.SelectSingleNode("/error/message").InnerText); } amount = xDoc.SelectSingleNode("/ROWSET/ROW[TIPCONT=1][1]/LAST_INVOICE").InnerText; payFor = "Achitare MOLDTELECOM"; npp = xDoc.SelectSingleNode("/ROWSET/ROW[TIPCONT=1][1]/ACCOUNTNAME").InnerText; contract = xDoc.SelectSingleNode("/ROWSET/ROW[TIPCONT=1][1]/CONTRACT").InnerText; branch = xDoc.SelectSingleNode("/ROWSET/ROW[TIPCONT=1][1]/FILIALA").InnerText; tipCont = xDoc.SelectSingleNode("/ROWSET/ROW[TIPCONT=1][1]/TIPCONT").InnerText; } else if (maxdsl.Contains(int.Parse(organizationID))) { resp = clientService.getAccountInfo(user, password, searchParam, ownerKey, "2"); xDoc.LoadXml(resp); name = xDoc.FirstChild.Name; if (name == "error" || xDoc.SelectSingleNode("/ROWSET/ROW[TIPCONT=2][1]/TIPCONT") == null) { throw new ArgumentException("Error code: " + xDoc.SelectSingleNode("/error/code").InnerText + " Message: " + xDoc.SelectSingleNode("/error/message").InnerText); } amount = xDoc.SelectSingleNode("/ROWSET/ROW[TIPCONT=2][1]/ACHITARERECOMANDAT").InnerText; payFor = "Achitare MaxDSL"; npp = xDoc.SelectSingleNode("/ROWSET/ROW[TIPCONT=2][1]/ACCOUNTNAME").InnerText; contract = xDoc.SelectSingleNode("/ROWSET/ROW[TIPCONT=2][1]/CONTRACT").InnerText; branch = xDoc.SelectSingleNode("/ROWSET/ROW[TIPCONT=2][1]/FILIALA").InnerText; tipCont = xDoc.SelectSingleNode("/ROWSET/ROW[TIPCONT=2][1]/TIPCONT").InnerText; } else if (unite.Contains(int.Parse(organizationID))) { resp = clientService.getAccountInfo(user, password, searchParam, ownerKey, "3"); xDoc.LoadXml(resp); name = xDoc.FirstChild.Name; if (name == "error" || xDoc.SelectSingleNode("/ROWSET/ROW[TIPCONT=3][1]/TIPCONT") == null) { throw new ArgumentException("Error code: " + xDoc.SelectSingleNode("/error/code").InnerText + " Message: " + xDoc.SelectSingleNode("/error/message").InnerText); } amount = xDoc.SelectSingleNode("/ROWSET/ROW[TIPCONT=3][1]/LAST_INVOICE").InnerText; payFor = "Achitare Unite"; npp = xDoc.SelectSingleNode("/ROWSET/ROW[TIPCONT=3][1]/ACCOUNTNAME").InnerText; contract = xDoc.SelectSingleNode("/ROWSET/ROW[TIPCONT=3][1]/CONTRACT").InnerText; branch = xDoc.SelectSingleNode("/ROWSET/ROW[TIPCONT=3][1]/FILIALA").InnerText; tipCont = xDoc.SelectSingleNode("/ROWSET/ROW[TIPCONT=3][1]/TIPCONT").InnerText; } else if (unitePrePay.Contains(int.Parse(organizationID))) { resp = clientService.getAccountInfo(user, password, searchParam, ownerKey, "4"); xDoc.LoadXml(resp); name = xDoc.FirstChild.Name; if (name == "error" || xDoc.SelectSingleNode("/ROWSET/ROW[TIPCONT=4][1]/TIPCONT") == null) { throw new ArgumentException("Error code: " + xDoc.SelectSingleNode("/error/code").InnerText + " Message: " + xDoc.SelectSingleNode("/error/message").InnerText); } amount = xDoc.SelectSingleNode("/ROWSET/ROW[TIPCONT=4][1]/LAST_INVOICE").InnerText; payFor = "Achitare Unite PrePay"; npp = xDoc.SelectSingleNode("/ROWSET/ROW[TIPCONT=4][1]/ACCOUNTNAME").InnerText; contract = xDoc.SelectSingleNode("/ROWSET/ROW[TIPCONT=4][1]/CONTRACT").InnerText; branch = xDoc.SelectSingleNode("/ROWSET/ROW[TIPCONT=4][1]/FILIALA").InnerText; tipCont = xDoc.SelectSingleNode("/ROWSET/ROW[TIPCONT=4][1]/TIPCONT").InnerText; } if (amount == "0") { throw new Exception("Invoice cu suma 0."); } XmlDocument doc = new XmlDocument(); XmlElement root = doc.CreateElement("root"); doc.AppendChild(root); XmlElement newDataSet = doc.CreateElement("NewDataSet"); root.AppendChild(newDataSet); XmlElement invoiceTable = doc.CreateElement("InvoiceTable"); newDataSet.AppendChild(invoiceTable); XmlElement childNode = doc.CreateElement("ID"); childNode.InnerText = DateTime.Now.ToString("yyMMddHHmmssfff"); invoiceTable.AppendChild(childNode); childNode = doc.CreateElement("OrganizationID"); childNode.InnerText = organizationID; invoiceTable.AppendChild(childNode); childNode = doc.CreateElement("OrganizationName"); childNode.InnerText = "MOLDTELECOM"; invoiceTable.AppendChild(childNode); childNode = doc.CreateElement("ExpirationDate"); childNode.InnerText = DateTime.Now.AddDays(1).ToString("dd") + "/" + DateTime.Now.AddDays(1).ToString("MM") + "/" + DateTime.Now.AddDays(1).ToString("yyyy"); // 01/03/2008 invoiceTable.AppendChild(childNode); childNode = doc.CreateElement("Amount"); childNode.InnerText = amount; invoiceTable.AppendChild(childNode); childNode = doc.CreateElement("AmountCurrencyCode"); childNode.InnerText = "498"; invoiceTable.AppendChild(childNode); childNode = doc.CreateElement("ExecuteCurrencyCode"); childNode.InnerText = "498"; invoiceTable.AppendChild(childNode); childNode = doc.CreateElement("OwnerKey"); childNode.InnerText = ownerKey; invoiceTable.AppendChild(childNode); childNode = doc.CreateElement("AllowPartialPay"); childNode.InnerText = "true"; invoiceTable.AppendChild(childNode); childNode = doc.CreateElement("Destination"); childNode.InnerText = payFor; invoiceTable.AppendChild(childNode); childNode = doc.CreateElement("FieldName0"); childNode.InnerText = "NPP"; invoiceTable.AppendChild(childNode); childNode = doc.CreateElement("FieldValue0"); childNode.InnerText = npp; invoiceTable.AppendChild(childNode); childNode = doc.CreateElement("FieldName1"); childNode.InnerText = "Numar contract"; invoiceTable.AppendChild(childNode); childNode = doc.CreateElement("FieldValue1"); childNode.InnerText = contract; invoiceTable.AppendChild(childNode); childNode = doc.CreateElement("FieldName2"); childNode.InnerText = "Filiala"; invoiceTable.AppendChild(childNode); childNode = doc.CreateElement("FieldValue2"); childNode.InnerText = branch; invoiceTable.AppendChild(childNode); childNode = doc.CreateElement("FieldName3"); childNode.InnerText = "Serviciu"; invoiceTable.AppendChild(childNode); childNode = doc.CreateElement("FieldValue3"); childNode.InnerText = ConfigurationManager.AppSettings[tipCont]; invoiceTable.AppendChild(childNode); childNode = doc.CreateElement("ExpirationDate1"); childNode.InnerText = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss.fffffffzz:00"); invoiceTable.AppendChild(childNode); invoicesDataAsXml = root.InnerXml; messageDataAsXML = "</NewDataSet>"; return true; } catch (Exception e) { WriteToLog(e.Message); invoicesDataAsXml = "</NewDataSet>"; messageDataAsXML = Errxml(e.Message); return false; } }