427 lines
8.4 KiB
JavaScript
427 lines
8.4 KiB
JavaScript
const db = require('../models');
|
|
const Users = db.users;
|
|
|
|
const FieldVisits = db.field_visits;
|
|
|
|
const Payments = db.payments;
|
|
|
|
const Projects = db.projects;
|
|
|
|
const FieldVisitsData = [
|
|
{
|
|
employee_name: 'Alice Johnson',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
site_name: 'Health Center A',
|
|
|
|
start_date: new Date('2023-06-10T00:00:00Z'),
|
|
|
|
departure_date: new Date('2023-06-09T00:00:00Z'),
|
|
|
|
return_date: new Date('2023-06-12T00:00:00Z'),
|
|
|
|
payment_type: 'PerDiem',
|
|
|
|
amount: 200,
|
|
|
|
purpose: 'Site Inspection',
|
|
},
|
|
|
|
{
|
|
employee_name: 'Bob Williams',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
site_name: 'Lab B',
|
|
|
|
start_date: new Date('2023-06-20T00:00:00Z'),
|
|
|
|
departure_date: new Date('2023-06-19T00:00:00Z'),
|
|
|
|
return_date: new Date('2023-06-22T00:00:00Z'),
|
|
|
|
payment_type: 'Transport',
|
|
|
|
amount: 150,
|
|
|
|
purpose: 'Equipment Setup',
|
|
},
|
|
|
|
{
|
|
employee_name: 'Catherine Lee',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
site_name: 'Community Center C',
|
|
|
|
start_date: new Date('2023-07-05T00:00:00Z'),
|
|
|
|
departure_date: new Date('2023-07-04T00:00:00Z'),
|
|
|
|
return_date: new Date('2023-07-07T00:00:00Z'),
|
|
|
|
payment_type: 'PerDiem',
|
|
|
|
amount: 100,
|
|
|
|
purpose: 'Nutritional Workshop',
|
|
},
|
|
|
|
{
|
|
employee_name: 'David Brown',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
site_name: 'Development Site D',
|
|
|
|
start_date: new Date('2023-07-15T00:00:00Z'),
|
|
|
|
departure_date: new Date('2023-07-14T00:00:00Z'),
|
|
|
|
return_date: new Date('2023-07-18T00:00:00Z'),
|
|
|
|
payment_type: 'Fuel',
|
|
|
|
amount: 250,
|
|
|
|
purpose: 'Community Meeting',
|
|
},
|
|
|
|
{
|
|
employee_name: 'Emma Davis',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
site_name: 'School E',
|
|
|
|
start_date: new Date('2023-08-01T00:00:00Z'),
|
|
|
|
departure_date: new Date('2023-07-31T00:00:00Z'),
|
|
|
|
return_date: new Date('2023-08-03T00:00:00Z'),
|
|
|
|
payment_type: 'Transport',
|
|
|
|
amount: 180,
|
|
|
|
purpose: 'Educational Seminar',
|
|
},
|
|
];
|
|
|
|
const PaymentsData = [
|
|
{
|
|
payee: 'John Doe',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
payment_date: new Date('2023-06-01T00:00:00Z'),
|
|
|
|
purpose: 'Consulting Services',
|
|
|
|
amount: 5000,
|
|
|
|
document_type: 'RV',
|
|
|
|
auto_generated_document_no: 'MOH001-BPV-001',
|
|
|
|
status: 'Filled',
|
|
|
|
shelf_no: 'A1',
|
|
},
|
|
|
|
{
|
|
payee: 'Jane Smith',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
payment_date: new Date('2023-06-15T00:00:00Z'),
|
|
|
|
purpose: 'Research Equipment',
|
|
|
|
amount: 12000,
|
|
|
|
document_type: 'RV',
|
|
|
|
auto_generated_document_no: 'CDC002-JV-002',
|
|
|
|
status: 'InProgress',
|
|
|
|
shelf_no: 'B2',
|
|
},
|
|
|
|
{
|
|
payee: 'Global Supplies Inc.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
payment_date: new Date('2023-07-01T00:00:00Z'),
|
|
|
|
purpose: 'Nutritional Supplies',
|
|
|
|
amount: 8000,
|
|
|
|
document_type: 'JV',
|
|
|
|
auto_generated_document_no: 'NNP003-RV-003',
|
|
|
|
status: 'InProgress',
|
|
|
|
shelf_no: 'C3',
|
|
},
|
|
|
|
{
|
|
payee: 'Tech Solutions',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
payment_date: new Date('2023-07-20T00:00:00Z'),
|
|
|
|
purpose: 'IT Services',
|
|
|
|
amount: 15000,
|
|
|
|
document_type: 'RV',
|
|
|
|
auto_generated_document_no: 'ACDC004-BPV-004',
|
|
|
|
status: 'Filled',
|
|
|
|
shelf_no: 'D4',
|
|
},
|
|
|
|
{
|
|
payee: 'Logistics Co.',
|
|
|
|
// type code here for "relation_one" field
|
|
|
|
payment_date: new Date('2023-08-05T00:00:00Z'),
|
|
|
|
purpose: 'Transportation Services',
|
|
|
|
amount: 3000,
|
|
|
|
document_type: 'BPV',
|
|
|
|
auto_generated_document_no: 'EDU005-JV-005',
|
|
|
|
status: 'Filled',
|
|
|
|
shelf_no: 'E5',
|
|
},
|
|
];
|
|
|
|
const ProjectsData = [
|
|
{
|
|
name: 'MOH Health Initiative',
|
|
|
|
code: 'MOH001',
|
|
|
|
source_of_funds: 'Government Grant',
|
|
|
|
start_date: new Date('2023-01-01T00:00:00Z'),
|
|
|
|
end_date: new Date('2023-12-31T00:00:00Z'),
|
|
|
|
status: 'Completed',
|
|
},
|
|
|
|
{
|
|
name: 'CDC Research Project',
|
|
|
|
code: 'CDC002',
|
|
|
|
source_of_funds: 'International Aid',
|
|
|
|
start_date: new Date('2023-02-15T00:00:00Z'),
|
|
|
|
end_date: new Date('2023-11-30T00:00:00Z'),
|
|
|
|
status: 'Completed',
|
|
},
|
|
|
|
{
|
|
name: 'NNP Nutrition Program',
|
|
|
|
code: 'NNP003',
|
|
|
|
source_of_funds: 'Private Donation',
|
|
|
|
start_date: new Date('2023-03-01T00:00:00Z'),
|
|
|
|
end_date: new Date('2023-10-15T00:00:00Z'),
|
|
|
|
status: 'Completed',
|
|
},
|
|
|
|
{
|
|
name: 'ACDC Community Development',
|
|
|
|
code: 'ACDC004',
|
|
|
|
source_of_funds: 'Local Government',
|
|
|
|
start_date: new Date('2023-04-10T00:00:00Z'),
|
|
|
|
end_date: new Date('2023-09-20T00:00:00Z'),
|
|
|
|
status: 'Completed',
|
|
},
|
|
|
|
{
|
|
name: 'Education Outreach',
|
|
|
|
code: 'EDU005',
|
|
|
|
source_of_funds: 'NGO Funding',
|
|
|
|
start_date: new Date('2023-05-05T00:00:00Z'),
|
|
|
|
end_date: new Date('2023-12-01T00:00:00Z'),
|
|
|
|
status: 'Completed',
|
|
},
|
|
];
|
|
|
|
// Similar logic for "relation_many"
|
|
|
|
async function associateFieldVisitWithProject() {
|
|
const relatedProject0 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const FieldVisit0 = await FieldVisits.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (FieldVisit0?.setProject) {
|
|
await FieldVisit0.setProject(relatedProject0);
|
|
}
|
|
|
|
const relatedProject1 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const FieldVisit1 = await FieldVisits.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (FieldVisit1?.setProject) {
|
|
await FieldVisit1.setProject(relatedProject1);
|
|
}
|
|
|
|
const relatedProject2 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const FieldVisit2 = await FieldVisits.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (FieldVisit2?.setProject) {
|
|
await FieldVisit2.setProject(relatedProject2);
|
|
}
|
|
|
|
const relatedProject3 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const FieldVisit3 = await FieldVisits.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (FieldVisit3?.setProject) {
|
|
await FieldVisit3.setProject(relatedProject3);
|
|
}
|
|
|
|
const relatedProject4 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const FieldVisit4 = await FieldVisits.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (FieldVisit4?.setProject) {
|
|
await FieldVisit4.setProject(relatedProject4);
|
|
}
|
|
}
|
|
|
|
async function associatePaymentWithProject() {
|
|
const relatedProject0 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const Payment0 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 0,
|
|
});
|
|
if (Payment0?.setProject) {
|
|
await Payment0.setProject(relatedProject0);
|
|
}
|
|
|
|
const relatedProject1 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const Payment1 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 1,
|
|
});
|
|
if (Payment1?.setProject) {
|
|
await Payment1.setProject(relatedProject1);
|
|
}
|
|
|
|
const relatedProject2 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const Payment2 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 2,
|
|
});
|
|
if (Payment2?.setProject) {
|
|
await Payment2.setProject(relatedProject2);
|
|
}
|
|
|
|
const relatedProject3 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const Payment3 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 3,
|
|
});
|
|
if (Payment3?.setProject) {
|
|
await Payment3.setProject(relatedProject3);
|
|
}
|
|
|
|
const relatedProject4 = await Projects.findOne({
|
|
offset: Math.floor(Math.random() * (await Projects.count())),
|
|
});
|
|
const Payment4 = await Payments.findOne({
|
|
order: [['id', 'ASC']],
|
|
offset: 4,
|
|
});
|
|
if (Payment4?.setProject) {
|
|
await Payment4.setProject(relatedProject4);
|
|
}
|
|
}
|
|
|
|
module.exports = {
|
|
up: async (queryInterface, Sequelize) => {
|
|
await FieldVisits.bulkCreate(FieldVisitsData);
|
|
|
|
await Payments.bulkCreate(PaymentsData);
|
|
|
|
await Projects.bulkCreate(ProjectsData);
|
|
|
|
await Promise.all([
|
|
// Similar logic for "relation_many"
|
|
|
|
await associateFieldVisitWithProject(),
|
|
|
|
await associatePaymentWithProject(),
|
|
]);
|
|
},
|
|
|
|
down: async (queryInterface, Sequelize) => {
|
|
await queryInterface.bulkDelete('field_visits', null, {});
|
|
|
|
await queryInterface.bulkDelete('payments', null, {});
|
|
|
|
await queryInterface.bulkDelete('projects', null, {});
|
|
},
|
|
};
|