smerp-quotation-engine 0.1.5 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (26) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/smerp/quotation/engine/quotation_item_distributions_controller.rb +95 -0
  3. data/app/controllers/smerp/quotation/engine/quotation_items_controller.rb +6 -1
  4. data/app/controllers/smerp/quotation/engine/quotation_products_controller.rb +1 -2
  5. data/app/helpers/smerp/quotation/engine/quotation_item_distributions_helper.rb +14 -0
  6. data/app/helpers/smerp/quotation/engine/quotation_items_helper.rb +28 -0
  7. data/app/helpers/smerp/quotation/engine/quotations_helper.rb +12 -12
  8. data/app/models/smerp/quotation/engine/quotation_item.rb +2 -0
  9. data/app/models/smerp/quotation/engine/quotation_item_distribution.rb +6 -0
  10. data/app/views/smerp/quotation/engine/quotation_item_distributions/_form.html.erb +71 -0
  11. data/app/views/smerp/quotation/engine/quotation_item_distributions/_quotation_item.html.erb +29 -0
  12. data/app/views/smerp/quotation/engine/quotation_item_distributions/_quotation_item_distribution.html.erb +2 -0
  13. data/app/views/smerp/quotation/engine/quotation_item_distributions/edit.html.erb +10 -0
  14. data/app/views/smerp/quotation/engine/quotation_item_distributions/index.html.erb +14 -0
  15. data/app/views/smerp/quotation/engine/quotation_item_distributions/new.html.erb +9 -0
  16. data/app/views/smerp/quotation/engine/quotation_item_distributions/show.html.erb +10 -0
  17. data/app/views/smerp/quotation/engine/quotation_items/_quotation_item.html.erb +28 -11
  18. data/app/views/smerp/quotation/engine/quotation_items/distribute.html.erb +47 -0
  19. data/app/views/smerp/quotation/engine/quotation_products/_quotation_product.html.erb +0 -1
  20. data/app/views/smerp/quotation/engine/quotation_products/index.html.erb +2 -5
  21. data/app/views/smerp/quotation/engine/quotations/_quotation_item.html.erb +80 -7
  22. data/app/views/smerp/quotation/engine/quotations/show.html.erb +3 -0
  23. data/config/routes.rb +6 -0
  24. data/lib/smerp/quotation/engine/version.rb +1 -1
  25. metadata +33 -23
  26. data/app/views/smerp/quotation/engine/_new_quotation_item_form.html.erb +0 -48
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 32de6281378bf9d836b4b7cdd1a32ed952e1e0cfdc4127aae6f4c569f5b02e1f
4
- data.tar.gz: 1d9ad81ffb2aca437e9aa78de0e66dd6f9cfb95a865c5e997b51a7af95f6edd0
3
+ metadata.gz: '078b0b00dc1fa24d1c265ed3e8376f747db91b6664358915686ea7eaea2e4404'
4
+ data.tar.gz: cdc5d36de1c87ce2a2a916b0573e4d34b1966110d224a6b40352a8906e54f351
5
5
  SHA512:
