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 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 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 add_handler(self): """ добавление расхода """ text = self.pr_ent.get() try: s = float(self.sum_ent.get().replace(',', '.')) except: box.showerror(title='Ошибка', message='Не верная сумма!') self.win.deiconify() return if s <= 0: box.showerror(title='Ошибка', message='Не верная сумма!') self.win.deiconify() return if len(text) < 3: box.showerror(title='Ошибка', message='Вы должны ввести причину!') self.win.deiconify() return dt, tm = date_now(), time_now() self.app.app.db.execute( 'insert into outcome values (?,?,?,?,?,?,0)', (dt, tm, text, -1, s, self.app.app.user.decode('utf-8'))) self.app.app.con.commit() self.win.destroy() self.app.update_tools() self.init_add_plugins(dt, tm)
def generate_csv(self): """ генерация csv """ try:path=self.app.app.sets.save_pdf except:path='' filename='Остатки по отделу %s на %s.csv'%(self.cur_dep+1,norm_date(date_now())) 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=csv.writer(open(f,'w'),delimiter=';',lineterminator='\n',quoting=csv.QUOTE_ALL) doc.writerow([u'Товар'.encode('cp1251'),u'Остаток'.encode('cp1251'),u'Стоимость'.encode('cp1251')]) r=self.rb_var.get() rate=self.rate_ent.get() self.app.app.db.execute('select name from dep where id=?',(self.cur_dep+1,)) dep_name=self.app.app.db.fetchall()[0][0] if r==0: self.app.app.db.execute('select id,rate,sum,type from article where dep=?',(self.cur_dep+1,)) else: try:rate=int(rate) except:return self.app.app.db.execute('select id,rate,sum,type from article where dep=? and rate<?',(self.cur_dep+1,rate)) rez1=self.app.app.db.fetchall() all_rate=0 all_sum=0 for x in rez1: t=[] flag=True self.app.app.db.execute('select name,edit,sum,parent from article where id=?',(x[0],)) s=self.app.app.db.fetchall()[0] par=s[3] t.append(s[0]) if par==-1:flag=0 while flag: self.app.app.db.execute('select name,parent from article where id=?',(par,)) rez=self.app.app.db.fetchall()[0] if rez[1]==-1: t.append(rez[0]) flag=False else: t.append(rez[0]) par=rez[1] cat_lst=' > '.join(t[::-1]) if x[3]=='item': doc.writerow([cat_lst.encode('cp1251'),x[1],x[2]]) all_rate+=x[1] all_sum+=x[1]*x[2] self.lab_var.set('Наименований: %s, количество: %s, на сумму %s'%(len(rez1),all_rate,all_sum)) self.win.deiconify()
def del_outcome(self, date, tm, art, sum, c_user, user, pr): """Запись об уделании расхода """ mess = u'Пользователь %s удалил расход от %s %s\nРасход: %s\nНа сумму: %s\nБыл сделан пользователем %s\nПричина: %s' % ( user, norm_date(date).decode('utf-8'), tm, art, sum, c_user, pr) self.db.execute( 'insert into edit_log values (?,?,?,?,?,?)', (date_now(), time_now(), u'Удален расход', mess, date, tm)) self.con.commit()
def del_income(self, date, tm, dep, art, pr, summa, rate, user): """Запись об уделании продажи """ mess = u'Пользователь %s удалил продажу от %s %s\nОтдела #%s\nТовар: %s\nСумма: %s, количество: %s\nПо причине: %s' % ( user, norm_date(date).decode('utf-8'), tm, dep, art, summa, rate, pr) self.db.execute( 'insert into edit_log values (?,?,?,?,?,?)', (date_now(), time_now(), u'Удалена продажа', mess, date, tm)) self.con.commit()
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 edit_outcome(self,date,tm,old,new,user,c_user): """Запись о редактировании расхода """ ms=[] if old[0]<>new[0]: ms.append(u'Причина с %s на %s'%(old[0],new[0])) if old[1]<>new[1]: ms.append(u'Сумма с %s на %s'%(old[1],new[1])) if not ms:return mess=u'Пользователь %s изменил расход от %s %s\nИзменения:\n%s\nБыл сделан пользователем %s'%(user,norm_date(date).decode('utf-8'),tm,'\n'.join(ms),c_user) self.db.execute('insert into edit_log values (?,?,?,?,?,?)',(date_now(),time_now(),u'Отредактирован расход',mess,date,tm)) self.con.commit()
def sync(self): self.db.execute('select value from misc where name="update_date"') update_date=self.db.fetchall()[0][0] self.db.execute('select value from misc where name="update_time"') update_time=self.db.fetchall()[0][0] r={} r['auth']={'login':self.sync_login,'passw':self.sync_passw} r['db']=self.sync_point out=[] n_dt=date2int(update_date,update_time) self.db.execute('select date,time,dep,article,sum,rate,name from income where myDate(date,time)>=?',(n_dt,)) for x in self.db.fetchall(): out.append(['income']+list(x)) self.db.execute('select date,time,article,sum,name from outcome where myDate(date,time)>=?',(n_dt,)) for x in self.db.fetchall(): out.append(['outcome']+list(x)) self.db.execute('select original_date,original_time,title from edit_log where myDate(date,time)>=?',(n_dt,)) for x in self.db.fetchall(): if x[2]==u'Отредактирована продажа': self.db.execute('select date,time,dep,article,sum,rate,name from income where date=? and time=?',(x[0],x[1])) try:out.append(['income']+list(self.db.fetchall()[0])) except IndexError:pass elif x[2]==u'Отредактирован расход': self.db.execute('select date,time,article,sum,name from outcome where date=? and time=?',(x[0],x[1])) try:out.append(['outcome']+list(self.db.fetchall()[0])) except IndexError:pass if x[2]==u'Удалена продажа': out.append(['del_income',x[0],x[1]]) if x[2]==u'Удален расход': out.append(['del_outcome',x[0],x[1]]) if len(out)==0: return r['data']=out d={} d['data']=json.dumps(r) self.db.execute('select value from misc where name="sync_server"') sync_server=self.db.fetchall()[0][0] response=urllib.urlopen(sync_server+'/sync',urllib.urlencode(d)).read() if response=='1': self.db.execute('update misc set value=? where name="update_date"',(date_now(),)) self.db.execute('update misc set value=? where name="update_time"',(time_now(),)) self.con.commit()
def edit_outcome(self, date, tm, old, new, user, c_user): """Запись о редактировании расхода """ ms = [] if old[0] <> new[0]: ms.append(u'Причина с %s на %s' % (old[0], new[0])) if old[1] <> new[1]: ms.append(u'Сумма с %s на %s' % (old[1], new[1])) if not ms: return mess = u'Пользователь %s изменил расход от %s %s\nИзменения:\n%s\nБыл сделан пользователем %s' % ( user, norm_date(date).decode('utf-8'), tm, '\n'.join(ms), c_user) self.db.execute( 'insert into edit_log values (?,?,?,?,?,?)', (date_now(), time_now(), u'Отредактирован расход', mess, date, tm)) self.con.commit()
def edit_income(self,date,tm,old,new,user,c_user): """Запись о редактировании продажи """ ms=[] if old[0]<>new[0]: ms.append(u'Отдел с %s на %s'%(old[0],new[0])) if old[1]<>new[1]: ms.append(u'Товар с %s на %s'%(old[1],new[1])) if old[2]<>new[2]: ms.append(u'Количество с %s на %s'%(old[2],new[2])) if old[3]<>new[3]: ms.append(u'Сумма с %s на %s'%(old[3],new[3])) if not ms:return mess=u'Пользователь %s изменил продажу от %s %s\nИзменения:\n%s\nБыла сделана пользователем %s'%(user,norm_date(date).decode('utf-8'),tm,'\n'.join(ms),c_user) self.db.execute('insert into edit_log values (?,?,?,?,?,?)',(date_now(),time_now(),u'Отредактирована продажа',mess,date,tm)) self.con.commit()
def save_all(self): """ Сохранияем списание """ date = date_now() tm = time_now() user = self.app.app.user.decode('utf-8') try: razves = eval(self.app.app.sets.razves)[self.cur_dep] except AttributeError: razves = 0 txt = self.dep_name.get('0.0', END).replace('\r', '').replace( '\n', ' ').replace('\t', ' ') if len(txt) < 2: box.showerror(title='Ошибка', message='Не выбран товар!') self.win.deiconify() return try: if razves: rate = float(self.rate_v.get().replace(',', '.')) else: rate = int(self.rate_v.get().replace(',', '.')) except: box.showerror(title='Ошибка', message='Не верное количество!') self.win.deiconify() return if rate <= 0: box.showerror(title='Ошибка', message='Не верное количество!') self.win.deiconify() return event = self.pr_ent.get() if len(event) < 2: box.showerror(title='Ошибка', message='Не введена причина!') self.win.deiconify() return self.app.app.db.execute('insert into out_art values (?,?,?,?,?,?)', (date, tm, txt, event, rate, user)) self.app.app.db.execute('select rate from article where id=?', (self.cat_id, )) rate = self.app.app.db.fetchall()[0][0] - rate if rate < 0: box.showerror(title='Ошибка', message='Товара итак нет!') self.win.deiconify() return self.app.app.db.execute('update article set rate=? where id=?', (rate, self.cat_id)) self.app.app.con.commit() self.win.destroy()
def edit_income(self, date, tm, old, new, user, c_user): """Запись о редактировании продажи """ ms = [] if old[0] <> new[0]: ms.append(u'Отдел с %s на %s' % (old[0], new[0])) if old[1] <> new[1]: ms.append(u'Товар с %s на %s' % (old[1], new[1])) if old[2] <> new[2]: ms.append(u'Количество с %s на %s' % (old[2], new[2])) if old[3] <> new[3]: ms.append(u'Сумма с %s на %s' % (old[3], new[3])) if not ms: return mess = u'Пользователь %s изменил продажу от %s %s\nИзменения:\n%s\nБыла сделана пользователем %s' % ( user, norm_date(date).decode('utf-8'), tm, '\n'.join(ms), c_user) self.db.execute('insert into edit_log values (?,?,?,?,?,?)', (date_now(), time_now(), u'Отредактирована продажа', mess, date, tm)) self.con.commit()
def save_all(self): """ Сохрание прихода и записть в таблицу приходов """ date=date_now() tm=time_now() user=self.app.app.user.decode('utf-8') self.app.app.db.execute('select max(id) from in_art') try:id=self.app.app.db.fetchall()[0][0]+1 except:id=1 for x in self.cur_list: self.app.app.db.execute('insert into in_art values (?,?,?,?,?,?,?)',(id,date,tm,x[0],x[1],x[2],user)) self.app.app.db.execute('select rate from article where id=?',(x[3],)) rate=self.app.app.db.fetchall()[0][0]+x[2] self.app.app.db.execute('update article set rate=? where id=?',(rate,x[3])) self.app.app.con.commit() self.win.destroy()
def save_all(self): """ Сохранияем списание """ date=date_now() tm=time_now() user=self.app.app.user.decode('utf-8') try:razves=eval(self.app.app.sets.razves)[self.cur_dep] except AttributeError:razves=0 txt=self.dep_name.get('0.0',END).replace('\r','').replace('\n',' ').replace('\t',' ') if len(txt)<2: box.showerror(title='Ошибка',message='Не выбран товар!') self.win.deiconify() return try: if razves:rate=float(self.rate_v.get().replace(',','.')) else:rate=int(self.rate_v.get().replace(',','.')) except: box.showerror(title='Ошибка',message='Не верное количество!') self.win.deiconify() return if rate<=0: box.showerror(title='Ошибка',message='Не верное количество!') self.win.deiconify() return event=self.pr_ent.get() if len(event)<2: box.showerror(title='Ошибка',message='Не введена причина!') self.win.deiconify() return self.app.app.db.execute('insert into out_art values (?,?,?,?,?,?)',(date,tm,txt,event,rate,user)) self.app.app.db.execute('select rate from article where id=?',(self.cat_id,)) rate=self.app.app.db.fetchall()[0][0]-rate if rate<0: box.showerror(title='Ошибка',message='Товара итак нет!') self.win.deiconify() return self.app.app.db.execute('update article set rate=? where id=?',(rate,self.cat_id)) self.app.app.con.commit() self.win.destroy()
def add_handler(self): """ добавление расхода """ text=self.pr_ent.get() try:s=float(self.sum_ent.get().replace(',','.')) except: box.showerror(title='Ошибка',message='Не верная сумма!') self.win.deiconify() return if s<=0: box.showerror(title='Ошибка',message='Не верная сумма!') self.win.deiconify() return if len(text)<3: box.showerror(title='Ошибка',message='Вы должны ввести причину!') self.win.deiconify() return dt,tm=date_now(),time_now() self.app.app.db.execute('insert into outcome values (?,?,?,?,?,?,0)',(dt,tm,text,-1,s,self.app.app.user.decode('utf-8'))) self.app.app.con.commit() self.win.destroy() self.app.update_tools() self.init_add_plugins(dt,tm)
def save_all(self): """ Сохрание прихода и записть в таблицу приходов """ date = date_now() tm = time_now() user = self.app.app.user.decode('utf-8') self.app.app.db.execute('select max(id) from in_art') try: id = self.app.app.db.fetchall()[0][0] + 1 except: id = 1 for x in self.cur_list: self.app.app.db.execute( 'insert into in_art values (?,?,?,?,?,?,?)', (id, date, tm, x[0], x[1], x[2], user)) self.app.app.db.execute('select rate from article where id=?', (x[3], )) rate = self.app.app.db.fetchall()[0][0] + x[2] self.app.app.db.execute('update article set rate=? where id=?', (rate, x[3])) self.app.app.con.commit() self.win.destroy()
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 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 generate_pdf(self): """ генерация pdf """ try:path=self.app.app.sets.save_pdf except:path='' filename='Остатки по отделу %s на %s.pdf'%(self.cur_dep+1,norm_date(date_now())) 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='Остатки товара',fname=f) r=self.rb_var.get() rate=self.rate_ent.get() self.app.app.db.execute('select name from dep where id=?',(self.cur_dep+1,)) dep_name=self.app.app.db.fetchall()[0][0] if r==0: self.app.app.db.execute('select id,rate,sum,type from article where dep=?',(self.cur_dep+1,)) doc.string(u'Все остатки по отделу %s %s'%(self.cur_dep+1,dep_name)) else: try:rate=int(rate) except:return self.app.app.db.execute('select id,rate,sum,type from article where dep=? and rate<?',(self.cur_dep+1,rate)) doc.string(u'Остатки по отделу %s %s, количество товара меньше %s'%(self.cur_dep+1,dep_name,rate)) rez1=self.app.app.db.fetchall() all_rate=0 all_sum=0 doc.table([('Товар',300),('Остаток',80),('Стоимость',80)]) for x in rez1: t=[] flag=True self.app.app.db.execute('select name,edit,sum,parent from article where id=?',(x[0],)) s=self.app.app.db.fetchall()[0] par=s[3] t.append(s[0]) if par==-1:flag=0 while flag: self.app.app.db.execute('select name,parent from article where id=?',(par,)) rez=self.app.app.db.fetchall()[0] if rez[1]==-1: t.append(rez[0]) flag=False else: t.append(rez[0]) par=rez[1] cat_lst=' > '.join(t[::-1]) if x[3]=='item': doc.table([(cat_lst,300),(x[1],80),(x[2],80)],font=10) all_rate+=x[1] all_sum+=x[1]*x[2] self.lab_var.set('Наименований: %s, количество: %s, на сумму %s'%(len(rez1),all_rate,all_sum)) doc.enter() doc.string('Всего наименований: %s'%(len(rez1))) doc.string('Всего количество: %s, на сумму %s'%(all_rate,all_sum)) doc.end() self.win.deiconify()
def sync(self): self.con=self.app.con self.db=self.con.cursor() # если не нужно, то выходим self.db.execute('select value from misc where name="sync_enable"') if self.db.fetchall()[0][0]=='0': sys.exit(0) self.db.execute('select value from misc where name="sync_period"') sync_time=int(self.db.fetchall()[0][0]) self.db.execute('select value from misc where name="sync_point"') self.sync_point=self.db.fetchall()[0][0].encode('utf-8') self.sync_point=hash(self.sync_point) self.db.execute('select value from misc where name="sync_login"') self.sync_login=self.db.fetchall()[0][0] self.db.execute('select value from misc where name="sync_passw"') self.sync_passw=self.db.fetchall()[0][0] self.db.execute('select value from misc where name="sync_server"') self.sync_server=self.db.fetchall()[0][0] self.db.execute('select value from misc where name="update_date"') update_date=self.db.fetchall()[0][0] self.db.execute('select value from misc where name="update_time"') update_time=self.db.fetchall()[0][0] r={} r['auth']={'login':self.sync_login,'passw':self.sync_passw} r['db']=self.sync_point out=[] n_dt=date2int(update_date,update_time) self.db.execute('select date,time,dep,article,sum,rate,name from income where myDate(date,time)>=?',(n_dt,)) for x in self.db.fetchall(): out.append(['income']+list(x)) self.db.execute('select date,time,article,sum,name from outcome where myDate(date,time)>=?',(n_dt,)) for x in self.db.fetchall(): out.append(['outcome']+list(x)) self.db.execute('select original_date,original_time,title from edit_log where myDate(date,time)>=?',(n_dt,)) for x in self.db.fetchall(): if x[2]==u'Отредактирована продажа': self.db.execute('select date,time,dep,article,sum,rate,name from income where date=? and time=?',(x[0],x[1])) try:out.append(['income']+list(self.db.fetchall()[0])) except IndexError:pass elif x[2]==u'Отредактирован расход': self.db.execute('select date,time,article,sum,name from outcome where date=? and time=?',(x[0],x[1])) try:out.append(['outcome']+list(self.db.fetchall()[0])) except IndexError:pass if x[2]==u'Удалена продажа': out.append(['del_income',x[0],x[1]]) if x[2]==u'Удален расход': out.append(['del_outcome',x[0],x[1]]) if len(out)==0: sys.exit(0) self.lab['text']='Выполняется отправка данных на сервер...' self.lab['background']='green' self.lab['foreground']='black' self.win.update() r['data']=out d={} d['data']=json.dumps(r) self.db.execute('select value from misc where name="sync_server"') sync_server=self.db.fetchall()[0][0] response=urllib.urlopen(sync_server+'/sync',urllib.urlencode(d)).read() if response=='1': self.db.execute('update misc set value=? where name="update_date"',(date_now(),)) self.db.execute('update misc set value=? where name="update_time"',(time_now(),)) self.con.commit() sys.exit(0) else: raise
def generate_pdf(self): """ генерация pdf """ try: path = self.app.app.sets.save_pdf except: path = '' filename = 'Остатки по отделу %s на %s.pdf' % (self.cur_dep + 1, norm_date(date_now())) 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='Остатки товара', fname=f) r = self.rb_var.get() rate = self.rate_ent.get() self.app.app.db.execute('select name from dep where id=?', (self.cur_dep + 1, )) dep_name = self.app.app.db.fetchall()[0][0] if r == 0: self.app.app.db.execute( 'select id,rate,sum,type from article where dep=?', (self.cur_dep + 1, )) doc.string(u'Все остатки по отделу %s %s' % (self.cur_dep + 1, dep_name)) else: try: rate = int(rate) except: return self.app.app.db.execute( 'select id,rate,sum,type from article where dep=? and rate<?', (self.cur_dep + 1, rate)) doc.string( u'Остатки по отделу %s %s, количество товара меньше %s' % (self.cur_dep + 1, dep_name, rate)) rez1 = self.app.app.db.fetchall() all_rate = 0 all_sum = 0 doc.table([('Товар', 300), ('Остаток', 80), ('Стоимость', 80)]) for x in rez1: t = [] flag = True self.app.app.db.execute( 'select name,edit,sum,parent from article where id=?', (x[0], )) s = self.app.app.db.fetchall()[0] par = s[3] t.append(s[0]) if par == -1: flag = 0 while flag: self.app.app.db.execute( 'select name,parent from article where id=?', (par, )) rez = self.app.app.db.fetchall()[0] if rez[1] == -1: t.append(rez[0]) flag = False else: t.append(rez[0]) par = rez[1] cat_lst = ' > '.join(t[::-1]) if x[3] == 'item': doc.table([(cat_lst, 300), (x[1], 80), (x[2], 80)], font=10) all_rate += x[1] all_sum += x[1] * x[2] self.lab_var.set('Наименований: %s, количество: %s, на сумму %s' % (len(rez1), all_rate, all_sum)) doc.enter() doc.string('Всего наименований: %s' % (len(rez1))) doc.string('Всего количество: %s, на сумму %s' % (all_rate, all_sum)) doc.end() self.win.deiconify()
def del_outcome(self,date,tm,art,sum,c_user,user,pr): """Запись об уделании расхода """ mess=u'Пользователь %s удалил расход от %s %s\nРасход: %s\nНа сумму: %s\nБыл сделан пользователем %s\nПричина: %s'%(user,norm_date(date).decode('utf-8'),tm,art,sum,c_user,pr) self.db.execute('insert into edit_log values (?,?,?,?,?,?)',(date_now(),time_now(),u'Удален расход',mess,date,tm)) self.con.commit()
def del_income(self,date,tm,dep,art,pr,summa,rate,user): """Запись об уделании продажи """ mess=u'Пользователь %s удалил продажу от %s %s\nОтдела #%s\nТовар: %s\nСумма: %s, количество: %s\nПо причине: %s'%(user,norm_date(date).decode('utf-8'),tm,dep,art,summa,rate,pr) self.db.execute('insert into edit_log values (?,?,?,?,?,?)',(date_now(),time_now(),u'Удалена продажа',mess,date,tm)) self.con.commit()
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 generate_csv(self): """ генерация csv """ try: path = self.app.app.sets.save_pdf except: path = '' filename = 'Остатки по отделу %s на %s.csv' % (self.cur_dep + 1, norm_date(date_now())) 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 = csv.writer(open(f, 'w'), delimiter=';', lineterminator='\n', quoting=csv.QUOTE_ALL) doc.writerow([ u'Товар'.encode('cp1251'), u'Остаток'.encode('cp1251'), u'Стоимость'.encode('cp1251') ]) r = self.rb_var.get() rate = self.rate_ent.get() self.app.app.db.execute('select name from dep where id=?', (self.cur_dep + 1, )) dep_name = self.app.app.db.fetchall()[0][0] if r == 0: self.app.app.db.execute( 'select id,rate,sum,type from article where dep=?', (self.cur_dep + 1, )) else: try: rate = int(rate) except: return self.app.app.db.execute( 'select id,rate,sum,type from article where dep=? and rate<?', (self.cur_dep + 1, rate)) rez1 = self.app.app.db.fetchall() all_rate = 0 all_sum = 0 for x in rez1: t = [] flag = True self.app.app.db.execute( 'select name,edit,sum,parent from article where id=?', (x[0], )) s = self.app.app.db.fetchall()[0] par = s[3] t.append(s[0]) if par == -1: flag = 0 while flag: self.app.app.db.execute( 'select name,parent from article where id=?', (par, )) rez = self.app.app.db.fetchall()[0] if rez[1] == -1: t.append(rez[0]) flag = False else: t.append(rez[0]) par = rez[1] cat_lst = ' > '.join(t[::-1]) if x[3] == 'item': doc.writerow([cat_lst.encode('cp1251'), x[1], x[2]]) all_rate += x[1] all_sum += x[1] * x[2] self.lab_var.set('Наименований: %s, количество: %s, на сумму %s' % (len(rez1), all_rate, all_sum)) self.win.deiconify()
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 sync(self): self.db.execute('select value from misc where name="update_date"') update_date = self.db.fetchall()[0][0] self.db.execute('select value from misc where name="update_time"') update_time = self.db.fetchall()[0][0] r = {} r['auth'] = {'login': self.sync_login, 'passw': self.sync_passw} r['db'] = self.sync_point out = [] n_dt = date2int(update_date, update_time) self.db.execute( 'select date,time,dep,article,sum,rate,name from income where myDate(date,time)>=?', (n_dt, )) for x in self.db.fetchall(): out.append(['income'] + list(x)) self.db.execute( 'select date,time,article,sum,name from outcome where myDate(date,time)>=?', (n_dt, )) for x in self.db.fetchall(): out.append(['outcome'] + list(x)) self.db.execute( 'select original_date,original_time,title from edit_log where myDate(date,time)>=?', (n_dt, )) for x in self.db.fetchall(): if x[2] == u'Отредактирована продажа': self.db.execute( 'select date,time,dep,article,sum,rate,name from income where date=? and time=?', (x[0], x[1])) try: out.append(['income'] + list(self.db.fetchall()[0])) except IndexError: pass elif x[2] == u'Отредактирован расход': self.db.execute( 'select date,time,article,sum,name from outcome where date=? and time=?', (x[0], x[1])) try: out.append(['outcome'] + list(self.db.fetchall()[0])) except IndexError: pass if x[2] == u'Удалена продажа': out.append(['del_income', x[0], x[1]]) if x[2] == u'Удален расход': out.append(['del_outcome', x[0], x[1]]) if len(out) == 0: return r['data'] = out d = {} d['data'] = json.dumps(r) self.db.execute('select value from misc where name="sync_server"') sync_server = self.db.fetchall()[0][0] response = urllib.urlopen(sync_server + '/sync', urllib.urlencode(d)).read() if response == '1': self.db.execute('update misc set value=? where name="update_date"', (date_now(), )) self.db.execute('update misc set value=? where name="update_time"', (time_now(), )) self.con.commit()