Beispiel #1
0
 def E_data(self):
     dbconn = self.dbconn
     form = self.form
     date_begin = form['date_begin']
     date_end = form['date_end']
     distrib_id = form['distrib_id']
     orders_tag = E.orders()
     data = E.data(orders_tag)
     limit = 100
     if distrib_id == --1:
         return E.data()
     ids = set(r[0] for r in dbconn.execute(
         'select * from(select * from (select order_id, status_order_id from porder join history_prod using(order_id) order by porder.order_id, history_prod.datetime desc) as c  group by order_id ) as d where status_order_id=9'
     ))
     query = dbconn.query(Order).filter(not_(Order.order_id.in_(ids)))
     if date_begin:
         limit = 0
         query = query.filter(Order.datetime >= date_begin)
     if date_end:
         limit = 0
         query = query.filter(Order.datetime <= date_end)
     if distrib_id:
         query = query.filter(Order.order_id == Prod_order.order_id).filter(
             Prod_order.product_id == Product.product_id).filter(
                 Product.distrib_id == distrib_id)
         for order in query:
             res = 0
             test = dbconn.query(
                 Prod_order.amount, Prod_order.count, Prod_order.close,
                 Prod_order.sale).filter(
                     Prod_order.order_id == order.order_id
                 ).filter(Prod_order.close == "no").filter(
                     Prod_order.product_id == Product.product_id).filter(
                         Product.distrib_id == distrib_id)
             for amount, count, close, sale in test:
                 res += float(amount) * float(count) - float(sale)
             order.amount = float(res)
     all_amount = 0
     query = query.order_by(desc(Order.datetime))
     if limit:
         query = query.limit(limit)
     count = 0
     for order in query:
         count += 1
         all_amount += float(order.amount)
         orders_tag.append(
             E.order(datetime=order.datetime.strftime('%Y-%m-%d'),
                     order_id=str(order.order_id),
                     amount=str(order.amount)))
     orders_tag.append(E.all_amount(str(all_amount)))
     if limit:
         str_limit = u"Выведены %s заказов" % str(limit)
     elif (date_begin or date_end or distrib_id):
         str_limit = u"Выведены все заказы"
     data.append(E.limit(limit=str_limit))
     data.append(E.count(str(count)))
     return data
Beispiel #2
0
    def E_data(self):
        colors = [
            'red', '#000080', '#006400', '#B22222', 'black', '#FF1493',
            '#CC00CC', '#8B0A50', '#660066', '#0033CC', '#666600', '#666666',
            'green', 'blue', '#000000', '#B22222', '#CC0099', '#663300',
            '#6633CC', '#663366', '#00FFFF', '#000080', '#006400', '#B22222',
            'black', '#8B0A50', '#660066', '#0033CC'
        ]
        get = self.req.POST
        f = get.get('csv')

        if f is not None:
            try:
                f = f.file
                content = f.read()
                #                content = content.read()
                tempfd, fname = tempfile.mkstemp(prefix='change',
                                                 suffix='.csv',
                                                 dir=htdocs_dir + '/csv/')
                temp = os.fdopen(tempfd, "w")
                temp.write(content)
                temp.close()
                del temp
                get['csv'] = fname
                xml = cStringIO.StringIO(content)
            except:
                xml = cStringIO.StringIO(get_xml())
        else:
            xml = cStringIO.StringIO(get_xml())
        get_params = E.gets(*[etree.Element(p, value=get.get(p)) for p in get])
        res = []
        for p in get:
            res.append(p + '=' + get.get(p))
        get_params.append(E.params('&'.join(res)))
        if xml is None:
            return E.data()
        reader = csv.reader(xml,
                            dialect='excel',
                            delimiter=str(','),
                            lineterminator='\r\n')
        test = iter(reader)
        params_name = reader.next()[2:]
        params = reader.next()[2:]
        params_name.append('количество заказов')
        params.append('_count_order')
        res = []
        for i in params:
            if i.startswith('_'):
                res.append((i, params_name[params.index(i)], params.index(i)))
        all_params = E.params(*[
            E.param(name=p[0],
                    color=colors[res.index(p)],
                    check=str(int(get.get(p[0]) is not None)),
                    count=str(res.index(p) + 1),
                    value=p[1].decode('utf-8')) for p in res
        ])
        return E.data(get_params, all_params)
