示例#1
0
    def ver_ventas_no_efectivos():
        start, end = parse_start_end_date(request.query)
        end += datetime.timedelta(hours=23)
        sales = dbapi.db_session.query(NNota).filter(
            NNota.timestamp >= start).filter(NNota.timestamp <= end).filter(
            NNota.payment_format != PaymentFormat.CASH)

        sales = map(InvMetadata.from_db_instance, sales)
        payments = list(paymentapi.list_payments(start, end))

        result = {}
        for x in sales:
            if x.client.codigo not in result:
                result[x.client.codigo] = {}
                result[x.client.codigo]['sales'] = []
                result[x.client.codigo]['payments'] = []
            result[x.client.codigo]['sales'].append(x)

        unused_payments = []
        for x in payments:
            if x.client_id in result:
                result[x.client_id]['payments'].append(x)
            else:
                unused_payments.append(x)

        result['unused_payments'] = unused_payments
        return json_dumps({
            'unused_payments': unused_payments,
            'sales': result.items()
        })
示例#2
0
    def get_sells_xml():
        start_date, end_date = parse_start_end_date(request.query)
        end_date = end_date + datetime.timedelta(days=1) - datetime.timedelta(
            seconds=1)
        form_type = request.query.get('form_type')

        ruc = request.query.get('alm')
        invs = invapi.search_metadata_by_date_range(
            start_date, end_date, other_filters={'almacen_ruc': ruc})

        deleted, sold = split_records_binary(
            invs, lambda x: x.status == Status.DELETED)
        grouped = group_by_customer(sold)

        meta = Meta()
        meta.date = start_date
        meta.total = reduce(lambda acc, x: acc + x.subtotal, grouped.values(),
                            0)
        meta.almacen_ruc = ruc
        meta.almacen_name = [
            x.nombre for x in dbapi.search(Store) if x.ruc == ruc
        ][0]
        temp = jinja_env.get_template('accounting/resumen_agrupado.html')
        if form_type == 'ats':
            temp = jinja_env.get_template('accounting/ats.xml')
            response.set_header('Content-disposition', 'attachment')
            response.set_header('Content-type', 'application/xml')
        return temp.render(vendidos=grouped, eliminados=deleted, meta=meta)
示例#3
0
    def get_resumen_viejo():
        user = request.query.get('user')
        store = request.query.get('almacen_id')
        start, end = parse_start_end_date(request.query)

        if user is None or store is None:
            abort(400, 'Escoje usuario y almacen')
        if start is None or end is None:
            abort(400, 'Hay que ingresar las fechas')

        store = int(store)
        result = get_notas_with_clients(dbapi.session, end, start, store)

        by_status = split_records(result, lambda x: x.status)
        deleted = by_status[Status.DELETED]
        committed = by_status[Status.COMITTED]
        ventas = split_records(committed, lambda x: x.payment_format)

        gtotal = sum((x.total for x in committed))
        temp = jinja_env.get_template('invoice/resumen.html')
        return temp.render(
            start=start,
            end=end,
            user=user,
            store=dbapi.search(Store),
            ventas=ventas,
            gtotal=gtotal,
            eliminados=deleted)
示例#4
0
    def get_resumen_viejo():
        user = request.query.get('user')
        store = request.query.get('almacen_id')
        start, end = parse_start_end_date(request.query)

        if user is None or store is None:
            abort(400, 'Escoje usuario y almacen')
        if start is None or end is None:
            abort(400, 'Hay que ingresar las fechas')

        store = int(store)
        result = get_notas_with_clients(dbapi.session, end, start, store)

        by_status = split_records(result, lambda x: x.status)
        deleted = by_status[Status.DELETED]
        committed = by_status[Status.COMITTED]
        ventas = split_records(committed, lambda x: x.payment_format)

        gtotal = sum((x.total for x in committed))
        temp = jinja_env.get_template('invoice/resumen.html')
        return temp.render(start=start,
                           end=end,
                           user=user,
                           store=dbapi.search(Store),
                           ventas=ventas,
                           gtotal=gtotal,
                           eliminados=deleted)
示例#5
0
    def ver_ventas_no_efectivos():
        start, end = parse_start_end_date(request.query)
        end += datetime.timedelta(hours=23)
        sales = dbapi.db_session.query(NNota).filter(
            NNota.timestamp >= start).filter(NNota.timestamp <= end).filter(
                NNota.payment_format != PaymentFormat.CASH)

        sales = map(InvMetadata.from_db_instance, sales)
        payments = list(paymentapi.list_payments(start, end))

        result = {}
        for x in sales:
            if x.client.codigo not in result:
                result[x.client.codigo] = {}
                result[x.client.codigo]['sales'] = []
                result[x.client.codigo]['payments'] = []
            result[x.client.codigo]['sales'].append(x)

        unused_payments = []
        for x in payments:
            if x.client_id in result:
                result[x.client_id]['payments'].append(x)
            else:
                unused_payments.append(x)

        result['unused_payments'] = unused_payments
        return json_dumps({
            'unused_payments': unused_payments,
            'sales': result.items()
        })
