home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Freelog Special Freeware 31
/
FreelogHS31.iso
/
ArgentCompta
/
Bankperfect
/
bp.exe
/
Scripts
/
Scheduler
/
scheduler_add.py
< prev
next >
Wrap
Text File
|
2005-07-15
|
3KB
|
110 lines
#Version 1.1
import BP, cPickle, time
data_path = "%sScripts\\Scheduler\\scheduler.dat" %BP.BankPerfectExePath()
modes = ["Carte", "Retrait DAB", "ChΦque Θmis", "PrΘlΦvement", "Virement Θmis", "TIP", "Versement", "DΘp⌠t de chΦque", "Virement reτu"]
def days_of_month(y, m):
is_leap_year = (y % 4 == 0) and (y % 100 != 0 or y % 400 == 0)
days = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
if m == 2 and is_leap_year: return 29
else: return days[m - 1]
def add_years(date, delta):
y, m, d = date
return y + delta, m, d
def add_days(date, delta):
stamp = date2stamp(date)
return stamp2date(stamp + 86400 * delta)
def add_months(date, delta):
y, m, d = date
is_last_day = days_of_month(y, m) == d
m += delta
if delta > 0:
while m > 12: y += 1; m -= 12
elif delta < 0:
while m < 1: y -= 1; m += 12;
last_day = days_of_month(y, m)
if is_last_day or d > last_day: return y, m, last_day
else: return y, m, d
def is_last_day_of_month(date):
y, m, d = date
days = days_of_month(y, m)
return d == days
def date2stamp(date):
return time.mktime(date + (3, 0, 0, 0, 0, 0))
def stamp2date(stamp):
return time.gmtime(stamp)[:3]
def add_to_date(date, delta, unit):
if unit == 0: #jours
return add_days(date, delta)
elif unit == 1: #mois
return add_months(date, delta)
else: #annΘes
return add_years(date, delta)
def str_to_date(date):
l = date.replace("/", "-").split("-")
return int(l[2]), int(l[1]), int(l[0])
def save_file():
global data_path
f = open(data_path, "wb")
cPickle.dump(files, f, 1)
f.close()
def extract_file_name(path):
while path.find("\\") > -1:
path = path[path.find("\\") + 1:]
return path
#_______________________________________________________________________________
try:
f = open(data_path, "rb")
files = cPickle.load(f)
f.close()
except:
files = {}
filename = extract_file_name(BP.BankPerfectFileName())
if files.has_key(filename): records = files[filename]
else:
records = []
files[filename] = records
account_index = BP.AccountCurrent()
line_index = BP.LineSelect(-1)
record = {}
date = str_to_date(BP.OperationDate[account_index][line_index])
record["nextdate"] = add_to_date(date, 1, 1)
record["tiers"] = BP.Operationthirdparty[account_index][line_index]
record["details"] = BP.OperationDetails[account_index][line_index]
record["categ"] = BP.OperationCateg[account_index][line_index]
record["montant"] = BP.OperationAmount[account_index][line_index]
record["autoinsert"] = 1
record["account"] = account_index
record["delta"] = 1
record["deltaunit"] = 1
record["enddate"] = (0, 0, 0)
m = BP.OperationMode[account_index][line_index]
try:
record["mode"] = modes.index(m)
except:
if record["montant"] > 0: record["mode"] = 8
else: record["mode"] = 3
records.append(record)
save_file()
BP.MsgBox("L'opΘration a ΘtΘ ajoutΘe α l'ΘchΘancier.", 0)