<?php

function display_pos_invoices_detail_inquiry_selection_parameters() {
    global $systypes_array;
    
    start_table(TABLESTYLE_NOBORDER);
        start_row();
            ref_cells(text_bold("Trans No #:"), 'trans_no', '',null, '', true);
            $pos_types_array = array(ST_POS_INVOICE => $systypes_array[ST_POS_INVOICE], 
                                     ST_POS_CREDIT_NOTE => $systypes_array[ST_POS_CREDIT_NOTE]);
            custom_values_list_cells("Tran Type:", 'tran_type', $pos_types_array, null, '', true);
            ref_cells("Reference:", 'reference', '',null, '', true);
            value_list_cells('Entry Type:', 'entry_type_id', 'UTILITY_BILL_ENTRY_TYPES', null, '', true);
            date_cells("From Date:", 'from_date', '', null, -1);
            date_cells("To Date:", 'to_date', '', null, -1);
        end_row();
    end_table();

    start_table(TABLESTYLE_NOBORDER);
        start_row();
            ref_cells("Description:", 'description', '',null, '', true);
            locations_list_cells(_("Location:"), 'loc_code', null, '', true);
            petty_cash_floats_list_cells("Float:", 'float_id', null, '', true);
            submit_cells('SearchOrders', _("Search"),'',_('Search'), 'default');
        end_row();    
    end_table(1);
}

function display_pos_invoices_detail_inquiry($trans_no, $tran_type, $reference, $entry_type_id, $from_date, $to_date, $description, $loc_code, $float_id) {
    global $systypes_array, $daily_item_types_array;
    
    start_table(TABLESTYLE, "width=99%");

        $th = array(_("Type"), _("Trans #"), _("Reference"), _("Entry Type"), _("Customer"), _("Date"), _("Location"), _("Float"), _("Id"), _("Item Type"), _("Description"), 
                    _("Unit"), _("Quantity"), _('Unit Price'), _('Amount'));  
        table_header($th);

            $k = $pre_type = $pre_inv_no = $invoice_total = $all_invoices_total = 0; 
            $result = get_pos_invoices_detail_inquiry($trans_no, $tran_type, $reference, $entry_type_id, $from_date, $to_date, $description, $loc_code, $float_id); 
                while ($row = db_fetch($result)) {
                    $type = $row['type'];
                    
                    if ($pre_inv_no != 0 && ($pre_inv_no != $row['trans_no'] || ($pre_inv_no == $row['trans_no'] && $type != $pre_type))) {
                        start_row();
                            label_cell('', 'colspan=13');
                            label_cell(text_bold('Invoice Total'), 'align=right');
                            amount_cell($invoice_total, true); 
                        end_row();
                        
                        vertical_space('height=17px colspan=15');
                        
                        $invoice_total = 0;
                    }
                    
                    alt_table_row_color($k);

                        label_cell($systypes_array[$type]);
                        label_cell(get_trans_view_str($type, $row['trans_no']), 'align=center');
                        label_cell($row["reference"]);
                        label_cell($row["entry_type_name"]);
                        $cust_name = get_customer_formatted_name($row['debtor_no']);
                        label_cell($cust_name);
                        label_cell(sql2date($row["tran_date"]));
                        label_cell($row["location_name"]);
                        label_cell($row["float_name"]);
                        
                        label_cell($row['trans_id'], 'align=center');
                        $daily_item_type = $row['daily_item_type'];
                        label_cell($daily_item_types_array[$daily_item_type]);
                        if (in_array($daily_item_type, array(NSIT_NON_STOCK_ITEM, NSIT_STOCK_ITEM))) {
                            label_cell($row["stock_id"]." - ".$row["item_description"]);  
                        } else {
                            label_cell($row["item_description"]);
                        }
                        label_cell($row["unit_name"]);
                        
                        $tran_qty = $row["tran_qty"];
                            if ($type == ST_POS_CREDIT_NOTE) {
                                $tran_qty *= -1;
                            }
                        
                        label_cell(number_format($tran_qty, 2), 'align=right');
                        
                        $tran_unit_price = $row["tran_unit_price"];
                        label_cell(number_format($tran_unit_price, 2), 'align=right');                         
                        $amount = $tran_qty * $tran_unit_price;
                        label_cell(number_format($amount, 2), 'align=right');  
                        
                    end_row();  
                    
                    $invoice_total += $amount;
                    $all_invoices_total += $amount;

                    $pre_inv_no = $row['trans_no'];
                    $pre_type = $row['type'];
                }
                
                if ($pre_inv_no > 0) {
                    start_row();
                        label_cell('', 'colspan=13');
                        label_cell(text_bold('Invoice Total'), 'align=right');
                        amount_cell($invoice_total, true); 
                    end_row();
                    
                    vertical_space('height=17px colspan=15');
                    
                    start_row();
                        label_cell('', 'colspan=13');
                        label_cell(text_bold('All Invoices Total'), 'align=right');
                        amount_cell($all_invoices_total, true); 
                    end_row();
                }
                
    end_table(2);
}

?>