Exemplo n.º 1
0
    def run(self):

        self.win = Toplevel(self.app.app.win)
        self.win.title(name)
        x, y = 800, 450
        pos = self.win.wm_maxsize()[0] / 2 - x / 2, self.win.wm_maxsize(
        )[1] / 2 - y / 2
        self.win.geometry('%sx%s+%s+%s' % (x, y, pos[0], pos[1] - 25))
        self.win.maxsize(width=x, height=y)
        self.win.minsize(width=x, height=y)
        if sys.platform == 'win32': self.win.iconbitmap('app/images/icon.ico')
        year, month = time.localtime()[0:2]
        self.date_t = StringVar()
        self.date_t.set(date_now())
        self.c_date = date_now()
        self.cal = TkCalendar(self.win,
                              year,
                              month,
                              self.date_t,
                              command=self.calend_handler)
        self.cal.grid(row=0, column=0, padx=5, pady=10, sticky=N)

        self.content_frame = Frame(self.win)
        self.content_frame.grid(row=0, column=1, rowspan=3, sticky=N)

        self.tool_frame = Frame(self.win)
        self.tool_frame.grid(row=1, column=0, sticky=N + W)
        Label(self.content_frame, text='Список:',
              font=('normal', 12)).pack(fill=BOTH)
        self.lst = MultiListbox(self.content_frame,
                                (('Дата', 10), ('Время', 9), ('Действие', 45)),
                                font=('normal', 12),
                                height=15,
                                command=self.command_handler)
        self.lst.pack(fill=BOTH, expand=1)
        Label(self.content_frame, text='Правка:',
              font=('normal', 12)).pack(fill=BOTH)
        self.scroll = Scrollbar(self.content_frame)
        self.txt = Text(self.content_frame,
                        width=68,
                        height=5,
                        font=('normal', 12))
        self.scroll.pack(side=RIGHT, fill=Y)
        self.txt.pack(side=LEFT, fill=Y)
        self.scroll.config(command=self.txt.yview)
        self.txt.config(yscrollcommand=self.scroll.set)

        s = 'За дату: %s' % ('.'.join(date_now().split('-')[::-1]))
        self.d_label = Label(self.tool_frame, text=s, font=('bold', 12))
        self.d_label.grid(row=0, columnspan=2, sticky=N + W)
        self.all_button = Button(self.tool_frame,
                                 text='Смотреть все',
                                 command=self.show_all,
                                 width=15)
        self.all_button.grid(row=1, column=0, sticky=N, pady=5)

        self.update_lists()
Exemplo n.º 2
0
	def run(self):

		self.win=Toplevel(self.app.app.win)
		self.win.title(name)
		x,y=800,450
		pos=self.win.wm_maxsize()[0]/2-x/2,self.win.wm_maxsize()[1]/2-y/2
		self.win.geometry('%sx%s+%s+%s'%(x,y,pos[0],pos[1]-25))	
		self.win.maxsize(width=x,height=y)
		self.win.minsize(width=x,height=y)
		if sys.platform=='win32':self.win.iconbitmap('app/images/icon.ico')
		year,month = time.localtime()[0:2]
		self.date_t=StringVar()
		self.date_t.set(date_now())
		self.c_date=date_now()
		self.cal=TkCalendar(self.win,year, month, self.date_t,command=self.calend_handler)	
		self.cal.grid(row=0,column=0,padx=5,pady=10,sticky=N)

		self.content_frame=Frame(self.win)
		self.content_frame.grid(row=0,column=1,rowspan=3,sticky=N)
		
		self.tool_frame=Labelframe(self.win,text='Итог')
		self.tool_frame.grid(row=1,column=0,sticky=N+W)
		Label(self.content_frame,text='Приход:',font=('normal',12)).pack(fill=BOTH)
		self.lst=MultiListbox(self.content_frame, (('Время', 8), ('Отдел', 5), ('Товар', 32),('Сумма',5),('Кол.во',1),('Итог',5),('Продавец',12)),font=('normal',10),height=15)
		self.lst.pack(fill=BOTH,expand=1)	
		Label(self.content_frame,text='Расход:',font=('normal',12)).pack(fill=BOTH)
		self.lst2=MultiListbox(self.content_frame, (('Время', 8),  ('Причина', 35),('Сумма',5),('Продавец',12)),font=('normal',10),height=6)
		self.lst2.pack(fill=BOTH,expand=1)


		s='За дату: %s'%(norm_date(date_now()))
		self.d_label=Label(self.tool_frame,text=s,font=('bold',12))
		self.d_label.grid(row=0,columnspan=2,sticky=N+W)

		s='Доход: 0'
		self.in_label=Label(self.tool_frame,text=s,font=('bold',12))
		self.in_label.grid(row=1,columnspan=2,sticky=N+W)
		
		s='Расход: 0'
		self.out_label=Label(self.tool_frame,text=s,font=('bold',12))
		self.out_label.grid(row=2,columnspan=2,sticky=N+W)
		
		s='Остаток: 0'
		self.all_label=Label(self.tool_frame,text=s,font=('bold',12))
		self.all_label.grid(row=3,columnspan=2,sticky=N+W)
		
		self.scr1=Scrollbar(self.tool_frame,orient=VERTICAL)
		self.scr1.grid(row=4,column=1,sticky=N+S,pady=5)
		self.list_1=Listbox(self.tool_frame,width=27,height=5,
			font=("normal",9),
			yscrollcommand=self.scr1.set)
		self.list_1.grid(row=4,column=0,pady=5)
		self.scr1['command']=self.list_1.yview

		self.pdf_but=Button(self.win,text='В pdf',image=self.app.app.img['pdf'],compound='left',command=self.generate_pdf)
		self.pdf_but.grid(row=2,column=0,sticky=N)

		self.update_lists()
Exemplo n.º 3
0
	def run(self):
		self.log=Log(self.app.app)
		self.win=Toplevel(self.app.app.win)
		self.win.title(name)
		self.win.protocol("WM_DELETE_WINDOW", self.exit)
		x,y=800,450
		pos=self.win.wm_maxsize()[0]/2-x/2,self.win.wm_maxsize()[1]/2-y/2
		self.win.geometry('%sx%s+%s+%s'%(x,y,pos[0],pos[1]-25))	
		self.win.maxsize(width=x,height=y)
		self.win.minsize(width=x,height=y)
		if sys.platform=='win32':self.win.iconbitmap('app/images/icon.ico')
		year,month = time.localtime()[0:2]
		self.date_t=StringVar()
		self.date_t.set(date_now())
		self.c_date=date_now()
		self.cal=TkCalendar(self.win,year, month, self.date_t,command=self.calend_handler)	
		self.cal.grid(row=0,column=0,padx=5,pady=10,sticky=N)

		self.content_frame=Frame(self.win)
		self.content_frame.grid(row=0,column=1,rowspan=3,sticky=N)
		
		self.tool_frame=Frame(self.win)
		self.tool_frame.grid(row=1,column=0,sticky=N+W)
		Label(self.content_frame,text='Приход:',font=('normal',12)).pack(fill=BOTH)
		self.lst=MultiListbox(self.content_frame, (('Время', 8), ('Отдел', 5), ('Товар', 40),('Сумма',5),('Кол.во',1),('Итог',5),('Продавец',12)),font=('normal',10),height=6,command=self.lst1select)
		self.lst.pack(fill=BOTH,expand=1)	
		Label(self.content_frame,text='Расход:',font=('normal',12)).pack(fill=BOTH)
		self.lst2=MultiListbox(self.content_frame, (('Время', 8),  ('Причина', 35),('Сумма',5),('Продавец',12)),font=('normal',10),height=6,command=self.lst2select)
		self.lst2.pack(fill=BOTH,expand=1)


		s='За дату: %s'%(norm_date(date_now()))
		self.d_label=Label(self.tool_frame,text=s,font=('bold',12))
		self.d_label.grid(row=0,columnspan=2,sticky=N+W)
		
		
		self.edit_frame_parrent=Labelframe(self.content_frame,text='Редактировать',
			width=50,height=100)
		self.edit_frame_parrent.pack(fill=BOTH,expand=1)

		self.delete_frame_parrent=Labelframe(self.content_frame,text='Удалить',
			width=50,height=50)
		self.delete_frame_parrent.pack(fill=BOTH,expand=1)	

		self.edit_frame=Frame(self.edit_frame_parrent,height=63)
		self.edit_frame.pack()
		self.delete_frame=Frame(self.delete_frame_parrent,height=46)
		self.delete_frame.pack()		



		self.update_lists()
Exemplo n.º 4
0
	def run(self):

		self.win=Toplevel(self.app.app.win)
		self.win.title(name)
		x,y=800,450
		pos=self.win.wm_maxsize()[0]/2-x/2,self.win.wm_maxsize()[1]/2-y/2
		self.win.geometry('%sx%s+%s+%s'%(x,y,pos[0],pos[1]-25))	
		self.win.maxsize(width=x,height=y)
		self.win.minsize(width=x,height=y)
		if sys.platform=='win32':self.win.iconbitmap('app/images/icon.ico')
		year,month = time.localtime()[0:2]
		self.date_t=StringVar()
		self.date_t.set(date_now())
		self.c_date=date_now()
		self.cal=TkCalendar(self.win,year, month, self.date_t,command=self.calend_handler)	
		self.cal.grid(row=0,column=0,padx=5,pady=10,sticky=N)

		self.content_frame=Frame(self.win)
		self.content_frame.grid(row=0,column=1,rowspan=3,sticky=N)
		
		self.tool_frame=Frame(self.win)
		self.tool_frame.grid(row=1,column=0,sticky=N+W)
		Label(self.content_frame,text='Список:',font=('normal',12)).pack(fill=BOTH)
		self.lst=MultiListbox(self.content_frame, (('Дата', 10), ('Время', 9), ('Действие', 45)),font=('normal',12),height=15,command=self.command_handler)
		self.lst.pack(fill=BOTH,expand=1)	
		Label(self.content_frame,text='Правка:',font=('normal',12)).pack(fill=BOTH)
		self.scroll = Scrollbar(self.content_frame)
		self.txt=Text(self.content_frame,width=68,height=5,font=('normal',12))
		self.scroll.pack(side=RIGHT, fill=Y)
		self.txt.pack(side=LEFT, fill=Y)
		self.scroll.config(command=self.txt.yview)
		self.txt.config(yscrollcommand=self.scroll.set)
		



		s='За дату: %s'%('.'.join(date_now().split('-')[::-1]))
		self.d_label=Label(self.tool_frame,text=s,font=('bold',12))
		self.d_label.grid(row=0,columnspan=2,sticky=N+W)
		self.all_button=Button(self.tool_frame,text='Смотреть все',command=self.show_all,width=15)
		self.all_button.grid(row=1,column=0,sticky=N,pady=5)


		self.update_lists()
