import moneybird from "../../moneybird.app.mjs";
import constants from "../common/constants.mjs";
export default {
key: "moneybird-create-sale-invoice",
name: "Create Sale Invoice",
description: "Create a sale invoice. [See docs here](https://developer.moneybird.com/api/sales_invoices/#post_sales_invoices)",
version: "0.0.1",
type: "action",
props: {
moneybird,
contactId: {
propDefinition: [
moneybird,
"contactId",
],
},
productId: {
propDefinition: [
moneybird,
"productId",
],
optional: true,
},
projectId: {
propDefinition: [
moneybird,
"projectId",
],
optional: true,
},
price: {
label: "Price",
description: "The estimated price . E.g 110,15",
type: "string",
},
amount: {
label: "Amount",
description: "The estimated amount",
type: "string",
},
discount: {
label: "Discount",
description: "Discount percentage. E.g 15.00",
type: "string",
optional: true,
},
language: {
label: "Language",
description: "The invoice language",
type: "string",
options: constants.QUOTE_LANGUAGES,
optional: true,
},
currency: {
label: "Currency",
description: "The invoice currency. E.g. EUR or USD",
type: "string",
optional: true,
},
reference: {
label: "reference",
description: "The invoice reference",
type: "string",
optional: true,
},
pricesAreIncludedTax: {
label: "Prices Are Included Tax",
description: "If the prices are included taxes",
type: "boolean",
optional: true,
},
showTax: {
label: "Show Tax",
description: "Show the taxes",
type: "boolean",
optional: true,
},
description: {
label: "Description",
description: "Description",
type: "string",
optional: true,
},
},
async run({ $ }) {
const response = await this.moneybird.createSaleInvoice({
$,
data: {
sales_invoice: {
contact_id: this.contactId,
reference: this.reference,
language: this.language,
currency: this.currency,
prices_are_incl_tax: this.pricesAreIncludedTax,
show_tax: this.showTax,
discount: this.discount,
details_attributes: [
{
description: this.description,
price: this.price,
amount: this.amount,
product_id: this.productId,
project_id: this.projectId,
},
],
},
},
});
$.export("$summary", "Successfully created sale invoice.");
return response;
},
};