Create warehouse module

Discuss about Group-Office development here

Moderator: Developers

mathil
Posts: 6
Joined: Fri Apr 11, 2014 10:40 am

Create warehouse module

Postby mathil » Fri Apr 11, 2014 10:58 am

Hi.
I create a module for product management. I modeled on the module presidents. I have a problem with adding items. At the beginning I created a new dialog (receptionDialog) in which I want to receive merchandise.
After reading the barcode field in the table, it should be filled with information about the product and also in the "adopted" type 1, it will automatically create a new blank record and move the cursor to it.
When you click save the values ​​in column "adopted" should be added to the value in the "quantity" and stored in a database.
I have no idea how to go about it. Can someone please point me?

Greetings, mathil
mathil
Posts: 6
Joined: Fri Apr 11, 2014 10:40 am

Re: Create warehouse module

Postby mathil » Fri Apr 18, 2014 11:31 am

It's me again.
I created a dialog that performs these steps but I don't know how to save it to the database. It is possible that the structure of the dialogue is not as it should but don't know how to do it in the controller.. I'm trying to add the items JsonStore records and call the submitMultiple, but I have error:

Notice: Undefined index: records in /usr/share/groupoffice/go/base/controller/AbstractModelController.php on line 1461

Warning: Invalid argument supplied for foreach() in /usr/share/groupoffice/go/base/controller/AbstractModelController.php on line 1463
{"success":true}


This is my code:

Code: Select all

/**
 * Copyright Intermesh
 *
 * This file is part of Group-Office. You should have received a copy of the
 * Group-Office license along with Group-Office. See the file /LICENSE.TXT
 *
 * If you have questions write an e-mail to info@intermesh.nl
 *
 * @version $Id: PresidentDialog.js 14816 2013-05-21 08:31:20Z mschering $
 * @copyright Copyright Intermesh
 * @author Merijn Schering <mschering@intermesh.nl>
 */

GO.warehouse.ReceptionDialog = function() {

    this.buildForm();

    this.goDialogId = 'reception';

    this.remind_before = '';


    this.win = new GO.Window({
        layout: 'fit',
        modal: false,
        resizable: true,
        width: 560,
        height: 400,
        closeAction: 'close',
        collapsible: true,
        title: 'Przyjęcie wewnętrzne',
        items: [this.grid, this.formPanel],
//        focus: focusName.createDelegate(this),
        buttons: [{
                text: GO.lang['cmdOk'],
                handler: function() {
                    this.submitForm(true);
                },
                scope: this
            }, /* {
             text : GO.lang['cmdApply'],
             handler : function() {
             this.submitForm();
             },
             scope : this
             }, */{
                text: GO.lang['cmdClose'],
                handler: function() {
                    this.win.close();

                },
                scope: this
            }]
    });

    this.win.render(Ext.getBody());
    GO.warehouse.ReceptionDialog.superclass.constructor.call(this);
}

