A big project! Here's a comprehensive guide to create an Electron app for School Account Management Software with Account Management, Voucher Creation, and Report Generation. We'll break it down into smaller tasks, and I'll provide code snippets to get you started.
Project Structure
school-account-management/
├── main.js (Electron main process)
├── renderer.js (Electron renderer process)
├── index.html (main window HTML)
├── package.json
├── assets/ (images, icons, etc.)
├── components/ (reusable UI components)
│ ├── Header.js
│ ├── Sidebar.js
│ └── ...
├── containers/ (container components)
│ ├── AccountManagement.js
│ ├── VoucherCreation.js
│ ├── ReportGeneration.js
│ └── ...
├── models/ (data models)
│ ├── Account.js
│ ├── Voucher.js
│ ├── Transaction.js
│ └── ...
├── services/ (business logic)
│ ├── AccountService.js
│ ├── VoucherService.js
│ ├── ReportService.js
│ └── ...
├── stores/ (data storage, e.g., SQLite)
│ ├── db.js (database connection)
│ ├── schema.sql (database schema)
│ └── ...
├── utils/ (utility functions)
│ ├── date.js
│ ├── helpers.js
│ └── ...
└── node_modules/ (dependencies)
Step 1: Initialize the project
Run the following commands in your terminal:
mkdir school-account-management
cd school-account-management
npm init -y
npm install electron sqlite3 moment bootstrap font-awesome
Step 2: Set up Electron
Create main.js (Electron main process):
// main.js
const { app, BrowserWindow } = require('electron');
const path = require('path');
let mainWindow;
function createWindow() {
mainWindow = new BrowserWindow({
width: 1200,
height: 800,
webPreferences: {
nodeIntegration: true,
},
});
mainWindow.loadURL(`file://${path.join(__dirname, 'index.html')}`);
mainWindow.on('closed', () => {
mainWindow = null;
});
}
app.on('ready', createWindow);
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if (mainWindow === null) {
createWindow();
}
});
Create index.html (main window HTML):
<!-- index.html -->
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>School Account Management</title>
<link rel="stylesheet" href="node_modules/bootstrap/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="node_modules/font-awesome/css/font-awesome.min.css">
<style>
body {
font-family: Arial, sans-serif;
}
</style>
</head>
<body>
<div id="app"></div>
<script src="renderer.js"></script>
</body>
</html>
Step 3: Set up the renderer process
Create renderer.js (Electron renderer process):
// renderer.js
import React from 'react';
import ReactDOM from 'react-dom';
import App from './containers/App';
ReactDOM.render(<App />, document.getElementById('app'));
Create containers/App.js:
// containers/App.js
import React, { useState, useEffect } from 'react';
import Header from '../components/Header';
import Sidebar from '../components/Sidebar';
import AccountManagement from './AccountManagement';
import VoucherCreation from './VoucherCreation';
import ReportGeneration from './ReportGeneration';
const App = () => {
const [activeTab, setActiveTab] = useState('account-management');
const handleTabChange = (tab) => {
setActiveTab(tab);
};
return (
<div>
<Header />
<div className="container-fluid">
<div className="row">
<Sidebar onTabChange={handleTabChange} />
<div className="col-md-10">
{activeTab === 'account-management' && <AccountManagement />}
{activeTab === 'voucher-creation' && <VoucherCreation />}
{activeTab === 'report-generation' && <ReportGeneration />}
</div>
</div>
</div>
</div>
);
};
export default App;
Step 4: Implement Account Management
Create models/Account.js:
// models/Account.js
class Account {
constructor(id, name, email, phone, balance = 0) {
this.id = id;
this.name = name;
this.email = email;
this.phone = phone;
this.balance = balance;
}
}
export default Account;
Create services/AccountService.js:
// services/AccountService.js
import db from '../stores/db';
import Account from '../models/Account';
const AccountService = {
async getAllAccounts() {
const rows = await db.all('SELECT * FROM accounts');
return rows.map((row) => new Account(row.id, row.name, row.email, row.phone, row.balance));
},
async createAccount(account) {
await db.run('INSERT INTO accounts (name, email, phone, balance) VALUES (?, ?, ?, ?)',
account.name, account.email, account.phone, account.balance);
},
async updateAccount(account) {
await db.run('UPDATE accounts SET name = ?, email = ?, phone = ?, balance = ? WHERE id = ?',
account.name, account.email, account.phone, account.balance, account.id);
},
async deleteAccount(id) {
await db.run('DELETE FROM accounts WHERE id = ?', id);
},
};
export default AccountService;
Create containers/AccountManagement.js:
// containers/AccountManagement.js
import React, { useState, useEffect } from 'react';
import AccountService from '../services/AccountService';
const AccountManagement = () => {
const [accounts, setAccounts] = useState([]);
const [name, setName] = useState('');
const [email, setEmail] = useState('');
const [phone, setPhone] = useState('');
const [balance, setBalance] = useState(0);
const [editing, setEditing] = useState(null);
useEffect(() => {
const fetchAccounts = async () => {
const accounts = await AccountService.getAllAccounts();
setAccounts(accounts);
};
fetchAccounts();
}, []);
const handleCreateAccount = async () => {
const account = new Account(null, name, email, phone, balance);
await AccountService.createAccount(account);
setAccounts([...accounts, account]);
setName('');
setEmail('');
setPhone('');
setBalance(0);
};
const handleUpdateAccount = async () => {
const account = new Account(editing.id, name, email, phone, balance);
await AccountService.updateAccount(account);
setAccounts(accounts.map((a) => (a.id === account.id ? account : a)));
setEditing(null);
};
const handleDeleteAccount = async (id) => {
await AccountService.deleteAccount(id);
setAccounts(accounts.filter((a) => a.id !== id));
};
return (
<div>
<h2>Account Management</h2>
<form>
<div className="form-group">
<label>Name:</label>
<input type="text" value={name} onChange={(e) => setName(e.target.value)} />
</div>
<div className="form-group">
<label>Email:</label>
<input type="email" value={email} onChange={(e) => setEmail(e.target.value)} />
</div>
<div className="form-group">
<label>Phone:</label>
<input type="text" value={phone} onChange={(e) => setPhone(e.target.value)} />
</div>
<div className="form-group">
<label>Balance:</label>
<input type="number" value={balance} onChange={(e) => setBalance(e.target.valueAsNumber)} />
</div>
{editing ? (
<button className="btn btn-primary" onClick={handleUpdateAccount}>
Update Account
</button>
) : (
<button className="btn btn-success" onClick={handleCreateAccount}>
Create Account
</button>
)}
</form>
<table className="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Phone</th>
<th>Balance</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{accounts.map((account) => (
<tr key={account.id}>
<td>{account.name}</td>
<td>{account.email}</td>
<td>{account.phone}</td>
<td>{account.balance}</td>
<td>
<button
className="btn btn-info"
onClick={() => {
setEditing(account);
setName(account.name);
setEmail(account.email);
setPhone(account.phone);
setBalance(account.balance);
}}
>
Edit
</button>
<button
className="btn btn-danger"
onClick={() => handleDeleteAccount(account.id)}
>
Delete
</button>
</td>
</tr>
))}
</tbody>
</table>
</div>
);
};
export default AccountManagement;
Step 5: Implement Voucher Creation
Create models/Voucher.js:
// models/Voucher.js
class Voucher {
constructor(id, date, accountId, amount, description) {
this.id = id;
this.date = date;
this.accountId = accountId;
this.amount = amount;
this.description = description;
}
}
export default Voucher;
Create services/VoucherService.js:
// services/VoucherService.js
import db from '../stores/db';
import Voucher from '../models/Voucher';
const VoucherService = {
async getAllVouchers() {
const rows = await db.all('SELECT * FROM vouchers');
return rows.map((row) => new Voucher(row.id, row.date, row.account_id, row.amount, row.description));
},
async createVoucher(voucher) {
await db.run('INSERT INTO vouchers (date, account_id, amount, description) VALUES (?, ?, ?, ?)',
voucher.date, voucher.accountId, voucher.amount, voucher.description);
},
async updateVoucher(voucher) {
await db.run('UPDATE vouchers SET date = ?, account_id = ?, amount = ?, description = ? WHERE id = ?',
voucher.date, voucher.accountId, voucher.amount, voucher.description, voucher.id);
},
async deleteVoucher(id) {
await db.run('DELETE FROM vouchers WHERE id = ?', id);
},
};
export default VoucherService;
Create containers/VoucherCreation.js:
// containers/VoucherCreation.js
import React, { useState, useEffect } from 'react';
import VoucherService from '../services/VoucherService';
import AccountService from '../services/AccountService';
const VoucherCreation = () => {
const [accounts, setAccounts] = useState([]);
const [voucherDate, setVoucherDate] = useState(new Date());
const [accountId, setAccountId] = useState('');
const [amount, setAmount] = useState(0);
const [description, setDescription] = useState('');
const [vouchers, setVouchers] = useState([]);
useEffect(() => {
const fetchAccounts = async () => {
const accounts = await AccountService.getAllAccounts();
setAccounts(accounts);
};
fetchAccounts();
const fetchVouchers = async () => {
const vouchers = await VoucherService.getAllVouchers();
setVouchers(vouchers);
};
fetchVouchers();
}, []);
const handleCreateVoucher = async () => {
const voucher = new Voucher(null, voucherDate, accountId, amount, description);
await VoucherService.createVoucher(voucher);
setVouchers([...vouchers, voucher]);
setVoucherDate(new Date());
setAccountId('');
setAmount(0);
setDescription('');
};
return (
<div>
<h2>Voucher Creation</h2>
<form>
<div className="form-group">
<label>Date:</label>
<input type="date" value={voucherDate.toISOString().slice(0, 10)} onChange={(e) => setVoucherDate(new Date(e.target.value))} />
</div>
<div className="form-group">
<label>Account:</label>
<select value={accountId} onChange={(e) => setAccountId(e.target.value)}>
<option value="">Select Account</option>
{accounts.map((account) => (
<option key={account.id} value={account.id}>
{account.name}
</option>
))}
</select>
</div>
<div className="form-group">
<label>Amount:</label>
<input type="number" value={amount} onChange={(e) => setAmount(e.target.valueAsNumber)} />
</div>
<div className="form-group">
<label>Description:</label>
<input type="text" value={description} onChange={(e) => setDescription(e.target.value)} />
</div>
<button className="btn btn-success" onClick={handleCreateVoucher}>
Create Voucher
</button>
</form>
<table className="table table-striped">
<thead>
<tr>
<th>Date</th>
<th>Account</th>
<th>Amount</th>
<th>Description</th>
</tr>
</thead>
<tbody>
{vouchers.map((voucher) => (
<tr key={voucher.id}>
<td>{voucher.date.toISOString().slice(0, 10)}</td>
<td>{accounts.find((a) => a.id === voucher.accountId).name}</td>
<td>{voucher.amount}</td>
<td>{voucher.description}</td>
</tr>
))}
</tbody>
</table>
</div>
);
};
export default VoucherCreation;
Step 6: Implement Report Generation
Create services/ReportService.js:
// services/ReportService.js
import db from '../stores/db';
const ReportService = {
async getAccountSummary() {
const rows = await db.all(`
SELECT
a.name,
SUM(v.amount) AS total_amount,
COUNT(v.id) AS total_vouchers
FROM
accounts a
LEFT JOIN
vouchers v ON a.id = v.account_id
GROUP BY
a.name
`);
return rows;
},
async getVoucherDetails(accountId) {
const rows = await db.all('SELECT * FROM vouchers WHERE account_id = ?', accountId);
return rows;
},
};
export default ReportService;
Create containers/ReportGeneration.js:
// containers/ReportGeneration.js
import React, { useState, useEffect } from 'react';
import ReportService from '../services/ReportService';
import AccountService from '../services/AccountService';
const ReportGeneration = () => {
const [accounts, setAccounts] = useState([]);
const [accountId, setAccountId] = useState('');
const [report, setReport] = useState(null);
const [voucherDetails, setVoucherDetails] = useState([]);
useEffect(() => {
const fetchAccounts = async () => {
const accounts = await AccountService.getAllAccounts();
setAccounts(accounts);
};
fetchAccounts();
}, []);
const handleGenerateReport = async () => {
const report = await ReportService.getAccountSummary();
setReport(report);
if (accountId) {
const voucherDetails = await ReportService.getVoucherDetails(accountId);
setVoucherDetails(voucherDetails);
}
};
return (
<div>
<h2>Report Generation</h2>
<form>
<div className="form-group">
<label>Account:</label>
<select value={accountId} onChange={(e) => setAccountId(e.target.value)}>
<option value="">Select Account</option>
{accounts.map((account) => (
<option key={account.id} value={account.id}>
{account.name}
</option>
))}
</select>
</div>
<button className="btn btn-primary" onClick={handleGenerateReport}>
Generate Report
</button>
</form>
{report && (
<div>
<h3>Account Summary</h3>
<table className="table table-striped">
<thead>
<tr>
<th>Account Name</th>
<th>Total Amount</th>
<th>Total Vouchers</th>
</tr>
</thead>
<tbody>
{report.map((row) => (
<tr key={row.name}>
<td>{row.name}</td>
<td>{row.total_amount}</td>
<td>{row.total_vouchers}</td>
</tr>
))}
</tbody>
</table>
{voucherDetails.length > 0 && (
<div>
<h3>Voucher Details for {accounts.find((a) => a.id === accountId).name}</h3>
<table className="table table-striped">
<thead>
<tr>
<th>Date</th>
<th>Amount</th>
<th>Description</th>
</tr>
</thead>
<tbody>
{voucherDetails.map((voucher) => (
<tr key={voucher.id}>
<td>{voucher.date.toISOString().slice(0, 10)}</td>
<td>{voucher.amount}</td>
<td>{voucher.description}</td>
</tr>
))}
</tbody>
</table>
</div>
)}
</div>
)}
</div>
);
};
export default ReportGeneration;
Step 7: Set up SQLite database
Create stores/db.js:
// stores/db.js
import sqlite3 from 'sqlite3';
const db = new sqlite3.Database('./school-account-management.db');
db.serialize(() => {
db.run(`
CREATE TABLE IF NOT EXISTS accounts (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
email TEXT NOT NULL,
phone TEXT NOT NULL,
balance REAL DEFAULT 0
);
`);
db.run(`
CREATE TABLE IF NOT EXISTS vouchers (
id INTEGER PRIMARY KEY AUTOINCREMENT,
date DATE NOT NULL,
account_id INTEGER NOT NULL,
amount REAL NOT NULL,
description TEXT,
FOREIGN KEY (account_id) REFERENCES accounts (id)
);
`);
});
export default db;
Step 8: Run the app
Update package.json:
"scripts": {
"start": "electron ."
}
Run the app:
npm start
This will launch the Electron app. You can now navigate through the different sections:
- Account Management: Create, update, and delete accounts.
- Voucher Creation: Create vouchers for selected accounts.
- Report Generation: Generate account summary and voucher details reports.
That's it! You've successfully created an Electron app for School Account Management Software with Account Management, Voucher Creation, and Report Generation.
Note that this is a basic implementation, and you may want to add more features, error handling, and security measures (e.g., encryption, authentication) to make it production-ready.
Happy coding!