| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557 |
- <?php
- // register global/PHP functions to be used with your template files
- // You can move this to common.conf.php $config['TEMPLATE_GLOBAL_TAGS'] = array('isset', 'empty');
- // 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
- Doo::conf ()->TEMPLATE_GLOBAL_TAGS = array (
- 'isTimeTR',
- 'isInvoiceNew',
- 'isHRNew',
- 'upper',
- 'tofloat',
- 'sample_with_args',
- 'debug',
- 'url',
- 'url2',
- 'function_deny',
- 'isset',
- 'empty',
- 'make_date',
- 'inarray',
- 'getGlobals',
- 'countArray',
- 'isInvoiceMoldShow',
- 'isReceiptAuthorityShow',
- 'isInvoiceAggregateCompanyShow',
- 'forMatAccess',
- 'isShowMenu',
- 'isStaffCompleteMsg',
- 'isInvoiceCategoryShow',
- 'isReceiptTrainShow',
- 'isPaymentsShow',
- 'isUrlEncode',
- 'isGHNews',
- 'numberFormat'
- );
- function numberFormat($a, $b) {
- return number_format ( $a, $b );
- }
- function isGHNews($staffGH) {
-
-
- $count=file_get_contents ( 'http://gh.cld.smartcost.com.cn/api/gh/receiptNews?staffId=' . $_COOKIE ["staff"] );
-
- return $count;
-
- // $BuildUrl = 'http://gh.cld.smartcost.com.cn';
- // // $url = $BuildUrl. '/mcm/authorize/receiptNewsTip?staffGH='. urlencode($staffGH);
- // // echo $url;
- // $url = $BuildUrl . '/mcm/authorize/receiptNewsTip';
- // $data = array (
- // "staffGH" => $_COOKIE ['staffGH']
- // );
-
- // $result = json_decode ( curl_request ( $url, $data ), true );
- // return $result ['count'];
- // print_r($result);
- // $isNews=false;
- // if($result['falg'])
- // $isNews=true;
- // return $isNews;
- }
- function isUrlEncode($url) {
- Doo::loadClass ( 'auth' );
- $auth = new auth ();
- $staffGH = $auth->yundanran_auth ( $url, 'DECODE', "GH" );
-
- $staffGH = $auth->yundanran_auth ( $staffGH, '', "GH" );
-
- return urlencode ( $staffGH );
- }
- function isStaffCompleteMsg() {
- // 检测用户信息完成
- Doo::loadModel ( 'staff' );
- $staff = new staff ();
- $isStaffCompleteMsg = false;
- if (! isset ( $_COOKIE ["staff"] ))
- return false;
- $detail = $staff->checkStaffInfoIsComplete ( $_COOKIE ["staff"] );
- if (! empty ( $detail ))
- $isStaffCompleteMsg = true;
- return $isStaffCompleteMsg;
- }
- function forMatAccess($access = array()) {
- $html = '';
- $accessMsg = array (
- 'INFORMATION' => '信息中心',
- 'DIRECTORIES' => '通讯录',
- 'LOCK' => '在线锁库',
- 'RECEIPTS' => '报销单',
- 'INVOICE' => '发票申请',
- 'HR' => '人资管理',
- 'BUILD' => '建筑计价'
- );
- if (empty ( $access ))
- return '';
- foreach ( $access as $value ) {
- $html .= $accessMsg [$value] . ' ';
- }
- return $html;
- }
- function countArray($list = array(), $count = 0) {
- return count ( $list ) + $count;
- }
- function isTimeTR($day = 3, $cTime) {
- $flag = false;
- $thenTime = time ();
- $futureTime = strtotime ( '+' . $day . ' day', strtotime ( $cTime ) );
- if ($thenTime < $futureTime)
- $flag = true;
-
- return $flag;
- }
- function isShowMenu($menu = '') {
- Doo::loadModel ( 'staff' );
- $staff = new staff ();
- $st = $staff->getStaffBySid ( $_COOKIE ["staff"] );
-
- $cldAccess = array ();
- if (! empty ( $st ['cldAccess'] ))
- $cldAccess = json_decode ( $st ['cldAccess'], true );
-
- Doo::loadModel ( "staffManage" );
- $staffManage = new staffManage ();
- $smList = $staffManage->getInvoiceCMByStaff ( $_COOKIE ["staff"] );
-
- // 是否有登陆者需要审批的员工
- $list = array ();
- if ($menu == 'HR') {
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- $uid = $XDeode->decode ( $_COOKIE ["staff"] );
- $list = $staff->find ( array (
- 'asc' => 'sid',
- 'where' => "(pendStatus= '2' or pendStatus='3' or pendStatus='5' or pendStatus='6') and ( pendingApprovalsLeave='" . $uid . "' or pendingApprovals='" . $uid . "') ",
- 'asArray' => TRUE
- ) );
- }
-
- if (in_array ( $menu, $cldAccess ) || ($st ['sid'] == superHR && $menu == 'HR') || (count ( $list ) > 0 && $menu == 'HR')) {
-
- return true;
- }
-
- if (empty ( $cldAccess )) {
-
- return false;
- }
-
- return false;
- }
- function isHRNew() {
- Doo::loadModel ( 'staff' );
- $staff = new staff ();
-
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
-
- $uid = $XDeode->decode ( $_COOKIE ["staff"] );
-
- $list = $staff->find ( array (
- 'asc' => 'sid',
- 'where' => "(pendStatus= '2' or pendStatus='3' or pendStatus='5' or pendStatus='6') and ( pendingApprovalsLeave='" . $uid . "' or pendingApprovals='" . $uid . "') ",
- 'asArray' => TRUE
- ) );
-
- return count ( $list );
- }
- function isInvoiceNew($type = "GLOBAL") {
- Doo::loadModel ( 'invoice' );
- $invoice = new invoice ();
- Doo::loadModel ( 'invoiceReceivables' );
- $invoiceReceivables = new invoiceReceivables ();
- Doo::loadModel ( 'staff' );
- $staff = new staff ();
- Doo::loadModel ( "invoiceManage" );
- $execute = new invoiceManage ();
-
- $st = $staff->getUserByIdList ( $_COOKIE ["staff"] );
-
- $exeGlobal = $execute->getInvoiceByStaff ( $st [0] ['sid'] );
-
- // 我的发票待处理
- $pendingInvoice = $invoice->getOne ( array ( // or (status=2 and printStatus=1 and untreadStatus=0 ) or (status=2 and printStatus=1 and untreadStatus=2 )
- 'where' => "(status=3 or status=4 ) and isDelete=0 and sid=" . $st [0] ['sid'],
- 'desc' => 'iid',
- 'asArray' => TRUE
- ) );
- // 我的收款待入账
- // $myClaim = $invoiceReceivables->getOne ( array (
- // 'where' => " receivablesStaff like '" . $st[0]['sid'] . "-%' and receivablesCategory like '" . $st [0] ['cid'] . ":%' and bindStatus=0",
- // 'desc' => 'irid',
- // 'asArray' => TRUE
- // ) );
-
- // 发票审批
- $approval = $invoice->getOne ( array (
- 'where' => 'status=1 and pendingApprovals=' . $st [0] ['sid'],
- 'desc' => 'iid',
- 'asArray' => true
- ) );
- // 发票邮寄
- $post = $invoice->getOne ( array (
- 'where' => "postStatus=0 and printStatus=1 and isDelete=0 and doPost=1 and status=2",
- 'asArray' => TRUE
- ) );
- // 发票打印
- $print = $invoice->getOne ( array (
- 'where' => "status=2 and printStatus=0 and untreadStatus=0 and moldManage like '%[\"" . $st [0] ['sid'] . "\",%'",
- 'desc' => 'iid',
- 'asArray' => TRUE
- ) );
-
- // 发票退票 printStatus=1 and
- $untread = $invoice->getOne ( array (
- 'where' => " untreadStatus=1 and status=2 ",
- 'asArray' => TRUE
- ) );
-
- $new = array (
- 'GLOBAL' => FALSE,
- 'pendingInvoice' => FALSE,
- 'myClaim' => FALSE,
- 'approval' => FALSE,
- 'post' => FALSE,
- 'print' => FALSE,
- 'untread' => FALSE
- );
-
- // || ! empty ( $myClaim )
- if (! empty ( $exeGlobal )) {
- if (! empty ( $pendingInvoice ))
- $new ['GLOBAL'] = TRUE;
-
- foreach ( $exeGlobal as $value ) {
- if ($value ['mold'] == '发票审批') {
- if (! empty ( $approval )) {
- $new ['GLOBAL'] = TRUE;
- break;
- }
- }
-
- if ($value ['mold'] == '发票打印') {
- if (! empty ( $print )) {
- $new ['GLOBAL'] = TRUE;
- break;
- }
- }
-
- if ($value ['mold'] == '发票邮寄') {
- if (! empty ( $post )) {
- $new ['GLOBAL'] = TRUE;
- break;
- }
- }
-
- if ($value ['mold'] == '发票退票') {
- if (! empty ( $untread )) {
- $new ['GLOBAL'] = TRUE;
- break;
- }
- }
- }
-
- // print_r($exeGlobal);die;
- // if (! empty ( $pendingInvoice ) || ! empty ( $approval ) || ! empty ( $post ) || ! empty ( $print ) || ! empty ( $untread ))
- // $new ['GLOBAL'] = TRUE;
- } else {
- if (! empty ( $pendingInvoice ))
- $new ['GLOBAL'] = TRUE;
- }
-
- if (! empty ( $pendingInvoice ))
- $new ['pendingInvoice'] = TRUE;
- if (! empty ( $myClaim ))
- $new ['myClaim'] = TRUE;
- if (! empty ( $approval ))
- $new ['approval'] = TRUE;
- if (! empty ( $post ))
- $new ['post'] = TRUE;
- if (! empty ( $print ))
- $new ['print'] = TRUE;
- if (! empty ( $untread ))
- $new ['untread'] = TRUE;
- return $new [$type];
- }
- /**
- * 是否有查看汇总的权限
- * @param unknown $sid
- */
- function isInvoiceCategoryShow($sid) {
- Doo::loadModel ( "invoiceCategoryManage" );
- $invoiceCategoryManage = new invoiceCategoryManage ();
-
- $icm = $invoiceCategoryManage->getInvoiceCMByStaff ( $sid );
- if (! empty ( $icm ))
- return true;
- else
- return false;
- }
- /**
- * 是否有查看培训班结算营收的权限
- * @param unknown $sid
- */
- function isReceiptTrainShow($sid) {
- Doo::loadModel ( "receiptTrainManage" );
- $invoiceCategoryManage = new receiptTrainManage ();
-
- $icm = $invoiceCategoryManage->getInvoiceCMByStaff ( $sid );
- if (! empty ( $icm ))
- return true;
- else
- return false;
- }
- /**
- * 是否有查看日常收支的权限
- */
- function isPaymentsShow($sid) {
- Doo::loadModel ( "execute" );
- $execute = new execute ();
-
- $list = $execute->find ( array (
- 'where' => '(staff like \'%["' . $sid . '%\' ) and mold="日常收支"',
- 'asArray' => true
- ) );
- if (empty ( $list )) {
- return false;
- } else {
- return true;
- }
- }
- /**
- * 是否有查看应收款的权限
- * @param unknown $sid
- */
- function isInvoiceAggregateCompanyShow($sid) {
- Doo::loadModel ( "invoiceCompanyManage" );
- $receiptAuthorityManage = new invoiceCompanyManage ();
-
- $icm = $receiptAuthorityManage->getInvoiceCMByStaff ( $sid );
- if (! empty ( $icm ))
- return true;
- else
- return false;
- }
- /**
- * 是否有查看报销单汇总的权限
- * @param unknown $sid
- */
- function isReceiptAuthorityShow($sid) {
- Doo::loadModel ( "receiptAuthorityManage" );
- $receiptAuthorityManage = new receiptAuthorityManage ();
-
- $icm = $receiptAuthorityManage->getInvoiceCMByStaff ( $sid );
-
- if (! empty ( $icm ))
- return true;
- else
- return false;
- }
- function isInvoiceCompanyShow($sid) {
- }
- /**
- * 判断发票的审批权限
- * @param number $sid 用户ID
- * @param string $mold 项目类型
- * @return boolean
- */
- function isInvoiceMoldShow($sid = 0, $mold = '') {
- if (! empty ( $sid ) && ! empty ( $mold )) {
- Doo::loadModel ( "invoiceManage" );
- $invoiceManage = new invoiceManage ();
- $imList = $invoiceManage->getInvoiceByMold ( $mold );
- $list = array ();
-
- foreach ( $imList ['staffList'] as $k => $v ) {
- array_push ( $list, $v [0] );
- }
- $fileInvoice = file_get_contents ( "protected/config/invoice/invoice.ini" );
- $fileInvoice = json_decode ( $fileInvoice, true );
- $delIM = array ();
- if (isset ( $fileInvoice [$mold] ))
- $delIM = explode ( ',', $fileInvoice [$mold] );
- foreach ( $delIM as $key => $value ) {
- if (! empty ( $value ))
- array_push ( $list, $value );
- }
- $list = array_unique ( $list );
- return inarray ( $sid, $list );
- } else
- return false;
- }
- function getGlobals($var) {
- if ($var == 'NEW')
- getReceiptCount ();
- elseif ($var == 'NEW2') {
- getExeCount ();
- }
- // echo $GLOBALS[$var].'/'.$var.'<br/>';
- return $GLOBALS [$var];
- // if (! empty ( $GLOBALS [$var] )) {
-
- // }else{
- // $count=file_get_contents ( 'http://gh.cld.smartcost.com.cn/api/gh/receiptNews?staffId=' . $_COOKIE ["staff"] );
- // return $count;
- // }
-
- }
- function inarray($v1, $v2) {
- return in_array ( $v1, $v2 );
- }
- function make_date() {
- return date ( "Y-m" );
- }
- function upper($str) {
- return strtoupper ( $str );
- }
- function tofloat($str) {
- return sprintf ( "%.2f", $str );
- }
- function sample_with_args($str, $prefix) {
- return $str . ' with args: ' . $prefix;
- }
- function debug($var) {
- if (! empty ( $var )) {
- echo '<pre>';
- print_r ( $var );
- echo '</pre>';
- }
- }
- // This will be called when a function NOT Registered is used in IF or ElseIF statment
- function function_deny($var = null) {
- echo '<span style="color:#ff0000;">Function denied in IF or ElseIF statement!</span>';
- exit ();
- }
- // Build URL based on route id
- function url($id, $param = null, $addRootUrl = false) {
- Doo::loadHelper ( 'DooUrlBuilder' );
- // param pass in as string with format
- // 'param1=>this_is_my_value, param2=>something_here'
-
- if ($param != null) {
- $param = explode ( ', ', $param );
- $param2 = null;
- foreach ( $param as $p ) {
- $splited = explode ( '=>', $p );
- $param2 [$splited [0]] = $splited [1];
- }
- return DooUrlBuilder::url ( $id, $param2, $addRootUrl );
- }
-
- return DooUrlBuilder::url ( $id, null, $addRootUrl );
- }
- // Build URL based on controller and method name
- function url2($controller, $method, $param = null, $addRootUrl = false) {
- Doo::loadHelper ( 'DooUrlBuilder' );
- // param pass in as string with format
- // 'param1=>this_is_my_value, param2=>something_here'
-
- if ($param != null) {
- $param = explode ( ', ', $param );
- $param2 = null;
- foreach ( $param as $p ) {
- $splited = explode ( '=>', $p );
- $param2 [$splited [0]] = $splited [1];
- }
- return DooUrlBuilder::url2 ( $controller, $method, $param2, $addRootUrl );
- }
-
- return DooUrlBuilder::url2 ( $controller, $method, null, $addRootUrl );
- }
- /**
- * 获得正在审批的费用单数量
- */
- function getReceiptCount() {
- $status = 2;
- $year = date ( 'Y' );
-
- Doo::loadModel ( 'receipt' );
- $receipt = new receipt ();
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- Doo::loadModel ( 'verify' );
- $verify = new verify ();
-
- $st [0] ['sid'] = $XDeode->decode ( $_COOKIE ["staff"] );
- $vidList = array ();
- $verifyDetail = $verify->find ( array (
- 'where' => ' (staff not like "%\"' . $st [0] ['sid'] . '\",\"ROLE%") and (staff like "%[\"' . $st [0] ['sid'] . '\",%" or staff like "%\"' . $st [0] ['sid'] . '\_%" )',
- 'asArray' => true
- ) );
- foreach ( $verifyDetail as $key => $value ) {
- array_push ( $vidList, $value ['vid'] );
- }
- $vid = implode ( ",", $vidList );
- if (empty ( $verifyDetail ))
- $vid = 0;
-
- $dateCondition = " and Year(date) =" . $year;
- $approvalCondition = ' and (nowStaff like "%,' . $st [0] ['sid'] . '%" or nowStaff like "%' . $st [0] ['sid'] . ',%" or nowStaff=' . $st [0] ['sid'] . ' ) ';
- $receiptList = $receipt->find ( array (
- 'where' => ' status=' . $status . $dateCondition . $approvalCondition . ' and verify in (' . $vid . ')',
- 'desc' => 'rid',
- 'asArray' => true
- ) );
-
- $GLOBALS ['NEW'] = count ( $receiptList );
- }
- /**
- * 获得执行费用的数量
- */
- function getExeCount() {
- Doo::loadModel ( 'receipt' );
- $receipt = new receipt ();
- Doo::loadClass ( 'XDeode' );
- $XDeode = new XDeode ( 5 );
- $st [0] ['sid'] = $XDeode->decode ( $_COOKIE ["staff"] );
- $receiptList = $receipt->find ( array (
- 'where' => '(executeCopy like \'%["' . $st [0] ['sid'] . '%\' and ( executeStaff NOT LIKE \'%' . $st [0] ['sid'] . '%\' or executeStaff is null ) ) and (status=1 or status=6)',
- 'desc' => 'rid',
- 'asArray' => true
- ) );
- $GLOBALS ['NEW2'] = count ( $receiptList );
- }
- /**
- * curl 获取接口数据,data为空时为GET方法,有值则为POST方法
- *
- * @param $url
- * @param string $data
- * @return mixed|string
- */
- function curl_request($url, $data = '') {
- $curl = curl_init ();
- curl_setopt ( $curl, CURLOPT_URL, $url );
- curl_setopt ( $curl, CURLOPT_HEADER, 0 );
- curl_setopt ( $curl, CURLOPT_RETURNTRANSFER, 1 );
- if ($data) {
- curl_setopt ( $curl, CURLOPT_POST, 1 );
- curl_setopt ( $curl, CURLOPT_POSTFIELDS, http_build_query ( $data ) );
- }
- curl_setopt ( $curl, CURLOPT_TIMEOUT, 10 );
- $data = curl_exec ( $curl );
- curl_close ( $curl );
- return $data;
- }
- ?>
|