|
|
@@ -5,10 +5,11 @@ namespace App\Services;
|
|
|
|
|
|
use App\Commodity;
|
|
|
use App\Http\Controllers\Controller;
|
|
|
-use App\Inventory;
|
|
|
-use App\InventoryMission;
|
|
|
+use App\InventoryAccount;
|
|
|
+use App\InventoryAccountMission;
|
|
|
use App\OraccleBasCustomer;
|
|
|
use App\OracleActTransactionLog;
|
|
|
+use App\OracleInvLotLocId;
|
|
|
use App\Owner;
|
|
|
use App\Services\common\QueryService;
|
|
|
use Illuminate\Http\Request;
|
|
|
@@ -17,11 +18,11 @@ use Illuminate\Support\Facades\Auth;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
|
|
-class InventoryService
|
|
|
+class InventoryAccountService
|
|
|
{
|
|
|
|
|
|
private function conditionQuery($queryParam){
|
|
|
- $inventories=Inventory::query()->with(['owner'])->orderBy('id','desc');
|
|
|
+ $inventories=InventoryAccount::query()->with(['owner'])->orderBy('id','desc');
|
|
|
$columnQueryRules=[
|
|
|
'owner_id' => ['multi' => ','],
|
|
|
'date_start' => ['alias' => 'created_at' , 'startDate' => ' 00:00:00'],
|
|
|
@@ -41,11 +42,11 @@ class InventoryService
|
|
|
}
|
|
|
|
|
|
public function some($queryParam){
|
|
|
- return Inventory::query()->with(['owner'])->orderBy('id','DESC')
|
|
|
+ return InventoryAccount::query()->with(['owner'])->orderBy('id','DESC')
|
|
|
->whereIn('id',explode(',',$queryParam['data']))->get();
|
|
|
}
|
|
|
-
|
|
|
- public function conditionSearch($date_start,$date_end,$ownerId){
|
|
|
+ //动盘查询
|
|
|
+ public function conditionPortStock($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 (';
|
|
|
@@ -93,7 +94,26 @@ class InventoryService
|
|
|
$sql .= ') ';
|
|
|
}
|
|
|
$sql.=' ) ';
|
|
|
- //dd($sql);
|
|
|
+ return DB::connection('oracle')->select($sql);
|
|
|
+ }
|
|
|
+ //全盘查询
|
|
|
+ private function conditionTotalStock($ownerId){
|
|
|
+ $descr_c=Owner::where('id',$ownerId)->value('name');
|
|
|
+ $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 批号,lot.LotAtt01 生产日期,lot.LotAtt03 入库日期 ';
|
|
|
+ $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,lot.LotAtt01,lot.LotAtt03 ';
|
|
|
+ $sql.=' )result where 1=1 ';
|
|
|
+ if ($descr_c)$sql.=" and 货主 = '".$descr_c."' ";
|
|
|
+ $sql.=' ) ';
|
|
|
return DB::connection('oracle')->select($sql);
|
|
|
}
|
|
|
//创建盘点任务
|
|
|
@@ -102,41 +122,39 @@ class InventoryService
|
|
|
if ($date_start&&$date_end){
|
|
|
$date_end_time=$date_end.' 23:59:59';
|
|
|
$type='动盘';
|
|
|
+ $wmsInventories=$this->conditionPortStock($date_start,$date_end,$ownerId);
|
|
|
}elseif (!$date_start&&!$date_end){
|
|
|
$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_time=OracleActTransactionLog::where('fmcustomerid',$ownerName)->orderBy('addtime','desc')->value('addtime');
|
|
|
+ $date_start=OracleInvLotLocId::where('customerid',$ownerName)->orderBy('addtime','ASC')->value('addtime');
|
|
|
+ $date_end_time=OracleInvLotLocId::where('customerid',$ownerName)->orderBy('addtime','DESC')->value('addtime');
|
|
|
$type='全盘';
|
|
|
+ $wmsInventories=$this->conditionTotalStock($ownerId);
|
|
|
}else{
|
|
|
return null;
|
|
|
}
|
|
|
- $inventory=new Inventory([
|
|
|
+ $inventory=new InventoryAccount([
|
|
|
'owner_id'=>$ownerId,
|
|
|
'type'=>$type,
|
|
|
'start_at'=>$date_start,
|
|
|
'end_at'=>$date_end_time,
|
|
|
+ 'total'=>count($wmsInventories),
|
|
|
]);
|
|
|
$inventory->save();
|
|
|
- $this->createInventoryMissionRecord($date_start,$date_end,$ownerId,$inventory['id']);
|
|
|
+ $this->createInventoryAccountMissionRecord($ownerId,$inventory['id'],$wmsInventories);
|
|
|
$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();
|
|
|
Controller::logS(__METHOD__,"创建盘点任务__".__FUNCTION__,json_encode($request),Auth::user()['id']);
|
|
|
return $inventory;
|
|
|
}
|
|
|
|
|
|
//创建盘点记录任务
|
|
|
- public function createInventoryMissionRecord($date_start,$date_end,$ownerId,$inventoryId){
|
|
|
- if (!$ownerId) return null;
|
|
|
- $wmsInventories=$this->conditionSearch($date_start,$date_end,$ownerId);
|
|
|
+ public function createInventoryAccountMissionRecord($ownerId,$inventoryAccountId,$wmsInventories){
|
|
|
+ $inventoryAccountMissions=[];
|
|
|
foreach ($wmsInventories as $wmsInventory){
|
|
|
$commodity=Commodity::query()->firstOrCreate([
|
|
|
'owner_id'=>$ownerId,
|
|
|
@@ -146,75 +164,74 @@ class InventoryService
|
|
|
Controller::logS(__METHOD__,"根据wms产品编码和货主查询或创建商品信息__".__FUNCTION__,json_encode($wmsInventory));
|
|
|
$commodity->newBarcode($wmsInventory->产品条码);
|
|
|
Controller::logS(__METHOD__,"根据wms产品条码和商品id查询或创建商品条码信息__".__FUNCTION__,json_encode($wmsInventory));
|
|
|
- $inventoryMission = new InventoryMission();
|
|
|
- $inventoryMission->commodity_id=$commodity->id;
|
|
|
- $inventoryMission->inventory_id=$inventoryId;
|
|
|
- $inventoryMission->location=$wmsInventory->库位;
|
|
|
- $inventoryMission->produced_at=$wmsInventory->生产日期;
|
|
|
- $inventoryMission->valid_at=$wmsInventory->失效日期;
|
|
|
- $inventoryMission->stored_at=$wmsInventory->入库日期;
|
|
|
- $inventoryMission->batch_number=$wmsInventory->批号;
|
|
|
- $inventoryMission->erp_type_position=$wmsInventory->属性仓;
|
|
|
- $inventoryMission->quality=$wmsInventory->质量状态;
|
|
|
- $inventoryMission->stored_amount=$wmsInventory->在库数量;
|
|
|
- $inventoryMission->occupied_amount=$wmsInventory->占用数量;
|
|
|
- $inventoryMission->save();
|
|
|
+ $inventoryAccountMission=[
|
|
|
+ 'commodity_id'=>$commodity->id,
|
|
|
+ 'inventory_account_id'=>$inventoryAccountId,
|
|
|
+ 'location'=>$wmsInventory->库位,
|
|
|
+ 'produced_at'=>$wmsInventory->生产日期,
|
|
|
+ 'valid_at'=>$wmsInventory->失效日期,
|
|
|
+ 'stored_at'=>$wmsInventory->入库日期,
|
|
|
+ 'batch_number'=>$wmsInventory->批号,
|
|
|
+ 'erp_type_position'=>$wmsInventory->属性仓,
|
|
|
+ 'quality'=>$wmsInventory->质量状态,
|
|
|
+ 'stored_amount'=>$wmsInventory->在库数量,
|
|
|
+ 'occupied_amount'=>$wmsInventory->占用数量,
|
|
|
+ ];
|
|
|
+ array_push($inventoryAccountMissions,$inventoryAccountMission);
|
|
|
}
|
|
|
-
|
|
|
+ DB::table('inventory_account_missions')->insert($inventoryAccountMissions);
|
|
|
}
|
|
|
//盘点库存
|
|
|
- public function stockInventory($location,$barcode,$count,$inventoryId){
|
|
|
+ public function stockInventory($location,$barcode,$count,$inventoryAccountId){
|
|
|
|
|
|
- $inventoryMission=InventoryMission::whereHas('commodity',function($query)use($barcode){
|
|
|
+ $inventoryAccountMission=InventoryAccountMission::whereHas('commodity',function($query)use($barcode){
|
|
|
$query->whereHas('barcodes',function($sql)use($barcode){
|
|
|
$sql->where('code','=',$barcode);
|
|
|
});
|
|
|
- })->where('location',$location)->where('inventory_id',$inventoryId)->first();
|
|
|
- if (!$inventoryMission) return null;
|
|
|
- $inventory=Inventory::find($inventoryId);
|
|
|
+ })->where('location',$location)->where('inventory_account_id',$inventoryAccountId)->first();
|
|
|
+ if (!$inventoryAccountMission) return null;
|
|
|
+ $inventory=InventoryAccount::find($inventoryAccountId);
|
|
|
if ($inventory->surplus!=0){
|
|
|
- $inventoryMission->verified_amount=$count;
|
|
|
- $inventoryMission->difference_amount=abs($inventoryMission->stored_amount-$count);
|
|
|
- $inventoryMission->checked='是';
|
|
|
+ $inventoryAccountMission->verified_amount=$count;
|
|
|
+ $inventoryAccountMission->difference_amount=abs($inventoryAccountMission->stored_amount-$count);
|
|
|
+ $inventoryAccountMission->checked='是';
|
|
|
}else{
|
|
|
- $inventoryMission->re_checked_amount=$count;
|
|
|
- $inventoryMission->difference_amount=abs($inventoryMission->stored_amount-$count);
|
|
|
- if ($inventoryMission->difference_amount==0){
|
|
|
- $inventoryMission->returned='是';
|
|
|
+ $inventoryAccountMission->re_checked_amount=$count;
|
|
|
+ $inventoryAccountMission->difference_amount=abs($inventoryAccountMission->stored_amount-$count);
|
|
|
+ if ($inventoryAccountMission->difference_amount==0){
|
|
|
+ $inventoryAccountMission->returned='是';
|
|
|
}else{
|
|
|
- $inventoryMission->returned='否';
|
|
|
+ $inventoryAccountMission->returned='否';
|
|
|
}
|
|
|
}
|
|
|
- $inventoryMission->update();
|
|
|
+ $inventoryAccountMission->update();
|
|
|
$request=[
|
|
|
'location'=>$location,
|
|
|
'barcode'=>$barcode,
|
|
|
'count'=>$count,
|
|
|
- 'inventoryId'=>$inventoryId,
|
|
|
+ 'inventoryId'=>$inventoryAccountId,
|
|
|
];
|
|
|
Controller::logS(__METHOD__,"盘点__".__FUNCTION__,json_encode($request));
|
|
|
- return $inventoryMission;
|
|
|
+ return $inventoryAccountMission;
|
|
|
}
|
|
|
//盘点修改盘点任务数据
|
|
|
- public function updateInventory($inventoryId){
|
|
|
- $inventory=Inventory::find($inventoryId);
|
|
|
- $inventory->processed=$inventory->getProcessedAmount();
|
|
|
- $inventory->difference=$inventory->getDifferenceAmount();
|
|
|
- $inventory->returned=$inventory->getReturnedAmount();
|
|
|
- $inventory->update();
|
|
|
- Controller::logS(__METHOD__,"盘点修改盘点任务中的已盘条数__".__FUNCTION__,json_encode($inventoryId));
|
|
|
- return $inventory;
|
|
|
+ public function updateInventory($inventoryAccountId){
|
|
|
+ $inventoryAccount=InventoryAccount::find($inventoryAccountId);
|
|
|
+ $inventoryAccount->processed=$inventoryAccount->getProcessedAmount();
|
|
|
+ $inventoryAccount->difference=$inventoryAccount->getDifferenceAmount();
|
|
|
+ $inventoryAccount->returned=$inventoryAccount->getReturnedAmount();
|
|
|
+ $inventoryAccount->update();
|
|
|
+ Controller::logS(__METHOD__,"盘点修改盘点任务中的已盘条数__".__FUNCTION__,json_encode($inventoryAccountId));
|
|
|
+ return $inventoryAccount;
|
|
|
}
|
|
|
//根据该库存和产品条码查询该条盘点记录
|
|
|
- public function searchStockInventoryRecord($location,$barcode,$inventoryId){
|
|
|
- $inventoryMission=InventoryMission::whereHas('commodity',function($query)use($barcode){
|
|
|
+ public function searchStockInventoryRecord($location,$barcode,$inventoryAccountId){
|
|
|
+ $inventoryAccountMission=InventoryAccountMission::whereHas('commodity',function($query)use($barcode){
|
|
|
$query->whereHas('barcodes',function($sql)use($barcode){
|
|
|
$sql->where('code',$barcode);
|
|
|
});
|
|
|
- })->where('location',$location)->where('inventory_id',$inventoryId)->first();
|
|
|
- if (!$inventoryMission) return null;
|
|
|
- return $inventoryMission;
|
|
|
+ })->where('location',$location)->where('inventory_account_id',$inventoryAccountId)->first();
|
|
|
+ if (!$inventoryAccountMission) return null;
|
|
|
+ return $inventoryAccountMission;
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|