2013-02-25 43 views
0

我正在構建一個報告銷售數據的應用程序。核心數據結構如下使用核心數據製表數據 - 如何有效地過濾?

Product <---->> SaleAggregate 
Customer <---->> SaleAggregate 

SaleAggregate是每個客戶的某個月的每個產品的總銷售額。該實體具有「月」,「年」和「金額」屬性。

我想以表格的形式顯示此如下(每個客戶一個單獨的表)

+---------+---------+---------+---------+---------+ 
| Product | 01/2011 | 02/2011 | 03/2011 | 04/2011 | 
+---------+---------+---------+---------+---------+ 
| Gizmo |  40 |  120 |  83 |  48 | 
| Widget |  92 |  38 |  37 |  36 | 
| Thingy |  12 |  84 |  29 |  40 | 
+---------+---------+---------+---------+---------+ 

每個客戶可以有銷售記錄的任何數量的產品,我需要檢索所有的銷售額,按產品分組,然後顯示每個SaleAggregate'Amount'與相應的月份/年份。

我可以通過NSPredicate輕鬆檢索所有SaleAggregates,並且所有銷售給客戶的獨特產品都帶有NSPredicate和@distinctUnionOfObjects,但我不確定該從哪裏出發。

該表是用UICollectionView實現的,但我不太確定邏輯應該將正確的值放在cellForItemAtIndexPath的正確單元格中。是否只是在一個查詢中檢索每個SaleAggregate,然後使用NSPredicate過濾每個想要顯示的單元格的正確月份/年的數組?我認爲必須有一個更聰明的方式來做到這一點。

謝謝!

+0

如果我沒有理解這個權利,有量SalesAggregate對象的例子,說40是一個特定產品的一個特定客戶在特定月份買了多少? – Rakesh 2013-02-25 17:58:47

回答

0

這個怎麼樣?

使用謂詞和過濾,你可以得到以下爲特定的客戶?

ProductArray: 
SalesAggreateDateArray: 

if section ==0 
     row==0 --> "Product" 
     rest of the rows --> [ProductArray objectAtIndex:indexPath.row] 
else if row ==0 
     sections --> [SalesAggregateDateArray objectAtIndex:indexPath.section] 
else 
     each cell --> [SalesAggregateAmountObjects filter with 
           date= date at row 0, indexPath.section and 
           product = product at section 0, indexPath.row]