TemplateTag.php 8.8 KB

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