partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

commit af40987c1fa6c232346d040af26acd9fe61c405d
parent 8c6fbdc731f283e0cea172faa234f22fd484cee2
Author: Felicitus <felicitus@felicitus.org>
Date:   Wed,  4 Jan 2012 22:19:00 +0100

Updated the project reports to support duplicate projects; also fixes the issue with PostgreSQL8

Diffstat:
Msrc/backend/de/RaumZeitLabor/PartKeepr/ProjectReport/ProjectReportService.php | 74++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------
Msrc/frontend/js/Components/Project/ProjectReport.js | 26+++++++++++++++++++++-----
2 files changed, 75 insertions(+), 25 deletions(-)

diff --git a/src/backend/de/RaumZeitLabor/PartKeepr/ProjectReport/ProjectReportService.php b/src/backend/de/RaumZeitLabor/PartKeepr/ProjectReport/ProjectReportService.php @@ -12,34 +12,68 @@ use de\RaumZeitLabor\PartKeepr\Project\ProjectManager, class ProjectReportService extends Service implements RestfulService { /** - * (non-PHPdoc) + * Returns a project report. + * + * The input format is an array with the following keys per entry: + * - project: The project ID + * - amount: Specifies how many copies of the project need to be reported + * + * The output format is an array which contains the following keys: + * - quantity: The overall quantity of parts needed (for a specific part) + * - part: The serialized part entity + * - storageLocation_name: The storage location name + * - available: The overall amount of available parts + * - sum_order: Always set to 0 because calculation happens in the frontend + * * @see de\RaumZeitLabor\PartKeepr\Service.RestfulService::get() */ public function get () { - $reportIds = explode(",",$this->getParameter("reports")); + $reports = json_decode($this->getParameter("reports"), true); - $dql = "SELECT SUM(pp.quantity) AS quantity, p.id AS part_id, st.name AS storageLocation_name, p.stockLevel "; - $dql .= "AS stockLevel FROM de\RaumZeitLabor\PartKeepr\Project\ProjectPart pp JOIN pp.part p JOIN "; - $dql .= "p.storageLocation st JOIN pp.project pr WHERE pr.id IN (:projects) GROUP BY pp.part"; + $aPartResults = array(); - $query = PartKeepr::getEM()->createQuery($dql); - $query->setParameter("projects", $reportIds); - - $aFinalResult = array(); - foreach ($query->getResult() as $record) { - $missing = $record["quantity"] - $record["stockLevel"]; - - if ($missing < 0) { $missing = 0; } + // Loop over all reports and calculate the overall quantities + foreach ($reports as $report) { + $dql = "SELECT pp.quantity, p.id FROM "; + $dql .= "de\RaumZeitLabor\PartKeepr\Project\ProjectPart pp JOIN pp.part p WHERE pp.project = :project"; - $aFinalResult[] = array( - "quantity" => $record["quantity"], - "available" => $record["stockLevel"], - "missing" => $missing, - "part" => array("response" => array("totalCount" => 1, "data" => Part::loadById($record["part_id"])->serialize())), - "storageLocation_name" => $record["storageLocation_name"], - "sum_order" => 0 + $query = PartKeepr::getEM()->createQuery($dql); + $query->setParameter("project", $report["project"]); + + foreach ($query->getArrayResult() as $result) { + $part = Part::loadById($result["id"]); + + if (array_key_exists($result["id"], $aPartResults)) { + // Only update the quantity of the part + $aPartResults[$result["id"]]["quantity"] += $result["quantity"] * $report["amount"]; + } else { + // Create a full resultset + $aPartResults[$result["id"]] = array( + "quantity" => $result["quantity"] * $report["amount"], + "part" => array("response" => array("totalCount" => 1, "data" => $part->serialize())), + "storageLocation_name" => $part->getStorageLocation()->getName(), + "available" => $part->getStockLevel(), + "sum_order" => 0 ); + } + } } + + $aFinalResult = array(); + + // Iterate over all results and calculate how many parts are missing + foreach ($aPartResults as $key => $partResult) { + $missing = $partResult["quantity"] - $partResult["available"]; + + if ($missing < 0) { + $missing = 0; + } + + $partResult["missing"] = $missing; + + $aFinalResult[] = $partResult; + } + return array("data" => $aFinalResult); } diff --git a/src/frontend/js/Components/Project/ProjectReport.js b/src/frontend/js/Components/Project/ProjectReport.js @@ -16,19 +16,32 @@ Ext.define('PartKeepr.ProjectReportView', { this.createStores(); + this.upperGridEditing = Ext.create('Ext.grid.plugin.CellEditing', { + clicksToEdit: 1 + }); + this.reportList = Ext.create("Ext.grid.Panel", { title: i18n("Choose Projects to create a report for"), selModel: { - mode: 'MULTI' }, selType: 'checkboxmodel', flex: 1, columns: [{ + header: i18n("Amount"), dataIndex: 'amount', + width: 50, + editor: { + xtype: 'numberfield' + } + },{ header: i18n("Project Name"), dataIndex: 'name', flex: 1 + },{ + header: i18n("Description"), dataIndex: 'description', + flex: 1 }], - store: this.store + store: this.store, + plugins: [ this.upperGridEditing ] }); this.editing = Ext.create('Ext.grid.plugin.CellEditing', { @@ -205,16 +218,19 @@ Ext.define('PartKeepr.ProjectReportView', { var params = new Array(); for (var i=0;i<selection.length;i++) { - params.push(selection[i].get("id")); + params.push({ project: selection[i].get("id"), amount: selection[i].get("amount")}); } - this.projectReportStore.getProxy().extraParams.reports = params.join(","); + this.projectReportStore.getProxy().extraParams.reports = Ext.encode(params); this.projectReportStore.load(); }, + /** + * Creates the store used in this view. + */ createStores: function () { var config = { autoLoad: true, - model: "PartKeepr.Project", + model: "PartKeepr.ProjectReportList", pageSize: -1 };