Browse Source

Add stock movements report

stock_management
João Andrade 2 years ago
parent
commit
488988f7d4
  1. 1
      langs/en/items.json
  2. 3
      langs/en/reports.json
  3. 48
      lib/reports.php
  4. 2
      pages/edititem.php
  5. 9
      pages/export.php

1
langs/en/items.json

@ -10,6 +10,7 @@
"itemid": "Item ID",
"id": "ID",
"Edit Item": "Edit Item",
"stockid": "Stock ID",
"adding stock": "Adding stock for {item}",
"removing stock": "Removing stock from {item}"
}

3
langs/en/reports.json

@ -5,5 +5,6 @@
"choose an option": "Choose an option",
"csv file": "CSV text file",
"ods file": "ODS spreadsheet",
"html file": "HTML web page"
"html file": "HTML web page",
"Stock": "Stock movements"
}

48
lib/reports.php

@ -151,6 +151,49 @@ function getLocationReport(): Report {
return $report;
}
function getStockReport($filter = []): Report {
global $database, $Strings;
$stock = $database->select(
"stock", [
"[>]items" => ["itemid"]
], [
"stockid",
"itemid",
"name",
'timestamp',
'stock',
'stock.text1',
'stock.userid'
]);
$report = new Report($Strings->get("Stock", false));
$report->setHeader([
$Strings->get("stockid", false),
$Strings->get("itemid", false),
$Strings->get("name", false),
$Strings->get("date", false),
$Strings->get("amount", false),
$Strings->get("description", false),
$Strings->get("changed by", false)
]);
for ($i = 0; $i < count($stock); $i++) {
$user = "";
if (!is_null($stock[$i]["userid"])) {
$u = new User($stock[$i]["userid"]);
$user = $u->getName() . " (" . $u->getUsername() . ')';
}
$report->addDataRow([
$stock[$i]["stockid"],
$stock[$i]["itemid"],
$stock[$i]["name"],
$stock[$i]["timestamp"],
$stock[$i]["stock"],
$stock[$i]["text1"],
$user
]);
}
return $report;
}
function getReport($type): Report {
switch ($type) {
case "item":
@ -165,6 +208,9 @@ function getReport($type): Report {
case "itemstock":
return getItemReport(["AND" => ["qty[<]want", "want[>]" => 0]]);
break;
case "stock":
return getStockReport();
break;
default:
return new Report("error", ["ERROR"], ["Invalid report type."]);
}
@ -173,4 +219,4 @@ function getReport($type): Report {
function generateReport($type, $format) {
$report = getReport($type);
$report->output($format);
}
}

2
pages/edititem.php

@ -165,7 +165,7 @@ if (!empty($VARS['id'])) {
<div class="form-group">
<label for="qty"><i class="fas fa-hashtag"></i> <?php $Strings->get('quantity'); ?></label>
<?php
if ($SETTINGS['stock_management'] && $editing && !$cloning){
if ($SETTINGS['stock_management'] && $editing && !$cloning) {
?>
<input type="text" class="form-control" id="qty" name="qty" readonly value="<?php echo $itemdata['qty']; ?>" />
<?php

9
pages/export.php

@ -16,6 +16,13 @@ redirectifnotloggedin();
<div class="form-group">
<label for="type"><?php $Strings->get("report type"); ?></label>
<select name="type" class="form-control" required>
<?php
if ($SETTINGS['stock_management']) {
?>
<option value="stock"><?php $Strings->get("Stock") ?></option>
<?php
}
?>
<option value="item"><?php $Strings->get("Items") ?></option>
<option value="category"><?php $Strings->get("Categories") ?></option>
<option value="location"><?php $Strings->get("Locations") ?></option>
@ -46,4 +53,4 @@ redirectifnotloggedin();
<button type="submit" class="btn btn-success ml-auto" id="genrptbtn"><i class="fas fa-download"></i> <?php $Strings->get("generate report"); ?></button>
</div>
</form>
</div>
</div>
Loading…
Cancel
Save