Exemplo n.º 5
0
    def run(self):

        self.win = Toplevel(self.app.app.win)
        self.win.title(name)
        x, y = 600, 400
        pos = self.win.wm_maxsize()[0] / 2 - x / 2, self.win.wm_maxsize(
        )[1] / 2 - y / 2
        self.win.geometry('%sx%s+%s+%s' % (x, y, pos[0], pos[1] - 25))
        self.win.maxsize(width=x, height=y)
        self.win.minsize(width=x, height=y)
        if sys.platform == 'win32': self.win.iconbitmap('app/images/icon.ico')
        year, month = time.localtime()[0:2]
        self.date_t = StringVar()
        self.date_t.set(date_now())
        self.c_date = date_now()
        Label(self.win, text='Начиная с..').grid(row=0,
                                                 column=0,
                                                 padx=5,
                                                 pady=2)
        self.cal = TkCalendar(self.win,
                              year,
                              month,
                              self.date_t,
                              command=self.calend_handler)
        self.cal.grid(row=1, column=0, padx=5, sticky=N)

        self.frame = Labelframe(self.win,
                                text='Показывать',
                                width=275,
                                height=200)
        self.frame.grid(row=0, column=1, rowspan=2)
        self.win.columnconfigure(1, minsize=275)

        self.date2_t = StringVar()
        self.date2_t.set(date_now())
        self.c_date2 = date_now()
        Label(self.win, text='Заканчивая..').grid(row=0,
                                                  column=2,
                                                  padx=5,
                                                  pady=2)
        self.cal2 = TkCalendar(self.win,
                               year,
                               month,
                               self.date_t,
                               command=self.calend_handler2)
        self.cal2.grid(row=1, column=2, padx=5, sticky=NE)
        self.lab_var = StringVar()
        Label(self.frame, textvariable=self.lab_var,
              font=('bold', 10)).grid(row=0,
                                      column=0,
                                      columnspan=2,
                                      padx=10,
                                      pady=5)

        Label(self.frame, text='По отделу').grid(row=1, column=0, sticky=E)
        self.dep_ent_txt = StringVar()
        self.dep_ent_txt.set('Все отделы')
        self.dep_ent = Combobox(self.frame,
                                width=20,
                                state='readonly',
                                textvariable=self.dep_ent_txt)
        self.dep_ent.grid(row=1, column=1, pady=5)

        Label(self.frame, text='По продавцу').grid(row=2, column=0, sticky=E)
        self.per_ent_var = StringVar()
        self.per_ent_var.set('Все продавцы')
        self.per_ent = Combobox(self.frame,
                                width=20,
                                state='readonly',
                                textvariable=self.per_ent_var)
        self.per_ent.grid(row=2, column=1, pady=5)

        self.show_but = Button(self.frame,
                               text='Показать',
                               image=self.app.app.img['check'],
                               compound='left',
                               command=self.calculate)
        self.show_but.grid(row=3, column=0, columnspan=2, pady=27)

        self.app.app.db.execute('select name from dep')
        self.deps = [u'Все отделы']
        for x in self.app.app.db.fetchall():
            if x[0]: self.deps.append(x[0])
        self.dep_ent['values'] = self.deps

        self.app.app.db.execute('select name from users')
        self.users = [u'Все продавцы']
        for x in self.app.app.db.fetchall():
            self.users.append(x[0])
        self.per_ent['values'] = self.users

        self.out_var = StringVar()
        self.out_var.set(' ')
        Label(self.win, textvariable=self.out_var,
              font=('bold', 12)).grid(row=2,
                                      column=0,
                                      columnspan=3,
                                      sticky=W,
                                      padx=15,
                                      pady=5)
        self.canvas = Canvas(self.win,
                             width=580,
                             height=150,
                             background='white')
        self.canvas.grid(row=3, column=0, columnspan=3, padx=5, pady=5)

        self.update_label()
Exemplo n.º 6
0
class Plugin:
    def __init__(self, app):
        self.app = app

    def run(self):

        self.win = Toplevel(self.app.app.win)
        self.win.title(name)
        x, y = 600, 400
        pos = self.win.wm_maxsize()[0] / 2 - x / 2, self.win.wm_maxsize(
        )[1] / 2 - y / 2
        self.win.geometry('%sx%s+%s+%s' % (x, y, pos[0], pos[1] - 25))
        self.win.maxsize(width=x, height=y)
        self.win.minsize(width=x, height=y)
        if sys.platform == 'win32': self.win.iconbitmap('app/images/icon.ico')
        year, month = time.localtime()[0:2]
        self.date_t = StringVar()
        self.date_t.set(date_now())
        self.c_date = date_now()
        Label(self.win, text='Начиная с..').grid(row=0,
                                                 column=0,
                                                 padx=5,
                                                 pady=2)
        self.cal = TkCalendar(self.win,
                              year,
                              month,
                              self.date_t,
                              command=self.calend_handler)
        self.cal.grid(row=1, column=0, padx=5, sticky=N)

        self.frame = Labelframe(self.win,
                                text='Показывать',
                                width=275,
                                height=200)
        self.frame.grid(row=0, column=1, rowspan=2)
        self.win.columnconfigure(1, minsize=275)

        self.date2_t = StringVar()
        self.date2_t.set(date_now())
        self.c_date2 = date_now()
        Label(self.win, text='Заканчивая..').grid(row=0,
                                                  column=2,
                                                  padx=5,
                                                  pady=2)
        self.cal2 = TkCalendar(self.win,
                               year,
                               month,
                               self.date_t,
                               command=self.calend_handler2)
        self.cal2.grid(row=1, column=2, padx=5, sticky=NE)
        self.lab_var = StringVar()
        Label(self.frame, textvariable=self.lab_var,
              font=('bold', 10)).grid(row=0,
                                      column=0,
                                      columnspan=2,
                                      padx=10,
                                      pady=5)

        Label(self.frame, text='По отделу').grid(row=1, column=0, sticky=E)
        self.dep_ent_txt = StringVar()
        self.dep_ent_txt.set('Все отделы')
        self.dep_ent = Combobox(self.frame,
                                width=20,
                                state='readonly',
                                textvariable=self.dep_ent_txt)
        self.dep_ent.grid(row=1, column=1, pady=5)

        Label(self.frame, text='По продавцу').grid(row=2, column=0, sticky=E)
        self.per_ent_var = StringVar()
        self.per_ent_var.set('Все продавцы')
        self.per_ent = Combobox(self.frame,
                                width=20,
                                state='readonly',
                                textvariable=self.per_ent_var)
        self.per_ent.grid(row=2, column=1, pady=5)

        self.show_but = Button(self.frame,
                               text='Показать',
                               image=self.app.app.img['check'],
                               compound='left',
                               command=self.calculate)
        self.show_but.grid(row=3, column=0, columnspan=2, pady=27)

        self.app.app.db.execute('select name from dep')
        self.deps = [u'Все отделы']
        for x in self.app.app.db.fetchall():
            if x[0]: self.deps.append(x[0])
        self.dep_ent['values'] = self.deps

        self.app.app.db.execute('select name from users')
        self.users = [u'Все продавцы']
        for x in self.app.app.db.fetchall():
            self.users.append(x[0])
        self.per_ent['values'] = self.users

        self.out_var = StringVar()
        self.out_var.set(' ')
        Label(self.win, textvariable=self.out_var,
              font=('bold', 12)).grid(row=2,
                                      column=0,
                                      columnspan=3,
                                      sticky=W,
                                      padx=15,
                                      pady=5)
        self.canvas = Canvas(self.win,
                             width=580,
                             height=150,
                             background='white')
        self.canvas.grid(row=3, column=0, columnspan=3, padx=5, pady=5)

        self.update_label()

    def calend_handler(self, date):
        """выбор начальной даты """
        self.c_date = date
        self.update_label()

    def calend_handler2(self, date):
        """ выбор конечной даты """
        self.c_date2 = date
        self.update_label()

    def update_label(self):
        self.lab_var.set('Показать с  %s  по %s' %
                         (norm_date(self.c_date), norm_date(self.c_date2)))

    def calculate(self):
        """ собственно сама функия сбора статистики """
        self.out_var.set('Идет сбор данных...')
        self.win.update()
        self.canvas.delete(ALL)
        dep = self.dep_ent.get()
        if dep == u'Все отделы': dep = -1
        else:
            self.app.app.db.execute('select id from dep where name=?', (dep, ))
            dep = self.app.app.db.fetchall()[0][0]
        per = self.per_ent.get()
        # делаем запросы в зависимости от того что хотим посмотреть
        if per == u'Все продавцы': per = -1

        if per == -1 and dep == -1:
            self.app.app.db.execute(
                'select date,sum,rate from income where date between ? and ?',
                (self.c_date, self.c_date2))
        elif per == -1 and dep <> -1:
            self.app.app.db.execute(
                'select date,sum,rate from income where dep=? and date between ? and ?',
                (dep, self.c_date, self.c_date2))
        elif per <> -1 and dep == -1:
            self.app.app.db.execute(
                'select date,sum,rate from income where name=? and date between ? and ?',
                (per, self.c_date, self.c_date2))
        else:
            self.app.app.db.execute(
                'select date,sum,rate from income where name=? and dep=? and date between ? and ?',
                (per, dep, self.c_date, self.c_date2))
        rezult = self.app.app.db.fetchall()
        rez = {}
        for x in all_dates(self.c_date, self.c_date2):
            rez[x] = 0
        all_sum = 0
        for x in rezult:
            rez[x[0]] += x[1] * x[2]
            all_sum += x[1] * x[2]
        try:
            self.out_var.set(
                'Итог за %s дней составляет %s. Среднее за день %s' %
                (len(rez), all_sum, int(all_sum / len(rez))))
        except ZeroDivisionError:
            self.out_var.set('Конечная дата не может быть меньше начальной')
            return
        k = rez.keys()
        k.sort()
        mx = max(rez.values())

        # вооо... график, который так любят смотреть рукогодители, строим на canvas
        # желаю чтоб не было провалов...
        last_x = 0
        last_y = 0
        k_x = 580.0 / float(len(k))

        for i in k:
            x = k_x + last_x
            try:
                y = float(rez[i]) / mx * 150.0
            except ZeroDivisionError:
                return

            self.canvas.create_line(last_x,
                                    150 - last_y,
                                    x,
                                    150 - y,
                                    fill='#348442')
            if i.split('-')[2] == '01':
                self.canvas.create_line(x, 0, x, 150, fill='grey')
                self.canvas.create_text(x + 2,
                                        30,
                                        text=i.split('-')[1],
                                        fill='black',
                                        anchor=NW)
            last_x = x
            last_y = y
        self.canvas.create_text(3, 3, text=str(mx), fill='red', anchor=NW)
        self.canvas.create_text(3,
                                60,
                                text=str(int(mx / 2)),
                                fill='red',
                                anchor=NW)
        self.canvas.create_line(0, 75, 580, 75, fill='grey')
