Esempio n. 1
0
        /// <summary>
        /// 作用:添加和编辑Bill_Record
        /// 作者:汪建龙
        /// 编写时间:2017年1月10日17:02:30
        /// </summary>
        /// <param name="record"></param>
        /// <returns></returns>
        public int Add(BillRecord record)
        {
            using (var db = GetDbContext())
            {
                var entry = db.Bill_Records.FirstOrDefault(e => e.SerialNumber == record.SerialNumber && e.HID == record.HID);
                if (entry != null)
                {
                    record.ID = entry.ID;
                    if (record.Budget == entry.Budget)//假如当前记录是收入或者支出统一时,一级类和二级类不做修改
                    {
                        record.Cost = entry.Cost;
                        record.RID  = entry.RID;
                    }
                    record.Sync = entry.Sync;
                    db.Entry(entry).CurrentValues.SetValues(record);
                }
                else
                {
                    db.Bill_Records.Add(record);
                }

                db.SaveChanges();
                return(record.ID);
            }
        }
Esempio n. 2
0
 public void Initialize()
 {
     _meal       = new Meal();
     _billRecord = new BillRecord(_meal, 0);
     //_meal = new Meal("",new Category(),0,"","");
     _target         = new PrivateObject(_billRecord);
     _propertyString = DEFAULT;
 }
Esempio n. 3
0
        /// <summary>
        /// 作用:
        /// 作者:汪建龙
        /// 编写时间:2016年11月16日15:46:10
        /// </summary>
        /// <param name="hid">账单头文件ID</param>
        /// <param name="list">追加的列表</param>
        /// <returns></returns>
        public List <string> Input(int hid, List <BillOne> list, int year, int month, Company company)
        {
            var     errors          = new List <string>();
            var     preSerialNumber = 1;
            BillOne preEntry        = null;

            foreach (var item in list)
            {
                var error = string.Empty;
                if (preEntry != null)
                {
                    if (!BillClass.CheckLogic(item, preEntry))
                    {
                        error = "序号前后不一致,应递增,账户余额收支前后不一致;";
                    }
                    if (!BillClass.CheckTime(item, year, month))
                    {
                        error += string.Format("交易日期不在{0}年{1}月,请核对!", year, month);
                    }
                }
                else
                {
                    if (item.SerialNumber == 1)
                    {
                        BillRecord last = null;
                        if (month == 1)
                        {
                            last = Core.Bill_RecordManager.GetLast(year - 1, 12, company);
                        }
                        else
                        {
                            last = Core.Bill_RecordManager.GetLast(year, month - 1, company);
                        }
                        if (last != null)
                        {
                            if (!BillClass.CheckLogic(last, item))
                            {
                                error += string.Format("当前月初第一笔收支与上个月不符,请核对!");
                            }
                        }
                    }
                }
                if (!string.IsNullOrEmpty(error))
                {
                    errors.Add(string.Format("第{0}个数据存在如下错误:{1}", preSerialNumber, error));
                    continue;
                }
                item.HID = hid;
                if (Add(item) == 0)
                {
                    errors.Add(string.Format("第{0}个数据:保存到数据库失败;", preSerialNumber));
                }
                preEntry = item;
                preSerialNumber++;
            }
            return(errors);
        }
Esempio n. 4
0
 public Bill(BillRecord record)
 {
     this.Id             = record.Id;
     this.Name           = record.Name;
     this.OriginalAmount = record.Amount;
     this.OverdueDays    = CalculateOverdueDays(record);
     this.PaymentDate    = record.PaymentDate;
     this.DueDate        = record.DueDate;
 }
Esempio n. 5
0
        private void dgBills_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            // Je potřeba na základě DB dočasně vytvořit XML účtenku
            CreateXmlBillFromDatabaseSource(((BillRecord)dgBills.SelectedItem).FileName);

            BillRecord record = (BillRecord)dgBills.SelectedItem;
            BillWindow billW  = new BillWindow(record.FileName + ".xml", true);

            billW.Owner = Window.GetWindow(this);
            billW.WindowStartupLocation = WindowStartupLocation.CenterOwner;
            billW.Show();
        }
Esempio n. 6
0
        public bool CreateBill(BillRecord bill)
        {
            try
            {
                bill.Id = Guid.NewGuid().ToString();
                _db.Add(bill);
                _db.SaveChanges();

                return(true);
            }
            catch (System.Exception)
            {
                return(false);
            }
        }
Esempio n. 7
0
        private int CalculateOverdueDays(BillRecord record)
        {
            var paymentDate = record.PaymentDate.HasValue
                ? record.PaymentDate.Value
                : DateTime.Now;

            var overdueDays = (int)paymentDate.Subtract(record.DueDate).TotalDays;

            if (overdueDays > 0)
            {
                return(overdueDays);
            }
            else
            {
                return(0);
            }
        }
Esempio n. 8
0
        public BillRecord GetBillInfo(string billNo, string billingNo, string serviceType)
        {
            using (OracleConnection connection = new OracleConnection())
            {
                OracleCommand command = new OracleCommand()
                {
                    CommandType = CommandType.StoredProcedure,
                    CommandText = "madfooat_utility.GET_AGREEMENT_INFO",
                    Connection  = new OracleConnection(connectionString),
                };
                command.Parameters.AddWithValue("P_CENTER_ID", "7").Direction       = ParameterDirection.Input;
                command.Parameters.AddWithValue("P_COLLECTOR", "ADMIN").Direction   = ParameterDirection.Input;
                command.Parameters.AddWithValue("P_AGREEMENT_ID", "1562").Direction = ParameterDirection.Input;
                command.Parameters.AddWithValue("P_BALANCE_TYPE", "3").Direction    = ParameterDirection.Input;



                command.Parameters.Add("P_NAME", OracleType.Char, 255).Direction    = ParameterDirection.Output;
                command.Parameters.Add("P_BALANCE", OracleType.Int32).Direction     = ParameterDirection.Output;
                command.Parameters.Add("P_RESULT", OracleType.Char, 1024).Direction = ParameterDirection.Output;

                command.Connection.Open();
                command.ExecuteNonQuery();
                BillRecord billRecord = null;
                decimal    dueAmount  = 0;
                dueAmount  = command.Parameters["P_BALANCE"].Value != DBNull.Value ? Convert.ToDecimal(command.Parameters["P_BALANCE"].Value) : 0;
                billRecord = new BillRecord()
                {
                    AccountInfo = new AccountInfo()
                    {
                        BillingNumber = billingNo,
                        BillNumber    = billNo,
                    },
                    BillStatus  = BillStatusCodes.BillNew,
                    DueAmount   = dueAmount,
                    IssueDate   = DateTime.Now,
                    DueDate     = DateTime.Now,
                    ServiceType = "Payment",
                };

                command.Connection.Close();
                return(billRecord);
            }
        }
Esempio n. 9
0
    public DataTable getBillListDt(int print_id)
    {
        SQL = "select *, '' as tran_id, ''as memo,'false' as is_checked, '' as bill_amt_clear, '' as invoices,'../enter_bill.aspx?view=yes&bill_number='+convert( NVARCHAR(10),bill_number) as url from bill where bill_amt_due <> 0 and elt_account_number = " + elt_account_number + " and print_id=" + print_id;
        DataTable      dt    = new DataTable();
        SqlDataAdapter ad    = new SqlDataAdapter(SQL, Con);
        BillRecord     bRec  = new BillRecord();
        GeneralUtility gUtil = new GeneralUtility();

        try
        {
            ad.Fill(dt);
            gUtil.removeNull(ref dt);
        }
        catch (Exception ex)
        {
            throw ex;
        }
        return(dt);
    }
Esempio n. 10
0
        /// <summary>
        /// ZASTARALÁ METODA: v nové implementaci se již plní daty z databáze, ne ze složky
        /// </summary>
        private void FillFromFolder()
        {
            List <BillRecord> bills = new List <BillRecord>();

            if (Directory.Exists(System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "PASS", "Bill")))
            {
                string        path    = (System.IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "PASS", "Bill"));
                DirectoryInfo dirInfo = new DirectoryInfo(path);
                FileInfo[]    files   = dirInfo.GetFiles("*.xml", SearchOption.AllDirectories);
                foreach (FileInfo s in files)
                {
                    BillRecord singleBill = new BillRecord()
                    {
                        FileName = s.Name, CreationTime = HelperClass.GetFullDatetime(s.CreationTime), Url = s.FullName
                    };
                    bills.Add(singleBill);
                }

                dgBills.ItemsSource = bills;
            }
        }
