InventoryController.php 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Http\Controllers;
  3. use Illuminate\Http\Request;
  4. use Illuminate\Support\Facades\DB;
  5. class InventoryController extends Controller
  6. {
  7. public function changeInventory(Request $request){
  8. $date_start=$request->input('date_start');
  9. $date_end=$request->input('date_end');
  10. $start=microtime(true);
  11. //$sql=' select * from (select ROWNUM r,result.* from ( ';
  12. $sql=' select customer.Descr_C 货主, 库位, sku.SKU 产品编码, sku.ALTERNATE_SKU1 产品条码, ';
  13. $sql.=' sku.Descr_C 商品名称, lot.LotAtt05 属性仓, lot.LotAtt08 质量状态, lot.LotAtt02 失效日期, ';
  14. $sql.=' lot.LotAtt04 批号 ';
  15. $sql.=' , sum(移出数量)移出数量, sum(移入数量)移入数量 ';
  16. $sql.=' , storeStatus.QTY 在库数量, storeStatus.QtyAllocated 占用数量,count(1) over () as sum from ';
  17. $sql.=' (select FMLotNum,FMSKU,TOCustomerID,0 as 移出数量, sum(TOQty_Each) as 移入数量, TOLocation as 库位 ';
  18. $sql.=" from ACT_Transaction_Log where TransactionType='PA' ";
  19. if ($date_start) $sql.=" and addtime > '".$date_start." 00:00:00' ";
  20. if ($date_end) $sql.=" and addtime < '".$date_end." 23:59:59' ";
  21. $sql.=' group by TOCustomerID, TOLocation, TOCustomerID,FMSKU,FMLotNum union all ';
  22. $sql.=' select FMLotNum,FMSKU,TOCustomerID,sum(FMQty_Each) as 移出数量, 0 as 移入数量, FMLOCATION as 库位 ';
  23. $sql.=" from ACT_Transaction_Log where TransactionType='SO' ";
  24. if ($date_start) $sql.=" and addtime > '".$date_start." 00:00:00' ";
  25. if ($date_end) $sql.=" and addtime < '".$date_end." 23:59:59' ";
  26. $sql.=' group by FMCustomerID, FMLocation, TOCustomerID,FMSKU,FMLotNum union all ';
  27. $sql.=' select FMLotNum,FMSKU,TOCustomerID,sum(FMQty_Each) as 移出数量,0 as 移入数量, FMLocation as 库位 ';
  28. $sql.=" from ACT_Transaction_Log where TransactionType='MV' ";
  29. if ($date_start) $sql.=" and addtime > '".$date_start." 00:00:00' ";
  30. if ($date_end) $sql.=" and addtime < '".$date_end." 23:59:59' ";
  31. $sql.=' group by FMLocation,TOCustomerID,FMSKU,FMLotNum union all ';
  32. $sql.=' select FMLotNum,FMSKU,TOCustomerID,0 as 移出数量,sum(TOQty_Each)as 移入数量, TOLocation as 库位 ';
  33. $sql.=" from ACT_Transaction_Log where TransactionType='MV' ";
  34. if ($date_start) $sql.=" and addtime > '".$date_start." 00:00:00' ";
  35. if ($date_end) $sql.=" and addtime < '".$date_end." 23:59:59' ";
  36. $sql.=' group by TOLocation,TOCustomerID,FMSKU,FMLotNum)stockLog ';
  37. $sql.=' left join BAS_Customer customer on customer.CustomerID=stockLog.TOCUSTOMERID ';
  38. $sql.=' left join BAS_SKU sku on sku.SKU=stockLog.FMSKU ';
  39. $sql.=' left join INV_LOT_ATT lot on lot.LOTNUM=stockLog.FMLOTNUM ';
  40. $sql.=' left join INV_LOT_LOC_ID storeStatus on storeStatus.LOTNUM=stockLog.FMLOTNUM ';
  41. $sql.=' left join INV_LOT_LOC_ID storeStatus on storeStatus.LOTNUM=stockLog.FMLOTNUM ';
  42. $sql.=' and storeStatus.LocationID=stockLog.库位 where rownum<=300 ';
  43. $sql.=' group by 库位,customer.Descr_C,sku.SKU,sku.ALTERNATE_SKU1 ';
  44. $sql.=' ,sku.Descr_C,FMLotNum,lot.LotAtt05,lot.LotAtt08,lot.LotAtt02,lot.LotAtt04 ';
  45. $sql.=' , storeStatus.QTY, storeStatus.QtyAllocated ';
  46. //$sql.=' ) result)data ';
  47. $page=$request->input('page')??1;
  48. /*$sql.=" where data.r>".($page-1)*50;
  49. $sql.=" and data.r<=".$page*50;*/
  50. $oracleActTransactingLogs=DB::connection('oracle')->select($sql);
  51. $oracleActTransactingLogs=json_encode($oracleActTransactingLogs);
  52. $end=microtime(true);
  53. $date=$end-$start;
  54. return view('inventory.statement.changeInventory',compact('oracleActTransactingLogs','page','date'));
  55. }
  56. }