Ejemplo n.º 1
0
 def UpdateAll(self, sAttr):
     value = getattr(self, sAttr, None)
     assert value is not None
     value = mydefines.get_insert_value(value, "blob")
     sql = "update %s set Data=%s where Name='%s'" % (TABLE_NAME, value,
                                                      sAttr)
     pubdefines.call_manager_func("dbmgr", "Excute", sql)
Ejemplo n.º 2
0
    def OutputGoods(self):
        if not self.ValidOutput():
            return
        self.dateEditOutput.setTime(QtCore.QTime.currentTime())
        oDataTime = self.dateEditOutput.dateTime()
        iTime = oDataTime.toTime_t()
        sGoods = self.comboBoxOutputGoods.currentText()
        sBuyer = self.comboBoxOutputBuyer.currentText()
        fPrice = float(self.lineEditOutputPrice.text())
        iNum = int(self.lineEditOutputNum.text())
        sRemark = self.lineEditOutputRemark.text()

        tInfo = [iTime, sGoods, sBuyer, fPrice, iNum, sRemark]
        logging.info("OutputGoods:%s" % (tInfo, ))
        self.Log("Output %s" % (tInfo))
        # 计算本次卖出的利润为多少
        fProfile = pubdefines.call_manager_func("goodsmgr", "OutputGoods",
                                                sGoods, fPrice, iNum)
        assert fProfile is not None

        tInfo.append(fProfile)
        pubdefines.call_manager_func("sellmgr", "OutputGoods", tInfo)
        pubdefines.call_manager_func("globalmgr", "AddBuyer", sBuyer)
        self.Log("OutputDone %s" % iTime)
        self.slotInformation("出货成功")
        self.InitOutput()
Ejemplo n.º 3
0
 def Update(self, sGoods, tInfo):
     lstSet = []
     for iIndex, value in enumerate(tInfo):
         sColName, sType = self.ColInfo[iIndex + self.KeyNum]
         value = mydefines.get_insert_value(value, sType)
         lstSet.append("%s=%s" % (sColName, value))
     sSet = ",".join(lstSet)
     sql = "update %s set %s where Goods='%s'" % (TABLE_NAME, sSet, sGoods)
     pubdefines.call_manager_func("dbmgr", "Excute", sql)
Ejemplo n.º 4
0
 def ImportBuyer(self):
     """批量导入买家"""
     sTexts = self.textEditImport.toPlainText()
     lstText = sTexts.split("\n")
     for sBuyer in lstText:
         if not sBuyer:
             continue
         pubdefines.call_manager_func("globalmgr", "AddBuyer", sBuyer)
     self.textEditImport.setText("")
Ejemplo n.º 5
0
 def ImportGoods(self):
     """根据商品类型批量导入商品"""
     sGoodsType = self.comboBoxImportGoodsType.currentText()
     sTexts = self.textEditImport.toPlainText()
     lstText = sTexts.split("\n")
     for sGoods in lstText:
         if not sGoods:
             continue
         pubdefines.call_manager_func("globalmgr", "AddGoods", sGoodsType,
                                      sGoods)
     self.textEditImport.setText("")
Ejemplo n.º 6
0
 def InitOutputRecord(self):
     oCurData = QtCore.QDate.currentDate()
     self.dateEditBeginOutputRecord.setDate(oCurData.addMonths(-1))
     self.dateEditEndOutputRecord.setDate(oCurData)
     self.comboBoxOutputRecordGoods.clear()
     lstGoods = pubdefines.call_manager_func("globalmgr", "GetAllGoodsList")
     self.comboBoxOutputRecordGoods.addItems(lstGoods)
     self.comboBoxOutputRecordGoods.setCurrentIndex(-1)
     self.comboBoxOutputRecordBuyer.clear()
     lstBuyer = pubdefines.call_manager_func("globalmgr", "GetAllBuyer")
     self.comboBoxOutputRecordBuyer.addItems(lstBuyer)
     self.comboBoxOutputRecordBuyer.setCurrentIndex(-1)
Ejemplo n.º 7
0
 def FocusOutOutputGoods(self):
     """卖出商品:当输入完商品之后自动填写价格"""
     sGoods = self.comboBoxOutputGoods.text()
     if not sGoods:
         return
     if not pubdefines.call_manager_func("goodsmgr", "HasGoods", sGoods):
         # self.slotInformation("库存中无商品记录")
         return
     fPrice = pubdefines.call_manager_func("goodsmgr", "GetGoodsSellPrice",
                                           sGoods)
     if abs(fPrice) > 1e-6:
         self.lineEditOutputPrice.setText(str(fPrice))  # 价格自动变
