Esempio n. 1
0
        private void btn_invoice_Click(object sender, EventArgs e)
        {
            check_on_inv = 1;
            Set_Comboas_Null.Set_Zero_If_Null_Textedit(txt_credit);
            Set_Comboas_Null.Set_Zero_If_Null_Textedit(txt_debit);
            if (Convert.ToDecimal(txt_credit.Text) > 0 || Convert.ToDecimal(txt_debit.Text) > 0)
            {
                //if (dgv_on_invoice.Visible == false)
                {
                    //if (dt_on_invoice.Rows.Count == 0)
                    {
                        if (Convert.ToDecimal(txt_credit.Text) > 0 && Convert.ToDecimal(txt_debit.Text) > 0)
                        {
                            MessageBox.Show("Enter Only 1 Amount Credit/Debit.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            txt_credit.Focus();
                            return;
                        }
                        if (Convert.ToDecimal(txt_credit.Text) > 0)
                        {
                            dt_on_invoice = sp_sqlconnection.get_sp("pur_sale_detail", "qtype=payment_remain_invoice|c_id=" + UserDetail.c_id + "|type=SALE|party=" + cmb_party.Text + "");
                        }
                        else if (Convert.ToDecimal(txt_debit.Text) > 0)
                        {
                            dt_on_invoice = sp_sqlconnection.get_sp("pur_sale_detail", "qtype=payment_remain_invoice|c_id=" + UserDetail.c_id + "|type=PUR|party=" + cmb_party.Text + "");
                        }
                        dgv_on_invoice.DataSource = dt_on_invoice;

                        decimal pay_amount = Convert.ToDecimal(txt_credit.Text);
                        if (Convert.ToDecimal(txt_credit.Text) > 0)
                        {
                            pay_amount = Convert.ToDecimal(txt_credit.Text);
                        }
                        else if (Convert.ToDecimal(txt_debit.Text) > 0)
                        {
                            pay_amount = Convert.ToDecimal(txt_debit.Text);
                        }
                        if (dgv_on_invoice.Rows.Count > 0)
                        {
                            for (int i = 0; i < dgv_on_invoice.Rows.Count; i++)
                            {
                                Set_Comboas_Null.Set_Zero_If_Null_GridCell(dgv_on_invoice, i, "payamt");
                                Set_Comboas_Null.Set_Zero_If_Null_GridCell(dgv_on_invoice, i, "outamt");
                                if (pay_amount > 0)
                                {
                                    if (pay_amount > Convert.ToDecimal(dgv_on_invoice.Rows[i].Cells["outamt"].Value.ToString()))
                                    {
                                        pay_amount = pay_amount - Convert.ToDecimal(dgv_on_invoice.Rows[i].Cells["outamt"].Value.ToString());
                                        dgv_on_invoice.Rows[i].Cells["payamt"].Value = dgv_on_invoice.Rows[i].Cells["outamt"].Value.ToString();
                                    }
                                    else
                                    {
                                        dgv_on_invoice.Rows[i].Cells["payamt"].Value = pay_amount;
                                        dgv_on_invoice.Rows[i].Cells["remamt"].Value = Convert.ToDecimal(dgv_on_invoice.Rows[i].Cells["outamt"].Value.ToString()) - pay_amount;
                                        pay_amount = 0.00M;
                                    }
                                }
                                else
                                {
                                    dgv_on_invoice.Rows[i].Cells["remamt"].Value = Convert.ToDecimal(dgv_on_invoice.Rows[i].Cells["outamt"].Value.ToString());
                                }
                            }
                        }
                        if (pay_amount > 0)
                        {
                            if (dgv_on_invoice.Rows.Count > 0)
                            {
                                for (int i = 0; i < dgv_on_invoice.Rows.Count; i++)
                                {
                                    if (Convert.ToDecimal(dgv_on_invoice.Rows[0].Cells["payamt"].Value.ToString()) > 0)
                                    {
                                        dgv_on_invoice.Rows[i].Cells["cursoramt"].Value = 0 - pay_amount;
                                        break;
                                    }
                                }
                            }
                            //MessageBox.Show("Invoice Outstanding Is Lower than Enter Amount.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                            //return;
                        }
                    }
                }
                //if (dgv_on_invoice.Visible == true)
                //{
                dgv_payment.Visible    = false;
                dgv_on_invoice.Visible = true;
                //}
                //else
                //{
                //    dgv_on_invoice.Visible = true;
                //    dgv_payment.Visible = false;
                //}
            }
            on_invoice_count();
        }
Esempio n. 2
0
        private void btn_save_Click(object sender, EventArgs e)
        {
            if (cmb_main.Text == "")
            {
                MessageBox.Show("Please Select Account.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cmb_main.Focus();
                return;
            }
            if (cmb_party.Text == "")
            {
                MessageBox.Show("Please Select Party.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cmb_party.Focus();
                return;
            }
            if (cmb_main.Text == cmb_party.Text)
            {
                MessageBox.Show("Please Select Another Party.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cmb_party.Focus();
                return;
            }
            if (cmb_payment.Text == "")
            {
                MessageBox.Show("Please Select Payment.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                cmb_payment.Focus();
                return;
            }
            decimal pay_amount = 0.00M;

            for (int i = 0; i < dgv_on_invoice.RowCount; i++)
            {
                if (Convert.ToDecimal(dgv_on_invoice.Rows[i].Cells["payamt"].Value.ToString()) > 0)
                {
                    pay_amount = pay_amount + Convert.ToDecimal(dgv_on_invoice.Rows[i].Cells["payamt"].Value.ToString());
                    if (Convert.ToDecimal(dgv_on_invoice.Rows[i].Cells["cursoramt"].Value.ToString()) < 0)
                    {
                        pay_amount = pay_amount - Convert.ToDecimal(dgv_on_invoice.Rows[i].Cells["cursoramt"].Value.ToString());
                    }
                }
            }
            generate_voucher();
            Set_Comboas_Null.Set_Zero_If_Null_Textedit(txt_credit);
            Set_Comboas_Null.Set_Zero_If_Null_Textedit(txt_debit);
            string  cr_dr = "";
            decimal us    = 0.00M;

            if (Convert.ToDecimal(txt_credit.Text) > 0)
            {
                cr_dr = "CREDIT";
                us    = Convert.ToDecimal(txt_credit.Text);
            }
            else
            {
                cr_dr = "DEBIT";
                us    = Convert.ToDecimal(txt_debit.Text);
            }
            if (check_on_inv == 1)
            {
                //if (us != pay_amount)
                //{
                //    MessageBox.Show("Invoice Amount and Total Amount Not Match.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //    return;
                //}
            }
            if (p_id == "")
            {
                p_id = sp_sqlconnection.dml_sp_id("payment_detail", "qtype=insert|account=" + cmb_main.Text + "|voucher=" + txt_voucher.Text + "|party=" + cmb_party.Text + "|date=" + Convert.ToDateTime(dtp_date.Text).ToString("MM-dd-yyyy") + "|payment_type=" + cmb_payment.Text + "|credit_debit=" + cr_dr + "|currency=USD|usd=" + us + "|rate=1|amount=" + us + "|description=" + txt_description.Text + "|status=0|u_id=" + UserDetail.user_id + "|c_id=" + UserDetail.c_id + "");
                if (p_id != "" && cmb_payment.SelectedIndex == 0)
                {
                    for (int i = 0; i < dgv_on_invoice.RowCount; i++)
                    {
                        Set_Comboas_Null.Set_Zero_If_Null_GridCell(dgv_on_invoice, i, "payamt");
                        Set_Comboas_Null.Set_Zero_If_Null_GridCell(dgv_on_invoice, i, "remamt");
                        Set_Comboas_Null.Set_Zero_If_Null_GridCell(dgv_on_invoice, i, "cursoramt");
                        string inv_no = "";
                        if (Convert.ToDecimal(dgv_on_invoice.Rows[i].Cells["payamt"].Value.ToString()) > 0 || Convert.ToDecimal(dgv_on_invoice.Rows[i].Cells["cursoramt"].Value.ToString()) > 0)
                        {
                            string[] inv_  = dgv_on_invoice.Rows[i].Cells["invbillno"].Value.ToString().Split('[');
                            string[] bill_ = inv_[1].Split(']');
                            sp_sqlconnection.dml_sp_id("payment_tran_detail", "qtype=insert|inv_type=" + dgv_on_invoice.Rows[i].Cells["type"].Value.ToString() + "|voucher=" + txt_voucher.Text + "|account=" + cmb_main.Text + "|invoice=" + inv_[0] + "|billno=" + bill_[0] + "|credit_debit=" + cr_dr + "|party=" + cmb_party.Text + "|currency=USD|usd=" + dgv_on_invoice.Rows[i].Cells["payamt"].Value.ToString() + "|rate=1|amount=" + dgv_on_invoice.Rows[i].Cells["payamt"].Value.ToString() + "|status=0|u_id=" + UserDetail.user_id + "|c_id=" + UserDetail.c_id + "");
                            sp_sqlconnection.dml_sp("pur_sale_detail", "qtype=update_payment|c_id=" + UserDetail.c_id + "|inv_type=" + dgv_on_invoice.Rows[i].Cells["type"].Value.ToString() + "|inv_no=" + inv_[0] + "|remain_amount_$=" + dgv_on_invoice.Rows[i].Cells["remamt"].Value.ToString() + "|cursor_amount_$=" + dgv_on_invoice.Rows[i].Cells["cursoramt"].Value.ToString() + "");
                        }
                    }
                }
                check_on_inv = 0;
                MessageBox.Show("Data Successfully Save", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            reset();
        }