Beispiel #1
0
        private void getTaxDetails(List<invoiceoutdetail> iodList)
        {
            try
            {
                double quantity = 0;
                double price = 0;
                double cost = 0.0;
                productvalue = 0.0;
                taxvalue = 0.0;
                string strtaxCode = "";
                //clear tax details table
                TaxDetailsTable.Rows.Clear();
                foreach (invoiceoutdetail iod in iodList)
                {
                    quantity = iod.Quantity;
                    price = iod.Price;
                    if (price != 0 && quantity != 0)
                    {
                        cost = Math.Round(quantity * price, 2);
                    }

                    try
                    {
                        strtaxCode = iod.TaxCode;
                    }
                    catch (Exception)
                    {
                        strtaxCode = "";
                    }
                    System.Data.DataTable TaxData = TaxCodeWorkingDB.calculateTax(strtaxCode, cost);
                    double ttax1 = 0.0;
                    double ttax2 = 0.0;
                    string strTax = "";
                    for (int j = 0; j < TaxData.Rows.Count; j++)
                    {
                        string tstr = "";
                        try
                        {
                            tstr = TaxData.Rows[j][7].ToString().Trim().Substring(0, TaxData.Rows[j][7].ToString().Trim().IndexOf('-'));
                            if (!(tstr.Length == 0 && tstr.Equals("Dummy")))
                            {
                                ttax1 = Convert.ToDouble(TaxData.Rows[j][6]);
                                string a = Convert.ToString(TaxData.Rows[j][1]);
                                string b = Convert.ToString(TaxData.Rows[j][6]);
                                string c = Convert.ToString(TaxData.Rows[j][7]);
                                strTax = strTax + tstr + "-" +
                                    Convert.ToString(TaxData.Rows[j][6]) + "\n";
                                int taxcodefound = 0;
                                for (int k = 0; k < (TaxDetailsTable.Rows.Count); k++)
                                {
                                    if (TaxDetailsTable.Rows[k][0].ToString().Trim().Equals(tstr))
                                    {
                                        TaxDetailsTable.Rows[k][1] = Convert.ToDouble(TaxDetailsTable.Rows[k][1]) +
                                            Convert.ToDouble(TaxData.Rows[j][6]);
                                        taxcodefound = 1;
                                    }
                                }
                                if (taxcodefound == 0)
                                {
                                    TaxDetailsTable.Rows.Add();
                                    TaxDetailsTable.Rows[TaxDetailsTable.Rows.Count - 1][0] = tstr;
                                    TaxDetailsTable.Rows[TaxDetailsTable.Rows.Count - 1][1] =
                                       Convert.ToDouble(TaxData.Rows[j][6]);
                                }
                            }
                            else
                            {
                                ttax1 = 0.0;
                            }
                        }
                        catch (Exception ex)
                        {
                            ttax1 = 0.0;
                        }
                        ttax2 = ttax2 + ttax1;
                    }
                }
            }
            catch (Exception ex)
            {

            }
        }
