Beispiel #1
0
 def parse_pvxchange(self,lines):
     items = []
     item = []
     preamble = True
     self.date = None
     self.no = None
     for line in lines:
         if "Bremen, den" in line:
             self.date = utils.convert_date4(line.split()[2])
         elif "Bremen," in line:
             self.date = utils.convert_date4(line.split()[1])
         if line[0:8] == "Rechnung":
             if len(line.split())>1:
                 self.no = line.split()[2]
         if preamble:
             if len(line)>=4 and line[0:4]=="Pos.":
                 preamble = False
             continue
         if len(line)>=5 and line[0:5]=="Seite":
             preamble = True
             continue
         try:
             pos_no = int(line.split()[0])
         except Exception:
             pos_no = -1
         if pos_no == 28219:
             break
         if pos_no>=0 or 'Nettosumme' in line:
             items.append(item)
             item = [line]
         else:
             item.append(line)
     items.append(item)
     self.items = []
     mypos = 0
     for item_lines in items[1:-1]:
         parts = " ".join(map(lambda s: s.strip(),item_lines)).split()
         s_item = SupplierItem(self)
         s_item.qty = int(parts[1])
         s_item.rate = utils.read_float(parts[-4])
         s_item.amount = utils.read_float(parts[-2])
         s_item.qty_unit = "Stk"
         s_item.description = " ".join(parts[2:-4])
         s_item.long_description = s_item.description
         try:
             ind = parts.index('Artikelnummer:')
             s_item.item_code = parts[ind+1]
         except Exception:
             s_item.item_code = None
         if not (s_item.description=="Selbstabholer" and s_item.amount==0.0):
             self.items.append(s_item)
     self.shipping = 0.0
     vat_line = [line for line in items[-1] if 'MwSt' in line][0]
     self.vat[self.default_vat] = utils.read_float(vat_line.split()[-2])
     total_line = [line for line in items[-1] if 'Nettosumme' in line][0]
     self.totals[self.default_vat] = utils.read_float(total_line.split()[-2])
     self.compute_total()
Beispiel #2
0
 def read_sparda_ethik(self,infile,is_sparda=True):
     blz = None
     baccount_no = None
     r = 0 if is_sparda else 1
     for row in utils.get_csv('iso-8859-4',infile,replacenl=is_sparda):
         if not row:
             continue
         if row[0]=='BLZ:':
             blz = int(row[1])
             continue
         if row[0]=='Konto:':
             baccount_no = int(row[1])
             continue
         date = utils.convert_date4(row[0])
         if not date:
             continue
         if row[9+r]=='Anfangssaldo':
             self.sbal = utils.read_float(row[11+r],row[12+r])
             continue
         if row[9+r]=='Endsaldo':
             self.ebal = utils.read_float(row[11+r],row[12+r])
             continue
         be = BankStatementEntry(self)
         be.posting_date = date
         be.purpose = row[8+r]
         be.partner = row[3+r]
         be.partner_iban = row[5+r]
         be.amount = utils.read_float(row[11+r],row[12+r])
         be.cleanup()
         self.entries.append(be)
     if blz and baccount_no:
         self.iban = utils.iban_de(blz,baccount_no)
Beispiel #3
0
def extract_date(lines):
    for line in lines:
        for word in line.split():
            d = utils.convert_date4(word)
            if d:
                return d
    return None
Beispiel #4
0
 def parse_kornkraft(self,lines):
     self.date = None
     self.no = None
     for vat in self.vat_rates:
         self.vat[vat] = 0
         self.totals[vat] = 0
     vat_rate_strs = ["{:.2f}".format(r).replace(".",",") for r in self.vat_rates]
     for line in lines:
         words = line.split()
         if not self.date:
             for i in range(len(words)):
                 self.date = utils.convert_date4(words[i])
                 if self.date:
                     self.no = words[i-2]
                     break
         else:
             if len(words)>12:
                 words = [w.replace('*','') for w in words]
                 for vat in vat_rate_strs:
                     if vat in words[0:6]:
                         #print(list(zip(words,range(len(words)))))
                         vat = utils.read_float(vat)
                         self.vat[vat] = utils.read_float(words[-4])
                         self.totals[vat] = utils.read_float(words[-2]) - self.vat[vat]
                         break
     #print(self.date,self.no,self.vat,self.totals)
     self.items = []
     self.shipping = 0.0
     self.compute_total()
     self.assign_default_e_items(KORNKRAFT_ACCOUNTS)
