Ejemplo n.º 1
0
 def del_item_sale(self):
     sdt = SaleDao()
     selectionIdxs = self.table_sale.selectedIndexes()[0]
     no = self.table_sale.item(selectionIdxs.row(), 0).text()
     sdt.delete_item(no)
     self.table_sale.removeRow(selectionIdxs.row())
     self.ui.table_sd.removeRow(selectionIdxs.row())
Ejemplo n.º 2
0
    def __init__(self, *args, **kwargs):
        super().__init__()
        self.pdt = ProductDao()
        self.idt = IDDao()
        self.sdt = SaleDao()
        self.ui = uic.loadUi("ui/main_menu.ui", self)

        self.month_count = 14
        self.graphcount = 0

        # combobox
        self.combobox_setting()

        # graph
        self.graph()

        # table
        self.table_pro = create_table(table=self.ui.table_pro, data=['제품코드', '제품명', '종류', '제품가격', '마진율(%)'])
        self.sale_pro = create_table(table=self.ui.table_sale, data=['제품명', '판매량', '판매금액', '판매일'])

        self.load_pro_all()
        self.load_sale_all()

        self.ui.btn_out.clicked.connect(self.exit)  # logout
        self.ui.btn_manage.clicked.connect(self.manage)
        self.ui.btn_sale.clicked.connect(self.sale_manage)
        self.ui.btn_exit.clicked.connect(self.exit)
        self.ui.btn_set.clicked.connect(self.user_setting)
        self.ui.combo_menu.currentIndexChanged.connect(self.select_menu)
        self.ui.combo_sale_year.currentIndexChanged.connect(self.select_sale)
        self.ui.combo_sale_month.currentIndexChanged.connect(self.select_month)
        self.ui.show()
    def __init__(self):
        super().__init__()
        self.ui = uic.loadUi("ui/sale_manage.ui")
        self.pdt = ProductDao()
        self.sdt = SaleDao()
        self.ui.table_sale.setColumnCount(7)
        self.ui.table_order.setColumnCount(3)
        self.table_order = create_table(table=self.ui.table_order,
                                        data=['제품명', '종류', '갯수'])
        self.table_sale_detail = create_table(
            table=self.ui.table_sale,
            data=['제품명', '종류', '판매량', '판매액', '세금', '마진액', '판매 시간'])
        self.load_sale()

        self.ui.combo_menu.addItem('all')
        self.ui.combo_sel_pro.addItem('--select--')
        self.count = 0
        self.nextIdx = 0
        self.namelist = []
        self.order_list = {}

        for i in range(len(self.pdt.select_category())):
            self.ui.combo_menu.addItems(self.pdt.select_category()[i])

        self.ui.combo_category.addItem('all')
        for i in range(len(self.pdt.select_category())):
            self.ui.combo_category.addItems(self.pdt.select_category()[i])
        for i in range(len(self.pdt.select_name())):
            self.ui.combo_sel_pro.addItems(self.pdt.select_name()[i])

        self.ui.btn_insert_menu.clicked.connect(self.ins_menu)
        self.ui.btn_del_menu.clicked.connect(self.del_menu)
        self.ui.btn_edit_menu.clicked.connect(self.edit_menu)
        self.ui.btn_ins_category.clicked.connect(self.category)
        self.ui.combo_menu.currentIndexChanged.connect(self.select_menu)
        self.ui.btn_exit.clicked.connect(self.exit)

        # sale_manage
        self.ui.tab_product.currentChanged.connect(self.tab_change)
        self.ui.btn_insert.clicked.connect(self.ins_order)
        self.ui.combo_category.currentIndexChanged.connect(self.order_category)
        self.ui.btn_edit.clicked.connect(self.edit_order)
        self.ui.btn_delete.clicked.connect(self.del_order)
        self.ui.btn_reset.clicked.connect(self.reset_order)
        self.ui.btn_ok.clicked.connect(self.ok_order)

        # select
        self.ui.btn_select.clicked.connect(self.select_sale_detail)
        self.ui.btn_init.clicked.connect(self.select_init)

        self.set_context_menu(self.ui.table_sale)
        self.set_context_menu_order(self.ui.table_order)

        self.ui.btn_edit_menu.setEnabled(False)
        self.ui.btn_edit.setEnabled(False)
        self.ui.btn_edit_menu.setText('편집시 우클릭')
        self.ui.btn_edit.setText('편집시 주문 현황 우클릭')

        self.ui.show()
Ejemplo n.º 4
0
 def __delete_sale(self):
     sdt = SaleDao()
     selectionIdxs = self.ui.tableWidget_2.selectedIndexes()[0]
     no = self.ui.tableWidget_2.item(selectionIdxs.row(), 0).text()
     self.ui.tableWidget_2.removeRow(selectionIdxs.row())
     self.ui.table_sd.removeRow(selectionIdxs.row())
     sdt.delete_item(no)
     QMessageBox.information(self, 'Delete', '확인', QMessageBox.Ok)
Ejemplo n.º 5
0
 def get_item_form_le_addsale(self, list=None):
     sdt = SaleDao()
     item_no = None
     code = list[0]
     price = list[1]
     saleCnt = list[2]
     marginRate = list[3]
     sdt.insert_item(code, price, saleCnt, marginRate)
     return self.create_item_sale(item_no, code, price, saleCnt, marginRate)
Ejemplo n.º 6
0
 def get_item_form_le_updatesale(self, list=None):
     sdt = SaleDao()
     no = list[0]
     code = list[1]
     price = list[2]
     saleCnt = list[3]
     marginRate = list[4]
     sdt.update_item(code, price, saleCnt, marginRate, no)
     return self.create_item_sale(no, code, price, saleCnt, marginRate)
Ejemplo n.º 7
0
    def get_item_form_le(self):
        pdt = ProductDao()
        sdt = SaleDao()
        code = self.ui.line_code.text()
        name = self.ui.line_name.text()
        price = self.ui.line_price.text()
        count = self.ui.line_count.text()
        margin = self.ui.line_margin.text()

        pdt.insert_product(code=code, name=name)
        sdt.insert_item(price=price,salecnt=count,marginrate=margin)
        return self.create_item(code, name)
Ejemplo n.º 8
0
 def __find(self):
     try:
         sdt = SaleDao()
         selectionIdxs = self.ui.tableWidget.selectedIndexes()[0]
         code = self.ui.tableWidget.item(selectionIdxs.row(), 0).text()
         res = sdt.find_item(code)
         find_res = str(res[0][2])
         QMessageBox.information(self, '검색완료', find_res + '원',
                                 QMessageBox.Ok)
     except IndexError as e:
         QMessageBox.information(self, '오류', 'sale에 값이 존재하지 않습니다.',
                                 QMessageBox.Ok)
Ejemplo n.º 9
0
    def __init__(self):
        super().__init__()
        pf = Product_form()
        sf = Sale_form()
        pdt = ProductDao()
        sdt = SaleDao()
        sdd = Sale_Detail_Dao()
        self.ui = uic.loadUi("ui/application.ui")
        # create table
        self.table = create_table(table=self.ui.tableWidget,
                                  data=['code', 'name'])
        self.table_sale = create_table(
            table=self.ui.tableWidget_2,
            data=['no', 'code', 'price', 'saleCnt', 'marginRate'])
        self.table_sdd = create_table(
            table=self.ui.table_sd,
            data=['no', 'sale_price', 'addTax', 'supply_price', 'marginPrice'])
        self.table_sdd_proc = create_table(table=self.ui.table_proc,
                                           data=[
                                               'rank', 'code', 'name', 'price',
                                               'saleCnt', 'supply_price',
                                               'addTax', 'sale_price',
                                               'marginRate', 'marginPrice'
                                           ])
        # select data
        res = pdt.select()
        res2 = sdt.select_item()
        res3 = sdd.select_item()
        self.load_data(res)
        self.load_data_sale(res2)
        self.load_data_sale_detail(res3)
        # product 버튼 연결
        self.ui.btn_insert.clicked.connect(self.add_item)
        self.ui.btn_update.clicked.connect(self.update_item)
        self.ui.btn_delete.clicked.connect(self.del_item)
        self.ui.btn_init.clicked.connect(self.init_item)
        self.ui.btn_pd_explain.clicked.connect(self.explain_pd)
        # sale 버튼 연결
        self.ui.btn_insert_2.clicked.connect(self.add_item_sale)
        self.ui.btn_update_2.clicked.connect(self.update_item_sale)
        self.ui.btn_delete_2.clicked.connect(self.del_item_sale)
        self.ui.btn_init_2.clicked.connect(self.init_item_sale)
        self.ui.btn_explain.clicked.connect(self.explain_sale)
        # sale_detail_proc 버튼 연결
        self.ui.rdbtn_sp.clicked.connect(self.call_proc_sp)
        self.ui.rdbtn_mp.clicked.connect(self.call_proc_mp)
        # 마우스 우클릭시 메뉴
        pf.set_context_menu(self.ui.tableWidget, self.__update, self.__delete,
                            self.__find)
        sf.set_context_menu_sale(self.ui.tableWidget_2, self.__update_sale,
                                 self.__delete_sale, self.__find_sale)

        self.ui.show()
Ejemplo n.º 10
0
    def update_item2(self):
        sale = SaleDao()
        selectionIdx = self.ui.tableWidget_2.selectedIndexes()[0]
        item_no, item_code, item_price, item_saleCnt, item_marginRate, no, code, price, saleCnt, marginRate = self.get_item_form_le2(
        )

        sale.update_item(code, price, saleCnt, marginRate, no)
        self.ui.tableWidget_2.setItem(selectionIdx.row(), 0, item_no)
        self.ui.tableWidget_2.setItem(selectionIdx.row(), 1, item_code)
        self.ui.tableWidget_2.setItem(selectionIdx.row(), 2, item_price)
        self.ui.tableWidget_2.setItem(selectionIdx.row(), 3, item_saleCnt)
        self.ui.tableWidget_2.setItem(selectionIdx.row(), 4, item_marginRate)
        self.init_item2()
Ejemplo n.º 11
0
 def init_item_sale(self):
     sdt = SaleDao()
     sdd = Sale_Detail_Dao()
     res2 = sdt.select_item()
     res3 = sdd.select_item()
     le_list = [
         self.ui.le_no, self.ui.le_code_2, self.ui.le_price,
         self.ui.le_saleCnt, self.ui.le_marginR
     ]
     [le_list[i].clear() for i in range(len(le_list))]
     row_res = self.ui.tableWidget_2.rowCount()
     for i in reversed(range(row_res)):
         self.ui.tableWidget_2.removeRow(i)
         self.ui.table_sd.removeRow(i)
     self.load_data_sale(res2)
     self.load_data_sale_detail(res3)
Ejemplo n.º 12
0
    def __init__(self):
        super().__init__()
        self.ui = uic.loadUi("ui/coffee_ui.ui")
        self.ui.show()
        self.table = view_table(table=self.ui.tableWidget,
                                data=["code", "name"])
        self.table = view_table(
            table=self.ui.tableWidget_2,
            data=["no", "code", "price", "saleCnt", "marginRate"])
        self.table = view_table(
            table=self.ui.tableWidget_3,
            data=["no", "sale_price", "addTax", "supply_price", "marginPrice"])

        # product slot/signal
        self.ui.btn_insert.clicked.connect(self.insert_item)
        self.ui.btn_delete.clicked.connect(self.delete_item)
        self.ui.btn_update.clicked.connect(self.update_item)
        self.ui.btn_init.clicked.connect(self.init_item)

        # sale slot/signal
        self.ui.btn_insert_2.clicked.connect(self.insert_item2)
        self.ui.btn_delete_2.clicked.connect(self.delete_item2)
        self.ui.btn_update_2.clicked.connect(self.update_item2)
        self.ui.btn_init_2.clicked.connect(self.init_item2)

        # sale_detail slot/signal
        self.load_data3()
        self.ui.btn_init_3.clicked.connect(self.load_data3)
        self.ui.btn_procedure.clicked.connect(
            lambda stat, x=True: self.procedure(stat, x))
        self.ui.btn_procedure2.clicked.connect(
            lambda stat, x=False: self.procedure(stat, x))

        pdt = ProductDao()
        data = pdt.select_item()
        self.load_data(data)

        sale = SaleDao()
        data2 = sale.select_item()
        self.load_data2(data2)

        # 우클릭 선택
        self.set_context_menu(self.ui.tableWidget)
        self.set_context_menu2(self.ui.tableWidget_2)
