Example #1
0
/** 
 * Get the tags names assigned to a lead.
 * 
 * @param mixed Id (int) or ids (array) of the lead/s.
 * @param array [Optional] Items to filter the tags.
 * 
 * @return array The list of the tag names.
 */
function get_lead_tag_names($lead_id = false, $tag_filter = array())
{
    $lead_filter = array();
    if (empty($lead_id)) {
        $lead_filter = array(LEADS_TABLE_LEAD_ID_COL => $lead_id);
    }
    return get_tag_names(LEAD, $lead_filter, $tag_filter);
}
Example #2
0
function print_annual_expense_breakdown()
{
    global $path_to_root, $date_system;
    $dim = get_company_pref('use_dimension');
    $dimension = $dimension2 = 0;
    if ($dim == 2) {
        $year = $_POST['PARAM_0'];
        $dimension = $_POST['PARAM_1'];
        $dimension2 = $_POST['PARAM_2'];
        $tags = isset($_POST['PARAM_3']) ? $_POST['PARAM_3'] : -1;
        $comments = $_POST['PARAM_4'];
        $orientation = $_POST['PARAM_5'];
        $destination = $_POST['PARAM_6'];
    } else {
        if ($dim == 1) {
            $year = $_POST['PARAM_0'];
            $dimension = $_POST['PARAM_1'];
            $tags = isset($_POST['PARAM_2']) ? $_POST['PARAM_2'] : -1;
            $comments = $_POST['PARAM_3'];
            $orientation = $_POST['PARAM_4'];
            $destination = $_POST['PARAM_5'];
        } else {
            $year = $_POST['PARAM_0'];
            $tags = isset($_POST['PARAM_1']) ? $_POST['PARAM_1'] : -1;
            $comments = $_POST['PARAM_2'];
            $orientation = $_POST['PARAM_3'];
            $destination = $_POST['PARAM_4'];
        }
    }
    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 = 1;
    //$pdec = user_percent_dec();
    $cols = array(0, 40, 150, 180, 210, 240, 270, 300, 330, 360, 390, 420, 450, 480, 510);
    //------------0--1---2----3----4----5----6----7----8----10---11---12---13---14---15-
    //$yr = date('Y');
    //$mo = date('m'):
    // from now
    $sql = "SELECT begin, end, YEAR(end) AS yr, MONTH(end) AS mo FROM " . TB_PREF . "fiscal_year WHERE id=" . db_escape($year);
    $result = db_query($sql, "could not get fiscal year");
    $row = db_fetch($result);
    $year = sql2date($row['begin']) . " - " . sql2date($row['end']);
    $yr = $row['yr'];
    $mo = $row['mo'];
    $da = 1;
    if ($date_system == 1) {
        list($yr, $mo, $da) = jalali_to_gregorian($yr, $mo, $da);
    } elseif ($date_system == 2) {
        list($yr, $mo, $da) = islamic_to_gregorian($yr, $mo, $da);
    }
    $per12 = strftime('%b', mktime(0, 0, 0, $mo, $da, $yr));
    $per11 = strftime('%b', mktime(0, 0, 0, $mo - 1, $da, $yr));
    $per10 = strftime('%b', mktime(0, 0, 0, $mo - 2, $da, $yr));
    $per09 = strftime('%b', mktime(0, 0, 0, $mo - 3, $da, $yr));
    $per08 = strftime('%b', mktime(0, 0, 0, $mo - 4, $da, $yr));
    $per07 = strftime('%b', mktime(0, 0, 0, $mo - 5, $da, $yr));
    $per06 = strftime('%b', mktime(0, 0, 0, $mo - 6, $da, $yr));
    $per05 = strftime('%b', mktime(0, 0, 0, $mo - 7, $da, $yr));
    $per04 = strftime('%b', mktime(0, 0, 0, $mo - 8, $da, $yr));
    $per03 = strftime('%b', mktime(0, 0, 0, $mo - 9, $da, $yr));
    $per02 = strftime('%b', mktime(0, 0, 0, $mo - 10, $da, $yr));
    $per01 = strftime('%b', mktime(0, 0, 0, $mo - 11, $da, $yr));
    $headers = array(_('Account'), _('Account Name'), $per01, $per02, $per03, $per04, $per05, $per06, $per07, $per08, $per09, $per10, $per11, $per12);
    $aligns = array('left', 'left', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right');
    if ($dim == 2) {
        $params = array(0 => $comments, 1 => array('text' => _("Year"), 'from' => $year, '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' => ''), 5 => array('text' => _('Info'), 'from' => _('Amounts in thousands'), 'to' => ''));
    } else {
        if ($dim == 1) {
            $params = array(0 => $comments, 1 => array('text' => _("Year"), 'from' => $year, 'to' => ''), 2 => array('text' => _('Dimension'), 'from' => get_dimension_string($dimension), 'to' => ''), 3 => array('text' => _('Tags'), 'from' => get_tag_names($tags), 'to' => ''), 4 => array('text' => _('Info'), 'from' => _('Amounts in thousands'), 'to' => ''));
        } else {
            $params = array(0 => $comments, 1 => array('text' => _("Year"), 'from' => $year, 'to' => ''), 2 => array('text' => _('Tags'), 'from' => get_tag_names($tags), 'to' => ''), 3 => array('text' => _('Info'), 'from' => _('Amounts in thousands'), 'to' => ''));
        }
    }
    $rep = new FrontReport(_('Annual Expense Breakdown'), "AnnualBreakDown", user_pagesize(), 9, $orientation);
    if ($orientation == 'L') {
        recalculate_cols($cols);
    }
    $rep->Font();
    $rep->Info($params, $cols, $headers, $aligns);
    $rep->NewPage();
    $sales = array(1 => 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
    $classresult = get_account_classes(false, 0);
    while ($class = db_fetch($classresult)) {
        $ctotal = array(1 => 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 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"], $yr, $mo, $convert, $dec, $rep, $dimension, $dimension2, $tags);
            for ($i = 1; $i <= 12; $i++) {
                $ctotal[$i] += $classtotal[$i];
            }
        }
        //Print Class Summary
        $rep->row += 6;
        $rep->Line($rep->row);
        $rep->NewLine();
        $rep->Font('bold');
        $rep->TextCol(0, 2, _('Total') . " " . $class["class_name"]);
        for ($i = 1; $i <= 12; $i++) {
            $rep->AmountCol($i + 1, $i + 2, $ctotal[$i] * $convert, $dec);
            $sales[$i] += $ctotal[$i];
        }
        $rep->Font();
        $rep->NewLine(2);
    }
    $rep->Font('bold');
    $rep->TextCol(0, 2, _("Calculated Return"));
    for ($i = 1; $i <= 12; $i++) {
        $rep->AmountCol($i + 1, $i + 2, $sales[$i] * -1, $dec);
    }
    $rep->Font();
    $rep->NewLine();
    $rep->Line($rep->row);
    $rep->NewLine(2);
    $rep->End();
}
Example #3
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();
}
Example #4
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();
}