InvoiceController.php 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  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. $categoryDetil=$lCategory->getOne(array('SELECT'=>'title','where'=>'cid='.$cid,'asArray'=>true));
  110. $invoice->cid=$cid;
  111. $invoice->categoryName=$categoryDetil['title'];
  112. $invoice->invoiceElement=$invoiceElement;
  113. $invoice->invoicePrice=$invoicePrice;
  114. $invoice->invoiceType=$invoiceType;
  115. if ($invoiceType==0)
  116. $invoice->invoiceTitle=$invoiceTitle;
  117. elseif ($invoiceType==1){
  118. $invoice->invoiceTitle=$invoiceCompany;
  119. $invoice->TIN=$TIN;
  120. $invoice->address=$address;
  121. $invoice->phone=$phone;
  122. $invoice->bank=$bank;
  123. $invoice->bankAccount=$$bankAccount;
  124. }
  125. $invoice->doPost=$doPost;
  126. if ($doPost==1){
  127. $invoice->recipients=$recipients;
  128. $invoice->recipientsPhone=$recipientsPhone;
  129. $invoice->recipientsAddress=$recipientsAddress;
  130. }
  131. $invoice->status=1;
  132. $invoice->invoiceSerial="#F".date("Ymd").mt_rand(1000,9999);
  133. $invoice->date=date("'Y-m-d H:i:s");
  134. $invoice->sid=$this->staff[0]['sid'];
  135. $invoice->userName=$this->staff[0]['username'];
  136. $invoice->insert();
  137. }
  138. return "/invoice";
  139. }
  140. function invoiceApproval(){
  141. Doo::loadModel('invoice');
  142. $invoice=new invoice();
  143. $invoiceList=$invoice->find(array('where'=>'status=1','asArray'=>true));
  144. $data['invoiceList']=$invoiceList;
  145. $data['memu']="invoice";
  146. $data['staff']=$this->staff;
  147. $data['receiptMemu']='invoiceApproval';
  148. $data['verifyId']=$this->verifyId;
  149. $data['executeId']=$this->executeId;
  150. $this->render ( "/admin/invoiceApproval", $data );
  151. }
  152. private function getExeCount(){
  153. Doo::loadModel('receipt');
  154. $receipt=new receipt();
  155. $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));
  156. return count($receiptList);
  157. }
  158. private function getReceiptCount(){
  159. $status=2;
  160. $year=date('Y');
  161. Doo::loadModel('receipt');
  162. $receipt=new receipt();
  163. Doo::loadModel('verify');
  164. $dateCondition=" and Year(date) =".$year;
  165. $approvalCondition=' and nowStaff like "%'.$this->staff[0]['sid'].'%" ';
  166. $receiptList=$receipt->find(array('where'=>' status='.$status.$dateCondition.$approvalCondition,'desc'=>'rid','asArray'=>true));
  167. return count($receiptList);
  168. }
  169. function _GetFileEXT($filename) {
  170. $pics = explode ( '.', $filename );
  171. $num = count ( $pics );
  172. return $pics [$num - 1];
  173. }
  174. /**
  175. * 获取get或者POST值
  176. * @param string $name 属性名称
  177. * @return fixed 值
  178. */
  179. function get_args($name) {
  180. if (isset ( $_GET [$name] )) {
  181. if (is_array ( $_GET [$name] ))
  182. return $_GET [$name];
  183. else
  184. return addslashes ( $_GET [$name] );
  185. } elseif (isset ( $_POST [$name] )) {
  186. if (is_array ( $_POST [$name] ))
  187. return $_POST [$name];
  188. else
  189. return addslashes ( $_POST [$name] );
  190. } else
  191. return false;
  192. }
  193. function num_to_rmb($num){
  194. $c1 = "零壹贰叁肆伍陆柒捌玖";
  195. $c2 = "分角元拾佰仟万拾佰仟亿";
  196. //精确到分后面就不要了,所以只留两个小数位
  197. $num = round($num, 2);
  198. //将数字转化为整数
  199. $num = $num * 100;
  200. if (strlen($num) > 10) {
  201. return "金额太大,请检查";
  202. }
  203. $i = 0;
  204. $c = "";
  205. while (1) {
  206. if ($i == 0) {
  207. //获取最后一位数字
  208. $n = substr($num, strlen($num)-1, 1);
  209. } else {
  210. $n = $num % 10;
  211. }
  212. //每次将最后一位数字转化为中文
  213. $p1 = substr($c1, 3 * $n, 3);
  214. $p2 = substr($c2, 3 * $i, 3);
  215. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  216. $c = $p1 . $p2 . $c;
  217. } else {
  218. $c = $p1 . $c;
  219. }
  220. $i = $i + 1;
  221. //去掉数字最后一位了
  222. $num = $num / 10;
  223. $num = (int)$num;
  224. //结束循环
  225. if ($num == 0) {
  226. break;
  227. }
  228. }
  229. $j = 0;
  230. $slen = strlen($c);
  231. while ($j < $slen) {
  232. //utf8一个汉字相当3个字符
  233. $m = substr($c, $j, 6);
  234. //处理数字中很多0的情况,每次循环去掉一个汉字“零”
  235. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  236. $left = substr($c, 0, $j);
  237. $right = substr($c, $j + 3);
  238. $c = $left . $right;
  239. $j = $j-3;
  240. $slen = $slen-3;
  241. }
  242. $j = $j + 3;
  243. }
  244. //这个是为了去掉类似23.0中最后一个“零”字
  245. if (substr($c, strlen($c)-3, 3) == '零') {
  246. $c = substr($c, 0, strlen($c)-3);
  247. }
  248. //将处理的汉字加上“整”
  249. if (empty($c)) {
  250. return "零元整";
  251. }else{
  252. return $c . "整";
  253. }
  254. }
  255. }
  256. class ReceiptController{
  257. public static $NEW = 0;
  258. public static $NEW2 = 0;
  259. }
  260. ?>