dorsale 1.2.6 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (267) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/accounting.js +413 -0
  3. data/app/assets/javascripts/dorsale/billing_machine/all.coffee +20 -0
  4. data/app/assets/javascripts/dorsale/billing_machine/invoices.coffee +39 -0
  5. data/app/assets/javascripts/dorsale/billing_machine/quotations.coffee +38 -0
  6. data/app/assets/javascripts/dorsale/comments.coffee +4 -0
  7. data/app/assets/javascripts/dorsale/customer_vault/all.coffee +9 -0
  8. data/app/assets/javascripts/dorsale/datepicker.coffee +1 -1
  9. data/app/assets/javascripts/dorsale/flyboy/all.coffee +0 -0
  10. data/app/assets/javascripts/dorsale/forms.coffee +20 -6
  11. data/app/assets/stylesheets/dorsale/billing_machine/all.sass +15 -0
  12. data/app/assets/stylesheets/dorsale/bootstrap_nav_left.sass +34 -0
  13. data/app/assets/stylesheets/dorsale/comments.sass +25 -3
  14. data/app/assets/stylesheets/dorsale/customer_vault/all.sass +89 -0
  15. data/app/assets/stylesheets/dorsale/filters.sass +4 -1
  16. data/app/assets/stylesheets/dorsale/flyboy/all.sass +52 -0
  17. data/app/assets/stylesheets/dorsale/forms.sass +19 -0
  18. data/app/controllers/dorsale/alexandrie/attachments_controller.rb +52 -0
  19. data/app/controllers/dorsale/billing_machine/application_controller.rb +15 -0
  20. data/app/controllers/dorsale/billing_machine/invoices_controller.rb +180 -0
  21. data/app/controllers/dorsale/billing_machine/quotations_controller.rb +151 -0
  22. data/app/controllers/dorsale/comments_controller.rb +64 -17
  23. data/app/controllers/dorsale/customer_vault/application_controller.rb +26 -0
  24. data/app/controllers/dorsale/customer_vault/corporations_controller.rb +100 -0
  25. data/app/controllers/dorsale/customer_vault/individuals_controller.rb +104 -0
  26. data/app/controllers/dorsale/customer_vault/links_controller.rb +92 -0
  27. data/app/controllers/dorsale/customer_vault/people_controller.rb +42 -0
  28. data/app/controllers/dorsale/flyboy/application_controller.rb +9 -0
  29. data/app/controllers/dorsale/flyboy/folders_controller.rb +124 -0
  30. data/app/controllers/dorsale/flyboy/task_comments_controller.rb +29 -0
  31. data/app/controllers/dorsale/flyboy/tasks_controller.rb +171 -0
  32. data/app/controllers/dorsale/small_data/filters_controller.rb +7 -0
  33. data/app/helpers/dorsale/alexandrie/attachments_helper.rb +17 -0
  34. data/app/helpers/dorsale/all_helpers.rb +12 -9
  35. data/app/helpers/dorsale/button_helper.rb +23 -3
  36. data/app/helpers/dorsale/comments_helper.rb +4 -0
  37. data/app/helpers/dorsale/customer_vault/application_helper.rb +98 -0
  38. data/app/helpers/dorsale/flyboy/application_helper.rb +44 -0
  39. data/app/helpers/dorsale/form_helper.rb +7 -0
  40. data/app/helpers/dorsale/link_helper.rb +3 -2
  41. data/app/helpers/dorsale/routes_helper.rb +5 -3
  42. data/app/helpers/dorsale/text_helper.rb +28 -1
  43. data/app/models/dorsale/ability_helper.rb +7 -0
  44. data/app/models/dorsale/alexandrie/ability_helper.rb +9 -0
  45. data/app/models/dorsale/alexandrie/attachment.rb +18 -0
  46. data/app/models/dorsale/billing_machine/ability_helper.rb +10 -0
  47. data/app/models/dorsale/billing_machine/id_card.rb +18 -0
  48. data/app/models/dorsale/billing_machine/invoice.rb +126 -0
  49. data/app/models/dorsale/billing_machine/invoice_line.rb +27 -0
  50. data/app/models/dorsale/billing_machine/payment_term.rb +12 -0
  51. data/app/models/dorsale/billing_machine/quotation.rb +66 -0
  52. data/app/models/dorsale/billing_machine/quotation_line.rb +25 -0
  53. data/app/models/dorsale/billing_machine/small_data/filter_for_invoices.rb +21 -0
  54. data/app/models/dorsale/billing_machine/small_data/filter_for_quotations.rb +20 -0
  55. data/app/models/dorsale/billing_machine/small_data/filter_strategy_by_customer.rb +12 -0
  56. data/app/models/dorsale/billing_machine/small_data/filter_strategy_by_payment_status.rb +23 -0
  57. data/app/models/dorsale/billing_machine/small_data/filter_strategy_by_time_period.rb +27 -0
  58. data/app/models/dorsale/comment.rb +6 -2
  59. data/app/models/dorsale/customer_vault/ability_helper.rb +9 -0
  60. data/app/models/dorsale/customer_vault/corporation.rb +12 -0
  61. data/app/models/dorsale/customer_vault/individual.rb +17 -0
  62. data/app/models/dorsale/customer_vault/link.rb +10 -0
  63. data/app/models/dorsale/customer_vault/person.rb +35 -0
  64. data/app/models/dorsale/customer_vault/small_data/filter_for_people.rb +19 -0
  65. data/app/models/dorsale/customer_vault/small_data/filter_strategy_by_tags.rb +18 -0
  66. data/app/models/dorsale/flyboy/ability_helper.rb +41 -0
  67. data/app/models/dorsale/flyboy/folder.rb +77 -0
  68. data/app/models/dorsale/flyboy/small_data/filter_for_folders.rb +19 -0
  69. data/app/models/dorsale/flyboy/small_data/filter_for_tasks.rb +19 -0
  70. data/app/models/dorsale/flyboy/small_data/filter_strategy_by_done.rb +12 -0
  71. data/app/models/dorsale/flyboy/small_data/filter_strategy_by_nothing.rb +11 -0
  72. data/app/models/dorsale/flyboy/small_data/filter_strategy_by_status.rb +15 -0
  73. data/app/models/dorsale/flyboy/task.rb +97 -0
  74. data/app/models/dorsale/flyboy/task_comment.rb +35 -0
  75. data/app/pdfs/dorsale/billing_machine/invoice_pdf.rb +209 -0
  76. data/app/pdfs/dorsale/billing_machine/quotation_pdf.rb +53 -0
  77. data/app/pdfs/dorsale/flyboy/roadmap.rb +51 -0
  78. data/app/uploaders/dorsale/alexandrie/file_uploader.rb +6 -0
  79. data/app/uploaders/dorsale/file_uploader.rb +9 -0
  80. data/app/uploaders/dorsale/image_uploader.rb +7 -0
  81. data/app/views/dorsale/_contextual.html.slim +3 -0
  82. data/app/views/dorsale/alexandrie/attachments/_form.html.slim +13 -0
  83. data/app/views/dorsale/alexandrie/attachments/_form_and_list.html.slim +2 -0
  84. data/app/views/dorsale/alexandrie/attachments/_list.html.slim +7 -0
  85. data/app/views/dorsale/billing_machine/invoices/_data_context.html.slim +10 -0
  86. data/app/views/dorsale/billing_machine/invoices/_filters.html.slim +16 -0
  87. data/app/views/dorsale/billing_machine/invoices/_form.html.slim +62 -0
  88. data/app/views/dorsale/billing_machine/invoices/_line_fields.html.slim +23 -0
  89. data/app/views/dorsale/billing_machine/invoices/_list.html.slim +30 -0
  90. data/app/views/dorsale/billing_machine/invoices/edit.html.slim +2 -0
  91. data/app/views/dorsale/billing_machine/invoices/index.html.slim +15 -0
  92. data/app/views/dorsale/billing_machine/invoices/new.html.slim +2 -0
  93. data/app/views/dorsale/billing_machine/invoices/show.html.slim +53 -0
  94. data/app/views/dorsale/billing_machine/quotations/_data_context.html.slim +10 -0
  95. data/app/views/dorsale/billing_machine/quotations/_filters.html.slim +13 -0
  96. data/app/views/dorsale/billing_machine/quotations/_form.html.slim +55 -0
  97. data/app/views/dorsale/billing_machine/quotations/_line_fields.html.slim +23 -0
  98. data/app/views/dorsale/billing_machine/quotations/_list.html.slim +30 -0
  99. data/app/views/dorsale/billing_machine/quotations/edit.html.slim +2 -0
  100. data/app/views/dorsale/billing_machine/quotations/index.html.slim +14 -0
  101. data/app/views/dorsale/billing_machine/quotations/new.html.slim +2 -0
  102. data/app/views/dorsale/billing_machine/quotations/show.html.slim +61 -0
  103. data/app/views/dorsale/comments/_comment.html.slim +23 -9
  104. data/app/views/dorsale/comments/_comments.html.slim +2 -2
  105. data/app/views/dorsale/comments/_form.html.slim +1 -1
  106. data/app/views/dorsale/comments/_list.html.slim +2 -0
  107. data/app/views/dorsale/comments/edit.html.slim +5 -0
  108. data/app/views/dorsale/customer_vault/_breadcrumb.html.slim +4 -0
  109. data/app/views/dorsale/customer_vault/corporations/_context.html.slim +20 -0
  110. data/app/views/dorsale/customer_vault/corporations/_form.html.slim +21 -0
  111. data/app/views/dorsale/customer_vault/corporations/_list_details.html.slim +20 -0
  112. data/app/views/dorsale/customer_vault/corporations/edit.html.slim +14 -0
  113. data/app/views/dorsale/customer_vault/corporations/new.html.slim +14 -0
  114. data/app/views/dorsale/customer_vault/corporations/show.html.slim +1 -0
  115. data/app/views/dorsale/customer_vault/individuals/_context.html.slim +15 -0
  116. data/app/views/dorsale/customer_vault/individuals/_form.html.slim +22 -0
  117. data/app/views/dorsale/customer_vault/individuals/_list_details.html.slim +20 -0
  118. data/app/views/dorsale/customer_vault/individuals/edit.html.slim +14 -0
  119. data/app/views/dorsale/customer_vault/individuals/new.html.slim +14 -0
  120. data/app/views/dorsale/customer_vault/individuals/show.html.slim +1 -0
  121. data/app/views/dorsale/customer_vault/links/_title.html.slim +7 -0
  122. data/app/views/dorsale/customer_vault/links/edit.html.slim +19 -0
  123. data/app/views/dorsale/customer_vault/links/new.html.slim +15 -0
  124. data/app/views/dorsale/customer_vault/people/_activity_tab.html.slim +5 -0
  125. data/app/views/dorsale/customer_vault/people/_comment.html.slim +1 -0
  126. data/app/views/dorsale/customer_vault/people/_context.html.slim +4 -0
  127. data/app/views/dorsale/customer_vault/people/_data_context.html.slim +32 -0
  128. data/app/views/dorsale/customer_vault/people/_filters.html.slim +15 -0
  129. data/app/views/dorsale/customer_vault/people/_index_tabs.html.slim +7 -0
  130. data/app/views/dorsale/customer_vault/people/_links_tab.html.slim +16 -0
  131. data/app/views/dorsale/customer_vault/people/_new_people_contexts.html.slim +7 -0
  132. data/app/views/dorsale/customer_vault/people/_show.html.slim +31 -0
  133. data/app/views/dorsale/customer_vault/people/_tasks_tab.html.slim +1 -0
  134. data/app/views/dorsale/customer_vault/people/activity.slim +20 -0
  135. data/app/views/dorsale/customer_vault/people/list.html.slim +27 -0
  136. data/app/views/dorsale/flyboy/_filters.html.slim +12 -0
  137. data/app/views/dorsale/flyboy/folders/_actions.html.slim +15 -0
  138. data/app/views/dorsale/flyboy/folders/_context.html.slim +18 -0
  139. data/app/views/dorsale/flyboy/folders/_form.html.slim +22 -0
  140. data/app/views/dorsale/flyboy/folders/_list.html.slim +30 -0
  141. data/app/views/dorsale/flyboy/folders/edit.html.slim +2 -0
  142. data/app/views/dorsale/flyboy/folders/index.html.slim +8 -0
  143. data/app/views/dorsale/flyboy/folders/new.html.slim +2 -0
  144. data/app/views/dorsale/flyboy/folders/show.html.slim +9 -0
  145. data/app/views/dorsale/flyboy/task_comments/_list.html.slim +31 -0
  146. data/app/views/dorsale/flyboy/tasks/_actions.html.slim +9 -0
  147. data/app/views/dorsale/flyboy/tasks/_context.html.slim +15 -0
  148. data/app/views/dorsale/flyboy/tasks/_form.html.slim +29 -0
  149. data/app/views/dorsale/flyboy/tasks/_list.html.slim +43 -0
  150. data/app/views/dorsale/flyboy/tasks/_tasks_for_taskable.html.slim +6 -0
  151. data/app/views/dorsale/flyboy/tasks/edit.html.slim +2 -0
  152. data/app/views/dorsale/flyboy/tasks/index.html.slim +10 -0
  153. data/app/views/dorsale/flyboy/tasks/index.xls.erb +29 -0
  154. data/app/views/dorsale/flyboy/tasks/new.html.slim +2 -0
  155. data/app/views/dorsale/flyboy/tasks/show.html.slim +14 -0
  156. data/app/views/dorsale/search/_form.html.slim +6 -0
  157. data/config/locales/alexandrie.fr.yml +8 -0
  158. data/config/locales/billing_machine.fr.yml +50 -0
  159. data/config/locales/common.fr.yml +142 -0
  160. data/config/locales/customer_vault.fr.yml +69 -0
  161. data/config/locales/flyboy.fr.yml +66 -0
  162. data/config/locales/fr.yml +8 -87
  163. data/config/routes.rb +50 -1
  164. data/db/migrate/20141010140200_create_dorsale_addresses.rb +1 -1
  165. data/db/migrate/20150312083147_create_dorsale_comments.rb +3 -3
  166. data/db/migrate/20150616074852_create_dorsale_alexandrie_attachments.rb +9 -0
  167. data/db/migrate/20150622075000_create_flyboy.rb +50 -0
  168. data/db/migrate/20150622075038_create_billing_machine.rb +121 -0
  169. data/db/migrate/20150622105217_create_customer_vault.rb +49 -0
  170. data/db/migrate/20150623093218_dorsale_v2_changes.rb +68 -0
  171. data/db/migrate/20150625093326_billing_machine_quotations_add_expires_at.rb +5 -0
  172. data/db/migrate/20150625131155_billing_machine_add_tracking_ids.rb +6 -0
  173. data/lib/active_record_comma_type_cast.rb +12 -0
  174. data/lib/dorsale/alexandrie/prawn.rb +17 -0
  175. data/lib/dorsale/engine.rb +19 -0
  176. data/lib/dorsale/file_loader.rb +10 -0
  177. data/lib/dorsale/model_i18n.rb +21 -0
  178. data/lib/dorsale/model_to_s.rb +13 -0
  179. data/lib/dorsale/polymorphic_id.rb +2 -0
  180. data/lib/dorsale/version.rb +1 -1
  181. data/spec/controllers/dorsale/alexandrie/attachments_controller_spec.rb +47 -0
  182. data/spec/controllers/dorsale/comments_controller_spec.rb +45 -0
  183. data/spec/controllers/dorsale/customer_vault/corporations_controller_spec.rb +132 -0
  184. data/spec/controllers/dorsale/customer_vault/individuals_controller_spec.rb +130 -0
  185. data/spec/controllers/dorsale/customer_vault/people_controller_spec.rb +59 -0
  186. data/spec/controllers/dorsale/flyboy/folders_controller_spec.rb +111 -0
  187. data/spec/controllers/dorsale/flyboy/task_comments_controller_spec.rb +16 -0
  188. data/spec/controllers/dorsale/flyboy/tasks_controller_spec.rb +234 -0
  189. data/spec/dummy/app/assets/javascripts/application.coffee +10 -0
  190. data/spec/dummy/app/assets/stylesheets/application.sass +9 -0
  191. data/spec/dummy/app/controllers/application_controller.rb +4 -0
  192. data/spec/dummy/app/models/ability.rb +16 -0
  193. data/spec/dummy/app/models/dummy_model.rb +2 -0
  194. data/spec/dummy/app/views/layouts/application.html.erb +10 -3
  195. data/spec/dummy/config/application.rb +4 -2
  196. data/spec/dummy/db/development.sqlite3 +0 -0
  197. data/spec/dummy/db/migrate/20150616082916_create_dorsale_dummy_models.rb +8 -0
  198. data/spec/dummy/db/migrate/20150624081204_acts_as_taggable_on_migration.acts_as_taggable_on_engine.rb +31 -0
  199. data/spec/dummy/db/migrate/20150624081205_add_missing_unique_indices.acts_as_taggable_on_engine.rb +20 -0
  200. data/spec/dummy/db/migrate/20150624081206_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb +15 -0
  201. data/spec/dummy/db/migrate/20150624081207_add_missing_taggable_index.acts_as_taggable_on_engine.rb +10 -0
  202. data/spec/dummy/db/migrate/20150624081208_change_collation_for_tag_names.acts_as_taggable_on_engine.rb +10 -0
  203. data/spec/dummy/db/schema.rb +243 -5
  204. data/spec/dummy/db/seed.rb +1 -0
  205. data/spec/dummy/db/test.sqlite3 +0 -0
  206. data/spec/dummy/log/development.log +227 -0
  207. data/spec/dummy/log/test.log +2740 -25
  208. data/spec/dummy/{app/assets/stylesheets/application.css → tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705} +0 -0
  209. data/spec/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  210. data/spec/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  211. data/spec/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  212. data/spec/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  213. data/spec/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  214. data/spec/factories/alexandrie_attachments.rb +12 -0
  215. data/spec/factories/billing_machine_id_cards.rb +26 -0
  216. data/spec/factories/billing_machine_invoice_lines.rb +11 -0
  217. data/spec/factories/billing_machine_invoices.rb +12 -0
  218. data/spec/factories/billing_machine_payment_terms.rb +5 -0
  219. data/spec/factories/billing_machine_quotation_lines.rb +12 -0
  220. data/spec/factories/billing_machine_quotations.rb +12 -0
  221. data/spec/factories/customer_vault_corporations.rb +14 -0
  222. data/spec/factories/customer_vault_individuals.rb +19 -0
  223. data/spec/factories/customer_vault_links.rb +7 -0
  224. data/spec/factories/dorsale_addresses.rb +6 -8
  225. data/spec/factories/dorsale_comments.rb +8 -0
  226. data/spec/factories/flyboy_folders.rb +7 -0
  227. data/spec/factories/flyboy_task_comments.rb +8 -0
  228. data/spec/factories/flyboy_tasks.rb +12 -0
  229. data/spec/files/pdf.pdf +0 -0
  230. data/spec/helpers/dorsale/flyboy/application_helper_spec.rb +91 -0
  231. data/spec/helpers/dorsale/link_helper_spec.rb +1 -0
  232. data/spec/helpers/dorsale/text_helper_spec.rb +33 -9
  233. data/spec/models/dorsale/ability_helper_spec.rb +11 -0
  234. data/spec/models/dorsale/alexandrie/ability_helper_spec.rb +10 -0
  235. data/spec/models/dorsale/alexandrie/attachment_spec.rb +12 -0
  236. data/spec/models/dorsale/billing_machine/id_card_spec.rb +12 -0
  237. data/spec/models/dorsale/billing_machine/invoice_line_spec.rb +50 -0
  238. data/spec/models/dorsale/billing_machine/invoice_spec.rb +156 -0
  239. data/spec/models/dorsale/billing_machine/quotation_line_spec.rb +36 -0
  240. data/spec/models/dorsale/billing_machine/quotation_spec.rb +91 -0
  241. data/spec/models/dorsale/comment_spec.rb +11 -0
  242. data/spec/models/dorsale/customer_vault/corporation_spec.rb +17 -0
  243. data/spec/models/dorsale/customer_vault/individual_spec.rb +17 -0
  244. data/spec/models/dorsale/customer_vault/link_spec.rb +12 -0
  245. data/spec/models/dorsale/customer_vault/person_spec.rb +44 -0
  246. data/spec/models/dorsale/flyboy/ability_spec.rb +148 -0
  247. data/spec/models/dorsale/flyboy/folder_spec.rb +103 -0
  248. data/spec/models/dorsale/flyboy/task_comment_spec.rb +52 -0
  249. data/spec/models/dorsale/flyboy/task_spec.rb +83 -0
  250. data/spec/pdfs/dorsale/billing_machine/invoice_pdf_spec.rb +252 -0
  251. data/spec/pdfs/dorsale/billing_machine/quotation_pdf_spec.rb +255 -0
  252. data/spec/rails_helper.rb +11 -11
  253. data/spec/routing/dorsale/alexandrie/attachments_routing_spec.rb +19 -0
  254. data/spec/routing/dorsale/billing_machine/invoices_routing_spec.rb +53 -0
  255. data/spec/routing/dorsale/billing_machine/quotations_routing_spec.rb +43 -0
  256. data/spec/routing/dorsale/comments_routing_spec.rb +25 -0
  257. data/spec/routing/dorsale/customer_vault/corporations_routing_spec.rb +66 -0
  258. data/spec/routing/dorsale/customer_vault/individual_routing_spec.rb +66 -0
  259. data/spec/routing/dorsale/customer_vault/people_routing_spec.rb +22 -0
  260. data/spec/routing/dorsale/flyboy/folders_routing_spec.rb +44 -0
  261. data/spec/routing/dorsale/flyboy/task_comments_routing_spec.rb +12 -0
  262. data/spec/routing/dorsale/flyboy/tasks_routing_spec.rb +44 -0
  263. data/spec/spec_helper.rb +0 -6
  264. metadata +439 -10
  265. data/MIT-LICENSE +0 -20
  266. data/README.rdoc +0 -3
  267. data/spec/dummy/app/assets/javascripts/application.js +0 -13
