예제 #1
0
 function set_language($code)
 {
     global $path_to_root, $installed_languages, $GetText;
     $lang = array_search_value($code, $installed_languages, 'code');
     $changed = $this->code != $code || $this->version != @$lang['version'];
     if ($lang && $changed) {
         // flush cache as we can use several languages in one account
         flush_dir(company_path() . '/js_cache');
         $this->name = $lang['name'];
         $this->code = $lang['code'];
         $this->encoding = $lang['encoding'];
         $this->version = @$lang['version'];
         $this->dir = isset($lang['rtl']) && $lang['rtl'] === true ? 'rtl' : 'ltr';
         $locale = $path_to_root . "/lang/" . $this->code . "/locale.inc";
         $this->is_locale_file = file_exists($locale);
     }
     $GetText->set_language($this->code, $this->encoding);
     $GetText->add_domain($this->code, $path_to_root . "/lang", $this->version);
     // Necessary for ajax calls. Due to bug in php 4.3.10 for this
     // version set globally in php.ini
     ini_set('default_charset', $this->encoding);
     if (isset($_SESSION['App']) && $changed) {
         $_SESSION['App']->init();
     }
     // refresh menu
 }
예제 #2
0
function get_reports()
{
    global $path_to_root, $go_debug;
    if ($go_debug || !isset($_SESSION['reports'])) {
        // to save time, store in session.
        $paths = array($path_to_root . '/reporting/', company_path() . '/reporting/');
        $reports = array('' => _('Default printing destination'));
        foreach ($paths as $dirno => $path) {
            $repdir = opendir($path);
            while (false !== ($fname = readdir($repdir))) {
                // reports have filenames in form rep(repid).php
                // where repid must contain at least one digit (reports_main.php is not ;)
                if (is_file($path . $fname) && preg_match('/rep(.*[0-9]+.*)[.]php/', $fname, $match)) {
                    $repno = $match[1];
                    $title = '';
                    $line = file_get_contents($path . $fname);
                    if (preg_match('/.*(FrontReport\\()\\s*_\\([\'"]([^\'"]*)/', $line, $match)) {
                        $title = trim($match[2]);
                    } else {
                        // for any 3rd party printouts without FrontReport() class use
                        if (preg_match('/.*(\\$Title).*[\'"](.*)[\'"].+/', $line, $match)) {
                            $title = trim($match[2]);
                        }
                    }
                    $reports[$repno] = $title;
                }
            }
            closedir();
        }
        ksort($reports);
        $_SESSION['reports'] = $reports;
    }
    return $_SESSION['reports'];
}
 function render($id, $title)
 {
     global $path_to_root;
     include_once $path_to_root . "/includes/ui.inc";
     include_once $path_to_root . "/reporting/includes/class.graphic.inc";
     if (!defined('FLOAT_COMP_DELTA')) {
         define('FLOAT_COMP_DELTA', 0.004);
     }
     if (!isset($this->top)) {
         $this->top = 10;
     }
     $begin = begin_fiscalyear();
     $today = Today();
     $begin1 = date2sql($begin);
     $today1 = date2sql($today);
     $sql = "SELECT SUM((trans.ov_amount + trans.ov_discount) * rate) AS total, s.supplier_id, s.supp_name FROM\n            " . TB_PREF . "supp_trans AS trans, " . TB_PREF . "suppliers AS s WHERE trans.supplier_id=s.supplier_id\n            AND (trans.type = " . ST_SUPPINVOICE . " OR trans.type = " . ST_SUPPCREDIT . ")\n            AND tran_date >= '{$begin1}' AND tran_date <= '{$today1}' ";
     if ($this->data_filter != '') {
         $sql .= ' AND ' . $this->data_filter;
     }
     $sql .= "GROUP by s.supplier_id ORDER BY total DESC, s.supplier_id " . " LIMIT " . $this->top;
     $result = db_query($sql);
     if ($this->graph_type == 'Table') {
         $th = array(_("Supplier"), _("Amount"));
         start_table(TABLESTYLE, "width=98%");
         table_header($th);
         $k = 0;
         //row colour counter
         while ($myrow = db_fetch($result)) {
             alt_table_row_color($k);
             $name = $myrow["supplier_id"] . " " . $myrow["supp_name"];
             label_cell($name);
             amount_cell($myrow['total']);
             end_row();
         }
         end_table(1);
     } else {
         $pg = new graph();
         $i = 0;
         while ($myrow = db_fetch($result)) {
             $name = $myrow["supplier_id"] . " " . $myrow["supp_name"];
             $pg->x[$i] = $name;
             $pg->y[$i] = $myrow['total'];
             $i++;
         }
         $pg->title = $title;
         $pg->axis_x = _("Supplier");
         $pg->axis_y = _("Amount");
         $pg->graphic_1 = $today;
         $pg->type = 2;
         $pg->skin = 1;
         $pg->built_in = false;
         $filename = company_path() . "/pdf_files/" . uniqid("") . ".png";
         $pg->display($filename, true);
         echo "<img src='{$filename}' border='0' alt='{$title}' style='max-width:100%'>";
     }
 }
예제 #4
0
 function render($id, $title)
 {
     global $path_to_root;
     include_once $path_to_root . "/reporting/includes/class.graphic.inc";
     if (!defined('FLOAT_COMP_DELTA')) {
         define('FLOAT_COMP_DELTA', 0.004);
     }
     if (!isset($this->top)) {
         $this->top = 10;
     }
     $begin = begin_fiscalyear();
     $today = Today();
     $begin1 = date2sql($begin);
     $today1 = date2sql($today);
     $sql = "SELECT SUM((ov_amount + ov_discount) * rate * IF(trans.type = " . ST_CUSTCREDIT . ", -1, 1)) AS total,d.debtor_no, d.name" . " FROM " . TB_PREF . "debtor_trans AS trans, " . TB_PREF . "debtors_master AS d" . " WHERE trans.debtor_no=d.debtor_no" . " AND (trans.type = " . ST_SALESINVOICE . " OR trans.type = " . ST_CUSTCREDIT . ")" . " AND tran_date >= '{$begin1}' AND tran_date <= '{$today1}'";
     if ($this->data_filter != '') {
         $sql .= ' AND ' . $this->data_filter;
     }
     $sql .= " GROUP by d.debtor_no ORDER BY total DESC, d.debtor_no " . " LIMIT " . $this->top;
     $result = db_query($sql);
     if ($this->graph_type == 'Table') {
         $th = array(null, _("Customer"), _("Amount"));
         start_table(TABLESTYLE, "width=98%");
         table_header($th);
         $k = 0;
         //row colour counter
         $i = 0;
         while ($myrow = db_fetch($result)) {
             alt_table_row_color($k);
             label_cell(viewer_link($myrow["debtor_no"], 'sales/inquiry/customer_inquiry.php?customer_id=' . $myrow["debtor_no"]));
             label_cell(viewer_link($myrow["name"], 'sales/inquiry/customer_inquiry.php?customer_id=' . $myrow["debtor_no"]));
             amount_cell($myrow['total']);
             end_row();
         }
         end_table(1);
     } else {
         $pg = new graph();
         $i = 0;
         while ($myrow = db_fetch($result)) {
             $pg->x[$i] = $myrow["debtor_no"] . " " . $myrow["name"];
             $pg->y[$i] = $myrow['total'];
             $i++;
         }
         $pg->title = $title;
         $pg->axis_x = _("Customer");
         $pg->axis_y = _("Amount");
         $pg->graphic_1 = $today;
         $pg->type = 2;
         $pg->skin = 1;
         $pg->built_in = false;
         $filename = company_path() . "/pdf_files/" . uniqid("") . ".png";
         $pg->display($filename, true);
         echo "<img src='{$filename}' border='0' alt='{$title}' style='max-width:100%'>";
     }
 }
예제 #5
0
파일: glreturn.php 프로젝트: raqib/ac_dev
 function render($id, $title)
 {
     global $path_to_root;
     include_once $path_to_root . "/reporting/includes/class.graphic.inc";
     $begin = begin_fiscalyear();
     $today = Today();
     $begin1 = date2sql($begin);
     $today1 = date2sql($today);
     $sql = "SELECT SUM(amount) AS total, c.class_name, c.ctype FROM\n            " . TB_PREF . "gl_trans," . TB_PREF . "chart_master AS a, " . TB_PREF . "chart_types AS t,\n            " . TB_PREF . "chart_class AS c WHERE\n            account = a.account_code AND a.account_type = t.id AND t.class_id = c.cid\n            AND IF(c.ctype > 3, tran_date >= '{$begin1}', tran_date >= '0000-00-00')\n            AND tran_date <= '{$today1}' ";
     if ($this->data_filter != '') {
         $sql .= ' AND ' . $this->data_filter;
     }
     $sql .= " GROUP BY c.cid ORDER BY c.cid";
     $result = db_query($sql, "Transactions could not be calculated");
     $calculated = _("Calculated Return");
     if ($this->graph_type == 'Table') {
         start_table(TABLESTYLE2, "width=98%");
         $total = 0;
         while ($myrow = db_fetch($result)) {
             if ($myrow['ctype'] > 3) {
                 $total += $myrow['total'];
                 $myrow['total'] = -$myrow['total'];
             }
             label_row($myrow['class_name'], number_format2($myrow['total'], user_price_dec()), "class='label' style='font-weight:bold;'", "style='font-weight:bold;' align=right");
         }
         label_row("&nbsp;", "");
         label_row($calculated, number_format2(-$total, user_price_dec()), "class='label' style='font-weight:bold;'", "style='font-weight:bold;' align=right");
         end_table(1);
     } else {
         $pg = new graph();
         $i = 0;
         $total = 0;
         while ($myrow = db_fetch($result)) {
             if ($myrow['ctype'] > 3) {
                 $total += $myrow['total'];
                 $myrow['total'] = -$myrow['total'];
                 $pg->x[$i] = $myrow['class_name'];
                 $pg->y[$i] = abs($myrow['total']);
                 $i++;
             }
         }
         $pg->x[$i] = $calculated;
         $pg->y[$i] = -$total;
         $pg->title = $title;
         $pg->axis_x = _("Class");
         $pg->axis_y = _("Amount");
         $pg->graphic_1 = $today;
         $pg->type = 5;
         $pg->skin = 1;
         $pg->built_in = false;
         $filename = company_path() . "/pdf_files/" . uniqid("") . ".png";
         $pg->display($filename, true);
         echo "<img src='{$filename}' border='0' alt='{$title}' style='max-width:100%'>";
     }
 }
