|
|
@@ -12,6 +12,7 @@ use App\OracleActTransactionLog;
|
|
|
use App\Owner;
|
|
|
use App\Services\common\QueryService;
|
|
|
use Illuminate\Http\Request;
|
|
|
+use Illuminate\Support\Collection;
|
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
@@ -19,36 +20,33 @@ use Illuminate\Support\Facades\Gate;
|
|
|
class InventoryService
|
|
|
{
|
|
|
|
|
|
- private function conditionQuery(Request $request){
|
|
|
+ private function conditionQuery($queryParam){
|
|
|
$inventories=Inventory::query()->with(['owner'])->orderBy('id','desc');
|
|
|
$columnQueryRules=[
|
|
|
'owner_id' => ['multi' => ','],
|
|
|
'date_start' => ['alias' => 'created_at' , 'startDate' => ' 00:00:00'],
|
|
|
'date_end' => ['alias' => 'created_at' , 'endDate' => ' 23:59:59'],
|
|
|
];
|
|
|
- $inventories = app(QueryService::class)->query($request,$inventories,$columnQueryRules);
|
|
|
+ $inventories = app(QueryService::class)->queryCondition($queryParam,$inventories,$columnQueryRules);
|
|
|
return $inventories;
|
|
|
}
|
|
|
- public function paginate(Request $request){
|
|
|
- $inventories = $this->conditionQuery($request);
|
|
|
- return $inventories->paginate($request->paginate ?? 50);
|
|
|
+ public function paginate($queryParam){
|
|
|
+ $inventories = $this->conditionQuery($queryParam);
|
|
|
+ return $inventories->paginate($queryParam['paginate'] ?? 50);
|
|
|
}
|
|
|
|
|
|
- public function get(Request $request){
|
|
|
- $inventories = $this->conditionQuery($request);
|
|
|
+ public function get($queryParam){
|
|
|
+ $inventories = $this->conditionQuery($queryParam);
|
|
|
return $inventories->get();
|
|
|
}
|
|
|
|
|
|
- public function some(Request $request){
|
|
|
+ public function some($queryParam){
|
|
|
return Inventory::query()->with(['owner'])->orderBy('id','DESC')
|
|
|
- ->whereIn('id',explode(',',$request->data))->get();
|
|
|
+ ->whereIn('id',explode(',',$queryParam['data']))->get();
|
|
|
}
|
|
|
|
|
|
- public function conditionSearch(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];
|
|
|
+ public function conditionSearch($date_start,$date_end,$ownerId){
|
|
|
+ if (!$ownerId) return null;
|
|
|
$descr_c=Owner::where('id',$ownerId)->value('name');
|
|
|
$sql='select * from (select result.*,rownum rn from (';
|
|
|
$sql.=' select customer.Descr_C as 货主,stockLog.客户 客户, 库位, sku.SKU 产品编码, sku.ALTERNATE_SKU1 产品条码, ';
|
|
|
@@ -98,33 +96,35 @@ class InventoryService
|
|
|
return DB::connection('oracle')->select($sql);
|
|
|
}
|
|
|
//创建盘点任务
|
|
|
- public function createMission(Request $request){
|
|
|
- if(!Gate::allows("库存管理-盘点")){ return redirect(url('/')); }
|
|
|
- $date_start=$request->input('formData.date_start');
|
|
|
- $date_end=$request->input('formData.date_end');
|
|
|
- $ownerIds=$request->input('formData.owner_id');
|
|
|
- if (count($ownerIds)<=0) return null;
|
|
|
+ public function createMission($date_start,$date_end,$ownerId){
|
|
|
+ if (!$ownerId) return null;
|
|
|
if ($date_start&&$date_end){
|
|
|
+ $date_end_time=$date_end.' 23:59:59';
|
|
|
$type='动盘';
|
|
|
}elseif (!$date_start&&!$date_end){
|
|
|
- $name=Owner::where('id',$ownerIds[0])->value('name');
|
|
|
+ $name=Owner::where('id',$ownerId)->value('name');
|
|
|
$ownerName=OraccleBasCustomer::where('customer_type','OW')->where('active_flag','Y')->where('descr_c',$name)->value('customerid');
|
|
|
$date_start=OracleActTransactionLog::where('fmcustomerid',$ownerName)->orderBy('addtime','asc')->value('addtime');
|
|
|
- $date_end=OracleActTransactionLog::where('fmcustomerid',$ownerName)->orderBy('addtime','desc')->value('addtime');
|
|
|
+ $date_end_time=OracleActTransactionLog::where('fmcustomerid',$ownerName)->orderBy('addtime','desc')->value('addtime');
|
|
|
$type='全盘';
|
|
|
}else{
|
|
|
return null;
|
|
|
}
|
|
|
- $ownerId=$ownerIds[0];
|
|
|
$inventory=new Inventory([
|
|
|
'owner_id'=>$ownerId,
|
|
|
'type'=>$type,
|
|
|
'start_at'=>$date_start,
|
|
|
- 'end_at'=>$date_end,
|
|
|
+ 'end_at'=>$date_end_time,
|
|
|
]);
|
|
|
$inventory->save();
|
|
|
- $this->createInventoryMissionRecord($request,$inventory['id'],$ownerId);
|
|
|
- Controller::logS(__METHOD__,"创建盘点记录任务__".__FUNCTION__,json_encode($request,$inventory['id'],$ownerId),Auth::user()['id']);
|
|
|
+ $this->createInventoryMissionRecord($date_start,$date_end,$ownerId,$inventory['id']);
|
|
|
+ $request=[
|
|
|
+ 'date_start'=>$date_start,
|
|
|
+ 'date_end'=>$date_end,
|
|
|
+ 'ownerId'=>$ownerId,
|
|
|
+ 'inventoryId'=>$inventory['id'],
|
|
|
+ ];
|
|
|
+ Controller::logS(__METHOD__,"创建盘点记录任务__".__FUNCTION__,json_encode($request),Auth::user()['id']);
|
|
|
$inventoryMissionCount=InventoryMission::where('inventory_id',$inventory['id'])->count();
|
|
|
$inventory->total=$inventoryMissionCount;
|
|
|
$inventory->update();
|
|
|
@@ -133,8 +133,9 @@ class InventoryService
|
|
|
}
|
|
|
|
|
|
//创建盘点记录任务
|
|
|
- public function createInventoryMissionRecord($request,$inventoryId,$ownerId){
|
|
|
- $wmsInventories=$this->conditionSearch($request);
|
|
|
+ public function createInventoryMissionRecord($date_start,$date_end,$ownerId,$inventoryId){
|
|
|
+ if (!$ownerId) return null;
|
|
|
+ $wmsInventories=$this->conditionSearch($date_start,$date_end,$ownerId);
|
|
|
foreach ($wmsInventories as $wmsInventory){
|
|
|
$commodity=Commodity::query()->firstOrCreate([
|
|
|
'owner_id'=>$ownerId,
|
|
|
@@ -161,36 +162,60 @@ class InventoryService
|
|
|
$inventoryMission->occupied_amount=$wmsInventory->占用数量;
|
|
|
$inventoryMission->save();
|
|
|
}
|
|
|
+
|
|
|
}
|
|
|
//盘点库存
|
|
|
- public function stockInventory($request){
|
|
|
- $inventoryId=$request->inventoryId;
|
|
|
- $count=$request->count;
|
|
|
- $location=$request->location;
|
|
|
- $barcode=$request->barcode;
|
|
|
+ public function stockInventory($location,$barcode,$count,$inventoryId){
|
|
|
$inventoryMission=InventoryMission::with(['commodity'=>function($query)use($barcode){
|
|
|
return $query->with(['barcodes'=>function($sql)use($barcode){
|
|
|
return $sql->where('code',$barcode);
|
|
|
}]);
|
|
|
}])->where('location',$location)->where('inventory_id',$inventoryId)->first();
|
|
|
if (!$inventoryMission) return null;
|
|
|
- $inventoryMission->verified_amount=$count;
|
|
|
- $inventoryMission->difference_amount=abs($inventoryMission->stored_amount-$count);
|
|
|
- $inventoryMission->checked='是';
|
|
|
+ $inventory=Inventory::find($inventoryId);
|
|
|
+ if ($inventory->surplus!=0){
|
|
|
+ $inventoryMission->verified_amount=$count;
|
|
|
+ $inventoryMission->difference_amount=abs($inventoryMission->stored_amount-$count);
|
|
|
+ $inventoryMission->checked='是';
|
|
|
+ }else{
|
|
|
+ $inventoryMission->re_checked_amount=$count;
|
|
|
+ $inventoryMission->difference_amount=abs($inventoryMission->stored_amount-$count);
|
|
|
+ if ($inventoryMission->difference_amount==0){
|
|
|
+ $inventoryMission->returned='是';
|
|
|
+ }else{
|
|
|
+ $inventoryMission->returned='否';
|
|
|
+ }
|
|
|
+ }
|
|
|
$inventoryMission->update();
|
|
|
+ $request=[
|
|
|
+ 'location'=>$location,
|
|
|
+ 'barcode'=>$barcode,
|
|
|
+ 'count'=>$count,
|
|
|
+ 'inventoryId'=>$inventoryId,
|
|
|
+ ];
|
|
|
Controller::logS(__METHOD__,"盘点__".__FUNCTION__,json_encode($request));
|
|
|
return $inventoryMission;
|
|
|
}
|
|
|
- //盘点修改盘点任务中的已盘条数
|
|
|
- public function updateInventoryMissionProcessed($request){
|
|
|
- $inventoryId=$request->inventoryId;
|
|
|
+ //盘点修改盘点任务数据
|
|
|
+ public function updateInventory($inventoryId){
|
|
|
$inventory=Inventory::find($inventoryId);
|
|
|
- $processed=InventoryMission::where('checked','是')->where('inventory_id',$inventoryId)->count();
|
|
|
- $inventory->processed=$processed;
|
|
|
+ $inventory->processed=$inventory->getProcessedAmount();
|
|
|
+ $inventory->difference=$inventory->getDifferenceAmount();
|
|
|
+ $inventory->returned=$inventory->getReturnedAmount();
|
|
|
$inventory->update();
|
|
|
- Controller::logS(__METHOD__,"盘点修改盘点任务中的已盘条数__".__FUNCTION__,json_encode($request));
|
|
|
+ Controller::logS(__METHOD__,"盘点修改盘点任务中的已盘条数__".__FUNCTION__,json_encode($inventoryId));
|
|
|
return $inventory;
|
|
|
}
|
|
|
+ //根据该库存和产品条码查询该条盘点记录
|
|
|
+ public function searchStockInventoryRecord($location,$barcode,$inventoryId){
|
|
|
+ $inventoryMission=InventoryMission::with(['commodity'=>function($query)use($barcode){
|
|
|
+ return $query->with(['barcodes'=>function($sql)use($barcode){
|
|
|
+ return $sql->where('code',$barcode);
|
|
|
+ }]);
|
|
|
+ }])->where('location',$location)->where('inventory_id',$inventoryId)->first();
|
|
|
+ if (!$inventoryMission) return null;
|
|
|
+ return $inventoryMission;
|
|
|
+ }
|
|
|
|
|
|
|
|
|
}
|