]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
[ERP-393] start testing
authorAlexander Smirnov <fredeom@mail.ru>
Sun, 30 Mar 2025 12:33:34 +0000 (15:33 +0300)
committerAlexander Smirnov <fredeom@mail.ru>
Sun, 30 Mar 2025 12:33:34 +0000 (15:33 +0300)
erp24/actions/orders/DeliveryAction.php
erp24/views/orders/delivery.php
erp24/web/js/orders/delivery.js [new file with mode: 0644]

index fc5ab8e3272ce9cf03d9f274634bdba727ac592f..4a8e4ea7f1c87aa59472b8f80316abdceed2b97f 100644 (file)
@@ -10,6 +10,7 @@ use yii_app\records\Balances;
 use yii_app\records\CityStore;
 use yii_app\records\CreateChecks;
 use yii_app\records\ExportImportTable;
+use yii_app\records\OrdersAmo;
 use yii_app\records\OrdersStatus;
 use yii_app\records\Products1c;
 use yii_app\records\Sales;
@@ -35,8 +36,6 @@ class DeliveryAction extends Action
             }
         }
 
-//        $products=array(); $payment_types=array();
-
         $usersArr = ArrayHelper::map(Products1c::find()->where(['tip' => 'admin'])->all(), 'id', 'name');
         $orderStatuses = OrdersStatus::find()->select(['status_id', 'color', 'name'])->where(['pipeline_id' => 4021495])->all();
         $status_ar = [];
@@ -44,7 +43,8 @@ class DeliveryAction extends Action
             /* @var $orderStatus OrdersStatus */
             if ($orderStatus->status_id == 142) { $orderStatus->name = "Успешно"; }
             if ($orderStatus->status_id == 143) { $orderStatus->name = "Отказ"; }
-            //$status_ar[$row["status_id"]]="<span class=\"tag\" style=\"background:".$row["color"]."\">".$row["name"]."</span>";
+
+            $status_ar[$orderStatus["status_id"]] = "<span class='tag' style='background:" . $orderStatus["color"] . "'>" . $orderStatus["name"] . "</span>";
         }
 
         $lid_id = (int)(Yii::$app->request->post("lid_id") ?? 0);
@@ -108,8 +108,77 @@ class DeliveryAction extends Action
             if (!in_array($checkr["order_id"], $sale)) {
                 $sale[$checkr["order_id"]] = '';
             }
+
+            if ($checkr["operation"] == "Возврат") {
+                $check_vozvrat_cnt[$checkr["order_id"]] = ($check_vozvrat_cnt[$checkr["order_id"]] ?? 0) + 1;
+            }
+            if ($checkr["operation"] == "Продажа") {
+                $check_sale_cnt[$checkr["order_id"]] = ($check_sale_cnt[$checkr["order_id"]] ?? 0) + 1;
+            }
+
+            $cheks_txt = 'ABCDEF';
+
+            $sale[$checkr["order_id"]] = ($sale[$checkr["order_id"]] ?? '') . $cheks_txt;
+        }
+
+        $createChecks2 = CreateChecks::find()->where([">=", 'date', date('Y-m-d H:i:s', strtotime('-30 days', time()))])->all();
+        $create_check_arr = [];
+        foreach($createChecks2 as $createCheck2) {
+            $create_check_arr[$createCheck2->order_id][] = $createCheck2;
+        }
+
+        $ordersAmoQuery = OrdersAmo::find()->where(['<=', 'delivery_date', date('Y-m-d H:i:s', time())]);
+        if (!empty($lid_id)) {
+            $ordersAmoQuery->andWhere(['id' => $lid_id]);
+        } elseif (!empty($amo_id)) {
+            $ordersAmoQuery->andWhere(['amo_id' => $amo_id]);
+        } else {
+            $statuses = ['142'];
+            foreach($_REQUEST["statuses"] ?? [] as $is => $idf)  {
+                if ($idf == 'on') {
+                    $statuses [] = $is;
+                }
+            }
+            $ordersAmoQuery->andWhere(['status_id' => $statuses]);
+            if (!empty($delivery_date)) {
+                $ordersAmoQuery->andWhere(['delivery_date' => $delivery_date]);
+            }
+        }
+
+        $ordersAmo = $ordersAmoQuery->orderBy(['delivery_date' => SORT_DESC, 'updated_at' => SORT_DESC])->limit(1750)->asArray()->all();
+
+        $in_orders = [];
+        $yeses = [];
+        $itog = 0;
+        $seller_id = [];
+        $ords = [];
+        foreach ($ordersAmo as $orderAmo) {
+            $yes=0;
+            if (!empty($sale[$orderAmo["id"]])) {
+                $yes=1;
+            }
+            if (!empty($sale[$orderAmo["amo_id"]])) {
+                $yes=1;
+            }
+            $yeses [] = $yes;
+
+            $itog += $orderAmo["price"];
+
+            $in_orders[] = $orderAmo["amo_id"];
+
+            $seller_idRec = ExportImportTable::find()->select(['export_val'])->where(['entity' => 'admin', 'export_id' => 1, 'entity_id' => $orderAmo["florist_id"]])->one();
+            $seller_id []= $seller_idRec ? $seller_idRec->export_val : null;
+
+            $ordRec = Sales::find()->select('order_id')->where(['order_id' => $orderAmo["amo_id"]])
+                ->andWhere(['>', 'order_id', 0])->orderBy(['date' => SORT_DESC])->one();
+            $ords []= $ordRec ? $ordRec->order_id : null;
+
+//            $summ_all = $orderAmo["price"] + $orderAmo["price_dostavka"] + $orderAmo["price_dostavka_povtor"];
         }
 
