]> gitweb.erp-flowers.ru Git - erp24_rep/yii-erp24/.git/commitdiff
Merge branch 'develop' into feature-zozirova-erp_256-send_doc_on_1c
authormarina <m.zozirova@gmail.com>
Wed, 18 Dec 2024 10:04:13 +0000 (13:04 +0300)
committermarina <m.zozirova@gmail.com>
Wed, 18 Dec 2024 10:04:13 +0000 (13:04 +0300)
# Conflicts:
# erp24/api2/controllers/DataController.php

1  2 
erp24/api2/controllers/DataController.php

index 34563df8e3c08fabfc4cc6ccfe2d2096b3a83b62,af1e063db9e1e865fd766ba521c4549b543d83bc..49ed92acc41628574ee5df768f955ffa93986844
@@@ -56,13 -53,11 +58,12 @@@ class DataController extends BaseContro
  
      const OUT_DIR =
  //        __DIR__ . "/../json";
 -    //    "/www/api2/json";
 -   "/var/www/erp24/api2/json";
 +        //    "/www/api2/json";
 +        "/var/www/erp24/api2/json";
  //          "/var/www/www-root/data/www/api.bazacvetov24.ru/data/json";
  
 -    public function actionRequest() {
 +    public function actionRequest()
 +    {
          Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
  
          $request = Yii::$app->request->getRawBody();
          }
      }
  
 -    private function getWaybillIncomingSetStatusSend($waybillIncomingIds) {
+     private function getWaybillWriteOffsSetStatusSend($waybillWriteOffIds) {
+         try {
+             $waybillWriteOffsErp = WaybillWriteOffs::find()->where(['in', 'id', $waybillWriteOffIds])->all();
+             foreach ($waybillWriteOffsErp as $waybillWriteOffsErpElem) {
+                 $waybillWriteOffsErpElem->status = WriteOffsErp::STATUS_SEND;
+                 $waybillWriteOffsErpElem->send_at = date('Y-m-d H:i:s');
+                 $waybillWriteOffsErpElem->save();
+                 if ($waybillWriteOffsErpElem->getErrors()) {
+                     LogService::apiErrorLog(json_encode(["error_id" => 2, "error" => $waybillWriteOffsErpElem->getErrors()], JSON_UNESCAPED_UNICODE));
+                 }
+             }
+         } catch (Exception $e3) {
+             file_put_contents(self::OUT_DIR . '/log_created_write_offs_erp_error.txt', PHP_EOL . date("d.m.Y H:i:s",time()). $e3->getMessage(), FILE_APPEND);
+         }
+     }
 +    private function getWaybillIncomingSetStatusSend($waybillIncomingIds)
 +    {
          try {
              $waybillIncoming = WaybillIncoming::find()->where(['in', 'id', $waybillIncomingIds])->all();
              foreach ($waybillIncoming as $waybillIncomingElem) {
                  }
              }
  
+             $waybillWriteOffs = WaybillWriteOffs::find()
+                 ->select([
+                     'id',
+                     'guid',
+                     'store_guid',
+                     'number',
+                     'date',
+                     'status',
+                     'comment',
+                     'quantity',
+                     'summ'
+                 ])
+                 ->where(['status' => WriteOffsErp::STATUS_CONFIRM])
+                 ->asArray()
+                 ->all();
+             if (!empty($waybillWriteOffs)) {
+                 $waybillWriteOffIds = array_column($waybillWriteOffs, 'id');
+                 $additionalProducts = WaybillWriteOffsProducts::find()
+                     ->select(['waybill_write_offs_id', 'product_id', 'product_count', 'product_price', 'summ'])
+                     ->where(['in', 'waybill_write_offs_id', $waybillWriteOffIds])
+                     ->asArray()
+                     ->all();
+                 $waybillWriteOffProducts = [];
+                 foreach ($additionalProducts as $product) {
+                     $waybillWriteOffProducts[$product['waybill_write_offs_id']][] = [
+                         'product_id' => $product['product_id'],
+                         'quantity' => (string) $product['product_count'],
+                         'price' => $product['product_price'],
+                     ];
+                 }
+                 foreach ($waybillWriteOffs as $row) {
+                     $waybillProductsRow = $waybillWriteOffProducts[$row['id']] ?? [];
+                     $writeOffResult[] = [
+                         'id' => $row['guid'],
+                         'store_id' => $row['store_guid'],
+                         'type' => 'ревизия при передаче смены',
+                         'cause' => 'Документ ревизии при передаче смены в ERP ' . $row['number'],
+                         'items' => $waybillProductsRow,
+                         'summ' => $row['summ'],
+                         'comment' => $row['comment'],
+                     ];
+                 }
+             }
          } catch (Exception $e3) {
 -            file_put_contents(self::OUT_DIR . '/log_created_write_offs_erp_error.txt', PHP_EOL . date("d.m.Y H:i:s",time()). $e3->getMessage(). ' file: '. $e3->getFile() . ' line: '. $e3->getLine(), FILE_APPEND);
 +            file_put_contents(self::OUT_DIR . '/log_created_write_offs_erp_error.txt', PHP_EOL . date("d.m.Y H:i:s", time()) . $e3->getMessage() . ' file: ' . $e3->getFile() . ' line: ' . $e3->getLine(), FILE_APPEND);
          }
  
          return [
                                      }
                                  }
                              }
