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


function add_cheque_printing_templates($bank_id, $page_width, $page_length, $font_size,
        
                                        $full_date_y, $year_format, $year_x, $year_width, 
                                        $month_x, $month_width, $date_x, $date_width, 
        
                                        $amount_text_x, $amount_text_y, $amount_text_width, 
                                        $amount_text_line_height, $amount_text_offset, 
        
                                        $amount_value_x, $amount_value_y, 
        
                                        $crossing_id, $crossing_x, $crossing_y,
        
                                        $account_name_x, $account_name_y,
                                        
                                        $company_name_x, $company_name_y, 
                                            
                                        $signatories_y, $signatory1_name, $signatory1_x,
                                        $signatory2_name, $signatory2_x)
{
    $created_by = $_SESSION['wa_current_user']->user;
    $created_on = date('Y-m-d H:i:s');    

    $sql = "INSERT INTO ".TB_PREF."cheque_printing_templates
        
          ( bank_id, page_width, 
            page_length, font_size, 
            full_date_y, year_format,
            year_x, year_width, 
            month_x, month_width, 
            date_x, date_width, 
            amount_text_x, amount_text_y, 
            amount_text_width, amount_text_line_height, amount_text_offset,
            amount_value_x, amount_value_y, 
            crossing_id, crossing_x, crossing_y, 
            
            account_name_x, account_name_y,
            
            company_name_x, company_name_y, 
                
            signatories_y, signatory1_name, signatory1_x, 
            signatory2_name, signatory2_x,
            
            created_by, created_on )
        
        VALUES

        (".db_escape($bank_id).",  ".db_escape($page_width).", 
            ".db_escape($page_length).", ".db_escape($font_size).",  
            ".db_escape($full_date_y).", ".db_escape($year_format).",  
            ".db_escape($year_x).",  ".db_escape($year_width).", 
            ".db_escape($month_x).",  ".db_escape($month_width).",  
            ".db_escape($date_x).", ".db_escape($date_width).",         
            ".db_escape($amount_text_x).",  ".db_escape($amount_text_y).",
            ".db_escape($amount_text_width).",  ".db_escape($amount_text_line_height).",".db_escape($amount_text_offset).",                    
            ".db_escape($amount_value_x).",  ".db_escape($amount_value_y).", 
            ".db_escape($crossing_id).",  ".db_escape($crossing_x).",  ".db_escape($crossing_y).",
            
            ".db_escape($account_name_x).",  ".db_escape($account_name_y).",  
                
            ".db_escape($company_name_x).",  ".db_escape($company_name_y).",
            
            ".db_escape($signatories_y).",  ".db_escape($signatory1_name).",  ".db_escape($signatory1_x).",
            ".db_escape($signatory2_name).",  ".db_escape($signatory2_x).", 
                
            ".db_escape($created_by).",  ".db_escape($created_on).")";
   
                        
    db_query($sql, "Could not insert cheque_printing_templates.");
    
}



function update_cheque_printing_templates($bank_id, $page_width, $page_length, $font_size,
        
                                            $full_date_y, $year_format, $year_x, $year_width, 
                                            $month_x, $month_width, $date_x, $date_width, 
        
                                            $amount_text_x, $amount_text_y, $amount_text_width, 
                                            $amount_text_line_height, $amount_text_offset,
        
                                            $amount_value_x, $amount_value_y, 
        
                                            $crossing_id, $crossing_x, $crossing_y,
        
                                            $account_name_x, $account_name_y,
        
                                            $company_name_x, $company_name_y, 
        
                                            $signatories_y, $signatory1_name, $signatory1_x,
                                            $signatory2_name, $signatory2_x)
{
    $updated_by = $_SESSION['wa_current_user']->user;
    $updated_on = date('Y-m-d H:i:s');    
    
    $sql = "UPDATE ".TB_PREF."cheque_printing_templates
            SET page_width =".db_escape($page_width).", 
                page_length =".db_escape($page_length).", 
                font_size =".db_escape($font_size).", 
                full_date_y =".db_escape($full_date_y).", 
                year_format =".db_escape($year_format).", 
                year_x =".db_escape($year_x).", 
                year_width =".db_escape($year_width).", 
                month_x =".db_escape($month_x).", 
                month_width =".db_escape($month_width).", 
                date_x =".db_escape($date_x).", 
                date_width =".db_escape($date_width).", 
                amount_text_x=".db_escape($amount_text_x).", 
                amount_text_y=".db_escape($amount_text_y).", 
                amount_text_width=".db_escape($amount_text_width).", 
                amount_text_line_height=".db_escape($amount_text_line_height).", 
                amount_text_offset=".db_escape($amount_text_offset).", 
                amount_value_x=".db_escape($amount_value_x).", 
                amount_value_y=".db_escape($amount_value_y).",
                crossing_id=".db_escape($crossing_id).",    
                crossing_x=".db_escape($crossing_x).",     
                crossing_y=".db_escape($crossing_y).", 
                    
                account_name_x=".db_escape($account_name_x).", 
                account_name_y=".db_escape($account_name_y).", 
                    
                company_name_x=".db_escape($company_name_x).", 
                company_name_y=".db_escape($company_name_y).", 
                
                signatories_y=".db_escape($signatories_y).",    
                signatory1_name=".db_escape($signatory1_name).",     
                signatory1_x=".db_escape($signatory1_x).", 
                signatory2_name=".db_escape($signatory2_name).", 
                signatory2_x=".db_escape($signatory2_x).", 
                    
                updated_by =".db_escape($updated_by).", 
                updated_on =".db_escape($updated_on)." 
    
            WHERE bank_id=".db_escape($bank_id);            
                    
    db_query($sql, "Could not update cheque_printing_templates");                
    
}


function get_cheque_printing_templates($bank_id)
{
    $sql = "SELECT cpt.*,
                    lv.value_name bank_name
        
            FROM ".TB_PREF."cheque_printing_templates cpt,
                ".TB_PREF."list_values lv

            WHERE cpt.bank_id = lv.id AND
                    cpt.bank_id=".db_escape($bank_id);
    
   return db_query($sql, "Could not get cheque_printing_templates");
    
}


function get_cheque_printing_template($selected_id)
{
    $sql = "SELECT *
            FROM ".TB_PREF."cheque_printing_templates
            WHERE bank_id=".db_escape($selected_id);
    
    $result = db_query($sql, "Could not get cheque_printing_templates.");
    return db_fetch($result);
}


function delete_cheque_printing_templates($selected_id)
{   
    $sql = "DELETE FROM ".TB_PREF."cheque_printing_templates WHERE bank_id=".db_escape($selected_id);

    db_query($sql,"could not delete cheque_printing_templates");
    return db_num_affected_rows();
   
}



?>