예제 #6
0
파일: dimensions.php 프로젝트: raqib/ac_dev
 function render($id, $title)
 {
     global $path_to_root;
     if (!isset($this->top)) {
         $this->top = 10;
     }
     global $path_to_root;
     $pg = new graph();
     $begin = begin_fiscalyear();
     $today = Today();
     $begin1 = date2sql($begin);
     $today1 = date2sql($today);
     $sql = "SELECT SUM(-t.amount) AS total, d.reference, d.name FROM\n            " . TB_PREF . "gl_trans AS t," . TB_PREF . "dimensions AS d WHERE\n            (t.dimension_id = d.id OR t.dimension2_id = d.id) AND\n            t.tran_date >= '{$begin1}' AND t.tran_date <= '{$today1}' ";
     if ($this->data_filter != '') {
         $sql .= ' AND ' . $this->data_filter;
     }
     $sql .= "GROUP BY d.id ORDER BY total DESC LIMIT " . $this->top;
     $result = db_query($sql, "Transactions could not be calculated");
     if ($this->graph_type == 'Table') {
         $title = _("Top 10 Dimensions in fiscal year");
         br(2);
         display_heading($title);
         br();
         $th = array(_("Dimension"), _("Amount"));
         start_table(TABLESTYLE, "width=98%");
         table_header($th);
         $k = 0;
         //row colour counter
         while ($myrow = db_fetch($result)) {
             alt_table_row_color($k);
             label_cell($myrow['reference'] . " " . $myrow["name"]);
             amount_cell($myrow['total']);
             end_row();
         }
         end_table(2);
     } else {
         $pg = new graph();
         $i = 0;
         while ($myrow = db_fetch($result)) {
             $pg->x[$i] = $myrow['reference'] . " " . $myrow["name"];
             $pg->y[$i] = abs($myrow['total']);
             $i++;
         }
         $pg->title = $title;
         $pg->axis_x = _("Dimension");
         $pg->axis_y = _("Amount");
         $pg->graphic_1 = $today;
         $pg->type = 5;
         $pg->skin = 1;
         $pg->built_in = false;
         $filename = company_path() . "/pdf_files/" . uniqid("") . ".png";
         $pg->display($filename, true);
         echo "<img src='{$filename}' border='0' alt='{$title}' style='max-width:100%'>";
     }
 }
예제 #7
0
function handle_delete()
{
    global $def_coy, $db_connections, $comp_subdirs, $path_to_root;
    $id = (int) $_GET['id'];
    // First make sure all company directories from the one under removal are writable.
    // Without this after operation we end up with changed per-company owners!
    for ($i = $id; $i < count($db_connections); $i++) {
        $comp_path = company_path($i);
        if (!is_dir($comp_path) || !is_writable($comp_path)) {
            display_error(_('Broken company subdirectories system. You have to remove this company manually.'));
            return;
        }
    }
    // make sure config file is writable
    if (!is_writeable($path_to_root . "/config_db.php")) {
        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."));
        return;
    }
    // rename directory to temporary name to ensure all
    // other subdirectories will have right owners even after
    // unsuccessfull removal.
    $cdir = company_path($id);
    $tmpname = company_path('/old_' . $id);
    if (!@rename($cdir, $tmpname)) {
        display_error(_('Cannot rename subdirectory to temporary name.'));
        return;
    }
    // 'shift' company directories names
    for ($i = $id + 1; $i < count($db_connections); $i++) {
        if (!rename(company_path($i), company_path($i - 1))) {
            display_error(_("Cannot rename company subdirectory"));
            return;
        }
    }
    $err = remove_connection($id);
    if ($err == 0) {
        display_error(_("Error removing Database: ") . $dbase . _(", please remove it manually"));
    }
    if ($def_coy == $id) {
        $def_coy = 0;
    }
    $error = write_config_db();
    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) {
        @rename($tmpname, $cdir);
        return;
    }
    // finally remove renamed company directory
    @flush_dir($tmpname, true);
    if (!@rmdir($tmpname)) {
        display_error(_("Cannot remove temporary renamed company data directory ") . $tmpname);
        return;
    }
    display_notification(_("Selected company has been deleted"));
}
예제 #8
0
    if (!is_numeric($_POST['query_size']) || $_POST['query_size'] < 1) {
        display_error($_POST['query_size']);
        display_error(_("Query size must be integer and greater than zero."));
        set_focus('query_size');
    } else {
        $_POST['theme'] = clean_file_name($_POST['theme']);
        $chg_theme = user_theme() != $_POST['theme'];
        $chg_lang = $_SESSION['language']->code != $_POST['language'];
        $chg_date_format = user_date_format() != $_POST['date_format'];
        $chg_date_sep = user_date_sep() != $_POST['date_sep'];
        set_user_prefs(get_post(array('prices_dec', 'qty_dec', 'rates_dec', 'percent_dec', 'date_format', 'date_sep', 'tho_sep', 'dec_sep', 'print_profile', 'theme', 'page_size', 'language', 'startup_tab', 'show_gl' => 0, 'show_codes' => 0, 'show_hints' => 0, 'rep_popup' => 0, 'graphic_links' => 0, 'sticky_doc_date' => 0, 'query_size' => 10.0)));
        if ($chg_lang) {
            $_SESSION['language']->set_language($_POST['language']);
        }
        // refresh main menu
        flush_dir(company_path() . '/js_cache');
        if ($chg_theme && $allow_demo_mode) {
            $_SESSION["wa_current_user"]->prefs->theme = $_POST['theme'];
        }
        if ($chg_theme || $chg_lang || $chg_date_format || $chg_date_sep) {
            meta_forward($_SERVER['PHP_SELF']);
        }
        if ($allow_demo_mode) {
            display_warning(_("Display settings have been updated. Keep in mind that changed settings are restored on every login in demo mode."));
        } else {
            display_notification_centered(_("Display settings have been updated."));
        }
    }
}
start_form();
start_outer_table(TABLESTYLE2);
예제 #9
0
        move_uploaded_file($tmpname, $dir . "/" . $unique_name);
        if ($Mode == 'ADD_ITEM') {
            add_attachment($_POST['filterType'], $_POST['trans_no'], $_POST['description'], $filename, $unique_name, $filesize, $filetype);
            display_notification(_("Attachment has been inserted."));
        } else {
            update_attachment($selected_id, $_POST['filterType'], $_POST['trans_no'], $_POST['description'], $filename, $unique_name, $filesize, $filetype);
            display_notification(_("Attachment has been updated."));
        }
    }
    refresh_pager('trans_tbl');
    $Ajax->activate('_page_body');
    $Mode = 'RESET';
}
if ($Mode == 'Delete') {
    $row = get_attachment($selected_id);
    $dir = company_path() . "/attachments";
    if (file_exists($dir . "/" . $row['unique_name'])) {
        unlink($dir . "/" . $row['unique_name']);
    }
    delete_attachment($selected_id);
    display_notification(_("Attachment has been deleted."));
    $Mode = 'RESET';
}
if ($Mode == 'RESET') {
    unset($_POST['trans_no']);
    unset($_POST['description']);
    $selected_id = -1;
}
function viewing_controls()
{
    global $selected_id;
 function display_applications(&$waapp)
 {
     global $path_to_root, $use_popup_windows;
     include_once "{$path_to_root}/includes/ui.inc";
     include_once $path_to_root . "/reporting/includes/class.graphic.inc";
     $selected_app = $waapp->get_selected_application();
     if (!$_SESSION["wa_current_user"]->check_application_access($selected_app)) {
         return;
     }
     if (method_exists($selected_app, 'render_index')) {
         $selected_app->render_index();
         return;
     }
     // first have a look through the directory,
     // and remove old temporary pdfs and pngs
     $dir = company_path() . '/pdf_files';
     if ($d = @opendir($dir)) {
         while (($file = readdir($d)) !== false) {
             if (!is_file($dir . '/' . $file) || $file == 'index.php') {
                 continue;
             }
             // then check to see if this one is too old
             $ftime = filemtime($dir . '/' . $file);
             // seems 3 min is enough for any report download, isn't it?
             if (time() - $ftime > 180) {
                 unlink($dir . '/' . $file);
             }
         }
         closedir($d);
     }
     //if ($selected_app->id == 'system') {
     //    include($path_to_root . "/includes/system_tests.inc");
     //    $title = "Display System Diagnostics";
     //    br(2);
     //    display_heading($title);
     //    br();
     //    display_system_tests();
     //    return;
     //}
     $dashboard_app = $waapp->get_application("Dashboard");
     echo '<div id="console" ></div>';
     $userid = $_SESSION["wa_current_user"]->user;
     $sql = "SELECT DISTINCT column_id FROM " . TB_PREF . "dashboard_widgets" . " WHERE user_id =" . db_escape($userid) . " AND app=" . db_escape($selected_app->id) . " ORDER BY column_id";
     $columns = db_query($sql);
     while ($column = db_fetch($columns)) {
         echo '<div class="column" id="column' . $column['column_id'] . '" >';
         $sql = "SELECT * FROM " . TB_PREF . "dashboard_widgets" . " WHERE column_id=" . db_escape($column['column_id']) . " AND user_id = " . db_escape($userid) . " AND app=" . db_escape($selected_app->id) . " ORDER BY sort_no";
         $items = db_query($sql);
         while ($item = db_fetch($items)) {
             $widgetData = $dashboard_app->get_widget($item['widget']);
             echo '
                   <div class="dragbox" id="item' . $item['id'] . '">
                       <h2>' . $item['description'] . '</h2>
                           <div id="widget_div_' . $item['id'] . '" class="dragbox-content" ';
             if ($item['collapsed'] == 1) {
                 echo 'style="display:none;" ';
             }
             echo '>';
             if ($widgetData != null) {
                 if ($_SESSION["wa_current_user"]->can_access_page($widgetData->access)) {
                     include_once $path_to_root . $widgetData->path;
                     $className = $widgetData->name;
                     $widgetObject = new $className($item['param']);
                     $widgetObject->render($item['id'], $item['description']);
                 } else {
                     echo "<center><br><br><br><b>";
                     echo _("The security settings on your account do not permit you to access this function");
                     echo "</b>";
                     echo "<br><br><br><br></center>";
                 }
             }
             echo '</div></div>';
         }
         echo '</div>';
     }
 }
예제 #11
0
 function display_applications(&$waapp)
 {
     global $path_to_root, $use_popup_windows;
     include_once "{$path_to_root}/includes/ui.inc";
     include_once $path_to_root . "/reporting/includes/class.graphic.inc";
     include $path_to_root . "/includes/system_tests.inc";
     if ($use_popup_windows) {
         echo "<script language='javascript'>\n";
         echo get_js_open_window(900, 500);
         echo "</script>\n";
     }
     $selected_app = $waapp->get_selected_application();
     // first have a look through the directory,
     // and remove old temporary pdfs and pngs
     $dir = company_path() . '/pdf_files';
     if ($d = @opendir($dir)) {
         while (($file = readdir($d)) !== false) {
             if (!is_file($dir . '/' . $file) || $file == 'index.php') {
                 continue;
             }
             // then check to see if this one is too old
             $ftime = filemtime($dir . '/' . $file);
             // seems 3 min is enough for any report download, isn't it?
             if (time() - $ftime > 180) {
                 unlink($dir . '/' . $file);
             }
         }
         closedir($d);
     }
     if ($selected_app->id == "orders") {
         display_customer_topten();
     } elseif ($selected_app->id == "AP") {
         display_supplier_topten();
     } elseif ($selected_app->id == "stock") {
         display_stock_topten();
     } elseif ($selected_app->id == "manuf") {
         display_stock_topten(true);
     } elseif ($selected_app->id == "proj") {
         display_dimension_topten();
     } elseif ($selected_app->id == "GL") {
         display_gl_info();
     } else {
         $title = "Display System Diagnostics";
         br(2);
         display_heading($title);
         br();
         display_system_tests();
     }
 }
예제 #12
0
function print_aged_supplier_analysis()
{
    global $path_to_root, $systypes_array;
    $to = $_POST['PARAM_0'];
    $fromsupp = $_POST['PARAM_1'];
    $currency = $_POST['PARAM_2'];
    $show_all = $_POST['PARAM_3'];
    $summaryOnly = $_POST['PARAM_4'];
    $no_zeros = $_POST['PARAM_5'];
    $graphics = $_POST['PARAM_6'];
    $comments = $_POST['PARAM_7'];
    $orientation = $_POST['PARAM_8'];
    $destination = $_POST['PARAM_9'];
    if ($destination) {
        include_once $path_to_root . "/reporting/includes/excel_report.inc";
    } else {
        include_once $path_to_root . "/reporting/includes/pdf_report.inc";
    }
    $orientation = $orientation ? 'L' : 'P';
    if ($graphics) {
        include_once $path_to_root . "/reporting/includes/class.graphic.inc";
        $pg = new graph();
    }
    if ($fromsupp == ALL_TEXT) {
        $from = _('All');
    } else {
        $from = get_supplier_name($fromsupp);
    }
    $dec = user_price_dec();
    if ($summaryOnly == 1) {
        $summary = _('Summary Only');
    } else {
        $summary = _('Detailed Report');
    }
    if ($currency == ALL_TEXT) {
        $convert = true;
        $currency = _('Balances in Home Currency');
    } else {
        $convert = false;
    }
    if ($no_zeros) {
        $nozeros = _('Yes');
    } else {
        $nozeros = _('No');
    }
    if ($show_all) {
        $show = _('Yes');
    } else {
        $show = _('No');
    }
    $PastDueDays1 = get_company_pref('past_due_days');
    $PastDueDays2 = 2 * $PastDueDays1;
    $nowdue = "1-" . $PastDueDays1 . " " . _('Days');
    $pastdue1 = $PastDueDays1 + 1 . "-" . $PastDueDays2 . " " . _('Days');
    $pastdue2 = _('Over') . " " . $PastDueDays2 . " " . _('Days');
    $cols = array(0, 100, 130, 190, 250, 320, 385, 450, 515);
    $headers = array(_('Supplier'), '', '', _('Current'), $nowdue, $pastdue1, $pastdue2, _('Total Balance'));
    $aligns = array('left', 'left', 'left', 'right', 'right', 'right', 'right', 'right');
    $params = array(0 => $comments, 1 => array('text' => _('End Date'), 'from' => $to, 'to' => ''), 2 => array('text' => _('Supplier'), 'from' => $from, 'to' => ''), 3 => array('text' => _('Currency'), 'from' => $currency, 'to' => ''), 4 => array('text' => _('Type'), 'from' => $summary, 'to' => ''), 5 => array('text' => _('Show Also Allocated'), 'from' => $show, 'to' => ''), 6 => array('text' => _('Suppress Zeros'), 'from' => $nozeros, 'to' => ''));
    if ($convert) {
        $headers[2] = _('currency');
    }
    $rep = new FrontReport(_('Aged Supplier Analysis'), "AgedSupplierAnalysis", user_pagesize(), 9, $orientation);
    if ($orientation == 'L') {
        recalculate_cols($cols);
    }
    $rep->Font();
    $rep->Info($params, $cols, $headers, $aligns);
    $rep->NewPage();
    $total = array();
    $total[0] = $total[1] = $total[2] = $total[3] = $total[4] = 0.0;
    $PastDueDays1 = get_company_pref('past_due_days');
    $PastDueDays2 = 2 * $PastDueDays1;
    $nowdue = "1-" . $PastDueDays1 . " " . _('Days');
    $pastdue1 = $PastDueDays1 + 1 . "-" . $PastDueDays2 . " " . _('Days');
    $pastdue2 = _('Over') . " " . $PastDueDays2 . " " . _('Days');
    $sql = "SELECT supplier_id, supp_name AS name, curr_code FROM " . TB_PREF . "suppliers";
    if ($fromsupp != ALL_TEXT) {
        $sql .= " WHERE supplier_id=" . db_escape($fromsupp);
    }
    $sql .= " ORDER BY supp_name";
    $result = db_query($sql, "The suppliers could not be retrieved");
    while ($myrow = db_fetch($result)) {
        if (!$convert && $currency != $myrow['curr_code']) {
            continue;
        }
        if ($convert) {
            $rate = get_exchange_rate_from_home_currency($myrow['curr_code'], $to);
        } else {
            $rate = 1.0;
        }
        $supprec = get_supplier_details($myrow['supplier_id'], $to, $show_all);
        if (!$supprec) {
            continue;
        }
        $supprec['Balance'] *= $rate;
        $supprec['Due'] *= $rate;
        $supprec['Overdue1'] *= $rate;
        $supprec['Overdue2'] *= $rate;
        $str = array($supprec["Balance"] - $supprec["Due"], $supprec["Due"] - $supprec["Overdue1"], $supprec["Overdue1"] - $supprec["Overdue2"], $supprec["Overdue2"], $supprec["Balance"]);
        if ($no_zeros && floatcmp(array_sum($str), 0) == 0) {
            continue;
        }
        $rep->fontSize += 2;
        $rep->TextCol(0, 2, $myrow['name']);
        if ($convert) {
            $rep->TextCol(2, 3, $myrow['curr_code']);
        }
        $rep->fontSize -= 2;
        $total[0] += $supprec["Balance"] - $supprec["Due"];
        $total[1] += $supprec["Due"] - $supprec["Overdue1"];
        $total[2] += $supprec["Overdue1"] - $supprec["Overdue2"];
        $total[3] += $supprec["Overdue2"];
        $total[4] += $supprec["Balance"];
        for ($i = 0; $i < count($str); $i++) {
            $rep->AmountCol($i + 3, $i + 4, $str[$i], $dec);
        }
        $rep->NewLine(1, 2);
        if (!$summaryOnly) {
            $res = get_invoices($myrow['supplier_id'], $to, $show_all);
            if (db_num_rows($res) == 0) {
                continue;
            }
            $rep->Line($rep->row + 4);
            while ($trans = db_fetch($res)) {
                $rep->NewLine(1, 2);
                $rep->TextCol(0, 1, $systypes_array[$trans['type']], -2);
                $rep->TextCol(1, 2, $trans['reference'], -2);
                $rep->TextCol(2, 3, sql2date($trans['tran_date']), -2);
                foreach ($trans as $i => $value) {
                    $trans[$i] *= $rate;
                }
                $str = array($trans["Balance"] - $trans["Due"], $trans["Due"] - $trans["Overdue1"], $trans["Overdue1"] - $trans["Overdue2"], $trans["Overdue2"], $trans["Balance"]);
                for ($i = 0; $i < count($str); $i++) {
                    $rep->AmountCol($i + 3, $i + 4, $str[$i], $dec);
                }
            }
            $rep->Line($rep->row - 8);
            $rep->NewLine(2);
        }
    }
    if ($summaryOnly) {
        $rep->Line($rep->row + 4);
        $rep->NewLine();
    }
    $rep->fontSize += 2;
    $rep->TextCol(0, 3, _('Grand Total'));
    $rep->fontSize -= 2;
    for ($i = 0; $i < count($total); $i++) {
        $rep->AmountCol($i + 3, $i + 4, $total[$i], $dec);
        if ($graphics && $i < count($total) - 1) {
            $pg->y[$i] = abs($total[$i]);
        }
    }
    $rep->Line($rep->row - 8);
    $rep->NewLine();
    if ($graphics) {
        global $decseps, $graph_skin;
        $pg->x = array(_('Current'), $nowdue, $pastdue1, $pastdue2);
        $pg->title = $rep->title;
        $pg->axis_x = _("Days");
        $pg->axis_y = _("Amount");
        $pg->graphic_1 = $to;
        $pg->type = $graphics;
        $pg->skin = $graph_skin;
        $pg->built_in = false;
        $pg->latin_notation = $decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()] != ".";
        $filename = company_path() . "/pdf_files/" . uniqid("") . ".png";
        $pg->display($filename, true);
        $w = $pg->width / 1.5;
        $h = $pg->height / 1.5;
        $x = ($rep->pageWidth - $w) / 2;
        $rep->NewLine(2);
        if ($rep->row - $h < $rep->bottomMargin) {
            $rep->NewPage();
        }
        $rep->AddImage($filename, $x, $rep->row - $h, $w, $h);
    }
    $rep->End();
}
 function render($id, $title)
 {
     global $path_to_root;
     if (!isset($this->top)) {
         $this->top = 10;
     }
     $begin = begin_fiscalyear();
     $today = Today();
     $begin1 = date2sql($begin);
     $today1 = date2sql($today);
     $sql = "SELECT SUM((trans.unit_price * trans.quantity) * d.rate) AS total, s.stock_id, s.description,\n            SUM(trans.quantity) AS qty FROM\n            " . TB_PREF . "debtor_trans_details AS trans, " . TB_PREF . "stock_master AS s, " . TB_PREF . "debtor_trans AS d\n            WHERE trans.stock_id=s.stock_id AND trans.debtor_trans_type=d.type AND trans.debtor_trans_no=d.trans_no\n            AND (d.type = " . ST_SALESINVOICE . " OR d.type = " . ST_CUSTCREDIT . ") ";
     if ($this->item_type == 'manuf') {
         $sql .= "AND s.mb_flag='M' ";
     }
     if ($this->data_filter != '') {
         $sql .= ' AND ' . $this->data_filter;
     }
     $sql .= "AND d.tran_date >= '{$begin1}' AND d.tran_date <= '{$today1}' GROUP by s.stock_id ORDER BY total DESC, s.stock_id " . " LIMIT " . $this->top;
     $result = db_query($sql);
     if ($this->graph_type == 'Table') {
         if ($this->item_type == 'manuf') {
             $title = _("Top 10 Manufactured Items in fiscal year");
         } else {
             $title = _("Top 10 Sold Items in fiscal year");
         }
         display_heading($title);
         br();
         $th = array(_("Item"), _("Amount"), _("Quantity"));
         start_table(TABLESTYLE, "width=98%");
         table_header($th);
         $k = 0;
         //row colour counter
         while ($myrow = db_fetch($result)) {
             alt_table_row_color($k);
             $name = $myrow["description"];
             label_cell($name);
             amount_cell($myrow['total']);
             qty_cell($myrow['qty']);
             end_row();
         }
         end_table(1);
     } else {
         $pg = new graph();
         $i = 0;
         while ($myrow = db_fetch($result)) {
             $pg->x[$i] = $myrow["description"];
             $pg->y[$i] = $myrow['total'];
             $i++;
         }
         $pg->title = $title;
         $pg->axis_x = _("Item");
         $pg->axis_y = _("Amount");
         $pg->graphic_1 = $today;
         $pg->type = 2;
         $pg->skin = 1;
         $pg->built_in = false;
         $filename = company_path() . "/pdf_files/" . uniqid("") . ".png";
         $pg->display($filename, true);
         echo "<img src='{$filename}' border='0' alt='{$title}' style='max-width:100%'>";
     }
 }
