<?php
// This script and data application were generated by AppGini 5.76
// Download AppGini for free from https://bigprof.com/appgini/download/

	$currDir=dirname(__FILE__);
	include("$currDir/defaultLang.php");
	include("$currDir/language.php");
	include("$currDir/lib.php");
	@include("$currDir/hooks/transferts_argent.php");
	include("$currDir/transferts_argent_dml.php");

	// mm: can the current member access this page?
	$perm=getTablePermissions('transferts_argent');
	if(!$perm[0]){
		echo error_message($Translation['tableAccessDenied'], false);
		echo '<script>setTimeout("window.location=\'index.php?signOut=1\'", 2000);</script>';
		exit;
	}

	$x = new DataList;
	$x->TableName = "transferts_argent";

	// Fields that can be displayed in the table view
	$x->QueryFieldsTV = array(   
		"`transferts_argent`.`idtransfert`" => "idtransfert",
		"`transferts_argent`.`num_facture`" => "num_facture",
		"`transferts_argent`.`code_transaction`" => "code_transaction",
		"if(`transferts_argent`.`date`,date_format(`transferts_argent`.`date`,'%d/%m/%Y'),'')" => "date",
		"IF(    CHAR_LENGTH(`clients1`.`nom_prenom`), CONCAT_WS('',   `clients1`.`nom_prenom`), '') /* Nom & Pr&#233;nom Emetteur */" => "emetteur",
		"IF(    CHAR_LENGTH(`clients1`.`nni`), CONCAT_WS('',   `clients1`.`nni`), '') /* NNI Emetteur */" => "nni_emetteur",
		"IF(    CHAR_LENGTH(`clients1`.`telephone`), CONCAT_WS('',   `clients1`.`telephone`), '') /* T&#233;l&#233;phone Emetteur */" => "phone_emetteur",
		"IF(    CHAR_LENGTH(`clients1`.`adresse`), CONCAT_WS('',   `clients1`.`adresse`), '') /* Adresse Emetteur */" => "adresse_emetteur",
		"`transferts_argent`.`beneficiaire`" => "beneficiaire",
		"`transferts_argent`.`nni_beneficiaire`" => "nni_beneficiaire",
		"`transferts_argent`.`phone_beneficiaire`" => "phone_beneficiaire",
		"`transferts_argent`.`adresse_beneficiaire`" => "adresse_beneficiaire",
		"`transferts_argent`.`prix_achat`" => "prix_achat",
		"`transferts_argent`.`commission`" => "commission",
		"`transferts_argent`.`total`" => "total",
		"`transferts_argent`.`statut`" => "statut",
		"`transferts_argent`.`observation`" => "observation"
	);
	// mapping incoming sort by requests to actual query fields
	$x->SortFields = array(   
		1 => '`transferts_argent`.`idtransfert`',
		2 => 2,
		3 => '`transferts_argent`.`code_transaction`',
		4 => '`transferts_argent`.`date`',
		5 => '`clients1`.`nom_prenom`',
		6 => '`clients1`.`nni`',
		7 => '`clients1`.`telephone`',
		8 => '`clients1`.`adresse`',
		9 => 9,
		10 => 10,
		11 => 11,
		12 => 12,
		13 => '`transferts_argent`.`prix_achat`',
		14 => '`transferts_argent`.`commission`',
		15 => '`transferts_argent`.`total`',
		16 => 16,
		17 => 17
	);

	// Fields that can be displayed in the csv file
	$x->QueryFieldsCSV = array(   
		"`transferts_argent`.`idtransfert`" => "idtransfert",
		"`transferts_argent`.`num_facture`" => "num_facture",
		"`transferts_argent`.`code_transaction`" => "code_transaction",
		"if(`transferts_argent`.`date`,date_format(`transferts_argent`.`date`,'%d/%m/%Y'),'')" => "date",
		"IF(    CHAR_LENGTH(`clients1`.`nom_prenom`), CONCAT_WS('',   `clients1`.`nom_prenom`), '') /* Nom & Pr&#233;nom Emetteur */" => "emetteur",
		"IF(    CHAR_LENGTH(`clients1`.`nni`), CONCAT_WS('',   `clients1`.`nni`), '') /* NNI Emetteur */" => "nni_emetteur",
		"IF(    CHAR_LENGTH(`clients1`.`telephone`), CONCAT_WS('',   `clients1`.`telephone`), '') /* T&#233;l&#233;phone Emetteur */" => "phone_emetteur",
		"IF(    CHAR_LENGTH(`clients1`.`adresse`), CONCAT_WS('',   `clients1`.`adresse`), '') /* Adresse Emetteur */" => "adresse_emetteur",
		"`transferts_argent`.`beneficiaire`" => "beneficiaire",
		"`transferts_argent`.`nni_beneficiaire`" => "nni_beneficiaire",
		"`transferts_argent`.`phone_beneficiaire`" => "phone_beneficiaire",
		"`transferts_argent`.`adresse_beneficiaire`" => "adresse_beneficiaire",
		"`transferts_argent`.`prix_achat`" => "prix_achat",
		"`transferts_argent`.`commission`" => "commission",
		"`transferts_argent`.`total`" => "total",
		"`transferts_argent`.`statut`" => "statut",
		"`transferts_argent`.`observation`" => "observation"
	);
	// Fields that can be filtered
	$x->QueryFieldsFilters = array(   
		"`transferts_argent`.`idtransfert`" => "id",
		"`transferts_argent`.`num_facture`" => "N&#176; Facture",
		"`transferts_argent`.`code_transaction`" => "Code transaction",
		"`transferts_argent`.`date`" => "Date",
		"IF(    CHAR_LENGTH(`clients1`.`nom_prenom`), CONCAT_WS('',   `clients1`.`nom_prenom`), '') /* Nom & Pr&#233;nom Emetteur */" => "Nom & Pr&#233;nom Emetteur",
		"IF(    CHAR_LENGTH(`clients1`.`nni`), CONCAT_WS('',   `clients1`.`nni`), '') /* NNI Emetteur */" => "NNI Emetteur",
		"IF(    CHAR_LENGTH(`clients1`.`telephone`), CONCAT_WS('',   `clients1`.`telephone`), '') /* T&#233;l&#233;phone Emetteur */" => "T&#233;l&#233;phone Emetteur",
		"IF(    CHAR_LENGTH(`clients1`.`adresse`), CONCAT_WS('',   `clients1`.`adresse`), '') /* Adresse Emetteur */" => "Adresse Emetteur",
		"`transferts_argent`.`beneficiaire`" => "Nom & Pr&#233;nom B&#233;n&#233;ficiaire",
		"`transferts_argent`.`nni_beneficiaire`" => "NNI B&#233;n&#233;ficiaire",
		"`transferts_argent`.`phone_beneficiaire`" => "T&#233;l&#233;phone B&#233;n&#233;ficiaire",
		"`transferts_argent`.`adresse_beneficiaire`" => "Adresse B&#233;n&#233;ficiaire",
		"`transferts_argent`.`prix_achat`" => "Montant envoy&#233;",
		"`transferts_argent`.`commission`" => "Commission",
		"`transferts_argent`.`total`" => "Net &#224; payer",
		"`transferts_argent`.`statut`" => "Statut",
		"`transferts_argent`.`observation`" => "Observation"
	);

	// Fields that can be quick searched
	$x->QueryFieldsQS = array(   
		"`transferts_argent`.`idtransfert`" => "idtransfert",
		"`transferts_argent`.`num_facture`" => "num_facture",
		"`transferts_argent`.`code_transaction`" => "code_transaction",
		"if(`transferts_argent`.`date`,date_format(`transferts_argent`.`date`,'%d/%m/%Y'),'')" => "date",
		"IF(    CHAR_LENGTH(`clients1`.`nom_prenom`), CONCAT_WS('',   `clients1`.`nom_prenom`), '') /* Nom & Pr&#233;nom Emetteur */" => "emetteur",
		"IF(    CHAR_LENGTH(`clients1`.`nni`), CONCAT_WS('',   `clients1`.`nni`), '') /* NNI Emetteur */" => "nni_emetteur",
		"IF(    CHAR_LENGTH(`clients1`.`telephone`), CONCAT_WS('',   `clients1`.`telephone`), '') /* T&#233;l&#233;phone Emetteur */" => "phone_emetteur",
		"IF(    CHAR_LENGTH(`clients1`.`adresse`), CONCAT_WS('',   `clients1`.`adresse`), '') /* Adresse Emetteur */" => "adresse_emetteur",
		"`transferts_argent`.`beneficiaire`" => "beneficiaire",
		"`transferts_argent`.`nni_beneficiaire`" => "nni_beneficiaire",
		"`transferts_argent`.`phone_beneficiaire`" => "phone_beneficiaire",
		"`transferts_argent`.`adresse_beneficiaire`" => "adresse_beneficiaire",
		"`transferts_argent`.`prix_achat`" => "prix_achat",
		"`transferts_argent`.`commission`" => "commission",
		"`transferts_argent`.`total`" => "total",
		"`transferts_argent`.`statut`" => "statut",
		"`transferts_argent`.`observation`" => "observation"
	);

	// Lookup fields that can be used as filterers
	$x->filterers = array(  'emetteur' => 'Nom & Pr&#233;nom Emetteur');

	$x->QueryFrom = "`transferts_argent` LEFT JOIN `clients` as clients1 ON `clients1`.`matricule_client`=`transferts_argent`.`emetteur` ";
	$x->QueryWhere = '';
	$x->QueryOrder = '';

	$x->AllowSelection = 1;
	$x->HideTableView = ($perm[2]==0 ? 1 : 0);
	$x->AllowDelete = $perm[4];
	$x->AllowMassDelete = true;
	$x->AllowInsert = $perm[1];
	$x->AllowUpdate = $perm[3];
	$x->SeparateDV = 1;
	$x->AllowDeleteOfParents = 0;
	$x->AllowFilters = 1;
	$x->AllowSavingFilters = 1;
	$x->AllowSorting = 1;
	$x->AllowNavigation = 1;
	$x->AllowPrinting = 1;
	$x->AllowPrintingDV = 1;
	$x->AllowCSV = 1;
	$x->RecordsPerPage = 500;
	$x->QuickSearch = 1;
	$x->QuickSearchText = $Translation["quick search"];
	$x->ScriptFileName = "transferts_argent_view.php";
	$x->RedirectAfterInsert = "transferts_argent_view.php?SelectedID=#ID#";
	$x->TableTitle = "TRANSFERT D'ARGENT";
	$x->TableIcon = "resources/table_icons/coins_in_hand.png";
	$x->PrimaryKey = "`transferts_argent`.`idtransfert`";
	$x->DefaultSortField = '`transferts_argent`.`date`';
	$x->DefaultSortDirection = 'asc';

	$x->ColWidth   = array(  150, 150, 150, 150, 150, 150, 150, 150, 150, 150, 150);
	$x->ColCaption = array("N&#176; Facture", "Code transaction", "Date", "Nom & Pr&#233;nom Emetteur", "NNI Emetteur", "T&#233;l&#233;phone Emetteur", "Nom & Pr&#233;nom B&#233;n&#233;ficiaire", "NNI B&#233;n&#233;ficiaire", "T&#233;l&#233;phone B&#233;n&#233;ficiaire", "Net &#224; payer", "Statut");
	$x->ColFieldName = array('num_facture', 'code_transaction', 'date', 'emetteur', 'nni_emetteur', 'phone_emetteur', 'beneficiaire', 'nni_beneficiaire', 'phone_beneficiaire', 'total', 'statut');
	$x->ColNumber  = array(2, 3, 4, 5, 6, 7, 9, 10, 11, 15, 16);

	// template paths below are based on the app main directory
	$x->Template = 'templates/transferts_argent_templateTV.html';
	$x->SelectedTemplate = 'templates/transferts_argent_templateTVS.html';
	$x->TemplateDV = 'templates/transferts_argent_templateDV.html';
	$x->TemplateDVP = 'templates/transferts_argent_templateDVP.html';

	$x->ShowTableHeader = 1;
	$x->TVClasses = "";
	$x->DVClasses = "";
	$x->HighlightColor = '#FFF0C2';

	// mm: build the query based on current member's permissions
	$DisplayRecords = $_REQUEST['DisplayRecords'];
	if(!in_array($DisplayRecords, array('user', 'group'))){ $DisplayRecords = 'all'; }
	if($perm[2]==1 || ($perm[2]>1 && $DisplayRecords=='user' && !$_REQUEST['NoFilter_x'])){ // view owner only
		$x->QueryFrom.=', membership_userrecords';
		$x->QueryWhere="where `transferts_argent`.`idtransfert`=membership_userrecords.pkValue and membership_userrecords.tableName='transferts_argent' and lcase(membership_userrecords.memberID)='".getLoggedMemberID()."'";
	}elseif($perm[2]==2 || ($perm[2]>2 && $DisplayRecords=='group' && !$_REQUEST['NoFilter_x'])){ // view group only
		$x->QueryFrom.=', membership_userrecords';
		$x->QueryWhere="where `transferts_argent`.`idtransfert`=membership_userrecords.pkValue and membership_userrecords.tableName='transferts_argent' and membership_userrecords.groupID='".getLoggedGroupID()."'";
	}elseif($perm[2]==3){ // view all
		// no further action
	}elseif($perm[2]==0){ // view none
		$x->QueryFields = array("Not enough permissions" => "NEP");
		$x->QueryFrom = '`transferts_argent`';
		$x->QueryWhere = '';
		$x->DefaultSortField = '';
	}
	// hook: transferts_argent_init
	$render=TRUE;
	if(function_exists('transferts_argent_init')){
		$args=array();
		$render=transferts_argent_init($x, getMemberInfo(), $args);
	}

	if($render) $x->Render();

	// hook: transferts_argent_header
	$headerCode='';
	if(function_exists('transferts_argent_header')){
		$args=array();
		$headerCode=transferts_argent_header($x->ContentType, getMemberInfo(), $args);
	}  
	if(!$headerCode){
		include_once("$currDir/header.php"); 
	}else{
		ob_start(); include_once("$currDir/header.php"); $dHeader=ob_get_contents(); ob_end_clean();
		echo str_replace('<%%HEADER%%>', $dHeader, $headerCode);
	}

	echo $x->HTML;
	// hook: transferts_argent_footer
	$footerCode='';
	if(function_exists('transferts_argent_footer')){
		$args=array();
		$footerCode=transferts_argent_footer($x->ContentType, getMemberInfo(), $args);
	}  
	if(!$footerCode){
		include_once("$currDir/footer.php"); 
	}else{
		ob_start(); include_once("$currDir/footer.php"); $dFooter=ob_get_contents(); ob_end_clean();
		echo str_replace('<%%FOOTER%%>', $dFooter, $footerCode);
	}
?>