smerp-quotation-engine 0.2.5 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 777e262c604a99493ca587be525eb924ac7d399893292206a95a395f235ae4ac
4
- data.tar.gz: 4cd1e47df6f981e2702d96061068910906fbc5d1ecbede7c0bad29b10ab6a467
3
+ metadata.gz: 8546e16b5580393b492285b0e9a1b6ad03db1b07b0d1c020d793c5d072cc7c2d
4
+ data.tar.gz: 6f4f31d01f493c52c75ef4efe931e53803a737a9b07ca5447e89a0867d00106d
5
5
  SHA512:
6
- metadata.gz: 06aacf73a6e7de230646cc4fb13174b6754caf60c613b9e54a771473dd0f3a7698e1a2f6b1fe72c61da44e5cea0c0694136a211c31c1145b630623fdf7e4f48d
7
- data.tar.gz: 3233365ebc395a89c4b6ab8c81788df3bfa39c6a3a6b8a2d9e1e54df5744e118301344cb75846314ee06bac9768bfc3d33b38743df2877d471423c13717fc9f1
6
+ metadata.gz: b22cf2555a4422d10f0e01a9e499bd41d76ba74b26f4f0b900f8a11a5382bdce58c6aba09e6c93f64615cd757e023c36f3cfdb1e1b93ffc12abfb025ad1131ca
7
+ data.tar.gz: bd09f9344fd1d7c9cce91d0958e953994dfcdc7e92e60be97c44e5a708a82c62e185c4e12056e26377b63ff657786d7e176386911735bc065c65682a55090567
@@ -3,7 +3,7 @@ require 'smerp/quotation'
3
3
 
4
4
  module Smerp::Quotation::Engine
5
5
  class QuotationsController < ApplicationController
6
- before_action :set_quotation, only: %i[ show edit update destroy extended_calculators new_extended_calculator create_calculator edit_extended_calculator update_extended_calculator delete_extended_calculator new_product_item ]
6
+ before_action :set_quotation, only: %i[ show edit update destroy extended_calculators new_extended_calculator create_calculator edit_extended_calculator update_extended_calculator delete_extended_calculator new_product_item resources_allocation_summary ]
7
7
 
8
8
  # GET /quotations
9
9
  def index
@@ -173,6 +173,17 @@ module Smerp::Quotation::Engine
173
173
  @quotation_item = QuotationItem.new
174
174
  end
175
175
 
176
+ def resources_allocation_summary
177
+ @resTable = {}
178
+ @quotation.quotation_items_allocated_resources.each do |qi|
179
+ prodId = qi.quotation_product.name
180
+ @resTable[prodId] = { total: 0.0, rate: qi.quotation_product.unit_price.to_f } if @resTable[prodId].nil?
181
+ @resTable[prodId][:total] += qi.quantity
182
+
183
+ @resTable[prodId][:total_rate] = @resTable[prodId][:total] * @resTable[prodId][:rate]
184
+ end
185
+ end
186
+
176
187
  private
177
188
  # Use callbacks to share common setup or constraints between actions.
178
189
  def set_quotation
@@ -76,5 +76,27 @@ module Smerp::Quotation::Engine
76
76
  not session[:hide_children_parent_id].nil? and session[:hide_children_parent_id].include?(id)
77
77
  end
78
78
 
79
+ def days_to_human_readable(days)
80
+ if days > 20
81
+ months = (days/20).to_i
82
+ monthDays = months*20
83
+ balMonthDay = days - monthDays
84
+
85
+ weeks = (balMonthDay/5).to_i
86
+ weekDays = weeks*5
87
+ days = (balMonthDay - weekDays).to_i
88
+
89
+ if days > 0
90
+ "#{months} month(s), #{weeks} week(s) and #{days} days (Calendar Based)"
91
+ elsif balMonthDay > 0
92
+ "#{months} month(s) and #{weeks} week(s) (Calendar Based)"
93
+ else
94
+ "#{months} month(s)"
95
+ end
96
+ else
97
+ "#{days} calendar day(s)"
98
+ end
99
+ end
100
+
79
101
  end
80
102
  end
@@ -7,5 +7,18 @@ module Smerp::Quotation::Engine
7
7
 
8
8
  validates_presence_of :name
9
9
 
10
+ has_many :quotation_items
11
+
12
+ def quotation_items_allocated_resources
13
+
14
+ resType = QuotationProductCategory.where(["name = ?","Resources"]).first
15
+
16
+ qpIds = QuotationProduct.active_products(resType.id).order(:position).select(:id)
17
+
18
+ # all quotation items that carries the resources link
19
+ self.quotation_items.where({ quotation_product_id: qpIds })
20
+
21
+ end
22
+
10
23
  end
11
24
  end
@@ -16,6 +16,8 @@ module Smerp::Quotation::Engine
16
16
 
17
17
  before_validation :map_product_item
18
18
 
19
+ belongs_to :quotation
20
+
19
21
  def map_product_item
20
22
 
21
23
  if not self.quotation_product_id.nil?
@@ -1,6 +1,11 @@
1
+
2
+ require 'acts_as_list'
3
+
1
4
  module Smerp::Quotation::Engine
2
5
  class QuotationProduct < ApplicationRecord
3
6
 
7
+ acts_as_list
8
+
4
9
  state_machine initial: :active do
5
10
 
6
11
  event :suspend do