6
- metadata.gz: 3ae01c0cad4ccb9b1b7445a979ec872f2cc7a2b6210e1cb695040007d96e71d613cf0e39eaa08cd0174966a319a6c31e215e0d64153b9a90d8bd5a2d5c3a00dc
7
- data.tar.gz: b224635e6c4c96660f637b12c1ce6c51e134d8a40bb8d1ebde9215d297d6fc3d830c5fc80dac81608559be6c16d2f4d8a73027a40dcace54463036f6b2f72a91
6
+ metadata.gz: 2e5d50a0b5d0b0c0d819cd86b6bc42077260394cb84e8dbb9a8c43cd0088f68a34b41d8c27611da9ef5dd9f699b54149a887b2b3131b7a6a314db19e1f0223cf
7
+ data.tar.gz: 6b3f0dba38911e1d852e3dc40b388e92438c247931be0eeff4f532d6d8a4dc9c36f3cf899d33cde71190827e00ea8ec950f7a59b4ce6ca6150cdca39da5ce2fd
@@ -0,0 +1,95 @@
1
+ module Smerp::Quotation::Engine
2
+ class QuotationItemDistributionsController < ApplicationController
3
+
4
+ before_action :set_quotation_item
5
+ before_action :set_quotation_item_distribution, only: %i[ show edit update destroy ]
6
+
7
+ def set_quotation_item
8
+ #@quotation_item = QuotationItem.find(params[:id])
9
+ #@quotation = @quotation_item.quotation
10
+ end
11
+
12
+ # GET /quotation_item_distributions
13
+ def index
14
+ @quotation_item_distributions = QuotationItemDistribution.all
15
+ end
16
+
17
+ # GET /quotation_item_distributions/1
18
+ def show
19
+ end
20
+
21
+ # GET /quotation_item_distributions/new
22
+ def new
23
+ @quotation_item = QuotationItem.find(params[:source_quotation_item])
24
+ @quotation = @quotation_item.quotation
25
+ @quotation_item_distribution = QuotationItemDistribution.new
26
+ end
27
+
28
+ # GET /quotation_item_distributions/1/edit
29
+ def edit
30
+ end
31
+
32
+ # POST /quotation_item_distributions
33
+ def create
34
+ #@quotation_item_distribution = QuotationItemDistribution.new(quotation_item_distribution_params)
35
+
36
+ qi = QuotationItem.find(params[:quotation_item_distribution][:quotation_item_id])
37
+
38
+ if not params[:quotation_item_distribution].nil? and not params[:quotation_item_distribution][:quantum].nil?
39
+ params[:quotation_item_distribution][:quantum].each do |k,v|
40
+
41
+ vv = v.first
42
+ indx = vv =~ /p/
43
+ if indx.nil?
44
+ val = vv.to_f
45
+ next if val == 0
46
+ else
47
+ val = vv[0...indx].to_f.percent
48
+ next if val.rep_value == 0
49
+ end
50
+
51
+ dest = QuotationItem.find(k)
52
+ qi.distribute_to(dest, val)
53
+
54
+ end
55
+ end
56
+
57
+ redirect_to quotation_path(qi.quotation), notice: "Distribution saved"
58
+
59
+ #if @quotation_item_distribution.save
60
+ # redirect_to @quotation_item_distribution, notice: "Quotation item distribution was successfully created."
61
+ #else
62
+ # render :new, status: :unprocessable_entity
63
+ #end
64
+ end
65
+
66
+ # PATCH/PUT /quotation_item_distributions/1
67
+ def update
68
+ if @quotation_item_distribution.update(quotation_item_distribution_params)
69
+ redirect_to @quotation_item_distribution, notice: "Quotation item distribution was successfully updated."
70
+ else
71
+ render :edit, status: :unprocessable_entity
72
+ end
73
+ end
74
+
75
+ # DELETE /quotation_item_distributions/1
76
+ def destroy
77
+ @quotation_item = @quotation_item_distribution.quotation_item
78
+ @quotation_item_distribution.destroy
79
+ #redirect_to quotation_item_distributions_url, notice: "Quotation item distribution was successfully destroyed."
80
+ redirect_to quotation_path(@quotation_item.quotation), notice: "Quotation item distribution was successfully destroyed."
81
+ end
82
+
83
+ private
84
+ # Use callbacks to share common setup or constraints between actions.
85
+ def set_quotation_item_distribution
86
+ @quotation_item_distribution = QuotationItemDistribution.find(params[:id])
87
+ end
88
+
89
+ # Only allow a list of trusted parameters through.
90
+ def quotation_item_distribution_params
91
+ params.fetch(:quotation_item_distribution, {})
92
+ #params.require(:quotation_item_distribution).permit()
93
+ end
94
+ end
95
+ end
@@ -4,7 +4,7 @@ module Smerp::Quotation::Engine
4
4
  include TR::CondUtils
5
5
 
6
6
  before_action :find_parent
7
- before_action :set_quotation_item, only: %i[ show edit update destroy apply_discount remove_tax add_sub_item apply_tax hide_children show_children new_product_item ]
7
+ before_action :set_quotation_item, only: %i[ show edit update destroy apply_discount remove_tax add_sub_item apply_tax hide_children show_children new_product_item distribute ]
8
8
 
9
9
  def find_parent
10
10
  if params[:quotation_item].nil?
@@ -222,6 +222,11 @@ module Smerp::Quotation::Engine
222
222
  @quotation_item = QuotationItem.new
223
223
  end
224
224
 
225
+ def distribute
226
+ @quotation = @quotation_item.quotation
227
+ #redirect_to quotation_url(@quotation_item.quotation)
228
+ end
229
+
225
230
  private
226
231
  # Use callbacks to share common setup or constraints between actions.
227
232
  def set_quotation_item
@@ -25,8 +25,7 @@ module Smerp::Quotation::Engine
25
25
  @quotation_product = QuotationProduct.new(quotation_product_params)
26
26
 
27
27
  if @quotation_product.save
28
- #redirect_to @quotation_product, notice: "Quotation product was successfully created."
29
- redirect_to quotation_products_path, notice: "Quotation product was successfully created."
28
+ redirect_to @quotation_product, notice: "Quotation product was successfully created."
30
29
  else
31
30
  render :new, status: :unprocessable_entity
32
31
  end
