1086 lines
49 KiB
C#
1086 lines
49 KiB
C#
using Dapper;
|
||
using dccdc.Models;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.Data;
|
||
using System.Linq;
|
||
using System.Text;
|
||
using System.Threading.Tasks;
|
||
|
||
namespace dccdc.DAL
|
||
{
|
||
public class chargeDal
|
||
{
|
||
|
||
public object getSFTJ()
|
||
{
|
||
string sql = "select method,sum(money) as count from charge " +
|
||
"where moneydate > convert(varchar(10), GETDATE(), 121)" +
|
||
"and moneydate<convert(varchar(10),dateadd(d, 1, GETDATE()),121)" +
|
||
"group by method";
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
return conn.Query(sql).ToList();
|
||
}
|
||
}
|
||
public object getmonthjf()
|
||
{
|
||
string sql = "select convert(varchar(10),moneydate,121) as date ,convert(decimal(10,2), sum(money)/10000) as sum from charge" +
|
||
" where status = '已缴费'" +
|
||
" and moneydate > convert(varchar(10), dateadd(dd, -day(getdate()) + 1, getdate()), 121)" +
|
||
" group by convert(varchar(10), moneydate, 121) ";
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
return conn.Query(sql).ToList();
|
||
}
|
||
}
|
||
|
||
public int getCount(string key)
|
||
{
|
||
string sql = "select count(1) from charge where 1=1";
|
||
if (!string.IsNullOrEmpty(key))
|
||
{
|
||
sql += " and (person like @area_name or company like @area_name)";
|
||
}
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
return conn.ExecuteScalar<int>(sql, new { area_name = "%" + key + "%" });
|
||
}
|
||
}
|
||
|
||
public void addYYCharge(MedicalAppointment m)
|
||
{
|
||
string havesql = "select count(1) from charge where zfid=@zfid";
|
||
using (var conn = CommHelper.GetSqlConnection())
|
||
{
|
||
int c = conn.ExecuteScalar<int>(havesql, new { zfid = m.ZFCode });
|
||
if (c > 0)
|
||
{
|
||
return;
|
||
}
|
||
}
|
||
//throw new NotImplementedException();
|
||
string sql = @"insert into charge(type,register_type,person,method,status,isprint,money,moneydate,moneyperson,createperson,createdate,zfid,person_type,department)
|
||
values('体检收费' ,'从业体检',@person,'微信','已缴费','未打印',@money,getdate(),'微信','微信',getdate(),@zfid,'','职业卫生科') select scope_identity()
|
||
";
|
||
using (var conn = CommHelper.GetSqlConnection())
|
||
{
|
||
int chargeid = conn.ExecuteScalar<int>(sql, new { person = m.xingMing, money = m.SFJE, zfid = m.ZFCode });
|
||
sql = "insert into charge_detail(chargeid,projectid,projectname,money,count,pid) values(@chargeid,1,'药品从业查体费',@money,1,0)";
|
||
conn.Execute(sql, new { chargeid = chargeid, money = m.SFJE });
|
||
}
|
||
}
|
||
|
||
public List<chargeModel> getList(int page, int pagesize, string key)
|
||
{
|
||
string sql = "select *,row_number() over(order by id) as rownum from charge where 1=1";
|
||
if (!string.IsNullOrEmpty(key))
|
||
{
|
||
sql += " and (person like @area_name or company like @area_name)";
|
||
}
|
||
sql = "select * from (" + sql + ") t where t.rownum>(" + page + "-1)*" + pagesize + " and rownum<=" + page + "*" + pagesize;
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
return conn.Query<chargeModel>(sql, new { area_name = "%" + key + "%" }).ToList();
|
||
}
|
||
}
|
||
|
||
public List<chargeModel> GetAllList(string id)
|
||
{
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
string param = "";
|
||
if (id != "")
|
||
{
|
||
param += " and id=@id";
|
||
}
|
||
|
||
string sql = "select * from charge where 1=1 ";
|
||
return conn.Query<chargeModel>(sql + param, new { id = id }).ToList();
|
||
}
|
||
}
|
||
|
||
public List<chargeModel> GetAllList2(string start, string end, string jfbm, string where, string print)
|
||
{
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
string param = "";
|
||
if (jfbm != "")
|
||
{
|
||
param += " and department=@jfbm";
|
||
}
|
||
if (where != "")
|
||
{
|
||
param += " and (person like @where or register_num like @where or company like @where )";
|
||
}
|
||
if (print != "")
|
||
{
|
||
param += " and isprint=@print";
|
||
}
|
||
string sql = "select * from charge where 1=1 and createdate >=@start and createdate<=@end and (status='已缴费' or status='未缴费') ";
|
||
return conn.Query<chargeModel>(sql + param, new { start = start + " 00:00:00", end = end + " 23:59:59", jfbm = jfbm, where = "%" + where + "%", print = print }).ToList();
|
||
}
|
||
}
|
||
|
||
public List<ym_jzlc> getyyymlist(object yyid)
|
||
{
|
||
//throw new NotImplementedException();
|
||
string sql = @"select * from ym_yyjl
|
||
where id = @id";
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
var m = conn.Query<Models.ym_yyjl>(sql, new { id = yyid }).FirstOrDefault();
|
||
if (m == null)
|
||
return null;
|
||
|
||
sql = "select * from ym_jzlc where ymid in (" + m.ymList + ") and jdid=" + m.jdid;
|
||
return conn.Query<Models.ym_jzlc>(sql).ToList();
|
||
}
|
||
}
|
||
|
||
public ym_yyjl getyyxx(string tag)
|
||
{
|
||
//throw new NotImplementedException();
|
||
string sql = "select * from ym_yyjl where id=@id";
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
return conn.Query<ym_yyjl>(sql, new { id = tag }).First();
|
||
}
|
||
}
|
||
|
||
public JiezhongmianyitiaomaModel getetxx(string tag)
|
||
{
|
||
//throw new NotImplementedException();
|
||
string sql = "select a.* from jiezhongmianyi_tiaomadayin a join ym_yyjl b on a.barcode=b.ertbm where b.id=@id";
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
return conn.Query<JiezhongmianyitiaomaModel>(sql, new { id = tag }).FirstOrDefault();
|
||
}
|
||
}
|
||
|
||
public List<BDXX> getbdxx(string tag)
|
||
{
|
||
string sql = @"select * from ym_yyjl
|
||
where id = @id";
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
var m = conn.Query<Models.ym_yyjl>(sql, new { id = tag }).FirstOrDefault();
|
||
if (m == null)
|
||
return null;
|
||
|
||
sql = "select a.* from bdxx a join jiezhongmianyi_tiaomadayin b on a.etid=b.id and b.barcode='" + m.ertbm + "'"; ;
|
||
return conn.Query<Models.BDXX>(sql).ToList();
|
||
}
|
||
}
|
||
|
||
public List<dynamic> getYMSFTJ(string b, string e)
|
||
{
|
||
//throw new NotImplementedException();
|
||
string sql = @"select vaccine.name as name,sum(YMDJMX.ymdj) as num from YMDJ
|
||
left join YMDJMX
|
||
ON YMDJ.ID = YMDJMX.ymdjbid
|
||
left join vaccine
|
||
on YMDJMX.ymid = vaccine.id
|
||
left join charge
|
||
on YMDJ.chargeid = charge.id
|
||
where jfzt = '已缴费' and YMDJMX.sfje <> 0";
|
||
DateTime tb = DateTime.Now.Date;
|
||
DateTime te = DateTime.Now.Date;
|
||
if (!string.IsNullOrEmpty(b))
|
||
{
|
||
|
||
if (DateTime.TryParse(b, out tb))
|
||
{
|
||
sql += " and charge.moneydate>=@b";
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(e))
|
||
{
|
||
|
||
if (DateTime.TryParse(e, out te))
|
||
{
|
||
sql += " and charge.moneydate<@e";
|
||
}
|
||
}
|
||
sql += " group by vaccine.name";
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
return conn.Query(sql, new { b = tb, e = te.AddDays(1) }).ToList();
|
||
}
|
||
}
|
||
|
||
public List<dynamic> getMRSFHZ(string b, string e)
|
||
{
|
||
//throw new NotImplementedException();
|
||
|
||
string sql = @"select CONVERT(varchar(10),moneydate,121) rq ,
|
||
sum(case method when '微信' then money else 0 end) as wx
|
||
,
|
||
sum(case method when '现金' then money else 0 end) as xj
|
||
,
|
||
sum(case method when '转账' then money else 0 end) as zz
|
||
,
|
||
sum(case method when '支付宝' then money else 0 end) as zfb,
|
||
SUM(money) hj
|
||
from charge where 1=1";
|
||
DateTime tb = DateTime.Now.Date;
|
||
DateTime te = DateTime.Now.Date;
|
||
if (!string.IsNullOrEmpty(b))
|
||
{
|
||
|
||
if (DateTime.TryParse(b, out tb))
|
||
{
|
||
sql += " and moneydate>=@b";
|
||
}
|
||
}
|
||
if (!string.IsNullOrEmpty(e))
|
||
{
|
||
|
||
if (DateTime.TryParse(e, out te))
|
||
{
|
||
sql += " and moneydate<@e";
|
||
}
|
||
}
|
||
sql += @"
|
||
group by CONVERT(varchar(10),moneydate,121)";
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
return conn.Query(sql, new { b = tb, e = te.AddDays(1) }).ToList();
|
||
}
|
||
}
|
||
|
||
public Models.DTO.YMJFXX getYYJFXX(string code)
|
||
{
|
||
//throw new NotImplementedException();
|
||
string sql = "select * from charge where [register_num] = @tm and type='疫苗收费' and status='未缴费' order by id desc";
|
||
using (var conn = CommHelper.GetSqlConnection())
|
||
{
|
||
var cm = conn.Query<Models.chargeModel>(sql, new { tm = code }).FirstOrDefault();
|
||
if (cm == null)
|
||
{
|
||
return new Models.DTO.YMJFXX { id = 0, State = 0, Message = "没有找到要缴费的消息!" };
|
||
}
|
||
else
|
||
{
|
||
var yj = new Models.DTO.YMJFXX();
|
||
yj.id = cm.id;
|
||
yj.xingming = cm.person;
|
||
yj.zfbm = cm.register_num;
|
||
yj.money = cm.money;
|
||
yj.jfrq = cm.createdate.ToString("yyyy-MM-dd HH:mm:ss");
|
||
yj.zfzt = cm.status;
|
||
yj.State = 1;
|
||
return yj;
|
||
}
|
||
}
|
||
//return null;
|
||
}
|
||
|
||
public Models.DTO.YMJFXX getTJJFXX(string code)
|
||
{
|
||
//throw new NotImplementedException();
|
||
string sql = "select * from charge where [register_num] = @tm and type='体检收费' and status='未缴费' order by id desc";
|
||
using (var conn = CommHelper.GetSqlConnection())
|
||
{
|
||
var cm = conn.Query<Models.chargeModel>(sql, new { tm = code }).FirstOrDefault();
|
||
if (cm == null)
|
||
{
|
||
return new Models.DTO.YMJFXX { id = 0, State = 0, Message = "没有找到要缴费的消息!" };
|
||
}
|
||
else
|
||
{
|
||
var yj = new Models.DTO.YMJFXX();
|
||
yj.id = cm.id;
|
||
yj.xingming = cm.person;
|
||
yj.zfbm = cm.register_num;
|
||
yj.money = cm.money;
|
||
yj.jfrq = cm.createdate.ToString("yyyy-MM-dd HH:mm:ss");
|
||
yj.zfzt = cm.status;
|
||
yj.State = 1;
|
||
return yj;
|
||
}
|
||
}
|
||
//return null;
|
||
}
|
||
|
||
public object bdfp(string id, string nfph, int printerid, string printerName)
|
||
{
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
string sql = "select * from invoice_print where id=@id and newfph is null";
|
||
int c = conn.ExecuteScalar<int>(sql, new { id });
|
||
if(c==1)
|
||
{
|
||
return new { State = 0, Message = "当前发票已经补打不能重新补打!" };
|
||
}
|
||
else
|
||
{
|
||
sql = "update invoice_print set newfph=@newfph,printTime=@printTime,printerid=@printerid,printerName=@printerName where id=@id";
|
||
conn.Execute(sql, new {id=id, newfph=nfph, printerid, printerName, printTime=DateTime.Now });
|
||
return new { State = 1, Message = "补打成功!" };
|
||
}
|
||
//return conn.Query<chargeModel>(sql + " order by id desc", new { start = start + " 00:00:00", end = end + " 23:59:59", person = person, tm = tm }).ToList();
|
||
}
|
||
}
|
||
|
||
public List<chargeModel> GetAllList3(string start, string end, string tm, string person)
|
||
{
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
string sql = "select * from charge where 1=1 and createdate >=@start and createdate<=@end and createperson=@person";
|
||
if (!string.IsNullOrEmpty(tm))
|
||
{
|
||
sql = sql + " and register_num = @tm";
|
||
}
|
||
return conn.Query<chargeModel>(sql + " order by id desc", new { start = start + " 00:00:00", end = end + " 23:59:59", person = person, tm = tm }).ToList();
|
||
}
|
||
}
|
||
|
||
public chargeModel getsfxx(string id)
|
||
{
|
||
//throw new NotImplementedException();
|
||
string sql = "select * from charge where id=@id";
|
||
using (var conn = CommHelper.GetSqlConnection())
|
||
{
|
||
var m = conn.Query<chargeModel>(sql, new { id = id }).FirstOrDefault();
|
||
if (m == null)
|
||
{
|
||
return m;
|
||
}
|
||
else
|
||
{
|
||
if (string.IsNullOrEmpty(m.register_num))
|
||
{
|
||
while (true)
|
||
{
|
||
m.register_num = DateTime.Now.ToString("yyyyMMddHHmmss") + new Random().Next(100, 999);
|
||
sql = "select count(1) from charge where register_num=@register_num";
|
||
int c = conn.ExecuteScalar<int>(sql, new { register_num = m.register_num });
|
||
if (c == 0)
|
||
{
|
||
sql = "update charge set register_num=@register_num where id=@id";
|
||
conn.Execute(sql, new { id = id, register_num = m.register_num });
|
||
return m;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
return m;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
public List<Models.charge_detailModel> getsfmx(string id)
|
||
{
|
||
string sql = "select * from charge_detail where chargeid=@id";
|
||
using (var conn = CommHelper.GetSqlConnection())
|
||
{
|
||
return conn.Query<charge_detailModel>(sql, new { id = id }).ToList();
|
||
}
|
||
}
|
||
|
||
//疫苗情况统计
|
||
public IEnumerable<dynamic> getYmList(string start, string end, string user)
|
||
{
|
||
string sql = "select vaccine.name,COUNT(ymzs.YMID) as sl,sum(ymdjmx.sfje) as je from ymzs,vaccine,ymdj,ymdjmx " +
|
||
"where ymzs.YMID = vaccine.id and ymzs.YMDJID = ymdj.id and ymzs.DJMXID = ymdjmx.id and vaccine.isCharge = '是' and " +
|
||
"ymdj.jfzt = '已缴费' and convert(datetime,ZSSJ) >=@start and convert(datetime,ZSSJ) <= @end and ZSRXM like '%" + user + "%' group by ymzs.YMID,vaccine.name " +
|
||
"union all " +
|
||
"select vaccine.name,COUNT(ymzs.YMID) as sl,0 as je from ymzs, vaccine, ymdj, ymdjmx " +
|
||
"where ymzs.YMID = vaccine.id and ymzs.YMDJID = ymdj.id and ymzs.DJMXID = ymdjmx.id and vaccine.isCharge = '否' " +
|
||
" and convert(datetime,ZSSJ) >=@start and convert(datetime,ZSSJ) <= @end and ZSRXM like '%" + user + "%' group by ymzs.YMID,vaccine.name";
|
||
using (var conn = CommHelper.GetSqlConnection())
|
||
{
|
||
return conn.Query(sql, new { start = DateTime.Parse(start), end = DateTime.Parse(end).AddDays(1) });
|
||
}
|
||
}
|
||
|
||
public void UpdateZfzt(string zfid, string t)
|
||
{
|
||
//throw new NotImplementedException();
|
||
string sql = "select * from charge where zfid=@zfid";
|
||
using (var conn = CommHelper.GetSqlConnection())
|
||
{
|
||
var m = conn.Query<chargeModel>(sql, new { zfid = zfid }).FirstOrDefault();
|
||
if (m != null)
|
||
{
|
||
if (m.type == "体检收费")
|
||
{
|
||
sql = "update professionalExam_register set payment='已缴费' where physical_num=@num";
|
||
conn.Execute(sql, new { num = m.register_num });
|
||
}
|
||
if (m.type == "疫苗收费")
|
||
{
|
||
sql = "update YMDJ set jfzt='已缴费' where chargeid=@id";
|
||
conn.Execute(sql, new { id = m.id });
|
||
}
|
||
}
|
||
sql = "update charge set status='已缴费' , method='" + t + "',moneydate=getdate(),moneyperson='" + t + "' where zfid='" + zfid + "'";
|
||
conn.Execute(sql);
|
||
}
|
||
}
|
||
|
||
public void UpdateZfCode(string id, string zfid)
|
||
{
|
||
//throw new NotImplementedException();
|
||
string sql = "update charge set zfid=@zfid where id=@id";
|
||
using (var conn = CommHelper.GetSqlConnection())
|
||
{
|
||
conn.Execute(sql, new { id = id, zfid = zfid });
|
||
}
|
||
}
|
||
|
||
public chargeModel getModel(string id)
|
||
{
|
||
//throw new NotImplementedException();
|
||
using (var conn = CommHelper.GetSqlConnection())
|
||
{
|
||
string sql = "select * from charge where id=@id";
|
||
return conn.Query<chargeModel>(sql, new { id = id }).FirstOrDefault();
|
||
}
|
||
}
|
||
|
||
public List<charge_detailModel> GetAllList2List(string chargeid)
|
||
{
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
string sql = "select * from charge_detail where 1=1 and chargeid = @chargeid";
|
||
return conn.Query<charge_detailModel>(sql, new { chargeid = chargeid }).ToList();
|
||
}
|
||
}
|
||
|
||
public object saveYmyy(ym_yyjl yyjl)
|
||
{
|
||
string sql = @"INSERT INTO [dbo].[ym_yyjl]
|
||
([ertbm]
|
||
,[yysj]
|
||
,[jdid]
|
||
,[ymList])
|
||
VALUES
|
||
(@ertbm
|
||
,@yysj
|
||
,@jdid
|
||
,@ymList)
|
||
";
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
try
|
||
{
|
||
int c = conn.Execute(sql, yyjl);
|
||
if (c > 0)
|
||
{
|
||
return new { State = 1, Message = "保存成功!" };
|
||
}
|
||
else
|
||
{
|
||
return new { State = 0, Message = "操作失败,请联系管理员!" };
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return new { State = 0, Message = ex.Message };
|
||
}
|
||
}
|
||
}
|
||
public object save(chargeModel ct, ERPUser user)
|
||
{
|
||
ct.createperson = user.TrueName;
|
||
ct.createdate = DateTime.Now;
|
||
string sql = "";
|
||
if (ct.id == 0)
|
||
{
|
||
sql = @"INSERT INTO [dbo].[charge]
|
||
([type]
|
||
,[type_id]
|
||
,[register_type]
|
||
,[register_num]
|
||
,[person_type]
|
||
,[person]
|
||
,[personcount]
|
||
,[company]
|
||
,[department]
|
||
,[method]
|
||
,[status]
|
||
,[isprint]
|
||
,[money]
|
||
,[moneydate]
|
||
,[createperson]
|
||
,[createdate])
|
||
VALUES
|
||
(@type
|
||
,@type_id
|
||
,@register_type
|
||
,@register_num
|
||
,@person_type
|
||
,@person
|
||
,@personcount
|
||
,@company
|
||
,@department
|
||
,@method
|
||
,@status
|
||
,@isprint
|
||
,@money
|
||
,@moneydate
|
||
,@createperson
|
||
,@createdate)";
|
||
}
|
||
else
|
||
{
|
||
sql = @"UPDATE [dbo].[charge]
|
||
SET [type] = @type
|
||
,[type_id] = @type_id
|
||
,[register_type] = @register_type
|
||
,[register_num] = @register_num
|
||
,[person_type] = @person_type
|
||
,[person] = @person
|
||
,[personcount] = @personcount
|
||
,[company] = @company
|
||
,[department] = @department
|
||
,[method] = @method
|
||
,[status] = @status
|
||
,[isprint] = @isprint
|
||
,[money] = @money
|
||
,[moneydate] = @moneydate
|
||
,[createperson] = @createperson
|
||
,[createdate] = @createdate
|
||
WHERE id=@id";
|
||
}
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
try
|
||
{
|
||
int c = conn.Execute(sql, ct);
|
||
if (c > 0)
|
||
{
|
||
return new { State = 1, Message = "保存成功!" };
|
||
}
|
||
else
|
||
{
|
||
return new { State = 0, Message = "操作失败,请联系管理员!" };
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return new { State = 0, Message = ex.Message };
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
public bool opSave(string jfdw, string jfbm, string jffs, string ysje, string items, string truename, string jdbm)
|
||
{
|
||
chargeModel mode = new chargeModel();
|
||
mode.type = "通用收费";
|
||
mode.type_id = "";
|
||
mode.register_type = "";
|
||
mode.register_num = "";
|
||
mode.person_type = "";
|
||
mode.person = jfdw;
|
||
mode.personcount = 1;
|
||
mode.company = "";
|
||
mode.department = jfbm;
|
||
mode.method = jffs;
|
||
mode.status = "未缴费";
|
||
mode.isprint = "未打印";
|
||
mode.money = Convert.ToDecimal(ysje);
|
||
mode.moneydate = null;
|
||
mode.createperson = truename;
|
||
mode.createdate = DateTime.Now;
|
||
|
||
string sql = @"INSERT INTO [dbo].[charge]
|
||
([type],[type_id],[register_type],[register_num],[person_type],[person],[personcount],[company] ,[department],[method],[status],[isprint] ,[money] ,[moneydate] ,[createperson],[createdate])
|
||
VALUES
|
||
(@type ,@type_id ,@register_type ,@register_num,@person_type ,@person,@personcount ,@company,@department
|
||
,@method ,@status,@isprint ,@money ,@moneydate,@createperson ,@createdate)select SCOPE_IDENTITY()";
|
||
int chargeid = 0;
|
||
|
||
List<charge_detailModel> models = new List<charge_detailModel>();
|
||
charge_detailModel m;
|
||
foreach (string item in items.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
|
||
{
|
||
string[] itemss = item.Split('|');
|
||
if (itemss.Length == 5)
|
||
{
|
||
m = new charge_detailModel();
|
||
m.chargeid = chargeid;
|
||
m.projectid = itemss[0];
|
||
m.projectname = itemss[1];
|
||
m.money = Convert.ToDecimal(itemss[2]);
|
||
m.count = Convert.ToInt32(itemss[3]);
|
||
m.pid = Convert.ToInt32(itemss[4]);
|
||
models.Add(m);
|
||
}
|
||
}
|
||
|
||
string sql2 = @"INSERT INTO [dbo].[charge_detail]
|
||
([chargeid] ,[projectid] ,[projectname] ,[money],[count],[pid])
|
||
VALUES
|
||
(@chargeid,@projectid ,@projectname,@money,@count,@pid) select scope_identity()";
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
var tran = conn.BeginTransaction();
|
||
try
|
||
{
|
||
chargeid = conn.Query<int>(sql, mode, tran).FirstOrDefault();
|
||
|
||
int result = 0;
|
||
for (int i = 0; i < models.Count; i++)
|
||
{
|
||
if (models[i].pid == -1)
|
||
{
|
||
models[i].chargeid = chargeid;
|
||
int id = conn.ExecuteScalar<int>(sql2, models[i], tran);
|
||
result++;
|
||
for (int j = 0; j < models.Count; j++)
|
||
{
|
||
if (models[j].pid == int.Parse(models[i].projectid))
|
||
{
|
||
models[j].chargeid = chargeid;
|
||
models[j].pid = id;
|
||
conn.ExecuteScalar<int>(sql2, models[j], tran);
|
||
result++;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
tran.Commit();
|
||
return true;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
tran.Rollback();
|
||
return false;
|
||
}
|
||
|
||
}
|
||
}
|
||
public int opSave1(string jfdw, string register_num, string jfbm, string jffs, string ysje, string items, ERPUser user, string type, string jmsq, string jdbm, string ertbm)
|
||
{
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
var tran = conn.BeginTransaction();
|
||
try
|
||
{
|
||
chargeModel mode = new chargeModel();
|
||
mode.type = type;
|
||
mode.type_id = "";
|
||
mode.register_type = "";
|
||
mode.register_num = register_num;
|
||
mode.person_type = "";
|
||
mode.person = jfdw;
|
||
mode.personcount = 1;
|
||
mode.company = "";
|
||
mode.department = jfbm;
|
||
mode.method = jffs;
|
||
if (jmsq != "1")
|
||
mode.status = "未缴费";
|
||
else
|
||
mode.status = "申请减免";
|
||
mode.isprint = "未打印";
|
||
mode.money = Convert.ToDecimal(ysje);
|
||
mode.moneydate = null;
|
||
mode.createperson = user.TrueName;
|
||
mode.createdate = DateTime.Now;
|
||
string sql = @"INSERT INTO [dbo].[charge]
|
||
([type],[type_id],[register_type],[register_num],[person_type],[person],[personcount],[company] ,[department],[method],[status],[isprint] ,[money] ,[moneydate] ,[createperson],[createdate])
|
||
VALUES
|
||
(@type ,@type_id ,@register_type ,@register_num,@person_type ,@person,@personcount ,@company,@department
|
||
,@method ,@status,@isprint ,@money ,@moneydate,@createperson ,@createdate)select SCOPE_IDENTITY()";
|
||
int chargeid = 0;
|
||
if (mode.money > 0)
|
||
chargeid = conn.Query<int>(sql, mode, tran).FirstOrDefault();
|
||
List<charge_detailModel> models = new List<charge_detailModel>();
|
||
charge_detailModel m;
|
||
ChargeProjectMaintainDal cpmd = new ChargeProjectMaintainDal();
|
||
string isCharge = "已缴费";
|
||
List<YMDJMX> mxs = new List<YMDJMX>();
|
||
foreach (string item in items.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
|
||
{
|
||
string[] itemss = item.Split('|');
|
||
if (itemss.Length == 7)
|
||
{
|
||
if (itemss[5] == "是")
|
||
{
|
||
isCharge = "未缴费";
|
||
}
|
||
YMDJMX mx = new YMDJMX();
|
||
mx.ymid = itemss[0];
|
||
mx.ymsl = itemss[3];
|
||
mx.sfje = double.Parse(itemss[2]);
|
||
mx.zssl = 0;
|
||
mx.ymdj = double.Parse(itemss[2]) * double.Parse(itemss[3]);
|
||
mxs.Add(mx);
|
||
string id = itemss[6];
|
||
List<ChargeProjectMaintainModel> cpmms = cpmd.getAddList(id);
|
||
for (int i = 0; i < cpmms.Count(); i++)
|
||
{
|
||
m = new charge_detailModel();
|
||
m.chargeid = chargeid;
|
||
m.projectid = cpmms[i].id.ToString();
|
||
m.projectname = cpmms[i].charge_project_name;
|
||
m.money = Convert.ToDecimal(cpmms[i].fee);
|
||
m.count = Convert.ToInt32(itemss[3]);
|
||
if (cpmms[i].is_add == "是")
|
||
{
|
||
for (int j = 0; j < cpmms.Count(); j++)
|
||
{
|
||
if (string.IsNullOrEmpty(cpmms[j].add_ids))
|
||
{
|
||
continue;
|
||
}
|
||
if (cpmms[j].add_ids.Split(',').Contains(cpmms[i].id.ToString()))
|
||
{
|
||
m.pid = cpmms[j].id;
|
||
}
|
||
}
|
||
}
|
||
else
|
||
{
|
||
m.pid = -1;
|
||
}
|
||
models.Add(m);
|
||
}
|
||
}
|
||
}
|
||
string max = "";
|
||
string dateStr = DateTime.Now.ToString("yyyyMMdd");
|
||
string getmaxsql = "select max(ymdjid) from YMDJ where ymdjid like '" + dateStr + "%'";
|
||
string nowMax = conn.ExecuteScalar<string>(getmaxsql, null, tran);
|
||
if (string.IsNullOrEmpty(nowMax))
|
||
{
|
||
max = dateStr + "0001";
|
||
}
|
||
else
|
||
{
|
||
max = (Int64.Parse(nowMax) + 1).ToString();
|
||
}
|
||
YMDJ ymdj = new YMDJ();
|
||
ymdj.ymdjid = max;
|
||
ymdj.ymjzid = register_num;
|
||
ymdj.name = jfdw;
|
||
ymdj.djrid = user.ID.ToString();
|
||
ymdj.djrxm = user.TrueName;
|
||
ymdj.djsj = DateTime.Now;
|
||
ymdj.sfzje = ysje;
|
||
ymdj.jfzt = isCharge;
|
||
ymdj.zs = "0";
|
||
ymdj.chargeid = chargeid.ToString();
|
||
YMDJDal ymdjDal = new YMDJDal();
|
||
int ymdjId = ymdjDal.save(ymdj).State;
|
||
for (int i = 0; i < mxs.Count(); i++)
|
||
{
|
||
mxs[i].ymdjbid = ymdjId.ToString();
|
||
}
|
||
YMDJMXDal mxDal = new YMDJMXDal();
|
||
mxDal.saves(mxs);
|
||
string sql2 = @"INSERT INTO [dbo].[charge_detail]
|
||
([chargeid] ,[projectid] ,[projectname] ,[money],[count],[pid])
|
||
VALUES
|
||
(@chargeid,@projectid ,@projectname,@money,@count,@pid) select scope_identity()";
|
||
int result = 0;
|
||
if (chargeid != 0)
|
||
for (int i = 0; i < models.Count; i++)
|
||
{
|
||
if (models[i].pid == -1)
|
||
{
|
||
int id = conn.ExecuteScalar<int>(sql2, models[i], tran);
|
||
result++;
|
||
for (int j = 0; j < models.Count; j++)
|
||
{
|
||
if (models[j].pid == int.Parse(models[i].projectid))
|
||
{
|
||
models[j].pid = id;
|
||
conn.ExecuteScalar<int>(sql2, models[j], tran);
|
||
result++;
|
||
}
|
||
}
|
||
}
|
||
}
|
||
var ss = new Common().getParm_Value("QYYMYY", "", "");
|
||
if (ss == "true")
|
||
{
|
||
//登记过程中 更新 疫苗接种流程记录表 ertbm = jiezhongmianyi_tiaomadayin表的id主键
|
||
if (!string.IsNullOrEmpty(ertbm))
|
||
{
|
||
|
||
string sql4 = @"INSERT INTO [dbo].[ym_jzlcjl]
|
||
([jdid] ,[jzsj] ,[ertbm])
|
||
VALUES
|
||
(@jdid,@jzsj ,@ertbm) select scope_identity()";
|
||
int id4 = conn.ExecuteScalar<int>(sql4, new { jdid = Convert.ToInt32(jdbm), jzsj = DateTime.Now, ertbm = ertbm }, tran);
|
||
|
||
string sql5 = "update jiezhongmianyi_tiaomadayin set jdid=@jdbm where barcode=@ertbm";
|
||
int id5 = conn.ExecuteScalar<int>(sql5, new { jdbm = Convert.ToInt32(jdbm), ertbm = ertbm }, tran);
|
||
}
|
||
}
|
||
tran.Commit();
|
||
return chargeid;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
tran.Rollback();
|
||
throw ex;
|
||
}
|
||
}
|
||
}
|
||
public string getInvoice(string truename, string sort)
|
||
{
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
try
|
||
{
|
||
charge_maintModel result = conn.Query<charge_maintModel>("select * from charge_maint where 1=1 and status='在用' and receive_person=@truename and invoice_type=@sort", new { truename = truename, sort = sort }).FirstOrDefault();
|
||
if (result == null)
|
||
return "不存在【" + sort + "】发票段";
|
||
else
|
||
{
|
||
string start = result.begin_num;
|
||
string end = result.end_num;
|
||
invoice_printModel result2 = conn.Query<invoice_printModel>("select * from invoice_print where 1=1 and charge_person_name=@truename and print_type=@sort and invoice_num>=@start and invoice_num<=@end order by id desc", new { truename = truename, sort = sort, start = start, end = end }).FirstOrDefault();
|
||
if (result2 == null)
|
||
return start + "|" + result.id;
|
||
else
|
||
{
|
||
if (result2.invoice_num == end)
|
||
{
|
||
return "发票段已用完,不能再使用";
|
||
}
|
||
else
|
||
{
|
||
return (Convert.ToInt64(result2.invoice_num) + 1).ToString() + "|" + result.id;
|
||
}
|
||
}
|
||
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return ex.Message;
|
||
}
|
||
}
|
||
}
|
||
|
||
public object opPrint(string fpdid, string fplx, string fpbh, string jfid, string jfry, string jfdw, string jffs, string jfbm, string jfje, string bz, string items, string truename, string zfm)
|
||
{
|
||
chargeModel result3;
|
||
charge_maintModel result4;
|
||
string serial = DateTime.Now.ToString("yyyyMMdd");
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
try
|
||
{
|
||
invoice_printModel result2 = conn.Query<invoice_printModel>("select * from invoice_print where 1=1 and invoice_num=@fpbh ", new { fpbh = fpbh }).FirstOrDefault();
|
||
if (result2 != null)
|
||
return new { State = 0, Message = "发票号已被使用!" };
|
||
//缴费主表
|
||
result3 = conn.Query<chargeModel>("select * from charge where 1=1 and id=@jfid", new { jfid = jfid }).FirstOrDefault();
|
||
//发票段表
|
||
result4 = conn.Query<charge_maintModel>("select * from charge_maint where 1=1 and id=@fpdid", new { fpdid = fpdid }).FirstOrDefault();
|
||
//流水号
|
||
var result5 = conn.Query<invoice_printModel>("select * from invoice_print where 1=1 and invoice_date='" + DateTime.Now.ToString("yyyy-MM-dd") + "' order by id desc").FirstOrDefault();
|
||
if (result5 == null)
|
||
serial += "1001";
|
||
else
|
||
serial += Convert.ToInt32(result5.serial_number.Substring(result5.serial_number.Length - 4, 4)) + 1;
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return new { State = 0, Message = ex.Message };
|
||
}
|
||
}
|
||
|
||
|
||
invoice_printModel mode = new invoice_printModel();
|
||
mode.invoice_num = fpbh;
|
||
mode.company = jfry;
|
||
mode.payment_type = jffs;
|
||
mode.department = jfbm;
|
||
mode.charge_person_name = truename;
|
||
mode.description = bz;
|
||
mode.person_count = result3.personcount;
|
||
mode.invoice_price = Convert.ToDecimal(jfje);
|
||
mode.actually_pay = Convert.ToDecimal(jfje);
|
||
mode.invoice_date = DateTime.Now.ToString("yyyy-MM-dd");
|
||
mode.pay_date = (result3.moneydate ?? DateTime.Now).ToString("yyyy-MM-dd");
|
||
mode.exam_type = result3.register_type;
|
||
mode.invoice_type = result3.person_type;
|
||
mode.money_type = result3.register_type;
|
||
mode.print_type = fplx;
|
||
mode.serial_number = serial;
|
||
mode.clear_num = "1";
|
||
mode.chargeid = Convert.ToInt32(jfid);
|
||
mode.fpdid = Convert.ToInt32(fpdid);
|
||
mode.invoice_num2 = "";
|
||
mode.iscancel = 1;
|
||
|
||
string sql = @"INSERT INTO [dbo].[invoice_print]
|
||
([invoice_num],[is_print_price_count],[company] ,[payment_type],[department] ,[charge_person_name],[description],[person_count] ,[match_person_count],[invoice_price],[actually_pay],[invoice_date],[status],[exam_type],[pay_company] ,[pay_date] ,[pay_person],[match_price],[no_match_price],[invoice_type] ,[money_type],[regist_rant],[dept_id],[return_description],[derate_money],[print_type],[accept_status],[serial_number],[upload_status],[clear_num],[chargeid],[fpdid],[invoice_num2],[iscancel])
|
||
VALUES
|
||
(@invoice_num ,@is_print_price_count ,@company ,@payment_type ,@department,@charge_person_name ,@description ,@person_count ,@match_person_count ,@invoice_price ,@actually_pay ,@invoice_date ,@status ,@exam_type ,@pay_company,@pay_date,@pay_person,@match_price ,@no_match_price ,@invoice_type,@money_type ,@regist_rant ,@dept_id,@return_description ,@derate_money
|
||
,@print_type ,@accept_status ,@serial_number ,@upload_status
|
||
,@clear_num,@chargeid,@fpdid,@invoice_num2,@iscancel)select SCOPE_IDENTITY()";
|
||
int invoiceid = 0;
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
IDbTransaction transaction = conn.BeginTransaction();
|
||
try
|
||
{
|
||
|
||
//发票表
|
||
invoiceid = conn.Query<int>(sql, mode, transaction).FirstOrDefault();
|
||
if (result3.status == "未缴费")
|
||
{
|
||
//收费表
|
||
conn.Execute("update charge set status='已缴费',isprint='已打印', moneydate='" + DateTime.Now + "',moneyperson=@truename,method=@method where id=@jfid", new { jfid = jfid, truename = truename, method = mode.payment_type }, transaction);
|
||
decimal total_money = result4.total_money + Convert.ToDecimal(jfje);
|
||
string normal_cou = (Convert.ToInt32(string.IsNullOrEmpty(result4.normal_cou) ? "0" : result4.normal_cou) + 1).ToString();
|
||
//发票段表
|
||
if (fpbh == result4.end_num)
|
||
conn.Execute("update charge_maint set status='已用完', over_time='" + DateTime.Now.ToString("yyyy-MM-dd") + "', total_money=@total_money ,normal_cou=@normal_cou where id=@fpdid", new { total_money = total_money, normal_cou = normal_cou, fpdid = fpdid }, transaction);
|
||
else
|
||
conn.Execute("update charge_maint set total_money=@total_money ,normal_cou=@normal_cou where id=@fpdid", new { total_money = total_money, normal_cou = normal_cou, fpdid = fpdid }, transaction);
|
||
//登记表
|
||
if (result3.type == "体检收费")
|
||
{
|
||
if (!string.IsNullOrEmpty(result3.type_id))
|
||
conn.Execute("update professionalExam_register set payment='已缴费' where id=@type_id", new { jfid = jfid, type_id = result3.type_id }, transaction);
|
||
}
|
||
else if (result3.type == "疫苗收费")
|
||
{
|
||
conn.Execute("update YMDJ set jfzt='已缴费' where chargeid=@type_id", new { type_id = result3.id }, transaction);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
//收费表
|
||
conn.Execute("update charge set isprint='已打印' where id=@jfid", new { jfid = jfid, truename = truename }, transaction);
|
||
decimal total_money = result4.total_money + Convert.ToDecimal(jfje);
|
||
string normal_cou = (Convert.ToInt32(string.IsNullOrEmpty(result4.normal_cou) ? "0" : result4.normal_cou) + 1).ToString();
|
||
//发票段表
|
||
if (fpbh == result4.end_num)
|
||
conn.Execute("update charge_maint set status='已用完', over_time='" + DateTime.Now.ToString("yyyy-MM-dd") + "', total_money=@total_money ,normal_cou=@normal_cou where id=@fpdid", new { total_money = total_money, normal_cou = normal_cou, fpdid = fpdid }, transaction);
|
||
else
|
||
conn.Execute("update charge_maint set total_money=@total_money ,normal_cou=@normal_cou where id=@fpdid", new { total_money = total_money, normal_cou = normal_cou, fpdid = fpdid }, transaction);
|
||
}
|
||
transaction.Commit();
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
transaction.Rollback();
|
||
return new { State = 0, Message = ex.Message };
|
||
}
|
||
}
|
||
|
||
List<charge_project_detailModel> models = new List<charge_project_detailModel>();
|
||
charge_project_detailModel m;
|
||
foreach (string item in items.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries))
|
||
{
|
||
string[] itemss = item.Split('|');
|
||
if (itemss.Length == 4)
|
||
{
|
||
m = new charge_project_detailModel();
|
||
m.invoice_print_id = invoiceid;
|
||
m.charge_project = itemss[1];
|
||
m.unit_price = Convert.ToDecimal(itemss[2]);
|
||
m.charge_num = Convert.ToInt32(itemss[3]);
|
||
m.charge_price = Convert.ToDecimal(itemss[2]) * Convert.ToInt32(itemss[3]);
|
||
models.Add(m);
|
||
}
|
||
}
|
||
|
||
string sql2 = @"INSERT INTO [dbo].[charge_project_detail]
|
||
([invoice_print_id],[charge_project],[unit_price],[charge_num],[charge_price])
|
||
VALUES
|
||
(@invoice_print_id,@charge_project,@unit_price,@charge_num,@charge_price)";
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
try
|
||
{
|
||
int result = conn.Execute(sql2, models);
|
||
if (result > 0)
|
||
return new { State = 1, Message = invoiceid };
|
||
else
|
||
return new { State = 0, Message = "添加明细0条!" };
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return new { State = 0, Message = ex.Message };
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
|
||
//结算
|
||
public List<chargeModel> GetBalance(string truename, string rq)
|
||
{
|
||
DateTime drq;
|
||
if (!DateTime.TryParse(rq, out drq))
|
||
{
|
||
drq = DateTime.Now;
|
||
}
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
string sql = "select a.* from charge a join invoice_print b on a.id=b.chargeid where 1=1 and a.status ='已缴费' and b.charge_person_name='" + truename + "' and (a.balance is null or a.balance ='' or a.balance ='未结算') and a.moneydate>='" + drq.ToString("yyyy-MM-dd") + "'"
|
||
+ " and a.moneydate<'" + drq.AddDays(1).ToString("yyyy-MM-dd") + "'";
|
||
//string sql = "select * from charge where 1=1 and status ='已缴费' and (balance is null or balance ='' or balance ='未结算') ";
|
||
return conn.Query<chargeModel>(sql + " order by id desc").ToList();
|
||
}
|
||
}
|
||
public object SaveBalance(string ids)
|
||
{
|
||
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
{
|
||
try
|
||
{
|
||
string sql = @"update charge set balance='已结算',balancedate='" + DateTime.Now + "' where id in (" + ids + ")";
|
||
int result = conn.Execute(sql);
|
||
return new { State = 1, Message = "操作成功" + result.ToString() };
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
return new { State = 0, Message = ex.Message };
|
||
}
|
||
}
|
||
}
|
||
|
||
// public OperationResult saveYmyy(ym_yyjl yyjl)
|
||
// {
|
||
// string sql = @"INSERT INTO [dbo].[ym_yyjl]
|
||
// ([ertbm]
|
||
// ,[yysj]
|
||
// ,[jdid]
|
||
// ,[ymList])
|
||
// VALUES
|
||
// (@ertbm
|
||
// ,@yysj
|
||
// ,@jdid
|
||
// ,@ymList)
|
||
// SELECT SCOPE_IDENTITY()
|
||
//";
|
||
// using (IDbConnection conn = CommHelper.GetSqlConnection())
|
||
// {
|
||
// try
|
||
// {
|
||
// int c = conn.ExecuteScalar<int>(sql, yyjl);
|
||
// if (c > 0)
|
||
// {
|
||
// return new OperationResult { State = 1, Message = "保存成功!", Tag = c.ToString() };
|
||
// }
|
||
// else
|
||
// {
|
||
// return new OperationResult { State = 0, Message = "操作失败,请联系管理员!" };
|
||
// }
|
||
// }
|
||
// catch (Exception ex)
|
||
// {
|
||
// return new OperationResult { State = 0, Message = ex.Message };
|
||
// }
|
||
// }
|
||
// }
|
||
|
||
}
|
||
}
|