query GetInvoices(
	$businessId: ID!
	$page: Int
	$pageSize: Int
	$sort: [InvoiceSort!]! = [INVOICE_DATE_DESC]
	$status: InvoiceStatus
	$customerId: ID
) {
	business(id: $businessId) {
		id
		invoices(
			page: $page
			pageSize: $pageSize
			sort: $sort
			status: $status
			customerId: $customerId
		) {
			edges {
				node {
					id
					invoiceNumber
					invoiceDate
					dueDate
					status
					title
					customer {
						id
						name
						email
					}
					amountDue {
						value
						currency {
							code
							symbol
						}
					}
					amountPaid {
						value
						currency {
							code
							symbol
						}
					}
					total {
						value
						currency {
							code
							symbol
						}
					}
					currency {
						code
						symbol
					}
					createdAt
					modifiedAt
					lastSentAt
					lastViewedAt
				}
			}
			pageInfo {
				currentPage
				totalPages
				totalCount
			}
		}
	}
}

query GetInvoice($businessId: ID!, $invoiceId: ID!) {
	business(id: $businessId) {
		id
		invoice(id: $invoiceId) {
			id
			invoiceNumber
			invoiceDate
			dueDate
			status
			title
			subhead
			poNumber
			memo
			footer
			pdfUrl
			viewUrl
			customer {
				id
				name
				firstName
				lastName
				email
				address {
					addressLine1
					addressLine2
					city
					province {
						code
						name
					}
					country {
						code
						name
					}
					postalCode
				}
			}
			items {
				product {
					id
					name
				}
				description
				quantity
				unitPrice
				subtotal {
					value
					currency {
						code
					}
				}
				total {
					value
					currency {
						code
					}
				}
				taxes {
					salesTax {
						id
						name
						abbreviation
					}
					amount {
						value
						currency {
							code
						}
					}
				}
			}
			discounts {
				... on FixedInvoiceDiscount {
					name
					amount
				}
				... on PercentageInvoiceDiscount {
					name
					percentage
				}
			}
			subtotal {
				value
				currency {
					code
					symbol
				}
			}
			taxTotal {
				value
				currency {
					code
					symbol
				}
			}
			discountTotal {
				value
				currency {
					code
					symbol
				}
			}
			total {
				value
				currency {
					code
					symbol
				}
			}
			amountDue {
				value
				currency {
					code
					symbol
				}
			}
			amountPaid {
				value
				currency {
					code
					symbol
				}
			}
			currency {
				code
				symbol
				name
			}
			exchangeRate
			createdAt
			modifiedAt
			lastSentAt
			lastSentVia
			lastViewedAt
		}
	}
}
