### `project_items.retail_price`: (now updating in prod)
Stores price * quantity instead of always calculating it on the fly.
### `project_items.ceiling_price`: (now updating in prod)
Stored as a rounded ceiling price.
For example, with a 5% marketing discount, $49.33 * 95% = 46.8635, stored as $46.86
### `project_items.marketing_discount_price`: (now updating in prod)
We have to round the marketing_discount_price, to the penny. We don’t want to keep hidden penny fragments in the db for this column.
### `project_product_prices.retail_amount`: (now updating in prod)
Sum of all the items retail prices for that product
### `project_product_prices.adjustment_amount`: (now updating in prod)
Sum of all the adjustments for that product
### `project_items.adjusted_marketing_discount_price`: (now updating in prod)
This column will represent the marketing discount price with all of the project adjustments have been factored in. (See steps in project_items.commissionable_sale_amount section)
### `finance_projects.commissionable_finance_discount_amount`: (now updating in prod)
Store this to calculate finance discount percentages on the fly. It will store the result of the existing `loan_buydown_amount` function in `finance_project.rb`.
```ruby
def loan_buydown_amount
loan_applications.approved_or_funded.to_a.sum do |app|
(app.usage_amount.to_f * (app.loan_plan.buydown_percentage_on(app.created_at).to_f / 100.0))
end
end
```
### `project_items.commissionable_sale_amount`:
What does this look like?
1. A project updates =>
2. Set all the retail_prices, ceiling_prices, & marketing_discount_prices on each project_item =>
3. Sum retail prices for the project_item's product and store it as `project_product_prices.retail_amount`.
4. Derive Item to Product Weight = ( `project_items.retail_price` / `project_product_prices.retail_amount` )
5. Derive total_product_adjustment from the adjustments table and stamp it on `project_product_prices` records.
6. adjusted_marketing_discount_price = marketing_discount_price + (item_to_product_weight * project_product_prices.adjustment_amount)
7. Sum up the `project_items.adjusted_marketing_discount_price`s to get the `projects.customer_price`
8. Derive Item to Project Weight = (adjusted_marketing_discount_price/projects.customer_price)
9. project_items.commissionable_sale_amount = adjusted_marketing_discount_price - ( loan_buydown * item_to_project_weight)
### `projects.customer_price`: (now updating in prod)
We need to store the new project_price based on the sum of all the `project_items.adjusted_marketing_discount_prices`.
Talked to Tim, this is the column name he wanted.