Skip to content

Commit

Permalink
tweak(Sales) add debitor xls export
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmhh committed Jan 12, 2024
1 parent 588c4c6 commit b21d64c
Show file tree
Hide file tree
Showing 4 changed files with 100 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tests/tine20/Sales/AllTests.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*
* @package Sales
* @license http://www.gnu.org/licenses/agpl.html
* @copyright Copyright (c) 2008-2022 Metaways Infosystems GmbH (http://www.metaways.de)
* @copyright Copyright (c) 2008-2024 Metaways Infosystems GmbH (http://www.metaways.de)
* @author Philipp Schuele <[email protected]>
*/

Expand Down Expand Up @@ -40,6 +40,7 @@ public static function suite ()
$suite->addTestSuite(Sales_Document_ControllerTest::class);
$suite->addTestSuite(Sales_Document_ExportTest::class);
$suite->addTestSuite(Sales_Document_JsonTest::class);
$suite->addTestSuite(Sales_Export_DebitorTest::class);
$suite->addTestSuite(Sales_Export_ProductTest::class);

return $suite;
Expand Down
53 changes: 53 additions & 0 deletions tests/tine20/Sales/Export/DebitorTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php declare(strict_types=1);
/**
* Tine 2.0 - http://www.tine20.org
*
* @package Sales
* @license http://www.gnu.org/licenses/agpl.html
* @copyright Copyright (c) 2024 Metaways Infosystems GmbH (http://www.metaways.de)
* @author Paul Mehrer <[email protected]>
*/

/**
* Sales Debitor export tests
*
* @package Sales
* @subpackage Export
*/
class Sales_Export_DebitorTest extends Sales_Document_Abstract
{
public function testXlsExport()
{
$customer = $this->_createCustomer();
$customer->{Sales_Model_Customer::FLD_DEBITORS}->addRecord(new Sales_Model_Debitor([
Sales_Model_Debitor::FLD_NAME => 'unittest',
Sales_Model_Debitor::FLD_DIVISION_ID => Sales_Config::getInstance()->{Sales_Config::DEFAULT_DIVISION},
], true));
$customer = Sales_Controller_Customer::getInstance()->update($customer);

$export = new Sales_Export_DebitorXls(Tinebase_Model_Filter_FilterGroup::getFilterForModel(
Sales_Model_Debitor::class, [
['field' => Sales_Model_Debitor::FLD_CUSTOMER_ID, 'operator' => 'equals', 'value' => $customer->getId()],
]), null,
[
'definitionId' => Tinebase_ImportExportDefinition::getInstance()->search(Tinebase_Model_Filter_FilterGroup::getFilterForModel(Tinebase_Model_ImportExportDefinition::class, [
'model' => Sales_Model_Debitor::class,
'name' => 'debitor_xls'
]))->getFirstRecord()->getId()
]);

$xls = Tinebase_TempFile::getTempPath();
$export->generate();
$export->write($xls);

$reader = PHPExcel_IOFactory::createReader('Excel2007');
$doc = $reader->load($xls);
$arrayData = $doc->getActiveSheet()->rangeToArray('A1:M4');

for ($i = 2; $i < 4; ++$i) {
$this->assertTrue(in_array($customer->getTitle(), $arrayData[$i]));
$this->assertTrue(in_array($customer->{Sales_Model_Customer::FLD_DEBITORS}->getFirstRecord()->{Sales_Model_Debitor::FLD_DIVISION_ID}->getTitle(), $arrayData[$i])
|| in_array($customer->{Sales_Model_Customer::FLD_DEBITORS}->getLastRecord()->{Sales_Model_Debitor::FLD_DIVISION_ID}->getTitle(), $arrayData[$i]));
}
}
}
32 changes: 32 additions & 0 deletions tine20/Sales/Export/DebitorXls.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php
/**
* Sales xls generation class
*
* @package Sales
* @subpackage Export
* @license http://www.gnu.org/licenses/agpl.html AGPL Version 3
* @author Paul Mehrer <[email protected]>
* @copyright Copyright (c) 2024 Metaways Infosystems GmbH (http://www.metaways.de)
*
*/

/**
* Sales xls generation class
*
* @package Sales
* @subpackage Export
*/
class Sales_Export_DebitorXls extends Tinebase_Export_Xls
{
/**
* @var string $_applicationName
*/
protected $_applicationName = 'Sales';

/**
* default export definition name
*
* @var string
*/
protected $_defaultExportname = 'debitor_default_xls';
}
13 changes: 13 additions & 0 deletions tine20/Sales/Export/definitions/debitor_xls.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<config>
<model>Sales_Model_Debitor</model>
<name>debitor_xls</name>
<!-- _('Excel all data') -->
<label>Excel all data</label>
<type>export</type>
<plugin>Sales_Export_DebitorXls</plugin>
<icon_class>tinebase-action-export-xls</icon_class>
<favorite>true</favorite>
<order>600</order>
<scope>multi</scope>
</config>

0 comments on commit b21d64c

Please sign in to comment.