TemplateTag.php 12 KB

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