function print_check()
{
    global $path_to_root, $systypes_array, $print_invoice_no;
    // Get the payment
    $from = $_POST['PARAM_0'];
    $destination = $_POST['PARAM_1'];
    $trans_no = explode("-", $from);
    $dec = user_price_dec();
    if ($destination) {
        include_once $path_to_root . "/reporting/includes/excel_report.inc";
    } else {
        include_once $path_to_root . "/reporting/includes/pdf_report.inc";
    }
    $from_trans = get_remittance($trans_no[1], $trans_no[0]);
    // Get check information
    $total_amt = $from_trans['Total'];
    $date = sql2date($from_trans['tran_date']);
    $memo = get_comments_string($trans_no[1], $trans_no[0]);
    // Begin the report
    $rep = new FrontReport(_('Printable Check'), "PrintableCheck", user_pagesize());
    $rep->SetHeaderType(null);
    $rep->NewPage();
    // Set the font
    $rep->Font('', 'courier');
    $rep->fontSize = 12;
    //////////////////
    // Check portion
    $rep->NewLine(1, 0, 76);
    $rep->cols = array(63, 340, 470, 565);
    $rep->aligns = array('left', 'left', 'right', 'right');
    // Pay to
    $rep->TextCol(0, 1, $from_trans['supp_name']);
    // Date
    $rep->DateCol(1, 2, $rep->DatePrettyPrint($date, 0, 0));
    // Amount (numeric)
    $rep->TextCol(2, 3, '***' . number_format2(-$total_amt, $dec));
    // Amount (words)
    $rep->NewLine(1, 0, 23);
    $rep->TextCol(0, 2, $from_trans['curr_code'] . ": " . price_in_words(-$total_amt, ST_CHEQUE));
    // Memo
    $rep->NewLine(1, 0, 78);
    $rep->TextCol(0, 1, $memo);
    $rep->company = get_company_prefs();
    /////////////////////
    // Item details x 2
    for ($section = 1; $section <= 2; $section++) {
        $rep->fontSize = 12;
        // Move down to the correct section
        $rep->row = $section == 1 ? 505 : 255;
        $rep->cols = array(20, 340, 470, 588);
        $rep->aligns = array('left', 'left', 'right', 'right');
        // Pay to
        $rep->Font('b');
        $rep->TextCol(0, 1, $from_trans['supp_name']);
        $rep->Font();
        // Date
        $rep->DateCol(1, 2, $rep->DatePrettyPrint($date, 0, 0));
        // Amount (numeric)
        $rep->TextCol(2, 3, number_format2(-$total_amt, 2));
        // Add Trans # + Reference
        $rep->NewLine();
        if ($print_invoice_no == 0) {
            $tno = $from_trans['reference'];
        } else {
            $tno = $from_trans['trans_no'];
        }
        $rep->TextCol(0, 3, sprintf(_("Payment # %s - from Customer: %s - %s"), $tno, $from_trans['supp_account_no'], $rep->company['coy_name']));
        // Add memo
        $rep->NewLine();
        $rep->TextCol(0, 3, _("Memo: ") . $memo);
        // TODO: Do we want to set a limit on # of item details?  (Max is probably 6-7)
        // Get item details
        $result = get_allocations_for_remittance($from_trans['supplier_id'], $from_trans['type'], $from_trans['trans_no']);
        // Fill in details
        $rep->NewLine(2);
        $rep->fontSize = 10;
        // Use different columns now for the additional info
        $rep->cols = array(20, 160, 235, 290, 370, 480, 588);
        $rep->aligns = array('left', 'left', 'left', 'right', 'right', 'right');
        // Add headers
        $rep->Font('b');
        $rep->TextCol(0, 1, _("Type/Id"));
        $rep->TextCol(1, 2, _("Trans Date"));
        $rep->TextCol(2, 3, _("Due Date"));
        $rep->TextCol(3, 4, _("Total Amount"));
        $rep->TextCol(4, 5, _("Left to Allocate"));
        $rep->TextCol(5, 6, _("This Allocation"));
        $rep->NewLine();
        $rep->Font();
        $total_allocated = 0;
        while ($item = db_fetch($result)) {
            $rep->TextCol(0, 1, $systypes_array[$item['type']] . " " . $item['supp_reference']);
            $rep->TextCol(1, 2, sql2date($item['tran_date']));
            $rep->TextCol(2, 3, sql2date($item['due_date']));
            $rep->AmountCol(3, 4, $item['Total'], $dec);
            $rep->AmountCol(4, 5, $item['Total'] - $item['alloc'], $dec);
            $rep->AmountCol(5, 6, $item['amt'], $dec);
            $total_allocated += $item['amt'];
            $rep->NewLine(1, 0, $rep->lineHeight + 3);
            // Space it out
        }
        $rep->NewLine();
        $rep->TextCol(4, 5, _("Total Allocated"));
        $rep->AmountCol(5, 6, $total_allocated, $dec);
        $rep->NewLine();
        $rep->TextCol(4, 5, _("Left to Allocate"));
        $rep->AmountCol(5, 6, -$from_trans['Total'] - $total_allocated, $dec);
    }
    // end of section
    $rep->End();
}
Esempio n. 2
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();
    }
}
{
    $sql = "SELECT " . TB_PREF . "supp_trans.*, \n   \t\t(" . TB_PREF . "supp_trans.ov_amount+" . TB_PREF . "supp_trans.ov_gst+" . TB_PREF . "supp_trans.ov_discount) AS Total, \n   \t\t" . TB_PREF . "suppliers.supp_name,  " . TB_PREF . "suppliers.supp_account_no,\n   \t\t" . TB_PREF . "suppliers.curr_code, " . TB_PREF . "suppliers.payment_terms, " . TB_PREF . "suppliers.gst_no AS tax_id, \n   \t\t" . TB_PREF . "suppliers.address, " . TB_PREF . "suppliers.contact\n\t\tFROM " . TB_PREF . "supp_trans, " . TB_PREF . "suppliers\n\t\tWHERE " . TB_PREF . "supp_trans.supplier_id = " . TB_PREF . "suppliers.supplier_id\n\t\tAND " . TB_PREF . "supp_trans.type = " . db_escape($type) . "\n\t\tAND " . TB_PREF . "supp_trans.trans_no = " . db_escape($trans_no);
    $result = db_query($sql, "The remittance cannot be retrieved");
    if (db_num_rows($result) == 0) {
        return false;
    }
    return db_fetch($result);
}
function get_allocations_for_remittance($supplier_id, $type, $trans_no)
{
    $sql = get_alloc_supp_sql("amt, supp_reference, trans.alloc", "trans.trans_no = alloc.trans_no_to\n\t\tAND trans.type = alloc.trans_type_to\n\t\tAND alloc.trans_no_from=" . db_escape($trans_no) . "\n\t\tAND alloc.trans_type_from=" . db_escape($type) . "\n\t\tAND trans.supplier_id=" . db_escape($supplier_id), TB_PREF . "supp_allocations as alloc");
    $sql .= " ORDER BY trans_no";
    return db_query($sql, "Cannot retrieve alloc to transactions");
}
// Grab Cheque Information
$from_trans = get_remittance($trans_no[1], $trans_no[0]);
$company_currency = get_company_currency();
$show_currencies = false;
$show_both_amounts = false;
$show_currencies = $from_trans['curr_code'] != $company_currency;
$cheque = new FrontReport(_("Cheque Printing"), "cheque.pdf", user_pagesize(), 10);
$cheque->SetHeaderType(null);
$cheque->NewPage();
$cheque->Font();
$cheque->lineHeight = 16;
$cheque->row = $cheque->pageHeight - $cheque->topMargin;
$cheque->row -= 47;
//------------------------ col - row - spec's ------------
$col0 = 45;
// the first column
$col1 = 248;