diff --git a/api/contracts/func.py b/api/contracts/func.py index a9af69b72a..b151a0c3a9 100644 --- a/api/contracts/func.py +++ b/api/contracts/func.py @@ -12,6 +12,8 @@ def researches_for_billing(type_price, company_id, date_start, date_end, price_i hospital_id = company_id base = CardBase.objects.filter(internal_type=True).first() finsource = IstochnikiFinansirovaniya.objects.filter(base=base, title__in=["Договор"], hide=False).first() + if not finsource: + return {"ok": False, "result": [], "issIds": [], "priceId": "", "message": "Нет источника финансирования 'Договор'"} if not is_confirmed: sql_result = statistics_research_by_hospital_for_external_orders(date_start, date_end, hospital_id, finsource.pk, price_id) else: @@ -20,27 +22,26 @@ def researches_for_billing(type_price, company_id, date_start, date_end, price_i research_coast = {coast.research_id: float(coast.coast) for coast in coast_research_price} result = {} iss_data = set() - if sql_result: - for i in sql_result: - iss_data.add(i.iss_id) - current_data = { - "research_id": i.research_id, - "research_title": i.research_title, - "date_confirm": i.date_confirm, - "patient_fio": f"{i.patient_family} {i.patient_name} {i.patient_patronymic}", - "patient_born": i.ru_date_born, - "tube_number": i.tube_number, - "coast": research_coast.get(i.research_id, 0), - "code_nmu": i.code_nmu, - "internal_code": i.internal_code, - "execute_date": i.date_confirm, - "dir_id": i.dir_id, - } - if not result.get(i.patient_card_num): - result[i.patient_card_num] = [current_data.copy()] - else: - result[i.patient_card_num].append(current_data.copy()) - return {"result": result, "issIds": list(iss_data), "priceId": price_id} + for i in sql_result: + iss_data.add(i.iss_id) + current_data = { + "research_id": i.research_id, + "research_title": i.research_title, + "date_confirm": i.date_confirm, + "patient_fio": f"{i.patient_family} {i.patient_name} {i.patient_patronymic}", + "patient_born": i.ru_date_born, + "tube_number": i.tube_number, + "coast": research_coast.get(i.research_id, 0), + "code_nmu": i.code_nmu, + "internal_code": i.internal_code, + "execute_date": i.date_confirm, + "dir_id": i.dir_id, + } + if not result.get(i.patient_card_num): + result[i.patient_card_num] = [current_data.copy()] + else: + result[i.patient_card_num].append(current_data.copy()) + return {"ok": True, "result": result, "issIds": list(iss_data), "priceId": price_id} def get_confirm_data_for_billing(price_id, billing_id): @@ -147,18 +148,19 @@ def structure_table(data_researches): "executeDate": "", "summ": sum_patient, } - patient_data["total"] = { - "serialNumber": "", - "patientFio": "Итого", - "patientBirthDay": "", - "tubeNumber": "", - "coast": "", - "researchTitle": "", - "internalId": "", - "codeNMU": "", - "executeDate": "", - "summ": total, - } + if patient_data: + patient_data["total"] = { + "serialNumber": "", + "patientFio": "Итого", + "patientBirthDay": "", + "tubeNumber": "", + "coast": "", + "researchTitle": "", + "internalId": "", + "codeNMU": "", + "executeDate": "", + "summ": total, + } table_data = [v for v in patient_data.values()] return {"columns": columns, "tableData": table_data} diff --git a/api/contracts/views.py b/api/contracts/views.py index 46478de4bf..feb7e10621 100644 --- a/api/contracts/views.py +++ b/api/contracts/views.py @@ -8,6 +8,7 @@ from directions.models import Issledovaniya from directory.models import Researches from laboratory.decorators import group_required +from slog.models import Log from utils.response import status_response @@ -70,6 +71,15 @@ def confirm_billing(request): set_billing_id_for_iss = Issledovaniya.save_billing(billing_id, iss_ids) data_confirm_billing = get_confirm_data_for_billing(price_id, billing_id) raw_document_pk = RawDocumentBillingRegister.create_raw_billing_data(billing_id, data_confirm_billing) + Log.log( + billing_data.pk, + 200000, + request.user.doctorprofile, + { + "billing": {"pk": billing_data.pk, "date_from": str(billing_data.date_from), "registry_number": billing_data.registry_number}, + "who_confirm": {"pk": user_who_create.pk, "family": user_who_create.family, "name": user_who_create.name, "patronymic": user_who_create.patronymic}, + }, + ) structure_data = structure_table(data) return JsonResponse({"ok": is_confirm_billing and set_billing_id_for_iss and raw_document_pk, **structure_data}) @@ -87,6 +97,15 @@ def cancel_billing(request): billing_data.who_create = user_who_create billing_data.save() Issledovaniya.cancel_billing(billing_id) + Log.log( + billing_data.pk, + 200001, + request.user.doctorprofile, + { + "billing": {"pk": billing_data.pk, "date_from": str(billing_data.date_from), "registry_number": billing_data.registry_number}, + "who_cancel": {"pk": user_who_create.pk, "family": user_who_create.family, "name": user_who_create.name, "patronymic": user_who_create.patronymic}, + }, + ) return JsonResponse({"ok": True}) @@ -131,5 +150,7 @@ def get_billing(request): result = BillingRegister.get_billing(billing_id) type_price = request_data.get("typeCompany") data = researches_for_billing(type_price, result["hospitalId"], result["dateStart"], result["dateEnd"], result["priceId"], result["isConfirmed"], billing_id) + if not data["ok"]: + return JsonResponse({"ok": data["ok"], "result": [], "message": data["message"]}) structure_data = structure_table(data) - return JsonResponse({"result": result, **structure_data}) + return JsonResponse({"ok": True, "result": result, "message": "", **structure_data}) diff --git a/api/views.py b/api/views.py index 26ae4d3ed4..773936f08a 100644 --- a/api/views.py +++ b/api/views.py @@ -2682,19 +2682,19 @@ def update_price(request): if request_data.get("typePrice") == "Работодатель": current_price = PriceName( title=request_data["title"], symbol_code=request_data["code"], date_start=request_data["start"], date_end=request_data["end"], company_id=request_data["company"], - contract_number=request_data["contractNumber"] + contract_number=request_data.get("contractNumber") ) elif request_data.get("typePrice") == "Заказчик": hospital = Hospitals.objects.filter(pk=int(request_data["company"])).first() current_price = PriceName( title=request_data["title"], symbol_code=request_data["code"], date_start=request_data["start"], date_end=request_data["end"], hospital=hospital, subcontract=True, - contract_number=request_data["contractNumber"] + contract_number=request_data.get("contractNumber") ) elif request_data.get("typePrice") == "Внешний исполнитель": hospital = Hospitals.objects.filter(pk=int(request_data["company"])).first() current_price = PriceName( title=request_data["title"], symbol_code=request_data["code"], date_start=request_data["start"], date_end=request_data["end"], hospital=hospital, external_performer=True, - contract_number=request_data["contractNumber"] + contract_number=request_data.get("contractNumber") ) if current_price: current_price.save() diff --git a/forms/xlsx/billing/billing_func.py b/forms/xlsx/billing/billing_func.py index 03eb17ae11..9ff66f9f09 100644 --- a/forms/xlsx/billing/billing_func.py +++ b/forms/xlsx/billing/billing_func.py @@ -46,10 +46,12 @@ def fill_billing(ws1, data, row=14): style_border2.border = Border(left=bd, top=bd, right=bd, bottom=bd) style_border2.font = Font(bold=False, size=10) style_border2.alignment = Alignment(wrap_text=True, horizontal="center", vertical="center") - logo = Image(os.path.join(BASE_DIR, "forms", "xlsx", "media", "logo.png")) - logo.height = 130 - logo.width = 920 - ws1.add_image(logo, "A1") + logo_exists = os.path.exists(f"{BASE_DIR}/forms/xlsx/media/logo.png") + if logo_exists: + logo = Image(os.path.join(BASE_DIR, "forms", "xlsx", "media", "logo.png")) + logo.height = 130 + logo.width = 920 + ws1.add_image(logo, "A1") ws1.merge_cells("A9:L11") megre_cell = ws1["A9"] megre_cell.value = "Реестр № 1YYYY от 00 марта 2024 года \n оказанных медицинских услуг по договору №00 - 00/00/2024 \n с 00.00.00 по 00.00.00" diff --git a/l2-frontend/src/pages/Billing/index.vue b/l2-frontend/src/pages/Billing/index.vue index bf5bcc695d..145a1ec67a 100644 --- a/l2-frontend/src/pages/Billing/index.vue +++ b/l2-frontend/src/pages/Billing/index.vue @@ -276,6 +276,7 @@ const currentBillingData = ref({ registryNumber: '', }); +const datesFilled = computed(() => !!(currentBillingData.value.dateStart && currentBillingData.value.dateEnd)); const clearBilling = () => { currentBillingData.value = { ...billingTemplate.value }; }; @@ -292,17 +293,21 @@ const getPrices = async () => { const getBilling = async () => { await store.dispatch(actions.INC_LOADING); - const { result, columns, tableData } = await api('contracts/get-billing', { + const { + ok, result, message, columns, tableData, + } = await api('contracts/get-billing', { billingId: selectedBilling.value, typeCompany: selectedType.value, }); await store.dispatch(actions.DEC_LOADING); - currentBillingData.value = result; - colTable.value = columns; - services.value = tableData; - const { data } = await api('contracts/get-hospital-prices', { ...currentBillingData }); - prices.value = data; - selectedPrice.value = result.priceId; + if (ok) { + currentBillingData.value = result; + colTable.value = columns; + services.value = tableData; + selectedPrice.value = result.priceId; + } else { + root.$emit('msg', 'error', message); + } }; watch(selectedBilling, () => { @@ -343,12 +348,12 @@ const confirmBilling = async () => { const priceId = selectedPrice.value; await store.dispatch(actions.INC_LOADING); const { - ok, billingInfo, + ok, } = await api(apiPoint, { ...billingData, priceId }); await store.dispatch(actions.DEC_LOADING); if (ok) { await getBilling(); - root.$emit('msg', 'ok', `${billingInfo} сохранен`); + root.$emit('msg', 'ok', 'Счёт подтверждён'); } else { root.$emit('msg', 'error', 'ошибка'); } @@ -360,12 +365,12 @@ const cancelBilling = async () => { const apiPoint = 'contracts/cancel-billing'; await store.dispatch(actions.INC_LOADING); const { - ok, billingInfo, + ok, } = await api(apiPoint, { id: selectedBilling.value }); await store.dispatch(actions.DEC_LOADING); if (ok) { await getBilling(); - root.$emit('msg', 'ok', `${billingInfo} Отменен`); + root.$emit('msg', 'ok', 'Счёт сброшен'); } else { root.$emit('msg', 'error', 'ошибка'); } @@ -392,6 +397,7 @@ const createBilling = async () => { await store.dispatch(actions.DEC_LOADING); if (ok) { root.$emit('msg', 'ok', 'Создано'); + await getBillings(); selectedBilling.value = billingInfo; } else { root.$emit('msg', 'error', 'ошибка'); @@ -399,14 +405,8 @@ const createBilling = async () => { } }; -watch(() => currentBillingData.value.dateStart, (newValue, oldValue) => { - if ((newValue !== oldValue) && currentBillingData.value.dateEnd) { - getPrices(); - } -}); - -watch(() => currentBillingData.value.dateEnd, (newValue, oldValue) => { - if ((newValue !== oldValue) && currentBillingData.value.dateStart) { +watch(() => [currentBillingData.value.dateStart, currentBillingData.value.dateEnd], () => { + if (datesFilled.value) { getPrices(); } }); @@ -415,7 +415,6 @@ watch(selectedCompany, () => { if (selectedCompany.value) { selectedBilling.value = null; getBillings(); - getPrices(); } else { selectedBilling.value = null; } diff --git a/slog/models.py b/slog/models.py index a80cb2fa21..0f025d69c6 100644 --- a/slog/models.py +++ b/slog/models.py @@ -161,6 +161,8 @@ class Log(models.Model): (190002, 'FTP HL7: результат pull'), (190003, 'FTP HL7: результат push'), (190004, 'REST: заказ принятие'), + (200000, 'Счет на оплату: подтверждение'), + (200001, 'Счет на оплату: сброс подтверждения'), ) # Виды событий, которые могут быть очищены