public function actionImportInsurer($orderId, $id = null)
{
$orderForm = OrderForm::findOne($orderId);
$client = ClientForm::findOne($id);
$insurerFormData = $orderForm->getData();
if ($insurerFormData['insurerPhone'] === $client->phone && $insurerFormData['insurerName'] === $client->name) {
if (!empty($insurerFormData['insurerLastname'])) {
$client->lastname = $insurerFormData['insurerLastname'];
}
if (!empty($insurerFormData['insurerSurname'])) {
$client->surname = $insurerFormData['insurerSurname'];
}
if (!empty($insurerFormData['insurerBirthDate'])) {
$client->birth_date = $insurerFormData['insurerBirthDate'];
}
if (!empty($insurerFormData['insurerTaxCode'])) {
$client->tax_code = $insurerFormData['insurerTaxCode'];
}
}
if ($client->save()) {
Yii::$app->session->setFlash('success', 'Импорт прошел успешно!');
return $this->redirect(['edit', 'id' => $orderId]);
} else {
Yii::$app->session->setFlash('error', array_values($client->getErrors())[0][0]);
return $this->redirect(['edit', 'id' => $orderId]);
}
}