hrsalaryModel.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. <?php
  2. class flow_hrsalaryClassModel extends flowModel
  3. {
  4. protected $flowviewufieds = 'xuid';
  5. public $floweditother = true; //可编辑uid别人的单据
  6. //薪资是个严格的模块,只能设置权限后才可以查看,不管是不是管理员
  7. protected function flowbillwhere($uid, $lx)
  8. {
  9. $key = $this->rock->post('key');
  10. $dt = $this->rock->post('dt');
  11. $ispay = $this->rock->post('ispay');
  12. $isturn = $this->rock->post('isturn');
  13. $where = '';
  14. $where = $this->viewmodel->viewwhere($this->moders, $this->adminid, $this->flowviewufieds, 1);
  15. if($lx=='faf'){
  16. $where.=' and a.`status`=1';
  17. }
  18. if($ispay!='')$where.=' and a.`ispay`='.$ispay.'';
  19. if($isturn!='')$where.=' and a.`isturn`='.$isturn.'';
  20. //自己部门下的
  21. if($lx=='dept'){
  22. $uidall = $this->adminmodel->getdown($uid);
  23. if(isempt($uidall))$uidall='0';
  24. $where.=' and a.`xuid` in('.$uidall.')';
  25. }
  26. //echo $where;
  27. //if($key!='')$where.=" and (c.deptallname like '%$key%' or a.uname like '%$key%' or a.ranking like '%$key%' )";
  28. if($dt!='')$where.=" and a.`month`='$dt'";
  29. return array(
  30. 'where' => $where,
  31. 'orlikefields' => 'c.`deptallname`,a.`uname`,a.`ranking`',
  32. 'tableleft' => '`[Q]userinfo` c on a.`xuid`=c.`id`',
  33. 'fieldsleft'=> 'c.`num`,c.deptallname,c.`bankname`,c.`banknum`',
  34. 'order' => 'a.`month` desc,a.`id` asc',
  35. );
  36. }
  37. public function flowrsreplace($rs, $lx=0){
  38. $s = '<font color=red>待发放</font>';
  39. $rs['ispays'] = $rs['ispay'];
  40. if($rs['ispay']==1)$s = '<font color=green>已发放</font>';
  41. $rs['ispay'] = $s;
  42. $s = '<font color=red>待核算</font>';
  43. if($rs['isturn']==1)$s = '<font color=green>已核算</font>';
  44. $rs['isturnss'] = $s;
  45. //详情展示时
  46. if($lx==1){
  47. }
  48. return $rs;
  49. }
  50. private function fafang()
  51. {
  52. $this->addlog(array(
  53. 'name' => '发放'
  54. ));
  55. $this->update('ispay=1', $this->id);
  56. m('reim')->asynurl('asynrun','salaryff', array(
  57. 'id' => $this->id
  58. ));//异步通知给人员
  59. }
  60. public function todouser()
  61. {
  62. $this->push($this->rs['xuid'],'工资条','您['.$this->rs['month'].']月份薪资已发放,请注意查看对账。','薪资发放通知');
  63. }
  64. public function gongzifafang($sid)
  65. {
  66. $sarrid = explode(',',$sid);
  67. foreach($sarrid as $id){
  68. $this->loaddata($id, false);
  69. if($this->rs['status']==1 && $this->rs['ispay']==0)$this->fafang();
  70. }
  71. }
  72. //一键生成薪资
  73. public function createdata($month)
  74. {
  75. $lmonth = c('date')->adddate($month.'-01','m',-1, 'Y-m');
  76. $swer = m('admin')->monthuwhere($month);
  77. $where = "`month`<'$month' and xuid in(select id from `[Q]userinfo` where 1=1 $swer) and `xuid` not in(select xuid from `[Q]".$this->mtable."` where `month`='$month')";
  78. $addfes = 'base,postjt';//基本工资跟岗位工资
  79. $adees = explode(',', $addfes);
  80. $rows = $this->db->getall("select * from `[Q]hrsalary` where $where order by `month` desc");
  81. $count = 0;
  82. $xuarr = array();
  83. foreach($rows as $k=>$rs){
  84. unset($rs['id']);
  85. $xuid = $rs['xuid'];
  86. if(isset($xuarr[$xuid]))continue;
  87. $count++;
  88. $xuarr[$xuid] = 1;
  89. $arr = array();
  90. $arr1 = array(
  91. 'xuid' => $xuid,
  92. 'uname' => $rs['uname'],
  93. 'ranking' => $rs['ranking'],
  94. 'udeptname' => $rs['udeptname'],
  95. 'uid' => $this->adminid,
  96. 'optid' => $this->adminid,
  97. 'optname' => $this->adminname,
  98. 'optdt' => $this->rock->now,
  99. 'applydt' => $this->rock->date,
  100. 'status' => 0,
  101. 'isturn' => 0,
  102. 'month' => $month,
  103. );
  104. foreach($adees as $adees1)$arr[$adees1]=$rs[$adees1];
  105. foreach($arr1 as $k1=>$v1)$arr[$k1]=$v1;
  106. $arr['explain']='一键生成参考了'.$rs['month'].'月份的工资';
  107. //读取固定值的
  108. $farrr = $this->getfiearrs($xuid, $month);
  109. foreach($farrr as $k1=>$rs1){
  110. foreach($rs1['fieldsarr'] as $k2=>$rs2){
  111. if($rs2['type']=='0')$arr[$rs2['fields']] = $rs2['devzhi'];
  112. if($rs2['gongsi']=='last')$arr[$rs2['fields']] = $rs[$rs2['fields']]; //读取上月
  113. }
  114. }
  115. $arr['jxdf'] = '0';
  116. $arr['jiansr'] = '0';
  117. $arr['otherzj'] = '0';
  118. $arr['otherjs'] = '0';
  119. /*
  120. $money = 0;
  121. foreach($adees as $fid){
  122. $arr[$fid] = $rs[$fid];
  123. $money += floatval($rs[$fid]);
  124. }
  125. $money -= floatval($rs['socials']);
  126. $arr['money'] = $money;*/
  127. $this->insert($arr);
  128. }
  129. return '成功生成'.$count.'条';
  130. }
  131. //导入数据的测试显示
  132. public function flowdaorutestdata()
  133. {
  134. $barr = array(
  135. 'uname' => '貂蝉',
  136. 'month' => '[2017-08]',
  137. 'base' => '1700',
  138. 'skilljt' => '3500',
  139. 'telbt' => '0',
  140. 'travelbt' => '0',
  141. 'postjt' => '500',
  142. 'reward' => '0',
  143. 'jiabans' => '0',
  144. 'punish' => '0', //处罚
  145. 'socials' => '0',
  146. 'taxes' => '0',
  147. 'money' => '5700',
  148. 'explain' => '本月薪资',
  149. 'isturn' => '是',
  150. 'status' => '是',
  151. );
  152. $barr1 = array(
  153. 'uname' => '大乔',
  154. 'month' => '[2017-08]',
  155. 'base' => '1700',
  156. 'skilljt' => '3000',
  157. 'telbt' => '0',
  158. 'travelbt' => '0',
  159. 'postjt' => '500',
  160. 'reward' => '0',
  161. 'jiabans' => '0',
  162. 'explain' => '本月薪资',
  163. 'punish' => '0', //处罚
  164. 'socials' => '0',
  165. 'taxes' => '0',
  166. 'money' => '5200',
  167. 'isturn' => '是',
  168. 'status' => '是',
  169. );
  170. $barr2 = array(
  171. 'uname' => '小乔',
  172. 'month' => '[2017-08]',
  173. 'base' => '1700',
  174. 'skilljt' => '2500',
  175. 'telbt' => '0',
  176. 'travelbt' => '0',
  177. 'postjt' => '500',
  178. 'reward' => '0',
  179. 'jiabans' => '0',
  180. 'explain' => '导入',
  181. 'punish' => '5', //处罚
  182. 'socials' => '0',
  183. 'taxes' => '0',
  184. 'money' => '4695',
  185. 'isturn' => '是',
  186. 'status' => '是',
  187. );
  188. return array($barr,$barr1,$barr2);
  189. }
  190. //导入之前判断
  191. public function flowdaorubefore($rows, &$errdata)
  192. {
  193. $inarr = array();
  194. $uarra = array();
  195. foreach($rows as $k=>$rs){
  196. $name = $rs['uname'];
  197. $month = str_replace('[','', $rs['month']);
  198. $month = substr(str_replace(']','', $month),0,7);
  199. $arr = $rs;
  200. $urs = $this->adminmodel->getone("`name`='$name'");
  201. if(!$urs){
  202. $errdata[$rs['drxu']] = '('.$name.')用户不存在';
  203. continue;
  204. }
  205. $to = $this->rows("`xuid`='".$urs['id']."' and `month`='$month'");
  206. if($to>0){
  207. $errdata[$rs['drxu']] = '('.$name.'的'.$month.')已经存在了';
  208. continue;//已经存在了
  209. }
  210. $arr['month'] = $month;
  211. $arr['xuid'] = $urs['id'];
  212. $arr['udeptname'] = $urs['deptname'];
  213. $arr['ranking'] = $urs['ranking'];
  214. $arr['isturn'] = (arrvalue($arr,'isturn')=='是') ? 1 : 0;
  215. $arr['status'] = (arrvalue($arr,'status')=='是') ? 1 : 0;
  216. $arr['ispay'] = (arrvalue($arr,'ispay')=='是') ? 1 : 0;
  217. if($arr['status']==1)$arr['isturn'] = 1;
  218. $inarr[] = $arr;
  219. }
  220. return $inarr;
  221. }
  222. //导入后处理,未审核需要提交审核
  223. public function flowdaoruafter($drdata=array())
  224. {
  225. foreach($drdata as $k=>$rs){
  226. //
  227. //if($rs['status']==0 && $rs['isturn']==1){
  228. // $id = $rs['id'];
  229. // $this->loaddata($id, false);
  230. // $this->submit('提交');
  231. //}
  232. }
  233. }
  234. //读取薪资模版上的
  235. private $pipeibarr = array();
  236. public function getfiearrs($uid, $month, $bo=true)
  237. {
  238. if($this->pipeibarr && $bo)return $this->pipeibarr;
  239. $month= substr($month, 0, 7);
  240. $rows = m('hrsalarm')->getall("`status`=1 and `startdt`<='$month' and `enddt`>='$month'",'*','`sort`');
  241. $rowa = array();
  242. foreach($rows as $k=>$rs){
  243. $rs['xuhao'] = $k+1;
  244. $rowa[$rs['atype']][] = $rs;
  245. }
  246. $kqob = m('kaoqin');
  247. $dbs = m('hrsalars');
  248. $garr = array();
  249. foreach($rowa as $klx=>$carr){
  250. $xu = $kqob->getpipeimid($uid, $carr, 'xuhao',0);
  251. if($xu>0){
  252. $nrsaa = $rows[$xu-1];
  253. $nrsaa['fieldsarr'] = $dbs->getall('mid='.$nrsaa['id'].'','*','`sort`');
  254. $garr[] = $nrsaa;
  255. }
  256. }
  257. if($bo)$this->pipeibarr = $garr; //最后匹配到的模版
  258. //echo $xu;
  259. return $garr;
  260. }
  261. public function flowgetfields($lx)
  262. {
  263. $farr = $this->flowfieldarr($this->fieldsarra, 3);
  264. $barr = array();
  265. foreach($farr as $k=>$rs){
  266. if(isset($rs['iszs']) && $rs['iszs']==2)$barr[$rs['fields']]=$rs['name'];
  267. }
  268. return $barr;
  269. }
  270. //先运行这个$lx=0,1移动端,2保存,3展示
  271. public function flowfieldarr($farr, $lx)
  272. {
  273. $mid = (int)$this->rock->get('mid','0');
  274. $demonth = c('date')->adddate($this->rock->date,'m',-1,'Y-m');
  275. $dexuid = $this->adminid;
  276. if($mid>0 && $mrs=$this->getone($mid)){
  277. $demonth = $mrs['month'];
  278. $dexuid = $mrs['xuid'];
  279. }
  280. $month= $this->rock->post('month', $demonth);
  281. $xuid = (int)$this->rock->post('xuid', $dexuid);
  282. $cfarr= $this->getfiearrs($xuid, $month);
  283. $fnar = array();
  284. foreach($cfarr as $k=>$rs){
  285. foreach($rs['fieldsarr'] as $k1=>$rs1)$fnar[$rs1['fields']]=$rs1;
  286. }
  287. $urs = $this->adminmodel->getone($xuid);
  288. foreach($farr as $k=>$rs){
  289. $farr[$k]['suantype']=-1;
  290. $fid = $rs['fields'];
  291. if(isset($fnar[$fid])){
  292. $nfrs = $fnar[$fid];
  293. if($nfrs['gongsi']=='last')$nfrs['gongsi']='';
  294. $farr[$k]['dev'] = $nfrs['devzhi'];
  295. $farr[$k]['gongsi'] = $nfrs['gongsi']; //公式
  296. $farr[$k]['islu'] = 1;
  297. $farr[$k]['iszs'] = 2;
  298. $farr[$k]['suantype']= $nfrs['type'];
  299. }
  300. if($fid=='month'){
  301. $farr[$k]['dev'] = $month;
  302. }
  303. if($fid=='uname'){
  304. $farr[$k]['dev'] = ''.$urs['name'].'|'.$xuid.'';
  305. }
  306. if($fid=='udeptname'){
  307. $farr[$k]['dev'] = $urs['deptname'];
  308. }
  309. if($fid=='ranking'){
  310. $farr[$k]['dev'] = $urs['ranking'];
  311. }
  312. if($fid=='gonghao'){
  313. $farr[$k]['dev'] = $urs['num'];
  314. }
  315. }
  316. return $farr;
  317. }
  318. //在运行这个,模版处理
  319. public function flowinputtpl($cont, $lx)
  320. {
  321. //pc
  322. if($lx==0){
  323. $cfarr = $this->pipeibarr;
  324. $str = '';
  325. foreach($cfarr as $k=>$rs){
  326. $carr = $rs['fieldsarr'];
  327. if(isempt($rs['title']))$rs['title']=$rs['atype'];
  328. $str.='<div><br><strong>'.$rs['title'].'</strong></div>';
  329. if(count($carr)%2!=0)$carr[]=array(
  330. 'name' => '',
  331. 'fields' => '',
  332. );
  333. $str.='<table width="100%" border="0" class="ke-zeroborder">';
  334. $str.='<tr>';
  335. foreach($carr as $k1=>$rs1){
  336. $str.='<td align="right" class="ys1" width="15%">'.$rs1['name'].'</td>';
  337. $str.='<td class="ys2" width="35%">{'.$rs1['fields'].'}</td>';
  338. if(($k1+1)%2==0)$str.='</tr><tr>';
  339. }
  340. $str.='</tr>';
  341. $str.='</table>';
  342. }
  343. $cont = str_replace('{autotpl}', $str, $cont);
  344. }
  345. return $cont;
  346. }
  347. public function flowviewtpl($cont, $lx)
  348. {
  349. $this->getfiearrs($this->rs['xuid'], $this->rs['month']);
  350. return $this->flowinputtpl($cont, $lx);
  351. }
  352. }
粤ICP备19079148号