コード例 #1
0
    def filter_product(self, event=None):
        product_name = self.filter_ety_product_name.get().strip()
        product_type = self.filter_ety_product_type.get().strip()
        product_size = self.filter_ety_product_size.get().strip()
        selling_price = str(self.filter_ety_product_sell_price.get().strip())
        if selling_price:
            selling_price = float(selling_price)
        else:
            selling_price = 0.0

        products = Product.search_products(product_name=product_name,
                                           product_type=product_type,
                                           product_size=product_size,
                                           selling_price=selling_price)
        self.products_tree.delete(*self.products_tree.get_children())
        if products:
            row_num = 0
            for product in products:
                stock = Stock.get_stock(product_code=product.product_code)

                quantity = "0"
                if stock:
                    quantity = stock.quantity

                row_num += 1
                row = (product.product_code, product.product_name,
                       product.product_type, product.product_size,
                       round(product.selling_price, 2), quantity)

                if row_num % 2 == 0:
                    if product.is_active:
                        self.products_tree.insert("",
                                                  tk.END,
                                                  values=row,
                                                  tags=('evenrow_active',
                                                        product.product_code))
                    else:
                        self.products_tree.insert("",
                                                  tk.END,
                                                  values=row,
                                                  tags=('evenrow_inactive',
                                                        product.product_code))
                else:
                    if product.is_active:
                        self.products_tree.insert("",
                                                  tk.END,
                                                  values=row,
                                                  tags=('oddrow_active',
                                                        product.product_code))
                    else:
                        self.products_tree.insert("",
                                                  tk.END,
                                                  values=row,
                                                  tags=('oddrow_inactive',
                                                        product.product_code))

            if row_num <= self.select_first_row_threshold:
                self.select_first_row()
        else:
            pass
コード例 #2
0
    def reload_report(self):
        self.filter_ety_product_name.delete(0, tk.END)
        self.filter_ety_product_type.delete(0, tk.END)

        self.tree.delete(*self.tree.get_children())

        sales = Sales.sales_report_daily()
        sl_no = 0
        for sale in sales:
            sl_no += 1
            product = Product.get_product(sale.product_code)
            rw = (sl_no, sale.sales_date, product.product_code,
                  product.product_name, product.product_type,
                  product.product_size, round(product.selling_price, 2),
                  round(product.actual_price, 2), sale.quantity,
                  round(product.selling_price * sale.quantity, 2))

            if sl_no % 2 == 0:
                self.tree.insert("",
                                 tk.END,
                                 values=rw,
                                 tags=('evenrow', product.product_code))
            else:
                self.tree.insert("",
                                 tk.END,
                                 values=rw,
                                 tags=('oddrow', product.product_code))
コード例 #3
0
def add_new_product(product_id, product_name, product_type, product_size,
                    selling_price, product_category):
    product_name = product_name
    product_type = product_type
    product_size = product_size
    selling_price = selling_price
    actual_price = selling_price
    product_category = product_category

    if product_type == "nan":
        product_type = "-"

    if product_size == "nan":
        product_size = "-"

    product_name_code = LkpProductName.get_code(product_name=product_name)
    if product_name_code is None:
        product_name_code = LkpProductName.create_lookup(
            product_name, product_category)

    product_type_code = LkpProductType.get_code(product_type=product_type)
    if product_type_code is None:
        product_type_code = LkpProductType.create_lookup(product_type)

    product_size_code = LkpProductSize.get_code(product_size=product_size)
    if product_size_code is None:
        product_size_code = LkpProductSize.create_lookup(product_size)

    product_price_code = str(int(selling_price)).zfill(4)
    product_code = f"{product_name_code}-{product_type_code}-{product_size_code}-{product_price_code}"

    product = (product_code, product_name, product_type, product_size,
               selling_price, actual_price)

    product_list = Product.search_products(product_code, product_name,
                                           product_type, product_size,
                                           selling_price)
    if product_list:
        print(f"Product: '{product}' is already exists!")
    else:
        Product.add_product(product)
        print(f"{product_id}, {product_code}")
        return f"{product_id}, {product_code}"
コード例 #4
0
    def add_to_purchase_list(self, event):
        quantity = self.var_quantity.get()

        self.selected_row = event.widget.selection()
        product = self.products_tree.item(self.selected_row)['values']

        active_product = Product.get_product_status(product_code=product[0])
        if not active_product:
            msg_box = messagebox.askquestion(
                "SS Fashion Tuty",
                "In-Active product! - Do you want to activate this Product?",
                icon='question')
            if msg_box == 'yes':
                Product.activate_product(product_code=product[0])
                self.reload_products()
            else:
                return

        for child in self.purchase_tree.get_children():
            if self.purchase_tree.item(child)["values"][1] == product[0]:
                prev_quantity = self.purchase_tree.item(child)["values"][6]
                price = self.purchase_tree.item(child)["values"][5]

                quantity += prev_quantity
                self.purchase_tree.set(child, "#7", quantity)
                self.purchase_tree.set(child, "#8", float(price) * quantity)

                break
        else:
            self.purchase_counter = self.purchase_counter + 1
            row = (self.purchase_counter, product[0], product[1], product[2],
                   product[3], round(float(product[4]), 2), quantity,
                   round(float(product[4]), 2) * quantity)

            self.purchase_tree.insert("", tk.END, values=row)

        self.calculate_total_amount_and_quantity()

        if len(self.products_tree.selection()) > 0:
            self.products_tree.selection_remove(
                self.products_tree.selection()[0])
コード例 #5
0
    def reload_products(self):
        self.cbo_product_category.delete(0, "end")
        self.filter_ety_product_name.delete(0, tk.END)
        self.filter_ety_product_type.delete(0, tk.END)
        self.filter_ety_product_size.delete(0, tk.END)
        self.filter_ety_product_sell_price.delete(0, tk.END)

        self.products_tree.delete(*self.products_tree.get_children())

        products = Product.get_all_products()
        row_num = 0
        for product in products:
            row_num += 1

            stock = Stock.get_stock(product_code=product.product_code)
            quantity = "0"
            if stock:
                quantity = stock.quantity

            row = (product.product_code, product.product_name,
                   product.product_type, product.product_size,
                   round(product.selling_price, 2), quantity)

            if row_num % 2 == 0:
                if product.is_active:
                    self.products_tree.insert("",
                                              tk.END,
                                              values=row,
                                              tags=('evenrow_active',
                                                    product.product_code))
                else:
                    self.products_tree.insert("",
                                              tk.END,
                                              values=row,
                                              tags=('evenrow_inactive',
                                                    product.product_code))
            else:
                if product.is_active:
                    self.products_tree.insert("",
                                              tk.END,
                                              values=row,
                                              tags=('oddrow_active',
                                                    product.product_code))
                else:
                    self.products_tree.insert("",
                                              tk.END,
                                              values=row,
                                              tags=('oddrow_inactive',
                                                    product.product_code))
コード例 #6
0
    def reload_lookup(self):
        garments = Purchase.get_all_garment_name()
        for garment in garments:
            self.garment_list.append(garment.garment_name)

        products = LkpProductName.get_all_product_names()
        for product in products:
            self.product_name_list.append(product.product_name)

        products = LkpProductType.get_all_product_types()
        for product in products:
            self.product_type_list.append(product.product_type)

        products = LkpProductSize.get_all_product_sizes()
        for product in products:
            self.product_size_list.append(product.product_size)

        products = Product.get_product_sell_price_list()
        for product in products:
            self.product_sell_price_list.append(str(round(product.selling_price, 2)))
コード例 #7
0
    def add_to_selected_list(self, event):
        quantity = self.var_quantity.get()

        self.selected_row = event.widget.selection()
        product = self.products_tree.item(self.selected_row)['values']

        active_product = Product.get_product_status(product_code=product[0])
        if not active_product:
            msg_box = messagebox.askquestion(
                "SS Fashion Tuty",
                "In-Active product! - Do you want to add this Product to selected list?",
                icon='question')
            if msg_box == 'no':
                return

        for child in self.selected_products_tree.get_children():
            if self.selected_products_tree.item(
                    child)["values"][1] == product[0]:
                prev_quantity = self.selected_products_tree.item(
                    child)["values"][6]

                quantity += prev_quantity
                self.selected_products_tree.set(child, "#7", quantity)

                break
        else:
            self.selected_products_counter = self.selected_products_counter + 1
            row = (self.selected_products_counter, product[0], product[1],
                   product[2], product[3], product[4], quantity)

            self.selected_products_tree.insert("", tk.END, values=row)

        self.calculate_total_amount_and_sheet()

        if len(self.products_tree.selection()) > 0:
            self.products_tree.selection_remove(
                self.products_tree.selection()[0])