Beispiel #3
0
 def E_data(self):
     dbconn = self.dbconn
     comment = dbconn.query(Comment.comment, Distrib_oper).filter(sqlalchemy.and_(Comment.order_id == self.form['order_id'], Comment.oper_id==Distrib_oper.oper_id))
     data = E.data()
     data_tag = data.xpath('//data')[0]
     for c, d in comment:
         data_tag.append(E.order(oper="%s %s" % (d.lastname, d.firstname), comment=c))
     return data
Beispiel #4
0
 def E_data(self):
     dbconn = self.dbconn
     history = dbconn.query(History.datetime, Status_order.name).filter(sqlalchemy.and_(History.order_id == self.form['order_id'], History.status_order_id == Status_order.status_order_id)).order_by(desc(History.datetime))
     data = E.data()
     data_tag = data.xpath('//data')[0]
     for date, status in history:
         data_tag.append(E.status(date=date.strftime('%Y-%m-%d %H:%M:%S'), status=status))
     return data
 def E_data(self):
     dbconn = self.dbconn
     return E.data(
         E.lines(*(E.line(name=l.name,
                          link=l.link,
                          color=l.color,
                          line_id=str(l.line_id))
                   for l in list(dbconn.query(Line)))))
 def E_data(self):
     dbconn = self.dbconn
     status = dbconn.query(Status_order)
     data = E.data()
     data_tag = data.xpath('//data')[0]
     for p in status:
         data_tag.append(
             E.status(status_id=str(p.status_order_id), name=p.name))
     return data
 def E_data(self):
     dbconn = self.dbconn
     delivery = dbconn.query(Price_delivery)
     data = E.data()
     data_tag = data.xpath('//data')[0]
     for p in delivery:
         data_tag.append(
             E.delivery(delivery_id=str(p.price_delivery_id),
                        name=p.name,
                        price=str(p.price)))
     return data
 def E_data(self):
     dbconn = self.dbconn
     status = dbconn.query(Banners)
     data = E.data()
     data_tag = data.xpath('//data')[0]
     for p in status:
         data_tag.append(
             E.banner(banner_id=str(p.banner_id),
                      name=p.name,
                      title=p.title,
                      alt=p.alt,
                      link=p.link,
                      mark=p.mark))
     return data
 def E_data(self):
     dbconn = self.dbconn
     distributor = dbconn.query(
         Distributor,
         Category).filter(Distributor.category_id == Category.category_id)
     data = E.data()
     data_tag = data.xpath('//data')[0]
     for p in distributor:
         data_tag.append(
             E.distributor(distrib_id=str(p[0].distrib_id),
                           category_name=p[1].name,
                           category_id=str(p[1].category_id),
                           discription=p[0].discription,
                           rate='%10.2f' % (p[0].rate)))
     return data
 def E_data(self):
     dbconn = self.dbconn
     delivery = dbconn.query(
         Delivery,
         Payment.name).filter(Delivery.payment_id == Payment.payment_id)
     data = E.data()
     data_tag = data.xpath('//data')[0]
     for p in delivery:
         data_tag.append(
             E.delivery(payment_id=str(p[0].payment_id),
                        delivery_id=str(p[0].delivery_id),
                        name=p[0].name,
                        note=p[0].note,
                        payment_name=p[1]))
     return data
 def E_data(self):
     dbconn = self.dbconn
     payment = dbconn.query(Payment)
     try:
         p = dbconn.query(Payment).filter(
             Payment.payment_id == self.form['payment_id']).one()
         text = p.text_email.replace('\n', " ").replace("'", '"')
     except sqlalchemy.orm.exc.NoResultFound:
         sys.exc_clear()
         text = u'Реквизиты'
     data = E.data(E.rich(), text=text)
     data_tag = data.xpath('//data')[0]
     for p in payment:
         data_tag.append(
             E.payment(payment_id=str(p.payment_id),
                       name=p.name,
                       sale_type=p.sale_type,
                       discription=p.discription))
     return data
 def E_data(self):
     dbconn = self.dbconn
     try:
         uri = dbconn.query(
             Sale.uid).filter(Sale.sale_id == self.form['new_id']).one()[0]
         f = open(htdocs_dir + '/pages/' + uri + '.html', 'r')
         text = f.read().replace('\n', " ").replace("'", '"')
         f.close()
     except sqlalchemy.orm.exc.NoResultFound:
         sys.exc_clear()
         text = 'Текст статьи'
     info = dbconn.query(Sale)
     data = E.data(E.rich(), text=text.decode('utf-8'), link=u'sale')
     data_tag = data.xpath('//data')[0]
     for p in info:
         data_tag.append(
             E.new(new_id=str(p.sale_id),
                   name=p.name,
                   uri=p.uid,
                   text=p.overview))
     return data
 def E_data(self):
     dbconn = self.dbconn
     try:
         uri = dbconn.query(Info_page.uri).filter(
             Info_page.info_page_id == self.form['info_page_id']).one()[0]
         f = open(htdocs_dir + '/pages/' + uri + '.html', 'r')
         text = f.read().replace('\n', " ").replace("'", '"')
         f.close()
         if not text:
             text = 'Текст статьи'
     except sqlalchemy.orm.exc.NoResultFound:
         sys.exc_clear()
         text = 'Текст статьи'
     info = dbconn.query(Info_page)
     data = E.data(text=text.decode('utf-8'))
     data_tag = data.xpath('//data')[0]
     for p in info:
         data_tag.append(
             E.info(info_page_id=str(p.info_page_id),
                    name=p.name,
                    uri=p.uri,
                    category_id=str(p.category_id),
                    weight=str(p.weight)))
     return data
