InventoryController.php 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Exports\Export;
  4. use App\OracleBasCustomer;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Support\Facades\DB;
  7. use Illuminate\Support\Facades\Gate;
  8. use Maatwebsite\Excel\Facades\Excel;
  9. class InventoryController extends Controller
  10. {
  11. public function conditionQuery(Request $request,$page=null,$paginate=null){
  12. if(!Gate::allows("库存管理-动库报表")){ return redirect(url('/')); }
  13. $date_start=$request->input('date_start');
  14. if ($request->input('range'))$date_start=date('Y-m-d',strtotime('-'.$request->input('range')." day"));
  15. $date_end=$request->input('date_end');
  16. $TOLocation=$request->input('TOLocation');
  17. $LotAtt05=$request->input('LotAtt05');
  18. $LotAtt02_start=$request->input('LotAtt02_start');
  19. $descr_c=$request->input('descr_c');
  20. $SKU=$request->input('SKU');
  21. $ALTERNATE_SKU1=$request->input('ALTERNATE_SKU1');
  22. $LotAtt02_end=$request->input('LotAtt02_end');
  23. $sql='select * from (select result.*,rownum rn from (';
  24. $sql.=' select customer.Descr_C 货主,stockLog.客户, 库位, sku.SKU 产品编码, sku.ALTERNATE_SKU1 产品条码, ';
  25. $sql.=' sku.Descr_C 商品名称, lot.LotAtt05 属性仓, lot.LotAtt08 质量状态, lot.LotAtt02 失效日期, ';
  26. $sql.=' lot.LotAtt04 批号 ';
  27. $sql.=' , sum(移出数量)移出数量, sum(移入数量)移入数量 ';
  28. $sql.=' , storeStatus.QTY 在库数量, storeStatus.QtyAllocated 占用数量,count(1) over () as sum from ';
  29. $sql.=' (select FMLotNum,FMSKU,TOCustomerID 客户,0 as 移出数量, sum(TOQty_Each) as 移入数量, TOLocation as 库位 ';
  30. $sql.=" from ACT_Transaction_Log where TransactionType='PA' ";
  31. if ($date_start) $sql.=" and addtime > to_date('".$date_start." 00:00:00','yyyy-mm-dd hh24:mi:ss') ";
  32. if ($date_end) $sql.=" and addtime < to_date('".$date_end." 23:59:59','yyyy-mm-dd hh24:mi:ss') ";
  33. if (!$date_start && !$date_end)$sql .= " and addtime >to_date('".date('Y-m-d H:i:s',strtotime("-1 day"))."','yyyy-mm-dd hh24:mi:ss') ";
  34. if ($TOLocation)$sql .= " and TOLocation like '".$TOLocation."%' ";
  35. $sql.=' group by TOCustomerID, TOLocation,FMSKU,FMLotNum union all ';
  36. $sql.=' select /*+INDEX(ACT_Transaction_Log I_ACT_TRANSACTION_LOG_TS)*/ FMLotNum,FMSKU,FMCUSTOMERID 客户,sum(FMQty_Each) as 移出数量, 0 as 移入数量, FMLOCATION as 库位 ';
  37. $sql.=" from ACT_Transaction_Log where TransactionType='SO' ";
  38. if ($date_start) $sql.=" and addtime > to_date('".$date_start." 00:00:00','yyyy-mm-dd hh24:mi:ss') ";
  39. if ($date_end) $sql.=" and addtime < to_date('".$date_end." 23:59:59','yyyy-mm-dd hh24:mi:ss') ";
  40. if (!$date_start && !$date_end)$sql .= " and addtime >to_date('".date('Y-m-d H:i:s',strtotime("-1 day"))."','yyyy-mm-dd hh24:mi:ss') ";
  41. if ($TOLocation)$sql .= " and FMLOCATION like '".$TOLocation."%' ";
  42. $sql.=' group by FMCustomerID, FMLocation,FMSKU,FMLotNum union all ';
  43. $sql.=' select FMLotNum,FMSKU,FMCUSTOMERID 客户,sum(FMQty_Each) as 移出数量,0 as 移入数量, FMLocation as 库位 ';
  44. $sql.=" from ACT_Transaction_Log where TransactionType='MV' ";
  45. if ($date_start) $sql.=" and addtime > to_date('".$date_start." 00:00:00','yyyy-mm-dd hh24:mi:ss') ";
  46. if ($date_end) $sql.=" and addtime < to_date('".$date_end." 23:59:59','yyyy-mm-dd hh24:mi:ss') ";
  47. if (!$date_start && !$date_end)$sql .= " and addtime >to_date('".date('Y-m-d H:i:s',strtotime("-1 day"))."','yyyy-mm-dd hh24:mi:ss') ";
  48. if ($TOLocation)$sql .= " and FMLocation like '".$TOLocation."%' ";
  49. $sql.=' group by FMLocation,FMCUSTOMERID,FMSKU,FMLotNum union all ';
  50. $sql.=' select FMLotNum,FMSKU,TOCustomerID 客户,0 as 移出数量,sum(TOQty_Each)as 移入数量, TOLocation as 库位 ';
  51. $sql.=" from ACT_Transaction_Log where TransactionType='MV' ";
  52. if ($date_start) $sql.=" and addtime > to_date('".$date_start." 00:00:00','yyyy-mm-dd hh24:mi:ss') ";
  53. if ($date_end) $sql.=" and addtime < to_date('".$date_end." 23:59:59','yyyy-mm-dd hh24:mi:ss') ";
  54. if (!$date_start && !$date_end)$sql .= " and addtime >to_date('".date('Y-m-d H:i:s',strtotime("-1 day"))."','yyyy-mm-dd hh24:mi:ss') ";
  55. if ($TOLocation)$sql .= " and TOLocation like '".$TOLocation."%' ";
  56. $sql.=' group by TOLocation,TOCustomerID,FMSKU,FMLotNum)stockLog ';
  57. $sql.=' left join BAS_Customer customer on customer.CustomerID=stockLog.客户 ';
  58. $sql.=' left join BAS_SKU sku on sku.SKU=stockLog.FMSKU and sku.CUSTOMERID=stockLog.客户 ';
  59. $sql.=' left join INV_LOT_ATT lot on lot.LOTNUM=stockLog.FMLOTNUM ';
  60. $sql.=' left join INV_LOT_LOC_ID storeStatus on storeStatus.LOTNUM=stockLog.FMLOTNUM ';;
  61. $sql.=' and storeStatus.LocationID=stockLog.库位 where 1=1';
  62. if ($LotAtt05)$sql .=" and lot.LotAtt05 like '".$LotAtt05."%' ";
  63. if ($LotAtt02_start)$sql.=" and lot.LotAtt02 >='".$LotAtt02_start." 00:00:00' ";
  64. if ($LotAtt02_end)$sql.=" and lot.LotAtt02 <='".$LotAtt02_end." 23:59:59' ";
  65. if ($descr_c)$sql.=" and customer.descr_c ='".$descr_c."' ";
  66. if ($SKU)$sql.=" and sku.SKU like '".$SKU."%' ";
  67. if ($ALTERNATE_SKU1)$sql.=" and sku.ALTERNATE_SKU1 like '".$ALTERNATE_SKU1."%' ";
  68. if ($page&&$paginate)$sql.=" and ROWNUM<='".$page*$paginate."'";
  69. $sql.=' group by 库位,customer.Descr_C,sku.SKU,sku.ALTERNATE_SKU1 ';
  70. $sql.=' ,sku.Descr_C,FMLotNum,lot.LotAtt05,lot.LotAtt08,lot.LotAtt02,lot.LotAtt04 ';
  71. $sql.=' , storeStatus.QTY, storeStatus.QtyAllocated,stockLog.客户 ';
  72. $sql.=' )result) ';
  73. if ($page&&$paginate)$sql.=" where rn>'".($page-1)*$paginate."'";dd($sql);
  74. return DB::connection('oracle')->select($sql);
  75. }
  76. public function changeInventory(Request $request){
  77. $page=$request->input('page')??1;
  78. $paginate=$request->input('paginate')??50;
  79. $oracleActTransactingLogs=$this->conditionQuery($request,$page,$paginate);
  80. $oracleActTransactingLogs=json_encode($oracleActTransactingLogs);
  81. $owners=OracleBasCustomer::select('descr_c')->where('customer_type','OW')->where('active_flag','Y')->get();
  82. return view('inventory.statement.changeInventory',compact('oracleActTransactingLogs','page','owners'));
  83. }
  84. public function exportData(Request $request){
  85. if ($request->input('export')==1){
  86. $oracleActTransactingLogs=json_decode($request->input('checkData'),true);
  87. return $this->export($oracleActTransactingLogs);
  88. }
  89. $oracleActTransactingLogs=$this->conditionQuery($request);
  90. $oracleActTransactingLogs=json_encode($oracleActTransactingLogs);
  91. $oracleActTransactingLogs=json_decode($oracleActTransactingLogs,true);
  92. return $this->export($oracleActTransactingLogs);
  93. }
  94. public function export($oracleActTransactingLogs){
  95. $row=[[
  96. 'customer_descr_c'=>'货主',
  97. 'TOLocation'=>'库位',
  98. 'LotAtt05'=>'属性仓',
  99. 'LotAtt02'=>'失效日期',
  100. 'SKU'=>'产品编码',
  101. 'ALTERNATE_SKU1'=>'产品条码',
  102. 'sku_Descr_C'=>'商品名称',
  103. 'LotAtt08'=>'质量状态',
  104. 'LotAtt04'=>'批号',
  105. 'come_sum'=>'移出数量',
  106. 'join_sum'=>'移入数量',
  107. 'QTY'=>'在库数量',
  108. 'QtyAllocated'=>'占用数量',
  109. ]];
  110. $list=[];
  111. for ($i=0; $i<count($oracleActTransactingLogs);$i++){
  112. $w=[
  113. 'customer_descr_c'=>$oracleActTransactingLogs[$i]['货主'],
  114. 'TOLocation'=>$oracleActTransactingLogs[$i]['库位'],
  115. 'LotAtt05'=>$oracleActTransactingLogs[$i]['属性仓'],
  116. 'LotAtt02'=>$oracleActTransactingLogs[$i]['失效日期'],
  117. 'SKU'=>$oracleActTransactingLogs[$i]['产品编码'],
  118. 'ALTERNATE_SKU1'=>$oracleActTransactingLogs[$i]['产品条码'],
  119. 'sku_Descr_C'=>$oracleActTransactingLogs[$i]['商品名称'],
  120. 'LotAtt08'=>$oracleActTransactingLogs[$i]['质量状态'],
  121. 'LotAtt04'=>$oracleActTransactingLogs[$i]['批号'],
  122. 'come_sum'=>$oracleActTransactingLogs[$i]['移出数量'],
  123. 'join_sum'=>$oracleActTransactingLogs[$i]['移入数量'],
  124. 'QTY'=>$oracleActTransactingLogs[$i]['在库数量'],
  125. 'QtyAllocated'=>$oracleActTransactingLogs[$i]['占用数量'],
  126. ];
  127. $list[$i]=$w;
  128. }
  129. return Excel::download(new Export($row,$list),date('YmdHis', time()).'-动库报表单.xlsx');
  130. }
  131. }