コード例 #8
0
    def load_generate_tag_purchase_form(self):
        for index in range(1, 9):
            self.menubar.entryconfig(index, state=tk.DISABLED)

        self.show_menu(MainForm.is_admin_user)
        self.update_username()

        products = LkpProductName.get_all_product_names()
        for product in products:
            self.product_name_list.append(product.product_name)

        products = LkpProductType.get_all_product_types()
        for product in products:
            self.product_type_list.append(product.product_type)

        products = LkpProductSize.get_all_product_sizes()
        for product in products:
            self.product_size_list.append(product.product_size)

        products = Product.get_product_sell_price_list()
        for product in products:
            self.product_sell_price_list.append(
                str(round(product.selling_price, 2)))

        # ********** Sub Containers *********
        left_container = tk.Frame(self.content_container,
                                  bd=5,
                                  padx=5,
                                  pady=2,
                                  relief=tk.RIDGE,
                                  bg=self.clr_yellow)
        left_container.pack(fill='both', expand=True, side=tk.LEFT)

        right_container = tk.Frame(self.content_container,
                                   bd=5,
                                   padx=5,
                                   pady=5,
                                   relief=tk.RIDGE,
                                   bg=self.clr_yellow)
        right_container.pack(fill='both', expand=True, side=tk.RIGHT)

        # left_container elements
        left_top_button_container = tk.Frame(left_container,
                                             relief=tk.RIDGE,
                                             bg=self.clr_yellow)
        left_top_button_container.pack(fill='both', expand=True, side=tk.TOP)

        products_tree_container = tk.Frame(left_container,
                                           pady=3,
                                           bg=self.clr_yellow,
                                           relief=tk.RIDGE)
        products_tree_container.pack(fill='both', expand=True, side=tk.TOP)

        # right_container elements
        right_top_button_container = tk.Frame(right_container,
                                              relief=tk.RIDGE,
                                              bg=self.clr_yellow)
        right_top_button_container.pack(fill='both', expand=True, side=tk.TOP)

        right_tree_container = tk.Frame(right_container,
                                        relief=tk.RIDGE,
                                        bg=self.clr_yellow)
        right_tree_container.pack(fill='both', expand=True, side=tk.TOP)

        right_bottom_container = tk.Frame(right_container,
                                          relief=tk.RIDGE,
                                          bg=self.clr_yellow)
        right_bottom_container.pack(fill='both', expand=True, side=tk.TOP)

        # ********** left_search_container elements *********
        filter_lbl_product_name = tk.Label(left_top_button_container,
                                           text="Name: ",
                                           bg=self.clr_yellow)
        filter_lbl_product_name.grid(row=0,
                                     column=0,
                                     sticky="nw",
                                     padx=1,
                                     pady=1)
        self.filter_ety_product_name = AutocompleteEntry(
            left_top_button_container,
            width=15,
            completevalues=self.product_name_list)
        self.filter_ety_product_name.grid(row=1,
                                          column=0,
                                          sticky="nw",
                                          padx=2,
                                          pady=1,
                                          ipady=6)
        self.filter_ety_product_name.bind(
            "<Return>", lambda event: self.filter_product(event))

        filter_lbl_product_type = tk.Label(left_top_button_container,
                                           text="Type: ",
                                           bg=self.clr_yellow)
        filter_lbl_product_type.grid(row=0,
                                     column=1,
                                     sticky="nw",
                                     padx=1,
                                     pady=1)
        self.filter_ety_product_type = AutocompleteEntry(
            left_top_button_container,
            width=18,
            completevalues=self.product_type_list)
        self.filter_ety_product_type.grid(row=1,
                                          column=1,
                                          sticky="nw",
                                          padx=2,
                                          pady=1,
                                          ipady=6)
        self.filter_ety_product_type.bind(
            "<Return>", lambda event: self.filter_product(event))

        filter_lbl_product_size = tk.Label(left_top_button_container,
                                           text="Size: ",
                                           bg=self.clr_yellow)
        filter_lbl_product_size.grid(row=0,
                                     column=2,
                                     sticky="nw",
                                     padx=1,
                                     pady=1)
        self.filter_ety_product_size = AutocompleteEntry(
            left_top_button_container,
            width=12,
            completevalues=self.product_size_list)
        self.filter_ety_product_size.grid(row=1,
                                          column=2,
                                          sticky="nw",
                                          padx=2,
                                          pady=1,
                                          ipady=6)
        self.filter_ety_product_size.bind(
            "<Return>", lambda event: self.filter_product(event))

        filter_lbl_product_price = tk.Label(left_top_button_container,
                                            text="Sell Price: ",
                                            bg=self.clr_yellow)
        filter_lbl_product_price.grid(row=0,
                                      column=3,
                                      sticky="nw",
                                      padx=1,
                                      pady=1)
        self.filter_ety_product_sell_price = AutocompleteEntry(
            left_top_button_container,
            width=8,
            completevalues=self.product_sell_price_list)
        self.filter_ety_product_sell_price.grid(row=1,
                                                column=3,
                                                sticky="nw",
                                                padx=2,
                                                pady=1,
                                                ipady=6)
        self.filter_ety_product_sell_price.bind(
            "<Return>", lambda event: self.filter_product(event))

        # filter_lbl_product_actual_price = tk.Label(left_top_button_container, text="Act. Price: ", bg=self.clr_yellow)
        # filter_lbl_product_actual_price.grid(row=0, column=4, sticky="nw", padx=1, pady=1)
        # self.filter_ety_product_actual_price = AutocompleteEntry(left_top_button_container, width=8,
        #                                                          completevalues=self.product_actual_price_list)
        # self.filter_ety_product_actual_price.grid(row=1, column=4, sticky="nw", padx=2, pady=1, ipady=6)
        # self.filter_ety_product_actual_price.bind("<Return>", lambda event: self.filter_product(event))

        btn_filter = tk.Button(left_top_button_container,
                               text="Apply Filter [F5]",
                               bg=self.clr_fuchsia,
                               fg='white',
                               command=self.filter_product)
        btn_filter.grid(row=1, column=4, sticky="news", padx=2, pady=1)

        btn_clear_filter = tk.Button(left_top_button_container,
                                     text="Clear",
                                     command=self.reload_products)
        btn_clear_filter.grid(row=1, column=5, sticky="news", padx=2, pady=1)

        # ********** tree_containers elements *********
        header = ('CODE', 'PRODUCT_NAME', 'PRODUCT_TYPE', 'SIZE', 'PRICE',
                  'QTY', '')
        self.products_tree = ttk.Treeview(products_tree_container,
                                          columns=header,
                                          height=20,
                                          show="headings",
                                          selectmode="browse")
        vsb = ttk.Scrollbar(products_tree_container,
                            orient="vertical",
                            command=self.products_tree.yview)
        hsb = ttk.Scrollbar(products_tree_container,
                            orient="horizontal",
                            command=self.products_tree.xview)

        style = ttk.Style()
        style.configure("Treeview.Heading", font=('Calibri', 12))
        style.configure("Treeview", font=('Calibri', 10), rowheight=25)

        self.products_tree.configure(yscrollcommand=vsb.set,
                                     xscrollcommand=hsb.set)
        self.products_tree.grid(column=0,
                                row=0,
                                sticky='nsew',
                                in_=products_tree_container)

        vsb.grid(column=1, row=0, sticky='ns', in_=products_tree_container)
        hsb.grid(column=0, row=1, sticky='ew', in_=products_tree_container)

        products_tree_container.grid_columnconfigure(0, weight=1)
        products_tree_container.grid_rowconfigure(0, weight=1)

        self.products_tree.heading("0", text="CODE")
        self.products_tree.heading("1", text="PRODUCT_NAME")
        self.products_tree.heading("2", text="PRODUCT_TYPE")
        self.products_tree.heading("3", text="SIZE")
        self.products_tree.heading("4", text="PRICE")
        self.products_tree.heading("5", text="QTY")

        self.products_tree.column(0, anchor='center', width="100")
        self.products_tree.column(1, anchor=tk.W, width="120")
        self.products_tree.column(2, anchor=tk.W, width="150")
        self.products_tree.column(3, anchor='center', width="50")
        self.products_tree.column(4, anchor=tk.E, width="50")
        self.products_tree.column(5, anchor='center', width="20")
        self.products_tree.column(6, anchor='center', width="1")

        self.reload_products()

        numeric_cols = ['PRICE', 'QTY']
        for col in header:
            if col in numeric_cols:
                self.products_tree.heading(col,
                                           text=col,
                                           command=lambda _col=col: self.
                                           sort_treeview(self.products_tree,
                                                         _col,
                                                         numeric_sort=True,
                                                         reverse=False))
            else:
                self.products_tree.heading(col,
                                           text=col,
                                           command=lambda _col=col: self.
                                           sort_treeview(self.products_tree,
                                                         _col,
                                                         numeric_sort=False,
                                                         reverse=False))

        # ********** Right Tree Details *********
        lbl_selected_quantity = tk.Label(right_top_button_container,
                                         text="Quantity:",
                                         bg=self.clr_yellow)
        lbl_selected_quantity.grid(row=0,
                                   column=0,
                                   rowspan=2,
                                   sticky="se",
                                   padx=2,
                                   pady=1)
        lbl_selected_quantity.config(font=("calibri bold", 18))

        ety_selected_quantity = tk.Entry(
            right_top_button_container,
            width=5,
            textvariable=self.var_selected_quantity,
            disabledbackground=self.clr_limegreen,
            disabledforeground="white",
            justify=tk.CENTER,
            state='disabled')
        ety_selected_quantity.grid(row=0,
                                   column=1,
                                   rowspan=2,
                                   sticky="se",
                                   padx=2,
                                   pady=1)
        ety_selected_quantity.config(font=("calibri bold", 18))

        btn_generate_tag = tk.Button(right_top_button_container,
                                     text="Generate Tag",
                                     bg=self.clr_fuchsia,
                                     fg='white',
                                     command=self.generate_tag)
        btn_generate_tag.grid(row=0,
                              column=2,
                              rowspan=2,
                              sticky="se",
                              padx=2,
                              pady=1)

        btn_clear = tk.Button(right_top_button_container,
                              text="Clear",
                              command=self.clear_all)
        btn_clear.grid(row=0, column=3, rowspan=2, sticky="se", padx=2, pady=1)

        purchase_tree_container = tk.Frame(right_tree_container,
                                           pady=1,
                                           relief=tk.RIDGE,
                                           bg=self.clr_yellow)
        purchase_tree_container.pack(fill='both', expand=True, side=tk.RIGHT)

        header = ('#', 'product_code', 'product_name', 'type', 'size',
                  'selling_price', 'quantity', 'dummy')
        self.selected_products_tree = ttk.Treeview(purchase_tree_container,
                                                   columns=header,
                                                   height=10,
                                                   show="headings",
                                                   selectmode="browse")
        vsb = ttk.Scrollbar(purchase_tree_container,
                            orient="vertical",
                            command=self.selected_products_tree.yview)
        hsb = ttk.Scrollbar(purchase_tree_container,
                            orient="horizontal",
                            command=self.selected_products_tree.xview)

        self.selected_products_tree.configure(yscrollcommand=vsb.set,
                                              xscrollcommand=hsb.set)
        self.selected_products_tree.grid(column=0, row=0, sticky='nsew')

        vsb.grid(column=1, row=0, sticky='ns')
        hsb.grid(column=0, row=1, sticky='ew')

        purchase_tree_container.grid_columnconfigure(0, weight=1)
        purchase_tree_container.grid_rowconfigure(0, weight=1)

        self.selected_products_tree.heading("0", text="#")
        self.selected_products_tree.heading("1", text="Code")
        self.selected_products_tree.heading("2", text="Product")
        self.selected_products_tree.heading("3", text="Type")
        self.selected_products_tree.heading("4", text="Size")
        self.selected_products_tree.heading("5", text="Price")
        self.selected_products_tree.heading("6", text="Qty")
        self.selected_products_tree.heading("7", text="")

        self.selected_products_tree.column(0,
                                           anchor='center',
                                           minwidth=25,
                                           width=25)
        self.selected_products_tree.column(1,
                                           anchor=tk.W,
                                           minwidth=40,
                                           width=110)
        self.selected_products_tree.column(2,
                                           anchor=tk.W,
                                           minwidth=80,
                                           width=100)  # Product
        self.selected_products_tree.column(3,
                                           anchor=tk.W,
                                           minwidth=110,
                                           width=110)  # Type
        self.selected_products_tree.column(4,
                                           anchor='center',
                                           minwidth=50,
                                           width=50)  # Size
        self.selected_products_tree.column(5,
                                           anchor=tk.E,
                                           minwidth=50,
                                           width=50)  # Price
        self.selected_products_tree.column(6,
                                           anchor='center',
                                           minwidth=40,
                                           width=40)  # Qty
        self.selected_products_tree.column(7, anchor='center', width=1)
        self.selected_products_tree["displaycolumns"] = (0, 1, 2, 3, 4, 5, 6,
                                                         7)
        self.selected_products_tree.bind(
            '<Double-1>', lambda event: self.remove_product(event))

        self.products_tree.tag_configure("evenrow_active",
                                         background='#fbefcc')
        self.products_tree.tag_configure("oddrow_active",
                                         background='white',
                                         foreground='black')
        self.products_tree.tag_configure("evenrow_inactive",
                                         background='#fbefcc',
                                         foreground='red')
        self.products_tree.tag_configure("oddrow_inactive",
                                         background='white',
                                         foreground='red')

        self.products_tree.bind('<<TreeviewSelect>>', self.on_tree_select)
        self.products_tree.bind('<Double-1>',
                                lambda event: self.get_quantity(event))
        self.products_tree.bind('<Return>',
                                lambda event: self.get_quantity(event))

        # ********** bottom_container elements *********
        image_container = tk.Frame(right_bottom_container,
                                   pady=1,
                                   bd=5,
                                   relief=tk.RIDGE,
                                   bg=self.clr_yellow)
        image_container.pack(fill='both', expand=True, side=tk.TOP)

        img = ImageTk.PhotoImage(
            Image.open(f"images/Sample.png").resize((250, 250),
                                                    Image.ANTIALIAS))
        # img = ImageTk.PhotoImage(Image.open(f"images/Sample.png"))
        self.image_label = tk.Label(image_container,
                                    image=img,
                                    bg=self.clr_yellow)
        self.image_label.image = img
        self.image_label.pack(side="bottom", fill="both", expand="yes")
