<?php
session_start();
require_once "../../conf/main.php";
require_once "../../bin/header.php";
require_once "../../bin/fun.php";
require_once "../../pear/html/Template/ITX.php";
require_once "../../pear/DB/DataObject.php";
if(!class_exists('quotation')){ include '../../bin/multi_deco_quotation.php'; }
if(!class_exists('price')){ include 'price_class.php'; }
if(!class_exists('cart')){ include '../../bin/cart.php'; }

$_SESSION["pager_stuff"] = $_SESSION["pager_stuff"];

require("sajax.php");
if(!($_SESSION["user"]["profile"]=="user")){
?>
<script language='javascript'>location.replace('../../www/message/message.php?msg=404error')</script><?	}function ajax_return_cal_values($obj) {
//require_once "price_class.php";
	$obj_array = explode("##",$obj);
	$product_id = $obj_array[0];
	$quantity = $obj_array[1];	
		$obj_price = new price;
		$obj_price->product_line_scd = $product_id;
		$obj_price->quantity = $quantity;
		$obj_price->get_product_price_for_qty_level();		
		$product_unit_price_1 = $obj_price->product_unit_price_1;
		$margin = $obj_price->margin;
		$frieght_marginnewvalue = $obj_price->frieght_marginnewvalue;		
	return $product_unit_price_1."##".$margin."##".$frieght_marginnewvalue;
	}	
function ajax_return_decoration_values($obj2,$method = null) {
//require_once "price_class.php";
	$obj_array = explode("##",$obj2);
	$product_id = $obj_array[0];
	$decoration_id = $obj_array[1];
	$quantity = $obj_array[2];	
		$obj_price2 = new price;
		$obj_price2->product_line_scd = $product_id;
		$obj_price2->decoration_type = $decoration_id;
		$obj_price2->quantity = $quantity;
		$obj_price2->get_decoration_unit_price();
		$decoration_unit_cost = $obj_price2->decoration_unit_price;
		//$logo_setup_unit_price = $obj_price2->logo_setup_charges_per_unit;
		//--update new change --//
		$logo_setup_tot_price = $obj_price2->logo_setup_charges;
	// reset decoration array when changing qty level
	//echo $decoration_id;exit;
		// find details of selected decoration
	if($decoration_id!='') {

/*		if($decoration_id == 'CUSTOM_DECORATION') {
		$selected_decoration_name = "hello";
		$selected_decoration_supplier_scd =	"custom";
		}else{*/

	$objDB_decoration = DB_DataObject::factory("decoration");
	$objDB_decoration->print_type = $decoration_id;
	$objDB_decoration->whereAdd("flag != 0");
	$objDB_decoration->find();
	$objDB_decoration->fetch();

	$selected_decoration_name = $objDB_decoration->name;
	$selected_decoration_supplier_scd = !empty($objDB_decoration->supplier_scd)?$objDB_decoration->supplier_scd:'N/A';
			//}

	if($method !='additional_decoration') {
	unset($_SESSION['custom_cal_decoration_list']);
	}
	
	ajax_insert_new_decoration($selected_decoration_name."@@".$selected_decoration_supplier_scd."@@".$decoration_unit_cost."@@".$logo_setup_tot_price."@@".$decoration_id);			}	return $decoration_unit_cost."##".$logo_setup_tot_price;
	}
/*new ajax function to find and add system decoration to the selected decoration array */
function ajax_add_system_decoration($obj2) {

	$obj_array = explode("##",$obj2);
	$product_id = $obj_array[0];
	$decoration_id = $obj_array[1];
	$quantity = $obj_array[2];

	/*find unit price and logo setup price of selected system decoration */
		$obj_price2 = new price;
		$obj_price2->product_line_scd = $product_id;
		$obj_price2->decoration_type = $decoration_id;
		$obj_price2->quantity = $quantity;
		$obj_price2->get_decoration_unit_price();
		$decoration_unit_cost = $obj_price2->decoration_unit_price;
		$logo_setup_tot_price = $obj_price2->logo_setup_charges;

	if($decoration_id!='') {
	$objDB_decoration = DB_DataObject::factory("decoration");
	$objDB_decoration->print_type = $decoration_id;
	$objDB_decoration->whereAdd("flag != 0");
	$objDB_decoration->find();
	$objDB_decoration->fetch();

	$selected_decoration_name = $objDB_decoration->name;
	$selected_decoration_supplier_scd = !empty($objDB_decoration->supplier_scd)?$objDB_decoration->supplier_scd:'N/A';

	ajax_insert_new_decoration($selected_decoration_name."@@".$selected_decoration_supplier_scd."@@".$decoration_unit_cost."@@".$logo_setup_tot_price."@@".$decoration_id);
			$out = implode('#',array_values($_SESSION['custom_cal_decoration_list']));
	return $out;
}
}

/* new ajax function to store new decoration record */
function ajax_insert_new_decoration($obj1){
//print_r($obj1); exit;
/* new decoration data insert to the php session */
if (!isset($_SESSION['custom_cal_decoration_list'])) {
    $_SESSION['custom_cal_decoration_list'] = array();
}
array_push($_SESSION['custom_cal_decoration_list'],$obj1);
$out = implode('#',array_values($_SESSION['custom_cal_decoration_list']));
//$js_array = json_encode($out);
//echo "var javascript_array = ". $js_array . ";\n";

return $out;

}

function ajax_return_existing_decoration_array(){

	if($_SESSION['custom_cal_decoration_list']) {
$out = implode('#',array_values($_SESSION['custom_cal_decoration_list']));

//$js_array = json_encode((object)$out);
//echo "var javascript_array = ". $js_array . ";\n";
return $out;
	}else{
return 'empty';
	}
}

function ajax_remove_decoration($remove_kay){

	if(($remove_kay!='') && (isset($_SESSION['custom_cal_decoration_list'][$remove_kay]))) {

		unset($_SESSION['custom_cal_decoration_list'][$remove_kay]);
		$_SESSION['custom_cal_decoration_list'] = array_values($_SESSION['custom_cal_decoration_list']);
}
$out = implode('#',$_SESSION['custom_cal_decoration_list']);

	if($_SESSION['custom_cal_decoration_list'].length <=0) {
return $out;
	}else{
return 'empty';
	}


}
function ajax_edit_decoration($edit_kay,$edit_decoration_string){

	if(($edit_kay!='') && (isset($_SESSION['custom_cal_decoration_list'][$edit_kay]))) {

		$_SESSION['custom_cal_decoration_list'][$edit_kay] = $edit_decoration_string;
		//unset($_SESSION['custom_cal_decoration_list'][$edit_kay]);
		$_SESSION['custom_cal_decoration_list'] = array_values($_SESSION['custom_cal_decoration_list']);
}
$out = implode('#',$_SESSION['custom_cal_decoration_list']);

	if($_SESSION['custom_cal_decoration_list'].length <=0) {
return $out;
	}else{
return 'empty';
	}


}
sajax_init();
	// $sajax_debug_mode = 1;
	sajax_export("ajax_return_cal_values");
	sajax_export("ajax_return_decoration_values");
	sajax_export("ajax_insert_new_decoration");
	sajax_export("ajax_add_system_decoration");
	sajax_export("ajax_return_existing_decoration_array");
	sajax_export("ajax_remove_decoration");
	sajax_export("ajax_edit_decoration");
	sajax_handle_client_request();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Price Setup</title><!--<script type="text/JavaScript" src="price_setup_javscripts.js?version=3"></script>--><script type="text/JavaScript" src="formvalidation.js"></script>
<link href="../../conf/css/style.css" rel="stylesheet" type="text/css" />
<link href="price_setup_style.css" rel="stylesheet" type="text/css" /><script type="text/javascript" language="JavaScript">
	<?
	sajax_show_javascript();
	?>	
	browserName=navigator.appName;
	var custom_decoration_added_flag = 'no';

function add_system_decoration() {
	if (document.getElementById('all_decorations').value==' ') {
		alert("Please select a decoration");
		document.getElementById('all_decorations').focus();
		return false;
	}
	system_decoration_code = document.getElementById('all_decorations').value;
	product_id = document.getElementById('product_id_hidden').value;
	product_qty = document.getElementById('main_qty_txt').value;
	
	if(product_qty==''){
		alert("Please add Quantity");
		document.getElementById('main_qty_txt').focus();
	document.getElementById('showstatus2').innerHTML = "Error loading values...!";
		return false;
	}


	x_ajax_add_system_decoration(product_id+"##"+system_decoration_code+"##"+product_qty, do_new_decoration_return);

}
	

function submit_new_decoration(){
	if (document.getElementById('supplier_ref').value=='') {
		alert("Please select a supplier");
		document.getElementById('supplier_ref').focus();
		return false;
	}
	if (document.getElementById('new_decoration_name').value=='') {
		alert("Please add a decoration name");
		document.getElementById('new_decoration_name').focus();
		return false;
	}
	if (document.getElementById('new_decoration_setup_value').value=='') {
		alert("Please add a setup value");
		document.getElementById('new_decoration_setup_value').focus()
		return false;
	}check_numeric(document.getElementById('new_decoration_setup_value'));

	if (document.getElementById('new_decoration_unit_value').value=='') {
		alert("Please add a decoration unit value");
		document.getElementById('new_decoration_unit_value').focus()
		return false;
	}


	check_numeric(document.getElementById('new_decoration_unit_value'));

	new_decoration_name = document.getElementById('new_decoration_name').value;
	new_decoration_supplier_ref = document.getElementById('supplier_ref').value;
	new_decoration_unit_value = document.getElementById('new_decoration_unit_value').value;
	new_decoration_logo_setup_value = document.getElementById('new_decoration_setup_value').value;

	new_decoration_data_string = new_decoration_name+"@@"+new_decoration_supplier_ref+"@@"+new_decoration_unit_value+"@@"+new_decoration_logo_setup_value+"@@"+"CUSTOM_DECORATION";


x_ajax_insert_new_decoration(new_decoration_data_string, do_new_decoration_return);

}
	function do_new_decoration_return(dynamic_decoration_array) {
		//alert(dynamic_decoration_array);
		if(dynamic_decoration_array!=''){
		//alert(dynamic_decoration_array);	
		//var value2= z.split("##");
		if (dynamic_decoration_array && dynamic_decoration_array.length) {
		do_existing_decoration_return(dynamic_decoration_array);
		custom_decoration_added_flag = 'yes';
		}else{
			document.getElementById('showstatus').innerHTML = "Error inserting new decoration...!";
		}				}else{
	document.getElementById('showstatus').innerHTML = "Error inserting new decoration...!";
		}		document.getElementById("defaultOpen").click();
	}


function import_existing_decoration_list() {

	x_ajax_return_existing_decoration_array('all', do_existing_decoration_return);
}

function do_existing_decoration_return(obj_decoration) {
	//alert(obj_decoration)
	var total_decoration_unit_value = 0;
	var total_setup_value = 0;
	if(obj_decoration!='empty' && obj_decoration!=''){

	var obj_decoration_array = obj_decoration.split("#");

	var html_table = "<table class='decoration_table'><tr><th>Decoration</th><th>Unit Cost</th><th>Setup</th><th>Edit</th><th>Remove</th></tr>";
	document.getElementById("dynamic_decoration_list_div").innerHTML = "";

	 for (var I = 0; I < obj_decoration_array.length; I++) {

  	var single_decoration_record_array = obj_decoration_array[I].split("@@");
  		//alert(single_decoration_record_array);
			total_decoration_unit_value += parseFloat(single_decoration_record_array[2]);
			total_setup_value += parseFloat(single_decoration_record_array[3]);
      html_table += "<tr><td>" + (I+1)+') ' + single_decoration_record_array[0] + "</td><td style='text-align:right;'><input type='hidden' name='edit_decoration_name_"+I+"' id='edit_decoration_name_"+I+"' value='" + single_decoration_record_array[0] + "' /><input type='hidden' name='edit_decoration_suppier_scd_"+I+"' id='edit_decoration_suppier_scd_"+I+"' value='" + single_decoration_record_array[1] + "' /><input type='hidden' name='edit_decoration_scd_"+I+"' id='edit_decoration_scd_"+I+"' value='" + single_decoration_record_array[4] + "' /><input readonly class='readonlytext' type='text' name='edit_decoration_line_unit_cost_"+I+"' id='edit_decoration_line_unit_cost_"+I+"' size='7' value=" + isMoney(single_decoration_record_array[2],2) + " /></td><td style='text-align:right;'><input type='text' readonly class='readonlytext' name='edit_decoration_line_setup_cost_"+I+"' id='edit_decoration_line_setup_cost_"+I+"' size='7' value=" + isMoney(single_decoration_record_array[3],2) + " /></td><td><input type='button' value='edit' name='edit_decoration_line_button_"+I+"' id='edit_decoration_line_button_"+I+"' style='padding: 2px 8px;' onclick='edit_decoration("+I+");' /></td><td><input type='button' value='X' name='' id='' style='padding: 2px 8px;' onclick='remove_decoration("+I+");' /></td></tr>";

  }
   html_table += "</table>";
  	document.getElementById("dynamic_decoration_list_div").innerHTML = html_table;

	}else{
	document.getElementById("dynamic_decoration_list_div").innerHTML = '<p></p>No Decorations found!';
	document.getElementById('gp_for_decoration_unit_txt').value ='';
	document.getElementById('gp_for_decoration_tot_txt').value ='';
	}
  	document.getElementById("decoration_cost1_txt").value = isMoney(total_decoration_unit_value,2);
  	document.getElementById("logosetup_tot_txt").value = isMoney(total_setup_value,2);
  	txt_function_chg_decor_cost(document.getElementById("decoration_cost1_txt"));

}

function remove_decoration(obj_remove_key) {
	//alert(obj_remove_key);
	x_ajax_remove_decoration(obj_remove_key, do_existing_decoration_return);

}
var edit_decoration_flag = 'close';