Esempio n. 11
0
        /// <summary>
        /// 记录资金结算记录
        /// </summary>
        /// <param name="record"></param>
        public void AddBillRecord(BillRecord record)
        {
            try
            {
                if (record == null)
                {
                    return;
                }

                MongoDBHelper <BillRecord> mongo = new MongoDBHelper <BillRecord>();
                mongo.Insert(CollectionNameDefine.BillRecord, record);
                if (record.BillRecordType == BillRecordType.结算点记录)
                {
                    //更新账单
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 12
0
    public BillRecord getBill(int bill_number)
    {
        SQL = "select * from bill where elt_account_number = " + elt_account_number + " and bill_number=" + bill_number;
        DataTable      dt    = new DataTable();
        SqlDataAdapter ad    = new SqlDataAdapter(SQL, Con);
        BillRecord     bRec  = new BillRecord();
        GeneralUtility gUtil = new GeneralUtility();

        ad.Fill(dt);
        if (dt.Rows.Count > 0)
        {
            try
            {
                gUtil.removeNull(ref dt);
                bRec.Lock              = dt.Rows[0]["lock"].ToString();
                bRec.Bill_amt          = Decimal.Parse(dt.Rows[0]["bill_amt"].ToString());
                bRec.Bill_amt_due      = Decimal.Parse(dt.Rows[0]["bill_amt_due"].ToString());
                bRec.Bill_amt_paid     = Decimal.Parse(dt.Rows[0]["bill_amt_paid"].ToString());
                bRec.Bill_ap           = Int32.Parse((dt.Rows[0]["bill_ap"].ToString()));
                bRec.Bill_date         = DateTime.Parse(dt.Rows[0]["bill_date"].ToString()).ToShortDateString();
                bRec.Bill_due_date     = DateTime.Parse(dt.Rows[0]["bill_due_date"].ToString()).ToShortDateString();
                bRec.Bill_expense_acct = Int32.Parse((dt.Rows[0]["bill_expense_acct"].ToString()));
                bRec.Bill_number       = Int32.Parse((dt.Rows[0]["bill_number"].ToString()));
                bRec.Bill_status       = dt.Rows[0]["bill_status"].ToString();
                bRec.Bill_type         = dt.Rows[0]["bill_type"].ToString();
                bRec.Is_org_merged     = dt.Rows[0]["is_org_merged"].ToString();
                bRec.Pmt_method        = dt.Rows[0]["pmt_method"].ToString();
                bRec.Print_id          = Int32.Parse((dt.Rows[0]["print_id"].ToString()));
                bRec.Ref_no            = dt.Rows[0]["ref_no"].ToString();
                bRec.Vendor_name       = dt.Rows[0]["vendor_name"].ToString();
                bRec.Vendor_number     = Int32.Parse((dt.Rows[0]["vendor_number"].ToString()));
                bRec.BillDetailList    = bdMgr.getBillDetailList(bill_number);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        return(bRec);
    }
Esempio n. 13
0
        /// <summary>
        /// 调价处理,如存在调价则处理
        /// </summary>
        private void TiaoJiaDowith(Meter meter, SubmitData dataItem)
        {
            //检查是否存在调价计划, 如存在并调价启动时间已到达,则将新的价格写入执行体系中(即修改价格对应的变量值),设置成功,删除调价计划数据.
            meter.PricingPlan = new PricingPlanDA().QueryPricingPlan(meter.Mac);
            if (meter.PricingPlan != null)
            {
                decimal[] prices = new decimal[5];
                decimal[] gas    = new decimal[5];
                prices[0] = meter.Price1;
                prices[1] = meter.Price2;
                prices[2] = meter.Price3;
                prices[3] = meter.Price4;
                prices[4] = meter.Price5;
                gas[0]    = meter.Gas1;
                gas[1]    = meter.Gas2;
                gas[2]    = meter.Gas3;
                gas[3]    = meter.Gas4;
                gas[4]    = -1;

                //存在调价计划
                DateTime pricingDate = Convert.ToDateTime(meter.PricingPlan.UseDate);
                if (getJianGe(dataItem.ReadDate, pricingDate) >= 0)
                {
                    //结算气量(原价格到调价时)
                    decimal jieSuanLJGas = dataItem.LJGas - meter.LastTotal;
                    //设置调价点(用于后续的阶梯量记账)
                    meter.TiaoJiaPointGas = dataItem.LJGas;
                    meter.IsPricing       = true;
                    //记录结算记录
                    BillRecord record = new BillRecord()
                    {
                        UserID = meter.UserID, MeterNo = meter.Mac
                    };
                    record.RecordDate     = dataItem.ReadDate.ToString("yyyy-MM-dd HH:mm:ss");
                    record.BillRecordType = BillRecordType.调价点记录;
                    record.BillID         = meter.BillID;
                    record.Ladder         = meter.CurrentLadder;
                    decimal lastPoint = meter.NextSettlementPointGas - gas[meter.CurrentLadder - 1];
                    if (meter.NextSettlementPointGas > 0)
                    {
                        //当前没有计价到最后一个阶梯
                        record.BeginPoint = lastPoint;
                        record.EndPoint   = dataItem.LJGas;
                        record.Gas        = record.EndPoint - record.BeginPoint;
                        record.Price      = meter.CurrentPrice;
                        record.Amount     = record.Gas * record.Price;
                        record.Ladder     = meter.CurrentLadder;
                    }
                    else
                    {
                        //当前已处于最后一个阶梯
                        record.BeginPoint = meter.LastTotal;
                        record.EndPoint   = dataItem.LJGas;
                        for (int i = 0; i < meter.Ladder; i++)
                        {
                            record.BeginPoint += gas[i];
                        }
                        record.Gas    = record.EndPoint - record.BeginPoint;
                        record.Price  = meter.CurrentPrice;
                        record.Amount = record.Gas * record.Price;
                        record.Ladder = meter.CurrentLadder;
                    }
                    new M_BillRecordService().AddBillRecord(record);//添加结算记录

                    //调价启用时间到
                    meter.IsUsedLadder = meter.PricingPlan.IsUsedLadder;
                    meter.Ladder       = meter.PricingPlan.Ladder;
                    meter.Price1       = meter.PricingPlan.Price1;
                    meter.Gas1         = meter.PricingPlan.Gas1;
                    meter.Price2       = meter.PricingPlan.Price2;
                    meter.Gas2         = meter.PricingPlan.Gas2;
                    meter.Price3       = meter.PricingPlan.Price3;
                    meter.Gas3         = meter.PricingPlan.Gas3;
                    meter.Price4       = meter.PricingPlan.Price4;
                    meter.Gas4         = meter.PricingPlan.Gas4;
                    meter.Price5       = meter.PricingPlan.Price5;
                    prices[0]          = meter.Price1;
                    prices[1]          = meter.Price2;
                    prices[2]          = meter.Price3;
                    prices[3]          = meter.Price4;
                    prices[4]          = meter.Price5;
                    gas[0]             = meter.Gas1;
                    gas[1]             = meter.Gas2;
                    gas[2]             = meter.Gas3;
                    gas[3]             = meter.Gas4;
                    gas[4]             = -1;

                    //结算周期
                    meter.SettlementType = meter.PricingPlan.SettlementType;

                    //设置当前计费价格
                    if (meter.IsUsedLadder)
                    {
                        meter.NextSettlementPointGas = meter.LastTotal;

                        for (int i = 0; i < meter.Ladder; i++)
                        {
                            meter.NextSettlementPointGas += gas[i];
                            meter.CurrentPrice            = prices[i];
                            meter.CurrentLadder           = i + 1;
                            if (meter.NextSettlementPointGas > dataItem.LJGas)
                            {
                                break;
                            }
                        }
                        meter.SetNextSettlementDateTime();//重新计算本阶段结算时间
                    }
                    else
                    {
                        //新价格未启用阶梯价
                        meter.CurrentPrice           = meter.Price1;
                        meter.NextSettlementPointGas = -1;
                    }
                    //删除调价计划
                    new PricingPlanDA().DeletePlan(meter.PricingPlan);
                    meter.PricingPlan = null;
                    new TaskManageDA().UpdateMeter(meter);
                }
                meter.PricingPlan = null;
            }
        }
Esempio n. 14
0
    public bool updateBillRecord(ref BillRecord bRec, string tran_type)
    {
        bool return_val   = false;
        int  bill_number  = bRec.Bill_number;
        int  next_item_id = bdMgr.getNextItemIDForBill(bill_number);


        setTranNoForAllAccountsJournalEntries(bRec.All_accounts_journal_list, bill_number);
        //UPDATE BILL DETAILS
        ArrayList bdList       = bRec.BillDetailList;
        ArrayList AAJEntryList = bRec.All_accounts_journal_list;

        Cmd            = new SqlCommand();
        Cmd.Connection = Con;
        Con.Open();
        SqlTransaction trans = Con.BeginTransaction();

        Cmd.Transaction = trans;
        string delete_list_condition = "";

        try
        {
            for (int i = 0; i < bdList.Count; i++)
            {
                BillDetailRecord bDRec = (BillDetailRecord)bdList[i];
                bDRec.bill_number = bill_number;

                if (bDRec.item_id != -1 && bDRec.item_id != 0)
                {
                    SQL  = "UPDATE [bill_detail] ";
                    SQL += "set elt_account_number= '" + elt_account_number + "',";
                    SQL += "item_ap= '" + bDRec.item_ap + "',";
                    SQL += "item_id= '" + bDRec.item_id + "',";
                    SQL += "item_no= '" + bDRec.item_no + "',";
                    SQL += "item_amt= '" + bDRec.item_amt + "',";
                    SQL += "is_manual= '" + bDRec.is_manual + "',";
                    SQL += "item_expense_acct= '" + bDRec.item_expense_acct + "',";
                    SQL += "tran_date= '" + bDRec.tran_date + "',";
                    //--------------here is where update can be effective for the bill_detail at AP Queue
                    if (bDRec.Is_checked)
                    {
                        SQL += "bill_number= '" + bDRec.bill_number + "',";
                    }
                    else
                    {
                        SQL += "bill_number= 0,";
                    }
                    //--------------
                    SQL += "invoice_no= '" + bDRec.invoice_no + "',";
                    SQL += "agent_debit_no= '" + bDRec.agent_debit_no + "',";
                    SQL += "mb_no= '" + bDRec.mb_no + "',";
                    SQL += "ref= '" + bDRec.ref_no + "',";
                    SQL += "iType= '" + bDRec.iType + "',";
                    SQL += "vendor_number= '" + bDRec.vendor_number + "'";
                    SQL += "WHERE elt_account_number = " + elt_account_number;
                    SQL += " AND invoice_no = " + bDRec.invoice_no;
                    SQL += " AND bill_number = " + bDRec.bill_number;
                    SQL += " AND item_id=" + bDRec.item_id;

                    Cmd.CommandText = SQL;
                    Cmd.ExecuteNonQuery();
                }
                else
                {
                    bDRec.item_id = next_item_id++;
                    SQL           = "INSERT INTO [bill_detail] ";
                    SQL          += "( elt_account_number, ";
                    SQL          += "item_ap,";
                    SQL          += "item_id,";
                    SQL          += "item_no,";
                    SQL          += "item_amt,";
                    SQL          += "is_manual,";
                    SQL          += "item_expense_acct,";
                    SQL          += "tran_date,";
                    SQL          += "bill_number,";
                    SQL          += "invoice_no,";
                    SQL          += "agent_debit_no,";
                    SQL          += "mb_no,";
                    SQL          += "ref,";
                    SQL          += "iType,";
                    SQL          += "vendor_number)";
                    SQL          += "VALUES";
                    SQL          += "('" + elt_account_number;
                    SQL          += "','" + bDRec.item_ap;
                    SQL          += "','" + bDRec.item_id;
                    SQL          += "','" + bDRec.item_no;
                    SQL          += "','" + bDRec.item_amt;
                    SQL          += "','" + bDRec.is_manual;
                    SQL          += "','" + bDRec.item_expense_acct;
                    SQL          += "','" + bDRec.tran_date;
                    SQL          += "','" + bDRec.bill_number;
                    SQL          += "','" + bDRec.invoice_no;
                    SQL          += "','" + bDRec.agent_debit_no;
                    SQL          += "','" + bDRec.mb_no;
                    SQL          += "','" + bDRec.ref_no;
                    SQL          += "','" + bDRec.iType;
                    SQL          += "','" + bDRec.vendor_number;
                    SQL          += "')";

                    Cmd.CommandText = SQL;
                    Cmd.ExecuteNonQuery();
                }

                delete_list_condition += " and item_id<>" + bDRec.item_id + " ";
            }

            /**************************************
             * delete unselected bill detail
             * **************************************/
            SQL = "Delete  FROM bill_detail WHERE elt_account_number = "
                  + elt_account_number + " AND bill_number = " + bill_number + delete_list_condition;
            Cmd.CommandText = SQL;
            Cmd.ExecuteNonQuery();

            //UPDATE AAJ ENTRIES
            //1) DELETE PREVIOUS
            SQL = "Delete  FROM all_accounts_journal WHERE elt_account_number = "
                  + elt_account_number + " AND tran_num = " + bill_number + " AND tran_type = '" + tran_type + "'";
            Cmd.CommandText = SQL;
            Cmd.ExecuteNonQuery();

            int next_tran_seq_no = 0;

            SQL = "select max(tran_seq_num) from all_accounts_journal where elt_account_number = "
                  + elt_account_number;
            Cmd.CommandText = SQL;
            int current = 0;

            string id_str = Cmd.ExecuteScalar().ToString();
            if (id_str != "")
            {
                current = Int32.Parse(id_str);
            }
            else
            {
                current = 0;
            }

            next_tran_seq_no = current + 1;

            //2) INSERT NEW
            if (AAJEntryList != null)
            {
                for (int i = 0; i < AAJEntryList.Count; i++)
                {
                    ((AllAccountsJournalRecord)AAJEntryList[i]).replaceQuote();
                    ((AllAccountsJournalRecord)AAJEntryList[i]).tran_num = bill_number;

                    SQL  = "INSERT INTO [all_accounts_journal] ";
                    SQL += "( elt_account_number, ";
                    SQL += "tran_num,";
                    SQL += "gl_account_number,";
                    SQL += "gl_account_name,";
                    SQL += "tran_seq_num,";
                    SQL += "tran_type,";
                    SQL += "tran_date,";
                    SQL += "Customer_Number,";
                    SQL += "Customer_Name,";
                    SQL += "debit_amount,";
                    SQL += "credit_amount,";
                    SQL += "balance,";
                    SQL += "previous_balance,";
                    SQL += "gl_balance,";
                    SQL += "gl_previous_balance)";
                    SQL += "VALUES";
                    SQL += "('" + elt_account_number;
                    SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).tran_num;
                    SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).gl_account_number;
                    SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).gl_account_name;
                    SQL += "','" + next_tran_seq_no++;
                    SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).tran_type;
                    SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).tran_date;
                    SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).customer_number;
                    SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).customer_name;
                    SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).debit_amount;
                    SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).credit_amount;
                    SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).balance;
                    SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).previous_balance;
                    SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).gl_balance;
                    SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).gl_previous_balance;
                    SQL += "')";

                    Cmd.CommandText = SQL;
                    Cmd.ExecuteNonQuery();
                }
            }
            //UPDATE THE BILL
            SQL  = "update [bill] set ";
            SQL += "elt_account_number='" + elt_account_number + "',";
            SQL += "bill_number='" + bRec.Bill_number + "',";
            SQL += "bill_type='" + bRec.Bill_type + "',";
            SQL += "vendor_number='" + bRec.Vendor_number + "',";
            SQL += "vendor_name='" + bRec.Vendor_name + "',";
            SQL += "bill_date='" + bRec.Bill_date + "',";
            SQL += "bill_due_date='" + bRec.Bill_due_date + "',";
            SQL += "bill_amt='" + bRec.Bill_amt + "',";
            SQL += "bill_amt_paid='" + bRec.Bill_amt_paid + "',";
            SQL += "bill_amt_due='" + bRec.Bill_amt_due + "',";
            SQL += "ref_no='" + bRec.Ref_no + "',";
            SQL += "bill_expense_acct='" + bRec.Bill_expense_acct + "',";
            SQL += "bill_ap='" + bRec.Bill_ap + "',";
            SQL += "bill_status='" + bRec.Bill_status + "',";
            SQL += "print_id='" + bRec.Print_id + "',";
            SQL += "lock='" + bRec.Lock + "',";
            SQL += "pmt_method='" + bRec.Pmt_method + "',";
            SQL += "is_org_merged='" + bRec.Is_org_merged + "'";
            SQL += " where elt_account_number='" + elt_account_number + "' and bill_number=" + bRec.Bill_number;

            Cmd.CommandText = SQL;
            Cmd.ExecuteNonQuery();
            trans.Commit();
            return_val = true;
        }
        catch (Exception ex)
        {
            trans.Rollback();
            throw ex;
        }
        finally
        {
            Con.Close();
        }
        return(return_val);
    }
