TemplateTag.php 11 KB

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