Skip to content

Commit 39b7fa5

Browse files
intacctcoleenhojimmymcpeter
authored andcommitted
Adding PurchasingTransactionUpdate, Line, and unit test (#137)
1 parent 4b46fbe commit 39b7fa5

File tree

4 files changed

+519
-0
lines changed

4 files changed

+519
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2018 Sage Intacct, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
7+
* use this file except in compliance with the License. You may obtain a copy
8+
* of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* or in the "LICENSE" file accompanying this file. This file is distributed on
13+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14+
* express or implied. See the License for the specific language governing
15+
* permissions and limitations under the License.
16+
*/
17+
18+
namespace Intacct\Functions\Purchasing;
19+
20+
use Intacct\Xml\XMLWriter;
21+
use InvalidArgumentException;
22+
23+
class PurchasingTransactionLineUpdate extends AbstractPurchasingTransactionLine
24+
{
25+
26+
/** @var int|string */
27+
private $lineNo;
28+
29+
/**
30+
* @return int|string
31+
*/
32+
public function getLineNo()
33+
{
34+
return $this->lineNo;
35+
}
36+
37+
/**
38+
* @param int|string $lineNo
39+
*/
40+
public function setLineNo($lineNo)
41+
{
42+
if ($lineNo < 1) {
43+
throw new InvalidArgumentException('Line No must be greater than zero');
44+
}
45+
$this->lineNo = $lineNo;
46+
}
47+
48+
/**
49+
* @param XMLWriter $xml
50+
*/
51+
public function writeXml(XMLWriter &$xml)
52+
{
53+
$xml->startElement('updatepotransitem');
54+
$xml->writeAttribute('line_num', $this->getLineNo());
55+
56+
$xml->writeElement('itemid', $this->getItemId());
57+
$xml->writeElement('itemdesc', $this->getItemDescription());
58+
$xml->writeElement('taxable', $this->isTaxable());
59+
$xml->writeElement('warehouseid', $this->getWarehouseId());
60+
$xml->writeElement('quantity', $this->getQuantity());
61+
$xml->writeElement('unit', $this->getUnit());
62+
$xml->writeElement('price', $this->getPrice());
63+
$xml->writeElement('locationid', $this->getLocationId());
64+
$xml->writeElement('departmentid', $this->getDepartmentId());
65+
$xml->writeElement('memo', $this->getMemo());
66+
67+
if (count($this->getItemDetails()) > 0) {
68+
$xml->startElement('itemdetails');
69+
foreach ($this->getItemDetails() as $itemDetail) {
70+
$itemDetail->writeXml($xml);
71+
}
72+
$xml->endElement(); //itemdetails
73+
}
74+
75+
$xml->writeElement('form1099', $this->isForm1099());
76+
77+
$this->writeXmlExplicitCustomFields($xml);
78+
79+
$xml->writeElement('projectid', $this->getProjectId());
80+
$xml->writeElement('customerid', $this->getCustomerId());
81+
$xml->writeElement('vendorid', $this->getVendorId());
82+
$xml->writeElement('employeeid', $this->getEmployeeId());
83+
$xml->writeElement('classid', $this->getClassId());
84+
$xml->writeElement('contractid', $this->getContractId());
85+
$xml->writeElement('billable', $this->isBillable());
86+
87+
$xml->endElement(); //updatepotransitem
88+
}
89+
}
Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2018 Sage Intacct, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
7+
* use this file except in compliance with the License. You may obtain a copy
8+
* of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* or in the "LICENSE" file accompanying this file. This file is distributed on
13+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14+
* express or implied. See the License for the specific language governing
15+
* permissions and limitations under the License.
16+
*/
17+
18+
namespace Intacct\Functions\Purchasing;
19+
20+
use Intacct\Xml\XMLWriter;
21+
22+
/**
23+
* Update as existing purchasing transaction record
24+
*/
25+
class PurchasingTransactionUpdate extends AbstractPurchasingTransaction
26+
{
27+
28+
/**
29+
* Write the function block XML
30+
*
31+
* @param XMLWriter $xml
32+
*/
33+
public function writeXml(XMLWriter &$xml)
34+
{
35+
$xml->startElement('function');
36+
$xml->writeAttribute('controlid', $this->getControlId());
37+
38+
$xml->startElement('update_potransaction');
39+
if ($this->getExternalId()) {
40+
$xml->writeAttribute('key', $this->getExternalId());
41+
$xml->writeAttribute('externalkey', 'true'); //TODO fix writeAttribute to accept bool
42+
} else {
43+
$xml->writeAttribute('key', $this->getDocumentNumber());
44+
}
45+
46+
if ( $this->getTransactionDate() ) {
47+
$xml->startElement('datecreated');
48+
$xml->writeDateSplitElements($this->getTransactionDate(), true);
49+
$xml->endElement(); //datecreated
50+
}
51+
52+
if ( $this->getGlPostingDate() ) {
53+
$xml->startElement('dateposted');
54+
$xml->writeDateSplitElements($this->getGlPostingDate(), true);
55+
$xml->endElement(); //dateposted
56+
}
57+
58+
$xml->writeElement('referenceno', $this->getReferenceNumber());
59+
$xml->writeElement('vendordocno', $this->getVendorDocNumber());
60+
$xml->writeElement('termname', $this->getPaymentTerm());
61+
62+
if ( $this->getDueDate() ) {
63+
$xml->startElement('datedue');
64+
$xml->writeDateSplitElements($this->getDueDate(), true);
65+
$xml->endElement(); //datedue
66+
}
67+
68+
$xml->writeElement('message', $this->getMessage());
69+
$xml->writeElement('shippingmethod', $this->getShippingMethod());
70+
71+
if ( $this->getReturnToContactName() ) {
72+
$xml->startElement('returnto');
73+
$xml->writeElement('contactname', $this->getReturnToContactName(), true);
74+
$xml->endElement(); //returnto
75+
76+
}
77+
78+
if ( $this->getPayToContactName() ) {
79+
$xml->startElement('payto');
80+
$xml->writeElement('contactname', $this->getPayToContactName(), true);
81+
$xml->endElement(); //payto
82+
83+
}
84+
85+
$xml->writeElement('supdocid', $this->getAttachmentsId());
86+
$xml->writeElement('externalid', $this->getExternalId());
87+
88+
$xml->writeElement('basecurr', $this->getBaseCurrency());
89+
$xml->writeElement('currency', $this->getTransactionCurrency());
90+
91+
if ( $this->getExchangeRateDate() ) {
92+
$xml->startElement('exchratedate');
93+
$xml->writeDateSplitElements($this->getExchangeRateDate(), true);
94+
$xml->endElement();
95+
}
96+
97+
if ( $this->getExchangeRateType() ) {
98+
$xml->writeElement('exchratetype', $this->getExchangeRateType());
99+
} elseif ( $this->getExchangeRateValue() ) {
100+
$xml->writeElement('exchrate', $this->getExchangeRateValue());
101+
} elseif ( $this->getBaseCurrency() || $this->getTransactionCurrency() ) {
102+
$xml->writeElement('exchratetype', $this->getExchangeRateType(), true);
103+
}
104+
105+
$this->writeXmlExplicitCustomFields($xml);
106+
107+
$xml->writeElement('state', $this->getState());
108+
109+
if (count($this->getLines()) > 0) {
110+
$xml->startElement('updatepotransitems');
111+
foreach ($this->getLines() as $line) {
112+
$line->writeXml($xml);
113+
}
114+
$xml->endElement(); //updatepotransitems
115+
}
116+
117+
if (count($this->getSubtotals()) > 0) {
118+
$xml->startElement('updatesubtotals');
119+
foreach ($this->getSubtotals() as $subtotal) {
120+
$subtotal->writeXml($xml);
121+
}
122+
$xml->endElement(); //subtotals
123+
}
124+
125+
$xml->endElement(); //update_potransaction
126+
127+
$xml->endElement(); //function
128+
}
129+
}
Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?php
2+
3+
/**
4+
* Copyright 2018 Sage Intacct, Inc.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License"). You may not
7+
* use this file except in compliance with the License. You may obtain a copy
8+
* of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* or in the "LICENSE" file accompanying this file. This file is distributed on
13+
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
14+
* express or implied. See the License for the specific language governing
15+
* permissions and limitations under the License.
16+
*/
17+
18+
namespace Intacct\Functions\Purchasing;
19+
20+
use Intacct\Functions\InventoryControl\TransactionItemDetail;
21+
use Intacct\Xml\XMLWriter;
22+
23+
/**
24+
* @coversDefaultClass \Intacct\Functions\Purchasing\PurchasingTransactionLineUpdate
25+
*/
26+
class PurchasingTransactionLineUpdateTest extends \PHPUnit\Framework\TestCase
27+
{
28+
29+
public function testDefaultParams()
30+
{
31+
$expected = <<<EOF
32+
<?xml version="1.0" encoding="UTF-8"?>
33+
<updatepotransitem line_num="1" />
34+
EOF;
35+
36+
$xml = new XMLWriter();
37+
$xml->openMemory();
38+
$xml->setIndent(true);
39+
$xml->setIndentString(' ');
40+
$xml->startDocument();
41+
42+
$entry = new PurchasingTransactionLineUpdate();
43+
$entry->setLineNo('1');
44+
45+
$entry->writeXml($xml);
46+
47+
$this->assertXmlStringEqualsXmlString($expected, $xml->flush());
48+
}
49+
50+
public function testParamsOverrides()
51+
{
52+
$expected = <<<EOF
53+
<?xml version="1.0" encoding="UTF-8"?>
54+
<updatepotransitem line_num="1">
55+
<itemid>26323</itemid>
56+
<itemdesc>Item Description</itemdesc>
57+
<taxable>true</taxable>
58+
<warehouseid>93294</warehouseid>
59+
<quantity>2340</quantity>
60+
<unit>593</unit>
61+
<price>32.35</price>
62+
<locationid>SF</locationid>
63+
<departmentid>Purchasing</departmentid>
64+
<memo>Memo</memo>
65+
<itemdetails>
66+
<itemdetail>
67+
<quantity>52</quantity>
68+
<lotno>3243</lotno>
69+
</itemdetail>
70+
</itemdetails>
71+
<form1099>true</form1099>
72+
<customfields>
73+
<customfield>
74+
<customfieldname>customfield1</customfieldname>
75+
<customfieldvalue>customvalue1</customfieldvalue>
76+
</customfield>
77+
</customfields>
78+
<projectid>235</projectid>
79+
<customerid>23423434</customerid>
80+
<vendorid>797656</vendorid>
81+
<employeeid>90295</employeeid>
82+
<classid>243609</classid>
83+
<contractid>9062</contractid>
84+
<billable>true</billable>
85+
</updatepotransitem>
86+
EOF;
87+
88+
$xml = new XMLWriter();
89+
$xml->openMemory();
90+
$xml->setIndent(true);
91+
$xml->setIndentString(' ');
92+
$xml->startDocument();
93+
94+
$entry = new PurchasingTransactionLineUpdate();
95+
$entry->setLineNo(1);
96+
$entry->setItemId('26323');
97+
$entry->setItemDescription('Item Description');
98+
$entry->setTaxable(true);
99+
$entry->setWarehouseId('93294');
100+
$entry->setQuantity(2340);
101+
$entry->setUnit('593');
102+
$entry->setPrice(32.35);
103+
$entry->setMemo('Memo');
104+
$entry->setBillable(true);
105+
$entry->setForm1099(true);
106+
$entry->setLocationId('SF');
107+
$entry->setDepartmentId('Purchasing');
108+
$entry->setProjectId('235');
109+
$entry->setCustomerId('23423434');
110+
$entry->setVendorId('797656');
111+
$entry->setEmployeeId('90295');
112+
$entry->setClassId('243609');
113+
$entry->setContractId('9062');
114+
115+
$itemDetail1 = new TransactionItemDetail();
116+
$itemDetail1->setQuantity(52);
117+
$itemDetail1->setLotNumber('3243');
118+
119+
$entry->setItemDetails([
120+
$itemDetail1,
121+
]);
122+
$entry->setCustomFields([
123+
'customfield1' => 'customvalue1',
124+
]);
125+
126+
$entry->writeXml($xml);
127+
128+
$this->assertXmlStringEqualsXmlString($expected, $xml->flush());
129+
}
130+
}

0 commit comments

Comments
 (0)