@@ -0,0 +1,14 @@
1
+ module Smerp::Quotation::Engine
2
+ module QuotationItemDistributionsHelper
3
+
4
+ def distribution_params(paramVal)
5
+ case paramVal
6
+ when Smerp::Common::FinUtils::Percent
7
+ "#{paramVal.value}%"
8
+ else
9
+ "#{currency(paramVal)}"
10
+ end
11
+ end
12
+
13
+ end
14
+ end
@@ -1,4 +1,32 @@
1
1
  module Smerp::Quotation::Engine
2
2
  module QuotationItemsHelper
3
+
4
+ def render_item_tree_table(itm, level = 1, indx = 0)
5
+ cont = []
6
+ level += 1
7
+ indx = 0
8
+ if session[:hide_children_parent_id].nil? or not session[:hide_children_parent_id].include?(itm.id)
9
+ itm.children.each do |c|
10
+ cont << render("quotation_item", quotation_item: c, level: level, index: indx)
11
+ indx += 1
12
+ cont += render_item_tree_table(c, level, indx)
13
+ end
14
+ end
15
+ cont
16
+
17
+ end
18
+
19
+ def level_marker(level)
20
+ marker = [
21
+ "#DBFED8", #light green
22
+ "#FEF0D8",
23
+ "#D8F8FE",
24
+ "#FED8D8"
25
+ ]
26
+
27
+ marker[level%4]
28
+ end
29
+
30
+
3
31
  end
4
32
  end
@@ -1,19 +1,19 @@
1
1
  module Smerp::Quotation::Engine
2
2
  module QuotationsHelper
3
3
 
4
- def render_item_tree(itm)
5
- cont = []
6
- cont << "<ol type=\"i\">"
7
- itm.children.each do |c|
8
- cont << "<div id=\"quotation_items\">"
9
- cont << render("quotation_item", quotation_item: c)
10
- cont << "</div>"
4
+ #def render_item_tree(itm)
5
+ # cont = []
6
+ # cont << "<ol type=\"i\">"
7
+ # itm.children.each do |c|
8
+ # cont << "<div id=\"quotation_items\">"
9
+ # cont << render("quotation_item", quotation_item: c)
10
+ # cont << "</div>"
11
11
 
12
- cont += render_item_tree(c)
13
- end
14
- cont << "</ol>"
15
- cont
16
- end
12
+ # cont += render_item_tree(c)
13
+ # end
14
+ # cont << "</ol>"
15
+ # cont
16
+ #end
17
17
 
18
18
  def render_item_tree_table(itm, level = 1, indx = 0)
19
19
  cont = []
@@ -8,6 +8,8 @@ module Smerp::Quotation::Engine
8
8
 
9
9
  acts_as_list
10
10
 
11
+ attr_accessor :sel_qi, :quantum
12
+
11
13
  belongs_to :quotation_product, optional: true
12
14
 
13
15
  validates_presence_of :name
