]> gitweb.erp-flowers.ru Git - yii-erp24/.git/commitdiff
add bonus/bonus-users
authorAlexander Smirnov <fredeom@mail.ru>
Wed, 24 Apr 2024 15:46:02 +0000 (18:46 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Wed, 24 Apr 2024 15:46:02 +0000 (18:46 +0300)
13 files changed:
erp24/controllers/BonusController.php
erp24/modul/bonus/ajax_bonus_history.php
erp24/modul/bonus/ajax_user_add_stop_list.php
erp24/modul/bonus/ajax_user_remove_stop_list.php
erp24/modul/bonus/bonus_users.php
erp24/views/bonus/ajax-bonus-history.php
erp24/views/bonus/ajax-bonus-history_.php [new file with mode: 0644]
erp24/views/bonus/ajax-bonus-remove.php
erp24/views/bonus/ajax-user-add-stop-list.php
erp24/views/bonus/ajax-user-add-stop-list_.php [new file with mode: 0644]
erp24/views/bonus/ajax-user-remove-stop-list.php
erp24/views/bonus/ajax-user-remove-stop-list_.php [new file with mode: 0644]
erp24/views/bonus/bonus-users.php [new file with mode: 0644]

index 6dea2810028a3daf695f9392622a43188976fc9a..f5c8b87356ec497d84093c44be00e293a9d8ed8b 100644 (file)
@@ -10,12 +10,16 @@ class BonusController extends \yii\web\Controller
             'stat' => \yii_app\actions\bonus\StatAction::class,
             'vozvrat-stats' => \yii_app\actions\bonus\VozvratStatsAction::class,
             'ajax-show-check' => \yii_app\actions\bonus\AjaxShowCheckAction::class,
-            'users' => \yii_app\actions\bonus\UsersAction::class,
-            'ajax-bonus-history' => \yii_app\actions\bonus\AjaxBonusHistoryAction::class,
-            'ajax-user-add-stop-list' => \yii_app\actions\bonus\AjaxUserAddStopListAction::class,
-            'ajax-user-remove-stop-list' => \yii_app\actions\bonus\AjaxUserRemoveStopListAction::class,
+//            'users' => \yii_app\actions\bonus\UsersAction::class,
+//            'ajax-bonus-history' => \yii_app\actions\bonus\AjaxBonusHistoryAction::class,
+//            'ajax-user-add-stop-list' => \yii_app\actions\bonus\AjaxUserAddStopListAction::class,
+//            'ajax-user-remove-stop-list' => \yii_app\actions\bonus\AjaxUserRemoveStopListAction::class,
             'ajax-bonus-remove' => \yii_app\actions\bonus\AjaxBonusRemoveAction::class,
             'sex' => \yii_app\actions\bonus\SexAction::class,
         ];
     }
+    public function actionBonusUsers() { return $this->render('bonus-users'); }
+    public function actionAjaxBonusHistory() { return $this->renderPartial('ajax-bonus-history'); }
+    public function actionAjaxUserAddStopList() { return $this->renderPartial('ajax-user-add-stop-list'); }
+    public function actionAjaxUserRemoveStopList() { return $this->renderPartial('ajax-user-remove-stop-list'); }
 }