コード例 #9
0
    def load_view_sales_form(self):
        for index in range(1, 9):
            self.menubar.entryconfig(index, state=tk.DISABLED)

        self.show_menu(MainForm.is_admin_user)
        self.update_username()

        products = Product.get_product_name_list()
        for product in products:
            self.product_name_list.append(product.product_name)

        products = Product.get_product_type_list()
        for product in products:
            self.product_type_list.append(product.product_type)

        products = Product.get_product_size_list()
        for product in products:
            self.product_size_list.append(product.product_size)

        products = Product.get_product_sell_price_list()
        for product in products:
            self.product_sell_price_list.append(
                str(round(product.selling_price, 2)))

        bills = Sales.get_bill_number_list()
        for bill in bills:
            self.billno_list.append(str(bill.bill_number))

        # ********** Sub Containers *********
        left_container = tk.Frame(self.content_container,
                                  bd=5,
                                  padx=2,
                                  pady=2,
                                  relief=tk.RIDGE,
                                  bg=self.clr_yellow)
        left_container.pack(fill='both', expand=True, side=tk.LEFT)

        right_container = tk.Frame(self.content_container,
                                   padx=2,
                                   relief=tk.RIDGE,
                                   bg=self.clr_yellow)
        right_container.pack(fill='both', expand=True, side=tk.RIGHT)

        # left_container main elements
        button_container = tk.Frame(left_container,
                                    padx=2,
                                    pady=2,
                                    relief=tk.RIDGE,
                                    bg=self.clr_yellow)
        button_container.pack(fill='both', expand=True, side=tk.TOP)

        sales_tree_container = tk.Frame(left_container,
                                        padx=2,
                                        pady=2,
                                        relief=tk.RIDGE,
                                        bg=self.clr_yellow)
        sales_tree_container.pack(fill='both', expand=True, side=tk.TOP)

        # button_container
        date_container = tk.Frame(button_container,
                                  bd=2,
                                  relief=tk.RIDGE,
                                  bg=self.clr_yellow)
        date_container.pack(fill='both', expand=True, anchor='w', side=tk.LEFT)

        name_filter_container = tk.Frame(button_container,
                                         bd=2,
                                         relief=tk.RIDGE,
                                         bg=self.clr_yellow)
        name_filter_container.pack(fill='both',
                                   expand=True,
                                   anchor='w',
                                   side=tk.TOP)

        code_filter_container = tk.Frame(button_container,
                                         bd=2,
                                         relief=tk.RIDGE,
                                         bg=self.clr_yellow)
        code_filter_container.pack(fill='both',
                                   expand=True,
                                   anchor='w',
                                   side=tk.LEFT)

        billno_filter_container = tk.Frame(button_container,
                                           bd=2,
                                           relief=tk.RIDGE,
                                           bg=self.clr_yellow)
        billno_filter_container.pack(fill='both',
                                     expand=True,
                                     anchor='w',
                                     side=tk.RIGHT)

        # ********** button_container elements *********
        date_container.grid_rowconfigure(0, weight=1)
        date_container.grid_rowconfigure(6, weight=1)

        date_container.grid_columnconfigure(0, weight=1)
        date_container.grid_columnconfigure(2, weight=1)

        lbl_from_date = tk.Label(date_container,
                                 text='From Date: ',
                                 bg=self.clr_yellow)
        lbl_from_date.grid(row=1, column=1, sticky="nw", padx=1, pady=1)
        self.from_date = DateEntry(date_container,
                                   date_pattern='yyyy-mm-dd',
                                   background='yellow',
                                   foreground='black',
                                   borderwidth=2,
                                   width=10)
        self.from_date.grid(row=2,
                            column=1,
                            sticky="sw",
                            padx=2,
                            pady=1,
                            ipady=3)

        lbl_to_date = tk.Label(date_container,
                               text='To Date: ',
                               bg=self.clr_yellow)
        lbl_to_date.grid(row=3, column=1, sticky="nw", padx=1, pady=1)
        self.to_date = DateEntry(date_container,
                                 date_pattern='yyyy-mm-dd',
                                 background='yellow',
                                 foreground='black',
                                 borderwidth=2,
                                 width=10)
        self.to_date.grid(row=4,
                          column=1,
                          sticky="sw",
                          padx=2,
                          pady=1,
                          ipady=3)

        include_date = tk.Checkbutton(date_container,
                                      text='Include Date',
                                      variable=self.var_chk_include_date,
                                      onvalue=1,
                                      offvalue=0,
                                      bg=self.clr_yellow)
        include_date.grid(row=5, column=1, sticky="sw", padx=2, pady=1)

        # name_filter_container elements
        name_filter_container.grid_rowconfigure(0, weight=1)
        name_filter_container.grid_rowconfigure(3, weight=1)

        name_filter_container.grid_columnconfigure(0, weight=1)
        name_filter_container.grid_columnconfigure(7, weight=1)

        filter_lbl_product_name = tk.Label(name_filter_container,
                                           text="Name: ",
                                           bg=self.clr_yellow)
        filter_lbl_product_name.grid(row=1,
                                     column=1,
                                     sticky="nw",
                                     padx=1,
                                     pady=1)
        self.ety_filter_product_name = AutocompleteEntry(
            name_filter_container,
            width=15,
            completevalues=self.product_name_list)
        self.ety_filter_product_name.grid(row=2,
                                          column=1,
                                          sticky="nw",
                                          padx=2,
                                          pady=1,
                                          ipady=6)
        self.ety_filter_product_name.bind(
            "<Return>", lambda event: self.filter_product(event))

        filter_lbl_product_type = tk.Label(name_filter_container,
                                           text="Type: ",
                                           bg=self.clr_yellow)
        filter_lbl_product_type.grid(row=1,
                                     column=2,
                                     sticky="nw",
                                     padx=1,
                                     pady=1)
        self.ety_filter_product_type = AutocompleteEntry(
            name_filter_container,
            width=20,
            completevalues=self.product_type_list)
        self.ety_filter_product_type.grid(row=2,
                                          column=2,
                                          sticky="nw",
                                          padx=2,
                                          pady=1,
                                          ipady=6)
        self.ety_filter_product_type.bind(
            "<Return>", lambda event: self.filter_product(event))

        filter_lbl_product_size = tk.Label(name_filter_container,
                                           text="Size: ",
                                           bg=self.clr_yellow)
        filter_lbl_product_size.grid(row=1,
                                     column=3,
                                     sticky="nw",
                                     padx=1,
                                     pady=1)
        self.ety_filter_product_size = AutocompleteEntry(
            name_filter_container,
            width=8,
            completevalues=self.product_size_list)
        self.ety_filter_product_size.grid(row=2,
                                          column=3,
                                          sticky="nw",
                                          padx=2,
                                          pady=1,
                                          ipady=6)
        self.ety_filter_product_size.bind(
            "<Return>", lambda event: self.filter_product(event))

        filter_lbl_product_price = tk.Label(name_filter_container,
                                            text="Price: ",
                                            bg=self.clr_yellow)
        filter_lbl_product_price.grid(row=1,
                                      column=4,
                                      sticky="nw",
                                      padx=1,
                                      pady=1)
        self.ety_filter_product_sell_price = AutocompleteEntry(
            name_filter_container,
            width=8,
            completevalues=self.product_sell_price_list)
        self.ety_filter_product_sell_price.grid(row=2,
                                                column=4,
                                                sticky="nw",
                                                padx=2,
                                                pady=1,
                                                ipady=6)
        self.ety_filter_product_sell_price.bind(
            "<Return>", lambda event: self.filter_product(event))

        btn_filter = tk.Button(name_filter_container,
                               text="Apply Filter",
                               bg=self.clr_fuchsia,
                               fg='white',
                               command=self.filter_product)
        btn_filter.grid(row=2, column=5, sticky="sw", padx=2, pady=1)

        btn_clear_filter = tk.Button(name_filter_container,
                                     text="Clear Filter",
                                     command=self.reload_sales)
        btn_clear_filter.grid(row=2, column=6, sticky="news", padx=2, pady=1)

        code_filter_container.grid_rowconfigure(0, weight=1)
        code_filter_container.grid_rowconfigure(3, weight=1)
        code_filter_container.grid_columnconfigure(0, weight=1)
        code_filter_container.grid_columnconfigure(7, weight=1)

        lbl_search_product_code = tk.Label(code_filter_container,
                                           text="Product Code: ",
                                           bg=self.clr_yellow)
        lbl_search_product_code.grid(row=1,
                                     column=1,
                                     columnspan=3,
                                     sticky="nw",
                                     padx=1,
                                     pady=1)

        self.ety_filter_product_code_1 = MaxLengthEntry(
            code_filter_container,
            maxlength=3,
            width=4,
            textvariable=self.var_search_product_code_1)
        self.ety_filter_product_code_1.grid(row=2,
                                            column=1,
                                            sticky="nw",
                                            padx=2,
                                            pady=2,
                                            ipady=5)
        self.ety_filter_product_code_1.bind(
            '<Return>', lambda event: self.validate_entry(event, 3))

        self.ety_filter_product_code_2 = MaxLengthEntry(
            code_filter_container,
            maxlength=3,
            width=4,
            textvariable=self.var_search_product_code_2)
        self.ety_filter_product_code_2.grid(row=2,
                                            column=2,
                                            sticky="nw",
                                            padx=2,
                                            pady=2,
                                            ipady=5)
        self.ety_filter_product_code_2.bind(
            '<Return>', lambda event: self.validate_entry(event, 3))

        self.ety_filter_product_code_3 = MaxLengthEntry(
            code_filter_container,
            maxlength=2,
            width=3,
            textvariable=self.var_search_product_code_3)
        self.ety_filter_product_code_3.grid(row=2,
                                            column=3,
                                            sticky="nw",
                                            padx=2,
                                            pady=2,
                                            ipady=5)
        self.ety_filter_product_code_3.bind(
            '<Return>', lambda event: self.validate_entry(event, 2))

        self.ety_filter_product_code_4 = MaxLengthEntry(
            code_filter_container,
            maxlength=4,
            width=5,
            textvariable=self.var_search_product_code_4)
        self.ety_filter_product_code_4.grid(row=2,
                                            column=4,
                                            sticky="nw",
                                            padx=2,
                                            pady=2,
                                            ipady=5)
        self.ety_filter_product_code_4.bind(
            '<Return>', lambda event: self.validate_entry(event, 4))

        btn_filter_product_code = tk.Button(code_filter_container,
                                            text="Apply Filter",
                                            bg=self.clr_fuchsia,
                                            fg='white',
                                            command=self.filter_product_code)
        btn_filter_product_code.grid(row=2,
                                     column=5,
                                     sticky="sw",
                                     padx=2,
                                     pady=1)
        btn_filter_product_code.bind(
            '<Return>', lambda event: self.filter_product_code(event))

        btn_clear_filter = tk.Button(code_filter_container,
                                     text="Clear Filter",
                                     command=self.reload_sales)
        btn_clear_filter.grid(row=2, column=6, sticky="news", padx=2, pady=1)

        # billno_filter_container elements
        billno_filter_container.grid_rowconfigure(0, weight=1)
        billno_filter_container.grid_rowconfigure(3, weight=1)
        billno_filter_container.grid_columnconfigure(0, weight=1)
        billno_filter_container.grid_columnconfigure(4, weight=1)

        filter_lbl_bill_number = tk.Label(billno_filter_container,
                                          text="Bill No: ",
                                          bg=self.clr_yellow)
        filter_lbl_bill_number.grid(row=1,
                                    column=1,
                                    sticky="nw",
                                    padx=1,
                                    pady=1)
        self.ety_filter_bill_number = AutocompleteEntry(
            billno_filter_container, width=8, completevalues=self.billno_list)
        self.ety_filter_bill_number.grid(row=2,
                                         column=1,
                                         sticky="nw",
                                         padx=2,
                                         pady=1,
                                         ipady=6)
        self.ety_filter_bill_number.bind(
            "<Return>", lambda event: self.filter_bill_number(event))

        btn_apply_filter = tk.Button(billno_filter_container,
                                     text="Apply Filter",
                                     bg=self.clr_fuchsia,
                                     fg='white',
                                     command=self.filter_bill_number)
        btn_apply_filter.grid(row=2, column=2, sticky="news", padx=2, pady=1)
        btn_apply_filter.bind('<Return>',
                              lambda event: self.filter_bill_number(event))

        btn_clear_filter = tk.Button(billno_filter_container,
                                     text="Clear Filter",
                                     command=self.reload_sales)
        btn_clear_filter.grid(row=2, column=3, sticky="news", padx=2, pady=1)

        # ********** tree_containers elements *********
        header = ('SALES_DATE', 'BILL_NO', 'PRODUCT_CODE', 'PRODUCT_NAME',
                  'PRODUCT_TYPE', 'SIZE', 'PRICE', 'QTY', '')
        self.sales_tree = ttk.Treeview(sales_tree_container,
                                       columns=header,
                                       height=20,
                                       show="headings",
                                       selectmode="browse")
        vsb = ttk.Scrollbar(sales_tree_container,
                            orient="vertical",
                            command=self.sales_tree.yview)
        hsb = ttk.Scrollbar(sales_tree_container,
                            orient="horizontal",
                            command=self.sales_tree.xview)

        self.sales_tree.configure(yscrollcommand=vsb.set,
                                  xscrollcommand=hsb.set)
        style = ttk.Style()
        style.configure("Treeview.Heading", font=('Calibri', 12))
        style.configure("Treeview", font=('Calibri', 12), rowheight=25)

        self.sales_tree.configure(yscrollcommand=vsb.set,
                                  xscrollcommand=hsb.set)
        self.sales_tree.grid(column=0,
                             row=0,
                             sticky='nsew',
                             in_=sales_tree_container)

        vsb.grid(column=1, row=0, sticky='ns', in_=sales_tree_container)
        hsb.grid(column=0, row=1, sticky='ew', in_=sales_tree_container)

        sales_tree_container.grid_columnconfigure(0, weight=1)
        sales_tree_container.grid_rowconfigure(0, weight=1)

        self.sales_tree.heading("0", text="SALES_DATE")
        self.sales_tree.heading("1", text="BILL_NO")
        self.sales_tree.heading("2", text="PRODUCT_CODE")
        self.sales_tree.heading("3", text="PRODUCT_NAME")
        self.sales_tree.heading("4", text="PRODUCT_TYPE")
        self.sales_tree.heading("5", text="SIZE")
        self.sales_tree.heading("6", text="PRICE")
        self.sales_tree.heading("7", text="QTY")

        self.sales_tree.column(0, anchor=tk.W, width="140")
        self.sales_tree.column(1, anchor=tk.W, width="80")
        self.sales_tree.column(2, anchor=tk.W, width="120")
        self.sales_tree.column(3, anchor=tk.W, width="140")
        self.sales_tree.column(4, anchor=tk.W, width="180")
        self.sales_tree.column(5, anchor='center', width="50")
        self.sales_tree.column(6, anchor=tk.E, width="80")
        self.sales_tree.column(7, anchor='center', width="50")
        self.sales_tree.column(8, anchor='center', width="2")

        self.reload_sales()

        numeric_cols = ['BILL_NO', 'PRICE', 'QTY']
        for col in header:
            if col in numeric_cols:
                self.sales_tree.heading(col,
                                        text=col,
                                        command=lambda _col=col: self.
                                        sort_treeview(self.sales_tree,
                                                      _col,
                                                      numeric_sort=True,
                                                      reverse=False))
            else:
                self.sales_tree.heading(col,
                                        text=col,
                                        command=lambda _col=col: self.
                                        sort_treeview(self.sales_tree,
                                                      _col,
                                                      numeric_sort=False,
                                                      reverse=False))

        self.sales_tree.tag_configure("evenrow", background='#fbefcc')
        self.sales_tree.tag_configure("oddrow",
                                      background='white',
                                      foreground='black')
        self.sales_tree.bind('<<TreeviewSelect>>', self.on_tree_select)

        # ********** Sales Details *********
        sales_details_container = tk.Frame(right_container,
                                           bd=5,
                                           pady=3,
                                           padx=10,
                                           relief=tk.RIDGE,
                                           bg=self.clr_yellow)
        sales_details_container.pack(fill='both', expand=True, side=tk.TOP)

        sales_stats_container = tk.Frame(right_container,
                                         bd=5,
                                         pady=3,
                                         padx=10,
                                         relief=tk.RIDGE,
                                         bg=self.clr_yellow)
        sales_stats_container.pack(fill='both',
                                   expand=True,
                                   side=tk.TOP,
                                   anchor='center')

        sales_details_container.grid_columnconfigure(0, weight=1)
        sales_details_container.grid_columnconfigure(3, weight=1)

        lbl_product_details = tk.Label(sales_details_container,
                                       text="Sales Details",
                                       bg=self.clr_blueiris,
                                       fg="white")
        lbl_product_details.grid(row=0,
                                 column=1,
                                 columnspan=2,
                                 sticky="news",
                                 padx=3,
                                 pady=3)
        lbl_product_details.config(font=("Calibri bold", 14))

        lbl_sales_date = tk.Label(sales_details_container,
                                  text="Sales Date: ",
                                  bg=self.clr_yellow)
        lbl_sales_date.grid(row=1, column=1, sticky="nw", padx=3, pady=1)
        ety_sales_date = tk.Entry(sales_details_container,
                                  textvariable=self.var_sales_date,
                                  state='disabled')
        ety_sales_date.grid(row=1, column=2, sticky="nw", padx=3, pady=1)

        lbl_bill_number = tk.Label(sales_details_container,
                                   text="Bill No: ",
                                   bg=self.clr_yellow)
        lbl_bill_number.grid(row=2, column=1, sticky="nw", padx=3, pady=1)
        ety_bill_number = tk.Entry(sales_details_container,
                                   width=8,
                                   textvariable=self.var_bill_number,
                                   state='disabled')
        ety_bill_number.grid(row=2,
                             column=2,
                             columnspan=2,
                             sticky="nw",
                             padx=3,
                             pady=1)

        lbl_product_code = tk.Label(sales_details_container,
                                    text="Product Code: ",
                                    bg=self.clr_yellow)
        lbl_product_code.grid(row=3, column=1, sticky="nw", padx=3, pady=1)
        ety_product_code = tk.Entry(sales_details_container,
                                    width=15,
                                    textvariable=self.var_product_code,
                                    state='disabled')
        ety_product_code.grid(row=3,
                              column=2,
                              columnspan=2,
                              sticky="nw",
                              padx=3,
                              pady=1)

        lbl_product_name = tk.Label(sales_details_container,
                                    text="Product Name: ",
                                    bg=self.clr_yellow)
        lbl_product_name.grid(row=4, column=1, sticky="nw", padx=3, pady=1)
        ety_product_name = tk.Entry(sales_details_container,
                                    textvariable=self.var_product_name,
                                    state='disabled')
        ety_product_name.grid(row=4,
                              column=2,
                              columnspan=2,
                              sticky="nw",
                              padx=3,
                              pady=1)

        lbl_product_type = tk.Label(sales_details_container,
                                    text="Product Type: ",
                                    bg=self.clr_yellow)
        lbl_product_type.grid(row=5, column=1, sticky="nw", padx=3, pady=1)
        ety_product_type = tk.Entry(sales_details_container,
                                    textvariable=self.var_product_type,
                                    state='disabled')
        ety_product_type.grid(row=5,
                              column=2,
                              columnspan=2,
                              sticky="nw",
                              padx=3,
                              pady=1)

        lbl_product_size = tk.Label(sales_details_container,
                                    text="Size: ",
                                    bg=self.clr_yellow)
        lbl_product_size.grid(row=6, column=1, sticky="nw", padx=3, pady=1)
        ety_product_size = tk.Entry(sales_details_container,
                                    width=12,
                                    textvariable=self.var_product_size,
                                    state='disabled')
        ety_product_size.grid(row=6,
                              column=2,
                              columnspan=2,
                              sticky="nw",
                              padx=3,
                              pady=1)

        lbl_selling_price = tk.Label(sales_details_container,
                                     text="Price: ",
                                     bg=self.clr_yellow)
        lbl_selling_price.grid(row=7, column=1, sticky="nw", padx=3, pady=1)
        ety_selling_price = tk.Entry(sales_details_container,
                                     width=8,
                                     textvariable=self.var_selling_price,
                                     state='disabled')
        ety_selling_price.grid(row=7, column=2, sticky="nw", padx=3, pady=1)

        lbl_quantity = tk.Label(sales_details_container,
                                text="Quantity: ",
                                bg=self.clr_yellow)
        lbl_quantity.grid(row=8, column=1, sticky="nw", padx=3, pady=1)
        ety_quantity = tk.Entry(sales_details_container,
                                width=5,
                                textvariable=self.var_quantity,
                                state='disabled')
        ety_quantity.grid(row=8, column=2, sticky="nw", padx=3, pady=1)

        # sales_stats_container element
        sales_stats_container.grid_columnconfigure(0, weight=1)
        sales_stats_container.grid_columnconfigure(3, weight=1)

        lbl_sales_stats = tk.Label(sales_stats_container,
                                   text="Sales Stats",
                                   bg=self.clr_blueiris,
                                   fg="white")
        lbl_sales_stats.grid(row=0,
                             column=1,
                             columnspan=2,
                             sticky="news",
                             padx=3,
                             pady=5)
        lbl_sales_stats.config(font=("Calibri bold", 14))

        lbl_from_date = tk.Label(sales_stats_container,
                                 text='From Date: ',
                                 bg=self.clr_yellow)
        lbl_from_date.grid(row=1, column=1, sticky="nw", padx=1, pady=5)
        self.sales_from_date = DateEntry(sales_stats_container,
                                         date_pattern='yyyy-mm-dd',
                                         background='yellow',
                                         foreground='black',
                                         borderwidth=2,
                                         width=10)
        self.sales_from_date.grid(row=1,
                                  column=2,
                                  sticky="sw",
                                  padx=2,
                                  pady=5,
                                  ipady=3)

        lbl_to_date = tk.Label(sales_stats_container,
                               text='To Date: ',
                               bg=self.clr_yellow)
        lbl_to_date.grid(row=2, column=1, sticky="nw", padx=1, pady=5)
        self.sales_to_date = DateEntry(sales_stats_container,
                                       date_pattern='yyyy-mm-dd',
                                       background='yellow',
                                       foreground='back',
                                       borderwidth=2,
                                       width=10)
        self.sales_to_date.grid(row=2,
                                column=2,
                                sticky="sw",
                                padx=2,
                                pady=5,
                                ipady=3)

        lbl_sold_quantity = tk.Label(sales_stats_container,
                                     text="Quantity: ",
                                     bg=self.clr_yellow)
        lbl_sold_quantity.grid(row=3, column=1, sticky="nw", padx=3, pady=5)
        ety_sold_quantity = tk.Entry(sales_stats_container,
                                     width=5,
                                     textvariable=self.var_sold_quantity,
                                     state='disabled')
        ety_sold_quantity.grid(row=3, column=2, sticky="nw", padx=3, pady=5)

        lbl_sales_amount = tk.Label(sales_stats_container,
                                    text="Amount: ",
                                    bg=self.clr_yellow)
        lbl_sales_amount.grid(row=4, column=1, sticky="nw", padx=3, pady=5)
        ety_sales_amount = tk.Entry(sales_stats_container,
                                    width=10,
                                    textvariable=self.var_sales_amount,
                                    state='disabled')
        ety_sales_amount.grid(row=4, column=2, sticky="nw", padx=3, pady=5)

        btn_get_sales_data = tk.Button(sales_stats_container,
                                       text="Get Sales Data",
                                       bg=self.clr_fuchsia,
                                       fg='white',
                                       command=self.get_sales_data)
        btn_get_sales_data.grid(row=5,
                                column=1,
                                columnspan=2,
                                sticky="news",
                                padx=2,
                                pady=5)
        btn_get_sales_data.bind('<Return>',
                                lambda event: self.get_sales_data(event))
