Commit b18ce509 authored by plb's avatar plb
Browse files

Prise en compte des cotisations sociales

parent c1ff4ce0
......@@ -65,6 +65,7 @@ def do_mysql(options):
bank_entries = dolibarr.get_bank_entries()
sell_entries = dolibarr.get_sell_entries()
supplier_entries = dolibarr.get_supplier_entries()
social_entries = dolibarr.get_social_entries()
dolibarr.disconnect()
......@@ -73,6 +74,7 @@ def do_mysql(options):
pc_missing.update(bank_entries.check_pc())
pc_missing.update(sell_entries.check_pc())
pc_missing.update(supplier_entries.check_pc())
pc_missing.update(social_entries.check_pc())
if len(pc_missing) > 0:
print "WARNING: poste comptable manquant"
for pc in pc_missing:
......@@ -82,6 +84,7 @@ def do_mysql(options):
Writer.write("bank",bank_entries)
Writer.write("sells",sell_entries)
Writer.write("suppliers",supplier_entries)
Writer.write("social",social_entries)
Writer.write_hreport_plan()
def main(argv):
......
......@@ -10,17 +10,21 @@ import os
import codecs
MYSQL_QUERIES = {
"bank": "SELECT DISTINCT b.rowid as b_rowid, ba.ref as ba_ref, ba.label as ba_label, ba.account_number as ba_account_number, b.datev as b_datev, b.dateo as b_dateo, b.label as b_label, b.num_chq as b_num_chq, -b.amount as _b_amount, b.amount as b_amount, b.num_releve as b_num_releve, b.datec as b_datec, bu.url_id as bu_url_id, s.nom as s_nom, s.code_compta as s_code_compta, s.code_compta_fournisseur as s_code_compta_fournisseur, bca.label as bca_label, bca.rowid as bca_rowid, bcl.lineid as bcl_lineid FROM (llx_bank_account as ba, llx_bank as b) LEFT JOIN llx_bank_url as bu ON (bu.fk_bank = b.rowid AND bu.type = 'company') LEFT JOIN llx_societe as s ON bu.url_id = s.rowid LEFT JOIN llx_bank_class as bcl ON bcl.lineid = b.rowid LEFT JOIN llx_bank_categ as bca ON bca.rowid = bcl.fk_categ WHERE ba.rowid = b.fk_account AND ba.entity = 1 and b.num_releve <> '' ORDER BY b.datev, b.num_releve",
# "bank": "SELECT DISTINCT b.rowid as b_rowid, ba.ref as ba_ref, ba.label as ba_label, ba.account_number as ba_account_number, b.datev as b_datev, b.dateo as b_dateo, b.label as b_label, b.num_chq as b_num_chq, -b.amount as _b_amount, b.amount as b_amount, b.num_releve as b_num_releve, b.datec as b_datec, bu.url_id as bu_url_id, s.nom as s_nom, s.code_compta as s_code_compta, s.code_compta_fournisseur as s_code_compta_fournisseur, bca.label as bca_label, bca.rowid as bca_rowid, bcl.lineid as bcl_lineid FROM (llx_bank_account as ba, llx_bank as b) LEFT JOIN llx_bank_url as bu ON (bu.fk_bank = b.rowid AND bu.type = 'company') LEFT JOIN llx_societe as s ON bu.url_id = s.rowid LEFT JOIN llx_bank_class as bcl ON bcl.lineid = b.rowid LEFT JOIN llx_bank_categ as bca ON bca.rowid = bcl.fk_categ WHERE ba.rowid = b.fk_account AND ba.entity = 1 and b.num_releve <> '' ORDER BY b.datev, b.num_releve",
"bank": "SELECT DISTINCT b.rowid as b_rowid, ba.ref as ba_ref, ba.label as ba_label, ba.account_number as ba_account_number, b.datev as b_datev, b.dateo as b_dateo, b.label as b_label, b.num_chq as b_num_chq, -b.amount as _b_amount, b.amount as b_amount, b.num_releve as b_num_releve, b.datec as b_datec, bu.url_id as bu_url_id, s.nom as s_nom, s.code_compta as s_code_compta, s.code_compta_fournisseur as s_code_compta_fournisseur, bca.label as bca_label, bca.rowid as bca_rowid, bcl.lineid as bcl_lineid, ccs.code as ccs_code, ccs.libelle as ccs_label FROM (llx_bank_account as ba, llx_bank as b) LEFT JOIN llx_bank_url as bu ON (bu.fk_bank = b.rowid AND bu.type = 'company') LEFT JOIN llx_societe as s ON bu.url_id = s.rowid LEFT JOIN llx_bank_class as bcl ON bcl.lineid = b.rowid LEFT JOIN llx_bank_categ as bca ON bca.rowid = bcl.fk_categ LEFT JOIN llx_paiementcharge as p ON p.fk_bank = b.rowid LEFT JOIN llx_chargesociales as cs ON cs.rowid = p.fk_charge LEFT JOIN llx_c_chargesociales as ccs ON cs.fk_type = ccs.id WHERE ba.rowid = b.fk_account AND ba.entity = 1 and b.num_releve <> '' ORDER BY b.datev, b.num_releve;",
"sells": "SELECT DISTINCT s.rowid as s_rowid, s.nom as s_nom, s.address as s_address, s.zip as s_zip, s.town as s_town, c.code as c_code, s.phone as s_phone, s.siren as s_siren, s.siret as s_siret, s.ape as s_ape, s.idprof4 as s_idprof4, s.code_compta as s_code_compta, s.code_compta_fournisseur as s_code_compta_fournisseur, s.tva_intra as s_tva_intra, f.rowid as f_rowid, f.facnumber as f_facnumber, f.datec as f_datec, f.datef as f_datef, f.date_lim_reglement as f_date_lim_reglement, f.total as f_total, f.total_ttc as f_total_ttc, f.tva as f_tva, f.paye as f_paye, f.fk_statut as f_fk_statut, f.note_private as f_note_private, f.note_public as f_note_public, fd.rowid as fd_rowid, fd.label as fd_label, fd.description as fd_description, fd.subprice as fd_subprice, fd.tva_tx as fd_tva_tx, fd.qty as fd_qty, fd.total_ht as fd_total_ht, fd.total_tva as fd_total_tva, fd.total_ttc as fd_total_ttc, fd.date_start as fd_date_start, fd.date_end as fd_date_end, fd.special_code as fd_special_code, fd.product_type as fd_product_type, fd.fk_product as fd_fk_product, p.ref as p_ref, p.label as p_label, p.accountancy_code_sell as p_accountancy_code_sell, a.account_number as a_account_number FROM llx_societe as s LEFT JOIN llx_c_pays as c on s.fk_pays = c.rowid, llx_facture as f LEFT JOIN llx_facture_extrafields as extra ON f.rowid = extra.fk_object , llx_facturedet as fd LEFT JOIN llx_product as p on (fd.fk_product = p.rowid) LEFT JOIN llx_accountingaccount as a ON fd.fk_code_ventilation = a.rowid WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture AND f.entity = 1",
"suppliers": "SELECT DISTINCT s.rowid as s_rowid, s.nom as s_nom, s.address as s_address, s.zip as s_zip, s.town as s_town, s.code_compta_fournisseur as s_code_supplier, c.code as c_code, s.phone as s_phone, s.siren as s_siren, s.siret as s_siret, s.ape as s_ape, s.idprof4 as s_idprof4, s.idprof5 as s_idprof5, s.idprof6 as s_idprof6, s.tva_intra as s_tva_intra, f.rowid as f_rowid, f.ref as f_ref, f.ref_supplier as f_ref_supplier, f.datec as f_datec, f.datef as f_datef, f.total_ht as f_total_ht, f.total_ttc as f_total_ttc, f.total_tva as f_total_tva, f.paye as f_paye, f.fk_statut as f_fk_statut, f.note_public as f_note_public, fd.rowid as fd_rowid, fd.description as fd_description, fd.tva_tx as fd_tva_tx, fd.qty as fd_qty, fd.remise_percent as fd_remise_percent, fd.total_ht as fd_total_ht, fd.total_ttc as fd_total_ttc, fd.tva as fd_tva, fd.product_type as fd_product_type, fd.fk_product as fd_fk_product, p.ref as p_ref, p.label as p_label, p.accountancy_code_buy as p_accountancy_code_buy, a.account_number as a_account_number FROM llx_societe as s LEFT JOIN llx_c_pays as c ON s.fk_pays = c.rowid, llx_facture_fourn as f LEFT JOIN llx_facture_fourn_extrafields as extra ON f.rowid = extra.fk_object , llx_facture_fourn_det as fd LEFT JOIN llx_product as p on (fd.fk_product = p.rowid) LEFT JOIN llx_accountingaccount as a ON fd.fk_code_ventilation = a.rowid WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture_fourn AND f.entity = 1",
"social": "SELECT DISTINCT cc.libelle as cc_libelle, c.rowid as c_rowid, c.libelle as c_libelle, c.date_ech as c_date_ech, c.periode as c_periode, c.amount as c_amount, c.paye as c_paye, p.rowid as p_rowid, p.datep as p_datep, p.amount as p_amount, p.num_paiement as p_num_paiement, cc.accountancy_code as cc_acc_code, cc.code as cc_code FROM llx_c_chargesociales as cc, llx_chargesociales as c LEFT JOIN llx_paiementcharge as p ON p.fk_charge = c.rowid WHERE c.fk_type = cc.id AND c.entity = 1",
}
class Entry(object):
accounting_years = settings.get('ACCOUNTING_YEARS')
pc_default_tiers = settings.get('PC_REFS')['default_tiers']
pc_default_client = settings.get('PC_REFS')['default_client']
pc_default_supplier = settings.get('PC_REFS')['default_supplier']
pc_default_produit = settings.get('PC_REFS')['default_produit']
......@@ -92,19 +96,40 @@ class BankEntry(Entry):
3: 'supplier',
4: 'supplier',
5: 'client',
'': 'client',
'': None
}
supplier_or_client = supplier_or_client_by_bca_rowid[self.cells['bca_rowid']]
print (self.cells['b_label'],self.cells['b_num_releve'],self.cells['b_datev'],self.cells['bca_label'],self.cells['s_nom'],self.cells['b_amount'])
if supplier_or_client == "client":
#entry_type = entry_type_by_bca_rowid[self.cells['bca_rowid']]
entry_type = None
if entry_type is None:
if self.cells['b_label'] == "(SupplierInvoicePayment)":
entry_type = "supplier"
elif self.cells['b_label'] == "(CustomerInvoicePayment)":
entry_type = "client"
elif self.cells['b_label'] == "Règlement client":
entry_type = "client"
elif self.cells['b_label'] == "Solde initial":
entry_type = ""
elif self.cells['b_label'] == "Souscription part sociale":
entry_type = "client"
elif self.cells['b_label'] == "(SocialContributionPayment)":
entry_type = "social"
else:
print "Impossible de déterminer sur l'écriture est sur un compte fournisseur ou client"
print self.cells
if entry_type == "client":
third_code = self.cells['s_code_compta']
if third_code == "":
third_code = self.pc_default_client
else:
elif entry_type == "supplier":
third_code = self.cells['s_code_compta_fournisseur']
if third_code == "":
third_code = self.pc_default_supplier
elif entry_type == "social":
third_code = SocialEntry.get_third_code(self.cells['ccs_code'])
else:
third_code = self.pc_default_tiers
return third_code
......@@ -237,9 +262,9 @@ class Sell(Entry):
}
if float(self.cells['f_tva']) != 0:
tva_deductible_account = settings.get('PC_REFS')['tva_deductible']
s += " %(compte_tva_deductible)s %(amount_tva)s\n" % {
'compte_tva_deductible': settings.get_ledger_account(tva_deductible_account),
tva_account = settings.get('PC_REFS')['tva_collecte']
s += " %(compte_tva_collecte)s %(amount_tva)s\n" % {
'compte_tva_collecte': settings.get_ledger_account(tva_account),
'amount_tva': self.cells['f_tva'],
}
......@@ -368,9 +393,9 @@ class Supplier(Entry):
}
if self.cells['f_total_tva'] != 0:
tva_deductible_account = settings.get('PC_REFS')['tva_collecte']
s += " %(compte_tva_deductible)s %(amount_tva)s\n" % {
'compte_tva_deductible': settings.get_ledger_account(tva_deductible_account),
tva_account = settings.get('PC_REFS')['tva_deductible']
s += " %(compte_tva)s %(amount_tva)s\n" % {
'compte_tva': settings.get_ledger_account(tva_account),
'amount_tva': -self.cells['f_total_tva'],
}
......@@ -432,6 +457,70 @@ class SupplierEntry(Entry):
return p_code
class SocialEntry(Entry):
@staticmethod
def get_third_code(code):
third_code = None
if code in settings.get('SOCIAL_REFS'):
third_code = settings.get('SOCIAL_REFS')[code]
else:
third_code = SocialEntry.pc_default_supplier
return third_code
@staticmethod
def get_s_code(code):
s_code = None
if code is None:
s_code = SocialEntry.pc_default_charge
else:
s_code = code
return s_code
@staticmethod
def clean(row):
return True
def addEntry(self, entry):
pass
def get_year(self):
return self.get_accounting_year('c_periode')
def getMissingPC(self):
pc_missing = []
if self.get_s_code(self.cells['cc_acc_code']) == self.pc_default_charge:
pc_missing.append("charges: %s" % (self.cells['cc_libelle']))
if self.get_third_code(self.cells['cc_code']) == self.pc_default_supplier:
pc_missing.append("tiers: %s (%s)" % (self.cells['c_libelle'], self.cells['cc_code']))
return pc_missing
def get_ledger(self):
s = ""
s += "%(date)s %(description)s\n" % {
'date': self.cells['c_periode'].strftime("%Y/%m/%d"),
'description': self.cells['c_libelle'] + " - " + self.cells['cc_libelle']
}
amount = self.cells['c_amount']
third_code = self.get_third_code(self.cells['cc_code'])
s_code = self.get_s_code(self.cells['cc_acc_code'])
s += " %(account)s \t %(amount)s\n" % {
'account': settings.get_ledger_account(third_code),
'amount': amount
}
s += " %(account)s \t %(amount)s\n" % {
'account': settings.get_ledger_account(s_code),
'amount': -amount
}
return s
class DolibarrSQL(object):
......@@ -467,6 +556,9 @@ class DolibarrSQL(object):
def get_supplier_entries(self):
return self.get_entries(self.queries['suppliers'], 'f_rowid', Supplier)
def get_social_entries(self):
return self.get_entries(self.queries['social'], 'c_rowid', SocialEntry)
def get_entries(self, query, index, entry_class):
cur = self.cnx.cursor(cursorclass=mdb.cursors.DictCursor)
cur.execute(query)
......@@ -489,7 +581,7 @@ class Writer(object):
filename = Writer.output_files[journal]
output = os.path.join(Writer.output_dir, filename)
entries_by_year = entries.get_by_year()
for year in entries_by_year:
output_file = output.replace("%year%", year)
output_dir = os.path.dirname(output_file)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment