billing 0.0.7i → 0.0.7

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: d0947871a8781aa70a9ab5fb3e8f920572f804c0
4
- data.tar.gz: 2834ca5fba520f2aa7de92f0bf1475ce0dcc0bb0
3
+ metadata.gz: 2ad7f574f1fd705d1c3fa07c37a6d82206cebe8d
4
+ data.tar.gz: d9c2f1161ef14b21b15fce52fa6befe525946cd9
5
5
  SHA512:
6
- metadata.gz: 3dab27eda9362c02de2c7b510dc7d3a3f52e2bd5834d438f951ca29c721c44b7ba8f474798d1ca030b0821284e07bfccd999c781895eae95df4152d86f45aaea
7
- data.tar.gz: 1ee6a7e48da1e9d50abf84cecf95c95f7036a14adc072ceb2e5e9a14581e669305070323434f0fc8dc6701405cc9b08cb2258127f0b8e61253fb08e931ecfbec
6
+ metadata.gz: 59892ba7beb3905f859f85f4c564191c0e85ac59c2cc48486f6077653f9e8881c10bba5ff39e6242ac6768e978b8de4663cad0f27f0e2c4058643ec398c77dc7
7
+ data.tar.gz: df3c4069cc8a8cb59d6439fb9daf72fa9cbba6889c02c375dc7dc9d264781ff1ce614d3056896942fdbaebcb4c885109c8a789dfb7919f3e2a8cb551224a0497
@@ -39,7 +39,6 @@ module Billing
39
39
  self.name = "B:#{number}" if name.nil?
40
40
  end
41
41
  before_save :perform_autofin, if: :becomes_paid?
42
- after_save :create_fiscal_job, if: :fiscalizable?
43
42
 
44
43
  validates_numericality_of :total, greater_than_or_equal_to: 0
45
44
  validates_numericality_of :balance, less_than_or_equal_to: 0
@@ -90,24 +89,17 @@ module Billing
90
89
  end
91
90
 
92
91
  def fiscalize(detailed = false)
93
- #TODO create resque job
94
- #self.extface_job = origin.fiscal_device.driver.fiscalize(self, detailed) if fiscalizable? && origin.try(:fiscal_device)
95
- #self.extface_job if save
96
- if defined?(Extface) && fiscalizable? && device = origin.try(:fiscal_device)
97
- #self.extface_job = origin.fiscal_device.driver.fiscalize(self) if fiscalizable? && origin.try(:fiscal_device)
98
- self.extface_job = device.jobs.new
99
- self.extface_job if save
100
- end
92
+ self.extface_job = origin.fiscal_device.driver.fiscalize(self, detailed) if fiscalizable? && origin.try(:fiscal_device)
93
+ self.extface_job if save
101
94
  end
102
95
 
103
96
  def global_modifier_value
104
- global_modifiers = modifiers.select{ |m| m.charge.nil? }
105
- if global_modifiers.any?
106
- gvalue = Money.new(0)
107
- global_modifiers.each do |global_modifier|
108
- gvalue += global_modifier.percent_ratio.nil? ? global_modifier.fixed_value : (charges_a.sum(&:value).to_money * global_modifier.percent_ratio)
109
- end
110
- return gvalue
97
+ if global_modifiers = modifiers.select{ |m| m.charge.nil? }
98
+ Money.new(0).tap() do |value|
99
+ global_modifiers.each do |global_modifier|
100
+ value += global_modifier.percent_ratio.nil? ? global_modifier.fixed_value : (charges_a.sum(&:value).to_money * global_modifier.percent_ratio)
101
+ end
102
+ end if global_modifiers.any?
111
103
  end
112
104
  end
113
105
 
@@ -115,10 +107,6 @@ module Billing
115
107
  # get operator, who close/pay the bill?
116
108
  #operator.operator_fiscal_driver_mapping.find_by(extface_driver_id: fiscal_driver.id) if fiscal_driver.fiscal?
117
109
  end
118
-
119
- def fiscalizable?
120
- self.finalized_at.present? && payments.select(&:fiscal?).any? && origin.try(:fiscal_device) && balance.zero?
121
- end
122
110
 
123
111
  private
124
112
  def calculate_modifiers
@@ -164,26 +152,17 @@ module Billing
164
152
  end
165
153
 
166
154
  def perform_autofin
167
- p "!!!!!!!!!!perform_autofin"
168
155
  if autofin
169
156
  self.finalized_at = Time.now
170
- if defined?(Extface) && fiscalizable? && device = origin.try(:fiscal_device)
171
- #self.extface_job = origin.fiscal_device.driver.fiscalize(self) if fiscalizable? && origin.try(:fiscal_device)
172
- self.extface_job = device.jobs.new
157
+ if defined? Extface
158
+ self.extface_job = origin.fiscal_device.driver.fiscalize(self) if fiscalizable? && origin.try(:fiscal_device)
173
159
  end
