abrar1

Untitled

Dec 10th, 2020
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.70 KB | None | 0 0
  1. from django.db import connection
  2. from django.shortcuts import render, redirect
  3. import customer.views as customer_view
  4.  
  5.  
  6. def load(request):
  7. if request.session.is_empty():
  8. print(111111111111111111111)
  9. return redirect(customer_view.login)
  10. else:
  11. if request.method == "POST":
  12. name = request.POST['name']
  13. phone_no = request.POST['phone_no']
  14. imei = request.POST['imei']
  15. estimated_delivery_date = request.POST['estimated_delivery_date']
  16. problem_description = request.POST['problem_description']
  17.  
  18. employee_id = request.session['employee_id']
  19.  
  20. # sql = "select IMEI_NO from PRODUCT_IMEI WHERE IMEI_NO = %s and SALE_STATUS = %s"
  21. # cursor = connection.cursor()
  22. # cursor.execute(sql, [imei, 'Y'])
  23. # result = cursor.fetchall()
  24. # cursor.close()
  25. # imei_fetched = -1
  26. # message1 = ""
  27. # message2 = ""
  28. # text = []
  29. # if not result:
  30. # print("table khali , No such product was sold")
  31. # message1 = "NO product with such ID was sold"
  32. # text.append({'message1': message1})
  33. # return render(request, "Product_Servicing_Receiving.html", {'text': text})
  34.  
  35. imei_fetched = imei
  36. message2 = ""
  37.  
  38. # check korbo warranty ase kina
  39.  
  40. sql = "select nvl((SP.WARRANTY*30 - (trunc(SYSDATE) - trunc(sa.DATE_OF_SALE))),0) FROM PRODUCT_IMEI I, " \
  41. "PRODUCT_SPECIFICATION SP, STOCK S ,SALES sa WHERE I.IMEI_NO = S.STOCK_IMEI AND " \
  42. "S.STOCK_PRODUCT_ID = SP.PRODUCT_ID and sa.PRODUCT_IMEI_NO = I.IMEI_NO and I.IMEI_NO = %s;"
  43. cursor = connection.cursor()
  44. cursor.execute(sql, [imei_fetched])
  45. result = cursor.fetchall()
  46. cursor.close()
  47.  
  48. rem_warranty_days = result[0][0]
  49.  
  50.  
  51. if rem_warranty_days <= 0:
  52. # check korbo warranty expired or not eligible
  53.  
  54. sql = "select nvl(SP.WARRANTY,%s) FROM PRODUCT_IMEI I, " \
  55. "PRODUCT_SPECIFICATION SP, STOCK S WHERE I.IMEI_NO = S.STOCK_IMEI AND " \
  56. "S.STOCK_PRODUCT_ID = SP.PRODUCT_ID and I.IMEI_NO = %s;"
  57. cursor = connection.cursor()
  58. war = -999
  59. cursor.execute(sql, [war, imei_fetched])
  60. result = cursor.fetchall()
  61. print(result[0][0])
  62. warranty_param = result[0][0]
  63. if warranty_param == war:
  64. print("Product is not eligible for warranty")
  65. message2 = "Product is not eligible for warranty"
  66. else:
  67. print("Waranty on this product is expired")
  68. message2 = "Waranty on this product is expired"
  69.  
  70. sql = "SELECT IMEI_NO FROM PRODUCT_IMEI WHERE SALE_STATUS='Y' and IMEI_NO <> " \
  71. "(select PRODUCT_IMEI_NO from CUSTOMER_SERVICE)"
  72. cursor = connection.cursor()
  73. cursor.execute(sql)
  74. table = cursor.fetchall()
  75. cursor.close()
  76. sold_imei = []
  77.  
  78. employee_id = request.session['employee_id']
  79.  
  80. for i in table:
  81. row = {'imei': i[0]}
  82. sold_imei.append(row)
  83.  
  84. return render(request, "Product_Servicing_Receiving.html", {'message2': message2, 'sold_imei': sold_imei, 'employee_id': employee_id})
  85.  
  86. # Jodi database e customer thake , toh new customer entry hobe na :
  87. sql_0 = "SELECT * FROM CUSTOMERS WHERE NAME = %s AND PHONE_NO = %s"
  88. cursor = connection.cursor()
  89. cursor.execute(sql_0, [name, phone_no])
  90. table = cursor.fetchall()
  91. cursor.close()
  92.  
  93. customer = [row[0] for row in table]
  94. if not customer:
  95. print("list is empty , taar maane customer er ager entry nai , new entry banate hobe")
  96. sql = "INSERT INTO CUSTOMERS(NAME, PHONE_NO ) VALUES(%s, %s)"
  97. cursor = connection.cursor()
  98. cursor.execute(sql, [name, phone_no])
  99. connection.commit()
  100. cursor.close()
  101. else:
  102. print("list faka na , so customer entry laagbe na")
  103.  
  104. # ekhn insert korbo .... servicing table e . receiving date pathano hoy nai
  105. print(estimated_delivery_date)
  106.  
  107. sql = "INSERT INTO CUSTOMER_SERVICE(CUSTOMER_ID, PRODUCT_IMEI_NO,DESCRIPTION, EMPLOYEE_ID) " \
  108. "VALUES((select CUSTOMER_ID from CUSTOMERS where NAME = %s and PHONE_NO = %s), %s, %s, %s)"
  109.  
  110. cursor = connection.cursor()
  111. print(name, phone_no, imei, problem_description, employee_id)
  112. cursor.execute(sql, [name, phone_no, imei, problem_description, employee_id])
  113. connection.commit()
  114. cursor.close()
  115.  
  116. return redirect(load)
  117. else:
  118. sql = "SELECT IMEI_NO FROM PRODUCT_IMEI WHERE SALE_STATUS='Y' and IMEI_NO <> " \
  119. "(select PRODUCT_IMEI_NO from CUSTOMER_SERVICE)"
  120. cursor = connection.cursor()
  121. cursor.execute(sql)
  122. table = cursor.fetchall()
  123. cursor.close()
  124. sold_imei = []
  125.  
  126. employee_id = request.session['employee_id']
  127.  
  128. for i in table:
  129. row = {'imei': i[0]}
  130. sold_imei.append(row)
  131.  
  132. return render(request, "Product_Servicing_Receiving.html",
  133. {'sold_imei': sold_imei, 'employee_id': employee_id})
Add Comment
Please, Sign In to add comment