LD 5 лет назад
Родитель
Сommit
a2d4a54074

+ 85 - 0
app/Http/Controllers/InventoryCompareController.php

@@ -0,0 +1,85 @@
+<?php
+
+namespace App\Http\Controllers;
+
+use App\InventoryCompare;
+use Illuminate\Http\Request;
+
+class InventoryCompareController extends Controller
+{
+    /**
+     * Display a listing of the resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function index()
+    {
+        //
+    }
+
+    /**
+     * Show the form for creating a new resource.
+     *
+     * @return \Illuminate\Http\Response
+     */
+    public function create()
+    {
+        //
+    }
+
+    /**
+     * Store a newly created resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @return \Illuminate\Http\Response
+     */
+    public function store(Request $request)
+    {
+        //
+    }
+
+    /**
+     * Display the specified resource.
+     *
+     * @param  \App\InventoryCompare  $inventoryCompare
+     * @return \Illuminate\Http\Response
+     */
+    public function show(InventoryCompare $inventoryCompare)
+    {
+        //
+    }
+
+    /**
+     * Show the form for editing the specified resource.
+     *
+     * @param  \App\InventoryCompare  $inventoryCompare
+     * @return \Illuminate\Http\Response
+     */
+    public function edit(InventoryCompare $inventoryCompare)
+    {
+        //
+    }
+
+    /**
+     * Update the specified resource in storage.
+     *
+     * @param  \Illuminate\Http\Request  $request
+     * @param  \App\InventoryCompare  $inventoryCompare
+     * @return \Illuminate\Http\Response
+     */
+    public function update(Request $request, InventoryCompare $inventoryCompare)
+    {
+        //
+    }
+
+    /**
+     * Remove the specified resource from storage.
+     *
+     * @param  \App\InventoryCompare  $inventoryCompare
+     * @return \Illuminate\Http\Response
+     */
+    public function destroy(InventoryCompare $inventoryCompare)
+    {
+        //
+    }
+}

+ 37 - 1
app/Http/Controllers/InventoryController.php

@@ -3,15 +3,21 @@
 namespace App\Http\Controllers;
 
 use App\Exports\Export;
+use App\Imports\InventoryCompareImport;
+use App\Imports\OrderIssueImport;
 use App\Inventory;
+use App\InventoryCompare;
 use App\InventoryDailyLoggingOwner;
 use App\InventoryMission;
 use App\OracleBasCustomer;
 use App\Owner;
+use App\Services\InventoryCompareService;
 use App\Services\InventoryService;
 use App\Services\OwnerService;
 use App\Services\InventoryAccountService;
 use Illuminate\Http\Request;
+use Illuminate\Support\Facades\Auth;
+use Illuminate\Support\Facades\Cache;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Gate;
 use Maatwebsite\Excel\Facades\Excel;