示例#6
0
 def get_account_transactions_mult_days():
     start, end = parse_start_end_date(request.query)
     # FIXME: remove this hack
     if override_transaction_getter:
         result = override_transaction_getter(start, end)
     else:
         result = get_transactions(dbapi, paymentapi, invapi, imgserver, start, end)
     return json_dumps(result)
示例#7
0
    def ver_entrega_de_cuenta_list():
        start, end = parse_start_end_date(request.query)
        if end is None:
            end = datetime.date.today()
        if start is None:
            start = datetime.date.today() - datetime.timedelta(days=7)

        accts = dbapi.db_session.query(NAccountStat).filter(
            NAccountStat.date >= start, NAccountStat.date <= end)
        temp = jinja_env.get_template('invoice/entrega_de_cuenta_list.html')
        return temp.render(accts=accts, start=start, end=end)
示例#8
0
    def ver_entrega_de_cuenta_list():
        start, end = parse_start_end_date(request.query)
        if end is None:
            end = datetime.date.today()
        if start is None:
            start = datetime.date.today() - datetime.timedelta(days=7)

        accts = dbapi.db_session.query(NAccountStat).filter(
            NAccountStat.date >= start, NAccountStat.date <= end)
        temp = jinja_env.get_template('invoice/entrega_de_cuenta_list.html')
        return temp.render(accts=accts, start=start, end=end)
示例#9
0
 def get_trans_by_date():
     start, end = parse_start_end_date(
         request.query, start_name='start_date', end_name='end_date')
     status = request.query.get('status')
     other_filters = {}
     for x in ('origin', 'dest'):
         t = request.query.get(x)
         if t:
             other_filters[x] = t
     result = transapi.search_metadata_by_date_range(
         start, end, status, other_filters)
     return json_dumps(list(result))
示例#10
0
 def get_trans_by_date():
     start, end = parse_start_end_date(request.query,
                                       start_name='start_date',
                                       end_name='end_date')
     status = request.query.get('status')
     other_filters = {}
     for x in ('origin', 'dest'):
         t = request.query.get(x)
         if t:
             other_filters[x] = t
     result = transapi.search_metadata_by_date_range(
         start, end, status, other_filters)
     return json_dumps(list(result))
示例#11
0
    def list_revision():
        start, end = parse_start_end_date(request.query)
        if end is None:
            end = datetime.datetime.now()
        if start is None:
            start = end - datetime.timedelta(days=7)

        revisions = dbapi.db_session.query(NInventoryRevision).filter(
            NInventoryRevision.timestamp <= end,
            NInventoryRevision.timestamp >= start)

        temp = jinja_env.get_template('inventory/list_revisions.html')
        return temp.render(revisions=revisions, start=start, end=end)
示例#12
0
 def list_ingress():
     start, end = parse_start_end_date(request.query)
     if not end:
         end = datetime.datetime.now()
     else:
         end = end + datetime.timedelta(days=1) - datetime.timedelta(seconds=1)
     if not start:
         start = end - datetime.timedelta(days=7)
     trans_list = transapi.search_metadata_by_date_range(start, end)
     temp = jinja_env.get_template('inventory/ingresos_list.html')
     bodega = {b.id: b.nombre for b in dbapi.search(Bodega)}
     print start, end
     return temp.render(trans=trans_list, start=start, end=end, bodega=bodega)
示例#13
0
 def list_facturas():
     start, end = parse_start_end_date(request.query)
     if not start:
         start = datetime.datetime.today() - datetime.timedelta(days=1)
     if not end:
         end = datetime.datetime.today()
     alm = request.query.almacen_id
     query = dbapi.db_session.query(NNota).filter(
         NNota.timestamp >= start, NNota.timestamp < end)
     if alm:
         query = query.filter_by(almacen_id=alm)
     temp = jinja_env.get_template('invoice/list_facturas.html')
     return temp.render(notas=query, start=start, end=end,
                        almacenes=dbapi.search(Store))
