]> gitweb.erp-flowers.ru Git - yii-erp24/.git/commitdiff
api2 edit
authorAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Wed, 3 Apr 2024 17:20:09 +0000 (20:20 +0300)
committerAleksey Filippov <Aleksey.Filippov@erp-flowers.ru>
Wed, 3 Apr 2024 17:20:09 +0000 (20:20 +0300)
erp24/api2/controllers/DataController.php

index 5c8e598255bbfbd9eb909be6f10cb448f0bbbba6..70d7f1776e609cd4e94871dab8467f95309f0d46 100644 (file)
@@ -606,7 +606,27 @@ class DataController extends BaseController {
                 }
             }
 
+            $update = false;
+            if (!empty($start_time) && !empty($end_time)) {
+                $start_time_unix = strtotime($start_time);
+                $startMonth = date("Y-m-01");
+                $end_time_unix = strtotime($end_time);
+                if (
+                    $startMonth <= (date("Y-m-d", strtotime($start_time)))
+                    ||
+                    ($end_time_unix < (time() - 90 * 86400))
+                ) {
+                    $update = true;
+                }
+            }
+            $update = true;
             if (!empty($result['write_offs'])) {
+                if (!empty($start_time)  and !empty($end_time)) {
+                    if ($update) {
+                        WriteOffs::deleteAll(['and', ['>=', 'date', $start_time], ['<=', 'date', $end_time]]);
+                    }
+                }
+
                 foreach ($result["write_offs"] as $gi => $arr) {
                     if (!empty($arr["error"])) {
                         file_put_contents(self::OUT_DIR . '/created_write_offs_erp_error.txt', PHP_EOL . " " . $arr["id"] . " error=" . $arr["error"], FILE_APPEND);
@@ -734,20 +754,6 @@ class DataController extends BaseController {
                 }
             }
 
-            $update = false;
-            if (!empty($start_time) && !empty($end_time)) {
-                $start_time_unix = strtotime($start_time);
-                $startMonth = date("Y-m-01");
-                $end_time_unix = strtotime($end_time);
-                if (
-                    $startMonth <= (date("Y-m-d", strtotime($start_time)))
-                    ||
-                    ($end_time_unix < (time() - 90 * 86400))
-                ) {
-                    $update = true;
-                }
-            }
-
             if (!empty($checks_dell) and !empty($start_time)  and !empty($end_time)) {
                 if ($update) {
                     Sales::updateAll(['operation' => 'Удален'], ['and', ['>=', 'date', $start_time], ['<=', 'date', $end_time]]);