Location: PHPKode > projects > allocPSA > finance/transactionRepeat.php

 * Copyright (C) 2006, 2007, 2008 Alex Lance, Clancy Malcolm, Cybersource
 * Pty. Ltd.
 * This file is part of the allocPSA application <hide@address.com>.
 * allocPSA is free software: you can redistribute it and/or modify it
 * under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or (at
 * your option) any later version.
 * allocPSA 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 Affero General Public
 * License for more details.
 * You should have received a copy of the GNU Affero General Public License
 * along with allocPSA. If not, see <http://www.gnu.org/licenses/>.



$transactionRepeat = new transactionRepeat;
$db = new db_alloc;

global $TPL;
global $transactionRepeatID;

$transactionRepeatID = $_POST["transactionRepeatID"] or $transactionRepeatID = $_GET["transactionRepeatID"];

if ($transactionRepeatID) {

if (!isset($_POST["reimbursementRequired"])) {
  $_POST["reimbursementRequired"] = 0;

if ($_POST["save"] || $_POST["delete"] || $_POST["pending"] || $_POST["approved"] || $_POST["rejected"]) {


  if (have_entity_perm("transaction", PERM_FINANCE_WRITE_APPROVED_TRANSACTION)) { 
    if ($_POST["pending"]) {
      $TPL["message_good"][] = "Repeating Expense form Pending.";
    } else if ($_POST["approved"]) {
      $TPL["message_good"][] = "Repeating Expense form Approved!";
    } else if ($_POST["rejected"]) {
      $TPL["message_good"][] = "Repeating Expense form  Rejected.";

  if ($_POST["delete"] && $transactionRepeatID) {

  $_POST["product"]  or $TPL["message"][].= "Please enter a Product";
  $_POST["amount"]   or $TPL["message"][].= "Please enter an Amount";
  $_POST["fromTfID"] or $TPL["message"][].= "Please select a Source TF";
  $_POST["tfID"]     or $TPL["message"][].= "Please select a Destination TF";
  $_POST["companyDetails"]  or $TPL["message"][].= "Please provide Company Details";
  $_POST["transactionType"] or $TPL["message"][].= "Please select a Transaction Type";
  $_POST["transactionStartDate"] or $TPL["message"][].= "You must enter the Start date in the format yyyy-mm-dd";
  $_POST["transactionFinishDate"] or $TPL["message"][].= "You must enter the Finish date in the format yyyy-mm-dd";

  if (!$TPL["message"]) {
    !$transactionRepeat->get_value("status") && $transactionRepeat->set_value("status","pending"); 

$TPL["reimbursementRequired_checked"] = $transactionRepeat->get_value("reimbursementRequired") ? " checked" : "";

if ($transactionRepeat->get_value("transactionRepeatModifiedUser")) {
  $db->query("select username from person where personID=".$transactionRepeat->get_value("transactionRepeatModifiedUser"));
  $TPL["user"] = $db->f("username");

if (have_entity_perm("tf", PERM_READ, $current_user, false)) {
  // Person can access all TF records
  $q = sprintf("SELECT tfID AS value, tfName AS label 
                  FROM tf 
                 WHERE tfActive = 1 
                    OR tf.tfID = %d 
                    OR tf.tfID = %d 
              ORDER BY tfName"
              , $transactionRepeat->get_value("tfID"), $transactionRepeat->get_value("fromTfID"));
} else if (have_entity_perm("tf", PERM_READ, $current_user, true)) {
  // Person can only read TF records that they own
  $q = sprintf("SELECT tf.tfID AS value, tf.tfName AS label
                  FROM tf, tfPerson 
                 WHERE tfPerson.personID=%d 
                   AND tf.tfID=tfPerson.tfID 
                   AND (tf.tfActive = 1 OR tf.tfID = %d OR tf.tfID = %d)
              ORDER BY tfName"
              ,$current_user->get_id(), $transactionRepeat->get_value("tfID"), $transactionRepeat->get_value("fromTfID"));
} else {
  die("No permissions to generate TF list");

//special case for disabled TF. Include it in the list, but also add a warning message.
$tf = new tf;
if ($tf->select() && !$tf->get_value("tfActive")) {
  $TPL["message_help"][] = "This expense is allocated to an inactive TF. It will not create transactions.";
$tf = new tf;
if ($tf->select() && !$tf->get_value("tfActive")) {
  $TPL["message_help"][] = "This expense is sourced from an inactive TF. It will not create transactions.";

$TPL["tfOptions"] = page::select_options($q, $transactionRepeat->get_value("tfID"));
$TPL["fromTfOptions"] = page::select_options($q, $transactionRepeat->get_value("fromTfID"));
$TPL["basisOptions"] = page::select_options(array("weekly"     =>"weekly"
                                                 ,"monthly"    =>"monthly"
                                                 ,"quarterly"  =>"quarterly"
                                                 ,"yearly"     =>"yearly")

$TPL["transactionTypeOptions"] = page::select_options(transaction::get_transactionTypes(), $transactionRepeat->get_value("transactionType"));

if (is_object($transactionRepeat) && $transactionRepeat->get_id() && have_entity_perm("transaction", PERM_FINANCE_WRITE_APPROVED_TRANSACTION)) {
  $TPL["adminButtons"].= "&nbsp;<input type=\"submit\" name=\"pending\" value=\"Pending\">";
  $TPL["adminButtons"].= "&nbsp;<input type=\"submit\" name=\"approved\" value=\"Approve\">";
  $TPL["adminButtons"].= "&nbsp;<input type=\"submit\" name=\"rejected\" value=\"Reject\">";

if (is_object($transactionRepeat) && $transactionRepeat->get_id() && $transactionRepeat->get_value("status") == "pending") {
  $TPL["message_help"][] = "This Repeating Expense will only create Transactions once its status is Approved.";
} else if (!$transactionRepeat->get_id()) {
  $TPL["message_help"][] = "Complete all the details and click the Save button to create an automatically Repeating Expense";

$transactionRepeat->get_value("status") and $TPL["statusLabel"] = " - ".ucwords($transactionRepeat->get_value("status"));

$TPL["taxName"] = config::get_config_item("taxName");

$TPL["main_alloc_title"] = "Create Repeating Expense - ".APPLICATION_NAME;

Return current item: allocPSA