<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<entitymodel xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:noNamespaceSchemaLocation="https://ofbiz.apache.org/dtds/entitymodel.xsd">
  <!-- ========================================================= -->
  <!-- ======================== Defaults ======================= -->
  <!-- ========================================================= -->
    <title>Entity of the Apache OFBiz Manufacturing Component</title>
    <description>None</description>
    <version>1.0</version>

  <!-- ========================================================= -->
  <!-- ======================== Data Model ===================== -->
  <!-- The modules in this file are as follows:                  -->
  <!--  - org.apache.ofbiz.manufacturing.bom -->
  <!--  - org.apache.ofbiz.manufacturing.techdata -->
  <!--  - org.apache.ofbiz.manufacturing.mrp -->
  <!-- ========================================================= -->


  <!-- ========================================================= -->
  <!-- org.apache.ofbiz.manufacturing.bom -->
  <!-- ========================================================= -->

    <entity entity-name="ProductManufacturingRule"
            package-name="org.apache.ofbiz.manufacturing.bom"
            title="Product To Part Rule">
      <field name="ruleId" type="id"></field>
      <field name="productId" type="id"></field>
      <field name="productIdFor" type="id"></field>
      <field name="productIdIn" type="id"></field>
      <field name="ruleSeqId" type="id"></field>
      <field name="fromDate" type="date-time"></field>
      <field name="productIdInSubst" type="id"></field>
      <field name="productFeature" type="id"></field>
      <field name="ruleOperator" type="id"></field>
      <field name="quantity" type="floating-point"></field>
      <field name="description" type="description"></field>
      <field name="thruDate" type="date-time"></field>
      <prim-key field="ruleId"/>
      <relation type="one" fk-name="PRODUCT_PARENT" rel-entity-name="Product">
        <key-map field-name="productId"/>
      </relation>
      <relation type="one" fk-name="PRODUCT_FOR" title="ProductFor" rel-entity-name="Product">
        <key-map field-name="productIdFor" rel-field-name="productId"/>
      </relation>
      <relation type="one" fk-name="PRODUCT_IN" title="ProductIn" rel-entity-name="Product">
        <key-map field-name="productIdIn" rel-field-name="productId"/>
      </relation>
      <relation type="one" fk-name="PRODUCT_SUBST" title="ProductSubst" rel-entity-name="Product">
        <key-map field-name="productIdInSubst" rel-field-name="productId"/>
      </relation>
      <relation type="one" fk-name="PRODUCT_FEAT" rel-entity-name="ProductFeature">
        <key-map field-name="productFeature" rel-field-name="productFeatureId"/>
      </relation>
    </entity>

  <!-- ========================================================= -->
  <!-- org.apache.ofbiz.manufacturing.techdata -->
  <!-- ========================================================= -->

    <entity entity-name="TechDataCalendar"
            package-name="org.apache.ofbiz.manufacturing.techdata"
            default-resource-name="ManufacturingEntityLabels"
            title="Calendar">
      <description>Used to defined the availability of the machines, this entity define the Id and the week definition.
      The Id is used in the exception calendar table as reference
      </description>
      <field name="calendarId" type="id"></field>
      <field name="description" type="description"></field>
      <field name="calendarWeekId" type="id"></field>
      <prim-key field="calendarId"/>
      <relation type="one" fk-name="CALENDAR_WEEK" rel-entity-name="TechDataCalendarWeek">
        <key-map field-name="calendarWeekId"/>
      </relation>
    </entity>
    <entity entity-name="TechDataCalendarExcDay"
            package-name="org.apache.ofbiz.manufacturing.techdata"
            title="Calendar Exception Day">
      <description>Used to defined some days which differ from the normal day definition in the weekId associated in the calendar.
      </description>
      <field name="calendarId" type="id"></field>
      <field name="exceptionDateStartTime" type="date-time"></field>
      <field name="exceptionCapacity" type="fixed-point"></field>
      <field name="usedCapacity" type="fixed-point"></field>
      <field name="description" type="description"></field>
      <prim-key field="calendarId"/>
      <prim-key field="exceptionDateStartTime"/>
      <relation type="one" fk-name="EXC_DAY_CALENDAR" rel-entity-name="TechDataCalendar">
        <key-map field-name="calendarId"/>
      </relation>
    </entity>
    <entity entity-name="TechDataCalendarExcWeek"
            package-name="org.apache.ofbiz.manufacturing.techdata"
            title="Calendar Exception Week">
      <description>Used to defined some weeks which differ from the normal week defined in the calendar.</description>
      <field name="calendarId" type="id"></field>
      <field name="exceptionDateStart" type="date"></field>
      <field name="calendarWeekId" type="id"></field>
      <field name="description" type="description"></field>
      <prim-key field="calendarId"/>
      <prim-key field="exceptionDateStart"/>
      <relation type="one" fk-name="EXC_WEEK_CALENDAR" rel-entity-name="TechDataCalendar">
        <key-map field-name="calendarId"/>
      </relation>
      <relation type="one" fk-name="EXC_WEEK_WEEK" rel-entity-name="TechDataCalendarWeek">
        <key-map field-name="calendarWeekId"/>
      </relation>
    </entity>
    <entity entity-name="TechDataCalendarWeek"
            package-name="org.apache.ofbiz.manufacturing.techdata"
            default-resource-name="ManufacturingEntityLabels"
            title="Week definition">
      <description>Used to defined the week definition disponibility for machine</description>
      <field name="calendarWeekId" type="id"></field>
      <field name="description" type="description"></field>
      <field name="mondayStartTime" type="time"></field>
      <field name="mondayCapacity" type="floating-point"></field>
      <field name="tuesdayStartTime" type="time"></field>
      <field name="tuesdayCapacity" type="floating-point"></field>
      <field name="wednesdayStartTime" type="time"></field>
      <field name="wednesdayCapacity" type="floating-point"></field>
      <field name="thursdayStartTime" type="time"></field>
      <field name="thursdayCapacity" type="floating-point"></field>
      <field name="fridayStartTime" type="time"></field>
      <field name="fridayCapacity" type="floating-point"></field>
      <field name="saturdayStartTime" type="time"></field>
      <field name="saturdayCapacity" type="floating-point"></field>
      <field name="sundayStartTime" type="time"></field>
      <field name="sundayCapacity" type="floating-point"></field>
      <prim-key field="calendarWeekId"/>
    </entity>

  <!-- ========================================================= -->
  <!-- org.apache.ofbiz.manufacturing.mrp -->
  <!-- ========================================================= -->

    <entity entity-name="MrpEventType"
            package-name="org.apache.ofbiz.manufacturing.mrp"
            default-resource-name="ManufacturingEntityLabels"
            title="MRP Event Type">
      <description></description>
      <field name="mrpEventTypeId" type="id"></field>
      <field name="description" type="description"></field>
      <prim-key field="mrpEventTypeId"/>
    </entity>

    <entity entity-name="MrpEvent"
            package-name="org.apache.ofbiz.manufacturing.mrp"
            title="MRP Event">
      <description></description>
      <field name="mrpId" type="id"></field>
      <field name="productId" type="id"></field>
      <field name="eventDate" type="date-time"></field>
      <field name="mrpEventTypeId" type="id"></field>
      <field name="facilityId" type="id"></field>
      <field name="quantity" type="floating-point"></field>
      <field name="eventName" type="very-long"></field>
      <field name="isLate" type="indicator"></field>
      <field name="facilityIdTo" type="id"></field>
      <prim-key field="mrpId"/>
      <prim-key field="productId"/>
      <prim-key field="eventDate"/>
      <prim-key field="mrpEventTypeId"/>
      <relation type="one" fk-name="MRPEV_PROD" rel-entity-name="Product">
        <key-map field-name="productId"/>
      </relation>
      <relation type="one" fk-name="MRPEV_TYP" rel-entity-name="MrpEventType">
        <key-map field-name="mrpEventTypeId"/>
      </relation>
      <relation type="one" fk-name="MRPEV_FAC" rel-entity-name="Facility">
        <key-map field-name="facilityId"/>
      </relation>
    </entity>

    <view-entity entity-name="MrpEventView"
                 package-name="org.apache.ofbiz.manufacturing.mrp"
                 title="MRP Event View">
      <member-entity entity-alias="MEV" entity-name="MrpEvent"></member-entity>
      <member-entity entity-alias="PR" entity-name="Product"></member-entity>
      <alias-all entity-alias="MEV"></alias-all>
      <alias entity-alias="PR" name="billOfMaterialLevel"></alias>
      <view-link entity-alias="MEV" rel-entity-alias="PR">
        <key-map field-name="productId"></key-map>
      </view-link>
      <relation rel-entity-name="Product" type="one-nofk">
        <key-map field-name="productId"/>
      </relation>
    </view-entity>

</entitymodel>