Beispiel #2
0
        private void grdList_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                if (e.RowIndex < 0)
                {
                    return;
                }
                if (e.ColumnIndex == 3)
                {
                    int rowID = e.RowIndex;
                    btnSave.Text            = "Update";
                    txtID.Text              = grdList.Rows[e.RowIndex].Cells[0].Value.ToString();
                    txtDescription.Text     = grdList.Rows[e.RowIndex].Cells[1].Value.ToString();
                    cmbStatus.SelectedIndex = cmbStatus.FindStringExact(grdList.Rows[e.RowIndex].Cells[2].Value.ToString());
                    txtID.Enabled           = false;
                    DataGridViewRow row = grdList.Rows[rowID];
                    //get customer bank details
                    TaxCodeWorkingDB      tcwdb      = new TaxCodeWorkingDB();
                    List <taxcodeworking> tcwDetails = tcwdb.getTaxCodeWorkings(txtID.Text);
                    grdTaxCodeWorking.Rows.Clear();
                    int i = 0;
                    foreach (taxcodeworking tcw in tcwDetails)
                    {
                        if (i == 0)
                        {
                            AddFirstTaxWorkingRow();
                            grdTaxCodeWorking.Rows[i].Cells[6].Value = tcw.Amount;
                            //break;
                        }
                        else
                        {
                            AddTaxWorkingRow();
                            grdTaxCodeWorking.Rows[i].Cells[0].Value = tcw.LineNo;
                            grdTaxCodeWorking.Rows[i].Cells[1].Value = tcw.Description;

                            //DataGridViewComboBoxCell ComboColumn1 = new DataGridViewComboBoxCell();
                            //ComboColumn1.FindStringExact(Main.getStatusString(cust.status));

                            grdTaxCodeWorking.Rows[i].Cells[2].Value = tcw.Operator;
                            if (tcw.OperandLine1 != 0)
                            {
                                grdTaxCodeWorking.Rows[i].Cells[3].Value = tcw.OperandLine1.ToString();
                            }
                            else
                            {
                                grdTaxCodeWorking.Rows[i].Cells[3].Value = null;
                            }
                            if (tcw.OperandLine2 != 0)
                            {
                                grdTaxCodeWorking.Rows[i].Cells[4].Value = tcw.OperandLine2.ToString();
                            }
                            else
                            {
                                grdTaxCodeWorking.Rows[i].Cells[4].Value = null;
                            }
                            if (tcw.OperatorValue != 0)
                            {
                                grdTaxCodeWorking.Rows[i].Cells[5].Value = tcw.OperatorValue;
                            }
                            else
                            {
                                grdTaxCodeWorking.Rows[i].Cells[5].Value = null;
                            }

                            grdTaxCodeWorking.Rows[i].Cells[6].Value = tcw.Amount;
                            grdTaxCodeWorking.Rows[i].Cells[7].Value = tcw.TaxItemName;
                        }
                        i++;
                    }
                    btnSave.Text = "Update";
                    pnlTaxCodeWorking.Visible = true;
                    pnlBottomButtons.Visible  = false;
                    disableBottomButtons();
                }
                //////////TaxCodeWorkingDB tcwdb1 = new TaxCodeWorkingDB();
                //////////tcwdb1.calculateTax(txtID.Text, 25000);
            }
            catch (Exception ex)
            {
                MessageBox.Show(this.ToString() + "-" + System.Reflection.MethodBase.GetCurrentMethod().Name + "() : Error");
            }
        }