예제 #14
0
function print_price_listing()
{
    global $path_to_root, $pic_height, $pic_width;
    $currency = $_POST['PARAM_0'];
    $category = $_POST['PARAM_1'];
    $salestype = $_POST['PARAM_2'];
    $pictures = $_POST['PARAM_3'];
    $showGP = $_POST['PARAM_4'];
    $comments = $_POST['PARAM_5'];
    $orientation = $_POST['PARAM_6'];
    $destination = $_POST['PARAM_7'];
    if ($destination) {
        include_once $path_to_root . "/reporting/includes/excel_report.inc";
    } else {
        include_once $path_to_root . "/reporting/includes/pdf_report.inc";
    }
    $orientation = $orientation ? 'L' : 'P';
    $dec = user_price_dec();
    $home_curr = get_company_pref('curr_default');
    if ($currency == ALL_TEXT) {
        $currency = $home_curr;
    }
    $curr = get_currency($currency);
    $curr_sel = $currency . " - " . $curr['currency'];
    if ($category == ALL_NUMERIC) {
        $category = 0;
    }
    if ($salestype == ALL_NUMERIC) {
        $salestype = 0;
    }
    if ($category == 0) {
        $cat = _('All');
    } else {
        $cat = get_category_name($category);
    }
    if ($salestype == 0) {
        $stype = _('All');
    } else {
        $stype = get_sales_type_name($salestype);
    }
    if ($showGP == 0) {
        $GP = _('No');
    } else {
        $GP = _('Yes');
    }
    $cols = array(0, 100, 360, 385, 450, 515);
    $headers = array(_('Category/Items'), _('Description'), _('UOM'), _('Price'), _('GP %'));
    $aligns = array('left', 'left', 'left', 'right', 'right');
    $params = array(0 => $comments, 1 => array('text' => _('Currency'), 'from' => $curr_sel, 'to' => ''), 2 => array('text' => _('Category'), 'from' => $cat, 'to' => ''), 3 => array('text' => _('Sales Type'), 'from' => $stype, 'to' => ''), 4 => array('text' => _('Show GP %'), 'from' => $GP, 'to' => ''));
    if ($pictures) {
        $user_comp = user_company();
    } else {
        $user_comp = "";
    }
    $rep = new FrontReport(_('Price Listing'), "PriceListing", user_pagesize(), 9, $orientation);
    if ($orientation == 'L') {
        recalculate_cols($cols);
    }
    $rep->Font();
    $rep->Info($params, $cols, $headers, $aligns);
    $rep->NewPage();
    $result = fetch_items($category);
    $catgor = '';
    $_POST['sales_type_id'] = $salestype;
    while ($myrow = db_fetch($result)) {
        if ($catgor != $myrow['description']) {
            $rep->Line($rep->row - $rep->lineHeight);
            $rep->NewLine(2);
            $rep->fontSize += 2;
            $rep->TextCol(0, 3, $myrow['category_id'] . " - " . $myrow['description']);
            $catgor = $myrow['description'];
            $rep->fontSize -= 2;
            $rep->NewLine();
        }
        $rep->NewLine();
        $rep->TextCol(0, 1, $myrow['stock_id']);
        $rep->TextCol(1, 2, $myrow['name']);
        $rep->TextCol(2, 3, $myrow['units']);
        $price = get_price($myrow['stock_id'], $currency, $salestype);
        $rep->AmountCol(3, 4, $price, $dec);
        if ($showGP) {
            $price2 = get_price($myrow['stock_id'], $home_curr, $salestype);
            if ($price2 != 0.0) {
                $disp = ($price2 - $myrow['Standardcost']) * 100 / $price2;
            } else {
                $disp = 0.0;
            }
            $rep->TextCol(4, 5, number_format2($disp, user_percent_dec()) . " %");
        }
        if ($pictures) {
            $image = company_path() . "/images/" . item_img_name($myrow['stock_id']) . ".jpg";
            if (file_exists($image)) {
                $rep->NewLine();
                if ($rep->row - $pic_height < $rep->bottomMargin) {
                    $rep->NewPage();
                }
                $rep->AddImage($image, $rep->cols[1], $rep->row - $pic_height, 0, $pic_height);
                $rep->row -= $pic_height;
                $rep->NewLine();
            }
        } else {
            $rep->NewLine(0, 1);
        }
    }
    $rep->Line($rep->row - 4);
    $result = get_kits($category);
    $catgor = '';
    while ($myrow = db_fetch($result)) {
        if ($catgor != $myrow['cat_name']) {
            if ($catgor == '') {
                $rep->NewLine(2);
                $rep->fontSize += 2;
                $rep->TextCol(0, 3, _("Sales Kits"));
                $rep->fontSize -= 2;
            }
            $rep->Line($rep->row - $rep->lineHeight);
            $rep->NewLine(2);
            $rep->fontSize += 2;
            $rep->TextCol(0, 3, $myrow['cat_id'] . " - " . $myrow['cat_name']);
            $catgor = $myrow['cat_name'];
            $rep->fontSize -= 2;
            $rep->NewLine();
        }
        $rep->NewLine();
        $rep->TextCol(0, 1, $myrow['kit_code']);
        $rep->TextCol(1, 3, $myrow['kit_name']);
        $price = get_kit_price($myrow['kit_code'], $currency, $salestype);
        $rep->AmountCol(3, 4, $price, $dec);
        $rep->NewLine(0, 1);
    }
    $rep->Line($rep->row - 4);
    $rep->NewLine();
    $rep->End();
}
예제 #15
0
function print_sales_quotations()
{
    global $path_to_root, $print_as_quote, $print_invoice_no, $no_zero_lines_amount, $print_item_images_on_quote, $pic_height;
    include_once $path_to_root . "/reporting/includes/pdf_report.inc";
    $from = $_POST['PARAM_0'];
    $to = $_POST['PARAM_1'];
    $currency = $_POST['PARAM_2'];
    $email = $_POST['PARAM_3'];
    $comments = $_POST['PARAM_4'];
    $orientation = $_POST['PARAM_5'];
    if (!$from || !$to) {
        return;
    }
    $orientation = $orientation ? 'L' : 'P';
    $dec = user_price_dec();
    $pictures = isset($print_item_images_on_quote) && $print_item_images_on_quote == 1;
    // If you want a larger image, then increase $pic_height f.i.
    // $pic_height += 25;
    $cols = array(4, 60, 225, 300, 325, 385, 450, 515);
    // $headers in doctext.inc
    $aligns = array('left', 'left', 'right', 'left', 'right', 'right', 'right');
    $params = array('comments' => $comments);
    $cur = get_company_Pref('curr_default');
    if ($email == 0) {
        $rep = new FrontReport(_("SALES QUOTATION"), "SalesQuotationBulk", user_pagesize(), 9, $orientation);
    }
    if ($orientation == 'L') {
        recalculate_cols($cols);
    }
    for ($i = $from; $i <= $to; $i++) {
        $myrow = get_sales_order_header($i, ST_SALESQUOTE);
        $baccount = get_default_bank_account($myrow['curr_code']);
        $params['bankaccount'] = $baccount['id'];
        $branch = get_branch($myrow["branch_code"]);
        if ($email == 1) {
            $rep = new FrontReport("", "", user_pagesize(), 9, $orientation);
            if ($print_invoice_no == 1) {
                $rep->filename = "SalesQuotation" . $i . ".pdf";
            } else {
                $rep->filename = "SalesQuotation" . $myrow['reference'] . ".pdf";
            }
        }
        $rep->SetHeaderType('Header2');
        $rep->currency = $cur;
        $rep->Font();
        $rep->Info($params, $cols, null, $aligns);
        $contacts = get_branch_contacts($branch['branch_code'], 'order', $branch['debtor_no'], true);
        $rep->SetCommonData($myrow, $branch, $myrow, $baccount, ST_SALESQUOTE, $contacts);
        //$rep->headerFunc = 'Header2';
        $rep->NewPage();
        $result = get_sales_order_details($i, ST_SALESQUOTE);
        $SubTotal = 0;
        $items = $prices = array();
        while ($myrow2 = db_fetch($result)) {
            $Net = round2((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"], user_price_dec());
            $prices[] = $Net;
            $items[] = $myrow2['stk_code'];
            $SubTotal += $Net;
            $DisplayPrice = number_format2($myrow2["unit_price"], $dec);
            $DisplayQty = number_format2($myrow2["quantity"], get_qty_dec($myrow2['stk_code']));
            $DisplayNet = number_format2($Net, $dec);
            if ($myrow2["discount_percent"] == 0) {
                $DisplayDiscount = "";
            } else {
                $DisplayDiscount = number_format2($myrow2["discount_percent"] * 100, user_percent_dec()) . "%";
            }
            $rep->TextCol(0, 1, $myrow2['stk_code'], -2);
            $oldrow = $rep->row;
            $rep->TextColLines(1, 2, $myrow2['description'], -2);
            $newrow = $rep->row;
            $rep->row = $oldrow;
            if ($Net != 0.0 || !is_service($myrow2['mb_flag']) || !isset($no_zero_lines_amount) || $no_zero_lines_amount == 0) {
                $rep->TextCol(2, 3, $DisplayQty, -2);
                $rep->TextCol(3, 4, $myrow2['units'], -2);
                $rep->TextCol(4, 5, $DisplayPrice, -2);
                $rep->TextCol(5, 6, $DisplayDiscount, -2);
                $rep->TextCol(6, 7, $DisplayNet, -2);
            }
            $rep->row = $newrow;
            if ($pictures) {
                $image = company_path() . "/images/" . item_img_name($myrow2['stk_code']) . ".jpg";
                if (file_exists($image)) {
                    //$rep->NewLine();
                    if ($rep->row - $pic_height < $rep->bottomMargin) {
                        $rep->NewPage();
                    }
                    $rep->AddImage($image, $rep->cols[1], $rep->row - $pic_height, 0, $pic_height);
                    $rep->row -= $pic_height;
                    $rep->NewLine();
                }
            }
            //$rep->NewLine(1);
            if ($rep->row < $rep->bottomMargin + 15 * $rep->lineHeight) {
                $rep->NewPage();
            }
        }
        if ($myrow['comments'] != "") {
            $rep->NewLine();
            $rep->TextColLines(1, 5, $myrow['comments'], -2);
        }
        $DisplaySubTot = number_format2($SubTotal, $dec);
        $DisplayFreight = number_format2($myrow["freight_cost"], $dec);
        $rep->row = $rep->bottomMargin + 15 * $rep->lineHeight;
        $doctype = ST_SALESQUOTE;
        $rep->TextCol(3, 6, _("Sub-total"), -2);
        $rep->TextCol(6, 7, $DisplaySubTot, -2);
        $rep->NewLine();
        $rep->TextCol(3, 6, _("Shipping"), -2);
        $rep->TextCol(6, 7, $DisplayFreight, -2);
        $rep->NewLine();
        $DisplayTotal = number_format2($myrow["freight_cost"] + $SubTotal, $dec);
        if ($myrow['tax_included'] == 0) {
            $rep->TextCol(3, 6, _("TOTAL ORDER EX VAT"), -2);
            $rep->TextCol(6, 7, $DisplayTotal, -2);
            $rep->NewLine();
        }
        $tax_items = get_tax_for_items($items, $prices, $myrow["freight_cost"], $myrow['tax_group_id'], $myrow['tax_included'], null);
        $first = true;
        foreach ($tax_items as $tax_item) {
            if ($tax_item['Value'] == 0) {
                continue;
            }
            $DisplayTax = number_format2($tax_item['Value'], $dec);
            $tax_type_name = $tax_item['tax_type_name'];
            if ($myrow['tax_included']) {
                if (isset($alternative_tax_include_on_docs) && $alternative_tax_include_on_docs == 1) {
                    if ($first) {
                        $rep->TextCol(3, 6, _("Total Tax Excluded"), -2);
                        $rep->TextCol(6, 7, number_format2($sign * $tax_item['net_amount'], $dec), -2);
                        $rep->NewLine();
                    }
                    $rep->TextCol(3, 6, $tax_type_name, -2);
                    $rep->TextCol(6, 7, $DisplayTax, -2);
                    $first = false;
                } else {
                    $rep->TextCol(3, 7, _("Included") . " " . $tax_type_name . " " . _("Amount") . ": " . $DisplayTax, -2);
                }
            } else {
                $SubTotal += $tax_item['Value'];
                $rep->TextCol(3, 6, $tax_type_name, -2);
                $rep->TextCol(6, 7, $DisplayTax, -2);
            }
            $rep->NewLine();
        }
        $rep->NewLine();
        $DisplayTotal = number_format2($myrow["freight_cost"] + $SubTotal, $dec);
        $rep->Font('bold');
        $rep->TextCol(3, 6, _("TOTAL ORDER VAT INCL."), -2);
        $rep->TextCol(6, 7, $DisplayTotal, -2);
        $words = price_in_words($myrow["freight_cost"] + $SubTotal, ST_SALESQUOTE);
        if ($words != "") {
            $rep->NewLine(1);
            $rep->TextCol(1, 7, $myrow['curr_code'] . ": " . $words, -2);
        }
        $rep->Font();
        if ($email == 1) {
            if ($print_invoice_no == 1) {
                $myrow['reference'] = $i;
            }
            $rep->End($email);
        }
    }
    if ($email == 0) {
        $rep->End();
    }
}
예제 #16
0
}
if (isset($_GET['xls'])) {
    $filename = $_GET['filename'];
    $unique_name = preg_replace('/[^0-9a-z.]/i', '', $_GET['unique']);
    $path = company_path() . '/pdf_files/';
    header("Content-type: application/vnd.ms-excel");
    header("Content-Disposition: attachment; filename={$filename}");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
    header("Pragma: public");
    echo file_get_contents($path . $unique_name);
    exit;
} elseif (isset($_GET['xml'])) {
    $filename = $_GET['filename'];
    $unique_name = preg_replace('/[^0-9a-z.]/i', '', $_GET['unique']);
    $path = company_path() . '/pdf_files/';
    header("content-type: text/xml");
    header("Content-Disposition: attachment; filename={$filename}");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0,pre-check=0");
    header("Pragma: public");
    echo file_get_contents($path . $unique_name);
    exit;
}
if (!isset($_POST['REP_ID'])) {
    // print link clicked
    $def_pars = array(0, 0, '', '', 0, '', '', 0);
    //default values
    $rep = $_POST['REP_ID'] = $_GET['REP_ID'];
    for ($i = 0; $i < 8; $i++) {
        $_POST['PARAM_' . $i] = isset($_GET['PARAM_' . $i]) ? $_GET['PARAM_' . $i] : $def_pars[$i];
예제 #17
0
         $result = unlink($filename);
         if (!$result) {
             display_error(_('The existing image could not be removed'));
             $input_error = 1;
         }
     }
     if ($input_error != 1) {
         $result = move_uploaded_file($_FILES['pic']['tmp_name'], $filename);
         $_POST['coy_logo'] = clean_file_name($_FILES['pic']['name']);
         if (!$result) {
             display_error(_('Error uploading logo file'));
         }
     }
 }
 if (check_value('del_coy_logo')) {
     $filename = company_path() . "/images/" . clean_file_name($_POST['coy_logo']);
     if (file_exists($filename)) {
         $result = unlink($filename);
         if (!$result) {
             display_error(_('The existing image could not be removed'));
             $input_error = 1;
         }
     }
     $_POST['coy_logo'] = "";
 }
 if ($_POST['add_pct'] == "") {
     $_POST['add_pct'] = -1;
 }
 if ($_POST['round_to'] <= 0) {
     $_POST['round_to'] = 1;
 }
예제 #18
0
function print_balance_sheet()
{
    global $path_to_root;
    $dim = get_company_pref('use_dimension');
    $dimension = $dimension2 = 0;
    $from = $_POST['PARAM_0'];
    $to = $_POST['PARAM_1'];
    if ($dim == 2) {
        $dimension = $_POST['PARAM_2'];
        $dimension2 = $_POST['PARAM_3'];
        $tags = isset($_POST['PARAM_4']) ? $_POST['PARAM_4'] : -1;
        $decimals = $_POST['PARAM_5'];
        $graphics = $_POST['PARAM_6'];
        $comments = $_POST['PARAM_7'];
        $orientation = $_POST['PARAM_8'];
        $destination = $_POST['PARAM_9'];
    } else {
        if ($dim == 1) {
            $dimension = $_POST['PARAM_2'];
            $tags = isset($_POST['PARAM_3']) ? $_POST['PARAM_3'] : -1;
            $decimals = $_POST['PARAM_4'];
            $graphics = $_POST['PARAM_5'];
            $comments = $_POST['PARAM_6'];
            $orientation = $_POST['PARAM_7'];
            $destination = $_POST['PARAM_8'];
        } else {
            $tags = isset($_POST['PARAM_2']) ? $_POST['PARAM_2'] : -1;
            $decimals = $_POST['PARAM_3'];
            $graphics = $_POST['PARAM_4'];
            $comments = $_POST['PARAM_5'];
            $orientation = $_POST['PARAM_6'];
            $destination = $_POST['PARAM_7'];
        }
    }
    if ($destination) {
        include_once $path_to_root . "/reporting/includes/excel_report.inc";
    } else {
        include_once $path_to_root . "/reporting/includes/pdf_report.inc";
    }
    $orientation = $orientation ? 'L' : 'P';
    if ($graphics) {
        include_once $path_to_root . "/reporting/includes/class.graphic.inc";
        $pg = new graph();
    }
    if (!$decimals) {
        $dec = 0;
    } else {
        $dec = user_price_dec();
    }
    $cols = array(0, 50, 200, 350, 425, 500);
    //------------0--1---2----3----4----5--
    $headers = array(_('Account'), _('Account Name'), _('Open Balance'), _('Period'), _('Close Balance'));
    $aligns = array('left', 'left', 'right', 'right', 'right');
    if ($dim == 2) {
        $params = array(0 => $comments, 1 => array('text' => _('Period'), 'from' => $from, 'to' => $to), 2 => array('text' => _('Dimension') . " 1", 'from' => get_dimension_string($dimension), 'to' => ''), 3 => array('text' => _('Dimension') . " 2", 'from' => get_dimension_string($dimension2), 'to' => ''), 4 => array('text' => _('Tags'), 'from' => get_tag_names($tags), 'to' => ''));
    } else {
        if ($dim == 1) {
            $params = array(0 => $comments, 1 => array('text' => _('Period'), 'from' => $from, 'to' => $to), 2 => array('text' => _('Dimension'), 'from' => get_dimension_string($dimension), 'to' => ''), 3 => array('text' => _('Tags'), 'from' => get_tag_names($tags), 'to' => ''));
        } else {
            $params = array(0 => $comments, 1 => array('text' => _('Period'), 'from' => $from, 'to' => $to), 2 => array('text' => _('Tags'), 'from' => get_tag_names($tags), 'to' => ''));
        }
    }
    $rep = new FrontReport(_('Balance Sheet'), "BalanceSheet", user_pagesize(), 9, $orientation);
    if ($orientation == 'L') {
        recalculate_cols($cols);
    }
    $rep->Font();
    $rep->Info($params, $cols, $headers, $aligns);
    $rep->NewPage();
    $calc_open = $calc_period = 0.0;
    $equity_open = $equity_period = 0.0;
    $liability_open = $liability_period = 0.0;
    $econvert = $lconvert = 0;
    $classresult = get_account_classes(false, 1);
    while ($class = db_fetch($classresult)) {
        $class_open_total = 0;
        $class_period_total = 0;
        $convert = get_class_type_convert($class["ctype"]);
        //Print Class Name
        $rep->Font('bold');
        $rep->TextCol(0, 5, $class["class_name"]);
        $rep->Font();
        $rep->NewLine();
        //Get Account groups/types under this group/type with no parents
        $typeresult = get_account_types(false, $class['cid'], -1);
        while ($accounttype = db_fetch($typeresult)) {
            $classtotal = display_type($accounttype["id"], $accounttype["name"], $from, $to, $convert, $dec, $rep, $dimension, $dimension2, $tags, $pg, $graphics);
            $class_open_total += $classtotal[0];
            $class_period_total += $classtotal[1];
        }
        //Print Class Summary
        $rep->row += 6;
        $rep->Line($rep->row);
        $rep->NewLine();
        $rep->Font('bold');
        $rep->TextCol(0, 2, _('Total') . " " . $class["class_name"]);
        $rep->AmountCol(2, 3, $class_open_total * $convert, $dec);
        $rep->AmountCol(3, 4, $class_period_total * $convert, $dec);
        $rep->AmountCol(4, 5, ($class_open_total + $class_period_total) * $convert, $dec);
        $rep->Font();
        $rep->NewLine(2);
        $calc_open += $class_open_total;
        $calc_period += $class_period_total;
        if ($class['ctype'] == CL_EQUITY) {
            $equity_open += $class_open_total;
            $equity_period += $class_period_total;
            $econvert = $convert;
        } elseif ($class['ctype'] == CL_LIABILITIES) {
            $liability_open += $class_open_total;
            $liability_period += $class_period_total;
            $lconvert = $convert;
        }
    }
    $rep->Font();
    $rep->TextCol(0, 2, _('Calculated Return'));
    if ($lconvert == 1) {
        $calc_open *= -1;
        $calc_period *= -1;
    }
    $rep->AmountCol(2, 3, $calc_open, $dec);
    // never convert
    $rep->AmountCol(3, 4, $calc_period, $dec);
    $rep->AmountCol(4, 5, $calc_open + $calc_period, $dec);
    $rep->NewLine(2);
    $rep->Font('bold');
    $rep->TextCol(0, 2, _('Total') . " " . _('Liabilities') . _(' and ') . _('Equities'));
    $topen = $equity_open * $econvert + $liability_open * $lconvert + $calc_open;
    $tperiod = $equity_period * $econvert + $liability_period * $lconvert + $calc_period;
    $tclose = $topen + $tperiod;
    $rep->AmountCol(2, 3, $topen, $dec);
    $rep->AmountCol(3, 4, $tperiod, $dec);
    $rep->AmountCol(4, 5, $tclose, $dec);
    $rep->Font();
    $rep->NewLine();
    $rep->Line($rep->row);
    if ($graphics) {
        $pg->x[] = _('Calculated Return');
        $pg->y[] = abs($calc_open);
        $pg->z[] = abs($calc_period);
        global $decseps, $graph_skin;
        $pg->title = $rep->title;
        $pg->axis_x = _("Group");
        $pg->axis_y = _("Amount");
        $pg->graphic_1 = $headers[2];
        $pg->graphic_2 = $headers[3];
        $pg->type = $graphics;
        $pg->skin = $graph_skin;
        $pg->built_in = false;
        $pg->latin_notation = $decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()] != ".";
        $filename = company_path() . "/pdf_files/" . uniqid("") . ".png";
        $pg->display($filename, true);
        $w = $pg->width / 1.5;
        $h = $pg->height / 1.5;
        $x = ($rep->pageWidth - $w) / 2;
        $rep->NewLine(2);
        if ($rep->row - $h < $rep->bottomMargin) {
            $rep->NewPage();
        }
        $rep->AddImage($filename, $x, $rep->row - $h, $w, $h);
    }
    $rep->End();
}
예제 #19
0
function item_settings(&$stock_id)
{
    global $SysPrefs, $path_to_root, $new_item, $pic_height;
    start_outer_table(TABLESTYLE2);
    table_section(1);
    table_section_title(_("Item"));
    //------------------------------------------------------------------------------------
    if ($new_item) {
        text_row(_("Item Code/ISBN:"), 'NewStockID', null, 21, 20);
        $_POST['inactive'] = 0;
    } else {
        // Must be modifying an existing item
        if (get_post('NewStockID') != get_post('stock_id') || get_post('addupdate')) {
            // first item display
            $_POST['NewStockID'] = $_POST['stock_id'];
            $myrow = get_item($_POST['NewStockID']);
            $_POST['long_description'] = $myrow["long_description"];
            $_POST['description'] = $myrow["description"];
            $_POST['category_id'] = $myrow["category_id"];
            /*==============MOODLEARNING=============*/
            $_POST['level_id'] = $myrow["level_id"];
            /*=======================================*/
            $_POST['tax_type_id'] = $myrow["tax_type_id"];
            $_POST['units'] = $myrow["units"];
            $_POST['mb_flag'] = $myrow["mb_flag"];
            $_POST['sales_account'] = $myrow['sales_account'];
            $_POST['inventory_account'] = $myrow['inventory_account'];
            $_POST['cogs_account'] = $myrow['cogs_account'];
            $_POST['adjustment_account'] = $myrow['adjustment_account'];
            $_POST['assembly_account'] = $myrow['assembly_account'];
            $_POST['dimension_id'] = $myrow['dimension_id'];
            $_POST['dimension2_id'] = $myrow['dimension2_id'];
            $_POST['no_sale'] = $myrow['no_sale'];
            $_POST['del_image'] = 0;
            $_POST['inactive'] = $myrow["inactive"];
            $_POST['editable'] = $myrow["editable"];
        }
        label_row(_("Item Code/ISBN:"), $_POST['NewStockID']);
        hidden('NewStockID', $_POST['NewStockID']);
        set_focus('description');
    }
    /*=================MOODLEARNING====================*/
    level_list_row(_("Level:"), 'level_id', null);
    /*=================================================*/
    text_row(_("Name:"), 'description', null, 52, 200);
    textarea_row(_('Description:'), 'long_description', null, 42, 3);
    stock_categories_list_row(_("Category/Subject:"), 'category_id', null, false, $new_item);
    if ($new_item && (list_updated('category_id') || !isset($_POST['units']))) {
        $category_record = get_item_category($_POST['category_id']);
        $_POST['level_id'] = $category_record["level_id"];
        // moodlearning edit
        $_POST['subject_id'] = $category_record["level_id"];
        $_POST['tax_type_id'] = $category_record["dflt_tax_type"];
        $_POST['units'] = $category_record["dflt_units"];
        $_POST['mb_flag'] = $category_record["dflt_mb_flag"];
        $_POST['inventory_account'] = $category_record["dflt_inventory_act"];
        $_POST['cogs_account'] = $category_record["dflt_cogs_act"];
        $_POST['sales_account'] = $category_record["dflt_sales_act"];
        $_POST['adjustment_account'] = $category_record["dflt_adjustment_act"];
        $_POST['assembly_account'] = $category_record["dflt_assembly_act"];
        $_POST['dimension_id'] = $category_record["dflt_dim1"];
        $_POST['dimension2_id'] = $category_record["dflt_dim2"];
        $_POST['no_sale'] = $category_record["dflt_no_sale"];
        $_POST['editable'] = 0;
    }
    $fresh_item = !isset($_POST['NewStockID']) || $new_item || check_usage($_POST['stock_id'], false);
    item_tax_types_list_row(_("Item Tax Type:"), 'tax_type_id', null);
    stock_item_types_list_row(_("Item Type:"), 'mb_flag', null, $fresh_item);
    stock_units_list_row(_('Units of Measure:'), 'units', null, $fresh_item);
    check_row(_("Editable description:"), 'editable');
    check_row(_("Exclude from sales:"), 'no_sale');
    table_section(2);
    $dim = get_company_pref('use_dimension');
    if ($dim >= 1) {
        table_section_title(_("Dimensions"));
        dimensions_list_row(_("Dimension") . " 1", 'dimension_id', null, true, " ", false, 1);
        if ($dim > 1) {
            dimensions_list_row(_("Dimension") . " 2", 'dimension2_id', null, true, " ", false, 2);
        }
    }
    if ($dim < 1) {
        hidden('dimension_id', 0);
    }
    if ($dim < 2) {
        hidden('dimension2_id', 0);
    }
    table_section_title(_("GL Accounts"));
    gl_all_accounts_list_row(_("Sales Account:"), 'sales_account', $_POST['sales_account']);
    if (!is_service($_POST['mb_flag'])) {
        gl_all_accounts_list_row(_("Inventory Account:"), 'inventory_account', $_POST['inventory_account']);
        gl_all_accounts_list_row(_("C.O.G.S. Account:"), 'cogs_account', $_POST['cogs_account']);
        gl_all_accounts_list_row(_("Inventory Adjustments Account:"), 'adjustment_account', $_POST['adjustment_account']);
    } else {
        gl_all_accounts_list_row(_("C.O.G.S. Account:"), 'cogs_account', $_POST['cogs_account']);
        hidden('inventory_account', $_POST['inventory_account']);
        hidden('adjustment_account', $_POST['adjustment_account']);
    }
    if (is_manufactured($_POST['mb_flag'])) {
        gl_all_accounts_list_row(_("Item Assembly Costs Account:"), 'assembly_account', $_POST['assembly_account']);
    } else {
        hidden('assembly_account', $_POST['assembly_account']);
    }
    table_section_title(_("Other"));
    // Add image upload for New Item  - by Joe
    file_row(_("Image File (.jpg)") . ":", 'pic', 'pic');
    // Add Image upload for New Item  - by Joe
    $stock_img_link = "";
    $check_remove_image = false;
    if (isset($_POST['NewStockID']) && file_exists(company_path() . '/images/' . item_img_name($_POST['NewStockID']) . ".jpg")) {
        // 31/08/08 - rand() call is necessary here to avoid caching problems. Thanks to Peter D.
        $stock_img_link .= "<img id='item_img' alt = '[" . $_POST['NewStockID'] . ".jpg" . "]' src='" . company_path() . '/images/' . item_img_name($_POST['NewStockID']) . ".jpg?nocache=" . rand() . "'" . " height='{$pic_height}' border='0'>";
        $check_remove_image = true;
    } else {
        $stock_img_link .= _("No image");
    }
    label_row("&nbsp;", $stock_img_link);
    if ($check_remove_image) {
        check_row(_("Delete Image:"), 'del_image');
    }
    record_status_list_row(_("Item status:"), 'inactive');
    end_outer_table(1);
    div_start('controls');
    if (!isset($_POST['NewStockID']) || $new_item) {
        submit_center('addupdate', _("Insert New Item"), true, '', 'default');
    } else {
        submit_center_first('addupdate', _("Update Item"), '', @$_REQUEST['popup'] ? true : 'default');
        submit_return('select', get_post('stock_id'), _("Select this items and return to document entry."), 'default');
        submit('clone', _("Clone This Item"), true, '', true);
        submit('delete', _("Delete This Item"), true, '', true);
        submit_center_last('cancel', _("Cancel"), _("Cancel Edition"), 'cancel');
    }
    div_end();
}
예제 #20
0
function print_stock_check()
{
    global $path_to_root, $pic_height;
    $category = $_POST['PARAM_0'];
    $location = $_POST['PARAM_1'];
    $pictures = $_POST['PARAM_2'];
    $check = $_POST['PARAM_3'];
    $shortage = $_POST['PARAM_4'];
    $no_zeros = $_POST['PARAM_5'];
    $like = $_POST['PARAM_6'];
    $comments = $_POST['PARAM_7'];
    $orientation = $_POST['PARAM_8'];
    $destination = $_POST['PARAM_9'];
    if ($destination) {
        include_once $path_to_root . "/reporting/includes/excel_report.inc";
    } else {
        include_once $path_to_root . "/reporting/includes/pdf_report.inc";
    }
    $orientation = $orientation ? 'L' : 'P';
    if ($category == ALL_NUMERIC) {
        $category = 0;
    }
    if ($category == 0) {
        $cat = _('All');
    } else {
        $cat = get_category_name($category);
    }
    if ($location == ALL_TEXT) {
        $location = 'all';
    }
    if ($location == 'all') {
        $loc = _('All');
    } else {
        $loc = get_location_name($location);
    }
    if ($shortage) {
        $short = _('Yes');
        $available = _('Shortage');
    } else {
        $short = _('No');
        $available = _('Available');
    }
    if ($no_zeros) {
        $nozeros = _('Yes');
    } else {
        $nozeros = _('No');
    }
    if ($check) {
        $cols = array(0, 75, 225, 250, 295, 345, 390, 445, 515);
        $headers = array(_('Stock ID'), _('Description'), _('UOM'), _('Quantity'), _('Check'), _('Demand'), $available, _('On Order'));
        $aligns = array('left', 'left', 'left', 'right', 'right', 'right', 'right', 'right');
    } else {
        $cols = array(0, 75, 225, 250, 315, 380, 445, 515);
        $headers = array(_('Stock ID'), _('Description'), _('UOM'), _('Quantity'), _('Demand'), $available, _('On Order'));
        $aligns = array('left', 'left', 'left', 'right', 'right', 'right', 'right');
    }
    $params = array(0 => $comments, 1 => array('text' => _('Category'), 'from' => $cat, 'to' => ''), 2 => array('text' => _('Location'), 'from' => $loc, 'to' => ''), 3 => array('text' => _('Only Shortage'), 'from' => $short, 'to' => ''), 4 => array('text' => _('Suppress Zeros'), 'from' => $nozeros, 'to' => ''));
    if ($pictures) {
        $user_comp = user_company();
    } else {
        $user_comp = "";
    }
    $rep = new FrontReport(_('Stock Check Sheets'), "StockCheckSheet", user_pagesize(), 9, $orientation);
    if ($orientation == 'L') {
        recalculate_cols($cols);
    }
    $rep->Font();
    $rep->Info($params, $cols, $headers, $aligns);
    $rep->NewPage();
    $res = getTransactions($category, $location, $like);
    $catt = '';
    while ($trans = db_fetch($res)) {
        if ($location == 'all') {
            $loc_code = "";
        } else {
            $loc_code = $location;
        }
        $demandqty = get_demand_qty($trans['stock_id'], $loc_code);
        $demandqty += get_demand_asm_qty($trans['stock_id'], $loc_code);
        $onorder = get_on_porder_qty($trans['stock_id'], $loc_code);
        $flag = get_mb_flag($trans['stock_id']);
        if ($flag == 'M') {
            $onorder += get_on_worder_qty($trans['stock_id'], $loc_code);
        }
        if ($no_zeros && $trans['QtyOnHand'] == 0 && $demandqty == 0 && $onorder == 0) {
            continue;
        }
        if ($shortage && $trans['QtyOnHand'] - $demandqty >= 0) {
            continue;
        }
        if ($catt != $trans['cat_description']) {
            if ($catt != '') {
                $rep->Line($rep->row - 2);
                $rep->NewLine(2, 3);
            }
            $rep->TextCol(0, 1, $trans['category_id']);
            $rep->TextCol(1, 2, $trans['cat_description']);
            $catt = $trans['cat_description'];
            $rep->NewLine();
        }
        $rep->NewLine();
        $dec = get_qty_dec($trans['stock_id']);
        $rep->TextCol(0, 1, $trans['stock_id']);
        $rep->TextCol(1, 2, $trans['description'] . ($trans['inactive'] == 1 ? " (" . _("Inactive") . ")" : ""), -1);
        $rep->TextCol(2, 3, $trans['units']);
        $rep->AmountCol(3, 4, $trans['QtyOnHand'], $dec);
        if ($check) {
            $rep->TextCol(4, 5, "_________");
            $rep->AmountCol(5, 6, $demandqty, $dec);
            $rep->AmountCol(6, 7, $trans['QtyOnHand'] - $demandqty, $dec);
            $rep->AmountCol(7, 8, $onorder, $dec);
        } else {
            $rep->AmountCol(4, 5, $demandqty, $dec);
            $rep->AmountCol(5, 6, $trans['QtyOnHand'] - $demandqty, $dec);
            $rep->AmountCol(6, 7, $onorder, $dec);
        }
        if ($pictures) {
            $image = company_path() . '/images/' . item_img_name($trans['stock_id']) . '.jpg';
            if (file_exists($image)) {
                $rep->NewLine();
                if ($rep->row - $pic_height < $rep->bottomMargin) {
                    $rep->NewPage();
                }
                $rep->AddImage($image, $rep->cols[1], $rep->row - $pic_height, 0, $pic_height);
                $rep->row -= $pic_height;
                $rep->NewLine();
            }
        }
    }
    $rep->Line($rep->row - 4);
    $rep->NewLine();
    $rep->End();
}
예제 #21
0
function print_profit_and_loss_statement()
{
    global $path_to_root;
    $dim = get_company_pref('use_dimension');
    $dimension = $dimension2 = 0;
    $from = $_POST['PARAM_0'];
    $to = $_POST['PARAM_1'];
    $compare = $_POST['PARAM_2'];
    if ($dim == 2) {
        $dimension = $_POST['PARAM_3'];
        $dimension2 = $_POST['PARAM_4'];
        $tags = isset($_POST['PARAM_5']) ? $_POST['PARAM_5'] : -1;
        $decimals = $_POST['PARAM_6'];
        $graphics = $_POST['PARAM_7'];
        $comments = $_POST['PARAM_8'];
        $orientation = $_POST['PARAM_9'];
        $destination = $_POST['PARAM_10'];
    } else {
        if ($dim == 1) {
            $dimension = $_POST['PARAM_3'];
            $tags = isset($_POST['PARAM_4']) ? $_POST['PARAM_4'] : -1;
            $decimals = $_POST['PARAM_5'];
            $graphics = $_POST['PARAM_6'];
            $comments = $_POST['PARAM_7'];
            $orientation = $_POST['PARAM_8'];
            $destination = $_POST['PARAM_9'];
        } else {
            $tags = isset($_POST['PARAM_3']) ? $_POST['PARAM_3'] : -1;
            $decimals = $_POST['PARAM_4'];
            $graphics = $_POST['PARAM_5'];
            $comments = $_POST['PARAM_6'];
            $orientation = $_POST['PARAM_7'];
            $destination = $_POST['PARAM_8'];
        }
    }
    if ($destination) {
        include_once $path_to_root . "/reporting/includes/excel_report.inc";
    } else {
        include_once $path_to_root . "/reporting/includes/pdf_report.inc";
    }
    $orientation = $orientation ? 'L' : 'P';
    if ($graphics) {
        include_once $path_to_root . "/reporting/includes/class.graphic.inc";
        $pg = new graph();
    }
    if (!$decimals) {
        $dec = 0;
    } else {
        $dec = user_price_dec();
    }
    $pdec = user_percent_dec();
    $cols = array(0, 50, 200, 350, 425, 500);
    //------------0--1---2----3----4----5--
    $headers = array(_('Account'), _('Account Name'), _('Period'), _('Accumulated'), _('Achieved %'));
    $aligns = array('left', 'left', 'right', 'right', 'right');
    if ($dim == 2) {
        $params = array(0 => $comments, 1 => array('text' => _('Period'), 'from' => $from, 'to' => $to), 2 => array('text' => _('Dimension') . " 1", 'from' => get_dimension_string($dimension), 'to' => ''), 3 => array('text' => _('Dimension') . " 2", 'from' => get_dimension_string($dimension2), 'to' => ''), 4 => array('text' => _('Tags'), 'from' => get_tag_names($tags), 'to' => ''));
    } else {
        if ($dim == 1) {
            $params = array(0 => $comments, 1 => array('text' => _('Period'), 'from' => $from, 'to' => $to), 2 => array('text' => _('Dimension'), 'from' => get_dimension_string($dimension), 'to' => ''), 3 => array('text' => _('Tags'), 'from' => get_tag_names($tags), 'to' => ''));
        } else {
            $params = array(0 => $comments, 1 => array('text' => _('Period'), 'from' => $from, 'to' => $to), 2 => array('text' => _('Tags'), 'from' => get_tag_names($tags), 'to' => ''));
        }
    }
    if ($compare == 0 || $compare == 2) {
        $end = $to;
        if ($compare == 2) {
            $begin = $from;
            $headers[3] = _('Budget');
        } else {
            $begin = begin_fiscalyear();
        }
    } elseif ($compare == 1) {
        $begin = add_months($from, -12);
        $end = add_months($to, -12);
        $headers[3] = _('Period Y-1');
    }
    $rep = new FrontReport(_('Profit and Loss Statement'), "ProfitAndLoss", user_pagesize(), 9, $orientation);
    if ($orientation == 'L') {
        recalculate_cols($cols);
    }
    $rep->Font();
    $rep->Info($params, $cols, $headers, $aligns);
    $rep->NewPage();
    $salesper = 0.0;
    $salesacc = 0.0;
    $classresult = get_account_classes(false, 0);
    while ($class = db_fetch($classresult)) {
        $class_per_total = 0;
        $class_acc_total = 0;
        $convert = get_class_type_convert($class["ctype"]);
        //Print Class Name
        $rep->Font('bold');
        $rep->TextCol(0, 5, $class["class_name"]);
        $rep->Font();
        $rep->NewLine();
        //Get Account groups/types under this group/type with no parents
        $typeresult = get_account_types(false, $class['cid'], -1);
        while ($accounttype = db_fetch($typeresult)) {
            $classtotal = display_type($accounttype["id"], $accounttype["name"], $from, $to, $begin, $end, $compare, $convert, $dec, $pdec, $rep, $dimension, $dimension2, $tags, $pg, $graphics);
            $class_per_total += $classtotal[0];
            $class_acc_total += $classtotal[1];
        }
        //Print Class Summary
        $rep->row += 6;
        $rep->Line($rep->row);
        $rep->NewLine();
        $rep->Font('bold');
        $rep->TextCol(0, 2, _('Total') . " " . $class["class_name"]);
        $rep->AmountCol(2, 3, $class_per_total * $convert, $dec);
        $rep->AmountCol(3, 4, $class_acc_total * $convert, $dec);
        $rep->AmountCol(4, 5, Achieve($class_per_total, $class_acc_total), $pdec);
        $rep->Font();
        $rep->NewLine(2);
        $salesper += $class_per_total;
        $salesacc += $class_acc_total;
    }
    $rep->Font('bold');
    $rep->TextCol(0, 2, _('Calculated Return'));
    $rep->AmountCol(2, 3, $salesper * -1, $dec);
    // always convert
    $rep->AmountCol(3, 4, $salesacc * -1, $dec);
    $rep->AmountCol(4, 5, Achieve($salesper, $salesacc), $pdec);
    if ($graphics) {
        $pg->x[] = _('Calculated Return');
        $pg->y[] = abs($salesper);
        $pg->z[] = abs($salesacc);
    }
    $rep->Font();
    $rep->NewLine();
    $rep->Line($rep->row);
    if ($graphics) {
        global $decseps, $graph_skin;
        $pg->title = $rep->title;
        $pg->axis_x = _("Group");
        $pg->axis_y = _("Amount");
        $pg->graphic_1 = $headers[2];
        $pg->graphic_2 = $headers[3];
        $pg->type = $graphics;
        $pg->skin = $graph_skin;
        $pg->built_in = false;
        $pg->latin_notation = $decseps[$_SESSION["wa_current_user"]->prefs->dec_sep()] != ".";
        $filename = company_path() . "/pdf_files/" . uniqid("") . ".png";
        $pg->display($filename, true);
        $w = $pg->width / 1.5;
        $h = $pg->height / 1.5;
        $x = ($rep->pageWidth - $w) / 2;
        $rep->NewLine(2);
        if ($rep->row - $h < $rep->bottomMargin) {
            $rep->NewPage();
        }
        $rep->AddImage($filename, $x, $rep->row - $h, $w, $h);
    }
    $rep->End();
}