Ejemplo n.º 8
0
 def InitOutput(self):
     """初始化卖出商品界面"""
     oCurData = QtCore.QDate.currentDate()
     self.dateEditOutput.setDate(oCurData)
     self.comboBoxOutputGoods.clear()
     self.comboBoxOutputBuyer.clear()
     lstGoods = pubdefines.call_manager_func("globalmgr", "GetAllGoodsList")
     self.comboBoxOutputGoods.addItems(lstGoods)
     lstBuyer = pubdefines.call_manager_func("globalmgr", "GetAllBuyer")
     self.comboBoxOutputBuyer.addItems(lstBuyer)
     self.comboBoxOutputGoods.setCurrentIndex(-1)
     self.comboBoxOutputBuyer.setCurrentIndex(-1)
     self.lineEditOutputNum.setText("")
     self.lineEditOutputPrice.setText("")
     self.lineEditOutputRemark.setText("")
Ejemplo n.º 9
0
    def QueryProfile(self):
        """查询利润"""
        oBeginDate = self.dateEditBegin.date()
        sBeginTime = oBeginDate.toString("yyyy-MM-dd 00:00:00")
        iBeginTime = pubdefines.str_to_time(sBeginTime)
        oEndDate = self.dateEditEnd.date()
        sEndTime = oEndDate.toString("yyyy-MM-dd 23:59:59")
        iEndTime = pubdefines.str_to_time(sEndTime)
        self.MaxProfileCol = 0
        dSellInfo = pubdefines.call_manager_func("sellmgr", "GetSellInfo",
                                                 iBeginTime, iEndTime)
        self.ProfileInfo = {}
        for _, tSellInfo in dSellInfo.items():
            iTime = tSellInfo[0]
            sTime = pubdefines.time_to_str(iTime)
            sGoods = tSellInfo[1]
            fProfile = tSellInfo[6]

            sDayTime = sTime[:10]
            sMonthTime = sTime[:7]
            sYearTime = sTime[:4]
            self.AddProfile(sGoods, sDayTime, fProfile)
            self.AddProfile(sGoods, sMonthTime + "月", fProfile)
            self.AddProfile(sGoods, sYearTime + "年", fProfile)
            self.AddProfile(sGoods, "总利润", fProfile)

        iGoodsNum = len(self.ProfileInfo)
        self.tableWidgetProfile.setRowCount(iGoodsNum)

        lstTime = [
            "总利润",
        ]
        sLastYear = ""
        while oBeginDate.toString("yyyy-MM") <= oEndDate.toString("yyyy-MM"):
            sCurYear = oBeginDate.toString("yyyy")
            if sLastYear != sCurYear:
                lstTime.append(sCurYear + "年")
                sLastYear = sCurYear
            lstTime.append(oBeginDate.toString("yyyy-MM") + "月")
            oBeginDate = oBeginDate.addMonths(1)

        self.tableWidgetProfile.setColumnCount(len(lstTime) + 1)

        lstGoods = [sGoods for sGoods in self.ProfileInfo]

        lstTitle = lstTime[:]
        lstTitle.insert(0, "商品")
        self.tableWidgetProfile.setHorizontalHeaderLabels(lstTitle)
        # if len(lstTitle) < 14:
        #     self.tableWidgetProfile.horizontalHeader().setSectionResizeMode(QtWidgets.QHeaderView.Stretch)

        for iRow, sGoods in enumerate(lstGoods):
            item = QtWidgets.QTableWidgetItem(sGoods)
            item.setTextAlignment(QtCore.Qt.AlignCenter)
            self.tableWidgetProfile.setItem(iRow, 0, item)
            for iCol, sTime in enumerate(lstTime):
                fProfile = self.GetProfileByDate(sGoods, sTime)
                item = QtWidgets.QTableWidgetItem(str(fProfile))
                item.setTextAlignment(QtCore.Qt.AlignCenter)
                self.tableWidgetProfile.setItem(iRow, iCol + 1, item)