コード例 #10
0
    def load_view_report_form(self):
        self.update_username()

        products = Product.get_product_name_list()
        for product in products:
            self.product_name_list.append(product.product_name)

        products = Product.get_product_type_list()
        for product in products:
            self.product_type_list.append(product.product_type)

        # ********** Sub Containers *********
        left_container = tk.Frame(self.content_container,
                                  bd=5,
                                  padx=5,
                                  pady=5,
                                  relief=tk.RIDGE,
                                  bg='#62b6e2')
        left_container.pack(fill='both', expand=True, side=tk.LEFT)

        left_button_container = tk.Frame(left_container,
                                         relief=tk.RIDGE,
                                         bg='#62b6e2')
        left_button_container.pack(fill='both', expand=True, side=tk.TOP)

        search_container = tk.Frame(left_button_container,
                                    relief=tk.RIDGE,
                                    bg='#62b6e2')
        search_container.pack(fill='x', expand=True, side=tk.LEFT)

        filter_container = tk.Frame(left_button_container,
                                    relief=tk.RIDGE,
                                    bg='#62b6e2')
        filter_container.pack(fill='x', expand=True, side=tk.LEFT)

        # ********** left_search_container elements *********
        search_lbl_product_id = tk.Label(search_container,
                                         text="ID: ",
                                         bg='#62b6e2')
        search_lbl_product_id.grid(row=0,
                                   column=0,
                                   sticky="nw",
                                   padx=1,
                                   pady=1)
        self.ety_search_product_id = tk.Entry(
            search_container, width=10, textvariable=self.search_product_id)
        self.ety_search_product_id.grid(row=1,
                                        column=0,
                                        sticky="nw",
                                        padx=2,
                                        pady=1,
                                        ipady=6)
        self.ety_search_product_id.bind(
            '<Return>', lambda event: self.search_report(event))

        btn_search = tk.Button(search_container,
                               text="Search",
                               command=self.search_report)
        btn_search.grid(row=1, column=1, sticky="sw", padx=2, pady=1)

        filter_lbl_product_name = tk.Label(filter_container,
                                           text="Name: ",
                                           bg='#62b6e2')
        filter_lbl_product_name.grid(row=0,
                                     column=0,
                                     sticky="nw",
                                     padx=5,
                                     pady=5)
        self.filter_ety_product_name = AutocompleteEntry(
            filter_container,
            completevalues=self.product_name_list,
            state='disabled')
        self.filter_ety_product_name.grid(row=1,
                                          column=0,
                                          sticky="nw",
                                          padx=5,
                                          pady=5,
                                          ipady=6)
        self.filter_ety_product_name.bind(
            "<Return>", lambda event: self.filter_report(event))

        filter_lbl_product_type = tk.Label(filter_container,
                                           text="Type: ",
                                           bg='#62b6e2')
        filter_lbl_product_type.grid(row=0,
                                     column=1,
                                     sticky="nw",
                                     padx=5,
                                     pady=5)
        self.filter_ety_product_type = AutocompleteEntry(
            filter_container,
            completevalues=self.product_type_list,
            state='disabled')
        self.filter_ety_product_type.grid(row=1,
                                          column=1,
                                          sticky="nw",
                                          padx=5,
                                          pady=5,
                                          ipady=6)
        self.filter_ety_product_type.grid(row=1,
                                          column=1,
                                          sticky="nw",
                                          padx=5,
                                          pady=5,
                                          ipady=6)
        self.filter_ety_product_type.bind(
            "<Return>", lambda event: self.filter_report(event))

        btn_filter = tk.Button(filter_container,
                               text="Apply Filter",
                               command=self.filter_report,
                               state='disabled')
        btn_filter.grid(row=1, column=2, sticky="sw", padx=2, pady=1)

        btn_clear_filter = tk.Button(filter_container,
                                     text="Clear Filter",
                                     command=self.reload_report)
        btn_clear_filter.grid(row=1, column=3, sticky="sw", padx=2, pady=1)

        btn_export = tk.Button(filter_container,
                               text="Export to Excel",
                               command=self.export_data)
        btn_export.grid(row=1, column=4, sticky="se", padx=15, pady=1)

        # ********** left_container *********
        tree_container = tk.Frame(left_container, pady=3, bg='#62b6e2')
        tree_container.pack(fill='both', expand=True, side=tk.TOP)

        header = ('#', 'date', 'product_id', 'product_name', 'product_type',
                  'product_size', 'selling_price', 'actual_price', 'quantity',
                  'total_amount', 'dummy')
        self.tree = ttk.Treeview(tree_container,
                                 columns=header,
                                 show="headings",
                                 height=15,
                                 selectmode="browse")
        vsb = ttk.Scrollbar(tree_container,
                            orient="vertical",
                            command=self.tree.yview)
        hsb = ttk.Scrollbar(orient="horizontal", command=self.tree.xview)

        self.tree.configure(yscrollcommand=vsb.set, xscrollcommand=hsb.set)
        style = ttk.Style()
        style.configure("Treeview.Heading", font=('Calibri', 12))
        style.configure("Treeview", font=('Calibri', 12), rowheight=25)

        self.tree.configure(yscrollcommand=vsb.set, xscrollcommand=hsb.set)
        self.tree.grid(column=0, row=0, sticky='nsew', in_=tree_container)

        vsb.grid(column=1, row=0, sticky='ns', in_=tree_container)
        hsb.grid(column=0, row=1, sticky='ew', in_=tree_container)

        tree_container.grid_columnconfigure(0, weight=1)
        tree_container.grid_rowconfigure(0, weight=1)

        self.tree.heading("0", text="#")
        self.tree.heading("1", text="DATE")
        self.tree.heading("2", text="ID")
        self.tree.heading("3", text="PRODUCT_NAME")
        self.tree.heading("4", text="PRODUCT_TYPE")
        self.tree.heading("5", text="SIZE")
        self.tree.heading("6", text="SELL_PRICE")
        self.tree.heading("7", text="ACTUAL_PRICE")
        self.tree.heading("8", text="QTY")
        self.tree.heading("9", text="TOTAL_AMOUNT")

        self.tree.column(0, anchor='center', width="50")
        self.tree.column(1, anchor=tk.W, width="100")
        self.tree.column(2, anchor='center', width="50")
        self.tree.column(3, anchor=tk.W, width="150")
        self.tree.column(4, anchor=tk.W, width="200")
        self.tree.column(5, anchor='center', width="100")
        self.tree.column(6, anchor=tk.E, width="120")
        self.tree.column(7, anchor=tk.E, width="120")
        self.tree.column(8, anchor='center', width="80")
        self.tree.column(9, anchor=tk.E, width="120")
        self.tree.column(10, anchor='center', width="5")

        self.reload_report()

        btn_close = tk.Button(self.footer_container,
                              text="Close",
                              width='20',
                              command=self.window.destroy)
        btn_close.pack(padx=5, pady=5)

        self.tree.tag_configure("evenrow", background='#fbefcc')
        self.tree.tag_configure("oddrow",
                                background='white',
                                foreground='black')
        self.tree.bind('<<TreeviewSelect>>', self.on_tree_select)
