272 lines
12 KiB
Python
272 lines
12 KiB
Python
from django.http import JsonResponse
|
||
from django.shortcuts import render
|
||
from django.urls import reverse
|
||
|
||
from application.pjt_mgnt.models import *
|
||
from common.utils.page_helper import paginate_query_and_assign_numbers
|
||
|
||
|
||
def proj_ledger_list_view(request):
|
||
# 声明查询集
|
||
query_set = ProjectLedger.objects.filter().order_by('-project_id')
|
||
|
||
# 获取查询参数
|
||
project_name = request.GET.get('project_name', '')
|
||
customer_name = request.GET.get('customer_name', '')
|
||
|
||
# 根据提供的参数进行筛选
|
||
if project_name:
|
||
query_set = query_set.filter(project_name__icontains=project_name)
|
||
if customer_name:
|
||
query_set = query_set.filter(customer_name__icontains=customer_name)
|
||
|
||
# 对查询结果进行分页,每页10条记录
|
||
items = paginate_query_and_assign_numbers(
|
||
request=request,
|
||
queryset=query_set,
|
||
per_page=10
|
||
)
|
||
|
||
# 构建上下文查询参数字符串
|
||
query_params = '&project_name={}&customer_name={}'.format(project_name, customer_name)
|
||
|
||
# Excel上传模板
|
||
template_name = "项目管理-项目台账-Excel上传模板.xlsx"
|
||
|
||
# 构建上下文
|
||
context = {
|
||
"model_config": 'pjt_mgnt.ProjectLedger',
|
||
"items": items,
|
||
"breadcrumb_list": [
|
||
{"title": "首页", "name": "index"},
|
||
{"title": "项目管理", "name": "index"},
|
||
{"title": "项目台账", "name": "proj_ledger_list"}
|
||
],
|
||
"filters": [
|
||
{"type": "text", "id": "project_name", "name": "project_name", "label": "项目名称",
|
||
"placeholder": "请输入项目名称"},
|
||
{"type": "text", "id": "customer_name", "name": "customer_name", "label": "客户名称",
|
||
"placeholder": "请输入客户名称"}
|
||
],
|
||
"excel_upload_config": {
|
||
"template_url": reverse("download_template", kwargs={'template_name': template_name}),
|
||
"parse_url": reverse("common_excel_parse"),
|
||
"save_url": reverse("save_excel_table_data"),
|
||
"fields_preview_config": {
|
||
"project_id": {"type": "text", "width": "180px"},
|
||
"project_name": {"type": "text", "width": "180px"},
|
||
"start_date": {"type": "date", "width": "180px"},
|
||
"end_date": {"type": "date", "width": "180px"},
|
||
"primary_department": {"type": "text", "width": "180px"},
|
||
"customer_name": {"type": "text", "width": "180px"},
|
||
"province": {"type": "text", "width": "180px"},
|
||
"city": {"type": "text", "width": "180px"},
|
||
"district": {"type": "text", "width": "180px"},
|
||
"project_leader": {"type": "text", "width": "180px"},
|
||
"project_members": {"type": "text", "width": "180px"},
|
||
"project_status": {"type": "select", "options": ['进行中', '暂停', '待收款', '完成'], "width": "180px"},
|
||
"resource_type": {"type": "select", "options": ['公司', '个人'], "width": "180px"},
|
||
"project_nature": {"type": "select", "options": ['新增', '存量', '新增及存量', '老客户新业务'],
|
||
"width": "180px"},
|
||
"project_progress": {"type": "text", "width": "180px"},
|
||
"contract_date": {"type": "date", "width": "180px"},
|
||
"contract_amount": {"type": "number", "width": "180px"},
|
||
"contract_rate": {"type": "number", "width": "180px"},
|
||
"revenue": {"type": "number", "width": "180px"},
|
||
"cost_rate": {"type": "number", "width": "180px"},
|
||
"cost": {"type": "number", "width": "180px"},
|
||
"net_income": {"type": "number", "width": "180px"},
|
||
"total_amount_including_tax": {"type": "number", "width": "180px"},
|
||
"repayment_amount": {"type": "number", "width": "180px"},
|
||
"receivable_net_income": {"type": "number", "width": "180px"},
|
||
"actual_net_income": {"type": "number", "width": "180px"},
|
||
"outstanding_net_income": {"type": "number", "width": "180px"},
|
||
"notes": {"type": "text", "width": "180px"},
|
||
"actions": {"type": "actions", "width": "100px"}
|
||
}
|
||
},
|
||
"query_params": query_params,
|
||
"form_action_url": 'proj_ledger_list',
|
||
"modify_url": reverse("proj_ledger_list_modify"),
|
||
"add_url": reverse("proj_ledger_list_add"),
|
||
"delete_url": reverse("proj_ledger_list_delete"),
|
||
}
|
||
|
||
return render(request, '../templates/list.html', context)
|
||
|
||
|
||
def proj_ledger_list_add(request):
|
||
if request.method == 'POST':
|
||
data = {
|
||
'project_name': request.POST.get('project_name'),
|
||
'start_date': request.POST.get('start_date'),
|
||
'end_date': request.POST.get('end_date'),
|
||
'primary_department': request.POST.get('primary_department'),
|
||
'customer_name': request.POST.get('customer_name'),
|
||
'province': request.POST.get('province'),
|
||
'city': request.POST.get('city'),
|
||
'district': request.POST.get('district'),
|
||
'project_leader': request.POST.get('project_leader'),
|
||
'project_members': request.POST.get('project_members'),
|
||
'project_status': request.POST.get('project_status'),
|
||
'resource_type': request.POST.get('resource_type'),
|
||
'project_nature': request.POST.get('project_nature'),
|
||
'project_progress': request.POST.get('project_progress'),
|
||
'contract_date': request.POST.get('contract_date'),
|
||
'contract_amount': request.POST.get('contract_amount'),
|
||
'contract_rate': request.POST.get('contract_rate'),
|
||
'revenue': request.POST.get('revenue'),
|
||
'cost_rate': request.POST.get('cost_rate'),
|
||
'cost': request.POST.get('cost'),
|
||
'net_income': request.POST.get('net_income'),
|
||
'total_amount_including_tax': request.POST.get('total_amount_including_tax'),
|
||
'repayment_amount': request.POST.get('repayment_amount'),
|
||
'receivable_net_income': request.POST.get('receivable_net_income'),
|
||
'actual_net_income': request.POST.get('actual_net_income'),
|
||
'outstanding_net_income': request.POST.get('outstanding_net_income'),
|
||
'notes': request.POST.get('notes')
|
||
}
|
||
ProjectLedger.objects.create(**data)
|
||
return JsonResponse({"message": "添加成功"})
|
||
return JsonResponse({"message": "无效的请求方法"}, status=405)
|
||
|
||
|
||
def proj_ledger_list_modify(request):
|
||
if request.method == 'POST':
|
||
project_id = request.POST.get('project_id')
|
||
data = {
|
||
'project_name': request.POST.get('project_name'),
|
||
'start_date': request.POST.get('start_date'),
|
||
'end_date': request.POST.get('end_date'),
|
||
'primary_department': request.POST.get('primary_department'),
|
||
'customer_name': request.POST.get('customer_name'),
|
||
'province': request.POST.get('province'),
|
||
'city': request.POST.get('city'),
|
||
'district': request.POST.get('district'),
|
||
'project_leader': request.POST.get('project_leader'),
|
||
'project_members': request.POST.get('project_members'),
|
||
'project_status': request.POST.get('project_status'),
|
||
'resource_type': request.POST.get('resource_type'),
|
||
'project_nature': request.POST.get('project_nature'),
|
||
'project_progress': request.POST.get('project_progress'),
|
||
'contract_date': request.POST.get('contract_date'),
|
||
'contract_amount': request.POST.get('contract_amount'),
|
||
'contract_rate': request.POST.get('contract_rate'),
|
||
'revenue': request.POST.get('revenue'),
|
||
'cost_rate': request.POST.get('cost_rate'),
|
||
'cost': request.POST.get('cost'),
|
||
'net_income': request.POST.get('net_income'),
|
||
'total_amount_including_tax': request.POST.get('total_amount_including_tax'),
|
||
'repayment_amount': request.POST.get('repayment_amount'),
|
||
'receivable_net_income': request.POST.get('receivable_net_income'),
|
||
'actual_net_income': request.POST.get('actual_net_income'),
|
||
'outstanding_net_income': request.POST.get('outstanding_net_income'),
|
||
'notes': request.POST.get('notes')
|
||
}
|
||
|
||
ProjectLedger.objects.filter(project_id=project_id).update(**data)
|
||
return JsonResponse({"message": "修改成功"})
|
||
return JsonResponse({"message": "无效的请求方法"}, status=405)
|
||
|
||
|
||
def proj_ledger_list_delete(request):
|
||
if request.method == 'GET':
|
||
project_id = request.GET.get('project_id')
|
||
ProjectLedger.objects.filter(project_id=project_id).delete()
|
||
return JsonResponse({"message": "删除成功"})
|
||
return JsonResponse({"message": "无效的请求方法"}, status=405)
|
||
|
||
|
||
def emp_proj_income_list_view(request):
|
||
# 声明查询集
|
||
query_set = EmployeeProjectIncomeSettlement.objects.filter().order_by('-record_id')
|
||
|
||
# 获取查询参数
|
||
project_name = request.GET.get('project_name', '')
|
||
year_month = request.GET.get('year_month', '')
|
||
|
||
# 根据提供的参数进行筛选
|
||
if project_name:
|
||
query_set = query_set.filter(project_name__project_name__icontains=project_name)
|
||
if year_month:
|
||
query_set = query_set.filter(year_month__icontains=year_month)
|
||
|
||
# 对查询结果进行分页,每页10条记录
|
||
items = paginate_query_and_assign_numbers(
|
||
request=request,
|
||
queryset=query_set,
|
||
per_page=10
|
||
)
|
||
|
||
# 构建上下文查询参数字符串
|
||
query_params = '&project_name={}&year_month={}'.format(project_name, year_month)
|
||
|
||
# Excel上传模板
|
||
template_name = "项目管理-项目组员收入结算表-Excel上传模板.xlsx"
|
||
|
||
# 构建上下文
|
||
context = {
|
||
"model_config": 'pjt_mgnt.EmployeeProjectIncomeSettlement',
|
||
"items": items,
|
||
"breadcrumb_list": [
|
||
{"title": "首页", "name": "index"},
|
||
{"title": "项目管理", "name": "index"},
|
||
{"title": "项目组员收入结算表", "name": "emp_proj_income_list"}
|
||
],
|
||
"filters": [
|
||
{"type": "text", "id": "project_name", "name": "project_name", "label": "项目名称",
|
||
"placeholder": "请输入项目名称"},
|
||
{"type": "text", "id": "year_month", "name": "year_month", "label": "年月", "placeholder": "请输入年月"}
|
||
],
|
||
"excel_upload_config": {
|
||
"template_url": reverse("download_template", kwargs={'template_name': template_name}),
|
||
"parse_url": reverse("common_excel_parse"),
|
||
"save_url": reverse("save_excel_table_data"),
|
||
"fields_preview_config": {
|
||
"record_id": {"type": "text", "width": "180px"},
|
||
"project_name": {"type": "text", "width": "180px"},
|
||
"year_month": {"type": "text", "width": "180px"},
|
||
"actions": {"type": "actions", "width": "100px"}
|
||
}
|
||
},
|
||
"query_params": query_params,
|
||
"form_action_url": 'emp_proj_income_list',
|
||
"modify_url": reverse("emp_proj_income_list_modify"),
|
||
"add_url": reverse("emp_proj_income_list_add"),
|
||
"delete_url": reverse("emp_proj_income_list_delete"),
|
||
}
|
||
|
||
return render(request, '../templates/list.html', context)
|
||
|
||
|
||
def emp_proj_income_list_add(request):
|
||
if request.method == 'POST':
|
||
data = {
|
||
'project_name_id': request.POST.get('project_name'),
|
||
'year_month': request.POST.get('year_month')
|
||
}
|
||
EmployeeProjectIncomeSettlement.objects.create(**data)
|
||
return JsonResponse({"message": "添加成功"})
|
||
return JsonResponse({"message": "无效的请求方法"}, status=405)
|
||
|
||
|
||
def emp_proj_income_list_modify(request):
|
||
if request.method == 'POST':
|
||
record_id = request.POST.get('record_id')
|
||
data = {
|
||
'project_name_id': request.POST.get('project_name'),
|
||
'year_month': request.POST.get('year_month')
|
||
}
|
||
|
||
EmployeeProjectIncomeSettlement.objects.filter(record_id=record_id).update(**data)
|
||
return JsonResponse({"message": "修改成功"})
|
||
return JsonResponse({"message": "无效的请求方法"}, status=405)
|
||
|
||
|
||
def emp_proj_income_list_delete(request):
|
||
if request.method == 'GET':
|
||
record_id = request.GET.get('record_id')
|
||
EmployeeProjectIncomeSettlement.objects.filter(record_id=record_id).delete()
|
||
return JsonResponse({"message": "删除成功"})
|
||
return JsonResponse({"message": "无效的请求方法"}, status=405)
|