public function renderButtons($data, $row) { //$getAllocatedItem = Allocate::model()->findByAttributes(array('cons_id'=>$data->id,'date_out'=>NULL)); $getAllocatedItem = Allocate::model()->find('cons_id = :cons_id AND (date_out IS NULL OR date_out = :date_out)', array(':cons_id' => $data->id, ':date_out' => '0000-00-00')); $getConsStatus = Consumable::model()->find('id = :id', array(':id' => $data->id)); $status = Status::model()->find('id = :id', array(':id' => $getConsStatus['status_id'])); $canAllocate = $getAllocatedItem['allocate_id'] && $status['status'] != 'blocked' ? true : false; $this->widget('bootstrap.widgets.TbButtonGroup', array('size' => 'small', 'type' => 'inverse', 'buttons' => array(array('label' => 'Manage Group', 'url' => 'http://localhost/asset_management/index.php/usergroup/listbuilder?groupId=' . $data->id . '&groupName=' . $data->name)))); }
?> <?php $link = Link::model()->findByAttributes(array('commodity2_id' => $model->commodity_id)); echo "<table class='table table-bordered'>"; if (count($link) == 0) { echo "<tr style='background:#F7819F;color:white'><td>No Commodity Linked to {$model->name}</td></tr>"; } else { $commodity = Commodity::model()->findByAttributes(array('id' => $link['commodity1_id'])); $commodityItems = $commodity['name']::model()->findAllByAttributes(array('link_to' => $model->id)); if (count($commodityItems) != 0) { echo "<tr style='background:#F5A9A9;'><th colspan='4' style='text-align:center'>Linked " . $commodity['name'] . " Allocate History</th></tr>"; foreach ($commodityItems as $c) { $cartridgeName = $c['name']; $fullallocates = Allocate::model()->findAll("commodity_id =:commodity_id AND cons_id=:cons_id", array('commodity_id' => 12, 'cons_id' => $c['id'])); $allocates = Allocate::model()->findAll("commodity_id =:commodity_id AND cons_id=:cons_id AND given_by IS NOT NULL", array('commodity_id' => 12, 'cons_id' => $c['id'])); $total = count($fullallocates); $allocated = count($allocates); echo "<tr style='background:#F6E3CE'><th colspan='4'>{$cartridgeName} <code>{$allocated} / {$total} allocated</code></th></tr>"; if (count($allocates) != 0) { echo "<tr><th>Date Out</th><th>Allocated By</th><th>Allocated To</th></tr>"; foreach ($allocates as $a) { echo "<tr>"; $date_out = $a['date_out']; echo "<td>"; echo Yii::app()->dateFormatter->format(Yii::app()->locale->getDateFormat("long"), CDateTimeParser::parse($date_out, 'yyyy-mm-dd')); echo "</td>"; $given_by = User::model()->findByPk($a['given_by']); $givenBy = $given_by['name']; echo "<td>{$givenBy}</td>"; if ($a['user_group'] == 'U') {
<?php $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array('id' => 'allocate-form', 'enableAjaxValidation' => false)); ?> <p class="help-block">Fields with <span class="required">*</span> are required.</p> <?php echo $form->errorSummary($model); ?> <?php $user = User::model()->findByAttributes(array('name' => CHtml::encode(Yii::app()->user->getId()))); $row = Allocate::model()->findByAttributes(array('allocate_id' => $_GET['allocateId'])); $consId = $row['cons_id']; $available_quantity = count(Allocate::model()->findAll('cons_id = :cons_id AND (date_out IS NULL OR date_out = :date_out)', array(':cons_id' => $consId, ':date_out' => '0000-00-00'))); $t = 'Consumable'; $item = $t::model()->findByAttributes(array('id' => $consId)); ?> <?php //echo $form->hiddenField($model,'stock_id',array('span'=>5)); ?> <?php //echo $form->hiddenField($model,'id',array('span'=>5)); ?> <?php //echo $form->hiddenField($model,'given_to',array('span'=>5)); ?> <?php //echo $form->hiddenField($model,'user_group',array('span'=>5,'maxlength'=>2));
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Allocate the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Allocate::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
public function renderButtons($data, $row) { //$getAllocatedItem = Allocate::model()->findByAttributes(array('cons_id'=>$data->id,'date_out'=>NULL)); $getAllocatedItem = Allocate::model()->find('cons_id = :cons_id AND (date_out IS NULL OR date_out = :date_out)', array(':cons_id' => $data->id, ':date_out' => '0000-00-00')); //$getConsStatus = Consumable::model()->find('id = :id',array(':id' => $data->id)); //$status = Status::model()->find('id = :id',array(':id' => $getConsStatus['status_id'])); $canAllocate = $getAllocatedItem['allocate_id'] ? true : false; $this->widget('bootstrap.widgets.TbButtonGroup', array('size' => 'small', 'type' => 'inverse', 'buttons' => array(array('label' => 'Action', 'items' => array(array('label' => 'Transfer Item', 'url' => Yii::app()->homeUrl . '/transferCons/create', 'linkOptions' => array('submit' => array('/transferCons/create', 'itemId' => $data->id, 'commodity_id' => $data->commodity_id))), array('label' => 'Block Item', 'url' => Yii::app()->homeUrl . '/blockeditem/create', 'linkOptions' => array('submit' => array('/blockeditem/create', 'id' => 1, 'itemId' => $data->id, 'commodity_id' => $data->commodity_id))), array('label' => 'Block User Group', 'url' => Yii::app()->homeUrl . '/blockeditem/create', 'linkOptions' => array('submit' => array('/blockeditem/create', 'id' => 2, 'itemId' => $data->id, 'commodity_id' => $data->commodity_id))), array('label' => 'Add Stock Commodity', 'url' => Yii::app()->homeUrl . '/consumablestock/create', 'linkOptions' => array('submit' => array('/consumablestock/create', 'itemId' => $data->id, 'commodity_id' => $data->commodity_id))), array('label' => 'Allocate Commodity', 'url' => $canAllocate ? Yii::app()->homeUrl . '/allocate/create' : NULL, 'linkOptions' => array('submit' => array('/allocate/update/' . $getAllocatedItem['allocate_id'] . '?allocateId=' . $getAllocatedItem['allocate_id'] . '&commodity_id=' . $data->commodity_id))), array('label' => 'View Allocate History', 'url' => Yii::app()->homeUrl . '/allocate/admin', 'linkOptions' => array('submit' => array('/allocate/admin', 'itemId' => $data->id, 'commodity_id' => $data->commodity_id)))))))); // }
public function getAvailableQuantity($data, $row) { $getAllocatedItem = Allocate::model()->findAll('cons_id = :cons_id AND commodity_id =:commodity_id AND (date_out IS NULL OR date_out = :date_out)', array(':cons_id' => $data->id, ':commodity_id' => $data->commodity_id, 'date_out' => '0000-00-00')); if (count($getAllocatedItem) == 0) { echo "<i style='font-size:12px;color:red'>Out of Stock</i>"; } else { echo "<b style='font-size:18px;'>" . count($getAllocatedItem) . "</b"; } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Report(); if (isset($_POST['Report'])) { $model->attributes = $_POST['Report']; $report_name = $model->name; $description = $model->description; //txt_field_commodity : selected column field names //field_commodity : selected row ids; //commodity : item_ids $attributeArray = []; $fromTables = []; $whereClauses = []; /*************COMMODITY*****************/ if (isset($_POST['txt_field_commodity'])) { $table = 'commodity'; $fromTables[] = '`commodity`'; $attributes = $_POST['txt_field_commodity']; foreach ($attributes as $attr) { $attributeArray[] = $table . '.' . $attr; } $rows = isset($_POST['commodity']) ? $_POST['commodity'] : []; $whereArray1 = []; foreach ($rows as $item) { $whereArray1[] = $item; } $whereText1 = implode(',', $whereArray1); if ($whereText1 != 'all') { $whereClauses[] = "commodity.id IN ({$whereText1})"; } } /*******COMMODITY CATEGORY********/ if (isset($_POST['txt_field_category'])) { $table = 'commodity_category'; $fromTables[] = '`commodity_category`'; $attributes = $_POST['txt_field_category']; foreach ($attributes as $attribute) { $attributeArray[] = $table . '.' . $attribute; } $rows = isset($_POST['category']) ? $_POST['category'] : []; $whereArray2 = []; foreach ($rows as $item) { $whereArray2[] = $item; } $whereText2 = implode(',', $whereArray2); $whereClauses[] = "commodity.id = commodity_category.commodity_id"; if ($whereText2 != 'all') { $whereClauses[] = "commodity_category.id IN ({$whereText2})"; } } /*******ITEMS********/ if (isset($_POST['txt_field_consumable'])) { $table = 'consumable'; $fromTables[] = '`consumable`'; $attributes = $_POST['txt_field_consumable']; foreach ($attributes as $attribute) { $attributeArray[] = $table . '.' . $attribute; } $rows = isset($_POST['consumable']) ? $_POST['consumable'] : []; $whereArray3 = []; foreach ($rows as $item) { $whereArray3[] = $item; } $whereText3 = implode(',', $whereArray3); $whereClauses[] = "commodity.id = consumable.commodity_id AND commodity_category.path = consumable.category_id"; if ($whereText3 != 'all') { $whereClauses[] = "consumable.id IN ({$whereText3})"; } } //blocked if (isset($_POST['total'])) { $whereClauses[] = "consumable.available_on_loan = 'Yes'"; } //on loan if (isset($_POST['new_stock'])) { $whereClauses[] = "consumable.available_on_loan = 'Yes'"; } /*******threshold********/ if (isset($_POST['threshold'])) { //print_r ($_POST['consumable']);die; $rows = isset($_POST['consumable']) ? $_POST['consumable'] : []; $itemId = implode(',', $rows); $connection = Yii::app()->db; if ($itemId == 'all') { $sql = "\n\t\t\t\t\tselect *\n\t\t\t\t\tfrom consumable"; } else { //$itemId = $_POST['consumable'][0]; $sql = "\n\t\t\t\t\tselect *\n\t\t\t\t\tfrom consumable \n\t\t\t\t\twhere id IN ({$itemId})"; } $command = $connection->createCommand($sql); $dataReader = $command->queryAll(); $id = $dataReader[0]['id']; $allocates = Allocate::model()->findAll('commodity_id=:commodity_id AND cons_id=:cons_id', array('commodity_id' => 3, 'cons_id' => $id)); $numUnitsLeft = count($allocates); //echo $numUnitsLeft;die; $whereClauses[] = "consumable.threshold < {$numUnitsLeft} "; } $attributeText = implode(',', $attributeArray); $fromTableText = implode(',', $fromTables); $whereClauseText = implode(' AND ', $whereClauses); if ($whereClauses == NULL) { $whereClauseText = 1; } $model->query = "SELECT {$attributeText} FROM {$fromTableText} WHERE {$whereClauseText}"; //echo $model->query;die; if ($model->save()) { $this->redirect(array('view', 'id' => $model->rid)); } } $this->render('create', array('model' => $model)); }
public function renderButtons($data) { $getAllocatedItem = Allocate::model()->find('cons_id = :cons_id AND (date_out IS NULL OR date_out = :date_out)', array(':cons_id' => $data->ID, ':date_out' => '0000-00-00')); $temp = Form::model()->find("FORM_ID=:FORM_ID", array(":FORM_ID" => $data->FORM_ID)); $canAllocate = $getAllocatedItem['allocate_id'] ? true : false; if ($data->FORM_ID == 16) { $this->widget('bootstrap.widgets.TbButtonGroup', array('size' => 'small', 'type' => 'inverse', 'buttons' => array(array('label' => 'Action', 'items' => array(array('label' => 'Transfer', 'url' => Yii::app()->homeUrl . '/transferFile/create', 'linkOptions' => array('submit' => array('/transferFile/create', 'formId' => $data->FORM_ID, 'itemId' => $data->ID, 'deptName' => $data->DEPARTMENT, 'owner' => $data->OWNER))), array('label' => 'Add details', 'url' => Yii::app()->homeUrl . '/filedetails/create', 'linkOptions' => array('submit' => array('/filedetails/create', 'formId' => $data->FORM_ID, 'itemId' => $data->ID, 'deptName' => $data->DEPARTMENT))), array('label' => 'Add Stock', 'url' => Yii::app()->homeUrl . '/consumablestock/create', 'linkOptions' => array('submit' => array('/consumablestock/create', 'itemId' => $data->ID, 'commodity_id' => $data->FORM_ID))), array('label' => 'Close File', 'url' => Yii::app()->homeUrl . '/filedetails/admin', 'linkOptions' => array('submit' => array('/filedetails/admin', 'itemId' => $data->ID))), array('label' => 'Sealed', 'url' => Yii::app()->homeUrl . '/filedetails/admin', 'linkOptions' => array('submit' => array('/filedetails/admin', 'itemId' => $data->ID))), array('label' => 'Print Label', 'url' => Yii::app()->homeUrl . '/label/printall', 'linkOptions' => array('submit' => array('/label/printallform', 'formId' => $data->FORM_ID, 'itemId' => $data->ID, 'fileType' => $data->FILE_TYPE))), array('label' => 'Print Details', 'url' => Yii::app()->homeUrl . '/fm/entry/view', 'linkOptions' => array('submit' => array('/fm/entry/view' . '?form=' . $data->FORM_ID . '&entry=' . $data->ID)))))))); } else { $this->widget('bootstrap.widgets.TbButtonGroup', array('size' => 'small', 'type' => 'inverse', 'buttons' => array(array('label' => 'Action', 'items' => array(array('label' => 'Block Item', 'url' => Yii::app()->homeUrl . '/blockeditem/create', 'linkOptions' => array('submit' => array('/blockeditem/create', 'id' => 1, 'itemId' => $data->ID, 'commodity_id' => $temp['TYPE_ID']))), array('label' => 'Block User Group', 'url' => Yii::app()->homeUrl . '/blockeditem/create', 'linkOptions' => array('submit' => array('/blockeditem/create', 'id' => 2, 'itemId' => $data->ID, 'commodity_id' => $temp['TYPE_ID']))), array('label' => 'Add Stock Commodity', 'url' => Yii::app()->homeUrl . '/consumablestock/create', 'linkOptions' => array('submit' => array('/consumablestock/create', 'itemId' => $data->ID, 'commodity_id' => $temp['TYPE_ID']))), array('label' => 'Allocate Commodity', 'url' => $canAllocate ? Yii::app()->homeUrl . '/allocate/create' : NULL, 'linkOptions' => array('submit' => array('/allocate/update/' . $getAllocatedItem['allocate_id'] . '?allocateId=' . $getAllocatedItem['allocate_id'] . '&commodity_id=' . $temp['TYPE_ID']))), array('label' => 'View Allocate History', 'url' => Yii::app()->homeUrl . '/allocate/admin', 'linkOptions' => array('submit' => array('/allocate/admin', 'itemId' => $data->ID, 'commodity_id' => $temp['TYPE_ID'])))))))); } // }
<div id="chart_big"></div> <?php $allocated = Allocate::model()->findAll('cons_id =:cons_id AND date_out IS NOT NULL', array(':cons_id' => 2)); $allocatedDates = []; foreach ($allocated as $a) { $allocatedDates[] = strtotime($a['date_out']); } sort($allocatedDates); $groupedArray = array_fill(0, count($allocatedDates), 0); foreach ($allocatedDates as $date) { $groupedArray[($date - $allocatedDates[0]) / 604800]++; } foreach ($groupedArray as $week => $num) { if ($num == 0) { unset($groupedArray[$week]); } } //$a = count($groupedArray); //echo "<script>alert($a)</script>";die; $x = array(); $y = array(); foreach ($groupedArray as $a => $b) { $x[] = 'Week ' . ($a + 1); $y[] = $b; } $x_data = json_encode($x); $y_data = json_encode($y); Yii::app()->clientScript->registerScript('chart_big', "\n\$(document).ready(function(){\n \$.jqplot.config.enablePlugins = true;\n var s1 = {$y_data};\n var ticks = {$x_data};\n \n plot1 = \$.jqplot('chart_big', [s1], {\n // Only animate if we're not using excanvas (not in IE 7 or IE 8)..\n animate: !\$.jqplot.use_excanvas,\n seriesDefaults:{\n renderer:\$.jqplot.BarRenderer,\n pointLabels: { show: true }\n },\n axes: {\n xaxis: {\n renderer: \$.jqplot.CategoryAxisRenderer,\n ticks: ticks\n }\n },\n highlighter: { show: false }\n });\n \n \$('#chart1').bind('jqplotDataClick',\n function (ev, seriesIndex, pointIndex, data) {\n \$('#info1').html('series: '+seriesIndex+', point: '+pointIndex+', data: '+data);\n }\n );\n });\n");
<div id="chart_big1"></div> <?php $x = array(); $y = array(); $allconsumables = Consumable::model()->findAllByAttributes(array('is_deleted' => 0)); foreach ($allconsumables as $cons) { $x[] = $cons['name']; $stocks = Allocate::model()->findAllByAttributes(array('cons_id' => $cons['id'], 'date_out' => NULL)); $y[] = count($stocks); } $x_data = json_encode($x); $y_data = json_encode($y); Yii::app()->clientScript->registerScript('chart_big1', "\n\$(document).ready(function(){\n \$.jqplot.config.enablePlugins = true;\n var s1 = {$y_data};\n var ticks = {$x_data};\n \n plot1 = \$.jqplot('chart_big1', [s1], {\n // Only animate if we're not using excanvas (not in IE 7 or IE 8)..\n animate: !\$.jqplot.use_excanvas,\n seriesDefaults:{\n renderer:\$.jqplot.BarRenderer,\n pointLabels: { show: true }\n },\n axes: {\n xaxis: {\n renderer: \$.jqplot.CategoryAxisRenderer,\n ticks: ticks\n }\n },\n highlighter: { show: false }\n });\n \n \$('#chart1').bind('jqplotDataClick',\n function (ev, seriesIndex, pointIndex, data) {\n \$('#info1').html('series: '+seriesIndex+', point: '+pointIndex+', data: '+data);\n }\n );\n });\n");
public function getInfo() { /* Items allocated*/ $commodity['consumable'] = Consumable::model()->findAll(); $commodity['monitor'] = Monitor::model()->findAll(); $commodity['printers'] = Printers::model()->findAll(); $commodity['devices'] = Devices::model()->findAll(); $dup = $commodity; /* Items available on Loan*/ $availableOnLoan = 0; $thresholdItems = 0; $content = ''; foreach ($commodity as $key => $commo) { foreach ($commo as $item) { if ($item['available_on_loan'] == 1 || $item['available_on_loan'] == 'Yes') { ++$availableOnLoan; } if ($key == 'consumable') { $commodity = Commodity::model()->findByAttributes(array('name' => $key)); $allocates = Allocate::model()->findAllByAttributes(array('commodity_id' => $commodity['id'], 'cons_id' => $item['id'])); if (count($allocates) < $item['threshold']) { ++$thresholdItems; } } } } /** Allocated and unallocated **/ $countAllocated = 0; $countUnAllocated = 0; $commodity = $dup; $unAllocated = Allocate::model()->findAllByAttributes(array('date_out' => NULL)); $allocated = Allocate::model()->findAll('date_out IS NOT NULL'); $countAllocated += count($allocated); $countUnAllocated += count($unAllocated); $content .= '<b style="color:red">' . $availableOnLoan . '</b> item available on loan<br/>'; $content .= '<b style="color:red">' . $thresholdItems . '</b> item below threshold<br/>'; $content .= '<b style="color:red">' . $countAllocated . '</b> item allocated<br/>'; $content .= '<b style="color:red">' . $countUnAllocated . '</b> item unallocated<br/>'; /* Items below threshold*/ return $content; }