stockor 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
Files changed (259) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -0
  3. data/Gemfile +11 -0
  4. data/Gemfile.lock +220 -0
  5. data/Guardfile +13 -0
  6. data/README.md +7 -0
  7. data/Rakefile +7 -0
  8. data/client/skr/Extension.coffee +12 -0
  9. data/client/skr/components/.gitkeep +0 -0
  10. data/client/skr/components/address/Address.coffee +21 -0
  11. data/client/skr/components/address/address.html +20 -0
  12. data/client/skr/index.js +21 -0
  13. data/client/skr/models/Address.coffee +17 -0
  14. data/client/skr/models/Base.coffee +8 -0
  15. data/client/skr/models/Customer.coffee +26 -0
  16. data/client/skr/models/GlAccount.coffee +10 -0
  17. data/client/skr/models/GlManualEntry.coffee +11 -0
  18. data/client/skr/models/GlPeriod.coffee +10 -0
  19. data/client/skr/models/GlPosting.coffee +15 -0
  20. data/client/skr/models/GlTransaction.coffee +16 -0
  21. data/client/skr/models/IaLine.coffee +19 -0
  22. data/client/skr/models/IaReason.coffee +12 -0
  23. data/client/skr/models/InvLine.coffee +27 -0
  24. data/client/skr/models/InventoryAdjustment.coffee +17 -0
  25. data/client/skr/models/Invoice.coffee +31 -0
  26. data/client/skr/models/Location.coffee +15 -0
  27. data/client/skr/models/PaymentTerm.coffee +11 -0
  28. data/client/skr/models/PickTicket.coffee +19 -0
  29. data/client/skr/models/PoLine.coffee +27 -0
  30. data/client/skr/models/PoReceipt.coffee +20 -0
  31. data/client/skr/models/PorLine.coffee +26 -0
  32. data/client/skr/models/PtLine.coffee +27 -0
  33. data/client/skr/models/PurchaseOrder.coffee +23 -0
  34. data/client/skr/models/SalesOrder.coffee +32 -0
  35. data/client/skr/models/Sku.coffee +21 -0
  36. data/client/skr/models/SkuLoc.coffee +21 -0
  37. data/client/skr/models/SkuTran.coffee +23 -0
  38. data/client/skr/models/SkuVendor.coffee +19 -0
  39. data/client/skr/models/SoLine.coffee +27 -0
  40. data/client/skr/models/Uom.coffee +17 -0
  41. data/client/skr/models/Vendor.coffee +28 -0
  42. data/client/skr/models/VoLine.coffee +23 -0
  43. data/client/skr/models/Voucher.coffee +22 -0
  44. data/client/skr/models/mixins/CodeField.coffee +5 -0
  45. data/client/skr/screens/.gitkeep +0 -0
  46. data/client/skr/screens/Base.coffee +3 -0
  47. data/client/skr/screens/base/index.js +5 -0
  48. data/client/skr/screens/base/index.scss +9 -0
  49. data/client/skr/screens/base/layout.html +3 -0
  50. data/client/skr/screens/customer-maint/CustomerMaint.coffee +49 -0
  51. data/client/skr/screens/customer-maint/index.js +5 -0
  52. data/client/skr/screens/customer-maint/index.scss +9 -0
  53. data/client/skr/screens/customer-maint/layout.html +32 -0
  54. data/client/skr/styles.scss +1 -0
  55. data/client/skr/views/.gitkeep +0 -0
  56. data/client/skr/views/Base.coffee +5 -0
  57. data/config/database.yml +9 -0
  58. data/config/lanes.rb +7 -0
  59. data/config/routes.rb +39 -0
  60. data/config/screens.rb +17 -0
  61. data/config.ru +5 -0
  62. data/db/.gitkeep +0 -0
  63. data/db/migrate/20120110142845_create_skr_sequential_ids.rb +35 -0
  64. data/db/migrate/20140202185309_create_skr_gl_accounts.rb +15 -0
  65. data/db/migrate/20140202193316_create_skr_gl_periods.rb +16 -0
  66. data/db/migrate/20140202193318_create_skr_gl_transactions.rb +14 -0
  67. data/db/migrate/20140202193319_create_skr_gl_postings.rb +16 -0
  68. data/db/migrate/20140202193700_create_skr_gl_manual_entries.rb +13 -0
  69. data/db/migrate/20140213040608_create_skr_payment_terms.rb +16 -0
  70. data/db/migrate/20140220031700_create_skr_addresses.rb +19 -0
  71. data/db/migrate/20140220031800_create_skr_locations.rb +19 -0
  72. data/db/migrate/20140220190836_create_skr_vendors.rb +22 -0
  73. data/db/migrate/20140220203029_create_skr_customers.rb +22 -0
  74. data/db/migrate/20140224034759_create_skr_skus.rb +22 -0
  75. data/db/migrate/20140225032853_create_skr_sku_locs.rb +21 -0
  76. data/db/migrate/20140320030501_create_skr_uoms.rb +19 -0
  77. data/db/migrate/20140321031604_create_skr_sku_vendors.rb +18 -0
  78. data/db/migrate/20140322012143_create_skr_ia_reasons.rb +14 -0
  79. data/db/migrate/20140322014401_create_skr_inventory_adjustments.rb +16 -0
  80. data/db/migrate/20140322023453_create_skr_ia_lines.rb +18 -0
  81. data/db/migrate/20140322035024_create_skr_sku_trans.rb +21 -0
  82. data/db/migrate/20140322223912_create_skr_sales_orders.rb +27 -0
  83. data/db/migrate/20140322223920_create_skr_so_lines.rb +25 -0
  84. data/db/migrate/20140323001446_create_so_details_view.rb +81 -0
  85. data/db/migrate/20140327202102_create_skr_purchase_orders.rb +20 -0
  86. data/db/migrate/20140327202107_create_skr_po_lines.rb +25 -0
  87. data/db/migrate/20140327202207_create_skr_pick_tickets.rb +16 -0
  88. data/db/migrate/20140327202209_create_skr_pt_lines.rb +23 -0
  89. data/db/migrate/20140327224000_create_skr_invoices.rb +25 -0
  90. data/db/migrate/20140327224002_create_skr_inv_lines.rb +23 -0
  91. data/db/migrate/20140330232808_create_skr_sku_loc_details_view.rb +31 -0
  92. data/db/migrate/20140330232810_create_skr_sku_qty_details_view.rb +48 -0
  93. data/db/migrate/20140400164729_create_skr_vouchers.rb +22 -0
  94. data/db/migrate/20140400164733_create_skr_vo_lines.rb +21 -0
  95. data/db/migrate/20140401164729_create_skr_po_receipt.rb +16 -0
  96. data/db/migrate/20140401164740_create_skr_por_line.rb +21 -0
  97. data/db/migrate/20140422024010_create_skr_inv_details_view.rb +42 -0
  98. data/db/schema.sql +2662 -0
  99. data/db/seed/chart_of_accounts.yml +168 -0
  100. data/db/seed/payment_terms.yml +60 -0
  101. data/db/seed.rb +29 -0
  102. data/lib/skr/access_roles.rb +28 -0
  103. data/lib/skr/concerns/acts_as_uom.rb +47 -0
  104. data/lib/skr/concerns/code_identifier.rb +43 -0
  105. data/lib/skr/concerns/gl_tran_extensions.rb +18 -0
  106. data/lib/skr/concerns/has_gl_transaction.rb +67 -0
  107. data/lib/skr/concerns/has_sku_loc_lines.rb +47 -0
  108. data/lib/skr/concerns/immutable_model.rb +32 -0
  109. data/lib/skr/concerns/inv_extensions.rb +24 -0
  110. data/lib/skr/concerns/is_order_like.rb +47 -0
  111. data/lib/skr/concerns/is_sku_loc_line.rb +65 -0
  112. data/lib/skr/concerns/locked_fields.rb +84 -0
  113. data/lib/skr/concerns/pt_extensions.rb +22 -0
  114. data/lib/skr/concerns/random_hash_code.rb +40 -0
  115. data/lib/skr/concerns/so_extensions.rb +30 -0
  116. data/lib/skr/concerns/state_machine.rb +61 -0
  117. data/lib/skr/concerns/visible_id_identifier.rb +53 -0
  118. data/lib/skr/configuration.rb +68 -0
  119. data/lib/skr/db/migration_helpers.rb +178 -0
  120. data/lib/skr/extension.rb +23 -0
  121. data/lib/skr/model.rb +19 -0
  122. data/lib/skr/models/address.rb +97 -0
  123. data/lib/skr/models/business_entity.rb +29 -0
  124. data/lib/skr/models/customer.rb +35 -0
  125. data/lib/skr/models/gl_account.rb +56 -0
  126. data/lib/skr/models/gl_manual_entry.rb +31 -0
  127. data/lib/skr/models/gl_period.rb +13 -0
  128. data/lib/skr/models/gl_posting.rb +54 -0
  129. data/lib/skr/models/gl_transaction.rb +175 -0
  130. data/lib/skr/models/ia_line.rb +129 -0
  131. data/lib/skr/models/ia_reason.rb +16 -0
  132. data/lib/skr/models/inv_line.rb +90 -0
  133. data/lib/skr/models/inventory_adjustment.rb +60 -0
  134. data/lib/skr/models/invoice.rb +159 -0
  135. data/lib/skr/models/location.rb +31 -0
  136. data/lib/skr/models/payment_term.rb +30 -0
  137. data/lib/skr/models/pick_ticket.rb +71 -0
  138. data/lib/skr/models/po_line.rb +69 -0
  139. data/lib/skr/models/po_receipt.rb +51 -0
  140. data/lib/skr/models/por_line.rb +80 -0
  141. data/lib/skr/models/pt_line.rb +74 -0
  142. data/lib/skr/models/purchase_order.rb +112 -0
  143. data/lib/skr/models/sales_order.rb +159 -0
  144. data/lib/skr/models/sequential_id.rb +23 -0
  145. data/lib/skr/models/sku.rb +99 -0
  146. data/lib/skr/models/sku_loc.rb +94 -0
  147. data/lib/skr/models/sku_tran.rb +111 -0
  148. data/lib/skr/models/sku_vendor.rb +26 -0
  149. data/lib/skr/models/so_line.rb +159 -0
  150. data/lib/skr/models/uom.rb +63 -0
  151. data/lib/skr/models/user_proxy.rb +60 -0
  152. data/lib/skr/models/vendor.rb +33 -0
  153. data/lib/skr/models/vo_line.rb +35 -0
  154. data/lib/skr/models/voucher.rb +119 -0
  155. data/lib/skr/standard_pricing_provider.rb +14 -0
  156. data/lib/skr/version.rb +3 -0
  157. data/lib/skr.rb +18 -0
  158. data/lib/stockor.rb +4 -0
  159. data/lib/tasks/debug-activity.rake +58 -0
  160. data/log/test.log +0 -0
  161. data/spec/fixtures/skr/address.yml +2 -0
  162. data/spec/fixtures/skr/customer.yml +2 -0
  163. data/spec/fixtures/skr/gl_account.yml +2 -0
  164. data/spec/fixtures/skr/gl_manual_entry.yml +2 -0
  165. data/spec/fixtures/skr/gl_period.yml +2 -0
  166. data/spec/fixtures/skr/gl_posting.yml +2 -0
  167. data/spec/fixtures/skr/gl_transaction.yml +2 -0
  168. data/spec/fixtures/skr/ia_line.yml +2 -0
  169. data/spec/fixtures/skr/ia_reason.yml +2 -0
  170. data/spec/fixtures/skr/inv_line.yml +2 -0
  171. data/spec/fixtures/skr/inventory_adjustment.yml +2 -0
  172. data/spec/fixtures/skr/invoice.yml +2 -0
  173. data/spec/fixtures/skr/location.yml +2 -0
  174. data/spec/fixtures/skr/payment_term.yml +2 -0
  175. data/spec/fixtures/skr/pick_ticket.yml +2 -0
  176. data/spec/fixtures/skr/po_line.yml +2 -0
  177. data/spec/fixtures/skr/po_receipt.yml +2 -0
  178. data/spec/fixtures/skr/por_line.yml +2 -0
  179. data/spec/fixtures/skr/pt_line.yml +2 -0
  180. data/spec/fixtures/skr/purchase_order.yml +2 -0
  181. data/spec/fixtures/skr/sales_order.yml +2 -0
  182. data/spec/fixtures/skr/sku.yml +2 -0
  183. data/spec/fixtures/skr/sku_loc.yml +2 -0
  184. data/spec/fixtures/skr/sku_tran.yml +2 -0
  185. data/spec/fixtures/skr/sku_vendor.yml +2 -0
  186. data/spec/fixtures/skr/so_line.yml +2 -0
  187. data/spec/fixtures/skr/uom.yml +2 -0
  188. data/spec/fixtures/skr/vendor.yml +2 -0
  189. data/spec/fixtures/skr/vo_line.yml +2 -0
  190. data/spec/fixtures/skr/voucher.yml +2 -0
  191. data/spec/skr/address.rb +10 -0
  192. data/spec/skr/concerns/code_identifier_spec.rb +45 -0
  193. data/spec/skr/customer.rb +10 -0
  194. data/spec/skr/gl_account.rb +10 -0
  195. data/spec/skr/gl_manual_entry.rb +10 -0
  196. data/spec/skr/gl_period.rb +10 -0
  197. data/spec/skr/gl_posting.rb +10 -0
  198. data/spec/skr/gl_transaction.rb +10 -0
  199. data/spec/skr/ia_line.rb +10 -0
  200. data/spec/skr/ia_reason.rb +10 -0
  201. data/spec/skr/inv_line.rb +10 -0
  202. data/spec/skr/inventory_adjustment.rb +10 -0
  203. data/spec/skr/invoice.rb +10 -0
  204. data/spec/skr/location.rb +10 -0
  205. data/spec/skr/models/AddressSpec.coffee +5 -0
  206. data/spec/skr/models/CustomerSpec.coffee +5 -0
  207. data/spec/skr/models/GlAccountSpec.coffee +5 -0
  208. data/spec/skr/models/GlManualEntrySpec.coffee +5 -0
  209. data/spec/skr/models/GlPeriodSpec.coffee +5 -0
  210. data/spec/skr/models/GlPostingSpec.coffee +5 -0
  211. data/spec/skr/models/GlTransactionSpec.coffee +5 -0
  212. data/spec/skr/models/IaLineSpec.coffee +5 -0
  213. data/spec/skr/models/IaReasonSpec.coffee +5 -0
  214. data/spec/skr/models/InvLineSpec.coffee +5 -0
  215. data/spec/skr/models/InventoryAdjustmentSpec.coffee +5 -0
  216. data/spec/skr/models/InvoiceSpec.coffee +5 -0
  217. data/spec/skr/models/LocationSpec.coffee +5 -0
  218. data/spec/skr/models/PaymentTermSpec.coffee +5 -0
  219. data/spec/skr/models/PickTicketSpec.coffee +5 -0
  220. data/spec/skr/models/PoLineSpec.coffee +5 -0
  221. data/spec/skr/models/PoReceiptSpec.coffee +5 -0
  222. data/spec/skr/models/PorLineSpec.coffee +5 -0
  223. data/spec/skr/models/PtLineSpec.coffee +5 -0
  224. data/spec/skr/models/PurchaseOrderSpec.coffee +5 -0
  225. data/spec/skr/models/SalesOrderSpec.coffee +5 -0
  226. data/spec/skr/models/SkuLocSpec.coffee +5 -0
  227. data/spec/skr/models/SkuSpec.coffee +5 -0
  228. data/spec/skr/models/SkuTranSpec.coffee +5 -0
  229. data/spec/skr/models/SkuVendorSpec.coffee +5 -0
  230. data/spec/skr/models/SoLineSpec.coffee +5 -0
  231. data/spec/skr/models/UomSpec.coffee +5 -0
  232. data/spec/skr/models/VendorSpec.coffee +5 -0
  233. data/spec/skr/models/VoLineSpec.coffee +5 -0
  234. data/spec/skr/models/VoucherSpec.coffee +5 -0
  235. data/spec/skr/payment_term.rb +10 -0
  236. data/spec/skr/pick_ticket.rb +10 -0
  237. data/spec/skr/po_line.rb +10 -0
  238. data/spec/skr/po_receipt.rb +10 -0
  239. data/spec/skr/por_line.rb +10 -0
  240. data/spec/skr/pt_line.rb +10 -0
  241. data/spec/skr/purchase_order.rb +10 -0
  242. data/spec/skr/sales_order.rb +10 -0
  243. data/spec/skr/screens/Base.coffee +7 -0
  244. data/spec/skr/screens/CustomerMaint.coffee +7 -0
  245. data/spec/skr/screens/vendor-maint/VendorMaintSpec.coffee +5 -0
  246. data/spec/skr/sku.rb +10 -0
  247. data/spec/skr/sku_loc.rb +10 -0
  248. data/spec/skr/sku_tran.rb +10 -0
  249. data/spec/skr/sku_vendor.rb +10 -0
  250. data/spec/skr/so_line.rb +10 -0
  251. data/spec/skr/spec_helper.rb +26 -0
  252. data/spec/skr/uom.rb +10 -0
  253. data/spec/skr/vendor.rb +10 -0
  254. data/spec/skr/views/AddressSpec.coffee +5 -0
  255. data/spec/skr/vo_line.rb +10 -0
  256. data/spec/skr/voucher.rb +10 -0
  257. data/stockor.gemspec +38 -0
  258. data/tmp/.gitkeep +0 -0
  259. metadata +414 -0