function edit_decoration(obj_edit_key) {

	if(edit_decoration_flag == 'close'){


	document.getElementById('edit_decoration_line_unit_cost_'+obj_edit_key).readOnly = false;
	document.getElementById('edit_decoration_line_setup_cost_'+obj_edit_key).readOnly = false;

	document.getElementById('edit_decoration_line_unit_cost_'+obj_edit_key).style.background = 'white';
	document.getElementById('edit_decoration_line_setup_cost_'+obj_edit_key).style.background = 'white';
	document.getElementById('edit_decoration_line_button_'+obj_edit_key).value = 'save';
	document.getElementById('edit_decoration_line_button_'+obj_edit_key).style.background = "red";



	edit_decoration_flag = 'open';
	}else{
	//save button clicked then save data
	unit_cost_line = document.getElementById('edit_decoration_line_unit_cost_'+obj_edit_key).value;
	setup_cost_line = document.getElementById('edit_decoration_line_setup_cost_'+obj_edit_key).value;
	document.getElementById('edit_decoration_line_button_'+obj_edit_key).value = 'edit';
	document.getElementById('edit_decoration_line_button_'+obj_edit_key).style.background = "#808080";
	document.getElementById('edit_decoration_line_unit_cost_'+obj_edit_key).style.background = '#E4F7EB';
	document.getElementById('edit_decoration_line_setup_cost_'+obj_edit_key).style.background = '#E4F7EB';
	document.getElementById('edit_decoration_line_unit_cost_'+obj_edit_key).readOnly = true;
	document.getElementById('edit_decoration_line_setup_cost_'+obj_edit_key).readOnly = true;
	edit_decoration_flag = 'close';

	new_decoration_name = document.getElementById('edit_decoration_name_'+obj_edit_key).value;
	new_decoration_supplier_ref = document.getElementById('edit_decoration_suppier_scd_'+obj_edit_key).value;
	new_decoration_unit_value = document.getElementById('edit_decoration_line_unit_cost_'+obj_edit_key).value;
	new_decoration_logo_setup_value = document.getElementById('edit_decoration_line_setup_cost_'+obj_edit_key).value;
	new_edit_decoration_scd_value = document.getElementById('edit_decoration_scd_'+obj_edit_key).value;	

	
	//new_decoration_data_string = new_decoration_name+"@@"+new_decoration_supplier_ref+"@@"+new_decoration_unit_value+"@@"+new_decoration_logo_setup_value+"@@"+"CUSTOM_DECORATION";
	new_decoration_data_string = new_decoration_name+"@@"+new_decoration_supplier_ref+"@@"+new_decoration_unit_value+"@@"+new_decoration_logo_setup_value+"@@"+new_edit_decoration_scd_value;
	//alert(new_decoration_data_string);
	x_ajax_edit_decoration(obj_edit_key,new_decoration_data_string, do_existing_decoration_return);
	}

}
function update_markup_using_margin_value(obj,obj2){
	margin_value = parseInt(obj);
	retail_lavel = 100;
	buffer_value = retail_lavel - margin_value;
	markup_percentage = ((retail_lavel / buffer_value)-1);
	markup_value = isMoney(((100 + markup_percentage*100)/100),2);
	
	document.getElementById(obj2).value = markup_value;
	
	call_item_markup();
	cal_decoration_markup();
	cal_final_unit_price_ex_vat();
	cal_final_unit_price_inc_vat();
	cal_total_gp();
}
function submitform(){
//this.parent.showHide("fruit1","fruitspan1");

this.parent.document.getElementById("display_output_div").innerHTML = "<center><span style=\'color:#B61A1A;\'><b>Order is processing. Please wait...</b>&nbsp;<img src='../../conf/images/loading1.gif' id='loading2' name='loading2' /></span></center><br/>";
	this.parent.document.getElementById("loading2").style.width ="16px";
	this.parent.document.getElementById("loading2").style.height ="16px";
	this.parent.document.getElementById("loading2").style.margin ="0";
	this.parent.document.getElementById("loading2").style.padding ="0";
	this.parent.document.getElementById("loading2").style.border ="0";
	this.parent.document.getElementById("loading2").style.verticalAlign ="middle";
	
	if (browserName!="Netscape")
	{ 
	parent.window.scrollTo(0,0);
	}

	return true;
}
	
	function callajax(){
	document.getElementById('showstatus').innerHTML = "Loading values. Please wait.....";
	
	product_id = document.getElementById('product_id_hidden').value;
	product_qty = document.getElementById('qty_level_hidden').value;
	
	//alert(product_id+"##"+product_qty);
		x_ajax_return_cal_values(product_id+"##"+product_qty, do_ajax_return);
	}
	
	function do_ajax_return(z) {
		
		//alert(z);
		if(z!=''){
		var value2= z.split("##");	
			
	document.getElementById('item_cost1_txt').value = isMoney(value2[0], 2);
	document.getElementById('markup_price1_txt').value = value2[1];
	//pass product markup for decoration markup as well
	document.getElementById('decoration_markup_decimal').value = value2[1];
	if(value2[2] > 0){
	document.getElementById('freight_total_cost_input').value = value2[2];
	}
	// display new margin percentage value 18-12-2018 % //
	markup_decimal_value = value2[1];
	hold_value = markup_decimal_value * 100;
	hold_value2 = hold_value - 100;
	new_margin_percentate = (hold_value2/markup_decimal_value).toFixed();
	//alert(new_margin_percentate);
	document.getElementById('markup').options[new_margin_percentate-1].selected = 'selected';

	update_margin_percentage_new(document.getElementById('decoration_markup_decimal'),'decoration_markup_percentage');

	cal_unit_marginfrgt_setup();
	document.getElementById('showstatus').innerHTML = "";
	call_item_markup();
	if ((document.getElementById("dynamic_decoration_list_div").innerHTML == "<p></p>No Decorations found!") || (document.getElementById("dynamic_decoration_list_div").innerHTML == '') ||(custom_decoration_added_flag != 'yes' )) {
	if(document.getElementById('decoraton_type_hidden').value!=''){
		load_decoration_levels_ajax(document.getElementById('decoraton_type_hidden').value);
	}			}else{
		cal_decoration_markup();
	}
	
	cal_unit_logo_setup();

	cal_final_unit_price_ex_vat();
	cal_final_unit_price_inc_vat();
	cal_total_gp();
		}else{
	document.getElementById('showstatus').innerHTML = "Error loading values...!";
		}
	}
	
function load_decoration_levels_ajax(obj){
	document.getElementById('showstatus2').innerHTML = "Loading values. Please wait.....";
	product_id = document.getElementById('product_id_hidden').value;
	product_qty = document.getElementById('main_qty_txt').value;
	document.getElementById('decoraton_type_hidden').value = obj;
	if(product_qty==''){
		alert("Please add Quantity");
		document.getElementById('main_qty_txt').focus();
	document.getElementById('showstatus2').innerHTML = "Error loading values...!";
		return false;
	}		x_ajax_return_decoration_values(product_id+"##"+obj+"##"+product_qty, do_ajax_return_2);
}

	function do_ajax_return_2(z) {
		if(z!=''){
		var value2= z.split("##");	
	document.getElementById('decoration_cost1_txt').value = isMoney(parseFloat(value2[0]),2);
	document.getElementById('logosetup_tot_txt').value = isMoney(parseFloat(value2[1]),2);
	
	document.getElementById('decoraton_multi_prices_array_hidden').value = value2[2];
	document.getElementById('decoraton_multi_logosetup_array_hidden').value = value2[3];

	document.getElementById('showstatus2').innerHTML = '';
	if(document.getElementById('decoration_cost1_txt').value ==''){
	reset_all_decoration_fields();	
	}
	cal_unit_marginfrgt_setup();	
	cal_decoration_markup();	cal_unit_logo_setup();
	
	cal_final_unit_price_ex_vat();
	cal_final_unit_price_inc_vat();
	cal_total_gp();
		}else{
	document.getElementById('showstatus2').innerHTML = "Error loading values...!";
		}
	import_existing_decoration_list();	
	}
function update_margin_percentage_new(obj,obj2){

	check_numeric(obj);
	markup_decimal_value = obj.value;
	hold_value = markup_decimal_value * 100;
	hold_value2 = hold_value - 100;
	new_margin_percentate = (hold_value2/markup_decimal_value).toFixed();

	document.getElementById(obj2).options[new_margin_percentate-1].selected = 'selected';
}
function reset_all_decoration_fields(){
	document.getElementById('decoration_markup_txt').value ='';
	document.getElementById('gp_for_decoration_unit_txt').value ='';
	document.getElementById('gp_for_decoration_tot_txt').value ='';
}	
		
//---update new requirement cal unit value of logo setup from total value (24-04-2010) --//
function cal_unit_logo_setup(){
	check_numeric(document.getElementById('logosetup_tot_txt'));
	  logosetup_unit_txt = (parseFloat(document.getElementById('logosetup_tot_txt').value)/parseFloat(document.getElementById('main_qty_txt').value));
	  document.getElementById('logosetup_unit_txt').value = isMoney(logosetup_unit_txt,2);
	  // calculate new logo setup markup value 20-09-2018 for QCA
	  	logo_setup_markup = 0;

	  	check_numeric(document.getElementById('logo_setup_markup_decimal'));
	  	logo_setup_markup_percentage = parseFloat(document.getElementById('logo_setup_markup_decimal').value);
	   logo_setup_markup = ((100 + logo_setup_markup_percentage)/100);

	  // display fright markup only value. only for display purpose
	  logo_setup_markup_only = isMoney(((logosetup_unit_txt/100) * logo_setup_markup_percentage),2);
	  //logo_setup_markup_only = isMoney((parseFloat((parseFloat(logosetup_unit_txt)*parseFloat(logo_setup_markup)))-logosetup_unit_txt),2);

	  document.getElementById('logo_setup_with_markup_txt').value = isMoney(parseFloat((parseFloat(logosetup_unit_txt)*parseFloat(logo_setup_markup_percentage))),2);

	  document.getElementById('logo_setup_markup_only_value_total_txt').value = isMoney((parseFloat(document.getElementById('logo_setup_with_markup_txt').value) * parseFloat(document.getElementById('main_qty_txt').value)),2);	  
	cal_final_unit_price_ex_vat();
	cal_final_unit_price_inc_vat();
	cal_total_gp();
}	
	
function call_item_markup(){
	if((document.getElementById('markup_price1_txt').value !='')&& (document.getElementById('item_cost1_txt').value !='')){

	  markup_price1_txt = document.getElementById('markup_price1_txt');
	  item_cost1_txt = document.getElementById('item_cost1_txt');
		check_numeric(markup_price1_txt);
		check_numeric(item_cost1_txt);
		
		document.getElementById('item_markup_txt').value = isMoney(parseFloat((parseFloat(markup_price1_txt.value)*parseFloat(item_cost1_txt.value))),2);		update_margin_percentage_new(document.getElementById('markup_price1_txt'),'markup');
	}cal_unit_marginfrgt_setup();
}

function cal_decoration_markup(){// update this function and included new decoration markup seperate field(decoration_markup_decimal) . earlier it took product markup field(markup_price1_txt)

	if((document.getElementById('decoration_markup_decimal').value !='')&& (document.getElementById('decoration_cost1_txt').value !='')){		
	  decoration_markup_decimal = document.getElementById('decoration_markup_decimal');
	  decoration_cost1_txt = document.getElementById('decoration_cost1_txt');
		check_numeric(decoration_markup_decimal);
		check_numeric(decoration_cost1_txt);		
	document.getElementById('decoration_markup_txt').value = isMoney(parseFloat((parseFloat(decoration_markup_decimal.value)*parseFloat(decoration_cost1_txt.value))),2);	update_margin_percentage_new(document.getElementById('decoration_markup_decimal'),'decoration_markup_percentage');
	}
	cal_unit_logo_setup();
}

function cal_unit_marginfrgt_setup(){

	check_numeric(document.getElementById('freight_total_cost_input'));
	if(document.getElementById('freight_total_cost_input').value==''){
	//document.getElementById('marginfreight_unit_txt').value = document.getElementById('freight_rate_txt').value;
	}else{
	  marginfreight_unit_txt = (parseFloat(document.getElementById('freight_total_cost_input').value)/parseFloat(document.getElementById('main_qty_txt').value));
	  document.getElementById('marginfreight_unit_txt').value = isMoney(marginfreight_unit_txt,2);

	  // calculate new fright markup value 20-09-2018 for QCA

	  freight_markup = 0;

	  check_numeric(document.getElementById('freight_markup_decimal'));
	  freight_markup_percentage = parseFloat(document.getElementById('freight_markup_decimal').value);
	  
	  freight_markup = ((100 + freight_markup_percentage)/100);

	  // display fright markup only value. only for display purpose
	  freight_markup_only = isMoney(((marginfreight_unit_txt/100) * freight_markup_percentage),2);

	  document.getElementById('freight_with_markup_txt').value = isMoney(parseFloat((parseFloat(marginfreight_unit_txt)*parseFloat(freight_markup_percentage))),2);

	  document.getElementById('freight_with_markup_total_txt').value = isMoney((parseFloat(document.getElementById('freight_with_markup_txt').value) * parseFloat(document.getElementById('main_qty_txt').value)),2);
	}

	cal_final_unit_price_ex_vat();
	cal_final_unit_price_inc_vat();
	cal_total_gp();

}	


function txt_function_chg_item_cost(obj){
	check_numeric(obj);
	call_item_markup();
	cal_final_unit_price_ex_vat();
	cal_final_unit_price_inc_vat();
	cal_total_gp();
}
function txt_function_chg_decor_cost(obj){
	check_numeric(obj);
	cal_decoration_markup();
	cal_final_unit_price_ex_vat();
	cal_final_unit_price_inc_vat();
	cal_total_gp();
}

function txt_function_chg_markup_rate(obj,obj2){

	update_margin_percentage_new(obj,obj2);
	check_numeric(obj);
	call_item_markup();
	cal_decoration_markup();
	cal_final_unit_price_ex_vat();
	cal_final_unit_price_inc_vat();
	cal_total_gp();
}

function update_qty(obj){
	check_numeric(obj);
	cal_unit_marginfrgt_setup();
	
	cal_unit_logo_setup();
	cal_final_unit_price_ex_vat();
	cal_final_unit_price_inc_vat();
	cal_total_gp();
}
function txt_freight_value_change(obj){
	check_numeric(obj);
	cal_final_unit_price_ex_vat();
	cal_final_unit_price_inc_vat();
	cal_total_gp();
}


function txt_add_extra_change(obj){
	check_numeric(obj);
	cal_final_unit_price_ex_vat();
	cal_final_unit_price_inc_vat();
	cal_total_gp();
}

