Ajoutez des fichiers projet.

This commit is contained in:
33inform
2021-12-17 09:49:53 +01:00
parent f820e2dbbe
commit a140a1d5c9
15 changed files with 4018 additions and 0 deletions

128
main.py Normal file
View File

@@ -0,0 +1,128 @@
import csv
import json
import os
from datetime import datetime
from class_invoices import *
if __name__ == '__main__':
print("Script conversion JSON to Winbiz csv, by Resk-U")
print("Lecture des fichiers .json dans le dossier ./File_input")
Elements = []
export_csv = "";
con_csv = "";
def parseFile(data,filename):
lines = []
for ele in data["invoices"]:
data = cls_Invoice()
data.parse_item(ele)
for article in data.Articles:
csv_col = cls_Col()
##Donnée globales
csv_col.data[0] = data.data["id"] # N° document
csv_col.data[129] = data.Intervention["type"] # Priorité
csv_col.data[1] = 20 # Type of document 20 = facture débiteur
csv_col.data[2] = datetime.strptime(data.data["date"], "%Y-%m-%d").strftime("%d.%m.%Y") # Date du document
csv_col.data[4] = data.Patient["fip_number"] # Référence
csv_col.data[10] = "<AUTO>" # Compte collectif du tiers = <AUTO>
if data.Patient["gender"] == "Féminin":
csv_col.data[12] = "F" # Langue du document, utilisé comme sexe
elif data.Patient["gender"] == "Masculin":
csv_col.data[12] = "M" # Langue du document, utilisé comme sexe
csv_col.data[19] = data.Debtor["code"] # Code adresse à récupérer dans recherche d'adresse automatisée
## Donnée Patients
csv_col.data[22] = data.Patient["lastname"] # Nom de famille du patient
csv_col.data[23] = data.Patient["firstname"] # Prénom du patient
csv_col.data[24] = data.Patient["street"] # Rue du patient
csv_col.data[25] = data.Patient["complement"] # Complément rue
csv_col.data[26] = data.Patient["postal_code"] # NPA du patient
csv_col.data[27] = data.Patient["city"] # Localité du patient
csv_col.data[107] = data.Patient["birthdate"] # Date de naissance du patient
csv_col.data[108] = "" # Profession
csv_col.data[109] = data.Patient["insurance_name"] # Assurance
csv_col.data[110] = "Filiation" # Filiation
csv_col.data[112] = data.Intervention["site_street"] # Rue PEC
csv_col.data[113] = data.Intervention["site_street_number"] # Rue PEC
csv_col.data[114] = data.Intervention["site_postal_code"] + " " + data.Intervention["site_city"] # Rue PEC
if "destination_name" not in data.Intervention.keys():
csv_col.data[115] = "Sans transport"
else:
csv_col.data[115] = data.Intervention["destination_name"]
csv_col.data[111] = datetime.strptime(data.Intervention["start_time"], "%Y-%m-%dT%H:%M:%S%z").strftime(
"%d.%m.%Y") # Date PEC
csv_col.data[118] = datetime.strptime(data.Intervention["start_time"], "%Y-%m-%dT%H:%M:%S%z").strftime(
"%H:%M") # Heure PEC
csv_col.data[119] = datetime.strptime(data.Intervention["end_time"], "%Y-%m-%dT%H:%M:%S%z").strftime(
"%H:%M") # Heure PEC
# Donnée débiteur
csv_col.data[120] = data.Debtor["lastname"] # Débiteur nom
csv_col.data[121] = data.Debtor["firstname"] # Débiteur prénom
if data.Debtor["street"] is not None:
csv_col.data[122] = data.Debtor["street"] + " " + data.Debtor["street_number"] # Débiteur nom
csv_col.data[127] = data.Debtor["street"] + " " + data.Debtor["street_number"] # Débiteur nom
csv_col.data[123] = data.Debtor["postal_code"] + " " + data.Debtor["city"] # Débiteur
csv_col.data[128] = data.Debtor["postal_code"] + " " + data.Debtor["city"] # Débiteur
csv_col.data[124] = "11111111" # Débiteur nom
if data.Debtor["gender"] == "Féminin":
csv_col.data[125] = "Madame" # Langue du document, utilisé comme sexe
elif data.Debtor["gender"] == "Masculin":
csv_col.data[125] = "Monsieur" # Langue du document, utilisé comme sexe
else:
csv_col.data[125] = "" # Langue du document, utilisé comme sexe
if data.Debtor["type"] == "Personne":
csv_col.data[126] = data.Debtor["firstname"] + " " + data.Debtor["lastname"] # Débiteur nom
elif data.Debtor["type"] == "Établissement":
temp_data = []
temp_data.append(data.Debtor["name"])
temp_data.append(data.Debtor["firstname"])
temp_data.append(data.Debtor["lastname"])
csv_col.data[126] = ' '.join(filter(None,temp_data)) # Débiteur nom
## Données prestations
if "code" in article.keys():
csv_col.data[49] = article["code"] # Code de prestations
csv_col.data[50] = article["line_1"]
if article["line_2"] != None:
csv_col.data[50] = article["line_1"] + " / " + article["line_2"] # Descriptions prestations
csv_col.data[52] = article["quantity"] # Quantité
csv_col.data[53] = article["unit_price"] # prix unitaire
csv_col.data[54] = article["unit"] # unité
csv_col.data[56] = article["price"] # prix total
csv_col.data[59] = "<AUTO>" # Compte chiffre d'affaire = <AUTO>
else:
csv_col.data[49] = "txt"
csv_col.data[50] = article["line_1"]
if article["line_2"] != None:
csv_col.data[50] = article["line_1"] + " / " + article["line_2"] # Descriptions prestations
csv_col.data[52] = 0
csv_col.data[53] = 0
csv_col.data[56] = 0 # prix total
csv_col.data[59] = "<AUTO>" # Compte chiffre d'affaire = <AUTO>
lines.append(csv_col.data)
csv_col = None
with open("./File_input/bizexdoc_"+filename.replace(".json","")+".csv","w", newline='') as csv_file:
wr = csv.writer(csv_file, delimiter=';')
for cdr in lines:
wr.writerow(cdr)
dir = "./File_input"
for filename in os.listdir(dir):
if ".json" in filename:
print(filename)
with open(dir + "/" + filename, encoding="utf-8") as f:
data = json.load(f)
parseFile(data,filename)
#os.remove(dir+"/"+filename)