hrsalaryModel.php 11 KB

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