next_sges 0.1.1 → 0.1.2

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
  SHA1:
3
- metadata.gz: 357f59de966cac997f49fd28d49021d3a01838a7
4
- data.tar.gz: 810c6356f03577e216708500f8eb1a5ba20d81fa
3
+ metadata.gz: 11b37e38c792857537cad669d29eeea53c0d19fa
4
+ data.tar.gz: 35a541d412bb53d91f2ff3c3ace9e3d03fb8bd04
5
5
  SHA512:
6
- metadata.gz: 208b89055b0c8d9ddb2f4c4a4b276917260d17c50a352ceeb758cd8069354c7994f19a83ad19fec0afd6e4a88fecff422832921c8abdced8f127cb7585954832
7
- data.tar.gz: 3da2da001ac7b8df04b042c297602419c71686e40158a1b5675078a1967bd1c4cbe3af39ddba40c2bebbd3e21b49cef005e6c5d54150bf855b44fdddc013f025
6
+ metadata.gz: 49f60b7bd91581f8204b42a8ab97013676155a1aca6fe7a1887413ac65b1db3bbfe6291b93cdbab03a3369b7364a20b1bd393c629084137a6f9cb5688ffa09a9
7
+ data.tar.gz: fd5540dc5846c88544f4603377c361e2d71a49ca8dfcfb9477b8b680e127b5dfb43c0eb81d6a88535a5b9691f4991578d45ffc0fb6d1ca23b5a6d2a2d569624e
@@ -4,6 +4,8 @@ module NextSges
4
4
  belongs_to :school
5
5
  has_many :collection_note_items, dependent: :destroy
6
6
  has_many :deposits
7
+ has_many :responsibles, through: :student
8
+ has_many :collection_note_responsibles
7
9
 
8
10
  enum status: {inactive: 0, active: 1, paid: 2}
9
11
  INITIAL_LETTER = "F"
@@ -25,8 +27,7 @@ module NextSges
25
27
  active!
26
28
  elsif paid?
27
29
  if active!
28
- encharged = student.parent
29
- encharged.update_columns(account_balance: encharged.account_balance + value)
30
+ collection_note_responsibles.each(&:destroy)
30
31
  end
31
32
  # TODO, Make code to return money address
32
33
  end
@@ -38,14 +39,21 @@ module NextSges
38
39
  inactive!
39
40
  end
40
41
 
42
+
41
43
  # Mark collection note to paid
42
- def pay
44
+ def pay(responsible)
43
45
  return unless can_pay?
44
46
  if paid!
45
- encharged = student.parent
46
- encharged.update_columns(account_balance: encharged.account_balance - value)
47
+ responsible.update_columns(account_balance: responsible.account_balance - value)
48
+ end
49
+ end
50
+
51
+ # pays the collection note with this responsible balance
52
+ def responsible_pay(responsible)
53
+ return unless can_responsible_pay?(responsible)
54
+ if paid!
55
+ ::CollectionNoteResponsible.create(responsible_id: responsible.id, collection_note_id: id, value: value)
47
56
  end
48
- # Make Code to move money
49
57
  end
50
58
 
51
59
  # Set Collection note to active
@@ -58,10 +66,19 @@ module NextSges
58
66
  active?
59
67
  end
60
68
 
61
- # Mark Collection note to paid
69
+ #TODO, Remove## Mark Collection note to paid
62
70
  def can_pay?
63
- active? && student.parent.account_balance >= value
71
+ active? #&& student.parent.account_balance >= value
64
72
  end
73
+
74
+ def can_responsible_pay?(responsible)
75
+ active? && responsible.account_balance >= value
76
+ end
77
+
78
+ def responsibles_that_can_pay
79
+ responsibles.active.where("account_balance >= ?", value)
80
+ end
81
+
65
82
  validates_presence_of :student_id, :school_id
66
83
  before_create :create_number
67
84
  end
@@ -116,7 +116,7 @@ module NextSges
116
116
  ob_coll_type = collection_type
117
117
  ob_student = student
118
118
  ob_school = school
119
- students_number = student.parent.students.size
119
+ students_number = 0#student.number #parent.students.size
120
120
  discount = 0
121
121
  desc = ''
122
122
 
@@ -1,6 +1,6 @@
1
1
  module NextSges
2
2
  class Deposit < NextSges::ApplicationRecord
3
- belongs_to :parent
3
+ belongs_to :responsible, class_name: ::Responsible.name
4
4
  belongs_to :school
5
5
  belongs_to :collection_note, optional: true
6
6
 
