TemplateTag.php 12 KB

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