InventoryController.php 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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 as 货主,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. if ($SKU)$sql.=" and FMSKU like '".$SKU."%' ";
  36. $sql.=' group by TOCustomerID, TOLocation,FMSKU,FMLotNum union all ';
  37. $sql.=' select FMLotNum,FMSKU,FMCUSTOMERID 客户,sum(FMQty_Each) as 移出数量, 0 as 移入数量, FMLOCATION as 库位 ';
  38. $sql.=" from ACT_Transaction_Log where TransactionType='SO' ";
  39. if ($date_start) $sql.=" and addtime > to_date('".$date_start." 00:00:00','yyyy-mm-dd hh24:mi:ss') ";
  40. if ($date_end) $sql.=" and addtime < to_date('".$date_end." 23:59:59','yyyy-mm-dd hh24:mi:ss') ";
  41. 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') ";
  42. if ($TOLocation)$sql .= " and FMLOCATION like '".$TOLocation."%' ";
  43. if ($SKU)$sql.=" and FMSKU like '".$SKU."%' ";
  44. $sql.=' group by FMCustomerID, FMLocation,FMSKU,FMLotNum union all ';
  45. $sql.=' select FMLotNum,FMSKU,FMCUSTOMERID 客户,sum(FMQty_Each) as 移出数量,0 as 移入数量, FMLocation as 库位 ';
  46. $sql.=" from ACT_Transaction_Log where TransactionType='MV' ";
  47. if ($date_start) $sql.=" and addtime > to_date('".$date_start." 00:00:00','yyyy-mm-dd hh24:mi:ss') ";
  48. if ($date_end) $sql.=" and addtime < to_date('".$date_end." 23:59:59','yyyy-mm-dd hh24:mi:ss') ";
  49. 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') ";
  50. if ($TOLocation)$sql .= " and FMLocation like '".$TOLocation."%' ";
  51. if ($SKU)$sql.=" and FMSKU like '".$SKU."%' ";
  52. $sql.=' group by FMLocation,FMCUSTOMERID,FMSKU,FMLotNum union all ';
  53. $sql.=' select FMLotNum,FMSKU,TOCustomerID 客户,0 as 移出数量,sum(TOQty_Each)as 移入数量, TOLocation as 库位 ';
  54. $sql.=" from ACT_Transaction_Log where TransactionType='MV' ";
  55. if ($date_start) $sql.=" and addtime > to_date('".$date_start." 00:00:00','yyyy-mm-dd hh24:mi:ss') ";
  56. if ($date_end) $sql.=" and addtime < to_date('".$date_end." 23:59:59','yyyy-mm-dd hh24:mi:ss') ";
  57. 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') ";
  58. if ($TOLocation)$sql .= " and TOLocation like '".$TOLocation."%' ";
  59. if ($SKU)$sql.=" and FMSKU like '".$SKU."%' ";
  60. $sql.=' group by TOLocation,TOCustomerID,FMSKU,FMLotNum)stockLog ';
  61. $sql.=' left join BAS_Customer customer on customer.CustomerID=stockLog.客户 ';
  62. $sql.=' left join BAS_SKU sku on sku.SKU=stockLog.FMSKU and sku.CUSTOMERID=stockLog.客户 ';
  63. $sql.=' left join INV_LOT_ATT lot on lot.LOTNUM=stockLog.FMLOTNUM ';
  64. $sql.=' left join INV_LOT_LOC_ID storeStatus on storeStatus.LOTNUM=stockLog.FMLOTNUM ';;
  65. $sql.=' and storeStatus.LocationID=stockLog.库位 ';
  66. $sql.=' group by 库位,customer.Descr_C,sku.SKU,sku.ALTERNATE_SKU1 ';
  67. $sql.=' ,sku.Descr_C,FMLotNum,lot.LotAtt05,lot.LotAtt08,lot.LotAtt02,lot.LotAtt04 ';
  68. $sql.=' , storeStatus.QTY, storeStatus.QtyAllocated,stockLog.客户 ';
  69. $sql.=' )result where 1=1 ';
  70. if ($LotAtt05)$sql .=" and 属性仓 like '".$LotAtt05."%' ";
  71. if ($LotAtt02_start)$sql.=" and 失效日期 >='".$LotAtt02_start." 00:00:00' ";
  72. if ($LotAtt02_end)$sql.=" and 失效日期 <='".$LotAtt02_end." 23:59:59' ";
  73. if ($descr_c)$sql.=" and 货主 ='".$descr_c."' ";
  74. if ($ALTERNATE_SKU1)$sql.=" and 产品条码 like '".$ALTERNATE_SKU1."%' ";
  75. if ($page&&$paginate)$sql.=" and ROWNUM<='".$page*$paginate."'";
  76. $sql.=' ) ';
  77. if ($page&&$paginate)$sql.=" where rn>'".($page-1)*$paginate."'";
  78. return DB::connection('oracle')->select($sql);
  79. }
  80. public function changeInventory(Request $request){
  81. $page=$request->input('page')??1;
  82. $paginate=$request->input('paginate')??50;
  83. $oracleActTransactingLogs=$this->conditionQuery($request,$page,$paginate);
  84. $oracleActTransactingLogs=json_encode($oracleActTransactingLogs);
  85. $owners=OracleBasCustomer::select('descr_c')->where('customer_type','OW')->where('active_flag','Y')->get();
  86. return view('inventory.statement.changeInventory',compact('oracleActTransactingLogs','page','owners'));
  87. }
  88. public function exportData(Request $request){
  89. if ($request->input('export')==1){
  90. $oracleActTransactingLogs=json_decode($request->input('checkData'),true);
  91. return $this->export($oracleActTransactingLogs);
  92. }
  93. $oracleActTransactingLogs=$this->conditionQuery($request);
  94. $oracleActTransactingLogs=json_encode($oracleActTransactingLogs);
  95. $oracleActTransactingLogs=json_decode($oracleActTransactingLogs,true);
  96. return $this->export($oracleActTransactingLogs);
  97. }
  98. public function export($oracleActTransactingLogs){
  99. $row=[[
  100. 'customer_descr_c'=>'货主',
  101. 'TOLocation'=>'库位',
  102. 'LotAtt05'=>'属性仓',
  103. 'LotAtt02'=>'失效日期',
  104. 'SKU'=>'产品编码',
  105. 'ALTERNATE_SKU1'=>'产品条码',
  106. 'sku_Descr_C'=>'商品名称',
  107. 'LotAtt08'=>'质量状态',
  108. 'LotAtt04'=>'批号',
  109. 'come_sum'=>'移出数量',
  110. 'join_sum'=>'移入数量',
  111. 'QTY'=>'在库数量',
  112. 'QtyAllocated'=>'占用数量',
  113. ]];
  114. $list=[];
  115. for ($i=0; $i<count($oracleActTransactingLogs);$i++){
  116. $w=[
  117. 'customer_descr_c'=>$oracleActTransactingLogs[$i]['货主'],
  118. 'TOLocation'=>$oracleActTransactingLogs[$i]['库位'],
  119. 'LotAtt05'=>$oracleActTransactingLogs[$i]['属性仓'],
  120. 'LotAtt02'=>$oracleActTransactingLogs[$i]['失效日期'],
  121. 'SKU'=>$oracleActTransactingLogs[$i]['产品编码'],
  122. 'ALTERNATE_SKU1'=>$oracleActTransactingLogs[$i]['产品条码'],
  123. 'sku_Descr_C'=>$oracleActTransactingLogs[$i]['商品名称'],
  124. 'LotAtt08'=>$oracleActTransactingLogs[$i]['质量状态'],
  125. 'LotAtt04'=>$oracleActTransactingLogs[$i]['批号'],
  126. 'come_sum'=>$oracleActTransactingLogs[$i]['移出数量'],
  127. 'join_sum'=>$oracleActTransactingLogs[$i]['移入数量'],
  128. 'QTY'=>$oracleActTransactingLogs[$i]['在库数量'],
  129. 'QtyAllocated'=>$oracleActTransactingLogs[$i]['占用数量'],
  130. ];
  131. $list[$i]=$w;
  132. }
  133. return Excel::download(new Export($row,$list),date('YmdHis', time()).'-动库报表单.xlsx');
  134. }
  135. }