public override void save_button_Click(object sender, EventArgs e)
        {
            try
            {
                if (shop_comboBox_salesreturn.SelectedIndex == -1 || customer_comboBox_salesreturn.SelectedIndex == -1 || sales_invoice_comboBox_salesreturn.SelectedIndex == -1 || total_amount_textBox_salesreturn.Text == "" || amount_paid_textBox_salesreturn.Text == "" || remaining_amount_textBox_salesreturn.Text == "" || amount_to_return_textBox_salesreturn.Text == "" || dateTimePicker_salesreturn.Text == "")
                {
                    throw new Exception("Please enter/select a record.");
                }
                else
                {
                    double debit = 0, credit = 0, bal = 0;

                    using (TransactionScope sc = new TransactionScope())
                    {
                        Hashtable ht = new Hashtable();

                        ht.Add("@salesinvoiceID", Convert.ToInt32(sales_invoice_comboBox_salesreturn.SelectedValue.ToString()));

                        ht.Add("@amount", Convert.ToInt32(amount_to_return_textBox_salesreturn.Text));

                        ht.Add("@date", dateTimePicker_salesreturn.Value);

                        if (LoginCodeClass.isAdmin)
                        {
                            throw new Exception("Admin cannot perfom current task.");
                        }
                        else
                        {
                            ht.Add("@userID", LoginCodeClass.USERID);
                        }

                        if (SQL_TASKS.insert_update_delete("st_insertSALESRETURN", ht) > 0)
                        {
                            Hashtable loadht = new Hashtable();

                            loadht.Add("@custID", Convert.ToInt32(customer_comboBox_salesreturn.SelectedValue.ToString()));

                            loadht.Add("@shopID", Convert.ToInt32(shop_comboBox_salesreturn.SelectedValue.ToString()));

                            double[] dd = SQL_TASKS.LoadLastBalance("st_getLASTBALANCES", loadht);

                            bal = dd[0];         //customer balance

                            debit = 0;

                            credit = Convert.ToDouble(amount_to_return_textBox_salesreturn.Text);

                            bal += debit - credit;

                            Hashtable ht2 = new Hashtable();

                            Int64 salesinvoiceID = Convert.ToInt64(sales_invoice_comboBox_salesreturn.SelectedValue.ToString());

                            DataRowView drvcustomer = customer_comboBox_salesreturn.SelectedItem as DataRowView;

                            DataRowView drvshop = shop_comboBox_salesreturn.SelectedItem as DataRowView;

                            DataRowView drvsalesinvoice = sales_invoice_comboBox_salesreturn.SelectedItem as DataRowView;

                            ht2.Add("@custID", Convert.ToInt32(customer_comboBox_salesreturn.SelectedValue.ToString()));

                            ht2.Add("@desc", drvcustomer[1].ToString() + " has return the goods worth Rs. " + amount_to_return_textBox_salesreturn.Text + " on bill # " + drvsalesinvoice[1].ToString() + " to " + drvshop[1].ToString() + " shop ");

                            ht2.Add("@debit", debit);

                            ht2.Add("@credit", credit);

                            ht2.Add("@balance", bal);

                            ht2.Add("@date", dateTimePicker_salesreturn.Value);

                            ht2.Add("@salesinvoiceid", salesinvoiceID);

                            SQL_TASKS.insert_update_delete("st_insertCUSTOMERLEDGER", ht2);

                            bal = dd[1];         //shop balance

                            debit = Convert.ToDouble(amount_to_return_textBox_salesreturn.Text);

                            credit = 0;

                            bal += debit - credit;

                            Hashtable ht3 = new Hashtable();

                            ht3.Add("@shopID", Convert.ToInt32(shop_comboBox_salesreturn.SelectedValue.ToString()));

                            ht3.Add("@desc", drvshop[1].ToString() + " has received Rs. " + amount_to_return_textBox_salesreturn.Text + " as returned from customer " + drvcustomer[1].ToString() + " on bill # " + drvsalesinvoice[1].ToString());

                            ht3.Add("@debit", debit);

                            ht3.Add("@credit", credit);

                            ht3.Add("@balance", bal);

                            ht3.Add("@date", dateTimePicker_salesreturn.Value);

                            ht3.Add("@salesinvoiceid", salesinvoiceID);

                            SQL_TASKS.insert_update_delete("insertVENDORLEDGER", ht3);

                            CodingSourceClass.ShowMsg("Record added successfully into the system.", "Success");

                            CodingSourceClass.disable_reset(left_panel);

                            LoadSalesReturn();

                            sc.Complete();
                        }
                        else
                        {
                            throw new Exception("Unable to save record.");
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CodingSourceClass.ShowMsg(ex.Message, "Error");

                CodingSourceClass.disable_reset(left_panel); enable_crud_buttons();
            }
        }
예제 #2
0
        public override void save_button_Click(object sender, EventArgs e)
        {
            try
            {
                if (shop_comboBox_payments.SelectedIndex == -1 || customer_comboBox_payments.SelectedIndex == -1 || sales_invoice_comboBox_payments.SelectedIndex == -1 || total_amount_textBox_payments.Text == "" || amount_paid_textBox_payments.Text == "" || remaining_amount_textBox_payments.Text == "" || amount_to_pay_textBox_payments.Text == "" || (cash_radioButton_sales_invoice.Checked == false && cheque_radioButton.Checked == false))
                {
                    throw new Exception("Please enter/select a record.");
                }
                else if ((shop_comboBox_payments.SelectedIndex != -1 && customer_comboBox_payments.SelectedIndex != -1 && sales_invoice_comboBox_payments.SelectedIndex != -1 && total_amount_textBox_payments.Text != "" && amount_paid_textBox_payments.Text != "" && remaining_amount_textBox_payments.Text != "" && amount_to_pay_textBox_payments.Text != "" && cheque_radioButton.Checked == true) && (clearing_date_dateTimePicker.Text == "" || bank_and_branch_textBox.Text == "" || cheque_no_textBox.Text == ""))
                {
                    throw new Exception("Please enter/select a record.");
                }
                else
                {
                    if (Convert.ToDouble(amount_to_pay_textBox_payments.Text) > Convert.ToDouble(total_amount_textBox_payments.Text))
                    {
                        throw new Exception("Amount to pay cannot be greater than total amount.");
                    }
                    else
                    {
                        double debit = 0, credit = 0, bal = 0;

                        using (TransactionScope sc = new TransactionScope())
                        {
                            Hashtable ht = new Hashtable();

                            if (cash_radioButton_sales_invoice.Checked == true)
                            {
                                ht.Add("@salesinvoiceid", Convert.ToInt32(sales_invoice_comboBox_payments.SelectedValue.ToString()));

                                ht.Add("@amount", Convert.ToInt32(amount_to_pay_textBox_payments.Text));

                                ht.Add("@date", dateTimePicker_payments.Value);

                                if (LoginCodeClass.isAdmin)
                                {
                                    throw new Exception("Admin cannot enter payments.");
                                }
                                else
                                {
                                    ht.Add("@userID", LoginCodeClass.USERID);
                                }

                                SQL_TASKS.insert_update_delete("st_insertPAYMENTSwrtCASH", ht);
                            }
                            else
                            {
                                ht.Add("@salesinvoiceid", Convert.ToInt32(sales_invoice_comboBox_payments.SelectedValue.ToString()));

                                ht.Add("@amount", Convert.ToInt32(amount_to_pay_textBox_payments.Text));

                                ht.Add("@date", dateTimePicker_payments.Value);

                                if (LoginCodeClass.isAdmin)
                                {
                                    ht.Add("@userID", LoginCodeClass.idOFadmin);
                                }
                                else
                                {
                                    ht.Add("@userID", LoginCodeClass.USERID);
                                }

                                ht.Add("@cheque", cheque_no_textBox.Text);

                                ht.Add("@bank", bank_and_branch_textBox.Text);

                                ht.Add("@clearing", clearing_date_dateTimePicker.Value);

                                SQL_TASKS.insert_update_delete("st_insertPAYMENTSwrtCHEQUE", ht);
                            }

                            Hashtable loadht = new Hashtable();

                            loadht.Add("@custID", Convert.ToInt32(customer_comboBox_payments.SelectedValue.ToString()));

                            loadht.Add("@shopID", Convert.ToInt32(shop_comboBox_payments.SelectedValue.ToString()));

                            double[] dd = SQL_TASKS.LoadLastBalance("st_getLASTBALANCES", loadht);

                            bal = dd[0];     //customer balance

                            debit = 0;

                            credit = Convert.ToDouble(amount_to_pay_textBox_payments.Text);

                            bal += debit - credit;

                            Hashtable ht2 = new Hashtable();

                            Int64 salesinvoiceID = Convert.ToInt64(sales_invoice_comboBox_payments.SelectedValue.ToString());

                            DataRowView drvcustomer = customer_comboBox_payments.SelectedItem as DataRowView;

                            DataRowView drvshop = shop_comboBox_payments.SelectedItem as DataRowView;

                            DataRowView drvsalesinvoice = sales_invoice_comboBox_payments.SelectedItem as DataRowView;

                            ht2.Add("@custID", Convert.ToInt32(customer_comboBox_payments.SelectedValue.ToString()));

                            ht2.Add("@desc", drvcustomer[1].ToString() + " has done the payment of Rs. " + amount_to_pay_textBox_payments.Text + " on bill # " + drvsalesinvoice[1].ToString() + " to " + drvshop[1].ToString());

                            ht2.Add("@debit", debit);

                            ht2.Add("@credit", credit);

                            ht2.Add("@balance", bal);

                            ht2.Add("@date", dateTimePicker_payments.Value);

                            ht2.Add("@salesinvoiceid", salesinvoiceID);

                            SQL_TASKS.insert_update_delete("st_insertCUSTOMERLEDGER", ht2);

                            bal = dd[1];     //shop balance

                            debit = Convert.ToDouble(amount_to_pay_textBox_payments.Text);

                            credit = 0;

                            bal += debit - credit;

                            Hashtable ht3 = new Hashtable();

                            ht3.Add("@shopID", Convert.ToInt32(shop_comboBox_payments.SelectedValue.ToString()));

                            ht3.Add("@desc", drvshop[1].ToString() + " has received Rs. " + amount_to_pay_textBox_payments.Text + " as paid from customer " + drvcustomer[1].ToString() + " on bill # " + drvsalesinvoice[1].ToString());

                            ht3.Add("@debit", debit);

                            ht3.Add("@credit", credit);

                            ht3.Add("@balance", bal);

                            ht3.Add("@date", dateTimePicker_payments.Value);

                            ht3.Add("@salesinvoiceid", salesinvoiceID);

                            SQL_TASKS.insert_update_delete("insertVENDORLEDGER", ht3);

                            Hashtable ht4 = new Hashtable();

                            if (Convert.ToDouble(amount_to_pay_textBox_payments.Text) == Convert.ToDouble(total_amount_textBox_payments.Text))
                            {
                                //complete payment

                                ht4.Add("@status", 2);
                            }
                            else if (Convert.ToDouble(amount_to_pay_textBox_payments.Text) < Convert.ToDouble(total_amount_textBox_payments.Text))
                            {
                                //partial payment

                                ht4.Add("@status", 1);
                            }

                            /*else //if status == 2
                             * {
                             *  ht4.Add("@status", 0);
                             * }*/

                            ht4.Add("@salesinvoiceid", salesinvoiceID);

                            CodingSourceClass.ShowMsg("Record added successfully into the system.", "Success");

                            CodingSourceClass.disable_reset(left_panel);

                            LoadPayments();

                            sc.Complete();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                CodingSourceClass.ShowMsg(ex.Message, "Error");
            }
        }
예제 #3
0
        public override void save_button_Click(object sender, EventArgs e)
        {
            try
            {
                if (shops_comboBox_sales_invoice.SelectedIndex == -1 || customers_comboBox_sales_invoice.SelectedIndex == -1 || order_details_textBox.Text == "" || dateTimePicker_sales_invoice.Text == "" || amount_textBox_sales_invoice.Text == "" || (cash_radioButton_sales_invoice.Checked == false && credit_card_radioButton_sales_invoice.Checked == false))
                {
                    throw new Exception("Please enter/select a record.");
                }
                else
                {
                    //0 is for crash and 1 is for debit

                    Int16?type = cash_radioButton_sales_invoice.Checked ? Convert.ToInt16(0) : Convert.ToInt16(1);

                    if (type != null)
                    {
                        double debit = 0, credit = 0, bal = 0;

                        if (edit == false) //code for save
                        {
                            using (TransactionScope sc = new TransactionScope())
                            {
                                Hashtable ht = new Hashtable();

                                ht.Add("@shopID", Convert.ToInt32(shops_comboBox_sales_invoice.SelectedValue.ToString()));

                                ht.Add("@customerID", Convert.ToInt32(customers_comboBox_sales_invoice.SelectedValue.ToString()));

                                ht.Add("@details", order_details_textBox.Text);

                                ht.Add("@amount", amount_textBox_sales_invoice.Text);

                                ht.Add("@type", type);

                                if (LoginCodeClass.isAdmin)
                                {
                                    throw new Exception("Admin cannot make salesinvoice.");
                                }
                                else
                                {
                                    ht.Add("@userID", LoginCodeClass.USERID);
                                }

                                ht.Add("@billno", bill_no_textBox_salesinvoice.Text);

                                ht.Add("@status", 0);

                                //0 = not paid, 1 = partially paid, 2 = completely paid

                                if (SQL_TASKS.insert_update_delete("st_insertSALESINVOICE", ht) > 0)
                                {
                                    Hashtable loadht = new Hashtable();

                                    loadht.Add("@custID", Convert.ToInt32(customers_comboBox_sales_invoice.SelectedValue.ToString()));

                                    loadht.Add("@shopID", Convert.ToInt32(shops_comboBox_sales_invoice.SelectedValue.ToString()));

                                    double[] dd = SQL_TASKS.LoadLastBalance("st_getLASTBALANCES", loadht);

                                    bal = dd[0]; //customer balance

                                    debit = Convert.ToDouble(amount_textBox_sales_invoice.Text);

                                    credit = 0;

                                    bal += debit - credit;

                                    Hashtable ht2 = new Hashtable();

                                    ht2.Add("@custID", Convert.ToInt32(customers_comboBox_sales_invoice.SelectedValue.ToString()));

                                    ht2.Add("@desc", order_details_textBox.Text);

                                    ht2.Add("@debit", debit);

                                    ht2.Add("@credit", credit);

                                    ht2.Add("@balance", bal);

                                    ht2.Add("@date", dateTimePicker_sales_invoice.Value);

                                    ht2.Add("@salesinvoiceid", salesinvoiceID);

                                    SQL_TASKS.insert_update_delete("st_insertCUSTOMERLEDGER", ht2);

                                    bal = dd[1]; //shop balance

                                    debit = 0;

                                    credit = Convert.ToDouble(amount_textBox_sales_invoice.Text);

                                    bal += debit - credit;

                                    Hashtable ht3 = new Hashtable();

                                    ht3.Add("@shopID", Convert.ToInt32(shops_comboBox_sales_invoice.SelectedValue.ToString()));

                                    ht3.Add("@desc", order_details_textBox.Text);

                                    ht3.Add("@debit", debit);

                                    ht3.Add("@credit", credit);

                                    ht3.Add("@balance", bal);

                                    ht3.Add("@date", dateTimePicker_sales_invoice.Value);

                                    ht3.Add("@salesinvoiceid", salesinvoiceID);

                                    SQL_TASKS.insert_update_delete("insertVENDORLEDGER", ht3);

                                    CodingSourceClass.ShowMsg("Record added successfully into the system.", "Success");

                                    CodingSourceClass.disable_reset(left_panel);

                                    LoadSalesInvoice();

                                    sc.Complete();
                                }
                                else
                                {
                                    throw new Exception("Unable to save record.");
                                }
                            }
                        }
                    }
                    else
                    {
                        throw new Exception("Please fill all fields.");
                    }
                }
            }
            catch (Exception ex)
            {
                CodingSourceClass.ShowMsg(ex.Message, "Error");

                CodingSourceClass.disable_reset(left_panel); enable_crud_buttons();
            }
        }