@@ -0,0 +1,6 @@
1
+ module Smerp::Quotation::Engine
2
+ class QuotationItemDistribution < Smerp::Quotation::ArModel::QuotationItemDistribution
3
+
4
+ validates_presence_of :quotation_item_id, :distributed_quotation_item_id
5
+ end
6
+ end
@@ -0,0 +1,71 @@
1
+ <%= form_with(model: quotation_item_distribution) do |form| %>
2
+ <% if quotation_item_distribution.errors.any? %>
3
+ <div style="color: red">
4
+ <h2><%= pluralize(quotation_item_distribution.errors.count, "error") %> prohibited this quotation_item_distribution from being saved:</h2>
5
+
6
+ <ul>
7
+ <% quotation_item_distribution.errors.each do |error| %>
8
+ <li><%= error.full_message %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <h4>Source Quotation Item</h4>
15
+ <table class="table">
16
+ <tr>
17
+ <th>Destination Quotation Item</th>
18
+ <th>Line Total</th>
19
+ </tr>
20
+ <tr>
21
+ <td><%= @quotation_item.name %></td>
22
+ <td><%= currency(@quotation_item.line_total) %></td>
23
+ </tr>
24
+ </table>
25
+
26
+ <%= form.hidden_field :quotation_item_id, value: @quotation_item.id %>
27
+
28
+ <h4>Select Destination Quotation Item</h4>
29
+ <table class="table" id="details">
30
+
31
+ <tr>
32
+ <th width="38%">Name</th>
33
+ <th class="text-center">Quantity</th>
34
+ <th class="text-center">Unit</th>
35
+ <th class="text-end">Unit Price</th>
36
+ <th class="text-end">Line Total</th>
37
+ <th width="138px;">&nbsp;</th>
38
+ </tr>
39
+
40
+ <% indx = 0 %>
41
+ <% @quotation.quotation_items.where(["parent_id is null"]).each do |i| %>
42
+
43
+ <% next if i.id == @quotation_item.id %>
44
+
45
+ <%= render "quotation_item", quotation_item: i, level: 0, index: indx, f: form %>
46
+
47
+ <% indx += 1 %>
48
+
49
+ <% iindx = 0 %>
50
+ <% i.children.each do |c| %>
51
+ <%= render "quotation_item", quotation_item: c, level: 1, index: iindx, f: form %>
52
+ <% iindx += 1 %>
53
+ <%= render_item_tree_table(c, 1, iindx).join.html_safe %>
54
+ <% end %>
55
+
56
+
57
+ <% end %>
58
+
59
+ <tr>
60
+ <td></td>
61
+ <td></td>
62
+ <td></td>
63
+ <td></td>
64
+ <td colspan="2" class="text-end"><%= form.submit class: "btn btn-primary" %></td>
65
+ </tr>
66
+
67
+
68
+ </table>
69
+
70
+
71
+ <% end %>
@@ -0,0 +1,29 @@
1
+
2
+ <tr style="background-color: <%= level_marker(level) %>">
3
+ <td>
4
+ <%= (" * " * level).html_safe %>
5
+ <%= index+1 %>.
6
+ <%= quotation_item.name %>
7
+ </td>
8
+ <td class="text-center"><%= quotation_item.quantity %></td>
9
+ <td class="text-first"><%= quotation_item.unit %></td>
10
+ <td class="text-end">
11
+ <%= currency(quotation_item.unit_price) %>
12
+ </td>
13
+ <td class="text-end">
14
+
15
+ <% if quotation_item.is_consolidation_destination_item? %>
16
+ <%= currency(quotation_item.consolidated_line_total) %>
17
+ <% else %>
18
+ <%= currency(quotation_item.line_total) %>
19
+ <% end %>
20
+
21
+ </td>
22
+
23
+ <td>
24
+ <%= f.text_field "quantum[#{quotation_item.id}]", multiple: true, class: "form-control text-center" %>
25
+ </td>
26
+
27
+ </tr>
28
+
29
+
@@ -0,0 +1,2 @@
1
+ <div id="<%= dom_id quotation_item_distribution %>">
2
+ </div>
@@ -0,0 +1,10 @@
1
+ <h1>Editing quotation item distribution</h1>
2
+
3
+ <%= render "form", quotation_item_distribution: @quotation_item_distribution %>
4
+
5
+ <br>
6
+
7
+ <div>
8
+ <%= link_to "Show this quotation item distribution", @quotation_item_distribution %> |
9
+ <%= link_to "Back to quotation item distributions", quotation_item_distributions_path %>
10
+ </div>
@@ -0,0 +1,14 @@
1
+ <p style="color: green"><%= notice %></p>
2
+
3
+ <h1>Quotation item distributions</h1>
4
+
5
+ <div id="quotation_item_distributions">
6
+ <% @quotation_item_distributions.each do |quotation_item_distribution| %>
7
+ <%= render quotation_item_distribution %>
8
+ <p>
9
+ <%= link_to "Show this quotation item distribution", quotation_item_distribution %>
10
+ </p>
11
+ <% end %>
12
+ </div>
13
+
14
+ <%= link_to "New quotation item distribution", new_quotation_item_distribution_path %>
@@ -0,0 +1,9 @@
1
+ <h1>New quotation item distribution</h1>
2
+
3
+ <%= render "form", quotation_item_distribution: @quotation_item_distribution %>
4
+
5
+ <br>
6
+
7
+ <div>
8
+ <%= link_back quotation_path(@quotation) %>
9
+ </div>
@@ -0,0 +1,10 @@
1
+ <p style="color: green"><%= notice %></p>
2
+
3
+ <%= render @quotation_item_distribution %>
4
+
5
+ <div>
6
+ <%= link_to "Edit this quotation item distribution", edit_quotation_item_distribution_path(@quotation_item_distribution) %> |
7
+ <%= link_to "Back to quotation item distributions", quotation_item_distributions_path %>
8
+
9
+ <%= button_to "Destroy this quotation item distribution", @quotation_item_distribution, method: :delete %>
10
+ </div>
@@ -1,16 +1,33 @@
1
1
  <div id="<%= dom_id quotation_item %>">
2
2
 
