<?php
$tdatasales_history_total = array();
$tdatasales_history_total[".searchableFields"] = array();
$tdatasales_history_total[".ShortName"] = "sales_history_total";
$tdatasales_history_total[".OwnerID"] = "";
$tdatasales_history_total[".OriginalTable"] = "sales";


$tdatasales_history_total[".pagesByType"] = my_json_decode( "{\"export\":[\"export\"],\"list\":[\"list\",\"list1\"],\"masterprint\":[\"masterprint\"],\"search\":[\"search\"]}" );
$tdatasales_history_total[".originalPagesByType"] = $tdatasales_history_total[".pagesByType"];
$tdatasales_history_total[".pages"] = types2pages( my_json_decode( "{\"export\":[\"export\"],\"list\":[\"list\",\"list1\"],\"masterprint\":[\"masterprint\"],\"search\":[\"search\"]}" ) );
$tdatasales_history_total[".originalPages"] = $tdatasales_history_total[".pages"];
$tdatasales_history_total[".defaultPages"] = my_json_decode( "{\"export\":\"export\",\"list\":\"list\",\"masterprint\":\"masterprint\",\"search\":\"search\"}" );
$tdatasales_history_total[".originalDefaultPages"] = $tdatasales_history_total[".defaultPages"];

//	field labels
$fieldLabelssales_history_total = array();
$fieldToolTipssales_history_total = array();
$pageTitlessales_history_total = array();
$placeHolderssales_history_total = array();

if(mlang_getcurrentlang()=="English")
{
	$fieldLabelssales_history_total["English"] = array();
	$fieldToolTipssales_history_total["English"] = array();
	$placeHolderssales_history_total["English"] = array();
	$pageTitlessales_history_total["English"] = array();
	$fieldLabelssales_history_total["English"]["customer_id"] = "Customer Id";
	$fieldToolTipssales_history_total["English"]["customer_id"] = "";
	$placeHolderssales_history_total["English"]["customer_id"] = "";
	$fieldLabelssales_history_total["English"]["total_difect"] = "Total Difect";
	$fieldToolTipssales_history_total["English"]["total_difect"] = "";
	$placeHolderssales_history_total["English"]["total_difect"] = "";
	if (count($fieldToolTipssales_history_total["English"]))
		$tdatasales_history_total[".isUseToolTips"] = true;
}


	$tdatasales_history_total[".NCSearch"] = true;



$tdatasales_history_total[".shortTableName"] = "sales_history_total";
$tdatasales_history_total[".nSecOptions"] = 0;

$tdatasales_history_total[".mainTableOwnerID"] = "";
$tdatasales_history_total[".entityType"] = 1;
$tdatasales_history_total[".connId"] = "test2_at_localhost";


$tdatasales_history_total[".strOriginalTableName"] = "sales";

	



$tdatasales_history_total[".showAddInPopup"] = false;

$tdatasales_history_total[".showEditInPopup"] = false;

$tdatasales_history_total[".showViewInPopup"] = false;

//page's base css files names
$popupPagesLayoutNames = array();
$tdatasales_history_total[".popupPagesLayoutNames"] = $popupPagesLayoutNames;


	$tdatasales_history_total[".listAjax"] = true;
//	temporary
$tdatasales_history_total[".listAjax"] = false;

	$tdatasales_history_total[".audit"] = true;

	$tdatasales_history_total[".locking"] = false;


$pages = $tdatasales_history_total[".defaultPages"];

if( $pages[PAGE_EDIT] ) {
	$tdatasales_history_total[".edit"] = true;
	$tdatasales_history_total[".afterEditAction"] = 2;
	$tdatasales_history_total[".closePopupAfterEdit"] = 0;
	$tdatasales_history_total[".afterEditActionDetTable"] = "table5";
}

if( $pages[PAGE_ADD] ) {
$tdatasales_history_total[".add"] = true;
$tdatasales_history_total[".afterAddAction"] = 2;
$tdatasales_history_total[".closePopupAfterAdd"] = 0;
$tdatasales_history_total[".afterAddActionDetTable"] = "payments";
}

if( $pages[PAGE_LIST] ) {
	$tdatasales_history_total[".list"] = true;
}



$tdatasales_history_total[".strSortControlSettingsJSON"] = "";




if( $pages[PAGE_VIEW] ) {
$tdatasales_history_total[".view"] = true;
}

if( $pages[PAGE_IMPORT] ) {
$tdatasales_history_total[".import"] = true;
}

if( $pages[PAGE_EXPORT] ) {
$tdatasales_history_total[".exportTo"] = true;
}

if( $pages[PAGE_PRINT] ) {
$tdatasales_history_total[".printFriendly"] = true;
}



$tdatasales_history_total[".showSimpleSearchOptions"] = true; // temp fix #13449

// Allow Show/Hide Fields in GRID
$tdatasales_history_total[".allowShowHideFields"] = true; // temp fix #13449
//

// Allow Fields Reordering in GRID
$tdatasales_history_total[".allowFieldsReordering"] = true; // temp fix #13449
//

$tdatasales_history_total[".isUseAjaxSuggest"] = true;

$tdatasales_history_total[".rowHighlite"] = true;



																																																																																																						

$tdatasales_history_total[".ajaxCodeSnippetAdded"] = false;

$tdatasales_history_total[".buttonsAdded"] = false;

$tdatasales_history_total[".addPageEvents"] = true;

// use timepicker for search panel
$tdatasales_history_total[".isUseTimeForSearch"] = false;


$tdatasales_history_total[".badgeColor"] = "2f4f4f";


$tdatasales_history_total[".allSearchFields"] = array();
$tdatasales_history_total[".filterFields"] = array();
$tdatasales_history_total[".requiredSearchFields"] = array();

$tdatasales_history_total[".googleLikeFields"] = array();
$tdatasales_history_total[".googleLikeFields"][] = "customer_id";
$tdatasales_history_total[".googleLikeFields"][] = "total_difect";



$tdatasales_history_total[".tableType"] = "list";