Beispiel #14
0
 def E_data(self):
     return E.data(order_id=str(self.form['order_id']))
Beispiel #15
0
 def E_data(self):
     form = self.form
     order_id = form['order_id']
     where = []
     if order_id:
         where = 'porder.order_id=%s' % order_id
     if where:
         where_clause = 'where '+where
     dbconn = self.dbconn
     t = """
         select sql_calc_found_rows * from( select  * from (
             select porder.order_id as ord_id,
                 status_order.name as status,
                 status_order.status_order_id as st_id,
                 porder.datetime as dt,
                 datetime_distr, 
                 concat(username, ' ', sername, ' ', patronymic) as fio,
                 email,
                 address,
                 phones,
                 amount,
                 porder.note,
                 payment.name as pmt,
                 delivery.name as delivery,
                 porder.sale as sale
             from porder join history_prod using(order_id) join status_order using(status_order_id) join delivery using(delivery_id) join payment on payment.payment_id=porder.payment_id
             %s
             order by porder.order_id, history_prod.datetime desc)
         as k  group by ord_id order by ord_id desc) as p; 
     """ % (where_clause,)
     order_status = dbconn.execute(t)
     orders = []
     for ord_id , sts, st_id, dt, dt_distr, fio, email, address, phones, amount, note, pmt, delivery, sale in order_status: 
         prods = dbconn.query(Prod_order).filter(Prod_order.order_id==ord_id)
         sale_str = u"нет"
         for pr in prods:
             if pr.sale:
                 sale_str = u"есть"
         css = 'green'
         orders.append(E.order(
             E.ord_id(str(ord_id)),
             E.status(sts),
             E.stid(str(st_id)),
             E.dt(dt.strftime('%Y-%m-%d')),
             E.dt_distr(dt_distr.strftime('%Y-%m-%d %H:%M'), css=css),
             E.fio(fio),
             E.email(email),
             E.address(address),
             E.phones(phones),
             E.amount('%10.2f' % (amount*(1-sale/100))),
             E.note(note),
             E.pmt(pmt),
             E.delivery(delivery),
             E.sale(sale_str),
             E.prods(*(E.prod(name=p.product_name, count=str(p.count), amount=str(p.amount), close=p.close) for p in prods)),
             #dbconn.query(Prod_order).filter(Prod_order.order_id==ord_id))),
             E.comments(*(E.comment(c.comment, name=d.firstname) for c,d in dbconn.query(Comment, Distrib_oper).filter(Comment.order_id==ord_id).filter(Comment.oper_id==Distrib_oper.oper_id).order_by(Comment.comment_order_id))),
             E.history(*(E.st(dt=h.datetime.strftime('%Y-%m-%d %H:%M:%S'), name=s.name, oper=op.firstname) for h,s, op in dbconn.query(History, Status_order, Distrib_oper).filter(
                 History.order_id==ord_id).filter(Status_order.status_order_id==History.status_order_id).filter(Distrib_oper.oper_id==History.oper_id).order_by(desc(History.datetime)) )),
         ))
     return E.data(*orders) 