3
- <tr>
4
- <th><%= quotation_item.name %></th>
5
- <td><%= quotation_item.quantity %></td>
6
- <td><%= quotation_item.unit %></td>
7
- <td><%= currency(quotation_item.unit_price) %></td>
8
- <td><%= currency(quotation_item.line_total) %></td>
9
- <td><%= currency(quotation_item.discount) %></td>
10
- <td><%= currency(quotation_item.line_total_after_discount) %></td>
11
- <td><%= currency(quotation_item.tax) %></td>
12
- <td><%= currency(quotation_item.line_total_with_tax) %></td>
13
- <td></td>
3
+ <tr style="background-color: <%= level_marker(level) %>">
4
+ <td>
5
+ <%= f.check_box :sel_qi, multiple: true %>
6
+ </td>
7
+ <td>
8
+ <%= (" * " * level).html_safe %>
9
+ <%= index+1 %>.
10
+ <%= quotation_item.name %>
11
+ </td>
12
+ <td class="text-center"><%= quotation_item.quantity %></td>
13
+ <td class="text-first"><%= quotation_item.unit %></td>
14
+ <td class="text-end">
15
+ <%= currency(quotation_item.unit_price) %>
16
+ </td>
17
+ <td class="text-end">
18
+
19
+ <% if quotation_item.is_consolidation_destination_item? %>
20
+ <%= currency(quotation_item.consolidated_line_total) %>
21
+ <% else %>
22
+ <%= currency(quotation_item.line_total) %>
23
+ <% end %>
24
+
25
+ </td>
26
+
27
+ <td>
28
+ <%= f.text_field :quantum, class: "form-control" %>
29
+ </td>
30
+
14
31
  </tr>
15
32
 
16
33
 
@@ -0,0 +1,47 @@
1
+
2
+ <h2>Distribute Quotation Item</h2>
3
+
4
+ <table class="table" id="details">
5
+
6
+ <tr>
7
+ <th></th>
8
+ <th width="38%">Name</th>
9
+ <th class="text-center">Quantity</th>
10
+ <th class="text-center">Unit</th>
11
+ <th class="text-end">Unit Price</th>
12
+ <th class="text-end">Line Total</th>
13
+ <th>&nbsp;</th>
14
+ </tr>
15
+
16
+ <%= form_for :quotation_item do |f| %>
17
+
18
+ <% indx = 0 %>
19
+ <% @quotation.quotation_items.where(["parent_id is null"]).each do |i| %>
20
+
21
+ <%= render "quotation_item", quotation_item: i, level: 0, index: indx, f: f %>
22
+
23
+ <% indx += 1 %>
24
+
25
+ <% iindx = 0 %>
26
+ <% i.children.each do |c| %>
27
+ <%= render "quotation_item", quotation_item: c, level: 1, index: iindx, f: f %>
28
+ <% iindx += 1 %>
29
+ <%= render_item_tree_table(c, 1, iindx).join.html_safe %>
30
+ <% end %>
31
+
32
+ <% end %>
33
+
34
+ <tr>
35
+ <td></td>
36
+ <td></td>
37
+ <td></td>
38
+ <td></td>
39
+ <td></td>
40
+ <td class="text-end"><%= f.submit "Create Distribution", class: "btn btn-primary" %></td>
41
+ <td></td>
42
+ </tr>
43
+
44
+ <% end %>
45
+
46
+ </table>
47
+
@@ -1,7 +1,6 @@
1
1
  <div id="<%= dom_id quotation_product %>">
2
2
 
3
3
  <tr>
4
- <td><%= cnt %>.</td>
5
4
  <td><%= link_to quotation_product.name, quotation_product %></td>
6
5
  <td><%= quotation_product.quotation_product_category.name %></td>
7
6
  <td><%= quotation_product.state.titleize %></td>
@@ -5,16 +5,13 @@
5
5
  <div id="quotation_products">
6
6
  <table class="table">
7
7
  <tr>
8
- <th width="18px"></th>
9
8
  <th>Name</th>
10
9
  <th>Category</th>
11
10
  <th>Status</th>
12
11
  </tr>
13
-
14
- <% cnt = 1 %>
12
+
15
13
  <% @quotation_products.each do |quotation_product| %>
16
- <%= render quotation_product, cnt: cnt %>
17
- <% cnt += 1 %>
14
+ <%= render quotation_product %>
18
15
  <% end %>
19
16
  </table>
20
17
  </div>
@@ -15,6 +15,7 @@
15
15
  <%= link_to image_tag('icon-hide.png', size: "20x20"), hide_children_quotation_item_url(quotation_item), data: { turbo_method: :post } %>
16
16
  <% end %>
17
17
  <% end %>
18
+ <%= link_to "Distribute", new_quotation_item_distribution_url(source_quotation_item: quotation_item) %>
18
19
  </td>
19
20
  <td class="text-center"><%= quotation_item.quantity %></td>
20
21
  <td class="text-first"><%= quotation_item.unit %></td>
@@ -34,8 +35,17 @@
34
35
  <% end %>
35
36
  </div>
36
37
  </td>
38
+
37
39
  <td class="text-end">
