def orderitem(request): m = request.POST['menu'] t = request.POST['table'] qty = request.POST['qty'] rem = request.POST['remarks'] now = datetime.now() cur_time = now.strftime('%H:%M') time = cur_time.split(':') table = Table.objects.get(id=t) if table.occupied == 0: table.occHrs = time[0] table.occMin = time[1] table.save() table.disval = 0 if table.merged == 1: merge = MergeTable.objects.get(Q(table1_id=table.id) | Q(table2_id=table.id)) t = merge.table1.id ps = 0 ob = request.user.id form = Order(table_id=t, menu_id=m, quantity=qty, remarks=rem, printsts=ps, orderedby_id=ob, servests=0) form.save() data = Table.objects.get(id=t) data.occupied = 1 data.save() logs = RestoLogs() logs.datentime = datetime.now() logs.account = request.user logs.activity = "Ordered " + qty + " \"" + Menu.objects.get(id=m).title + "\" in table \"" + t + "\"." logs.save() messages.add_message(request, messages.SUCCESS, "Your order has been placed.") return redirect('/table-order/' + t)
def serveitem(request, id): do = Order.objects.get(pk=id) id1 = do.table.id do.servests = 1 do.save() print(do.quantity) date = datetime.today().date() todaytotalitem = TotalServedItem.objects.filter(date=date) if todaytotalitem: flag = 0 for t in todaytotalitem: if t.menu.id == do.menu.id: flag = 1 t.quantity = t.quantity + do.quantity t.save() if flag == 0: newitem = TotalServedItem(date=date, menu=do.menu, quantity=do.quantity) newitem.save() else: newitem = TotalServedItem(date=date, menu=do.menu, quantity=do.quantity) newitem.save() logs = RestoLogs() logs.datentime = datetime.now() logs.account = request.user logs.activity = "Served item \"" + Menu.objects.get( id=do.menu.id).title + "\" of Table no: " + Table.objects.get( id=id1).title logs.save() messages.add_message(request, messages.SUCCESS, "Item served successfully") return redirect('/table-order/' + str(id1))
def unserveitem(request, id): do = Order.objects.get(pk=id) id1 = do.table.id do.servests = 0 do.save() date = datetime.today().date() todaytotalitem = TotalServedItem.objects.filter(date=date) if todaytotalitem: flag = 0 for t in todaytotalitem: if t.menu.id == do.menu.id: flag = 1 t.quantity = t.quantity - do.quantity t.save() if t.quantity <= 0: t.delete() if flag == 0: messages.add_message(request, messages.ERROR, "Nothing is served today") else: messages.add_message(request, messages.ERROR, "Nothing is served today") logs = RestoLogs() logs.datentime = datetime.now() logs.account = request.user logs.activity = "Unerved item \"" + Menu.objects.get( id=do.menu.id).title + "\" of Table no: " + Table.objects.get( id=id1).title logs.save() messages.add_message(request, messages.ERROR, "Item unserved successfully") return redirect('/table-order/' + str(id1))
def additemstotable(request, id): to = int(request.POST['totalordval']) m = request.POST.getlist('orderid') qty = request.POST.getlist('orderqty') rem = request.POST.getlist('remarks') ob = request.user.id for t in range(to): form = Order(table_id=id, menu_id=m[t], quantity=qty[t], remarks=rem[t], printsts=0, orderedby_id=ob, servests=0) form.save() now1 = datetime.now() cur_time1 = now1.strftime('%H:%M') time1 = cur_time1.split(':') table = Table.objects.get(id=id) if table.occupied == 0: table.occHrs = time1[0] table.occMin = time1[1] table.occupied = 1 table.save() else: table.occupied = 1 table.save() logs = RestoLogs() logs.datentime = datetime.now() logs.account = request.user logs.activity = "Added Multiple orders at Table \"" + table.title logs.save() messages.add_message(request, messages.SUCCESS, "Your order has been placed.") return redirect('/table-order/' + str(id))
def signout(request): logs = RestoLogs() logs.datentime = datetime.now() logs.account = request.user logs.activity = "Signed out!!" logs.save() logout(request) messages.add_message(request, messages.ERROR, "You've been logged out!") return redirect('signin')
def removedis1(request, id): table = Table.objects.get(id=id) table.disval = 0 table.save() logs = RestoLogs() logs.datentime = datetime.now() logs.account = request.user logs.activity = "Removed discount of Table no: " + table.title logs.save() return redirect('/gen-tax-bill/' + str(id))
def deletetable(request, id): t = Table.objects.get(pk=id) tablename = t.title t.delete() logs = RestoLogs() logs.datentime = datetime.now() logs.account = request.user logs.activity = "Deleted Table \"" + tablename + "\"." logs.save() messages.add_message(request, messages.ERROR, "Table deleted successfully") return redirect('table')
def addTables(request): t = request.POST['title'] form = Table(title=t, occupied=0, reserved=0, merged=0, occHrs=0, occMin=0) form.save() logs = RestoLogs() logs.datentime = datetime.now() logs.account = request.user logs.activity = "Added new table \"" + t + "\"." logs.save() messages.add_message(request, messages.SUCCESS, "Table created successfully!!!") return redirect('table')
def deletefrommenucat(request, id): dm = MenuCategory.objects.get(pk=id) menucate = dm.title dm.delete() logs = RestoLogs() logs.datentime = datetime.now() logs.account = request.user logs.activity = "Deleted Menu Category \"" + menucate + "\"." logs.save() messages.add_message(request, messages.ERROR, "Item deleted successfully") return redirect('dashboard')
def addMenu(request, id): title = request.POST['title'] price = request.POST['price'] add = Menu(title=title, price=price, category_id=id) add.save() logs = RestoLogs() logs.datentime = datetime.now() logs.account = request.user logs.activity = "Added Menu Item \"" + title + "." logs.save() messages.add_message(request, messages.SUCCESS, "Menu Item added successfully") return redirect('/menu/' + str(id))
def editTable(request, id): data = Table.objects.get(pk=id) old = data.title newtitle = request.POST['newtitle'] data.title = newtitle data.save() logs = RestoLogs() logs.datentime = datetime.now() logs.account = request.user logs.activity = "Table Edited from \"" + old + "\" to \"" + newtitle + "\"." logs.save() return redirect('table')
def deletefrommenu(request, id): dm = Menu.objects.get(pk=id) itemname = dm.title id1 = dm.category.id dm.delete() logs = RestoLogs() logs.datentime = datetime.now() logs.account = request.user logs.activity = "Deleted Menu Item \"" + itemname + "\"." logs.save() messages.add_message(request, messages.ERROR, "Item deleted successfully") return redirect('/menu/' + str(id1))
def closeTable(request, id): table = Table.objects.get(pk=id) table.occupied = 0 table.occHrs = 0 table.occMin = 0 table.disval = 0 table.save() logs = RestoLogs() logs.datentime = datetime.now() logs.account = request.user logs.activity = "Closed Table " + table.title logs.save() return redirect('table')
def printbill1(request, id): disper = request.POST['disper'] if disper == '': disper = 0.0 table = Table.objects.get(id=id) table.disval = float(disper) table.save() logs = RestoLogs() logs.datentime = datetime.now() logs.account = request.user logs.activity = "Added discount \"" + disper + "%\" to Table no: " + table.title logs.save() return redirect('/gen-tax-bill/' + str(id))
def unprint(request, id): do = Order.objects.get(pk=id) id1 = do.table.id do.printsts = 0 do.save() logs = RestoLogs() logs.datentime = datetime.now() logs.account = request.user logs.activity = "Unprinted item \"" + Menu.objects.get( id=do.menu.id).title + "\" of Table no: " + Table.objects.get( id=id1).title logs.save() return redirect('/table-order/' + str(id1))
def sendAllToCBMS(request): b = BillSync.objects.filter(sync_ird=0) if b.count() != 0: serverurl = "http://103.1.92.174:9050/api/bill" headers = {'Content-Type': "application/json"} for unsyncedbills in b: bills = Bill.objects.get(id=unsyncedbills.bill_id) # print(bills) rltm = "false" payload_bill = "{\"username\":\"Test_CBMS\",\"password\":\"test@321\",\"seller_pan\":\"999999999\",\"buyer_pan\":\"123456789\",\"buyer_name\":\"\",\"fiscal_year\" : \"" + str( bills.fiscalyrs) + "\",\"invoice_number\":\"" + str(bills.billnum) + "\",\"invoice_date\":\"" + str( bills.bill_date) + "\",\"total_sales\":" + str(bills.total_amnt) + ",\"taxable_sales_vat\":" + str( bills.taxable_amnt) + ",\"vat\":" + str( bills.tax_amnt) + ",\"excisable_amount\":0,\"excise\":0,\"taxable_sales_hst\":0,\"hst\":0,\"amount_for_esf\":0,\"esf\":0,\"export_sales\":0,\"tax_exempted_sales\":0,\"isrealtime\":" + rltm + ",\"datetimeclient\":\"" + datetime.today().strftime( '%Y/%m/%d %H:%M:%S') + "\" }" # print(payload_bill) try: send_bill = requests.request("POST", serverurl, data=payload_bill, headers=headers) except requests.exceptions.RequestException as e: # print(e) messages.add_message(request, messages.ERROR, "Connection Refused!!! No Internet Connection") return redirect('report') r_bill = send_bill.json() # print(r_bill) unsyncedbills.sync_ird = 1 unsyncedbills.save() if r_bill == 200: logs = RestoLogs() logs.datentime = datetime.now() logs.account = request.user logs.activity = "Sent Multiple Bills data to CBMS." logs.save() messages.add_message(request, messages.SUCCESS, "Your data was sent successfully!!!") elif r_bill == 100: messages.add_message(request, messages.ERROR, "Error:100 - API credentials do not match !!!") elif r_bill == 101: messages.add_message(request, messages.ERROR, "Error:101 - Bill Already exists!!!") elif r_bill == 102: messages.add_message(request, messages.ERROR, "Error:102 - Exception while saving bill details, Please check model fields and values!!!") elif r_bill == 103: messages.add_message(request, messages.ERROR, "Error:103 - Unknown exceptions, Please check API URL and model fields and values !!!") elif r_bill == 104: messages.add_message(request, messages.ERROR, "Error:104 - Model invalid!!!") else: messages.add_message(request, messages.ERROR, "Internal Server Error!!!") else: messages.add_message(request, messages.ERROR, "All Bills are synced!!!") return redirect('report')
def unmergeTable(request, id): mt = MergeTable.objects.get(id=id) tbl1 = Table.objects.get(id=mt.table1.id) tbl1.merged = 0 tbl1.save() tbl2 = Table.objects.get(id=mt.table2.id) tbl2.merged = 0 tbl2.save() mt.delete() logs = RestoLogs() logs.datentime = datetime.now() logs.account = request.user logs.activity = "Unmerged Tables \"" + tbl1.title + "\" and \"" + tbl2.title + "\"." logs.save() return redirect('table')
def changeMenuCate(request, id): data = Menu.objects.get(pk=id) oldcat = data.category.title cate = request.POST['newCategory'] # print(cate,data.category_id) data.category_id = cate newcat = data.category.title data.save() logs = RestoLogs() logs.datentime = datetime.now() logs.account = request.user logs.activity = "Menu Category of \"" + data.title + "\" changed from \"" + oldcat + "\" to \"" + newcat + "\"." logs.save() # print(data.category.id) return redirect('/menu/' + str(cate))
def editMenu(request, id): data = Menu.objects.get(pk=id) id1 = data.category.id menuTitle = request.POST['title'] price = request.POST['price'] data.title = menuTitle data.price = price data.save() logs = RestoLogs() logs.datentime = datetime.now() logs.account = request.user logs.activity = "Edited menu item\"" + data.title + "\"." logs.save() messages.add_message(request, messages.SUCCESS, "Menu Update successfully") return redirect('/menu/' + str(id1))
def edituser(request): # u = request.POST['username'] first = request.POST['firstname'] last = request.POST['lastname'] user = User.objects.get(pk=request.user.id) # user.username=u user.first_name = first user.last_name = last user.save() logs = RestoLogs() logs.datentime = datetime.now() logs.account = user logs.activity = "Edited their profile information." logs.save() messages.add_message(request, messages.SUCCESS, "Your account is successfully changed!!!") return redirect('setting')
def addReservation(request): if request.user.is_staff: table = Table.objects.all() id = request.POST['table'] res = Table.objects.get(id=id) res.reserved = 1 res.save() logs = RestoLogs() logs.datentime = datetime.now() logs.account = request.user logs.activity = "Added Reservation of Table \"" + res.title + "\"." logs.save() messages.add_message(request, messages.SUCCESS, "Table - " + res.title + " is reserved") return render(request, 'reserved.html', context={'table': table}) messages.add_message(request, messages.ERROR, "Not Authorized") return redirect('table')
def editqty(request, id): data = Order.objects.get(pk=id) oldqty = data.quantity id1 = data.table.id newqty = request.POST['qty'] remarks = request.POST['remarks'] data.quantity = newqty data.remarks = remarks data.save() logs = RestoLogs() logs.datentime = datetime.now() logs.account = request.user logs.activity = "Edited quantity of item \"" + Menu.objects.get(id=data.menu.id).title + "\" from " + str( oldqty) + " to " + str(newqty) + " from " + Table.objects.get(id=id1).title logs.save() return redirect('/table-order/' + str(id1))
def printit(request, id): table = Table.objects.get(id=id) if table.merged == 1: merge = MergeTable.objects.get(Q(table1_id=table.id) | Q(table2_id=table.id)) data = Order.objects.filter(table_id=merge.table1.id, printsts=0) | Order.objects.filter( table_id=merge.table2.id, printsts=0) else: data = Order.objects.filter(table_id=id) for d in data: d.printsts = 1 d.save() logs = RestoLogs() logs.datentime = datetime.now() logs.account = request.user logs.activity = "Printed KOT/BOT" logs.save() return redirect('/table-order/' + str(id))
def sendToCBMSfromBill(request, billnum): bills = Bill.objects.get(billnum=billnum) cbmsdata = CBMSdata.objects.get(id=1) rltm = "true" serverurl = "http://103.1.92.174:9050/api/bill" payload_bill = "{\"username\":\"" + cbmsdata.cbmsusername + "\",\"password\":\"" + cbmsdata.cbmspassword + "\",\"seller_pan\":\"" + cbmsdata.sellerpan + "\",\"buyer_pan\":\"\",\"buyer_name\":\"\",\"fiscal_year\" : \"" + str( bills.fiscalyrs) + "\",\"invoice_number\":\"" + str(bills.billnum) + "\",\"invoice_date\":\"" + str( bills.bill_date) + "\",\"total_sales\":" + str(bills.total_amnt) + ",\"taxable_sales_vat\":" + str( bills.taxable_amnt) + ",\"vat\":" + str( bills.tax_amnt) + ",\"excisable_amount\":0,\"excise\":0,\"taxable_sales_hst\":0,\"hst\":0,\"amount_for_esf\":0,\"esf\":0,\"export_sales\":0,\"tax_exempted_sales\":0,\"isrealtime\":" + rltm + ",\"datetimeclient\":\"" + datetime.today().strftime( '%Y/%m/%d %H:%M:%S') + "\" }" # print(payload_bill) headers = {'Content-Type': "application/json"} try: send_bill = requests.request("POST", serverurl, data=payload_bill, headers=headers) except requests.exceptions.RequestException as e: # print(e) messages.add_message(request, messages.ERROR, "Connection Refused!!! No Internet Connection") return 0 r_bill = send_bill.json() # print(r_bill) if r_bill == 200: logs = RestoLogs() logs.datentime = datetime.now() logs.account = request.user logs.activity = "Sent Bill data to CBMS of bill no\"" + bills.billnum + "\"." logs.save() messages.add_message(request, messages.SUCCESS, "Your data was sent successfully!!!") return 1 elif r_bill == 100: messages.add_message(request, messages.ERROR, "Error:100 - API credentials do not match !!!") elif r_bill == 101: messages.add_message(request, messages.ERROR, "Error:101 - Bill Already exists!!!") elif r_bill == 102: messages.add_message(request, messages.ERROR, "Error:102 - Exception while saving bill details, Please check model fields and values!!!") elif r_bill == 103: messages.add_message(request, messages.ERROR, "Error:103 - Unknown exceptions, Please check API URL and model fields and values !!!") elif r_bill == 104: messages.add_message(request, messages.ERROR, "Error:104 - Model invalid!!!") else: messages.add_message(request, messages.ERROR, "Internal Server Error!!!") return 0
def saveEditedUser(request): if request.user.is_superuser: users = User.objects.all() for u in users: stf = request.POST['stf_' + str(u.id)] adm = request.POST['adm_' + str(u.id)] act = request.POST['act_' + str(u.id)] u.is_staff = stf u.is_superuser = adm u.is_active = act u.save() logs = RestoLogs() logs.datentime = datetime.now() logs.account = request.user logs.activity = "Edited User Permission." logs.save() return redirect('users')
def editMenuCategory(request, id): data = MenuCategory.objects.get(pk=id) oldtitle = data.title form = MenuCategoryForm(request.POST or None, request.FILES or None, instance=data) if form.is_valid(): form.save() logs = RestoLogs() logs.datentime = datetime.now() logs.account = request.user logs.activity = "Edited Menu Category from \"" + oldtitle + "\" to \"" + request.POST['title'] + "\"!!" logs.save() messages.add_message(request, messages.SUCCESS, "Category Updated successfully") return redirect('dashboard') context = { 'form': form, 'cate': data } return render(request, 'edit_menu_category.html', context)
def dash_board(request): data = MenuCategory.objects.all() form = MenuCategoryForm(request.POST or None, request.FILES or None) if form.is_valid(): form.save() logs = RestoLogs() logs.datentime = datetime.now() logs.account = request.user logs.activity = "Created a new Menu Category \"" + request.POST['title'] + "\"!!" logs.save() messages.add_message(request, messages.SUCCESS, "Menu Category \"" + request.POST['title'] + "\" created successfully!!!") return redirect('dashboard') context = { 'form': form, 'category': data } return render(request, 'dashboard.html', context)
def reset_pass_complete(request, id): user = User.objects.get(id=id) p1 = request.POST['pass1'] p2 = request.POST['pass2'] if p1 == p2: user.set_password(p1) user.save() logs = RestoLogs() logs.datentime = datetime.now() logs.account = "System" logs.activity = "Changed password of \"" + str(user) + "\"." logs.save() messages.add_message(request, messages.SUCCESS, "Your password is changed!!!") return redirect('signin') else: messages.add_message(request, messages.ERROR, "Your confirm password doesn't match!!!") context = { 'user': user } return render(request, 'reset.html', context)
def signin(request): if request.user.is_authenticated: return redirect('dashboard') if request.method == 'GET': return render(request, 'login.html') else: u = request.POST['username'] p = request.POST['password'] user = authenticate(username=u, password=p) if user is not None: login(request, user) datentime = datetime logs = RestoLogs() logs.datentime = datetime.now() logs.account = user logs.activity = "Signed in!!" logs.save() return redirect('dashboard') else: messages.add_message(request, messages.ERROR, "Your username and password doesn't match!!!") return redirect('signin')
def mergeTable(request): t1 = request.POST['tbl1'] t2 = request.POST['tbl2'] tbl1 = Table.objects.get(id=t1) tbl2 = Table.objects.get(id=t2) # order = Order.objects.filter(table_id=tbl2) # for o in order: # o.table_id = tbl1 # o.save() tbl1.merged = 1 tbl2.merged = 1 # tbl2.occupied = 0 tbl1.save() tbl2.save() merge = MergeTable(table1_id=t1, table2_id=t2) merge.save() logs = RestoLogs() logs.datentime = datetime.now() logs.account = request.user logs.activity = "Merged tables \"" + tbl1.title + "\" and \"" + tbl2.title + "\"." logs.save() return redirect('table')