1 /*
2  * Copyright 2009-2017 Alibaba Cloud All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #include <alibabacloud/ocr/model/RecognizeVATInvoiceResult.h>
18 #include <json/json.h>
19 
20 using namespace AlibabaCloud::Ocr;
21 using namespace AlibabaCloud::Ocr::Model;
22 
RecognizeVATInvoiceResult()23 RecognizeVATInvoiceResult::RecognizeVATInvoiceResult() :
24 	ServiceResult()
25 {}
26 
RecognizeVATInvoiceResult(const std::string & payload)27 RecognizeVATInvoiceResult::RecognizeVATInvoiceResult(const std::string &payload) :
28 	ServiceResult()
29 {
30 	parse(payload);
31 }
32 
~RecognizeVATInvoiceResult()33 RecognizeVATInvoiceResult::~RecognizeVATInvoiceResult()
34 {}
35 
parse(const std::string & payload)36 void RecognizeVATInvoiceResult::parse(const std::string &payload)
37 {
38 	Json::Reader reader;
39 	Json::Value value;
40 	reader.parse(payload, value);
41 	setRequestId(value["RequestId"].asString());
42 	auto dataNode = value["Data"];
43 	auto contentNode = dataNode["Content"];
44 	if(!contentNode["InvoiceCode"].isNull())
45 		data_.content.invoiceCode = contentNode["InvoiceCode"].asString();
46 	if(!contentNode["InvoiceNo"].isNull())
47 		data_.content.invoiceNo = contentNode["InvoiceNo"].asString();
48 	if(!contentNode["InvoiceDate"].isNull())
49 		data_.content.invoiceDate = contentNode["InvoiceDate"].asString();
50 	if(!contentNode["AntiFakeCode"].isNull())
51 		data_.content.antiFakeCode = contentNode["AntiFakeCode"].asString();
52 	if(!contentNode["PayerName"].isNull())
53 		data_.content.payerName = contentNode["PayerName"].asString();
54 	if(!contentNode["PayerRegisterNo"].isNull())
55 		data_.content.payerRegisterNo = contentNode["PayerRegisterNo"].asString();
56 	if(!contentNode["PayerAddress"].isNull())
57 		data_.content.payerAddress = contentNode["PayerAddress"].asString();
58 	if(!contentNode["PayerBankName"].isNull())
59 		data_.content.payerBankName = contentNode["PayerBankName"].asString();
60 	if(!contentNode["WithoutTaxAmount"].isNull())
61 		data_.content.withoutTaxAmount = contentNode["WithoutTaxAmount"].asString();
62 	if(!contentNode["TaxAmount"].isNull())
63 		data_.content.taxAmount = contentNode["TaxAmount"].asString();
64 	if(!contentNode["SumAmount"].isNull())
65 		data_.content.sumAmount = contentNode["SumAmount"].asString();
66 	if(!contentNode["InvoiceAmount"].isNull())
67 		data_.content.invoiceAmount = contentNode["InvoiceAmount"].asString();
68 	if(!contentNode["PayeeName"].isNull())
69 		data_.content.payeeName = contentNode["PayeeName"].asString();
70 	if(!contentNode["PayeeRegisterNo"].isNull())
71 		data_.content.payeeRegisterNo = contentNode["PayeeRegisterNo"].asString();
72 	if(!contentNode["PayeeAddress"].isNull())
73 		data_.content.payeeAddress = contentNode["PayeeAddress"].asString();
74 	if(!contentNode["PayeeBankName"].isNull())
75 		data_.content.payeeBankName = contentNode["PayeeBankName"].asString();
76 	if(!contentNode["Payee"].isNull())
77 		data_.content.payee = contentNode["Payee"].asString();
78 	if(!contentNode["Checker"].isNull())
79 		data_.content.checker = contentNode["Checker"].asString();
80 	if(!contentNode["Clerk"].isNull())
81 		data_.content.clerk = contentNode["Clerk"].asString();
82 	auto boxNode = dataNode["Box"];
83 		auto allInvoiceCodes = boxNode["InvoiceCodes"]["InvoiceCode"];
84 		for (auto value : allInvoiceCodes)
85 			data_.box.invoiceCodes.push_back(value.asString());
86 		auto allInvoiceNoes = boxNode["InvoiceNoes"]["InvoiceNo"];
87 		for (auto value : allInvoiceNoes)
88 			data_.box.invoiceNoes.push_back(value.asString());
89 		auto allInvoiceDates = boxNode["InvoiceDates"]["InvoiceDate"];
90 		for (auto value : allInvoiceDates)
91 			data_.box.invoiceDates.push_back(value.asString());
92 		auto allInvoiceFakeCodes = boxNode["InvoiceFakeCodes"]["InvoiceFakeCode"];
93 		for (auto value : allInvoiceFakeCodes)
94 			data_.box.invoiceFakeCodes.push_back(value.asString());
95 		auto allPayerNames = boxNode["PayerNames"]["PayerName"];
96 		for (auto value : allPayerNames)
97 			data_.box.payerNames.push_back(value.asString());
98 		auto allPayerRegisterNoes = boxNode["PayerRegisterNoes"]["PayerRegisterNo"];
99 		for (auto value : allPayerRegisterNoes)
100 			data_.box.payerRegisterNoes.push_back(value.asString());
101 		auto allPayerAddresses = boxNode["PayerAddresses"]["PayerAddress"];
102 		for (auto value : allPayerAddresses)
103 			data_.box.payerAddresses.push_back(value.asString());
104 		auto allPayerBankNames = boxNode["PayerBankNames"]["PayerBankNames"];
105 		for (auto value : allPayerBankNames)
106 			data_.box.payerBankNames.push_back(value.asString());
107 		auto allWithoutTaxAmounts = boxNode["WithoutTaxAmounts"]["WithoutTaxAmount"];
108 		for (auto value : allWithoutTaxAmounts)
109 			data_.box.withoutTaxAmounts.push_back(value.asString());
110 		auto allTaxAmounts = boxNode["TaxAmounts"]["TaxAmount"];
111 		for (auto value : allTaxAmounts)
112 			data_.box.taxAmounts.push_back(value.asString());
113 		auto allSumAmounts = boxNode["SumAmounts"]["SumAmount"];
114 		for (auto value : allSumAmounts)
115 			data_.box.sumAmounts.push_back(value.asString());
116 		auto allInvoiceAmounts = boxNode["InvoiceAmounts"]["InvoiceAmount"];
117 		for (auto value : allInvoiceAmounts)
118 			data_.box.invoiceAmounts.push_back(value.asString());
119 		auto allPayeeNames = boxNode["PayeeNames"]["PayeeName"];
120 		for (auto value : allPayeeNames)
121 			data_.box.payeeNames.push_back(value.asString());
122 		auto allPayeeRegisterNoes = boxNode["PayeeRegisterNoes"]["PayeeRegisterNo"];
123 		for (auto value : allPayeeRegisterNoes)
124 			data_.box.payeeRegisterNoes.push_back(value.asString());
125 		auto allPayeeAddresses = boxNode["PayeeAddresses"]["PayeeAddress"];
126 		for (auto value : allPayeeAddresses)
127 			data_.box.payeeAddresses.push_back(value.asString());
128 		auto allPayeeBankNames = boxNode["PayeeBankNames"]["PayeeBankName"];
129 		for (auto value : allPayeeBankNames)
130 			data_.box.payeeBankNames.push_back(value.asString());
131 		auto allPayees = boxNode["Payees"]["Payee"];
132 		for (auto value : allPayees)
133 			data_.box.payees.push_back(value.asString());
134 		auto allCheckers = boxNode["Checkers"]["Checker"];
135 		for (auto value : allCheckers)
136 			data_.box.checkers.push_back(value.asString());
137 		auto allClerks = boxNode["Clerks"]["Clerk"];
138 		for (auto value : allClerks)
139 			data_.box.clerks.push_back(value.asString());
140 
141 }
142 
getData() const143 RecognizeVATInvoiceResult::Data RecognizeVATInvoiceResult::getData()const
144 {
145 	return data_;
146 }
147 
148