@@ -0,0 +1,27 @@
1
+ module Dorsale
2
+ module BillingMachine
3
+ class InvoiceLine < ActiveRecord::Base
4
+ self.table_name = "dorsale_billing_machine_invoice_lines"
5
+
6
+ belongs_to :invoice, inverse_of: :lines
7
+
8
+ default_scope -> {
9
+ order(created_at: :asc)
10
+ }
11
+
12
+ before_save :update_total
13
+
14
+ def update_total
15
+ self.quantity ||= 0
16
+ self.unit_price ||= 0
17
+ self.total = self.quantity * self.unit_price
18
+ end
19
+
20
+ # ???
21
+ after_save do
22
+ self.invoice.reload.save
23
+ end
24
+
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,12 @@
1
+ module Dorsale
2
+ module BillingMachine
3
+ class PaymentTerm < ActiveRecord::Base
4
+ self.table_name = "dorsale_billing_machine_payment_terms"
5
+
6
+ def name
7
+ label
8
+ end
9
+
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,66 @@
1
+ module Dorsale
2
+ module BillingMachine
3
+ class Quotation < ActiveRecord::Base
4
+ self.table_name = "dorsale_billing_machine_quotations"
5
+
6
+ belongs_to :customer, polymorphic: true
7
+ belongs_to :id_card
8
+ belongs_to :payment_term
9
+ has_many :lines,
10
+ :inverse_of => :quotation,
11
+ :dependent => :destroy,
12
+ :class_name => ::Dorsale::BillingMachine::QuotationLine
13
+
14
+ has_many :attachments,
15
+ :as => :attachable,
16
+ :dependent => :destroy,
17
+ :class_name => ::Dorsale::Alexandrie::Attachment
18
+
19
+ accepts_nested_attributes_for :lines, allow_destroy: true
20
+
21
+ polymorphic_id_for :customer
22
+
23
+ validates :id_card, presence: true
24
+ validates :date, presence: true
25
+
26
+ # simple_form
27
+ validates :id_card_id, presence: true
28
+
29
+ def initialize(*args)
30
+ super
31
+ self.date = Date.today if date.nil?
32
+ self.expires_at = date + 1.month if expires_at.nil?
33
+ self.vat_rate = 20 if vat_rate.nil?
34
+ end
35
+
36
+ before_create :assign_unique_index
37
+ before_create :assign_tracking_id
38
+
39
+ def assign_unique_index
40
+ if unique_index.nil?
41
+ self.unique_index = self.class.all.pluck(:unique_index).max.to_i.next
42
+ end
43
+ end
44
+
45
+ def assign_tracking_id
46
+ self.tracking_id = date.year.to_s + "-" + unique_index.to_s.rjust(2, "0")
47
+ end
48
+
49
+ before_save :update_total
50
+
51
+ def update_total
52
+ self.vat_rate = 0 if vat_rate.nil?
53
+ self.total_duty = lines.pluck(:total).sum
54
+ self.vat_amount = total_duty * vat_rate / 100.0
55
+ self.total_all_taxes = total_duty + vat_amount
56
+ end
57
+
58
+ def pdf
59
+ pdf = ::Dorsale::BillingMachine::QuotationPdf.new(self)
60
+ pdf.build
61
+ pdf
62
+ end
63
+
64
+ end # Quotation
65
+ end # BillingMachine
66
+ end # Dorsale
@@ -0,0 +1,25 @@
1
+ module Dorsale
2
+ module BillingMachine
3
+ class QuotationLine < ActiveRecord::Base
4
+ self.table_name = "dorsale_billing_machine_quotation_lines"
5
+
6
+ belongs_to :quotation, inverse_of: :lines
7
+ default_scope -> {
8
+ order(:created_at => :asc)
9
+ }
10
+
11
+ before_save :update_total
12
+
13
+ def update_total
14
+ self.quantity ||= 0
15
+ self.unit_price ||= 0
16
+ self.total = self.quantity * self.unit_price
17
+ end
18
+
19
+ # ???
20
+ after_save do
21
+ self.quotation.reload.save
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+ module Dorsale
2
+ module BillingMachine
3
+ module SmallData
4
+ class FilterForInvoices < ::Dorsale::SmallData::Filter
5
+ STRATEGIES = {
6
+ 'customer_guid' => FilterStrategyByCustomer.new('invoices'),
7
+ 'time_period' => FilterStrategyByTimePeriod.new('invoices'),
8
+ 'payment_status' => FilterStrategyByPaymentStatus.new('invoices'),
9
+ }
10
+
11
+ def strategy key
12
+ STRATEGIES[key]
13
+ end
14
+
15
+ def target
16
+ 'invoices'
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ module Dorsale
2
+ module BillingMachine
3
+ module SmallData
4
+ class FilterForQuotations < ::Dorsale::SmallData::Filter
5
+ STRATEGIES = {
6
+ 'customer_guid' => FilterStrategyByCustomer.new('quotations'),
7
+ 'time_period' => FilterStrategyByTimePeriod.new('quotations'),
8
+ }
9
+
10
+ def strategy key
11
+ STRATEGIES[key]
12
+ end
13
+
14
+ def target
15
+ 'quotations'
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,12 @@
1
+ module Dorsale
2
+ module BillingMachine
3
+ module SmallData
4
+ class FilterStrategyByCustomer < ::Dorsale::SmallData::FilterStrategy
5
+ def do_apply query
6
+ type, id = @value.split("-")
7
+ query.where(customer_type: type, customer_id: id)
8
+ end
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,23 @@
1
+ module Dorsale
2
+ module BillingMachine
3
+ module SmallData
4
+ class FilterStrategyByPaymentStatus < ::Dorsale::SmallData::FilterStrategy
5
+ def do_apply query
6
+ table_name = query.model.table_name
7
+
8
+ if @value == "paid"
9
+ return query.where("#{table_name}.paid = ?", true)
10
+ elsif @value == "unpaid"
11
+ return query.where("#{table_name}.paid = ?", false)
12
+ elsif @value == "pending"
13
+ return query.where("#{table_name}.paid = ? and #{table_name}.due_date >= ?", false, Date.today)
14
+ elsif @value == "late"
15
+ return query.where("#{table_name}.paid = ? and (#{table_name}.due_date < ? or #{table_name}.due_date is null)", false, Date.today)
16
+ else
17
+ return query
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,27 @@
1
+ module Dorsale
2
+ module BillingMachine
3
+ module SmallData
4
+ class FilterStrategyByTimePeriod < ::Dorsale::SmallData::FilterStrategy
5
+ def do_apply query
6
+ if query.model.attribute_names.include?("day")
7
+ field = :day
8
+ else
9
+ field = :date
10
+ end
11
+
12
+ criteria = "#{query.model.table_name}.#{field}"
13
+
14
+ if @value == "today"
15
+ return query.where("#{criteria} >= ?", Date.today)
16
+ elsif @value == "week"
17
+ return query.where("#{criteria} >= ?", Date.today.at_beginning_of_week)
18
+ elsif @value == "month"
19
+ return query.where("#{criteria} >= ?", Date.today.at_beginning_of_month)
20
+ else
21
+ return query
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,9 +1,13 @@
1
1
  module Dorsale
