Director hiring added
This commit is contained in:
@@ -9,6 +9,18 @@ class FalukantController {
|
||||
this.getInfo = this.getInfo.bind(this);
|
||||
this.getInventory = this.getInventory.bind(this);
|
||||
this.sellProduct = this.sellProduct.bind(this);
|
||||
this.sellAllProducts = this.sellAllProducts.bind(this);
|
||||
this.moneyHistory = this.moneyHistory.bind(this);
|
||||
this.getStorage = this.getStorage.bind(this);
|
||||
this.buyStorage = this.buyStorage.bind(this);
|
||||
this.sellStorage = this.sellStorage.bind(this);
|
||||
this.getStockTypes = this.getStockTypes.bind(this);
|
||||
this.getStockOverview = this.getStockOverview.bind(this);
|
||||
this.getAllProductions = this.getAllProductions.bind(this);
|
||||
this.getDirectorProposals = this.getDirectorProposals.bind(this);
|
||||
this.convertProposalToDirector = this.convertProposalToDirector.bind(this);
|
||||
this.getDirectorForBranch = this.getDirectorForBranch.bind(this);
|
||||
this.setSetting = this.setSetting.bind(this);
|
||||
}
|
||||
|
||||
async getUser(req, res) {
|
||||
@@ -118,6 +130,7 @@ class FalukantController {
|
||||
}
|
||||
|
||||
async createStock(req, res) {
|
||||
console.log('build stock');
|
||||
try {
|
||||
const { userid: hashedUserId } = req.headers;
|
||||
const { branchId, stockTypeId, stockSize } = req.body;
|
||||
@@ -159,6 +172,146 @@ class FalukantController {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
async sellAllProducts(req, res) {
|
||||
try {
|
||||
const { userid: hashedUserId } = req.headers;
|
||||
const { branchId } = req.body;
|
||||
const result = await FalukantService.sellAllProducts(hashedUserId, branchId);
|
||||
res.status(201).json(result);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
async moneyHistory(req, res) {
|
||||
try {
|
||||
const { userid: hashedUserId } = req.headers;
|
||||
const { page, filter } = req.body;
|
||||
if (!page) {
|
||||
page = 1;
|
||||
}
|
||||
const result = await FalukantService.moneyHistory(hashedUserId, page, filter);
|
||||
res.status(201).json(result);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
async getStorage(req, res) {
|
||||
try {
|
||||
const { userid: hashedUserId } = req.headers;
|
||||
const { branchId } = req.params;
|
||||
const result = await FalukantService.getStorage(hashedUserId, branchId);
|
||||
res.status(200).json(result);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message});
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
async buyStorage(req, res) {
|
||||
try {
|
||||
const { userid: hashedUserId } = req.headers;
|
||||
const { branchId, amount, stockTypeId } = req.body;
|
||||
const result = await FalukantService.buyStorage(hashedUserId, branchId, amount, stockTypeId);
|
||||
res.status(201).json(result);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message});
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
async sellStorage(req, res) {
|
||||
try {
|
||||
const { userid: hashedUserId } = req.headers;
|
||||
const { branchId, amount, stockTypeId } = req.body;
|
||||
const result = await FalukantService.sellStorage(hashedUserId, branchId, amount, stockTypeId);
|
||||
res.status(202).json(result);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message});
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
async getStockTypes(req, res) {
|
||||
console.log('load stock');
|
||||
try {
|
||||
const result = await FalukantService.getStockTypes();
|
||||
res.status(200).json(result);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
async getStockOverview(req, res) {
|
||||
try {
|
||||
const result = await FalukantService.getStockOverview();
|
||||
res.status(200).json(result);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
async getAllProductions(req, res) {
|
||||
try {
|
||||
const { userid: hashedUserId } = req.headers;
|
||||
const result = await FalukantService.getAllProductions(hashedUserId);
|
||||
res.status(200).json(result);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
async getDirectorProposals(req, res) {
|
||||
try {
|
||||
const { userid: hashedUserId } = req.headers;
|
||||
const { branchId } = req.body;
|
||||
const result = await FalukantService.getDirectorProposals(hashedUserId, branchId);
|
||||
res.status(200).json(result);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
async convertProposalToDirector(req, res) {
|
||||
try {
|
||||
const { userid: hashedUserId } = req.headers;
|
||||
const { proposalId } = req.body;
|
||||
const result = await FalukantService.convertProposalToDirector(hashedUserId, proposalId);
|
||||
res.status(200).json(result);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
async getDirectorForBranch(req, res) {
|
||||
try {
|
||||
const { userid: hashedUserId } = req.headers;
|
||||
const { branchId } = req.params;
|
||||
const result = await FalukantService.getDirectorForBranch(hashedUserId, branchId);
|
||||
if (!result) {
|
||||
return res.status(404).json({ message: 'No director found for this branch' });
|
||||
}
|
||||
res.status(200).json(result);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
}
|
||||
}
|
||||
|
||||
async setSetting(req, res) {
|
||||
try {
|
||||
const { userid: hashedUserId } = req.headers;
|
||||
const { branchId, directorId, settingKey, value } = req.body;
|
||||
const result = await FalukantService.setSetting(hashedUserId, branchId, directorId, settingKey, value);
|
||||
res.status(200).json(result);
|
||||
} catch (error) {
|
||||
res.status(500).json({ error: error.message });
|
||||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
export default FalukantController;
|
||||
|
||||
@@ -44,8 +44,10 @@ import Branch from './falukant/data/branch.js';
|
||||
import BranchType from './falukant/type/branch.js';
|
||||
import Production from './falukant/data/production.js';
|
||||
import Inventory from './falukant/data/inventory.js';
|
||||
import BuyableStock from './falukant/data/buayble_stock.js';
|
||||
|
||||
import BuyableStock from './falukant/data/buyable_stock.js';
|
||||
import MoneyFlow from './falukant/log/moneyflow.js';
|
||||
import Director from './falukant/data/director.js';
|
||||
import DirectorProposal from './falukant/data/director_proposal.js';
|
||||
|
||||
export default function setupAssociations() {
|
||||
// UserParam related associations
|
||||
@@ -251,4 +253,21 @@ export default function setupAssociations() {
|
||||
Branch.hasMany(FalukantStock, { foreignKey: 'branchId', as: 'stocks' });
|
||||
FalukantStock.belongsTo(Branch, { foreignKey: 'branchId', as: 'branch' });
|
||||
|
||||
MoneyFlow.belongsTo(FalukantUser, { foreignKey: 'falukantUserId', as: 'user' });
|
||||
FalukantUser.hasMany(MoneyFlow, { foreignKey: 'falukantUserId', as: 'flows' });
|
||||
|
||||
BuyableStock.belongsTo(FalukantStockType, { foreignKey: 'stockTypeId', as: 'stockType' });
|
||||
FalukantStockType.hasMany(BuyableStock, { foreignKey: 'stockTypeId', as: 'buyableStocks' });
|
||||
|
||||
Director.belongsTo(FalukantUser, { foreignKey: 'employerUserId', as: 'user' });
|
||||
FalukantUser.hasMany(Director, { foreignKey: 'employerUserId', as: 'directors' });
|
||||
|
||||
Director.belongsTo(FalukantCharacter, { foreignKey: 'directorCharacterId', as: 'character' });
|
||||
FalukantCharacter.hasMany(Director, { foreignKey: 'directorCharacterId', as: 'directors' });
|
||||
|
||||
DirectorProposal.belongsTo(FalukantUser, { foreignKey: 'employerUserId', as: 'user' });
|
||||
FalukantUser.hasMany(DirectorProposal, { foreignKey: 'employerUserId', as: 'directorProposals' });
|
||||
|
||||
DirectorProposal.belongsTo(FalukantCharacter, { foreignKey: 'directorCharacterId', as: 'character' });
|
||||
FalukantCharacter.hasMany(DirectorProposal, { foreignKey: 'directorCharacterId', as: 'directorProposals' });
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ Branch.init({
|
||||
},
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: 'BranchType',
|
||||
modelName: 'Branch',
|
||||
tableName: 'branch',
|
||||
schema: 'falukant_data',
|
||||
timestamps: false,
|
||||
|
||||
48
backend/models/falukant/data/director.js
Normal file
48
backend/models/falukant/data/director.js
Normal file
@@ -0,0 +1,48 @@
|
||||
import { Model, DataTypes } from 'sequelize';
|
||||
import { sequelize } from '../../../utils/sequelize.js';
|
||||
|
||||
class Director extends Model { }
|
||||
|
||||
Director.init({
|
||||
directorCharacterId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
employerUserId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
income: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
satisfaction: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
defaultValue: 100,
|
||||
},
|
||||
mayProduce: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: true,
|
||||
},
|
||||
maySell: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: true,
|
||||
},
|
||||
mayStartTransport: {
|
||||
type: DataTypes.BOOLEAN,
|
||||
allowNull: false,
|
||||
defaultValue: true,
|
||||
}
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: 'Director',
|
||||
tableName: 'director',
|
||||
schema: 'falukant_data',
|
||||
timestamps: false,
|
||||
underscored: true,
|
||||
});
|
||||
|
||||
export default Director;
|
||||
28
backend/models/falukant/data/director_proposal.js
Normal file
28
backend/models/falukant/data/director_proposal.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import { Model, DataTypes } from 'sequelize';
|
||||
import { sequelize } from '../../../utils/sequelize.js';
|
||||
|
||||
class DirectorProposal extends Model { }
|
||||
|
||||
DirectorProposal.init({
|
||||
directorCharacterId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
employerUserId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
proposedIncome: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: 'DirectorProposal',
|
||||
tableName: 'director_proposal',
|
||||
schema: 'falukant_data',
|
||||
timestamps: true,
|
||||
underscored: true,
|
||||
});
|
||||
|
||||
export default DirectorProposal;
|
||||
@@ -19,7 +19,7 @@ FalukantStock.init({
|
||||
},
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: 'StockType',
|
||||
modelName: 'StockData',
|
||||
tableName: 'stock',
|
||||
schema: 'falukant_data',
|
||||
timestamps: false,
|
||||
|
||||
45
backend/models/falukant/log/moneyflow.js
Normal file
45
backend/models/falukant/log/moneyflow.js
Normal file
@@ -0,0 +1,45 @@
|
||||
import { Model, DataTypes } from 'sequelize';
|
||||
import { sequelize } from '../../../utils/sequelize.js';
|
||||
|
||||
class MoneyFlow extends Model { }
|
||||
|
||||
MoneyFlow.init({
|
||||
falukantUserId: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: false,
|
||||
},
|
||||
activity: {
|
||||
type: DataTypes.STRING,
|
||||
allowNull: false,
|
||||
},
|
||||
moneyBefore: {
|
||||
type: DataTypes.DOUBLE,
|
||||
allowNull: false,
|
||||
},
|
||||
moneyAfter: {
|
||||
type: DataTypes.DOUBLE,
|
||||
allowNull: true,
|
||||
},
|
||||
time: {
|
||||
type: DataTypes.DATE,
|
||||
allowNull: false,
|
||||
defaultValue: DataTypes.NOW
|
||||
},
|
||||
changeValue: {
|
||||
type: DataTypes.DOUBLE,
|
||||
allowNull: false,
|
||||
},
|
||||
changedBy: {
|
||||
type: DataTypes.INTEGER,
|
||||
allowNull: true,
|
||||
},
|
||||
}, {
|
||||
sequelize,
|
||||
modelName: 'MoneyFlow',
|
||||
tableName: 'moneyflow',
|
||||
schema: 'falukant_log',
|
||||
timestamps: false,
|
||||
underscored: true,
|
||||
});
|
||||
|
||||
export default MoneyFlow;
|
||||
@@ -48,7 +48,10 @@ import BranchType from './falukant/type/branch.js';
|
||||
import Branch from './falukant/data/branch.js';
|
||||
import Production from './falukant/data/production.js';
|
||||
import Inventory from './falukant/data/inventory.js';
|
||||
import BuyableStock from './falukant/data/buayble_stock.js';
|
||||
import BuyableStock from './falukant/data/buyable_stock.js';
|
||||
import MoneyFlow from './falukant/log/moneyflow.js';
|
||||
import Director from './falukant/data/director.js';
|
||||
import DirectorProposal from './falukant/data/director_proposal.js';
|
||||
|
||||
const models = {
|
||||
SettingsType,
|
||||
@@ -102,6 +105,9 @@ const models = {
|
||||
Production,
|
||||
Inventory,
|
||||
BuyableStock,
|
||||
MoneyFlow,
|
||||
Director,
|
||||
DirectorProposal,
|
||||
};
|
||||
|
||||
export default models;
|
||||
|
||||
@@ -124,6 +124,62 @@ export async function createTriggers() {
|
||||
EXECUTE FUNCTION falukant_data.create_knowledge_trigger();
|
||||
`;
|
||||
|
||||
const updateMoney = `
|
||||
CREATE OR REPLACE FUNCTION falukant_data.update_money(
|
||||
p_falukant_user_id integer,
|
||||
p_money_change numeric,
|
||||
p_activity text,
|
||||
p_changed_by integer DEFAULT NULL
|
||||
)
|
||||
RETURNS void
|
||||
LANGUAGE plpgsql
|
||||
AS $function$
|
||||
DECLARE
|
||||
v_money_before numeric(10,2);
|
||||
v_money_after numeric(10,2);
|
||||
v_moneyflow_id bigint;
|
||||
BEGIN
|
||||
SELECT money
|
||||
INTO v_money_before
|
||||
FROM falukant_data.falukant_user
|
||||
WHERE id = p_falukant_user_id;
|
||||
IF NOT FOUND THEN
|
||||
RAISE EXCEPTION 'FalukantUser mit ID % nicht gefunden', p_falukant_user_id;
|
||||
END IF;
|
||||
v_money_after := v_money_before + p_money_change;
|
||||
INSERT INTO falukant_log.moneyflow (
|
||||
falukant_user_id,
|
||||
activity,
|
||||
money_before,
|
||||
money_after,
|
||||
change_value,
|
||||
changed_by,
|
||||
time
|
||||
)
|
||||
VALUES (
|
||||
p_falukant_user_id,
|
||||
p_activity,
|
||||
v_money_before,
|
||||
NULL, -- Wird gleich aktualisiert
|
||||
p_money_change,
|
||||
p_changed_by,
|
||||
NOW()
|
||||
)
|
||||
RETURNING id INTO v_moneyflow_id;
|
||||
UPDATE falukant_data.falukant_user
|
||||
SET money = v_money_after
|
||||
WHERE id = p_falukant_user_id;
|
||||
UPDATE falukant_log.moneyflow
|
||||
SET money_after = (
|
||||
SELECT money
|
||||
FROM falukant_data.falukant_user
|
||||
WHERE id = p_falukant_user_id
|
||||
)
|
||||
WHERE id = v_moneyflow_id;
|
||||
END;
|
||||
$function$;
|
||||
`;
|
||||
|
||||
try {
|
||||
await sequelize.query(createTriggerFunction);
|
||||
await sequelize.query(createInsertTrigger);
|
||||
@@ -136,6 +192,7 @@ export async function createTriggers() {
|
||||
await sequelize.query(createCharacterCreationTrigger);
|
||||
await sequelize.query(createKnowledgeTriggerMethod);
|
||||
await sequelize.query(createKnowledgeTrigger);
|
||||
await sequelize.query(updateMoney);
|
||||
|
||||
console.log('Triggers created successfully');
|
||||
} catch (error) {
|
||||
|
||||
@@ -11,11 +11,24 @@ router.get('/name/randomlastname', falukantController.randomLastName);
|
||||
router.get('/info', falukantController.getInfo);
|
||||
router.get('/branches/:branch', falukantController.getBranch);
|
||||
router.get('/branches', falukantController.getBranches);
|
||||
router.get('/productions', falukantController.getAllProductions);
|
||||
router.post('/production', falukantController.createProduction);
|
||||
router.get('/production/:branchId', falukantController.getProduction);
|
||||
router.get('/stocktypes', falukantController.getStockTypes);
|
||||
router.get('/stockoverview', falukantController.getStockOverview);
|
||||
router.get('/stock/?:branchId', falukantController.getStock);
|
||||
router.post('/stock', falukantController.createStock);
|
||||
router.get('/products', falukantController.getProducts);
|
||||
router.get('/inventory/?:branchId', falukantController.getInventory);
|
||||
router.post('/sell/all', falukantController.sellAllProducts);
|
||||
router.post('/sell', falukantController.sellProduct);
|
||||
router.post('/moneyhistory', falukantController.moneyHistory);
|
||||
router.get('/storage/:branchId', falukantController.getStorage);
|
||||
router.post('/storage', falukantController.buyStorage);
|
||||
router.delete('/storage', falukantController.sellStorage);
|
||||
router.post('/director/proposal', falukantController.getDirectorProposals);
|
||||
router.post('/director/convertproposal', falukantController.convertProposalToDirector);
|
||||
router.post('/director/settings', falukantController.setSetting);
|
||||
router.get('/director/:branchId', falukantController.getDirectorForBranch);
|
||||
|
||||
export default router;
|
||||
|
||||
@@ -104,12 +104,14 @@ export const loginUser = async ({ username, password }) => {
|
||||
user.authCode = authCode;
|
||||
await user.save();
|
||||
const friends = await getFriends(user.id);
|
||||
console.log('send login to friends');
|
||||
for (const friend of friends) {
|
||||
await notifyUser(friend.hashedId, 'friendloginchanged', {
|
||||
userId: user.hashedId,
|
||||
status: 'online',
|
||||
});
|
||||
}
|
||||
console.log('set user session');
|
||||
const sessionData = {
|
||||
id: user.hashedId,
|
||||
username: user.username,
|
||||
@@ -118,6 +120,7 @@ export const loginUser = async ({ username, password }) => {
|
||||
timestamp: Date.now()
|
||||
};
|
||||
await setUserSession(user.id, sessionData);
|
||||
console.log('get user params');
|
||||
const params = await UserParam.findAll({
|
||||
where: {
|
||||
userId: user.id
|
||||
@@ -133,6 +136,7 @@ export const loginUser = async ({ username, password }) => {
|
||||
const mappedParams = params.map(param => {
|
||||
return { 'name': param.paramType.description, 'value': param.value };
|
||||
});
|
||||
console.log('return user');
|
||||
return {
|
||||
id: user.hashedId,
|
||||
username: user.username,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -214,12 +214,15 @@ const initializeFalukantLastnames = async () => {
|
||||
}
|
||||
|
||||
async function initializeFalukantStockTypes() {
|
||||
try {
|
||||
await FalukantStockType.bulkCreate([
|
||||
{ labelTr: 'wood', cost: 15 },
|
||||
{ labelTr: 'stone', cost: 25 },
|
||||
{ labelTr: 'iron', cost: 100 },
|
||||
{ labelTr: 'field', cost: 5 },
|
||||
]);
|
||||
} catch (error) {
|
||||
}
|
||||
}
|
||||
|
||||
async function initializeFalukantProducts() {
|
||||
|
||||
@@ -20,6 +20,7 @@ const createSchemas = async () => {
|
||||
await sequelize.query('CREATE SCHEMA IF NOT EXISTS falukant_data');
|
||||
await sequelize.query('CREATE SCHEMA IF NOT EXISTS falukant_type');
|
||||
await sequelize.query('CREATE SCHEMA IF NOT EXISTS falukant_predefine');
|
||||
await sequelize.query('CREATE SCHEMA IF NOT EXISTS falukant_log');
|
||||
};
|
||||
|
||||
const initializeDatabase = async () => {
|
||||
@@ -34,4 +35,37 @@ const syncModels = async (models) => {
|
||||
}
|
||||
};
|
||||
|
||||
export { sequelize, initializeDatabase, syncModels };
|
||||
async function updateFalukantUserMoney(falukantUserId, moneyChange, activity, changedBy = null) {
|
||||
try {
|
||||
const result = await sequelize.query(
|
||||
`SELECT falukant_data.update_money(
|
||||
:falukantUserId,
|
||||
:moneyChange,
|
||||
:activity,
|
||||
:changedBy
|
||||
)`,
|
||||
{
|
||||
replacements: {
|
||||
falukantUserId,
|
||||
moneyChange,
|
||||
activity,
|
||||
changedBy,
|
||||
},
|
||||
type: sequelize.QueryTypes.SELECT,
|
||||
}
|
||||
);
|
||||
return {
|
||||
success: true,
|
||||
message: 'Money updated successfully',
|
||||
result
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Error updating money:', error);
|
||||
return {
|
||||
success: false,
|
||||
message: error.message
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export { sequelize, initializeDatabase, syncModels, updateFalukantUserMoney };
|
||||
|
||||
@@ -48,7 +48,9 @@ export async function notifyUser(recipientHashedUserId, event, data) {
|
||||
if (recipientUser) {
|
||||
const socketId = userSockets[recipientUser.hashedId];
|
||||
if (socketId) {
|
||||
setTimeout(() => {
|
||||
io.to(socketId).emit(event, data);
|
||||
}, 250);
|
||||
}
|
||||
} else {
|
||||
console.log(`Benutzer mit gehashter ID ${recipientHashedUserId} nicht gefunden.`);
|
||||
@@ -56,6 +58,7 @@ export async function notifyUser(recipientHashedUserId, event, data) {
|
||||
} catch (err) {
|
||||
console.error('Fehler beim Senden der Benachrichtigung:', err);
|
||||
}
|
||||
console.log('done sending socket');
|
||||
}
|
||||
|
||||
export async function notifyAllUsers(event, data) {
|
||||
|
||||
BIN
frontend/dump.rdb
Normal file
BIN
frontend/dump.rdb
Normal file
Binary file not shown.
@@ -75,5 +75,6 @@ export default {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -113,3 +113,15 @@ span.button:hover {
|
||||
.font-color-gender-nonbinary {
|
||||
color: #DAA520;
|
||||
}
|
||||
|
||||
main,
|
||||
.contenthidden {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: hidden;
|
||||
}
|
||||
.contentscroll {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
}
|
||||
@@ -81,6 +81,7 @@ export default {
|
||||
width: calc(100% + 40px);
|
||||
gap: 2em;
|
||||
margin: -21px -20px 1.5em -20px;
|
||||
position: fixed;
|
||||
}
|
||||
|
||||
.status-item {
|
||||
|
||||
162
frontend/src/dialogues/falukant/NewDirectorDialog.vue
Normal file
162
frontend/src/dialogues/falukant/NewDirectorDialog.vue
Normal file
@@ -0,0 +1,162 @@
|
||||
<template>
|
||||
<DialogWidget ref="dialog" :title="$t('factset.newdirector.title')" :show-close="true" :buttons="buttons"
|
||||
@close="closeDialog" name="FalukantNewDirector" :modal="true" :isTitleTranslated="true">
|
||||
<div class="director-dialog">
|
||||
<div class="proposal-list">
|
||||
<ul>
|
||||
<li v-for="proposal in proposals" :key="proposal.id" @click="selectProposal(proposal)"
|
||||
:class="{ selected: selectedProposal && selectedProposal.id === proposal.id }">
|
||||
{{ $t('falukant.titles.' + proposal.character.gender + '.' + proposal.character.title) }} {{ proposal.character.name }} ({{ proposal.character.age }} Jahre)
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="proposal-details" v-if="selectedProposal">
|
||||
<h3>{{ selectedProposal.character.name }}</h3>
|
||||
<p><strong>{{ $t('falukant.newdirector.age') }}</strong> {{ selectedProposal.character.age }} Jahre</p>
|
||||
<p><strong>{{ $t('falukant.newdirector.salary') }}</strong> {{ selectedProposal.proposedIncome }} $</p>
|
||||
<h4>{{ $t('falukant.newdirector.skills') }}</h4>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ $t('falukant.newdirector.product') }}</th>
|
||||
<th>{{ $t('falukant.newdirector.knowledge') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="knowledge in selectedProposal.character.knowledge" :key="knowledge.id">
|
||||
<td>{{ $t('falukant.product.' + knowledge.labelTr) }}</td>
|
||||
<td>{{ mapKnowledgeToText(knowledge.value) }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</DialogWidget>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import apiClient from '@/utils/axios.js';
|
||||
import DialogWidget from '@/components/DialogWidget.vue';
|
||||
import { mapKnowledgeToText } from '@/utils/knowledgeHelper.js';
|
||||
|
||||
export default {
|
||||
name: 'FalukantNewDirector',
|
||||
components: {
|
||||
DialogWidget,
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
dialog: null,
|
||||
proposals: [],
|
||||
selectedProposal: null,
|
||||
products: [],
|
||||
buttons: [
|
||||
{ text: 'Einstellen', action: this.hireDirector },
|
||||
{ text: 'Abbrechen', action: 'close' },
|
||||
],
|
||||
};
|
||||
},
|
||||
methods: {
|
||||
async open(branchId) {
|
||||
this.dialog.open();
|
||||
await this.loadProposals(branchId);
|
||||
},
|
||||
|
||||
closeDialog() {
|
||||
this.dialog.close();
|
||||
this.proposals = [];
|
||||
this.selectedProposal = null;
|
||||
},
|
||||
|
||||
async loadProposals(branchId) {
|
||||
try {
|
||||
const response = await apiClient.post('/api/falukant/director/proposal', { branchId });
|
||||
this.proposals = response.data.map((proposal) => {
|
||||
return {
|
||||
...proposal,
|
||||
knowledge: proposal.knowledge || [],
|
||||
};
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error loading proposals:', error);
|
||||
}
|
||||
},
|
||||
|
||||
selectProposal(proposal) {
|
||||
this.selectedProposal = proposal;
|
||||
},
|
||||
|
||||
async hireDirector() {
|
||||
if (!this.selectedProposal) return;
|
||||
try {
|
||||
await apiClient.post('/api/falukant/director/convertproposal', { proposalId: this.selectedProposal.id });
|
||||
this.closeDialog();
|
||||
this.$emit('directorHired');
|
||||
} catch (error) {
|
||||
console.error('Error hiring director:', error);
|
||||
}
|
||||
},
|
||||
|
||||
mapKnowledgeToText(value) {
|
||||
return mapKnowledgeToText(value, this.$t);
|
||||
},
|
||||
},
|
||||
|
||||
mounted() {
|
||||
this.dialog = this.$refs.dialog;
|
||||
},
|
||||
|
||||
beforeUnmount() { },
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.director-dialog {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.proposal-list {
|
||||
width: 40%;
|
||||
border-right: 1px solid #ddd;
|
||||
padding-right: 20px;
|
||||
}
|
||||
|
||||
.proposal-list ul {
|
||||
list-style: none;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.proposal-list li {
|
||||
padding: 10px;
|
||||
cursor: pointer;
|
||||
border: 1px solid transparent;
|
||||
margin-bottom: 10px;
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
.proposal-list li:hover {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
|
||||
.proposal-list li.selected {
|
||||
border-color: #f9a22c;
|
||||
background-color: #fdf1db;
|
||||
}
|
||||
|
||||
.proposal-details {
|
||||
width: 60%;
|
||||
}
|
||||
|
||||
.proposal-details table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
|
||||
.proposal-details table th,
|
||||
.proposal-details table td {
|
||||
padding: 10px;
|
||||
border: 1px solid #ddd;
|
||||
text-align: left;
|
||||
}
|
||||
</style>
|
||||
@@ -50,7 +50,7 @@
|
||||
"titles": {
|
||||
"male": {
|
||||
"noncivil": "Leibeigener",
|
||||
"civil": "Bürgerlich",
|
||||
"civil": "Freier Bürger",
|
||||
"sir": "Herr",
|
||||
"townlord": "Stadtherr",
|
||||
"by": "von",
|
||||
@@ -71,7 +71,7 @@
|
||||
},
|
||||
"female": {
|
||||
"noncivil": "Leibeigene",
|
||||
"civil": "Bürgerlich",
|
||||
"civil": "Freie Bürgerin",
|
||||
"sir": "Frau",
|
||||
"townlord": "Stadtherrin",
|
||||
"by": "zu",
|
||||
@@ -106,7 +106,18 @@
|
||||
},
|
||||
"director": {
|
||||
"title": "Direktor-Infos",
|
||||
"info": "Informationen über den Direktor der Niederlassung."
|
||||
"info": "Informationen über den Direktor der Niederlassung.",
|
||||
"actions": {
|
||||
"new": "Direktor einstellen"
|
||||
},
|
||||
"name": "Name",
|
||||
"salary": "Gehalt",
|
||||
"satisfaction": "Zufriedenheit",
|
||||
"fire": "Feuern",
|
||||
"teach": "Weiterbilden",
|
||||
"produce": "Darf produzieren",
|
||||
"sell": "Darf verkaufen",
|
||||
"starttransport": "Darf Transporte veranlassen"
|
||||
},
|
||||
"sale": {
|
||||
"title": "Inventar",
|
||||
@@ -137,7 +148,8 @@
|
||||
"time": "Uhr",
|
||||
"current": "Laufende Produktionen",
|
||||
"product": "Produkt",
|
||||
"remainingTime": "Verbleibende Zeit (Sekunden)"
|
||||
"remainingTime": "Verbleibende Zeit (Sekunden)",
|
||||
"noProductions": "Keine laufenden Produktionen."
|
||||
},
|
||||
"columns": {
|
||||
"city": "Stadt",
|
||||
@@ -155,7 +167,31 @@
|
||||
"perMinute": "Erlös pro Minute",
|
||||
"expand": "Erträge anzeigen",
|
||||
"collapse": "Erträge ausblenden",
|
||||
"knowledge": "Produktwissen"
|
||||
"knowledge": "Produktwissen",
|
||||
"profitAbsolute": "Gesamtgewinn",
|
||||
"profitPerMinute": "Gewinn pro Minute"
|
||||
},
|
||||
"storage": {
|
||||
"title": "Lager",
|
||||
"currentCapacity": "Verwendetes Lager",
|
||||
"stockType": "Lagerart",
|
||||
"totalCapacity": "Vorhanden",
|
||||
"used": "Verwendet",
|
||||
"availableToBuy": "Zum Kauf verfügbar",
|
||||
"buyAmount": "Größe",
|
||||
"buyStorageButton": "Kaufen",
|
||||
"sellAmount": "Größe",
|
||||
"sellStorageButton": "Verkaufen",
|
||||
"selectStockType": "Lagertyp auswählen",
|
||||
"costPerUnit": "Kosten pro Einheit",
|
||||
"buycost": "Kosten",
|
||||
"sellincome": "Einnahmen"
|
||||
},
|
||||
"stocktype": {
|
||||
"wood": "Holzlager",
|
||||
"stone": "Steinlager",
|
||||
"iron": "Eisenlager",
|
||||
"field": "Feldlager"
|
||||
}
|
||||
},
|
||||
"product": {
|
||||
@@ -194,6 +230,38 @@
|
||||
},
|
||||
"regionType": {
|
||||
"city": "Stadt"
|
||||
},
|
||||
"moneyHistory": {
|
||||
"title": "Geldhistorie",
|
||||
"filter": "Filter",
|
||||
"search": "Filter setzen",
|
||||
"activity": "Aktivität",
|
||||
"moneyBefore": "Geld vor der Transaktion",
|
||||
"moneyAfter": "Geld nach der Transaktion",
|
||||
"changeValue": "Wertänderung",
|
||||
"time": "Zeit",
|
||||
"activities": {
|
||||
"Product sale": "Produktverkauf",
|
||||
"Production cost": "Produktionskosten",
|
||||
"Sell all products": "Alle Produkte verkaufen"
|
||||
}
|
||||
},
|
||||
"newdirector": {
|
||||
"title": "Neuer Direktor",
|
||||
"age": "Alter",
|
||||
"salary": "Gehalt",
|
||||
"skills": "Wissen",
|
||||
"product": "Produkt",
|
||||
"knowledge": "Produktwissen"
|
||||
},
|
||||
"skillKnowledges": {
|
||||
"excelent": "Exzellent",
|
||||
"veryhigh": "Sehr gut",
|
||||
"high": "Gut",
|
||||
"medium": "Mittel",
|
||||
"low": "Schlecht",
|
||||
"verylow": "Sehr schlecht",
|
||||
"none": "Kein Wissen"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import BranchView from '../views/falukant/BranchView.vue';
|
||||
import Createview from '../views/falukant/CreateView.vue';
|
||||
import FalukantOverviewView from '../views/falukant/OverviewView.vue';
|
||||
import MoneyHistoryView from '../views/falukant/MoneyHistoryView.vue';
|
||||
|
||||
const falukantRoutes = [
|
||||
{
|
||||
@@ -21,6 +22,12 @@ const falukantRoutes = [
|
||||
component: BranchView,
|
||||
meta: { requiresAuth: true },
|
||||
},
|
||||
{
|
||||
path: '/falukant/moneyhistory',
|
||||
name: 'MoneyHistoryView',
|
||||
component: MoneyHistoryView,
|
||||
meta: { requiresAuth: true },
|
||||
},
|
||||
];
|
||||
|
||||
export default falukantRoutes;
|
||||
|
||||
@@ -56,7 +56,7 @@ const store = createStore({
|
||||
},
|
||||
clearDaemonSocket(state) {
|
||||
if (state.daemonSocket) {
|
||||
state.daemonSocket.disconnect();
|
||||
state.daemonSocket.close();
|
||||
}
|
||||
state.daemonSocket = null;
|
||||
},
|
||||
@@ -73,6 +73,7 @@ const store = createStore({
|
||||
await dispatch('loadMenu');
|
||||
},
|
||||
logout({ commit }) {
|
||||
console.log('Logging out...');
|
||||
commit('clearSocket');
|
||||
commit('clearDaemonSocket');
|
||||
commit('dologout');
|
||||
@@ -80,12 +81,16 @@ const store = createStore({
|
||||
},
|
||||
initializeSocket({ commit, state }) {
|
||||
if (state.isLoggedIn && state.user) {
|
||||
let currentSocket = state.socket;
|
||||
const connectSocket = () => {
|
||||
if (currentSocket) {
|
||||
currentSocket.disconnect();
|
||||
}
|
||||
const socket = io(import.meta.env.VITE_API_BASE_URL);
|
||||
|
||||
socket.on('connect', () => {
|
||||
console.log('Socket.io connected');
|
||||
socket.emit('setUserId', state.user.id);
|
||||
socket.emit('setUserId', state.user.id); // Sende user.id, wenn user vorhanden ist
|
||||
});
|
||||
|
||||
socket.on('disconnect', (reason) => {
|
||||
@@ -104,11 +109,17 @@ const store = createStore({
|
||||
};
|
||||
|
||||
connectSocket();
|
||||
} else {
|
||||
console.log("User is not logged in or user data is not available.");
|
||||
}
|
||||
},
|
||||
initializeDaemonSocket({ commit, state }) {
|
||||
if (state.isLoggedIn && state.user) {
|
||||
let currentDaemonSocket = state.daemonSocket;
|
||||
const connectDaemonSocket = () => {
|
||||
if (currentDaemonSocket) {
|
||||
currentDaemonSocket.disconnect();
|
||||
}
|
||||
const daemonSocket = new WebSocket(import.meta.env.VITE_DAEMON_SOCKET);
|
||||
|
||||
daemonSocket.onopen = () => {
|
||||
@@ -127,6 +138,7 @@ const store = createStore({
|
||||
|
||||
daemonSocket.onerror = (error) => {
|
||||
console.error('Daemon WebSocket error:', error);
|
||||
console.log('WebSocket readyState:', daemonSocket.readyState);
|
||||
retryConnection(connectDaemonSocket);
|
||||
};
|
||||
|
||||
@@ -134,7 +146,6 @@ const store = createStore({
|
||||
const message = event.data;
|
||||
console.log(message);
|
||||
if (message === "ping") {
|
||||
console.log("Ping received, sending Pong...");
|
||||
daemonSocket.send("pong");
|
||||
} else {
|
||||
try {
|
||||
|
||||
9
frontend/src/utils/knowledgeHelper.js
Normal file
9
frontend/src/utils/knowledgeHelper.js
Normal file
@@ -0,0 +1,9 @@
|
||||
export function mapKnowledgeToText(value, t) {
|
||||
if (value >= 90) return t('falukant.skillKnowledges.excelent');
|
||||
if (value >= 75) return t('falukant.skillKnowledges.veryhigh');
|
||||
if (value >= 60) return t('falukant.skillKnowledges.high');
|
||||
if (value >= 45) return t('falukant.skillKnowledges.medium');
|
||||
if (value >= 30) return t('falukant.skillKnowledges.low');
|
||||
if (value >= 15) return t('falukant.skillKnowledges.verylow');
|
||||
return t('falukant.skillKnowledges.none');
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
<template>
|
||||
<div>
|
||||
<div class="contenthidden">
|
||||
<StatusBar />
|
||||
<div class="contentscroll">
|
||||
<h2>{{ $t('falukant.branch.title') }}</h2>
|
||||
|
||||
<!-- Branch Selection Section -->
|
||||
<div class="branch-selection">
|
||||
<h3>{{ $t('falukant.branch.selection.title') }}</h3>
|
||||
<div>
|
||||
@@ -21,16 +20,50 @@
|
||||
<!-- Director Info Section -->
|
||||
<div class="director-info">
|
||||
<h3>{{ $t('falukant.branch.director.title') }}</h3>
|
||||
<p v-if="selectedBranch">
|
||||
{{ $t('falukant.branch.director.info', { branchName: selectedBranch.cityName }) }}
|
||||
<p v-if="selectedBranch && !director">
|
||||
<button @click="openNewDirectorDialog">{{ $t('falukant.branch.director.actions.new') }}</button>
|
||||
</p>
|
||||
<p v-else>{{ $t('falukant.branch.director.noSelection') }}</p>
|
||||
<div v-else-if="selectedBranch && director" class="director-info-container">
|
||||
<div>
|
||||
<table>
|
||||
<tr>
|
||||
<td>{{ $t('falukant.branch.director.name') }}</td>
|
||||
<td>{{ $t('falukant.titles.' + director.director.character.gender + '.' + director.director.character.title) }} {{ director.director.character.name }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ $t('falukant.branch.director.salary') }}</td>
|
||||
<td>{{ director.director.income }}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>{{ $t('falukant.branch.director.satisfaction') }}</td>
|
||||
<td>{{ director.director.satisfaction }} %</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
<div>
|
||||
<table>
|
||||
<tr>
|
||||
<td><button>{{ $t('falukant.branch.director.fire') }}</button></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><button>{{ $t('falukant.branch.director.teach') }}</button></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label><input type="checkbox" v-model="director.director.mayProduce">{{ $t('falukant.branch.director.produce') }}</label></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label><input type="checkbox" v-model="director.director.maySell">{{ $t('falukant.branch.director.sell') }}</label></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label><input type="checkbox" v-model="director.director.mayStartTransport">{{ $t('falukant.branch.director.starttransport') }}</label></td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Sale Section -->
|
||||
<div class="sale-section">
|
||||
<h3>{{ $t('falukant.branch.sale.title') }}</h3>
|
||||
<p>{{ $t('falukant.branch.sale.info') }}</p>
|
||||
<div class="inventory-table" v-if="inventory.length > 0">
|
||||
<table>
|
||||
<thead>
|
||||
@@ -45,15 +78,19 @@
|
||||
<tbody>
|
||||
<tr v-for="(item, index) in inventory"
|
||||
:key="`${item.region.id}-${item.product.id}-${item.quality}`">
|
||||
<td>{{ item.region.name }} ({{ $t(`falukant.regionType.${item.region.regionType.labelTr}`)
|
||||
}})</td>
|
||||
<td>
|
||||
{{ item.region.name }}
|
||||
({{ $t(`falukant.regionType.${item.region.regionType.labelTr}`) }})
|
||||
</td>
|
||||
<td>{{ $t(`falukant.product.${item.product.labelTr}`) }}</td>
|
||||
<td>{{ item.quality }}</td>
|
||||
<td>{{ item.totalQuantity }}</td>
|
||||
<td>
|
||||
<input type="number" v-model.number="item.sellQuantity" :min="1"
|
||||
:max="item.totalQuantity" :placeholder="item.totalQuantity" />
|
||||
<button @click="sellItem(index)">{{ $t('falukant.branch.sale.sellButton') }}</button>
|
||||
<button @click="sellItem(index)">
|
||||
{{ $t('falukant.branch.sale.sellButton') }}
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
@@ -65,10 +102,10 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Production Section -->
|
||||
<div class="production-section" v-if="['fullstack', 'production'].includes(branchData?.branchType?.labelTr)">
|
||||
<div class="production-section"
|
||||
v-if="['fullstack', 'production'].includes(branchData?.branchType?.labelTr)">
|
||||
<h3>{{ $t('falukant.branch.production.title') }}</h3>
|
||||
<div v-if="this.productions?.length > 0">
|
||||
<div v-if="productions?.length > 0">
|
||||
<h4>{{ $t('falukant.branch.production.current') }}</h4>
|
||||
<table>
|
||||
<thead>
|
||||
@@ -81,17 +118,31 @@
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="production in productions" :key="production.id">
|
||||
<td>{{ $t(`falukant.product.${production.productType.labelTr}`) }}</td>
|
||||
<td>
|
||||
{{ $t(`falukant.product.${production.productType.labelTr}`) }}
|
||||
</td>
|
||||
<td>{{ production.quantity }}</td>
|
||||
<td>{{ calculateEndDateTime(production.startTimestamp,
|
||||
production.productType.productionTime) }}</td>
|
||||
<td>{{ calculateRemainingTime(production.startTimestamp,
|
||||
production.productType.productionTime) }}</td>
|
||||
<td>
|
||||
{{
|
||||
calculateEndDateTime(
|
||||
production.startTimestamp,
|
||||
production.productType.productionTime
|
||||
)
|
||||
}}
|
||||
</td>
|
||||
<td>
|
||||
{{
|
||||
calculateRemainingTime(
|
||||
production.startTimestamp,
|
||||
production.productType.productionTime
|
||||
)
|
||||
}}
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<template v-if="!this.productions || this.productions.length < 2">
|
||||
<template v-if="!productions || productions.length < 2">
|
||||
<div>
|
||||
<label for="product">{{ $t('falukant.branch.production.selectProduct') }}</label>
|
||||
<select name="product" id="product" v-model="selectedProduct">
|
||||
@@ -111,7 +162,7 @@
|
||||
</p>
|
||||
<p>
|
||||
{{ $t('falukant.branch.production.duration') }}:
|
||||
<strong>{{ calculateProductionDuration(selectedProduct?.id) }}</strong>
|
||||
<strong>{{ calculateProductionDuration(selectedProduct?? 0) }}</strong>
|
||||
</p>
|
||||
<p>
|
||||
{{ $t('falukant.branch.production.revenue') }}:
|
||||
@@ -124,6 +175,85 @@
|
||||
</template>
|
||||
</div>
|
||||
|
||||
<div class="storage-section" v-if="branchData">
|
||||
<h3>{{ $t('falukant.branch.storage.title') }}</h3>
|
||||
<div class="storage-info">
|
||||
<p>
|
||||
{{ $t('falukant.branch.storage.currentCapacity') }}:
|
||||
<strong>{{ currentStorage }} / {{ maxStorage }}</strong>
|
||||
</p>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ $t('falukant.branch.storage.stockType') }}</th>
|
||||
<th>{{ $t('falukant.branch.storage.totalCapacity') }}</th>
|
||||
<th>{{ $t('falukant.branch.storage.used') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(usage, idx) in storageUsage" :key="idx">
|
||||
<td>
|
||||
{{ $t(`falukant.branch.stocktype.${usage.stockTypeLabelTr}`) }}
|
||||
</td>
|
||||
<td>{{ usage.totalCapacity }}</td>
|
||||
<td>{{ usage.used }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<h4>{{ $t('falukant.branch.storage.availableToBuy') }}</h4>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ $t('falukant.branch.storage.stockType') }}</th>
|
||||
<th>{{ $t('falukant.branch.storage.totalCapacity') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(buyable, i) in buyableUsage" :key="i">
|
||||
<td>
|
||||
{{ $t(`falukant.branch.stocktype.${buyable.stockTypeLabelTr}`) }}
|
||||
</td>
|
||||
<td>{{ buyable.quantity }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="storage-market">
|
||||
<div class="buy-section">
|
||||
<label>{{ $t('falukant.branch.storage.selectStockType') }}</label>
|
||||
<select v-model="selectedBuyStockTypeId">
|
||||
<option v-for="type in buyableUsage" :key="type.stockTypeId" :value="type.stockTypeId">
|
||||
{{ $t(`falukant.branch.stocktype.${type.stockTypeLabelTr}`) }} - {{ getCostOfType(type.stockTypeId) }}
|
||||
</option>
|
||||
</select>
|
||||
<div>
|
||||
<label>{{ $t('falukant.branch.storage.buyAmount') }}</label>
|
||||
<input type="number" v-model.number="buyStorageAmount" :max="maxBuyableForSelectedBuy"
|
||||
min="1" />
|
||||
<button @click="onBuyStorage">
|
||||
{{ $t('falukant.branch.storage.buyStorageButton') }} ({{ buyCost }})
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="sell-section">
|
||||
<label>{{ $t('falukant.branch.storage.selectStockType') }}</label>
|
||||
<select v-model="selectedSellStockTypeId">
|
||||
<option v-for="type in storageUsage" :key="type.stockTypeId" :value="type.stockTypeId">
|
||||
{{ $t(`falukant.branch.stocktype.${type.stockTypeLabelTr}`) }} - {{ getCostOfType(type.stockTypeId) }}
|
||||
</option>
|
||||
</select>
|
||||
<div>
|
||||
<label>{{ $t('falukant.branch.storage.sellAmount') }}</label>
|
||||
<input type="number" v-model.number="sellStorageAmount" :max="maxSellableForSelectedSell"
|
||||
min="1" />
|
||||
<button @click="onSellStorage">
|
||||
{{ $t('falukant.branch.storage.sellStorageButton') }} ({{ sellIncome }})
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="revenue-section">
|
||||
<h3>
|
||||
<button @click="toggleRevenueTable">
|
||||
@@ -139,22 +269,29 @@
|
||||
<th>{{ $t('falukant.branch.revenue.knowledge') }}</th>
|
||||
<th>{{ $t('falukant.branch.revenue.absolute') }}</th>
|
||||
<th>{{ $t('falukant.branch.revenue.perMinute') }}</th>
|
||||
<th>{{ $t('falukant.branch.revenue.profitAbsolute') }}</th>
|
||||
<th>{{ $t('falukant.branch.revenue.profitPerMinute') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="product in products" :key="product.id">
|
||||
<tr v-for="product in products" :key="product.id"
|
||||
:class="{ highlight: product.id === productWithMaxRevenuePerMinute?.id }">
|
||||
<td>{{ $t(`falukant.product.${product.labelTr}`) }}</td>
|
||||
<td>{{ product.knowledges[0]?.knowledge }} %</td>
|
||||
<td>{{ mapKnowledgeToText(product.knowledges[0]?.knowledge) }}</td>
|
||||
<td>{{ calculateProductRevenue(product).absolute }}</td>
|
||||
<td>{{ calculateProductRevenue(product).perMinute }}</td>
|
||||
<td>{{ calculateProductProfit(product).absolute }}</td>
|
||||
<td>{{ calculateProductProfit(product).perMinute }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<MessageDialog ref="messageDialog" />
|
||||
<ErrorDialog ref="errorDialog" />
|
||||
<FalukantNewDirector ref="newDirectorDialog" />
|
||||
</template>
|
||||
|
||||
<script>
|
||||
@@ -163,7 +300,9 @@ import FormattedDropdown from '@/components/form/FormattedDropdown.vue';
|
||||
import apiClient from '@/utils/axios.js';
|
||||
import MessageDialog from '@/dialogues/standard/MessageDialog.vue';
|
||||
import ErrorDialog from '@/dialogues/standard/ErrorDialog.vue';
|
||||
import FalukantNewDirector from '@/dialogues/falukant/NewDirectorDialog.vue';
|
||||
import { mapState } from "vuex";
|
||||
import { mapKnowledgeToText } from '@/utils/knowledgeHelper.js';
|
||||
|
||||
export default {
|
||||
name: "BranchView",
|
||||
@@ -172,9 +311,47 @@ export default {
|
||||
FormattedDropdown,
|
||||
MessageDialog,
|
||||
ErrorDialog,
|
||||
FalukantNewDirector
|
||||
},
|
||||
computed: {
|
||||
...mapState(["socket", "daemonSocket"]),
|
||||
storageFreePortion() {
|
||||
return Math.max(this.maxStorage - this.currentStorage, 0);
|
||||
},
|
||||
buyCost() {
|
||||
const st = this.stockTypes.find(s => s.id === this.selectedStockTypeId);
|
||||
const cost = st ? st.cost : 0;
|
||||
return this.buyStorageAmount * cost;
|
||||
},
|
||||
sellIncome() {
|
||||
const st = this.stockTypes.find(s => s.id === this.selectedStockTypeId);
|
||||
const cost = st ? st.cost : 0;
|
||||
return this.sellStorageAmount * cost;
|
||||
},
|
||||
maxSellableForSelectedSell() {
|
||||
const usage = this.storageUsage.find(
|
||||
(u) => u.stockTypeId === this.selectedSellStockTypeId
|
||||
);
|
||||
return usage ? usage.totalCapacity : 0;
|
||||
},
|
||||
maxBuyableForSelectedBuy() {
|
||||
const buyable = this.buyableUsage.find(
|
||||
b => b.stockTypeId === this.selectedBuyStockTypeId
|
||||
);
|
||||
return buyable ? buyable.quantity : 0;
|
||||
},
|
||||
productWithMaxRevenuePerMinute() {
|
||||
if (!this.products || this.products.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return this.products.reduce((maxProduct, currentProduct) => {
|
||||
const currentRevenue = parseFloat(this.calculateProductRevenue(currentProduct).perMinute);
|
||||
const maxRevenue = maxProduct ? parseFloat(this.calculateProductRevenue(maxProduct).perMinute) : 0;
|
||||
|
||||
return currentRevenue > maxRevenue ? currentProduct : maxProduct;
|
||||
}, null);
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
@@ -186,12 +363,28 @@ export default {
|
||||
],
|
||||
products: [],
|
||||
branchData: null,
|
||||
productions: [],
|
||||
selectedProduct: null,
|
||||
productionQuantity: 1,
|
||||
isRevenueTableOpen: false,
|
||||
inventory: [],
|
||||
currentTime: Date.now(),
|
||||
timer: null,
|
||||
currentStorage: 0,
|
||||
maxStorage: 0,
|
||||
storageUsage: [],
|
||||
availableStorageToBuy: 0,
|
||||
buyStorageAmount: 0,
|
||||
sellStorageAmount: 0,
|
||||
stockTypes: [],
|
||||
selectedStockTypeId: 0,
|
||||
selectedBuyStockTypeId: null,
|
||||
selectedSellStockTypeId: null,
|
||||
buyableUsage: [],
|
||||
director: null,
|
||||
directorMayProduce: false,
|
||||
directorMaySell: false,
|
||||
directorMayStartTransport: false,
|
||||
};
|
||||
},
|
||||
async mounted() {
|
||||
@@ -199,7 +392,6 @@ export default {
|
||||
const branchId = this.$route.params.branchId;
|
||||
const products = await apiClient.get('/api/falukant/products');
|
||||
this.products = products.data;
|
||||
console.log('products loaded');
|
||||
if (branchId) {
|
||||
this.selectedBranch = this.branches.find(branch => branch.id === parseInt(branchId)) || null;
|
||||
} else {
|
||||
@@ -207,6 +399,8 @@ export default {
|
||||
}
|
||||
if (this.socket) {
|
||||
this.socket.on("falukantBranchUpdate", this.fetchBranch);
|
||||
this.socket.on("stock_change", this.stockChange);
|
||||
this.socket.on("directorchanged", this.loadDirector);
|
||||
}
|
||||
if (this.daemonSocket) {
|
||||
this.daemonSocket.addEventListener('message', (event) => {
|
||||
@@ -215,11 +409,12 @@ export default {
|
||||
return;
|
||||
}
|
||||
const message = JSON.parse(event.data);
|
||||
console.log('Daemon WebSocket message received in BranchView:', message);
|
||||
|
||||
if (message.event === 'production_ready' && message.branch_id === this.selectedBranch?.id) {
|
||||
this.handleProductionReadyEvent(message);
|
||||
}
|
||||
if (message.event === 'stock_change' && message.branch_id === this.selectedBranch?.id) {
|
||||
this.stockChange();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error processing WebSocket message in BranchView:', error);
|
||||
}
|
||||
@@ -227,6 +422,7 @@ export default {
|
||||
} else {
|
||||
console.error('Daemon socket is not initialized.');
|
||||
}
|
||||
this.mountedLogic();
|
||||
this.startTimer();
|
||||
},
|
||||
beforeUnmount() {
|
||||
@@ -239,11 +435,35 @@ export default {
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
|
||||
async selectedBranch(newBranch) {
|
||||
await this.loadBranchData(newBranch);
|
||||
}
|
||||
await this.loadDirector();
|
||||
},
|
||||
'director.director.mayProduce': {
|
||||
handler(newValue) {
|
||||
this.saveDirectorSettings('mayProduce', newValue);
|
||||
},
|
||||
deep: true,
|
||||
},
|
||||
'director.director.maySell': {
|
||||
handler(newValue) {
|
||||
this.saveDirectorSettings('maySell', newValue);
|
||||
},
|
||||
deep: true,
|
||||
},
|
||||
'director.director.mayStartTransport': {
|
||||
handler(newValue) {
|
||||
this.saveDirectorSettings('mayStartTransport', newValue);
|
||||
},
|
||||
deep: true,
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
mapKnowledgeToText(value) {
|
||||
return mapKnowledgeToText(value, this.$t);
|
||||
},
|
||||
|
||||
async loadBranches() {
|
||||
try {
|
||||
const branchesResult = await apiClient.get('/api/falukant/branches');
|
||||
@@ -260,21 +480,26 @@ export default {
|
||||
console.error('Error loading branches:', error);
|
||||
}
|
||||
},
|
||||
|
||||
async loadBranchData(newBranch) {
|
||||
if (newBranch) {
|
||||
this.getBranchData(newBranch);
|
||||
await this.loadInventory();
|
||||
this.loadStorageData();
|
||||
}
|
||||
},
|
||||
|
||||
selectMainBranch() {
|
||||
const main = this.branches.find(b => b.isMainBranch) || null;
|
||||
if (main !== this.selectedBranch) {
|
||||
this.selectedBranch = main;
|
||||
}
|
||||
},
|
||||
|
||||
createBranch() {
|
||||
alert(this.$t('falukant.branch.actions.createAlert'));
|
||||
},
|
||||
|
||||
upgradeBranch() {
|
||||
if (this.selectedBranch) {
|
||||
alert(
|
||||
@@ -282,16 +507,18 @@ export default {
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
calculateProductionCost() {
|
||||
if (!this.products) {
|
||||
return 0;
|
||||
}
|
||||
const product = this.products.find(p => p.id === this.selectedProduct);
|
||||
if (product) {
|
||||
return 7 * product.category * this.productionQuantity;
|
||||
return 6 * product.category * this.productionQuantity;
|
||||
}
|
||||
return 0;
|
||||
},
|
||||
|
||||
calculateProductionDuration(productId) {
|
||||
if (!this.products || !productId) {
|
||||
return 0;
|
||||
@@ -300,12 +527,11 @@ export default {
|
||||
if (!product) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const totalMinutes = product.productionTime * 60;
|
||||
const decimalTime = (totalMinutes / 60).toFixed(2);
|
||||
|
||||
return decimalTime;
|
||||
},
|
||||
|
||||
async startProduction() {
|
||||
if (this.selectedBranch && this.selectedProduct && this.productionQuantity > 0) {
|
||||
try {
|
||||
@@ -316,10 +542,13 @@ export default {
|
||||
});
|
||||
this.$root.$refs.messageDialog.open(this.$t('falukant.branch.production.success'));
|
||||
} catch (error) {
|
||||
this.$root.$refs.errorDialog.open(this.$t(`falukant.branch.production.error${error.response.data.error}`));
|
||||
this.$root.$refs.errorDialog.open(
|
||||
this.$t(`falukant.branch.production.error${error.response.data.error}`)
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
calculateProductionRevenue() {
|
||||
if (!this.selectedProduct) {
|
||||
return 0;
|
||||
@@ -328,30 +557,19 @@ export default {
|
||||
return 0;
|
||||
}
|
||||
const product = this.products.find(p => p.id === this.selectedProduct);
|
||||
console.log(product);
|
||||
if (!product) {
|
||||
return 0;
|
||||
}
|
||||
const productRevenue = this.calculateProductRevenue(product);
|
||||
return productRevenue.absolute;
|
||||
|
||||
const productRevenue = this.calculateProductRevenue(product).absolute * this.productionQuantity;
|
||||
return productRevenue;
|
||||
},
|
||||
|
||||
toggleRevenueTable() {
|
||||
this.isRevenueTableOpen = !this.isRevenueTableOpen;
|
||||
},
|
||||
calculateProductRevenue(product) {
|
||||
if (!product.knowledges || product.knowledges.length === 0) {
|
||||
return { absolute: 0, perMinute: 0 };
|
||||
}
|
||||
const knowledgeFactor = product.knowledges[0]?.knowledge || 0;
|
||||
const maxPrice = product.category * 9;
|
||||
const minPrice = maxPrice * 0.6;
|
||||
const revenuePerUnit = minPrice + (maxPrice - minPrice) * (knowledgeFactor / 100);
|
||||
const productionTimeInMinutes = product.productionTime;
|
||||
const perMinute = (revenuePerUnit / productionTimeInMinutes).toFixed(2);
|
||||
return {
|
||||
absolute: revenuePerUnit.toFixed(2),
|
||||
perMinute: perMinute,
|
||||
};
|
||||
},
|
||||
|
||||
async fetchBranch(data) {
|
||||
try {
|
||||
if (data.branchId === this.selectedBranch.id) {
|
||||
@@ -361,82 +579,242 @@ export default {
|
||||
console.error(error);
|
||||
}
|
||||
},
|
||||
|
||||
async getBranchData(newBranch = null) {
|
||||
try {
|
||||
const response = await apiClient.get(`/api/falukant/branches/${newBranch ? newBranch.id : this.selectedBranch.id}`);
|
||||
const response = await apiClient.get(
|
||||
`/api/falukant/branches/${newBranch ? newBranch.id : this.selectedBranch.id}`
|
||||
);
|
||||
this.branchData = response.data;
|
||||
this.director = response.data.director;
|
||||
this.productions = response.data.productions.sort((a, b) => {
|
||||
const endTimeA = new Date(a.startTimestamp).getTime() + a.productType.productionTime * 60 * 1000;
|
||||
const endTimeB = new Date(b.startTimestamp).getTime() + b.productType.productionTime * 60 * 1000;
|
||||
const endTimeA =
|
||||
new Date(a.startTimestamp).getTime() + a.productType.productionTime * 60 * 1000;
|
||||
const endTimeB =
|
||||
new Date(b.startTimestamp).getTime() + b.productType.productionTime * 60 * 1000;
|
||||
return endTimeA - endTimeB;
|
||||
});
|
||||
this.loadInventory();
|
||||
this.loadStorageData();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
},
|
||||
|
||||
calculateEndDateTime(startTimestamp, productionTime) {
|
||||
const startTime = new Date(startTimestamp);
|
||||
const endTime = new Date(startTime.getTime() + productionTime * 60 * 1000);
|
||||
return endTime.toLocaleString(); // Datum und Uhrzeit
|
||||
return endTime.toLocaleString();
|
||||
},
|
||||
|
||||
calculateRemainingTime(startTimestamp, productionTime) {
|
||||
const startTime = new Date(startTimestamp).getTime();
|
||||
const endTime = startTime + productionTime * 60 * 1000;
|
||||
const now = Date.now();
|
||||
const remainingSeconds = Math.max(Math.floor((endTime - now) / 1000), 0);
|
||||
return remainingSeconds; // Verbleibende Zeit in Sekunden
|
||||
return remainingSeconds;
|
||||
},
|
||||
|
||||
startTimer() {
|
||||
this.timer = setInterval(() => {
|
||||
this.$forceUpdate(); // Aktualisiert die verbleibende Zeit in der Tabelle
|
||||
this.$forceUpdate();
|
||||
}, 1000);
|
||||
},
|
||||
|
||||
stopTimer() {
|
||||
if (this.timer) {
|
||||
clearInterval(this.timer);
|
||||
this.timer = null;
|
||||
}
|
||||
},
|
||||
|
||||
sellItem(index) {
|
||||
try {
|
||||
const item = this.inventory[index];
|
||||
console.log(`Selling ${item.sellQuantity || item.totalQuantity} of ${item.product.labelTr}`);
|
||||
const quantityToSell = item.sellQuantity || item.totalQuantity;
|
||||
item.totalQuantity -= quantityToSell;
|
||||
if (item.totalQuantity <= 0) {
|
||||
this.inventory.splice(index, 1);
|
||||
}
|
||||
item.sellQuantity = null;
|
||||
},
|
||||
sellAll() {
|
||||
console.log('Selling all items in inventory');
|
||||
this.inventory.forEach(item => {
|
||||
console.log(`Selling ${item.totalQuantity} of ${item.product.labelTr}`);
|
||||
apiClient.post(`/api/falukant/sell`, {
|
||||
branchId: this.selectedBranch.id,
|
||||
productId: item.product.id,
|
||||
quantity: quantityToSell,
|
||||
quality: item.quality,
|
||||
});
|
||||
this.inventory = []; // Leert das Inventar
|
||||
} catch (error) {
|
||||
this.$refs.errorDialog.open(this.$t('falukant.branch.sale.sellError'));
|
||||
}
|
||||
},
|
||||
|
||||
sellAll() {
|
||||
try {
|
||||
apiClient.post(`/api/falukant/sell/all`, {
|
||||
branchId: this.selectedBranch.id,
|
||||
});
|
||||
} catch (error) {
|
||||
this.$refs.errorDialog.open(this.$t('falukant.branch.sale.sellAllError'));
|
||||
}
|
||||
},
|
||||
|
||||
async loadInventory() {
|
||||
try {
|
||||
const response = await apiClient.get(`/api/falukant/inventory/${this.selectedBranch?.id}`, {});
|
||||
const response = await apiClient.get(`/api/falukant/inventory/${this.selectedBranch?.id}`);
|
||||
this.inventory = response.data.map(item => ({
|
||||
...item,
|
||||
sellQuantity: item.totalQuantity, // Voreinstellung
|
||||
sellQuantity: item.totalQuantity,
|
||||
}));
|
||||
} catch (error) {
|
||||
console.error('Error loading inventory:', error);
|
||||
this.$refs.errorDialog.open(this.$t('falukant.branch.sale.loadError'));
|
||||
}
|
||||
},
|
||||
|
||||
async handleProductionReadyEvent(message) {
|
||||
try {
|
||||
console.log('Production ready event received:', message);
|
||||
if (message.branch_id === this.selectedBranch?.id) {
|
||||
await this.loadBranchData(this.selectedBranch);
|
||||
await this.loadInventory();
|
||||
this.loadStorageData();
|
||||
this.stockChange();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error processing production_ready event:', error);
|
||||
console.error(message);
|
||||
}
|
||||
},
|
||||
|
||||
calculateProductRevenue(product) {
|
||||
if (!product.knowledges || product.knowledges.length === 0) {
|
||||
return { absolute: 0, perMinute: 0 };
|
||||
}
|
||||
const knowledgeFactor = product.knowledges[0]?.knowledge || 0;
|
||||
const maxPrice = product.sellCost;
|
||||
const minPrice = maxPrice * 0.6;
|
||||
const revenuePerUnit = minPrice + (maxPrice - minPrice) * (knowledgeFactor / 100);
|
||||
const productionTimeInMinutes = product.productionTime;
|
||||
const perMinute = productionTimeInMinutes > 0
|
||||
? revenuePerUnit / productionTimeInMinutes
|
||||
: 0;
|
||||
return {
|
||||
absolute: revenuePerUnit.toFixed(2),
|
||||
perMinute: perMinute.toFixed(2),
|
||||
};
|
||||
},
|
||||
|
||||
calculateProductProfit(product) {
|
||||
const { absolute: revenueAbsoluteStr, perMinute: revenuePerMinuteStr } =
|
||||
this.calculateProductRevenue(product);
|
||||
const revenueAbsolute = parseFloat(revenueAbsoluteStr);
|
||||
const revenuePerMinute = parseFloat(revenuePerMinuteStr);
|
||||
const costPerUnit = 6 * product.category;
|
||||
const profitAbsolute = revenueAbsolute - costPerUnit;
|
||||
const productionTimeInMinutes = product.productionTime;
|
||||
const costPerMinute = productionTimeInMinutes > 0 ? costPerUnit / productionTimeInMinutes : 0;
|
||||
const profitPerMinute = revenuePerMinute - costPerMinute;
|
||||
return {
|
||||
absolute: profitAbsolute.toFixed(2),
|
||||
perMinute: profitPerMinute.toFixed(2),
|
||||
};
|
||||
},
|
||||
|
||||
async loadStorageData(branchId) {
|
||||
if (!branchId) return;
|
||||
try {
|
||||
const { data } = await apiClient.get(`/api/falukant/storage/${branchId}`);
|
||||
this.currentStorage = data.totalUsedCapacity;
|
||||
this.maxStorage = data.maxCapacity;
|
||||
this.storageUsage = data.usageByType;
|
||||
this.buyableUsage = data.buyableByType;
|
||||
} catch (error) {
|
||||
console.error('Error loading storage data:', error);
|
||||
}
|
||||
},
|
||||
|
||||
async loadStockTypes() {
|
||||
try {
|
||||
const response = await apiClient.get('/api/falukant/stocktypes');
|
||||
this.stockTypes = response.data;
|
||||
if (this.stockTypes.length) {
|
||||
this.selectedStockTypeId = this.stockTypes[0].id;
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error loading stock types:', error);
|
||||
}
|
||||
},
|
||||
|
||||
onBuyStorage() {
|
||||
if (!this.selectedBranch || !this.buyStorageAmount || !this.selectedStockTypeId) return;
|
||||
apiClient.post(`/api/falukant/storage`, {
|
||||
branchId: this.selectedBranch.id,
|
||||
amount: this.buyStorageAmount,
|
||||
stockTypeId: this.selectedStockTypeId
|
||||
})
|
||||
.then(() => this.loadStorageData(this.selectedBranch.id))
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
this.$refs.errorDialog.open('Error buying storage');
|
||||
});
|
||||
},
|
||||
|
||||
onSellStorage() {
|
||||
if (!this.selectedBranch || !this.sellStorageAmount || !this.selectedStockTypeId) return;
|
||||
apiClient.delete(`/api/falukant/storage`, {
|
||||
data: {
|
||||
branchId: this.selectedBranch.id,
|
||||
amount: this.sellStorageAmount,
|
||||
stockTypeId: this.selectedStockTypeId
|
||||
}
|
||||
})
|
||||
.then(() => this.loadStorageData(this.selectedBranch.id))
|
||||
.catch(err => {
|
||||
console.error(err);
|
||||
this.$refs.errorDialog.open('Error selling storage');
|
||||
});
|
||||
},
|
||||
|
||||
async mountedLogic() {
|
||||
if (this.selectedBranch) {
|
||||
await this.loadStorageData(this.selectedBranch.id);
|
||||
await this.loadDirector();
|
||||
}
|
||||
await this.loadStockTypes();
|
||||
},
|
||||
|
||||
async stockChange(params = null) {
|
||||
if (params !== null && params.branchId !== this.selectedBranch.id) {
|
||||
return;
|
||||
}
|
||||
if (this.selectedBranch) {
|
||||
await this.loadStorageData(this.selectedBranch.id);
|
||||
}
|
||||
await this.loadStockTypes();
|
||||
},
|
||||
|
||||
getCostOfType(stockTypeId) {
|
||||
const st = this.stockTypes.find(s => s.id === stockTypeId);
|
||||
return st ? st.cost : 0;
|
||||
},
|
||||
|
||||
openNewDirectorDialog() {
|
||||
this.$refs.newDirectorDialog.open(this.selectedBranch.id);
|
||||
},
|
||||
|
||||
async loadDirector() {
|
||||
if (!this.selectedBranch) {
|
||||
return;
|
||||
}
|
||||
const response = await apiClient.get(`/api/falukant/director/${this.selectedBranch.id}`);
|
||||
this.director = response.data;
|
||||
},
|
||||
|
||||
async saveDirectorSettings(settingKey, value) {
|
||||
if (!this.director || !this.director.director) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await apiClient.post(`/api/falukant/director/settings`, {
|
||||
branchId: this.selectedBranch.id,
|
||||
directorId: this.director.director.id,
|
||||
settingKey,
|
||||
value,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error(`Error saving director setting ${settingKey}:`, error);
|
||||
this.$refs.errorDialog.open(this.$t('falukant.branch.director.settingsError'));
|
||||
}
|
||||
},
|
||||
},
|
||||
@@ -447,7 +825,8 @@ export default {
|
||||
.branch-selection,
|
||||
.director-info,
|
||||
.sale-section,
|
||||
.production-section {
|
||||
.production-section,
|
||||
.storage-section {
|
||||
border: 1px solid #ccc;
|
||||
margin: 10px 0;
|
||||
border-radius: 4px;
|
||||
@@ -563,4 +942,21 @@ button {
|
||||
.inventory-table th {
|
||||
background-color: #f2f2f2;
|
||||
}
|
||||
|
||||
.storage-section .storage-market {
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
||||
.highlight {
|
||||
background-color: #dfffd6; /* Helles Hellgrün */
|
||||
}
|
||||
|
||||
.director-info-container {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.director-info-container > div {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
</style>
|
||||
|
||||
106
frontend/src/views/falukant/MoneyHistoryView.vue
Normal file
106
frontend/src/views/falukant/MoneyHistoryView.vue
Normal file
@@ -0,0 +1,106 @@
|
||||
<template>
|
||||
<div>
|
||||
<h2>{{ $t('falukant.moneyHistory.title') }}</h2>
|
||||
|
||||
<div class="filter-section">
|
||||
<label>{{ $t('falukant.moneyHistory.filter') }}</label>
|
||||
<input v-model="filter" type="text" />
|
||||
<button @click="fetchMoneyHistory(1)">{{ $t('falukant.moneyHistory.search') }}</button>
|
||||
</div>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ $t('falukant.moneyHistory.activity') }}</th>
|
||||
<th>{{ $t('falukant.moneyHistory.moneyBefore') }}</th>
|
||||
<th>{{ $t('falukant.moneyHistory.moneyAfter') }}</th>
|
||||
<th>{{ $t('falukant.moneyHistory.changeValue') }}</th>
|
||||
<th>{{ $t('falukant.moneyHistory.time') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(entry, index) in moneyHistory.data" :key="index">
|
||||
<td>{{ $t(`falukant.moneyHistory.activities.${entry.activity}`) }}</td>
|
||||
<td>{{ entry.moneyBefore }}</td>
|
||||
<td>{{ entry.moneyAfter }}</td>
|
||||
<td>{{ entry.changeValue }}</td>
|
||||
<td>{{ new Date(entry.time).toLocaleString() }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<div class="pagination">
|
||||
<button
|
||||
v-if="moneyHistory.currentPage > 1"
|
||||
@click="fetchMoneyHistory(moneyHistory.currentPage - 1)"
|
||||
>
|
||||
{{ $t('falukant.moneyHistory.prev') }}
|
||||
</button>
|
||||
<span>
|
||||
{{ moneyHistory.currentPage }} / {{ moneyHistory.totalPages }}
|
||||
</span>
|
||||
<button
|
||||
v-if="moneyHistory.currentPage < moneyHistory.totalPages"
|
||||
@click="fetchMoneyHistory(moneyHistory.currentPage + 1)"
|
||||
>
|
||||
{{ $t('falukant.moneyHistory.next') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import apiClient from '@/utils/axios.js';
|
||||
|
||||
export default {
|
||||
name: 'MoneyHistoryView',
|
||||
data() {
|
||||
return {
|
||||
filter: '',
|
||||
moneyHistory: {
|
||||
data: [],
|
||||
currentPage: 1,
|
||||
totalPages: 1,
|
||||
},
|
||||
};
|
||||
},
|
||||
async mounted() {
|
||||
await this.fetchMoneyHistory(1);
|
||||
},
|
||||
methods: {
|
||||
async fetchMoneyHistory(page) {
|
||||
try {
|
||||
const response = await apiClient.post('/api/falukant/moneyhistory', {
|
||||
page,
|
||||
filter: this.filter,
|
||||
});
|
||||
this.moneyHistory = response.data;
|
||||
} catch (error) {
|
||||
console.error('Error fetching money history:', error);
|
||||
}
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.filter-section {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
th, td {
|
||||
border: 1px solid #ccc;
|
||||
padding: 8px;
|
||||
text-align: left;
|
||||
}
|
||||
.pagination {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 1rem;
|
||||
}
|
||||
</style>
|
||||
|
||||
@@ -27,16 +27,56 @@
|
||||
</div>
|
||||
<div>
|
||||
<h3>{{ $t('falukant.overview.productions.title') }}</h3>
|
||||
<table v-if="productions.length > 0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ $t('falukant.branch.sale.region') }}</th>
|
||||
<th>{{ $t('falukant.branch.production.product') }}</th>
|
||||
<th>{{ $t('falukant.branch.production.quantity') }}</th>
|
||||
<th>{{ $t('falukant.branch.production.ending') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(production, index) in productions" :key="index">
|
||||
<td>{{ production.cityName }}</td>
|
||||
<td>{{ $t(`falukant.product.${production.productName}`) }}</td>
|
||||
<td>{{ production.quantity }}</td>
|
||||
<td>{{ formatDate(production.endTimestamp) }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p v-else>{{ $t('falukant.branch.production.noProductions') }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<h3>{{ $t('falukant.overview.stock.title') }}</h3>
|
||||
<table v-if="allStock.length > 0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>{{ $t('falukant.branch.sale.region') }}</th>
|
||||
<th>{{ $t('falukant.branch.sale.product') }}</th>
|
||||
<th>{{ $t('falukant.branch.sale.quantity') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="(item, index) in allStock" :key="index">
|
||||
<td>{{ item.regionName }}</td>
|
||||
<td>{{ $t(`falukant.product.${item.productLabelTr}`) }}</td>
|
||||
<td>{{ item.quantity }}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
<p v-else>{{ $t('falukant.branch.sale.noInventory') }}</p>
|
||||
</div>
|
||||
<div>
|
||||
<h3>{{ $t('falukant.overview.branches.title') }}</h3>
|
||||
<table>
|
||||
<tr v-for="branch in falukantUser?.branches">
|
||||
<td><span @click="openBranch(branch.id)" class="link">{{ branch.region.name }}</span></td>
|
||||
<td>{{ $t(`falukant.overview.branches.level.${branch.branchType.labelTr}`) }}</td>
|
||||
<tr v-for="branch in falukantUser?.branches" :key="branch.id">
|
||||
<td>
|
||||
<span @click="openBranch(branch.id)" class="link">{{ branch.region.name }}</span>
|
||||
</td>
|
||||
<td>
|
||||
{{ $t(`falukant.overview.branches.level.${branch.branchType.labelTr}`) }}
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
@@ -48,8 +88,9 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import apiClient from '@/utils/axios.js';
|
||||
import StatusBar from '@/components/falukant/StatusBar.vue';
|
||||
import apiClient from '@/utils/axios.js';
|
||||
import { mapState } from 'vuex';
|
||||
|
||||
const AVATAR_POSITIONS = {
|
||||
male: {
|
||||
@@ -90,26 +131,18 @@ const AVATAR_POSITIONS = {
|
||||
|
||||
export default {
|
||||
name: 'FalukantOverviewView',
|
||||
data() {
|
||||
return {
|
||||
falukantUser: null,
|
||||
};
|
||||
},
|
||||
components: {
|
||||
StatusBar,
|
||||
},
|
||||
async mounted() {
|
||||
await this.fetchFalukantUser();
|
||||
if (this.socket) {
|
||||
this.socket.on("falukantUserUpdated", this.fetchFalukantUser);
|
||||
}
|
||||
},
|
||||
beforeUnmount() {
|
||||
if (this.socket) {
|
||||
this.socket.off("falukantUserUpdated", this.fetchFalukantUser);
|
||||
}
|
||||
data() {
|
||||
return {
|
||||
falukantUser: null,
|
||||
allStock: [],
|
||||
productions: [],
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
...mapState(['daemonSocket']),
|
||||
getAvatarStyle() {
|
||||
if (!this.falukantUser) return {};
|
||||
const { gender, age } = this.falukantUser.character;
|
||||
@@ -128,6 +161,38 @@ export default {
|
||||
};
|
||||
},
|
||||
},
|
||||
async mounted() {
|
||||
await this.fetchFalukantUser();
|
||||
await this.fetchAllStock();
|
||||
await this.fetchProductions();
|
||||
if (this.socket) {
|
||||
this.socket.on("falukantUserUpdated", this.fetchFalukantUser);
|
||||
this.socket.on("production_ready", this.handleProductionReadyEvent);
|
||||
}
|
||||
if (this.daemonSocket) {
|
||||
this.daemonSocket.addEventListener('message', (event) => {
|
||||
console.log('incoming event', event);
|
||||
try {
|
||||
if (event.data === "ping") return;
|
||||
const message = JSON.parse(event.data);
|
||||
if (message.event === 'production_ready') {
|
||||
this.handleProductionReadyEvent(message);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error processing WebSocket message in FalukantOverviewView:', error);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
beforeUnmount() {
|
||||
if (this.socket) {
|
||||
this.socket.off("falukantUserUpdated", this.fetchFalukantUser);
|
||||
this.socket.off("production_ready", this.handleProductionReadyEvent);
|
||||
}
|
||||
if (this.daemonSocket) {
|
||||
this.daemonSocket.onmessage = null;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
getAgeGroup(age) {
|
||||
if (age <= 1) return "0-1";
|
||||
@@ -150,9 +215,41 @@ export default {
|
||||
}
|
||||
this.falukantUser = falukantUser.data;
|
||||
},
|
||||
openBranch(branchId) {
|
||||
this.$router.push({ name: 'BranchView', params: { branchId: branchId } });
|
||||
async fetchAllStock() {
|
||||
const response = await apiClient.get('/api/falukant/stockoverview');
|
||||
const rawData = response.data;
|
||||
const aggregated = {};
|
||||
for (const item of rawData) {
|
||||
const key = `${item.regionName}__${item.productLabelTr}`;
|
||||
if (!aggregated[key]) {
|
||||
aggregated[key] = {
|
||||
regionName: item.regionName,
|
||||
productLabelTr: item.productLabelTr,
|
||||
quantity: 0,
|
||||
};
|
||||
}
|
||||
aggregated[key].quantity += item.quantity;
|
||||
}
|
||||
this.allStock = Object.values(aggregated);
|
||||
},
|
||||
handleProductionReadyEvent() {
|
||||
this.fetchAllStock();
|
||||
this.fetchProductions();
|
||||
},
|
||||
openBranch(branchId) {
|
||||
this.$router.push({ name: 'BranchView', params: { branchId } });
|
||||
},
|
||||
async fetchProductions() {
|
||||
try {
|
||||
const response = await apiClient.get('/api/falukant/productions');
|
||||
this.productions = response.data;
|
||||
} catch (error) {
|
||||
console.error('Error fetching productions:', error);
|
||||
}
|
||||
},
|
||||
formatDate(timestamp) {
|
||||
return new Date(timestamp).toLocaleString();
|
||||
},
|
||||
},
|
||||
};
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user