public bool SaveVatTaxDeclaration(VatTaxDeclaration declaration) { int year = declaration.Year; int quarter = declaration.Quarter; VatTaxDeclaration check = db.VatTaxDeclarations.FirstOrDefault(m => m.Year == year && m.Quarter == quarter); if (check != null) { db.VatTaxDeclarations.Remove(check); } db.VatTaxDeclarations.Add(declaration); try { db.SaveChanges(); } catch (Exception) { return false; } return true; }
public int SaveVatTaxDeclaration(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 ProcessData Models.VatTaxDeclaration taxDeclaration = new VatTaxDeclaration(); taxDeclaration.Quarter = Convert.ToInt32(taxQuarter); taxDeclaration.Year = Convert.ToInt32(taxYear); taxDeclaration.StoreOwnerName = storeOwnerName; taxDeclaration.StoreTaxCode = storeTaxcode; taxDeclaration.StoreAddress = storeAddress; taxDeclaration.StoreDistrict = storeDistrict; taxDeclaration.StoreProvince = storeProvince; taxDeclaration.StorePhone = storePhone; taxDeclaration.StoreEmail = storeEmail; taxDeclaration.StoreFax = storeFax; taxDeclaration.TaxAgentOwnerName = vatAgentOwnerName; taxDeclaration.TaxAgentTaxCode = vatAgentTaxCode; taxDeclaration.TaxAgentAddress = vatAgentAddress; taxDeclaration.TaxAgentDistrict = vatAgentDistrict; taxDeclaration.TaxAgentProvince = vatAgentProvince; taxDeclaration.TaxAgentPhone = vatAgentPhone; taxDeclaration.TaxAgentEmail = vatAgentEmail; taxDeclaration.TaxAgentFax = vatAgentFax; taxDeclaration.TaxAgentName = vatAgentName; taxDeclaration.TaxAgentNo = vatAgentNo; taxDeclaration.CreateLocation = createLocation; taxDeclaration.CreateDate = DateTime.ParseExact(createDate, "yyyy-MM-dd", CultureInfo.InvariantCulture); taxDeclaration.SignName = signName; taxDeclaration.Value20No = value20No; taxDeclaration.Value20Date = DateTime.ParseExact(value20Date, "yyyy-MM-dd", CultureInfo.InvariantCulture); taxDeclaration.Value21 = Convert.ToInt32(value21); taxDeclaration.Value22 = Convert.ToInt32(value22); taxDeclaration.Value25 = Convert.ToInt32(value25); taxDeclaration.Value36 = Convert.ToInt32(value36); taxDeclaration.Value37 = Convert.ToInt32(value37); taxDeclaration.Value38 = Convert.ToInt32(value38); taxDeclaration.Value39 = Convert.ToInt32(value39); taxDeclaration.Value40 = Convert.ToInt32(value40); taxDeclaration.Value40a = Convert.ToInt32(value40a); taxDeclaration.Value40b = Convert.ToInt32(value40b); taxDeclaration.Value41 = Convert.ToInt32(value41); taxDeclaration.Value42 = Convert.ToInt32(value42); taxDeclaration.Value43 = Convert.ToInt32(value43); #region Output int totalOutputAmount = 0; int haveTaxTotalOutputAmount = 0; int totalTaxOutputAmount = 0; #region OutputCategory1 string outputCategory1 = ""; 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++) { string eachOutputCategory1 = ""; eachOutputCategory1 += outputCategory1Column2Array[i] + ","; eachOutputCategory1 += outputCategory1Column3Array[i] + ","; eachOutputCategory1 += outputCategory1Column4Array[i] + ","; eachOutputCategory1 += outputCategory1Column5Array[i] + ","; eachOutputCategory1 += outputCategory1Column6Array[i].Replace(".", "") + ","; eachOutputCategory1 += outputCategory1Column7Array[i].Replace(".", "") + ","; eachOutputCategory1 += outputCategory1Column8Array[i]; int categoryColumn6Number = Convert.ToInt32(outputCategory1Column6Array[i].Replace(".", "")); totalOutputCategory1 += categoryColumn6Number; outputCategory1 += eachOutputCategory1 + ";"; } taxDeclaration.OutputCategory1TotalAmountValue26 = totalOutputCategory1; totalOutputAmount += totalOutputCategory1; } taxDeclaration.OutputCategory1 = outputCategory1; #endregion #region OutputCategory2 string outputCategory2 = ""; 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++) { string eachOutputCategory2 = ""; eachOutputCategory2 += outputCategory2Column2Array[i] + ","; eachOutputCategory2 += outputCategory2Column3Array[i] + ","; eachOutputCategory2 += outputCategory2Column4Array[i] + ","; eachOutputCategory2 += outputCategory2Column5Array[i] + ","; eachOutputCategory2 += outputCategory2Column6Array[i].Replace(".", "") + ","; eachOutputCategory2 += outputCategory2Column7Array[i].Replace(".", "") + ","; eachOutputCategory2 += outputCategory2Column8Array[i]; int categoryColumn6Number = Convert.ToInt32(outputCategory2Column6Array[i].Replace(".", "")); totalOutputCategory2 += categoryColumn6Number; outputCategory2 += eachOutputCategory2 + ";"; } taxDeclaration.OutputCategory2TotalAmountValue29 = totalOutputCategory2; haveTaxTotalOutputAmount += totalOutputCategory2; totalOutputAmount += totalOutputCategory2; } taxDeclaration.OutputCategory2 = outputCategory2; #endregion #region OutputCategory3 string outputCategory3List = ""; 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++) { string outputCategory3 = ""; outputCategory3 += outputCategory3Column2Array[i] + ","; outputCategory3 += outputCategory3Column3Array[i] + ","; outputCategory3 += outputCategory3Column4Array[i] + ","; outputCategory3 += outputCategory3Column5Array[i] + ","; outputCategory3 += outputCategory3Column6Array[i].Replace(".", "") + ","; outputCategory3 += outputCategory3Column7Array[i].Replace(".", "") + ","; outputCategory3 += outputCategory3Column8Array[i]; int categoryColumn6Number = Convert.ToInt32(outputCategory3Column6Array[i].Replace(".", "")); totalOutputCategory3 += categoryColumn6Number; int categoryColumn7Number = Convert.ToInt32(outputCategory3Column7Array[i].Replace(".", "")); totalTaxOutputCategory3 += categoryColumn7Number; outputCategory3List += outputCategory3 + ";"; } taxDeclaration.OutputCategory3TotalAmountValue30 = totalOutputCategory3; taxDeclaration.OutputCategory3TotalTaxAmountValue31 = totalTaxOutputCategory3; totalOutputAmount += totalOutputCategory3; haveTaxTotalOutputAmount += totalOutputCategory3; totalTaxOutputAmount += totalTaxOutputCategory3; } taxDeclaration.OutputCategory3 = outputCategory3List; #endregion #region OutputCategory4 string outputCategory4List = ""; 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++) { string outputCategory4 = ""; outputCategory4 += outputCategory4Column2Array[i] + ","; outputCategory4 += outputCategory4Column3Array[i] + ","; outputCategory4 += outputCategory4Column4Array[i] + ","; outputCategory4 += outputCategory4Column5Array[i] + ","; outputCategory4 += outputCategory4Column6Array[i].Replace(".", "") + ","; outputCategory4 += outputCategory4Column7Array[i].Replace(".", "") + ","; outputCategory4 += outputCategory4Column8Array[i]; int categoryColumn6Number = Convert.ToInt32(outputCategory4Column6Array[i].Replace(".", "")); totalOutputCategory4 += categoryColumn6Number; int categoryColumn7Number = Convert.ToInt32(outputCategory4Column7Array[i].Replace(".", "")); totalTaxOutputCategory4 += categoryColumn7Number; outputCategory4List += outputCategory4 + ";"; } taxDeclaration.OutputCategory4TotalAmountValue32 = totalOutputCategory4; taxDeclaration.OutputCategory4TotalTaxAmountValue33 = totalTaxOutputCategory4; totalOutputAmount += totalOutputCategory4; haveTaxTotalOutputAmount += totalOutputCategory4; totalTaxOutputAmount += totalTaxOutputCategory4; } taxDeclaration.OutputCategory4 = outputCategory4List; #endregion taxDeclaration.OutputTotalAmountValue34 = totalOutputAmount; taxDeclaration.OutputTotalTaxAmountValue28 = totalTaxOutputAmount; taxDeclaration.HaveTaxOutputTotalAmountValue27 = haveTaxTotalOutputAmount; #endregion #region Input int totalInputAmount = 0; int totalTaxInputAmount = 0; #region InputCategory1 string inputCategory1List = ""; 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++) { string inputCategory1 = ""; inputCategory1 += inputCategory1Column2Array[i] + ","; inputCategory1 += inputCategory1Column3Array[i] + ","; inputCategory1 += inputCategory1Column4Array[i] + ","; inputCategory1 += inputCategory1Column5Array[i] + ","; inputCategory1 += inputCategory1Column6Array[i].Replace(".", "") + ","; inputCategory1 += inputCategory1Column7Array[i].Replace(".", "") + ","; inputCategory1 += inputCategory1Column8Array[i]; int categoryColumn6Number = Convert.ToInt32(inputCategory1Column6Array[i].Replace(".", "")); totalInputCategory1 += categoryColumn6Number; int categoryColumn7Number = Convert.ToInt32(inputCategory1Column7Array[i].Replace(".", "")); totalTaxInputCategory1 += categoryColumn7Number; inputCategory1List += inputCategory1 + ";"; } taxDeclaration.InputCategory1TotalAmount = totalInputCategory1; taxDeclaration.InputCategory1TotalTaxAmount = totalTaxInputCategory1; totalInputAmount += totalInputCategory1; totalTaxInputAmount += totalTaxInputCategory1; } taxDeclaration.InputCategory1 = inputCategory1List; #endregion #region InputCategory2 string inputCategory2List = ""; 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++) { string inputCategory2 = ""; inputCategory2 += inputCategory2Column2Array[i] + ","; inputCategory2 += inputCategory2Column3Array[i] + ","; inputCategory2 += inputCategory2Column4Array[i] + ","; inputCategory2 += inputCategory2Column5Array[i] + ","; inputCategory2 += inputCategory2Column6Array[i].Replace(".", "") + ","; inputCategory2 += inputCategory2Column7Array[i].Replace(".", "") + ","; inputCategory2 += inputCategory2Column8Array[i]; int categoryColumn6Number = Convert.ToInt32(inputCategory2Column6Array[i].Replace(".", "")); totalInputCategory2 += categoryColumn6Number; int categoryColumn7Number = Convert.ToInt32(inputCategory2Column7Array[i].Replace(".", "")); totalTaxInputCategory2 += categoryColumn7Number; inputCategory2List += inputCategory2 + ";"; } taxDeclaration.InputCategory2TotalAmount = totalInputCategory2; taxDeclaration.InputCategory2TotalTaxAmount = totalTaxInputCategory2; totalInputAmount += totalInputCategory2; totalTaxInputAmount += totalTaxInputCategory2; } taxDeclaration.InputCategory2 = inputCategory2List; #endregion #region InputCategory3 string inputCategory3List = ""; 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++) { string inputCategory3 = ""; inputCategory3 += inputCategory3Column2Array[i] + ","; inputCategory3 += inputCategory3Column3Array[i] + ","; inputCategory3 += inputCategory3Column4Array[i] + ","; inputCategory3 += inputCategory3Column5Array[i] + ","; inputCategory3 += inputCategory3Column6Array[i].Replace(".", "") + ","; inputCategory3 += inputCategory3Column7Array[i].Replace(".", "") + ","; inputCategory3 += inputCategory3Column8Array[i]; int categoryColumn6Number = Convert.ToInt32(inputCategory3Column6Array[i].Replace(".", "")); totalInputCategory3 += categoryColumn6Number; int categoryColumn7Number = Convert.ToInt32(inputCategory3Column7Array[i].Replace(".", "")); totalTaxInputCategory3 += categoryColumn7Number; inputCategory3List += inputCategory3 + ";"; } taxDeclaration.InputCategory3TotalAmount = totalInputCategory3; taxDeclaration.InputCategory3TotalTaxAmount = totalTaxInputCategory3; } taxDeclaration.InputCategory3 = inputCategory3List; #endregion taxDeclaration.InputTotalAmountValue23 = totalInputAmount; taxDeclaration.InputTotalTaxAmountValue24 = totalTaxInputAmount; #endregion #endregion TaxBusiness business = new TaxBusiness(); return business.SaveVatTaxDeclaration(taxDeclaration) ? 1 : 0; } catch (Exception) { return 0; } }