public DeclarationVatForm GetVatTaxDeclaration(int quarter, int year) { DeclarationVatForm result = new DeclarationVatForm(); VatTaxDeclaration vatTaxDeclaration = db.VatTaxDeclarations.FirstOrDefault(m => m.Quarter == quarter && m.Year == year); if (vatTaxDeclaration == null) { result.Quarter = quarter; result.Year = year; result.CreateDate = new DateTime(year, quarter * 3, 1).AddMonths(1).AddDays(-1); // Get StoreInfo 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; } int startMonth = quarter * 3 - 2; int endMonth = quarter * 3; // Get Input Bill List<InputBill> inputBillList = db.InputBills.Where( m => m.ImportDate.Month >= startMonth && m.ImportDate.Month <= endMonth && m.ImportDate.Year == year) .ToList(); List<DeclarationVatCategory> inputCategories1 = new List<DeclarationVatCategory>(); int totalInputCategory1 = 0; int totalTaxInputCategory1 = 0; if (inputBillList.Count > 0) { foreach (InputBill inputBill in inputBillList) { DeclarationVatCategory category1 = new DeclarationVatCategory { Column2 = inputBill.InputBillCode, Column3 = inputBill.ImportDate, Column4 = inputBill.Supplier.SupplierName, Column5 = inputBill.Supplier.SupplierTaxCode, Column6 = inputBill.InputBillAmount, Column7 = inputBill.InputTaxAmount }; totalInputCategory1 += (int)inputBill.InputBillAmount; totalTaxInputCategory1 += (int)inputBill.InputTaxAmount; inputCategories1.Add(category1); } } result.InputCategories1 = inputCategories1; result.InputCategories1TotalAmount = totalInputCategory1; result.InputCategories1TotalTaxAmount = totalTaxInputCategory1; result.InputTotalAmount = totalInputCategory1; result.InputTotalTaxAmount = totalTaxInputCategory1; // Get Output bill List<OutputBill> outputBillList = db.OutputBills.Where( m => m.ExportDate.Month >= startMonth && m.ExportDate.Month <= endMonth && m.ExportDate.Year == year).ToList(); List<DeclarationVatCategory> outputCategories4 = new List<DeclarationVatCategory>(); int totalOutputCategory4 = 0; int totalTaxOutputCategory4 = 0; if (outputBillList.Count > 0) { foreach (OutputBill outputBill in outputBillList) { DeclarationVatCategory category4 = new DeclarationVatCategory(); category4.Column2 = outputBill.OutputBillCode; category4.Column3 = outputBill.ExportDate; category4.Column4 = outputBill.Order.User.Fullname; category4.Column5 = outputBill.Order.User.Customers.ElementAt(0).TaxCode; category4.Column6 = outputBill.OutputBillAmount; category4.Column7 = outputBill.OutputBillTaxAmount; totalOutputCategory4 += (int)outputBill.OutputBillAmount; totalTaxOutputCategory4 += (int)outputBill.OutputBillTaxAmount; outputCategories4.Add(category4); } } result.OutputCategories4 = outputCategories4; result.OutputCategories4TotalAmount = totalOutputCategory4; result.OutputCategories4TotalTaxAmount = totalTaxOutputCategory4; result.OutputTotalAmount = totalOutputCategory4; result.HaveTaxOutputAmount = totalOutputCategory4; result.OutputTotalTaxAmount = totalTaxOutputCategory4; result.Value25 = result.InputTotalTaxAmount; result.Value36 = result.OutputTotalTaxAmount - result.Value25; if (result.Value36 >= 0) { result.Value40A = result.Value36; result.Value40 = result.Value40A; } else { result.Value41 = -result.Value36; result.Value42 = result.Value41; } result.Value40 = result.Value40A; if (result.InputTotalAmount == 0 && result.OutputCategories1TotalAmount == 0 && result.HaveTaxOutputAmount == 0) { result.Value21 = true; } else { result.Value21 = false; } } else { result.Quarter = quarter; result.Year = year; if (vatTaxDeclaration.CreateDate == null) { result.CreateDate = new DateTime(year, quarter * 3, 1).AddMonths(1).AddDays(-1); } else { result.CreateDate = vatTaxDeclaration.CreateDate; } if (vatTaxDeclaration.Value20Date == null) { result.Value20Date = new DateTime(2013, 1, 1); } else { result.Value20Date = vatTaxDeclaration.Value20Date.Value; } result.Value20No = vatTaxDeclaration.Value20No; // Get StoreInfo StoreInfo storeInfo = db.StoreInfoes.FirstOrDefault(); if (vatTaxDeclaration.StoreOwnerName.Trim() == "") { if (storeInfo != null) { result.StoreOwnerName = storeInfo.OwnerName; } } else { result.StoreOwnerName = vatTaxDeclaration.StoreOwnerName; } if (vatTaxDeclaration.StoreTaxCode.Trim() == "") { if (storeInfo != null) { result.StoreTaxCode = storeInfo.TaxCode; } } else { result.StoreTaxCode = vatTaxDeclaration.StoreTaxCode; } if (vatTaxDeclaration.StoreAddress.Trim() == "") { if (storeInfo != null) { result.StoreAddress = storeInfo.Address; } } else { result.StoreAddress = vatTaxDeclaration.StoreAddress; } if (vatTaxDeclaration.StoreDistrict.Trim() == "") { if (storeInfo != null) { result.StoreDistrict = storeInfo.District; } } else { result.StoreDistrict = vatTaxDeclaration.StoreDistrict; } if (vatTaxDeclaration.StoreProvince.Trim() == "") { if (storeInfo != null) { result.StoreProvince = storeInfo.Province; } } else { result.StoreProvince = vatTaxDeclaration.StoreProvince; } if (vatTaxDeclaration.StorePhone.Trim() == "") { if (storeInfo != null) { result.StorePhone = storeInfo.Phonenumber; } } else { result.StorePhone = vatTaxDeclaration.StorePhone; } if (vatTaxDeclaration.StoreFax.Trim() == "") { if (storeInfo != null) { result.StoreFax = storeInfo.Fax; } } else { result.StoreFax = vatTaxDeclaration.StoreFax; } if (vatTaxDeclaration.StoreEmail.Trim() == "") { if (storeInfo != null) { result.StoreEmail = storeInfo.Email; } } else { result.StoreEmail = vatTaxDeclaration.StoreEmail; } // Tax agent info result.VatAgentOwnerName = vatTaxDeclaration.TaxAgentOwnerName; result.VatAgentTaxCode = vatTaxDeclaration.TaxAgentTaxCode; result.VatAgentName = vatTaxDeclaration.TaxAgentName; result.VatAgentNo = vatTaxDeclaration.TaxAgentNo; result.VatAgentAddress = vatTaxDeclaration.TaxAgentAddress; result.VatAgentDistrict = vatTaxDeclaration.TaxAgentDistrict; result.VatAgentProvince = vatTaxDeclaration.TaxAgentProvince; result.VatAgentPhone = vatTaxDeclaration.TaxAgentPhone; result.VatAgentFax = vatTaxDeclaration.TaxAgentFax; result.VatAgentEmail = vatTaxDeclaration.TaxAgentEmail; result.Value21 = (vatTaxDeclaration.Value21 == 1); result.Value22 = vatTaxDeclaration.Value22.Value; result.Value25 = vatTaxDeclaration.Value25.Value; result.Value36 = vatTaxDeclaration.Value36.Value; result.Value37 = vatTaxDeclaration.Value37.Value; result.Value38 = vatTaxDeclaration.Value38.Value; result.Value39 = vatTaxDeclaration.Value39.Value; result.Value40 = vatTaxDeclaration.Value40.Value; result.Value40A = vatTaxDeclaration.Value40a.Value; result.Value40B = vatTaxDeclaration.Value40b.Value; result.Value41 = vatTaxDeclaration.Value41.Value; result.Value42 = vatTaxDeclaration.Value42.Value; result.Value43 = vatTaxDeclaration.Value43.Value; #region Input if (!vatTaxDeclaration.InputCategory1.Trim().IsEmpty()) { List<DeclarationVatCategory> inputCategory1List = new List<DeclarationVatCategory>(); string[] inputCategory1ListString = vatTaxDeclaration.InputCategory1.Split(';'); foreach (string s in inputCategory1ListString) { string[] inputCategory1String = s.Split(','); if (inputCategory1String.Length == 7) { DeclarationVatCategory inputCategory1 = new DeclarationVatCategory(); inputCategory1.Column2 = inputCategory1String[0]; inputCategory1.Column3 = DateTime.ParseExact(inputCategory1String[1], "yyyy-MM-dd", CultureInfo.InvariantCulture); inputCategory1.Column4 = inputCategory1String[2]; inputCategory1.Column5 = inputCategory1String[3]; inputCategory1.Column6 = Convert.ToInt32(inputCategory1String[4]); inputCategory1.Column7 = Convert.ToInt32(inputCategory1String[5]); inputCategory1.Column8 = inputCategory1String[6]; inputCategory1List.Add(inputCategory1); } } result.InputCategories1 = inputCategory1List; } if (!vatTaxDeclaration.InputCategory2.Trim().IsEmpty()) { List<DeclarationVatCategory> inputCategory2List = new List<DeclarationVatCategory>(); string[] inputCategory2ListString = vatTaxDeclaration.InputCategory2.Split(';'); foreach (string s in inputCategory2ListString) { string[] inputCategory2String = s.Split(','); if (inputCategory2String.Length == 7) { DeclarationVatCategory inputCategory2 = new DeclarationVatCategory(); inputCategory2.Column2 = inputCategory2String[0]; inputCategory2.Column3 = DateTime.ParseExact(inputCategory2String[1], "yyyy-MM-dd", CultureInfo.InvariantCulture); inputCategory2.Column4 = inputCategory2String[2]; inputCategory2.Column5 = inputCategory2String[3]; inputCategory2.Column6 = Convert.ToInt32(inputCategory2String[4]); inputCategory2.Column7 = Convert.ToInt32(inputCategory2String[5]); inputCategory2.Column8 = inputCategory2String[6]; inputCategory2List.Add(inputCategory2); } } result.InputCategories2 = inputCategory2List; } if (!vatTaxDeclaration.InputCategory3.Trim().IsEmpty()) { List<DeclarationVatCategory> inputCategory3List = new List<DeclarationVatCategory>(); string[] inputCategory3ListString = vatTaxDeclaration.InputCategory3.Split(';'); foreach (string s in inputCategory3ListString) { string[] inputCategory3String = s.Split(','); if (inputCategory3String.Length == 7) { DeclarationVatCategory inputCategory3 = new DeclarationVatCategory(); inputCategory3.Column2 = inputCategory3String[0]; inputCategory3.Column3 = DateTime.ParseExact(inputCategory3String[1], "yyyy-MM-dd", CultureInfo.InvariantCulture); inputCategory3.Column4 = inputCategory3String[2]; inputCategory3.Column5 = inputCategory3String[3]; inputCategory3.Column6 = Convert.ToInt32(inputCategory3String[4]); inputCategory3.Column7 = Convert.ToInt32(inputCategory3String[5]); inputCategory3.Column8 = inputCategory3String[6]; inputCategory3List.Add(inputCategory3); } } result.InputCategories3 = inputCategory3List; } #endregion #region Output if (!vatTaxDeclaration.OutputCategory1.Trim().IsEmpty()) { List<DeclarationVatCategory> outputCategory1List = new List<DeclarationVatCategory>(); string[] outputCategory1ListString = vatTaxDeclaration.OutputCategory1.Split(';'); foreach (string s in outputCategory1ListString) { string[] outputCategory1String = s.Split(','); if (outputCategory1String.Length == 7) { DeclarationVatCategory outputCategory1 = new DeclarationVatCategory(); outputCategory1.Column2 = outputCategory1String[0]; outputCategory1.Column3 = DateTime.ParseExact(outputCategory1String[1], "yyyy-MM-dd", CultureInfo.InvariantCulture); outputCategory1.Column4 = outputCategory1String[2]; outputCategory1.Column5 = outputCategory1String[3]; outputCategory1.Column6 = Convert.ToInt32(outputCategory1String[4]); outputCategory1.Column7 = Convert.ToInt32(outputCategory1String[5]); outputCategory1.Column8 = outputCategory1String[6]; outputCategory1List.Add(outputCategory1); } } result.OutputCategories1 = outputCategory1List; } if (!vatTaxDeclaration.OutputCategory2.Trim().IsEmpty()) { List<DeclarationVatCategory> outputCategory2List = new List<DeclarationVatCategory>(); string[] outputCategory2ListString = vatTaxDeclaration.OutputCategory2.Split(';'); foreach (string s in outputCategory2ListString) { string[] outputCategory2String = s.Split(','); if (outputCategory2String.Length == 7) { DeclarationVatCategory outputCategory2 = new DeclarationVatCategory(); outputCategory2.Column2 = outputCategory2String[0]; outputCategory2.Column3 = DateTime.ParseExact(outputCategory2String[1], "yyyy-MM-dd", CultureInfo.InvariantCulture); outputCategory2.Column4 = outputCategory2String[2]; outputCategory2.Column5 = outputCategory2String[3]; outputCategory2.Column6 = Convert.ToInt32(outputCategory2String[4]); outputCategory2.Column7 = Convert.ToInt32(outputCategory2String[5]); outputCategory2.Column8 = outputCategory2String[6]; outputCategory2List.Add(outputCategory2); } } result.OutputCategories2 = outputCategory2List; } if (!vatTaxDeclaration.OutputCategory3.Trim().IsEmpty()) { List<DeclarationVatCategory> outputCategory3List = new List<DeclarationVatCategory>(); string[] outputCategory3ListString = vatTaxDeclaration.OutputCategory3.Split(';'); foreach (string s in outputCategory3ListString) { string[] outputCategory3String = s.Split(','); if (outputCategory3String.Length == 7) { DeclarationVatCategory outputCategory3 = new DeclarationVatCategory(); outputCategory3.Column2 = outputCategory3String[0]; outputCategory3.Column3 = DateTime.ParseExact(outputCategory3String[1], "yyyy-MM-dd", CultureInfo.InvariantCulture); outputCategory3.Column4 = outputCategory3String[2]; outputCategory3.Column5 = outputCategory3String[3]; outputCategory3.Column6 = Convert.ToInt32(outputCategory3String[4]); outputCategory3.Column7 = Convert.ToInt32(outputCategory3String[5]); outputCategory3.Column8 = outputCategory3String[6]; outputCategory3List.Add(outputCategory3); } } result.OutputCategories3 = outputCategory3List; } if (!vatTaxDeclaration.OutputCategory4.Trim().IsEmpty()) { List<DeclarationVatCategory> outputCategory4List = new List<DeclarationVatCategory>(); string[] outputCategory4ListString = vatTaxDeclaration.OutputCategory4.Split(';'); foreach (string s in outputCategory4ListString) { string[] outputCategory4String = s.Split(','); if (outputCategory4String.Length == 7) { DeclarationVatCategory outputCategory4 = new DeclarationVatCategory(); outputCategory4.Column2 = outputCategory4String[0]; outputCategory4.Column3 = DateTime.ParseExact(outputCategory4String[1], "yyyy-MM-dd", CultureInfo.InvariantCulture); outputCategory4.Column4 = outputCategory4String[2]; outputCategory4.Column5 = outputCategory4String[3]; outputCategory4.Column6 = Convert.ToInt32(outputCategory4String[4]); outputCategory4.Column7 = Convert.ToInt32(outputCategory4String[5]); outputCategory4.Column8 = outputCategory4String[6]; outputCategory4List.Add(outputCategory4); } } result.OutputCategories4 = outputCategory4List; } #endregion result.InputCategories1TotalAmount = vatTaxDeclaration.InputCategory1TotalAmount ?? 0; result.InputCategories2TotalAmount = vatTaxDeclaration.InputCategory2TotalAmount ?? 0; result.InputCategories3TotalAmount = vatTaxDeclaration.InputCategory3TotalAmount ?? 0; result.InputCategories1TotalTaxAmount = vatTaxDeclaration.InputCategory1TotalTaxAmount ?? 0; result.InputCategories2TotalTaxAmount = vatTaxDeclaration.InputCategory2TotalTaxAmount ?? 0; result.InputCategories3TotalTaxAmount = vatTaxDeclaration.InputCategory3TotalTaxAmount ?? 0; result.InputTotalAmount = vatTaxDeclaration.InputTotalAmountValue23; result.InputTotalTaxAmount = vatTaxDeclaration.InputTotalTaxAmountValue24; result.OutputCategories1TotalAmount = vatTaxDeclaration.OutputCategory1TotalAmountValue26 ?? 0; result.OutputCategories2TotalAmount = vatTaxDeclaration.OutputCategory2TotalAmountValue29 ?? 0; result.OutputCategories3TotalAmount = vatTaxDeclaration.OutputCategory3TotalAmountValue30 ?? 0; result.OutputCategories4TotalAmount = vatTaxDeclaration.OutputCategory4TotalAmountValue32 ?? 0; result.OutputCategories3TotalTaxAmount = vatTaxDeclaration.OutputCategory3TotalTaxAmountValue31 ?? 0; result.OutputCategories4TotalTaxAmount = vatTaxDeclaration.OutputCategory4TotalTaxAmountValue33 ?? 0; result.OutputTotalAmount = vatTaxDeclaration.OutputTotalAmountValue34; result.HaveTaxOutputAmount = vatTaxDeclaration.HaveTaxOutputTotalAmountValue27; result.OutputTotalTaxAmount = vatTaxDeclaration.OutputTotalTaxAmountValue28; if (result.InputTotalAmount == 0 && result.OutputCategories1TotalAmount == 0 && result.HaveTaxOutputAmount == 0) { result.Value21 = true; } else { result.Value21 = false; } } return result; }
public ActionResult ExportVatTaxDeclaration(FormCollection form) { try { #region Get data from Form string taxQuarter = form["taxQuarter"]; string taxYear = form["taxYear"]; 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 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 value20No = form["value20No"]; string value20Date = form["value20Date"]; string value21 = form["value21"]; string value22 = form["value22"].Replace(".", ""); string value25 = form["value25"].Replace(".", ""); string value36 = form["value36"].Replace(".", ""); string value37 = form["value37"].Replace(".", ""); string value38 = form["value38"].Replace(".", ""); string value39 = form["value39"].Replace(".", ""); string value40a = form["value40a"].Replace(".", ""); string value40b = form["value40b"].Replace(".", ""); string value40 = form["value40"].Replace(".", ""); string value41 = form["value41"].Replace(".", ""); string value42 = form["value42"].Replace(".", ""); string value43 = form["value43"].Replace(".", ""); string signName = form["signName"]; string createDate = form["createDate"]; string createLocation = form["createLocation"]; string outputCategory1Column2 = form["output_category1_column2"]; string outputCategory1Column3 = form["output_category1_column3"]; string outputCategory1Column4 = form["output_category1_column4"]; string outputCategory1Column5 = form["output_category1_column5"]; string outputCategory1Column6 = form["output_category1_column6"]; string outputCategory1Column7 = form["output_category1_column7"]; string outputCategory1Column8 = form["output_category1_column8"]; string outputCategory2Column2 = form["output_category2_column2"]; string outputCategory2Column3 = form["output_category2_column3"]; string outputCategory2Column4 = form["output_category2_column4"]; string outputCategory2Column5 = form["output_category2_column5"]; string outputCategory2Column6 = form["output_category2_column6"]; string outputCategory2Column7 = form["output_category2_column7"]; string outputCategory2Column8 = form["output_category2_column8"]; string outputCategory3Column2 = form["output_category3_column2"]; string outputCategory3Column3 = form["output_category3_column3"]; string outputCategory3Column4 = form["output_category3_column4"]; string outputCategory3Column5 = form["output_category3_column5"]; string outputCategory3Column6 = form["output_category3_column6"]; string outputCategory3Column7 = form["output_category3_column7"]; string outputCategory3Column8 = form["output_category3_column8"]; string outputCategory4Column2 = form["output_category4_column2"]; string outputCategory4Column3 = form["output_category4_column3"]; string outputCategory4Column4 = form["output_category4_column4"]; string outputCategory4Column5 = form["output_category4_column5"]; string outputCategory4Column6 = form["output_category4_column6"]; string outputCategory4Column7 = form["output_category4_column7"]; string outputCategory4Column8 = form["output_category4_column8"]; string inputCategory1Column2 = form["input_category1_column2"]; string inputCategory1Column3 = form["input_category1_column3"]; string inputCategory1Column4 = form["input_category1_column4"]; string inputCategory1Column5 = form["input_category1_column5"]; string inputCategory1Column6 = form["input_category1_column6"]; string inputCategory1Column7 = form["input_category1_column7"]; string inputCategory1Column8 = form["input_category1_column8"]; string inputCategory2Column2 = form["input_category2_column2"]; string inputCategory2Column3 = form["input_category2_column3"]; string inputCategory2Column4 = form["input_category2_column4"]; string inputCategory2Column5 = form["input_category2_column5"]; string inputCategory2Column6 = form["input_category2_column6"]; string inputCategory2Column7 = form["input_category2_column7"]; string inputCategory2Column8 = form["input_category2_column8"]; string inputCategory3Column2 = form["input_category3_column2"]; string inputCategory3Column3 = form["input_category3_column3"]; string inputCategory3Column4 = form["input_category3_column4"]; string inputCategory3Column5 = form["input_category3_column5"]; string inputCategory3Column6 = form["input_category3_column6"]; string inputCategory3Column7 = form["input_category3_column7"]; string inputCategory3Column8 = form["input_category3_column8"]; #endregion #region Process Data DeclarationVatForm vatForm = new DeclarationVatForm(); #region Output int totalOutputAmount = 0; int haveTaxTotalOutputAmount = 0; int totalTaxOutputAmount = 0; #region OutputCategory1 List<DeclarationVatCategory> outputCategory1List = new List<DeclarationVatCategory>(); if (outputCategory1Column4 != null) { string[] outputCategory1Column2Array = outputCategory1Column2.Split(','); string[] outputCategory1Column3Array = outputCategory1Column3.Split(','); string[] outputCategory1Column4Array = outputCategory1Column4.Split(','); string[] outputCategory1Column5Array = outputCategory1Column5.Split(','); string[] outputCategory1Column6Array = outputCategory1Column6.Split(','); string[] outputCategory1Column7Array = outputCategory1Column7.Split(','); string[] outputCategory1Column8Array = outputCategory1Column8.Split(','); int totalOutputCategory1 = 0; for (int i = 0; i < outputCategory1Column4Array.Length; i++) { DeclarationVatCategory outputCategory1 = new DeclarationVatCategory(); outputCategory1.Column2 = outputCategory1Column2Array[i]; outputCategory1.Column3 = DateTime.ParseExact(outputCategory1Column3Array[i], "yyyy-MM-dd", CultureInfo.InvariantCulture); outputCategory1.Column4 = outputCategory1Column4Array[i]; outputCategory1.Column5 = outputCategory1Column5Array[i]; outputCategory1.Column6 = Convert.ToInt32(outputCategory1Column6Array[i].Replace(".", "")); outputCategory1.Column7 = Convert.ToInt32(outputCategory1Column7Array[i].Replace(".", "")); outputCategory1.Column8 = outputCategory1Column8Array[i]; int categoryColumn6Number = Convert.ToInt32(outputCategory1Column6Array[i].Replace(".", "")); totalOutputCategory1 += categoryColumn6Number; outputCategory1List.Add(outputCategory1); } vatForm.OutputCategories1TotalAmount = totalOutputCategory1; totalOutputAmount += totalOutputCategory1; } vatForm.OutputCategories1 = outputCategory1List; #endregion #region OutputCategory2 List<DeclarationVatCategory> outputCategory2List = new List<DeclarationVatCategory>(); if (outputCategory2Column4 != null) { string[] outputCategory2Column2Array = outputCategory2Column2.Split(','); string[] outputCategory2Column3Array = outputCategory2Column3.Split(','); string[] outputCategory2Column4Array = outputCategory2Column4.Split(','); string[] outputCategory2Column5Array = outputCategory2Column5.Split(','); string[] outputCategory2Column6Array = outputCategory2Column6.Split(','); string[] outputCategory2Column7Array = outputCategory2Column7.Split(','); string[] outputCategory2Column8Array = outputCategory2Column8.Split(','); int totalOutputCategory2 = 0; for (int i = 0; i < outputCategory2Column4Array.Length; i++) { DeclarationVatCategory outputCategory2 = new DeclarationVatCategory(); outputCategory2.Column2 = outputCategory2Column2Array[i]; outputCategory2.Column3 = DateTime.ParseExact(outputCategory2Column3Array[i], "yyyy-MM-dd", CultureInfo.InvariantCulture); outputCategory2.Column4 = outputCategory2Column4Array[i]; outputCategory2.Column5 = outputCategory2Column5Array[i]; outputCategory2.Column6 = Convert.ToInt32(outputCategory2Column6Array[i].Replace(".", "")); outputCategory2.Column7 = Convert.ToInt32(outputCategory2Column7Array[i].Replace(".", "")); outputCategory2.Column8 = outputCategory2Column8Array[i]; int categoryColumn6Number = Convert.ToInt32(outputCategory2Column6Array[i].Replace(".", "")); totalOutputCategory2 += categoryColumn6Number; outputCategory2List.Add(outputCategory2); } vatForm.OutputCategories2TotalAmount = totalOutputCategory2; haveTaxTotalOutputAmount += totalOutputCategory2; totalOutputAmount += totalOutputCategory2; } vatForm.OutputCategories2 = outputCategory2List; #endregion #region OutputCategory3 List<DeclarationVatCategory> outputCategory3List = new List<DeclarationVatCategory>(); if (outputCategory3Column4 != null) { string[] outputCategory3Column2Array = outputCategory3Column2.Split(','); string[] outputCategory3Column3Array = outputCategory3Column3.Split(','); string[] outputCategory3Column4Array = outputCategory3Column4.Split(','); string[] outputCategory3Column5Array = outputCategory3Column5.Split(','); string[] outputCategory3Column6Array = outputCategory3Column6.Split(','); string[] outputCategory3Column7Array = outputCategory3Column7.Split(','); string[] outputCategory3Column8Array = outputCategory3Column8.Split(','); int totalOutputCategory3 = 0; int totalTaxOutputCategory3 = 0; for (int i = 0; i < outputCategory3Column4Array.Length; i++) { DeclarationVatCategory outputCategory3 = new DeclarationVatCategory(); outputCategory3.Column2 = outputCategory3Column2Array[i]; outputCategory3.Column3 = DateTime.ParseExact(outputCategory3Column3Array[i], "yyyy-MM-dd", CultureInfo.InvariantCulture); outputCategory3.Column4 = outputCategory3Column4Array[i]; outputCategory3.Column5 = outputCategory3Column5Array[i]; outputCategory3.Column6 = Convert.ToInt32(outputCategory3Column6Array[i].Replace(".", "")); outputCategory3.Column7 = Convert.ToInt32(outputCategory3Column7Array[i].Replace(".", "")); outputCategory3.Column8 = outputCategory3Column8Array[i]; int categoryColumn6Number = Convert.ToInt32(outputCategory3Column6Array[i].Replace(".", "")); totalOutputCategory3 += categoryColumn6Number; int categoryColumn7Number = Convert.ToInt32(outputCategory3Column7Array[i].Replace(".", "")); totalTaxOutputCategory3 += categoryColumn7Number; outputCategory3List.Add(outputCategory3); } vatForm.OutputCategories3TotalAmount = totalOutputCategory3; vatForm.OutputCategories3TotalTaxAmount = totalTaxOutputCategory3; totalOutputAmount += totalOutputCategory3; haveTaxTotalOutputAmount += totalOutputCategory3; totalTaxOutputAmount += totalTaxOutputCategory3; } vatForm.OutputCategories3 = outputCategory3List; #endregion #region OutputCategory4 List<DeclarationVatCategory> outputCategory4List = new List<DeclarationVatCategory>(); if (outputCategory4Column4 != null) { string[] outputCategory4Column2Array = outputCategory4Column2.Split(','); string[] outputCategory4Column3Array = outputCategory4Column3.Split(','); string[] outputCategory4Column4Array = outputCategory4Column4.Split(','); string[] outputCategory4Column5Array = outputCategory4Column5.Split(','); string[] outputCategory4Column6Array = outputCategory4Column6.Split(','); string[] outputCategory4Column7Array = outputCategory4Column7.Split(','); string[] outputCategory4Column8Array = outputCategory4Column8.Split(','); int totalOutputCategory4 = 0; int totalTaxOutputCategory4 = 0; for (int i = 0; i < outputCategory4Column4Array.Length; i++) { DeclarationVatCategory outputCategory4 = new DeclarationVatCategory(); outputCategory4.Column2 = outputCategory4Column2Array[i]; outputCategory4.Column3 = DateTime.ParseExact(outputCategory4Column3Array[i], "yyyy-MM-dd", CultureInfo.InvariantCulture); outputCategory4.Column4 = outputCategory4Column4Array[i]; outputCategory4.Column5 = outputCategory4Column5Array[i]; outputCategory4.Column6 = Convert.ToInt32(outputCategory4Column6Array[i].Replace(".", "")); outputCategory4.Column7 = Convert.ToInt32(outputCategory4Column7Array[i].Replace(".", "")); outputCategory4.Column8 = outputCategory4Column8Array[i]; int categoryColumn6Number = Convert.ToInt32(outputCategory4Column6Array[i].Replace(".", "")); totalOutputCategory4 += categoryColumn6Number; int categoryColumn7Number = Convert.ToInt32(outputCategory4Column7Array[i].Replace(".", "")); totalTaxOutputCategory4 += categoryColumn7Number; outputCategory4List.Add(outputCategory4); } vatForm.OutputCategories4TotalAmount = totalOutputCategory4; vatForm.OutputCategories4TotalTaxAmount = totalTaxOutputCategory4; totalOutputAmount += totalOutputCategory4; haveTaxTotalOutputAmount += totalOutputCategory4; totalTaxOutputAmount += totalTaxOutputCategory4; } vatForm.OutputCategories4 = outputCategory4List; #endregion vatForm.OutputTotalAmount = totalOutputAmount; vatForm.OutputTotalTaxAmount = totalTaxOutputAmount; vatForm.HaveTaxOutputAmount = haveTaxTotalOutputAmount; #endregion #region Input int totalInputAmount = 0; int totalTaxInputAmount = 0; #region InputCategory1 List<DeclarationVatCategory> inputCategory1List = new List<DeclarationVatCategory>(); if (inputCategory1Column4 != null) { string[] inputCategory1Column2Array = inputCategory1Column2.Split(','); string[] inputCategory1Column3Array = inputCategory1Column3.Split(','); string[] inputCategory1Column4Array = inputCategory1Column4.Split(','); string[] inputCategory1Column5Array = inputCategory1Column5.Split(','); string[] inputCategory1Column6Array = inputCategory1Column6.Split(','); string[] inputCategory1Column7Array = inputCategory1Column7.Split(','); string[] inputCategory1Column8Array = inputCategory1Column8.Split(','); int totalInputCategory1 = 0; int totalTaxInputCategory1 = 0; for (int i = 0; i < inputCategory1Column4Array.Length; i++) { DeclarationVatCategory inputCategory1 = new DeclarationVatCategory(); inputCategory1.Column2 = inputCategory1Column2Array[i]; inputCategory1.Column3 = DateTime.ParseExact(inputCategory1Column3Array[i], "yyyy-MM-dd", CultureInfo.InvariantCulture); inputCategory1.Column4 = inputCategory1Column4Array[i]; inputCategory1.Column5 = inputCategory1Column5Array[i]; inputCategory1.Column6 = Convert.ToInt32(inputCategory1Column6Array[i].Replace(".", "")); inputCategory1.Column7 = Convert.ToInt32(inputCategory1Column7Array[i].Replace(".", "")); inputCategory1.Column8 = inputCategory1Column8Array[i]; int categoryColumn6Number = Convert.ToInt32(inputCategory1Column6Array[i].Replace(".", "")); totalInputCategory1 += categoryColumn6Number; int categoryColumn7Number = Convert.ToInt32(inputCategory1Column7Array[i].Replace(".", "")); totalTaxInputCategory1 += categoryColumn7Number; inputCategory1List.Add(inputCategory1); } vatForm.InputCategories1TotalAmount = totalInputCategory1; vatForm.InputCategories1TotalTaxAmount = totalTaxInputCategory1; totalInputAmount += totalInputCategory1; totalTaxInputAmount += totalTaxInputCategory1; } vatForm.InputCategories1 = inputCategory1List; #endregion #region InputCategory2 List<DeclarationVatCategory> inputCategory2List = new List<DeclarationVatCategory>(); if (inputCategory2Column4 != null) { string[] inputCategory2Column2Array = inputCategory2Column2.Split(','); string[] inputCategory2Column3Array = inputCategory2Column3.Split(','); string[] inputCategory2Column4Array = inputCategory2Column4.Split(','); string[] inputCategory2Column5Array = inputCategory2Column5.Split(','); string[] inputCategory2Column6Array = inputCategory2Column6.Split(','); string[] inputCategory2Column7Array = inputCategory2Column7.Split(','); string[] inputCategory2Column8Array = inputCategory2Column8.Split(','); int totalInputCategory2 = 0; int totalTaxInputCategory2 = 0; for (int i = 0; i < inputCategory2Column4Array.Length; i++) { DeclarationVatCategory inputCategory2 = new DeclarationVatCategory(); inputCategory2.Column2 = inputCategory2Column2Array[i]; inputCategory2.Column3 = DateTime.ParseExact(inputCategory2Column3Array[i], "yyyy-MM-dd", CultureInfo.InvariantCulture); inputCategory2.Column4 = inputCategory2Column4Array[i]; inputCategory2.Column5 = inputCategory2Column5Array[i]; inputCategory2.Column6 = Convert.ToInt32(inputCategory2Column6Array[i].Replace(".", "")); inputCategory2.Column7 = Convert.ToInt32(inputCategory2Column7Array[i].Replace(".", "")); inputCategory2.Column8 = inputCategory2Column8Array[i]; int categoryColumn6Number = Convert.ToInt32(inputCategory2Column6Array[i].Replace(".", "")); totalInputCategory2 += categoryColumn6Number; int categoryColumn7Number = Convert.ToInt32(inputCategory2Column7Array[i].Replace(".", "")); totalTaxInputCategory2 += categoryColumn7Number; inputCategory2List.Add(inputCategory2); } vatForm.InputCategories2TotalAmount = totalInputCategory2; vatForm.InputCategories2TotalTaxAmount = totalTaxInputCategory2; totalInputAmount += totalInputCategory2; totalTaxInputAmount += totalTaxInputCategory2; } vatForm.InputCategories2 = inputCategory2List; #endregion #region InputCategory3 List<DeclarationVatCategory> inputCategory3List = new List<DeclarationVatCategory>(); if (inputCategory3Column4 != null) { string[] inputCategory3Column2Array = inputCategory3Column2.Split(','); string[] inputCategory3Column3Array = inputCategory3Column3.Split(','); string[] inputCategory3Column4Array = inputCategory3Column4.Split(','); string[] inputCategory3Column5Array = inputCategory3Column5.Split(','); string[] inputCategory3Column6Array = inputCategory3Column6.Split(','); string[] inputCategory3Column7Array = inputCategory3Column7.Split(','); string[] inputCategory3Column8Array = inputCategory3Column8.Split(','); int totalInputCategory3 = 0; int totalTaxInputCategory3 = 0; for (int i = 0; i < inputCategory3Column4Array.Length; i++) { DeclarationVatCategory inputCategory3 = new DeclarationVatCategory(); inputCategory3.Column2 = inputCategory3Column2Array[i]; inputCategory3.Column3 = DateTime.ParseExact(inputCategory3Column3Array[i], "yyyy-MM-dd", CultureInfo.InvariantCulture); inputCategory3.Column4 = inputCategory3Column4Array[i]; inputCategory3.Column5 = inputCategory3Column5Array[i]; inputCategory3.Column6 = Convert.ToInt32(inputCategory3Column6Array[i].Replace(".", "")); inputCategory3.Column7 = Convert.ToInt32(inputCategory3Column7Array[i].Replace(".", "")); inputCategory3.Column8 = inputCategory3Column8Array[i]; int categoryColumn6Number = Convert.ToInt32(inputCategory3Column6Array[i].Replace(".", "")); totalInputCategory3 += categoryColumn6Number; int categoryColumn7Number = Convert.ToInt32(inputCategory3Column7Array[i].Replace(".", "")); totalTaxInputCategory3 += categoryColumn7Number; inputCategory3List.Add(inputCategory3); } vatForm.InputCategories3TotalAmount = totalInputCategory3; vatForm.InputCategories3TotalTaxAmount = totalTaxInputCategory3; } vatForm.InputCategories3 = inputCategory3List; #endregion vatForm.InputTotalAmount = totalInputAmount; vatForm.InputTotalTaxAmount = totalTaxInputAmount; #endregion #endregion #region Create XML File XElement root = new XElement("HSoThueDTu"); XElement HSoKhaiThue = new XElement("HSoKhaiThue"); HSoKhaiThue.Add(new XAttribute("id", "ID_18")); 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", "01"); TKhaiThue.Add(maTKhai); XElement tenTKhai = new XElement("tenTKhai", "TỜ KHAI THUẾ GIÁ TRỊ GIA TĂNG (Mẫu số 01/GTGT)"); TKhaiThue.Add(tenTKhai); XElement moTaBMau = new XElement("moTaBMau", "(Ban hành kèm theo Thông tư số 119/2014/TT-BTC ngày 25/8/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", "Q"); KyKKhaiThue.Add(kieuKy); XElement kyKKhai = new XElement("kyKKhai", taxQuarter + "/" + taxYear); KyKKhaiThue.Add(kyKKhai); XElement kyKKhaiTuNgay = new XElement("kyKKhaiTuNgay", "01/" + (Convert.ToInt32(taxQuarter) * 3 - 2) + "/" + taxYear); KyKKhaiThue.Add(kyKKhaiTuNgay); XElement kyKKhaiDenNgay = new XElement("kyKKhaiDenNgay", new DateTime(Convert.ToInt32(taxYear), (Convert.ToInt32(taxQuarter) * 3), 1).AddMonths(1).AddDays(-1).ToString("dd/MM/yyyy")); 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); XElement GiaHan = new XElement("GiaHan"); XElement maLyDoGiaHan = new XElement("maLyDoGiaHan"); GiaHan.Add(maLyDoGiaHan); XElement lyDoGiaHan = new XElement("lyDoGiaHan"); GiaHan.Add(lyDoGiaHan); 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", storeTaxcode); NNT.Add(mst); XElement tenNNT = new XElement("tenNNT", storeOwnerName); NNT.Add(tenNNT); XElement dchiNNT = new XElement("dchiNNT", 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", storeDistrict); NNT.Add(tenHuyenNNT); XElement maTinhNNT = new XElement("maTinhNNT"); NNT.Add(maTinhNNT); XElement tenTinhNNT = new XElement("tenTinhNNT", storeProvince); NNT.Add(tenTinhNNT); XElement dthoaiNNT = new XElement("dthoaiNNT", storePhone); NNT.Add(dthoaiNNT); XElement faxNNT = new XElement("faxNNT", storeFax); NNT.Add(faxNNT); XElement emailNNT = new XElement("emailNNT", storeEmail); NNT.Add(emailNNT); TTinTKhaiThue.Add(NNT); XElement DLyThue = new XElement("DLyThue"); XElement mstDLyThue = new XElement("mstDLyThue", vatAgentTaxCode); 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", value20No); DLyThue.Add(soHDongDLyThue); XElement ngayKyHDDLyThue = new XElement("ngayKyHDDLyThue", value20Date); 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", "1701"); CTieuTKhaiChinh.Add(tieuMucHachToan); XElement ct21 = new XElement("ct21", value21); CTieuTKhaiChinh.Add(ct21); XElement ct22 = new XElement("ct22", value22); CTieuTKhaiChinh.Add(ct22); XElement GiaTriVaThueGTGTHHDVMuaVao = new XElement("GiaTriVaThueGTGTHHDVMuaVao"); XElement ct23 = new XElement("ct23", vatForm.InputTotalAmount); GiaTriVaThueGTGTHHDVMuaVao.Add(ct23); XElement ct24 = new XElement("ct24", vatForm.InputTotalTaxAmount); GiaTriVaThueGTGTHHDVMuaVao.Add(ct24); CTieuTKhaiChinh.Add(GiaTriVaThueGTGTHHDVMuaVao); XElement ct25 = new XElement("ct25", value25); CTieuTKhaiChinh.Add(ct25); XElement ct26 = new XElement("ct26", vatForm.OutputCategories1TotalAmount); CTieuTKhaiChinh.Add(ct26); XElement HHDVBRaChiuThueGTGT = new XElement("HHDVBRaChiuThueGTGT"); XElement ct27 = new XElement("ct27", vatForm.HaveTaxOutputAmount); HHDVBRaChiuThueGTGT.Add(ct27); XElement ct28 = new XElement("ct28", vatForm.OutputTotalTaxAmount); HHDVBRaChiuThueGTGT.Add(ct28); CTieuTKhaiChinh.Add(HHDVBRaChiuThueGTGT); XElement ct29 = new XElement("ct29", vatForm.OutputCategories2TotalAmount); CTieuTKhaiChinh.Add(ct29); XElement HHDVBRaChiuTSuat5 = new XElement("HHDVBRaChiuTSuat5"); XElement ct30 = new XElement("ct30", vatForm.OutputCategories3TotalAmount); HHDVBRaChiuTSuat5.Add(ct30); XElement ct31 = new XElement("ct31", vatForm.OutputCategories3TotalTaxAmount); HHDVBRaChiuTSuat5.Add(ct31); CTieuTKhaiChinh.Add(HHDVBRaChiuTSuat5); XElement HHDVBRaChiuTSuat10 = new XElement("HHDVBRaChiuTSuat10"); XElement ct32 = new XElement("ct32", vatForm.OutputCategories4TotalAmount); HHDVBRaChiuTSuat10.Add(ct32); XElement ct33 = new XElement("ct33", vatForm.OutputCategories4TotalTaxAmount); HHDVBRaChiuTSuat10.Add(ct33); CTieuTKhaiChinh.Add(HHDVBRaChiuTSuat10); XElement TongDThuVaThueGTGTHHDVBRa = new XElement("TongDThuVaThueGTGTHHDVBRa"); XElement ct34 = new XElement("ct34", vatForm.OutputTotalAmount); TongDThuVaThueGTGTHHDVBRa.Add(ct34); XElement ct35 = new XElement("ct35", vatForm.OutputTotalTaxAmount); TongDThuVaThueGTGTHHDVBRa.Add(ct35); CTieuTKhaiChinh.Add(TongDThuVaThueGTGTHHDVBRa); XElement ct36 = new XElement("ct36", value36); CTieuTKhaiChinh.Add(ct36); XElement ct37 = new XElement("ct37", value37); CTieuTKhaiChinh.Add(ct37); XElement ct38 = new XElement("ct38", value38); CTieuTKhaiChinh.Add(ct38); XElement ct39 = new XElement("ct39", value39); CTieuTKhaiChinh.Add(ct39); XElement ct40 = new XElement("ct40", value40); CTieuTKhaiChinh.Add(ct40); XElement ct40a = new XElement("ct40a", value40a); CTieuTKhaiChinh.Add(ct40a); XElement ct40b = new XElement("ct40b", value40b); CTieuTKhaiChinh.Add(ct40b); XElement ct41 = new XElement("ct41", value41); CTieuTKhaiChinh.Add(ct41); XElement ct42 = new XElement("ct42", value42); CTieuTKhaiChinh.Add(ct42); XElement ct43 = new XElement("ct43", value43); CTieuTKhaiChinh.Add(ct43); HSoKhaiThue.Add(CTieuTKhaiChinh); XElement PLuc = new XElement("PLuc"); #region PL01_1_GTGT XElement PL01_1_GTGT = new XElement("PL01_1_GTGT"); XElement HHDVKChiuThue = new XElement("HHDVKChiuThue"); XElement ChiTietHHDVKChiuThue = new XElement("ChiTietHHDVKChiuThue"); if (vatForm.OutputCategories1 != null && vatForm.OutputCategories1.Count > 0) { for (int i = 0; i < vatForm.OutputCategories1.Count; i++) { XElement HDonBRa = new XElement("HDonBRa"); HDonBRa.Add(new XAttribute("id", "ID_" + (i + 1))); XElement kyHieuMauHDon = new XElement("kyHieuMauHDon"); HDonBRa.Add(kyHieuMauHDon); XElement kyHieuHDon = new XElement("kyHieuHDon"); HDonBRa.Add(kyHieuHDon); XElement soHDon = new XElement("soHDon", vatForm.OutputCategories1.ElementAt(i).Column2); HDonBRa.Add(soHDon); XElement ngayPHanh = new XElement("ngayPHanh", vatForm.OutputCategories1.ElementAt(i).Column3.ToString("yyyy-MM-dd")); HDonBRa.Add(ngayPHanh); XElement tenNMUA = new XElement("tenNMUA", vatForm.OutputCategories1.ElementAt(i).Column4); HDonBRa.Add(tenNMUA); XElement mstNMUA = new XElement("mstNMUA", vatForm.OutputCategories1.ElementAt(i).Column5); HDonBRa.Add(mstNMUA); XElement matHang = new XElement("matHang"); HDonBRa.Add(matHang); XElement dsoBanChuaThue = new XElement("dsoBanChuaThue", vatForm.OutputCategories1.ElementAt(i).Column6); HDonBRa.Add(dsoBanChuaThue); XElement thueGTGT = new XElement("thueGTGT", vatForm.OutputCategories1.ElementAt(i).Column7); HDonBRa.Add(thueGTGT); XElement ghiChu = new XElement("ghiChu", vatForm.OutputCategories1.ElementAt(i).Column8); ChiTietHHDVKChiuThue.Add(HDonBRa); } } HHDVKChiuThue.Add(ChiTietHHDVKChiuThue); XElement tongDThuBRaKChiuThue = new XElement("tongDThuBRaKChiuThue", vatForm.OutputCategories1TotalAmount); HHDVKChiuThue.Add(tongDThuBRaKChiuThue); PL01_1_GTGT.Add(HHDVKChiuThue); #region 0% XElement HHDVThue0 = new XElement("HHDVThue0"); XElement ChiTietHHDVThue0 = new XElement("ChiTietHHDVThue0"); if (vatForm.OutputCategories2 != null && vatForm.OutputCategories2.Count > 0) { for (int i = 0; i < vatForm.OutputCategories2.Count; i++) { XElement HDonBRa = new XElement("HDonBRa"); HDonBRa.Add(new XAttribute("id", "ID_" + (i + 1))); XElement kyHieuMauHDon = new XElement("kyHieuMauHDon"); HDonBRa.Add(kyHieuMauHDon); XElement kyHieuHDon = new XElement("kyHieuHDon"); HDonBRa.Add(kyHieuHDon); XElement soHDon = new XElement("soHDon", vatForm.OutputCategories2.ElementAt(i).Column2); HDonBRa.Add(soHDon); XElement ngayPHanh = new XElement("ngayPHanh", vatForm.OutputCategories2.ElementAt(i).Column3.ToString("yyyy-MM-dd")); HDonBRa.Add(ngayPHanh); XElement tenNMUA = new XElement("tenNMUA", vatForm.OutputCategories2.ElementAt(i).Column4); HDonBRa.Add(tenNMUA); XElement mstNMUA = new XElement("mstNMUA", vatForm.OutputCategories2.ElementAt(i).Column5); HDonBRa.Add(mstNMUA); XElement matHang = new XElement("matHang"); HDonBRa.Add(matHang); XElement dsoBanChuaThue = new XElement("dsoBanChuaThue", vatForm.OutputCategories2.ElementAt(i).Column6); HDonBRa.Add(dsoBanChuaThue); XElement thueGTGT = new XElement("thueGTGT", vatForm.OutputCategories2.ElementAt(i).Column7); HDonBRa.Add(thueGTGT); XElement ghiChu = new XElement("ghiChu", vatForm.OutputCategories2.ElementAt(i).Column8); ChiTietHHDVThue0.Add(HDonBRa); } } HHDVThue0.Add(ChiTietHHDVThue0); XElement tongDThuBRaThue0 = new XElement("tongDThuBRaKChiuThue", vatForm.OutputCategories1TotalAmount); HHDVThue0.Add(tongDThuBRaThue0); XElement tongThueBRaThue0 = new XElement("tongThueBRaThue0", "0"); HHDVThue0.Add(tongThueBRaThue0); PL01_1_GTGT.Add(HHDVThue0); #endregion #region 5% XElement HHDVThue5 = new XElement("HHDVThue5"); XElement ChiTietHHDVThue5 = new XElement("ChiTietHHDVThue5"); if (vatForm.OutputCategories3 != null && vatForm.OutputCategories3.Count > 0) { for (int i = 0; i < vatForm.OutputCategories3.Count; i++) { XElement HDonBRa = new XElement("HDonBRa"); HDonBRa.Add(new XAttribute("id", "ID_" + (i + 1))); XElement kyHieuMauHDon = new XElement("kyHieuMauHDon"); HDonBRa.Add(kyHieuMauHDon); XElement kyHieuHDon = new XElement("kyHieuHDon"); HDonBRa.Add(kyHieuHDon); XElement soHDon = new XElement("soHDon", vatForm.OutputCategories3.ElementAt(i).Column2); HDonBRa.Add(soHDon); XElement ngayPHanh = new XElement("ngayPHanh", vatForm.OutputCategories3.ElementAt(i).Column3.ToString("yyyy-MM-dd")); HDonBRa.Add(ngayPHanh); XElement tenNMUA = new XElement("tenNMUA", vatForm.OutputCategories3.ElementAt(i).Column4); HDonBRa.Add(tenNMUA); XElement mstNMUA = new XElement("mstNMUA", vatForm.OutputCategories3.ElementAt(i).Column5); HDonBRa.Add(mstNMUA); XElement matHang = new XElement("matHang"); HDonBRa.Add(matHang); XElement dsoBanChuaThue = new XElement("dsoBanChuaThue", vatForm.OutputCategories3.ElementAt(i).Column6); HDonBRa.Add(dsoBanChuaThue); XElement thueGTGT = new XElement("thueGTGT", vatForm.OutputCategories3.ElementAt(i).Column7); HDonBRa.Add(thueGTGT); XElement ghiChu = new XElement("ghiChu", vatForm.OutputCategories3.ElementAt(i).Column8); ChiTietHHDVThue5.Add(HDonBRa); } } HHDVThue5.Add(ChiTietHHDVThue5); XElement tongDThuBRaThue5 = new XElement("tongDThuBRaThue5", vatForm.OutputCategories3TotalAmount); HHDVThue5.Add(tongDThuBRaThue5); XElement tongThueBRaThue5 = new XElement("tongThueBRaThue5", vatForm.OutputCategories3TotalTaxAmount); HHDVThue5.Add(tongThueBRaThue5); PL01_1_GTGT.Add(HHDVThue5); #endregion #region 10% XElement HHDVThue10 = new XElement("HHDVThue10"); XElement ChiTietHHDVThue10 = new XElement("ChiTietHHDVThue10"); if (vatForm.OutputCategories4 != null && vatForm.OutputCategories4.Count > 0) { for (int i = 0; i < vatForm.OutputCategories4.Count; i++) { XElement HDonBRa = new XElement("HDonBRa"); HDonBRa.Add(new XAttribute("id", "ID_" + (i + 1))); XElement kyHieuMauHDon = new XElement("kyHieuMauHDon"); HDonBRa.Add(kyHieuMauHDon); XElement kyHieuHDon = new XElement("kyHieuHDon"); HDonBRa.Add(kyHieuHDon); XElement soHDon = new XElement("soHDon", vatForm.OutputCategories4.ElementAt(i).Column2); HDonBRa.Add(soHDon); XElement ngayPHanh = new XElement("ngayPHanh", vatForm.OutputCategories4.ElementAt(i).Column3.ToString("yyyy-MM-dd")); HDonBRa.Add(ngayPHanh); XElement tenNMUA = new XElement("tenNMUA", vatForm.OutputCategories4.ElementAt(i).Column4); HDonBRa.Add(tenNMUA); XElement mstNMUA = new XElement("mstNMUA", vatForm.OutputCategories4.ElementAt(i).Column5); HDonBRa.Add(mstNMUA); XElement matHang = new XElement("matHang"); HDonBRa.Add(matHang); XElement dsoBanChuaThue = new XElement("dsoBanChuaThue", vatForm.OutputCategories4.ElementAt(i).Column6); HDonBRa.Add(dsoBanChuaThue); XElement thueGTGT = new XElement("thueGTGT", vatForm.OutputCategories4.ElementAt(i).Column7); HDonBRa.Add(thueGTGT); XElement ghiChu = new XElement("ghiChu", vatForm.OutputCategories4.ElementAt(i).Column8); ChiTietHHDVThue10.Add(HDonBRa); } } HHDVThue10.Add(ChiTietHHDVThue10); XElement tongDThuBRaThue10 = new XElement("tongDThuBRaThue10", vatForm.OutputCategories4TotalAmount); HHDVThue10.Add(tongDThuBRaThue10); XElement tongThueBRaThue10 = new XElement("tongThueBRaThue10", vatForm.OutputCategories4TotalTaxAmount); HHDVThue10.Add(tongThueBRaThue10); PL01_1_GTGT.Add(HHDVThue10); #endregion XElement HHDVBRaKhongTHop = new XElement("HHDVBRaKhongTHop"); XElement ChiTietHHDVBRaKhongTHop = new XElement("ChiTietHHDVBRaKhongTHop"); HHDVBRaKhongTHop.Add(ChiTietHHDVBRaKhongTHop); XElement tongDThuBRaKoKKhai = new XElement("tongDThuBRaKoKKhai", "0"); HHDVBRaKhongTHop.Add(tongDThuBRaKoKKhai); XElement tongThueBRaKoKKhai = new XElement("tongThueBRaKoKKhai", "0"); HHDVBRaKhongTHop.Add(HHDVBRaKhongTHop); PL01_1_GTGT.Add(HHDVBRaKhongTHop); XElement tongDThuBRa = new XElement("tongDThuBRa", vatForm.OutputTotalAmount); PL01_1_GTGT.Add(tongDThuBRa); XElement tongDThuBRaChiuThue = new XElement("tongDThuBRaChiuThue", vatForm.HaveTaxOutputAmount); PL01_1_GTGT.Add(tongDThuBRaChiuThue); XElement tongThueBRa = new XElement("tongThueBRa", vatForm.OutputTotalTaxAmount); PL01_1_GTGT.Add(tongThueBRa); PLuc.Add(PL01_1_GTGT); #endregion #region PL01_2_GTGT XElement PL01_2_GTGT = new XElement("PL01_2_GTGT"); #region HHDVDRieng XElement HHDVDRieng = new XElement("HHDVDRieng"); XElement ChiTietHHDVDRieng = new XElement("ChiTietHHDVDRieng"); if (vatForm.InputCategories1 != null && vatForm.InputCategories1.Count > 0) { for (int i = 0; i < vatForm.InputCategories1.Count; i++) { XElement HDonMVao = new XElement("HDonMVao"); HDonMVao.Add(new XAttribute("id", "ID_" + (i + 1))); XElement kyHieuMauHDon = new XElement("kyHieuMauHDon"); HDonMVao.Add(kyHieuMauHDon); XElement kyHieuHDon = new XElement("kyHieuHDon"); HDonMVao.Add(kyHieuHDon); XElement soHDon = new XElement("soHDon", vatForm.InputCategories1.ElementAt(i).Column2); HDonMVao.Add(soHDon); XElement ngayPHanh = new XElement("ngayPHanh", vatForm.InputCategories1.ElementAt(i).Column3.ToString("yyyy-MM-dd")); HDonMVao.Add(ngayPHanh); XElement tenNBAN = new XElement("tenNBAN", vatForm.InputCategories1.ElementAt(i).Column4); HDonMVao.Add(tenNBAN); XElement mstNBAN = new XElement("mstNBAN", vatForm.InputCategories1.ElementAt(i).Column5); HDonMVao.Add(mstNBAN); XElement matHang = new XElement("matHang"); HDonMVao.Add(matHang); XElement thueSuat = new XElement("thueSuat", "0"); HDonMVao.Add(thueSuat); XElement dsoMuaChuaThue = new XElement("dsoMuaChuaThue", vatForm.InputCategories1.ElementAt(i).Column6); HDonMVao.Add(dsoMuaChuaThue); XElement thueGTGT = new XElement("thueGTGT", vatForm.InputCategories1.ElementAt(i).Column7); HDonMVao.Add(thueGTGT); XElement ghiChu = new XElement("ghiChu", vatForm.InputCategories1.ElementAt(i).Column8); ChiTietHHDVDRieng.Add(HDonMVao); } } HHDVDRieng.Add(ChiTietHHDVDRieng); XElement tongGTriMVao = new XElement("tongGTriMVao", vatForm.InputCategories1TotalAmount); HHDVDRieng.Add(tongGTriMVao); XElement tongThueMVao = new XElement("tongThueMVao", vatForm.InputCategories1TotalTaxAmount); HHDVDRieng.Add(tongThueMVao); PL01_2_GTGT.Add(HHDVDRieng); #endregion #region HHDVKhongKTru XElement HHDVKhongKTru = new XElement("HHDVKhongKTru"); XElement ChiTietHHDVKhongKTru = new XElement("ChiTietHHDVKhongKTru"); HHDVKhongKTru.Add(HHDVKhongKTru); XElement tongGTriMVao1 = new XElement("tongGTriMVao", "0"); HHDVKhongKTru.Add(tongGTriMVao1); XElement tongThueMVao1 = new XElement("tongThueMVao", "0"); HHDVKhongKTru.Add(tongThueMVao1); PL01_2_GTGT.Add(HHDVKhongKTru); #endregion #region HHDVDChung XElement HHDVDChung = new XElement("HHDVDChung"); XElement ChiTietHHDVDChung = new XElement("ChiTietHHDVDChung"); if (vatForm.InputCategories2 != null && vatForm.InputCategories2.Count > 0) { for (int i = 0; i < vatForm.InputCategories2.Count; i++) { XElement HDonMVao = new XElement("HDonMVao"); HDonMVao.Add(new XAttribute("id", "ID_" + (i + 1))); XElement kyHieuMauHDon = new XElement("kyHieuMauHDon"); HDonMVao.Add(kyHieuMauHDon); XElement kyHieuHDon = new XElement("kyHieuHDon"); HDonMVao.Add(kyHieuHDon); XElement soHDon = new XElement("soHDon", vatForm.InputCategories2.ElementAt(i).Column2); HDonMVao.Add(soHDon); XElement ngayPHanh = new XElement("ngayPHanh", vatForm.InputCategories2.ElementAt(i).Column3.ToString("yyyy-MM-dd")); HDonMVao.Add(ngayPHanh); XElement tenNBAN = new XElement("tenNBAN", vatForm.InputCategories2.ElementAt(i).Column4); HDonMVao.Add(tenNBAN); XElement mstNBAN = new XElement("mstNBAN", vatForm.InputCategories2.ElementAt(i).Column5); HDonMVao.Add(mstNBAN); XElement matHang = new XElement("matHang"); HDonMVao.Add(matHang); XElement thueSuat = new XElement("thueSuat", "0"); HDonMVao.Add(thueSuat); XElement dsoMuaChuaThue = new XElement("dsoMuaChuaThue", vatForm.InputCategories2.ElementAt(i).Column6); HDonMVao.Add(dsoMuaChuaThue); XElement thueGTGT = new XElement("thueGTGT", vatForm.InputCategories2.ElementAt(i).Column7); HDonMVao.Add(thueGTGT); XElement ghiChu = new XElement("ghiChu", vatForm.InputCategories2.ElementAt(i).Column8); ChiTietHHDVDChung.Add(HDonMVao); } } HHDVDChung.Add(ChiTietHHDVDChung); XElement tongGTriMVao3 = new XElement("tongGTriMVao", vatForm.InputCategories2TotalAmount); HHDVDChung.Add(tongGTriMVao3); XElement tongThueMVao3 = new XElement("tongThueMVao", vatForm.InputCategories2TotalTaxAmount); HHDVDChung.Add(tongThueMVao3); PL01_2_GTGT.Add(HHDVDChung); #endregion #region HHDVKTru XElement HHDVKTru = new XElement("HHDVKTru"); XElement ChiTietHHDVKTru = new XElement("ChiTietHHDVKTru"); HHDVKTru.Add(ChiTietHHDVKTru); XElement tongGTriMVao2 = new XElement("tongGTriMVao", "0"); HHDVKTru.Add(tongGTriMVao2); XElement tongThueMVao2 = new XElement("tongThueMVao", "0"); HHDVKTru.Add(tongThueMVao2); PL01_2_GTGT.Add(HHDVKTru); #endregion #region HHDVMVaoKhongTHop XElement HHDVMVaoKhongTHop = new XElement("HHDVMVaoKhongTHop"); XElement ChiTietHHDVMVaoKhongTHop = new XElement("ChiTietHHDVMVaoKhongTHop"); HHDVMVaoKhongTHop.Add(ChiTietHHDVKTru); XElement tongGTriMVao4 = new XElement("tongGTriMVao", "0"); HHDVMVaoKhongTHop.Add(tongGTriMVao4); XElement tongThueMVao4 = new XElement("tongThueMVao", "0"); HHDVMVaoKhongTHop.Add(tongThueMVao4); PL01_2_GTGT.Add(HHDVMVaoKhongTHop); #endregion XElement tongGTriMVao5 = new XElement("tongGTriMVao", vatForm.InputTotalAmount); PL01_2_GTGT.Add(tongGTriMVao5); XElement tongThueMVao5 = new XElement("tongThueMVao", vatForm.InputTotalTaxAmount); PL01_2_GTGT.Add(tongThueMVao5); PLuc.Add(PL01_2_GTGT); #endregion 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", "VAT_Quy" + taxQuarter + "_" + taxYear + ".xml"); #endregion } catch (Exception) { return RedirectToAction("ManageError", "Error"); } }