Class: Ish::Invoice

Inherits:
Object
  • Object
show all
Includes:
Mongoid::Autoinc, Mongoid::Document, Mongoid::Timestamps
Defined in:
lib/ish/invoice.rb

Overview

Invoice - for wasya.co 2017-10-31 vp Start 2023-08-18 vp Continue

Instance Method Summary collapse

Instance Method Details

#assetObject

the pdf



30
# File 'lib/ish/invoice.rb', line 30

has_one :asset, class_name: '::Gameui::Asset3d'

#filenameObject



32
33
34
# File 'lib/ish/invoice.rb', line 32

def filename
  "invoice-#{number}.pdf"
end

#generate_monthly_invoiceObject

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



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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
# File 'lib/ish/invoice.rb', line 50

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

#leadsetObject



22
23
24
# File 'lib/ish/invoice.rb', line 22

def leadset
  Leadset.find leadset_id
end