public function startDay($sess, $dates) { $this->Holiday($dates); $prodModel = Products::model()->findAll(); //$department = Department::model()->findAll(); $max_date = Balance::model()->find(array('select' => 'MAX(b_date) as b_date')); $curProd = Balance::model()->with('products')->findAll('date(t.b_date) = :dates', array(':dates' => $max_date->b_date)); $max_date = DepBalance::model()->find(array('select' => 'MAX(b_date) as b_date')); $curDepProd = DepBalance::model()->with('products')->findAll('date(t.b_date) = :dates', array(':dates' => $max_date->b_date)); $transaction = Yii::app()->db->beginTransaction(); $coockieModel = Coockie::model()->find('date(t.coockie_date) = :dates', array(':dates' => $dates)); if (empty($coockieModel)) { if (!empty($curProd)) { foreach ($prodModel as $key => $value) { $model = new Balance(); $model->b_date = $dates; $model->prod_id = $value->product_id; foreach ($curProd as $val) { if ($val->prod_id == $value->product_id) { $model->startCount = $val->CurEndCount; } } $model->save(); } } else { $startProducts = Storage::model()->findAll(); foreach ($prodModel as $key => $value) { $model = new Balance(); $model->b_date = $dates; $model->prod_id = $value->product_id; if (!empty($startProducts)) { foreach ($startProducts as $val) { if ($val->prod_id == $value->product_id) { $model->startCount = $val->curCount; } } } $model->save(); } } if (!empty($curDepProd)) { foreach ($curDepProd as $val) { $model = new DepBalance(); $model->startCount = $val->CurEndCount; $model->department_id = $val->department_id; $model->b_date = $dates; $model->prod_id = $val->prod_id; $model->type = $val->type; $model->save(); } } else { $startProducts = DepStorage::model()->findAll(); if (!empty($startProducts)) { foreach ($startProducts as $val) { $model = new DepBalance(); $model->b_date = $dates; $model->prod_id = $val->prod_id; $model->startCount = $val->curCount; $model->department_id = $val->department_id; $model->type = $val->type; $model->save(); } } } $coockie = new Coockie(); $coockie->coockie_date = $dates; $coockie->coockie_start = $sess; $coockie->save(); } $transaction->commit(); }
public function addStuff($id, $depId) { if ($this->checkStuff($id, $depId) != true) { $max_date = DepBalance::model()->find(array('select' => 'MAX(b_date) as b_date')); $model = new DepBalance(); $model->b_date = $max_date->b_date; $model->prod_id = $id; $model->startCount = 0; $model->endCount = 0; $model->department_id = $depId; $model->type = 2; $model->save(); } //Список полуфабрикатов и их продуктов //$dishStruct = Halfstaff::model()->with('stuffStruct.Struct')->findByPk($id,'stuffStruct.types = :types',array(':types'=>1)); $model = Halfstaff::model()->with('stuffStruct')->findByPk($id); $prod = ''; foreach ($model->getRelated('stuffStruct') as $val) { if ($val->types == 2) { $this->addStuff($val->prod_id, $depId); } else { $this->addProd($val->prod_id, $depId); } } return $prod; }
public function addStuff($id, $depId) { if ($this->checkStuff($id, $depId) != true) { $max_date = DepBalance::model()->find(array('select' => 'MAX(b_date) as b_date')); $model = new DepBalance(); $model->b_date = $max_date->b_date; $model->prod_id = $id; $model->startCount = 0; $model->endCount = 0; $model->department_id = $depId; $model->type = 2; $model->save(); //Список полуфабрикатов и их продуктов $dishStruct = Halfstaff::model()->with('stuffStruct.Struct')->findByPk($id, 'stuffStruct.types = :types', array(':types' => 1)); if (!empty($dishStruct)) { foreach ($dishStruct->getRelated('stuffStruct') as $val) { $this->addProd($val->getRelated('Struct')->product_id, $depId); } } //Список подполуфабрикатов и их продуктов $stuffStructs = Halfstaff::model()->with('stuffStruct.podstuff.podstuffStruct.Struct')->findByPk($id, 'stuffStruct.types = :types', array(':types' => 2)); if (!empty($stuffStructs)) { foreach ($stuffStructs->getRelated('stuffStruct') as $val) { $this->addStuff($val->prod_id, $depId); foreach ($val->getRelated('podstuff')->getRelated('podstuffStruct') as $vals) { $this->addProd($vals->prod_id, $depId); } } } } }