Ejemplo n.º 1
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);
    }