From c05154353256498bf8d8e557955c3ae563c08b8f Mon Sep 17 00:00:00 2001 From: iriska-gri <79623434+iriska-gri@users.noreply.github.com> Date: Tue, 21 Nov 2023 15:20:22 +0300 Subject: [PATCH] =?UTF-8?q?=D0=97=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=B2=20=D0=91=D0=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/db.sqlite3 | Bin 405504 -> 405504 bytes src/front/src/components/load-round.vue | 4 +- src/general_vacation/excel.py | 75 ++++++++++++++++++++++++ src/general_vacation/models.py | 2 +- src/general_vacation/views.py | 59 +++---------------- src/userauth/models.py | 1 + 6 files changed, 87 insertions(+), 54 deletions(-) diff --git a/src/db.sqlite3 b/src/db.sqlite3 index 6c2d38404be84fd164ecde94dd3449937aa36bf2..445761ab73e6307dfef6d5321b563612f2fd162d 100644 GIT binary patch delta 2611 zcmaKud2AF_9LML)yxIGp^lq)pc3a8{vpa8Q_KYG08-jMBLP-oL%hKJ@Lc80vr5pve z+oC2Uk~V8HK@&_2!6VUtn>d30p)n@3G+e=`!J{S`VkClp7zyF<%}jUc)(n5l&d!_9 z@AtmH#%Z>VKa-XnQz-zf9-rpTIkV@{2#o}E}`>809emO@n)pZpVwVaIa z8S0MpCkOg^1_yi6DPkt~u`dEp{tsXMDhgSqa>o7_Ny}9JrT(;~vH~{LgFS=E0mUlO z(>2te9z^+{4=k<3==q#+B2HS)=UbU=mdbJjiH7>2 zU;Na{beNwoP=G|ljCQ-A-KMqM)VS@sY`YHbTmxkieVTL`tmiGm^pm+(rb+HNO@3r1 zi4loQ!@cq?7M79n>tB$E%4Nub`%W3mk}DtxNxnY1US9Vb`T5(SI_pWo`K|Lq=cseD z^C`ze$2G?Xj>C>kj%D`y_N(^y?T73e?Jc%@wkx(%wh>#0t=W3lddYec3+=XMJatCG z?E+=4a5xZPIgUj_faiFDMLdf_j`X1Vzy(+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>DGSuh4L=LDukJ(ST`GL7;`Y`#HODX&1eG{DiDXPe}qh@EyEE`6T|uy52*^ zj*eYcT!rJ5U%`H+*|8CSi^r`3kN^-zGlv1cEsjsiFh_>6NA;Xn)C)?LmkWjuFJ48h z7Fp_1)LNFZ9kw3#dYRXBB$I0_m7cMl~thk`;@@+W$kIJ_gxfkV_y { - + console.log(ex, 'sdata'); const sdata = new FormData() sdata.append('dailyfiles', dailyfiles.value[0]) - console.log(sdata, 'sdata'); + axiosApiInstance.post(`api/general_vacation/dailyroundup/?excel=${ex}`, sdata).then(result => { info.value = result.data console.log(result.data, '----------------') diff --git a/src/general_vacation/excel.py b/src/general_vacation/excel.py index b5ba7f877..67b5281bc 100644 --- a/src/general_vacation/excel.py +++ b/src/general_vacation/excel.py @@ -7,6 +7,9 @@ from openpyxl.worksheet.formula import ArrayFormula from pandas.api.types import CategoricalDtype import urllib.request from datetime import date +from .models import * +from datetime import datetime +from django.db.models import Count class roundExcel(): def __init__(self, us): @@ -168,6 +171,7 @@ class roundExcel(): return (width) / PIXELS_PER_CHAR def excelvacation(self): + print('helooooooooooooooooooooooooooooooooooooo') # def excroundread(self): # file = request.data['dailyfiles'] @@ -218,4 +222,75 @@ class roundExcel(): # mess = "Файл загружен" +class loadExcel(): + def __init__(self, us, files): + self.file = files + self.dfuser = pd.DataFrame.from_records(us) + + + + def roundfilse(self): + ed = pd.read_excel(self.file) + df = pd.DataFrame(ed) + datas = df.columns[8].split(" ")[1] + + df.columns = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"] + df=df.iloc[6:] + df= df[df.b.notna()] + df= df[df.a.notna()] + df['b']=df['b'].str[-3:] + df=df[['b', 'f', 'h', 'j','l']] + + df['b'] = df['b'].astype(int) + + types = ['f', 'h', 'j','l'] + for n in types: + df[n] = df[n].fillna(0) + df[n] = df[n].astype(int) + + df3 = pd.merge(df, self.dfuser, left_on= 'b', right_on="id") + df3=df3[['login', 'f', 'h', 'j','l']] + + for ind in df3.index: + keys = '' + if df3['h'][ind] == 1: + keys = 4 # В отпуске + elif df3['j'][ind] == 1: + keys = 5 # Болен + elif df3['l'][ind] == 1: + keys = 2 # Удаленка + elif df3['f'][ind] == 1: + keys = 1 # На работе + else: + keys = 6 + base=BasePosition.objects.get(pk=keys) + DailyRoundUp.objects.update_or_create(todaysDate=datetime.strptime(datas, '%d.%m.%Y').strftime('%Y-%m-%d'), + user=df3['login'][ind], defaults={'position':base}) + + pos = DailyRoundUp.objects.values('position__name', 'position').filter(position=6,todaysDate=date.today()).annotate(Count('user')) + + + + return pos + + def vacationsExcel(self): + ed = pd.read_excel(self.file, sheet_name='Запланированные отпуска') + df = pd.DataFrame(ed) + df.columns = ["a", "b", "c", "d", "e", "f", "g"] + df=df[['b', 'c', 'd', 'e','f']] + df3 = pd.merge(df, self.dfuser, left_on= 'b', right_on="fio") + df3=df3[['login', 'c', 'd', 'e','f']] + df3.loc[(df3['e'] == 'Осн'), 'e'] = 'os' + df3.loc[(df3['e'] == 'Доп н/д'), 'e'] = 'nd' + df3.loc[(df3['e'] == 'Доп в/л'), 'e'] = 'vl' + df3['d'] = df3['d'].astype(int) + print(df3) + for ind in df3.index: + # print(df3['login'][ind]) +# + GeneralVacation.objects.create(login=df3['login'][ind], planned_date=df3['c'][ind], count_days=df3['d'][ind], type_of_vacation=df3['e'][ind], start_work_period=df3['f'][ind]) + # DailyRoundUp.objects.update_or_create(todaysDate=datetime.strptime(datas, '%d.%m.%Y').strftime('%Y-%m-%d'), + # user=df3['login'][ind], defaults={'position':base}) + + \ No newline at end of file diff --git a/src/general_vacation/models.py b/src/general_vacation/models.py index 05a1bc992..84fe3363f 100644 --- a/src/general_vacation/models.py +++ b/src/general_vacation/models.py @@ -36,7 +36,7 @@ class GeneralVacation(models.Model): count_days = models.IntegerField(verbose_name='Кол-во дней', default=0, blank=True) type_of_vacation = models.CharField(max_length=300, choices = CHOICES, verbose_name='Тип отпуска') start_work_period = models.DateField(verbose_name='Начало рабочего периода') - end_work_period = models.DateField(verbose_name='Конец рабочего периода') + # end_work_period = models.DateField(verbose_name='Конец рабочего периода') class Meta: verbose_name = "График отпусков" diff --git a/src/general_vacation/views.py b/src/general_vacation/views.py index 711b3a754..264e61250 100644 --- a/src/general_vacation/views.py +++ b/src/general_vacation/views.py @@ -1,5 +1,5 @@ from datetime import datetime -from .excel import roundExcel +from .excel import roundExcel, loadExcel import os from django.forms import model_to_dict from openpyxl import load_workbook @@ -46,7 +46,6 @@ class DailyRoundUpAPIView(APIView): if request.GET.get("excel") == 'round': file_path = re.excround() if request.GET.get("excel") == 'vacation': - file_path = re.excelvacation() @@ -61,61 +60,19 @@ class DailyRoundUpAPIView(APIView): def post(self, request): - user = DictEmployee.objects.using('user_directory').filter(deleted=0).values('login', 'id') - dfuser = pd.DataFrame.from_records(user) + user = DictEmployee.objects.using('user_directory').filter(deleted=0).values('login', 'id', 'fio') + re = loadExcel(user, request.data['dailyfiles']) try: if request.GET.get("excel") == 'round': - file = request.data['dailyfiles'] - ed = pd.read_excel(file) - df = pd.DataFrame(ed) - - datas = df.columns[8].split(" ")[1] - - df.columns = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"] - df=df.iloc[6:] - df= df[df.b.notna()] - df= df[df.a.notna()] - df['b']=df['b'].str[-3:] - df=df[['b', 'f', 'h', 'j','l']] - - df['b'] = df['b'].astype(int) - - types = ['f', 'h', 'j','l'] - for n in types: - df[n] = df[n].fillna(0) - df[n] = df[n].astype(int) - - df3 = pd.merge(df, dfuser, left_on= 'b', right_on="id") - df3=df3[['login', 'f', 'h', 'j','l']] - - - - for ind in df3.index: - - keys = '' - if df3['h'][ind] == 1: - keys = 4 # В отпуске - elif df3['j'][ind] == 1: - keys = 5 # Болен - elif df3['l'][ind] == 1: - keys = 2 # Удаленка - elif df3['f'][ind] == 1: - keys = 1 # На работе - else: - keys = 6 - base=BasePosition.objects.get(pk=keys) - DailyRoundUp.objects.update_or_create(todaysDate=datetime.strptime(datas, '%d.%m.%Y').strftime('%Y-%m-%d'), - user=df3['login'][ind], defaults={'position':base}) - - pos = DailyRoundUp.objects.values('position__name', 'position').filter(position=6,todaysDate=date.today()).annotate(Count('user')) - - - + + re.roundfilse() mess = "Файл загружен" if request.GET.get("excel") == 'vacation': + re.vacationsExcel() print(request.data['dailyfiles'], 'request.data[dailyfiles]--------------------') - + mess = 'Файл в обраотке' + pos='' except Exception as e: pos='' mess = 'Файл не найден' diff --git a/src/userauth/models.py b/src/userauth/models.py index e67f05953..2fb8fb2b8 100644 --- a/src/userauth/models.py +++ b/src/userauth/models.py @@ -173,6 +173,7 @@ class DictPosition(models.Model): + class MatrixCompetences(models.Model): id_dict_employee = models.ForeignKey(DictEmployee, models.DO_NOTHING, db_column='id_dict_employee', db_comment='шфхэЄшЇшърЄюЁ ёюЄЁєфэшър') id_dict_competences = models.ForeignKey(DictCompetences, models.DO_NOTHING, db_column='id_dict_competences', db_comment='шфхэЄшЇшърЄюЁ ъюьяхЄхэЎшш')