-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* upbooks init * [Components] upbooks #12071 Sources - New Data Actions - Add Outward Payment - Create Expense Category - Add Employee * pnpm update * Fix prop description * some adjusts --------- Co-authored-by: Lucas Caresia <[email protected]> Co-authored-by: Leo Vu <[email protected]>
- Loading branch information
1 parent
ef83ecf
commit bb95b53
Showing
10 changed files
with
565 additions
and
7 deletions.
There are no files selected for viewing
120 changes: 120 additions & 0 deletions
120
components/upbooks/actions/add-employee/add-employee.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: YYYY-MM-DD", | ||
optional: true, | ||
}, | ||
dateOfJoining: { | ||
type: "string", | ||
label: "Date Of Joining", | ||
description: "The employee's start date. Format: YYYY-MM-DDTHH:MM:SSZ", | ||
optional: true, | ||
}, | ||
dateOfLeaving: { | ||
type: "string", | ||
label: "Date Of Leaving", | ||
description: "The employee's end date. Format: YYYY-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; | ||
}, | ||
}; |
55 changes: 55 additions & 0 deletions
55
components/upbooks/actions/create-expense-category/create-expense-category.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}, | ||
}; |
88 changes: 88 additions & 0 deletions
88
components/upbooks/actions/record-outward-payment/record-outward-payment.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
import { CURRENCY_OPTIONS } from "../../common/constants.mjs"; | ||
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.", | ||
options: CURRENCY_OPTIONS, | ||
}, | ||
}, | ||
async run({ $ }) { | ||
const currency = CURRENCY_OPTIONS.filter((item) => item.value === this.currency)[0]; | ||
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: currency.label, | ||
symbol: currency.value, | ||
}, | ||
}, | ||
}); | ||
$.export("$summary", `Successfully recorded outward payment with Id: ${response.data._id}`); | ||
return response; | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
export const CURRENCY_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", | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [ | ||
|
@@ -11,5 +11,9 @@ | |
"author": "Pipedream <[email protected]> (https://pipedream.com/)", | ||
"publishConfig": { | ||
"access": "public" | ||
}, | ||
"dependencies": { | ||
"@pipedream/platform": "^1.6.5" | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
}; |
Oops, something went wrong.