/// <summary> /// 已纳税额输入,均分 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolStripMenuItem3_Click(object sender, EventArgs e) { string x = string.Empty; if (dgvSals.SelectedRows.Count == 0) { MessageBox.Show("请选择一行记录后进行操作", this.funName, MessageBoxButtons.OK); return; } string name = (string)dgvSals.SelectedRows[0].Cells[1].Value; x = (string)dgvSals.SelectedRows[0].Cells[1].Value; if (InputDialog.ShowInputDialog(ref x) == System.Windows.Forms.DialogResult.OK) { decimal sum = Convert.ToDecimal(x); //TODO 小数点位数 decimal sumRMB = Convert.ToDecimal((sum * rate1 * rate2).ToString("f2")); //f4 if (sum >= 0) { if (TaxAlready.ContainsKey(name)) { TaxAlready.Remove(name); } TaxAlready.Add(name, sum); int count = dgvSals.SelectedRows.Count; List <decimal> lrate = getRateList(); //按比例均分已纳税 List <decimal> tm = new List <decimal>(); for (int i = 0; i < dgvSals.SelectedRows.Count; i++) { if ((bool)(dgvSals.SelectedRows[i].Cells[0].Value) == true) { dgvSals.SelectedRows[i].Cells[6].Value = sum * lrate[i]; dgvSals.SelectedRows[i].Cells[7].Value = sumRMB * lrate[i]; tm.Add(sumRMB * lrate[i]); } else { dgvSals.SelectedRows[i].Cells[6].Value = 0; dgvSals.SelectedRows[i].Cells[7].Value = 0; } } } } }
/// <summary> /// 报表导出 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnEm_Click(object sender, EventArgs e) { //*** Modified by CYQ on 2018-07-26 ***// // 根据财通嘉鑫要求,增加有关无身份证号的报税申请人处理 //*** Begin ***// TAX_PLAYER currTP = db.TAX_PLAYERs.SingleOrDefault(ai => ai.TP_ID == RW1.Base.RI_TPID); #region 用户输入无身份证号的报税申请人的身份证号 string id = string.Empty; // 申报人身份证号 if (string.IsNullOrEmpty(currTP.TP_IDNUMBER)) { string s = "请输入申报人身份证号"; if (InputDialog.ShowInputDialog(ref s) == DialogResult.OK) { id = s.Trim(); } } else { id = currTP.TP_IDNUMBER; } if (id != string.Empty) { currTP.TP_IDNUMBER = id; db.SubmitChanges(); } else { MessageBox.Show("未获取到有效的身份证号信息,请重新输入", "消息", MessageBoxButtons.OK, MessageBoxIcon.Information); return; } #endregion //*** End ***// fbdPath.Description = "将导出文件保存到..."; DialogResult result = fbdPath.ShowDialog(); if (result != System.Windows.Forms.DialogResult.OK) { return; } Assembly assembly = Assembly.GetExecutingAssembly(); Assembly asm = Assembly.GetExecutingAssembly(); string file = string.Format("{0}.Resources.ReportTemplate.xlsx", asm.GetName().Name); Stream fileStream = asm.GetManifestResourceStream(file); string filename = fbdPath.SelectedPath + string.Format("\\{0}-{1}_{2}.xlsx", RW1.ACNAME, RW1.TPNAME, DateTime.Now.ToString("yyyyMMddHHmm")); SaveStreamToFile(filename, fileStream); ExcelHelper excel = new ExcelHelper(); //报表一 excel.OpenFile(filename, 1); excel.SetValue(1, 2, string.Format("{0}-{1}{2}工资单", RW1.ACNAME, RW1.TPNAME, RW1.Base.RI_YEARTITLE1)); excel.SetValue(4, 6, RW1.Base.RI_CURRENTNAME); var data = RW1.Details.OrderBy(a => a.R1_MONTH).ToList(); //load data; int i = 0; foreach (var d in data) { string[] tmp = new string[] { d.R1_MONTH, d.R1_FORTAX.ToString(), d.R1_REALDOLLOR.ToString(), d.R1_REALRMB.ToString(), d.R1_TAXALREADY.ToString(), d.R1_TAXALREADYRMB.ToString(), d.R1_SALARYRMB.ToString() }; excel.SetValue(5 + i, 2, tmp); i++; } excel.SetValue(17, 3, RW1.Base.RI_BONUS.ToString()); excel.SetValue(18, 2, RW1.Base.RI_NOTE1); excel.SetValue(19, 2, RW1.Base.RI_NOTE2); /* Modified by cyq 20160331 */ /************ Begin *********/ excel.SetFontNameSize(21, 2, "宋体", 11); excel.SetFontNameSize(21, 4, "宋体", 11); excel.SetFontNameSize(23, 2, "宋体", 11); excel.SetFontNameSize(23, 4, "宋体", 11); excel.SetValue(21, 2, "编制日期: " + RW1.Base.RI_TABLETIME.ToLongDateString().ToString()); excel.SetValue(21, 4, "复核日期: " + RW1.Base.RI_TABLETIME.AddDays(2).ToLongDateString().ToString()); excel.SetValue(23, 2, "编制人: " + txtScheduler.Text.Trim()); excel.SetValue(23, 4, "复核人: " + txtReviewer.Text.Trim()); /************ End *********/ //报表二 excel.ChangeSheet(2); excel.SetValue(3, 1, string.Format("{0}--工资个税 {1}", RW2.TPNAME, RW2.Base.RI_YEARTITLE2)); var data2 = RW2.Details.OrderBy(a => a.R2_MONTH).ToList(); i = 0; foreach (var d in data2) { string[] tmp = new string[] { d.R2_MONTH, d.R2_SALARY.ToString(), d.R2_MINUS.ToString(), d.R2_TAXSALARY.ToString(), string.Format("{0}%", d.R2_TAXRATE), d.R2_QUICK.ToString(), d.R2_NEED.ToString() }; excel.SetValue(7 + i, 1, tmp); i++; } excel.SetValue(19, 2, RW2.Base.RI_BONUS.ToString()); excel.SetValue(19, 4, RW2.Base.RI_BONUS.ToString()); TAX_RATE tr = SysUtil.GetTaxRate((int)RW2.Base.RI_BONUSTAXRATEID); excel.SetValue(19, 5, string.Format("{0}%", tr.TR_RATE)); excel.SetValue(19, 6, tr.TR_QUICH.ToString()); excel.SetValue(19, 7, RW2.Base.RI_BONUSTAX.ToString()); excel.SetValue(20, 2, RW2.Base.RI_SUMS.ToString()); excel.SetValue(20, 4, RW2.Base.RI_SUMTAXSALARY.ToString()); excel.SetValue(20, 7, RW2.Base.RI_SUMTAXRMB.ToString()); excel.SetValue(20, 8, RW2.Base.RI_SUMTAXALREADYRMB.ToString()); // Modified by CYQ on 2018-09-10 // 根据财通嘉鑫要求,将“本年已缴/以前留抵”拆分为“境内已纳税额”和“以前留抵税额” // Begin //excel.SetValue(20, 9, RW2.Base.RI_USEALL.ToString()); excel.SetValue(20, 9, (RW2.Base.RI_USE2).ToString()); // 境内已纳税额 excel.SetValue(20, 10, (RW2.Base.RI_USEALL - RW2.Base.RI_USE2).ToString()); // 以前留抵税额 //*** Modified by CYQ on 2018-07-13 ***// // //*** Begin ***// //excel.SetValue(20, 10, RW2.Base.RI_NEEDPACKREAL.ToString()); //if (RW2.Base.RI_NEEDPACKREAL.HasValue && // RW2.Base.RI_NEEDPACKREAL.Value > 0) //{ // excel.SetValue(20, 10, RW2.Base.RI_NEEDPACKREAL.ToString()); //} // end if //if (RW2.Base.RI_NEEDPACKREAL.HasValue) //{ // if (RW2.Base.RI_NEEDPACKREAL.Value > 0) // { // excel.SetValue(20, 10, RW2.Base.RI_NEEDPACKREAL.ToString()); // } // end if // else // { // excel.SetValue(20, 10, "0.00"); // } // end else //} if (RW2.Base.RI_NEEDPACKREAL.HasValue) { if (RW2.Base.RI_NEEDPACKREAL.Value > 0) { excel.SetValue(20, 11, RW2.Base.RI_NEEDPACKREAL.ToString()); } // end if else { excel.SetValue(20, 11, "0.00"); } // end else } // End //*** End ***// excel.SetValue(22, 1, RW2.Base.RI_NOTE1); excel.SetValue(23, 1, string.Format(" {0}", RW2.Base.RI_NOTE2)); /* Modified by cyq 20160331 */ /************ Begin *********/ excel.SetFontNameSize(25, 2, "宋体", 11); excel.SetFontNameSize(25, 4, "宋体", 11); excel.SetFontNameSize(27, 2, "宋体", 11); excel.SetFontNameSize(27, 4, "宋体", 11); excel.SetValue(25, 2, "编制日期: " + RW1.Base.RI_TABLETIME.ToLongDateString().ToString()); excel.SetValue(25, 4, "复核日期: " + RW1.Base.RI_TABLETIME.AddDays(2).ToLongDateString().ToString()); excel.SetValue(27, 2, "编制人: " + txtScheduler.Text.Trim()); excel.SetValue(27, 4, "复核人: " + txtReviewer.Text.Trim()); /************ End *********/ excel.Close(); //生成报表三 if (RW2.Base.RI_MOUNTHCOUNT == 12) { filename = fbdPath.SelectedPath + string.Format("\\{0}-{1}_{2}.doc", RW1.ACNAME, RW1.TPNAME, DateTime.Now.ToString("yyyyMMddHHmm")); File.WriteAllBytes(filename, TaxDemo.Properties.Resources.Template3); AGENT_INFO ai = SysUtil.GetAgentInfo(RW1.Base.RI_ACID); TAX_PLAYER tp = SysUtil.GetTaxPlayer(RW1.Base.RI_TPID); WordUtil word = new WordUtil(); { word.Open(filename); /* Modified by cyq 20160331 */ /************ Begin *********/ word.WriteData(RW1.Base, ai, tp, InternalTotal, ExternalTotal); /************ End *********/ word.Close(); } } MessageBox.Show("导出成功", this.funName); if (cbxOpen.Checked) { Process.Start(fbdPath.SelectedPath); } }
/// <summary> /// 查看报表 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void toolStripMenuItem1_Click(object sender, EventArgs e) { decimal internalTotal = 0; // 境内合计 Added by CYQ 2018-07-12 decimal externalTotal = 0; // 境外合计 Added by CYQ 2018-07-12 try { if (dgvSals.SelectedRows.Count == 0) { MessageBox.Show("请选择一行记录后进行操作", this.funName, MessageBoxButtons.OK); return; } List <string> months = new List <string>(); for (int i = 0; i < dgvSals.SelectedRows.Count; i++) { months.Add(dgvSals.SelectedRows[i].Cells[2].Value.ToString()); } List <string> mons = months.OrderBy(a => a).ToList(); //修改每月建费用额 string x = string.Empty; frmInput frm = new frmInput(); frm.monthList = mons; if (frm.ShowDialog() != DialogResult.OK) { return; } try { Dictionary <string, decimal> minusList = frm.minusList; //每月减费用额,计算税级时使用 TEMPLATE_INFO ti = db.TEMPLATE_INFOs.SingleOrDefault(a => a.TI_ID == this.TIID); string playerName = (string)dgvSals.SelectedRows[0].Cells[1].Value; // 个税申报人 using (frmReportNew fa = new frmReportNew()) { Report1Wrapper rw1 = new Report1Wrapper(); //报表1数据 Report2Wrapper rw2 = new Report2Wrapper(); //报表2数据 REPORT_INFO ri = new REPORT_INFO(); //报表数据 rw1.ACNAME = ((AGENT_COUNTRY)cbxAgentCs.SelectedItem).AC_NAME; // 国别名称 Added by CYQ 2018-07-12 rw1.TPNAME = rw2.TPNAME = playerName; // 个税申报人姓名 Added by CYQ 2018-07-12 rw1.MINUS = 4800; ri.RI_ACID = this.ACID; // 国别ID Added by CYQ 2018-07-12 decimal bonus = getBonus(); if (bonus == -1) { string s = "年终奖多于1行,请输入年终奖最终值"; if (InputDialog.ShowInputDialog(ref s) == DialogResult.OK) { bonus = Convert.ToDecimal(s); } else { return; } } //报表基础信息 ri.RI_BONUS = bonus; // 年终奖金 ri.RI_DECLARETIME = dtDeclare.Value; // 报税时间 ri.RI_TABLETIME = dtTableOn.Value; // 填表时间 ri.RI_ERATE1 = Convert.ToDecimal(txtERate1.Text); // 汇率 1 ri.RI_ERATE2 = Convert.ToDecimal(txtERate2.Text); // 汇率 2 ri.RI_MOUNTHCOUNT = dgvSals.SelectedRows.Count; // 纳税月数 ri.RI_MONTH = mons[0] + "-" + mons[months.Count - 1]; // 月数说明 ri.RI_CREATETIME = dtTableOn.Value; // 生成时间 ri.RI_UIID = SysUtil.CurrentUserID(); // 操作用户 ri.RI_YEARTITLE1 = txtYearTitle1.Text; // 报表1年度说明 ri.RI_YEARTITLE2 = txtYearTitle2.Text; // 报表2年度说明 ri.RI_AYNAME = AYNAME; // 纳税年度 ri.RI_YEARANNU = Convert.ToDecimal(txtYearAnnu.Text.Trim()); // 年金限额 ri.RI_CURRENTNAME = lblCurrent.Text.Substring(1, lblCurrent.Text.Length - 2); // 币种名称 int tpid = 0; if (SysUtil.GetPlayerID(ACID, playerName, ref tpid)) { ri.RI_TPID = tpid; } for (int i = 0; i < dgvSals.SelectedRows.Count; i++) { //报表1数据 var td = new REPORT1_DETAIL { R1_MONTH = dgvSals.SelectedRows[i].Cells[2].Value.ToString(), // 月份 R1_FORTAX = Convert.ToDecimal(dgvSals.SelectedRows[i].Cells[3].Value.ToString()), // 应纳税工资 R1_REALDOLLOR = Convert.ToDecimal(dgvSals.SelectedRows[i].Cells[4].Value.ToString()), // 实发工资(美元) R1_REALRMB = Convert.ToDecimal(dgvSals.SelectedRows[i].Cells[5].Value.ToString()), // 实发工资(RMB) R1_TAXALREADY = Convert.ToDecimal(dgvSals.SelectedRows[i].Cells[6].Value.ToString()), // 已纳税额 R1_TAXALREADYRMB = Convert.ToDecimal(dgvSals.SelectedRows[i].Cells[7].Value.ToString()), // 已纳税额(RMB) }; td.R1_SALARYRMB = td.R1_FORTAX + td.R1_REALRMB + td.R1_TAXALREADYRMB; // 应纳税工资合计 /* Modified by cyq 20160331 */ /************ Begin *********/ if (minusList[td.R1_MONTH] == 3500) { internalTotal += td.R1_SALARYRMB; } else { externalTotal += td.R1_SALARYRMB; } /************ End *********/ //报表2数据 var td2 = new REPORT2_DETAIL(); td2.R2_MONTH = dgvSals.SelectedRows[i].Cells[2].Value.ToString(); td2.R2_SALARY = td.R1_SALARYRMB; // 应纳税工资(报表2) td2.R2_MINUS = minusList[td2.R2_MONTH]; // 减费用额(报表2) td2.R2_TAXSALARY = td2.R2_SALARY - td2.R2_MINUS; // 应纳税所得额(报表2) TAX_RATE ta = SysUtil.GetTaxRate(td2.R2_SALARY, minusList[td2.R2_MONTH]); td2.R2_TAXRATE = ta.TR_RATE; // 税率(报表2) td2.R2_QUICK = ta.TR_QUICH; // 速算扣除数(报表2) td2.R2_NEED = Convert.ToDecimal((td2.R2_TAXSALARY * td2.R2_TAXRATE / 100 - td2.R2_QUICK).ToString("F2")); // 应纳税额(报表2) rw1.Details.Add(td); rw2.Details.Add(td2); } /* Modified by cyq 20160331 */ /************ Begin *********/ fa.InternalTotal = internalTotal; fa.ExternalTotal = externalTotal; /************ End *********/ decimal min = rw2.Details.Min(a => a.R2_TAXSALARY); if (min > 0) { min = 0; } //*** Modified by CYQ on 2018-07-26 ***// // 根据财通佳鑫要求: // 1.当应纳税工资<=0时 年终奖调整额根据min所在行减费用额,调减3500或4800。 // 2.如果“应纳税所得额”值min不唯一,且“减费用额”列对应数值不唯一,则取值4800对年终奖进行调整。 //*** Begin ***// else { if (min < -3500) { int minTSCnt = rw2.Details.Where(r => r.R2_TAXSALARY == min).Count(); // 应纳税所得额唯一值统计 decimal[] r2_Minus = rw2.Details.Where(r => r.R2_TAXSALARY == min).Select(r => r.R2_MINUS).ToArray(); if (minTSCnt > 1) // 存在重复的应纳税所得额 { if (r2_Minus.Distinct().Count() > 1) { min = -4800; } else { min = (-1) * r2_Minus[0]; } // end else } else // 无重复的应纳税所得额 { min = (-1) * r2_Minus[0]; } } } // end else //*** End ***// TAX_RATE trbonus = SysUtil.GetTaxRate((ri.RI_BONUS + min) / 12, 4800, true); ri.RI_BONUSTAXRATEID = trbonus.TR_ID; // 年终奖金税率 ri.RI_BONUSTAX = Convert.ToDecimal(((ri.RI_BONUS * trbonus.TR_RATE / 100) - trbonus.TR_QUICH).ToString("F2")); // 应纳税额(年终奖) ri.RI_SUMS = rw2.Details.Sum(a => a.R2_SALARY) + ri.RI_BONUS; // 收入额(合计) ri.RI_SUMTAXSALARY = rw2.Details.Sum(a => a.R2_TAXSALARY) + ri.RI_BONUS; // 应纳税所得额(合计) ri.RI_SUMTAXRMB = rw2.Details.Sum(a => a.R2_NEED) + (decimal)ri.RI_BONUSTAX; // 应纳税额(合计) ri.RI_SUMTAXALREADY = TaxAlready[playerName]; ri.RI_SUMTAXALREADYRMB = Convert.ToDecimal((TaxAlready[playerName] * ri.RI_ERATE1 * ri.RI_ERATE2).ToString("F2")); // rw1.Details.Sum(a => a.R1_TAXALREADYRMB); // 境外已纳税额 ri.RI_NEEDPACK = (decimal)ri.RI_SUMTAXRMB - (decimal)ri.RI_SUMTAXALREADYRMB; // 境内应补税额【计算公式:应纳税额(合计) - 境外已纳税额】 ri.RI_USEALL = 0; ri.RI_USE2 = 0; /* Modified by cyq 20160331 */ /* *********** Begin *********/ if (ri.RI_NEEDPACK < 0) { TAX_CREDIT tc = new TAX_CREDIT { TP_ID = tpid, TC_YEAR = AYNAME, TC_CREDITALL = Math.Abs(ri.RI_NEEDPACK), TC_CREDITUSED = 0, TC_CREDITBALANCE = Math.Abs(ri.RI_NEEDPACK) }; fa.AddedTC = tc; } else { TAX_CREDIT tc = new TAX_CREDIT { TP_ID = tpid, TC_YEAR = AYNAME, TC_CREDITALL = 0, TC_CREDITUSED = 0, TC_CREDITBALANCE = 0 }; fa.AddedTC = tc; } /* *********** End *********/ if (ri.RI_NEEDPACK < 0) { ri.RI_NEEDPACKREAL = 0; } else { ri.RI_NEEDPACKREAL = ri.RI_NEEDPACK; // 境内实需补税额 } ri.RI_NOTE1 = string.Format("注:1. {0}{1}{2}元人民币", dtDeclare.Value.ToString("yyyy年MM月dd日"), lblCurrent.Text, (ri.RI_ERATE1 * ri.RI_ERATE2).ToString("f6")); // 备注1 ri.RI_NOTE2 = string.Format("2. {0}年{1}已纳税额 {2} {3},折合人民币 {4} 元", txtYear.Text, rw1.ACNAME, ri.RI_SUMTAXALREADY.ToString("N2"), ((AGENT_COUNTRY)cbxAgentCs.SelectedItem).AC_CURRENCY, ((decimal)ri.RI_SUMTAXALREADYRMB).ToString("N2")); // 备注2 ri.RI_USEALL = 0; // 使用可抵税总额 rw1.Base = rw2.Base = ri; fa.RW1 = rw1; fa.RW2 = rw2; fa.Owner = this; //展示报表 if (fa.ShowDialog() == System.Windows.Forms.DialogResult.OK) { } } } catch (Exception ex) { MessageBox.Show("错误类型:" + ex.GetType().ToString() + "\n" + "错误消息:" + ex.Message + "\n" + "对象名称:" + ex.Source + "\n" + "引发异常的方法:" + ex.TargetSite + "\n" + "调用堆栈:" + ex.StackTrace + "\n"); throw; } } catch (Exception ex) { MessageBox.Show(ex.Message + ";是否已纳税额尚未输入"); return; } }