categories for invoices/bills

This commit is contained in:
denisdulici
2018-04-23 22:17:20 +03:00
parent a81e1c76b9
commit 1af5720915
18 changed files with 215 additions and 182 deletions

View File

@ -28,14 +28,8 @@ class ProfitLoss extends Controller
$income_categories = Category::enabled()->type('income')->pluck('name', 'id')->toArray();
// Add invoice to income categories
$income_categories[0] = trans_choice('general.invoices', 2);
$expense_categories = Category::enabled()->type('expense')->pluck('name', 'id')->toArray();
// Add bill to expense categories
$expense_categories[0] = trans_choice('general.bills', 2);
// Get year
$year = request('year');
if (empty($year)) {
@ -53,15 +47,6 @@ class ProfitLoss extends Controller
'currency_rate' => 1
);
// Compares
$compares['income'][0][$dates[$j]] = [
'category_id' => 0,
'name' => trans_choice('general.invoices', 1),
'amount' => 0,
'currency_code' => setting('general.default_currency'),
'currency_rate' => 1
];
foreach ($income_categories as $category_id => $category_name) {
$compares['income'][$category_id][$dates[$j]] = [
'category_id' => $category_id,
@ -72,14 +57,6 @@ class ProfitLoss extends Controller
];
}
$compares['expense'][0][$dates[$j]] = [
'category_id' => 0,
'name' => trans_choice('general.bills', 1),
'amount' => 0,
'currency_code' => setting('general.default_currency'),
'currency_rate' => 1
];
foreach ($expense_categories as $category_id => $category_name) {
$compares['expense'][$category_id][$dates[$j]] = [
'category_id' => $category_id,
@ -99,14 +76,6 @@ class ProfitLoss extends Controller
'currency_rate' => 1
];
$compares['income'][0]['total'] = [
'category_id' => 0,
'name' => trans_choice('general.totals', 1),
'amount' => 0,
'currency_code' => setting('general.default_currency'),
'currency_rate' => 1
];
$gross['income'] = $gross['expense'] = [1 => 0, 2 => 0, 3 => 0, 4 => 0, 'total' => 0];
foreach ($income_categories as $category_id => $category_name) {
@ -119,14 +88,6 @@ class ProfitLoss extends Controller
];
}
$compares['expense'][0]['total'] = [
'category_id' => 0,
'name' => trans_choice('general.totals', 1),
'amount' => 0,
'currency_code' => setting('general.default_currency'),
'currency_rate' => 1
];
foreach ($expense_categories as $category_id => $category_name) {
$compares['expense'][$category_id]['total'] = [
'category_id' => $category_id,
@ -196,15 +157,9 @@ class ProfitLoss extends Controller
foreach ($items as $item) {
$date = Date::parse($item->$date_field)->quarter;
if (($type == 'invoice') || ($type == 'bill')) {
$category_id = 0;
} else {
$category_id = $item->category_id;
}
$group = (($type == 'invoice') || ($type == 'revenue')) ? 'income' : 'expense';
if (!isset($compares[$group][$category_id])) {
if (!isset($compares[$group][$item->category_id])) {
continue;
}
@ -217,10 +172,10 @@ class ProfitLoss extends Controller
}
}
$compares[$group][$category_id][$date]['amount'] += $amount;
$compares[$group][$category_id][$date]['currency_code'] = $item->currency_code;
$compares[$group][$category_id][$date]['currency_rate'] = $item->currency_rate;
$compares[$group][$category_id]['total']['amount'] += $amount;
$compares[$group][$item->category_id][$date]['amount'] += $amount;
$compares[$group][$item->category_id][$date]['currency_code'] = $item->currency_code;
$compares[$group][$item->category_id][$date]['currency_rate'] = $item->currency_rate;
$compares[$group][$item->category_id]['total']['amount'] += $amount;
if ($group == 'income') {
$totals[$date]['amount'] += $amount;