]> gitweb.erp-flowers.ru Git - yii-erp24/.git/commitdiff
shipment store product fact p1
authorAlexander Smirnov <fredeom@mail.ru>
Sat, 20 Apr 2024 14:04:43 +0000 (17:04 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Sat, 20 Apr 2024 14:04:43 +0000 (17:04 +0300)
erp24/controllers/ShipmentController.php
erp24/modul/shipment/storeProductsFact.php
erp24/modul/shipment/storeProductsFactEdit.php
erp24/views/shipment/store-products-fact-edit.php [new file with mode: 0644]
erp24/views/shipment/store-products-fact.php [new file with mode: 0644]

index 1b0fe7ae141b606a731c1c304f5a7c35e642eb85..efc3e9cb4148f216074e652f38e16a6c67428a94 100755 (executable)
@@ -20,4 +20,6 @@ class ShipmentController extends Controller
     public function actionDivisionStorePrint() { return $this->render('division-store-print'); }
     public function actionStoreOrderScore() { return $this->render('store-order-score'); }
     public function actionAjaxDivisionAutoHandStart() { return $this->renderPartial('ajax-division-auto-hand-start'); }
+    public function actionStoreProductsFact() { return $this->render('store-products-fact'); }
+    public function actionStoreProductsFactEdit() { return $this->renderPartial('store-products-fact-edit'); }
 }
\ No newline at end of file
index e086af399649f9ae048917a79b2383c1632d581f..e727097396925dbda0df4e434e1101538c6bdd3a 100644 (file)
@@ -1,10 +1,12 @@
-<?
-include_once("startup.php");
-include_once("inc/db.php");
-include_once("inc/base_new.php");
-include_once("inc/design_new.php");
+<?php
+include_once(dirname(__DIR__, 2) . "/startup.php");
+include_once(dirname(__DIR__, 2) . "/inc/db.php");
+include_once(dirname(__DIR__, 2) . "/inc/base_new.php");
+include_once(dirname(__DIR__, 2) . "/inc/design_new.php");
 
-include"templates/top.php";
+global $store_id, $date_id, $act;
+
+$act = 'store-products-fact';
 
 if(!empty($_REQUEST["store_id"])) $store_id=htmlentities($_REQUEST["store_id"]);
 //$date_id=date("Ymd");
@@ -13,16 +15,16 @@ $arrayDate=["first","second","third","fourth","fifth"];
 $typeDay="monday";
 if(!isset($_SESSION["show_planogram_0"])) $_SESSION["show_planogram_0"]=1;
 
-if($_GET["show_planogram_0"]=="hide")  $_SESSION["show_planogram_0"]=0;  
-if($_GET["show_planogram_0"]=="show")  $_SESSION["show_planogram_0"]=1;  
+if(($_GET["show_planogram_0"] ?? '')=="hide")  $_SESSION["show_planogram_0"]=0;
+if(($_GET["show_planogram_0"] ?? '')=="show")  $_SESSION["show_planogram_0"]=1;
 
 
 
-if($_REQUEST["typeDay"]) $typeDay=htmlentities($_REQUEST["typeDay"]); //"wednesday";
+if($_REQUEST["typeDay"] ?? false) $typeDay=htmlentities($_REQUEST["typeDay"]); //"wednesday";
 
 //$date_n_id=$db::getValue("SELECT date_id FROM `store_products_fact` WHERE date_id!=? order by date_id desc LIMIT 1",[date("Ymd")]);
 //f(empty($date_n_id))
-$date_n_id=$db::getValue("SELECT date_id FROM `store_products_fact` WHERE 1 order by date_id desc LIMIT 1"); 
+$date_n_id=$db::getValue("SELECT date_id FROM store_products_fact WHERE 1 = 1 order by date_id desc LIMIT 1");
 
 
 $massivert[$date_n_id]=date('d.m.Y', strtotime($date_n_id));  
@@ -32,7 +34,7 @@ if(empty($date_id)) $date_id=$date_n_id;
 
 if(date('l', time())=="Wednesday") $typeDay="wednesday";
 
-$dayLinkstArray=["monday"=>"Понедельник", "wednesday"=>"Среда" ];
+$dayLinkstArray=["monday"=>"Понедельник", "wednesday"=>"Среда"];
 $typer="";
 foreach($dayLinkstArray as $lnk => $name) {
     
@@ -75,7 +77,8 @@ error_mess("Выберите дату  $date_div");
 exit();    
 } 
 
