[Idées ]
Ecrit en Python grâce à Python For BankPerfect, ce petit script vous permet d'ajuster votre solde très simplement.
Il rajoute une opération du bon montant afin de faire coincider votre solde BP avec votre solde réel. Pratique aussi pour faire un point sur les espèces.

Utilisation :
* Champs Tiers & Détails configurables :
Vous pouvez maintenant renseigner (et sauvegarder) le Tiers et le Détail et y ajouter les informations de l'opération courante ou du solde :
Exemple :
tiers = "Solde au ^d (précédent : ^sp, nouveau : ^s)" detail = "^c au ^d de ^m euros"
Historique :
Pour en discuter : Le sujet sur le forum
#===============================================================================
# Ajustement du solde
# Auteur : Fabrice VADO
# Date : 14-05-2008
#-------------------------------------------------------------------------------
# Historique :
# 0.8 : Affichage des catégories au format BP 6 + modification du compte sélectionné
# 0.7 : Date de référence du solde + fermeture sur X
# 0.6 : Mode de paiement selon le signe de l'ajustement
# 0.5 : Sélection du solde (Pointé, Non Pointé, Tout)
# 0.4 : Choix de la catégorie, Détail & Tiers configurables, Configuration
# 0.3 : Gestion des espaces et de la virgule dans le nouveau solde
# 0.2 : Date du jour + valeur absolue du montant de l'opération
# 0.1 : 1ere release
#-------------------------------------------------------------------------------
script_version = "0.8"
script_name = "Ajuster Solde"
script_url = "https://chelly.net/bp_plugins/download/bpp_ajustersolde.exe"
#-------------------------------------------------------------------------------
# Configurez les valeurs suivantes selon vos souhaits
# ^d = Date de l'opération
# ^c = Catégorie
# ^m = Montant de l'opération
# ^s = Nouveau Solde
# ^sp = Solde précédent
op_tiers = "=> Solde au ^d (précédent : ^sp)"
op_detail = "Ajustement le ^d de ^m euros"
#===============================================================================
#_______________________________________________________________________________
import BP, time
# Valeurs globales par défaut de l'opération
op_amount = 0.00
op_date = time.strftime('%d-%m-%Y',time.localtime())
op_categ = 0
op_categorie = ""
# Variables liées au compte
ac_current = BP.AccountCurrent()
ac_balance = 0.00
new_balance = 0.00
ac_pointage = 2
ac_date_solde = BP.OperationDate[ac_current][0]
# Fichier de configuration
exe_path = BP.BankPerfectExePath()
file_name = BP.BankPerfectFileName()
file_name = file_name[file_name.rfind("\\") + 1:-3]
categs_path = exe_path + "Scripts\\Ajuster Solde\\%s.dat" %file_name
try:
inilines = open(categs_path, "r").readlines()
inilines = [l.strip() for l in inilines if l.strip() != ""]
except:
inilines = [op_tiers, op_detail]
op_tiers = inilines[0]
op_detail = inilines[1]
#____ CONSTANTES _______________________________________________________________
MB_OK = 0x00000000
MB_OKCANCEL = 0x00000001
MB_ABORTRETRYIGNORE = 0x00000002
MB_YESNOCANCEL = 0x00000003
MB_YESNO = 0x00000004
MB_RETRYCANCEL = 0x00000005
MB_ICONWARNING = 0x00000030
MB_ICONINFORMATION = 0x00000040
MB_ICONQUESTION = 0x00000020
MB_ICONSTOP = 0x00000010
ID_OK = 1
ID_CANCEL = 2
ID_ABORT = 3
ID_RETRY = 4
ID_IGNORE = 5
ID_YES = 6
ID_NO = 7
ID_CLOSE = 8
ID_HELP = 9
ID_TRYAGAIN = 10
ID_CONTINUE = 11
#_______________________________________________________________________________
def parse(value):
lines = value.replace("\r\n", "\n").replace("\r", "\n").split("\n")
d = {}
for line in lines:
i = line.find("=")
d[line[:i]] = line[i + 1:]
return d
#_______________________________________________________________________________
def Date2Int(date):
datetmp = date.split("-")
datetmp = int(datetmp[2] + datetmp[1] + datetmp[0])
return datetmp
def BPAccountBalance(account):
solde = 0.00
i = 0
while i < BP.OperationCount[account]:
if Date2Int(BP.OperationDate[account][i]) >= Date2Int(ac_date_solde):
op_pointage = BP.OperationMark[account][i]
if ac_pointage == 0 and op_pointage == 0:
solde += BP.OperationAmount[account][i]
elif ac_pointage == 1 and op_pointage > 0:
solde += BP.OperationAmount[account][i]
elif ac_pointage == 2:
solde += BP.OperationAmount[account][i]
i += 1
return solde
#_______________________________________________________________________________
def OpReplace(champ):
text = champ.replace("^d", op_date).replace("^c", op_categorie).replace("^m", str(abs(op_amount)))
text = text.replace("^sp", str(ac_balance)).replace("^s", str(new_balance))
return text
#_______________________________________________________________________________
def save_ini():
open(categs_path, "w").write("%s\n%s" %(op_tiers, op_detail))
#_______________________________________________________________________________
if BP.BankPerfectFileName() == "":
BP.MsgBox("Il n'y a pas de fichier BankPerfect ouvert", 0)
else:
# Fenêtre générée par designer de forms
# Modification Edit.Color, Date.Date, combo.ItemIndex
form = """
label=Label1;Left=12;Top=12;Width=37;Height=13;Anchors=tl;Caption=Compte;Color=
label=Label2;Left=12;Top=96;Width=45;Height=13;Anchors=tl;Caption=Solde %s;Color=
label=Label3;Left=256;Top=12;Width=71;Height=13;Anchors=tl;Caption=Nouveau solde;Color=
label=Label4;Left=12;Top=124;Width=70;Height=13;Anchors=tl;Caption=Ajustement de;Color=
label=Label6;Left=256;Top=42;Width=23;Height=13;Anchors=tl;Caption=Tiers;Color=
label=Label5;Left=256;Top=96;Width=23;Height=13;Anchors=tl;Caption=Date;Color=
label=Label7;Left=256;Top=126;Width=47;Height=13;Anchors=tl;Caption=Catégorie;Color=
label=Label8;Left=256;Top=68;Width=27;Height=13;Anchors=tl;Caption=Détail;Color=
label=Label9;Left=12;Top=40;Width=87;Height=13;Anchors=tl;Caption=Inclure opérations;Color=
label=Label10;Left=12;Top=68;Width=88;Height=13;Anchors=tl;Caption=Date de référence;Color=
combo=comboAccount;Left=112;Top=8;Width=126;Height=21;Anchors=tl;Text=%s;Enabled=1;ItemIndex=%i
combo=comboPointage;Left=112;Top=36;Width=128;Height=21;Anchors=tl;Text=%s;Enabled=1;ItemIndex=%i
date=dateSolde;Left=112;Top=64;Width=130;Height=20;Anchors=tl;Date=%s;Enabled=1
edit=editBalance;Left=112;Top=92;Width=110;Height=21;Anchors=tl;Text=%f;Enabled=0;Readonly=1
edit=editNewBalance;Left=336;Top=8;Width=90;Height=21;Anchors=tl;Text=%f;Enabled=1;Readonly=0
edit=editAmount;Left=112;Top=120;Width=110;Height=21;Anchors=tl;Text=%f;Enabled=0;Readonly=1
edit=editTiers;Left=336;Top=36;Width=160;Height=21;Anchors=tl;Text=%s;Enabled=1;Readonly=0
edit=editDetail;Left=336;Top=64;Width=160;Height=21;Anchors=tl;Text=%s;Enabled=1;Readonly=0
date=dateAmount;Left=337;Top=93;Width=130;Height=20;Anchors=tl;Date=%s;Enabled=1
combo=comboCateg;Left=337;Top=122;Width=132;Height=21;Anchors=tl;Text=%s\\r\\n;Enabled=1;ItemIndex=%i
button=buttonRefresh;Left=216;Top=160;Width=56;Height=28;Anchors=tl;Caption=Rafraichir;Enabled=1;Default=1;Cancel=0
button=buttonCreer;Left=360;Top=160;Width=62;Height=28;Anchors=tl;Caption=Créer;Enabled=1;Default=0;Cancel=0
button=buttonQuit;Left=60;Top=160;Width=58;Height=28;Anchors=tl;Caption=Quitter;Enabled=1;Default=0;Cancel=1
"""
#<v 0.8>
none = "- Aucune -"
CPrt = BP.CategParent
cnames = BP.CategName
CTrimNames = []
CPositions = {-1: -1}
CIndexes = {-1: -1}
CNames = []
for i, c in enumerate(cnames):
p = c.find("=")
CNames.append(c[p+1:])
CTrimNames.append(c[p+1:].strip())
idx = int(c[:p])
CPositions[idx] = i
CIndexes[i] = idx
ccnames = [none] + [ ("%s > %s" %(CTrimNames[CPrt[i]], c), c)[CPrt[i] == i] for i, c in enumerate(CTrimNames)]
cnames = "\\r\\n".join([none] + CNames)
#</v 0.8>
lstpointage = ["Non pointées", "Pointées/Rap.", "Toutes" ]
strpointage = "\\r\\n".join(lstpointage) + "\\r\\n"
accounts = [BP.AccountName[i] for i in range(BP.AccountCount())]
accounts = "\\r\\n".join(accounts) + "\\r\\n"
lst_modes = [ BP.OperationGetNameFromModeIndex(i) for i in range( int( BP.GetURL("mode_count") ) ) ]
ac_balance = BPAccountBalance(ac_current)
bdisplay = True
while bdisplay:
params = (lstpointage[ac_pointage], accounts, ac_current, strpointage, ac_pointage, ac_date_solde, ac_balance, new_balance, op_amount, op_tiers, op_detail, op_date, cnames, op_categ)
result = parse(BP.CustomForm("Ajustement de solde %s" %script_version, form %params, 520, 230))
op_date = result["dateAmount"]
op_tiers = result["editTiers"]
op_categ = int(result["comboCateg"])
op_categorie = BP.CategName[int(op_categ)]
ac_current = int(result["comboAccount"])
ac_pointage = int(result["comboPointage"])
ac_date_solde = result["dateSolde"]
ac_balance = BPAccountBalance(ac_current)
# définit le nom du compte
ac_name = BP.AccountName[ac_current]
# définit la monnaie du compte
ac_currency = BP.AccountCurrency1[ac_current].split("|")
ac_currency = ac_currency[0]
sel_button = result["SelectedButton"]
# Nouveau solde saisi
if result["editNewBalance"] != "":
try:
new_balance = float(result["editNewBalance"].replace(" ", "").replace(",", "."))
except:
BP.MsgBox("Montant incorrect !", MB_ICONWARNING)
sel_button = ""
op_amount = new_balance - ac_balance
if op_amount < 0:
smode = lst_modes[4]
else:
smode = lst_modes[8]
# Action selon le bouton
if sel_button == "buttonCreer":
op_input = BP.MsgBox("La nouvelle opération aura un montant de %.2f %s\r\n\nVoulez-vous la créer dans le compte '%s' ?" %(abs(op_amount), ac_currency, ac_name), MB_YESNO)
if op_input == ID_YES:
if BP.LineAdd(ac_current, op_date, smode, OpReplace(op_tiers), OpReplace(op_detail), op_categ - 1, op_amount, 1) == 0:
BP.MsgBox("Erreur lors de la création de l'opération !", MB_ICONWARNING)
save_ini()
bdisplay = False
elif sel_button == "buttonQuit" or sel_button == "":
bdisplay = False
BP.AccountRefreshScreen()