def renderTableSales(self, event): try: self.selected_date = self.date_entry.text print(self.selected_date) selected_date_o = datetime.datetime.strptime( self.selected_date, "%d/%m/%Y") datalist = InventoryDB() datalist = datalist.getAllSales() items = [[ "ID", "Item Name", "Date", "Quantity", "Selling Amount", "Tip", "Collected by" ]] for i in datalist: date = datetime.datetime.strptime(str(i.time[:10]), "%Y-%m-%d") if selected_date_o == date: items.append([ i.id, i.itemname, i.time[:11], i.quantity, i.amount, i.tip, i.name ]) reportstable.renderMatPlot(items) except ValueError: messagebox( title="Error", message= "Please enter a valid date. \nPlease enter the date in dd/mm/yyyy format" )
def toReadOnlyTable(self, event): # try: datalist = InventoryDB() self.layout.selected_date = self.layout.date_entry.text self.layout.to_selected_date = self.layout.to_date_entry.text datalist = datalist.getAllSales() items = [[ "Item Name", "Date", "Quantity", "Selling Amount", "Category", "Tip", "Collected by" ]] selected_date_o = datetime.datetime.strptime(self.layout.selected_date, "%d/%m/%Y") selected_date_to = datetime.datetime.strptime( self.layout.to_selected_date, "%d/%m/%Y") for i in datalist: date = datetime.datetime.strptime(str(i.time[:10]), "%Y-%m-%d") if date >= selected_date_o and date <= selected_date_to: items.append([ i.itemname, i.time[:11], i.quantity, i.amount, i.category, i.tip, i.name ]) if len(items) == 1: messagebox(title="Oops", message="No data to show") else: self.manager.add_widget( views.grid.ReadOnlyTable(dataList=items, title="Sales Details")) self.manager.current = "readonlytable"
def fetch(self, event): itembarcode = self.barcode.text if len(itembarcode) == 0: messagebox(title="Failed", message="Please enter a barcode to fetch details") return inventory_db = models.InventoryDB() record = inventory_db.getInventoryRecodeByBarcode(itembarcode) if record == []: messagebox(title="Failed", message="Item with this barcode does not exist") return record = record[0] self.id = record.id self.price.text = str(record.price) self.itemname.text = record.itemname self.label_qty.text = "Additional Qty." self.available.text = "Available: {}".format(record.quantity) self.quantity.text = str(1) self.man.text = record.manufacturer self.category_entry.text = record.category self.category = record.category self.quantity_update = str(record.quantity)
def show_tip_details(self, button): tip = {} employee = [] datalist1 = InventoryDB() msg = '' nl = '\n' total_tip = 0.0 msg_ = datalist1.getTipSummary() print(msg_) lst_keys = list(msg_.keys()) print(lst_keys) for m in lst_keys: n = str(msg_[m]) msg = msg + m + ':' + ' $' msg = msg + n msg = msg + nl total_tip += float(n) message_text = "Tip Summary\n ________________ \n" + msg + '________________\nTotal: $' + str( total_tip) messagebox(title="Sales Details", message=message_text) def back(self, event): self.manager.current = "reports" self.manager.remove_widget(self)
def setupDatabase(self): report = setupDatabase() if report == {}: messagebox("Info", "Database is already setup") else: messagebox("Info", json.dumps(report))
def fetch(self, event): itembarcode = self.barcode.text inventory_db = models.InventoryDB() record = inventory_db.getInventoryRecodeByBarcode(itembarcode) if record == []: messagebox(title="Failed", message="Item with this barcode does not exist") return record = record[0] # self.category_entry.text = record. # self.price.delete(0, END) # self.productname.delete(0, END) # self.productname.focus() # self.quantity.delete(0, END) # self.manufacturer.delete(0, END) # self.category_entry.delete(0, END) self.id = record.id self.price.text = str(record.price) self.itemname.text = record.itemname self.quantity.text = str(1) self.man.text = record.manufacturer self.category_entry.text = record.category self.category = record.category self.quantity_update = str(record.quantity)
def createTableMatPlot(dataList): if len(dataList) == 1: messagebox("No data", message="No data to show") return else: import matplotlib.pyplot as plt fig, ax = plt.subplots() # hide axes fig.patch.set_visible(False) ax.axis('off') ax.axis('auto') # df = pd.DataFrame(np.random.randn(10, 4), columns=list('ABCD')) # print(df.values) print(dataList) t = ax.table(cellText=dataList, loc='center') t.auto_set_font_size(False) t.set_fontsize(8) fig.tight_layout() plt.show()
def renderTableStock(self, event): try: selected_date = self.date_entry.text selected_date_o = datetime.datetime.strptime( selected_date, "%d/%m/%Y") datalist = InventoryDB() datalist = datalist.getInventory() items = [[ "Sl No", "Barcode", "Item Name", "Price", "Manufacturer", "Quantity", "Category" ]] for i in enumerate(datalist): items.append([ i[0] + 1, i[1].barcode, i[1].itemname, i[1].price, i[1].manufacturer, i[1].quantity, i[1].category ]) # reportstable.renderTable(items) reportstable.renderMatPlot(items) except ValueError: messagebox( title="Error", message= "Please enter a valid date. \nPlease enter the date in dd/mm/yyyy format" )
def callback2(instance): try: dateobject = datetime.datetime.strptime( self.date_entry.text, "%d/%m/%Y") except Exception: messagebox( title="Invalid date format", message= "You've entered an invalid date format.\n Please enter a date with the format dd/mm/yyyy" )
def show_sale_details(self, button): card_sales = 0.0 cash_sales = 0.0 # print(self.dataList) for d in self.dataList: if d[1] == "cash" or d[1] == "": cash_sales = cash_sales + float(d[3]) elif d[1] == "card": card_sales = card_sales + float(d[3]) total_sales = card_sales + cash_sales message_text = "By Cash : {}\n\nBy Card : {}\n\n__________________________\nTotal Sales : {}".format(cash_sales, card_sales, total_sales) messagebox(title="Sales Details", message=message_text)
def close_btn(event): print(payment_method.Flag1) print(customer_name.text, payment_method.method) if (self.mainbutton.text == 'Select Stylists'): self.sty_name = 'Reception' else: self.sty_name = self.mainbutton.text print(self.mainbutton.text) tip_ = 0 try: if (float(tip.text) and payment_method.Flag1): tip_ = float(tip.text) payment_method.total = payment_method.total + tip_ payment_method.Flag1 = False except: tip.text = "" try: self.cash_amt = float(cash_amt.text) self.card_amt = float(card_amt.text) except: if (payment_method.method == 'cash'): self.cash_amt = payment_method.total self.card_amt = 0.0 elif (payment_method.method == 'card'): self.cash_amt = 0.0 self.card_amt = payment_method.total print(payment_method.total) print(tip_) print(self.cash_amt) print(self.card_amt) print(payment_method.Flag1) if (payment_method.method == "both"): if (payment_method.total != self.cash_amt + self.card_amt): messagebox(title="Oops", message="Please check the cash and card total") payment_method.Flag2 = False else: payment_method.Flag2 = True if payment_method.Flag2: self.sellAll(customername=customer_name.text, paymentmode=payment_method.method, invoice_no=invoice_no, tip=tip_) payment_method.method = "cash" payment_method.Flag1 = True popup.dismiss()
def toTable(self, event): try: data = InventoryDB() datalist = data.getInventory() items = [[ "Sl No", "Barcode", "Item Name", "Price", "Manufacturer", "Quantity", "Category" ]] for i in enumerate(datalist): items.append([ i[0] + 1, i[1].barcode, i[1].itemname, i[1].price, i[1].manufacturer, i[1].quantity, i[1].category ]) self.manager.add_widget( views.grid.EditableTable(dataList=items, title="Stock Details")) self.manager.current = "editabletable" except TypeError: messagebox(title="Error", message="No data to show")
def update(self): # Get all the data from the text entries and update the database quantity = self.quantity.text productname = self.itemname.text category = self.category_entry.text barcode = self.barcode.text manufacturer = self.man.text price = self.price.text # print(productname,quantity, category, barcode, manufacturer, price) inventory_db = models.InventoryDB() record = inventory_db.getInventoryRecodeByBarcode(barcode) record = record[0] record.price = price record.itemname = productname record.manufacturer = manufacturer record.quantity = quantity record.save(update=True) messagebox(title="Success", message="Data updated successfully") pass
def enter_btn_pressed(instance): try: # in response of the button click barcode_ = self.barcode_text.text quantity_text = int(self.quantity_.text) if len(barcode_) == 0: messagebox(title='Warning', message="Please enter the barcode") return else: barcode_ = int(barcode_) record = InventoryDB().getInventoryRecodeByBarcode(barcode=barcode_) if len(record) == 0: messagebox(title="Error", message="No such item with {} barcode exists".format(barcode_)) return else: record = record[0] if record.quantity > quantity_text: total_price = float(record.price) * float(quantity_text) obj = {"barcode": self.bar_str, "Item Name": record.itemname, "quantity": str(self.quantity_.text), "amount": total_price} self.basket.append(obj) # label1.text = label1.text + self.bar_str + self.qty_str + '\nEntered\n' self.label1.text = self.label1.text + json.dumps(obj) + "\n" self.barcode_text.text = "" self.quantity_.text = "1" else: # send_mail(subject="Stock Update", # message="The stock for {} is finished up. Please add some stock to the inventory".format( # record.itemname)) messagebox(title="Sorry :(", message="Stock not available. The available qunatity is {} ".format( record.quantity)) except TypeError: messagebox(title="Failed", message="Quantity must be a Numeric value") except ValueError: messagebox(title="Failed", message="Quantity must be a Numeric value") except smtplib.SMTPServerDisconnected: print("Internet Not connected")
def show_sale_details(self, button): card_sales = 0.0 cash_sales = 0.0 tip = 0.0 cash_collected = 0.0 card_collected = 0.0 datalist1 = InventoryDB() datalist1 = datalist1.getAllSales() for i in datalist1: card_collected = card_collected + i.card cash_collected = cash_collected + i.cash tip = tip + i.tip # print(self.dataList) for d in self.dataList: if d[1] == "cash" or d[1] == "": cash_sales = cash_sales + float(d[3]) elif d[1] == "card": card_sales = card_sales + float(d[3]) total_sales = card_collected + cash_collected message_text = "By Cash : {}\n\nBy Card : {}\n\n__________________________\nTotal Sales : {} \nTotal Tip : {}".format( cash_collected, card_collected, total_sales, tip) messagebox(title="Sales Details", message=message_text)
def addItem_cascade(self): try: itemname = self.itemname.text itembarcode = self.barcode.text price = float(self.price.text) manufacturer = self.man.text quantity = int(self.quantity.text) quantity = int(self.quantity_update) + quantity item = models.Inventory(itemname=itemname, price=price, barcode=str(itembarcode), manufacturer=manufacturer, quantity=quantity, sold=0, id=self.id, category=self.category) saved = item.save(update=True) if saved == 1 or saved == 0: # messagebox.showinfo(title="Success", message="Item {} updated successfully".format(itemname)) popup = Popup( title='Success', content=Label( text="Item {} updated successfully".format(itemname)), size_hint=(None, None), size=(400, 400)) popup.open() self.itemname.text = "" self.barcode.text = "" self.price.text = "" self.man.text = "" self.quantity.text = "" self.available.text = "" self.label_qty.text = "Quantity" models.log(activity="Item modification", transactiontype="modify", amount=0, barcode=itembarcode, time=str(datetime.datetime.now())) else: messagebox(title="Failed", message="Nothing to update in {}".format(itemname)) except ValueError: messagebox(title="Warning", message="Price, quantity, barcode must be a Numbers") except AttributeError: messagebox( title="Oops!", message= "Seems like the item is already present in the database. \n" "Please fill in the barcode field and press \"Enter\" key to get all the details" "\nof the item and update corresponding fields")
def addItem(self, event): try: itemname = self.itemname.text itembarcode = self.barcode.text price = float(self.price.text) manufacturer = self.man.text quantity = int(self.quantity.text) item = models.Inventory(itemname=itemname, price=price, barcode=str(itembarcode), manufacturer=manufacturer, quantity=quantity, sold=0, category=self.category) saved = item.save(insert=True) if saved == 1: messagebox( title="Success", message="Item {} added successfully".format(itemname)) self.itemname.text = "" self.barcode.text = "" self.price.text = "" self.man.text = "" self.quantity.text = "" models.log(activity="Item Addition", transactiontype="additem", amount=0, barcode=itembarcode, time=str(datetime.datetime.now())) else: messagebox(title="Failed", message="Could not add {}".format(itemname)) except ValueError: messagebox(title="Warning", message="Price, quantity, barcode must be a Numbers") except pymysql.err.IntegrityError: # messagebox.showinfo(title="Error", # message="Item with same barcode cannot be added multiple times. Use update button to update the item details ") # p = Popup(title="Are you sure?", # content=Label( # text="Are you sure to overwrite the existing data for {}".format(self.itemname.text)), # size_hint=(None, None), size=(400, 200)) # p.open() # itembarcode = self.barcode.text # inventory_db = models.InventoryDB() # record = inventory_db.getInventoryRecodeByBarcode(itembarcode)[0] # self.quantity_update = str(record.quantity) # self.category_entry.text = record.category # self.category = record.category self.addItem_cascade()
def fill_price(instance): try: # in response of barcode entry barcode_ = self.barcode_text.text quantity_text = int(self.quantity_.text) if len(barcode_) == 0: messagebox(title='Warning', message="Please enter the barcode") return else: barcode_ = int(barcode_) record = InventoryDB().getInventoryRecodeByBarcode( barcode=barcode_) if len(record) == 0: messagebox( title="Error", message="No such item with {} barcode exists". format(barcode_)) return else: record = record[0] print(record.quantity >= quantity_text and record.category == "SERVICE") if record.quantity >= quantity_text or record.category == "SERVICE": total_price = float( record.price) * float(quantity_text) self.selling_price.text = str(record.price) except TypeError: messagebox(title="Failed", message="Quantity must be a Numeric value") except ValueError: messagebox(title="Failed", message="Quantity must be a Numeric value") except smtplib.SMTPServerDisconnected: print("Internet Not connected")
def sellAll(self, event): try: if len(self.basket) == 0: raise EmptyBasketError for i in self.basket: # {"barcode": self.bar_str, "Item Name": record.itemname,"quantity": str(self.quantity_.text), "amount": total_price} barcodetext = str(i["barcode"]) quantity_ = int(i["quantity"]) sellable = InventoryDB() sellable = sellable.getInventoryRecodeByBarcode(barcodetext)[0] # sellable.quantity = sellable.quantity - int(quantity_) remaining = sellable.quantity - int(quantity_) if remaining <= 0: print("Quantity not available ") continue else: sellable.quantity = sellable.quantity - int(quantity_) saved = sellable.save(update=True) sold_price = sellable.price * quantity_ sell = Sales(barcode=barcodetext, time=str(datetime.datetime.now()), quantity=quantity_, itemname=sellable.itemname, amount=sold_price, category=sellable.category) sold = sell.save(insert=True) if saved == 1 and sold == 1: messagebox(title="Success", message="Item {} of quantity {} sold successfully".format(sellable.itemname, quantity_)) self.barcode_text.text = "" log(activity="Sales", transactiontype="sale", amount=sold_price, barcode=barcodetext, time=str(datetime.datetime.now())) # self.label1.text = "" # self.basket.clear() # print(self.basket) self.label1.text = "" self.basket.clear() self.quantity_.text = "1" print(self.basket) except IndexError: messagebox(title="Failed", message="Barcode {} does not exists".format(self.barcode_text.text)) self.barcode_text.text = "" except EmptyBasketError: messagebox(title="Oops!", message="Nothing to sell")
def sellPopUp(self, event): if len(self.basket) == 0: messagebox(title="Oops", message="Nothing to sell") return class payment_method: method = "cash" total = 0 invoice_no = generateInvoiceNumber() total = 0 for s in self.basket: total = total + s["amount"] payment_method.total = total sellDialog = BoxLayout(orientation="vertical") submit = Button(size_hint=(0.2, 0.3), pos_hint={ 'x': .4, 'y': 0.2 }, text="Done") cancelbtn = Button(size_hint=(0.2, 0.2), pos_hint={'x': .8}, text="Cancel") def tipTextChange(tip): print(tip.text) try: if float(tip.text): payment_method.total = payment_method.total + float( tip.text) except: tip.text = "" tip = TextInput(size_hint=(0.4, 0.3), hint_text="Tip", multiline=False) message = "Invoice # {} \n Total Amount ${}".format( invoice_no, payment_method.total) msg_label = Label(text=message, size_hint=(None, 0.3), pos_hint={'x': .4}) customer_name = TextInput(size_hint=(1, None), hint_text="Customer Name", multiline=False) sellDialog.add_widget(cancelbtn) sellDialog.add_widget(tip) sellDialog.add_widget(customer_name) tip.bind(on_text=tipTextChange) checboxGroup = BoxLayout( orientation="horizontal", size_hint=(None, 0.3), ) cash_label = Label(text="Cash", size_hint=(None, None)) card_label = Label(text="Card", size_hint=(None, None)) cash = CheckBox(size_hint=(None, None), state="down") card = CheckBox(size_hint=(None, None)) def on_checkbox_card(checkbox, value): print(value) # cash.state = "normal" if value: payment_method.method = "card" cash.state = "normal" def on_checkbox_cash(checkbox, value): # card.state = "normal" if value: payment_method.method = "cash" card.state = "normal" card.bind(active=on_checkbox_card) cash.bind(active=on_checkbox_cash) checboxGroup.add_widget(cash_label) checboxGroup.add_widget(cash) checboxGroup.add_widget(card_label) checboxGroup.add_widget(card) sellDialog.add_widget(msg_label) sellDialog.add_widget(checboxGroup) sellDialog.add_widget(submit) popup = Popup(content=sellDialog, title="Sell Items", auto_dismiss=False, size_hint=(None, None), size=(500, 450)) popup.open() def close_btn(event): print(customer_name.text, payment_method.method) popup.dismiss() tip_ = 0 try: if float(tip.text): tip_ = float(tip.text) payment_method.total = payment_method.total + float( tip.text) except: tip.text = "" self.sellAll(customername=customer_name.text, paymentmode=payment_method.method, invoice_no=invoice_no, tip=tip_) payment_method.method = "cash" def cancel(event): popup.dismiss() submit.bind(on_press=close_btn) cancelbtn.bind(on_press=cancel) return (customer_name.text, payment_method.method)
def sellPopUp(self, event): if len(self.basket) == 0: messagebox(title="Oops", message="Nothing to sell") return class payment_method: method = "cash" total = 0 Flag1 = True Flag2 = True invoice_no = generateInvoiceNumber() total = 0 for s in self.basket: total = total + s["amount"] payment_method.total = total sellDialog = BoxLayout(orientation="vertical") submit = Button(size_hint=(0.2, 0.3), pos_hint={ 'x': .4, 'y': 0.2 }, text="Done") cancelbtn = Button(size_hint=(0.2, 0.2), pos_hint={'x': .8}, text="Cancel") tip_layout = BoxLayout(orientation="horizontal", size_hint=(1, 0.2)) stylists = Employee.getEmployeeName('x') stylist = DropDown() for index in range(len(stylists)): btn = Button(text=stylists[index], size_hint_y=None, height=44) btn.bind(on_release=lambda btn: stylist.select(btn.text)) stylist.add_widget(btn) self.mainbutton = Button(text='Select Stylists', size_hint=(0.4, 1)) self.mainbutton.bind(on_release=stylist.open) stylist.bind( on_select=lambda instance, x: setattr(self.mainbutton, 'text', x)) def tipTextChange(tip): print(tip.text) try: if float(tip.text): payment_method.total = payment_method.total + float( tip.text) except: tip.text = "" #tip_layout.remove_widget(self.mainbutton) tip = TextInput(size_hint=(0.5, 1), hint_text="Tip", multiline=False) tip_layout.add_widget(tip) tip_layout.add_widget(self.mainbutton) message = "Invoice # {} \n Total Amount ${}".format( invoice_no, payment_method.total) msg_label = Label(text=message, size_hint=(None, 0.3), pos_hint={'x': .4}) customer_name = TextInput(size_hint=(1, None), hint_text="Customer Name", multiline=False) sellDialog.add_widget(cancelbtn) sellDialog.add_widget(tip_layout) sellDialog.add_widget(customer_name) tip.bind(on_text=tipTextChange) checboxGroup = BoxLayout(orientation="horizontal", size_hint=(None, 0.3)) cash_label = Label(text="Cash", size_hint=(None, None)) card_label = Label(text="Card", size_hint=(None, None)) cash = CheckBox(size_hint=(None, None), state="down") card = CheckBox(size_hint=(None, None)) ''' def on_checkbox_card(checkbox, value): print(value) # cash.state = "normal" if value: payment_method.method = "card" cash.state = "normal" def on_checkbox_cash(checkbox, value): # card.state = "normal" if value: payment_method.method = "cash" card.state = "normal" ''' #card.bind(active=on_checkbox_card) #cash.bind(active=on_checkbox_cash) checboxGroup.add_widget(cash_label) checboxGroup.add_widget(cash) checboxGroup.add_widget(card_label) checboxGroup.add_widget(card) def pay_method(checkbox, value): if (cash.state == 'down' and card.state == 'down'): payment_method.method = "both" sellDialog.add_widget(Amount_split) elif (cash.state == 'down' and card.state == 'normal'): payment_method.method = "cash" sellDialog.remove_widget(Amount_split) elif (cash.state == 'normal' and card.state == 'down'): payment_method.method = "card" sellDialog.remove_widget(Amount_split) else: cash.state = 'down' payment_method.method = "cash" sellDialog.remove_widget(Amount_split) Amount_split = BoxLayout(orientation="horizontal", size_hint=(1, 0.2)) cash_amt = TextInput(hint_text="Cash", size_hint=(0.8, 1), multiline=False) card_amt = TextInput(hint_text="Card", size_hint=(0.8, 1), multiline=False) Amount_split.add_widget(cash_amt) Amount_split.add_widget(card_amt) card.bind(active=pay_method) cash.bind(active=pay_method) sellDialog.add_widget(msg_label) sellDialog.add_widget(checboxGroup) sellDialog.add_widget(submit, index=0) popup = Popup(content=sellDialog, title="Sell Items", auto_dismiss=False, size_hint=(None, None), size=(500, 450)) popup.open() def close_btn(event): print(payment_method.Flag1) print(customer_name.text, payment_method.method) if (self.mainbutton.text == 'Select Stylists'): self.sty_name = 'Reception' else: self.sty_name = self.mainbutton.text print(self.mainbutton.text) tip_ = 0 try: if (float(tip.text) and payment_method.Flag1): tip_ = float(tip.text) payment_method.total = payment_method.total + tip_ payment_method.Flag1 = False except: tip.text = "" try: self.cash_amt = float(cash_amt.text) self.card_amt = float(card_amt.text) except: if (payment_method.method == 'cash'): self.cash_amt = payment_method.total self.card_amt = 0.0 elif (payment_method.method == 'card'): self.cash_amt = 0.0 self.card_amt = payment_method.total print(payment_method.total) print(tip_) print(self.cash_amt) print(self.card_amt) print(payment_method.Flag1) if (payment_method.method == "both"): if (payment_method.total != self.cash_amt + self.card_amt): messagebox(title="Oops", message="Please check the cash and card total") payment_method.Flag2 = False else: payment_method.Flag2 = True if payment_method.Flag2: self.sellAll(customername=customer_name.text, paymentmode=payment_method.method, invoice_no=invoice_no, tip=tip_) payment_method.method = "cash" payment_method.Flag1 = True popup.dismiss() def cancel(event): popup.dismiss() submit.bind(on_press=close_btn) cancelbtn.bind(on_press=cancel) return (customer_name.text, payment_method.method)
def sell(self): try: # print("Sell called") barcodetext = str(self.barcode_text.text) quantity_ = int(self.quantity_.text) # print(quantity_) sellable = InventoryDB() sellable = sellable.getInventoryRecodeByBarcode(barcodetext) # print(sellable) sellable = sellable[0] if (sellable.quantity >= quantity_): sellable.quantity = sellable.quantity - quantity_ saved = sellable.save(update=True) sold_price = sellable.price * quantity_ sell = Sales(barcode=barcodetext, time=str(datetime.datetime.now()), quantity=quantity_, itemname=sellable.itemname, amount=sold_price, category=sellable.category) sold = sell.save(insert=True) if saved == 1 and sold == 1: messagebox( title="Success", message="Item {} of quantity {} sold successfully". format(sellable.itemname, quantity_)) self.barcode_text.text = "" log(activity="Sales", transactiontype="sale", amount=sold_price, barcode=barcodetext, time=str(datetime.datetime.now())) else: messagebox(title="Failed", message="Could not sell {}".format( self.barcode_text.text)) elif sellable.quantity == 0: send_mail( subject="Stock Update", message= "The stock for {} is finished up. Please add some stock to the inventory" .format(sellable.itemname)) messagebox( title="Oops..", message= "The stock is empty. A Remainder mail is sent to you") else: messagebox( title="Sorry :(", message="Stock not available. The available quantity is {} " .format(sellable.quantity)) if sellable.quantity <= config.STOCK_LIMIT: send_mail( subject="Stock Update", message= "The stock for {} is finished up. Please add some stock to the inventory" .format(sellable.itemname)) except IndexError: messagebox(title="Failed", message="Barcode {} does not exists".format( self.barcode_text.text)) except TypeError: messagebox(title="Failed", message="Barcode not provided") except smtplib.SMTPServerDisconnected: messagebox(title="Warning", message="Mailing configuration isn't setup")
def sellAll(self, customername, paymentmode, invoice_no, tip=0): try: if len(self.basket) == 0: raise EmptyBasketError for i in self.basket: # {"barcode": self.bar_str, "Item Name": record.itemname,"quantity": str(self.quantity_.text), "amount": total_price} barcodetext = str(i["barcode"]) quantity_ = int(i["quantity"]) sellable = InventoryDB() sellable = sellable.getInventoryRecodeByBarcode(barcodetext)[0] # sellable.quantity = sellable.quantity - int(quantity_) remaining = sellable.quantity - int(quantity_) if remaining < 0 and sellable.category != "SERVICE": messagebox(title="Warning", message="Quantity not available ") continue elif sellable.category == "SERVICE": sellable.quantity = 0 else: sellable.quantity = sellable.quantity - int(quantity_) saved = sellable.save(update=True) sold_price = sellable.price * quantity_ # sold_price = float(self.selling_price.text) * quantity_ sold_price = sold_price + float(tip) sell = Sales(barcode=barcodetext, time=str(datetime.datetime.now()), quantity=quantity_, itemname=sellable.itemname, amount=sold_price, category=sellable.category, invoice_no=invoice_no, customername=customername, paymentmode=paymentmode, tip=tip, cash=self.cash_amt, card=self.card_amt, name=self.sty_name) sold = sell.save(insert=True) tip = tip - tip if saved == 1 and sold == 1: # messagebox(title="Success", # message="Item {} of quantity {} sold successfully..\nTotal amount : {}".format( # sellable.itemname, # quantity_)) self.barcode_text.text = "" log(activity="Sales", transactiontype="sale", amount=sold_price, barcode=barcodetext, time=str(datetime.datetime.now())) # self.label1.text = "" # self.basket.clear() # print(self.basket) if sellable.quantity <= config.STOCK_LIMIT: try: send_mail( subject="Stock Update", message= "The stock for {} is finished up. Current available stock is {} . Please add some stock to the inventory" .format(sellable.itemname, sellable.quantity)) except smtplib.SMTPServerDisconnected: messagebox( title="Warning", message="Mailing configuration isn't setup") messagebox(title="Success", message="Order successful") self.label1.text = "" self.basket.clear() self.quantity_.text = "1" print(self.basket) except IndexError: messagebox(title="Failed", message="Barcode {} does not exists".format( self.barcode_text.text)) self.barcode_text.text = "" except EmptyBasketError: messagebox(title="Oops!", message="Nothing to sell")
def __init__(self, **kwargs): super(SearchPage, self).__init__() try: self.category = kwargs["category"] self.manufacturer_filled = kwargs["manufacturer"] self.quantity_prefilled = kwargs["pre_quantity"] root = self root.bind(size=self._update_rect, pos=self._update_rect) self.bar_str = '' self.qty_str = '' # Product name label label_qty = Label(text='Product', color=(0, 0, 0, 0.25), font_size=20, pos_hint={ 'center_x': 0.175, 'center_y': 0.9 }) root.add_widget(label_qty) # barcode label label_bar = Label(text='Barcode', color=(0, 0, 0, 0.25), font_size=20, pos_hint={ 'center_x': 0.175, 'center_y': 0.8 }) root.add_widget(label_bar) # quantity label self.label_qty = Label(text='Quantity', color=(0, 0, 0, 0.25), font_size=20, pos_hint={ 'center_x': 0.175, 'center_y': 0.7 }) root.add_widget(self.label_qty) # price label label_price = Label(text='Price', color=(0, 0, 0, 0.25), font_size=20, pos_hint={ 'center_x': 0.175, 'center_y': 0.6 }) root.add_widget(label_price) # price label label_man = Label(text='Manufacturer', color=(0, 0, 0, 0.25), font_size=20, pos_hint={ 'center_x': 0.175, 'center_y': 0.5 }) root.add_widget(label_man) # Category label label_category = Label(text="Category", color=(0, 0, 0, 0.25), font_size=20, pos_hint={ 'center_x': 0.175, 'center_y': 0.4 }) root.add_widget(label_category) # text box for Product name self.itemname = TextInput(hint_text='Name', multiline=False, pos_hint={ 'center_x': 0.5, 'center_y': 0.9 }, size_hint=(0.5, 0.075)) root.add_widget(self.itemname) # text box for barcode self.barcode = TextInput(hint_text='barcode', multiline=False, pos_hint={ 'center_x': 0.5, 'center_y': 0.8 }, size_hint=(0.5, 0.075), on_text_validate=self.fetch) self.fetch_btn = Button(text="Fetch", pos_hint={ "center_x": 0.84, 'center_y': 0.8 }, size_hint=(.15, .07), on_press=self.fetch) def on_text(instance, value): # use try to check if value in database self.bar_str = self.barcode.text self.barcode.bind(text=on_text) root.add_widget(self.barcode) root.add_widget(self.fetch_btn) # text box for quantity self.quantity = TextInput(text=self.quantity_prefilled, multiline=False, hint_text="Quantity", pos_hint={ 'center_x': 0.5, 'center_y': 0.7 }, size_hint=(0.5, 0.075)) root.add_widget(self.quantity) # Available quantity self.available = Label(text="", pos_hint={ 'center_x': 0.85, 'center_y': 0.7 }, size_hint=(0.5, 0.075), color=(0, 0, 0, 1)) root.add_widget(self.available) # text box for Price self.price = TextInput(hint_text='USD', multiline=False, pos_hint={ 'center_x': 0.5, 'center_y': 0.6 }, size_hint=(0.5, 0.075)) root.add_widget(self.price) # text box for Manufacturer self.man = TextInput(hint_text='Brand', text=self.manufacturer_filled, multiline=False, pos_hint={ 'center_x': 0.5, 'center_y': 0.5 }, size_hint=(0.5, 0.075)) root.add_widget(self.man) self.category_entry = TextInput(hint_text='Product Category', multiline=False, disabled=True, text=self.category, pos_hint={ 'center_x': 0.5, 'center_y': 0.4 }, size_hint=(0.5, 0.075)) root.add_widget(self.category_entry) # company name self.company = Button(text='<- | KAKABOKA', color=(0, 0, 0, 1), background_color=(0, 0, 0, 0), font_size=30, size_hint=(.25, .07), pos_hint={ 'center_x': 0.12, 'center_y': 0.95 }) root.add_widget(self.company) #back button #self.img=Rectangle(source='ButtonBack.png', size=root.size, pos=root.pos) #self.button_back.add_widget(self.img) # Done button self.button_home = Button(text='Home', size_hint=(0.2, 0.15), pos_hint={ 'center_x': 0.5, 'center_y': 0.2 }) root.add_widget(self.button_home) with root.canvas.before: base_folder = os.path.dirname(__file__) image_path = os.path.join(base_folder, 'background.png') self.rect = Rectangle(source=image_path, size=root.size, pos=root.pos) # return root except: messagebox(message="Category Not provided", title="Error!")