Exemplo n.º 7
0
class Plugin:
    def __init__(self, app):
        self.app = app

    def run(self):

        self.win = Toplevel(self.app.app.win)
        self.win.title(name)
        x, y = 800, 450
        pos = self.win.wm_maxsize()[0] / 2 - x / 2, self.win.wm_maxsize(
        )[1] / 2 - y / 2
        self.win.geometry('%sx%s+%s+%s' % (x, y, pos[0], pos[1] - 25))
        self.win.maxsize(width=x, height=y)
        self.win.minsize(width=x, height=y)
        if sys.platform == 'win32': self.win.iconbitmap('app/images/icon.ico')
        year, month = time.localtime()[0:2]
        self.date_t = StringVar()
        self.date_t.set(date_now())
        self.c_date = date_now()
        self.cal = TkCalendar(self.win,
                              year,
                              month,
                              self.date_t,
                              command=self.calend_handler)
        self.cal.grid(row=0, column=0, padx=5, pady=10, sticky=N)

        self.content_frame = Frame(self.win)
        self.content_frame.grid(row=0, column=1, rowspan=3, sticky=N)

        self.tool_frame = Frame(self.win)
        self.tool_frame.grid(row=1, column=0, sticky=N + W)
        Label(self.content_frame, text='Список:',
              font=('normal', 12)).pack(fill=BOTH)
        self.lst = MultiListbox(self.content_frame,
                                (('Дата', 10), ('Время', 9), ('Действие', 45)),
                                font=('normal', 12),
                                height=15,
                                command=self.command_handler)
        self.lst.pack(fill=BOTH, expand=1)
        Label(self.content_frame, text='Правка:',
              font=('normal', 12)).pack(fill=BOTH)
        self.scroll = Scrollbar(self.content_frame)
        self.txt = Text(self.content_frame,
                        width=68,
                        height=5,
                        font=('normal', 12))
        self.scroll.pack(side=RIGHT, fill=Y)
        self.txt.pack(side=LEFT, fill=Y)
        self.scroll.config(command=self.txt.yview)
        self.txt.config(yscrollcommand=self.scroll.set)

        s = 'За дату: %s' % ('.'.join(date_now().split('-')[::-1]))
        self.d_label = Label(self.tool_frame, text=s, font=('bold', 12))
        self.d_label.grid(row=0, columnspan=2, sticky=N + W)
        self.all_button = Button(self.tool_frame,
                                 text='Смотреть все',
                                 command=self.show_all,
                                 width=15)
        self.all_button.grid(row=1, column=0, sticky=N, pady=5)

        self.update_lists()

    def calend_handler(self, date):
        """при выборе даты """
        self.c_date = date
        self.update_lists()
        self.txt.delete(0.0, END)

    def update_lists(self):
        """ обновляем списки """
        self.all_data = []
        self.lst.delete(0, END)
        if self.c_date == 'Все':
            self.app.app.db.execute(
                'select date,time,title,event from edit_log')
        else:
            self.app.app.db.execute(
                'select date,time,title,event from edit_log where date=?',
                (self.c_date, ))
        for x in self.app.app.db.fetchall():
            x = list(x)
            x[0] = norm_date(x[0])
            self.lst.insert(END, x)
            self.all_data.append(x)
        self.lst.see(END)
        if self.c_date == 'Все':
            self.d_label['text'] = 'За дату: ВСЕ'
        else:
            s = 'За дату: %s' % (norm_date(self.c_date))
            self.d_label['text'] = s

    def command_handler(self):
        """ при выборе пункта в таблице, показываем полный текст изменения """
        if not self.lst.curselection(): return
        c = int(self.lst.curselection()[0])
        txt = self.all_data[c][3]
        self.txt.delete(0.0, END)
        self.txt.insert(0.0, txt)

    def show_all(self):
        """ по кнопке "смотреть все" """
        self.c_date = 'Все'
        self.update_lists()
        self.txt.delete(0.0, END)
Exemplo n.º 8
0
class Plugin:
	def __init__(self,app):
		self.app=app
		
	def run(self):

		self.win=Toplevel(self.app.app.win)
		self.win.title(name)
		x,y=800,450
		pos=self.win.wm_maxsize()[0]/2-x/2,self.win.wm_maxsize()[1]/2-y/2
		self.win.geometry('%sx%s+%s+%s'%(x,y,pos[0],pos[1]-25))	
		self.win.maxsize(width=x,height=y)
		self.win.minsize(width=x,height=y)
		if sys.platform=='win32':self.win.iconbitmap('app/images/icon.ico')
		year,month = time.localtime()[0:2]
		self.date_t=StringVar()
		self.date_t.set(date_now())
		self.c_date=date_now()
		self.cal=TkCalendar(self.win,year, month, self.date_t,command=self.calend_handler)	
		self.cal.grid(row=0,column=0,padx=5,pady=10,sticky=N)

		self.content_frame=Frame(self.win)
		self.content_frame.grid(row=0,column=1,rowspan=3,sticky=N)
		
		self.tool_frame=Frame(self.win)
		self.tool_frame.grid(row=1,column=0,sticky=N+W)
		Label(self.content_frame,text='Список:',font=('normal',12)).pack(fill=BOTH)
		self.lst=MultiListbox(self.content_frame, (('Дата', 10), ('Время', 9), ('Действие', 45)),font=('normal',12),height=15,command=self.command_handler)
		self.lst.pack(fill=BOTH,expand=1)	
		Label(self.content_frame,text='Правка:',font=('normal',12)).pack(fill=BOTH)
		self.scroll = Scrollbar(self.content_frame)
		self.txt=Text(self.content_frame,width=68,height=5,font=('normal',12))
		self.scroll.pack(side=RIGHT, fill=Y)
		self.txt.pack(side=LEFT, fill=Y)
		self.scroll.config(command=self.txt.yview)
		self.txt.config(yscrollcommand=self.scroll.set)
		



		s='За дату: %s'%('.'.join(date_now().split('-')[::-1]))
		self.d_label=Label(self.tool_frame,text=s,font=('bold',12))
		self.d_label.grid(row=0,columnspan=2,sticky=N+W)
		self.all_button=Button(self.tool_frame,text='Смотреть все',command=self.show_all,width=15)
		self.all_button.grid(row=1,column=0,sticky=N,pady=5)


		self.update_lists()

	def calend_handler(self,date):
		"""при выборе даты """
		self.c_date=date
		self.update_lists()
		self.txt.delete(0.0,END)
		
	def update_lists(self):
		""" обновляем списки """
		self.all_data=[]
		self.lst.delete(0,END)
		if self.c_date=='Все':
			self.app.app.db.execute('select date,time,title,event from edit_log')
		else:self.app.app.db.execute('select date,time,title,event from edit_log where date=?',(self.c_date,))
		for x in self.app.app.db.fetchall():
			x=list(x)
			x[0]=norm_date(x[0])
			self.lst.insert(END,x)
			self.all_data.append(x)
		self.lst.see(END)
		if self.c_date=='Все':
			self.d_label['text']='За дату: ВСЕ'	
		else:
			s='За дату: %s'%(norm_date(self.c_date))
			self.d_label['text']=s	

	def command_handler(self):
		""" при выборе пункта в таблице, показываем полный текст изменения """
		if not self.lst.curselection():return
		c=int(self.lst.curselection()[0])
		txt=self.all_data[c][3]
		self.txt.delete(0.0,END)
		self.txt.insert(0.0,txt)
	def show_all(self):
		""" по кнопке "смотреть все" """
		self.c_date='Все'
		self.update_lists()
		self.txt.delete(0.0,END)		
		
Exemplo n.º 9
0
    def run(self):

        self.win = Toplevel(self.app.app.win)
        self.win.title(name)
        x, y = 600, 400
        pos = self.win.wm_maxsize()[0] / 2 - x / 2, self.win.wm_maxsize()[1] / 2 - y / 2
        self.win.geometry("%sx%s+%s+%s" % (x, y, pos[0], pos[1] - 25))
        self.win.maxsize(width=x, height=y)
        self.win.minsize(width=x, height=y)
        if sys.platform == "win32":
            self.win.iconbitmap("app/images/icon.ico")
        year, month = time.localtime()[0:2]
        self.date_t = StringVar()
        self.date_t.set(date_now())
        self.c_date = date_now()
        Label(self.win, text="Начиная с..").grid(row=0, column=0, padx=5, pady=2)
        self.cal = TkCalendar(self.win, year, month, self.date_t, command=self.calend_handler)
        self.cal.grid(row=1, column=0, padx=5, sticky=N)

        self.frame = Labelframe(self.win, text="Показывать", width=275, height=200)
        self.frame.grid(row=0, column=1, rowspan=2)
        self.win.columnconfigure(1, minsize=275)

        self.date2_t = StringVar()
        self.date2_t.set(date_now())
        self.c_date2 = date_now()
        Label(self.win, text="Заканчивая..").grid(row=0, column=2, padx=5, pady=2)
        self.cal2 = TkCalendar(self.win, year, month, self.date_t, command=self.calend_handler2)
        self.cal2.grid(row=1, column=2, padx=5, sticky=NE)
        self.lab_var = StringVar()
        Label(self.frame, textvariable=self.lab_var, font=("bold", 10)).grid(
            row=0, column=0, columnspan=2, padx=10, pady=5
        )

        Label(self.frame, text="По отделу").grid(row=1, column=0, sticky=E)
        self.dep_ent_txt = StringVar()
        self.dep_ent_txt.set("Все отделы")
        self.dep_ent = Combobox(self.frame, width=20, state="readonly", textvariable=self.dep_ent_txt)
        self.dep_ent.grid(row=1, column=1, pady=5)

        Label(self.frame, text="По продавцу").grid(row=2, column=0, sticky=E)
        self.per_ent_var = StringVar()
        self.per_ent_var.set("Все продавцы")
        self.per_ent = Combobox(self.frame, width=20, state="readonly", textvariable=self.per_ent_var)
        self.per_ent.grid(row=2, column=1, pady=5)

        self.show_but = Button(
            self.frame, text="Показать", image=self.app.app.img["check"], compound="left", command=self.calculate
        )
        self.show_but.grid(row=3, column=0, columnspan=2, pady=27)

        self.app.app.db.execute("select name from dep")
        self.deps = [u"Все отделы"]
        for x in self.app.app.db.fetchall():
            if x[0]:
                self.deps.append(x[0])
        self.dep_ent["values"] = self.deps

        self.app.app.db.execute("select name from users")
        self.users = [u"Все продавцы"]
        for x in self.app.app.db.fetchall():
            self.users.append(x[0])
        self.per_ent["values"] = self.users

        self.out_var = StringVar()
        self.out_var.set(" ")
        Label(self.win, textvariable=self.out_var, font=("bold", 12)).grid(
            row=2, column=0, columnspan=3, sticky=W, padx=15, pady=5
        )
        self.canvas = Canvas(self.win, width=580, height=150, background="white")
        self.canvas.grid(row=3, column=0, columnspan=3, padx=5, pady=5)

        self.update_label()