@@ -21,6 +27,7 @@ class InventoryController extends Controller
     public function __construct()
     {
         app()->singleton('inventoryService',InventoryService::class);
+        app()->singleton('inventoryCompareService',InventoryCompareService::class);
     }
     private function conditionQuery(Request $request,$page=null,$paginate=null){
         $date_start=$request->input('date_start');
@@ -270,6 +277,35 @@ class InventoryController extends Controller
     function inventoryCompare(Request $request,OwnerService $ownerService){
         if (!Gate::allows('库存管理-库存-库存对比')){return redirect(url('/')); }
         $owners = $ownerService->getSelection();
-        return view('inventory.statement.inventoryCompare',compact('owners'));
+        $inventoryCompares=app('inventoryCompareService')->getInventoryCompare($request->all());
+        $param = $request->input();
+        return view('inventory.statement.inventoryCompare',compact('owners','inventoryCompares','param'));
+    }
+    function importExcel(Request $request){
+        if (!Gate::allows('库存管理-库存-库存对比')){return redirect(url('/')); }
+        $owner_id=$request->owner_id;
+        if(!$owner_id) return '<h1 class="text-danger">导入Excel失败<br><p style="color: red">您还未选择相应货主!</p></h1>';
+        $fileSuffix = $request->file()['file']->getClientOriginalExtension();
+        if (in_array($fileSuffix, ['xlsx', 'xlsm', 'xltx', 'xltm', 'xls', 'xlt', 'ods', 'ots', 'slk', 'xml', 'gnumeric', 'htm', 'html', 'csv', 'tsv'])) {
+            ini_set('max_execution_time', 2100);
+            ini_set('memory_limit', '512M');
+            $extension = $request->file()['file']->getClientOriginalExtension();
+            $extension[0] = strtoupper($extension[0]);
+            Excel::import(new InventoryCompareImport($owner_id), $request->file('file')->path(), null, $extension);
+            if (Cache::has('error')) {
+                return '<h1 class="text-danger">导入Excel失败<br><p style="color: red">' . Cache::pull('error') . '</p></h1>';
+            } else {
+                $exception = Cache::get('exception');
+                $a = '';
+                for ($i = 0; $i < count($exception); $i++) {
+                    $a .= implode(',', $exception[$i]) . '&#10';
+                };
+                $this->log(__METHOD__, __FUNCTION__, json_encode($request->toArray()), Auth::user()['id']);
+                return '<h1 class="text-danger">导入Excel成功<br><textarea style="width: 50%;height: 50%">' . $a . '</textarea></h1>';
+
+            }
+        } else {
+            return '<h1 class="text-danger">失败<br><p style="color: red">不支持该文件类型</p></h1>';
+        }
     }
 }

+ 29 - 19
app/Imports/InventoryCompareImport.php

@@ -2,16 +2,9 @@
 
 namespace App\Imports;
 
-use App\OracleDOCOrderHeader;
-use App\Order;
-use App\OrderIssue;
-use App\OrderIssueProcessLog;
-use App\OrderIssueType;
-use App\Services\OrderService;
-use App\Services\RejectedService;
-use Doctrine\DBAL\Connection;
+use App\Commodity;
+use App\Services\InventoryCompareService;
 use Illuminate\Support\Collection;
-use Illuminate\Support\Facades\Auth;
 use Illuminate\Support\Facades\Cache;
 use Maatwebsite\Excel\Concerns\ToCollection;
 use Maatwebsite\Excel\Concerns\WithHeadingRow;
@@ -22,24 +15,33 @@ HeadingRowFormatter::default('none');
 
 class InventoryCompareImport implements ToCollection, WithHeadingRow, WithMultipleSheets
 {
+    protected $owner_id=null;
+    public function __construct($owner_id)
+    {
+            $this->owner_id=$owner_id;
+            app()->singleton('inventoryCompareService',InventoryCompareService::class);
+    }
 
     public function Collection(Collection $collection)
     {
-        //$sku=$collection->toArray()[0]['产品编号'] ?? $collection->toArray()[0]['SKU'] ?? $collection->toArray()[0]['物料编号'] ?? ' ';
-        //$amount=$collection->toArray()[0]['数量'] ?? $collection->toArray()[0]['物料库存'] ?? $collection->toArray()[0]['库存量'] ?? ' ';
-        //$warehouse=$collection->toArray()[0]['属性仓'] ?? $collection->toArray()[0]['仓库'] ??' ';
         $endIS = false;
+        $skuAndWarehouseArr=[];
+        foreach ($collection as $row){
+            $skuAndWarehouse=$row['产品编号'].$row['属性仓'];
+            array_push($skuAndWarehouseArr,$skuAndWarehouse);
+        }
+        $uniqueArr=array_unique($skuAndWarehouseArr);
         if (!isset($collection->toArray()[0]['产品编号']) || !isset($collection->toArray()[0]['数量']) || !isset($collection->toArray()[0]['属性仓'])) {
             Cache::put('error', '请检查您第一行标题是否存在产品编号,数量,属性仓');
+        }elseif(count($uniqueArr)!=count($skuAndWarehouseArr)){
+            Cache::put('error', '产品编号+属性仓不能同时重复!');
         } else {
             $endIS = true;
         }
         $exception = [];
-        $skuAndWarehouseArr=[];
         $sum = 2;
         if ($endIS) {
             foreach ($collection as $row) {
-                //$sku = trim($row['产品编号'], ' ');
                 if (!$row['产品编号']) {
                     array_push($exception, ['第' . $sum . '行产品编号为空!']);
                     $sum++;
@@ -53,12 +55,20 @@ class InventoryCompareImport implements ToCollection, WithHeadingRow, WithMultip
                     $sum++;
                     continue;
                 }
-                $skuAndWarehouse=$row['产品编号']+$row['属性仓'];
-                array_push($skuAndWarehouseArr,$skuAndWarehouse);
+                $hasSku=Commodity::where('owner_id',$this->owner_id)->where('sku',$row['产品编号'])->first();
+                if (!$hasSku){
+                    array_push($exception, ['该货主下不存在产品编号:'.$row['产品编号']]);
+                    $sum++;
+                }
+                $inventoryCompare=app('inventoryCompareService')->createInventoryCompare($row['产品编号'],$row['属性仓'],$row['数量'],$this->owner_id);
+                if ($inventoryCompare){
+                    array_push($exception, ['产品编号为:' . $row['产品编号'] . '库存对比创建成功!']);
+                }else{
+                    array_push($exception, ['产品编号为:' . $row['产品编号'] . '库存对比创建失败!']);
+                }
                 $sum++;
             }
-            $uniqueArr=array_unique($skuAndWarehouseArr);
-            if (count($uniqueArr)!=count($skuAndWarehouseArr))array_push($exception, ['产品编码+属性仓不能同时重复!']);
+
         }
         Cache::put('exception', $exception, 86400);
     }
@@ -70,6 +80,6 @@ class InventoryCompareImport implements ToCollection, WithHeadingRow, WithMultip
      */
     public function sheets(): array
     {
-        return [0 => new OrderIssueImport()];
+        return [0 => new InventoryCompareImport($this->owner_id)];
     }
 }