示例#14
0
 def get_sales():
     """ start=<start>&end=<end>
     """
     start_date, end_date = parse_start_end_date(request.query)
     if not end_date:
         end_date = datetime.date.today()
     end_date = end_date + datetime.timedelta(hours=23)
     query = dbapi.db_session.query(NNota.almacen_id, func.sum(
         NNota.total)).filter(NNota.timestamp >= start_date).filter(
             NNota.timestamp <= end_date).filter(
                 NNota.status != Status.DELETED).group_by(NNota.almacen_id)
     result = []
     for aid, total in query:
         result.append((aid, Decimal(total) / 100))
     return json_dumps({'result': result})
示例#15
0
 def get_sales():
     """ start=<start>&end=<end>
     """
     start_date, end_date = parse_start_end_date(request.query)
     if not end_date:
         end_date = datetime.date.today()
     end_date = end_date + datetime.timedelta(hours=23)
     query = dbapi.db_session.query(
         NNota.almacen_id, func.sum(NNota.total)).filter(
         NNota.timestamp >= start_date).filter(
         NNota.timestamp <= end_date).filter(
         NNota.status != Status.DELETED).group_by(NNota.almacen_id)
     result = []
     for aid, total in query:
         result.append((aid, Decimal(total) / 100))
     return json_dumps({'result': result})
示例#16
0
 def list_facturas():
     start, end = parse_start_end_date(request.query)
     if not start:
         start = datetime.datetime.today() - datetime.timedelta(days=1)
     if not end:
         end = datetime.datetime.today()
     alm = request.query.almacen_id
     query = dbapi.db_session.query(NNota).filter(NNota.timestamp >= start,
                                                  NNota.timestamp < end)
     if alm:
         query = query.filter_by(almacen_id=alm)
     temp = jinja_env.get_template('invoice/list_facturas.html')
     return temp.render(notas=query,
                        start=start,
                        end=end,
                        almacenes=dbapi.search(Store))
示例#17
0
def all_daily_stats():
    start, end = parse_start_end_date(request.query)
    if end is None:
        end = datetime.date.today()
    if start is None:
        start = end - datetime.timedelta(days=7)

    result = {}
    for x in timerange(start, end):
        if x.isoweekday() != 7:  # skips Sundays
            report = invmanager.get(x)
            if report is not None:
                result[x.isoformat()] = (report.total_count, report.total_value, report.total_tax)
            else:
                result[x.isoformat()] = None
    return result
示例#18
0
def all_daily_stats():
    start, end = parse_start_end_date(request.query)
    if end is None:
        end = datetime.date.today()
    if start is None:
        start = end - datetime.timedelta(days=7)

    result = {}
    for x in timerange(start, end):
        if x.isoweekday() != 7:  # skips Sundays
            report = invmanager.get(x)
            if report is not None:
                result[x.isoformat()] = (report.total_count,
                                         report.total_value, report.total_tax)
            else:
                result[x.isoformat()] = None
    return result
示例#19
0
 def list_ingress():
     start, end = parse_start_end_date(request.query)
     if not end:
         end = datetime.datetime.now()
     else:
         end = end + datetime.timedelta(days=1) - datetime.timedelta(
             seconds=1)
     if not start:
         start = end - datetime.timedelta(days=7)
     trans_list = transapi.search_metadata_by_date_range(start, end)
     temp = jinja_env.get_template('inventory/ingresos_list.html')
     bodega = {b.id: b.nombre for b in dbapi.search(Bodega)}
     print start, end
     return temp.render(trans=trans_list,
                        start=start,
                        end=end,
                        bodega=bodega)
示例#20
0
def vendidos_por_categoria():
    cat = request.query.categoria_id
    start, end = parse_start_end_date(request.query)
    prods = sessionmanager.session.query(
        NProducto.codigo).filter_by(categoria_id=cat)
    all_codigos = {p.codigo for p in prods}
    all_items = []
    total = 0
    for inv, x in full_invoice_items(invapi, start, end):
        if x.prod.prod_id in all_codigos:
            x.prod.precio = (x.prod.precio1 if x.cant >= x.prod.cant_mayorista
                             else x.prod.precio2)
            x.subtotal = x.prod.precio * x.cant
            total += x.subtotal
            all_items.append((inv, x))
    temp = jinja_env.get_template('ver_vendidos.html')
    return temp.render(items=all_items, total=total)
示例#21
0
 def vendidos_por_categoria():
     cat = request.query.categoria_id
     start, end = parse_start_end_date(request.query)
     prods = dbapi.db_session.query(NProducto.codigo).filter_by(
         categoria_id=cat)
     all_codigos = {p.codigo for p in prods}
     all_items = []
     total = 0
     for inv, x in full_invoice_items(invapi, start, end):
         if x.prod.prod_id in all_codigos:
             x.prod.precio = (x.prod.precio1 if x.cant >= x.prod.cant_mayorista
                              else x.prod.precio2)
             x.subtotal = x.prod.precio * x.cant
             total += x.subtotal
             all_items.append((inv, x))
     temp = jinja_env.get_template('ver_vendidos.html')
     return temp.render(items=all_items, total=total)