38
- <%= currency(quotation_item.line_total) %>
40
+
41
+ <% if quotation_item.is_consolidation_destination_item? %>
42
+ <%= currency(quotation_item.consolidated_line_total) %>
43
+ <% elsif quotation_item.is_consolidation_source_item? %>
44
+ <%= currency(quotation_item.balance_after_distribution[:balance_amount]) %> *
45
+ <% else %>
46
+ <%= currency(quotation_item.line_total) %>
47
+ <% end %>
48
+
39
49
  <div class="collapse" id="dist<%= quotation_item.id %>">
40
50
  <%= form_for(:quotation_item, url: apply_discount_quotation_item_path(quotation_item), method: :post) do |f| %>
41
51
  <%= f.hidden_field :discount_on, value: :line_total %>
@@ -56,12 +66,28 @@
56
66
  <% end %>
57
67
  </div>
58
68
  </td>
69
+
70
+ <td class="text-end">
71
+ <% if not quotation_item.is_consolidation_source_item? %>
72
+ <%= link_to currency(quotation_item.discount), "#dist#{quotation_item.id}", "data-bs-toggle" => "collapse", "aria-expanded" => "false", "aria-controls" => "dist#{quotation_item.id}", role: "button" %>
73
+ <% end %>
74
+ </td>
75
+
76
+ <td>
77
+ <% if not quotation_item.is_consolidation_source_item? %>
78
+ (<%= quotation_item.discount.percent_of(quotation_item.line_total,2) %>%)
79
+ <% end %>
80
+ </td>
81
+
59
82
  <td class="text-end">
60
- <%= link_to currency(quotation_item.discount), "#dist#{quotation_item.id}", "data-bs-toggle" => "collapse", "aria-expanded" => "false", "aria-controls" => "dist#{quotation_item.id}", role: "button" %>
83
+ <% if not quotation_item.is_consolidation_source_item? %>
84
+ <%= currency(quotation_item.line_total_after_discount) %>
85
+ <% end %>
61
86
  </td>
62
- <td>(<%= quotation_item.discount.percent_of(quotation_item.line_total,2) %>%)</td>
63
- <td class="text-end"><%= currency(quotation_item.line_total_after_discount) %></td>
87
+
64
88
  <td class="text-end">
89
+
90
+ <% if not quotation_item.is_consolidation_source_item? %>
65
91
  <%= link_to currency(quotation_item.tax), "#tax#{quotation_item.id}", "data-bs-toggle" => "collapse", "aria-expanded" => "false", "aria-controls" => "tax#{quotation_item.id}", role: "button" %>
66
92
  <div class="collapse" id="tax<%= quotation_item.id %>">
67
93
  <%= form_for(:quotation_item, url: apply_tax_quotation_item_path(quotation_item), method: :post) do |f| %>
@@ -81,16 +107,63 @@
81
107
  </table>
82
108
  <% end %>
83
109
  </div>
84
-
110
+ <% end %>
111
+ </td>
112
+
113
+ <td>
114
+ <% if not quotation_item.is_consolidation_source_item? %>
115
+ <%= link_to image_tag('taxfree.png', size: "22x22"), remove_tax_quotation_item_path(quotation_item), data: { turbo_method: "post" } %>
116
+ <% end %>
117
+ </td>
118
+
119
+ <td class="text-end">
120
+ <% if not quotation_item.is_consolidation_source_item? %>
121
+ <%= currency(quotation_item.line_total_with_tax) %>
122
+ <% end %>
85
123
  </td>
86
- <td><%= link_to image_tag('taxfree.png', size: "22x22"), remove_tax_quotation_item_path(quotation_item), data: { turbo_method: "post" } %></td>
87
- <td class="text-end"><%= currency(quotation_item.line_total_with_tax) %></td>
124
+
88
125
  <td>
89
126
  <%= link_to image_tag('edit.png'), edit_quotation_quotation_item_path(quotation_item.quotation, quotation_item) %>
90
127
  <%= link_to image_tag('Delete.png'), quotation_item_path(quotation_item), dataz: { turbo_method: :delete, turbo_confirm: "Delete this item?" } %>
91
128
  </td>
92
129
  </tr>
93
130
 
