1
0

mode_finpiaoAction.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. * 此文件是流程模块【finpiao.发票管理】对应控制器接口文件。
  4. */
  5. class mode_finpiaoClassAction extends inputAction{
  6. protected function savebefore($table, $arr, $id, $addbo){
  7. }
  8. protected function saveafter($table, $arr, $id, $addbo){
  9. }
  10. //发票统计
  11. public function piaototalAjax()
  12. {
  13. $rows = array();
  14. $dt1 = $this->post('dt1');
  15. $dt2 = $this->post('dt2');
  16. if(isempt($dt1))$dt1 = date('Y-01');
  17. if(isempt($dt2))$dt2 = date('Y-m');
  18. $dtobj = c('date');
  19. $start = $dt1.'-01';
  20. $enddt = $dtobj->getenddt($dt2);
  21. $jg = $dtobj->datediff('m', $dt1.'-01', $dt2.'-01');
  22. $where = m('admin')->getcompanywhere(1);
  23. $drows = m('finpiao')->getall("`opendt`>='$start' and `opendt`<='$enddt' and `status`=1 ".$where."");
  24. $toarr = array();
  25. foreach($drows as $k=>$rs){
  26. $rq = substr($rs['opendt'],0,7);
  27. if(!isset($toarr[$rq]))$toarr[$rq] = array('moneyshou'=>0,'moneykai'=>0,'moneyzong'=>0);
  28. $fee = floatval($rs['money']);
  29. //收到的
  30. if($rs['type']=='1'){
  31. $toarr[$rq]['moneyshou']+=$fee;
  32. }else{
  33. $toarr[$rq]['moneykai']+=$fee;
  34. }
  35. }
  36. $month = $dt2;
  37. $hjrows= array('moneyshou'=>0,'month' => '合计','moneykai'=>0,'moneyzong'=>0);
  38. for($i=0;$i<=$jg; $i++){
  39. if($i>0){
  40. $month = $dtobj->adddate($dt2.'-01','m',0-$i,'Y-m');
  41. }
  42. $jers = array('moneyshou'=>0,'month' => $month,'moneykai'=>0,'moneyzong'=>0);
  43. if(isset($toarr[$month])){
  44. $jers1 = $toarr[$month];
  45. $jers['moneyshou'] = $jers1['moneyshou'];
  46. $jers['moneykai'] = $jers1['moneykai'];
  47. $jers['moneyzong'] = $jers1['moneykai']-$jers1['moneyshou'];
  48. }
  49. $hjrows['moneyshou']+=$jers['moneyshou'];
  50. $hjrows['moneykai']+=$jers['moneykai'];
  51. $hjrows['moneyzong']+=$jers['moneyzong'];
  52. if($jers['moneyshou']==0)$jers['moneyshou']='';
  53. if($jers['moneykai']==0)$jers['moneykai']='';
  54. if($jers['moneyzong']==0)$jers['moneyzong']='';
  55. $rows[] = $jers;
  56. }
  57. if($hjrows['moneyshou']==0)$hjrows['moneyshou']='';
  58. if($hjrows['moneykai']==0)$hjrows['moneykai']='';
  59. if($hjrows['moneyzong']==0)$hjrows['moneyzong']='';
  60. $rows[] = $hjrows;
  61. foreach($rows as $k=>$rs){
  62. if($rs['moneyshou'])$rows[$k]['moneyshou'] = $this->rock->number($rs['moneyshou']);
  63. if($rs['moneykai'])$rows[$k]['moneykai'] = $this->rock->number($rs['moneykai']);
  64. if($rs['moneyzong'])$rows[$k]['moneyzong'] = $this->rock->number($rs['moneyzong']);
  65. }
  66. $barr = array(
  67. 'rows' => $rows,
  68. 'dt1' => $dt1,
  69. 'dt2' => $dt2,
  70. 'jg' => $jg,
  71. 'totalCount'=>count($rows),
  72. );
  73. if($this->post('execldown')=='true')return $this->exceldown($barr); //导出
  74. return $barr;
  75. }
  76. /**
  77. * 发邮件给客户
  78. */
  79. public function sendemailAjax()
  80. {
  81. $id = (int)$this->get('id','0');
  82. $rs = m('finpiao')->getone('`id`='.$id.'');
  83. if(!$rs || $rs['type']!=0)return returnerror('不存在');
  84. $mairs = m('customer')->getone('`id`='.$rs['maicustid'].'');
  85. if(!$mairs)return returnerror('客户不存在');
  86. $email = $mairs['email'];
  87. if(isempt($email))return returnerror('此客户没有设置邮箱');
  88. $fjar = m('file')->getfilepath('finpiao', $id);
  89. $html = c('html')->createtable(array(
  90. 'custname' => '开票方',
  91. 'maicustname' => '购买方',
  92. 'opendt' => '开票日期',
  93. 'ptype' => '发票类型',
  94. 'daima' => '发票代码',
  95. 'haoma' => '发票号码',
  96. 'money' => '金额',
  97. ), $rs,'发票信息');
  98. $emcont = '您好:<br>这是我们开的发票消息请查收。<br>'.$html.'';
  99. if($fjar[2])$emcont.='<br><b>相关文件:</b><br>'.$fjar[2].'';
  100. $emcont .= '<hr>发送人:'.$rs['optname'].'<br>发送时间:'.$this->now.'';
  101. $msg = m('email')->sendmail('给您开的发票信息',$emcont , array(
  102. 'receemail' => $email,
  103. 'recename' => $rs['maicustname'],
  104. 'receid' => $mairs['id'],
  105. ), array(), 0, array(
  106. 'attachpath'=> $fjar[0],
  107. 'attachname'=> $fjar[1],
  108. ));
  109. if($msg!='ok')return returnerror($msg);
  110. return returnsuccess('已发送给:'.$email.'');
  111. }
  112. }
粤ICP备19079148号