TemplateTag.php 7.0 KB

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