function cal_final_unit_price_ex_vat(){
	  item_markup_txt = document.getElementById('item_markup_txt');

	  marginfreight_unit_txt = document.getElementById('marginfreight_unit_txt');
	  // new update calling fright with markup value requested by QCA 20-09-2018
	  if (document.getElementById('freight_with_markup_txt').value !='' && document.getElementById('freight_with_markup_txt').value >0) {
	  	marginfreight_unit_txt = document.getElementById('freight_with_markup_txt');
	  }

	  

	  decoration_markup_txt = document.getElementById('decoration_markup_txt');
	  logosetup_unit_txt = document.getElementById('logosetup_unit_txt');		if (document.getElementById('logo_setup_with_markup_txt').value !='' && document.getElementById('logo_setup_with_markup_txt').value >0) {
		logosetup_unit_txt = document.getElementById('logo_setup_with_markup_txt');
		}
	  
	  main_qty_txt = document.getElementById('main_qty_txt');
	check_numeric(item_markup_txt);
	check_numeric(decoration_markup_txt);
	
	if(item_markup_txt.value=='')
	item_markup_txt.value =0;

	if(marginfreight_unit_txt.value=='')
	marginfreight_unit_txt.value =0;
		
	if(decoration_markup_txt.value=='')
	decoration_markup_txt.value =0;
	
	if(logosetup_unit_txt.value=='')
	logosetup_unit_txt.value =0;
	
	if(main_qty_txt.value=='')
	main_qty_txt.value =0;

	//if(document.getElementById('extra_charge_txt').value!=''){
	//addtional_charge = document.getElementById('extra_charge_txt').value;	
	//}else{
	addtional_charge = 0;	
	//}
	
	//--- updated (if costomer discount found then add customer discount value into markup value) ---//
	discount_value = 0;
	if((document.getElementById('client_discount_txt').value!='') && (parseFloat(document.getElementById('client_discount_txt').value)>0)){
	check_numeric(document.getElementById('client_discount_txt'));
	client_discount_txt_value = document.getElementById('client_discount_txt').value;	
	
	discount_value = isMoney(parseFloat(item_markup_txt.value) - (parseFloat(item_markup_txt.value) * parseFloat(client_discount_txt_value) / 100),2);
	}else{
	discount_value = item_markup_txt.value;
	}
	discount_value = isMoney(parseFloat(discount_value) + parseFloat(marginfreight_unit_txt.value),2);
	
	//--cal normal freight rate for each product and decoration (03-04-2012) edited --//
	new_product_price_before_freight = discount_value;
	
	freight_rate_txt = document.getElementById('freight_rate_txt');
	freight_rate_txt_value = freight_rate_txt.value;
	if(freight_rate_txt_value==1)freight_rate_txt_value=0;

	  if((freight_rate_txt_value !='') && (parseFloat(freight_rate_txt_value) !=0)){
		 
	freight_with_unit_val_for_product = isMoney((parseFloat(new_product_price_before_freight)*parseFloat(freight_rate_txt_value))- parseFloat(new_product_price_before_freight),2);
	}else{
	freight_with_unit_val_for_product = 0;	
	}
	new_product_unit_ex_price = isMoney(parseFloat(new_product_price_before_freight) + parseFloat(freight_with_unit_val_for_product),2); 
	
	//--- cal decoration with freight --//
	if((decoration_markup_txt.value !='') && (parseFloat(decoration_markup_txt.value) >=0)){
	new_deco_price_before_freight = parseFloat(decoration_markup_txt.value);
	
	if((logosetup_unit_txt.value !='') && (parseFloat(logosetup_unit_txt.value) !=0)){
	new_deco_price_before_freight = isMoney(parseFloat(decoration_markup_txt.value)+parseFloat(logosetup_unit_txt.value),2);
	}
	
	  if((freight_rate_txt_value !='') && (parseFloat(freight_rate_txt_value) !=0)&& (new_deco_price_before_freight !=0)){
	freight_with_unit_val_for_decoration = isMoney((parseFloat(new_deco_price_before_freight)*parseFloat(freight_rate_txt_value))- parseFloat(new_deco_price_before_freight),2);
	}else{
	freight_with_unit_val_for_decoration = 0;	
	}
	
	if(new_deco_price_before_freight !=0){
	new_decoration_unit_ex_price = isMoney(parseFloat(new_deco_price_before_freight) + parseFloat(freight_with_unit_val_for_decoration),2); 
	}else{
	new_decoration_unit_ex_price =0;	
	}

	}else{
	new_decoration_unit_ex_price =0;	
	}
	
	document.getElementById('sell_price_ex_txt').value = isMoney(parseFloat(new_product_unit_ex_price) + parseFloat(new_decoration_unit_ex_price),2);
	document.getElementById('sell_price_ex_txt_hidden').value = document.getElementById('sell_price_ex_txt').value;
	
	//alert("result: product wi margin: "+new_product_price_before_freight+" deco_with_margin: "+new_deco_price_before_freight+" freight rate: "+freight_rate_txt_value+"");
	//---------------------end new update 03-04-2012-----------------------------//
	
	//--- call freight price old function disabled from 03-04-2012 update--//
	//document.getElementById('sell_price_ex_txt').value = isMoney(parseFloat((parseFloat(discount_value)+parseFloat(decoration_markup_txt.value)+parseFloat(logosetup_unit_txt.value))+ parseFloat(addtional_charge)),2);
	//alert('marginvalue '+item_markup_txt.value+' withfreight '+document.getElementById('sell_price_ex_txt').value);
	//cal_price_with_freight_vat();
	
	sell_price_ex_txt = document.getElementById('sell_price_ex_txt');
	document.getElementById('sell_price_ex_tot_txt').value = isMoney(parseFloat(parseFloat(sell_price_ex_txt.value)* main_qty_txt.value) ,2);
	
}
function cal_price_with_freight_vat(){
	  freight_rate_txt = document.getElementById('freight_rate_txt');
	  	freight_rate_txt_value = freight_rate_txt.value;

	  	if(freight_rate_txt_value==1)freight_rate_txt_value=0;

	  if((freight_rate_txt_value !='') && (parseFloat(freight_rate_txt_value) !=0)){
		 
	  sell_price_ex_txt = document.getElementById('sell_price_ex_txt');
	  sell_price_ex_tot_txt = document.getElementById('sell_price_ex_tot_txt');
	  
	freight_with_unit_val = (parseFloat(sell_price_ex_txt.value)*parseFloat(freight_rate_txt_value))- parseFloat(sell_price_ex_txt.value);
	
	  }else{
	freight_with_unit_val = 0;
		  
	  }
	document.getElementById('sell_price_ex_txt').value = isMoney(parseFloat(document.getElementById('sell_price_ex_txt').value) + freight_with_unit_val,2); 	document.getElementById('sell_price_ex_txt_hidden').value = document.getElementById('sell_price_ex_txt').value;}function cal_final_unit_price_inc_vat(){
	  tax_rate_txt = document.getElementById('tax_rate_txt');
	  sell_price_ex_txt = document.getElementById('sell_price_ex_txt');
	  sell_price_ex_tot_txt = document.getElementById('sell_price_ex_tot_txt');
	  sell_price_inc_txt = document.getElementById('sell_price_inc_txt');
	  
	  main_qty_txt = document.getElementById('main_qty_txt');
	  
	  if(main_qty_txt.value=='')
		main_qty_txt.value =0;
	  
	document.getElementById('sell_price_inc_txt').value = isMoney(parseFloat((parseFloat(sell_price_ex_txt.value)*parseFloat(tax_rate_txt.value))),2);
	sell_price_inc_txt = document.getElementById('sell_price_inc_txt');
	document.getElementById('sell_price_inc_tot_txt').value = isMoney(parseFloat(parseFloat(sell_price_inc_txt.value)* main_qty_txt.value) ,2);
	
}

		
function pass_price_to_field(value){


//	if (!"<?php echo $_POST['add_n_reopen']?>") {
//
//	}else{
//		return;
//	}
	var value2= value.split("##");
	//--- pass qty level to hidden field --//
	document.getElementById('qty_level_hidden').value = value2[0];
	//----pass qty qty field , --//
	document.getElementById('main_qty_txt').value = value2[0];
	callajax();
	
}
function cal_total_gp(){
	//--cal gp for item --//
	item_markup_txt = document.getElementById('item_markup_txt').value;
	item_cost1_txt = document.getElementById('item_cost1_txt').value;
	main_qty_txt = document.getElementById('main_qty_txt').value;	
	item_gp_for_unit = item_markup_txt-item_cost1_txt;
	item_gp_for_total = parseFloat(item_gp_for_unit*main_qty_txt);	
	//--cal gp for decoration --//
	decoration_markup_txt = document.getElementById('decoration_markup_txt').value;
	decoration_cost1_txt = document.getElementById('decoration_cost1_txt').value;	
	decoration_gp_for_unit = decoration_markup_txt-decoration_cost1_txt;
	decoration_gp_for_total = parseFloat(decoration_gp_for_unit*main_qty_txt);


	//--- new 20-09-2018 calculate GP for new product freight markup value (for QCA) --//
	freight_with_markup_txt = document.getElementById('freight_with_markup_txt').value;
	marginfreight_unit_txt = document.getElementById('marginfreight_unit_txt').value;

	freight_markup_percentage = parseFloat(document.getElementById('freight_markup_percentage').value);
	freight_with_markup_gp_for_unit = isMoney(((marginfreight_unit_txt/100) * freight_markup_percentage),2);	
	//freight_with_markup_gp_for_unit = freight_with_markup_txt-marginfreight_unit_txt;
	
	freight_with_markup_gp_for_total = parseFloat(freight_with_markup_gp_for_unit*main_qty_txt);

		if (freight_with_markup_gp_for_unit <= 0) {
	document.getElementById('gp_for_freight_markup_unit_txt').value = 0;
	document.getElementById('gp_for_freight_markup_tot_txt').value = 0;
		}else {
	document.getElementById('gp_for_freight_markup_unit_txt').value = isMoney(freight_with_markup_gp_for_unit,2);
	document.getElementById('gp_for_freight_markup_tot_txt').value = isMoney(freight_with_markup_gp_for_total,2);
		}



	//--- new 20-09-2018 calculate GP for new logo setup markup value (for QCA) --//

	logo_setup_with_markup_txt = document.getElementById('logo_setup_with_markup_txt').value;
	logosetup_unit_txt = document.getElementById('logosetup_unit_txt').value;
	logo_setup_markup_percentage = parseFloat(document.getElementById('logo_setup_markup_percentage').value);
	logo_setup_with_markup_gp_for_unit = isMoney(((logosetup_unit_txt/100) * logo_setup_markup_percentage),2);
	//logo_setup_with_markup_gp_for_unit = logo_setup_with_markup_txt-logosetup_unit_txt;
	logo_setup_with_markup_gp_for_total = parseFloat(logo_setup_with_markup_gp_for_unit*main_qty_txt);

	if (logo_setup_with_markup_gp_for_unit <= 0) {
	document.getElementById('gp_for_setup_markup_unit_txt').value = 0;
	document.getElementById('gp_for_setup_markup_tot_txt').value = 0;
	}else {
	document.getElementById('gp_for_setup_markup_unit_txt').value = isMoney(logo_setup_with_markup_gp_for_unit,2);
	document.getElementById('gp_for_setup_markup_tot_txt').value = isMoney(logo_setup_with_markup_gp_for_total,2);
	}


	// -- calculate total GP -- //
	//total_gp_of_item_and_decoration = isMoney(parseFloat(item_gp_for_total + decoration_gp_for_total),2);

	//--new total after adding product freight markup and logo setup markup gps 20-09-2018 - QCA request --//
	total_gp_of_item_and_decoration = isMoney(parseFloat(item_gp_for_total + decoration_gp_for_total + freight_with_markup_gp_for_total + logo_setup_with_markup_gp_for_total),2);

	
	//document.getElementById('total_gp_txt').value = total_gp_of_item_and_decoration;	
	document.getElementById('total_gp_txt').value = total_gp_of_item_and_decoration;	
	//--cal GP percentage% value -- (added 16-04-2010)
	//--calculate gp for product (GP Information on Product)
	item_markup_txt_value = document.getElementById('item_markup_txt').value;
	item_cost1_txt_value = document.getElementById('item_cost1_txt').value;	
	decoration_markup_txt_value = document.getElementById('decoration_markup_txt').value;
	decoration_cost1_txt_value = document.getElementById('decoration_cost1_txt').value;	
	gp_for_product_unit_txt_value = item_markup_txt_value-item_cost1_txt_value;
	gp_for_decoration_unit_txt_value = decoration_markup_txt_value-decoration_cost1_txt_value;			//-- gp for product -//	document.getElementById('gp_for_product_unit_txt').value = isMoney(gp_for_product_unit_txt_value,2);
	document.getElementById('gp_for_product_tot_txt').value = isMoney((isMoney(gp_for_product_unit_txt_value,2) * document.getElementById('main_qty_txt').value),2);
	//-- gp of decoration
if (gp_for_decoration_unit_txt_value <= 0) {
	document.getElementById('gp_for_decoration_unit_txt').value = 0;
	document.getElementById('gp_for_decoration_tot_txt').value = 0;		
}else {	document.getElementById('gp_for_decoration_unit_txt').value = isMoney(gp_for_decoration_unit_txt_value,2);
	document.getElementById('gp_for_decoration_tot_txt').value = isMoney((isMoney(gp_for_decoration_unit_txt_value,2) * document.getElementById('main_qty_txt').value),2);
}


	//--take final sell price for unit inc GST
	final_sell_unit_price = document.getElementById('sell_price_ex_txt').value;	
	//-- calculate GP percentage
	//gp_for_product_and_decoration_unit_value = parseFloat(isMoney(gp_for_product_unit_txt_value,2))+parseFloat(isMoney(gp_for_decoration_unit_txt_value,2));

	gp_for_product_and_decoration_unit_value = parseFloat(isMoney(gp_for_product_unit_txt_value,2))+parseFloat(isMoney(gp_for_decoration_unit_txt_value,2))+parseFloat(isMoney(freight_with_markup_gp_for_unit,2))+parseFloat(isMoney(logo_setup_with_markup_gp_for_unit,2));



	
	//alert(gp_for_product_and_decoration_unit_value);	
	gp_percentage_txt_value = (gp_for_product_and_decoration_unit_value/final_sell_unit_price)*100;
	document.getElementById('gp_percentage_txt').value = isMoney(gp_percentage_txt_value,2)+'%';

new_load_all_unit_prices_before_margin_calculate();	
}


function pass_price_to_dec_field(value){
	document.getElementById('unitprice2').value = value;
}

function generate_discounted_price(){
	call_item_markup();
	cal_decoration_markup();
	cal_final_unit_price_ex_vat();
	cal_final_unit_price_inc_vat();
	cal_total_gp();
	
}

