Skip to content

Added Order tracking feature #9

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Changelog

### 1.5.0 - 31.01.2019 (Mike Glover)
* Added Order feature. Track what consumable are on order. When delivered you click Complete and added to stock levels.
* When choosing a printer on the home page it displays if that consumable is on order

### 1.4.0 - 19.02.2013
* Fix model name character length
* Update to config methods (please see UPGRADE for instructions)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Features
* List all printers (linkable to web IP interface)
* Manage consumable stock levels
* Log consumable installations
* Log consumable orders


Screenshot
Expand Down
8 changes: 8 additions & 0 deletions db/patch7.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
CREATE TABLE `orders` (
`id` int(10) NOT NULL AUTO_INCREMENT PRIMARY KEY,
`order_date` date NOT NULL,
`status` tinyint(1) unsigned NOT NULL,
`item_qty` int(10) unsigned NOT NULL,
`item_id` int(10) unsigned NOT NULL,
FOREIGN KEY (`item_id`) REFERENCES `consumables` (`id`) ON DELETE CASCADE
) COMMENT='' ENGINE='InnoDB' COLLATE 'utf8_unicode_ci';
4 changes: 3 additions & 1 deletion inc/classes/Consumable.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,9 @@ static public function getQtyStatus($qty){
public static function getForModels(&$db){

$sql = "SELECT
consumables.*, models.name AS model, models.id AS model_id
consumables.*, models.name AS model, models.id AS model_id, orders.status AS order_status
FROM consumables
LEFT JOIN orders ON consumables.id = (SELECT orders.item_id WHERE orders.status = 0 LIMIT 1)
LEFT JOIN consumables_models ON consumables.id = consumables_models.consumable_id
LEFT JOIN models ON consumables_models.model_id = models.id";

Expand All @@ -143,6 +144,7 @@ public static function getForModels(&$db){
'colours' => $colours,
'qty' => $c->qty,
'cost' => $c->cost,
'status' => $c->order_status
);

//{"id": 1, "name": "C9720A", "colour": "c", "qty": 5},
Expand Down
107 changes: 107 additions & 0 deletions inc/classes/Order.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php
/*
Copyright (C) 2010 Craig A Rodway.

This file is part of Print Master.

Print Master is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Print Master is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Print Master. If not, see <http://www.gnu.org/licenses/>.
*/


class Order extends fActiveRecord{


var $err;


protected function configure(){
}




/**
* Get a single order
*/
static public function getOne($id){


global $db;

$sql = "SELECT
orders.*
FROM orders
WHERE orders.id = %i
GROUP BY orders.id
LIMIT 1";

$query = $db->query($sql)->asObjects();
$result = $query->fetchRow();
return $result;

}
public static function getConsumables(&$db){

// Get simple list of models
$sql = 'SELECT consumables.*,
consumables.id AS consumable_id,
consumables.name AS consumable_name,
consumables.qty AS current_qty
FROM consumables
ORDER BY consumables.qty ASC, consumables.name ASC';
$consumables = $db->query($sql)->asObjects();
return $consumables;

}
public function increaseStockBy($qty){

global $db;

// Test if quantity is OK (number above 0)
if(!is_numeric($qty) /* OR $qty < 1 */ ){
$this->err = 'Quantity is not a valid number';
return FALSE;
}

// Increase stock
try {
$sql = 'UPDATE consumables SET qty = qty + %i WHERE id = %i LIMIT 1';
$query = $db->execute($sql, $qty, $this->getItemId());
} catch(fSQLException $e){
$this->err = $e->getMessage();
return FALSE;
}

return TRUE;

}
public function setDelivered(){

global $db;


// Set Delivered
try {
$status = 1;
$sql2 = 'UPDATE orders SET status = %i WHERE id = %i LIMIT 1';
$query2 = $db->execute($sql2, $status, $this->getId());
} catch(fSQLException $e){
$this->err = $e->getMessage();
return FALSE;
}

return TRUE;

}
}
55 changes: 55 additions & 0 deletions inc/classes/OrderItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/*
Copyright (C) 2010 Craig A Rodway.

This file is part of Print Master.

Print Master is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Print Master is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Print Master. If not, see <http://www.gnu.org/licenses/>.
*/


class OrderItem extends fActiveRecord{


var $err;


protected function configure(){
}




/**
* Get a single order
*/
static public function getOne($id){


global $db;

$sql = "SELECT
order_items.*
FROM order_items
WHERE order_items.id = %i
GROUP BY order_items.id
LIMIT 1";

$query = $db->query($sql)->asObjects();
$result = $query->fetchRow();
return $result;

}

}
4 changes: 2 additions & 2 deletions inc/core.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@

// @TODO remove these when the thresholds become configurable.
global $status;
$status[3] = array('OK', '73D216'); // 3+ OK
$status[2] = array('Low', 'EDD400'); // 2+ Warning
$status[2] = array('OK', '73D216'); // 2+ OK
$status[1] = array('Low', 'EDD400'); // 1+ Warning
$status[0] = array('Critical', 'CC0000'); // 0: Empty - bad.

// Set up database connection
Expand Down
8 changes: 6 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,17 @@
$sql = "SELECT
consumables.*,
( round( ( (consumables.qty) / (SELECT MAX(qty) FROM consumables) ) * 100 ) ) AS qty_percent,
GROUP_CONCAT(CAST(CONCAT(manufacturers.name, ' ', models.name) AS CHAR) SEPARATOR ', ') AS model
GROUP_CONCAT(CAST(CONCAT(manufacturers.name, ' ', models.name) AS CHAR) SEPARATOR ', ') AS model,
orders.status AS order_status,
orders.id AS order_id,
orders.item_qty AS order_qty
FROM consumables
LEFT JOIN orders ON orders.item_id = (SELECT consumables.id WHERE orders.status = 0 LIMIT 1)
LEFT JOIN consumables_models ON consumables.id = consumables_models.consumable_id
LEFT JOIN models ON consumables_models.model_id = models.id
LEFT JOIN manufacturers ON models.manufacturer_id = manufacturers.id
GROUP BY consumables.id
ORDER BY models.name ASC, consumables.name ASC";
ORDER BY models.name ASC, consumables.name ASC, orders.id ASC";
$consumables = $db->query($sql)->asObjects();

// Get the most consumables in stock
Expand Down
Loading