// <#-- Part Store -->
Ext.define('App.store.OrderStore', {
	extend: 'Ext.data.Store',

	constructor: function(cfg) {
		var me = this;
		cfg = cfg || {};
		me.callParent([Ext.apply({
			proxy: {
				type: 'ajax',
				url: App.url('/order/list.json'),
				extraParams: cfg.extraParams || {},
				reader: {
					type: 'json',
					root: 'records',
					idProperty: 'id'
				}
			},
			fields: [
				{
					name: 'id',
					type: 'int',
					useNull: true
				},
				{
					name: 'code',
					type: 'string'
				},
				{
					name: 'type',
					type: 'string'
				},
				{
					name: "orderNo",
					type: "string",
					convert: function(value, record) {
						return record.get("type")+record.get("code");
					}
				},
				{
					name: "ref",
					type: 'int'
				},
				{
					name: "refNo",
					type: 'string'
				},
				{
					name: "status",
					type: 'int'
				},
				{
					name: 'date',
					type: 'date'
				},
				{
					name: 'custId',
					type: 'int'
				},
				{
					name: 'customerName',
					type: 'string'
				},
				{
					name: 'paymentAmount',
					type: 'float',
					convert: function(value, record){
						return value?value:0;
					}
				},
				{
					name: 'orderAmount',
					type: 'float',
					convert: function(value, record){
						return value?value:0;
					}
				},
				{
					name: "amount",
					type: "string",
					convert: function(value, record) {
						if(record.get("refNo")) return record.get("refNo");
                        return "$"+ Ext.util.Format.number(record.get("orderAmount"), '0,000.00');
					}
				},
				{
					name: 'outstanding',
					type: 'string',
					convert: function(value, record) {
						var outstanding = record.get("orderAmount")-record.get("paymentAmount");
						if(!record.get("refNo") && outstanding>0)
							return " $"+ Ext.util.Format.number(outstanding, '0,000.00');
                        return "";
					}
				},
				{
					name: 'balance',
					type: 'boolean',
					convert: function(value, record) {
						var outstanding = record.get("orderAmount")-record.get("paymentAmount");
						if(!record.get("refNo") && outstanding>0)
							return true;
                        return false;
					}
				},
				{
					name: 'havePayment',
					type: 'boolean',
				},
				{
					name: 'view',
					type: 'boolean',
				},
				{
					name: 'complete',
					type: 'boolean',
				},
				{
					name: 'cancel',
					type: 'boolean',
				},
				{
					name: 'outDate',
					type: 'date',
				},
				{
					name: 'inDate',
					type: 'date',
				},
				{
					name: 'outRemark',
					type: 'string',
				},
				{
					name: 'inRemark',
					type: 'string',
				},
				{
					name: 'inStatus',
					type: 'int',
				},
				{
					name: 'workshopStatus',
					type: 'int',
				},
				{
					name: 'ignoreC',
					type: 'boolean',
				},
				{
					name: 'changeStatus',
					type: 'boolean',
				}
			],
		},
		cfg)]);
	}
});

Ext.define('App.store.OrderComboStore', {
	extend: 'Ext.data.Store',
	autoLoad: true,

	constructor: function(cfg) {
		var me = this;
		cfg = cfg || {};
		me.callParent([Ext.apply({
			proxy: {
				type: 'ajax',
				url: App.url('/order/combo.json'),
				extraParams: cfg.extraParams || {},
				reader: {
					type: 'json',
					root: 'records',
					idProperty: 'id'
				}
			},
			fields: [
				{
					name: 'id',
					type: 'int',
					useNull: true
				},
				{
					name: 'code',
					type: 'string'
				},
				{
					name: 'type',
					type: 'string'
				},
				{
					name: "orderNo",
					type: "string",
					convert: function(value, record) {
						return record.get("type")+record.get("code");
					}
				},
				{
					name: "status",
					type: 'int'
				},
				{
					name: 'custId',
					type: 'int'
				},
				{
					name: 'customerName',
					type: 'string'
				},
			],
		},
		cfg)]);
	}
});

