mode_custfinbAction.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /**
  3. * 客户.付款单
  4. */
  5. class mode_custfinbClassAction extends inputAction{
  6. protected function savebefore($table, $arr, $id, $addbo){
  7. $narr = array();
  8. $htid = (int)$arr['htid'];
  9. $money = floatval($arr['money']);
  10. if($money<=0)return '金额必须大于0';
  11. //从合同读取
  12. if($htid>0){
  13. $htrs = m('custract')->getone($htid);
  14. $narr['htnum'] = $htrs['num'];
  15. $narr['custid'] = $htrs['custid'];
  16. $narr['type'] = $htrs['type'];
  17. $narr['custname'] = $htrs['custname'];
  18. $zmoney = floatval($htrs['money']);
  19. $omoney = m('crm')->getmoneys($htid, $id);
  20. $chaojg = $omoney + $money - $zmoney;
  21. if($chaojg>0)return '金额已超过合同上金额'.$zmoney.'';
  22. }
  23. //从销售单读取
  24. /*
  25. if($htid<0){
  26. $htrs = m('goodm')->getone('`id`='.(0-$htid).'');
  27. $narr['htnum'] = $htrs['num'];
  28. $narr['custid'] = $htrs['custid'];
  29. $narr['type'] = '0';
  30. $narr['custname'] = $htrs['custname'];
  31. $zmoney = floatval($htrs['money']);
  32. $omoney = m('crm')->getmoneys($htid, $id);
  33. $chaojg = $omoney + $money - $zmoney;
  34. if($chaojg>0)return '金额已超过销售单上金额'.$zmoney.'';
  35. }
  36. */
  37. $narr['htid'] = $htid;
  38. if(!isset($narr['type']))$narr['type'] = 1;
  39. return array('rows'=> $narr);
  40. }
  41. protected function saveafter($table, $arr, $id, $addbo){
  42. $htid = (int)$arr['htid'];
  43. if($htid>0)m('crm')->ractmoney($htid);
  44. if($htid<0){
  45. $htrs = m('goodm')->getone('`id`='.(0-$htid).'');
  46. m('crm')->xiaozhuantai($htrs,1);
  47. }
  48. }
  49. public function selectcust()
  50. {
  51. $rows = m('crm')->getmycust($this->adminid, $this->rock->arrvalue($this->rs, 'custid'));
  52. return $rows;
  53. }
  54. public function hetongdata()
  55. {
  56. $htid = 0;
  57. $mid = (int)$this->get('mid','0');
  58. if($mid>0){
  59. $htid = (int)$this->flow->getmou('htid', $mid); //当前记录也要显示合同ID
  60. }
  61. $rows = m('crm')->getmyract($this->adminid, $htid, 1);
  62. $arr = array();
  63. $arr[] = array(
  64. 'value' => '0',
  65. 'name' => '不选择',
  66. );
  67. foreach($rows as $k=>$rs){
  68. $arr[] = array(
  69. 'value' => $rs['id'],
  70. 'optgroup'=>'合同',
  71. 'name' => '['.$rs['num'].']'.$rs['custname'],
  72. );
  73. }
  74. return $arr;
  75. }
  76. public function ractchangeAjax()
  77. {
  78. $htid = (int)$this->get('ractid');
  79. $cars['type'] = '1';
  80. //销售单
  81. if($htid<0){
  82. $xrs = m('goodm')->getone('`id`='.(0-$htid).'');
  83. $cars['custid'] = $xrs['custid'];
  84. $cars['custname'] = $xrs['custname'];
  85. $cars['num'] = $xrs['num'];
  86. $cars['signdt'] = $xrs['applydt'];
  87. $cars['money'] = m('crm')->xiaozhuantai($xrs,1);
  88. }else{
  89. $cars = m('custract')->getone($htid, 'id,custid,custname,money,type,num,signdt');
  90. $omoney = m('crm')->getmoneys($htid);
  91. $cars['money'] = $cars['money']-$omoney;
  92. }
  93. $this->returnjson($cars);
  94. }
  95. protected function storeafter($table, $rows)
  96. {
  97. $money = 0;
  98. $hjfields = arrvalue($this->flow->moders, 'hjfields');
  99. if($rows && isempt($hjfields)){
  100. foreach($rows as $k1=>$rs1){
  101. $money+=floatval($rs1['money']);
  102. }
  103. $carr['money'] = $this->rock->number($money);
  104. $carr['htnum'] = '合计';
  105. $carr['id'] = 0;
  106. $rows[] = $carr;
  107. }
  108. $zhangarr = false;
  109. if($this->loadci==1 && $this->get('pnum')=='finall'){
  110. $zhangarr = m('fina')->getzhangtao();
  111. $zhangarrs= array();
  112. foreach($zhangarr as $k=>$rs){
  113. $zhangarrs[] = array('optgroup'=>'start','name'=>$rs['name']);
  114. $arows = m('fina')->getaccount($rs['value']);
  115. if($arows)foreach($arows as $k1=>$rs1){
  116. $zhangarrs[] = $rs1;
  117. }
  118. $zhangarrs[] = array('optgroup'=>'end','name'=>$rs['name']);
  119. }
  120. $zhangarr = $zhangarrs;
  121. }
  122. return array(
  123. 'rows' => $rows,
  124. 'zhangarr'=> $zhangarr
  125. );
  126. }
  127. }
粤ICP备19079148号