def invoice(self): hash = self.request.matchdict['hash'] invoice = Invoices.load(hash=hash) records = invoice.get_records_raw() self.set('invoice', invoice) self.set('records', records) return self.response
def manage_order(self): id = int(self.request.matchdict['id']) if 'invoice.submit' in self.request.params: invoice = Invoices.load(id=id) invoice.fullname = self.request.params.get('invoice.fullname','') invoice.email = self.request.params.get('invoice.email','') invoice.phone = self.request.params.get('invoice.phone','') invoice.address = self.request.params.get('invoice.address','') invoice.county_state_zip = self.request.params.get('invoice.county_state_zip','') invoice.status = int(self.request.params.get('invoice.status',1)) invoice.deliver_digitally = Validators.bool(self.request.params.get('invoice.deliver_digitally',0)) invoice.deliver_physically = Validators.bool(self.request.params.get('invoice.deliver_physically',0)) final_status = Statuses.load(order='priority desc') if final_status.id == invoice.status: invoice.completed = True if Validators.bool(self.request.params.get('invoice.status.emailer',0)): status = Statuses.load(id=invoice.status) orders_data = invoice.get_records_raw() archive = Archives.load(id=orders_data[0]['location']) Emailer.send(self.request, [invoice.email], status.email_subject, status.email_message, signature=archive.email_signature, link=self.request.application_url + '/invoice/' + invoice.hash ) invoice = Invoices.load(id=id) self.set('invoice',invoice) self.set('records',invoice.get_records()) self.set('statuses',Statuses.loadAll(order='priority asc')) return self.response
def manage_orders(self): self.set('invoices',Invoices.loadAll(order='created desc')) return self.response
def create_invoice(self): records = self.request.params.getall('records') if records: fullname = self.request.params.get('customer.name','') email = self.request.params.get('customer.email','') address = self.request.params.get('customer.address','') address2 = self.request.params.get('customer.address2','') phone = self.request.params.get('customer.phone','') agreement = Validators.bool(self.request.params.get('customer.agreement',0)) checkout = self.request.params.getall('customer.checkout') deliver_digitally = False deliver_physically = False # Delivery Options for option in checkout: if option == 'digitally': deliver_digitally = True if option == 'physically': deliver_physically = True # Prep Orders orders = [] total_price = 0.0 location_emails = {} # to notify any locations a request has been made for record in records: c = Cases.load(id=int(record)) e = Entities.load(case_id=int(record)) r = Roles.load(id=e.role) l = Archives.load(id=c.archive) location_emails[l.email] = l.email total_price += float(r.price) orders.append({'case':int(c.id), 'price' : r.price, 'location':int(l.id)}) invoice = Invoices(fullname=fullname, email=email, address=address, county_state_zip=address2, phone=phone, records=orders, agreement_accepted=agreement, deliver_digitally=deliver_digitally, deliver_physically=deliver_physically, total_price='${:,.2f}'.format(total_price)) invoice.insert(self.request) invoice = Invoices.load(order='id desc') #Email Client starting_status = Statuses.load(order='priority asc') Emailer.send(self.request, [email], starting_status.email_subject, starting_status.email_message, link=self.request.application_url + '/invoice/' + invoice.hash ) #Email Archives Involved Emailer.send(self.request, list(location_emails), 'Order request has been placed', 'A new order request has been placed', link=self.request.application_url + '/login?goto=' + self.request.application_url + '/manage/orders' ) response = HTTPFound(location=route_url('invoice', self.request, hash=invoice.hash)) response.delete_cookie('basket') return response else: return self.response