InventoryController.php 7.1 KB

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