Ejemplo n.º 13
0
def product_dao_test():
    global pdt
    pdt = ProductDao()
    [print(row) for row in pdt.select_product()]
    [
        print(row) for row in pdt.select_product(
            sql="select * from product where code like %s", code='A%')
    ]
    sdt = SaleDao()
    [print(row) for row in sdt.select_item()]
    # sdt.insert_item(code='A001', price=5000, saleCnt=10, marginRate=10)
    [print(row) for row in sdt.select_item(no=1)]
    select_product()
    pdt.insert_product("Insert into product values(%s, %s)", 'C001', '라떼')
    select_product()
    pdt.update_product("update product set name = %s where code = %s", '라떼수정',
                       'C001')
    select_product()
    pdt.delete_product("delete from product where code = %s", 'C001')
    select_product()
Ejemplo n.º 14
0
    def insert_item2(self):
        item_no, item_code, item_price, item_saleCnt, item_marginRate, no, code, price, saleCnt, marginRate \
            = self.get_item_form_le2()

        sale = SaleDao()
        sale.insert_item(code, price, saleCnt, marginRate)
        self.init_item2()

        currentIdx = self.ui.tableWidget_2.rowCount()
        self.ui.tableWidget_2.insertRow(currentIdx)

        sale = SaleDao()
        data2 = sale.select_item()
        self.load_data2(data2)
class SaleMenu(QWidget):
    def __init__(self):
        super().__init__()
        self.ui = uic.loadUi("ui/sale_manage.ui")
        self.pdt = ProductDao()
        self.sdt = SaleDao()
        self.ui.table_sale.setColumnCount(7)
        self.ui.table_order.setColumnCount(3)
        self.table_order = create_table(table=self.ui.table_order,
                                        data=['제품명', '종류', '갯수'])
        self.table_sale_detail = create_table(
            table=self.ui.table_sale,
            data=['제품명', '종류', '판매량', '판매액', '세금', '마진액', '판매 시간'])
        self.load_sale()

        self.ui.combo_menu.addItem('all')
        self.ui.combo_sel_pro.addItem('--select--')
        self.count = 0
        self.nextIdx = 0
        self.namelist = []
        self.order_list = {}

        for i in range(len(self.pdt.select_category())):
            self.ui.combo_menu.addItems(self.pdt.select_category()[i])

        self.ui.combo_category.addItem('all')
        for i in range(len(self.pdt.select_category())):
            self.ui.combo_category.addItems(self.pdt.select_category()[i])
        for i in range(len(self.pdt.select_name())):
            self.ui.combo_sel_pro.addItems(self.pdt.select_name()[i])

        self.ui.btn_insert_menu.clicked.connect(self.ins_menu)
        self.ui.btn_del_menu.clicked.connect(self.del_menu)
        self.ui.btn_edit_menu.clicked.connect(self.edit_menu)
        self.ui.btn_ins_category.clicked.connect(self.category)
        self.ui.combo_menu.currentIndexChanged.connect(self.select_menu)
        self.ui.btn_exit.clicked.connect(self.exit)

        # sale_manage
        self.ui.tab_product.currentChanged.connect(self.tab_change)
        self.ui.btn_insert.clicked.connect(self.ins_order)
        self.ui.combo_category.currentIndexChanged.connect(self.order_category)
        self.ui.btn_edit.clicked.connect(self.edit_order)
        self.ui.btn_delete.clicked.connect(self.del_order)
        self.ui.btn_reset.clicked.connect(self.reset_order)
        self.ui.btn_ok.clicked.connect(self.ok_order)

        # select
        self.ui.btn_select.clicked.connect(self.select_sale_detail)
        self.ui.btn_init.clicked.connect(self.select_init)

        self.set_context_menu(self.ui.table_sale)
        self.set_context_menu_order(self.ui.table_order)

        self.ui.btn_edit_menu.setEnabled(False)
        self.ui.btn_edit.setEnabled(False)
        self.ui.btn_edit_menu.setText('편집시 우클릭')
        self.ui.btn_edit.setText('편집시 주문 현황 우클릭')

        self.ui.show()

    #product manage
    def ins_menu(self):
        item_mode = self.ui.combo_menu.currentText()

        count = 0
        if item_mode == 'all':
            QMessageBox.information(self, '제품 관리', '제품의 종류를 설정해 주세요.',
                                    QMessageBox.Ok)
            count = 1
        else:
            item_code = self.ui.le_pro_code.text().upper()
            item_name = self.ui.le_pro_name.text()
            item_price = self.ui.le_pro_price.text()
            item_margin = self.ui.le_pro_margin.text()
            check_name = [(item_name.upper(), )]
            check_code = [(item_code, )]

        if count == 0:
            if item_code == '':
                QMessageBox.information(self, '제품 관리', '코드를 입력해주세요.',
                                        QMessageBox.Ok)
                count = 1
            else:
                if item_name == '':
                    QMessageBox.information(self, '제품 관리', '제품명을 입력해주세요.',
                                            QMessageBox.Ok)
                    count = 1

                elif check_code == self.pdt.select_check_menu_code(item_code):
                    QMessageBox.information(self, '제품 관리', '코드가 이미 있습니다.',
                                            QMessageBox.Ok)
                    count = 1

                else:
                    if check_name == self.pdt.select_check_menu_name(
                            item_name):
                        QMessageBox.information(self, '제품 관리',
                                                '해당 메뉴가 이미 있습니다.',
                                                QMessageBox.Ok)
                        count = 1

                    elif item_price == '':
                        QMessageBox.information(self, '제품 관리', '가격을 입력해주세요.',
                                                QMessageBox.Ok)
                        count = 1
                    else:
                        if item_margin == '':
                            QMessageBox.information(self, '제품 관리',
                                                    '마진율을 입력해주세요.',
                                                    QMessageBox.Ok)
                            count = 1

        if count == 0:
            self.pdt.insert_item(item_code, item_name, item_mode, item_price,
                                 item_margin)
            self.load_pro_all()

    def del_menu(self):
        selectionIdxs = self.ui.table_sale.selectedIndexes()[0]
        item_code = self.ui.table_sale.item(selectionIdxs.row(),
                                            0).text().upper()
        category = self.ui.combo_menu.currentText()
        self.pdt.delete_item(item_code)
        if category == 'all':
            self.load_pro_all()
        else:
            res = list(self.pdt.select_menu(self.ui.combo_menu.currentText()))
            self.load_pro(res)

    def edit_menu(self):
        code = self.ui.le_pro_code.text()
        category = self.ui.combo_menu.currentText()
        name = self.ui.le_pro_name.text()
        price = self.ui.le_pro_price.text()
        margin = self.ui.le_pro_margin.text()

        if category == 'all':
            QMessageBox.information(self, '제품 관리', '제품의 종류 설정해 주세요.',
                                    QMessageBox.Ok)
        else:
            item_code, item_name, item_price, item_margin = self.pro_create_item(
                code, name, price, margin)

            countIdxs = self.ui.table_sale.rowCount()

            self.ui.table_sale.setItem(countIdxs, 0, item_code)
            self.ui.table_sale.setItem(countIdxs, 1, item_name)
            self.ui.table_sale.setItem(countIdxs, 3, item_price)
            self.ui.table_sale.setItem(countIdxs, 4, item_margin)

            self.pdt.update_item(name, price, margin, category, code)
            QMessageBox.information(self, '사용자 관리', '확인', QMessageBox.Ok)

            self.ui.btn_del_menu.setEnabled(True)
            self.ui.btn_insert_menu.setEnabled(True)
            self.ui.btn_edit_menu.setEnabled(False)
            self.ui.btn_edit_menu.setText('편집시 우클릭')
            self.ui.le_pro_code.setEnabled(True)
            self.ui.btn_insert.setEnabled(False)
            self.ui.btn_ins_category.setEnabled(True)
            self.ui.btn_ins_category.clicked.connect(self.category)

            self.ui.le_pro_price.clear()
            self.ui.le_pro_code.clear()
            self.ui.le_pro_margin.clear()
            self.ui.le_pro_name.clear()
            if category == 'all':
                self.load_pro_all()
            else:
                res = list(
                    self.pdt.select_menu(self.ui.combo_menu.currentText()))
                self.load_pro(res)

    def load_pro(self, res):
        self.ui.table_sale.setRowCount(0)
        for (code, name, category, price, marginrate) in res:
            item_code, item_name, item_category, item_price, item_marginrate = self.pro_create_item(
                code,
                name,
                category,
                price,
                marginrate,
            )
            nextIdx = self.ui.table_sale.rowCount()
            self.ui.table_sale.insertRow(nextIdx)
            self.ui.table_sale.setItem(nextIdx, 0, item_code)
            self.ui.table_sale.setItem(nextIdx, 1, item_name)
            self.ui.table_sale.setItem(nextIdx, 2, item_category)
            self.ui.table_sale.setItem(nextIdx, 3, item_price)
            self.ui.table_sale.setItem(nextIdx, 4, item_marginrate)

    def pro_create_item(self, code, name, price, marginrate, category):
        item_code = QTableWidgetItem()
        item_code.setTextAlignment(Qt.AlignCenter)
        item_code.setData(Qt.DisplayRole, code)

        item_name = QTableWidgetItem()
        item_name.setTextAlignment(Qt.AlignCenter)
        item_name.setData(Qt.DisplayRole, name)

        item_category = QTableWidgetItem()
        item_category.setTextAlignment(Qt.AlignCenter)
        item_category.setData(Qt.DisplayRole, category)

        item_price = QTableWidgetItem()
        item_price.setTextAlignment(Qt.AlignRight)
        if price != None:
            item_price.setData(Qt.DisplayRole, format(int(price), ',d'))
        else:
            item_price.setData(Qt.DisplayRole, '-')

        item_marginrate = QTableWidgetItem()
        item_marginrate.setTextAlignment(Qt.AlignRight)
        if marginrate != None:
            item_marginrate.setData(Qt.DisplayRole, (marginrate))
        else:
            item_marginrate.setData(Qt.DisplayRole, '-')

        return item_code, item_name, item_category, item_price, item_marginrate

    def select_menu(self):
        if self.ui.combo_menu.currentText() == 'all':
            self.load_pro_all()
        else:
            res = list(self.pdt.select_menu(self.ui.combo_menu.currentText()))
            self.load_pro(res)

    def load_pro_all(self):
        self.ui.table_sale.setRowCount(0)
        res = self.pdt.select_menu2()
        for (code, name, category, price, marginrate) in res:
            item_code, item_name, item_category, item_price, item_marginrate = self.pro_create_item(
                code, name, category, price, marginrate)
            nextIdx = self.ui.table_sale.rowCount()
            self.ui.table_sale.insertRow(nextIdx)
            self.ui.table_sale.setItem(nextIdx, 0, item_code)
            self.ui.table_sale.setItem(nextIdx, 1, item_name)
            self.ui.table_sale.setItem(nextIdx, 2, item_category)
            self.ui.table_sale.setItem(nextIdx, 3, item_price)
            self.ui.table_sale.setItem(nextIdx, 4, item_marginrate)

    def set_context_menu(self, tv):
        tv.setContextMenuPolicy(Qt.ActionsContextMenu)
        update_action = QAction('수정', tv)
        tv.addAction(update_action)
        update_action.triggered.connect(self.update)

    def update(self):
        selectionIdxs = self.ui.table_sale.selectedIndexes()[0]
        QMessageBox.information(self, '제품 관리', '제품의 종류 설정해 주세요.',
                                QMessageBox.Ok)
        returnIdxs1 = self.ui.table_sale.item(selectionIdxs.row(), 0).text()
        returnIdxs2 = self.ui.table_sale.item(selectionIdxs.row(), 1).text()
        if self.ui.table_sale.item(selectionIdxs.row(),
                                   3).text().count(',') >= 1:
            returnIdxs3 = self.ui.table_sale.item(
                selectionIdxs.row(),
                3).text().split(',')[0] + self.ui.table_sale.item(
                    selectionIdxs.row(), 3).text().split(',')[1]
        else:
            returnIdxs3 = self.ui.table_sale.item(selectionIdxs.row(),
                                                  3).text()
        returnIdxs4 = self.ui.table_sale.item(selectionIdxs.row(), 3).text()

        self.ui.le_pro_code.setText(returnIdxs1)
        self.ui.le_pro_name.setText(returnIdxs2)
        self.ui.le_pro_price.setText(returnIdxs3)
        self.ui.le_pro_margin.setText(returnIdxs4)

        self.ui.btn_insert.setEnabled(False)
        self.ui.btn_del_menu.setEnabled(False)
        self.ui.btn_insert_menu.setEnabled(False)
        self.ui.btn_edit_menu.setEnabled(True)
        self.ui.btn_edit_menu.setText('편집')
        self.ui.le_pro_code.setEnabled(False)
        self.ui.btn_ins_category.setEnabled(False)

    def category(self):
        self.ca = Category()

        self.ca.ui.btn_ins_category.clicked.connect(self.init_category)
        self.ca.ui.btn_del_category.clicked.connect(self.init_category2)
        self.ca.ui.btn_edit_category.clicked.connect(self.init_category)

    def init_category(self):
        cdt = CateDao()
        for i in range(len(cdt.select_item()) + 1):
            self.ui.combo_menu.removeItem(0)
        self.ui.combo_menu.addItem('all')
        for i in range(len(cdt.select_item())):
            self.ui.combo_menu.addItems(self.pdt.select_category()[i])

        self.load_pro_all()

    def init_category2(self):
        cdt = CateDao()
        for i in range(len(cdt.select_item()) + 2):
            self.ui.combo_menu.removeItem(0)
        self.ui.combo_menu.addItem('all')
        for i in range(len(cdt.select_item())):
            self.ui.combo_menu.addItems(self.pdt.select_category()[i])

        self.load_pro_all()

    def load_order(self):
        index = self.ui.tab_product.currentIndex()
        if self.ui.tab_product.tabText(index) == '제품 관리 (&1)':
            self.ui.table_sale.setColumnCount(5)
            self.table_sale = create_table(
                table=self.ui.table_sale,
                data=['제품코드', '제품명', '종류', '제품가격', '마진율(%)'])
            self.load_pro_all()
            self.ui.table_order.hide()
            self.ui.lb_order.hide()

        elif self.ui.tab_product.tabText(index) == '판매 관리 (&2)':
            self.ui.table_sale.setColumnCount(7)
            self.table_sale_detail = create_table(
                table=self.ui.table_sale,
                data=['제품명', '종류', '판매량', '판매액', '세금', '마진액', '판매 시간'])
            self.ui.table_order.setColumnCount(3)
            self.table_sale_order = create_table(table=self.ui.table_order,
                                                 data=['제품명', '종류', '갯수'])
            self.ui.table_order.show()
            self.ui.lb_order.show()
            self.load_sale()

        elif self.ui.tab_product.tabText(index) == '검색 (&3)':
            self.ui.table_sale.setColumnCount(4)
            self.table_select = create_table(
                table=self.ui.table_sale, data=['제품명', '판매량', '판매가', '판매시간'])
            self.ui.table_order.hide()
            self.ui.lb_order.hide()
            self.load_select()

    def order_category(self):
        self.init_combo_pro_name()
        category = self.ui.combo_category.currentText()
        res = list(self.pdt.select_order_name(category))
        for i in range(len(self.pdt.select_order_name(category))):
            self.ui.combo_pro_name.addItems(res[i])
            self.count += 1

    def ins_order(self):
        name = self.ui.combo_pro_name.currentText()
        category = self.pdt.select_order_name_category(name)
        category = str(category).strip(("[('")).strip("',)]")
        cnt = self.ui.le_salecnt.text()

        if name in self.order_list.keys():
            self.order_list[name] = int(self.order_list[name]) + int(cnt)
        else:
            self.order_list[name] = int(cnt)
            self.namelist.append(name)

        item_name = QTableWidgetItem()
        item_name.setTextAlignment(Qt.AlignCenter)
        item_name.setData(Qt.DisplayRole, name)

        item_category = QTableWidgetItem()
        item_category.setTextAlignment(Qt.AlignCenter)
        item_category.setData(Qt.DisplayRole, category)

        item_cnt = QTableWidgetItem()
        item_cnt.setTextAlignment(Qt.AlignRight)
        item_cnt.setData(Qt.DisplayRole, cnt)

        self.ui.table_order.insertRow(self.nextIdx)
        self.ui.table_order.setItem(self.nextIdx, 0, item_name)
        self.ui.table_order.setItem(self.nextIdx, 1, item_category)
        self.ui.table_order.setItem(self.nextIdx, 2, item_cnt)

        self.nextIdx += 1
        self.ui.le_salecnt.clear()

    def init_combo_pro_name(self):
        for i in range(self.count):
            self.ui.combo_pro_name.removeItem(0)
        self.count = 0

    def tab_change(self):
        self.init_combo_pro_name()
        for i in range(len(self.pdt.select_category()) + 1):
            self.ui.combo_category.removeItem(0)
        self.ui.combo_category.addItem('--select--')
        for i in range(len(self.pdt.select_category())):
            self.ui.combo_category.addItems(self.pdt.select_category()[i])
            self.count += 1
        self.load_order()

    def edit_order(self):
        try:
            self.ui.btn_edit.setText('편집시 우클릭')
            self.ui.btn_ok.setEnabled(True)
            self.ui.btn_reset.setEnabled(True)
            self.ui.btn_delete.setEnabled(True)
            self.ui.btn_exit.setEnabled(True)
            self.ui.btn_insert.setEnabled(True)

            self.ui.btn_edit.setEnabled(False)

            selectionIdxs = self.ui.table_order.selectedIndexes()[0]
            cnt = self.ui.le_salecnt.text()

            item_cnt = QTableWidgetItem()
            item_cnt.setTextAlignment(Qt.AlignCenter)
            item_cnt.setData(Qt.DisplayRole, int(cnt))

            self.ui.table_order.setItem(selectionIdxs.row(), 2, item_cnt)
        except Error as err:
            print(err)

    def del_order(self):
        selectionIdxs = self.ui.table_order.selectedIndexes()[0]
        self.ui.table_order.removeRow(selectionIdxs.row())

    def reset_order(self):
        for i in range(self.nextIdx):
            self.ui.table_order.removeRow(0)
        self.nextIdx = 0

    def load_sale(self):
        self.ui.table_sale.setRowCount(0)
        res = self.sdt.select_sale_table()
        for (name, category, cnt, sale_price, tax, margin_price, time) in res:
            item_name, item_category, item_cnt, item_sale_price, item_tax, item_margin_price, item_time = self.sale_create_item(
                name, category, cnt, sale_price, tax, margin_price, time)
            nextIdx = self.ui.table_sale.rowCount()
            self.ui.table_sale.insertRow(nextIdx)
            self.ui.table_sale.setItem(nextIdx, 0, item_name)
            self.ui.table_sale.setItem(nextIdx, 1, item_category)
            self.ui.table_sale.setItem(nextIdx, 2, item_cnt)
            self.ui.table_sale.setItem(nextIdx, 3, item_sale_price)
            self.ui.table_sale.setItem(nextIdx, 4, item_tax)
            self.ui.table_sale.setItem(nextIdx, 5, item_margin_price)
            self.ui.table_sale.setItem(nextIdx, 6, item_time)

    def sale_create_item(self, name, category, cnt, sale_price, tax,
                         margin_price, time):
        item_name = QTableWidgetItem()
        item_name.setTextAlignment(Qt.AlignCenter)
        item_name.setData(Qt.DisplayRole, name)

        item_category = QTableWidgetItem()
        item_category.setTextAlignment(Qt.AlignCenter)
        item_category.setData(Qt.DisplayRole, category)

        item_name = QTableWidgetItem()
        item_name.setTextAlignment(Qt.AlignCenter)
        item_name.setData(Qt.DisplayRole, name)

        item_cnt = QTableWidgetItem()
        item_cnt.setTextAlignment(Qt.AlignRight)
        if cnt != None:
            item_cnt.setData(Qt.DisplayRole, format(int(cnt), ',d'))
        else:
            item_cnt.setData(Qt.DisplayRole, '-')

        item_sale_price = QTableWidgetItem()
        item_sale_price.setTextAlignment(Qt.AlignRight)
        item_sale_price.setData(Qt.DisplayRole, format(int(sale_price), ',d'))

        item_tax = QTableWidgetItem()
        item_tax.setTextAlignment(Qt.AlignRight)
        item_tax.setData(Qt.DisplayRole, format(int(tax), ',d'))

        item_margin_price = QTableWidgetItem()
        item_margin_price.setTextAlignment(Qt.AlignRight)
        item_margin_price.setData(Qt.DisplayRole,
                                  format(int(margin_price), ',d'))

        item_time = QTableWidgetItem()
        item_time.setTextAlignment(Qt.AlignCenter)
        item_time.setData(Qt.DisplayRole, time)

        return item_name, item_category, item_cnt, item_sale_price, item_tax, item_margin_price, item_time

    def set_context_menu_order(self, tv):
        tv.setContextMenuPolicy(Qt.ActionsContextMenu)
        update_action = QAction('수정', tv)
        tv.addAction(update_action)
        update_action.triggered.connect(self.update_order)

    def update_order(self, tv):
        selectionIdxs = self.ui.table_order.selectedIndexes()[0]

        returnIdxs = self.ui.table_order.item(selectionIdxs.row(), 2).text()
        self.ui.le_salecnt.setText(returnIdxs)

        self.ui.btn_ok.setEnabled(False)
        self.ui.btn_reset.setEnabled(False)
        self.ui.btn_insert.setEnabled(False)
        self.ui.btn_delete.setEnabled(False)
        self.ui.btn_exit.setEnabled(False)

        self.ui.btn_edit.setText('편집')
        self.ui.btn_edit.setEnabled(True)

    def ok_order(self):
        self.ui.table_order.setRowCount(0)
        for i in range(len(self.namelist)):
            self.sdt.insert_item(self.namelist[i],
                                 self.order_list[self.namelist[i]])

        self.ui.le_salecnt.clear()
        self.nextIdx = 0
        self.load_sale()

    # tab index = 3
    def load_select(self):
        self.ui.table_sale.setRowCount(0)
        seldt = SelDao()
        res = seldt.select_item_where()
        for (name, cnt, sale_price, date) in res:
            item_name, item_cnt, item_sale_price, item_date = self.select_create_item(
                name, cnt, sale_price, date)
            nextIdx = self.ui.table_sale.rowCount()
            self.ui.table_sale.insertRow(nextIdx)
            self.ui.table_sale.setItem(nextIdx, 0, item_name)
            self.ui.table_sale.setItem(nextIdx, 1, item_cnt)
            self.ui.table_sale.setItem(nextIdx, 2, item_sale_price)
            self.ui.table_sale.setItem(nextIdx, 3, item_date)

    def select_create_item(self, name, cnt, sale_price, date):
        item_name = QTableWidgetItem()
        item_name.setTextAlignment(Qt.AlignCenter)
        item_name.setData(Qt.DisplayRole, name)

        item_cnt = QTableWidgetItem()
        item_cnt.setTextAlignment(Qt.AlignCenter)
        item_cnt.setData(Qt.DisplayRole, format(int(cnt), 'd'))

        item_sale_price = QTableWidgetItem()
        item_sale_price.setTextAlignment(Qt.AlignRight)
        item_sale_price.setData(Qt.DisplayRole, format(int(sale_price), ',d'))

        item_date = QTableWidgetItem()
        item_date.setTextAlignment(Qt.AlignRight)
        item_date.setData(Qt.DisplayRole, date)

        return item_name, item_cnt, item_sale_price, item_date

    def select_sale_detail(self):
        name = self.ui.combo_sel_pro.currentText()
        seldt = SelDao()
        if name == '--select--':
            name = ''
        min_price = self.ui.le_min_price.text()
        max_price = self.ui.le_max_price.text()
        min_date = self.ui.le_min_date_y.text(
        ) + '-' + self.ui.le_min_date_m.text(
        ) + '-' + self.ui.le_min_date_d.text()
        max_date = self.ui.le_max_date_y.text(
        ) + '-' + self.ui.le_max_date_m.text(
        ) + '-' + self.ui.le_max_date_d.text()
        if min_date == '--':
            min_date = ''
        if max_date == '--':
            max_date = ''

        self.ui.table_sale.setRowCount(0)

        res = seldt.select_item_where(name, min_price, max_price, min_date,
                                      max_date)

        for (name, cnt, sale_price, date) in res:
            item_name, item_cnt, item_sale_price, item_date = self.select_create_item(
                name, cnt, sale_price, date)
            nextIdx = self.ui.table_sale.rowCount()
            self.ui.table_sale.insertRow(nextIdx)
            self.ui.table_sale.setItem(nextIdx, 0, item_name)
            self.ui.table_sale.setItem(nextIdx, 1, item_cnt)
            self.ui.table_sale.setItem(nextIdx, 2, item_sale_price)
            self.ui.table_sale.setItem(nextIdx, 3, item_date)

    def select_init(self):
        self.load_select()
        self.ui.le_min_price.setText('0')
        self.ui.le_max_price.clear()
        self.ui.le_min_date_d.clear()
        self.ui.le_min_date_m.clear()
        self.ui.le_min_date_y.clear()
        self.ui.le_max_date_d.clear()
        self.ui.le_max_date_m.clear()
        self.ui.le_max_date_y.clear()

    def exit(self):
        self.ui.close()
