fifo_lifo 0.1.0 → 0.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ace09f6ff24004f28ac2535898a15234f15edd7bd22383b1621b4ccc6f972b29
4
- data.tar.gz: 98edfc1a879c86a6c1bef63cbf3117ac79a46f7de32b620916419bfd7bb2ad82
3
+ metadata.gz: 37b80b191d8613d91e95f6f5afcb988539f0c23c8a3f3953848d357805d2532c
4
+ data.tar.gz: e562e9ced16c3f287411624e9695e7b2a96c14a3240f640e1bffa40ff98e4ab8
5
5
  SHA512:
6
- metadata.gz: 89ec95439c03d6a6008fb831cb7e9c9948b8cc30beb8d7b7fcdfdba2c31468cc5ba1a24b7346eb652fbbab1411ba7f97cbf27dc40171cfc490406140493a0c98
7
- data.tar.gz: fc844a10a44b0befc45541f5c00ad9dae5813b2522f509115c30ea0aedc4b38de052c3c8af04bd4f3da661e072b501fbff289abd50277e1027fd25b37ad1a7ac
6
+ metadata.gz: 17d57d7dda1e53256f7ffeb70bdcec247628d9073c5be643f15d36f2d40ef9296115045bc71f9444c7e15e442ebf06be3812398a2a9ea708b061a973373d9e93
7
+ data.tar.gz: 90793be6aae71f2acb57d83f6876ccc98021bab91a7050ddd5a610d90ea39031ecb61ab21c0a9f706dce10850bbb0c6e7c82803163a07a976130bce92f891d5e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fifo_lifo (0.1.0)
4
+ fifo_lifo (0.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -1,9 +1,3 @@
1
- # FifoLifo
2
-
3
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/fifo_lifo`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
6
-
7
1
  ## Installation
8
2
 
9
3
  Add this line to your application's Gemfile:
@@ -4,51 +4,8 @@ class Fifo
4
4
  end
5
5
  # calculating whether we have profit all loss and output final results
6
6
  def get_profit_or_lost_with_fifo
7
- total_profit = 0
8
- total_cost = 0
9
- cost_of_goods_sold = 0
10
- total_income = 0
11
- temp_remaining_invetory = 0
12
-
13
- purchases = @utils.get_purchase_and_prices[0]
14
- purchases_prices = @utils.get_purchase_and_prices[1]
15
-
16
- sells = @utils.get_sell_and_prices[0]
17
- sells_prices = @utils.get_sell_and_prices[1]
18
-
19
- purchases.each_with_index do |curr_purchase, purchase_index|
20
- invetory = curr_purchase + temp_remaining_invetory # initializing the invetory
21
- temp_remaining_invetory = 0
22
- total_amt_spent = invetory * purchases_prices[purchase_index] # setting the amout spent purchasing a given good
23
- temp_income = 0 # initializing a temporary income variable to zero
24
- sells.each_with_index do |curr_sell, index|
25
- break if sells.sum().zero?
26
- next if curr_sell.zero?
27
- if invetory.zero? || ((invetory + curr_sell) < 0) # whenever the current invetory is zero
28
- temp_remaining_invetory = invetory
29
- total_profit += temp_income - total_amt_spent
30
- cost_of_goods_sold += total_amt_spent
31
- total_income += temp_income
32
- temp_income = 0
33
- total_amt_spent = 0
34
- break
35
- end
36
- temp_income += (-1 * curr_sell) * sells_prices[index] # calculating the income at every selling and save it in a temporary variable
37
- invetory += curr_sell # modifying the invetory whenever we sell
38
- sells[index] = 0 # setting the sell to zero so that it won't count for the next time
39
- end
40
- remaining_invetory_cost = total_amt_spent - (invetory * purchases_prices[purchase_index])
41
- total_profit += temp_income - remaining_invetory_cost
42
- total_income += temp_income
43
- cost_of_goods_sold += remaining_invetory_cost
44
- break if sells.sum().zero?
45
- end
46
-
47
- result = if total_profit.positive?
48
- "The total profit with FIFO is: #{total_profit}"
49
- else
50
- "The loss with FIFO is: #{total_profit}"
51
- end
52
- [result, cost_of_goods_sold, total_income]
7
+ list_purchases = @utils.get_purchase_and_prices[0]
8
+ list_prices = @utils.get_purchase_and_prices[1]
9
+ @utils.calculate_profit_or_loss(list_purchases,list_prices)
53
10
  end
54
11
  end
@@ -3,51 +3,8 @@ class Lifo
3
3
  @utils = utils
4
4
  end
5
5
  def get_profit_or_lost_with_lifo
6
- total_profit = 0
7
- total_cost = 0
8
- cost_of_goods_sold = 0
9
- total_income = 0
10
- temp_remaining_invetory = 0
11
-
12
- purchases = @utils.get_purchase_and_prices[0].reverse()
13
- purchases_prices = @utils.get_purchase_and_prices[1].reverse()
14
-
15
- sells = @utils.get_sell_and_prices[0]
16
- sells_prices = @utils.get_sell_and_prices[1]
17
-
18
- purchases.each_with_index do |curr_purchase, purchase_index|
19
- invetory = curr_purchase + temp_remaining_invetory # initializing the invetory
20
- temp_remaining_invetory = 0
21
- total_amt_spent = invetory * purchases_prices[purchase_index] # setting the amout spent purchasing a given good
22
- temp_income = 0 # initializing a temporary income variable to zero
23
- sells.each_with_index do |curr_sell, index|
24
- break if sells.sum().zero?
25
- next if curr_sell.zero?
26
- if invetory.zero? || ((invetory + curr_sell) < 0)# whenever the current invetory is zero
27
- temp_remaining_invetory = invetory
28
- total_profit += temp_income - total_amt_spent
29
- cost_of_goods_sold += total_amt_spent
30
- total_income += temp_income
31
- temp_income = 0
32
- total_amt_spent = 0
33
- break
34
- end
35
- temp_income += (-1 * curr_sell) * sells_prices[index] # calculating the income at every selling and save it in a temporary variable
36
- invetory += curr_sell # modifying the invetory whenever we sell
37
- sells[index] = 0 # setting the sell to zero so that it won't count for the next time
38
- end
39
- remaining_invetory_cost = total_amt_spent - (invetory * purchases_prices[purchase_index])
40
- total_profit += temp_income - remaining_invetory_cost
41
- total_income += temp_income
42
- cost_of_goods_sold += remaining_invetory_cost
43
- break if sells.sum().zero?
44
- end
45
-
46
- result = if total_profit.positive?
47
- "The total profit with LIFO is: #{total_profit}"
48
- else
49
- "The loss with LIFO is: #{total_profit}"
50
- end
51
- [result, cost_of_goods_sold, total_income]
6
+ list_purchases = @utils.reverse_array(@utils.get_purchase_and_prices[0])
7
+ list_prices = @utils.reverse_array(@utils.get_purchase_and_prices[1])
8
+ @utils.calculate_profit_or_loss(list_purchases,list_prices)
52
9
  end
53
10
  end
@@ -49,4 +49,52 @@ class Utilities
49
49
  def get_unit_purchased
50
50
  get_purchase_and_prices[0].sum()
51
51
  end
52
+
53
+ # reverse the array
54
+ def reverse_array(arr)
55
+ arr.reverse()
56
+ end
57
+
58
+ def calculate_profit_or_loss(purchases, purchases_prices)
59
+ total_cost = 0
60
+ cost_of_goods_sold = 0
61
+ total_income = 0
62
+ temp_remaining_invetory = 0
63
+
64
+ sells = get_sell_and_prices[0]
65
+ sells_prices = get_sell_and_prices[1]
66
+
67
+ purchases.each_with_index do |curr_purchase, purchase_index|
68
+ invetory = curr_purchase + temp_remaining_invetory # initializing the invetory
69
+ temp_remaining_invetory = 0
70
+ total_amt_spent = invetory * purchases_prices[purchase_index] # setting the amout spent purchasing a given good
71
+ temp_income = 0 # initializing a temporary income variable to zero
72
+ sells.each_with_index do |curr_sell, index|
73
+ break if sells.sum().zero? # breaking the loop if there is no more sells remaining on the list
74
+ next if curr_sell.zero?
75
+ if invetory.zero? || ((invetory + curr_sell) < 0) # whenever the current invetory is less than the sell
76
+ temp_remaining_invetory = invetory
77
+ cost_of_goods_sold += total_amt_spent
78
+ total_income += temp_income
79
+ temp_income = 0 # resetting the temporary income variable to zero
80
+ total_amt_spent = 0
81
+ break
82
+ end
83
+ temp_income += (-1 * curr_sell) * sells_prices[index] # calculating the income at every selling and save it in a temporary variable
84
+ invetory += curr_sell # modifying the invetory whenever we sell
85
+ sells[index] = 0 # setting the sell to zero so that it won't count for the next time
86
+ end
87
+ remaining_invetory_cost = total_amt_spent - (invetory * purchases_prices[purchase_index])
88
+ total_income += temp_income
89
+ cost_of_goods_sold += remaining_invetory_cost
90
+ break if sells.sum().zero?
91
+ end
92
+ total_profit = total_income - cost_of_goods_sold # calculating the final total profit
93
+ result = if total_profit.positive?
94
+ "The total profit is: #{total_profit}"
95
+ else
96
+ "The loss is: #{total_profit}"
97
+ end
98
+ [result, cost_of_goods_sold, total_income]
99
+ end
52
100
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FifoLifo
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/fifo_lifo.rb CHANGED
@@ -7,7 +7,7 @@ require_relative 'fifo_lifo/lifo'
7
7
 
8
8
  module FifoLifo
9
9
  class Error < StandardError; end
10
- # Your code goes here...
10
+
11
11
  class Main
12
12
  def initialize(bitcoins, prices)
13
13
  @utils = Utilities.new(bitcoins, prices)
@@ -16,45 +16,45 @@ module FifoLifo
16
16
  end
17
17
 
18
18
  # displays all of the result desired
19
- def display_results
20
- fifo_gotten_results = @fifo.get_profit_or_lost_with_fifo
21
- fifo_cost_of_goods_sold = fifo_gotten_results[1]
22
- fifo_total_income = fifo_gotten_results[2]
23
- lifo_gotten_results = @lifo.get_profit_or_lost_with_lifo
24
- lifo_cost_of_goods_sold = lifo_gotten_results[1]
25
- lifo_total_income = lifo_gotten_results[2]
26
-
27
- units_purchased = @utils.get_unit_purchased
28
- units_sold = @utils.get_unit_sold
29
- final_invetory = units_purchased + units_sold
30
-
31
- puts "\n\n"
32
- puts "======= The following are the general results regardless of FIFO nor LIFO approach ======="
33
- puts "============================================================================================"
34
- puts "The final invetory is: #{final_invetory}"
35
- puts "Units sold are: #{units_sold}"
36
- puts "Units purchased are: #{units_purchased}"
37
- puts "The total cost is: #{@utils.get_total_cost}"
38
-
39
- puts "\n\n"
40
-
41
- puts "======= The following are the results gotten if we perform the FIFO approach ======="
42
- puts "======================================================================================"
43
-
44
- puts "The cost_of_goods_sold with FIFO is: #{fifo_cost_of_goods_sold}"
45
- puts "The total_income with FIFO is: #{fifo_total_income}"
46
- puts fifo_gotten_results[0]
47
-
48
- puts "\n\n"
49
-
50
- puts "======= The following are the results gotten if we perform the LIFO approach ======="
51
- puts "======================================================================================"
52
-
53
- puts "The cost_of_goods_sold with LIFO is: #{lifo_cost_of_goods_sold}"
54
- puts "The total_income with LIFO is: #{lifo_total_income}"
55
- puts lifo_gotten_results[0]
56
- puts "\n\n"
57
- end
19
+ def display_results
20
+ fifo_gotten_results = @fifo.get_profit_or_lost_with_fifo
21
+ fifo_cost_of_goods_sold = fifo_gotten_results[1]
22
+ fifo_total_income = fifo_gotten_results[2]
23
+ lifo_gotten_results = @lifo.get_profit_or_lost_with_lifo
24
+ lifo_cost_of_goods_sold = lifo_gotten_results[1]
25
+ lifo_total_income = lifo_gotten_results[2]
26
+
27
+ units_purchased = @utils.get_unit_purchased
28
+ units_sold = @utils.get_unit_sold
29
+ final_invetory = units_purchased + units_sold
30
+
31
+ puts "\n\n"
32
+ puts "======= The following are the general results regardless of FIFO nor LIFO approach ======="
33
+ puts "============================================================================================"
34
+ puts "The final invetory is: #{final_invetory}"
35
+ puts "Units sold are: #{units_sold}"
36
+ puts "Units purchased are: #{units_purchased}"
37
+ puts "The total cost is: #{@utils.get_total_cost}"
38
+
39
+ puts "\n\n"
40
+
41
+ puts "======= The following are the results gotten if we perform the FIFO approach ======="
42
+ puts "======================================================================================"
43
+
44
+ puts "The cost_of_goods_sold with FIFO is: #{fifo_cost_of_goods_sold}"
45
+ puts "The total_income with FIFO is: #{fifo_total_income}"
46
+ puts fifo_gotten_results[0]
47
+
48
+ puts "\n\n"
49
+
50
+ puts "======= The following are the results gotten if we perform the LIFO approach ======="
51
+ puts "======================================================================================"
52
+
53
+ puts "The cost_of_goods_sold with LIFO is: #{lifo_cost_of_goods_sold}"
54
+ puts "The total_income with LIFO is: #{lifo_total_income}"
55
+ puts lifo_gotten_results[0]
56
+ puts "\n\n"
57
+ end
58
58
  end
59
59
 
60
60
  isbit_calculator = Main.new([4, -2, -1, 5, -0.5, -0.5, -4.5], [5000, 6500, 7000, 6000, 8000, 9000, 6500])
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fifo_lifo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - descholar-ceo
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-02-04 00:00:00.000000000 Z
11
+ date: 2022-02-05 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: You will pass it the two arrays, the goods array and the prices array,
14
14
  the purchases should have positive sign and sells should be negatives