<?php
          
  require("../quote/quoteSql.inc");

  //================================================================================================

  class QuoteSection extends Section {

    //================================================================================================
    // Function Constructor()
    //================================================================================================

    public function __construct($section) {

      // Define product type select options
      $createdByUserIdOptions = ["0"=>"All","24"=>"Den Watson"];

      // Define section filter form inputs
      $section["sectionFilter"]["sectionFilterInput"] = [
        ["attributes"=>[ "type"=>"text", "id"=>"quoteId", "value"=>"" ], "label"=>"Quote No." ],
        ["attributes"=>[ "type"=>"text", "id"=>"quoteStockNumber", "value"=>"" ], "label"=>"Stock Number" ],
        ["attributes"=>[ "type"=>"text", "id"=>"quoteCustomerName", "value"=>"" ], "label"=>"Customer" ],
        ["attributes"=>[ "type"=>"select", "id"=>"quoteCreatedByUserId", "value"=>"0" ], "label"=>"Created By", "options"=>$createdByUserIdOptions ]
      ];

      // Define section table columns
      $section["sectionTable"]["sectionTableColumn"] = [
        ["id"=>"quoteId", "header"=>"Quote No", "width"=>120],
        ["id"=>"quoteStockNumber", "header"=>"Stock No", "width"=>120],
        ["id"=>"quoteCreatedDate", "header"=>"Created Date", "width"=>120],
        ["id"=>"van_stock_year", "header"=>"Year", "width"=>40],
        ["id"=>"van_model_type_description", "header"=>"Model", "width"=>400],
        ["id"=>"quoteCustomerName", "header"=>"Customer Name", "width"=>300],
        ["id"=>"quoteEnquirySourceDescription", "header"=>"Enquiry Source", "width"=>120],
        ["id"=>"quoteVanStockTotalCost", "header"=>"Total (inc. vat)", "width"=>120],
        ["id"=>"quoteCreatedByUserName", "header"=>"Created By", "width"=>120]
      ];

      // Define section record fields
      $section["sectionRecord"]["sectionRecordStructure"] = [
        "quoteId"=>["type"=>"int", "length"=>"" ],
        "quoteStockNumber"=>["type"=>"varchar", "length"=>"10" ]
      ];

      // Define section record summary items
      $section["sectionRecord"]["sectionRecordSummaryItem"] = [
        ["id"=>"quoteId", "label"=>"Quote Id", "value"=>"36"]
      ];

      // Define section record form columns and groups
      $section["sectionRecord"]["sectionRecordTabColumn"] = [
        ["columnId"=>"1", "columnClass"=>"", "columnGroup"=>[["groupId"=>"1"]]]
      ];

      // Define section record form inputs
      $section["sectionRecord"]["sectionRecordInput"] = [
        ["attributes"=>[ "type"=>"hidden", "id"=>"quoteId", "name"=>"quoteId", "value"=>"0" ], "label"=>"", "groupId"=>"1" ], 
        ["attributes"=>[ "type"=>"text", "id"=>"quoteStockNumber", "name"=>"quoteStockNumber", "required"=>"", "maxlength"=>"10", "value"=>"" ], "label"=>"Stock Number", "groupId"=>"1" ]
      ];
        
      // Create the section's sql class
      $sectionSql = new QuoteSql();
      
			// Create the parent section object
      parent :: __construct( $section, $sectionSql );

      // Set the section title, filter inputs, filter limit, menu buttons, table columns and table rows 
      $this->set_sectionTitle($section["sectionTitle"]);
      $this->set_sectionTableRecordset();
    }

    //================================================================================================
    // Function set_sqlSelect()
    //================================================================================================

    public function set_sqlSelectFilters($filters) {

    	$DBGeneric = new DBGeneric();

      $sqlSelectWhere = "WHERE 1";
      $sqlSelectWhere .= $DBGeneric->getFilterSql(['filterValue'=>$filters["quoteId"], 'filterValueType'=>'integer', 'filterOperator'=>'=', 'filterList'=>['quoteId']]);			
      $sqlSelectWhere .= $DBGeneric->getFilterSql(['filterValue'=>$filters["quoteStockNumber"], 'filterValueType'=>'string', 'filterOperator'=>'', 'filterList'=>['quoteStockNumber']]);			
      $sqlSelectWhere .= $DBGeneric->getFilterSql(['filterValue'=>$filters["quoteCreatedByUserId"], 'filterValueType'=>'integer', 'filterOperator'=>'=', 'filterList'=>['quoteCreatedByUserId']]);			

      if ($filters["quoteCustomerName"] != "") { $sqlSelectWhere .= sprintf(" and (((( tblC.contact_first_name like '%%%1\$s%%' ) or ( tblC.contact_last_name like '%%%1\$s%%' )) and tblQ.quoteCustomerTypeId=1) or (( tblS.site_name like '%%%1\$s%%' ) and tblQ.quoteCustomerTypeId=2))", $filters["quoteCustomerName"]);	}
      
      $this->set_sqlSelectWhere($sqlSelectWhere);
      $this->set_sqlSelectLimit($filters["quoteLimit"]);
      
    }

  }

  //================================================================================================

?>