@@ -9,7 +9,7 @@ module NextSges
9
9
 
10
10
  INITIAL_LETTER = "D"
11
11
 
12
- validates_presence_of :value, :school_id
12
+ validates_presence_of :value, :school_id, :responsible_id
13
13
  validates_numericality_of :value, greater_than: 0
14
14
 
15
15
  before_create :create_number
@@ -18,12 +18,12 @@ module NextSges
18
18
 
19
19
  private
20
20
  def increase_parent_balance
21
- encharged = parent
21
+ encharged = responsible
22
22
  encharged.update_columns(account_balance: encharged.account_balance + value)
23
23
  end
24
24
 
25
25
  def decrease_parent_balance
26
- encharged = parent
26
+ encharged = responsible
27
27
  encharged.update_columns(account_balance: encharged.account_balance - value)
28
28
  end
29
29
 
@@ -1,12 +1,16 @@
1
1
  module NextSges
2
2
  class School < NextSges::ApplicationRecord
3
- has_many :parents, dependent: :destroy
3
+ #has_many :parents, dependent: :destroy
4
4
  has_many :students, dependent: :destroy
5
5
  has_many :collection_types, dependent: :destroy
6
6
  has_many :collection_notes, dependent: :destroy
7
7
  has_many :collection_note_items, dependent: :destroy
8
8
  has_many :deposits, dependent: :destroy
9
- has_many :responsible_others, dependent: :destroy
9
+ #has_many :responsible_others, dependent: :destroy
10
+ has_many :responsibles, dependent: :destroy, class_name: Responsible.name
11
+ has_many :student_responsibles, through: :responsibles, class_name: StudentResponsible.name
12
+ has_many :student_responsible_periods, through: :student_responsibles, class_name: StudentResponsiblePeriod.name
13
+
10
14
  INITIAL_LETTER = "C"
11
15
 
12
16
  def name_and_number
@@ -1,7 +1,11 @@
1
1
  module NextSges
2
2
  class Student < NextSges::ApplicationRecord
3
- belongs_to :parent, optional: true
3
+ #belongs_to :parent, optional: true
4
4
  belongs_to :school
5
+ has_many :collection_notes
6
+ has_many :student_responsibles, dependent: :destroy, class_name: StudentResponsible.name
7
+ has_many :responsibles, through: :student_responsibles, class_name: Responsible.name
8
+ has_many :student_responsible_periods, through: :student_responsibles, class_name: StudentResponsiblePeriod.name
5
9
  has_and_belongs_to_many :collection_types, association_foreign_key: :next_sges_collection_type_id, foreign_key: :next_sges_student_id
6
10
  enum relation: {son: 0, other: 1}
7
11
  enum identification_type: DEFAULT_IDENTIFICATION_ENUM
@@ -22,6 +26,10 @@ module NextSges
22
26
  "#{number} - #{first_and_last_name}"
23
27
  end
24
28
 
29
+ def not_associated_responsibles
30
+ ::Responsible.where(school_id: school_id).where.not(id: responsibles.ids)
31
+ end
32
+
25
33
  # validates_presence_of :parent_id
26
34
  validate :student_services
27
35
  before_create :create_number
@@ -0,0 +1,5 @@
1
+ class AddResponsibleToNextSgesDeposits < ActiveRecord::Migration[5.1]
2
+ def change
3
+ add_reference :next_sges_deposits, :responsible, foreign_key: {to_table: :next_sges_deposits}
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ class FixResponisbleOnDeposit < ActiveRecord::Migration[5.1]
2
+ def change
3
+ remove_column :next_sges_deposits, :responsible_id
4
+ add_reference :next_sges_deposits, :responsible, foreign_key: {to_table: :responsibles}
5
+ end
6
+ end
@@ -1,3 +1,3 @@
1
1
  module NextSges
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: next_sges
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - NEXTBSS
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-02-19 00:00:00.000000000 Z
11
+ date: 2018-02-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -195,6 +195,8 @@ files:
195
195
  - db/migrate/20180216140129_add_collection_note_to_deposits.rb
196
196
  - db/migrate/20180219135538_add_birthday_to_parents.rb
197
197
  - db/migrate/20180219135554_add_gender_to_students.rb
198
+ - db/migrate/20180221140558_add_responsible_to_next_sges_deposits.rb
199
+ - db/migrate/20180227075126_fix_responisble_on_deposit.rb
198
200
  - lib/next_sges.rb
199
201
  - lib/next_sges/engine.rb
200
202
  - lib/next_sges/version.rb