-                             /** @var WriteOffsErp $writeOffsErp */
-                             $writeOffsErp->status = WriteOffsErp::STATUS_ERROR_1С;
-                             $writeOffsErp->error_text = $errorText;
-                             $writeOffsErp->save();
-                             if ($writeOffsErp->getErrors()) {
-                                 LogService::apiErrorLog(
-                                     json_encode(
-                                         ["error_id" => 11, "error" => $writeOffsErp->getErrors()],
-                                         JSON_UNESCAPED_UNICODE
-                                     )
-                                 );
+                             if (!empty($writeOffsErp)) {
+                                 /** @var WriteOffsErp $writeOffsErp */
+                                 $writeOffsErp->status = WriteOffsErp::STATUS_ERROR_1С;
+                                 $writeOffsErp->error_text = $errorText;
+                                 $writeOffsErp->save();
+                                 if ($writeOffsErp->getErrors()) {
+                                     LogService::apiErrorLog(
+                                         json_encode(
+                                             ["error_id" => 11, "error" => $writeOffsErp->getErrors()],
+                                             JSON_UNESCAPED_UNICODE
+                                         )
+                                     );
+                                 }
+                             }
+                             if (!empty($waybillWriteOffsErp)) {
+                                 /** @var WaybillWriteOffs $waybillWriteOffsErp */
+                                 $waybillWriteOffsErp->status = WriteOffsErp::STATUS_ERROR_1С;
+                                 $waybillWriteOffsErp->save();
+                                 if ($waybillWriteOffsErp->getErrors()) {
+                                     LogService::apiErrorLog(
+                                         json_encode(
+                                             ["error_id" => 11, "error" => $waybillWriteOffsErp->getErrors()],
+                                             JSON_UNESCAPED_UNICODE
+                                         )
+                                     );
+                                 }
                              }
                          } else {
-                             /** @var WriteOffsErp $writeOffsErp */
-                             $writeOffsErp->status = WriteOffsErp::STATUS_CREATED_1С;
-                             $writeOffsErp->number_1c = $arr["number"] ?? '';
-                             $writeOffsErp->save();
-                             if ($writeOffsErp->getErrors()) {
-                                 LogService::apiErrorLog(
-                                     json_encode(
-                                         ["error_id" => 11,
-                                             "error" => $writeOffsErp->getErrors()],
-                                         JSON_UNESCAPED_UNICODE
-                                     )
-                                 );
+                             if (!empty($writeOffsErp)) {
+                                 /** @var WriteOffsErp $writeOffsErp */
+                                 $writeOffsErp->status = WriteOffsErp::STATUS_CREATED_1С;
+                                 $writeOffsErp->number_1c = $arr["number"] ?? '';
+                                 $writeOffsErp->save();
+                                 if ($writeOffsErp->getErrors()) {
+                                     LogService::apiErrorLog(
+                                         json_encode(
+                                             [
+                                                 "error_id" => 11,
 -                                                "error" => $writeOffsErp->getErrors()
++                                            "error" => $writeOffsErp->getErrors()
+                                             ],
+                                             JSON_UNESCAPED_UNICODE
+                                         )
+                                     );
+                                 }
+                             }
+                             if (!empty($waybillWriteOffsErp)) {
+                                 /** @var WaybillWriteOffs $waybillWriteOffsErp */
+                                 $waybillWriteOffsErp->status = WriteOffsErp::STATUS_CREATED_1С;
+                                 $waybillWriteOffsErp->number_1c = $arr["number"] ?? '';
+                                 $waybillWriteOffsErp->save();
+                                 if ($waybillWriteOffsErp->getErrors()) {
+                                     LogService::apiErrorLog(
+                                         json_encode(
+                                             [
+                                                 "error_id" => 11,
+                                                 "error" => $waybillWriteOffsErp->getErrors()
+                                             ],
+                                             JSON_UNESCAPED_UNICODE
+                                         )
+                                     );
+                                 }
                              }
  
                          }
      }
  
  
 -
      private function insertDataSales($values, $tableName, $columns, $chunks = 1000)