+ 20 - 0
app/InventoryCompare.php

@@ -0,0 +1,20 @@
+<?php
+
+namespace App;
+
+use App\Traits\ModelTimeFormat;
+use Illuminate\Database\Eloquent\Model;
+
+class InventoryCompare extends Model
+{
+    use ModelTimeFormat;
+    protected $fillable=[
+        'owner_id','commodity_id', 'mission_code', 'source','custom_location','quality','amount_in_sys','amount_in_compare','differ','created_at',
+    ];
+    public function commodity(){
+        return $this->belongsTo('App\Commodity','commodity_id','id');
+    }
+    public function owner(){
+        return $this->belongsTo('App\Owner','owner_id','id');
+    }
+}

+ 140 - 0
app/Services/InventoryCompareService.php

@@ -0,0 +1,140 @@
+<?php
+
+
+namespace App\Services;
+
+use App\Commodity;
+use App\Http\Controllers\Controller;
+use App\InventoryCompare;
+use App\Owner;
+use App\Services\common\QueryService;
+use Carbon\Carbon;
+use Illuminate\Support\Facades\DB;
+use Overtrue\Pinyin\Pinyin;
+use Ramsey\Uuid\Uuid;
+
+class InventoryCompareService
+{
+    private function conditionQuery($SKU,$LotAtt05,$descr_c){
+        $sql='select * from (select result.*,rownum rn from (';
+        $sql.=' select customer.Descr_C as 货主,storeStatus.CUSTOMERID 客户,storeStatus.LocationID 库位, sku.SKU 产品编码, sku.ALTERNATE_SKU1 产品条码, ';
+        $sql.=' sku.Descr_C 商品名称, lot.LotAtt05 属性仓, lot.LotAtt08 质量状态, lot.LotAtt02 失效日期, storeStatus.ADDTIME 创建时间, ';
+        $sql.=' lot.LotAtt04 批号 ';
+        $sql.=' , storeStatus.QTY 在库数量, storeStatus.QtyAllocated 占用数量,count(1) over () as sum from ';
+        $sql.=' INV_LOT_LOC_ID storeStatus';
+        $sql.=' left join BAS_Customer customer on customer.CustomerID=storeStatus.CUSTOMERID ';
+        $sql.=' left join BAS_SKU sku on sku.SKU=storeStatus.SKU and sku.CUSTOMERID=storeStatus.CUSTOMERID ';
+        $sql.=' left join INV_LOT_ATT lot on lot.LOTNUM = storeStatus.LOTNUM AND lot.CUSTOMERID = storeStatus.CUSTOMERID ';
+        $sql.=' group by storeStatus.LocationID,customer.Descr_C,sku.SKU,sku.ALTERNATE_SKU1 ';
+        $sql.=' ,sku.Descr_C,lot.LotAtt05,lot.LotAtt08,lot.LotAtt02,lot.LotAtt04 ';
+        $sql.=' , storeStatus.QTY, storeStatus.QtyAllocated,storeStatus.CUSTOMERID,storeStatus.ADDTIME  ';
+        $sql.=' )result where 1=1 ';
+        if ($SKU)$sql.=" and 产品编码 like '".$SKU."' ";
+        if ($LotAtt05)$sql .=" and 属性仓 like '".$LotAtt05."' ";
+        if ($descr_c)$sql.=" and 货主 = '".$descr_c."' ";
+        $sql.=' )  ';
+        return DB::connection('oracle')->select($sql);
+    }
+
+    public function createInventoryCompare($SKU,$LotAtt05,$amount,$ownerId){
+        $ownerName=Owner::where('id',$ownerId)->value('name');
+        $request=[
+            '产品编码'=>$SKU,
+            '属性仓'=>$LotAtt05,
+            '数量'=>$amount,
+            '货主'=>$ownerId,
+        ];
+        $wmsInventories=$this->conditionQuery($SKU,$LotAtt05,$ownerName);
+        if (count($wmsInventories)==0) return null;
+        $zpAmount=0;
+        $ccAmount=0;
+        $amountTotal=0;
+        foreach ($wmsInventories as $wmsInventory){
+            $commodity=Commodity::query()->firstOrCreate([
+                'owner_id'=>$ownerId,
+                'sku'=>$wmsInventory->产品编码,
+                'name'=>$wmsInventory->商品名称,
+            ]);
+            Controller::logS(__METHOD__,"根据wms产品编码和货主查询或创建商品信息__".__FUNCTION__,json_encode($wmsInventory));
+            $commodity->newBarcode($wmsInventory->产品条码);
+            Controller::logS(__METHOD__,"根据wms产品条码和商品id查询或创建商品条码信息__".__FUNCTION__,json_encode($wmsInventory));
+            $amountTotal=$amountTotal+$wmsInventory->在库数量;
+            if ($wmsInventory->质量状态=='DJ'||$wmsInventory->质量状态=='ZP'){
+                $zpAmount=$zpAmount+$wmsInventory->在库数量;
+            }
+            if ($wmsInventory->质量状态=='CC'){
+                $ccAmount=$ccAmount+$wmsInventory->在库数量;
+            }
+        }
+        $unknownStatusAmount=$amountTotal-$ccAmount-$zpAmount;
+        $pinyin=new Pinyin();
+        $owner=strtoupper($pinyin->abbr($ownerName));
+        $commodityId=Commodity::where('sku',$SKU)->where('owner_id',$ownerId)->value('id');
+        $inventoryCompare=new InventoryCompare();
+        $inventoryCompare->owner_id=$ownerId;
+        $inventoryCompare->commodity_id=$commodityId;
+        $inventoryCompare->mission_code=Uuid::uuid1();
+        $inventoryCompare->custom_location=$LotAtt05;
+        $inventoryCompare->created_at=Carbon::now()->format('Y-m-d H:i:s');
+        if ($zpAmount!=0){
+            $inventoryCompare->quality='正品';
+            $inventoryCompare->amount_in_sys=$zpAmount;
+            $inventoryCompare->amount_in_compare=$amount;
+            $inventoryCompare->differ=$zpAmount-$amount;
+            $inventoryCompare->save();
+            Controller::logS(__METHOD__,"创建库存对比__".__FUNCTION__,json_encode($request));
+            $mission_code =$owner.date ("ymd").'KCBD'.str_pad($inventoryCompare['id']>99999?$inventoryCompare['id']%99999:$inventoryCompare['id'],4,"0",STR_PAD_LEFT);
+            $inventoryCompare->update(['mission_code' => $mission_code ]);
+            Controller::logS(__METHOD__,"修改库存对比任务号__".__FUNCTION__,json_encode($mission_code));
+        }
+        if ($ccAmount!=0){
+            $inventoryCompare->quality='次品';
+            $inventoryCompare['amount_in_sys']=$ccAmount;
+            $inventoryCompare->save();
+            Controller::logS(__METHOD__,"创建库存对比__".__FUNCTION__,json_encode($request));
+            $mission_code =$owner.date ("ymd").'KCBD'.str_pad($inventoryCompare['id']>99999?$inventoryCompare['id']%99999:$inventoryCompare['id'],4,"0",STR_PAD_LEFT);
+            $inventoryCompare->update(['mission_code' => $mission_code ]);
+            Controller::logS(__METHOD__,"修改库存对比任务号__".__FUNCTION__,json_encode($mission_code));
+        }
+        if ($unknownStatusAmount!=0){
+            $inventoryCompare->quality='未知';
+            $inventoryCompare->amount_in_sys=$unknownStatusAmount;
+            $inventoryCompare->save();
+            Controller::logS(__METHOD__,"创建库存对比__".__FUNCTION__,json_encode($request));
+            $mission_code =$owner.date ("ymd").'KCBD'.str_pad($inventoryCompare['id']>99999?$inventoryCompare['id']%99999:$inventoryCompare['id'],4,"0",STR_PAD_LEFT);
+            $inventoryCompare->update(['mission_code' => $mission_code ]);
+            Controller::logS(__METHOD__,"修改库存对比任务号__".__FUNCTION__,json_encode($mission_code));
+        }
+        return $inventoryCompare;
+    }
+
+    private function conditionQueryInventoryCompare(array $param){
+        $differ=$param['differ']??'';
+        if ($differ=='有'){
+            $inventoryCompares = InventoryCompare::query()->with(['owner','commodity'=>function($query){
+                $query->with('barcodes');
+            }])->where('differ','>',0)->orderByDesc('id');
+        }elseif ($differ=='无'){
+            $inventoryCompares = InventoryCompare::query()->with(['owner','commodity'=>function($query){
+                $query->with('barcodes');
+            }])->where('differ','<',0)->orderByDesc('id');
+        }else{
+            $inventoryCompares = InventoryCompare::query()->with(['owner','commodity'=>function($query){
+                $query->with('barcodes');
+            }])->orderByDesc('id');
+        }
+        unset($param['differ']);
+        $columnQueryRules=[
+            'owner_id' => ['multi' => ','],
+            'date_start' => ['alias' => 'created_at' , 'startDate' => ' 00:00:00'],
+            'date_end' => ['alias' => 'created_at' , 'endDate' => ' 23:59:59'],
+            'mission_code' => ['timeLimit' => 20],
+        ];
+        $inventoryCompares = app(QueryService::class)->query($param,$inventoryCompares,$columnQueryRules);
+        return $inventoryCompares;
+    }
+
+    public function getInventoryCompare(array $param){
+        return $this->conditionQueryInventoryCompare($param)->paginate($param['paginate'] ?? 50);
+    }
+}

