function check_overdue($row) { global $trans_type; if ($trans_type == ST_SALESQUOTE) { return date1_greater_date2(Today(), sql2date($row['delivery_date'])); } else { return $row['type'] == 0 && date1_greater_date2(Today(), sql2date($row['ord_date'])) && $row['TotDelivered'] < $row['TotQuantity']; } }
function render($id, $title) { global $path_to_root; include_once $path_to_root . "/includes/ui.inc"; $end_date = date2sql(add_days(Today(), $this->days_future)); $role_id = $_SESSION["wa_current_user"]->access; $sql = "SELECT id, description, next_date FROM " . TB_PREF . "dashboard_reminders " . " WHERE next_date < '{$end_date}'" . " AND role_id = '{$role_id}'"; if ($this->data_filter != '') { $sql .= ' AND ' . $this->data_filter; } $sql .= " ORDER BY next_date"; $result = db_query($sql); br(); $th = array(_("Actioned"), _("Date"), _("Description")); start_table(TABLESTYLE, "id='reminder' width=98%"); table_header($th); $k = 0; //row colour counter while ($myrow = db_fetch($result)) { $nextdate = sql2date($myrow["next_date"]); if (date1_greater_date2(Today(), $nextdate)) { $extra = "class='reminder_overdue'"; } elseif (Today() == $nextdate) { $extra = "class='reminder_due'"; } else { $extra = "class='reminder'"; } alt_table_row_color($k); $js = 'setTimeout(function(){updateToDoData(' . $myrow["id"] . ');}, 0);'; check_cells(null, null, null, $js); label_cell($nextdate, $extra); label_cell("<pre>" . $myrow["description"] . "</pre>", $extra); end_row(); } end_table(1); }
function check_data() { if (!is_date($_POST['from_date']) || is_date_in_fiscalyears($_POST['from_date'])) { display_error(_("Invalid BEGIN date in fiscal year.")); set_focus('from_date'); return false; } if (!is_date($_POST['to_date']) || is_date_in_fiscalyears($_POST['to_date'])) { display_error(_("Invalid END date in fiscal year.")); set_focus('to_date'); return false; } if (!check_begin_end_date($_POST['from_date'], $_POST['to_date'])) { display_error(_("Invalid BEGIN or END date in fiscal year.")); set_focus('from_date'); return false; } if (date1_greater_date2($_POST['from_date'], $_POST['to_date'])) { display_error(_("BEGIN date bigger than END date.")); set_focus('from_date'); return false; } return true; }
function check_data() { if (!isset($selected_id)) { $from = $_POST['from_date']; } else { $from = $selected_id; } if (!is_date($from)) { display_error(tr("Invalid BEGIN date in fiscal year.")); set_focus('from_date'); return false; } if (!is_date($_POST['to_date'])) { display_error(tr("Invalid END date in fiscal year.")); set_focus('to_date'); return false; } if (date1_greater_date2($from, $_POST['to_date'])) { display_error(tr("BEGIN date bigger than END date.")); set_focus('from_date'); return false; } return true; }
date_cells(_("Invoice date:"), 'date', ''); end_row(); end_table(); start_table(TABLESTYLE, "width=70%"); $th = array(_("Description"), _("Template No"), _("Customer"), _("Branch") . "/" . _("Group"), _("Days"), _("Monthly"), _("Begin"), _("End"), _("Last Created"), ""); table_header($th); $k = 0; $today = add_days($_POST['date'], 1); $due = false; while ($myrow = db_fetch($result)) { $begin = sql2date($myrow["begin"]); $end = sql2date($myrow["end"]); $last_sent = calculate_from($myrow); $due_date = add_months($last_sent, $myrow['monthly']); $due_date = add_days($due_date, $myrow['days']); $overdue = date1_greater_date2($today, $due_date) && date1_greater_date2($today, $begin) && date1_greater_date2($end, $today); if ($overdue) { start_row("class='overduebg'"); $due = true; } else { alt_table_row_color($k); } label_cell($myrow["description"]); label_cell(get_customer_trans_view_str(30, $myrow["order_no"])); if ($myrow["debtor_no"] == 0) { label_cell(""); label_cell(get_sales_group_name($myrow["group_no"])); } else { label_cell(get_customer_name($myrow["debtor_no"])); label_cell(get_branch_name($myrow['group_no'])); }
function show_results() { global $path_to_root, $systypes_array; if (!isset($_POST["account"])) { $_POST["account"] = null; } $act_name = $_POST["account"] ? get_gl_account_name($_POST["account"]) : ""; $dim = get_company_pref('use_dimension'); /*Now get the transactions */ if (!isset($_POST['Dimension'])) { $_POST['Dimension'] = 0; } if (!isset($_POST['Dimension2'])) { $_POST['Dimension2'] = 0; } $result = get_gl_transactions($_POST['TransFromDate'], $_POST['TransToDate'], -1, $_POST["account"], $_POST['Dimension'], $_POST['Dimension2'], null, input_num('amount_min'), input_num('amount_max')); $colspan = $dim == 2 ? "6" : ($dim == 1 ? "5" : "4"); if ($_POST["account"] != null) { display_heading($_POST["account"] . " " . $act_name); } // Only show balances if an account is specified AND we're not filtering by amounts $show_balances = $_POST["account"] != null && input_num("amount_min") == 0 && input_num("amount_max") == 0; start_table(TABLESTYLE); $first_cols = array(_("Type"), _("#"), _("Date")); if ($_POST["account"] == null) { $account_col = array(_("Account")); } else { $account_col = array(); } if ($dim == 2) { $dim_cols = array(_("Dimension") . " 1", _("Dimension") . " 2"); } else { if ($dim == 1) { $dim_cols = array(_("Dimension")); } else { $dim_cols = array(); } } if ($show_balances) { $remaining_cols = array(_("Person/Item"), _("Debit"), _("Credit"), _("Balance"), _("Memo")); } else { $remaining_cols = array(_("Person/Item"), _("Debit"), _("Credit"), _("Memo")); } $th = array_merge($first_cols, $account_col, $dim_cols, $remaining_cols); table_header($th); if ($_POST["account"] != null && is_account_balancesheet($_POST["account"])) { $begin = ""; } else { $begin = get_fiscalyear_begin_for_date($_POST['TransFromDate']); if (date1_greater_date2($begin, $_POST['TransFromDate'])) { $begin = $_POST['TransFromDate']; } $begin = add_days($begin, -1); } $bfw = 0; if ($show_balances) { $bfw = get_gl_balance_from_to($begin, $_POST['TransFromDate'], $_POST["account"], $_POST['Dimension'], $_POST['Dimension2']); start_row("class='inquirybg'"); label_cell("<b>" . _("Opening Balance") . " - " . $_POST['TransFromDate'] . "</b>", "colspan={$colspan}"); display_debit_or_credit_cells($bfw, true); label_cell(""); label_cell(""); end_row(); } $running_total = $bfw; $j = 1; $k = 0; //row colour counter while ($myrow = db_fetch($result)) { alt_table_row_color($k); $running_total += $myrow["amount"]; $trandate = sql2date($myrow["tran_date"]); label_cell($systypes_array[$myrow["type"]]); label_cell(get_gl_view_str($myrow["type"], $myrow["type_no"], $myrow["type_no"], true)); label_cell($trandate); if ($_POST["account"] == null) { label_cell($myrow["account"] . ' ' . get_gl_account_name($myrow["account"])); } if ($dim >= 1) { label_cell(get_dimension_string($myrow['dimension_id'], true)); } if ($dim > 1) { label_cell(get_dimension_string($myrow['dimension2_id'], true)); } label_cell(payment_person_name($myrow["person_type_id"], $myrow["person_id"])); display_debit_or_credit_cells($myrow["amount"]); if ($show_balances) { amount_cell($running_total); } if ($myrow['memo_'] == "") { $myrow['memo_'] = get_comments_string($myrow['type'], $myrow['type_no']); } label_cell($myrow['memo_']); end_row(); $j++; if ($j == 12) { $j = 1; table_header($th); } } //end of while loop if ($show_balances) { start_row("class='inquirybg'"); label_cell("<b>" . _("Ending Balance") . " - " . $_POST['TransToDate'] . "</b>", "colspan={$colspan}"); display_debit_or_credit_cells($running_total, true); label_cell(""); label_cell(""); end_row(); } end_table(2); if (db_num_rows($result) == 0) { display_note(_("No general ledger transactions have been created for the specified criteria."), 0, 1); } }
function display_type($type, $typename, &$dec, &$rep, $from, $to, $zero, $balances, $dimension, $dimension2) { global $pdeb, $pcre, $cdeb, $ccre, $tdeb, $tcre, $pbal, $cbal, $tbal, $clear_trial_balance_opening; $printtitle = 0; //Flag for printing type name //Get Accounts directly under this group/type $accounts = get_gl_accounts(null, null, $type); $begin = get_fiscalyear_begin_for_date($from); if (date1_greater_date2($begin, $from)) { $begin = $from; } $begin = add_days($begin, -1); while ($account = db_fetch($accounts)) { //Print Type Title if it has atleast one non-zero account if (!$printtitle) { $rep->row -= 4; $rep->TextCol(0, 8, _("Group") . " - " . $type . " - " . $typename); $printtitle = 1; $rep->row -= 4; $rep->Line($rep->row); $rep->NewLine(); } // FA doesn't really clear the closed year, therefore the brought forward balance includes all the transactions from the past, even though the balance is null. // If we want to remove the balanced part for the past years, this option removes the common part from from the prev and tot figures. if (@$clear_trial_balance_opening) { $open = get_balance($account["account_code"], $dimension, $dimension2, $begin, $begin, false, true); $offset = min($open['debit'], $open['credit']); } else { $offset = 0; } $prev = get_balance($account["account_code"], $dimension, $dimension2, $begin, $from, false, false); $curr = get_balance($account["account_code"], $dimension, $dimension2, $from, $to, true, true); $tot = get_balance($account["account_code"], $dimension, $dimension2, $begin, $to, false, true); if ($zero == 0 && !$prev['balance'] && !$curr['balance'] && !$tot['balance']) { continue; } $rep->TextCol(0, 1, $account['account_code']); $rep->TextCol(1, 2, $account['account_name']); if ($balances != 0) { if ($prev['balance'] >= 0.0) { $rep->AmountCol(2, 3, $prev['balance'], $dec); } else { $rep->AmountCol(3, 4, abs($prev['balance']), $dec); } if ($curr['balance'] >= 0.0) { $rep->AmountCol(4, 5, $curr['balance'], $dec); } else { $rep->AmountCol(5, 6, abs($curr['balance']), $dec); } if ($tot['balance'] >= 0.0) { $rep->AmountCol(6, 7, $tot['balance'], $dec); } else { $rep->AmountCol(7, 8, abs($tot['balance']), $dec); } } else { $rep->AmountCol(2, 3, $prev['debit'] - $offset, $dec); $rep->AmountCol(3, 4, $prev['credit'] - $offset, $dec); $rep->AmountCol(4, 5, $curr['debit'], $dec); $rep->AmountCol(5, 6, $curr['credit'], $dec); $rep->AmountCol(6, 7, $tot['debit'] - $offset, $dec); $rep->AmountCol(7, 8, $tot['credit'] - $offset, $dec); $pdeb += $prev['debit'] - $offset; $pcre += $prev['credit'] - $offset; $cdeb += $curr['debit']; $ccre += $curr['credit']; $tdeb += $tot['debit'] - $offset; $tcre += $tot['credit'] - $offset; } $pbal += $prev['balance']; $cbal += $curr['balance']; $tbal += $tot['balance']; $rep->NewLine(); if ($rep->row < $rep->bottomMargin + $rep->lineHeight) { $rep->Line($rep->row - 2); $rep->NewPage(); } } //Get Account groups/types under this group/type $result = get_account_types(false, false, $type); while ($accounttype = db_fetch($result)) { //Print Type Title if has sub types and not previously printed if (!$printtitle) { $rep->row -= 4; $rep->TextCol(0, 8, _("Group") . " - " . $type . " - " . $typename); $printtitle = 1; $rep->row -= 4; $rep->Line($rep->row); $rep->NewLine(); } display_type($accounttype["id"], $accounttype["name"] . ' (' . $typename . ')', $dec, $rep, $from, $to, $zero, $balances, $dimension, $dimension2); } }
function check_overdue($row) { return date1_greater_date2(Today(), sql2date($row["due_date"])) && $row["Outstanding"] != 0; }
function print_statements() { global $path_to_root, $systypes_array; include_once $path_to_root . "/reporting/includes/pdf_report2.inc"; $from = date2sql($_POST['PARAM_0']); $to = date2sql($_POST['PARAM_1']); $customer = $_POST['PARAM_2']; $currency = $_POST['PARAM_3']; $email = $_POST['PARAM_4']; $comments = $_POST['PARAM_5']; $orientation = $_POST['PARAM_6']; $orientation = $orientation ? 'L' : 'P'; $dec = 2; $cols = array(4, 64, 180, 250, 300, 350, 400, 480); //$headers in doctext.inc $aligns = array('left', 'left', 'left', 'right', 'right', 'right', 'right', 'right'); $params = array('comments' => $comments); $cur = get_company_pref('curr_default'); $PastDueDays1 = get_company_pref('past_due_days'); $PastDueDays2 = 2 * $PastDueDays1; if ($email == 0) { $rep = new FrontReport(_('CUSTOMER ACCOUNT STATEMENT'), "StatementBulk", user_pagesize(), 9, $orientation); } if ($orientation == 'L') { recalculate_cols($cols); } $sql = "SELECT b.debtor_no, b.name AS DebtorName, b.address, b.tax_id, b.curr_code, cust.salesman, \n\tcurdate() AS tran_date, CONCAT (d.name, d.name2) AS contactPerson, d.phone, d.phone2 \n\tFROM " . TB_PREF . "debtors_master b INNER JOIN\n" . TB_PREF . "crm_contacts c on b.debtor_no=c.entity_id INNER JOIN " . TB_PREF . "crm_persons d on c.person_id=d.id\nINNER JOIN " . TB_PREF . "cust_branch cust on b.debtor_no=cust.debtor_no"; if ($customer != ALL_TEXT) { $sql .= " WHERE c.type='customer' and cust.salesman = " . db_escape($customer); } else { $sql .= " where c.type='customer' and cust.salesman = " . db_escape($customer) . " ORDER by b.name"; } $result = db_query($sql, "The customers could not be retrieved"); while ($debtor_row = db_fetch($result)) { $date = date('Y-m-d'); if ($from != $to) { // find the latest point where the balance was null $start = findLatestNullDate($debtor_row['debtor_no'], $from); // but not earlier than the $to date. if (date1_greater_date2(sql2date($start), sql2date($to))) { $start = $to; } if (date1_greater_date2(sql2date($from), sql2date($start))) { $start = $from; } } else { $start = $from; } $debtor_row['order_'] = ""; $TransResult = getTransactions($debtor_row['debtor_no'], $start, $date); $baccount = get_default_bank_account($debtor_row['curr_code']); $params['bankaccount'] = $baccount['id']; if (db_num_rows($TransResult) == 0) { continue; } if ($email == 1) { $rep = new FrontReport("CUSTOMER ACCOUNT STATEMENT", "", user_pagesize(), 9, $orientation); $rep->title = _('STATEMENT OF ACCOUNT'); $rep->filename = "Statement" . $debtor_row['debtor_no'] . ".pdf"; $rep->Info($params, $cols, null, $aligns); } $rep->filename = "ST-" . strtr($debtor_row['DebtorName'], " '", "__") . "--" . strtr(Today(), "/", "-") . ".pdf"; $contacts = get_customer_contacts($debtor_row['debtor_no'], 'invoice'); $rep->SetHeaderType('customheader'); $rep->currency = $cur; $rep->Font(); $rep->Info(null, $cols, null, $aligns); $rep->SetCommonData($debtor_row, null, null, $baccount, ST_STATEMENT, $contacts); $rep->NewPage(); $doctype = ST_STATEMENT; //$rep->TextCol(0,4,"yeah"); $current = false; $balance = getInitialBalance($debtor_row['debtor_no'], $start); if (true || Abs($balance) > 1.0E-6) { if (Abs($balance) < 1.0E-6) { $rep->SetTextColor(190, 190, 190); } else { if ($balance > 0) { $rep->SetTextColor(190, 0, 0); } } $rep->SetTextColor(0, 0, 0); } $overdue = 0; $prev = ''; $gross_amount = 0; $gross_amount2 = 0; $payment_tot = 0; $tots = 0; $discount_amount = 0; $percent = 0; while ($transaction_row = db_fetch($TransResult)) { if ($myrow['IsVoid'] == '') { $company_data = get_company_prefs(); $branch = get_branch($transaction_row["branch_code"]); $branch_data = get_branch_accounts($transaction_row['branch_code']); $dt = get_discount($branch_data['sales_discount_account'], $transaction_row['type'], $transaction_row['trans_no']); $DisplayTotal = number_format2(Abs($transaction_row["TotalAmount"] + $dt), $dec); $DisplayAlloc = number_format2($transaction_row["Allocated"], $dec); $DisplayNet = number_format2($transaction_row["TotalAmount"] - $transaction_row["Allocated"], $dec); /*if ($dt != 0 && $transaction_row['type'] == ST_SALESINVOICE || $transaction_row['type'] == ST_CUSTCREDIT) { $discount_amount += $dt; $ctr = $transaction_row['bulk_discount']; }*/ $amount = $transaction_row["TotalAmount"] + $dt; $balance += $transaction_row["TotalAmount"]; $invoice_no = get_custom_no($transaction_row['trans_no'], $transaction_row['type']); $enter1 = 0; if ($systypes_array[$transaction_row['type']] == "Customer Payment") { $open_pay = get_payment_invoice_details($transaction_row["trans_no"], ST_CUSTPAYMENT); if ($open_pay) { $stat2 = false; } else { $stat2 = true; $payment_tot += $amount; $text = "pr#"; } } if ($systypes_array[$transaction_row['type']] == "Sales Invoice") { if ($transaction_row['ov_amount'] > $transaction_row['alloc'] || $transaction_row['alloc'] == 0) { $discount_amount += $dt; $ctr = $transaction_row['bulk_discount']; $gross_amount += $amount; $text = ''; $stat3 = true; } else { $stat3 = false; } } if ($systypes_array[$transaction_row['type']] == "Customer Credit Note") { $open = get_sales_invoice_details($transaction_row['order_'], ST_SALESINVOICE); if ($open) { $stat = false; } else { $discount_amount += $dt; $ctr = $transaction_row['bulk_discount']; $gross_amount2 += $amount; $stat = true; } $text = "cm#"; } $current = $text; $tot = $gross_amount + $gross_amount2 - $discount_amount; if ($current != '') { if ($prev == $current) { } else { if ($prev == "" && $text == "cm#" && $stat) { $rep->NewLine(); $rep->TextCol(1, 2, "Less Returns"); $rep->NewLine(); } if ($text == 'pr#' && $prev == "cm#" && $stat2) { $rep->AmountCol(6, 7, $tot, 2); $rep->NewLine(2); $rep->TextCol(1, 2, "Less Payments:"); $rep->NewLine(); } if ($prev == '' && $text == 'pr#' && $stat2) { $rep->TextCol(1, 2, "Less Payments:"); $rep->NewLine(); } } $prev = $current; } if ($transaction_row['type'] == ST_SALESINVOICE && $stat3) { $rep->TextCol(1, 2, $text . $invoice_no, -2); $rep->TextCol(0, 3, sql2date($transaction_row['tran_date']), -2); $rep->TextCol(3, 4, $DisplayTotal, -2); $rep->NewLine(); } if ($transaction_row['type'] == ST_CUSTCREDIT && $stat) { $rep->TextCol(1, 2, $text . $invoice_no, -2); $rep->TextCol(0, 3, sql2date($transaction_row['tran_date']), -2); $rep->TextCol(3, 4, $DisplayTotal, -2); $rep->NewLine(); } if ($transaction_row['type'] == ST_CUSTPAYMENT && $stat2) { if ($invoice_no == "") { $rep->TextCol(1, 2, $text . $transaction_row['reference'], -2); } else { $rep->TextCol(1, 2, $text . $invoice_no, -2); } $rep->TextCol(0, 3, sql2date($transaction_row['tran_date']), -2); $rep->TextCol(5, 6, $DisplayTotal, -2); $rep->NewLine(); } $rep->SetTextColor(0, 0, 0); //$rep->NewLine(); if ($rep->row < $rep->bottomMargin + 10 * $rep->lineHeight) { $rep->NewPage(); } } } if (!$current) { $overdue = $balance; $balance = 0; } $rep->NewLine(); $net = $gross_amount - abs($gross_amount2); $percent = $ctr / $net * 100; $per = number_format2($percent, 2); if ($per != 0) { $rep->TextCol(1, 2, "Less " . $ctr . "% discount"); $rep->AmountCol(5, 6, $discount_amount, 2); } $rep->SetTextColor(0, 0, 0); $rep->fontSize += 2; $rep->NewLine(5); $rep->TextCol(1, 2, 'Amount Due'); //$rep->TextCol(6,7, " ____________", -2); if ($payment_tot != 0) { $rep->TextCol(6, 7, number_format2($tot - abs($payment_tot), $dec)); } else { $rep->AmountCol(6, 7, $tot, 2); } $rep->NewLine(5); $rep->TextCol(2, 4, "Verified & Checked by:"); $rep->TextCol(4, 6, "___________________"); $rep->NewLine(); $rep->TextCol(4, 6, "Credit & Collection"); $rep->fontSize -= 2; } //$rep->NewPage(); if ($email == 0) { $rep->End(); } }
$th[] = ''; $th[] = ''; } table_header($th); start_form(); $j = 1; $k = 0; //row colour counter $overdue_items = false; while ($myrow = db_fetch($result)) { $view_page = get_customer_trans_view_str(systypes::sales_order(), $myrow["order_no"]); $formated_del_date = sql2date($myrow["delivery_date"]); $formated_order_date = sql2date($myrow["ord_date"]); // $not_closed = $myrow['type'] && ($myrow["TotDelivered"] < $myrow["TotQuantity"]); // if overdue orders, then highlight as so if ($myrow['type'] == 0 && date1_greater_date2(Today(), $formated_del_date)) { start_row("class='overduebg'"); $overdue_items = true; } else { alt_table_row_color($k); } label_cell($view_page); label_cell($myrow["name"]); label_cell($myrow["br_name"]); if ($_POST['order_view_mode'] == 'InvoiceTemplates' || $_POST['order_view_mode'] == 'DeliveryTemplates') { label_cell($myrow["comments"]); } else { label_cell($myrow["customer_ref"]); } label_cell($formated_order_date); label_cell($formated_del_date);
if ($showdims) { $th = array(tr("Period"), tr("Amount"), tr("Dim. incl."), tr("Last Year")); } else { $th = array(tr("Period"), tr("Amount"), tr("Last Year")); } table_header($th); $year = $_POST['fyear']; $sql = "SELECT * FROM fiscal_year WHERE id={$year}"; $result = db_query($sql, "could not get current fiscal year"); $fyear = db_fetch($result); $begin = sql2date($fyear['begin']); $end = sql2date($fyear['end']); hidden('begin', $begin); hidden('end', $end); $total = $btotal = $ltotal = 0; for ($i = 0, $date_ = $begin; date1_greater_date2($end, $date_); $i++) { start_row(); $_POST['amount' . $i] = number_format2(get_only_budget_trans_from_to($date_, $date_, $_POST['account'], $_POST['dim1'], $_POST['dim2']), 0); label_cell($date_); if (!isset($_POST['amount' . $i])) { $_POST['amount' . $i] = '0'; } amount_cells(null, 'amount' . $i, null, 15, null, 0); if ($showdims) { $d = get_budget_trans_from_to($date_, $date_, $_POST['account'], $_POST['dim1'], $_POST['dim2']); label_cell(number_format2($d, 0), "nowrap align=right"); $btotal += $d; } $lamount = get_gl_trans_from_to(add_years($date_, -1), add_years(end_month($date_), -1), $_POST['account'], $_POST['dim1'], $_POST['dim2']); $total += input_num('amount' . $i); $ltotal += $lamount;
function render($id, $title) { global $path_to_root; include_once $path_to_root . "/reporting/includes/class.graphic.inc"; $today = date2sql(Today()); if (!isset($data->days_past)) { $this->days_past = 30; } if (!isset($data->days_future)) { $this->days_future = 30; } $sql = "SELECT bank_act, bank_account_name, trans_date, amount" . " FROM (" . " SELECT bank_act, bank_account_name, null trans_date, SUM(amount) amount" . " FROM " . TB_PREF . "bank_trans bt" . " INNER JOIN " . TB_PREF . "bank_accounts ba ON bt.bank_act = ba.id" . " WHERE bank_act = " . $this->bank_act . " AND trans_date < now() - INTERVAL " . $this->days_past . " DAY" . " GROUP BY bank_act, bank_account_name" . " UNION ALL" . " SELECT bank_act, bank_account_name, trans_date, SUM(amount) amount" . " FROM 0_bank_trans bt" . " INNER JOIN " . TB_PREF . "bank_accounts ba ON bt.bank_act = ba.id" . " WHERE bank_act = " . $this->bank_act . " AND trans_date < now() + INTERVAL " . $this->days_future . " DAY" . " AND trans_date > now() - INTERVAL " . $this->days_past . " DAY" . " GROUP BY bank_act, trans_date, bank_account_name" . " ) trans" . " ORDER BY bank_account_name, trans_date"; $result = db_query($sql); $rows = array(); //flag is not needed $flag = true; $table = array(); $table['cols'] = array(array('label' => 'Date', 'type' => 'string'), array('label' => 'Balance', 'type' => 'number')); $rows = array(); $total = 0; $last_day = 0; $date = add_days(Today(), -$this->days_past); $balance_date = $date; while ($r = db_fetch_assoc($result)) { if ($r['trans_date'] == null) { $total = $r['amount']; } else { $balance_date = sql2date($r['trans_date']); while (date1_greater_date2($balance_date, $date)) { $temp = array(); $temp[] = array('v' => (string) $date, 'f' => $date); $temp[] = array('v' => (double) $total, 'f' => number_format2($total, user_price_dec())); $rows[] = array('c' => $temp); $date = add_days($date, 1); } $total += $r['amount']; $temp = array(); $temp[] = array('v' => (string) $balance_date, 'f' => $balance_date); $temp[] = array('v' => (double) $total, 'f' => number_format2($total, user_price_dec())); $rows[] = array('c' => $temp); $date = $balance_date; } } $end_date = add_days(Today(), $this->days_future); while (date1_greater_date2($end_date, $date)) { $temp = array(); $temp[] = array('v' => (string) $date, 'f' => $date); $temp[] = array('v' => (double) $total, 'f' => number_format2($total, user_price_dec())); $rows[] = array('c' => $temp); $last_day++; $date = add_days($date, 1); } $table['rows'] = $rows; $jsonTable = json_encode($table); $js = "google.load('visualization', '1', {'packages':['corechart','table']});\ngoogle.setOnLoadCallback(drawChart" . $id . ");\nfunction drawChart" . $id . "() {\n var data = new google.visualization.DataTable(" . $jsonTable . ");\n var options = {"; if ($this->graph_type != 'Table') { $js .= "height: 300, "; } $js .= "title: '" . $title . "'\n };\n var chart" . $id . " = new google.visualization." . $this->graph_type . "(document.getElementById('widget_div_" . $id . "'));\n chart" . $id . ".draw(data, options);\n}"; add_js_source($js); }
function display_trial_balance($type, $typename) { global $path_to_root; global $k, $pdeb, $pcre, $cdeb, $ccre, $tdeb, $tcre, $pbal, $cbal, $tbal; $printtitle = 0; //Flag for printing type name $k = 0; //$accounts = get_gl_accounts(); //Get Accounts directly under this group/type $accounts = get_gl_accounts(null, null, $type); $begin = get_fiscalyear_begin_for_date($_POST['TransFromDate']); //$begin = begin_fiscalyear(); if (date1_greater_date2($begin, $_POST['TransFromDate'])) { $begin = $_POST['TransFromDate']; } $begin = add_days($begin, -1); while ($account = db_fetch($accounts)) { //Print Type Title if it has atleast one non-zero account if ($type == 3502) { continue; } if (!$printtitle) { start_row("class='inquirybg' style='font-weight:bold'"); label_cell(_("Group") . " - " . $type . " - " . $typename, "colspan=8"); end_row(); $printtitle = 1; } $prev = get_balance($account["account_code"], $_POST['Dimension'], $_POST['Dimension2'], $begin, $_POST['TransFromDate'], false, false); $curr = get_balance($account["account_code"], $_POST['Dimension'], $_POST['Dimension2'], $_POST['TransFromDate'], $_POST['TransToDate'], true, true); $tot = get_balance($account["account_code"], $_POST['Dimension'], $_POST['Dimension2'], $begin, $_POST['TransToDate'], false, true); if (check_value("NoZero") && !$prev['balance'] && !$curr['balance'] && !$tot['balance']) { continue; } alt_table_row_color($k); $url = "<a href='{$path_to_root}/gl/inquiry/gl_account_inquiry.php?TransFromDate=" . $_POST["TransFromDate"] . "&TransToDate=" . $_POST["TransToDate"] . "&account=" . $account["account_code"] . "&Dimension=" . $_POST["Dimension"] . "&Dimension2=" . $_POST["Dimension2"] . "'>" . $account["account_code"] . "</a>"; label_cell($url); label_cell($account["account_name"]); if (check_value('Balance')) { display_debit_or_credit_cells($prev['balance']); display_debit_or_credit_cells($curr['balance']); display_debit_or_credit_cells($tot['balance']); } else { amount_cell($prev['debit']); amount_cell($prev['credit']); amount_cell($curr['debit']); amount_cell($curr['credit']); amount_cell($tot['debit']); amount_cell($tot['credit']); $pdeb += $prev['debit']; $pcre += $prev['credit']; $cdeb += $curr['debit']; $ccre += $curr['credit']; $tdeb += $tot['debit']; $tcre += $tot['credit']; } $pbal += $prev['balance']; $cbal += $curr['balance']; $tbal += $tot['balance']; end_row(); } //Get Account groups/types under this group/type $result = get_account_types(false, false, $type); while ($accounttype = db_fetch($result)) { //Print Type Title if has sub types and not previously printed if (!$printtitle) { start_row("class='inquirybg' style='font-weight:bold'"); label_cell(_("Group") . " - " . $type . " - " . $typename, "colspan=8"); end_row(); $printtitle = 1; } display_trial_balance($accounttype["id"], $accounttype["name"] . ' (' . $typename . ')'); } }
function display_trial_balance($type, $typename) { global $path_to_root, $clear_trial_balance_opening; global $k, $pdeb, $pcre, $cdeb, $ccre, $tdeb, $tcre, $pbal, $cbal, $tbal; $printtitle = 0; //Flag for printing type name $k = 0; //$accounts = get_gl_accounts(); //Get Accounts directly under this group/type $accounts = get_gl_accounts(null, null, $type); $begin = get_fiscalyear_begin_for_date($_POST['TransFromDate']); //$begin = begin_fiscalyear(); if (date1_greater_date2($begin, $_POST['TransFromDate'])) { $begin = $_POST['TransFromDate']; } $begin = add_days($begin, -1); while ($account = db_fetch($accounts)) { //Print Type Title if it has atleast one non-zero account if (!$printtitle) { start_row("class='inquirybg' style='font-weight:bold'"); label_cell(_("Group") . " - " . $type . " - " . $typename, "colspan=8"); end_row(); $printtitle = 1; } // FA doesn't really clear the closed year, therefore the brought forward balance includes all the transactions from the past, even though the balance is null. // If we want to remove the balanced part for the past years, this option removes the common part from from the prev and tot figures. if (@$clear_trial_balance_opening) { $open = get_balance($account["account_code"], $_POST['Dimension'], $_POST['Dimension2'], $begin, $begin, false, true); $offset = min($open['debit'], $open['credit']); } else { $offset = 0; } $prev = get_balance($account["account_code"], $_POST['Dimension'], $_POST['Dimension2'], $begin, $_POST['TransFromDate'], false, false); $curr = get_balance($account["account_code"], $_POST['Dimension'], $_POST['Dimension2'], $_POST['TransFromDate'], $_POST['TransToDate'], true, true); $tot = get_balance($account["account_code"], $_POST['Dimension'], $_POST['Dimension2'], $begin, $_POST['TransToDate'], false, true); if (check_value("NoZero") && !$prev['balance'] && !$curr['balance'] && !$tot['balance']) { continue; } alt_table_row_color($k); $url = "<a href='{$path_to_root}/gl/inquiry/gl_account_inquiry.php?TransFromDate=" . $_POST["TransFromDate"] . "&TransToDate=" . $_POST["TransToDate"] . "&account=" . $account["account_code"] . "&Dimension=" . $_POST["Dimension"] . "&Dimension2=" . $_POST["Dimension2"] . "'>" . $account["account_code"] . "</a>"; label_cell($url); label_cell($account["account_name"]); if (check_value('Balance')) { display_debit_or_credit_cells($prev['balance']); display_debit_or_credit_cells($curr['balance']); display_debit_or_credit_cells($tot['balance']); } else { amount_cell($prev['debit'] - $offset); amount_cell($prev['credit'] - $offset); amount_cell($curr['debit']); amount_cell($curr['credit']); amount_cell($tot['debit'] - $offset); amount_cell($tot['credit'] - $offset); $pdeb += $prev['debit']; $pcre += $prev['credit']; $cdeb += $curr['debit']; $ccre += $curr['credit']; $tdeb += $tot['debit']; $tcre += $tot['credit']; } $pbal += $prev['balance']; $cbal += $curr['balance']; $tbal += $tot['balance']; end_row(); } //Get Account groups/types under this group/type $result = get_account_types(false, false, $type); while ($accounttype = db_fetch($result)) { //Print Type Title if has sub types and not previously printed if (!$printtitle) { start_row("class='inquirybg' style='font-weight:bold'"); label_cell(_("Group") . " - " . $type . " - " . $typename, "colspan=8"); end_row(); $printtitle = 1; } display_trial_balance($accounttype["id"], $accounttype["name"] . ' (' . $typename . ')'); } }
function print_statements() { global $path_to_root, $systypes_array; include_once $path_to_root . "/reporting/includes/pdf_report.inc"; $from = date2sql($_POST['PARAM_0']); $to = date2sql($_POST['PARAM_1']); $customer = $_POST['PARAM_2']; $currency = $_POST['PARAM_3']; $email = $_POST['PARAM_4']; $comments = $_POST['PARAM_5']; $orientation = $_POST['PARAM_6']; $orientation = $orientation ? 'L' : 'P'; $dec = user_price_dec(); $cols = array(4, 64, 180, 250, 320, 385, 450, 515); //$headers in doctext.inc $aligns = array('left', 'left', 'left', 'left', 'right', 'right', 'right', 'right'); $params = array('comments' => $comments); $cur = get_company_pref('curr_default'); $PastDueDays1 = get_company_pref('past_due_days'); $PastDueDays2 = 2 * $PastDueDays1; if ($email == 0) { $rep = new FrontReport(_('CUSTOMER ACCOUNT STATEMENT'), "StatementBulk", user_pagesize(), 9, $orientation); } if ($orientation == 'L') { recalculate_cols($cols); } $sql = "SELECT b.debtor_no, b.name AS DebtorName, b.address, b.tax_id, b.curr_code, curdate() AS tran_date, CONCAT (d.name, d.name2) AS contactPerson, d.phone, d.phone2 FROM " . TB_PREF . "debtors_master b INNER JOIN\n" . TB_PREF . "crm_contacts c on b.debtor_no=c.entity_id INNER JOIN " . TB_PREF . "crm_persons d on c.person_id=d.id"; if ($customer != ALL_TEXT) { $sql .= " WHERE b.debtor_no = " . db_escape($customer); } else { $sql .= " ORDER by b.name"; } $result = db_query($sql, "The customers could not be retrieved"); while ($debtor_row = db_fetch($result)) { $date = date('Y-m-d'); if ($from != $to) { // find the latest point where the balance was null $start = findLatestNullDate($debtor_row['debtor_no'], $from); // but not earlier than the $to date. if (date1_greater_date2(sql2date($start), sql2date($to))) { $start = $to; } if (date1_greater_date2(sql2date($from), sql2date($start))) { $start = $from; } } else { $start = $from; } $debtor_row['order_'] = ""; $TransResult = getTransactions($debtor_row['debtor_no'], $start, $date); $baccount = get_default_bank_account($debtor_row['curr_code']); $params['bankaccount'] = $baccount['id']; if (db_num_rows($TransResult) == 0) { continue; } if ($email == 1) { $rep = new FrontReport("CUSTOMER ACCOUNT STATEMENT", "", user_pagesize(), 9, $orientation); $rep->title = _('CUSTOMER ACCOUNT STATEMENT'); $rep->filename = "Statement" . $debtor_row['debtor_no'] . ".pdf"; $rep->Info($params, $cols, null, $aligns); } $rep->filename = "ST-" . strtr($debtor_row['DebtorName'], " '", "__") . "--" . strtr(Today(), "/", "-") . ".pdf"; $contacts = get_customer_contacts($debtor_row['debtor_no'], 'invoice'); $rep->SetHeaderType(0); $rep->currency = $cur; $rep->Font(); $rep->Info(null, $cols, null, $aligns); //= get_branch_contacts($branch['branch_code'], 'invoice', $branch['debtor_no']); $rep->SetCommonData($debtor_row, null, null, $baccount, ST_STATEMENT, $contacts); $rep->NewPage(); $doctype = ST_STATEMENT; /* $rep->NewLine(); $rep->fontSize += 2; $rep->TextCol(0, 7, _("Overdue")); $rep->fontSize -= 2; $rep->NewLine(2); */ $rep->NewLine(10); $rep->TextCol(0, 5, $debtor_row['DebtorName']); $rep->NewLine(); $rep->TextCol(0, 5, $debtor_row['contactPerson']); $rep->NewLine(); $rep->TextCol(0, 5, $debtor_row['address']); $rep->NewLine(); $rep->TextCol(0, 5, $debtor_row['phone'] . " " . $debtor_row['phone2']); $rep->NewLine(5); $current = false; $balance = getInitialBalance($debtor_row['debtor_no'], $start); if (true || Abs($balance) > 1.0E-6) { // Display initial balance //$rep->TextCol(1, 4, 'Balance Brought Forward'); if (Abs($balance) < 1.0E-6) { $rep->SetTextColor(190, 190, 190); } else { if ($balance > 0) { $rep->SetTextColor(190, 0, 0); } } //$rep->TextCol(6, 7, number_format2(-$balance, $dec), -2); $rep->SetTextColor(0, 0, 0); //$rep->NewLine(); } $overdue = 0; while ($transaction_row = db_fetch($TransResult)) { if (!$current && !$transaction_row['OverDue'] == true) { $rep->fontSize += 2; //$rep->NewLine(2); //$rep->TextCol(0, 7, _("Due Soon")); $rep->fontSize -= 2; $current = true; $overdue = $balance; /* Reset the balance. so we have a separate balance for overdue * and current. However if the customer is in credit * don't reset the balance. * Example : A Customer has made a payment before the invoice * is overdue. The total balance after the invoice should be 0. */ if ($balance > 0) { $balance = 0; } else { $overdue = 0; } $rep->NewLine(2); } if ($current) { $rep->SetTextColor(0, 0, 190); } $DisplayTotal = number_format2(Abs($transaction_row["TotalAmount"]), $dec); $DisplayAlloc = number_format2($transaction_row["Allocated"], $dec); $DisplayNet = number_format2($transaction_row["TotalAmount"] - $transaction_row["Allocated"], $dec); $balance += $transaction_row["TotalAmount"]; if ($systypes_array[$transaction_row['type']] == "Customer Payment") { $invoice_no = get_custom_no($transaction_row['trans_no'], 53); } else { $invoice_no = get_custom_no($transaction_row['trans_no'], $transaction_row['type']); } if ($systypes_array[$transaction_row['type']] == "Sales Invoice") { $typename = "Charge Invoice"; } else { $typename = $systypes_array[$transaction_row['type']]; } $rep->TextCol(1, 1, $typename, -2); $rep->TextCol(2, 2, $invoice_no, -2); $rep->TextCol(0, 3, sql2date($transaction_row['EffectiveDate']), -2); if ($transaction_row['type'] == ST_SALESINVOICE) { $rep->TextCol(3, 4, sql2date($transaction_row['tran_date']), -2); } if ($transaction_row['type'] == ST_SALESINVOICE || $transaction_row['type'] == ST_BANKPAYMENT) { $rep->TextCol(4, 5, $DisplayTotal, -2); } else { $rep->TextCol(5, 6, $DisplayTotal, -2); } if (!$current) { if (Abs($balance) < 1.0E-6) { $rep->SetTextColor(190, 190, 190); } else { if ($balance > 0) { $rep->SetTextColor(190, 0, 0); } } } $rep->TextCol(6, 7, number_format2(-$balance, $dec), -2); $rep->SetTextColor(0, 0, 0); $rep->NewLine(); if ($rep->row < $rep->bottomMargin + 10 * $rep->lineHeight) { $rep->NewPage(); } } if (!$current) { $overdue = $balance; $balance = 0; } // Total $rep->NewLine(); $rep->SetTextColor(0, 0, 0); $rep->fontSize += 2; $rep->NewLine(18); $rep->TextCol(1, 2, 'Total Balance'); $rep->TextCol(2, 3, number_format2(-($balance + $overdue), $dec)); if ($overdue > 1.0E-6) { // $rep->fontSize += 2; $rep->NewLine(2); $rep->SetTextColor(190, 0, 0); $rep->TextCol(5, 6, 'Overdue'); $rep->TextCol(6, 7, number_format2($overdue, $dec)); $rep->TextCol(2, 5, 'PLEASE PAY NOW'); // $rep->fontSize -= 2; $rep->SetTextColor(0, 0, 0); $rep->NewLine(); } $rep->fontSize -= 2; /* $nowdue = "1-" . $PastDueDays1 . " " . _("Days"); $pastdue1 = $PastDueDays1 + 1 . "-" . $PastDueDays2 . " " . _("Days"); $pastdue2 = _("Over") . " " . $PastDueDays2 . " " . _("Days"); $CustomerRecord = get_customer_details($debtor_row['debtor_no'], null, $show_also_allocated); $str = array(_("Current"), $nowdue, $pastdue1, $pastdue2, _("Total Balance")); $str2 = array(number_format2(($CustomerRecord["Balance"] - $CustomerRecord["Due"]),$dec), number_format2(($CustomerRecord["Due"]-$CustomerRecord["Overdue1"]),$dec), number_format2(($CustomerRecord["Overdue1"]-$CustomerRecord["Overdue2"]) ,$dec), number_format2($CustomerRecord["Overdue2"],$dec), number_format2($CustomerRecord["Balance"],$dec)); $col = array($rep->cols[0], $rep->cols[0] + 110, $rep->cols[0] + 210, $rep->cols[0] + 310, $rep->cols[0] + 410, $rep->cols[0] + 510); $rep->row = $rep->bottomMargin + (10 * $rep->lineHeight - 6); for ($i = 0; $i < 5; $i++) $rep->TextWrap($col[$i], $rep->row, $col[$i + 1] - $col[$i], $str[$i], 'right'); $rep->NewLine(); for ($i = 0; $i < 5; $i++) $rep->TextWrap($col[$i], $rep->row, $col[$i + 1] - $col[$i], $str2[$i], 'right'); */ if ($email == 1) { $rep->End($email, _("Statement") . " " . _("as of") . " " . sql2date($date)); } } if ($email == 0) { $rep->End(); } }
function display_type($type, $typename, &$dec, &$rep, $from, $to, $zero, $balances, $dimension, $dimension2) { global $pdeb, $pcre, $cdeb, $ccre, $tdeb, $tcre, $pbal, $cbal, $tbal; $printtitle = 0; //Flag for printing type name //Get Accounts directly under this group/type $accounts = get_gl_accounts(null, null, $type); $begin = get_fiscalyear_begin_for_date($from); if (date1_greater_date2($begin, $from)) { $begin = $from; } $begin = add_days($begin, -1); while ($account = db_fetch($accounts)) { //Print Type Title if it has atleast one non-zero account if (!$printtitle) { $rep->row -= 4; $rep->TextCol(0, 8, _("Group") . " - " . $type . " - " . $typename); $printtitle = 1; $rep->row -= 4; $rep->Line($rep->row); $rep->NewLine(); } $prev = get_balance($account["account_code"], $dimension, $dimension2, $begin, $from, false, false); $curr = get_balance($account["account_code"], $dimension, $dimension2, $from, $to, true, true); $tot = get_balance($account["account_code"], $dimension, $dimension2, $begin, $to, false, true); if ($zero == 0 && !$prev['balance'] && !$curr['balance'] && !$tot['balance']) { continue; } $rep->TextCol(0, 1, $account['account_code']); $rep->TextCol(1, 2, $account['account_name']); if ($balances != 0) { if ($prev['balance'] >= 0.0) { $rep->AmountCol(2, 3, $prev['balance'], $dec); } else { $rep->AmountCol(3, 4, abs($prev['balance']), $dec); } if ($curr['balance'] >= 0.0) { $rep->AmountCol(4, 5, $curr['balance'], $dec); } else { $rep->AmountCol(5, 6, abs($curr['balance']), $dec); } if ($tot['balance'] >= 0.0) { $rep->AmountCol(6, 7, $tot['balance'], $dec); } else { $rep->AmountCol(7, 8, abs($tot['balance']), $dec); } } else { $rep->AmountCol(2, 3, $prev['debit'], $dec); $rep->AmountCol(3, 4, $prev['credit'], $dec); $rep->AmountCol(4, 5, $curr['debit'], $dec); $rep->AmountCol(5, 6, $curr['credit'], $dec); $rep->AmountCol(6, 7, $tot['debit'], $dec); $rep->AmountCol(7, 8, $tot['credit'], $dec); $pdeb += $prev['debit']; $pcre += $prev['credit']; $cdeb += $curr['debit']; $ccre += $curr['credit']; $tdeb += $tot['debit']; $tcre += $tot['credit']; } $pbal += $prev['balance']; $cbal += $curr['balance']; $tbal += $tot['balance']; $rep->NewLine(); if ($rep->row < $rep->bottomMargin + $rep->lineHeight) { $rep->Line($rep->row - 2); $rep->NewPage(); } } //Get Account groups/types under this group/type $result = get_account_types(false, false, $type); while ($accounttype = db_fetch($result)) { //Print Type Title if has sub types and not previously printed if (!$printtitle) { $rep->row -= 4; $rep->TextCol(0, 8, _("Group") . " - " . $type . " - " . $typename); $printtitle = 1; $rep->row -= 4; $rep->Line($rep->row); $rep->NewLine(); } display_type($accounttype["id"], $accounttype["name"] . ' (' . $typename . ')', $dec, $rep, $from, $to, $zero, $balances, $dimension, $dimension2); } }
function print_subsidiary_ledger() { global $path_to_root, $systypes_array; $dim = get_company_pref('use_dimension'); $dimension = $dimension2 = 0; $from = $_POST['PARAM_0']; $to = $_POST['PARAM_1']; $fromacc = $_POST['PARAM_2']; $comments = $_POST['PARAM_3']; $orientation = $_POST['PARAM_4']; $destination = $_POST['PARAM_5']; if ($destination) { include_once $path_to_root . "/reporting/includes/excel_report.inc"; } else { include_once $path_to_root . "/reporting/includes/pdf_report2.inc"; } $orientation = $orientation ? 'L' : 'P'; $rep = new FrontReport(_('Subsidiary Ledger Report'), "SubsidiaryLedger", user_pagesize(), 9, $orientation); $dec = user_price_dec(); //$headers = array(_('Type'), _('Ref'), _('#'), _('Date'), _('Dimension')." 1", _('Dimension')." 2", // _('Person/Item'), _('Debit'), _('Credit'), _('Balance')); //$cols = array(0, 80, 100, 150, 210, 280, 340, 400, 450, 510, 570); $cols = array(0, 65, 105, 125, 175, 230, 290, 345, 405, 465, 525); //------------0--1---2---3----4----5----6----7----8----9----10------- //-----------------------dim1-dim2----------------------------------- //-----------------------dim1---------------------------------------- //------------------------------------------------------------------- $aligns = array('left', 'left', 'left', 'center', 'left', 'left', 'left', 'right', 'right', 'right', 'right'); $headers = array(_('Account Name'), '', '', '', '', '', _('Debit'), _('Credit'), '', _('Balance')); $params = array(0 => $comments, 1 => array('text' => _('Period'), 'from' => $from, 'to' => $to), 2 => array('text' => _('Accounts'), 'from' => $fromacc, 'to' => $fromacc)); if ($orientation == 'L') { recalculate_cols($cols); } $rep->SetHeaderType('Header_custom'); $rep->Font(); $rep->Info($params, $cols, $headers, $aligns); $rep->NewPage(); $accounts = get_gl_accounts($fromacc, $fromacc); while ($account = db_fetch($accounts)) { if (is_account_balancesheet($account["account_code"])) { $begin = ""; } else { $begin = get_fiscalyear_begin_for_date($from); if (date1_greater_date2($begin, $from)) { $begin = $from; } $begin = add_days($begin, -1); } $prev_balance = get_gl_balance_from_to($begin, $from, $account["account_code"], $dimension, $dimension2); $trans = get_gl_transactions($from, $to, -1, $account['account_code'], $dimension, $dimension2); $rows = db_num_rows($trans); if ($prev_balance == 0.0 && $rows == 0) { continue; } $rep->Font('bold'); $rep->TextCol(0, 4, $account['account_code'] . " " . $account['account_name'], -2); $rep->TextCol(4, 6, _('Opening Balance')); if ($prev_balance > 0.0) { $rep->AmountCol(7, 8, abs($prev_balance), $dec); } else { $rep->AmountCol(8, 9, abs($prev_balance), $dec); } $rep->Font(); $total = $prev_balance; $rep->NewLine(2); if ($rows > 0) { $previous = ''; while ($myrow = db_fetch($trans)) { $total += $myrow['amount']; $txt = payment_person_name($myrow["person_type_id"], $myrow["person_id"], false); $current = $txt; $memo = $myrow['memo_']; if ($txt != "") { if ($previous == $current) { $txt = ''; } else { $rep->NewLine(1); $rep->Line($rep->row - $rep->lineHeight + 4); $rep->NewLine(2, 0); $rep->TextCol(3, 8, $txt, -2); $rep->Line($rep->row - $rep->lineHeight + 4); $rep->NewLine(2, 1); $rep->NewLine(1); } $previous = $current; } $rep->TextCol(0, 3, $systypes_array[$myrow["type"]], -2); $rep->DateCol(4, 6, $myrow["tran_date"], true); if ($myrow['amount'] > 0.0) { $rep->AmountCol(6, 7, abs($myrow['amount']), $dec); } else { $rep->AmountCol(7, 8, abs($myrow['amount']), $dec); } $rep->TextCol(8, 10, number_format2($total, $dec)); $rep->NewLine(); if ($rep->row < $rep->bottomMargin + $rep->lineHeight) { $rep->Line($rep->row - 2); $rep->NewPage(); } } $rep->NewLine(); } $rep->Font('bold'); $rep->TextCol(4, 6, _("Ending Balance")); if ($total > 0.0) { $rep->AmountCol(7, 8, abs($total), $dec); } else { $rep->AmountCol(8, 9, abs($total), $dec); } $rep->Font(); } $rep->End(); }
read_po($_GET['trans_no'], $purchase_order); echo "<br>"; display_po_summary($purchase_order, true); start_table(TABLESTYLE, "width='90%'", 6); echo "<tr><td valign=top>"; // outer table display_heading2(_("Line Details")); start_table(TABLESTYLE, "width='100%'"); $th = array(_("Item Code"), _("Item Description"), _("Quantity"), _("Unit"), _("Price"), _("Requested By"), _("Line Total"), _("Quantity Received"), _("Quantity Invoiced")); table_header($th); $total = $k = 0; $overdue_items = false; foreach ($purchase_order->line_items as $stock_item) { $line_total = $stock_item->quantity * $stock_item->price; // if overdue and outstanding quantities, then highlight as so if ($stock_item->quantity - $stock_item->qty_received > 0 && date1_greater_date2(Today(), $stock_item->req_del_date)) { start_row("class='overduebg'"); $overdue_items = true; } else { alt_table_row_color($k); } label_cell($stock_item->stock_id); label_cell($stock_item->item_description); $dec = get_qty_dec($stock_item->stock_id); qty_cell($stock_item->quantity, false, $dec); label_cell($stock_item->units); amount_decimal_cell($stock_item->price); label_cell($stock_item->req_del_date); amount_cell($line_total); qty_cell($stock_item->qty_received, false, $dec); qty_cell($stock_item->qty_inv, false, $dec);
function can_process() { global $Refs, $SysPrefs; copy_to_cart(); if (!get_post('customer_id')) { display_error(_("There is no customer selected.")); set_focus('customer_id'); return false; } if (!get_post('branch_id')) { display_error(_("This customer has no branch defined.")); set_focus('branch_id'); return false; } if (!is_date($_POST['OrderDate'])) { display_error(_("The entered date is invalid.")); set_focus('OrderDate'); return false; } if ($_SESSION['Items']->trans_type != ST_SALESORDER && $_SESSION['Items']->trans_type != ST_SALESQUOTE && !is_date_in_fiscalyear($_POST['OrderDate'])) { display_error(_("The entered date is not in fiscal year")); set_focus('OrderDate'); return false; } if (count($_SESSION['Items']->line_items) == 0) { display_error(_("You must enter at least one non empty item line.")); set_focus('AddItem'); return false; } if (!$SysPrefs->allow_negative_stock() && ($low_stock = $_SESSION['Items']->check_qoh())) { display_error(_("This document cannot be processed because there is insufficient quantity for items marked.")); return false; } if ($_SESSION['Items']->payment_terms['cash_sale'] == 0) { if (strlen($_POST['deliver_to']) <= 1) { display_error(_("You must enter the person or company to whom delivery should be made to.")); set_focus('deliver_to'); return false; } if ($_SESSION['Items']->trans_type != ST_SALESQUOTE && strlen($_POST['delivery_address']) <= 1) { display_error(_("You should enter the street address in the box provided. Orders cannot be accepted without a valid street address.")); set_focus('delivery_address'); return false; } if ($_POST['freight_cost'] == "") { $_POST['freight_cost'] = price_format(0); } if (!check_num('freight_cost', 0)) { display_error(_("The shipping cost entered is expected to be numeric.")); set_focus('freight_cost'); return false; } if (!is_date($_POST['delivery_date'])) { if ($_SESSION['Items']->trans_type == ST_SALESQUOTE) { display_error(_("The Valid date is invalid.")); } else { display_error(_("The delivery date is invalid.")); } set_focus('delivery_date'); return false; } if (date1_greater_date2($_POST['OrderDate'], $_POST['delivery_date'])) { if ($_SESSION['Items']->trans_type == ST_SALESQUOTE) { display_error(_("The requested valid date is before the date of the quotation.")); } else { display_error(_("The requested delivery date is before the date of the order.")); } set_focus('delivery_date'); return false; } } else { if (!db_has_cash_accounts()) { display_error(_("You need to define a cash account for your Sales Point.")); return false; } } if (!$Refs->is_valid($_POST['ref'])) { display_error(_("You must enter a reference.")); set_focus('ref'); return false; } if (!db_has_currency_rates($_SESSION['Items']->customer_currency, $_POST['OrderDate'])) { return false; } if ($_SESSION['Items']->get_items_total() < 0) { display_error("Invoice total amount cannot be less than zero."); return false; } return true; }
if ($showdims) { $th = array(_("Period"), _("Amount"), _("Dim. incl."), _("Last Year")); } else { $th = array(_("Period"), _("Amount"), _("Last Year")); } table_header($th); $year = $_POST['fyear']; if (get_post('update') == '') { $fyear = get_fiscalyear($year); $_POST['begin'] = sql2date($fyear['begin']); $_POST['end'] = sql2date($fyear['end']); } hidden('begin'); hidden('end'); $total = $btotal = $ltotal = 0; for ($i = 0, $date_ = $_POST['begin']; date1_greater_date2($_POST['end'], $date_); $i++) { start_row(); if (get_post('update') == '') { $_POST['amount' . $i] = number_format2(get_only_budget_trans_from_to($date_, $date_, $_POST['account'], $_POST['dim1'], $_POST['dim2']), 0); } label_cell($date_); amount_cells(null, 'amount' . $i, null, 15, null, 0); if ($showdims) { $d = get_budget_trans_from_to($date_, $date_, $_POST['account'], $_POST['dim1'], $_POST['dim2']); label_cell(number_format2($d, 0), "nowrap align=right"); $btotal += $d; } $lamount = get_gl_trans_from_to(add_years($date_, -1), add_years(end_month($date_), -1), $_POST['account'], $_POST['dim1'], $_POST['dim2']); $total += input_num('amount' . $i); $ltotal += $lamount; label_cell(number_format2($lamount, 0), "nowrap align=right");
function print_GL_transactions() { global $path_to_root, $systypes_array; $dim = get_company_pref('use_dimension'); $dimension = $dimension2 = 0; $from = $_POST['PARAM_0']; $to = $_POST['PARAM_1']; $fromacc = $_POST['PARAM_2']; $toacc = $_POST['PARAM_3']; if ($dim == 2) { $dimension = $_POST['PARAM_4']; $dimension2 = $_POST['PARAM_5']; $comments = $_POST['PARAM_6']; $orientation = $_POST['PARAM_7']; $destination = $_POST['PARAM_8']; } else { if ($dim == 1) { $dimension = $_POST['PARAM_4']; $comments = $_POST['PARAM_5']; $orientation = $_POST['PARAM_6']; $destination = $_POST['PARAM_7']; } else { $comments = $_POST['PARAM_4']; $orientation = $_POST['PARAM_5']; $destination = $_POST['PARAM_6']; } } 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'; $rep = new FrontReport(_('GL Account Transactions'), "GLAccountTransactions", user_pagesize(), 9, $orientation); $dec = 2; //$cols = array(0, 80, 100, 150, 210, 280, 340, 400, 450, 510, 570); $cols = array(0, 65, 105, 125, 175, 230, 290, 345, 405, 465, 525); //------------0--1---2---3----4----5----6----7----8----9----10------- //-----------------------dim1-dim2----------------------------------- //-----------------------dim1---------------------------------------- //------------------------------------------------------------------- $aligns = array('left', 'left', 'left', 'left', 'left', 'left', 'left', 'right', 'right', 'right'); if ($dim == 2) { $headers = array(_('Type'), _('Ref'), _('#'), _('Date'), _('Dimension') . " 1", _('Dimension') . " 2", _('Person/Item'), _('Debit'), _('Credit'), _('Balance')); } elseif ($dim == 1) { $headers = array(_('Type'), _('Ref'), _('#'), _('Date'), _('Dimension'), "", _('Person/Item'), _('Debit'), _('Credit'), _('Balance')); } else { $headers = array(_('Type'), _('Ref'), _('#'), _('Date'), "", "", _('Person/Item'), _('Debit'), _('Credit'), _('Balance')); } if ($dim == 2) { $params = array(0 => $comments, 1 => array('text' => _('Period'), 'from' => $from, 'to' => $to), 2 => array('text' => _('Accounts'), 'from' => $fromacc, 'to' => $toacc), 3 => array('text' => _('Dimension') . " 1", 'from' => get_dimension_string($dimension), 'to' => ''), 4 => array('text' => _('Dimension') . " 2", 'from' => get_dimension_string($dimension2), 'to' => '')); } else { if ($dim == 1) { $params = array(0 => $comments, 1 => array('text' => _('Period'), 'from' => $from, 'to' => $to), 2 => array('text' => _('Accounts'), 'from' => $fromacc, 'to' => $toacc), 3 => array('text' => _('Dimension'), 'from' => get_dimension_string($dimension), 'to' => '')); } else { $params = array(0 => $comments, 1 => array('text' => _('Period'), 'from' => $from, 'to' => $to), 2 => array('text' => _('Accounts'), 'from' => $fromacc, 'to' => $toacc)); } } if ($orientation == 'L') { recalculate_cols($cols); } $rep->Font(); $rep->Info($params, $cols, $headers, $aligns); $rep->NewPage(); $accounts = get_gl_accounts($fromacc, $toacc); while ($account = db_fetch($accounts)) { if (is_account_balancesheet($account["account_code"])) { $begin = ""; } else { $begin = get_fiscalyear_begin_for_date($from); if (date1_greater_date2($begin, $from)) { $begin = $from; } $begin = add_days($begin, -1); } $prev_balance = get_gl_balance_from_to($begin, $from, $account["account_code"], $dimension, $dimension2); $trans = get_gl_transactions($from, $to, -1, $account['account_code'], $dimension, $dimension2); $rows = db_num_rows($trans); if ($prev_balance == 0.0 && $rows == 0) { continue; } $rep->Font('bold'); $rep->TextCol(0, 4, $account['account_code'] . " " . $account['account_name'], -2); $rep->TextCol(4, 6, _('Opening Balance')); if ($prev_balance > 0.0) { $rep->AmountCol(7, 8, abs($prev_balance), $dec); } else { $rep->AmountCol(8, 9, abs($prev_balance), $dec); } $rep->Font(); $total = $prev_balance; $rep->NewLine(2); if ($rows > 0) { while ($myrow = db_fetch($trans)) { $total += $myrow['amount']; $type_name = $systypes_array[$myrow["type"]]; if ($type_name == "Customer Payment") { $rep->TextCol(0, 1, "CRB", -2); } if ($type_name == "Cash Disbursement/Check Voucher") { $rep->TextCol(0, 1, "CDB", -2); } if ($type_name == "Journal Entry") { $rep->TextCol(0, 1, "JB", -2); } if ($type_name == "Customer Credit Note") { $type_name = "Credit Memo"; } if ($type_name == "Sales Invoice") { $type_name = "Invoice"; } else { if ($type_name != "Customer Payment" && $type_name != "Cash Disbursement/Check Voucher" && $type_name != "Journal Entry") { $rep->TextCol(0, 1, $type_name, -2); } } $reference = get_reference($myrow["type"], $myrow["type_no"]); $rep->TextCol(1, 2, $reference); $rep->TextCol(2, 3, $myrow['type_no'], -2); $rep->DateCol(3, 4, $myrow["tran_date"], true); if ($dim >= 1) { $rep->TextCol(4, 5, get_dimension_string($myrow['dimension_id'])); } if ($dim > 1) { $rep->TextCol(5, 6, get_dimension_string($myrow['dimension2_id'])); } $txt = payment_person_name($myrow["person_type_id"], $myrow["person_id"], false); $memo = $myrow['memo_']; if ($txt != "") { if ($memo != "") { $txt = $txt . "/" . $memo; } } else { $txt = $memo; } $rep->TextCol(6, 7, $txt, -2); if ($myrow['amount'] > 0.0) { $rep->AmountCol(7, 8, abs($myrow['amount']), $dec); } else { $rep->AmountCol(8, 9, abs($myrow['amount']), $dec); } $rep->TextCol(9, 10, number_format2($total, $dec)); $rep->NewLine(); if ($rep->row < $rep->bottomMargin + $rep->lineHeight) { $rep->Line($rep->row - 2); $rep->NewPage(); } } $rep->NewLine(); } $rep->Font('bold'); $rep->TextCol(4, 6, _("Ending Balance")); if ($total > 0.0) { $rep->AmountCol(7, 8, abs($total), $dec); } else { $rep->AmountCol(8, 9, abs($total), $dec); } $rep->Font(); $rep->Line($rep->row - $rep->lineHeight + 4); $rep->NewLine(2, 1); } $rep->End(); }
function can_process() { if (!is_date($_POST['OrderDate'])) { display_error(tr("The entered date is invalid.")); set_focus('OrderDate'); return false; } if ($_SESSION['Items']->trans_type != 30 && !is_date_in_fiscalyear($_POST['OrderDate'])) { display_error(tr("The entered date is not in fiscal year")); set_focus('OrderDate'); return false; } if (count($_SESSION['Items']->line_items) == 0) { display_error(tr("You must enter at least one non empty item line.")); set_focus('AddItem'); return false; } if (strlen($_POST['deliver_to']) <= 1) { display_error(tr("You must enter the person or company to whom delivery should be made to.")); set_focus('deliver_to'); return false; } if (strlen($_POST['delivery_address']) <= 1) { display_error(tr("You should enter the street address in the box provided. Orders cannot be accepted without a valid street address.")); set_focus('delivery_address'); return false; } if ($_POST['freight_cost'] == "") { $_POST['freight_cost'] = price_format(0); } if (!check_num('freight_cost', 0)) { display_error(tr("The shipping cost entered is expected to be numeric.")); set_focus('freight_cost'); return false; } if (!is_date($_POST['delivery_date'])) { display_error(tr("The delivery date is invalid.")); set_focus('delivery_date'); return false; } if (date1_greater_date2($_SESSION['Items']->document_date, $_POST['delivery_date'])) { display_error(tr("The requested delivery date is before the date of the order.")); set_focus('delivery_date'); return false; } if ($_SESSION['Items']->trans_type != 30 && !references::is_valid($_POST['ref'])) { display_error(tr("You must enter a reference.")); set_focus('ref'); return false; } return true; }