bulkpayrolltest.php
Upload User: mnp333
Upload Date: 2019-02-07
Package Size: 1618k
Code Size: 6k
Category:

Java Develop

Development Platform:

Java

  1. <?php
  2. //
  3. // CK-ERP  --  Copyright (C) 2004 - 2009       Wu Chiu Kay
  4. // ------------------------------------------------------
  5. //  This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
  6. //
  7. // bulkpayrolltest.php 0.29.1 2009/01/31 C K Wu
  8. $app = 'ck-payroll' ;
  9. $tran = $class = 'bulkpayroll' ;
  10. require_once('../ck-api/ckapi.inc.php') ;
  11. $id = isset($_GET['id']) ? $_GET['id'] : (isset($_POST['id'])?$_POST['id']:'');
  12. $filter = isset($_GET['filter']) ? $_GET['filter'] : (isset($_POST['filter'])?$_POST['filter']:'');
  13. $period = isset($_GET['period']) ? $_GET['period'] : (isset($_POST['period'])?$_POST['period']:'');
  14. $datefrom = isset($_GET['datefrom']) ? $_GET['datefrom'] : (isset($_POST['datefrom'])?$_POST['datefrom']:'');
  15. $dateto = isset($_GET['dateto']) ? $_GET['dateto'] : (isset($_POST['dateto'])?$_POST['dateto']:'');
  16. $filter=stripslashes($filter);
  17. $gp = newobj($app,$class) ;
  18. $t = exapi_tpl($app);
  19. $t->set_file('report','bulkpayrollscreen.tpl') ;
  20. $t->set_file('screen','journalscreen.tpl') ;
  21. $t->set_block('report','detail','detail_section');
  22. $t->set_block('screen','journal','journal_section');
  23. $t->set_var('lang_title',exapi_lang('Test Run on Current Period Payroll Generation'));
  24. $msg1 = exapi_lang('When actually generating period payroll, make sure the period from/to dates are accurate.');
  25. $msg2 = exapi_lang("Inaccurate Date will affect subsequent period's payroll.");
  26. $t->set_var('message',"<b>$msg1<br>$msg2</b>") ;
  27. $t->set_var('readonly','readonly');
  28. $t->set_var('disabled','');
  29. /*------------- Write Journal to Screen Display ----------------------------*/
  30. $p['datefrom'] = $datefrom ;
  31. $p['dateto'] = $dateto ;
  32. $gp->bulkpayroll_header_write($t, $p) ;
  33. $float = ($ckapi['hostsys']['dbtype']=="mysql") ? "double" : "float" ;
  34. $ck_user = $ckapi['hostsys']['username'];
  35. $temp = "${pre}pyr".$ck_user.time() ;
  36. $temp1 = "${pre}pyr1".$ck_user.time() ;
  37. $creattempsql = "CREATE TABLE $temp (pyrcodeid int,amount $float)" ;
  38. $adodb->query("CREATE TABLE $temp1 as SELECT * FROM ${pre}pyrohist WHERE 1<>1");
  39. $where = "WHERE empid=b.id" ;
  40. if ($period<>'') $where = "$where and period='$period'" ;
  41. $ck_sql = "SELECT a.id as id,empid,salary,period,chart_id,bankac,bankacname " ;
  42. $ck_sql.= "FROM ${pre}payroll a,${pre}employee b $where" ;
  43. $result = $adodb->query($ck_sql);
  44. For ($i=1;$arr[$i]=$result->fetchRow();$i++) ;
  45. $tot_recur = $tot_nonrecur = $tot_reductn = $tot_net = $tot_contri = 0 ;
  46. For ($j=1;isset($arr[$j]['id']);$j++) {
  47. $p = $arr[$j] ;
  48. $id = ($p['id']=='') ? 0 : $p['id'] ;
  49. $p['empid'] = ($p['empid']=='') ? 0 : $p['empid'] ;
  50. $p['temp'] = $temp ;
  51. $p['temp1'] = $temp1 ;
  52. $p['creattempsql'] = $creattempsql ;
  53. $result = $adodb->query("SELECT * FROM ${pre}pyrc_trans WHERE pyroid='$id' ORDER BY id");
  54. For ($i=1;$rs=$result->fetchRow();$i++) {
  55. $p['eaid'.$i] = $rs['pyrcodeid'] ;
  56. $p['qty'.$i] = $rs['qty'] ;
  57. $p['rate'.$i] = $rs['rate'] ;
  58. $p['amount'.$i] = $rs['amount'] ;
  59. $p['comment'.$i] = $rs['comment'] ;
  60. $p['chart_id'.$i] = $rs['chart_id'] ;
  61. }
  62. $result = $adodb->query("SELECT * FROM ${pre}pynr_trans WHERE empid='$p[empid]' and approved_by<>'' ORDER BY id");
  63. For ($i=1;$rs=$result->fetchRow();$i++) {
  64. $p['nreaid'.$i] = $rs['pyrcodeid'] ;
  65. $p['nrapproved_by'.$i] = $rs['approved_by'] ;
  66. $p['nrqty'.$i] = $rs['qty'] ;
  67. $p['nrrate'.$i] = $rs['rate'] ;
  68. $p['nramount'.$i] = $rs['amount'] ;
  69. $p['nrcomment'.$i] = $rs['comment'] ;
  70. $p['nrchart_id'.$i] = $rs['chart_id'] ;
  71. }
  72. $ck_sql = "SELECT rdtnid,chart_id FROM ${pre}rdtn_trans a,${pre}reductn b " ;
  73. $ck_sql.= "WHERE pyroid='$id' and rdtnid=b.id ORDER BY a.id";
  74. $result = $adodb->query($ck_sql);
  75. For ($i=1;$rs=$result->fetchRow();$i++) {
  76. $p['rdtnid'.$i] = $rs['rdtnid'] ;
  77. $p['rdchart_id'.$i] = $rs['chart_id'] ;
  78. }
  79. $ck_sql = "SELECT cntrid,ac_exp,ac_liab FROM ${pre}cntr_trans a,${pre}contri b " ;
  80. $ck_sql.= "WHERE pyroid='$id' and cntrid=b.id ORDER BY a.id" ;
  81. $result = $adodb->query($ck_sql);
  82. For ($i=1;$rs=$result->fetchRow();$i++) {
  83. $p['cntrid'.$i] = $rs['cntrid'] ;
  84. $p['ac_exp'.$i] = $rs['ac_exp'] ;
  85. $p['ac_liab'.$i] = $rs['ac_liab'] ;
  86. }
  87. $gp->bulkpayroll_detail_write($t, $p);
  88. $tot_recur += $p['recur'] ;
  89. $tot_nonrecur += $p['nonrecur'] ;
  90. $tot_reductn += $p['reductn'] ;
  91. $tot_net += $p['net'] ;
  92. $tot_contri += $p['contri'] ;
  93. }
  94. $t->set_var('tot_recur',$tot_recur) ;
  95. $t->set_var('tot_nonrecur',$tot_nonrecur) ;
  96. $t->set_var('tot_reductn',$tot_reductn) ;
  97. $t->set_var('tot_net',$tot_net) ;
  98. $t->set_var('tot_contri',$tot_contri) ;
  99. /*--------------------Write bottom Section------------------------------------------*/
  100. $getstr = "id=$id&filter=$filter" ;
  101. $t->set_var('action',exapi_link("/ck-payroll/bulkpayrollfilter.php",$getstr));
  102. $t->set_var('done_action',exapi_link("/ck-payroll/bulkpayrollfilter.php",$getstr));
  103. $t->set_var('lang_done',exapi_lang('Done'));
  104. $t->pparse('out','report',True);
  105. //---- Generate Payroll journal
  106. $lang_payperiod = exapi_lang('Payroll for period') ;
  107. $lang_from = exapi_lang('*from*') ;
  108. $lang_to = exapi_lang('*to*') ;
  109. $t->set_var('lang_jtitle',exapi_lang('Payroll Journal to be Generated'));
  110. $jl['source'] = "PYRO" ;
  111. $jl['description'] = "$lang_payperiod $lang_from::$datefrom $lang_to::$dateto" ;
  112. $jl['transdate'] = date("Y-m-d") ;
  113. $gp->journal_header_write($t, $jl) ;
  114. $ck_sql = "SELECT chart_id,sum(amount) as amount FROM $temp1 a, ${pre}chart b " ;
  115. $ck_sql.= "WHERE a.chart_id=b.id GROUP BY chart_id ORDER BY chart_id";
  116. $result = $adodb->query($ck_sql);
  117. $i=1;
  118. while ($rs=$result->fetchRow()) {
  119. $jl['accno'.$i] = $rs['chart_id'] ;
  120. $jl['attrib1'.$i] = isset($rs['attrib1']) ?  $rs['attrib1'] : '' ;
  121. $jl['attrib2'.$i] = isset($rs['attrib2']) ?  $rs['attrib2'] : '' ;
  122. $jl['attrib3'.$i] = isset($rs['attrib3']) ?  $rs['attrib3'] : '' ;
  123. $cr = sprintf($ck_nbrfmt,$rs['amount']);
  124. $dr = sprintf($ck_nbrfmt,-$cr) ;
  125. if ($cr>0) {$dr='';} else {$cr='';}
  126. $jl['dr'.$i] = $dr ;
  127. $jl['cr'.$i] = $cr ;
  128. $i++ ;
  129. }
  130. $gp->journal_detail_write($t,$jl,True);
  131. $adodb->query("DROP TABLE $temp1");
  132. $t->pparse('out','screen',True);
  133. ck_footer() ;
  134. ?>