+ 1 - 0
composer.json

@@ -24,6 +24,7 @@
         "laravel/ui": "^2.0",
         "maatwebsite/excel": "^3.1",
         "overtrue/laravel-pinyin": "^4.0",
+        "overtrue/pinyin": "~4.0",
         "predis/predis": "^1.1",
         "pusher/pusher-php-server": "^4.1",
         "te7a-houdini/laravel-trix": "^2.0",

+ 3 - 65
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "f4d52aaf7352619209624162217398b6",
+    "content-hash": "3265d788ac2bebe35d6a987757bc3a21",
     "packages": [
         {
             "name": "bacon/bacon-qr-code",
@@ -111,12 +111,6 @@
                 "brick",
                 "math"
             ],
-            "funding": [
-                {
-                    "url": "https://tidelift.com/funding/github/packagist/brick/math",
-                    "type": "tidelift"
-                }
-            ],
             "time": "2020-04-15T15:59:35+00:00"
         },
         {
@@ -407,20 +401,6 @@
                 "sqlserver",
                 "sqlsrv"
             ],
-            "funding": [
-                {
-                    "url": "https://www.doctrine-project.org/sponsorship.html",
-                    "type": "custom"
-                },
-                {
-                    "url": "https://www.patreon.com/phpdoctrine",
-                    "type": "patreon"
-                },
-                {
-                    "url": "https://tidelift.com/funding/github/packagist/doctrine%2Fdbal",
-                    "type": "tidelift"
-                }
-            ],
             "time": "2020-04-20T17:19:26+00:00"
         },
         {
@@ -2994,12 +2974,6 @@
                 "Pinyin",
                 "cn2pinyin"
             ],
