Class: Waveapps::Invoice

Inherits:
Object
  • Object
show all
Defined in:
lib/waveapps.rb

Constant Summary collapse

ListInvoicesQuery =
Waveapps::Client.parse <<-'GRAPHQL'
		query($businessId: ID!, $page: Int!, $pageSize: Int!) {
	  business(id: $businessId) {
	    id
	    isClassicInvoicing
	    invoices(page: $page, pageSize: $pageSize) {
	      pageInfo {
	        currentPage
	        totalPages
	        totalCount
	      }
	      edges {
	        node {
	          id
	          createdAt
	          modifiedAt
	          pdfUrl
	          viewUrl
	          status
	          title
	          subhead
	          invoiceNumber
	          invoiceDate
	          poNumber
	          customer {
	            id
	            name
	            # Can add additional customer fields here
	          }
	          currency {
	            code
	          }
	          dueDate
	          amountDue {
	            value
	            currency {
	              symbol
	            }
	          }
	          amountPaid {
	            value
	            currency {
	              symbol
	            }
	          }
	          taxTotal {
	            value
	            currency {
	              symbol
	            }
	          }
	          total {
	            value
	            currency {
	              symbol
	            }
	          }
	          exchangeRate
	          footer
	          memo
	          disableCreditCardPayments
	          disableBankPayments
	          itemTitle
	          unitTitle
	          priceTitle
	          amountTitle
	          hideName
	          hideDescription
	          hideUnit
	          hidePrice
	          hideAmount
	          items {
	            product {
	              id
	              name
	              # Can add additional product fields here
	            }
	            description
	            quantity
	            price
	            subtotal {
	              value
	              currency {
	                symbol
	              }
	            }
	            total {
	              value
	              currency {
	                symbol
	              }
	            }
	            account {
	              id
	              name
	              subtype {
	                name
	                value
	              }
	              # Can add additional account fields here
	            }
	            taxes {
	              amount {
	                value
	              }
	              salesTax {
	                id
	                name
	                # Can add additional sales tax fields here
	              }
	            }
	          }
	          lastSentAt
	          lastSentVia
	          lastViewedAt
	        }
	      }
	    }
	  }
	}
GRAPHQL
CreateInvoiceQuery =
Waveapps::Client.parse <<-'GRAPHQL'
	mutation ($input: InvoiceCreateInput!) {
  invoiceCreate(input: $input) {
    didSucceed
    inputErrors {
      message
      code
      path
    }
    invoice {
      id
      createdAt
      modifiedAt
      pdfUrl
      viewUrl
      status
      title
      subhead
      invoiceNumber
      invoiceDate
      poNumber
      customer {
        id
        name
        # Can add additional customer fields here
      }
      currency {
        code
      }
      dueDate
      amountDue {
        value
        currency {
          symbol
        }
      }
      amountPaid {
        value
        currency {
          symbol
        }
      }
      taxTotal {
        value
        currency {
          symbol
        }
      }
      total {
        value
        currency {
          symbol
        }
      }
      exchangeRate
      footer
      memo
      disableCreditCardPayments
      disableBankPayments
      itemTitle
      unitTitle
      priceTitle
      amountTitle
      hideName
      hideDescription
      hideUnit
      hidePrice
      hideAmount
      items {
        product {
          id
          name
          # Can add additional product fields here
        }
        description
        quantity
        price
        subtotal {
          value
          currency {
            symbol
          }
        }
        total {
          value
          currency {
            symbol
          }
        }
        account {
          id
          name
          subtype {
            name
            value
          }
          # Can add additional account fields here
        }
        taxes {
          amount {
            value
          }
          salesTax {
            id
            name
            # Can add additional sales tax fields here
          }
        }
      }
      lastSentAt
      lastSentVia
      lastViewedAt
    }
  }
}
GRAPHQL
DeleteInvoiceQuery =
Waveapps::Client.parse <<-'GRAPHQL'
	mutation ($input: InvoiceDeleteInput!) {
		invoiceDelete(input: $input) {
    didSucceed
    inputErrors {
      code
      message
      path
    }
  }
	}
GRAPHQL

Class Method Summary collapse

Class Method Details

.create_invoice(items:, business_id:, customer_id:) ⇒ Object

“input”: {

  "businessId": "<BUSINESS_ID>",
  "customerId": "<CUSTOMER_ID>",
  "items": [
    {
      "productId": "<PRODUCT_ID>"
    }
  ]
}

}



291
292
293
294
295
296
297
298
299
300
301
302
303
304
# File 'lib/waveapps.rb', line 291

def self.create_invoice(items: , business_id: , customer_id: )
	Waveapps::Client.query(CreateInvoiceQuery, variables: {
		input: {
			businessId: business_id,
			customerId: customer_id,
			items: items.map { |pid| {
         productId: pid[:product_id],
         quantity: pid[:quantity],
         description: pid[:description],
         unitPrice: pid[:unit_price]
       }}
		}
	})
end

.delete_invoice(id) ⇒ Object



319
320
321
322
# File 'lib/waveapps.rb', line 319

def self.delete_invoice(id)
	result = Waveapps::Client.query(DeleteInvoiceQuery, variables: {input: { id: id}})
result.data
end

.list_invoices(page: 1, page_size: 10, business_id:) ⇒ Object



154
155
156
157
158
159
160
# File 'lib/waveapps.rb', line 154

def self.list_invoices(page: 1, page_size: 10, business_id:)
	result = Waveapps::Client.query(ListInvoicesQuery, variables: {
     businessId: business_id, page: page, pageSize: page_size
   }).data
	return nil if result.nil?
	result.business.invoices.edges.map {|n| n.node}
end