| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- <?php
- namespace App\Http\Controllers;
- use App\Components\AsyncResponse;
- use App\Exports\InventoryBlindReceiveExcelExport;
- use App\InventoryBlindReceiveExcel;
- use App\OracleDOCASNDetail;
- use App\Services\HandInStorageService;
- use Carbon\Carbon;
- use Doctrine\DBAL\Exception\DatabaseObjectExistsException;
- use Illuminate\Http\Request;
- use Maatwebsite\Excel\Facades\Excel;
- class StoreCountGoodsAndReceiveController extends Controller
- {
- use AsyncResponse;
- public function index()
- {
- /** @var HandInStorageService $handInStorageService */
- $handInStorageService=app('HandInStorageService');
- $qualityStatus=$handInStorageService->getQualityStatus();
- $attributeLocations=$handInStorageService->getAttributeLocation();
- return view('store.countGoodsAndReceive.index',
- compact('qualityStatus','attributeLocations'));
- }
- public function excel()
- {
- $excels=InventoryBlindReceiveExcel::query()
- ->where('name','like','清点%')
- ->orderByDesc('id')->get();
- return view('store.countGoodsAndReceive.excel',['excels'=>$excels]);
- }
- public function createExcel(Request $request): array
- {
- $goodses=$request->input('goodses')??'';
- $excelFileName=$request->input('filename')??'';
- if(!$goodses||!is_array($goodses)||count($goodses)==0){
- return ['result'=>'failure','fail_info'=>'没有数据提交!'];
- }
- $goodsExcelArray=[['条码','数量','箱号']];
- foreach ($goodses as $goods){
- array_push($goodsExcelArray,[$goods['barcode'],$goods['amount'],$goods['cast_number']]);
- }
- $fileName=Carbon::now()->toDateTimeLocalString().'.xlsx';
- $fileName = str_replace( ':', '_',$fileName);
- $goodsNeateningExcel = new InventoryBlindReceiveExcel(['file' => $fileName, 'goods_amount' => count($goodses), 'name'=>'清点_'.$excelFileName]);
- $goodsNeateningExcel->save();
- Excel::store(new InventoryBlindReceiveExcelExport($goodsExcelArray),$fileName,'public');
- $this->removeExpiredExcel();
- return ['result'=>'success'];
- }
- private function removeExpiredExcel(){
- $excels=InventoryBlindReceiveExcel::query()->where('created_at','<',Carbon::now()->subDays(100)->toDateTimeString())->get();
- $excels->each(
- /** @throws \Exception */
- function(InventoryBlindReceiveExcel $excel){
- $excel->delete();
- });
- }
- // /**
- // * @param Request $request
- // * 查询富勒bas_sku 并关联 bas_lotid
- // */
- // public function getReceiveInfoWithLot(Request $request): array
- // {
- // $barcode= $request->input('barcode');
- // $asnno= $request->input('asnno');
- // $asnDetail=app('HandInStorageService')->getAsnDetail($asnno,$barcode);
- // if (!$asnDetail)$this->error('无效条码');
- // $basSku =app('HandInStorageService')->getBasSkuLotId($asnDetail->customerid,$asnDetail->sku);
- // if (isset($basSku)&&isset($asnDetail))return ['success'=>true,'basSku'=>$basSku,'asnDetail'=>$asnDetail];
- // else $this->error('无效条码');
- // }
- public function getReceiveTaskByAsnNoAndBarcodes(Request $request)
- {
- $asnno=$request->input('asnno');//ASN1906280001
- $goods=$request->input('goods');
- // $barcodes=array_diff(array_unique(data_get($goods,'*.barcode')),['','*',null]);
- $asnDetails=OracleDOCASNDetail::query()
- ->select('asnno','asnlineno','customerid','sku','expectedqty','receivedqty_each',
- 'lotatt01','lotatt02','lotatt03','lotatt04','lotatt05','lotatt08')
- ->with('basSku.lotId')
- ->where('asnno',$asnno)
- ->whereIn('linestatus', ['00', '30'])
- ->get();
- foreach ($goods as &$good){
- foreach ($asnDetails as $asnDetail){
- if (!$asnDetail['basSku']??false)continue;
- if ($good['barcode']==$asnDetail['basSku']['alternate_sku1']
- ||$good['barcode']==$asnDetail['basSku']['alternate_sku2']
- ||$good['barcode']==$asnDetail['basSku']['alternate_sku3']){
- $good['basSku']=$asnDetail['basSku'];
- $good['customerid']=$asnDetail['customerid'];
- $good['asn_amount']=($asnDetail['expectedqty']-$asnDetail['receivedqty_each']);
- $good['diff_val']=($good['asn_amount']-$good['amount']);
- $good['receiveStatus']=true;
- $good['lotatt01']=$asnDetail['lotatt01'];
- $good['lotatt02']=$asnDetail['lotatt02'];
- $good['lotatt03']=$asnDetail['lotatt03'];
- $good['lotatt04']=$asnDetail['lotatt04'];
- $good['lotatt05']=$asnDetail['lotatt05'];
- $good['lotatt08']=$asnDetail['lotatt08'];
- }
- }
- }
- $this->success($goods);
- }
- }
|