TemplateTag.php 9.6 KB

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