|
@@ -179,7 +179,8 @@ class ProductInventoryService extends Service
|
|
|
|
|
|
//现存量
|
|
//现存量
|
|
public function productInventoryList($data,$user){
|
|
public function productInventoryList($data,$user){
|
|
- $model = ProductInventory::from('product_inventory as a')
|
|
|
|
|
|
+ $model = new ProductInventory(['userData' => $user, 'search' => $data]);
|
|
|
|
+ $model = $model->from('product_inventory as a')
|
|
->join('product as b','b.id','a.product_id')
|
|
->join('product as b','b.id','a.product_id')
|
|
->select('a.product_id','a.id','a.number','b.title','b.code','b.product_category_id','b.unit','b.bar_code','a.crt_time','a.storehouse_id')
|
|
->select('a.product_id','a.id','a.number','b.title','b.code','b.product_category_id','b.unit','b.bar_code','a.crt_time','a.storehouse_id')
|
|
->orderby('a.crt_time', 'desc');
|
|
->orderby('a.crt_time', 'desc');
|
|
@@ -237,16 +238,19 @@ class ProductInventoryService extends Service
|
|
|
|
|
|
//库存台账
|
|
//库存台账
|
|
public function productInventoryStockList($data,$user){
|
|
public function productInventoryStockList($data,$user){
|
|
- $model = InOutRecord::from('in_out_record as a')
|
|
|
|
|
|
+ if(empty($data['crt_time'][0]) || empty($data['crt_time'][1])) return [false,'时间必须选择'];
|
|
|
|
+
|
|
|
|
+ $model = new InOutRecord(['userData' => $user, 'search' => $data]);
|
|
|
|
+ $model = $model->from('in_out_record as a')
|
|
->where('a.del_time',0)
|
|
->where('a.del_time',0)
|
|
->join('product as b','b.id','a.product_id')
|
|
->join('product as b','b.id','a.product_id')
|
|
- ->select('a.id','a.product_id','a.number','a.order_type','a.crt_time','b.title','b.code','b.product_category_id','b.unit',DB::raw('SUM(CASE WHEN number < 0 THEN number ELSE 0 END) as out_number'),DB::raw('SUM(CASE WHEN number >= 0 THEN number ELSE 0 END) as in_number'),'a.order_number','a.crt_time','a.storehouse_id')
|
|
|
|
- ->groupby('a.product_id','a.order_number')
|
|
|
|
|
|
+ ->select('a.id','a.product_id','a.number','a.order_type','a.crt_time','b.title','b.code','b.product_category_id','b.unit',DB::raw('SUM(CASE WHEN a.number < 0 THEN a.number ELSE 0 END) as out_number'),DB::raw('SUM(CASE WHEN a.number >= 0 THEN a.number ELSE 0 END) as in_number'),'a.order_number','a.crt_time','a.storehouse_id','a.top_depart_id')
|
|
|
|
+ ->groupby('a.product_id','a.top_depart_id','a.order_number')
|
|
->orderBy('a.crt_time','asc');
|
|
->orderBy('a.crt_time','asc');
|
|
|
|
|
|
- if(empty($data['crt_time'][0]) || empty($data['crt_time'][1])) return [false,'时间必须选择'];
|
|
|
|
$return = $this->changeDateToTimeStampAboutRange($data['crt_time']);
|
|
$return = $this->changeDateToTimeStampAboutRange($data['crt_time']);
|
|
$model->whereBetween('a.crt_time',[$return[0],$return[1]]);
|
|
$model->whereBetween('a.crt_time',[$return[0],$return[1]]);
|
|
|
|
+
|
|
if(! empty($data['product_name'])){
|
|
if(! empty($data['product_name'])){
|
|
$product_name = $data['product_name'];
|
|
$product_name = $data['product_name'];
|
|
$id = Product::where('del_time',0)
|
|
$id = Product::where('del_time',0)
|
|
@@ -277,15 +281,16 @@ class ProductInventoryService extends Service
|
|
public function fillData($data,$time_arr){
|
|
public function fillData($data,$time_arr){
|
|
if (empty($data)) return $data;
|
|
if (empty($data)) return $data;
|
|
|
|
|
|
- $start_data = InOutRecord::whereIn('product_id',array_column($data,'product_id'))
|
|
|
|
|
|
+ $start_data = InOutRecord::withoutGlobalScopes()
|
|
|
|
+ ->whereIn('product_id',array_unique(array_column($data,'product_id')))
|
|
->where('crt_time','<',$time_arr[0])
|
|
->where('crt_time','<',$time_arr[0])
|
|
->where('del_time',0)
|
|
->where('del_time',0)
|
|
- ->select('product_id','number',DB::raw('sum(number) as number'))
|
|
|
|
- ->groupby('product_id')
|
|
|
|
|
|
+ ->select('product_id','number',DB::raw('sum(number) as number'),'top_depart_id')
|
|
|
|
+ ->groupby('product_id','top_depart_id')
|
|
->get()->toArray();
|
|
->get()->toArray();
|
|
$start_map = [];
|
|
$start_map = [];
|
|
foreach ($start_data as $value){
|
|
foreach ($start_data as $value){
|
|
- $start_map[$value['product_id']] = $value['number'];
|
|
|
|
|
|
+ $start_map[$value['product_id'].$value['top_depart_id']] = $value['number'];
|
|
}
|
|
}
|
|
|
|
|
|
$category = ProductCategory::whereIn('id',array_unique(array_column($data,'product_category_id')))
|
|
$category = ProductCategory::whereIn('id',array_unique(array_column($data,'product_category_id')))
|
|
@@ -298,11 +303,11 @@ class ProductInventoryService extends Service
|
|
|
|
|
|
$roll_tmp = [];
|
|
$roll_tmp = [];
|
|
$order_type = $this->getOrderType();
|
|
$order_type = $this->getOrderType();
|
|
- $storehouse = Storehouse::whereIn('id',array_unique(array_column($data['data'],'storehouse_id')))
|
|
|
|
|
|
+ $storehouse = Storehouse::whereIn('id',array_unique(array_column($data,'storehouse_id')))
|
|
->pluck('title','id')
|
|
->pluck('title','id')
|
|
->toArray();
|
|
->toArray();
|
|
foreach ($data as $key => $value){
|
|
foreach ($data as $key => $value){
|
|
- $keys = $value['product_id'];
|
|
|
|
|
|
+ $keys = $value['product_id'] . $value['top_depart_id'];
|
|
if(! isset($roll_tmp[$keys])){
|
|
if(! isset($roll_tmp[$keys])){
|
|
if(isset($start_map[$keys])){
|
|
if(isset($start_map[$keys])){
|
|
$data[$key]['start_number'] = $start_map[$keys];
|
|
$data[$key]['start_number'] = $start_map[$keys];
|
|
@@ -324,7 +329,7 @@ class ProductInventoryService extends Service
|
|
$data[$key]['order_name'] = $order_type[$value['order_type']] ?? '';
|
|
$data[$key]['order_name'] = $order_type[$value['order_type']] ?? '';
|
|
$data[$key]['crt_time'] = $value['crt_time'] ? date("Y-m-d",$value['crt_time']):'';
|
|
$data[$key]['crt_time'] = $value['crt_time'] ? date("Y-m-d",$value['crt_time']):'';
|
|
$data[$key]['unit_title'] = $basic_map[$value['unit']] ?? '';
|
|
$data[$key]['unit_title'] = $basic_map[$value['unit']] ?? '';
|
|
- $data['data'][$key]['storehouse_title'] = $storehouse[$value['storehouse_id']] ?? '';
|
|
|
|
|
|
+ $data[$key]['storehouse_title'] = $storehouse[$value['storehouse_id']] ?? '';
|
|
}
|
|
}
|
|
|
|
|
|
return $data;
|
|
return $data;
|
|
@@ -364,30 +369,6 @@ class ProductInventoryService extends Service
|
|
return [true, $list];
|
|
return [true, $list];
|
|
}
|
|
}
|
|
|
|
|
|
- //系统设置列表
|
|
|
|
- public function productInventorySetList1($data, $user){
|
|
|
|
- $model = new ProductInventorySet();
|
|
|
|
- $model = $model->where('del_time',0)
|
|
|
|
- ->select('id','top_depart_id','param_one','param_two');
|
|
|
|
-
|
|
|
|
- if(empty($data['top_depart_id'])){
|
|
|
|
- //默认进来 只显示自己公司下的 自己权限范围下的部门数据
|
|
|
|
- $top_depart_id = $user['depart_top'][0] ?? [];
|
|
|
|
- $top_depart_id = $top_depart_id['depart_id'] ?? 0;
|
|
|
|
- }else{
|
|
|
|
- $top_depart_id = $data['top_depart_id'];
|
|
|
|
- }
|
|
|
|
- $model->where('top_depart_id', $top_depart_id);
|
|
|
|
- $list = $model->get()->toArray();
|
|
|
|
-
|
|
|
|
- $map = Depart::whereIn('id',array_column($list,'top_depart_id'))->pluck('title','id')->toArray();
|
|
|
|
- foreach ($list as $key => $value){
|
|
|
|
- $list[$key]['top_depart_title'] = $map[$value['top_depart_id']] ?? "";
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return [true, $list];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
//库存设置
|
|
//库存设置
|
|
public function productInventorySet($data, $user){
|
|
public function productInventorySet($data, $user){
|
|
if(empty($data['id'])) return [false, 'ID不能为空'];
|
|
if(empty($data['id'])) return [false, 'ID不能为空'];
|