function floatsort($a, $b)
{
    if (floatgtr($a[0], $b[0])) {
        return 1;
    }
    if (floatcmp($a[0], $b[0])) {
        return 0;
    }
    return -1;
}
function alloc_link($row)
{
    $link = pager_link(_("Allocation"), "/sales/allocations/customer_allocate.php?trans_no=" . $row["trans_no"] . "&trans_type=" . $row["type"] . "&debtor_no=" . $row["debtor_no"], ICON_ALLOC);
    if ($row["type"] == ST_CUSTCREDIT && $row['TotalAmount'] > 0) {
        /*its a credit note which could have an allocation */
        return $link;
    } elseif (($row["type"] == ST_CUSTPAYMENT || $row["type"] == ST_BANKDEPOSIT) && floatcmp($row['TotalAmount'], $row['Allocated']) >= 0) {
        /*its a receipt  which could have an allocation*/
        return $link;
    } elseif ($row["type"] == ST_CUSTPAYMENT && $row['TotalAmount'] <= 0) {
        /*its a negative receipt */
        return '';
    } elseif ($row["type"] == ST_SALESINVOICE && $row['TotalAmount'] - $row['Allocated'] > 0) {
        return pager_link(_("Payment"), "/sales/customer_payments.php?customer_id=" . $row["debtor_no"] . "&SInvoice=" . $row["trans_no"], ICON_MONEY);
    }
}
function check_trans()
{
    global $Refs;
    $input_error = 0;
    if ($_SESSION['pay_items']->count_gl_items() < 1) {
        display_error(_("You must enter at least one payment line."));
        set_focus('code_id');
        $input_error = 1;
    }
    if ($_SESSION['pay_items']->gl_items_total() == 0.0) {
        display_error(_("The total bank amount cannot be 0."));
        set_focus('code_id');
        $input_error = 1;
    }
    $limit = get_bank_account_limit($_POST['bank_account'], $_POST['date_']);
    $amnt_chg = -$_SESSION['pay_items']->gl_items_total() - $_SESSION['pay_items']->original_amount;
    if ($limit !== null && floatcmp($limit, -$amnt_chg) < 0) {
        display_error(sprintf(_("The total bank amount exceeds allowed limit (%s)."), price_format($limit - $_SESSION['pay_items']->original_amount)));
        set_focus('code_id');
        $input_error = 1;
    }
    if ($trans = check_bank_account_history($amnt_chg, $_POST['bank_account'], $_POST['date_'])) {
        display_error(sprintf(_("The bank transaction would result in exceed of authorized overdraft limit for transaction: %s #%s on %s."), $systypes_array[$trans['type']], $trans['trans_no'], sql2date($trans['trans_date'])));
        set_focus('amount');
        $input_error = 1;
    }
    if (!$Refs->is_valid($_POST['ref'])) {
        display_error(_("You must enter a reference."));
        set_focus('ref');
        $input_error = 1;
    } elseif ($_POST['ref'] != $_SESSION['pay_items']->reference && !is_new_reference($_POST['ref'], $_SESSION['pay_items']->trans_type)) {
        display_error(_("The entered reference is already in use."));
        set_focus('ref');
        $input_error = 1;
    }
    if (!is_date($_POST['date_'])) {
        display_error(_("The entered date for the payment is invalid."));
        set_focus('date_');
        $input_error = 1;
    } elseif (!is_date_in_fiscalyear($_POST['date_'])) {
        display_error(_("The entered date is not in fiscal year."));
        set_focus('date_');
        $input_error = 1;
    }
    if (get_post('PayType') == PT_CUSTOMER && (!get_post('person_id') || !get_post('PersonDetailID'))) {
        display_error(_("You have to select customer and customer branch."));
        set_focus('person_id');
        $input_error = 1;
    } elseif (get_post('PayType') == PT_SUPPLIER && !get_post('person_id')) {
        display_error(_("You have to select supplier."));
        set_focus('person_id');
        $input_error = 1;
    }
    if (!db_has_currency_rates(get_bank_account_currency($_POST['bank_account']), $_POST['date_'], true)) {
        $input_error = 1;
    }
    if (isset($_POST['settled_amount']) && in_array(get_post('PayType'), array(PT_SUPPLIER, PT_CUSTOMER)) && input_num('settled_amount') <= 0) {
        display_error(_("Settled amount have to be positive number."));
        set_focus('person_id');
        $input_error = 1;
    }
    return $input_error;
}
function check_overdue($row)
{
    return $row['OverDue'] == 1 && floatcmp($row["TotalAmount"], $row["Allocated"]) != 0;
}
function check_valid_entries()
{
    global $Refs;
    if (!is_date($_POST['DatePaid'])) {
        display_error(_("The entered date is invalid."));
        set_focus('DatePaid');
        return false;
    }
    if (!is_date_in_fiscalyear($_POST['DatePaid'])) {
        display_error(_("The entered date is not in fiscal year."));
        set_focus('DatePaid');
        return false;
    }
    if (!check_num('amount', 0)) {
        display_error(_("The entered amount is invalid or less than zero."));
        set_focus('amount');
        return false;
    }
    if (input_num('amount') == 0) {
        display_error(_("The total bank amount cannot be 0."));
        set_focus('amount');
        return false;
    }
    $limit = get_bank_account_limit($_POST['FromBankAccount'], $_POST['DatePaid']);
    $amnt_tr = input_num('charge') + input_num('amount');
    if ($limit !== null && floatcmp($limit, $amnt_tr) < 0) {
        display_error(sprintf(_("The total bank amount exceeds allowed limit (%s) for source account."), price_format($limit)));
        set_focus('amount');
        return false;
    }
    if ($trans = check_bank_account_history(-$amnt_tr, $_POST['FromBankAccount'], $_POST['DatePaid'])) {
        display_error(sprintf(_("The bank transaction would result in exceed of authorized overdraft limit for transaction: %s #%s on %s."), $systypes_array[$trans['type']], $trans['trans_no'], sql2date($trans['trans_date'])));
        set_focus('amount');
        $input_error = 1;
    }
    if (isset($_POST['charge']) && !check_num('charge', 0)) {
        display_error(_("The entered amount is invalid or less than zero."));
        set_focus('charge');
        return false;
    }
    if (isset($_POST['charge']) && input_num('charge') > 0 && get_company_pref('bank_charge_act') == '') {
        display_error(_("The Bank Charge Account has not been set in System and General GL Setup."));
        set_focus('charge');
        return false;
    }
    if (!$Refs->is_valid($_POST['ref'])) {
        display_error(_("You must enter a reference."));
        set_focus('ref');
        return false;
    }
    if (!is_new_reference($_POST['ref'], ST_BANKTRANSFER)) {
        display_error(_("The entered reference is already in use."));
        set_focus('ref');
        return false;
    }
    if ($_POST['FromBankAccount'] == $_POST['ToBankAccount']) {
        display_error(_("The source and destination bank accouts cannot be the same."));
        set_focus('ToBankAccount');
        return false;
    }
    if (isset($_POST['target_amount']) && !check_num('target_amount', 0)) {
        display_error(_("The entered amount is invalid or less than zero."));
        set_focus('target_amount');
        return false;
    }
    if (isset($_POST['target_amount']) && input_num('target_amount') == 0) {
        display_error(_("The incomming bank amount cannot be 0."));
        set_focus('target_amount');
        return false;
    }
    if (!db_has_currency_rates(get_bank_account_currency($_POST['FromBankAccount']), $_POST['DatePaid'])) {
        return false;
    }
    if (!db_has_currency_rates(get_bank_account_currency($_POST['ToBankAccount']), $_POST['DatePaid'])) {
        return false;
    }
    return true;
}
Exemple #6
0
function check_inputs()
{
    global $Refs;
    if (!get_post('supplier_id')) {
        display_error(_("There is no supplier selected."));
        set_focus('supplier_id');
        return false;
    }
    if (@$_POST['amount'] == "") {
        $_POST['amount'] = price_format(0);
    }
    if (!check_num('amount', 0)) {
        display_error(_("The entered amount is invalid or less than zero."));
        set_focus('amount');
        return false;
    }
    if (isset($_POST['charge']) && !check_num('charge', 0)) {
        display_error(_("The entered amount is invalid or less than zero."));
        set_focus('charge');
        return false;
    }
    if (isset($_POST['charge']) && input_num('charge') > 0) {
        $charge_acct = get_company_pref('bank_charge_act');
        if (get_gl_account($charge_acct) == false) {
            display_error(_("The Bank Charge Account has not been set in System and General GL Setup."));
            set_focus('charge');
            return false;
        }
    }
    if (@$_POST['discount'] == "") {
        $_POST['discount'] = 0;
    }
    if (!check_num('discount', 0)) {
        display_error(_("The entered discount is invalid or less than zero."));
        set_focus('amount');
        return false;
    }
    //if (input_num('amount') - input_num('discount') <= 0)
    if (input_num('amount') <= 0) {
        display_error(_("The total of the amount and the discount is zero or negative. Please enter positive values."));
        set_focus('amount');
        return false;
    }
    if (isset($_POST['bank_amount']) && input_num('bank_amount') <= 0) {
        display_error(_("The entered bank amount is zero or negative."));
        set_focus('bank_amount');
        return false;
    }
    if (!is_date($_POST['DatePaid'])) {
        display_error(_("The entered date is invalid."));
        set_focus('DatePaid');
        return false;
    } elseif (!is_date_in_fiscalyear($_POST['DatePaid'])) {
        display_error(_("The entered date is out of fiscal year or is closed for further data entry."));
        set_focus('DatePaid');
        return false;
    }
    $limit = get_bank_account_limit($_POST['bank_account'], $_POST['DatePaid']);
    if ($limit !== null && floatcmp($limit, input_num('amount')) < 0) {
        display_error(sprintf(_("The total bank amount exceeds allowed limit (%s)."), price_format($limit)));
        set_focus('amount');
        return false;
    }
    if (!$Refs->is_valid($_POST['ref'])) {
        display_error(_("You must enter a reference."));
        set_focus('ref');
        return false;
    }
    if (!is_new_reference($_POST['ref'], ST_SUPPAYMENT)) {
        display_error(_("The entered reference is already in use."));
        set_focus('ref');
        return false;
    }
    if (!db_has_currency_rates(get_supplier_currency($_POST['supplier_id']), $_POST['DatePaid'], true)) {
        return false;
    }
    $_SESSION['alloc']->amount = -input_num('amount');
    if (isset($_POST["TotalNumberOfAllocs"])) {
        return check_allocations();
    } else {
        return true;
    }
}
Exemple #7
0
function print_remittances()
{
    global $path_to_root, $systypes_array;
    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();
    $fno = explode("-", $from);
    $tno = explode("-", $to);
    $from = min($fno[0], $tno[0]);
    $to = max($fno[0], $tno[0]);
    $cols = array(4, 85, 150, 225, 275, 360, 450, 515);
    // $headers in doctext.inc
    $aligns = array('left', 'left', 'left', 'left', 'right', 'right', 'right');
    $params = array('comments' => $comments);
    $cur = get_company_Pref('curr_default');
    if ($email == 0) {
        $rep = new FrontReport(_('REMITTANCE'), "RemittanceBulk", user_pagesize(), 9, $orientation);
    }
    if ($orientation == 'L') {
        recalculate_cols($cols);
    }
    for ($i = $from; $i <= $to; $i++) {
        if ($fno[0] == $tno[0]) {
            $types = array($fno[1]);
        } else {
            $types = array(ST_BANKPAYMENT, ST_SUPPAYMENT, ST_SUPPCREDIT);
        }
        foreach ($types as $j) {
            $myrow = get_remittance($j, $i);
            if (!$myrow) {
                continue;
            }
            $res = get_bank_trans($j, $i);
            $baccount = db_fetch($res);
            $params['bankaccount'] = $baccount['bank_act'];
            if ($email == 1) {
                $rep = new FrontReport("", "", user_pagesize(), 9, $orientation);
                $rep->title = _('REMITTANCE');
                $rep->filename = "Remittance" . $i . ".pdf";
            }
            $rep->SetHeaderType('Header2');
            $rep->currency = $cur;
            $rep->Font();
            $rep->Info($params, $cols, null, $aligns);
            $contacts = get_supplier_contacts($myrow['supplier_id'], 'invoice');
            $rep->SetCommonData($myrow, null, $myrow, $baccount, ST_SUPPAYMENT, $contacts);
            $rep->NewPage();
            $result = get_allocations_for_remittance($myrow['supplier_id'], $myrow['type'], $myrow['trans_no']);
            $doctype = ST_SUPPAYMENT;
            $total_allocated = 0;
            $rep->TextCol(0, 4, _("As advance / full / part / payment towards:"), -2);
            $rep->NewLine(2);
            while ($myrow2 = db_fetch($result)) {
                $rep->TextCol(0, 1, $systypes_array[$myrow2['type']], -2);
                $rep->TextCol(1, 2, $myrow2['supp_reference'], -2);
                $rep->TextCol(2, 3, sql2date($myrow2['tran_date']), -2);
                $rep->TextCol(3, 4, sql2date($myrow2['due_date']), -2);
                $rep->AmountCol(4, 5, $myrow2['Total'], $dec, -2);
                $rep->AmountCol(5, 6, $myrow2['Total'] - $myrow2['alloc'], $dec, -2);
                $rep->AmountCol(6, 7, $myrow2['amt'], $dec, -2);
                $total_allocated += $myrow2['amt'];
                $rep->NewLine(1);
                if ($rep->row < $rep->bottomMargin + 15 * $rep->lineHeight) {
                    $rep->NewPage();
                }
            }
            $memo = get_comments_string($j, $i);
            if ($memo != "") {
                $rep->NewLine();
                $rep->TextColLines(1, 5, $memo, -2);
            }
            $rep->row = $rep->bottomMargin + 16 * $rep->lineHeight;
            $rep->TextCol(3, 6, _("Total Allocated"), -2);
            $rep->AmountCol(6, 7, $total_allocated, $dec, -2);
            $rep->NewLine();
            $rep->TextCol(3, 6, _("Left to Allocate"), -2);
            $myrow['Total'] *= -1;
            $myrow['ov_discount'] *= -1;
            $rep->AmountCol(6, 7, $myrow['Total'] + $myrow['ov_discount'] - $total_allocated, $dec, -2);
            if (floatcmp($myrow['ov_discount'], 0)) {
                $rep->NewLine();
                $rep->TextCol(3, 6, _("Discount"), -2);
                $rep->AmountCol(6, 7, -$myrow['ov_discount'], $dec, -2);
            }
            $rep->NewLine();
            $rep->Font('bold');
            $rep->TextCol(3, 6, _("TOTAL REMITTANCE"), -2);
            $rep->AmountCol(6, 7, $myrow['Total'], $dec, -2);
            $words = price_in_words($myrow['Total'], ST_SUPPAYMENT);
            if ($words != "") {
                $rep->NewLine(2);
                $rep->TextCol(1, 7, $myrow['curr_code'] . ": " . $words, -2);
            }
            $rep->Font();
            if ($email == 1) {
                $myrow['DebtorName'] = $myrow['supp_name'];
                $rep->End($email);
            }
        }
    }
    if ($email == 0) {
        $rep->End();
    }
}
Exemple #8
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 __sortByStartTime($a, $b)
 {
     if (floatgtr($a['start'], $b['start'])) {
         return 1;
     }
     if (floatcmp($a['start'], $b['start'])) {
         return 0;
     }
     return -1;
 }
