289 lines
13 KiB
Python
289 lines
13 KiB
Python
from django.http import JsonResponse, Http404
|
||
from django.shortcuts import render, get_object_or_404, redirect
|
||
from django.template.loader import render_to_string
|
||
from django.urls import reverse
|
||
from django.contrib.auth.decorators import login_required, permission_required
|
||
|
||
from application.pjt_mgnt.forms import ProjectLedgerForm, EmployeeProjectIncomeSettlementForm
|
||
from application.pjt_mgnt.models import *
|
||
from common.utils.page_helper import paginate_query_and_assign_numbers
|
||
|
||
|
||
@login_required
|
||
@permission_required('pjt_mgnt.view_projectledger', raise_exception=True)
|
||
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__icontain=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"),
|
||
"table_exclude_field_name": ['project_id'], # Exclude primary key
|
||
}
|
||
|
||
return render(request, 'items_list.html', context)
|
||
|
||
|
||
@login_required
|
||
@permission_required('pjt_mgnt.add_projectledger', raise_exception=True)
|
||
def proj_ledger_list_add(request):
|
||
if request.method == 'POST':
|
||
form = ProjectLedgerForm(request.POST)
|
||
if form.is_valid():
|
||
form.save()
|
||
return JsonResponse({"message": "添加成功"})
|
||
else:
|
||
form_html = render_to_string('form_partial.html', {'form': form}, request)
|
||
return JsonResponse({"form_html": form_html, "errors": form.errors}, status=400)
|
||
elif request.method == 'GET':
|
||
form = ProjectLedgerForm()
|
||
form_html = render_to_string('form_partial.html', {'form': form}, request)
|
||
return JsonResponse({"form_html": form_html})
|
||
else:
|
||
return JsonResponse({"message": "无效的请求方法"}, status=405)
|
||
|
||
|
||
@login_required
|
||
@permission_required('pjt_mgnt.change_projectledger', raise_exception=True)
|
||
def proj_ledger_list_modify(request):
|
||
if request.method == 'POST':
|
||
if 'project_id' in request.POST:
|
||
instance = ProjectLedger.objects.get(project_id=request.POST['project_id'])
|
||
form = ProjectLedgerForm(request.POST, instance=instance)
|
||
else:
|
||
form = ProjectLedgerForm(request.POST)
|
||
|
||
if form.is_valid():
|
||
form.save()
|
||
return JsonResponse({"message": "保存成功"})
|
||
else:
|
||
form_html = render_to_string('form_partial.html', {'form': form}, request)
|
||
return JsonResponse({"form_html": form_html, "errors": form.errors}, status=400)
|
||
elif request.method == 'GET':
|
||
if 'project_id' in request.GET:
|
||
try:
|
||
instance = ProjectLedger.objects.get(project_id=request.GET['project_id'])
|
||
form = ProjectLedgerForm(instance=instance)
|
||
except ProjectLedger.DoesNotExist:
|
||
raise Http404("对象不存在")
|
||
else:
|
||
form = ProjectLedgerForm()
|
||
|
||
form_html = render_to_string('form_partial.html', {'form': form}, request)
|
||
return JsonResponse({"form_html": form_html})
|
||
else:
|
||
return JsonResponse({"message": "无效的请求方法"}, status=405)
|
||
|
||
|
||
@login_required
|
||
@permission_required('pjt_mgnt.delete_projectledger', raise_exception=True)
|
||
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)
|
||
|
||
|
||
@login_required
|
||
@permission_required('pjt_mgnt.view_employeeprojectincome', raise_exception=True)
|
||
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"),
|
||
"table_exclude_field_name": ['record_id'], # Exclude primary key
|
||
}
|
||
|
||
return render(request, 'items_list.html', context)
|
||
|
||
|
||
@login_required
|
||
@permission_required('pjt_mgnt.add_employeeprojectincome', raise_exception=True)
|
||
def emp_proj_income_list_add(request):
|
||
if request.method == 'POST':
|
||
form = EmployeeProjectIncomeSettlementForm(request.POST)
|
||
if form.is_valid():
|
||
form.save()
|
||
return JsonResponse({"message": "添加成功"})
|
||
else:
|
||
form_html = render_to_string('form_partial.html', {'form': form}, request)
|
||
return JsonResponse({"form_html": form_html, "errors": form.errors}, status=400)
|
||
elif request.method == 'GET':
|
||
form = EmployeeProjectIncomeSettlementForm()
|
||
form_html = render_to_string('form_partial.html', {'form': form}, request)
|
||
return JsonResponse({"form_html": form_html})
|
||
else:
|
||
return JsonResponse({"message": "无效的请求方法"}, status=405)
|
||
|
||
|
||
@login_required
|
||
@permission_required('pjt_mgnt.change_employeeprojectincome', raise_exception=True)
|
||
def emp_proj_income_list_modify(request):
|
||
if request.method == 'POST':
|
||
if 'record_id' in request.POST:
|
||
instance = EmployeeProjectIncomeSettlement.objects.get(record_id=request.POST['record_id'])
|
||
form = EmployeeProjectIncomeSettlementForm(request.POST, instance=instance)
|
||
else:
|
||
form = EmployeeProjectIncomeSettlementForm(request.POST)
|
||
|
||
if form.is_valid():
|
||
form.save()
|
||
return JsonResponse({"message": "保存成功"})
|
||
else:
|
||
form_html = render_to_string('form_partial.html', {'form': form}, request)
|
||
return JsonResponse({"form_html": form_html, "errors": form.errors}, status=400)
|
||
elif request.method == 'GET':
|
||
if 'record_id' in request.GET:
|
||
try:
|
||
instance = EmployeeProjectIncomeSettlement.objects.get(record_id=request.GET['record_id'])
|
||
form = EmployeeProjectIncomeSettlementForm(instance=instance)
|
||
except EmployeeProjectIncomeSettlement.DoesNotExist:
|
||
raise Http404("对象不存在")
|
||
else:
|
||
form = EmployeeProjectIncomeSettlementForm()
|
||
|
||
form_html = render_to_string('form_partial.html', {'form': form}, request)
|
||
return JsonResponse({"form_html": form_html})
|
||
else:
|
||
return JsonResponse({"message": "无效的请求方法"}, status=405)
|
||
|
||
|
||
@login_required
|
||
@permission_required('pjt_mgnt.delete_employeeprojectincome', raise_exception=True)
|
||
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)
|