From f43d86b22de3bd2b4587af60f17677d6ffa50e2b Mon Sep 17 00:00:00 2001
From: Kevin Deldycke <kevin@nexedi.com>
Date: Thu, 26 Oct 2006 09:09:58 +0000
Subject: [PATCH] Print total payment on PDF. Format PDF values according
 currency/

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@10950 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../PaySheetTransaction_getDetails.xml        | 61 +++++++++++++++++--
 ...ansaction_viewPaySheetTransactionAsPDF.xml | 27 +++++++-
 2 files changed, 81 insertions(+), 7 deletions(-)

diff --git a/bt5/erp5_payroll/SkinTemplateItem/portal_skins/erp5_payroll/PaySheetTransaction_getDetails.xml b/bt5/erp5_payroll/SkinTemplateItem/portal_skins/erp5_payroll/PaySheetTransaction_getDetails.xml
index bb4c04700c..2eddb90983 100644
--- a/bt5/erp5_payroll/SkinTemplateItem/portal_skins/erp5_payroll/PaySheetTransaction_getDetails.xml
+++ b/bt5/erp5_payroll/SkinTemplateItem/portal_skins/erp5_payroll/PaySheetTransaction_getDetails.xml
@@ -347,12 +347,51 @@ for psl in context.objectValues(portal_type=\'Pay Sheet Line\'):\n
 \n
 \n
 \n
-details[\'totals\'][\'gross_salary\']         = gross_salary\n
-details[\'totals\'][\'net_salary\']           = net_salary\n
-details[\'totals\'][\'taxable_net_salary\']   = taxable_net_salary\n
-details[\'totals\'][\'total_employer_share\'] = total_employer_share\n
-details[\'totals\'][\'total_employee_share\'] = total_employee_share\n
-details[\'totals\'][\'total_addendum\']       = total_addendum\n
+details[\'totals\'][\'gross_salary\']           = gross_salary\n
+details[\'totals\'][\'net_salary\']             = net_salary\n
+details[\'totals\'][\'taxable_net_salary\']     = taxable_net_salary\n
+details[\'totals\'][\'total_employer_share\']   = total_employer_share\n
+details[\'totals\'][\'total_employee_share\']   = total_employee_share\n
+details[\'totals\'][\'total_addendum\']         = total_addendum\n
+details[\'totals\'][\'total_employee_payment\'] = r_(net_salary + total_addendum)\n
+\n
+\n
+\n
+##############################################################################\n
+# Transform every float value to a string representation according the currency.\n
+##############################################################################\n
+\n
+# There is 2 kind of numbers to format: rates and amounts.\n
+rate_propertie_list   = [\'employer_rate\', \'employee_rate\']\n
+amount_propertie_list = [\'base\', \'employer_share\', \'employee_share\']\n
+\n
+# The "three decimals" format is arbitrary. "3" was choose because there is no rate with\n
+# precision above 3. Feel free to update dynamiccaly this format if required.\n
+RATE_PRECISION = 3\n
+\n
+# Format each "normal" lines\n
+for group_id in getPSLGroupIdList():\n
+  for subline_id in getGroupSubLineIdList(group_id=group_id):\n
+    subline = getSubLine(group_id=group_id, subline_id=subline_id)\n
+    for (property, value) in subline.items():\n
+      if same_type(value, 1.0) or same_type(value, 1):\n
+        new_value = None\n
+        if property in rate_propertie_list:\n
+          new_value = (\'%.\' + str(RATE_PRECISION) + \'f\') % value\n
+        elif property in amount_propertie_list:\n
+          new_value = (\'%.\' + str(precision) + \'f\') % value\n
+        if new_value != None:\n
+          updateSubLine( group_id   = group_id\n
+                       , subline_id = subline_id\n
+                       , property   = property\n
+                       , value      = new_value\n
+                       )\n
+\n
+# Format totals\n
+for (key, value) in details[\'totals\'].items():\n
+  if same_type(value, 1.0) or same_type(value, 1):\n
+    details[\'totals\'][key] = (\'%.\' + str(precision) + \'f\') % value\n
+\n
 \n
 return details\n
 
@@ -457,6 +496,16 @@ return details\n
                             <string>cell_rate</string>
                             <string>cell_base</string>
                             <string>cell_share</string>
+                            <string>rate_propertie_list</string>
+                            <string>amount_propertie_list</string>
+                            <string>RATE_PRECISION</string>
+                            <string>subline</string>
+                            <string>property</string>
+                            <string>value</string>
+                            <string>same_type</string>
+                            <string>new_value</string>
+                            <string>str</string>
+                            <string>key</string>
                           </tuple>
                         </value>
                     </item>
diff --git a/bt5/erp5_payroll/SkinTemplateItem/portal_skins/erp5_payroll/PaySheetTransaction_viewPaySheetTransactionAsPDF.xml b/bt5/erp5_payroll/SkinTemplateItem/portal_skins/erp5_payroll/PaySheetTransaction_viewPaySheetTransactionAsPDF.xml
index 163c0affb8..1845123970 100644
--- a/bt5/erp5_payroll/SkinTemplateItem/portal_skins/erp5_payroll/PaySheetTransaction_viewPaySheetTransactionAsPDF.xml
+++ b/bt5/erp5_payroll/SkinTemplateItem/portal_skins/erp5_payroll/PaySheetTransaction_viewPaySheetTransactionAsPDF.xml
@@ -191,6 +191,11 @@
                        condition="python: details[\'totals\'].has_key(\'net_salary\')"/> </td>\n
       </tr>\n
     </table>\n
+\n
+    <!-- This table act as a spacer -->\n
+    <table rowheight="0.6cm"><tr><td> </td></tr></table>\n
+\n
+    <h1>Payment</h1>\n
 \n
     <tal:block repeat="group python: details[\'groups\']">\n
       <table splitbyrow="1" rowheight=\'0.4cm\' repeatrows="1" repeatcols="0" style="decompte"\n
@@ -204,6 +209,16 @@
           <td colwidth="2.397cm"> </td>\n
           <td colwidth="1.959cm">Montant</td>\n
         </tr>\n
+        <tr tal:attributes="stylecmd boldstyle">\n
+          <td>Salaire Net</td>\n
+          <td> </td>\n
+          <td> </td>\n
+          <td> </td>\n
+          <td> </td>\n
+          <td> </td>\n
+          <td><tal:block replace="python: details[\'totals\'][\'net_salary\']"\n
+                        condition="python: details[\'totals\'].has_key(\'net_salary\')"/> </td>\n
+        </tr>\n
         <tr tal:attributes="stylecmd boldstyle">\n
           <td tal:content="python: group[\'title\']"> </td>\n
           <td> </td>\n
@@ -228,7 +243,7 @@
                         condition="python: line[\'employee_share\'] != None"/> </td>\n
         </tr>\n
         <tr tal:attributes="stylecmd boldstyle">\n
-          <td>Total</td>\n
+          <td>Total Addendum</td>\n
           <td> </td>\n
           <td> </td>\n
           <td> </td>\n
@@ -237,6 +252,16 @@
           <td><tal:block replace="python: details[\'totals\'][\'total_addendum\']"\n
                           condition="python: details[\'totals\'].has_key(\'total_addendum\')"/> </td>\n
         </tr>\n
+        <tr tal:attributes="stylecmd boldstyle">\n
+          <td>Paiement Final</td>\n
+          <td> </td>\n
+          <td> </td>\n
+          <td> </td>\n
+          <td> </td>\n
+          <td> </td>\n
+          <td><tal:block replace="python: details[\'totals\'][\'total_employee_payment\']"\n
+                        condition="python: details[\'totals\'].has_key(\'total_employee_payment\')"/> </td>\n
+        </tr>\n
       </table>\n
     </tal:block>\n
 \n
-- 
2.30.9