TemplateTag.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318
  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 printStatus=1 and isDelete=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 untreadStatus=0 and moldManage like '%[\"" . $st[0]['sid'] . "\",%'",
  71. 'desc' => 'iid',
  72. 'asArray' => TRUE
  73. ) );
  74. // 发票退票 printStatus=1 and
  75. $untread = $invoice->getOne ( array (
  76. 'where' => " 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. //|| ! empty ( $myClaim )
  89. if (!empty($exeGlobal)){
  90. if (! empty ( $pendingInvoice ))
  91. $new ['GLOBAL'] = TRUE;
  92. foreach ($exeGlobal as $value){
  93. if ($value['mold']=='发票审批'){
  94. if(! empty ( $approval )){
  95. $new ['GLOBAL'] = TRUE;
  96. break;
  97. }
  98. }
  99. if ($value['mold']=='发票打印'){
  100. if(! empty ( $print )){
  101. $new ['GLOBAL'] = TRUE;
  102. break;
  103. }
  104. }
  105. if ($value['mold']=='发票邮寄'){
  106. if(! empty ( $post )){
  107. $new ['GLOBAL'] = TRUE;
  108. break;
  109. }
  110. }
  111. if ($value['mold']=='发票退票'){
  112. if(! empty ( $untread )){
  113. $new ['GLOBAL'] = TRUE;
  114. break;
  115. }
  116. }
  117. }
  118. // print_r($exeGlobal);die;
  119. // if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
  120. // $new ['GLOBAL'] = TRUE;
  121. }else{
  122. if (! empty ( $pendingInvoice ) )
  123. $new ['GLOBAL'] = TRUE;
  124. }
  125. if (! empty ( $pendingInvoice ))
  126. $new ['pendingInvoice'] = TRUE;
  127. if (! empty ( $myClaim ))
  128. $new ['myClaim'] = TRUE;
  129. if (! empty ( $approval ))
  130. $new ['approval'] = TRUE;
  131. if (! empty ( $post ))
  132. $new ['post'] = TRUE;
  133. if (! empty ( $print ))
  134. $new ['print'] = TRUE;
  135. if (! empty ( $untread ))
  136. $new ['untread'] = TRUE;
  137. return $new [$type];
  138. }
  139. /**
  140. * 判断发票的审批权限
  141. * @param number $sid 用户ID
  142. * @param string $mold 项目类型
  143. * @return boolean
  144. */
  145. function isInvoiceMoldShow($sid = 0, $mold = '') {
  146. if (! empty ( $sid ) && ! empty ( $mold )) {
  147. Doo::loadModel ( "invoiceManage" );
  148. $invoiceManage = new invoiceManage ();
  149. $imList = $invoiceManage->getInvoiceByMold ( $mold );
  150. $list = array ();
  151. foreach ( $imList ['staffList'] as $k => $v ) {
  152. array_push ( $list, $v [0] );
  153. }
  154. $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
  155. $fileInvoice = json_decode ( $fileInvoice, true );
  156. $delIM = array ();
  157. if (isset ( $fileInvoice [$mold] ))
  158. $delIM = explode ( ',', $fileInvoice [$mold] );
  159. foreach ( $delIM as $key => $value ) {
  160. if (! empty ( $value ))
  161. array_push ( $list, $value );
  162. }
  163. $list = array_unique ( $list );
  164. return inarray ( $sid, $list );
  165. } else
  166. return false;
  167. }
  168. function getGlobals($var) {
  169. if ($var == 'NEW')
  170. getReceiptCount ();
  171. elseif ($var == 'NEW2')
  172. getExeCount ();
  173. // echo $GLOBALS[$var].'/'.$var.'<br/>';
  174. return $GLOBALS [$var];
  175. }
  176. function inarray($v1, $v2) {
  177. return in_array ( $v1, $v2 );
  178. }
  179. function make_date() {
  180. return date ( "Y-m" );
  181. }
  182. function upper($str) {
  183. return strtoupper ( $str );
  184. }
  185. function tofloat($str) {
  186. return sprintf ( "%.2f", $str );
  187. }
  188. function sample_with_args($str, $prefix) {
  189. return $str . ' with args: ' . $prefix;
  190. }
  191. function debug($var) {
  192. if (! empty ( $var )) {
  193. echo '<pre>';
  194. print_r ( $var );
  195. echo '</pre>';
  196. }
  197. }
  198. // This will be called when a function NOT Registered is used in IF or ElseIF statment
  199. function function_deny($var = null) {
  200. echo '<span style="color:#ff0000;">Function denied in IF or ElseIF statement!</span>';
  201. exit ();
  202. }
  203. // Build URL based on route id
  204. function url($id, $param = null, $addRootUrl = false) {
  205. Doo::loadHelper ( 'DooUrlBuilder' );
  206. // param pass in as string with format
  207. // 'param1=>this_is_my_value, param2=>something_here'
  208. if ($param != null) {
  209. $param = explode ( ', ', $param );
  210. $param2 = null;
  211. foreach ( $param as $p ) {
  212. $splited = explode ( '=>', $p );
  213. $param2 [$splited [0]] = $splited [1];
  214. }
  215. return DooUrlBuilder::url ( $id, $param2, $addRootUrl );
  216. }
  217. return DooUrlBuilder::url ( $id, null, $addRootUrl );
  218. }
  219. // Build URL based on controller and method name
  220. function url2($controller, $method, $param = null, $addRootUrl = false) {
  221. Doo::loadHelper ( 'DooUrlBuilder' );
  222. // param pass in as string with format
  223. // 'param1=>this_is_my_value, param2=>something_here'
  224. if ($param != null) {
  225. $param = explode ( ', ', $param );
  226. $param2 = null;
  227. foreach ( $param as $p ) {
  228. $splited = explode ( '=>', $p );
  229. $param2 [$splited [0]] = $splited [1];
  230. }
  231. return DooUrlBuilder::url2 ( $controller, $method, $param2, $addRootUrl );
  232. }
  233. return DooUrlBuilder::url2 ( $controller, $method, null, $addRootUrl );
  234. }
  235. /**
  236. * 获得正在审批的费用单数量
  237. */
  238. function getReceiptCount() {
  239. $status = 2;
  240. $year = date ( 'Y' );
  241. Doo::loadModel ( 'receipt' );
  242. $receipt = new receipt ();
  243. Doo::loadClass ( 'XDeode' );
  244. $XDeode = new XDeode ( 5 );
  245. Doo::loadModel ( 'verify' );
  246. $verify = new verify ();
  247. $st[0]['sid'] = $XDeode->decode ( $_COOKIE["staff"] );
  248. $vidList = array ();
  249. $verifyDetail = $verify->find ( array (
  250. 'where' => ' (staff not like "%\"' . $st [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $st [0] ['sid'] . '\",%" or staff like "%\"' . $st [0] ['sid'] . '\_%" )',
  251. 'asArray' => true
  252. ) );
  253. foreach ( $verifyDetail as $key => $value ) {
  254. array_push ( $vidList, $value ['vid'] );
  255. }
  256. $vid = implode ( ",", $vidList );
  257. if (empty ( $verifyDetail ))
  258. $vid = 0;
  259. $dateCondition = " and Year(date) =" . $year;
  260. $approvalCondition = ' and (nowStaff like "%,' . $st[0]['sid'] . '%" or nowStaff like "%' . $st[0]['sid'] . ',%" or nowStaff=' . $st[0]['sid'] . ' ) ';
  261. $receiptList = $receipt->find ( array (
  262. 'where' => ' status=' . $status . $dateCondition . $approvalCondition. ' and verify in (' . $vid . ')',
  263. 'desc' => 'rid',
  264. 'asArray' => true
  265. ) );
  266. $GLOBALS ['NEW'] = count ( $receiptList );
  267. }
  268. /**
  269. * 获得执行费用的数量
  270. */
  271. function getExeCount() {
  272. Doo::loadModel ( 'receipt' );
  273. $receipt = new receipt ();
  274. Doo::loadClass ( 'XDeode' );
  275. $XDeode = new XDeode ( 5 );
  276. $st[0]['sid'] = $XDeode->decode ( $_COOKIE["staff"] );
  277. $receiptList = $receipt->find ( array (
  278. 'where' => '(executeCopy like \'%["' . $st[0]['sid'] . '%\' and executeStaff NOT LIKE \'%' . $st[0]['sid'] . '%\' ) and (status=1 or status=6)',
  279. 'desc' => 'rid',
  280. 'asArray' => true
  281. ) );
  282. $GLOBALS ['NEW2'] = count ( $receiptList );
  283. }
  284. ?>