131
+
132
+ <% if quotation_item.is_consolidation_destination_item? %>
133
+
134
+ <tr style="background-color: <%= level_marker(level) %>">
135
+ <td class="text-end" style="font-style: italic"><%= quotation_item.name %> (Existing Value)</td>
136
+ <td></td>
137
+ <td></td>
138
+ <td></td>
139
+ <td class="text-end" style="font-style: italic"><%= currency(quotation_item.line_total) %></td>
140
+ <td></td>
141
+ <td></td>
142
+ <td></td>
143
+ <td></td>
144
+ <td></td>
145
+ <td></td>
146
+ <td></td>
147
+ </tr>
148
+
149
+ <% quotation_item.source_quotation_items_link.each do |s| %>
150
+ <% cal = YAML.load(s.distribution_calculations) %>
151
+ <tr style="background-color: <%= level_marker(level) %>">
152
+ <td class="text-end" style="font-style: italic">Distributed from : <%= s.quotation_item.name %> </td>
153
+ <td colspan="3" style="font-style: italic" class="">(<%= distribution_params(cal.params) %> from total <%= currency(s.quotation_item.consolidated_line_total) %>)</td>
154
+ <td class="text-end" style="font-style: italic"><%= currency(cal.result[Smerp::Quotation::DistributionCalculator::DistributedAmount]) %></td>
155
+ <td><%= button_to "X", quotation_item_distribution_path(s), method: :delete, class: "btn btn-danger" %></td>
156
+ <td></td>
157
+ <td></td>
158
+ <td></td>
159
+ <td></td>
160
+ <td></td>
161
+ <td></td>
162
+ </tr>
163
+ <% end %>
164
+ <% end %>
165
+
166
+
94
167
  </div>
95
168
 
96
169
 
@@ -31,6 +31,9 @@
31
31
  <%= link_to "Back", quotations_path, class: "btn btn-secondary" %>
32
32
  <%= link_to "Edit", edit_quotation_path(@quotation), class: "btn btn-warning" %>
33
33
  <%= link_to "Add/Edit Extended Calculator", extended_calculators_quotation_path(@quotation), class: "btn btn-info" %>
34
+ <div style="clear: left; float: right;" class="text-end">
35
+ <%= button_to "Delete Quotation", @quotation, method: :delete, class: "btn btn-danger" %>
36
+ </div>
34
37
 
35
38
  <table class="table">
36
39
 
data/config/routes.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  Smerp::Quotation::Engine::Engine.routes.draw do
2
+
2
3
  resources :quotation_product_categories
3
4
  resources :quotation_products
4
5
 
@@ -41,9 +42,14 @@ Smerp::Quotation::Engine::Engine.routes.draw do
41
42
 
42
43
  post :hide_children
43
44
  post :show_children
45
+
46
+ #resources :quotation_item_distributions #, as: :distribution
47
+
44
48
  end
45
49
  end # quotation_items
46
50
 
51
+ resources :quotation_item_distributions #, as: :distribution
52
+
47
53
  resources :quotation_item_groups do
48
54
  resources :quotation_items
49
55
  end
@@ -1,7 +1,7 @@
1
1
  module Smerp
2
2
  module Quotation
3
3
  module Engine
4
- VERSION = "0.1.5"
4
+ VERSION = "0.2.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smerp-quotation-engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-30 00:00:00.000000000 Z
11
+ date: 2022-10-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -42,72 +42,72 @@ dependencies:
42
42
  name: smerp-common
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 0.1.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 0.1.0
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: ca-data_store
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 0.1.0
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 0.1.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: ca-data_store-ar
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 0.1.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 0.1.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: smerp-quotation
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: 0.2.0
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: 0.2.0
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: devops_assist
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: 0.3.0
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: 0.3.0
111
111
  description: ''
112
112
  email:
113
113
  - cameronian0@protonmail.com
@@ -121,12 +121,14 @@ files:
121
121
  - app/assets/config/smerp_quotation_engine_manifest.js
122
122
  - app/assets/stylesheets/smerp/quotation/engine/application.css
123
123
  - app/controllers/smerp/quotation/engine/application_controller.rb
124
+ - app/controllers/smerp/quotation/engine/quotation_item_distributions_controller.rb
124
125
  - app/controllers/smerp/quotation/engine/quotation_item_groups_controller.rb
125
126
  - app/controllers/smerp/quotation/engine/quotation_items_controller.rb
126
127
  - app/controllers/smerp/quotation/engine/quotation_product_categories_controller.rb
127
128
  - app/controllers/smerp/quotation/engine/quotation_products_controller.rb
128
129
  - app/controllers/smerp/quotation/engine/quotations_controller.rb
129
130
  - app/helpers/smerp/quotation/engine/application_helper.rb
131
+ - app/helpers/smerp/quotation/engine/quotation_item_distributions_helper.rb
130
132
  - app/helpers/smerp/quotation/engine/quotation_item_groups_helper.rb
131
133
  - app/helpers/smerp/quotation/engine/quotation_items_helper.rb
132
134
  - app/helpers/smerp/quotation/engine/quotation_product_categories_helper.rb
@@ -137,12 +139,19 @@ files:
137
139
  - app/models/smerp/quotation/engine/application_record.rb
138
140
  - app/models/smerp/quotation/engine/quotation.rb
139
141
  - app/models/smerp/quotation/engine/quotation_item.rb
