Commit 09561e2f authored by Jean-Paul Saman's avatar Jean-Paul Saman

Invoice version 0.3.3 - initial import.

parents
This diff is collapsed.
<?php
$del = isset($_POST['del']) ? $_POST['del'] : 0;
$stat = isset($_POST['stat']) ? $_POST['stat'] : -1;
$obj = new CInvoice();
if (!$obj->bind( $_POST )) {
$AppUI->setMsg( $obj->getError(), UI_MSG_ERROR );
$AppUI->redirect();
}
$obj->task_invoice=$_POST["task_invoice"];
$AppUI->setMsg( 'Invoice' );
if ($del) {
if (($msg = $obj->delete())) {
$AppUI->setMsg( $msg, UI_MSG_ERROR );
} else {
$AppUI->setMsg( "deleted", UI_MSG_OK, true );
}
$AppUI->redirect("m=invoice&a=addedit&invoice_id=".$obj->task_invoice."&project_id=".$obj->_invoice_project);
} elseif ($stat != -1 && $obj->task_invoice != 0) {
if (($msg = $obj->change_status($stat))) {
$AppUI->setMsg( $msg, UI_MSG_ERROR );
} else {
$AppUI->setMsg( $msg . "updated", UI_MSG_OK, true );
}
$AppUI->redirect("m=invoice&a=addedit&invoice_id=".$obj->task_invoice."&project_id=".$obj->_invoice_project);
} else {
while(list($key,$value)=each($_POST)) {
$tmparr=split("_",$key);
if ($tmparr[0] == "num") {
$obj->task_invouce=$_POST["task_invoice"];
$obj->task_log_id=$tmparr[1];
$obj->task_amount=$_POST["fixed_".$tmparr[1]];
$obj->store();
}
}
$AppUI->setMsg( $msg . "updated", UI_MSG_OK, true );
$AppUI->redirect("m=invoice&a=addedit&invoice_id=".$obj->task_invoice."&project_id=".$obj->_invoice_project);
}
?>
<?php
//$AppUI->savePlace();
if (isset( $_GET['project_id'] )) {
$AppUI->setState( 'InvoiceIdxProject', $_GET['project_id'] );
}
$project_id = $AppUI->getState( 'InvoiceIdxProject' ) ? $AppUI->getState( 'InvoiceIdxProject' ) : 0;
// retrieve any state parameters
if (isset( $_GET['tab'] )) {
$AppUI->setState( 'InvoiceIdxTab', $_GET['tab'] );
}
$tab = $AppUI->getState( 'InvoiceIdxTab' ) !== NULL ? $AppUI->getState( 'InvoiceIdxTab' ) : 1;
$active = intval( !$AppUI->getState( 'InvoiceIdxTab' ) );
$q = new DBQuery;
$q->addQuery('
invoice_id,
invoice_project,
invoice_status,
invoice_date,
invoice_creator');
$q->addTable('invoice');
$invoices = $q->loadList();
// setup the title block
$titleBlock = new CTitleBlock( 'Invoice', 'applet3-48.png', $m, "$m.$a" );
$titleBlock->addCell();
if ($canEdit && $project_id) {
$titleBlock->addCell(
'<input type="submit" class="button" value="'.$AppUI->_('new invoice').'">', '',
'<form action="?m=invoice&a=addedit&project_id=' . $project_id . '" method="post">', '</form>'
);
}
$titleBlock->show();
// include the re-usable sub view
$min_view = false;
// include("{$AppUI->cfg['root_dir']}/modules/invoice/index.php");
// tabbed information boxes
$tabBox = new CTabBox( "?m=invoice", dPgetConfig('root_dir') . '/modules/invoice/', $tab );
$tabBox->add( "vw_open", 'Invoices (Open)' );
$tabBox->add( "vw_pend", 'Invoices (Pending)' );
$tabBox->add( "vw_paid", 'Invoices (Paid)' );
$tabBox->show();
?>
<?php
require_once( $AppUI->getSystemClass( 'libmail' ) );
require_once( $AppUI->getSystemClass( 'dp' ) );
class CInvoice extends CDpObject {
var $invoice_task_queue_id = NULL;
var $task_invoice = NULL;
var $task_log_id = NULL;
var $task_amount = NULL;
function CInvoice() {
$this->CDpObject( 'invoice_task_queue', 'task_invoice' );
$this->_invoice_project=$_POST["invoice_project"];
$this->_task_queue_id=$_POST["task_queue_id"];
}
function check() {
if ($this->task_invoice == NULL || $this->task_invoice == "0") {
$this->init();
}
if (empty($this->task_amount))
$this->task_amount = '0';
return NULL;
}
function init() {
$q = new DBQuery;
$q->addTable('invoice');
$q->addInsert('invoice_project,invoice_date,invoice_creator', $_POST['invoice_project'].','.time().','.$_POST['project_creator'], true);;
$q->exec();
$this->task_invoice = db_insert_id();
// $temp_array = mysql_fetch_array(mysql_query("select last_insert_id() from invoice"));
// $my_last_id = $temp_array['last_insert_id()'];
// $this->task_invoice=(int)$my_last_id;
}
function store() {
$msg = $this->check();
$q = new DBQuery;
$q->addTable('invoice_task_queue');
$q->addInsert('task_invoice,task_amount,task_log_id',
$this->task_invoice.','.$this->task_amount.','.$this->task_log_id,
true);
$q->exec();
//db_insertObject('invoice_task_queue',$this,'task_queue_id');
}
function delete()
{
$this->_action='deleted';
$q = new DBQuery();
$q->setDelete('invoice_task_queue');
$q->addWhere('task_queue_id = ' . $this->_task_queue_id);
if (!$q->exec())
return db_error();
else
return NULL;
}
function purge()
{
$this->_action='purged';
$q = new DBQuery;
$q->addQuery('invoice_status');
$q->addTable('invoice');
$q->addWhere('invoice_id = ' . $this->task_invoice);
$temp_array= $q->loadList();
$mystatus=$temp_array[0]["invoice_status"];
if ($mystatus == 0)
{
$q->clear();
$q->setDelete('invoice_task_queue');
$q->addWhere('task_invoice = ' . $this->task_invoice);
$q->exec();
}
else
{
$q->clear();
$q->addTable('tasks');
$q->addUpdate('task_invoice', '0');
$q->addUpdate('task_cost' , '0');
$q->addWhere('task_invoice = ' . $this->task_invoice);
$q->exec();
}
$q->clear();
$q->setDelete('invoices');
$q->addWhere('invoice_id = ' . $this->task_invoice);
if (!$q->exec())
return db_error();
else
return NULL;
}
function change_status($stat)
{
$this->_action='updated';
$q = new DBQuery;
$q->addTable('invoice');
$q->addUpdate('invoice_status', $stat);
$q->addWhere('invoice_id = ' . $this->task_invoice);
$q->exec();
}
}
<?php
$project_id = intval( dPgetParam( $_GET, "project_id", 0 ) );
$perms =& $AppUI->acl();
if (!$perms->checkModuleItem('invoice', 'view', $project_id)) {
$AppUI->redirect( "m=public&a=access_denied" );
}
// retrieve any state parameters
if (isset( $_GET['tab'] )) {
$AppUI->setState( 'ProjVwTab', $_GET['tab'] );
}
$tab = $AppUI->getState( 'ProjVwTab' ) !== NULL ? $AppUI->getState( 'ProjVwTab' ) : 0;
$q = new DBQuery;
$q->addQuery('
invoice_id,
invoice_project,
invoice_status,
invoice_date,
invoice_creator');
$q->addTable('invoice');
$q->addWhere('invoice_project = ' . $project_id);
$q->addOrder('invoice_id DESC');
$invoices = null;
$ptrc=$q->exec();
$nums=db_num_rows($ptrc);
echo db_error();
for ($x=0; $x < $nums; $x++) {
$row = db_fetch_assoc( $ptrc );
$invoices[] = $row;
}
function showtask_inv( &$a, $level=0 ) {
global $AppUI, $done, $query_string, $durnTypes, $project_id, $perms;
$df = $AppUI->getPref( 'SHDATEFORMAT' );
$done[] = $a['invoice_id'];
$invoice_status="Closed";
if ($a["invoice_status"] == "0") {
$invoice_status="Open";
}elseif ($a["invoice_status"] == "1") {
$invoice_status="Pending";
}elseif ($a["invouce_status"] == "2") {
$invoice_status="Paid";
}
$start_date=strftime($df,$a["invoice_date"]);
// edit query FROM users; user_first_name and user_last_name
$q = new DBQuery;
$q->addQuery('
contact_first_name,
contact_last_name');
$q->addTable('contacts');
$q->leftJoin('users', 'u', 'user_contact=contact_id');
$q->addWhere('user_id = ' . $a['invoice_creator']);
$tmpuser=$q->exec();
$username=db_fetch_assoc($tmpuser);
$s = "\n<tr>";
// edit icon
$s .= "\n\t<td>";
if ($perms->checkModuleItem('invoice', "edit", $a['invoice_id'])) {
$s .= "\n\t\t<a href=\"?m=invoice&a=addedit&invoice_id={$a['invoice_id']}&project_id=${project_id}\">"
. "\n\t\t\t".'<img src="./images/icons/pencil.gif" alt="'.$AppUI->_( 'Edit Invoice' ).'" border="0" width="12" height="12">'
. "\n\t\t</a>";
}
$s .= "\n\t</td>";
// name link
$alt = htmlspecialchars( $a["invoice_id"] );
$s .= '<td align=right>&nbsp;<a href="./index.php?m=invoice&a=view&invoice_id='.$a["invoice_id"].'&project_id='.$project_id.'" title="' . $alt . '"># ' . $a["invoice_id"] . '</a></td>';
// task owner
$s .= '<td nowrap="nowrap" align=center>'.$username["contact_first_name"].' '.$username["contact_last_name"].'</td>';
// start date
$s .= '<td nowrap="nowrap" align=center>'.$start_date.'</td>';
// status
$s .= '<td nowrap="nowrap">'.$invoice_status.'</td>';
$s .= '</tr>';
echo $s;
}
?>
<?php
if ($perms->checkModule('invoice', 'add'))
{
?>
<form action="?m=invoice&a=addedit&project_id=<?php echo $project_id; ?>" method="post">
<input type="submit" class="button" value="<?php echo $AppUI->_('new invoice'); ?>" />
</form>
<?php } ?>
<table width="100%" border="0" cellpadding="2" cellspacing="1" class="tbl" valign="top">
<tr>
<th width="10">&nbsp;</th>
<th width="250"><?php echo $AppUI->_('Invoice Number');?></th>
<th nowrap="nowrap"><?php echo $AppUI->_('Invoice Creator');?></th>
<th width="100" nowrap="nowrap"><?php echo $AppUI->_('Creation Date');?></th>
<th width="100" nowrap="nowrap"><?php echo $AppUI->_('Invoive Status');?></th>
</tr>
<?php
//echo '<pre>'; print_r($invoices); echo '</pre>';
//print count($invoices);
@reset( $invoices);
for ($s=0; $s < count($invoices); $s++) {
$tnums=count($invoices);
if ($tnums) {
showtask_inv( $invoices[$s], 1 );
}
}
?>
</table>
<?php /* PROJECTS $Id: reports.php,v 1.12 2005/04/15 11:27:50 cyberhorse Exp $ */
error_reporting( E_ALL );
$project_id = intval( dPgetParam( $_REQUEST, "project_id", 0 ) );
$report_type = dPgetParam( $_REQUEST, "report_type", '' );
$reports = $AppUI->readFiles( dPgetConfig( 'root_dir' )."/modules/invoice/reports", "\.php$" );
// $report_type_var = dPgetParam($_GET, 'report_type', '');
if (!empty($report_type_var))
$report_type_var = '&report_type=' . $report_type;
// if (! $suppressHeaders)
// {
//if (!isset($display_project_name))
// $display_project_name = "None";
//echo $AppUI->_('Selected Project') . ": <b>".$display_project_name."</b>";
/* ?>
<form name="changeMe" action="./index.php?m=invoice&a=reports<?php echo $report_type_var; ?>" method="post">
<?php echo $AppUI->_('Projects') . ':';?>
<?php echo arraySelect( $project_list, 'project_id', 'size="1" class="text" onchange="changeIt();"', $project_id, false );?>
</form>
<?php
}
*/
if ($report_type) {
$report_type = $AppUI->checkFileName( $report_type );
$report_type = str_replace( ' ', '_', $report_type );
require "$baseDir/modules/invoice/reports/$report_type.php";
} else {
echo "<table>";
echo "<tr><td><h2>" . $AppUI->_( 'Reports Available' ) . "</h2></td></tr>";
foreach ($reports as $v) {
$type = str_replace( ".php", "", $v );
$desc_file = str_replace( ".php", ".{$AppUI->user_locale}.txt", $v );
$desc = @file( "$baseDir/modules/invoice/reports/$desc_file");
echo "\n<tr>";
echo "\n <td><a href=\"index.php?m=invoice&a=reports&project_id=$project_id&report_type=$type";
if (isset($desc[2]))
echo "&" . $desc[2];
echo "\">";
echo @$desc[0] ? $desc[0] : $v;
echo "</a>";
echo "\n</td>";
echo "\n<td>" . (@$desc[1] ? "- $desc[1]" : '') . "</td>";
echo "\n</tr>";
}
echo "</table>";
}
?>
Invoice Style 1
Details include date, desc, hourly rate, hours worked, line total and invoice total.
\ No newline at end of file
<?php
error_reporting(!E_ALL);
$project_id = intval( dPgetParam( $_GET, "project_id", 0 ) );
$invoice_id = intval( dPgetParam( $_GET, "invoice_id", 0 ) );
$invoice_to = intval( dPgetParam( $_GET, "invoice_to", 0 ) );
$tasks = intval( dPgetParam( $_GET, "tasks", 0 ) );
$invTitlePos = 650; // up/down where to begin printing theINVOICE header
$invToPos = 600; // up/down where to print the To: block
$invToInfoPos = 570; // up/down where to print the To: and Info data
$df = $AppUI->getPref('SHDATEFORMAT');
$font_dir = dPgetConfig( 'root_dir' )."/lib/ezpdf/fonts";
$temp_dir = dPgetConfig( 'root_dir' )."/files/temp";
$base_url = dPgetConfig( 'base_url' );
require( $AppUI->getLibraryClass( 'ezpdf/class.ezpdf' ) );
$landscape = 0;
if ($landscape != 1)
$pdf =& new Cezpdf("letter", "portrait");
else
$pdf =& new Cezpdf("letter", "landscape");
$pdf->ezSetCmMargins( 1, 2, 1.5, 1.5 );
$pdf->selectFont( "$font_dir/Helvetica.afm" );
//================================================
// Invoice header
//================================================
$logoFontSize = 20; // font size for the company name
$addressFontSize = 13; // font size for the address lines
$phoneFontSize = 10; // font size for the phone lines
$justification = 'center'; // justification can be left, right, center, full
$compRColor = 0; // rgb color for the company name
$compGColor = 0;
$compBColor = 0;
$textRColor = 0; // rgb values for the remaing text
$textGColor = 0;
$textBColor = 0;
//
// query the database for company info
//
$q = new DBQuery;
$q->addQuery('
company_name,
company_address1,
company_address2,
company_city,
company_state,
company_zip,
company_phone1,
company_fax');
$q->addTable('companies');
$q->leftJoin('config', 'c', 'company_name = config_value');
$q->addWhere('c.config_name = \'company_name\'');
//$srcComp = $q->loadHash();
db_loadHash($q->prepare(), $srcComp);
//
// Set up and print the header data
//
$pdf->ezImage('/var/www/localhost/htdocs/dotproject3/modules/invoice/images/boone.jpg');
$pdf->setColor($compRColor,$compGColor,$compBColor);
$pdf->ezText($srcComp['company_name'], $logoFontSize,
array('justification' => $justification));
$pdf->setColor($textRColor,$textGColor,$textBColor);
$pdf->ezText($srcComp['company_address1'], $addressFontSize, array('justification' => $justification));
// if the second address line is blank, don't print it
if ($srcComp['company_address2'] != '')
$pdf->ezText($srcComp['company_address2'], $addressFontSize, array('justification' => $justification));
$pdf->ezText($srcComp['company_city'] . ', ' .
$srcComp['company_state'] . ' ' .
$srcComp['company_zip'], $addressFontSize,
array('justification' => $justification));
$pdf->ezText($srcComp['company_phone1'], $phoneFontSize,
array('justification' => $justification));
$pdf->ezText($srcComp['company_fax'], $phoneFontSize,
array('justification' => $justification));
$pdf->ezText('');
$pdf->ezText('');
//================================================
// Invoice Title
//================================================
$pdf->ezSetY($invTitlePos);
$pdf->setColor(0,0,1);
$pdf->ezText('INVOICE', 18, array('justification' => 'center'));
$pdf->setColor(0,0,0);
//================================================
// Target company info
//================================================
$pdf->ezSetY($invToPos);
$toFontSize = 14; // font size for the "Invoice To" text
$addressFontSize = 12; // font size for all other "Invoice To" text
$toRColor = 0; // rgb color values for the "Invoice To: text
$toGColor = 0;
$toBColor = 0;
$textRColor = 0; // rgb color values for the remaining text
$textGColor = 0;
$textBColor = 0;
// the next 3 values set where the "Invoice to" block will print on the page
$leftOffset = 45; // offset from left margin
$invoiceInfo = 575; // absolute up/down position
$leftIndent = $leftOffset + 15; // how far to indent the text UNDER "Invoice To"
//
// query the database for the invoiced company address
//
$q = new DBQuery;
$q->addQuery('
company_name,
company_address1,
company_address2,
company_city,
company_state,
company_zip,
company_phone1,
company_fax');
$q->addTable('companies');
$q->leftJoin('projects', 'p', 'project_company = company_id');
$q->addWhere('p.project_id = ' . $project_id);
//$targComp = $q->loadHash();
$targComp = $q->loadHash(); //db_loadHash($q->prepare(), $targComp);
//
// Set up and print the addressed to block
//
$pdf->setColor($toRColor,$toGColor,$toBColor);
$pdf->ezText('Invoice To:', $toFontSize, array('aleft' =>
$leftOffset));
$pdf->ezSetY($invToInfoPos);
$pdf->setColor(0,0,0);
$pdf->ezText($targComp['company_name'], $addressFontSize, array('aleft' => $leftIndent));
$pdf->ezText($targComp['company_address1'], $addressFontSize, array('aleft' => $leftIndent));
if ($targComp['company_address2'] != '')
$pdf->ezText($targComp['company_address2'], $addressFontSize, array('aleft' => $leftIndent));
$pdf->ezText($targComp['company_city'] . ', ' .
$targComp['company_state'] . ' ' .
$targComp['company_zip'], $addressFontSize, array('aleft' =>
$leftIndent));
//================================================
// Main invoice info
//================================================
$pdf->ezSetY($invToInfoPos);
// positions and prints the invoice number, date etc
$fontSize = 12;
$xpos = 0; // holds the position of the last up/down print
$aleftText = 350; // position from left margin to the left of text position
$aleftInfo = $aleftText + 100; // position from left margin to left of data position
// $invoiceInfo sets the up/down position to start printing
$pdf->ezSetY( $invoiceInfo );
// print invoice number
$pdf->ezText( "Invoice Number:", $fontSize, array('aleft' => $aleftText ));
$pdf->ezSetY( $invoiceInfo );
// print invoice date
$xpos = $pdf->ezText( $invoice_id, $fontSize, array('aleft' => $aleftInfo ));
$date = new CDate();
$pdf->ezSetY( $xpos );
$pdf->ezText( 'Invoice Date:', $fontSize, array('aleft' => $aleftText ));
$pdf->ezSetY( $xpos );
$xpos = $pdf->ezText($date->format( $df ) , $fontSize, array('aleft' => $aleftInfo ));
// print invoice terms
$pdf->ezText( 'Invoice Terms:', $fontSize, array('aleft' => $aleftText ));
$pdf->ezSetY( $xpos );
$pdf->ezText('Due Upon Receipt' , $fontSize, array('aleft' => $aleftInfo ));
$pdf->ezSetY( $invoiceInfo - 125 );
//================================================
// Invoice details table
//================================================
// set up the header array
$pdfheaders3 = array(
'Date',
'Description',
'Price',
'Hours',
'Amount');
//-- get some data
$q = new DBQuery;
$q->addQuery('task_amount');
$q->addQuery('invoice_task_queue.task_log_id');
$q->addQuery('task_log_description');
$q->addQuery('task_log_date');
$q->addQuery('task_log_hours');
$q->addQuery('task_log_costcode');
$q->addQuery('billingcode_value');
$q->addTable('invoice_task_queue');
$q->addTable('task_log');
$q->leftJoin('billingcode', 'b', 'b.billingcode_id = task_log_costcode');
$q->addWhere('task_invoice = ' . $invoice_id);
$q->addWhere('task_log.task_log_id = invoice_task_queue.task_log_id');
//$q->addWhere('billingcode.billingcode_id = task_log_costcode');
$pname = $q->loadList();
// create the array needed by ezTable
$pdfdata = array();
$invTotal = 0;
$hoursTotal = 0;
foreach ($pname as $inv) {
$d = new CDate($inv['task_log_date']);
if ($inv['task_amount'] > 0)
$amt = $inv['task_amount'];
else
$amt = round($inv['billingcode_value'] * $inv['task_log_hours'], 2);
$dispAmt = dPgetConfig('currency_symbol') . sprintf("%.2f", $amt, 2);
$invTotal = $invTotal + $amt;
$hoursTotal += $inv['task_log_hours'];
$pdfdata[] = array(
$d->format($df),
$inv['task_log_description'],
(($inv['task_amount'] > 0)?'set':(dPgetConfig('currency_symbol').sprintf("%.2f",$inv['billingcode_value'], 2))),
sprintf("%.2f", $inv['task_log_hours'], 2),
$dispAmt );
}
// define the options for the table
$options = array(
'showLines' => 1,
'showHeadings' => 1,
'fontSize' => 8,
'rowGap' => 2,
'colGap' => 5,
'xPos' => 50,
'xOrientation' => 'right',
'width'=>'527',
'cols'=>array(
0=>array('justification'=>'left','width'=>50),
1=>array('justification'=>'left','width'=>150),
2=>array('justification'=>'center','width'=>75),
3=>array('justification'=>'center','width'=>75),
4=>array('justification'=>'center','width'=>75))
);
// print the table
$pdf->ezTable( $pdfdata, $pdfheaders3,'',$options );
$pdf->ezText('');
$pdf->ezText('');
// print the invoice total
$pdf->ezText("Total hours: " . sprintf("%.2f",$hoursTotal), 12,
array('justification'=>'right'));
$pdf->ezText("Invoice Total: " . dPgetConfig('currency_symbol').sprintf("%.2f",$invTotal,2), 12,
array('justification'=>'right'));
$options = array (
'compress' => 0
);
if (!isset($file))
$pdf->ezStream();
else
{
$file = "$base_url/files/temp/temp_inv" . $AppUI->user_id . '.pdf';
if ($fp = fopen( "$temp_dir/temp_inv" . $AppUI->user_id . '.pdf', 'wb' )) {
fwrite( $fp, $pdf->ezOutput() );
fclose( $fp );
echo "<HTML><SCRIPT>document.location='$file';</SCRIPT></HTML>";
}
else {
echo "Could not open file to save PDF. ";
if (!is_writable( $temp_dir )) {
"The files/temp directory is not writable. Check your file system permissions.";
}
}
}
?>
Invoice Style 2
Same as Style 1 but different colors
\ No newline at end of file
<?php
error_reporting(!E_ALL);
$project_id = intval( dPgetParam( $_GET, "project_id", 0 ) );
$invoice_id = intval( dPgetParam( $_GET, "invoice_id", 0 ) );
$invoice_to = intval( dPgetParam( $_GET, "invoice_to", 0 ) );
$tasks = intval( dPgetParam( $_GET, "tasks", 0 ) );
$invTitlePos = 650; // up/down where to begin printing theINVOICE header
$invToPos = 600; // up/down where to print the To: block
$invToInfoPos = 570; // up/down where to print the To: and Info data
$df = $AppUI->getPref('SHDATEFORMAT');
$font_dir = dPgetConfig( 'root_dir' )."/lib/ezpdf/fonts";
$temp_dir = dPgetConfig( 'root_dir' )."/files/temp";
$base_url = dPgetConfig( 'base_url' );
require( $AppUI->getLibraryClass( 'ezpdf/class.ezpdf' ) );
$landscape = 0;
if ($landscape != 1)
$pdf =& new Cezpdf("letter", "portrait");
else
$pdf =& new Cezpdf("letter", "landscape");
$pdf->ezSetCmMargins( 1, 2, 1.5, 1.5 );
$pdf->selectFont( "$font_dir/Helvetica.afm" );
//================================================
// Invoice header
//================================================
$logoFontSize = 20; // font size for the company name
$addressFontSize = 13; // font size for the address lines
$phoneFontSize = 10; // font size for the phone lines
$justification = 'center'; // justification can be left, right, center, full
$compRColor = .1; // rgb color for the company name
$compGColor = .2;
$compBColor = 1;
$textRColor = .6; // rgb values for the remaing text
$textGColor = 0;
$textBColor = .3;
//
// query the database for company info
//
$q = new DBQuery;
$q->addQuery('
company_name,
company_address1,
company_address2,
company_city,
company_state,
company_zip,
company_phone1,
company_fax');
$q->addTable('companies');
$q->leftJoin('config', 'c', 'company_name = config_value');
$q->addWhere('c.config_name = \'company_name\'');
//$srcComp = $q->loadHash();
db_loadHash($q->prepare(), $srcComp);
//
// Set up and print the header data
//
$pdf->ezImage('/var/www/localhost/htdocs/dotproject3/modules/invoice/images/boone.jpg');
$pdf->setColor($compRColor,$compGColor,$compBColor);
$pdf->ezText($srcComp['company_name'], $logoFontSize,
array('justification' => $justification));
$pdf->setColor($textRColor,$textGColor,$textBColor);
$pdf->ezText($srcComp['company_address1'], $addressFontSize, array('justification' => $justification));
// if the second address line is blank, don't print it
if ($srcComp['company_address2'] != '')
$pdf->ezText($srcComp['company_address2'], $addressFontSize, array('justification' => $justification));
$pdf->ezText($srcComp['company_city'] . ', ' .
$srcComp['company_state'] . ' ' .
$srcComp['company_zip'], $addressFontSize,
array('justification' => $justification));
$pdf->ezText($srcComp['company_phone1'], $phoneFontSize,
array('justification' => $justification));
$pdf->ezText($srcComp['company_fax'], $phoneFontSize,
array('justification' => $justification));
$pdf->ezText('');
$pdf->ezText('');
//================================================
// Invoice Title
//================================================
$pdf->ezSetY($invTitlePos);
$pdf->setColor(0,0,1);
$pdf->ezText('INVOICE', 18, array('justification' => 'center'));
$pdf->setColor(0,0,0);
//================================================
// Target company info
//================================================
$pdf->ezSetY($invToPos);
$toFontSize = 14; // font size for the "Invoice To" text
$addressFontSize = 12; // font size for all other "Invoice To" text
$toRColor = 0; // rgb color values for the "Invoice To: text
$toGColor = 0;
$toBColor = 0;
$textRColor = 0; // rgb color values for the remaining text
$textGColor = 0;
$textBColor = 0;
// the next 3 values set where the "Invoice to" block will print on the page
$leftOffset = 45; // offset from left margin
$invoiceInfo = 575; // absolute up/down position
$leftIndent = $leftOffset + 15; // how far to indent the text UNDER "Invoice To"
//
// query the database for the invoiced company address
//
$q = new DBQuery;
$q->addQuery('
company_name,
company_address1,
company_address2,
company_city,
company_state,
company_zip,
company_phone1,
company_fax');
$q->addTable('companies');
$q->leftJoin('projects', 'p', 'project_company = company_id');
$q->addWhere('p.project_id = ' . $project_id);
//$targComp = $q->loadHash();
db_loadHash($q->prepare(), $targComp);
//
// Set up and print the addressed to block
//
$pdf->setColor($toRColor,$toGColor,$toBColor);
$pdf->ezText('Invoice To:', $toFontSize, array('aleft' =>
$leftOffset));
$pdf->ezSetY($invToInfoPos);
$pdf->setColor(0,0,0);
$pdf->ezText($targComp['company_name'], $addressFontSize, array('aleft' => $leftIndent));
$pdf->ezText($targComp['company_address1'], $addressFontSize, array('aleft' => $leftIndent));
if ($targComp['company_address2'] != '')
$pdf->ezText($targComp['company_address2'], $addressFontSize, array('aleft' => $leftIndent));
$pdf->ezText($targComp['company_city'] . ', ' .
$targComp['company_state'] . ' ' .
$targComp['company_zip'], $addressFontSize, array('aleft' =>
$leftIndent));
//================================================
// Main invoice info
//================================================
$pdf->ezSetY($invToInfoPos);
// positions and prints the invoice number, date etc
$fontSize = 12;
$xpos = 0; // holds the position of the last up/down print
$aleftText = 350; // position from left margin to the left of text position
$aleftInfo = $aleftText + 100; // position from left margin to left of data position
// $invoiceInfo sets the up/down position to start printing
$pdf->ezSetY( $invoiceInfo );
// print invoice number
$pdf->ezText( "Invoice Number:", $fontSize, array('aleft' => $aleftText ));
$pdf->ezSetY( $invoiceInfo );
// print invoice date
$xpos = $pdf->ezText( $invoice_id, $fontSize, array('aleft' => $aleftInfo ));
$date = new CDate();
$pdf->ezSetY( $xpos );
$pdf->ezText( 'Invoice Date:', $fontSize, array('aleft' => $aleftText ));
$pdf->ezSetY( $xpos );
$xpos = $pdf->ezText($date->format( $df ) , $fontSize, array('aleft' => $aleftInfo ));
// print invoice terms
$pdf->ezText( 'Invoice Terms:', $fontSize, array('aleft' => $aleftText ));
$pdf->ezSetY( $xpos );
$pdf->ezText('Due Upon Receipt' , $fontSize, array('aleft' => $aleftInfo ));
$pdf->ezSetY( $invoiceInfo - 125 );
//================================================
// Invoice details table
//================================================
// set up the header array
$pdfheaders3 = array(
'Date',
'Description',
'Price',
'Hours',
'Amount');
//-- get some data
$q = new DBQuery;
$q->addQuery('task_amount');
$q->addQuery('invoice_task_queue.task_log_id');
$q->addQuery('task_log_description');
$q->addQuery('task_log_date');
$q->addQuery('task_log_hours');
$q->addQuery('task_log_costcode');
$q->addQuery('billingcode_value');
$q->addTable('invoice_task_queue');
$q->addTable('task_log');
$q->leftJoin('billingcode', 'b', 'b.billingcode_id = task_log_costcode');
$q->addWhere('task_invoice = ' . $invoice_id);
$q->addWhere('task_log.task_log_id = invoice_task_queue.task_log_id');
//$q->addWhere('billingcode.billingcode_id = task_log_costcode');
$pname = $q->loadList();
// create the array needed by ezTable
$pdfdata = array();
$invTotal = 0;
$hoursTotal = 0;
foreach ($pname as $inv) {
$d = new CDate($inv['task_log_date']);
if ($inv['task_amount'] > 0)
$amt = $inv['task_amount'];
else
$amt = round($inv['billingcode_value'] * $inv['task_log_hours'], 2);
$dispAmt = dPgetConfig('currency_symbol') . sprintf("%.2f", $amt, 2);
$invTotal = $invTotal + $amt;
$hoursTotal += $inv['task_log_hours'];
$pdfdata[] = array(
$d->format($df),
$inv['task_log_description'],
(($inv['task_amount'] > 0)?'set':(dPgetConfig('currency_symbol').sprintf("%.2f",$inv['billingcode_value'], 2))),
sprintf("%.2f", $inv['task_log_hours'], 2),
$dispAmt );
}
// define the options for the table
$options = array(
'showLines' => 1,
'showHeadings' => 1,
'fontSize' => 8,
'rowGap' => 2,
'colGap' => 5,
'xPos' => 50,
'xOrientation' => 'right',
'width'=>'527',
'cols'=>array(
0=>array('justification'=>'left','width'=>50),
1=>array('justification'=>'left','width'=>150),
2=>array('justification'=>'center','width'=>75),
3=>array('justification'=>'center','width'=>75),
4=>array('justification'=>'center','width'=>75))
);
// print the table
$pdf->ezTable( $pdfdata, $pdfheaders3,'',$options );
$pdf->ezText('');
$pdf->ezText('');
// print the invoice total
$pdf->ezText("Total hours: " . sprintf("%.2f",$hoursTotal), 12,
array('justification'=>'right'));
$pdf->ezText("Invoice Total: " . dPgetConfig('currency_symbol').sprintf("%.2f",$invTotal,2), 12,
array('justification'=>'right'));
$options = array (
'compress' => 0
);
if (!isset($file))
$pdf->ezStream();
else
{
$file = "$base_url/files/temp/temp_inv" . $AppUI->user_id . '.pdf';
if ($fp = fopen( "$temp_dir/temp_inv" . $AppUI->user_id . '.pdf', 'wb' )) {
fwrite( $fp, $pdf->ezOutput() );
fclose( $fp );
echo "<HTML><SCRIPT>document.location='$file';</SCRIPT></HTML>";
}
else {
echo "Could not open file to save PDF. ";
if (!is_writable( $temp_dir )) {
"The files/temp directory is not writable. Check your file system permissions.";
}
}
}
?>
<?php
/*
* Name: Invoice
* Directory: invoice
* Version: 0.1
* Class: user
* UI Name: Invoice
* UI Icon:
*/
// MODULE CONFIGURATION DEFINITION
$config = array();
$config['mod_name'] = 'Invoice';
$config['mod_version'] = '0.1';
$config['mod_directory'] = 'invoice';
$config['mod_setup_class'] = 'CSetupInvoice';
$config['mod_type'] = 'user';
$config['mod_ui_name'] = 'Invoice';
$config['mod_ui_icon'] = 'applet3-48.png';
$config['mod_description'] = 'A module for billing tasks';
if (@$a == 'setup') {
echo dPshowModuleConfig( $config );
}
class CSetupInvoice{
function install() {
$sql = "(
`invoice_id` bigint(20) NOT NULL auto_increment,
`invoice_project` int(11) NOT NULL default '0',
`invoice_status` int(4) NOT NULL default '0',
`invoice_date` int(11) NOT NULL default '0',
`invoice_paid` int(11) default NULL,
`invoice_creator` int(11) NOT NULL default '0',
PRIMARY KEY (`invoice_id`)
) TYPE=MyISAM ";
$q = new DBQuery;
$q->createTable('invoice');
$q->createDefinition($sql);
$q->exec();
$sql = "(
`task_queue_id` int(11) NOT NULL auto_increment,
`task_invoice` int(11) NOT NULL default '0',
`task_amount` float NOT NULL default '0',
`task_log_id` bigint(20) NOT NULL default '0',
PRIMARY KEY (`task_queue_id`)
) TYPE=MyISAM ";
$q->clear();
$q->createTable('invoice_task_queue');
$q->createDefinition($sql);
$q->exec();
return null;
}
function remove() {
$q = new DBQuery;
$q->dropTable('invoice');
$q->exec();
$q->clear();
$q->dropTable('invoice_task_queue');
$q->exec();
return null;
}
function upgrade() {
return null;
}
}
?>
This diff is collapsed.
<?php
function invoices($type)
{
GLOBAL $AppUI, $invoices;
$df = $AppUI->getPref('SHDATEFORMAT');
?>
<table width="100%" border="0" cellpadding="3" cellspacing="1" class="tbl">
<tr>
<th align="right" width="65" nowrap="nowrap">&nbsp;<?php echo $AppUI->_('sort by');?>:&nbsp;</th>
<th nowrap="nowrap">
<a href="?m=invoice&orderby=invoice_id" class="hdr"><?php echo $AppUI->_('Invoice Number');?></a>
</th>
<th nowrap="nowrap">
<a href="?m=invoice&orderby=invoice_project" class="hdr"><?php echo $AppUI->_('Project');?></a>
</th>
<th nowrap="nowrap">
<a href="?m=invoice&orderby=invoice_creator" class="hdr"><?php echo $AppUI->_('Creator');?></a>
</th>
<th nowrap="nowrap">
<a href="?m=invoice&orderby=invoice_date" class="hdr"><?php echo $AppUI->_('Created On');?></a>
</th>
<th nowrap="nowrap">
<a href="?m=invoice&orderby=invoice_amount" class="hdr"><?php echo $AppUI->_('Invoice Amount');?>:</a>
</th>
</tr>
<?php
$CR = "\n";
$CT = "\n\t";
$none = true;
$q = new DBQuery;
foreach ($invoices as $row)
{
if ($row["invoice_status"] == $type)
{
$none = false;
$q->clear();
$q->addQuery('
project_name,
project_description');
$q->addTable('projects');
$q->addWhere('project_id = ' . $row['invoice_project']);
$myproject_name=$q->loadList();
// edit query FROM users; user_first_name and user_last_name
$q->clear();
$q->addQuery('
contact_first_name,
contact_last_name');
$q->addTable('contacts');
$q->leftJoin('users', 'u', 'user_contact=contact_id');
$q->addWhere('user_id = ' . $row['invoice_creator']);
$myuser_name=$q->loadList();
$mydate=strftime($df,$row["invoice_date"]);
$total_amount=get_invoice_amount($row["invoice_id"], $row["invoice_project"]);
$s = '<tr>';
$s .= $CR . '<td>';
if ($type == 0)
$s .= '<a href="?m=invoice&a=addedit&invoice_id=' . $row['invoice_id'] . '&project_id=' . $row['invoice_project'] . '"><img src="./images/icons/pencil.gif" alt="'.$AppUI->_( 'Edit Invoice' ).'" border="0" width="12" height="12"></a>';
$s .= '&nbsp; </td>';
$s .= $CR . '<td nowrap="nowrap" width=100><a href="?m=invoice&a=view&project_id=' . $row["invoice_project"] . '&invoice_id=' . $row["invoice_id"] .'">#' . $row["invoice_id"] . '</a></td>';
$s .= $CR . '<td width=500>';
$s .= $CT . '<a href="?m=projects&a=view&project_id=' . $row["invoice_project"] . '" title="' . $myproject_name[0]["project_description"] . '">' . $myproject_name[0]["project_name"] . '</a>';
$s .= $CR . '</td>';
$s .= $CR . '<td nowrap="nowrap">' .$myuser_name[0]["contact_first_name"]. ' '.$myuser_name[0]["contact_last_name"]. '</td>';
$s .= $CR . '<td nowrap="nowrap">' .$mydate. '</td>';
$s .= $CR . '<td nowrap="nowrap">'.dPgetConfig('currency_symbol') .$total_amount. '</td>';
$s .= $CR . '</tr>';
echo $s;
}
}
if ($none) {
echo $CR . '<tr><td colspan="6">' . $AppUI->_( 'No open invoice available' ) . '</td></tr>';
}
?>
<tr>
<td colspan="6">&nbsp;</td>
</tr>
</table>
<?php
}
function get_invoice_amount($invoice_id, $project_id) {
$amount=0;
$q = new DBQuery;
$q->addQuery('project_company');
$q->addTable('projects');
$q->addWhere('project_id = '. $project_id);
$company_id = $q->loadResult();
//$tmpprj=db_exec($sql);
//$row=db_fetch_assoc($tmpprj);
//$company_id=$row["project_company"];
$q->clear();
$q->addQuery('
billingcode_id,
billingcode_name,
billingcode_value');
$q->addTable('billingcode');
$q->addWhere('company_id = ' . $company_id);
$q->addOrder('billingcode_name ASC');
$billingcodes = $q->loadList();
$q->clear();
$q->addQuery('
t.task_invoice,
t.task_queue_id,
t.task_amount,
t.task_log_id,
t1.task_log_costcode,
t1.task_log_hours');
$q->addTable('invoice_task_queue', 't');
$q->leftJoin('task_log', 't1', 't.task_log_id=t1.task_log_id');
$q->addWhere('task_invoice = ' . $invoice_id);
$q->addGroup('t.task_log_id');
$tasks=$q->loadList();
foreach($tasks as $task)
{
if ($task['task_amount'] == '0')
{
for ($x=0; $x < count($billingcodes); $x++)
if ($billingcodes[$x]['billingcode_id'] == $task['task_log_costcode'])
$rate=$billingcodes[$x]['billingcode_value'];
$amount+=round($rate * $task['task_log_hours'],2);
}
else
$amount=$amount + round($task['task_amount'],2);
}
return $amount;
}
?>
<?php
include("vw_inc.php");
echo invoices(0);
?>
<?php
include("vw_inc.php");
echo invoices(2);
?>
<?php
include("vw_inc.php");
echo invoices(1);
?>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment