From 8be047875002c9d1ecffd7d5006c7402fe159af9 Mon Sep 17 00:00:00 2001 From: Jesus Guerrero Date: Thu, 7 Dec 2023 09:53:28 -0400 Subject: [PATCH 1/2] feat: add migrations --- .../2023_12_07_120516_add_accounts_balance_in_month.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/database/migrations/2023_12_07_120516_add_accounts_balance_in_month.php b/database/migrations/2023_12_07_120516_add_accounts_balance_in_month.php index d21d5d32..7de20190 100644 --- a/database/migrations/2023_12_07_120516_add_accounts_balance_in_month.php +++ b/database/migrations/2023_12_07_120516_add_accounts_balance_in_month.php @@ -13,6 +13,8 @@ public function up(): void { Schema::table('budget_months', function (Blueprint $table) { $table->decimal('accounts_balance')->default(0)->after('left_from_last_month'); + $table->decimal('overspending_from_last_month')->default(0); + $table->json('meta_data')->nullable(); }); } }; From 0e8b799d925682d57a2296a4dfe4e6582f119be9 Mon Sep 17 00:00:00 2001 From: Jesus Guerrero Date: Sun, 10 Dec 2023 15:07:41 -0400 Subject: [PATCH 2/2] fix: meal issues --- app/Domains/Meal/Models/Meal.php | 17 +-- app/Domains/Meal/Services/MealService.php | 27 +++- .../Api/IngredientApiController.php | 22 ++- resources/js/Components/icons/IconBell.vue | 8 +- .../molecules/AppNotificationBell.vue | 24 ++-- resources/js/Pages/Finance/Account.vue | 61 +------- .../Finance/AccountReconciliationForm.vue | 134 ++++++++++++++++++ resources/js/Pages/Meals/Create.vue | 35 +++-- resources/js/Pages/Meals/Index.vue | 5 +- resources/js/Pages/Meals/Ingredients.vue | 3 + resources/js/Pages/Meals/Planner.vue | 1 + .../js/domains/meal/components/MealForm.vue | 29 ++-- .../domains/meal/components/MealSection.vue | 44 +++--- .../transactions/models/transactions.ts | 1 + 14 files changed, 260 insertions(+), 151 deletions(-) create mode 100644 resources/js/Pages/Finance/AccountReconciliationForm.vue diff --git a/app/Domains/Meal/Models/Meal.php b/app/Domains/Meal/Models/Meal.php index a8eb88dc..12dfb207 100644 --- a/app/Domains/Meal/Models/Meal.php +++ b/app/Domains/Meal/Models/Meal.php @@ -2,9 +2,9 @@ namespace App\Domains\Meal\Models; -use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Insane\Journal\Models\Product\Product; +use Illuminate\Database\Eloquent\Factories\HasFactory; class Meal extends Model { @@ -26,11 +26,12 @@ public function saveIngredients($items) { Ingredient::query()->where('meal_id', $this->id)->delete(); foreach ($items as $item) { - if (isset($item['product_id']) && $item['product_id'] !== "new::{$item['name']}") { + if (isset($item['product_id']) && !str_contains($item['product_id'], "new::")) { $product = Product::find($item['product_id']); - } elseif (isset($item['name'])) { - $product = Product::create([ - 'name' => $item['name'], + } else { + $ingredientName = str_replace("new::", "", $item['product_id']); + $product = Product::firstOrCreate([ + 'name' => $ingredientName, 'team_id' => $this->team_id, 'user_id' => $this->user_id, ]); @@ -40,9 +41,9 @@ public function saveIngredients($items) 'user_id' => $this->user_id, 'meal_id' => $this->id, 'product_id' => $product->id, - 'quantity' => $item['quantity'], - 'name' => $item['name'], - 'unit' => $item['unit'], + 'quantity' => $item['quantity'] ?? 1, + 'name' => $product->name, + 'unit' => $item['unit'] ?? "", ]); } } diff --git a/app/Domains/Meal/Services/MealService.php b/app/Domains/Meal/Services/MealService.php index 28d186d1..c406660d 100644 --- a/app/Domains/Meal/Services/MealService.php +++ b/app/Domains/Meal/Services/MealService.php @@ -2,21 +2,23 @@ namespace App\Domains\Meal\Services; -use App\Domains\AppCore\Models\Planner; +use App\Models\User; +use Illuminate\Support\Carbon; use App\Domains\Meal\Models\Meal; +use App\Domains\Meal\Models\Product; use App\Domains\Meal\Models\MealPlan; -use Illuminate\Support\Carbon; +use App\Domains\AppCore\Models\Planner; class MealService { public function addPlan($mealsData) { foreach ($mealsData['meals'] as $mealData) { - if (isset($mealData['id']) && $mealData['id'] !== "new::{$mealData['name']}") { + if (isset($mealData['id']) && !str_contains($mealData['id'],"new::")) { $meal = Meal::find($mealData['id']); } elseif (isset($mealData['name'])) { $meal = Meal::create([ - 'name' => $mealData['name'], + 'name' => str_replace("new::", "", $mealData['name']), 'meal_type_id' => $mealData['meal_type_id'], 'team_id' => $mealsData['team_id'], 'user_id' => $mealsData['user_id'], @@ -106,4 +108,21 @@ public static function getIngredients($plans) return $ingredients; } + + public function addIngredientLabel(Product $product, mixed $postData, User $user) { + if (!str_contains($postData['label_id'], "new::")) { + $label = $product->labels()->find($postData['label_id']); + } else { + $labelName = str_replace("new::", "", $postData['label_id']); + $label = $product->labels()->create([ + 'user_id' => $user->id, + 'team_id' => $user->current_team_id, + 'name' => $labelName, + 'label' => $labelName, + 'color' => $postData['color'] ?? "", + ]); + } + + return $label; + } } diff --git a/app/Http/Controllers/Api/IngredientApiController.php b/app/Http/Controllers/Api/IngredientApiController.php index a42fabfb..914fea47 100644 --- a/app/Http/Controllers/Api/IngredientApiController.php +++ b/app/Http/Controllers/Api/IngredientApiController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Api; use App\Domains\Meal\Models\Product; +use App\Domains\Meal\Services\MealService; class IngredientApiController extends BaseController { @@ -14,21 +15,14 @@ public function __construct() $this->includes = ['labels']; } - public function addLabel($id) + public function addLabel($id, MealService $mealService) { - $postData = request()->post(); - $product = $this->model->find($id); - if ($postData['label_id'] !== "new::{$postData['name']}") { - $label = $product->labels()->find($postData['label_id']); - } else { - $label = $product->labels()->create([ - 'user_id' => auth()->user()->id, - 'team_id' => auth()->user()->current_team_id, - 'name' => $postData['name'], - 'label' => $postData['name'], - 'color' => $postData['color'], - ]); - } + $product = $this->model->find($id); + $label = $mealService->addIngredientLabel( + $product, + request()->post(), + request()->user() + ); return response()->json(['label' => $label]); } diff --git a/resources/js/Components/icons/IconBell.vue b/resources/js/Components/icons/IconBell.vue index 896e1611..a54e6d5c 100644 --- a/resources/js/Components/icons/IconBell.vue +++ b/resources/js/Components/icons/IconBell.vue @@ -1,10 +1,4 @@ - - + diff --git a/resources/js/Components/molecules/AppNotificationBell.vue b/resources/js/Components/molecules/AppNotificationBell.vue index 91781cc0..6bee4f71 100644 --- a/resources/js/Components/molecules/AppNotificationBell.vue +++ b/resources/js/Components/molecules/AppNotificationBell.vue @@ -1,15 +1,4 @@ - - - + + diff --git a/resources/js/Pages/Finance/Account.vue b/resources/js/Pages/Finance/Account.vue index 380e15ed..9ec0551d 100644 --- a/resources/js/Pages/Finance/Account.vue +++ b/resources/js/Pages/Finance/Account.vue @@ -22,13 +22,14 @@ import TransactionSearch from "@/domains/transactions/components/TransactionSear import TransactionTable from "@/domains/transactions/components/TransactionTable.vue"; import DraftButtons from "@/domains/transactions/components/DraftButtons.vue"; -import { useTransactionModal, TRANSACTION_DIRECTIONS } from "@/domains/transactions"; +import { useTransactionModal, TRANSACTION_DIRECTIONS, removeTransaction } from "@/domains/transactions"; // import { IServerSearchData, useServerSearch } from "@/composables/useServerSearch"; import { tableAccountCols } from "@/domains/transactions"; import { useAppContextStore } from "@/store"; import { formatMoney } from "@/utils"; import { IAccount, ICategory, ITransaction } from "@/domains/transactions/models"; import axios from "axios"; +import AccountReconciliationForm from "./AccountReconciliationForm.vue"; const { openTransactionModal } = useTransactionModal(); @@ -260,63 +261,11 @@ const reconcileForm = useForm({ /> - - - - - - + :account="selectedAccount" + /> diff --git a/resources/js/Pages/Finance/AccountReconciliationForm.vue b/resources/js/Pages/Finance/AccountReconciliationForm.vue new file mode 100644 index 00000000..4a3d73e9 --- /dev/null +++ b/resources/js/Pages/Finance/AccountReconciliationForm.vue @@ -0,0 +1,134 @@ + + + diff --git a/resources/js/Pages/Meals/Create.vue b/resources/js/Pages/Meals/Create.vue index 39987d81..deef7088 100644 --- a/resources/js/Pages/Meals/Create.vue +++ b/resources/js/Pages/Meals/Create.vue @@ -1,29 +1,35 @@