-            "funding": [
-                {
-                    "url": "https://www.patreon.com/overtrue",
-                    "type": "patreon"
-                }
-            ],
             "time": "2020-04-13T08:53:30+00:00"
         },
         {
@@ -3319,12 +3293,12 @@
             "version": "v1.1.1",
             "source": {
                 "type": "git",
-                "url": "https://github.com/nrk/predis.git",
+                "url": "https://github.com/predis/predis.git",
                 "reference": "f0210e38881631afeafb56ab43405a92cafd9fd1"
             },
             "dist": {
                 "type": "zip",
-                "url": "https://api.github.com/repos/nrk/predis/zipball/f0210e38881631afeafb56ab43405a92cafd9fd1",
+                "url": "https://api.github.com/repos/predis/predis/zipball/f0210e38881631afeafb56ab43405a92cafd9fd1",
                 "reference": "f0210e38881631afeafb56ab43405a92cafd9fd1",
                 "shasum": "",
                 "mirrors": [
@@ -4170,12 +4144,6 @@
                 "highlight.php",
                 "syntax"
             ],
-            "funding": [
-                {
-                    "url": "https://github.com/allejo",
-                    "type": "github"
-                }
-            ],
             "time": "2020-03-02T05:59:21+00:00"
         },
         {
@@ -7203,16 +7171,6 @@
                 "oracle",
                 "pdo_oci"
             ],
-            "funding": [
-                {
-                    "url": "https://www.paypal.me/yajra",
-                    "type": "custom"
-                },
-                {
-                    "url": "https://www.patreon.com/yajra",
-                    "type": "patreon"
-                }
-            ],
             "time": "2020-03-04T02:15:19+00:00"
         },
         {
@@ -7336,12 +7294,6 @@
                 "profiler",
                 "webprofiler"
             ],