142
+ - app/models/smerp/quotation/engine/quotation_item_distribution.rb
140
143
  - app/models/smerp/quotation/engine/quotation_item_group.rb
141
144
  - app/models/smerp/quotation/engine/quotation_product.rb
142
145
  - app/models/smerp/quotation/engine/quotation_product_category.rb
143
146
  - app/views/layouts/smerp/quotation/engine/application.html.erb
144
- - app/views/smerp/quotation/engine/_new_quotation_item_form.html.erb
145
147
  - app/views/smerp/quotation/engine/extended_calculators/extended_calculators.html.erb
148
+ - app/views/smerp/quotation/engine/quotation_item_distributions/_form.html.erb
149
+ - app/views/smerp/quotation/engine/quotation_item_distributions/_quotation_item.html.erb
150
+ - app/views/smerp/quotation/engine/quotation_item_distributions/_quotation_item_distribution.html.erb
151
+ - app/views/smerp/quotation/engine/quotation_item_distributions/edit.html.erb
152
+ - app/views/smerp/quotation/engine/quotation_item_distributions/index.html.erb
153
+ - app/views/smerp/quotation/engine/quotation_item_distributions/new.html.erb
154
+ - app/views/smerp/quotation/engine/quotation_item_distributions/show.html.erb
146
155
  - app/views/smerp/quotation/engine/quotation_item_groups/_form.html.erb
147
156
  - app/views/smerp/quotation/engine/quotation_item_groups/_quotation_item_group.html.erb
148
157
  - app/views/smerp/quotation/engine/quotation_item_groups/edit.html.erb
@@ -152,6 +161,7 @@ files:
152
161
  - app/views/smerp/quotation/engine/quotation_items/_form.html.erb
153
162
  - app/views/smerp/quotation/engine/quotation_items/_product_item_form.html.erb
154
163
  - app/views/smerp/quotation/engine/quotation_items/_quotation_item.html.erb
164
+ - app/views/smerp/quotation/engine/quotation_items/distribute.html.erb
155
165
  - app/views/smerp/quotation/engine/quotation_items/edit.html.erb
156
166
  - app/views/smerp/quotation/engine/quotation_items/index.html.erb
157
167
  - app/views/smerp/quotation/engine/quotation_items/new.html.erb
@@ -1,48 +0,0 @@
1
-
2
-
3
- <% parent = (defined?(group).nil? ? @quotation : group) %>
4
- <% url = (defined?(group).nil? ? quotation_quotation_items_path(@quotation) : quotation_item_group_quotation_items_path(group)) %>
5
-
6
- <%= form_with(model: @qi, url: url, method: :post) do |f| %>
7
- <% if @qi.errors.any? %>
8
- <div style="color: red">
9
- <h2><%= pluralize(@qi.errors.count, "error") %> prohibited this quotation_item from being saved:</h2>
10
-
11
- <ul>
12
- <% @qi.errors.each do |error| %>
13
- <li><%= error.full_message %></li>
14
- <% end %>
15
- </ul>
16
- </div>
17
- <% end %>
18
-
19
- <% if not defined?(group).nil? %>
20
- <%= f.hidden_field :quotation_item_group_id, value: group.id %>
21
- <% else %>
22
- <%= f.hidden_field :quotation_id, value: @quotation.id %>
23
- <% end %>
24
-
25
- <div class="row pb-1">
26
- <div class="col-10">
27
- <%= f.select :parent_is, @parent, {}, class: "form-control" %>
28
- </div>
29
- </div>
30
-
31
- <div class="row pb-1">
32
- <div class="col-6"><%= f.text_field :name, placeholder: (defined?(group).nil?) ? "Item" : "Sub Item Under Group #{group.name}", class: "form-control" %></div>
33
- <div class="col-1"><%= f.text_field :quantity, placeholder: "Quantity", class: "form-control" %></div>
34
- <div class="col-1"><%= f.text_field :unit, placeholder: "Unit", class: "form-control" %></div>
35
- <div class="col-1"><%= f.text_field :unit_price, placeholder: "Unit Price", class: "form-control" %></div>
36
- <div class="col-1">
37
- <%= f.text_field :discount, placeholder: "Discount", class: "form-control" %>
38
- <%= f.select :discount_unit, [["Percent","percent"],["Value","value"]], {}, class: "form-control" %>
39
- </div>
40
- <div class="col-1">
41
- <%= f.text_field :tax, placeholder: "Tax", class: "form-control" %>
42
- <%= f.select :tax_unit, [["Percent","percent"],["Value","value"]], {}, class: "form-control" %>
43
- </div>
44
- <div class="col-1"><%= f.submit "Create" %></div>
45
- </div>
46
-
47
- <% end %>
48
-