Beispiel #1
0
        public bool SaveTndnTaxDeclaration(TndnTaxDeclaration declaration)
        {
            int year = declaration.Year;

            TndnTaxDeclaration check = db.TndnTaxDeclarations.FirstOrDefault(m => m.Year == year);

            if (check != null)
            {
                db.TndnTaxDeclarations.Remove(check);
            }
            db.TndnTaxDeclarations.Add(declaration);

            try
            {
                db.SaveChanges();
            }
            catch (Exception)
            {
                return false;
            }

            return true;
        }
Beispiel #2
0
        public int SaveTndnTaxTndnTaxDeclaration(FormCollection form)
        {
            try
            {
                #region Get Data from Form
                string taxYear = form["taxYear"];

                string createDate = form["createDate"];
                string vatAgentOwnerName = form["vatAgentOwnerName"];
                string vatAgentName = form["agentName"];
                string vatAgentTaxCode = form["agentTaxCode"].Replace(",", "");
                string vatAgentNo = form["agentNo"];
                string vatAgentAddress = form["vatAgentAddress"];
                string vatAgentDistrict = form["vatAgentDistrict"];
                string vatAgentProvince = form["vatAgentProvince"];
                string vatAgentPhone = form["vatAgentPhone"];
                string vatAgentFax = form["vatAgentFax"];
                string vatAgentEmail = form["vatAgentEmail"];
                string signName = form["signName"];
                string maxRevenueRatio = form["maxRevenueRatio"];

                string storeOwnerName = form["storeOwnerName"];
                string storeTaxcode = form["storeTaxcode"].Replace(",", "");
                string storeAddress = form["storeAddress"];
                string storeDistrict = form["storeDistrict"];
                string storeProvince = form["storeProvince"];
                string storePhone = form["storePhone"];
                string storeFax = form["storeFax"];
                string storeEmail = form["storeEmail"];

                string value22No = form["value22No"];
                string value22Date = form["value22Date"];

                string valueA1 = form["valueA1"].Replace(".", "");

                string valueB1 = form["valueB1"].Replace(".", "");
                string valueB2 = form["valueB2"].Replace(".", "");
                string valueB3 = form["valueB3"].Replace(".", "");
                string valueB4 = form["valueB4"].Replace(".", "");
                string valueB5 = form["valueB5"].Replace(".", "");
                string valueB6 = form["valueB6"].Replace(".", "");
                string valueB7 = form["valueB7"].Replace(".", "");
                string valueB8 = form["valueB8"].Replace(".", "");
                string valueB9 = form["valueB9"].Replace(".", "");
                string valueB10 = form["valueB10"].Replace(".", "");
                string valueB11 = form["valueB11"].Replace(".", "");
                string valueB12 = form["valueB12"].Replace(".", "");
                string valueB13 = form["valueB13"].Replace(".", "");
                string valueB14 = form["valueB14"].Replace(".", "");

                string valueC1 = form["valueC1"].Replace(".", "");
                string valueC2 = form["valueC2"].Replace(".", "");
                string valueC3 = form["valueC3"].Replace(".", "");
                string valueC3a = form["valueC3a"].Replace(".", "");
                string valueC3b = form["valueC3b"].Replace(".", "");
                string valueC4 = form["valueC4"].Replace(".", "");
                string valueC5 = form["valueC5"].Replace(".", "");
                string valueC6 = form["valueC6"].Replace(".", "");
                string valueC7 = form["valueC7"].Replace(".", "");
                string valueC8 = form["valueC8"].Replace(".", "");
                string valueC9 = form["valueC9"].Replace(".", "");
                string valueC9a = form["valueC9a"].Replace(".", "");
                string valueC10 = form["valueC10"].Replace(".", "");
                string valueC11 = form["valueC11"].Replace(".", "");
                string valueC12 = form["valueC12"].Replace(".", "");
                string valueC13 = form["valueC13"].Replace(".", "");
                string valueC14 = form["valueC14"].Replace(".", "");
                string valueC15 = form["valueC15"].Replace(".", "");
                string valueC16 = form["valueC16"].Replace(".", "");

                string valueD = form["valueD"].Replace(".", "");
                string valueD1 = form["valueD1"].Replace(".", "");
                string valueD2 = form["valueD2"].Replace(".", "");
                string valueD3 = form["valueD3"].Replace(".", "");

                string valueE = form["valueE"].Replace(".", "");
                string valueE1 = form["valueE1"].Replace(".", "");
                string valueE2 = form["valueE2"].Replace(".", "");
                string valueE3 = form["valueE3"].Replace(".", "");

                string valueG = form["valueG"].Replace(".", "");
                string valueG1 = form["valueG1"].Replace(".", "");
                string valueG2 = form["valueG2"].Replace(".", "");
                string valueG3 = form["valueG3"].Replace(".", "");

                string valueH = form["valueH"].Replace(".", "");
                string valueI = form["valueI"].Replace(".", "");

                string valueL1 = form["valueL1"];
                string valueL2Code = form["valueL2Code"];
                string valueL3 = form["valueL3"];
                string valueL4 = form["valueL4"].Replace(".", "");
                string valueL5 = form["valueL5"].Replace(".", "");

                string valueM1DayQuantity = form["valueM1DayQuantity"];
                string valueM1FromDate = form["valueM1FromDate"];
                string valueM1ToDate = form["valueM1ToDate"];
                string valueM2 = form["valueM2"].Replace(".", "");

                string value1 = form["value01"].Replace(".", "");
                string value2 = form["value02"].Replace(".", "");
                string value3 = form["value03"].Replace(".", "");
                string value4 = form["value04"].Replace(".", "");
                string value5 = form["value05"].Replace(".", "");
                string value6 = form["value06"].Replace(".", "");
                string value7 = form["value07"].Replace(".", "");
                string value8 = form["value08"].Replace(".", "");
                string value9 = form["value09"].Replace(".", "");
                string value10 = form["value10"].Replace(".", "");
                string value11 = form["value11"].Replace(".", "");
                string value12 = form["value12"].Replace(".", "");
                string value13 = form["value13"].Replace(".", "");
                string value14 = form["value14"].Replace(".", "");
                string value15 = form["value15"].Replace(".", "");
                string value16 = form["value16"].Replace(".", "");
                string value17 = form["value17"].Replace(".", "");
                string value18 = form["value18"].Replace(".", "");
                string value19 = form["value19"].Replace(".", "");
                #endregion

                #region Create TndnTaxDeclaration Model and Save

                TndnTaxDeclaration tndn = new TndnTaxDeclaration();

                tndn.Year = Convert.ToInt32(taxYear.Trim());
                if (maxRevenueRatio.Trim().Length > 0)
                {
                    tndn.MaxRevenueRatio = Convert.ToInt32(maxRevenueRatio.Trim());
                }
                else
                {
                    tndn.MaxRevenueRatio = 0;
                }

                tndn.StoreOwnerName = storeOwnerName;
                tndn.StoreTaxCode = storeTaxcode;
                tndn.StoreAddress = storeAddress;
                tndn.StoreDistrict = storeDistrict;
                tndn.StoreProvince = storeProvince;
                tndn.StorePhone = storePhone;
                tndn.StoreFax = storeFax;
                tndn.StoreEmail = storeEmail;

                tndn.TaxAgentTaxCode = vatAgentTaxCode;
                tndn.TaxAgentName = vatAgentName;
                tndn.TaxAgentOwnerName = vatAgentOwnerName;
                tndn.TaxAgentNo = vatAgentNo;
                tndn.TaxAgentAddress = vatAgentAddress;
                tndn.TaxAgentDistrict = vatAgentDistrict;
                tndn.TaxAgentProvince = vatAgentProvince;
                tndn.TaxAgentPhone = vatAgentPhone;
                tndn.TaxAgentFax = vatAgentFax;
                tndn.TaxAgentEmail = vatAgentEmail;
                tndn.SignName = signName;
                if (!createDate.Trim().IsEmpty())
                {
                    tndn.CreateDate = DateTime.ParseExact(createDate, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                }

                if (value22No.Trim().Length > 0)
                {
                    tndn.Value22No = Convert.ToInt32(value22No);
                }
                if (!value22Date.Trim().IsEmpty())
                {
                    tndn.Value22Date = DateTime.ParseExact(value22Date, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                }

                tndn.ValueA1 = Convert.ToInt32(valueA1);
                tndn.ValueB1 = Convert.ToInt32(valueB1);
                tndn.ValueB2 = Convert.ToInt32(valueB2);
                tndn.ValueB3 = Convert.ToInt32(valueB3);
                tndn.ValueB4 = Convert.ToInt32(valueB4);
                tndn.ValueB5 = Convert.ToInt32(valueB5);
                tndn.ValueB6 = Convert.ToInt32(valueB6);
                tndn.ValueB7 = Convert.ToInt32(valueB7);
                tndn.ValueB8 = Convert.ToInt32(valueB8);
                tndn.ValueB9 = Convert.ToInt32(valueB9);
                tndn.ValueB10 = Convert.ToInt32(valueB10);
                tndn.ValueB11 = Convert.ToInt32(valueB11);
                tndn.ValueB12 = Convert.ToInt32(valueB12);
                tndn.ValueB13 = Convert.ToInt32(valueB13);
                tndn.ValueB14 = Convert.ToInt32(valueB14);

                tndn.ValueC1 = Convert.ToInt32(valueC1);
                tndn.ValueC2 = Convert.ToInt32(valueC2);
                tndn.ValueC3 = Convert.ToInt32(valueC3);
                tndn.ValueC3a = Convert.ToInt32(valueC3a);
                tndn.ValueC3b = Convert.ToInt32(valueC3b);
                tndn.ValueC4 = Convert.ToInt32(valueC4);
                tndn.ValueC5 = Convert.ToInt32(valueC5);
                tndn.ValueC6 = Convert.ToInt32(valueC6);
                tndn.ValueC7 = Convert.ToInt32(valueC7);
                tndn.ValueC8 = Convert.ToInt32(valueC8);
                tndn.ValueC9 = Convert.ToInt32(valueC9);
                tndn.ValueC9a = Convert.ToInt32(valueC9a);
                tndn.ValueC10 = Convert.ToInt32(valueC10);
                tndn.ValueC11 = Convert.ToInt32(valueC11);
                tndn.ValueC12 = Convert.ToInt32(valueC12);
                tndn.ValueC13 = Convert.ToInt32(valueC13);
                tndn.ValueC14 = Convert.ToInt32(valueC14);
                tndn.ValueC15 = Convert.ToInt32(valueC15);
                tndn.ValueC16 = Convert.ToInt32(valueC16);

                tndn.ValueD = Convert.ToInt32(valueD);
                tndn.ValueD1 = Convert.ToInt32(valueD1);
                tndn.ValueD2 = Convert.ToInt32(valueD2);
                tndn.ValueD3 = Convert.ToInt32(valueD3);

                tndn.ValueE = Convert.ToInt32(valueE);
                tndn.ValueE1 = Convert.ToInt32(valueE1);
                tndn.ValueE2 = Convert.ToInt32(valueE2);
                tndn.ValueE3 = Convert.ToInt32(valueE3);

                tndn.ValueG = Convert.ToInt32(valueG);
                tndn.ValueG1 = Convert.ToInt32(valueG1);
                tndn.ValueG2 = Convert.ToInt32(valueG2);
                tndn.ValueG3 = Convert.ToInt32(valueG3);

                tndn.ValueH = Convert.ToInt32(valueH);
                tndn.ValueI = Convert.ToInt32(valueI);

                if (valueL1 != null && valueL1.Equals("on"))
                {
                    tndn.ValueL1 = true;
                    tndn.ValueL2No = Convert.ToInt32(valueL2Code);
                    tndn.ValueL3 = DateTime.ParseExact(valueL3, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                    tndn.ValueL4 = Convert.ToInt32(valueL4);
                    tndn.ValueL5 = Convert.ToInt32(valueL5);
                }
                else
                {
                    tndn.ValueL1 = false;
                }

                if (!valueM1FromDate.IsEmpty())
                {
                    tndn.ValueM1FromDate = DateTime.ParseExact(valueM1FromDate, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                }

                if (!valueM1ToDate.IsEmpty())
                {
                    tndn.ValueM1ToDate = DateTime.ParseExact(valueM1FromDate, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                }

                tndn.ValueM2 = Convert.ToInt32(valueM2);

                tndn.Value1 = Convert.ToInt32(value1);
                tndn.Value2 = Convert.ToInt32(value2);
                tndn.Value3 = Convert.ToInt32(value3);
                tndn.Value4 = Convert.ToInt32(value4);
                tndn.Value5 = Convert.ToInt32(value5);
                tndn.Value6 = Convert.ToInt32(value6);
                tndn.Value7 = Convert.ToInt32(value7);
                tndn.Value8 = Convert.ToInt32(value8);
                tndn.Value9 = Convert.ToInt32(value9);
                tndn.Value10 = Convert.ToInt32(value10);
                tndn.Value11 = Convert.ToInt32(value11);
                tndn.Value12 = Convert.ToInt32(value12);
                tndn.Value13 = Convert.ToInt32(value13);
                tndn.Value14 = Convert.ToInt32(value14);
                tndn.Value15 = Convert.ToInt32(value15);
                tndn.Value16 = Convert.ToInt32(value16);
                tndn.Value17 = Convert.ToInt32(value17);
                tndn.Value18 = Convert.ToInt32(value18);
                tndn.Value19 = Convert.ToInt32(value19);

                TaxBusiness business = new TaxBusiness();
                return business.SaveTndnTaxDeclaration(tndn) ? 1 : 0;

                #endregion
            }
            catch (Exception)
            {
                return 0;
            }
        }
Beispiel #3
0
        public TndnTaxDeclaration GeTndnTaxDeclaration(int year)
        {
            TndnTaxDeclaration result = db.TndnTaxDeclarations.FirstOrDefault(m => m.Year == year);
            {
                if (result == null)
                {
                    result = new TndnTaxDeclaration();
                    StoreInfo storeInfo = db.StoreInfoes.FirstOrDefault();
                    if (storeInfo != null)
                    {
                        result.StoreOwnerName = storeInfo.OwnerName;
                        result.StoreTaxCode = storeInfo.TaxCode;
                        result.StoreAddress = storeInfo.Address;
                        result.StoreDistrict = storeInfo.District;
                        result.StoreProvince = storeInfo.Province;
                        result.StorePhone = storeInfo.Phonenumber;
                        result.StoreFax = storeInfo.Fax;
                        result.StoreEmail = storeInfo.Email;

                        result.SignName = storeInfo.OwnerName;
                        result.Year = year;
                    }

                    ReportBusiness business = new ReportBusiness();
                    List<sp_GetIncomeYearly_Result> incomeYearly = business.GetIncomeYearlyStore(year, year);

                    var revenue = incomeYearly.ElementAt(0).Revenue;
                    result.Value1 = revenue ?? 0;
                    result.Value2 = 0;
                    result.Value4 = 0;
                    result.Value5 = 0;
                    result.Value6 = 0;
                    result.Value7 = 0;
                    result.Value3 = result.Value4 + result.Value5 + result.Value6 + result.Value7;
                    result.Value8 = 0;

                    var materialExpense = incomeYearly.ElementAt(0).MaterialExpense;
                    result.Value10 = materialExpense ?? 0;

                    List<OtherExpense> value11List =
                        db.OtherExpenses.Where(m => m.Type == 11 && m.OtherExpenseYearTime == year).ToList();
                    result.Value11 = 0;
                    foreach (OtherExpense otherExpense in value11List)
                    {
                        result.Value11 += otherExpense.OtherExpenseAmount;
                    }

                    List<OtherExpense> value12List = db.OtherExpenses.Where(m => m.Type == 12 && m.OtherExpenseYearTime == year).ToList();
                    result.Value12 = 0;
                    foreach (OtherExpense otherExpense in value12List)
                    {
                        result.Value12 += otherExpense.OtherExpenseAmount;
                    }

                    result.Value9 = result.Value10 + result.Value11 + result.Value12;

                    result.Value13 = 0;
                    result.Value14 = 0;
                    result.Value15 = result.Value1 - result.Value3 + result.Value8 - result.Value9 - result.Value13;
                    result.Value16 = 0;
                    result.Value17 = 0;
                    result.Value18 = result.Value16 - result.Value17;
                    result.Value19 = result.Value15 + result.Value18;

                    result.ValueA1 = result.Value19;
                    result.ValueB1 = 0;
                    result.ValueB2 = 0;
                    result.ValueB3 = 0;
                    result.ValueB4 = 0;
                    result.ValueB5 = 0;
                    result.ValueB6 = 0;
                    result.ValueB7 = 0;
                    result.ValueB8 = 0;
                    result.ValueB9 = 0;
                    result.ValueB10 = 0;
                    result.ValueB11 = 0;
                    result.ValueB12 = result.ValueA1;
                    result.ValueB14 = 0;
                    result.ValueB13 = result.ValueB12 - result.ValueB14;

                    result.ValueC1 = result.ValueB13;
                    result.ValueC2 = 0;
                    result.ValueC3 = 0;
                    result.ValueC3a = 0;
                    result.ValueC3b = 0;
                    result.ValueC4 = result.ValueC1;
                    result.ValueC5 = 0;
                    result.ValueC6 = result.ValueC4 - result.ValueC5;

                    // Bug Hard code
                    int tndnTaxRate = 0;
                    TaxRate taxRate = db.TaxRates.FirstOrDefault(m => m.TaxRateId == 2);
                    if (taxRate != null)
                    {
                        tndnTaxRate = taxRate.TaxRateValue;
                    }

                    if (tndnTaxRate == 22)
                    {
                        result.ValueC7 = result.ValueC4;
                    }
                    else
                    {
                        result.ValueC7 = 0;
                    }

                    if (tndnTaxRate == 20)
                    {
                        result.ValueC8 = result.ValueC4;
                    }
                    else
                    {
                        result.ValueC8 = 0;
                    }

                    if (tndnTaxRate != 22 && tndnTaxRate != 20)
                    {
                        result.ValueC9 = result.ValueC4;
                        result.ValueC9a = tndnTaxRate;
                    }
                    else
                    {
                        result.ValueC9 = 0;
                        result.ValueC9a = 0;
                    }

                    result.ValueC10 = (int)(result.ValueC7 / 5 + result.ValueC8 * 0.22 + result.ValueC9 * result.ValueC9a / 100);
                    result.ValueC11 = 0;
                    result.ValueC12 = 0;
                    result.ValueC13 = 0;
                    result.ValueC14 = 0;
                    result.ValueC15 = 0;
                    result.ValueC16 = result.ValueC10 - result.ValueC11 - result.ValueC12 - result.ValueC15;

                    result.ValueD1 = result.ValueC16;
                    result.ValueD2 = 0;
                    result.ValueD3 = 0;
                    result.ValueD = result.ValueD1 + result.ValueD2 + result.ValueD3;

                    result.ValueE = 0;
                    result.ValueE2 = 0;
                    result.ValueE3 = 0;
                    result.ValueE1 = 0;

                    result.ValueG1 = result.ValueD1 - result.ValueE1;
                    result.ValueG2 = result.ValueD2 - result.ValueE2;
                    result.ValueG3 = result.ValueD3 - result.ValueE3;
                    result.ValueG = result.ValueG1 + result.ValueG2 + result.ValueG3;

                    result.ValueH = result.ValueD / 5;

                    result.ValueI = result.ValueG - result.ValueH;
                    result.ValueL1 = false;
                }
            }

            return result;
        }
Beispiel #4
0
        public ActionResult ExportXmlTndnTaxDeclaration(FormCollection form)
        {
            try
            {
                #region Get Data from Form
                string taxYear = form["taxYear"];

                //Store Info Not get from form; Get from DB
                BMAEntities db = new BMAEntities();

                string createDate = form["createDate"];
                string vatAgentOwnerName = form["vatAgentOwnerName"];
                string vatAgentName = form["agentName"];
                string vatAgentTaxCodeString = form["agentTaxCode"];
                string vatAgentTaxCode = "";
                if (vatAgentTaxCodeString != null)
                {
                    vatAgentTaxCode = vatAgentTaxCodeString.Replace(",", "");
                }
                string vatAgentNo = form["agentNo"];
                string vatAgentAddress = form["vatAgentAddress"];
                string vatAgentDistrict = form["vatAgentDistrict"];
                string vatAgentProvince = form["vatAgentProvince"];
                string vatAgentPhone = form["vatAgentPhone"];
                string vatAgentFax = form["vatAgentFax"];
                string vatAgentEmail = form["vatAgentEmail"];
                string signName = form["signName"];
                string maxRevenueRatio = form["maxRevenueRatio"];

                string storeOwnerName = form["storeOwnerName"];
                string storeTaxcode = form["storeTaxcode"].Replace(",", "");
                string storeAddress = form["storeAddress"];
                string storeDistrict = form["storeDistrict"];
                string storeProvince = form["storeProvince"];
                string storePhone = form["storePhone"];
                string storeFax = form["storeFax"];
                string storeEmail = form["storeEmail"];

                string value22No = form["value22No"];
                string value22Date = form["value22Date"];

                string valueA1 = form["valueA1"].Replace(".", "");

                string valueB1 = form["valueB1"].Replace(".", "");
                string valueB2 = form["valueB2"].Replace(".", "");
                string valueB3 = form["valueB3"].Replace(".", "");
                string valueB4 = form["valueB4"].Replace(".", "");
                string valueB5 = form["valueB5"].Replace(".", "");
                string valueB6 = form["valueB6"].Replace(".", "");
                string valueB7 = form["valueB7"].Replace(".", "");
                string valueB8 = form["valueB8"].Replace(".", "");
                string valueB9 = form["valueB9"].Replace(".", "");
                string valueB10 = form["valueB10"].Replace(".", "");
                string valueB11 = form["valueB11"].Replace(".", "");
                string valueB12 = form["valueB12"].Replace(".", "");
                string valueB13 = form["valueB13"].Replace(".", "");
                string valueB14 = form["valueB14"].Replace(".", "");

                string valueC1 = form["valueC1"].Replace(".", "");
                string valueC2 = form["valueC2"].Replace(".", "");
                string valueC3 = form["valueC3"].Replace(".", "");
                string valueC3a = form["valueC3a"].Replace(".", "");
                string valueC3b = form["valueC3b"].Replace(".", "");
                string valueC4 = form["valueC4"].Replace(".", "");
                string valueC5 = form["valueC5"].Replace(".", "");
                string valueC6 = form["valueC6"].Replace(".", "");
                string valueC7 = form["valueC7"].Replace(".", "");
                string valueC8 = form["valueC8"].Replace(".", "");
                string valueC9 = form["valueC9"].Replace(".", "");
                string valueC9a = form["valueC9a"].Replace(".", "");
                string valueC10 = form["valueC10"].Replace(".", "");
                string valueC11 = form["valueC11"].Replace(".", "");
                string valueC12 = form["valueC12"].Replace(".", "");
                string valueC13 = form["valueC13"].Replace(".", "");
                string valueC14 = form["valueC14"].Replace(".", "");
                string valueC15 = form["valueC15"].Replace(".", "");
                string valueC16 = form["valueC16"].Replace(".", "");

                string valueD = form["valueD"].Replace(".", "");
                string valueD1 = form["valueD1"].Replace(".", "");
                string valueD2 = form["valueD2"].Replace(".", "");
                string valueD3 = form["valueD3"].Replace(".", "");

                string valueE = form["valueE"].Replace(".", "");
                string valueE1 = form["valueE1"].Replace(".", "");
                string valueE2 = form["valueE2"].Replace(".", "");
                string valueE3 = form["valueE3"].Replace(".", "");

                string valueG = form["valueG"].Replace(".", "");
                string valueG1 = form["valueG1"].Replace(".", "");
                string valueG2 = form["valueG2"].Replace(".", "");
                string valueG3 = form["valueG3"].Replace(".", "");

                string valueH = form["valueH"].Replace(".", "");
                string valueI = form["valueI"].Replace(".", "");

                string valueL1 = form["valueL1"];
                string valueL2Code = form["valueL2Code"];
                string valueL3 = form["valueL3"];
                string valueL4 = form["valueL4"].Replace(".", "");
                string valueL5 = form["valueL5"].Replace(".", "");

                string valueM1DayQuantity = form["valueM1DayQuantity"];
                string valueM1FromDate = form["valueM1FromDate"];
                string valueM1ToDate = form["valueM1ToDate"];
                string valueM2 = form["valueM2"].Replace(".", "");

                string value1 = form["value01"].Replace(".", "");
                string value2 = form["value02"].Replace(".", "");
                string value3 = form["value03"].Replace(".", "");
                string value4 = form["value04"].Replace(".", "");
                string value5 = form["value05"].Replace(".", "");
                string value6 = form["value06"].Replace(".", "");
                string value7 = form["value07"].Replace(".", "");
                string value8 = form["value08"].Replace(".", "");
                string value9 = form["value09"].Replace(".", "");
                string value10 = form["value10"].Replace(".", "");
                string value11 = form["value11"].Replace(".", "");
                string value12 = form["value12"].Replace(".", "");
                string value13 = form["value13"].Replace(".", "");
                string value14 = form["value14"].Replace(".", "");
                string value15 = form["value15"].Replace(".", "");
                string value16 = form["value16"].Replace(".", "");
                string value17 = form["value17"].Replace(".", "");
                string value18 = form["value18"].Replace(".", "");
                string value19 = form["value19"].Replace(".", "");
                #endregion

                #region Create TndnTaxDeclaration Model and Save

                TndnTaxDeclaration tndn = new TndnTaxDeclaration();

                tndn.Year = Convert.ToInt32(taxYear.Trim());
                if (maxRevenueRatio.Trim().Length > 0)
                {
                    tndn.MaxRevenueRatio = Convert.ToInt32(maxRevenueRatio.Trim());
                }
                else
                {
                    tndn.MaxRevenueRatio = 0;
                }

                tndn.StoreOwnerName = storeOwnerName;
                tndn.StoreTaxCode = storeTaxcode;
                tndn.StoreAddress = storeAddress;
                tndn.StoreDistrict = storeDistrict;
                tndn.StoreProvince = storeProvince;
                tndn.StorePhone = storePhone;
                tndn.StoreFax = storeFax;
                tndn.StoreEmail = storeEmail;

                tndn.TaxAgentTaxCode = vatAgentTaxCode;
                tndn.TaxAgentName = vatAgentName;
                tndn.TaxAgentOwnerName = vatAgentOwnerName;
                tndn.TaxAgentNo = vatAgentNo;
                tndn.TaxAgentAddress = vatAgentAddress;
                tndn.TaxAgentDistrict = vatAgentDistrict;
                tndn.TaxAgentProvince = vatAgentProvince;
                tndn.TaxAgentPhone = vatAgentPhone;
                tndn.TaxAgentFax = vatAgentFax;
                tndn.TaxAgentEmail = vatAgentEmail;
                tndn.SignName = signName;
                if (!createDate.Trim().IsEmpty())
                {
                    tndn.CreateDate = DateTime.ParseExact(createDate, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                }

                if (!value22No.Trim().IsEmpty())
                {
                    tndn.Value22No = Convert.ToInt32(value22No);
                }

                if (!value22Date.Trim().IsEmpty())
                {
                    tndn.Value22Date = DateTime.ParseExact(value22Date, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                }

                tndn.ValueA1 = Convert.ToInt32(valueA1);
                tndn.ValueB1 = Convert.ToInt32(valueB1);
                tndn.ValueB2 = Convert.ToInt32(valueB2);
                tndn.ValueB3 = Convert.ToInt32(valueB3);
                tndn.ValueB4 = Convert.ToInt32(valueB4);
                tndn.ValueB5 = Convert.ToInt32(valueB5);
                tndn.ValueB6 = Convert.ToInt32(valueB6);
                tndn.ValueB7 = Convert.ToInt32(valueB7);
                tndn.ValueB8 = Convert.ToInt32(valueB8);
                tndn.ValueB9 = Convert.ToInt32(valueB9);
                tndn.ValueB10 = Convert.ToInt32(valueB10);
                tndn.ValueB11 = Convert.ToInt32(valueB11);
                tndn.ValueB12 = Convert.ToInt32(valueB12);
                tndn.ValueB13 = Convert.ToInt32(valueB13);
                tndn.ValueB14 = Convert.ToInt32(valueB14);

                tndn.ValueC1 = Convert.ToInt32(valueC1);
                tndn.ValueC2 = Convert.ToInt32(valueC2);
                tndn.ValueC3 = Convert.ToInt32(valueC3);
                tndn.ValueC3a = Convert.ToInt32(valueC3a);
                tndn.ValueC3b = Convert.ToInt32(valueC3b);
                tndn.ValueC4 = Convert.ToInt32(valueC4);
                tndn.ValueC5 = Convert.ToInt32(valueC5);
                tndn.ValueC6 = Convert.ToInt32(valueC6);
                tndn.ValueC7 = Convert.ToInt32(valueC7);
                tndn.ValueC8 = Convert.ToInt32(valueC8);
                tndn.ValueC9 = Convert.ToInt32(valueC9);
                tndn.ValueC9a = Convert.ToInt32(valueC9a);
                tndn.ValueC10 = Convert.ToInt32(valueC10);
                tndn.ValueC11 = Convert.ToInt32(valueC11);
                tndn.ValueC12 = Convert.ToInt32(valueC12);
                tndn.ValueC13 = Convert.ToInt32(valueC13);
                tndn.ValueC14 = Convert.ToInt32(valueC14);
                tndn.ValueC15 = Convert.ToInt32(valueC15);
                tndn.ValueC16 = Convert.ToInt32(valueC16);

                tndn.ValueD = Convert.ToInt32(valueD);
                tndn.ValueD1 = Convert.ToInt32(valueD1);
                tndn.ValueD2 = Convert.ToInt32(valueD2);
                tndn.ValueD3 = Convert.ToInt32(valueD3);

                tndn.ValueE = Convert.ToInt32(valueE);
                tndn.ValueE1 = Convert.ToInt32(valueE1);
                tndn.ValueE2 = Convert.ToInt32(valueE2);
                tndn.ValueE3 = Convert.ToInt32(valueE3);

                tndn.ValueG = Convert.ToInt32(valueG);
                tndn.ValueG1 = Convert.ToInt32(valueG1);
                tndn.ValueG2 = Convert.ToInt32(valueG2);
                tndn.ValueG3 = Convert.ToInt32(valueG3);

                tndn.ValueH = Convert.ToInt32(valueH);
                tndn.ValueI = Convert.ToInt32(valueI);

                if (valueL1 != null && valueL1.Equals("on"))
                {
                    tndn.ValueL1 = true;
                    tndn.ValueL2No = Convert.ToInt32(valueL2Code);
                    tndn.ValueL3 = DateTime.ParseExact(valueL3, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                    tndn.ValueL4 = Convert.ToInt32(valueL4);
                    tndn.ValueL5 = Convert.ToInt32(valueL5);
                }
                else
                {
                    tndn.ValueL1 = false;
                }

                if (!valueM1FromDate.IsEmpty())
                {
                    tndn.ValueM1FromDate = DateTime.ParseExact(valueM1FromDate, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                }

                if (!valueM1ToDate.IsEmpty())
                {
                    tndn.ValueM1ToDate = DateTime.ParseExact(valueM1FromDate, "yyyy-MM-dd", CultureInfo.InvariantCulture);
                }

                tndn.ValueM2 = Convert.ToInt32(valueM2);

                tndn.Value1 = Convert.ToInt32(value1);
                tndn.Value2 = Convert.ToInt32(value2);
                tndn.Value3 = Convert.ToInt32(value3);
                tndn.Value4 = Convert.ToInt32(value4);
                tndn.Value5 = Convert.ToInt32(value5);
                tndn.Value6 = Convert.ToInt32(value6);
                tndn.Value7 = Convert.ToInt32(value7);
                tndn.Value8 = Convert.ToInt32(value8);
                tndn.Value9 = Convert.ToInt32(value9);
                tndn.Value10 = Convert.ToInt32(value10);
                tndn.Value11 = Convert.ToInt32(value11);
                tndn.Value12 = Convert.ToInt32(value12);
                tndn.Value13 = Convert.ToInt32(value13);
                tndn.Value14 = Convert.ToInt32(value14);
                tndn.Value15 = Convert.ToInt32(value15);
                tndn.Value16 = Convert.ToInt32(value16);
                tndn.Value17 = Convert.ToInt32(value17);
                tndn.Value18 = Convert.ToInt32(value18);
                tndn.Value19 = Convert.ToInt32(value19);

                TaxBusiness business = new TaxBusiness();
                business.SaveTndnTaxDeclaration(tndn);

                #endregion

                #region Create XML File

                XElement root = new XElement("HSoThueDTu");

                XElement HSoKhaiThue = new XElement("HSoKhaiThue");
                HSoKhaiThue.Add(new XAttribute("id", "ID_1"));

                XElement TTinChung = new XElement("TTinChung");

                XElement TTinDVu = new XElement("TTinDVu");

                XElement maDVu = new XElement("maDVu", "HTKK");
                TTinDVu.Add(maDVu);
                XElement tenDVu = new XElement("tenDVu", "HTKK");
                TTinDVu.Add(tenDVu);
                XElement pbanDVu = new XElement("pbanDVu", "3.3.4");
                TTinDVu.Add(pbanDVu);

                TTinChung.Add(TTinDVu);

                XElement TTinTKhaiThue = new XElement("TTinTKhaiThue");

                XElement TKhaiThue = new XElement("TKhaiThue");

                XElement maTKhai = new XElement("maTKhai", "03");
                TKhaiThue.Add(maTKhai);

                XElement tenTKhai = new XElement("tenTKhai", "TỜ KHAI QUYẾT TOÁN THUẾ THU NHẬP DOANH NGHIỆP (Mẫu số 03/TNDN)");
                TKhaiThue.Add(tenTKhai);

                XElement moTaBMau = new XElement("moTaBMau", "(Ban hành kèm theo Thông tư số 151/2014/TT-BTC  ngày 10/10/2014 của  Bộ Tài chính)");
                TKhaiThue.Add(moTaBMau);

                XElement pbanTKhaiXML = new XElement("pbanTKhaiXML", "2.0.7");
                TKhaiThue.Add(pbanTKhaiXML);

                XElement loaiTKhai = new XElement("loaiTKhai", "C");
                TKhaiThue.Add(loaiTKhai);

                XElement soLan = new XElement("soLan", "0");
                TKhaiThue.Add(soLan);

                XElement KyKKhaiThue = new XElement("KyKKhaiThue");

                XElement kieuKy = new XElement("kieuKy", "Y");
                KyKKhaiThue.Add(kieuKy);

                XElement kyKKhai = new XElement("kyKKhai", taxYear);
                KyKKhaiThue.Add(kyKKhai);

                XElement kyKKhaiTuNgay = new XElement("kyKKhaiTuNgay", "01/01/" + taxYear);
                KyKKhaiThue.Add(kyKKhaiTuNgay);

                XElement kyKKhaiDenNgay = new XElement("kyKKhaiDenNgay", "31/12/" + taxYear);
                KyKKhaiThue.Add(kyKKhaiDenNgay);

                XElement kyKKhaiTuThang = new XElement("kyKKhaiTuThang");
                KyKKhaiThue.Add(kyKKhaiTuThang);

                XElement kyKKhaiDenThang = new XElement("kyKKhaiDenThang");
                KyKKhaiThue.Add(kyKKhaiDenThang);

                TKhaiThue.Add(KyKKhaiThue);

                XElement maCQTNoiNop = new XElement("maCQTNoiNop");
                TKhaiThue.Add(maCQTNoiNop);

                XElement tenCQTNoiNop = new XElement("tenCQTNoiNop", "Chi cục Thuế Quận 12");
                TKhaiThue.Add(tenCQTNoiNop);

                XElement ngayLapTKhai = new XElement("ngayLapTKhai", createDate);
                TKhaiThue.Add(ngayLapTKhai);
                if (valueL1 != null && valueL1.Equals("on"))
                {
                    XElement GiaHan = new XElement("GiaHan");
                    if (valueL2Code.Equals("01"))
                    {
                        XElement lyDoGiaHan = new XElement("lyDoGiaHan", "Doanh nghiệp có quy mô nhỏ và vừa");
                        GiaHan.Add(lyDoGiaHan);
                    }
                    if (valueL2Code.Equals("02"))
                    {
                        XElement lyDoGiaHan = new XElement("lyDoGiaHan", "Doanh nghiệp sử dụng nhiều lao động");
                        GiaHan.Add(lyDoGiaHan);
                    }
                    if (valueL2Code.Equals("99"))
                    {
                        XElement lyDoGiaHan = new XElement("lyDoGiaHan", "Lý do khác");
                        GiaHan.Add(lyDoGiaHan);
                    }

                    XElement maLyDoGiaHan = new XElement("maLyDoGiaHan", valueL2Code);
                    GiaHan.Add(maLyDoGiaHan);

                    TKhaiThue.Add(GiaHan);

                }
                else
                {
                    XElement GiaHan = new XElement("GiaHan");

                    XElement lyDoGiaHan = new XElement("lyDoGiaHan");
                    GiaHan.Add(lyDoGiaHan);

                    XElement maLyDoGiaHan = new XElement("maLyDoGiaHan");
                    GiaHan.Add(maLyDoGiaHan);

                    TKhaiThue.Add(GiaHan);
                }

                XElement nguoiKy = new XElement("nguoiKy", signName);
                TKhaiThue.Add(nguoiKy);

                XElement ngayKy = new XElement("ngayKy", createDate);
                TKhaiThue.Add(ngayKy);

                XElement nganhNgheKD = new XElement("nganhNgheKD");
                TKhaiThue.Add(nganhNgheKD);

                TTinTKhaiThue.Add(TKhaiThue);

                XElement NNT = new XElement("NNT");

                XElement mst = new XElement("mst", tndn.StoreTaxCode);
                NNT.Add(mst);

                XElement tenNNT = new XElement("tenNNT", tndn.StoreOwnerName);
                NNT.Add(tenNNT);

                XElement dchiNNT = new XElement("dchiNNT", tndn.StoreAddress);
                NNT.Add(dchiNNT);

                XElement phuongXa = new XElement("phuongXa");
                NNT.Add(phuongXa);

                XElement maHuyenNNT = new XElement("maHuyenNNT");
                NNT.Add(maHuyenNNT);

                XElement tenHuyenNNT = new XElement("tenHuyenNNT", tndn.StoreDistrict);
                NNT.Add(tenHuyenNNT);

                XElement maTinhNNT = new XElement("maTinhNNT");
                NNT.Add(maTinhNNT);

                XElement tenTinhNNT = new XElement("tenTinhNNT", tndn.StoreProvince);
                NNT.Add(tenTinhNNT);

                XElement dthoaiNNT = new XElement("dthoaiNNT", tndn.StorePhone);
                NNT.Add(dthoaiNNT);

                XElement faxNNT = new XElement("faxNNT", tndn.StoreFax);
                NNT.Add(faxNNT);

                XElement emailNNT = new XElement("emailNNT", tndn.StoreEmail);
                NNT.Add(emailNNT);

                TTinTKhaiThue.Add(NNT);

                XElement DLyThue = new XElement("DLyThue");

                XElement mstDLyThue = new XElement("mstDLyThue", vatAgentTaxCode.Replace(",", ""));
                DLyThue.Add(mstDLyThue);

                XElement tenDLyThue = new XElement("tenDLyThue", vatAgentOwnerName);
                DLyThue.Add(tenDLyThue);

                XElement dchiDLyThue = new XElement("dchiDLyThue", vatAgentAddress);
                DLyThue.Add(dchiDLyThue);

                XElement maHuyenDLyThue = new XElement("maHuyenDLyThue");
                DLyThue.Add(maHuyenDLyThue);

                XElement tenHuyenDLyThue = new XElement("tenHuyenDLyThue", vatAgentDistrict);
                DLyThue.Add(tenHuyenDLyThue);

                XElement maTinhDLyThue = new XElement("maTinhDLyThue");
                DLyThue.Add(maTinhDLyThue);

                XElement tenTinhDLyThue = new XElement("tenTinhDLyThue", vatAgentProvince);
                DLyThue.Add(tenTinhDLyThue);

                XElement dthoaiDLyThue = new XElement("dthoaiDLyThue", vatAgentPhone);
                DLyThue.Add(dthoaiDLyThue);

                XElement faxDLyThue = new XElement("faxDLyThue", vatAgentFax);
                DLyThue.Add(faxDLyThue);

                XElement emailDLyThue = new XElement("emailDLyThue", vatAgentEmail);
                DLyThue.Add(emailDLyThue);

                XElement soHDongDLyThue = new XElement("soHDongDLyThue", value22No);
                DLyThue.Add(soHDongDLyThue);

                XElement ngayKyHDDLyThue = new XElement("ngayKyHDDLyThue", value22Date);
                DLyThue.Add(ngayKyHDDLyThue);

                XElement NVienDLy = new XElement("NVienDLy");

                XElement tenNVienDLyThue = new XElement("tenNVienDLyThue", vatAgentName);
                NVienDLy.Add(tenNVienDLyThue);

                XElement cchiHNghe = new XElement("cchiHNghe", vatAgentNo);
                NVienDLy.Add(cchiHNghe);

                DLyThue.Add(NVienDLy);

                TTinTKhaiThue.Add(DLyThue);

                TTinChung.Add(TTinTKhaiThue);

                HSoKhaiThue.Add(TTinChung);

                XElement CTieuTKhaiChinh = new XElement("CTieuTKhaiChinh");

                XElement tieuMucHachToan = new XElement("tieuMucHachToan", "1052");
                CTieuTKhaiChinh.Add(tieuMucHachToan);

                XElement doanhNghiepCoQuyMoVuaVaNho = new XElement("doanhNghiepCoQuyMoVuaVaNho", "1");
                CTieuTKhaiChinh.Add(doanhNghiepCoQuyMoVuaVaNho);

                XElement doanhNghiepCoCSoHToanPThuoc = new XElement("doanhNghiepCoCSoHToanPThuoc", "0");
                CTieuTKhaiChinh.Add(doanhNghiepCoCSoHToanPThuoc);

                XElement doanhNghiepKeKhaiTTinLienKet = new XElement("doanhNghiepKeKhaiTTinLienKet", "0");
                CTieuTKhaiChinh.Add(doanhNghiepKeKhaiTTinLienKet);

                XElement ct_04_ma = new XElement("ct_04_ma", "C");
                CTieuTKhaiChinh.Add(ct_04_ma);

                XElement ct_04_ten = new XElement("ct_04_ten", "Công nghiệp chế biến, chế tạo");
                CTieuTKhaiChinh.Add(ct_04_ten);

                XElement ct_05 = new XElement("ct_05", maxRevenueRatio);
                CTieuTKhaiChinh.Add(ct_05);

                XElement ctA1 = new XElement("ctA1", valueA1);
                CTieuTKhaiChinh.Add(ctA1);

                XElement ctB1 = new XElement("ctB1", valueB1);
                CTieuTKhaiChinh.Add(ctB1);
                XElement ctB2 = new XElement("ctB2", valueB2);
                CTieuTKhaiChinh.Add(ctB2);
                XElement ctB3 = new XElement("ctB3", valueB3);
                CTieuTKhaiChinh.Add(ctB3);
                XElement ctB4 = new XElement("ctB4", valueB4);
                CTieuTKhaiChinh.Add(ctB4);
                XElement ctB5 = new XElement("ctB5", valueB5);
                CTieuTKhaiChinh.Add(ctB5);
                XElement ctB6 = new XElement("ctB6", valueB6);
                CTieuTKhaiChinh.Add(ctB6);
                XElement ctB7 = new XElement("ctB7", valueB7);
                CTieuTKhaiChinh.Add(ctB7);
                XElement ctB8 = new XElement("ctB8", valueB8);
                CTieuTKhaiChinh.Add(ctB8);
                XElement ctB9 = new XElement("ctB9", valueB9);
                CTieuTKhaiChinh.Add(ctB9);
                XElement ctB10 = new XElement("ctB10", valueB10);
                CTieuTKhaiChinh.Add(ctB10);
                XElement ctB11 = new XElement("ctB11", valueB11);
                CTieuTKhaiChinh.Add(ctB11);
                XElement ctB12 = new XElement("ctB12", valueB12);
                CTieuTKhaiChinh.Add(ctB12);
                XElement ctB13 = new XElement("ctB13", valueB13);
                CTieuTKhaiChinh.Add(ctB13);
                XElement ctB14 = new XElement("ctB14", valueB14);
                CTieuTKhaiChinh.Add(ctB14);

                XElement ctC1 = new XElement("ctC1", valueC1);
                CTieuTKhaiChinh.Add(ctC1);
                XElement ctC2 = new XElement("ctC2", valueC2);
                CTieuTKhaiChinh.Add(ctC2);
                XElement ctC3 = new XElement("ctC3", valueC3);
                CTieuTKhaiChinh.Add(ctC3);
                XElement ctC3a = new XElement("ctC3a", valueC3a);
                CTieuTKhaiChinh.Add(ctC3a);
                XElement ctC3b = new XElement("ctC3b", valueC3b);
                CTieuTKhaiChinh.Add(ctC3b);
                XElement ctC4 = new XElement("ctC4", valueC4);
                CTieuTKhaiChinh.Add(ctC4);
                XElement ctC5 = new XElement("ctC5", valueC5);
                CTieuTKhaiChinh.Add(ctC5);
                XElement ctC6 = new XElement("ctC6", valueC6);
                CTieuTKhaiChinh.Add(ctC6);
                XElement ctC7 = new XElement("ctC7", valueC7);
                CTieuTKhaiChinh.Add(ctC7);
                XElement ctC8 = new XElement("ctC8", valueC8);
                CTieuTKhaiChinh.Add(ctC8);
                XElement ctC9 = new XElement("ctC9", valueC9);
                CTieuTKhaiChinh.Add(ctC9);
                XElement ctC9a = new XElement("ctC9a", valueC9a);
                CTieuTKhaiChinh.Add(ctC9a);
                XElement ctC10 = new XElement("ctC10", valueC10);
                CTieuTKhaiChinh.Add(ctC10);
                XElement ctC11 = new XElement("ctC11", valueC11);
                CTieuTKhaiChinh.Add(ctC11);
                XElement ctC12 = new XElement("ctC12", valueC12);
                CTieuTKhaiChinh.Add(ctC12);
                XElement ctC13 = new XElement("ctC13", valueC13);
                CTieuTKhaiChinh.Add(ctC13);
                XElement ctC14 = new XElement("ctC14", valueC14);
                CTieuTKhaiChinh.Add(ctC14);
                XElement ctC15 = new XElement("ctC15", valueC15);
                CTieuTKhaiChinh.Add(ctC15);
                XElement ctC16 = new XElement("ctC16", valueC16);
                CTieuTKhaiChinh.Add(ctC16);

                XElement ctD = new XElement("ctD", valueD);
                CTieuTKhaiChinh.Add(ctD);
                XElement ctD1 = new XElement("ctD1", valueD1);
                CTieuTKhaiChinh.Add(ctD1);
                XElement ctD2 = new XElement("ctD2", valueD2);
                CTieuTKhaiChinh.Add(ctD2);
                XElement ctD3 = new XElement("ctD3", valueD3);
                CTieuTKhaiChinh.Add(ctD3);

                XElement ctE = new XElement("ctE", valueE);
                CTieuTKhaiChinh.Add(ctE);
                XElement ctE1 = new XElement("ctE1", valueE1);
                CTieuTKhaiChinh.Add(ctE1);
                XElement ctE2 = new XElement("ctE2", valueE2);
                CTieuTKhaiChinh.Add(ctE2);
                XElement ctE3 = new XElement("ctE3", valueE3);
                CTieuTKhaiChinh.Add(ctE3);

                XElement ctG = new XElement("ctG", valueG);
                CTieuTKhaiChinh.Add(ctG);
                XElement ctG1 = new XElement("ctG1", valueG1);
                CTieuTKhaiChinh.Add(ctG1);
                XElement ctG2 = new XElement("ctG2", valueG2);
                CTieuTKhaiChinh.Add(ctG2);
                XElement ctG3 = new XElement("ctG3", valueG3);
                CTieuTKhaiChinh.Add(ctG3);

                XElement ctH = new XElement("ctH", valueH);
                CTieuTKhaiChinh.Add(ctH);
                XElement ctI = new XElement("ctI", valueI);
                CTieuTKhaiChinh.Add(ctI);

                XElement GiaHanNopThue = new XElement("GiaHanNopThue");

                if (valueL1 != null && valueL1.Equals("on"))
                {
                    XElement ctL1 = new XElement("ctL1", "1");
                    GiaHanNopThue.Add(ctL1);

                    XElement ctL2_ma = new XElement("ctL2_ma", valueL2Code);
                    GiaHanNopThue.Add(ctL2_ma);

                    if (valueL2Code.Equals("01"))
                    {
                        XElement ctL2_ten = new XElement("ctL2_ten", "Doanh nghiệp có quy mô nhỏ và vừa");
                        GiaHanNopThue.Add(ctL2_ten);
                    }
                    if (valueL2Code.Equals("02"))
                    {
                        XElement ctL2_ten = new XElement("ctL2_ten", "Doanh nghiệp sử dụng nhiều lao động");
                        GiaHanNopThue.Add(ctL2_ten);
                    }
                    if (valueL2Code.Equals("99"))
                    {
                        XElement ctL2_ten = new XElement("ctL2_ten", "Lý do khác");
                        GiaHanNopThue.Add(ctL2_ten);
                    }

                    XElement ctL3 = new XElement("ctL3",
                        (valueL3.Trim().Length > 0
                            ? DateTime.ParseExact(valueL3, "dd/MM/yyyy", CultureInfo.InvariantCulture)
                                .ToString("yyyy-MM-dd")
                            : ""));
                    GiaHanNopThue.Add(ctL3);

                    XElement ctL4 = new XElement("ctL4", valueL4);
                    GiaHanNopThue.Add(ctL4);

                    XElement ctL5 = new XElement("ctL5", valueL5);
                    GiaHanNopThue.Add(ctL5);
                }
                else
                {
                    XElement ctL1 = new XElement("ctL1", "0");
                    GiaHanNopThue.Add(ctL1);

                    XElement ctL2_ma = new XElement("ctL2_ma");
                    GiaHanNopThue.Add(ctL2_ma);

                    XElement ctL2_ten = new XElement("ctL2_ten");
                    GiaHanNopThue.Add(ctL2_ten);

                    XElement ctL3 = new XElement("ctL3");
                    GiaHanNopThue.Add(ctL3);

                    XElement ctL4 = new XElement("ctL4");
                    GiaHanNopThue.Add(ctL4);

                    XElement ctL5 = new XElement("ctL5");
                    GiaHanNopThue.Add(ctL5);
                }

                CTieuTKhaiChinh.Add(GiaHanNopThue);

                XElement TienChamNop = new XElement("TienChamNop");

                XElement CTM1 = new XElement("CTM1");

                XElement soNgay = new XElement("soNgay", valueM1DayQuantity);
                CTM1.Add(soNgay);

                XElement tuNgay = new XElement("tuNgay", (valueM1FromDate.Trim().Length > 0 ? DateTime.ParseExact(valueM1FromDate, "dd/MM/yyyy", CultureInfo.InvariantCulture).ToString("yyyy-MM-dd") : ""));
                CTM1.Add(tuNgay);

                XElement denNgay = new XElement("denNgay", (valueM1ToDate.Trim().Length > 0 ? DateTime.ParseExact(valueM1ToDate, "dd/MM/yyyy", CultureInfo.InvariantCulture).ToString("yyyy-MM-dd") : ""));
                CTM1.Add(denNgay);

                TienChamNop.Add(CTM1);

                XElement ctM2 = new XElement("ctM2", valueM2);
                TienChamNop.Add(ctM2);

                CTieuTKhaiChinh.Add(TienChamNop);

                XElement TaiLieu_Guikem = new XElement("TaiLieu_Guikem");
                CTieuTKhaiChinh.Add(TaiLieu_Guikem);

                HSoKhaiThue.Add(CTieuTKhaiChinh);

                XElement PLuc = new XElement("PLuc");

                XElement PL03_1A_TNDN = new XElement("PL03_1A_TNDN");

                XElement ct01 = new XElement("ct01", value1);
                PL03_1A_TNDN.Add(ct01);

                XElement ct02 = new XElement("ct02", value2);
                PL03_1A_TNDN.Add(ct02);

                XElement ct03 = new XElement("ct03", value3);
                PL03_1A_TNDN.Add(ct03);

                XElement ct04 = new XElement("ct04", value4);
                PL03_1A_TNDN.Add(ct04);

                XElement ct05 = new XElement("ct05", value5);
                PL03_1A_TNDN.Add(ct05);

                XElement ct06 = new XElement("ct06", value6);
                PL03_1A_TNDN.Add(ct06);

                XElement ct07 = new XElement("ct07", value7);
                PL03_1A_TNDN.Add(ct07);

                XElement ct08 = new XElement("ct08", value8);
                PL03_1A_TNDN.Add(ct08);

                XElement ct09 = new XElement("ct09", value9);
                PL03_1A_TNDN.Add(ct09);

                XElement ct10 = new XElement("ct10", value10);
                PL03_1A_TNDN.Add(ct10);

                XElement ct11 = new XElement("ct11", value11);
                PL03_1A_TNDN.Add(ct11);

                XElement ct12 = new XElement("ct12", value12);
                PL03_1A_TNDN.Add(ct12);

                XElement ct13 = new XElement("ct13", value13);
                PL03_1A_TNDN.Add(ct13);

                XElement ct14 = new XElement("ct14", value14);
                PL03_1A_TNDN.Add(ct14);

                XElement ct15 = new XElement("ct15", value15);
                PL03_1A_TNDN.Add(ct15);

                XElement ct16 = new XElement("ct16", value16);
                PL03_1A_TNDN.Add(ct16);

                XElement ct17 = new XElement("ct17", value17);
                PL03_1A_TNDN.Add(ct17);

                XElement ct18 = new XElement("ct18", value18);
                PL03_1A_TNDN.Add(ct18);

                XElement ct19 = new XElement("ct19", value19);
                PL03_1A_TNDN.Add(ct19);

                PLuc.Add(PL03_1A_TNDN);

                HSoKhaiThue.Add(PLuc);

                root.Add(HSoKhaiThue);

                var xs = new XmlSerializer(root.GetType());
                var stream = new MemoryStream();
                var streamWriter = new StreamWriter(stream, System.Text.Encoding.UTF8);

                xs.Serialize(streamWriter, root);
                stream.Position = 0;
                return File(stream, "application/xml", "TNDN" + taxYear + ".xml");

                #endregion
            }
            catch (Exception)
            {
                return RedirectToAction("ManageError", "Error");
            }
        }