muhammad_nasif

sales.views/check_stock + sales_representative_status

Dec 11th, 2020
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.58 KB | None | 0 0
  1. def check_stock(request):
  2.     if request.session.is_empty():
  3.         return redirect(customer_view.login)
  4.     else:
  5.         if request.method == 'POST':
  6.  
  7.             product_id = request.POST['product_id']
  8.  
  9.             sql = "select (B.AREA ||' '||B.BRANCH_ID) AS branch , count(B.BRANCH_ID) as stock " \
  10.                   "from PRODUCT_SPECIFICATION SP, STOCK STK, PRODUCT_IMEI I, BRANCH_PRODUCT_STOCK BP, BRANCH B " \
  11.                   "where SP.PRODUCT_ID = STK.STOCK_PRODUCT_ID AND STK.STOCK_IMEI = I.IMEI_NO " \
  12.                   "AND I.IMEI_NO = BP.STOCK_IMEI AND BP.STOCK_BRANCH_ID = B.BRANCH_ID AND SP.PRODUCT_ID = %s " \
  13.                   "group by (B.AREA ||' '||B.BRANCH_ID)"
  14.  
  15.             cursor = connection.cursor()
  16.             cursor.execute(sql,[product_id])
  17.             result = cursor.fetchall()
  18.             table = []
  19.  
  20.             for i in result:
  21.                 branch = i[0]
  22.                 stock = i[1]
  23.                 row = {'branch':branch, 'stock':stock}
  24.                 table.append(row)
  25.  
  26.             print("printing table.........")
  27.             print(table)
  28.  
  29.             sql_1 = "select NAME from PRODUCT_SPECIFICATION where PRODUCT_ID = %s"
  30.             cursor = connection.cursor()
  31.             cursor.execute(sql_1,[product_id])
  32.             result_1 = cursor.fetchall()
  33.  
  34.             name = result_1[0][0]
  35.  
  36.             return render(request, "check_stock.html", {'available_stock':table, 'product_name':name})
  37.         else:
  38.             return render(request, "check_stock.html")
  39.  
  40. def sales_representative_status(request):
  41.     if request.session.is_empty():
  42.         return redirect(customer_view.login)
  43.     else:
  44.         sql = "SELECT * FROM EMPLOYEES WHERE EMPLOYEE_ID = %s"
  45.         sql_1 = "select employee_profit(EMPLOYEE_ID) from EMPLOYEES where  EMPLOYEE_ID=%s "
  46.         employee_id = request.session['employee_id']
  47.  
  48.         cursor = connection.cursor()
  49.         cursor.execute(sql,[employee_id])
  50.         result = cursor.fetchall()
  51.         cursor.close()
  52.         emp_info = []
  53.  
  54.         cursor = connection.cursor()
  55.         cursor.execute(sql_1, [employee_id])
  56.         result_1 = cursor.fetchall()
  57.         cursor.close()
  58.  
  59.         profit = result_1[0][0]
  60.  
  61.         for i in result:
  62.             name = i[1]
  63.             designation = i[2]
  64.             salary = i[3]
  65.             emp_id = employee_id
  66.             row = {'name':name,'designation':designation,'salary':salary,'emp_id':emp_id,'profit':profit}
  67.             emp_info.append(row)
  68.  
  69.         print(emp_info)
  70.         return render(request,'sales_representative_status.html',{'emp_info':emp_info})
  71.  
Advertisement
Add Comment
Please, Sign In to add comment