Ext.extend(GO.warehouse.ReceptionDialog, Ext.util.Observable, {
    show: function(config) {
        console.log('show');
        this.win.show();


    },
    submitForm: function(hide) {
//        console.log('count ' + this.bufStore.getCount());
        for (var i = 0; i < this.bufStore.getCount(); i++) {
            for (var j = 0; j < this.dataStore.getCount(); j++) {
                if (this.bufStore.getAt(i)['data']['Kod'] == this.dataStore.getAt(j)['data']['barcode']) {
                    this.dataStore.getAt(j)['data']['quantity'] = this.dataStore.getAt(j)['data']['quantity'] + this.bufStore.getAt(i)['data']['Przyjeto'];
                }
            }
//            console.log(this.bufStore.getAt(i)['data']['Nazwa'] + ', ' + this.bufStore.getAt(i)['data']['Przyjeto']);
        }

        for (var i = 0; i < this.dataStore.getCount(); i++) {
//            console.log(this.dataStore.getAt(i)['data']['name'] + ', ' + this.dataStore.getAt(i)['data']['quantity']);
        }

        this.formPanel.form.submit({
            store: this.dataStore,
            url: GO.url('warehouse/reception/submitMultiple'),
            success: function() {
                console.log('success');
            },
            failure: function() {
                console.log('failure');
            },
            scope: this.dataStore
        });



    },
    buildForm: function() {
        console.log('buildForm');

        var myData = [['', '', '']];
        GO.dialog.TabbedFormDialog.prototype.refreshActiveDisplayPanels.call(this);
        var bufStore = new Ext.data.ArrayStore({
            fields: [
                {name: 'Kod', type: 'string'},
                {name: 'Nazwa', type: 'string'},
                {name: 'Przyjeto', type: 'string'}
            ]
        });

        var dataStore = new GO.data.JsonStore({
            url: GO.url('warehouse/warehouse/store'),
            fields: ['id', 'barcode', 'name', 'quantity', 'available', 'unit', 'price', 'price_val'],
            remoteSort: true,
            model: 'GO_Warehouse_Model_Reception'
        });
        dataStore.load();
        this.dataStore = dataStore;
        console.log(dataStore);

        bufStore.loadData(myData);
        this.bufStore = bufStore;

        var fm = Ext.form;
        var counter = 0;

        var grid = new Ext.grid.EditorGridPanel({
            store: bufStore,
            loadMask: false,
            clicksToEdit: 1,
            sm: new Ext.grid.RowSelectionModel({singleSelect: true}),
            height: 320,
            frame: true,
            title: 'Produkty',
            iconCls: 'icon-grid',
            border: false,
            colModel: new Ext.grid.ColumnModel({
                columns: [
                    {
                        id: 01,
                        header: 'Kod',
                        dataIndex: 'Kod',
                        width: 160,
                        editable: true,
                        editor: new fm.TextField({
                            allowBlank: false,
                            listeners: {
                                specialKey: function(fm, e) {
                                    if (e.getKey() === Ext.EventObject.ENTER) {
                                        console.log('enter');
                                        var zm = this.getValue();
                                        console.log(zm);
                                        var m = grid.getSelectionModel();
                                        var rec = m.getSelected();
                                        for (var i = 0; i < dataStore.getCount(); i++) {
                                            if (dataStore.getAt(i)['data']['barcode'] == zm) {
//                                                console.log('jest');
                                                rec.set('Nazwa', dataStore.getAt(i)['data']['name']);
                                                rec.set('Przyjeto', 1);
                                                var defaultData = {
                                                    Kod: '',
                                                    Nazwa: '',
                                                    Przyjeto: ''
                                                };
                                                var recId = counter + 2;
                                                var p = new bufStore.recordType(defaultData, recId);
                                                bufStore.insert(bufStore.getCount(), p);
//                                                console.log(bufStore.getCount());
                                                grid.startEditing(counter, 0);
                                                counter++;
//                                                console.log(i);
                                                break;
                                            }
                                        }
                                    }
//                                    console.log('getCount ' + bufStore.getCount());
                                }
                            }
                        })
                    },
                    {
                        id: 02,
                        header: 'Nazwa',
                        dataIndex: 'Nazwa',
                        width: 160
                    },
                    {
                        id: 03,
                        header: 'Przyjęto',
                        dataIndex: 'Przyjeto',
                        width: 160,
                        editable: true,
                        editor: new fm.TextField({
                            allowBlank: false
                        }
                        )}
                ]
            }),
            view: new Ext.grid.GridView({
                emptyText: GO.lang.strNoItemse
            })
        });
        this.grid = grid;

        var formPanel = this.formPanel = new Ext.form.FormPanel({
            border: false,
            baseParams: {
                reception: 'reception'
            }
        });


    }





});


Can someone please steer me what should I change?

Grreetings, mathil :)
mathil
Posts: 6
Joined: Fri Apr 11, 2014 10:40 am

Re: Create warehouse module

Postby mathil » Mon May 26, 2014 8:13 am

Everything is working, but I have another problem. I created MainPanel on the model of the module adressbook and I have a probem with TabPanel in which I want to display the products and documents.When I run GO I get an error:

Uncaught TypeError: Can not read property 'added' of undefined


What could be the reason? This is my MainPanel code:

Code: Select all