Beispiel #5
0
 def parse_nkk(self,lines):
     self.date = None
     self.no = None
     for line in lines:
         words = line.split()
         if not self.date:
             for i in range(len(words)):
                 self.date = utils.convert_date4(words[i])
                 if self.date:
                     self.no = words[i-1]
                     break
         elif words:
             for vat in self.vat_rates:
                 vatstr = "{:.2f}%".format(vat).replace(".",",")
                 if words[0]==vatstr:
                     self.vat[vat] = utils.read_float(words[5])
                     self.totals[vat] = utils.read_float(words[1])+\
                                        utils.read_float(words[3])
     self.items = []
     self.shipping = 0.0
     self.compute_total()
     self.assign_default_e_items(NKK_ACCOUNTS)
Beispiel #6
0
 def parse_generic(self,lines):
     if lines:
         (amount,vat) = extract_amount_and_vat(lines,self.vat_rates)
     if lines and amount:    
         self.vat[self.default_vat] = vat
         self.totals[self.default_vat] = amount-self.vat[self.default_vat]
         self.shipping = 0.0
         self.date = extract_date(lines)
         self.no = extract_no(lines)
         self.supplier = extract_supplier(lines)
         if self.check_if_present():
             return None
     else:
         amount = ""
         self.vat[self.default_vat] = ""
         self.totals[self.default_vat] = ""
         self.shipping = 0.0
         self.date = ""
         self.no = ""
         self.supplier = ""
     suppliers = gui_api_wrapper(Api.api.get_list,"Supplier")
     supplier_names = [supp['name'] for supp in suppliers]+['neu']
     def_supp = self.supplier if self.supplier in supplier_names else "neu"
     def_new_supp = "" if self.supplier in supplier_names else self.supplier
     layout = [  [sg.Text('Lieferant')],
                 [sg.OptionMenu(values=supplier_names, k='-supplier-',
                                default_value = def_supp)],
                 [sg.Text('ggf. neuer Lieferant')],
                 [sg.Input(default_text = def_new_supp,
                           k='-supplier-name-')],
                 [sg.Text('Rechnungsnr.')],     
                 [sg.Input(default_text = self.no, k='-no-')],
                 [sg.Text('Datum')],     
                 [sg.Input(key='-date-',
                           default_text = utils.show_date4(self.date)),
                  sg.CalendarButton('Kalender', target='-date-',
                                    format = '%d.%m.%Y',
                                    begin_at_sunday_plus=1)],
                 [sg.Text('MWSt')],     
                 [sg.Input(default_text = str(self.vat[self.default_vat]),
                           k='-vat-')],
                 [sg.Text('Brutto')],     
                 [sg.Input(default_text = str(amount), k='-gross-')],
                 [sg.Checkbox('Schon selbst bezahlt',
                              default=False, k='-paid-')],
                 [sg.Text('Kommentar')],     
                 [sg.Input(k='-remarks-')],
                 [sg.Button('Speichern')] ]
     window1 = sg.Window("Einkaufsrechnung", layout, finalize=True)
     window1.bring_to_front()
     event, values = window1.read()
     #print(event, values)             
     window1.close()
     if values:
         if '-supplier-' in values:
             self.supplier = values['-supplier-']
             if self.supplier == 'neu' and '-supplier-name-' in values:
                 self.supplier = values['-supplier-name-']
         if '-no-' in values:
             self.no = values['-no-']
         if '-date-' in values:
             date = utils.convert_date4(values['-date-'])
             if date:
                 self.date = date
         if '-vat-' in values:
             self.vat[self.default_vat] = \
                 float(values['-vat-'].replace(",","."))
         if '-gross-' in values:
             self.totals[self.default_vat] = \
                 float(values['-gross-'].replace(",","."))\
                 -self.vat[self.default_vat]
         if '-paid-' in values and values['-paid-']:
             self.paid_by_submitter = True
         if '-remarks-' in values:
             self.remarks = values['-remarks-']
     else:
         return None
     self.compute_total()
     accounts = self.company.leaf_accounts_for_credit
     account_names = [acc['name'] for acc in accounts]
     pinvs = self.company.purchase_invoices[self.supplier]
     paccs = [pi['expense_account'] for pi in pinvs if 'expense_account' in pi]
     paccs = list(set(paccs))
     for acc in paccs:
         try:
             account_names.remove(j)
         except Exception:
             pass
     account_names = paccs + account_names
     title = 'Buchungskonto wählen'
     msg = 'Bitte ein Buchungskonto wählen\n'
     account = easygui.choicebox(msg, title, account_names)
     if not account:
         return None
     self.assign_default_e_items({self.default_vat:account})
     return self
