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 function actionWorkshopTo() { $post = $this->app->request->post; $c_id = $this->app->request->get->c_id; if (isset($c_id)) { $this->data->places = Remain::getPlaceRemains($c_id, 2); $this->data->c_id = $c_id; } if ($post->count()) { try { $move = new Model(); $move->fill($post); $move->__type_id = 4; $move->save(); $remain = Remain::findByConsPlace($post->__consignment_id, $post->__place_from_id); $post->qty = $post->qty_from; Remain::saveWithoutCheck($remain, $post); $this->app->flash->success = 'Запись #' . $move->__id . ' успешно добавлена'; $this->redirect('/report/main'); } catch (\Exception $e) { $this->data->error = $e->getMessage(); } } $this->data->consignments = Remain::getConsignmentRemains(2); }
public static function invent($post) { foreach ($post as $k => $v) { $remain = static::findByPK($k); if ((int) $remain->qty != (int) $v) { $diff = $remain->qty - $v; $move = new Move(); $move->__type_id = 5; $move->__consignment_id = $remain->__consignment_id; if ($diff > 0) { $move->__place_from_id = $remain->__place_id; $move->qty_from = $diff; } else { $move->__place_to_id = $remain->__place_id; $move->qty_to = -$diff; } $move->save(); $remain->qty = $v; $remain->save(); } } }