Esempio n. 1
0
    public PaymentRecord getcustomerPaymentRecordByRefCheck(string ref_check)
    {
        SQL = "select * from customer_payment where elt_account_number = " + elt_account_number + " and ref_no='" + ref_check + "'";
        DataTable      dt   = new DataTable();
        SqlDataAdapter ad   = new SqlDataAdapter(SQL, Con);
        PaymentRecord  PRec = new PaymentRecord();

        PRec.payment_no = 0;
        GeneralUtility       gUtil  = new GeneralUtility();
        PaymentDetailManager pdMger = new PaymentDetailManager(elt_account_number);

        ad.Fill(dt);
        if (dt.Rows.Count > 0)
        {
            try
            {
                gUtil.removeNull(ref dt);
                PRec.accounts_receivable = Decimal.Parse(dt.Rows[0]["accounts_receivable"].ToString());
                PRec.added_amt           = Decimal.Parse(dt.Rows[0]["added_amt"].ToString());
                PRec.balance             = Decimal.Parse(dt.Rows[0]["balance"].ToString());
                PRec.branch           = dt.Rows[0]["branch"].ToString();
                PRec.customer_name    = dt.Rows[0]["customer_name"].ToString();
                PRec.customer_number  = Int32.Parse((dt.Rows[0]["customer_number"].ToString()));
                PRec.deposit_to       = Int32.Parse(dt.Rows[0]["deposit_to"].ToString());
                PRec.existing_credits = Decimal.Parse(dt.Rows[0]["existing_credits"].ToString());
                PRec.is_org_merged    = dt.Rows[0]["is_org_merged"].ToString();
                PRec.payment_date     = dt.Rows[0]["payment_date"].ToString();
                PRec.payment_no       = Int32.Parse((dt.Rows[0]["payment_no"].ToString()));
                PRec.pmt_method       = dt.Rows[0]["pmt_method"].ToString();
                PRec.received_amt     = Decimal.Parse(dt.Rows[0]["received_amt"].ToString());
                //PRec.PAY
                PRec.ref_no            = dt.Rows[0]["ref_no"].ToString();
                PRec.unapplied_amt     = Decimal.Parse(dt.Rows[0]["unapplied_amt"].ToString());
                PRec.PaymentDetailList = pdMger.getPaymentDetailList(PRec.payment_no);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
        return(PRec);
    }
Esempio n. 2
0
    public bool CancelPayment(PaymentRecord pRec, string tran_type, string is_credit_back)
    {
        Decimal   totalPayment = 0;
        bool      return_val   = false;
        int       payment_no   = pRec.payment_no;
        ArrayList pdList       = pdMgr.getPaymentDetailList(payment_no);
        //Get invoice list from payment detail

        ArrayList IRecList = new ArrayList();

        for (int i = 0; i < pdList.Count; i++)
        {
            int           invoice_no = ((PaymentDetailRecord)pdList[i]).invoice_no;
            InvoiceRecord IRec       = ivMgr.getInvoiceRecord(invoice_no);
            IRec.amount_paid -= ((PaymentDetailRecord)pdList[i]).payment;

            totalPayment += ((PaymentDetailRecord)pdList[i]).payment;

            IRec.balance += ((PaymentDetailRecord)pdList[i]).payment;

            if (IRec.amount_charged == IRec.balance)
            {
                IRec.lock_ar = "N";
            }
            //ivRec.pmt_method meaningless
            IRec.pay_status = "A";
            IRecList.Add(IRec);
        }

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

        Cmd.Transaction = trans;

        try
        {
            //UPDATE INVOICE LIST

            for (int i = 0; i < IRecList.Count; i++)
            {
                InvoiceRecord ivRec = (InvoiceRecord)IRecList[i];
                SQL  = "update invoice set ";
                SQL += "amount_paid= '" + ivRec.amount_paid + "'  ,";
                SQL += "balance= '" + ivRec.balance + "'  ,";
                SQL += "deposit_to= '" + ivRec.deposit_to + "'  ,";

                if (ivRec.amount_paid == 0)//WHEN NOTHING PAID
                {
                    SQL += "lock_ar= 'N'  ,";
                    SQL += "pay_status= 'A'  ,";
                }
                else if (ivRec.amount_paid == ivRec.amount_charged)//WHEN EVERYTHING'S PAID
                {
                    SQL += "lock_ar= 'Y'  ,";
                    SQL += "pay_status= 'p'  ,";
                }
                else//WHEN PARTIALLY PAID
                {
                    SQL += "lock_ar= 'Y'  ,";
                    SQL += "pay_status= 'A'  ,";
                }
                SQL += "pmt_method= '" + ivRec.pmt_method + "'";
                SQL += " WHERE elt_account_number = " + elt_account_number + " and invoice_no=" + ivRec.Invoice_no;

                Cmd.CommandText = SQL;
                Cmd.ExecuteNonQuery();
            }
            //DELETE PAYMENT DETAIL LIST
            SQL  = "DELETE FROM customer_payment_detail WHERE elt_account_number =";
            SQL += elt_account_number + " and payment_no="
                   + payment_no;
            Cmd.CommandText = SQL;
            Cmd.ExecuteNonQuery();
            //DELETE AAJ ENTRIES
            SQL = "Delete  FROM all_accounts_journal WHERE elt_account_number = "
                  + elt_account_number + " AND tran_num = " + payment_no + " AND tran_type = '" + tran_type + "'";
            Cmd.CommandText = SQL;
            Cmd.ExecuteNonQuery();
            //DELETE PAYMENT
            SQL             = "delete  from customer_payment where elt_account_number = " + elt_account_number + " and payment_no=" + payment_no;
            Cmd.CommandText = SQL;
            Cmd.ExecuteNonQuery();

            if (is_credit_back == "Y")
            {
                SQL             = "INSERT INTO [customer_credit_info] ";
                SQL            += "(elt_account_number, ";
                SQL            += "customer_no,";
                SQL            += "tran_date,";
                SQL            += "memo,";
                SQL            += "credit)";
                SQL            += "VALUES";
                SQL            += "('" + elt_account_number;
                SQL            += "','" + pRec.customer_number;
                SQL            += "','" + DateTime.Today.ToShortDateString();
                SQL            += "','" + "Refund From Customer Payment";
                SQL            += "','" + totalPayment;
                SQL            += "')";
                Cmd.CommandText = SQL;
                Cmd.ExecuteNonQuery();
            }

            trans.Commit();
        }
        catch (Exception ex)
        {
            trans.Rollback();
            throw ex;
        }
        finally
        {
            Con.Close();
        }
        return(return_val);
    }