var windowReportReportTripCargo = null;

/*
Ext.define('Company', {
	extend: 'Ext.data.Model',
	idProperty: 'CID',
	fields: [ {
		name: 'coId'
	}, {
		name: 'company'
	}, {
		name: 'price'
	}, {
		name: 'change'
	}, {
		name: 'pctChange'
	}, {
		name: 'lastChange',
		type: 'date',
		dateFormat: 'c'
	} ],

	hasMany: {
        model: 'History', 
        name: 'history',
        foreignKey: 'customerId'
    },
	
	proxy: {
		type: 'direct',
		directFn: 'areService.readWithHistory'
	}

});

Ext.define('History', {
	extend: 'Ext.data.Model',
	fields: [ {
		name: 'id'
	}, {
		name: 'date',
		type: 'date',
		dateFormat: 'c'
	}, {
		name: 'text'
	}, {
		name: 'companyId',
		reference: 'Company'
	} ]
});
*/



   
//-----------------window-----------------------------------------------------   
function show_LogistMobile_ReportTripCargo_Window()
{
	
	if(!windowReportReportTripCargo){
	
	
	Ext.define('modelReportReportTripTripCargo2', {
    extend: 'Ext.data.Model',
	idProperty: 'CID',
	fields: ['CID','Name','Address','Driver','StartWorkTime','EndWorkTime','DELIVERY_DATE_FACT','DELIVERY_OUTDATE_FACT','PointState',{name: 'SumCargo', type: 'float'},'DriverComments',{name: 'FuelVal', type: 'float'},{name: 'StartOdom', type: 'float'},{name: 'EndOdom', type: 'float'},{name: 'DiffOdom', type: 'float'},'InTime', 'fName', 'imei', {name: 'Distance', type: 'float'}, {name: 'DistanceFact', type: 'float'}, {name: 'CargoValueCount', type: 'float'}, {name: 'ValueVolume', type: 'float'}, {name: 'ValueWeight', type: 'float'}, {name: 'Cost', type: 'float'}
	/*,{
        name: 'Distance',
        type: 'float',
        convert: function(value, record) {
			alert('convert = '+value);
		    //if(!value) {
            //    value = record.get('SumCargo') * record.get('units');
            //}
            return value;
        }
    },*/
	] //{name: 'indoor', type: 'bool'}
	/*,set: function (fieldName, value) {
        alert('set = '+fieldName);
		this.callParent(arguments);
        if (fieldName === 'Distance') { 
            //var total = this.get('SumCargo') * this.get('units');
			var total = this.get('Distance');
            this.set('total');
        }
	}*/
	,hasMany: {
        model: 'modelReportReportTripCargo', 
        name: 'cargo',
        foreignKey: 'CheckPoint_ID'
    },
	});

	Ext.define('modelReportReportTripCargo', {
	extend: 'Ext.data.Model',
	fields: [ 'ID',{name:'CheckPoint_ID',reference:'modelReportReportTripTripCargo2'},'Name','duName','du2Name','CargoValueVolume','Comments']
	});


	var storeReportReportTripTripCargo =  new Ext.data.Store({	        
			    //pageSize: 50,
				//groupField: 'DriverId',
				groupField: 'imei',
		        model: 'modelReportReportTripTripCargo2',
				autoDestroy: true,
	/*idProperty: 'CID',
	hasMany: {
        model: 'modelReportReportTrip2', 
        name: 'cargo',
        foreignKey: 'CheckPoint_ID'
    },*/
				proxy: 
		        {
		          type: 'ajax',
		          url: 'app/LogistMobile_ReportTripCargo.php?load=1',
		          reader: 
		          {
		            type: 'json',
		            root: 'rows',
					totalProperty: 'total'
		          }
		        }
	});
	
	
	
	
	
	
	
	
	
	
	Ext.define('CarsRun_panelReportTripCargo', {
	extend: 'Ext.data.Model',
	fields: [ {name: 'Name'},
	          {name: 'imei'}
	]
	});
	
	var Data_CarsRun_panelReportTripCargo = new Ext.data.Store({
	model: 'CarsRun_panelReportTripCargo',
	proxy: {
		type: 'ajax',
		url: 'scripts/Cars.php',
		reader: {
			type: 'json',
			root: 'rows'
		}
	}
	});

	Ext.define('GroupsRun_panelReportTripCargo', {
	extend: 'Ext.data.Model',
	fields: [ {name: 'id'},
	          {name: 'name'}
	]
	});

	var Data_GroupsRun_panelReportTripCargo = new Ext.data.Store({
	model: 'GroupsRun_panelReportTripCargo',
	proxy: {
		type: 'ajax',
		url: 'scripts/CarsGroups.php',
		reader: {
			type: 'json',
			root: 'rows'
		}
	}
	});
	
	Data_CarsRun_panelReportTripCargo.load();
	Data_GroupsRun_panelReportTripCargo.load();
	
	
	//----------------------------------------------------------------------------------------------------------
	//-----------grid Вибору автомобілів--------------------------------------------------
	var CarsRun_sm = Ext.create('Ext.selection.CheckboxModel');
	var CarsRun_panel_Grid = new Ext.grid.GridPanel({
		border: false,
		height: 180,
		store:Data_CarsRun_panelReportTripCargo,
		autoScroll: true,
		selModel: CarsRun_sm, //або selModel описано після  CarsRun_panel_Grid 
		columns : [

		           {
		        	   //text : 'Название',
		        	   text : reports.name,
		        	   dataIndex : 'Name',
		        	   width:150,
		        	   sortable: true,
		        	   hideable: false

		           },
		           {
		        	   text : 'Imei',
		        	   dataIndex: 'imei',
		        	   width:135,
		        	   sortable: true,
		        	   hideable: false

		           }

		           ], tbar: [{
		        	   xtype: 'textfield',
		        	   id: 'filter_cars_field_run',
		        	   enableKeyEvents: true,
		        	   listeners:  {
		        		   keypress: function(field, e, eOpts) {
		        			   if (e.getKey() == e.ENTER) {
		        				   var filterVal = Ext.getCmp('filter_cars_field_run').getValue();
		        				   filterReportCar(Data_CarsRun_panelReportTripCargo ,filterVal);
		        			   } 

		        		   }
		        	   }
		           }, {
		        	   xtype: 'button',
		        	   //text: 'Фильтровать',
		        	   text: all.filter,
		        	   handler: function() {            		
		        		   var filterVal = Ext.getCmp('filter_cars_field_run').getValue();
		        		   filterReportCar(Data_CarsRun_panelReportTripCargo ,filterVal);
		        	   }
		           }, {
		        	   xtype: 'button',
		        	   //text: 'Сброс',
		        	   text: all.reset,
		        	   handler: function() {
		        		   var filterVal = ''; 
		        		   filterReportCar(Data_CarsRun_panelReportTripCargo ,filterVal);
		        		   Ext.getCmp('filter_cars_field_run').setValue('');
		        	   }
		           }]
	});

	//--------------------------------------------------------------------------------------------
	//-----------grid Вибору групи автомобілів--------------------------------------------------
	var CarsRun_sm2 = Ext.create('Ext.selection.CheckboxModel');
	var CarsRun_Group_panel_Grid = new Ext.grid.GridPanel({
		border: false,
		store: Data_GroupsRun_panelReportTripCargo,
		selModel: CarsRun_sm2, //або selModel2 описано після  CarsRun_Group_panel_Grid
		columns : [

		           {
		        	   //text : 'Название',
		        	   text : reports.name,
		        	   dataIndex : 'id',
		        	   width:170,
		        	   sortable: true,
		        	   hidden:true,
		        	   hideable: false

		           },

		           {
		        	   //text : 'Название',
		        	   text : reports.name,
		        	   dataIndex : 'name',
		        	   width:170,
		        	   sortable: true,
		        	   hideable: false

		           }
		           ]
	});

	//--------------------------------------------------------------------------------------------
	//-----------grid Результату формування звіту--------------------------------------------------
	var CarsRun_groupingFeature = Ext.create('Ext.grid.feature.Grouping',{
		//groupHeaderTpl: 'Cuisine: {name} ({rows.length} Item{[values.rows.length > 1 ? "s" : ""]})'
	});


	//---------------------------------------------------------------------------------------	
	//---------------Поля вибору дати-----------------------------------------
	var CarsRun_date_fields = {
			defaultType: 'datefield',
//			bodyStyle: 'padding: 10 0 0 10',
			bodyStyle: 'padding: 3 0 0 3',
			border: false,
			width: '100%',
			height: 110,
			items: [
			        {
			        	xtype: 'fieldset',
			        	//title: 'Период c',
			        	title: date.from,
			        	defaultType: 'numberfield',
			        	//defaults: { width: 280 },
			        	items: [
			        	        {
			        	        	xtype: 'datefield',	format: 'Y-m-d',  altFormats: 'Y-m-d',startDay: 1,
			        	        	//fieldLabel: 'Период с',
			        	        	labelAlign: 'top', style:'float:left; margin-left:0px;', id: 'Cars_run_startdt', width: 105, value: new Date(), maxValue: new Date(), listeners:{ change: function(newValue, oldValue, eOpts){ Ext.getCmp('Cars_run_enddt').setMinValue( this.getValue() ) }}
			        	        }
			        	        ]
					},
			        	        {
			        	        	xtype: 'fieldset',
			        	        	//title: 'Период по',
			        	        	title: date.to,
			        	        	defaultType: 'numberfield',
			        	        	//defaults: { width: 280 },
			        	        	items: [
			        	        	        {
			        	        	        	xtype: 'datefield', format: 'Y-m-d', altFormats: 'Y-m-d',startDay: 1,
			        	        	        	//fieldLabel: 'Период по',
			        	        	        	labelAlign: 'top', id: 'Cars_run_enddt', style:'float:left; margin-left:0px;', width: 105, value: new Date()
			        	        	        }
			        	        	        ]},

			        	        	        ]
	}	
	//-----------------------------------------------------------------------
	var CarsRun_treePanel = {
			//title: 'Выбор автомобилей',
			region:'north',
			//split: true,

			//height: '34%',
			height: 180,
			width: '100%',
			autoScroll: false,
			items:[CarsRun_panel_Grid]
	};
	var CarsRun_treePanel2 = {
			//title: 'Выбор груп автомобилей',
			title: reports.selecting_a_group_cars,
			region:'north',
			split: true,
			height: '33%',
			width: '100%',
			autoScroll: true,
			collapsible: true,
			items:[CarsRun_Group_panel_Grid]
	};
	var CarsRun_detailsPanel = {
			//title: 'Выбор периода',
			title:  reports.select_period,
			region: 'center',
			split: true,
			height: 110,
			width: '100%',
			autoScroll: true,
			items:[CarsRun_date_fields]
	};
	
	
	
	
	//storeReportReportTripTripCargo.load();
	
	var pagingToolbarReportReportTrip2 = Ext.create('Ext.PagingToolbar', {
        border: false,
        frame: false,
        store: storeReportReportTripTripCargo,
        displayInfo: true
    });
	
	
	var gridReportReportTripTripCargo = new Ext.create('Ext.grid.Panel',{
		    selType: 'rowmodel',
		    columnLines: true,
		    store: storeReportReportTripTripCargo,
		    loadMask: true,
			id: 'ReportTrip2_GridIdTripCargo',
		    border: false,
		    autoScroll: true,
			//bbar:[pagingToolbarReportReportTrip2],
			features: [
			{
				ftype: 'groupingsummary',
				//groupHeaderTpl: '{[values.rows.trade_point]} {name}',//{[values.rows[0].trade_point]}
				groupHeaderTpl: '{[values.rows[0].data["Car"]]} {[values.rows[0].data["Driver"]]}',
				hideGroupedHeader: false,
				//startCollapsed: true,
				enableGroupingMenu: true
			},
			{
                ftype: 'summary',
                    dock: 'bottom'
            }
			],
			viewConfig: {
				enableTextSelection: true
			},
			tbar:[
				/*{
                            xtype: 'datefield',
                            format: 'Y-m-d',
                            altFormats: 'Y-m-d',
                            startDay: 1,
                            fieldLabel: 'Период с',
                            labelAlign: 'left',
                            labelWidth: 60,
                            style:' margin-left:3px;',
                            id: 'ReportTrip2_startdt',
                            width: 165,
                            value: new Date(),
                            maxValue: new Date(),
                            listeners:{
                                change: function(newValue, oldValue, eOpts){

                                }
                            }
                },
                {
                             xtype: 'datefield',
                             format: 'Y-m-d',
                             altFormats: 'Y-m-d',
                             startDay: 1,
                             fieldLabel: 'Период по',
                             labelAlign: 'left',
                             labelWidth: 60,
                             id: 'ReportTrip2_enddt',
                             style:'margin-left:3px;',
                             width: 165,
                             value: new Date()
                },*/
                {
                            text: "Сформировать",
                            //iconCls: 'left-right',
                            //id:'filter_data',
                            handler:function(){
                               
								var date_to =Ext.getCmp('Cars_run_enddt').getRawValue();
								var date_from =Ext.getCmp('Cars_run_startdt').getRawValue();
								date_from = date_from + ' ' + '00:00:00';
								date_to = date_to + ' ' + '23:59:59';
								
								var arr_car = CarsRun_panel_Grid.getSelectionModel().getSelection();
								var arr_group = CarsRun_Group_panel_Grid.getSelectionModel().getSelection();

								var arr_car_temp = [];
								Ext.each(arr_car, function(rec){
								arr_car_temp.push(rec.get('imei'));
								});
						
								var arr_group_temp = [];
								Ext.each(arr_group, function(rec){
								arr_group_temp.push(rec.get('id'));
								});
						
								if(arr_car_temp.length > 0 || arr_group_temp.length > 0){
								
								var str_car = arr_car_temp.join(',');
								var str_group = arr_group_temp.join(',');
							   
							   storeReportReportTripTripCargo.removeAll();
							   
							   storeReportReportTripTripCargo.load({
									params: {
									reportQues_startdt: date_from,
									reportQues_enddt: date_to,
									str_car: str_car,
									str_group: str_group
									
									}
								});
								
								/*storeReportReportTripTripCargo.setProxy({
									type: 'ajax',
									url: 'app/LogistMobile_ReportTripCargo.php?load=1&reportQues_startdt='+date_from+'&reportQues_enddt='+date_to+'&str_car='+str_car+'&str_group'+str_group,
									reader: 
									{
										type: 'json',
										root: 'rows',
										totalProperty: 'total'
									}
								});
								storeReportReportTripTripCargo.load();
								*/
								
								Ext.getCmp('ReportTrip2_GridIdTripCargo').getView().refresh();
								//Ext.getCmp('ReportTrip2_GridIdTripCargo').doLayout();
								
								}else{
									Ext.MessageBox.alert(all.attention, general.you_have_no_the_car_or_group_of_cars);
									return false;
								}
								
								/*storeReportReportTripTripCargo.setProxy({
									type: 'ajax',
									url: 'app/LogistMobile_ReportTripCargo.php?load=1&reportQues_startdt='+Ext.getCmp('ReportTrip2_startdt').getRawValue()+'&reportQues_enddt='+Ext.getCmp('ReportTrip2_enddt').getRawValue(),
									reader: 
									{
										type: 'json',
										root: 'rows',
										totalProperty: 'total'
									}
								});*/
							   
                            }
                },'-',
				{
	  						  text: all.export_xls,
	  						  tooltip: all.export_xls,
	  						  iconCls:'xls',
	  						  handler:function() 
	  						  {
								/*var ArrData=new Array(); 
								var columnCount = modelReportReportTrip2.fields.length;
								//if(Ext.getCmp('ReportTrip2_GridIdTripCargo').store.getCount() > 0){
								if(Ext.getCmp('ReportTrip2_GridIdTripCargo').store.getTotalCount() > 0){
									ArrData = save_table_data(columnCount); 
									export_xls(ArrData,Ext.getCmp('ReportTrip2_startdt').getRawValue(),Ext.getCmp('ReportTrip2_enddt').getRawValue());
								}*/
								
								var date_to = Ext.getCmp('Cars_run_enddt').getRawValue();
								var date_from = Ext.getCmp('Cars_run_startdt').getRawValue();
								date_from = date_from + ' ' + '00:00:00';
								date_to = date_to + ' ' + '23:59:59';
								
								var arr_car = CarsRun_panel_Grid.getSelectionModel().getSelection();
								var arr_group = CarsRun_Group_panel_Grid.getSelectionModel().getSelection();

								var arr_car_temp = [];
								Ext.each(arr_car, function(rec){
								arr_car_temp.push(rec.get('imei'));
								});
						
								var arr_group_temp = [];
								Ext.each(arr_group, function(rec){
								arr_group_temp.push(rec.get('id'));
								});
						
								if(arr_car_temp.length > 0 || arr_group_temp.length > 0){
								
								var str_car = arr_car_temp.join(',');
								var str_group = arr_group_temp.join(',');
								
								export_xls(date_from,date_to,str_car,str_group);
								
								}else{
									Ext.MessageBox.alert(all.attention, general.you_have_no_the_car_or_group_of_cars);
									return false;
								}
								
								
								
								
	  						  }
	  			}
			],
			/*dockedItems: [{
                    dock: 'top',
                    xtype: 'toolbar',
                    items: [{
                        tooltip: 'Toggle the visibility of the summary row',
                        text: 'Toggle Summary',
                        enableToggle: true,
                        showSummaryRow: false,
                        pressed: false,
                        handler: function () {
                            gridReportReportTripTripCargo.lockedGrid.getView().getFeature('group').toggleSummaryRow();
                        }
                    }]
            }],*/
			plugins: [
				{
					ptype: "subtable",
					association: 'cargo',
					headerWidth: 24,
					columns: [
					{
						text: 'Название товара',
						dataIndex: 'Name',
						width: 100
					},
					{
						text: 'Стоимость',
						dataIndex: 'Cost',
						width: 100
					},
					{
						text: 'Объем',
						dataIndex: 'CargoValueVolume',
						width: 100
					},
					{
						text: 'Вес',
						dataIndex: 'CargoValueWeight',
						width: 100
					},
					{
						text: 'Количество',
						dataIndex: 'CargoValueCount',
						width: 100
					},
					{
						text: 'Статус',
						dataIndex: 'State',
						width: 100
					},
					{
						text: 'Коментарий',
						dataIndex: 'Comments',
						width: 100
					}
					]
				}
				/*{
				ptype: 'associationrowexpander',
				getterName: 'actions',
				gridConfig: {
					flex: 1,
					plugins: {
						//ptype: 'cellediting',
						//clicksToEdit: 1
					},
					columns: [
						{
						text: 'Название товара',
						dataIndex: 'Name',
						width: 100
						}
					]
				}
				}*/
				/*{
					ptype: 'rowexpander',
					rowBodyTpl : new Ext.XTemplate(
						'<p><b>Company:</b> {company}</p>',
						'<p><b>Change:</b> {change:this.formatChange}</p><br>',
						'<p><b>Summary:</b> {desc}</p>',
					{
						formatChange: function(v){
							var color = v >= 0 ? 'green' : 'red';
							return '<span style="color: ' + color + ';">' + Ext.util.Format.usMoney(v) + '</span>';
						}
					}
					)
				}*/
			],
			columns:[
			/*{
				xtype: 'checkcolumn', 
				width: 30, 
				dataIndex: 'indoor', 
				hideable: false, 
				sortable: false,
				listeners:
                {
                    checkchange:function(CheckColumn, rowIndex, checked, eOpts )
                    {
						
					}
				}
			},*/
			{
	        	xtype: 'rownumberer',
				width: 30
	        },
			{
				text: 'Маршрут',
				dataIndex: 'fName',
				width: 110,
				summaryRenderer: function(value, summaryData, dataIndex) { return ('Итого:'); }
			},
			{
	        	text: 'Название',
	            dataIndex: 'Name',         
	            width: 200,
	            sortable: true,
				//summaryRenderer: function(value, summaryData, dataIndex) { return ('Итого:'); }
	        },
			{
	        	text: 'Адрес доставки',
	            dataIndex: 'Address',
	            width: 200,
				sortable: true
	        },
			{
	        	text: 'Объект',
	            dataIndex: 'Car',  
				width: 120,
	            sortable: true
	        },
			{
	        	text: 'Водитель',
	            dataIndex: 'Driver',  
				width: 120,
	            sortable: true
	        },
			{
	        	text: 'Начало работы',
	            dataIndex: 'StartWorkTime',  
				width: 120,
	            sortable: true
	        },
			{
	        	text: 'Конец работы',
	            dataIndex: 'EndWorkTime',
	            width: 120,
				sortable: true
	        },
			{
	        	text: 'Время прибытия',
	            dataIndex: 'DELIVERY_DATE_FACT',
	            width: 120,
				sortable: true
	        },
			{
	        	text: 'Время отбытия',
	            dataIndex: 'DELIVERY_OUTDATE_FACT',
	            width: 120,
				sortable: true
	        },
			{
				text: 'Пробег плановый',
				width: 120,
				xtype: 'numbercolumn',
				format:0.00,
				dataIndex: 'Distance',
				//summaryType: 'sum'
				//summaryRenderer: function(value, summaryData, records){
				summaryType: function(records){
							var i = 0;
							var length = records.length;
							var total = 0;
							var record;
							for (; i < length; ++i) {
								record = records[i];
								total += record.get('Distance');
							}
	                
							total = total.toFixed(2);
							return total;
				}
			},
			{
				text: 'Пробег фактический',
				width: 120,
				xtype: 'numbercolumn',
				format:0.00,
				dataIndex: 'DistanceFact',
				summaryType: function(records){
							var i = 0;
							var length = records.length;
							var total = 0;
							var record;
							for (; i < length; ++i) {
								record = records[i];
								total += record.get('DistanceFact');
							}
	                
							total = total.toFixed(2);
							return total;
				}
			},
			{
				text: 'Количество товаров',
				width: 120,
				xtype: 'numbercolumn',
				format:0.00,
				dataIndex: 'CargoValueCount',
				summaryType: function(records){
							var i = 0;
							var length = records.length;
							var total = 0;
							var record;
							for (; i < length; ++i) {
								record = records[i];
								total += record.get('CargoValueCount');
							}
	                
							total = total.toFixed(2);
							return total;
				}
			},
			{
				text: 'Общий вес',
				dataIndex: 'ValueWeight',
				xtype: 'numbercolumn',
				format:0.00,
				summaryType: function(records){
							var i = 0;
							var length = records.length;
							var total = 0;
							var record;
							for (; i < length; ++i) {
								record = records[i];
								total += record.get('ValueWeight');
							}
	                
							total = total.toFixed(2);
							return total;
				}
			},
			{
				text: 'Общий объем',
				dataIndex: 'ValueVolume',
				xtype: 'numbercolumn',
				format:0.00,
				summaryType: function(records){
							var i = 0;
							var length = records.length;
							var total = 0;
							var record;
							for (; i < length; ++i) {
								record = records[i];
								total += record.get('ValueVolume');
							}
	                
							total = total.toFixed(2);
							return total;
				}
			},
			{
				text: 'Общая стоимость',
				xtype: 'numbercolumn',
				format:0.00,
				dataIndex: 'Cost',
				summaryType: function(records){
							var i = 0;
							var length = records.length;
							var total = 0;
							var record;
							for (; i < length; ++i) {
								record = records[i];
								total += record.get('Cost');
							}
	                
							total = total.toFixed(2);
							return total;
				}
			},
			{
	        	text: 'Состояние резерва',
	            dataIndex: 'PointState',
	            width: 130,
				sortable: true
	        },
			{
	        	text: 'Сумма оплаты',
	            dataIndex: 'SumCargo',
	            width:90,
				sortable: true,
				xtype: 'numbercolumn',
				format:0.00,
				//summaryType: 'sum'
				summaryType: function(records){
							var i = 0;
							var length = records.length;
							var total = 0;
							var record;
							for (; i < length; ++i) {
								record = records[i];
								total += record.get('SumCargo');
							}
	                
							total = total.toFixed(2);
							return total;
				}
	        },
			{
	        	text: 'Комментарий курьера',
	            dataIndex: 'DriverComments',
	            width:200,
				sortable: true
	        },
			{
	        	text: 'Заправка',
	            dataIndex: 'FuelVal',
	            width:80,
				sortable: true,
				xtype: 'numbercolumn',
				format:0.00,
				renderer:function(){
				return '-';
				},
				summaryType: function(records){
					//return records[0].get('FuelVal');
				}
	        },
			{
	        	text: 'Показатели одометра 9:00',
	            dataIndex: 'StartOdom',
	            width:80,
				sortable: true,
				xtype: 'numbercolumn',
				format:0.00,
				renderer:function(){
				return '-';
				},
				summaryType: function(records){
					//return records[0].get('StartOdom');
				}
	        },
			{
	        	text: 'Показатели одометра 18:00',
	            dataIndex: 'EndOdom',
	            width:80,
				sortable: true,
				xtype: 'numbercolumn',
				format:0.00,
				renderer:function(){
				return '-';
				},
				summaryType: function(records){
					//return records[0].get('EndOdom');
				}
	        },
			{
	        	text: 'Показатели одометра разница',
	            dataIndex: 'DiffOdom',
	            width:80,
				sortable: true,
				xtype: 'numbercolumn',
				format:0.00,
				renderer:function(){
				return '-';
				},
				summaryType: function(records){
					//return records[0].get('DiffOdom');
				}
	        },
			{
	        	text: 'Оценка',
	            dataIndex: 'InTime',
	            width:80,
				sortable: true
	        }
			],
			listeners: {
				beforeedit: function(editor, ctx, e, eOpts, record)
				{
           
				},
				edit: function(editor, ctx, e, eOpts, record) {
           
				},
				itemdblclick: function(cmp, records) {    		
    		
				}
			}
	});

	
	
        windowReportReportTripCargo = new Ext.Window({
                        width: 800,
                        height: 400,
                        //title: LogistMobile.ReportTrip,
						title: LogistMobile.ReportTripCargo,
                        closeAction: 'destroy',
                        //layout: 'fit',
						layout: 'border',
                        resizable: true,
                        modal: false,
						maximizable: true,
						constrain: true,
						listeners: {
							destroy: function(){
								windowReportReportTripCargo = null;
							}
						},
                        //bodyStyle:{'background-color': '#FFFFFF'},
                 items:[
									{
			            	        	 //title: 'Параметры формирования отчета',
			            	        	 //title: 'Выбор автомобилей',
			            	        	 title: reports.choosing_cars,
			            	        	 layout: 'border',
			            	        	 //border: false,
			            	        	 //split: false,
			            	        	 region:'west',
			            	        	 margins: '5 0 5 5',
			            	        	 //cmargins: '5 5 5 5',
			            	        	 width: 325,
			            	        	 //minSize: '40%',
			            	        	 //maxSize: '40%',
			            	        	 items:[CarsRun_treePanel, CarsRun_treePanel2, CarsRun_detailsPanel]			
			            	         },
			            	         {
			            	        	 //title: 'Результаты отчета',
			            	        	 title:  reports.report_results,
			            	        	 layout: 'fit',
			            	        	 collapsible: false,
			            	        	 region:'center',
			            	        	 margins: '5 5 5 0',
			            	        	 items:[gridReportReportTripTripCargo]
			            	         }
					//gridReportReportTripTripCargo
				 ]
                     

        });    
         
    }
    windowReportReportTripCargo.show();
	
	
function save_table_data(ColumsCount)
{
	var ColumnsArray = new Array(); 
	var i=0;
	console.log(modelReportReportTrip2.fields);
	
	ColumsCount = ColumsCount - 1;
	
	Ext.getCmp('ReportTrip2_GridIdTripCargo').store.each(function(rec){
				//var j=1;
				var k=0;
				Str='';
				while (k<ColumsCount)
				{
					console.log(modelReportReportTrip2.fields[k].name);
					//Str += rec.get('result_'+j)+'/n';
					Str += rec.get(''+modelReportReportTrip2.fields[k].name)+'/n';
					//j++;
					k++;
				}
				ColumnsArray[i]=Str;
				i++;
	});
	return ColumnsArray;
}

function export_xls(reportQues_startdt,reportQues_enddt,str_car,str_group)
{
	$.post("app/LogistMobile_ReportTripCargo.php",{load:1,export_xls:1,reportQues_startdt:reportQues_startdt,reportQues_enddt:reportQues_enddt,str_group:str_group,str_car:str_car}, function(data){
		window.open('app/LogistMobile_ReportTripCargo.php?func=SaveExportData', '_blank');
		
	});
}
	
}