5 コミット a603c385d1 ... 12db366ffa

作者 SHA1 メッセージ 日付
  vnc-console 12db366ffa added test_bolt_invoice 3 ヶ月 前
  vnc-console 4823267525 added BoltSaleinv module 3 ヶ月 前
  vnc-console d218595135 added initial partner module 3 ヶ月 前
  vnc-console 7b61839cff import Boltsaleinv + Partner 3 ヶ月 前
  vnc-console ab0c212297 added bolt template + partner template 3 ヶ月 前

+ 2 - 0
py_mentor_imports/__init__.py

@@ -1,4 +1,6 @@
 '''Created on 13 May 2024 @author: vnc-console'''
 
 from .monetars import Monetar
+from .sale_invoices import BoltSaleInvoice
+from .partners import Partner
 from .utils import (convert_date_format, get_last_month)

+ 25 - 0
py_mentor_imports/partners.py

@@ -0,0 +1,25 @@
+'''Created on 4 Jun 2024 @author: vnc-console'''
+
+from anafapi.anafapi import anafAPI
+
+class Partner(object):
+    '''classdocs'''
+    api = anafAPI()
+
+    def __init__(self, vat_code):
+        '''Constructor'''
+        self.vat_code = vat_code
+        self.fiscal_code = self.vat_code.replace('RO', '')
+        _, self.part = self.api.get_vat(self.fiscal_code)
+        self.name = self.part['denumire']
+
+    # def get_data(self):
+    #     _, part = self.api.get_vat(self.fiscal_code)
+    #     self.name = part['denumire']
+    #     return self.api.get_vat(self.fiscal_code)
+
+
+if __name__ == '__main__':
+    partner = Partner('11358358')
+    # print(partner.get_data())
+    print(partner.part)

+ 12 - 0
py_mentor_imports/sale_invoices.py

@@ -0,0 +1,12 @@
+'''Created on 3 Jun 2024 @author: vnc-console'''
+
+class BoltSaleInvoice(object):
+    '''classdocs'''
+
+    def __init__(self, doc_data, buyer_name, buyer_code, total_value, doc_number, doc_notes):
+        self.buyer_name = buyer_name
+        self.buyer_code = buyer_code
+        self.total_value = total_value
+        self.doc_number = doc_number
+        self.doc_notes = doc_notes
+        self.doc_data = doc_data

+ 21 - 0
py_mentor_imports/templates/bolt_sale_invoice.txt

@@ -0,0 +1,21 @@
+[InfoPachet]
+AnLucru={{ AnLucru }}
+LunaLucru={{ LunaLucru }}
+TipDocument=FACTURA IESIRE
+TotalFacturi={{ TotalFacturi }}
+{% for document in documents %}
+    [Factura_{{ loop.index }}]
+    NrDoc={{ document.doc_number }}
+    ClasificareSAFT=380
+    SerieCarnet=RO24
+    Data={{ document.doc_data }}
+    CodClient={{ document.buyer_code }}
+    TipPlata=9
+    EmisTert=D
+    Observatii={{ document.doc_notes }}
+    EFactObs={{ document.doc_notes }}
+    Operat=D
+    TotalArticole=1
+    [Items_{{ loop.index }}]
+    Item_1=TRBOLT;Buc;1;{{ document.total_value }}
+{% endfor %}

+ 13 - 0
py_mentor_imports/templates/partners.txt

