feat: revert the resource columns

This commit is contained in:
Ahmed Bouhuolia
2024-04-07 23:48:23 +02:00
parent 086b060351
commit a1f8417b5d
21 changed files with 304 additions and 610 deletions

View File

@@ -349,7 +349,7 @@ export default class AccountsController extends BaseController {
// Filter query. // Filter query.
const filter = { const filter = {
sortOrder: 'desc', sortOrder: 'desc',
columnSortBy: 'createdAt', columnSortBy: 'created_at',
inactiveMode: false, inactiveMode: false,
structure: IAccountsStructureType.Tree, structure: IAccountsStructureType.Tree,
...this.matchedQueryData(req), ...this.matchedQueryData(req),

View File

@@ -289,7 +289,7 @@ export default class CustomersController extends ContactsController {
const filter = { const filter = {
inactiveMode: false, inactiveMode: false,
sortOrder: 'desc', sortOrder: 'desc',
columnSortBy: 'createdAt', columnSortBy: 'created_at',
page: 1, page: 1,
pageSize: 12, pageSize: 12,
...this.matchedQueryData(req), ...this.matchedQueryData(req),

View File

@@ -272,7 +272,7 @@ export default class VendorsController extends ContactsController {
const vendorsFilter: IVendorsFilter = { const vendorsFilter: IVendorsFilter = {
inactiveMode: false, inactiveMode: false,
sortOrder: 'desc', sortOrder: 'desc',
columnSortBy: 'createdAt', columnSortBy: 'created_at',
page: 1, page: 1,
pageSize: 12, pageSize: 12,
...this.matchedQueryData(req), ...this.matchedQueryData(req),

View File

@@ -317,7 +317,7 @@ export class ExpensesController extends BaseController {
const { tenantId } = req; const { tenantId } = req;
const filter = { const filter = {
sortOrder: 'desc', sortOrder: 'desc',
columnSortBy: 'createdAt', columnSortBy: 'created_at',
page: 1, page: 1,
pageSize: 12, pageSize: 12,
...this.matchedQueryData(req), ...this.matchedQueryData(req),

View File

@@ -344,7 +344,7 @@ export default class ItemsController extends BaseController {
const filter = { const filter = {
sortOrder: 'DESC', sortOrder: 'DESC',
columnSortBy: 'createdAt', columnSortBy: 'created_at',
page: 1, page: 1,
pageSize: 12, pageSize: 12,
inactiveMode: false, inactiveMode: false,

View File

@@ -328,7 +328,7 @@ export default class ManualJournalsController extends BaseController {
const { tenantId } = req; const { tenantId } = req;
const filter = { const filter = {
sortOrder: 'desc', sortOrder: 'desc',
columnSortBy: 'createdAt', columnSortBy: 'created_at',
page: 1, page: 1,
pageSize: 12, pageSize: 12,
...this.matchedQueryData(req), ...this.matchedQueryData(req),

View File

@@ -459,7 +459,7 @@ export default class SaleInvoicesController extends BaseController {
const { tenantId } = req; const { tenantId } = req;
const filter = { const filter = {
sortOrder: 'desc', sortOrder: 'desc',
columnSortBy: 'createdAt', columnSortBy: 'created_at',
page: 1, page: 1,
pageSize: 12, pageSize: 12,
...this.matchedQueryData(req), ...this.matchedQueryData(req),

View File

@@ -12,18 +12,11 @@ export default {
name: 'account.field.name', name: 'account.field.name',
column: 'name', column: 'name',
fieldType: 'text', fieldType: 'text',
unique: true,
required: true,
importable: true,
exportable: true,
order: 1,
}, },
description: { description: {
name: 'account.field.description', name: 'account.field.description',
column: 'description', column: 'description',
fieldType: 'text', fieldType: 'text',
importable: true,
exportable: true,
}, },
slug: { slug: {
name: 'account.field.slug', name: 'account.field.slug',
@@ -31,20 +24,13 @@ export default {
fieldType: 'text', fieldType: 'text',
columnable: false, columnable: false,
filterable: false, filterable: false,
importable: false,
}, },
code: { code: {
name: 'account.field.code', name: 'account.field.code',
column: 'code', column: 'code',
fieldType: 'text', fieldType: 'text',
exportable: true,
importable: true,
minLength: 3,
maxLength: 6,
unique: true,
importHint: 'Unique number to identify the account.',
}, },
rootType: { root_type: {
name: 'account.field.root_type', name: 'account.field.root_type',
fieldType: 'enumeration', fieldType: 'enumeration',
options: [ options: [
@@ -56,7 +42,6 @@ export default {
], ],
filterCustomQuery: RootTypeFieldFilterQuery, filterCustomQuery: RootTypeFieldFilterQuery,
sortable: false, sortable: false,
importable: false,
}, },
normal: { normal: {
name: 'account.field.normal', name: 'account.field.normal',
@@ -67,9 +52,8 @@ export default {
], ],
filterCustomQuery: NormalTypeFieldFilterQuery, filterCustomQuery: NormalTypeFieldFilterQuery,
sortable: false, sortable: false,
importable: false,
}, },
accountType: { type: {
name: 'account.field.type', name: 'account.field.type',
column: 'account_type', column: 'account_type',
fieldType: 'enumeration', fieldType: 'enumeration',
@@ -77,46 +61,28 @@ export default {
label: accountType.label, label: accountType.label,
key: accountType.key, key: accountType.key,
})), })),
required: true,
importable: true,
exportable: true,
order: 2,
}, },
active: { active: {
name: 'account.field.active', name: 'account.field.active',
column: 'active', column: 'active',
fieldType: 'boolean', fieldType: 'boolean',
filterable: false, filterable: false,
exportable: true,
importable: true,
}, },
balance: { balance: {
name: 'account.field.balance', name: 'account.field.balance',
column: 'amount', column: 'amount',
fieldType: 'number', fieldType: 'number',
importable: false,
}, },
currencyCode: { currency: {
name: 'account.field.currency', name: 'account.field.currency',
column: 'currency_code', column: 'currency_code',
fieldType: 'text', fieldType: 'text',
filterable: false, filterable: false,
importable: true,
exportable: true,
}, },
parentAccount: { created_at: {
name: 'account.field.parent_account',
column: 'parent_account_id',
fieldType: 'relation',
to: { model: 'Account', to: 'id' },
importable: false,
},
createdAt: {
name: 'account.field.created_at', name: 'account.field.created_at',
column: 'created_at', column: 'created_at',
fieldType: 'date', fieldType: 'date',
importable: false,
exportable: true,
}, },
}, },
fields2: { fields2: {

View File

@@ -12,6 +12,10 @@ export default {
sortOrder: 'DESC', sortOrder: 'DESC',
sortField: 'name', sortField: 'name',
}, },
importable: true,
importAggregator: 'group',
importAggregateOn: 'entries',
importAggregateBy: 'creditNoteNumber',
fields: { fields: {
customer: { customer: {
name: 'credit_note.field.customer', name: 'credit_note.field.customer',
@@ -77,10 +81,6 @@ export default {
fieldType: 'date', fieldType: 'date',
}, },
}, },
importable: true,
importAggregator: 'group',
importAggregateOn: 'entries',
importAggregateBy: 'creditNoteNumber',
fields2: { fields2: {
customerId: { customerId: {
name: 'Customer', name: 'Customer',

View File

@@ -3,213 +3,91 @@ export default {
defaultFilterField: 'displayName', defaultFilterField: 'displayName',
defaultSort: { defaultSort: {
sortOrder: 'DESC', sortOrder: 'DESC',
sortField: 'createdAt', sortField: 'created_at',
}, },
fields: { fields: {
customerType: { first_name: {
name: 'Customer Type', name: 'vendor.field.first_name',
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', column: 'first_name',
fieldType: 'text', fieldType: 'text',
importable: true,
}, },
lastName: { last_name: {
name: 'customer.field.last_name', name: 'vendor.field.last_name',
column: 'last_name', column: 'last_name',
fieldType: 'text', fieldType: 'text',
importable: true,
}, },
displayName: { display_name: {
name: 'customer.field.display_name', name: 'vendor.field.display_name',
column: 'display_name', column: 'display_name',
fieldType: 'text', fieldType: 'text',
required: true,
importable: true,
}, },
email: { email: {
name: 'customer.field.email', name: 'vendor.field.email',
column: 'email', column: 'email',
fieldType: 'text', fieldType: 'text',
importable: true,
}, },
workPhone: { work_phone: {
name: 'customer.field.work_phone', name: 'vendor.field.work_phone',
column: 'work_phone', column: 'work_phone',
fieldType: 'text', fieldType: 'text',
importable: true,
}, },
personalPhone: { personal_phone: {
name: 'customer.field.personal_phone', name: 'vendor.field.personal_pone',
column: 'personal_phone', column: 'personal_phone',
fieldType: 'text', fieldType: 'text',
importable: true,
}, },
companyName: { company_name: {
name: 'customer.field.company_name', name: 'vendor.field.company_name',
column: 'company_name', column: 'company_name',
fieldType: 'text', fieldType: 'text',
importable: true,
}, },
website: { website: {
name: 'customer.field.website', name: 'vendor.field.website',
column: 'website', column: 'website',
fieldType: 'url', fieldType: 'text',
importable: true, },
created_at: {
name: 'vendor.field.created_at',
column: 'created_at',
fieldType: 'date',
}, },
balance: { balance: {
name: 'customer.field.balance', name: 'vendor.field.balance',
column: 'balance', column: 'balance',
fieldType: 'number', fieldType: 'number',
}, },
openingBalance: { opening_balance: {
name: 'customer.field.opening_balance', name: 'vendor.field.opening_balance',
column: 'opening_balance', column: 'opening_balance',
fieldType: 'number', fieldType: 'number',
importable: true,
}, },
openingBalanceAt: { opening_balance_at: {
name: 'customer.field.opening_balance_at', name: 'vendor.field.opening_balance_at',
column: 'opening_balance_at', column: 'opening_balance_at',
filterable: false,
fieldType: 'date', fieldType: 'date',
importable: true,
}, },
openingBalanceExchangeRate: { currency_code: {
name: 'Opening Balance Ex. Rate', name: 'vendor.field.currency',
column: 'opening_balance_exchange_rate',
fieldType: 'number',
importable: true,
},
currencyCode: {
name: 'customer.field.currency',
column: 'currency_code', column: 'currency_code',
fieldType: 'text', fieldType: 'text',
importable: true,
},
note: {
name: 'Note',
column: 'note',
fieldType: 'text',
importable: true,
},
active: {
name: 'Active',
column: 'active',
fieldType: 'boolean',
importable: true,
}, },
status: { status: {
name: 'customer.field.status', name: 'vendor.field.status',
fieldType: 'enumeration', type: 'enumeration',
options: [ options: [
{ key: 'active', label: 'customer.field.status.active' }, { key: 'overdue', label: 'vendor.field.status.overdue' },
{ key: 'inactive', label: 'customer.field.status.inactive' }, { key: 'unpaid', label: 'vendor.field.status.unpaid' },
{ key: 'overdue', label: 'customer.field.status.overdue' },
{ key: 'unpaid', label: 'customer.field.status.unpaid' },
], ],
filterCustomQuery: statusFieldFilterQuery, filterCustomQuery: (query, role) => {
switch (role.value) {
case 'overdue':
query.modify('overdue');
break;
case 'unpaid':
query.modify('unpaid');
break;
}
}, },
// Billing Address
billingAddress1: {
name: 'Billing Address 1',
column: 'billing_address1',
fieldType: 'text',
importable: true,
},
billingAddress2: {
name: 'Billing Address 2',
column: 'billing_address2',
fieldType: 'text',
importable: true,
},
billingAddressCity: {
name: 'Billing Address City',
column: 'billing_address_city',
fieldType: 'text',
importable: true,
},
billingAddressCountry: {
name: 'Billing Address Country',
column: 'billing_address_country',
fieldType: 'text',
importable: true,
},
billingAddressPostcode: {
name: 'Billing Address Postcode',
column: 'billing_address_postcode',
fieldType: 'text',
importable: true,
},
billingAddressState: {
name: 'Billing Address State',
column: 'billing_address_state',
fieldType: 'text',
importable: true,
},
billingAddressPhone: {
name: 'Billing Address Phone',
column: 'billing_address_phone',
fieldType: 'text',
importable: true,
},
// Shipping Address
shippingAddress1: {
name: 'Shipping Address 1',
column: 'shipping_address1',
fieldType: 'text',
importable: true,
},
shippingAddress2: {
name: 'Shipping Address 2',
column: 'shipping_address2',
fieldType: 'text',
importable: true,
},
shippingAddressCity: {
name: 'Shipping Address City',
column: 'shipping_address_city',
fieldType: 'text',
importable: true,
},
shippingAddressCountry: {
name: 'Shipping Address Country',
column: 'shipping_address_country',
fieldType: 'text',
importable: true,
},
shippingAddressPostcode: {
name: 'Shipping Address Postcode',
column: 'shipping_address_postcode',
fieldType: 'text',
importable: true,
},
shippingAddressPhone: {
name: 'Shipping Address Phone',
column: 'shipping_address_phone',
fieldType: 'text',
importable: true,
},
shippingAddressState: {
name: 'Shipping Address State',
column: 'shipping_address_state',
fieldType: 'text',
importable: true,
},
//
createdAt: {
name: 'customer.field.created_at',
column: 'created_at',
fieldType: 'date',
}, },
}, },
fields2: { fields2: {

View File

@@ -55,7 +55,7 @@ export default {
filterCustomQuery: StatusFieldFilterQuery, filterCustomQuery: StatusFieldFilterQuery,
sortCustomQuery: StatusFieldSortQuery, sortCustomQuery: StatusFieldSortQuery,
}, },
createdAt: { created_at: {
name: 'expense.field.created_at', name: 'expense.field.created_at',
column: 'created_at', column: 'created_at',
fieldType: 'date', fieldType: 'date',

View File

@@ -5,96 +5,6 @@ export default {
sortField: 'name', sortField: 'name',
sortOrder: 'DESC', sortOrder: 'DESC',
}, },
fields2: {
type: {
name: 'item.field.type',
fieldType: 'enumeration',
options: [
{ key: 'inventory', label: 'item.field.type.inventory' },
{ key: 'service', label: 'item.field.type.service' },
{ key: 'non-inventory', label: 'item.field.type.non-inventory' },
],
required: true,
},
name: {
name: 'item.field.name',
fieldType: 'text',
required: true,
unique: true,
},
code: {
name: 'item.field.code',
fieldType: 'text',
unique: true,
},
sellable: {
name: 'item.field.sellable',
fieldType: 'boolean',
required: true,
},
purchasable: {
name: 'item.field.purchasable',
fieldType: 'boolean',
required: true,
},
sellPrice: {
name: 'item.field.sell_price',
fieldType: 'number',
required: true,
},
costPrice: {
name: 'item.field.cost_price',
fieldType: 'number',
required: true,
},
costAccount: {
name: 'item.field.cost_account',
fieldType: 'relation',
relationModel: 'Account',
relationImportMatch: ['name', 'code'],
required: true,
},
sellAccount: {
name: 'item.field.sell_account',
fieldType: 'relation',
relationModel: 'Account',
relationImportMatch: ['name', 'code'],
required: true,
},
inventoryAccount: {
name: 'item.field.inventory_account',
fieldType: 'relation',
relationModel: 'Account',
relationImportMatch: ['name', 'code'],
required: true,
},
sellDescription: {
name: 'Sell description',
column: 'sell_description',
fieldType: 'text',
},
purchaseDescription: {
name: 'Purchase description',
column: 'purchase_description',
fieldType: 'text',
importable: true,
},
note: {
name: 'item.field.note',
fieldType: 'text',
},
category: {
name: 'item.field.category',
fieldType: 'relation',
relationModel: 'ItemCategory',
relationImportMatch: 'name',
},
active: {
name: 'item.field.active',
fieldType: 'boolean',
importable: true,
},
},
fields: { fields: {
type: { type: {
name: 'item.field.type', name: 'item.field.type',
@@ -105,109 +15,80 @@ export default {
{ key: 'service', label: 'item.field.type.service' }, { 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,
required: true,
}, },
name: { name: {
name: 'item.field.name', name: 'item.field.name',
column: 'name', column: 'name',
fieldType: 'text', fieldType: 'text',
importable: true,
required: true,
unique: true,
}, },
code: { code: {
name: 'item.field.code', name: 'item.field.code',
column: 'code', column: 'code',
fieldType: 'text', fieldType: 'text',
importable: true,
}, },
sellable: { sellable: {
name: 'item.field.sellable', name: 'item.field.sellable',
column: 'sellable', column: 'sellable',
fieldType: 'boolean', fieldType: 'boolean',
importable: true,
required: true,
}, },
purchasable: { purchasable: {
name: 'item.field.purchasable', name: 'item.field.purchasable',
column: 'purchasable', column: 'purchasable',
fieldType: 'boolean', fieldType: 'boolean',
importable: true,
required: true,
}, },
sellPrice: { sell_price: {
name: 'item.field.sell_price', name: 'item.field.cost_price',
column: 'sell_price', column: 'sell_price',
fieldType: 'number', fieldType: 'number',
importable: true,
required: true,
}, },
costPrice: { cost_price: {
name: 'item.field.cost_price', name: 'item.field.cost_account',
column: 'cost_price', column: 'cost_price',
fieldType: 'number', fieldType: 'number',
importable: true,
required: true,
}, },
costAccount: { cost_account: {
name: 'item.field.cost_account', name: 'item.field.sell_account',
column: 'cost_account_id', column: 'cost_account_id',
fieldType: 'relation', fieldType: 'relation',
relationType: 'enumeration',
relationKey: 'costAccount', relationKey: 'costAccount',
relationEntityLabel: 'name', relationEntityLabel: 'name',
relationEntityKey: 'slug', relationEntityKey: 'slug',
importableRelationLabel: ['name', 'code'],
importable: true,
required: true,
}, },
sellAccount: { sell_account: {
name: 'item.field.sell_account', name: 'item.field.sell_description',
column: 'sell_account_id', column: 'sell_account_id',
fieldType: 'relation', fieldType: 'relation',
relationType: 'enumeration',
relationKey: 'sellAccount', relationKey: 'sellAccount',
relationType: 'one-to-many',
relationEntityLabel: 'name', relationEntityLabel: 'name',
relationEntityKey: 'slug', relationEntityKey: 'slug',
importableRelationLabel: ['name', 'code'],
importable: true,
required: true,
}, },
inventoryAccount: { inventory_account: {
name: 'item.field.inventory_account', name: 'item.field.inventory_account',
column: 'inventory_account_id', column: 'inventory_account_id',
fieldType: 'relation',
relationType: 'enumeration',
relationKey: 'inventoryAccount', relationKey: 'inventoryAccount',
relationEntityLabel: 'name', relationEntityLabel: 'name',
relationEntityKey: 'slug', relationEntityKey: 'slug',
importableRelationLabel: ['name', 'code'],
importable: true,
required: true,
}, },
sellDescription: { sell_description: {
name: 'Sell description', name: 'Sell description',
column: 'sell_description', column: 'sell_description',
fieldType: 'text', fieldType: 'text',
importable: true,
}, },
purchaseDescription: { purchase_description: {
name: 'Purchase description', name: 'Purchase description',
column: 'purchase_description', column: 'purchase_description',
fieldType: 'text', fieldType: 'text',
importable: true,
}, },
quantityOnHand: { quantity_on_hand: {
name: 'item.field.quantity_on_hand', name: 'item.field.quantity_on_hand',
column: 'quantity_on_hand', column: 'quantity_on_hand',
fieldType: 'number', fieldType: 'number',
@@ -216,28 +97,140 @@ export default {
name: 'item.field.note', name: 'item.field.note',
column: 'note', column: 'note',
fieldType: 'text', fieldType: 'text',
importable: true,
}, },
category: { category: {
name: 'item.field.category', name: 'item.field.category',
column: 'category_id', column: 'category_id',
fieldType: 'relation',
relationType: 'enumeration',
relationKey: 'category', relationKey: 'category',
relationEntityLabel: 'name', relationEntityLabel: 'name',
relationEntityKey: 'id', relationEntityKey: 'id',
importableRelationLabel: 'name',
importable: true,
}, },
active: { active: {
name: 'item.field.active', name: 'item.field.active',
column: 'active', column: 'active',
fieldType: 'boolean', fieldType: 'boolean',
importable: true, filterable: false,
}, },
createdAt: { created_at: {
name: 'item.field.created_at',
column: 'created_at',
columnType: 'date',
fieldType: 'date',
},
},
fields2: {
type: {
name: 'item.field.type',
column: 'type',
fieldType: 'enumeration',
options: [
{ key: 'inventory', label: 'item.field.type.inventory' },
{ key: 'service', label: 'item.field.type.service' },
{ key: 'non-inventory', label: 'item.field.type.non-inventory' },
],
},
name: {
name: 'item.field.name',
column: 'name',
fieldType: 'text',
},
code: {
name: 'item.field.code',
column: 'code',
fieldType: 'text',
},
sellable: {
name: 'item.field.sellable',
column: 'sellable',
fieldType: 'boolean',
},
purchasable: {
name: 'item.field.purchasable',
column: 'purchasable',
fieldType: 'boolean',
},
sell_price: {
name: 'item.field.cost_price',
column: 'sell_price',
fieldType: 'number',
},
cost_price: {
name: 'item.field.cost_account',
column: 'cost_price',
fieldType: 'number',
},
cost_account: {
name: 'item.field.sell_account',
column: 'cost_account_id',
fieldType: 'relation',
relationType: 'enumeration',
relationKey: 'costAccount',
relationEntityLabel: 'name',
relationEntityKey: 'slug',
},
sell_account: {
name: 'item.field.sell_description',
column: 'sell_account_id',
fieldType: 'relation',
relationType: 'enumeration',
relationKey: 'sellAccount',
relationEntityLabel: 'name',
relationEntityKey: 'slug',
},
inventory_account: {
name: 'item.field.inventory_account',
column: 'inventory_account_id',
relationType: 'enumeration',
relationKey: 'inventoryAccount',
relationEntityLabel: 'name',
relationEntityKey: 'slug',
},
sell_description: {
name: 'Sell description',
column: 'sell_description',
fieldType: 'text',
},
purchase_description: {
name: 'Purchase description',
column: 'purchase_description',
fieldType: 'text',
},
quantity_on_hand: {
name: 'item.field.quantity_on_hand',
column: 'quantity_on_hand',
fieldType: 'number',
},
note: {
name: 'item.field.note',
column: 'note',
fieldType: 'text',
},
category: {
name: 'item.field.category',
column: 'category_id',
relationType: 'enumeration',
relationKey: 'category',
relationEntityLabel: 'name',
relationEntityKey: 'id',
},
active: {
name: 'item.field.active',
column: 'active',
fieldType: 'boolean',
filterable: false,
},
created_at: {
name: 'item.field.created_at', name: 'item.field.created_at',
column: 'created_at', column: 'created_at',
columnType: 'date', columnType: 'date',

View File

@@ -10,13 +10,11 @@ export default {
name: 'item_category.field.name', name: 'item_category.field.name',
column: 'name', column: 'name',
fieldType: 'text', fieldType: 'text',
importable: true,
}, },
description: { description: {
name: 'item_category.field.description', name: 'item_category.field.description',
column: 'description', column: 'description',
fieldType: 'text', fieldType: 'text',
importable: true,
}, },
count: { count: {
name: 'item_category.field.count', name: 'item_category.field.count',

View File

@@ -13,23 +13,18 @@ export default {
name: 'manual_journal.field.date', name: 'manual_journal.field.date',
column: 'date', column: 'date',
fieldType: 'date', fieldType: 'date',
importable: true,
required: true,
}, },
journalNumber: { journal_number: {
name: 'manual_journal.field.journal_number', name: 'manual_journal.field.journal_number',
column: 'journal_number', column: 'journal_number',
fieldType: 'text', fieldType: 'text',
importable: true,
required: true,
}, },
reference: { reference: {
name: 'manual_journal.field.reference', name: 'manual_journal.field.reference',
column: 'reference', column: 'reference',
fieldType: 'text', fieldType: 'text',
importable: true,
}, },
journalType: { journal_type: {
name: 'manual_journal.field.journal_type', name: 'manual_journal.field.journal_type',
column: 'journal_type', column: 'journal_type',
fieldType: 'text', fieldType: 'text',
@@ -43,63 +38,6 @@ export default {
name: 'manual_journal.field.description', name: 'manual_journal.field.description',
column: 'description', column: 'description',
fieldType: 'text', fieldType: 'text',
importable: true,
},
entries: {
name: 'Entries',
fieldType: 'collection',
collectionOf: 'object',
collectionMinLength: 2,
required: true,
importable: true,
filterable: false,
fields: {
credit: {
name: 'Credit',
fieldType: 'number',
importable: true,
required: true,
},
debit: {
name: 'Debit',
fieldType: 'number',
importable: true,
required: true,
},
accountId: {
name: 'Account',
fieldType: 'relation',
relationKey: 'account',
relationModel: 'Account',
importable: true,
required: true,
importableRelationLabel: ['name', 'code'],
},
contactId: {
name: 'Contact',
fieldType: 'relation',
relationKey: 'contact',
relationModel: 'Contact',
required: false,
importable: true,
importableRelationLabel: 'displayName',
},
note: {
name: 'Note',
fieldType: 'text',
importable: true,
},
},
},
publish: {
name: 'Publish',
fieldType: 'boolean',
importable: true,
}, },
status: { status: {
name: 'manual_journal.field.status', name: 'manual_journal.field.status',
@@ -112,7 +50,7 @@ export default {
filterCustomQuery: StatusFieldFilterQuery, filterCustomQuery: StatusFieldFilterQuery,
sortCustomQuery: StatusFieldSortQuery, sortCustomQuery: StatusFieldSortQuery,
}, },
createdAt: { created_at: {
name: 'manual_journal.field.created_at', name: 'manual_journal.field.created_at',
column: 'created_at', column: 'created_at',
fieldType: 'date', fieldType: 'date',
@@ -132,7 +70,6 @@ export default {
reference: { reference: {
name: 'manual_journal.field.reference', name: 'manual_journal.field.reference',
fieldType: 'text', fieldType: 'text',
importable: true,
}, },
journalType: { journalType: {
name: 'manual_journal.field.journal_type', name: 'manual_journal.field.journal_type',

View File

@@ -2,7 +2,7 @@ export default {
defaultFilterField: 'customer', defaultFilterField: 'customer',
defaultSort: { defaultSort: {
sortOrder: 'DESC', sortOrder: 'DESC',
sortField: 'createdAt', sortField: 'created_at',
}, },
importable: true, importable: true,
importAggregator: 'group', importAggregator: 'group',
@@ -81,7 +81,7 @@ export default {
filterCustomQuery: StatusFieldFilterQuery, filterCustomQuery: StatusFieldFilterQuery,
sortCustomQuery: StatusFieldSortQuery, sortCustomQuery: StatusFieldSortQuery,
}, },
createdAt: { created_at: {
name: 'invoice.field.created_at', name: 'invoice.field.created_at',
column: 'created_at', column: 'created_at',
fieldType: 'date', fieldType: 'date',

View File

@@ -2,7 +2,7 @@ export default {
defaultFilterField: 'createdAt', defaultFilterField: 'createdAt',
defaultSort: { defaultSort: {
sortOrder: 'DESC', sortOrder: 'DESC',
sortField: 'createdAt', sortField: 'created_at',
}, },
importable: true, importable: true,
fields: { fields: {
@@ -10,33 +10,27 @@ export default {
name: 'Date', name: 'Date',
column: 'date', column: 'date',
fieldType: 'date', fieldType: 'date',
importable: true,
required: true,
}, },
payee: { payee: {
name: 'Payee', name: 'Payee',
column: 'payee', column: 'payee',
fieldType: 'text', fieldType: 'text',
importable: true,
}, },
description: { description: {
name: 'Description', name: 'Description',
column: 'description', column: 'description',
fieldType: 'text', fieldType: 'text',
importable: true,
}, },
referenceNo: { referenceNo: {
name: 'Reference No.', name: 'Reference No.',
column: 'reference_no', column: 'reference_no',
fieldType: 'text', fieldType: 'text',
importable: true,
}, },
amount: { amount: {
name: 'Amount', name: 'Amount',
column: 'Amount', column: 'Amount',
fieldType: 'numeric', fieldType: 'numeric',
required: true, required: true,
importable: true,
}, },
account: { account: {
name: 'Account', name: 'Account',
@@ -78,6 +72,5 @@ export default {
fieldType: 'numeric', fieldType: 'numeric',
required: true, required: true,
}, },
},
}
}; };

View File

@@ -2,99 +2,74 @@ export default {
defaultFilterField: 'displayName', defaultFilterField: 'displayName',
defaultSort: { defaultSort: {
sortOrder: 'DESC', sortOrder: 'DESC',
sortField: 'createdAt', sortField: 'created_at',
}, },
importable: true, importable: true,
fields: { fields: {
firstName: { first_name: {
name: 'vendor.field.first_name', name: 'vendor.field.first_name',
column: 'first_name', column: 'first_name',
fieldType: 'text', fieldType: 'text',
importable: true,
}, },
lastName: { last_name: {
name: 'vendor.field.last_name', name: 'vendor.field.last_name',
column: 'last_name', column: 'last_name',
fieldType: 'text', fieldType: 'text',
importable: true,
}, },
displayName: { display_name: {
name: 'vendor.field.display_name', name: 'vendor.field.display_name',
column: 'display_name', column: 'display_name',
fieldType: 'text', fieldType: 'text',
required: true,
importable: true,
}, },
email: { email: {
name: 'vendor.field.email', name: 'vendor.field.email',
column: 'email', column: 'email',
fieldType: 'text', fieldType: 'text',
importable: true,
}, },
workPhone: { work_phone: {
name: 'vendor.field.work_phone', name: 'vendor.field.work_phone',
column: 'work_phone', column: 'work_phone',
fieldType: 'text', fieldType: 'text',
importable: true,
}, },
personalPhone: { personal_phone: {
name: 'vendor.field.personal_phone', name: 'vendor.field.personal_pone',
column: 'personal_phone', column: 'personal_phone',
fieldType: 'text', fieldType: 'text',
importable: true,
}, },
companyName: { company_name: {
name: 'vendor.field.company_name', name: 'vendor.field.company_name',
column: 'company_name', column: 'company_name',
fieldType: 'text', fieldType: 'text',
importable: true,
}, },
website: { website: {
name: 'vendor.field.website', name: 'vendor.field.website',
column: 'website', column: 'website',
fieldType: 'text', fieldType: 'text',
importable: true, },
created_at: {
name: 'vendor.field.created_at',
column: 'created_at',
fieldType: 'date',
}, },
balance: { balance: {
name: 'vendor.field.balance', name: 'vendor.field.balance',
column: 'balance', column: 'balance',
fieldType: 'number', fieldType: 'number',
}, },
openingBalance: { opening_balance: {
name: 'vendor.field.opening_balance', name: 'vendor.field.opening_balance',
column: 'opening_balance', column: 'opening_balance',
fieldType: 'number', fieldType: 'number',
importable: true,
}, },
openingBalanceAt: { opening_balance_at: {
name: 'vendor.field.opening_balance_at', name: 'vendor.field.opening_balance_at',
column: 'opening_balance_at', column: 'opening_balance_at',
fieldType: 'date', fieldType: 'date',
importable: true,
}, },
openingBalanceExchangeRate: { currency_code: {
name: 'Opening Balance Ex. Rate',
column: 'opening_balance_exchange_rate',
fieldType: 'number',
importable: true,
},
currencyCode: {
name: 'vendor.field.currency', name: 'vendor.field.currency',
column: 'currency_code', column: 'currency_code',
fieldType: 'text', fieldType: 'text',
importable: true,
},
note: {
name: 'Note',
column: 'note',
fieldType: 'text',
importable: true,
},
active: {
name: 'Active',
column: 'active',
fieldType: 'boolean',
importable: true,
}, },
status: { status: {
name: 'vendor.field.status', name: 'vendor.field.status',
@@ -114,97 +89,6 @@ export default {
} }
}, },
}, },
// Billing Address
billingAddress1: {
name: 'Billing Address 1',
column: 'billing_address1',
fieldType: 'text',
importable: true,
},
billingAddress2: {
name: 'Billing Address 2',
column: 'billing_address2',
fieldType: 'text',
importable: true,
},
billingAddressCity: {
name: 'Billing Address City',
column: 'billing_address_city',
fieldType: 'text',
importable: true,
},
billingAddressCountry: {
name: 'Billing Address Country',
column: 'billing_address_country',
fieldType: 'text',
importable: true,
},
billingAddressPostcode: {
name: 'Billing Address Postcode',
column: 'billing_address_postcode',
fieldType: 'text',
importable: true,
},
billingAddressState: {
name: 'Billing Address State',
column: 'billing_address_state',
fieldType: 'text',
importable: true,
},
billingAddressPhone: {
name: 'Billing Address Phone',
column: 'billing_address_phone',
fieldType: 'text',
importable: true,
},
// Shipping Address
shippingAddress1: {
name: 'Shipping Address 1',
column: 'shipping_address1',
fieldType: 'text',
importable: true,
},
shippingAddress2: {
name: 'Shipping Address 2',
column: 'shipping_address2',
fieldType: 'text',
importable: true,
},
shippingAddressCity: {
name: 'Shipping Address City',
column: 'shipping_address_city',
fieldType: 'text',
importable: true,
},
shippingAddressCountry: {
name: 'Shipping Address Country',
column: 'shipping_address_country',
fieldType: 'text',
importable: true,
},
shippingAddressPostcode: {
name: 'Shipping Address Postcode',
column: 'shipping_address_postcode',
fieldType: 'text',
importable: true,
},
shippingAddressState: {
name: 'Shipping Address State',
column: 'shipping_address_state',
fieldType: 'text',
importable: true,
},
shippingAddressPhone: {
name: 'Shipping Address Phone',
column: 'shipping_address_phone',
fieldType: 'text',
importable: true,
},
createdAt: {
name: 'vendor.field.created_at',
column: 'created_at',
fieldType: 'date',
},
}, },
fields2: { fields2: {
firstName: { firstName: {

View File

@@ -33,7 +33,12 @@ export const ERRORS = {
IMPORTED_SHEET_EMPTY: 'IMPORTED_SHEET_EMPTY', IMPORTED_SHEET_EMPTY: 'IMPORTED_SHEET_EMPTY',
}; };
export function trimObject(obj) { /**
* Trimms the imported object string values before parsing.
* @param {Record<string, string | number>} obj
* @returns {<Record<string, string | number>}
*/
export function trimObject(obj: Record<string, string | number>) {
return Object.entries(obj).reduce((acc, [key, value]) => { return Object.entries(obj).reduce((acc, [key, value]) => {
// Trim the key // Trim the key
const trimmedKey = key.trim(); const trimmedKey = key.trim();
@@ -46,6 +51,11 @@ export function trimObject(obj) {
}, {}); }, {});
} }
/**
* Generates the Yup validation schema based on the given resource fields.
* @param {ResourceMetaFieldsMap} fields
* @returns {Yup}
*/
export const convertFieldsToYupValidation = (fields: ResourceMetaFieldsMap) => { export const convertFieldsToYupValidation = (fields: ResourceMetaFieldsMap) => {
const yupSchema = {}; const yupSchema = {};
@@ -123,15 +133,18 @@ export const convertFieldsToYupValidation = (fields: ResourceMetaFieldsMap) => {
const parseFieldName = (fieldName: string, field: IModelMetaField) => { const parseFieldName = (fieldName: string, field: IModelMetaField) => {
let _key = fieldName; let _key = fieldName;
// if (field.fieldType === 'relation') {
// _key = `${fieldName}Id`;
// }
if (field.dataTransferObjectKey) { if (field.dataTransferObjectKey) {
_key = field.dataTransferObjectKey; _key = field.dataTransferObjectKey;
} }
return _key; return _key;
}; };
/**
* Retrieves the unmapped sheet columns.
* @param columns
* @param mapping
* @returns
*/
export const getUnmappedSheetColumns = (columns, mapping) => { export const getUnmappedSheetColumns = (columns, mapping) => {
return columns.filter( return columns.filter(
(column) => !mapping.some((map) => map.from === column) (column) => !mapping.some((map) => map.from === column)
@@ -315,13 +328,13 @@ export const valueParser =
return _value; return _value;
}; };
export const parseKey = R.curry(
/** /**
* * Parses the field key and detarmines the key path.
* @param {{ [key: string]: IModelMetaField2 }} fields * @param {{ [key: string]: IModelMetaField2 }} fields
* @param {string} key - Mapped key path. formats: `group.key` or `key`. * @param {string} key - Mapped key path. formats: `group.key` or `key`.
* @returns {string} * @returns {string}
*/ */
export const parseKey = R.curry(
(fields: { [key: string]: IModelMetaField2 }, key: string) => { (fields: { [key: string]: IModelMetaField2 }, key: string) => {
const fieldKey = getFieldKey(key); const fieldKey = getFieldKey(key);
const field = fields[fieldKey]; const field = fields[fieldKey];
@@ -344,6 +357,11 @@ export const parseKey = R.curry(
} }
); );
/**
* Retrieves the field root key, for instance: I -> entries.itemId O -> entries.
* @param {string} input
* @returns {string}
*/
export const getFieldKey = (input: string) => { export const getFieldKey = (input: string) => {
const keys = split(input, '.'); const keys = split(input, '.');
const firstKey = head(keys).split('[')[0]; // Split by "[" in case of array notation const firstKey = head(keys).split('[')[0]; // Split by "[" in case of array notation

View File

@@ -4,6 +4,7 @@ import {
ISaleReceipt, ISaleReceipt,
ISaleReceiptCreatedPayload, ISaleReceiptCreatedPayload,
ISaleReceiptCreatingPayload, ISaleReceiptCreatingPayload,
ISaleReceiptDTO,
} from '@/interfaces'; } from '@/interfaces';
import events from '@/subscribers/events'; import events from '@/subscribers/events';
import TenancyService from '@/services/Tenancy/TenancyService'; import TenancyService from '@/services/Tenancy/TenancyService';
@@ -41,7 +42,7 @@ export class CreateSaleReceipt {
*/ */
public async createSaleReceipt( public async createSaleReceipt(
tenantId: number, tenantId: number,
saleReceiptDTO: any, saleReceiptDTO: ISaleReceiptDTO,
trx?: Knex.Transaction trx?: Knex.Transaction
): Promise<ISaleReceipt> { ): Promise<ISaleReceipt> {
const { SaleReceipt, Contact } = this.tenancy.models(tenantId); const { SaleReceipt, Contact } = this.tenancy.models(tenantId);

View File

@@ -1,6 +1,6 @@
import { Inject, Service } from 'typedi'; import { Inject, Service } from 'typedi';
import { Knex } from 'knex'; import { Knex } from 'knex';
import { IAccountCreateDTO } from '@/interfaces'; import { IAccountCreateDTO, ISaleReceiptDTO } from '@/interfaces';
import { CreateSaleReceipt } from './CreateSaleReceipt'; import { CreateSaleReceipt } from './CreateSaleReceipt';
import { Importable } from '@/services/Import/Importable'; import { Importable } from '@/services/Import/Importable';
import { SaleReceiptsSampleData } from './constants'; import { SaleReceiptsSampleData } from './constants';
@@ -18,7 +18,7 @@ export class SaleReceiptsImportable extends Importable {
*/ */
public importable( public importable(
tenantId: number, tenantId: number,
createAccountDTO: IAccountCreateDTO, createAccountDTO: ISaleReceiptDTO,
trx?: Knex.Transaction trx?: Knex.Transaction
) { ) {
return this.createReceiptService.createSaleReceipt( return this.createReceiptService.createSaleReceipt(

View File

@@ -1,7 +1,20 @@
// @ts-nocheck // @ts-nocheck
import { useMemo } from 'react'; import { useMemo } from 'react';
import { chain, isEmpty, lowerCase, head, last, set, get } from 'lodash'; import {
import { useImportFileContext } from './ImportFileProvider'; chain,
isEmpty,
lowerCase,
head,
last,
set,
get,
assign,
} from 'lodash';
import {
EntityColumn,
SheetColumn,
useImportFileContext,
} from './ImportFileProvider';
import { useImportFileMapBootContext } from './ImportFileMappingBoot'; import { useImportFileMapBootContext } from './ImportFileMappingBoot';
import { deepdash, transformToForm } from '@/utils'; import { deepdash, transformToForm } from '@/utils';
import { ImportFileMappingFormValues } from './_types'; import { ImportFileMappingFormValues } from './_types';
@@ -34,15 +47,40 @@ export const transformValueToReq = (
}; };
/** /**
* * Transformes the mapping response to form values.
* @param value * @param {{ from: string; to: string, group: string }[]} value
* @returns * @returns {Record<string, object | string>}
*/ */
export const transformResToFormValues = ( export const transformResToFormValues = (
value: { from: string; to: string }[], value: { from: string; to: string , group: string }[],
) => { ): Record<string, object | string> => {
return value?.reduce((acc, map) => { return value?.reduce((acc, map) => {
acc[map.to] = map.from; const path = map?.group ? `${map.group}.${map.to}` : map.to;
set(acc, path, map.from);
return acc;
}, {});
};
/**
* Retrieves the initial values of mapping form.
* @param {EntityColumn[]} entityColumns
* @param {SheetColumn[]} sheetColumns
*/
const getInitialDefaultValues = (
entityColumns: EntityColumn[],
sheetColumns: SheetColumn[],
) => {
return entityColumns.reduce((acc, { fields, groupKey }) => {
fields.forEach(({ key, name }) => {
const _name = lowerCase(name);
const _matched = sheetColumns.find(
(column) => lowerCase(column) === _name,
);
const _key = groupKey ? `${groupKey}.${key}` : key;
const _value = _matched ? _matched : '';
set(acc, _key, _value);
});
return acc; return acc;
}, {}); }, {});
}; };
@@ -59,30 +97,18 @@ export const useImportFileMappingInitialValues = () => {
() => transformResToFormValues(importFile?.map || []), () => transformResToFormValues(importFile?.map || []),
[importFile?.map], [importFile?.map],
); );
// Retrieves the initial default values.
const initialValues = useMemo( const initialDefaultValues = useMemo(
() => () => getInitialDefaultValues(entityColumns, sheetColumns),
entityColumns.reduce((acc, { fields, groupKey }) => {
fields.forEach(({ key, name }) => {
const _name = lowerCase(name);
const _matched = sheetColumns.find(
(column) => lowerCase(column) === _name,
);
const _key = groupKey ? `${groupKey}.${key}` : key;
const _value = _matched ? _matched : '';
set(acc, _key, _value);
});
return acc;
}, {}),
[entityColumns, sheetColumns], [entityColumns, sheetColumns],
); );
return useMemo<Record<string, any>>( return useMemo<Record<string, any>>(
() => ({ () =>
...transformToForm(initialResValues, initialValues), assign(
...initialValues, initialDefaultValues,
}), transformToForm(initialResValues, initialDefaultValues),
[initialValues, initialResValues], ),
[initialDefaultValues, initialResValues],
); );
}; };