Exemplo n.º 10
0
class Plugin:
    def __init__(self, app):
        self.app = app

    def run(self):

        self.win = Toplevel(self.app.app.win)
        self.win.title(name)
        x, y = 600, 400
        pos = self.win.wm_maxsize()[0] / 2 - x / 2, self.win.wm_maxsize()[1] / 2 - y / 2
        self.win.geometry("%sx%s+%s+%s" % (x, y, pos[0], pos[1] - 25))
        self.win.maxsize(width=x, height=y)
        self.win.minsize(width=x, height=y)
        if sys.platform == "win32":
            self.win.iconbitmap("app/images/icon.ico")
        year, month = time.localtime()[0:2]
        self.date_t = StringVar()
        self.date_t.set(date_now())
        self.c_date = date_now()
        Label(self.win, text="Начиная с..").grid(row=0, column=0, padx=5, pady=2)
        self.cal = TkCalendar(self.win, year, month, self.date_t, command=self.calend_handler)
        self.cal.grid(row=1, column=0, padx=5, sticky=N)

        self.frame = Labelframe(self.win, text="Показывать", width=275, height=200)
        self.frame.grid(row=0, column=1, rowspan=2)
        self.win.columnconfigure(1, minsize=275)

        self.date2_t = StringVar()
        self.date2_t.set(date_now())
        self.c_date2 = date_now()
        Label(self.win, text="Заканчивая..").grid(row=0, column=2, padx=5, pady=2)
        self.cal2 = TkCalendar(self.win, year, month, self.date_t, command=self.calend_handler2)
        self.cal2.grid(row=1, column=2, padx=5, sticky=NE)
        self.lab_var = StringVar()
        Label(self.frame, textvariable=self.lab_var, font=("bold", 10)).grid(
            row=0, column=0, columnspan=2, padx=10, pady=5
        )

        Label(self.frame, text="По отделу").grid(row=1, column=0, sticky=E)
        self.dep_ent_txt = StringVar()
        self.dep_ent_txt.set("Все отделы")
        self.dep_ent = Combobox(self.frame, width=20, state="readonly", textvariable=self.dep_ent_txt)
        self.dep_ent.grid(row=1, column=1, pady=5)

        Label(self.frame, text="По продавцу").grid(row=2, column=0, sticky=E)
        self.per_ent_var = StringVar()
        self.per_ent_var.set("Все продавцы")
        self.per_ent = Combobox(self.frame, width=20, state="readonly", textvariable=self.per_ent_var)
        self.per_ent.grid(row=2, column=1, pady=5)

        self.show_but = Button(
            self.frame, text="Показать", image=self.app.app.img["check"], compound="left", command=self.calculate
        )
        self.show_but.grid(row=3, column=0, columnspan=2, pady=27)

        self.app.app.db.execute("select name from dep")
        self.deps = [u"Все отделы"]
        for x in self.app.app.db.fetchall():
            if x[0]:
                self.deps.append(x[0])
        self.dep_ent["values"] = self.deps

        self.app.app.db.execute("select name from users")
        self.users = [u"Все продавцы"]
        for x in self.app.app.db.fetchall():
            self.users.append(x[0])
        self.per_ent["values"] = self.users

        self.out_var = StringVar()
        self.out_var.set(" ")
        Label(self.win, textvariable=self.out_var, font=("bold", 12)).grid(
            row=2, column=0, columnspan=3, sticky=W, padx=15, pady=5
        )
        self.canvas = Canvas(self.win, width=580, height=150, background="white")
        self.canvas.grid(row=3, column=0, columnspan=3, padx=5, pady=5)

        self.update_label()

    def calend_handler(self, date):
        """выбор начальной даты """
        self.c_date = date
        self.update_label()

    def calend_handler2(self, date):
        """ выбор конечной даты """
        self.c_date2 = date
        self.update_label()

    def update_label(self):
        self.lab_var.set("Показать с  %s  по %s" % (norm_date(self.c_date), norm_date(self.c_date2)))

    def calculate(self):
        """ собственно сама функия сбора статистики """
        self.out_var.set("Идет сбор данных...")
        self.win.update()
        self.canvas.delete(ALL)
        dep = self.dep_ent.get()
        if dep == u"Все отделы":
            dep = -1
        else:
            self.app.app.db.execute("select id from dep where name=?", (dep,))
            dep = self.app.app.db.fetchall()[0][0]
        per = self.per_ent.get()
        # делаем запросы в зависимости от того что хотим посмотреть
        if per == u"Все продавцы":
            per = -1

        if per == -1 and dep == -1:
            self.app.app.db.execute(
                "select date,sum,rate from income where date between ? and ?", (self.c_date, self.c_date2)
            )
        elif per == -1 and dep <> -1:
            self.app.app.db.execute(
                "select date,sum,rate from income where dep=? and date between ? and ?",
                (dep, self.c_date, self.c_date2),
            )
        elif per <> -1 and dep == -1:
            self.app.app.db.execute(
                "select date,sum,rate from income where name=? and date between ? and ?",
                (per, self.c_date, self.c_date2),
            )
        else:
            self.app.app.db.execute(
                "select date,sum,rate from income where name=? and dep=? and date between ? and ?",
                (per, dep, self.c_date, self.c_date2),
            )
        rezult = self.app.app.db.fetchall()
        rez = {}
        for x in all_dates(self.c_date, self.c_date2):
            rez[x] = 0
        all_sum = 0
        for x in rezult:
            rez[x[0]] += x[1] * x[2]
            all_sum += x[1] * x[2]
        try:
            self.out_var.set(
                "Итог за %s дней составляет %s. Среднее за день %s" % (len(rez), all_sum, int(all_sum / len(rez)))
            )
        except ZeroDivisionError:
            self.out_var.set("Конечная дата не может быть меньше начальной")
            return
        k = rez.keys()
        k.sort()
        mx = max(rez.values())

        # вооо... график, который так любят смотреть рукогодители, строим на canvas
        # желаю чтоб не было провалов...
        last_x = 0
        last_y = 0
        k_x = 580.0 / float(len(k))

        for i in k:
            x = k_x + last_x
            try:
                y = float(rez[i]) / mx * 150.0
            except ZeroDivisionError:
                return

            self.canvas.create_line(last_x, 150 - last_y, x, 150 - y, fill="#348442")
            if i.split("-")[2] == "01":
                self.canvas.create_line(x, 0, x, 150, fill="grey")
                self.canvas.create_text(x + 2, 30, text=i.split("-")[1], fill="black", anchor=NW)
            last_x = x
            last_y = y
        self.canvas.create_text(3, 3, text=str(mx), fill="red", anchor=NW)
        self.canvas.create_text(3, 60, text=str(int(mx / 2)), fill="red", anchor=NW)
        self.canvas.create_line(0, 75, 580, 75, fill="grey")
Exemplo n.º 11
0
    def run(self):

        self.win = Toplevel(self.app.app.win)
        self.win.title(name)
        x, y = 800, 450
        pos = self.win.wm_maxsize()[0] / 2 - x / 2, self.win.wm_maxsize(
        )[1] / 2 - y / 2
        self.win.geometry('%sx%s+%s+%s' % (x, y, pos[0], pos[1] - 25))
        self.win.maxsize(width=x, height=y)
        self.win.minsize(width=x, height=y)
        if sys.platform == 'win32': self.win.iconbitmap('app/images/icon.ico')
        year, month = time.localtime()[0:2]
        self.date_t = StringVar()
        self.date_t.set(date_now())
        self.c_date = date_now()
        self.cal = TkCalendar(self.win,
                              year,
                              month,
                              self.date_t,
                              command=self.calend_handler)
        self.cal.grid(row=0, column=0, padx=5, pady=10, sticky=N)

        self.content_frame = Frame(self.win)
        self.content_frame.grid(row=0, column=1, rowspan=3, sticky=N)

        self.tool_frame = Labelframe(self.win, text='Итог')
        self.tool_frame.grid(row=1, column=0, sticky=N + W)
        Label(self.content_frame, text='Приход:',
              font=('normal', 12)).pack(fill=BOTH)
        self.lst = MultiListbox(self.content_frame,
                                (('Время', 8), ('Отдел', 5), ('Товар', 32),
                                 ('Сумма', 5), ('Кол.во', 1), ('Итог', 5),
                                 ('Продавец', 12)),
                                font=('normal', 10),
                                height=15)
        self.lst.pack(fill=BOTH, expand=1)
        Label(self.content_frame, text='Расход:',
              font=('normal', 12)).pack(fill=BOTH)
        self.lst2 = MultiListbox(self.content_frame,
                                 (('Время', 8), ('Причина', 35), ('Сумма', 5),
                                  ('Продавец', 12)),
                                 font=('normal', 10),
                                 height=6)
        self.lst2.pack(fill=BOTH, expand=1)

        s = 'За дату: %s' % (norm_date(date_now()))
        self.d_label = Label(self.tool_frame, text=s, font=('bold', 12))
        self.d_label.grid(row=0, columnspan=2, sticky=N + W)

        s = 'Доход: 0'
        self.in_label = Label(self.tool_frame, text=s, font=('bold', 12))
        self.in_label.grid(row=1, columnspan=2, sticky=N + W)

        s = 'Расход: 0'
        self.out_label = Label(self.tool_frame, text=s, font=('bold', 12))
        self.out_label.grid(row=2, columnspan=2, sticky=N + W)

        s = 'Остаток: 0'
        self.all_label = Label(self.tool_frame, text=s, font=('bold', 12))
        self.all_label.grid(row=3, columnspan=2, sticky=N + W)

        self.scr1 = Scrollbar(self.tool_frame, orient=VERTICAL)
        self.scr1.grid(row=4, column=1, sticky=N + S, pady=5)
        self.list_1 = Listbox(self.tool_frame,
                              width=27,
                              height=5,
                              font=("normal", 9),
                              yscrollcommand=self.scr1.set)
        self.list_1.grid(row=4, column=0, pady=5)
        self.scr1['command'] = self.list_1.yview

        self.pdf_but = Button(self.win,
                              text='В pdf',
                              image=self.app.app.img['pdf'],
                              compound='left',
                              command=self.generate_pdf)
        self.pdf_but.grid(row=2, column=0, sticky=N)

        self.update_lists()
