def list(self, id=None): company_name = request.params.get('company_name', '') number = request.params.get('number', '') date_from = request.params.get('invoiceDateFrom', h.today(30)) date_to = request.params.get('invoiceDateTo', h.today()) query = InvoiceCorrect.query if company_name: query = query.filter(Company.shortName.like('%' + company_name + '%') ) query = query.filter(InvoiceCorrect.created_at.between(date_from, date_to) ) query = query.filter(InvoiceCorrect.number.like('%' + number + '%') ) if id: query = InvoiceCorrect.query.filter(InvoiceCorrect.invoice_id == id) records = query.order_by(InvoiceCorrect.created_at.desc(), InvoiceCorrect.series_number.desc()) c.paginator = paginate.Page( records, page=int(request.GET.pop('page', 1)), items_per_page = int(request.GET.pop('page_size', 30)), **dict(request.GET) ) if 'partial' in request.params: return render('/corrects/list-partial.xhtml') else: return render('/corrects/list.xhtml')
def add(self, id): order = Order.query.get_or_abort(id) c.invoices = Invoice.query.filter_by(idCompany=order.idCompany, isBooked=0).all() c.form = NewInvoiceForm(request.POST) if request.method == "POST" and c.form.validate(): invoice = Invoice() element = InvoicePosition() invoice.series_year = c.form.year.data invoice.series_month = c.form.months.data invoice.issueDate = h.today() invoice.idCompany = order.idCompany invoice.tax = order.company.tax invoice.save() element.order_id = order.id element.invoice_id = invoice.id element.value = order.freight element.currency_id = order.currency.id element.tax = order.company.tax element.save() flash(u"Faktura pomyślnie dodana.") return self.redirect(url(controller="invoices", action="edit", id=invoice.id)) return render("/invoices/add.xhtml")
def month_balance(self, id): orders = meta.Session.query(func.month(Order.created_at).label('month'), func.day(Order.created_at).label('day'), func.sum(Order.real_value - TransportOrder.real_value).label('value')) \ .join(Order.transport_order) \ .group_by( func.month(Order.created_at), func.day(Order.created_at)) \ .filter(and_(Order.idCreator == id, Order.created_at.between(h.today(31), h.today()))) \ .all() chart = open_flash_chart() t = title(text='Zestawienie') b = bar() b.values = [order.value for order in orders] lbl = labels(labels = [str(order.month) + ' ' + str(order.day) for order in orders]) x = x_axis() x.labels = lbl y = y_axis() y.min, y.max= 0, max(b.values or [0]) chart.title = t chart.y_axis = y chart.x_axis = x chart.add_element(b) return chart.render()
def company_balance(self, id): orders = meta.Session.query(func.year(Order.created_at).label('year'), func.month(Order.created_at).label('month'), func.sum(Order.real_value).label('value')) \ .join(Order.transport_order) \ .filter(and_(Order.idCompany == id, Order.created_at.between(h.today(365), h.today()))) \ .group_by( func.year(Order.created_at), func.month(Order.created_at)) \ .all() profits = meta.Session.query(func.year(Order.created_at).label('year'), func.month(Order.created_at).label('month'), func.sum(Order.real_value - TransportOrder.real_value).label('value')) \ .join(Order.transport_order) \ .filter(and_(Order.idCompany == id, Order.created_at.between(h.today(365), h.today()))) \ .group_by( func.year(Order.created_at), func.month(Order.created_at)) \ .all() chart = open_flash_chart() t = title(text='Zestawienie') b = bar() b.values = [order.value for order in orders] b2 = bar() b2.values = [order.value for order in profits] b2.colour = '#56acde' lbl = labels(labels = [str(order.year) + ' ' + str(order.month) for order in orders]) x = x_axis() x.labels = lbl y = y_axis() y.min, y.max= 0, max(b.values or [0]) y.labels = None y.offset = False chart.title = t chart.y_axis = y chart.x_axis = x chart.add_element(b) chart.add_element(b2) return chart.render()
def list(self): company_name = request.params.get("company_name", "") number = request.params.get("number", "") is_booked = request.params.get("is_booked", "") date_from = request.params.get("invoiceDateFrom", h.today(30)) date_to = request.params.get("invoiceDateTo", h.today()) query = Invoice.query.join(Invoice.company).options(eagerload("company"), eagerload("elements")) if company_name != "": query = query.filter(Company.shortName.like(u"%" + company_name + u"%")) if is_booked: query = query.filter(Invoice.isBooked == is_booked) query = query.filter(Invoice.created_at.between(date_from, date_to)) query = query.filter(Invoice.number.like(u"%" + number + u"%")) records = query.order_by(Invoice.created_at.desc(), Invoice.series_number.desc()) invoice = Invoice() c.actions = invoice.get_action_choices(request) if request.method == "POST": response = invoice.response_action(request, Invoice.query) if response is not None: return response c.months = h.months_list() c.year = str(datetime.datetime.now().year) c.paginator = paginate.Page( records, page=int(request.GET.pop("page", 1)), items_per_page=int(request.GET.pop("page_size", 30)), **dict(request.GET) ) if "partial" in request.params: return render("/invoices/list-partial.xhtml") else: return render("/invoices/list.xhtml")
def list(self): c.user = meta.Session.query(User.id, User.last_name + u' ' + User.first_name).all() company_name = request.params.get('company_name', '') number = request.params.get('number', '') is_factured = request.params.get('is_factured', '') numberTransportOrder = request.params.get('numberTransportOrder', '') date_from = request.params.get('orderDateFrom', h.today(30)) date_to = request.params.get('orderDateTo', h.today()) idCreator = request.params.get('idCreator', '') records = Order.query.options(eagerload('places'), eagerload('transport_order')) if company_name: records = records.join(Company, aliased=True).filter(Company.shortName.like('%' + company_name + '%') ) if numberTransportOrder: records = records.join(Order.transport_order).join(TransportOrder.company, aliased=True).filter(and_(Company.shortName.like('%' + numberTransportOrder + '%'))) if is_factured: records = records.filter(Order.isFactured == is_factured) if idCreator: records = records.filter(Order.idCreator == idCreator) if number: records = records.filter(Order.number.like('%' + number + '%') ) records = records.filter(Order.created_at.between(date_from, date_to) ).order_by(desc(Order.id)) c.paginator = paginate.Page( records, page=int(request.GET.pop('page', 1)), items_per_page = int(request.GET.pop('page_size', 30)), **dict(request.GET) ) if 'partial' in request.params: return render('/orders/list-partial.xhtml') else: return render('/orders/list.xhtml')
def add(self, id): c.invoice = Invoice.query.get(id) c.form = InvoiceCorrectForm(request.POST, correct_date = h.today(), sell_date = c.invoice.sellDate, company=c.invoice.company.name, payment_form=c.invoice.company.payment, payment_date=c.invoice.payment_date, positions=c.invoice.elements) for index, position in enumerate(c.form.positions): position.tax.value = c.invoice.elements[index].tax.id if request.method == 'POST' and c.form.validate(): correct = InvoiceCorrect() correct.company = c.invoice.company correct.currency = c.invoice.elements[0].currency correct.invoice = c.invoice correct.series_year = str(datetime.datetime.now().year) correct.series_month = str(datetime.datetime.now().month) correct.currency_symbol = c.invoice.currencySymbol correct.currency_date = c.invoice.currencyDate correct.currency_value = c.invoice.currencyValue correct.currency_table_number = c.invoice.currencyTableNumber c.form.populate_obj(correct, exclude = ['id', 'company', 'number', 'positions']) for form_position in c.form.positions: position = InvoicePositionCorrect() form_position.form.populate_obj(position, exclude=['id']) correct.positions.append(position) correct.save() flash(u'Korekta pomyślnie dodana.') return self.redirect(url(controller='corrects', action='edit', id=correct.id)) return render('/corrects/add.xhtml')
def edit(self, id): c.order = Order.query.get_or_abort(id) c.form = OrderForm(request.POST, obj=c.order, prefix='order') c.places_form = OrderPlaceForm(request.POST) c.transport_form = TransportOrderForm(request.POST, obj=c.order.transport_order, prefix='transport-order') c.place_form = PlaceForm(request.POST, idCompany=c.order.idCompany) if c.order.delegation is None: #c.drivers = [(driver.id, driver.full_name) for driver in Driver.query.filter(Driver.is_active == True).all()] c.drivers = [(driver.id, driver.full_name) for driver in Driver.query.filter(Driver.is_active == True).all()] c.delegation_form = DelegationForm(request.POST, prefix='delegation') if request.method == 'POST': if request.POST['action'] == 'Save' and c.form.validate(): c.order.idCompany = c.form.idCompany.data c.order.freight = c.form.freight.data c.order.currency = c.form.currency.data c.order.description = c.form.description.data c.order.isCurrencyDate = c.form.isCurrencyDate.data c.order.foreignOrder = c.form.foreignOrder.data c.order.save() flash(u'Zlecenie pomyślnie edytowane.') self.redirect(url(controller='orders', action='edit', id=c.order.id)) return if request.POST['action'] == 'Add Place': if c.places_form.validate(): place_order = PlaceOrder() place_order.idOrder = c.order.id place_order.type = c.places_form.idType.data place_order.idPlace = c.places_form.idPlace.data place_order.date = c.places_form.placeDate.data place_order.name = 'PyTiS' place_order.save() return render_macro('/base/macros.xhtml', 'show_places', form=OrderPlaceForm(), places=c.order.places) else: return render_macro('/base/macros.xhtml', 'show_places', form=c.places_form, places=c.order.places) if request.POST['action'] == 'Save TO': if c.transport_form.validate(): if not c.transport_form.id.data: transport_order = TransportOrder() else: transport_order = TransportOrder.query.get(c.transport_form.id.data) transport_order.idOrder = c.order.id transport_order.idCompany = c.transport_form.idCompany.data transport_order.currency = c.transport_form.currency.data transport_order.driverName = c.transport_form.driverName.data transport_order.tractorName = c.transport_form.tractorName.data transport_order.freight = c.transport_form.freight.data transport_order.description = c.transport_form.description.data transport_order.save() c.transport_form.id.data = transport_order.id c.transport_form.number.data = transport_order.number return render_macro('/base/macros.xhtml', 'show_transport_order', order=c.order, form=c.transport_form) else: return render_macro('/base/macros.xhtml', 'show_transport_order', order=c.order, form=c.transport_form) if request.POST['action'] == 'Create Place': if c.place_form.validate(): place = Place() c.place_form.populate_obj(place) place.idCompany = c.order.company.id place.save() return render_macro('/base/macros.xhtml', 'new_place', form=PlaceForm()) else: return render_macro('/base/macros.xhtml', 'new_place', form=c.place_form) if request.POST['action'] == 'Add Delegation': if c.delegation_form.validate(): delegation = Delegation() c.delegation_form.populate_obj(delegation) delegation.series_year = h.today().year delegation.series_month = h.today().month delegation.save() c.order.delegation = delegation c.order.save() return render_macro('/base/macros.xhtml', 'show_delegation') else: return render_macro('/base/macros.xhtml', 'new_delegation') if c.order.isFactured: c.invoice = InvoicePosition.query.filter_by(order_id = c.order.id).first() return render('/orders/edit.xhtml')