Ejemplo n.º 10
0
    def QueryOutputRecord(self):
        """查询进货记录"""
        oBeginDate = self.dateEditBeginOutputRecord.date()
        sBeginTime = oBeginDate.toString("yyyy-MM-dd 00:00:00")
        iBeginTime = pubdefines.str_to_time(sBeginTime)
        oEndDate = self.dateEditEndOutputRecord.date()
        sEndTime = oEndDate.toString("yyyy-MM-dd 23:59:59")
        iEndTime = pubdefines.str_to_time(sEndTime)
        sGoods = self.comboBoxOutputRecordGoods.currentText()
        sBuyer = self.comboBoxOutputRecordBuyer.currentText()

        dSellInfo = pubdefines.call_manager_func("sellmgr",
                                                 "GetSellInfoRecord",
                                                 iBeginTime, iEndTime, sGoods,
                                                 sBuyer)
        lstHead = ["日期", "商品", "卖家", "售价", "数量", "备注", "利润"]
        self.tableWidgetOutputRecord.setColumnCount(len(lstHead))
        self.tableWidgetOutputRecord.setRowCount(len(dSellInfo))
        self.tableWidgetOutputRecord.setHorizontalHeaderLabels(lstHead)
        self.tableWidgetOutputRecord.horizontalHeader().setSectionResizeMode(
            QtWidgets.QHeaderView.Stretch)
        iRow = fProfile = 0
        for _, tSellInfo in dSellInfo.items():
            for iCol, xValue in enumerate(tSellInfo):
                if iCol == 0:
                    xValue = pubdefines.time_to_str(xValue)
                if iCol == 6:
                    fProfile += xValue
                item = QtWidgets.QTableWidgetItem(str(xValue))
                item.setTextAlignment(QtCore.Qt.AlignCenter)
                self.tableWidgetOutputRecord.setItem(iRow, iCol, item)
            iRow += 1
        self.labelOutputRecordProfile.setText("总利润:%s" % fProfile)
        self.labelOutputRecordProfile.show()
Ejemplo n.º 11
0
 def InitInput(self):
     """初始化录入商品界面"""
     oCurData = QtCore.QDate.currentDate()
     self.dateEditInput.setDate(oCurData)
     self.comboBoxInputType.clear()
     self.comboBoxInputGoods.clear()
     lstGoodsType = pubdefines.call_manager_func("globalmgr", "GetAllType")
     self.comboBoxInputType.addItems(lstGoodsType)
     lstGoods = pubdefines.call_manager_func("globalmgr", "GetAllGoodsList")
     self.comboBoxInputGoods.addItems(lstGoods)
     self.comboBoxInputType.setCurrentIndex(0)
     self.comboBoxInputGoods.setCurrentIndex(-1)
     self.InputTiplabel.hide()
     self.lineEditInputNum.setText("")
     self.lineEditInputPrice.setText("")
     self.lineEditInputRemark.setText("")
Ejemplo n.º 12
0
    def QueryInputRecord(self):
        """查询进货记录"""
        oBeginDate = self.dateEditBeginInputRecord.date()
        sBeginTime = oBeginDate.toString("yyyy-MM-dd 00:00:00")
        iBeginTime = pubdefines.str_to_time(sBeginTime)
        oEndDate = self.dateEditEndInputRecord.date()
        sEndTime = oEndDate.toString("yyyy-MM-dd 23:59:59")
        iEndTime = pubdefines.str_to_time(sEndTime)
        sGoods = self.comboBoxInputRecord.currentText()

        dbuyInfo = pubdefines.call_manager_func("buymgr", "GetBuyInfoRecord",
                                                iBeginTime, iEndTime, sGoods)
        lstHead = ["日期", "类型", "商品", "进价", "数量", "备注"]
        self.tableWidgetInputRecord.setColumnCount(len(lstHead))
        self.tableWidgetInputRecord.setRowCount(len(dbuyInfo))
        self.tableWidgetInputRecord.setHorizontalHeaderLabels(lstHead)
        self.tableWidgetInputRecord.horizontalHeader().setSectionResizeMode(
            QtWidgets.QHeaderView.Stretch)
        iRow = 0
        for _, tBuyInfo in dbuyInfo.items():
            for iCol, xValue in enumerate(tBuyInfo):
                if iCol == 0:
                    xValue = pubdefines.time_to_str(tBuyInfo[iCol])
                item = QtWidgets.QTableWidgetItem(str(xValue))
                item.setTextAlignment(QtCore.Qt.AlignCenter)
                self.tableWidgetInputRecord.setItem(iRow, iCol, item)
            iRow += 1
Ejemplo n.º 13
0
 def QueryAllInfo(self):
     """查询所有的进货信息"""
     sql = "select * from %s" % TABLE_NAME
     result = pubdefines.call_manager_func("dbmgr", "Query", sql)
     for ID, *tData in result:
         logging.debug("sell query:%s %s" % (ID, tData))
         self.SellInfo[ID] = tData
