From 61dcd3c596d0d534a708251f86e55195d7acacd4 Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Wed, 25 Sep 2024 12:47:44 +0300 Subject: [PATCH] =?utf8?q?[ERP-195]=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?utf8?q?=D0=B5=D0=BD=D0=B0=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA?= =?utf8?q?=D0=B0=20=D0=BF=D1=80=D0=BE=D0=B8=D0=B7=D0=B2=D0=BE=D0=B4=D1=81?= =?utf8?q?=D1=82=D0=B2=D0=B5=D0=BD=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=BA=D0=B0?= =?utf8?q?=D0=BB=D0=B5=D0=BD=D0=B4=D0=B0=D1=80=D1=8F=20=D1=81=20=D1=81?= =?utf8?q?=D0=B0=D0=B9=D1=82=D0=B0=20xmlcalendar.ru=20=D0=B8=20=D0=B5?= =?utf8?q?=D0=B3=D0=BE=20=D0=BE=D1=82=D0=BE=D0=B1=D1=80=D0=B0=D0=B6=D0=B5?= =?utf8?q?=D0=BD=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- docker/php/Dockerfile | 2 +- erp24/composer.json | 3 +- .../ProductionCalendarController.php | 97 +++++++++++++++++++ ...63026_create_table_production_calendar.php | 30 ++++++ erp24/records/ProductionCalendar.php | 48 +++++++++ erp24/views/production-calendar/index.php | 72 ++++++++++++++ erp24/web/css/production-calendar/style.css | 71 ++++++++++++++ 7 files changed, 321 insertions(+), 2 deletions(-) create mode 100644 erp24/controllers/ProductionCalendarController.php create mode 100755 erp24/migrations/m240925_063026_create_table_production_calendar.php create mode 100644 erp24/records/ProductionCalendar.php create mode 100644 erp24/views/production-calendar/index.php create mode 100644 erp24/web/css/production-calendar/style.css diff --git a/docker/php/Dockerfile b/docker/php/Dockerfile index 2de2f1f1..1215d6f1 100644 --- a/docker/php/Dockerfile +++ b/docker/php/Dockerfile @@ -12,7 +12,7 @@ RUN apk add --no-cache zlib libpng icu zip libzip-dev \ && apk del .deps RUN apk --no-cache --update --repository http://dl-cdn.alpinelinux.org/alpine/v$ALPINE_VERSION/main/ add \ - postgresql-dev + autoconf dpkg-dev dpkg file g++ gcc libc-dev make pkgconf re2c postgresql-dev RUN docker-php-ext-install pdo_pgsql #add composer diff --git a/erp24/composer.json b/erp24/composer.json index 4cef5838..d1f2c033 100644 --- a/erp24/composer.json +++ b/erp24/composer.json @@ -30,7 +30,8 @@ "kartik-v/yii2-bootstrap5-dropdown": "@dev", "kartik-v/yii2-grid": "@dev", "kartik-v/yii2-widget-datepicker": "dev-master", - "phpoffice/phpspreadsheet": "^2.2" + "phpoffice/phpspreadsheet": "^2.2", + "ext-xmlreader": "*" }, "require-dev": { "yiisoft/yii2-debug": "~2.1.0", diff --git a/erp24/controllers/ProductionCalendarController.php b/erp24/controllers/ProductionCalendarController.php new file mode 100644 index 00000000..9ec3a123 --- /dev/null +++ b/erp24/controllers/ProductionCalendarController.php @@ -0,0 +1,97 @@ + $date]); + if (!$productionCalendar) { + $productionCalendar = new ProductionCalendar; + $productionCalendar->date = $date; + } + $productionCalendar->work = $work ?? ($weekDay < 6 ? 1 : 0); + $productionCalendar->save(); + if ($productionCalendar->getErrors()) { + throw new \Exception(Json::encode($productionCalendar->getErrors())); + } + } + + public function parseXml($xml) { + $s = date("Y-01-01 00:00:00"); + $f = date("Y-12-31 00:00:00"); + while ($s < $f) { + $this->setCalendarValue($s); + $s = date("Y-m-d 00:00:00", strtotime("+1 day", strtotime($s))); + } + $calendarYear = ''; + while ($xml->read()) { + if ($xml->nodeType == XMLReader::ELEMENT && $xml->localName == 'calendar') { + $calendarYear = $xml->getAttribute('year'); + } + if ($xml->nodeType == XMLReader::ELEMENT && $xml->localName == 'day') { + $date1 = date($calendarYear . '-' . str_replace('.', '-', $xml->getAttribute('d'))); + $work = $xml->getAttribute('t') > 1 ? 1 : 0; + $this->setCalendarValue($date1, $work); + } + } + } + + public function actionIndex($viewYear = null) { + if (Yii::$app->request->isPost) { + $xml = UploadedFile::getInstanceByName('xmlFile'); + $path = Yii::getAlias("@uploads") . '/' . $xml->getBaseName() . '.' . $xml->getExtension(); + $xml->saveAs($path); + + $xml = new XMLReader; + $xml->open($path); + + $this->parseXml($xml); + + Yii::$app->session->setFlash('success', 'Календарь успешно загружен.'); + } + + $months = ['Январь',' Февраль', 'Март', 'Апрель', 'Май', 'Июнь', 'Июль', 'Август', 'Сентябрь', 'Октябрь', 'Ноябрь', 'Декабрь']; + $daysInWeek = ['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс']; + + $workDaysMap = ArrayHelper::map(ProductionCalendar::find()->where(['between', 'date', '2024-01-01', '2024-12-31'])->all(), 'date', 'work'); + + if (!$viewYear) { + $viewYear = date('Y'); + } + + $workDaysInMonthCountMap = []; + foreach (range(1,12) as $monthIndex) { + if ($monthIndex < 10) { + $monthIndex = '0' . $monthIndex; + } + $date1 = date($viewYear . '-' . $monthIndex . '-01'); + $date2 = date($viewYear . '-' . $monthIndex . '-t', strtotime($date1)); + $cnt = 0; + while ($date1 <= $date2) { + $cnt += $workDaysMap[$date1]; + $date1 = date('Y-m-d', strtotime('+1 day', strtotime($date1))); + } + $workDaysInMonthCountMap[$monthIndex] = $cnt; + } + + $years = []; + foreach (range(2023, date('Y')) as $y) { + $years[$y] = $y; + } + + return $this->render('index', + compact('months', 'daysInWeek', 'workDaysMap', 'viewYear', 'years', 'workDaysInMonthCountMap')); + } +} \ No newline at end of file diff --git a/erp24/migrations/m240925_063026_create_table_production_calendar.php b/erp24/migrations/m240925_063026_create_table_production_calendar.php new file mode 100755 index 00000000..8cdd982f --- /dev/null +++ b/erp24/migrations/m240925_063026_create_table_production_calendar.php @@ -0,0 +1,30 @@ +createTable(self::TABLE_NAME, [ + 'id' => $this->primaryKey(), + 'date' => $this->string(10)->notNull()->comment('День определяющих рабочее состояние'), + 'work' => $this->tinyInteger()->notNull()->comment('1 - будни, 0 - выходной или праздник'), + ]); + } + + /** + * {@inheritdoc} + */ + public function safeDown() + { + $this->dropTable(self::TABLE_NAME); + } +} diff --git a/erp24/records/ProductionCalendar.php b/erp24/records/ProductionCalendar.php new file mode 100644 index 00000000..67b733f5 --- /dev/null +++ b/erp24/records/ProductionCalendar.php @@ -0,0 +1,48 @@ + null], + [['work'], 'integer'], + [['date'], 'string', 'max' => 10], + ]; + } + + /** + * {@inheritdoc} + */ + public function attributeLabels() + { + return [ + 'id' => 'ID', + 'date' => 'Date', + 'work' => 'Work', + ]; + } +} diff --git a/erp24/views/production-calendar/index.php b/erp24/views/production-calendar/index.php new file mode 100644 index 00000000..4efedeea --- /dev/null +++ b/erp24/views/production-calendar/index.php @@ -0,0 +1,72 @@ +registerCssFile('/css/production-calendar/style.css'); + +?> + +
+ + session->hasFlash('success')): ?> +
+ + session->getFlash('success') ?> +
+ + + ['enctype' => 'multipart/form-data']]) ?> + + 'btn btn-success', 'onchange' => 'this.form.submit()', 'accept' => '.xml']) ?> + + Отобразить календарь за 'window.location = "/production-calendar/index?viewYear=" + this.value;']) ?> год. + Текущий просматриваемый год: . + + + + +
+ $month): ?> +
+
+
+ + + + + + + + + + + + + $dayName): ?> + + + + + + + + + + +
+ 0 && $num <= $numMonth ? $num : ' ' ?>
Число рабочих дней:
+
+
+ +
+ +
diff --git a/erp24/web/css/production-calendar/style.css b/erp24/web/css/production-calendar/style.css new file mode 100644 index 00000000..fb301bb0 --- /dev/null +++ b/erp24/web/css/production-calendar/style.css @@ -0,0 +1,71 @@ +h1 { + text-align: center; +} +h2 { + text-align: center; +} +.text-right { + text-align: right; +} +.text-left { + text-align: left; +} +.text-center { + text-align: center; +} +/*.pcal-month-container, .pcal-norm-container {*/ +/* clear:both;*/ +/* display: block;*/ +/*}*/ +.pcal-norm-container table { + width: 100%; +} +.pcal-norm-container thead, .pcal-norm-container tfoot { + font-weight: bold; +} +.pcal-month div, .pcal-month td, thead { + font-size: 22px; +} +.pcal-month td , td { + padding: 3px; +} +.pcal-month { + width: 230px; + float: left; + margin: 5px; +} +.pcal-day-of-week1 { + font-size: 1rem !important; +} +.pcal-day-of-week, td.pcal-norm-month, .pcal-norm-container tfoot td{ + background-color: #DAE8F3; + font-weight: bold; +} +.pcal-month-name { + font-weight: bold; + text-align: center; +} +.pcal-day { + cursor: pointer; +} +.pcal-day-hover { + background-color: #ffff99; +} +.pcal-day-short { + font-weight: bold; + color: #8EBC51; +} +.pcal-day-holiday { + font-weight: bold; + color: #e20000; +} +.pcal-current { + /*border: 2px solid red;*/ + background-color: #FFD4D4; +} +.pcal-footer { + margin: 20px 5px 5px 5px; +} +.pcal-footer-ital { + font-style: italic; +} -- 2.39.5