-        return $this->controller->render('delivery', compact('yesses', 'lid_id', 'delivery_date', 'status_ar2'));
+        return $this->controller->render('delivery', compact('yesses', 'lid_id',
+            'delivery_date', 'status_ar', 'status_ar2', 'checkarr', 'ordersAmo', 'yeses', 'in_orders',
+            'users_arr_group_3_plus', 'check_sale_cnt', 'check_vozvrat_cnt', 'exportStore', 'storesNameArr',
+            'balancesAll', 'services', 'seller_id', 'create_check_arr', 'usersArr', 'ords', 'itog'));
     }
 }
index 7efe1cf682e160637c853c782aeb45d7107bda71..f5ad520336273be23daa9a16c9c8978c17416f67 100644 (file)
@@ -6,7 +6,34 @@ use yii\widgets\ActiveForm;
 /* @var $yesses array */
 /* @var $lid_id int */
 /* @var $delivery_date string */
+/* @var $status_ar array */
 /* @var $status_ar2 array */
+/* @var $checkarr array */
+/* @var $ordersAmo array */
+/* @var $yeses array */
+/* @var $in_orders array */
+/* @var $users_arr_group_3_plus array */
+/* @var $check_sale_cnt array */
+/* @var $check_vozvrat_cnt array */
+/* @var $exportStore array */
+/* @var $storesNameArr array */
+/* @var $balancesAll array */
+/* @var $services array */
+/* @var $seller_id array */
+/* @var $create_check_arr array */
+/* @var $usersArr array */
+/* @var $ords array */
+/* @var $itog double */
+
+$this->registerJsFile('/js/orders/delivery.js', ['position' => \yii\web\View::POS_END]);
+
+$this->registerCss('
+    .table td table.table-products tbody tr td {
+        padding:0;
+        margin:0;
+        font-size:11px;
+    }
+')
 
 ?>
 
@@ -63,4 +90,172 @@ use yii\widgets\ActiveForm;
 
     <?php ActiveForm::end() ?>
 
+    <details><summary>SQL</summary>SELECT *, TO_CHAR(delivery_date, 'DD.MM.YYYY') as dated FROM orders_amo
+        WHERE $WHERE AND delivery_date <= NOW() order by delivery_date DESC, updated_at DESC LIMIT 1750</details>
+
+    <br><span><b> всего <?= count($ordersAmo) ?></b></span>
+
+    <table class="table table-hover">
+        <tbody>
+        <?php foreach ($ordersAmo as $ind => $orderAmo): ?>
+            <tr>
+                <td class="bg-<?= $yeses[$ind] ? "danger" : "success" ?>">
+                    <a href="https://bazacvetov24.amocrm.ru/leads/detail/<?= $orderAmo["amo_id"] ?>" target=new><b><?= $orderAmo["dated"] ?></b></a>
+                    <?= $orderAmo["updated_at"] ?> <br> <?= $orderAmo["delivery"] . ' ' . $orderAmo["delivery_time"] ?>
+                    <?php if ($orderAmo["store"] != "" && $orderAmo["store"] != "ул. Аэродромная, 28"): ?>
+                        <span class="btn btn-warning btn-sm"><?= $orderAmo["store"] ?></span>
+                        <?php if ($orderAmo["delivery"] == "Доставка" || $orderAmo["delivery"] == "Такси"): ?>
+                            ---
+                        <?php endif; ?>
+                    <?php endif; ?>
+                </td>
+                <td <?= in_array($orderAmo["amo_id"], $in_orders) ? "class=\"bg-danger\"" : "" ?> >
+                    <?= $orderAmo["id"] . " / " . $orderAmo["amo_id"] ?>
+                    <?= $status_ar[$orderAmo["status_id"]] . ' ' . ($users_arr_group_3_plus[$orderAmo["florist_id"]] ?? '') ?>
+                    <?php if (empty($orderAmo["florist_id"])): ?><span class="btn btn-danger">флорист в амо не указан</span><?php endif; ?>
+                </td>
+                <td>
+                    <b><?= $orderAmo["price"] ?></b> yes=<?= $yeses[$ind] . ' ' . $orderAmo["store"] . ' ' . $orderAmo["delivery_adress"] ?>
+                    <?php if (($store_arr[$orderAmo["store_id"]] ?? '' == "ул. Аэродромная 28 (к-р Москва)" ||
+                                $orderAmo["store"] == "ул. Аэродромная, 28" || $orderAmo["store"] == "") && $yeses[$ind] == 1 && $orderAmo["payment_type_id"] != "Оплачен в магазине"): ?>
+                        <?php if ($check_vozvrat_cnt[$orderAmo["id"]] >= $check_sale_cnt[$orderAmo["id"]]): ?>
+                            возвратов <?= $check_vozvrat_cnt[$orderAmo["id"]] ?> чеков <?= $check_sale_cnt[$orderAmo["id"]] ?>
+                        <?php endif ?>
+                    <?php endif ?>
+                    <?php
+                        $products = [];
+                        $products_json = json_decode($orderAmo["products_json"], true);
+                    ?>
+                    <?php if (!empty($products_json)): ?>
+                        <table class="table-products">
+                            <thead>
+                                <tr>
+                                    <th>кол-во</th>
+                                    <th>наименование</th>
+                                    <th>цвет</th>
+                                    <th>цена</th>
+                                    <th>остаток</th>
+                                </tr>
+                            </thead>
+                            <tbody>
+                                <?php $pickup = false; ?>
+                                <?php if ($orderAmo["store"] != "" && $orderAmo["store"] != "ул. Аэродромная, 28") { $pickup=true; } ?>
+                                <?php foreach($products_json as $k => $arp): ?>
+                                    <?php foreach($arp["items"] as $item): ?>
+                                        <?php if (isset($item["color_id"])): ?>
+                                            <?php
+                                                $products[$item["guid"]][$item["color_id"]] = ($products[$item["guid"]][$item["color_id"]] ?? 0) + $item["quantity"];
+                                            ?>
+                                        <?php endif; ?>
+                                        <?php
+                                            $quantity=str_replace(".00","",$item["quantity"]);
+                                            $bal = isset($storesNameArr[$row["store"]]) ? $balancesAll[$exportStore[$storesNameArr[$orderAmo["store"]]]][$item["guid"]] ?? 0 : 0;
+                                        ?>
+                                        <tr <?php if ($bal < $quantity && !in_array($item["guid"], $services)): ?>class="bg-danger"<?php endif; ?> >
+                                            <td class="text-center"><b class="mr-2 ml-2"><?= $quantity ?></b></td>
+                                            <td class="text-left"><?= $item["name"] ?></td><td><?= ($item["color_id"] ?? '') ?></td>
+                                            <td class="text-center"><?= str_replace(".00","",$item["price"]) ?></td>
+                                            <td><?= $bal ?></td>
+                                        </tr>
+                                    <?php endforeach; ?>
+                                <?php endforeach; ?>
+                            </tbody>
+                        </table>
+                    <?php endif; ?>
+                    <?php if ($yeses[$ind] == 2): ?>
+                        <span style="color: red">Сумма в чеке больше суммы заказ это норм!</span>
+                    <?php endif; ?>
+                </td>
+                <td>
+                    <?php if (empty($seller_id[$ind])): ?>
+                        <span class="p-1 m-1 bg-danger color-white">Укажите верного ID флориста в АМО! И обновите данные
+                            по заказам - иначе чек не пробьется! У каждого чека должен быть актуальный продавец</span>
+                    <?php endif; ?>
+                    <div class="row">
+                        <div class="col-6">
+                            <?= $orderAmo["payment_type_id"] ?>
+                            <?php if ($store_arr[$orderAmo["store_id"]] ?? '' != "ул. Аэродромная 28 (к-р Москва)" &&
+                                !empty($store_arr[$orderAmo["store_id"]])): ?>
+                                <span class="m-1 btn btn-sm btn-warning"><?= $store_arr[$orderAmo["store_id"]] ?></span>
+                            <?php endif; ?>
+                        </div>
+                        <div class="col-6 text-right">
+                            <?php if (!empty($users_arr[$orderAmo["florist_id"]])): ?>
+                                Флорист <?= $users_arr[$orderAmo["florist_id"]] ?>
+                            <?php endif; ?>
+                            <?php if (!empty($users_arr[$orderAmo["courier_id"]])): ?>
+                                Курьер <?= $users_arr[$orderAmo["courier_id"]] ?>
+                            <?php endif; ?>
+                        </div>
+                    </div>
+                    <div class="row">
+                        <?php
+                            $create_check = 0;
+                            $ids_arr = [$orderAmo["amo_id"]];
+                            if ($orderAmo["id"] != $orderAmo["amo_id"]) {
+                                $ids_arr = [$orderAmo["amo_id"], $orderAmo["id"]];
+                            }
+                        ?>
+                        <?php foreach($ids_arr as $val_id): ?>
+                            <?php if (empty($sale[$val_id])): ?>
+                                <?php foreach($create_check_arr[$val_id] ?? [] as $create_check_row ): ?>
+                                    <?php
+                                        $yescheck = 0;
+                                        foreach($create_check_arr[$val_id] as $sl) {
+                                            if ($sl["sales_check"] == $create_check_row["check_id"]) {
+                                                $yescheck = 1;
+                                            }
+                                        }
+                                    ?>
+                                    <div onmouseover="$('#check__<?= $create_check_row["check_id"] ?>').show();"
+                                         onclick="$('#check__<?= $create_check_row["check_id"] ?>').show();"
+                                         class="col text-center p-1 m-1 bg-<?= $create_check_row["type"] == "Продажа" ? "success" : "warning" ?>"
+                                         <?= $yescheck || $create_check_row["type"] == "Возврат" ? "style='opacity:0.3'" : "" ?>
+                                    >
+                                        <?php if ($create_check_row["status"] == 1): ?>
+                                            Пробит
+                                        <?php else: ?>
+                                            <span class="bg bg-danger p-2 color-white">Создан - находится в очереди на пробитие в 1с</span>
+                                        <?php endif; ?>
+                                        <?php $create_check++; ?>
+                                        <?= $create_check_row["type"] ?>
+                                        <?= $create_check_row["date"] ?>
+                                        <?= $create_check_row["name"] ?>
+                                        продавец
+                                        <?php if (!empty($create_check_row)): ?>
+                                            <?php if (array_key_exists($create_check_row["seller_id"], $usersArr)): ?>
+                                                <?= $usersArr[$create_check_row["seller_id"]] ?>
+                                            <?php else: ?>
+                                                <?= $create_check_row["seller_id"] ?>
+                                            <?php endif; ?>
+                                        <?php endif; ?>
+                                        <?php if ($create_check_row["type"] == "Продажа"): ?>
+                                            <span style="display:none;" id="check__<?= $create_check_row["check_id"] ?>" class="m-1 btn btn-sm btn-danger" onclick="ajax_return_check('<?= $create_check_row["check_id"] ?>'); $(this).hide();">сделать возврат</span>
+                                        <?php endif; ?>
+                                    </div>
+                                <?php endforeach; ?>
+                            <?php else: ?>
+                                <?= $sale[$val_id] ?>
+                            <?php endif; ?>
+                        <?php endforeach; ?>
+                        <?php if (!empty($orderAmo["products_json"])): ?>
+                            <?php if (($store_arr[$orderAmo["store_id"]] ?? '' == "ул. Аэродромная 28 (к-р Москва)" ||
+                                $orderAmo["store"] == "ул. Аэродромная, 28" || $orderAmo["store"] == "") && $yeses[$ind] == 0 &&
+                                $orderAmo["payment_type_id"] != "Оплачен в магазине"): ?>
+                                <?php if ($create_check > 0 && $ords[$ind] && $seller_id[$ind]): ?>
+                                    <button class="btn btn-sm btn-danger btn__<?= $orderAmo["amo_id"] ?>"
+                                            onclick="ajax_create_check_json('<?= $orderAmo["amo_id"] ?>');">пробить чек</button>
+                                <?php endif; ?>
+                            <?php endif; ?>
+                        <?php else: ?>
+                            Нужно провести заказ в amo по новой системе - добавить состав
+                        <?php endif; ?>
+                    </div>
+                </td>
+            </tr>
+        <?php endforeach; ?>
+        </tbody>
+    </table>
+    Итого <?= $itog ?> руб. всего <?= $cnt ?>
+
 </div>
diff --git a/erp24/web/js/orders/delivery.js b/erp24/web/js/orders/delivery.js
new file mode 100644 (file)
index 0000000..09b7f6f
--- /dev/null
@@ -0,0 +1,91 @@
+/* jshint esversion: 6 */
+
+function ajax_return_check(sales_check) {
+    const $mainModal = $('#mainModal');
+    const $modalBody = $mainModal.find('.modal-body');
+    const $modalFooter = $mainModal.find('.modal-footer');
+    $mainModal.find('.close').on('click', () => { $mainModal.modal('hide'); });
+    $mainModal.find('.modal-title').html('');
+    $modalFooter.html('');
+    $mainModal.modal('show');
+
+    const param3 = $('meta[name=csrf-param]').attr('content');
+    const token3 = $('meta[name=csrf-token]').attr('content');
+    $.ajax({
+        url: '/orders/ajax-return-check/',
+        method: 'post',
+        dataType: 'html',
+        data: { sales_check: sales_check, [param3]: token3},
+        success: function(data){
+            $modalBody.html(data);
+            $('#check__' + sales_check).remove();
+        }});
+}
+
+function ajax_create_check(order_id) {
+    const $mainModal = $('#mainModal');
+    const $modalBody = $mainModal.find('.modal-body');
+    const $modalFooter = $mainModal.find('.modal-footer');
+    $mainModal.find('.close').on('click', () => { $mainModal.modal('hide'); });
+    $mainModal.find('.modal-title').html('');
+    $modalFooter.html('');
+    $mainModal.modal('show');
+
+    const param3 = $('meta[name=csrf-param]').attr('content');
+    const token3 = $('meta[name=csrf-token]').attr('content');
+    $.ajax({
+        url: '/orders/ajax-create-check/',
+        method: 'post',
+        dataType: 'html',
+        data: { order_id: order_id, create_check: '2', [param3]: token3 },
+        success: function(data) {
+            $modalBody.html(data);
+            $('.btn__' + order_id).hide();
+        }});
+}
+
+
+
+
+function ajax_create_check_json(order_id) {
+    const $mainModal = $('#mainModal');
+    const $modalBody = $mainModal.find('.modal-body');
+    const $modalFooter = $mainModal.find('.modal-footer');
+    $mainModal.find('.close').on('click', () => { $mainModal.modal('hide'); });
+    $mainModal.find('.modal-title').html('');
+    $modalFooter.html('');
+    $mainModal.modal('show');
+
+    const param3 = $('meta[name=csrf-param]').attr('content');
+    const token3 = $('meta[name=csrf-token]').attr('content');
+    $.ajax({
+        url: '/orders/ajax-create-check-json/',
+        method: 'post',
+        dataType: 'html',
+        data: { order_id: order_id, create_check: '2', [param3]: token3 },
+        success: function(data){
+            $modalBody.html(data);
+            $('.btn__' +order_id).hide();
+        }});
+}
+
+function ajax_check_remove(order_id) {
+    const $mainModal = $('#mainModal');
+    const $modalBody = $mainModal.find('.modal-body');
+    const $modalFooter = $mainModal.find('.modal-footer');
+    $mainModal.find('.close').on('click', () => { $mainModal.modal('hide'); });
+    $mainModal.find('.modal-title').html('');
+    $modalFooter.html('');
+    $mainModal.modal('show');
+
+    const param3 = $('meta[name=csrf-param]').attr('content');
+    const token3 = $('meta[name=csrf-token]').attr('content');
+    $.ajax({
+        url: '/orders/ajax-check-remove/',
+        method: 'post',
+        dataType: 'html',
+        data: { order_id: order_id, [param3]: token3},
+        success: function(data) {
+            $modalBody.html(data);
+        }});
+}