TemplateTag.php 10 KB

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