GO.warehouse.MainPanel = function(config) {

    if (!config)
    {
        config = {};
    }

    //deklaracja siatki z produktami
    GO.warehouse.warehouseGrid = this.warehouseGrid = new GO.warehouse.WarehouseGrid({
        layout: 'fit',
        region: 'center',
        id: 'wm-warehouse-grid',
        title: 'Produkty'
    });

    this.warehouseGrid.on("delayedrowselect", function(grid, rowIndex, r) {
        this.displayCardPanel.getLayout().setActiveItem(this.warehouseEastPanel);
        this.warehouseEastPanel.load(r.get('id'));
    }, this);

    this.warehouseGrid.on("rowdblclick", function() {
        this.warehouseEastPanel.editHandler();
    }, this);

    //deklaracja siatki z dokumentami
    GO.warehouse.documentsGrid = this.documentsGrid = new GO.warehouse.DocumentsGrid({
        layout: 'fit',
        region: 'center',
        id: 'wm-documents-grid',
        title: 'Dokumenty'
    });

    this.documentsGrid.on("delayedrowselect", function(grid, rowIndex, r) {
        this.displayCardPanel.getLayout().setActiveItem(this.documentsEastPanel);
        this.documentsEastPanel.load(r.get('id'));
    }, this);

    this.documentsGrid.on("rowdblclick", function() {
        this.documentsEastPanel.editHandler();
    }, this);

    this.warehouseGrid.store.on('load', function() {
        this.warehouseGrid.store.load();
    }, this);

    this.documentsGrid.store.on('load', function() {
        this.documentsGrid.store.load();
    }, this);

    //deklaracja lewego panelu dla siatki produkty
    this.warehouseEastPanel = new GO.warehouse.WarehousePanel({
        id: 'wm-warehouse-panel',
        border: false
    });

    //deklaracja lewego panelu dla siatki dokumenty
    this.documentsEastPanel = new GO.warehouse.DocumentsPanel({
        id: 'wm-documents-panel',
        border: false
    });

    //deklaracja tabPanelu
    this.tabPanel = new Ext.TabPanel({
        region: 'center',
        activeTab: 0,
        border: true,
        listeners: {
            scope: this,
            tabchange: function(tabPanel, activeTab) {
                if (activeTab.id == 'wm-warehouse-grid')
                    this.warehouseGrid.store.load();
                else
                    this.documentsGrid.store.load();
            }
        },
        items: [
            this.warehouseGrid,
            this.documentsGrid
        ]
    });

    //deklaracja lewego panelu zawierającego panel produkty i dokumenty
    this.displayCardPanel = new Ext.Panel({
        region: 'east',
        layout: 'card',
        layoutConfig: {
            layoutOnCardChange: true
        },
        width: 500,
        id: 'wm-east-panel',
        split: true,
        items: [
            this.warehouseEastPanel,
            this.documentsEastPanel
        ]
    });

    config.layout = 'border';
    config.border = false;

    //deklaracja zawartości okna głównego
    config.items = [
        this.tabPanel,
        this.displayCardPanel
    ];

    //deklaracja paska narzędziowego
    var tbar = [
        {
            iconCls: 'btn-add',
            text: GO.lang['cmdAdd'],
            cls: 'x-btn-text-icon',
            handler: function() {
                this.tabPanel.showEditDialog();
            },
            scope: this
        },
        {
            iconCls: 'btn-edit',
            text: "Przyjęcie wewnętrzne",
            cls: 'x-btn-text-icon',
            handler: function() {
                GO.warehouse.showReceptionDialog();
            },
            scope: this
        },
        {
            iconCls: 'btn-edit',
            text: "Wydanie wewnętrzne",
            cls: 'x-btn-text-icon',
            handler: function() {
                GO.warehouse.showInternalEditionDialog();
            },
            scope: this
        },
        {
            iconCls: 'btn-delete',
            text: GO.lang['cmdDelete'],
            cls: 'x-btn-text-icon',
            handler: function() {
                var activetab = this.tabPanel.getActiveTab();

                switch (activetab.id)
                {
                    case 'wm-warehouse-grid':
                        this.warehouseGrid.deleteSelected({
                            callback: this.warehouseEastPanel.gridDeleteCallback,
                            scope: this.warehouseEastPanel
                        });
                        break;
                    case 'wm-documents-grid':
                        this.documentsGrid.deleteSelected({
                            callback: this.documentsEastPanel.gridDeleteCallback,
                            scope: this.documentsEastPanel
                        });
                        break;
                }
            },
            scope: this
        },
        {
            iconCls: 'btn-refresh',
            text: GO.lang['cmdRefresh'],
            cls: 'x-btn-text-icon',
            handler: function() {
                var activetab = this.tabPanel.getActiveTab();

                switch (activetab.id)
                {
                    case 'wm-warehouse-grid':
                        this.warehouseGrid.store.reload();
                        break;
                    case 'wm-documents-grid':
                        this.documentsGrid.store.reload();
                        break;
                }
            },
            scope: this
        }
    ];

    //dodanie paska narzędzi do panelu
    config.tbar = new Ext.Toolbar({
        cls: 'go-head-tb',
        items: tbar
    });

};

