Invoice.php 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. <?php
  2. namespace app\admin\controller\qingdongams\finance;
  3. use addons\qingdongams\model\ConsumeDetail;
  4. use addons\qingdongams\model\ExamineRecord;
  5. use addons\qingdongams\model\File;
  6. use addons\qingdongams\model\Flow;
  7. use addons\qingdongams\model\Message;
  8. use addons\qingdongams\model\Staff;
  9. use app\admin\controller\qingdongams\Base;
  10. use addons\qingdongams\model\Contract;
  11. use addons\qingdongams\model\Customer;
  12. use think\Db;
  13. use think\Exception;
  14. /**
  15. * 发票管理
  16. * @desc 操作文档:https://doc.fastadmin.net/qingdongams
  17. * @desc 软件介绍:https://www.fastadmin.net/store/qingdongams.html
  18. * @desc 售后微信:qingdong_crm
  19. */
  20. class Invoice extends Base
  21. {
  22. protected $relationSearch = true;
  23. /**
  24. * @var \addons\qingdongams\model\Invoice
  25. */
  26. protected $model = null;
  27. public function _initialize()
  28. {
  29. parent::_initialize();
  30. $this->model = new \addons\qingdongams\model\Invoice;
  31. }
  32. /**
  33. * 查看
  34. */
  35. public function index()
  36. {
  37. //设置过滤方法
  38. $this->request->filter(['strip_tags', 'trim']);
  39. if ($this->request->isAjax()) {
  40. if ($this->request->request('keyField')) {
  41. return $this->selectpage();
  42. }
  43. //0:全部 1:我负责的 2:下属负责的
  44. $type = input('type', 0);
  45. switch ($type) {
  46. case 1:
  47. $staff = Staff::info();
  48. $wheres['owner_staff_id'] = $staff->id;
  49. break;
  50. case 2:
  51. $wheres['owner_staff_id'] = array('in', Staff::getLowerStaffId());
  52. break;
  53. default:
  54. $wheres['owner_staff_id'] = array('in', Staff::getMyStaffIds());
  55. break;
  56. }
  57. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  58. $list = $this->model->where($where)->where($wheres)->with(['customer', 'ownerStaff','contract'])->order($sort, $order)->paginate($limit);
  59. $result = array("total" => $list->total(), "rows" => $list->items());
  60. return json($result);
  61. }
  62. return $this->view->fetch();
  63. }
  64. /**
  65. * 添加
  66. */
  67. public function add()
  68. {
  69. if ($this->request->isPost()) {
  70. $params = $this->request->post("row/a");
  71. if ($params) {
  72. $params = $this->preExcludeFields($params);
  73. // 表单验证
  74. if (($result = $this->qingdongamsValidate($params, 'Invoice', 'create')) !== true) {
  75. $this->error($result);
  76. }
  77. $result = false;
  78. $data = $this->request->post('row/a');
  79. if(isset($data['flow_staff_ids'])){
  80. if(!$data['flow_staff_ids']){
  81. $this->error('请选择审批人');
  82. }
  83. }
  84. Db::startTrans();
  85. try {
  86. $result = $this->model::createInvoice($data);
  87. Db::commit();
  88. } catch (Exception $e) {
  89. Db::rollback();
  90. $this->error($e->getMessage());
  91. }
  92. if ($result !== false) {
  93. $this->success('添加成功');
  94. } else {
  95. $this->error(__('No rows were inserted'));
  96. }
  97. }
  98. $this->error(__('Parameter %s can not be empty', ''));
  99. }
  100. $flow = Flow::getsteplist(Flow::INVOICE_STATUS);
  101. if (empty($flow)) {
  102. $this->error('无可用审批流,请联系管理员');
  103. }
  104. $customer_id = input('customer_id', null);
  105. $contract_id = input('contract_id', null);
  106. $this->assign('contract_id', $contract_id);
  107. $this->assign('customer_id', $customer_id);
  108. $this->assign('customer', Customer::get($customer_id));
  109. $this->assign('contract', Contract::get($contract_id));
  110. $this->assign('flow', $flow);
  111. $this->assign('staff', Staff::getStaff());
  112. $this->assign('number',$this->model::getNumber());
  113. return $this->view->fetch();
  114. }
  115. private function operateParasm($datas)
  116. {
  117. $detail_field = ['consume_type', 'consume_date', 'car_number', 'consume_money', 'start_mileage', 'end_mileage', 'mileage', 'file_ids', 'remark', 'detail_id'];
  118. $list = [];
  119. foreach ($datas as $k => $v) {
  120. if (in_array($k, $detail_field) && is_array($v)) {
  121. foreach ($v as $key => $val) {
  122. if ($k == 'detail_id') {
  123. $k = 'id';
  124. }
  125. $list[$key][$k] = $val;
  126. }
  127. }
  128. }
  129. return array_values($list);
  130. }
  131. /**
  132. * 修改
  133. */
  134. public function edit($ids = null)
  135. {
  136. $map['id'] = $ids;
  137. if ($this->request->isAjax()) {
  138. $params = $this->request->post('row/a');
  139. $params = $this->preExcludeFields($params);
  140. $row = $this->model::where(['id' => $ids, 'check_status' => ['in', [0, 1, 3, 4, 5]]])->find();
  141. if (empty($row)) {
  142. $this->error('审核通过的费用不可编辑');
  143. }
  144. Db::startTrans();
  145. try {
  146. $params['id'] = $ids;
  147. $result = $this->model::updateInvoice($params);
  148. Db::commit();
  149. } catch (Exception $e) {
  150. Db::rollback();
  151. $this->error($e->getMessage());
  152. }
  153. if ($result !== false) {
  154. $this->success('修改成功');
  155. } else {
  156. $this->error('修改失败');
  157. }
  158. }
  159. $row = $this->model->where($map)->with(['customer','contract'])->find();
  160. $flow = Flow::getsteplist(Flow::INVOICE_STATUS);
  161. if (empty($flow)) {
  162. $this->error('无可用审批流,请联系管理员');
  163. }
  164. $customer_id = input('customer_id', null);
  165. $contract_id = input('contract_id', null);
  166. $this->assign('contract_id', $contract_id);
  167. $this->assign('customer_id', $customer_id);
  168. $this->assign('customer', Customer::get($customer_id));
  169. $this->assign('contract', Contract::get($contract_id));
  170. $this->assign('flow', $flow);
  171. $row=$row->toArray();
  172. $this->view->assign("row", $row);
  173. $this->assign('staff', Staff::getStaff());
  174. return $this->view->fetch();
  175. }
  176. /**
  177. * 费用详情
  178. */
  179. public function detail($ids = null)
  180. {
  181. $row = $this->model->with(['ownerStaff', 'customer', 'contract'])->where([
  182. 'id' => $ids,
  183. ])->find();
  184. if (empty($row)) {
  185. $this->error(__('No Results were found'));
  186. }
  187. switch($row['type']){
  188. case 0:
  189. $row['type'] = '增值税专用发票';
  190. break;
  191. case 1:
  192. $row['type'] = '增值税普通发票';
  193. break;
  194. case 2:
  195. $row['type'] = '国税通用机打发票';
  196. break;
  197. case 3:
  198. $row['type'] = '地税通用机打发票';
  199. break;
  200. case 4:
  201. $row['type'] = '收据';
  202. break;
  203. default:
  204. $row['type'] = '增值税专用发票';
  205. break;
  206. }
  207. switch($row['head_type']){
  208. case 0:
  209. $row['head_type'] = '单位';
  210. break;
  211. case 1:
  212. $row['head_type'] = '个人';
  213. break;
  214. default:
  215. $row['type'] = '单位';
  216. break;
  217. }
  218. $this->assign('flow', Flow::getstepdetail(Flow::INVOICE_STATUS, $ids));
  219. //标记通知已读
  220. Message::setRead(Message::INVOICE_TYPE, $ids, $this->_staff->id);
  221. //审批记录
  222. $this->assign('examine_record', ExamineRecord::getList(ExamineRecord::INVOICE_TYPE, $ids));
  223. $this->assign('row', $row);
  224. $this->assign('ids', $ids);
  225. return $this->view->fetch();
  226. }
  227. /**
  228. * 删除
  229. */
  230. public function del($ids = "")
  231. {
  232. if (!$this->request->isPost()) {
  233. $this->error(__("Invalid parameters"));
  234. }
  235. $ids = $ids ? $ids : $this->request->post("ids");
  236. $row = $this->model::where(['id' => $ids, 'check_status' => ['in', [0, 1, 3, 4, 5]]])->find();
  237. if (empty($row)) {
  238. $this->error('审核通过的费用不可删除');
  239. }
  240. $row = $this->model->get($ids);
  241. $this->modelValidate = true;
  242. if (!$row) {
  243. $this->error(__('No Results were found'));
  244. }
  245. $row->delete();
  246. $this->success();
  247. }
  248. //标记开票
  249. public function batchstatus($ids = null){
  250. $row = $this->model->where([
  251. 'id' => $ids,
  252. ])->find();
  253. if (empty($row)) {
  254. $this->error(__('No Results were found'));
  255. }
  256. if ($this->request->isAjax()) {
  257. $params = $this->request->post('row/a');
  258. $params = $this->preExcludeFields($params);
  259. Db::startTrans();
  260. try {
  261. $params['id'] = $ids;
  262. $result = $this->model::updateInfo($params);
  263. Db::commit();
  264. } catch (Exception $e) {
  265. Db::rollback();
  266. $this->error($e->getMessage());
  267. }
  268. if ($result !== false) {
  269. $this->success('标记成功');
  270. } else {
  271. $this->error('标记失败');
  272. }
  273. }
  274. $this->assign('row', $row);
  275. $this->assign('ids', $ids);
  276. return $this->view->fetch();
  277. }
  278. }