diff --git a/src/db.sqlite3 b/src/db.sqlite3 index 4ed992402..5bb61f348 100644 Binary files a/src/db.sqlite3 and b/src/db.sqlite3 differ diff --git a/src/front/package-lock.json b/src/front/package-lock.json index ae640b005..3d23835b6 100644 --- a/src/front/package-lock.json +++ b/src/front/package-lock.json @@ -1,12 +1,12 @@ { "name": "front", - "version": "0.0.26", + "version": "0.0.27", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "front", - "version": "0.0.26", + "version": "0.0.27", "dependencies": { "@fullcalendar/core": "^6.1.8", "@fullcalendar/daygrid": "^6.1.8", diff --git a/src/front/package.json b/src/front/package.json index 44940e8a7..c9a8d9957 100644 --- a/src/front/package.json +++ b/src/front/package.json @@ -1,6 +1,6 @@ { "name": "front", - "version": "0.0.26", + "version": "0.0.27", "scripts": { "dev": "vite", "build": "vite build", diff --git a/src/front/src/components/digital-letna.vue b/src/front/src/components/digital-letna.vue index 124fd7335..6f5b0b597 100644 --- a/src/front/src/components/digital-letna.vue +++ b/src/front/src/components/digital-letna.vue @@ -43,12 +43,12 @@ v-else class="h-100 w-100 d-flex justify-center flex-column" > - + > --> - + diff --git a/src/general_vacation/admin.py b/src/general_vacation/admin.py index 3196d10b9..7437e8b6a 100644 --- a/src/general_vacation/admin.py +++ b/src/general_vacation/admin.py @@ -1,20 +1,20 @@ from django.contrib import admin from .models import * -class GeneralVacationAdmin(admin.ModelAdmin): - fields = ('user', 'planned_date', 'count_days', 'type_of_vacation', 'start_work_period', 'end_work_period') - list_display=('get_name', 'user', 'planned_date', 'count_days', 'type_of_vacation', 'start_work_period', 'end_work_period') - readonly_fields=('get_name',) - def get_name(self, obj): +# class GeneralVacationAdmin(admin.ModelAdmin): +# fields = ('login', 'planned_date', 'count_days', 'type_of_vacation', 'start_work_period', 'end_work_period') +# list_display=('get_name', 'login', 'planned_date', 'count_days', 'type_of_vacation', 'start_work_period', 'end_work_period') +# readonly_fields=('get_name',) +# def get_name(self, obj): - return obj.user.fio() +# return obj.user.fio() class PlanCalendarAdmin(admin.ModelAdmin): list_display = ('name', 'start_work_period', 'end_work_period') list_filter = ('start_work_period', 'end_work_period') fields = ('name', 'start_work_period', 'end_work_period') -admin.site.register(GeneralVacation, GeneralVacationAdmin), +# admin.site.register(GeneralVacation, GeneralVacationAdmin), admin.site.register(PlanCalendar, PlanCalendarAdmin) admin.site.register(BasePosition) admin.site.register(DailyRoundUp) \ No newline at end of file diff --git a/src/general_vacation/excel.py b/src/general_vacation/excel.py new file mode 100644 index 000000000..a0de38346 --- /dev/null +++ b/src/general_vacation/excel.py @@ -0,0 +1,219 @@ +import pandas as pd +from pandas.io.excel import ExcelWriter +import openpyxl as oxl +from openpyxl import Workbook +from openpyxl.styles import Font, Alignment, Side, Border, PatternFill +from openpyxl.worksheet.formula import ArrayFormula +from pandas.api.types import CategoricalDtype +import urllib.request +from datetime import date + +class roundExcel(): + def __init__(self, us): + self.df = pd.DataFrame.from_records(us) + self.wb = Workbook() + pass + + def excround(self): + + self.df['tabel'] = self.df['login'].str.split('-', expand = True)[1]+self.df['login'].str.split('-', expand = True)[2] + file_path = 'media/DailyRoundUp.xlsx' + thins = Side(border_style="thin") + + ws = self.wb.active + filters = ws.auto_filter + filters.ref = "A6:L15" + ws.title = "Список" + ws['B2'] = 'Список сотрудников' + ws['B3'] = 'МИ ФНС России по ЦОД № 2' + ws['B4'] = 'по подразделениям' + + ws['B6'] = 'Таб.' + ws['C6'] = 'Фамилия' + ws['D6'] = 'Имя' + ws['E6'] = 'Очество' + + for col in ws.iter_cols(min_row=6, max_row=6, min_col=2, max_col=5): + for cell in col: + cell.font = Font(name='Times New Roman', size=11, bold=True) + cell.border = Border(top=thins, bottom=thins, left=thins, right=thins) + + ws['G6'] = 'Отпуск' + ws['I6'] = 'Болен' + ws['K6'] = 'Удаленка' + + + + + heads =['G6', 'I6', 'K6'] + for x in heads: + + ws[x].fill = PatternFill(fgColor="00FFFF00", fill_type = "solid") + ws[x].font = Font(name='Times New Roman', size=10, bold=True) + ws[x].border = Border(top=thins, bottom=thins, left=thins, right=thins) + ws[x].alignment = Alignment(horizontal='center') + + + ws['I1'] = 'На '+ date.today().strftime("%d.%m.%Y") + + numb = 1 + + column_widths = [29, 53, 96, 96, 112, 28, 222, 29, 148, 28, 145, 33] + for i, width in enumerate(column_widths): + column_letter = oxl.utils.get_column_letter(i+1) + ws.column_dimensions[column_letter].width = self.convert_width(width) + + + + for col in ws.iter_cols(min_row=2, max_row=5, min_col=2, max_col=5): + for cell in col: + cell.font = Font(name='Times New Roman', size=12, bold=True) + cell.alignment = Alignment(horizontal='center') + + ws['I1'].font = Font(name='Times New Roman', size=14, bold=True) + ws['I1'].alignment = Alignment(horizontal='left') + + + for x in range(3): + ws.merge_cells(start_row=2+x, start_column=2, end_row=2+x, end_column=6) + + + k=7 + + + for i in sorted(self.df['department'].unique(), reverse=True): + + ws.cell(row = k, column = 2).value = i + + ws.cell(row = k, column = 2).font = Font(name='Times New Roman', size=10, bold=True) + ws.merge_cells(start_row=k, start_column=2, end_row=k, end_column=12) + + l = pd.DataFrame(self.df[(self.df.department==i)][['tabel', 'familyname', 'name', 'parentname']]) + + zap = [7, 9, 11] + for x in range(len(l)): + k=k+1 + + ws.cell(row = k, column = 1).value = numb + ws.cell(row = k, column = 1).font = Font(name='Times New Roman', size=10, bold=True) + + ws.cell(row = k, column = 2).value = l.iloc[x]['tabel'] + ws.cell(row = k, column = 3).value = l.iloc[x]['familyname'] + ws.cell(row = k, column = 4).value = l.iloc[x]['name'] + ws.cell(row = k, column = 5).value = l.iloc[x]['parentname'] + + for h in zap: + ws.cell(row = k, column = h).border = Border(top=thins, bottom=thins, left=thins, right=thins) + ws.cell(row = k, column = h).font = Font(name='Times New Roman', size=10) + ws.cell(row = k, column = h).alignment = Alignment(horizontal='center') + + + for v in range(4): + ws.cell(row = k, column = 2+v).font = Font(name='Times New Roman', size=10) + ws.cell(row = k, column = 2+v).border = Border(top=thins, bottom=thins, left=thins, right=thins) + + + numb=numb+1 + + k=k+1 + + ws.cell(row = k+1, column=6).value = "=SUM(F6:F"+str(k-1)+")" + ws.cell(row = k+1, column=6).fill = PatternFill(fgColor="00FFFF00", fill_type = "solid") + ws.cell(row = k+1, column=6).font = Font(name='Times New Roman', size=13, bold=True) + + ws.cell(row = k+1, column=7).value = "ВСЕГО отпуск=" + ws.cell(row = k+1, column=7).fill = PatternFill(fgColor="00FFFF00", fill_type = "solid") + ws.cell(row = k+1, column=7).font = Font(name='Times New Roman', size=10, bold=True) + + ws.cell(row = k+1, column=8).value = "=SUM(H6:H"+str(k-1)+")" + ws.cell(row = k+1, column=8).fill = PatternFill(fgColor="00FFFF00", fill_type = "solid") + ws.cell(row = k+1, column=8).font = Font(name='Times New Roman', size=10, bold=True) + + ws.cell(row = k+1, column=9).value = "Всего больных=" + ws.cell(row = k+1, column=9).fill = PatternFill(fgColor="8EA9DB", fill_type = "solid") + ws.cell(row = k+1, column=9).font = Font(name='Times New Roman', size=10, bold=True) + + ws.cell(row = k+1, column=10).value = "=SUM(J6:J"+str(k-1)+")" + ws.cell(row = k+1, column=10).fill = PatternFill(fgColor="8EA9DB", fill_type = "solid") + ws.cell(row = k+1, column=10).font = Font(name='Times New Roman', size=10, bold=True) + + ws.cell(row = k+1, column=11).value = "Всего удаленка=" + ws.cell(row = k+1, column=11).fill = PatternFill(fgColor="8EA9DB", fill_type = "solid") + ws.cell(row = k+1, column=11).font = Font(name='Times New Roman', size=10, bold=True) + + ws.cell(row = k+1, column=12).value = "=SUM(L6:L"+str(k-1)+")" + ws.cell(row = k+1, column=12).fill = PatternFill(fgColor="8EA9DB", fill_type = "solid") + ws.cell(row = k+1, column=12).font = Font(name='Times New Roman', size=10, bold=True) + + ws.cell(row = k+3, column=5).value = "ИТОГО" + ws.cell(row = k+3, column=5).font = Font(name='Times New Roman', size=14, bold=True) + + ws.cell(row = k+3, column=7).value = "факт работающих" + ws.cell(row = k+3, column=7).font = Font(name='Times New Roman', size=14, bold=True) + + + ws.cell(row = k+3, column=8).value = f"=F{k+1}-H{k+1}-J{k+1}-L{k+1}" + ws.cell(row = k+3, column=8).font = Font(name='Times New Roman', size=14, bold=True) + + + + self.wb.save(file_path) + return file_path + + def convert_width(self, width): + """ + Конвертируем ширину столбца Excel в ширину столбца openpyxl + """ + PIXELS_PER_CHAR = 7 + return (width) / PIXELS_PER_CHAR + + # def excroundread(self): + # 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')) + + + + # mess = "Файл загружен" + + diff --git a/src/general_vacation/models.py b/src/general_vacation/models.py index 7eb889244..05a1bc992 100644 --- a/src/general_vacation/models.py +++ b/src/general_vacation/models.py @@ -30,7 +30,8 @@ class GeneralVacation(models.Model): ('nd', 'Доп н/д'), ('vl', 'Доп в/л'), ) - user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.PROTECT, verbose_name='Сотрудник') + + login = models.CharField(max_length=100, blank=True, null=True, verbose_name='Логин') planned_date = models.DateField(verbose_name='Запланированная дата') count_days = models.IntegerField(verbose_name='Кол-во дней', default=0, blank=True) type_of_vacation = models.CharField(max_length=300, choices = CHOICES, verbose_name='Тип отпуска') @@ -42,10 +43,10 @@ class GeneralVacation(models.Model): verbose_name_plural = "График отпусков" def __str__(self): - return str(self.user) + return str(self.login) - def department(self): - return DictEmployee.objects.using('user_directory').get(login=self.username).department + # def department(self): + # return DictEmployee.objects.using('user_directory').get(login=self.username).department class PlanCalendar(models.Model): name = models.CharField(verbose_name='Название', max_length=500, blank=True, db_index=True) @@ -58,3 +59,8 @@ class PlanCalendar(models.Model): def __str__(self): return str(self.name) + + + + + diff --git a/src/general_vacation/serializers.py b/src/general_vacation/serializers.py index 374f14287..aaa6a5a1a 100644 --- a/src/general_vacation/serializers.py +++ b/src/general_vacation/serializers.py @@ -1,11 +1,11 @@ from rest_framework import serializers from .models import * -class GeneralVacationSerializer(serializers.ModelSerializer): +# class GeneralVacationSerializer(serializers.ModelSerializer): - class Meta: - model = GeneralVacation - fields ='__all__' +# class Meta: +# model = GeneralVacation +# fields ='__all__' class PlanCalendarSerializer(serializers.ModelSerializer): diff --git a/src/general_vacation/views.py b/src/general_vacation/views.py index 7c0d99393..1d50530d6 100644 --- a/src/general_vacation/views.py +++ b/src/general_vacation/views.py @@ -1,4 +1,5 @@ from datetime import datetime +from .excel import roundExcel import os from django.forms import model_to_dict from openpyxl import load_workbook @@ -39,168 +40,15 @@ class GeneralVacationAPIView(APIView): class DailyRoundUpAPIView(APIView): - def convert_width(self, width): - """ - Конвертируем ширину столбца Excel в ширину столбца openpyxl - """ - PIXELS_PER_CHAR = 7 - return (width) / PIXELS_PER_CHAR + def get(self, request): user = DictEmployee.objects.using('user_directory').filter(deleted=0).values('login', 'department', 'familyname', 'name', 'parentname') - df = pd.DataFrame.from_records(user) - df['tabel'] = df['login'].str.split('-', expand = True)[1]+df['login'].str.split('-', expand = True)[2] - file_path = 'media/DailyRoundUp.xlsx' - - thins = Side(border_style="thin") - # l = pd.DataFrame(df[(df.department=='Руководство')][['tabel', 'familyname', 'name', 'parentname']]) - # l.to_excel(file_path, sheet_name="Список", index= False, header= False, startcol=2, startrow=8) - wb = Workbook() - ws = wb.active - filters = ws.auto_filter - filters.ref = "A6:L15" - ws.title = "Список" - ws['B2'] = 'Список сотрудников' - ws['B3'] = 'МИ ФНС России по ЦОД № 2' - ws['B4'] = 'по подразделениям' - - ws['B6'] = 'Таб.' - ws['C6'] = 'Фамилия' - ws['D6'] = 'Имя' - ws['E6'] = 'Очество' - - for col in ws.iter_cols(min_row=6, max_row=6, min_col=2, max_col=5): - for cell in col: - cell.font = Font(name='Times New Roman', size=11, bold=True) - cell.border = Border(top=thins, bottom=thins, left=thins, right=thins) - - ws['G6'] = 'Отпуск' - ws['I6'] = 'Болен' - ws['K6'] = 'Удаленка' - - # ws['F99']= ArrayFormula("A1:A90", "=SUM(C2:C11*D2:D11)") - - - - heads =['G6', 'I6', 'K6'] - for x in heads: - - ws[x].fill = PatternFill(fgColor="00FFFF00", fill_type = "solid") - ws[x].font = Font(name='Times New Roman', size=10, bold=True) - ws[x].border = Border(top=thins, bottom=thins, left=thins, right=thins) - ws[x].alignment = Alignment(horizontal='center') - # for col in ws.iter_cols(min_row=6, max_row=6, min_col=2, max_col=5): - # for cell in col: - # cell.font = Font(name='Times New Roman', size=11, bold=True) - # cell.border = Border(top=thins, bottom=thins, left=thins, right=thins) - - - ws['I1'] = 'На '+ date.today().strftime("%d.%m.%Y") - - numb = 1 - - column_widths = [29, 53, 96, 96, 112, 28, 222, 29, 148, 28, 145, 33] - for i, width in enumerate(column_widths): - column_letter = openpyxl.utils.get_column_letter(i+1) - ws.column_dimensions[column_letter].width = self.convert_width(width) - - - - for col in ws.iter_cols(min_row=2, max_row=5, min_col=2, max_col=5): - for cell in col: - cell.font = Font(name='Times New Roman', size=12, bold=True) - cell.alignment = Alignment(horizontal='center') - - ws['I1'].font = Font(name='Times New Roman', size=14, bold=True) - ws['I1'].alignment = Alignment(horizontal='left') - - - for x in range(3): - ws.merge_cells(start_row=2+x, start_column=2, end_row=2+x, end_column=6) - - - k=7 - - - for i in sorted(df['department'].unique(), reverse=True): - - ws.cell(row = k, column = 2).value = i - - ws.cell(row = k, column = 2).font = Font(name='Times New Roman', size=10, bold=True) - ws.merge_cells(start_row=k, start_column=2, end_row=k, end_column=12) - - l = pd.DataFrame(df[(df.department==i)][['tabel', 'familyname', 'name', 'parentname']]) - - zap = [7, 9, 11] - for x in range(len(l)): - k=k+1 - - ws.cell(row = k, column = 1).value = numb - ws.cell(row = k, column = 1).font = Font(name='Times New Roman', size=10, bold=True) - - ws.cell(row = k, column = 2).value = l.iloc[x]['tabel'] - ws.cell(row = k, column = 3).value = l.iloc[x]['familyname'] - ws.cell(row = k, column = 4).value = l.iloc[x]['name'] - ws.cell(row = k, column = 5).value = l.iloc[x]['parentname'] - - for h in zap: - ws.cell(row = k, column = h).border = Border(top=thins, bottom=thins, left=thins, right=thins) - ws.cell(row = k, column = h).font = Font(name='Times New Roman', size=10) - ws.cell(row = k, column = h).alignment = Alignment(horizontal='center') - - - for v in range(4): - ws.cell(row = k, column = 2+v).font = Font(name='Times New Roman', size=10) - ws.cell(row = k, column = 2+v).border = Border(top=thins, bottom=thins, left=thins, right=thins) - - - numb=numb+1 - - k=k+1 - - ws.cell(row = k+1, column=6).value = "=SUM(F6:F"+str(k-1)+")" - ws.cell(row = k+1, column=6).fill = PatternFill(fgColor="00FFFF00", fill_type = "solid") - ws.cell(row = k+1, column=6).font = Font(name='Times New Roman', size=13, bold=True) - - ws.cell(row = k+1, column=7).value = "ВСЕГО отпуск=" - ws.cell(row = k+1, column=7).fill = PatternFill(fgColor="00FFFF00", fill_type = "solid") - ws.cell(row = k+1, column=7).font = Font(name='Times New Roman', size=10, bold=True) - - ws.cell(row = k+1, column=8).value = "=SUM(H6:H"+str(k-1)+")" - ws.cell(row = k+1, column=8).fill = PatternFill(fgColor="00FFFF00", fill_type = "solid") - ws.cell(row = k+1, column=8).font = Font(name='Times New Roman', size=10, bold=True) - - ws.cell(row = k+1, column=9).value = "Всего больных=" - ws.cell(row = k+1, column=9).fill = PatternFill(fgColor="8EA9DB", fill_type = "solid") - ws.cell(row = k+1, column=9).font = Font(name='Times New Roman', size=10, bold=True) - - ws.cell(row = k+1, column=10).value = "=SUM(J6:J"+str(k-1)+")" - ws.cell(row = k+1, column=10).fill = PatternFill(fgColor="8EA9DB", fill_type = "solid") - ws.cell(row = k+1, column=10).font = Font(name='Times New Roman', size=10, bold=True) - - ws.cell(row = k+1, column=11).value = "Всего удаленка=" - ws.cell(row = k+1, column=11).fill = PatternFill(fgColor="8EA9DB", fill_type = "solid") - ws.cell(row = k+1, column=11).font = Font(name='Times New Roman', size=10, bold=True) - - ws.cell(row = k+1, column=12).value = "=SUM(L6:L"+str(k-1)+")" - ws.cell(row = k+1, column=12).fill = PatternFill(fgColor="8EA9DB", fill_type = "solid") - ws.cell(row = k+1, column=12).font = Font(name='Times New Roman', size=10, bold=True) - - ws.cell(row = k+3, column=5).value = "ИТОГО" - ws.cell(row = k+3, column=5).font = Font(name='Times New Roman', size=14, bold=True) - - ws.cell(row = k+3, column=7).value = "факт работающих" - ws.cell(row = k+3, column=7).font = Font(name='Times New Roman', size=14, bold=True) - - - ws.cell(row = k+3, column=8).value = f"=F{k+1}-H{k+1}-J{k+1}-L{k+1}" - ws.cell(row = k+3, column=8).font = Font(name='Times New Roman', size=14, bold=True) - - - - wb.save(file_path) + re = roundExcel(user) + file_path = re.excround() + @@ -211,7 +59,7 @@ class DailyRoundUpAPIView(APIView): def post(self, request): - # DictCommitteeExpert.objects.using('user_directory').update(fio='kfkf', tel='03') + user = DictEmployee.objects.using('user_directory').filter(deleted=0).values('login', 'id') dfuser = pd.DataFrame.from_records(user) @@ -225,8 +73,6 @@ class DailyRoundUpAPIView(APIView): datas = df.columns[8].split(" ")[1] - - # DailyRoundUp.objects.update_or_create(todaysDate=datetime.datetime.strptime(datas, '%d.%m.%Y').strftime('%Y-%m-%d'), defaults={'user':self.request.user, 'position':base}) df.columns = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l"] df=df.iloc[6:] df= df[df.b.notna()] @@ -244,9 +90,10 @@ class DailyRoundUpAPIView(APIView): df3 = pd.merge(df, dfuser, left_on= 'b', right_on="id") df3=df3[['login', 'f', 'h', 'j','l']] - + for ind in df3.index: + print(df3['h'][ind], 'df3-----------------------------------') keys = '' if df3['h'][ind] == 1: keys = 4 # В отпуске @@ -269,15 +116,12 @@ class DailyRoundUpAPIView(APIView): mess = "Файл загружен" except Exception as e: - print(e, '--------jjjjjjjjjjjjjjjjjj------------------------------') + print(e, '1111111111111111111111') pos='' mess = 'Файл не найден' - # serializer_for_daily = DailyRoundUpSerializer( - # instance=daily, # Передаём набор записей - # many=True # Указываем, что на вход подаётся именно набор записей - # ) + diff --git a/src/media/DailyRoundUp.xlsx b/src/media/DailyRoundUp.xlsx index 4ddbaf869..2b4a94c1f 100644 Binary files a/src/media/DailyRoundUp.xlsx and b/src/media/DailyRoundUp.xlsx differ