174
160
  end
175
161
  true
176
162
  end
177
163
 
178
- def create_fiscal_job
179
- if self.extface_job_id_changed? && defined?(Resque) && defined?(Extface) && device = origin.try(:fiscal_device)
180
- p "device: #{device.try(:id)}"
181
- p "self: #{self.try(:id)}"
182
- p "self.finalized_at changed: #{self.finalized_at_changed?}"
183
-
184
- Resque.enqueue_to("extface_#{device.id}", Billing::IssueFiscalDoc, self.id)
185
- end
186
- true
164
+ def fiscalizable?
165
+ payments.select(&:fiscal?).any?
187
166
  end
188
167
 
189
168
  end
@@ -5,8 +5,7 @@ module Billing
5
5
  FISCAL_PERIOD_REPORT = 'period_report'.freeze
6
6
  FISCAL_PAYED_RECVD = 'payed_recvd'.freeze
7
7
  F_OPERATIONS = [FISCAL_X_REPORT, FISCAL_Z_REPORT, FISCAL_PERIOD_REPORT, FISCAL_PAYED_RECVD].freeze
8
-
9
- acts_as_paranoid if respond_to?(:acts_as_paranoid)
8
+
10
9
  has_paper_trail class_name: 'Billing::Version'
11
10
  belongs_to :origin, inverse_of: :reports
12
11
  has_many :bills, inverse_of: :report, autosave: true
@@ -1,7 +1,5 @@
1
1
  module Billing
2
2
  class Version < PaperTrail::Version
3
3
  self.table_name = :billing_versions
4
-
5
- belongs_to :changable, -> { with_deleted }, polymorphic: true, foreign_key: :item_id, foreign_type: :item_type
6
4
  end
7
5
  end
@@ -6,10 +6,5 @@ require 'collection_proxy_wild'
6
6
  module Billing
7
7
  class Engine < ::Rails::Engine
8
8
  isolate_namespace Billing
9
- config.to_prepare do
10
- PaperTrail::Version.module_eval do
11
- self.abstract_class = true
12
- end
13
- end
14
9
  end
15
10
  end
@@ -1,3 +1,3 @@
1
1
  module Billing
2
- VERSION = "0.0.7i"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -11,7 +11,7 @@
11
11
  #
12
12
  # It's strongly recommended that you check this file into your version control system.
13
13
 
14
- ActiveRecord::Schema.define(version: 20150512040421) do
14
+ ActiveRecord::Schema.define(version: 20150510142229) do
15
15
 
16
16
  create_table "billing_bills", force: :cascade do |t|
17
17
  t.integer "billable_id"
@@ -231,7 +231,6 @@ ActiveRecord::Schema.define(version: 20150512040421) do
231
231
  t.string "f_operation", limit: 255
232
232
  t.integer "f_amount_cents", default: 0, null: false
233
233
  t.string "f_amount_currency", limit: 255, default: "USD", null: false
234
- t.datetime "deleted_at"
235
234
  end
236
235
 
237
236
  add_index "billing_reports", ["origin_id"], name: "index_billing_reports_on_origin_id"
@@ -280,8 +279,6 @@ ActiveRecord::Schema.define(version: 20150512040421) do
280
279
  t.string "ip", limit: 255
281
280
  t.string "user_agent", limit: 255
282
281
  t.text "object_changes"
283
- t.integer "master_id"
284
- t.string "master_type"
285
282
  end
286
283
 
287
284
  add_index "billing_versions", ["item_type", "item_id"], name: "index_billing_versions_on_item_type_and_item_id"
@@ -2331,482 +2331,3 @@ Migrating to AddObjectChangesToBillingVersions (20150510142229)
2331
2331
  FROM sqlite_temp_master
2332
2332
  WHERE name='index_billing_versions_on_item_type_and_item_id' AND type='index'
2333
2333
  
