Exemple #1
0
        public async Task <string> CreateBulkBills(IConfiguration configuration, RequestBulkControlNumbersModel model)
        {
            var billTrxRefs = new List <BillTrxInf>();
            var rand        = new Random();

            var sSQL = "uspPrepareBulkControlNumberRequests";

            SqlParameter[] parameters =
            {
                new SqlParameter("@Count",       model.ControlNumberCount),
                new SqlParameter("@ProductCode", model.ProductCode),
                new SqlParameter("@ErrorCode",   SqlDbType.Int)
                {
                    Direction = ParameterDirection.Output
                }
            };

            var dh = new DataHelper(configuration);

            DataTable dt = dh.GetDataTable(sSQL, parameters, CommandType.StoredProcedure);

            foreach (DataRow dr in dt.Rows)
            {
                var      billItems = new List <BillItem>();
                BillItem item      = new BillItem()
                {
                    BillItemRef     = model.ProductCode,
                    BillItemAmt     = Convert.ToDouble(dr["Amount"]),
                    BillItemEqvAmt  = Convert.ToDouble(dr["Amount"]),
                    BillItemMiscAmt = 0,
                    UseItemRefOnPay = "N",
                    GfsCode         = configuration["PaymentGateWay:GePG:GfsCode:0"]
                };
                billItems.Add(item);


                BillTrxInf billTrxInf = new BillTrxInf()
                {
                    BillId     = (int)dr["BillId"],
                    SubSpCode  = Convert.ToInt32(configuration["PaymentGateWay:GePG:SubSpCode"]),
                    SpSysId    = configuration["PaymentGateWay:GePG:SystemId"],
                    Ccy        = "TZS",
                    BillPayOpt = 3,
                    BillGenDt  = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss"),
                    BillEqvAmt = Convert.ToDecimal(dr["Amount"]),
                    RemFlag    = true,
                    BillExprDt = DateTime.Now.AddYears(3).ToString("yyyy-MM-ddTHH:mm:ss"),
                    BillAmt    = Convert.ToDecimal(dr["Amount"]),
                    MiscAmt    = 0,
                    BillItems  = billItems,
                    BillDesc   = "Bill",
                    BillApprBy = "Imis",
                    BillGenBy  = "Imis"
                };

                billTrxInf.PyrId      = dr["BillId"].ToString();
                billTrxInf.PyrName    = "CHF IMIS";
                billTrxInf.PyrEmail   = "*****@*****.**";
                billTrxInf.PyrCellNum = "";

                billTrxRefs.Add(billTrxInf);
            }

            string accountCode = GetAccountCodeByProductCode(model.ProductCode);

            newBill         = new gepgBillSubReq();
            newBill.BillHdr = new BillHdr()
            {
                SpCode = accountCode, RtrRespFlg = true
            };
            newBill.BillTrxInf = billTrxRefs;

            var xs = new XmlSerializer(typeof(gepgBillSubReq));
            var ns = new XmlSerializerNamespaces();

            ns.Add("", "");
            var settings = new XmlWriterSettings()
            {
                OmitXmlDeclaration = true
            };
            var sb = new StringBuilder();

            using (var xw = XmlWriter.Create(sb, settings))
            {
                try
                {
                    xs.Serialize(xw, newBill, ns);
                    xw.Flush();
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "Exception during XML serialization");
                }

                return(sb.ToString());
            }
        }