@@ -3,7 +3,7 @@ module Smerp::Quotation::Engine
3
3
 
4
4
  has_many :quotation_products
5
5
 
6
- def QuotationProductCategory.active_products
6
+ def QuotationProductCategory.active_categories
7
7
  QuotationProductCategory.where(["state = 'active'"])
8
8
  end
9
9
 
@@ -0,0 +1,62 @@
1
+
2
+
3
+ <h3>Resources Allocation Summary</h3>
4
+
5
+ <table class="table">
6
+
7
+ <tr>
8
+ <th>Quotation ID</th>
9
+ <th>Customer</th>
10
+ <th class="text-center">Date</th>
11
+ <th>Status</th>
12
+ </tr>
13
+
14
+ <div <%= dom_id @quotation %>>
15
+ <%= render "quotation", quotation: @quotation %>
16
+ </div>
17
+
18
+ </table>
19
+
20
+ <table class="table">
21
+ <tr style="background-color: lightgrey">
22
+ <th></th>
23
+ <th>Role</th>
24
+ <th colspan="2" class="text-center">Total Allocated Mandays</th>
25
+ <th colspan="2" class="text-center">Total Price</th>
26
+ </tr>
27
+
28
+ <% cnt = 0 %>
29
+ <% ttlMd = 0 %>
30
+ <% ttlPrice = 0 %>
31
+ <% @resTable.each do |res, val| %>
32
+ <tr>
33
+ <td><%= cnt += 1 %>.</td>
34
+ <td><%= res %></td>
35
+ <td class="text-end"><%= val[:total] %></td>
36
+ <td style="font-style: italic">
37
+ (Roughly <%= days_to_human_readable(val[:total]) %>)
38
+ </td>
39
+ <td class="text-end">
40
+ <%= currency(val[:total_rate]) %>
41
+ </td>
42
+ <td></td>
43
+ </tr>
44
+ <% ttlMd += val[:total] %>
45
+ <% ttlPrice += val[:total_rate] %>
46
+ <% end %>
47
+
48
+ <tr style="font-weight: bold; background-color: #8EFEC1">
49
+ <td></td>
50
+ <td class="text-end">Grand Total : </td>
51
+ <td class="text-end"><%= ttlMd %></td>
52
+ <td style="font-style: italic">(Roughly <%= days_to_human_readable(ttlMd) %>)</td>
53
+ <td class="text-end"><%= currency(ttlPrice) %></td>
54
+ <td style="font-style: italic;"><%= ttlPrice.percent_of(@quotation.total, 2) %>%</td>
55
+ </tr>
56
+
57
+ </table>
58
+
59
+
60
+ <%= link_back quotation_url(@quotation) %>
61
+
62
+
@@ -35,6 +35,10 @@
35
35
  <%= button_to "Delete Quotation", @quotation, method: :delete, class: "btn btn-danger" %>
36
36
  </div>
37
37
 
38
+ <div class="pt-2">
39
+ <%= link_to "Resources Summary", resources_allocation_summary_quotation_path(@quotation), class: "btn btn-secondary" %>
40
+ </div>
41
+
38
42
  <table class="table">
39
43
 
40
44
  <tr>
data/config/routes.rb CHANGED
@@ -4,6 +4,7 @@ Smerp::Quotation::Engine::Engine.routes.draw do
4
4
  resources :quotation_products
5
5
 
6
6
  resources :quotations do
7
+
7
8
  resources :quotation_item_groups do
8
9
  resources :quotation_items
9
10
  end
@@ -24,6 +25,8 @@ Smerp::Quotation::Engine::Engine.routes.draw do
24
25
 
25
26
  get :new_product_item
26
27
 
28
+ get :resources_allocation_summary
29
+
27
30
  end
28
31
 
29
32
  end # quotations
@@ -0,0 +1,6 @@
1
+ class AddPositionToQuotationProducts < ActiveRecord::Migration[7.0]
2
+ def change
3
+ # support acts_as_list
4
+ add_column :smerp_quotation_engine_quotation_products, :position, :integer
5
+ end
6
+ end
@@ -1,7 +1,7 @@
1
1
  module Smerp
2
2
  module Quotation
3
3
  module Engine
4
- VERSION = "0.2.5"
4
+ VERSION = "0.3.1"
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.2.5
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-10-04 00:00:00.000000000 Z
11
+ date: 2022-10-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -190,11 +190,13 @@ files:
190
190
  - app/views/smerp/quotation/engine/quotations/new.html.erb
191
191
  - app/views/smerp/quotation/engine/quotations/new_extended_calculator.html.erb
192
192
  - app/views/smerp/quotation/engine/quotations/new_product_item.html.erb
193
+ - app/views/smerp/quotation/engine/quotations/resources_allocation_summary.html.erb
193
194
  - app/views/smerp/quotation/engine/quotations/show.html.erb
194
195
  - config/routes.rb
195
196
  - db/migrate/20220929020407_create_smerp_quotation_engine_quotation_products.rb
196
197
  - db/migrate/20220929041715_create_smerp_quotation_engine_quotation_product_categories.rb
197
198
  - db/migrate/20220929074438_link_product_to_item.rb
199
+ - db/migrate/20221005090104_add_position_to_quotation_products.rb
198
200
  - db/seeds.rb
199
201
  - lib/smerp/quotation/engine.rb
200
202
  - lib/smerp/quotation/engine/engine.rb