2334
- ActiveRecord::SchemaMigration Load (0.3ms) SELECT "schema_migrations".* FROM "schema_migrations"
2335
- Migrating to AddMasterToBillingVersion (20150510235441)
2336
-  (0.1ms) begin transaction
2337
-  (0.5ms) ALTER TABLE "billing_versions" ADD "master_id" integer
2338
-  (0.3ms) ALTER TABLE "billing_versions" ADD "master_type" varchar
2339
- SQL (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20150510235441"]]
2340
-  (82.0ms) commit transaction
2341
- ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
2342
-  (0.3ms) SELECT sql
2343
- FROM sqlite_master
2344
- WHERE name='index_billing_bills_on_billable_id_and_billable_type' AND type='index'
2345
- UNION ALL
2346
- SELECT sql
2347
- FROM sqlite_temp_master
2348
- WHERE name='index_billing_bills_on_billable_id_and_billable_type' AND type='index'
2349
-
2350
-  (0.2ms)  SELECT sql
2351
- FROM sqlite_master
2352
- WHERE name='index_billing_bills_on_origin_id' AND type='index'
2353
- UNION ALL
2354
- SELECT sql
2355
- FROM sqlite_temp_master
2356
- WHERE name='index_billing_bills_on_origin_id' AND type='index'
2357
- 
2358
-  (0.2ms) SELECT sql
2359
- FROM sqlite_master
2360
- WHERE name='index_billing_bills_on_extface_job_id' AND type='index'
2361
- UNION ALL
2362
- SELECT sql
2363
- FROM sqlite_temp_master
2364
- WHERE name='index_billing_bills_on_extface_job_id' AND type='index'
2365
-
2366
-  (0.2ms)  SELECT sql
2367
- FROM sqlite_master
2368
- WHERE name='index_billing_bills_on_report_id' AND type='index'
2369
- UNION ALL
2370
- SELECT sql
2371
- FROM sqlite_temp_master
2372
- WHERE name='index_billing_bills_on_report_id' AND type='index'
2373
- 
2374
-  (0.2ms) SELECT sql
2375
- FROM sqlite_master
2376
- WHERE name='index_billing_charges_on_bill_id' AND type='index'
2377
- UNION ALL
2378
- SELECT sql
2379
- FROM sqlite_temp_master
2380
- WHERE name='index_billing_charges_on_bill_id' AND type='index'
2381
-
2382
-  (0.2ms)  SELECT sql
2383
- FROM sqlite_master
2384
- WHERE name='index_billing_charges_on_revenue_at' AND type='index'
2385
- UNION ALL
2386
- SELECT sql
2387
- FROM sqlite_temp_master
2388
- WHERE name='index_billing_charges_on_revenue_at' AND type='index'
2389
- 
2390
-  (0.2ms) SELECT sql
2391
- FROM sqlite_master
2392
- WHERE name='index_billing_charges_on_deleted_at' AND type='index'
2393
- UNION ALL
2394
- SELECT sql
2395
- FROM sqlite_temp_master
2396
- WHERE name='index_billing_charges_on_deleted_at' AND type='index'
2397
-
2398
-  (0.2ms)  SELECT sql
2399
- FROM sqlite_master
2400
- WHERE name='index_billing_charges_on_origin_id' AND type='index'
2401
- UNION ALL
2402
- SELECT sql
2403
- FROM sqlite_temp_master
2404
- WHERE name='index_billing_charges_on_origin_id' AND type='index'
2405
- 
2406
-  (0.2ms) SELECT sql
2407
- FROM sqlite_master
2408
- WHERE name='index_billing_charges_on_chargable_id_and_chargable_type' AND type='index'
2409
- UNION ALL
2410
- SELECT sql
2411
- FROM sqlite_temp_master
2412
- WHERE name='index_billing_charges_on_chargable_id_and_chargable_type' AND type='index'
2413
-
2414
-  (0.2ms)  SELECT sql
2415
- FROM sqlite_master
2416
- WHERE name='index_billing_departments_on_deleted_at' AND type='index'
2417
- UNION ALL
2418
- SELECT sql
2419
- FROM sqlite_temp_master
2420
- WHERE name='index_billing_departments_on_deleted_at' AND type='index'
2421
- 
2422
-  (0.2ms) SELECT sql
2423
- FROM sqlite_master
2424
- WHERE name='index_billing_departments_on_tax_group_id' AND type='index'
2425
- UNION ALL
2426
- SELECT sql
2427
- FROM sqlite_temp_master
2428
- WHERE name='index_billing_departments_on_tax_group_id' AND type='index'
2429
-
2430
-  (0.2ms)  SELECT sql
2431
- FROM sqlite_master
2432
- WHERE name='index_billing_modifiers_on_bill_id' AND type='index'
2433
- UNION ALL
2434
- SELECT sql
2435
- FROM sqlite_temp_master
2436
- WHERE name='index_billing_modifiers_on_bill_id' AND type='index'
2437
- 
2438
-  (0.2ms) SELECT sql
2439
- FROM sqlite_master
2440
- WHERE name='index_billing_op_fp_mappings_on_operator_id' AND type='index'
2441
- UNION ALL
2442
- SELECT sql
2443
- FROM sqlite_temp_master
2444
- WHERE name='index_billing_op_fp_mappings_on_operator_id' AND type='index'
2445
-
2446
-  (0.2ms)  SELECT sql
2447
- FROM sqlite_master
2448
- WHERE name='index_billing_op_fp_mappings_on_extface_driver_id' AND type='index'
2449
- UNION ALL
2450
- SELECT sql
2451
- FROM sqlite_temp_master
2452
- WHERE name='index_billing_op_fp_mappings_on_extface_driver_id' AND type='index'
2453
- 
2454
-  (0.2ms) SELECT sql
2455
- FROM sqlite_master
2456
- WHERE name='index_billing_operators_on_deleted_at' AND type='index'
2457
- UNION ALL
2458
- SELECT sql
2459
- FROM sqlite_temp_master
2460
- WHERE name='index_billing_operators_on_deleted_at' AND type='index'
2461
-
2462
-  (0.2ms)  SELECT sql
2463
- FROM sqlite_master
2464
- WHERE name='index_billing_origins_on_transfer_device_id' AND type='index'
2465
- UNION ALL
2466
- SELECT sql
2467
- FROM sqlite_temp_master
2468
- WHERE name='index_billing_origins_on_transfer_device_id' AND type='index'
2469
- 
2470
-  (0.2ms) SELECT sql
2471
- FROM sqlite_master
2472
- WHERE name='index_billing_origins_on_deleted_at' AND type='index'
2473
- UNION ALL
2474
- SELECT sql
2475
- FROM sqlite_temp_master
2476
- WHERE name='index_billing_origins_on_deleted_at' AND type='index'
2477
-
2478
-  (0.2ms)  SELECT sql
2479
- FROM sqlite_master
2480
- WHERE name='index_billing_origins_on_fiscal_device_id' AND type='index'
2481
- UNION ALL
2482
- SELECT sql
2483
- FROM sqlite_temp_master
2484
- WHERE name='index_billing_origins_on_fiscal_device_id' AND type='index'
2485
- 
2486
-  (0.2ms) SELECT sql
2487
- FROM sqlite_master
2488
- WHERE name='index_billing_payment_types_on_deleted_at' AND type='index'
2489
- UNION ALL
2490
- SELECT sql
2491
- FROM sqlite_temp_master
2492
- WHERE name='index_billing_payment_types_on_deleted_at' AND type='index'
2493
-
2494
-  (0.2ms)  SELECT sql
2495
- FROM sqlite_master
2496
- WHERE name='index_billing_payments_on_bill_id' AND type='index'
2497
- UNION ALL
2498
- SELECT sql
2499
- FROM sqlite_temp_master
2500
- WHERE name='index_billing_payments_on_bill_id' AND type='index'
2501
- 
2502
-  (0.2ms) SELECT sql
2503
- FROM sqlite_master
2504
- WHERE name='index_billing_payments_on_deleted_at' AND type='index'
2505
- UNION ALL
2506
- SELECT sql
2507
- FROM sqlite_temp_master
2508
- WHERE name='index_billing_payments_on_deleted_at' AND type='index'
2509
-
2510
-  (0.2ms)  SELECT sql
2511
- FROM sqlite_master
2512
- WHERE name='index_billing_plus_on_department_id' AND type='index'
2513
- UNION ALL
2514
- SELECT sql
2515
- FROM sqlite_temp_master
2516
- WHERE name='index_billing_plus_on_department_id' AND type='index'
2517
- 
2518
-  (0.2ms) SELECT sql
2519
- FROM sqlite_master
2520
- WHERE name='index_billing_plus_on_tax_group_id' AND type='index'
2521
- UNION ALL
2522
- SELECT sql
2523
- FROM sqlite_temp_master
2524
- WHERE name='index_billing_plus_on_tax_group_id' AND type='index'
2525
-
2526
-  (0.2ms)  SELECT sql
2527
- FROM sqlite_master
2528
- WHERE name='index_billing_pt_fp_mappings_on_payment_type_id' AND type='index'
2529
- UNION ALL
2530
- SELECT sql
2531
- FROM sqlite_temp_master
2532
- WHERE name='index_billing_pt_fp_mappings_on_payment_type_id' AND type='index'
2533
- 
2534
-  (0.2ms) SELECT sql
2535
- FROM sqlite_master
2536
- WHERE name='index_billing_pt_fp_mappings_on_extface_driver_id' AND type='index'
2537
- UNION ALL
2538
- SELECT sql
2539
- FROM sqlite_temp_master
2540
- WHERE name='index_billing_pt_fp_mappings_on_extface_driver_id' AND type='index'
2541
-
2542
-  (0.2ms)  SELECT sql
2543
- FROM sqlite_master
2544
- WHERE name='index_billing_reports_on_origin_id' AND type='index'
2545
- UNION ALL
2546
- SELECT sql
2547
- FROM sqlite_temp_master
2548
- WHERE name='index_billing_reports_on_origin_id' AND type='index'
2549
- 
2550
-  (0.2ms) SELECT sql
2551
- FROM sqlite_master
2552
- WHERE name='index_billing_tg_fp_mappings_on_tax_group_id' AND type='index'
2553
- UNION ALL
2554
- SELECT sql
2555
- FROM sqlite_temp_master
2556
- WHERE name='index_billing_tg_fp_mappings_on_tax_group_id' AND type='index'
2557
-
2558
-  (0.2ms)  SELECT sql
2559
- FROM sqlite_master
2560
- WHERE name='index_billing_tg_fp_mappings_on_extface_driver_id' AND type='index'
2561
- UNION ALL
2562
- SELECT sql
2563
- FROM sqlite_temp_master
2564
- WHERE name='index_billing_tg_fp_mappings_on_extface_driver_id' AND type='index'
2565
- 
2566
-  (0.2ms) SELECT sql
2567
- FROM sqlite_master
2568
- WHERE name='index_billing_versions_on_item_type_and_item_id' AND type='index'
2569
- UNION ALL
2570
- SELECT sql
2571
- FROM sqlite_temp_master
2572
- WHERE name='index_billing_versions_on_item_type_and_item_id' AND type='index'
2573
-
2574
- ActiveRecord::SchemaMigration Load (0.3ms) SELECT "schema_migrations".* FROM "schema_migrations"
2575
- Migrating to AddDeletedAtToBillingReport (20150512040421)
2576
-  (0.1ms) begin transaction
2577
-  (0.6ms) ALTER TABLE "billing_reports" ADD "deleted_at" datetime
2578
- SQL (0.3ms) INSERT INTO "schema_migrations" ("version") VALUES (?) [["version", "20150512040421"]]
2579
-  (114.6ms) commit transaction
2580
- ActiveRecord::SchemaMigration Load (0.5ms) SELECT "schema_migrations".* FROM "schema_migrations"
2581
-  (0.3ms)  SELECT sql
2582
- FROM sqlite_master
2583
- WHERE name='index_billing_bills_on_billable_id_and_billable_type' AND type='index'
2584
- UNION ALL
2585
- SELECT sql
2586
- FROM sqlite_temp_master
2587
- WHERE name='index_billing_bills_on_billable_id_and_billable_type' AND type='index'
2588
- 
2589
-  (0.3ms) SELECT sql
2590
- FROM sqlite_master
2591
- WHERE name='index_billing_bills_on_origin_id' AND type='index'
2592
- UNION ALL
2593
- SELECT sql
2594
- FROM sqlite_temp_master
2595
- WHERE name='index_billing_bills_on_origin_id' AND type='index'
2596
-
2597
-  (0.2ms)  SELECT sql
2598
- FROM sqlite_master
2599
- WHERE name='index_billing_bills_on_extface_job_id' AND type='index'
2600
- UNION ALL
2601
- SELECT sql
2602
- FROM sqlite_temp_master
2603
- WHERE name='index_billing_bills_on_extface_job_id' AND type='index'
2604
- 
2605
-  (0.2ms) SELECT sql
2606
- FROM sqlite_master
2607
- WHERE name='index_billing_bills_on_report_id' AND type='index'
2608
- UNION ALL
2609
- SELECT sql
2610
- FROM sqlite_temp_master
2611
- WHERE name='index_billing_bills_on_report_id' AND type='index'
2612
-
2613
-  (0.2ms)  SELECT sql
2614
- FROM sqlite_master
2615
- WHERE name='index_billing_charges_on_bill_id' AND type='index'
2616
- UNION ALL
2617
- SELECT sql
2618
- FROM sqlite_temp_master
2619
- WHERE name='index_billing_charges_on_bill_id' AND type='index'
2620
- 
2621
-  (0.2ms) SELECT sql
2622
- FROM sqlite_master
2623
- WHERE name='index_billing_charges_on_revenue_at' AND type='index'
2624
- UNION ALL
2625
- SELECT sql
2626
- FROM sqlite_temp_master
2627
- WHERE name='index_billing_charges_on_revenue_at' AND type='index'
2628
-
2629
-  (0.2ms)  SELECT sql
2630
- FROM sqlite_master
2631
- WHERE name='index_billing_charges_on_deleted_at' AND type='index'
2632
- UNION ALL
2633
- SELECT sql
2634
- FROM sqlite_temp_master
2635
- WHERE name='index_billing_charges_on_deleted_at' AND type='index'
2636
- 
2637
-  (0.2ms) SELECT sql
2638
- FROM sqlite_master
2639
- WHERE name='index_billing_charges_on_origin_id' AND type='index'
2640
- UNION ALL
2641
- SELECT sql
2642
- FROM sqlite_temp_master
2643
- WHERE name='index_billing_charges_on_origin_id' AND type='index'
2644
-
2645
-  (0.2ms)  SELECT sql
2646
- FROM sqlite_master
2647
- WHERE name='index_billing_charges_on_chargable_id_and_chargable_type' AND type='index'
2648
- UNION ALL
2649
- SELECT sql
2650
- FROM sqlite_temp_master
2651
- WHERE name='index_billing_charges_on_chargable_id_and_chargable_type' AND type='index'
2652
- 
2653
-  (0.2ms) SELECT sql
2654
- FROM sqlite_master
2655
- WHERE name='index_billing_departments_on_deleted_at' AND type='index'
2656
- UNION ALL
2657
- SELECT sql
2658
- FROM sqlite_temp_master
2659
- WHERE name='index_billing_departments_on_deleted_at' AND type='index'
2660
-
2661
-  (0.2ms)  SELECT sql
2662
- FROM sqlite_master
2663
- WHERE name='index_billing_departments_on_tax_group_id' AND type='index'
2664
- UNION ALL
2665
- SELECT sql
2666
- FROM sqlite_temp_master
2667
- WHERE name='index_billing_departments_on_tax_group_id' AND type='index'
2668
- 
2669
-  (0.2ms) SELECT sql
2670
- FROM sqlite_master
2671
- WHERE name='index_billing_modifiers_on_bill_id' AND type='index'
2672
- UNION ALL
2673
- SELECT sql
2674
- FROM sqlite_temp_master
2675
- WHERE name='index_billing_modifiers_on_bill_id' AND type='index'
2676
-
2677
-  (0.2ms)  SELECT sql
2678
- FROM sqlite_master
2679
- WHERE name='index_billing_op_fp_mappings_on_operator_id' AND type='index'
2680
- UNION ALL
2681
- SELECT sql
2682
- FROM sqlite_temp_master
2683
- WHERE name='index_billing_op_fp_mappings_on_operator_id' AND type='index'
2684
- 
2685
-  (0.2ms) SELECT sql
2686
- FROM sqlite_master
2687
- WHERE name='index_billing_op_fp_mappings_on_extface_driver_id' AND type='index'
2688
- UNION ALL
2689
- SELECT sql
2690
- FROM sqlite_temp_master
2691
- WHERE name='index_billing_op_fp_mappings_on_extface_driver_id' AND type='index'
2692
-
2693
-  (0.2ms)  SELECT sql
2694
- FROM sqlite_master
2695
- WHERE name='index_billing_operators_on_deleted_at' AND type='index'
2696
- UNION ALL
2697
- SELECT sql
2698
- FROM sqlite_temp_master
2699
- WHERE name='index_billing_operators_on_deleted_at' AND type='index'
2700
- 
2701
-  (0.2ms) SELECT sql
2702
- FROM sqlite_master
2703
- WHERE name='index_billing_origins_on_transfer_device_id' AND type='index'
2704
- UNION ALL
2705
- SELECT sql
2706
- FROM sqlite_temp_master
2707
- WHERE name='index_billing_origins_on_transfer_device_id' AND type='index'
2708
-
2709
-  (0.2ms)  SELECT sql
2710
- FROM sqlite_master
2711
- WHERE name='index_billing_origins_on_deleted_at' AND type='index'
2712
- UNION ALL
2713
- SELECT sql
2714
- FROM sqlite_temp_master
2715
- WHERE name='index_billing_origins_on_deleted_at' AND type='index'
2716
- 
2717
-  (0.2ms) SELECT sql
2718
- FROM sqlite_master
2719
- WHERE name='index_billing_origins_on_fiscal_device_id' AND type='index'
2720
- UNION ALL
2721
- SELECT sql
2722
- FROM sqlite_temp_master
2723
- WHERE name='index_billing_origins_on_fiscal_device_id' AND type='index'
2724
-
2725
-  (0.2ms)  SELECT sql
2726
- FROM sqlite_master
2727
- WHERE name='index_billing_payment_types_on_deleted_at' AND type='index'
2728
- UNION ALL
2729
- SELECT sql
2730
- FROM sqlite_temp_master
2731
- WHERE name='index_billing_payment_types_on_deleted_at' AND type='index'
2732
- 
2733
-  (0.2ms) SELECT sql
2734
- FROM sqlite_master
2735
- WHERE name='index_billing_payments_on_bill_id' AND type='index'
2736
- UNION ALL
2737
- SELECT sql
2738
- FROM sqlite_temp_master
2739
- WHERE name='index_billing_payments_on_bill_id' AND type='index'
2740
-
2741
-  (0.2ms)  SELECT sql
2742
- FROM sqlite_master
2743
- WHERE name='index_billing_payments_on_deleted_at' AND type='index'
2744
- UNION ALL
2745
- SELECT sql
2746
- FROM sqlite_temp_master
2747
- WHERE name='index_billing_payments_on_deleted_at' AND type='index'
2748
- 
2749
-  (0.2ms) SELECT sql
2750
- FROM sqlite_master
2751
- WHERE name='index_billing_plus_on_department_id' AND type='index'
2752
- UNION ALL
2753
- SELECT sql
2754
- FROM sqlite_temp_master
2755
- WHERE name='index_billing_plus_on_department_id' AND type='index'
2756
-
2757
-  (0.2ms)  SELECT sql
2758
- FROM sqlite_master
2759
- WHERE name='index_billing_plus_on_tax_group_id' AND type='index'
2760
- UNION ALL
2761
- SELECT sql
2762
- FROM sqlite_temp_master
2763
- WHERE name='index_billing_plus_on_tax_group_id' AND type='index'
2764
- 
2765
-  (0.2ms) SELECT sql
2766
- FROM sqlite_master
2767
- WHERE name='index_billing_pt_fp_mappings_on_payment_type_id' AND type='index'
2768
- UNION ALL
2769
- SELECT sql
2770
- FROM sqlite_temp_master
2771
- WHERE name='index_billing_pt_fp_mappings_on_payment_type_id' AND type='index'
2772
-
2773
-  (0.2ms)  SELECT sql
2774
- FROM sqlite_master
2775
- WHERE name='index_billing_pt_fp_mappings_on_extface_driver_id' AND type='index'
2776
- UNION ALL
2777
- SELECT sql
2778
- FROM sqlite_temp_master
2779
- WHERE name='index_billing_pt_fp_mappings_on_extface_driver_id' AND type='index'
2780
- 
2781
-  (0.2ms) SELECT sql
2782
- FROM sqlite_master
2783
- WHERE name='index_billing_reports_on_origin_id' AND type='index'
2784
- UNION ALL
2785
- SELECT sql
2786
- FROM sqlite_temp_master
2787
- WHERE name='index_billing_reports_on_origin_id' AND type='index'
2788
-
2789
-  (0.2ms)  SELECT sql
2790
- FROM sqlite_master
2791
- WHERE name='index_billing_tg_fp_mappings_on_tax_group_id' AND type='index'
2792
- UNION ALL
2793
- SELECT sql
2794
- FROM sqlite_temp_master
2795
- WHERE name='index_billing_tg_fp_mappings_on_tax_group_id' AND type='index'
2796
- 
2797
-  (0.2ms) SELECT sql
2798
- FROM sqlite_master
2799
- WHERE name='index_billing_tg_fp_mappings_on_extface_driver_id' AND type='index'
2800
- UNION ALL
2801
- SELECT sql
2802
- FROM sqlite_temp_master
2803
- WHERE name='index_billing_tg_fp_mappings_on_extface_driver_id' AND type='index'
2804
-
2805
-  (0.2ms)  SELECT sql
2806
- FROM sqlite_master
2807
- WHERE name='index_billing_versions_on_item_type_and_item_id' AND type='index'
2808
- UNION ALL
2809
- SELECT sql
2810
- FROM sqlite_temp_master
2811
- WHERE name='index_billing_versions_on_item_type_and_item_id' AND type='index'
2812
- 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: billing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7i
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Vangelov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-31 00:00:00.000000000 Z
11
+ date: 2015-05-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -52,20 +52,6 @@ dependencies:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: resque
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
67
- - !ruby/object:Gem::Version
68
- version: '0'
69
55
  - !ruby/object:Gem::Dependency
70
56
  name: sqlite3
71
57
  requirement: !ruby/object:Gem::Requirement
@@ -90,7 +76,6 @@ files:
90
76
  - MIT-LICENSE
91
77
  - README.rdoc
92
78
  - Rakefile
93
- - app/jobs/billing/issue_fiscal_doc.rb
94
79
  - app/models/billing/bill.rb
95
80
  - app/models/billing/charge.rb
96
81
  - app/models/billing/department.rb
@@ -172,8 +157,6 @@ files:
172
157
  - db/migrate/20141229234928_create_billing_resources.rb
173
158
  - db/migrate/20150311013019_add_pwd_to_billing_operator_mapping.rb
174
159
  - db/migrate/20150510142229_add_object_changes_to_billing_versions.rb
175
- - db/migrate/20150510235441_add_master_to_billing_version.rb
176
- - db/migrate/20150512040421_add_deleted_at_to_billing_report.rb
177
160
  - lib/billing.rb
178
161
  - lib/billing/billable.rb
179
162
  - lib/billing/engine.rb
@@ -263,12 +246,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
263
246
  version: '0'
264
247
  required_rubygems_version: !ruby/object:Gem::Requirement
265
248
  requirements:
266
- - - ">"
249
+ - - ">="
267
250
  - !ruby/object:Gem::Version
268
- version: 1.3.1
251
+ version: '0'
269
252
  requirements: []
270
253
  rubyforge_project:
271
- rubygems_version: 2.5.0
254
+ rubygems_version: 2.4.6
272
255
  signing_key:
273
256
  specification_version: 4
274
257
  summary: Billing for Rails 4 app
@@ -1,132 +0,0 @@
1
- module Resque
2
- module Plugins
3
- module ExtfaceLonelyDevice
4
- LOCK_TIMEOUT = 60 * 60 * 24 * 5 # 5 days
5
-
6
- def lock_timeout
7
- Time.now.to_i + LOCK_TIMEOUT + 1
8
- end
9
-
10
- def requeue_interval
11
- self.instance_variable_get(:@requeue_interval) || 1
12
- end
13
-
14
- # Overwrite this method to uniquely identify which mutex should be used
15
- # for a resque worker.
16
- def redis_key(*args)
17
- "extface_"
18
- end
19
-
20
- def can_lock_queue?(*args)
21
- now = Time.now.to_i
22
- key = redis_key(*args)
23
- timeout = lock_timeout
24
-
25
- # Per http://redis.io/commands/setnx
26
- return true if Resque.redis.setnx(key, timeout)
27
- return false if Resque.redis.get(key).to_i > now
28
- return true if Resque.redis.getset(key, timeout).to_i <= now
29
- return false
30
- rescue ActiveRecord::RecordNotFound #redis_key exception
31
- p "Not found!!!"
32
- sleep 1
33
- reenqueue(*args) #will stop if new redis_key exception
34
- end
35
-
36
- def unlock_queue(*args)
37
- Resque.redis.del(redis_key(*args))
38
- end
39
-
40
- def reenqueue(*args)
41
- Resque.enqueue_to(redis_key(*args), self, *args)
42
- end
43
-
44
- def before_perform(*args)
45
- unless can_lock_queue?(*args)
46
- # Sleep so the CPU's rest
47
- sleep(requeue_interval)
48
-
49
- # can't get the lock, so re-enqueue the task
50
- reenqueue(*args)
51
-
52
- # and don't perform
53
- raise Resque::Job::DontPerform
54
- end
55
- end
56
-
57
- def around_perform(*args)
58
- begin
59
- yield
60
- ensure
61
- unlock_queue(*args)
62
- end
63
- end
64
- end
65
- end
66
- end
67
-
68
- module Billing
69
- class IssueFiscalDoc
70
- extend Resque::Plugins::ExtfaceLonelyDevice
71
-
72
- def self.redis_key(bill_id)
73
- "extface_#{Bill.find(bill_id).extface_job.device_id}"
74
- end
75
-
76
- def self.perform(bill_id)
77
- bill = Bill.find(bill_id)
78
- qname = "extface_#{bill.extface_job.device_id}"
79
- wjs = Resque::Worker.working.find_all{ |w| w.job && w.job['queue'] == qname }
80
-
81
- p "############################"
82
- p "d: #{bill.extface_job.device_id} Issue Fiscal Doc ##{bill_id}, job: #{bill.extface_job_id}, wjs: #{wjs.inspect}"
83
- p "____________________________"
84
- p "active jobs: #{bill.extface_job.device.jobs.active.count}"
85
-
86
-
87
- bill.extface_job.runtime do |s|
88
- return unless bill.fiscalizable?
89
- operator_mapping = bill.find_operator_mapping_for(s)
90
- s.notify "Fiscal Doc Start"
91
- s.autofix_unclosed_doc
92
- s.open_fiscal_doc(operator_mapping.try(:mapping), operator_mapping.try(:pwd))
93
- s.notify "Register Sale"
94
- bill.charges.each do |charge|
95
- neto, percent_ratio = nil, nil, nil
96
- if modifier = charge.modifier
97
- neto = modifier.fixed_value
98
- percent_ratio = modifier.percent_ratio unless neto.present?
99
- end
100
- if charge.price.zero? #printing comments with zero charges (TODO check zero charges allowed?)
101
- s.add_comment charge.text
102
- else
103
- s.add_sale(
104
- s.class::SaleItem.new(
105
- price: charge.price.to_f,
106
- text1: charge.name,
107
- text2: charge.description,
108
- tax_group: charge.find_tax_group_mapping_for(s), #find tax group mapping by ratio , not nice
109
- qty: charge.qty,
110
- neto: neto,
111
- percent_ratio: percent_ratio #TODO check format
112
- )
113
- )
114
- end
115
- end
116
- if global_modifier_value = bill.global_modifier_value
117
- s.notify "Register Global Modifier"
118
- s.add_total_modifier global_modifier_value.to_f
119
- end
120
- s.notify "Register Payment"
121
- bill.payments.each do |payment|
122
- s.add_payment payment.value.to_f, payment.find_payment_type_mapping_for(s)
123
- end
124
- s.notify "Close Fiscal Receipt"
125
- s.close_fiscal_doc
126
- s.notify "Fiscal Doc End"
127
- end
128
- rescue Resque::TermException
129
- reenqueue(bill_id)
130
- end
131
- end
132
- end
@@ -1,6 +0,0 @@
1
- class AddMasterToBillingVersion < ActiveRecord::Migration
2
- def change
3
- add_column :billing_versions, :master_id, :integer
4
- add_column :billing_versions, :master_type, :string
5
- end
6
- end
@@ -1,5 +0,0 @@
1
- class AddDeletedAtToBillingReport < ActiveRecord::Migration
2
- def change
3
- add_column :billing_reports, :deleted_at, :timestamp
4
- end
5
- end