Ext.define('App.store.OrderItemStore', {
	extend: 'Ext.data.Store',

	constructor: function(cfg) {
		var me = this;
		cfg = cfg || {};
		me.callParent([Ext.apply({
			proxy: {
				type: 'ajax',
				url: App.url('/order/item/list.json'),
				extraParams: cfg.extraParams || {},
				reader: {
					type: 'json',
					root: 'records',
					idProperty: 'id'
				}
			},
			fields: [
				{
					name: 'id',
					type: 'int',
					useNull: true
				},
				{
					name: 'name',
					type: 'string'
				},
				{
					name: 'price',
					type: 'float'
				},
			],
		},
		cfg)]);
	}
});

Ext.define('App.store.OrderPaymentStore', {
	extend: 'Ext.data.Store',

	constructor: function(cfg) {
		var me = this;
		cfg = cfg || {};
		me.callParent([Ext.apply({
			proxy: {
				type: 'ajax',
				url: App.url('/order/payment/list.json'),
				extraParams: cfg.extraParams || {},
				reader: {
					type: 'json',
					root: 'records',
					idProperty: 'id'
				}
			},
			fields: [
				{
					name: 'id',
					type: 'int',
					useNull: true
				},
				{
					name: 'date',
					type: 'date'
				},
				{
					name: 'amount',
					type: 'float'
				},
				{
					name: 'method',
					type: 'string'
				},
				{
					name: 'referenceNo',
					type: 'string'
				},
			],
			// data:[
			// 	{id: 1, code: '0001', name:'A Company'},
			// 	{id: 2,code: '0002', name:'B Company'},
			// 	{id: 3,code: '0003', name:'C Company'},
			// 	{id: 4,code: '0004', name:'D Company'},
			// ]
		},
		cfg)]);
	}
});

Ext.define('App.store.OrderLogStore', {
	extend: 'Ext.data.Store',

	constructor: function(cfg) {
		var me = this;
		cfg = cfg || {};
		me.callParent([Ext.apply({
			proxy: {
				type: 'ajax',
				url: App.url('/common/log/order.json'),
				extraParams: cfg.extraParams || {},
				reader: {
					type: 'json',
					root: 'records',
					idProperty: 'date'
				}
			},
			fields: [
				{
					name: 'modified',
					type: 'date',
					dateFormat: 'time'
				},
				{
					name: 'tableName',
					type: 'string'
				},
				{
					name: 'recordId',
					type: 'int'
				},
				{
					name: "modifiedBy",
					type: "int",
				},
				{
					name: "actionStr",
					type: 'string'
				},
				{
					name: "dataStr",
					type: 'string'
				},
				{
					name: "refId",
					type: 'int'
				},
				{
					name: 'refType',
					type: 'string'
				},
				{
					name: 'userName',
					type: 'string'
				},
			],
		},
		cfg)]);
	}
});

Ext.define('App.store.OrderDateRemarksStore', {
	extend: 'Ext.data.Store',
	queryMode: 'local',

	constructor: function(cfg) {
		var me = this;
		cfg = cfg || {};
		me.callParent([Ext.apply({
			fields: [
				{
					name: 'id',
					type: 'int',
					useNull: true
				},
				{
					name: 'code',
					type: 'string'
				},
				{
					name: 'type',
					type: 'string'
				},
				{
					name: "orderNo",
					type: "string",
					convert: function(value, record) {
						return record.get("type")+record.get("code");
					}
				},
				{
					name: "outDate",
					type: 'date'
				},
				{
					name: 'outRemark',
					type: 'string'
				},
				{
					name: "inDate",
					type: 'date'
				},
				{
					name: 'inRemark',
					type: 'string'
				},
			],
		},
		cfg)]);
	}
});