-            "funding": [
-                {
-                    "url": "https://github.com/barryvdh",
-                    "type": "github"
-                }
-            ],
             "time": "2020-05-05T10:53:32+00:00"
         },
         {
@@ -7868,20 +7820,6 @@
                 "php",
                 "symfony"
             ],
-            "funding": [
-                {
-                    "url": "https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=66BYDWAT92N6L",
-                    "type": "custom"
-                },
-                {
-                    "url": "https://github.com/nunomaduro",
-                    "type": "github"
-                },
-                {
-                    "url": "https://www.patreon.com/nunomaduro",
-                    "type": "patreon"
-                }
-            ],
             "time": "2020-04-04T19:56:08+00:00"
         },
         {

+ 29 - 0
database/migrations/2020_08_27_142630_add_authorities_inventory_compare.php

@@ -0,0 +1,29 @@
+<?php
+
+use App\Authority;
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddAuthoritiesInventoryCompare extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        (new Authority(['name'=>'库存管理-库存-库存对比','alias_name'=>'库存管理-库存-库存对比']))->save();
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Authority::where('name','库存管理-库存-库存对比')->delete();
+    }
+}

+ 41 - 0
database/migrations/2020_08_27_153512_create_inventory_compares_table.php

@@ -0,0 +1,41 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class CreateInventoryComparesTable extends Migration
+{
+    /**
+     * Run the migrations.
+     *
+     * @return void
+     */
+    public function up()
+    {
+        Schema::create('inventory_compares', function (Blueprint $table) {
+            $table->bigIncrements('id');
+            $table->integer('owner_id')->index();
+            $table->integer('commodity_id')->index();
+            $table->string('mission_code')->nullable()->comment('任务号');
+            $table->enum('source',['客户表','无'])->default('客户表')->index()->comment('来源');
+            $table->string('custom_location')->nullable()->comment('属性仓');
+            $table->enum('quality',['正品','次品','未知'])->comment('质量状态');
+            $table->integer('amount_in_sys')->nullable()->comment('宝时库存');
+            $table->integer('amount_in_compare')->nullable()->comment('参考库存');
+            $table->integer('differ')->index()->default(0)->comment('差值');
+            $table->timestamp('created_at')->index()->nullable();
+            $table->timestamp('updated_at')->nullable();
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     *
+     * @return void
+     */
+    public function down()
+    {
+        Schema::dropIfExists('inventory_compares');
+    }
+}

+ 88 - 26
resources/views/inventory/statement/inventoryCompare.blade.php

@@ -4,6 +4,70 @@
 @section('content')
     @component('inventory.statement.menu')@endcomponent
     <div class="d-none card" id="container">
+
+
+        <div class="modal fade" id="importExcel" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
+            <div class="modal-dialog">
+                <div class="modal-content">
+                    <div class="modal-header">
+                        <h5 class="modal-title" id="exampleModalLabel">导入相关excel</h5>
+                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
+                            <span aria-hidden="true">&times;</span>
+                        </button>
+                    </div>
+                    <div class="modal-body">
+                        <form method="POST" action="{{ url('inventory/inventoryCompare/import/excel') }}" enctype="multipart/form-data" target="_blank">
+                            @csrf
+                            <div class="form-group row text-center">
+                                <div class="col-12 text-danger">
+
+                                    注意:导入字段头必须有以下字段名在第一行表头行,不分顺序:<br>
+                                    产品编码,数量,属性仓<br>
+                                </div>
+                                <div class="col-12 text-info ">
+                                    导入时间随文件大小可能达数十分钟以上,请耐心等候
+                                    <hr>
+                                </div>
+                            </div>
+                            <div class="form-group row">
+                                <label for="sku" class="col-2 col-form-label text-right">选择EXCEL</label>
+                                <div class="col-8">
+                                    <div class="form-control">
+                                        <input type="file" class="form-control-file @error('file') is-invalid @enderror"
+                                               name="file" value="{{ old('file') }}" required>
+                                        @error('file')
+                                        <span class="invalid-feedback" role="alert">
+                                <strong>{{ $message }}</strong>
+                            </span>
+                                        @enderror
+                                    </div>
+                                </div>
+                            </div>
+                            <div class="form-group row">
+                                <label for="sku" class="col-2 col-form-label text-right">选择货主</label>
+                                <div class="col-8">
+                                    <select name="owner_id" id="owner_id" class="form-control @error('owner_id') is-invalid @enderror">
+                                        <option value="">货主</option>
+                                        <option v-for="owner in owners" :value="owner.name">@{{ owner.value }}</option>
+                                    </select>
+                                    @error('owner_id')
+                                    <span class="invalid-feedback" role="alert">
+                                <strong>{{ $message }}</strong>
+                            </span>
+                                    @enderror
+                                </div>
+                            </div>
+                            <div class="form-group row">
+                                <div class="col-8 offset-2">
+                                    <input type="submit" class="btn btn-success form-control"  value="执行导入">
+                                </div>
+                            </div>
+                        </form>
+                    </div>
+                </div>
+            </div>
+        </div>
+
         <div class="card-header pt-0">
             <div id="form"></div>
         </div>
@@ -14,15 +78,12 @@
                     导出Excel
                 </button>
                 <div class="dropdown-menu">
-                    <a class="dropdown-item" @click="dailyLogExport(false)" href="javascript:">导出勾选内容</a>
-                    <a class="dropdown-item" @click="dailyLogExport(true)" href="javascript:">导出所有页</a>
+                    <a class="dropdown-item" @click="inventoryCompareExport(false)" href="javascript:">导出勾选内容</a>
+                    <a class="dropdown-item" @click="inventoryCompareExport(true)" href="javascript:">导出所有页</a>
                 </div>
             </span>
             <span>
-                <button class="btn btn-outline-dark btn-sm form-control-sm  tooltipTarget"
-                           title="导入Excel生成库存对比">
-                   导入
-                </button>
+                <button class="btn btn-outline-dark btn-sm form-control-sm  tooltipTarget" title="导入Excel生成库存对比" @click="importExcel">导入</button>
             </span>
         </div>
     </span>
@@ -33,25 +94,22 @@
             <table class="table table-sm text-nowrap table-bordered d-none" id="headerRoll"></table>
             <table class="table table-sm text-nowrap table-striped table-bordered m-0" id="headerParent">
                 <tr class="p-0" id="header"></tr>
-                <tr >
+                <tr v-for="(inventoryCompare,i) in inventoryCompares">
                    <td>
                        <input type="checkbox" >
                    </td>
-                    <td>@{{  }}</td>
-                    <td>@{{  }}</td>
-                    <td>@{{  }}</td>
-                    <td>@{{  }}</td>
-                    <td>@{{  }}</td>
-                    <td>
-                        <span>
-                            <span >
-                                @{{  }}
-                            </span>
-                            <span >
-                                <small >@{{  }}<br></small>
-                            </span>
-                        </span>
-                    </td>
+                    <td>@{{ i+1 }}</td>
+                    <td>@{{ inventoryCompare.owner.name }}</td>
+                    <td>@{{ inventoryCompare.mission_code }}</td>
+                    <td>@{{ inventoryCompare.created_at }}</td>
+                    <td>@{{ inventoryCompare.commodity.name }}</td>
+                    <td>@{{ inventoryCompare.commodity.sku }}</td>
+                    <td>@{{ inventoryCompare.commodity.barcode }}</td>
+                    <td>@{{ inventoryCompare.custom_location }}</td>
+                    <td>@{{ inventoryCompare.quality }}</td>
+                    <td>@{{ inventoryCompare.amount_in_sys }}</td>
+                    <td>@{{ inventoryCompare.amount_in_compare }}</td>
+                    <td>@{{ inventoryCompare.differ }}</td>
                 </tr>
             </table>
         </div>
@@ -66,6 +124,7 @@
         let vue = new Vue({
             el:"#container",
             data:{
+                inventoryCompares:{!! $inventoryCompares->toJson() !!}['data'],
                 differ:[
                     {name:'全部',value:'全部'},{name:'有',value:'有'},{name:'无',value:'无'},
                 ],
@@ -112,10 +171,10 @@
                     {name:'commodity_sku',value: '商品编码'},
                     {name: 'commodity_barcodes', value: '商品条码', neglect: true},
                     {name: 'amount', value: '属性仓', neglect: true},
-                    {name: '', value: '质量状态', neglect: true},
-                    {name: '',value: '宝时库存', neglect: true},
-                    {name: '', value: '参考库存', neglect: true},
-                    {name: '', value: '差值', neglect: true},
+                    {name: 'quality', value: '质量状态', neglect: true},
+                    {name: 'amount_in_sys',value: '宝时库存', neglect: true},
+                    {name: 'amount_in_compare', value: '参考库存', neglect: true},
+                    {name: 'differ', value: '差值', neglect: true},
                 ];
                 let _this = this;
                 setTimeout(function () {
@@ -131,6 +190,9 @@
                 },0);
             },
             methods:{
+                importExcel(){
+                    $('#importExcel').modal('show');
+                },
             },
         });
     </script>

+ 3 - 0
routes/web.php

@@ -318,8 +318,11 @@ Route::group(['prefix'=>'inventory'],function (){
     Route::post('statement/dailyLog/getLoggingOwner','InventoryController@getLoggingOwner');
     //复盘查询盘点记录
     Route::post('searchStockInventoryRecord','InventoryAccountController@searchStockInventoryRecord');
+
     //库存对比
     Route::get('statement/inventoryCompare','InventoryController@inventoryCompare');
+    //库存对比批量导入
+    Route::post('inventoryCompare/import/excel','InventoryController@importExcel');
 
     Route::post('statement/dailyLog/addLoggingOwner','InventoryController@addLoggingOwner');
 });