Ext.extend(GO.warehouse.MainPanel, Ext.Panel, {
    init: function() {
        this.getEl().mask(GO.lang.waitMsgLoad);
    },
    afterRender: function()
    {
        GO.warehouse.MainPanel.superclass.afterRender.call(this);
        this.init();

        GO.dialogListeners.add('warehouse', {
            scope: this,
            'save': function() {
                var panel = this.tabPanel.getActiveTab();
                if (panel.id == 'wm-warehouse-grid')
                {
                    this.warehouseGrid.store.reload();
                }
            }
        });

        GO.dialogListeners.add('documents', {
            scope: this,
            'save': function() {
                var panel = this.tabPanel.getActiveTab();
                if (panel.id == 'wm-documents-grid')
                {
                    this.documentsGrid.store.reload();
                }
            }
        });
    },
});


/*
 * This will add the module to the main tabpanel filled with all the modules
 */
GO.moduleManager.addModule(
        'warehouse', //Module alias
        GO.warehouse.MainPanel, //The main panel for this module
        {
            title: 'Magazyn', //Module name in startmenu
            iconCls: 'go-module-icon-warehouse' //The css class with icon for startmenu
        }
);

/*
 * Add linkHandeler for linking models from this module to other GroupOffice models
 */
GO.linkHandlers["GO_Warehouse_Model_Warehouse"] = function(id) {
    if (!GO.warehouse.linkWarehouseWindow) {


        var warehousePanel = new GO.warehouse.WarehousePanel();
        GO.warehouse.linkWarehouseWindow = new GO.LinkViewWindow({
            title: GO.warehouse.lang.warehouse,
            items: warehousePanel,
            warehousePanel: warehousePanel,
            closeAction: "hide"
        });
    }
    GO.warehouse.linkWarehouseWindow.warehousePanel.load(id);
    GO.warehouse.linkWarehouseWindow.show();
    return GO.warehouse.linkWarehouseWindow;
},
        GO.linkPreviewPanels["GO_Warehouse_Model_Warehouse"] = function(config) {

    config = config || {};
    return new GO.warehouse.WarehousePanel(config);
},
        GO.linkPreviewPanels["GO_Warehouse_Model_Documents"] = function(config) {

    config = config || {};
    return new GO.warehouse.DocumentsPanel(config);
},
        GO.linkHandlers["GO_Warehouse_Model_Documents"] = function(id) {
    if (!GO.warehouse.linkDocumentsWindow) {

        var documentsPanel = new GO.warehouse.DocumentsPanel();
        GO.warehouse.linkDocumentsWindow = new GO.LinkViewWindow({
            title: 'Dokumenty',
            items: documentsPanel,
            documentsPanel: documentsPanel,
            closeAction: "hide"
        });
    }
    GO.warehouse.linkDocumentsWindow.warehousePanel.load(id);
    GO.warehouse.linkDocumentsWindow.show();
    return GO.warehouse.linkDocumentsWindow;
},
        GO.warehouse.showReceptionDialog = function() {

    if (!GO.warehouse.receptionDialog)
        GO.warehouse.receptionDialog = new GO.warehouse.ReceptionDialog();

    GO.warehouse.receptionDialog.show();
},
        GO.warehouse.showInternalEditionDialog = function() {

    if (!GO.warehouse.internalEditionDialog)
        GO.warehouse.internalEditionDialog = new GO.warehouse.InternalEditionDialog();

    GO.warehouse.internalEditionDialog.show();
};


And WarehouseGrid and DocumentGrid code:

Code: Select all

/**
 * Copyright Intermesh
 *
 * This file is part of Group-Office. You should have received a copy of the
 * Group-Office license along with Group-Office. See the file /LICENSE.TXT
 *
 * If you have questions write an e-mail to info@intermesh.nl
 *
 * @version $Id: PresidentsGrid.js 14816 2013-05-21 08:31:20Z mschering $
 * @copyright Copyright Intermesh
 * @author Merijn Schering <mschering@intermesh.nl>
 */

GO.warehouse.WarehouseGrid = function(config) {

    if (!config)
    {
        config = {};
    }

    config.title = GO.warehouse.lang.warehouse; //Title of this panel
    config.layout = 'fit'; //How to lay out the panel
    config.autoScroll = true;
    config.split = true;
    config.autoLoadStore = true; //Load the datastore when grid render for the first time
    config.paging = true; //Use pagination for the grid
    config.sm = new Ext.grid.RowSelectionModel();
    config.loadMask = true; //Mask the grid when it is loading data

    //This dialog will be opened when double clicking a row or calling showEditDialog()
    config.editDialogClass = GO.warehouse.WarehouseDialog;
    config.pwDialogClass = GO.warehouse.ReceptionDialog;

    //Configuring the column model
    config.cm = new Ext.grid.ColumnModel({
        defaults: {
            sortable: true
        },
        columns: [{
                header: '#',
                readOnly: true,
                dataIndex: 'id',
                renderer: function(value, cell) {
                    cell.css = "readonlycell";
                    return value;
                },
                width: 50
            }, {
                header: GO.warehouse.lang.barcode,
                dataIndex: 'barcode',
                width: 120,
                align: "right"
            }, {
                header: GO.warehouse.lang.name,
                dataIndex: 'name',
                width: 120,
                align: "right"
               
            }, {
                header: GO.warehouse.lang.quantity,
                dataIndex: 'quantity',
                align: "right",
                width: 120
            }, {
                header: GO.warehouse.lang.unit,
                dataIndex: 'unit',
                align: "right",
                width: 120
            }, {
                header: GO.warehouse.lang.price,
                dataIndex: 'price',
                width: 120,
                align: "right",
            }]
    });

    //Defining the data store for the grid
    config.store = new GO.data.JsonStore({
        url: GO.url('warehouse/warehouse/store'),
        fields: ['id', 'barcode', 'name', 'quantity', 'unit', 'price', 'price_val'],
        remoteSort: true,
        model: 'GO_Warehouse_Model_Warehouse'
    });


    //Adding the gridview to the grid panel
    config.view = new Ext.grid.GridView({
        emptyText: GO.lang.strNoItemse
    });

    //Setup a toolbar for the grid panel
    config.tbar = new Ext.Toolbar({
        items: [
            GO.lang.strSearch + ':',
            new GO.form.SearchField({
                store: config.store,
                width: 320
            })
        ]
    });


    //Construct the Gridpanel with the above configuration
    GO.warehouse.WarehouseGrid.superclass.constructor.call(this, config);

};

//Extend the WarehouseGrid from GridPanel
Ext.extend(GO.warehouse.WarehouseGrid, GO.grid.GridPanel, {
   
});


Code: Select all

/**
 * Copyright Intermesh
 *
 * This file is part of Group-Office. You should have received a copy of the
 * Group-Office license along with Group-Office. See the file /LICENSE.TXT
 *
 * If you have questions write an e-mail to info@intermesh.nl
 *
 * @version $Id: PresidentsGrid.js 14816 2013-05-21 08:31:20Z mschering $
 * @copyright Copyright Intermesh
 * @author Merijn Schering <mschering@intermesh.nl>
 */

