Jelajahi Sumber

库存管理 补货

ANG YU 4 tahun lalu
induk
melakukan
3161ce3dae

+ 85 - 20
app/Http/Controllers/ReplenishmentController.php

@@ -3,8 +3,10 @@
 namespace App\Http\Controllers;
 
 use App\Components\AsyncResponse;
+use App\Owner;
 use App\Services\ReplenishmentService;
 use Illuminate\Http\Request;
+use Oursdreams\Export\Export;
 
 class ReplenishmentController extends Controller
 {
@@ -13,34 +15,97 @@ class ReplenishmentController extends Controller
     public function getReplenishmentInfoByCustomer(Request $request)
     {
         $this->gate("库存管理-补货列表");
-        $customer=$request->input('customer');
-        if (!$customer)$this->error('请选择指定货主!');
+        $customer = $request->input('customer');
+        if (!$customer) $this->error('请选择指定货主!');
+        $orders = $this->getOrders($customer);
+        if (count($orders) > 0) $this->success($orders);
+        else $this->error('未查询到相应信息!');
+
+
+    }
+
+
+    public function index(Request $request)
+    {
+        $this->gate("库存管理-补货列表");
+        /** @var UserService $userService */
+        $userService = app('UserService');
+        $owners = Owner::query()->whereIn('id', $userService->getPermittingOwnerIds(auth()->user()))->get();
+        return view('inventory.stockOut.index', compact('owners'));
+    }
+
+    public function export(Request $request)
+    {
+        $this->gate("库存管理-补货列表");
+
+        $customer = $request->input('customer');
+        $orders = array_filter($this->getOrders($customer),function($item){
+            return $item['amount'] > 0;
+        });
+        $row = [
+            '货主',
+            '商品名称',
+            '商品条码',
+            '拣货库位',
+            '缺货数',
+            '存储库位'
+        ];
+        $json = [];
+
+        foreach ($orders as $order) {
+            $eaLocation = '';
+
+            $rsLocation = '';
+            foreach ($order['eaLocation'] as $v) {
+                $eaLocation .= $v . ",\r\n";
+            }
+
+            foreach ($order['rsLocation'] as $v) {
+                $rsLocation .= $v . ",\r\n";
+            }
+
+            $data = [
+                $order['customerid'],
+                $order['sku'],
+                $order['alternate_sku1'],
+                $eaLocation,
+                $order['amount'],
+                $rsLocation,
+            ];
+            $json[] = $data;
+        }
+        return Export::make($row, $json, "库存管理-补货列表");
+    }
+
+    /**
+     * @param $customer
+     * @return array
+     */
+    private function getOrders($customer): array
+    {
         /** @var ReplenishmentService $service */
         $service = app('ReplenishmentService');
-        $orders=$service->getOrderInfoRecentMonthByCustomer($customer);
-        $skuArr=array_diff(array_unique(data_get($orders, '*.sku')), ['', '*', null]);
-        $info=$service->getEaInventoryByCustomerAndSku($customer,$skuArr);
-        $rsInfo=$service->getRsInventoryByCustomerAndSku($customer,$skuArr);
+        $orders = $service->getOrderInfoRecentMonthByCustomer($customer);
+        $skuArr = array_diff(array_unique(data_get($orders, '*.sku')), ['', '*', null]);
+        $info = $service->getEaInventoryByCustomerAndSku($customer, $skuArr);
+        $rsInfo = $service->getRsInventoryByCustomerAndSku($customer, $skuArr);
 
         //将整合后拣货位信息 结合订单汇总
-        foreach ($orders as &$order){
-            if(isset($info[$order['sku']])){
+        foreach ($orders as &$order) {
+            if (isset($info[$order['sku']])) {
                 $item = $info[$order['sku']];
-                $order['amount']=($order['amount']-$item['qty']);
-                $order['eaLocation']=$item['locationid'];
-            }else{
-                $order['eaLocation']=[];
+                $order['amount'] = ($order['amount'] - $item['qty']);
+                $order['eaLocation'] = $item['locationid'];
+            } else {
+                $order['eaLocation'] = [];
             }
-            if(isset($rsInfo[$order['sku']])){
+            if (isset($rsInfo[$order['sku']])) {
                 $rsItem = $rsInfo[$order['sku']];
-                $order['rsLocation']=$rsItem['locationid'];
-            }else{
-                $order['rsLocation']=[];
+                $order['rsLocation'] = $rsItem['locationid'];
+            } else {
+                $order['rsLocation'] = [];
             }
         }
-        if (count($orders)>0)$this->success($orders);
-        else $this->error('未查询到相应信息!');
-
-
+        return $orders;
     }
 }

+ 133 - 0
resources/views/inventory/stockOut/index.blade.php

@@ -0,0 +1,133 @@
+@extends('layouts.app')
+@section('title')库存管理-补货列表@endsection
+@section('content')
+    <div id="list" class="d-none item-logistic-index">
+        <div class="container-fluid">
+            <div class="form-inline ml-5">
+                <select class="form-control form-control-sm tooltipTarget" name="owner_id" id="owner_id"
+                        style="width: 150px;position: relative" title="选择指定货主" v-model="owner_id">
+                    <option value="">货主</option>
+                    <option v-for="owner in owners" :value="owner.name">@{{ owner.value }}</option>
+                </select>
+                <input placeholder="定位货主" id="ownerName" autocomplete="off" @input="定位货主($event)"
+                       class="form-control form-control-sm tooltipTarget" style="width: 100px" title="输入关键字定位货主">
+                <button @click="search()">查询</button>
+            </div>
+
+
+            <div class="ml-3 form-inline" id="btn">
+                    <span class="dropdown">
+                        <button type="button"
+                                class="btn btn-outline-dark btn-sm form-control-sm dropdown-toggle tooltipTarget"
+                                data-toggle="dropdown" title="导出所有页将会以搜索条件得到的筛选结果,将其全部记录(每一页)导出">导出Excel
+                        </button>
+                        <div class="dropdown-menu">
+                            <a class="dropdown-item" @click="orderItemExport(true)" href="javascript:">导出所有页</a>
+                        </div>
+                    </span>
+            </div>
+            <table class="table table-striped table-bordered table-hover card-body td-min-width-80" id="table">
+                <tr v-if="item.amount > 0 " v-for="(item,i) in details" @click="selectTr===i+1?selectTr=0:selectTr=i+1"
+                    :class="selectTr===i+1?'focusing' : ''">
+                    <td>@{{ i }}</td>
+                    <td>@{{ item.customerid }}</td>
+                    <td>@{{ item.sku }}</td>
+                    <td>@{{ item.alternate_sku1 }}</td>
+                    <td>
+                        <ul style="list-style: none" v-if="item.eaLocation>0">
+                            <li v-for="(v,k) in item.eaLocation" v-if="k<3 || item.moreEaLocation">@{{ v }}</li>
+                            <a v-if="item.eaLocation.length >= 3" href="javascript:;"
+                               @click="item.moreEaLocation = !(item.moreEaLocation)">展示更多</a>
+                        </ul>
+                        <div v-else>拣货库位不存在</div>
+                    </td>
+                    <td>@{{ item.amount }}</td>
+                    <td>
+                        <ul style="list-style: none">
+                            <li v-for="(v,k) in item.rsLocation" v-if="k<3 || item.moreRaLocation">@{{ v }}</li>
+                            <a v-if="item.rsLocation.length >= 3" href="#javascript:;"
+                               @click="item.moreRaLocation = !(item.moreRaLocation)">展示更多</a>
+                        </ul>
+                    </td>
+                </tr>
+            </table>
+        </div>
+    </div>
+@endsection
+
+@section('lastScript')
+    <script type="text/javascript" src="{{mix('js/queryForm/export.js')}}"></script>
+    <script type="text/javascript" src="{{mix('js/queryForm/header.js')}}"></script>{{--新版2--}}
+    <script>
+        let vue = new Vue({
+            el: "#list",
+            data: {
+                selectTr: 0,
+                owner_id: '',
+                owners: [
+                        @foreach($owners as $owner)
+                    {
+                        name: '{{$owner->code}}', value: '{{$owner->name}}'
+                    },
+                    @endforeach
+                ],
+                details: []
+            },
+            created() {
+            },
+            mounted() {
+                $('#list').removeClass('d-none');
+                $(".up").slideUp();
+                let column = [
+                    {name: 'owner_name', value: '货主'},
+                    {name: 'sku', value: '商品名称'},
+                    {name: 'barcode', value: '商品条码'},
+                    {name: 'ea_location', value: '拣货库位'},
+                    {name: 'amount', value: '缺货数'},
+                    {name: 'rs_location', value: '存储库位'},
+                ];
+                new Header({
+                    el: "table",
+                    name: "item",
+                    column: column,
+                    data: this.details,
+                    restorationColumn: 'addtime',
+                    fixedTop: ($('#form_div').height()) + ($('#btn').height()) + 1,
+                }).init();
+            },
+            methods: {
+                orderItemExport(sign) {
+                    let url = '{{url('inventory/stockOut/export')}}';
+                    // url =   url + "?customer=" + this.owner_id;
+                    let token = '{{ csrf_token() }}';
+                    if (sign) {
+                        excelExport(true, checkData, url, this.total, token,{customer: this.owner_id});
+                    }
+                },
+
+                定位货主(e) {
+                    this.owners.some(owner => {
+                        if (owner.value.indexOf(e.target.value) !== -1) {
+                            this.owner_id = owner.name;
+                            return true;
+                        }
+                    });
+                    if (e.target.value === '' || e.target.value === null || e.target.value === undefined) {
+                        this.owner_id = '';
+                    }
+                },
+
+                search() {
+                    let url = "{{ url('inventory/stockOut/getReplenishmentInfoByCustomer') }}"
+                    axios.post(url, {
+                        customer: this.owner_id
+                    }).then(res => {
+                        this.details = res.data.data
+                        console.log(this.details);
+                    });
+                }
+            },
+            filters: {},
+        });
+    </script>
+@endsection

+ 6 - 0
routes/web.php

@@ -730,6 +730,12 @@ Route::group(['prefix'=>'package'],function(){
     /** 库存 */
     $route->group(['prefix'=>'inventory'],function(){
         /** 说明 */
+        Route::group(['prefix' => 'stockOut'], function () {
+            Route::get('/', 'ReplenishmentController@index');
+            Route::post('/getReplenishmentInfoByCustomer', 'ReplenishmentController@getReplenishmentInfoByCustomer');
+            Route::get('/export', 'ReplenishmentController@export');
+        });
+
         Route::group(['prefix'=>'statement'],function(){
             /** 动库报表 */
             Route::group(['prefix'=>'changeInventory'],function(){