From 307b54dafc0c756a352416a7a35490bec0d3e77a Mon Sep 17 00:00:00 2001 From: ultrageese Date: Fri, 19 Jun 2026 20:04:14 +1000 Subject: [PATCH] =?UTF-8?q?=D0=B3=D0=BB=D1=83=D0=BF=D1=8B=D0=B9=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=BC=D0=BC=D0=B8=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- code/database.sql | 478 +++++++++++++++++++++++++++++++++++++++++++++ code/src/app.rs | 71 +++++-- code/src/models.rs | 4 +- 3 files changed, 534 insertions(+), 19 deletions(-) create mode 100644 code/database.sql diff --git a/code/database.sql b/code/database.sql new file mode 100644 index 0000000..8c656a5 --- /dev/null +++ b/code/database.sql @@ -0,0 +1,478 @@ +/*M!999999\- enable the sandbox mode */ +-- MariaDB dump 10.19-11.8.8-MariaDB, for Linux (x86_64) +-- +-- Host: localhost Database: Brewery +-- ------------------------------------------------------ +-- Server version 11.8.8-MariaDB-alt1 + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8mb4 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*M!100616 SET @OLD_NOTE_VERBOSITY=@@NOTE_VERBOSITY, NOTE_VERBOSITY=0 */; + +-- +-- Table structure for table `client` +-- + +DROP TABLE IF EXISTS `client`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8mb4 */; +CREATE TABLE `client` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + `address` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `client` +-- + +SET @OLD_AUTOCOMMIT=@@AUTOCOMMIT, @@AUTOCOMMIT=0; +LOCK TABLES `client` WRITE; +/*!40000 ALTER TABLE `client` DISABLE KEYS */; +/*!40000 ALTER TABLE `client` ENABLE KEYS */; +UNLOCK TABLES; +COMMIT; +SET AUTOCOMMIT=@OLD_AUTOCOMMIT; + +-- +-- Table structure for table `equipment` +-- + +DROP TABLE IF EXISTS `equipment`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8mb4 */; +CREATE TABLE `equipment` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `inv_number` varchar(20) DEFAULT NULL, + `maintenance_date` datetime DEFAULT NULL, + `worker_id` int(11) DEFAULT NULL, + `name` varchar(100) DEFAULT NULL, + `is_written_off` tinyint(1) NOT NULL DEFAULT 0, + PRIMARY KEY (`id`), + KEY `fk_worker1` (`worker_id`), + CONSTRAINT `fk_worker1` FOREIGN KEY (`worker_id`) REFERENCES `worker` (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `equipment` +-- + +SET @OLD_AUTOCOMMIT=@@AUTOCOMMIT, @@AUTOCOMMIT=0; +LOCK TABLES `equipment` WRITE; +/*!40000 ALTER TABLE `equipment` DISABLE KEYS */; +INSERT INTO `equipment` VALUES +(1,'М-1','1970-01-01 00:00:00',1,'Метла деревяная',0), +(2,'М-2','1970-01-01 00:00:00',2,'Метла деревяная',0); +/*!40000 ALTER TABLE `equipment` ENABLE KEYS */; +UNLOCK TABLES; +COMMIT; +SET AUTOCOMMIT=@OLD_AUTOCOMMIT; + +-- +-- Table structure for table `material` +-- + +DROP TABLE IF EXISTS `material`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8mb4 */; +CREATE TABLE `material` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + `quantity` int(11) DEFAULT NULL, + `category_id` int(11) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `fk_material_category` (`category_id`), + CONSTRAINT `fk_material_category` FOREIGN KEY (`category_id`) REFERENCES `material_category` (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `material` +-- + +SET @OLD_AUTOCOMMIT=@@AUTOCOMMIT, @@AUTOCOMMIT=0; +LOCK TABLES `material` WRITE; +/*!40000 ALTER TABLE `material` DISABLE KEYS */; +INSERT INTO `material` VALUES +(1,'Курский тёмный',20,2), +(2,'Курский пилзнер',15,2), +(3,'Давыдовский ключ',100,1); +/*!40000 ALTER TABLE `material` ENABLE KEYS */; +UNLOCK TABLES; +COMMIT; +SET AUTOCOMMIT=@OLD_AUTOCOMMIT; + +-- +-- Table structure for table `material_category` +-- + +DROP TABLE IF EXISTS `material_category`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8mb4 */; +CREATE TABLE `material_category` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=8 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `material_category` +-- + +SET @OLD_AUTOCOMMIT=@@AUTOCOMMIT, @@AUTOCOMMIT=0; +LOCK TABLES `material_category` WRITE; +/*!40000 ALTER TABLE `material_category` DISABLE KEYS */; +INSERT INTO `material_category` VALUES +(1,'Вода'), +(2,'Солод'), +(3,'Хмель'), +(7,'Дрожжи'); +/*!40000 ALTER TABLE `material_category` ENABLE KEYS */; +UNLOCK TABLES; +COMMIT; +SET AUTOCOMMIT=@OLD_AUTOCOMMIT; + +-- +-- Table structure for table `order` +-- + +DROP TABLE IF EXISTS `order`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8mb4 */; +CREATE TABLE `order` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `client_id` int(11) DEFAULT NULL, + `order_date` datetime DEFAULT NULL, + `total_amount` decimal(10,0) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `fk_client` (`client_id`), + CONSTRAINT `fk_client` FOREIGN KEY (`client_id`) REFERENCES `client` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `order` +-- + +SET @OLD_AUTOCOMMIT=@@AUTOCOMMIT, @@AUTOCOMMIT=0; +LOCK TABLES `order` WRITE; +/*!40000 ALTER TABLE `order` DISABLE KEYS */; +/*!40000 ALTER TABLE `order` ENABLE KEYS */; +UNLOCK TABLES; +COMMIT; +SET AUTOCOMMIT=@OLD_AUTOCOMMIT; + +-- +-- Table structure for table `order_element` +-- + +DROP TABLE IF EXISTS `order_element`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8mb4 */; +CREATE TABLE `order_element` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `order_id` int(11) DEFAULT NULL, + `product_id` int(11) DEFAULT NULL, + `quantity` int(11) DEFAULT NULL, + `total_amount` decimal(10,0) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `fk_order` (`order_id`), + KEY `fk_product` (`product_id`), + CONSTRAINT `fk_order` FOREIGN KEY (`order_id`) REFERENCES `order` (`id`), + CONSTRAINT `fk_product` FOREIGN KEY (`product_id`) REFERENCES `product` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `order_element` +-- + +SET @OLD_AUTOCOMMIT=@@AUTOCOMMIT, @@AUTOCOMMIT=0; +LOCK TABLES `order_element` WRITE; +/*!40000 ALTER TABLE `order_element` DISABLE KEYS */; +/*!40000 ALTER TABLE `order_element` ENABLE KEYS */; +UNLOCK TABLES; +COMMIT; +SET AUTOCOMMIT=@OLD_AUTOCOMMIT; + +-- +-- Table structure for table `position` +-- + +DROP TABLE IF EXISTS `position`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8mb4 */; +CREATE TABLE `position` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + `wage` decimal(10,0) DEFAULT NULL, + `is_admin` tinyint(1) NOT NULL DEFAULT 0, + PRIMARY KEY (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `position` +-- + +SET @OLD_AUTOCOMMIT=@@AUTOCOMMIT, @@AUTOCOMMIT=0; +LOCK TABLES `position` WRITE; +/*!40000 ALTER TABLE `position` DISABLE KEYS */; +INSERT INTO `position` VALUES +(1,'Уборщик',20000,0), +(2,'Кладовщик',32000,0), +(3,'Пивовар',65000,0), +(4,'Менеджер',70000,1); +/*!40000 ALTER TABLE `position` ENABLE KEYS */; +UNLOCK TABLES; +COMMIT; +SET AUTOCOMMIT=@OLD_AUTOCOMMIT; + +-- +-- Table structure for table `product` +-- + +DROP TABLE IF EXISTS `product`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8mb4 */; +CREATE TABLE `product` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `recipe_id` int(11) DEFAULT NULL, + `volume` float DEFAULT NULL, + `price_per_unit` decimal(10,0) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `fk_recipe1` (`recipe_id`), + CONSTRAINT `fk_recipe1` FOREIGN KEY (`recipe_id`) REFERENCES `recipe` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `product` +-- + +SET @OLD_AUTOCOMMIT=@@AUTOCOMMIT, @@AUTOCOMMIT=0; +LOCK TABLES `product` WRITE; +/*!40000 ALTER TABLE `product` DISABLE KEYS */; +/*!40000 ALTER TABLE `product` ENABLE KEYS */; +UNLOCK TABLES; +COMMIT; +SET AUTOCOMMIT=@OLD_AUTOCOMMIT; + +-- +-- Table structure for table `profile` +-- + +DROP TABLE IF EXISTS `profile`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8mb4 */; +CREATE TABLE `profile` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `login` varchar(100) DEFAULT NULL, + `password` varchar(100) DEFAULT NULL, + `worker_id` int(11) NOT NULL, + PRIMARY KEY (`id`), + KEY `profile_worker_FK` (`worker_id`), + CONSTRAINT `profile_worker_FK` FOREIGN KEY (`worker_id`) REFERENCES `worker` (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `profile` +-- + +SET @OLD_AUTOCOMMIT=@@AUTOCOMMIT, @@AUTOCOMMIT=0; +LOCK TABLES `profile` WRITE; +/*!40000 ALTER TABLE `profile` DISABLE KEYS */; +INSERT INTO `profile` VALUES +(1,'brewmaster','20acc91677fc5efae45936a628f7760919f836f8ffaa6abe877978b6387c5579',8), +(2,'client','948fe603f61dc036b5c596dc09fe3ce3f3d30dc90f024c85f3c82db2ccab679d',3); +/*!40000 ALTER TABLE `profile` ENABLE KEYS */; +UNLOCK TABLES; +COMMIT; +SET AUTOCOMMIT=@OLD_AUTOCOMMIT; + +-- +-- Table structure for table `recipe` +-- + +DROP TABLE IF EXISTS `recipe`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8mb4 */; +CREATE TABLE `recipe` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `name` varchar(50) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `recipe` +-- + +SET @OLD_AUTOCOMMIT=@@AUTOCOMMIT, @@AUTOCOMMIT=0; +LOCK TABLES `recipe` WRITE; +/*!40000 ALTER TABLE `recipe` DISABLE KEYS */; +/*!40000 ALTER TABLE `recipe` ENABLE KEYS */; +UNLOCK TABLES; +COMMIT; +SET AUTOCOMMIT=@OLD_AUTOCOMMIT; + +-- +-- Table structure for table `recipe_element` +-- + +DROP TABLE IF EXISTS `recipe_element`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8mb4 */; +CREATE TABLE `recipe_element` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `recipe_id` int(11) DEFAULT NULL, + `material_id` int(11) DEFAULT NULL, + `equipment_id` int(11) DEFAULT NULL, + `quantity` int(11) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `fk_recipe` (`recipe_id`), + KEY `fk_material` (`material_id`), + KEY `fk_equipment` (`equipment_id`), + CONSTRAINT `fk_equipment` FOREIGN KEY (`equipment_id`) REFERENCES `equipment` (`id`), + CONSTRAINT `fk_material` FOREIGN KEY (`material_id`) REFERENCES `material` (`id`), + CONSTRAINT `fk_recipe` FOREIGN KEY (`recipe_id`) REFERENCES `recipe` (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `recipe_element` +-- + +SET @OLD_AUTOCOMMIT=@@AUTOCOMMIT, @@AUTOCOMMIT=0; +LOCK TABLES `recipe_element` WRITE; +/*!40000 ALTER TABLE `recipe_element` DISABLE KEYS */; +/*!40000 ALTER TABLE `recipe_element` ENABLE KEYS */; +UNLOCK TABLES; +COMMIT; +SET AUTOCOMMIT=@OLD_AUTOCOMMIT; + +-- +-- Table structure for table `salary` +-- + +DROP TABLE IF EXISTS `salary`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8mb4 */; +CREATE TABLE `salary` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `worker_id` int(11) DEFAULT NULL, + `salary_size` decimal(10,0) DEFAULT NULL, + `salary_date` datetime DEFAULT NULL, + `comment` varchar(100) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `fk_worker` (`worker_id`), + CONSTRAINT `fk_worker` FOREIGN KEY (`worker_id`) REFERENCES `worker` (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `salary` +-- + +SET @OLD_AUTOCOMMIT=@@AUTOCOMMIT, @@AUTOCOMMIT=0; +LOCK TABLES `salary` WRITE; +/*!40000 ALTER TABLE `salary` DISABLE KEYS */; +INSERT INTO `salary` VALUES +(2,3,30000,'1970-01-20 00:00:00','Премия за пиво'); +/*!40000 ALTER TABLE `salary` ENABLE KEYS */; +UNLOCK TABLES; +COMMIT; +SET AUTOCOMMIT=@OLD_AUTOCOMMIT; + +-- +-- Table structure for table `salary_cluster` +-- + +DROP TABLE IF EXISTS `salary_cluster`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8mb4 */; +CREATE TABLE `salary_cluster` ( + `id` int(11) NOT NULL, + `name` varchar(100) DEFAULT NULL, + PRIMARY KEY (`id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `salary_cluster` +-- + +SET @OLD_AUTOCOMMIT=@@AUTOCOMMIT, @@AUTOCOMMIT=0; +LOCK TABLES `salary_cluster` WRITE; +/*!40000 ALTER TABLE `salary_cluster` DISABLE KEYS */; +/*!40000 ALTER TABLE `salary_cluster` ENABLE KEYS */; +UNLOCK TABLES; +COMMIT; +SET AUTOCOMMIT=@OLD_AUTOCOMMIT; + +-- +-- Table structure for table `worker` +-- + +DROP TABLE IF EXISTS `worker`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8mb4 */; +CREATE TABLE `worker` ( + `id` int(11) NOT NULL AUTO_INCREMENT, + `position_id` int(11) NOT NULL, + `hire_date` datetime DEFAULT NULL, + `is_fired` tinyint(1) DEFAULT NULL, + `full_name` varchar(100) DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `fk_position` (`position_id`), + CONSTRAINT `fk_position` FOREIGN KEY (`position_id`) REFERENCES `position` (`id`) +) ENGINE=InnoDB AUTO_INCREMENT=13 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `worker` +-- + +SET @OLD_AUTOCOMMIT=@@AUTOCOMMIT, @@AUTOCOMMIT=0; +LOCK TABLES `worker` WRITE; +/*!40000 ALTER TABLE `worker` DISABLE KEYS */; +INSERT INTO `worker` VALUES +(1,1,'1997-02-23 14:00:00',0,'Иван Петров'), +(2,1,'2021-06-11 14:00:00',0,'Петр Иванов'), +(3,1,'2010-02-11 14:00:00',0,'Pupue!'), +(4,1,'2003-01-26 14:00:00',0,'Никита Булаников'), +(5,2,'2009-01-06 14:00:00',0,'Никитин Олег'), +(6,1,'2009-09-08 13:00:00',0,'Авраамов Моисей'), +(7,2,'2018-04-21 14:00:00',0,'Беридзе Игнат'), +(8,4,'2026-04-24 00:00:00',0,'Иванов Иван'), +(9,3,'2024-04-21 14:00:00',0,'Власов Иннокентий'), +(10,2,'1970-01-19 14:00:00',0,'Петров Пётр Петрович'), +(11,2,'2003-02-01 14:00:00',0,'Никитин Олег Михайлович'), +(12,2,'2008-02-01 14:00:00',1,'Славик'); +/*!40000 ALTER TABLE `worker` ENABLE KEYS */; +UNLOCK TABLES; +COMMIT; +SET AUTOCOMMIT=@OLD_AUTOCOMMIT; +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*M!100616 SET NOTE_VERBOSITY=@OLD_NOTE_VERBOSITY */; + +-- Dump completed on 2026-06-19 20:04:08 diff --git a/code/src/app.rs b/code/src/app.rs index a3f8856..70dc855 100644 --- a/code/src/app.rs +++ b/code/src/app.rs @@ -1,11 +1,17 @@ -use std::{collections::HashMap, default::Default, ops::Deref, str::FromStr, sync::Arc}; +use std::{ + collections::{HashMap, HashSet}, + default::Default, + ops::Deref, + str::FromStr, + sync::Arc, +}; use crate::{ database::DBOperator, material_tab::MaterialTabViewer, models::{ Equipment, LoginModalState, LoginStatus, Material, MaterialCategory, MaterialRow, - ModalStatus, ModalWinState, Position, Salary, Worker, + ModalStatus, ModalWinState, Position, Salary, SalaryModalState, Worker, }, tab::*, worker_tab::{self, *}, @@ -175,7 +181,7 @@ struct MainTabViewer { material_tree: egui_dock::DockState, rt: tokio::runtime::Runtime, equipment_modal_state: ModalWinState, - salary_modal_state: ModalWinState, + salary_modal_state: SalaryModalState, is_dark_theme: bool, interface_scale_ratio: f32, is_admin: bool, @@ -232,7 +238,7 @@ impl Default for MainTabViewer { ]), status: ModalStatus::Add, }, - salary_modal_state: ModalWinState { + salary_modal_state: SalaryModalState { is_open: false, can_finish: false, data: HashMap::from([ @@ -242,6 +248,7 @@ impl Default for MainTabViewer { ("comment".to_owned(), String::new()), ]), status: ModalStatus::Add, + workers: HashSet::new(), }, is_admin: false, } @@ -565,9 +572,10 @@ impl MainTabViewer { self.salary_modal_state .data .insert("salary_size".to_owned(), sal.salary_size.to_string()); - self.salary_modal_state - .data - .insert("salary_date".to_owned(), sal.salary_date.to_string()); + self.salary_modal_state.data.insert( + "salary_date".to_owned(), + sal.salary_date.date_naive().to_string(), + ); self.salary_modal_state .data .insert("comment".to_owned(), sal.comment.clone()); @@ -585,23 +593,52 @@ impl MainTabViewer { } if self.salary_modal_state.status != ModalStatus::Remove { egui::Grid::new("process_salary_grid").show(ui, |ui| { - let mut size = ui.available_size(); - size.x = 40.0; - ui.label("Сотрудник(-и):"); - egui::ComboBox::new("process_salary_grid_combobox", "").show_ui(ui, |ui| { - for wrkr in self.workers.read().clone().iter(){ - - } - }); + let size = ui.available_size(); + if self.salary_modal_state.status == ModalStatus::Add { + ui.label("Сотрудник(-и):"); + egui::ComboBox::new("process_salary_grid_combobox", "") + .selected_text(format!( + "{} выбран(-о)", + self.salary_modal_state.workers.len() + )) + .show_ui(ui, |ui| { + for wrkr in self.workers.read().clone().iter() { + let mut checked = + self.salary_modal_state.workers.contains(wrkr); + let res = ui.add(egui::Checkbox::new( + &mut checked, + &wrkr.full_name, + )); + if res.clicked() { + if checked { + self.salary_modal_state + .workers + .insert(wrkr.clone()); + } else { + self.salary_modal_state.workers.remove(wrkr); + } + } + } + }); + ui.end_row(); + } - ui.end_row(); - ui.label("Размер оплаты:"); + ui.label("Размер платежа:"); ui.add_sized( size, egui::TextEdit::singleline( self.salary_modal_state.data.get_mut("salary_size").unwrap(), ), ); + + ui.end_row(); + ui.label("Дата платежа:"); + ui.add_sized( + size, + egui::TextEdit::singleline( + self.salary_modal_state.data.get_mut("salary_date").unwrap(), + ), + ); }); } }); diff --git a/code/src/models.rs b/code/src/models.rs index d4533e5..79b16ce 100644 --- a/code/src/models.rs +++ b/code/src/models.rs @@ -6,7 +6,7 @@ use sqlx::{ types::{BigDecimal, chrono::DateTime}, }; -#[derive(Clone, Hash, sqlx::FromRow, PartialEq)] +#[derive(Clone, Hash, sqlx::FromRow, PartialEq, std::cmp::Eq)] pub struct Position { pub id: i32, pub name: String, @@ -21,7 +21,7 @@ impl Default for Position { } } } -#[derive(Default, Clone, Hash)] +#[derive(Default, Clone, Hash, std::cmp::Eq, PartialEq)] pub struct Worker { pub id: i32, pub full_name: String,