@@ -0,0 +1,35 @@
1
+ require 'skr/db/migration_helpers'
2
+
3
+ class CreateSkrSequentialIds < ActiveRecord::Migration
4
+ def up
5
+ # rails can suck it here, there's no reason to have a id(int)
6
+ create_skr_table :sequential_ids, :id=>false do |t|
7
+ t.string :name, :null=>false
8
+ t.integer :current_value, :null=>false, :default=>0
9
+ end
10
+
11
+ execute "alter table #{Skr.config.table_prefix}sequential_ids add primary key (name)"
12
+ execute <<-EOS
13
+ create or replace function #{Skr.config.table_prefix}next_sequential_id( varchar )
14
+ returns integer AS '
15
+ declare
16
+ next_id integer;
17
+ begin
18
+ select current_value into next_id from skr_sequential_ids where name = $1 for update;
19
+ if not found then
20
+ insert into skr_sequential_ids ( name, current_value ) values ( $1, 1 );
21
+ return 1;
22
+ else
23
+ update skr_sequential_ids set current_value = next_id+1 where name = $1;
24
+ return next_id+1;
25
+ end if;
26
+ end;
27
+ ' language plpgsql;
28
+ EOS
29
+ end
30
+
31
+ def down
32
+ drop_skr_table :sequential_ids
33
+ execute "drop function #{Skr.config.table_prefix}next_sequential_id(varchar)"
34
+ end
35
+ end
@@ -0,0 +1,15 @@
1
+ require 'skr/db/migration_helpers'
2
+
3
+ class CreateSkrGlAccounts < ActiveRecord::Migration
4
+ def change
5
+
6
+ create_skr_table "gl_accounts" do |t|
7
+ t.string "number", null: false
8
+ t.string "name", null: false
9
+ t.text "description", null: false
10
+ t.boolean "is_active", default: true, null: false
11
+ t.skr_track_modifications
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ require 'skr/db/migration_helpers'
2
+
3
+ class CreateSkrGlPeriods < ActiveRecord::Migration
4
+
5
+ def change
6
+
7
+ create_skr_table "gl_periods" do |t|
8
+ t.integer "year", limit: 2, null: false
9
+ t.integer "period", limit: 2, null: false
10
+ t.boolean "is_locked", default: false, null: false
11
+ t.skr_track_modifications
12
+ end
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,14 @@
1
+ require 'skr/db/migration_helpers'
2
+
3
+ class CreateSkrGlTransactions < ActiveRecord::Migration
4
+ def change
5
+
6
+ create_skr_table "gl_transactions" do |t|
7
+ t.skr_reference "period", to_table: 'gl_periods'
8
+ t.belongs_to "source", polymorphic: true
9
+ t.text "description", null: false
10
+ t.skr_track_modifications create_only: true # since it can't be updated
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ require 'skr/db/migration_helpers'
2
+
3
+ class CreateSkrGlPostings < ActiveRecord::Migration
4
+ def change
5
+ create_skr_table "gl_postings" do |t|
6
+ t.skr_reference :gl_transaction, single: true
7
+ t.string "account_number", null: false
8
+ t.skr_currency "amount", null: false
9
+ t.boolean "is_debit", null: false
10
+ t.integer "year", null: false, limit: 2
11
+ t.integer "period", null: false, limit: 2
12
+ t.skr_track_modifications create_only: true # since it can't be updated
13
+ end
14
+ skr_add_index :gl_postings, [:period,:year,:account_number]
15
+ end
16
+ end
@@ -0,0 +1,13 @@
1
+ require 'skr/db/migration_helpers'
2
+
3
+ class CreateSkrGlManualEntries < ActiveRecord::Migration
4
+ def change
5
+
6
+ create_skr_table "gl_manual_entries" do |t|
7
+ t.skr_visible_id
8
+ t.text "notes"
9
+ t.skr_track_modifications
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,16 @@
1
+ require 'skr/db/migration_helpers'
2
+
3
+ class CreateSkrPaymentTerms < ActiveRecord::Migration
4
+ def change
5
+
6
+ create_skr_table "payment_terms" do |t|
7
+ t.skr_code_identifier
8
+ t.integer "days", null: false, :default=>0
9
+ t.string "description", null: false
10
+ t.integer "discount_days"
11
+ t.string "discount_amount"
12
+ t.skr_track_modifications
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,19 @@
1
+ require 'skr/db/migration_helpers'
2
+
3
+ class CreateSkrAddresses < ActiveRecord::Migration
4
+ def change
5
+
6
+ create_skr_table "addresses" do |t|
7
+ t.string "name"
8
+ t.string "email"
9
+ t.string "phone"
10
+ t.string "line1"
11
+ t.string "line2"
12
+ t.string "city"
13
+ t.string "state"
14
+ t.string "postal_code"
15
+ t.skr_track_modifications
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'skr/db/migration_helpers'
2
+
3
+ class CreateSkrLocations < ActiveRecord::Migration
4
+ def change
5
+
6
+ create_skr_table "locations" do |t|
7
+ t.skr_code_identifier
8
+ t.string "name", null: false
9
+ t.skr_reference :address, null: false, single: true
10
+ t.boolean "is_active", null: false, default: true
11
+ t.string "gl_branch_code",
12
+ default: Skr.config.default_branch_code,
13
+ null: false,
14
+ limit: 2
15
+ t.skr_track_modifications
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ require 'skr/db/migration_helpers'
2
+
3
+ class CreateSkrVendors < ActiveRecord::Migration
4
+ def change
5
+
6
+ create_skr_table "vendors" do |t|
7
+ t.skr_reference :billing_address, null: false, to_table: :addresses
8
+ t.skr_reference :shipping_address, null: false, to_table: :addresses
9
+ t.skr_reference :terms, null: false, to_table: :payment_terms
10
+ t.skr_reference :gl_payables_account, null: false, to_table: :gl_accounts
11
+ t.skr_reference :gl_freight_account, null: false, to_table: :gl_accounts
12
+ t.string "code", null: false
13
+ t.string "hash_code", null: false
14
+ t.string "name", null: false
15
+ t.text "notes"
16
+ t.string "account_code"
17
+ t.string "website"
18
+ t.skr_track_modifications
19
+ end
20
+
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require 'skr/db/migration_helpers'
2
+
3
+ class CreateSkrCustomers < ActiveRecord::Migration
4
+ def change
5
+
6
+ create_skr_table "customers" do |t|
7
+ t.skr_code_identifier
8
+ t.skr_reference :billing_address, null: false, to_table: :addresses
9
+ t.skr_reference :shipping_address, null: false, to_table: :addresses
10
+ t.skr_reference :terms, null: false, to_table: :payment_terms
11
+ t.skr_reference :gl_receivables_account, null: false, to_table: :gl_accounts
12
+ t.skr_currency :credit_limit, default: 0.0
13
+ t.skr_currency :open_balance, default: 0.0
14
+ t.string "hash_code", null: false
15
+ t.string "name", null: false
16
+ t.text "notes"
17
+ t.text "website"
18
+ t.hstore "options", default: {}
19
+ t.skr_track_modifications
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ require 'skr/db/migration_helpers'
2
+
3
+ class CreateSkrSkus < ActiveRecord::Migration
4
+
5
+ def change
6
+
7
+ create_skr_table "skus" do |t|
8
+ t.skr_reference "default_vendor", null: false, to_table: 'vendors'
9
+ t.skr_reference "gl_asset_account", null: false, to_table: 'gl_accounts'
10
+ t.string "default_uom_code", null: false
11
+ t.string "code", null: false
12
+ t.string "description", null: false
13
+ t.boolean "is_other_charge", null: false, default: false
14
+ t.boolean "does_track_inventory", null: false, default: false
15
+ t.boolean "can_backorder", null: false, default: false
16
+ t.skr_track_modifications
17
+ end
18
+
19
+ #skr_add_index :
20
+ end
21
+
22
+ end
@@ -0,0 +1,21 @@
1
+ require 'skr/db/migration_helpers'
2
+
3
+ class CreateSkrSkuLocs < ActiveRecord::Migration
4
+
5
+ def change
6
+
7
+ create_skr_table "sku_locs" do |t|
8
+ t.skr_reference :sku, null: false, single: true
9
+ t.skr_reference :location, null: false, single: true
10
+ t.decimal "mac", precision: 15, scale: 4, default: 0.0, null: false
11
+ t.integer "qty", default: 0, null: false
12
+ t.integer "qty_allocated", default: 0, null: false
13
+ t.integer "qty_picking", default: 0, null: false
14
+ t.integer "qty_reserved", default: 0, null: false
15
+ t.string "bin"
16
+ t.skr_track_modifications
17
+ end
18
+
19
+
20
+ end
21
+ end
@@ -0,0 +1,19 @@
1
+ require 'skr/db/migration_helpers'
2
+
3
+ class CreateSkrUoms < ActiveRecord::Migration
4
+ def change
5
+
6
+ create_skr_table "uoms" do |t|
7
+ t.skr_reference :sku, null: false, single: true
8
+ t.skr_currency "price", null: false, precision: 15, scale: 2
9
+ t.integer "size", null: false, default: 1, limit: 2
10
+ t.string "code", null: false, default: "EA"
11
+ t.decimal "weight", precision: 6, scale: 1
12
+ t.decimal "height", precision: 6, scale: 1
13
+ t.decimal "width", precision: 6, scale: 1
14
+ t.decimal "depth", precision: 6, scale: 1
15
+ t.skr_track_modifications
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,18 @@
1
+ require 'skr/db/migration_helpers'
2
+
3
+ class CreateSkrSkuVendors < ActiveRecord::Migration
4
+ def change
5
+
6
+ create_skr_table "sku_vendors" do |t|
7
+ t.skr_reference :sku, null: false, single: true
8
+ t.skr_reference :vendor, null: false, single: true
9
+ t.skr_currency "list_price", null: false, precision: 15, scale: 2
10
+ t.string "part_code", null: false
11
+ t.boolean "is_active", null: false, default: true
12
+ t.integer "uom_size", null: false, default: 1
13
+ t.string "uom_code", null: false, default: 'EA'
14
+ t.decimal "cost", null: false, precision: 15, scale: 2
15
+ t.skr_track_modifications
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,14 @@
1
+ require 'skr/db/migration_helpers'
2
+
3
+ class CreateSkrIaReasons < ActiveRecord::Migration
4
+ def change
5
+
6
+ create_skr_table "ia_reasons" do |t|
7
+ t.skr_reference :gl_account, null: false, single: true
8
+ t.string "code", null: false
9
+ t.string "description", null: false
10
+ t.skr_track_modifications
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,16 @@
1
+ require 'skr/db/migration_helpers'
2
+
3
+ class CreateSkrInventoryAdjustments < ActiveRecord::Migration
4
+ def change
5
+
6
+ create_skr_table "inventory_adjustments" do |t|
7
+ t.skr_visible_id
8
+ t.skr_reference :location, null: false, single: true
9
+ t.skr_reference :reason, null: false, to_table: 'ia_reasons'
10
+ t.string "state", null: false
11
+ t.text "description", null: false
12
+ t.skr_track_modifications
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,18 @@
1
+ require 'skr/db/migration_helpers'
2
+
3
+ class CreateSkrIaLines < ActiveRecord::Migration
4
+ def change
5
+
6
+ create_skr_table "ia_lines" do |t|
7
+ t.skr_reference :inventory_adjustment, null: false, single: true
8
+ t.skr_reference :sku_loc, null: false, single: true
9
+ t.integer "qty", null: false, default: 1
10
+ t.string "uom_code", null: false, default: 'EA'
11
+ t.integer "uom_size", null: false, default: 1, limit: 2
12
+ t.skr_currency "cost", precision: 15, scale: 2 # n.b. the cost may be left null
13
+ t.boolean "cost_was_set", null: false, default: false
14
+ t.skr_track_modifications
15
+ end
16
+
17
+ end
18
+ end
@@ -0,0 +1,21 @@
1
+ require 'skr/db/migration_helpers'
2
+
3
+ class CreateSkrSkuTrans < ActiveRecord::Migration
4
+ def change
5
+
6
+ create_skr_table "sku_trans" do |t|
7
+ t.references :origin, :polymorphic => true
8
+ t.skr_reference :sku_loc, null: false, single: true
9
+ t.skr_currency "cost", null: false
10
+ t.string "origin_description", null: false
11
+ t.integer "prior_qty", null: false
12
+ t.decimal "mac", null: false, precision: 15, scale: 4
13
+ t.decimal "prior_mac", null: false, precision: 15, scale: 4
14
+ t.integer "qty", null: false, default: 0
15
+ t.string "uom_code", null: false, default: 'EA'
16
+ t.integer "uom_size", null: false, default: 1
17
+ t.skr_track_modifications create_only: true # sku_tran can only be created
18
+ end
19
+
20
+ end
21
+ end
@@ -0,0 +1,27 @@
1
+ require 'skr/db/migration_helpers'
2
+
3
+ class CreateSkrSalesOrders < ActiveRecord::Migration
4
+ def change
5
+
6
+ create_skr_table "sales_orders" do |t|
7
+ t.skr_visible_id
8
+ t.skr_reference :customer, single: true
9
+ t.skr_reference :location, single: true
10
+ t.skr_reference :shipping_address, to_table: 'addresses'
11
+ t.skr_reference :billing_address, to_table: 'addresses'
12
+ t.skr_reference :terms, to_table: 'payment_terms'
13
+ t.date "order_date", null: false
14
+ t.string "state", null: false
15
+ t.boolean "is_revised", null: false, default: false
16
+ t.string "hash_code", null: false
17
+ t.boolean "ship_partial", null: false, default: false
18
+ t.boolean "is_complete", null: false, default: false
19
+ t.string "po_num"
20
+ t.text "notes"
21
+ t.hstore "options", default: {}
22
+ t.skr_track_modifications
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,25 @@
1
+ require 'skr/db/migration_helpers'
2
+
3
+ class CreateSkrSoLines < ActiveRecord::Migration
4
+ def change
5
+
6
+ create_skr_table "so_lines" do |t|
7
+ t.skr_reference :sales_order, null: false, single: true
8
+ t.skr_reference :sku_loc, null: false, single: true
9
+ t.skr_currency "price", null: false
10
+ t.string "sku_code", null: false
11
+ t.string "description", null: false
12
+ t.string "uom_code", null: false
13
+ t.integer "uom_size", null: false, limit: 2
14
+ t.integer "position", null: false, limit: 2
15
+ t.integer "qty", null: false, default: 0
16
+ t.integer "qty_allocated", null: false, default: 0
17
+ t.integer "qty_picking", null: false, default: 0
18
+ t.integer "qty_invoiced", null: false, default: 0
19
+ t.integer "qty_canceled", null: false, default: 0
20
+ t.boolean "is_revised", null: false, default: false
21
+ t.skr_track_modifications
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,81 @@
1
+ require 'skr/db/migration_helpers'
2
+
3
+ class CreateSoDetailsView < ActiveRecord::Migration
4
+ def up
5
+ execute <<-EOS.squish
6
+ create view #{skr_prefix}so_amount_details as
7
+ select so.id as sales_order_id,
8
+ to_char(so.order_date,'YYYY-MM-DD') as string_order_date,
9
+ cust.code as customer_code, cust.name as customer_name,
10
+ addr.name as bill_addr_name,
11
+ coalesce( ttls.total,0.0 ) as total,
12
+ coalesce( ttls.num_lines, 0 ) as num_lines,
13
+ coalesce( ttls.other_charge_total, 0 ) as total_other_charge_amount,
14
+ coalesce( ttls.tax_charge_total, 0 ) as total_tax_amount,
15
+ coalesce( ttls.shipping_charge_total, 0 ) as total_shipping_amount,
16
+ coalesce( ttls.total,0.0 ) - coalesce( ttls.other_charge_total, 0.0 ) as subtotal_amount
17
+ from #{skr_prefix}sales_orders so
18
+ join #{skr_prefix}customers cust on cust.id = so.customer_id
19
+ join #{skr_prefix}addresses addr on addr.id = so.billing_address_id
20
+ left join (
21
+ select
22
+ sales_order_id,
23
+ sum(sol.qty*sol.price) as total,
24
+ sum( case when s.is_other_charge then sol.qty*sol.price else 0 end ) as other_charge_total,
25
+ sum( case when sol.sku_code = '#{Skr.config.ship_sku_code}' then sol.qty*sol.price else 0 end )
26
+ as shipping_charge_total,
27
+ sum( case when sol.sku_code = '#{Skr.config.tax_sku_code}' then sol.qty*sol.price else 0 end )
28
+ as tax_charge_total,
29
+ count(sol.*) as num_lines
30
+ from #{skr_prefix}so_lines sol
31
+ join #{skr_prefix}sku_locs sl on sl.id = sol.sku_loc_id
32
+ join #{skr_prefix}skus s on s.id = sl.sku_id
33
+ group by sales_order_id
34
+ ) ttls on ttls.sales_order_id = so.id
35
+ EOS
36
+
37
+ execute <<-EOS.squish
38
+ create view #{skr_prefix}so_allocation_details as
39
+ select sales_order_id, count(*) as number_of_lines, sum(sol.qty_allocated*price) as allocated_total,
40
+ sum( case when sol.qty_allocated - sol.qty_canceled - sol.qty_picking > 0 then 1 else 0 end )
41
+ as number_of_lines_allocated,
42
+ sum( case when sol.qty_allocated = (sol.qty - sol.qty_canceled - sol.qty_picking)
43
+ then 1 else 0 end )
44
+ as number_of_lines_fully_allocated
45
+ from #{skr_prefix}so_lines sol
46
+ join #{skr_prefix}sku_locs sl on sl.id = sol.sku_loc_id
47
+ join #{skr_prefix}skus s on s.id = sl.sku_id and s.is_other_charge='f'
48
+ group by sales_order_id having ( sum ( case when
49
+ sol.qty_allocated - sol.qty_canceled - sol.qty_picking > 0 then 1 else 0 end
50
+ ) ) > 0
51
+ EOS
52
+
53
+ execute <<-EOS.squish
54
+ create view #{skr_prefix}so_dailly_sales_history as
55
+ select
56
+ days_ago,
57
+ date_trunc('day', (current_date - days_ago)) as day,
58
+ coalesce( ttls.order_count, 0 ) as order_count,
59
+ coalesce( ttls.line_count, 0 ) as line_count,
60
+ coalesce(ttls.total,0.0) as total
61
+ from generate_series(0, 120, 1) as days_ago
62
+ left join (
63
+ select
64
+ count(distinct(sales_order_id)) as order_count,
65
+ count(*) as line_count,
66
+ sum(sol.price*sol.qty) as total,
67
+ date_trunc('day', so.created_at ) as so_date
68
+ from #{skr_prefix}so_lines sol
69
+ join #{skr_prefix}sales_orders so on sol.sales_order_id = so.id
70
+ group by date_trunc('day', so.created_at )
71
+ ) ttls on ttls.so_date = date_trunc('day', (current_date - days_ago))
72
+ order by day desc
73
+ EOS
74
+ end
75
+
76
+ def down
77
+ execute "drop view #{skr_prefix}so_amount_details"
78
+ execute "drop view #{skr_prefix}so_allocation_details"
79
+ execute "drop view #{skr_prefix}so_dailly_sales_history"
80
+ end
81
+ end
@@ -0,0 +1,20 @@
1
+ require 'skr/db/migration_helpers'
2
+
3
+ class CreateSkrPurchaseOrders < ActiveRecord::Migration
4
+ def change
5
+
6
+ create_skr_table "purchase_orders" do |t|
7
+ t.skr_visible_id
8
+ t.skr_reference :vendor, single: true
9
+ t.skr_reference :location, single: true
10
+ t.skr_reference :ship_addr, to_table: 'addresses'
11
+ t.skr_reference :terms, to_table: 'payment_terms'
12
+ t.string "state", null: false
13
+ t.boolean "is_revised", null: false, default: false
14
+ t.date "order_date", null: false
15
+ t.datetime "receiving_completed_at"
16
+ t.skr_track_modifications
17
+ end
18
+
19
+ end
20
+ end
@@ -0,0 +1,25 @@
1
+ require 'skr/db/migration_helpers'
2
+
3
+ class CreateSkrPoLines < ActiveRecord::Migration
4
+ def change
5
+
6
+ create_skr_table "po_lines" do |t|
7
+ t.skr_reference :purchase_order, null: false, single: true
8
+ t.skr_reference :sku_loc, null: false, single: true
9
+ t.skr_reference :sku_vendor, null: false, single: true
10
+ t.string "part_code", null: false
11
+ t.string "sku_code", null: false
12
+ t.string "description", null: false
13
+ t.string "uom_code", null: false
14
+ t.integer "uom_size", null: false, limit: 2
15
+ t.integer "position", null: false, limit: 2
16
+ t.integer "qty", null: false, default: 0
17
+ t.integer "qty_received", null: false, default: 0
18
+ t.integer "qty_canceled", null: false, default: 0
19
+ t.skr_currency "price", null: false
20
+ t.boolean "is_revised", null: false, default: false
21
+ t.skr_track_modifications
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,16 @@
1
+ require 'skr/db/migration_helpers'
2
+
3
+ class CreateSkrPickTickets < ActiveRecord::Migration
4
+ def change
5
+
6
+ create_skr_table "pick_tickets" do |t|
7
+ t.skr_visible_id
8
+ t.skr_reference :sales_order, single: true
9
+ t.skr_reference :location, single: true
10
+ t.date "shipped_at"
11
+ t.boolean "is_complete", default: false
12
+ t.skr_track_modifications
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,23 @@
1
+ require 'skr/db/migration_helpers'
2
+
3
+ class CreateSkrPtLines < ActiveRecord::Migration
4
+ def change
5
+
6
+ create_skr_table "pt_lines" do |t|
7
+ t.skr_reference :pick_ticket, single: true
8
+ t.skr_reference :so_line, single: true
9
+ t.skr_reference :sku_loc, single: true
10
+ t.skr_currency "price", null: false
11
+ t.string "sku_code", null: false
12
+ t.string "description", null: false
13
+ t.string "uom_code", null: false
14
+ t.string "bin", null: true
15
+ t.integer "uom_size", null: false, limit: 2
16
+ t.integer "position", null: false, limit: 2
17
+ t.integer "qty", null: false, default: 0
18
+ t.integer "qty_invoiced", null: false, default: 0
19
+ t.boolean "is_complete", null: false, default: false
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,25 @@
1
+ require 'skr/db/migration_helpers'
2
+
3
+ class CreateSkrInvoices < ActiveRecord::Migration
4
+
5
+ def change
6
+ create_skr_table "invoices" do |t|
7
+ t.skr_visible_id
8
+ t.skr_reference :terms, to_table: 'payment_terms'
9
+ t.skr_reference :customer, single: true
10
+ t.skr_reference :location, single: true
11
+ t.skr_reference :sales_order, single: true, null: true
12
+ t.skr_reference :pick_ticket, single: true, null: true
13
+ t.skr_reference :shipping_address, to_table: 'addresses'
14
+ t.skr_reference :billing_address, to_table: 'addresses'
15
+ t.skr_currency :amount_paid, null: false, default: 0.0
16
+ t.string "state", null: false
17
+ t.string "hash_code", null: false
18
+ t.date "invoice_date", null: false
19
+ t.string "po_num"
20
+ t.hstore "options", default: {}
21
+ t.skr_track_modifications
22
+ end
23
+ end
24
+
25
+ end