|
|
@@ -0,0 +1,589 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\admin\controller\stock;
|
|
|
+
|
|
|
+use app\common\controller\Backend;
|
|
|
+use fast\Tree;
|
|
|
+use app\admin\model;
|
|
|
+use think\Exception;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 商品出库
|
|
|
+ *
|
|
|
+ * @icon fa fa-circle-o
|
|
|
+ */
|
|
|
+class Stockout extends Backend
|
|
|
+{
|
|
|
+
|
|
|
+ /**
|
|
|
+ * StockStockout模型对象
|
|
|
+ * @var \app\admin\modelstock\Stockout
|
|
|
+ */
|
|
|
+ protected $model = null;
|
|
|
+ protected $listmodel = null;
|
|
|
+ protected $noNeedLogin = ['countData','info'];
|
|
|
+
|
|
|
+ public function _initialize()
|
|
|
+ {
|
|
|
+ parent::_initialize();
|
|
|
+ $this->model = model('\app\admin\model\stock\Stockout');
|
|
|
+ $this->listmodel = model('\app\admin\model\stock\Stockoutlist');
|
|
|
+ $customerList = collection(model('\app\admin\model\stock\Customer')->select())->toArray();
|
|
|
+ Tree::instance()->init($customerList);
|
|
|
+ $customerList = Tree::instance()->getTreeList(Tree::instance()->getTreeArray(0), 'name');
|
|
|
+ $customer = ['' => '==请选择=='];
|
|
|
+ foreach ($customerList as $k => $v) {
|
|
|
+ $customer[$v['id']] = $v['name'];
|
|
|
+ }
|
|
|
+ $this->view->assign('customer', $customer);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
|
|
|
+ * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
|
|
|
+ * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
|
|
|
+ */
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查看
|
|
|
+ */
|
|
|
+ public function index()
|
|
|
+ {
|
|
|
+ //设置过滤方法
|
|
|
+ $this->request->filter(['strip_tags']);
|
|
|
+ if ($this->request->isAjax()) {
|
|
|
+ //如果发送的来源是Selectpage,则转发到Selectpage
|
|
|
+ if ($this->request->request('keyField')) {
|
|
|
+ return $this->selectpage();
|
|
|
+ }
|
|
|
+ $this->relationSearch = true;
|
|
|
+ $this->searchFields = 'docnum,customer.name';
|
|
|
+ list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
|
|
+ $total = $this->model
|
|
|
+ ->where($where)
|
|
|
+ ->with('customer')
|
|
|
+ ->order($sort, $order)
|
|
|
+ ->count();
|
|
|
+
|
|
|
+ $list = $this->model
|
|
|
+ ->where($where)
|
|
|
+ ->with('customer')
|
|
|
+ ->order($sort, $order)
|
|
|
+ ->limit($offset, $limit)
|
|
|
+ ->select();
|
|
|
+
|
|
|
+ $list = collection($list)->toArray();
|
|
|
+ $result = array("total" => $total, "rows" => $list);
|
|
|
+
|
|
|
+ return json($result);
|
|
|
+ }
|
|
|
+ return $this->view->fetch();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 出库时序表
|
|
|
+ */
|
|
|
+ public function getlist()
|
|
|
+ {
|
|
|
+ //设置过滤方法
|
|
|
+ $this->request->filter(['strip_tags']);
|
|
|
+ if ($this->request->isAjax()) {
|
|
|
+ //如果发送的来源是Selectpage,则转发到Selectpage
|
|
|
+ if ($this->request->request('keyField')) {
|
|
|
+ return $this->selectpage();
|
|
|
+ }
|
|
|
+ $this->relationSearch = true;
|
|
|
+ $this->searchFields = 'docnum,goods.goodsname,goods.productmodel';
|
|
|
+ list($where, $sort, $order, $offset, $limit) = $this->buildparams();
|
|
|
+ $total = $this->listmodel
|
|
|
+ ->with(['goods','stockinlist','stockout'])
|
|
|
+ ->where('stockout.audittime', 'NOT NULL')
|
|
|
+ ->where($where)
|
|
|
+ ->order($sort, $order)
|
|
|
+ ->count();
|
|
|
+ $list = $this->listmodel
|
|
|
+ ->with(['goods','stockinlist','stockout'])
|
|
|
+ ->where('stockout.audittime', 'NOT NULL')
|
|
|
+ ->where($where)
|
|
|
+ ->order($sort, $order)
|
|
|
+ ->limit($offset, $limit)
|
|
|
+ ->select();
|
|
|
+ foreach ($list as $k => $v) {
|
|
|
+ $v->stockout->customer;
|
|
|
+ }
|
|
|
+ $list = collection($list)->toArray();
|
|
|
+ $result = array("total" => $total, "rows" => $list);
|
|
|
+ return json($result);
|
|
|
+ }
|
|
|
+ return $this->view->fetch();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 添加
|
|
|
+ */
|
|
|
+ public function add()
|
|
|
+ {
|
|
|
+ if ($this->request->isPost()) {
|
|
|
+ $params = $this->request->post("row/a");
|
|
|
+ $main = json_decode($params['main'], true);
|
|
|
+ $goods = json_decode($params['goodslist'], true);
|
|
|
+ if ($main && $goods) {
|
|
|
+ try {
|
|
|
+ $main["docnum"] = $this->model->createdocnum();
|
|
|
+ $main['outboundtime'] = strtotime($main['outboundtime']);
|
|
|
+ $num = count($goods);
|
|
|
+ $stockoutgoods = [];
|
|
|
+ $stockcurmodel = model('\app\admin\model\stock\Stockcur');
|
|
|
+ $stockOutTotalNum = 0; //单据总出库商品总数
|
|
|
+ $errorgoods = [];
|
|
|
+ for ($i = 0; $i < $num; $i++) {
|
|
|
+ //$curtotalnum 要出库的商品当前库存总数
|
|
|
+ $curtotalnum = $stockcurmodel->where('stock_goods_id', $goods[$i]['stock_goods_id'])->sum('curnums');
|
|
|
+ $outtotalnum = 0;
|
|
|
+ foreach ($goods as $v) {
|
|
|
+ if ($v['stock_goods_id'] == $goods[$i]['stock_goods_id']) {
|
|
|
+ $outtotalnum += $v['stockoutnums'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $stockOutTotalNum += $goods[$i]['stockoutnums'];
|
|
|
+ //库存总数小于要出库数 出库失败!
|
|
|
+ if ($curtotalnum < $outtotalnum) {
|
|
|
+ $errorgoods[] = $goods[$i]['goodsname'] . '当前库存:' . $curtotalnum . ',出库数量' . $outtotalnum . ',出库数大于库存数,操作失败!';
|
|
|
+ } else {
|
|
|
+ $stockoutgoods[] = array_merge($params, $goods[$i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (count($errorgoods) > 0) {
|
|
|
+ $this->error(implode('</br>', $errorgoods)); //拼接成字符串
|
|
|
+ }
|
|
|
+ $main['totaloutamount'] = null;
|
|
|
+ $main['stockouttotalnums'] = $stockOutTotalNum;
|
|
|
+ $this->model->save($main);
|
|
|
+ for ($i = 0; $i < count($stockoutgoods); $i++) {
|
|
|
+ $stockoutgoods[$i]['stock_stockout_id'] = $this->model->id;
|
|
|
+ }
|
|
|
+ $result = $this->listmodel->allowField(true)->saveAll($stockoutgoods, false);
|
|
|
+ if ($result !== false) {
|
|
|
+ $this->success();
|
|
|
+ } else {
|
|
|
+ $this->error($this->model->getError());
|
|
|
+ }
|
|
|
+ } catch (\think\exception\PDOException $e) {
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->error(__('Parameter %s can not be empty', ''));
|
|
|
+ }
|
|
|
+ return $this->view->fetch();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 编辑
|
|
|
+ */
|
|
|
+ public function edit($ids = null)
|
|
|
+ {
|
|
|
+ $row = $this->model->get($ids);
|
|
|
+ if (!$row) {
|
|
|
+ $this->error(__('No Results were found'));
|
|
|
+ }
|
|
|
+ if ($row['audittime']) {
|
|
|
+ return ($this->error(__('该记录已通过审核,不能修改!')));
|
|
|
+ }
|
|
|
+ if ($row['settletime']) {
|
|
|
+ return ($this->error(__('该记录已结算,不能修改!')));
|
|
|
+ }
|
|
|
+ if ($this->request->isPost()) {
|
|
|
+ $params = $this->request->post("row/a");
|
|
|
+ $main = json_decode($params['main'], true);
|
|
|
+ $goods = json_decode($params['goodslist'], true);
|
|
|
+ $delist = json_decode($params["deletedgoodslist"], true);
|
|
|
+ if ($main && $goods) {
|
|
|
+ try {
|
|
|
+ $row->outboundtime = strtotime($main['outboundtime']);
|
|
|
+ $row->stock_customer_id = $main['stock_customer_id'];
|
|
|
+ $row->remark = $main['remark'];
|
|
|
+ $num = count($goods);
|
|
|
+ $stockoutgoods = [];
|
|
|
+ $stockcurmodel = model('\app\admin\model\stock\Stockcur');
|
|
|
+ $stockOutTotalNum = 0; //单据总出库商品总数
|
|
|
+ $errorgoods = [];
|
|
|
+ for ($i = 0; $i < $num; $i++) {
|
|
|
+ //$curtotalnum 要出库的商品当前库存总数
|
|
|
+ $curtotalnum = $stockcurmodel->where('stock_goods_id', $goods[$i]['stock_goods_id'])->sum('curnums');
|
|
|
+ $outtotalnum = 0;
|
|
|
+ foreach ($goods as $v) {
|
|
|
+ if ($v['stock_goods_id'] == $goods[$i]['stock_goods_id']) {
|
|
|
+ $outtotalnum += $v['stockoutnums'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $stockOutTotalNum += $goods[$i]['stockoutnums'];
|
|
|
+ //库存总数小于要出库数 出库失败!
|
|
|
+ if ($curtotalnum < $outtotalnum) {
|
|
|
+ $errorgoods[] = $goods[$i]['goodsname'] . '当前库存:' . $curtotalnum . ',出库数量' . $outtotalnum . ',出库数大于库存数,操作失败!';
|
|
|
+ } else {
|
|
|
+ $stockoutgoods[] = array_merge($params, $goods[$i]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (count($errorgoods) > 0) {
|
|
|
+ $this->error(implode('</br>', $errorgoods)); //拼接成字符串
|
|
|
+ }
|
|
|
+ $row->stockouttotalnums = $stockOutTotalNum;
|
|
|
+ $row->save();
|
|
|
+ for ($i = 0; $i < count($stockoutgoods); $i++) {
|
|
|
+ $stockoutgoods[$i]['stock_stockout_id'] = $row->id;
|
|
|
+ }
|
|
|
+ $result = $this->listmodel->allowField(true)->saveAll($stockoutgoods);
|
|
|
+ $this->listmodel->destroy($delist);
|
|
|
+ if ($result !== false) {
|
|
|
+ $this->success();
|
|
|
+ } else {
|
|
|
+ $this->error($this->model->getError());
|
|
|
+ }
|
|
|
+ } catch (\think\exception\PDOException $e) {
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->error(__('Parameter %s can not be empty', ''));
|
|
|
+ }
|
|
|
+ $this->view->assign("row", $row);
|
|
|
+ return $this->view->fetch();
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 审核
|
|
|
+ */
|
|
|
+ public function audit()
|
|
|
+ {
|
|
|
+ if ($this->request->isPost()) {
|
|
|
+ $params = $this->request->post("row/a");
|
|
|
+ if ($params) {
|
|
|
+ $stockcurmodel = model('\app\admin\model\stock\Stockcur');
|
|
|
+ $stockinlistmodel = model('\app\admin\model\stock\Stockinlist');
|
|
|
+ $row = $this->model->get($params["id"]);
|
|
|
+ if (!$row) {
|
|
|
+ $this->error(__('No Results were found'));
|
|
|
+ }
|
|
|
+ $stockcurmodel->startTrans();
|
|
|
+ $stockinlistmodel->startTrans();
|
|
|
+ $this->model->startTrans();
|
|
|
+ $this->listmodel->startTrans();
|
|
|
+ try {
|
|
|
+ $totalOutAmount = 0; //单据总出库金额
|
|
|
+ $stockOutTotalNum = 0; //单据总出库商品总数
|
|
|
+ $goods = $this->listmodel->with('goods')->where('stock_stockout_id', $row->id)->select();
|
|
|
+ $newgoods = [];
|
|
|
+ $errorgoods = [];
|
|
|
+ if ($goods) {
|
|
|
+ if ($row->audittime) {
|
|
|
+ $this->error(__('出库单据已审核,不可重复审核', ''));
|
|
|
+ }
|
|
|
+ $num = count($goods);
|
|
|
+ for ($i = 0; $i < $num; $i++) {
|
|
|
+ //$curtotalnum 要出库的商品当前库存总数
|
|
|
+ $curtotalnum = $stockcurmodel->where('stock_goods_id', $goods[$i]['stock_goods_id'])->sum('curnums');
|
|
|
+ //库存总数小于此次要出库数 出库失败!
|
|
|
+ if ($curtotalnum < $goods[$i]['stockoutnums']) {
|
|
|
+ $errorgoods[] = $goods[$i]['goods']['goodsname'] . '当前库存:' . $curtotalnum . ',出库数量' . $goods[$i]['stockoutnums'] . ',出库数大于库存数,操作失败!';
|
|
|
+ } else {
|
|
|
+ //获得要出库商品的所有库存信息
|
|
|
+ $stockcurgoods = $stockcurmodel->with('stockinlist')->where('stockcur.stock_goods_id', $goods[$i]['stock_goods_id'])->order('id')->select();
|
|
|
+ $curstockoutgoods = $goods[$i]->toArray();
|
|
|
+ unset($curstockoutgoods['id']);
|
|
|
+ //出库初始数量为
|
|
|
+ $stockoutnum = 0;
|
|
|
+ $j = 0;
|
|
|
+ while ($stockoutnum < $goods[$i]['stockoutnums']) {
|
|
|
+ $neednum = $goods[$i]['stockoutnums'] - $stockoutnum; //$neednum 还需要出库的数量
|
|
|
+ $restnum = $stockcurgoods[$j]['curnums'] - $neednum; //$restnum 该条记录出完库后剩余库存。
|
|
|
+ //小于等于0则表示不够出或刚够
|
|
|
+ if ($restnum <= 0) {
|
|
|
+ $curstockoutgoods['stock_stockout_id'] = $row->id;
|
|
|
+ $curstockoutgoods['stockoutgoodsremark'] = $goods[$i]['stockoutgoodsremark'];
|
|
|
+ $curstockoutgoods['stock_stockinlist_id'] = $stockcurgoods[$j]['stockinlist']['id'];
|
|
|
+ $curstockoutgoods['stockoutnums'] = $stockcurgoods[$j]['curnums'];
|
|
|
+ $curstockoutgoods['amount'] = bcmul($stockcurgoods[$j]['curnums'], $stockcurgoods[$j]['stockinlist']['inboundprice'], 2);
|
|
|
+ $stockoutnum += $stockcurgoods[$j]['curnums'];
|
|
|
+ $totalOutAmount += $curstockoutgoods['amount'];
|
|
|
+ $stockOutTotalNum += $stockcurgoods[$j]['curnums'];
|
|
|
+ $stockcurmodel->destroy($stockcurgoods[$j]['id']);
|
|
|
+ $stockinlist = $stockinlistmodel->get($stockcurgoods[$j]['stockinlist']['id']);
|
|
|
+ $stockinlist->charged = true;
|
|
|
+ $stockinlist->save();
|
|
|
+ } elseif (($restnum > 0)) { //大于0则表示够出
|
|
|
+ $curstockoutgoods['stock_stockout_id'] = $row->id;
|
|
|
+ $curstockoutgoods['stockoutgoodsremark'] = $goods[$i]['stockoutgoodsremark'];
|
|
|
+ $curstockoutgoods['stock_stockinlist_id'] = $stockcurgoods[$j]['stockinlist']['id'];
|
|
|
+ $curstockoutgoods['stockoutnums'] = $neednum;
|
|
|
+ $curstockoutgoods['amount'] = bcmul($neednum, $stockcurgoods[$j]['stockinlist']['inboundprice'], 2);
|
|
|
+ $stockoutnum += $neednum;
|
|
|
+ $totalOutAmount += $curstockoutgoods['amount'];
|
|
|
+ $stockOutTotalNum += $neednum;
|
|
|
+ $stockcurgoods[$j]['curnums'] = $restnum;
|
|
|
+ $updatestockcur = $stockcurmodel->get($stockcurgoods[$j]['id']);
|
|
|
+ $updatestockcur->curnums = $restnum;
|
|
|
+ $updatestockcur->save();
|
|
|
+ $stockinlist = $stockinlistmodel->get($stockcurgoods[$j]['stockinlist']['id']);
|
|
|
+ $stockinlist->charged = true;
|
|
|
+ $stockinlist->save();
|
|
|
+ }
|
|
|
+ $newgoods[] = $curstockoutgoods;
|
|
|
+ $j++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ };
|
|
|
+ }
|
|
|
+ if (count($errorgoods) > 0) {
|
|
|
+ throw new Exception(implode('</br>', $errorgoods));
|
|
|
+ }
|
|
|
+ $row->totaloutamount = $totalOutAmount;
|
|
|
+ $row->stockouttotalnums = $stockOutTotalNum;
|
|
|
+ $row->audittime = time();
|
|
|
+ $row->save();
|
|
|
+ $goods = $this->listmodel->where('stock_stockout_id', $row->id)->delete();
|
|
|
+ $result = $this->listmodel->allowField(true)->saveAll($newgoods); //更新审核标记位
|
|
|
+ $this->model->commit();
|
|
|
+ $this->listmodel->commit();
|
|
|
+ $stockcurmodel->commit();
|
|
|
+ $stockinlistmodel->commit();
|
|
|
+ if ($result !== false) {
|
|
|
+ $this->success();
|
|
|
+ } else {
|
|
|
+ $this->error($this->model->getError());
|
|
|
+ }
|
|
|
+ } catch (\think\exception\PDOException $e) {
|
|
|
+ $this->model->rollBack();
|
|
|
+ $this->listmodel->rollBack();
|
|
|
+ $stockcurmodel->rollBack();
|
|
|
+ $stockinlistmodel->rollBack();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ } catch (\think\Exception $e) {
|
|
|
+ $this->model->rollBack();
|
|
|
+ $this->listmodel->rollBack();
|
|
|
+ $stockcurmodel->rollBack();
|
|
|
+ $stockinlistmodel->rollBack();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->error(__('Parameter %s can not be empty', ''));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 反审核
|
|
|
+ */
|
|
|
+ public function unaudit()
|
|
|
+ {
|
|
|
+ if ($this->request->isPost()) {
|
|
|
+ $params = $this->request->post("row/a");
|
|
|
+ $row = $this->model->get($params["id"]);
|
|
|
+ if ($row) {
|
|
|
+ try {
|
|
|
+ if (!$row->audittime) {
|
|
|
+ $this->error(__('出库单据已反审核,不可重复反审核', ''));
|
|
|
+ };
|
|
|
+ $goods = $this->listmodel->where('stock_stockout_id', $row->id)->select();
|
|
|
+ if ($goods) {
|
|
|
+ foreach ($goods as $k => $v) {
|
|
|
+ $stockinlistmodel = model('\app\admin\model\stock\Stockinlist')->get(["id" => $v['stock_stockinlist_id']]);
|
|
|
+ $stockinmodel = model('\app\admin\model\stock\Stockin')->get($stockinlistmodel->stock_stockin_id);
|
|
|
+ $stockcurmodel = model('\app\admin\model\stock\Stockcur')->get(["stock_stockin_list_id" => $v['stock_stockinlist_id']]);
|
|
|
+ if ($stockcurmodel) {
|
|
|
+ $stockcurmodel->curnums = $stockcurmodel->curnums + $v->stockoutnums;
|
|
|
+ if ($stockcurmodel->curnums == $stockinlistmodel->stockinnums) {
|
|
|
+ $stockinlistmodel->charged = false;
|
|
|
+ $stockinlistmodel->save();
|
|
|
+ }
|
|
|
+ $stockcurmodel->save();
|
|
|
+ } else {
|
|
|
+ $stockcur = [
|
|
|
+ 'stock_stockin_list_id' => $stockinlistmodel['id'],
|
|
|
+ 'stock_stockin_id' => $stockinlistmodel['stock_stockin_id'],
|
|
|
+ 'curnums' => $v->stockoutnums,
|
|
|
+ 'stock_goods_id' => $stockinlistmodel['stock_goods_id'],
|
|
|
+ 'stock_stockin_docnum' => $stockinmodel->docnum,
|
|
|
+ ];
|
|
|
+ model('\app\admin\model\stock\Stockcur')->isUpdate(false)->data($stockcur, true)->save();
|
|
|
+ if ($stockinlistmodel->stockinnums == $v->stockoutnums) {
|
|
|
+ $stockinlistmodel->charged = false;
|
|
|
+ $stockinlistmodel->save();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $v->stock_stockinlist_id = null;
|
|
|
+ $v->amount = null;
|
|
|
+ $v->save();
|
|
|
+ };
|
|
|
+ } else {
|
|
|
+ $this->error($this->model->getError());
|
|
|
+ }
|
|
|
+ $row->audittime = null;
|
|
|
+ $row->totaloutamount = null;
|
|
|
+ $result = $row->save();
|
|
|
+
|
|
|
+ if ($result !== false) {
|
|
|
+ $this->success();
|
|
|
+ } else {
|
|
|
+ $this->error($this->model->getError());
|
|
|
+ }
|
|
|
+ } catch (\think\exception\PDOException $e) {
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->error(__('Parameter %s can not be empty', ''));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 结算
|
|
|
+ */
|
|
|
+ public function settle()
|
|
|
+ {
|
|
|
+ if ($this->request->isPost()) {
|
|
|
+ $params = $this->request->post("row/a");
|
|
|
+ $row = $this->model->get($params["id"]);
|
|
|
+ if ($row) {
|
|
|
+ try {
|
|
|
+ $row->settletime = time();
|
|
|
+ $result = $row->save();
|
|
|
+ if ($result) {
|
|
|
+ $this->success('结算成功');
|
|
|
+ } else {
|
|
|
+ $this->error(__('结算失败'));
|
|
|
+ }
|
|
|
+ } catch (\think\exception\PDOException $e) {
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->error(__('Parameter %s can not be empty', ''));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 反结算
|
|
|
+ */
|
|
|
+ public function unsettle()
|
|
|
+ {
|
|
|
+ if ($this->request->isPost()) {
|
|
|
+ $params = $this->request->post("row/a");
|
|
|
+ $row = $this->model->get($params["id"]);
|
|
|
+ if ($row) {
|
|
|
+ try {
|
|
|
+ $row->settletime = null;
|
|
|
+ $result = $row->save();
|
|
|
+ if ($result) {
|
|
|
+ $this->success('反结算成功');
|
|
|
+ } else {
|
|
|
+ $this->error(__('反结算失败'));
|
|
|
+ }
|
|
|
+ } catch (\think\exception\PDOException $e) {
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->error(__('Parameter %s can not be empty', ''));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查看
|
|
|
+ */
|
|
|
+ public function look($ids = null)
|
|
|
+ {
|
|
|
+ $row = $this->model->get($ids);
|
|
|
+ if (!$row) {
|
|
|
+ $this->error(__('No Results were found'));
|
|
|
+ }
|
|
|
+ return $this->view->fetch();
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 删除
|
|
|
+ */
|
|
|
+ public function del($ids = "")
|
|
|
+ {
|
|
|
+ if ($ids) {
|
|
|
+ $row = $this->model->get($ids);
|
|
|
+ if (!$row) {
|
|
|
+ $this->error(__('No Results were found'));
|
|
|
+ }
|
|
|
+ $list = collection($this->listmodel->where('stock_stockout_id', $row->id)->select())->toArray();
|
|
|
+ if ($row['audittime']) {
|
|
|
+ return ($this->error(__('该单据已审核,不能删除!')));
|
|
|
+ }
|
|
|
+ $result = $this->listmodel->where('stock_stockout_id', $row->id)->delete();
|
|
|
+ $result = $row->delete();
|
|
|
+ if ($result) {
|
|
|
+ $this->success();
|
|
|
+ } else {
|
|
|
+ $this->error(__('No rows were deleted'));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->error(__('Parameter %s can not be empty', 'ids'));
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 查看页,根据单据编号返回商品信息
|
|
|
+ */
|
|
|
+ public function info($id = null)
|
|
|
+ {
|
|
|
+ if ($this->request->isPost()) {
|
|
|
+ if ($id) {
|
|
|
+ try {
|
|
|
+ $row = $this->model->get($id);
|
|
|
+ $row->customer;
|
|
|
+ $goodslist = \think\Db::view('stock_stockout_list', '*')
|
|
|
+ ->view('stock_goods', 'id as stock_goods_id,volnum,goodsname,productmodel,measureunit', 'stock_stockout_list.stock_goods_id=stock_goods.id', 'left')
|
|
|
+ ->view('stock_stockin_list', 'id as stock_stockin_list,inboundprice', 'stock_stockin_list.id=stock_stockout_list.stock_stockinlist_id', 'left')
|
|
|
+ ->where('stock_stockout_list.stock_stockout_id', $id)->select();
|
|
|
+ return json(["row" => $row, "goodslist" => $goodslist]);
|
|
|
+ } catch (\think\exception\PDOException $e) {
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $this->error(__('Parameter %s can not be empty', ''));
|
|
|
+ }
|
|
|
+ $this->error('只接受POST请求', '');
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 控制台出库统计
|
|
|
+ */
|
|
|
+ public function countData()
|
|
|
+ {
|
|
|
+ if ($this->request->isAjax()) {
|
|
|
+ $dateRange = $this->request->request("dateRange");
|
|
|
+ $dateRange = explode(' - ', $dateRange);
|
|
|
+ $dateRange = count($dateRange) > 1 ? $dateRange : $dateRange[0];
|
|
|
+ $list1 = $this->model
|
|
|
+ ->with('stockgoods,customer')
|
|
|
+ ->field('sum(amount) totalitemamount,count(*) totalitem,sum(stockoutnums) totalnum')
|
|
|
+ ->where('audittime', 'not null')
|
|
|
+ ->whereTime('stockout.createtime', $dateRange)
|
|
|
+ ->group('stockout.stock_customer_id')
|
|
|
+ ->select();
|
|
|
+ $list1 = collection($list1)->toArray();
|
|
|
+
|
|
|
+ $list2 = $this->model
|
|
|
+ ->with('stockgoods,customer')
|
|
|
+ ->field('sum(amount) totalitemamount,count(*) totalitem,sum(stockoutnums) totalnum')
|
|
|
+ ->where('audittime', 'not null')
|
|
|
+ ->whereTime('stockout.createtime', $dateRange)
|
|
|
+ ->group('goodscategoryid')
|
|
|
+ ->select();
|
|
|
+ $list2 = collection($list2)->toArray();
|
|
|
+ $result = array("rows1" => $list1, "rows2" => $list2);
|
|
|
+ return json($result);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 打印数据(LODOP)
|
|
|
+ */
|
|
|
+ public function printer($id)
|
|
|
+ {
|
|
|
+ $row = $this->model->get($id);
|
|
|
+ if (!$row) {
|
|
|
+ $this->error(__('No Results were found'));
|
|
|
+ } else if (!$row->audittime) {
|
|
|
+ $this->error(__('单据尚未审核,请先审核!'));
|
|
|
+ }
|
|
|
+ return $this->view->fetch();
|
|
|
+ }
|
|
|
+}
|