TemplateTag.php 6.4 KB

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