public function __construct($idRecipe, $user_id) { $this->_db = STOCK_DB::getInstance(); $this->_user_id = $user_id; $recipe = $this->_db->get('Recipes', ['idRecipe', '=', $idRecipe], $this->_user_id); $recipe = $recipe->first(); }
public function __construct() { $this->_db = STOCK_DB::getInstance(); if (!$this->_user) { $this->_user = new User(); } $data = $this->_db->get('Products', ['id', '>=', 1], $this->_user->data()->id); $this->_count = count($data); $this->_products = $data->results(); }
public function __construct($id = null, $user = null) { $this->_db = STOCK_DB::getInstance(); if (!$this->_user) { $this->_user = new User(); } if (isset($id)) { $this->find($id); return $this; } }
public static function exists($name) { $db = STOCK_DB::getInstance(); $user = new User(); $userId = $user->data()->id; $sql = "SELECT * FROM `Unit` WHERE `Unit`.`Name` = ? AND `Unit`.`user` = ?;"; if ($db->query($sql, [$name, $userId])->count()) { return true; } else { return false; } }
public function __construct() { $this->_db = STOCK_DB::getInstance(); if (!$this->_user) { $this->_user = new User(); } $data = $this->_db->get('Suppliers', ['id', '>=', 1], $this->_user->data()->id); $this->_count = count($data); $this->_suppliers = array(); foreach ($data->results() as $result) { $supplier = new supplier($result->id); array_push($this->_suppliers, $supplier); } }
public function __construct($recipe_id) { $this->_db = STOCK_DB::getInstance(); $this->_user = new User(); $ingredientUnit = $this->_db->join(array(array('table_name' => 'ProductRecipes', 'next_table_name' => 'Unit', 'table_column' => 'unit', 'next_table_column' => 'Name', 'selections' => array('*')), array('table_name' => 'Unit', 'next_table_name' => null, 'table_column' => null, 'next_table_column' => null, 'selections' => array('Ratio'))), true); //select distinct $this->_ingredients = $ingredientUnit->results(); $recipeInfo = $this->toArray(); //echo var_dump($recipeInfo); //die(); $ingredients = array(); foreach ($recipeInfo as $ingredient) { $products = new products(); $product = $products->findProduct($ingredient['Products_id']); $product = $this->_db->get('Products', ['id', '=', $ingredient['Products_id']])->results(); $product = json_decode(json_encode($product), true); $product = $product[0]; //remove unneccesary fields unset($product['user']); unset($product['Suppliers_id']); unset($product['purchaseUnitPrice']); unset($product['user']); unset($product['purchaseUnitWeight']); unset($product['purchaseUnit']); unset($product['discount']); unset($product['density']); //append ProductRecipes fields $product['quantity'] = $ingredient['quantity']; $product['Ratio'] = $ingredient['Ratio']; //replace the unitName with ProductRecipes unit $product['unitName'] = $ingredient['unit']; array_push($ingredients, $product); /* final $product: id - from Products productName - from Products yeild - from Products costPerKiloUnit - from Products unitName - from ProductRecipes quantity - from ProductRecipes Ratio - from Unit */ } $this->_ingredients = $ingredients; return $this; }
public function __construct() { $this->_db = STOCK_DB::getInstance(); if (!$this->_user) { $this->_user = new User(); } $data = $this->_db->get('Recipes', ['id', '>=', 1], $this->_user->data()->id); $this->_count = count($data); $this->_recipes = $data->results(); $recipes = $this->toArray(); for ($i = 0; $i < count($recipes); $i++) { $ingredients = new ingredients($recipes[$i]['id']); $recipes[$i]['ingredients'] = $ingredients->get(); //remove user from the array unset($recipes[$i]['user']); } $this->_recipes = $recipes; }
public function __construct($dom, $user_id) { $this->_db = STOCK_DB::getInstance(); $this->_user_id = $user_id; //load database content $units = $this->_db->get('Unit', ['name', '<>', ''], $this->_user_id); $unit_count = $units->count(); $units = $units->results(); //set the root document self::$dom = $dom; //create the table and add it to the dom $this->table = self::$dom->createElement('table'); $this->table->setAttribute('id', 'units_table'); //initialize num_rows/num_columns $this->num_rows = sizeof($units); $this->num_columns = sizeof($units[0]); $units_heading = self::$dom->createElement('thead'); $this->table->appendChild($units_heading); $heading_row = self::$dom->createElement('tr'); $units_heading->appendChild($heading_row); $heading = array(); array_push($heading, self::$dom->createElement('th', 'Unit name')); array_push($heading, self::$dom->createElement('th', 'Ratio')); array_push($heading, self::$dom->createElement('th', 'Unit type')); array_push($heading, self::$dom->createElement('th', ' ')); foreach ($heading as $head) { $heading_row->appendChild($head); } //create all the cells in the table and fill them with database content foreach ($units as $unit) { //create the table row $row = self::$dom->createElement('tr'); //Name: $span = self::$dom->createElement('span', $unit->Name); $cell = self::$dom->createElement('td'); $cell->setAttribute('id', $unit->Name . 'name'); $cell->appendChild($span); $row->appendChild($cell); //Ratio: $span = self::$dom->createElement('span', $unit->Ratio); $cell = self::$dom->createElement('td'); $cell->setAttribute('id', $unit->Name . 'ratio'); $cell->appendChild($span); $row->appendChild($cell); //Unit type: $span = self::$dom->createElement('span', $unit->UnitType); $cell = self::$dom->createElement('td'); $types = $this->_db->get('UnitType', ['UnitName', '<>', '']); $types = $types->results(); $select = self::$dom->createElement('select'); $select->setAttribute('id', $unit->UnitType . 'UnitType'); foreach ($types as $type) { $option = self::$dom->createElement('option', $type->UnitName); $option->setAttribute('value', $type->UnitName); if ($type->UnitName == $unit->UnitType) { $option->setAttribute('selected', ''); } $select->appendChild($option); } $cell->appendChild($select); $cell->setAttribute('id', $unit->Name . 'untiType'); $row->appendChild($cell); /****Add in Delete button cell*****/ $link = self::$dom->createElement('a', 'Delete'); $a = '/account/unit/'; $link->setAttribute('href', 'unit/' . $unit->Name); $cell = self::$dom->createElement('td'); $cell->setAttribute('id', $unit->Name . 'view'); $cell->appendChild($link); $row->appendChild($cell); //Set row attributes $row->setAttribute('id', $unit->Name); //Finish row $this->table->appendChild($row); } return $this; }
public function __construct($dom, $user_id) { $this->_db = STOCK_DB::getInstance(); $user = new User(); $this->_user_id = $user->data()->id; //load database content $this->_suppliers = new suppliers(); //set the root document self::$dom = $dom; //create the table and add it to the dom $this->table = self::$dom->createElement('table'); $this->table->setAttribute('id', 'supplier_table'); //initialize num_rows/num_columns $this->num_rows = $this->_suppliers->count(); $this->num_columns = sizeof($this->_suppliers->getSuppliers()[0]); //Draw the supplier heading $suppliers_heading = self::$dom->createElement('thead'); $this->table->appendChild($suppliers_heading); $heading_row = self::$dom->createElement('tr'); $suppliers_heading->appendChild($heading_row); $heading = array(); array_push($heading, self::$dom->createElement('th', 'Supplier Name')); array_push($heading, self::$dom->createElement('th', 'Phone Number')); array_push($heading, self::$dom->createElement('th', 'Fax Number')); array_push($heading, self::$dom->createElement('th', 'Email')); array_push($heading, self::$dom->createElement('th', ' ')); foreach ($heading as $head) { $heading_row->appendChild($head); } //create all the cells in the table and fill them with database content foreach ($this->_suppliers->getSuppliers() as $supplier) { //create the table row $row = self::$dom->createElement('tr'); //Name: $span = self::$dom->createElement('span', $supplier->data()->supplierName); $cell = self::$dom->createElement('td'); $cell->setAttribute('id', $supplier->data()->id . 'name'); $cell->appendChild($span); $row->appendChild($cell); //Phone $span = self::$dom->createElement('span', $supplier->data()->phoneNumber); $cell = self::$dom->createElement('td'); $cell->setAttribute('id', $supplier->data()->id . 'phone'); $cell->appendChild($span); $row->appendChild($cell); //Fax $span = self::$dom->createElement('span', $supplier->data()->faxNumber); $cell = self::$dom->createElement('td'); $cell->setAttribute('id', $supplier->data()->id . 'fax'); $cell->appendChild($span); $row->appendChild($cell); //Email $span = self::$dom->createElement('span', $supplier->data()->emailAddress); $cell = self::$dom->createElement('td'); $cell->setAttribute('id', $supplier->data()->id . 'email'); $cell->appendChild($span); $row->appendChild($cell); /****Add in Edit button cell*****/ $button = self::$dom->createElement('input'); $button->setAttribute('type', 'submit'); $button->setAttribute('value', 'Edit/Delete'); $button->setAttribute('class', 'button'); $button->setAttribute('id', 'button' . $supplier->data()->id); $cell = self::$dom->createElement('td'); $cell->setAttribute('id', $supplier->data()->id . 'edit'); $cell->appendChild($button); $row->appendChild($cell); //Set row attributes $row->setAttribute('id', $supplier->data()->id); //Finish row $this->table->appendChild($row); } return $this; }
public function __construct($dom, $user_id) { $this->_db = STOCK_DB::getInstance(); $this->_user_id = $user_id; //load database content $dishs = $this->_db->get('Dishes', ['id', '>=', '1'], $this->_user_id); $dish_count = $dishs->count(); $dishs = $dishs->results(); //set the root document self::$dom = $dom; //create the table and add it to the dom $this->table = self::$dom->createElement('table'); $this->table->setAttribute('id', 'dishes_table'); //initialize num_rows/num_columns $this->num_rows = sizeof($dishs); $this->num_columns = sizeof($dishs[0]); $dishs_heading = self::$dom->createElement('thead'); $this->table->appendChild($dishs_heading); $heading_row = self::$dom->createElement('tr'); $dishs_heading->appendChild($heading_row); $heading = array(); array_push($heading, self::$dom->createElement('th', 'Dish name')); array_push($heading, self::$dom->createElement('th', 'Retail price')); array_push($heading, self::$dom->createElement('th', 'Cost price')); array_push($heading, self::$dom->createElement('th', 'Margin')); array_push($heading, self::$dom->createElement('th', 'Gross Revenue')); array_push($heading, self::$dom->createElement('th', ' ')); array_push($heading, self::$dom->createElement('th', ' ')); foreach ($heading as $head) { $heading_row->appendChild($head); } //create all the cells in the table and fill them with database content foreach ($dishs as $dish) { //create the table row $row = self::$dom->createElement('tr'); //Name: $span = self::$dom->createElement('span', $dish->dishName); $cell = self::$dom->createElement('td'); $cell->setAttribute('id', $dish->id . 'name'); $cell->appendChild($span); $row->appendChild($cell); //Price: $span = self::$dom->createElement('span', number_format($dish->dishPrice, 2)); $cell = self::$dom->createElement('td'); $cell->setAttribute('id', $dish->id . 'dishPrice'); $text = self::$dom->createTextNode('$ '); $cell->appendChild($text); $cell->appendChild($span); $row->appendChild($cell); //Cost price: $span = self::$dom->createElement('span', number_format($dish->costPrice, 2)); $cell = self::$dom->createElement('td'); $cell->setAttribute('id', $dish->id . 'costPrice'); $text = self::$dom->createTextNode('$ '); $cell->appendChild($text); $cell->appendChild($span); $row->appendChild($cell); //Margin: $span = self::$dom->createElement('span', $dish->margin); $cell = self::$dom->createElement('td'); $cell->setAttribute('id', $dish->id . 'margin'); $text = self::$dom->createTextNode('%'); $cell->appendChild($span); $cell->appendChild($text); $row->appendChild($cell); //Gross revenue: $span = self::$dom->createElement('span', number_format($dish->grossRevenue, 2)); $cell = self::$dom->createElement('td'); $cell->setAttribute('id', $dish->id . 'grossRevenue'); $text = self::$dom->createTextNode('$ '); $cell->appendChild($text); $cell->appendChild($span); $row->appendChild($cell); /****Add in view button cell*****/ $link = self::$dom->createElement('a', 'View'); $a = '/account/dish/'; $link->setAttribute('href', 'dish/' . $dish->id); $cell = self::$dom->createElement('td'); $cell->setAttribute('id', $dish->id . 'view'); $cell->appendChild($link); $row->appendChild($cell); /****Add in Edit button cell*****/ $link = self::$dom->createElement('a', 'Edit/Delete'); $a = '/account/dish/'; $link->setAttribute('href', 'dish/' . $dish->id); $cell = self::$dom->createElement('td'); $cell->setAttribute('id', $dish->id . 'edit'); $cell->appendChild($link); $row->appendChild($cell); //Set row attributes $row->setAttribute('id', $dish->id); //Finish row $this->table->appendChild($row); } return $this; }
public function __construct($dom) { $this->_db = STOCK_DB::getInstance(); $user = new User(); $this->_user_id = $user->data()->id; //load database content $this->_products = new products(); //set the root document self::$dom = $dom; //create the table and add it to the dom $this->table = self::$dom->createElement('table'); $this->table->setAttribute('id', 'products_table'); //initialize num_rows/num_columns $this->num_rows = $this->_products->count(); $this->num_columns = sizeof($this->_products->getProducts()[0]); $products_heading = self::$dom->createElement('thead'); $this->table->appendChild($products_heading); $heading_row = self::$dom->createElement('tr'); $products_heading->appendChild($heading_row); $heading = array(); array_push($heading, self::$dom->createElement('th', 'Product Name')); array_push($heading, self::$dom->createElement('th', 'Order by')); array_push($heading, self::$dom->createElement('th', 'Supplier')); array_push($heading, self::$dom->createElement('th', 'Cost per kilo/litre')); array_push($heading, self::$dom->createElement('th', ' ')); foreach ($heading as $head) { $heading_row->appendChild($head); } //create all the cells in the table and fill them with database content foreach ($this->_products->getProducts() as $product) { //create the table row $row = self::$dom->createElement('tr'); //Name: $span = self::$dom->createElement('span', $product->data()->productName); $cell = self::$dom->createElement('td'); $cell->setAttribute('id', $product->data()->id . 'name'); $cell->appendChild($span); $row->appendChild($cell); //Purchase Unit: $span = self::$dom->createElement('span', $product->data()->purchaseUnit); $cell = self::$dom->createElement('td'); $cell->setAttribute('id', $product->data()->id . 'purchaseUnit'); $cell->appendChild($span); $row->appendChild($cell); //Supplier: $supplier = $this->_db->get('Suppliers', ['id', '=', $product->data()->Suppliers_id], $this->_user_id); $span = self::$dom->createElement('span', $supplier->first()->supplierName); $cel = self::$dom->createElement('td'); $cel->setAttribute('id', $product->data()->id . 'supplier'); $cel->appendChild($span); $row->appendChild($cel); //Cost per kilo/litre: $span = self::$dom->createElement('span', $product->data()->costPerKiloUnit); $ce = self::$dom->createElement('td'); $ce->setAttribute('id', $product->data()->id . 'costPerKiloUnit'); $ce->appendChild($span); $suffix = self::$dom->createTextNode('kilo/litre'); $ce->appendChild($suffix); $row->appendChild($ce); /****Add in Edit button cell*****/ $button = self::$dom->createElement('input'); $button->setAttribute('type', 'submit'); $button->setAttribute('value', 'Edit/Delete'); $button->setAttribute('class', 'button'); $button->setAttribute('id', 'button' . $product->data()->id); $cell = self::$dom->createElement('td'); $cell->setAttribute('id', $product->data()->id . 'edit'); $cell->appendChild($button); $row->appendChild($cell); //Set row attributes $row->setAttribute('id', $product->data()->id); //Finish row $this->table->appendChild($row); } return $this; }
public function __construct($dom, $user_id) { $this->_db = STOCK_DB::getInstance(); $this->_user_id = $user_id; //load database content $recipes = $this->_db->get('Recipes', ['id', '>=', '1'], $this->_user_id); $recipe_count = $recipes->count(); $recipes = $recipes->results(); //set the root document self::$dom = $dom; //create the table and add it to the dom $this->table = self::$dom->createElement('table'); $this->table->setAttribute('id', 'recipes_table'); //initialize num_rows/num_columns $this->num_rows = sizeof($recipes); $this->num_columns = sizeof($recipes[0]); $recipes_heading = self::$dom->createElement('thead'); $this->table->appendChild($recipes_heading); $heading_row = self::$dom->createElement('tr'); $recipes_heading->appendChild($heading_row); $heading = array(); array_push($heading, self::$dom->createElement('th', 'Recipe name')); array_push($heading, self::$dom->createElement('th', 'Yeild')); array_push($heading, self::$dom->createElement('th', 'Cost')); array_push($heading, self::$dom->createElement('th', ' ')); array_push($heading, self::$dom->createElement('th', ' ')); foreach ($heading as $head) { $heading_row->appendChild($head); } //create all the cells in the table and fill them with database content foreach ($recipes as $recipe) { //create the table row $row = self::$dom->createElement('tr'); //Name: $span = self::$dom->createElement('span', $recipe->recipeName); $cell = self::$dom->createElement('td'); $cell->setAttribute('id', $recipe->id . 'name'); $cell->appendChild($span); $row->appendChild($cell); //Yeild: $span = self::$dom->createElement('span', $recipe->yeild); $cell = self::$dom->createElement('td'); $cell->setAttribute('id', $recipe->id . 'yeild'); $cell->appendChild($span); $text = $recipe->yeildUnit; switch ($text) { case 'Volume': $text = ' L'; case 'Weight': $text = ' Kg'; case 'Each': $text = ' Portion/Serving'; } if ($recipe->yeild > 1) { $text .= 's'; } $text = self::$dom->createTextNode($text); $cell->appendChild($text); $row->appendChild($cell); //Cost: $span = self::$dom->createElement('span', $recipe->recipeCost); $cell = self::$dom->createElement('td'); $cell->setAttribute('id', $recipe->id . 'cost'); $cell->appendChild($span); $row->appendChild($cell); /****Add in view button cell*****/ $link = self::$dom->createElement('a', 'View'); $a = '/account/recipe/'; $link->setAttribute('href', 'recipe/' . $recipe->id); $cell = self::$dom->createElement('td'); $cell->setAttribute('id', $recipe->id . 'view'); $cell->appendChild($link); $row->appendChild($cell); /****Add in Edit button cell*****/ $link = self::$dom->createElement('a', 'Edit'); $a = '/account/recipe/'; $link->setAttribute('href', 'edit_recipe/' . $recipe->id); $cell = self::$dom->createElement('td'); $cell->setAttribute('id', $recipe->id . 'edit'); $cell->appendChild($link); $row->appendChild($cell); //Set row attributes $row->setAttribute('id', $recipe->id); //Finish row $this->table->appendChild($row); } return $this; }