Esempio n. 15
0
    public bool CancelPayment(int print_id, string tran_type)
    {
        bool      return_val = false;
        int       check_no   = Int32.Parse(getCheckNo(print_id));
        ArrayList cdList     = cdMgr.getcheckDetailListForPrintId(print_id);
        ArrayList bRecList   = new ArrayList();

        for (int i = 0; i < cdList.Count; i++)
        {
            int        bill_number = ((CheckDetailRecord)cdList[i]).bill_number;
            BillRecord bRec        = bMgr.getBill(bill_number);
            bRec.Bill_amt_due  += ((CheckDetailRecord)cdList[i]).amt_paid;
            bRec.Bill_amt_paid -= ((CheckDetailRecord)cdList[i]).amt_paid;
            if (bRec.Bill_amt_paid == 0)
            {
                bRec.Lock = "N";
            }
            bRec.Bill_status = "A";
            bRecList.Add(bRec);
        }
        Cmd            = new SqlCommand();
        Cmd.Connection = Con;
        Con.Open();
        SqlTransaction trans = Con.BeginTransaction();

        Cmd.Transaction = trans;
        try
        {
            //UPDATE BILL RECORD
            for (int i = 0; i < bRecList.Count; i++)
            {
                BillRecord bRec        = (BillRecord)bRecList[i];
                int        bill_number = bRec.Bill_number;
                SQL  = "update [bill] set ";
                SQL += "elt_account_number='" + elt_account_number + "'";
                SQL += ",bill_number='" + bRec.Bill_number + "'";
                SQL += ",bill_type='" + bRec.Bill_type + "'";
                SQL += ",vendor_number='" + bRec.Vendor_number + "'";
                SQL += ",vendor_name='" + bRec.Vendor_name + "'";
                SQL += ",bill_date='" + bRec.Bill_date + "'";
                SQL += ",bill_due_date='" + bRec.Bill_due_date + "'";
                SQL += ",bill_amt='" + bRec.Bill_amt + "'";
                SQL += ",bill_amt_paid='" + bRec.Bill_amt_paid + "'";
                SQL += ",bill_amt_due='" + bRec.Bill_amt_due + "'";
                SQL += ",ref_no='" + bRec.Bill_amt_paid + "'";
                SQL += ",bill_expense_acct='" + bRec.Bill_expense_acct + "'";
                SQL += ",bill_ap='" + bRec.Bill_ap + "'";
                SQL += ",bill_status='" + bRec.Bill_status + "'";
                SQL += ",print_id='" + print_id + "'";
                SQL += ",lock='" + bRec.Lock + "'";
                SQL += ",pmt_method='" + bRec.Pmt_method + "'";
                SQL += " WHERE elt_account_number = " + elt_account_number + " and bill_number=" + bRec.Bill_number;

                Cmd.CommandText = SQL;
                Cmd.ExecuteNonQuery();
            }
            //DELETE ALL THE CHECK DETAIL( ALL PAYMNET HAS ITS CHECK DETAIL!!)
            SQL = "delete from check_detail where elt_account_number = " + elt_account_number + " and print_id=" + print_id;

            Cmd.CommandText = SQL;
            Cmd.ExecuteNonQuery();
            if (tran_type == "BP-CHK" || tran_type == "CHK")
            {
                //VOID CHECK INSIDE CHECK_QUEUE
                SQL = "update check_queue set chk_void='Y' where elt_account_number = " + elt_account_number + " and print_id = " + print_id;

                Cmd.CommandText = SQL;
                Cmd.ExecuteNonQuery();
                //VOID CHECK IN AAJ
                SQL = "update all_accounts_journal set chk_void='Y', debit_amount=0, credit_amount=0 where elt_account_number = " + elt_account_number + " and tran_num = " + print_id + " and tran_type='" + tran_type + "'";

                Cmd.CommandText = SQL;
                Cmd.ExecuteNonQuery();

                if (check_no == 0)
                {
                    SQL = "delete from  check_queue  where elt_account_number = " + elt_account_number + " and print_id = " + print_id;

                    Cmd.CommandText = SQL;
                    Cmd.ExecuteNonQuery();
                }
            }
            else
            {
                //DELETE ALL AAJ ENTRIES
                SQL = "Delete  FROM all_accounts_journal WHERE elt_account_number = "
                      + elt_account_number + " AND tran_num = " + print_id + " AND tran_type = '" + tran_type + "'";

                Cmd.CommandText = SQL;
                Cmd.ExecuteNonQuery();

                //DELETE CHECK QUEUE ENTRIES
                SQL = "delete from  check_queue  where elt_account_number = " + elt_account_number + " and print_id = " + print_id;

                Cmd.CommandText = SQL;
                Cmd.ExecuteNonQuery();
            }
            trans.Commit();
            return_val = true;
        }
        catch (Exception ex)
        {
            trans.Rollback();
            throw ex;
        }
        finally
        {
            Con.Close();
        }
        return(return_val);
    }