Ejemplo n.º 14
0
 def FocusOutInputGoods(self):
     """录入商品:当输入完商品之后自动填写类型+价格"""
     sGoods = self.comboBoxInputGoods.text()
     if not sGoods:
         return
     if not pubdefines.call_manager_func("goodsmgr", "HasGoods", sGoods):
         self.InputTiplabel.show()
         return
     self.InputTiplabel.hide()
     fPrice = pubdefines.call_manager_func("goodsmgr", "GetGoodsBuyPrice",
                                           sGoods)
     self.lineEditInputPrice.setText(str(fPrice))  # 价格自动变
     sType = pubdefines.call_manager_func("globalmgr", "GetGoodsType",
                                          sGoods)
     if sType:
         self.comboBoxInputType.setCurrentText(sType)
Ejemplo n.º 15
0
 def ValidOutput(self):
     """卖出商品时控件判断"""
     if not self.lineEditOutputPrice.text():
         self.slotInformation("价格不能为空")
         return False
     if not self.lineEditOutputNum.text():
         self.slotInformation("数量不能为空")
         return False
     if not self.dateEditOutput.dateTime():
         self.slotInformation("日期不能为空")
         return False
     if not self.comboBoxOutputBuyer.currentText():
         self.slotInformation("买家不能为空")
         return False
     if not self.comboBoxOutputGoods.currentText():
         self.slotInformation("商品不能为空")
         return False
     sGoods = self.comboBoxOutputGoods.text()
     if not pubdefines.call_manager_func("goodsmgr", "HasGoods", sGoods):
         self.slotInformation("库存中无商品记录")
         return False
     # iStock = pubdefines.call_manager_func("goodsmgr", "GetGoodsNum", sGoods)
     # iNum = int(self.lineEditOutputNum.text())
     # if iStock < iNum:
     #     self.slotInformation("没有足够的库存,当前库存%s" % iStock)
     #     return False
     return True
Ejemplo n.º 16
0
    def InputGoods(self):
        """点击录入商品调用"""
        if not self.ValidInput():
            return
        self.dateEditInput.setTime(QtCore.QTime.currentTime())
        oDataTime = self.dateEditInput.dateTime()
        iTime = oDataTime.toTime_t()
        sGoodsType = self.comboBoxInputType.currentText()
        sGoods = self.comboBoxInputGoods.currentText()
        fPrice = float(self.lineEditInputPrice.text())
        iNum = int(self.lineEditInputNum.text())
        sRemark = self.lineEditInputRemark.text()

        # TODO 判断是否已经有了.增加商品、价格判断
        tInfo = [iTime, sGoodsType, sGoods, fPrice, iNum, sRemark]
        logging.info("InputGoods:%s" % (tInfo, ))
        self.Log("Input %s" % (tInfo, ))
        pubdefines.call_manager_func("buymgr", "InputGoods", tInfo)
        pubdefines.call_manager_func("goodsmgr", "InputGoods", sGoods, fPrice,
                                     iNum)

        if not pubdefines.call_manager_func("globalmgr", "HasGoods", sGoods):
            pubdefines.call_manager_func("globalmgr", "AddGoods", sGoodsType,
                                         sGoods)
        self.Log("InputDone %s" % iTime)
        self.slotInformation("进货成功")
        self.InitInput()
Ejemplo n.º 17
0
 def InitInputRecord(self):
     oCurData = QtCore.QDate.currentDate()
     self.dateEditBeginInputRecord.setDate(oCurData.addMonths(-1))
     self.dateEditEndInputRecord.setDate(oCurData)
     self.comboBoxInputRecord.clear()
     lstGoods = pubdefines.call_manager_func("globalmgr", "GetAllGoodsList")
     self.comboBoxInputRecord.addItems(lstGoods)
     self.comboBoxInputRecord.setCurrentIndex(-1)
     self.labelInputRecordNum.hide()
Ejemplo n.º 18
0
 def GetSellInfo(self, iBegin, iEnd):
     dSellInfo = {}
     sql = "select * from %s where Time>=%s and Time<=%s" % (TABLE_NAME,
                                                             iBegin, iEnd)
     result = pubdefines.call_manager_func("dbmgr", "Query", sql)
     for ID, *tData in result:
         logging.debug("sell info:%s %s" % (ID, tData))
         dSellInfo[ID] = tData
     return dSellInfo
