GO.moduleManager.onModuleReady('projects2', function() {
	Ext.override(GO.projects2.IncomeDialog, {
		
		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']
					}, {
						xtype: 'compositefield',
						items: [ this.txtInvoiceNo = new Ext.form.TextField({
								name: 'income.invoice_number',
								maxLength: 50,
								fieldLabel: GO.projects2.lang['invoiceNo']
							}),this.exactInvoiceButton = new Ext.Button({
								text: GO.exactonline.lang['showExactInvoice'],
								handler: function() {
									window.open(GO.url('exactonline/oauth/callApi',{invoiceNumber:this.txtInvoiceNo.getValue(),'incomeId':this.remoteModelId,'toPDF':true}));
								},
								scope: this
							})]
					}, 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);
			
		}

	});
	
	Ext.override(GO.projects2.TemplateDialog, {
		buildForm: GO.projects2.TemplateDialog.prototype.buildForm.createSequence(function(){	
//			
//			if (GO.util.empty(this.pluginPropertiesFields))
//				this.pluginPropertiesFields = new Array();
			
			this.propertiesPanel.add({
				xtype: 'textfield',
				name: 'exactonline_division_number',
				anchor: '-20',
				fieldLabel: GO.exactonline.lang['divisionNumber']
			});
		})
	});
}, this);


GO.exactonline.downloadSalesInvoice = function(projectId,invoiceNumber) {
	
	window.open(GO.url('exactonline/oauth/callApi',{invoiceNumber:invoiceNumber,'projectId':projectId,'toPDF':true}));
	
}