db_ticket = ticket_database()

hotel_db = db_hotel.hotel
image_db = db_image.image
firm_db = db_firm.firm
firm_image_db = db_firm_image.firm_image
vehicle_db = db_vehicle.vehicle
driver_db = db_driver.driver
expedition_db = db_expedition.expedition
seat_db = db_seat.seat
ticket_db = db_ticket.ticket

userop = UserDao()
city_db = CityDao()
terminalop = TerminalDao()
sale_db = SaleDao()

salt = "3re"

today = datetime.today()

str_today = str(today.month) + '/' + str(today.day) + '/' + str(today.year)


def dayCompare(toCompare):
    t0 = str_today.split('/', 3)
    t1 = toCompare.split('/', 3)
    if t0[2] > t1[2]:
        return False
    elif t0[2] == t1[2]:
        if t0[1] > t1[1]:
Ejemplo n.º 17
0
 def delete_item2(self):
     sale = SaleDao()
     selectionIdx = self.ui.tableWidget_2.selectedIndexes()[0]
     sale_no = self.ui.tableWidget_2.item(selectionIdx.row(), 0).text()
     sale.delete_item(no=sale_no)
     self.ui.tableWidget_2.removeRow(selectionIdx.row())
Ejemplo n.º 18
0
class Main(QtWidgets.QMainWindow):
    def __init__(self, *args, **kwargs):
        super().__init__()
        self.pdt = ProductDao()
        self.idt = IDDao()
        self.sdt = SaleDao()
        self.ui = uic.loadUi("ui/main_menu.ui", self)

        self.month_count = 14
        self.graphcount = 0

        # combobox
        self.combobox_setting()

        # graph
        self.graph()

        # table
        self.table_pro = create_table(table=self.ui.table_pro, data=['제품코드', '제품명', '종류', '제품가격', '마진율(%)'])
        self.sale_pro = create_table(table=self.ui.table_sale, data=['제품명', '판매량', '판매금액', '판매일'])

        self.load_pro_all()
        self.load_sale_all()

        self.ui.btn_out.clicked.connect(self.exit)  # logout
        self.ui.btn_manage.clicked.connect(self.manage)
        self.ui.btn_sale.clicked.connect(self.sale_manage)
        self.ui.btn_exit.clicked.connect(self.exit)
        self.ui.btn_set.clicked.connect(self.user_setting)
        self.ui.combo_menu.currentIndexChanged.connect(self.select_menu)
        self.ui.combo_sale_year.currentIndexChanged.connect(self.select_sale)
        self.ui.combo_sale_month.currentIndexChanged.connect(self.select_month)
        self.ui.show()

    # button ui
    def manage(self):
        self.ms = management_system()
        self.ms.ui.lbl_ID.setText(self.ui.lbl_ID.text())
        self.ms.ui.lbl_mode.setText(list(self.idt.select_item(self.ui.lbl_ID.text()))[0][1])
        self.ms.check_grant()

    def sale_manage(self):
        self.sale = SaleMenu()
        grant = []
        for i in range(len(IDDao().select_grant('admin'))):
            a = IDDao().select_grant(self.ui.lbl_mode.text()).count(IDDao().select_grant('admin')[i])
            grant.append(a)
        if grant[2] == 0:
            self.sale.ui.tab_product.removeTab(0)

    def logout(self):
        self.ui.close()

    def exit(self):
        self.ui.close()

    def combobox_setting(self):
        self.ui.combo_menu.addItem('all')
        self.ui.combo_sale_year.addItem('all')
        self.ui.combo_sale_month.addItem('년도를 선택해주세요')

        for i in range(len(self.pdt.select_category())):
            self.ui.combo_menu.addItems(self.pdt.select_category()[i])
        for i in range(len(self.sdt.select_item(True))):
            self.ui.combo_sale_year.addItems(tuple(self.sdt.select_item(True)[i]))

    # product table
    def select_menu(self):
        if self.ui.combo_menu.currentText() == 'all':
            self.load_pro_all()
        else:
            res = list(self.pdt.select_menu(self.ui.combo_menu.currentText()))
            self.load_pro(res)

    def load_pro(self, res):
        self.ui.table_pro.setRowCount(0)
        for (code, name, price, marginrate, category) in res:
            item_code, item_name, item_price, item_marginrate, item_category = self.pro_create_item(code, name, price,
                                                                                                    marginrate,
                                                                                                    category)
            nextIdx = self.ui.table_pro.rowCount()
            self.ui.table_pro.insertRow(nextIdx)
            self.ui.table_pro.setItem(nextIdx, 0, item_code)
            self.ui.table_pro.setItem(nextIdx, 1, item_name)
            self.ui.table_pro.setItem(nextIdx, 2, item_category)
            self.ui.table_pro.setItem(nextIdx, 3, item_price)
            self.ui.table_pro.setItem(nextIdx, 4, item_marginrate)

    def pro_create_item(self, code, name, price, marginrate, category):
        item_code = QTableWidgetItem()
        item_code.setTextAlignment(Qt.AlignCenter)
        item_code.setData(Qt.DisplayRole, code)

        item_name = QTableWidgetItem()
        item_name.setTextAlignment(Qt.AlignCenter)
        item_name.setData(Qt.DisplayRole, name)

        item_price = QTableWidgetItem()
        item_price.setTextAlignment(Qt.AlignRight)
        if price != None:
            item_price.setData(Qt.DisplayRole, format(int(price), ',d'))
        else:
            item_price.setData(Qt.DisplayRole, '-')

        item_marginrate = QTableWidgetItem()
        item_marginrate.setTextAlignment(Qt.AlignRight)
        if marginrate != None:
            item_marginrate.setData(Qt.DisplayRole, (marginrate))
        else:
            item_marginrate.setData(Qt.DisplayRole, '-')

        item_category = QTableWidgetItem()
        item_category.setTextAlignment(Qt.AlignCenter)
        item_category.setData(Qt.DisplayRole, category)

        return item_code, item_name, item_price, item_marginrate, item_category

    def load_pro_all(self):
        self.ui.table_pro.setRowCount(0)
        res = self.pdt.select_menu2()
        for (code, name, price, marginrate, category) in res:
            item_code, item_name, item_price, item_marginrate, item_category = self.pro_create_item(code, name, price,
                                                                                                    marginrate,
                                                                                                    category)
            nextIdx = self.ui.table_pro.rowCount()
            self.ui.table_pro.insertRow(nextIdx)
            self.ui.table_pro.setItem(nextIdx, 0, item_code)
            self.ui.table_pro.setItem(nextIdx, 1, item_name)
            self.ui.table_pro.setItem(nextIdx, 2, item_category)
            self.ui.table_pro.setItem(nextIdx, 3, item_price)
            self.ui.table_pro.setItem(nextIdx, 4, item_marginrate)

    # sale_table
    def sale_create_item(self, name, salecnt, sale_price, date):
        item_name = QTableWidgetItem()
        item_name.setTextAlignment(Qt.AlignCenter)
        item_name.setData(Qt.DisplayRole, name)

        item_salecnt = QTableWidgetItem()
        item_salecnt.setTextAlignment(Qt.AlignCenter)
        item_salecnt.setData(Qt.DisplayRole, salecnt)

        item_sale_price = QTableWidgetItem()
        item_sale_price.setTextAlignment(Qt.AlignRight)
        item_sale_price.setData(Qt.DisplayRole, format(int(sale_price), ',d'))

        item_date = QTableWidgetItem()
        item_date.setTextAlignment(Qt.AlignCenter)
        item_date.setData(Qt.DisplayRole, date)

        return item_name, item_salecnt, item_sale_price, item_date

    def load_sale_all(self):
        self.ui.table_sale.setRowCount(0)
        res = self.sdt.select_item()
        for (name, salecnt, sale_price, date) in res:
            item_name, item_salecnt, item_sale_price, item_date = self.sale_create_item(name, salecnt, sale_price, date)
            nextIdx = self.ui.table_sale.rowCount()
            self.ui.table_sale.insertRow(nextIdx)
            self.ui.table_sale.setItem(nextIdx, 0, item_name)
            self.ui.table_sale.setItem(nextIdx, 1, item_salecnt)
            self.ui.table_sale.setItem(nextIdx, 2, item_sale_price)
            self.ui.table_sale.setItem(nextIdx, 3, item_date)

    def select_sale(self):
        if self.ui.combo_sale_year.currentText() == 'all':
            for i in range(0, self.month_count):
                self.ui.combo_sale_month.removeItem(0)
            self.ui.combo_sale_month.addItem('년도를 선택해주세요')
            self.load_sale_all()
        else:
            res = list(self.sdt.select_date(self.ui.combo_sale_year.currentText()))

            for i in range(0, self.month_count):
                self.ui.combo_sale_month.removeItem(0)
            self.ui.combo_sale_month.addItem('all')
            self.load_sale(res)
            for i in range(len(self.sdt.select_date(self.ui.combo_sale_year.currentText(), 2))):
                self.ui.combo_sale_month.addItems(self.sdt.select_date(self.ui.combo_sale_year.currentText(), 2)[i])

    def load_sale(self, res):
        self.ui.table_sale.setRowCount(0)

        for (name, salecnt, sale_price, date) in res:
            item_name, item_salecnt, item_sale_price, item_date = self.sale_create_item(name, salecnt, sale_price, date)
            nextIdx = self.ui.table_sale.rowCount()
            self.ui.table_sale.insertRow(nextIdx)
            self.ui.table_sale.setItem(nextIdx, 0, item_name)
            self.ui.table_sale.setItem(nextIdx, 1, item_salecnt)
            self.ui.table_sale.setItem(nextIdx, 2, item_sale_price)
            self.ui.table_sale.setItem(nextIdx, 3, item_date)

    def select_month(self, res):
        if self.ui.combo_sale_month.currentText() is None or self.ui.combo_sale_month.currentText() == 'all':
            self.load_sale(self.sdt.select_date(self.ui.combo_sale_year.currentText()))
        else:
            date = self.sdt.select_date(
                self.ui.combo_sale_year.currentText() + ' ' + self.ui.combo_sale_month.currentText(), 3)
            self.load_sale(date)

    # 계정관리
    def user_setting(self):
        self.set = Setting()
        self.set.ui.lbl_id.setText(self.ui.lbl_ID.text())
        self.set.ui.lbl_name.setText(self.idt.select_item_id(self.ui.lbl_ID.text())[0][0])
        self.set.ui.lbl_mode.setText(self.idt.select_item_id(self.ui.lbl_ID.text())[0][1])

    # graph
    def graph(self):
        # 글꼴
        mpl.rcParams['font.family'] = 'NanumGothic'
        mpl.rcParams['axes.unicode_minus'] = False
        # data
        name, price = self.sdt.select_graph()
        fig, ax1 = plt.subplots()

        # plot
        self.plotWidget = FigureCanvas(fig)


        ax1.set_title("커피 판매량")
        self.lay = QtWidgets.QVBoxLayout(self.ui.content_plot)
        self.lay.addWidget(self.plotWidget)

        ax1.pie(price, labels=name, autopct=lambda pct: self.func(pct, price), shadow=False,
                     startangle=90, radius=1.0)

    def func(self, pct, data):
        absolute = round(int(pct * float(math.ceil(np.sum(data)))) / 100)
        return "{:.1f}%\n({:,d})".format(pct, absolute)