InventoryController.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\OracleBasCustomer;
  4. use App\Owner;
  5. use App\Services\AllInventoryService;
  6. use App\Services\InventoryDailyLogService;
  7. use App\Services\InventoryService;
  8. use App\Services\OwnerService;
  9. use Exception;
  10. use Illuminate\Http\Request;
  11. use Illuminate\Support\Facades\Gate;
  12. use Illuminate\Support\Facades\Http;
  13. use Oursdreams\Export\Export;
  14. class InventoryController extends Controller
  15. {
  16. public function __construct()
  17. {
  18. app()->singleton('inventoryService',InventoryService::class);
  19. app()->singleton('AllInventoryService',AllInventoryService::class);
  20. }
  21. //动库报表
  22. public function changeInventory(Request $request){
  23. if(!Gate::allows("库存管理-库存")){ return redirect(url('/')); }
  24. $oracleActTransactingLogs=app('inventoryService')->paginate($request->input());
  25. $oracleActTransactingLogs=json_encode($oracleActTransactingLogs);
  26. $owners=Owner::filterAuthorities()->select(['code', 'name'])->get();
  27. $isTotalStock=false;
  28. $page = $request->page ?? 1;
  29. return view('inventory.statement.changeInventory',compact('oracleActTransactingLogs','page','owners','isTotalStock'));
  30. }
  31. //全部库存
  32. public function allInventory(Request $request){
  33. if(!Gate::allows("库存管理-库存")){ return redirect(url('/')); }
  34. /** @var AllInventoryService $service */
  35. $service = app('AllInventoryService');
  36. $oracleActTransactingLogs= $service->paginate($request->input());
  37. $oracleActTransactingLogs=json_encode($oracleActTransactingLogs);
  38. // $owners=OracleBasCustomer::query()->select('customerid','descr_c')->where('customer_type','OW')->where('active_flag','Y')->get();
  39. $owners=Owner::filterAuthorities()->select(['code', 'name'])->get();
  40. $isTotalStock=true;
  41. $page = $request->page ?? 1;
  42. return view('inventory.statement.changeInventory',compact('oracleActTransactingLogs','page','owners','isTotalStock'));
  43. }
  44. public function exportData(Request $request){
  45. if(!Gate::allows("库存管理-库存")){ return redirect(url('/')); }
  46. if ($request->checkAllSign){
  47. $params = $request->input();
  48. unset($params['checkAllSign']);
  49. $sql=app('inventoryService')->getSql($request->input());
  50. $e = new Export();
  51. $e->setOracleConnection(config('database.connections.oracle.host'),
  52. config('database.connections.oracle.port'),config('database.connections.oracle.database')
  53. ,config('database.connections.oracle.username'),config('database.connections.oracle.password'));
  54. $e->setFileName("动库报表");
  55. return $e->sql($sql,[
  56. "货主"=>"货主","库位"=>"库位",
  57. "产品编码"=>"产品编码","产品条码"=>"产品条码",
  58. "商品名称"=>"商品名称","属性仓"=>"属性仓",
  59. "质量状态"=>"质量状态","失效日期"=>"失效日期",
  60. "批号"=>"批号","移出数量"=>"移出数量","移入数量"=>"移入数量"
  61. ])->direct();
  62. }else return "暂时关闭,如需开启请联系管理员";
  63. }
  64. public function exportAllInventory(Request $request){
  65. if(!Gate::allows("库存管理-库存")){ return view("denied"); }
  66. if ($request->checkAllSign){
  67. $params = $request->input();
  68. unset($params['checkAllSign']);
  69. $sql=app('AllInventoryService')->getSql($request->input());
  70. $e = new Export();
  71. $e->setOracleConnection(config('database.connections.oracle.host'),
  72. config('database.connections.oracle.port'),config('database.connections.oracle.database')
  73. ,config('database.connections.oracle.username'),config('database.connections.oracle.password'));
  74. $e->setFileName("全部库存");
  75. return $e->sql($sql,[
  76. "货主"=>"货主","库位"=>"库位",
  77. "产品编码"=>"产品编码","产品条码"=>"产品条码",
  78. "商品名称"=>"商品名称","属性仓"=>"属性仓",
  79. "质量状态"=>"质量状态","失效日期"=>"失效日期",
  80. "批号"=>"批号","在库数量"=>"在库数量","占用数量"=>"占用数量"
  81. ])->direct();
  82. }else return "暂时关闭,如需开启请联系管理员";
  83. }
  84. /*
  85. * 库存体积
  86. */
  87. function dailyLog(Request $request,OwnerService $ownerService){
  88. if (!Gate::allows('库存管理-库存体积')){return redirect(url('/')); }
  89. /** @var InventoryDailyLogService*/
  90. $inventoryDailyLogs = app('InventoryDailyLogService')->paginate($request->input());
  91. $owners = $ownerService->getIntersectPermitting();
  92. $param = $request->input();
  93. return view('inventory.statement.dailyLog',compact('inventoryDailyLogs','owners','param'));
  94. }
  95. //获取记录监听货主
  96. function getLoggingOwner(){
  97. $loggingOwners = app('InventoryDailyLogService')->getInventoryDailyLoggingOwner('owner_id');
  98. return array_column($loggingOwners->toArray(),'owner_id');
  99. }
  100. //添加记录监听货主
  101. function addLoggingOwner(Request $request){
  102. if (!Gate::allows('库存管理-库存体积-管理监听货主')){return redirect(url('/')); }
  103. $owner_id = $request->owner_id;
  104. if (!$owner_id || !is_numeric($owner_id))return ['success'=>false,'data'=>'传递参数错误!'];
  105. $loggingOwner = app('InventoryDailyLogService')->firstOrCreate(['owner_id'=>$owner_id]);
  106. if (!$loggingOwner)return ['success'=>false,'data'=>'录入失败!'];
  107. return ['success'=>true,'data'=>$loggingOwner->owner_id];
  108. }
  109. //导出库存体积记录
  110. public function exportDailyLog(Request $request){
  111. if (!Gate::allows('库存管理-库存体积')){return redirect(url('/')); }
  112. if ($request->checkAllSign){
  113. $params = $request->input();
  114. unset($params['checkAllSign']);
  115. $sql=app('InventoryDailyLogService')->getSql($params);
  116. }else $sql=app('InventoryDailyLogService')->getSql(['id'=>$request->data]);
  117. $rule = ["created_at"=> "mysqlDate"];
  118. $e = new Export();
  119. $e->setMysqlConnection(config('database.connections.mysql.host'),
  120. config('database.connections.mysql.port'),config('database.connections.mysql.database')
  121. ,config('database.connections.mysql.username'),config('database.connections.mysql.password'));
  122. $e->setFileName("库存体积");
  123. return $e->sql($sql,[
  124. "owner_name"=>"货主","created_at"=>"日期",
  125. "commodity_name"=>"商品名称","commodity_sku"=>"商品编码",
  126. "commodity_barcode_code"=>"商品条码","depository_name"=>"属性仓",
  127. "amount"=>"在库数量","commodity_length"=>"长",
  128. "commodity_width"=>"宽","commodity_height"=>"高",
  129. "commodity_volumn"=>"体积","volumn_occupied"=>"总占用体积",
  130. "gross_weight"=>"总毛重"
  131. ],$rule)->direct();
  132. }
  133. }