public function actionAjaxBalance() { $dates = $_POST['dates']; $expense = new Expense(); if (isset($_POST)) { $command = Yii::app()->db->createCommand(); if ($_POST['types'] == 0) { foreach ($_POST['prod_id'] as $key => $val) { $command->update('balance', array('CurEndCount' => $expense->changeToFloat($_POST['count'][$key])), 'b_date=:dates AND prod_id = :prod_id', array(':dates' => $dates, ':prod_id' => $val)); } } elseif ($_POST['types'] == 1) { $depId = $_POST['depId']; foreach ($_POST['prod_id'] as $key => $val) { $command->update('dep_balance', array('CurEndCount' => $expense->changeToFloat($_POST['pcount'][$key])), 'b_date=:dates AND prod_id = :prod_id AND type = :types AND department_id = :depId', array(':dates' => $dates, ':prod_id' => $val, ':types' => 1, ':depId' => $depId)); } foreach ($_POST['stuff_id'] as $key => $val) { $command->update('dep_balance', array('CurEndCount' => $expense->changeToFloat($_POST['hcount'][$key])), 'b_date=:dates AND prod_id = :prod_id AND type = :types AND department_id = :depId', array(':dates' => $dates, ':prod_id' => $val, ':types' => 2, ':depId' => $depId)); } } } }
public function actionSetRequest() { $model = Yii::app()->db->createCommand()->select('')->from('request r')->join('provider p', 'p.provider_id = r.provider_id')->where('r.status = :status', array(':status' => 0))->queryAll(); foreach ($model as $val) { $List[$val['request_id']] = $val['req_date'] . " - " . $val['name']; } if (isset($_POST['request'])) { $command = Yii::app()->db->createCommand(); $expense = new Expense(); $dates = date('Y-m-d H:i:s'); $prodCount = array(); $provId = Yii::app()->db->createCommand()->select('provider_id')->from('request')->where('request_id = :id', array(':id' => $_POST['list']))->queryRow(); foreach ($_POST['request'] as $keys => $value) { if ($keys != 0) { $command->insert('dep_faktura', array('real_date' => $dates, 'department_id' => $keys, 'fromDepId' => 0)); $lastDepId = Yii::app()->db->lastInsertID; foreach ($value as $key => $val) { $prodCount[$key] = $prodCount[$key] + $val['count']; if ($val['count'] != 0) { $command->insert('dep_realize', array('dep_faktura_id' => $lastDepId, 'prod_id' => $key, 'price' => $_POST['price'][$key], 'count' => $expense->changeToFloat($val['count']))); } } } else { $command->insert('expense', array('order_date' => $dates, 'employee_id' => Yii::app()->user->getId(), 'table' => 0, 'status' => 0, 'kind' => 1, 'debt' => 0, 'comment' => '', 'mType' => 0)); $lastExpId = Yii::app()->db->lastInsertID; foreach ($value as $key => $val) { $prodCount[$key] = $prodCount[$key] + $val['count']; if ($val['count'] != 0) { $command->insert('orders', array('expense_id' => $lastExpId, 'just_id' => $key, 'type' => 3, 'count' => $expense->changeToFloat($val['count']))); } } } } $command->insert('faktura', array('realize_date' => $dates, 'provider_id' => $provId['provider_id'])); $lastId = Yii::app()->db->lastInsertID; foreach ($prodCount as $key => $val) { $count = $expense->changeToFloat($val); $command->insert('realize', array('faktura_id' => $lastId, 'prod_id' => $key, 'price' => $_POST['price'][$key], 'count' => $count)); } $command->update('request', array('status' => 1), 'request_id = :id', array(':id' => $_POST['list'])); $this->redirect(array('site/index')); } $this->render('setRequest', array('List' => $List)); }