/******************************************************************************
* gshpCommonManagerClasses.js
*******************************************************************************
Classes communes utilisees par le price et basket manager
*******************************************************************************
*******************************************************************************
*                                                                             *
* Copyright 2008								                          *
*                                                                             *
******************************************************************************/

//
// ------------------------------------- class GshpBasket
//
function GshpBasket(oid, typeOid, label)
{
	this.oid 		= oid;
	this.typeOid 	= typeOid;
	this.label 		= label;
	this.nbItems	= null;
	this.quantity	= null;
	this.amount		= null;
	this.vatAmount	= null;
	this.basketItems= new Object();
}

GshpBasket.prototype.setCount = function(nbItems, quantity)
{
	this.nbItems	= nbItems;
	this.quantity	= quantity;
}

GshpBasket.prototype.setAmount = function(amount, vatAmount)
{
	this.amount		= amount;
	this.vatAmount	= vatAmount;
}

GshpBasket.prototype.addBasketItem = function(type, record)
{
	var basketItem = new GshpBasketItem();
	if (basketItem != null) {
		basketItem.init(type, record);
		this.basketItems[basketItem.oid] = basketItem;
	}
	return basketItem;
}


//
// ------------------------------------- class GshpBasketItem
//
function GshpBasketItem()
{
	this.type = "";
	this.isInit = false;

	// Standard data
	this.oid 			= "";
	this.referenceOid 	= "";
	this.productOid 	= "";
	this.sector 		= "";

	this.quantity		= 0;
	this.byHowMuch		= 1;
	this.minimalQuantity= 1;
	this.isIntangible	= false;

	this.creationDate 	= 0;

	// Avanced data
	this.code 			= null;
	this.label 			= null;
	this.customization	= null;

	this.vatRate 		= null;
	this.basePrice		= null;
	this.baseVatPrice 	= null;
	this.refPrice		= null;
	this.refVatPrice 	= null;
	this.price			= null;
	this.vatPrice 		= null;
	this.ecoTax			= null;

	this.clientDiscountPercentage	= null;
	this.unitClientDiscountAmount	= null;
	this.unitClientDiscountVatAmount= null;

	this.packOid 					= null;
	this.clientPackId				= null;
	this.packDiscountPercentag		= null;
	this.unitPackDiscountAmount		= null;
	this.unitPackDiscountVatAmount	= null;

	this.priceSystemCombination		= null;
	this.customRate					= null;
	this.discount					= null;

	this.totalPrice		= null;
	this.totalVatPrice 	= null;
}

//	-------------------------------------------------------------------------
//	Init
//	-------------------------------------------------------------------------
GshpBasketItem.prototype.init = function(type, record)
{
	this.type = type;
	if (type == "B2C") {
		if (record.length >= 30 ) {
			this.oid 			= record[0];
			this.referenceOid 	= record[1];
			this.productOid 	= record[2];

			this.quantity		= parseInt(record[3], 10);
			this.byHowMuch		= parseInt(record[4], 10);
			this.minimalQuantity= parseInt(record[5], 10);
			this.isIntangible	= (record[6] == 'true');

			this.creationDate 	= parseFloat(record[7]);

			this.isDownloadable = (record[8] == 'true');

			this.code 			= unescape(record[9]);
			this.label 			= unescape(record[10]);
			this.customization	= unescape(record[11]);

			this.vatRate 		= parseFloat(record[12]);
			this.basePrice		= parseFloat(record[13]);
			this.baseVatPrice 	= parseFloat(record[14]);
			this.refPrice		= parseFloat(record[15]);
			this.refVatPrice 	= parseFloat(record[16]);
			this.price			= parseFloat(record[17]);
			this.vatPrice 		= parseFloat(record[18]);
			this.ecoTax			= parseFloat(record[19]);

			this.clientDiscountPercentage	= parseFloat(record[20]);
			this.unitClientDiscountAmount	= parseFloat(record[21]);
			this.unitClientDiscountVatAmount= parseFloat(record[22]);

			this.packOid 					= record[23];
			this.clientPackId				= record[24];
			this.packDiscountPercentage		= parseFloat(record[25]);
			this.unitPackDiscountAmount		= parseFloat(record[26]);
			this.unitPackDiscountVatAmount	= parseFloat(record[27]);

			this.totalPrice		= parseFloat(record[28]);
			this.totalVatPrice 	= parseFloat(record[29]);

			this.isInit = true;
		}
	}
	else
	if (type == "B2B") {
		if (record.length >= 24) {
			this.oid 			= record[0];
			this.referenceOid 	= record[1];
			this.productOid 	= record[2];
			this.sector 		= unescape(record[3]);

			this.quantity		= parseInt(record[4], 10);
			this.byHowMuch		= parseInt(record[5], 10);
			this.minimalQuantity= parseInt(record[6], 10);
			this.isIntangible	= (record[7] == 'true');

			this.creationDate 	= parseFloat(record[8]);

			this.isDownloadable = (record[9] == 'true');

			this.code 			= unescape(record[10]);
			this.label 			= unescape(record[11]);
			this.customization	= unescape(record[12]);

			this.vatRate 		= parseFloat(record[13]);
			this.basePrice		= parseFloat(record[14]);
			this.baseVatPrice 	= parseFloat(record[15]);
			this.price			= parseFloat(record[16]);
			this.vatPrice 		= parseFloat(record[17]);
			this.ecoTax			= parseFloat(record[18]);

			this.priceSystemCombination		= record[19];
			this.customRate					= parseFloat(record[20]);
			this.discount					= parseFloat(record[21]);

			this.totalPrice		= parseFloat(record[22]);
			this.totalVatPrice 	= parseFloat(record[23]);

			this.isInit = true;
		}
	}
	return this.isInit;
}