Beispiel #3
0
        private System.Data.DataTable taxDetails4Print(List<invoiceoutdetail> IODetails, string documentID)
        {
            int HSNLength = 0;
            System.Data.DataTable dt = new System.Data.DataTable();
            System.Data.DataTable dtTax = new System.Data.DataTable();
            try
            {
                if (documentID == "PRODUCTINVOICE")
                {
                    HSNLength = 4;
                }
                else if (documentID == "SERVICEINVOICE")
                {
                    HSNLength = 6;
                }

                {
                    dt.Columns.Add("HSNCode", typeof(string));
                    dt.Columns.Add("TaxCode", typeof(string));
                    dt.Columns.Add("Amount", typeof(double));
                    dt.Columns.Add("TaxAmount", typeof(double));
                    dt.Columns.Add("TaxItem", typeof(string));
                    dt.Columns.Add("TaxItemPercentage", typeof(double));
                    dt.Columns.Add("TaxItemAmount", typeof(double));
                }
                //fill hsn code wise tax details in dt
                foreach (invoiceoutdetail iod in IODetails)
                {
                    string tstr = iod.TaxDetails;
                    string[] lst1 = tstr.Split('\n');
                    for (int j = 0; j < lst1.Length - 1; j++)
                    {
                        string[] lst2 = lst1[j].Split('-');
                        if (Convert.ToDouble(lst2[1]) > 0)
                        {
                            dt.Rows.Add();
                            dt.Rows[dt.Rows.Count - 1][0] = iod.HSNCode.Substring(0, HSNLength);
                            dt.Rows[dt.Rows.Count - 1][1] = iod.TaxCode;
                            dt.Rows[dt.Rows.Count - 1][2] = iod.Quantity * iod.Price;
                            dt.Rows[dt.Rows.Count - 1][3] = iod.Tax;
                            dt.Rows[dt.Rows.Count - 1][4] = lst2[0];
                            dt.Rows[dt.Rows.Count - 1][5] = iod.HSNCode; //need to replace with percentage
                            dt.Rows[dt.Rows.Count - 1][6] = lst2[1];
                        }
                    }

                }
            }
            catch (Exception ex)
            {
            }

            try
            {
                //fill tax rate for each tax item in dt
                TaxCodeWorkingDB tcwdb = new TaxCodeWorkingDB();
                List<taxcodeworking> tcwDetails = tcwdb.getTaxCodeDetails();
                for (int i = 0; i < (dt.Rows.Count); i++)
                {
                    foreach (taxcodeworking tcwd in tcwDetails)
                    {
                        if (dt.Rows[i][1].ToString() == tcwd.TaxCode && dt.Rows[i][4].ToString() == tcwd.TaxItemName)
                        {
                            dt.Rows[i][5] = tcwd.OperatorValue;
                            break;
                        }
                    }

                }
                //prepare HSN Code wise totals in a new table
                System.Data.DataTable dttotal = new System.Data.DataTable();
                dttotal = dt.Copy();
                dttotal.Clear();

                for (int i = 0; i < (dt.Rows.Count); i++)
                {

                    Boolean fount = false;
                    string tstr1 = dt.Rows[i][0].ToString();
                    string tstr2 = dt.Rows[i][4].ToString();
                    string tstr3 = dt.Rows[i][5].ToString();
                    for (int j = 0; j < (dttotal.Rows.Count); j++)
                    {
                        string tstr4 = dttotal.Rows[j][0].ToString();
                        string tstr5 = dttotal.Rows[j][4].ToString();
                        string tstr6 = dttotal.Rows[j][5].ToString();

                        if (tstr1 == tstr4 && tstr2 == tstr5 && tstr3 == tstr6)
                        {
                            dttotal.Rows[j][2] = Convert.ToDouble(dttotal.Rows[j][2].ToString()) +
                                Convert.ToDouble(dt.Rows[i][2].ToString());
                            dttotal.Rows[j][6] = Convert.ToDouble(dttotal.Rows[j][6].ToString()) +
                                Convert.ToDouble(dt.Rows[i][6].ToString());
                            fount = true;
                        }
                    }
                    if (!fount)
                    {
                        dttotal.ImportRow(dt.Rows[i]);
                    }
                }
                string tstr = "";
                ////for (int i = 0; i < (dttotal.Rows.Count); i++)
                ////{
                ////    tstr = tstr+
                ////        dttotal.Rows[i][0].ToString() + "," +
                ////        dttotal.Rows[i][1].ToString() + "," +
                ////        dttotal.Rows[i][2].ToString() + "," +
                ////        dttotal.Rows[i][3].ToString() + "," +
                ////        dttotal.Rows[i][4].ToString() + "," +
                ////        dttotal.Rows[i][5].ToString() + "," +
                ////        dttotal.Rows[i][6].ToString() + "\n";

                ////}
                ////MessageBox.Show(tstr);
                //create print table
                tstr = "";
                //find distinct tax item in dttotal
                DataTable dtDistinct = dttotal.AsEnumerable().GroupBy(row => row.Field<string>("TaxItem")).Select(group => group.First()).CopyToDataTable();
                ////for (int i = 0; i < (dtDistinct.Rows.Count); i++)
                ////{
                ////    tstr = tstr +
                ////        dtDistinct.Rows[i][0].ToString() + "," +
                ////        dtDistinct.Rows[i][1].ToString() + "," +
                ////        dtDistinct.Rows[i][2].ToString() + "," +
                ////        dtDistinct.Rows[i][3].ToString() + "," +
                ////        dtDistinct.Rows[i][4].ToString() + "," +
                ////        dtDistinct.Rows[i][5].ToString() + "," +
                ////        dtDistinct.Rows[i][6].ToString() + "\n";

                ////}
                ////MessageBox.Show(tstr);

                //create columns in dttax table. dynamically creating the columns for each tax item
                {
                    dtTax.Columns.Add("HSNCode", typeof(string));
                    dtTax.Columns.Add("Amount", typeof(double));
                    for (int i = 0; i < dtDistinct.Rows.Count && i < 3; i++)
                    {
                        dtTax.Columns.Add(dtDistinct.Rows[i][4].ToString(), typeof(string));
                        dtTax.Columns.Add(dtDistinct.Rows[i][4].ToString() + "Amount", typeof(double));
                    }
                    dtTax.Columns.Add("Total", typeof(double));
                }
                //add data in dttax table
                for (int i = 0; i < (dttotal.Rows.Count); i++)
                {
                    Boolean hsnFount = false;
                    string tstr1 = dttotal.Rows[i][0].ToString(); //for domestic
                    int j = 0;
                    for (j = 0; j < (dtTax.Rows.Count); j++)
                    {
                        string tstr2 = dtTax.Rows[j][0].ToString(); //for domestic
                        if (tstr1 == tstr2)
                        {
                            hsnFount = true;
                            break;
                        }
                    }
                    if (!hsnFount)
                    {
                        dtTax.Rows.Add();
                        j = dtTax.Rows.Count - 1;
                        dtTax.Rows[j][0] = tstr1;
                        dtTax.Rows[j][1] = dttotal.Rows[i][2]; ;
                    }
                    string tstr3 = dttotal.Rows[i][4].ToString();
                    string tstr4 = dttotal.Rows[i][4].ToString() + "Amount";
                    try
                    {
                        dtTax.Rows[j][tstr3] = dttotal.Rows[i][5];
                        dtTax.Rows[j][tstr4] = dttotal.Rows[i][6];
                        string t1 = String.IsNullOrEmpty(dtTax.Rows[j]["Total"].ToString()) ? "0" : dtTax.Rows[j]["Total"].ToString();
                        string t2 = String.IsNullOrEmpty(dttotal.Rows[i][6].ToString()) ? "0" : dttotal.Rows[i][6].ToString();
                        double d1 = Convert.ToDouble(t1) + Convert.ToDouble(t2);
                        dtTax.Rows[j]["Total"] = d1;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error creating HSN wise tax summary");
                    }
                }
                tstr = "";
                ////double td1=0, td2=0, td3 = 0;
                ////for (int i = 0; i < (dtTax.Rows.Count); i++)
                ////{
                ////    for (int j=0; j<dtTax.Columns.Count;j++)
                ////    {
                ////        tstr = tstr + dtTax.Rows[i][j].ToString() + ",";
                ////    }
                ////    tstr = tstr+"\n";
                ////    td1 = td1 + Convert.ToDouble(dtTax.Rows[i][1].ToString());
                ////    td2 = td2 + Convert.ToDouble(dtTax.Rows[i][dtTax.Columns.Count-1].ToString());
                ////}

                ////MessageBox.Show(tstr);
                ////MessageBox.Show(td1.ToString());
                ////MessageBox.Show(td2.ToString());
            }
            catch (Exception ex)
            {
                MessageBox.Show("taxDetails4Print() : Error - " + ex.ToString());
            }
            return dtTax;
        }
