From 012ceea51cffb4a5129cb77024a5b69aff9db7fe Mon Sep 17 00:00:00 2001 From: Alexander Smirnov Date: Mon, 16 Dec 2024 15:50:41 +0300 Subject: [PATCH] =?utf8?q?[ERP-261]=20=D0=BE=D1=82=D0=BF=D1=80=D0=B0=D0=B2?= =?utf8?q?=D0=BA=D0=B0=20=D0=B2=201=D1=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- erp24/api2/controllers/DataController.php | 103 ++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/erp24/api2/controllers/DataController.php b/erp24/api2/controllers/DataController.php index a54c78b5..bbd1af1f 100644 --- a/erp24/api2/controllers/DataController.php +++ b/erp24/api2/controllers/DataController.php @@ -38,6 +38,8 @@ use yii_app\records\SelfCostProduct; //use yii_app\records\SalesProductsUpdate; use yii_app\records\SalesUpdate; use yii_app\records\Terminals; +use yii_app\records\WaybillIncoming; +use yii_app\records\WaybillIncomingProducts; use yii_app\records\WriteOffs; use yii_app\records\WriteOffsErp; use yii_app\records\WriteOffsProducts; @@ -134,6 +136,14 @@ class DataController extends BaseController { $mess['create_write_offs'] = $writeOff; } + $waybillIncomingArray = $this->getWaybillIncomingDoc(); + $waybillIncoming = $waybillIncomingArray['waybillIncoming']; + $waybillIncomingIds = $waybillIncomingArray['waybillIncomingIds']; + + if (!empty($waybillIncoming)) { + $mess['create_waybill_incoming'] = $waybillIncoming; + } + $createEmployeeArray = $this->getCreateEmployee(); if (!empty($createEmployeeArray)) { $mess['create_employee'] = $createEmployeeArray; @@ -182,6 +192,9 @@ class DataController extends BaseController { if (!empty($writeOffIds) && !empty($writeOff)) { $this->getWriteOffsSetStatusSend($writeOffIds); } + if (!empty($waybillIncomingIds) && !empty($waybillIncoming)) { + $this->getWaybillIncomingSetStatusSend($waybillIncomingIds); + } $json = json_encode($mess, JSON_UNESCAPED_UNICODE); } // @@ -219,6 +232,22 @@ class DataController extends BaseController { } } + private function getWaybillIncomingSetStatusSend($waybillIncomingIds) { + try { + $waybillIncoming = WaybillIncoming::find()->where(['in', 'id', $waybillIncomingIds])->all(); + foreach ($waybillIncoming as $waybillIncomingElem) { + $waybillIncomingElem->status = 3; + $waybillIncomingElem->send_at = date('Y-m-d H:i:s'); + $waybillIncomingElem->save(); + if ($waybillIncomingElem->getErrors()) { + LogService::apiErrorLog(json_encode(["error_id" => 2.5, "error" => $waybillIncomingElem->getErrors()], JSON_UNESCAPED_UNICODE)); + } + } + } catch (Exception $e3) { + file_put_contents(self::OUT_DIR . '/log_created_waybill_incoming_error.txt', PHP_EOL . date("d.m.Y H:i:s",time()). $e3->getMessage(), FILE_APPEND); + } + } + private function getWriteOffsDoc() : array { $writeOff = []; @@ -306,6 +335,80 @@ class DataController extends BaseController { ]; } + private function getWaybillIncomingDoc() : array { + $waybillIncoming = []; + $waybillIncomingIds = []; + $waybillIncomingResult = []; + + try { + $waybillIncoming = WaybillIncoming::find() + ->select([ + 'id', + 'guid', + 'store_guid', + 'number', + 'date', +// 'write_offs_type', + 'comment', + 'quantity', + 'summ' + ]) + ->indexBy('id') + ->andWhere(['and', ['status' => 2], ['active' => 1]]) + ->asArray() + ->all(); + + if (!empty($waybillIncoming)) { + $waybillIncomingIds = array_column($waybillIncoming, 'id'); + + $products = WaybillIncomingProducts::find() + ->select(['waybill_incoming_id', 'product_id', 'product_count', 'product_price', 'summ']) + ->where(['in', 'waybill_incoming_id', $waybillIncomingIds]) +// ->andWhere(['active_product' => 1]) + ->asArray() + ->all(); + + $waybillIncomingProducts = []; + + foreach ($products as $product) { + $waybillIncomingProducts[$product['waybill_incoming_id']][] = [ + 'product_id' => $product['product_id'], + 'quantity' => (string) $product['product_count'], + 'price' => $product['product_price'], + ]; + } + + $waybillIncomingTemp = $waybillIncoming; + foreach ($waybillIncomingTemp as $key => $row) { + $waybillIncomingProductsRow = []; + if (array_key_exists($row['id'], $waybillIncomingProducts)) { + $waybillIncomingProductsRow = $waybillIncomingProducts[$row['id']]; + } + if (!empty($waybillIncomingProductsRow)) { + $waybillIncoming[$key]['items'] = $waybillIncomingProductsRow; + } + } + + foreach ($waybillIncoming as $row) { + $waybillIncomingResult[] = [ + 'id' => $row['guid'], + 'store_id' => $row['store_guid'], +// 'type' => $row['write_offs_type'], +// 'cause' => 'Документ списания в ERP ' . $row['number'], + 'items' => $row['items'], + 'summ' => $row['summ'], + 'comment' => $row['comment'], + ]; + } + } + + } catch (Exception $e3) { + file_put_contents(self::OUT_DIR . '/log_created_waybill_incoming_error.txt', PHP_EOL . date("d.m.Y H:i:s",time()). $e3->getMessage(). ' file: '. $e3->getFile() . ' line: '. $e3->getLine(), FILE_APPEND); + } + + return compact('waybillIncoming', 'waybillIncomingIds'); + } + private function getCreateEmployee() : array { $employeeOnShiftArray = EmployeeOnShift::find() ->where([ -- 2.39.5