StoreCountGoodsAndReceiveController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Components\AsyncResponse;
  4. use App\Exports\InventoryBlindReceiveExcelExport;
  5. use App\InventoryBlindReceiveExcel;
  6. use App\OracleDOCASNDetail;
  7. use App\Services\HandInStorageService;
  8. use Carbon\Carbon;
  9. use Doctrine\DBAL\Exception\DatabaseObjectExistsException;
  10. use Illuminate\Http\Request;
  11. use Maatwebsite\Excel\Facades\Excel;
  12. class StoreCountGoodsAndReceiveController extends Controller
  13. {
  14. use AsyncResponse;
  15. public function index()
  16. {
  17. /** @var HandInStorageService $handInStorageService */
  18. $handInStorageService=app('HandInStorageService');
  19. $qualityStatus=$handInStorageService->getQualityStatus();
  20. $attributeLocations=$handInStorageService->getAttributeLocation();
  21. return view('store.countGoodsAndReceive.index',
  22. compact('qualityStatus','attributeLocations'));
  23. }
  24. public function excel()
  25. {
  26. $excels=InventoryBlindReceiveExcel::query()
  27. ->where('name','like','清点%')
  28. ->orderByDesc('id')->get();
  29. return view('store.countGoodsAndReceive.excel',['excels'=>$excels]);
  30. }
  31. public function createExcel(Request $request): array
  32. {
  33. $goodses=$request->input('goodses')??'';
  34. $excelFileName=$request->input('filename')??'';
  35. if(!$goodses||!is_array($goodses)||count($goodses)==0){
  36. return ['result'=>'failure','fail_info'=>'没有数据提交!'];
  37. }
  38. $goodsExcelArray=[['条码','数量','箱号']];
  39. foreach ($goodses as $goods){
  40. array_push($goodsExcelArray,[$goods['barcode'],$goods['amount'],$goods['cast_number']]);
  41. }
  42. $fileName=Carbon::now()->toDateTimeLocalString().'.xlsx';
  43. $fileName = str_replace( ':', '_',$fileName);
  44. $goodsNeateningExcel = new InventoryBlindReceiveExcel(['file' => $fileName, 'goods_amount' => count($goodses), 'name'=>'清点_'.$excelFileName]);
  45. $goodsNeateningExcel->save();
  46. Excel::store(new InventoryBlindReceiveExcelExport($goodsExcelArray),$fileName,'public');
  47. $this->removeExpiredExcel();
  48. return ['result'=>'success'];
  49. }
  50. private function removeExpiredExcel(){
  51. $excels=InventoryBlindReceiveExcel::query()->where('created_at','<',Carbon::now()->subDays(100)->toDateTimeString())->get();
  52. $excels->each(
  53. /** @throws \Exception */
  54. function(InventoryBlindReceiveExcel $excel){
  55. $excel->delete();
  56. });
  57. }
  58. // /**
  59. // * @param Request $request
  60. // * 查询富勒bas_sku 并关联 bas_lotid
  61. // */
  62. // public function getReceiveInfoWithLot(Request $request): array
  63. // {
  64. // $barcode= $request->input('barcode');
  65. // $asnno= $request->input('asnno');
  66. // $asnDetail=app('HandInStorageService')->getAsnDetail($asnno,$barcode);
  67. // if (!$asnDetail)$this->error('无效条码');
  68. // $basSku =app('HandInStorageService')->getBasSkuLotId($asnDetail->customerid,$asnDetail->sku);
  69. // if (isset($basSku)&&isset($asnDetail))return ['success'=>true,'basSku'=>$basSku,'asnDetail'=>$asnDetail];
  70. // else $this->error('无效条码');
  71. // }
  72. public function getReceiveTaskByAsnNoAndBarcodes(Request $request)
  73. {
  74. $asnno=$request->input('asnno');//ASN1906280001
  75. $goods=$request->input('goods');
  76. // $barcodes=array_diff(array_unique(data_get($goods,'*.barcode')),['','*',null]);
  77. $asnDetails=OracleDOCASNDetail::query()
  78. ->select('asnno','asnlineno','customerid','sku','expectedqty','receivedqty_each',
  79. 'lotatt01','lotatt02','lotatt03','lotatt04','lotatt05','lotatt08')
  80. ->with('basSku.lotId')
  81. ->where('asnno',$asnno)
  82. ->whereIn('linestatus', ['00', '30'])
  83. ->get();
  84. foreach ($goods as &$good){
  85. foreach ($asnDetails as $asnDetail){
  86. if (!$asnDetail['basSku']??false)continue;
  87. if ($good['barcode']==$asnDetail['basSku']['alternate_sku1']
  88. ||$good['barcode']==$asnDetail['basSku']['alternate_sku2']
  89. ||$good['barcode']==$asnDetail['basSku']['alternate_sku3']){
  90. $good['basSku']=$asnDetail['basSku'];
  91. $good['customerid']=$asnDetail['customerid'];
  92. $good['asn_amount']=($asnDetail['expectedqty']-$asnDetail['receivedqty_each']);
  93. $good['diff_val']=($good['asn_amount']-$good['amount']);
  94. $good['receiveStatus']=true;
  95. $good['lotatt01']=$asnDetail['lotatt01'];
  96. $good['lotatt02']=$asnDetail['lotatt02'];
  97. $good['lotatt03']=$asnDetail['lotatt03'];
  98. $good['lotatt04']=$asnDetail['lotatt04'];
  99. $good['lotatt05']=$asnDetail['lotatt05'];
  100. $good['lotatt08']=$asnDetail['lotatt08'];
  101. }
  102. }
  103. }
  104. $this->success($goods);
  105. }
  106. }