}
} 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);
+ 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');
+ return compact('waybillIncoming', 'waybillIncomingIds', 'waybillIncomingResult');
}
- private function getCreateEmployee() : array {
+
+ private function getResortingDoc(): array
+ {
+ $replacementInvoice = [];
+ $replacementInvoicesIds = [];
+ $replacementInvoiceResult = [];
+
+ try {
+ $replacementInvoice = ReplacementInvoice::find()
+ ->select(['id', 'guid', 'shift_transfer_id', 'store_guid', 'number', 'date', 'comment', 'quantity', 'summ'])
+ ->andWhere(['status' => WriteOffsErp::STATUS_CONFIRM])
+ ->indexBy('id')
+ ->asArray()
+ ->all();
+
+ if (!empty($replacementInvoice)) {
+ $replacementInvoicesIds = array_column($replacementInvoice, 'id');
+ $shiftTransferIds = array_column($replacementInvoice, 'shift_transfer_id');
+
+ $products = EqualizationRemains::find()
+ ->where(['in', 'shift_transfer_id', $shiftTransferIds])
+ ->asArray()
+ ->all();
+
+ $replacementInvoiceProducts = [];
+
+ foreach ($products as $product) {
+ $replacementInvoiceProducts[$product['']][] = [
+ 'product_id' => $product->product_id,
+ 'color' => Products1cAdditionalCharacteristics::findOne([
+ 'property_id' => '5880b25c-809f-11ef-84ea-ac1f6b1b7573',
+ 'product_id' => $product->product_id])->value ?? '',
+ 'price' => $product->product_price,
+ 'new_product_id' => $product->product_replacement_id,
+ 'new_color' => Products1cAdditionalCharacteristics::findOne([
+ 'property_id' => '5880b25c-809f-11ef-84ea-ac1f6b1b7573',
+ 'product_id' => $product->product_replacement_id])->value ?? '',
+ 'new_price' => $product->product_replacement_price,
+ 'quantity' => $product->product_replacement_count,
+ ];
+ }
+
+ $replacementInvoiceTemp = $replacementInvoice;
+ foreach ($replacementInvoiceTemp as $key => $row) {
+ $replacementInvoiceProductsRow = [];
+ if (!isset($replacementInvoice[$key]['items'])) {
+ $replacementInvoice[$key]['items'] = [];
+ }
+ if (array_key_exists($row['id'], $replacementInvoiceProducts)) {
+ $replacementInvoiceProductsRow = $replacementInvoiceProducts[$row['id']];
+ }
+ if (!empty($replacementInvoiceProductsRow)) {
+ $replacementInvoice[$key]['items'] = $replacementInvoiceProductsRow;
+ }
+ }
+
+ foreach ($replacementInvoice as $row) {
+ $replacementInvoiceResult[] = [
+ 'id' => $row['guid'],
+ 'store_id' => $row['store_guid'],
+ '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_replacement_invoice_error.txt', PHP_EOL . date("d.m.Y H:i:s", time()) . $e3->getMessage() . ' file: ' . $e3->getFile() . ' line: ' . $e3->getLine(), FILE_APPEND);
+ }
+
+ return compact('replacementInvoice', 'replacementInvoicesIds', 'replacementInvoiceResult');
+ }
+
+
+ private function getCreateEmployee(): array
+ {
$employeeOnShiftArray = EmployeeOnShift::find()
->where([
'status' => EmployeeOnShift::STATUS_ACCEPT,