function resetall(){
	document.getElementById('qty_level_hidden').value = '';
	document.getElementById('item_cost1_txt').value = '';
	document.getElementById('main_qty_txt').value = '1';
	document.getElementById('markup_price1_txt').value = '';
	document.getElementById('item_markup_txt').value = '';
	document.getElementById('decoration_cost1_txt').value = '';
	document.getElementById('decoration_markup_txt').value = '';
	document.getElementById('sell_price_ex_txt').value = '';
	document.getElementById('sell_price_ex_tot_txt').value = '';
	document.getElementById('sell_price_inc_txt').value = '';
	document.getElementById('sell_price_inc_tot_txt').value = '';
	document.getElementById('logosetup_unit_txt').value = '';
	document.getElementById('logosetup_tot_txt').value = '';
	//document.getElementById('price_method').checked = false;
	
	
}

function resetdecorationprices(){
	document.getElementById('decoration_cost1_txt').value = '';document.getElementById("decoration_type").options[0].selected=true;
	document.getElementById('decoration_markup_txt').value = '';
	document.getElementById('logosetup_unit_txt').value = '';
	document.getElementById('logosetup_tot_txt').value = '';
	cal_final_unit_price_ex_vat();
	cal_final_unit_price_inc_vat();
	cal_total_gp();
	
}
// new function to recalculate markup value based on updated sell price by the user //
	function call_recalculate_markup(obj) {


		system_generated_sell_price_buffer = parseFloat(document.getElementById('sell_price_ex_txt_hidden').value);

		markup_value_buffer = parseFloat(document.getElementById('markup_price1_txt').value);

		// user input value for sell price //
		if(obj!='recursive'){
		new_sell_price_ex_txt = parseFloat(document.getElementById('sell_price_ex_txt').value);
		}


		// if new sell price is greater than system sell price then re calculate //
		if(new_sell_price_ex_txt > system_generated_sell_price_buffer){

		markup_value_buffer += 0.01;
//		alert(markup_value_buffer);
		document.getElementById('markup_price1_txt').value = isMoney(markup_value_buffer,2);


		call_item_markup();
		cal_decoration_markup();
		cal_final_unit_price_ex_vat();

		new_sell_price_ex_txt_hidden = parseFloat(document.getElementById('sell_price_ex_txt_hidden').value);
		if (new_sell_price_ex_txt <= new_sell_price_ex_txt_hidden) {
			
			return true;
		}else {
			call_recalculate_markup("recursive");
		}


//		parseFloat(isMoney(markup_value_buffer,2))

		}else if(new_sell_price_ex_txt < system_generated_sell_price_buffer){
		
		markup_value_buffer -= 0.01; 
		document.getElementById('markup_price1_txt').value = isMoney(markup_value_buffer,2);
		call_item_markup();
		cal_decoration_markup();
		cal_final_unit_price_ex_vat();
		
				
		new_sell_price_ex_txt_hidden = parseFloat(document.getElementById('sell_price_ex_txt_hidden').value);
		
		if (new_sell_price_ex_txt == new_sell_price_ex_txt_hidden) {
			
			return true;
		}else {
			call_recalculate_markup("recursive");
		}		
		
		}

update_margin_percentage_new(document.getElementById('markup_price1_txt'),'markup');


	}

function update_price_in_original_decoration(obj) {
	document.getElementById('decoration_cost1_txt').value = obj;
	cal_decoration_markup();
	cal_final_unit_price_ex_vat();
	cal_final_unit_price_inc_vat();
	cal_total_gp();
}
	
//------------------------check_numeric()-----------------------//
function check_numeric(obj){
	var fld =obj.value;
	var numberfield = obj;
   	var minval = 0;
   	var maxval = 999999999;
   	var comma  = "";   //","
   	var period = ".";   //"."
   	var hyphen = "";   //"-"    
     
	if (chkNumeric(numberfield,minval,maxval,comma,period,hyphen) == false) {
      numberfield.select();
      numberfield.focus();
      return false;
      } 
        	          	
}
 //-------------------roundup()---------------------------------//
 function roundup(theNumber,decimalPlaces){
	
	if((theNumber=="")||(isNaN(theNumber)))
		theNumber = 0;
	 
	var newNum= "" + parseFloat(theNumber);
	var theLength = newNum.length;
	var theDecLoc = newNum.lastIndexOf(".");
	
	if(theDecLoc==-1){
		newNum = newNum + ".";
		for(i=0;i<2;i++)
			newNum = newNum + "0";
	return newNum;
	}
	
	if(theDecLoc!=-1){
		var theRupees = parseInt(newNum.substring(0,theDecLoc));
		var theCents = newNum.substring(theDecLoc,theLength);
		
		if(theCents == '.5'){
		return new_num = theRupees + ".50";
		}
		
		if (parseInt(decimalPlaces)==0){
		new_num ='';
		var round_value = Math.round(theNumber);
		
		if(parseInt(round_value) == parseInt(theNumber)){
			new_num = round_value + ".50";
			//new_num = parseFloat(new_num);
		}else{
			new_num = round_value + ".00";
			//new_num = parseFloat(new_num);
		}
		return new_num;
		
		}
		
	}
		
}
 //-------------------old-isMoney()-----------------------------// 
 /*
 function isMoney(theNumber,decimalPlaces){

	if((theNumber=="")||(isNaN(theNumber)))
		theNumber = 0;
	 
	if (parseInt(decimalPlaces)==0){
		return (Math.round(theNumber));
	}
	
	var newNum= "" + parseFloat(theNumber);
	var theLength = newNum.length;
	var theDecLoc = newNum.lastIndexOf(".");

	if(theDecLoc==-1){
		newNum = newNum + ".";
		for(i=0;i<decimalPlaces;i++)
			newNum = newNum + "0";
	return newNum;
	}

	if(theDecLoc!=-1){
		var theRupees = parseInt(newNum.substring(0,theDecLoc));
		var theCents = newNum.substring(theDecLoc,theLength);
		var x=Math.pow(10,decimalPlaces);

		var theCents = "" + Math.round(theCents*x);
		
		if(theCents.length>decimalPlaces){
				theCents= "" + 0;
				theRupees+=1;
		}
		while(theCents.length<decimalPlaces){
				theCents= "0" + theCents;
		}
		newNum = theRupees + "." + theCents;
	return newNum;
	}
} */

//---- 24-10-2011 new is money function ()--///

function multiply2values(cal_value1,cal_value2)
{
 var v_onum1 = cal_value1*1 
 var v_onum2 = cal_value2*1 
 var v_dp    = 2
 
 var v_num      = v_onum1*v_onum2 
 //frm.num.value  = v_num 
 //v_num = frm.num.value 
 return isMoney(v_num,v_dp); 
}
//---------------new-- [ isMoney(theNumber,decimalPlaces) ] ------------------------------//

function isMoney(theNumber,decimalPlaces)
{
 if(theNumber=="" || isNaN(theNumber)) 
 {
  return "0" 
 }

 var dpto10 = Math.pow(10,decimalPlaces) 
 theNumber  = theNumber*dpto10/dpto10 
 theNumber  = theNumber.toFixed(decimalPlaces)

 return theNumber;
}

function new_load_all_unit_prices_before_margin_calculate(){

	if (document.getElementById('item_cost1_txt').value!='') {
		item_cost1_txt_before_margin = document.getElementById('item_cost1_txt').value;
	}else{
		item_cost1_txt_before_margin = 0;
	}
	if (document.getElementById('decoration_cost1_txt').value!='') {
		decoration_cost1_txt_before_margin = document.getElementById('decoration_cost1_txt').value;
	}else{
		decoration_cost1_txt_before_margin = 0;
	}
	if (document.getElementById('logosetup_unit_txt').value!='') {
		logosetup_unit_txt_before_margin = document.getElementById('logosetup_unit_txt').value;
	}else{
		logosetup_unit_txt_before_margin = 0;
	}
	if (document.getElementById('marginfreight_unit_txt').value!='') {
		marginfreight_unit_txt_before_margin = document.getElementById('marginfreight_unit_txt').value;
	}else{
		marginfreight_unit_txt_before_margin = 0;
	}
	document.getElementById('item_unit_without_margin_txt').value = item_cost1_txt_before_margin;
	document.getElementById('decoration_unit_without_margin_txt').value = decoration_cost1_txt_before_margin;
	document.getElementById('setup_unit_without_margin_txt').value = logosetup_unit_txt_before_margin;
	document.getElementById('freight_unit_without_margin_txt').value = marginfreight_unit_txt_before_margin;

	total_unit_value_before_margin_cal = isMoney(parseFloat(item_cost1_txt_before_margin) + parseFloat(decoration_cost1_txt_before_margin) + parseFloat(logosetup_unit_txt_before_margin) + parseFloat(marginfreight_unit_txt_before_margin),2);
	document.getElementById('total_item_cost_before_margin_txt').value = total_unit_value_before_margin_cal;
}
function empty_decoration_and_all_fields() {
	document.getElementById("dynamic_decoration_list_div").innerHTML = '<p></p>No Decorations found!';
	document.getElementById('gp_for_decoration_unit_txt').value ='';
	document.getElementById('gp_for_decoration_tot_txt').value ='';
	custom_decoration_added_flag = 'no';	
}
</script>
</head>
<body onload="">
<?php
//--- submit add to cart --//
if(isset($_POST['add']) || isset($_POST['add_n_reopen'])){
$main_qty_txt =1;$_SESSION['custom_cal_previous_product_scd_buffer'] = $_POST["product_id_hidden"];

/* if edit cart item then remove existing record require_once("../../bin/cart.php");*/if(isset($_POST['key_id']) && ($_POST['sequenceid']!="")){
$sequenceid = $_REQUEST['sequenceid'];
$key_id = $_POST['key_id'];
remove_cart_item($key_id,$sequenceid);
}
	//customer is adding items to cart
	if ( (!isset($_SESSION["user"])) && (NOT_LOGED_IN_USER_POLICY !== "WORKFLOW")){
		$buttons[1] = array(action => "../client/client.php" , value => "Register", other_button_properties=>"");
		$buttons[2] = array(action => "../product/productlist.php", value => "Back to product list", other_button_properties=>"");
		simple_message("Please register using the registration button below to get access to product pricing.", "Registration Required", $buttons);
		exit;
	}	
	$sell_price_ex_unit = $_POST["sell_price_ex_txt"];
	$sell_price_ex_tot = $_POST["sell_price_ex_tot_txt"];
	$sell_price_inc_unit = $_POST["sell_price_inc_txt"];
	$sell_price_inc_tot = $_POST["sell_price_inc_tot_txt"];	
	$unit_price = $_POST["item_cost1_txt"];
	$decoration_unit_price = $_POST["decoration_cost1_txt"];
	$client_discount_txt = $_POST["client_discount_txt"];

	if($client_discount_txt=='')
	$client_discount_txt =0;		
	$product_margin = $_POST["markup_price1_txt"];
	/* new decoration margin field - 15-05-2019 */
	$decoration_margin_new = $_POST["decoration_markup_decimal"];
	
	$freight_total_cost_input = $_POST["freight_total_cost_input"];
	
	if($freight_total_cost_input=='')
	$freight_total_cost_input =0;
	
	if($decoration_unit_price=='')
	$decoration_unit_price =0;	
	$logo_setup_charges = (floatval($_POST["logosetup_unit_txt"])*($_POST["main_qty_txt"]));	
	//----update new fields (19-04-2010) --//
	$product_short_des_txt = $_POST["product_short_des_txt"];
	$product_long_des_txt = $_POST["product_long_des_txt"];
	$product_long_des_txt = str_replace("#", "@@", $product_long_des_txt);	
	if($_POST["new_decoration_chk_box"]=='1'){
		$new_decoration_txt = $_POST["decoration_new_txt"];
		}else{
		$new_decoration_txt = "no";	
		}

	//print_r($_SESSION['custom_cal_decoration_list']); exit;
	// multi decoration code array pass to the cart database	//$multiple_decoration_code_array = $_POST["decoraton_type_hidden"];

	$multiple_decoration_prices_array = 'N/A';
	$multiple_decoration_logosetup_array = 'N/A';

	if(isset($_SESSION['custom_cal_decoration_list']) && count($_SESSION['custom_cal_decoration_list']>0)) {
		/* if decorations selected is more than one decoration then multiple decoration found */
	$multiple_decoration_prices_array = '';
	$multiple_decoration_logosetup_array = '';
		foreach($_SESSION['custom_cal_decoration_list'] as $multi_decoraton_key=>$multi_decoration_data){

			$multi_decoration_single_array = explode("@@", $multi_decoration_data);

			$multiple_decoration_code_array .= $multi_decoration_single_array[4].",";
			$multiple_decoration_name_array .= $multi_decoration_single_array[0]."~~";
			$multiple_decoration_supplier_array .= $multi_decoration_single_array[1].",";
			$multiple_decoration_prices_array .= $multi_decoration_single_array[2].",";
			$multiple_decoration_logosetup_array .= $multi_decoration_single_array[3].",";

		}

		//$multiple_decoration_prices_array = $_POST["decoraton_multi_prices_array_hidden"];
		//$multiple_decoration_logosetup_array = $_POST["decoraton_multi_logosetup_array_hidden"];

		$multiple_decoration_code_array = substr($multiple_decoration_code_array,0,-1);
		$multiple_decoration_name_array = substr($multiple_decoration_name_array,0,-2);
		$multiple_decoration_supplier_array = substr($multiple_decoration_supplier_array,0,-1);
		$multiple_decoration_prices_array = substr($multiple_decoration_prices_array,0,-1);
		$multiple_decoration_logosetup_array = substr($multiple_decoration_logosetup_array,0,-1);

	}

		$freight_markup_percentage = $_POST["freight_markup_percentage"];
		$freight_total_cost_input = $_POST["freight_total_cost_input"];
		$marginfreight_unit_txt = $_POST["marginfreight_unit_txt"];
		$freight_with_markup_txt = $_POST["freight_with_markup_txt"];

		$logo_setup_markup_percentage = $_POST["logo_setup_markup_percentage"];
		$logosetup_tot_txt = $_POST["logosetup_tot_txt"];
		$logosetup_unit_txt = $_POST["logosetup_unit_txt"];	
		$logo_setup_with_markup_txt = $_POST["logo_setup_with_markup_txt"];

			if($freight_markup_percentage=='')
	$freight_markup_percentage=0;
			if($freight_total_cost_input=='')
	$freight_total_cost_input=0;
			if($marginfreight_unit_txt=='')
	$marginfreight_unit_txt=0;
			if($freight_with_markup_txt=='')
	$freight_with_markup_txt=0;
			if($logo_setup_markup_percentage=='')
	$logo_setup_markup_percentage=0;
			if($logosetup_tot_txt=='')
	$logosetup_tot_txt=0;
			if($logosetup_unit_txt=='')
	$logosetup_unit_txt=0;
			if($logo_setup_with_markup_txt=='')
	$logo_setup_with_markup_txt=0;


	$total_item_cost_before_margin_txt = $_POST["total_item_cost_before_margin_txt"];
			if($total_item_cost_before_margin_txt=='')
	$total_item_cost_before_margin_txt=0;

	//echo $_POST["decoration_new_txt"];
	//adding new freight markup values and logo setup markup values into the string for saving into the database of quote details and then later sending them to the back end system. - 30-09-2018 QCA request
		//$string = $sell_price_ex_unit."#".$sell_price_inc_unit."#".$sell_price_ex_tot."#".$sell_price_inc_tot."#".$unit_price."#".$decoration_unit_price."#".$product_margin."#".$logo_setup_charges."#".$product_short_des_txt."#".$new_decoration_txt."#".$client_discount_txt."#".$freight_total_cost_input."#".$product_long_des_txt;
	$string = $sell_price_ex_unit."#".$sell_price_inc_unit."#".$sell_price_ex_tot."#".$sell_price_inc_tot."#".$unit_price."#".$decoration_unit_price."#".$product_margin."#".$logo_setup_charges."#".$product_short_des_txt."#".$new_decoration_txt."#".$client_discount_txt."#".$freight_total_cost_input."#".$product_long_des_txt."#".$freight_markup_percentage."#".$freight_total_cost_input."#".$marginfreight_unit_txt."#".$freight_with_markup_txt."#".$logo_setup_markup_percentage."#".$logosetup_tot_txt."#".$logosetup_unit_txt."#".$logo_setup_with_markup_txt."#".$multiple_decoration_code_array."#".$multiple_decoration_prices_array."#".$multiple_decoration_logosetup_array."#".$multiple_decoration_supplier_array."#".$multiple_decoration_name_array."#".$decoration_margin_new."#".$total_item_cost_before_margin_txt;
	//echo $string; exit;

	$obj_cart = new Cart();
	//if (empty($_POST["decoraton_type_hidden"])){
	//	$obj_cart->add_to_cart($_POST["product_id_hidden"], array($_POST["main_qty_txt"]), false, null, $string);
	//} else {
		//$obj_cart->add_to_cart($_POST["product_id_hidden"], array($_POST["main_qty_txt"]), false, $_POST["decoraton_type_hidden"], $string);	/* pass multi decoration checkbox as an array (new) */
	$multiple_decoration_array_selected = explode(",", $multiple_decoration_code_array);
	
		$obj_cart->add_to_cart_with_multi_decoration($_POST["product_id_hidden"], array($_POST["main_qty_txt"]), false, $multiple_decoration_array_selected, $string);
	//}
	unset($DB_Obj_product);

//echo "<center><span style='color:#B61A1A;'><b>Selected product added into cart</b></span></center>";
?>
<script type="text/javascript">
	browserName=navigator.appName; 
	if (browserName=="Netscape")
	{ 
	this.parent.window.scrollTo(0,0);
	}

this.parent.document.getElementById("display_output_div").innerHTML = "<center><span style='color:#B61A1A;'><b>Selected product added into cart</b></span></center><br/>";
</script>
<?php
if(isset($_POST['add_n_reopen'])) {

/*var_dump($_POST);
echo "<br/><br/>Sessions:";
var_dump($_SESSION);
exit;*/
$product_name = $_POST['product_short_des_txt'];
$product_long_desc = $_POST['product_long_des_txt'];
$product_scd = $_POST['product_id_hidden'];
//$product_name = $_POST['qty_level_hidden'];
$selected_decoration = $_POST['decoraton_type_hidden'];
$action = $_POST['action'];
$key_id = $_POST['key_id'];
$sequenceid = $_POST['sequenceid'];
$edit_item_quantity = $_POST['product_unit_level'];
$markup_price1_txt = $_POST['markup_price1_txt'];
$decoration_markup_decimal = $_POST["decoration_markup_decimal"];
$main_qty_txt = $_POST['main_qty_txt'];
$item_cost1_txt = $_POST['item_cost1_txt'];
$discount_percentage = $_POST['client_discount_txt'];
$item_markup_txt = $_POST['item_markup_txt'];
$marginfreight_unit_txt = $_POST['marginfreight_unit_txt'];
$freight_total_cost_input = $_POST['freight_total_cost_input'];
$freight_with_markup_txt = $_POST['freight_with_markup_txt'];
$freight_with_markup_total_txt = $_POST['freight_with_markup_total_txt'];
$freight_markup_percentage = $_POST['freight_markup_percentage'];
$decoration_cost1_txt = $_POST['decoration_cost1_txt'];
$decoration_markup_txt = $_POST['decoration_markup_txt'];
$logosetup_unit_txt = $_POST['logosetup_unit_txt'];
$logosetup_tot_txt = $_POST['logosetup_tot_txt'];
$logo_setup_with_markup_txt = $_POST['logo_setup_with_markup_txt'];
$logo_setup_markup_only_value_total_txt = $_POST['logo_setup_markup_only_value_total_txt'];
$logo_setup_markup_percentage = $_POST['logo_setup_markup_percentage'];
$freightrate = $_POST['freight_rate_txt'];
$sell_price_ex_txt = $_POST['sell_price_ex_txt'];
$sell_price_ex_txt_hidden = $_POST['sell_price_ex_txt_hidden'];
$sell_price_ex_tot_txt = $_POST['sell_price_ex_tot_txt'];
$sell_price_inc_txt = $_POST['sell_price_inc_txt'];
$sell_price_inc_tot_txt = $_POST['sell_price_inc_tot_txt'];
$total_gp_txt = $_POST['total_gp_txt'];
$gp_percentage_txt = $_POST['gp_percentage_txt'];
$gp_for_product_unit_txt = $_POST['gp_for_product_unit_txt'];
$gp_for_product_tot_txt = $_POST['gp_for_product_tot_txt'];
$gp_for_decoration_unit_txt = $_POST['gp_for_decoration_unit_txt'];
$gp_for_decoration_tot_txt = $_POST['gp_for_decoration_tot_txt'];
$gp_for_freight_markup_unit_txt = $_POST['gp_for_freight_markup_unit_txt'];
$gp_for_freight_markup_tot_txt = $_POST['gp_for_freight_markup_tot_txt'];
$gp_for_setup_markup_unit_txt = $_POST['gp_for_setup_markup_unit_txt'];
$gp_for_setup_markup_tot_txt = $_POST['gp_for_setup_markup_tot_txt'];

    echo '<script>';
    echo 'var add_n_reopen = '.json_encode("add_n_reopen").';';
    echo '</script>';

}else{
?>
<script type="text/javascript">
//window.parent.location.href = "../../www/viewcart/viewcart.php";
close_me();
</script>
<?
}
}
/* load screen first time using product info url */

