Compare commits

...

2 Commits

Author SHA1 Message Date
Flatlogic Bot
167832a396 test V1.1 2025-07-25 06:34:03 +00:00
Flatlogic Bot
cbd5ae0344 Test v1 2025-07-25 06:19:49 +00:00
29 changed files with 787 additions and 19 deletions

5
.gitignore vendored
View File

@ -1,3 +1,8 @@
node_modules/ node_modules/
*/node_modules/ */node_modules/
*/build/ */build/
**/node_modules/
**/build/
.DS_Store
.env

File diff suppressed because one or more lines are too long

View File

@ -16,6 +16,26 @@ module.exports = class CompaniesDBApi {
{ {
id: data.id || undefined, id: data.id || undefined,
name: data.name
||
null
,
address: data.address
||
null
,
email: data.email
||
null
,
phonenumber: data.phonenumber
||
null
,
importHash: data.importHash || null, importHash: data.importHash || null,
createdById: currentUser.id, createdById: currentUser.id,
updatedById: currentUser.id, updatedById: currentUser.id,
@ -34,6 +54,26 @@ module.exports = class CompaniesDBApi {
const companiesData = data.map((item, index) => ({ const companiesData = data.map((item, index) => ({
id: item.id || undefined, id: item.id || undefined,
name: item.name
||
null
,
address: item.address
||
null
,
email: item.email
||
null
,
phonenumber: item.phonenumber
||
null
,
importHash: item.importHash || null, importHash: item.importHash || null,
createdById: currentUser.id, createdById: currentUser.id,
updatedById: currentUser.id, updatedById: currentUser.id,
@ -54,6 +94,14 @@ module.exports = class CompaniesDBApi {
const updatePayload = {}; const updatePayload = {};
if (data.name !== undefined) updatePayload.name = data.name;
if (data.address !== undefined) updatePayload.address = data.address;
if (data.email !== undefined) updatePayload.email = data.email;
if (data.phonenumber !== undefined) updatePayload.phonenumber = data.phonenumber;
updatePayload.updatedById = currentUser.id; updatePayload.updatedById = currentUser.id;
await companies.update(updatePayload, {transaction}); await companies.update(updatePayload, {transaction});
@ -149,6 +197,50 @@ module.exports = class CompaniesDBApi {
}; };
} }
if (filter.name) {
where = {
...where,
[Op.and]: Utils.ilike(
'companies',
'name',
filter.name,
),
};
}
if (filter.address) {
where = {
...where,
[Op.and]: Utils.ilike(
'companies',
'address',
filter.address,
),
};
}
if (filter.email) {
where = {
...where,
[Op.and]: Utils.ilike(
'companies',
'email',
filter.email,
),
};
}
if (filter.phonenumber) {
where = {
...where,
[Op.and]: Utils.ilike(
'companies',
'phonenumber',
filter.phonenumber,
),
};
}
if (filter.active !== undefined) { if (filter.active !== undefined) {
where = { where = {
...where, ...where,
@ -219,7 +311,7 @@ module.exports = class CompaniesDBApi {
{ ['id']: Utils.uuid(query) }, { ['id']: Utils.uuid(query) },
Utils.ilike( Utils.ilike(
'companies', 'companies',
'id', 'name',
query, query,
), ),
], ],
@ -227,16 +319,16 @@ module.exports = class CompaniesDBApi {
} }
const records = await db.companies.findAll({ const records = await db.companies.findAll({
attributes: [ 'id', 'id' ], attributes: [ 'id', 'name' ],
where, where,
limit: limit ? Number(limit) : undefined, limit: limit ? Number(limit) : undefined,
offset: offset ? Number(offset) : undefined, offset: offset ? Number(offset) : undefined,
orderBy: [['id', 'ASC']], orderBy: [['name', 'ASC']],
}); });
return records.map((record) => ({ return records.map((record) => ({
id: record.id, id: record.id,
label: record.id, label: record.name,
})); }));
} }

View File

@ -0,0 +1,54 @@
module.exports = {
/**
* @param {QueryInterface} queryInterface
* @param {Sequelize} Sequelize
* @returns {Promise<void>}
*/
async up(queryInterface, Sequelize) {
/**
* @type {Transaction}
*/
const transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.addColumn(
'companies',
'name',
{
type: Sequelize.DataTypes.TEXT,
},
{ transaction }
);
await transaction.commit();
} catch (err) {
await transaction.rollback();
throw err;
}
},
/**
* @param {QueryInterface} queryInterface
* @param {Sequelize} Sequelize
* @returns {Promise<void>}
*/
async down(queryInterface, Sequelize) {
/**
* @type {Transaction}
*/
const transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.removeColumn(
'companies',
'name',
{ transaction }
);
await transaction.commit();
} catch (err) {
await transaction.rollback();
throw err;
}
}
};

View File

@ -0,0 +1,54 @@
module.exports = {
/**
* @param {QueryInterface} queryInterface
* @param {Sequelize} Sequelize
* @returns {Promise<void>}
*/
async up(queryInterface, Sequelize) {
/**
* @type {Transaction}
*/
const transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.addColumn(
'companies',
'address',
{
type: Sequelize.DataTypes.TEXT,
},
{ transaction }
);
await transaction.commit();
} catch (err) {
await transaction.rollback();
throw err;
}
},
/**
* @param {QueryInterface} queryInterface
* @param {Sequelize} Sequelize
* @returns {Promise<void>}
*/
async down(queryInterface, Sequelize) {
/**
* @type {Transaction}
*/
const transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.removeColumn(
'companies',
'address',
{ transaction }
);
await transaction.commit();
} catch (err) {
await transaction.rollback();
throw err;
}
}
};

View File

@ -0,0 +1,54 @@
module.exports = {
/**
* @param {QueryInterface} queryInterface
* @param {Sequelize} Sequelize
* @returns {Promise<void>}
*/
async up(queryInterface, Sequelize) {
/**
* @type {Transaction}
*/
const transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.addColumn(
'companies',
'email',
{
type: Sequelize.DataTypes.TEXT,
},
{ transaction }
);
await transaction.commit();
} catch (err) {
await transaction.rollback();
throw err;
}
},
/**
* @param {QueryInterface} queryInterface
* @param {Sequelize} Sequelize
* @returns {Promise<void>}
*/
async down(queryInterface, Sequelize) {
/**
* @type {Transaction}
*/
const transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.removeColumn(
'companies',
'email',
{ transaction }
);
await transaction.commit();
} catch (err) {
await transaction.rollback();
throw err;
}
}
};

View File

@ -0,0 +1,54 @@
module.exports = {
/**
* @param {QueryInterface} queryInterface
* @param {Sequelize} Sequelize
* @returns {Promise<void>}
*/
async up(queryInterface, Sequelize) {
/**
* @type {Transaction}
*/
const transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.addColumn(
'companies',
'phonenumber',
{
type: Sequelize.DataTypes.TEXT,
},
{ transaction }
);
await transaction.commit();
} catch (err) {
await transaction.rollback();
throw err;
}
},
/**
* @param {QueryInterface} queryInterface
* @param {Sequelize} Sequelize
* @returns {Promise<void>}
*/
async down(queryInterface, Sequelize) {
/**
* @type {Transaction}
*/
const transaction = await queryInterface.sequelize.transaction();
try {
await queryInterface.removeColumn(
'companies',
'phonenumber',
{ transaction }
);
await transaction.commit();
} catch (err) {
await transaction.rollback();
throw err;
}
}
};

View File

@ -0,0 +1,38 @@
module.exports = {
/**
* @param {QueryInterface} queryInterface
* @param {Sequelize} Sequelize
* @returns {Promise<void>}
*/
async up(queryInterface, Sequelize) {
/**
* @type {Transaction}
*/
const transaction = await queryInterface.sequelize.transaction();
try {
await transaction.commit();
} catch (err) {
await transaction.rollback();
throw err;
}
},
/**
* @param {QueryInterface} queryInterface
* @param {Sequelize} Sequelize
* @returns {Promise<void>}
*/
async down(queryInterface, Sequelize) {
/**
* @type {Transaction}
*/
const transaction = await queryInterface.sequelize.transaction();
try {
await transaction.commit();
} catch (err) {
await transaction.rollback();
throw err;
}
}
};

View File

@ -0,0 +1,38 @@
module.exports = {
/**
* @param {QueryInterface} queryInterface
* @param {Sequelize} Sequelize
* @returns {Promise<void>}
*/
async up(queryInterface, Sequelize) {
/**
* @type {Transaction}
*/
const transaction = await queryInterface.sequelize.transaction();
try {
await transaction.commit();
} catch (err) {
await transaction.rollback();
throw err;
}
},
/**
* @param {QueryInterface} queryInterface
* @param {Sequelize} Sequelize
* @returns {Promise<void>}
*/
async down(queryInterface, Sequelize) {
/**
* @type {Transaction}
*/
const transaction = await queryInterface.sequelize.transaction();
try {
await transaction.commit();
} catch (err) {
await transaction.rollback();
throw err;
}
}
};

View File

@ -14,6 +14,26 @@ module.exports = function(sequelize, DataTypes) {
primaryKey: true, primaryKey: true,
}, },
name: {
type: DataTypes.TEXT,
},
address: {
type: DataTypes.TEXT,
},
email: {
type: DataTypes.TEXT,
},
phonenumber: {
type: DataTypes.TEXT,
},
importHash: { importHash: {
type: DataTypes.STRING(255), type: DataTypes.STRING(255),
allowNull: true, allowNull: true,

View File

@ -17,6 +17,19 @@ const { parse } = require('json2csv');
* type: object * type: object
* properties: * properties:
* name:
* type: string
* default: name
* address:
* type: string
* default: address
* email:
* type: string
* default: email
* phonenumber:
* type: string
* default: phonenumber
*/ */
/** /**
@ -272,7 +285,7 @@ router.get('/', wrapAsync(async (req, res) => {
req.query, { currentUser } req.query, { currentUser }
); );
if (filetype && filetype === 'csv') { if (filetype && filetype === 'csv') {
const fields = ['id', const fields = ['id','name','address','email','phonenumber',
]; ];
const opts = { fields }; const opts = { fields };

View File

@ -71,6 +71,18 @@ module.exports = class SearchService {
], ],
"companies": [
"name",
"address",
"email",
"phonenumber",
],
}; };
const columnsInt = { const columnsInt = {

View File

@ -0,0 +1 @@
{}

View File

@ -46,7 +46,7 @@ const CardCompanies = ({
}`} }`}
> >
<Link href={`/companies/companies-view/?id=${item.id}`} className='text-lg font-bold leading-6 line-clamp-1'> <Link href={`/companies/companies-view/?id=${item.id}`} className='text-lg font-bold leading-6 line-clamp-1'>
{item.id} {item.name}
</Link> </Link>
<div className='ml-auto'> <div className='ml-auto'>
@ -61,6 +61,51 @@ const CardCompanies = ({
</div> </div>
<dl className='divide-y dark:divide-dark-700 px-6 py-4 text-sm leading-6 h-64 overflow-y-auto'> <dl className='divide-y dark:divide-dark-700 px-6 py-4 text-sm leading-6 h-64 overflow-y-auto'>
<div className='flex justify-between gap-x-4 py-3'>
<dt className='text-gray-500 dark:text-dark-600'>Name</dt>
<dd className='flex items-start gap-x-2'>
<div className='font-medium line-clamp-4'>
{ item.name }
</div>
</dd>
</div>
<div className='flex justify-between gap-x-4 py-3'>
<dt className='text-gray-500 dark:text-dark-600'>Address</dt>
<dd className='flex items-start gap-x-2'>
<div className='font-medium line-clamp-4'>
{ item.address }
</div>
</dd>
</div>
<div className='flex justify-between gap-x-4 py-3'>
<dt className='text-gray-500 dark:text-dark-600'>Email</dt>
<dd className='flex items-start gap-x-2'>
<div className='font-medium line-clamp-4'>
{ item.email }
</div>
</dd>
</div>
<div className='flex justify-between gap-x-4 py-3'>
<dt className='text-gray-500 dark:text-dark-600'>Phonenumber</dt>
<dd className='flex items-start gap-x-2'>
<div className='font-medium line-clamp-4'>
{ item.phonenumber }
</div>
</dd>
</div>
<div className='flex justify-between gap-x-4 py-3'>
<dt className='text-gray-500 dark:text-dark-600'>Buildings</dt>
<dd className='flex items-start gap-x-2'>
<div className='font-medium line-clamp-4'>
{ item.buildings }
</div>
</dd>
</div>
</dl> </dl>
</li> </li>
))} ))}

View File

@ -35,6 +35,31 @@ const ListCompanies = ({ companies, loading, onDelete, currentPage, numPages, on
} }
> >
<div className={'flex-1 px-3'}>
<p className={'text-xs text-gray-500'}>Name</p>
<p className={'line-clamp-2'}>{ item.name }</p>
</div>
<div className={'flex-1 px-3'}>
<p className={'text-xs text-gray-500'}>Address</p>
<p className={'line-clamp-2'}>{ item.address }</p>
</div>
<div className={'flex-1 px-3'}>
<p className={'text-xs text-gray-500'}>Email</p>
<p className={'line-clamp-2'}>{ item.email }</p>
</div>
<div className={'flex-1 px-3'}>
<p className={'text-xs text-gray-500'}>Phonenumber</p>
<p className={'line-clamp-2'}>{ item.phonenumber }</p>
</div>
<div className={'flex-1 px-3'}>
<p className={'text-xs text-gray-500'}>Buildings</p>
<p className={'line-clamp-2'}>{ item.buildings }</p>
</div>
</Link> </Link>
<ListActionsPopover <ListActionsPopover
onDelete={onDelete} onDelete={onDelete}

View File

@ -27,6 +27,71 @@ export const loadColumns = async (
} }
return [ return [
{
field: 'name',
headerName: 'Name',
flex: 1,
minWidth: 120,
filterable: false,
headerClassName: 'datagrid--header',
cellClassName: 'datagrid--cell',
editable: true,
},
{
field: 'address',
headerName: 'Address',
flex: 1,
minWidth: 120,
filterable: false,
headerClassName: 'datagrid--header',
cellClassName: 'datagrid--cell',
editable: true,
},
{
field: 'email',
headerName: 'Email',
flex: 1,
minWidth: 120,
filterable: false,
headerClassName: 'datagrid--header',
cellClassName: 'datagrid--cell',
editable: true,
},
{
field: 'phonenumber',
headerName: 'Phonenumber',
flex: 1,
minWidth: 120,
filterable: false,
headerClassName: 'datagrid--header',
cellClassName: 'datagrid--cell',
editable: true,
},
{
field: 'buildings',
headerName: 'Buildings',
flex: 1,
minWidth: 120,
filterable: false,
headerClassName: 'datagrid--header',
cellClassName: 'datagrid--cell',
editable: true,
},
{ {
field: 'actions', field: 'actions',
type: 'actions', type: 'actions',

View File

@ -115,6 +115,15 @@ const CardUsers = ({
</dd> </dd>
</div> </div>
<div className='flex justify-between gap-x-4 py-3'>
<dt className='text-gray-500 dark:text-dark-600'>Reimbursements</dt>
<dd className='flex items-start gap-x-2'>
<div className='font-medium line-clamp-4'>
{ item.reimbursements }
</div>
</dd>
</div>
</dl> </dl>
</li> </li>
))} ))}

View File

@ -65,6 +65,11 @@ const ListUsers = ({ users, loading, onDelete, currentPage, numPages, onPageChan
<p className={'line-clamp-2'}>{ item.avatar }</p> <p className={'line-clamp-2'}>{ item.avatar }</p>
</div> </div>
<div className={'flex-1 px-3'}>
<p className={'text-xs text-gray-500'}>Reimbursements</p>
<p className={'line-clamp-2'}>{ item.reimbursements }</p>
</div>
</Link> </Link>
<ListActionsPopover <ListActionsPopover
onDelete={onDelete} onDelete={onDelete}

View File

@ -106,6 +106,19 @@ export const loadColumns = async (
}, },
{
field: 'reimbursements',
headerName: 'Reimbursements',
flex: 1,
minWidth: 120,
filterable: false,
headerClassName: 'datagrid--header',
cellClassName: 'datagrid--cell',
editable: true,
},
{ {
field: 'actions', field: 'actions',
type: 'actions', type: 'actions',

View File

@ -96,23 +96,42 @@ export default {
return {label: val.station_id, id: val.id} return {label: val.station_id, id: val.id}
}, },
reimbursementsManyListFormatter(val) {
if (!val || !val.length) return []
return val.map((item) => item.request_date)
},
reimbursementsOneListFormatter(val) {
if (!val) return ''
return val.request_date
},
reimbursementsManyListFormatterEdit(val) {
if (!val || !val.length) return []
return val.map((item) => {
return {id: item.id, label: item.request_date}
});
},
reimbursementsOneListFormatterEdit(val) {
if (!val) return ''
return {label: val.request_date, id: val.id}
},
companiesManyListFormatter(val) { companiesManyListFormatter(val) {
if (!val || !val.length) return [] if (!val || !val.length) return []
return val.map((item) => item.id) return val.map((item) => item.name)
}, },
companiesOneListFormatter(val) { companiesOneListFormatter(val) {
if (!val) return '' if (!val) return ''
return val.id return val.name
}, },
companiesManyListFormatterEdit(val) { companiesManyListFormatterEdit(val) {
if (!val || !val.length) return [] if (!val || !val.length) return []
return val.map((item) => { return val.map((item) => {
return {id: item.id, label: item.id} return {id: item.id, label: item.name}
}); });
}, },
companiesOneListFormatterEdit(val) { companiesOneListFormatterEdit(val) {
if (!val) return '' if (!val) return ''
return {label: val.id, id: val.id} return {label: val.name, id: val.id}
}, },
} }

View File

@ -114,7 +114,7 @@ const EditBuildings = () => {
options={initialValues.company} options={initialValues.company}
itemRef={'companies'} itemRef={'companies'}
showField={'id'} showField={'name'}
></Field> ></Field>
</FormField> </FormField>

View File

@ -112,7 +112,7 @@ const EditBuildingsPage = () => {
options={initialValues.company} options={initialValues.company}
itemRef={'companies'} itemRef={'companies'}
showField={'id'} showField={'name'}
></Field> ></Field>
</FormField> </FormField>

View File

@ -62,7 +62,7 @@ const BuildingsView = () => {
<div className={'mb-4'}> <div className={'mb-4'}>
<p className={'block font-bold mb-2'}>Company</p> <p className={'block font-bold mb-2'}>Company</p>
<p>{buildings?.company?.id ?? 'No data'}</p> <p>{buildings?.company?.name ?? 'No data'}</p>
</div> </div>

View File

@ -32,6 +32,14 @@ const EditCompanies = () => {
const dispatch = useAppDispatch() const dispatch = useAppDispatch()
const initVals = { const initVals = {
'name': '',
'address': '',
'email': '',
'phonenumber': '',
} }
const [initialValues, setInitialValues] = useState(initVals) const [initialValues, setInitialValues] = useState(initVals)
@ -82,6 +90,42 @@ const EditCompanies = () => {
> >
<Form> <Form>
<FormField
label="Name"
>
<Field
name="name"
placeholder="Name"
/>
</FormField>
<FormField
label="Address"
>
<Field
name="address"
placeholder="Address"
/>
</FormField>
<FormField
label="Email"
>
<Field
name="email"
placeholder="Email"
/>
</FormField>
<FormField
label="Phonenumber"
>
<Field
name="phonenumber"
placeholder="Phonenumber"
/>
</FormField>
<BaseDivider /> <BaseDivider />
<BaseButtons> <BaseButtons>
<BaseButton type="submit" color="info" label="Submit" /> <BaseButton type="submit" color="info" label="Submit" />

View File

@ -33,6 +33,14 @@ const EditCompaniesPage = () => {
const dispatch = useAppDispatch() const dispatch = useAppDispatch()
const initVals = { const initVals = {
'name': '',
'address': '',
'email': '',
'phonenumber': '',
} }
const [initialValues, setInitialValues] = useState(initVals) const [initialValues, setInitialValues] = useState(initVals)
@ -80,6 +88,42 @@ const EditCompaniesPage = () => {
> >
<Form> <Form>
<FormField
label="Name"
>
<Field
name="name"
placeholder="Name"
/>
</FormField>
<FormField
label="Address"
>
<Field
name="address"
placeholder="Address"
/>
</FormField>
<FormField
label="Email"
>
<Field
name="email"
placeholder="Email"
/>
</FormField>
<FormField
label="Phonenumber"
>
<Field
name="phonenumber"
placeholder="Phonenumber"
/>
</FormField>
<BaseDivider /> <BaseDivider />
<BaseButtons> <BaseButtons>
<BaseButton type="submit" color="info" label="Submit" /> <BaseButton type="submit" color="info" label="Submit" />

View File

@ -22,7 +22,7 @@ const CompaniesTablesPage = () => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const [filters] = useState([ const [filters] = useState([{label: 'Name', title: 'name'},{label: 'Address', title: 'address'},{label: 'Email', title: 'email'},{label: 'Phonenumber', title: 'phonenumber'},
]); ]);
const addFilter = () => { const addFilter = () => {

View File

@ -25,6 +25,14 @@ import { useRouter } from 'next/router'
const initialValues = { const initialValues = {
name: '',
address: '',
email: '',
phonenumber: '',
} }
const CompaniesNew = () => { const CompaniesNew = () => {
@ -53,6 +61,42 @@ const CompaniesNew = () => {
> >
<Form> <Form>
<FormField
label="Name"
>
<Field
name="name"
placeholder="Name"
/>
</FormField>
<FormField
label="Address"
>
<Field
name="address"
placeholder="Address"
/>
</FormField>
<FormField
label="Email"
>
<Field
name="email"
placeholder="Email"
/>
</FormField>
<FormField
label="Phonenumber"
>
<Field
name="phonenumber"
placeholder="Phonenumber"
/>
</FormField>
<BaseDivider /> <BaseDivider />
<BaseButtons> <BaseButtons>
<BaseButton type="submit" color="info" label="Submit" /> <BaseButton type="submit" color="info" label="Submit" />

View File

@ -22,7 +22,7 @@ const CompaniesTablesPage = () => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
const [filters] = useState([ const [filters] = useState([{label: 'Name', title: 'name'},{label: 'Address', title: 'address'},{label: 'Email', title: 'email'},{label: 'Phonenumber', title: 'phonenumber'},
]); ]);
const addFilter = () => { const addFilter = () => {

View File

@ -49,6 +49,26 @@ const CompaniesView = () => {
</SectionTitleLineWithButton> </SectionTitleLineWithButton>
<CardBox> <CardBox>
<div className={'mb-4'}>
<p className={'block font-bold mb-2'}>Name</p>
<p>{companies?.name}</p>
</div>
<div className={'mb-4'}>
<p className={'block font-bold mb-2'}>Address</p>
<p>{companies?.address}</p>
</div>
<div className={'mb-4'}>
<p className={'block font-bold mb-2'}>Email</p>
<p>{companies?.email}</p>
</div>
<div className={'mb-4'}>
<p className={'block font-bold mb-2'}>Phonenumber</p>
<p>{companies?.phonenumber}</p>
</div>
<> <>
<p className={'block font-bold mb-2'}>Buildings Company</p> <p className={'block font-bold mb-2'}>Buildings Company</p>
<CardBox <CardBox