【发布时间】:2016-12-01 05:47:06
【问题描述】:
我正在开发房屋应用程序。我使用查询从不同的表名分别作为费用和收入来检索费用和收入的数据。 如果我只使用费用,那么它会打印出来,如果我也尝试混合收入值,它会给我带来问题。
代码:
$expenses = $expense->dailyExpense();
$income = $income->dailyIncome();
return response()->json(['data' => ['expenses' => $expenses , 'income' => $income] , 'msg' => 'Daily Expense']);
收入的查询部分是:
public function dailyIncome()
{
return $this->makeModel()
->select(DB::raw("sum(cost) as income"),"date")
->groupBy('date')
->get();
}
收入的查询部分是:
public function dailyExpense()
{
return $this->makeModel()
->select(DB::raw("sum(cost) as cost") , "date" , DB::raw("dayname(date) as calendar"))
->groupBy('date')
->get();
}
客户部分:
$scope.genereateReport = function () {
$scope.choices = ['Daily', 'Monthly', 'Yearly'];
$scope.$watch('selection', function (newVal, oldVal) {
switch (newVal) {
case 'Daily':
$scope.url = $scope.base_path + 'dailyExpenses';
$http.get($scope.url).success(function (response) {
$scope.expenses = response.data.expenses;
$scope.income = response.data.income;
$scope.totalExpenses = response.data.totalExpenses;
});
$scope.displayedCollection = [].concat($scope.expenses,$scope.income);
console.log("collection:" + $scope.displayedCollection);
$scope.totalExpenses = [].concat($scope.$totalExpenses);
// $scope.income = [].concat($scope.income);
//
$scope.itemsByPage = 10;
break;
}
);
};
查看部分:
<tr>
<th class="table-header-check">S.N</th>
<th st-sort="date" class="table-header-repeat line-left minwidth-1">Date</th>
<th st-sort="date" class="table-header-repeat line-left minwidth-1">Calandar</th>
<th st-sort="cost" class="table-header-repeat line-left minwidth-1">
Expense
</th> <th st-sort="cost" class="table-header-repeat line-left minwidth-1">
Income
</th>
</tr>
</thead>
<tbody>
<tr data-ng-repeat="row in displayedCollection track by $index" >
<td><% $index+1 %></td>
<td><%row.date%></td>
<td><%row.calendar%></td>
<td><%row.cost%></td>
<td><%income['row.date']%></td>
</tr>
<tr>
<td colspan="4">
Total Expense: <%totalExpenses%>
</td>
</tr>
上述json形式的查询结果为:
想要的输出是这样的..
]3
【问题讨论】: