diff --git a/app/controllers/credit_card_bills_controller.rb b/app/controllers/credit_card_bills_controller.rb new file mode 100644 index 0000000..8c41a88 --- /dev/null +++ b/app/controllers/credit_card_bills_controller.rb @@ -0,0 +1,70 @@ +class CreditCardBillsController < ApplicationController + before_action :set_credit_card_bill, only: %i[ show edit update destroy ] + + # GET /credit_card_bills or /credit_card_bills.json + def index + @credit_card_bills = CreditCardBill.all + end + + # GET /credit_card_bills/1 or /credit_card_bills/1.json + def show + end + + # GET /credit_card_bills/new + def new + @credit_card_bill = CreditCardBill.new + end + + # GET /credit_card_bills/1/edit + def edit + end + + # POST /credit_card_bills or /credit_card_bills.json + def create + @credit_card_bill = CreditCardBill.new(credit_card_bill_params) + + respond_to do |format| + if @credit_card_bill.save + format.html { redirect_to credit_card_bill_url(@credit_card_bill), notice: "Credit card bill was successfully created." } + format.json { render :show, status: :created, location: @credit_card_bill } + else + format.html { render :new, status: :unprocessable_entity } + format.json { render json: @credit_card_bill.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /credit_card_bills/1 or /credit_card_bills/1.json + def update + respond_to do |format| + if @credit_card_bill.update(credit_card_bill_params) + format.html { redirect_to credit_card_bill_url(@credit_card_bill), notice: "Credit card bill was successfully updated." } + format.json { render :show, status: :ok, location: @credit_card_bill } + else + format.html { render :edit, status: :unprocessable_entity } + format.json { render json: @credit_card_bill.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /credit_card_bills/1 or /credit_card_bills/1.json + def destroy + @credit_card_bill.destroy + + respond_to do |format| + format.html { redirect_to credit_card_bills_url, notice: "Credit card bill was successfully destroyed." } + format.json { head :no_content } + end + end + + private + # Use callbacks to share common setup or constraints between actions. + def set_credit_card_bill + @credit_card_bill = CreditCardBill.find(params[:id]) + end + + # Only allow a list of trusted parameters through. + def credit_card_bill_params + params.require(:credit_card_bill).permit(:description, :amount) + end +end diff --git a/app/controllers/expenses_controller.rb b/app/controllers/expenses_controller.rb index c88513d..34fb814 100644 --- a/app/controllers/expenses_controller.rb +++ b/app/controllers/expenses_controller.rb @@ -65,6 +65,6 @@ class ExpensesController < ApplicationController # Only allow a list of trusted parameters through. def expense_params - params.require(:expense).permit(:description, :payment, :period, :autopaid, :estimated) + params.require(:expense).permit(:description, :payment, :period, :credit_card, :estimated) end end diff --git a/app/controllers/extra_bills_controller.rb b/app/controllers/extra_bills_controller.rb deleted file mode 100644 index 3caed45..0000000 --- a/app/controllers/extra_bills_controller.rb +++ /dev/null @@ -1,70 +0,0 @@ -class ExtraBillsController < ApplicationController - before_action :set_extra_bill, only: %i[ show edit update destroy ] - - # GET /extra_bills or /extra_bills.json - def index - @extra_bills = ExtraBill.all - end - - # GET /extra_bills/1 or /extra_bills/1.json - def show - end - - # GET /extra_bills/new - def new - @extra_bill = ExtraBill.new - end - - # GET /extra_bills/1/edit - def edit - end - - # POST /extra_bills or /extra_bills.json - def create - @extra_bill = ExtraBill.new(extra_bill_params) - - respond_to do |format| - if @extra_bill.save - format.html { redirect_to extra_bill_url(@extra_bill), notice: "Extra bill was successfully created." } - format.json { render :show, status: :created, location: @extra_bill } - else - format.html { render :new, status: :unprocessable_entity } - format.json { render json: @extra_bill.errors, status: :unprocessable_entity } - end - end - end - - # PATCH/PUT /extra_bills/1 or /extra_bills/1.json - def update - respond_to do |format| - if @extra_bill.update(extra_bill_params) - format.html { redirect_to extra_bill_url(@extra_bill), notice: "Extra bill was successfully updated." } - format.json { render :show, status: :ok, location: @extra_bill } - else - format.html { render :edit, status: :unprocessable_entity } - format.json { render json: @extra_bill.errors, status: :unprocessable_entity } - end - end - end - - # DELETE /extra_bills/1 or /extra_bills/1.json - def destroy - @extra_bill.destroy - - respond_to do |format| - format.html { redirect_to extra_bills_url, notice: "Extra bill was successfully destroyed." } - format.json { head :no_content } - end - end - - private - # Use callbacks to share common setup or constraints between actions. - def set_extra_bill - @extra_bill = ExtraBill.find(params[:id]) - end - - # Only allow a list of trusted parameters through. - def extra_bill_params - params.require(:extra_bill).permit(:description, :amount, :deduct_autopaid) - end -end diff --git a/app/models/credit_card_bill.rb b/app/models/credit_card_bill.rb new file mode 100644 index 0000000..9d90972 --- /dev/null +++ b/app/models/credit_card_bill.rb @@ -0,0 +1,5 @@ +class CreditCardBill < ApplicationRecord + def unpaid + amount - Expense.credit_card_monthly_total + end +end diff --git a/app/models/expense.rb b/app/models/expense.rb index b40b49d..3e38e34 100644 --- a/app/models/expense.rb +++ b/app/models/expense.rb @@ -19,7 +19,7 @@ class Expense < ApplicationRecord Expense.all.map(&:monthly).sum.round(2) end - def self.autopaid_total - Expense.where(autopaid: true).map(&:monthly).sum.round(2) + def self.credit_card_monthly_total + Expense.where(credit_card: true).map(&:monthly).sum.round(2) end end diff --git a/app/models/extra_bill.rb b/app/models/extra_bill.rb deleted file mode 100644 index 95d1845..0000000 --- a/app/models/extra_bill.rb +++ /dev/null @@ -1,5 +0,0 @@ -class ExtraBill < ApplicationRecord - def adjusted_amount - deduct_autopaid? ? amount - Expense.autopaid_total : amount - end -end diff --git a/app/views/extra_bills/_extra_bill.html.erb b/app/views/credit_card_bills/_credit_card_bill.html.erb similarity index 66% rename from app/views/extra_bills/_extra_bill.html.erb rename to app/views/credit_card_bills/_credit_card_bill.html.erb index e077fb7..df91f34 100644 --- a/app/views/extra_bills/_extra_bill.html.erb +++ b/app/views/credit_card_bills/_credit_card_bill.html.erb @@ -1,27 +1,22 @@ -
Description: - <%= extra_bill.description %> + <%= credit_card_bill.description %>
Amount: - <%= extra_bill.amount %> -
- -- Adjusted Amount: - <%= extra_bill.adjusted_amount %> + <%= credit_card_bill.amount %>
Accounted For: - <%= Expense.autopaid_total %> + <%= Expense.credit_card_monthly_total %>
- Deduct autopaid: - <%= extra_bill.deduct_autopaid %> + Unpaid: + <%= credit_card_bill.unpaid %>
@@ -38,7 +33,7 @@
<%= notice %>
+ <% end %> + +<%= notice %>
+ <% end %> + + <%= render @credit_card_bill %> + + <%= link_to 'Edit this credit_card_bill', edit_credit_card_bill_path(@credit_card_bill), class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> +- Autopaid: - <%= expense.autopaid %> + Credit card: + <%= expense.credit_card %>
diff --git a/app/views/expenses/_expense.json.jbuilder b/app/views/expenses/_expense.json.jbuilder index 216ad4e..964a52e 100644 --- a/app/views/expenses/_expense.json.jbuilder +++ b/app/views/expenses/_expense.json.jbuilder @@ -1,2 +1,2 @@ -json.extract! expense, :id, :description, :payment, :period, :autopaid, :estimated, :created_at, :updated_at +json.extract! expense, :id, :description, :payment, :period, :credit_card, :estimated, :created_at, :updated_at json.url expense_url(expense, format: :json) diff --git a/app/views/expenses/_form.html.erb b/app/views/expenses/_form.html.erb index 0630871..766faec 100644 --- a/app/views/expenses/_form.html.erb +++ b/app/views/expenses/_form.html.erb @@ -32,8 +32,8 @@
<%= notice %>
- <% end %> - -<%= notice %>
- <% end %> - - <%= render @extra_bill %> - - <%= link_to 'Edit this extra_bill', edit_extra_bill_path(@extra_bill), class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %> -