2
2
  class Comment < ActiveRecord::Base
3
- belongs_to :user, polymorphic: true
3
+ belongs_to :user
4
4
  belongs_to :commentable, polymorphic: true
5
-
5
+
6
6
  validates :commentable, presence: true
7
7
  validates :text, presence: true
8
+
9
+ default_scope -> {
10
+ order(created_at: :desc)
11
+ }
8
12
  end
9
13
  end
@@ -0,0 +1,9 @@
1
+ module Dorsale
2
+ module CustomerVault
3
+ module AbilityHelper
4
+ def define_dorsale_customer_vault_abilities
5
+ can [:list, :create, :read, :update, :delete], ::Dorsale::CustomerVault::Person
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ module Dorsale
2
+ module CustomerVault
3
+ class Corporation < Person
4
+ self.table_name = "dorsale_customer_vault_corporations"
5
+
6
+ include ::Dorsale::Search
7
+
8
+ validates :name, presence: true
9
+
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,17 @@
1
+ module Dorsale
2
+ module CustomerVault
3
+ class Individual < ::Dorsale::CustomerVault::Person
4
+ self.table_name = "dorsale_customer_vault_individuals"
5
+
6
+ include ::Dorsale::Search
7
+
8
+ validates :first_name, presence: true
9
+ validates :last_name, presence: true
10
+
11
+ def name
12
+ [self.last_name, self.first_name].join(", ")
13
+ end
14
+
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,10 @@
1
+ module Dorsale
2
+ module CustomerVault
3
+ class Link < ActiveRecord::Base
4
+ self.table_name = "dorsale_customer_vault_links"
5
+
6
+ belongs_to :alice, polymorphic: true
7
+ belongs_to :bob, polymorphic: true
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,35 @@
1
+ module Dorsale
2
+ module CustomerVault
3
+ class Person < ActiveRecord::Base
4
+ self.abstract_class = true
5
+
6
+ after_destroy :destroy_links
7
+
8
+ acts_as_taggable
9
+
10
+ def tags_on(*args)
11
+ super(*args).order(:name)
12
+ end
13
+
14
+ has_many :comments, -> { order("id DESC") }, class_name: ::Dorsale::Comment, as: :commentable
15
+ has_one :address, class_name: ::Dorsale::Address, as: :addressable, inverse_of: :addressable
16
+ has_many :tasks, class_name: ::Dorsale::Flyboy::Task, as: :taskable
17
+ accepts_nested_attributes_for :address, allow_destroy: true
18
+
19
+ def self.list
20
+ ::Dorsale::CustomerVault::Individual.all + ::Dorsale::CustomerVault::Corporation.all
21
+ end
22
+
23
+ def links
24
+ a = Link.where(alice_id: self.id, alice_type: self.class).map {|l| {title: l.title, person: l.bob, origin: l}}
25
+ b = Link.where(bob_id: self.id, bob_type: self.class).map {|l| {title: l.title, person: l.alice, origin: l}}
26
+ return a + b
27
+ end
28
+
29
+ def destroy_links
30
+ links.map{ |l| l[:origin].destroy! }
31
+ end
32
+
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,19 @@
1
+ module Dorsale
2
+ module CustomerVault
3
+ module SmallData
4
+ class FilterForPeople < ::Dorsale::SmallData::Filter
5
+ STRATEGIES = {
6
+ "tags" => ::Dorsale::CustomerVault::SmallData::FilterStrategyByTags.new("people")
7
+ }
8
+
9
+ def strategy key
10
+ STRATEGIES[key]
11
+ end
12
+
13
+ def target
14
+ "people"
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ module Dorsale
2
+ module CustomerVault
3
+ module SmallData
4
+ class FilterStrategyByTags < ::Dorsale::SmallData::FilterStrategy
5
+ def do_apply(query)
6
+ @value = [*@value].flatten.select{ |v| v.present? }
7
+
8
+ if @value.any?
9
+ query.tagged_with(@value)
10
+ else
11
+ query
12
+ end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,41 @@
1
+ module Dorsale
2
+ module Flyboy
3
+ module AbilityHelper
4
+ def define_dorsale_flyboy_abilities
5
+ # Allowed actions (all by default)
6
+ can [:list, :create, :read, :update, :delete, :open, :close], ::Dorsale::Flyboy::Folder
7
+ can [:list, :create, :read, :update, :delete, :complete, :snooze], ::Dorsale::Flyboy::Task
8
+
9
+ # Restricted actions
10
+
11
+ cannot [:update, :delete], ::Dorsale::Flyboy::Folder do |folder|
12
+ folder.closed?
13
+ end
14
+
15
+ cannot :close, ::Dorsale::Flyboy::Folder do |folder|
16
+ not folder.may_close?
17
+ end
18
+
19
+ cannot :open, ::Dorsale::Flyboy::Folder do |folder|
20
+ not folder.may_open?
21
+ end
22
+
23
+ cannot :create, ::Dorsale::Flyboy::Task do |task|
24
+ task.taskable.present? && cannot?(:show, task.taskable)
25
+ end
26
+
27
+ cannot [:create, :update, :delete], ::Dorsale::Flyboy::Task do |task|
28
+ task.taskable.is_a?(::Dorsale::Flyboy::Folder) && task.taskable.closed?
29
+ end
30
+
31
+ cannot :complete, ::Dorsale::Flyboy::Task do |task|
32
+ task.done?
33
+ end
34
+
35
+ cannot :snooze, ::Dorsale::Flyboy::Task do |task|
36
+ task.done? || task.reminder >= Date.today
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,77 @@
1
+ require "dorsale/search"
2
+ require "dorsale/polymorphic_id"
3
+
4
+ module Dorsale
5
+ module Flyboy
6
+ class Folder < ActiveRecord::Base
7
+ self.table_name = "dorsale_flyboy_folders"
8
+
9
+ include AASM
10
+ include ::Dorsale::Search
11
+
12
+ paginates_per 50
13
+
14
+ aasm(column: "status", whiny_transitions: false) do
15
+ state :open, initial: true
16
+ state :closed
17
+
18
+ event :close, if: :no_undone_tasks? do
19
+ transitions from: [:open], to: :closed
20
+ end
21
+
22
+ event :open do
23
+ transitions from: [:closed], to: :open
24
+ end
25
+ end
26
+
27
+ belongs_to :folderable, polymorphic: true
28
+ has_many :tasks, dependent: :destroy, as: :taskable
29
+
30
+ validates :name, presence: true
31
+ validates :status, inclusion: {
32
+ in: proc { ::Dorsale::Flyboy::Folder.aasm.states.map(&:to_s) }
33
+ }
34
+
35
+ def initialize(*args)
36
+ super
37
+ self.progress = 0 if progress.nil?
38
+ end
39
+
40
+ def no_undone_tasks?
41
+ tasks.where(done: false).count == 0
42
+ end
43
+
44
+ def revision
45
+ "#{tracking} #{version}"
46
+ end
47
+
48
+ before_create :create_tracking
49
+
50
+ def create_tracking
51
+ dailycounter = Folder.where("DATE(created_at) = ?", Date.today).count + 1
52
+ self.tracking = "#{Time.now.strftime("%y%m%d")}-#{dailycounter}"
53
+ end
54
+
55
+ before_save :update_version
56
+
57
+ def update_version
58
+ self.version = 0 if self.version.nil?
59
+ self.version = self.version + 1
60
+ end
61
+
62
+ def update_progress
63
+ if tasks.count.zero?
64
+ self.progress = 0
65
+ else
66
+ self.progress = tasks.sum(:progress) / tasks.count
67
+ end
68
+ end
69
+
70
+ def update_progress!
71
+ update_progress
72
+ save
73
+ end
74
+
75
+ end
76
+ end
77
+ end