public async Task <IActionResult> SubmitForm([FromBody] AddFeeInput input) { await _billingApp.CreateBatch(input); return(Success("操作成功。")); }
public async Task <float> CreateBatch(AddFeeInput input) { var list = new List <BillingEntity>(); var patient = await _uow.GetRepository <PatientEntity>().FindEntityAsync(input.PatientId); var date = DateTime.Now; var user = await _usersService.GetCurrentUserAsync(); foreach (var item in input.Items) { switch (item.BillType) { case 1: if (item.Amount > 0) { var dict = await _uow.GetRepository <DrugsEntity>().FindEntityAsync(item.ItemId); list.Add(new BillingEntity { F_Amount = item.Amount, F_BillingDateTime = date, F_BillingPerson = user?.F_RealName, F_BillingPersonId = user?.F_Id, F_Charges = dict.F_Charges, F_Costs = (dict.F_Charges * item.Amount).ToFloat(2), F_DialylisNo = patient.F_DialysisNo, F_Pid = patient.F_Id, F_PGender = patient.F_Gender, F_PName = patient.F_Name, F_ItemClass = "药品", F_ItemCode = dict.F_DrugCode, F_ItemId = dict.F_Id, F_ItemName = dict.F_DrugName, F_ItemSpec = dict.F_DrugSpec, F_ItemSpell = dict.F_DrugSpell, F_ItemUnit = dict.F_DrugUnit, F_Supplier = dict.F_DrugSupplier }); } break; case 2: if (item.Amount > 0) { var dict = await _uow.GetRepository <MaterialEntity>().FindEntityAsync(item.ItemId); list.Add(new BillingEntity { F_Amount = item.Amount, F_BillingDateTime = date, F_BillingPerson = user?.F_RealName, F_BillingPersonId = user?.F_Id, F_Charges = dict.F_Charges, F_Costs = (dict.F_Charges * item.Amount).ToFloat(2), F_DialylisNo = patient.F_DialysisNo, F_Pid = patient.F_Id, F_PGender = patient.F_Gender, F_PName = patient.F_Name, F_ItemClass = "耗材", F_ItemCode = dict.F_MaterialCode, F_ItemId = dict.F_Id, F_ItemName = dict.F_MaterialName, F_ItemSpec = dict.F_MaterialSpec, F_ItemSpell = dict.F_MaterialSpell, F_ItemUnit = dict.F_MaterialUnit, F_Supplier = dict.F_MaterialSupplier }); } break; case 3: if (item.Amount > 0) { var dict = await _uow.GetRepository <TreatmentEntity>().FindEntityAsync(item.ItemId); list.Add(new BillingEntity { F_Amount = item.Amount, F_BillingDateTime = date, F_BillingPerson = user?.F_RealName, F_BillingPersonId = user?.F_Id, F_Charges = dict.F_Charges, F_Costs = (dict.F_Charges * item.Amount).ToFloat(2), F_DialylisNo = patient.F_DialysisNo, F_Pid = patient.F_Id, F_PGender = patient.F_Gender, F_PName = patient.F_Name, F_ItemClass = "诊疗", F_ItemCode = dict.F_TreatmentCode, F_ItemId = dict.F_Id, F_ItemName = dict.F_TreatmentName, F_ItemSpec = dict.F_TreatmentSpec, F_ItemSpell = dict.F_TreatmentSpell, F_ItemUnit = dict.F_TreatmentUnit }); } break; } } await SubmitFormBatch(list); //扣减库存 //if (type == "耗材") || type == "药品")) //{ // var storageList = (from r in NFine.Code.Json.ToJArrayObject(data) // select new // { // itemId = r.Value<string>("F_ItemId"), // count = r.Value<float>("F_Amount").ToInt() // }).ToList(); // new StorageApp().ConsumeStock(storageList.ToJson()); //} return(list.Sum(t => t.F_Costs * t.F_Amount).ToFloat(2)); }
public async Task <IActionResult> AddFee([FromBody] AddFeeInput input) { var patient = await _patientApp.GetForm(input.PatientId); if (patient == null) { return(BadRequest("患者Id有误!")); } var drugDict = _drugsApp; var materials = _materialApp; var treatments = _treatmentApp; var user = await _usersService.GetCurrentUserAsync(); var billingDateTime = DateTime.Now; var totalCosts = 0f; var list = new List <BillingEntity>(); foreach (var item in input.Items.FindAll(t => t.Amount > 0 && (t.BillType == 1 || t.BillType == 2 || t.BillType == 3))) { var entity = new BillingEntity { F_Id = Common.GuId(), F_Pid = input.PatientId, F_DialylisNo = patient.F_DialysisNo, F_PName = patient.F_Name, F_PGender = patient.F_Gender, F_BillingDateTime = billingDateTime, F_BillingPersonId = user.F_Id, F_BillingPerson = user.F_RealName, F_CreatorTime = DateTime.Now, F_CreatorUserId = user.F_Id, F_EnabledMark = true }; switch (item.BillType) { case 1: entity.F_ItemClass = "药品"; var findDrug = await drugDict.GetForm(item.ItemId); if (findDrug != null) { entity.F_ItemId = item.ItemId; entity.F_ItemCode = findDrug.F_DrugCode; entity.F_ItemName = findDrug.F_DrugName; entity.F_ItemSpec = findDrug.F_DrugSpec; entity.F_ItemUnit = findDrug.F_DrugUnit; entity.F_Amount = item.Amount; entity.F_Charges = entity.F_Costs = item.Amount * findDrug.F_Charges; entity.F_Supplier = findDrug.F_DrugSupplier; list.Add(entity); } break; case 2: entity.F_ItemClass = "耗材"; var findMaterials = await materials.GetForm(item.ItemId); if (findMaterials != null) { entity.F_ItemId = item.ItemId; entity.F_ItemCode = findMaterials.F_MaterialCode; entity.F_ItemName = findMaterials.F_MaterialName; entity.F_ItemSpec = findMaterials.F_MaterialSpec; entity.F_ItemUnit = findMaterials.F_MaterialUnit; entity.F_Amount = item.Amount; entity.F_Charges = entity.F_Costs = item.Amount * findMaterials.F_Charges; entity.F_Supplier = findMaterials.F_MaterialSupplier; list.Add(entity); } break; case 3: entity.F_ItemClass = "诊疗"; var treatmentEntity = await treatments.GetForm(item.ItemId); if (treatmentEntity != null) { entity.F_ItemId = item.ItemId; entity.F_ItemCode = treatmentEntity.F_TreatmentCode; entity.F_ItemName = treatmentEntity.F_TreatmentName; entity.F_ItemSpec = treatmentEntity.F_TreatmentSpec; entity.F_ItemUnit = treatmentEntity.F_TreatmentUnit; entity.F_Amount = item.Amount; entity.F_Charges = entity.F_Costs = item.Amount * treatmentEntity.F_Charges; //entity.F_Supplier = findtreatments; list.Add(entity); } break; } } await _billingApp.InsertList(list); totalCosts = list.Sum(t => t.F_Costs).ToFloat(2); var data = new { totalCosts }; return(Ok(data)); }