if(isset($_REQUEST['pid']) || isset($_REQUEST['edit_pid'])){
	
	if(isset($_REQUEST['pid']) && ($_SESSION["current_product_scd"]!=$_REQUEST['pid'])) {
	unset($_SESSION['custom_cal_decoration_list']);
	}
if(isset($_POST['product_id_hidden'])) {
$product_scd = $_POST['product_id_hidden'];
$action = $_POST['action'];
}else {
$product_scd = $_REQUEST['pid'];
$_SESSION["current_product_scd"] = $product_scd;
}

/* edit url */

if(isset($_REQUEST['action']) && ($_REQUEST['action']=='edit')){	
$key_id = $_REQUEST['edit_pid'];
$sequenceid = $_REQUEST['sequenceid'];//require_once "../../bin/quotation.php";
	$action = "update";
/* if edit product then find and load item data from cart session array */
$obj_quote = new Quotation;
$arr_cart_preview = $obj_quote->read_cart_and_preview_for_multi_decoration();
//print_r($arr_cart_preview);
$ss = $arr_cart_preview[0];
for($a=1;$a<=count($arr_cart_preview);$a++){	
	if(in_array($key_id, $arr_cart_preview[$a],TRUE)){
/* pass values into form */
		$standard_product = false;
		$product_scd = $arr_cart_preview[$a]["product_line_scd"];
		$edit_item_quantity =$arr_cart_preview[$a]["quantity"];
		$edit_item_decoration = $arr_cart_preview[$a]["decoration_type_scd"];
		break;
	}	
}
		if(isset($product_scd) && isset($edit_item_decoration) && isset($edit_item_quantity)){
		$obj_cart = new Cart;
		$item_type = $obj_cart->find_item_type($product_scd, $edit_item_decoration, $edit_item_quantity, $sequenceid);	
		//echo $item_type;		
		$item_type = explode("@@",$item_type);
		$item_type_name = $item_type[0];		$item_type_quantity = $item_type[1];		
		if($item_type_name == "standard_product"){
		$standard_product = true;		
		$main_qty_txt = $edit_item_quantity;
		$selected_decoration = $edit_item_decoration;
				
		}else if($item_type_name == "custom_cal_product"){
		$custom_cal_product = true;
		$item_type_string_array = explode("##",$item_type_quantity);
		$main_qty_txt = $item_type_string_array[0];
		//echo $item_type_string_array[1];		
		$other_values = explode("#",$item_type_string_array[1]);		
		$sell_price_ex_unit = $other_values[0];
		$sell_price_inc_unit = $other_values[1];
		$sell_price_ex_tot = $other_values[2];
		$sell_price_inc_tot = $other_values[3];
		$unit_price = $other_values[4];
		$decoration_unit_price = $other_values[5];
		$product_margin = $other_values[6];

		$decoration_margin = $other_values[26];
		/* set decoration margin value taken from product margin value for old type cart items */
/*		if($decoration_margin == 0) {
			$decoration_margin = $product_margin;
		}*/		//echo $decoration_margin;
		$logo_setup_charges = $other_values[7];
		$product_short_des_txt = $other_values[8];
		$new_decoration_txt = $other_values[9];
		$client_discount_txt = $other_values[10];
		$freight_total_cost_input = $other_values[11];
		$product_long_des_txt = $other_values[12];

		$freight_markup_percentage = $other_values[13];

		$logo_setup_markup_percentage = $other_values[17];		
		$sell_price_ex_txt = $sell_price_ex_unit;
		$sell_price_ex_tot_txt = $sell_price_ex_tot;
		$sell_price_inc_txt = $sell_price_inc_unit;
		$sell_price_inc_tot_txt = $sell_price_inc_tot;
		$item_cost1_txt = $unit_price;
		$decoration_cost1_txt = $decoration_unit_price;
		$markup_price1_txt = $product_margin;

		$decoration_markup_decimal = $decoration_margin;
		$logosetup_tot_txt = $logo_setup_charges;
		$product_name = $product_short_des_txt;
		if($new_decoration_txt !="no"){
				$decoration_new_txt = $new_decoration_txt;
		}

		/* extract multi decoration data 30/01/2019 if multi decoration then decoration scd data should have comma seperated */


		//if(strstr($other_values[21],',')) {

		$multi_decration_scd_array = explode(',', $other_values[21]);

		$multi_decoration_unit_value_array = explode(',', $other_values[22]);
		$multi_decoration_logo_setup_value_array = explode(',', $other_values[23]);
		$multi_decoration_name_array = explode('~~', $other_values[25]);
		$multi_decoration_supplier_scd_array = explode(',', $other_values[24]);
			unset($_SESSION['custom_cal_decoration_list']);
			
		$edit_item_decoration_array = explode('##', $edit_item_decoration);
		if(count($edit_item_decoration_array)==1) {
			//echo $edit_item_decoration_array[0];
			$objDB_decoration = DB_DataObject::factory("decoration");
			$objDB_decoration->print_type = $edit_item_decoration_array[0];
			$objDB_decoration->whereAdd("flag != 0");
			$objDB_decoration->find();
			$objDB_decoration->fetch();
			$selected_edit_decoration_name = $objDB_decoration->name;			
			$selected_edit_decoration_supplier_scd = !empty($objDB_decoration->supplier_scd)?$objDB_decoration->supplier_scd:'N/A';
			if($edit_item_decoration_array[0] == 'CUSTOM_DECORATION') {
			$selected_edit_decoration_name = !empty($other_values[25])?$other_values[25]:'Custom Decoration';
			$selected_edit_decoration_supplier_scd = !empty($other_values[24])?$other_values[24]:'N/A';
			}
			ajax_insert_new_decoration($selected_edit_decoration_name."@@".$selected_edit_decoration_supplier_scd."@@".$decoration_unit_price."@@".$logo_setup_charges."@@".$edit_item_decoration_array[0]);				
				
		}else if(count($edit_item_decoration_array)>1) {

			foreach($edit_item_decoration_array as $record_key=>$multi_decration_scd){		
			ajax_insert_new_decoration($multi_decoration_name_array[$record_key]."@@".$multi_decoration_supplier_scd_array[$record_key]."@@".$multi_decoration_unit_value_array[$record_key]."@@".$multi_decoration_logo_setup_value_array[$record_key]."@@".$multi_decration_scd_array[$record_key]);
				}
			
		}
		//}
		$discount_percentage = $client_discount_txt;
		$freight_total_cost_input = $freight_total_cost_input;
		$product_long_desc = $product_long_des_txt;
		
		}				
		}		
}else{
//require_once "price_class.php";if(isset($_POST['action'])) {
$action = $_POST['action'];
}else {
	$action = "add";
}
//echo 	$action;}

if(!isset($_SESSION["current_product_scd"])) {
$_SESSION["current_product_scd"] = $product_scd;
}
//--select product name and details --//
	$db_conn = new DB_DataObject();	
	$DB_Connection = $db_conn->getDatabaseConnection();
	$DB_Connection->setFetchMode(DB_FETCHMODE_ASSOC);	
	//--find product group scd from product line scd and fetch product data--//
	$DB_Obj_product_line = DB_DataObject::factory("product_line");
	$DB_Obj_product_line->product_line = trim($product_scd);
	$DB_Obj_product_line->find();
	$DB_Obj_product_line->fetch();
	$product_group_scd = $DB_Obj_product_line->product_scd;	//print_r($product_group_scd);	//--end --//
	
	$DB_Obj_product = DB_DataObject::factory("product");
	$DB_Obj_product->scd = trim($product_group_scd);
	$DB_Obj_product->find();
	$DB_Obj_product->fetch();

	if(!isset($product_name)){
	$product_name = $DB_Obj_product->short_description;
	}	
	if(!isset($product_long_desc)){
	$product_long_desc = $DB_Obj_product->long_description;
	}		//print_r($product_name);	
	//-------take product price breaks --//
	$obj_quantity_break = DB_DataObject::factory("quantity_break");
	$obj_quantity_break->product_line_scd = trim($product_scd);
	$obj_quantity_break->quantity_type = "product";
	$arr_product_price_info = $obj_quantity_break->get_filtered_price_info();	//print_r($arr_product_price_info);	//---take decoration list --//
	$decoration_list = $DB_Obj_product->get_decoration_list();
	//---take decoration list --//	if($selected_decoration =='') {
	$selected_decoration = $DB_Obj_product->get_default_decoration();
	}
	//echo "selected decoration: ".$selected_decoration;	//print_r($decoration_list);		//---take tax rate --//
			//getting GST percentage
			$objDB_sysmaster = DB_DataObject::factory("sysmaster");
			$taxrate = $objDB_sysmaster->get_value("gst", "gst");
			$taxrate = ((100 + $taxrate)/100);			
	//---take freight rate --//
			$objDB_sysmaster = DB_DataObject::factory("sysmaster");
			$freightrate = $objDB_sysmaster->get_value("freight_percentage", "freight_percentage");
			if($freightrate ==0){
			$freightrate = 0;
			}else{
			$freightrate = ((100 + $freightrate)/100);
			}
	/*--- take the discount if exist -- */	if($discount_percentage == ''){	$discount_percentage = get_discount();
	}

	/* take new fright markup value from the system variable 20-09-2018 for quick corporate customer */
	//echo $freight_markup_percentage;
			if(!isset($freight_markup_percentage) && ($freight_markup_percentage =='')){
				$objDB_sysmaster = DB_DataObject::factory("sysmaster");
				$freight_markup_percentage = $objDB_sysmaster->get_value("freight_markup", "freight_markup");
				if($freight_markup_percentage ==0){
				$freight_markup = 0;
				}else{
				$freight_markup = ((100 + $freight_markup_percentage)/100);
				}
			}
			
				//---- take new logo setup markup value from the system variable 20-09-2018 for quick corporate customer -- //
			if(!isset($logo_setup_markup_percentage) && ($logo_setup_markup_percentage =='')){
				$objDB_sysmaster = DB_DataObject::factory("sysmaster");
				$logo_setup_markup_percentage = $objDB_sysmaster->get_value("logo_setup_markup", "logo_setup_markup");
				if($logo_setup_markup_percentage ==0){
				$logo_setup_markup = 0;
				}else{
				$logo_setup_markup = ((100 + $logo_setup_markup_percentage)/100);
				}
			}

			//echo $logo_setup_markup_percentage;

	