\ No newline at end of file
index 4d431efa65abb4b48ebd22308d097b263678c2c8..766a3f6949da85aacbcc75aa63ce495bc38dbd5c 100644 (file)
@@ -1,9 +1,10 @@
-<?
-include_once("startup.php");
-include_once("inc/db.php");
-include_once("inc/base_new.php");
-include_once("inc/uni.php");
-include_once("inc/bonus.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/uni.php");
+include_once(dirname(__DIR__, 2) . "/inc/bonus.php");
 
 
 if(!empty($_REQUEST["id"])) { 
@@ -12,7 +13,7 @@ $phone=phoneClear($_REQUEST["phone"]);
 
 
 
-if($_REQUEST["dell_hostory"]==0) $dell_hostory=0; else $dell_hostory=1;
+if(($_REQUEST["dell_hostory"]??-1)==0) $dell_hostory=0; else $dell_hostory=1;
 
 $store_arr=get_sql_array("city_store", "id", "name", "" );     
 $user_arr=get_sql_array("admin", "id", "name", "" );   
@@ -24,14 +25,15 @@ $phone_user = $db::getValue("SELECT phone FROM users WHERE  phone=? LIMIT 1",[$p
 if(empty($phone_user)) echo"<div class=\"text-center\"><a href=\"/users/add/\" target=new class=\"btn btn-lg btn-success mt-5 mb-5\">Добавить клиента в бонусную</a></div>";
 
 
-$data = $db::getRows("SELECT id,tip, tip_sale, store_id,bonus,date, name,admin_id, check_id, DATE_FORMAT(date,'%d.%m.%Y в %H:%i') as date_h,
-DATE_FORMAT(date_end,'%d.%m.%Y') as date_end, price,price_skidka
+$data = $db::getRows("SELECT id,tip, tip_sale, store_id,bonus,date, name,admin_id, check_id, TO_CHAR(date,'DD.MM.YYYY в HH:MM') as date_h,
+TO_CHAR(date_end,'DD.MM.YYYY') as date_end, price,price_skidka
 FROM users_bonus WHERE  phone=? order by date DESC",[$phone]);
 echo"<table class=\"table table-bordered table-hover table-sm m-0\">
 <thead><th width=120>бонусы</th><th width=150>дата</th><th width=25%>магазин, сотрудник</th><th>наименование</th><th>дата сгорания</th></thead><tbody>";
+$minus = 0;
 foreach ($data as $row)  {
-if($row["tip"]=="plus") {$tip="+"; $store_arr_bonus[$row["store_id"]]["plus"]=$store_arr_bonus[$row["store_id"]]["plus"]+$row["bonus"];} 
-else { $tip="-"; $minus=$minus+$row["bonus"]; $store_arr_bonus[$row["store_id"]]["minus"]=$store_arr_bonus[$row["store_id"]]["minus"]+$row["bonus"];  }
+if($row["tip"]=="plus") {$tip="+"; $store_arr_bonus[$row["store_id"]]["plus"]=($store_arr_bonus[$row["store_id"]]["plus"]??0)+$row["bonus"];}
+else { $tip="-"; $minus=$minus+$row["bonus"]; $store_arr_bonus[$row["store_id"]]["minus"]=($store_arr_bonus[$row["store_id"]]["minus"]??0)+$row["bonus"];  }
 
 echo'<tr class="bg-'; if($row["tip"]=="plus") echo'success';
 if($row["tip"]=="minus") echo'danger';
@@ -107,6 +109,14 @@ $data_v = $db::getRow("SELECT id, date, payments,summ FROM sales WHERE sales_che
 $db::sql("INSERT INTO users_bonus (name, phone,date,store_id,check_id,tip,tip_sale,price,bonus) 
 VALUES ('Возврат по чеку', ?,?,?,?,'minus','vozvrat',?,?)",
 [$phone, $data_v["date"], $row["store_id"], $check_id,$data_v["summ"] ,$row["bonus"] ]);
+
+
+
+
+
+
+
+
 get_bonus_balans($phone, "update");
 }    
     
index 844665dc942988a024cb927d9fb6c233521027be..1cd5efdb1752bd9e698ac8eaedb659255ffd7d81 100644 (file)
@@ -1,10 +1,13 @@
-<?
-include_once("startup.php");
-include_once("inc/db.php");
-include_once("inc/base_new.php");
-if(!empty($_REQUEST["phone"])) { 
+<?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");
+
+if(!empty($_REQUEST["phone"])) {
 $phone=(int)$_REQUEST["phone"];
-$db::sql("INSERT IGNORE INTO users_stop_list (phone,date, admin_id) VALUES (?,NOW(),?)",[$phone,$_SESSION["admin_id"]]);
+$sql = "INSERT INTO users_stop_list (phone, name, date, admin_id) VALUES (?,'bonus/bonus-users',NOW(),?) ON CONFLICT (phone) DO UPDATE SET date=NOW(), admin_id=?";
+$db::sql($sql, [$phone,$_SESSION["admin_id"],$_SESSION["admin_id"]]);
 $db::sql("UPDATE users SET black_list='1' WHERE phone=?",[$phone]);
 echo"Добавлен!";
 
index 194b963b21d1be7a0682824ee0abe112e6815cfd..5e86d74ae76ec212b07e6350934d51e02ae1ac84 100644 (file)
@@ -1,8 +1,10 @@
-<?
-include_once("startup.php");
-include_once("inc/db.php");
-include_once("inc/base_new.php");
-if(!empty($_REQUEST["phone"])) { 
+<?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");
+
+if(!empty($_REQUEST["phone"])) {
 $phone=(int)$_REQUEST["phone"];
 $db::sql("DELETE  FROM users_stop_list WHERE phone=?",[$phone]);
 $db::sql("UPDATE users SET black_list='0' WHERE phone=?",[$phone]);
index 6b5f62f580749386030bbfdf1708843a2b8c307a..a42044d57d52df8cc136e6f40865e0e1e1dacf6c 100644 (file)
@@ -1,16 +1,16 @@
-<?
-include_once("startup.php");
-include_once("inc/db.php");
-include_once("inc/base_new.php");
-include_once("inc/design_new.php");
-include_once("inc/uni2.php");
-include_once("inc/bonus.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_once(dirname(__DIR__, 2) . "/inc/uni2.php");
+include_once(dirname(__DIR__, 2) . "/inc/bonus.php");
 
 global $modul,$act;
 $modul="bonus";
-$act="bonus_users";
+$act="bonus-users";
 
-include"templates/top.php";
 /*
 $arr["bonus"]=rand(10,999);
 $arr["phone"]="7".rand(0,9)."".rand(0,9)."".rand(0,9)."".rand(0,9)."".rand(0,9)."".rand(0,9)."".rand(0,9)."".rand(0,9)."".rand(0,9)."";
@@ -52,7 +52,7 @@ $users_date[$row["user_id"]] .= " <br>".$row["name"]." ".$row["date"]."  ".$row[
 $get="";
 $where=" AND id>? ";
 $binding[]=0;
-
+$search = [];
 if(!empty($_REQUEST["search"])) {
   foreach($_REQUEST["search"] as $pole =>$val) {
    $search[$pole]=$val;   
@@ -72,20 +72,21 @@ if(!empty($_REQUEST["asc_desc"]))  $asc_desc=htmlentities($_REQUEST["asc_desc"])
   
     
     
-$where .="order by $sort_by $asc_desc";
 
 
 // получаем кол-во записей
-$resultNum = $db::getRow("SELECT COUNT(*) as postNum FROM users WHERE 1 $where ",$binding); //'%'.$name.'%'
-$rowCount = $resultNum['postNum'];
+$sql = "SELECT COUNT(*) as postnum FROM users WHERE 1 = 1 $where ";
+$resultNum = $db::getRow($sql,$binding); //'%'.$name.'%'
+$rowCount = $resultNum['postnum'];
 
 $limit = 100;
 $offset = !empty($_GET['p'])?(($_GET['p']-1)*$limit):0;
 $offset=(int)$offset;
 
+$where .="order by $sort_by $asc_desc";
 echo $where;
-$data = $db::getRows("SELECT *,DATE_FORMAT(bdate,'%d.%m.%Y') as bdate2,DATE_FORMAT(date,'%d.%m.%Y %H:%i') as date2 FROM users WHERE 1 $where   LIMIT $offset,$limit",$binding);
-
+$sql = "SELECT *,TO_CHAR(bdate,'DD.MM.YYYY') as bdate2, TO_CHAR(date,'DD.MM.YYYY HH:MM') as date2 FROM users WHERE 1=1 $where   LIMIT $limit OFFSET $offset";
+$data = $db::getRows($sql, $binding);
 echo"<h1>Клиенты в программе лояльности</h1> ";
 // $where ".print_r($binding)."
 //пагинация 
@@ -102,10 +103,10 @@ if(!empty($data))  {
 }   
 
 
-echo"<div class=\"table-rosponsive\"><form method=post action=\"/$modul/$act/\"><table class=\"table table-bordered table-sm\">
-<thead><th>дата добавления</th><th>Клиент <br> <input type=text name=search[name] value=\"".$search["name"]."\">
+echo"<div class=\"table-rosponsive\"><form method=post action=\"/$modul/$act/\">" . '<input type="hidden" name="_csrf" value="' . Yii::$app->request->getCsrfToken() . '" />' . "<table class=\"table table-bordered table-sm\">
+<thead><th>дата добавления</th><th>Клиент <br> <input type=text name=search[name] value=\"".($search["name"] ?? '')."\">
 <button type=submit class=\"btn btn-success btn-sm\">поиск</button>
-</th><th>Телефон <br> <input type=text name=search[phone] value=\"".$search["phone"]."\">
+</th><th>Телефон <br> <input type=text name=search[phone] value=\"".($search["phone"] ?? '')."\">
 <button type=submit class=\"btn btn-success btn-sm\">поиск</button>
 </th><th>продаж</th>
 <th>Даты клиента</th>
@@ -169,9 +170,13 @@ echo'">даты клиента</a></td><td>';
 if($row["bdate"]!='0000-00-00') { 
 
 $barr=explode("-",$row["bdate"]);
-echo '<small>'.$barr[2].'.'.$barr[1].'.'.$barr[0].'</small>';
-$vozrast=date("Y")-$barr[0];
-echo'('.$vozrast.')';
+    if (!empty($barr)) {
+        echo '<small>' . ($barr[2] ?? '') . '.' . ($barr[1] ?? '') . '.' . ($barr[0] ?? '') . '</small>';
+        if (!empty($barr[0])) {
+            $vozrast = date("Y") - (int)($barr[0] ?? 0);
+            echo '(' . $vozrast . ')';
+        }
+    }
 } 
 
 
@@ -180,7 +185,7 @@ echo'</td>
 
 
 <td>'.$row["balans"].' <font color=red>'.$balans.'</font></td><td>'.$row["bonus_minus"].'</td>
-<td> '.$row["referal_id"].'
+<td> '.($row["referal_id"] ?? '').'
  Сума продажи '.$row["sale_price"].'
 ';
 
@@ -212,23 +217,26 @@ $_CONFIG["jscss"]="
 
 <script>
 function ajax_bonus_history(id,phone) {
-
+const param3 = $('meta[name=csrf-param]').attr('content');
+const token3 = $('meta[name=csrf-token]').attr('content');
 $.ajax({
-       url: '/bonus/ajax_bonus_history/',
+       url: '/bonus/ajax-bonus-history/',
        method: 'post',       
        dataType: 'html',        
-       data: {id: ''+id+'',phone: ''+phone+''},  
+       data: {id: ''+id+'',phone: ''+phone+'', [param3]:token3},  
        success: function(data){  
     $('#tr_'+id).after('<tr id=\"trr_'+id+'\" class=\"bg-gray-400\"><td colspan=10>'+data+'</td></tr>');
        }}); 
 }
 
 function ajax_user_add_stop_list(phone) {
+const param3 = $('meta[name=csrf-param]').attr('content');
+const token3 = $('meta[name=csrf-token]').attr('content');
 $.ajax({
-       url: '/bonus/ajax_user_add_stop_list/',
+       url: '/bonus/ajax-user-add-stop-list/',
        method: 'post',       
        dataType: 'html',        
-       data: {phone: ''+phone+''},  
+       data: {phone: ''+phone+'', [param3]:token3},  
        success: function(data){  
     $('#tdstop_'+phone).html(data);
        }}); 
@@ -236,11 +244,13 @@ $.ajax({
 
 
 function ajax_user_remove_stop_list(phone) {
+const param3 = $('meta[name=csrf-param]').attr('content');
+const token3 = $('meta[name=csrf-token]').attr('content');
 $.ajax({
-       url: '/bonus/ajax_user_remove_stop_list/',
+       url: '/bonus/ajax-user-remove-stop-list/',
        method: 'post',       
        dataType: 'html',        
-       data: {phone: ''+phone+''},  
+       data: {phone: ''+phone+'', [param3]:token3},  
        success: function(data){  
     $('#tdstop_'+phone).html(data);
        }}); 
@@ -249,11 +259,13 @@ $.ajax({
 
 
 function ajax_bonus_remove(id) {
+const param3 = $('meta[name=csrf-param]').attr('content');
+const token3 = $('meta[name=csrf-token]').attr('content');
 $.ajax({
-       url: '/bonus/ajax_bonus_remove/',
+       url: '/bonus/ajax-bonus-remove/',
        method: 'post',       
        dataType: 'html',        
-       data: { id: ''+id+''},  
+       data: { id: ''+id+'',[param3]:token3},  
        success: function(data){  
     $('#his'+id).html(data);
        }}); 
@@ -263,12 +275,15 @@ $.ajax({
 
 function ajax_show_check(id) {
  jQuery('#modal-7').modal('show', {backdrop: 'static'}); $('#modal-7 .modal-title').text('');  
+
+const param3 = $('meta[name=csrf-param]').attr('content');
+const token3 = $('meta[name=csrf-token]').attr('content');
+
 $.ajax({
-       url: '/bonus/ajax_show_check/',
+       url: '/bonus/ajax-show-check/',
        method: 'post',       
        dataType: 'html',        
-       data: { id: ''+id+''},  
+       data: { id: ''+id+'', [param3]:token3},  
        success: function(data){  
        $('#modal-7 .modal-body').html(data);
        }}); 
@@ -300,12 +315,12 @@ $.ajax({
                        </div>
                </div>
 
-'; 
+';
+
 
 
 
-include"templates/bottom.php";
+include_once dirname(__DIR__, 2) . '/templates/bottom_light.php';
 
 
 
index 63ee33a3ba45bef9e662b5ac1476f3a95977fe50..1f42c12047f2738d84fdbed023331fde9bfc6739 100644 (file)
@@ -1,136 +1,5 @@
 <?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/uni.php");
-include_once(dirname(__DIR__, 2) . "/inc/bonus.php");
-
-error_reporting(E_ALL ^ E_NOTICE);
-
-
-if(!empty($_REQUEST["id"])) {
-    $user_id=(int)$_REQUEST["id"];
-    $phone=phoneClear($_REQUEST["phone"]);
-
-
-
-    if($_REQUEST["dell_hostory"]==0) $dell_hostory=0; else $dell_hostory=1;
-
-    $store_arr=get_sql_array("city_store", "id", "name", "" );
-    $user_arr=get_sql_array("admin", "id", "name", "" );
-
-
-
-
-    $phone_user = $db::getValue("SELECT phone FROM users WHERE  phone=? LIMIT 1",[$phone]);
-    if(empty($phone_user)) echo"<div class=\"text-center\"><a href=\"/users/add/\" target=new class=\"btn btn-lg btn-success mt-5 mb-5\">Добавить клиента в бонусную</a></div>";
-
-
-    $data = $db::getRows("SELECT id,tip, tip_sale, store_id,bonus,date, name,admin_id, check_id, DATE_FORMAT(date,'%d.%m.%Y в %H:%i') as date_h,
-DATE_FORMAT(date_end,'%d.%m.%Y') as date_end, price,price_skidka
-FROM users_bonus WHERE  phone=? order by date DESC",[$phone]);
-    echo"<table class=\"table table-bordered table-hover table-sm m-0\">
-<thead><th width=120>бонусы</th><th width=150>дата</th><th width=25%>магазин, сотрудник</th><th>наименование</th><th>дата сгорания</th></thead><tbody>";
-    foreach ($data as $row)  {
-        if($row["tip"]=="plus") {$tip="+"; $store_arr_bonus[$row["store_id"]]["plus"]=$store_arr_bonus[$row["store_id"]]["plus"]+$row["bonus"];}
-        else { $tip="-"; $minus=$minus+$row["bonus"]; $store_arr_bonus[$row["store_id"]]["minus"]=$store_arr_bonus[$row["store_id"]]["minus"]+$row["bonus"];  }
-
-        echo'<tr class="bg-'; if($row["tip"]=="plus") echo'success';
-        if($row["tip"]=="minus") echo'danger';
-
-
-        echo'"><td>';
-
-        if($dell_hostory==1)
-            echo'<span id=his'.$row["id"].' onclick="ajax_bonus_remove('.$row["id"].')" class="btn btn-sm btn-danger">X</span>';
-
-
-        echo $tip.' '.$row["bonus"].'<br> от '.(int)$row["price"].'</td>
-<td>'.$row["date_h"].'';
-        if($row["check_id"]) {
-
-
-            echo'<br><span id=ch'.$row["id"].' onclick="ajax_show_check(\''.$row["check_id"].'\')" class="btn btn-sm btn-info">просмотр чека</span> ';
-
-
-            $operation= $db::getValue("SELECT operation FROM sales WHERE id=? LIMIT 1",[$row["check_id"]]);
-
-
-            if($operation=="Удален")  echo'<sapn class="btn btn-lg btn-danger ">'.$operation.'</span> ';
-
-
-
-
-
-        }
-
-
-        $zov='';
-
-        if($row["tip"]=="plus" and $row["tip_sale"]=="sale") {
-            $data_v = $db::getRow("SELECT id, date, payments,summ,sales_check, operation FROM sales WHERE sales_check=? AND sales_check!='' LIMIT 1",[$row["check_id"]]);
-            if(!empty($data_v)) {
-                $paym=json_decode($data_v["payments"],true);
-                $nal=0;
-                $paym_txt='';
-                foreach($paym as $kl =>$arrr) {
-                    if($arrr["type"]=="Наличные") $nal=1;
-                    $paym_txt .='1) Тип: '.$arrr["type"].'  '.$arrr["terminal"].'  Сумма:'.$arrr["summ"].'<br> ';
-                }
-
-
-
-                $zov='<div class="alert alert-danger">По этому чеку был возврат <b>'.$data_v["operation"].'</b><br> Дата: <b>'.$data_v["date"].'<br> '.$paym_txt.'</div>';
-
-                if(!empty($row["check_id"]) and !empty($phone)) {
-                    $id_ol = $db::getValue("SELECT  check_id FROM users_bonus WHERE phone=? AND check_id=? AND tip='minus' 
-AND tip_sale='vozvrat' LIMIT 1",[$phone,$data_v["id"]]);
-                    if(empty($id_ol)) {
-                        $db::sql("INSERT INTO users_bonus (name, phone,date,store_id,check_id,tip,tip_sale,price,bonus) 
-VALUES ('Возврат по чеку', ?,?,?,?,'minus','vozvrat',?,?)",
-                            [$phone, $data_v["date"], $row["store_id"], $data_v["id"],$data_v["summ"] ,$row["bonus"] ]);
-                        get_bonus_balans($phone, "update");
-                    }
-
-                }
-            }
-        }
-
-
-        /*function insert_bonus_vozvrat($phone,$check_id) {
-        global $db;
-        $id_ol = $db::getValue("SELECT  check_id FROM users_bonus WHERE phone=? AND check_id=? AND tip='minus' AND tip_sale='vozvrat' LIMIT 1",[$phone,$check_id]);
-        if(empty($id_ol)) {
-
-        $data_v = $db::getRow("SELECT id, date, payments,summ FROM sales WHERE sales_check=?",[$row["check_id"]]);
-
-
-
-        $db::sql("INSERT INTO users_bonus (name, phone,date,store_id,check_id,tip,tip_sale,price,bonus)
-        VALUES ('Возврат по чеку', ?,?,?,?,'minus','vozvrat',?,?)",
-        [$phone, $data_v["date"], $row["store_id"], $check_id,$data_v["summ"] ,$row["bonus"] ]);
-        get_bonus_balans($phone, "update");
-        }
-
-        }*/
-
-
-        echo'</td>
-<td>'.$store_arr[$row["store_id"]].', '.$user_arr[$row["admin_id"]].'</td>
-<td>'.$row["name"].' Сумма покупки: '.$row["price"].'';
-        $row["price_skidka"]=(int)$row["price_skidka"];
-        if(!empty($row["price_skidka"])) echo'Скидка:'.$row["price_skidka"];
-
-        echo $zov;
-
-        echo'</td><td>'.$row["date_end"].'</td></tr>';
-    }
-
-    echo'<tr><td colspan=2>Итого Списано бонусов: '.$minus.'</td></tr>';
-
-    echo'</tbody></table>';
-
-}
-
+chdir(__DIR__ . '/../../');
 
+include 'modul/bonus/ajax_bonus_history.php';
\ No newline at end of file
diff --git a/erp24/views/bonus/ajax-bonus-history_.php b/erp24/views/bonus/ajax-bonus-history_.php
new file mode 100644 (file)
index 0000000..63ee33a
--- /dev/null
@@ -0,0 +1,136 @@
+<?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/uni.php");
+include_once(dirname(__DIR__, 2) . "/inc/bonus.php");
+
+error_reporting(E_ALL ^ E_NOTICE);
+
+
+if(!empty($_REQUEST["id"])) {
+    $user_id=(int)$_REQUEST["id"];
+    $phone=phoneClear($_REQUEST["phone"]);
+
+
+
+    if($_REQUEST["dell_hostory"]==0) $dell_hostory=0; else $dell_hostory=1;
+
+    $store_arr=get_sql_array("city_store", "id", "name", "" );
+    $user_arr=get_sql_array("admin", "id", "name", "" );
+
+
+
+
+    $phone_user = $db::getValue("SELECT phone FROM users WHERE  phone=? LIMIT 1",[$phone]);
+    if(empty($phone_user)) echo"<div class=\"text-center\"><a href=\"/users/add/\" target=new class=\"btn btn-lg btn-success mt-5 mb-5\">Добавить клиента в бонусную</a></div>";
+
+
+    $data = $db::getRows("SELECT id,tip, tip_sale, store_id,bonus,date, name,admin_id, check_id, DATE_FORMAT(date,'%d.%m.%Y в %H:%i') as date_h,
+DATE_FORMAT(date_end,'%d.%m.%Y') as date_end, price,price_skidka
+FROM users_bonus WHERE  phone=? order by date DESC",[$phone]);
+    echo"<table class=\"table table-bordered table-hover table-sm m-0\">
+<thead><th width=120>бонусы</th><th width=150>дата</th><th width=25%>магазин, сотрудник</th><th>наименование</th><th>дата сгорания</th></thead><tbody>";
+    foreach ($data as $row)  {
+        if($row["tip"]=="plus") {$tip="+"; $store_arr_bonus[$row["store_id"]]["plus"]=$store_arr_bonus[$row["store_id"]]["plus"]+$row["bonus"];}
+        else { $tip="-"; $minus=$minus+$row["bonus"]; $store_arr_bonus[$row["store_id"]]["minus"]=$store_arr_bonus[$row["store_id"]]["minus"]+$row["bonus"];  }
+
+        echo'<tr class="bg-'; if($row["tip"]=="plus") echo'success';
+        if($row["tip"]=="minus") echo'danger';
+
+
+        echo'"><td>';
+
+        if($dell_hostory==1)
+            echo'<span id=his'.$row["id"].' onclick="ajax_bonus_remove('.$row["id"].')" class="btn btn-sm btn-danger">X</span>';
+
+
+        echo $tip.' '.$row["bonus"].'<br> от '.(int)$row["price"].'</td>
+<td>'.$row["date_h"].'';
+        if($row["check_id"]) {
+
+
+            echo'<br><span id=ch'.$row["id"].' onclick="ajax_show_check(\''.$row["check_id"].'\')" class="btn btn-sm btn-info">просмотр чека</span> ';
+
+
+            $operation= $db::getValue("SELECT operation FROM sales WHERE id=? LIMIT 1",[$row["check_id"]]);
+
+
+            if($operation=="Удален")  echo'<sapn class="btn btn-lg btn-danger ">'.$operation.'</span> ';
+
+
+
+
+
+        }
+
+
+        $zov='';
+
+        if($row["tip"]=="plus" and $row["tip_sale"]=="sale") {
+            $data_v = $db::getRow("SELECT id, date, payments,summ,sales_check, operation FROM sales WHERE sales_check=? AND sales_check!='' LIMIT 1",[$row["check_id"]]);
+            if(!empty($data_v)) {
+                $paym=json_decode($data_v["payments"],true);
+                $nal=0;
+                $paym_txt='';
+                foreach($paym as $kl =>$arrr) {
+                    if($arrr["type"]=="Наличные") $nal=1;
+                    $paym_txt .='1) Тип: '.$arrr["type"].'  '.$arrr["terminal"].'  Сумма:'.$arrr["summ"].'<br> ';
+                }
+
+
+
+                $zov='<div class="alert alert-danger">По этому чеку был возврат <b>'.$data_v["operation"].'</b><br> Дата: <b>'.$data_v["date"].'<br> '.$paym_txt.'</div>';
+
+                if(!empty($row["check_id"]) and !empty($phone)) {
+                    $id_ol = $db::getValue("SELECT  check_id FROM users_bonus WHERE phone=? AND check_id=? AND tip='minus' 
+AND tip_sale='vozvrat' LIMIT 1",[$phone,$data_v["id"]]);
+                    if(empty($id_ol)) {
+                        $db::sql("INSERT INTO users_bonus (name, phone,date,store_id,check_id,tip,tip_sale,price,bonus) 
+VALUES ('Возврат по чеку', ?,?,?,?,'minus','vozvrat',?,?)",
+                            [$phone, $data_v["date"], $row["store_id"], $data_v["id"],$data_v["summ"] ,$row["bonus"] ]);
+                        get_bonus_balans($phone, "update");
+                    }
+
+                }
+            }
+        }
+
+
+        /*function insert_bonus_vozvrat($phone,$check_id) {
+        global $db;
+        $id_ol = $db::getValue("SELECT  check_id FROM users_bonus WHERE phone=? AND check_id=? AND tip='minus' AND tip_sale='vozvrat' LIMIT 1",[$phone,$check_id]);
+        if(empty($id_ol)) {
+
+        $data_v = $db::getRow("SELECT id, date, payments,summ FROM sales WHERE sales_check=?",[$row["check_id"]]);
+
+
+
+        $db::sql("INSERT INTO users_bonus (name, phone,date,store_id,check_id,tip,tip_sale,price,bonus)
+        VALUES ('Возврат по чеку', ?,?,?,?,'minus','vozvrat',?,?)",
+        [$phone, $data_v["date"], $row["store_id"], $check_id,$data_v["summ"] ,$row["bonus"] ]);
+        get_bonus_balans($phone, "update");
+        }
+
+        }*/
+
+
+        echo'</td>
+<td>'.$store_arr[$row["store_id"]].', '.$user_arr[$row["admin_id"]].'</td>
+<td>'.$row["name"].' Сумма покупки: '.$row["price"].'';
+        $row["price_skidka"]=(int)$row["price_skidka"];
+        if(!empty($row["price_skidka"])) echo'Скидка:'.$row["price_skidka"];
+
+        echo $zov;
+
+        echo'</td><td>'.$row["date_end"].'</td></tr>';
+    }
+
+    echo'<tr><td colspan=2>Итого Списано бонусов: '.$minus.'</td></tr>';
+
+    echo'</tbody></table>';
+
+}
+
+
index e843cdeaae263527d283e3f628ea017da1dec948..d3c6e7939f0acb9d9be189281cd2013d7f482143 100644 (file)
@@ -7,8 +7,9 @@ include_once(dirname(__DIR__, 2) . "/inc/base_new.php");
 if(!empty($_REQUEST["id"])) {
     $id=(int)$_REQUEST["id"];
 
-    if($_SESSON["group_id"]<3) {
-        $db::sql("DELETE FROM users_bonus WHERE id=? LIMIT 1",[$id]);
+    if($_SESSION["group_id"]<3) {
+        $sql = "DELETE FROM users_bonus WHERE id=?";
+        $db::sql($sql,[$id]);
         echo"Удален $id !";
     }
 
index 6a98477cf43e4fab9f0486caad2d4dee84836d25..c809dc5e4e548ed36447f60695067e1dd3fd9ea1 100644 (file)
@@ -1,17 +1,5 @@
 <?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");
-
-error_reporting(E_ALL ^ E_NOTICE);
-
-if(!empty($_REQUEST["phone"])) {
-    $phone=(int)$_REQUEST["phone"];
-    $db::sql("INSERT IGNORE INTO users_stop_list (phone,date, admin_id) VALUES (?,NOW(),?)",[$phone,$_SESSION["admin_id"]]);
-    $db::sql("UPDATE users SET black_list='1' WHERE phone=?",[$phone]);
-    echo"Добавлен!";
-
-}
-
+chdir(__DIR__ . '/../../');
 
+include 'modul/bonus/ajax_user_add_stop_list.php';
\ No newline at end of file
diff --git a/erp24/views/bonus/ajax-user-add-stop-list_.php b/erp24/views/bonus/ajax-user-add-stop-list_.php
new file mode 100644 (file)
index 0000000..6a98477
--- /dev/null
@@ -0,0 +1,17 @@
+<?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");
+
+error_reporting(E_ALL ^ E_NOTICE);
+
+if(!empty($_REQUEST["phone"])) {
+    $phone=(int)$_REQUEST["phone"];
+    $db::sql("INSERT IGNORE INTO users_stop_list (phone,date, admin_id) VALUES (?,NOW(),?)",[$phone,$_SESSION["admin_id"]]);
+    $db::sql("UPDATE users SET black_list='1' WHERE phone=?",[$phone]);
+    echo"Добавлен!";
+
+}
+
+
index e872a55ca502a29dd64116481adbaf2a671537eb..0f156e4f88432bbc4d4fc506cbba9dc412584028 100644 (file)
@@ -1,17 +1,5 @@
 <?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");
-
-error_reporting(E_ALL ^ E_NOTICE);
-
-if(!empty($_REQUEST["phone"])) {
-    $phone=(int)$_REQUEST["phone"];
-    $db::sql("DELETE  FROM users_stop_list WHERE phone=?",[$phone]);
-    $db::sql("UPDATE users SET black_list='0' WHERE phone=?",[$phone]);
-    echo"Удален из стоп листа!";
-
-}
-
+chdir(__DIR__ . '/../../');
 
+include 'modul/bonus/ajax_user_remove_stop_list.php';
\ No newline at end of file
diff --git a/erp24/views/bonus/ajax-user-remove-stop-list_.php b/erp24/views/bonus/ajax-user-remove-stop-list_.php
new file mode 100644 (file)
index 0000000..e872a55
--- /dev/null
@@ -0,0 +1,17 @@
+<?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");
+
+error_reporting(E_ALL ^ E_NOTICE);
+
+if(!empty($_REQUEST["phone"])) {
+    $phone=(int)$_REQUEST["phone"];
+    $db::sql("DELETE  FROM users_stop_list WHERE phone=?",[$phone]);
+    $db::sql("UPDATE users SET black_list='0' WHERE phone=?",[$phone]);
+    echo"Удален из стоп листа!";
+
+}
+
+
diff --git a/erp24/views/bonus/bonus-users.php b/erp24/views/bonus/bonus-users.php
new file mode 100644 (file)
index 0000000..9535e52
--- /dev/null
@@ -0,0 +1,5 @@
+<?php
+
+chdir(__DIR__ . '/../../');
+
+include 'modul/bonus/bonus_users.php';
\ No newline at end of file