<?php

/*************************************************************************\
* phpGroupWare app (Bookkeeping)                                          *
* http://www.phpgroupware.org                                             *
* Written by Rick Bakker <r.bakker@linvision.com>                         *
* --------------------------------------------                            *
* 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.                                              *
\*************************************************************************/

/* $Id: index.php,v 1.6 2001/05/21 22:09:38 darw1n Exp $ */

// -------------------------------- HTTP_GET_VARS --------------------------------
  $order=$HTTP_GET_VARS["order"];
  $selected=$HTTP_GET_VARS["selected"];
// --------------------------------  --------------------------------
  $phpgw_info["flags"]["currentapp"]='bookkeeping';
  include('../header.inc.php');
  include('inc/bookkeeping_header.inc.php');
  $phpgw->template->set_file(array( "entries" => "entries.tpl"));
  $phpgw->template->set_block("entries", "entries_list", "entries_list_t");
  $phpgw->template->set_var('header',$header);
  $phpgw->template->set_var('lang_app_title',lang('bookkeeping'));
  $phpgw->template->set_var('lang_title',lang('entries'));
  $phpgw->template->set_var('head_color',"D3DCE3");
// -------------------------------- order --------------------------------
  if($order=='')
  {
     $order='date_entry';
  }
// -------------------------------- selected --------------------------------
  if($selected==''){
    $selected='expenses';
  }
  $lang_switch=lang('switch to');
  if($selected=='expenses')
  {
    $lang_selected=lang("expenses");
    $lang_switch.=': <a href="'.$phpgw->link("/bookkeeping/index.php","selected=income&order=$order").'">'.lang("income").'</a>';
    $income_expense='E';
  }
  else
  {
    $lang_selected=lang("income");
    $lang_switch.=': <a href="'.$phpgw->link("/bookkeeping/index.php","selected=expenses&order=$order").'">'.lang("expenses").'</a>';
    $income_expense='I';
  }

  $phpgw->template->set_var("lang_selected",$lang_selected);
  $phpgw->template->set_var("lang_switch",$lang_switch);
  $phpgw->template->set_var("lang_date_entry",'<a href="'.$phpgw->link("/bookkeeping/index.php","selected=$selected&order=date_entry").'">'.lang("date").'</a>');
  $phpgw->template->set_var("lang_category",'<a href="'.$phpgw->link("/bookkeeping/index.php","selected=$selected&order=category").'">'.lang("category").'</a>');
  $phpgw->template->set_var("lang_description",'<a href="'.$phpgw->link("/bookkeeping/index.php","selected=$selected&order=description").'">'.lang("description").'</a>');
  $phpgw->template->set_var("lang_amount",'<a href="'.$phpgw->link("/bookkeeping/index.php","selected=$selected&order=amount").'">'.lang("amount").'</a>');
  $phpgw->template->set_var("lang_view",lang("view"));
  $phpgw->template->set_var("lang_edit",lang("edit"));
  $phpgw->template->set_var("lang_delete",lang("delete"));

  $phpgw->db->query("SELECT e.entry_id as entry_id,e.date_entry as date_entry,c.description as category,e.amount as amount,e.description as description ".
                     "FROM phpgw_bk_entries e,phpgw_bk_categories c WHERE e.account_id='".$phpgw_info["user"]["account_id"]."' ".
                     "AND e.income_expense='$income_expense' AND e.category_id=c.category_id order by $order");
  while(  $phpgw->db->next_record() )
  {
    $color=row_color($color);
    $phpgw->template->set_var(color,$color);
    $entry_id = $phpgw->db->f("entry_id");
    $_date_entry = getdate($phpgw->db->f("date_entry"));
    $date_entry=$_date_entry["year"]."-".$_date_entry["mon"]."-".$_date_entry["mday"];
    $category = $phpgw->db->f("category");
    $description = $phpgw->db->f("description");
    $amount = $phpgw->db->f("amount");
    $phpgw->template->set_var(array("date_entry" => $date_entry,
                                    "category" => $category,
                                    "description" => $description,
                                    "amount" => $amount,
                                    "view" => '<a href="'.$phpgw->link("/bookkeeping/entry_view.php","entry_id=".$entry_id."&selected=$selected&order=$order").'">'.lang("view")."</a>",
                                    "edit" => '<a href="'.$phpgw->link("/bookkeeping/entry_edit.php","entry_id=".$entry_id."&selected=$selected&order=$order").'">'.lang("edit")."</a>",
                                    "delete" => '<a href="'.$phpgw->link("/bookkeeping/entry_delete.php","entry_id=".$entry_id."&selected=$selected&order=$order").'">'.lang("delete")."</a>"));
    $phpgw->template->parse("entries_list_t", "entries_list", true);
  }

  $phpgw->template->set_var(actionurl,$phpgw->link("/bookkeeping/entry_add.php","selected=$selected&order=$order"));
  $phpgw->template->set_var(lang_add,lang("add"));
  $phpgw->template->parse("out", "entries", true);
  $phpgw->template->p("out");

  $phpgw->common->phpgw_footer();

?>
