2016-06-28 30 views
0

我在CakePHP中創建了一個可以生成引號的小腳本,但是引號項似乎在我的PDF上以非特定方式排序。按升序排序的最好方法是什麼?sortin 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,特別是排序

如果你把你的$物品包裝在一個集合中,然後對它們進行排序,然後遍歷它們,你將實現你的目標。 喜歡的東西:

use Cake\Collection\Collection; 

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

如果這不起作用與其他方法,如進行分組的戲

+0

非常感謝您的有益的見解,被欣賞 – Dan

+0

很高興我能幫助丹 –