Location: PHPKode > projects > PhpRechnung > phpRechnung/payment/searchlist.php
<?php
/*
	searchlist.php

	phpRechnung - is easy-to-use Web-based multilingual accounting software.
	Copyright (C) 2001 - 2008 Edy Corak < phprechnung at ecorak dot net >

	This program is free software; you can redistribute it and/or modify
	it under the terms of the GNU General Public License as published by
	the Free Software Foundation; either version 2 of the License, or
	(at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

require_once("../include/phprechnung.inc.php");
require_once("../include/company_settings.inc.php");
require_once("../include/smarty.inc.php");
CheckUser();
CheckSession();

if(isset($_REQUEST['myID']))
{
	$myID = $_REQUEST['myID'];
	$smarty->assign("myID","$myID");
}
if(isset($_REQUEST['paymentID']))
{
	$paymentID = $_REQUEST['paymentID'];
	$smarty->assign("paymentID","$paymentID");
}
if(!empty($_REQUEST['page']))
{
	$intCurrentPage = $_REQUEST['page'];
} else {
	$intCurrentPage = 1;
}
if(!empty($_REQUEST['Order']))
{
	$Order = $_REQUEST['Order'];
	$smarty->assign("Order","$Order");
} else {
	$Order = "P.PAYMENT_DATE DESC, P.PAYMENTID DESC";
	$smarty->assign("Order","$Order");
}
if(isset($_REQUEST['Sort']))
{
	$Sort = $_REQUEST['Sort'];
	$smarty->assign("Sort","$Sort");
}
if(isset($_REQUEST['CustomerNo_1']))
{
	$CustomerNo_1 = $_REQUEST['CustomerNo_1'];
}
if(isset($_REQUEST['InvoiceNo_1']))
{
	$InvoiceNo_1 = $_REQUEST['InvoiceNo_1'];
}
if(isset($_REQUEST['PaymentNo_1']))
{
	$PaymentNo_1 = $_REQUEST['PaymentNo_1'];
}
if(isset($_REQUEST['SumPaid_1']))
{
	$SumPaid_1 = $_REQUEST['SumPaid_1'];
}
if(isset($_REQUEST['DateFrom_1']))
{
	$DateFrom_1 = $_REQUEST['DateFrom_1'];
	$smarty->assign("DateFrom_1","$DateFrom_1");
}
if(isset($_REQUEST['DateTill_1']))
{
	$DateTill_1 = $_REQUEST['DateTill_1'];
	$smarty->assign("DateTill_1","$DateTill_1");
}
if(isset($_REQUEST['MethodOfPay_1']))
{
	$MethodOfPay_1 = $_REQUEST['MethodOfPay_1'];
}

if ($MethodOfPay_1 > 0)
{
	$MethodOfPay_1 = "AND P.METHODOFPAYID=$MethodOfPay_1";
}
if(isset($_REQUEST['Canceled']))
{
	$Canceled = $_REQUEST['Canceled'];
	$smarty->assign("Canceled","$Canceled");
}

$Searchstring = "CustomerNo_1=$CustomerNo_1&amp;InvoiceNo_1=$InvoiceNo_1&amp;PaymentNo_1=$PaymentNo_1&amp;SumPaid_1=$SumPaid_1&amp;DateFrom_1=$DateFrom_1&amp;DateTill_1=$DateTill_1&amp;MethodOfPay_1=$MethodOfPay_1";
$smarty->assign("Searchstring",$Searchstring);

$smarty->assign("Title","$a[payment] - $a[searchlist]");
$smarty->assign("First_Name","$a[firstname]");
$smarty->assign("Last_Name","$a[lastname]");
$smarty->assign("Company_Name","$a[company]");
$smarty->assign("Customer_No","$a[customer_no]");
$smarty->assign("Customer","$a[customer]");
$smarty->assign("EntryCanceled","$a[entry_canceled]");
$smarty->assign("NewEntry","$a[new_entry]");
$smarty->assign("Payment_No","$a[payment_number]");
$smarty->assign("Payment_Sum","$a[payment_sum]");
$smarty->assign("Total_Payment","$a[total_payment]");
$smarty->assign("Open_Account","$a[open_account]");
$smarty->assign("Method_Of_Payment","$a[method_of_payment]");
$smarty->assign("DateFrom","$a[date_from]");
$smarty->assign("DateTill","$a[date_till]");

// Database connection
//
DBConnect();

// Get data from company_settings.inc.php
//
$smarty->assign("Payment_Currency",$CompanyCurrency);

$intCursor = ($intCurrentPage - 1) * $EntrysPerPage;

// Get Payment Information
//
$DateFrom_1 = German_Mysql_Date($DateFrom_1);
$DateTill_1 = German_Mysql_Date($DateTill_1);

if($Canceled == 1)
{
	$query = $db->GetAll("SELECT A.MYID, A.FIRSTNAME, A.LASTNAME, A.COMPANY,  P.CREATEDBY, P.PAYMENTID, P.INVOICEID, P.MYID, DATE_FORMAT(P.PAYMENT_DATE,'%d.%m.%Y') AS PAYMENT_DATE, P.SUM_PAID, P.METHOD_OF_PAY, P.CANCELED FROM {$TBLName}payment AS P, {$TBLName}addressbook AS A
		WHERE P.CANCELED=1 AND A.MYID=P.MYID AND P.MYID LIKE '$CustomerNo_1%' AND P.INVOICEID LIKE '%$InvoiceNo_1%' AND P.PAYMENTID LIKE '%$PaymentNo_1%' AND P.SUM_PAID LIKE '%$SumPaid_1%'
		AND P.PAYMENT_DATE >= '$DateFrom_1' AND P.PAYMENT_DATE <= '$DateTill_1' $MethodOfPay_1 ORDER BY $Order $Sort LIMIT $intCursor, $EntrysPerPage");
}
else if($Canceled == 3)
{
	$query = $db->GetAll("SELECT A.MYID, A.FIRSTNAME, A.LASTNAME, A.COMPANY,  P.CREATEDBY, P.PAYMENTID, P.INVOICEID, P.MYID, DATE_FORMAT(P.PAYMENT_DATE,'%d.%m.%Y') AS PAYMENT_DATE, P.SUM_PAID, P.METHOD_OF_PAY, P.CANCELED FROM {$TBLName}payment AS P, {$TBLName}addressbook AS A
		WHERE A.MYID=P.MYID AND P.MYID LIKE '$CustomerNo_1%' AND P.INVOICEID LIKE '%$InvoiceNo_1%' AND P.PAYMENTID LIKE '%$PaymentNo_1%' AND P.SUM_PAID LIKE '%$SumPaid_1%'
		AND P.PAYMENT_DATE >= '$DateFrom_1' AND P.PAYMENT_DATE <= '$DateTill_1' $MethodOfPay_1 ORDER BY $Order $Sort LIMIT $intCursor, $EntrysPerPage");
}
else
{
	$query = $db->GetAll("SELECT A.MYID, A.FIRSTNAME, A.LASTNAME, A.COMPANY,  P.CREATEDBY, P.PAYMENTID, P.INVOICEID, P.MYID, DATE_FORMAT(P.PAYMENT_DATE,'%d.%m.%Y') AS PAYMENT_DATE, P.SUM_PAID, P.METHOD_OF_PAY, P.CANCELED FROM {$TBLName}payment AS P, {$TBLName}addressbook AS A
		WHERE P.CANCELED=2 AND A.MYID=P.MYID AND P.MYID LIKE '$CustomerNo_1%' AND P.INVOICEID LIKE '%$InvoiceNo_1%' AND P.PAYMENTID LIKE '%$PaymentNo_1%' AND P.SUM_PAID LIKE '%$SumPaid_1%'
		AND P.PAYMENT_DATE >= '$DateFrom_1' AND P.PAYMENT_DATE <= '$DateTill_1' $MethodOfPay_1 ORDER BY $Order $Sort LIMIT $intCursor, $EntrysPerPage");
}

// If an error has occurred, display the error message
//
if (!$query)
	print($db->ErrorMsg());
else
	// Count PageRows
	//
	$pagenumrows = count($query);

	// Count MaxRows
	//
	if($Canceled == 1)
	{
		$query1 = $db->Execute("SELECT A.MYID, A.FIRSTNAME, A.LASTNAME, A.COMPANY,  P.CREATEDBY, P.PAYMENTID, P.INVOICEID, P.MYID, DATE_FORMAT(P.PAYMENT_DATE,'%d.%m.%Y') AS PAYMENT_DATE, P.SUM_PAID, P.METHOD_OF_PAY, P.CANCELED FROM {$TBLName}payment AS P, {$TBLName}addressbook AS A
		WHERE P.CANCELED=1 AND A.MYID=P.MYID AND P.MYID LIKE '$CustomerNo_1%' AND P.INVOICEID LIKE '%$InvoiceNo_1%' AND P.PAYMENTID LIKE '%$PaymentNo_1%' AND P.SUM_PAID LIKE '%$SumPaid_1%'
		AND P.PAYMENT_DATE >= '$DateFrom_1' AND P.PAYMENT_DATE <= '$DateTill_1' $MethodOfPay_1");
	}
	else if($Canceled == 3)
	{
		$query1 = $db->Execute("SELECT A.MYID, A.FIRSTNAME, A.LASTNAME, A.COMPANY,  P.CREATEDBY, P.PAYMENTID, P.INVOICEID, P.MYID, DATE_FORMAT(P.PAYMENT_DATE,'%d.%m.%Y') AS PAYMENT_DATE, P.SUM_PAID, P.METHOD_OF_PAY, P.CANCELED FROM {$TBLName}payment AS P, {$TBLName}addressbook AS A
		WHERE A.MYID=P.MYID AND P.MYID LIKE '$CustomerNo_1%' AND P.INVOICEID LIKE '%$InvoiceNo_1%' AND P.PAYMENTID LIKE '%$PaymentNo_1%' AND P.SUM_PAID LIKE '%$SumPaid_1%'
		AND P.PAYMENT_DATE >= '$DateFrom_1' AND P.PAYMENT_DATE <= '$DateTill_1' $MethodOfPay_1");
	}
	else
	{
		$query1 = $db->Execute("SELECT A.MYID, A.FIRSTNAME, A.LASTNAME, A.COMPANY,  P.CREATEDBY, P.PAYMENTID, P.INVOICEID, P.MYID, DATE_FORMAT(P.PAYMENT_DATE,'%d.%m.%Y') AS PAYMENT_DATE, P.SUM_PAID, P.METHOD_OF_PAY, P.CANCELED FROM {$TBLName}payment AS P, {$TBLName}addressbook AS A
		WHERE P.CANCELED=2 AND A.MYID=P.MYID AND P.MYID LIKE '$CustomerNo_1%' AND P.INVOICEID LIKE '%$InvoiceNo_1%' AND P.PAYMENTID LIKE '%$PaymentNo_1%' AND P.SUM_PAID LIKE '%$SumPaid_1%'
		AND P.PAYMENT_DATE >= '$DateFrom_1' AND P.PAYMENT_DATE <= '$DateTill_1' $MethodOfPay_1");
	}

	foreach($query1 as $result1)
	{
		$numrows += count($query1);

		// Save Total Page Sum Paid by searchresult
		//
		$TotalSearchresult += $result1['SUM_PAID'];
		$smarty->assign("TOTAL_SEARCHRESULT",$TotalSearchresult);
	}

	// Save MaxPages
	//
	$intPages = ceil($numrows/$EntrysPerPage);

	// Save all entrys in $PaymentData array
	//
	foreach($query as $result)
	{
		$PaymentData[] = $result;

		// Save Total Page Sum Paid
		//
		$TotalPage += $result['SUM_PAID'];
		$smarty->assign("TOTAL_PAGE",$TotalPage);
	}

	$smarty->assign("PageRows","$pagenumrows");
	$smarty->assign("MaxRows","$numrows");
	$smarty->assign('PaymentData', $PaymentData);

// Get information from selected customer
//
$query3 = $db->Execute("SELECT LASTNAME, FIRSTNAME, COMPANY, MYID FROM {$TBLName}addressbook WHERE MYID='$myID'");

// If an error has occurred, display the error message
//
if (!$query3)
	print($db->ErrorMsg());
else
	foreach($query3 as $result3)
	{
		$smarty->assign("FIRSTNAME","$result3[FIRSTNAME]");
		$smarty->assign("LASTNAME","$result3[LASTNAME]");
		$smarty->assign("COMPANY","$result3[COMPANY]");
		$smarty->assign("MYID","$result3[MYID]");
	}

// Calculate total paid sum
//
$query5 = $db->Execute("SELECT SUM(SUM_PAID) AS SUM_PAID FROM {$TBLName}payment WHERE CANCELED=2");

// If an error has occurred, display the error message
//
if (!$query5)
	print($db->ErrorMsg());
else
	foreach($query5 as $result5)
	{
		$TotalAmount += $result5['SUM_PAID'];
		$smarty->assign("TOTAL_AMOUNT",$TotalAmount);
	}

// Display pager only if $numrows > $EntrysPerPage ( lines per page )
// from settings menu
//
if ($numrows > $EntrysPerPage)
{
	$smarty->assign('CurrentPage', "$intCurrentPage");
	$smarty->assign('MaxPages', "$intPages");
	$smarty->assign('AddCurrentPage', "page=$intCurrentPage&amp;");

	// If we are not on first page then display
	// first page, previous page link
	//
	if ($intCurrentPage > 1)
	{
		$Page = $intCurrentPage - 1;
		$smarty->assign('PrevPage', "$Page");
	}

	// If we are not on the last page then display
	// next page, last page link
	//
	if ($intCurrentPage < $intPages)
	{
		$Page = $intCurrentPage + 1;
		$smarty->assign('NextPage', "$Page");
	}
}

$smarty->display('payment/searchlist.tpl');

unset($_SESSION['CancelID']);
unset($_SESSION['NewID']);
unset($_SESSION['Type']);
?>
Return current item: PhpRechnung