コード例 #11
0
    def load_add_purchase_form(self):
        for index in range(1, 9):
            self.menubar.entryconfig(index, state=tk.DISABLED)

        self.show_menu(MainForm.is_admin_user)
        self.update_username()

        products = LkpProductName.get_all_product_names()
        for product in products:
            self.product_name_list.append(product.product_name)

        products = LkpProductType.get_all_product_types()
        for product in products:
            self.product_type_list.append(product.product_type)

        products = LkpProductSize.get_all_product_sizes()
        for product in products:
            self.product_size_list.append(product.product_size)

        products = Product.get_product_sell_price_list()
        for product in products:
            self.product_sell_price_list.append(
                str(round(product.selling_price, 2)))

        categories = ProductCategory.get_all_categories()
        for category in categories:
            self.product_category_list.append(category.category)

        # ********** Sub Containers *********
        left_container = tk.Frame(self.content_container,
                                  bd=5,
                                  padx=5,
                                  pady=2,
                                  relief=tk.RIDGE,
                                  bg=self.clr_yellow)
        left_container.pack(fill='both', expand=True, side=tk.LEFT)

        right_container = tk.Frame(self.content_container,
                                   bd=5,
                                   padx=5,
                                   pady=5,
                                   relief=tk.RIDGE,
                                   bg=self.clr_yellow)
        right_container.pack(fill='both', expand=True, side=tk.RIGHT)

        # left_container elements
        left_top_button_container = tk.Frame(left_container,
                                             relief=tk.RIDGE,
                                             bg=self.clr_yellow)
        left_top_button_container.pack(fill='both', expand=True, side=tk.TOP)

        products_tree_container = tk.Frame(left_container,
                                           pady=3,
                                           bg=self.clr_yellow,
                                           relief=tk.RIDGE)
        products_tree_container.pack(fill='both', expand=True, side=tk.TOP)

        # right_container elements
        right_top_button_container = tk.Frame(right_container,
                                              relief=tk.RIDGE,
                                              bg=self.clr_yellow)
        right_top_button_container.pack(fill='both', expand=True, side=tk.TOP)

        right_tree_container = tk.Frame(right_container,
                                        relief=tk.RIDGE,
                                        bg=self.clr_yellow)
        right_tree_container.pack(fill='both', expand=True, side=tk.TOP)

        right_bottom_button_container = tk.Frame(right_container,
                                                 relief=tk.RIDGE,
                                                 bg=self.clr_yellow)
        right_bottom_button_container.pack(fill='both',
                                           expand=True,
                                           side=tk.TOP)

        # ********** left_search_container elements *********
        filter_lbl_product_name = tk.Label(left_top_button_container,
                                           text="Name: ",
                                           bg=self.clr_yellow)
        filter_lbl_product_name.grid(row=0,
                                     column=0,
                                     sticky="nw",
                                     padx=1,
                                     pady=1)
        self.filter_ety_product_name = AutocompleteEntry(
            left_top_button_container,
            width=15,
            completevalues=self.product_name_list)
        self.filter_ety_product_name.grid(row=1,
                                          column=0,
                                          sticky="nw",
                                          padx=2,
                                          pady=1,
                                          ipady=6)
        self.filter_ety_product_name.bind(
            "<Return>", lambda event: self.filter_product(event))

        filter_lbl_product_type = tk.Label(left_top_button_container,
                                           text="Type: ",
                                           bg=self.clr_yellow)
        filter_lbl_product_type.grid(row=0,
                                     column=1,
                                     sticky="nw",
                                     padx=1,
                                     pady=1)
        self.filter_ety_product_type = AutocompleteEntry(
            left_top_button_container,
            width=18,
            completevalues=self.product_type_list)
        self.filter_ety_product_type.grid(row=1,
                                          column=1,
                                          sticky="nw",
                                          padx=2,
                                          pady=1,
                                          ipady=6)
        self.filter_ety_product_type.bind(
            "<Return>", lambda event: self.filter_product(event))

        filter_lbl_product_size = tk.Label(left_top_button_container,
                                           text="Size: ",
                                           bg=self.clr_yellow)
        filter_lbl_product_size.grid(row=0,
                                     column=2,
                                     sticky="nw",
                                     padx=1,
                                     pady=1)
        self.filter_ety_product_size = AutocompleteEntry(
            left_top_button_container,
            width=12,
            completevalues=self.product_size_list)
        self.filter_ety_product_size.grid(row=1,
                                          column=2,
                                          sticky="nw",
                                          padx=2,
                                          pady=1,
                                          ipady=6)
        self.filter_ety_product_size.bind(
            "<Return>", lambda event: self.filter_product(event))

        filter_lbl_product_price = tk.Label(left_top_button_container,
                                            text="Sell Price: ",
                                            bg=self.clr_yellow)
        filter_lbl_product_price.grid(row=0,
                                      column=3,
                                      sticky="nw",
                                      padx=1,
                                      pady=1)
        self.filter_ety_product_sell_price = AutocompleteEntry(
            left_top_button_container,
            width=8,
            completevalues=self.product_sell_price_list)
        self.filter_ety_product_sell_price.grid(row=1,
                                                column=3,
                                                sticky="nw",
                                                padx=2,
                                                pady=1,
                                                ipady=6)
        self.filter_ety_product_sell_price.bind(
            "<Return>", lambda event: self.filter_product(event))

        # filter_lbl_product_actual_price = tk.Label(left_top_button_container, text="Act. Price: ", bg=self.clr_yellow)
        # filter_lbl_product_actual_price.grid(row=0, column=4, sticky="nw", padx=1, pady=1)
        # self.filter_ety_product_actual_price = AutocompleteEntry(left_top_button_container, width=8,
        #                                                          completevalues=self.product_actual_price_list)
        # self.filter_ety_product_actual_price.grid(row=1, column=4, sticky="nw", padx=2, pady=1, ipady=6)
        # self.filter_ety_product_actual_price.bind("<Return>", lambda event: self.filter_product(event))

        lbl_product_category = tk.Label(left_top_button_container,
                                        text="Category:",
                                        bg=self.clr_yellow)
        lbl_product_category.grid(row=0, column=4, sticky="nw", padx=1, pady=1)
        self.cbo_product_category = ttk.Combobox(
            left_top_button_container,
            width=7,
            values=self.product_category_list)
        self.cbo_product_category.grid(row=1,
                                       column=4,
                                       sticky="nw",
                                       padx=2,
                                       pady=1,
                                       ipady=6)

        btn_filter = tk.Button(left_top_button_container,
                               text="Apply Filter [F5]",
                               bg=self.clr_fuchsia,
                               fg='white',
                               command=self.filter_product)
        btn_filter.grid(row=1, column=5, sticky="news", padx=2, pady=1)

        btn_clear_filter = tk.Button(left_top_button_container,
                                     text="Clear",
                                     command=self.reload_products)
        btn_clear_filter.grid(row=1, column=6, sticky="news", padx=2, pady=1)

        btn_add_new = tk.Button(left_top_button_container,
                                text="Add New [F4]",
                                bg=self.clr_limegreen,
                                command=self.add_new_product)
        btn_add_new.grid(row=0, column=5, sticky="news", padx=1, pady=1)

        btn_copy = tk.Button(left_top_button_container,
                             text="Copy [F3]",
                             bg=self.clr_blueiris,
                             fg='white',
                             command=self.copy_to_new)
        btn_copy.grid(row=0, column=6, sticky="news", padx=1, pady=1)

        # ********** tree_containers elements *********
        header = ('CODE', 'PRODUCT_NAME', 'PRODUCT_TYPE', 'SIZE', 'PRICE',
                  'QTY', '')
        self.products_tree = ttk.Treeview(products_tree_container,
                                          columns=header,
                                          height=20,
                                          show="headings",
                                          selectmode="browse")
        vsb = ttk.Scrollbar(products_tree_container,
                            orient="vertical",
                            command=self.products_tree.yview)
        hsb = ttk.Scrollbar(products_tree_container,
                            orient="horizontal",
                            command=self.products_tree.xview)

        style = ttk.Style()
        style.configure("Treeview.Heading", font=('Calibri', 12))
        style.configure("Treeview", font=('Calibri', 10), rowheight=25)

        self.products_tree.configure(yscrollcommand=vsb.set,
                                     xscrollcommand=hsb.set)
        self.products_tree.grid(column=0,
                                row=0,
                                sticky='nsew',
                                in_=products_tree_container)

        vsb.grid(column=1, row=0, sticky='ns', in_=products_tree_container)
        hsb.grid(column=0, row=1, sticky='ew', in_=products_tree_container)

        products_tree_container.grid_columnconfigure(0, weight=1)
        products_tree_container.grid_rowconfigure(0, weight=1)

        self.products_tree.heading("0", text="CODE")
        self.products_tree.heading("1", text="PRODUCT_NAME")
        self.products_tree.heading("2", text="PRODUCT_TYPE")
        self.products_tree.heading("3", text="SIZE")
        self.products_tree.heading("4", text="PRICE")
        self.products_tree.heading("5", text="QTY")

        self.products_tree.column(0, anchor='center', width="100")
        self.products_tree.column(1, anchor=tk.W, width="120")
        self.products_tree.column(2, anchor=tk.W, width="150")
        self.products_tree.column(3, anchor='center', width="50")
        self.products_tree.column(4, anchor=tk.E, width="50")
        self.products_tree.column(5, anchor='center', width="20")
        self.products_tree.column(6, anchor='center', width="1")

        self.products_tree.bind("<F3>", lambda event: self.copy_to_new(event))

        self.reload_products()

        numeric_cols = ['PRICE', 'QTY']
        for col in header:
            if col in numeric_cols:
                self.products_tree.heading(col,
                                           text=col,
                                           command=lambda _col=col: self.
                                           sort_treeview(self.products_tree,
                                                         _col,
                                                         numeric_sort=True,
                                                         reverse=False))
            else:
                self.products_tree.heading(col,
                                           text=col,
                                           command=lambda _col=col: self.
                                           sort_treeview(self.products_tree,
                                                         _col,
                                                         numeric_sort=False,
                                                         reverse=False))

        # ********** Right Tree Details *********
        lbl_purchase_date = tk.Label(right_top_button_container,
                                     text='Purchase Date: ',
                                     bg=self.clr_yellow)
        lbl_purchase_date.grid(row=0, column=0, sticky="nw", padx=1, pady=1)
        self.purchase_date = DateEntry(right_top_button_container,
                                       date_pattern='yyyy-mm-dd',
                                       background='yellow',
                                       foreground='black',
                                       borderwidth=2)
        self.purchase_date.grid(row=1,
                                column=0,
                                sticky="nw",
                                padx=2,
                                pady=1,
                                ipady=3)

        lbl_garment_name = tk.Label(right_top_button_container,
                                    text='Garment Name: ',
                                    bg=self.clr_yellow)
        lbl_garment_name.grid(row=0, column=1, sticky="nw", padx=1, pady=1)
        self.ety_garment_name = tk.Entry(right_top_button_container)
        self.ety_garment_name.grid(row=1,
                                   column=1,
                                   sticky="nw",
                                   padx=2,
                                   pady=1,
                                   ipady=3)

        btn_add_purchase = tk.Button(right_top_button_container,
                                     text="Add Purchase",
                                     bg=self.clr_fuchsia,
                                     fg='white',
                                     command=self.add_purchase)
        btn_add_purchase.grid(row=0,
                              column=2,
                              rowspan=2,
                              sticky="se",
                              padx=2,
                              pady=1)

        btn_clear = tk.Button(right_top_button_container,
                              text="Clear",
                              command=self.clear_all)
        btn_clear.grid(row=0, column=3, rowspan=2, sticky="se", padx=2, pady=1)

        purchase_tree_container = tk.Frame(right_tree_container,
                                           pady=1,
                                           relief=tk.RIDGE,
                                           bg=self.clr_yellow)
        purchase_tree_container.pack(fill='both', expand=True, side=tk.RIGHT)

        header = ('#', 'product_code', 'product_name', 'type', 'size',
                  'selling_price', 'quantity', 'amount', 'dummy')
        self.purchase_tree = ttk.Treeview(purchase_tree_container,
                                          columns=header,
                                          height=15,
                                          show="headings",
                                          selectmode="browse")
        vsb = ttk.Scrollbar(purchase_tree_container,
                            orient="vertical",
                            command=self.purchase_tree.yview)
        hsb = ttk.Scrollbar(purchase_tree_container,
                            orient="horizontal",
                            command=self.purchase_tree.xview)

        self.purchase_tree.configure(yscrollcommand=vsb.set,
                                     xscrollcommand=hsb.set)
        self.purchase_tree.grid(column=0, row=0, sticky='nsew')

        vsb.grid(column=1, row=0, sticky='ns')
        hsb.grid(column=0, row=1, sticky='ew')

        purchase_tree_container.grid_columnconfigure(0, weight=1)
        purchase_tree_container.grid_rowconfigure(0, weight=1)

        self.purchase_tree.heading("0", text="#")
        self.purchase_tree.heading("1", text="Code")
        self.purchase_tree.heading("2", text="Product")
        self.purchase_tree.heading("3", text="Type")
        self.purchase_tree.heading("4", text="Size")
        self.purchase_tree.heading("5", text="Price")
        self.purchase_tree.heading("6", text="Qty")
        self.purchase_tree.heading("7", text="Amount")
        self.purchase_tree.heading("8", text="")

        self.purchase_tree.column(0, anchor='center', minwidth=25, width=25)
        self.purchase_tree.column(1, anchor=tk.W, minwidth=40, width=110)
        self.purchase_tree.column(2, anchor=tk.W, minwidth=80,
                                  width=100)  # Product
        self.purchase_tree.column(3, anchor=tk.W, minwidth=110,
                                  width=110)  # Type
        self.purchase_tree.column(4, anchor='center', minwidth=50,
                                  width=50)  # Size
        self.purchase_tree.column(5, anchor=tk.E, minwidth=50,
                                  width=50)  # Price
        self.purchase_tree.column(6, anchor='center', minwidth=40,
                                  width=40)  # Qty
        self.purchase_tree.column(7, anchor=tk.E, minwidth=60,
                                  width=60)  # Amount
        self.purchase_tree.column(8, anchor='center', width=1)
        self.purchase_tree["displaycolumns"] = (0, 1, 2, 3, 4, 5, 6, 7, 8)
        self.purchase_tree.bind('<Double-1>',
                                lambda event: self.remove_product(event))

        self.products_tree.tag_configure("evenrow_active",
                                         background='#fbefcc')
        self.products_tree.tag_configure("oddrow_active",
                                         background='white',
                                         foreground='black')
        self.products_tree.tag_configure("evenrow_inactive",
                                         background='#fbefcc',
                                         foreground='red')
        self.products_tree.tag_configure("oddrow_inactive",
                                         background='white',
                                         foreground='red')

        self.products_tree.bind('<<TreeviewSelect>>', self.on_tree_select)
        self.products_tree.bind('<Double-1>',
                                lambda event: self.get_quantity(event))
        self.products_tree.bind('<Return>',
                                lambda event: self.get_quantity(event))

        # ********** bottom_button_container elements *********
        lbl_purchase_quantity = tk.Label(
            right_bottom_button_container,
            fg=self.clr_limegreen,
            relief=tk.RAISED,
            textvariable=self.var_purchase_quantity)
        lbl_purchase_quantity.pack(side=tk.LEFT,
                                   fill='x',
                                   expand=True,
                                   padx=1,
                                   pady=1)
        lbl_purchase_quantity.config(font=("calibri bold", 30))

        lbl_purchase_amount = tk.Label(right_bottom_button_container,
                                       fg=self.clr_blueiris,
                                       relief=tk.RAISED,
                                       textvariable=self.var_purchase_amount)
        lbl_purchase_amount.pack(side=tk.LEFT,
                                 fill='x',
                                 expand=True,
                                 padx=1,
                                 pady=1)
        lbl_purchase_amount.config(font=("calibri bold", 30))
