TemplateTag.php 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561
  1. <?php
  2. // register global/PHP functions to be used with your template files
  3. // You can move this to common.conf.php $config['TEMPLATE_GLOBAL_TAGS'] = array('isset', 'empty');
  4. // Every public static methods in TemplateTag class (or tag classes from modules) are available in templates without the need to define in TEMPLATE_GLOBAL_TAGS
  5. Doo::conf ()->TEMPLATE_GLOBAL_TAGS = array (
  6. 'isTimeTR',
  7. 'isInvoiceNew',
  8. 'isHRNew',
  9. 'upper',
  10. 'tofloat',
  11. 'sample_with_args',
  12. 'debug',
  13. 'url',
  14. 'url2',
  15. 'function_deny',
  16. 'isset',
  17. 'empty',
  18. 'make_date',
  19. 'inarray',
  20. 'getGlobals',
  21. 'countArray',
  22. 'isInvoiceMoldShow',
  23. 'isReceiptAuthorityShow',
  24. 'isInvoiceAggregateCompanyShow',
  25. 'forMatAccess',
  26. 'isShowMenu',
  27. 'isStaffCompleteMsg',
  28. 'isInvoiceCategoryShow',
  29. 'isReceiptTrainShow',
  30. 'isPaymentsShow',
  31. 'isUrlEncode',
  32. 'isGHNews',
  33. 'numberFormat'
  34. );
  35. function numberFormat($a,$b){
  36. return number_format($a,$b);
  37. }
  38. function isGHNews($staffGH){
  39. $BuildUrl = 'http://gh.cld.smartcost.com.cn';
  40. //$url = $BuildUrl. '/mcm/authorize/receiptNewsTip?staffGH='. urlencode($staffGH);
  41. //echo $url;
  42. $url = $BuildUrl. '/mcm/authorize/receiptNewsTip';
  43. $data=array("staffGH"=>$_COOKIE ['staffGH']);
  44. $result = json_decode(curl_request($url,$data), true);
  45. return $result['count'];
  46. // print_r($result);
  47. // $isNews=false;
  48. // if($result['falg'])
  49. // $isNews=true;
  50. // return $isNews;
  51. }
  52. function isUrlEncode($url){
  53. Doo::loadClass ( 'auth' );
  54. $auth = new auth ( );
  55. $staffGH=$auth->yundanran_auth($url,'DECODE',"GH");
  56. $staffGH=$auth->yundanran_auth($staffGH,'',"GH");
  57. return urlencode($staffGH);
  58. }
  59. function isStaffCompleteMsg(){
  60. //检测用户信息完成
  61. Doo::loadModel ( 'staff' );
  62. $staff = new staff ();
  63. $isStaffCompleteMsg=false;
  64. if (!isset($_COOKIE ["staff"]))
  65. return false;
  66. $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
  67. if(!empty($detail))
  68. $isStaffCompleteMsg=true;
  69. return $isStaffCompleteMsg;
  70. }
  71. function forMatAccess($access=array()){
  72. $html='';
  73. $accessMsg = array (
  74. 'INFORMATION' => '信息中心',
  75. 'DIRECTORIES' => '通讯录',
  76. 'LOCK' => '在线锁库',
  77. 'RECEIPTS' => '报销单',
  78. 'INVOICE' => '发票申请',
  79. 'HR' => '人资管理',
  80. 'BUILD'=>'建筑计价'
  81. );
  82. if (empty($access))
  83. return '';
  84. foreach ($access as $value){
  85. $html.=$accessMsg[$value].'&nbsp;&nbsp;';
  86. }
  87. return $html;
  88. }
  89. function countArray($list=array(),$count=0){
  90. return count($list)+$count;
  91. }
  92. function isTimeTR($day = 3,$cTime) {
  93. $flag=false;
  94. $thenTime=time();
  95. $futureTime=strtotime('+'.$day.' day',strtotime($cTime));
  96. if($thenTime<$futureTime)
  97. $flag=true;
  98. return $flag;
  99. }
  100. function isShowMenu($menu=''){
  101. Doo::loadModel ( 'staff' );
  102. $staff = new staff ();
  103. $st = $staff->getStaffBySid( $_COOKIE ["staff"] );
  104. $cldAccess=array();
  105. if (!empty($st['cldAccess']))
  106. $cldAccess=json_decode($st['cldAccess'],true);
  107. Doo::loadModel ( "staffManage" );
  108. $staffManage = new staffManage ();
  109. $smList=$staffManage->getInvoiceCMByStaff($_COOKIE ["staff"]);
  110. //是否有登陆者需要审批的员工
  111. $list=array();
  112. if ($menu=='HR'){
  113. Doo::loadClass ( 'XDeode' );
  114. $XDeode = new XDeode ( 5 );
  115. $uid = $XDeode->decode ( $_COOKIE ["staff"] );
  116. $list=$staff->find ( array (
  117. 'asc' => 'sid',
  118. 'where' => "(pendStatus= '2' or pendStatus='3' or pendStatus='5' or pendStatus='6') and ( pendingApprovalsLeave='".$uid."' or pendingApprovals='".$uid."') ",
  119. 'asArray' => TRUE
  120. ) );
  121. }
  122. if (in_array($menu,$cldAccess)||($st['sid']==superHR&&$menu=='HR')||(count($list)>0&&$menu=='HR')){
  123. return true;
  124. }
  125. if (empty($cldAccess)){
  126. return false;
  127. }
  128. return false;
  129. }
  130. function isHRNew(){
  131. Doo::loadModel ( 'staff' );
  132. $staff = new staff ();
  133. Doo::loadClass ( 'XDeode' );
  134. $XDeode = new XDeode ( 5 );
  135. $uid = $XDeode->decode ( $_COOKIE ["staff"] );
  136. $list=$staff->find ( array (
  137. 'asc' => 'sid',
  138. 'where' => "(pendStatus= '2' or pendStatus='3' or pendStatus='5' or pendStatus='6') and ( pendingApprovalsLeave='".$uid."' or pendingApprovals='".$uid."') ",
  139. 'asArray' => TRUE
  140. ) );
  141. return count($list);
  142. }
  143. function isInvoiceNew($type = "GLOBAL") {
  144. Doo::loadModel ( 'invoice' );
  145. $invoice = new invoice ();
  146. Doo::loadModel ( 'invoiceReceivables' );
  147. $invoiceReceivables = new invoiceReceivables ();
  148. Doo::loadModel ( 'staff' );
  149. $staff = new staff ();
  150. Doo::loadModel ( "invoiceManage" );
  151. $execute = new invoiceManage ();
  152. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  153. $exeGlobal=$execute->getInvoiceByStaff($st[0]['sid']);
  154. // 我的发票待处理
  155. $pendingInvoice = $invoice->getOne ( array (//or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  156. 'where' => "(status=3 or status=4 ) and isDelete=0 and sid=" . $st[0]['sid'],
  157. 'desc' => 'iid',
  158. 'asArray' => TRUE
  159. ) );
  160. // 我的收款待入账
  161. // $myClaim = $invoiceReceivables->getOne ( array (
  162. // 'where' => " receivablesStaff like '" . $st[0]['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0",
  163. // 'desc' => 'irid',
  164. // 'asArray' => TRUE
  165. // ) );
  166. // 发票审批
  167. $approval = $invoice->getOne ( array (
  168. 'where' => 'status=1 and pendingApprovals=' . $st[0]['sid'],
  169. 'desc' => 'iid',
  170. 'asArray' => true
  171. ) );
  172. // 发票邮寄
  173. $post = $invoice->getOne ( array (
  174. 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
  175. 'asArray' => TRUE
  176. ) );
  177. // 发票打印
  178. $print = $invoice->getOne ( array (
  179. 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st[0]['sid'] . "\",%'",
  180. 'desc' => 'iid',
  181. 'asArray' => TRUE
  182. ) );
  183. // 发票退票 printStatus=1 and
  184. $untread = $invoice->getOne ( array (
  185. 'where' => " untreadStatus=1 and status=2 ",
  186. 'asArray' => TRUE
  187. ) );
  188. $new = array (
  189. 'GLOBAL' => FALSE,
  190. 'pendingInvoice' => FALSE,
  191. 'myClaim' => FALSE,
  192. 'approval' => FALSE,
  193. 'post' => FALSE,
  194. 'print' => FALSE,
  195. 'untread' => FALSE
  196. );
  197. //|| ! empty ( $myClaim )
  198. if (!empty($exeGlobal)){
  199. if (! empty ( $pendingInvoice ))
  200. $new ['GLOBAL'] = TRUE;
  201. foreach ($exeGlobal as $value){
  202. if ($value['mold']=='发票审批'){
  203. if(! empty ( $approval )){
  204. $new ['GLOBAL'] = TRUE;
  205. break;
  206. }
  207. }
  208. if ($value['mold']=='发票打印'){
  209. if(! empty ( $print )){
  210. $new ['GLOBAL'] = TRUE;
  211. break;
  212. }
  213. }
  214. if ($value['mold']=='发票邮寄'){
  215. if(! empty ( $post )){
  216. $new ['GLOBAL'] = TRUE;
  217. break;
  218. }
  219. }
  220. if ($value['mold']=='发票退票'){
  221. if(! empty ( $untread )){
  222. $new ['GLOBAL'] = TRUE;
  223. break;
  224. }
  225. }
  226. }
  227. // print_r($exeGlobal);die;
  228. // if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  229. // $new ['GLOBAL'] = TRUE;
  230. }else{
  231. if (! empty ( $pendingInvoice ) )
  232. $new ['GLOBAL'] = TRUE;
  233. }
  234. if (! empty ( $pendingInvoice ))
  235. $new ['pendingInvoice'] = TRUE;
  236. if (! empty ( $myClaim ))
  237. $new ['myClaim'] = TRUE;
  238. if (! empty ( $approval ))
  239. $new ['approval'] = TRUE;
  240. if (! empty ( $post ))
  241. $new ['post'] = TRUE;
  242. if (! empty ( $print ))
  243. $new ['print'] = TRUE;
  244. if (! empty ( $untread ))
  245. $new ['untread'] = TRUE;
  246. return $new [$type];
  247. }
  248. /**
  249. * 是否有查看汇总的权限
  250. * @param unknown $sid
  251. */
  252. function isInvoiceCategoryShow($sid){
  253. Doo::loadModel ( "invoiceCategoryManage" );
  254. $invoiceCategoryManage = new invoiceCategoryManage ();
  255. $icm=$invoiceCategoryManage->getInvoiceCMByStaff($sid);
  256. if (!empty($icm))
  257. return true;
  258. else
  259. return false;
  260. }
  261. /**
  262. * 是否有查看培训班结算营收的权限
  263. * @param unknown $sid
  264. */
  265. function isReceiptTrainShow($sid){
  266. Doo::loadModel ( "receiptTrainManage" );
  267. $invoiceCategoryManage = new receiptTrainManage ();
  268. $icm=$invoiceCategoryManage->getInvoiceCMByStaff($sid);
  269. if (!empty($icm))
  270. return true;
  271. else
  272. return false;
  273. }
  274. /**
  275. * 是否有查看日常收支的权限
  276. */
  277. function isPaymentsShow($sid){
  278. Doo::loadModel ( "execute" );
  279. $execute = new execute ();
  280. $list = $execute->find ( array (
  281. 'where' => '(staff like \'%["' . $sid . '%\' ) and mold="日常收支"',
  282. 'asArray' => true
  283. ) );
  284. if (empty($list)){
  285. return false;
  286. }else {
  287. return true;
  288. }
  289. }
  290. /**
  291. * 是否有查看应收款的权限
  292. * @param unknown $sid
  293. */
  294. function isInvoiceAggregateCompanyShow($sid){
  295. Doo::loadModel ( "invoiceCompanyManage" );
  296. $receiptAuthorityManage = new invoiceCompanyManage ();
  297. $icm=$receiptAuthorityManage->getInvoiceCMByStaff($sid);
  298. if (!empty($icm))
  299. return true;
  300. else
  301. return false;
  302. }
  303. /**
  304. * 是否有查看报销单汇总的权限
  305. * @param unknown $sid
  306. */
  307. function isReceiptAuthorityShow($sid){
  308. Doo::loadModel ( "receiptAuthorityManage" );
  309. $receiptAuthorityManage = new receiptAuthorityManage ();
  310. $icm=$receiptAuthorityManage->getInvoiceCMByStaff($sid);
  311. if (!empty($icm))
  312. return true;
  313. else
  314. return false;
  315. }
  316. function isInvoiceCompanyShow($sid){
  317. }
  318. /**
  319. * 判断发票的审批权限
  320. * @param number $sid 用户ID
  321. * @param string $mold 项目类型
  322. * @return boolean
  323. */
  324. function isInvoiceMoldShow($sid = 0, $mold = '') {
  325. if (! empty ( $sid ) && ! empty ( $mold )) {
  326. Doo::loadModel ( "invoiceManage" );
  327. $invoiceManage = new invoiceManage ();
  328. $imList = $invoiceManage->getInvoiceByMold ( $mold );
  329. $list = array ();
  330. foreach ( $imList ['staffList'] as $k => $v ) {
  331. array_push ( $list, $v [0] );
  332. }
  333. $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
  334. $fileInvoice = json_decode ( $fileInvoice, true );
  335. $delIM = array ();
  336. if (isset ( $fileInvoice [$mold] ))
  337. $delIM = explode ( ',', $fileInvoice [$mold] );
  338. foreach ( $delIM as $key => $value ) {
  339. if (! empty ( $value ))
  340. array_push ( $list, $value );
  341. }
  342. $list = array_unique ( $list );
  343. return inarray ( $sid, $list );
  344. } else
  345. return false;
  346. }
  347. function getGlobals($var) {
  348. if ($var == 'NEW')
  349. getReceiptCount ();
  350. elseif ($var == 'NEW2')
  351. getExeCount ();
  352. // echo $GLOBALS[$var].'/'.$var.'<br/>';
  353. return $GLOBALS [$var];
  354. }
  355. function inarray($v1, $v2) {
  356. return in_array ( $v1, $v2 );
  357. }
  358. function make_date() {
  359. return date ( "Y-m" );
  360. }
  361. function upper($str) {
  362. return strtoupper ( $str );
  363. }
  364. function tofloat($str) {
  365. return sprintf ( "%.2f", $str );
  366. }
  367. function sample_with_args($str, $prefix) {
  368. return $str . ' with args: ' . $prefix;
  369. }
  370. function debug($var) {
  371. if (! empty ( $var )) {
  372. echo '<pre>';
  373. print_r ( $var );
  374. echo '</pre>';
  375. }
  376. }
  377. // This will be called when a function NOT Registered is used in IF or ElseIF statment
  378. function function_deny($var = null) {
  379. echo '<span style="color:#ff0000;">Function denied in IF or ElseIF statement!</span>';
  380. exit ();
  381. }
  382. // Build URL based on route id
  383. function url($id, $param = null, $addRootUrl = false) {
  384. Doo::loadHelper ( 'DooUrlBuilder' );
  385. // param pass in as string with format
  386. // 'param1=>this_is_my_value, param2=>something_here'
  387. if ($param != null) {
  388. $param = explode ( ', ', $param );
  389. $param2 = null;
  390. foreach ( $param as $p ) {
  391. $splited = explode ( '=>', $p );
  392. $param2 [$splited [0]] = $splited [1];
  393. }
  394. return DooUrlBuilder::url ( $id, $param2, $addRootUrl );
  395. }
  396. return DooUrlBuilder::url ( $id, null, $addRootUrl );
  397. }
  398. // Build URL based on controller and method name
  399. function url2($controller, $method, $param = null, $addRootUrl = false) {
  400. Doo::loadHelper ( 'DooUrlBuilder' );
  401. // param pass in as string with format
  402. // 'param1=>this_is_my_value, param2=>something_here'
  403. if ($param != null) {
  404. $param = explode ( ', ', $param );
  405. $param2 = null;
  406. foreach ( $param as $p ) {
  407. $splited = explode ( '=>', $p );
  408. $param2 [$splited [0]] = $splited [1];
  409. }
  410. return DooUrlBuilder::url2 ( $controller, $method, $param2, $addRootUrl );
  411. }
  412. return DooUrlBuilder::url2 ( $controller, $method, null, $addRootUrl );
  413. }
  414. /**
  415. * 获得正在审批的费用单数量
  416. */
  417. function getReceiptCount() {
  418. $status = 2;
  419. $year = date ( 'Y' );
  420. Doo::loadModel ( 'receipt' );
  421. $receipt = new receipt ();
  422. Doo::loadClass ( 'XDeode' );
  423. $XDeode = new XDeode ( 5 );
  424. Doo::loadModel ( 'verify' );
  425. $verify = new verify ();
  426. $st[0]['sid'] = $XDeode->decode ( $_COOKIE["staff"] );
  427. $vidList = array ();
  428. $verifyDetail = $verify->find ( array (
  429. 'where' => ' (staff not like "%\"' . $st [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $st [0] ['sid'] . '\",%" or staff like "%\"' . $st [0] ['sid'] . '\_%" )',
  430. 'asArray' => true
  431. ) );
  432. foreach ( $verifyDetail as $key => $value ) {
  433. array_push ( $vidList, $value ['vid'] );
  434. }
  435. $vid = implode ( ",", $vidList );
  436. if (empty ( $verifyDetail ))
  437. $vid = 0;
  438. $dateCondition = " and Year(date) =" . $year;
  439. $approvalCondition = ' and (nowStaff like "%,' . $st[0]['sid'] . '%" or nowStaff like "%' . $st[0]['sid'] . ',%" or nowStaff=' . $st[0]['sid'] . ' ) ';
  440. $receiptList = $receipt->find ( array (
  441. 'where' => ' status=' . $status . $dateCondition . $approvalCondition. ' and verify in (' . $vid . ')',
  442. 'desc' => 'rid',
  443. 'asArray' => true
  444. ) );
  445. $GLOBALS ['NEW'] = count ( $receiptList );
  446. }
  447. /**
  448. * 获得执行费用的数量
  449. */
  450. function getExeCount() {
  451. Doo::loadModel ( 'receipt' );
  452. $receipt = new receipt ();
  453. Doo::loadClass ( 'XDeode' );
  454. $XDeode = new XDeode ( 5 );
  455. $st[0]['sid'] = $XDeode->decode ( $_COOKIE["staff"] );
  456. $receiptList = $receipt->find ( array (
  457. 'where' => '(executeCopy like \'%["' . $st[0]['sid'] . '%\' and ( executeStaff NOT LIKE \'%' . $st[0]['sid'] . '%\' or executeStaff is null ) ) and (status=1 or status=6)',
  458. 'desc' => 'rid',
  459. 'asArray' => true
  460. ) );
  461. $GLOBALS ['NEW2'] = count ( $receiptList );
  462. }
  463. /**
  464. * curl 获取接口数据,data为空时为GET方法,有值则为POST方法
  465. *
  466. * @param $url
  467. * @param string $data
  468. * @return mixed|string
  469. */
  470. function curl_request($url, $data = '') {
  471. $curl = curl_init();
  472. curl_setopt($curl, CURLOPT_URL, $url);
  473. curl_setopt($curl, CURLOPT_HEADER, 0);
  474. curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
  475. if($data) {
  476. curl_setopt($curl, CURLOPT_POST, 1);
  477. curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
  478. }
  479. curl_setopt($curl, CURLOPT_TIMEOUT, 10);
  480. $data = curl_exec($curl);
  481. curl_close($curl);
  482. return $data;
  483. }
  484. ?>