Quickbooks IPP v3 sales tax issue - intuit-partner-platform

We are building an application using IPP v3 that will sync invoices from our SaaS app to QBOE (and hopefully QBD). The problem are are encountering is with replicating the sales on our invoices with the invoices created in quickbooks.
Specifically, our invoices can have line items which are not taxable (each state is different in terms of which items are taxed and at what rate). Also there are many times both state, city and county taxes, some of which apply to some line items and not to others.
It appears for the IPP v3 US version, taxes must be global to the invoice?
I think that all of this could be solved if we could just override the total tax amount for the invoice. Documentations seems to indicate that API supports that. However, all my attempts were ignored. It's either no Tax or default tax rate (in percentage). That means that we can't override totals or enter fixed taxes.
Another option would be to add an extra line to the invoice named "Tax Name" and the value. The invoice total would be correct but Tax Reports on quickbooks wouldn't?
I would really like a straight answer like "tax amount cannot be overridden through the API" just to be sure.
I would also like to know if Intuit plans to support that feature in a near future?
There are fields in the API like "PercentBased" (which can be set to true or false) that seem to indicate that fixed amounts can be set. But these fields are completely ignored when I try to use them.
Any help or future guidance on this would be greatly appreciate as it pertains to IPP v3 for QBOE / QBD.
Here's our XML request
<?xml version='1.0' encoding='utf-8'?>
<IntuitBatchRequest xmlns:ns2="http://www.intuit.com/sb/cdm/qbo"
xmlns="http://schema.intuit.com/finance/v3">
<BatchItemRequest bId="bid1" operation="create">
<Invoice>
<DocNumber>2459999</DocNumber>
<TxnDate>2012-12-10</TxnDate>
<GlobalTaxCalculation>TaxIncluded</GlobalTaxCalculation>
<Line>
<DetailType>SalesItemLineDetail</DetailType>
<Amount>200</Amount>
<SalesItemLineDetail>
<TaxCodeRef>TAX</TaxCodeRef>
<ServiceDate>2012-12-10</ServiceDate>
</SalesItemLineDetail>
<Description>Test</Description>
<ItemRef>1</ItemRef>
</Line>
<CustomerRef>66</CustomerRef>
<TxnTaxDetail>
<TaxLine>
<DetailType>TaxLineDetail</DetailType>
<Amount>13.00</Amount>
<TaxLineDetail>
<NetAmountTaxable>200.00</NetAmountTaxable>
<TaxPercent>6.50</TaxPercent>
<TaxRateRef>1</TaxRateRef>
<PercentBased>true</PercentBased>
</TaxLineDetail>
</TaxLine>
</TxnTaxDetail>
</Invoice>
</BatchItemRequest>
</IntuitBatchRequest>

You can override the tax amount in the Taxline in TxnTaxDetail-
Eg:
Includes tax # 20% on 16.67 = 3.33. we would expect the request to include following tax details
"TxnTaxDetail": {
"TotalTax":3.33,
"TaxLine":[
{
"Amount":3.33,
"DetailType": "TaxLineDetail",
"TaxLineDetail": {
"TaxRateRef": {
"value":"4"
},
"PercentBased":true,
"TaxPercent": 20,
"NetAmountTaxable": 16.67
"GlobalTaxCalculation": "TaxIncludes",...
Please refer-
https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/v3/020_key_concepts/0700_other_topics#TxnTaxDetail
EDIT:
Adding the sample request and response xml. Just set the following tags.
<TxnTaxDetail>
<TxnTaxCodeRef>
<TotalTax>
</TxnTaxDetail>
Do not set the Taxline as QBO recalculates the tax based on the details sent in the request. So in response you’ll get the recalculated amount based in the TaxPercent specified.
Request sample-
<?xml version="1.0"?>
<Invoice xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://schema.intuit.com/finance/v3">
<TxnDate>2013-10-11+05:30</TxnDate>
<PrivateNote>This is a private note</PrivateNote>
<Line>
<Description>Invoice line description.</Description>
<Amount>900</Amount>
<DetailType>SalesItemLineDetail</DetailType>
<SalesItemLineDetail>
<ItemRef name="Bat">2</ItemRef>
<UnitPrice>90</UnitPrice>
<Qty>10</Qty>
<TaxCodeRef>TAX</TaxCodeRef>
<ServiceDate>2013-10-11+05:30</ServiceDate>
</SalesItemLineDetail>
</Line>
<TxnTaxDetail>
<TxnTaxCodeRef name="StateSalesTax">8</TxnTaxCodeRef>
<TotalTax>450</TotalTax>
</TxnTaxDetail>
<AutoDocNumber>true</AutoDocNumber>
<CustomerRef name="5748584cc7d64bb18a0e">23</CustomerRef>
<BillAddr>
<Line1>123 Main St.</Line1>
<Line2>Unit 506</Line2>
<City>Brockton</City>
<Country>United States</Country>
<CountrySubDivisionCode>MA</CountrySubDivisionCode>
<PostalCode>02301</PostalCode>
<Note>Billing Address Note</Note>
</BillAddr>
<ShipAddr>
<Line1>100 Fifth Ave.</Line1>
<City>Waltham</City>
<Country>United States</Country>
<CountrySubDivisionCode>MA</CountrySubDivisionCode>
<PostalCode>02452</PostalCode>
<Note>Shipping Address Note</Note>
</ShipAddr>
<SalesTermRef name="Due on receipt">1</SalesTermRef>
<DueDate>2013-11-10+05:30</DueDate>
<GlobalTaxCalculation>TaxInclusive</GlobalTaxCalculation>
<ARAccountRef name="Accounts Receivable (A/R)">32</ARAccountRef>
</Invoice>
Response sample-
<IntuitResponse xmlns="http://schema.intuit.com/finance/v3" time="2013-10-18T01:50:19.576-07:00">
<Invoice domain="QBO" sparse="false">
<Id>50</Id>
<SyncToken>0</SyncToken>
<MetaData>
<CreateTime>2013-10-18T01:50:20-07:00</CreateTime>
<LastUpdatedTime>2013-10-18T01:50:20-07:00</LastUpdatedTime>
</MetaData>
<DocNumber>1037</DocNumber>
<TxnDate>2013-10-11</TxnDate>
<PrivateNote>This is a private note</PrivateNote>
<Line>
<Id>1</Id>
<LineNum>1</LineNum>
<Description>Invoice line test</Description>
<Amount>900.00</Amount>
<DetailType>SalesItemLineDetail</DetailType>
<SalesItemLineDetail>
<ItemRef name="Bat">2</ItemRef>
<UnitPrice>90</UnitPrice>
<Qty>10</Qty>
<TaxCodeRef>TAX</TaxCodeRef>
<ServiceDate>2013-10-11</ServiceDate>
</SalesItemLineDetail>
</Line>
<Line>
<Amount>900.00</Amount>
<DetailType>SubTotalLineDetail</DetailType>
<SubTotalLineDetail />
</Line>
<TxnTaxDetail>
<TxnTaxCodeRef>8</TxnTaxCodeRef>
<TotalTax>450.00</TotalTax>
<TaxLine>
<Amount>450.00</Amount>
<DetailType>TaxLineDetail</DetailType>
<TaxLineDetail>
<TaxRateRef>18</TaxRateRef>
<PercentBased>true</PercentBased>
<TaxPercent>2.5</TaxPercent>
<NetAmountTaxable>900.00</NetAmountTaxable>
</TaxLineDetail>
</TaxLine>
</TxnTaxDetail>
<CustomerRef name="5748584cc7d64bb18a0e">23</CustomerRef>
<BillAddr>
<Id>78</Id>
<Line1>123 Main St.</Line1>
<Line2>Unit 506</Line2>
<City>Brockton</City>
<Country>United States</Country>
<CountrySubDivisionCode>MA</CountrySubDivisionCode>
<PostalCode>02301</PostalCode>
<Lat>42.0829092</Lat>
<Long>-71.01995200000002</Long>
</BillAddr>
<ShipAddr>
<Id>79</Id>
<Line1>100 Fifth Ave.</Line1>
<City>Waltham</City>
<Country>United States</Country>
<CountrySubDivisionCode>MA</CountrySubDivisionCode>
<PostalCode>02452</PostalCode>
<Lat>42.3933303</Lat>
<Long>-71.256777</Long>
</ShipAddr>
<SalesTermRef>1</SalesTermRef>
<DueDate>2013-11-10</DueDate>
<TotalAmt>1350.00</TotalAmt>
<ApplyTaxAfterDiscount>false</ApplyTaxAfterDiscount>
<PrintStatus>NeedToPrint</PrintStatus>
<EmailStatus>NotSet</EmailStatus>
<Balance>1350.00</Balance>
<Deposit>0</Deposit>
<AllowIPNPayment>false</AllowIPNPayment>
<AllowOnlinePayment>false</AllowOnlinePayment>
</Invoice>
</IntuitResponse>
EDIT for Global-
Ok, I retested this fr Global.
I can override amounts for individual taxlines and then final taxamount-
here is an invoice update request -
I changed the following tags-
<TxnTaxDetail>
<TotalTax>2.90</TotalTax>
and then in one of the taxlines
<TaxLine>
<Amount>0.70</Amount>
and then in the final invoice amounts
<TotalAmt>79.90</TotalAmt>
<Balance>79.90</Balance>
<Invoice xmlns="http://schema.intuit.com/finance/v3" domain="QBO" sparse="false">
<Id>1</Id>
<SyncToken>0</SyncToken>
<MetaData>
<CreateTime>2015-01-30T09:32:06-08:00</CreateTime>
<LastUpdatedTime>2015-01-30T09:32:06-08:00</LastUpdatedTime>
</MetaData>
<DocNumber>1001</DocNumber>
<TxnDate>2015-01-30</TxnDate>
<CurrencyRef name="Canadian Dollar">CAD</CurrencyRef>
<Line>
<Id>1</Id>
<LineNum>1</LineNum>
<Amount>33.00</Amount>
<DetailType>SalesItemLineDetail</DetailType>
<SalesItemLineDetail>
<ItemRef name="Hours">2</ItemRef>
<UnitPrice>33</UnitPrice>
<Qty>1</Qty>
<TaxCodeRef>7</TaxCodeRef>
</SalesItemLineDetail>
</Line>
<Line>
<Id>2</Id>
<LineNum>2</LineNum>
<Amount>44.00</Amount>
<DetailType>SalesItemLineDetail</DetailType>
<SalesItemLineDetail>
<ItemRef name="Sales">1</ItemRef>
<UnitPrice>44</UnitPrice>
<Qty>1</Qty>
<TaxCodeRef>5</TaxCodeRef>
</SalesItemLineDetail>
</Line>
<Line>
<Amount>77.00</Amount>
<DetailType>SubTotalLineDetail</DetailType>
<SubTotalLineDetail />
</Line>
<TxnTaxDetail>
<TotalTax>2.90</TotalTax>
<TaxLine>
<Amount>2.20</Amount>
<DetailType>TaxLineDetail</DetailType>
<TaxLineDetail>
<TaxRateRef>6</TaxRateRef>
<PercentBased>true</PercentBased>
<TaxPercent>5</TaxPercent>
<NetAmountTaxable>44.00</NetAmountTaxable>
</TaxLineDetail>
</TaxLine>
<TaxLine>
<Amount>0.70</Amount>
<DetailType>TaxLineDetail</DetailType>
<TaxLineDetail>
<TaxRateRef>15</TaxRateRef>
<PercentBased>true</PercentBased>
<TaxPercent>2</TaxPercent>
<NetAmountTaxable>33.00</NetAmountTaxable>
</TaxLineDetail>
</TaxLine>
</TxnTaxDetail>
<CustomerRef name="dd">1</CustomerRef>
<SalesTermRef>3</SalesTermRef>
<DueDate>2015-03-01</DueDate>
<GlobalTaxCalculation>TaxExcluded</GlobalTaxCalculation>
<TotalAmt>79.90</TotalAmt>
<PrintStatus>NotSet</PrintStatus>
<EmailStatus>NotSet</EmailStatus>
<Balance>79.90</Balance>
<Deposit>0</Deposit>
<AllowIPNPayment>false</AllowIPNPayment>
<AllowOnlinePayment>false</AllowOnlinePayment>
<AllowOnlineCreditCardPayment>false</AllowOnlineCreditCardPayment>
<AllowOnlineACHPayment>false</AllowOnlineACHPayment>

Related

How to create multiple charts of same type but with different dataseries using JRBeanCollectionDatasource in Jasperreports

I have to create multiple XY-line charts with different dataset using same chart report template and I also have to use JRBeanCollectionDatasource for it.
Requirements:
1) Should be done using JRBeanCollectionDatasource.
2) Have to use the same chart report template to create multiple charts.
3) Number of charts are not fixed (Here I have problem giving names to Report Parameter in java). Because in ReportParametersMap, they can only have unique key name .
Java:
Coordinates.java
private Number series;
private Number xCoordinate;
private Number yCoordinate;
//Getters & Setters
GenerateReport.java
I am working with Report Book and each report template of the report book is considered as a sub-report. So I am passing XYChartDataSource(java.util.List) to master report book and I would map this parameter with the subreport by using
new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{XYChartDataSource}) as a Datasource Expression.
and in Subreport, I have created a parameter XYChartDataSource(java.util.List) and created fields (series,xCoordinate,yCoordinate) in MainDataset ( used in chart)
List<List<Coordinates>> allchartData = new ArrayList<>();
List<Coordinates> chartData = new ArrayList<>();
chartData.add(new Coordinates(2.08, xCoordinate, yCoordinate));
chartData.add(new Coordinates(2.08, xCoordinate, yCoordinate));
chartData.add(new Coordinates(2.08, xCoordinate, yCoordinate));
allchartData.add(chartData);
.
.
.
chartData.add(new Coordinates(2.12, xCoordinate, yCoordinate));
chartData.add(new Coordinates(2.12, xCoordinate, yCoordinate));
chartData.add(new Coordinates(2.12, xCoordinate, yCoordinate));
allchartData.add(chartData);
.
.
.
for (int i = 0; i < baselineChartData.size(); i++) {
parameters.put("XYChartDataSource", allchartData.get(i));
}
main_report_book.jrxml
<parameter name="XYChartDataSource" class="java.util.List"/>
<part uuid="5e668430-9acd-4835-be21-f4e2902ce33d">
<p:subreportPart xmlns:p="http://jasperreports.sourceforge.net/jasperreports/parts" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports/parts http://jasperreports.sourceforge.net/xsd/parts.xsd">
<subreportParameter name="REPORT_DATA_SOURCE">
<subreportParameterExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($P{XYChartDataSource})]]></subreportParameterExpression>
</subreportParameter>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR}+"/sub_chart.jasper"]]></subreportExpression>
</p:subreportPart>
</part>
sub_chart.jrxml
<parameter name="XYChartDataSource" class="java.util.List"/>
<field name="xCoordinate" class="java.lang.Double"/>
<field name="yCoordinate" class="java.lang.Double"/>
<field name="series" class="java.lang.Double"/>
<summary>
<band height="405">
<xyLineChart>
<chart evaluationTime="Report" bookmarkLevel="1">
<reportElement x="30" y="98" width="525" height="230" uuid="627d87d6-b675-409c-accb-b2bb3ffb9c80">
<property name="net.sf.jasperreports.chart.domain.axis.tick.interval" value="1"/>
</reportElement>
<chartTitle/>
<chartSubtitle/>
<chartLegend position="Right"/>
</chart>
<xyDataset>
<xySeries autoSort="true">
<seriesExpression><![CDATA[$F{series}]]></seriesExpression>
<xValueExpression><![CDATA[$F{xCoordinate}]]></xValueExpression>
<yValueExpression><![CDATA[$F{yCoordinate}]]></yValueExpression>
</xySeries>
</xyDataset>
<linePlot isShowShapes="false">
<plot/>
<categoryAxisFormat>
<axisFormat/>
</categoryAxisFormat>
<valueAxisFormat>
<axisFormat/>
</valueAxisFormat>
</linePlot>
</xyLineChart>
</textField>
</band>
</summary>
Current Output:
only one chart is being printed, using the regular method.
Expected Output:
Here I am showing two charts(could be more in actual output) , which needs to be generated from same report template in the SAME PDF REPORT:
chart1
chart2
You problem is here:
for (int i = 0; i < baselineChartData.size(); i++) {
parameters.put("XYChartDataSource", allchartData.get(i));
}
Your parameter "XYChartDataSource" will contain last entry in your List, you replace each time in loop see Map.put(K key,V value))
What we need instead is the whole list
parameters.put("XYChartDataSource", allchartData);
However now we can't access directly the List<Coordinates>
On solution to not change your current subreport is to insert another subreport in the middle which will iterate your List<List<Coordinates>> in detail band.
The structure will be
Pass List<List<Coordinates>> allchartData as datasource to this new subreport (sub_charts.jrxml)
Define the field _THIS which is List<Coordinates> in subreport (hence it's iterating your List<List<Coordinates>>)
In detail band include current sub_chart.jrxml and pass $F{_THIS} as datasource
sub_charts.jrxml
<?xml version="1.0" encoding="UTF-8"?>
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="sub_charts" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="bc8c76ba-0b85-4522-bf67-4c62ae87202b">
<field name="_THIS" class="java.util.List">
<fieldDescription>_THIS</fieldDescription>
</field>
<detail>
<band height="63" splitType="Stretch">
<subreport>
<reportElement x="0" y="0" width="550" height="60" uuid="b0e761bf-fe02-4a0a-bafb-32d6831b7a13"/>
<dataSourceExpression><![CDATA[new net.sf.jasperreports.engine.data.JRBeanCollectionDataSource($F{_THIS})]]></dataSourceExpression>
<subreportExpression><![CDATA[$P{SUBREPORT_DIR}+"/sub_chart.jasper"]]></subreportExpression>
</subreport>
</band>
</detail>
</jasperReport>
Remember to call this new subreport in your main_report_book.jrxml.
<subreportExpression><![CDATA[$P{SUBREPORT_DIR}+"/sub_charts.jasper"]]></subreportExpression>
The OP Dhruvil Thaker did this great graphical representation of this answer.

Using a json dataset within a report not working [duplicate]

I'm using Jasper Reports to build a simple report pdf. I have a JSON file that looks like this:
{"employees": [
{"firstName" : "John", "lastName" : "Doe"},
{"firstName" : "Anna", "lastName" : "Smith"},
{"firstName" : "Peter", "lastName" : "Jones"}
]}
And I'm trying to read it in like this:
File file = new File("E:/Workspaces/jasperPDFreport/src/main/resources/emp.json");
JsonDataSource datasource = new JsonDataSource(file);
JasperDesign jasperDesign = JRXmlLoader.load("E:/Workspaces/jasperPDFreport/src/main/resources/jsonTemplate.jrxml");
JasperReport jasperReport = JasperCompileManager.compileReport(jasperDesign);
Map parameters = new HashMap();
JasperPrint jasperPrint;
jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, datasource);
JasperExportManager.exportReportToPdfFile(jasperPrint, "BasicReport.pdf");
JasperViewer.viewReport(jasperPrint);
However my the values from the JSON file are not passed to my pdf.
This is my Template:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 6.1.1.final using JasperReports Library version 6.1.1 -->
<!-- 2015-10-22T13:45:32 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Blank_A4_2" pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20" rightMargin="20" topMargin="20" bottomMargin="20" uuid="9e494ebe-c1fb-4448-bcee-38994e9720f7">
<!--property name="net.sf.jasperreports.json.source" value="emp.json"/-->
<queryString language="json">
<![CDATA[employees]]>
</queryString>
<field name="firstName" class="java.lang.String">
<fieldDescription><![CDATA[firstName]]></fieldDescription>
</field>
<field name="lastName" class="java.lang.String">
<fieldDescription><![CDATA[lastName]]></fieldDescription>
</field>
<background>
<band splitType="Stretch"/>
</background>
<detail>
<band height="125" splitType="Stretch">
<textField>
<reportElement x="100" y="0" width="100" height="30" uuid="02b279da-3795-4655-8571-5a36a3ef378c"/>
<textFieldExpression><![CDATA[$F{firstName}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="0" width="100" height="30" uuid="671e61ad-8d8f-48cb-969f-78c05a516398"/>
<text><![CDATA[firstName]]></text>
</staticText>
<textField>
<reportElement x="100" y="30" width="100" height="30" uuid="9d53f46f-a252-48b3-9213-8c3092c29f49"/>
<textFieldExpression><![CDATA[$F{lastName}]]></textFieldExpression>
</textField>
<staticText>
<reportElement x="0" y="30" width="100" height="30" uuid="3b49affb-685a-4df2-a872-c0e6fdcab94b"/>
<text><![CDATA[lastName]]></text>
</staticText>
</band>
</detail>
</jasperReport>
Now you see the commented out line
property name="net.sf.jasperreports.json.source" value="emp.json"
If I comment this in, everything works as intended, I don't want to hard code my JSON values into the template, because later on I want to get them from a rest service, that's not ready yet. I do not understand, why the values are not getting parsed into the report, instead i just get two null values.
From JasperReports - JSON Data Source Sample (version 6.4.3)
The built-in JSON query executer (see the JsonQueryExecuter class) is a tool that uses the query string to produce a JsonDataSource instance, based on specific built-in parameters (or equivalent report properties). This query executer is registered via JsonQueryExecuterFactory factory class.
In order to prepare the data source, the JSON query executer looks for the JSON_INPUT_STREAM parameter that contains the JSON source objects in the form of an java.io.InputStream. If no JSON_INPUT_STREAM parameter is provided, then the query executer looks for the alternate net.sf.jasperreports.json.source String parameter or report property that stores the path to the location of the JSON source file.
JsonQueryExecuter runs the query over the input source and stores the result in an in-memory JsonDataSource object.
So if you do not want to use:
<property name="net.sf.jasperreports.json.source" value="emp.json"/>
You need to pass the file as java.io.InputStream in the parameter JSON_INPUT_STREAM
Hence you are currently passing it as datasource you should try something like this
params.put(JsonQueryExecuterFactory.JSON_INPUT_STREAM, new FileInputStream(file));
JasperFillManager.fillReportToFile(jasperReport, params);
If you instead like to use the new JsonQLQueryExecuterFactory JSONQL Data Source
params.put(JsonQLQueryExecuterFactory.JSON_INPUT_STREAM, new FileInputStream(file));
JasperFillManager.fillReportToFile(jasperReport, params);
If you pass your json string as InputStream then it will works.
String reportContents = "{}" //your json
InputStream is = new ByteArrayInputStream(reportContent.getBytes());
Map params = new HashMap();
params.put(JsonQueryExecuterFactory.JSON_INPUT_STREAM, is);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, params);
Take a look here for data source implementation that wraps a collection of JavaBean objects.
List<YourClass> yourBeanCollection = queryDataFromJSON();
JRDataSource beanCollectionDataSource = new JRBeanCollectionDataSource(yourBeanCollection);
JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport,
reportParams, beanCollectionDataSource);
and in the report template import java.util and declare the collection which you "injected" in the report
<import value="java.util.*"/>
<field name="yourBeanCollection" class="java.util.List"/>
also take a look here for an example

