commit 6ee4eb2c5e428c7480d93756788d814b5e08cc61
parent f832324b8254bdc386adc491b35da1f5b48f7cba
Author: Felicitus <felicitus@felicitus.org>
Date: Thu, 5 Apr 2012 06:58:17 +0200
Project reports can now trigger stock removal for all parts in the result view
Diffstat:
2 files changed, 78 insertions(+), 2 deletions(-)
diff --git a/src/backend/de/RaumZeitLabor/PartKeepr/Part/PartService.php b/src/backend/de/RaumZeitLabor/PartKeepr/Part/PartService.php
@@ -222,6 +222,32 @@ class PartService extends Service implements RestfulService {
return array("data" => $part->serialize());
}
+ public function massDeleteStock () {
+ $data = $this->getParameter("removals");
+
+ $updateStockLevels = array();
+
+ foreach ($data as $item) {
+ $part = PartManager::getInstance()->getPart($item["part"]);
+ $user = SessionManager::getCurrentSession()->getUser();
+
+ $stock = new StockEntry($part, 0-intval($item["amount"]), $user);
+ $stock->setComment($item["comment"]);
+ PartKeepr::getEM()->persist($stock);
+
+ $updateStockLevels[$item["part"]] = $part;
+ }
+
+ PartKeepr::getEM()->flush();
+
+ foreach ($updateStockLevels as $part) {
+ $part->updateStockLevel();
+ }
+
+ PartKeepr::getEM()->flush();
+ return array();
+ }
+
public function deletePart () {
PartManager::getInstance()->deletePart($this->getParameter("part"));
}
diff --git a/src/frontend/js/Components/Project/ProjectReport.js b/src/frontend/js/Components/Project/ProjectReport.js
@@ -134,15 +134,27 @@ Ext.define('PartKeepr.ProjectReportView', {
});
this.autoFillButton = Ext.create('Ext.button.Button', {
- xtype: 'button',
text: i18n("Autofill"),
width: 120,
+ margins: {
+ right: 20
+ },
listeners: {
click: this.onAutoFillClick,
scope: this
}
});
+ this.removeStockButton = Ext.create('Ext.button.Button', {
+ text: i18n("Remove parts from stock"),
+ width: 160,
+ listeners: {
+ click: this.onStockRemovalClick,
+ scope: this
+ }
+
+ });
+
this.items = [
{
title: i18n("Choose Projects to create a report for"),
@@ -168,7 +180,7 @@ Ext.define('PartKeepr.ProjectReportView', {
},
border: false,
bodyStyle: 'background:#DBDBDB',
- items: [ this.createReportButton , this.autoFillButton ]
+ items: [ this.createReportButton , this.autoFillButton, { xtype: 'tbspacer'}, this.removeStockButton ]
}
]
},{
@@ -184,6 +196,12 @@ Ext.define('PartKeepr.ProjectReportView', {
this.callParent();
},
+ /**
+ * Called when the distributor field is about to be edited.
+ *
+ * Filters the distributor list and show only distributors which are assigned to the particular item.
+ * @param e
+ */
onBeforeEdit: function (e) {
if (e.field !== "distributor_id") { return; }
@@ -204,6 +222,38 @@ Ext.define('PartKeepr.ProjectReportView', {
return false;
}});
},
+ /**
+ * Removes all parts in the project view.
+ */
+ onStockRemovalClick: function () {
+ Ext.Msg.confirm(i18n("Remove parts from stock"),
+ i18n("Do you really want to remove the parts in the project report from the stock?"),
+ this.removeStocks, this);
+ },
+ removeStocks: function (btn) {
+ if (btn == "yes") {
+
+ var store = this.reportResult.getStore();
+ var removals = [];
+
+ for (var i=0;i<store.count();i++) {
+ var item = store.getAt(i);
+
+ removals.push({
+ part: item.part().getAt(0).get("id"),
+ amount: item.get("quantity"),
+ comment: item.get("projects")
+ });
+ }
+
+ var call = new PartKeepr.ServiceCall(
+ "Part",
+ "massDeleteStock");
+
+ call.setParameter("removals", removals);
+ call.doCall();
+ }
+ },
onEdit: function (editor, e) {
if (e.field == "distributor_id") {
var distributors = e.record.part().getAt(0).distributors();