Esempio n. 16
0
    public bool enqueuePayment(CheckQueueRecord Check, string tran_type)
    {
        Check.replaceQuote();
        bool      return_val   = false;
        ArrayList AAJEntryList = Check.All_accounts_journal_entry_list;
        int       printID      = getNextPrintID();

        Check.print_id = printID;
        for (int i = 0; i < AAJEntryList.Count; i++)
        {
            this.aajMgr.checkInitial_Acct_Record((AllAccountsJournalRecord)AAJEntryList[i]);
        }

        Cmd            = new SqlCommand();
        Cmd.Connection = Con;
        Con.Open();
        SqlTransaction trans = Con.BeginTransaction();

        Cmd.Transaction = trans;

        try
        {
            //UPDATE LIST OF BILLS TO SET THE CHANGES MADE BY PAYMENT
            ArrayList bRecList = Check.BillList;
            for (int i = 0; i < bRecList.Count; i++)
            {
                BillRecord bRec = (BillRecord)bRecList[i];
                SQL             = "update [bill] set ";
                SQL            += "elt_account_number='" + elt_account_number + "'";
                SQL            += ",bill_number='" + bRec.Bill_number + "'";
                SQL            += ",bill_type='" + bRec.Bill_type + "'";
                SQL            += ",vendor_number='" + bRec.Vendor_number + "'";
                SQL            += ",vendor_name='" + bRec.Vendor_name + "'";
                SQL            += ",bill_date='" + bRec.Bill_date + "'";
                SQL            += ",bill_due_date='" + bRec.Bill_due_date + "'";
                SQL            += ",bill_amt='" + bRec.Bill_amt + "'";
                SQL            += ",bill_amt_paid='" + bRec.Bill_amt_paid + "'";
                SQL            += ",bill_amt_due='" + bRec.Bill_amt_due + "'";
                SQL            += ",ref_no='" + bRec.Bill_amt_paid + "'";
                SQL            += ",bill_expense_acct='" + bRec.Bill_expense_acct + "'";
                SQL            += ",bill_ap='" + bRec.Bill_ap + "'";
                SQL            += ",bill_status='" + bRec.Bill_status + "'";
                SQL            += ",print_id='" + printID + "'";
                SQL            += ",lock='" + bRec.Lock + "'";
                SQL            += ",pmt_method='" + bRec.Pmt_method + "'";
                SQL            += " WHERE elt_account_number = " + elt_account_number + " and bill_number=" + bRec.Bill_number;
                Cmd.CommandText = SQL;
                Cmd.ExecuteNonQuery();
            }
            //INSERT CHECK DETAIL LIST
            ArrayList chkList = Check.CheckDetailList;

            for (int i = 0; i < chkList.Count; i++)
            {
                CheckDetailRecord cdRec = (CheckDetailRecord)chkList[i];
                cdRec.replaceQuote();
                cdRec.print_id  = printID;
                SQL             = "INSERT INTO [check_detail] ";
                SQL            += "( elt_account_number, ";
                SQL            += "amt_due,";
                SQL            += "amt_paid,";
                SQL            += "bill_amt,";
                SQL            += "bill_number,";
                SQL            += "due_date,";
                SQL            += "invoice_no,";
                SQL            += "memo,";
                SQL            += "pmt_method,";
                SQL            += "print_id,";
                SQL            += "tran_id)";
                SQL            += "VALUES";
                SQL            += "('" + elt_account_number;
                SQL            += "','" + cdRec.amt_due;
                SQL            += "','" + cdRec.amt_paid;
                SQL            += "','" + cdRec.bill_amt;
                SQL            += "','" + cdRec.bill_number;
                SQL            += "','" + cdRec.due_date;
                SQL            += "','" + cdRec.invoice_no;
                SQL            += "','" + cdRec.memo;
                SQL            += "','" + cdRec.pmt_method;
                SQL            += "','" + printID;
                SQL            += "','" + cdRec.tran_id;
                SQL            += "')";
                Cmd.CommandText = SQL;
                Cmd.ExecuteNonQuery();
            }
            //INSERT AAJ ENTRIES

            int tran_seq_id = 0;

            SQL = "select max(tran_seq_num) from all_accounts_journal where elt_account_number = "
                  + elt_account_number;
            Cmd.CommandText = SQL;
            int current = 0;

            string id_str = Cmd.ExecuteScalar().ToString();
            if (id_str != "")
            {
                current = Int32.Parse(id_str);
            }
            else
            {
                current = 0;
            }

            tran_seq_id = current + 1;

            for (int i = 0; i < AAJEntryList.Count; i++)
            {
                ((AllAccountsJournalRecord)AAJEntryList[i]).replaceQuote();
                ((AllAccountsJournalRecord)AAJEntryList[i]).tran_num = printID;
                SQL             = "INSERT INTO [all_accounts_journal] ";
                SQL            += "( elt_account_number, ";
                SQL            += "tran_num,";
                SQL            += "gl_account_number,";
                SQL            += "gl_account_name,";
                SQL            += "tran_seq_num,";
                SQL            += "tran_type,";
                SQL            += "tran_date,";
                SQL            += "Customer_Number,";
                SQL            += "Customer_Name,";
                SQL            += "debit_amount,";
                SQL            += "credit_amount,";
                SQL            += "balance,";
                SQL            += "previous_balance,";
                SQL            += "gl_balance,";
                SQL            += "gl_previous_balance)";
                SQL            += "VALUES";
                SQL            += "('" + elt_account_number;
                SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).tran_num;
                SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).gl_account_number;
                SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).gl_account_name;
                SQL            += "','" + tran_seq_id++;
                SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).tran_type;
                SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).tran_date;
                SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).customer_number;
                SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).customer_name;
                SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).debit_amount;
                SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).credit_amount;
                SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).balance;
                SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).previous_balance;
                SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).gl_balance;
                SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).gl_previous_balance;
                SQL            += "')";
                Cmd.CommandText = SQL;
                Cmd.ExecuteNonQuery();
            }
            string check_type = "";
            if (tran_type == "BP-CHK")//ONLY AT BILL PAY
            {
                check_type = "C";
            }
            else
            {
                check_type = "BP";
            }

            SQL  = "INSERT INTO [check_queue] ";
            SQL += "(elt_account_number,";
            SQL += "ap,";
            SQL += "bank,";
            SQL += "bill_date,";
            SQL += "bill_due_date,";
            SQL += "check_amt,";
            SQL += "check_type,";
            SQL += "memo,";
            SQL += "pmt_method,";
            SQL += "print_check_as,";
            SQL += "print_date,";
            SQL += "print_id,";
            SQL += "print_status,";
            SQL += "vendor_info,";
            SQL += "vendor_name,";
            if (Check.check_no != 0)
            {
                SQL += "check_no,";
            }
            SQL += "vendor_number)";
            SQL += "VALUES";
            SQL += "('" + elt_account_number;
            SQL += "','" + Check.ap;
            SQL += "','" + Check.bank;
            SQL += "','" + Check.bill_date;
            SQL += "','" + Check.bill_due_date;
            SQL += "','" + Check.check_amt;
            SQL += "','" + check_type;
            SQL += "','" + Check.memo;
            SQL += "','" + Check.pmt_method;
            SQL += "','" + Check.print_check_as;
            SQL += "','" + Check.print_date;
            SQL += "','" + Check.print_id;
            SQL += "','" + Check.print_status;
            SQL += "','" + Check.vendor_info;
            SQL += "','" + Check.vendor_name;
            if (Check.check_no != 0)
            {
                SQL += "','" + Check.check_no;
            }
            SQL            += "','" + Check.vendor_number;
            SQL            += "')";
            Cmd.CommandText = SQL;
            Cmd.ExecuteNonQuery();
            trans.Commit();
            return_val = true;
        }
        catch (Exception ex)
        {
            trans.Rollback();
            throw ex;
        }
        finally
        {
            Con.Close();
        }
        if (Check.check_no != 0)
        {
            GLManager glmgr = new GLManager(elt_account_number);
            try
            {
                glmgr.updateNextCheckNumber(Check.bank, Check.check_no);
            }
            catch (Exception ex2)
            {
                throw ex2;
            }
        }
        return(return_val);
    }
Esempio n. 17
0
    public bool updateCheck(CheckQueueRecord Check, string tran_type)
    {
        bool return_val = false;

        Check.replaceQuote();
        BillManager bMgr = new BillManager(elt_account_number);

        ArrayList AAJEntryList = Check.All_accounts_journal_entry_list;
        int       printID      = Check.print_id;


        BillRecord bRec = (BillRecord)Check.BillList[0];

        if (bMgr.updateBillRecord(ref bRec, "CHK"))
        {
            for (int i = 0; i < AAJEntryList.Count; i++)
            {
                if (((AllAccountsJournalRecord)AAJEntryList[i]).gl_account_number != -1 && ((AllAccountsJournalRecord)AAJEntryList[i]).gl_account_number != 0)
                {
                    this.aajMgr.checkInitial_Acct_Record((AllAccountsJournalRecord)AAJEntryList[i]);
                }
            }

            int tran_seq_id = this.aajMgr.getNextTranSeqNumber();


            Cmd            = new SqlCommand();
            Cmd.Connection = Con;
            Con.Open();
            SqlTransaction trans = Con.BeginTransaction();
            Cmd.Transaction = trans;

            try
            {
                //DELETE PREVIOUS CHECK_DETAIL LIST

                SQL             = "DELETE FROM check_detail where elt_account_number =" + elt_account_number + " and print_id=" + printID;
                Cmd.CommandText = SQL;
                Cmd.ExecuteNonQuery();

                //DELETE ALL_ACCOUNTS_JOURNAL ENTRY

                SQL             = "DELETE FROM all_accounts_journal where elt_account_number =" + elt_account_number + " and tran_num=" + printID + " and tran_type='" + tran_type + "'";
                Cmd.CommandText = SQL;
                Cmd.ExecuteNonQuery();

                //INSERT CHECK_DETAL LIST
                ArrayList chkList = Check.CheckDetailList;
                for (int i = 0; i < chkList.Count; i++)
                {
                    CheckDetailRecord cdRec = (CheckDetailRecord)chkList[i];
                    cdRec.replaceQuote();
                    cdRec.print_id = printID;
                    SQL            = "INSERT INTO [check_detail] ";
                    SQL           += "( elt_account_number, ";
                    SQL           += "amt_due,";
                    SQL           += "amt_paid,";
                    SQL           += "bill_amt,";
                    SQL           += "bill_number,";
                    SQL           += "due_date,";
                    SQL           += "invoice_no,";
                    SQL           += "memo,";
                    SQL           += "pmt_method,";
                    SQL           += "print_id,";
                    SQL           += "tran_id)";
                    SQL           += "VALUES";
                    SQL           += "('" + elt_account_number;
                    SQL           += "','" + cdRec.amt_due;
                    SQL           += "','" + cdRec.amt_paid;
                    SQL           += "','" + cdRec.bill_amt;
                    SQL           += "','" + cdRec.bill_number;
                    SQL           += "','" + cdRec.due_date;

                    SQL            += "','" + cdRec.invoice_no;
                    SQL            += "','" + cdRec.memo;
                    SQL            += "','" + cdRec.pmt_method;
                    SQL            += "','" + printID;
                    SQL            += "','" + cdRec.tran_id;
                    SQL            += "')";
                    Cmd.CommandText = SQL;
                    Cmd.ExecuteNonQuery();
                }
                //INSERT AAJ ENTRIES
                for (int i = 0; i < AAJEntryList.Count; i++)
                {
                    if (((AllAccountsJournalRecord)AAJEntryList[i]).gl_account_number != -1 && ((AllAccountsJournalRecord)AAJEntryList[i]).gl_account_number != 0)
                    {
                        ((AllAccountsJournalRecord)AAJEntryList[i]).replaceQuote();
                        ((AllAccountsJournalRecord)AAJEntryList[i]).tran_num = printID;
                        SQL             = "INSERT INTO [all_accounts_journal] ";
                        SQL            += "( elt_account_number, ";
                        SQL            += "tran_num,";
                        SQL            += "gl_account_number,";
                        SQL            += "gl_account_name,";
                        SQL            += "tran_seq_num,";
                        SQL            += "tran_type,";
                        SQL            += "tran_date,";
                        SQL            += "Customer_Number,";
                        SQL            += "Customer_Name,";
                        SQL            += "debit_amount,";
                        SQL            += "credit_amount,";
                        SQL            += "balance,";
                        SQL            += "previous_balance,";
                        SQL            += "gl_balance,";
                        SQL            += "gl_previous_balance)";
                        SQL            += "VALUES";
                        SQL            += "('" + elt_account_number;
                        SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).tran_num;
                        SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).gl_account_number;
                        SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).gl_account_name;
                        SQL            += "','" + tran_seq_id++;
                        SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).tran_type;
                        SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).tran_date;
                        SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).customer_number;
                        SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).customer_name;
                        SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).debit_amount;
                        SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).credit_amount;
                        SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).balance;
                        SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).previous_balance;
                        SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).gl_balance;
                        SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).gl_previous_balance;
                        SQL            += "')";
                        Cmd.CommandText = SQL;
                        Cmd.ExecuteNonQuery();
                    }
                }
                //UPDATE THE CHECK

                string check_type = "";
                if (tran_type == "CHK" || tran_type == "CSH" || tran_type == "CRC" || tran_type == "BTB")
                {
                    check_type = "C";
                }
                else
                {
                    check_type = "BP";
                }

                SQL  = "UPDATE [check_queue] ";
                SQL += "Set elt_account_number='" + elt_account_number + "',";
                SQL += "ap='" + Check.ap + "',";
                SQL += "bank='" + Check.bank + "',";
                SQL += "bill_date='" + Check.bill_date + "',";
                SQL += "bill_due_date='" + Check.bill_due_date + "',";
                SQL += "check_amt='" + Check.check_amt + "',";
                SQL += "check_type='" + check_type + "',";
                SQL += "memo='" + Check.memo + "',";
                SQL += "pmt_method='" + Check.pmt_method + "',";
                SQL += "print_check_as='" + Check.print_check_as + "',";
                SQL += "print_date='" + Check.print_date + "',";
                SQL += "print_id='" + Check.print_id + "',";
                SQL += "print_status='" + Check.print_status + "',";
                SQL += "vendor_info='" + Check.vendor_info + "',";
                SQL += "vendor_name='" + Check.vendor_name + "',";
                SQL += "vendor_number='" + Check.vendor_number + "'";
                SQL += "where elt_account_number =" + elt_account_number
                       + " and print_id=" + printID;

                Cmd.CommandText = SQL;
                Cmd.ExecuteNonQuery();
                trans.Commit();
                return_val = true;
            }
            catch (Exception ex)
            {
                trans.Rollback();
                throw ex;
            }
            finally
            {
                Con.Close();
            }
        }
        return(return_val);
    }