Exemple #2
0
        public String CreateBill(IConfiguration Configuration, string OfficerCode, string PhoneNumber, int BillId, decimal ExpectedAmount, List <PaymentDetail> policies)
        {
            DataHelper dh = new DataHelper(Configuration);

            List <BillItem> items = new List <BillItem>();

            if (policies.Count > 0)
            {
                foreach (var policy in policies)
                {
                    BillItem item = new BillItem()
                    {
                        BillItemRef     = policy.payment_detail_id.ToString(),
                        BillItemAmt     = Convert.ToDouble(policy.amount),
                        BillItemEqvAmt  = Convert.ToDouble(policy.amount),
                        BillItemMiscAmt = 0,
                        UseItemRefOnPay = "N",
                        GfsCode         = Configuration["PaymentGateWay:GePG:GfsCode:0"]
                    };
                    items.Add(item);
                }
            }
            else
            {
                return("-2: error - no policy");
            }

            BillTrxInf billTrxInf = new BillTrxInf()
            {
                BillId     = BillId,
                SubSpCode  = Convert.ToInt32(Configuration["PaymentGateWay:GePG:SubSpCode"]),
                SpSysId    = Configuration["PaymentGateWay:GePG:SystemId"],
                Ccy        = "TZS",
                BillPayOpt = 3,
                BillGenDt  = DateTime.Now.ToString("yyyy-MM-ddTHH:mm:ss"),
                BillEqvAmt = Convert.ToDecimal(ExpectedAmount),
                RemFlag    = true,
                BillExprDt = DateTime.Now.AddMonths(1).ToString("yyyy-MM-ddTHH:mm:ss"),
                BillAmt    = Convert.ToDecimal(ExpectedAmount),
                MiscAmt    = 0,
                BillItems  = items,
                BillDesc   = "Bill",
                BillApprBy = "Imis",
                BillGenBy  = "Imis"
            };

            if (OfficerCode == null)
            {
                var InsureeNumber = policies.FirstOrDefault().insurance_number;

                var sSQL = @"SELECT CHFID,LastName,OtherNames,Phone,Email
                             FROM tblInsuree WHERE CHFID = @InsureeNumber";

                SqlParameter[] parameters =
                {
                    new SqlParameter("@InsureeNumber", InsureeNumber),
                };

                var       data = new DataHelper(Configuration);
                DataTable dt   = data.GetDataTable(sSQL, parameters, CommandType.Text);

                billTrxInf.PyrId = InsureeNumber;
                if (dt.Rows.Count > 0)
                {
                    var row = dt.Rows[0];
                    billTrxInf.PyrName    = Convert.ToString(row["LastName"]) + " " + Convert.ToString(row["OtherNames"]);
                    billTrxInf.PyrEmail   = "*****@*****.**";
                    billTrxInf.PyrCellNum = Convert.ToString(row["Phone"]).Length == 0 ? PhoneNumber : Convert.ToString(row["Phone"]);
                }
                else
                {
                    billTrxInf.PyrName    = InsureeNumber;
                    billTrxInf.PyrEmail   = "*****@*****.**"; // TODO: replace with insuree's email if exists
                    billTrxInf.PyrCellNum = PhoneNumber;
                }
            }
            else
            {
                var            sSQL       = @"SELECT Code,LastName,OtherNames,DOB,Phone,EmailId
                            FROM tblOfficer WHERE ValidityTo IS NULL AND Code = @OfficerCode";
                SqlParameter[] parameters =
                {
                    new SqlParameter("@OfficerCode", OfficerCode),
                };

                var       data = new DataHelper(Configuration);
                DataTable dt   = data.GetDataTable(sSQL, parameters, CommandType.Text);

                if (dt.Rows.Count > 0)
                {
                    var row = dt.Rows[0];

                    billTrxInf.PyrId      = OfficerCode;
                    billTrxInf.PyrName    = Convert.ToString(row["LastName"]) + " " + Convert.ToString(row["OtherNames"]);
                    billTrxInf.PyrEmail   = "*****@*****.**"; // TODO: replace with officer's email
                    billTrxInf.PyrCellNum = Convert.ToString(row["Phone"]).Length == 0 ? PhoneNumber : Convert.ToString(row["Phone"]);
                }
            }

            string accountCode = GetAccountCodeByProductCode(policies.FirstOrDefault().insurance_product_code);

            var billTrxInfs = new List <BillTrxInf> {
                billTrxInf
            };


            newBill = new gepgBillSubReq()
            {
                BillHdr = new BillHdr()
                {
                    SpCode = accountCode, RtrRespFlg = true
                },
                BillTrxInf = billTrxInfs
            };

            var settings = new XmlWriterSettings()
            {
                OmitXmlDeclaration = true
            };
            var ns = new XmlSerializerNamespaces();

            ns.Add("", "");
            var sb = new StringBuilder();
            var xs = new XmlSerializer(typeof(gepgBillSubReq));

            using (var xw = XmlWriter.Create(sb, settings))
            {
                try
                {
                    xs.Serialize(xw, newBill, ns);
                    xw.Flush();
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, "Exception during XML serialization");
                }
                return(sb.ToString());
            }
        }