public function actionNew() { $post = $this->app->request->post; if ($post->count()) { try { $remain = new Model(); $remain->fill($post); $remain->save(); $move = new Move(); $move->__type_id = 5; $move->__consignment_id = $post->__consignment_id; if ($post->qty > 0) { $move->__place_to_id = $post->__place_id; $move->qty_to = $post->qty; } else { $move->__place_from_id = $post->__place_id; $move->qty_from = -$post->qty; } $move->save(); $this->app->flash->success = 'Запись #' . $remain->__id . ' успешно добавлена'; $this->redirect('/remain/index'); } catch (\Exception $e) { $this->data->error = $e->getMessage(); } } $this->data->consignments = Consignment::findAll(['order' => 'name']); $this->data->places = Place::findAll(['order' => 'name']); }
public static function saveWithoutCheck(Remain $remain, $post) { $remain->qty -= $post->qty; $remain->save(); }