コード例 #12
0
    def add_new_product(self, event=None):
        product_name = self.filter_ety_product_name.get().strip()
        product_type = self.filter_ety_product_type.get().strip()
        product_size = self.filter_ety_product_size.get().strip()
        product_category = self.cbo_product_category.get().strip()

        try:
            selling_price = round(
                float(self.filter_ety_product_sell_price.get().strip()), 2)
        except (ValueError, TclError):
            selling_price = 0.0

        try:
            actual_price = round(self.var_actual_price.get(), 2)
        except TclError:
            actual_price = 0.0

        if len(product_name) == 0:
            messagebox.showerror("SS Fashion Tuty",
                                 f"Product_Name is missing!")
            print(f"Product_Name is missing!")
            return

        if selling_price == "" or selling_price <= 0:
            messagebox.showerror("SS Fashion Tuty",
                                 f"Selling Price is missing!")
            print(f"selling price is missing!")
            return

        if product_category == "" or product_category is None:
            messagebox.showerror("SS Fashion Tuty", f"Category is missing!")
            print(f"Category is missing!")
            return

        if len(product_type) == 0:
            product_type = "-"

        if len(product_size) == 0:
            product_size = "-"

        existing_product_category = LkpProductName.get_product_category(
            product_name=product_name)
        if existing_product_category and product_category != existing_product_category:
            print(
                f"'{product_name}' already in '{existing_product_category}' category!"
            )
            messagebox.showerror(
                "SS Fashion Tuty",
                f"'{product_name}' already in '{existing_product_category}' category!"
                f"\nPlease rename the Product Name and try again!")
            return

        product_name_code = LkpProductName.get_code(product_name=product_name)
        if product_name_code is None:
            product_name_code = LkpProductName.create_lookup(
                product_name, product_category)

        product_type_code = LkpProductType.get_code(product_type=product_type)
        if product_type_code is None:
            product_type_code = LkpProductType.create_lookup(product_type)

        product_size_code = LkpProductSize.get_code(product_size=product_size)
        if product_size_code is None:
            product_size_code = LkpProductSize.create_lookup(product_size)

        product_price_code = str(int(selling_price)).zfill(4)
        product_code = f"{product_name_code}-{product_type_code}-{product_size_code}-{product_price_code}"

        product = (product_code, product_name, product_type, product_size,
                   selling_price, actual_price)

        product_list = Product.search_products(product_code, product_name,
                                               product_type, product_size,
                                               selling_price)
        if product_list:
            print(f"Product: '{product}' is already exists!")
            messagebox.showerror(
                "SS Fashion Tuty",
                f"Product already exists! \nProduct_Code: {product_code}")
        else:
            Product.add_product(product)
            self.reload_products()
            print(f"Product: {product} is added!")

            product = Product.search_products(product_code=product_code)
            if product:
                self.products_tree.selection_set(
                    self.products_tree.tag_has(product.product_code))
                self.products_tree.focus_set()

                self.products_tree.event_generate('<Return>')