<?php
/**********************************************************************
***********************************************************************/

$page_security = 'SA_CREATE_GATE_PASS';
// ----------------------------------------------------------------
// $ Revision:	2.0 $
// Creator:	Joe Hunt
// date_:	2005-05-19
// Title:	Purchase Remittance/SA_REP_PAY_VOUCHER
// ----------------------------------------------------------------
$path_to_root = "..";

include_once($path_to_root . "/includes/session.inc");
include_once($path_to_root . "/payroll/includes/db/employees_db.inc"); 
include_once($path_to_root . "/services/includes/ui/create_job_gate_pass_ui.inc"); 
include_once($path_to_root . "/services/includes/db/create_job_gate_pass_db.inc"); 
include_once($path_to_root . "/assets/includes/db/assets_db.inc");  

print_job_gate_pass_temp();
    
function print_column_headers(&$rep, $start_row) {
    $right = $rep->pageWidth - $rep->rightMargin;
    $rep->row = $start_row;
    $rep->Font('bold');
        $count = count($rep->headers);
        $rep->cols[$count] = $right - 3;
        for ($i = 0; $i < $count; $i++) 
            $rep->TextColCenter($i, $i + 1, $rep->headers[$i], -2);
        $rep->Font();
}

function display_gp_header_details(&$rep, $header, $gp_row) {
        $rep->row += 10;
                        
        $row_line = $rep->row;

        $rep->row = $row_line;
        $rep->Text(40, "From Location :");
        $rep->Font('bold');
        $rep->Text(98, $header['from_location']);
        $rep->Font();
        $rep->row -= 20; 

        $rep->Text(40, "To Location :");
        $rep->Font('bold');
        $rep->Text(98, $header['to_location']);
        $rep->Font();
        $rep->row -= 20; 

        $rep->Text(40, _("Project :"));
        $rep->Font('bold');
        $rep->Text(98, $header['project_id'].' '.$header['project_description']);
        $rep->Font();
        $rep->row -= 20; 

        $rep->Text(40, _("Gate Pass No :"));
        $rep->Font('bold');
        $rep->Text(98, $gp_row['id']);
        $rep->Font();

        $rep->row = $row_line; 

        $rep->Text(340, _("Date :"));
        $rep->Font('bold');
        $rep->Text(420, date("Y/m/d h:i:sa"));
        $rep->Font();
        $rep->row -= 20; 

        $rep->Text(340, _("Vehicle No :"));
        $rep->Font('bold');
        $rep->Text(420, strlen($gp_row['vehicle_no']) > 0 ? $gp_row['vehicle_no'] : $gp_row['plate_number']);
        $rep->Font();
        $rep->row -= 20; 

        $rep->Text(340, _("Driver Name :"));
        $rep->Font('bold');
        $rep->Text(420, $gp_row['driver_name']);
        $rep->Font();
        $rep->row -= 20; 

        $rep->Text(340, _("Transaction No :"));
        $rep->Font('bold');
        $rep->Text(420, $header['jo_id']);
        $rep->Font();
        $rep->row -= 4;
}

function draw_payment_items_table($column_headers_start, &$rep) {
    $right = $rep->pageWidth - $rep->rightMargin;
    
    $rep->row = $column_headers_start;
    $cols = count($rep->cols);
    
    $iline7 = $column_headers_start + 12;
    $iline5 = $column_headers_start - 5;
    
    $increase_height = 185;

    $rep->LineTo(25, $iline7, 570, $iline7);
    $rep->LineTo(25, $iline5, 570, $iline5);
    $rep->LineTo(25, $iline7 - $increase_height, 570, $iline7 - $increase_height);
    
//    $rep->Line($iline7);
//    $rep->Line($iline5);
//    $rep->Line($iline7 - $increase_height);

    $top_line_row = $iline7;

//    $rep->LineTo($rep->leftMargin, $top_line_row ,$rep->leftMargin, $iline7 - $increase_height);
    $rep->LineTo(25, $top_line_row, 25, $iline7 - $increase_height);
    $rep->LineTo(50, $top_line_row, 50, $iline7 - $increase_height);
    $rep->LineTo(390, $top_line_row, 390, $iline7 - $increase_height);
    $rep->LineTo(450, $top_line_row, 450, $iline7 - $increase_height);
//    $rep->LineTo($rep->cols[$cols - 5], $top_line_row, $rep->cols[$cols - 5], $iline7 - $increase_height);
//    $rep->LineTo($rep->cols[$cols - 4], $top_line_row, $rep->cols[$cols - 4], $iline7 - $increase_height);
    $rep->LineTo(500, $top_line_row, 500, $iline7 - $increase_height);
    $rep->LineTo(570, $top_line_row, 570, $iline7 - $increase_height);
//    $rep->LineTo($right, $top_line_row, $right, $iline7 - $increase_height);
}

