<?php
$must_login                = true ;
$require_path              = '../../../' ;
$require_sub               = '../../' ;
require( $require_sub.'header.php' ) ;

if ( $boolean_login ){
    $status                = '300' ;

    $item_id               = $array['item_id'] ;
    $title                 = $array['title'] ;
    $reference1            = $array['reference1'] ;
    $reference2            = $array['reference2'] ;
    $reference3            = $array['reference3'] ;
    $reference4            = $array['reference4'] ;

    if ( $array['item_id'] != '' && $array['title'] != '' ){
        $status           = '201' ;

        $select_item       = $mysqli->query( "SELECT is_reference1, is_reference2, is_reference3, is_reference4 FROM rms_bill_item
                                              WHERE deleted_at IS NULL AND status = 'active' AND item_id = '".$item_id."' LIMIT 1" ) ;

        if ( $select_item->num_rows > 0 ){
            $status        = '300' ;

            $row_item      = $select_item->fetch_assoc() ;

            $is_error      = 0 ;
            if ( $row_item['is_reference1'] == 'yes' && $reference1 == '' ){
                $is_error++ ;
            }
            if ( $row_item['is_reference2'] == 'yes' && $reference2 == '' ){
                $is_error++ ;
            }
            if ( $row_item['is_reference3'] == 'yes' && $reference3 == '' ){
                $is_error++ ;
            }
            if ( $row_item['is_reference4'] == 'yes' && $reference4 == '' ){
                $is_error++ ;
            }

            if ( $is_error == 0 ){
                $status     = '203' ;

                if ( $mysqli->query( "INSERT INTO staff_rms_bill
                                   ( `branch_id`, `staff_id`, `item_id`, `title`, `reference1`, `reference2`, `reference3`, `reference4` ) VALUES
                                   ( '".$array['branch_id']."', '".$staff_info['staff_id']."', '".$array['item_id']."', '".$array['title']."', '".$array['reference1']."', '".$array['reference2']."', '".$array['reference3']."', '".$array['reference4']."' )" ) ){
                    $status = '200' ;
                }
            }

        }

    }
}

require( $require_sub.'footer.php' ) ;
?>