TemplateTag.php 7.0 KB

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