function scale_switches($orig_dims, $dims, $fill)
{
    $target_w = floatval($dims[0]);
    $target_h = floatval($dims[1]);
    $vf = '';
    $scale = 'scale=' . $target_w . ':' . $target_h;
    if ($fill && $fill != 'stretch') {
        $orig_even_w = floatval($orig_dims[0]);
        $orig_dims1 = floatval($orig_dims[1]);
        $extra0 = $orig_even_w % 2;
        $extra1 = $orig_dims1 % 2;
        $orig_even_w -= $extra0;
        $orig_dims1 -= $extra1;
        $ratio_w = $target_w / $orig_even_w;
        $ratio_h = $target_h / $orig_dims1;
        if (!floatcmp($ratio_w, $ratio_h)) {
            $multiplier = $fill == 'scale' ? floatmin($ratio_w, $ratio_h) : floatmax($ratio_w, $ratio_h);
            $scaled_w = round($target_w / $multiplier);
            $scaled_h = round($target_h / $multiplier);
            if (!floatcmp($orig_even_w, $scaled_w)) {
                if (floatgtr($orig_even_w, $scaled_w)) {
                    //$a['cropleft'] = $a['cropright'] = floor((($orig_even_w - $scaled_w) / 2));
                    $vf .= 'crop=' . floor(($orig_even_w - $scaled_w) / 2) . ':0:' . $scaled_w . ':' . $scaled_h;
                } else {
                    /*$pad_x = $pad_width = floor(($scaled_w -$orig_even_w) / 2);
                    			$pad_x -= $extra0;
                    			$dims[0] -= 2 * $pad_width;
                    			$dims[0] += $extra0;
                    			$dims[1] += $extra1;
                    		*/
                    $vf .= 'pad=' . $scaled_w . ':' . $scaled_h . ':' . (floor(($scaled_w - $orig_even_w) / 2) - $extra0) . ':0';
                }
            }
            if (!floatcmp($orig_dims1, $scaled_h)) {
                if (floatgtr($orig_dims1, $scaled_h)) {
                    $vf .= 'crop=0:' . floor(($orig_dims1 - $scaled_h) / 2) . ':' . $scaled_w . ':' . $scaled_h;
                } else {
                    /*
                    $pad_y = $pad_height = floor(($scaled_h - $orig_dims1) / 2);
                    $pad_y -= $extra1;
                    $dims[1] -= 2 * $pad_height;
                    $dims[1] += $extra1;
                    $dims[0] += $extra0;
                    */
                    $vf .= 'pad=' . $scaled_w . ':' . $scaled_h . ':0:' . (floor(($scaled_h - $orig_dims1) / 2) - $extra1);
                }
            }
        }
        //$a['s'] = $dims[0] . 'x' . $dims[1];
    }
    if ($vf) {
        $vf .= ',';
    }
    $vf .= $scale;
    $a = array();
    $a['vf'] = $vf;
    return $a;
}
Exemple #11
0
function print_customer_balances()
{
    global $path_to_root, $systypes_array;
    $from = $_POST['PARAM_0'];
    $to = $_POST['PARAM_1'];
    $fromcust = $_POST['PARAM_2'];
    $show_balance = $_POST['PARAM_3'];
    $currency = $_POST['PARAM_4'];
    $no_zeros = $_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 ($fromcust == ALL_TEXT) {
        $cust = _('All');
    } else {
        $cust = get_customer_name($fromcust);
    }
    $dec = user_price_dec();
    if ($currency == ALL_TEXT) {
        $convert = true;
        $currency = _('Balances in Home Currency');
    } else {
        $convert = false;
    }
    if ($no_zeros) {
        $nozeros = _('Yes');
    } else {
        $nozeros = _('No');
    }
    $cols = array(0, 100, 130, 190, 250, 320, 385, 450, 515);
    $headers = array(_('Trans Type'), _('#'), _('Date'), _('Due Date'), _('Charges'), _('Credits'), _('Allocated'), _('Outstanding'));
    if ($show_balance) {
        $headers[7] = _('Balance');
    }
    $aligns = array('left', 'left', 'left', 'left', 'right', 'right', 'right', 'right');
    $params = array(0 => $comments, 1 => array('text' => _('Period'), 'from' => $from, 'to' => $to), 2 => array('text' => _('Customer'), 'from' => $cust, 'to' => ''), 3 => array('text' => _('Currency'), 'from' => $currency, 'to' => ''), 4 => array('text' => _('Suppress Zeros'), 'from' => $nozeros, 'to' => ''));
    $rep = new FrontReport(_('Customer Balances'), "CustomerBalances", user_pagesize(), 9, $orientation);
    if ($orientation == 'L') {
        recalculate_cols($cols);
    }
    $rep->Font();
    $rep->Info($params, $cols, $headers, $aligns);
    $rep->NewPage();
    $grandtotal = array(0, 0, 0, 0);
    $sql = "SELECT debtor_no, name, curr_code FROM " . TB_PREF . "debtors_master ";
    if ($fromcust != ALL_TEXT) {
        $sql .= "WHERE debtor_no=" . db_escape($fromcust);
    }
    $sql .= " ORDER BY name";
    $result = db_query($sql, "The customers could not be retrieved");
    while ($myrow = db_fetch($result)) {
        if (!$convert && $currency != $myrow['curr_code']) {
            continue;
        }
        $accumulate = 0;
        $rate = $convert ? get_exchange_rate_from_home_currency($myrow['curr_code'], Today()) : 1;
        $bal = get_open_balance($myrow['debtor_no'], $from, $convert);
        $init[0] = $init[1] = 0.0;
        $init[0] = round2(abs($bal['charges'] * $rate), $dec);
        $init[1] = round2(Abs($bal['credits'] * $rate), $dec);
        $init[2] = round2($bal['Allocated'] * $rate, $dec);
        if ($show_balance) {
            $init[3] = $init[0] - $init[1];
            $accumulate += $init[3];
        } else {
            $init[3] = round2($bal['OutStanding'] * $rate, $dec);
        }
        $res = get_transactions($myrow['debtor_no'], $from, $to);
        if ($no_zeros && db_num_rows($res) == 0) {
            continue;
        }
        $rep->fontSize += 2;
        $rep->TextCol(0, 2, $myrow['name']);
        if ($convert) {
            $rep->TextCol(2, 3, $myrow['curr_code']);
        }
        $rep->fontSize -= 2;
        $rep->TextCol(3, 4, _("Open Balance"));
        $rep->AmountCol(4, 5, $init[0], $dec);
        $rep->AmountCol(5, 6, $init[1], $dec);
        $rep->AmountCol(6, 7, $init[2], $dec);
        $rep->AmountCol(7, 8, $init[3], $dec);
        $total = array(0, 0, 0, 0);
        for ($i = 0; $i < 4; $i++) {
            $total[$i] += $init[$i];
            $grandtotal[$i] += $init[$i];
        }
        $rep->NewLine(1, 2);
        $rep->Line($rep->row + 4);
        if (db_num_rows($res) == 0) {
            $rep->NewLine(1, 2);
            continue;
        }
        while ($trans = db_fetch($res)) {
            if ($no_zeros && floatcmp($trans['TotalAmount'], $trans['Allocated']) == 0) {
                continue;
            }
            $rep->NewLine(1, 2);
            $rep->TextCol(0, 1, $systypes_array[$trans['type']]);
            $rep->TextCol(1, 2, $trans['reference']);
            $rep->DateCol(2, 3, $trans['tran_date'], true);
            if ($trans['type'] == ST_SALESINVOICE) {
                $rep->DateCol(3, 4, $trans['due_date'], true);
            }
            $item[0] = $item[1] = 0.0;
            if ($trans['type'] == ST_CUSTCREDIT || $trans['type'] == ST_CUSTPAYMENT || $trans['type'] == ST_BANKDEPOSIT) {
                $trans['TotalAmount'] *= -1;
            }
            if ($trans['TotalAmount'] > 0.0) {
                $item[0] = round2(abs($trans['TotalAmount']) * $rate, $dec);
                $rep->AmountCol(4, 5, $item[0], $dec);
                $accumulate += $item[0];
            } else {
                $item[1] = round2(Abs($trans['TotalAmount']) * $rate, $dec);
                $rep->AmountCol(5, 6, $item[1], $dec);
                $accumulate -= $item[1];
            }
            $item[2] = round2($trans['Allocated'] * $rate, $dec);
            $rep->AmountCol(6, 7, $item[2], $dec);
            if ($trans['type'] == ST_SALESINVOICE || $trans['type'] == ST_BANKPAYMENT) {
                $item[3] = $item[0] + $item[1] - $item[2];
            } else {
                $item[3] = $item[0] - $item[1] + $item[2];
            }
            if ($show_balance) {
                $rep->AmountCol(7, 8, $accumulate, $dec);
            } else {
                $rep->AmountCol(7, 8, $item[3], $dec);
            }
            for ($i = 0; $i < 4; $i++) {
                $total[$i] += $item[$i];
                $grandtotal[$i] += $item[$i];
            }
            if ($show_balance) {
                $total[3] = $total[0] - $total[1];
            }
        }
        $rep->Line($rep->row - 8);
        $rep->NewLine(2);
        $rep->TextCol(0, 3, _('Total'));
        for ($i = 0; $i < 4; $i++) {
            $rep->AmountCol($i + 4, $i + 5, $total[$i], $dec);
        }
        $rep->Line($rep->row - 4);
        $rep->NewLine(2);
    }
    $rep->fontSize += 2;
    $rep->TextCol(0, 3, _('Grand Total'));
    $rep->fontSize -= 2;
    if ($show_balance) {
        $grandtotal[3] = $grandtotal[0] - $grandtotal[1];
    }
    for ($i = 0; $i < 4; $i++) {
        $rep->AmountCol($i + 4, $i + 5, $grandtotal[$i], $dec);
    }
    $rep->Line($rep->row - 4);
    $rep->NewLine();
    $rep->End();
}