GO.warehouse.DocumentsGrid = function(config) {

    if (!config)
    {
        config = {};
    }

    config.title = 'Dokumenty'; //Title of this panel
    config.layout = 'fit'; //How to lay out the panel
    config.autoScroll = true;
    config.split = true;
    config.autoLoadStore = true; //Load the datastore when grid render for the first time
    config.paging = true; //Use pagination for the grid
    config.sm = new Ext.grid.RowSelectionModel();
    config.loadMask = true; //Mask the grid when it is loading data

    //This dialog will be opened when double clicking a row or calling showEditDialog()
    config.editDialogClass = GO.warehouse.WarehouseDialog;
    config.pwDialogClass = GO.warehouse.ReceptionDialog;

    //Configuring the column model
    config.cm = new Ext.grid.ColumnModel({
        defaults: {
            sortable: true
        },
        columns: [{
                header: '#',
                readOnly: true,
                dataIndex: 'id',
                renderer: function(value, cell) {
                    cell.css = "readonlycell";
                    return value;
                },
                width: 50
            }, {
                header: 'Użytkownik',
                dataIndex: 'user',
                align: "right",
                width: 120
            }, {
                header: 'Typ',
                dataIndex: 'type',
                align: "right",
                width: 120
            }, {
                header: 'Data utworzenia',
                dataIndex: 'ctime',
                align: "right",
                width: 120
            }, {
                header: 'Ilość',
                dataIndex: 'quantity',
                align: "right",
                width: 120
            }]
    });

    //Defining the data store for the grid
    config.store = new GO.data.JsonStore({
        url: GO.url('warehouse/documents/store'),
        fields: ['id', 'user', 'type', 'ctime', 'quantity'],
        remoteSort: true,
        model: 'GO_Warehouse_Model_Documents'
    });


    //Adding the gridview to the grid panel
    config.view = new Ext.grid.GridView({
        emptyText: GO.lang.strNoItemse
    });

    //Setup a toolbar for the grid panel
    config.tbar = new Ext.Toolbar({
        items: [
            GO.lang.strSearch + ':',
            new GO.form.SearchField({
                store: config.store,
                width: 320
            })
        ]
    });


    //Construct the Gridpanel with the above configuration
    GO.warehouse.DocumentsGrid.superclass.constructor.call(this, config);

};

//Extend the WarehouseGrid from GridPanel
Ext.extend(GO.warehouse.DocumentsGrid, GO.grid.GridPanel, {
   
});


Can anyone help me?
mschering
Site Admin
Site Admin
Posts: 8154
Joined: Tue Apr 20, 2004 1:06 pm
Location: The Netherlands - Den Bosch
Contact:

Re: Create warehouse module

Postby mschering » Tue May 27, 2014 9:49 am

I can't find it in your code directly. But this error indicates that you add an empty or null item to something somewhere.
Best regards,

Merijn Schering
Intermesh
richarddodd
Posts: 66
Joined: Fri Jun 21, 2013 2:55 pm

Re: Create warehouse module

Postby richarddodd » Thu May 29, 2014 12:42 pm

You get extjs errors like this that aren't always helpful. What I do is set chrome to 'pause on exception' and then inspect the stack trace to see if my code features in it anywhere. If it does, then begin looking here, if not then it's probably an initialization problem, like not specifying 'fields' for a Store, or something like that.

Hope this helps
richarddodd
Posts: 66
Joined: Fri Jun 21, 2013 2:55 pm

Re: Create warehouse module

Postby richarddodd » Thu May 29, 2014 12:43 pm

<Impartiality note> There are many other js stack inspectors (firebug, ie, ...) :)
mathil
Posts: 6
Joined: Fri Apr 11, 2014 10:40 am

Re: Create warehouse module

Postby mathil » Thu May 29, 2014 1:08 pm

Everything is fine. I forgot to add

GO.warehouse.MainPanel.superclass.constructor.call(this, config);


in MainPanel Code,but thanks for your answers :)
mathil
Posts: 6
Joined: Fri Apr 11, 2014 10:40 am

Re: Create warehouse module

Postby mathil » Mon Jun 02, 2014 11:09 am

It's me again :) I have a problem with load all records by JSONStore. I have 55 records in DB, but JSONStore returns only 30 records. How to fix it?
mschering
Site Admin
Site Admin
Posts: 8154
Joined: Tue Apr 20, 2004 1:06 pm
Location: The Netherlands - Den Bosch
Contact:

Re: Create warehouse module

Postby mschering » Tue Jun 03, 2014 7:52 am

It pages by default. Add a paging toolbar or send param limit=0.
Best regards,



Merijn Schering

Intermesh

Return to “Development Chats”

Who is online

Users browsing this forum: No registered users and 1 guest

cron