Implementing GitHub Badges in Golang

I have asked this question before and didn't receive satisfactory answer, so this time I'd try to be more specific.
I would like to implement a server in golang which outputs dynamic status updates in the form of svg. (Think "Build Passing/Failing" GitHub Badges.) The purpose is that one should be able to embed a link to the server's address in GitHub Readme and the Readme should update automatically depending on the server state.
Here's the golang code that I came up with but it doesn't seem to work with GitHub aggressive caching. Do I need to add more Cache-Control headers? Do I need to add ETag?
I'm using the following to embed the image in GitHub Readme.
[![Mine](http://58dcd0b5.ngrok.com/view)]()
Ideally, I would like to see the GitHub Readme change the image every time I load it -- flipping between the two images "correct"/"wrong". (This is just a proof of concept.)
package main
import (
"log"
"net/http"
_ "time"
)
var mymap map[string][]byte
var state bool = false
func viewHandler(w http.ResponseWriter, r *http.Request) {
log.Printf("State %v", state)
state = !state
w.Header().Set("Content-Type", "image/svg+xml")
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
if state {
w.Write(mymap["correct"])
} else {
w.Write(mymap["wrong"])
}
}
func main() {
mymap = make(map[string][]byte)
mymap["correct"] = []byte(`<svg xmlns="http://www.w3.org/2000/svg" width="104" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><mask id="a"><rect width="104" height="20" rx="3" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h54v20H0z"/><path fill="#4c1" d="M54 0h50v20H54z"/><path fill="url(#b)" d="M0 0h104v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="28" y="15" fill="#010101" fill-opacity=".3">solution</text><text x="28" y="14">solution</text><text x="78" y="15" fill="#010101" fill-opacity=".3">correct</text><text x="78" y="14">correct</text></g></svg>`)
mymap["wrong"] = []byte(`<svg xmlns="http://www.w3.org/2000/svg" width="99" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><mask id="a"><rect width="99" height="20" rx="3" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h54v20H0z"/><path fill="#e05d44" d="M54 0h45v20H54z"/><path fill="url(#b)" d="M0 0h99v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="28" y="15" fill="#010101" fill-opacity=".3">solution</text><text x="28" y="14">solution</text><text x="75.5" y="15" fill="#010101" fill-opacity=".3">wrong</text><text x="75.5" y="14">wrong</text></g></svg>`)
mux := http.NewServeMux()
mux.HandleFunc("/view", viewHandler)
http.ListenAndServe(":8085", mux)
}
Here's what travis are serving for their images:
Age:0
Cache-Control:no-cache
Content-Length:0
Date:Mon, 30 Mar 2015 07:49:10 GMT
ETag:"88e168c2d5cdb30ee9af739765e78e4d"
Expires:Mon, 30 Mar 2015 07:49:10 GMT
Keep-Alive:timeout=10, max=48
Last-Modified:Wed, 07 Jan 2015 11:26:53 GMT
Timing-Allow-Origin:https://github.com
X-Timer:S1427701750.146025,VS0,VE156
It might be a good start to try these and see what works.
Here is a Github issue about it : https://github.com/github/markup/issues/224
Assets must include Cache-Control: no-cache and ETag headers. If a
badge is not updating, then it means they are not properly setting
these headers.
and
The assets may also need to include either an ETag or Expires header.
Fastly's docs on Cache-Control say that no-cache means "re-validate
before serving this content", but it doesn't specify what it does to
"re-validate". I'm guessing it is re-validating, but there's no
indication that the asset has changed, so it continues to serves the
cached asset.
An ETag would be the biggest win, since it would guarantee that the
cache gets refreshed when it changes, but still saves bandwidth.
Following this commit to shields.io server, I made the following changes to the above code and it works now.
w.Header().Set("Date", date)
w.Header().Set("Expires", date)
For completeness (and in case someone wants to try it out), here's the complete code. (Also on GitHub.)
package main
import (
"log"
"net/http"
"time"
)
var mymap map[string][]byte
var state bool = false
func viewHandler(w http.ResponseWriter, r *http.Request) {
date := time.Now().Format(http.TimeFormat)
log.Printf("%v", date)
log.Printf("State %v", state)
state = !state
w.Header().Set("Content-Type", "image/svg+xml")
w.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
w.Header().Set("Date", date)
w.Header().Set("Expires", date)
if state {
w.Write(mymap["correct"])
} else {
w.Write(mymap["wrong"])
}
}
func main() {
mymap = make(map[string][]byte)
mymap["correct"] = []byte(`<svg xmlns="http://www.w3.org/2000/svg" width="104" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><mask id="a"><rect width="104" height="20" rx="3" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h54v20H0z"/><path fill="#4c1" d="M54 0h50v20H54z"/><path fill="url(#b)" d="M0 0h104v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="28" y="15" fill="#010101" fill-opacity=".3">solution</text><text x="28" y="14">solution</text><text x="78" y="15" fill="#010101" fill-opacity=".3">correct</text><text x="78" y="14">correct</text></g></svg>`)
mymap["wrong"] = []byte(`<svg xmlns="http://www.w3.org/2000/svg" width="99" height="20"><linearGradient id="b" x2="0" y2="100%"><stop offset="0" stop-color="#bbb" stop-opacity=".1"/><stop offset="1" stop-opacity=".1"/></linearGradient><mask id="a"><rect width="99" height="20" rx="3" fill="#fff"/></mask><g mask="url(#a)"><path fill="#555" d="M0 0h54v20H0z"/><path fill="#e05d44" d="M54 0h45v20H54z"/><path fill="url(#b)" d="M0 0h99v20H0z"/></g><g fill="#fff" text-anchor="middle" font-family="DejaVu Sans,Verdana,Geneva,sans-serif" font-size="11"><text x="28" y="15" fill="#010101" fill-opacity=".3">solution</text><text x="28" y="14">solution</text><text x="75.5" y="15" fill="#010101" fill-opacity=".3">wrong</text><text x="75.5" y="14">wrong</text></g></svg>`)
mux := http.NewServeMux()
mux.HandleFunc("/view", viewHandler)
log.Println("Server started. Listening on 8085...")
http.ListenAndServe(":8085", mux)
}

Customer attributes not saving on Add

So I've been experimenting with adding customers to QuickBooks Online from a local database instance at our business. I want to keep track of our internal customer reference numbers in QBO, so have tried to save those to several different attributes like AcctNum, ExternalKey, ExternalId, AlternateId, or even directly to the Id attribute. After attempting to save to these fields, the return result looks good.
var qbCustomer = new Customer
{
AcctNum = customer.CustRef.ToString(CultureInfo.InvariantCulture),
ExternalKey = new IdType {idDomain = idDomainEnum.NG, Value = customer.CustRef.ToString(CultureInfo.InvariantCulture)},
Id = new IdType {idDomain = idDomainEnum.NG, Value = customer.CustRef.ToString(CultureInfo.InvariantCulture)},
Name = customer.CustName1,
FamilyName = customer.CustRef.ToString(CultureInfo.InvariantCulture),
};
Customer resultCustomer = dataServices.Add(qbCustomer);
But the next time I retrieve those customers, all of those fields are just null. Why are these fields not saving? Is there another more appropriate field to use to store an external ID besides just using one of the plain text fields (Name, Address, etc.)?
UPDATE:
Here's the raw XML exchange.
What I sent when adding a new customer:
<?xml version="1.0" encoding="utf-8"?>
<q1:Customer xmlns="http://www.intuit.com/sb/cdm/qbo" xmlns:q1="http://www.intuit.com/sb/cdm/v2">
<q1:Id>7</q1:Id>
<q1:ExternalKey>7</q1:ExternalKey>
<q1:TypeOf>Person</q1:TypeOf>
<q1:Name>Customer Name</q1:Name>
<q1:FamilyName>7</q1:FamilyName>
<q1:AcctNum>7</q1:AcctNum>
</q1:Customer>
Intuit's response:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Customer xmlns="http://www.intuit.com/sb/cdm/v2" xmlns:qbp="http://www.intuit.com/sb/cdm/qbopayroll/v1" xmlns:qbo="http://www.intuit.com/sb/cdm/qbo">
<Id idDomain="QBO">12</Id>
<SyncToken>0</SyncToken>
<MetaData><CreateTime>2013-07-25T13:51:43-07:00</CreateTime><LastUpdatedTime>2013-07-25T13:51:43-07:00</LastUpdatedTime></MetaData>
<Name>Customer Name</Name>
<WebSite/>
<Email/>
<FamilyName>7</FamilyName>
<CustomField xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="StringTypeCustomField"><DefinitionId>Preferred Delivery Method</DefinitionId><Value>DONT</Value></CustomField>
<CustomField xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="StringTypeCustomField"><DefinitionId>Resale Number</DefinitionId></CustomField>
<CustomField xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="BooleanTypeCustomField"><DefinitionId>Bill With Parent</DefinitionId><Value>false</Value></CustomField>
<ShowAs>Erik Kunze/Magdalena Guarda Munoz</ShowAs>
<OpenBalance><Amount>0</Amount></OpenBalance>
</Customer>
My retrieval later:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<qbo:SearchResults xmlns="http://www.intuit.com/sb/cdm/v2" xmlns:qbp="http://www.intuit.com/sb/cdm/qbopayroll/v1" xmlns:qbo="http://www.intuit.com/sb/cdm/qbo">
<qbo:CdmCollections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Customers">
<Customer>
<Id idDomain="QBO">12</Id>
<SyncToken>0</SyncToken>
<MetaData><CreateTime>2013-07-25T13:51:43-07:00</CreateTime><LastUpdatedTime>2013-07-25T13:51:43-07:00</LastUpdatedTime></MetaData>
<Name>Customer Name</Name>
<WebSite/>
<Email/>
<FamilyName>7</FamilyName>
<CustomField xsi:type="BooleanTypeCustomField"><DefinitionId>Bill With Parent</DefinitionId><Value>false</Value></CustomField>
<CustomField xsi:type="StringTypeCustomField"><DefinitionId>Preferred Delivery Method</DefinitionId><Value>DONT</Value></CustomField>
<ShowAs>Erik Kunze/Magdalena Guarda Munoz</ShowAs>
<OpenBalance><Amount>0</Amount></OpenBalance>
</Customer>
</qbo:CdmCollections>
<qbo:Count>1</qbo:Count>
<qbo:CurrentPage>1</qbo:CurrentPage>
</qbo:SearchResults>
There's no AcctNum in the raw XML anywhere.
You are referring QBD's customer endpoint in apiexplorer.
Correct QBO link - https://developer.intuit.com/apiexplorer?apiname=V2QBO#Customer
Api Docs & Sample Create request - https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/v2/0400_quickbooks_online/customer#Sample_Create_Request_XML
Simplest request body to create QBO customer -
<Customer xmlns:ns2="http://www.intuit.com/sb/cdm/qbo" xmlns="http://www.intuit.com/sb/cdm/v2" xmlns:ns3="http://www.intuit.com/sb/cdm/baseexceptionmodel/xsd">
<TypeOf>Person</TypeOf>
<Name>TestQBCustomer12345</Name>
</Customer>
Simplest Response
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Customer xmlns="http://www.intuit.com/sb/cdm/v2" xmlns:qbp="http://www.intuit.com/sb/cdm/qbopayroll/v1" xmlns:qbo="http://www.intuit.com/sb/cdm/qbo">
<Id idDomain="QBO">14</Id>
<SyncToken>0</SyncToken>
<MetaData>
<CreateTime>2013-07-25T14:08:49-07:00</CreateTime>
<LastUpdatedTime>2013-07-25T14:08:49-07:00</LastUpdatedTime>
</MetaData>
<Name>TestQBCustomer12345</Name>
<WebSite/>
<Email/>
<CustomField xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="StringTypeCustomField">
<DefinitionId>Preferred Delivery Method</DefinitionId>
<Value>DONT</Value>
</CustomField>
<CustomField xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="StringTypeCustomField">
<DefinitionId>Resale Number</DefinitionId>
</CustomField>
<CustomField xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="BooleanTypeCustomField">
<DefinitionId>Bill With Parent</DefinitionId>
<Value>false</Value>
</CustomField>
<ShowAs>TestQBCustomer12345</ShowAs>
<OpenBalance>
<Amount>0</Amount>
</OpenBalance>
</Customer>
You can test it first using apiexplorer then use the proper setters to do the same in your code.
Please let me know how it goes.
Thanks
Refer to the documentation:
https://developer.intuit.com/docs/0025_quickbooksapi/0050_data_services/v2/0500_quickbooks_windows/0600_object_reference/customer
You'll note that:
Id is an internal key generated by IPP/IDS - it's NOT something you can set yourself.
ExternalKey is the same situation - it's generated by IPP/IDS, not set-able by you.
ExternalId is marked "UNSUPPORTED FIELD."
AlternateId is marked "NOT SUPPORTED."
The only one of these fields that should work is:
AcctNum
If you're still having problems with that field, the way to troubleshoot is to get the raw XML outgoing request from Intuit, the raw XML that you get back (showing success) and then the raw response that you get back when you query it, showing that it's NULL.

Orbeon autocomplete - Content is not allowed in prolog

I'm trying to add an autocomplete component in dynamic mode to a form created with the Orbeon Form Builder (version Orbeon Forms 3.9.0+.stable.201109261742 PE).
The xml below is a simple test form with the autocomplete that retrieves the data from a public webservice (currently with a static request body).
The first time the autocomplete loads the data it works just fine: the items are presented in a list. But the second time, when I type another character to narrow down the search results, or when I select an item from the list, I get the error message "Content is not allowed in prolog".
If I ignore the error and continue anyway, the error changes to "Got unexpected request sequence number".
I don't understand why it only works the first time since the data returned by the web service is always the same because of the static request body.
Below you find the complete xml of the test form.
<xhtml:html xmlns:xhtml="http://www.w3.org/1999/xhtml"
xmlns:xxi="http://orbeon.org/oxf/xml/xinclude"
xmlns:xi="http://www.w3.org/2001/XInclude"
xmlns:ev="http://www.w3.org/2001/xml-events"
xmlns:xforms="http://www.w3.org/2002/xforms"
xmlns:saxon="http://saxon.sf.net/"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:exforms="http://www.exforms.org/exf/1-0"
xmlns:sql="http://orbeon.org/oxf/xml/sql"
xmlns:fr="http://orbeon.org/oxf/xml/form-runner"
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xxforms="http://orbeon.org/oxf/xml/xforms"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<xhtml:head>
<xhtml:title>Test form</xhtml:title>
<xforms:model id="fr-form-model">
<xforms:instance id="fr-form-instance">
<form>
<section-1>
<codeSearch/>
</section-1>
</form>
</xforms:instance>
<xforms:bind id="fr-form-binds" nodeset="instance('fr-form-instance')">
<xforms:bind id="section-1-bind" nodeset="section-1">
<xforms:bind id="codeSearch-bind" nodeset="codeSearch" name="codeSearch" type="xforms:string"/>
</xforms:bind>
</xforms:bind>
<xforms:instance id="fr-form-metadata" xxforms:readonly="true">
<metadata>
<application-name>IRISbox</application-name>
<form-name>Test</form-name>
<title xml:lang="fr">Test form</title>
<description xml:lang="fr"/>
<author/>
<logo mediatype="" filename="" size=""/>
</metadata>
</xforms:instance>
<xforms:instance id="fr-form-attachments">
<attachments>
<css mediatype="text/css" filename="" size=""/>
<pdf mediatype="application/pdf" filename="" size=""/>
</attachments>
</xforms:instance>
<xforms:instance id="fr-form-resources" xxforms:readonly="false">
<resources>
<resource xml:lang="fr">
<codeSearch>
<label>Cities</label>
<hint/>
<help/>
<alert/>
</codeSearch>
<section-1>
<label>Test</label>
<help/>
</section-1>
</resource>
</resources>
</xforms:instance>
<xforms:instance id="fr-service-request-instance" xxforms:exclude-result-prefixes="#all">
<request/>
</xforms:instance>
<xforms:instance id="fr-service-response-instance" xxforms:exclude-result-prefixes="#all">
<response/>
</xforms:instance>
<!-- Search Cities by Name HTTP service -->
<xforms:instance id="searchCitiesByName-instance" class="fr-service"
xxforms:exclude-result-prefixes="#all">
<body><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns="http://www.restfulwebservices.net/ServiceContracts/2008/01">
<soapenv:Header/>
<soapenv:Body>
<ns:GetCitiesByCountry>
<ns:Country>USA</ns:Country>
</ns:GetCitiesByCountry>
</soapenv:Body>
</soapenv:Envelope></body>
</xforms:instance>
<xforms:submission id="searchCitiesByName-submission" class="fr-service"
ref="instance('fr-service-request-instance')"
resource="http://www.restfulwebservices.net/wcf/WeatherForecastService.svc"
method="post"
serialization="application/xml"
mediatype="application/soap+xml; action=GetCitiesByCountry"
replace="instance"
instance="searchCitiesByName-instance"/>
<xforms:action ev:event="xforms-submit" ev:observer="searchCitiesByName-submission">
<xxforms:variable name="request-instance-name" select="'searchCitiesByName-instance'"
as="xs:string"/>
<xforms:insert nodeset="instance('fr-service-request-instance')"
origin="saxon:parse(instance($request-instance-name))"/>
</xforms:action>
</xforms:model>
</xhtml:head>
<xhtml:body>
<fr:view>
<xforms:label ref="instance('fr-form-metadata')/title"/>
<fr:body>
<fr:section id="section-1-section" bind="section-1-bind">
<xforms:label ref="$form-resources/section-1/label"/>
<xforms:help ref="$form-resources/section-1/help"/>
<fr:grid columns="1">
<xhtml:tr>
<xhtml:td>
<fr:autocomplete
id="codeSearch"
bind="codeSearch-bind"
dynamic-itemset="true"
max-results-displayed="50">
<xforms:label ref="$form-resources/codeSearch/label"/>
<!-- React to user searching -->
<xforms:action ev:event="fr-search-changed">
<xxforms:variable name="search-value" select="event('fr-search-value')"/>
<xxforms:variable name="make-suggestion" select="string-length($search-value) >= 2"/>
<xforms:action if="$make-suggestion">
<xforms:setvalue ref="instance('code-search-instance')/searchFor" value="$search-value"/>
<xforms:send submission="searchCitiesByName-submission"/>
</xforms:action>
<xforms:action if="not($make-suggestion)">
<!-- Delete itemset -->
<xforms:delete nodeset="instance('searchCitiesByName-instance')//*:GetCitiesByCountryResult/*:string"/>
</xforms:action>
</xforms:action>
<xforms:itemset nodeset="instance('searchCitiesByName-instance')//*:GetCitiesByCountryResult/*:string">
<xforms:label ref="text()"/>
<xforms:value ref="text()"/>
</xforms:itemset>
</fr:autocomplete>
</xhtml:td>
</xhtml:tr>
<xhtml:tr>
<xhtml:td>
<widget:xforms-instance-inspector xmlns:widget="http://orbeon.org/oxf/xml/widget" id="orbeon-xforms-inspector"/>
</xhtml:td>
</xhtml:tr>
</fr:grid>
</fr:section>
</fr:body>
</fr:view>
</xhtml:body>
</xhtml:html>
Any help is appreciated.