/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     while (true) {
         $serial = new PhpSerial();
         // First we must specify the device. This works on both linux and windows (if
         // your linux serial device is /dev/ttyS0 for COM1, etc)
         $serial->deviceSet($this->argument('device'));
         // We can change the baud rate, parity, length, stop bits, flow control
         $serial->confBaudRate(9600);
         $serial->confParity("none");
         $serial->confCharacterLength(8);
         $serial->confStopBits(1);
         $serial->confFlowControl("none");
         $serial->deviceOpen();
         $read = '';
         $theResult = '';
         $start = microtime(true);
         while ($read == '' && microtime(true) <= $start + 0.5) {
             $read = $serial->readPort();
             if ($read != '') {
                 $theResult .= $read;
                 $read = '';
             }
         }
         $theResult = trim($theResult);
         if (!$theResult) {
             continue;
         }
         echo $theResult . "\n";
         $line = explode("\n", $theResult);
         foreach ($line as $l) {
             $l = trim($l);
             $watt_array = explode(" ", $l);
             $unitId = 1;
             if ($watt_array[0] == "watt" && isset($watt_array[1]) && $watt_array[1] != false) {
                 Watts::addWatt($unitId, $watt_array[1]);
                 //funtion sa models/Watts.php
                 Units::lessCredit($unitId, $watt_array[1]);
             }
         }
         $unitId = 1;
         if (Units::hasCredit($unitId)) {
             $serial->sendMessage("on");
         } else {
             $serial->sendMessage("off");
         }
         $serial->deviceClose();
     }
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $number = $this->ask('Enter Room Number');
     $units = new Units();
     $units->number = $number;
     $units->save();
     $this->info('Success!');
 }
Example #3
0
 public function insertUnits(Units $units)
 {
     $con = self::openConnection();
     $affected = 0;
     mysqli_begin_transaction($con);
     $stm = mysqli_stmt_init($con);
     $sql = "INSERT INTO currency (code) VALUE (?)";
     mysqli_stmt_prepare($stm, $sql);
     foreach ($units->getUnits() as $unit) {
         $code = $unit->getCode();
         mysqli_stmt_bind_param($stm, 's', $code);
         mysqli_stmt_execute($stm);
         if (mysqli_affected_rows($con) == 1) {
             $affected++;
         }
     }
     if ($affected > 0) {
         mysqli_commit($con);
     } else {
         mysqli_rollback($con);
     }
     return $affected;
 }
 /**
 	Constructor to create/load a Recipe
 */
 function Recipe($id = 0, $name = '', $ethnic = 'NULL', $base = 'NULL', $course = 'NULL', $time = 'NULL', $difficulty = 'NULL', $directions = '', $comments = '', $serving = 0, $source = 0, $source_desc = '', $user = NULL, $private = 'FALSE', $picture = '', $picture_type = '', $picture_oid = NULL)
 {
     global $DB_LINK, $SMObj;
     // Initial a new Recipe Object
     $this->id = $id;
     $this->name = $name;
     $this->ethnic = $ethnic;
     $this->base = $base;
     $this->course = $course;
     $this->prep_time = $time;
     $this->difficulty = $difficulty;
     $this->directions = $directions;
     $this->comments = $comments;
     $this->serving_size = $serving;
     $this->source = $source;
     $this->source_desc = $source_desc;
     $this->picture = $picture;
     $this->picture_type = $picture_type;
     $this->picture_oid = $picture_oid;
     if ($user == "" || $user == NULL) {
         $this->user = $SMObj->getUserID();
     } else {
         $this->user = $user;
     }
     if ($this->source == '') {
         $this->source = 'NULL';
     }
     $this->modified = $DB_LINK->DBDate(time());
     // set the current date
     $this->unitSystem = Units::getLocalSystem();
     if ($private == "TRUE") {
         $this->private = $DB_LINK->true;
     } else {
         $this->private = $DB_LINK->false;
     }
 }
 /**
  * Show the form for editing the specified resource.
  *
  * @param  int $id
  * @return Response
  */
 public function edit($id)
 {
     if (!$id) {
         return Redirect::route('products.index')->with('error', 'Please Provide product id');
     }
     $product = Products::find($id);
     if (empty($product)) {
         return Redirect::route('products.index')->with('error', 'Product not found');
     }
     $types = Types::dropdownList();
     $units = Units::dropdownList();
     return View::make('products.edit', compact('product', 'types', 'units'));
 }
