From: fomichev Date: Wed, 18 Dec 2024 06:41:25 +0000 (+0300) Subject: Отправка списаний X-Git-Tag: 1.7~151^2~6 X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=2db69f1727d34cdcb18a7184f43ca5fa4c06cdc1;p=erp24_rep%2Fyii-erp24%2F.git Отправка списаний --- diff --git a/erp24/api2/controllers/DataController.php b/erp24/api2/controllers/DataController.php index ade8e360..85756fb8 100644 --- a/erp24/api2/controllers/DataController.php +++ b/erp24/api2/controllers/DataController.php @@ -40,6 +40,8 @@ use yii_app\records\SalesUpdate; use yii_app\records\Terminals; use yii_app\records\WaybillIncoming; use yii_app\records\WaybillIncomingProducts; +use yii_app\records\WaybillWriteOffs; +use yii_app\records\WaybillWriteOffsProducts; use yii_app\records\WriteOffs; use yii_app\records\WriteOffsErp; use yii_app\records\WriteOffsProducts; @@ -131,6 +133,7 @@ class DataController extends BaseController { $writeOffCount = $writeOffArray['writeOffCount']; $writeOffIdsString = $writeOffArray['writeOffIdsString']; $writeOffIds = $writeOffArray['writeOffIds']; + $waybillWriteOffIds = $writeOffArray['waybillWriteOffIds']; if (!empty($writeOff)) { $mess['create_write_offs'] = $writeOff; @@ -192,6 +195,9 @@ class DataController extends BaseController { if (!empty($writeOffIds) && !empty($writeOff)) { $this->getWriteOffsSetStatusSend($writeOffIds); } + if (!empty($waybillWriteOffIds) && !empty($writeOff)) { + $this->getWaybillWriteOffsSetStatusSend($waybillWriteOffIds); + } if (!empty($waybillIncomingIds) && !empty($waybillIncoming)) { $this->getWaybillIncomingSetStatusSend($waybillIncomingIds); } @@ -232,6 +238,23 @@ class DataController extends BaseController { } } + private function getWaybillWriteOffsSetStatusSend($waybillWriteOffIds) { + try { + $waybillWriteOffsErp = WaybillWriteOffs::find()->where(['in', 'id', $waybillWriteOffIds])->all(); + foreach ($waybillWriteOffsErp as $waybillWriteOffsErpElem) { + $waybillWriteOffsErpElem->status = 3; + $waybillWriteOffsErpElem->error_text = ''; + $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(); @@ -322,6 +345,56 @@ class DataController extends BaseController { } } + + $waybillWriteOffs = WaybillWriteOffs::find() + ->select([ + 'id', + 'guid', + 'store_guid', + 'number', + 'date', + 'status', + 'comment', + 'quantity', + 'summ' + ]) + ->where(['status' => WaybillWriteOffs::STATUS_NEW]) + ->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); } @@ -332,6 +405,7 @@ class DataController extends BaseController { 'writeOffCount' => $writeOffCount, 'writeOffIds' => $writeOffIds, 'writeOffIdsString' => $writeOffIdsString, + 'waybillWriteOffIds' => $waybillWriteOffIds, ]; }