]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
правки по автозаказу фикс редактирования полей ajax
authorAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Mon, 22 Apr 2024 11:19:08 +0000 (14:19 +0300)
committerAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Mon, 22 Apr 2024 11:19:08 +0000 (14:19 +0300)
erp24/controllers/ShipmentController.php
erp24/modul/shipment/ajaxField.php
erp24/modul/shipment/shipment.php
erp24/views/shipment/ajax-field.php [new file with mode: 0644]

index efc3e9cb4148f216074e652f38e16a6c67428a94..d1b2cd31f3474ab1420ce8da52ccf6232a6a228e 100755 (executable)
@@ -22,4 +22,5 @@ class ShipmentController extends Controller
     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'); }
+    public function actionAjaxField() { return $this->renderPartial('ajax-field'); }
 }
\ No newline at end of file
index 29294ec5024c004cb49b2c009528ddc4da5b180b..14991f3e10927ab240d0a70548a400a8a1523d2b 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");
 
 $id=(int)$_REQUEST["id"];
 $product_id=htmlentities($_REQUEST["product_id"]);
@@ -30,7 +30,8 @@ $products=[$product_id=>"товар"];
 //echo"$name_eng=$value $product_id $store_id";
 if(!empty($store_id)) {
 global $dependent_fields;    
-$data=$db::getRows("SELECT id, dependent_fields, name_eng FROM store_orders_fields WHERE 1"); 
+$data=$db::getRows("SELECT id, dependent_fields, name_eng FROM store_orders_fields WHERE 1=1");
+
 foreach($data as $row) { 
     $dependent_fields[$row["id"]]=explode(",",$row["dependent_fields"]);  
     $fieldRows[$row["id"]]=$row["name_eng"];
@@ -39,10 +40,17 @@ foreach($data as $row) {
 global $arrayp;
 
 function recurs_depended($fieldId) {
- global $dependent_fields,$arrayp;
- $arrayp .=",".implode(",",$dependent_fields[$fieldId]);    
- foreach($dependent_fields[$fieldId] as $fieldId2)          recurs_depended($fieldId2); 
- return $arrayp;
+    global $dependent_fields,$arrayp;
+    if (isset($dependent_fields[$fieldId])) {
+        $arrayp .=",".implode(",",$dependent_fields[$fieldId]);
+
+        foreach($dependent_fields[$fieldId] as $fieldId2) {
+            if (!empty($fieldId2)) {
+                recurs_depended($fieldId2);
+            }
+        }
+    }
+    return $arrayp;
 }    
     
     
@@ -55,8 +63,10 @@ if(is_array($row)) {
     
  
  
-if(1) {    
-$arrayp=recurs_depended($fieldId); 
+if(1) {
+    if (!empty($fieldId)) {
+        $arrayp=recurs_depended($fieldId);
+    }
 
 
 $arrayp = array_unique(explode(",",$arrayp));
@@ -114,17 +124,16 @@ if($name_eng=="quantity_zakup_new") {
 }
  
  //$db::sql("DELETE FROM store_orders_fields_data WHERE product_id=? AND order_id=? AND store_id=? AND field_name=? AND field_id=? AND color=?",[$product_id,$id,$store_id,$name_eng,$fieldId,$color]);
- //echo"удаление пустой записи";   
-    
+ //echo"удаление пустой записи";
+
+$upFields = "product_id, order_id, store_id, field_name, field_id, color, date_update, hand, value, title";
+$valuesFields= "'$product_id', '$id', '$store_id', '$name_eng', '$fieldId', '$color', NOW(), 1, 0, 0";
 
-    
 $value_old=$db::getValue("SELECT $pole FROM store_orders_fields_data WHERE product_id=? AND order_id=?
-AND store_id=? AND field_name=? AND field_id=? AND color=? LIMIT 1",[$product_id,$id,$store_id,$name_eng,$fieldId,$color]);    
-$value_old=str_replace('.000','',$value_old);    
-$sql="INSERT IGNORE INTO store_orders_fields_data SET  ";
-  $up2 =" $pole='$value'"; 
-  $up .= ",".$up2; 
-$sql .="$up ON DUPLICATE KEY UPDATE $up2";
+AND store_id=? AND field_name=? AND field_id=? AND color=? LIMIT 1",[$product_id,$id,$store_id,$name_eng,$fieldId,$color]);
+$value_old=str_replace('.000','',$value_old);
+$sql="INSERT INTO store_orders_fields_data ($upFields) VALUES ($valuesFields) ON CONFLICT (order_id, product_id, store_id, field_id, field_name, color) DO UPDATE SET $pole='$value'";
+
 $db::sql($sql);
 //echo'сохранили '.$name_eng.' store_id='.$store_id.' '.$name_eng.'  color='.$color.' value='.$value.'  ';
   
@@ -139,8 +148,8 @@ VALUES(?,?,?,?,?, ?, ?, NOW(), ?)", [$product_id,$fieldId,$id,$store_id,$color,$
     
 //echo"Считаем Заивисимые поля";
 //print_r($arrayp);    
- $orderId=(int)$id; 
-include_once("modul/shipment/functionsShipment.php");
+ $orderId=(int)$id;
+include_once(__DIR__ . "/functionsShipment.php");
 
 foreach($arrayp as $key => $Field) {
  $f="modul/shipment/fields/$Field.php";    
index 8e2d3842f8c1afb226a2446fb43194d932f46639..443e20243968daa480c06f8d15e819c941358c67 100644 (file)
@@ -443,11 +443,14 @@ $(\'#\'+id+\'\').val(\'\'+uname+\'\');
 
 function ajaxEditFieldValue(name_eng,product_id,color)
 { 
+    
+ const param3 = $("meta[name=csrf-param]").attr("content");
+ const token3 = $("meta[name=csrf-token]").attr("content");  
 $.ajax({
-       url: \'/shipment/ajaxField/\',
+       url: \'/shipment/ajax-field/\',
        method: \'post\',       
        dataType: \'html\',        
-       data: { id: '.$orderId.',  name_eng: \'\'+name_eng+\'\', store_id:\'\'+$(\'#store_id_id\').val()+\'\', product_id:\'\'+product_id+\'\', color: \'\'+color+\'\', value:\'\'+$(\'#\'+name_eng+\'\'+product_id+\'\').val()+\'\' },  
+       data: { id: '.$orderId.',  name_eng: \'\'+name_eng+\'\', store_id:\'\'+$(\'#store_id_id\').val()+\'\', product_id:\'\'+product_id+\'\', color: \'\'+color+\'\', value:\'\'+$(\'#\'+name_eng+\'\'+product_id+\'\').val()+\'\', [param3]:token3 },  
        success: function(data){  
     $(\'#edit_div\').html(data);
 
@@ -462,12 +465,13 @@ $.ajax({
 
 function ajaxEditFieldColorValue(name_eng,product_id,color,colormd5)
 { 
-
+ const param3 = $("meta[name=csrf-param]").attr("content");
+ const token3 = $("meta[name=csrf-token]").attr("content");  
 $.ajax({
-       url: \'/shipment/ajaxField/\',
+       url: \'/shipment/ajax-field/\',
        method: \'post\',       
        dataType: \'html\',        
-       data: { id: '.$orderId.',  name_eng: \'\'+name_eng+\'\', store_id:\'\'+$(\'#store_id_id\').val()+\'\', product_id:\'\'+product_id+\'\', color: \'\'+color+\'\', value:\'\'+$(\'#\'+name_eng+\'\'+product_id+\'\'+colormd5+\'\').val()+\'\' },  
+       data: { id: '.$orderId.',  name_eng: \'\'+name_eng+\'\', store_id:\'\'+$(\'#store_id_id\').val()+\'\', product_id:\'\'+product_id+\'\', color: \'\'+color+\'\', value:\'\'+$(\'#\'+name_eng+\'\'+product_id+\'\'+colormd5+\'\').val()+\'\' , [param3]:token3},  
        success: function(data){  
     $(\'#edit_div\').html(data);
        }}); 
diff --git a/erp24/views/shipment/ajax-field.php b/erp24/views/shipment/ajax-field.php
new file mode 100644 (file)
index 0000000..7a32710
--- /dev/null
@@ -0,0 +1,5 @@
+<?php
+
+chdir(__DIR__ . '/../../');
+
+include 'modul/shipment/ajaxField.php';
\ No newline at end of file