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