@@ -0,0 +1,13 @@
+[InfoPachet ]
+{% for partner in partners %}
+    [ParteneriNoi_{{ partner.vat_code }}]
+    Denumire={{ partner.name }}
+    {# Localitate={{ partner.location }} #}
+    Tara=Romania
+    SimbolTara=RO
+    {# Judet={{ partner.county }} #}
+    CodFiscal={{ partner.vat_code }}
+    {# Adresa=Str.AAA, nr.1;Str.BBB, nr.2 #}
+    PersoanaFizica=NU
+    TipContabil=Tipic
+{% endfor %}

+ 90 - 0
tests/test_sale_invoice.py

@@ -0,0 +1,90 @@
+'''
+Created on 3 Jun 2024 @author: vnc-console
+'''
+import unittest
+import re
+import os
+import datetime
+from jinja2 import (Environment, PackageLoader)
+import pymupdf
+import pandas as pd
+from py_mentor_imports import (convert_date_format, get_last_month, BoltSaleInvoice, Partner)
+
+class Test(unittest.TestCase):
+
+    templates = Environment(loader=PackageLoader('py_mentor_imports', 'templates'))
+    template = templates.get_template('bolt_sale_invoice.txt')
+    template2 = templates.get_template('partners.txt')
+
+    def test_bolt_inv(self):
+        names = []
+        codes = []
+        values = []
+        numbers = []
+        notes = []
+        dates = []
+        for root, _dir, files in os.walk(r'f:\Gdrive\Misc\Dosar-Contabilitate\Ridewave\2024_06'):
+            for file in files:
+                if file.endswith('.pdf'):
+                    with pymupdf.open(os.path.join(root, file)) as doc:
+                        page = doc[0]
+                        texts = []
+                        txt = page.get_text()
+                        texts.append(txt)
+                        # print(texts)
+                        buyer_name = re.search(r'[a-zA-Z0-9. ]*(?=\nRidewave SRL)', txt)
+                        buyer_code = re.search(r'(?<=Cod TVA: )[a-zA-Z0-9]*|(?<=Reg. code: )[a-zA-Z0-9]*', txt).group()
+                        if buyer_code == '49340170':
+                            buyer_code = input(f'enter code manually for {buyer_name.group()}')
+
+                        total_value = re.search(r'(?<=otal \(RON\):\n)[a-zA-Z0-9.]*', txt)
+                        doc_number = re.search(r'(?<=Factura nr. )[a-zA-Z\n0-9-]*|(?<=Invoice no. )[a-zA-Z\n0-9-]*', txt)
+                        doc_number = doc_number.group().strip().replace('\n', '')[-3:]
+                        doc_notes = re.search(r'(?<=Pornire: )[a-zA-Z \n,.\(\):0-9-]*|(?<=Start: )[a-zA-Z \n,.\(\):0-9-]*', txt)
+                        doc_notes = doc_notes.group().strip().replace('\n', '')
+                        doc_data = re.search(r'(?<=Dată: )[0-9.]*|(?<=Date: )[0-9.]*', txt)
+                        names.append(buyer_name.group())
+                        codes.append(buyer_code)
+                        values.append(total_value.group())
+                        numbers.append(doc_number)
+                        notes.append(doc_notes)
+                        dates.append(doc_data.group())
+                        # print(total_value.group(), buyer_code.group(), doc_number)
+        data = {'dates': dates, 'names': names, 'codes': codes, 'values': values, 'numbers': numbers, 'notes': notes}
+        df = pd.DataFrame(data)
+        # print(df)
+        invoices = []
+        partners = []
+        for date, name, code, value, number, note in zip(df['dates'], df['names'], df['codes'], df['values'], df['numbers'], df['notes']):
+            invoice = BoltSaleInvoice(doc_data=date, buyer_name=name, buyer_code=code, total_value=value, doc_number=number, doc_notes=note)
+            invoices.append(invoice)
+            partner = Partner(vat_code=code)
+            partners.append(partner)
+        data = {'AnLucru': datetime.date.today().year,
+                'LunaLucru': get_last_month(0),
+                'TotalFacturi': len(df),
+                'documents': invoices,
+                # 'NrDoc': [],
+                # 'NumarBonuri': [],
+                # 'Data': [],
+                # 'Observatii': [],
+                'Code': 'TRANSPMF'
+                # 'Pret': []
+                }
+        data2 = {'partners': partners}
+        output = self.template.render(data)
+        output2 = self.template2.render(data2)
+        print(output)
+        home = os.path.expanduser('~')
+        downloads_dir = os.path.join(home, 'Downloads', 'mentor', 'import', 'RIDEWAVE')
+        output_file = os.path.join(downloads_dir, 'facturi.txt')
+        output_file2 = os.path.join(downloads_dir, 'PARTNER.txt')
+        with open(output_file, 'w') as text:
+            text.write(output)
+        with open(output_file2, 'w') as text:
+            text.write(output2)
+
+
+if __name__ == "__main__":
+    # unittest.main()
+    Test().test_bolt_inv()