/* import supplier list for finding and selecting new decoration */

	$objDB_supplier = DB_DataObject::factory("supplier");
	$objDB_supplier_array = $objDB_supplier->list_all();

	$supplier_code = base64_encode($DB_Obj_product->supplier_code);
}

$obj_tem_sysmaster = DB_DataObject::factory("sysmaster");
$cart_button = trim($obj_tem_sysmaster->get_value("cart_button", "cart_button"));

/* pass all decoration */
	$objDB_decoration_all = DB_DataObject::factory("decoration");
	$decoration_list_all = $objDB_decoration_all->list_subdecoration();
	//print_r($decoration_list_all);


?>
<h5>Custom Price Calculator</h5>
<form action="" method="post" name="Form1" id="Form1">

<table align="center" width="100%" style="padding:10px;" class="contenttable">
<tr>
<th width="" align="left" ><strong>Product Name</strong></th>
<th width="" align="left" ><strong>
<input type="text" name="product_short_des_txt" id="product_short_des_txt" style="text-align:left;" size="71" onkeyup="" value="<?=$product_name?>" />
<span>&nbsp;Code:&nbsp;<?=$product_scd?></span>
</th>
</tr>
<tr>
<th width="" align="left" ><strong>Product Desc</strong></th>
<th width="" align="left" >
<textarea name="product_long_des_txt" id="product_long_des_txt" cols="53" rows="3" ><?=$product_long_desc?></textarea>
&nbsp;&nbsp;<input type="button" name="" id="" onclick="javascript:window.open('../../www/supplier/supplier.php?scd=<?=$supplier_code?>&action=view', '_blank');" value="Supplier Info" />
</th>
</tr>

<tr>
<td>Load price from Product Qty level&nbsp;</td>
<td align="left">
<input type="hidden" name="product_id_hidden" id="product_id_hidden" value="<?=$product_scd?>" />
<input type="hidden" name="qty_level_hidden" id="qty_level_hidden" value="" />
<input type="hidden" name="decoraton_type_hidden" id="decoraton_type_hidden" value="<?=$selected_decoration?>" />
<input type="hidden" name="decoraton_multi_prices_array_hidden" id="decoraton_multi_prices_array_hidden" value="" />
<input type="hidden" name="decoraton_multi_logosetup_array_hidden" id="decoraton_multi_logosetup_array_hidden" value="" />
<input type="hidden" name="action" id="action" value="<?=$action?>" />
<input type="hidden" name="key_id" id="key_id" value="<?=$key_id?>" />
<input type="hidden" name="sequenceid" id="sequenceid" value="<?=$sequenceid?>" />

<select name="product_unit_level" id="product_unit_level" style="" onchange="javascript:pass_price_to_field(this.value);">
<option value=" "> --- Qty Level --- </option>
<?php
$level =0;
	foreach ($arr_product_price_info as $quantity => $price) {
		if ($price != 0) {			
			/*
			 * The price displayed to the user should be preprocessed
			 * by adding freight, margin etc.
			 *
			 */
			$level +=1;
			$obj_price = new price;
			$obj_price->product_line_scd = trim($product_scd);
			$obj_price->quantity = $quantity;
			$obj_price->discount_percentage = get_discount();			
			$obj_price->get_price("viewing");			
			$product_line_unit_price = currency_format($obj_price->product_line_unit_price);		
			$selected ='';
		if((isset($_REQUEST['action']) && ($_REQUEST['action']=='edit')) || isset($_POST['add_n_reopen'])){
			if($quantity == $edit_item_quantity){
				$selected ='selected';
			}
			}		
		echo "<option value='{$quantity}##{$product_line_unit_price}##{$level}' $selected >$quantity</option>";
		}
	}
?>
</select>
<input type="reset" value="reset data" onclick="empty_decoration_and_all_fields();" />
</td>
</tr>
<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr>
<td>&nbsp;Markup Rate</td>
<td>
<input type="text" name="markup_price1_txt" id="markup_price1_txt" size="7" onkeyup="javascript:txt_function_chg_markup_rate(this,'markup');" value="<?=$markup_price1_txt?>" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Margin<select name="markup" id="markup" onchange="update_markup_using_margin_value(this.value,'markup_price1_txt');">
<option value="1">1%</option>
<option value="2">2%</option>
<option value="3">3%</option>
<option value="4">4%</option>
<option value="5">5%</option>
<option value="6">6%</option>
<option value="7">7%</option>
<option value="8">8%</option>
<option value="9">9%</option>
<option value="10">10%</option>
<option value="11">11%</option>
<option value="12">12%</option>
<option value="13">13%</option>
<option value="14">14%</option>
<option value="15">15%</option>
<option value="16">16%</option>
<option value="17">17%</option>
<option value="18">18%</option>
<option value="19">19%</option>
<option value="20">20%</option>
<option value="21">21%</option>
<option value="22">22%</option>
<option value="23">23%</option>
<option value="24">24%</option>
<option value="25">25%</option>
<option value="26">26%</option>
<option value="27">27%</option>
<option value="28">28%</option>
<option value="29">29%</option>
<option value="30">30%</option>
<option value="31">31%</option>
<option value="32">32%</option>
<option value="33">33%</option>
<option value="34">34%</option>
<option value="35">35%</option>
<option value="36">36%</option>
<option value="37">37%</option>
<option value="38">38%</option>
<option value="39">39%</option>
<option value="40">40%</option>
<option value="41">41%</option>
<option value="42">42%</option>
<option value="43">43%</option>
<option value="44">44%</option>
<option value="45">45%</option>
<option value="46">46%</option>
<option value="47">47%</option>
<option value="48">48%</option>
<option value="49">49%</option>
<option value="50">50%</option>
<option value="51">51%</option>
<option value="52">52%</option>
<option value="53">53%</option>
<option value="54">54%</option>
<option value="55">55%</option>
<option value="56">56%</option>
<option value="57">57%</option>
<option value="58">58%</option>
<option value="59">59%</option>
<option value="60">60%</option>
<option value="61">61%</option>
<option value="62">62%</option>
<option value="63">63%</option>
<option value="64">64%</option>
<option value="65">65%</option>
<option value="66">66%</option>
<option value="67">67%</option>
<option value="68">68%</option>
<option value="69">69%</option>
<option value="70">70%</option>
<option value="71">71%</option>
<option value="72">72%</option>
<option value="73">73%</option>
<option value="74">74%</option>
<option value="75">75%</option>
<option value="76">76%</option>
<option value="77">77%</option>
<option value="78">78%</option>
<option value="79">79%</option>
<option value="80">80%</option>
<option value="81">81%</option>
<option value="82">82%</option>
<option value="83">83%</option>
<option value="84">84%</option>
<option value="85">85%</option>
<option value="86">86%</option>
<option value="87">87%</option>
<option value="88">88%</option>
<option value="89">89%</option>
<option value="90">90%</option>
<option value="91">91%</option>
<option value="92">92%</option>
<option value="93">93%</option>
<option value="94">94%</option>
<option value="95">95%</option>
<option value="96">96%</option>
<option value="97">97%</option>
<option value="98">98%</option>
<option value="99">99%</option>
<option value="100">100%</option>
</select>
<span name="showstatus" id="showstatus" style="color:#DD8325" />
</td>
</tr>
<tr>
<td>&nbsp;Quantity</td>
<td>
<input type="text" name="main_qty_txt" id="main_qty_txt" size="7" onkeyup="javascript:update_qty(this);" value="<?=$main_qty_txt?>"/>&nbsp;&nbsp;&nbsp;&nbsp;
</td>
</tr>
<tr>
<td>&nbsp;Item Cost</td>
<td>
<input type="text" name="item_cost1_txt" id="item_cost1_txt" size="7" value="<?=$item_cost1_txt?>" onkeyup="javascript:txt_function_chg_item_cost(this);" />&nbsp;&nbsp;&nbsp;&nbsp;
Discount % &nbsp;&nbsp;
<input type="text" name="client_discount_txt" id="client_discount_txt" size="7" value="<?=$discount_percentage?>" onkeyup="javascript:generate_discounted_price();" />&nbsp;&nbsp;&nbsp;&nbsp;</td></tr>
<tr>
<td>&nbsp;Items Marked up</td>
<td>
<input type="text" name="item_markup_txt" id="item_markup_txt" class="readonlytext" size="7" readonly value="<?=$item_markup_txt?>" onkeyup="javascript:check_numeric(this);" />&nbsp;&nbsp;&nbsp;&nbsp;
</td>
</tr>
<tr>
<td>&nbsp;Freight</td>
<td>
<input type="text" name="marginfreight_unit_txt" id="marginfreight_unit_txt" class="readonlytext" readonly size="7" value="<?=$marginfreight_unit_txt?>" onkeyup="javascript:check_numeric(this);" />&nbsp;(Unit)&nbsp;&nbsp;&nbsp;

Freight Cost in &#36;&nbsp;<input type="text" name="freight_total_cost_input" id="freight_total_cost_input" class="" size="5"
value="<?=$freight_total_cost_input?>" onkeyup="javascript:cal_unit_marginfrgt_setup();" />&nbsp;(Total)


</td>
</tr>
<tr>
<td>&nbsp;Freight with Markup</td>
<td>
<input type="text" name="freight_with_markup_txt" id="freight_with_markup_txt" class="readonlytext" readonly size="7" value="<?=$freight_with_markup_txt?>" onkeyup="javascript:check_numeric(this);" />&nbsp;(Unit)&nbsp;&nbsp;&nbsp;

Freight Sell &nbsp;&nbsp;&nbsp;&nbsp; &#36;&nbsp;&nbsp;<input type="text" name="freight_with_markup_total_txt" id="freight_with_markup_total_txt" class="readonlytext" readonly size="5" value="<?=$freight_with_markup_total_txt?>" onkeyup="javascript:check_numeric(this);" />&nbsp;(Total)

&nbsp;&nbsp;&nbsp;Markup for Freight&nbsp;
<input type="hidden" name="freight_markup_percentage_hidden" id="freight_markup_percentage_hidden" value="<?=$freight_markup_percentage?>" size="3" onkeyup="javascript:cal_unit_marginfrgt_setup();" />

