我有 100 多个项目,项目有差异数据。我想通过单击打印 n 个 pdf,每个 pdf 可以有 n 页。我正在使用 foreach 并获得结果,但是当项目有 2000 多行(1 页有 25 行)时,它会超时。这是我的代码:
$finalItems = array('1,2,3,4',5,6,..............);
foreach($finalItems as $item){
$i++;
$getGrp = DB::table('item_master')->select('group')->where('item_name', $item)->get();
$rs = json_decode(json_encode($getGrp), true);
$getGP = call_user_func_array('array_merge', $rs);
$saleData = DB::table('sale_data')->where('item_name', $item)->where('site_id', $site_id)->whereBetween('bill_date',[$_POST['fromDate'],$_POST['toDate']])->get();
$purchaseData= DB::table('purchase_data')->where('item_name', $item)->where('site_id', $site_id)->whereBetween('bill_date',[$_POST['fromDate'],$_POST['toDate']])->get();
$stock_trf = DB::table('stock_transfer')->where('item_name',$item)->where('site_id', $site_id)->whereBetween('bill_date',[$_POST['fromDate'],$_POST['toDate']])->get();
$sales = json_decode(json_encode($saleData), true);
$purchase = json_decode(json_encode($purchaseData), true);
$stock = json_decode(json_encode($stock_trf), true);
$res = array_merge($sales, $purchase, $stock);
$groupName = $getGP['group'];
$pdf = PDF::loadView('myPDF', compact('res'));
$pdf->setPaper('a3', 'landscape');
$pdf->save(public_path().'/pdf/item_'.$item.'.pdf')>stream('item_'.$item.'.pdf');
$pdf_name[] = 'item_'.$item.'.pdf';
}
/****************** HTML 查看文件 ****************************** ***********/
@$dlr = array_chunk($res, 100);
$loopCount = count($dlr);
@for($i=0; $i<$loopCount; $i++)
@foreach ($dlr[$i] as $sldata[$i])
<tr >
<td style="width:2%"></td>
<td style="width:5.10%"></td>
<td style="width:9.10%"></td>
<td style="width:7.10%"></td>
<td style="width:5.10%">{{ $sldata[$i]['batch_no'] }}</td>
<td style="width:5.10%">{{ $sldata[$i]['mfg_date'] }}</td>
<td style="width:5.10%">{{ $sldata[$i]['exp_date'] }}</td>
<td style="width:5.10%"></td>
<td style="width:5.10%"></td>
<td style="width:5.10%"></td>
<td style="width:3.10%">{{ $last_balance }}</td>
<td style="width:5.10%"></td>
<td style="width:3.10%">{{ $sldata[$i]['quantity_in_kgltr'] }}</td>
<td style="width:4.10%"></td>
<td style="width:4.10%"></td>
<td style="width:5.10%">
<?php
$tocl = (int)$sldata[$i]['quantity_in_kgltr'];
echo @$last_balance -= $tocl; ?>
</td>
<td style="width:5.10%">{{ $sldata[$i]['bill_no'] }}</td>
<td style="width:5.10%">{{ date('d-m-Y', strtotime($sldata[$i]['bill_date'])) }}</td>
<td style="width:8.10%">{{ $sldata[$i]['sales_to_customer_name'] }}</td>
<td style="width:3.10%"></td>
</tr>
@endforeach
@endfor