示例#22
0
    def get_resumen():
        user = request.query.get('user')
        store = request.query.get('almacen_id')
        start, end = parse_start_end_date(request.query)

        if user is None or store is None:
            abort(400, 'Escoje usuario y almacen')
        if start is None or end is None:
            abort(400, 'Hay que ingresar las fechas')

        store = int(store)
        report = payment_report(dbapi, end, start, store)

        temp = jinja_env.get_template('invoice/resumen_nuevo.html')
        return temp.render(start=start,
                           end=end,
                           user=user,
                           store=dbapi.search(Store),
                           report=report)
示例#23
0
    def get_resumen():
        user = request.query.get('user')
        store = request.query.get('almacen_id')
        start, end = parse_start_end_date(request.query)

        if user is None or store is None:
            abort(400, 'Escoje usuario y almacen')
        if start is None or end is None:
            abort(400, 'Hay que ingresar las fechas')

        store = int(store)
        report = payment_report(dbapi, end, start, store)

        temp = jinja_env.get_template('invoice/resumen_nuevo.html')
        return temp.render(
            start=start,
            end=end,
            user=user,
            store=dbapi.search(Store),
            report=report)
示例#24
0
    def get_sells_xml():
        start_date, end_date = parse_start_end_date(request.query)
        end_date = end_date + datetime.timedelta(days=1) - datetime.timedelta(seconds=1)
        form_type = request.query.get('form_type')

        ruc = request.query.get('alm')
        invs = invapi.search_metadata_by_date_range(
            start_date, end_date, other_filters={'almacen_ruc': ruc})

        deleted, sold = split_records_binary(invs, lambda x: x.status == Status.DELETED)
        grouped = group_by_customer(sold)

        meta = Meta()
        meta.date = start_date
        meta.total = reduce(lambda acc, x: acc + x.subtotal, grouped.values(), 0)
        meta.almacen_ruc = ruc
        meta.almacen_name = [x.nombre for x in dbapi.search(Store) if x.ruc == ruc][0]
        temp = jinja_env.get_template('accounting/resumen_agrupado.html')
        if form_type == 'ats':
            temp = jinja_env.get_template('accounting/ats.xml')
            response.set_header('Content-disposition', 'attachment')
            response.set_header('Content-type', 'application/xml')
        return temp.render(vendidos=grouped, eliminados=deleted, meta=meta)
示例#25
0
 def get_all_payments():
     start, end = parse_start_end_date(request.query)
     result = list(paymentapi.list_payments(start, end))
     return json_dumps({'result': result})
示例#26
0
 def get_all_payments():
     start, end = parse_start_end_date(request.query)
     result = list(paymentapi.list_payments(start, end))
     return json_dumps({'result': result})
示例#27
0
 def get_account_transactions_mult_days():
     start, end = parse_start_end_date(request.query)
     result = get_transactions(dbapi, paymentapi, invapi, imgserver, start,
                               end)
     return json_dumps(result)
示例#28
0
 def get_account_transactions_mult_days():
     start, end = parse_start_end_date(request.query)
     result = get_transactions(dbapi, paymentapi, invapi, imgserver, start, end)
     return json_dumps(result)
示例#29
0
 def get_sales_report():
     start, end = parse_start_end_date(request.query)
     sales_by_date = list(client_sale_report(dbapi, start, end))
     return json_dumps({'result': sales_by_date})
示例#30
0
 def sale_report_monthly():
     start, end = parse_start_end_date(request.query)
     report = get_sale_report(invapi, start, end)
     report.best_sellers = sorted(report.best_sellers, key=lambda x: x[1].value, reverse=True)
     temp = jinja_env.get_template('sale_report_monthly.html')
     return temp.render(report=report)
示例#31
0
 def sale_report_monthly():
     start, end = parse_start_end_date(request.query)
     report = get_sale_report(invapi, start, end)
     return json_dumps(report)
示例#32
0
 def get_sales():
     start, end = parse_start_end_date(request.query)
     result = list(get_sales_by_date_and_user(dbapi, start, end))
     return json_dumps(result)
示例#33
0
 def get_transactions_of_item_group(uid):
     start, end = parse_start_end_date(request.query)
     start = start.date()
     end = end.date()
     return json_dumps({"results": list(inventoryapi.list_transactions(uid, start, end))})