model = new \addons\qingdongams\model\Invoice; } /** * 查看 */ public function index() { //设置过滤方法 $this->request->filter(['strip_tags', 'trim']); if ($this->request->isAjax()) { if ($this->request->request('keyField')) { return $this->selectpage(); } //0:全部 1:我负责的 2:下属负责的 $type = input('type', 0); switch ($type) { case 1: $staff = Staff::info(); $wheres['owner_staff_id'] = $staff->id; break; case 2: $wheres['owner_staff_id'] = array('in', Staff::getLowerStaffId()); break; default: $wheres['owner_staff_id'] = array('in', Staff::getMyStaffIds()); break; } list($where, $sort, $order, $offset, $limit) = $this->buildparams(); $list = $this->model->where($where)->where($wheres)->with(['customer', 'ownerStaff','contract'])->order($sort, $order)->paginate($limit); $result = array("total" => $list->total(), "rows" => $list->items()); return json($result); } return $this->view->fetch(); } /** * 添加 */ public function add() { if ($this->request->isPost()) { $params = $this->request->post("row/a"); if ($params) { $params = $this->preExcludeFields($params); // 表单验证 if (($result = $this->qingdongamsValidate($params, 'Invoice', 'create')) !== true) { $this->error($result); } $result = false; $data = $this->request->post('row/a'); if(isset($data['flow_staff_ids'])){ if(!$data['flow_staff_ids']){ $this->error('请选择审批人'); } } Db::startTrans(); try { $result = $this->model::createInvoice($data); Db::commit(); } catch (Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result !== false) { $this->success('添加成功'); } else { $this->error(__('No rows were inserted')); } } $this->error(__('Parameter %s can not be empty', '')); } $flow = Flow::getsteplist(Flow::INVOICE_STATUS); if (empty($flow)) { $this->error('无可用审批流,请联系管理员'); } $customer_id = input('customer_id', null); $contract_id = input('contract_id', null); $this->assign('contract_id', $contract_id); $this->assign('customer_id', $customer_id); $this->assign('customer', Customer::get($customer_id)); $this->assign('contract', Contract::get($contract_id)); $this->assign('flow', $flow); $this->assign('staff', Staff::getStaff()); $this->assign('number',$this->model::getNumber()); return $this->view->fetch(); } private function operateParasm($datas) { $detail_field = ['consume_type', 'consume_date', 'car_number', 'consume_money', 'start_mileage', 'end_mileage', 'mileage', 'file_ids', 'remark', 'detail_id']; $list = []; foreach ($datas as $k => $v) { if (in_array($k, $detail_field) && is_array($v)) { foreach ($v as $key => $val) { if ($k == 'detail_id') { $k = 'id'; } $list[$key][$k] = $val; } } } return array_values($list); } /** * 修改 */ public function edit($ids = null) { $map['id'] = $ids; if ($this->request->isAjax()) { $params = $this->request->post('row/a'); $params = $this->preExcludeFields($params); $row = $this->model::where(['id' => $ids, 'check_status' => ['in', [0, 1, 3, 4, 5]]])->find(); if (empty($row)) { $this->error('审核通过的费用不可编辑'); } Db::startTrans(); try { $params['id'] = $ids; $result = $this->model::updateInvoice($params); Db::commit(); } catch (Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result !== false) { $this->success('修改成功'); } else { $this->error('修改失败'); } } $row = $this->model->where($map)->with(['customer','contract'])->find(); $flow = Flow::getsteplist(Flow::INVOICE_STATUS); if (empty($flow)) { $this->error('无可用审批流,请联系管理员'); } $customer_id = input('customer_id', null); $contract_id = input('contract_id', null); $this->assign('contract_id', $contract_id); $this->assign('customer_id', $customer_id); $this->assign('customer', Customer::get($customer_id)); $this->assign('contract', Contract::get($contract_id)); $this->assign('flow', $flow); $row=$row->toArray(); $this->view->assign("row", $row); $this->assign('staff', Staff::getStaff()); return $this->view->fetch(); } /** * 费用详情 */ public function detail($ids = null) { $row = $this->model->with(['ownerStaff', 'customer', 'contract'])->where([ 'id' => $ids, ])->find(); if (empty($row)) { $this->error(__('No Results were found')); } switch($row['type']){ case 0: $row['type'] = '增值税专用发票'; break; case 1: $row['type'] = '增值税普通发票'; break; case 2: $row['type'] = '国税通用机打发票'; break; case 3: $row['type'] = '地税通用机打发票'; break; case 4: $row['type'] = '收据'; break; default: $row['type'] = '增值税专用发票'; break; } switch($row['head_type']){ case 0: $row['head_type'] = '单位'; break; case 1: $row['head_type'] = '个人'; break; default: $row['type'] = '单位'; break; } $this->assign('flow', Flow::getstepdetail(Flow::INVOICE_STATUS, $ids)); //标记通知已读 Message::setRead(Message::INVOICE_TYPE, $ids, $this->_staff->id); //审批记录 $this->assign('examine_record', ExamineRecord::getList(ExamineRecord::INVOICE_TYPE, $ids)); $this->assign('row', $row); $this->assign('ids', $ids); return $this->view->fetch(); } /** * 删除 */ public function del($ids = "") { if (!$this->request->isPost()) { $this->error(__("Invalid parameters")); } $ids = $ids ? $ids : $this->request->post("ids"); $row = $this->model::where(['id' => $ids, 'check_status' => ['in', [0, 1, 3, 4, 5]]])->find(); if (empty($row)) { $this->error('审核通过的费用不可删除'); } $row = $this->model->get($ids); $this->modelValidate = true; if (!$row) { $this->error(__('No Results were found')); } $row->delete(); $this->success(); } //标记开票 public function batchstatus($ids = null){ $row = $this->model->where([ 'id' => $ids, ])->find(); if (empty($row)) { $this->error(__('No Results were found')); } if ($this->request->isAjax()) { $params = $this->request->post('row/a'); $params = $this->preExcludeFields($params); Db::startTrans(); try { $params['id'] = $ids; $result = $this->model::updateInfo($params); Db::commit(); } catch (Exception $e) { Db::rollback(); $this->error($e->getMessage()); } if ($result !== false) { $this->success('标记成功'); } else { $this->error('标记失败'); } } $this->assign('row', $row); $this->assign('ids', $ids); return $this->view->fetch(); } }