TemplateTag.php 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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. );
  23. function countArray($list=array()){
  24. return count($list);
  25. }
  26. function isTimeTR($day = 3,$cTime) {
  27. $flag=false;
  28. $thenTime=time();
  29. $futureTime=strtotime('+'.$day.' day',strtotime($cTime));
  30. if($thenTime<$futureTime)
  31. $flag=true;
  32. return $flag;
  33. }
  34. function isInvoiceNew($type = "GLOBAL") {
  35. Doo::loadModel ( 'invoice' );
  36. $invoice = new invoice ();
  37. Doo::loadModel ( 'invoiceReceivables' );
  38. $invoiceReceivables = new invoiceReceivables ();
  39. Doo::loadModel ( 'staff' );
  40. $staff = new staff ();
  41. Doo::loadModel ( "invoiceManage" );
  42. $execute = new invoiceManage ();
  43. $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
  44. $exeGlobal=$execute->getInvoiceByStaff($st[0]['sid']);
  45. // 我的发票待处理
  46. $pendingInvoice = $invoice->getOne ( array (//or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
  47. 'where' => "(status=3 or status=4 ) and isDelete=0 and sid=" . $st[0]['sid'],
  48. 'desc' => 'iid',
  49. 'asArray' => TRUE
  50. ) );
  51. // 我的收款待入账
  52. $myClaim = $invoiceReceivables->getOne ( array (
  53. 'where' => " receivablesStaff like '" . $st[0]['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0",
  54. 'desc' => 'irid',
  55. 'asArray' => TRUE
  56. ) );
  57. // 发票审批
  58. $approval = $invoice->getOne ( array (
  59. 'where' => 'status=1 and pendingApprovals=' . $st[0]['sid'],
  60. 'desc' => 'iid',
  61. 'asArray' => true
  62. ) );
  63. // 发票邮寄
  64. $post = $invoice->getOne ( array (
  65. 'where' => "postStatus=0 and doPost=1 and status=2",
  66. 'asArray' => TRUE
  67. ) );
  68. // 发票打印
  69. $print = $invoice->getOne ( array (
  70. 'where' => "status=2 and printStatus=0 and moldManage like '%[\"" . $st[0]['sid'] . "\",%'",
  71. 'desc' => 'iid',
  72. 'asArray' => TRUE
  73. ) );
  74. // 发票退票
  75. $untread = $invoice->getOne ( array (
  76. 'where' => " printStatus=1 and untreadStatus=1 and status=2 ",
  77. 'asArray' => TRUE
  78. ) );
  79. $new = array (
  80. 'GLOBAL' => FALSE,
  81. 'pendingInvoice' => FALSE,
  82. 'myClaim' => FALSE,
  83. 'approval' => FALSE,
  84. 'post' => FALSE,
  85. 'print' => FALSE,
  86. 'untread' => FALSE
  87. );
  88. if (!empty($exeGlobal)){
  89. if (! empty ( $pendingInvoice ) || ! empty ( $myClaim ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  90. $new ['GLOBAL'] = TRUE;
  91. }else{
  92. if (! empty ( $pendingInvoice ) || ! empty ( $myClaim ) )
  93. $new ['GLOBAL'] = TRUE;
  94. }
  95. if (! empty ( $pendingInvoice ))
  96. $new ['pendingInvoice'] = TRUE;
  97. if (! empty ( $myClaim ))
  98. $new ['myClaim'] = TRUE;
  99. if (! empty ( $approval ))
  100. $new ['approval'] = TRUE;
  101. if (! empty ( $post ))
  102. $new ['post'] = TRUE;
  103. if (! empty ( $print ))
  104. $new ['print'] = TRUE;
  105. if (! empty ( $untread ))
  106. $new ['untread'] = TRUE;
  107. return $new [$type];
  108. }
  109. /**
  110. * 判断发票的审批权限
  111. * @param number $sid 用户ID
  112. * @param string $mold 项目类型
  113. * @return boolean
  114. */
  115. function isInvoiceMoldShow($sid = 0, $mold = '') {
  116. if (! empty ( $sid ) && ! empty ( $mold )) {
  117. Doo::loadModel ( "invoiceManage" );
  118. $invoiceManage = new invoiceManage ();
  119. $imList = $invoiceManage->getInvoiceByMold ( $mold );
  120. $list = array ();
  121. foreach ( $imList ['staffList'] as $k => $v ) {
  122. array_push ( $list, $v [0] );
  123. }
  124. $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
  125. $fileInvoice = json_decode ( $fileInvoice, true );
  126. $delIM = array ();
  127. if (isset ( $fileInvoice [$mold] ))
  128. $delIM = explode ( ',', $fileInvoice [$mold] );
  129. foreach ( $delIM as $key => $value ) {
  130. if (! empty ( $value ))
  131. array_push ( $list, $value );
  132. }
  133. $list = array_unique ( $list );
  134. return inarray ( $sid, $list );
  135. } else
  136. return false;
  137. }
  138. function getGlobals($var) {
  139. if ($var == 'NEW')
  140. getReceiptCount ();
  141. elseif ($var == 'NEW2')
  142. getExeCount ();
  143. // echo $GLOBALS[$var].'/'.$var.'<br/>';
  144. return $GLOBALS [$var];
  145. }
  146. function inarray($v1, $v2) {
  147. return in_array ( $v1, $v2 );
  148. }
  149. function make_date() {
  150. return date ( "Y-m" );
  151. }
  152. function upper($str) {
  153. return strtoupper ( $str );
  154. }
  155. function tofloat($str) {
  156. return sprintf ( "%.2f", $str );
  157. }
  158. function sample_with_args($str, $prefix) {
  159. return $str . ' with args: ' . $prefix;
  160. }
  161. function debug($var) {
  162. if (! empty ( $var )) {
  163. echo '<pre>';
  164. print_r ( $var );
  165. echo '</pre>';
  166. }
  167. }
  168. // This will be called when a function NOT Registered is used in IF or ElseIF statment
  169. function function_deny($var = null) {
  170. echo '<span style="color:#ff0000;">Function denied in IF or ElseIF statement!</span>';
  171. exit ();
  172. }
  173. // Build URL based on route id
  174. function url($id, $param = null, $addRootUrl = false) {
  175. Doo::loadHelper ( 'DooUrlBuilder' );
  176. // param pass in as string with format
  177. // 'param1=>this_is_my_value, param2=>something_here'
  178. if ($param != null) {
  179. $param = explode ( ', ', $param );
  180. $param2 = null;
  181. foreach ( $param as $p ) {
  182. $splited = explode ( '=>', $p );
  183. $param2 [$splited [0]] = $splited [1];
  184. }
  185. return DooUrlBuilder::url ( $id, $param2, $addRootUrl );
  186. }
  187. return DooUrlBuilder::url ( $id, null, $addRootUrl );
  188. }
  189. // Build URL based on controller and method name
  190. function url2($controller, $method, $param = null, $addRootUrl = false) {
  191. Doo::loadHelper ( 'DooUrlBuilder' );
  192. // param pass in as string with format
  193. // 'param1=>this_is_my_value, param2=>something_here'
  194. if ($param != null) {
  195. $param = explode ( ', ', $param );
  196. $param2 = null;
  197. foreach ( $param as $p ) {
  198. $splited = explode ( '=>', $p );
  199. $param2 [$splited [0]] = $splited [1];
  200. }
  201. return DooUrlBuilder::url2 ( $controller, $method, $param2, $addRootUrl );
  202. }
  203. return DooUrlBuilder::url2 ( $controller, $method, null, $addRootUrl );
  204. }
  205. /**
  206. * 获得正在审批的费用单数量
  207. */
  208. function getReceiptCount() {
  209. $status = 2;
  210. $year = date ( 'Y' );
  211. Doo::loadModel ( 'receipt' );
  212. $receipt = new receipt ();
  213. Doo::loadClass ( 'XDeode' );
  214. $XDeode = new XDeode ( 5 );
  215. $st[0]['sid'] = $XDeode->decode ( $_COOKIE["staff"] );
  216. $dateCondition = " and Year(date) =" . $year;
  217. $approvalCondition = ' and (nowStaff like "%,' . $st[0]['sid'] . '%" or nowStaff like "%' . $st[0]['sid'] . ',%" or nowStaff=' . $st[0]['sid'] . ' ) ';
  218. $receiptList = $receipt->find ( array (
  219. 'where' => ' status=' . $status . $dateCondition . $approvalCondition,
  220. 'desc' => 'rid',
  221. 'asArray' => true
  222. ) );
  223. $GLOBALS ['NEW'] = count ( $receiptList );
  224. }
  225. /**
  226. * 获得执行费用的数量
  227. */
  228. function getExeCount() {
  229. Doo::loadModel ( 'receipt' );
  230. $receipt = new receipt ();
  231. Doo::loadClass ( 'XDeode' );
  232. $XDeode = new XDeode ( 5 );
  233. $st[0]['sid'] = $XDeode->decode ( $_COOKIE["staff"] );
  234. $receiptList = $receipt->find ( array (
  235. 'where' => '(executeCopy like \'%["' . $st[0]['sid'] . '%\' and executeStaff NOT LIKE \'%' . $st[0]['sid'] . '%\' ) and (status=1 or status=6)',
  236. 'desc' => 'rid',
  237. 'asArray' => true
  238. ) );
  239. $GLOBALS ['NEW2'] = count ( $receiptList );
  240. }
  241. ?>