Example #1
0
 function install($pref, $force)
 {
     global $db, $systypes_array;
     if (!$this->preconf) {
         return false;
     }
     // Until 2.2 sanitizing text input with db_escape was not
     // consequent enough. To avoid comparision problems we have to
     // fix this now.
     sanitize_database($pref);
     if ($this->beta) {
         // nothing more to be done on upgrade from 2.2beta
         return true;
     }
     // set item category dflt accounts to values from company GL setup
     $prefs = get_company_prefs();
     $sql = "UPDATE {$pref}stock_category SET " . "dflt_sales_act = '" . $prefs['default_inv_sales_act'] . "'," . "dflt_cogs_act = '" . $prefs['default_cogs_act'] . "'," . "dflt_inventory_act = '" . $prefs['default_inventory_act'] . "'," . "dflt_adjustment_act = '" . $prefs['default_adj_act'] . "'," . "dflt_assembly_act = '" . $prefs['default_assembly_act'] . "'";
     if (db_query($sql) == false) {
         display_error("Cannot update category default GL accounts" . ':<br>' . db_error_msg($db));
         return false;
     }
     // add all references to refs table for easy searching via journal interface
     foreach ($systypes_array as $typeno => $typename) {
         $info = get_systype_db_info($typeno);
         if ($info == null || $info[3] == null) {
             continue;
         }
         $tbl = str_replace(TB_PREF, $pref, $info[0]);
         $sql = "SELECT DISTINCT {$info[2]} as id,{$info[3]} as ref FROM {$tbl}";
         if ($info[1]) {
             $sql .= " WHERE {$info[1]}={$typeno}";
         }
         $result = db_query($sql);
         if (db_num_rows($result)) {
             while ($row = db_fetch($result)) {
                 $res2 = db_query("INSERT INTO {$pref}refs VALUES(" . $row['id'] . "," . $typeno . ",'" . $row['ref'] . "')");
                 if (!$res2) {
                     display_error(_("Cannot copy references from {$tbl}") . ':<br>' . db_error_msg($db));
                     return false;
                 }
             }
         }
     }
     if (!($ret = db_query("SELECT MAX(`order_no`) FROM `{$pref}sales_orders`")) || !db_num_rows($ret)) {
         display_error(_('Cannot query max sales order number.'));
         return false;
     }
     $row = db_fetch($ret);
     $max_order = $row[0];
     $next_ref = $max_order + 1;
     $sql = "UPDATE `{$pref}sys_types` \n\t\t\tSET `type_no`='{$max_order}',`next_reference`='{$next_ref}'\n\t\t\tWHERE `type_id`=30";
     if (!db_query($sql)) {
         display_error(_('Cannot store next sales order reference.'));
         return false;
     }
     return convert_roles($pref);
 }
