mode règlement avec regroupement par règlement (je crois)
This commit is contained in:
parent
5ad54a2ff0
commit
06a5fc8df4
1 changed files with 297 additions and 113 deletions
|
|
@ -175,6 +175,7 @@ def lire_tous_reglements(
|
||||||
type_reglement: str = None,
|
type_reglement: str = None,
|
||||||
limit: int = 500,
|
limit: int = 500,
|
||||||
) -> Dict:
|
) -> Dict:
|
||||||
|
"""Liste tous les règlements avec TOUTES les colonnes F_CREGLEMENT"""
|
||||||
if not self.cial:
|
if not self.cial:
|
||||||
raise RuntimeError("Connexion Sage non établie")
|
raise RuntimeError("Connexion Sage non établie")
|
||||||
|
|
||||||
|
|
@ -188,40 +189,60 @@ def lire_tous_reglements(
|
||||||
query = """
|
query = """
|
||||||
SELECT
|
SELECT
|
||||||
r.RG_No,
|
r.RG_No,
|
||||||
|
r.CT_NumPayeur,
|
||||||
r.RG_Date,
|
r.RG_Date,
|
||||||
r.RG_Reference,
|
r.RG_Reference,
|
||||||
r.RG_Libelle,
|
r.RG_Libelle,
|
||||||
r.RG_Montant,
|
r.RG_Montant,
|
||||||
r.RG_MontantDev,
|
r.RG_MontantDev,
|
||||||
|
r.N_Reglement,
|
||||||
r.RG_Impute,
|
r.RG_Impute,
|
||||||
r.RG_Compta,
|
r.RG_Compta,
|
||||||
|
r.EC_No,
|
||||||
r.RG_Type,
|
r.RG_Type,
|
||||||
r.RG_Cours,
|
r.RG_Cours,
|
||||||
r.RG_Banque,
|
r.N_Devise,
|
||||||
r.RG_Impaye,
|
|
||||||
r.RG_MontantEcart,
|
|
||||||
r.CT_NumPayeur,
|
|
||||||
r.JO_Num,
|
r.JO_Num,
|
||||||
r.RG_Piece,
|
|
||||||
r.N_Reglement,
|
|
||||||
r.CG_NumCont,
|
r.CG_NumCont,
|
||||||
|
r.RG_Impaye,
|
||||||
|
r.CG_Num,
|
||||||
|
r.RG_TypeReg,
|
||||||
|
r.RG_Heure,
|
||||||
|
r.RG_Piece,
|
||||||
|
r.CA_No,
|
||||||
|
r.CO_NoCaissier,
|
||||||
|
r.RG_Banque,
|
||||||
|
r.RG_Transfere,
|
||||||
r.RG_Cloture,
|
r.RG_Cloture,
|
||||||
r.RG_Ticket,
|
r.RG_Ticket,
|
||||||
|
r.RG_Souche,
|
||||||
|
r.CT_NumPayeurOrig,
|
||||||
|
r.RG_DateEchCont,
|
||||||
|
r.CG_NumEcart,
|
||||||
|
r.JO_NumEcart,
|
||||||
|
r.RG_MontantEcart,
|
||||||
|
r.RG_NoBonAchat,
|
||||||
|
r.RG_Valide,
|
||||||
|
r.RG_Anterieur,
|
||||||
|
r.RG_MontantCommission,
|
||||||
|
r.RG_MontantNet,
|
||||||
r.cbCreation,
|
r.cbCreation,
|
||||||
r.cbModification,
|
r.cbModification,
|
||||||
|
r.cbCreateur,
|
||||||
c.CT_Intitule,
|
c.CT_Intitule,
|
||||||
j.JO_Intitule,
|
j.JO_Intitule,
|
||||||
mr.R_Intitule as ModeReglementIntitule,
|
mr.R_Intitule as ModeReglementIntitule,
|
||||||
(SELECT ISNULL(SUM(RE_Montant), 0) FROM F_REGLECH WHERE RG_No = r.RG_No) as MontantImpute
|
dev.D_Intitule as DeviseIntitule,
|
||||||
|
(SELECT ISNULL(SUM(RC_Montant), 0) FROM F_REGLECH WHERE RG_No = r.RG_No) as MontantImpute
|
||||||
FROM F_CREGLEMENT r
|
FROM F_CREGLEMENT r
|
||||||
LEFT JOIN F_COMPTET c ON r.CT_NumPayeur = c.CT_Num
|
LEFT JOIN F_COMPTET c ON r.CT_NumPayeur = c.CT_Num
|
||||||
LEFT JOIN F_JOURNAUX j ON r.JO_Num = j.JO_Num
|
LEFT JOIN F_JOURNAUX j ON r.JO_Num = j.JO_Num
|
||||||
LEFT JOIN P_REGLEMENT mr ON r.N_Reglement = mr.cbIndice
|
LEFT JOIN P_REGLEMENT mr ON r.N_Reglement = mr.cbIndice
|
||||||
|
LEFT JOIN P_DEVISE dev ON r.N_Devise = dev.cbIndice
|
||||||
WHERE 1=1
|
WHERE 1=1
|
||||||
"""
|
"""
|
||||||
params = []
|
params = []
|
||||||
|
|
||||||
# Filtrer par type (0 = client, 1 = fournisseur)
|
|
||||||
if type_reglement:
|
if type_reglement:
|
||||||
if type_reglement.lower() == "client":
|
if type_reglement.lower() == "client":
|
||||||
query += " AND r.RG_Type = 0"
|
query += " AND r.RG_Type = 0"
|
||||||
|
|
@ -240,7 +261,7 @@ def lire_tous_reglements(
|
||||||
query += " AND r.CT_NumPayeur = ?"
|
query += " AND r.CT_NumPayeur = ?"
|
||||||
params.append(client_code)
|
params.append(client_code)
|
||||||
|
|
||||||
query += f" ORDER BY r.RG_Date DESC, r.RG_No DESC"
|
query += " ORDER BY r.RG_Date DESC, r.RG_No DESC"
|
||||||
|
|
||||||
if limit:
|
if limit:
|
||||||
query = query.replace("SELECT", f"SELECT TOP {limit}")
|
query = query.replace("SELECT", f"SELECT TOP {limit}")
|
||||||
|
|
@ -249,10 +270,12 @@ def lire_tous_reglements(
|
||||||
rows = cursor.fetchall()
|
rows = cursor.fetchall()
|
||||||
|
|
||||||
types_reglement = {0: "Client", 1: "Fournisseur", 2: "Salarié"}
|
types_reglement = {0: "Client", 1: "Fournisseur", 2: "Salarié"}
|
||||||
statuts_impute = {
|
types_reg = {
|
||||||
0: "Non imputé",
|
0: "Aucun",
|
||||||
1: "Partiellement imputé",
|
1: "Règlement",
|
||||||
2: "Totalement imputé",
|
2: "Escompte accordé",
|
||||||
|
3: "Effet encaissé",
|
||||||
|
4: "Effet impayé",
|
||||||
}
|
}
|
||||||
|
|
||||||
reglements = []
|
reglements = []
|
||||||
|
|
@ -260,12 +283,10 @@ def lire_tous_reglements(
|
||||||
total_impute = 0.0
|
total_impute = 0.0
|
||||||
|
|
||||||
for row in rows:
|
for row in rows:
|
||||||
rg_no = row[0]
|
rg_montant = float(row[5] or 0)
|
||||||
rg_montant = float(row[4] or 0)
|
montant_impute = float(row[45] or 0)
|
||||||
montant_impute = float(row[25] or 0)
|
|
||||||
reste_a_imputer = rg_montant - montant_impute
|
reste_a_imputer = rg_montant - montant_impute
|
||||||
|
|
||||||
# Déterminer le statut d'imputation
|
|
||||||
if montant_impute == 0:
|
if montant_impute == 0:
|
||||||
statut_imputation = "Non imputé"
|
statut_imputation = "Non imputé"
|
||||||
elif abs(reste_a_imputer) < 0.01:
|
elif abs(reste_a_imputer) < 0.01:
|
||||||
|
|
@ -273,79 +294,141 @@ def lire_tous_reglements(
|
||||||
else:
|
else:
|
||||||
statut_imputation = "Partiellement imputé"
|
statut_imputation = "Partiellement imputé"
|
||||||
|
|
||||||
|
heure_str = None
|
||||||
|
if row[19]:
|
||||||
|
try:
|
||||||
|
heure_str = (
|
||||||
|
row[19].strftime("%H:%M:%S")
|
||||||
|
if hasattr(row[19], "strftime")
|
||||||
|
else str(row[19])
|
||||||
|
)
|
||||||
|
except:
|
||||||
|
heure_str = str(row[19])
|
||||||
|
|
||||||
reglement = {
|
reglement = {
|
||||||
"rg_no": rg_no,
|
"rg_no": row[0],
|
||||||
"numero_piece": (row[15] or "").strip(),
|
"numero_piece": (row[20] or "").strip(),
|
||||||
"date": row[1].strftime("%Y-%m-%d") if row[1] else None,
|
"date": row[2].strftime("%Y-%m-%d") if row[2] else None,
|
||||||
"reference": (row[2] or "").strip(),
|
"heure": heure_str,
|
||||||
"libelle": (row[3] or "").strip(),
|
"date_echeance_contrepartie": row[29].strftime("%Y-%m-%d")
|
||||||
|
if row[29]
|
||||||
|
else None,
|
||||||
|
"reference": (row[3] or "").strip(),
|
||||||
|
"libelle": (row[4] or "").strip(),
|
||||||
"montant": rg_montant,
|
"montant": rg_montant,
|
||||||
"montant_devise": float(row[5] or 0),
|
"montant_devise": float(row[6] or 0),
|
||||||
"montant_impute": montant_impute,
|
"montant_impute": montant_impute,
|
||||||
"reste_a_imputer": reste_a_imputer,
|
"reste_a_imputer": reste_a_imputer,
|
||||||
|
"montant_ecart": float(row[32] or 0),
|
||||||
|
"montant_commission": float(row[36] or 0),
|
||||||
|
"montant_net": float(row[37] or 0),
|
||||||
|
"cours": float(row[12] or 1),
|
||||||
"statut_imputation": statut_imputation,
|
"statut_imputation": statut_imputation,
|
||||||
"type_code": row[8],
|
"est_impute": row[8] == 1,
|
||||||
"type_libelle": types_reglement.get(row[8], f"Type {row[8]}"),
|
"est_comptabilise": row[9] == 1,
|
||||||
"client_code": (row[13] or "").strip(),
|
"est_impaye": row[16] == 1,
|
||||||
"client_intitule": (row[22] or "").strip(),
|
"est_transfere": row[24] == 1,
|
||||||
|
"est_cloture": row[25] == 1,
|
||||||
|
"est_valide": row[34] == 1,
|
||||||
|
"est_anterieur": row[35] == 1,
|
||||||
|
"type_code": row[11],
|
||||||
|
"type_libelle": types_reglement.get(row[11], f"Type {row[11]}"),
|
||||||
|
"type_reg_code": row[18],
|
||||||
|
"type_reg_libelle": types_reg.get(row[18], f"TypeReg {row[18]}"),
|
||||||
|
"client_code": (row[1] or "").strip(),
|
||||||
|
"client_intitule": (row[41] or "").strip(),
|
||||||
|
"client_origine": (row[28] or "").strip(),
|
||||||
"journal_code": (row[14] or "").strip(),
|
"journal_code": (row[14] or "").strip(),
|
||||||
"journal_intitule": (row[23] or "").strip(),
|
"journal_intitule": (row[42] or "").strip(),
|
||||||
"mode_reglement_code": row[16],
|
"compte_general": (row[17] or "").strip(),
|
||||||
|
"compte_contrepartie": (row[15] or "").strip(),
|
||||||
|
"compte_ecart": (row[30] or "").strip(),
|
||||||
|
"journal_ecart": (row[31] or "").strip(),
|
||||||
|
"mode_reglement_code": row[7],
|
||||||
"mode_reglement_libelle": (
|
"mode_reglement_libelle": (
|
||||||
row[24] or ModeReglement.get_libelle(row[16] or 0)
|
row[43] or ModeReglement.get_libelle(row[7] or 0)
|
||||||
).strip(),
|
).strip()
|
||||||
"compte_contrepartie": (row[17] or "").strip(),
|
if row[43]
|
||||||
"cours": float(row[9] or 1),
|
else ModeReglement.get_libelle(row[7] or 0),
|
||||||
"banque": (row[10] or "").strip(),
|
"devise_code": row[13],
|
||||||
"impaye": row[11] == 1,
|
"devise_intitule": (row[44] or "").strip(),
|
||||||
"ecart": float(row[12] or 0),
|
"banque": (row[23] or "").strip(),
|
||||||
"cloture": row[18] == 1,
|
"caisse_no": row[21],
|
||||||
"ticket": (row[19] or "").strip(),
|
"caissier_no": row[22],
|
||||||
"date_creation": row[20].strftime("%Y-%m-%d %H:%M:%S")
|
"echeancier_no": row[10],
|
||||||
if row[20]
|
"ticket": (row[26] or "").strip(),
|
||||||
|
"souche": row[27],
|
||||||
|
"bon_achat_no": row[33],
|
||||||
|
"date_creation": row[38].strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
if row[38]
|
||||||
else None,
|
else None,
|
||||||
"date_modification": row[21].strftime("%Y-%m-%d %H:%M:%S")
|
"date_modification": row[39].strftime("%Y-%m-%d %H:%M:%S")
|
||||||
if row[21]
|
if row[39]
|
||||||
else None,
|
else None,
|
||||||
|
"createur": (row[40] or "").strip() if row[40] else None,
|
||||||
}
|
}
|
||||||
|
|
||||||
reglements.append(reglement)
|
reglements.append(reglement)
|
||||||
total_montant += rg_montant
|
total_montant += rg_montant
|
||||||
total_impute += montant_impute
|
total_impute += montant_impute
|
||||||
|
|
||||||
# Récupérer les détails d'imputation pour chaque règlement
|
|
||||||
for reg in reglements:
|
for reg in reglements:
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"""
|
"""
|
||||||
SELECT
|
SELECT
|
||||||
re.RE_Montant,
|
re.RG_No,
|
||||||
re.RE_MontantDev,
|
re.RC_Montant,
|
||||||
e.DR_No,
|
re.DR_No,
|
||||||
d.DO_Piece,
|
dr.DO_Domaine,
|
||||||
|
dr.DO_Type,
|
||||||
|
dr.DO_Piece,
|
||||||
d.DO_Date,
|
d.DO_Date,
|
||||||
d.DO_TotalTTC
|
d.DO_TotalTTC,
|
||||||
|
d.DO_Ref
|
||||||
FROM F_REGLECH re
|
FROM F_REGLECH re
|
||||||
LEFT JOIN F_DOCREGL e ON re.DR_No = e.DR_No
|
LEFT JOIN F_DOCREGL dr ON re.DR_No = dr.DR_No
|
||||||
LEFT JOIN F_DOCENTETE d ON e.DO_Domaine = d.DO_Domaine AND e.DO_Type = d.DO_Type AND e.DO_Piece = d.DO_Piece
|
AND re.DO_Domaine = dr.DO_Domaine
|
||||||
|
AND re.DO_Type = dr.DO_Type
|
||||||
|
AND re.DO_Piece = dr.DO_Piece
|
||||||
|
LEFT JOIN F_DOCENTETE d ON dr.DO_Domaine = d.DO_Domaine
|
||||||
|
AND dr.DO_Type = d.DO_Type
|
||||||
|
AND dr.DO_Piece = d.DO_Piece
|
||||||
WHERE re.RG_No = ?
|
WHERE re.RG_No = ?
|
||||||
""",
|
""",
|
||||||
(reg["rg_no"],),
|
(reg["rg_no"],),
|
||||||
)
|
)
|
||||||
|
|
||||||
imputations = cursor.fetchall()
|
imputations = cursor.fetchall()
|
||||||
|
types_doc = {
|
||||||
|
0: "Devis",
|
||||||
|
1: "Bon de commande",
|
||||||
|
2: "Préparation",
|
||||||
|
3: "Bon de livraison",
|
||||||
|
6: "Facture",
|
||||||
|
7: "Avoir",
|
||||||
|
}
|
||||||
|
domaines = {0: "Vente", 1: "Achat", 2: "Stock"}
|
||||||
|
|
||||||
reg["imputations"] = [
|
reg["imputations"] = [
|
||||||
{
|
{
|
||||||
"montant": float(imp[0] or 0),
|
"rg_no": imp[0],
|
||||||
"montant_devise": float(imp[1] or 0),
|
"montant": float(imp[1] or 0),
|
||||||
"document_piece": (imp[3] or "").strip() if imp[3] else None,
|
"dr_no": imp[2],
|
||||||
"document_date": imp[4].strftime("%Y-%m-%d") if imp[4] else None,
|
"document_domaine": domaines.get(imp[3], f"Domaine {imp[3]}")
|
||||||
"document_total": float(imp[5] or 0) if imp[5] else None,
|
if imp[3] is not None
|
||||||
|
else None,
|
||||||
|
"document_type": types_doc.get(imp[4], f"Type {imp[4]}")
|
||||||
|
if imp[4] is not None
|
||||||
|
else None,
|
||||||
|
"document_piece": (imp[5] or "").strip() if imp[5] else None,
|
||||||
|
"document_date": imp[6].strftime("%Y-%m-%d") if imp[6] else None,
|
||||||
|
"document_total": float(imp[7] or 0) if imp[7] else None,
|
||||||
|
"document_reference": (imp[8] or "").strip() if imp[8] else None,
|
||||||
}
|
}
|
||||||
for imp in imputations
|
for imp in imputations
|
||||||
]
|
]
|
||||||
reg["nb_imputations"] = len(imputations)
|
reg["nb_imputations"] = len(imputations)
|
||||||
|
|
||||||
# Statistiques
|
|
||||||
nb_total = len(reglements)
|
nb_total = len(reglements)
|
||||||
nb_imputes = sum(
|
nb_imputes = sum(
|
||||||
1 for r in reglements if r["statut_imputation"] == "Totalement imputé"
|
1 for r in reglements if r["statut_imputation"] == "Totalement imputé"
|
||||||
|
|
@ -387,40 +470,92 @@ def lire_reglement_detail(self, rg_no: int) -> Dict:
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"""
|
"""
|
||||||
SELECT
|
SELECT
|
||||||
r.RG_No, r.RG_Date, r.RG_Reference, r.RG_Libelle,
|
r.RG_No,
|
||||||
r.RG_Montant, r.RG_MontantDev, r.RG_Impute, r.RG_Compta,
|
r.CT_NumPayeur,
|
||||||
r.RG_Type, r.RG_Cours, r.RG_Banque, r.RG_Impaye,
|
r.RG_Date,
|
||||||
r.RG_MontantEcart, r.CT_NumPayeur, r.JO_Num, r.RG_Piece,
|
r.RG_Reference,
|
||||||
r.N_Reglement, r.CG_NumCont, r.RG_Cloture, r.RG_Ticket,
|
r.RG_Libelle,
|
||||||
r.cbCreation, r.cbModification,
|
r.RG_Montant,
|
||||||
c.CT_Intitule, j.JO_Intitule, mr.R_Intitule
|
r.RG_MontantDev,
|
||||||
|
r.N_Reglement,
|
||||||
|
r.RG_Impute,
|
||||||
|
r.RG_Compta,
|
||||||
|
r.EC_No,
|
||||||
|
r.RG_Type,
|
||||||
|
r.RG_Cours,
|
||||||
|
r.N_Devise,
|
||||||
|
r.JO_Num,
|
||||||
|
r.CG_NumCont,
|
||||||
|
r.RG_Impaye,
|
||||||
|
r.CG_Num,
|
||||||
|
r.RG_TypeReg,
|
||||||
|
r.RG_Heure,
|
||||||
|
r.RG_Piece,
|
||||||
|
r.CA_No,
|
||||||
|
r.CO_NoCaissier,
|
||||||
|
r.RG_Banque,
|
||||||
|
r.RG_Transfere,
|
||||||
|
r.RG_Cloture,
|
||||||
|
r.RG_Ticket,
|
||||||
|
r.RG_Souche,
|
||||||
|
r.CT_NumPayeurOrig,
|
||||||
|
r.RG_DateEchCont,
|
||||||
|
r.CG_NumEcart,
|
||||||
|
r.JO_NumEcart,
|
||||||
|
r.RG_MontantEcart,
|
||||||
|
r.RG_NoBonAchat,
|
||||||
|
r.RG_Valide,
|
||||||
|
r.RG_Anterieur,
|
||||||
|
r.RG_MontantCommission,
|
||||||
|
r.RG_MontantNet,
|
||||||
|
r.cbCreation,
|
||||||
|
r.cbModification,
|
||||||
|
r.cbCreateur,
|
||||||
|
c.CT_Intitule,
|
||||||
|
j.JO_Intitule,
|
||||||
|
mr.R_Intitule,
|
||||||
|
dev.D_Intitule
|
||||||
FROM F_CREGLEMENT r
|
FROM F_CREGLEMENT r
|
||||||
LEFT JOIN F_COMPTET c ON r.CT_NumPayeur = c.CT_Num
|
LEFT JOIN F_COMPTET c ON r.CT_NumPayeur = c.CT_Num
|
||||||
LEFT JOIN F_JOURNAUX j ON r.JO_Num = j.JO_Num
|
LEFT JOIN F_JOURNAUX j ON r.JO_Num = j.JO_Num
|
||||||
LEFT JOIN P_REGLEMENT mr ON r.N_Reglement = mr.cbIndice
|
LEFT JOIN P_REGLEMENT mr ON r.N_Reglement = mr.cbIndice
|
||||||
|
LEFT JOIN P_DEVISE dev ON r.N_Devise = dev.cbIndice
|
||||||
WHERE r.RG_No = ?
|
WHERE r.RG_No = ?
|
||||||
""",
|
""",
|
||||||
(rg_no,),
|
(rg_no,),
|
||||||
)
|
)
|
||||||
row = cursor.fetchone()
|
|
||||||
|
|
||||||
|
row = cursor.fetchone()
|
||||||
if not row:
|
if not row:
|
||||||
raise ValueError(f"Règlement {rg_no} introuvable")
|
raise ValueError(f"Règlement {rg_no} introuvable")
|
||||||
|
|
||||||
# Imputations
|
|
||||||
cursor.execute(
|
cursor.execute(
|
||||||
"""
|
"""
|
||||||
SELECT
|
SELECT
|
||||||
re.RE_No, re.RE_Montant, re.RE_MontantDev, re.DR_No,
|
re.RG_No,
|
||||||
e.DO_Domaine, e.DO_Type, e.DO_Piece,
|
re.RC_Montant,
|
||||||
d.DO_Date, d.DO_TotalTTC, d.DO_MontantRegle, d.DO_Ref
|
re.DR_No,
|
||||||
|
dr.DO_Domaine,
|
||||||
|
dr.DO_Type,
|
||||||
|
dr.DO_Piece,
|
||||||
|
d.DO_Date,
|
||||||
|
d.DO_TotalTTC,
|
||||||
|
d.DO_MontantRegle,
|
||||||
|
d.DO_Ref,
|
||||||
|
d.DO_Tiers
|
||||||
FROM F_REGLECH re
|
FROM F_REGLECH re
|
||||||
LEFT JOIN F_DOCREGL e ON re.DR_No = e.DR_No
|
LEFT JOIN F_DOCREGL dr ON re.DR_No = dr.DR_No
|
||||||
LEFT JOIN F_DOCENTETE d ON e.DO_Domaine = d.DO_Domaine AND e.DO_Type = d.DO_Type AND e.DO_Piece = d.DO_Piece
|
AND re.DO_Domaine = dr.DO_Domaine
|
||||||
|
AND re.DO_Type = dr.DO_Type
|
||||||
|
AND re.DO_Piece = dr.DO_Piece
|
||||||
|
LEFT JOIN F_DOCENTETE d ON dr.DO_Domaine = d.DO_Domaine
|
||||||
|
AND dr.DO_Type = d.DO_Type
|
||||||
|
AND dr.DO_Piece = d.DO_Piece
|
||||||
WHERE re.RG_No = ?
|
WHERE re.RG_No = ?
|
||||||
""",
|
""",
|
||||||
(rg_no,),
|
(rg_no,),
|
||||||
)
|
)
|
||||||
|
|
||||||
imputations_rows = cursor.fetchall()
|
imputations_rows = cursor.fetchall()
|
||||||
|
|
||||||
types_doc = {
|
types_doc = {
|
||||||
|
|
@ -432,6 +567,14 @@ def lire_reglement_detail(self, rg_no: int) -> Dict:
|
||||||
7: "Avoir",
|
7: "Avoir",
|
||||||
}
|
}
|
||||||
domaines = {0: "Vente", 1: "Achat", 2: "Stock"}
|
domaines = {0: "Vente", 1: "Achat", 2: "Stock"}
|
||||||
|
types_reglement = {0: "Client", 1: "Fournisseur", 2: "Salarié"}
|
||||||
|
types_reg = {
|
||||||
|
0: "Aucun",
|
||||||
|
1: "Règlement",
|
||||||
|
2: "Escompte accordé",
|
||||||
|
3: "Effet encaissé",
|
||||||
|
4: "Effet impayé",
|
||||||
|
}
|
||||||
|
|
||||||
imputations = []
|
imputations = []
|
||||||
total_impute = 0.0
|
total_impute = 0.0
|
||||||
|
|
@ -440,65 +583,106 @@ def lire_reglement_detail(self, rg_no: int) -> Dict:
|
||||||
total_impute += montant_imp
|
total_impute += montant_imp
|
||||||
imputations.append(
|
imputations.append(
|
||||||
{
|
{
|
||||||
"re_no": imp[0],
|
"rg_no": imp[0],
|
||||||
"montant": montant_imp,
|
"montant": montant_imp,
|
||||||
"montant_devise": float(imp[2] or 0),
|
"dr_no": imp[2],
|
||||||
"document": {
|
"document": {
|
||||||
"domaine": domaines.get(imp[4], f"Domaine {imp[4]}")
|
"domaine": domaines.get(imp[3], f"Domaine {imp[3]}")
|
||||||
|
if imp[3] is not None
|
||||||
|
else None,
|
||||||
|
"type": types_doc.get(imp[4], f"Type {imp[4]}")
|
||||||
if imp[4] is not None
|
if imp[4] is not None
|
||||||
else None,
|
else None,
|
||||||
"type": types_doc.get(imp[5], f"Type {imp[5]}")
|
"numero": (imp[5] or "").strip() if imp[5] else None,
|
||||||
if imp[5] is not None
|
"date": imp[6].strftime("%Y-%m-%d") if imp[6] else None,
|
||||||
else None,
|
"total_ttc": float(imp[7] or 0) if imp[7] else None,
|
||||||
"numero": (imp[6] or "").strip() if imp[6] else None,
|
"montant_regle": float(imp[8] or 0) if imp[8] else None,
|
||||||
"date": imp[7].strftime("%Y-%m-%d") if imp[7] else None,
|
"reference": (imp[9] or "").strip() if imp[9] else None,
|
||||||
"total_ttc": float(imp[8] or 0) if imp[8] else None,
|
"tiers": (imp[10] or "").strip() if imp[10] else None,
|
||||||
"montant_regle": float(imp[9] or 0) if imp[9] else None,
|
|
||||||
"reference": (imp[10] or "").strip() if imp[10] else None,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
rg_montant = float(row[4] or 0)
|
rg_montant = float(row[5] or 0)
|
||||||
reste = rg_montant - total_impute
|
reste = rg_montant - total_impute
|
||||||
|
|
||||||
types_reglement = {0: "Client", 1: "Fournisseur", 2: "Salarié"}
|
heure_str = None
|
||||||
|
if row[19]:
|
||||||
|
try:
|
||||||
|
heure_str = (
|
||||||
|
row[19].strftime("%H:%M:%S")
|
||||||
|
if hasattr(row[19], "strftime")
|
||||||
|
else str(row[19])
|
||||||
|
)
|
||||||
|
except:
|
||||||
|
heure_str = str(row[19])
|
||||||
|
|
||||||
|
if total_impute == 0:
|
||||||
|
statut_imputation = "Non imputé"
|
||||||
|
elif abs(reste) < 0.01:
|
||||||
|
statut_imputation = "Totalement imputé"
|
||||||
|
else:
|
||||||
|
statut_imputation = "Partiellement imputé"
|
||||||
|
|
||||||
return {
|
return {
|
||||||
"rg_no": row[0],
|
"rg_no": row[0],
|
||||||
"numero_piece": (row[15] or "").strip(),
|
"numero_piece": (row[20] or "").strip(),
|
||||||
"date": row[1].strftime("%Y-%m-%d") if row[1] else None,
|
"date": row[2].strftime("%Y-%m-%d") if row[2] else None,
|
||||||
"reference": (row[2] or "").strip(),
|
"heure": heure_str,
|
||||||
"libelle": (row[3] or "").strip(),
|
"date_echeance_contrepartie": row[29].strftime("%Y-%m-%d")
|
||||||
|
if row[29]
|
||||||
|
else None,
|
||||||
|
"reference": (row[3] or "").strip(),
|
||||||
|
"libelle": (row[4] or "").strip(),
|
||||||
"montant": rg_montant,
|
"montant": rg_montant,
|
||||||
"montant_devise": float(row[5] or 0),
|
"montant_devise": float(row[6] or 0),
|
||||||
"montant_impute": total_impute,
|
"montant_impute": total_impute,
|
||||||
"reste_a_imputer": reste,
|
"reste_a_imputer": reste,
|
||||||
"statut_imputation": "Totalement imputé"
|
"montant_ecart": float(row[32] or 0),
|
||||||
if abs(reste) < 0.01
|
"montant_commission": float(row[36] or 0),
|
||||||
else ("Partiellement imputé" if total_impute > 0 else "Non imputé"),
|
"montant_net": float(row[37] or 0),
|
||||||
"est_comptabilise": row[7] == 1,
|
"cours": float(row[12] or 1),
|
||||||
"type_code": row[8],
|
"statut_imputation": statut_imputation,
|
||||||
"type_libelle": types_reglement.get(row[8], f"Type {row[8]}"),
|
"est_impute": row[8] == 1,
|
||||||
"client_code": (row[13] or "").strip(),
|
"est_comptabilise": row[9] == 1,
|
||||||
"client_intitule": (row[22] or "").strip(),
|
"est_impaye": row[16] == 1,
|
||||||
|
"est_transfere": row[24] == 1,
|
||||||
|
"est_cloture": row[25] == 1,
|
||||||
|
"est_valide": row[34] == 1,
|
||||||
|
"est_anterieur": row[35] == 1,
|
||||||
|
"type_code": row[11],
|
||||||
|
"type_libelle": types_reglement.get(row[11], f"Type {row[11]}"),
|
||||||
|
"type_reg_code": row[18],
|
||||||
|
"type_reg_libelle": types_reg.get(row[18], f"TypeReg {row[18]}"),
|
||||||
|
"client_code": (row[1] or "").strip(),
|
||||||
|
"client_intitule": (row[41] or "").strip(),
|
||||||
|
"client_origine": (row[28] or "").strip(),
|
||||||
"journal_code": (row[14] or "").strip(),
|
"journal_code": (row[14] or "").strip(),
|
||||||
"journal_intitule": (row[23] or "").strip(),
|
"journal_intitule": (row[42] or "").strip(),
|
||||||
"mode_reglement_code": row[16],
|
"compte_general": (row[17] or "").strip(),
|
||||||
|
"compte_contrepartie": (row[15] or "").strip(),
|
||||||
|
"compte_ecart": (row[30] or "").strip(),
|
||||||
|
"journal_ecart": (row[31] or "").strip(),
|
||||||
|
"mode_reglement_code": row[7],
|
||||||
"mode_reglement_libelle": (
|
"mode_reglement_libelle": (
|
||||||
row[24] or ModeReglement.get_libelle(row[16] or 0)
|
row[43] or ModeReglement.get_libelle(row[7] or 0)
|
||||||
).strip(),
|
).strip()
|
||||||
"compte_contrepartie": (row[17] or "").strip(),
|
if row[43]
|
||||||
"cours": float(row[9] or 1),
|
else ModeReglement.get_libelle(row[7] or 0),
|
||||||
"banque": (row[10] or "").strip(),
|
"devise_code": row[13],
|
||||||
"impaye": row[11] == 1,
|
"devise_intitule": (row[44] or "").strip() if row[44] else "",
|
||||||
"ecart": float(row[12] or 0),
|
"banque": (row[23] or "").strip(),
|
||||||
"cloture": row[18] == 1,
|
"caisse_no": row[21],
|
||||||
"ticket": (row[19] or "").strip(),
|
"caissier_no": row[22],
|
||||||
"date_creation": row[20].strftime("%Y-%m-%d %H:%M:%S") if row[20] else None,
|
"echeancier_no": row[10],
|
||||||
"date_modification": row[21].strftime("%Y-%m-%d %H:%M:%S")
|
"ticket": (row[26] or "").strip(),
|
||||||
if row[21]
|
"souche": row[27],
|
||||||
|
"bon_achat_no": row[33],
|
||||||
|
"date_creation": row[38].strftime("%Y-%m-%d %H:%M:%S") if row[38] else None,
|
||||||
|
"date_modification": row[39].strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
if row[39]
|
||||||
else None,
|
else None,
|
||||||
|
"createur": (row[40] or "").strip() if row[40] else None,
|
||||||
"nb_imputations": len(imputations),
|
"nb_imputations": len(imputations),
|
||||||
"imputations": imputations,
|
"imputations": imputations,
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue