Git Product home page Git Product logo

Comments (2)

AidanHak avatar AidanHak commented on May 25, 2024
<?php

// Include classes
include_once('tbs/tbs_class.php');
include_once('tbs/plugins/tbs_plugin_opentbs.php');

// prevent from a PHP configuration problem when using mktime() and date()
if (version_compare(PHP_VERSION,'5.1.0')>=0) {
    if (ini_get('date.timezone')=='') {
        date_default_timezone_set('UTC');
    }
}

// Initialize the TBS instance
$TBS = new clsTinyButStrong; // new instance of TBS
$TBS->Plugin(TBS_INSTALL, OPENTBS_PLUGIN); // load the OpenTBS plugin

// ------------------------------
// Prepare some data
// ------------------------------

$fields = $_POST;
//echo '<pre>'; print_r($fields); echo '</pre>';
//die();

if (intval($fields['ParkingSpots']) < 1 || intval($fields['ParkingSpots']) > 1) {
	$hasOneParking = 0;
} else {
	$hasOneParking = 1;
}

$intOrigFee = intval($fields['OriginalFee']);
$intNewFee = intval($fields['NewFee']);
if ($intOrigFee < $intNewFee) {
	$hasBiggerNewFee = 1;
	$hasBiggerOrigFee = 0;
	$hasEqualFees = 0;
} elseif ($intOrigFee > $intNewFee) {
	$hasBiggerNewFee = 0;
	$hasBiggerOrigFee = 1;
	$hasEqualFees = 0;
} else {
	$hasBiggerNewFee = 0;
	$hasBiggerOrigFee = 0;
	$hasEqualFees = 1;
}

if ($fields['PhoneFee'] <= 0) {
	$hasNoVoIPPhones = 1;
} else {
	$hasNoVoIPPhones = 0;
}
if ($fields['PhoneReceptionFee'] <= 0) {
	$hasNoPhoneReceptionService = 1;
} else {
	$hasNoPhoneReceptionService = 0;
}
if ($fields['MailForwardFee'] <= 0) {
	$hasNoMail = 1;
} else {
	$hasNoMail = 0;
}
if (intval($fields['FreeMonth']) === 1) {
	$hasFreeMonth = 1;
	$hasNoFreeMonth = 0;
} else {
	$hasFreeMonth = 0;
	$hasNoFreeMonth = 1;
}

$additionalCoins = intval($fields['AdditionalCoins']);
$hasNoAdditionalCoins = $additionalCoins <= 0 ? 1 : 0;

$additionalSecurityDeposit = intval($fields['AdditionalSecurityDeposit']);
$totalSecurityDeposit = intval($fields['TotalSecurityDeposit']);
$hasNoSecurityDeposit = $additionalSecurityDeposit <= 0 || $totalSecurityDeposit <= 0 ? 1 : 0;

$voipLines = $fields['VoIPLines'];
$voipPhones = $fields['VoIPPhones'];
$hasPhoneLineOnly = !empty($voipLines) && empty($voipPhones) ? 1 : 0;

$addSub = $fields['AddSub']; // Amendment Agreement - addition, substitution, or none
$isAdd = $addSub === 'Addition' ? 1 : 0;
$isSub = $addSub === 'Substitution' ? 1 : 0;

if (isset($fields['hasRenewal'])) {
	$hasRenewal = 1;
	$hasNoRenewal = 0;

	//$renewalCoinsIncDec = $fields['RenewalCoinsIncDec'];
	//$renewalNewCoins = intval($fields['RenewalNewCoins']);
	$renewalTotalCoins = intval($fields['RenewalTotalCoins']);
	//$hasRenewalCoins = $renewalNewCoins > 0 && $renewalTotalCoins > 0 ? 1 : 0;
	$hasRenewalCoins = $renewalTotalCoins > 0 ? 1 : 0;

	$renewalAdditionalSecurityDeposit = intval($fields['RenewalAdditionalSecurityDeposit']);
	$renewalTotalSecurityDeposit = intval($fields['RenewalTotalSecurityDeposit']);
	$hasRenewalSecurityDeposit = $renewalAdditionalSecurityDeposit > 0 && $renewalTotalSecurityDeposit > 0 ? 1 : 0;

	$renewalSuiteNumber = intval($fields['RenewalSuiteNumber']);
	$renewalLicenseFee = intval($fields['RenewalLicenseFee']);
} else {
	$hasRenewal = 0;
	$hasNoRenewal = 1;

	//$renewalCoinsIncDec = 0;
	//$renewalNewCoins = 0;
	$renewalTotalCoins = 0;
	$hasRenewalCoins = 0;

	$renewalNewSecurityDeposit = 0;
	$renewalTotalSecurityDeposit = 0;
	$hasRenewalSecurityDeposit = 0;

	$RenewalSuiteNumber = 0;
	$renewalLicenseFee = 0;

}