Ejemplo n.º 19
0
 def Load(self):
     logging.info("%s load" % TABLE_NAME)
     sql = "select * from %s" % TABLE_NAME
     result = pubdefines.call_manager_func("dbmgr", "Query", sql)
     for sGoods, *tInfo in result:
         tInfo[3] = mydefines.get_value_by_data(tInfo[3], "blob")
         self.GoodsInfo[sGoods] = tInfo
         logging.debug("load: %s %s" % (sGoods, tInfo))
     logging.info("    load finish %s" % len(result))
Ejemplo n.º 20
0
 def LoadFromDB(self):
     for sAttr in self.NameList:
         sql = "select * from %s where Name='%s'" % (TABLE_NAME, sAttr)
         result = pubdefines.call_manager_func("dbmgr", "Query", sql, True)
         if not result:
             self.FirstInsertData(sAttr)
             continue
         assert len(result) == 2
         _, sData = result
         value = mydefines.get_value_by_data(sData, "blob")
         setattr(self, sAttr, value)
Ejemplo n.º 21
0
 def GetBuyInfoRecord(self, iBegin, iEnd, sGoods):
     dBuyInfo = {}
     sql = "select * from %s where Time>=%s and Time<=%s" % (TABLE_NAME,
                                                             iBegin, iEnd)
     if sGoods:
         sql = sql + " and Goods like '%%%s%%'" % sGoods
     sql += " ORDER BY Time"
     result = pubdefines.call_manager_func("dbmgr", "Query", sql)
     for ID, *tData in result:
         logging.debug("buy record:%s %s" % (ID, tData))
         dBuyInfo[ID] = tData
     return dBuyInfo
Ejemplo n.º 22
0
    def ShowStock(self):
        lstTitle = ["商品", "当前买入价格", "当前卖出价格", "库存"]
        self.tableWidgetStock.setHorizontalHeaderLabels(lstTitle)
        dGoodsInfo = pubdefines.call_manager_func("goodsmgr", "GetGoodsInfo")
        iGoodsNum = len(dGoodsInfo)
        self.tableWidgetStock.setRowCount(iGoodsNum)

        self.tableWidgetStock.horizontalHeader().setSectionResizeMode(
            QtWidgets.QHeaderView.Stretch)
        # 设置每列自适应
        # self.tableWidgetStock.horizontalHeader().setSectionResizeMode(0, QtWidgets.QHeaderView.ResizeToContents)

        iIndex = 0
        for sGoods, tInfo in dGoodsInfo.items():
            item = QtWidgets.QTableWidgetItem(str(sGoods))
            item.setTextAlignment(QtCore.Qt.AlignCenter)
            self.tableWidgetStock.setItem(iIndex, 0, item)
            for y in range(len(tInfo) - 1):
                # TODO 其他类型怎么判断,字符串价格排序有问题
                xTmp = tInfo[y]
                item = QtWidgets.QTableWidgetItem(str(xTmp))
                item.setTextAlignment(QtCore.Qt.AlignCenter)
                self.tableWidgetStock.setItem(iIndex, y + 1, item)
            iIndex += 1
Ejemplo n.º 23
0
 def TestQueryInput(self):
     pubdefines.call_manager_func("buymgr", "QueryAllInfo")
Ejemplo n.º 24
0
 def InitImport(self):
     self.comboBoxImportGoodsType.clear()
     lstGoodsType = pubdefines.call_manager_func("globalmgr", "GetAllType")
     self.comboBoxImportGoodsType.addItems(lstGoodsType)
Ejemplo n.º 25
0
 def NewGoodsInfo(self, sGoods):
     self.GoodsInfo[sGoods] = [0, 0, 0, []]
     sql = mydefines.get_insert_sql(TABLE_NAME,
                                    [sGoods, *self.GoodsInfo[sGoods]],
                                    self.ColInfo)
     pubdefines.call_manager_func("dbmgr", "Excute", sql)
Ejemplo n.º 26
0
 def FirstInsertData(self, sAttr):
     value = getattr(self, sAttr, None)
     assert value is not None
     value = mydefines.get_insert_value(value, "blob")
     sql = "insert into %s values('%s', %s)" % (TABLE_NAME, sAttr, value)
     pubdefines.call_manager_func("dbmgr", "Excute", sql)
Ejemplo n.º 27
0
 def TestQueryOutput(self):
     pubdefines.call_manager_func("sellmgr", "QueryAllInfo")
Ejemplo n.º 28
0
 def OutputGoods(self, tData):
     """出货保存数据库"""
     sql = mydefines.get_insert_sql(TABLE_NAME, tData, self.ColInfo)
     pubdefines.call_manager_func("dbmgr", "Excute", sql)