-<?
+<?php
include_once("startup.php");
include_once("inc/db.php");
include_once("inc/base_new.php");
include_once("inc/design_new.php");
-include"templates/top.php";
-
-$year=date("Y");
-$month=(int)date("m");
-
-if(!empty($_REQUEST["store_id"])) $store_id=htmlentities($_REQUEST["store_id"]);
-if(!empty($_REQUEST["year"])) $year=intval($_REQUEST["year"]);
-if(!empty($_REQUEST["month"])) $month=intval($_REQUEST["month"]);
+$year = date("Y");
+$month = date("m");
+$values_data = $values_data ?? [];
+if (!empty($_REQUEST["store_id"])) $store_id = htmlentities($_REQUEST["store_id"]);
+if (!empty($_REQUEST["year"])) $year = intval($_REQUEST["year"]);
+if (!empty($_REQUEST["month"])) $month = intval($_REQUEST["month"]);
//$users_group=$db::mapping("SELECT id,name FROM admin_group order by name ASC");
-$stores=$db::mapping("SELECT name,id FROM products_1c WHERE tip='city_store' AND view='1' order by name ASC");
+$stores = $db::mapping("SELECT name,id FROM products_1c WHERE tip='city_store' AND view='1' order by name ASC");
+foreach ($_POST["summ_week"] ?? [] as $storeid => $summ) {
-foreach($_POST["summ_week"] as $storeid => $summ) {
-
//$_POST["summ_week"] as $storeid => $summ
-$summ2=$_POST["summ"][$storeid];
-$summ_fact=$_POST["summ_fact"][$storeid];
+ $summ2 = $_POST["summ"][$storeid];
+ $summ_fact = $_POST["summ_fact"][$storeid];
-$sql="INSERT IGNORE INTO store_plan SET store_id='$storeid', month='$month', year='$year' , summ_week='$summ', summ='$summ2', summ_fact='$summ_fact'
-ON DUPLICATE KEY UPDATE store_id='$storeid', month='$month', year='$year', summ_week='$summ', summ='$summ2', summ_fact='$summ_fact' ";
-$db::sql($sql);
+ $sql = "INSERT INTO store_plan (store_id, month, year, summ_week, summ, summ_fact, plan_day, plan_day_saturday, plan_checks_counter, plan_avg, plan_checks_counter_saturday, plan_chacks_counter_week, plan_people_day, plan_people_day_saturday, plan_people_week, admin_id, date_edit)
+VALUES ('$storeid','$month','$year','$summ','$summ2','$summ_fact',0,0,0,0,0,0,0,0,0,0,now())
+ON CONFLICT (store_id, month, year) DO UPDATE SET store_id='$storeid', month='$month', year='$year', summ_week='$summ', summ='$summ2', summ_fact='$summ_fact', date_edit=now()";
+ $db::sql($sql);
//echo $sql;
}
-$data=$db::getRows("SELECT * FROM store_plan WHERE year=? AND month=?",[$year,$month]);
-foreach($data as $row){
-$values_data[$row["store_id"]]["summ"]=$row["summ"];
-$values_data[$row["store_id"]]["summ_week"]=$row["summ_week"];
-$values_data[$row["store_id"]]["summ_fact"]=$row["summ_fact"];
+$data = $db::getRows("SELECT * FROM store_plan WHERE year=? AND month=?", [$year, $month]);
+foreach ($data as $row) {
+ $values_data[$row["store_id"]]["summ"] = $row["summ"];
+ $values_data[$row["store_id"]]["summ_week"] = $row["summ_week"];
+ $values_data[$row["store_id"]]["summ_fact"] = $row["summ_fact"];
}
-echo'<h1>План продаж и закупки по магазинам</h1>';
-$array=[2019,2020,2021,2022];
-
+echo '<h1>План продаж и закупки по магазинам</h1>';
+$array = [2019, 2020, 2021, 2022];
-foreach($array as $y) {
- echo"<a href=\"/shipment/store_plan/?year=$y\" class=\"btn btn-";
-if($year==$y) { echo"success";
+foreach ($array as $y) {
+ echo "<a href=\"/shipment/store-plan/?year=$y\" class=\"btn btn-";
+ if ($year == $y) {
+ echo "success";
-} else echo"warning"; echo" btn-sm m-1\">$y ";
-echo"</a> ";
+ } else echo "warning";
+ echo " btn-sm m-1\">$y ";
+ echo "</a> ";
}
$array = array(
- 1 => 'Январь',
- 2 => 'Февраль',
- 3 => 'Март',
- 4 => 'Апрель',
- 5 => 'Май',
- 6 => 'Июнь',
- 7 => 'Июль',
- 8 => 'Август',
- 9 => 'Сентябрь',
- 10 => 'Октябрь',
- 11 => 'Ноябрь',
- 12 => 'Декабрь'
+ 1 => 'Январь',
+ 2 => 'Февраль',
+ 3 => 'Март',
+ 4 => 'Апрель',
+ 5 => 'Май',
+ 6 => 'Июнь',
+ 7 => 'Июль',
+ 8 => 'Август',
+ 9 => 'Сентябрь',
+ 10 => 'Октябрь',
+ 11 => 'Ноябрь',
+ 12 => 'Декабрь'
);
-
-
- echo"<br>";
-foreach($array as $monf => $m) {
- echo"<a href=\"/shipment/store_plan/?year=$year&month=$monf\" class=\"btn btn-";
-if($month==$monf) { echo"success";
-} else echo"info"; echo" btn-sm m-1\">$m ";
-echo"</a> ";
-}
-
+echo "<br>";
+foreach ($array as $monf => $m) {
+ echo "<a href=\"/shipment/store-plan/?year=$year&month=$monf\" class=\"btn btn-";
+ if ($month == $monf) {
+ echo "success";
+ } else echo "info";
+ echo " btn-sm m-1\">$m ";
+ echo "</a> ";
+}
-echo'<form method=post action="/shipment/store_plan/?year='.$year.'&month='.$month.'"><table class="table table-hover">
+echo '<form method=post action="/shipment/store-plan/?year=' . $year . '&month=' . $month . '">
+<input type="hidden" name="_csrf" value=" ' . Yii::$app->request->getCsrfToken() . ' "/>
+<table class="table table-hover">
<thead><th>магазин</th>
<th>план продаж</th>
</thead>
<tbody>';
-foreach($stores as $strid=>$namestore){
-echo"<tr><td class=\"text-right\">$namestore</td><td><input value=\"".$values_data[$strid]["summ"]."\" type=text class=\"form-control\" name=summ[$strid]></td>
-<td><input type=text class=\"form-control\" value=\"".$values_data[$strid]["summ_week"]."\" name=summ_week[$strid]></td>
-<td><input type=text class=\"form-control\" value=\"".$values_data[$strid]["summ_fact"]."\" name=summ_fact[$strid]></td>
-
-</tr>";
+foreach ($stores as $strid => $namestore) {
+ if ($values_data[$strid] ?? false) {
+ echo "<tr><td class=\"text-right\">$namestore</td><td><input value=\"" . $values_data[$strid]["summ"] . "\" type=text class=\"form-control\" name=summ[$strid]></td>
+<td><input type=text class=\"form-control\" value=\"" . $values_data[$strid]["summ_week"] . "\" name=summ_week[$strid]></td>
+<td><input type=text class=\"form-control\" value=\"" . $values_data[$strid]["summ_fact"] . "\" name=summ_fact[$strid]></td>
+</tr>";
+ }
}
-echo'</tbody></table>
+echo '</tbody></table>
<button type=submit name=save value=1 class="btn btn-success btn-lg m-2">сохранить</button>
</form>';
-
-
-
-
-include"templates/bottom.php";