/** 
 * 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: IncomeDialog.js 19675 2014-09-16 10:13:31Z wvbeusekom $
 * @copyright Copyright Intermesh
 * @author Michael de Hart <mdhart@intermesh.nl>
 */
 
GO.projects2.IncomeDialog = Ext.extend(GO.dialog.TabbedFormDialog , {
		
	jsonPost: true,
	_projectId: 0,
		
	initComponent : function(){
		
		Ext.apply(this, {
			titleField:'description',
			title:GO.projects2.lang.income,
			height: 550,
			formControllerUrl: 'projects2/income'
		});
		
		GO.projects2.IncomeDialog.superclass.initComponent.call(this);	
	},
	buildForm : function () {

		this.propertiesPanel = new Ext.Panel({
			title:GO.lang['strProperties'],
			cls:'go-form-panel',
			layout:'form',
			items:[
			this.projectButton = new Ext.Button({
				text: GO.projects2.lang['showProject'],
				handler: function() {
					GO.projects2.showProjectDialog({
						project_id: this._projectId
					})
				},
				scope: this
			}),
			{				
				xtype: 'textfield',
				name: 'income.description',
				anchor: '100%',
				maxLength: 250,	
				fieldLabel: GO.lang.strDescription
			},{				
				xtype: 'numberfield',
				name: 'income.amount',
				anchor: '100%',		
				fieldLabel: GO.projects2.lang['amount']
			},{				
				xtype: 'datefield',
				name: 'income.invoice_at',
				anchor: '100%',
				maxLength: 50,
				allowBlank:false,
				fieldLabel: GO.projects2.lang['invoiceAt'],
				value: new Date()
			},{				
				xtype: 'xcheckbox',
				name: 'income.is_invoiced',
				fieldLabel: GO.projects2.lang['invoiced']
			},this.txtInvoiceNo = new Ext.form.TextField({				
				name: 'income.invoice_number',
				maxLength: 50,
//				hidden: this.isNew(),
				fieldLabel: GO.projects2.lang['invoiceNo']
			}),this.referenceNoField = new Ext.form.TextField({				
				name: 'income.reference_no',
				maxLength: 64,
				fieldLabel: GO.projects2.lang['referenceNo']
			}),
			this.commentsField = new Ext.form.TextArea({				
				name: 'income.comments',
				height: 150,
				width: '100%',
				fieldLabel: GO.lang['strComment']
			}),
			{
				xtype: 'plainfield',
				value: '<br /><strong>'+GO.projects2.lang['customerAddress']+':</strong>',
				hideLabel: true
			},
			this.customerAddressField = new GO.form.PlainField({
				name: 'customer.formatted_address',
				hideLabel: true
			})
			]
		});

		this.addPanel(this.propertiesPanel);
	},
	show : function (remoteModelId, config) {
//		this.txtInvoiceNo.setVisible(!!remoteModelId);
		
		GO.projects2.IncomeDialog.superclass.show.call(this,remoteModelId, config);

		this.formPanel.baseParams['income.project_id'] = this._projectId = config.project_id;
//		this.projectId.setValue(config.project_id);
		this.projectButton.setVisible(this._projectId>0);
	}
});