User authentication is temporarily unavailable. If this situation persists, please inform your Wiki Admin.

Report page for tax per month

Just two files to get a report for tax per month. You can use it for your tax filing. I have used the script of Justin Kelly and recode it till it works for me.

report_tax_month.tpl

../templates/default/reports

<div id="top"><h3>Total tax amount per month</h3></div>
 <hr />

<table width="100%">
 {foreach item=year from=$years}
   <tr>
   <td><b>{$year|htmlsafe}</b></td>
   <tr>
   <td></td><td>Month:<br />BTW:</td>
     {foreach key=key item=item_tax from=$total_tax.$year}
	      <td>{$key|htmlsafe}
		  <br />{if $item_tax > 0}{$item_tax|siLocal_number}{else}{$item_tax|htmlsafe}{/if}
		  </td>
     {/foreach}

	</tr>
 {/foreach}
 </table>

report_tax_month.php

../modules/reports

<?php

/*
* Script: report_tax_month.php
*	Tax reports by period add page
*
* Authors:
*	Sibo Attema
*
* Last edited:
*	2012-02-29
*
* License:
*	GPL v3
*/
 
checkLogin();
//   include phpreports library
//require_once("./include/reportlib.php");

/*
* Get first invoice date
*/
$sql="SELECT min(date) as date from ".TB_PREFIX."invoices";
$sth = dbQuery($sql) or die(htmlsafe(end($dbh->errorInfo())));
$invoice_start_array = $sth->fetch();
//print_r($invoice_start_array['date']);
$first_invoice_year = date('Y', strtotime($invoice_start_array['date']));

/*
* Get the total amount of taxes per month of every your 
* beginning with the first invoice
*/
$this_year = date('Y');
$year = $first_invoice_year ;

/*
* Loop every year
*/
while ( $year <= $this_year )
{
	/*
	* Loop every month
	*/
 	$month = 01;
 	while ($month <= 12)
 	{
		//maand goedzetten voor SQL
		if ($month < 10 )
		{
			$month = "0".$month;
		}
		
		/*
		* Get TAX total per month
		*/
		$total_month_tax_sql = "SELECT sum(ii.tax_amount) as month_tax_total 
					FROM ".TB_PREFIX."invoice_items ii,
					".TB_PREFIX."invoices i, ".TB_PREFIX."preferences p
					WHERE i.id = ii.invoice_id 
					AND i.preference_id = p.pref_id
					AND p.status = '1'
					AND i.date like '$year-$month%'";
		$total_month_tax = dbQuery($total_month_tax_sql) or die(htmlsafe(end($dbh->errorInfo())));
		$total_month_tax_array = $total_month_tax -> fetch();
		
		$total_tax[$year][$month] = $total_month_tax_array['month_tax_total'];
		if ($total_tax[$year][$month] == "" )
		{
			$total_tax[$year][$month] = "-";
		}
		$month++;
 	}
	$years[]=$year;
	$year++;
}

//Use smarty so you can use the varible in your tpl file
$smarty->assign('total_tax', $total_tax);
$years = array_reverse($years);
$smarty->assign('years', $years);

$smarty -> assign('pageActive', 'report');
$smarty -> assign('active_tab', '#home');
?>

index.tpl

Add a button to the report page.

../templates/default/reports

...
<h2>{$LANG.tax}</h2>
<table class="buttons" >
    <tr>
        <td>

            <a href="index.php?module=reports&view=report_tax_total" class="">
                <img src="./images/famfam/money_delete.png" alt="" />
                {$LANG.total_taxes}
            </a>

            <a href="index.php?module=reports&view=report_tax_month" class="">
                <img src="./images/famfam/money_delete.png" alt="" />
                Per month
            </a>

        </td>
    </tr>
</table>
...
 
 | wiki/report_tax_month.txt · Last modified: 2016/10/11 06:15 (external edit)