Example #6
0
<input type="hidden" name="dosql" value="update">

<table cellspacing="1" cellpadding="2" border="0" class="data">
<tr>
	<th colspan = "2">
		<?php 
if ($ingredient_id) {
    echo $LangUI->_('Edit Ingredient');
} else {
    echo $LangUI->_('Add Ingredient');
}
?>
	</th>
</tr>
<?php 
$units = Units::getAllUnits();
// Load the units
$rc_locations = DBUtils::fetchColumn($db_table_locations, 'location_desc', 'location_id', 'location_desc');
$locations = DBUtils::createList($rc_locations, 'location_id', 'location_desc');
$liqsol = array("FALSE" => $LangUI->_('Liquid'), "TRUE" => $LangUI->_('Solid'));
$ingredient_name = "";
$ingredient_desc = "";
$ingredient_unit = "";
$ingredient_loc = "";
$ingredient_solid = "";
$coreingredient_id = "";
$coreingredient_Name = "";
if ($ingredient_id) {
    $ingredient_name = $ingredients->fields['ingredient_name'];
    $ingredient_desc = $ingredients->fields['ingredient_desc'];
    $ingredient_unit = $ingredients->fields['ingredient_unit'];
Example #7
0
 function run($dbi, $argstr, &$request, $basepage)
 {
     global $WikiTheme;
     $this->_supported_operators = array(':=', '<', '<=', '>', '>=', '!=', '==', '=~');
     $this->_text_operators = array(':=', '==', '=~', '!=');
     $args = $this->getArgs($argstr, $request);
     if (empty($args['page'])) {
         $args['page'] = "*";
     }
     if (!isset($args['s'])) {
         // it might be (integer) 0
         $args['s'] = "*";
     }
     $posted = $request->getArg("semsearch");
     $form = $this->showForm($dbi, $request, $args);
     if (isset($this->_norelations_warning)) {
         $form->pushContent(HTML::div(array('class' => 'warning'), _("Warning:"), HTML::br(), _("No relations nor attributes in the whole wikidb defined!"), "\n", fmt("See %s", WikiLink(_("Help:SemanticRelations")))));
     }
     extract($args);
     // for convenience and harmony we allow GET requests also.
     if (!$request->isPost()) {
         if ($relation or $attribute) {
             // check for good GET request
         } else {
             return $form;
         }
         // nobody called us, so just display our supadupa form
     }
     $pagequery = $this->regex_query($page, $args['case_exact'], $args['regex']);
     // we might want to check for semsearch['relations'] and semsearch['attributes'] also
     if (empty($relation) and empty($attribute)) {
         // so we just clicked without selecting any relation.
         // hmm. check which button we clicked, before we do the massive alltogether search.
         if (isset($posted['relations']) and $posted['relations']) {
             $relation = '*';
         } elseif (isset($posted['attributes']) and $posted['attributes']) {
             $attribute = '*';
             // here we have to check for invalid text operators. ignore it then
             if (!in_array($attr_op, $this->_text_operators)) {
                 $attribute = '';
             }
         }
     }
     $searchtype = "Text";
     if (!empty($relation)) {
         $querydesc = $relation . "::" . $s;
         $linkquery = $this->regex_query($s, $args['case_exact'], $args['regex']);
         $relquery = $this->regex_query($relation, $args['case_exact'], $args['regex']);
         $links = $dbi->linkSearch($pagequery, $linkquery, 'relation', $relquery);
         $pagelist = new PageList($info, $exclude, $args);
         $pagelist->_links = array();
         while ($link = $links->next()) {
             $pagelist->addPage($link['pagename']);
             $pagelist->_links[] = $link;
         }
         // default (=empty info) wants all three. but we want to be able to override this.
         // $pagelist->_columns_seen is the exploded info
         if (!$info or $info and isset($pagelist->_columns_seen['relation'])) {
             $pagelist->addColumnObject(new _PageList_Column_SemanticSearch_relation('relation', _("Relation"), $pagelist));
         }
         if (!$args['info'] or $args['info'] and isset($pagelist->_columns_seen['linkto'])) {
             $pagelist->addColumnObject(new _PageList_Column_SemanticSearch_link('linkto', _("Link"), $pagelist));
         }
     }
     // can we merge two different pagelist?
     if (!empty($attribute)) {
         $relquery = $this->regex_query($attribute, $args['case_exact'], $args['regex']);
         if (!in_array($attr_op, $this->_supported_operators)) {
             return HTML($form, $this->error(fmt("Illegal operator: %s", HTML::tt($attr_op))));
         }
         $s_base = preg_replace("/,/", "", $s);
         $units = new Units();
         if (!is_numeric($s_base)) {
             $s_base = $units->basevalue($s_base);
             $is_numeric = is_numeric($s_base);
         } else {
             $is_numeric = true;
         }
         // check which type to search with:
         // at first check if forced text matcher
         if ($attr_op == '=~') {
             if ($s == '*') {
                 $s = '.*';
             }
             // help the poor user. we need pcre syntax.
             $linkquery = new TextSearchQuery("{$s}", $args['case_exact'], 'pcre');
             $querydesc = "{$attribute} {$attr_op} {$s}";
         } elseif ($is_numeric) {
             // do comparison with numbers
             /* We want to search for multiple attributes also. linkSearch can do this.
              * But we have to construct the query somehow. (that's why we try the AND OR dhtml)
              *     population < 1 million AND area > 50 km2
              * Here we check only for one attribute per page.
              * See SemanticSearchAdvanced for the full expression.
              */
             // it might not be the best idea to use '*' as variable to expand. hmm.
             if ($attribute == '*') {
                 $attribute = '_star_';
             }
             $searchtype = "Numeric";
             $query = $attribute . " " . $attr_op . " " . $s_base;
             $linkquery = new SemanticAttributeSearchQuery($query, $attribute, $units->baseunit($s));
             if ($attribute == '_star_') {
                 $attribute = '*';
             }
             $querydesc = $attribute . " " . $attr_op . " " . $s;
             // no number or unit: check other text matchers or '*' MATCH_ALL
         } elseif (in_array($attr_op, $this->_text_operators)) {
             if ($attr_op == '=~') {
                 if ($s == '*') {
                     $s = '.*';
                 }
                 // help the poor user. we need pcre syntax.
                 $linkquery = new TextSearchQuery("{$s}", $args['case_exact'], 'pcre');
             } else {
                 $linkquery = $this->regex_query($s, $args['case_exact'], $args['regex']);
             }
             $querydesc = "{$attribute} {$attr_op} {$s}";
             // should we fail or skip when the user clicks on Relations?
         } elseif (isset($posted['relations']) and $posted['relations']) {
             $linkquery = false;
             // skip
         } else {
             $querydesc = $attribute . " " . $attr_op . " " . $s;
             return HTML($form, $this->error(fmt("Only text operators can be used with strings: %s", HTML::tt($querydesc))));
         }
         if ($linkquery) {
             $links = $dbi->linkSearch($pagequery, $linkquery, 'attribute', $relquery);
             if (empty($relation)) {
                 $pagelist = new PageList($args['info'], $args['exclude'], $args);
                 $pagelist->_links = array();
             }
             while ($link = $links->next()) {
                 $pagelist->addPage($link['pagename']);
                 $pagelist->_links[] = $link;
             }
             // default (=empty info) wants all three. but we want to override this.
             if (!$args['info'] or $args['info'] and isset($pagelist->_columns_seen['attribute'])) {
                 $pagelist->addColumnObject(new _PageList_Column_SemanticSearch_relation('attribute', _("Attribute"), $pagelist));
             }
             if (!$args['info'] or $args['info'] and isset($pagelist->_columns_seen['value'])) {
                 $pagelist->addColumnObject(new _PageList_Column_SemanticSearch_link('value', _("Value"), $pagelist));
             }
         }
     }
     if (!isset($pagelist)) {
         $querydesc = _("<empty>");
         $pagelist = new PageList();
     }
     if (!$noheader) {
         // We put the form into the caption just to be able to return one pagelist object,
         // and to still have the convenience form at the top. we could workaround this by
         // putting the form as WikiFormRich into the actionpage. but thid doesnt look as
         // nice as this here.
         $pagelist->setCaption(HTML($noform ? '' : HTML($form, HTML::hr()), fmt("Semantic %s Search Result for \"%s\" in pages \"%s\"", $searchtype, $querydesc, $page)));
     }
     return $pagelist;
 }
 /**
 	Converts an ingredients quantity and units.  This way combining of
 	ingredients will be easier
 */
 function convertToBaseUnits($scaling)
 {
     $this->quantity = Units::convertTo($this->quantity * $scaling, $this->unitMap, $this->unit, $this->solid, $this->unitSystem);
     $this->unitMap = $this->unit;
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     if (!$id) {
         return Redirect::route('units.index')->with('error', 'Please provide unit id');
     }
     $unit = Units::find($id);
     if (empty($unit)) {
         return Redirect::route('units.index')->with('error', 'Unit not found');
     }
     Units::destroy($id);
     return Redirect::route('units.index')->with('success', 'Unit deleted successfully');
 }
Example #10
0
    DBUtils::checkResult($rc, NULL, NULL, $sql);
    // get the list of sections to display, default is 'default'
    $useLayout = split(',', $rc->fields[0]);
    if (!count($useLayout)) {
        $useLayout[] = '';
    }
    //if it does not exist, set it to empty
} else {
    // No store is selected, use the default all sections store
    foreach ($locations as $key => $value) {
        $useLayout[] = $key;
        // add the section
    }
}
// Load the units we are to deal with
$units = Units::getUnits();
// Get the shopping list
$items = array();
if (is_object($listObj)) {
    $items = $listObj->getShoppingList();
}
$printedItems = 0;
//keep track of how many items we show at once
if ($mode == "print") {
    /*************************************************
    			Print the prelim List
    *************************************************/
    ?>
<SCRIPT language="javascript">
<!--
function submitIt(mode) {
Example #11
0
 function _expandurl($url)
 {
     $m = array();
     if (!preg_match('/^ ([^:]+) (:[:=]) (.+) $/x', $url, $m)) {
         return HTML::span(array('class' => 'error'), _("BAD semantic relation link"));
     }
     $this->_relation = urldecode($m[1]);
     $is_attribute = $m[2] == ':=';
     if ($is_attribute) {
         $this->_attribute = urldecode($m[3]);
         // since this stored in the markup cache, we are extra sensible
         // not to store false empty stuff.
         $units = new Units();
         if (!DISABLE_UNITS and !$units->errcode) {
             $this->_attribute_base = $units->Definition($this->_attribute);
             $this->_unit = $units->baseunit($this->_attribute);
         }
     } else {
         $this->_page = urldecode($m[3]);
     }
     return $m;
 }
Example #12
0
 /**
  * @param int $count
  *
  * @return string
  */
 public static function generateSampleProducts($count = 10)
 {
     //		Type
     $typeIds = Producttype::getIdsOrCreateDummy();
     //		category
     $categoryIds = Productcategory::getIdsOrCreateSampelData();
     //		unit berat
     $unitIds = Units::getIdsOrCreateSampleUnits();
     //		parent_id
     $parentId = 0;
     $fake = static::getFake();
     //
     //		Buat Product
     $catId = $fake->getFake()->randomElement($categoryIds);
     $typeId = $fake->getFake()->randomElement($typeIds);
     $unitWeightId = $fake->getFake()->randomElement($unitIds);
     $unitWidthId = $fake->getFake()->randomElement($unitIds);
     $supplierIds = Suppliers::getRecordIdsOrCreate();
     $currencyIds = Currencies::getIdsOrCreateSample();
     //		color
     $colorIds = Colors::getIdsOrCreate();
     //  gradeIds
     $gradeIds = Fabricgrade::getIdsOrCreate();
     $productIds = array();
     for ($rec = 0; $rec < $count; $rec++) {
         $product = $fake->getProduct()->product($catId, $typeId, $unitWeightId, $unitWidthId, $parentId, '\\Emayk\\Ics\\Repo\\Productcategory\\Productcategory');
         $record = static::createRecord($product);
         $productId = $record->id;
         $productIds[] = $productId;
         //		Image/ Photo Product
         $imagesIds[] = Images::getIdsOrCreate($productId, '\\Emayk\\Ics\\Repo\\Products\\Products');
         //			Supplier Product
         //		Product Supplier (Product dapat dari Supplier mana ?)
         $supplierId = $fake->getFake()->randomElement($supplierIds);
         $supplierProduct = Productsuppliers::create(array('master_product_id' => $productId, 'master_supplier_id' => $supplierId));
         $supplierProductId = $supplierProduct->id;
         //			Create Detail
         //		Buat Product Detail
         $unitId = $fake->getFake()->randomElement($unitIds);
         $colorId = $fake->getFake()->randomElement($colorIds);
         $gradeId = $fake->getFake()->randomElement($gradeIds);
         $currSp = $fake->getFake()->randomElement($currencyIds);
         $currSpm = $fake->getFake()->randomElement($currencyIds);
         $detailIds[] = Productdetails::getIdOrCreate($productId, $colorId, $unitId, $gradeId, $currSp, $currSpm);
         //Buat Stock
         //		Buat Stock
         $stockIds[] = Stockproducts::createStock($productId);
     }
     foreach ($stockIds as $stockId) {
         for ($history = 0; $history < 9; $history++) {
             //		Buat Stock Detail/History277
             if ($history % 2 == 0 || $history == 0) {
                 $typeHistory = 'in';
             } else {
                 $typeHistory = 'out';
             }
             $firstHistory = $history == 0;
             //                $stockHistoryIds[] =
             Stockproducthistory::createHistoryStockSample($stockId, $typeHistory, $firstHistory);
         }
     }
     return "Sudah Generate sebanyak " . count($productIds) . " records";
     return s($productIds, $supplierProductId, $imagesIds, $detailIds);
 }
Example #13
0
 public static function dropdownList()
 {
     return array('' => 'Select Unit') + Units::orderBy('name', 'asc')->get()->lists('name', 'id');
 }
Example #14
0
 public static function hasCredit($unitId)
 {
     $units = Units::where('id', $unitId)->first();
     return $units->credit <= 0;
 }
Example #15
0
	<th><?php 
echo $LangUI->_('Ingredient') . " - ";
?>
	<a href="#" id="addNewIngredientsLink" style="color: #FFFFFF;">[<?php 
echo $LangUI->_('add new');
?>
]</a></th>
	<th><?php 
echo $LangUI->_('Optional');
?>
</th>
</tr>
</thead>
<tbody class="content">
<?php 
$localUnits = Units::getAllUnits();
// Print out the ingredient fields
for ($i = 0; $i < $total_ingredients; $i++) {
    if ($ingredients != null) {
        $ingredient_id = $ingredients->fields['map_ingredient'];
        $ingredient_name = $ingredients->fields['ingredient_name'];
        $ingredient_qual = $ingredients->fields['map_qualifier'];
        $ingredient_quant = $ingredients->fields['map_quantity'];
        $ingredient_unit = $ingredients->fields['map_unit'];
        $ingredient_optional = $ingredients->fields['map_optional'] == $DB_LINK->true ? 'checked' : '';
    }
    $ingredient_delete = '';
    // default starting out value (nothing selected)
    if ($i >= $n) {
        $ingredient_id = 0;
        $ingredient_name = "";
Example #16
0
 /**
 	Convert one type of unit to another type of unit
 	@param $val value to convert
 	@param $from unit to convert from (id)
 	@param $to unit to convert to (id)
 	@param $solid true if it is solid, false if not
 	@param $system system of both to and from, 'usa' or 'metric'
 */
 function convertTo($val, $from, $to, $solid, $system)
 {
     global $SMObj, $LangUI, $DB_LINK, $g_rb_units;
     // If it is a unit type that cannot be converted then just return it (unit, pinch, clove...)
     if (in_array($to, $g_rb_units['static']) || in_array($from, $g_rb_units['static'])) {
         return $val;
     }
     // If it can be converted, try...
     $state = NULL;
     if ($solid == $DB_LINK->true) {
         $state = "dry";
     } else {
         $state = "wet";
     }
     $unitFrom = Units::getUnitInfo($from, $state, $system);
     $unitTo = Units::getUnitInfo($to, $state, $system);
     if ($unitFrom == NULL || $unitTo == NULL) {
         // DEBUG: put this back in for warnings
         //echo $LangUI->_('Warning: conversion failure while trying to convert from unit ID') .  " '". $from . "' "
         //	. $LangUI->_('to unit ID') . " '". $to . "'<br />";
         return -1;
     } else {
         return round($val * $unitFrom[0] / $unitTo[0] * 10000) / 10000;
     }
 }
 public function getStatus()
 {
     $unit = Units::where('id', 1)->first();
     return View::make('users.report', array('unit' => $unit));
 }