AllInventoryService.php 4.1 KB

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