Beispiel #7
0
 def parse_krannich(self,lines):
     items = []
     item = []
     for line in lines:
         if line[0].isdigit():
             items.append(item)
             item = [line]
         else:
             item.append(line)
     items.append(item)
     self.date = None
     self.no = None
     for line in items[0]:
         if "Rechnung" in line:
             self.no = line.split()[1]
             self.date = utils.convert_date4(line.split()[2])
     self.items = []
     mypos = 0
     rounding_error = 0
     for item_lines in items[1:]:
         item_str = item_lines[0]
         clutter = ['Einzelpreis','Krannich','IBAN','Rechnung','Übertrag']
         s_item = SupplierItem(self)
         long_description_lines = \
             [l for l in item_lines[1:] \
                if utils.no_substr(clutter,l) and l.strip()]
         s_item.description = " ".join(long_description_lines[0][0:82].split())
         s_item.long_description = ""
         for l in long_description_lines:
             if "Zwischensumme" in l:
                 break
             s_item.long_description += l
         pos = int(item_str[0:7].split()[0])
         if not (pos in [mypos,mypos+1,mypos+2]):
             break
         if "Vorkasse" in s_item.description:
             continue
         mypos = pos
         #print(item_str)
         s_item.item_code = item_str.split()[1]
         q=re.search("([0-9]+) *([A-Za-z]+)",item_str[80:99])
         s_item.qty = int(q.group(1))
         s_item.qty_unit = q.group(2)
         price = utils.read_float(item_str[130:142].split()[0])
         try:
             discount = utils.read_float(item_str[142:152].split()[0])
         except Exception:
             discount = 0
         s_item.amount = utils.read_float(item_str[157:].split()[0])
         if s_item.qty_unit=="Rol":
             try:
                 r1 = re.search('[0-9]+ *[mM]', s_item.description)
                 r2 = re.search('[0-9]+', r1.group(0))
                 s_item.qty_unit = "Meter"
                 s_item.qty = int(r2.group(0))
             except Exception:
                 pass
         s_item.rate = round(s_item.amount/s_item.qty,2)
         rounding_error += s_item.amount-s_item.rate*s_item.qty
         self.items.append(s_item)
     vat_line = ""
     for i in range(-1,-len(items),-1):
         vat_lines = [line for line in items[i] if 'MwSt' in line]
         if vat_lines:
             vat_line = vat_lines[0]
             self.shipping = PurchaseInvoice.get_amount_krannich\
                 ([line for line in items[i]\
                    if 'Insurance' in line or 'Freight' in line\
                        or 'Neukundenrabatt' in line])
             break
     self.totals[self.default_vat] = utils.read_float(vat_line[145:157])
     self.vat[self.default_vat] = PurchaseInvoice.get_amount_krannich([vat_line])
     self.shipping += rounding_error
     self.compute_total()