Esempio n. 18
0
    public bool enqueueCheck(CheckQueueRecord Check, string tran_type)
    {
        bool return_val = false;

        Check.replaceQuote();
        BillManager bMgr = new BillManager(elt_account_number);

        ArrayList AAJEntryList = Check.All_accounts_journal_entry_list;
        int       printID      = getNextPrintID();

        Check.print_id = printID;

        BillRecord bRec = (BillRecord)Check.BillList[0];

        bRec.Print_id = printID;
        if (bMgr.insertBillRecord(ref bRec, "CHK"))
        {
            for (int i = 0; i < AAJEntryList.Count; i++)
            {
                if (((AllAccountsJournalRecord)AAJEntryList[i]).gl_account_number != -1 && ((AllAccountsJournalRecord)AAJEntryList[i]).gl_account_number != 0)
                {
                    this.aajMgr.checkInitial_Acct_Record((AllAccountsJournalRecord)AAJEntryList[i]);
                }
            }

            int tran_seq_id = this.aajMgr.getNextTranSeqNumber();

            //INSERT CHECK_DETAL LIST
            Cmd            = new SqlCommand();
            Cmd.Connection = Con;
            Con.Open();
            SqlTransaction trans = Con.BeginTransaction();
            Cmd.Transaction = trans;

            try
            {
                ArrayList chkList = Check.CheckDetailList;
                for (int i = 0; i < chkList.Count; i++)
                {
                    CheckDetailRecord cdRec = (CheckDetailRecord)chkList[i];
                    cdRec.replaceQuote();
                    cdRec.print_id = printID;
                    SQL            = "INSERT INTO [check_detail] ";
                    SQL           += "( elt_account_number, ";
                    SQL           += "amt_due,";
                    SQL           += "amt_paid,";
                    SQL           += "bill_amt,";
                    SQL           += "bill_number,";
                    SQL           += "due_date,";
                    SQL           += "invoice_no,";
                    SQL           += "memo,";
                    SQL           += "pmt_method,";
                    SQL           += "print_id,";
                    SQL           += "tran_id)";
                    SQL           += "VALUES";
                    SQL           += "('" + elt_account_number;
                    SQL           += "','" + cdRec.amt_due;
                    SQL           += "','" + cdRec.amt_paid;
                    SQL           += "','" + cdRec.bill_amt;
                    SQL           += "','" + cdRec.bill_number;
                    SQL           += "','" + cdRec.due_date;

                    SQL            += "','" + cdRec.invoice_no;
                    SQL            += "','" + cdRec.memo;
                    SQL            += "','" + cdRec.pmt_method;
                    SQL            += "','" + printID;
                    SQL            += "','" + cdRec.tran_id;
                    SQL            += "')";
                    Cmd.CommandText = SQL;
                    Cmd.ExecuteNonQuery();
                }
                //INSERT AAJ ENTRIES
                for (int i = 0; i < AAJEntryList.Count; i++)
                {
                    if (((AllAccountsJournalRecord)AAJEntryList[i]).gl_account_number != -1 && ((AllAccountsJournalRecord)AAJEntryList[i]).gl_account_number != 0)
                    {
                        ((AllAccountsJournalRecord)AAJEntryList[i]).replaceQuote();
                        ((AllAccountsJournalRecord)AAJEntryList[i]).tran_num = printID;
                        SQL             = "INSERT INTO [all_accounts_journal] ";
                        SQL            += "( elt_account_number, ";
                        SQL            += "tran_num,";
                        SQL            += "gl_account_number,";
                        SQL            += "gl_account_name,";
                        SQL            += "tran_seq_num,";
                        SQL            += "tran_type,";
                        SQL            += "tran_date,";
                        SQL            += "Customer_Number,";
                        SQL            += "Customer_Name,";
                        SQL            += "debit_amount,";
                        SQL            += "credit_amount,";
                        SQL            += "balance,";
                        SQL            += "previous_balance,";
                        SQL            += "gl_balance,";
                        SQL            += "gl_previous_balance)";
                        SQL            += "VALUES";
                        SQL            += "('" + elt_account_number;
                        SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).tran_num;
                        SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).gl_account_number;
                        SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).gl_account_name;
                        SQL            += "','" + tran_seq_id++;
                        SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).tran_type;
                        SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).tran_date;
                        SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).customer_number;
                        SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).customer_name;
                        SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).debit_amount;
                        SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).credit_amount;
                        SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).balance;
                        SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).previous_balance;
                        SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).gl_balance;
                        SQL            += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).gl_previous_balance;
                        SQL            += "')";
                        Cmd.CommandText = SQL;
                        Cmd.ExecuteNonQuery();
                    }
                }
                //INSERT A CHECK

                string check_type = "";
                if (tran_type == "CHK" || tran_type == "CSH" || tran_type == "CRC" || tran_type == "BTB")
                {
                    check_type = "C";
                }
                else
                {
                    check_type = "BP";
                }

                SQL  = "INSERT INTO [check_queue] ";
                SQL += "(elt_account_number,";
                SQL += "ap,";
                SQL += "bank,";
                SQL += "bill_date,";
                SQL += "bill_due_date,";
                SQL += "check_amt,";
                SQL += "check_type,";
                SQL += "memo,";
                SQL += "pmt_method,";
                SQL += "print_check_as,";
                SQL += "print_date,";
                SQL += "print_id,";
                SQL += "print_status,";
                SQL += "vendor_info,";
                SQL += "vendor_name,";
                if (Check.check_no != 0)
                {
                    SQL += "check_no,";
                }
                SQL += "vendor_number)";
                SQL += "VALUES";
                SQL += "('" + elt_account_number;
                SQL += "','" + Check.ap;
                SQL += "','" + Check.bank;
                SQL += "','" + Check.bill_date;
                SQL += "','" + Check.bill_due_date;
                SQL += "','" + Check.check_amt;
                SQL += "','" + check_type;
                SQL += "','" + Check.memo;
                SQL += "','" + Check.pmt_method;
                SQL += "','" + Check.print_check_as;
                SQL += "','" + Check.print_date;
                SQL += "','" + Check.print_id;
                SQL += "','" + Check.print_status;
                SQL += "','" + Check.vendor_info;
                SQL += "','" + Check.vendor_name;
                if (Check.check_no != 0)
                {
                    SQL += "','" + Check.check_no;
                }
                SQL            += "','" + Check.vendor_number;
                SQL            += "')";
                Cmd.CommandText = SQL;
                Cmd.ExecuteNonQuery();
                trans.Commit();
                return_val = true;
            }
            catch (Exception ex)
            {
                trans.Rollback();
                throw ex;
            }
            finally
            {
                Con.Close();
            }
        }
        if (Check.check_no != 0)
        {
            GLManager glmgr = new GLManager(elt_account_number);
            try
            {
                glmgr.updateNextCheckNumber(Check.bank, Check.check_no);
            }
            catch (Exception ex2)
            {
                throw ex2;
            }
        }
        return(return_val);
    }
        private static XElement GenerateAutoResponse(string guid, XElement billPullRequest)
        {
            MFEPMessage <BillInquiryRequestEntity> deserializedRequest = billPullRequest.FromXElement <MFEPMessage <BillInquiryRequestEntity> >();

            MFEPMessage <BillsRecord> response = new MFEPMessage <BillsRecord>();

            response.Header.TimeStamp    = DateTime.Now.ToString("s");
            response.Header.Guid         = guid;
            response.Header.TransmitInfo = new TransmitInfo()
            {
                SenderCode   = deserializedRequest.Header.TransmitInfo.ReceiverCode,
                ResponseType = ProcessesCodes.BILPULRS
            };

            response.Header.Result = new Result();

            response.Body = new BillsRecord()
            {
                RecCount = 1
            };

            Collection <BillRecord> billRecords = new Collection <BillRecord>();

            BillRecord o = new BillRecord();

            o.PmtConst           = new PmtConst();
            o.PmtConst.AllowPart = AllowPart;
            if (o.PmtConst.AllowPart != false)
            {
                o.PmtConst.Lower = 50;
                o.PmtConst.Upper = 100;
            }
            BillRecord billRecord = new BillRecord()
            {
                AccountInfo = new AccountInfo
                {
                    BillingNumber = deserializedRequest.Body.AccountInfo.BillingNumber,
                    BillNumber    = deserializedRequest.Body.AccountInfo.BillNumber
                                    // BillerCode = 191
                },
                BillStatus = BillStatusCodes.BillNew,
                DueAmount  = new Random().Next(50, 100),

                IssueDate   = DateTime.Now.AddMinutes(TimeDifference),
                DueDate     = DateTime.Now.AddMinutes(TimeDifference),
                ServiceType = deserializedRequest.Body.ServiceType,
                // PmtConst = o.PmtConst
            };


            billRecords.Add(billRecord);
            response.Body.BillRecords = billRecords;


            XElement billPullResponse = response.ToXElement <MFEPMessage <BillsRecord> >();

            string signatureValue = string.Empty;

            if (EnableSecuity)
            {
                signatureValue = CertificateManager.SignMessage(billPullResponse, new Collection <string>()
                {
                    ".//MsgBody"
                }, BillerCertificateSerialNumber, (SignMode)Enum.Parse(typeof(SignMode), SecurityMode));
            }

            response.Footer = new MFEPFooter()
            {
                Security =
                    new Security()
                {
                    Signature = signatureValue
                }
            };

            //return response;

            return(response.ToXElement <MFEPMessage <BillsRecord> >());
        }
