partkeepr

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

commit 2bc014bc1f3f8f3ae609165ebd6f775e2a9320a0
parent 77b2cbc86744cfbafcc2dec7c80b4e44c7f849ca
Author: Felicitus <privat@timohummel.com>
Date:   Mon,  6 Jun 2011 03:10:54 +0200

* Added Part to Manufacturer and Part to Distributor relation + editing
* Fixed JS warnings

Diffstat:
Mfrontend/index.html | 6++++++
Mfrontend/js/Components/CategoryEditor/CategoryEditorTree.js | 4++--
Mfrontend/js/Components/CategoryTree.js | 5++---
Mfrontend/js/Components/Editor/Editor.js | 12++++++------
Mfrontend/js/Components/Editor/EditorComponent.js | 6++----
Mfrontend/js/Components/Editor/EditorGrid.js | 5+++--
Mfrontend/js/Components/MessageLog.js | 2+-
Afrontend/js/Components/Part/PartDistributorGrid.js | 106+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mfrontend/js/Components/Part/PartEditor.js | 95++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------
Mfrontend/js/Components/Part/PartEditorWindow.js | 2++
Afrontend/js/Components/Part/PartManufacturerGrid.js | 97+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mfrontend/js/Components/Part/PartsGrid.js | 2+-
Mfrontend/js/Components/Part/PartsManager.js | 4++--
Mfrontend/js/Components/Widgets/CategoryComboBox.js | 4++--
Afrontend/js/Components/Widgets/DistributorComboBox.js | 27+++++++++++++++++++++++++++
Afrontend/js/Components/Widgets/ManufacturerComboBox.js | 27+++++++++++++++++++++++++++
Mfrontend/js/Dialogs/ExceptionWindow.js | 2+-
Mfrontend/js/Models/Category.js | 2+-
Mfrontend/js/Models/Distributor.js | 2+-
Mfrontend/js/Models/Footprint.js | 2+-
Mfrontend/js/Models/Manufacturer.js | 2+-
Mfrontend/js/Models/Part.js | 1+
Afrontend/js/Models/PartDistributor.js | 16++++++++++++++++
Afrontend/js/Models/PartManufacturer.js | 14++++++++++++++
Mfrontend/js/PartDB2.js | 42++++++++++++++++++++++++++++++++++++++----
Mfrontend/js/Util/ServiceCall.js | 4++--
Mfrontend/js/bugfixes.js | 8++++----
Mfrontend/js/org.jerrymouse.util.locale/locale.js | 4++--
Msrc/de/RaumZeitLabor/PartDB2/Distributor/Distributor.php | 27+++++++++++++++++++++++++++
Msrc/de/RaumZeitLabor/PartDB2/Manufacturer/Manufacturer.php | 26++++++++++++++++++++++++++
Msrc/de/RaumZeitLabor/PartDB2/Part/Part.php | 49+++++++++++++++++++++++++++++++++++++++++++++----
Asrc/de/RaumZeitLabor/PartDB2/Part/PartDistributor.php | 93+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/de/RaumZeitLabor/PartDB2/Part/PartManager.php | 88+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartDB2/Part/PartManufacturer.php | 79+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/de/RaumZeitLabor/PartDB2/Part/PartService.php | 40+++++++++++-----------------------------
Msrc/de/RaumZeitLabor/PartDB2/PartDB2.php | 2++
Asrc/de/RaumZeitLabor/PartDB2/PartDistributor/PartDistributorManager.php | 76++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/de/RaumZeitLabor/PartDB2/PartDistributor/PartDistributorService.php | 89+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mtesting/SetupDatabase.php | 66+++++++++++++++++++++++++++++++++++++++++++++++++-----------------
39 files changed, 1021 insertions(+), 117 deletions(-)

