TemplateTag.php 13 KB

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