Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Components - upbooks #12078

Merged
merged 7 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
120 changes: 120 additions & 0 deletions components/upbooks/actions/add-employee/add-employee.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
import upbooks from "../../upbooks.app.mjs";

export default {
key: "upbooks-add-employee",
name: "Add New Employee",
description: "Adds a new employee to Upbooks. [See the documentation](https://www.postman.com/scrrum/workspace/upbooks-io/request/13284127-a51a907a-0648-477d-96f6-f5a9e79262fd)",
version: "0.0.1",
type: "action",
props: {
upbooks,
name: {
type: "string",
label: "Name",
description: "Full name of the employee.",
},
employeeNumber: {
type: "string",
label: "Employee Number",
description: "The identification number of the employee.",
optional: true,
},
type: {
type: "string",
label: "Type",
description: "The employee's type.",
options: [
"full-time",
"part-time",
],
optional: true,
},
email: {
type: "string",
label: "Email",
description: "The employee's email.",
optional: true,
},
phone: {
type: "string",
label: "Phone",
description: "The employee's phone.",
optional: true,
},
dob: {
type: "string",
label: "DOB",
description: "The employee's date of birth. Format: YYY-MM-DD",
optional: true,
},
dateOfJoining: {
type: "string",
label: "Date Of Joining",
description: "The employee's start date. Format: YYY-MM-DDTHH:MM:SSZ",
optional: true,
},
dateOfLeaving: {
type: "string",
label: "Date Of Leaving",
description: "The employee's end date. Format: YYY-MM-DDTHH:MM:SSZ",
optional: true,
},
ctc: {
type: "integer",
label: "CTC",
description: "Cost to company in cents.",
},
salaryComponentId: {
propDefinition: [
upbooks,
"salaryComponentId",
],
},
designation: {
type: "string",
label: "Designation",
description: "In which position the employee will work.",
optional: true,
},
role: {
type: "string",
label: "Role",
description: "The identification of the employee's role.",
options: [
"staff",
"admin",
"others",
],
optional: true,
},
},
async run({ $ }) {
const response = await this.upbooks.addNewEmployee({
$,
data: {
name: this.name,
employeeNumber: this.employeeNumber,
type: this.type,
email: this.email,
phone: this.phone,
dob: this.dob,
employment: [
{
dateOfJoining: this.dateOfJoining,
dateOfLeaving: this.dateOfLeaving,
salary: {
ctc: (this.ctc / 100).toFixed(2),
componentGroup: {
id: this.salaryComponentId,
},
},
designation: this.designation,
role: this.role,
},
],
},
});
$.export("$summary", `Successfully added a new employee with Id: ${response.data._id}`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import upbooks from "../../upbooks.app.mjs";

export default {
key: "upbooks-create-expense-category",
name: "Create Expense Category",
description: "Creates a new expense category in UpBooks. [See the documentation](https://www.postman.com/scrrum/workspace/upbooks-io/request/13284127-a07ae2fc-f712-42aa-bcf5-6ce63c7a0929)",
version: "0.0.1",
type: "action",
props: {
upbooks,
title: {
type: "string",
label: "Title",
description: "The expense category's title.",
},
subCategory: {
type: "string",
label: "Sub Category",
description: "subCategory",
options: [
{
label: "Operating Expense",
value: "operating-expense",
},
{
label: "Non Operating Expense",
value: "non-operating-expense",
},
{
label: "Cost Of Goods Sold",
value: "cost-of-goods-sold",
},
],
},
summary: {
type: "string",
label: "Summary",
description: "summary",
optional: true,
},
},
async run({ $ }) {
const {
upbooks,
...data
} = this;

const response = await upbooks.createExpenseCategory({
$,
data,
});
$.export("$summary", `Successfully created new expense category with Id: ${response.data._id}`);
return response;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
import { parseObject } from "../../common/utils.mjs";
import upbooks from "../../upbooks.app.mjs";

export default {
key: "upbooks-record-outward-payment",
name: "Record Outward Payment",
description: "Records an outward payment in UpBooks. [See the documentation](https://www.postman.com/scrrum/workspace/upbooks-io/request/13284127-3fc82d7a-2173-4b3a-a8ec-4c812c928810)",
version: "0.0.1",
type: "action",
props: {
upbooks,
mode: {
type: "string",
label: "Mode",
description: "The outward payment mode.",
options: [
{
label: "Cash",
value: "cash",
},
{
label: "Cheque",
value: "cheque",
},
{
label: "Neft",
value: "neft",
},
{
label: "Imps",
value: "imps",
},
{
label: "Wire Transfer",
value: "wire transfer",
},
],
},
amount: {
type: "string",
label: "Amount",
description: "The outwart payment amount in cents.",
},
date: {
type: "string",
label: "Date",
description: "The date of the outward payment. Format: YYYY-MM-DD",
},
expenseIds: {
propDefinition: [
upbooks,
"expenseIds",
],
},
account: {
propDefinition: [
upbooks,
"accountId",
],
},
currency: {
type: "string",
label: "Currency",
description: "The currency of the outward payment.",
withLabel: true,
options: [
{
label: "Indian Rupees",
value: "INR",
},
{
label: "US Dollar",
value: "USD",
},
{
label: "Euro",
value: "EUR",
},
{
label: "Australian Dollar",
value: "AUD",
},
{
label: "Emirati Dirham",
value: "AED",
},
],
},
},
async run({ $ }) {
const response = await this.upbooks.recordOutwardPayment({
$,
data: {
mode: this.mode,
amount: (this.amount / 100).toFixed(2),
date: this.date,
expenseIds: parseObject(this.expenseIds),
accountId: this.account,
currency: {
name: this.currency.label,
symbol: this.currency.value,
},
},
});
$.export("$summary", `Successfully recorded outward payment with Id: ${response.data._id}`);
return response;
},
};
24 changes: 24 additions & 0 deletions components/upbooks/common/utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
export const parseObject = (obj) => {
if (!obj) return undefined;

if (Array.isArray(obj)) {
return obj.map((item) => {
if (typeof item === "string") {
try {
return JSON.parse(item);
} catch (e) {
return item;
}
}
return item;
});
}
if (typeof obj === "string") {
try {
return JSON.parse(obj);
} catch (e) {
return obj;
}
}
return obj;
};
8 changes: 6 additions & 2 deletions components/upbooks/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pipedream/upbooks",
"version": "0.0.1",
"version": "0.1.0",
"description": "Pipedream UpBooks Components",
"main": "upbooks.app.mjs",
"keywords": [
Expand All @@ -11,5 +11,9 @@
"author": "Pipedream <[email protected]> (https://pipedream.com/)",
"publishConfig": {
"access": "public"
},
"dependencies": {
"@pipedream/platform": "^1.6.5"
}
}
}

61 changes: 61 additions & 0 deletions components/upbooks/sources/new-data/new-data.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { DEFAULT_POLLING_SOURCE_TIMER_INTERVAL } from "@pipedream/platform";
import upbooks from "../../upbooks.app.mjs";
import sampleEmit from "./test-event.mjs";

export default {
key: "upbooks-new-data",
name: "New Data Available",
description: "Emit new event when fresh data is available for a specific collection.",
version: "0.0.1",
type: "source",
dedupe: "unique",
props: {
upbooks,
db: "$.service.db",
timer: {
type: "$.interface.timer",
default: {
intervalSeconds: DEFAULT_POLLING_SOURCE_TIMER_INTERVAL,
},
},
},
methods: {
_getLastDate() {
return this.db.get("lastDate") || "1970-01-01T00:00:00Z";
},
_setLastDate(created) {
this.db.set("lastDate", created);
},
generateMeta(item) {
return {
id: item._id,
summary: `New ${item.title}`,
ts: item.occurredAt,
};
},
async startEvent(maxResults = 0) {
const lastDate = this._getLastDate();
const { data } = await this.upbooks.listActivities({
params: {
fromDate: lastDate,
},
});

if (maxResults && maxResults.length > maxResults) maxResults.length = maxResults;
if (data.length) this._setLastDate(data[0].occurredAt);

for (const item of data.reverse()) {
this.$emit(item, this.generateMeta(item));
}
},
},
hooks: {
async deploy() {
await this.startEvent(25);
},
},
async run() {
await this.startEvent();
},
sampleEmit,
};
Loading
Loading