Server IP : 103.6.199.200 / Your IP : 18.119.137.175 Web Server : Microsoft-IIS/10.0 System : Windows NT EMPUSA 10.0 build 20348 (Windows Server 2016) i586 User : EMPUSA$ ( 0) PHP Version : 7.4.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : OFF | Perl : OFF | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : C:/Domains/kmsjbcom/kmsjb.com/wwwroot/ |
Upload File : |
<%@ WebHandler Language="C#" Class="ChequePrintingHandler" %> using System; using System.Xml; using System.Web; using System.Data; using System.Collections.Generic; using YL; using YL.KIS; using YL.KIS.DA; public class ChequePrintingHandler : IHttpHandler { public void ProcessRequest(HttpContext context) { bool handled = false; try { if (!string.IsNullOrEmpty(context.Request.QueryString["usr"]) && !string.IsNullOrEmpty(context.Request.QueryString["pwd"]) && !string.IsNullOrEmpty(context.Request.QueryString["app"])) { string usr = context.Request.QueryString["usr"]; // USER NAME string pwd = context.Request.QueryString["pwd"]; // PASSWORD string app = context.Request.QueryString["app"]; // APPLICATION TYPE string arg = context.Request.QueryString["arg"]; // ARGUMENT UserLogin l_UserLogin = Core.Service.UserLogin.Authenticate(usr, pwd); if (l_UserLogin != null) { if (app == "1") { XmlDocument l_XmlDocument = GetSessionXml(l_UserLogin); // <<== ***** context.Response.ContentType = "text/xml"; context.Response.Write(l_XmlDocument.OuterXml); handled = true; } else if (app == "2") { if (string.IsNullOrEmpty(arg)) throw new ApplicationException( "Payment Listing 'GCODE' not found."); XmlDocument l_XmlDocument = GetPaymentDetailXml(arg); // <<== ***** context.Response.ContentType = "text/xml"; context.Response.Write(l_XmlDocument.OuterXml); handled = true; } else if (app == "3") { if (string.IsNullOrEmpty(arg)) throw new ApplicationException( "Payment Listing 'GCODE' not found."); XmlDocument l_XmlDocument = GetPaymentItemDetailXml(arg); // <<== ***** context.Response.ContentType = "text/xml"; context.Response.Write(l_XmlDocument.OuterXml); handled = true; } else if (app == "4") { XmlDocument l_XmlDocument = GetCompanyDetailXml(l_UserLogin); // <<== ***** context.Response.ContentType = "text/xml"; context.Response.Write(l_XmlDocument.OuterXml); handled = true; } } else { XmlDocument l_XmlDocument = GetLoginFailXml(); context.Response.ContentType = "text/xml"; context.Response.Write(l_XmlDocument.OuterXml); handled = true; } } } catch (Exception ex) { XmlDocument l_XmlDocument = GetExceptionXml(ex); context.Response.ContentType = "text/xml"; context.Response.Write(l_XmlDocument.OuterXml); handled = true; } if (!handled) { XmlDocument l_XmlDocument = GetExceptionXml(new Exception("Invalid")); context.Response.ContentType = "text/xml"; context.Response.Write(l_XmlDocument.OuterXml); } } private XmlDocument GetPaymentItemDetailXml(string p_GCODE) { DataTable chequeUsage = Core.Service.ChequeUsage.GetByPaymentListingGCode( new Guid(p_GCODE)); DataTable voucherNo = Core.Service.PaymentItemVoucher.GetByPaymentListingGCode( new Guid(p_GCODE)); DataTable voucher = Core.Service.PaymentVoucher.GetByPaymentListingGCode( new Guid(p_GCODE)); DataTable table = Core.Service.PaymentItem.Select( new Guid(p_GCODE), "ITEM_NO"); // Extra Column table.Columns.Add("CHEQUE_NO", typeof(string)); table.Columns.Add("VOUCHER_NO", typeof(string)); table.Columns.Add("VOUCHER_TYPE", typeof(string)); table.Columns.Add("C_PRINTABLE", typeof(string)); table.Columns.Add("V_PRINTABLE", typeof(string)); XmlDocument l_XmlDocument = new XmlDocument(); XmlElement l_Header_Ele = AddHeaderXml(l_XmlDocument, "0", string.Empty); for (int i = 0; i < table.Rows.Count; i++) { DataRow row = table.Rows[i]; string l_ITEM_NO = row["ITEM_NO"].ToString(); string l_ITEM_CODE = row["ITEM_CODE"].ToString(); string l_DESCRIPTION = row["DESCRIPTION"].ToString(); string l_BENEFICIARY = row["BENEFICIARY"].ToString(); string l_PAYMENT_AMOUNT = row["PAYMENT_AMOUNT"].ToString(); string l_CHEQUE_PAYEE = row["CHEQUE_PAYEE"].ToString(); string l_CHEQUE_DATE = Convert.ToDateTime(row["CHEQUE_DATE"]).ToString("ddMMyyyy"); string l_VOUCHER_PAYEE = row["VOUCHER_PAYEE"].ToString(); string l_VOUCHER_DATE = Convert.ToDateTime(row["VOUCHER_DATE"]).ToString("ddMMyyyy"); ////////////////////////////////////////////// string l_C_PRINTABLE = string.Empty; string l_V_PRINTABLE = string.Empty; decimal l_PAYMENT_AMOUNT_DEC = 0; decimal.TryParse(l_PAYMENT_AMOUNT, out l_PAYMENT_AMOUNT_DEC); l_C_PRINTABLE = l_PAYMENT_AMOUNT_DEC > 0 ? "1" : "0"; //l_V_PRINTABLE = l_PAYMENT_AMOUNT_DEC > 0 ? "1" : "0"; l_V_PRINTABLE = "1"; ////////////////////////////////////////////// string l_VOUCHER_NO = string.Empty; DataRow[] l_VoucherNoRows = voucherNo.Select(string.Format( "GCODE='{0}'", row["GCODE"].ToString())); if (l_VoucherNoRows.Length > 0) { int voucherNO = Convert.ToInt32(l_VoucherNoRows[0]["VOUCHER_NO"]); DateTime voucherDate = Convert.ToDateTime(l_VoucherNoRows[0]["VOUCHER_DATE"]); l_VOUCHER_NO = string.Format("PV{0}/{1}/{2}", voucherDate.ToString("yy"), voucherDate.ToString("MM"), voucherNO.ToString() ); } ////////////////////////////////////////////// string l_CHEQUE_NO = string.Empty; string l_VOUCHER_TYPE = string.Empty; DataRow[] l_ChequeRows = chequeUsage.Select(string.Format( "PAYMENT_LISTING_ITEM_NO={0}", l_ITEM_NO)); if (l_ChequeRows.Length > 0) { l_CHEQUE_NO = Convert.ToInt32(l_ChequeRows[0]["CHEQUE_NO"].ToString()).ToString("000000"); l_VOUCHER_TYPE = "1"; } else if (Convert.ToBoolean(row["IS_DD"])) { //l_CHEQUE_NO = "CASH"; l_CHEQUE_NO = "Dr. Adv."; //l_VOUCHER_TYPE = "2"; l_VOUCHER_TYPE = "0"; } else { l_CHEQUE_NO = ""; l_VOUCHER_TYPE = "0"; } ////////////////////////////////////////////// XmlElement l_ITM_Ele = l_XmlDocument.CreateElement("ITM"); l_ITM_Ele.SetAttribute("ITEM_NO", l_ITEM_NO); l_ITM_Ele.SetAttribute("ITEM_CODE", l_ITEM_CODE); l_ITM_Ele.SetAttribute("CHEQUE_NO", l_CHEQUE_NO); l_ITM_Ele.SetAttribute("VOUCHER_NO", l_VOUCHER_NO); l_ITM_Ele.SetAttribute("DESCRIPTION", l_DESCRIPTION); l_ITM_Ele.SetAttribute("BENEFICIARY", l_BENEFICIARY); l_ITM_Ele.SetAttribute("PAYMENT_AMOUNT", l_PAYMENT_AMOUNT); l_ITM_Ele.SetAttribute("CHEQUE_PAYEE", l_CHEQUE_PAYEE); l_ITM_Ele.SetAttribute("CHEQUE_DATE", l_CHEQUE_DATE); l_ITM_Ele.SetAttribute("VOUCHER_PAYEE", l_VOUCHER_PAYEE); l_ITM_Ele.SetAttribute("VOUCHER_DATE", l_VOUCHER_DATE); l_ITM_Ele.SetAttribute("VOUCHER_TYPE", l_VOUCHER_TYPE); l_ITM_Ele.SetAttribute("C_PRINTABLE", l_C_PRINTABLE); l_ITM_Ele.SetAttribute("V_PRINTABLE", l_V_PRINTABLE); l_Header_Ele.AppendChild(l_ITM_Ele); ////////////////////////////////////////////// DataRow[] l_VoucherRows = voucher.Select( string.Format("PAYMENT_ITEM_GCODE='{0}'", row["GCODE"].ToString())); for (int j = 0; j < l_VoucherRows.Length; j++) { DataRow rowVC = l_VoucherRows[j]; string l_AC_CODE = rowVC["AC_CODE"].ToString(); string l_PARTICULARS = rowVC["PARTICULARS"].ToString(); string l_AMOUNT = rowVC["AMOUNT"].ToString(); string l_TYPE_ID = rowVC["ITEM_TYPE_ID"].ToString(); string l_COL_1 = rowVC["COL_1"].ToString(); string l_COL_2 = rowVC["COL_2"].ToString(); XmlElement l_VC_Ele = l_XmlDocument.CreateElement("VC"); l_VC_Ele.SetAttribute("AC_CODE", l_AC_CODE); l_VC_Ele.SetAttribute("COL_1", l_COL_1); l_VC_Ele.SetAttribute("COL_2", l_COL_2); l_VC_Ele.SetAttribute("PARTICULARS", l_PARTICULARS); l_VC_Ele.SetAttribute("AMOUNT", l_AMOUNT); l_VC_Ele.SetAttribute("ITEM_TYPE_ID", l_TYPE_ID); l_ITM_Ele.AppendChild(l_VC_Ele); } } return l_XmlDocument; } private XmlDocument GetPaymentDetailXml(string p_GCODE) { DataTable table = Core.CoreDbAccess.ExecuteSelectEx(string.Format( "SELECT PAYMENT_ITEM.DESCRIPTION, PAYMENT_ITEM.BENEFICIARY, " + "PAYMENT_ITEM.PAYMENT_AMOUNT, PAYMENT_ITEM.CHEQUE_PAYEE, " + "PAYMENT_ITEM.CHEQUE_DATE, BANK_CHEQUE.CHEQUE_NO, " + "PAYMENT_ITEM.VOUCHER_PAYEE , PAYMENT_ITEM.VOUCHER_DATE " + "FROM PAYMENT_ITEM, BANK_CHEQUE_USAGE, BANK_CHEQUE " + "WHERE BANK_CHEQUE_USAGE.BANK_CHEQUE_GCODE=BANK_CHEQUE.GCODE " + "AND PAYMENT_ITEM.PAYMENT_LISTING_GCODE=BANK_CHEQUE_USAGE.PAYMENT_LISTING_GCODE " + "AND PAYMENT_ITEM.ITEM_NO = BANK_CHEQUE_USAGE.PAYMENT_LISTING_ITEM_NO " + "AND PAYMENT_ITEM.ITEM_CODE NOT IN ('CCL','KIV') " + "AND BANK_CHEQUE_USAGE.PAYMENT_LISTING_GCODE='{0}' " + "ORDER BY BANK_CHEQUE.CHEQUE_NO;", p_GCODE)); XmlDocument l_XmlDocument = new XmlDocument(); XmlElement l_Header_Ele = AddHeaderXml(l_XmlDocument, "0", string.Empty); for (int i = 0; i < table.Rows.Count; i++) { DataRow row = table.Rows[i]; string l_CHEQUE_NO = row["CHEQUE_NO"].ToString(); string l_DESCRIPTION = row["DESCRIPTION"].ToString(); string l_BENEFICIARY = row["BENEFICIARY"].ToString(); string l_PAYMENT_AMOUNT = row["PAYMENT_AMOUNT"].ToString(); string l_CHEQUE_PAYEE = row["CHEQUE_PAYEE"].ToString(); string l_CHEQUE_DATE = Convert.ToDateTime(row["CHEQUE_DATE"]).ToString("ddMMyyyy"); string l_VOUCHER_PAYEE = row["VOUCHER_PAYEE"].ToString(); string l_VOUCHER_DATE = Convert.ToDateTime(row["VOUCHER_DATE"]).ToString("ddMMyyyy"); XmlElement l_ITM_Ele = l_XmlDocument.CreateElement("ITM"); l_ITM_Ele.SetAttribute("CHEQUE_NO", l_CHEQUE_NO); l_ITM_Ele.SetAttribute("DESCRIPTION", l_DESCRIPTION); l_ITM_Ele.SetAttribute("BENEFICIARY", l_BENEFICIARY); l_ITM_Ele.SetAttribute("PAYMENT_AMOUNT", l_PAYMENT_AMOUNT); l_ITM_Ele.SetAttribute("CHEQUE_PAYEE", l_CHEQUE_PAYEE); l_ITM_Ele.SetAttribute("CHEQUE_DATE", l_CHEQUE_DATE); l_ITM_Ele.SetAttribute("VOUCHER_PAYEE", l_VOUCHER_PAYEE); l_ITM_Ele.SetAttribute("VOUCHER_DATE", l_VOUCHER_DATE); l_Header_Ele.AppendChild(l_ITM_Ele); } return l_XmlDocument; } private XmlDocument GetCompanyDetailXml(UserLogin userLogin) { XmlDocument l_XmlDocument = new XmlDocument(); XmlElement l_Header_Ele = AddHeaderXml(l_XmlDocument, "0", string.Empty); DataTable table = Core.CoreDbAccess.ExecuteSelectEx(string.Format( "SELECT COMPANY.* " + "FROM COMPANY " + "WHERE ('{1}' = '{2}') " + "OR (COMPANY.GCODE IN (SELECT user_login_company.COMPANY_GCODE " + "FROM user_login_company WHERE user_login_company.USER_NAME = '{0}')) " + "ORDER BY COMPANY.COMPANY_NAME;", userLogin.User_Name, userLogin.Role_ID.ToString(), UserRole.ADMIN.Role_ID.ToString() )); Dictionary<string, XmlNode> l_Dic_Company = new Dictionary<string, XmlNode>(); for (int i = 0; i < table.Rows.Count; i++) { DataRow row = table.Rows[i]; string l_COMPANY_FULL_NAME = row["COMPANY_FULL_NAME"].ToString(); string l_COMPANY_NAME = row["COMPANY_NAME"].ToString(); string l_COMPANY_GCODE = row["GCODE"].ToString(); string l_ADDRESS_LINE_1 = row["ADDRESS_LINE_1"].ToString(); string l_ADDRESS_LINE_2 = row["ADDRESS_LINE_2"].ToString(); string l_PHONE = row["PHONE"].ToString(); string l_FAX = row["FAX"].ToString(); string l_LOGO_B64 = row["LOGO_B64"].ToString(); string l_COMPANY_REG_NO = row["COMPANY_REG_NO"].ToString(); string l_CURRENCY_CODE = row["CURRENCY_CODE"].ToString(); if (!l_Dic_Company.ContainsKey(l_COMPANY_GCODE)) { XmlElement l_CO_Ele = l_XmlDocument.CreateElement("CO"); l_CO_Ele.SetAttribute("COMPANY_GCODE", l_COMPANY_GCODE); l_CO_Ele.SetAttribute("COMPANY_REG_NO", l_COMPANY_REG_NO); l_CO_Ele.SetAttribute("COMPANY_NAME", l_COMPANY_NAME); l_CO_Ele.SetAttribute("COMPANY_FULL_NAME", l_COMPANY_FULL_NAME); l_CO_Ele.SetAttribute("ADDRESS_LINE_1", HttpUtility.HtmlEncode(l_ADDRESS_LINE_1)); l_CO_Ele.SetAttribute("ADDRESS_LINE_2", HttpUtility.HtmlEncode(l_ADDRESS_LINE_2)); l_CO_Ele.SetAttribute("PHONE", HttpUtility.HtmlEncode(l_PHONE)); l_CO_Ele.SetAttribute("FAX", HttpUtility.HtmlEncode(l_FAX)); l_CO_Ele.SetAttribute("LOGO_B64", l_LOGO_B64); l_CO_Ele.SetAttribute("CURRENCY_CODE", l_CURRENCY_CODE); l_Dic_Company.Add(l_COMPANY_GCODE, l_CO_Ele); l_Header_Ele.AppendChild(l_CO_Ele); } } return l_XmlDocument; } private XmlDocument GetSessionXml(UserLogin userLogin) { DataTable table = Core.CoreDbAccess.ExecuteSelectEx(string.Format( "SELECT PAYMENT_LISTING.*, BANK.BANK_NAME, BANK.BANK_CODE, " + "COMPANY.COMPANY_NAME, COMPANY.COMPANY_FULL_NAME, COMPANY.COMPANY_REG_NO, " + "COMPANY.ADDRESS_LINE_1, COMPANY.ADDRESS_LINE_2, " + "COMPANY.PHONE, COMPANY.FAX, COMPANY.LOGO_B64, COMPANY.CURRENCY_CODE " + "FROM PAYMENT_LISTING, COMPANY, BANK " + "WHERE PAYMENT_LISTING.COMPANY_GCODE=COMPANY.GCODE " + "AND PAYMENT_LISTING.BANK_GCODE=BANK.GCODE " + "AND PAYMENT_LISTING.STATUS_CODE IN ('{0}', '{1}') " + "AND (('{3}' = '{4}') " + "OR (COMPANY.GCODE IN (SELECT user_login_company.COMPANY_GCODE " + "FROM user_login_company WHERE user_login_company.USER_NAME = '{2}'))) " + "ORDER BY COMPANY.COMPANY_NAME, " + "BANK.BANK_NAME, " + "PAYMENT_LISTING.PAGE_NO;", PaymentListingCode.CODE_PENDING, PaymentListingCode.CODE_PREPARED, userLogin.User_Name, userLogin.Role_ID.ToString(), UserRole.ADMIN.Role_ID.ToString() )); XmlDocument l_XmlDocument = new XmlDocument(); XmlElement l_Header_Ele = AddHeaderXml(l_XmlDocument, "0", string.Empty); Dictionary<string, XmlNode> l_Dic_Company = new Dictionary<string, XmlNode>(); Dictionary<string, XmlNode> l_Dic_Bank = new Dictionary<string, XmlNode>(); for (int i = 0; i < table.Rows.Count; i++) { DataRow row = table.Rows[i]; string l_COMPANY_REG_NO = row["COMPANY_REG_NO"].ToString(); string l_COMPANY_FULL_NAME = row["COMPANY_FULL_NAME"].ToString(); string l_COMPANY_NAME = row["COMPANY_NAME"].ToString(); string l_COMPANY_GCODE = row["COMPANY_GCODE"].ToString(); string l_ADDRESS_LINE_1 = row["ADDRESS_LINE_1"].ToString(); string l_ADDRESS_LINE_2 = row["ADDRESS_LINE_2"].ToString(); string l_PHONE = row["PHONE"].ToString(); string l_FAX = row["FAX"].ToString(); string l_LOGO_B64 = row["LOGO_B64"].ToString(); string l_BANK_GCODE = row["BANK_GCODE"].ToString(); string l_GCODE = row["GCODE"].ToString(); string l_BANK_NAME = row["BANK_NAME"].ToString(); string l_BANK_CODE = row["BANK_CODE"].ToString(); string l_PAGE_CODE = row["PAGE_CODE"].ToString(); decimal l_TOTAL_PAYMENT = Convert.ToDecimal(row["TOTAL_PAYMENT"]); DateTime l_EFFECTIVE_DATE = Convert.ToDateTime(row["EFFECTIVE_DATE"]); string l_CURRENCY_CODE = row["CURRENCY_CODE"].ToString(); if (!l_Dic_Company.ContainsKey(l_COMPANY_GCODE)) { XmlElement l_CO_Ele = l_XmlDocument.CreateElement("CO"); l_CO_Ele.SetAttribute("COMPANY_GCODE", l_COMPANY_GCODE); l_CO_Ele.SetAttribute("COMPANY_REG_NO", l_COMPANY_REG_NO); l_CO_Ele.SetAttribute("COMPANY_NAME", l_COMPANY_NAME); l_CO_Ele.SetAttribute("COMPANY_FULL_NAME", l_COMPANY_FULL_NAME); l_CO_Ele.SetAttribute("ADDRESS_LINE_1", HttpUtility.HtmlEncode(l_ADDRESS_LINE_1)); l_CO_Ele.SetAttribute("ADDRESS_LINE_2", HttpUtility.HtmlEncode(l_ADDRESS_LINE_2)); l_CO_Ele.SetAttribute("PHONE", HttpUtility.HtmlEncode(l_PHONE)); l_CO_Ele.SetAttribute("FAX", HttpUtility.HtmlEncode(l_FAX)); l_CO_Ele.SetAttribute("LOGO_B64", l_LOGO_B64); l_CO_Ele.SetAttribute("CURRENCY_CODE", l_CURRENCY_CODE); l_Dic_Company.Add(l_COMPANY_GCODE, l_CO_Ele); l_Header_Ele.AppendChild(l_CO_Ele); } if (!l_Dic_Bank.ContainsKey(l_BANK_GCODE)) { XmlElement l_BK_Ele = l_XmlDocument.CreateElement("BK"); l_BK_Ele.SetAttribute("BANK_GCODE", l_BANK_GCODE); l_BK_Ele.SetAttribute("BANK_NAME", l_BANK_NAME); l_BK_Ele.SetAttribute("BANK_CODE", l_BANK_CODE); l_Dic_Bank.Add(l_BANK_GCODE, l_BK_Ele); l_Dic_Company[l_COMPANY_GCODE].AppendChild(l_BK_Ele); } XmlElement l_PL_Ele = l_XmlDocument.CreateElement("PL"); l_PL_Ele.SetAttribute("GCODE", l_GCODE); l_PL_Ele.SetAttribute("PAGE_CODE", l_PAGE_CODE); l_PL_Ele.SetAttribute("TOTAL_PAYMENT", l_TOTAL_PAYMENT.ToString()); l_PL_Ele.SetAttribute("EFFECTIVE_DATE", l_EFFECTIVE_DATE.ToString("yyyyMMdd")); l_Dic_Bank[l_BANK_GCODE].AppendChild(l_PL_Ele); } return l_XmlDocument; } private XmlDocument GetExceptionXml(Exception ex) { XmlDocument l_XmlDocument = new XmlDocument(); XmlElement l_Header_Ele = AddHeaderXml(l_XmlDocument, "1", "Unexpected server error. " + ex.Message); return l_XmlDocument; } private XmlDocument GetLoginFailXml() { XmlDocument l_XmlDocument = new XmlDocument(); XmlElement l_Header_Ele = AddHeaderXml(l_XmlDocument, "1", "Login failed. Please check your user name and password."); return l_XmlDocument; } private XmlElement AddHeaderXml(XmlDocument p_XmlDocument, string p_Status, string p_Message) { XmlElement l_Header_Ele = p_XmlDocument.CreateElement("MODEL"); l_Header_Ele.SetAttribute("STATUS", p_Status); l_Header_Ele.SetAttribute("MESSAGE", p_Message); p_XmlDocument.AppendChild(l_Header_Ele); return l_Header_Ele; } public bool IsReusable { get { return false; } } }