first
This commit is contained in:
commit
d731fb6608
486 files changed
+251018
No files matched your search
@@ -0,0 +1,828 @@
|
||||
from django.shortcuts import redirect, render
|
||||
from django.urls.base import reverse
|
||||
from persiantools.jdatetime import JalaliDate
|
||||
from persiantools import characters, digits
|
||||
import datetime
|
||||
from django.core.paginator import Paginator
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
|
||||
|
||||
# Create your views here.
|
||||
from django.http import HttpResponse
|
||||
from django.urls import reverse
|
||||
from django.http import Http404, HttpResponseRedirect
|
||||
from django.db.models import Count, Sum
|
||||
from django.contrib.auth.models import Permission, User
|
||||
from django.contrib.auth import authenticate, login, logout
|
||||
from django.contrib.auth.decorators import login_required, permission_required
|
||||
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.db.models import Q
|
||||
|
||||
from .models import *
|
||||
|
||||
def p_login(request):
|
||||
username = request.POST.get('username', NULL)
|
||||
password = request.POST.get('password', NULL)
|
||||
if username != NULL and password != NULL:
|
||||
if not request.user.is_authenticated:
|
||||
user = authenticate(request, username=username, password=password)
|
||||
if user is not None:
|
||||
login(request, user)
|
||||
return redirect("/panel/ActionList/"+str(request.user.id)+"/today")
|
||||
else:
|
||||
data = {'message': 'یوزنیم یا پسورد اشتباه است'}
|
||||
return render(request, 'admin_panel/login.html', data)
|
||||
else:
|
||||
return redirect("/panel/")
|
||||
else:
|
||||
if request.user.is_authenticated:
|
||||
return redirect("/panel/")
|
||||
else:
|
||||
return render(request, 'admin_panel/login.html')
|
||||
#return logout(request)
|
||||
|
||||
def p_logout(request):
|
||||
logout(request)
|
||||
return redirect("/panel/p_login/")
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
@permission_required('admin_panel.ViewReportMali', raise_exception=True)
|
||||
def bedehi(request):
|
||||
try:
|
||||
debit = Article.objects.filter().aggregate(Sum('debit'))['debit__sum']
|
||||
credit = Article.objects.filter().aggregate(Sum('credit'))['credit__sum']
|
||||
mandehesabCs = debit - credit
|
||||
articls = Article.objects.filter().order_by('-createdDT')[:100]
|
||||
except:
|
||||
articls =None
|
||||
mandehesabCs = 0
|
||||
|
||||
data = {'articls': articls, 'mandehesabKP': mandehesabCs}
|
||||
return render(request, 'admin_panel/bedehi.html', data)
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
@permission_required('admin_panel.ViewReportMali', raise_exception=True)
|
||||
def bedehiKhadamat(request):
|
||||
#bedehiKhadamat
|
||||
try:
|
||||
debit = Article.objects.filter(typePy='khadamat').aggregate(Sum('debit'))['debit__sum']
|
||||
credit = Article.objects.filter(typePy='khadamat').aggregate(Sum('credit'))['credit__sum']
|
||||
mandehesabCs = debit - credit
|
||||
articls = Article.objects.filter(typePy='khadamat').order_by('-createdDT')[:100]
|
||||
except:
|
||||
articls =None
|
||||
mandehesabCs = 0
|
||||
|
||||
data = {'articls': articls, 'mandehesabKP': mandehesabCs}
|
||||
return render(request, 'admin_panel/bedehi.html', data)
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
@permission_required('admin_panel.ViewReportMali', raise_exception=True)
|
||||
def bedehiNasb(request):
|
||||
try:
|
||||
debit = Article.objects.filter(typePy='nasb').aggregate(Sum('debit'))['debit__sum']
|
||||
credit = Article.objects.filter(typePy='nasb').aggregate(Sum('credit'))['credit__sum']
|
||||
mandehesabCs = debit - credit
|
||||
articls = Article.objects.filter(typePy='nasb').order_by('-createdDT')[:100]
|
||||
except:
|
||||
articls =None
|
||||
mandehesabCs = 0
|
||||
|
||||
data = {'articls': articls, 'mandehesabKP': mandehesabCs}
|
||||
return render(request, 'admin_panel/bedehi.html', data)
|
||||
|
||||
@csrf_exempt
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
def customers(request):
|
||||
searchVal = request.GET.get('searchVal', '')
|
||||
searchOn = request.GET.get('searchOn', '')
|
||||
searchStatus = True
|
||||
full_path = request.get_full_path()
|
||||
|
||||
if searchOn == 'code':
|
||||
all_customers = Customer.objects.filter(idCode__contains=searchVal).order_by('-create_date')
|
||||
elif searchOn == 'phone':
|
||||
all_customers = Customer.objects.filter(phone1__contains=searchVal).order_by('-create_date')
|
||||
elif searchOn == 'name':
|
||||
all_customers = Customer.objects.filter(name_family__contains=searchVal).order_by('-create_date')
|
||||
elif searchOn == 'address':
|
||||
all_customers = Customer.objects.filter(address__contains=searchVal).order_by('-create_date')
|
||||
else:
|
||||
searchStatus = False
|
||||
all_customers = Customer.objects.all().order_by('-create_date')
|
||||
|
||||
paginator = Paginator(all_customers, 25) # Show 25 contacts per page.
|
||||
page_number = request.GET.get('page', None)
|
||||
all_customers = paginator.get_page(page_number)
|
||||
data = {'customersD': all_customers, 'searchStatus': searchStatus, 'full_path': full_path}
|
||||
return render(request, 'admin_panel/customers.html', data)
|
||||
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
def customersSearch(request, searchVal,searchOn):
|
||||
searchStatus = True
|
||||
|
||||
if searchOn == 'code':
|
||||
all_customers = Customer.objects.filter(idCode__contains=searchVal).order_by('-create_date')
|
||||
elif searchOn == 'phone':
|
||||
all_customers = Customer.objects.filter(phone1__contains=searchVal).order_by('-create_date')
|
||||
elif searchOn == 'name':
|
||||
all_customers = Customer.objects.filter(name_family__contains=searchVal).order_by('-create_date')
|
||||
elif searchOn == 'address':
|
||||
all_customers = Customer.objects.filter(address__contains=searchVal).order_by('-create_date')
|
||||
else:
|
||||
searchStatus = False
|
||||
all_customers = Customer.objects.all().order_by('-create_date')
|
||||
|
||||
paginator = Paginator(all_customers, 25) # Show 25 contacts per page.
|
||||
page_number = request.GET.get('page', None)
|
||||
all_customers = paginator.get_page(page_number)
|
||||
|
||||
|
||||
data = {'customersD': all_customers, 'searchStatus': searchStatus}
|
||||
return render(request, 'admin_panel/customers.html', data)
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
def customer(request ,c_id):
|
||||
customer = Customer.objects.get(id=c_id)
|
||||
categorys = ProductCategory.objects.all()
|
||||
factorha = Factor.objects.filter(customer__id = c_id)
|
||||
#all_prd = serializers.serialize("json", all_prda)
|
||||
#return JsonResponse(all_prd,safe = False)
|
||||
dateNow = datetime.datetime.now().date
|
||||
data = {'customer': customer, 'categorys': categorys, 'dateNow': dateNow, 'factorha': factorha}
|
||||
return render(request, 'admin_panel/customerID.html', data)
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
def customerNew(request ,c_id):
|
||||
customer = Customer.objects.get(id=c_id)
|
||||
categorys = ProductCategory.objects.all()
|
||||
factorha = Factor.objects.filter(customer__id = c_id)
|
||||
#all_prd = serializers.serialize("json", all_prda)
|
||||
#return JsonResponse(all_prd,safe = False)
|
||||
dateNow = datetime.datetime.now().date
|
||||
data = {'customer': customer, 'categorys': categorys, 'dateNow': dateNow, 'factorha': factorha}
|
||||
return render(request, 'admin_panel/customerNew.html', data)
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
def customerFactors(request ,c_id):
|
||||
customer = Customer.objects.get(id=c_id)
|
||||
categorys = ProductCategory.objects.all()
|
||||
factorha = Factor.objects.filter(customer__id = c_id).order_by('-create_date')
|
||||
#all_prd = serializers.serialize("json", all_prda)
|
||||
#return JsonResponse(all_prd,safe = False)
|
||||
dateNow = datetime.datetime.now().date
|
||||
data = {'customer': customer, 'categorys': categorys, 'dateNow': dateNow, 'factorha': factorha}
|
||||
return render(request, 'admin_panel/customerIDFactor.html', data)
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
def customerFactor(request ,c_id, f_id):
|
||||
customer = Customer.objects.get(id=c_id)
|
||||
categorys = ProductCategory.objects.all()
|
||||
factorO = Factor.objects.get(customer=customer, id=f_id)
|
||||
fiteam = FactorIteam.objects.filter(factor=factorO)
|
||||
#all_prd = serializers.serialize("json", all_prda)
|
||||
#return JsonResponse(all_prd,safe = False)
|
||||
dateNow = datetime.datetime.now().date
|
||||
data = {'customer': customer, 'categorys': categorys, 'dateNow': dateNow, 'factorO': factorO, 'fiteam': fiteam}
|
||||
return render(request, 'admin_panel/customerFactor.html', data)
|
||||
|
||||
|
||||
def productsJson(request):
|
||||
from django.core import serializers
|
||||
from django.http import JsonResponse
|
||||
all_prd = Product.objects.all()
|
||||
all_prd = serializers.serialize("json", all_prd)
|
||||
return JsonResponse(all_prd,safe = False)
|
||||
|
||||
def ActionJson(request, action_id):
|
||||
from django.core import serializers
|
||||
from django.http import JsonResponse
|
||||
AcJson = Action.objects.filter(id=action_id)
|
||||
AcJson = serializers.serialize("json", AcJson)
|
||||
return JsonResponse(AcJson,safe = False)
|
||||
|
||||
def CustomerJson(request, c_id):
|
||||
from django.core import serializers
|
||||
from django.http import JsonResponse
|
||||
customerJson = Customer.objects.filter(id=c_id)
|
||||
customerJson = serializers.serialize("json", customerJson)
|
||||
return JsonResponse(customerJson,safe = False)
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
def productMojodi(request, p_id):
|
||||
storeUser = StoreRoom.objects.get(user__id=request.user.id)
|
||||
productS_in = ProductInStore.objects.filter(Product__id=p_id, StoreRoom=storeUser, year=1400).aggregate(Sum('s_in'))['s_in__sum']
|
||||
productS_out = ProductInStore.objects.filter(Product__id=p_id, StoreRoom=storeUser, year=1400).aggregate(Sum('s_out'))['s_out__sum']
|
||||
#return HttpResponse(productS_out)
|
||||
try:
|
||||
mojodi_prd = productS_in - productS_out
|
||||
except:
|
||||
mojodi_prd = 0
|
||||
return HttpResponse(str(mojodi_prd))
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
def customersAdd(request):
|
||||
an_name = request.POST.get('an_name', '')
|
||||
an_address = request.POST.get('an_address', '')
|
||||
phone1 = request.POST.get('phone1', '')
|
||||
phone2 = request.POST.get('phone2', '')
|
||||
phone3 = request.POST.get('phone3', '')
|
||||
installDate = request.POST.get('installDate', '')
|
||||
idnCode = request.POST.get('idnCode', '')
|
||||
an_name = request.POST.get('an_name', '')
|
||||
|
||||
year = int(installDate.split('/')[0])
|
||||
month = int(installDate.split('/')[1])
|
||||
day = int(installDate.split('/')[2])
|
||||
|
||||
#return HttpResponse(year)
|
||||
installDate = JalaliDate(year, month, day).to_gregorian()
|
||||
|
||||
newCs = Customer()
|
||||
newCs.name_family = an_name
|
||||
newCs.address = an_address
|
||||
newCs.phone1 = phone1
|
||||
newCs.phone2 = phone2
|
||||
newCs.phone3 = phone3
|
||||
newCs.installDate = installDate
|
||||
newCs.idCode = idnCode
|
||||
newCs.save()
|
||||
|
||||
#return HttpResponse(installDate)
|
||||
return redirect('/panel/customers/')
|
||||
#return render(request, 'admin_panel/customersAdd.html')
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
def customerEdit(request, c_id):
|
||||
an_name = request.POST.get('an_name', '')
|
||||
an_address = request.POST.get('an_address', '')
|
||||
phone1 = request.POST.get('phone1', '')
|
||||
phone2 = request.POST.get('phone2', '')
|
||||
phone3 = request.POST.get('phone3', '')
|
||||
installDate = request.POST.get('installDate', '')
|
||||
idnCode = request.POST.get('idnCode', '')
|
||||
an_name = request.POST.get('an_name', '')
|
||||
|
||||
year = int(installDate.split('/')[0])
|
||||
month = int(installDate.split('/')[1])
|
||||
day = int(installDate.split('/')[2])
|
||||
|
||||
#return HttpResponse(year)
|
||||
installDate = JalaliDate(year, month, day).to_gregorian()
|
||||
|
||||
newCs = Customer.objects.get(id=c_id)
|
||||
newCs.name_family = an_name
|
||||
newCs.address = an_address
|
||||
newCs.phone1 = phone1
|
||||
newCs.phone2 = phone2
|
||||
newCs.phone3 = phone3
|
||||
newCs.installDate = installDate
|
||||
newCs.idCode = idnCode
|
||||
newCs.save()
|
||||
|
||||
#return HttpResponse(installDate)
|
||||
return redirect('/panel/customer/'+str(c_id))
|
||||
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
def entezar(request):
|
||||
return render(request, 'admin_panel/entezar.html')
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
def stores(request):
|
||||
if request.user.username not in ('admin', 'office1', 'office2', 'office3', 'khatibi'):
|
||||
all_store = StoreRoom.objects.filter(user__id=request.user.id).order_by('id')[:20]
|
||||
else:
|
||||
all_store = StoreRoom.objects.all().order_by('id')[:20]
|
||||
data = {'all_store': all_store}
|
||||
return render(request, 'admin_panel/stores.html', data)
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
def store(request, s_id):
|
||||
productCategory = ProductCategory.objects.all()
|
||||
storeO = StoreRoom.objects.get(id=s_id)
|
||||
searchStatus = False
|
||||
searchQS = request.POST.get('searchQS', '')
|
||||
mojodi = request.POST.get('mojodi', '')
|
||||
#return HttpResponse(mojodi)
|
||||
if searchQS !='':
|
||||
productSum = Product.objects.filter(productinstore__StoreRoom=storeO ,productinstore__year=1400,product_name__contains=searchQS).annotate(mojodi=( Sum('productinstore__s_in') - Sum('productinstore__s_out') ))
|
||||
if mojodi == "0":
|
||||
productSum = productSum.filter(mojodi__lte=0)
|
||||
searchStatus = True
|
||||
else:
|
||||
productSum = Product.objects.filter(productinstore__StoreRoom=storeO ,productinstore__year=1400).annotate(mojodi=( Sum('productinstore__s_in') - Sum('productinstore__s_out') ))
|
||||
if mojodi == "0":
|
||||
searchStatus = True
|
||||
productSum = productSum.filter(mojodi__lte=0)
|
||||
data = {'storeO': storeO,'productSum': productSum, 's_id': s_id, 'searchStatus': searchStatus, "mojodi": mojodi, 'djsearchQS':searchQS, 'productCategory': productCategory}
|
||||
return render(request, 'admin_panel/store.html', data)
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
@permission_required('admin_panel.ViewStore', raise_exception=True)
|
||||
def operations(request, s_id):
|
||||
productCategory = ProductCategory.objects.all()
|
||||
storeO = StoreRoom.objects.get(id=s_id)
|
||||
operationsList = ProductInStore.objects.filter(StoreRoom=storeO, year=1400).order_by('-createdDT')
|
||||
data = {'storeO': storeO, 'operationsList': operationsList, 's_id': s_id, 'productCategory': productCategory}
|
||||
return render(request, 'admin_panel/operations.html', data)
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
@permission_required('admin_panel.ViewStore', raise_exception=True)
|
||||
def operationProduct(request, s_id, p_id):
|
||||
productCategory = ProductCategory.objects.all()
|
||||
storeO = StoreRoom.objects.get(id=s_id)
|
||||
operationsList = ProductInStore.objects.filter(StoreRoom=storeO, year=1400, Product__id=p_id).order_by('-createdDT')
|
||||
data = {'storeO': storeO, 'operationsList': operationsList, 's_id': s_id, 'productCategory': productCategory}
|
||||
return render(request, 'admin_panel/operations.html', data)
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
@permission_required('admin_panel.ViewStore', raise_exception=True)
|
||||
def newOperation(request, s_id, p_id):
|
||||
productCategory = ProductCategory.objects.all()
|
||||
storeO = StoreRoom.objects.get(id=s_id)
|
||||
allStores = StoreRoom.objects.exclude(id=s_id)
|
||||
product = Product.objects.get(id=p_id)
|
||||
data = {'s_id': s_id,'p_id': p_id, 'allStores': allStores, 'storeO': storeO, 'product':product, 'productCategory': productCategory}
|
||||
return render(request, 'admin_panel/newOperation.html', data )
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
@permission_required('admin_panel.ViewStore', raise_exception=True)
|
||||
def newStore(request):
|
||||
storeName = request.POST.get('storeName', '')
|
||||
newStore = StoreRoom()
|
||||
newStore.store_name = storeName
|
||||
newStore.save()
|
||||
|
||||
return redirect('/panel/store/')
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
@permission_required('admin_panel.ViewStore', raise_exception=True)
|
||||
def productAdd(request):
|
||||
namePrd = request.POST.get('namePrd', '')
|
||||
category = request.POST.get('category', '')
|
||||
price = request.POST.get('price', '')
|
||||
mojodiAval = request.POST.get('mojodiAval', '')
|
||||
storeroom = request.POST.get('storeroom', '')
|
||||
|
||||
newProduct = Product()
|
||||
newProduct.product_name = namePrd
|
||||
newProduct.ProductCategory = ProductCategory.objects.get(id=category)
|
||||
newProduct.product_price = price
|
||||
newProduct.save()
|
||||
|
||||
prd_in_store = ProductInStore()
|
||||
prd_in_store.Product = newProduct
|
||||
prd_in_store.StoreRoom = StoreRoom.objects.get(id=storeroom)
|
||||
prd_in_store.s_in = mojodiAval
|
||||
prd_in_store.desc = "موجودی اولیه: "+str(mojodiAval)
|
||||
prd_in_store.save()
|
||||
|
||||
#return HttpResponse(installDate)
|
||||
return redirect('/panel/store/1')
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
@permission_required('admin_panel.ViewStore', raise_exception=True)
|
||||
def productEdit(request):
|
||||
prd_code = request.POST.get('prd_code', '')
|
||||
namePrd = request.POST.get('namePrd', '')
|
||||
category = request.POST.get('category', '')
|
||||
price = request.POST.get('price', '')
|
||||
|
||||
#return HttpResponse(prd_code)
|
||||
|
||||
editProduct = Product.objects.get(id=prd_code)
|
||||
editProduct.product_name = namePrd
|
||||
editProduct.ProductCategory = ProductCategory.objects.get(id=category)
|
||||
editProduct.product_price = price
|
||||
editProduct.save()
|
||||
|
||||
return redirect('/panel/store/1')
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
@permission_required('admin_panel.ViewStore', raise_exception=True)
|
||||
def productDel(request, p_id, s_id):
|
||||
Product.objects.get(id=p_id).delete()
|
||||
return redirect('/panel/store/'+str(s_id))
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
@permission_required('admin_panel.ViewStore', raise_exception=True)
|
||||
def operation(request):
|
||||
prd_id = request.POST.get('prd_id', '')
|
||||
actionType = request.POST.get('actionType', '')
|
||||
tedad = int(request.POST.get('tedad', ''))
|
||||
azanbar = request.POST.get('azanbar', '')
|
||||
beanbar = request.POST.get('beanbar', '')
|
||||
desc = request.POST.get('desc', '')
|
||||
|
||||
pInStore = ProductInStore()
|
||||
sRoom = StoreRoom.objects.get(id=azanbar)
|
||||
productO = Product.objects.get(id=prd_id)
|
||||
pInStore.StoreRoom = sRoom
|
||||
pInStore.Product = productO
|
||||
if actionType == 'vorod':
|
||||
pInStore.s_in = tedad
|
||||
pInStore.desc = "ورود: "+str(tedad)+" به انبار " + str(sRoom.store_name) + "#" + str(desc)
|
||||
elif actionType == 'khoroj':
|
||||
productS_in = ProductInStore.objects.filter(Product=productO, StoreRoom=sRoom, year=1400).aggregate(Sum('s_in'))['s_in__sum']
|
||||
productS_out = ProductInStore.objects.filter(Product=productO, StoreRoom=sRoom, year=1400).aggregate(Sum('s_out'))['s_out__sum']
|
||||
mojodi_prd = productS_in - productS_out
|
||||
if mojodi_prd >= tedad:
|
||||
pInStore.s_out = tedad
|
||||
pInStore.desc = "خروج: "+str(tedad)+" از انبار " + str(sRoom.store_name) + "#" + str(desc)
|
||||
else:
|
||||
return HttpResponse("موجودی کافی نیست، موجودی فعلی: "+ str(mojodi_prd))
|
||||
elif actionType == 'transfer':
|
||||
beanbar = int(beanbar)
|
||||
beanbarOjb = StoreRoom.objects.get(id=beanbar)
|
||||
productS_in = ProductInStore.objects.filter(Product=productO, StoreRoom=sRoom, year=1400).aggregate(Sum('s_in'))['s_in__sum']
|
||||
productS_out = ProductInStore.objects.filter(Product=productO, StoreRoom=sRoom, year=1400).aggregate(Sum('s_out'))['s_out__sum']
|
||||
mojodi_prd = productS_in - productS_out
|
||||
if mojodi_prd >= tedad:
|
||||
pInStore.s_out = tedad
|
||||
pInStore.desc = "خروج: "+str(tedad)+" از انبار " + str(sRoom.store_name) + " جهت انتقال به انبار " + str(beanbarOjb.store_name)
|
||||
else:
|
||||
return HttpResponse("موجودی کافی نیست، موجودی فعلی: "+ str(mojodi_prd))
|
||||
|
||||
pInStore.save()
|
||||
|
||||
if actionType == 'transfer':
|
||||
pInStore = ProductInStore()
|
||||
pInStore.StoreRoom = beanbarOjb
|
||||
pInStore.s_in = tedad
|
||||
pInStore.Product = productO
|
||||
pInStore.desc = "ورود: "+str(tedad)+" از انبار " + str(sRoom.store_name)
|
||||
pInStore.save()
|
||||
|
||||
return redirect('/panel/store/'+str(sRoom.id))
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
def newFactor(request, c_id):
|
||||
prdsList = request.POST.get('prdsList', '')
|
||||
sarResidDate = request.POST.get('sarResidDate', None)
|
||||
pardakhti = request.POST.get('pardakhti', None)
|
||||
#return HttpResponse(pardakhti)
|
||||
if pardakhti:
|
||||
pardakhti=int(pardakhti)
|
||||
if pardakhti>=1:
|
||||
pass
|
||||
else:
|
||||
pardakhti = None
|
||||
#return HttpResponse(sarResidDate)
|
||||
try:
|
||||
sarResidDate = digits.fa_to_en(digits.ar_to_fa(sarResidDate))
|
||||
#return HttpResponse(sarResidDate)
|
||||
sarResidDate = sarResidDate.split("/")
|
||||
#return HttpResponse(sarResidDate[2])
|
||||
sarResidDate = JalaliDate(int(sarResidDate[0]), int(sarResidDate[1]), int(sarResidDate[2])).to_gregorian()
|
||||
#return HttpResponse(sarResidDate)
|
||||
except:
|
||||
sarResidDate = None
|
||||
|
||||
#return HttpResponse(sarResidDate[1])
|
||||
#sarResidDate = JalaliDate(sarResidDate[0], sarResidDate[1], sarResidDate[2]).to_gregorian()
|
||||
|
||||
payType = request.POST.get('payType', '')
|
||||
FactorDate = request.POST.get('FactorDate', '')
|
||||
FactorType = request.POST.get('FactorType', '')
|
||||
FactorDesc = request.POST.get('FactorDesc', '')
|
||||
Factorfail = False
|
||||
customerObj=Customer.objects.get(id=c_id)
|
||||
storeUser = StoreRoom.objects.get(user__id=request.user.id)
|
||||
import json
|
||||
prdsList = json.loads(prdsList)
|
||||
sum_price = 0
|
||||
for prd in prdsList:
|
||||
if prd['garanty_Esh'] == ' ' or prd['garanty_Esh'] == '' or prd['garanty_Esh'] == None:
|
||||
sum_price += prd['prd_count'] * prd['price']
|
||||
|
||||
#return HttpResponse(prd_code)
|
||||
try:
|
||||
newFactor = Factor()
|
||||
newFactor.customer= customerObj
|
||||
newFactor.amount = sum_price
|
||||
if payType in ('naghd', 'kartKhan', 'cardToCard'):
|
||||
newFactor.pay_status = 'paid'
|
||||
else:
|
||||
newFactor.pay_status = 'unpaid'
|
||||
newFactor.FactorType = FactorType
|
||||
newFactor.PayType = payType
|
||||
newFactor.desc = FactorDesc
|
||||
if sarResidDate != None:
|
||||
newFactor.deadline = sarResidDate
|
||||
newFactor.user = User.objects.get(id=request.user.id)
|
||||
newFactor.save()
|
||||
except:
|
||||
try:
|
||||
Factorfail=True
|
||||
newFactor.delete()
|
||||
except:
|
||||
pass
|
||||
|
||||
if Factorfail != True:
|
||||
#accFactor To article
|
||||
is_naghd = False
|
||||
articleHesabDari = Article()
|
||||
articleHesabDari.debit = newFactor.amount
|
||||
articleHesabDari.credit = 0
|
||||
articleHesabDari.customer = customerObj
|
||||
articleHesabDari.factor = newFactor
|
||||
if payType in ('naghd', 'kartKhan', 'cardToCard'):
|
||||
is_naghd = True
|
||||
articleHesabDari.type = payType
|
||||
articleHesabDari.desc = str(FactorType) + " " + str(customerObj.name_family) + " طی فاکتور شماره: " + str(newFactor.id)
|
||||
articleHesabDari.save()
|
||||
|
||||
if is_naghd:
|
||||
articleHesabDari2 = Article()
|
||||
articleHesabDari2.debit = 0
|
||||
articleHesabDari2.credit = newFactor.amount
|
||||
articleHesabDari2.customer = customerObj
|
||||
articleHesabDari2.type = payType
|
||||
articleHesabDari2.factor = newFactor
|
||||
articleHesabDari2.desc = str(FactorType) + " " + str(customerObj.name_family) + " تسویه نقدی فاکتور شماره: " + str(newFactor.id)
|
||||
articleHesabDari2.save()
|
||||
elif pardakhti != None and pardakhti!='' and pardakhti != ' ':
|
||||
articleHesabDari2 = Article()
|
||||
articleHesabDari2.debit = 0
|
||||
articleHesabDari2.credit = pardakhti
|
||||
articleHesabDari2.customer = customerObj
|
||||
articleHesabDari2.type = payType
|
||||
articleHesabDari2.factor = newFactor
|
||||
articleHesabDari2.desc = str(customerObj.name_family) + " پرداخت نقد در محل برا فاکتور " + str(newFactor.id)
|
||||
articleHesabDari2.save()
|
||||
|
||||
for prd in prdsList:
|
||||
try:
|
||||
fIteams = FactorIteam()
|
||||
fIteams.factor = newFactor
|
||||
if prd['prd_id'] == 9999:
|
||||
Gproduct = None
|
||||
fIteams.product = Gproduct
|
||||
fIteams.product_name = prd['product_name']
|
||||
fIteams.num = prd['prd_count']
|
||||
fIteams.amount = int(prd['priceKol'])
|
||||
else:
|
||||
Gproduct = Product.objects.get(id=prd['prd_id'])
|
||||
fIteams.product = Gproduct
|
||||
fIteams.product_name = Gproduct.product_name
|
||||
fIteams.num = prd['prd_count']
|
||||
fIteams.amount = prd['prd_count'] * Gproduct.product_price
|
||||
fIteams.garantyEsh = prd['garanty_Esh']
|
||||
fIteams.save()
|
||||
except:
|
||||
Factorfail = True
|
||||
newFactor.delete()
|
||||
break
|
||||
|
||||
if Factorfail != True:
|
||||
for prd in prdsList:
|
||||
if prd['prd_id'] != 9999:
|
||||
pInStore = ProductInStore()
|
||||
sRoom = storeUser
|
||||
productO = Product.objects.get(id=prd['prd_id'])
|
||||
pInStore.StoreRoom = sRoom
|
||||
pInStore.Product = productO
|
||||
pInStore.factor = newFactor
|
||||
productS_in = ProductInStore.objects.filter(Product=productO, StoreRoom=sRoom, year=1400).aggregate(Sum('s_in'))['s_in__sum']
|
||||
productS_out = ProductInStore.objects.filter(Product=productO, StoreRoom=sRoom, year=1400).aggregate(Sum('s_out'))['s_out__sum']
|
||||
mojodi_prd = productS_in - productS_out
|
||||
if mojodi_prd >= prd['prd_count']:
|
||||
pInStore.s_out = prd['prd_count']
|
||||
if prd['garanty_Esh'] != ' ' and prd['garanty_Esh'] != '' and prd['garanty_Esh'] != None:
|
||||
pInStore.desc = "خروج: " + str(prd['prd_count']) + "#"+str(prd['garanty_Esh'])+ "#" + str(customerObj.name_family) + " * " + str(request.user.first_name) + " " + str(request.user.last_name)
|
||||
else:
|
||||
pInStore.desc = "خروج: " + str(prd['prd_count']) + "#فروش" + "#" + str(customerObj.name_family) + " * " + str(request.user.first_name) + " " + str(request.user.last_name)
|
||||
pInStore.save()
|
||||
else:
|
||||
return HttpResponse("موجودی کافی نیست، موجودی فعلی: "+ str(mojodi_prd))
|
||||
|
||||
return redirect('/panel/customer/'+str(c_id)+'/factors/')
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
@permission_required('admin_panel.DelFactor', raise_exception=True)
|
||||
def FactorDel(request, c_id ,f_id):
|
||||
try:
|
||||
#ProductInStore.objects.filter(factor__id= f_id).delete()
|
||||
Factor.objects.get(id=f_id).delete()
|
||||
return redirect('/panel/customer/'+str(c_id)+'/factors/')
|
||||
except:
|
||||
return HttpResponse("خطا در حذف فاکتور")
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
@permission_required('admin_panel.DelCustomer', raise_exception=True)
|
||||
def customerDel(request, c_id):
|
||||
try:
|
||||
Customer.objects.get(id=c_id).delete()
|
||||
return redirect('/panel/customers/')
|
||||
except:
|
||||
return HttpResponse("خطا در حذف مشتری")
|
||||
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
def customerHesabdari(request ,c_id):
|
||||
customer = Customer.objects.get(id=c_id)
|
||||
try:
|
||||
debit = Article.objects.filter(customer=customer).aggregate(Sum('debit'))['debit__sum']
|
||||
credit = Article.objects.filter(customer=customer).aggregate(Sum('credit'))['credit__sum']
|
||||
mandehesabCs = debit - credit
|
||||
articls = Article.objects.filter(customer=customer).order_by('-createdDT')
|
||||
except:
|
||||
articls =None
|
||||
mandehesabCs = 0
|
||||
|
||||
dateNow = datetime.datetime.now().date
|
||||
data = {'customer': customer, 'mandehesabCs': mandehesabCs, 'articls': articls}
|
||||
return render(request, 'admin_panel/customerHesabDari.html', data)
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
def customerHesabdariAdd(request ,c_id):
|
||||
price = request.POST.get('price', None)
|
||||
type = request.POST.get('type', None)
|
||||
typePy = request.POST.get('typePy', None)
|
||||
desc = request.POST.get('desc', None)
|
||||
newArticl = Article()
|
||||
newArticl.customer = Customer.objects.get(id=c_id)
|
||||
newArticl.desc = desc
|
||||
newArticl.typePy = typePy
|
||||
if type == 'credit':
|
||||
newArticl.credit = price
|
||||
newArticl.debit = 0
|
||||
elif type == 'debit':
|
||||
newArticl.debit = price
|
||||
newArticl.credit = 0
|
||||
newArticl.save()
|
||||
return redirect('/panel/customer/'+str(c_id)+'/hesabdari')
|
||||
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
def customerAction(request ,c_id):
|
||||
customer = Customer.objects.get(id=c_id)
|
||||
actions = Action.objects.filter(customer=customer).order_by("-createdDT")
|
||||
allUsers = User.objects.filter().exclude(username='admin').exclude(username='fesahat')
|
||||
data = {'customer': customer, 'actions': actions, 'allUsers': allUsers}
|
||||
return render(request, 'admin_panel/customerAction.html', data)
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
def customerNewAction(request ,c_id):
|
||||
actionType = request.POST.get('actionType', None)
|
||||
dateTimeAnjam = request.POST.get('dateTimeAnjam', None)
|
||||
#return HttpResponse(float(dateTimeAnjam+".0"))
|
||||
try:
|
||||
dateTimeAnjam = datetime.datetime.fromtimestamp(int(dateTimeAnjam)/1e3)
|
||||
except:
|
||||
pass
|
||||
desc = request.POST.get('desc', None)
|
||||
userID = request.POST.get('userID', None)
|
||||
is_done = request.POST.get('is_done', None)
|
||||
result = request.POST.get('result', None)
|
||||
FinishDateTime = request.POST.get('FinishDateTime', None)
|
||||
try:
|
||||
FinishDateTime = datetime.datetime.fromtimestamp(int(FinishDateTime)/1e3)
|
||||
except:
|
||||
pass
|
||||
|
||||
newAction = Action()
|
||||
newAction.actionType = actionType
|
||||
newAction.actionDateTime = dateTimeAnjam
|
||||
newAction.desc = desc
|
||||
newAction.forUser = User.objects.get(id=int(userID))
|
||||
newAction.customer = Customer.objects.get(id=int(c_id))
|
||||
if is_done:
|
||||
newAction.status = 'finish'
|
||||
newAction.finishDateTime = FinishDateTime
|
||||
newAction.result = result
|
||||
else:
|
||||
newAction.status = 'waite'
|
||||
newAction.save()
|
||||
return redirect('/panel/customer/'+str(c_id)+'/action')
|
||||
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
def ActionList(request):
|
||||
actions = Action.objects.filter(forUser__id=request.user.id, status='waite').order_by("-createdDT")
|
||||
allUsers = User.objects.filter().exclude(username='admin').exclude(username='fesahat')
|
||||
data = {'actions': actions, 'allUsers': allUsers}
|
||||
return render(request, 'admin_panel/ActionList.html', data)
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
def ActionListUser(request, u_id):
|
||||
actions = Action.objects.filter(forUser__id=u_id, status='waite').order_by("-createdDT")
|
||||
allUsers = User.objects.filter().exclude(username='admin').exclude(username='fesahat')
|
||||
data = {'actions': actions, 'allUsers': allUsers}
|
||||
return render(request, 'admin_panel/ActionList.html', data)
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
def customerEditAction(request ,c_id, action_id):
|
||||
|
||||
actionType = request.POST.get('actionType', None)
|
||||
dateTimeAnjam = request.POST.get('dateTimeAnjam', None)
|
||||
#return HttpResponse(float(dateTimeAnjam+".0"))
|
||||
try:
|
||||
dateTimeAnjam = datetime.datetime.fromtimestamp(int(dateTimeAnjam)/1e3)
|
||||
except:
|
||||
pass
|
||||
desc = request.POST.get('desc', None)
|
||||
userID = request.POST.get('userID', None)
|
||||
is_done = request.POST.get('is_done', None)
|
||||
result = request.POST.get('result', None)
|
||||
FinishDateTime = request.POST.get('FinishDateTime', None)
|
||||
try:
|
||||
FinishDateTime = datetime.datetime.fromtimestamp(int(FinishDateTime)/1e3)
|
||||
except:
|
||||
pass
|
||||
|
||||
newAction = Action.objects.get(id=action_id)
|
||||
newAction.actionType = actionType
|
||||
newAction.actionDateTime = dateTimeAnjam
|
||||
newAction.desc = desc
|
||||
newAction.forUser = User.objects.get(id=int(userID))
|
||||
newAction.customer = Customer.objects.get(id=int(c_id))
|
||||
if is_done:
|
||||
newAction.status = 'finish'
|
||||
newAction.finishDateTime = FinishDateTime
|
||||
newAction.result = result
|
||||
else:
|
||||
newAction.status = 'waite'
|
||||
newAction.save()
|
||||
#return redirect('/panel/customer/'+str(c_id)+'/action')
|
||||
return redirect(request.META.get('HTTP_REFERER', 'redirect_if_referer_not_found'))
|
||||
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
def ActionListAll(request):
|
||||
actions = Action.objects.filter().order_by("-id")
|
||||
allUsers = User.objects.filter().exclude(username='admin').exclude(username='fesahat')
|
||||
data = {'actions': actions, 'allUsers': allUsers}
|
||||
return render(request, 'admin_panel/ActionList.html', data)
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
def ActionListToday(request):
|
||||
startTodayDT= datetime.datetime.today().strftime('%Y-%m-%d 00:00:00')
|
||||
endTodayDT= datetime.datetime.today().strftime('%Y-%m-%d 23:59:59')
|
||||
#startTodayDT = datetime.datetime.strptime(startTodayDT, '%Y-%m-%d-00:00:00')
|
||||
#endTodayDT = datetime.datetime.strptime(endTodayDT, '%Y-%m-%d-23:59:59')
|
||||
#return HttpResponse(todayDT)
|
||||
actions = Action.objects.filter(actionDateTime__gte=startTodayDT,actionDateTime__lte=endTodayDT, forUser__id=request.user.id, status='waite').order_by("-actionDateTime")[:50]
|
||||
allUsers = User.objects.filter().exclude(username='admin').exclude(username='fesahat')
|
||||
data = {'actions': actions, 'allUsers': allUsers}
|
||||
return render(request, 'admin_panel/ActionList.html', data)
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
def ActionListUserToday(request, u_id):
|
||||
dateTimeAction = request.GET.get('dateTime', None)
|
||||
status = request.GET.get('status', None)
|
||||
unixADT = dateTimeAction
|
||||
if dateTimeAction:
|
||||
dateTimeAction = datetime.datetime.fromtimestamp(int(dateTimeAction)/1e3)
|
||||
startTodayDT = dateTimeAction.strftime('%Y-%m-%d 00:00:00')
|
||||
endTodayDT= dateTimeAction.strftime('%Y-%m-%d 23:59:59')
|
||||
else:
|
||||
startTodayDT= datetime.datetime.today().strftime('%Y-%m-%d 00:00:00')
|
||||
endTodayDT= datetime.datetime.today().strftime('%Y-%m-%d 23:59:59')
|
||||
#startTodayDT = datetime.datetime.strptime(startTodayDT, '%Y-%m-%d-00:00:00')
|
||||
#endTodayDT = datetime.datetime.strptime(endTodayDT, '%Y-%m-%d-23:59:59')
|
||||
#return HttpResponse(todayDT)
|
||||
if status == 'waite' or status == None or status == '' or status == ' ':
|
||||
status = 'waite'
|
||||
actions = Action.objects.filter(actionDateTime__gte=startTodayDT,actionDateTime__lte=endTodayDT, forUser__id=u_id, status=status).order_by("-actionDateTime")[:50]
|
||||
actionPr = Action.objects.filter(actionDateTime__lt=startTodayDT, forUser__id=u_id, status=status).order_by("-actionDateTime")[:200]
|
||||
elif status == 'finish':
|
||||
actionPr = None
|
||||
actions = Action.objects.filter(actionDateTime__gte=startTodayDT,actionDateTime__lte=endTodayDT, forUser__id=u_id, status=status).order_by("-actionDateTime")[:50]
|
||||
|
||||
allUsers = User.objects.filter().exclude(username='admin').exclude(username='fesahat')
|
||||
data = {'actions': actions, 'allUsers': allUsers, 'u_id': u_id, "unixADT": unixADT, "status": status, 'actionPr': actionPr}
|
||||
return render(request, 'admin_panel/ActionList.html', data)
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
def rezayat(request):
|
||||
dateTimeAction = request.GET.get('dateTime', None)
|
||||
statusRezayat = request.GET.get('status', None)
|
||||
status='finish'
|
||||
if statusRezayat=='finish':
|
||||
actions = Action.objects.exclude(actionType='vosol').exclude(Q(nazar='') | Q(nazar=None)).filter(status='finish').order_by("-id")[:50]
|
||||
else:
|
||||
statusRezayat='waite'
|
||||
actions = Action.objects.filter(Q(nazar='') | Q(nazar=None) & Q(status='finish')).exclude(actionType='vosol').order_by("id")[:50]
|
||||
data = {'actions': actions, "status": statusRezayat}
|
||||
return render(request, 'admin_panel/customerRezayat.html', data)
|
||||
|
||||
|
||||
@login_required(login_url='/panel/p_login/')
|
||||
def rezayatEdit(request, ac_id):
|
||||
csGrade = request.POST.get('csGrade', None)
|
||||
csDesc = request.POST.get('csDesc', None)
|
||||
if csDesc and csGrade:
|
||||
action = Action.objects.get(id=ac_id)
|
||||
action.nazar = csDesc
|
||||
action.grade = csGrade
|
||||
action.nazarDT = datetime.datetime.now()
|
||||
action.save()
|
||||
return redirect('/panel/rezayat/')
|
||||
else:
|
||||
return HttpResponse('لطفا همه فیلد ها را پر کنید')
|
||||
#data = {'actions': actions, "status": status}
|
||||
#return render(request, 'admin_panel/customerRezayat.html', data)
|
||||
Reference in new issue
Block a user