-$data=$db::getRows("SELECT id,name, providers_arr FROM `store_orders` WHERE date_start>NOW() - interval 25 day");
+$data=$db::getRows("SELECT id,name, providers_arr FROM store_orders WHERE date_start > NOW()::date - '25 day'::interval");
+$prov = [];
 foreach($data as $row) {
 $pr=explode(",",$row["providers_arr"]);  
  foreach($pr as $prid) { if(!empty($prid)) $prov[$prid]=$prid;}
@@ -158,16 +161,16 @@ foreach($data3 as $row2) $factAll[$row2["store_id"]][$row2["product_id"]]=$row2[
 foreach($stores as $stId =>$nameStore) {
 //echo"<br>магазин ".$nameStore."   ";
 $cnt=0; $all=0;
-$arrays=$store_planogramAllStores[$stId];
+$arrays=$store_planogramAllStores[$stId] ?? [];
 if(!empty($stores[$stId])){
   foreach($arrays as $productId =>$quantity) {
-   if($factAll[$stId][$productId]>0 and $quantity>0)  { 
+   if(($factAll[$stId][$productId] ?? 0)>0 and $quantity>0)  {
     //echo"+ $productId  = $quantity";
     $cnt++; 
      }
    $all++; 
   }  
-  $percent=round(100*($cnt/$all));
+  $percent=$all > 0 ? round(100*($cnt/$all)) : 0;
 //echo" $cnt из $all =$percent %";
 $storesFact[$stId]=$percent;
 //не заполнившие магазины
@@ -182,7 +185,7 @@ if($percent<15) $storesFactNo[]=$stId;
 
 
 foreach($stores as $strid=>$namestore){
-echo"<a href=\"/shipment/storeProductsFact/?store_id=$strid&date_id=$date_id\" class=\"btn btn-sm btn-";
+echo"<a href=\"/shipment/store-products-fact/?store_id=$strid&date_id=$date_id\" class=\"btn btn-sm btn-";
 if($store_id==$strid) echo"warning btn"; else echo"info";  echo" m-1\">";
 
 if($storesFact[$strid]>20) echo"<span class=\"btn btn-sm bg-success me-1\" title=\"Полнограмма заполнена на ".$storesFact[$strid]."%\">+".$storesFact[$strid]."%</span>";
@@ -209,7 +212,7 @@ if(!empty($storesFactNo)) {
 $w="";
 $providers=$db::mapping("SELECT id,name FROM shipment_providers ");
 $k=0;
-foreach($in as $pid) { echo'<span class="tag m-1">'.$providers[$pid].'</span>'; if($k!=0) $w .=" OR";  $w .=" o.provider_id='$pid'"; $k++; }
+foreach($in ?? [] as $pid) { echo'<span class="tag m-1">'.$providers[$pid].'</span>'; if($k!=0) $w .=" OR";  $w .=" o.provider_id='$pid'"; $k++; }
 
 if(!empty($_POST["quantity"])) {
   
@@ -302,18 +305,25 @@ foreach($prov as $pid) {
  }
 $where .=")";
 
-$data=$db::getRows("SELECT p.id, p.name, o.provider_id, o.colors FROM products_1c_options as o, products_1c as p 
-WHERE o.provider_id>0 AND p.view='1' AND p.id=o.id $where order by o.provider_id ASC, p.name ASC");
+if ($where != ' AND o.provider_id in()') {
+    $sql = "SELECT p.id, p.name, o.provider_id, o.colors FROM products_1c_options as o, products_1c as p 
+WHERE o.provider_id>0 AND p.view='1' AND p.id=o.id $where order by o.provider_id ASC, p.name ASC";
+    $data = $db::getRows($sql);
+} else {
+    $data = [];
+}
 
 
 $products_group=$db::mapping("SELECT id, name FROM products_1c   WHERE tip='products_group'");
 //foreach($data4 as $row4) $products_group[$row4["id"]]=$row4["name"];
 
-$data2=$db::getRows("SELECT p.id, p.name, p.parent_id,  o.provider_id, o.colors, p.parent_id as category_id FROM
+$sql = "SELECT p.id, p.name, p.parent_id,  o.provider_id, o.colors, p.parent_id as category_id FROM
    products_class as cl
   LEFT JOIN products_1c as p    ON (p.view='1' AND p.parent_id=cl.category_id ) 
    LEFT  JOIN products_1c_options as o ON (p.id=o.id) 
-WHERE cl.tip='related' group by p.id order by o.provider_id, p.parent_id, p.name ASC");
+WHERE cl.tip='related' group by p.id, o.provider_id, o.colors order by o.provider_id, p.parent_id, p.name ASC";
+//var_dump($sql); die;
+$data2=$db::getRows($sql);
 //SELECT p.id, p.name, p.parent_id, provider_id FROM products_class as cl, products_1c as p  WHERE p.parent_id=cl.category_id  AND cl.tip='related' AND p.view='1'  order by p.parent_id, p.name ASC
 
 $data = array_merge($data, $data2);
@@ -322,6 +332,8 @@ $data = array_merge($data, $data2);
 
 $p=0;
 $p2=0;
+$providersIn = [];
+$category_idIn = [];
 foreach($data as $row) { 
     
     
@@ -360,8 +372,8 @@ if(!in_array($row["category_id"],$category_idIn) and !empty($products_group[$row
   // <small>".$providers[$row["provider_id"]]."</small>  
 // echo"<tr style=\"display:none;\" class=\"pr__".$row["provider_id"]."\"><td colspan=4 class=\"fs-5\">".$row["name"]."</td></tr>";
  
-if($store_planogram[$row["id"]]>0 or $_SESSION["show_planogram_0"]==1) {
-$difference=$store_planogram[$row["id"]]-$values_in[$row["id"]]["quantity"];
+if(($store_planogram[$row["id"]] ?? 0)>0 or $_SESSION["show_planogram_0"]==1) {
+$difference=($store_planogram[$row["id"]] ?? 0)-($values_in[$row["id"]]["quantity"] ?? 0);
 if(!empty($store_planogram[$row["id"]])) $difference_percent=100-round(100*$difference/$store_planogram[$row["id"]]);
 else $difference_percent="";
 
@@ -370,8 +382,8 @@ else $difference_percent="";
  
  if($p>1 or $p2>1) echo"display:none;"; 
  
-if($store_planogram[$row["id"]]==0) echo"opacity:0.9;"; 
-if($difference_percent==0 and $store_planogram[$row["id"]]!=0) echo"background:#ffe391;"; 
+if(($store_planogram[$row["id"]] ?? 0)==0) echo"opacity:0.9;";
+if($difference_percent==0 and ($store_planogram[$row["id"]] ?? 0)!=0) echo"background:#ffe391;";
 if($difference_percent>=100) echo"background:#9effd2;"; 
 
 
@@ -380,16 +392,16 @@ if($difference_percent>=100) echo"background:#9effd2;";
  
  if(!empty($row["category_id"])) echo" category__".$row["category_id"];
  
-if($store_planogram[$row["id"]]==0) echo" bg-danger2"; 
+if(($store_planogram[$row["id"]] ?? -1) ==0) echo" bg-danger2";
  
  echo"\"><td class=\"text-right fs-6 pr-2\">".$row["name"]."</td>
  
-<td class=\"text-center tdcntr\">".$balances[$row["id"]]."</td>";
+<td class=\"text-center tdcntr\">".($balances[$row["id"]] ?? '')."</td>";
  foreach($massiver as $f =>$mass) {
     echo'<td title="'.$mass["title"].'">';
     
     if($mass["type"]=="number") {
-    echo'<input type=number oninput="up(this)" onchange="storeProductsFactEdit(\''.$row["id"].'\',\'NULL\')" min="0" id="color_quantity_'.$row["id"].'_NULL" name='.$mass["name_eng"].'['.$row["id"].'] class="poln '.$mass["class"].'" value="';
+    echo'<input type=number oninput="up(this)" onchange="storeProductsFactEdit(\''.$row["id"].'\',\'NULL\')" min="0" id="color_quantity_'.$row["id"].'_NULL" name='.$mass["name_eng"].'['.$row["id"].'] class="poln '.($mass["class"]??'').'" value="';
     if(isset($values_in[$row["id"]][$mass["name_eng"]])) echo $values_in[$row["id"]][$mass["name_eng"]];
       echo'"';
     if(!empty($mass["pattern"])) echo' pattern="'.$mass["pattern"].'"';
@@ -408,7 +420,7 @@ if($store_planogram[$row["id"]]==0) echo" bg-danger2";
   //  echo"<option value=0 "; if(empty($values_in[$row["id"]])) echo "select";  echo">-выбрать-</option>";
     
     foreach($mass["values_arr"] as $v => $name) {
-     echo"<option value=$v "; if($v==$values_in[$row["id"]][$mass["name_eng"]]) echo "selected";
+     echo"<option value=$v "; if($v==($values_in[$row["id"]][$mass["name_eng"]] ?? '')) echo "selected";
      echo">$name</option>";
     }
     echo'</select>';
@@ -418,7 +430,7 @@ if($store_planogram[$row["id"]]==0) echo" bg-danger2";
  } 
  
 
-echo'<td class="tdcntr bg-default">'.$store_planogram[$row["id"]].'</td>
+echo'<td class="tdcntr bg-default">'.($store_planogram[$row["id"]] ?? '').'</td>
 <td class="tdcntr bg-';
 if($difference>0) echo'danger2';elseif($difference<0) echo'success';else echo'default';
 
@@ -573,7 +585,10 @@ table.zak tr.zg th b, table.zak tr.zg td b {  writing-mode: vertical-rl; transfo
 
 */
 
-$_CONFIG["jscss"] .='<style>.t tbody tr td{padding:0;}
+$quantity=htmlentities($_REQUEST["quantity"] ?? 0);
+
+
+$_CONFIG["jscss"] ='<style>.t tbody tr td{padding:0;}
 .t tbody tr td input.form-control{padding:0;margin:0 2px;text-align:center;font-weight:bold;}
 
 .table tbody tr td{padding:0;}
@@ -602,19 +617,17 @@ table tbody td small{color:#787878; text-align:center; font-size:0.7rem; margin:
 
 <script>
 
-
-$quantity=htmlentities($_REQUEST["quantity"]);
-
-
 function storeProductsFactEdit(product_id,color){
 
 var quantity=$(\'#color_quantity_\'+product_id+\'_\'+color+\'\').val();
-
+ const param3 = $("meta[name=csrf-param]").attr("content");
+ const token3 = $("meta[name=csrf-token]").attr("content");  
  $.ajax({
-       url: \'/shipment/storeProductsFactEdit/\',
+       url: \'/shipment/store-products-fact-edit/\',
        method: \'post\',       
        dataType: \'html\',        
-       data: {store_id: \''.$store_id.'\', date_id: \''.$date_id.'\', quantity: quantity,  product_id: product_id, color: color},  
+       data: {store_id: \''.$store_id.'\', date_id: \''.$date_id.'\', quantity: quantity,  product_id: product_id, color: color, [param3]:token3},  
        success: function(data){  
     $(\'#editDiv\').html(data);
        }}); 
@@ -629,9 +642,5 @@ function up(e) {
 }
 </script>';
 
+include_once dirname(__DIR__, 2) . '/templates/bottom_light.php';
 }
-       
-include"templates/bottom.php"; 
-       
-
-
index 55916341e3cb8922ec34072533be04efd403d6c1..72da4f76810adc80bcea28dc6613100b358398ac 100644 (file)
@@ -1,6 +1,6 @@
-<?
-include_once("startup.php");
-include_once("inc/db.php");
+<?php
+include_once(dirname(__DIR__, 2) . "/startup.php");
+include_once(dirname(__DIR__, 2) . "/inc/db.php");
 
 if(!empty($_REQUEST["product_id"])) {
 
@@ -9,15 +9,14 @@ $color=htmlentities($_REQUEST["color"]);
 $quantity=intval($_REQUEST["quantity"]);
 $store_id=htmlentities($_REQUEST["store_id"]);
 $date_id=intval($_REQUEST["date_id"]);
-echo"Сохранили количество =$quantity";
+echo"Сохранили количество =$quantity" . " $product_id,$color,$store_id,$date_id";
 
 
 
 if($color!="NULL") $color=str_replace('"','',$color); 
 else $color='';
-$sql="INSERT IGNORE INTO store_products_fact SET  ";
-$up= "store_id='$store_id', product_id='$product_id', date_id='$date_id', color='$color', quantity='$quantity' ";  
-$sql .="$up ON DUPLICATE KEY UPDATE $up"; 
+$sql = "INSERT INTO store_products_fact (store_id, product_id, date_id, color, quantity) VALUES ('$store_id','$product_id','$date_id','$color','$quantity')"
+    . " ON CONFLICT(date_id, product_id, color, store_id) DO UPDATE SET quantity=$quantity";
 //echo"<br><br>++$color++$sql";
 $db::sql($sql);    
 
diff --git a/erp24/views/shipment/store-products-fact-edit.php b/erp24/views/shipment/store-products-fact-edit.php
new file mode 100644 (file)
index 0000000..51a023e
--- /dev/null
@@ -0,0 +1,5 @@
+<?php
+
+chdir(__DIR__ . '/../../');
+
+include 'modul/shipment/storeProductsFactEdit.php';
\ No newline at end of file
diff --git a/erp24/views/shipment/store-products-fact.php b/erp24/views/shipment/store-products-fact.php
new file mode 100644 (file)
index 0000000..7eb9ccb
--- /dev/null
@@ -0,0 +1,5 @@
+<?php
+
+chdir(__DIR__ . '/../../');
+
+include 'modul/shipment/storeProductsFact.php';
\ No newline at end of file