Moving company data storage to company subdirectory
authorJanusz Dobrowolski <janusz@frontaccounting.eu>
Tue, 25 Mar 2008 10:37:39 +0000 (10:37 +0000)
committerJanusz Dobrowolski <janusz@frontaccounting.eu>
Tue, 25 Mar 2008 10:37:39 +0000 (10:37 +0000)
13 files changed:
admin/backups.php
admin/create_coy.php
admin/db/maintenance_db.inc
install/index.php
inventory/manage/items.php
reporting/includes/pdf_report.inc
reporting/pdf_files/index.php [deleted file]
reporting/rep102.php
reporting/rep104.php
reporting/rep202.php
reporting/rep303.php
reporting/rep706.php
reporting/rep707.php

index dd73be6d899ef0d73ba8974255dfdb95e1bd5eb6..3286f48c8600d4678a30fe211996e054a9c1002a 100644 (file)
@@ -46,7 +46,7 @@ echo "
                        alert('" . _('This extension can not be be viewed: ') . "' + ext)
                        return
                }       
-               window.open('" . $path_to_root . BACKUP_PATH . "'+pFilename, '', 'toolbar=no,scrollbars=yes')
+               window.open('" . BACKUP_PATH . "'+pFilename, '', 'toolbar=no,scrollbars=yes')
        }
        function deleteBackup() {
                pFilename = document.forms[0].cmb_backups.options[document.forms[0].cmb_backups.selectedIndex].value
@@ -128,14 +128,14 @@ function handle_form($conn)
                //Download the file
                if ($_GET['c']=='d') 
                {
-                       download_file($path_to_root . BACKUP_PATH . $_GET['fn']);
+                       download_file(BACKUP_PATH . $_GET['fn']);
                        exit;
                }
                //Delete the file
                if ($_GET['c']=='df') 
                {
                        $filename = $_GET['fn'];
-                       @unlink($path_to_root . BACKUP_PATH . $filename);
+                       @unlink(BACKUP_PATH . $filename);
                        header("Location: backups.php?c=dff&fn=" . urlencode($filename));
                        return "";
                }
@@ -166,7 +166,7 @@ function handle_form($conn)
                if ($_GET['c']=='r') 
                {
                        $filename=$_GET['fn'];
-                       restore_backup($path_to_root . BACKUP_PATH . $filename, $conn);
+                       restore_backup(BACKUP_PATH . $filename, $conn);
                        header("Location: backups.php?c=rs&fn=" . urlencode($filename));
                        return "";
                }
@@ -217,7 +217,7 @@ function get_backup_file_combo()
        global $path_to_root;
        $ar_files = array();
 
-    $dh = opendir($path_to_root . BACKUP_PATH);
+    $dh = opendir(BACKUP_PATH);
        while (($file = readdir($dh)) !== false)
                $ar_files[] = $file;
        closedir($dh);
@@ -266,8 +266,8 @@ function valid_paths()
        global $path_to_root;
        
        $st = "";
-       if (!file_exists($path_to_root . BACKUP_PATH))  
-               $st .= "&nbsp;&nbsp;&nbsp;-&nbsp;" . _("cannot find backup directory") . " - " . $path_to_root . BACKUP_PATH . "<br>";
+       if (!file_exists(BACKUP_PATH))  
+               $st .= "&nbsp;&nbsp;&nbsp;-&nbsp;" . _("cannot find backup directory") . " - " . BACKUP_PATH . "<br>";
        return $st;
 }
 
index 2730b7cfd130fdbde716f02e522fdb5740aef8b2..b43224abce6724db30095f0790540ca9cf0eee4b 100644 (file)
@@ -11,6 +11,7 @@ include_once($path_to_root . "/includes/ui.inc");
 
 page(_("Create/Update Company"));
 
+$comp_subdirs = array('images', 'pdf_files', 'backup','js_cache');
 
 //---------------------------------------------------------------------------------------------
 
@@ -34,9 +35,24 @@ function check_data()
 
 //---------------------------------------------------------------------------------------------
 
+function remove_connection($id) {
+       global $db_connections;
+
+       $dbase = $db_connections[$id]['dbname'];
+       $err = db_drop_db($db_connections[$id]);
+
+       unset($db_connections[$id]);
+       $conn = array_values($db_connections);
+       $db_connections = $conn;
+       //$$db_connections = array_values($db_connections);
+    return $err;
+}
+//---------------------------------------------------------------------------------------------
+
 function handle_submit()
 {
-       global $db_connections, $def_coy, $tb_pref_counter, $db;
+       global $db_connections, $def_coy, $tb_pref_counter, $db,
+           $comp_path, $comp_subdirs;
 
        $new = false;
 
@@ -64,21 +80,13 @@ function handle_submit()
        }
        if ((bool)$_POST['def'] == true)
                $def_coy = $id;
-       $error = write_config_db($new);
-       if ($error == -1)
-               display_error(_("Cannot open the configuration file - ") . $path_to_root . "/config_db.php");
-       else if ($error == -2)
-               display_error(_("Cannot write to the configuration file - ") . $path_to_root . "/config_db.php");
-       else if ($error == -3)
-               display_error(_("The configuration file ") . $path_to_root . "/config_db.php" . _(" is not writable. Change its permissions so it is, then re-run the operation."));
-       if ($error != 0)
-               return false;
        if (isset($_GET['ul']) && $_GET['ul'] == 1)
        {
                $conn = $db_connections[$id];
                if (($db = db_create_db($conn)) == 0)
                {
                        display_error(_("Error creating Database: ") . $conn['dbname'] . _(", Please create it manually"));
+                       remove_connection($id);
                        set_global_connection();
                        return false;
                }
@@ -98,6 +106,28 @@ function handle_submit()
                }
                set_global_connection();
        }
+       $error = write_config_db($new);
+       if ($error == -1)
+               display_error(_("Cannot open the configuration file - ") . $path_to_root . "/config_db.php");
+       else if ($error == -2)
+               display_error(_("Cannot write to the configuration file - ") . $path_to_root . "/config_db.php");
+       else if ($error == -3)
+               display_error(_("The configuration file ") . $path_to_root . "/config_db.php" . _(" is not writable. Change its permissions so it is, then re-run the operation."));
+       if ($error != 0) {
+               return false;
+       }
+       $index = "<?php\nheader(\"Location: ../../index.php\");\n?>";
+       
+       if ($new) {
+           $cdir = $comp_path.'/'.($tb_pref_counter-1);
+           @mkdir($cdir); 
+           save_to_file($cdir.'/'.'index.php', 0, $index);
+           
+           foreach($comp_subdirs as $dir) {
+               @mkdir($cdir.'/'.$dir);
+               save_to_file($cdir.'/'.$dir.'/'.'index.php', 0, $index);
+           }
+       }
        return true;
 }
 
@@ -105,18 +135,18 @@ function handle_submit()
 
 function handle_delete()
 {
-       global $def_coy, $db_connections;
+       global $comp_path, $def_coy, $db_connections, $comp_subdirs;
 
        $id = $_GET['id'];
 
-       $dbase = $db_connections[$id]['dbname'];
-       $err = db_drop_db($db_connections[$id]);
+       $pref = $db_connections[$id]['tbpref'];
+       if($pref!='')
+           $pref = substr($pref, 0, strlen($pref)-1); 
 
-       unset($db_connections[$id]);
-       $conn = array_values($db_connections);
-       $db_connections = $conn;
+       $err = remove_connection($id);
+       if ($err == 0)
+               display_error(_("Error removing Database: ") . $dbase . _(", please remove it manuallly"));
 
-       //$$db_connections = array_values($db_connections);
        if ($def_coy == $id)
                $def_coy = 0;
        $error = write_config_db();
@@ -128,10 +158,15 @@ function handle_delete()
                display_error(_("The configuration file ") . $path_to_root . "/config_db.php" . _(" is not writable. Change its permissions so it is, then re-run the operation."));
        if ($error != 0)
                return;
-       if ($err == 0)
-               display_error(_("Error removing Database: ") . $dbase . _(", please remove it manuallly"));
-       else
-               meta_forward($_SERVER['PHP_SELF']);
+
+       $cdir = $comp_path.'/'.$pref;
+       flush_dir($cdir);
+       if (!rmdir($cdir)) {
+               display_error(_("Cannot remove company data directory ") . $cdir);
+               return;
+       }
+       
+       meta_forward($_SERVER['PHP_SELF']);
 }
 
 //---------------------------------------------------------------------------------------------
index 8ed6b7dffd57dfe6e3bef9b9da68db4984cd7cb6..4907366693dd5ec65069b4bc1eb09245be0e4c1b 100644 (file)
@@ -96,7 +96,7 @@ function db_drop_db($connection)
         // get table structures
                foreach ($all_tables as $table)
                {
-                       if (strpos($table['Name'], $connection["tbpref"]) !== false)
+                       if (strpos($table['Name'], $connection["tbpref"]) === 0)
                                db_query("DROP TABLE `".$table['Name'] . "`");
                }
                //deleting the tables, how??
@@ -435,7 +435,7 @@ function db_export($conn, $filename, $zip='no', $comment='')
                        }
                        elseif ($error)
                        {
-                               @unlink($path_to_root . BACKUP_PATH . $backupfile);
+                               @unlink(BACKUP_PATH . $backupfile);
                                return false;
                        }
 
@@ -453,7 +453,7 @@ function db_export($conn, $filename, $zip='no', $comment='')
        }
        else
        {
-               @unlink($path_to_root . BACKUP_PATH . $backupfile);
+               @unlink(BACKUP_PATH . $backupfile);
                return false;
        }
 
@@ -468,7 +468,7 @@ function db_export($conn, $filename, $zip='no', $comment='')
        }
        else
        {
-               @unlink($path_to_root . BACKUP_PATH . $backupfile);
+               @unlink(BACKUP_PATH . $backupfile);
                return false;
        }
     return $backupfile;
@@ -531,7 +531,7 @@ function save_to_file($backupfile, $zip, $fileData)
 
     if ($zip == "gzip")
     {
-        if ($zp = @gzopen($path_to_root . BACKUP_PATH . $backupfile, "a9"))
+        if ($zp = @gzopen(BACKUP_PATH . $backupfile, "a9"))
         {
                        @gzwrite($zp, $fileData);
                        @gzclose($zp);
@@ -607,7 +607,7 @@ function save_to_file($backupfile, $zip, $fileData)
         // total # of entries "on this disk", total # of entries overall, size of central dir, offset to start of central dir, .zip file comment length
         $fileData .= pack('v', 1) . pack('v', 1) . pack('V', strlen($cdrec)) . pack('V', strlen($fr)) . "\x00\x00";
 
-        if ($zp = @fopen($path_to_root . BACKUP_PATH . $backupfile, "a"))
+        if ($zp = @fopen(BACKUP_PATH . $backupfile, "a"))
         {
                        @fwrite($zp, $fileData);
                        @fclose($zp);
@@ -622,7 +622,7 @@ function save_to_file($backupfile, $zip, $fileData)
     }
     else
     {
-        if ($zp = @fopen($path_to_root . BACKUP_PATH . $backupfile, "a"))
+        if ($zp = @fopen(BACKUP_PATH . $backupfile, "a"))
         {
                        @fwrite($zp, $fileData);
                        @fclose($zp);
index 65ce6668a7dcc74a18f9b6a51c2898729b485c8d..68f3b354ae8f20f80eb4d98674450a450f57fed8 100644 (file)
@@ -1,5 +1,4 @@
 <?php
-
 error_reporting(E_ALL);
 ini_set("display_errors", "On");
 // Start a session
@@ -32,6 +31,7 @@ else
        }
 }
 $path_to_root = "..";
+include_once($path_to_root.'/config.php');
 
 ?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
@@ -128,20 +128,16 @@ function change_os(type) {
                <tr>
                        <td style="color: #666666;">config_db.php</td>
                        <td><?php if(is_writable($path_to_root.'/config_db.php')) { echo '<font class="good">Writeable</font>'; } elseif(!file_exists($path_to_root.'/config_db.php')) { echo '<font class="bad">File Not Found</font>'; } else { echo '<font class="bad">Unwriteable</font>'; } ?></td>
-                       <td style="color: #666666;">inventory/manage/image/</td>
-                       <td><?php if(is_writable($path_to_root.'/inventory/manage/image/')) { echo '<font class="good">Writeable</font>'; } elseif(!file_exists($path_to_root.'/inventory/manage/image/')) { echo '<font class="bad">Directory Not Found</font>'; } else { echo '<font class="bad">Unwriteable</font>'; } ?></td>
+                       <td style="color: #666666;">modules/</td>
+                       <td><?php if(is_writable($path_to_root.'/modules/')) { echo '<font class="good">Writeable</font>'; } elseif(!file_exists($path_to_root.'/lang/')) { echo '<font class="bad">Directory Not Found</font>'; } else { echo '<font class="bad">Unwriteable</font>'; } ?></td>
                </tr>
                <tr>
                        <td style="color: #666666;">lang/</td>
                        <td><?php if(is_writable($path_to_root.'/lang/')) { echo '<font class="good">Writeable</font>'; } elseif(!file_exists($path_to_root.'/lang/')) { echo '<font class="bad">Directory Not Found</font>'; } else { echo '<font class="bad">Unwriteable</font>'; } ?></td>
-                       <td style="color: #666666;">reporting/pdf_files/</td>
-                       <td><?php if(is_writable($path_to_root.'/reporting/pdf_files/')) { echo '<font class="good">Writeable</font>'; } elseif(!file_exists($path_to_root.'/reporting/pdf_files/')) { echo '<font class="bad">Directory Not Found</font>'; } else { echo '<font class="bad">Unwriteable</font>'; } ?></td>
-               </tr>
-               <tr>
-                       <td style="color: #666666;">modules/</td>
-                       <td><?php if(is_writable($path_to_root.'/modules/')) { echo '<font class="good">Writeable</font>'; } elseif(!file_exists($path_to_root.'/lang/')) { echo '<font class="bad">Directory Not Found</font>'; } else { echo '<font class="bad">Unwriteable</font>'; } ?></td>
-                       <td style="color: #666666;">admin/backup/</td>
-                       <td><?php if(is_writable($path_to_root.'/admin/backup/')) { echo '<font class="good">Writeable</font>'; } elseif(!file_exists($path_to_root.'/admin/backup/')) { echo '<font class="bad">Directory Not Found</font>'; } else { echo '<font class="bad">Unwriteable</font>'; } ?></td>
+                       <td style="color: #666666;"><?php echo 'Company data dirs ('.  $comp_path. '/*)'; ?></td>
+                       <td><?php if(is_writable($comp_path) && is_writable($comp_path.'/0') && is_writable($comp_path.'/0/images')) 
+                       { echo '<font class="good">Writeable</font>'; } elseif(!file_exists($comp_path)) {
+                        echo '<font class="bad">Directory Not Found</font>'; } else { echo '<font class="bad">Unwriteable</font>'; } ?></td>
                </tr>
                </table>
                <table cellpadding="3" cellspacing="0" width="100%" align="center">
index 486a3d16fd54306922f2a3b0fd695b8808f55544..4a954d34ab77e068373b86068f08cc0fcfe4a016 100644 (file)
@@ -39,7 +39,7 @@ if (isset($_FILES['pic']) && $_FILES['pic']['name'] != '')
 {
        $result = $_FILES['pic']['error'];
        $upload_file = 'Yes'; //Assume all is well to start off with
-       $filename = $path_to_root . "/inventory/manage/image/$user_comp/";
+       $filename = $comp_path . "/$user_comp/images";
        if (!file_exists($filename))
        {
                mkdir($filename);
@@ -206,7 +206,7 @@ if (isset($_POST['delete']) && strlen($_POST['delete']) > 1)
 
                $stock_id = $_POST['NewStockID'];
                delete_item($stock_id);
-               $filename = $path_to_root . "/inventory/manage/image/$user_comp/$stock_id.jpg";
+               $filename = $comp_path . "/$user_comp/images/$stock_id.jpg";
                if (file_exists($filename))
                        unlink($filename);
                meta_forward($_SERVER['PHP_SELF']);
@@ -300,9 +300,9 @@ start_table("$table_style2 width=40%");
 start_row();
 label_cells(_("Image File (.jpg)") . ":", "<input type='file' id='pic' name='pic'>");
 // Add Image upload for New Item  - by Joe
-if (isset($_POST['NewStockID']) && file_exists("$path_to_root/inventory/manage/image/$user_comp/".$_POST['NewStockID'].".jpg")) 
+if (isset($_POST['NewStockID']) && file_exists("$comp_path/$user_comp/images/".$_POST['NewStockID'].".jpg")) 
 {
-       $stock_img_link = "<img src='$path_to_root/inventory/manage/image/$user_comp/".$_POST['NewStockID'].".jpg' width='$pic_width' height='$pic_height' border='0'>";
+       $stock_img_link = "<img src='$comp_path/$user_comp/images/".$_POST['NewStockID'].".jpg' width='$pic_width' height='$pic_height' border='0'>";
 } 
 else 
 {
index 05bb203e9b4019d6fda241a76e165bb4bba33501..71589758e8fd080c57cfb66d1d5fdace14fc3455 100644 (file)
@@ -3,7 +3,7 @@
 $page_security = 8;
 include_once($path_to_root . "reporting/includes/class.pdf.inc");
 include_once($path_to_root . "admin/db/company_db.inc");
-
+include_once($path_to_root . "config.php");
 class FrontReport extends Cpdf
 {
        var $size;
@@ -265,7 +265,7 @@ class FrontReport extends Cpdf
 
        function Header2($myrow, $branch, $sales_order, $bankaccount, $doctype)
        {
-               global $path_to_root, $print_as_quote, $print_invoice_no;
+               global $comp_path, $path_to_root, $print_as_quote, $print_invoice_no;
 
                $this->pageNumber++;
                if ($this->pageNumber > 1)
@@ -325,7 +325,7 @@ class FrontReport extends Cpdf
                $this->row = $upper - 2 * $this->lineHeight - 2;
                if ($this->company['coy_logo'] != '')
                {
-                       $logo = $path_to_root . "themes/default/images/" . $this->company['coy_logo'];
+                       $logo = $comp_path .'/'. user_company() . "/images/" . $this->company['coy_logo'];
                        $this->AddImage($logo, $ccol, $iline1 + 5, 250, 40);
                }
                else
@@ -604,7 +604,7 @@ class FrontReport extends Cpdf
 
        function End($email=0, $subject=null, $myrow=null, $doctype = 0)
        {
-               global $go_debug, $path_to_root;
+               global $go_debug, $path_to_root, $comp_path;
 
                // this is no good in IE so has been replaced, see down under
                // but good for debugging purposes in IE
@@ -631,7 +631,7 @@ class FrontReport extends Cpdf
                {
                        $buf = $this->output();
                        $len = strlen($buf);
-                       $dir = './pdf_files';
+                       $dir =  $comp_path.'/'.user_company(). '/pdf_files';
                        //save the file
                        if (!file_exists($dir))
                        {
diff --git a/reporting/pdf_files/index.php b/reporting/pdf_files/index.php
deleted file mode 100644 (file)
index 763940a..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-<?php
-header("Location: ../index.php");
-?>
index ffe022f81930f8dc4a158e1cfe927acea859eec0..508844da6c5d233fd8afffdba82d425a60b950a5 100644 (file)
@@ -98,7 +98,7 @@ function get_invoices($costomer_id, $to)
 
 function print_aged_customer_analysis()
 {
-    global $path_to_root;
+    global $comp_path, $path_to_root;
 
     include_once($path_to_root . "reporting/includes/pdf_report.inc");
 
@@ -228,7 +228,7 @@ function print_aged_customer_analysis()
        $rep->Line($rep->row  + 4);
        $rep->NewLine();
        }
-    $rep->fontSize += 2;
+       $rep->fontSize += 2;
        $rep->TextCol(0, 3, _('Grand Total'));
        $rep->fontSize -= 2;
        for ($i = 0; $i < count($total); $i++)
@@ -253,7 +253,7 @@ function print_aged_customer_analysis()
                $pg->built_in  = false;
                $pg->fontfile  = $path_to_root . "reporting/fonts/Vera.ttf";
                $pg->latin_notation = ($decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()] != ".");
-               $filename = $path_to_root . "reporting/pdf_files/test.png";
+               $filename = $comp_path .'/'. user_company(). "/images/test.png";
                $pg->display($filename, true);
                $w = $pg->width / 1.5;
                $h = $pg->height / 1.5;
index dd30a31625e93eab8174ac9b661ef3ea2991b150..899da054cfcbfe0f00f4df5cc93d46137a0c9bf9 100644 (file)
@@ -54,7 +54,7 @@ function get_prices($category=0, $salestype=0)
 
 function print_price_listing()
 {
-    global $path_to_root, $pic_height, $pic_width;
+    global $comp_path, $path_to_root, $pic_height, $pic_width;
 
     include_once($path_to_root . "reporting/includes/pdf_report.inc");
 
@@ -145,7 +145,7 @@ function print_price_listing()
                }       
                if ($pictures)
                {
-                       $image = $path_to_root . "inventory/manage/image/" . $user_comp . "/" . $myrow['stock_id'] . ".jpg";
+                       $image = $comp_path . '/'. $user_comp . "/images/" . $myrow['stock_id'] . ".jpg";
                        if (file_exists($image))
                        {
                                $rep->NewLine();
index 6c23b6347045aa1825ca2df088a0089aff5b3dc3..ce39dd8668a2cc403e017e84533c45acbebcf7ce 100644 (file)
@@ -107,7 +107,7 @@ function get_invoices($supplier_id, $to)
 
 function print_aged_supplier_analysis()
 {
-    global $path_to_root;
+    global $comp_path, $path_to_root;
 
     include_once($path_to_root . "reporting/includes/pdf_report.inc");
 
@@ -268,7 +268,7 @@ function print_aged_supplier_analysis()
                $pg->built_in  = false;
                $pg->fontfile  = $path_to_root . "reporting/fonts/Vera.ttf";
                $pg->latin_notation = ($decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()] != ".");
-               $filename = $path_to_root . "reporting/pdf_files/test.png";
+               $filename = $comp_path.'/'.user_company(). "/pdf_files/test.png";
                $pg->display($filename, true);
                $w = $pg->width / 1.5;
                $h = $pg->height / 1.5;
index 801561f197ddccba89e3108ff0e8a0cdc8ba3afa..bb0fc86d6a15228ed12dc9d3b6c30f5276044cba 100644 (file)
@@ -94,7 +94,7 @@ function getDemandAsmQty($stockid, $location)
 
 function print_stock_check()
 {
-    global $path_to_root, $pic_height, $pic_width;
+    global $comp_path, $path_to_root, $pic_height, $pic_width;
 
     include_once($path_to_root . "reporting/includes/pdf_report.inc");
 
@@ -166,7 +166,7 @@ function print_stock_check()
                $rep->TextCol(4, 5, number_format2($trans['QtyOnHand'] - $demandqty, $dec));
                if ($pictures)
                {
-                       $image = $path_to_root . "inventory/manage/image/" . $user_comp . "/" . $trans['stock_id'] . ".jpg";
+                       $image = $comp_path .'/'. $user_comp . '/images/' . $trans['stock_id'] . '.jpg';
                        if (file_exists($image))
                        {
                                $rep->NewLine();
index 9f20eb6bf44a5d75aab022afe520e15d6a7131c7..68b52f98ef8c0863730741ef6d403585678bdbeb 100644 (file)
@@ -24,7 +24,7 @@ print_balance_sheet();
 
 function print_balance_sheet()
 {
-       global $path_to_root;
+       global $comp_path, $path_to_root;
 
        include_once($path_to_root . "reporting/includes/pdf_report.inc");
        $dim = get_company_pref('use_dimension');
@@ -259,7 +259,7 @@ function print_balance_sheet()
                $pg->built_in  = false;
                $pg->fontfile  = $path_to_root . "reporting/fonts/Vera.ttf";
                $pg->latin_notation = ($decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()] != ".");
-               $filename = $path_to_root . "reporting/pdf_files/test.png";
+               $filename =  $comp_path.'/'.user_company()."/pdf_files/test.png";
                $pg->display($filename, true);
                $w = $pg->width / 1.5;
                $h = $pg->height / 1.5;
index 7059d837b397ce1bf7dda7696ebc2bcb318c01f5..1228e10bdbc2c28fe10b79443d666aadf808a9dc 100644 (file)
@@ -37,7 +37,7 @@ function Achieve($d1, $d2)
 
 function print_profit_and_loss_statement()
 {
-       global $path_to_root;
+       global $comp_path, $path_to_root;
 
        include_once($path_to_root . "reporting/includes/pdf_report.inc");
        $dim = get_company_pref('use_dimension');
@@ -295,7 +295,7 @@ function print_profit_and_loss_statement()
                $pg->built_in  = false;
                $pg->fontfile  = $path_to_root . "reporting/fonts/Vera.ttf";
                $pg->latin_notation = ($decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()] != ".");
-               $filename = $path_to_root . "reporting/pdf_files/test.png";
+               $filename = $comp_path.'/'.user_company(). ."/pdf_files/test.png";
                $pg->display($filename, true);
                $w = $pg->width / 1.5;
                $h = $pg->height / 1.5;