From ca75d199ce417df84188a4cff3ee9c2fc100d68c Mon Sep 17 00:00:00 2001 From: sergei kasianenko Date: Sun, 5 May 2024 20:48:34 +0800 Subject: [PATCH 01/18] bill with price --- api/contracts/func.py | 10 +-- api/contracts/views.py | 17 +++-- contracts/admin.py | 2 +- contracts/models.py | 13 ++-- directions/models.py | 2 +- l2-frontend/src/pages/Billing/index.vue | 97 +++++++++++++++---------- statistic/sql_func.py | 6 +- 7 files changed, 89 insertions(+), 58 deletions(-) diff --git a/api/contracts/func.py b/api/contracts/func.py index 8917aa0d85..cafa5fd75a 100644 --- a/api/contracts/func.py +++ b/api/contracts/func.py @@ -6,17 +6,15 @@ from statistic.views import get_price_hospital -def researches_for_billing(type_price, company_id, date_start, date_end): +def researches_for_billing(type_price, company_id, date_start, date_end, price_id): sql_result = None research_coast = {} - price = None if type_price == "Заказчик": hospital_id = company_id - price = get_price_hospital(hospital_id, date_start, date_end) base = CardBase.objects.filter(internal_type=True).first() finsource = IstochnikiFinansirovaniya.objects.filter(base=base, title__in=["Договор"], hide=False).first() - sql_result = statistics_research_by_hospital_for_external_orders(date_start, date_end, hospital_id, finsource.pk) - coast_research_price = get_research_coast_by_prce((price.pk,)) + sql_result = statistics_research_by_hospital_for_external_orders(date_start, date_end, hospital_id, finsource.pk, price_id) + coast_research_price = get_research_coast_by_prce((price_id,)) research_coast = {coast.research_id: float(coast.coast) for coast in coast_research_price} result = {} iss_data = set() @@ -39,7 +37,7 @@ def researches_for_billing(type_price, company_id, date_start, date_end): 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.pk} + return {"result": result, "issIds": list(iss_data), "priceId": price_id} def get_confirm_data_for_billing(price_id, billing_id): diff --git a/api/contracts/views.py b/api/contracts/views.py index 71927e00d7..36ea004d17 100644 --- a/api/contracts/views.py +++ b/api/contracts/views.py @@ -19,8 +19,9 @@ def create_billing(request): hospital_id = body.get("hospitalId") date_start = body.get("dateStart") date_end = body.get("dateEnd") + price_id = body.get("priceId") info = body.get("info") - billing_id = BillingRegister.create_billing(company_id, hospital_id, date_start, date_end, info) + billing_id = BillingRegister.create_billing(company_id, hospital_id, date_start, date_end, info, price_id) return JsonResponse({"ok": True, "billingInfo": billing_id}) @@ -33,9 +34,10 @@ def update_billing(request): date_end = body.get("dateEnd") billing_id = body.get("id") info = body.get("info") - billing_info = BillingRegister.update_billing(billing_id, date_start, date_end, info) + price_id = body.get("priceId") + billing_info = BillingRegister.update_billing(billing_id, date_start, date_end, info, price_id) type_price = body.get("typeCompany") - data = researches_for_billing(type_price, hospital_id, date_start, date_end) + data = researches_for_billing(type_price, hospital_id, date_start, date_end, price_id) structure_data = structure_table(data) return JsonResponse({"ok": True, "billingInfo": billing_info, **structure_data}) @@ -63,8 +65,11 @@ def get_hospital_prices(request): hospital_id = body.get("hospitalId") date_start = body.get("dateStart") date_end = body.get("dateEnd") - prices = PriceName.get_hospital_many_prices_by_date(hospital_id, date_start, date_end, is_subcontract=True) - prices_data = [{"id": i.pk, "label": i.title} for i in prices] + if not(date_start) or not(date_end): + prices_data = [] + else: + prices = PriceName.get_hospital_many_prices_by_date(hospital_id, date_start, date_end, is_subcontract=True) + prices_data = [{"id": i.pk, "label": i.title} for i in prices] return JsonResponse({"data": prices_data}) @@ -94,6 +99,6 @@ def get_billing(request): billing_id = request_data.get("billingId") result = BillingRegister.get_billing(billing_id) type_price = request_data.get("typeCompany") - data = researches_for_billing(type_price, result["hospitalId"], result["dateStart"], result["dateEnd"]) + data = researches_for_billing(type_price, result["hospitalId"], result["dateStart"], result["dateEnd"], result["priceId"]) structure_data = structure_table(data) return JsonResponse({"result": result, **structure_data}) diff --git a/contracts/admin.py b/contracts/admin.py index 2d026100f6..4cbc32871f 100644 --- a/contracts/admin.py +++ b/contracts/admin.py @@ -95,7 +95,7 @@ class ResMedicalExamination(admin.ModelAdmin): class ResBillingRegister(admin.ModelAdmin): - list_display = ('company', 'hospital',) + list_display = ('company', 'hospital', 'date_start', 'date_end', 'price',) list_display_links = ('company', 'hospital',) list_filter = ('hospital', 'create_at',) diff --git a/contracts/models.py b/contracts/models.py index 6cb38bfa5b..44955ca3f8 100644 --- a/contracts/models.py +++ b/contracts/models.py @@ -364,26 +364,28 @@ class BillingRegister(models.Model): date_end = models.DateField(help_text="Дата окончания периода", default=None, blank=True, null=True, db_index=True) info = models.CharField(max_length=128, help_text="Информация по счет", default=None, blank=True, null=True) is_confirmed = models.BooleanField(default=False, help_text="Сформирован счет") - price_name = models.ForeignKey(PriceName, on_delete=models.DO_NOTHING, default=None, blank=True, null=True, db_index=True) + price = models.ForeignKey(PriceName, on_delete=models.DO_NOTHING, default=None, blank=True, null=True, db_index=True) def __str__(self): - return f"{self.company} - {self.date_start} - {self.date_end}" + return f"{self.company} - {self.date_start} - {self.date_end} - {self.price}" @staticmethod - def update_billing(billing_id, date_start, date_end, info): + def update_billing(billing_id, date_start, date_end, info, price_id): current_billing = BillingRegister.objects.filter(id=billing_id).first() if current_billing: current_billing.date_start = date_start current_billing.date_end = date_end current_billing.info = info + current_billing.price_id = price_id current_billing.save() return info else: return False @staticmethod - def create_billing(company_id, hospital_id, date_start, date_end, info): - current_billing = BillingRegister(hospital_id=hospital_id, company_id=company_id, date_start=date_start, date_end=date_end, info=info) + def create_billing(company_id, hospital_id, date_start, date_end, info, price_id): + current_billing = BillingRegister(hospital_id=hospital_id, company_id=company_id, date_start=date_start, date_end=date_end, info=info, + price_name_id=price_id) current_billing.save() return current_billing.pk @@ -420,6 +422,7 @@ def as_json(self): "dateEnd": self.date_end, "info": self.info, "isConfirmed": self.is_confirmed, + "priceId": self.price_id, } return result diff --git a/directions/models.py b/directions/models.py index 5399b04e67..f1feca8176 100644 --- a/directions/models.py +++ b/directions/models.py @@ -2385,7 +2385,7 @@ def gen_after_confirm(self, user: User): ) def __str__(self): - return f"{self.pk} - {self.napravleniye.pk}-{self.napravleniye.client.get_fio_w_card()}" + return f"{self.pk} - {self.napravleniye}" def is_get_material(self): """ diff --git a/l2-frontend/src/pages/Billing/index.vue b/l2-frontend/src/pages/Billing/index.vue index 35d7b42a54..7dded19aaf 100644 --- a/l2-frontend/src/pages/Billing/index.vue +++ b/l2-frontend/src/pages/Billing/index.vue @@ -70,18 +70,28 @@
+ +