Beispiel #4
0
        private void createAndUpdateTaxCodeWorking()
        {
            try
            {
                TaxCodeWorkingDB tcwdb = new TaxCodeWorkingDB();
                taxcodeworking   tcw   = new taxcodeworking();

                List <taxcodeworking> tcwDetails = new List <taxcodeworking>();
                for (int i = 0; i < grdTaxCodeWorking.Rows.Count; i++)
                {
                    try
                    {
                        tcw         = new taxcodeworking();
                        tcw.TaxCode = txtID.Text;
                        try
                        {
                            tcw.LineNo = Convert.ToInt32(grdTaxCodeWorking.Rows[i].Cells[0].Value.ToString());
                        }
                        catch (Exception)
                        {
                            tcw.LineNo = -1;
                        }
                        try
                        {
                            tcw.Description = grdTaxCodeWorking.Rows[i].Cells[1].Value.ToString();
                        }
                        catch (Exception)
                        {
                            tcw.Description = null;
                        }
                        try
                        {
                            tcw.Operator = grdTaxCodeWorking.Rows[i].Cells[2].Value.ToString();
                        }
                        catch (Exception)
                        {
                            tcw.Operator = null;
                        }
                        try
                        {
                            tcw.OperandLine1 = Convert.ToInt32(grdTaxCodeWorking.Rows[i].Cells[3].Value.ToString());
                        }
                        catch (Exception)
                        {
                            tcw.OperandLine1 = 0;
                        }
                        try
                        {
                            tcw.OperandLine2 = Convert.ToInt32(grdTaxCodeWorking.Rows[i].Cells[4].Value.ToString());
                        }
                        catch (Exception)
                        {
                            tcw.OperandLine2 = 0;
                        }
                        try
                        {
                            tcw.OperatorValue = Convert.ToDouble(grdTaxCodeWorking.Rows[i].Cells[5].Value.ToString());
                        }
                        catch (Exception)
                        {
                            tcw.OperatorValue = 0;
                        }
                        try
                        {
                            tcw.Amount = Convert.ToDouble(grdTaxCodeWorking.Rows[i].Cells[6].Value.ToString());
                        }
                        catch (Exception)
                        {
                            tcw.Amount = 0;
                        }
                        try
                        {
                            tcw.TaxItemName = grdTaxCodeWorking.Rows[i].Cells[7].Value.ToString();
                        }
                        catch (Exception)
                        {
                            tcw.TaxItemName = null;
                        }
                        tcw.status = 1;
                        tcwDetails.Add(tcw);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("createAndUpdateTaxCodeWorking() : Error creating Tax Code Working");
                        return;
                    }
                }
                /////*TaxCodeWorkingDB*/ customerbankdetailsdb = new CustomerBankDetailsDB();
                if (!tcwdb.updateTaxCodeWorkings(txtID.Text, tcwDetails))
                {
                    MessageBox.Show("createAndUpdateTaxCodeWorking() : Failed to update Tax Code Working. Please check the values");
                }
            }
            catch (Exception)
            {
                MessageBox.Show("createAndUpdateTaxCodeWorking() : Error updating Tax Code Workingt");
            }
        }