Class: Wco::Invoice
- Inherits:
-
Object
- Object
- Wco::Invoice
- Includes:
- Mongoid::Autoinc, Mongoid::Document, Mongoid::Paranoia, Mongoid::Timestamps
- Defined in:
- app/models/wco/invoice.rb
Overview
Invoice - for wasya.co 2017-10-31 vp Start 2023-08-18 vp Continue
Instance Attribute Summary collapse
-
#is_stripe ⇒ Object
Returns the value of attribute is_stripe.
Instance Method Summary collapse
-
#asset ⇒ Object
the pdf.
- #create_stripe ⇒ Object
- #filename ⇒ Object
-
#generate_monthly_invoice ⇒ Object
Prawn/pdf unit of measure is 1/72“ Canvas width: 612, height: 792.
Instance Attribute Details
#is_stripe ⇒ Object
Returns the value of attribute is_stripe.
17 18 19 |
# File 'app/models/wco/invoice.rb', line 17 def is_stripe @is_stripe end |
Instance Method Details
#asset ⇒ Object
the pdf
29 |
# File 'app/models/wco/invoice.rb', line 29 has_one :asset, class_name: 'Wco::Asset' |
#create_stripe ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'app/models/wco/invoice.rb', line 39 def create_stripe if is_stripe stripe_invoice = Stripe::Invoice.create({ customer: leadset.customer_id, collection_method: 'send_invoice', days_until_due: 0, # collection_method: 'charge_automatically', pending_invoice_items_behavior: 'exclude', }) items.each do |item| stripe_price = Wco::Price.find( item[:price_id] ).price_id invoice_item = Stripe::InvoiceItem.create({ customer: leadset.customer_id, price: stripe_price, invoice: stripe_invoice.id, quantity: item[:quantity], }) end Stripe::Invoice.finalize_invoice( stripe_invoice[:id] ) self.invoice_id = stripe_invoice[:id] end end |
#filename ⇒ Object
31 32 33 |
# File 'app/models/wco/invoice.rb', line 31 def filename "invoice-#{number}.pdf" end |
#generate_monthly_invoice ⇒ Object
Prawn/pdf unit of measure is 1/72“ Canvas width: 612, height: 792
tree image: 896 x 1159 tree image: 791 x 1024 tree image: 964 x 1248
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'app/models/wco/invoice.rb', line 69 def generate_monthly_invoice tree_img_url = "#{Rails.root.join('public')}/tree-#{number}.jpg" wasya_co_logo_url = "#{Rails.root.join('public')}/259x66-WasyaCo-logo.png" ## canvas width: 612, height: 792 pdf = Prawn::Document.new pdf.canvas do pdf.image tree_img_url, at: [ 0, 792 ], width: 612 pdf.fill_color 'ffffff' pdf.transparent( 0.75 ) do pdf.fill_rectangle [0, 792], 612, 792 end pdf.fill_color '000000' pdf.image wasya_co_logo_url, at: [252, 720], width: 108 ## 1.5" pdf.bounding_box( [0.75*72, 9.25*72], width: 3.25*72, height: 0.75*72 ) do pdf.text "From:" pdf.text "Wasya Co" pdf.text "[email protected]" end pdf.bounding_box( [4.5*72, 9.25*72], width: 3.25*72, height: 0.75*72 ) do pdf.text "Stats:" pdf.text "Date: #{ Time.now.to_date.to_s }" pdf.text "Invoice #: #{ number }" end pdf.bounding_box( [0.75*72, 8.25*72], width: 3.25*72, height: 0.75*72 ) do pdf.text "To:" pdf.text leadset.name pdf.text leadset.email end pdf.bounding_box( [4.5*72, 8.25*72], width: 3.25*72, height: 0.75*72 ) do pdf.text "Notes:" pdf.text "Support & various tasks, for the month of #{ month_on.strftime('%B') }." end lineitems_with_header = [ [ 'Description', 'Per Unit', '# of Units', 'Subtotal' ] ] total = 0 leadset.subscriptions.each do |i| subtotal = (i.price.amount_cents * i.quantity).to_f/100 lineitems_with_header.push([ i.price.product.name, i.price.name_simple, i.quantity, subtotal ]) total += subtotal end pdf.move_down 20 pdf.table(lineitems_with_header, { position: :center, width: 7.5*72, cell_style: { inline_format: true, borders: [ :bottom ] }, } ) pdf.table([ [ 'Total' ], [ total ], ], { position: 7*72, width: 1*72, cell_style: { inline_format: true, borders: [ :bottom ] }, } ) pdf.text_box "Thank you!", at: [ 3.25*72, 1.25*72 ], width: 2*72, height: 1*72, align: :center end return pdf end |