AllInventoryService.php 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. namespace App\Services;
  3. use App\Owner;
  4. use Illuminate\Support\Facades\DB;
  5. Class AllInventoryService
  6. {
  7. public function getSql(array $params, $page=null, $paginate=null){
  8. $ownerCodes=Owner::filterAuthorities()->select('code')->get();
  9. $date_start=$params['date_start'] ?? null;
  10. $range = $params['range'] ?? null;
  11. if ($range)$date_start=date('Y-m-d',strtotime('-'.$range." day"));
  12. $date_end=$params['date_end'] ?? null;
  13. $TOLocation=$params['TOLocation'] ?? null;
  14. $LotAtt05=$params['LotAtt05'] ?? null;
  15. $LotAtt02_start=$params['LotAtt02_start'] ?? null;
  16. $customerid=$params['customerid'] ?? null;
  17. $SKU=$params['SKU'] ?? null;
  18. $ALTERNATE_SKU1=$params['ALTERNATE_SKU1'] ?? null;
  19. $LotAtt02_end=$params['LotAtt02_end'] ?? null;
  20. $sql='select * from (select result.*,rownum rn from (';
  21. $sql.=' select customer.descr_c as 货主,storeStatus.CUSTOMERID 客户,storeStatus.LocationID 库位, sku.SKU 产品编码, sku.ALTERNATE_SKU1 产品条码, ';
  22. $sql.=' sku.Descr_C 商品名称, lot.LotAtt05 属性仓, lot.LotAtt08 质量状态, lot.LotAtt02 失效日期, storeStatus.ADDTIME 创建时间, ';
  23. $sql.=' lot.LotAtt04 批号 ';
  24. $sql.=' , storeStatus.QTY 在库数量, storeStatus.QtyAllocated 占用数量,count(1) over () as sum from ';
  25. $sql.=' INV_LOT_LOC_ID storeStatus';
  26. $sql.=' left join BAS_Customer customer on customer.CustomerID=storeStatus.CUSTOMERID ';
  27. $sql.=' left join BAS_SKU sku on sku.SKU=storeStatus.SKU and sku.CUSTOMERID=storeStatus.CUSTOMERID ';
  28. $sql.=' left join INV_LOT_ATT lot on lot.LOTNUM = storeStatus.LOTNUM AND lot.CUSTOMERID = storeStatus.CUSTOMERID ';
  29. if ($customerid){
  30. $sql .= ' where storeStatus.CUSTOMERID in (';
  31. $arr = explode(',',$customerid);
  32. foreach ($arr as $index => $data){
  33. if ($index != 0)$sql .= ',';
  34. $sql .= "'".$data."'";
  35. }
  36. $sql .= ') ';
  37. }
  38. if (!$customerid&&$ownerCodes){
  39. $sql .= ' where storeStatus.CUSTOMERID in (';
  40. foreach ($ownerCodes as $index => $data){
  41. if ($index != 0)$sql .= ',';
  42. $sql .= "'".$data['code']."'";
  43. }
  44. $sql .= ') ';
  45. }
  46. $sql.=' group by storeStatus.LocationID,customer.Descr_C,sku.SKU,sku.ALTERNATE_SKU1 ';
  47. $sql.=' ,sku.Descr_C,lot.LotAtt05,lot.LotAtt08,lot.LotAtt02,lot.LotAtt04 ';
  48. $sql.=' , storeStatus.QTY, storeStatus.QtyAllocated,storeStatus.CUSTOMERID,storeStatus.ADDTIME ';
  49. $sql.=' )result where 1=1 ';
  50. if ($TOLocation)$sql .= " and 库位 like '".$TOLocation."' ";
  51. if ($SKU)$sql.=" and 产品编码 like '".$SKU."' ";
  52. if ($LotAtt05)$sql .=" and 属性仓 like '".$LotAtt05."' ";
  53. if ($date_start)$sql.=" and 创建时间 > to_date('".$date_start." 00:00:00','yyyy-mm-dd hh24:mi:ss') ";
  54. if ($date_end)$sql.=" and 创建时间 < to_date('".$date_end." 23:59:59','yyyy-mm-dd hh24:mi:ss') ";
  55. if ($LotAtt02_start)$sql.=" and 失效日期 >='".$LotAtt02_start." 00:00:00' ";
  56. if ($LotAtt02_end)$sql.=" and 失效日期 <='".$LotAtt02_end." 23:59:59' ";
  57. // if ($customerid){
  58. // $sql .= ' and 客户 in (';
  59. // $arr = explode(',',$customerid);
  60. // foreach ($arr as $index => $data){
  61. // if ($index != 0)$sql .= ',';
  62. // $sql .= "'".$data."'";
  63. // }
  64. // $sql .= ') ';
  65. // }
  66. if ($ALTERNATE_SKU1)$sql.=" and 产品条码 like '".$ALTERNATE_SKU1."' ";
  67. if ($page&&$paginate)$sql.=" and ROWNUM<='".$page*$paginate."'";
  68. $sql.=' ) ';
  69. if ($page&&$paginate)$sql.=" where rn>'".($page-1)*$paginate."'";
  70. return $sql;
  71. }
  72. public function paginate(array $params){
  73. return DB::connection('oracle')->select(DB::raw($this->getSql($params,$params['page'] ?? 1, $params['paginate'] ?? 50)));
  74. }
  75. }