function print_inventory_sales()
{
    global $path_to_root;
    $from = $_POST['PARAM_0'];
    $destination = $_POST['PARAM_1'];
    if ($destination) {
        include_once $path_to_root . "/reporting/includes/excel_report.inc";
    } else {
        include_once $path_to_root . "/reporting/includes/pdf_report.inc";
    }
    $dec = user_price_dec();
    if ($category == ALL_NUMERIC) {
        $category = 0;
    }
    if ($category == 0) {
        $cat = _('All');
    } else {
        $cat = get_category_name($category);
    }
    $cols = array(0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000, 1050, 1100, 1150, 1200);
    $headers = array(_('Date'), _('Client Name'), _('IMC'), _('Charge'), _('Sales'), _('Date'), _('CM#'), _('Returns'), _(''), _('Discount'), _('Balance'), _('Date'), _('PR/OR#'), _('Date'), _('OR #'), _('Amount'), _('Partial'), _('Balance'), _('Date'), _(''), _('Commission'), _('w/tax'), _('Net Commission'));
    $header2 = array(_(''), '', '', _('Invoice'), _('Amount'), _(''), _(''), _(''), _(''), _(''), _(''), _(''), _(''), _(''), _(''), _(''), _(''), _(''), _(''), _(''), '', _(''), _(''));
    $aligns = array('left', 'center', 'center', 'center', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right');
    $params = array(0 => $comments, 1 => array('text' => _('Period'), 'from' => $from, 'to' => $to), 2 => array('text' => _('Category'), 'from' => $cat, 'to' => ''));
    $rep = new FrontReport(_('Series Report'), "SeriesReport", user_pagesize(), 8, 'L');
    $rep->Font();
    $rep->Info($params, $cols, $header2, $aligns, $cols, $headers, $aligns);
    $rep->NewPage();
    $total = $grandtotal = 0.0;
    $total1 = $grandtotal1 = 0.0;
    $total2 = $grandtotal2 = 0.0;
    $catt = '';
    $res = getTransactions($imc, $from);
    while ($myrow = db_fetch($res)) {
        $company_data = get_company_prefs();
        $branch = get_branch($myrow["branch_code"]);
        $branch_data = get_branch_accounts($myrow['branch_code']);
        $dt = get_discount($branch_data['sales_discount_account'], $myrow['type'], $myrow['trans_no']);
        $salesman = get_imc_code($myrow['branch_code']);
        $res2 = get_return_details($myrow['order_']);
        $returns = 0;
        $rtn_dt = 0;
        $credit_num = "";
        $cm_date = "";
        $num = db_num_rows($res2);
        $var = array();
        while ($myrow2 = db_fetch($res2)) {
            $returns += $myrow2['ov_amount'];
            if ($num > 1) {
                $credit_num .= $myrow2['customized_no'] . "/";
                $cm_date = $myrow2['tran_date'] . "/";
            } else {
                $credit_num .= $myrow2['customized_no'];
                $cm_date = $myrow2['tran_date'];
            }
            $var = array($myrow2['trans_no']);
            //$res2 = get_return_discount($branch_data['sales_discount_account'], $myrow2['type'], $myrow2['trans_no']);
            //	while ($myrow3 = db_fetch($res2)){
            //		$rtn_dt += abs($myrow3['amount']);
            //	}
        }
        foreach ($var as $vars) {
            $res2 = get_return_discount($branch_data['sales_discount_account'], ST_CUSTCREDIT, $vars);
            while ($myrow3 = db_fetch($res2)) {
                $rtn_dt += abs($myrow3['amount']);
            }
        }
        $total_returns = $returns + $rtn_dt;
        $return_discount = $rtn_dt / $total_returns * 100;
        //$discount = $myrow['discount'];
        $invoicetot = $myrow['ov_amount'] + $dt;
        $invoice_discount = $dt / $invoicetot * 100;
        $sales_discount = ($invoicetot - $total_returns) * ($invoice_discount / 100);
        $net_sales = $invoicetot - $total_returns - $sales_discount;
        $gross_commission = ($invoicetot - $total_returns) * ($myrow['commission'] / 100);
        $tot_invoice = $invoicetot - $invoicetot * ($invoice_discount / 100);
        $sample = $invoicetot - $total_returns;
        $rep->TextCol(0, 1, $myrow['tranDate']);
        $rep->TextCol(1, 2, $myrow['br_name']);
        $rep->TextCol(2, 3, $salesman);
        $rep->TextCol(3, 4, $myrow['customized_no']);
        if ($myrow['IsVoid'] == '') {
            $rep->AmountCol(4, 5, $invoicetot, 2);
            $rep->TextCol(5, 6, $cm_date);
            $rep->TextCol(6, 7, $credit_num);
            if ($total_returns != 0) {
                $rep->AmountCol(7, 8, $total_returns, 2);
            }
            if ($invoice_discount < 0) {
                $rep->TextCol(8, 9, "CLIENT SALES/SALES DISCOUNT NOT DEFINED.");
            } else {
                $rep->TextCol(8, 9, $invoice_discount . "%");
            }
            if ($sales_discount < 0) {
                $rep->TextCol(9, 10, "ERROR.");
            } else {
                if ($sales_discount != 0) {
                    $rep->AmountCol(9, 10, $sales_discount, 2);
                }
            }
            if ($net_sales != 0) {
                $rep->AmountCol(10, 11, $net_sales, 2);
            }
            $partial_payment = 0;
            $or = get_pr_details($myrow['type'], $myrow['trans_no']);
            $ref = '';
            $num2 = db_num_rows($or);
            $date_alloc = '';
            while ($pr = db_fetch($or)) {
                $partial_payment += $pr['amt'];
                $date_alloc = $pr['prDate'] . " ";
                $pr_number = $pr['customized_no'] . " ";
                if ($num2 > 1) {
                    $ref .= $pr['reference'] . "/";
                } else {
                    $ref = $pr['reference'];
                }
            }
            $net_remittance = $net_sales - $partial_payment;
            $rep->TextCol(11, 12, $date_alloc);
            $rep->TextCol(12, 13, $ref);
            $rep->TextCol(13, 14, $date_alloc);
            $rep->TextCol(14, 15, _(""));
            if ($partial_payment == $tot_invoice) {
                $rep->AmountCol(15, 16, $partial_payment, 2);
            }
            if ($partial_payment != 0) {
                if ($partial_payment < $tot_invoice) {
                    $bal = $tot_invoice - $partial_payment;
                    $rep->AmountCol(16, 17, $partial_payment, 2);
                    $rep->AmountCol(17, 18, $bal, 2);
                }
            }
            //$rep->AmountCol(15,16, $partial_payment, 2);
            //$rep->AmountCol(17,18, $net_remittance, 2);
            $myrow4 = db_fetch(get_commission_details($myrow['type'], $myrow['trans_no']));
            $comm = ($invoicetot - $total_returns) * ($myrow4['commission'] / 100);
            $rep->TextCol(18, 19, $myrow4['tranDate']);
            if ($myrow4['commission'] != 0) {
                $rep->TextCol(19, 20, $myrow4['commission'] . "%");
            }
            if ($comm != 0) {
                $rep->AmountCol(20, 21, $comm, 2);
            }
            if ($myrow4['with_tax'] != 0) {
                $rep->AmountCol(21, 22, $myrow4['with_tax'], 2);
            }
            if ($myrow4['net_commission'] != 0) {
                $rep->AmountCol(22, 23, $myrow4['net_commission'], 2);
            }
            $net_invoice += $invoicetot;
            $net_discount += $sales_discount;
            $net_returns += $total_returns;
            $sale_amount += $net_sales;
            $net_partial += $partial_payment;
            $net_rem += $net_remittance;
            $net_bal += $bal;
            $net_balance = $net_rem + $net_bal;
            $net_comm += $comm;
            $net_tax += $myrow4['with_tax'];
            $net_net_comm += $myrow4['net_commission'];
        } else {
            $rep->TextCol(4, 5, "Voided");
        }
        $rep->NewLine();
    }
    $rep->Font('bold');
    $rep->NewLine();
    $rep->TextCol(1, 2, "TOTAL");
    $rep->AmountCol(4, 5, $net_invoice, 2);
    $rep->AmountCol(7, 8, $net_returns, 2);
    $rep->AmountCol(9, 10, $net_discount, 2);
    $rep->AmountCol(10, 11, $sale_amount, 2);
    $rep->AmountCol(16, 17, $net_partial, 2);
    //$rep->AmountCol(17,18, $net_balance, 2);
    $rep->AmountCol(20, 21, $net_comm, 2);
    $rep->AmountCol(21, 22, $net_tax, 2);
    $rep->AmountCol(22, 23, $net_net_comm, 2);
    $rep->NewLine();
    $rep->End();
}
Example #3
0
        $_POST['adjustment_account'] = $myrow["dflt_adjustment_act"];
        $_POST['assembly_account'] = $myrow["dflt_assembly_act"];
        $_POST['units'] = $myrow["dflt_units"];
        $_POST['mb_flag'] = $myrow["dflt_mb_flag"];
        $_POST['dim1'] = $myrow["dflt_dim1"];
        $_POST['dim2'] = $myrow["dflt_dim2"];
        $_POST['no_sale'] = $myrow["dflt_no_sale"];
    }
    hidden('selected_id', $selected_id);
    hidden('category_id');
} else {
    if ($Mode != 'CLONE') {
        $_POST['long_description'] = '';
        $_POST['description'] = '';
        $_POST['no_sale'] = 0;
        $company_record = get_company_prefs();
        if (get_post('inventory_account') == "") {
            $_POST['inventory_account'] = $company_record["default_inventory_act"];
        }
        if (get_post('cogs_account') == "") {
            $_POST['cogs_account'] = $company_record["default_cogs_act"];
        }
        if (get_post('sales_account') == "") {
            $_POST['sales_account'] = $company_record["default_inv_sales_act"];
        }
        if (get_post('adjustment_account') == "") {
            $_POST['adjustment_account'] = $company_record["default_adj_act"];
        }
        if (get_post('assembly_account') == "") {
            $_POST['assembly_account'] = $company_record["default_assembly_act"];
        }
function print_inventory_sales()
{
    global $path_to_root;
    $from = $_POST['PARAM_0'];
    $destination = $_POST['PARAM_1'];
    if ($destination) {
        include_once $path_to_root . "/reporting/includes/excel_report.inc";
    } else {
        include_once $path_to_root . "/reporting/includes/pdf_report.inc";
    }
    $dec = user_price_dec();
    if ($category == ALL_NUMERIC) {
        $category = 0;
    }
    if ($category == 0) {
        $cat = _('All');
    } else {
        $cat = get_category_name($category);
    }
    $cols = array(0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000, 1050, 1100, 1150, 1200);
    $headers = array(_('Date'), _('Client Name'), _('IMC'), _('Charge'), _('Sales'), _('Date'), _('CM#'), _('Returns'), _(''), _('Discount'), _('Balance'), _('Date'), _('PR/OR#'), _('Date'), _('OR #'), _('Partial'), _('Net'), _('Balance'), _('Date'), _(''), _('Commission'), _('w/tax'), _('Net Commission'));
    $header2 = array(_(''), '', '', _('Invoice'), _('Amount'), _(''), _(''), _(''), _(''), _(''), _(''), _(''), _(''), _(''), _(''), _(''), _(''), _(''), _(''), _(''), '', _(''), _(''));
    $aligns = array('left', 'center', 'center', 'center', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right');
    $params = array(0 => $comments, 1 => array('text' => _('Period'), 'from' => $from, 'to' => $to), 2 => array('text' => _('Category'), 'from' => $cat, 'to' => ''));
    $rep = new FrontReport(_('Series Report'), "Series Report", user_pagesize(), 8, 'L');
    $rep->Font();
    $rep->Info($params, $cols, $header2, $aligns, $cols, $headers, $aligns);
    $rep->NewPage();
    $total = $grandtotal = 0.0;
    $total1 = $grandtotal1 = 0.0;
    $total2 = $grandtotal2 = 0.0;
    $catt = '';
    $res = getTransactions($imc, $from);
    while ($myrow = db_fetch($res)) {
        $company_data = get_company_prefs();
        $branch = get_branch($myrow["branch_code"]);
        $branch_data = get_branch_accounts($myrow['branch_code']);
        $dt = get_discount($branch_data['sales_discount_account'], $myrow['type'], $myrow['trans_no']);
        $salesman = get_imc_code($myrow['branch_code']);
        $res2 = get_return_details($myrow['order_']);
        $returns = 0;
        $rtn_dt = 0;
        while ($myrow2 = db_fetch($res2)) {
            $returns += $myrow2['ov_amount'];
            $credit_num = $myrow2['customized_no'];
            $cm_date = $myrow2['tran_date'];
            $res2 = get_return_discount($branch_data['sales_discount_account'], $myrow2['type'], $myrow2['trans_no']);
            while ($myrow3 = db_fetch($res2)) {
                $rtn_dt += abs($myrow3['amount']);
            }
        }
        $total_returns = $returns + $rtn_dt;
        $return_discount = $rtn_dt / $total_returns * 100;
        $discount = $myrow['discount'];
        $invoicetot = $myrow['ov_amount'] + $dt;
        $sales_discount = ($invoicetot - $total_returns) * ($return_discount / 100);
        $net_sales = $invoicetot - $total_returns - $sales_discount;
        $gross_commission = ($invoicetot - $total_returns) * ($myrow['commission'] / 100);
        $rep->TextCol(0, 1, $myrow['tran_date']);
        $rep->TextCol(1, 2, $myrow['br_name']);
        $rep->TextCol(2, 3, $salesman);
        $rep->TextCol(3, 4, $myrow['customized_no']);
        $rep->AmountCol(4, 5, $invoicetot, 2);
        $rep->TextCol(5, 6, $cm_date);
        $rep->TextCol(6, 7, $credit_num);
        $rep->AmountCol(7, 8, $total_returns, 2);
        $rep->TextCol(8, 9, $return_discount . "%");
        $rep->AmountCol(9, 10, $sales_discount, 2);
        $rep->AmountCol(10, 11, $net_sales, 2);
        $rep->TextCol(18, 19, $myrow['date']);
        $rep->TextCol(19, 20, $myrow['commission'] . "%");
        $rep->AmountCol(20, 21, $gross_commission, 2);
        $rep->AmountCol(21, 22, $myrow['with_tax'], 2);
        $rep->AmountCol(22, 23, $myrow['net_commission'], 2);
        $or = get_pr_details($myrow['type'], $myrow['trans_no']);
        while ($pr = db_fetch($or)) {
            $net_remittance = $net_sales - $pr['amt'];
            $rep->TextCol(11, 12, $pr['date_alloc']);
            $rep->TextCol(12, 13, $pr['customized_no']);
            $rep->TextCol(13, 14, _("DATE"));
            $rep->TextCol(14, 15, _("OR#"));
            $rep->TextCol(15, 16, "");
            $rep->AmountCol(17, 18, '', 2);
        }
        $rep->NewLine();
        //
    }
    $rep->NewLine();
    $rep->End();
}
Example #5
0
//-------------------------------------------------------------------------------------------------
if (isset($_POST['submit']) && can_process()) {
    update_company_prefs(get_post(array('retained_earnings_act', 'profit_loss_year_act', 'debtors_act', 'pyt_discount_act', 'creditors_act', 'freight_act', 'exchange_diff_act', 'bank_charge_act', 'default_sales_act', 'default_sales_discount_act', 'default_prompt_payment_act', 'default_inventory_act', 'default_cogs_act', 'default_adj_act', 'default_inv_sales_act', 'default_assembly_act', 'legal_text', 'past_due_days', 'default_workorder_required', 'default_dim_required', 'default_delivery_required', 'grn_clearing_act', 'allow_negative_stock' => 0, 'accumulate_shipping' => 0, 'po_over_receive' => 0.0, 'po_over_charge' => 0.0, 'default_credit_limit' => 0.0)));
    display_notification(_("The general GL setup has been updated."));
}
/* end of if submit */
//-------------------------------------------------------------------------------------------------
start_form();
start_outer_table(TABLESTYLE2);
table_section(1);
if (get_company_pref('grn_clearing_act') === null) {
    // available from 2.3.1, can be not defined on pre-2.4 installations
    set_company_pref('grn_clearing_act', 'glsetup.purchase', 'varchar', 15, 0);
    refresh_sys_prefs();
}
$myrow = get_company_prefs();
$_POST['retained_earnings_act'] = $myrow["retained_earnings_act"];
$_POST['profit_loss_year_act'] = $myrow["profit_loss_year_act"];
$_POST['debtors_act'] = $myrow["debtors_act"];
$_POST['creditors_act'] = $myrow["creditors_act"];
$_POST['freight_act'] = $myrow["freight_act"];
$_POST['pyt_discount_act'] = $myrow["pyt_discount_act"];
$_POST['exchange_diff_act'] = $myrow["exchange_diff_act"];
$_POST['bank_charge_act'] = $myrow["bank_charge_act"];
$_POST['default_sales_act'] = $myrow["default_sales_act"];
$_POST['default_sales_discount_act'] = $myrow["default_sales_discount_act"];
$_POST['default_prompt_payment_act'] = $myrow["default_prompt_payment_act"];
$_POST['default_inventory_act'] = $myrow["default_inventory_act"];
$_POST['default_cogs_act'] = $myrow["default_cogs_act"];
$_POST['default_adj_act'] = $myrow["default_adj_act"];
$_POST['default_inv_sales_act'] = $myrow['default_inv_sales_act'];
Example #6
0
function print_invoices()
{
    global $path_to_root, $alternative_tax_include_on_docs, $suppress_tax_rates, $no_zero_lines_amount;
    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'];
    $pay_service = $_POST['PARAM_4'];
    $comments = $_POST['PARAM_5'];
    $customer = $_POST['PARAM_6'];
    $orientation = $_POST['PARAM_7'];
    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, 40, 60, 100, 200, 250, 300, 320, 400, 450, 500);
    // $headers in doctext.inc
    $aligns = array('left', 'left', 'left', 'left', 'right', 'right', 'right', 'right', 'right', 'right', 'right');
    //$params = array('comments' => $comments);
    $cur = get_company_Pref('curr_default');
    $company_data = get_company_prefs();
    if ($email == 0) {
        $rep = new FrontReport(_('INVOICE'), "InvoiceBulk", user_pagesize(), 9, $orientation);
    }
    if ($orientation == 'L') {
        recalculate_cols($cols);
    }
    for ($i = $from; $i <= $to; $i++) {
        if (!exists_customer_trans(ST_SALESINVOICE, $i)) {
            continue;
        }
        $sign = 1;
        $myrow = get_customer_trans($i, ST_SALESINVOICE);
        if ($customer && $myrow['debtor_no'] != $customer) {
            continue;
        }
        $baccount = get_default_bank_account($myrow['curr_code']);
        $params['bankaccount'] = $baccount['id'];
        $branch = get_branch($myrow["branch_code"]);
        $sales_order = get_sales_order_header($myrow["order_"], ST_SALESORDER);
        if ($email == 1) {
            $rep = new FrontReport("", "", user_pagesize(), 9, $orientation);
            //$rep->title = _('INVOICE');
            $rep->filename = "Invoice" . $myrow['reference'] . ".pdf";
        }
        $rep->SetHeaderType(0);
        $rep->currency = $cur;
        $rep->Font();
        $rep->Info(null, $cols, null, $aligns);
        //$contacts = get_branch_contacts($branch['branch_code'], 'invoice', $branch['debtor_no'], true);
        //$baccount['payment_service'] = $pay_service;
        $salesman = get_imc_code($branch['branch_code']);
        $pay_term = get_payment_terms($myrow['payment_terms']);
        $branch_data = get_branch_accounts($myrow['branch_code']);
        $dt = get_discount($branch_data['sales_discount_account'], $myrow['type'], $myrow['trans_no']);
        $invoice_no = get_custom_no($myrow['trans_no'], $myrow['type']);
        $contact = getContactPerson($myrow['salesman'], $myrow['debtor_no'], $branch['branch_code']);
        $rep->NewPage();
        $result = get_customer_trans_details(ST_SALESINVOICE, $i);
        $SubTotal = 0;
        $rep->NewLine(8);
        $rep->TextCol(2, 7, _("CHARGE INVOICE # " . $invoice_no));
        $rep->TextCol(8, 9, $myrow['TranDate']);
        $rep->NewLine();
        $rep->TextCol(2, 7, $branch['br_name']);
        if ($dt != 0) {
            //$display_bulk_discount = (($sub_total - $myrow['Total']) / $sub_total) * 100;
            $tot = $myrow['Total'] + $dt;
            $dscnt = ($tot - $myrow['Total']) / $tot * 100;
            //$dscnt = ($dt / $myrow['Total']) * 100;
            $significant = strlen(substr(strrchr($dscnt, "."), 1));
            if ($significant > 2) {
                $rep->TextCol(7, 9, floor($dscnt) . "%");
            } else {
                $rep->TextCol(7, 9, $dscnt . "%");
            }
        }
        $rep->NewLine();
        $rep->TextCol(2, 7, $branch['branch_ref']);
        $rep->TextCol(8, 9, $salesman);
        $rep->NewLine();
        $rep->TextCol(2, 6, $contact);
        if ($pay_term['terms'] == 'Cash Only') {
            $rep->TextCol(8, 9, $pay_term['terms']);
        } else {
            $rep->TextCol(7, 10, $pay_term['terms']);
        }
        $rep->NewLine();
        $oldrow = $rep->row;
        $newrow = $rep->row;
        $rep->TextColLines(2, 6, $branch['br_address'], -2);
        $rep->row = $oldrow;
        $rep->NewLine(5);
        $rep->Font('bold');
        //$rep->Line($rep->row  + 10);
        //$rep->TextCol(2,5, _("Item Description"));
        //$rep->TextCol(5,6, _("Quantity"));
        //$rep->TextCol(7,8, _("Unit Price"));
        //$rep->TextCol(9,10, _("Total Amount"));
        //$rep->Line($rep->row  - 4);
        $rep->NewLine(2);
        $rep->Font();
        while ($myrow2 = db_fetch($result)) {
            if ($myrow2["quantity"] == 0) {
                continue;
            }
            $Net = round2($sign * ((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]), user_price_dec());
            $Net2 = round2($sign * ($myrow2["unit_price"] * $myrow2["quantity"]), user_price_dec());
            $SubTotal += $Net;
            $DisplayPrice = number_format2($myrow2["unit_price"], $dec);
            $DisplayQty = number_format2($sign * $myrow2["quantity"], get_qty_dec($myrow2['stock_id']));
            $DisplayNet = number_format2($Net, $dec);
            $dNet = number_format2($Net2, $dec);
            /*if ($myrow2["discount_percent"]==0)
            		$DisplayDiscount ="";
            		else
            		$DisplayDiscount = number_format2($myrow2["discount_percent"]*100,user_percent_dec()) . "%";*/
            //if ($myrow["ov_discount"]==0)
            //	$DisplayDiscount ="";
            //else
            //$DisplayDiscount = number_format2($myrow["ov_discount"]/$myrow["ov_amount"] * 100,user_percent_dec()) . "%";
            //$rep->TextCol(0, 3,	$myrow2['stock_id'], -2);
            $oldrow = $rep->row;
            $rep->TextColLines(0, 5, $myrow2['StockDescription'], -2);
            $newrow = $rep->row;
            $rep->row = $oldrow;
            if ($Net != 0.0 || !is_service($myrow2['mb_flag']) || !isset($no_zero_lines_amount) || $no_zero_lines_amount == 0) {
                $rep->TextCol(5, 6, $DisplayQty . " " . $myrow2['units']);
                //$rep->TextCol(5, 6,	$myrow2['units'], -2);
                $rep->TextCol(7, 8, $DisplayPrice, -2);
                //$rep->TextCol(5, 6,	$DisplayDiscount, -2);
                $rep->TextCol(8, 10, $dNet, -2);
            }
            $rep->row = $newrow;
            //$rep->NewLine(1);
            if ($rep->row < $rep->bottomMargin + 15 * $rep->lineHeight) {
                $rep->NewPage();
            }
        }
        $memo = get_comments_string(ST_SALESINVOICE, $i);
        if ($memo != "") {
            $rep->NewLine();
            $rep->TextColLines(1, 5, $memo, -2);
        }
        $DisplayNet = number_format2($SubTotal, $dec);
        $DisplaySubTot = number_format2($SubTotal, $dec);
        $DisplayFreight = number_format2($sign * $myrow["ov_freight"], $dec);
        $DisplayTots = number_format2($myrow['Total'], $dec);
        $DisplayDiscount = number_format2($SubTotal - $myrow['Total'], $dec);
        $rep->row = $rep->bottomMargin + 30 * $rep->lineHeight;
        $doctype = ST_SALESINVOICE;
        $rep->NewLine();
        $rep->Font('bold');
        $rep->TextCol(9, 10, $DisplayNet, -2);
        $rep->NewLine();
        //$rep->TextCol(8, 9, _("Less discount: "));
        $rep->TextCol(9, 10, $DisplayDiscount, -2);
        $rep->NewLine();
        //$rep->TextCol(8, 9, _("Net Amount : "), -2);
        $rep->TextCol(9, 10, $DisplayTots, -2);
        $rep->NewLine();
        /*$tax_items = get_trans_tax_details(ST_SALESINVOICE, $i);
        			$first = true;
            		while ($tax_item = db_fetch($tax_items))
            		{
            			if ($tax_item['amount'] == 0)
            				continue;
            			$DisplayTax = number_format2($sign*$tax_item['amount'], $dec);
            			
            			if (isset($suppress_tax_rates) && $suppress_tax_rates == 1)
            				$tax_type_name = $tax_item['tax_type_name'];
            			else
            				$tax_type_name = $tax_item['tax_type_name']." (".$tax_item['rate']."%) ";
        
            			if ($tax_item['included_in_price'])
            			{
            				if (isset($alternative_tax_include_on_docs) && $alternative_tax_include_on_docs == 1)
            				{
            					if ($first)
            					{
        							$rep->TextCol(3, 6, _("Total Tax Excluded"), -2);
        							$rep->TextCol(6, 7,	number_format2($sign*$tax_item['net_amount'], $dec), -2);
        							$rep->NewLine();
            					}
        						$rep->TextCol(3, 6, $tax_type_name, -2);
        						$rep->TextCol(6, 7,	$DisplayTax, -2);
        						$first = false;
            				}
            				else
        						$rep->TextCol(3, 7, _("Included") . " " . $tax_type_name . _("Amount") . ": " . $DisplayTax, -2);
        				}
            			else
            			{
        					$rep->TextCol(3, 6, $tax_type_name, -2);
        					$rep->TextCol(6, 7,	$DisplayTax, -2);
        				}
        				$rep->NewLine();
            		}
        
            		$rep->NewLine();
        			$DisplayTotal = number_format2($sign*($myrow["ov_freight"] + $myrow["ov_gst"] +
        				$myrow["ov_amount"]+$myrow["ov_freight_tax"]),$dec);*/
        //$rep->Font('bold');
        //$rep->TextCol(3, 6, _("TOTAL INVOICE"), - 2);
        //$rep->TextCol(6, 7, $DisplayTotal, -2);
        //$words = price_in_words($myrow['Total'], ST_SALESINVOICE);
        //if ($words != "")
        //{
        //	$rep->NewLine(1);
        //	$rep->TextCol(1, 7, $myrow['curr_code'] . ": " . $words, - 2);
        //}
        //$rep->Font();
        if ($email == 1) {
            $rep->End($email);
        }
    }
    if ($email == 0) {
        $rep->End();
    }
}
Example #7
0
function supplier_settings(&$supplier_id)
{
    start_outer_table(TABLESTYLE2);
    table_section(1);
    if ($supplier_id) {
        //SupplierID exists - either passed when calling the form or from the form itself
        $myrow = get_supplier($_POST['supplier_id']);
        $_POST['supp_name'] = $myrow["supp_name"];
        $_POST['supp_ref'] = $myrow["supp_ref"];
        $_POST['address'] = $myrow["address"];
        $_POST['supp_address'] = $myrow["supp_address"];
        $_POST['gst_no'] = $myrow["gst_no"];
        $_POST['website'] = $myrow["website"];
        $_POST['supp_account_no'] = $myrow["supp_account_no"];
        $_POST['bank_account'] = $myrow["bank_account"];
        $_POST['dimension_id'] = $myrow["dimension_id"];
        $_POST['dimension2_id'] = $myrow["dimension2_id"];
        $_POST['curr_code'] = $myrow["curr_code"];
        $_POST['payment_terms'] = $myrow["payment_terms"];
        $_POST['credit_limit'] = price_format($myrow["credit_limit"]);
        $_POST['tax_group_id'] = $myrow["tax_group_id"];
        $_POST['tax_included'] = $myrow["tax_included"];
        $_POST['payable_account'] = $myrow["payable_account"];
        $_POST['purchase_account'] = $myrow["purchase_account"];
        $_POST['payment_discount_account'] = $myrow["payment_discount_account"];
        $_POST['notes'] = $myrow["notes"];
        $_POST['inactive'] = $myrow["inactive"];
    } else {
        $_POST['supp_name'] = $_POST['supp_ref'] = $_POST['address'] = $_POST['supp_address'] = $_POST['tax_group_id'] = $_POST['website'] = $_POST['supp_account_no'] = $_POST['notes'] = '';
        $_POST['dimension_id'] = 0;
        $_POST['dimension2_id'] = 0;
        $_POST['tax_included'] = 0;
        $_POST['sales_type'] = -1;
        $_POST['gst_no'] = $_POST['bank_account'] = '';
        $_POST['payment_terms'] = '';
        $_POST['credit_limit'] = price_format(0);
        $company_record = get_company_prefs();
        $_POST['curr_code'] = $company_record["curr_default"];
        $_POST['payable_account'] = $company_record["creditors_act"];
        $_POST['purchase_account'] = '';
        // default/item's cogs account
        $_POST['payment_discount_account'] = $company_record['pyt_discount_act'];
    }
    table_section_title(_("Basic Data"));
    text_row(_("Supplier Name:"), 'supp_name', null, 42, 40);
    text_row(_("Supplier Short Name:"), 'supp_ref', null, 30, 30);
    text_row(_("GSTNo:"), 'gst_no', null, 42, 40);
    link_row(_("Website:"), 'website', null, 35, 55);
    if ($supplier_id && !is_new_supplier($supplier_id) && (key_in_foreign_table($_POST['supplier_id'], 'supp_trans', 'supplier_id') || key_in_foreign_table($_POST['supplier_id'], 'purch_orders', 'supplier_id'))) {
        label_row(_("Supplier's Currency:"), $_POST['curr_code']);
        hidden('curr_code', $_POST['curr_code']);
    } else {
        currencies_list_row(_("Supplier's Currency:"), 'curr_code', null);
    }
    tax_groups_list_row(_("Tax Group:"), 'tax_group_id', null);
    text_row(_("Our Customer No:"), 'supp_account_no', null, 42, 40);
    table_section_title(_("Purchasing"));
    text_row(_("Bank Name/Account:"), 'bank_account', null, 42, 40);
    amount_row(_("Credit Limit:"), 'credit_limit', null);
    payment_terms_list_row(_("Payment Terms:"), 'payment_terms', null);
    //
    // tax_included option from supplier record is used directly in update_average_cost() function,
    // therefore we can't edit the option after any transaction waas done for the supplier.
    //
    if (is_new_supplier($supplier_id)) {
        check_row(_("Prices contain tax included:"), 'tax_included');
    } else {
        hidden('tax_included');
        label_row(_("Prices contain tax included:"), $_POST['tax_included'] ? _('Yes') : _('No'));
    }
    table_section_title(_("Accounts"));
    gl_all_accounts_list_row(_("Accounts Payable Account:"), 'payable_account', $_POST['payable_account']);
    gl_all_accounts_list_row(_("Purchase Account:"), 'purchase_account', $_POST['purchase_account'], false, false, _("Use Item Inventory/COGS Account"));
    gl_all_accounts_list_row(_("Purchase Discount Account:"), 'payment_discount_account', $_POST['payment_discount_account']);
    if (!$supplier_id) {
        table_section_title(_("Contact Data"));
        text_row(_("Phone Number:"), 'phone', null, 32, 30);
        text_row(_("Secondary Phone Number:"), 'phone2', null, 32, 30);
    }
    table_section(2);
    $dim = get_company_pref('use_dimension');
    if ($dim >= 1) {
        table_section_title(_("Dimension"));
        dimensions_list_row(_("Dimension") . " 1:", 'dimension_id', null, true, " ", false, 1);
        if ($dim > 1) {
            dimensions_list_row(_("Dimension") . " 2:", 'dimension2_id', null, true, " ", false, 2);
        }
    }
    if ($dim < 1) {
        hidden('dimension_id', 0);
    }
    if ($dim < 2) {
        hidden('dimension2_id', 0);
    }
    table_section_title(_("Addresses"));
    textarea_row(_("Mailing Address:"), 'address', null, 35, 5);
    textarea_row(_("Physical Address:"), 'supp_address', null, 35, 5);
    table_section_title(_("General"));
    textarea_row(_("General Notes:"), 'notes', null, 35, 5);
    if ($supplier_id) {
        record_status_list_row(_("Supplier status:"), 'inactive');
    } else {
        table_section_title(_("Contact Data"));
        text_row(_("Contact Person:"), 'contact', null, 42, 40);
        text_row(_("Fax Number:"), 'fax', null, 32, 30);
        email_row(_("E-mail:"), 'email', null, 35, 55);
        languages_list_row(_("Document Language:"), 'rep_lang', null, _('System default'));
    }
    end_outer_table(1);
    div_start('controls');
    if ($supplier_id) {
        submit_center_first('submit', _("Update Supplier"), _('Update supplier data'), @$_REQUEST['popup'] ? true : 'default');
        submit_return('select', get_post('supplier_id'), _("Select this supplier and return to document entry."));
        submit_center_last('delete', _("Delete Supplier"), _('Delete supplier data if have been never used'), true);
    } else {
        submit_center('submit', _("Add New Supplier Details"), true, '', 'default');
    }
    div_end();
}
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();
    }
}
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();
}
function print_summary()
{
    global $path_to_root;
    $sman = $_POST['PARAM_0'];
    $from = $_POST['PARAM_1'];
    $to = $_POST['PARAM_2'];
    $stat = $_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_report.inc";
    }
    $orientation = $orientation ? 'L' : 'P';
    $dec = user_price_dec();
    $cols = array(0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 520, 550);
    $headers = array(_('IMC'), _('Gross'), _('Returns'), _('% To Sales'), _('Net Sales'), _('Full Payment'), _('% To Sales'), _('Partial Payments'), _('% To Sales'), _('Accounts Receivables'), _('% To Sales'));
    $aligns = array('left', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right');
    $aligns2 = $aligns;
    $summary = 1;
    $rep = new FrontReport(_('Sales Status'), "Sales Status", user_pagesize(), 9, $orientation);
    if ($orientation == 'L') {
        recalculate_cols($cols);
    }
    $cols2 = $cols;
    $rep->Font();
    $rep->Info(null, $cols, $headers, $aligns);
    $rep->NewPage();
    $total = $grandtotal = 0.0;
    $total1 = $grandtotal1 = 0.0;
    $total2 = $grandtotal2 = 0.0;
    $catt = '';
    $slist = array();
    if ($sman == "") {
        $row = get_all_salesman();
        while ($r = db_fetch($row)) {
            array_push($slist, $r['salesman_code']);
        }
        foreach ($slist as $slists) {
            $res = getTransactions($from, $to, $slists, $stat);
        }
    } else {
        $res = getTransactions($from, $to, $sman, $stat);
    }
    $prev = '';
    while ($myrow = db_fetch($res)) {
        $current = $myrow['salesman_code'];
        if ($myrow['salesman_code'] != "") {
            if ($current == $prev) {
            } else {
            }
            $prev = $current;
        }
        $company_data = get_company_prefs();
        $branch = get_branch($myrow["branch_code"]);
        $branch_data = get_branch_accounts($myrow['branch_code']);
        $dt = get_discount($branch_data['sales_discount_account'], $myrow['type'], $myrow['trans_no']);
        $salesman = get_imc_code($myrow['branch_code']);
        $res2 = get_return_details($myrow['order_']);
        $returns = 0;
        $rtn_dt = 0;
        $credit_num = "";
        $cm_date = "";
        $num = db_num_rows($res2);
        $var = array();
        while ($myrow2 = db_fetch($res2)) {
            $returns += $myrow2['ov_amount'];
            if ($num > 1) {
                $credit_num .= $myrow2['customized_no'] . "/";
                $cm_date = $myrow2['tran_date'] . "/";
            } else {
                $credit_num .= $myrow2['customized_no'];
                $cm_date = $myrow2['tran_date'];
            }
            $var = array($myrow2['trans_no']);
        }
        foreach ($var as $vars) {
            $res2 = get_return_discount($branch_data['sales_discount_account'], ST_CUSTCREDIT, $vars);
            while ($myrow3 = db_fetch($res2)) {
                $rtn_dt += abs($myrow3['amount']);
            }
        }
        $total_returns = $returns + $rtn_dt;
        $return_discount = $rtn_dt / $total_returns * 100;
        $invoicetot = $myrow['ov_amount'] + $dt;
        $invoice_discount = $dt / $invoicetot * 100;
        $sales_discount = ($invoicetot - $total_returns) * ($invoice_discount / 100);
        $net_sales = $invoicetot - $total_returns - $sales_discount;
        $gross_commission = ($invoicetot - $total_returns) * ($myrow['commission'] / 100);
        $tot_invoice = $invoicetot - $invoicetot * ($invoice_discount / 100);
        if ($myrow['IsVoid'] == '') {
            $myrow4 = db_fetch(get_commission_details($myrow['type'], $myrow['trans_no']));
            $comm = ($invoicetot - $total_returns) * ($myrow4['commission'] / 100);
            $partial_payment = 0;
            $zero;
            $or = get_pr_details($myrow['type'], $myrow['trans_no']);
            $ref = '';
            $num2 = db_num_rows($or);
            $date_alloc = '';
            $ctr = 0;
            $bal = 0;
            $bal1 = 0;
            $bal2 = 0;
            $ppayment = 0;
            $fpayment = 0;
            $all_bal = 0;
            $payment = get_total_payment($myrow['type'], $myrow['trans_no']);
            while ($pr = db_fetch($or)) {
                $partial_payment += $pr['amt'];
                $date_alloc = $pr['prDate'] . " ";
                $pr_number = $pr['customized_no'] . " ";
                $ref = $pr['reference'];
                $net_remittance = $net_sales - $partial_payment;
                $ctr++;
                if ($num2 > 1) {
                    $bal = $net_sales - $partial_payment;
                    if (number_format($payment, 2) == number_format($net_sales, 2)) {
                        $fpayment += $pr['amt'];
                    } else {
                        $ppayment += $pr['amt'];
                        $all_bal += $bal;
                    }
                } else {
                    $bal = $net_sales - $partial_payment;
                    if ($bal == 0) {
                        $bal = number_format($net_sales, 2) - number_format($partial_payment, 2);
                        $fpayment += $partial_payment;
                        $bal1 += $bal;
                    } else {
                        $bal = $net_sales - $pr['amt'];
                        $ppayment += $partial_payment;
                        $bal2 += $bal;
                    }
                }
                if ($num2 > 1) {
                    $rep->NewLine();
                }
            }
            $net_invoice += $invoicetot;
            $net_discount += $sales_discount;
            $net_returns += $total_returns;
            $sale_amount += $net_sales;
            $net_partial += $ppayment;
            $net_rem += $net_remittance;
            $net_bal += $bal;
            $net_balance = $net_rem + $net_bal;
            $net_comm += $comm;
            $net_tax += $myrow4['with_tax'];
            $net_net_comm += $myrow4['net_commission'];
            $net_full_payment += $fpayment;
        }
    }
    $Percentage1 = $net_returns / $net_invoice * 100;
    $NetSales = $net_invoice - $net_returns;
    $Percentage2 = $net_full_payment / $NetSales * 100;
    $Percentage3 = $net_partial / $NetSales * 100;
    $ReceivablesTotal = $NetSales - $net_full_payment - $net_partial;
    $Percentage4 = $ReceivablesTotal / $NetSales * 100;
    $rep->Font('bold');
    $rep->NewLine();
    $rep->TextCol(0, 1, $salesman);
    $rep->AmountCol(1, 2, $net_invoice, 2);
    $rep->AmountCol(2, 3, $net_returns, 2);
    $rep->AmountCol(3, 4, $Percentage1, 2);
    $rep->AmountCol(4, 5, $NetSales, 2);
    $rep->AmountCol(5, 6, $net_full_payment, 2);
    $rep->AmountCol(6, 7, $Percentage2, 2);
    $rep->AmountCol(7, 8, $net_partial, 2);
    $rep->AmountCol(8, 9, $Percentage3, 2);
    $rep->AmountCol(9, 10, $ReceivablesTotal, 2);
    $rep->AmountCol(10, 11, $Percentage4, 2);
    $rep->NewLine();
    $rep->End();
}
Example #11
0
function print_invoices()
{
    global $path_to_root, $alternative_tax_include_on_docs, $suppress_tax_rates, $no_zero_lines_amount;
    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'];
    $pay_service = $_POST['PARAM_4'];
    $comments = $_POST['PARAM_5'];
    $customer = $_POST['PARAM_6'];
    $orientation = $_POST['PARAM_7'];
    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(-18, 40, 60, 100, 160, 200, 260, 360, 420, 450, 500);
    // $headers in doctext.inc
    $aligns = array('left', 'left', 'left', 'left', 'right', 'right', 'right', 'right', 'right', 'right', 'right');
    //$params = array('comments' => $comments);
    $cur = get_company_Pref('curr_default');
    $company_data = get_company_prefs();
    if ($email == 0) {
        $rep = new FrontReport(_('INVOICE'), "InvoiceBulk", user_pagesize(), 9, $orientation);
    }
    if ($orientation == 'L') {
        recalculate_cols($cols);
    }
    for ($i = $from; $i <= $to; $i++) {
        if (!exists_customer_trans(ST_SALESINVOICE, $i)) {
            continue;
        }
        $sign = 1;
        $myrow = get_customer_trans($i, ST_SALESINVOICE);
        if ($customer && $myrow['debtor_no'] != $customer) {
            continue;
        }
        $baccount = get_default_bank_account($myrow['curr_code']);
        $params['bankaccount'] = $baccount['id'];
        $branch = get_branch($myrow["branch_code"]);
        $sales_order = get_sales_order_header($myrow["order_"], ST_SALESORDER);
        if ($email == 1) {
            $rep = new FrontReport("", "", user_pagesize(), 9, $orientation);
            //$rep->title = _('INVOICE');
            $rep->filename = "Invoice" . $myrow['reference'] . ".pdf";
        }
        $rep->SetHeaderType(0);
        $rep->currency = $cur;
        $rep->Font();
        $rep->Info(null, $cols, null, $aligns);
        $salesman = get_imc_code($branch['branch_code']);
        $pay_term = get_payment_terms($myrow['payment_terms']);
        $branch_data = get_branch_accounts($myrow['branch_code']);
        $invoice_no = get_custom_no($myrow['trans_no'], $myrow['type']);
        $contact = getContact($myrow['salesman'], $myrow['debtor_no'], $branch['branch_code']);
        $cnumber = getContactNumber($myrow['salesman'], $myrow['debtor_no'], $branch['branch_code']);
        $rep->NewPage();
        $result = get_customer_trans_details(ST_SALESINVOICE, $i);
        $SubTotal = 0;
        $rep->NewLine(6);
        $rep->TextCol(2, 7, $invoice_no);
        $rep->TextCol(6, 8, $myrow['TranDate']);
        $rep->NewLine();
        $rep->TextCol(2, 7, $branch['br_name']);
        $rep->TextCol(7, 8, $myrow['bulk_discount'] . "%");
        $rep->NewLine();
        $rep->TextCol(2, 7, $branch['branch_ref']);
        $rep->TextCol(6, 8, $salesman);
        $rep->NewLine();
        $rep->TextCol(2, 6, $contact . " - " . $cnumber);
        if ($pay_term['terms'] == 'C.O.D.' || $pay_term['Cash Only']) {
            $rep->TextCol(7, 8, $pay_term['terms'], -2);
        } else {
            $oldrow = $rep->row;
            $newrow = $rep->row;
            $rep->TextColLines(7, 9, $pay_term['terms'], -2);
            $newrow = $rep->row;
            $rep->row = $oldrow;
        }
        $rep->NewLine();
        $oldrow = $rep->row;
        $newrow = $rep->row;
        $rep->TextColLines(2, 6, $branch['br_address'], -2);
        $rep->row = $oldrow;
        $rep->NewLine(4);
        $rep->Font();
        while ($myrow2 = db_fetch($result)) {
            if ($myrow2["quantity"] == 0) {
                continue;
            }
            $Net = round2($sign * ((1 - $myrow2["discount_percent"]) * $myrow2["unit_price"] * $myrow2["quantity"]), user_price_dec());
            $Net2 = round2($sign * ($myrow2["unit_price"] * $myrow2["quantity"]), user_price_dec());
            $SubTotal += $Net;
            $DisplayPrice = number_format2($myrow2["unit_price"], 2);
            $DisplayQty = number_format2($sign * $myrow2["quantity"], get_qty_dec($myrow2['stock_id']));
            $DisplayNet = number_format2($Net, 2);
            $dNet = number_format2($Net2, 2);
            $oldrow = $rep->row;
            $rep->TextColLines(-0.75, 4, $myrow2['StockDescription'], -2);
            $newrow = $rep->row;
            $rep->row = $oldrow;
            if ($Net != 0.0 || !is_service($myrow2['mb_flag']) || !isset($no_zero_lines_amount) || $no_zero_lines_amount == 0) {
                $rep->TextCol(4, 5, $DisplayQty . " " . $myrow2['units']);
                $rep->TextCol(5, 6, $DisplayPrice, -2);
                $rep->TextCol(6, 8, $dNet, -2);
            }
            $rep->row = $newrow;
            if ($rep->row < $rep->bottomMargin + 15 * $rep->lineHeight) {
                $rep->NewPage();
            }
        }
        $memo = get_comments_string(ST_SALESINVOICE, $i);
        if ($memo != "") {
            $rep->NewLine();
            $rep->TextColLines(1, 5, $memo, -2);
        }
        $DisplayNet = number_format2($SubTotal, 2);
        $DisplaySubTot = number_format2($SubTotal, 2);
        $DisplayTots = number_format2($myrow['Total'], 2);
        $DisplayDiscount = number_format2($SubTotal * ($myrow['bulk_discount'] / 100), 2);
        $rep->NewLine(3);
        $doctype = ST_SALESINVOICE;
        $rep->NewLine();
        $rep->Font('bold');
        $rep->TextCol(6, 7, "TOTAL AMOUNT :");
        $rep->TextCol(6, 8, $DisplayNet, -2);
        $rep->NewLine();
        $rep->TextCol(6, 7, "VOLUME DISCOUNT :");
        $rep->TextCol(5, 8, $DisplayDiscount, -2);
        $rep->NewLine();
        $rep->TextCol(6, 7, _("NET AMOUNT : "), -2);
        $rep->TextCol(5, 8, $DisplayTots, -2);
        $rep->NewLine();
        if ($email == 1) {
            $rep->End($email);
        }
    }
    if ($email == 0) {
        $rep->End();
    }
}
function print_summary()
{
    global $path_to_root;
    $imc = $_POST['PARAM_0'];
    $from = $_POST['PARAM_1'];
    $to = $_POST['PARAM_2'];
    $status = $_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_report.inc";
    }
    $orientation = $orientation ? 'L' : 'P';
    $dec = user_price_dec();
    $cols = array(0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 520, 550);
    $headers = array(_('IMC'), _('Gross'), _('Returns'), _('Discount'), _('% To Sales'), _('Net Sales'), _('Full Payment'), _('% To Sales'), _('Partial Payments'), _('% To Sales'), _('Accounts Receivables'), _('% To Sales'));
    $aligns = array('left', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right');
    $aligns2 = $aligns;
    $summary = 1;
    $rep = new FrontReport(_('Sales Status'), "Sales Status", user_pagesize(), 9, $orientation);
    if ($orientation == 'L') {
        recalculate_cols($cols);
    }
    $cols2 = $cols;
    $rep->Font();
    $rep->Info(null, $cols, $headers, $aligns);
    $rep->NewPage();
    $result = getTransactions($imc, $from, $to, ST_SALESINVOICE, $status);
    $InvoiceTotal = 0;
    $TotalReturn = 0;
    $DiscountTotal = 0;
    $NetSales = 0;
    $FullAlloc = 0;
    $PartialAlloc = 0;
    $ReceivablesTotal = 0;
    $Percentage1 = 0;
    $Percentage2 = 0;
    $Percentage3 = 0;
    $Percentage4 = 0;
    $TotalInvoice = 0;
    $TotalReturn_2 = 0;
    $TotalSales = 0;
    $TotalFullAlloc = 0;
    $TotalPartialAlloc = 0;
    $TotalReceivables = 0;
    $TotalDiscount = 0;
    $previous = '';
    while ($myrow = db_fetch($result)) {
        $company_data = get_company_prefs();
        $imc = $myrow['imc_code'];
        $imc_code = $myrow['salesman_code'];
        $DiscountTotal = getDiscountTotal($imc_code, $from, $to, ST_SALESINVOICE, get_company_pref('default_sales_discount_act'), $status);
        $ReturnDiscount = getDiscountTotal($imc_code, $from, $to, ST_CUSTCREDIT, get_company_pref('default_sales_discount_act'), $status);
        $InvoiceTotal = $myrow['InvoiceTotal'] + $DiscountTotal;
        $TotalDiscount = $ReturnDiscount + $DiscountTotal;
        $net_partial = 0;
        $net_full_payment = 0;
        $TotalReturn = 0;
        $Transact = getAllocTransact($from, $to, $imc_code, $status);
        while ($row = db_fetch($Transact)) {
            $branch = get_branch($row["branch_code"]);
            $branch_data = get_branch_accounts($row['branch_code']);
            $dt = get_discount($branch_data['sales_discount_account'], $row['type'], $row['trans_no']);
            $res2 = get_return_details($row['order_']);
            $returns = 0;
            $rtn_dt = 0;
            $num = db_num_rows($res2);
            $var = array();
            while ($myrow2 = db_fetch($res2)) {
                $returns += $myrow2['ov_amount'];
                $var = array($myrow2['trans_no']);
            }
            foreach ($var as $vars) {
                $res2 = get_return_discount($branch_data['sales_discount_account'], ST_CUSTCREDIT, $vars);
                while ($myrow3 = db_fetch($res2)) {
                    $rtn_dt += abs($myrow3['amount']);
                }
            }
            $total_returns = $returns + $rtn_dt;
            $return_discount = $rtn_dt / $total_returns * 100;
            $TotalReturn += $total_returns;
            $invoicetot = $row['ov_amount'] + $dt;
            $invoice_discount = $dt / $invoicetot * 100;
            $sales_discount = ($invoicetot - $total_returns) * ($invoice_discount / 100);
            $net_sales = $invoicetot - $total_returns - $sales_discount;
            if ($row['IsVoid'] == '') {
                $partial_payment = 0;
                $zero;
                $or = get_pr_details($row['type'], $row['trans_no']);
                $num2 = db_num_rows($or);
                $date_alloc = '';
                $ctr = 0;
                $bal = 0;
                $bal1 = 0;
                $bal2 = 0;
                $ppayment = 0;
                $fpayment = 0;
                $all_bal = 0;
                $payment = get_total_payment($row['type'], $row['trans_no']);
                while ($pr = db_fetch($or)) {
                    $partial_payment += $pr['amt'];
                    $ctr++;
                    if ($num2 > 1) {
                        $bal = $net_sales - $partial_payment;
                        if (number_format($payment, 2) == number_format($net_sales, 2)) {
                            if ($status == 1 || $status == "" || $status == 0) {
                                $fpayment += $pr['amt'];
                            }
                        } else {
                            if ($status == 2 || $status == "" || $status == 0) {
                                $ppayment += $pr['amt'];
                                $all_bal += $bal;
                            }
                        }
                    } else {
                        $bal = $net_sales - $partial_payment;
                        if ($bal == 0) {
                            $bal = number_format($net_sales, 2) - number_format($partial_payment, 2);
                            if ($status == 1 || $status == "" || $status == 0) {
                                $fpayment += $partial_payment;
                                $bal1 += $bal;
                            }
                        } else {
                            $bal = $net_sales - $pr['amt'];
                            if ($status == 2 || $status == "" || $status == 0) {
                                $ppayment += $partial_payment;
                                $bal2 += $bal;
                            }
                        }
                    }
                }
                $net_partial += $ppayment;
                $net_full_payment += $fpayment;
            }
        }
        $Percentage1 = $TotalReturn / $InvoiceTotal * 100;
        $NetSales = $InvoiceTotal - $TotalReturn;
        $Percentage2 = $net_full_payment / $NetSales * 100;
        $Percentage3 = $net_partial / $NetSales * 100;
        $ReceivablesTotal = $NetSales - $fpayment - $ppayment;
        $Percentage4 = $ReceivablesTotal / $NetSales * 100;
        $rep->TextCol(0, 1, $myrow['imc_code']);
        $rep->AmountCol(1, 2, $InvoiceTotal, 2);
        $rep->AmountCol(2, 3, $TotalReturn, 2);
        $rep->AmountCol(3, 4, $TotalDiscount, 2);
        $rep->AmountCol(4, 5, $Percentage1, 2);
        $rep->AmountCol(5, 6, $NetSales, 2);
        $rep->AmountCol(6, 7, $net_full_payment, 2);
        $rep->AmountCol(7, 8, $Percentage2, 2);
        $rep->AmountCol(8, 9, $net_partial, 2);
        $rep->AmountCol(9, 10, $Percentage3, 2);
        if ($status != 1) {
            $rep->AmountCol(10, 11, $ReceivablesTotal, 2);
        }
        $rep->AmountCol(11, 12, $Percentage4, 2);
        $rep->NewLine();
        $TotalInvoice += $InvoiceTotal;
        $TotalReturn_2 += $TotalReturn;
        $TotalSales += $NetSales;
        $TotalFullAlloc += $net_full_payment;
        $TotalPartialAlloc += $net_partial;
        if ($status != 1) {
            $TotalReceivables += $ReceivablesTotal;
        }
    }
    $rep->NewLine();
    $rep->Font('bold');
    $rep->TextCol(0, 1, "TOTAL");
    $rep->AmountCol(1, 2, $TotalInvoice, 2);
    $rep->AmountCol(2, 3, $TotalReturn_2, 2);
    $rep->AmountCol(5, 6, $TotalSales, 2);
    $rep->AmountCol(6, 7, $TotalFullAlloc, 2);
    $rep->AmountCol(8, 9, $TotalPartialAlloc, 2);
    $rep->AmountCol(10, 11, $TotalReceivables, 2);
    $rep->NewLine();
    $rep->NewLine();
    $rep->End();
}
    if (empty($_POST['smtp_password']) && $_POST['mail_type'] == 'SMTP') {
        $errors++;
        display_error(_("The SMTP password must be entered."));
    }
    return $errors == 0;
}
//-------------------------------------------------------------------------------------------------
if (isset($_POST['submit']) && can_process()) {
    update_company_prefs(get_post(array('mail_type', 'smtp_host', 'smtp_port', 'smtp_auth', 'smtp_secure', 'smtp_username', 'smtp_password')));
    display_notification(_("The mail sending settings has been updated."));
}
/* end of if submit */
if (list_updated('mail_type')) {
    $Ajax->activate('details');
}
$prefs = get_company_prefs();
if (!isset($_POST['mail_type'])) {
    $_POST['mail_type'] = $prefs['mail_type'];
}
$_POST['smtp_host'] = $prefs['smtp_host'];
$_POST['smtp_port'] = $prefs['smtp_port'];
$_POST['smtp_secure'] = $prefs['smtp_secure'];
$_POST['smtp_username'] = $prefs['smtp_username'];
$_POST['smtp_password'] = $prefs['smtp_password'];
//-------------------------------------------------------------------------------------------------
start_form();
start_table(TABLESTYLE_NOBORDER);
start_row();
$_selector = array_selector('mail_type', $_POST['mail_type'], array('MAIL' => 'PHP\'s mail function', 'SMTP' => 'SMTP server'), array('select_submit' => true));
label_cells(_("Mail type:"), $_selector);
end_row();
function print_cash_sale()
{
    global $path_to_root;
    $from = $_POST['PARAM_0'];
    $destination = $_POST['PARAM_1'];
    if ($destination) {
        include_once $path_to_root . "/reporting/includes/excel_report.inc";
    } else {
        include_once $path_to_root . "/reporting/includes/pdf_report.inc";
    }
    $dec = user_price_dec();
    if ($category == ALL_NUMERIC) {
        $category = 0;
    }
    if ($category == 0) {
        $cat = _('All');
    } else {
        $cat = get_category_name($category);
    }
    $cols = array(0, 50, 250, 350, 400, 450, 500, 550, 600, 700, 750, 800, 850, 900, 950, 1000, 1050, 1100, 1150, 1200);
    $headers = array(_('DATE'), _('CLIENT NAME'), _('IMC'), _('CASH SALES'), _('INVOICE'), _('CASH'), _('SALES'), _('RETURNS'), _('SALES DISCOUNT'), _('SUNDRIES'), _('DR'), _('CR'));
    $header2 = array(_(''), '', _('CODE'), _('INVOICE'), _('AMOUNT'), _('DR'), _('CR'), _(' DR'), _('DR'), _(''), _(''));
    $aligns = array('left', 'left', 'center', 'left', 'right', 'right', 'right', 'right', 'right', 'right', 'right', 'right');
    $params = array(0 => $comments, 1 => array('text' => _('Period'), 'from' => $from, 'to' => $to), 2 => array('text' => _('Category'), 'from' => $cat, 'to' => ''));
    $rep = new FrontReport(_('Cash Sales Report'), "CashSalesReport", user_pagesize(), 8, 'L');
    $rep->Font();
    $rep->Info($params, $cols, $header2, $aligns, $cols, $headers, $aligns);
    $rep->NewPage();
    $res = getTransactions($from);
    while ($myrow = db_fetch($res)) {
        $company_data = get_company_prefs();
        $branch = get_branch($myrow["branch_code"]);
        $branch_data = get_branch_accounts($myrow['branch_code']);
        $dt = get_discount($branch_data['sales_discount_account'], $myrow['type'], $myrow['trans_no']);
        $sales_acct = get_discount($branch_data['sales_account'], $myrow['type'], $myrow['trans_no']);
        $salesman = get_imc_code($myrow['branch_code']);
        $invoicetot = $myrow['ov_amount'] + $dt;
        $invoice_discount = $dt / $invoicetot * 100;
        $rep->TextCol(0, 1, $myrow['tranDate']);
        $rep->TextCol(1, 2, $myrow['br_name']);
        $rep->TextCol(2, 3, $salesman);
        $rep->TextCol(3, 4, $myrow['customized_no']);
        if ($myrow['IsVoid'] == '') {
            $rep->AmountCol(4, 5, $invoicetot, 2);
            $rep->AmountCol(5, 6, $myrow['ov_amount'], 2);
            $rtn_dt = 0;
            $res2 = get_return_details($myrow['order_']);
            while ($myrow2 = db_fetch($res2)) {
                $returns += $myrow2['ov_amount'];
                $res2 = get_return_discount($branch_data['sales_discount_account'], $myrow2['type'], $myrow2['trans_no']);
                while ($myrow3 = db_fetch($res2)) {
                    $rtn_dt += abs($myrow3['amount']);
                }
            }
            $net_sales = abs($sales_acct) - $dt - $rtn_dt;
            $rep->AmountCol(6, 7, $net_sales, 2);
            if ($rtn_dt != 0) {
                $rep->AmountCol(7, 8, $rtn_dt, 2);
            }
            if ($dt != 0) {
                $rep->AmountCol(8, 9, $dt, 2);
            }
            $rep->NewLine();
        } else {
            $rep->TextCol(4, 5, "Voided");
        }
        $net_invoice += $invoicetot;
        $net_dr += $myrow['ov_amount'];
        $net_cr += $net_sales;
        $net_return += $rtn_dt;
        $net_ret_dt += $dt;
    }
    $rep->NewLine();
    $rep->Font('bold');
    $rep->TextCol(1, 2, "TOTAL");
    $rep->AmountCol(4, 5, $net_invoice, 2);
    $rep->AmountCol(5, 6, $net_dr, 2);
    $rep->AmountCol(6, 7, $net_cr, 2);
    $rep->AmountCol(7, 8, $net_return, 2);
    $rep->AmountCol(8, 9, $net_ret_dt, 2);
    $rep->End();
}
Example #15
0
function branch_settings($selected_id)
{
    global $Mode, $num_branches;
    start_outer_table(TABLESTYLE2);
    table_section(1);
    $_POST['email'] = "";
    if ($selected_id != -1) {
        if ($Mode == 'Edit' || !isset($_POST['br_name'])) {
            //editing an existing branch
            $myrow = get_cust_branch($_POST['customer_id'], $_POST['branch_code']);
            set_focus('br_name');
            $_POST['branch_code'] = $myrow["branch_code"];
            $_POST['br_name'] = $myrow["br_name"];
            $_POST['br_ref'] = $myrow["branch_ref"];
            $_POST['br_address'] = $myrow["br_address"];
            $_POST['br_post_address'] = $myrow["br_post_address"];
            //		    $_POST['contact_name'] = $myrow["contact_name"];
            $_POST['salesman'] = $myrow["salesman"];
            $_POST['area'] = $myrow["area"];
            //		    $_POST['rep_lang'] =$myrow["rep_lang"];
            //		    $_POST['phone'] =$myrow["phone"];
            //		    $_POST['phone2'] =$myrow["phone2"];
            //		    $_POST['fax'] =$myrow["fax"];
            //		    $_POST['email'] =$myrow["email"];
            $_POST['tax_group_id'] = $myrow["tax_group_id"];
            $_POST['disable_trans'] = $myrow['disable_trans'];
            $_POST['default_location'] = $myrow["default_location"];
            $_POST['default_ship_via'] = $myrow['default_ship_via'];
            $_POST['sales_account'] = $myrow["sales_account"];
            $_POST['sales_discount_account'] = $myrow['sales_discount_account'];
            $_POST['receivables_account'] = $myrow['receivables_account'];
            $_POST['payment_discount_account'] = $myrow['payment_discount_account'];
            $_POST['group_no'] = $myrow["group_no"];
            $_POST['notes'] = $myrow["notes"];
        }
    } elseif ($Mode != 'ADD_ITEM') {
        //end of if $SelectedBranch only do the else when a new record is being entered
        $myrow = get_default_info_for_branch($_POST['customer_id']);
        //		$_POST['rep_lang'] = $myrow['rep_lang'];
        if (!$num_branches) {
            $_POST['br_name'] = $myrow["name"];
            $_POST['br_ref'] = $myrow["debtor_ref"];
            $_POST['contact_name'] = _('Main Branch');
            $_POST['br_address'] = $_POST['br_post_address'] = $myrow["address"];
        }
        $_POST['branch_code'] = "";
        if (!isset($_POST['sales_account']) || !isset($_POST['sales_discount_account'])) {
            $company_record = get_company_prefs();
            // We use the Item Sales Account as default!
            // $_POST['sales_account'] = $company_record["default_sales_act"];
            $_POST['sales_account'] = $_POST['notes'] = '';
            $_POST['sales_discount_account'] = $company_record['default_sales_discount_act'];
            $_POST['receivables_account'] = $company_record['debtors_act'];
            $_POST['payment_discount_account'] = $company_record['default_prompt_payment_act'];
        }
    }
    hidden('popup', @$_REQUEST['popup']);
    table_section_title(_("Name and Contact"));
    text_row(_("Branch Name:"), 'br_name', null, 35, 40);
    text_row(_("Branch Short Name:"), 'br_ref', null, 30, 30);
    table_section_title(_("Sales"));
    sales_persons_list_row(_("Sales Person:"), 'salesman', null);
    sales_areas_list_row(_("Sales Area:"), 'area', null);
    sales_groups_list_row(_("Sales Group:"), 'group_no', null, true);
    locations_list_row(_("Default Inventory Location:"), 'default_location', null);
    shippers_list_row(_("Default Shipping Company:"), 'default_ship_via', null);
    tax_groups_list_row(_("Tax Group:"), 'tax_group_id', null);
    table_section_title(_("GL Accounts"));
    // 2006-06-14. Changed gl_al_accounts_list to have an optional all_option 'Use Item Sales Accounts'
    gl_all_accounts_list_row(_("Sales Account:"), 'sales_account', null, false, false, true);
    gl_all_accounts_list_row(_("Sales Discount Account:"), 'sales_discount_account');
    gl_all_accounts_list_row(_("Accounts Receivable Account:"), 'receivables_account', null, true);
    gl_all_accounts_list_row(_("Prompt Payment Discount Account:"), 'payment_discount_account');
    table_section(2);
    if ($selected_id == -1) {
        table_section_title(_("General contact data"));
        text_row(_("Contact Person:"), 'contact_name', null, 35, 40);
        text_row(_("Phone Number:"), 'phone', null, 32, 30);
        text_row(_("Secondary Phone Number:"), 'phone2', null, 32, 30);
        text_row(_("Fax Number:"), 'fax', null, 32, 30);
        email_row(_("E-mail:"), 'email', null, 35, 55);
        languages_list_row(_("Document Language:"), 'rep_lang', null, _("Customer default"));
    }
    table_section_title(_("Addresses"));
    textarea_row(_("Mailing Address:"), 'br_post_address', null, 35, 4);
    textarea_row(_("Billing Address:"), 'br_address', null, 35, 4);
    textarea_row(_("General Notes:"), 'notes', null, 35, 4);
    if ($selected_id != -1) {
        yesno_list_row(_("Disable this Branch:"), 'disable_trans', null);
    }
    end_outer_table(1);
    submit_add_or_update_center($selected_id == -1, '', 'both');
}
    hidden('sales_id', $_POST['sales_id']);
    end_row();
    end_table();
    div_end();
    if (get_post('_show_inactive_update')) {
        $Ajax->activate('imc');
        set_focus('imc');
    }
} else {
    display_error("Enter some IMC/Salesman.");
    hidden('imc');
}
$edit_id = find_submit("Edit");
if ($edit_id != -1) {
    $myrow = db_fetch(get_selected_salesman($edit_id));
    $company_data = get_company_prefs();
    $branch = get_branch($myrow["branch_code"]);
    $branch_data = get_branch_accounts($myrow['branch_code']);
    clear_data();
    $_POST['sales'] = $myrow['salesman_name'];
    //get imc name
    $_POST['invoice_no'] = $myrow['customized_no'];
    //get invoice number
    $_POST['client'] = $myrow['br_name'];
    //get customer name
    $_POST['br_id'] = $myrow['debtor_no'];
    $_POST['order_no'] = $myrow['order_'];
    $dt = get_discount($branch_data['sales_discount_account'], $myrow['type'], $myrow['trans_no']);
    $res = get_returns($_POST['order_no']);
    while ($myrow2 = db_fetch($res)) {
        $rtn += $myrow2['ov_amount'];