<input type="text" name="freight_markup_decimal" id="freight_markup_decimal" size="5" onkeyup="javascript:txt_function_chg_markup_rate(this,'freight_markup_percentage');" value="">
Margin&nbsp;<select name="freight_markup_percentage" id="freight_markup_percentage" onchange="update_markup_using_margin_value(this.value,'freight_markup_decimal');cal_unit_marginfrgt_setup();">
<option value="1">1%</option>
<option value="2">2%</option>
<option value="3">3%</option>
<option value="4">4%</option>
<option value="5">5%</option>
<option value="6">6%</option>
<option value="7">7%</option>
<option value="8">8%</option>
<option value="9">9%</option>
<option value="10">10%</option>
<option value="11">11%</option>
<option value="12">12%</option>
<option value="13">13%</option>
<option value="14">14%</option>
<option value="15">15%</option>
<option value="16">16%</option>
<option value="17">17%</option>
<option value="18">18%</option>
<option value="19">19%</option>
<option value="20">20%</option>
<option value="21">21%</option>
<option value="22">22%</option>
<option value="23">23%</option>
<option value="24">24%</option>
<option value="25">25%</option>
<option value="26">26%</option>
<option value="27">27%</option>
<option value="28">28%</option>
<option value="29">29%</option>
<option value="30">30%</option>
<option value="31">31%</option>
<option value="32">32%</option>
<option value="33">33%</option>
<option value="34">34%</option>
<option value="35">35%</option>
<option value="36">36%</option>
<option value="37">37%</option>
<option value="38">38%</option>
<option value="39">39%</option>
<option value="40">40%</option>
<option value="41">41%</option>
<option value="42">42%</option>
<option value="43">43%</option>
<option value="44">44%</option>
<option value="45">45%</option>
<option value="46">46%</option>
<option value="47">47%</option>
<option value="48">48%</option>
<option value="49">49%</option>
<option value="50">50%</option>
<option value="51">51%</option>
<option value="52">52%</option>
<option value="53">53%</option>
<option value="54">54%</option>
<option value="55">55%</option>
<option value="56">56%</option>
<option value="57">57%</option>
<option value="58">58%</option>
<option value="59">59%</option>
<option value="60">60%</option>
<option value="61">61%</option>
<option value="62">62%</option>
<option value="63">63%</option>
<option value="64">64%</option>
<option value="65">65%</option>
<option value="66">66%</option>
<option value="67">67%</option>
<option value="68">68%</option>
<option value="69">69%</option>
<option value="70">70%</option>
<option value="71">71%</option>
<option value="72">72%</option>
<option value="73">73%</option>
<option value="74">74%</option>
<option value="75">75%</option>
<option value="76">76%</option>
<option value="77">77%</option>
<option value="78">78%</option>
<option value="79">79%</option>
<option value="80">80%</option>
<option value="81">81%</option>
<option value="82">82%</option>
<option value="83">83%</option>
<option value="84">84%</option>
<option value="85">85%</option>
<option value="86">86%</option>
<option value="87">87%</option>
<option value="88">88%</option>
<option value="89">89%</option>
<option value="90">90%</option>
<option value="91">91%</option>
<option value="92">92%</option>
<option value="93">93%</option>
<option value="94">94%</option>
<option value="95">95%</option>
<option value="96">96%</option>
<option value="97">97%</option>
<option value="98">98%</option>
<option value="99">99%</option>
<option value="100">100%</option>
</select>


</td>
</tr>
<tr>
<td>&nbsp;</td>
<td></td>
</tr><tr><td>&nbsp;Decoration Type</td>
<td>
<div class="tab">
  <button class="tablinks" onclick="openCity(event, 'selected_list_tab');import_existing_decoration_list(); return false;" id="defaultOpen">Selected list</button>
  <button class="tablinks" onclick="openCity(event, 'decoration_import_tab'); return false;">Import Decoration </button>
  <button class="tablinks" onclick="openCity(event, 'new_decoration_tab'); return false;">Add New</button>
</div>
<!--selected decorations list box-->
<div id="selected_list_tab" class="tabcontent">
  <span onclick="this.parentElement.style.display='none'" class="topright">&times</span>
<!--  <h5>Selected Decorations</h5>-->

  <div id="dynamic_decoration_list_div">
  </div>
<!--<a class='decoration_ajax_form' onclick="event.preventDefault();" href="../../www/message/message.php">Add New Decoration</a><br/>-->

<!--<select name="decoration_type" id="decoration_type" onchange="javascript:load_decoration_levels_ajax(this.value);">-->
</div>
<!--import decoration box-->
<div id="decoration_import_tab" class="tabcontent">
  <span onclick="this.parentElement.style.display='none'" class="topright">&times</span>
  <h5>Select Decoration</h5>
  <p>
<select name="all_decorations" id="all_decorations" onchange="">
<option value=" ">Select Decoration Type</option>
<?php
	foreach($decoration_list_all as $decoration_code => $decoration) {
		echo "<option value='$decoration[print_type]'>".$decoration[supplier_scd]." - ".$decoration[name]."</option>";

	}
?>
 </select>
</p><br/>
<div id="buttons"><input type="button" name="add_decoration_button" id="add_decoration_button" value="Add" onclick="add_system_decoration();"/></div>
</div>

<!--add new decoration box-->
<div id="new_decoration_tab" class="tabcontent" style="">
  <span onclick="this.parentElement.style.display='none'" class="topright">&times</span>
  <h5>Add New Decoration</h5>
<!-- add new decoration master record -->

			<div id="form">
				
					<form method="post" action="">
					<p>
						<label for="supplier_ref">Supplier Reference:</label>
						<select name="supplier_ref" id="supplier_ref" >
							
							<option value="">--Select a Supplier--</option>
<?php
foreach ($objDB_supplier_array as $supplier) {
?>
<option value="<?php echo $supplier['scd'];?>"><?php echo $supplier['name']." - ".$supplier['scd'];?></option>
<?php
}
?>					

						</select><br />
						</p>
					<p>
					<label for="name">Decoration Name: </label><input type="text" value="" name="new_decoration_name" id="new_decoration_name" class="hoverOff" onmouseover="hoverOn(this);" onmouseout="hoverOff(this);" size="30" /></p>
					<p>
					<label for="logo_setup_charges">Unit Value: </label><input type="text" value="" name="new_decoration_unit_value" id="new_decoration_unit_value" class="hoverOff" onmouseover="hoverOn(this);" onmouseout="hoverOff(this);" size="5" /></p>
					<p>					
					<label for="logo_setup_charges">Setup Charges: </label><input type="text" value="" name="new_decoration_setup_value" id="new_decoration_setup_value" class="hoverOff" onmouseover="hoverOn(this);" onmouseout="hoverOff(this);" size="5" />(total)</p>



					
					<p>
					<br />
					<div id="buttons"><input name="submit" value="Add new decoration" type="button" onclick="submit_new_decoration();"></div>
					</p><br />
					</form>
			</div>

</div>
<!--end multi decoration boxes-->
</td>
</tr>
<tr>
<td>&nbsp;Decoration Total</td>
<td><div id="standard_decoration_div">
<input type="text" name="decoration_cost1_txt" id="decoration_cost1_txt" size="7" value="<?=$decoration_cost1_txt?>" onkeyup="javascript:txt_function_chg_decor_cost(this);" />&nbsp;&nbsp;&nbsp;&nbsp;
<!--<select name="decoration_type" id="decoration_type" onchange="javascript:load_decoration_levels_ajax(this.value);">
<option value=" ">Select Decoration Type</option>
</select>--><div></td>
</tr>

<tr>
<td>&nbsp;Decoration Marked up</td>
<td>
<input type="text" name="decoration_markup_txt" id="decoration_markup_txt" class="readonlytext" readonly size="7" value="<?=$decoration_markup_txt?>" onkeyup="javascript:check_numeric(this);" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; Markup for Decoration
<input type="hidden" id="decoration_markup_percentage_hidden" name="decoration_markup_percentage_hidden" value="<?=$decoration_markup_percentage?>" size="5" onkeyup="" />

<input type="text" name="decoration_markup_decimal" id="decoration_markup_decimal" size="5" onkeyup="javascript:txt_function_chg_markup_rate(this,'decoration_markup_percentage');" value="<?=$decoration_markup_decimal?>">
Margin&nbsp;<select name="decoration_markup_percentage" id="decoration_markup_percentage" onchange="update_markup_using_margin_value(this.value,'decoration_markup_decimal');cal_unit_logo_setup();">
<option value="1">1%</option>
<option value="2">2%</option>
<option value="3">3%</option>
<option value="4">4%</option>
<option value="5">5%</option>
<option value="6">6%</option>
<option value="7">7%</option>
<option value="8">8%</option>
<option value="9">9%</option>
<option value="10">10%</option>
<option value="11">11%</option>
<option value="12">12%</option>
<option value="13">13%</option>
<option value="14">14%</option>
<option value="15">15%</option>
<option value="16">16%</option>
<option value="17">17%</option>
<option value="18">18%</option>
<option value="19">19%</option>
<option value="20">20%</option>
<option value="21">21%</option>
<option value="22">22%</option>
<option value="23">23%</option>
<option value="24">24%</option>
<option value="25">25%</option>
<option value="26">26%</option>
<option value="27">27%</option>
<option value="28">28%</option>
<option value="29">29%</option>
<option value="30">30%</option>
<option value="31">31%</option>
<option value="32">32%</option>
<option value="33">33%</option>
<option value="34">34%</option>
<option value="35">35%</option>
<option value="36">36%</option>
<option value="37">37%</option>
<option value="38">38%</option>
<option value="39">39%</option>
<option value="40">40%</option>
<option value="41">41%</option>
<option value="42">42%</option>
<option value="43">43%</option>
<option value="44">44%</option>
<option value="45">45%</option>
<option value="46">46%</option>
<option value="47">47%</option>
<option value="48">48%</option>
<option value="49">49%</option>
<option value="50">50%</option>
<option value="51">51%</option>
<option value="52">52%</option>
<option value="53">53%</option>
<option value="54">54%</option>
<option value="55">55%</option>
<option value="56">56%</option>
<option value="57">57%</option>
<option value="58">58%</option>
<option value="59">59%</option>
<option value="60">60%</option>
<option value="61">61%</option>
<option value="62">62%</option>
<option value="63">63%</option>
<option value="64">64%</option>
<option value="65">65%</option>
<option value="66">66%</option>
<option value="67">67%</option>
<option value="68">68%</option>
<option value="69">69%</option>
<option value="70">70%</option>
<option value="71">71%</option>
<option value="72">72%</option>
<option value="73">73%</option>
<option value="74">74%</option>
<option value="75">75%</option>
<option value="76">76%</option>
<option value="77">77%</option>
<option value="78">78%</option>
<option value="79">79%</option>
<option value="80">80%</option>
<option value="81">81%</option>
<option value="82">82%</option>
<option value="83">83%</option>
<option value="84">84%</option>
<option value="85">85%</option>
<option value="86">86%</option>
<option value="87">87%</option>
<option value="88">88%</option>
<option value="89">89%</option>
<option value="90">90%</option>
<option value="91">91%</option>
<option value="92">92%</option>
<option value="93">93%</option>
<option value="94">94%</option>
<option value="95">95%</option>
<option value="96">96%</option>
<option value="97">97%</option>
<option value="98">98%</option>
<option value="99">99%</option>
<option value="100">100%</option>
</select>

</td>
</tr><tr><td>&nbsp;</td>
<td></td>
</tr>
<tr>
<td>&nbsp;Logo Setup</td>
<td>
<input type="text" name="logosetup_unit_txt" id="logosetup_unit_txt" class="readonlytext" readonly size="7" value="<?=$logosetup_unit_txt?>" onkeyup="javascript:check_numeric(this);" />&nbsp;(Unit)&nbsp;&nbsp;&nbsp;Setup Cost in &#36;<input type="text" name="logosetup_tot_txt" id="logosetup_tot_txt" class="" size="5" value="<?=$logosetup_tot_txt?>" onkeyup="javascript:cal_unit_logo_setup();" />&nbsp;(Total)</td>
</tr>
<tr>
<td>&nbsp;Setup with Markup</td>
<td>
<input name="logo_setup_with_markup_txt" id="logo_setup_with_markup_txt" class="readonlytext" readonly="" size="7" value="<?=$logo_setup_with_markup_txt?>" onkeyup="javascript:check_numeric(this);" type="text">&nbsp;(Unit)&nbsp;&nbsp;&nbsp;&nbsp;Setup Sell&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#36;&nbsp;
<input type="text" name="logo_setup_markup_only_value_total_txt" id="logo_setup_markup_only_value_total_txt" class="readonlytext" readonly size="5" value="<?=$logo_setup_markup_only_value_total_txt?>" onkeyup="javascript:check_numeric(this);" />
&nbsp;&nbsp;&nbsp;&nbsp;
Markup for Setup

<input type="hidden" id="logo_setup_markup_percentage_hidden" name="logo_setup_markup_percentage_hidden" value="<?=$logo_setup_markup_percentage?>" size="5" onkeyup="javascript:cal_unit_logo_setup();" />

<input type="text" name="logo_setup_markup_decimal" id="logo_setup_markup_decimal" size="5" onkeyup="javascript:txt_function_chg_markup_rate(this,'logo_setup_markup_percentage');" value="">
Margin&nbsp;<select name="logo_setup_markup_percentage" id="logo_setup_markup_percentage" onchange="update_markup_using_margin_value(this.value,'logo_setup_markup_decimal');cal_unit_logo_setup();">
<option value="1">1%</option>
<option value="2">2%</option>
<option value="3">3%</option>
<option value="4">4%</option>
<option value="5">5%</option>
<option value="6">6%</option>
<option value="7">7%</option>
<option value="8">8%</option>
<option value="9">9%</option>
<option value="10">10%</option>
<option value="11">11%</option>
<option value="12">12%</option>
<option value="13">13%</option>
<option value="14">14%</option>
<option value="15">15%</option>
<option value="16">16%</option>
<option value="17">17%</option>
<option value="18">18%</option>
<option value="19">19%</option>
<option value="20">20%</option>
<option value="21">21%</option>
<option value="22">22%</option>
<option value="23">23%</option>
<option value="24">24%</option>
<option value="25">25%</option>
<option value="26">26%</option>
<option value="27">27%</option>
<option value="28">28%</option>
<option value="29">29%</option>
<option value="30">30%</option>
<option value="31">31%</option>
<option value="32">32%</option>
<option value="33">33%</option>
<option value="34">34%</option>
<option value="35">35%</option>
<option value="36">36%</option>
<option value="37">37%</option>
<option value="38">38%</option>
<option value="39">39%</option>
<option value="40">40%</option>
<option value="41">41%</option>
<option value="42">42%</option>
<option value="43">43%</option>
<option value="44">44%</option>
<option value="45">45%</option>
<option value="46">46%</option>
<option value="47">47%</option>
<option value="48">48%</option>
<option value="49">49%</option>
<option value="50">50%</option>
<option value="51">51%</option>
<option value="52">52%</option>
<option value="53">53%</option>
<option value="54">54%</option>
<option value="55">55%</option>
<option value="56">56%</option>
<option value="57">57%</option>
<option value="58">58%</option>
<option value="59">59%</option>
<option value="60">60%</option>
<option value="61">61%</option>
<option value="62">62%</option>
<option value="63">63%</option>
<option value="64">64%</option>
<option value="65">65%</option>
<option value="66">66%</option>
<option value="67">67%</option>
<option value="68">68%</option>
<option value="69">69%</option>
<option value="70">70%</option>
<option value="71">71%</option>
<option value="72">72%</option>
<option value="73">73%</option>
<option value="74">74%</option>
<option value="75">75%</option>
<option value="76">76%</option>
<option value="77">77%</option>
<option value="78">78%</option>
<option value="79">79%</option>
<option value="80">80%</option>
<option value="81">81%</option>
<option value="82">82%</option>
<option value="83">83%</option>
<option value="84">84%</option>
<option value="85">85%</option>
<option value="86">86%</option>
<option value="87">87%</option>
<option value="88">88%</option>
<option value="89">89%</option>
<option value="90">90%</option>
<option value="91">91%</option>
<option value="92">92%</option>
<option value="93">93%</option>
<option value="94">94%</option>
<option value="95">95%</option>
<option value="96">96%</option>
<option value="97">97%</option>
<option value="98">98%</option>
<option value="99">99%</option>
<option value="100">100%</option>
</select>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><span name="showstatus2" id="showstatus2" style="color:#DD8325"> </span></td>
</tr>
<!--
<tr>
<td>&nbsp;Add additional charge (unit)</td>
<td>
<input type="text" name="extra_charge_txt" id="extra_charge_txt" class="" size="7" value="" onkeyup="javascript:txt_add_extra_change(this);" />&nbsp;&nbsp;&nbsp;&nbsp;
</td>
</tr> -->

