def on_generate(self, event): today = datetime.date.today() bills = [] item = -1 while True: item = self.reminders.GetNextSelected(item) if item == -1: break id_bill = self.data[item][0] self.cursor.execute( """INSERT INTO reminders (id_bill, amount_cts, reminder_date) VALUES (%s, %s, %s)""", [id_bill, custo.MONTANT_RAPPEL_CTS, today]) bills.append(Bill.load(self.cursor, id_bill)) consults = [b for b in bills if b.type == BILL_TYPE_CONSULTATION] if consults: filename = normalize_filename(datetime.datetime.now().strftime( 'rappels_consultations_%F_%Hh%Mm%Ss.pdf')) pdf_bills.consultations(filename, consults) cmd, cap = mailcap.findmatch(mailcap.getcaps(), 'application/pdf', 'view', filename) os.system(cmd) manuals = [b for b in bills if b.type == BILL_TYPE_MANUAL] if manuals: filename = normalize_filename(datetime.datetime.now().strftime( 'rappels_factures_manuelles_%F_%Hh%Mm%Ss.pdf')) pdf_bills.manuals(filename, manuals) cmd, cap = mailcap.findmatch(mailcap.getcaps(), 'application/pdf', 'view', filename) os.system(cmd) self.Close()
def on_print_again(self, event): bill_ids = [ id for i, id in enumerate(self.data) if self.payments.IsSelected(i) ] if bill_ids: bills = [Bill.load(self.cursor, id_bill) for id_bill in bill_ids] consults = [b for b in bills if b.type == BILL_TYPE_CONSULTATION] if consults: filename_consult = normalize_filename( datetime.datetime.now().strftime( 'consultations_%F_%Hh%Mm%Ss.pdf')) pdf_bills.consultations(filename_consult, consults) cmd, cap = mailcap.findmatch(mailcap.getcaps(), 'application/pdf', 'view', filename_consult) os.system(cmd + '&') manuals = [b for b in bills if b.type == BILL_TYPE_MANUAL] if manuals: filename_manual = normalize_filename( datetime.datetime.now().strftime( 'fact_manuelles_%F_%Hh%Mm%Ss.pdf')) pdf_bills.manuals(filename_manual, manuals) cmd, cap = mailcap.findmatch(mailcap.getcaps(), 'application/pdf', 'view', filename_manual) os.system(cmd + '&')
def on_update_list(self, *args): from dateutil import parse_ISO upto = parse_ISO(self.upto.Value.strip()) self.reminders.DeleteAllItems() self.total.Value = '' self.data = [] self.is_updating_list = True try: where = dict(payment_date__isnull=True, bv_ref__isnull=False, bv_ref__ne='', timestamp__le=upto, status__notin=('P', 'A')) for bill in Bill.yield_all(self.cursor, where=where, order='timestamp'): if bill.reminders: reminders_last = sorted(bill.reminders, key=attrgetter('reminder_date'))[-1].reminder_date if reminders_last > upto: continue else: reminders_last = '' index = self.reminders.Append((bill.sex, bill.lastname, bill.firstname, bill.timestamp.date(), '%0.2f' % ((bill.total_cts)/100.), reminders_last, len(bill.reminders))) self.reminders.Select(index) if len(bill.reminders) == 1: self.reminders.SetItemTextColour(index, wx.Colour(64, 0, 0)) self.reminders.SetItemFont(index, self.GetFont().Italic()) elif len(bill.reminders) > 1: self.reminders.SetItemTextColour(index, wx.Colour(128, 0, 0)) self.reminders.SetItemFont(index, self.GetFont().Bold()) self.data.append((bill.id, bill.total_cts, bill.sex, bill.lastname, bill.firstname, bill.timestamp, len(bill.reminders), sum(p.total_cts for p in bill.positions), sum(r.amount_cts for r in bill.reminders))) except: traceback.print_exc() showwarning(windows_title.db_error, errors_text.db_read) self.is_updating_list = False for c in range(self.reminders.ColumnCount): self.reminders.SetColumnWidth(c, wx.LIST_AUTOSIZE) self.reminders.SetColumnWidth(c, self.reminders.GetColumnWidth(c) + 5) # Workaround for font style not being taken into account self.on_update_selection()
def on_import_payments(self, event): with wx.FileDialog(self, "Importer les paiements", wildcard="Relevers de paiement (*.v11)|*.v11", style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) as dlg: if dlg.ShowModal() == wx.ID_CANCEL: return filename = dlg.GetPath() records = self.read_payments(filename) if records is None: return ignored = [] not_found = [] ok = [] ko = [] doubled = [] for transaction_type, bvr_client_no, ref_no, amount_cts, depot_ref, depot_date, processing_date, credit_date, microfilm_no, reject_code, postal_fee_cts in records: if transaction_type[2] != '2': ignored.append( (transaction_type, bvr_client_no, ref_no, amount_cts, depot_ref, depot_date, processing_date, credit_date, microfilm_no, reject_code, postal_fee_cts)) continue l = None reminder_cts = 0 bills = list(Bill.yield_all(self.cursor, where=dict(bv_ref=ref_no))) if bills: bill = bills[0] bill_cts = sum(p.total_cts for p in bill.positions) for reminder in [0] + [ r.amount_cts for r in sorted(bill.reminders, key=attrgetter('reminder_date')) ]: reminder_cts += reminder if bill_cts + reminder_cts == amount_cts: if bill.payment_date is None: l = ok else: l = doubled break else: l = ko if l is not None: l.append((bill.id, bill_cts, reminder_cts, transaction_type, bvr_client_no, ref_no, amount_cts, depot_ref, depot_date, processing_date, credit_date, microfilm_no, reject_code, postal_fee_cts)) else: not_found.append( (transaction_type, bvr_client_no, ref_no, amount_cts, depot_ref, depot_date, processing_date, credit_date, microfilm_no, reject_code, postal_fee_cts)) ImportDialog(self, ok, ko, doubled, not_found, ignored).ShowModal() self.update_list()
def on_refresh(self, event): "Populate liste based on the filter fields" self.on_deselect_payment(None) self.payments.DeleteAllItems() try: self.data = list(Bill.yield_all(self.cursor, "type = 'C' AND timestamp > CURDATE() AND (status = 'O' OR status = 'I' AND payment_method = 'BVR')", "timestamp")) for bill in self.data: self.payments.Append((bill.sex, bill.lastname, bill.firstname, bill.consultation.therapeute, bill.timestamp.strftime('%H:%M'), '%0.2f' % (bill.total_cts/100), bill.payment_method)) except: traceback.print_exc() showwarning(windows_title.db_error, errors_text.db_read)
def on_refresh(self, event): "Populate liste based on the filter fields" self.on_deselect_payment(None) self.payments.DeleteAllItems() try: self.data = list( Bill.yield_all( self.cursor, "type = 'C' AND site = '%s' AND timestamp > CURDATE() AND (status = 'O' OR status = 'I' AND payment_method = 'BVR')" % SITE, "timestamp")) for bill in self.data: self.payments.Append( (bill.sex, bill.lastname, bill.firstname, bill.consultation.therapeute, bill.timestamp.strftime('%H:%M'), '%0.2f' % (bill.total_cts / 100), bill.payment_method)) except: show_db_warning(logger, 'read')
def update_list(self): from dateutil import parse_ISO therapeute = self.therapeute.StringSelection payment_method = self.payment_method.StringSelection filter_start = parse_ISO(self.filter_start.Value.strip()) filter_end = parse_ISO(self.filter_end.Value.strip()) bill_status = self.bill_status.StringSelection site = self.site.StringSelection filter_firstname = self.filter_firstname.Value.strip() filter_lastname = self.filter_lastname.Value.strip() where = {} if therapeute != 'Tous': where['author_id'] = therapeute if payment_method != '': where['payment_method'] = payment_method if filter_start: where['timestamp__ge'] = filter_start if filter_end: where['timestamp__lt'] = filter_end + datetime.timedelta(days=1) if bill_status != 'Tous': bill_status = bill_status[0] if bill_status == 'O': where['status__in'] = ('O', 'I', 'E') else: where['status'] = bill_status if site != 'Tous': where['site'] = site if filter_firstname: where['firstname__like'] = filter_firstname.replace('*', '%') if filter_lastname: where['lastname__like'] = filter_lastname.replace('*', '%') self.payments.DeleteAllItems() self.payments_count.Value = '' self.total_bills.Value = '' self.total_reminder_costs.Value = '' self.total.Value = '' self.data = [] count = 0 total_bills = 0 total_reminder_costs = 0 try: for bill in Bill.yield_all(self.cursor, where=where, order='timestamp'): if bill.status not in (STATUS_ABANDONED, STATUS_PAYED) and bill.reminders: status = sorted(bill.reminders, key=attrgetter('reminder_date'))[-1].status else: status = bill.status index = self.payments.Append( (status, bill.sex, bill.lastname, bill.firstname, bill.site, bill.timestamp.date(), '%6.2f' % (bill.total_cts / 100), bill.payment_date or '')) if len(bill.reminders) == 1: self.payments.GetItem(index).SetTextColour( wx.Colour(64, 0, 0)) elif len(bill.reminders) > 1: self.payments.GetItem(index).SetTextColour( wx.Colour(128, 0, 0)) self.data.append(bill.id) total_bills += sum(p.total_cts for p in bill.positions) total_reminder_costs += sum(r.amount_cts for r in bill.reminders) count += 1 except: show_db_warning(logger, 'read') for c in range(self.payments.ColumnCount): self.payments.SetColumnWidth( c, wx.LIST_AUTOSIZE_USEHEADER if c == 1 else wx.LIST_AUTOSIZE) self.payments_count.Value = str(count) self.total_bills.Value = '%0.2f CHF' % (total_bills / 100.) self.total_reminder_costs.Value = '%0.2f CHF' % (total_reminder_costs / 100.) self.total.Value = '%0.2f CHF' % ( (total_bills + total_reminder_costs) / 100.)