Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
172 changes: 172 additions & 0 deletions components/alegra/actions/create-contact/create-contact.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
import alegra from "../../alegra.app.mjs";
import {
STATUS_OPTIONS,
TYPE_OPTIONS,
} from "../../common/constants.mjs";
import { parseObject } from "../../common/utils.mjs";

export default {
key: "alegra-create-contact",
name: "Create Contact",
description: "Adds a new contact to Alegra. [See the documentation](https://developer.alegra.com/reference/post_contacts).",
version: "0.0.1",
type: "action",
props: {
alegra,
name: {
type: "string",
label: "Name",
description: "Name of the contact",
},
identification: {
type: "string",
label: "Identification",
description: "Identification of the contact",
optional: true,
},
address: {
type: "string",
label: "Address",
description: "Address of the contact",
optional: true,
},
city: {
type: "string",
label: "City",
description: "City of the contact",
optional: true,
},
phonePrimary: {
type: "string",
label: "Primary Phone",
description: "Primary phone number of the contact",
optional: true,
},
phoneSecondary: {
type: "string",
label: "Secondary Phone",
description: "Secondary phone number of the contact",
optional: true,
},
mobile: {
type: "string",
label: "Mobile",
description: "Mobile phone number of the contact",
optional: true,
},
email: {
type: "string",
label: "Email",
description: "Email of the contact",
optional: true,
},
type: {
type: "string",
label: "Type",
description: "Type of the contact",
options: TYPE_OPTIONS,
optional: true,
},
status: {
type: "string",
label: "Status",
description: "Status of the contact",
options: STATUS_OPTIONS,
optional: true,
},
fax: {
type: "string",
label: "Fax",
description: "Fax number of the contact",
optional: true,
},
debtToPay: {
propDefinition: [
alegra,
"debtToPay",
],
optional: true,
},
accountReceivable: {
propDefinition: [
alegra,
"debtToPay",
],
label: "Account Receivable",
description: "Id of the account receivable associated with the contact",
optional: true,
},
internalContacts: {
type: "string[]",
label: "Internal Contacts",
description: "A list of objects of internal contacts related to the contact. **Example: [ { name: \"John Doe\", email: \"[email protected]\"}]**. [See the documentation](https://developer.alegra.com/reference/post_contacts) for further information.",
optional: true,
},
ignoreRepeated: {
type: "boolean",
label: "Ignore Repeated",
description: "Ignore repeated contacts",
optional: true,
},
statementAttached: {
type: "boolean",
label: "Statement Attached",
description: "Indicates whether to include a statement for the contact",
optional: true,
},
seller: {
propDefinition: [
alegra,
"seller",
],
optional: true,
},
priceList: {
propDefinition: [
alegra,
"priceList",
],
optional: true,
},
term: {
propDefinition: [
alegra,
"term",
],
optional: true,
},
},
async run({ $ }) {
const {
alegra,
city,
address,
debtToPay,
accountReceivable,
internalContacts,
statementAttached,
...data
} = this;

const response = await alegra.createContact({
$,
data: {
...data,
address: {
city,
address,
},
accounting: {
debtToPay,
accountReceivable,
},
internalContacts: parseObject(internalContacts),
statementAttached: statementAttached
? "yes"
: "no",
},
});
$.export("$summary", `Created contact with ID ${response.id}`);
return response;
},
};
193 changes: 193 additions & 0 deletions components/alegra/actions/create-invoice/create-invoice.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,193 @@
import { ConfigurationError } from "@pipedream/platform";
import alegra from "../../alegra.app.mjs";
import {
INVOICE_STATUS_OPTIONS, PERIODICITY_OPTIONS,
} from "../../common/constants.mjs";
import { parseObject } from "../../common/utils.mjs";

