# encoding: utf-8
-from decimal import Decimal
-
-import odf.opendocument
-import odf.style
-import odf.table
-from odf.style import Style, MasterPage, PageLayout, PageLayoutProperties, \
- TextProperties, GraphicProperties, ParagraphProperties, \
- DrawingPageProperties
-
-
-class Separator():
-
- def __unicode__(self):
- return u""
-
- def __str__(self):
- return ""
-
-
-def valuetype(val):
- valuetype = "string"
- if isinstance(val, str):
- valuetype = "string"
- if isinstance(val, (int, float, Decimal)):
- valuetype = "float"
- if isinstance(val, bool):
- valuetype = "boolean"
-
- return valuetype
-
-
-class Wrapper(object):
-
- def __init__(self, *args, **kwargs):
- self.__wrapped = self._wrapper_constructor(*args, **kwargs)
-
- def __getattr__(self, attr):
- return getattr(self.__wrapped, attr)
-
-
-class OpenDocumentSpreadsheet(Wrapper):
- _wrapper_constructor = staticmethod(
- odf.opendocument.OpenDocumentSpreadsheet
+import odsgen
+
+
+def masse_salariale(lignes, annee, titres_traitements, titres_indemnites,
+ titres_primes, titres_charges, masse_salariale_totale):
+ doc = odsgen.Document()
+ doc.add_iso_date_style('iso-date')
+
+ table = doc.add_table(name=u'Masse salariale')
+ for width in (
+ ['1.75cm', '5cm', '4cm', '3cm', '3.5cm', '5cm', '4cm', '6cm',
+ '14cm', '2.5cm', '1.5cm', '4.5cm', '3cm', '1.5cm', '3.75cm',
+ '0.5cm', '2.5cm', '2cm', '3cm', '0.5cm', '1.5cm', '4cm',
+ '3.25cm', '5cm', '0.5cm', '4.25cm'] +
+ ['5cm'] * len(titres_traitements) + ['4cm', '0.5cm'] +
+ ['5cm'] * len(titres_indemnites) + ['4cm', '0.5cm'] +
+ ['5cm'] * len(titres_primes) + ['4cm', '0.5cm'] +
+ ['5cm'] * len(titres_charges) + ['4cm', '0.5cm'] +
+ ['3.75cm'] * 4 + ['0.5cm', '2.75cm', '4cm']
+ ):
+ table.add_column(columnwidth=width)
+
+ row = table.add_row()
+ row.add_cells([
+ u'Bureau', u'Pays', u'Implantation', u'Valeur du point',
+ u"Numéro d'employé", u'Nom', u'Prénom', u'Type de poste',
+ u'Intitulé du poste', u'Niveau actuel', u'Points',
+ u'Régime de travail annuel', u'Local / Expatrié', u'Statut',
+ u'Date de fin de contrat'
+ ], fontweight='bold')
+ row.add_cell(backgroundcolor='#d3d3d3')
+ row.add_cells([
+ u'Date de début', u'Date de fin', u'Nombre de jours'
+ ], fontweight='bold')
+ row.add_cell(backgroundcolor='#d3d3d3')
+ row.add_cells([
+ u'Devise', u'Salaire BSTG ANNUEL', u'Salaire BSTG EUR',
+ u'Organisme BSTG'
+ ], fontweight='bold')
+ row.add_cell(backgroundcolor='#d3d3d3')
+ row.add_cells(
+ [u'Salaire théorique annuel'] + titres_traitements +
+ [u'Total des traitements'],
+ backgroundcolor='#ecab44', fontweight='bold'
+ )
+ row.add_cell(backgroundcolor='#d3d3d3')
+ row.add_cells(
+ titres_indemnites + [u'Total des indemnités'],
+ backgroundcolor='#fff840', fontweight='bold'
+ )
+ row.add_cell(backgroundcolor='#d3d3d3')
+ row.add_cells(
+ titres_primes + [u'Total des primes'],
+ backgroundcolor='#d7fb0f', fontweight='bold'
+ )
+ row.add_cell(backgroundcolor='#d3d3d3')
+ row.add_cells(
+ titres_charges + [u'Total des charges'],
+ backgroundcolor='#fb680f', fontweight='bold'
+ )
+ row.add_cell(backgroundcolor='#d3d3d3')
+ row.add_cell(
+ u'Total des traitements', backgroundcolor='#ecab44',
+ fontweight='bold'
+ )
+ row.add_cell(
+ u'Total des indemnités', backgroundcolor='#fff840',
+ fontweight='bold'
+ )
+ row.add_cell(
+ u'Total des primes', backgroundcolor='#d7fb0f',
+ fontweight='bold'
+ )
+ row.add_cell(
+ u'Total des charges', backgroundcolor='#fb680f',
+ fontweight='bold'
+ )
+ row.add_cell(backgroundcolor='#d3d3d3')
+ row.add_cells(
+ [u'Masse salariale', u'Masse salariale EUR'],
+ backgroundcolor='#e6c6ed', fontweight='bold'
)
- def __init__(self, *args, **kwargs):
- super(OpenDocumentSpreadsheet, self).__init__(*args, **kwargs)
- self._automatic_style_idx = 0
-
- def add_table(self, **kwargs):
- table = Table(**kwargs)
- table._doc = self
- self.spreadsheet.addElement(table)
- return table
-
- def add_automatic_style(self, **kwargs):
- name = 'auto_style_%d' % self._automatic_style_idx
- style = odf.style.Style(name=name, **kwargs)
- self.automaticstyles.addElement(style)
- self._automatic_style_idx += 1
- return style
-
-
-class Table(Wrapper):
- _wrapper_constructor = staticmethod(odf.table.Table)
-
- def add_row(self, values=[], **kwargs):
- # attributs appartenant à table-column-poperties
-# props = {}
-# for attr in ['rowheight']:
-# if attr in kwargs:
-# props[attr] = kwargs.pop(attr)
-
- style = self._doc.add_automatic_style(family='table-row')
- if 'rowheight' in kwargs:
- style.addElement(odf.style.TableRowProperties(
- rowheight=kwargs['rowheight']))
- kwargs['stylename'] = style.getAttribute('name')
- del kwargs['rowheight']
-
- style = {}
-
- row = TableRow(**kwargs)
- row._doc = self._doc
- for value in values:
- row.add_cell(value, verticalalign='middle', **style)
- self.addElement(row)
- return row
-
- def add_column(self, **kwargs):
-
- # attributs appartenant à table-column-poperties
- props = {}
- for attr in ['columnwidth']:
- if attr in kwargs:
- props[attr] = kwargs.pop(attr)
-
- if props:
- style = self._doc.add_automatic_style(family='table-column')
- style.addElement(odf.style.TableColumnProperties(**props))
- kwargs['stylename'] = style.getAttribute('name')
- col = odf.table.TableColumn(**kwargs)
- self.addElement(col)
- return col
-
-
-class TableRow(Wrapper):
- _wrapper_constructor = staticmethod(odf.table.TableRow)
-
- def add_cell(self, value=None, **kwargs):
- if value:
- if isinstance(value, (basestring, unicode)):
- kwargs['stringvalue'] = unicode(value)
- elif isinstance(value, (int, float, Decimal)):
- kwargs['valuetype'] = "float"
- kwargs['value'] = float(value)
- elif type(value) == type(None) or isinstance(value, Separator):
- kwargs['stringvalue'] = u""
- else:
- kwargs['stringvalue'] = unicode(value)
-
- style = self._doc.add_automatic_style(family='table-cell')
- if 'verticalalign' in kwargs:
- style.addElement(odf.style.TableCellProperties(
- verticalalign=kwargs['verticalalign'], wrapoption='wrap'))
- del kwargs['verticalalign']
-
- if isinstance(value, Separator) or type(value) == type(Separator()):
- style.addElement(odf.style.TableCellProperties(
- backgroundcolor='#D3D3D3'))
-
- kwargs['stylename'] = style.getAttribute('name')
-# props = {}
-# if 'fontweight' in kwargs:
-# props['fontweight'] = kwargs.pop('fontweight')
-# if 'stringvalue' in kwargs:
-# props['stringvalue'] = kwargs.pop('stringvalue')
-
- cell = odf.table.TableCell(**kwargs)
-# if 'fontweight' in props:
-# tablecontents = Style(name="Bold", family="paragraph")
-# tablecontents.addElement(TextProperties(fontweight="bold"))
-# self._doc.styles.addElement(tablecontents)
-
-# if 'stringvalue' in props:
-# p = P(stylename='Bold',text=props['stringvalue'])
-# cell.addElement(p)
-
- self.addElement(cell)
- return cell
+ for ligne in lignes:
+ row = table.add_row()
+ row.add_cells([
+ ligne['poste'].implantation.region.code,
+ ligne['poste'].implantation.adresse_physique_pays.nom,
+ ligne['poste'].implantation.nom_court
+ ])
+ row.add_cell(ligne['valeur_point'], decimalplaces=2)
+ row.add_cells([
+ ligne['dossier'].employe.id or 'VACANT',
+ ligne['dossier'].employe.nom,
+ ligne['dossier'].employe.prenom,
+ ligne['poste'].type_poste.nom,
+ ligne['poste'].nom,
+ unicode(ligne['dossier'].classement),
+ ligne['dossier'].classement
+ and ligne['dossier'].classement.coefficient,
+ ligne['regime_travail'],
+ ligne['local_expatrie'],
+ ligne['dossier'].statut.code,
+ ])
+ row.add_cell(ligne['dossier'].date_fin, datastylename='iso-date')
+ row.add_cell(backgroundcolor='#d3d3d3')
+ row.add_cells([
+ ligne['date_debut'], ligne['date_fin']
+ ], datastylename='iso-date')
+ row.add_cell(ligne['jours'])
+ row.add_cell(backgroundcolor='#d3d3d3')
+ row.add_cell(ligne['devise'])
+ row.add_cells([
+ ligne['salaire_bstg'], ligne['salaire_bstg_eur']
+ ], decimalplaces=2)
+ row.add_cell(
+ ligne['dossier'].organisme_bstg
+ and ligne['dossier'].organisme_bstg.nom,
+ )
+ row.add_cell(backgroundcolor='#d3d3d3')
+ row.add_cells(
+ [ligne['salaire_theorique']] + ligne['traitements'] +
+ [ligne['total_traitements']],
+ decimalplaces=2
+ )
+ row.add_cell(backgroundcolor='#d3d3d3')
+ row.add_cells(
+ ligne['indemnites'] + [ligne['total_indemnites']],
+ decimalplaces=2
+ )
+ row.add_cell(backgroundcolor='#d3d3d3')
+ row.add_cells(
+ ligne['primes'] + [ligne['total_primes']],
+ decimalplaces=2
+ )
+ row.add_cell(backgroundcolor='#d3d3d3')
+ row.add_cells(
+ ligne['charges'] + [ligne['total_charges']],
+ decimalplaces=2
+ )
+ row.add_cell(backgroundcolor='#d3d3d3')
+ row.add_cells([
+ ligne['total_traitements'], ligne['total_indemnites'],
+ ligne['total_primes'], ligne['total_charges']
+ ], decimalplaces=2)
+ row.add_cell(backgroundcolor='#d3d3d3')
+ row.add_cells([
+ ligne['masse_salariale'], ligne['masse_salariale_eur']
+ ], decimalplaces=2)
+ return doc