Exemplo n.º 12
0
class Plugin:
    def __init__(self, app):
        self.app = app

    def run(self):

        self.win = Toplevel(self.app.app.win)
        self.win.title(name)
        x, y = 800, 450
        pos = self.win.wm_maxsize()[0] / 2 - x / 2, self.win.wm_maxsize(
        )[1] / 2 - y / 2
        self.win.geometry('%sx%s+%s+%s' % (x, y, pos[0], pos[1] - 25))
        self.win.maxsize(width=x, height=y)
        self.win.minsize(width=x, height=y)
        if sys.platform == 'win32': self.win.iconbitmap('app/images/icon.ico')
        year, month = time.localtime()[0:2]
        self.date_t = StringVar()
        self.date_t.set(date_now())
        self.c_date = date_now()
        self.cal = TkCalendar(self.win,
                              year,
                              month,
                              self.date_t,
                              command=self.calend_handler)
        self.cal.grid(row=0, column=0, padx=5, pady=10, sticky=N)

        self.content_frame = Frame(self.win)
        self.content_frame.grid(row=0, column=1, rowspan=3, sticky=N)

        self.tool_frame = Labelframe(self.win, text='Итог')
        self.tool_frame.grid(row=1, column=0, sticky=N + W)
        Label(self.content_frame, text='Приход:',
              font=('normal', 12)).pack(fill=BOTH)
        self.lst = MultiListbox(self.content_frame,
                                (('Время', 8), ('Отдел', 5), ('Товар', 32),
                                 ('Сумма', 5), ('Кол.во', 1), ('Итог', 5),
                                 ('Продавец', 12)),
                                font=('normal', 10),
                                height=15)
        self.lst.pack(fill=BOTH, expand=1)
        Label(self.content_frame, text='Расход:',
              font=('normal', 12)).pack(fill=BOTH)
        self.lst2 = MultiListbox(self.content_frame,
                                 (('Время', 8), ('Причина', 35), ('Сумма', 5),
                                  ('Продавец', 12)),
                                 font=('normal', 10),
                                 height=6)
        self.lst2.pack(fill=BOTH, expand=1)

        s = 'За дату: %s' % (norm_date(date_now()))
        self.d_label = Label(self.tool_frame, text=s, font=('bold', 12))
        self.d_label.grid(row=0, columnspan=2, sticky=N + W)

        s = 'Доход: 0'
        self.in_label = Label(self.tool_frame, text=s, font=('bold', 12))
        self.in_label.grid(row=1, columnspan=2, sticky=N + W)

        s = 'Расход: 0'
        self.out_label = Label(self.tool_frame, text=s, font=('bold', 12))
        self.out_label.grid(row=2, columnspan=2, sticky=N + W)

        s = 'Остаток: 0'
        self.all_label = Label(self.tool_frame, text=s, font=('bold', 12))
        self.all_label.grid(row=3, columnspan=2, sticky=N + W)

        self.scr1 = Scrollbar(self.tool_frame, orient=VERTICAL)
        self.scr1.grid(row=4, column=1, sticky=N + S, pady=5)
        self.list_1 = Listbox(self.tool_frame,
                              width=27,
                              height=5,
                              font=("normal", 9),
                              yscrollcommand=self.scr1.set)
        self.list_1.grid(row=4, column=0, pady=5)
        self.scr1['command'] = self.list_1.yview

        self.pdf_but = Button(self.win,
                              text='В pdf',
                              image=self.app.app.img['pdf'],
                              compound='left',
                              command=self.generate_pdf)
        self.pdf_but.grid(row=2, column=0, sticky=N)

        self.update_lists()

    def calend_handler(self, date):
        """ при щелчке на дату в календаре """
        self.c_date = date
        self.update_lists()

    def update_lists(self):
        """ заполняем таблицы """
        self.lst.delete(0, END)
        self.app.app.db.execute(
            'select time,dep,article,sum,rate,name,art_id,edit from income where date=?',
            (self.c_date, ))
        income_all = 0
        for x in self.app.app.db.fetchall():
            out = list(x)
            if out[7] <> 0:
                out[1] = str(out[1]) + ' (≈)'
            if out[6] <> -1:
                out[1] = str(out[1]) + ' →'
            out.insert(5, round(x[3] * x[4], 2))
            income_all += x[3] * x[4]
            self.lst.insert(END, out)
        self.lst.see(END)
        outcome_all = 0
        self.lst2.delete(0, END)
        self.app.app.db.execute(
            'select time,article,sum,name,art_id,edit from outcome where date=?',
            (self.c_date, ))
        for x in self.app.app.db.fetchall():
            out = list(x)
            if out[5] <> 0:
                out[1] = u'(≈) ' + out[1]
            self.lst2.insert(END, out)
            outcome_all += out[2]
        self.lst2.see(END)
        self.in_label['text'] = 'Доход: %s' % (income_all)
        self.out_label['text'] = 'Расход: %s' % (outcome_all)
        self.all_label['text'] = 'Остаток: %s' % (income_all - outcome_all)
        s = 'За дату: %s' % (norm_date(self.c_date))
        self.d_label['text'] = s

        deps = {}
        deps_sum = {}
        self.app.app.db.execute('select name from dep')

        self.deps = []

        for n, name in enumerate(self.app.app.db.fetchall()):
            if name:
                deps_sum[n + 1] = 0
                self.deps.append('%s' % (name[0]))

        self.app.app.db.execute('select dep,sum,rate from income where date=?',
                                (self.c_date, ))
        out = self.app.app.db.fetchall()
        in_all = 0
        for x in out:
            in_all += float(x[1]) * float(x[2])
            deps_sum[x[0]] += float(x[1]) * float(x[2])

        self.list_1.delete(0, END)

        for x in deps_sum:
            if deps_sum[x]:
                self.list_1.insert(
                    END,
                    str(x) + ' ' + self.deps[x - 1] + u'→ ' + str(deps_sum[x]))

    def generate_pdf(self):
        """ генерация pdf. Ваш К.О. """
        try:
            path = self.app.app.sets.save_pdf
        except:
            path = ''
        filename = 'Продажи за %s.pdf' % (norm_date(self.c_date))
        f = tkFileDialog.asksaveasfilename(initialdir=path,
                                           initialfile=filename)
        if not f: return
        f = f.replace('\\', '/')
        self.app.app.sets.save_pdf = '/'.join(f.split('/')[:-1])
        doc = pdf.Pdf(title='Продажи за %s' % (norm_date(self.c_date)),
                      fname=f)
        doc.string('Доходы:')

        doc.table([('Время', 45), ('Отд', 35), ('Товар', 220), ('Сум.', 40),
                   ('К-во', 30), ('Итого', 40), ('Продавец', 90)])

        self.app.app.db.execute(
            'select time,dep,article,sum,rate,name,art_id,edit from income where date=?',
            (self.c_date, ))
        income_all = 0
        for x in self.app.app.db.fetchall():
            out = list(x)
            if out[7] <> 0:
                out[1] = str(out[1]) + u' (≈)'
            if out[6] <> -1:
                out[1] = str(out[1]) + u' →'
            out.insert(5, x[3] * x[4])
            income_all += x[3] * x[4]

            doc.table([(out[0], 45), (out[1], 35), (out[2], 220), (out[3], 40),
                       (out[4], 30), (out[5], 40), (out[6], 90)],
                      font=10)
        doc.enter()
        doc.string('Расходы:')
        outcome_all = 0

        doc.table([('Время', 45), ('Причина', 220), ('Сум.', 40),
                   ('Продавец', 90)])
        self.app.app.db.execute(
            'select time,article,sum,name,art_id,edit from outcome where date=?',
            (self.c_date, ))
        for x in self.app.app.db.fetchall():
            out = list(x)
            if out[5] <> 0:
                out[1] = u'(≈) ' + out[1]
            doc.table([(out[0], 45), (out[1], 220), (out[2], 40),
                       (out[3], 90)],
                      font=10)
            outcome_all += out[2]

        doc.enter()
        doc.string('Всего доходов: %s' % (income_all))
        doc.string('Всего расходов: %s' % (outcome_all))
        doc.string('Остаток: %s' % (income_all - outcome_all))
        doc.end()
        self.win.deiconify()
Exemplo n.º 13
0
    def run(self):
        self.log = Log(self.app.app)
        self.win = Toplevel(self.app.app.win)
        self.win.title(name)
        self.win.protocol("WM_DELETE_WINDOW", self.exit)
        x, y = 800, 450
        pos = self.win.wm_maxsize()[0] / 2 - x / 2, self.win.wm_maxsize(
        )[1] / 2 - y / 2
        self.win.geometry('%sx%s+%s+%s' % (x, y, pos[0], pos[1] - 25))
        self.win.maxsize(width=x, height=y)
        self.win.minsize(width=x, height=y)
        if sys.platform == 'win32': self.win.iconbitmap('app/images/icon.ico')
        year, month = time.localtime()[0:2]
        self.date_t = StringVar()
        self.date_t.set(date_now())
        self.c_date = date_now()
        self.cal = TkCalendar(self.win,
                              year,
                              month,
                              self.date_t,
                              command=self.calend_handler)
        self.cal.grid(row=0, column=0, padx=5, pady=10, sticky=N)

        self.content_frame = Frame(self.win)
        self.content_frame.grid(row=0, column=1, rowspan=3, sticky=N)

        self.tool_frame = Frame(self.win)
        self.tool_frame.grid(row=1, column=0, sticky=N + W)
        Label(self.content_frame, text='Приход:',
              font=('normal', 12)).pack(fill=BOTH)
        self.lst = MultiListbox(self.content_frame,
                                (('Время', 8), ('Отдел', 5), ('Товар', 40),
                                 ('Сумма', 5), ('Кол.во', 1), ('Итог', 5),
                                 ('Продавец', 12)),
                                font=('normal', 10),
                                height=6,
                                command=self.lst1select)
        self.lst.pack(fill=BOTH, expand=1)
        Label(self.content_frame, text='Расход:',
              font=('normal', 12)).pack(fill=BOTH)
        self.lst2 = MultiListbox(self.content_frame,
                                 (('Время', 8), ('Причина', 35), ('Сумма', 5),
                                  ('Продавец', 12)),
                                 font=('normal', 10),
                                 height=6,
                                 command=self.lst2select)
        self.lst2.pack(fill=BOTH, expand=1)

        s = 'За дату: %s' % (norm_date(date_now()))
        self.d_label = Label(self.tool_frame, text=s, font=('bold', 12))
        self.d_label.grid(row=0, columnspan=2, sticky=N + W)

        self.edit_frame_parrent = Labelframe(self.content_frame,
                                             text='Редактировать',
                                             width=50,
                                             height=100)
        self.edit_frame_parrent.pack(fill=BOTH, expand=1)

        self.delete_frame_parrent = Labelframe(self.content_frame,
                                               text='Удалить',
                                               width=50,
                                               height=50)
        self.delete_frame_parrent.pack(fill=BOTH, expand=1)

        self.edit_frame = Frame(self.edit_frame_parrent, height=63)
        self.edit_frame.pack()
        self.delete_frame = Frame(self.delete_frame_parrent, height=46)
        self.delete_frame.pack()

        self.update_lists()
