Example Invoice Data: Add a Field

Example 1: Invoice Analyte Order

This example adds a new element to sort contract charges for analytes.

Activity Steps

  1. Add the new element (an integer value called Order) to the XSD.
    Copy
    <xs:complexType name="InvoiceAnalyte">
        <xs:sequence>
            <xs:element name="AnalyteDef">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:minLength value="1"/>
                        <xs:maxLength value="50"/>
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element name="Value" type="xs:decimal"/>
            <xs:element name="UOM" type="xs:string"/>
        <xs:element name="IsPayable" type="xs:string"/>
        <xs:element name="Order" type="xs:int"/>
        </xs:sequence>
    </xs:complexType>
  2. Verify the database in Crystal Reports so that the XSD update is available. See Invoice Data XSD.
  3. Modify the report template as required.
  4. Add code to the invoice data XML script within a loop that creates and appends an Order element to the InvoiceAnalyte node. This code allows the sort order to be set in the XML script. Crystal Reports can use this field to sort the records based on the new sort order instead of the original order.
    Copy
    XmlElement order = originalDocument.CreateElement("Order");
        invoiceAnalyte.AppendChild(order);
        order.InnerText = "0";

Example 2: Despatch Order Shipping Date and Arrival Date

This example adds two dates related to the despatch order.

Activity Steps

  1. Modify the XSD definition. For this particular example, the fields must be placed at the despatch order level within the XSD because the values could be different per despatch order.
    Copy
    <xs:complexType name="DespatchOrder">
        <xs:sequence>
            <xs:element name="DespatchOrderName">
                <xs:simpleType>
                    <xs:restriction base="xs:string">
                        <xs:minLength value="1" />
                        <xs:maxLength value="50" />
                    </xs:restriction>
                </xs:simpleType>
            </xs:element>
            <xs:element name="InvoiceType" />
            <xs:element name="ContractName" type="xs:string" />
            <xs:element name="QuotaName" />
            <xs:element name="Despatch" type="xs:string" />
            <xs:element name="DespatchType" type="xs:string" />
    //...
            <xs:element name="DespatchOrderID" type="xs:int" />
            <xs:element name="ShippingDate" type="xs:string" />
            <xs:element name="ArrivalDate" type="xs:string" />
            <xs:element name="ContractDocumentRef" type="xs:string" />
            <xs:element name="ProductCode" type="xs:string" />
            <xs:element name="UnloadingPort" type="xs:string" />
            <xs:element name="UnloadingCountry" type="xs:string" />
            <xs:element name="Lots" type="Lot" minOccurs="0" maxoccurs="unbounded" />
        </xs:sequence>
    </xs:complexType>
  2. Verify the database in Crystal Reports so that the XSD update is available. See Invoice Data XSD.
  3. Modify the report template as required.
  4. Modify the invoice data XML script to populate the new fields with test data.
    Copy
    public XmlDocument UpdateDataSet(Invoice inv, XmlDocument originalDocument, 
        ArrayList parameters)
    {
        // Get the despatch orders node from the original XMLDocument
        // XSD Reference = <xx:element name="DespatchOrders" type="DespatchOrder" 
        // minOccurs="0" maxOccurs="unbounded" />
        XmlNodeList despatchorders = 
            originalDocument.GetElementsByTagName("DespatchOrders");
        foreach(XmlNode node in despatchorders)
        (
            XmlElement newElement = originalDocument.CreateElement("ShippingDate");
            XmlNode newNode = node.AppendChild(newElement)';
            newElement.InnerText = "test1";
            XmlElement newElement = originalDocument.CreateElement("ArrivalDate");
            XmlNode newNode = node.AppendChild(newElement2)';
            newElement2.InnerText = "test2";
        )
        return originalDocument;
    }
  5. Compile and run the report to test the new output.
  6. Modify the invoice data XML script to obtain actual data from MineMarket.

    Direct queries are not executed on the database because the MineMarket object model provides most of the needed data. Therefore, the despatch order will be determined from the XML and the required object will be instanced. The DespatchOrder object has a lot of methods to obtain the relevant dates (refer to the DespatchOrder class and go to Region #region Reference Date estimation methods). This example uses two methods from this region: the ATD and the ATA.

    Copy
    public XmlDocument UpdateDataSet(Invoice inv, XmlDocument originalDocument, 
        ArrayList parameters)
    {
        // Get the despatch orders node from the original XMLDocument
        // XSD Reference = <xx:element name="DespatchOrders" type="DespatchOrder" 
        // minOccurs="0" maxOccurs="unbounded" />
        XmlNodeList despatchorders = 
            originalDocument.GetElementsByTagName("DespatchOrders");
        foreach(XmlNode node in despatchorders)
        (
            DespatchOrder order = null;
                // Use the DespatchOrderID already in the XML to obtain the DO for 
                // this iteration.
            XmlNode desporderid = node.SelectSingleNode("DepatchOrderID");
            if(desporderid != null)
            (
                foreach(InvDespatchTotal idt in inv.DespatchTotals)
                (
                    //Compare the ID in the XML with the DOs of the invoice.
                    if(idt.DespatchOrder != null && 
                        idt.DespatchOrder.ID.ToString().CompareTo(
                                desporderid.InnerText
                            ) == 0)
                        order = idt.DespatchOrder;
                )
                if(order != null)
                (
                    // Add additional info at despatch order level.
                    // min(drpl.atd) 
                    // As ShippingDate: actual time of departure (origin)
                    DateTime ATD = order.getDepartureFromOrigin(
                            QuotationPeriodEstimationMode.Invoicing
                        );
                    XmlElement newElement = 
                        originalDocument.CreateElement("ShippingDate");
                    XmlNode newNode = node.AppendChild(newElement);
                    newElement.InnerText = ATD.ToString();
                    // min(drpu.ata) 
                    // As ArrivalDate: actual time of arrival (destination)
                    DateTime ATD = order.getArrivalAtDestination(
                            QuotationPeriodEstimationMode.Invoicing
                        );
                    XmlElement newElement2 = 
                        originalDocument.CreateElement("ArrivalDate");
                    XmlNode newNode2 = node.AppendChild(newElement2);
                    newElement2.InnerText = ATA.ToString();
                )
            )
        )
        return originalDocument;
    }
  7. Compile and run the report to show the required dates.