TemplateTag.php 10 KB

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