| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- <?php
- namespace App\Http\Controllers;
- use App\Exports\Export;
- use App\InventoryAccount;
- use App\InventoryAccountMission;
- use App\Owner;
- use App\Services\InventoryAccountService;
- use App\Services\OwnerService;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Support\Facades\Gate;
- use Maatwebsite\Excel\Facades\Excel;
- class InventoryAccountController extends Controller
- {
- public function __construct()
- {
- app()->singleton('inventoryAccountService',InventoryAccountService::class);
- }
- //创建盘点任务
- public function createStockInventoryMission(Request $request){
- if(!Gate::allows("库存管理-盘点")){ return redirect(url('/')); }
- // $date_start=$request->input('formData.date_start');
- // $date_end=$request->input('formData.date_end');
- // $ownerId=$request->input('formData.owner_id')[0];
- $date_start=$request->input('date_start');
- $date_end=$request->input('date_end');
- $ownerId=$request->input('owner_id');
- $inventoryAccount=app('inventoryAccountService')->createMission($date_start,$date_end,$ownerId);
- $inventoryAccount=InventoryAccount::with('owner')->find($inventoryAccount->id);
- if (is_null($inventoryAccount)) return ['success'=>false,'data'=>'参数错误!'];
- return ['success'=>true,'data'=>$inventoryAccount];
- }
- //删除盘点任务
- public function deleteStockInventoryMission($id){
- if(!Gate::allows('库存管理-盘点')){return['success'=>0,'status'=>'没有权限'];}
- if(is_null($id)){return ['success'=>false,'data'=>'传入id为空'];}
- $inventoryAccount=InventoryAccount::where('id',$id)->delete();
- return ['success'=>true,'data'=>$inventoryAccount];
- }
- //盘点-任务页面
- public function mission(Request $request,OwnerService $ownerService){
- if(!Gate::allows("库存管理-盘点")){ return redirect(url('/')); }
- $ownerService->syncOwnersData();
- $paginateParams = $request->input();
- $queryParam=$request->all();
- $inventoryAccounts=app('inventoryAccountService')->paginate($queryParam);
- $owners=Owner::select('id','name')->get();
- return view('inventory.stockInventory.mission',compact('owners','inventoryAccounts','paginateParams'));
- }
- //进入盘点中或复盘页面
- public function enterStockInventory($id){
- if (!Gate::allows('库存管理-盘点')){return redirect(url('/')); }
- if (!$id) return ['success'=>false,'data'=>'参数错误!'];
- $inventoryAccount=InventoryAccount::with('owner')->find($id);
- $inventoryAccountMissions=InventoryAccountMission::with('commodity.barcodes')->where('inventory_account_id',$id)->orderBy('difference_amount','desc')->get();
- return view('inventory.stockInventory.inventoryMission',compact('inventoryAccount','inventoryAccountMissions'));
- }
- //依据盘点任务id进行 --盘点
- public function stockInventory(Request $request){
- if (!Gate::allows('库存管理-盘点')){return redirect(url('/')); }
- $location=$request->input('location');
- $barcode=$request->input('barcode');
- $inventoryId=$request->input('inventoryId');
- $count=$request->input('count');
- if (is_null($count)) return ['success'=>false,'data'=>'盘点数不能为空!'];
- $inventoryAccountMission=app('inventoryAccountService')->stockInventory($location,$barcode,$count,$inventoryId);
- if (!$inventoryAccountMission)return ['success'=>false,'data'=>'参数错误!'];
- $inventoryAccount=app('inventoryAccountService')->updateInventory($inventoryId);
- return ['success'=>true,'inventoryMission'=>$inventoryAccountMission,'inventory'=>$inventoryAccount];
- }
- //根据该库存和产品条码查询该条盘点记录
- public function searchStockInventoryRecord(Request $request){
- if (!Gate::allows('库存管理-盘点')){return redirect(url('/')); }
- $location=$request->input('location');
- $barcode=$request->input('barcode');
- $inventoryId=$request->input('inventoryId');
- $inventoryAccountMission=app('inventoryAccountService')->searchStockInventoryRecord($location,$barcode,$inventoryId);
- if (!$inventoryAccountMission)return ['success'=>false,'data'=>'参数错误!'];
- return ['success'=>true,'data'=>$inventoryAccountMission];
- }
- //盘点任务导出
- public function stockInventoryExport(Request $request){
- if (!Gate::allows('库存管理-盘点')){return redirect(url('/')); }
- ini_set('max_execution_time',3500);
- ini_set('memory_limit','3526M');
- if ($request->checkAllSign){
- $request->offsetUnset('checkAllSign');
- $queryParam=$request->all();
- $inventoryAccounts=app('inventoryAccountService')->get($queryParam);
- }else{
- $queryParam=$request->all();
- $inventoryAccounts=app('inventoryAccountService')->some($queryParam);
- }
- $row=[[
- 'id'=>'盘点编号',
- 'status'=>'盘点状态',
- 'created_at'=>'创建时间',
- 'owner_id'=>'货主',
- 'type'=>'任务类型',
- 'start_at'=>'起始时间',
- 'end_at'=>'结束时间',
- 'total'=>'记录数',
- 'processed'=>'已盘数',
- 'surplus'=>'剩余数',
- 'difference'=>'复盘差异',
- 'returned'=>'复盘归位',
- ]];
- $list=[];
- for ($i=0; $i<count($inventoryAccounts);$i++){
- $inventoryAccount=$inventoryAccounts[$i];
- $w=[
- 'id'=>isset($inventoryAccount->id)?$inventoryAccount->id:'',
- 'status'=>isset($inventoryAccount->status)?$inventoryAccount->status:'',
- 'created_at'=>isset($inventoryAccount->created_at)?$inventoryAccount->created_at:'',
- 'owner_id'=>isset($inventoryAccount->owner->name)?$inventoryAccount->owner->name:'',
- 'type'=>isset($inventoryAccount->type)?$inventoryAccount->type:'',
- 'start_at'=>isset($inventoryAccount->start_at)?$inventoryAccount->start_at:'',
- 'end_at'=>isset($inventoryAccount->end_at)?$inventoryAccount->end_at:'',
- 'total'=>isset($inventoryAccount->total)?$inventoryAccount->total:'',
- 'processed'=>isset($inventoryAccount->processed)?$inventoryAccount->processed:'',
- 'surplus'=>isset($inventoryAccount->surplus)?$inventoryAccount->surplus:'',
- 'difference'=>isset($inventoryAccount->difference)?$inventoryAccount->difference:'',
- 'returned'=>isset($inventoryAccount->returned)?$inventoryAccount->returned:'',
- ];
- $list[$i]=$w;
- }
- return Excel::download(new Export($row,$list),date('YmdHis', time()).'-盘点任务记录单.xlsx');
- }
- public function stockInventoryEnd(Request $request){
- if (!Gate::allows('库存管理-盘点')){return redirect(url('/')); }
- $id=$request->input('id');
- if (!$id) return ['success'=>false,'data'=>'参数错误!'];
- $inventoryAccount=InventoryAccount::query()->where('id',$id)->update(['status'=>'复盘中']);
- $this->log(__METHOD__,'结束初盘任务'.__FUNCTION__,json_encode($request->toArray()),Auth::user()['id']);
- if ($inventoryAccount>0) return ['success'=>true,'data'=>'复盘中'];
- return ['success'=>false,'data'=>'参数错误!'];
- }
- public function syncOwners(OwnerService $ownerService){
- if (!Gate::allows('库存管理-盘点')){return redirect(url('/')); }
- $owners=$ownerService->syncOwnersData();
- if (!$owners)return ['success'=>false,'data'=>'同步货主失败!'];
- return ['success'=>true,'data'=>$owners];
- }
- }
|