gentili_async_mssql_importer 0.1.19

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 159283cf9661120748abbb69916078bd51a22d0ec221e4e7fb9774669f71b0a1
4
+ data.tar.gz: f81da1fb8eb14e479a3f90f68be63bb01f1c16e3e4f5f33c019468ff25441f96
5
+ SHA512:
6
+ metadata.gz: 66f0da9b1c10ddb44359e5724bacf59dd9dac3f633c5a7e9c90345cd48635055b03a70baee0942d6bc966c7826a22d668a4c69d5d1512ed99d803341b637cffa
7
+ data.tar.gz: 6fe4bd71b6833384745d1752da2378aafa491c52c025d42301a0d626f376b9143d0d991fdc209ab7614240c4d1f45e1663c2fbd8f80fac46ab02231c5675de08
@@ -0,0 +1,20 @@
1
+ Copyright 2018 Gabriele Tassoni
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,28 @@
1
+ # GentiliAsyncMssqlImporter
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'gentili_async_mssql_importer'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install gentili_async_mssql_importer
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -0,0 +1,32 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'GentiliAsyncMssqlImporter'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+ load 'rails/tasks/statistics.rake'
21
+
22
+ require 'bundler/gem_tasks'
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'test'
28
+ t.pattern = 'test/**/*_test.rb'
29
+ t.verbose = false
30
+ end
31
+
32
+ task default: :test
@@ -0,0 +1,8 @@
1
+ class GentiliImportWorker
2
+ include Sidekiq::Worker
3
+ sidekiq_options retry: false
4
+
5
+ def perform(*args)
6
+ TrackerImporter.import_all_records
7
+ end
8
+ end
@@ -0,0 +1,23 @@
1
+
2
+ require 'active_support/concern'
3
+
4
+ module GentiliAsyncMssqlImporterAbilitiesConcern
5
+ extend ActiveSupport::Concern
6
+ included do
7
+ def gentili_async_mssql_importer_abilities user
8
+ if user
9
+ # if the user is logged in, it can do certain tasks regardless his role
10
+ if user.admin?
11
+ # if the user is an admin, it can do a lot of things, usually
12
+ end
13
+
14
+ if user.has_role? :role
15
+ # a specific role, brings specific powers
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ # include the extension
23
+ TheCoreAbilities.send(:include, GentiliAsyncMssqlImporterAbilitiesConcern)
@@ -0,0 +1,5 @@
1
+
2
+ Rails.application.configure do
3
+ config.after_initialize do
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ Rails.application.routes.draw do
2
+ end
@@ -0,0 +1,5 @@
1
+ class AddCompanyGentili < ActiveRecord::Migration[5.2]
2
+ def change
3
+ Company.find_or_create_by!(name: "Gentili")
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+
2
+ require 'thecore'
3
+ require 'thecore_mssql_importer_common'
4
+ require 'tracker_models'
5
+ require "gentili_async_mssql_importer/engine"
6
+ require 'tracker_importer'
7
+
8
+ module GentiliAsyncMssqlImporter
9
+ # Your code goes here...
10
+ end
@@ -0,0 +1,15 @@
1
+ require 'thecore'
2
+ module GentiliAsyncMssqlImporter
3
+ class Engine < ::Rails::Engine
4
+
5
+ initializer 'gentili_async_mssql_importer.add_to_migrations' do |app|
6
+ unless app.root.to_s == root.to_s
7
+ # APPEND TO MAIN APP MIGRATIONS FROM THIS GEM
8
+ config.paths['db/migrate'].expanded.each do |expanded_path|
9
+ app.config.paths['db/migrate'] << expanded_path
10
+ end
11
+ end
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module GentiliAsyncMssqlImporter
2
+ VERSION = '0.1.19'.freeze
3
+ end
@@ -0,0 +1,12 @@
1
+ # desc "Explaining what the task does"
2
+ # task :gentili_async_mssql_importer do
3
+ # # Task goes here
4
+ # end
5
+ require 'tracker_importer'
6
+
7
+ namespace :tracker do
8
+ desc "Retrieves all records from the reading table and imports into tables."
9
+ task import_all_records: :environment do
10
+ TrackerImporter.import_all_records
11
+ end
12
+ end
@@ -0,0 +1,128 @@
1
+ require 'tiny_tds'
2
+
3
+ class TrackerImporter
4
+ # "Retrieves all records from the reading table and imports into tables."
5
+ def self.import_all_records
6
+ @client = MSSQLImporterCommon.connect
7
+ # Read all employees
8
+ puts "Reading data from table and putting into our database"
9
+ where_query = []
10
+ latest_migration_code = Settings.ns('mssql_connector').latest_migration_code
11
+ where_query << "mo_flevas = 'c'"
12
+ where_query << "mo_quant > 0"
13
+ where_query << "CONVERT(bigint,ts) > #{latest_migration_code.to_i}" unless latest_migration_code.blank?
14
+ query = "SELECT CONVERT(bigint,ts) as ts, mo_numord, mo_codart, ar_codalt, mo_quant, mo_commeca FROM #{Settings.ns('mssql_connector').table_read} WHERE #{where_query.join(" AND ")} ORDER BY ts ASC"
15
+ puts "Query: #{query}"
16
+ res = @client.execute(query).each.to_a
17
+
18
+ res.each do |row|
19
+ # A row looks like this (X are the one effectively used for the import:
20
+ # Cosa succede a quelle chiuse? Non me le danno direttamente, quelle chiuse
21
+ # o me le danno e io devo scartarle?
22
+ # {
23
+ # X "ts"=>"\x00\x00\x00\x00\x00\x04\xF6\x97",
24
+ # "mo_anno"=>2011,
25
+ # "mo_serie"=>" ",
26
+ # X "mo_numord"=>450032382,
27
+ # "mo_riga"=>1,
28
+ # "mo_codart"=>"09AS0W070401",
29
+ # -----------------------| Il settimo campo è da importare e
30
+ # cambiare sempre a 3 quando importo la prima volta.
31
+ # Il campo non cresce mai di valore (da 2 non passa a 3, mai, come da 1, mai a 2, etc.)
32
+ # aggiungere nelle ubicazioni un field per questo valore
33
+ # tutte le ubicazioni avranno il valore valorizzato, alcune
34
+ # avranno lo stesso valore, quando un tag vine rievato in una ubicazione,
35
+ # cambia il valore a quello dell'ubicazione corrente, a meno che non sia superiore,
36
+ # in quel caso non lo cambia.
37
+ # WARNING: forse è meglio tenere un secondo campo, con solo lo stato
38
+ # in cui il codice articolo mi resta sempre quello, ma poi come visualizzazione
39
+ # per loro, sostituisco solo in to_title al settimo char. VALUTARE!!!!!!!
40
+ # - Stato 0, quando viene messo in spedizione (lo fa il DJ, Ubic. 10)
41
+ # - Stato 1: Ubicazione Spazzolatura, Finitura (Ubic: 7, 8, 9)
42
+ # - Stato 2: Ubicazione Verniciatura, Ferramenta (Ubic: 4 e 5)
43
+ # - Stato 3: Appena entrato nel sistema (Ubic: 1, 2 e 3)
44
+ # "mo_descr"=>"Ecrin en bois pour plume",
45
+ # -----------------------> Questo non va bene, descr non va usato, ma va usato la descralt (chiedere a Fraticelli)
46
+ # X "ar_codalt" ->>>>>>>> Da usare questo e non quello sopra
47
+ # X "mo_flevas" => "c" (c = chiuse quindi diverse da 'c')
48
+ # "mo_desint"=>nil,
49
+ # "mo_unmis"=>"NR",
50
+ # X "mo_quant"=>75.0,
51
+ # X "mo_commeca"=>0
52
+ # }
53
+ #
54
+
55
+ puts "Importing row with TS: #{row["ts"]}"
56
+ puts "Importing Commission: #{row["mo_commeca"]}"
57
+ ActiveRecord::Base.transaction do
58
+ commission = Commission.find_or_create_by! code: row["mo_commeca"]
59
+ item = Item.find_or_initialize_by code: row["mo_codart"]
60
+ item.description = row["ar_codalt"]
61
+ # item.location_code = 3 Attenzione non esiste più
62
+ item.save! # I use the blockless version since I need to update also if found, not just in creation
63
+
64
+ puts "Order: #{row["mo_numord"]}"
65
+ order = Order.find_or_initialize_by code: row["mo_numord"]
66
+ order.quantity = order.quantity_in_production = row["mo_quant"]
67
+ order.commission = commission
68
+ order.item = item
69
+ # Se la company madre non esiste, allora la creo
70
+ order.company = Company.find_by(name: "Gentili")
71
+ order.save! # I use the blockless version since I need to update also if found, not just in creation
72
+ end
73
+ end
74
+ unless res.blank?
75
+ last_ts = res.last["ts"]
76
+ puts "Setting last TS: #{last_ts}"
77
+ Settings.ns('mssql_connector').latest_migration_code = last_ts
78
+ end
79
+ end
80
+
81
+ def self.import_csv_for_test
82
+ if File.exists? "rfid8500.csv"
83
+ csv = File.readlines("rfid8500.csv").map(&:chomp)
84
+ uids = csv[6..(csv.count-1)]
85
+ quantity_from_csv = uids.count
86
+
87
+ ActiveRecord::Base.transaction do
88
+ commission_code = "TEST-COM-#{Time.now.to_s(:db).gsub(" ", "|")}"
89
+ puts "COMMISSION CODE: #{commission_code}"
90
+ commission = Commission.find_or_create_by! code: commission_code
91
+ item_code = "TEST-ITM-#{Time.now.to_s(:db).gsub(" ", "|")}"
92
+ puts "ITEM CODE: #{item_code}"
93
+ item = Item.find_or_initialize_by code: item_code
94
+ item.description = "TEST-ITM-DESC-#{Time.now.to_s(:db).gsub(" ", "|")}"
95
+ # item.location_code = 3 Attenzione non esiste più
96
+ item.save! # I use the blockless version since I need to update also if found, not just in creation
97
+
98
+ order_code = "TEST-ORD-#{Time.now.to_s(:db).gsub(" ", "|")}"
99
+ puts "ORDER CODE: #{order_code}"
100
+ order = Order.find_or_initialize_by code: order_code
101
+ order.quantity = order.quantity_in_production = quantity_from_csv
102
+ order.commission = commission
103
+ order.item = item
104
+ # Se la company madre non esiste, allora la creo
105
+ order.company = Company.find_by(name: "Gentili")
106
+ order.save! # I use the blockless version since I need to update also if found, not just in creation
107
+
108
+ uids.each { |u|
109
+ puts "- INSERTING UID: #{u.split(",").first}"
110
+ Uid.find_or_create_by! code: u.split(",").first, order_id: order.id
111
+ }
112
+ end
113
+ end
114
+ end
115
+
116
+ private
117
+
118
+ def self.connect
119
+ conn = {
120
+ username: Settings.ns('mssql_connector').username,
121
+ password: Settings.ns('mssql_connector').password,
122
+ host: Settings.ns('mssql_connector').host,
123
+ port: Settings.ns('mssql_connector').port,
124
+ database: Settings.ns('mssql_connector').database,
125
+ }
126
+ @client = TinyTds::Client.new conn
127
+ end
128
+ end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gentili_async_mssql_importer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.19
5
+ platform: ruby
6
+ authors:
7
+ - Gabriele Tassoni
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-04-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thecore
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: thecore_mssql_importer_common
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: tracker_models
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ description: Thecorized gentili_async_mssql_importer full description.
56
+ email:
57
+ - gabriele.tassoni@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - MIT-LICENSE
63
+ - README.md
64
+ - Rakefile
65
+ - app/assets/config/gentili_async_mssql_importer_manifest.js
66
+ - app/workers/gentili_import_worker.rb
67
+ - config/initializers/abilities_gentili_async_mssql_importer_concern.rb
68
+ - config/initializers/gentili_async_mssql_importer_after_initialize.rb
69
+ - config/routes.rb
70
+ - db/migrate/20190124115124_add_company_gentili.rb
71
+ - lib/gentili_async_mssql_importer.rb
72
+ - lib/gentili_async_mssql_importer/engine.rb
73
+ - lib/gentili_async_mssql_importer/version.rb
74
+ - lib/tasks/gentili_async_mssql_importer_tasks.rake
75
+ - lib/tracker_importer.rb
76
+ homepage: https://www.taris.it
77
+ licenses:
78
+ - MIT
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.7.7
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Thecorized gentili_async_mssql_importer
100
+ test_files: []