$tdatasales_history_total[".printerPageOrientation"] = 0;
$tdatasales_history_total[".nPrinterPageScale"] = 100;

$tdatasales_history_total[".nPrinterSplitRecords"] = 40;

$tdatasales_history_total[".geocodingEnabled"] = false;










$tdatasales_history_total[".pageSize"] = 20;

$tdatasales_history_total[".warnLeavingPages"] = true;



$tstrOrderBy = "";
if(strlen($tstrOrderBy) && strtolower(substr($tstrOrderBy,0,8))!="order by")
	$tstrOrderBy = "order by ".$tstrOrderBy;
$tdatasales_history_total[".strOrderBy"] = $tstrOrderBy;

$tdatasales_history_total[".orderindexes"] = array();


$tdatasales_history_total[".sqlHead"] = "SELECT customer_id,      SUM(difect) AS total_difect";
$tdatasales_history_total[".sqlFrom"] = "FROM (      SELECT          sales.id,sales.`date_&_time`,customer_id,          IFNULL(              CASE                  WHEN (IFNULL(sold.sol, 0) > IFNULL(purch.pur, 0))                  THEN ((IFNULL(sold.sol, 0)) - (IFNULL(purch.pur, 0)) - (IFNULL(`amount`, 0)))              END,              0          ) AS \"difect\"      FROM          sales      LEFT JOIN (SELECT  `m_id`,SUM(`sub_total`) AS sol FROM sales_details WHERE 1          GROUP BY `m_id`) AS sold ON sales.`id` = sold.`m_id`      LEFT JOIN (          SELECT              `sales_id`,              SUM(`amount`) AS pur          FROM              payments          GROUP BY              `sales_id`      ) AS purch ON sales.id = purch.sales_id      LEFT OUTER JOIN sys_manage ON sales.`user` = sys_manage.username      INNER JOIN company_profile ON sys_manage.outlet_code = company_profile.id  ) AS subquery";
$tdatasales_history_total[".sqlWhereExpr"] = "";
$tdatasales_history_total[".sqlTail"] = "";

//fill array of tabs for list page
$arrGridTabs = array();
$arrGridTabs[] = array(
	'tabId' => "",
	'name' => "All data",
	'nameType' => 'Text',
	'where' => "",
	'showRowCount' => 0,
	'hideEmpty' => 0,
);
$tdatasales_history_total[".arrGridTabs"] = $arrGridTabs;









//fill array of records per page for list and report without group fields
$arrRPP = array();
$arrRPP[] = 10;
$arrRPP[] = 20;
$arrRPP[] = 30;
$arrRPP[] = 50;
$arrRPP[] = 100;
$arrRPP[] = 500;
$arrRPP[] = -1;
$tdatasales_history_total[".arrRecsPerPage"] = $arrRPP;

//fill array of groups per page for report with group fields
$arrGPP = array();
$arrGPP[] = 1;
$arrGPP[] = 3;
$arrGPP[] = 5;
$arrGPP[] = 10;
$arrGPP[] = 50;
$arrGPP[] = 100;
$arrGPP[] = -1;
$tdatasales_history_total[".arrGroupsPerPage"] = $arrGPP;

$tdatasales_history_total[".highlightSearchResults"] = true;

$tableKeyssales_history_total = array();
$tdatasales_history_total[".Keys"] = $tableKeyssales_history_total;


$tdatasales_history_total[".hideMobileList"] = array();




//	customer_id
//	Custom field settings
	$fdata = array();
	$fdata["Index"] = 1;
	$fdata["strName"] = "customer_id";
	$fdata["GoodName"] = "customer_id";
	$fdata["ownerTable"] = "";
	$fdata["Label"] = GetFieldLabel("sales_history_total","customer_id");
	$fdata["FieldType"] = 3;

	
	
	
			

		$fdata["strField"] = "customer_id";

	
		$fdata["isSQLExpression"] = true;
	$fdata["FullName"] = "customer_id";

	
	
				$fdata["UploadFolder"] = "files";

//  Begin View Formats
	$fdata["ViewFormats"] = array();

	$vdata = array("ViewFormat" => "");

	
	
	
	
	
	
	
	
	
	
	
		
	
		$vdata["NeedEncode"] = true;

	
		$vdata["truncateText"] = true;
	$vdata["NumberOfChars"] = 80;

	$fdata["ViewFormats"]["view"] = $vdata;
//  End View Formats

//	Begin Edit Formats
	$fdata["EditFormats"] = array();

	$edata = array("EditFormat" => "Readonly");

	
		$edata["weekdayMessage"] = array("message" => "", "messageType" => "Text");
	$edata["weekdays"] = "[]";


	
	



	
	
	
	
			$edata["acceptFileTypes"] = ".+$";
		$edata["acceptFileTypesHtml"] = "";

		$edata["maxNumberOfFiles"] = 1;

	
	
	
	
	
	
		$edata["controlWidth"] = 200;

//	Begin validation
	$edata["validateAs"] = array();
	$edata["validateAs"]["basicValidate"] = array();
	$edata["validateAs"]["customMessages"] = array();
							
	
	//	End validation

	
			
	
	
	
	$fdata["EditFormats"]["edit"] = $edata;
//	End Edit Formats


	$fdata["isSeparate"] = false;




// the field's search options settings
		$fdata["defaultSearchOption"] = "Contains";

			// the default search options list
				$fdata["searchOptionsList"] = array("Contains", "Equals", "Starts with", "More than", "Less than", "Between", "Empty", NOT_EMPTY);
// the end of search options settings


//Filters settings
	$fdata["filterTotals"] = 0;
		$fdata["filterMultiSelect"] = 0;
			$fdata["filterFormat"] = "Values list";
		$fdata["showCollapsed"] = false;

		$fdata["sortValueType"] = 0;
		$fdata["numberOfVisibleItems"] = 10;

		$fdata["filterBy"] = 0;

	

	
	
//end of Filters settings


	$tdatasales_history_total["customer_id"] = $fdata;
		$tdatasales_history_total[".searchableFields"][] = "customer_id";
//	total_difect
//	Custom field settings
	$fdata = array();
	$fdata["Index"] = 2;
	$fdata["strName"] = "total_difect";
	$fdata["GoodName"] = "total_difect";
	$fdata["ownerTable"] = "";
	$fdata["Label"] = GetFieldLabel("sales_history_total","total_difect");
	$fdata["FieldType"] = 14;

	
	
	
			

		$fdata["strField"] = "total_difect";

	
		$fdata["isSQLExpression"] = true;
	$fdata["FullName"] = "SUM(difect)";

	
	
				$fdata["UploadFolder"] = "files";

//  Begin View Formats
	$fdata["ViewFormats"] = array();

	$vdata = array("ViewFormat" => "Number");

	
	
	
	
	
	
		$vdata["DecimalDigits"] = 2;

	
	
	
	
		
	
		$vdata["NeedEncode"] = true;

	
		$vdata["truncateText"] = true;
	$vdata["NumberOfChars"] = 80;

	$fdata["ViewFormats"]["view"] = $vdata;
//  End View Formats

//	Begin Edit Formats
	$fdata["EditFormats"] = array();

	$edata = array("EditFormat" => "Text field");

	
		$edata["weekdayMessage"] = array("message" => "", "messageType" => "Text");
	$edata["weekdays"] = "[]";


	
	



		$edata["IsRequired"] = true;

	
	
	
			$edata["acceptFileTypes"] = ".+$";
		$edata["acceptFileTypesHtml"] = "";

		$edata["maxNumberOfFiles"] = 1;

	
	
	
	
			$edata["HTML5InuptType"] = "text";

		$edata["EditParams"] = "";
		
		$edata["controlWidth"] = 200;

//	Begin validation
	$edata["validateAs"] = array();
	$edata["validateAs"]["basicValidate"] = array();
	$edata["validateAs"]["customMessages"] = array();
				$edata["validateAs"]["basicValidate"][] = getJsValidatorName("Number");
						$edata["validateAs"]["basicValidate"][] = "IsRequired";
		
	
	//	End validation

	
			
	
	
	
	$fdata["EditFormats"]["edit"] = $edata;
//	End Edit Formats


	$fdata["isSeparate"] = false;




// the field's search options settings
		$fdata["defaultSearchOption"] = "Contains";

			// the default search options list
				$fdata["searchOptionsList"] = array("Contains", "Equals", "Starts with", "More than", "Less than", "Between", "Empty", NOT_EMPTY);
// the end of search options settings


//Filters settings
	$fdata["filterTotals"] = 0;
		$fdata["filterMultiSelect"] = 0;
			$fdata["filterFormat"] = "Values list";
		$fdata["showCollapsed"] = false;

		$fdata["sortValueType"] = 0;
		$fdata["numberOfVisibleItems"] = 10;

		$fdata["filterBy"] = 0;

	

	
	
//end of Filters settings


	$tdatasales_history_total["total_difect"] = $fdata;
		$tdatasales_history_total[".searchableFields"][] = "total_difect";


$tables_data["sales_history_total"]=&$tdatasales_history_total;
$field_labels["sales_history_total"] = &$fieldLabelssales_history_total;
$fieldToolTips["sales_history_total"] = &$fieldToolTipssales_history_total;
$placeHolders["sales_history_total"] = &$placeHolderssales_history_total;
$page_titles["sales_history_total"] = &$pageTitlessales_history_total;

// -----------------start  prepare master-details data arrays ------------------------------//
// tables which are detail tables for current table (master)
$detailsTablesData["sales_history_total"] = array();

// tables which are master tables for current table (detail)
$masterTablesData["sales_history_total"] = array();



	
				$strOriginalDetailsTable="sales";
	$masterParams = array();
	$masterParams["mDataSourceTable"]="credit_sales";
	$masterParams["mOriginalTable"]= $strOriginalDetailsTable;
	$masterParams["mShortTable"]= "credit_sales";
	$masterParams["masterKeys"]= array();
	$masterParams["detailKeys"]= array();

	$masterParams["type"] = PAGE_LIST;
					$masterTablesData["sales_history_total"][0] = $masterParams;
				$masterTablesData["sales_history_total"][0]["masterKeys"] = array();
	$masterTablesData["sales_history_total"][0]["masterKeys"][]="customer_id";
				$masterTablesData["sales_history_total"][0]["detailKeys"] = array();
	$masterTablesData["sales_history_total"][0]["detailKeys"][]="customer_id";
		
// -----------------end  prepare master-details data arrays ------------------------------//



require_once(getabspath("classes/sql.php"));











function createSqlQuery_sales_history_total()
{
$proto0=array();
$proto0["m_strHead"] = "SELECT";
$proto0["m_strFieldList"] = "customer_id,      SUM(difect) AS total_difect";
$proto0["m_strFrom"] = "FROM (      SELECT          sales.id,sales.`date_&_time`,customer_id,          IFNULL(              CASE                  WHEN (IFNULL(sold.sol, 0) > IFNULL(purch.pur, 0))                  THEN ((IFNULL(sold.sol, 0)) - (IFNULL(purch.pur, 0)) - (IFNULL(`amount`, 0)))              END,              0          ) AS \"difect\"      FROM          sales      LEFT JOIN (SELECT  `m_id`,SUM(`sub_total`) AS sol FROM sales_details WHERE 1          GROUP BY `m_id`) AS sold ON sales.`id` = sold.`m_id`      LEFT JOIN (          SELECT              `sales_id`,              SUM(`amount`) AS pur          FROM              payments          GROUP BY              `sales_id`      ) AS purch ON sales.id = purch.sales_id      LEFT OUTER JOIN sys_manage ON sales.`user` = sys_manage.username      INNER JOIN company_profile ON sys_manage.outlet_code = company_profile.id  ) AS subquery";
$proto0["m_strWhere"] = "";
$proto0["m_strOrderBy"] = "";
	
		;
			$proto0["cipherer"] = null;
$proto2=array();
$proto2["m_sql"] = "";
$proto2["m_uniontype"] = "SQLL_UNKNOWN";
	$obj = new SQLNonParsed(array(
	"m_sql" => ""
));

$proto2["m_column"]=$obj;
$proto2["m_contained"] = array();
$proto2["m_strCase"] = "";
$proto2["m_havingmode"] = false;
$proto2["m_inBrackets"] = false;
$proto2["m_useAlias"] = false;
$obj = new SQLLogicalExpr($proto2);

$proto0["m_where"] = $obj;
$proto4=array();
$proto4["m_sql"] = "total_difect > 0";
$proto4["m_uniontype"] = "SQLL_UNKNOWN";
						$proto5=array();
			$proto6=array();
$proto6["m_functiontype"] = "SQLF_SUM";
$proto6["m_arguments"] = array();
						$obj = new SQLField(array(
	"m_strName" => "difect",
	"m_strTable" => "subquery",
	"m_srcTableName" => "sales_history_total"
));

$proto6["m_arguments"][]=$obj;
$proto6["m_strFunctionName"] = "SUM";
$obj = new SQLFunctionCall($proto6);

$proto5["m_sql"] = "SUM(difect)";
$proto5["m_srcTableName"] = "sales_history_total";
$proto5["m_expr"]=$obj;
$proto5["m_alias"] = "total_difect";
$obj = new SQLFieldListItem($proto5);

$proto4["m_column"]=$obj;
$proto4["m_contained"] = array();
$proto4["m_strCase"] = "> 0";
$proto4["m_havingmode"] = true;
$proto4["m_inBrackets"] = false;
$proto4["m_useAlias"] = true;
$obj = new SQLLogicalExpr($proto4);

$proto0["m_having"] = $obj;
$proto0["m_fieldlist"] = array();
						$proto8=array();
			$obj = new SQLField(array(
	"m_strName" => "customer_id",
	"m_strTable" => "subquery",
	"m_srcTableName" => "sales_history_total"
));

$proto8["m_sql"] = "customer_id";
$proto8["m_srcTableName"] = "sales_history_total";
$proto8["m_expr"]=$obj;
$proto8["m_alias"] = "";
$obj = new SQLFieldListItem($proto8);

$proto0["m_fieldlist"][]=$obj;
						$proto10=array();
			$proto11=array();
$proto11["m_functiontype"] = "SQLF_SUM";
$proto11["m_arguments"] = array();
						$obj = new SQLField(array(
	"m_strName" => "difect",
	"m_strTable" => "subquery",
	"m_srcTableName" => "sales_history_total"
));

$proto11["m_arguments"][]=$obj;
$proto11["m_strFunctionName"] = "SUM";
$obj = new SQLFunctionCall($proto11);

$proto10["m_sql"] = "SUM(difect)";
$proto10["m_srcTableName"] = "sales_history_total";
$proto10["m_expr"]=$obj;
$proto10["m_alias"] = "total_difect";
$obj = new SQLFieldListItem($proto10);

$proto0["m_fieldlist"][]=$obj;
$proto0["m_fromlist"] = array();
												$proto13=array();
$proto13["m_link"] = "SQLL_MAIN";
			$proto14=array();
$proto14["m_strHead"] = "      SELECT";
$proto14["m_strFieldList"] = "sales.id,sales.`date_&_time`,customer_id,          IFNULL(              CASE                  WHEN (IFNULL(sold.sol, 0) > IFNULL(purch.pur, 0))                  THEN ((IFNULL(sold.sol, 0)) - (IFNULL(purch.pur, 0)) - (IFNULL(`amount`, 0)))              END,              0          ) AS \"difect\"";
$proto14["m_strFrom"] = "FROM          sales      LEFT JOIN (SELECT  `m_id`,SUM(`sub_total`) AS sol FROM sales_details WHERE 1          GROUP BY `m_id`) AS sold ON sales.`id` = sold.`m_id`      LEFT JOIN (          SELECT              `sales_id`,              SUM(`amount`) AS pur          FROM              payments          GROUP BY              `sales_id`      ) AS purch ON sales.id = purch.sales_id      LEFT OUTER JOIN sys_manage ON sales.`user` = sys_manage.username      INNER JOIN company_profile ON sys_manage.outlet_code = company_profile.id";
$proto14["m_strWhere"] = "";
$proto14["m_strOrderBy"] = "";
	
		;
			$proto14["cipherer"] = null;
$proto16=array();
$proto16["m_sql"] = "";
$proto16["m_uniontype"] = "SQLL_UNKNOWN";
	$obj = new SQLNonParsed(array(
	"m_sql" => ""
));

$proto16["m_column"]=$obj;
$proto16["m_contained"] = array();
$proto16["m_strCase"] = "";
$proto16["m_havingmode"] = false;
$proto16["m_inBrackets"] = false;
$proto16["m_useAlias"] = false;
$obj = new SQLLogicalExpr($proto16);

$proto14["m_where"] = $obj;
$proto18=array();
$proto18["m_sql"] = "";
$proto18["m_uniontype"] = "SQLL_UNKNOWN";
	$obj = new SQLNonParsed(array(
	"m_sql" => ""
));

$proto18["m_column"]=$obj;
$proto18["m_contained"] = array();
$proto18["m_strCase"] = "";
$proto18["m_havingmode"] = false;
$proto18["m_inBrackets"] = false;
$proto18["m_useAlias"] = false;
$obj = new SQLLogicalExpr($proto18);

$proto14["m_having"] = $obj;
$proto14["m_fieldlist"] = array();
						$proto20=array();
			$obj = new SQLField(array(
	"m_strName" => "id",
	"m_strTable" => "sales",
	"m_srcTableName" => "sales_history_total"
));

$proto20["m_sql"] = "sales.id";
$proto20["m_srcTableName"] = "sales_history_total";
$proto20["m_expr"]=$obj;
$proto20["m_alias"] = "";
$obj = new SQLFieldListItem($proto20);

$proto14["m_fieldlist"][]=$obj;
						$proto22=array();
			$obj = new SQLField(array(
	"m_strName" => "date_&_time",
	"m_strTable" => "sales",
	"m_srcTableName" => "sales_history_total"
));

$proto22["m_sql"] = "sales.`date_&_time`";
$proto22["m_srcTableName"] = "sales_history_total";
$proto22["m_expr"]=$obj;
$proto22["m_alias"] = "";
$obj = new SQLFieldListItem($proto22);

$proto14["m_fieldlist"][]=$obj;
						$proto24=array();
			$obj = new SQLField(array(
	"m_strName" => "customer_id",
	"m_strTable" => "sales",
	"m_srcTableName" => "sales_history_total"
));

$proto24["m_sql"] = "customer_id";
$proto24["m_srcTableName"] = "sales_history_total";
$proto24["m_expr"]=$obj;
$proto24["m_alias"] = "";
$obj = new SQLFieldListItem($proto24);

$proto14["m_fieldlist"][]=$obj;
						$proto26=array();
			$proto27=array();
$proto27["m_functiontype"] = "SQLF_CUSTOM";
$proto27["m_arguments"] = array();
						$obj = new SQLNonParsed(array(
	"m_sql" => "CASE                  WHEN (IFNULL(sold.sol, 0) > IFNULL(purch.pur, 0))                  THEN ((IFNULL(sold.sol, 0)) - (IFNULL(purch.pur, 0)) - (IFNULL(`amount`, 0)))              END"
));

$proto27["m_arguments"][]=$obj;
						$obj = new SQLNonParsed(array(
	"m_sql" => "0"
));

$proto27["m_arguments"][]=$obj;
$proto27["m_strFunctionName"] = "IFNULL";
$obj = new SQLFunctionCall($proto27);

$proto26["m_sql"] = "IFNULL(              CASE                  WHEN (IFNULL(sold.sol, 0) > IFNULL(purch.pur, 0))                  THEN ((IFNULL(sold.sol, 0)) - (IFNULL(purch.pur, 0)) - (IFNULL(`amount`, 0)))              END,              0          )";
$proto26["m_srcTableName"] = "sales_history_total";
$proto26["m_expr"]=$obj;
$proto26["m_alias"] = "difect";
$obj = new SQLFieldListItem($proto26);

$proto14["m_fieldlist"][]=$obj;
$proto14["m_fromlist"] = array();
												$proto30=array();
$proto30["m_link"] = "SQLL_MAIN";
			$proto31=array();
$proto31["m_strName"] = "sales";
$proto31["m_srcTableName"] = "sales_history_total";
$proto31["m_columns"] = array();
$proto31["m_columns"][] = "id";
$proto31["m_columns"][] = "customer_name";
$proto31["m_columns"][] = "cash";
$proto31["m_columns"][] = "tt";
$proto31["m_columns"][] = "date_&_time";
$proto31["m_columns"][] = "branch_code";
$proto31["m_columns"][] = "user";
$proto31["m_columns"][] = "outlet_code";
$proto31["m_columns"][] = "h";
$proto31["m_columns"][] = "f";
$proto31["m_columns"][] = "advance_id";
$proto31["m_columns"][] = "amount";
$proto31["m_columns"][] = "left_advance";
$proto31["m_columns"][] = "details";
$proto31["m_columns"][] = "status";
$proto31["m_columns"][] = "customer_id";
$obj = new SQLTable($proto31);

$proto30["m_table"] = $obj;
$proto30["m_sql"] = "sales";
$proto30["m_alias"] = "";
$proto30["m_srcTableName"] = "sales_history_total";
$proto32=array();
$proto32["m_sql"] = "";
$proto32["m_uniontype"] = "SQLL_UNKNOWN";
	$obj = new SQLNonParsed(array(
	"m_sql" => ""
));

$proto32["m_column"]=$obj;
$proto32["m_contained"] = array();
$proto32["m_strCase"] = "";
$proto32["m_havingmode"] = false;
$proto32["m_inBrackets"] = false;
$proto32["m_useAlias"] = false;
$obj = new SQLLogicalExpr($proto32);

$proto30["m_joinon"] = $obj;
$obj = new SQLFromListItem($proto30);

$proto14["m_fromlist"][]=$obj;
												$proto34=array();
$proto34["m_link"] = "SQLL_LEFTJOIN";
			$proto35=array();
$proto35["m_strHead"] = "SELECT";
$proto35["m_strFieldList"] = "`m_id`,SUM(`sub_total`) AS sol";
$proto35["m_strFrom"] = "FROM sales_details";
$proto35["m_strWhere"] = "1";
$proto35["m_strOrderBy"] = "";
	
		;
			$proto35["cipherer"] = null;
$proto37=array();
$proto37["m_sql"] = "1";
$proto37["m_uniontype"] = "SQLL_UNKNOWN";
						$obj = new SQLNonParsed(array(
	"m_sql" => "1"
));

$proto37["m_column"]=$obj;
$proto37["m_contained"] = array();
$proto37["m_strCase"] = "= True";
$proto37["m_havingmode"] = false;
$proto37["m_inBrackets"] = false;
$proto37["m_useAlias"] = false;
$obj = new SQLLogicalExpr($proto37);

$proto35["m_where"] = $obj;
$proto39=array();
$proto39["m_sql"] = "";
$proto39["m_uniontype"] = "SQLL_UNKNOWN";
	$obj = new SQLNonParsed(array(
	"m_sql" => ""
));

$proto39["m_column"]=$obj;
$proto39["m_contained"] = array();
$proto39["m_strCase"] = "";
$proto39["m_havingmode"] = false;
$proto39["m_inBrackets"] = false;
$proto39["m_useAlias"] = false;
$obj = new SQLLogicalExpr($proto39);

$proto35["m_having"] = $obj;
$proto35["m_fieldlist"] = array();
						$proto41=array();
			$obj = new SQLField(array(
	"m_strName" => "m_id",
	"m_strTable" => "sales_details",
	"m_srcTableName" => "sales_history_total"
));

$proto41["m_sql"] = "`m_id`";
$proto41["m_srcTableName"] = "sales_history_total";
$proto41["m_expr"]=$obj;
$proto41["m_alias"] = "";
$obj = new SQLFieldListItem($proto41);

$proto35["m_fieldlist"][]=$obj;
						$proto43=array();
			$proto44=array();
$proto44["m_functiontype"] = "SQLF_SUM";
$proto44["m_arguments"] = array();
						$obj = new SQLField(array(
	"m_strName" => "sub_total",
	"m_strTable" => "sales_details",
	"m_srcTableName" => "sales_history_total"
));

$proto44["m_arguments"][]=$obj;
$proto44["m_strFunctionName"] = "SUM";
$obj = new SQLFunctionCall($proto44);

$proto43["m_sql"] = "SUM(`sub_total`)";
$proto43["m_srcTableName"] = "sales_history_total";
$proto43["m_expr"]=$obj;
$proto43["m_alias"] = "sol";
$obj = new SQLFieldListItem($proto43);

$proto35["m_fieldlist"][]=$obj;
$proto35["m_fromlist"] = array();
												$proto46=array();
$proto46["m_link"] = "SQLL_MAIN";
			$proto47=array();
$proto47["m_strName"] = "sales_details";
$proto47["m_srcTableName"] = "sales_history_total";
$proto47["m_columns"] = array();
$proto47["m_columns"][] = "id";
$proto47["m_columns"][] = "bar_code";
$proto47["m_columns"][] = "product";
$proto47["m_columns"][] = "quntity";
$proto47["m_columns"][] = "price";
$proto47["m_columns"][] = "m_id";
$proto47["m_columns"][] = "sub_total";
$proto47["m_columns"][] = "user";
$proto47["m_columns"][] = "discount";
$proto47["m_columns"][] = "tax";
$proto47["m_columns"][] = "newp";
$proto47["m_columns"][] = "stk_tra";
$proto47["m_columns"][] = "unit";
$proto47["m_columns"][] = "stk_tra_status";
$proto47["m_columns"][] = "package_details";
$proto47["m_columns"][] = "date_time";
$proto47["m_columns"][] = "outlet_code";
$obj = new SQLTable($proto47);

$proto46["m_table"] = $obj;
$proto46["m_sql"] = "sales_details";
$proto46["m_alias"] = "";
$proto46["m_srcTableName"] = "sales_history_total";
$proto48=array();
$proto48["m_sql"] = "";
$proto48["m_uniontype"] = "SQLL_UNKNOWN";
	$obj = new SQLNonParsed(array(
	"m_sql" => ""
));

$proto48["m_column"]=$obj;
$proto48["m_contained"] = array();
$proto48["m_strCase"] = "";
$proto48["m_havingmode"] = false;
$proto48["m_inBrackets"] = false;
$proto48["m_useAlias"] = false;
$obj = new SQLLogicalExpr($proto48);

$proto46["m_joinon"] = $obj;
$obj = new SQLFromListItem($proto46);

$proto35["m_fromlist"][]=$obj;
$proto35["m_groupby"] = array();
												$proto50=array();
						$obj = new SQLField(array(
	"m_strName" => "m_id",
	"m_strTable" => "sales_details",
	"m_srcTableName" => "sales_history_total"
));

$proto50["m_column"]=$obj;
$obj = new SQLGroupByItem($proto50);

$proto35["m_groupby"][]=$obj;
$proto35["m_orderby"] = array();
$proto35["m_srcTableName"]="sales_history_total";		
$obj = new SQLQuery($proto35);

$proto34["m_table"] = $obj;
$proto34["m_sql"] = "LEFT JOIN (SELECT  `m_id`,SUM(`sub_total`) AS sol FROM sales_details WHERE 1          GROUP BY `m_id`) AS sold ON sales.`id` = sold.`m_id`";
$proto34["m_alias"] = "sold";
$proto34["m_srcTableName"] = "sales_history_total";
$proto52=array();
$proto52["m_sql"] = "sales.`id` = sold.`m_id`";
$proto52["m_uniontype"] = "SQLL_UNKNOWN";
						$obj = new SQLField(array(
	"m_strName" => "id",
	"m_strTable" => "sales",
	"m_srcTableName" => "sales_history_total"
));

$proto52["m_column"]=$obj;
$proto52["m_contained"] = array();
$proto52["m_strCase"] = "= sold.`m_id`";
$proto52["m_havingmode"] = false;
$proto52["m_inBrackets"] = false;
$proto52["m_useAlias"] = false;
$obj = new SQLLogicalExpr($proto52);

$proto34["m_joinon"] = $obj;
$obj = new SQLFromListItem($proto34);

$proto14["m_fromlist"][]=$obj;
												$proto54=array();
$proto54["m_link"] = "SQLL_LEFTJOIN";
			$proto55=array();
$proto55["m_strHead"] = "          SELECT";
$proto55["m_strFieldList"] = "`sales_id`,              SUM(`amount`) AS pur";
$proto55["m_strFrom"] = "FROM              payments";
$proto55["m_strWhere"] = "";
$proto55["m_strOrderBy"] = "";
	
		;
			$proto55["cipherer"] = null;
$proto57=array();
$proto57["m_sql"] = "";
$proto57["m_uniontype"] = "SQLL_UNKNOWN";
	$obj = new SQLNonParsed(array(
	"m_sql" => ""
));

$proto57["m_column"]=$obj;
$proto57["m_contained"] = array();
$proto57["m_strCase"] = "";
$proto57["m_havingmode"] = false;
$proto57["m_inBrackets"] = false;
$proto57["m_useAlias"] = false;
$obj = new SQLLogicalExpr($proto57);

$proto55["m_where"] = $obj;
$proto59=array();
$proto59["m_sql"] = "";
$proto59["m_uniontype"] = "SQLL_UNKNOWN";
	$obj = new SQLNonParsed(array(
	"m_sql" => ""
));

$proto59["m_column"]=$obj;
$proto59["m_contained"] = array();
$proto59["m_strCase"] = "";
$proto59["m_havingmode"] = false;
$proto59["m_inBrackets"] = false;
$proto59["m_useAlias"] = false;
$obj = new SQLLogicalExpr($proto59);

$proto55["m_having"] = $obj;
$proto55["m_fieldlist"] = array();
						$proto61=array();
			$obj = new SQLField(array(
	"m_strName" => "sales_id",
	"m_strTable" => "payments",
	"m_srcTableName" => "sales_history_total"
));

$proto61["m_sql"] = "`sales_id`";
$proto61["m_srcTableName"] = "sales_history_total";
$proto61["m_expr"]=$obj;
$proto61["m_alias"] = "";
$obj = new SQLFieldListItem($proto61);

$proto55["m_fieldlist"][]=$obj;
						$proto63=array();
			$proto64=array();
$proto64["m_functiontype"] = "SQLF_SUM";
$proto64["m_arguments"] = array();
						$obj = new SQLField(array(
	"m_strName" => "amount",
	"m_strTable" => "payments",
	"m_srcTableName" => "sales_history_total"
));

$proto64["m_arguments"][]=$obj;
$proto64["m_strFunctionName"] = "SUM";
$obj = new SQLFunctionCall($proto64);

$proto63["m_sql"] = "SUM(`amount`)";
$proto63["m_srcTableName"] = "sales_history_total";
$proto63["m_expr"]=$obj;
$proto63["m_alias"] = "pur";
$obj = new SQLFieldListItem($proto63);

$proto55["m_fieldlist"][]=$obj;
$proto55["m_fromlist"] = array();
												$proto66=array();
$proto66["m_link"] = "SQLL_MAIN";
			$proto67=array();
$proto67["m_strName"] = "payments";
$proto67["m_srcTableName"] = "sales_history_total";
$proto67["m_columns"] = array();
$proto67["m_columns"][] = "id";
$proto67["m_columns"][] = "sales_id";
$proto67["m_columns"][] = "type";
$proto67["m_columns"][] = "amount";
$proto67["m_columns"][] = "cheque_number";
$proto67["m_columns"][] = "cheque_date";
$proto67["m_columns"][] = "hide";
$proto67["m_columns"][] = "status";
$proto67["m_columns"][] = "opening_balance_id";
$proto67["m_columns"][] = "outlet";
$proto67["m_columns"][] = "date_time";
$proto67["m_columns"][] = "user";
$proto67["m_columns"][] = "status_2";
$obj = new SQLTable($proto67);

$proto66["m_table"] = $obj;
$proto66["m_sql"] = "payments";
$proto66["m_alias"] = "";
$proto66["m_srcTableName"] = "sales_history_total";
$proto68=array();
$proto68["m_sql"] = "";
$proto68["m_uniontype"] = "SQLL_UNKNOWN";
	$obj = new SQLNonParsed(array(
	"m_sql" => ""
));

$proto68["m_column"]=$obj;
$proto68["m_contained"] = array();
$proto68["m_strCase"] = "";
$proto68["m_havingmode"] = false;
$proto68["m_inBrackets"] = false;
$proto68["m_useAlias"] = false;
$obj = new SQLLogicalExpr($proto68);

$proto66["m_joinon"] = $obj;
$obj = new SQLFromListItem($proto66);

$proto55["m_fromlist"][]=$obj;
$proto55["m_groupby"] = array();
												$proto70=array();
						$obj = new SQLField(array(
	"m_strName" => "sales_id",
	"m_strTable" => "payments",
	"m_srcTableName" => "sales_history_total"
));

$proto70["m_column"]=$obj;
$obj = new SQLGroupByItem($proto70);

$proto55["m_groupby"][]=$obj;
$proto55["m_orderby"] = array();
$proto55["m_srcTableName"]="sales_history_total";		
$obj = new SQLQuery($proto55);

$proto54["m_table"] = $obj;
$proto54["m_sql"] = "LEFT JOIN (          SELECT              `sales_id`,              SUM(`amount`) AS pur          FROM              payments          GROUP BY              `sales_id`      ) AS purch ON sales.id = purch.sales_id";
$proto54["m_alias"] = "purch";
$proto54["m_srcTableName"] = "sales_history_total";
$proto72=array();
$proto72["m_sql"] = "sales.id = purch.sales_id";
$proto72["m_uniontype"] = "SQLL_UNKNOWN";
						$obj = new SQLField(array(
	"m_strName" => "id",
	"m_strTable" => "sales",
	"m_srcTableName" => "sales_history_total"
));

$proto72["m_column"]=$obj;
$proto72["m_contained"] = array();
$proto72["m_strCase"] = "= purch.sales_id";
$proto72["m_havingmode"] = false;
$proto72["m_inBrackets"] = false;
$proto72["m_useAlias"] = false;
$obj = new SQLLogicalExpr($proto72);

$proto54["m_joinon"] = $obj;
$obj = new SQLFromListItem($proto54);

$proto14["m_fromlist"][]=$obj;
												$proto74=array();
$proto74["m_link"] = "SQLL_LEFTJOIN";
			$proto75=array();
$proto75["m_strName"] = "sys_manage";
$proto75["m_srcTableName"] = "sales_history_total";
$proto75["m_columns"] = array();
$proto75["m_columns"][] = "ID";
$proto75["m_columns"][] = "username";
$proto75["m_columns"][] = "password";
$proto75["m_columns"][] = "email";
$proto75["m_columns"][] = "fullname";
$proto75["m_columns"][] = "groupid";
$proto75["m_columns"][] = "active";
$proto75["m_columns"][] = "ext_security_id";
$proto75["m_columns"][] = "reset_token";
$proto75["m_columns"][] = "reset_date";
$proto75["m_columns"][] = "teliphone_number";
$proto75["m_columns"][] = "date";
$proto75["m_columns"][] = "branch_code";
$proto75["m_columns"][] = "outlet_code";
$proto75["m_columns"][] = "MyTheme";
$proto75["m_columns"][] = "MyThemeSize";
$proto75["m_columns"][] = "password2";
$obj = new SQLTable($proto75);

$proto74["m_table"] = $obj;
$proto74["m_sql"] = "LEFT OUTER JOIN sys_manage ON sales.`user` = sys_manage.username";
$proto74["m_alias"] = "";
$proto74["m_srcTableName"] = "sales_history_total";
$proto76=array();
$proto76["m_sql"] = "sales.`user` = sys_manage.username";
$proto76["m_uniontype"] = "SQLL_UNKNOWN";
						$obj = new SQLField(array(
	"m_strName" => "user",
	"m_strTable" => "sales",
	"m_srcTableName" => "sales_history_total"
));

$proto76["m_column"]=$obj;
$proto76["m_contained"] = array();
$proto76["m_strCase"] = "= sys_manage.username";
$proto76["m_havingmode"] = false;
$proto76["m_inBrackets"] = false;
$proto76["m_useAlias"] = false;
$obj = new SQLLogicalExpr($proto76);

$proto74["m_joinon"] = $obj;
$obj = new SQLFromListItem($proto74);

$proto14["m_fromlist"][]=$obj;
												$proto78=array();
$proto78["m_link"] = "SQLL_INNERJOIN";
			$proto79=array();
$proto79["m_strName"] = "company_profile";
$proto79["m_srcTableName"] = "sales_history_total";
$proto79["m_columns"] = array();
$proto79["m_columns"][] = "id";
$proto79["m_columns"][] = "company_name";
$proto79["m_columns"][] = "address_line_1";
$proto79["m_columns"][] = "address_line_2";
$proto79["m_columns"][] = "country";
$proto79["m_columns"][] = "provinces";
$proto79["m_columns"][] = "districts";
$proto79["m_columns"][] = "postal_code";
$proto79["m_columns"][] = "hot_line";
$proto79["m_columns"][] = "Fax";
$proto79["m_columns"][] = "email";
$proto79["m_columns"][] = "logo";
$proto79["m_columns"][] = "branch_code";
$proto79["m_columns"][] = "header";
$proto79["m_columns"][] = "footer";
$proto79["m_columns"][] = "time_calibration";
$obj = new SQLTable($proto79);

$proto78["m_table"] = $obj;
$proto78["m_sql"] = "INNER JOIN company_profile ON sys_manage.outlet_code = company_profile.id";
$proto78["m_alias"] = "";
$proto78["m_srcTableName"] = "sales_history_total";
$proto80=array();
$proto80["m_sql"] = "sys_manage.outlet_code = company_profile.id";
$proto80["m_uniontype"] = "SQLL_UNKNOWN";
						$obj = new SQLField(array(
	"m_strName" => "outlet_code",
	"m_strTable" => "sys_manage",
	"m_srcTableName" => "sales_history_total"
));

$proto80["m_column"]=$obj;
$proto80["m_contained"] = array();
$proto80["m_strCase"] = "= company_profile.id";
$proto80["m_havingmode"] = false;
$proto80["m_inBrackets"] = false;
$proto80["m_useAlias"] = false;
$obj = new SQLLogicalExpr($proto80);

$proto78["m_joinon"] = $obj;
$obj = new SQLFromListItem($proto78);

$proto14["m_fromlist"][]=$obj;
$proto14["m_groupby"] = array();
$proto14["m_orderby"] = array();
$proto14["m_srcTableName"]="sales_history_total";		
$obj = new SQLQuery($proto14);

$proto13["m_table"] = $obj;
$proto13["m_sql"] = "(      SELECT          sales.id,sales.`date_&_time`,customer_id,          IFNULL(              CASE                  WHEN (IFNULL(sold.sol, 0) > IFNULL(purch.pur, 0))                  THEN ((IFNULL(sold.sol, 0)) - (IFNULL(purch.pur, 0)) - (IFNULL(`amount`, 0)))              END,              0          ) AS \"difect\"      FROM          sales      LEFT JOIN (SELECT  `m_id`,SUM(`sub_total`) AS sol FROM sales_details WHERE 1          GROUP BY `m_id`) AS sold ON sales.`id` = sold.`m_id`      LEFT JOIN (          SELECT              `sales_id`,              SUM(`amount`) AS pur          FROM              payments          GROUP BY              `sales_id`      ) AS purch ON sales.id = purch.sales_id      LEFT OUTER JOIN sys_manage ON sales.`user` = sys_manage.username      INNER JOIN company_profile ON sys_manage.outlet_code = company_profile.id  ) AS subquery";
$proto13["m_alias"] = "subquery";
$proto13["m_srcTableName"] = "sales_history_total";
$proto82=array();
$proto82["m_sql"] = "";
$proto82["m_uniontype"] = "SQLL_UNKNOWN";
	$obj = new SQLNonParsed(array(
	"m_sql" => ""
));

$proto82["m_column"]=$obj;
$proto82["m_contained"] = array();
$proto82["m_strCase"] = "";
$proto82["m_havingmode"] = false;
$proto82["m_inBrackets"] = false;
$proto82["m_useAlias"] = false;
$obj = new SQLLogicalExpr($proto82);

$proto13["m_joinon"] = $obj;
$obj = new SQLFromListItem($proto13);

$proto0["m_fromlist"][]=$obj;
$proto0["m_groupby"] = array();
												$proto84=array();
						$obj = new SQLField(array(
	"m_strName" => "customer_id",
	"m_strTable" => "subquery",
	"m_srcTableName" => "sales_history_total"
));

$proto84["m_column"]=$obj;
$obj = new SQLGroupByItem($proto84);

$proto0["m_groupby"][]=$obj;
$proto0["m_orderby"] = array();
$proto0["m_srcTableName"]="sales_history_total";		
$obj = new SQLQuery($proto0);

	return $obj;
}
$queryData_sales_history_total = createSqlQuery_sales_history_total();


	
		;

		

$tdatasales_history_total[".sqlquery"] = $queryData_sales_history_total;



include_once(getabspath("include/sales_history_total_events.php"));
$tableEvents["sales_history_total"] = new eventclass_sales_history_total;
$tdatasales_history_total[".hasEvents"] = true;

?>