function print_job_gate_pass_temp() {
    global $path_to_root, $approval_statuses;

    include_once($path_to_root . "/reporting/includes/pdf_report.inc");
    
    $jo_id = $_POST['PARAM_0'];
    $driver_name = $_POST['PARAM_1'];
    $comment = $_POST['PARAM_2'];
    
    if ($driver_name == 0) {
        $driver_name = '';
    }
    
    $msg = save_job_gate_pass_($jo_id, $driver_name, $comment, 1);
        if ($msg['success'] !== true) {
            display_error($msg['message']);
            return;
        }
    
    $cols = array(4, 60, 160, 210, 275, 360, 458, 528);

//    $aligns = array('center', 'left', 'center', 'right', 'right', 'right', 'right');
//    $headers  = array(_("Date"), _("Job Card"), _("Reference"), _("Total Amount"), _("Left to Allocate"), _("This Allocation"));

    $rep = new FrontReport(_('JOB GATE PASS TEMP.'), "JobGatePassTemporary", 'A5', 9, 'L');
    
//        $cur = get_company_Pref('curr_default');
            $gp_row = get_job_gate_pass_by_jo_id($jo_id);
        
            $params['gate_pass_no'] = $gp_row['rec_id'];
//            $params['jo_id'] = $jo_id;
//            $params['job_gate_pass_no'] = $gp_row['id'];
//            $params['driver_name'] = $gp_row['driver_name'];
//            $params['comment'] = $gp_row['comment'];
//            $sys_user = get_user($gp_row['printed_by']);
//            $params['printed_by'] = $sys_user['real_name'];
//            $params['printed_on'] = sql2date($gp_row['printed_on']);

                $rep->SetHeaderType('form_653');
//                $rep->currency = $cur;
                $rep->Font();
                $rep->Info($params, $cols, $headers=array(), $aligns=array());

                    $rep->NewPage();
                        
//                        $brs = 17;
                        $rep->row -= 20; 
                        
//                        $seq_no = 1;
//                        $add_new_line = false;
                        
                        
//                                if ($add_new_line) {
//                                    $rep->NewLine();
//                                }
                                
                                
                                $rep->row -= 50;

                                $row_line = $rep->row;

                                $rep->row = $row_line;
                                $rep->Text(40, "Job Card :");
                                $rep->Font('bold');
                                $rep->Text(120, $jo_id);
                                $rep->Font();
                                $rep->row -= 20; 
                                
                                $rep->Text(40, "Job Ref :");
                                $rep->Font('bold');
                                $rep->Text(120, $gp_row['jo_ref']);
                                $rep->Font();
                                $rep->row -= 20; 

                                $rep->Text(40, "Vehicle :");
                                $rep->Font('bold');
                                $rep->Text(120, get_asset_formatted_name($gp_row['vehicle_id']));
                                $rep->Font();
                                $rep->row -= 20; 

                                $rep->Text(40, "Job Date :");
                                $rep->Font('bold');
                                $rep->Text(120, sql2date($gp_row['date_']));
                                $rep->Font();
                                $rep->row -= 20; 

                                $rep->row = $row_line; 

                                $rep->Text(340, _("Date Time :"));
                                $rep->Font('bold');
                                $rep->Text(420, date("Y/m/d h:i:s a"));
                                $rep->Font();
                                $rep->row -= 20; 

                                $rep->Text(340, _("Printed By :"));
                                $rep->Font('bold');
                                $rep->Text(420, $gp_row['real_name']);
                                $rep->Font();
                                $rep->row -= 20; 

                                $rep->Text(340, _("Driver :"));
                                $rep->Font('bold');
                                $rep->Text(420, $gp_row['driver_name']);
                                $rep->Font();
                                $rep->row -= 20;

                                $rep->Text(340, _("Approval Status :"));
                                $rep->Font('bold');
                                $rep->Text(420, $approval_statuses[$gp_row['approval_status']]);
                                $rep->Font();
                                $rep->row -= 20;

                //                $rep->row = $row_line; 
//                                $rep->row -= 10;

                                $rep->Text(40, "Comment :");
                                $rep->Font('bold');
                                $rep->Text(120, $gp_row['comment']);
                                $rep->Font();
                                $rep->row -= 20; 
                                
                                $rep->NewLine(2);
                                
                                $rep->Text(40, "Customer Complain/ Request :");
                                $rep->Font('bold');
                                $rep->TextWrapLines(175, 450, $gp_row['description']);
                                $rep->Font();
                                $rep->row -= 20; 
                                
//                                $rep->Text(32, $jo_id);
//                                $rep->Text(55, $job_row['id']);
//                                $rep->Text(412, $item['date_']);
//                                $rep->Text(480, $item['jo_ref']);
//                                $rep->Text(526, $item['department_name']);
//                                
//                                $add_new_line = true;
//                                
//                                $brs--;
//                                
//                                $seq_no++;
//                                
//                                    $pg_h = $rep->bottomMargin + (5 * $rep->lineHeight);
//                                    
//                                    if ($rep->row < $pg_h) {
//                                        $rep->NewPage();
//                                        
//                                        $brs = 17;
//                                    }
//                            
//                            
//                            if ($brs > 0 && $add_new_line === true) {
//                                $rep->NewLine($brs);
//                            } else {
//                                $rep->NewLine(16);
//                            }
                        
//                        if ($rep->row < $rep->bottomMargin + (1 * $rep->lineHeight)) {
//                            $rep->NewPage();
//                            $rep->NewLine(2);
//                        }
                                
                        $rep->NewLine();
                        
                        $rep->Text(30, "Driver's Signature");
                        $rep->Text(104, _("..........................................."));
                        $rep->Text(220, "Supervisor/ Manager");
                        $rep->Text(305, _("..........................................."));
                        $rep->Text(418, "Received By");
                        $rep->Text(470, _("..........................................."));

    $rep->End();
}

?>