| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- <?php
- namespace App\Http\Controllers;
- use App\Exports\Export;
- use App\OracleBasCustomer;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\DB;
- use Maatwebsite\Excel\Facades\Excel;
- class InventoryController extends Controller
- {
- public function conditionQuery(Request $request,$page=null,$paginate=null){
- $date_start=$request->input('date_start');
- $date_end=$request->input('date_end');
- $TOLocation=$request->input('TOLocation');
- $LotAtt05=$request->input('LotAtt05');
- $LotAtt02_start=$request->input('LotAtt02_start');
- $descr_c=$request->input('descr_c');
- $SKU=$request->input('SKU');
- $ALTERNATE_SKU1=$request->input('ALTERNATE_SKU1');
- $LotAtt02_end=$request->input('LotAtt02_end');
- $sql='select * from (select result.*,rownum rn from (';
- $sql.=' select customer.Descr_C 货主, 库位, sku.SKU 产品编码, sku.ALTERNATE_SKU1 产品条码, ';
- $sql.=' sku.Descr_C 商品名称, lot.LotAtt05 属性仓, lot.LotAtt08 质量状态, lot.LotAtt02 失效日期, ';
- $sql.=' lot.LotAtt04 批号 ';
- $sql.=' , sum(移出数量)移出数量, sum(移入数量)移入数量 ';
- $sql.=' , storeStatus.QTY 在库数量, storeStatus.QtyAllocated 占用数量,count(1) over () as sum from ';
- $sql.=' (select FMLotNum,FMSKU,TOCustomerID,0 as 移出数量, sum(TOQty_Each) as 移入数量, TOLocation as 库位 ';
- $sql.=" from ACT_Transaction_Log where TransactionType='PA' ";
- if ($date_start) $sql.=" and addtime > '".$date_start." 00:00:00' ";
- if ($date_end) $sql.=" and addtime < '".$date_end." 23:59:59' ";
- if (!$date_start && !$date_end)$sql .= " and addtime >'".date('Y-m-d H:i:s',strtotime("-1 day"))."' ";
- if ($TOLocation)$sql .= " and TOLocation like '".$TOLocation."%' ";
- $sql.=' group by TOCustomerID, TOLocation, TOCustomerID,FMSKU,FMLotNum union all ';
- $sql.=' select FMLotNum,FMSKU,TOCustomerID,sum(FMQty_Each) as 移出数量, 0 as 移入数量, FMLOCATION as 库位 ';
- $sql.=" from ACT_Transaction_Log where TransactionType='SO' ";
- if ($date_start) $sql.=" and addtime > '".$date_start." 00:00:00' ";
- if ($date_end) $sql.=" and addtime < '".$date_end." 23:59:59' ";
- if (!$date_start && !$date_end)$sql .= " and addtime >'".date('Y-m-d H:i:s',strtotime("-1 day"))."' ";
- if ($TOLocation)$sql .= " and FMLOCATION like '".$TOLocation."%' ";
- $sql.=' group by FMCustomerID, FMLocation, TOCustomerID,FMSKU,FMLotNum union all ';
- $sql.=' select FMLotNum,FMSKU,TOCustomerID,sum(FMQty_Each) as 移出数量,0 as 移入数量, FMLocation as 库位 ';
- $sql.=" from ACT_Transaction_Log where TransactionType='MV' ";
- if ($date_start) $sql.=" and addtime > '".$date_start." 00:00:00' ";
- if ($date_end) $sql.=" and addtime < '".$date_end." 23:59:59' ";
- if (!$date_start && !$date_end)$sql .= " and addtime >'".date('Y-m-d H:i:s',strtotime("-1 day"))."' ";
- if ($TOLocation)$sql .= " and FMLocation like '".$TOLocation."%' ";
- $sql.=' group by FMLocation,TOCustomerID,FMSKU,FMLotNum union all ';
- $sql.=' select FMLotNum,FMSKU,TOCustomerID,0 as 移出数量,sum(TOQty_Each)as 移入数量, TOLocation as 库位 ';
- $sql.=" from ACT_Transaction_Log where TransactionType='MV' ";
- if ($date_start) $sql.=" and addtime > '".$date_start." 00:00:00' ";
- if ($date_end) $sql.=" and addtime < '".$date_end." 23:59:59' ";
- if (!$date_start && !$date_end)$sql .= " and addtime >'".date('Y-m-d H:i:s',strtotime("-1 day"))."' ";
- if ($TOLocation)$sql .= " and TOLocation like '".$TOLocation."%' ";
- $sql.=' group by TOLocation,TOCustomerID,FMSKU,FMLotNum)stockLog ';
- $sql.=' left join BAS_Customer customer on customer.CustomerID=stockLog.TOCUSTOMERID ';
- $sql.=' left join BAS_SKU sku on sku.SKU=stockLog.FMSKU ';
- $sql.=' left join INV_LOT_ATT lot on lot.LOTNUM=stockLog.FMLOTNUM ';
- $sql.=' left join INV_LOT_LOC_ID storeStatus on storeStatus.LOTNUM=stockLog.FMLOTNUM ';;
- $sql.=' and storeStatus.LocationID=stockLog.库位 where 1=1';
- if ($LotAtt05)$sql .=" and lot.LotAtt05 like '".$LotAtt05."%' ";
- if ($LotAtt02_start)$sql.=" and lot.LotAtt02 >='".$LotAtt02_start." 00:00:00' ";
- if ($LotAtt02_end)$sql.=" and lot.LotAtt02 <='".$LotAtt02_end." 23:59:59' ";
- if ($descr_c)$sql.=" and customer.descr_c ='".$descr_c."' ";
- if ($SKU)$sql.=" and sku.SKU like '".$SKU."%' ";
- if ($ALTERNATE_SKU1)$sql.=" and sku.ALTERNATE_SKU1 like '".$ALTERNATE_SKU1."%' ";
- if ($page&&$paginate)$sql.=' and ROWNUM<='.$page*$paginate;
- $sql.=' group by 库位,customer.Descr_C,sku.SKU,sku.ALTERNATE_SKU1 ';
- $sql.=' ,sku.Descr_C,FMLotNum,lot.LotAtt05,lot.LotAtt08,lot.LotAtt02,lot.LotAtt04 ';
- $sql.=' , storeStatus.QTY, storeStatus.QtyAllocated ';
- $sql.=' )result) ';
- if ($page&&$paginate)$sql.=' where rn>='.($page-1)*$paginate;
- return DB::connection('oracle')->select($sql);
- }
- public function changeInventory(Request $request){
- $page=$request->input('page')??1;
- $paginate=$request->input('paginate')??50;
- $oracleActTransactingLogs=$this->conditionQuery($request,$page,$paginate);
- $oracleActTransactingLogs=json_encode($oracleActTransactingLogs);
- $owners=OracleBasCustomer::select('descr_c')->get();
- return view('inventory.statement.changeInventory',compact('oracleActTransactingLogs','page','owners'));
- }
- public function exportData(Request $request){
- if ($request->input('export')==1){
- $oracleActTransactingLogs=json_decode($request->input('checkData'),true);
- return $this->export($oracleActTransactingLogs);
- }
- $oracleActTransactingLogs=$this->conditionQuery($request);
- $oracleActTransactingLogs=json_encode($oracleActTransactingLogs);
- $oracleActTransactingLogs=json_decode($oracleActTransactingLogs,true);
- return $this->export($oracleActTransactingLogs);
- }
- public function export($oracleActTransactingLogs){
- $row=[[
- 'customer_descr_c'=>'货主',
- 'TOLocation'=>'库位',
- 'LotAtt05'=>'属性仓',
- 'LotAtt02'=>'失效日期',
- 'SKU'=>'产品编码',
- 'ALTERNATE_SKU1'=>'产品条码',
- 'sku_Descr_C'=>'商品名称',
- 'LotAtt08'=>'质量状态',
- 'LotAtt04'=>'批号',
- 'come_sum'=>'移出数量',
- 'join_sum'=>'移入数量',
- 'QTY'=>'在库数量',
- 'QtyAllocated'=>'占用数量',
- ]];
- $list=[];
- for ($i=0; $i<count($oracleActTransactingLogs);$i++){
- $w=[
- 'customer_descr_c'=>$oracleActTransactingLogs[$i]['货主'],
- 'TOLocation'=>$oracleActTransactingLogs[$i]['库位'],
- 'LotAtt05'=>$oracleActTransactingLogs[$i]['属性仓'],
- 'LotAtt02'=>$oracleActTransactingLogs[$i]['失效日期'],
- 'SKU'=>$oracleActTransactingLogs[$i]['产品编码'],
- 'ALTERNATE_SKU1'=>$oracleActTransactingLogs[$i]['产品条码'],
- 'sku_Descr_C'=>$oracleActTransactingLogs[$i]['商品名称'],
- 'LotAtt08'=>$oracleActTransactingLogs[$i]['质量状态'],
- 'LotAtt04'=>$oracleActTransactingLogs[$i]['批号'],
- 'come_sum'=>$oracleActTransactingLogs[$i]['移出数量'],
- 'join_sum'=>$oracleActTransactingLogs[$i]['移入数量'],
- 'QTY'=>$oracleActTransactingLogs[$i]['在库数量'],
- 'QtyAllocated'=>$oracleActTransactingLogs[$i]['占用数量'],
- ];
- $list[$i]=$w;
- }
- return Excel::download(new Export($row,$list),date('YmdHis', time()).'-动库报表单.xlsx');
- }
- public function downLoadExcel(Request $request){
- $fileName=storage_path('app\files\\'.$request->input('fileName'));
- if (!file_exists($fileName))return "<h1 style='color: red;text-align:center'>请求过于频繁!</h1>";
- return response()->download($fileName);
- }
- public function deleteExcel(Request $request){
- $fileName=storage_path('app\files\\'.$request->input('fileName'));
- return ["success"=>unlink($fileName)];
- }
- }
|