export default {
key: "alegra-create-invoice",
name: "Create Invoice",
description: "Creates a new invoice in Alegra. [See the documentation](https://developer.alegra.com/reference/post_invoices)",
version: "0.0.1",
type: "action",
props: {
alegra,
status: {
type: "string",
label: "Status",
description: "Status of the invoice. If this attribute is not sent and no associated payments are sent, the invoice is created in \"draft\". If payments are sent to the invoice, the invoice is created in \"open\".",
options: INVOICE_STATUS_OPTIONS,
optional: true,
},
numberTemplateId: {
type: "string",
label: "Number Template ID",
description: "Number template ID for the invoice. You can use this to automatically numbering.",
optional: true,
},
numberTemplatePrefix: {
type: "string",
label: "Number Template Prefix",
description: "Number template prefix for the invoice. Send in case the numbering is manual. (Optional)",
optional: true,
},
numberTemplateNumber: {
type: "string",
label: "Number Template Number",
description: "Number template number for the invoice. Send in case the numbering is manual. (Required)",
optional: true,
},
items: {
type: "string[]",
label: "Items",
description: "Array of item objects (products/services) associated with the invoice. **Example: [{\"id\": \"123\", \"name\": \"Name\", \"price\": \"12.00\", \"quantity\": \"2\"}]**. [See the documentation](https://developer.alegra.com/reference/post_invoices) for further information.",
},
payments: {
type: "string[]",
label: "Payments",
description: "Array of objects indicating the payments made to the invoice. **Example: [{\"date\": \"YYYY-MM-DD\", \"account\": \"123123\", \"amount\": \"10,00\"}]**. [See the documentation](https://developer.alegra.com/reference/post_invoices) for further information.",
optional: true,
},
estimate: {
type: "string",
label: "Estimate",
description: "Specifies the identifier of the quote you want to associate with the sales invoice, in this way, the quote is invoiced and the items specified in the items parameter are associated, not those in the quote.",
optional: true,
},
termsConditions: {
type: "string",
label: "Terms and Conditions",
description: "Terms and conditions of the invoice. Maximum allowed length: 500.",
optional: true,
},
annotation: {
type: "string",
label: "Annotation",
description: "Invoice notes, visible in the PDF or printed document. Maximum allowed length: 500.",
optional: true,
},
dueDate: {
type: "string",
label: "Due Date",
description: "Invoice due date. Format yyyy-MM-dd.",
},
date: {
type: "string",
label: "Date",
description: "Invoice date. Format yyyy-MM-dd.",
},
observations: {
type: "string",
label: "Observations",
description: "Invoice observations (not visible in the PDF or printed document). Maximum allowed length: 500.",
optional: true,
},
client: {
propDefinition: [
alegra,
"client",
],
},
seller: {
propDefinition: [
alegra,
"seller",
],
description: "Seller associated with the invoice.",
optional: true,
},
pricelist: {
propDefinition: [
alegra,
"priceList",
],
description: "Price list associated with the invoice",
optional: true,
},
currency: {
type: "object",
label: "Currency",
description: "Object that includes the information of the currency and exchange rate associated with the invoice. It should only be included if the company has the multi-currency functionality active and has configured the selected currency. It must include the currency code (three letters according to ISO) and the exchange rate.",
optional: true,
},
retentions: {
type: "string[]",
label: "Retentions",
description: "Array of retention objects indicating the retentions of the sales invoice. **Example: [{\"id\": \"123123\", \"amount\": 10}]**. [See the documentation](https://developer.alegra.com/reference/post_invoices) for further information.",
optional: true,
},
warehouse: {
propDefinition: [
alegra,
"warehouse",
],
optional: true,
},
remissions: {
type: "string[]",
label: "Remissions",
description: "Array of identifiers of the remissions to be invoiced, you can associate one or more remissions by simply indicating the id of each one in an array. The client of the remissions and the sales invoice must be the same. Only open remissions can be invoiced. In this way, the items of each remission will be invoiced, and you can also specify other items with the items parameter. **Example: [{\"id\": 123, \"items\": [{\"id\": 123}], }]**. [See the documentation](https://developer.alegra.com/reference/post_invoices) for further information.",
optional: true,
},
costCenter: {
propDefinition: [
alegra,
"costCenter",
],
optional: true,
},
comments: {
type: "string[]",
label: "Comments",
description: "Array of strings with each of the comments to be associated. Comments can be updated even if the sales invoice cannot be edited.",
optional: true,
},
periodicity: {
type: "string",
label: "Periodicity",
description: "Indicates the periodicity of the payments of the invoice installments. If you want to issue the invoice, the payment method is on credit this attribute becomes mandatory.",
options: PERIODICITY_OPTIONS,
optional: true,
},
},
async run({ $ }) {
try {
const invoice = await this.alegra.generateInvoice({
$,
data: {
status: this.status,
numberTemplate: {
id: this.numberTemplateId,
prefix: this.numberTemplatePrefix,
number: this.numberTemplateNumber,
},
items: parseObject(this.items),
payments: parseObject(this.payments),
estimate: this.estimate,
termsConditions: this.termsConditions,
annotation: this.annotation,
dueDate: this.dueDate,
date: this.date,
observations: this.observations,
client: {
id: this.client,
},
seller: this.seller,
pricelist: this.pricelist,
currency: parseObject(this.currency),
retentions: parseObject(this.retentions),
warehouse: this.warehouse,
remissions: parseObject(this.remissions),
costCenter: this.costCenter,
comments: parseObject(this.comments),
periodicity: this.periodicity,
},
});
$.export("$summary", `Created invoice with ID ${invoice.id}`);
return invoice;
} catch (e) {
throw new ConfigurationError(e.response.data.message);
}
},
};
29 changes: 29 additions & 0 deletions components/alegra/actions/find-contact/find-contact.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import alegra from "../../alegra.app.mjs";

export default {
key: "alegra-find-contact",
name: "Find Contact",
description: "Search for an existing contact in Alegra based on name or identification. [See the documentation](https://developer.alegra.com/reference/listcontacts-1)",
version: "0.0.1",
type: "action",
props: {
alegra,
query: {
propDefinition: [
alegra,
"query",
],
},
},
async run({ $ }) {
const response = await this.alegra.searchContact({
$,
params: {
query: this.query,
},
});

$.export("$summary", `Found ${response.length} contact(s) matching your query`);
return response;
},
};
Loading
Loading