Esempio n. 20
0
    public bool insertBillRecord(ref BillRecord bRec, string tran_type)
    {
        bRec.replaceQuote();
        bool return_val  = false;
        int  bill_number = getNewbillNumber();

        bRec.Bill_number = bill_number;

        int next_item_id = bdMgr.getNextItemIDForBill(bill_number);

        if (bRec.All_accounts_journal_list != null)
        {
            setTranNoForAllAccountsJournalEntries(bRec.All_accounts_journal_list, bill_number);
        }

        for (int i = 0; i < bRec.BillDetailList.Count; i++)
        {
            ((BillDetailRecord)bRec.BillDetailList[i]).bill_number = bill_number;
        }
        ArrayList bdList = bRec.BillDetailList;

        ArrayList AAJEntryList = bRec.All_accounts_journal_list;

        if (bRec.All_accounts_journal_list != null)
        {
            for (int i = 0; i < AAJEntryList.Count; i++)
            {
                AAJMgr.checkInitial_Acct_Record((AllAccountsJournalRecord)AAJEntryList[i]);
            }
        }
        int next_tran_seq_no = AAJMgr.getNextTranSeqNumber();

        Cmd            = new SqlCommand();
        Cmd.Connection = Con;
        Con.Open();
        SqlTransaction trans = Con.BeginTransaction();

        Cmd.Transaction = trans;

        try
        {
            //Keept the ID from OPERATION/UPDATE BILL DETAILS SINCE BILL_DETAIL CAN BE ALREAY EXISTING/ generated From MB/
            for (int i = 0; i < bdList.Count; i++)
            {
                BillDetailRecord bDRec = (BillDetailRecord)bdList[i];
                bDRec.bill_number = bill_number;

                if (bDRec.item_id != -1 && bDRec.item_id != 0)
                {
                    SQL  = "UPDATE [bill_detail] ";
                    SQL += "set elt_account_number= '" + elt_account_number + "',";
                    SQL += "item_ap= '" + bDRec.item_ap + "',";
                    SQL += "item_id= '" + bDRec.item_id + "',";
                    SQL += "item_no= '" + bDRec.item_no + "',";
                    SQL += "item_amt= '" + bDRec.item_amt + "',";
                    SQL += "is_manual= '" + bDRec.is_manual + "',";
                    SQL += "item_expense_acct= '" + bDRec.item_expense_acct + "',";
                    SQL += "tran_date= '" + bDRec.tran_date + "',";
                    //--------------here is where update can be effective for the bill_detail at AP Queue
                    if (bDRec.Is_checked)
                    {
                        SQL += "bill_number= '" + bDRec.bill_number + "',";
                    }
                    else
                    {
                        SQL += "bill_number= 0,";
                        bDRec.bill_number = 0;
                    }
                    //--------------
                    SQL += "invoice_no= '" + bDRec.invoice_no + "',";
                    SQL += "agent_debit_no= '" + bDRec.agent_debit_no + "',";
                    SQL += "mb_no= '" + bDRec.mb_no + "',";
                    SQL += "ref= '" + bDRec.ref_no + "',";
                    SQL += "iType= '" + bDRec.iType + "',";
                    SQL += "vendor_number= '" + bDRec.vendor_number + "'";
                    SQL += "WHERE elt_account_number = " + elt_account_number;
                    SQL += " AND invoice_no = " + bDRec.invoice_no;
                    SQL += " AND item_id=" + bDRec.item_id;

                    Cmd.CommandText = SQL;
                    Cmd.ExecuteNonQuery();
                }
                else
                {
                    bDRec.item_id = next_item_id++;
                    SQL           = "INSERT INTO [bill_detail] ";
                    SQL          += "( elt_account_number, ";
                    SQL          += "item_ap,";
                    SQL          += "item_id,";
                    SQL          += "item_no,";
                    SQL          += "item_amt,";
                    SQL          += "is_manual,";
                    SQL          += "item_expense_acct,";
                    SQL          += "tran_date,";
                    SQL          += "bill_number,";
                    SQL          += "invoice_no,";
                    SQL          += "agent_debit_no,";
                    SQL          += "mb_no,";
                    SQL          += "ref,";
                    SQL          += "iType,";
                    SQL          += "vendor_number)";
                    SQL          += "VALUES";
                    SQL          += "('" + elt_account_number;
                    SQL          += "','" + bDRec.item_ap;
                    SQL          += "','" + bDRec.item_id;
                    SQL          += "','" + bDRec.item_no;
                    SQL          += "','" + bDRec.item_amt;
                    SQL          += "','" + bDRec.is_manual;
                    SQL          += "','" + bDRec.item_expense_acct;
                    SQL          += "','" + bDRec.tran_date;
                    SQL          += "','" + bDRec.bill_number;
                    SQL          += "','" + bDRec.invoice_no;
                    SQL          += "','" + bDRec.agent_debit_no;
                    SQL          += "','" + bDRec.mb_no;
                    SQL          += "','" + bDRec.ref_no;
                    SQL          += "','" + bDRec.iType;
                    SQL          += "','" + bDRec.vendor_number;
                    SQL          += "')";

                    Cmd.CommandText = SQL;
                    Cmd.ExecuteNonQuery();
                }
            }
            if (bRec.All_accounts_journal_list != null)
            {
                for (int i = 0; i < AAJEntryList.Count; i++)
                {
                    ((AllAccountsJournalRecord)AAJEntryList[i]).replaceQuote();
                    ((AllAccountsJournalRecord)AAJEntryList[i]).tran_num = bill_number;

                    SQL  = "INSERT INTO [all_accounts_journal] ";
                    SQL += "( elt_account_number, ";
                    SQL += "tran_num,";
                    SQL += "gl_account_number,";
                    SQL += "gl_account_name,";
                    SQL += "tran_seq_num,";
                    SQL += "tran_type,";
                    SQL += "tran_date,";
                    SQL += "Customer_Number,";
                    SQL += "Customer_Name,";
                    SQL += "debit_amount,";
                    SQL += "credit_amount,";
                    SQL += "balance,";
                    SQL += "previous_balance,";
                    SQL += "gl_balance,";
                    SQL += "gl_previous_balance)";
                    SQL += "VALUES";
                    SQL += "('" + elt_account_number;
                    SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).tran_num;
                    SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).gl_account_number;
                    SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).gl_account_name;
                    SQL += "','" + next_tran_seq_no++;
                    SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).tran_type;
                    SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).tran_date;
                    SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).customer_number;
                    SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).customer_name;
                    SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).debit_amount;
                    SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).credit_amount;
                    SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).balance;
                    SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).previous_balance;
                    SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).gl_balance;
                    SQL += "','" + ((AllAccountsJournalRecord)AAJEntryList[i]).gl_previous_balance;
                    SQL += "')";

                    Cmd.CommandText = SQL;
                    Cmd.ExecuteNonQuery();
                }
            }


            SQL  = "INSERT INTO [bill] ";
            SQL += "(elt_account_number,";
            SQL += "bill_number,";
            SQL += "bill_type,";
            SQL += "vendor_number,";
            SQL += "vendor_name,";
            SQL += "bill_date,";
            SQL += "bill_due_date,";
            SQL += "bill_amt,";
            SQL += "bill_amt_paid,";
            SQL += "bill_amt_due,";
            SQL += "ref_no,";
            SQL += "bill_expense_acct,";
            SQL += "bill_ap,";
            SQL += "bill_status,";
            SQL += "print_id,";
            SQL += "lock,";
            SQL += "pmt_method,";
            SQL += "is_org_merged)";
            SQL += "VALUES";
            SQL += "('" + elt_account_number;
            SQL += "','" + bRec.Bill_number;
            SQL += "','" + bRec.Bill_type;
            SQL += "','" + bRec.Vendor_number;
            SQL += "','" + bRec.Vendor_name;
            SQL += "','" + bRec.Bill_date;
            SQL += "','" + bRec.Bill_due_date;
            SQL += "','" + bRec.Bill_amt;
            SQL += "','" + bRec.Bill_amt_paid;
            SQL += "','" + bRec.Bill_amt_due;
            SQL += "','" + bRec.Ref_no;
            SQL += "','" + bRec.Bill_expense_acct;
            SQL += "','" + bRec.Bill_ap;
            SQL += "','" + bRec.Bill_status;
            SQL += "','" + bRec.Print_id;
            SQL += "','" + bRec.Lock;
            SQL += "','" + bRec.Pmt_method;
            SQL += "','" + bRec.Is_org_merged;
            SQL += "')";

            Cmd.CommandText = SQL;
            Cmd.ExecuteNonQuery();


            SQL = "Delete  FROM bill_detail WHERE elt_account_number = "
                  + elt_account_number + " AND bill_number = " + bill_number + " AND item_amt = " + 0;
            Cmd.CommandText = SQL;
            Cmd.ExecuteNonQuery();

            trans.Commit();
            return_val = true;
        }
        catch (Exception ex)
        {
            trans.Rollback();
            throw ex;
        }
        finally
        {
            Con.Close();
        }
        MBCostItemsManager MBCostItemMgr = new MBCostItemsManager(elt_account_number);
        IVCostItemsManager IVCostItemMgr = new IVCostItemsManager(elt_account_number);
        int    invoice_no = 0;
        string mb_no      = "";
        int    item_id    = 0;

        for (int i = 0; i < bdList.Count; i++)
        {
            if (((BillDetailRecord)bdList[i]).bill_number == 0)
            {
                if (((BillDetailRecord)bdList[i]).mb_no != "")
                {
                    mb_no   = ((BillDetailRecord)bdList[i]).mb_no;
                    item_id = ((BillDetailRecord)bdList[i]).item_id;
                    MBCostItemMgr.resetAPLock(mb_no, item_id, "N");
                }
                if (((BillDetailRecord)bdList[i]).invoice_no != 0)
                {
                    invoice_no = ((BillDetailRecord)bdList[i]).invoice_no;
                    item_id    = ((BillDetailRecord)bdList[i]).item_id;
                    IVCostItemMgr.resetAPLock(invoice_no, item_id, "N");
                }
            }
            else
            {
                if (((BillDetailRecord)bdList[i]).mb_no != "")
                {
                    mb_no   = ((BillDetailRecord)bdList[i]).mb_no;
                    item_id = ((BillDetailRecord)bdList[i]).item_id;
                    MBCostItemMgr.resetAPLock(mb_no, item_id, "Y");
                }
                if (((BillDetailRecord)bdList[i]).invoice_no != 0)
                {
                    invoice_no = ((BillDetailRecord)bdList[i]).invoice_no;
                    item_id    = ((BillDetailRecord)bdList[i]).item_id;
                    IVCostItemMgr.resetAPLock(invoice_no, item_id, "Y");
                }
            }
        }

        return(return_val);
    }