-     {
-         $chunkValues = array_chunk($values, $chunks);
++
+         {
+             $chunkValues = array_chunk($values, $chunks);
  
 -            foreach ($chunkValues as $key => $rows) {
 -                try {
 -                    $transaction = \Yii::$app->db->beginTransaction();
 -                    Yii::$app->db->createCommand()->batchInsert($tableName, $columns, $rows)->execute();
 -                    $transaction->commit();
 -                } catch (Exception $e) {
 -                    $errorString = substr($e->getMessage(), 0, 2000);
 -                    file_put_contents(
 -                        self::OUT_DIR . '/error_upload.txt',
 -                        PHP_EOL . $errorString,
 -                        FILE_APPEND
 -                    );
 -                    $transaction->rollBack();
 -                    InfoLogService::setInfoLog(__FILE__, __LINE__, $tableName, 'error_id_25');
 -                    InfoLogService::setInfoLog(__FILE__, __LINE__, $errorString, 'error_id_25_22');
 -                    LogService::apiErrorLog(
 -                        json_encode(["error_id" => 25, "error" => $errorString], JSON_UNESCAPED_UNICODE)
 +        foreach ($chunkValues as $key => $rows) {
 +
 +            try {
 +                $transaction = \Yii::$app->db->beginTransaction();
 +                Yii::$app->db->createCommand()->batchInsert($tableName, $columns, $rows)->execute();
 +                $transaction->commit();
 +            } catch (Exception $e) {
 +                $errorString = substr($e->getMessage(), 0, 2000);
 +                file_put_contents(self::OUT_DIR . '/error_upload.txt',
-                     PHP_EOL . $errorString, FILE_APPEND);
-                 $transaction->rollBack();
++                    PHP_EOL . $errorString, FILE_APPEND
++                );$transaction->rollBack();
 +                InfoLogService::setInfoLog(__FILE__, __LINE__, $tableName, 'error_id_25');
 +                InfoLogService::setInfoLog(__FILE__, __LINE__, $errorString, 'error_id_25_22');
-                 LogService::apiErrorLog(json_encode(["error_id" => 25, "error" => $errorString], JSON_UNESCAPED_UNICODE));
++                LogService::apiErrorLog(json_encode(["error_id" => 25, "error" => $errorString], JSON_UNESCAPED_UNICODE)
+                     );
 -                }
              }
          }
 +    }
  }