<?php
	// For help on using hooks, please refer to https://bigprof.com/appgini/help/working-with-generated-web-database-application/hooks

	function gestion_transactions_init(&$options, $memberInfo, &$args) {

		return TRUE;
	}

	function gestion_transactions_header($contentType, $memberInfo, &$args) {
		$header='';

		switch($contentType) {
			case 'tableview':
				$header='';
				break;

			case 'detailview':
				$header='';
				break;

			case 'tableview+detailview':
				$header='';
				break;

			case 'print-tableview':
				$header='';
				break;

			case 'print-detailview':
				$header='';
				break;

			case 'filters':
				$header='';
				break;
		}

		return $header;
	}

	function gestion_transactions_footer($contentType, $memberInfo, &$args) {
		$footer='';

		switch($contentType) {
			case 'tableview':
				$footer='';
				break;

			case 'detailview':
				$footer='';
				break;

			case 'tableview+detailview':
				$footer='';
				break;

			case 'print-tableview':
				$footer='';
				break;

			case 'print-detailview':
				$footer='';
				break;

			case 'filters':
				$footer='';
				break;
		}

		return $footer;
	}

	function gestion_transactions_before_insert(&$data, $memberInfo, &$args) {

		return TRUE;
	}

	function gestion_transactions_after_insert($data, $memberInfo, &$args) {
			sql("update `gestion_transactions` set `numero`= 'MV/{$data['idgtransaction']}' where `idgtransaction` = LAST_INSERT_ID()", $eo);
		return TRUE;
	}

	function gestion_transactions_before_update(&$data, $memberInfo, &$args) {

		return TRUE;
	}

	function gestion_transactions_after_update($data, $memberInfo, &$args) {

		return TRUE;
	}

	function gestion_transactions_before_delete($selectedID, &$skipChecks, $memberInfo, &$args) {

		return TRUE;
	}

	function gestion_transactions_after_delete($selectedID, $memberInfo, &$args) {

	}

	function gestion_transactions_dv($selectedID, $memberInfo, &$html, &$args) {
		/* if this is the print preview, don't modify the detail view */
		if(isset($_REQUEST['dvprint_x'])) return;
		
		ob_start(); ?>

<script>
    $j(function() {
        <?php if($selectedID){ ?>
        $j('#gestion_transactions_dv_action_buttons .btn-toolbar').append(
            '<div class="btn-group-vertical btn-group-lg" style="width: 100%;">' +
			
            '<button type="button" class="btn btn-default btn-lg" onclick="print_billet()">' +
            '<i class="glyphicon glyphicon-print"></i> FACTURE</button>' +            
			
			'<button type="button" class="btn btn-default btn-lg" onclick="print_accompte()">' +
            '<i class="glyphicon glyphicon-print"></i> ACCOMPTE</button>' +			
			
			'<button type="button" class="btn btn-default btn-lg" onclick="print_mermoz()">' +
            '<i class="glyphicon glyphicon-print"></i> MERMOZ</button>' +
			
            '</div>'
        );
        <?php } ?>
    });

    function print_billet() {
        var selectedID = '<?php echo urlencode($selectedID); ?>';
        window.location = 'billet_invoice.php?idgtransaction=' + selectedID;
    }     
	
	function print_accompte() {
        var selectedID = '<?php echo urlencode($selectedID); ?>';
        window.location = 'billet_acompte_invoice.php?idgtransaction=' + selectedID;
    }	
	
	function print_mermoz() {
        var selectedID = '<?php echo urlencode($selectedID); ?>';
        window.location = 'billet_mermoz_invoice.php?idgtransaction=' + selectedID;
    }

</script>

<?php
		$form_code = ob_get_contents();
		ob_end_clean();
		
		$html .= $form_code;
	}

	function gestion_transactions_csv($query, $memberInfo, &$args) {

		return $query;
	}
	function gestion_transactions_batch_actions(&$args) {

		return array();
	}