Beispiel #16
0
    def E_data(self):
        form = self.form
        limit=form['limit']
        offset=form['offset']
        date_b = form['date_b']
        date_e = form['date_e']
        date_distr = form['date_distr']
        sess = self.req.environ['rrduet.sess']
        oper_id = sess['oper_id']
#        if date_distr == '' and oper_id==1:
#            date_distr = datetime.datetime.now().strftime('%Y-%m-%d')
        date_now = datetime.datetime.now().strftime('%Y-%m-%d')
        status = form['status']
        order_id = form['order_id']
        where = []
        if date_b !='':
            where.append('porder.datetime>="%s"' % date_b)
        if date_e != '':
            where.append('porder.datetime<="%s"' % date_e)
        if date_distr != '':
            where.append('porder.datetime_distr>="%s 0:0:0" and porder.datetime_distr<="%s 23:59:59"' % (date_distr, date_distr))
        if order_id:
            where = ['porder.order_id=%s' % order_id]
        if where:
            where_clause = 'where '+' and '.join(where)
        if where:
            where_clause = 'where '+' and '.join(where)
        else:
            where_clause = ''
        if status:
            st_where = 'where st_id=%s' % (status,)
        else:
            st_where = ''
        dbconn = self.dbconn
        t = """
            select sql_calc_found_rows * from( select  * from (
                select porder.order_id as ord_id,
                    status_order.name as status,
                    status_order.status_order_id as st_id,
                    porder.datetime as dt,
                    datetime_distr, 
                    concat(username, ' ', sername, ' ', patronymic) as fio,
                    email,
                    address,
                    phones,
                    amount,
                    porder.note,
                    payment.name as pmt,
                    delivery.name as delivery,
                    porder.sale as sale
                from porder join history_prod using(order_id) join status_order using(status_order_id) join delivery using(delivery_id) join payment on payment.payment_id=porder.payment_id
                %s
                order by porder.order_id, history_prod.datetime desc)
            as k  group by ord_id order by ord_id desc) as p %s limit %s offset %s; 
        """ % (where_clause, st_where, limit, offset,)
        order_status = dbconn.execute(t)
        count = list(dbconn.execute("select found_rows()"))[0][0]
        next = prev = ''
        if count>offset+limit:
            next = str(offset+limit) 
        if offset > 0:
            prev = str(offset-limit)
        orders= []
        for ord_id , sts, st_id, dt, dt_distr, fio, email, address, phones, amount, note, pmt, delivery, sale in order_status: 
            prods = dbconn.query(Prod_order).filter(Prod_order.order_id==ord_id)
            sale_str = u"нет"
            for pr in prods:
                if pr.sale:
                    sale_str = u"есть"
            css = 'green'
            if date_now == dt_distr.strftime('%Y-%m-%d'):
                css = 'red'
            orders.append(E.order(
                E.ord_id(str(ord_id)),
                E.status(sts),
                E.stid(str(st_id)),
                E.dt(dt.strftime('%Y-%m-%d')),
                E.dt_distr(dt_distr.strftime('%Y-%m-%d %H:%M'), css=css),
                E.fio(fio),
                E.email(email),
                E.address(address),
                E.phones(phones),
                E.amount('%10.2f' % (amount*(1-sale/100))),
                E.note(note),
                E.pmt(pmt),
                E.delivery(delivery),
                E.sale(sale_str),
                E.prods(*(E.prod(name=p.product_name, count=str(p.count), amount=str(p.amount), close=p.close) for p in prods)),
                #dbconn.query(Prod_order).filter(Prod_order.order_id==ord_id))),
                E.comments(*(E.comment(c.comment, name=d.firstname) for c,d in dbconn.query(Comment, Distrib_oper).filter(Comment.order_id==ord_id).filter(Comment.oper_id==Distrib_oper.oper_id).order_by(Comment.comment_order_id))),
                E.history(*(E.st(dt=h.datetime.strftime('%Y-%m-%d %H:%M:%S'), name=s.name, oper=op.firstname) for h,s, op in dbconn.query(History, Status_order, Distrib_oper).filter(
                    History.order_id==ord_id).filter(Status_order.status_order_id==History.status_order_id).filter(Distrib_oper.oper_id==History.oper_id).order_by(desc(History.datetime)) )),
            ))
        return E.data(*orders, offset=str(offset), next=next, prev=prev,date_b=date_b, date_e=str(date_e), status=str(status))