InvoiceController.php 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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. function __construct() {
  12. if(isset($_COOKIE["staff"])){
  13. if(!empty($_COOKIE["staff"])){
  14. Doo::loadModel ( 'staff' );
  15. Doo::loadModel('verify');
  16. $verify=new verify();
  17. $staff = new staff ();
  18. Doo::loadModel("execute");
  19. $execute=new execute();
  20. $verifyList=$verify->find(array('select'=>'staff','asArray'=>true));
  21. $list=array();
  22. //判断角色的审批权限
  23. foreach ($verifyList as $key=>$value){
  24. $ver=json_decode($value['staff']);
  25. foreach ($ver as $k=>$v){
  26. if ($v[1]=='ROLE'){
  27. $roleList=json_decode($v[3]);
  28. foreach ($roleList as $t=>$g){
  29. $gList=explode("_", $g);
  30. array_push($list, $gList[0]);
  31. //print_r($list);
  32. }
  33. }else
  34. array_push($list, $v[0]);
  35. }
  36. }
  37. //判断执行人的审批权限
  38. $executeList=$execute->find(array('select'=>'staff','asArray'=>true));
  39. $list2=array();
  40. foreach ($executeList as $key=>$value){
  41. $ver=json_decode($value['staff']);
  42. foreach ($ver as $k=>$v){
  43. array_push($list2, $v[0]);
  44. }
  45. }
  46. $eidList=file_get_contents("protected/config/execute/execute.ini");
  47. $eidList=array_filter(explode(",", $eidList));
  48. $this->executeId= array_merge($list2,$eidList);
  49. $this->verifyId=$list;
  50. $this->staff=$staff->getUserByIdList($_COOKIE["staff"]);
  51. ReceiptController::$NEW= $this->getReceiptCount();
  52. ReceiptController::$NEW2= $this->getExeCount();
  53. return "/";
  54. }
  55. }
  56. Doo::loadCore ( 'uri/DooUriRouter' );
  57. $router = new DooUriRouter ();
  58. $routeRs = $router->execute ( Doo::app ()->route, Doo::conf ()->SUBFOLDER );
  59. if($routeRs['1']!="login"){
  60. header ( 'Content-Type:text/html;charset=utf-8' );
  61. @header ( "Location: /login" );
  62. }
  63. }
  64. function invoice(){
  65. $data['memu']="invoice";
  66. $data['staff']=$this->staff;
  67. $data['receiptMemu']='invoice';
  68. $data['verifyId']=$this->verifyId;
  69. $data['executeId']=$this->executeId;
  70. $this->render ( "/admin/invoice", $data );
  71. }
  72. function invoiceAdd(){
  73. Doo::loadModel('L_category');
  74. $lCategory=new L_category();
  75. $category=$lCategory->find(array('asArray'=>true));
  76. $data['category']=$category;
  77. $data['memu']="invoice";
  78. $data['staff']=$this->staff;
  79. $data['receiptMemu']='invoice';
  80. $data['verifyId']=$this->verifyId;
  81. $data['executeId']=$this->executeId;
  82. $this->render ( "/admin/invoiceAdd", $data );
  83. }
  84. function invoiceAddDo(){
  85. $cid=$this->get_args('cid')&&is_numeric($this->get_args('cid'))?$this->get_args('cid'):0;
  86. $invoiceType=$this->get_args('invoiceType')&&is_numeric($this->get_args('invoiceType'))?$this->get_args('invoiceType'):0;
  87. $doPost=$this->get_args('doPost')&&is_numeric($this->get_args('doPost'))?$this->get_args('doPost'):0;
  88. $invoicePrice=$this->get_args('invoicePrice')?$this->get_args('invoicePrice'):"";
  89. $invoiceElement=$this->get_args('invoiceElement')?$this->get_args('invoiceElement'):"";
  90. $invoiceTitle=$this->get_args('invoiceTitle')?$this->get_args('invoiceTitle'):"";
  91. $invoiceCompany=$this->get_args('invoiceCompany')?$this->get_args('invoiceCompany'):"";
  92. $TIN=$this->get_args('TIN')?$this->get_args('TIN'):"";
  93. $address=$this->get_args('address')?$this->get_args('address'):"";
  94. $phone=$this->get_args('phone')?$this->get_args('phone'):"";
  95. $bank=$this->get_args('bank')?$this->get_args('bank'):"";
  96. $bankAccount=$this->get_args('bankAccount')?$this->get_args('bankAccount'):"";
  97. $recipients=$this->get_args('recipients')?$this->get_args('recipients'):"";
  98. $recipientsPhone=$this->get_args('recipientsPhone')?$this->get_args('recipientsPhone'):"";
  99. $recipientsAddress=$this->get_args('recipientsAddress')?$this->get_args('recipientsAddress'):"";
  100. $mailItems=$this->get_args('mailItems')?$this->get_args('mailItems'):"";
  101. $remark=$this->get_args('remark')?$this->get_args('remark'):"";
  102. //&&!empty($invoiceTitle)&&!empty($invoiceCompany)&&!empty($TIN)&&!empty($address)
  103. // &&!empty($phone)&&!empty($bank)&&!empty($bankAccount)&&!empty($recipients)&&!empty($recipientsPhone)&&!empty($recipientsAddress)
  104. if(!empty($cid)&&!empty($invoicePrice)&&!empty($invoiceElement)){
  105. Doo::loadModel('invoice');
  106. $invoice=new invoice();
  107. Doo::loadModel('L_category');
  108. $lCategory=new L_category();
  109. Doo::loadModel('invoiceManage');
  110. $invoiceManage=new invoiceManage();
  111. $categoryDetil=$lCategory->getOne(array('SELECT'=>'title','where'=>'cid='.$cid,'asArray'=>true));
  112. $invoiceManageDetail=$invoiceManage->getOne(array('SELECT'=>'title','where'=>'mold="发票审批"','asArray'=>true));
  113. $invoice->cid=$cid;
  114. $invoice->categoryName=$categoryDetil['title'];
  115. $invoice->invoiceElement=$invoiceElement;
  116. $invoice->invoicePrice=$invoicePrice;
  117. $invoice->invoiceType=$invoiceType;
  118. if ($invoiceType==0)
  119. $invoice->invoiceTitle=$invoiceTitle;
  120. elseif ($invoiceType==1){
  121. $invoice->invoiceTitle=$invoiceCompany;
  122. $invoice->TIN=$TIN;
  123. $invoice->address=$address;
  124. $invoice->phone=$phone;
  125. $invoice->bank=$bank;
  126. $invoice->bankAccount=$$bankAccount;
  127. }
  128. $invoice->doPost=$doPost;
  129. if ($doPost==1){
  130. $invoice->recipients=$recipients;
  131. $invoice->recipientsPhone=$recipientsPhone;
  132. $invoice->recipientsAddress=$recipientsAddress;
  133. }
  134. $invoice->status=1;
  135. $invoice->invoiceSerial="#F".date("Ymd").mt_rand(1000,9999);
  136. $invoice->date=date("'Y-m-d H:i:s");
  137. $invoice->sid=$this->staff[0]['sid'];
  138. $invoice->userName=$this->staff[0]['username'];
  139. $invoice->invoiceManage=$invoiceManageDetail['staff'];
  140. $staffId=$a=json_decode($invoiceManageDetail['staff']);
  141. $invoice->pendingApprovals=$staffId[0][0];
  142. $invoice->insert();
  143. }
  144. return "/invoice";
  145. }
  146. function invoiceApproval(){
  147. Doo::loadModel('invoice');
  148. $invoice=new invoice();
  149. Doo::loadModel('invoiceManage');
  150. $invoiceManage=new invoiceManage();
  151. $invoiceList=$invoice->find(array('where'=>'status=1 and pendingApprovals='.$this->staff[0]['sid'],'asArray'=>true));
  152. $data['invoiceList']=$invoiceList;
  153. $data['memu']="invoice";
  154. $data['staff']=$this->staff;
  155. $data['receiptMemu']='invoiceApproval';
  156. $data['verifyId']=$this->verifyId;
  157. $data['executeId']=$this->executeId;
  158. $this->render ( "/admin/invoiceApproval", $data );
  159. }
  160. function invoiceDetail(){
  161. $iid=isset($this->params['iid'])&&is_numeric($this->params['iid'])?$this->params['iid']:0;
  162. Doo::loadModel('invoice');
  163. $invoice=new invoice();
  164. Doo::loadModel('invoiceManage');
  165. $invoiceManage=new invoiceManage();
  166. $invoiceDetail=$invoice->getOne(array('where'=>'status=1 and pendingApprovals='.$this->staff[0]['sid'],'asArray'=>true));
  167. $invoiceManageDetail=$invoiceManage->getOne(array('SELECT'=>'title','where'=>'mold="发票审批"','asArray'=>true));
  168. $a=json_decode($invoiceManageDetail['staff']);
  169. $data['invoiceDetail']=$invoiceDetail;
  170. $data['memu']="invoice";
  171. $data['staff']=$this->staff;
  172. $data['receiptMemu']='invoiceApproval';
  173. $data['verifyId']=$this->verifyId;
  174. $data['executeId']=$this->executeId;
  175. $this->render ( "/admin/invoiceApprovalDetail", $data );
  176. }
  177. private function getExeCount(){
  178. Doo::loadModel('receipt');
  179. $receipt=new receipt();
  180. $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));
  181. return count($receiptList);
  182. }
  183. private function getReceiptCount(){
  184. $status=2;
  185. $year=date('Y');
  186. Doo::loadModel('receipt');
  187. $receipt=new receipt();
  188. Doo::loadModel('verify');
  189. $dateCondition=" and Year(date) =".$year;
  190. $approvalCondition=' and nowStaff like "%'.$this->staff[0]['sid'].'%" ';
  191. $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  192. return count($receiptList);
  193. }
  194. function _GetFileEXT($filename) {
  195. $pics = explode ( '.', $filename );
  196. $num = count ( $pics );
  197. return $pics [$num - 1];
  198. }
  199. /**
  200. * 获取get或者POST值
  201. * @param string $name 属性名称
  202. * @return fixed 值
  203. */
  204. function get_args($name) {
  205. if (isset ( $_GET [$name] )) {
  206. if (is_array ( $_GET [$name] ))
  207. return $_GET [$name];
  208. else
  209. return addslashes ( $_GET [$name] );
  210. } elseif (isset ( $_POST [$name] )) {
  211. if (is_array ( $_POST [$name] ))
  212. return $_POST [$name];
  213. else
  214. return addslashes ( $_POST [$name] );
  215. } else
  216. return false;
  217. }
  218. function num_to_rmb($num){
  219. $c1 = "零壹贰叁肆伍陆柒捌玖";
  220. $c2 = "分角元拾佰仟万拾佰仟亿";
  221. //精确到分后面就不要了,所以只留两个小数位
  222. $num = round($num, 2);
  223. //将数字转化为整数
  224. $num = $num * 100;
  225. if (strlen($num) > 10) {
  226. return "金额太大,请检查";
  227. }
  228. $i = 0;
  229. $c = "";
  230. while (1) {
  231. if ($i == 0) {
  232. //获取最后一位数字
  233. $n = substr($num, strlen($num)-1, 1);
  234. } else {
  235. $n = $num % 10;
  236. }
  237. //每次将最后一位数字转化为中文
  238. $p1 = substr($c1, 3 * $n, 3);
  239. $p2 = substr($c2, 3 * $i, 3);
  240. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  241. $c = $p1 . $p2 . $c;
  242. } else {
  243. $c = $p1 . $c;
  244. }
  245. $i = $i + 1;
  246. //去掉数字最后一位了
  247. $num = $num / 10;
  248. $num = (int)$num;
  249. //结束循环
  250. if ($num == 0) {
  251. break;
  252. }
  253. }
  254. $j = 0;
  255. $slen = strlen($c);
  256. while ($j < $slen) {
  257. //utf8一个汉字相当3个字符
  258. $m = substr($c, $j, 6);
  259. //处理数字中很多0的情况,每次循环去掉一个汉字“零”
  260. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  261. $left = substr($c, 0, $j);
  262. $right = substr($c, $j + 3);
  263. $c = $left . $right;
  264. $j = $j-3;
  265. $slen = $slen-3;
  266. }
  267. $j = $j + 3;
  268. }
  269. //这个是为了去掉类似23.0中最后一个“零”字
  270. if (substr($c, strlen($c)-3, 3) == '零') {
  271. $c = substr($c, 0, strlen($c)-3);
  272. }
  273. //将处理的汉字加上“整”
  274. if (empty($c)) {
  275. return "零元整";
  276. }else{
  277. return $c . "整";
  278. }
  279. }
  280. }
  281. class ReceiptController{
  282. public static $NEW = 0;
  283. public static $NEW2 = 0;
  284. }
  285. ?>