echo CHtml::link('<i class="icon-eye-open"></i>', array('/dishes/view?id=' . $value->just_id), array('target' => '_blank', 'class' => 'btn btn-success edit')); ?> </td> </tr> <?php } ?> <?php $cnt++; } ?> <?php foreach ($model2 as $value) { ?> <?php $costPrice = $stuff->getCostPrice($value->just_id, $dates); $price = $prices->getPrice($value->just_id, $value->mType, $value->type, $dates); if ($costPrice == 0) { $costPrice = 1; } $percent = $price * 100 / $costPrice - 100; ?> <?php if ($percent < 50) { ?> <tr class="error"> <td><?php echo $cnt; ?> </td> <td><?php
?> </td> <td><?php echo $stuff->getName($key); ?> </td> <td><?php echo number_format($value, 2, ',', ' '); ?> <?php echo $measure->getMeasure($key, 'stuff'); ?> </td> <td> <?php $summ = $summ + $stuff->getCostPrice($key, $dates) * $value; ?> <?php echo number_format($stuff->getCostPrice($key, $dates) * $value, 0, ',', ' '); ?> </td> </tr> <?php $cnt++; } ?> </tbody> <tfoot> <tr> <th colspan="3">Сумма</th> <th><?php
} elseif (number_format($margin - 50, 0, ',', ' ') < number_format($beforeMargin - 50, 0, ',', ' ')) { ?> <span class="red"><i class="fa fa-caret-down"></i></span> <?php } ?> </th> </tr> <?php $cnt++; } ?> <?php foreach ($model2 as $val) { $beforeDates = date('Y-m-d', strtotime($dates) - 86400); $costPrice = $stuff->getCostPrice($val['just_id'], $dates); $price = $prices->getPrice($val['just_id'], $val['mType'], $val['type'], $dates); $beforeCostPrice = $stuff->getCostPrice($val['just_id'], $beforeDates); $beorePrice = $prices->getPrice($val['just_id'], $val['mType'], $val['type'], $beforeDates); if ($costPrice == 0) { $margin = $price * 100 / 1 - 100; } elseif ($price == 0) { $margin = 1 * 100 / $costPrice - 100; } else { $margin = $price * 100 / $costPrice - 100; } if ($beforeCostPrice == 0) { $beforeMargin = $beorePrice * 100 / 1 - 100; } elseif ($beorePrice == 0) { $beforeMargin = 1 * 100 / $beforeCostPrice - 100; } else {
public function getDepBalanceSumm($dates, $depId) { $summ = array(); $prod = new Products(); $stuff = new Halfstaff(); $model = Yii::app()->db->createCommand()->select('')->from('dep_balance b')->where('b_date = :dates AND b.department_id = :depId AND b.type = :types', array(':dates' => $dates, ':depId' => $depId, ':types' => 1))->queryAll(); foreach ($model as $val) { $summ[0] = $summ[0] + $val['startCount'] * $prod->getCostPrice($val['prod_id'], $dates); $summ[1] = $summ[1] + $val['endCount'] * $prod->getCostPrice($val['prod_id'], $dates); $summ[2] = $summ[2] + $val['CurEndCount'] * $prod->getCostPrice($val['prod_id'], $dates); } $model2 = Yii::app()->db->createCommand()->select('')->from('dep_balance b')->where('b_date = :dates AND b.department_id = :depId AND b.type = :types', array(':dates' => $dates, ':depId' => $depId, ':types' => 2))->queryAll(); foreach ($model2 as $val) { $summ[0] = $summ[0] + $val['startCount'] * $stuff->getCostPrice($val['prod_id'], $dates); $summ[1] = $summ[1] + $val['endCount'] * $stuff->getCostPrice($val['prod_id'], $dates); $summ[2] = $summ[2] + $val['CurEndCount'] * $stuff->getCostPrice($val['prod_id'], $dates); } return $summ; }
public function getCostPrice($id, $order_date) { $log = new Logs(); $stuffSum = 0; $prodSum = 0; $model = $log->getStructure($order_date, $id, $this->tableName()); if (!empty($model['prod']) && !empty($model['stuff']) && !empty($model['count'])) { if ($model['count'] == 0) { $dish = Yii::app()->db->createCommand()->select('count')->from('dishes')->where('dish_id = :id', array(':id' => $id))->queryRow(); $model['count'] = $dish['count']; } } else { $model = $this->getStruct($id); } $stuff = new Halfstaff(); $costPrice = array(); $products = new Products(); if (!empty($model)) { if (!empty($model['prod'])) { foreach ($model['prod'] as $key => $value) { $costPrice['prod'][$key] = $products->getCostPrice($key, $order_date) * $value / $model['count']; } } if (!empty($model['stuff'])) { foreach ($model['stuff'] as $key => $value) { $costPrice['stuff'][$key] = $stuff->getCostPrice($key, $order_date) * $value / $model['count']; } } } if (!empty($costPrice['prod'])) { $prodSum = array_sum($costPrice['prod']); } if (!empty($costPrice['stuff'])) { $stuffSum = array_sum($costPrice['stuff']); } return $prodSum + $stuffSum; }
public function actionAjaxDishIncome() { $prices = new Prices(); $dishCnt = array(); $dCount = array(); $prodCnt = array(); $pCount = array(); $stuffCnt = array(); $sCount = array(); $dish = new Dishes(); $stuff = new Halfstaff(); $prod = new Products(); $model = Expense::model()->with('order.dish')->findAll('date(t.order_date) BETWEEN :from AND :to', array(':from' => $_POST['from'], ':to' => $_POST['to'])); if (!empty($model)) { foreach ($model as $value) { foreach ($value->getRelated('order') as $val) { $dishes[$val->just_id] = $val->getRelated('dish')->name; $dishCnt[$val->just_id] = $dishCnt[$val->just_id] + $val->count * $prices->getPrice($val->just_id, $value->mType, $val->type, $value->order_date) - $dish->getCostPrice($val->just_id, $value->order_date); $dCount[$val->just_id] = $dCount[$val->just_id] + $val->count; } } } $model2 = Expense::model()->with('order.halfstuff')->findAll('date(t.order_date) BETWEEN :from AND :to', array(':from' => $_POST['from'], ':to' => $_POST['to'])); if (!empty($model2)) { foreach ($model2 as $value) { foreach ($value->getRelated('order') as $val) { $halfstuff[$val->just_id] = $val->getRelated('halfstuff')->name; $stuffCnt[$val->just_id] = $stuffCnt[$val->just_id] + $val->count * $prices->getPrice($val->just_id, $value->mType, $val->type, $value->order_date) - $stuff->getCostPrice($val->just_id, $value->order_date); $sCount[$val->just_id] = $sCount[$val->just_id] + $val->count; } } } $model3 = Expense::model()->with('order.products')->findAll('date(t.order_date) BETWEEN :from AND :to', array(':from' => $_POST['from'], ':to' => $_POST['to'])); if (!empty($model3)) { foreach ($model3 as $value) { foreach ($value->getRelated('order') as $val) { $products[$val->just_id] = $val->getRelated('products')->name; $prodCnt[$val->just_id] = $prodCnt[$val->just_id] + $val->count * $prices->getPrice($val->just_id, $value->mType, $val->type, $value->order_date) - $prod->getCostPrice($val->just_id, $value->order_date); $pCount[$val->just_id] = $pCount[$val->just_id] + $val->count; } } } $this->renderPartial('ajaxDishIncome', array('dishes' => $dishes, 'dishCnt' => $dishCnt, 'halfstuff' => $halfstuff, 'stuffCnt' => $stuffCnt, 'products' => $products, 'prodCnt' => $prodCnt, 'dCount' => $dCount, 'sCount' => $sCount, 'pCount' => $pCount)); }
public function getDepCost($depId, $dates) { $summ = 0; $dish = new Dishes(); $stuff = new Halfstaff(); $prod = new Products(); $model = Yii::app()->db->createCommand()->select('ord.just_id,sum(ord.count) as count')->from('expense ex')->join('orders ord', 'ord.expense_id = ex.expense_id')->join('dishes d', 'd.dish_id = ord.just_id')->where('date(ex.order_date) = :dates AND ord.type = :types AND ex.status = :status AND d.department_id = :depId', array(':dates' => $dates, ':types' => 1, ':status' => 0, ':depId' => $depId))->group('ord.just_id')->queryAll(); foreach ($model as $val) { $summ = $summ + $dish->getCostPrice($val['just_id'], $dates) * $val['count']; } $model2 = Yii::app()->db->createCommand()->select('ord.just_id,sum(ord.count) as count')->from('expense ex')->join('orders ord', 'ord.expense_id = ex.expense_id')->join('halfstaff h', 'h.halfstuff_id = ord.just_id')->where('date(ex.order_date) = :dates AND ord.type = :types AND ex.status = :status AND h.department_id = :depId', array(':dates' => $dates, ':types' => 2, ':status' => 0, ':depId' => $depId))->group('ord.just_id')->queryAll(); foreach ($model2 as $val) { $summ = $summ + $stuff->getCostPrice($val['just_id'], $dates) * $val['count']; } $model3 = Yii::app()->db->createCommand()->select('ord.just_id,sum(ord.count) as count')->from('expense ex')->join('orders ord', 'ord.expense_id = ex.expense_id')->join('products p', 'p.product_id = ord.just_id')->where('date(ex.order_date) = :dates AND ord.type = :types AND ex.status = :status AND p.department_id = :depId', array(':dates' => $dates, ':types' => 3, ':status' => 0, ':depId' => $depId))->group('ord.just_id')->queryAll(); foreach ($model3 as $val) { $summ = $summ + $prod->getCostPrice($val['just_id'], $dates) * $val['count']; } return $summ; }
<label>Полуфабрикаты</label> <table class="table table-bordered"> <thead> <th>название</th> <th>кол</th> <th>ед.изм</th> <th>цена</th> </thead> <tbody> <?php $sum = array(); $DishSumm = 0; $stuff = new Halfstaff(); if ($HalfstuffProd) { foreach ($HalfstuffProd->getRelated('halfstuff') as $keys => $value) { $price = $stuff->getCostPrice($value->getRelated('Structs')->halfstuff_id, $dates); ?> <tr> <td><?php echo $value->getRelated('Structs')->name; ?> </td> <td><?php echo $value->amount; ?> </td> <td><?php echo $value->getRelated('Structs')->getRelated('halfstuffType')->name; ?> </td> <td><?php
</td> <td><?php echo number_format($price * $val->amount, 2); ?> </td> </tr> <?php $sum = $sum + $price * $val->amount; } } if ($Stuff) { $stuffSum = 0; $stuff = new Halfstaff(); foreach ($Stuff->getRelated('stuffStruct') as $value) { $price = $stuff->getCostPrice($value->prod_id, $dates); //$stuffSum = $countStuff/$value->getRelated('stuff')->count; ?> <tr> <td><?php echo $value->getRelated('stuff')->name; ?> </td> <td><?php echo $value->amount; ?> </td> <td><?php echo $value->getRelated('stuff')->getRelated('halfstuffType')->name; ?> </td>
public function getDepInExp($dates, $depId) { $prod = new Products(); $stuff = new Halfstaff(); $summ = 0; $model = Yii::app()->db->createCommand()->select()->from('dep_faktura df')->join('dep_realize dr', 'dr.dep_faktura_id = df.dep_faktura_id')->where('date(df.real_date) = :dates AND df.department_id != :depId AND df.fromDepId = :fromDepId', array(':dates' => $dates, ':depId' => $depId, ':fromDepId' => $depId))->queryAll(); foreach ($model as $val) { $summ = $summ + $val['count'] * $prod->getCostPrice($val['prod_id'], $dates); } $model2 = Yii::app()->db->createCommand()->select()->from('inexpense inexp')->join('inorder inord', 'inord.inexpense_id = inexp.inexpense_id')->where('date(inexp.inexp_date) = :dates AND inexp.department_id != :depId AND inexp.fromDepId = :fromDepId', array(':dates' => $dates, ':depId' => $depId, ':fromDepId' => $depId))->queryAll(); foreach ($model2 as $val) { $summ = $summ + $val['count'] * $stuff->getCostPrice($val['stuff_id'], $dates); } return $summ; }
</td> <?php if ($key == 'price') { ?> <td><?php echo number_format($price->getPrice($val['prod_id'], $val['mType'], $val['type'], $dates) * $val['count'], 0, ',', ' '); ?> </td> <?php $sum = $sum + $price->getPrice($val['prod_id'], $val['mType'], $val['type'], $dates) * $val['count']; ?> <?php } else { ?> <td><?php echo number_format($stuff->getCostPrice($val['prod_id'], $dates) * $val['count'], 0, ',', ' '); ?> </td> <?php $sum = $sum + $stuff->getCostPrice($val['prod_id'], $dates) * $val['count']; ?> <?php } ?> </tr> <?php $cnt++; } } } if (!empty($model3)) {