Esempio n. 21
0
        /// <summary>
        /// 计算气费
        /// </summary>
        /// <param name="meter"></param>
        /// <param name="ljGas"></param>
        /// <returns></returns>
        public Meter CalculateGasFee(Meter meter, decimal ljGas, string calculateDate = "", bool isChangeMeter = false)
        {
            decimal[] prices = new decimal[5];
            prices[0] = meter.Price1;
            prices[1] = meter.Price2;
            prices[2] = meter.Price3;
            prices[3] = meter.Price4;
            prices[4] = meter.Price5;
            decimal[] gas = new decimal[4];
            gas[0] = meter.Gas1;
            gas[1] = meter.Gas2;
            gas[2] = meter.Gas3;
            gas[3] = meter.Gas4;
            if (meter.Ladder <= 0)
            {
                meter.Ladder = 1;
            }

            //计算当前阶段用气量
ReCalulate:
            decimal JieDuanYongQiLiang = ljGas - meter.LastGasPoint;

            meter.CurrentPrice = prices[meter.CurrentLadder - 1];

            if (meter.Ladder > 1 && meter.NextSettlementPointGas != -1 && ljGas >= meter.NextSettlementPointGas)
            {
                //已到达阶梯结算点
                JieDuanYongQiLiang    = meter.NextSettlementPointGas - meter.LastGasPoint;
                meter.CurrentBalance -= JieDuanYongQiLiang * meter.CurrentPrice;
                meter.LastGasPoint    = meter.NextSettlementPointGas;

                if (!isChangeMeter)
                {
                    //记录结算记录
                    if (calculateDate == "")
                    {
                        calculateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    }
                    BillRecord record = new BillRecord()
                    {
                        UserID = meter.UserID, MeterNo = meter.Mac
                    };
                    record.RecordDate     = calculateDate;
                    record.BillID         = meter.BillID;
                    record.BillRecordType = BillRecordType.阶梯点结算记录;

                    record.EndPoint = meter.NextSettlementPointGas;
                    if (meter.IsPricing)
                    {
                        record.BeginPoint = meter.TiaoJiaPointGas;
                        meter.IsPricing   = false;
                    }
                    else
                    {
                        record.BeginPoint = meter.NextSettlementPointGas - gas[meter.CurrentLadder - 1];
                    }
                    record.Gas     = record.EndPoint - record.BeginPoint;
                    record.Price   = meter.CurrentPrice;
                    record.Amount  = record.Gas * record.Price;
                    record.Balance = meter.CurrentBalance;
                    record.Ladder  = meter.CurrentLadder;

                    new M_BillRecordService().AddBillRecord(record);
                }

                if (meter.CurrentLadder < meter.Ladder)
                {
                    meter.CurrentLadder++;
                }

                meter.CurrentPrice = prices[meter.CurrentLadder - 1];
                //重新设置下一个结算点
                if (meter.CurrentLadder == meter.Ladder)
                {
                    //已到达最大阶梯
                    meter.NextSettlementPointGas = -1;
                }
                else
                {
                    meter.NextSettlementPointGas += gas[meter.CurrentLadder - 1];
                }
                goto ReCalulate;
            }
            else
            {
                //未到达结算点或已超过最后阶梯
                meter.CurrentBalance -= JieDuanYongQiLiang * meter.CurrentPrice;
                meter.LastGasPoint    = meter.TotalAmount;
            }

            return(meter);
        }