Exemplo n.º 14
0
class Plugin:
    def __init__(self, app):
        self.app = app

    def run(self):
        self.log = Log(self.app.app)
        self.win = Toplevel(self.app.app.win)
        self.win.title(name)
        self.win.protocol("WM_DELETE_WINDOW", self.exit)
        x, y = 800, 450
        pos = self.win.wm_maxsize()[0] / 2 - x / 2, self.win.wm_maxsize(
        )[1] / 2 - y / 2
        self.win.geometry('%sx%s+%s+%s' % (x, y, pos[0], pos[1] - 25))
        self.win.maxsize(width=x, height=y)
        self.win.minsize(width=x, height=y)
        if sys.platform == 'win32': self.win.iconbitmap('app/images/icon.ico')
        year, month = time.localtime()[0:2]
        self.date_t = StringVar()
        self.date_t.set(date_now())
        self.c_date = date_now()
        self.cal = TkCalendar(self.win,
                              year,
                              month,
                              self.date_t,
                              command=self.calend_handler)
        self.cal.grid(row=0, column=0, padx=5, pady=10, sticky=N)

        self.content_frame = Frame(self.win)
        self.content_frame.grid(row=0, column=1, rowspan=3, sticky=N)

        self.tool_frame = Frame(self.win)
        self.tool_frame.grid(row=1, column=0, sticky=N + W)
        Label(self.content_frame, text='Приход:',
              font=('normal', 12)).pack(fill=BOTH)
        self.lst = MultiListbox(self.content_frame,
                                (('Время', 8), ('Отдел', 5), ('Товар', 40),
                                 ('Сумма', 5), ('Кол.во', 1), ('Итог', 5),
                                 ('Продавец', 12)),
                                font=('normal', 10),
                                height=6,
                                command=self.lst1select)
        self.lst.pack(fill=BOTH, expand=1)
        Label(self.content_frame, text='Расход:',
              font=('normal', 12)).pack(fill=BOTH)
        self.lst2 = MultiListbox(self.content_frame,
                                 (('Время', 8), ('Причина', 35), ('Сумма', 5),
                                  ('Продавец', 12)),
                                 font=('normal', 10),
                                 height=6,
                                 command=self.lst2select)
        self.lst2.pack(fill=BOTH, expand=1)

        s = 'За дату: %s' % (norm_date(date_now()))
        self.d_label = Label(self.tool_frame, text=s, font=('bold', 12))
        self.d_label.grid(row=0, columnspan=2, sticky=N + W)

        self.edit_frame_parrent = Labelframe(self.content_frame,
                                             text='Редактировать',
                                             width=50,
                                             height=100)
        self.edit_frame_parrent.pack(fill=BOTH, expand=1)

        self.delete_frame_parrent = Labelframe(self.content_frame,
                                               text='Удалить',
                                               width=50,
                                               height=50)
        self.delete_frame_parrent.pack(fill=BOTH, expand=1)

        self.edit_frame = Frame(self.edit_frame_parrent, height=63)
        self.edit_frame.pack()
        self.delete_frame = Frame(self.delete_frame_parrent, height=46)
        self.delete_frame.pack()

        self.update_lists()

    def exit(self, event=None):
        """ при выходе обновляем главное окно """
        self.app.update_list()
        self.app.update_tools()
        self.win.destroy()

    def calend_handler(self, date):
        """ вызывается при щелчке на дату """
        self.c_date = date
        self.edit_frame.destroy()
        self.edit_frame = Frame(self.edit_frame_parrent, height=63)
        self.edit_frame.pack(fill=BOTH, expand=1)
        self.delete_frame.destroy()
        self.delete_frame = Frame(self.delete_frame_parrent, height=46)
        self.delete_frame.pack(fill=BOTH, expand=1)
        self.update_lists()

    def update_lists(self):
        """ наполняем таблицы """
        self.current_income = []
        self.current_outcome = []
        self.lst.delete(0, END)
        self.app.app.db.execute(
            'select time,dep,article,sum,rate,name,art_id,date,edit from income where date=?',
            (self.c_date, ))
        income_all = 0
        for x in self.app.app.db.fetchall():
            out = list(x)

            if out[8] <> 0:
                out[1] = str(out[1]) + ' (≈)'
            if out[6] <> -1:
                out[1] = str(out[1]) + ' →'
            out.insert(5, round(x[3] * x[4], 2))
            income_all += x[3] * x[4]
            self.lst.insert(END, out)
            self.current_income.append(x)
        self.lst.see(END)
        outcome_all = 0
        self.lst2.delete(0, END)
        self.app.app.db.execute(
            'select time,article,sum,name,art_id,date,edit from outcome where date=?',
            (self.c_date, ))
        for x in self.app.app.db.fetchall():
            out = list(x)
            if out[6] <> 0:
                out[1] = u'(≈) ' + out[1]
            self.lst2.insert(END, out)
            self.current_outcome.append(x)
            outcome_all += out[2]
        self.lst2.see(END)

        s = 'За дату: %s' % (norm_date(self.c_date))
        self.d_label['text'] = s

    def lst1select(self):
        """ при  щелчке на продаже """
        if self.lst2.curselection():
            self.lst2.selection_clear(self.lst2.curselection())
        self.edit_frame.destroy()
        self.edit_frame = Frame(self.edit_frame_parrent, height=63)
        self.edit_frame.pack(fill=BOTH, expand=1)
        self.delete_frame.destroy()
        self.delete_frame = Frame(self.delete_frame_parrent, height=46)
        self.delete_frame.pack(fill=BOTH, expand=1)
        Label(self.delete_frame, text='Причина удаления').grid(row=0,
                                                               column=0,
                                                               padx=10,
                                                               pady=5)
        self.delete_entry = Entry(self.delete_frame,
                                  width=35,
                                  cursor='xterm',
                                  font=('normal', 12))
        self.delete_entry.grid(row=0, column=1, pady=10)
        self.delete_button = Button(self.delete_frame,
                                    text='Удалить',
                                    image=self.app.app.img['delete'],
                                    compound='left',
                                    command=self.delete_income)
        self.delete_button.grid(row=0, column=2, padx=5)

        Label(self.edit_frame, text='Отдел').grid(row=0,
                                                  column=0,
                                                  padx=2,
                                                  pady=2)
        self.otd_ent = Entry(self.edit_frame,
                             width=3,
                             cursor='xterm',
                             font=('normal', 12))
        self.otd_ent.grid(row=0, column=1, padx=2, pady=2)
        Label(self.edit_frame, text='Товар').grid(row=0,
                                                  column=2,
                                                  padx=2,
                                                  pady=2)
        self.tov_ent = Entry(self.edit_frame,
                             width=30,
                             cursor='xterm',
                             font=('normal', 12))
        self.tov_ent.grid(row=0, column=3, padx=2, pady=2)
        Label(self.edit_frame, text='Кол-во').grid(row=0,
                                                   column=4,
                                                   padx=2,
                                                   pady=2)
        self.kvo_ent = Entry(self.edit_frame,
                             width=4,
                             cursor='xterm',
                             font=('normal', 12))
        self.kvo_ent.grid(row=0, column=5, padx=2, pady=2)
        Label(self.edit_frame, text='Сумма').grid(row=0,
                                                  column=6,
                                                  padx=2,
                                                  pady=2)
        self.sum_ent = Entry(self.edit_frame,
                             width=7,
                             cursor='xterm',
                             font=('normal', 12))
        self.sum_ent.grid(row=0, column=7, padx=2, pady=2)

        self.save_but = Button(self.edit_frame,
                               text='Сохранить',
                               image=self.app.app.img['save'],
                               compound='left',
                               command=self.save_income)
        self.save_but.grid(row=1, column=6, columnspan=2, pady=2)
        if not self.lst.curselection(): return
        c = self.current_income[int(self.lst.curselection()[0])]
        self.otd_ent.delete(0, END)
        self.otd_ent.insert(0, c[1])
        self.tov_ent.delete(0, END)
        self.tov_ent.insert(0, c[2])
        self.kvo_ent.delete(0, END)
        self.kvo_ent.insert(0, c[4])
        self.sum_ent.delete(0, END)
        self.sum_ent.insert(0, c[3])

    def lst2select(self):
        """ при  щелчке на расходе """
        if self.lst.curselection():
            self.lst.selection_clear(self.lst.curselection())
        self.edit_frame.destroy()
        self.edit_frame = Frame(self.edit_frame_parrent, height=63)
        self.edit_frame.pack(fill=BOTH, expand=1)
        self.delete_frame.destroy()
        self.delete_frame = Frame(self.delete_frame_parrent, height=46)
        self.delete_frame.pack(fill=BOTH, expand=1)
        Label(self.delete_frame, text='Причина удаления').grid(row=0,
                                                               column=0,
                                                               padx=10,
                                                               pady=5)
        self.delete_entry = Entry(self.delete_frame,
                                  width=35,
                                  cursor='xterm',
                                  font=('normal', 12))
        self.delete_entry.grid(row=0, column=1, pady=10)
        self.delete_button = Button(self.delete_frame,
                                    text='Удалить',
                                    image=self.app.app.img['delete'],
                                    compound='left',
                                    command=self.delete_outcome)
        self.delete_button.grid(row=0, column=2, padx=5)

        Label(self.edit_frame, text='Причина').grid(row=0,
                                                    column=0,
                                                    padx=2,
                                                    pady=2)
        self.pr_ent = Entry(self.edit_frame,
                            width=48,
                            cursor='xterm',
                            font=('normal', 12))
        self.pr_ent.grid(row=0, column=1, padx=2, pady=2)
        Label(self.edit_frame, text='Сумма').grid(row=0,
                                                  column=2,
                                                  padx=2,
                                                  pady=2)
        self.sum_ent = Entry(self.edit_frame,
                             width=7,
                             cursor='xterm',
                             font=('normal', 12))
        self.sum_ent.grid(row=0, column=3, padx=2, pady=2)

        self.save_but = Button(self.edit_frame,
                               text='Сохранить',
                               image=self.app.app.img['save'],
                               compound='left',
                               command=self.save_outcome)
        self.save_but.grid(row=1, column=2, columnspan=2, pady=2, sticky=E)
        if not self.lst2.curselection(): return
        c = self.current_outcome[int(self.lst2.curselection()[0])]
        self.pr_ent.delete(0, END)
        self.pr_ent.insert(0, c[1])
        self.sum_ent.delete(0, END)
        self.sum_ent.insert(0, c[2])

    def delete_income(self):
        """ удаление продажи """
        if not self.lst.curselection(): return
        text = self.delete_entry.get()
        if len(text) < 3:
            box.showerror(title='Ошибка',
                          message='Вы должны ввести причину удаления!')
            self.win.deiconify()
            return
        c = self.current_income[int(self.lst.curselection()[0])]
        self.app.app.db.execute('delete from income where time=? and date=?',
                                (c[0], c[7]))
        self.app.app.con.commit()
        self.delete_entry.delete(0, END)
        self.update_lists()
        self.log.del_income(c[7], c[0], c[1], c[2], text, c[3], c[4],
                            self.app.app.user.decode('utf-8'))

    def delete_outcome(self):
        """ Удаление расхода """
        if not self.lst2.curselection(): return
        text = self.delete_entry.get()
        if len(text) < 3:
            box.showerror(title='Ошибка',
                          message='Вы должны ввести причину удаления!')
            self.win.deiconify()
            return
        c = self.current_outcome[int(self.lst2.curselection()[0])]
        self.app.app.db.execute('delete from outcome where time=? and date=?',
                                (c[0], c[5]))
        self.app.app.con.commit()
        self.delete_entry.delete(0, END)
        self.update_lists()
        self.log.del_outcome(c[5], c[0], c[1], c[2], c[3],
                             self.app.app.user.decode('utf-8'), text)

    def save_income(self):
        """ сохранение отредактированной продажи """
        if not self.lst.curselection(): return
        dep = self.otd_ent.get()
        art = self.tov_ent.get()
        self.app.app.db.execute('select * from dep where id=?', (dep, ))
        if not self.app.app.db.fetchall():
            box.showerror(title='Ошибка', message='Не верный отдел!')
            self.win.deiconify()
            return
        dep = int(dep)
        try:
            kvo = int(self.kvo_ent.get())
        except:
            box.showerror(title='Ошибка', message='Не верное количество!')
            self.win.deiconify()
            return
        try:
            summa = float(self.sum_ent.get().replace(',', '.'))
            if summa <= 0: s = 1 / 0
        except:
            box.showerror(title='Ошибка', message='Не верная сумма!')
            self.win.deiconify()
            return
        c = self.current_income[int(self.lst.curselection()[0])]
        i = int(self.lst.curselection()[0])
        self.app.app.db.execute(
            'update income set dep=?,article=?,rate=?,sum=?,edit=1 where date=? and time=?',
            (dep, art, kvo, summa, c[7], c[0]))
        self.app.app.con.commit()
        self.update_lists()
        self.lst.selection_set(i)
        self.log.edit_income(c[7], c[0], [c[1], c[2], c[4], c[3]],
                             [dep, art, kvo, summa],
                             self.app.app.user.decode('utf-8'), c[5])

    def save_outcome(self):
        """ сохранение отредактированного расхода """
        if not self.lst2.curselection(): return
        text = self.pr_ent.get()
        if len(text) < 3:
            box.showerror(
                title='Ошибка',
                message='Причина удаления не может быть удалена! (как то так)')
            self.win.deiconify()
            return
        c = self.current_outcome[int(self.lst2.curselection()[0])]
        try:
            summa = float(self.sum_ent.get().replace(',', '.'))
            if summa <= 0: s = 1 / 0
        except:
            box.showerror(title='Ошибка', message='Не верная сумма!')
            self.win.deiconify()
            return
        i = int(self.lst2.curselection()[0])

        self.app.app.db.execute(
            'update outcome set article=?,sum=?,edit=1 where date=? and time=?',
            (text, summa, c[5], c[0]))
        self.app.app.con.commit()
        self.update_lists()
        self.lst2.selection_set(i)
        self.log.edit_outcome(c[5], c[0], [c[1], c[2]], [text, summa],
                              self.app.app.user.decode('utf-8'), c[3])
Exemplo n.º 15
0
class Plugin:
	def __init__(self,app):
		self.app=app
		
	def run(self):

		self.win=Toplevel(self.app.app.win)
		self.win.title(name)
		x,y=800,450
		pos=self.win.wm_maxsize()[0]/2-x/2,self.win.wm_maxsize()[1]/2-y/2
		self.win.geometry('%sx%s+%s+%s'%(x,y,pos[0],pos[1]-25))	
		self.win.maxsize(width=x,height=y)
		self.win.minsize(width=x,height=y)
		if sys.platform=='win32':self.win.iconbitmap('app/images/icon.ico')
		year,month = time.localtime()[0:2]
		self.date_t=StringVar()
		self.date_t.set(date_now())
		self.c_date=date_now()
		self.cal=TkCalendar(self.win,year, month, self.date_t,command=self.calend_handler)	
		self.cal.grid(row=0,column=0,padx=5,pady=10,sticky=N)

		self.content_frame=Frame(self.win)
		self.content_frame.grid(row=0,column=1,rowspan=3,sticky=N)
		
		self.tool_frame=Labelframe(self.win,text='Итог')
		self.tool_frame.grid(row=1,column=0,sticky=N+W)
		Label(self.content_frame,text='Приход:',font=('normal',12)).pack(fill=BOTH)
		self.lst=MultiListbox(self.content_frame, (('Время', 8), ('Отдел', 5), ('Товар', 32),('Сумма',5),('Кол.во',1),('Итог',5),('Продавец',12)),font=('normal',10),height=15)
		self.lst.pack(fill=BOTH,expand=1)	
		Label(self.content_frame,text='Расход:',font=('normal',12)).pack(fill=BOTH)
		self.lst2=MultiListbox(self.content_frame, (('Время', 8),  ('Причина', 35),('Сумма',5),('Продавец',12)),font=('normal',10),height=6)
		self.lst2.pack(fill=BOTH,expand=1)


		s='За дату: %s'%(norm_date(date_now()))
		self.d_label=Label(self.tool_frame,text=s,font=('bold',12))
		self.d_label.grid(row=0,columnspan=2,sticky=N+W)

		s='Доход: 0'
		self.in_label=Label(self.tool_frame,text=s,font=('bold',12))
		self.in_label.grid(row=1,columnspan=2,sticky=N+W)
		
		s='Расход: 0'
		self.out_label=Label(self.tool_frame,text=s,font=('bold',12))
		self.out_label.grid(row=2,columnspan=2,sticky=N+W)
		
		s='Остаток: 0'
		self.all_label=Label(self.tool_frame,text=s,font=('bold',12))
		self.all_label.grid(row=3,columnspan=2,sticky=N+W)
		
		self.scr1=Scrollbar(self.tool_frame,orient=VERTICAL)
		self.scr1.grid(row=4,column=1,sticky=N+S,pady=5)
		self.list_1=Listbox(self.tool_frame,width=27,height=5,
			font=("normal",9),
			yscrollcommand=self.scr1.set)
		self.list_1.grid(row=4,column=0,pady=5)
		self.scr1['command']=self.list_1.yview

		self.pdf_but=Button(self.win,text='В pdf',image=self.app.app.img['pdf'],compound='left',command=self.generate_pdf)
		self.pdf_but.grid(row=2,column=0,sticky=N)

		self.update_lists()

	def calend_handler(self,date):
		""" при щелчке на дату в календаре """
		self.c_date=date
		self.update_lists()
		
	def update_lists(self):
		""" заполняем таблицы """
		self.lst.delete(0,END)
		self.app.app.db.execute('select time,dep,article,sum,rate,name,art_id,edit from income where date=?',(self.c_date,))
		income_all=0
		for x in self.app.app.db.fetchall():
			out=list(x)
			if out[7]<>0:
				out[1]=str(out[1])+' (≈)'			
			if out[6]<>-1:
				out[1]=str(out[1])+' →'
			out.insert(5,round(x[3]*x[4],2))
			income_all+=x[3]*x[4]
			self.lst.insert(END,out)
		self.lst.see(END)
		outcome_all=0
		self.lst2.delete(0,END)
		self.app.app.db.execute('select time,article,sum,name,art_id,edit from outcome where date=?',(self.c_date,))
		for x in self.app.app.db.fetchall():
			out=list(x)
			if out[5]<>0:
				out[1]=u'(≈) '+out[1]
			self.lst2.insert(END,out)
			outcome_all+=out[2]
		self.lst2.see(END)
		self.in_label['text']='Доход: %s'%(income_all)
		self.out_label['text']='Расход: %s'%(outcome_all)
		self.all_label['text']='Остаток: %s'%(income_all-outcome_all)
		s='За дату: %s'%(norm_date(self.c_date))
		self.d_label['text']=s	

		deps={}
		deps_sum={}
		self.app.app.db.execute('select name from dep')
		
		self.deps=[]

		
		for n,name in enumerate(self.app.app.db.fetchall()):
			if name:
				deps_sum[n+1]=0
				self.deps.append('%s'%(name[0]))
		
		self.app.app.db.execute('select dep,sum,rate from income where date=?',(self.c_date,))
		out=self.app.app.db.fetchall()
		in_all=0
		for x in out:
			in_all+=float(x[1])*float(x[2])
			deps_sum[x[0]]+=float(x[1])*float(x[2])

		self.list_1.delete(0,END)
		
		for x in deps_sum:
			if deps_sum[x]:
				self.list_1.insert(END,str(x)+' '+self.deps[x-1]+u'→ '+str(deps_sum[x]))
				
	def generate_pdf(self):
		""" генерация pdf. Ваш К.О. """
		try:path=self.app.app.sets.save_pdf
		except:path=''
		filename='Продажи за %s.pdf'%(norm_date(self.c_date))
		f=tkFileDialog.asksaveasfilename(initialdir=path,initialfile=filename)
		if not f:return
		f=f.replace('\\','/')
		self.app.app.sets.save_pdf='/'.join(f.split('/')[:-1])
		doc=pdf.Pdf(title='Продажи за %s'%(norm_date(self.c_date)),fname=f)
		doc.string('Доходы:')
		
		doc.table([('Время',45),('Отд',35),('Товар',220),('Сум.',40),('К-во',30),('Итого',40),('Продавец',90)])
		
		self.app.app.db.execute('select time,dep,article,sum,rate,name,art_id,edit from income where date=?',(self.c_date,))
		income_all=0
		for x in self.app.app.db.fetchall():
			out=list(x)
			if out[7]<>0:
				out[1]=str(out[1])+u' (≈)'			
			if out[6]<>-1:
				out[1]=str(out[1])+u' →'
			out.insert(5,x[3]*x[4])
			income_all+=x[3]*x[4]

			doc.table([(out[0],45),(out[1],35),(out[2],220),(out[3],40),(out[4],30),(out[5],40),(out[6],90)],font=10)
		doc.enter()
		doc.string('Расходы:')		
		outcome_all=0


		doc.table([('Время',45),('Причина',220),('Сум.',40),('Продавец',90)])
		self.app.app.db.execute('select time,article,sum,name,art_id,edit from outcome where date=?',(self.c_date,))
		for x in self.app.app.db.fetchall():
			out=list(x)
			if out[5]<>0:
				out[1]=u'(≈) '+out[1]
			doc.table([(out[0],45),(out[1],220),(out[2],40),(out[3],90)],font=10)
			outcome_all+=out[2]

		doc.enter()
		doc.string('Всего доходов: %s'%(income_all))	
		doc.string('Всего расходов: %s'%(outcome_all))		
		doc.string('Остаток: %s'%(income_all-outcome_all))			
		doc.end()
		self.win.deiconify()
		
		
