Skip to content

Commit

Permalink
feat: import customers/vendors
Browse files Browse the repository at this point in the history
  • Loading branch information
abouolia committed Mar 27, 2024
1 parent fc1d123 commit 7a3e121
Show file tree
Hide file tree
Showing 12 changed files with 437 additions and 48 deletions.
12 changes: 6 additions & 6 deletions packages/server/resources/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -376,16 +376,16 @@
"customer.field.last_name": "Last name",
"customer.field.display_name": "Display name",
"customer.field.email": "Email",
"customer.field.work_phone": "Work phone",
"customer.field.personal_phone": "Personal phone",
"customer.field.work_phone": "Work Phone Number",
"customer.field.personal_phone": "Personal Phone Number",
"customer.field.company_name": "Company name",
"customer.field.website": "Website",
"customer.field.opening_balance_at": "Opening balance at",
"customer.field.opening_balance": "Opening balance",
"customer.field.created_at": "Created at",
"customer.field.balance": "Balance",
"customer.field.status": "Status",
"customer.field.currency": "Curreny",
"customer.field.currency": "Currency",
"customer.field.status.active": "Active",
"customer.field.status.inactive": "Inactive",
"customer.field.status.overdue": "Overdue",
Expand All @@ -394,16 +394,16 @@
"vendor.field.last_name": "Last name",
"vendor.field.display_name": "Display name",
"vendor.field.email": "Email",
"vendor.field.work_phone": "Work phone",
"vendor.field.personal_phone": "Personal phone",
"vendor.field.work_phone": "Work Phone Number",
"vendor.field.personal_phone": "Personal Phone Number",
"vendor.field.company_name": "Company name",
"vendor.field.website": "Website",
"vendor.field.opening_balance_at": "Opening balance at",
"vendor.field.opening_balance": "Opening balance",
"vendor.field.created_at": "Created at",
"vendor.field.balance": "Balance",
"vendor.field.status": "Status",
"vendor.field.currency": "Curreny",
"vendor.field.currency": "Currency",
"vendor.field.status.active": "Active",
"vendor.field.status.inactive": "Inactive",
"vendor.field.status.overdue": "Overdue",
Expand Down
3 changes: 2 additions & 1 deletion packages/server/src/api/controllers/Import/_utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { ServiceError } from '@/exceptions';
export function allowSheetExtensions(req, file, cb) {
if (
file.mimetype !== 'text/csv' &&
file.mimetype !== 'application/vnd.ms-excel'
file.mimetype !== 'application/vnd.ms-excel' &&
file.mimetype !== 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
) {
cb(new ServiceError('IMPORTED_FILE_EXTENSION_INVALID'));

Expand Down
37 changes: 26 additions & 11 deletions packages/server/src/interfaces/Model.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

export interface IModel {
name: string;
tableName: string;
Expand Down Expand Up @@ -40,18 +39,35 @@ export interface IModelMetaFieldCommon {
order?: number;
}

export interface IModelMetaFieldNumber {
fieldType: 'number';
export interface IModelMetaFieldText {
fieldType: 'text';
minLength?: number;
maxLength?: number;
}

export interface IModelMetaFieldOther {
fieldType: 'text' | 'boolean';
export interface IModelMetaFieldBoolean {
fieldType: 'boolean';
}
export interface IModelMetaFieldNumber {
fieldType: 'number';
min?: number;
max?: number;
}
export interface IModelMetaFieldDate {
fieldType: 'date';
}
export interface IModelMetaFieldUrl {
fieldType: 'url';
}

export type IModelMetaField = IModelMetaFieldCommon &
(IModelMetaFieldOther | IModelMetaEnumerationField | IModelMetaRelationField);
(
| IModelMetaFieldText
| IModelMetaFieldNumber
| IModelMetaFieldBoolean
| IModelMetaFieldDate
| IModelMetaFieldUrl
| IModelMetaEnumerationField
| IModelMetaRelationField
);

export interface IModelMetaEnumerationOption {
key: string;
Expand All @@ -74,9 +90,8 @@ export interface IModelMetaRelationEnumerationField {
relationEntityKey: string;
}

export type IModelMetaRelationField = IModelMetaRelationFieldCommon & (
IModelMetaRelationEnumerationField
);
export type IModelMetaRelationField = IModelMetaRelationFieldCommon &
IModelMetaRelationEnumerationField;

export interface IModelMeta {
defaultFilterField: string;
Expand Down
26 changes: 24 additions & 2 deletions packages/server/src/models/Customer.Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ export default {
sortField: 'createdAt',
},
fields: {
customerType: {
name: 'Customer Type',
column: 'contact_type',
fieldType: 'enumeration',
options: [
{ key: 'business', label: 'Business' },
{ key: 'individual', label: 'Individual' },
],
importable: true,
required: true,
},
firstName: {
name: 'customer.field.first_name',
column: 'first_name',
Expand Down Expand Up @@ -52,7 +63,7 @@ export default {
website: {
name: 'customer.field.website',
column: 'website',
fieldType: 'text',
fieldType: 'url',
importable: true,
},
balance: {
Expand Down Expand Up @@ -85,6 +96,18 @@ export default {
fieldType: 'text',
importable: true,
},
note: {
name: 'Note',
column: 'note',
fieldType: 'text',
importable: true,
},
active: {
name: 'Active',
column: 'active',
fieldType: 'boolean',
importable: true,
},
status: {
name: 'customer.field.status',
fieldType: 'enumeration',
Expand All @@ -95,7 +118,6 @@ export default {
{ key: 'unpaid', label: 'customer.field.status.unpaid' },
],
filterCustomQuery: statusFieldFilterQuery,
importable: true,
},
// Billing Address
billingAddress1: {
Expand Down
59 changes: 39 additions & 20 deletions packages/server/src/models/Item.Settings.ts
Original file line number Diff line number Diff line change
@@ -1,51 +1,59 @@
export default {
importable: true,
defaultFilterField: 'name',
defaultSort: {
sortField: 'name',
sortOrder: 'DESC',
},
fields: {
'type': {
type: {
name: 'item.field.type',
column: 'type',
fieldType: 'enumeration',
options: [
{ key: 'inventory', label: 'item.field.type.inventory', },
{ key: 'inventory', label: 'item.field.type.inventory' },
{ key: 'service', label: 'item.field.type.service' },
{ key: 'non-inventory', label: 'item.field.type.non-inventory', },
{ key: 'non-inventory', label: 'item.field.type.non-inventory' },
],
importable: true,
},
'name': {
name: {
name: 'item.field.name',
column: 'name',
fieldType: 'text',
importable: true,
},
'code': {
code: {
name: 'item.field.code',
column: 'code',
fieldType: 'text',
importable: true,
},
'sellable': {
sellable: {
name: 'item.field.sellable',
column: 'sellable',
fieldType: 'boolean',
importable: true,
},
'purchasable': {
purchasable: {
name: 'item.field.purchasable',
column: 'purchasable',
fieldType: 'boolean',
importable: true,
},
'sell_price': {
sellPrice: {
name: 'item.field.cost_price',
column: 'sell_price',
fieldType: 'number',
importable: true,
},
'cost_price': {
costPrice: {
name: 'item.field.cost_account',
column: 'cost_price',
fieldType: 'number',
importable: true,
},
'cost_account': {
costAccount: {
name: 'item.field.sell_account',
column: 'cost_account_id',
fieldType: 'relation',
Expand All @@ -55,8 +63,10 @@ export default {

relationEntityLabel: 'name',
relationEntityKey: 'slug',

importable: true,
},
'sell_account': {
sellAccount: {
name: 'item.field.sell_description',
column: 'sell_account_id',
fieldType: 'relation',
Expand All @@ -66,8 +76,10 @@ export default {

relationEntityLabel: 'name',
relationEntityKey: 'slug',

importable: true,
},
'inventory_account': {
inventoryAccount: {
name: 'item.field.inventory_account',
column: 'inventory_account_id',

Expand All @@ -76,28 +88,34 @@ export default {

relationEntityLabel: 'name',
relationEntityKey: 'slug',

importable: true,
},
'sell_description': {
sellDescription: {
name: 'Sell description',
column: 'sell_description',
fieldType: 'text',
importable: true,
},
'purchase_description': {
purchaseDescription: {
name: 'Purchase description',
column: 'purchase_description',
fieldType: 'text',
importable: true,
},
'quantity_on_hand': {
quantityOnHand: {
name: 'item.field.quantity_on_hand',
column: 'quantity_on_hand',
fieldType: 'number',
importable: true,
},
'note': {
note: {
name: 'item.field.note',
column: 'note',
fieldType: 'text',
importable: true,
},
'category': {
category: {
name: 'item.field.category',
column: 'category_id',

Expand All @@ -106,14 +124,15 @@ export default {

relationEntityLabel: 'name',
relationEntityKey: 'id',
importable: true,
},
'active': {
active: {
name: 'item.field.active',
column: 'active',
fieldType: 'boolean',
filterable: false,
importable: true,
},
'created_at': {
createdAt: {
name: 'item.field.created_at',
column: 'created_at',
columnType: 'date',
Expand Down
15 changes: 13 additions & 2 deletions packages/server/src/models/Vendor.Settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default {
importable: true,
},
personalPhone: {
name: 'vendor.field.personal_pone',
name: 'vendor.field.personal_phone',
column: 'personal_phone',
fieldType: 'text',
importable: true,
Expand Down Expand Up @@ -84,6 +84,18 @@ export default {
fieldType: 'text',
importable: true,
},
note: {
name: 'Note',
column: 'note',
fieldType: 'text',
importable: true,
},
active: {
name: 'Active',
column: 'active',
fieldType: 'boolean',
importable: true,
},
status: {
name: 'vendor.field.status',
type: 'enumeration',
Expand All @@ -101,7 +113,6 @@ export default {
break;
}
},
importable: true,
},
// Billing Address
billingAddress1: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Importable } from '@/services/Import/Importable';
import { CreateCustomer } from './CRUD/CreateCustomer';
import { Knex } from 'knex';
import { ICustomer, ICustomerNewDTO } from '@/interfaces';
import { CustomersSampleData } from './_SampleData';

@Service()
export class CustomersImportable extends Importable {
Expand All @@ -23,4 +24,11 @@ export class CustomersImportable extends Importable {
): Promise<void> {
await this.createCustomerService.createCustomer(tenantId, createDTO, trx);
}

/**
* Retrieves the sample data of customers used to download sample sheet.
*/
public sampleData(): any[] {
return CustomersSampleData;
}
}
Loading

0 comments on commit 7a3e121

Please sign in to comment.