From 2ff47f3204a4f497572ddff6f027f9a05a1d330f Mon Sep 17 00:00:00 2001 From: Peng DU Date: Fri, 9 Jun 2017 11:08:08 +0200 Subject: [PATCH] add task Id: 3713, reference: 1706002/VL, stripe id: in_1ASRQy2sOmf47Nz9Xpxtw46A, invoice total: 30.0, stripe invoice total: 80.0, date: 2017-06-08 16:16:26 +0200 Id: 3716, reference: 1706005/VL, stripe id: in_1ASRye2sOmf47Nz9utkjPDve, invoice total: 30.0, stripe invoice total: 40.0, date: 2017-06-08 16:51:15 +0200 Id: 3717, reference: 1706006/VL, stripe id: in_1ASS1X2sOmf47Nz93Xn2UxVh, invoice total: 30.0, stripe invoice total: 40.0, date: 2017-06-08 16:54:14 +0200 Id: 3718, reference: 1706007/VL, stripe id: in_1ASSBI2sOmf47Nz9Ol0gEEfC, invoice total: 30.0, stripe invoice total: 40.0, date: 2017-06-08 17:04:19 +0200 allow find the invoices incoherent --- CHANGELOG.md | 2 ++ app/models/invoice.rb | 5 +++++ lib/tasks/fablab.rake | 18 ++++++++++++++++++ 3 files changed, 25 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index df1597c46..bc5b9885b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog Fab Manager +- add task `rake fablab:get_incoherent_invoice` allow find the invoices incoherent + ## v2.5.7 2017 June 8 - Portuguese and Brazilian support diff --git a/app/models/invoice.rb b/app/models/invoice.rb index bcc1211c9..dbd1e2390 100644 --- a/app/models/invoice.rb +++ b/app/models/invoice.rb @@ -202,6 +202,11 @@ class Invoice < ActiveRecord::Base end end + # get amount total paid + def amount_paid + total - (wallet_amount ? wallet_amount : 0) + end + private def generate_and_send_invoice unless Rails.env.test? diff --git a/lib/tasks/fablab.rake b/lib/tasks/fablab.rake index 12d1cdf16..f38a8a447 100644 --- a/lib/tasks/fablab.rake +++ b/lib/tasks/fablab.rake @@ -304,4 +304,22 @@ namespace :fablab do p.save end end + + desc 'get incoherent invoice' + task :get_incoherent_invoice, [:start_date] => :environment do |task, args| + date = Date.parse('2017-05-01') + if args.start_date + begin + date = Date.parse(args.start_date) + rescue => e + fail e + end + end + Invoice.where('created_at > ? AND stp_invoice_id IS NOT NULL', date).each do |invoice| + stp_invoice = Stripe::Invoice.retrieve(invoice.stp_invoice_id) + if invoice.amount_paid != stp_invoice.total + puts "Id: #{invoice.id}, reference: #{invoice.reference}, stripe id: #{stp_invoice.id}, invoice total: #{invoice.amount_paid / 100.0}, stripe invoice total: #{stp_invoice.total / 100.0}, date: #{invoice.created_at}" + end + end + end end