if (isset($fields['hasAddSub'])) {
	$hasAddSub = 1;
	$hasNoAddSub = 0;

	//$addSubNewCoins = intval($fields['AddSubNewCoins']);
	$addSubTotalCoins = intval($fields['AddSubTotalCoins']);
	//$hasAddSubCoins = $addSubNewCoins > 0 && $addSubTotalCoins > 0 ? 1 : 0;
	$hasAddSubCoins = $addSubTotalCoins > 0 ? 1 : 0;

	$addSubAdditionalSecurityDeposit = intval($fields['AddSubAdditionalSecurityDeposit']);
	$addSubTotalSecurityDeposit = intval($fields['AddSubTotalSecurityDeposit']);
	$hasAddSubSecurityDeposit = $addSubAdditionalSecurityDeposit > 0 && $addSubTotalSecurityDeposit > 0 ? 1 : 0;

	$addSubLicFeeIncDec = $fields['AddSubLicFeeIncDec'];
	$addSubNewLicenseFee = $fields['AddSubNewLicenseFee'];

	if ($addSubLicFeeIncDec === 'same') {
		$fields['AddSubNewLicenseFee'] = "remain unchanged at $" . $addSubNewLicenseFee;
	} else {
		$fields['AddSubNewLicenseFee'] = $addSubLicFeeIncDec . " to $" . $addSubNewLicenseFee;
	}
} else {
	$hasAddSub = 0;
	$hasNoAddSub = 1;

	//$addSubNewCoins = 0;
	$addSubTotalCoins = 0;
	$hasAddSubCoins = 0;

	$addSubNewSecurityDeposit = 0;
	$addSubTotalSecurityDeposit = 0;
	$hasAddSubSecurityDeposit = 0;

	$addSubLicFeeIncDec = 0;
	$addSubNewLicenseFee = 0;
}

if (isset($fields['hasParking'])) {
	$hasParking = 1;
	$hasNoParking = 0;
	
	$hasParkingSpaceLicenseFee = 0;
	if (isset($fields['ParkingSpacesIncDec']) && isset($fields['ParkingSpaceLicFeeIncDec'])) {
		$hasParkingSpaceLicenseFee = 1;
		$parkingSpacesIncDec = $fields['ParkingSpacesIncDec'];
		$parkingSpaceLicFeeIncDec = $fields['ParkingSpaceLicFeeIncDec'];
	}

	$parkingSpaceAdditionalSecurityDeposit = $fields['ParkingSpaceAdditionalSecurityDeposit'];
	$parkingSpaceTotalSecurityDeposit = $fields['ParkingSpaceTotalSecurityDeposit'];
	$hasParkingSecurityDeposit = $parkingSpaceAdditionalSecurityDeposit > 0 && $parkingSpaceTotalSecurityDeposit > 0 ? 1 : 0;
} else {
	$hasParking = 0;
	$hasNoParking = 1;

	$parkingSpacesIncDec = 0;
	$parkingSpaceLicFeeIncDec = 0;

	$parkingSpaceAdditionalSecurityDeposit = 0;
	$parkingSpaceTotalSecurityDeposit = 0;
	$hasParkingSecurityDeposit = 0;
}

$fields['LicenseFee'] = number_format($fields['LicenseFee']);
$fields['TotalMonthlyFee'] = number_format($fields['TotalMonthlyFee']);
$fields['SecurityDeposit'] = number_format($fields['SecurityDeposit']);

if (isset($fields['LicenseeSuiteApt']) && $fields['LicenseeSuiteApt'] !== '') {
	//$fields['LicenseeSuiteAptNewLine'] = '^p' . $fields['LicenseeSuiteApt'];
	$fields['LicenseeSuiteApt'] = ', ' . $fields['LicenseeSuiteApt'];
}

if (isset($fields['AssigneeSuiteApt']) && $fields['AssigneeSuiteApt'] !== '') {
	$fields['AssigneeSuiteApt'] = ', ' . $fields['AssigneeSuiteApt'];
}

// -----------------
// Load the template
// -----------------

$document = $_POST['document_name'];
unset($_POST['document_name']);
$file = $document.'.docx';
$template = 'templates/'.$file;
//echo $template;
$TBS->LoadTemplate($template, OPENTBS_ALREADY_UTF8); // Also merge some [onload] automatic fields (depends of the type of document).

// --------------------------------------------
// Merging and other operations on the template
// --------------------------------------------

// Merge data in the body of the document
//$TBS->MergeBlock('a,b', $fields);
//$TBS->MergeField('fields', $fields);

// Delete comments
$TBS->PlugIn(OPENTBS_DELETE_COMMENTS);

// -----------------
// Output the result
// -----------------

// Define the name of the output file
$save_as = (isset($_POST['save_as']) && (trim($_POST['save_as'])!=='') && ($_SERVER['SERVER_NAME']=='localhost')) ? trim($_POST['save_as']) : '';

$output_file_name = ' ' . $_POST['file_name'] . ".docx";
if (isset($fields['FileNameDate'])) {
	$output_file_name = date('n-j-Y', strtotime($fields['FileNameDate'])) . $output_file_name;
} elseif (isset($fields['StartDate'])) {
	$output_file_name = date('n-j-Y', strtotime($fields['StartDate'])) . $output_file_name;
} elseif (isset($fields['EffectiveDate'])) {
	$output_file_name = date('n-j-Y', strtotime($fields['EffectiveDate'])) . $output_file_name;
}

if ($save_as === '') {
    // Output the result as a downloadable file (only streaming, no data saved in the server)
    $TBS->Show(OPENTBS_DOWNLOAD, $output_file_name); // Also merges all [onshow] automatic fields.
    // Be sure that no more output is done, otherwise the download file is corrupted with extra data.
    exit();
} else {
    // Output the result as a file on the server.
    $TBS->Show(OPENTBS_FILE, $output_file_name); // Also merges all [onshow] automatic fields.
    // The script can continue.
    exit("File [$output_file_name] has been created.");
}

from opentbs.

Skrol29 avatar Skrol29 commented on May 25, 2024

The correct place for support is on StackOverflow

For your problem, see :
https://www.tinybutstrong.com/opentbs.php?doc#debug_error

from opentbs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.