Exemplo n.º 16
0
class Plugin:
	def __init__(self,app):
		self.app=app
		
	def run(self):
		self.log=Log(self.app.app)
		self.win=Toplevel(self.app.app.win)
		self.win.title(name)
		self.win.protocol("WM_DELETE_WINDOW", self.exit)
		x,y=800,450
		pos=self.win.wm_maxsize()[0]/2-x/2,self.win.wm_maxsize()[1]/2-y/2
		self.win.geometry('%sx%s+%s+%s'%(x,y,pos[0],pos[1]-25))	
		self.win.maxsize(width=x,height=y)
		self.win.minsize(width=x,height=y)
		if sys.platform=='win32':self.win.iconbitmap('app/images/icon.ico')
		year,month = time.localtime()[0:2]
		self.date_t=StringVar()
		self.date_t.set(date_now())
		self.c_date=date_now()
		self.cal=TkCalendar(self.win,year, month, self.date_t,command=self.calend_handler)	
		self.cal.grid(row=0,column=0,padx=5,pady=10,sticky=N)

		self.content_frame=Frame(self.win)
		self.content_frame.grid(row=0,column=1,rowspan=3,sticky=N)
		
		self.tool_frame=Frame(self.win)
		self.tool_frame.grid(row=1,column=0,sticky=N+W)
		Label(self.content_frame,text='Приход:',font=('normal',12)).pack(fill=BOTH)
		self.lst=MultiListbox(self.content_frame, (('Время', 8), ('Отдел', 5), ('Товар', 40),('Сумма',5),('Кол.во',1),('Итог',5),('Продавец',12)),font=('normal',10),height=6,command=self.lst1select)
		self.lst.pack(fill=BOTH,expand=1)	
		Label(self.content_frame,text='Расход:',font=('normal',12)).pack(fill=BOTH)
		self.lst2=MultiListbox(self.content_frame, (('Время', 8),  ('Причина', 35),('Сумма',5),('Продавец',12)),font=('normal',10),height=6,command=self.lst2select)
		self.lst2.pack(fill=BOTH,expand=1)


		s='За дату: %s'%(norm_date(date_now()))
		self.d_label=Label(self.tool_frame,text=s,font=('bold',12))
		self.d_label.grid(row=0,columnspan=2,sticky=N+W)
		
		
		self.edit_frame_parrent=Labelframe(self.content_frame,text='Редактировать',
			width=50,height=100)
		self.edit_frame_parrent.pack(fill=BOTH,expand=1)

		self.delete_frame_parrent=Labelframe(self.content_frame,text='Удалить',
			width=50,height=50)
		self.delete_frame_parrent.pack(fill=BOTH,expand=1)	

		self.edit_frame=Frame(self.edit_frame_parrent,height=63)
		self.edit_frame.pack()
		self.delete_frame=Frame(self.delete_frame_parrent,height=46)
		self.delete_frame.pack()		



		self.update_lists()

	def exit(self,event=None):
		""" при выходе обновляем главное окно """
		self.app.update_list()
		self.app.update_tools()
		self.win.destroy()

	def calend_handler(self,date):
		""" вызывается при щелчке на дату """
		self.c_date=date
		self.edit_frame.destroy()
		self.edit_frame=Frame(self.edit_frame_parrent,height=63)
		self.edit_frame.pack(fill=BOTH,expand=1)
		self.delete_frame.destroy()
		self.delete_frame=Frame(self.delete_frame_parrent,height=46)
		self.delete_frame.pack(fill=BOTH,expand=1)	
		self.update_lists()
		
	def update_lists(self):
		""" наполняем таблицы """
		self.current_income=[]
		self.current_outcome=[]
		self.lst.delete(0,END)
		self.app.app.db.execute('select time,dep,article,sum,rate,name,art_id,date,edit from income where date=?',(self.c_date,))
		income_all=0
		for x in self.app.app.db.fetchall():
			out=list(x)
			
			if out[8]<>0:
				out[1]=str(out[1])+' (≈)'			
			if out[6]<>-1:
				out[1]=str(out[1])+' →'
			out.insert(5,round(x[3]*x[4],2))
			income_all+=x[3]*x[4]
			self.lst.insert(END,out)
			self.current_income.append(x)
		self.lst.see(END)
		outcome_all=0
		self.lst2.delete(0,END)
		self.app.app.db.execute('select time,article,sum,name,art_id,date,edit from outcome where date=?',(self.c_date,))
		for x in self.app.app.db.fetchall():
			out=list(x)
			if out[6]<>0:
				out[1]=u'(≈) '+out[1]
			self.lst2.insert(END,out)
			self.current_outcome.append(x)
			outcome_all+=out[2]
		self.lst2.see(END)

		s='За дату: %s'%(norm_date(self.c_date))
		self.d_label['text']=s	
	
	def lst1select(self):
		""" при  щелчке на продаже """
		if self.lst2.curselection():
			self.lst2.selection_clear(self.lst2.curselection())
		self.edit_frame.destroy()
		self.edit_frame=Frame(self.edit_frame_parrent,height=63)
		self.edit_frame.pack(fill=BOTH,expand=1)
		self.delete_frame.destroy()
		self.delete_frame=Frame(self.delete_frame_parrent,height=46)
		self.delete_frame.pack(fill=BOTH,expand=1)
		Label(self.delete_frame,text='Причина удаления').grid(row=0,column=0,padx=10,pady=5)
		self.delete_entry=Entry(self.delete_frame,width=35,cursor='xterm',font=('normal',12))
		self.delete_entry.grid(row=0,column=1,pady=10)
		self.delete_button=Button(self.delete_frame,text='Удалить',image=self.app.app.img['delete'],compound='left',command=self.delete_income)
		self.delete_button.grid(row=0,column=2,padx=5)
		
		Label(self.edit_frame,text='Отдел').grid(row=0,column=0,padx=2,pady=2)
		self.otd_ent=Entry(self.edit_frame,width=3,cursor='xterm',font=('normal',12))
		self.otd_ent.grid(row=0,column=1,padx=2,pady=2)
		Label(self.edit_frame,text='Товар').grid(row=0,column=2,padx=2,pady=2)		
		self.tov_ent=Entry(self.edit_frame,width=30,cursor='xterm',font=('normal',12))
		self.tov_ent.grid(row=0,column=3,padx=2,pady=2)		
		Label(self.edit_frame,text='Кол-во').grid(row=0,column=4,padx=2,pady=2)	
		self.kvo_ent=Entry(self.edit_frame,width=4,cursor='xterm',font=('normal',12))
		self.kvo_ent.grid(row=0,column=5,padx=2,pady=2)
		Label(self.edit_frame,text='Сумма').grid(row=0,column=6,padx=2,pady=2)
		self.sum_ent=Entry(self.edit_frame,width=7,cursor='xterm',font=('normal',12))
		self.sum_ent.grid(row=0,column=7,padx=2,pady=2)		
		
		self.save_but=Button(self.edit_frame,text='Сохранить',image=self.app.app.img['save'],compound='left',command=self.save_income)
		self.save_but.grid(row=1,column=6,columnspan=2,pady=2)
		if not self.lst.curselection():return
		c=self.current_income[int(self.lst.curselection()[0])]
		self.otd_ent.delete(0,END)
		self.otd_ent.insert(0,c[1])
		self.tov_ent.delete(0,END)
		self.tov_ent.insert(0,c[2])		
		self.kvo_ent.delete(0,END)
		self.kvo_ent.insert(0,c[4])	
		self.sum_ent.delete(0,END)
		self.sum_ent.insert(0,c[3])	
	def lst2select(self):
		""" при  щелчке на расходе """
		if self.lst.curselection():
			self.lst.selection_clear(self.lst.curselection())
		self.edit_frame.destroy()
		self.edit_frame=Frame(self.edit_frame_parrent,height=63)
		self.edit_frame.pack(fill=BOTH,expand=1)
		self.delete_frame.destroy()
		self.delete_frame=Frame(self.delete_frame_parrent,height=46)
		self.delete_frame.pack(fill=BOTH,expand=1)	
		Label(self.delete_frame,text='Причина удаления').grid(row=0,column=0,padx=10,pady=5)
		self.delete_entry=Entry(self.delete_frame,width=35,cursor='xterm',font=('normal',12))
		self.delete_entry.grid(row=0,column=1,pady=10)	
		self.delete_button=Button(self.delete_frame,text='Удалить',image=self.app.app.img['delete'],compound='left',command=self.delete_outcome)
		self.delete_button.grid(row=0,column=2,padx=5)

		
		Label(self.edit_frame,text='Причина').grid(row=0,column=0,padx=2,pady=2)
		self.pr_ent=Entry(self.edit_frame,width=48,cursor='xterm',font=('normal',12))
		self.pr_ent.grid(row=0,column=1,padx=2,pady=2)
		Label(self.edit_frame,text='Сумма').grid(row=0,column=2,padx=2,pady=2)		
		self.sum_ent=Entry(self.edit_frame,width=7,cursor='xterm',font=('normal',12))
		self.sum_ent.grid(row=0,column=3,padx=2,pady=2)		

		
		self.save_but=Button(self.edit_frame,text='Сохранить',image=self.app.app.img['save'],compound='left',command=self.save_outcome)
		self.save_but.grid(row=1,column=2,columnspan=2,pady=2,sticky=E)
		if not self.lst2.curselection():return
		c=self.current_outcome[int(self.lst2.curselection()[0])]
		self.pr_ent.delete(0,END)
		self.pr_ent.insert(0,c[1])
		self.sum_ent.delete(0,END)
		self.sum_ent.insert(0,c[2])		



	def delete_income(self):
		""" удаление продажи """
		if not self.lst.curselection():return
		text=self.delete_entry.get()
		if len(text)<3:
			box.showerror(title='Ошибка',message='Вы должны ввести причину удаления!')
			self.win.deiconify()
			return
		c=self.current_income[int(self.lst.curselection()[0])]
		self.app.app.db.execute('delete from income where time=? and date=?',(c[0],c[7]))
		self.app.app.con.commit()
		self.delete_entry.delete(0,END)
		self.update_lists()
		self.log.del_income(c[7],c[0],c[1],c[2],text,c[3],c[4],self.app.app.user.decode('utf-8'))
		
	def delete_outcome(self):
		""" Удаление расхода """
		if not self.lst2.curselection():return
		text=self.delete_entry.get()
		if len(text)<3:
			box.showerror(title='Ошибка',message='Вы должны ввести причину удаления!')
			self.win.deiconify()
			return
		c=self.current_outcome[int(self.lst2.curselection()[0])]
		self.app.app.db.execute('delete from outcome where time=? and date=?',(c[0],c[5]))
		self.app.app.con.commit()
		self.delete_entry.delete(0,END)
		self.update_lists()
		self.log.del_outcome(c[5],c[0],c[1],c[2],c[3],self.app.app.user.decode('utf-8'),text)		
		
	def save_income(self):
		""" сохранение отредактированной продажи """
		if not self.lst.curselection():return
		dep=self.otd_ent.get()
		art=self.tov_ent.get()
		self.app.app.db.execute('select * from dep where id=?',(dep,))
		if not self.app.app.db.fetchall():
			box.showerror(title='Ошибка',message='Не верный отдел!')
			self.win.deiconify()
			return
		dep=int(dep)
		try:
			kvo=int(self.kvo_ent.get())
		except:
			box.showerror(title='Ошибка',message='Не верное количество!')
			self.win.deiconify()
			return	
		try:
			summa=float(self.sum_ent.get().replace(',','.'))
			if summa<=0:s=1/0
		except:
			box.showerror(title='Ошибка',message='Не верная сумма!')
			self.win.deiconify()
			return
		c=self.current_income[int(self.lst.curselection()[0])]	
		i=int(self.lst.curselection()[0])
		self.app.app.db.execute('update income set dep=?,article=?,rate=?,sum=?,edit=1 where date=? and time=?',(dep,art,kvo,summa,c[7],c[0]))
		self.app.app.con.commit()
		self.update_lists()
		self.lst.selection_set(i)
		self.log.edit_income(c[7],c[0],[c[1],c[2],c[4],c[3]],[dep,art,kvo,summa],self.app.app.user.decode('utf-8'),c[5])
		
	def save_outcome(self):
		""" сохранение отредактированного расхода """
		if not self.lst2.curselection():return
		text=self.pr_ent.get()
		if len(text)<3:
			box.showerror(title='Ошибка',message='Причина удаления не может быть удалена! (как то так)')
			self.win.deiconify()
			return
		c=self.current_outcome[int(self.lst2.curselection()[0])]
		try:
			summa=float(self.sum_ent.get().replace(',','.'))
			if summa<=0:s=1/0
		except:
			box.showerror(title='Ошибка',message='Не верная сумма!')
			self.win.deiconify()
			return		
		i=int(self.lst2.curselection()[0])
		
		self.app.app.db.execute('update outcome set article=?,sum=?,edit=1 where date=? and time=?',(text,summa,c[5],c[0]))
		self.app.app.con.commit()
		self.update_lists()
		self.lst2.selection_set(i)
		self.log.edit_outcome(c[5],c[0],[c[1],c[2]],[text,summa],self.app.app.user.decode('utf-8'),c[3])