Esempio n. 22
0
        /// <summary>
        /// 进行计费汇算,本次会算值作为是否校准的依据,如需要校准,则返回true
        /// </summary>
        /// <param name="meter"></param>
        /// <param name="dataItem"></param>
        /// <returns></returns>
        public bool Calculate(Meter meter, SubmitData dataItem, SubmitResult returnResult)
        {
            #region

            /*
             * //计算当前阶段用气量
             * decimal JieDuanYongQiLiang = dataItem.LJGas - meter.LastTotal;// dataItem.LastLJGas;
             * decimal[] prices = new decimal[5];
             * prices[0] = meter.Price1;
             * prices[1] = meter.Price2;
             * prices[2] = meter.Price3;
             * prices[3] = meter.Price4;
             * prices[4] = meter.Price5;
             * decimal[] gas = new decimal[4];
             * gas[0] = meter.Gas1;
             * gas[1] = meter.Gas2;
             * gas[2] = meter.Gas3;
             * gas[3] = meter.Gas4;
             * decimal currentPirce = meter.Price1;
             * decimal currentGas = meter.Gas1;
             * decimal amount = meter.LastSettlementAmount;
             *
             * decimal[] fees = new decimal[5];
             * decimal[] usedGas = new decimal[5];
             * if (meter.IsUsedLadder)
             * {
             *  //启用了阶梯价
             *  int iLadder = 1;
             *  while (iLadder < meter.Ladder)
             *  {
             *      currentPirce = prices[iLadder - 1];
             *      currentGas = gas[iLadder - 1];
             *      if (JieDuanYongQiLiang > currentGas)
             *      {
             *          //当前阶段总用气量大于当前阶梯用气量
             *          fees[iLadder - 1] = currentGas * currentPirce;
             *          usedGas[iLadder - 1] = currentGas;
             *
             *          amount -= fees[iLadder - 1];
             *          JieDuanYongQiLiang -= currentGas;
             *          iLadder++;
             *      }
             *      else if (JieDuanYongQiLiang > 0)
             *      {
             *          fees[iLadder - 1] = JieDuanYongQiLiang * currentPirce;
             *          usedGas[iLadder - 1] = JieDuanYongQiLiang;
             *
             *          amount -= fees[iLadder - 1];
             *          JieDuanYongQiLiang = 0;
             *          iLadder++;
             *          break;
             *      }
             *      else
             *      {
             *          iLadder++;
             *          break;
             *      }
             *  }
             *  if (JieDuanYongQiLiang > 0)
             *  {
             *      //计算最后一个阶梯
             *      currentPirce = prices[iLadder - 1];
             *
             *      fees[iLadder - 1] = JieDuanYongQiLiang * currentPirce;
             *      usedGas[iLadder - 1] = JieDuanYongQiLiang;
             *      amount -= fees[iLadder - 1];
             *  }
             * }
             * else
             * {
             *  //未使用阶梯价
             *  amount -= JieDuanYongQiLiang * currentPirce;
             *  fees[0] = JieDuanYongQiLiang * currentPirce;
             *  usedGas[0] = JieDuanYongQiLiang;
             * }
             */
            #endregion
            if (meter.BillID == null)
            {
                meter.CreateBillID();
            }
            decimal amount = CalculateGasFee(meter, dataItem);

            //判断结算日是否到达
            //判断是否到结算日,该处的功能依赖表必须传输结算日气量数据,且上报的数据必须按时间顺序传输。
            if (meter.Jiange(meter.GetSettlementTimePoint()) >= 0)
            {
                decimal[] gas = new decimal[5];
                gas[0] = meter.Gas1;
                gas[1] = meter.Gas2;
                gas[2] = meter.Gas3;
                gas[3] = meter.Gas4;
                gas[4] = -1;

                //记录结算记录
                BillRecord record = new BillRecord()
                {
                    UserID = meter.UserID, MeterNo = meter.Mac
                };
                record.RecordDate     = dataItem.ReadDate.ToString("yyyy-MM-dd HH:mm:ss");
                record.BillRecordType = BillRecordType.结算点记录;
                record.BillID         = meter.BillID;
                record.Ladder         = meter.CurrentLadder;

                if (meter.NextSettlementPointGas != -1 && dataItem.LJGas < meter.NextSettlementPointGas)
                {
                    record.EndPoint = dataItem.LJGas;
                    if (meter.IsPricing)
                    {
                        record.BeginPoint = meter.TiaoJiaPointGas;
                    }
                    else
                    {
                        record.BeginPoint = meter.NextSettlementPointGas - gas[meter.CurrentLadder - 1];
                    }
                    record.Gas     = record.EndPoint - record.BeginPoint;
                    record.Price   = meter.CurrentPrice;
                    record.Amount  = record.Gas * record.Price;
                    record.Balance = meter.CurrentBalance;
                }
                else if (meter.NextSettlementPointGas != -1 && dataItem.LJGas == meter.NextSettlementPointGas)
                {
                    record.EndPoint = meter.NextSettlementPointGas;
                    if (meter.IsPricing)
                    {
                        record.BeginPoint = meter.TiaoJiaPointGas;
                    }
                    else
                    {
                        record.BeginPoint = meter.NextSettlementPointGas - gas[meter.CurrentLadder - 1];
                    }
                    record.Gas     = record.EndPoint - record.BeginPoint;
                    record.Price   = meter.CurrentPrice;
                    record.Amount  = record.Gas * record.Price;
                    record.Balance = meter.CurrentBalance;
                }
                else
                {
                    //最后一个阶梯
                    record.EndPoint = dataItem.LJGas;
                    if (meter.IsPricing)
                    {
                        record.BeginPoint = meter.TiaoJiaPointGas;
                    }
                    else
                    {
                        record.BeginPoint = meter.LastTotal;
                        for (int i = 0; i < meter.Ladder; i++)
                        {
                            record.BeginPoint += gas[i];
                        }
                    }
                    record.Gas     = record.EndPoint - record.BeginPoint;
                    record.Price   = meter.CurrentPrice;
                    record.Amount  = record.Gas * record.Price;
                    record.Balance = meter.CurrentBalance;
                }
                new M_BillRecordService().AddBillRecord(record);
                meter.IsPricing = false;
                meter.CreateBillID();
                //创建新的账单
                Bill bill = new Bill()
                {
                    BillID = meter.BillID, UserID = meter.UserID, BeginDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")
                };
                new M_BillRecordService().AddBill(bill);

                returnResult.IsReLoadMeter = true;
                //更新结算数据
                if (meter.NextSettlementPointGas != 0 && !String.IsNullOrEmpty(meter.SettlementDateTime))
                {
                    meter.LastTotal = dataItem.LJGas;
                }
                meter.SetNextSettlementDateTime();
                meter.TotalAmount          = dataItem.LJGas;
                meter.LastSettlementAmount = amount;
                meter.CurrentLadder        = 1;
                meter.CurrentPrice         = meter.Price1;

                if (meter.IsUsedLadder && meter.CurrentLadder < meter.Ladder)
                {
                    //设置第1个节点的结算点气量
                    meter.NextSettlementPointGas = meter.LastTotal + gas[meter.CurrentLadder - 1];
                }
                else
                {
                    //下一次结算点气量为无穷大
                    meter.NextSettlementPointGas = -1;
                }
                new TaskManageDA().UpdateMeter(meter);
                //TODO:在此记录阶段用气账单
            }
            //处理调价。
            TiaoJiaDowith(meter, dataItem);

            decimal syMoney = Convert.ToDecimal(dataItem.SYMoney.ToString("0.00"));
            //在此可以定义系统参数,修正精度,默认差值大于1角做修正处理
            if (meter.IsDianHuo && Math.Abs(syMoney - amount) > 0.1m)
            {
                //修正时间、修正原因、 表号、表上传的当前余额、 上次结算日累计气量(4字节),上次结算日剩余金额(4字节),累计购入金额(4字节),当前结算日
                Console.WriteLine("需要修正表计量数据,表余额:{0} ,后台系统余额:{1}", dataItem.SYMoney, amount);
                CorrectRecord correct = new CorrectRecord();
                correct.MeterBalance = syMoney;
                correct.MeterNo      = meter.Mac;
                correct.MeterLastSettleMentDayLJGas = dataItem.LastLJGas;
                correct.MeterLJGas    = dataItem.LJGas;
                correct.MeterLJMoney  = dataItem.LJMoney;
                correct.MeterReadDate = dataItem.ReadDate.ToString("yyyy-MM-dd HH:mm:ss");

                correct.SettlementDay          = (byte)meter.SettlementDay;
                correct.CorrectDate            = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                correct.CorrectReason          = string.Format("表计量数据和后台不一致,表余额误差超出允许范围,表余额:{0} ,后台余额:{1} 差额:{2}", dataItem.SYMoney, amount, Math.Abs(syMoney - amount));
                correct.TotalTopUp             = meter.TotalTopUp;
                correct.SettlementBalance      = amount;
                correct.LastSettlementDayLJGas = meter.LastTotal;
                dataItem.SYMoney = amount;
                Task   _task;
                string result = new CorrectDA().AddCorrentTask(correct, out _task);//记录修正数据和添加修正任务
                if (result == "")
                {
                    returnResult.IsCalibration = true;
                    returnResult.Calibrations.Add(_task);
                }
            }
            return(returnResult.IsCalibration);
        }
        public XElement BillPull(string guid, XElement billPullRequest)
        {
            MFEPMessage <BillsRecord> deserializedResponse = new MFEPMessage <BillsRecord>();
            XElement serializedResponse = null;
            string   fileGuid           = Guid.NewGuid().ToString();

            try
            {
                // Write the request to physical path
                WriteToPhysicalPath(billPullRequest, BillPullRequestPath, fileGuid);
                MFEPMessage <BillInquiryRequestEntity> deserializedRequest = billPullRequest.FromXElement <MFEPMessage <BillInquiryRequestEntity> >();

                deserializedResponse.Header.TimeStamp    = DateTime.Now.ToString("s");
                deserializedResponse.Header.Guid         = guid;
                deserializedResponse.Header.TransmitInfo = new TransmitInfo()
                {
                    SenderCode   = deserializedRequest.Header.TransmitInfo.ReceiverCode,
                    ResponseType = ProcessesCodes.BILPULRS
                };

                deserializedResponse.Header.Result = new Result();
                bool isTestReponse = IsTestReponse;
                if (!isTestReponse)
                {
                    // Verifying
                    if (EnableSecuity)
                    {
                        if (deserializedRequest == null || deserializedRequest.Footer.Security == null || deserializedRequest.Footer.Security.Signature == null || string.IsNullOrWhiteSpace(deserializedRequest.Footer.Security.Signature.Trim()))
                        {
                            Result result_1 = new Result();
                            result_1.ErrorCode = (int)ServiceErrors.InvalidSignature;
                            result_1.ErrorDesc = ServiceErrors.InvalidSignature.ToString();
                            result_1.Severity  = Severity.Error;
                            deserializedResponse.Header.Result = result_1;
                            serializedResponse = deserializedResponse.ToXElement <MFEPMessage <BillsRecord> >();
                            // Write the request to physical path
                            WriteToPhysicalPath(serializedResponse, BillPullResponsePath, fileGuid);

                            return(serializedResponse);
                        }
                        else
                        {
                            VerifyMode verifyMode = VerifyMode.WithFormat;
                            if (SecurityMode.Equals("WithOutFormat", StringComparison.CurrentCultureIgnoreCase))
                            {
                                verifyMode = VerifyMode.WithOutFormat;
                            }
                            Collection <string> xPath = new Collection <string> {
                                XPath
                            };
                            bool verifiedSuccessfully = CertificateManager.VerifyMessageSignature(deserializedRequest.ToXElement <MFEPMessage <BillInquiryRequestEntity> >(), xPath, deserializedRequest.Footer.Security.Signature, BillerCertificateSerialNumber, verifyMode);
                            if (!verifiedSuccessfully)
                            {
                                Result result_2 = new Result();
                                result_2.ErrorCode = (int)ServiceErrors.InvalidSignature;
                                result_2.ErrorDesc = ServiceErrors.InvalidSignature.ToString();
                                result_2.Severity  = Severity.Error;
                                deserializedResponse.Header.Result = result_2;
                                serializedResponse = deserializedResponse.ToXElement <MFEPMessage <BillsRecord> >();

                                WriteToPhysicalPath(serializedResponse, BillPullResponsePath, fileGuid);

                                return(serializedResponse);
                            }
                        }


                        if (deserializedRequest.Header.TransmitInfo.SenderCode != MFEPCode)
                        {
                            Result result_3 = new Result();
                            result_3.ErrorCode = (int)ServiceErrors.InvalidSenderCode;
                            result_3.ErrorDesc = ServiceErrors.InvalidSenderCode.ToString();
                            result_3.Severity  = Severity.Error;
                            deserializedResponse.Header.Result = result_3;
                            serializedResponse = deserializedResponse.ToXElement <MFEPMessage <BillsRecord> >();
                            // Write the request to physical path
                            WriteToPhysicalPath(serializedResponse, BillPullResponsePath, fileGuid);
                            return(serializedResponse);
                        }

                        // Validate Biller code
                        if (deserializedRequest.Header.TransmitInfo.ReceiverCode != BillerCode)
                        {
                            Result result_4 = new Result();
                            result_4.ErrorCode = (int)ServiceErrors.UnsuccessfulBillPullRequest;
                            result_4.ErrorDesc = ServiceErrors.UnsuccessfulBillPullRequest.ToString();
                            result_4.Severity  = Severity.Error;
                            deserializedResponse.Header.Result = result_4;
                            serializedResponse = deserializedResponse.ToXElement <MFEPMessage <BillsRecord> >();
                            // Write the request to physical path
                            WriteToPhysicalPath(serializedResponse, BillPullResponsePath, fileGuid);

                            return(serializedResponse);
                        }

                        // Validate Service Type
                        if (!ServiceType.Equals(deserializedRequest.Body.ServiceType, StringComparison.CurrentCultureIgnoreCase))
                        {
                            Result result_5 = new Result();
                            result_5.ErrorCode = (int)ServiceErrors.UnrecognizedServiceType;
                            result_5.ErrorDesc = ServiceErrors.UnrecognizedServiceType.ToString();
                            result_5.Severity  = Severity.Error;
                            deserializedResponse.Header.Result = result_5;
                            serializedResponse = deserializedResponse.ToXElement <MFEPMessage <BillsRecord> >();
                            // Write the request to physical path
                            WriteToPhysicalPath(serializedResponse, BillPullResponsePath, fileGuid);


                            return(serializedResponse);
                        }

                        // Get Bill and generate the response
                        DAL        dal        = new DAL();
                        BillRecord billRecord = dal.GetBillInfo(deserializedRequest.Body.AccountInfo.BillNumber, deserializedRequest.Body.AccountInfo.BillingNumber, deserializedRequest.Body.ServiceType);
                        if (billRecord != null)
                        {
                            billRecord.IssueDate      = billRecord.IssueDate.Value.AddMinutes(TimeDifference);
                            billRecord.DueDate        = billRecord.DueDate.Value.AddMinutes(TimeDifference);
                            deserializedResponse.Body = new BillsRecord()
                            {
                                RecCount = 1
                            };
                            deserializedResponse.Body.BillRecords.Add(billRecord);
                        }
                        else
                        {
                            deserializedResponse.Body = new BillsRecord()
                            {
                                RecCount = 0, BillRecords = null
                            };
                        }
                        // Sign the response
                        if (EnableSecuity)
                        {
                            SignMode signMode = SignMode.WithFormat;
                            if (SecurityMode.Equals("WithOutFormat", StringComparison.CurrentCultureIgnoreCase))
                            {
                                signMode = SignMode.WithOutFormat;
                            }
                            Collection <string> xPath = new Collection <string> {
                                XPath
                            };
                            deserializedResponse.Footer = new MFEPFooter();
                            deserializedResponse.Footer.Security.Signature = CertificateManager.SignMessage(deserializedResponse.ToXElement <MFEPMessage <BillsRecord> >(), xPath, BillerCertificateSerialNumber, signMode);
                        }
                        else
                        {
                            SignMode signMode = SignMode.WithFormat;
                            if (SecurityMode.Equals("WithOutFormat", StringComparison.CurrentCultureIgnoreCase))
                            {
                                signMode = SignMode.WithOutFormat;
                            }
                            Collection <string> xPath = new Collection <string> {
                                XPath
                            };
                            deserializedResponse.Footer = new MFEPFooter();
                            deserializedResponse.Footer.Security.Signature = CertificateManager.SignMessage(deserializedResponse.ToXElement <MFEPMessage <BillsRecord> >(), xPath, BillerCertificateSerialNumber, signMode);
                        }
                        serializedResponse = deserializedResponse.ToXElement <MFEPMessage <BillsRecord> >();
                        // Write the request to physical path
                        WriteToPhysicalPath(serializedResponse, BillPullResponsePath, fileGuid);


                        return(serializedResponse);
                    }



                    // Sign the response
                    return(GenerateAutoResponse(guid, billPullRequest));

                    /* serializedResponse = deserializedResponse.ToXElement<MFEPMessage<BillsRecord>>();
                     * // Write the request to physical path
                     * WriteToPhysicalPath(serializedResponse, BillPullResponsePath, fileGuid);
                     *
                     */
                    /*return serializedResponse;*/
                }
                else
                {
                    return(GenerateAutoResponse(guid, billPullRequest));
                }
            }
            catch (Exception exception)
            {
                string ex = exception.Message + "\n" + exception.StackTrace;
                WriteException(ex, ExceptionPath);
                Result result = new Result();
                result.ErrorCode = (int)ServiceErrors.InternalError;
                result.ErrorDesc = ServiceErrors.InternalError.ToString();
                result.Severity  = Severity.Error;
                deserializedResponse.Header.Result = result;
                return(deserializedResponse.ToXElement <MFEPMessage <BillsRecord> >());
            }
        }