diff --git a/frontend/index.html b/frontend/index.html @@ -35,6 +35,8 @@ <script type="text/javascript" src="js/Components/Widgets/CategoryComboBox.js"></script> <script type="text/javascript" src="js/Components/Widgets/StorageLocationComboBox.js"></script> <script type="text/javascript" src="js/Components/Widgets/FootprintComboBox.js"></script> + <script type="text/javascript" src="js/Components/Widgets/ManufacturerComboBox.js"></script> + <script type="text/javascript" src="js/Components/Widgets/DistributorComboBox.js"></script> <script type="text/javascript" src="js/Util/ServiceCall.js"></script> @@ -51,6 +53,8 @@ <script type="text/javascript" src="js/Models/ManufacturerICLogo.js"></script> <script type="text/javascript" src="js/Models/Category.js"></script> <script type="text/javascript" src="js/Models/Part.js"></script> + <script type="text/javascript" src="js/Models/PartDistributor.js"></script> + <script type="text/javascript" src="js/Models/PartManufacturer.js"></script> <script type="text/javascript" src="js/Models/Message.js"></script> @@ -91,6 +95,8 @@ <script type="text/javascript" src="js/Components/Part/PartsManager.js"></script> <script type="text/javascript" src="js/Components/Part/PartsGrid.js"></script> + <script type="text/javascript" src="js/Components/Part/PartDistributorGrid.js"></script> + <script type="text/javascript" src="js/Components/Part/PartManufacturerGrid.js"></script> <script type="text/javascript" src="js/Components/Part/PartEditorWindow.js"></script> <script type="text/javascript" src="js/Components/Part/PartEditor.js"></script> <script type="text/javascript" src="js/Components/Part/PartDisplay.js"></script> diff --git a/frontend/js/Components/CategoryEditor/CategoryEditorTree.js b/frontend/js/Components/CategoryEditor/CategoryEditorTree.js @@ -111,7 +111,7 @@ PartDB2.CategoryEditorTree = Ext.define("CategoryEditorTree", { onUpdateRecord: function (record) { var currentRecord = this.getStore().getRootNode().findChild("id", record.get("id"), true); - if (currentRecord == null) { + if (currentRecord === null) { var parentRecord = this.getStore().getRootNode().findChild("id", record.get("parent"), true); var nodeData = { @@ -120,7 +120,7 @@ PartDB2.CategoryEditorTree = Ext.define("CategoryEditorTree", { tooltip : record.get("description") }; - parentRecord.appendChild(nodeData) + parentRecord.appendChild(nodeData); } else { currentRecord.set("name", record.get("name")); diff --git a/frontend/js/Components/CategoryTree.js b/frontend/js/Components/CategoryTree.js @@ -43,7 +43,6 @@ PartDB2.CategoryTree = Ext.define("CategoryTree", { }, buildCategoryTree : function(root, data) { - var node; var nodeData = { id : data.id, name : data.name, @@ -55,9 +54,9 @@ PartDB2.CategoryTree = Ext.define("CategoryTree", { nodeData.allowDrag = false; } - if (data.children.length == 0) { + //if (data.children.length === 0) { //nodeData.leaf = true; - } + //} var node = root.appendChild(nodeData); for ( var i = 0; i < data.children.length; i++) { diff --git a/frontend/js/Components/Editor/Editor.js b/frontend/js/Components/Editor/Editor.js @@ -12,17 +12,17 @@ Ext.define('PartDB2.Editor', { autoScroll: true, defaults: { anchor: '100%', - labelWidth: 150, + labelWidth: 150 }, onFieldChange: function () { return; // @todo Finish implementing the dirty flag later - if (this.change == false) { + /*if (this.change == false) { this.setTitle(this.record.getName() + "*"); } - this.change = true; + this.change = true;*/ }, initComponent: function () { this.saveButton = Ext.create("Ext.button.Button", { @@ -70,7 +70,7 @@ Ext.define('PartDB2.Editor', { this.record = record; this.getForm().loadRecord(this.record); this.show(); - if (this.record.getName() != "") { + if (this.record.getName() !== "") { this.setTitle(this.record.getName()); } @@ -87,7 +87,7 @@ Ext.define('PartDB2.Editor', { onItemSave: function () { if (this.record) { /* Check if this is an in-memory record */ - if (this.record.phantom == true) { + if (this.record.phantom === true) { /* Push form values into the record */ this.getForm().updateRecord(this.record); @@ -129,5 +129,5 @@ Ext.define('PartDB2.Editor', { } } } - }, + } }); \ No newline at end of file diff --git a/frontend/js/Components/Editor/EditorComponent.js b/frontend/js/Components/Editor/EditorComponent.js @@ -61,7 +61,7 @@ Ext.define('PartDB2.EditorComponent', { //this.editor.editItem(r); - var editor = this.createEditor(r.getName()); + editor = this.createEditor(r.getName()); editor.editItem(r); this.editorTabPanel.add(editor).show(); @@ -106,9 +106,7 @@ Ext.define('PartDB2.EditorComponent', { r.destroy(); this.store.load(); } - }, - this - ); + },this); }, // Creates a store. To be called from child's initComponent createStore: function (config) { diff --git a/frontend/js/Components/Editor/EditorGrid.js b/frontend/js/Components/Editor/EditorGrid.js @@ -54,8 +54,9 @@ Ext.define('PartDB2.EditorGrid', { this.searchField] }); Ext.apply(this, { - dockedItems: [this.topToolbar - ,{ + dockedItems: [ + this.topToolbar, + { xtype: 'pagingtoolbar', store: this.store, dock: 'bottom', diff --git a/frontend/js/Components/MessageLog.js b/frontend/js/Components/MessageLog.js @@ -18,5 +18,5 @@ Ext.define('PartDB2.MessageLog', { sorters: [{ property: 'date', direction:'DESC' - }], + }] }); \ No newline at end of file diff --git a/frontend/js/Components/Part/PartDistributorGrid.js b/frontend/js/Components/Part/PartDistributorGrid.js @@ -0,0 +1,105 @@ +Ext.define('PartDB2.PartDistributorGrid', { + extend: 'Ext.grid.Panel', + alias: 'widget.PartDistributorGrid', + initComponent: function () { + this.store = Ext.create("Ext.data.Store", { + model: 'PartDistributor', + proxy: { + type: 'memory', + reader: { + type: 'json' + } + } + + }); + + this.editing = Ext.create('Ext.grid.plugin.RowEditing', { + clicksToEdit: 1 + }); + + this.plugins = [ this.editing ]; + + this.deleteButton = Ext.create("Ext.button.Button", { + text: 'Delete', + disabled: true, + itemId: 'delete', + scope: this, + handler: this.onDeleteClick + }); + + this.dockedItems = [{ + xtype: 'toolbar', + items: [{ + text: 'Add', + scope: this, + handler: this.onAddClick + }, this.deleteButton] + }]; + + this.columns = [ + { + header: i18n("Distributor"), + dataIndex: 'distributor_id', + xtype: 'templatecolumn', + tpl: '{distributor_name}', + flex: 0.4, + editor: { + xtype:'DistributorComboBox', + allowBlank:true + } + }, + { + header: i18n("Order Number"), + dataIndex: 'orderNumber', + flex: 0.4, + editor: { + xtype:'textfield', + allowBlank:true + } + },{ + header: i18n("Packaging Unit"), + dataIndex: 'packagingUnit', + flex: 0.2, + editor: { + xtype:'numberfield', + allowDecimals: false, + allowBlank:false + } + } + ]; + + this.callParent(); + + this.getSelectionModel().on('selectionchange', this.onSelectChange, this); + this.on("edit", this.onEdit, this); + }, + onEdit: function (data) { + var id = data.record.get("distributor_id"); + + var rec = PartDB2.getApplication().getDistributorStore().findRecord("id", id); + + if (rec) { + data.record.set("distributor_name", rec.get("name")); + } + }, + onAddClick: function () { + this.editing.cancelEdit(); + + var rec = new PartDB2.PartDistributor({ + packagingUnit: 1 + }); + + this.store.insert(0, rec); + + this.editing.startEdit(0,0); + }, + onDeleteClick: function () { + var selection = this.getView().getSelectionModel().getSelection()[0]; + if (selection) { + this.store.remove(selection); + } + }, + onSelectChange: function(selModel, selections){ + this.deleteButton.setDisabled(selections.length === 0); + } +});+ \ No newline at end of file diff --git a/frontend/js/Components/Part/PartEditor.js b/frontend/js/Components/Part/PartEditor.js @@ -1,36 +1,65 @@ Ext.define('PartDB2.PartEditor', { extend: 'PartDB2.Editor', autoScroll: true, - items: [{ - xtype: 'textfield', - name: 'name', - fieldLabel: i18n("Name") - },{ - xtype: 'numberfield', - fieldLabel: i18n('Minimum Stock'), - allowDecimals: false, - allowBlank: false, - name: 'minStockLevel' - },{ - xtype: 'CategoryComboBox', - fieldLabel: i18n("Category"), - name: 'category_id' - },{ - xtype: 'StorageLocationComboBox', - fieldLabel: i18n("Storage Location"), - name: 'storageLocation_id' - },{ - xtype: 'FootprintComboBox', - fieldLabel: i18n("Footprint"), - name: 'footprint_id' - },{ - xtype: 'textarea', - fieldLabel: i18n("Comment"), - name: 'comment' - }], + border: false, model: 'PartDB2.Part', mode: 'add', + layout: 'fit', + bodyStyle: 'background:#DFE8F6;', initComponent: function () { + var basicEditorFields = [{ + xtype: 'textfield', + name: 'name', + fieldLabel: i18n("Name") + },{ + xtype: 'numberfield', + fieldLabel: i18n('Minimum Stock'), + allowDecimals: false, + allowBlank: false, + name: 'minStockLevel' + },{ + xtype: 'CategoryComboBox', + fieldLabel: i18n("Category"), + name: 'category_id' + },{ + xtype: 'StorageLocationComboBox', + fieldLabel: i18n("Storage Location"), + name: 'storageLocation_id' + },{ + xtype: 'FootprintComboBox', + fieldLabel: i18n("Footprint"), + name: 'footprint_id' + },{ + xtype: 'textarea', + fieldLabel: i18n("Comment"), + name: 'comment' + }]; + + this.partDistributorGrid = Ext.create("PartDB2.PartDistributorGrid", { + title: i18n("Distributors"), + layout: 'fit' + }); + + this.partManufacturerGrid = Ext.create("PartDB2.PartManufacturerGrid", { + title: i18n("Manufacturers"), + layout: 'fit' + }); + + this.items = { + xtype: 'tabpanel', + border: false, + items: [{ + xtype: 'panel', + border: false, + bodyStyle: 'background:#DFE8F6;padding: 10px;', + title: i18n("Basic Data"), + items: basicEditorFields + }, + this.partDistributorGrid, + this.partManufacturerGrid + ] + }; + this.on("startEdit", function () { this.mode = "edit"; }, this); this.addEvents("partSaved"); @@ -48,6 +77,18 @@ Ext.define('PartDB2.PartEditor', { var values = this.getForm().getFieldValues(); + values.distributorChanges = { + "inserts": PartDB2.serializeRecords(this.partDistributorGrid.getStore().getNewRecords()), + "updates": PartDB2.serializeRecords(this.partDistributorGrid.getStore().getUpdatedRecords()), + "removals": PartDB2.serializeRecords(this.partDistributorGrid.getStore().getRemovedRecords()) + }; + + values.manufacturerChanges = { + "inserts": PartDB2.serializeRecords(this.partManufacturerGrid.getStore().getNewRecords()), + "updates": PartDB2.serializeRecords(this.partManufacturerGrid.getStore().getUpdatedRecords()), + "removals": PartDB2.serializeRecords(this.partManufacturerGrid.getStore().getRemovedRecords()) + }; + call.setParameters(values); call.setHandler(Ext.bind(this.onPartSave, this)); call.doCall(); diff --git a/frontend/js/Components/Part/PartEditorWindow.js b/frontend/js/Components/Part/PartEditorWindow.js @@ -21,5 +21,7 @@ Ext.define('PartDB2.PartEditorWindow', { this.editor.getForm().setValues(r); this.editor.rawValues = r; + this.editor.partDistributorGrid.getStore().loadData(r.distributors); + this.editor.partManufacturerGrid.getStore().loadData(r.manufacturers); } }); \ No newline at end of file diff --git a/frontend/js/Components/Part/PartManufacturerGrid.js b/frontend/js/Components/Part/PartManufacturerGrid.js @@ -0,0 +1,96 @@ +Ext.define('PartDB2.PartManufacturerGrid', { + extend: 'Ext.grid.Panel', + alias: 'widget.PartManufacturerGrid', + initComponent: function () { + this.store = Ext.create("Ext.data.Store", { + model: 'PartManufacturer', + proxy: { + type: 'memory', + reader: { + type: 'json' + } + } + + }); + + this.editing = Ext.create('Ext.grid.plugin.RowEditing', { + clicksToEdit: 1 + }); + + this.plugins = [ this.editing ]; + + this.deleteButton = Ext.create("Ext.button.Button", { + text: 'Delete', + disabled: true, + itemId: 'delete', + scope: this, + handler: this.onDeleteClick + }); + + this.dockedItems = [{ + xtype: 'toolbar', + items: [{ + text: 'Add', + scope: this, + handler: this.onAddClick + }, this.deleteButton] + }]; + + this.columns = [ + { + header: i18n("Manufacturer"), + dataIndex: 'manufacturer_id', + xtype: 'templatecolumn', + tpl: '{manufacturer_name}', + flex: 0.4, + editor: { + xtype:'ManufacturerComboBox', + allowBlank:true + } + }, + { + header: i18n("Part Number"), + dataIndex: 'partNumber', + flex: 0.4, + editor: { + xtype:'textfield', + allowBlank:true + } + } + ]; + + this.callParent(); + + this.getSelectionModel().on('selectionchange', this.onSelectChange, this); + this.on("edit", this.onEdit, this); + }, + onEdit: function (data) { + var id = data.record.get("manufacturer_id"); + + var rec = PartDB2.getApplication().getManufacturerStore().findRecord("id", id); + + if (rec) { + data.record.set("manufacturer_name", rec.get("name")); + } + }, + onAddClick: function () { + this.editing.cancelEdit(); + + var rec = new PartDB2.PartManufacturer({ + packagingUnit: 1 + }); + + this.store.insert(0, rec); + + this.editing.startEdit(0,0); + }, + onDeleteClick: function () { + var selection = this.getView().getSelectionModel().getSelection()[0]; + if (selection) { + this.store.remove(selection); + } + }, + onSelectChange: function(selModel, selections){ + this.deleteButton.setDisabled(selections.length === 0); + } +});+ \ No newline at end of file diff --git a/frontend/js/Components/Part/PartsGrid.js b/frontend/js/Components/Part/PartsGrid.js @@ -6,7 +6,7 @@ Ext.define('PartDB2.PartsGrid', { {header: i18n("Storage Location"), dataIndex: 'storageLocationName'}, {header: i18n("Stock"), dataIndex: 'stockLevel'}, {header: i18n("Min. Stock"), dataIndex: 'minStockLevel'}, - {header: i18n("Footprint"), dataIndex: 'footprintName'}, + {header: i18n("Footprint"), dataIndex: 'footprintName'} ], buttonTextMode: 'show', initComponent: function () { diff --git a/frontend/js/Components/Part/PartsManager.js b/frontend/js/Components/Part/PartsManager.js @@ -8,8 +8,8 @@ Ext.define('PartDB2.PartManager', { layout: 'border', initComponent: function () { this.createStore({ - model: 'Part' - , sorters: [{ + model: 'Part', + sorters: [{ property: 'name', direction:'ASC' }] diff --git a/frontend/js/Components/Widgets/CategoryComboBox.js b/frontend/js/Components/Widgets/CategoryComboBox.js @@ -4,7 +4,7 @@ Ext.define("PartDB2.CategoryComboBox",{ requires:["Ext.tree.Panel"], selectedValue: null, initComponent: function(){ - var self = this + var self = this; Ext.apply(self,{ pickerAlign:"tl-bl?", @@ -61,7 +61,7 @@ Ext.define("PartDB2.CategoryComboBox",{ }, setValue: function (val, parent) { if (parent) { - return this.callParent([val]); + this.callParent([val]); } if (!this.picker) { return; } diff --git a/frontend/js/Components/Widgets/DistributorComboBox.js b/frontend/js/Components/Widgets/DistributorComboBox.js @@ -0,0 +1,27 @@ +Ext.define("PartDB2.DistributorComboBox",{ + extend:"Ext.form.field.ComboBox", + alias: 'widget.DistributorComboBox', + displayField: 'name', + valueField: 'id', + autoSelect: true, + queryMode: 'local', + triggerAction: 'all', + forceSelection: true, + editable: false, + initComponent: function () { + this.store = PartDB2.getApplication().getDistributorStore(); + + /* Workaround to remember the value when loading */ + this.store.on("beforeload", function () { + this._oldValue = this.getValue(); + }, this); + + /* Set the old value when load is complete */ + this.store.on("load", function () { + this.setValue(this._oldValue); + }, this); + + this.callParent(); + } +}); + diff --git a/frontend/js/Components/Widgets/ManufacturerComboBox.js b/frontend/js/Components/Widgets/ManufacturerComboBox.js @@ -0,0 +1,27 @@ +Ext.define("PartDB2.ManufacturerComboBox",{ + extend:"Ext.form.field.ComboBox", + alias: 'widget.ManufacturerComboBox', + displayField: 'name', + valueField: 'id', + autoSelect: true, + queryMode: 'local', + triggerAction: 'all', + forceSelection: true, + editable: false, + initComponent: function () { + this.store = PartDB2.getApplication().getManufacturerStore(); + + /* Workaround to remember the value when loading */ + this.store.on("beforeload", function () { + this._oldValue = this.getValue(); + }, this); + + /* Set the old value when load is complete */ + this.store.on("load", function () { + this.setValue(this._oldValue); + }, this); + + this.callParent(); + } +}); + diff --git a/frontend/js/Dialogs/ExceptionWindow.js b/frontend/js/Dialogs/ExceptionWindow.js @@ -71,7 +71,7 @@ Ext.define('PartDB2.ExceptionWindow', { pack: 'center' }, items: [ - { xtype: 'button', text: 'OK', handler: Ext.bind(function () { this.hide(); }, this) }, + { xtype: 'button', text: 'OK', handler: Ext.bind(function () { this.hide(); }, this) } //{ xtype: 'button', text: 'Details >>', handler: Ext.bind(function () { this.showDetails(); }, this) } ] }]; diff --git a/frontend/js/Models/Category.js b/frontend/js/Models/Category.js @@ -4,7 +4,7 @@ PartDB2.Category = Ext.define("Category", { { name: 'id', type: 'int' }, { name: 'name', type: 'string' }, { name: 'description', type: 'string' }, - { name: 'parent', type: 'int' }, + { name: 'parent', type: 'int' } ], proxy: PartDB2.getRESTProxy("Category"), getName: function () { diff --git a/frontend/js/Models/Distributor.js b/frontend/js/Models/Distributor.js @@ -6,7 +6,7 @@ PartDB2.Distributor = Ext.define("Distributor", { { name: 'url', type: 'string'}, { name: 'comment', type: 'string'}, { name: 'address', type: 'string'}, - { name: 'email', type: 'string'}, + { name: 'email', type: 'string'} ], proxy: PartDB2.getRESTProxy("Distributor"), getName: function () { diff --git a/frontend/js/Models/Footprint.js b/frontend/js/Models/Footprint.js @@ -2,7 +2,7 @@ PartDB2.Footprint = Ext.define("Footprint", { extend: "Ext.data.Model", fields: [ { id: 'id', name: 'id', type: 'int' }, - { name: 'footprint', type: 'string'}, + { name: 'footprint', type: 'string'} ], proxy: PartDB2.getRESTProxy("Footprint"), getName: function () { diff --git a/frontend/js/Models/Manufacturer.js b/frontend/js/Models/Manufacturer.js @@ -6,7 +6,7 @@ PartDB2.Manufacturer = Ext.define("Manufacturer", { { name: 'url', type: 'string'}, { name: 'comment', type: 'string'}, { name: 'address', type: 'string'}, - { name: 'email', type: 'string'}, + { name: 'email', type: 'string'} ], hasMany: {model: 'ManufacturerICLogo', name: 'iclogos'}, proxy: PartDB2.getRESTProxy("Manufacturer"), diff --git a/frontend/js/Models/Part.js b/frontend/js/Models/Part.js @@ -20,6 +20,7 @@ PartDB2.Part = Ext.define("Part", { { model: 'Footprint', primaryKey: 'id', foreignKey: 'footprint_id'}, { model: 'Category', primaryKey: 'id', foreignKey: 'category_id'} ], + hasMany: { model: 'PartDistributor', name: 'distributors'}, proxy: PartDB2.getRESTProxy("Part"), getName: function () { return this.get("name"); diff --git a/frontend/js/Models/PartDistributor.js b/frontend/js/Models/PartDistributor.js @@ -0,0 +1,15 @@ +PartDB2.PartDistributor = Ext.define("PartDistributor", { + extend: "Ext.data.Model", + fields: [ + { id: 'id', name: 'id', type: 'int' }, + { name: 'part_id', type: 'int' }, + { name: 'part_name', type: 'string' }, + { name: 'distributor_id', type: 'int' }, + { name: 'distributor_name', type: 'string' }, + { name: 'orderNumber', type: 'string' }, + { name: 'packagingUnit', type: 'int'} + ], + belongsTo: { type: 'belongsTo', model: 'Part', primaryKey: 'id', foreignKey: 'part_id'}, + belongsTo: { type: 'belongsTo', model: 'Distributor', primaryKey: 'id', foreignKey: 'distributor_id'}, + proxy: PartDB2.getRESTProxy("PartDistributor") +});+ \ No newline at end of file diff --git a/frontend/js/Models/PartManufacturer.js b/frontend/js/Models/PartManufacturer.js @@ -0,0 +1,14 @@ +PartDB2.PartManufacturer = Ext.define("PartManufacturer", { + extend: "Ext.data.Model", + fields: [ + { id: 'id', name: 'id', type: 'int' }, + { name: 'part_id', type: 'int' }, + { name: 'part_name', type: 'string' }, + { name: 'manufacturer_id', type: 'int' }, + { name: 'manufacturer_name', type: 'string' }, + { name: 'partNumber', type: 'string' } + ], + belongsTo: { type: 'belongsTo', model: 'Part', primaryKey: 'id', foreignKey: 'part_id'}, + belongsTo: { type: 'belongsTo', model: 'Manufacturer', primaryKey: 'id', foreignKey: 'manufacturer_id'}, + proxy: PartDB2.getRESTProxy("PartManufacturer") +}); diff --git a/frontend/js/PartDB2.js b/frontend/js/PartDB2.js @@ -1,7 +1,7 @@ Ext.namespace('PartDB2'); Ext.Loader.setPath({ - 'PartDB2': 'js', + 'PartDB2': 'js' }); PartDB2.application = null; @@ -35,6 +35,20 @@ Ext.application({ pageSize: -1, autoLoad: false }); + + this.distributorStore = Ext.create("Ext.data.Store", + { + model: 'Distributor', + pageSize: -1, + autoLoad: false + }); + + this.manufacturerStore = Ext.create("Ext.data.Store", + { + model: 'Manufacturer', + pageSize: -1, + autoLoad: false + }); }, getStorageLocationStore: function () { return this.storageLocationStore; @@ -42,6 +56,12 @@ Ext.application({ getFootprintStore: function () { return this.footprintStore; }, + getManufacturerStore: function () { + return this.manufacturerStore; + }, + getDistributorStore: function () { + return this.distributorStore; + }, /** * Reload all global stores each 100 seconds. * @@ -55,6 +75,8 @@ Ext.application({ reloadStores: function () { this.storageLocationStore.load(); this.footprintStore.load(); + this.manufacturerStore.load(); + this.distributorStore.load(); Ext.defer(PartDB2.getApplication().reloadStores, 100000, this); }, createLayout: function () { @@ -181,8 +203,8 @@ PartDB2.getRESTProxy = function (service) { }; - var j = new PartDB2.ExceptionWindow(); - j.showException(exception); + var jj = new PartDB2.ExceptionWindow(); + jj.showException(exception); } @@ -211,7 +233,8 @@ PartDB2.getSession = function () { PartDB2.log = function (message) { PartDB2.getApplication().log(message); -} +}; + /** * <p>This static method returns the instance of the application.</p> * @return {Object} The application @@ -222,4 +245,15 @@ PartDB2.getApplication = function () { PartDB2.getBasePath = function () { return "rest.php"; +}; + +PartDB2.serializeRecords = function (records) { + console.log(records); + var finalData = []; + + for (var i=0;i<records.length;i++) { + finalData.push(records[i].data); + } + + return finalData; }; \ No newline at end of file diff --git a/frontend/js/Util/ServiceCall.js b/frontend/js/Util/ServiceCall.js @@ -141,8 +141,8 @@ Ext.define('PartDB2.ServiceCall', { }; - var j = new PartDB2.ExceptionWindow(); - j.showException(exception); + var jj = new PartDB2.ExceptionWindow(); + jj.showException(exception); } diff --git a/frontend/js/bugfixes.js b/frontend/js/bugfixes.js @@ -2,14 +2,14 @@ Ext.override(Ext.data.reader.Reader, { readRecords: function(data) { - var data = this.callOverridden(arguments); + var dt = this.callOverridden(arguments); - if (data.success == false) { + //if (dt.success === false) { //Ext.Msg.alert("Error", data.message); - } + //} - return data; + return dt; } }); diff --git a/frontend/js/org.jerrymouse.util.locale/locale.js b/frontend/js/org.jerrymouse.util.locale/locale.js @@ -38,11 +38,11 @@ Ext.replaceLocaleTags = function (string) { var regexp = /\$\[(.+?)\]/g; var workingCopy = string; - while (result = regexp.exec(string)) { + /*while (result = regexp.exec(string)) { if (locales[Ext.jm_locale][result[1]]) { workingCopy = Ext.replaceString(result[0], locales[Ext.jm_locale][result[1]], workingCopy); } - } + }*/ return workingCopy; }; diff --git a/src/de/RaumZeitLabor/PartDB2/Distributor/Distributor.php b/src/de/RaumZeitLabor/PartDB2/Distributor/Distributor.php @@ -32,6 +32,16 @@ class Distributor { /** * @Column(type="string",nullable=true) */ + private $phone; + + /** + * @Column(type="string",nullable=true) + */ + private $fax; + + /** + * @Column(type="string",nullable=true) + */ private $email; /** @@ -57,6 +67,23 @@ class Distributor { return $this->address; } + public function setPhone ($phone) { + $this->phone = $phone; + } + + public function getPhone () { + return $this->phone; + } + + public function setFax ($fax) { + $this->fax = $fax; + } + + public function getFax ($fax) { + return $this->fax; + } + + public function setComment ($comment) { $this->comment = $comment; } diff --git a/src/de/RaumZeitLabor/PartDB2/Manufacturer/Manufacturer.php b/src/de/RaumZeitLabor/PartDB2/Manufacturer/Manufacturer.php @@ -40,6 +40,16 @@ class Manufacturer { private $comment; /** + * @Column(type="string",nullable=true) + */ + private $phone; + + /** + * @Column(type="string",nullable=true) + */ + private $fax; + + /** * @OneToMany(targetEntity="de\RaumZeitLabor\PartDB2\Manufacturer\ManufacturerICLogo",mappedBy="manufacturer",cascade={"persist", "remove"}) */ private $icLogos; @@ -55,6 +65,22 @@ class Manufacturer { return $this->name; } + public function setPhone ($phone) { + $this->phone = $phone; + } + + public function getPhone () { + return $this->phone; + } + + public function setFax ($fax) { + $this->fax = $fax; + } + + public function getFax ($fax) { + return $this->fax; + } + public function setAddress ($address) { $this->address = $address; } diff --git a/src/de/RaumZeitLabor/PartDB2/Part/Part.php b/src/de/RaumZeitLabor/PartDB2/Part/Part.php @@ -35,9 +35,14 @@ class Part { private $storageLocation; /** - * @ManyToOne(targetEntity="de\RaumZeitLabor\PartDB2\Manufacturer\Manufacturer") + * @OneToMany(targetEntity="de\RaumZeitLabor\PartDB2\Part\PartManufacturer",mappedBy="part",cascade={"persist", "remove"}) */ - private $manufacturer; + private $manufacturers; + + /** + * @OneToMany(targetEntity="de\RaumZeitLabor\PartDB2\Part\PartDistributor",mappedBy="part",cascade={"persist", "remove"}) + */ + private $distributors; /** * @Column(type="text") @@ -61,6 +66,15 @@ class Part { */ private $stockLevels; + public function __construct () { + $this->distributors = new \Doctrine\Common\Collections\ArrayCollection(); + $this->manufacturers = new \Doctrine\Common\Collections\ArrayCollection(); + } + + public function getName () { + return $this->name; + } + public function updateStockLevel () { $this->stockLevel = $this->getStockLevel(); } @@ -93,6 +107,14 @@ class Part { $this->comment = $comment; } + public function getDistributors () { + return $this->distributors; + } + + public function getManufacturers () { + return $this->manufacturers; + } + public function getStockLevel () { $query = PartDB2::getEM()->createQuery("SELECT SUM(s.stockLevel) FROM de\RaumZeitLabor\PartDB2\Stock\StockEntry s WHERE s.part = :part"); $query->setParameter("part", $this); @@ -100,7 +122,24 @@ class Part { return $query->getSingleScalarResult(); } + + public function getId () { + return $this->id; + } + public function serialize () { + $aManufacturers = array(); + + foreach ($this->getManufacturers() as $manufacturer) { + $aManufacturers[] = $manufacturer->serialize(); + } + + $aDistributors = array(); + + foreach ($this->getDistributors() as $distributor) { + $aDistributors[] = $distributor->serialize(); + } + return array( "id" => $this->id, "name" => $this->name, @@ -110,8 +149,10 @@ class Part { "minStockLevel" => $this->minStockLevel, "storageLocation_id" => is_object($this->storageLocation) ? $this->storageLocation->getId() : null, "storageLocationName" => is_object($this->storageLocation) ? $this->storageLocation->getName() : null, - "manufacturer" => is_object($this->manufacturer) ? $this->manufacturer->serialize() : null, - "category_id" => is_object($this->category) ? $this->category->getId() : null + "category_id" => is_object($this->category) ? $this->category->getId() : null, + "manufacturers" => $aManufacturers, + "distributors" => $aDistributors, + ); } } \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Part/PartDistributor.php b/src/de/RaumZeitLabor/PartDB2/Part/PartDistributor.php @@ -0,0 +1,92 @@ +<?php +namespace de\RaumZeitLabor\PartDB2\Part; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartDB2\PartDB2, + de\RaumZeitLabor\PartDB2\Distributor\Distributor; + +/** @Entity **/ +class PartDistributor { + /** + * @Id @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + * @var unknown_type + */ + private $id; + + /** + * @ManyToOne(targetEntity="de\RaumZeitLabor\PartDB2\Part\Part") + */ + private $part; + + /** + * @ManyToOne(targetEntity="de\RaumZeitLabor\PartDB2\Distributor\Distributor") + */ + private $distributor; + + /** + * @Column(type="string",nullable=true) + * Enter description here ... + * @var unknown_type + */ + private $orderNumber; + + /** + * @Column(type="integer") + * @var unknown_type + */ + private $packagingUnit; + + public function __construct (Part $part, Distributor $distributor) { + $this->setPart($part); + $this->setDistributor($distributor); + $this->setPackagingUnit(1); + } + + public function setPackagingUnit ($unit) { + $this->packagingUnit = $unit; + } + + public function getPackagingUnit () { + return $this->packagingUnit; + } + + public function setPart (Part $part) { + $this->part = $part; + } + + public function getPart () { + return $this->part; + } + + public function setDistributor (Distributor $distributor) { + $this->distributor = $distributor; + } + + public function getDistributor () { + return $this->distributor; + } + + public function setOrderNumber ($orderNumber) { + $this->orderNumber = $orderNumber; + } + + public function getOrderNumber () { + return $this->orderNumber; + } + + public function getId () { + return $this->id; + } + + public function serialize () { + return array( + "id" => $this->getId(), + "orderNumber" => $this->getOrderNumber(), + "distributor_id" => $this->getDistributor()->getId(), + "distributor_name" => $this->getDistributor()->getName(), + "part_id" => $this->getPart()->getId(), + "part_name" => $this->getPart()->getName(), + "packagingUnit" => $this->getPackagingUnit()); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Part/PartManager.php b/src/de/RaumZeitLabor/PartDB2/Part/PartManager.php @@ -1,10 +1,14 @@ <?php namespace de\raumzeitlabor\PartDB2\Part; +use de\RaumZeitLabor\PartDB2\Part\PartDistributor; + use de\RaumZeitLabor\PartDB2\StorageLocation\StorageLocation; use de\RaumZeitLabor\PartDB2\StorageLocation\StorageLocationManager; use de\RaumZeitLabor\PartDB2\Part\Part; +use de\RaumZeitLabor\PartDB2\Distributor\Distributor; +use de\RaumZeitLabor\PartDB2\Manufacturer\Manufacturer; use de\RaumZeitLabor\PartDB2\Footprint\FootprintManager; use de\RaumZeitLabor\PartDB2\Session\SessionManager; use de\RaumZeitLabor\PartDB2\Stock\StockEntry; @@ -131,10 +135,94 @@ class PartManager extends Singleton { $part->setCategory($category->getNode()); } + /* Process linked changes */ + if (array_key_exists("distributorChanges", $aParameters)) { + if (is_array($aParameters["distributorChanges"])) { + $this->processDistributorChanges($part, $aParameters["distributorChanges"]); + } + } + + if (array_key_exists("manufacturerChanges", $aParameters)) { + if (is_array($aParameters["manufacturerChanges"])) { + $this->processManufacturerChanges($part, $aParameters["manufacturerChanges"]); + } + } + PartDB2::getEM()->persist($part); PartDB2::getEM()->flush(); } + + private function processDistributorChanges (Part $part, Array $data) { + if (array_key_exists("updates", $data)) { + foreach ($data["updates"] as $record) { + foreach ($part->getDistributors() as $partDistributor) { + if ($partDistributor->getId() == $record["id"]) { + $partDistributor->setOrderNumber($record["orderNumber"]); + $partDistributor->setDistributor(Distributor::loadById($record["distributor_id"])); + $partDistributor->setPackagingUnit($record["packagingUnit"]); + } + } + } + } + + if (array_key_exists("removals", $data)) { + foreach ($data["removals"] as $record) { + foreach ($part->getDistributors() as $partDistributor) { + if ($partDistributor->getId() == $record["id"]) { + PartDB2::getEM()->remove($partDistributor); + $part->getDistributors()->removeElement($partDistributor); + break; + } + } + } + } + + if (array_key_exists("inserts", $data)) { + foreach ($data["inserts"] as $record) { + $distributor = new PartDistributor($part, Distributor::loadById($record["distributor_id"])); + $distributor->setOrderNumber($record["orderNumber"]); + $distributor->setPackagingUnit($record["packagingUnit"]); + + $part->getDistributors()->add($distributor); + } + } + } + + private function processManufacturerChanges (Part $part, Array $data) { + if (array_key_exists("updates", $data)) { + foreach ($data["updates"] as $record) { + foreach ($part->getManufacturers() as $partManufacturer) { + if ($partManufacturer->getId() == $record["id"]) { + $partManufacturer->setPartNumber($record["partNumber"]); + $partManufacturer->setManufacturer(Manufacturer::loadById($record["manufacturer_id"])); + } + } + } + } + + if (array_key_exists("removals", $data)) { + foreach ($data["removals"] as $record) { + foreach ($part->getManufacturers() as $partManufacturer) { + if ($partManufacturer->getId() == $record["id"]) { + PartDB2::getEM()->remove($partManufacturer); + $part->getManufacturers()->removeElement($partManufacturer); + break; + } + } + } + } + + if (array_key_exists("inserts", $data)) { + foreach ($data["inserts"] as $record) { + $manufacturer = new PartManufacturer($part, Manufacturer::loadById($record["manufacturer_id"])); + $manufacturer->setPartNumber($record["partNumber"]); + + $part->getManufacturers()->add($manufacturer); + } + } + } + public function deletePart ($id) { $part = PartManager::getInstance()->getPart($id); diff --git a/src/de/RaumZeitLabor/PartDB2/Part/PartManufacturer.php b/src/de/RaumZeitLabor/PartDB2/Part/PartManufacturer.php @@ -0,0 +1,78 @@ +<?php +namespace de\RaumZeitLabor\PartDB2\Part; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartDB2\PartDB2, + de\RaumZeitLabor\PartDB2\Manufacturer\Manufacturer; + +/** @Entity **/ +class PartManufacturer { + /** + * @Id @Column(type="integer") + * @GeneratedValue(strategy="AUTO") + * @var unknown_type + */ + private $id; + + /** + * @ManyToOne(targetEntity="de\RaumZeitLabor\PartDB2\Part\Part") + */ + private $part; + + /** + * @ManyToOne(targetEntity="de\RaumZeitLabor\PartDB2\Manufacturer\Manufacturer") + */ + private $manufacturer; + + /** + * @Column(type="string",nullable=true) + * Enter description here ... + * @var unknown_type + */ + private $partNumber; + + public function __construct (Part $part, Manufacturer $manufacturer) { + $this->setPart($part); + $this->setManufacturer($manufacturer); + } + + public function setPart (Part $part) { + $this->part = $part; + } + + public function getPart () { + return $this->part; + } + + public function setManufacturer (Manufacturer $manufacturer) { + $this->manufacturer = $manufacturer; + } + + public function getManufacturer () { + return $this->manufacturer; + } + + public function setPartNumber ($partNumber) { + $this->partNumber = $partNumber; + } + + public function getPartNumber () { + return $this->partNumber; + } + + public function getId () { + return $this->id; + } + + public function serialize () { + return array( + "id" => $this->getId(), + "partNumber" => $this->getPartNumber(), + "manufacturer_id" => $this->getManufacturer()->getId(), + "manufacturer_name" => $this->getManufacturer()->getName(), + "part_id" => $this->getPart()->getId(), + "part_name" => $this->getPart()->getName()); + } + + +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/Part/PartService.php b/src/de/RaumZeitLabor/PartDB2/Part/PartService.php @@ -11,7 +11,7 @@ use de\RaumZeitLabor\PartDB2\Part\PartManager, de\RaumZeitLabor\PartDB2\Session\SessionManager; class PartService extends Service implements RestfulService { -public function get () { + public function get () { if ($this->hasParameter("id")) { return PartManager::getInstance()->getPart($this->getParameter("id"))->serialize(); } else { @@ -35,31 +35,15 @@ public function get () { } public function create () { - $this->requireParameter("footprint"); - - $fp = FootprintManager::getInstance()->addFootprint($this->getParameter("footprint")); - - return array("data" => $fp->serialize()); + throw new \Exception("Not yet implemented"); } public function update () { - $this->requireParameter("id"); - $this->requireParameter("footprint"); - $footprint = FootprintManager::getInstance()->getFootprint($this->getParameter("id")); - $footprint->setFootprint($this->getParameter("footprint")); - - PartDB2::getEM()->flush(); - - return array("data" => $footprint->serialize()); - + throw new \Exception("Not yet implemented"); } public function destroy () { - $this->requireParameter("id"); - - FootprintManager::getInstance()->deleteFootprint($this->getParameter("id")); - - return array("data" => null); + throw new \Exception("Not yet implemented"); } @@ -128,15 +112,13 @@ public function get () { $aParameters["quantity"] = $this->getParameter("quantity"); } - /* - $aParameters["category"] = $this->getParameter("category"); - $aParameters["name"] = $this->getParameter("name"); - $aParameters["quantity"] = $this->getParameter("quantity"); - $aParameters["minstock"] = $this->getParameter("minstock"); - $aParameters["storagelocation"] = $this->getParameter("storagelocation"); - $aParameters["footprint"] = $this->getParameter("footprint"); - $aParameters["comment"] = $this->getParameter("comment"); - $aParameters["manufacturer"] = $this->getParameter("manufacturer");*/ + if ($this->hasParameter("distributorChanges")) { + $aParameters["distributorChanges"] = $this->getParameter("distributorChanges"); + } + + if ($this->hasParameter("manufacturerChanges")) { + $aParameters["manufacturerChanges"] = $this->getParameter("manufacturerChanges"); + } PartManager::getInstance()->addOrUpdatePart($aParameters); diff --git a/src/de/RaumZeitLabor/PartDB2/PartDB2.php b/src/de/RaumZeitLabor/PartDB2/PartDB2.php @@ -171,6 +171,8 @@ class PartDB2 { 'de\RaumZeitLabor\PartDB2\Footprint\Footprint', 'de\RaumZeitLabor\PartDB2\Category\Category', 'de\RaumZeitLabor\PartDB2\Part\Part', + 'de\RaumZeitLabor\PartDB2\Part\PartManufacturer', + 'de\RaumZeitLabor\PartDB2\Part\PartDistributor', 'de\RaumZeitLabor\PartDB2\StorageLocation\StorageLocation', 'de\RaumZeitLabor\PartDB2\Stock\StockEntry', 'de\RaumZeitLabor\PartDB2\Manufacturer\Manufacturer', diff --git a/src/de/RaumZeitLabor/PartDB2/PartDistributor/PartDistributorManager.php b/src/de/RaumZeitLabor/PartDB2/PartDistributor/PartDistributorManager.php @@ -0,0 +1,75 @@ +<?php +namespace de\RaumZeitLabor\PartDB2\PartDistributor; +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartDB2\Util\Singleton, + de\RaumZeitLabor\PartDB2\Manufacturer\Manufacturer, + de\RaumZeitLabor\PartDB2\PartDB2, + de\RaumZeitLabor\PartDB2\Manufacturer\Exceptions\ManufacturerNotFoundException; + +class PartDistributorManager extends Singleton { + public function getPartDistributors ($start = 0, $limit = 10, $sort = "name", $dir = "asc", $filter = "") { + + $qb = PartDB2::getEM()->createQueryBuilder(); + $qb->select("pd.orderNumber, part.id AS part_id, dist.id AS distributor_id")->from("de\RaumZeitLabor\PartDB2\Part\PartDistributor","pd") + ->leftJoin('pd.distributor', "dist") + ->leftJoin("pd.part", "part"); + + /*if ($filter != "") { + $manufacturer = Manufacturer::loadById($filter); + $qb = $qb->where("st.manufacturer = :manufacturer"); + $qb->setParameter("manufacturer", $manufacturer); + }*/ + + if ($limit > -1) { + $qb->setMaxResults($limit); + $qb->setFirstResult($start); + } + + $qb->orderBy("pd.".$sort, $dir); + + $query = $qb->getQuery(); + + $result = $query->getResult(); + + $totalQueryBuilder = PartDB2::getEM()->createQueryBuilder(); + $totalQueryBuilder->select("COUNT(pd.id)")->from("de\RaumZeitLabor\PartDB2\Part\PartDistributor","pd"); + + + /* + if ($filter != "") { + $totalQueryBuilder = $totalQueryBuilder->where("st.manufacturer = :manufacturer"); + $totalQueryBuilder->setParameter("manufacturer", $manufacturer); + }*/ + + $totalQuery = $totalQueryBuilder->getQuery(); + + return array("data" => $result, "totalCount" => $totalQuery->getSingleScalarResult()); + } + + public function getPartDistributor ($id) { + $partDistributor = PartDB2::getEM()->find("de\RaumZeitLabor\PartDB2\Part\PartDistributor", $id); + + if ($partDistributor) { + return $partDistributor; + } else { + throw new PartDistributorNotFoundException(); + } + } + + public function addPartDistributor ($orderNumber) { + $partDistributor = new PartDistributor(); + $partDistributor->setName($orderNumber); + + PartDB2::getEM()->persist($partDistributor); + PartDB2::getEM()->flush(); + + return $partDistributor; + } + public function deletePartDistributor ($id) { + $manufacturer = $this->getManufacturer($id); + + PartDB2::getEM()->remove($manufacturer); + PartDB2::getEM()->flush(); + } +}+ \ No newline at end of file diff --git a/src/de/RaumZeitLabor/PartDB2/PartDistributor/PartDistributorService.php b/src/de/RaumZeitLabor/PartDB2/PartDistributor/PartDistributorService.php @@ -0,0 +1,88 @@ +<?php +namespace de\RaumZeitLabor\PartDB2\ManufacturerICLogo; +use de\RaumZeitLabor\PartDB2\Manufacturer\ManufacturerICLogo; + +use de\RaumZeitLabor\PartDB2\Image\TempImage; + +use de\RaumZeitLabor\PartDB2\Service\RestfulService; + +declare(encoding = 'UTF-8'); + +use de\RaumZeitLabor\PartDB2\Service\Service; +use de\RaumZeitLabor\PartDB2\PartDB2, + de\RaumZeitLabor\PartDB2\Manufacturer\Manufacturer, + de\RaumZeitLabor\PartDB2\Session\SessionManager; + +class PartDistributorService extends Service implements RestfulService { + public function get () { + if ($this->hasParameter("id")) { + return PartDistributorManager::getInstance()->getManufacturerICLogo($this->getParameter("id"))->serialize(); + } else { + if ($this->hasParameter("sort")) { + $tmp = json_decode($this->getParameter("sort"), true); + + $aSortParams = $tmp[0]; + } else { + $aSortParams = array( + "property" => "id", + "direction" => "ASC"); + } + + $filter = ""; + + if ($this->hasParameter("filter")) { + $tmp = json_decode($this->getParameter("filter"), true); + + foreach ($tmp as $item) { + if (array_key_exists("property", $item)) { + if ($item["property"] == "manufacturer_id") { + if (array_key_exists("value", $item)) { + $filter = $item["value"]; + } + } + } + } + } + return ManufacturerICLogoManager::getInstance()->getManufacturerICLogos( + $this->getParameter("start", $this->getParameter("start", 0)), + $this->getParameter("limit", $this->getParameter("limit", 25)), + $this->getParameter("sortby", $aSortParams["property"]), + $this->getParameter("dir", $aSortParams["direction"]), + $filter); + } + } + + public function create () { + $this->requireParameter("tmp_id"); + $this->requireParameter("manufacturer_id"); + + $tmpImage = TempImage::loadById($this->getParameter("tmp_id")); + + $image = new ManufacturerICLogo(); + + $manufacturer = Manufacturer::loadById($this->getParameter("manufacturer_id")); + + $image->setManufacturer($manufacturer); + $image->replace($tmpImage->getImageFilename()); + PartDB2::getEM()->persist($image); + PartDB2::getEM()->flush(); + + return $image->serialize(); + } + + public function update () { + + } + + public function destroy () { + $this->requireParameter("id"); + + $logo = ManufacturerICLogo::loadById($this->getParameter("id")); + + PartDB2::getEM()->remove($logo); + PartDB2::getEM()->flush(); + + return array("data" => null); + } + +}+ \ No newline at end of file diff --git a/testing/SetupDatabase.php b/testing/SetupDatabase.php @@ -18,6 +18,10 @@ use de\RaumZeitLabor\PartDB2\Category\CategoryManagerService; use de\RaumZeitLabor\PartDB2\Manufacturer\ManufacturerICLogo; use de\RaumZeitLabor\PartDB2\Manufacturer\Manufacturer; +use de\RaumZeitLabor\PartDB2\Distributor\Distributor; + +use de\RaumZeitLabor\PartDB2\Part\PartDistributor; +use de\RaumZeitLabor\PartDB2\Part\PartManufacturer; PartDB2::initialize(); @@ -139,6 +143,38 @@ while ($store = mysql_fetch_assoc($r)) { echo "\n"; +/* Add manufacturers and IC logos */ +$data = \Symfony\Component\Yaml\Yaml::load("../setup/data/manufacturers/manufacturers.yaml"); + +$aManufacturers = array(); +$aDistributors = array(); + +foreach ($data as $mfgname => $logos) { + $manufacturer = new Manufacturer(); + $manufacturer->setName($mfgname); + + PartDB2::getEM()->persist($manufacturer); + $aManufacturers[] = $manufacturer; + /* Temporary: Add fake distributors */ + + $distributor = new Distributor(); + $distributor->setName("Distributor ".$mfgname); + + PartDB2::getEM()->persist($distributor); + + $aDistributors[] = $distributor; + + foreach ($logos as $logo) { + $mfglogo = new ManufacturerICLogo(); + $mfglogo->setManufacturer($manufacturer); + $mfglogo->replace("../setup/data/manufacturers/images/".$logo); + + PartDB2::getEM()->persist($mfglogo); + } +} + +PartDB2::getEM()->flush(); + $r = mysql_query("SELECT * FROM parts"); while ($part = mysql_fetch_assoc($r)) { @@ -149,6 +185,16 @@ while ($part = mysql_fetch_assoc($r)) { $oPart->setCategory($newCategories[$part["id_category"]]); $oPart->setStorageLocation($newStorageLocations[$part["id_storeloc"]]); $oPart->setMinStockLevel($part["mininstock"]); + + for ($i=0;$i<rand(0,15);$i++) { + $randomManufacturer = rand(0, count($aManufacturers)-1); + $oPart->getManufacturers()->add(new PartManufacturer($oPart, $aManufacturers[$randomManufacturer])); + } + + for ($i=0;$i<rand(0,15);$i++) { + $randomDistributor = rand(0, count($aDistributors)-1); + $oPart->getDistributors()->add(new PartDistributor($oPart, $aDistributors[$randomDistributor])); + } echo "Migrating part ".sprintf("%-40s", $part["name"])."\r"; PartDB2::getEM()->persist($oPart); @@ -159,25 +205,11 @@ while ($part = mysql_fetch_assoc($r)) { PartDB2::getEM()->flush(); -/* Add manufacturers and IC logos */ -$data = \Symfony\Component\Yaml\Yaml::load("../setup/data/manufacturers/manufacturers.yaml"); -foreach ($data as $mfgname => $logos) { - $manufacturer = new Manufacturer(); - $manufacturer->setName($mfgname); - - PartDB2::getEM()->persist($manufacturer); - - foreach ($logos as $logo) { - $mfglogo = new ManufacturerICLogo(); - $mfglogo->setManufacturer($manufacturer); - $mfglogo->replace("../setup/data/manufacturers/images/".$logo); - - PartDB2::getEM()->persist($mfglogo); - } -} -PartDB2::getEM()->flush(); + + + echo "All done.\n";