Demo project
This commit is contained in:
1 parent
5e4f3540e8
commit
a68267d0f0
146 files changed
+41587
No files matched your search
@@ -0,0 +1,269 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class Actual extends Component
|
||||
{
|
||||
protected $listeners = [
|
||||
'$refresh'
|
||||
];
|
||||
|
||||
// General data
|
||||
public int $year;
|
||||
public array $activeMonths;
|
||||
public int $activeMonthCount;
|
||||
|
||||
// Quick add
|
||||
public string $quickValue;
|
||||
public int $quickPostID;
|
||||
public int $quickMonth;
|
||||
|
||||
// Clear month
|
||||
public string $columnName;
|
||||
public int $columnMonth;
|
||||
|
||||
// Edit field
|
||||
public string $fieldName;
|
||||
public string $fieldMonthName;
|
||||
public string $fieldTypeHTML;
|
||||
public string $fieldHistoryHTML;
|
||||
public int $fieldPostID;
|
||||
public int $fieldMonth;
|
||||
public string $fieldAddValue;
|
||||
|
||||
// Delete value
|
||||
public int $deleteValueID;
|
||||
public string $deleteValueHTML;
|
||||
|
||||
// View mode switch
|
||||
public string $switchValuesCSS;
|
||||
public string $switchDifferenceCSS;
|
||||
public string $switchMode;
|
||||
|
||||
// Modals
|
||||
public bool $modalFieldUpdate;
|
||||
public bool $modalColumnUpdate;
|
||||
public bool $modalDelete;
|
||||
|
||||
public function mount() {
|
||||
$category = \App\Models\Category::where("user_id", \Auth::user()->id)->orderBy("priority")->first();
|
||||
|
||||
$this->quickValue = "";
|
||||
$this->quickPostID = $category->posts->where('year', $this->year)->count() > 0 ? $category->posts->where('year', $this->year)->first()->id : -1;
|
||||
$this->quickMonth = intval((new \Datetime())->format("m"));
|
||||
|
||||
$this->columnName = "January";
|
||||
$this->columnMonth = 1;
|
||||
|
||||
$this->fieldName = "";
|
||||
$this->fieldMonthName = $this->columnName;
|
||||
$this->fieldTypeHTML = "expense";
|
||||
$this->fieldHistoryHTML = "Nothing";
|
||||
$this->fieldPostID = $this->quickPostID;
|
||||
$this->fieldAddValue = "";
|
||||
$this->month = $this->columnMonth;
|
||||
|
||||
$this->deleteValueID = 0;
|
||||
$this->deleteValueHTML = "";
|
||||
|
||||
$this->modalFieldUpdate = false;
|
||||
$this->modalColumnUpdate = false;
|
||||
$this->modalDelete = false;
|
||||
|
||||
$this->switchMode("values");
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$this->activeMonths = \Auth::user()->activeActualMonths($this->year);
|
||||
$this->activeMonthCount = 0;
|
||||
foreach($this->activeMonths as $month) {
|
||||
if($month) {
|
||||
$this->activeMonthCount++;
|
||||
}
|
||||
}
|
||||
|
||||
$categories = \App\Models\Category::where("user_id", \Auth::user()->id)->orderBy("priority")->get();
|
||||
|
||||
if($this->quickPostID == -1) {
|
||||
$category = \App\Models\Category::where("user_id", \Auth::user()->id)->orderBy("priority")->first();
|
||||
$this->quickPostID = $category->posts->where('year', $this->year)->count() > 0 ? $category->posts->where('year', $this->year)->first()->id : -1;
|
||||
}
|
||||
|
||||
$hf = new \App\Http\Livewire\Helper();
|
||||
|
||||
return view('livewire.actual', ["categories" => $categories, "hf" => $hf]);
|
||||
}
|
||||
|
||||
public function quickinput() {
|
||||
$post = \App\Models\Post::whereHas('category', function ($query) {
|
||||
return $query->where('user_id', \Auth::user()->id);
|
||||
})->where("id", $this->quickPostID)->first();
|
||||
|
||||
$value = null;
|
||||
if($this->quickValue != null && trim($this->quickValue) != "" && is_numeric(trim($this->quickValue))) {
|
||||
$value = floatval($this->quickValue);
|
||||
}
|
||||
|
||||
if($value != 0) {
|
||||
$transaction = new \App\Models\TransactionValue();
|
||||
$transaction->post_id = $post->id;
|
||||
$transaction->value = $value;
|
||||
$transaction->month = $this->quickMonth;
|
||||
$transaction->save();
|
||||
}
|
||||
|
||||
$this->quickValue = "";
|
||||
$this->emit("focusField", "quickValue");
|
||||
}
|
||||
|
||||
public function openColumnUpdate($month) {
|
||||
$this->columnName = ["-", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][$month];
|
||||
$this->columnMonth = $month;
|
||||
$this->modalColumnUpdate = true;
|
||||
}
|
||||
|
||||
public function closeColumnUpdate() {
|
||||
$this->modalColumnUpdate = false;
|
||||
}
|
||||
|
||||
public function updateColumn() {
|
||||
$categories = \App\Models\Category::where("user_id", \Auth::user()->id)->orderBy("priority")->get();
|
||||
foreach($categories as $category) {
|
||||
foreach($category->posts->where("year", $this->year) as $post) {
|
||||
foreach(\App\Models\TransactionValue::where("post_id", $post->id)->where("month", $this->columnMonth)->get() as $value) {
|
||||
if($value != null) {
|
||||
$value->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->modalColumnUpdate = false;
|
||||
}
|
||||
|
||||
public function openFieldUpdate($postID, $month) {
|
||||
$post = \App\Models\Post::whereHas('category', function ($query) {
|
||||
return $query->where('user_id', \Auth::user()->id);
|
||||
})->where("id", $postID)->first();
|
||||
|
||||
if($post) {
|
||||
$this->fieldPostID = $post->id;
|
||||
$this->fieldName = $post->name;
|
||||
$this->fieldTypeHTML = "<span class=\"".($post->is_expense ? "col-neg" : "col-pos")."\">".($post->is_expense ? "expense" : "income")."</span>";
|
||||
$this->fieldMonth = $month;
|
||||
$this->fieldMonthName = ["-", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][$month];
|
||||
|
||||
$values = \App\Models\TransactionValue::where("post_id", $post->id)->where("month", $month);
|
||||
if($values->count() > 0) {
|
||||
$hf = new \App\Http\Livewire\Helper();
|
||||
$this->fieldHistoryHTML = "<span class=\"text-sm text-gray-500\">";
|
||||
|
||||
$first = true;
|
||||
foreach($values->get() as $value) {
|
||||
$v = $value->value * ($post->is_expense ? -1.00 : 1.00);
|
||||
|
||||
if(!$first) {
|
||||
if($value->value > 0) {
|
||||
$this->fieldHistoryHTML .= " + ";
|
||||
} else {
|
||||
$this->fieldHistoryHTML .= " - ";
|
||||
}
|
||||
} else {
|
||||
$first = false;
|
||||
}
|
||||
|
||||
$this->fieldHistoryHTML .= "<span wire:click=\"openDelete(".$value->id.")\">";
|
||||
$this->fieldHistoryHTML .= $hf->number($v);
|
||||
$this->fieldHistoryHTML .= "</span>";
|
||||
}
|
||||
|
||||
if($values->count() > 1) {
|
||||
$this->fieldHistoryHTML .= " = <strong>" . $hf->number($post->monthActualValue($month))."</strong>";
|
||||
}
|
||||
|
||||
$this->fieldHistoryHTML .= "</span>";
|
||||
} else {
|
||||
$this->fieldHistoryHTML = "<span class=\"text-sm text-gray-500\">Nothing ...</span>";
|
||||
}
|
||||
$this->modalFieldUpdate = true;
|
||||
$this->emit("focusField", "fieldAddValue");
|
||||
}
|
||||
}
|
||||
|
||||
public function closeFieldUpdate() {
|
||||
$this->modalFieldUpdate = false;
|
||||
}
|
||||
|
||||
public function addValue() {
|
||||
$post = \App\Models\Post::whereHas('category', function ($query) {
|
||||
return $query->where('user_id', \Auth::user()->id);
|
||||
})->where("id", $this->fieldPostID)->first();
|
||||
|
||||
$value = null;
|
||||
if($this->fieldAddValue != null && trim($this->fieldAddValue) != "" && is_numeric(trim($this->fieldAddValue))) {
|
||||
$value = floatval($this->fieldAddValue);
|
||||
}
|
||||
|
||||
if($value != 0) {
|
||||
$transaction = new \App\Models\TransactionValue();
|
||||
$transaction->post_id = $post->id;
|
||||
$transaction->value = $value;
|
||||
$transaction->month = $this->fieldMonth;
|
||||
$transaction->save();
|
||||
}
|
||||
|
||||
$this->fieldAddValue = "";
|
||||
$this->openFieldUpdate($this->fieldPostID, $this->fieldMonth);
|
||||
$this->emit("focusField", "fieldAddValue");
|
||||
}
|
||||
|
||||
public function openDelete($valueID) {
|
||||
$hf = new \App\Http\Livewire\Helper();
|
||||
|
||||
$this->deleteValueID = $valueID;
|
||||
$value = \App\Models\TransactionValue::with("post")->whereHas('post', function ($query) {
|
||||
return $query->whereHas('category', function($query2) {
|
||||
return $query2->where('user_id', \Auth::user()->id);
|
||||
});
|
||||
})->where("id", $this->deleteValueID)->first();
|
||||
|
||||
$this->deleteValueHTML = $hf->number($value->value * ($value->post->is_expense ? -1.0 : 1.0));
|
||||
|
||||
$this->modalFieldUpdate = false;
|
||||
$this->modalDelete = true;
|
||||
}
|
||||
|
||||
public function closeDelete() {
|
||||
$this->modalFieldUpdate = true;
|
||||
$this->modalDelete = false;
|
||||
}
|
||||
|
||||
public function deleteValue() {
|
||||
$value = \App\Models\TransactionValue::with("post")->whereHas('post', function ($query) {
|
||||
return $query->whereHas('category', function($query2) {
|
||||
return $query2->where('user_id', \Auth::user()->id);
|
||||
});
|
||||
})->where("id", $this->deleteValueID)->first();
|
||||
|
||||
if($value != null) {
|
||||
$value->delete();
|
||||
}
|
||||
|
||||
$this->modalDelete = false;
|
||||
$this->openFieldUpdate($this->fieldPostID, $this->fieldMonth);
|
||||
}
|
||||
|
||||
public function switchMode($mode) {
|
||||
$this->switchMode = $mode;
|
||||
|
||||
if($mode == "values") {
|
||||
$this->switchValuesCSS = "bg-blue-700";
|
||||
$this->switchDifferenceCSS = "bg-gray-300";
|
||||
} else {
|
||||
$this->switchValuesCSS = "bg-gray-300";
|
||||
$this->switchDifferenceCSS = "bg-blue-700";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class Categories extends Component
|
||||
{
|
||||
public $name;
|
||||
public $deleteID;
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.categories', [
|
||||
'categories' => \App\Models\Category::where("user_id", \Auth::user()->id)->orderBy("priority")->get()
|
||||
]);
|
||||
}
|
||||
|
||||
public function create() {
|
||||
if(trim($this->name) == "") {
|
||||
$this->name = ""; return;
|
||||
}
|
||||
|
||||
$existing = \App\Models\Category::where("user_id", \Auth::user()->id)->where("name", $this->name)->first();
|
||||
if($existing != null) {
|
||||
$this->name = ""; return;
|
||||
}
|
||||
|
||||
$highest = \App\Models\Category::where("user_id", \Auth::user()->id)->orderBy("priority", "desc")->first();
|
||||
if($highest != null) {
|
||||
$highest = $highest->priority;
|
||||
} else {
|
||||
$highest = 0;
|
||||
}
|
||||
|
||||
$cat = new \App\Models\Category();
|
||||
$cat->user_id = \Auth::user()->id;
|
||||
$cat->name = trim($this->name);
|
||||
$cat->priority = $highest + 1;
|
||||
$cat->save();
|
||||
|
||||
$this->name = "";
|
||||
}
|
||||
|
||||
public function delete() {
|
||||
$cat = \App\Models\Category::where("user_id", \Auth::user()->id)->where("id", $this->deleteID)->first();
|
||||
if($cat) {
|
||||
$cat->delete();
|
||||
}
|
||||
}
|
||||
|
||||
public function moveUp($catID) {
|
||||
$cat = \App\Models\Category::where("user_id", \Auth::user()->id)->where("id", $catID)->first();
|
||||
if($cat) {
|
||||
$cat->move(true);
|
||||
}
|
||||
}
|
||||
|
||||
public function moveDown($catID) {
|
||||
$cat = \App\Models\Category::where("user_id", \Auth::user()->id)->where("id", $catID)->first();
|
||||
if($cat) {
|
||||
$cat->move(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
class Helper {
|
||||
public function Number($value) {
|
||||
return '<span class="'.(round($value) == 0 ? 'col-zero' : (round($value) > 0 ? 'col-pos' : 'col-neg')) .'">'.number_format(abs(round($value)), 0).'</span>';
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,296 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Livewire;
|
||||
|
||||
use Livewire\Component;
|
||||
|
||||
class Projected extends Component
|
||||
{
|
||||
// General data
|
||||
public int $year;
|
||||
public array $activeMonths;
|
||||
public int $activeMonthCount;
|
||||
|
||||
// Creating posts
|
||||
public string $createName;
|
||||
public string $createType;
|
||||
public int $createCategoryID;
|
||||
|
||||
// Updating rows
|
||||
public string $rowName;
|
||||
public string $rowTypeHTML;
|
||||
public string $rowValue;
|
||||
public int $rowPostID;
|
||||
|
||||
// Updating fields
|
||||
public string $fieldName;
|
||||
public string $fieldTypeHTML;
|
||||
public int $fieldMonth;
|
||||
public string $fieldMonthName;
|
||||
public string $fieldValue;
|
||||
public int $fieldPostID;
|
||||
|
||||
// Update column
|
||||
public string $columnName;
|
||||
public int $columnMonth;
|
||||
|
||||
// Delete row
|
||||
public int $deletePostID;
|
||||
public string $deleteName;
|
||||
|
||||
// Copy year
|
||||
public int $copyYear;
|
||||
public string $copyMethod;
|
||||
|
||||
// Modals
|
||||
public bool $modalRowUpdate;
|
||||
public bool $modalFieldUpdate;
|
||||
public bool $modalColumnUpdate;
|
||||
public bool $modalDelete;
|
||||
|
||||
public function mount() {
|
||||
$this->createName = "";
|
||||
$this->createType = "expense";
|
||||
$this->createCategoryID = \App\Models\Category::where("user_id", \Auth::user()->id)->orderBy("priority")->first()->id;
|
||||
|
||||
$this->rowName = "";
|
||||
$this->rowTypeHTML = "expense";
|
||||
$this->rowValue = "";
|
||||
$this->rowPostID = 0;
|
||||
|
||||
$this->fieldName = "";
|
||||
$this->fieldTypeHTML = "expense";
|
||||
$this->fieldMonth = 1;
|
||||
$this->fieldMonthName = "January";
|
||||
$this->fieldValue = "";
|
||||
$this->fieldPostID = 0;
|
||||
|
||||
$this->columnName = "January";
|
||||
$this->columnMonth = 1;
|
||||
|
||||
$this->deletePostID = 0;
|
||||
$this->deleteName = "";
|
||||
|
||||
$this->modalRowUpdate = false;
|
||||
$this->modalFieldUpdate = false;
|
||||
$this->modalColumnUpdate = false;
|
||||
$this->modalDelete = false;
|
||||
|
||||
$this->copyYear = 0;
|
||||
$this->copyMethod = "full";
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
$this->activeMonths = \Auth::user()->activeMonths($this->year);
|
||||
$this->activeMonthCount = 0;
|
||||
foreach($this->activeMonths as $month) {
|
||||
if($month) {
|
||||
$this->activeMonthCount++;
|
||||
}
|
||||
}
|
||||
|
||||
$categories = \App\Models\Category::with(["posts" => function($query) {
|
||||
$query->where("year", $this->year);
|
||||
}])->where("user_id", \Auth::user()->id)->orderBy("priority")->get();
|
||||
|
||||
$yearList = [];
|
||||
if(!\Auth::user()->hasPosts($this->year)) {
|
||||
$results = \DB::select(
|
||||
\DB::raw("SELECT DISTINCT posts.year
|
||||
FROM posts
|
||||
INNER JOIN categories ON posts.category_id = categories.id
|
||||
WHERE
|
||||
categories.user_id = :user_id
|
||||
ORDER BY posts.year DESC"),
|
||||
array('user_id' => \Auth::user()->id));
|
||||
foreach($results as $result) {
|
||||
if($this->copyYear == 0) {
|
||||
$this->copyYear = $result->year;
|
||||
}
|
||||
$yearList[] = $result->year;
|
||||
}
|
||||
}
|
||||
|
||||
$hf = new \App\Http\Livewire\Helper();
|
||||
|
||||
return view('livewire.projected', ['categories' => $categories, 'yearList' => $yearList, 'hf' => $hf]);
|
||||
}
|
||||
|
||||
public function openDelete() {
|
||||
$post = \App\Models\Post::whereHas('category', function ($query) {
|
||||
return $query->where('user_id', \Auth::user()->id);
|
||||
})->where("id", $this->rowPostID)->first();
|
||||
|
||||
if($post) {
|
||||
$this->deletePostID = $post->id;
|
||||
$this->deleteName = $post->name;
|
||||
$this->modalDelete = true;
|
||||
$this->modalRowUpdate = false;
|
||||
}
|
||||
}
|
||||
|
||||
public function deletePost() {
|
||||
$post = \App\Models\Post::whereHas('category', function ($query) {
|
||||
return $query->where('user_id', \Auth::user()->id);
|
||||
})->where("id", $this->deletePostID)->first();
|
||||
|
||||
if($post) {
|
||||
$post->delete();
|
||||
$this->emitTo('actual', '$refresh');
|
||||
}
|
||||
$this->modalDelete = false;
|
||||
}
|
||||
|
||||
public function closeDelete() {
|
||||
$this->modalDelete = false;
|
||||
}
|
||||
|
||||
public function openColumnUpdate($month) {
|
||||
$this->columnName = ["-", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][$month];
|
||||
$this->columnMonth = $month;
|
||||
$this->modalColumnUpdate = true;
|
||||
}
|
||||
|
||||
public function updateColumn() {
|
||||
$categories = \App\Models\Category::where("user_id", \Auth::user()->id)->orderBy("priority")->get();
|
||||
foreach($categories as $category) {
|
||||
foreach($category->posts->where("year", $this->year) as $post) {
|
||||
$value = \App\Models\PostValue::where("post_id", $post->id)->where("month", $this->columnMonth)->first();
|
||||
if($value != null) {
|
||||
$value->delete();
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->emitTo('actual', '$refresh');
|
||||
$this->modalColumnUpdate = false;
|
||||
}
|
||||
|
||||
public function closeColumnUpdate() {
|
||||
$this->modalColumnUpdate = false;
|
||||
}
|
||||
|
||||
public function openFieldUpdate($id, $month) {
|
||||
$post = \App\Models\Post::whereHas('category', function ($query) {
|
||||
return $query->where('user_id', \Auth::user()->id);
|
||||
})->where("id", $id)->first();
|
||||
|
||||
if($post) {
|
||||
$this->fieldPostID = $post->id;
|
||||
$this->fieldName = $post->name;
|
||||
$this->fieldTypeHTML = "<span class=\"".($post->is_expense ? "col-neg" : "col-pos")."\">".($post->is_expense ? "expense" : "income")."</span>";
|
||||
$this->fieldMonth = $month;
|
||||
$this->fieldMonthName = ["-", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"][$month];
|
||||
$this->fieldValue = $post->monthValue($month) * ($post->is_expense ? -1.00 : 1.00);
|
||||
if($this->fieldValue == "-0") {
|
||||
$this->fieldValue = "0";
|
||||
}
|
||||
$this->modalFieldUpdate = true;
|
||||
$this->emit("focusField", "fieldValue");
|
||||
}
|
||||
}
|
||||
|
||||
public function updateField() {
|
||||
$post = \App\Models\Post::whereHas('category', function ($query) {
|
||||
return $query->where('user_id', \Auth::user()->id);
|
||||
})->where("id", $this->fieldPostID)->first();
|
||||
|
||||
$value = null;
|
||||
if($this->fieldValue != null && trim($this->fieldValue) != "" && is_numeric(trim($this->fieldValue))) {
|
||||
$value = floatval($this->fieldValue);
|
||||
}
|
||||
|
||||
if($post != null && $value !== null) {
|
||||
$post->setMonthValue($this->fieldMonth, $value);
|
||||
}
|
||||
$this->emitTo('actual', '$refresh');
|
||||
$this->modalFieldUpdate = false;
|
||||
}
|
||||
|
||||
public function closeFieldUpdate() {
|
||||
$this->modalFieldUpdate = false;
|
||||
}
|
||||
|
||||
public function openRowUpdate($id) {
|
||||
$post = \App\Models\Post::whereHas('category', function ($query) {
|
||||
return $query->where('user_id', \Auth::user()->id);
|
||||
})->where("id", $id)->first();
|
||||
|
||||
if($post) {
|
||||
$this->rowPostID = $post->id;
|
||||
$this->rowName = $post->name;
|
||||
$this->rowTypeHTML = "<span class=\"".($post->is_expense ? "col-neg" : "col-pos")."\">".($post->is_expense ? "expense" : "income")."</span>";
|
||||
$this->modalRowUpdate = true;
|
||||
$this->emit("focusField", "rowValue");
|
||||
}
|
||||
}
|
||||
|
||||
public function updateRow() {
|
||||
$post = \App\Models\Post::whereHas('category', function ($query) {
|
||||
return $query->where('user_id', \Auth::user()->id);
|
||||
})->where("id", $this->rowPostID)->first();
|
||||
|
||||
$value = null;
|
||||
if($this->rowValue != null && trim($this->rowValue) != "" && is_numeric(trim($this->rowValue))) {
|
||||
$value = floatval($this->rowValue);
|
||||
}
|
||||
|
||||
if($post != null && $value !== null) {
|
||||
for($m=1;$m<=12;$m++) {
|
||||
$post->setMonthValue($m, $value);
|
||||
}
|
||||
}
|
||||
$this->emitTo('actual', '$refresh');
|
||||
$this->rowValue = "";
|
||||
$this->modalRowUpdate = false;
|
||||
}
|
||||
|
||||
public function closeRowUpdate() {
|
||||
$this->modalRowUpdate = false;
|
||||
}
|
||||
|
||||
public function createPost() {
|
||||
if(trim($this->createName) == "") {
|
||||
$this->createName = ""; return;
|
||||
}
|
||||
|
||||
$category = \App\Models\Category::where("user_id", \Auth::user()->id)->where("id", $this->createCategoryID)->first();
|
||||
if($category == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
$expense = $this->createType != "income";
|
||||
|
||||
$post = new \App\Models\Post();
|
||||
$post->year = $this->year;
|
||||
$post->name = trim($this->createName);
|
||||
$post->is_expense = $expense;
|
||||
$post->category_id = $this->createCategoryID;
|
||||
$post->save();
|
||||
|
||||
$this->createName = "";
|
||||
$this->emitTo('actual', '$refresh');
|
||||
$this->emit("focusField", "createName");
|
||||
}
|
||||
|
||||
public function copyBudget() {
|
||||
$categories = \App\Models\Category::where("user_id", \Auth::user()->id)->orderBy("priority")->get();
|
||||
foreach($categories as $category) {
|
||||
foreach($category->posts->where("year", $this->copyYear) as $post) {
|
||||
$newPost = new \App\Models\Post();
|
||||
$newPost->category_id = $category->id;
|
||||
$newPost->year = $this->year;
|
||||
$newPost->name = $post->name;
|
||||
$newPost->is_expense = $post->is_expense;
|
||||
$newPost->save();
|
||||
|
||||
if($this->copyMethod == "full") {
|
||||
for($m=1; $m <= 12; $m++) {
|
||||
$newPost->setMonthValue($m, $post->monthValue($m) * ($newPost->is_expense ? -1.00 : 1.00));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->emitTo('actual', '$refresh');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user