<?php
/**********************************************************************

	Released under the terms of the GNU General Public License, GPL,
***********************************************************************/

$page_security = 'SA_REP_PURCH';
// ----------------------------------------------------------------
// $ Revision:	2.0 $
// Creator:	Joe Hunt
// date_:	2005-05-19
// Title:	Purchase Orders
// ----------------------------------------------------------------
$path_to_root="..";

include_once($path_to_root . "/includes/session.inc");

print_supplier_list();

function report_get_suppliers_list() {
    $sql = "SELECT sp.*, 
                stp.value_name supplier_type 
            FROM ".TB_PREF."suppliers sp  
                LEFT JOIN ".TB_PREF."list_values stp  
                    ON sp.supplier_type = stp.id 
                        AND stp.list_code = 'SUPP_TYPES' 
            ORDER BY sp.supp_ref";
    
	return db_query($sql, "report_get_suppliers_list");
}

function print_supplier_list() {
    global $path_to_root;

    $destination = $_POST['PARAM_0'];
    
    if ($destination) {
        include_once($path_to_root . "/reporting/includes/excel_report.inc");
    } else {
        include_once($path_to_root . "/reporting/includes/pdf_report.inc");
    }

    $orientation = 'L';
    
        $x = 0;
	$cols = array($x, $x+=45, $x+=140, $x+=180, $x+=180, $x+=100, $x+=80, $x+=50);
        $headers =array(_("Suf Ref."), _("Supplier Name"), ("Mailing Address"), _("Physical Address"), _("Supplier Type"), _("Contact Number"), _("Supplier Id"));
	$aligns = array('left',	'left',	'left', 'left',	'left',	'center', 'center');

	$params = array(0 => '');

	$rep = new FrontReport(_('Supplier List'), "SupplierList", 'A4', 9, $orientation);

            $rep->Font();
            $rep->Info($params, $cols, $headers, $aligns);
            $rep->NewPage();

                $result = report_get_suppliers_list();
                    while ($row = db_fetch($result)) {
                        $rep->NewLine();
                        
                        $rep->TextCol(0, 1, $row['supp_ref']);
                        $rep->TextCol(1, 2, $row['supp_name']);
                        $rep->TextCol(2, 3, $row['address']);
                        $rep->TextCol(3, 4, $row['supp_address']);
                        $rep->TextCol(4, 5, $row['supplier_type']);
                        $rep->TextCol(5, 6, $row['contact']);  
                        $rep->TextCol(6, 7, $row['supplier_id']);  
                    } 
                
        $rep->End();
}

?>