<?php

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

  require("../product/productSql.inc");

  class ProductSection extends Section {

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

    public function __construct($section) {

      // Define product type select options
      $productTypeOptions = ["0"=>"All", "1"=>"Caravan Structure", "2"=>"Glazing", "3"=>"Heating", "4"=>"Fire", "5"=>"Exterior", "6"=>"Option", "7"=>"Additional Specification", "8"=>"Door", "9"=>"Electrical", "10"=>"After Sale Job"];

      // Define product type select options
      $vatRateCodeOptions = ["1"=>"T0 0.00", "2"=>"T1 20.00", "3"=>"T5 5.00"];

      // Define section filter form inputs
      $section["sectionFilter"]["sectionFilterInput"] = [
        ["attributes"=>[ "type"=>"select", "id"=>"productTypeId", "value"=>"0" ], "label"=>"Type", "options"=>$productTypeOptions ],
        ["attributes"=>[ "type"=>"text", "id"=>"productShortDescription", "value"=>"" ], "label"=>"Description" ]
      ];

      // Define section table columns
      $section["sectionTable"]["sectionTableColumn"] = [
        ["id"=>"productId", "header"=>"Id", "width"=>30],
        ["id"=>"productCategoryId", "header"=>"Id", "width"=>30],
        ["id"=>"productTypeDescription", "header"=>"Type", "width"=>150],
        ["id"=>"productShortDescription", "header"=>"Description", "width"=>350],
        ["id"=>"productPrice", "header"=>"Retail Price (inc. vat)", "width"=>130],
        ["id"=>"vatRateDescription", "header"=>"Vat Rate", "width"=>130],
        ["id"=>"productDiscountRate", "header"=>"Discount Rate", "width"=>130]
      ];

      // Define section record fields
      $section["sectionRecord"]["sectionRecordStructure"] = [
        "productId"=>["type"=>"int", "length"=>"" ],
        "productCode"=>["type"=>"varchar", "length"=>"50" ],
        "productShortDescription"=>["type"=>"varchar", "length"=>"255" ],
        "productTypeId"=>["type"=>"int", "length"=>"" ],
        "productPrice"=>["type"=>"double", "length"=>"(10,2)" ],
        "productVatRateCode"=>["type"=>"varchar", "length"=>"50" ],
        "productDiscountRate"=>["type"=>"double", "length"=>"(10,2)" ],
        "productNominalCode"=>["type"=>"varchar", "length"=>"50" ]
      ];

      // Define section record summary items
      $section["sectionRecord"]["sectionRecordSummaryItem"] = [
        ["id"=>"productShortDescription", "label"=>"Description", "value"=>""]
      ];

      // 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"=>"productId", "name"=>"productId", "value"=>"0" ], "label"=>"", "groupId"=>"1" ], 
        ["attributes"=>[ "type"=>"text", "id"=>"productShortDescription", "name"=>"productShortDescription", "required"=>"", "maxlength"=>"255", "value"=>"" ], "label"=>"Description", "groupId"=>"1" ],
        ["attributes"=>[ "type"=>"select", "id"=>"productTypeId", "name"=>"productTypeId", "required"=>"", "value"=>"6" ], "label"=>"Type", "groupId"=>"1", "options"=>$productTypeOptions ],
        ["attributes"=>[ "type"=>"text", "id"=>"productCode", "name"=>"productCode", "maxlength"=>"50", "value"=>"" ], "label"=>"Code", "groupId"=>"1" ],
        ["attributes"=>[ "type"=>"text", "id"=>"productNominalCode", "name"=>"productNominalCode", "pattern"=>"^\d{4}$", "value"=>"" ], "label"=>"Nominal Code", "width"=>"120px", "groupId"=>"1" ],
        ["attributes"=>[ "type"=>"number", "id"=>"productPrice", "name"=>"productPrice", 'min'=>'0', 'max'=>'1000000', 'step'=>'0.01', 'value'=>'0.00' ], "label"=>"Retail Price (inc vat)", "width"=>"120px", "groupId"=>"1" ],
        ["attributes"=>[ "type"=>"select", "id"=>"productVatRateCode", "name"=>"productVatRateCode", "required"=>"", "value"=>"2" ], "label"=>"Vat Code", "width"=>"120px", "groupId"=>"1", "options"=>$vatRateCodeOptions ],
        ["attributes"=>[ 'type'=>'number', 'id'=>'productDiscountRate', 'name'=>'productDiscountRate', 'min'=>'0', 'max'=>'100', 'step'=>'0.01', 'value'=>'20.00' ], "label"=>"Discount Rate", "width"=>"120px", "groupId"=>"1" ]
      ];

      // Create the section's sql class
      $sectionSql = new ProductSql();

			// 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"]);

      // Set the section filter attributes
      //$this->set_productSectionFilterAttributes();

      $this->set_sectionTableRecordset();
    }

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

    public function set_sqlSelectFilters($filters) {

    	$DBGeneric = new DBGeneric();

      $sqlSelectWhere = sprintf("WHERE 1");
      $sqlSelectWhere .= $DBGeneric->getFilterSql(['filterValue'=>$filters["productShortDescription"], 'filterValueType'=>'string', 'filterOperator'=>'', 'filterList'=>['productShortDescription']]);			
      $sqlSelectWhere .= $DBGeneric->getFilterSql(['filterValue'=>$filters["productTypeId"], 'filterValueType'=>'integer', 'filterOperator'=>'=', 'filterList'=>['productTypeId']]);			
      
      $this->set_sqlSelectWhere($sqlSelectWhere);
      $this->set_sqlSelectLimit($filters["productLimit"]);
      
    }

  }

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

?>