InvoiceController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. <?php
  2. /**
  3. * @author darkredz
  4. */
  5. class InvoiceController extends DooController {
  6. public $staff;
  7. public $verifyId;
  8. public $executeId;
  9. public static $NEW = 0;
  10. public static $NEW2 = 0;
  11. private $INVOICEKEY="APPROVAL";
  12. function __construct() {
  13. if(isset($_COOKIE["staff"])){
  14. if(!empty($_COOKIE["staff"])){
  15. Doo::loadModel ( 'staff' );
  16. Doo::loadModel('verify');
  17. $verify=new verify();
  18. $staff = new staff ();
  19. Doo::loadModel("execute");
  20. $execute=new execute();
  21. $verifyList=$verify->find(array('select'=>'staff','asArray'=>true));
  22. $list=array();
  23. //判断角色的审批权限
  24. foreach ($verifyList as $key=>$value){
  25. $ver=json_decode($value['staff']);
  26. foreach ($ver as $k=>$v){
  27. if ($v[1]=='ROLE'){
  28. $roleList=json_decode($v[3]);
  29. foreach ($roleList as $t=>$g){
  30. $gList=explode("_", $g);
  31. array_push($list, $gList[0]);
  32. //print_r($list);
  33. }
  34. }else
  35. array_push($list, $v[0]);
  36. }
  37. }
  38. //判断执行人的审批权限
  39. $executeList=$execute->find(array('select'=>'staff','asArray'=>true));
  40. $list2=array();
  41. foreach ($executeList as $key=>$value){
  42. $ver=json_decode($value['staff']);
  43. foreach ($ver as $k=>$v){
  44. array_push($list2, $v[0]);
  45. }
  46. }
  47. $eidList=file_get_contents("protected/config/execute/execute.ini");
  48. $eidList=array_filter(explode(",", $eidList));
  49. $this->executeId= array_merge($list2,$eidList);
  50. $this->verifyId=$list;
  51. $this->staff=$staff->getUserByIdList($_COOKIE["staff"]);
  52. ReceiptController::$NEW= $this->getReceiptCount();
  53. ReceiptController::$NEW2= $this->getExeCount();
  54. return "/";
  55. }
  56. }
  57. Doo::loadCore ( 'uri/DooUriRouter' );
  58. $router = new DooUriRouter ();
  59. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  60. if($routeRs['1']!="login"){
  61. header ( 'Content-Type:text/html;charset=utf-8' );
  62. @header ( "Location: /login" );
  63. }
  64. }
  65. function invoice(){
  66. $data['memu']="invoice";
  67. $data['staff']=$this->staff;
  68. $data['receiptMemu']='invoice';
  69. $data['verifyId']=$this->verifyId;
  70. $data['executeId']=$this->executeId;
  71. $this->render ( "/admin/invoice", $data );
  72. }
  73. function invoiceAdd(){
  74. Doo::loadModel('L_category');
  75. $lCategory=new L_category();
  76. $category=$lCategory->find(array('asArray'=>true));
  77. $data['category']=$category;
  78. $data['memu']="invoice";
  79. $data['staff']=$this->staff;
  80. $data['receiptMemu']='invoice';
  81. $data['verifyId']=$this->verifyId;
  82. $data['executeId']=$this->executeId;
  83. $this->render ( "/admin/invoiceAdd", $data );
  84. }
  85. function invoiceAddDo(){
  86. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  87. $invoiceType=$this->get_args('invoiceType')&&is_numeric($this->get_args('invoiceType'))?$this->get_args('invoiceType'):0;
  88. $doPost=$this->get_args('doPost')&&is_numeric($this->get_args('doPost'))?$this->get_args('doPost'):0;
  89. $invoicePrice=$this->get_args('invoicePrice')?$this->get_args('invoicePrice'):"";
  90. $invoiceElement=$this->get_args('invoiceElement')?$this->get_args('invoiceElement'):"";
  91. $invoiceTitle=$this->get_args('invoiceTitle')?$this->get_args('invoiceTitle'):"";
  92. $invoiceCompany=$this->get_args('invoiceCompany')?$this->get_args('invoiceCompany'):"";
  93. $TIN=$this->get_args('TIN')?$this->get_args('TIN'):"";
  94. $address=$this->get_args('address')?$this->get_args('address'):"";
  95. $phone=$this->get_args('phone')?$this->get_args('phone'):"";
  96. $bank=$this->get_args('bank')?$this->get_args('bank'):"";
  97. $bankAccount=$this->get_args('bankAccount')?$this->get_args('bankAccount'):"";
  98. $recipients=$this->get_args('recipients')?$this->get_args('recipients'):"";
  99. $recipientsPhone=$this->get_args('recipientsPhone')?$this->get_args('recipientsPhone'):"";
  100. $recipientsAddress=$this->get_args('recipientsAddress')?$this->get_args('recipientsAddress'):"";
  101. $mailItems=$this->get_args('mailItems')?$this->get_args('mailItems'):"";
  102. $remark=$this->get_args('remark')?$this->get_args('remark'):"";
  103. if(!empty($cid)&&!empty($invoicePrice)&&!empty($invoiceElement)){
  104. Doo::loadModel('invoice');
  105. $invoice=new invoice();
  106. Doo::loadModel('L_category');
  107. $lCategory=new L_category();
  108. Doo::loadModel('invoiceManage');
  109. $invoiceManage=new invoiceManage();
  110. $categoryDetil=$lCategory->getOne(array('SELECT'=>'title','where'=>'cid='.$cid,'asArray'=>true));
  111. $invoiceManageDetail=$invoiceManage->getOne(array('SELECT'=>'title','where'=>'mold="发票审批"','asArray'=>true));
  112. $invoice->cid=$cid;
  113. $invoice->categoryName=$categoryDetil['title'];
  114. $invoice->invoiceElement=$invoiceElement;
  115. $invoice->invoicePrice=$invoicePrice;
  116. $invoice->invoiceType=$invoiceType;
  117. if ($invoiceType==0)
  118. $invoice->invoiceTitle=$invoiceTitle;
  119. elseif ($invoiceType==1){
  120. $invoice->invoiceTitle=$invoiceCompany;
  121. $invoice->TIN=$TIN;
  122. $invoice->address=$address;
  123. $invoice->phone=$phone;
  124. $invoice->bank=$bank;
  125. $invoice->bankAccount=$$bankAccount;
  126. }
  127. $invoice->doPost=$doPost;
  128. if ($doPost==1){
  129. $invoice->recipients=$recipients;
  130. $invoice->recipientsPhone=$recipientsPhone;
  131. $invoice->recipientsAddress=$recipientsAddress;
  132. }
  133. $invoice->status=1;
  134. $invoice->invoiceSerial="#F".date("Ymd").mt_rand(1000,9999);
  135. $invoice->date=date("'Y-m-d H:i:s");
  136. $invoice->sid=$this->staff[0]['sid'];
  137. $invoice->userName=$this->staff[0]['username'];
  138. $invoice->invoiceManage=$invoiceManageDetail['staff'];
  139. $staffId=$a=json_decode($invoiceManageDetail['staff']);
  140. $invoice->pendingApprovals=$staffId[0][0];
  141. $invoice->insert();
  142. }
  143. return "/invoice";
  144. }
  145. function invoiceApproval(){
  146. Doo::loadModel('invoice');
  147. $invoice=new invoice();
  148. Doo::loadModel('invoiceManage');
  149. $invoiceManage=new invoiceManage();
  150. $invoiceList=$invoice->find(array('where'=>'status=1 and pendingApprovals='.$this->staff[0]['sid'],'asArray'=>true));
  151. foreach ($invoiceList as $key=>$value){
  152. $invoiceList[$key]['iidKey']=base64_encode($value['iid']);
  153. }
  154. $data['invoiceList']=$invoiceList;
  155. $data['memu']="invoice";
  156. $data['staff']=$this->staff;
  157. $data['receiptMemu']='invoiceApproval';
  158. $data['verifyId']=$this->verifyId;
  159. $data['executeId']=$this->executeId;
  160. $this->render ( "/admin/invoiceApproval", $data );
  161. }
  162. function invoiceDetail(){
  163. $iid=isset($this->params['iid'])?$this->params['iid']:"";
  164. $iid=base64_decode($iid);
  165. Doo::loadModel('invoice');
  166. $invoice=new invoice();
  167. Doo::loadModel('invoiceManage');
  168. $invoiceManage=new invoiceManage();
  169. $invoiceDetail=$invoice->getOne(array('where'=>'status=1 and pendingApprovals='.$this->staff[0]['sid'].' and iid='.$iid,'asArray'=>true));
  170. $invoiceManageDetail=$invoiceManage->getOne(array('SELECT'=>'title','where'=>'mold="发票审批"','asArray'=>true));
  171. $a=json_decode($invoiceManageDetail['staff']);
  172. $data['invoiceDetail']=$invoiceDetail;
  173. $data['INVOICEKEY']=$this->authcode($invoiceDetail['iid'],'');
  174. $data['memu']="invoice";
  175. $data['staff']=$this->staff;
  176. $data['receiptMemu']='invoiceApproval';
  177. $data['verifyId']=$this->verifyId;
  178. $data['executeId']=$this->executeId;
  179. $this->render ( "/admin/invoiceApprovalDetail", $data );
  180. }
  181. function invoiceApprovalDo(){
  182. $iid=$this->get_args('iid')?$this->get_args('iid'):"";
  183. $status=$this->get_args('status')&&is_numeric($this->get_args('status'))?$this->get_args('status'):0;
  184. $opinion=$this->get_args('opinion')?$this->get_args('opinion'):"";
  185. if (!empty($iid)&&!empty($status)&&!empty($opinion)){
  186. if (!($status==2||$status==3||$status==4))
  187. die('illegal request');
  188. Doo::loadModel('invoice');
  189. $invoice=new invoice();
  190. $iid=$this->authcode($iid);
  191. $invoice->getOne(array('where'=>'status=1 and iid='.$iid.' and pendingApprovals='.$this->staff[0]['sid'],'asArray'=>true));
  192. echo $iid.$status.$opinion;
  193. }
  194. }
  195. private function getExeCount(){
  196. Doo::loadModel('receipt');
  197. $receipt=new receipt();
  198. $receiptList=$receipt->find(array('where'=>'(executeCopy like \'%["'.$this->staff[0]['sid'].'%\' and executeStaff NOT LIKE \'%'.$this->staff[0]['sid'].'%\' ) and (status=1 or status=6)','desc'=>'rid','asArray'=>true));
  199. return count($receiptList);
  200. }
  201. private function getReceiptCount(){
  202. $status=2;
  203. $year=date('Y');
  204. Doo::loadModel('receipt');
  205. $receipt=new receipt();
  206. Doo::loadModel('verify');
  207. $dateCondition=" and Year(date) =".$year;
  208. $approvalCondition=' and nowStaff like "%'.$this->staff[0]['sid'].'%" ';
  209. $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  210. return count($receiptList);
  211. }
  212. function _GetFileEXT($filename) {
  213. $pics = explode ( '.', $filename );
  214. $num = count ( $pics );
  215. return $pics [$num - 1];
  216. }
  217. /**
  218. * 获取get或者POST值
  219. * @param string $name 属性名称
  220. * @return fixed 值
  221. */
  222. function get_args($name) {
  223. if (isset ( $_GET [$name] )) {
  224. if (is_array ( $_GET [$name] ))
  225. return $_GET [$name];
  226. else
  227. return addslashes ( $_GET [$name] );
  228. } elseif (isset ( $_POST [$name] )) {
  229. if (is_array ( $_POST [$name] ))
  230. return $_POST [$name];
  231. else
  232. return addslashes ( $_POST [$name] );
  233. } else
  234. return false;
  235. }
  236. /**
  237. * 加密或解密指定字符串
  238. * @param string $string 要加密或解密的字符串
  239. * @param string $operation 当取值为'DECODE'时表示解密,否则为加密
  240. * @param string $key 加解密的key
  241. * @param $expiry 超时值
  242. * */
  243. function authcode($string, $operation = 'DECODE', $key = '', $expiry = 0) {
  244. $ckey_length = 4;
  245. if (! $key) {
  246. $key = $this->INVOICEKEY;
  247. }
  248. $key = md5 ( $key );
  249. $keya = md5 ( substr ( $key, 0, 16 ) );
  250. $keyb = md5 ( substr ( $key, 16, 16 ) );
  251. $keyc = $ckey_length ? ($operation == 'DECODE' ? substr ( $string, 0, $ckey_length ) : substr ( md5 ( microtime () ), - $ckey_length )) : '';
  252. $cryptkey = $keya . md5 ( $keya . $keyc );
  253. $key_length = strlen ( $cryptkey );
  254. $string = $operation == 'DECODE' ? base64_decode ( substr ( $string, $ckey_length ) ) : sprintf ( '%010d', $expiry ? $expiry + time () : 0 ) . substr ( md5 ( $string . $keyb ), 0, 16 ) . $string;
  255. $string_length = strlen ( $string );
  256. $result = '';
  257. $box = range ( 0, 255 );
  258. $rndkey = array ();
  259. for($i = 0; $i <= 255; $i ++) {
  260. $rndkey [$i] = ord ( $cryptkey [$i % $key_length] );
  261. }
  262. for($j = $i = 0; $i < 256; $i ++) {
  263. $j = ($j + $box [$i] + $rndkey [$i]) % 256;
  264. $tmp = $box [$i];
  265. $box [$i] = $box [$j];
  266. $box [$j] = $tmp;
  267. }
  268. for($a = $j = $i = 0; $i < $string_length; $i ++) {
  269. $a = ($a + 1) % 256;
  270. $j = ($j + $box [$a]) % 256;
  271. $tmp = $box [$a];
  272. $box [$a] = $box [$j];
  273. $box [$j] = $tmp;
  274. $result .= chr ( ord ( $string [$i] ) ^ ($box [($box [$a] + $box [$j]) % 256]) );
  275. }
  276. if ($operation == 'DECODE') {
  277. if ((substr ( $result, 0, 10 ) == 0 || substr ( $result, 0, 10 ) - time () > 0) && substr ( $result, 10, 16 ) == substr ( md5 ( substr ( $result, 26 ) . $keyb ), 0, 16 )) {
  278. return substr ( $result, 26 );
  279. } else {
  280. return '';
  281. }
  282. } else {
  283. return $keyc . str_replace ( '=', '', base64_encode ( $result ) );
  284. }
  285. }
  286. }
  287. class ReceiptController{
  288. public static $NEW = 0;
  289. public static $NEW2 = 0;
  290. }
  291. ?>