<tr>
<td>&nbsp;Tax Rate</td>
<td>
<input type="text" name="tax_rate_txt" id="tax_rate_txt" class="readonlytext" readonly size="7" value="<?=$taxrate?>" onkeyup="javascript:check_numeric(this);" />
</td>
</tr>

<tr>
<td>&nbsp;Freight Rate</td>
<td>
<input type="text" name="freight_rate_txt" id="freight_rate_txt" class="" size="7" value="<?=$freightrate?>" onkeyup="javascript:txt_freight_value_change(this);" />
</td>
</tr>

<tr>
<td>&nbsp;Ex sell Price</td>
<td>
<input type="text" name="sell_price_ex_txt" id="sell_price_ex_txt" size="7" value="<?=$sell_price_ex_txt?>" readonly onkeyup="javascript:check_numeric(this);" />&nbsp;(Unit)&nbsp;&nbsp;&nbsp;
<input type="hidden" name="sell_price_ex_txt_hidden" id="sell_price_ex_txt_hidden" value="<?=$sell_price_ex_txt_hidden?>" />
<INPUT type="checkbox" name="update_ex_sell_price_checkbox" id="update_ex_sell_price_checkbox" value="1" onclick="javascript:if(this.checked){document.getElementById('sell_price_ex_txt').readOnly = false;}else{document.getElementById('sell_price_ex_txt').readOnly = true;}">&nbsp;&nbsp; Update sell price?&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;

<input type="text" name="sell_price_ex_tot_txt" id="sell_price_ex_tot_txt" size="12" readonly value="<?=$sell_price_ex_tot_txt?>" onkeyup="javascript:check_numeric(this);" />&nbsp;(Total)&nbsp;&nbsp;
<input type="button" name="recalculate_markup" id="recalculate_markup" value=" price re-calculate " onclick="javascript:return call_recalculate_markup('no');" />
</td>
</tr>
<tr>
<td>&nbsp;Sell price inc Tax</td>
<td>
<input type="text" name="sell_price_inc_txt" id="sell_price_inc_txt" size="7" value="<?=$sell_price_inc_txt?>" readonly onkeyup="javascript:check_numeric(this);" />&nbsp;(Unit)<span style="padding: 0 69px;">&nbsp;&nbsp;</span>
<input type="text" name="sell_price_inc_tot_txt" id="sell_price_inc_tot_txt" size="12" readonly value="<?=$sell_price_inc_tot_txt?>" onkeyup="javascript:check_numeric(this);" />&nbsp;(Total)&nbsp;&nbsp;
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td></td>
</tr>
<tr>
<td colspan="2"><b>&nbsp;GP Information</b></td>
</tr>


<tr>
<td>&nbsp;Gross profit</td>
<td>
<input type="text" name="total_gp_txt" id="total_gp_txt" class="readonlytext" size="12" readonly value="<?=$total_gp_txt?>" onkeyup="javascript:check_numeric(this);" />

</td>
</tr>
<tr>
<td>&nbsp;GP %</td>
<td>
<input type="text" name="gp_percentage_txt" id="gp_percentage_txt" class="readonlytext" size="12" readonly value="<?=$gp_percentage_txt?>" onkeyup="" />

</td>
</tr>

<tr>
<td>&nbsp;GP Info on Product</td>
<td>
<input type="text" name="gp_for_product_unit_txt" id="gp_for_product_unit_txt" class="readonlytext" size="12" readonly value="<?=$gp_for_product_unit_txt?>" onkeyup="javascript:check_numeric(this);" />&nbsp;(Unit)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="gp_for_product_tot_txt" id="gp_for_product_tot_txt" class="readonlytext" size="12" readonly value="<?=$gp_for_product_tot_txt?>" onkeyup="javascript:check_numeric(this);" />&nbsp;(Quantity)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<div class="label_span"><label>Item Unit Cost</label>
<input type="text" name="item_unit_without_margin_txt" id="item_unit_without_margin_txt" class="readonlytext" size="12" readonly value="<?=$item_unit_without_margin_txt?>" onkeyup="javascript:check_numeric(this);" /></div>
</td>
</tr>

<tr>
<td>&nbsp;GP Info on Decoration</td>
<td>
<input type="text" name="gp_for_decoration_unit_txt" id="gp_for_decoration_unit_txt" class="readonlytext" size="12" readonly value="<?=$gp_for_decoration_unit_txt?>" onkeyup="javascript:check_numeric(this);" />&nbsp;(Unit)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="gp_for_decoration_tot_txt" id="gp_for_decoration_tot_txt" class="readonlytext" size="12" readonly value="<?=$gp_for_decoration_tot_txt?>" onkeyup="javascript:check_numeric(this);" />&nbsp;(Quantity)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<div class="label_span"><label>Decoration Unit Cost</label>
<input type="text" name="decoration_unit_without_margin_txt" id="decoration_unit_without_margin_txt" class="readonlytext" size="12" readonly value="<?=$decoration_unit_without_margin_txt?>" onkeyup="javascript:check_numeric(this);" /></div>
</td>
</tr>
<tr>
<td>&nbsp;GP Info on Freight markup</td>
<td>
<input type="text" name="gp_for_freight_markup_unit_txt" id="gp_for_freight_markup_unit_txt" class="readonlytext" size="12" readonly value="<?=$gp_for_freight_markup_unit_txt?>" onkeyup="javascript:check_numeric(this);" />&nbsp;(Unit)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="gp_for_freight_markup_tot_txt" id="gp_for_freight_markup_tot_txt" class="readonlytext" size="12" readonly value="<?=$gp_for_freight_markup_tot_txt?>" onkeyup="javascript:check_numeric(this);" />&nbsp;(Quantity)
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<div class="label_span"><label>Freight Unit Cost</label>
<input type="text" name="freight_unit_without_margin_txt" id="freight_unit_without_margin_txt" class="readonlytext" size="12" readonly value="<?=$freight_unit_without_margin_txt?>" onkeyup="javascript:check_numeric(this);" /></div>

</td>
</tr>

<tr>
<td>&nbsp;GP Info on Logo Setup markup</td>
<td>
<input type="text" name="gp_for_setup_markup_unit_txt" id="gp_for_setup_markup_unit_txt" class="readonlytext" size="12" readonly value="<?=$gp_for_setup_markup_unit_txt?>" onkeyup="javascript:check_numeric(this);" />&nbsp;(Unit)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="gp_for_setup_markup_tot_txt" id="gp_for_setup_markup_tot_txt" class="readonlytext" size="12" readonly value="<?=$gp_for_setup_markup_tot_txt?>" onkeyup="javascript:check_numeric(this);" />&nbsp;(Quantity)

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<div class="label_span"><label>Setup Unit Cost</label>
<input type="text" name="setup_unit_without_margin_txt" id="setup_unit_without_margin_txt" class="readonlytext" size="12" readonly value="<?=$setup_unit_without_margin_txt?>" onkeyup="javascript:check_numeric(this);" /></div>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<div class="label_span"><label><b>Total Item Cost:</b></label>
<input type="text" name="total_item_cost_before_margin_txt" id="total_item_cost_before_margin_txt" class="readonlytext" size="12" readonly value="<?=$total_item_cost_before_margin_txt?>" onkeyup="javascript:check_numeric(this);" /></div>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td></td>
</tr>


</table><?php
if(isset($_REQUEST['action']) && (($_REQUEST['action']=='edit') || ($_REQUEST['action']=='update'))){
	$cart_button = 'Save Item';
}
?>
<center><label for="add"></label><input type="submit" name="add" id="add" value="<?=$cart_button?>" class="button" onclick="javascript:return submitform();" style="text-align: center;"/>&nbsp;&nbsp;&nbsp;
<?php
//if(($_REQUEST['action']!='edit')){
?>
<input type="submit" name="add_n_reopen" id="add_n_reopen" value="<?=$cart_button?> + copy data into another qty" class="button" onclick="javascript:return submitform();" style="text-align: center;"/><?php//}
if(isset($_REQUEST['action']) && (($_REQUEST['action']=='edit') || ($_REQUEST['action']=='update'))){
?>
<input type="button" name="cancel" id="cancel" value="Close" class="button" style="text-align: center;margin-left:20px;" onclick="javascript:close_me();"/>
<?php
}
?>
</center>
</form>
</body>
<script type="text/javascript" language="JavaScript">

window.onbeforeunload = function () {
  // window.parent.location.href = "../../www/viewcart/viewcart.php";
};
generate_discounted_price();
function close_me(){
	if (parent) {
	parent.$.fn.colorbox.close();
	}
window.parent.location.href = "../../www/viewcart/viewcart.php";
}
</script><script>function openCity(evt, cityName) {
    var i, tabcontent, tablinks;
    tabcontent = document.getElementsByClassName("tabcontent");
    for (i = 0; i < tabcontent.length; i++) {
        tabcontent[i].style.display = "none";
    }
    tablinks = document.getElementsByClassName("tablinks");
    for (i = 0; i < tablinks.length; i++) {
        tablinks[i].className = tablinks[i].className.replace(" active", "");
    }
    document.getElementById(cityName).style.display = "block";
    evt.currentTarget.className += " active";
}
//Get the element with id="defaultOpen" and click on it

document.getElementById("defaultOpen").click();
</script>
<?php
if(!isset($_POST['add'])){
?>
<script type="text/javascript" language="JavaScript">
this.parent.document.getElementById("display_output_div").innerHTML = "";
</script>
<?php
}
if((isset($_REQUEST['action']) && ($_REQUEST['action']=='edit')) || isset($_POST['add_n_reopen'])){
?>	
<script type="text/javascript" language="JavaScript">
custom_decoration_added_flag = 'yes';
document.getElementById('product_unit_level').style.visibility='visible';
//update_margin_percentage_new(document.getElementById('markup_price1_txt'),'markup');
//update_margin_percentage_new(document.getElementById('decoration_markup_decimal'),'decoration_markup_percentage');

if (document.getElementById('logo_setup_markup_percentage_hidden').value !='') {
	document.getElementById('logo_setup_markup_percentage').options[document.getElementById('logo_setup_markup_percentage_hidden').value-1].selected = 'selected';
	update_markup_using_margin_value(document.getElementById('logo_setup_markup_percentage_hidden').value,'logo_setup_markup_decimal');
}
if (document.getElementById('freight_markup_percentage_hidden').value !='') {
		document.getElementById('freight_markup_percentage').options[document.getElementById('freight_markup_percentage_hidden').value-1].selected = 'selected';
update_markup_using_margin_value(document.getElementById('freight_markup_percentage_hidden').value,'freight_markup_decimal');}
</script>
<?php	
}else{
?>	
<script type="text/javascript" language="JavaScript">
	resetall();if (document.getElementById('logo_setup_markup_percentage_hidden').value !='') {
	document.getElementById('logo_setup_markup_percentage').options[document.getElementById('logo_setup_markup_percentage_hidden').value-1].selected = 'selected';
	update_markup_using_margin_value(document.getElementById('logo_setup_markup_percentage_hidden').value,'logo_setup_markup_decimal');
}
if (document.getElementById('freight_markup_percentage_hidden').value !='') {
		document.getElementById('freight_markup_percentage').options[document.getElementById('freight_markup_percentage_hidden').value-1].selected = 'selected';
update_markup_using_margin_value(document.getElementById('freight_markup_percentage_hidden').value,'freight_markup_decimal');}

</script>
<?php
}
if($standard_product){
?>
<script type="text/javascript" language="JavaScript">
pass_price_to_field(document.getElementById('product_unit_level').value);update_margin_percentage_new(document.getElementById('markup_price1_txt'),'markup');
update_margin_percentage_new(document.getElementById('decoration_markup_decimal'),'decoration_markup_percentage');
</script>
<?php	
}else if($custom_cal_product){?><script type="text/javascript" language="JavaScript">
update_qty(document.getElementById('main_qty_txt').value);update_margin_percentage_new(document.getElementById('markup_price1_txt'),'markup');
update_margin_percentage_new(document.getElementById('decoration_markup_decimal'),'decoration_markup_percentage');
</script>
<?php
}
?>
</html>
<?php
function remove_cart_item($key_id,$sequenceid){
	//require_once "../../bin/quotation.php";

$obj_quote = new Quotation;

$arr_cart_preview = $obj_quote->read_cart_and_preview_for_multi_decoration();
//echo count($arr_cart_preview);
//print_r($_SESSION["cart"]["content"]);
//print_r($arr_cart_preview);
for($a=1;$a<=count($arr_cart_preview);$a++){
	
	if(in_array($key_id, $arr_cart_preview[$a], true)){
/* pass values into form */
		$product_scd = $arr_cart_preview[$a]["product_line_scd"];
		$edit_item_quantity =$arr_cart_preview[$a]["quantity"];
		$edit_item_decoration = $arr_cart_preview[$a]["decoration_type_scd"];
		break;
	}
	
}
/* remove product from cart array */
	if (isset($product_scd) && isset($edit_item_decoration) && isset($edit_item_quantity) && isset($edit_item_custom_product)) {
		$obj_cart = new Cart;
		$obj_cart->remove_customproduct_item($product_scd, $edit_item_decoration, $edit_item_quantity, $sequenceid);
	}	
	elseif (isset($product_scd) && isset($edit_item_decoration) && isset($edit_item_quantity)) {
		$obj_cart = new Cart;
		$obj_cart->remove_item($product_scd, $edit_item_decoration, $edit_item_quantity, $sequenceid);
	}}
?>