2016-06-28 13 views
0

CakePHPで作成した小文字は、引用符を生成することができますが、見積もり項目はPDF上で非特定の方法でソートされているようです。このIDを昇順にソートするにはどうすればよいでしょうか?私の引用のすべての項目が一覧表示されます私の関連するコードスニペット以下cakephp/fpdfで並べ替え

検索:一部の専門家の助けをいただければ幸いです

foreach ($items as $item) { 
     $itemSubTotal = $item['quantity'] * $item['unit_price']; 
     $discount_rate=$item['discount_rate']; 
     $unit_price=$item['unit_price']; 
     $subTotal += $itemSubTotal; 
     $itemDiscount=$itemSubTotal*$discount_rate/100; 
     $discount+=$itemDiscount; 
     //$itemTax = $itemSubTotal * ($item['tax_rate']/100); 
     $itemTax = ($itemSubTotal - $itemDiscount) * ($item['tax_rate']/100); 
     $tax += $itemTax; 
     $itemSubTotal = $itemSubTotal*((100-$discount_rate)/100); 
     $itemSubTotal = number_format($itemSubTotal, 2, '.', ','); 
     $y+=5; 
     $pdf->setXY(5, $y); 
     $pdf->MultiCell(10, 5, $i++, 0, 'L'); 
     $pdf->setXY(15, $y); 
     //$pdf->MultiCell(30, 5, $item['title'], 0, 'L'); 
     $pdf->Cell(30, 5, $item['title'], 0, 2, 'L'); 
     $pdf->setXY(45, $y); 
     //$pdf->MultiCell(80, 5, $item['details'], 0, 'L'); 
     $pdf->Cell(30, 5, $item['details'], 0, 2, 'L'); 
     $pdf->setXY(125, $y); 
     $pdf->MultiCell(20, 5, $item['quantity'], 0, 'R'); 
     $pdf->setXY(145, $y); 
     $pdf->MultiCell(15, 5, number_format($unit_price, 2, '.', ','), 0, 'R'); 
     $pdf->setXY(160, $y); 
     $pdf->MultiCell(20, 5, number_format($discount_rate, 2, '.', ','), 0, 'R'); 
     $pdf->setXY(180, $y); 
     $pdf->MultiCell(25, 5, $itemSubTotal, 0, 'R'); 
    } 

は、私はこれを試していない

答えて

0

ありがとう、それが動作するはずです。 cake 3 collectionsを参照してください。具体的にはsortBy

$アイテムをコレクションにラップして並べ替え、並べ替えた後、繰り返して目標を達成してください。以下のような 何か:

use Cake\Collection\Collection; 

$collection = new Collection($items); 
$sortedByField = $collection->sortBy('field') 

これはGROUPBY

+0

のような他の方法とプレーをしている動作しない場合は有益な洞察力をありがとうございました、私はダンを助けることができるうれしい – Dan

+0

を高く評価 –

関連する問題