Example #1
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 #2
0
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'];
    $cat = $_POST['PARAM_2'];
    $account = $_POST['PARAM_3'];
    $account2 = $_POST['PARAM_4'];
    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, L);
    $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, 50, 140, 200, 210, 400, 450, 550, 600, 650);
    //------------0--1---2-----3----4----5----6----7----8----9----10-------
    //-----------------------dim1-dim2-----------------------------------
    //-----------------------dim1----------------------------------------
    //-------------------------------------------------------------------
    $aligns = array('left', 'left', 'left', 'left', 'left', 'right', 'right', 'right', 'right', 'right');
    //$headers = array(_('ID'), '', '', '', '', '', '', _('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('header3');
    $rep->Font();
    $rep->Info($params, $cols, $headers, $aligns);
    $rep->NewPage();
    if ($cat == 3) {
        $person = get_salesman_name($account);
    }
    if ($cat == 1) {
        $person = get_supplier_name($account);
    }
    /*$rep->TextCol(0,2, $cat);
      $rep->NewLine();*/
    $rep->Font('bold');
    $rep->TextCol(0, 2, "Name:" . $person);
    $rep->NewLine();
    $rep->TextCol(0, 1, "ID:");
    $rep->TextCol(1, 2, "Src:");
    $rep->TextCol(2, 3, "Date:");
    $rep->TextCol(4, 5, "Memo:");
    $rep->TextCol(5, 6, "Account:");
    $rep->TextCol(6, 7, "Debit:");
    $rep->TextCol(8, 9, "Credit:");
    $rep->Font();
    $rep->NewLine(2);
    $result = getTransaction($from, $to, $cat, $account, $account2);
    $type = '';
    while ($myrow = db_fetch($result)) {
        if ($myrow['Voided'] == '' && $myrow['amount'] > 0) {
            $comments = get_comments_string($myrow['type'], $myrow['type_no']);
            $custom = get_custom_no($myrow['type_no'], $myrow['type']);
            if ($myrow['type'] == ST_DISBURSEMENT) {
                $type = "CD";
            }
            if ($myrow['type'] == ST_PURCHASEORDER) {
                $type = "P.O.";
            }
            if ($myrow['type'] == ST_SUPPAYMENT) {
                $type = "CD";
            }
            //else
            //    $type = $systypes_array[$myrow["type"]];
            $rep->TextCol(0, 1, "#" . $custom);
            $rep->TextCol(1, 2, $type);
            $rep->TextCol(2, 3, $myrow['tranDate']);
            $rep->TextCol(4, 5, $comments);
            $rep->TextCol(5, 6, $myrow['account']);
            $dr += $myrow['amount'];
            $rep->AmountCol(6, 7, $myrow['amount'], 2);
            $rep->NewLine();
        } else {
            if ($myrow['Voided'] == '' && $myrow['amount'] < 0) {
                $cr += $myrow['amount'];
                //$rep->AmountCol(8,9, $myrow['amount'], 2);
            }
        }
    }
    $rep->NewLine(2);
    $rep->Font('bold');
    $rep->AmountCol(6, 7, $dr, 2);
    $rep->NewLine(2);
    $rep->TextCol(1, 2, "Net Activity: ");
    $rep->AmountCol(2, 4, $cr, 2);
    $rep->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();
    }
}
    $new = 0;
    $myrow = get_customer_trans($_POST['trans_no'], ST_CUSTPAYMENT);
    $_POST['customer_id'] = $myrow["debtor_no"];
    $_POST['customer_name'] = $myrow["DebtorName"];
    $_POST['BranchID'] = $myrow["branch_code"];
    $_POST['bank_account'] = $myrow["bank_act"];
    $_POST['ref'] = $myrow["reference"];
    $old_ref = $myrow["reference"];
    $charge = get_cust_bank_charge(ST_CUSTPAYMENT, $_POST['trans_no']);
    $_POST['charge'] = price_format($charge);
    $_POST['DateBanked'] = sql2date($myrow['tran_date']);
    $_POST["amount"] = price_format($myrow['Total'] - $myrow['ov_discount']);
    $_POST["bank_amount"] = price_format($myrow['bank_amount'] + $charge);
    $_POST["discount"] = price_format($myrow['ov_discount']);
    $_POST["memo_"] = get_comments_string(ST_CUSTPAYMENT, $_POST['trans_no']);
    $ornum = get_custom_no($_POST['trans_no'], ST_CUSTPAYMENT);
    $ordate = get_custom_date($_POST['trans_no'], ST_CUSTPAYMENT);
    $_POST['or_num'] = $ornum;
    //moodlearning
    $_POST['or_date'] = sql2date($ordate);
    //moodlearning
    //Prepare allocation cart
    if (isset($_POST['trans_no']) && $_POST['trans_no'] > 0) {
        $_SESSION['alloc'] = new allocation(ST_CUSTPAYMENT, $_POST['trans_no']);
    } else {
        $_SESSION['alloc'] = new allocation(ST_CUSTPAYMENT, 0);
        $Ajax->activate('alloc_tbl');
    }
}
//----------------------------------------------------------------------------------------------
$new = !$_SESSION['alloc']->trans_no;
Example #5
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(-15, 10, 30, 50, 80, 240, 300, 340, 360, 400);
    // $headers in doctext.inc
    $aligns = array('right', 'left', 'left', 'left', 'left', 'left', 'right', 'right', 'right', 'right');
    $params = array('comments' => $comments);
    $cur = get_company_Pref('curr_default');
    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"]);
        $salesm = get_salesman_name($branch['salesman']);
        $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;
        $rep->SetCommonData($myrow, $branch, $sales_order, $baccount, ST_SALESINVOICE, $contacts);
        $rep->NewPage();
        $result = get_customer_trans_details(ST_SALESINVOICE, $i);
        $SubTotal = 0;
        $invoice_no = get_custom_no($myrow['trans_no'], ST_SALESINVOICE);
        $rep->NewLine(5);
        $rep->TextCol(2, 5, $branch['br_name']);
        $rep->TextCol(7, 9, $myrow['TranDate']);
        $rep->NewLine();
        $rep->TextCol(2, 10, $branch['br_address']);
        $rep->TextCol(7, 9, "SI - " . $invoice_no);
        $rep->NewLine();
        $rep->TextCol(0, 2, "Contact: ");
        $rep->TextCol(2, 5, $contacts["name"] . $contacts["name2"]);
        $rep->TextCol(6, 9, "IMC: " . $salesm);
        $rep->NewLine();
        $rep->TextCol(2, 5, "");
        $rep->NewLine();
        $rep->TextCol(2, 5, "");
        $rep->NewLine(3);
        //$rep->NewLine(2);
        $ent = 0;
        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());
            $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);
            if ($myrow2["discount_percent"] == 0) {
                $DisplayDiscount = "";
            } else {
                $DisplayDiscount = number_format2($myrow2["discount_percent"] * 100, 2) . "%";
            }
            //$rep->TextCol(3, 4,	$myrow2['stock_id'], -2);
            $oldrow = $rep->row;
            $rep->TextColLines(4, 6, $myrow2['StockDescription'], -2);
            $newrow = $rep->row;
            $rep->row = $oldrow;
            $ent++;
            if ($Net != 0.0 || !is_service($myrow2['mb_flag']) || !isset($no_zero_lines_amount) || $no_zero_lines_amount == 0) {
                $rep->TextCol(2, 3, $DisplayQty, -2);
                $rep->TextCol(3, 4, $myrow2['units'], -2);
                $rep->TextCol(6, 7, $DisplayPrice, -2);
                $rep->TextCol(7, 9, $DisplayNet, -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);
        }
        $DisplaySubTot = $SubTotal;
        $rep->NewLine(8 - $ent);
        $doctype = ST_SALESINVOICE;
        $tot = $sign * ($myrow["ov_freight"] + $myrow["ov_gst"] + $myrow["ov_amount"] + $myrow["ov_freight_tax"]);
        if ($tot != $SubTotal) {
            $discount = $SubTotal * ($myrow['bulk_discount'] / 100);
        }
        $rep->AmountCol(7, 9, $DisplaySubTot, 2);
        $rep->NewLine();
        if ($myrow['bulk_discount'] != 0) {
            $rep->TextCol(5, 7, "Less Discount: " . $myrow['bulk_discount'] . "%");
        }
        $rep->AmountCol(7, 9, $discount, 2);
        $rep->NewLine();
        $DisplayTotal = $sign * ($myrow["ov_freight"] + $myrow["ov_gst"] + $myrow["ov_amount"] + $myrow["ov_freight_tax"]);
        $rep->Font('bold');
        $rep->AmountCol(7, 9, $DisplayTotal, 2);
    }
    if ($email == 0) {
        $rep->End();
    }
}
Example #6
0
include_once $path_to_root . "/sales/includes/sales_db.inc";
include_once $path_to_root . "/sales/ml/db/customer_trans.php";
//moodlearning
$js = "";
if ($use_popup_windows) {
    $js .= get_js_open_window(900, 600);
}
page(_($help_context = "View Sales Invoice"), true, false, "", $js);
if (isset($_GET["trans_no"])) {
    $trans_id = $_GET["trans_no"];
} elseif (isset($_POST["trans_no"])) {
    $trans_id = $_POST["trans_no"];
}
// 3 different queries to get the information - what a JOKE !!!!
$myrow = get_customer_trans($trans_id, ST_SALESINVOICE);
$custom_row = get_custom_no($trans_id, ST_SALESINVOICE);
$branch = get_branch($myrow["branch_code"]);
$sales_order = get_sales_order_header($myrow["order_"], ST_SALESORDER);
display_heading(sprintf(_("SALES INVOICE #%d"), $custom_row));
//moodlearning edit
echo "<br>";
start_table(TABLESTYLE2, "width=95%");
echo "<tr valign=top><td>";
// outer table
/*Now the customer charged to details in a sub table*/
start_table(TABLESTYLE, "width=100%");
$th = array(_("Charge To"));
table_header($th);
label_row(null, $myrow["DebtorName"] . "<br>" . nl2br($myrow["address"]), "nowrap");
end_table();
/*end of the small table showing charge to account details */
Example #7
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();
    }
}
Example #8
0
function print_credits()
{
    global $path_to_root, $alternative_tax_include_on_docs, $suppress_tax_rates;
    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'];
    $paylink = $_POST['PARAM_4'];
    $comments = $_POST['PARAM_5'];
    $orientation = $_POST['PARAM_6'];
    if (!$from || !$to) {
        return;
    }
    $orientation = $orientation ? 'L' : 'P';
    $dec = 2;
    $fno = explode("-", $from);
    $tno = explode("-", $to);
    $from = min($fno[0], $tno[0]);
    $to = max($fno[0], $tno[0]);
    $cols = array(-20, 15, 20, 100, 130, 200, 255, 285, 335, 385, 440, 480, 550, 600);
    // $headers in doctext.inc
    $aligns = array('left', 'left', 'left', 'left', 'left', 'left', 'left', 'right', 'right', 'right', 'right', 'right');
    $params = array('comments' => $comments);
    $cur = get_company_Pref('curr_default');
    if ($email == 0) {
        $rep = new FrontReport(_('CREDIT NOTE'), "InvoiceBulk", user_pagesize(), 9, $orientation);
    }
    if ($orientation == 'L') {
        recalculate_cols($cols);
    }
    for ($i = $from; $i <= $to; $i++) {
        if (!exists_customer_trans(ST_CUSTCREDIT, $i)) {
            continue;
        }
        $sign = -1;
        $myrow = get_customer_trans($i, ST_CUSTCREDIT);
        $baccount = get_default_bank_account($myrow['curr_code']);
        $params['bankaccount'] = $baccount['id'];
        $branch = get_branch($myrow["branch_code"]);
        $branch['disable_branch'] = $paylink;
        // helper
        $sales_order = null;
        if ($email == 1) {
            $rep = new FrontReport("", "", user_pagesize(), 9, $orientation);
            $rep->title = _('CREDIT NOTE');
            $rep->filename = "CreditNote" . $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);
        //$rep->SetCommonData($myrow, $branch, $sales_order, $baccount, ST_CUSTCREDIT, $contacts);
        $rep->NewPage();
        $result = get_customer_trans_details(ST_CUSTCREDIT, $i);
        $SubTotal = 0;
        //$data = get_custom_no($from, ST_CUSTCREDIT);
        $invoice_no = get_sales_invoice_no($myrow['order_'], ST_SALESINVOICE);
        $credit_no = get_custom_no($myrow['trans_no'], ST_CUSTCREDIT);
        $imc = get_imc_name($branch['branch_code']);
        $rep->NewLine(9);
        $rep->TextCol(6, 8, $myrow['TranDate']);
        $rep->NewLine(1);
        $oldrow = $rep->row;
        $rep->TextColLines(0, 12, $branch['br_name'], -2);
        $newrow = $rep->row;
        $rep->row = $oldrow;
        $rep->NewLine(3);
        $rep->TextCol(0, 3, "Ref. Invoice # " . $invoice_no, -2);
        $rep->TextCol(3, 5, "Credit#" . $credit_no, -2);
        $rep->TextCol(5, 8, $imc, -2);
        $rep->NewLine(2);
        $rep->NewLine(2);
        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());
            $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);
            if ($myrow2["discount_percent"] == 0) {
                $DisplayDiscount = "";
            } else {
                $DisplayDiscount = number_format2($myrow2["discount_percent"] * 100, user_percent_dec()) . "%";
            }
            //$rep->TextCol(4, 5,	$myrow2['stock_id'], -2);
            $oldrow = $rep->row;
            $rep->TextColLines(2, 5, $myrow2['StockDescription'], -2);
            $newrow = $rep->row;
            $rep->row = $oldrow;
            $rep->TextCol(0, 1, $DisplayQty . " " . $myrow2['units'], -2);
            $rep->TextCol(6, 7, $DisplayPrice, -2);
            $rep->TextCol(7, 8, $DisplayNet, -2);
            $rep->row = $newrow;
            //$rep->NewLine(1);
            if ($rep->row < $rep->bottomMargin + 15 * $rep->lineHeight) {
                $rep->NewPage();
            }
        }
        $memo = get_comments_string(ST_CUSTCREDIT, $i);
        if ($memo != "") {
            $rep->NewLine();
            //$rep->TextColLines(1, 5, $memo, -2);
        }
        $DisplaySubTot = $SubTotal;
        $DisplayFreight = number_format2($sign * $myrow["ov_freight"], $dec);
        $DisplayTotal = $sign * ($myrow["ov_freight"] + $myrow["ov_gst"] + $myrow["ov_amount"] + $myrow["ov_freight_tax"]);
        $sub = $myrow["ov_freight"] + $myrow["ov_gst"] + $myrow["ov_amount"] + $myrow["ov_freight_tax"];
        $Discount = abs($SubTotal) * ($myrow['bulk_discount'] / 100);
        //$rep->row = $rep->bottomMargin + (15 * $rep->lineHeight);
        $doctype = ST_CUSTCREDIT;
        $rep->NewLine(2);
        $rep->Font('bold');
        $rep->TextCol(4, 7, _("Total Amount : "), -2);
        $rep->AmountCol(7, 8, $DisplaySubTot, 2);
        $rep->NewLine();
        $rep->TextCol(4, 7, _("Volume Discount : "), -2);
        $rep->AmountCol(7, 8, $Discount, 2);
        $rep->NewLine();
        $rep->TextCol(4, 7, _("Net Amount : "), -2);
        $rep->AmountCol(7, 8, $DisplayTotal, 2);
        $rep->Font();
        if ($email == 1) {
            $myrow['dimension_id'] = $paylink;
            // helper for pmt link
            $rep->End($email);
        }
    }
    if ($email == 0) {
        $rep->End();
    }
}
Example #9
0
include_once $path_to_root . "/sales/includes/sales_db.inc";
include_once $path_to_root . "/sales/ml/db/customer_trans.php";
//moodlearning
$js = "";
if ($use_popup_windows) {
    $js .= get_js_open_window(900, 600);
}
page(_($help_context = "View Sales Dispatch"), true, false, "", $js);
if (isset($_GET["trans_no"])) {
    $trans_id = $_GET["trans_no"];
} elseif (isset($_POST["trans_no"])) {
    $trans_id = $_POST["trans_no"];
}
// 3 different queries to get the information - what a JOKE !!!!
$myrow = get_customer_trans($trans_id, ST_CUSTDELIVERY);
$custom_row = get_custom_no($trans_id, ST_CUSTDELIVERY);
$branch = get_branch($myrow["branch_code"]);
$sales_order = get_sales_order_header($myrow["order_"], ST_SALESORDER);
display_heading(sprintf(_("DISPATCH NOTE #%d"), $custom_row));
echo "<br>";
start_table(TABLESTYLE2, "width=95%");
echo "<tr valign=top><td>";
// outer table
/*Now the customer charged to details in a sub table*/
start_table(TABLESTYLE, "width=100%");
$th = array(_("Charge To"));
table_header($th);
label_row(null, $myrow["DebtorName"] . "<br>" . nl2br($myrow["address"]), "nowrap");
end_table();
/*end of the small table showing charge to account details */
echo "</td><td>";
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();
    }
}
Example #11
0
include_once $path_to_root . "/includes/ui.inc";
include_once $path_to_root . "/sales/includes/sales_db.inc";
include_once $path_to_root . "/sales/ml/db/customer_trans.php";
//moodlearning
$js = "";
if ($use_popup_windows) {
    $js .= get_js_open_window(900, 500);
}
page(_($help_context = "View Credit Note"), true, false, "", $js);
if (isset($_GET["trans_no"])) {
    $trans_id = $_GET["trans_no"];
} elseif (isset($_POST["trans_no"])) {
    $trans_id = $_POST["trans_no"];
}
$myrow = get_customer_trans($trans_id, ST_CUSTCREDIT);
$custom_row = get_custom_no($trans_id, ST_CUSTCREDIT);
$branch = get_branch($myrow["branch_code"]);
display_heading("<font color=red>" . _("CREDIT NOTE # " . $custom_row) . "</font>");
echo "<br>";
start_table(TABLESTYLE2, "width=95%");
echo "<tr valign=top><td>";
// outer table
/*Now the customer charged to details in a sub table*/
start_table(TABLESTYLE, "width=100%");
$th = array(_("Customer"));
table_header($th);
label_row(null, $myrow["DebtorName"] . "<br>" . nl2br($myrow["address"]), "nowrap");
end_table();
/*end of the small table showing charge to account details */
echo "</td><td>";
// outer table