コード例 #1
0
ファイル: Statistics.php プロジェクト: bitller/nova
 /**
  * Return number of bills, number user sold products, total price and total discount.
  *
  * @return array
  */
 public static function billData()
 {
     // Build an array with all user bill ids
     $billIds = [];
     $bills = Bill::select('id')->where('user_id', Auth::user()->id)->get();
     foreach ($bills as $bill) {
         $billIds[] = $bill->id;
     }
     $data = ['sold_products' => BillApplicationProduct::whereIn('bill_id', $billIds)->count() + BillProduct::whereIn('bill_id', $billIds)->count(), 'bills' => count($billIds), 'total_price' => BillApplicationProduct::whereIn('bill_id', $billIds)->sum('final_price') + BillProduct::whereIn('bill_id', $billIds)->sum('final_price')];
     $data['total_discount'] = BillApplicationProduct::whereIn('bill_id', $billIds)->sum('price') + BillProduct::whereIn('bill_id', $billIds)->sum('price') - $data['total_price'];
     return $data;
 }