tiki-accounting_entry.php 2.86 KB
Newer Older
1
<?php
changi67's avatar
changi67 committed
2 3 4
/**
 * @package tikiwiki
 */
5
// (c) Copyright 2002-2016 by authors of the Tiki Wiki CMS Groupware Project
6
//
7 8
// All Rights Reserved. See copyright.txt for details and a complete list of authors.
// Licensed under the GNU LESSER GENERAL PUBLIC LICENSE. See license.txt for details.
9
// $Id$
10 11 12 13 14 15 16 17

$section = 'accounting';
require_once ('tiki-setup.php');
require_once ('lib/accounting/accountinglib.php');


// Feature available?
if ($prefs['feature_accounting'] !='y') {
18 19
	$smarty->assign('msg', tra('This feature is disabled') . ': feature_accounting');
	$smarty->display('error.tpl');
20 21 22
	die;
}

23
$globalperms = Perms::get();
24
$objectperms = Perms::get(array( 'type' => 'accounting book', 'object' => $bookId ));
25 26

if (!($globalperms->acct_book or $objectperms->acct_book)) {
27 28 29
	$smarty->assign('msg', tra('You do not have the right to book'));
	$smarty->display('error.tpl');
	die;
30 31 32
}

if (!isset($_REQUEST['bookId'])) {
33 34
	$smarty->assign('msg', tra('Missing book id'));
	$smarty->display('error.tpl');
35 36
	die;
}
37 38
$bookId = $_REQUEST['bookId'];
$smarty->assign('bookId', $bookId);
39

40 41
$book = $accountinglib->getBook($bookId);
$smarty->assign('book', $book);
42

43
$accounts = $accountinglib->getAccounts($bookId, $all = true);
44
$smarty->assign('accounts', $accounts);
45 46 47

if (isset($_REQUEST['book'])) {
	check_ticket('accounting');
48
	$result = $accountinglib->book(
49 50 51 52 53 54 55 56 57
		$bookId,
		$_REQUEST['journalDate'],
		$_REQUEST['journalDescription'],
		$_REQUEST['debitAccount'],
		$_REQUEST['creditAccount'],
		$_REQUEST['debitAmount'],
		$_REQUEST['creditAmount'],
		$_REQUEST['debitText'],
		$_REQUEST['creditText']
58
	);
59
	if (is_numeric($result)) {
60
		if (isset($_REQUEST['statementId'])) {
61
			$accountinglib->updateStatement($bookId, $_REQUEST['statementId'], $result);
62 63 64
		}
	}
} else {
65
	$result = 0;
66
}
67

68
if (is_array($result)) {
69 70 71 72 73 74 75 76 77 78 79 80
	$smarty->assign('errors', $result);
	$smarty->assign('journalDate', $_REQUEST['journalDate']);
	$smarty->assign('journalDescription', $_REQUEST['journalDescription']);
	$smarty->assign('debitAccount', $_REQUEST['debitAccount']);
	$smarty->assign('creditAccount', $_REQUEST['creditAccount']);
	$smarty->assign('debitAmount', $_REQUEST['debitAmount']);
	$smarty->assign('creditAmount', $_REQUEST['creditAmount']);
	$smarty->assign('debitText', $_REQUEST['debitText']);
	$smarty->assign('creditText', $_REQUEST['creditText']);
	if (isset($_REQUEST['statementId'])) {
		$smarty->assign('statementId', $_REQUEST['statementId']);
	}
81
} else {
82 83 84 85 86 87
	$smarty->assign('debitAccount', array(''));
	$smarty->assign('creditAccount', array(''));
	$smarty->assign('debitAmount', array(''));
	$smarty->assign('creditAmount', array(''));
	$smarty->assign('debitText', array(''));
	$smarty->assign('creditText', array(''));
88 89 90 91
}

ask_ticket('accounting');

92 93
$journal = $accountinglib->getJournal($bookId, '%', '`journalId` DESC', 5);
$smarty->assign('journal', $journal);
94

95 96
$smarty->assign('mid', 'tiki-accounting_entry.tpl');
$smarty->display('tiki.tpl');